      1 ﻿/*
      2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
      3 For licensing, see LICENSE.html or http://ckeditor.com/license
      4 */
      5
      6 (function()
      7 {
      8 	var loaded = {};
      9
     10 	var loadImage = function( image, callback )
     11 	{
     12 		var doCallback = function()
     13 			{
     14 				loaded[ image ] = 1;
     15 				callback();
     16 			};
     17
     18 		var img = new CKEDITOR.dom.element( 'img' );
     19 		img.on( 'load', doCallback );
     20 		img.on( 'error', doCallback );
     21 		img.setAttribute( 'src', image );
     22 	};
     23
     24 	/**
     25 	 * Load images into the browser cache.
     26 	 * @namespace
     27 	 * @example
     28 	 */
     29  	CKEDITOR.imageCacher =
     30 	{
     31 		/**
     32 		 * Loads one or more images.
     33 		 * @param {Array} images The URLs for the images to be loaded.
     34 		 * @param {Function} callback The function to be called once all images
     35 		 *		are loaded.
     36 		 */
     37 		load : function( images, callback )
     38 		{
     39 			var pendingCount = images.length;
     40
     41 			var checkPending = function()
     42 			{
     43 				if ( --pendingCount === 0 )
     44 					callback();
     45 			};
     46
     47 			for ( var i = 0 ; i < images.length ; i++ )
     48 			{
     49 				var image = images[ i ];
     50
     51 				if ( loaded[ image ] )
     52 					checkPending();
     53 				else
     54 					loadImage( image, checkPending );
     55 			}
     56 		}
     57 	};
     58 })();
     59