X-Git-Url: https://jasonwoof.com/gitweb/?p=ckeditor.git;a=blobdiff_plain;f=_source%2Fcore%2Fimagecacher.js;h=cb19c12aa6d0d0e162140b80823aa53a7f1fc6bb;hp=07045567a3542fde2d0f312b58d3828e21991baf;hb=039a051ccf3901311661022a30afd60fc38130c9;hpb=c9fdde67e6384bd5a66adc2b3bba5c4ce9db56c7 diff --git a/_source/core/imagecacher.js b/_source/core/imagecacher.js index 0704556..cb19c12 100644 --- a/_source/core/imagecacher.js +++ b/_source/core/imagecacher.js @@ -23,27 +23,46 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }; /** - * Load images into the browser cache. - * @namespace - * @example + * @namespace Load images into the browser cache. */ CKEDITOR.imageCacher = { /** * Loads one or more images. - * @param {Array} images The URLs for the images to be loaded. - * @param {Function} callback The function to be called once all images + * @param {Array} images The URLs of the images to be loaded. + * @param {Function} [callback] A function to be called once all images * are loaded. + * @return {CKEDITOR.event} An event object which fires the 'loaded' + * event when all images are completely loaded. Additionally, the + * "finished" property is set after the "loaded" event call. + * @example + * var loader = CKEDITOR.imageCacher.load( [ '/image1.png', 'image2.png' ] ); + * if ( !loader.finished ) + * { + * loader.on( 'load', function() + * { + * alert( 'All images are loaded' ); + * }); + * } */ load : function( images, callback ) { var pendingCount = images.length; + var event = new CKEDITOR.event; + event.on( 'loaded', function() + { + event.finished = 1; + }); + + if ( callback ) + event.on( 'loaded', callback ); + var checkPending = function() - { - if ( --pendingCount === 0 ) - callback(); - }; + { + if ( --pendingCount === 0 ) + event.fire( 'loaded' ); + }; for ( var i = 0 ; i < images.length ; i++ ) { @@ -54,6 +73,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license else loadImage( image, checkPending ); } + + return event; } }; })();