raf.js 1.1 KB

123456789101112131415161718192021222324252627
  1. /**
  2. * angular-strap
  3. * @version v2.3.5 - 2015-10-29
  4. * @link http://mgcrea.github.io/angular-strap
  5. * @author Olivier Louvignes <olivier@mg-crea.com> (https://github.com/mgcrea)
  6. * @license MIT License, http://www.opensource.org/licenses/MIT
  7. */
  8. 'use strict';
  9. angular.version.minor < 3 && angular.version.dot < 14 && angular.module('ng').factory('$$rAF', [ '$window', '$timeout', function($window, $timeout) {
  10. var requestAnimationFrame = $window.requestAnimationFrame || $window.webkitRequestAnimationFrame || $window.mozRequestAnimationFrame;
  11. var cancelAnimationFrame = $window.cancelAnimationFrame || $window.webkitCancelAnimationFrame || $window.mozCancelAnimationFrame || $window.webkitCancelRequestAnimationFrame;
  12. var rafSupported = !!requestAnimationFrame;
  13. var raf = rafSupported ? function(fn) {
  14. var id = requestAnimationFrame(fn);
  15. return function() {
  16. cancelAnimationFrame(id);
  17. };
  18. } : function(fn) {
  19. var timer = $timeout(fn, 16.66, false);
  20. return function() {
  21. $timeout.cancel(timer);
  22. };
  23. };
  24. raf.supported = rafSupported;
  25. return raf;
  26. } ]);