Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions spec/images.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ describe('Images addon', function () {
expect(this.$el.find('.medium-insert-images img').attr('src')).toEqual('test.jpg');
});

it('replaces preview by uploaded image, with user built url', function () {
var stubbedImage = jasmine.createSpy('image');
spyOn(this.addon, 'getDOMImage').and.returnValue(stubbedImage);
spyOn(this.addon.options, 'returnURLFromUploadResult').and.callFake(function (result) {
return result.success[0].id;
});
this.$el.prepend('<div class="medium-insert-images medium-insert-active"><figure><img src="data:" alt=""></figure></div>');

this.addon.uploadDone(null, {
context: this.$el.find('figure'),
result: {
success: [
{ id: 'test-image-url.jpg' }
]
}
});
stubbedImage.onload();
expect(this.$el.find('.medium-insert-images img').attr('src')).toEqual('test-image-url.jpg');
});

it('uploads without preview when it is set like this in options', function (done) {
var $p = this.$el.find('p');

Expand Down
14 changes: 13 additions & 1 deletion src/js/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
messages: {
acceptFileTypesError: 'This file is not in a supported format: ',
maxFileSizeError: 'This file is too big: '
},
returnURLFromUploadResult: function (result) {
return result.files[0].url;
}
// uploadError: function($el, data) {}
// uploadCompleted: function ($el, data) {}
Expand Down Expand Up @@ -361,7 +364,16 @@
*/

Images.prototype.uploadDone = function (e, data) {
$.proxy(this, 'showImage', data.result.files[0].url, data)();

var url = '';

if (typeof this.options.returnURLFromUploadResult === 'function') {
url = this.options.returnURLFromUploadResult(data.result);
} else {
url = defaults.returnURLFromUploadResult(data.result);
}

$.proxy(this, 'showImage', url, data)();

this.core.clean();
this.sorting();
Expand Down