Skip to content

Commit

Permalink
Merge pull request TryGhost#997 from cobbspur/uploadrefactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ErisDS committed Oct 11, 2013
2 parents 0bb5e87 + c52a10c commit e613d88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
20 changes: 14 additions & 6 deletions core/client/assets/lib/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -57,7 +57,6 @@
}).attr('src', result);
}
preLoadImage();

},

bindFileUpload: function () {
Expand Down Expand Up @@ -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');
Expand All @@ -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();
});
},
Expand Down
11 changes: 3 additions & 8 deletions core/client/views/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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),
Expand All @@ -633,9 +632,6 @@
);
}
}
}

function handleDownloadSuccess(e, result_src) {
editor.replaceSelection(result_src);
}

Expand All @@ -652,8 +648,7 @@
// Public API
_.extend(this, {
getEditorValue: getEditorValue,
handleDownloadStart: handleDownloadStart,
handleDownloadSuccess: handleDownloadSuccess
handleUpload: handleUpload
});

// initialise
Expand Down

0 comments on commit e613d88

Please sign in to comment.