mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 12:53:13 +03:00
Merge pull request #997 from cobbspur/uploadrefactor
This commit is contained in:
commit
e613d88167
@ -7,7 +7,7 @@
|
||||
|
||||
UploadUi = function ($dropzone, settings) {
|
||||
var source,
|
||||
$url = '<div class="js-url"><input id="uploadurl" class="url" type="url" placeholder="http://"/></div>',
|
||||
$url = '<div class="js-url"><input class="url js-upload-url" type="url" placeholder="http://"/></div>',
|
||||
$cancel = '<a class="image-cancel js-cancel"><span class="hidden">Delete</span></a>',
|
||||
$progress = $('<div />', {
|
||||
"class" : "js-upload-progress progress progress-success active",
|
||||
@ -57,7 +57,6 @@
|
||||
}).attr('src', result);
|
||||
}
|
||||
preLoadImage();
|
||||
|
||||
},
|
||||
|
||||
bindFileUpload: function () {
|
||||
@ -162,17 +161,21 @@
|
||||
$dropzone.find('div.description').before($url);
|
||||
|
||||
$dropzone.find('.js-button-accept').on('click', function () {
|
||||
$dropzone.trigger('uploadstart', [$dropzone.attr('id')]);
|
||||
val = $dropzone.find('.js-upload-url').val();
|
||||
$dropzone.find('div.description').hide();
|
||||
val = $('#uploadurl').val();
|
||||
$dropzone.find('.js-fileupload').removeClass('right');
|
||||
$dropzone.find('.js-url').remove();
|
||||
$dropzone.find('button.centre').remove();
|
||||
self.complete(val);
|
||||
if (val === "") {
|
||||
$dropzone.trigger("uploadsuccess", 'http://');
|
||||
self.initWithDropzone();
|
||||
} else {
|
||||
self.complete(val);
|
||||
}
|
||||
});
|
||||
},
|
||||
initWithImage: function () {
|
||||
var self = this;
|
||||
var self = this, val;
|
||||
// This is the start point if an image already exists
|
||||
source = $dropzone.find('img.js-upload-target').attr('src');
|
||||
$dropzone.removeClass('image-uploader image-uploader-url').addClass('pre-image-uploader');
|
||||
@ -181,6 +184,11 @@
|
||||
$dropzone.find('.js-cancel').on('click', function () {
|
||||
$dropzone.find('img.js-upload-target').attr({'src': ''});
|
||||
$dropzone.find('div.description').show();
|
||||
$dropzone.delay(2500).animate({opacity: 100}, 1000, function () {
|
||||
self.init();
|
||||
});
|
||||
|
||||
$dropzone.trigger("uploadsuccess", 'http://');
|
||||
self.initWithDropzone();
|
||||
});
|
||||
},
|
||||
|
@ -440,10 +440,9 @@
|
||||
initUploads: function () {
|
||||
this.$('.js-drop-zone').upload({editor: true});
|
||||
this.$('.js-drop-zone').on('uploadstart', $.proxy(this.disableEditor, this));
|
||||
this.$('.js-drop-zone').on('uploadstart', this.uploadMgr.handleDownloadStart);
|
||||
this.$('.js-drop-zone').on('uploadfailure', $.proxy(this.enableEditor, this));
|
||||
this.$('.js-drop-zone').on('uploadsuccess', $.proxy(this.enableEditor, this));
|
||||
this.$('.js-drop-zone').on('uploadsuccess', this.uploadMgr.handleDownloadSuccess);
|
||||
this.$('.js-drop-zone').on('uploadsuccess', this.uploadMgr.handleUpload);
|
||||
},
|
||||
|
||||
enableEditor: function () {
|
||||
@ -608,7 +607,7 @@
|
||||
// TODO: hasMarker but no image?
|
||||
}
|
||||
|
||||
function handleDownloadStart(e) {
|
||||
function handleUpload(e, result_src) {
|
||||
/*jslint regexp: true, bitwise: true */
|
||||
var line = findLine($(e.currentTarget).attr('id')),
|
||||
lineNumber = editor.getLineNumber(line),
|
||||
@ -633,9 +632,6 @@
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleDownloadSuccess(e, result_src) {
|
||||
editor.replaceSelection(result_src);
|
||||
}
|
||||
|
||||
@ -652,8 +648,7 @@
|
||||
// Public API
|
||||
_.extend(this, {
|
||||
getEditorValue: getEditorValue,
|
||||
handleDownloadStart: handleDownloadStart,
|
||||
handleDownloadSuccess: handleDownloadSuccess
|
||||
handleUpload: handleUpload
|
||||
});
|
||||
|
||||
// initialise
|
||||
|
Loading…
Reference in New Issue
Block a user