forked from benbarnett/jquery-animate-enhanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.animate-enhanced.min.js
19 lines (18 loc) · 5.32 KB
/
jquery.animate-enhanced.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/************************************************
jquery.animate-enhanced plugin v0.63
Author: www.benbarnett.net || @benpbarnett
Copyright (c) 2010 Ben Barnett
Licensed under the MIT license
http://www.opensource.org/licenses/mit-license.php
*************************************************/
(function(o,x,y){function B(a,d,k,i){var j=C.exec(d),f=a.css(k)==="auto"?0:a.css(k);f=typeof f=="string"?v(f):f;typeof d=="string"&&v(d);i=i===true?0:f;var g=a.is(":hidden"),b=a.translation();if(k=="left")i=parseInt(f,10)+b.x;if(k=="top")i=parseInt(f,10)+b.y;if(!j&&d=="show"){i=1;g&&a.css({display:"block",opacity:0})}if(j){a=parseFloat(j[2]);if(j[1])a=(j[1]==="-="?-1:1)*a+parseInt(i,10);return a}else return i}function D(a,d,k,i,j,f,g){var b=a.data("cssEnhanced")||jQuery.extend(true,{},E),c=j;if(d==
"left"||d=="top"){var l=b.meta,r=v(a.css(d))||0;c=f?j-r:j;l[d]=c;l[d+"_o"]=a.css(d)=="auto"?0+c:r+c||0;b.meta=l;if(f&&c===0){c=0-l[d+"_o"];l[d]=c;l[d+"_o"]=0}}return a.data("cssEnhanced",F(b,d,k,i,c,f,g))}function F(a,d,k,i,j,f,g){a=typeof a==="undefined"?{}:a;a.secondary=typeof a.secondary==="undefined"?{}:a.secondary;for(var b=e.length-1;b>=0;b--){if(typeof a[e[b]+"transition-property"]==="undefined")a[e[b]+"transition-property"]="";a[e[b]+"transition-property"]+=", "+(f===true?e[b]+"transform":
d);a[e[b]+"transition-duration"]=k+"ms";a[e[b]+"transition-timing-function"]=i;a.secondary[f===true?e[b]+"transform":d]=f===true?g===true&&G?"translate3d("+a.meta.left+"px,"+a.meta.top+"px,0)":"translate("+a.meta.left+"px,"+a.meta.top+"px)":j}return a}function p(a){for(var d in a)return false;return true}function v(a){return parseFloat(a.replace(/px/i,""))}var H=["top","left","opacity","height","width"],e=["","-webkit-","-moz-","-o-"],I=["avoidTransforms","useTranslate3d","leaveTransforms"],C=/^([+-]=)?([\d+-.]+)(.*)$/,
J=/([A-Z])/g,E={secondary:{},meta:{left:0,top:0}};o=(document.body||document.documentElement).style;var s=o.WebkitTransition!==undefined?"webkitTransitionEnd":o.OTransition!==undefined?"oTransitionEnd":"transitionend",z=o.WebkitTransition!==undefined||o.MozTransition!==undefined||o.OTransition!==undefined||o.transition!==undefined,G="WebKitCSSMatrix"in window&&"m11"in new WebKitCSSMatrix;jQuery.fn.translation=function(){if(!this[0])return null;for(var a=window.getComputedStyle(this[0],null),d={x:0,
y:0},k=e.length-1;k>=0;k--){var i=a.getPropertyValue(e[k]+"transform");if(i&&/matrix/i.test(i)){a=i.replace(/^matrix\(/i,"").split(/, |\)$/g);d={x:a[4],y:a[5]};break}}return d};jQuery.fn.animate=function(a,d,k,i){var j=jQuery.speed(d,k,i),f=0;if(!z||p(a))return x.apply(this,arguments);return this[j.queue===false?"each":"queue"](function(){var g=jQuery(this),b=jQuery.extend({},j),c=this||window,l=function(){f--;if(f==0)if(typeof b.complete==="function")return b.complete.apply(c,arguments)},r=function(){for(var t=
{},n=e.length-1;n>=0;n--){t[e[n]+"transition-property"]="none";t[e[n]+"transition-duration"]="";t[e[n]+"transition-timing-function"]=""}g.unbind(s);if(!a.leaveTransforms===true){var w=g.data("cssEnhanced")||{},u={};for(n=e.length-1;n>=0;n--)u[e[n]+"transform"]="";if(typeof w.meta!=="undefined"){u.left=w.meta.left_o+"px";u.top=w.meta.top_o+"px"}g.css(t).css(u)}g.data("cssEnhanced",null);l()},m={bounce:"cubic-bezier(0.0, 0.35, .5, 1.3)",linear:"linear",swing:"ease-in-out",easeInOutQuint:"cubic-bezier(0.5, 0, 0, 0.8)"},
q=null;m=m[b.easing||"swing"]?m[b.easing||"swing"]:b.easing||"swing";for(var h in a)if(jQuery.inArray(h,I)===-1){var A=B(g,a[h],h,(h=="left"||h=="top")&&a.avoidTransforms!==true?true:false);if(jQuery.inArray(h,H)>-1&&!((h=="width"||h=="height")&&(a[h]=="show"||a[h]=="hide"||a[h]=="toggle")))D(g,h,b.duration,m,(h=="left"||h=="top")&&a.avoidTransforms===true?A+"px":A,(h=="left"||h=="top")&&a.avoidTransforms!==true?true:false,a.useTranslate3d===true?true:false);else{q=!q?{}:q;q[h]=a[h]}}h=g.data("cssEnhanced")||
{};for(m=e.length-1;m>=0;m--)if(typeof h[e[m]+"transition-property"]!=="undefined")h[e[m]+"transition-property"]=h[e[m]+"transition-property"].substr(2);g.data("cssEnhanced",h);g.unbind(s);if(!p(g.data("cssEnhanced"))&&!p(g.data("cssEnhanced").secondary)){f++;g.css(g.data("cssEnhanced"));setTimeout(function(){g.bind(s,r).css(g.data("cssEnhanced").secondary)})}if(!p(q)){f++;x.apply(g,[q,{duration:b.duration,easing:b.easing,complete:l,queue:b.queue}])}return true})};jQuery.fn.stop=function(a,d,k){if(!z)return y.apply(this,
[a,d]);a&&this.queue([]);for(var i={},j=e.length-1;j>=0;j--){i[e[j]+"transition-property"]="none";i[e[j]+"transition-duration"]="";i[e[j]+"transition-timing-function"]=""}this.each(function(){var f=jQuery(this),g=window.getComputedStyle(this,null),b={},c;if(!p(f.data("cssEnhanced"))&&!p(f.data("cssEnhanced").secondary)){c=f.data("cssEnhanced");if(d){b=c.secondary;if(!k&&typeof c.meta.left_o!==undefined||typeof c.meta.top_o!==undefined){b.left=typeof c.meta.left_o!==undefined?c.meta.left_o:"auto";
b.top=typeof c.meta.top_o!==undefined?c.meta.top_o:"auto";for(c=e.length-1;c>=0;c--)b[e[c]+"transform"]=""}}else for(var l in f.data("cssEnhanced").secondary){l=l.replace(J,"-$1").toLowerCase();b[l]=g.getPropertyValue(l);if(!k&&/matrix/i.test(b[l])){c=b[l].replace(/^matrix\(/i,"").split(/, |\)$/g);b.left=c[4]+"px"||"auto";b.top=c[5]+"px"||"auto";for(c=e.length-1;c>=0;c--)b[e[c]+"transform"]=""}}f.unbind(s).css(i).css(b).data("cssEnhanced",null)}else y.apply(f,[a,d])});return this}})(jQuery,jQuery.fn.animate,
jQuery.fn.stop);