qanimationframe.js

/*
 * Qanimationframe.js - Promisified requestAnimationFrame with Q
 */
/*jslint newcap: true */
(function (definition) {
    if (typeof exports === "object") {
        module.exports = definition();
    } else {
        window.QanimationFrame = definition();
    }
})(function () {
  "use strict";

Import Q

  var Q = window.Q || require("q");

requestAnimationFrame polyfill

  var requestAnimationFrame = (function(){
    return window.requestAnimationFrame       ||
           window.oRequestAnimationFrame      ||
           window.msRequestAnimationFrame     ||
           window.mozRequestAnimationFrame    ||
           window.webkitRequestAnimationFrame ||
           function (callback) {
             window.setTimeout(callback, 1000 / 60);
           };
  })();

QanimationFrame(elt: DOM.Element) => Promise[DOM.Element]

  var QanimationFrame = function (elt) {
    var d = Q.defer();
    requestAnimationFrame(function () {
      d.resolve(elt);
    }, elt);
    return d.promise;
  };

  return QanimationFrame;
});