From c52a10cd1a5c3888326185621448b85641d1e2fc Mon Sep 17 00:00:00 2001 From: cobbspur Date: Thu, 10 Oct 2013 21:37:09 +0100 Subject: [PATCH] fixed image upload url synchronicity and url removed on cancel closes #988, closes #956, closes #975 - fixed multiple ids and refactored triggers - persistence requirement overridden - trash can now removes url in editor - if empty url is saved http:// is inserted and dropzone initialized Conflicts: core/client/assets/lib/uploader.js --- core/client/assets/lib/uploader.js | 20 ++++++++++++++------ core/client/views/editor.js | 11 +++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core/client/assets/lib/uploader.js b/core/client/assets/lib/uploader.js index 28b8ce93ff..28ecc9af34 100644 --- a/core/client/assets/lib/uploader.js +++ b/core/client/assets/lib/uploader.js @@ -7,7 +7,7 @@ UploadUi = function ($dropzone, settings) { var source, - $url = '
', + $url = '
', $cancel = '', $progress = $('
', { "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(); }); }, diff --git a/core/client/views/editor.js b/core/client/views/editor.js index 7d31ddae1d..afd9297a85 100644 --- a/core/client/views/editor.js +++ b/core/client/views/editor.js @@ -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