Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

ngAnimate mock

Olivier Louvignes edited this page Jul 24, 2014 · 4 revisions

The ngAnimate dependency can be mocked out with:

angular.module('ngAnimate', [])

  .factory('$$animateReflow', ['$window', '$timeout', function($window, $timeout) {
    var requestAnimationFrame = $window.requestAnimationFrame       ||
                                $window.webkitRequestAnimationFrame ||
                                function(fn) {
                                  return $timeout(fn, 10, false);
                                };

    var cancelAnimationFrame = $window.cancelAnimationFrame       ||
                               $window.webkitCancelAnimationFrame ||
                               function(timer) {
                                 return $timeout.cancel(timer);
                               };
    return function(fn) {
      var id = requestAnimationFrame(fn);
      return function() {
        cancelAnimationFrame(id);
      };
    };
  }])
Clone this wiki locally