aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/raf.js
blob: f4eb31c0bf7ebca2941ca242f2d2234cf0d0e83e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'use strict';

function $$RAFProvider(){ //rAF
  this.$get = ['$window', function($window) {
    var requestAnimationFrame = $window.requestAnimationFrame ||
                                $window.webkitRequestAnimationFrame ||
                                $window.mozRequestAnimationFrame;

    var cancelAnimationFrame = $window.cancelAnimationFrame ||
                               $window.webkitCancelAnimationFrame ||
                               $window.mozCancelAnimationFrame;

    var raf = function(fn) {
      var id = requestAnimationFrame(fn);
      return function() {
        cancelAnimationFrame(id);
      };
    };

    raf.supported = !!requestAnimationFrame;

    return raf;
  }];
}