Permalink
Browse files

added requestAnimationFrame

  • Loading branch information...
1 parent 22206fc commit 7638b4b988be6e640bb5919300c6a63b61bc2590 @WebReflection committed Jun 22, 2015
Showing with 107 additions and 4 deletions.
  1. +1 −1 README.md
  2. +0 −1 bower.json
  3. +1 −1 build/dom4.js
  4. +43 −0 build/dom4.max.js
  5. +1 −1 package.json
  6. +43 −0 src/dom4.js
  7. +18 −0 test/dom4.js
View
@@ -7,7 +7,7 @@ DOM4
Many thanks to [cdnjs](http://www.cdnjs.com) for hosting this script. Following an example on how to include it.
```html
<script
- src="//cdnjs.cloudflare.com/ajax/libs/dom4/1.4.5/dom4.js"
+ src="//cdnjs.cloudflare.com/ajax/libs/dom4/1.4.6/dom4.js"
>/* DOM4 */</script>
```
View
@@ -1,7 +1,6 @@
{
"name": "DOM4",
"description": "new DOM Level 4 entries",
- "version": "1.4.5",
"main": "build/dom4.max.js",
"ignore": [
"test",
View
@@ -1,2 +1,2 @@
/*! (C) WebReflection Mit Style License */
-(function(e){"use strict";function t(){return f.createDocumentFragment()}function n(e){if(e.length===1)return r(e[0]);for(var n=t(),i=O.call(e),s=0;s<e.length;s++)n.appendChild(r(i[s]));return n}function r(e){return typeof e=="string"?f.createTextNode(e):e}for(var i,s,o,u,a,f=e.document,l=Object.defineProperty||function(e,t,n){e.__defineGetter__(t,n.get)},c=[].indexOf||function(t){var n=this.length;while(n--)if(this[n]===t)break;return n},h=function(e){if(!e)throw"SyntaxError";if(g.test(e))throw"InvalidCharacterError";return e},p=function(e){var t=e.className,n=typeof t=="object",r=(n?t.baseVal:t).replace(m,"");r.length&&A.push.apply(this,r.split(g)),this._isSVG=n,this._=e},d={get:function(){return new p(this)},set:function(){}},v="dom4-tmp-".concat(Math.random()*+(new Date)).replace(".","-"),m=/^\s+|\s+$/g,g=/\s+/,y=" ",b="classList",w=function(t,n){if(this.contains(t))n||this.remove(t);else if(n===undefined||n)n=!0,this.add(t);return!!n},E=e.DocumentFragment,S=(e.Element||e.Node||e.HTMLElement).prototype,x=e.ShadowRoot,T=e.SVGElement,N=/ /g,C="\\ ",k=function(e){var t=e==="querySelectorAll";return function(n){var r,i,s,o,u,a,f=this.parentNode;if(f){for(s=this.getAttribute("id")||v,o=s===v?s:s.replace(N,C),a=n.split(","),i=0;i<a.length;i++)a[i]="#"+o+" "+a[i];n=a.join(",")}s===v&&this.setAttribute("id",s),u=(f||this)[e](n),s===v&&this.removeAttribute("id");if(t){i=u.length,r=new Array(i);while(i--)r[i]=u[i]}else r=u;return r}},L=function(e){"query"in e||(e.query=S.query),"queryAll"in e||(e.queryAll=S.queryAll)},A=["matches",S.matchesSelector||S.webkitMatchesSelector||S.khtmlMatchesSelector||S.mozMatchesSelector||S.msMatchesSelector||S.oMatchesSelector||function(t){var n=this.parentNode;return!!n&&-1<c.call(n.querySelectorAll(t),this)},"closest",function(t){var n=this,r;while((r=n&&n.matches)&&!n.matches(t))n=n.parentNode;return r?n:null},"prepend",function(){var t=this.firstChild,r=n(arguments);t?this.insertBefore(r,t):this.appendChild(r)},"append",function(){this.appendChild(n(arguments))},"before",function(){var t=this.parentNode;t&&t.insertBefore(n(arguments),this)},"after",function(){var t=this.parentNode,r=this.nextSibling,i=n(arguments);t&&(r?t.insertBefore(i,r):t.appendChild(i))},"replace",function(){this.replaceWith.apply(this,arguments)},"replaceWith",function(){var t=this.parentNode;t&&t.replaceChild(n(arguments),this)},"remove",function(){var t=this.parentNode;t&&t.removeChild(this)},"query",k("querySelector"),"queryAll",k("querySelectorAll")],O=A.slice,M=A.length;M;M-=2)s=A[M-2],s in S||(S[s]=A[M-1]);L(f);if(E)L(E.prototype);else try{L(t().constructor.prototype)}catch(_){}x&&L(x.prototype),f.createElement("a").matches("a")||(S[s]=function(e){return function(n){return e.call(this.parentNode?this:t().appendChild(this),n)}}(S[s])),p.prototype={length:0,add:function(){for(var t=0,n;t<arguments.length;t++)n=arguments[t],this.contains(n)||A.push.call(this,s);this._isSVG?this._.setAttribute("class",""+this):this._.className=""+this},contains:function(e){return function(n){return M=e.call(this,s=h(n)),-1<M}}([].indexOf||function(e){M=this.length;while(M--&&this[M]!==e);return M}),item:function(t){return this[t]||null},remove:function(){for(var t=0,n;t<arguments.length;t++)n=arguments[t],this.contains(n)&&A.splice.call(this,M,1);this._isSVG?this._.setAttribute("class",""+this):this._.className=""+this},toggle:w,toString:function D(){return A.join.call(this,y)}},T&&!(b in T.prototype)&&l(T.prototype,b,d),b in f.documentElement?(u=f.createElement("div")[b],u.add("a","b","a"),"a b"!=u&&(o=u.constructor.prototype,"add"in o||(o=e.TemporaryTokenList.prototype),a=function(e){return function(){var t=0;while(t<arguments.length)e.call(this,arguments[t++])}},o.add=a(o.add),o.remove=a(o.remove),o.toggle=w)):l(S,b,d),"head"in f||l(f,"head",{get:function(){return i||(i=f.getElementsByTagName("head")[0])}});try{new e.CustomEvent("?")}catch(_){e.CustomEvent=function(e,t){function n(n,i){var s=f.createEvent(e);if(typeof n!="string")throw new Error("An event name must be provided");return e=="Event"&&(s.initCustomEvent=r),i==null&&(i=t),s.initCustomEvent(n,i.bubbles,i.cancelable,i.detail),s}function r(e,t,n,r){this.initEvent(e,t,n),this.detail=r}return n}(e.CustomEvent?"CustomEvent":"Event",{bubbles:!1,cancelable:!1,detail:null})}})(window);
+(function(e){"use strict";function t(){return f.createDocumentFragment()}function n(e){if(e.length===1)return r(e[0]);for(var n=t(),i=O.call(e),s=0;s<e.length;s++)n.appendChild(r(i[s]));return n}function r(e){return typeof e=="string"?f.createTextNode(e):e}for(var i,s,o,u,a,f=e.document,l=Object.defineProperty||function(e,t,n){e.__defineGetter__(t,n.get)},c=[].indexOf||function(t){var n=this.length;while(n--)if(this[n]===t)break;return n},h=function(e){if(!e)throw"SyntaxError";if(g.test(e))throw"InvalidCharacterError";return e},p=function(e){var t=e.className,n=typeof t=="object",r=(n?t.baseVal:t).replace(m,"");r.length&&A.push.apply(this,r.split(g)),this._isSVG=n,this._=e},d={get:function(){return new p(this)},set:function(){}},v="dom4-tmp-".concat(Math.random()*+(new Date)).replace(".","-"),m=/^\s+|\s+$/g,g=/\s+/,y=" ",b="classList",w=function(t,n){if(this.contains(t))n||this.remove(t);else if(n===undefined||n)n=!0,this.add(t);return!!n},E=e.DocumentFragment,S=(e.Element||e.Node||e.HTMLElement).prototype,x=e.ShadowRoot,T=e.SVGElement,N=/ /g,C="\\ ",k=function(e){var t=e==="querySelectorAll";return function(n){var r,i,s,o,u,a,f=this.parentNode;if(f){for(s=this.getAttribute("id")||v,o=s===v?s:s.replace(N,C),a=n.split(","),i=0;i<a.length;i++)a[i]="#"+o+" "+a[i];n=a.join(",")}s===v&&this.setAttribute("id",s),u=(f||this)[e](n),s===v&&this.removeAttribute("id");if(t){i=u.length,r=new Array(i);while(i--)r[i]=u[i]}else r=u;return r}},L=function(e){"query"in e||(e.query=S.query),"queryAll"in e||(e.queryAll=S.queryAll)},A=["matches",S.matchesSelector||S.webkitMatchesSelector||S.khtmlMatchesSelector||S.mozMatchesSelector||S.msMatchesSelector||S.oMatchesSelector||function(t){var n=this.parentNode;return!!n&&-1<c.call(n.querySelectorAll(t),this)},"closest",function(t){var n=this,r;while((r=n&&n.matches)&&!n.matches(t))n=n.parentNode;return r?n:null},"prepend",function(){var t=this.firstChild,r=n(arguments);t?this.insertBefore(r,t):this.appendChild(r)},"append",function(){this.appendChild(n(arguments))},"before",function(){var t=this.parentNode;t&&t.insertBefore(n(arguments),this)},"after",function(){var t=this.parentNode,r=this.nextSibling,i=n(arguments);t&&(r?t.insertBefore(i,r):t.appendChild(i))},"replace",function(){this.replaceWith.apply(this,arguments)},"replaceWith",function(){var t=this.parentNode;t&&t.replaceChild(n(arguments),this)},"remove",function(){var t=this.parentNode;t&&t.removeChild(this)},"query",k("querySelector"),"queryAll",k("querySelectorAll")],O=A.slice,M=A.length;M;M-=2)s=A[M-2],s in S||(S[s]=A[M-1]);L(f);if(E)L(E.prototype);else try{L(t().constructor.prototype)}catch(_){}x&&L(x.prototype),f.createElement("a").matches("a")||(S[s]=function(e){return function(n){return e.call(this.parentNode?this:t().appendChild(this),n)}}(S[s])),p.prototype={length:0,add:function(){for(var t=0,n;t<arguments.length;t++)n=arguments[t],this.contains(n)||A.push.call(this,s);this._isSVG?this._.setAttribute("class",""+this):this._.className=""+this},contains:function(e){return function(n){return M=e.call(this,s=h(n)),-1<M}}([].indexOf||function(e){M=this.length;while(M--&&this[M]!==e);return M}),item:function(t){return this[t]||null},remove:function(){for(var t=0,n;t<arguments.length;t++)n=arguments[t],this.contains(n)&&A.splice.call(this,M,1);this._isSVG?this._.setAttribute("class",""+this):this._.className=""+this},toggle:w,toString:function D(){return A.join.call(this,y)}},T&&!(b in T.prototype)&&l(T.prototype,b,d),b in f.documentElement?(u=f.createElement("div")[b],u.add("a","b","a"),"a b"!=u&&(o=u.constructor.prototype,"add"in o||(o=e.TemporaryTokenList.prototype),a=function(e){return function(){var t=0;while(t<arguments.length)e.call(this,arguments[t++])}},o.add=a(o.add),o.remove=a(o.remove),o.toggle=w)):l(S,b,d),"head"in f||l(f,"head",{get:function(){return i||(i=f.getElementsByTagName("head")[0])}}),function(){for(var t,n=e.requestAnimationFrame,r=e.cancelAnimationFrame,i=["o","ms","moz","webkit"],s=i.length;!r&&s--;)n=n||e[i[s]+"RequestAnimationFrame"],r=e[i[s]+"CancelAnimationFrame"]||e[i[s]+"CancelRequestAnimationFrame"];r||(n?(t=n,n=function(e){var n=!0;return t(function(){n&&e.apply(this,arguments)}),function(){n=!1}},r=function(e){e()}):(n=function(e){return setTimeout(e,15,15)},r=function(e){clearTimeout(e)})),e.requestAnimationFrame=n,e.cancelAnimationFrame=r}();try{new e.CustomEvent("?")}catch(_){e.CustomEvent=function(e,t){function n(n,i){var s=f.createEvent(e);if(typeof n!="string")throw new Error("An event name must be provided");return e=="Event"&&(s.initCustomEvent=r),i==null&&(i=t),s.initCustomEvent(n,i.bubbles,i.cancelable,i.detail),s}function r(e,t,n,r){this.initEvent(e,t,n),this.detail=r}return n}(e.CustomEvent?"CustomEvent":"Event",{bubbles:!1,cancelable:!1,detail:null})}})(window);
View
@@ -375,6 +375,49 @@ THE SOFTWARE.
});
}
+ // requestAnimationFrame partial polyfill
+ (function () {
+ for (var
+ raf,
+ rAF = window.requestAnimationFrame,
+ cAF = window.cancelAnimationFrame,
+ prefixes = ['o', 'ms', 'moz', 'webkit'],
+ i = prefixes.length;
+ !cAF && i--;
+ ) {
+ rAF = rAF || window[prefixes[i] + 'RequestAnimationFrame'];
+ cAF = window[prefixes[i] + 'CancelAnimationFrame'] ||
+ window[prefixes[i] + 'CancelRequestAnimationFrame'];
+ }
+ if (!cAF) {
+ // some FF apparently implemented rAF but no cAF
+ if (rAF) {
+ raf = rAF;
+ rAF = function (callback) {
+ var goOn = true;
+ raf(function () {
+ if (goOn) callback.apply(this, arguments);
+ });
+ return function () {
+ goOn = false;
+ };
+ };
+ cAF = function (id) {
+ id();
+ };
+ } else {
+ rAF = function (callback) {
+ return setTimeout(callback, 15, 15);
+ };
+ cAF = function (id) {
+ clearTimeout(id);
+ };
+ }
+ }
+ window.requestAnimationFrame = rAF;
+ window.cancelAnimationFrame = cAF;
+ }());
+
// http://www.w3.org/TR/dom/#customevent
try{new window.CustomEvent('?');}catch(o_O){
window.CustomEvent = function(
View
@@ -2,7 +2,7 @@
"name": "dom4",
"title": "DOM4",
"description": "a fully tested and covered polyfill for new DOM Level 4 entries",
- "version": "1.4.5",
+ "version": "1.4.6",
"main": "build/dom4.js",
"homepage": "https://github.com/WebReflection/dom4",
"author": {
View
@@ -353,6 +353,49 @@
});
}
+ // requestAnimationFrame partial polyfill
+ (function () {
+ for (var
+ raf,
+ rAF = window.requestAnimationFrame,
+ cAF = window.cancelAnimationFrame,
+ prefixes = ['o', 'ms', 'moz', 'webkit'],
+ i = prefixes.length;
+ !cAF && i--;
+ ) {
+ rAF = rAF || window[prefixes[i] + 'RequestAnimationFrame'];
+ cAF = window[prefixes[i] + 'CancelAnimationFrame'] ||
+ window[prefixes[i] + 'CancelRequestAnimationFrame'];
+ }
+ if (!cAF) {
+ // some FF apparently implemented rAF but no cAF
+ if (rAF) {
+ raf = rAF;
+ rAF = function (callback) {
+ var goOn = true;
+ raf(function () {
+ if (goOn) callback.apply(this, arguments);
+ });
+ return function () {
+ goOn = false;
+ };
+ };
+ cAF = function (id) {
+ id();
+ };
+ } else {
+ rAF = function (callback) {
+ return setTimeout(callback, 15, 15);
+ };
+ cAF = function (id) {
+ clearTimeout(id);
+ };
+ }
+ }
+ window.requestAnimationFrame = rAF;
+ window.cancelAnimationFrame = cAF;
+ }());
+
// http://www.w3.org/TR/dom/#customevent
try{new window.CustomEvent('?');}catch(o_O){
window.CustomEvent = function(
View
@@ -434,6 +434,24 @@ wru.test([
wru.assert('DocumentFragment#query', df.query);
wru.assert('DocumentFragment#queryAll', df.queryAll);
}
+ }, {
+ name: 'requestAnimationFrame',
+ test: function () {
+ requestAnimationFrame(wru.async(function () {
+ wru.assert('OK');
+ }));
+ }
+ }, {
+ name: 'cancelAnimationFrame',
+ test: function () {
+ var called = false, ok = wru.async(function () {
+ wru.assert('never executed', !called);
+ });
+ cancelAnimationFrame(requestAnimationFrame(function () {
+ called = true;
+ }));
+ setTimeout(ok, 250);
+ }
}
].concat(
typeof ShadowRoot === 'function' ?

0 comments on commit 7638b4b

Please sign in to comment.