From e3eb1b8692f6f53c1b4a96c094c47d41d7e505fa Mon Sep 17 00:00:00 2001 From: Tomas Sardyha Date: Thu, 7 Aug 2014 22:16:58 +0200 Subject: [PATCH] Release 2.2.2 --- dist/jquery.motio.js | 63 ++++++++++++++++++++-------------------- dist/jquery.motio.min.js | 17 ++++++----- dist/motio.js | 63 ++++++++++++++++++++-------------------- dist/motio.min.js | 17 ++++++----- meta.json | 4 +-- motio.jquery.json | 2 +- 6 files changed, 83 insertions(+), 83 deletions(-) diff --git a/dist/jquery.motio.js b/dist/jquery.motio.js index b0bf3d6..54ab6f2 100644 --- a/dist/jquery.motio.js +++ b/dist/jquery.motio.js @@ -1,6 +1,6 @@ /*! - * Motio 2.2.1 - 18th Apr 2013 - * https://github.com/Darsain/motio + * motio 2.2.2 - 7th Aug 2014 + * https://github.com/darsain/motio * * Licensed under the MIT license. * http://opensource.org/licenses/MIT @@ -38,6 +38,15 @@ } }()); + // Returns time in as precise manner as possible + var getTime = (function () { + var perf = w.performance; + if (perf && perf.now) return perf.now.bind(perf); + return function () { + return +new Date(); + }; + }()); + /** * Motio. * @@ -58,7 +67,7 @@ var callbacks = {}; var animation = {}; var active = 0; - var pos, bgPos, lastPos, frameID, renderID, i, l; + var pos, bgPos, lastPos, frameID, i, l; // Exposed properties self.element = element; @@ -73,10 +82,9 @@ * @return {Object} Motio instance. */ self.pause = function () { - // frameID can be timeout, or animationFrame ID cAF(frameID); - clearTimeout(frameID); frameID = 0; + animation.lastFrame = 0; if (!self.isPaused) { self.isPaused = true; trigger('pause'); @@ -111,7 +119,7 @@ if (!frameID) { self.isPaused = false; trigger('play'); - requestRender(); + frameID = rAF(render); } } @@ -240,8 +248,14 @@ * @return {Void} */ function render() { - // Reset renderID - renderID = 0; + frameID = rAF(render); + var time = getTime(); + + // Don't render when it's not time for next frame yet + if (o.fps < 60 && animation.lastFrame && animation.lastFrame + (1000 / o.fps) + 1 > time) return; + + animation.lastFrame = time; + positionTick(); // Prepare new background position bgPos = isPan ? Math.round(pos.x) + 'px ' + Math.round(pos.y) + 'px' : frames[active]; @@ -264,29 +278,6 @@ } } - /** - * Render rAF wrapper. - * - * @return {Int} Animation frame index. - */ - function requestRender() { - if (!(animation.finite && animation.to === active)) { - if (animation.immediate) { - frameID = 0; - } else { - if (o.fps >= 60) { - frameID = rAF(requestRender); - } else { - frameID = setTimeout(requestRender, 1000 / o.fps); - } - } - positionTick(); - if (!renderID) { - renderID = rAF(render); - } - } - } - /** * Update one of the dynamic option properties. * @@ -465,7 +456,15 @@ * @return {String} */ function type(value) { - return Object.prototype.toString.call(value).match(/\s([a-z]+)/i)[1].toLowerCase(); + if (value == null) { + return String(value); + } + if (typeof value === 'object' || typeof value === 'function') { + return (value instanceof w.NodeList && 'nodelist') || + (value instanceof w.HTMLCollection && 'htmlcollection') || + Object.prototype.toString.call(value).match(/\s([a-z]+)/i)[1].toLowerCase(); + } + return typeof value; } /** diff --git a/dist/jquery.motio.min.js b/dist/jquery.motio.min.js index b9750be..d9bf2bd 100644 --- a/dist/jquery.motio.min.js +++ b/dist/jquery.motio.min.js @@ -1,8 +1,9 @@ -/*! Motio 2.2.1 - 18th Apr 2013 | https://github.com/Darsain/motio */ -(function(f,l){function w(u,p){function k(c){b.reversed=c;x||(a.isPaused=!1,C("play"),D())}function v(){E=0;F=z?Math.round(h.x)+"px "+Math.round(h.y)+"px":r[m];F!==H&&(u.style.backgroundPosition=H=F);C("frame");b.finite&&b.to===m&&(a.pause(),"function"===j(b.callback)&&b.callback.call(a))}function D(){b.finite&&b.to===m||(x=b.immediate?0:60<=d.fps?y(D):setTimeout(D,1E3/d.fps),z?(h.x+=d.speedX/d.fps,h.y+=d.speedY/d.fps,d.bgWidth&&Math.abs(h.x)>d.bgWidth&&(h.x%=d.bgWidth),d.bgHeight&&Math.abs(h.y)> -d.bgHeight&&(h.y%=d.bgHeight)):(b.finite?m=b.immediate?b.to:m+(m>b.to?-1:1):b.reversed?0>=--m&&(m=r.length-1):++m>=r.length&&(m=0),a.frame=m),E||(E=y(v)))}function I(a,g){s=0;for(A=q[a].length;sc||c>=r.length)return a;"function"===j(g)&&(e=g,g=!1);if(c===m)if(0===c)m=r.length;else if(c===r.length-1)m=-1;else return"function"===j(e)&&e.call(a),a.pause(),a;b.finite=!0;b.to=c;b.immediate=!!g;b.callback=e;k();return a};a.set=function(c,g){d[c]=g;return a};a.on=function(c,g){if("object"===j(c))for(var e in c){if(c.hasOwnProperty(e))a.on(e,c[e])}else if("function"===j(g)){e=c.split(" ");for(var b=0,d=e.length;bg.fps&&d.lastFrame&&d.lastFrame+1E3/g.fps+1>c||(d.lastFrame=c,x?(h.x+=g.speedX/g.fps,h.y+=g.speedY/g.fps,g.bgWidth&&Math.abs(h.x)>g.bgWidth&&(h.x%=g.bgWidth),g.bgHeight&&Math.abs(h.y)>g.bgHeight&&(h.y%=g.bgHeight)):(d.finite?n=d.immediate?d.to:n+(n>d.to?-1:1):d.reversed?0>=--n&&(n=r.length-1):++n>=r.length&&(n=0),b.frame=n),B=x?Math.round(h.x)+"px "+Math.round(h.y)+"px":r[n], +B!==D&&(a.style.backgroundPosition=D=B),A("frame"),d.finite&&d.to===n&&(b.pause(),"function"===k(d.callback)&&d.callback.call(b)))}function E(c,b){u=0;for(y=p[c].length;uc||c>=r.length)return b;"function"===k(a)&&(f=a,a=!1);if(c===n)if(0===c)n=r.length;else if(c===r.length- +1)n=-1;else return"function"===k(f)&&f.call(b),b.pause(),b;d.finite=!0;d.to=c;d.immediate=!!a;d.callback=f;m();return b};b.set=function(c,a){g[c]=a;return b};b.on=function(c,a){if("object"===k(c))for(var f in c){if(c.hasOwnProperty(f))b.on(f,c[f])}else if("function"===k(a)){f=c.split(" ");for(var d=0,e=f.length;d time) return; + + animation.lastFrame = time; + positionTick(); // Prepare new background position bgPos = isPan ? Math.round(pos.x) + 'px ' + Math.round(pos.y) + 'px' : frames[active]; @@ -264,29 +278,6 @@ } } - /** - * Render rAF wrapper. - * - * @return {Int} Animation frame index. - */ - function requestRender() { - if (!(animation.finite && animation.to === active)) { - if (animation.immediate) { - frameID = 0; - } else { - if (o.fps >= 60) { - frameID = rAF(requestRender); - } else { - frameID = setTimeout(requestRender, 1000 / o.fps); - } - } - positionTick(); - if (!renderID) { - renderID = rAF(render); - } - } - } - /** * Update one of the dynamic option properties. * @@ -465,7 +456,15 @@ * @return {String} */ function type(value) { - return Object.prototype.toString.call(value).match(/\s([a-z]+)/i)[1].toLowerCase(); + if (value == null) { + return String(value); + } + if (typeof value === 'object' || typeof value === 'function') { + return (value instanceof w.NodeList && 'nodelist') || + (value instanceof w.HTMLCollection && 'htmlcollection') || + Object.prototype.toString.call(value).match(/\s([a-z]+)/i)[1].toLowerCase(); + } + return typeof value; } /** diff --git a/dist/motio.min.js b/dist/motio.min.js index e7393c6..9518f6a 100644 --- a/dist/motio.min.js +++ b/dist/motio.min.js @@ -1,8 +1,9 @@ -/*! Motio 2.2.1 - 18th Apr 2013 | https://github.com/Darsain/motio */ -(function(p,J){function w(j,n){function G(c){b.reversed=c;s||(a.isPaused=!1,B("play"),C())}function t(){D=0;E=x?Math.round(g.x)+"px "+Math.round(g.y)+"px":q[h];E!==H&&(j.style.backgroundPosition=H=E);B("frame");b.finite&&b.to===h&&(a.pause(),"function"===l(b.callback)&&b.callback.call(a))}function C(){b.finite&&b.to===h||(s=b.immediate?0:60<=d.fps?y(C):setTimeout(C,1E3/d.fps),x?(g.x+=d.speedX/d.fps,g.y+=d.speedY/d.fps,d.bgWidth&&Math.abs(g.x)>d.bgWidth&&(g.x%=d.bgWidth),d.bgHeight&&Math.abs(g.y)> -d.bgHeight&&(g.y%=d.bgHeight)):(b.finite?h=b.immediate?b.to:h+(h>b.to?-1:1):b.reversed?0>=--h&&(h=q.length-1):++h>=q.length&&(h=0),a.frame=h),D||(D=y(t)))}function v(a,f){r=0;for(z=m[a].length;rc||c>=q.length)return a;"function"===l(f)&&(e=f,f=!1);if(c===h)if(0===c)h=q.length;else if(c===q.length-1)h=-1;else return"function"===l(e)&&e.call(a),a.pause(),a;b.finite=!0;b.to=c;b.immediate=!!f;b.callback=e;G();return a};a.set=function(c,f){d[c]=f;return a};a.on=function(c,f){if("object"===l(c))for(var e in c){if(c.hasOwnProperty(e))a.on(e,c[e])}else if("function"===l(f)){e=c.split(" ");for(var b=0,d=e.length;be.fps&&d.lastFrame&&d.lastFrame+1E3/e.fps+1>c||(d.lastFrame=c,v?(g.x+=e.speedX/e.fps,g.y+=e.speedY/e.fps,e.bgWidth&&Math.abs(g.x)>e.bgWidth&&(g.x%=e.bgWidth),e.bgHeight&&Math.abs(g.y)>e.bgHeight&&(g.y%=e.bgHeight)):(d.finite?m=d.immediate?d.to:m+(m>d.to?-1:1):d.reversed?0>=--m&&(m=q.length-1):++m>=q.length&&(m=0),b.frame=m),y=v?Math.round(g.x)+"px "+Math.round(g.y)+"px":q[m], +y!==A&&(a.style.backgroundPosition=A=y),x("frame"),d.finite&&d.to===m&&(b.pause(),"function"===p(d.callback)&&d.callback.call(b)))}function B(c,b){r=0;for(w=n[c].length;rc||c>=q.length)return b;"function"===p(a)&&(f=a,a=!1);if(c===m)if(0===c)m=q.length;else if(c===q.length- +1)m=-1;else return"function"===p(f)&&f.call(b),b.pause(),b;d.finite=!0;d.to=c;d.immediate=!!a;d.callback=f;k();return b};b.set=function(c,a){e[c]=a;return b};b.on=function(c,a){if("object"===p(c))for(var f in c){if(c.hasOwnProperty(f))b.on(f,c[f])}else if("function"===p(a)){f=c.split(" ");for(var d=0,e=f.length;d