-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.animatetimeline.min.js
1 lines (1 loc) · 5.29 KB
/
jquery.animatetimeline.min.js
1
!function(t){function e(n,s,a){if(!(this instanceof e))return new e(n,s,a);this.frames={},this.duration=0,this.timeout=null;for(var r,u=0,o=s.length;o>u;u++){if(r=null,s[u].el.jquery?r=s[u].el:n[s[u].el]&&n[s[u].el].jquery?r=n[s[u].el]:n[s[u].el]&&(r=t(n[s[u].el])),!r)throw new Error("Invalid element "+u+":"+s[u].el);this.push(new i(r.get(0),s[u]))}a&&(this.timeout=setTimeout(a,this.getDuration()+e.BUFFER)),this.play()}function n(t){this.steps=[],this.start=t,this.delayTimeout=null,this.runTimeout=null,this.isRunning=!1}function i(t,e){if(this.element=t,this.start=e.start,this.duration=e.duration,this.props=e.props,this.easing=e.easing,!this.element)throw new Error("Invalid Step")}function s(e,n,i,s){if(p){f&&(n=u(n)),r(e,c(n),i,s);for(var a in n)e.style[a]=n[a]}else i?t(e).animate(n,{duration:i,easing:s||"easeOutQuad",queue:"animatetimeline"}):t(e).css(n);"block"===n.display&&t.noop(t(e).offset().left)}function a(t){p?clearTransitions(t.get(0),props):t.stop("animatetimeline",!0,!0)}function r(e,n,i,s){var a=t.data(e,"transitions.animatetimeline")||{};return 2===arguments.length&&"string"==typeof n?r[prop]:(n?(n="string"==typeof n?[n]:n,t.map(n,function(t){a[t]=i?(t===f?m:t)+" "+i+"ms "+(y[s]?"cubic-bezier("+y[s]+")":"ease-in-out"):null})):a={},e.style[p]=h(a).join(","),t.data(e,"transitions.animatetimeline",a),a)}function u(t){var e={};for(var n in t)"left"!==n&&"top"!==n&&(e[n]=t[n]);return t.left&&t.top?(t.left=t.left,t.top=t.top,e[f]="translate("+t.left+","+t.top+")"):t.left?e[f]="translateX("+t.left+")":t.top&&(e[f]="translateY("+t.left+")"),e}function o(t){try{var e=document.createElement("div");if("undefined"!=typeof e.style[t])return t;t=t.charAt(0).toUpperCase()+t.slice(1);for(var n=["webkit","Moz","ms","O"],i=0;i<n.length;i++)if("undefined"!=typeof e.style[n[i]+t])return n[i]+t}catch(s){}return""}function l(t){return t&&"-"+t.replace(/([A-Z])/g,function(t,e){return"-"+e.toLowerCase()})}function h(t){var e=[];for(var n in t)t[n]&&e.push(t[n]);return e}t.fn.animatetimeline=function(n,i,s){if(this.length>1)return this.each(function(){t(this).animatetimeline(n,i,s)});if(1===arguments.length&&"string"==typeof n){var a=this.data("animatetimeline"),r=Array.prototype.slice.call(arguments,1);if(a)return a[n].apply(a,r)}(1===arguments.length||2===arguments.length&&"function"==typeof i)&&(s=arguments[1],i=arguments[0],n={});for(var u in n)n[u]&&n[u].jquery&&(n[u]=this.find(n[u]));return n.el||(n.el=this),this.data("animatetimeline",new e(n,i,s)),this},t.fn.animatetimeline_animate=function(t,e,n){return this.each(function(){s(this,t,e,n)})},t.fn.animatetimeline_transition=function(t,e,n){return this.each(function(){r(this,t,e,n)})},t.animatetimeline=e,e.Frame=n,e.Step=i,e.animate=s,e.stopAnimate=a,e.transition=r,e.prefixed=o,e.CSS_EASING=y,e.BUFFER=60,e.prototype.play=function(){for(var t in this.frames)this.frames[t].play()},e.prototype.stop=function(){for(var t in this.frames)this.frames[t].stop();null!==this.timeout&&(clearTimeout(this.timeout),this.timeout=null)},e.prototype.push=function(t){this.frames[t.start]||(this.frames[t.start]=new n(t.start)),this.frames[t.start].push(t)},e.prototype.getDuration=function(){var t=0;for(var e in this.frames)t=Math.max(t,this.frames[e].getTotalTime());return t},n.prototype.push=function(t){this.steps.push(t)},n.prototype.play=function(){var t=this;this.delayTimeout=setTimeout(function(){t.run(),t.delayTimeout=null},this.start)},n.prototype.stop=function(){if(null!==this.delayTimeout&&(clearTimeout(this.delayTimeout),this.delayTimeout=null),null!==this.runTimeout&&(clearTimeout(this.runTimeout),this.runTimeout=null),this.isRunning){for(var t=0,e=this.steps.length;e>t;t++)this.steps[t].stop();this.isRunning=!1}},n.prototype.run=function(){for(var t=this,e=0,n=this.steps.length;n>e;e++)this.steps[e].run();this.isRunning=!0,this.runTimeout=setTimeout(function(){t.isRunning=!1,t.runTimeout=null})},n.prototype.getDuration=function(){for(var t=0,e=0,n=this.steps.length;n>e;e++)t=Math.max(t,this.steps[e].duration||0);return t},n.prototype.getTotalTime=function(){return this.start+this.getDuration()},i.prototype.run=function(){s(this.element,this.props,this.duration,this.easing)},i.prototype.stop=function(){a(this.element,this.props)};var f=o("transform"),p=o("transition"),m=l(f),c=Object.keys||function(t){var e=[];for(var n in t)e.push(n);return e},y={ease:"0.250, 0.100, 0.250, 1.000",easeInQuad:"0.550, 0.085, 0.680, 0.530",easeInCubic:"0.550, 0.055, 0.675, 0.190",easeInQuart:"0.895, 0.030, 0.685, 0.220",easeInQuint:"0.755, 0.050, 0.855, 0.060",easeInSine:"0.470, 0.000, 0.745, 0.715",easeInExpo:"0.950, 0.050, 0.795, 0.035",easeInCirc:"0.600, 0.040, 0.980, 0.335",easeInBack:"0.600, -0.280, 0.735, 0.045",easeOutQuad:"0.250, 0.460, 0.450, 0.940",easeOutCubic:"0.215, 0.610, 0.355, 1.000",easeOutQuart:"0.165, 0.840, 0.440, 1.000",easeOutQuint:"0.230, 1.000, 0.320, 1.000",easeOutSine:"0.390, 0.575, 0.565, 1.000",easeOutExpo:"0.190, 1.000, 0.220, 1.000",easeOutCirc:"0.075, 0.820, 0.165, 1.000",easeOutBack:"0.175, 0.885, 0.320, 1.275",easeInOutQuad:"0.455, 0.030, 0.515, 0.955",easeInOutCubic:"0.645, 0.045, 0.355, 1.000",easeInOutQuart:"0.770, 0.000, 0.175, 1.000",easeInOutQuint:"0.860, 0.000, 0.070, 1.000",easeInOutSine:"0.445, 0.050, 0.550, 0.950",easeInOutExpo:"1.000, 0.000, 0.000, 1.000",easeInOutCirc:"0.785, 0.135, 0.150, 0.860",easeInOutBack:"0.680, -0.550, 0.265, 1.550"}}(jQuery);