2 * jQuery Asynchronous Plugin 1.0
4 * Copyright (c) 2008 Vincent Robert (genezys.net)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
11 // opts.delay : (default 10) delay between async call in ms
12 // opts.bulk : (default 500) delay during which the loop can continue synchronously without yielding the CPU
13 // opts.test : (default true) function to test in the while test part
14 // opts.loop : (default empty) function to call in the while loop part
15 // opts.end : (default empty) function to call at the end of the while loop
16 $.whileAsync = function(opts
)
18 var delay
= Math
.abs(opts
.delay
) || 10,
19 bulk
= isNaN(opts
.bulk
) ? 500 : Math
.abs(opts
.bulk
),
20 test
= opts
.test
|| function(){ return true; },
21 loop
= opts
.loop
|| function(){},
22 end
= opts
.end
|| function(){};
32 if( bulk
=== 0 || (new Date() - begin
) > bulk
)
39 setTimeout(arguments
.callee
, delay
);
49 // opts.delay : (default 10) delay between async call in ms
50 // opts.bulk : (default 500) delay during which the loop can continue synchronously without yielding the CPU
51 // opts.loop : (default empty) function to call in the each loop part, signature: function(index, value) this = value
52 // opts.end : (default empty) function to call at the end of the each loop
53 $.eachAsync = function(array
, opts
)
57 loop
= opts
.loop
|| function(){};
61 test: function(){ return i
< l
; },
65 return loop
.call(val
, i
++, val
);
71 $.fn
.eachAsync = function(opts
)
73 $.eachAsync(this, opts
);