limitExecByInterval fixes

This commit is contained in:
mourner 2012-05-10 11:09:30 +03:00
parent b333f86e1d
commit 7956c8c87e

View File

@ -71,23 +71,28 @@ L.Util = {
}()),
limitExecByInterval: function (fn, time, context) {
var lock, execOnUnlock, args;
function exec() {
lock = false;
if (execOnUnlock) {
args.callee.apply(context, args);
execOnUnlock = false;
}
}
return function () {
args = arguments;
if (!lock) {
lock = true;
setTimeout(exec, time);
fn.apply(context, args);
} else {
var lock, execOnUnlock;
return function wrapperFn() {
var args = arguments;
if (lock) {
execOnUnlock = true;
return;
}
lock = true;
setTimeout(function () {
lock = false;
if (execOnUnlock) {
wrapperFn.apply(context, args);
execOnUnlock = false;
}
}, time);
fn.apply(context, args);
};
},