diff options
| author | Matias Niemelä | 2014-03-14 12:01:45 -0400 |
|---|---|---|
| committer | Matias Niemelä | 2014-03-14 13:48:37 -0400 |
| commit | ee8e4a946ed8f943e00846b88d8d51c0b2cd1fab (patch) | |
| tree | ae7c8e617d9473c376b4e5634da563b083243ace /src/ng/raf.js | |
| parent | a41a2a1d2ce20f86ac2709592e4ada527160e580 (diff) | |
| download | angular.js-ee8e4a946ed8f943e00846b88d8d51c0b2cd1fab.tar.bz2 | |
fix($$rAF): always fallback to a $timeout incase native rAF isn't supported
Closes #6654
Diffstat (limited to 'src/ng/raf.js')
| -rw-r--r-- | src/ng/raf.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/ng/raf.js b/src/ng/raf.js index f85ee12a..0bc43f34 100644 --- a/src/ng/raf.js +++ b/src/ng/raf.js @@ -1,21 +1,29 @@ 'use strict'; function $$RAFProvider(){ //rAF - this.$get = ['$window', function($window) { + this.$get = ['$window', '$timeout', function($window, $timeout) { var requestAnimationFrame = $window.requestAnimationFrame || $window.webkitRequestAnimationFrame; var cancelAnimationFrame = $window.cancelAnimationFrame || $window.webkitCancelAnimationFrame; - var raf = function(fn) { - var id = requestAnimationFrame(fn); - return function() { - cancelAnimationFrame(id); - }; - }; + var rafSupported = !!requestAnimationFrame; + var raf = rafSupported + ? function(fn) { + var id = requestAnimationFrame(fn); + return function() { + cancelAnimationFrame(id); + }; + } + : function(fn) { + var timer = $timeout(fn, 16.66, false); // 1000 / 60 = 16.666 + return function() { + $timeout.cancel(timer); + }; + }; - raf.supported = !!requestAnimationFrame; + raf.supported = rafSupported; return raf; }]; |
