diff options
author | Timo Tijhof <krinklemail@gmail.com> | 2018-08-19 22:23:51 +0100 |
---|---|---|
committer | Krinkle <krinklemail@gmail.com> | 2018-08-20 21:11:51 +0000 |
commit | 9f86db20286c2c39ae5f134a31ad2927441340d0 (patch) | |
tree | e2f2a40e1d3cf7a9414b92f69ad0c5f6e56d73ff /resources/lib/jquery.async.js | |
parent | 0087dcf2ac0ebefae98128b2259a732d92d253a8 (diff) | |
download | mediawikicore-9f86db20286c2c39ae5f134a31ad2927441340d0.tar.gz mediawikicore-9f86db20286c2c39ae5f134a31ad2927441340d0.zip |
resources: Move non-jquery files from /resources/lib/jquery to /resources/lib
Per discussion on T193826, these are not part of jquery (the library, or the
module), and should not be in the same subdirectory.
To follow the new convention that all entries directly in /resources/lib
should correspond to single library only (either as file, or as directory),
move them one directory up.
Bug: T193826
Change-Id: I24c05ec5fc5f0a2d54d501a4a022d829675bf850
Diffstat (limited to 'resources/lib/jquery.async.js')
-rw-r--r-- | resources/lib/jquery.async.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/resources/lib/jquery.async.js b/resources/lib/jquery.async.js new file mode 100644 index 000000000000..2161f6b9e3ae --- /dev/null +++ b/resources/lib/jquery.async.js @@ -0,0 +1,69 @@ +/* + * 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);
\ No newline at end of file |