|
546 | 546 |
|
547 | 547 | if (images.length) { |
548 | 548 | for (i = 0; i < images.length; i++) { |
549 | | - this.deleteFile(images[i].attr('src')); |
| 549 | + this.deleteFile(images[i].attr('src'), images[i]); |
550 | 550 |
|
551 | 551 | $parent = images[i].closest('.medium-insert-images'); |
552 | 552 | images[i].closest('figure').remove(); |
|
577 | 577 | /** |
578 | 578 | * Makes ajax call to deleteScript |
579 | 579 | * |
580 | | - * @param {String} file File name |
| 580 | + * @param {string} file The name of the file to delete |
| 581 | + * @param {jQuery} $el The jQuery element of the file to delete |
581 | 582 | * @returns {void} |
582 | 583 | */ |
583 | 584 |
|
584 | | - Images.prototype.deleteFile = function (file) { |
| 585 | + Images.prototype.deleteFile = function (file, $el) { |
| 586 | + // only take action if there is a truthy value |
585 | 587 | if (this.options.deleteScript) { |
586 | | - $.ajax($.extend(true, {}, { |
587 | | - url: this.options.deleteScript, |
588 | | - type: this.options.deleteMethod || 'POST', |
589 | | - data: { file: file } |
590 | | - }, this.options.fileDeleteOptions)); |
| 588 | + // try to run it as a callback |
| 589 | + if (typeof this.options.deleteScript === 'function') { |
| 590 | + this.options.deleteScript(file, $el); |
| 591 | + // otherwise, it's probably a string, call it as ajax |
| 592 | + } else { |
| 593 | + $.ajax($.extend(true, {}, { |
| 594 | + url: this.options.deleteScript, |
| 595 | + type: this.options.deleteMethod || 'POST', |
| 596 | + data: { file: file } |
| 597 | + }, this.options.fileDeleteOptions)); |
| 598 | + } |
591 | 599 | } |
592 | 600 | }; |
593 | 601 |
|
|
0 commit comments