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 FragmentAnchor
RangeAnchor RangeAnchor
......
baseURI = require('base-url')() baseURI = require('base-url')()
raf = require('raf')
Annotator = require('annotator') Annotator = require('annotator')
$ = Annotator.$ $ = Annotator.$
...@@ -8,7 +7,7 @@ highlighter = require('./highlighter') ...@@ -8,7 +7,7 @@ highlighter = require('./highlighter')
animationPromise = (fn) -> animationPromise = (fn) ->
return new Promise (resolve, reject) -> return new Promise (resolve, reject) ->
raf -> requestAnimationFrame ->
try try
resolve(fn()) resolve(fn())
catch error catch error
...@@ -241,7 +240,7 @@ module.exports = class Guest extends Annotator ...@@ -241,7 +240,7 @@ module.exports = class Guest extends Annotator
self.anchors.push(anchor) self.anchors.push(anchor)
# Remove all the highlights that have no corresponding target anymore. # 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. # Anchor any targets of this annotation that are not anchored already.
for target in annotation.target when target not in anchoredTargets for target in annotation.target when target not in anchoredTargets
...@@ -305,7 +304,7 @@ module.exports = class Guest extends Annotator ...@@ -305,7 +304,7 @@ module.exports = class Guest extends Annotator
this.plugins.BucketBar?.update() this.plugins.BucketBar?.update()
unhighlight = Array::concat(unhighlight...) unhighlight = Array::concat(unhighlight...)
raf -> highlighter.removeHighlights(unhighlight) requestAnimationFrame -> highlighter.removeHighlights(unhighlight)
return annotation return annotation
......
raf = require('raf')
Annotator = require('annotator') Annotator = require('annotator')
$ = Annotator.$ $ = Annotator.$
...@@ -97,7 +95,7 @@ class Annotator.Plugin.BucketBar extends Annotator.Plugin ...@@ -97,7 +95,7 @@ class Annotator.Plugin.BucketBar extends Annotator.Plugin
# Update sometime soon # Update sometime soon
update: => update: =>
return if @_updatePending? return if @_updatePending?
@_updatePending = raf => @_updatePending = requestAnimationFrame =>
delete @_updatePending delete @_updatePending
@_update() @_update()
......
raf = require('raf')
Annotator = require('annotator') Annotator = require('annotator')
Guest = require('../guest') Guest = require('../guest')
anchoring = require('../anchoring/html') anchoring = require('../anchoring/html')
...@@ -398,7 +397,7 @@ describe 'Guest', -> ...@@ -398,7 +397,7 @@ describe 'Guest', ->
annotation = {} annotation = {}
guest.anchors.push({annotation}) guest.anchors.push({annotation})
guest.deleteAnnotation(annotation) guest.deleteAnnotation(annotation)
new Promise(raf).then -> new Promise(requestAnimationFrame).then ->
assert.equal(guest.anchors.length, 0) assert.equal(guest.anchors.length, 0)
done() done()
...@@ -408,7 +407,7 @@ describe 'Guest', -> ...@@ -408,7 +407,7 @@ describe 'Guest', ->
annotation = {} annotation = {}
guest.anchors.push({annotation}) guest.anchors.push({annotation})
guest.deleteAnnotation(annotation) guest.deleteAnnotation(annotation)
new Promise(raf).then -> new Promise(requestAnimationFrame).then ->
assert.calledOnce(guest.plugins.BucketBar.update) assert.calledOnce(guest.plugins.BucketBar.update)
done() done()
...@@ -417,7 +416,7 @@ describe 'Guest', -> ...@@ -417,7 +416,7 @@ describe 'Guest', ->
annotation = {} annotation = {}
publish = sandbox.stub(guest, 'publish') publish = sandbox.stub(guest, 'publish')
guest.deleteAnnotation(annotation) guest.deleteAnnotation(annotation)
new Promise(raf).then -> new Promise(requestAnimationFrame).then ->
assert.calledOnce(publish) assert.calledOnce(publish)
assert.calledWith(publish, 'annotationDeleted', [annotation]) assert.calledWith(publish, 'annotationDeleted', [annotation])
done() done()
...@@ -429,7 +428,7 @@ describe 'Guest', -> ...@@ -429,7 +428,7 @@ describe 'Guest', ->
removeHighlights = sandbox.stub(highlighter, 'removeHighlights') removeHighlights = sandbox.stub(highlighter, 'removeHighlights')
guest.anchors.push({annotation, highlights}) guest.anchors.push({annotation, highlights})
guest.deleteAnnotation(annotation) guest.deleteAnnotation(annotation)
new Promise(raf).then -> new Promise(requestAnimationFrame).then ->
assert.calledOnce(removeHighlights) assert.calledOnce(removeHighlights)
assert.calledWith(removeHighlights, highlights) assert.calledWith(removeHighlights, highlights)
done() done()
...@@ -103,21 +103,8 @@ describe 'Host', -> ...@@ -103,21 +103,8 @@ describe 'Host', ->
assert.calledOnce(hideFrame) assert.calledOnce(hideFrame)
describe 'panleft and panright events', -> 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 -> beforeEach ->
if window.requestAnimationFrame? sandbox.stub(window, 'requestAnimationFrame')
sandbox.stub(window, 'requestAnimationFrame')
else
raf = window.requestAnimationFrame = sandbox.stub()
afterEach ->
if raf?
raf = null
delete window.requestAnimationFrame
it 'shrinks or grows the widget to match the delta', -> it 'shrinks or grows the widget to match the delta', ->
host.gestureState = {initial: -100} host.gestureState = {initial: -100}
......
...@@ -33,6 +33,7 @@ module.exports = function(config) { ...@@ -33,6 +33,7 @@ module.exports = function(config) {
// These are needed until PhantomJS 2.0 // These are needed until PhantomJS 2.0
'../../../node_modules/es6-promise/dist/es6-promise.js', '../../../node_modules/es6-promise/dist/es6-promise.js',
'vendor/bind.js', 'vendor/bind.js',
'vendor/raf.js',
'vendor/url.js', 'vendor/url.js',
// Test deps // 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 @@ ...@@ -38,7 +38,6 @@
"ng-tags-input": "2.2.0", "ng-tags-input": "2.2.0",
"node-iterator-shim": "^1.0.1", "node-iterator-shim": "^1.0.1",
"node-uuid": "^1.4.3", "node-uuid": "^1.4.3",
"raf": "^3.1.0",
"showdown": "^1.2.1", "showdown": "^1.2.1",
"uglify-js": "^2.4.14", "uglify-js": "^2.4.14",
"unorm": "^1.3.3" "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