X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Fimagecacher.js;h=cb19c12aa6d0d0e162140b80823aa53a7f1fc6bb;hb=614511639979907ceb0da3614122a4d8eb963ad4;hp=c6260931513655ab9f73b655d3b27498c467ecb4;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/core/imagecacher.js b/_source/core/imagecacher.js index c626093..cb19c12 100644 --- a/_source/core/imagecacher.js +++ b/_source/core/imagecacher.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -11,6 +11,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { var doCallback = function() { + img.removeAllListeners(); loaded[ image ] = 1; callback(); }; @@ -22,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++ ) { @@ -53,6 +73,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license else loadImage( image, checkPending ); } + + return event; } }; })();