Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
deleteScript can now be a callback (#428)
Browse files Browse the repository at this point in the history
* Delete Script can now be a callback

* Fixed backwards compat issue
  • Loading branch information
derrekbertrand authored and linkesch committed Oct 4, 2017
1 parent 63c865b commit d6ec905
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/js/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@

if (images.length) {
for (i = 0; i < images.length; i++) {
this.deleteFile(images[i].attr('src'));
this.deleteFile(images[i].attr('src'), images[i]);

$parent = images[i].closest('.medium-insert-images');
images[i].closest('figure').remove();
Expand Down Expand Up @@ -577,17 +577,25 @@
/**
* Makes ajax call to deleteScript
*
* @param {String} file File name
* @param {string} file The name of the file to delete
* @param {jQuery} $el The jQuery element of the file to delete
* @returns {void}
*/

Images.prototype.deleteFile = function (file) {
Images.prototype.deleteFile = function (file, $el) {
// only take action if there is a truthy value
if (this.options.deleteScript) {
$.ajax($.extend(true, {}, {
url: this.options.deleteScript,
type: this.options.deleteMethod || 'POST',
data: { file: file }
}, this.options.fileDeleteOptions));
// try to run it as a callback
if (typeof this.options.deleteScript === 'function') {
this.options.deleteScript(file, $el);
// otherwise, it's probably a string, call it as ajax
} else {
$.ajax($.extend(true, {}, {
url: this.options.deleteScript,
type: this.options.deleteMethod || 'POST',
data: { file: file }
}, this.options.fileDeleteOptions));
}
}
};

Expand Down

0 comments on commit d6ec905

Please sign in to comment.