JSFiddle - React, Tailwind, and code Playground
HTML
<img src="http://test.thecodecentral.com/demos/imageloader/Tree.jpg" />
<img src="http://nimg.sulekha.com/others/thumbnailfull/pakistan-muslims-festival-2009-11-22-9-10-3.jpg" />
<img src="http://nimg.sulekha.com/ot" />
JavaScript
(function($) {
$.fn.extend({
myplugin: function (callback) {
// create array of deferred objects to track loading
var def = this.map(function(ix, el) {
return $.Deferred(function() {
$(el).one('load', this.resolve)
.one('error', this.resolve);
}).promise();
}).get();
// register the final callback
$.when.apply($, def).done(callback);
// and chain
return this;
}
}) ;
})(jQuery) ;
$('img').myplugin(function() {
alert('done');
});