ded/morpheus — pull request #37 by rvagg (2012-12-09 11:06:20+00:00)
Title: rework framing method with proper feature detect

A.K.A. uber-feature-detect

Further to the discussion @ #36 (/cc @danro)

In summary I've turned `frame(fn)` into a function that takes a render-function and puts it into the animation queue (or makes a queue if required). The function is then called with 2 arguments, (1) is the time-delta from the start of the animation, and (2) a callback that can be used to resubmit the render-function to the same queue.

When first loaded, `frame` will be the most basic version that does `setTimeout` and delta-calculation itself; meanwhile it runs a feature-detect on a `requestAnimationFrame` to see what kind of argument it provides. The alternatives allowed for are (1) standard epoch-`Date`-based timestamp and (2) `performance.now()`-based timestamp. If it finds an `rAF` that works like this, it replaces `frame` with an appropriate `rAF`-based alternative.

This should be pretty future-proof as the fallback should always work. However there may be a need to enhance it in future. e.g. if Mozilla's `animationStartTime` gets traction or if other browsers start using `performance.now()`-based timestamps and vendor-prefix `now` (note though that that won't break this implementation, they'll just fall back to the basic implementation).

I've also imported Bonzo's .jshintrc and I've added a test to ensure that `duration` is roughly obeyed, this should help detect shortcutting.