JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.2
[ckeditor.git] / _source / core / imagecacher.js
index 0704556..cb19c12 100644 (file)
@@ -23,27 +23,46 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        };\r
 \r
        /**\r
-        * Load images into the browser cache.\r
-        * @namespace\r
-        * @example\r
+        * @namespace Load images into the browser cache.\r
         */\r
        CKEDITOR.imageCacher =\r
        {\r
                /**\r
                 * Loads one or more images.\r
-                * @param {Array} images The URLs for the images to be loaded.\r
-                * @param {Function} callback The function to be called once all images\r
+                * @param {Array} images The URLs of the images to be loaded.\r
+                * @param {Function} [callback] A function to be called once all images\r
                 *              are loaded.\r
+                * @return {CKEDITOR.event} An event object which fires the 'loaded'\r
+                *              event when all images are completely loaded. Additionally, the\r
+                *              "finished" property is set after the "loaded" event call.\r
+                * @example\r
+                * var loader = CKEDITOR.imageCacher.load( [ '/image1.png', 'image2.png' ] );\r
+                * if ( !loader.finished )\r
+                * {\r
+                *     loader.on( 'load', function()\r
+                *         {\r
+                *             alert( 'All images are loaded' );\r
+                *         });\r
+                * }\r
                 */\r
                load : function( images, callback )\r
                {\r
                        var pendingCount = images.length;\r
 \r
+                       var event = new CKEDITOR.event;\r
+                       event.on( 'loaded', function()\r
+                               {\r
+                                       event.finished = 1;\r
+                               });\r
+\r
+                       if ( callback )\r
+                               event.on( 'loaded', callback );\r
+\r
                        var checkPending = function()\r
-                       {\r
-                               if ( --pendingCount === 0 )\r
-                                       callback();\r
-                       };\r
+                               {\r
+                                       if ( --pendingCount === 0 )\r
+                                               event.fire( 'loaded' );\r
+                               };\r
 \r
                        for ( var i = 0 ; i < images.length ; i++ )\r
                        {\r
@@ -54,6 +73,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                else\r
                                        loadImage( image, checkPending );\r
                        }\r
+\r
+                       return event;\r
                }\r
        };\r
 })();\r