diff options
Diffstat (limited to 'src/polyfill.js')
-rw-r--r-- | src/polyfill.js | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/polyfill.js b/src/polyfill.js index 3a3c25c..06ae0fd 100644 --- a/src/polyfill.js +++ b/src/polyfill.js @@ -1,7 +1,7 @@ // Add CustomEvent to IE9 and IE10 if (typeof CustomEvent !== 'function') { // Code from: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent - function CustomEvent (event, options) { + var CustomEvent = function(event, options) { options = options || { bubbles: false, cancelable: false, detail: undefined } var e = document.createEvent('CustomEvent') e.initCustomEvent(event, options.bubbles, options.cancelable, options.detail) @@ -11,4 +11,32 @@ if (typeof CustomEvent !== 'function') { CustomEvent.prototype = window.Event.prototype window.CustomEvent = CustomEvent -}
\ No newline at end of file +} + +// requestAnimationFrame / cancelAnimationFrame Polyfill with fallback based on Paul Irish +(function(w) { + var lastTime = 0 + var vendors = ['moz', 'webkit'] + + for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { + w.requestAnimationFrame = w[vendors[x] + 'RequestAnimationFrame'] + w.cancelAnimationFrame = w[vendors[x] + 'CancelAnimationFrame'] || + w[vendors[x] + 'CancelRequestAnimationFrame'] + } + + w.requestAnimationFrame = w.requestAnimationFrame || + function(callback) { + var currTime = new Date().getTime() + var timeToCall = Math.max(0, 16 - (currTime - lastTime)) + + var id = w.setTimeout(function() { + callback(currTime + timeToCall) + }, timeToCall) + + lastTime = currTime + timeToCall + return id + } + + w.cancelAnimationFrame = w.cancelAnimationFrame || w.clearTimeout; + +}(window))
\ No newline at end of file |