From dfdd363d2e58cca368a5821baa05aa740b40cc2f Mon Sep 17 00:00:00 2001 From: mourner Date: Wed, 22 Feb 2012 08:59:17 +0200 Subject: [PATCH] cancelAnimFrame function --- src/core/Util.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/core/Util.js b/src/core/Util.js index 337d405f..75e8ea0e 100644 --- a/src/core/Util.js +++ b/src/core/Util.js @@ -30,6 +30,9 @@ L.Util = { }; }()), + + // TODO refactor: remove repetition + requestAnimFrame: (function () { function timeoutDefer(callback) { window.setTimeout(callback, 1000 / 60); @@ -47,11 +50,24 @@ L.Util = { if (immediate && requestFn === timeoutDefer) { callback(); } else { - requestFn(callback, contextEl); + return requestFn.call(window, callback, contextEl); } }; }()), + cancelAnimFrame: (function () { + var requestFn = window.cancelAnimationFrame || + window.webkitCancelRequestAnimationFrame || + window.mozCancelRequestAnimationFrame || + window.oCancelRequestAnimationFrame || + window.msCancelRequestAnimationFrame || + clearTimeout; + + return function (handle) { + return requestFn.call(window, handle); + } + }()), + limitExecByInterval: function (fn, time, context) { var lock, execOnUnlock, args; function exec() {