Commit e7d1b5fd authored by Randall Leeds's avatar Randall Leeds

Remove requestAnimationFrame polyfill

We work on IE10+ but not IE9. Other major browsers all support it
for a while.
parent 71cd89e9
raf = require('raf')
{
FragmentAnchor
RangeAnchor
......
baseURI = require('base-url')()
raf = require('raf')
Annotator = require('annotator')
$ = Annotator.$
......@@ -8,7 +7,7 @@ highlighter = require('./highlighter')
animationPromise = (fn) ->
return new Promise (resolve, reject) ->
raf ->
requestAnimationFrame ->
try
resolve(fn())
catch error
......@@ -241,7 +240,7 @@ module.exports = class Guest extends Annotator
self.anchors.push(anchor)
# Remove all the highlights that have no corresponding target anymore.
raf -> highlighter.removeHighlights(deadHighlights)
requestAnimationFrame -> highlighter.removeHighlights(deadHighlights)
# Anchor any targets of this annotation that are not anchored already.
for target in annotation.target when target not in anchoredTargets
......@@ -305,7 +304,7 @@ module.exports = class Guest extends Annotator
this.plugins.BucketBar?.update()
unhighlight = Array::concat(unhighlight...)
raf -> highlighter.removeHighlights(unhighlight)
requestAnimationFrame -> highlighter.removeHighlights(unhighlight)
return annotation
......
raf = require('raf')
Annotator = require('annotator')
$ = Annotator.$
......@@ -97,7 +95,7 @@ class Annotator.Plugin.BucketBar extends Annotator.Plugin
# Update sometime soon
update: =>
return if @_updatePending?
@_updatePending = raf =>
@_updatePending = requestAnimationFrame =>
delete @_updatePending
@_update()
......
raf = require('raf')
Annotator = require('annotator')
Guest = require('../guest')
anchoring = require('../anchoring/html')
......@@ -398,7 +397,7 @@ describe 'Guest', ->
annotation = {}
guest.anchors.push({annotation})
guest.deleteAnnotation(annotation)
new Promise(raf).then ->
new Promise(requestAnimationFrame).then ->
assert.equal(guest.anchors.length, 0)
done()
......@@ -408,7 +407,7 @@ describe 'Guest', ->
annotation = {}
guest.anchors.push({annotation})
guest.deleteAnnotation(annotation)
new Promise(raf).then ->
new Promise(requestAnimationFrame).then ->
assert.calledOnce(guest.plugins.BucketBar.update)
done()
......@@ -417,7 +416,7 @@ describe 'Guest', ->
annotation = {}
publish = sandbox.stub(guest, 'publish')
guest.deleteAnnotation(annotation)
new Promise(raf).then ->
new Promise(requestAnimationFrame).then ->
assert.calledOnce(publish)
assert.calledWith(publish, 'annotationDeleted', [annotation])
done()
......@@ -429,7 +428,7 @@ describe 'Guest', ->
removeHighlights = sandbox.stub(highlighter, 'removeHighlights')
guest.anchors.push({annotation, highlights})
guest.deleteAnnotation(annotation)
new Promise(raf).then ->
new Promise(requestAnimationFrame).then ->
assert.calledOnce(removeHighlights)
assert.calledWith(removeHighlights, highlights)
done()
......@@ -103,21 +103,8 @@ describe 'Host', ->
assert.calledOnce(hideFrame)
describe 'panleft and panright events', ->
raf = null
# PhantomJS may or may not have rAF so the normal sandbox approach
# doesn't quite work. We assign and delete it ourselves instead when
# it isn't already present.
beforeEach ->
if window.requestAnimationFrame?
sandbox.stub(window, 'requestAnimationFrame')
else
raf = window.requestAnimationFrame = sandbox.stub()
afterEach ->
if raf?
raf = null
delete window.requestAnimationFrame
sandbox.stub(window, 'requestAnimationFrame')
it 'shrinks or grows the widget to match the delta', ->
host.gestureState = {initial: -100}
......
......@@ -33,6 +33,7 @@ module.exports = function(config) {
// These are needed until PhantomJS 2.0
'../../../node_modules/es6-promise/dist/es6-promise.js',
'vendor/bind.js',
'vendor/raf.js',
'vendor/url.js',
// Test deps
......
// Adapted from https://gist.github.com/paulirish/1579671 which derived from
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller.
// Fixes from Paul Irish, Tino Zijdel, Andrew Mao, Klemen Slavič, Darius Bacon
// MIT license
if (!Date.now)
Date.now = function() { return new Date().getTime(); };
(function() {
'use strict';
var vendors = ['webkit', 'moz'];
for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
var vp = vendors[i];
window.requestAnimationFrame = window[vp+'RequestAnimationFrame'];
window.cancelAnimationFrame = (window[vp+'CancelAnimationFrame']
|| window[vp+'CancelRequestAnimationFrame']);
}
if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) // iOS6 is buggy
|| !window.requestAnimationFrame || !window.cancelAnimationFrame) {
var lastTime = 0;
window.requestAnimationFrame = function(callback) {
var now = Date.now();
var nextTime = Math.max(lastTime + 16, now);
return setTimeout(function() { callback(lastTime = nextTime); },
nextTime - now);
};
window.cancelAnimationFrame = clearTimeout;
}
}());
......@@ -38,7 +38,6 @@
"ng-tags-input": "2.2.0",
"node-iterator-shim": "^1.0.1",
"node-uuid": "^1.4.3",
"raf": "^3.1.0",
"showdown": "^1.2.1",
"uglify-js": "^2.4.14",
"unorm": "^1.3.3"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment