diff options
| author | Matias Niemelä | 2014-03-14 12:01:45 -0400 | 
|---|---|---|
| committer | Matias Niemelä | 2014-03-14 12:42:07 -0400 | 
| commit | 7b5e019981f352add88be2984de68e553d1bfa93 (patch) | |
| tree | ffa2a2c0154031f6d2c53ab4f77b0f63f0cc50d8 /src/ng/raf.js | |
| parent | 129e2e021ab1d773874428cd1fb329eae72797c4 (diff) | |
| download | angular.js-7b5e019981f352add88be2984de68e553d1bfa93.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 f4eb31c0..e07adbfe 100644 --- a/src/ng/raf.js +++ b/src/ng/raf.js @@ -1,7 +1,7 @@  'use strict';  function $$RAFProvider(){ //rAF -  this.$get = ['$window', function($window) { +  this.$get = ['$window', '$timeout', function($window, $timeout) {      var requestAnimationFrame = $window.requestAnimationFrame ||                                  $window.webkitRequestAnimationFrame ||                                  $window.mozRequestAnimationFrame; @@ -10,14 +10,22 @@ function $$RAFProvider(){ //rAF                                 $window.webkitCancelAnimationFrame ||                                 $window.mozCancelAnimationFrame; -    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;    }]; | 
