raf.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. /**
  2. * angular-strap
  3. * @version v2.3.9 - 2016-06-10
  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. if (angular.version.minor < 3 && angular.version.dot < 14) {
  10. angular.module('ng').factory('$$rAF', [ '$window', '$timeout', function($window, $timeout) {
  11. var requestAnimationFrame = $window.requestAnimationFrame || $window.webkitRequestAnimationFrame || $window.mozRequestAnimationFrame;
  12. var cancelAnimationFrame = $window.cancelAnimationFrame || $window.webkitCancelAnimationFrame || $window.mozCancelAnimationFrame || $window.webkitCancelRequestAnimationFrame;
  13. var rafSupported = !!requestAnimationFrame;
  14. var raf = rafSupported ? function(fn) {
  15. var id = requestAnimationFrame(fn);
  16. return function() {
  17. cancelAnimationFrame(id);
  18. };
  19. } : function(fn) {
  20. var timer = $timeout(fn, 16.66, false);
  21. return function() {
  22. $timeout.cancel(timer);
  23. };
  24. };
  25. raf.supported = rafSupported;
  26. return raf;
  27. } ]);
  28. }