aboutsummaryrefslogtreecommitdiffstats
path: root/resources/jquery/jquery.async.js
diff options
context:
space:
mode:
authorRoan Kattouw <catrope@users.mediawiki.org>2010-09-04 04:00:09 +0000
committerRoan Kattouw <catrope@users.mediawiki.org>2010-09-04 04:00:09 +0000
commit32377424b9492bca276d6f8036ed297bef726ed3 (patch)
tree35913f9b33983e1eb157dcc55a472cc39e2a5336 /resources/jquery/jquery.async.js
parentecf56c33fae16e8a7a8f7ab56e7b6aba3720ceeb (diff)
downloadmediawikicore-32377424b9492bca276d6f8036ed297bef726ed3.tar.gz
mediawikicore-32377424b9492bca276d6f8036ed297bef726ed3.zip
Merging resourceloader branch into trunk. Full documentation is at http://www.mediawiki.org/wiki/ResourceLoader and a general overview has been posted on wikitech-li <http://lists.wikimedia.org/pipermail/wikitech-l/2010-September/049253.html>. One important change is that all JS is now loaded at the bottom, so any scripts assuming things from wikibits or whatever are present will fail.
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/72349
Diffstat (limited to 'resources/jquery/jquery.async.js')
-rw-r--r--resources/jquery/jquery.async.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/resources/jquery/jquery.async.js b/resources/jquery/jquery.async.js
new file mode 100644
index 000000000000..f5de32664570
--- /dev/null
+++ b/resources/jquery/jquery.async.js
@@ -0,0 +1,78 @@
+/*
+ * jQuery Asynchronous Plugin 1.0
+ *
+ * Copyright (c) 2008 Vincent Robert (genezys.net)
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ *
+ */
+(function($){
+
+// opts.delay : (default 10) delay between async call in ms
+// opts.bulk : (default 500) delay during which the loop can continue synchronously without yielding the CPU
+// opts.test : (default true) function to test in the while test part
+// opts.loop : (default empty) function to call in the while loop part
+// opts.end : (default empty) function to call at the end of the while loop
+$.whileAsync = function(opts)
+{
+ var delay = Math.abs(opts.delay) || 10,
+ bulk = isNaN(opts.bulk) ? 500 : Math.abs(opts.bulk),
+ test = opts.test || function(){ return true; },
+ loop = opts.loop || function(){},
+ end = opts.end || function(){};
+
+ (function(){
+
+ var t = false,
+ begin = new Date();
+
+ while( t = test() )
+ {
+ loop();
+ if( bulk === 0 || (new Date() - begin) > bulk )
+ {
+ break;
+ }
+ }
+ if( t )
+ {
+ setTimeout(arguments.callee, delay);
+ }
+ else
+ {
+ end();
+ }
+
+ })();
+}
+
+// opts.delay : (default 10) delay between async call in ms
+// opts.bulk : (default 500) delay during which the loop can continue synchronously without yielding the CPU
+// opts.loop : (default empty) function to call in the each loop part, signature: function(index, value) this = value
+// opts.end : (default empty) function to call at the end of the each loop
+$.eachAsync = function(array, opts)
+{
+ var i = 0,
+ l = array.length,
+ loop = opts.loop || function(){};
+
+ $.whileAsync(
+ $.extend(opts, {
+ test: function(){ return i < l; },
+ loop: function()
+ {
+ var val = array[i];
+ return loop.call(val, i++, val);
+ }
+ })
+ );
+}
+
+$.fn.eachAsync = function(opts)
+{
+ $.eachAsync(this, opts);
+ return this;
+}
+
+})(jQuery);
+