-
Notifications
You must be signed in to change notification settings - Fork 1
/
clanim-min.js
1 lines (1 loc) · 3.43 KB
/
clanim-min.js
1
!function(){function n(n){var e=document.createElement("div");return n.reduce(function(n,t){return void 0!==e.style[t]?t:n},void 0)}function e(n){return n}function t(n){this.name=n,this.setStart=function(e){var t=e.elt[n];return e.$start[n]=t,void 0!==t&&void 0!==e.$end[n]},this.applyCurrent=function(e){e.elt[n]=e.$current[n]}}function r(n,t,r,i){i=i||e,this.name=n,this.setStart=function(e){var t=parseFloat(e.elt.style[n]);return isNaN(t)&&(t=e.$current[n]||r),e.$start[n]=t,void 0!==e.$end[n]},this.applyCurrent=function(e){e.elt.style[n]=i(e.$current[n])+t}}function i(n,t,r,i){i=i||e,this.name=n,this.setStart=function(e){var t=e.$current[n];return void 0===t&&(t=r),e.$start[n]=t,void 0===e.$end[n]&&(e.$end[n]=t),void 0!==t},this.applyCurrent=function(e){var a=e.$current[n];return a!==r&&n+"("+i(a)+t+")"}}function a(n){this.elt=n,this.$current={},this.$pending={}}function o(n){function e(n){if(n.target===r){r.removeEventListener(m,e);var i=t.$end.endCb;t.$end.endCb=void 0,i&&i()}}var t=this,r=this.elt,i=(Date.now()-t.$startTime)/t.$end.duration,a="";if(n){i=1;var s=["all",t.$end.duration+"ms",t.$end.easing.toCSS()];t.$end.delay&&s.push(t.$end.delay+"ms"),a=s.join(" "),t.$end.endCb&&r.addEventListener(m,e)}else if(1>i){if(t.$requestId=window.requestAnimationFrame(o.bind(t,!1)),0>i)return}else t.$end.endCb&&(t.$requestId=window.requestAnimationFrame(t.$end.endCb));var d=t.$end.easing.get(i),u=t.$attributes.reduce(function(n,e){if(1>i){var r=t.$end[e.name]-t.$start[e.name];t.$current[e.name]=t.$start[e.name]+r*d}else t.$current[e.name]=t.$end[e.name];var a=e.applyCurrent(t);return a&&n.push(a),n},[]);u.length&&u.push("translateZ(0)");var c=u.join(" ");r.style[l]=c,r.style[$]=a,t.$end.stepCb&&t.$end.stepCb()}for(var s=["moz","webkit"],d=0;d<s.length&&!window.requestAnimationFrame;++d)window.requestAnimationFrame=window[s[d]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[s[d]+"CancelAnimationFrame"]||window[s[d]+"CancelRequestAnimationFrame"];var u=["WebkitTransform","MozTransform","msTransform","OTransform","transform"],c={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",msTransition:"MSTransitionEnd",OTransition:"oTransitionEnd",transition:"transitionend"},l=n(u),$=n(Object.keys(c)),m=c[$],f=[new t("scrollTop"),new t("scrollLeft"),new r("opacity","",1),new r("zIndex","",0),new i("translateX","px",0,Math.round),new i("translateY","px",0,Math.round),new i("scale","",1),new i("rotate","deg",0)].concat(["width","height","top","right","bottom","left"].map(function(n){return new r(n,"px",0,Math.round)}));f.map(function(n){return n.name}).concat("duration","easing","delay").forEach(function(n){a.prototype[n]=function(e){return this.$pending[n]=e,this}}),a.prototype.start=function(n,e){var t=!1;"boolean"==typeof n&&(t=n,n=arguments[1],e=arguments[2]);var r=this;return r.stop(),r.$start={},r.$end=r.$pending,r.$pending={},r.$attributes=f.filter(function(n){return n.setStart(r)}),r.$end.duration=r.$end.duration||0,r.$end.delay=r.$end.delay||0,r.$end.easing=window.BezierEasing.css[r.$end.easing]||window.BezierEasing.css["ease-out"],r.$end.endCb="function"==typeof n&&n,r.$end.stepCb="function"==typeof e&&e,r.$startTime=Date.now()+r.$end.delay,o.call(r,r.$end.duration&&t),r.elt},a.prototype.stop=function(){window.cancelAnimationFrame(this.$requestId)},Object.defineProperty(window.Element.prototype,"clanim",{get:function(){return Object.defineProperty(this,"clanim",{value:new a(this)}),this.clanim},configurable:!0,writeable:!1})}();