0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00

Merge pull request #997 from cobbspur/uploadrefactor

This commit is contained in:
Hannah Wolfe 2013-10-11 18:15:38 +01:00
commit e613d88167
2 changed files with 17 additions and 14 deletions

View file

@ -7,7 +7,7 @@
UploadUi = function ($dropzone, settings) { UploadUi = function ($dropzone, settings) {
var source, 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>', $cancel = '<a class="image-cancel js-cancel"><span class="hidden">Delete</span></a>',
$progress = $('<div />', { $progress = $('<div />', {
"class" : "js-upload-progress progress progress-success active", "class" : "js-upload-progress progress progress-success active",
@ -57,7 +57,6 @@
}).attr('src', result); }).attr('src', result);
} }
preLoadImage(); preLoadImage();
}, },
bindFileUpload: function () { bindFileUpload: function () {
@ -162,17 +161,21 @@
$dropzone.find('div.description').before($url); $dropzone.find('div.description').before($url);
$dropzone.find('.js-button-accept').on('click', function () { $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(); $dropzone.find('div.description').hide();
val = $('#uploadurl').val();
$dropzone.find('.js-fileupload').removeClass('right'); $dropzone.find('.js-fileupload').removeClass('right');
$dropzone.find('.js-url').remove(); $dropzone.find('.js-url').remove();
$dropzone.find('button.centre').remove(); $dropzone.find('button.centre').remove();
self.complete(val); if (val === "") {
$dropzone.trigger("uploadsuccess", 'http://');
self.initWithDropzone();
} else {
self.complete(val);
}
}); });
}, },
initWithImage: function () { initWithImage: function () {
var self = this; var self = this, val;
// This is the start point if an image already exists // This is the start point if an image already exists
source = $dropzone.find('img.js-upload-target').attr('src'); source = $dropzone.find('img.js-upload-target').attr('src');
$dropzone.removeClass('image-uploader image-uploader-url').addClass('pre-image-uploader'); $dropzone.removeClass('image-uploader image-uploader-url').addClass('pre-image-uploader');
@ -181,6 +184,11 @@
$dropzone.find('.js-cancel').on('click', function () { $dropzone.find('.js-cancel').on('click', function () {
$dropzone.find('img.js-upload-target').attr({'src': ''}); $dropzone.find('img.js-upload-target').attr({'src': ''});
$dropzone.find('div.description').show(); $dropzone.find('div.description').show();
$dropzone.delay(2500).animate({opacity: 100}, 1000, function () {
self.init();
});
$dropzone.trigger("uploadsuccess", 'http://');
self.initWithDropzone(); self.initWithDropzone();
}); });
}, },

View file

@ -440,10 +440,9 @@
initUploads: function () { initUploads: function () {
this.$('.js-drop-zone').upload({editor: true}); this.$('.js-drop-zone').upload({editor: true});
this.$('.js-drop-zone').on('uploadstart', $.proxy(this.disableEditor, this)); 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('uploadfailure', $.proxy(this.enableEditor, this));
this.$('.js-drop-zone').on('uploadsuccess', $.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 () { enableEditor: function () {
@ -608,7 +607,7 @@
// TODO: hasMarker but no image? // TODO: hasMarker but no image?
} }
function handleDownloadStart(e) { function handleUpload(e, result_src) {
/*jslint regexp: true, bitwise: true */ /*jslint regexp: true, bitwise: true */
var line = findLine($(e.currentTarget).attr('id')), var line = findLine($(e.currentTarget).attr('id')),
lineNumber = editor.getLineNumber(line), lineNumber = editor.getLineNumber(line),
@ -633,9 +632,6 @@
); );
} }
} }
}
function handleDownloadSuccess(e, result_src) {
editor.replaceSelection(result_src); editor.replaceSelection(result_src);
} }
@ -652,8 +648,7 @@
// Public API // Public API
_.extend(this, { _.extend(this, {
getEditorValue: getEditorValue, getEditorValue: getEditorValue,
handleDownloadStart: handleDownloadStart, handleUpload: handleUpload
handleDownloadSuccess: handleDownloadSuccess
}); });
// initialise // initialise