1/* v1.5 */ 2if ('undefined' != typeof jQuery) { (function($) { 3 4 $.imgpreload = function(imgs, settings) { 5 settings = $.extend({}, 6 $.fn.imgpreload.defaults, (settings instanceof Function) ? { 7 all: settings 8 }: settings); 9 10 if ('string' == typeof imgs) { 11 imgs = new Array(imgs); 12 } 13 14 var loaded = new Array(); 15 16 $.each(imgs, 17 function(i, elem) { 18 var img = new Image(); 19 20 var url = elem; 21 22 var img_obj = img; 23 24 if ('string' != typeof elem) { 25 url = $(elem).attr('src') || $(elem).css('background-image').replace(/^url\((?:"|')?(.*)(?:'|")?\)$/mg, "$1"); 26 27 img_obj = elem; 28 } 29 30 $(img).bind('load error', 31 function(e) { 32 loaded.push(img_obj); 33 34 $.data(img_obj, 'loaded', ('error' == e.type) ? false: true); 35 36 if (settings.each instanceof Function) { 37 settings.each.call(img_obj); 38 } 39 40 41 if (loaded.length >= imgs.length && settings.all instanceof Function) { 42 settings.all.call(loaded); 43 } 44 45 $(this).unbind('load error'); 46 }); 47 48 img.src = url; 49 }); 50 }; 51 52 $.fn.imgpreload = function(settings) { 53 $.imgpreload(this, settings); 54 55 return this; 56 }; 57 58 $.fn.imgpreload.defaults = { 59 each: null // callback invoked when each image in a group loads 60 , 61 all: null // callback invoked when when the entire group of images has loaded 62 }; 63 64 })(jQuery); 65} 66 67/* 68 69Usage: 70 71$('#content img').imgpreload(function() 72{ 73// this = array of dom image objects 74// callback executes when all images are loaded 75}); 76 77$('#content img').imgpreload 78({ 79each: function() 80{ 81// this = dom image object 82// check for success with: $(this).data('loaded') 83// callback executes when each image loads 84}, 85all: function() 86{ 87// this = array of dom image objects 88// check for success with: $(this[i]).data('loaded') 89// callback executes when all images are loaded 90} 91}); 92 93$.imgpreload('/images/a.gif',function() 94{ 95// this = array of dom image objects 96// check for success with: $(this[i]).data('loaded') 97// callback 98}); 99 100$.imgpreload(['/images/a.gif','/images/b.gif'],function() 101{ 102// this = array of dom image objects 103// check for success with: $(this[i]).data('loaded') 104// callback executes when all images are loaded 105}); 106 107$.imgpreload(['/images/a.gif','/images/b.gif'], 108{ 109each: function() 110{ 111// this = dom image object 112// check for success with: $(this).data('loaded') 113// callback executes on every image load 114}, 115all: function() 116{ 117// this = array of dom image objects 118// check for success with: $(this[i]).data('loaded') 119// callback executes when all images are loaded 120} 121}); 122*/
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.