forked from dmotz/oriDomi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoriDomi.min.js
2 lines (2 loc) · 14.6 KB
/
oriDomi.min.js
1
2
// Generated by CoffeeScript 1.3.3
(function(){"use strict";var e,t,n,r,i,s,o,u,a,f,l,c,h,p;l=window,o=[],e=l.$||!1,i=!1,a=!0,c=document.createElement("div"),f=["Webkit","Moz","O","ms","Khtml"],n={transform:"transform",origin:"transformOrigin",transformStyle:"transformStyle",transitionProp:"transitionProperty",transitionDuration:"transitionDuration",transitionEasing:"transitionTimingFunction",perspective:"perspective",backface:"backfaceVisibility"},h=function(e){var t,n,r,i;if(c.style[e]!=null)return e;t=e.charAt(0).toUpperCase()+e.slice(1);for(r=0,i=f.length;r<i;r++){n=f[r];if(c.style[n+t]!=null)return n+t}return!1};for(u in n){p=n[u],n[u]=h(p);if(!n[u]){i&&console.warn("oriDomi: Browser does not support oriDomi"),a=!1;break}}n.gradientProp=function(){var e,t,n,r;for(n=0,r=f.length;n<r;n++){t=f[n],e="-"+t.toLowerCase()+"-linear-gradient",c.style.backgroundImage=""+e+"(left, #000, #fff)";if(c.style.backgroundImage.indexOf("gradient")!==-1)return e}return"linear-gradient"}(),n.transformProp=function(){var e;return e=n.transform.match(/(\w+)Transform/i),e?"-"+e[1].toLowerCase()+"-transform":"transform"}(),n.transitionEnd=function(){switch(n.transitionProp){case"transitionProperty":return"transitionEnd";case"WebkitTransitionProperty":return"webkitTransitionEnd";case"MozTransitionProperty":return"transitionend";case"OTransitionProperty":return"oTransitionEnd";case"MSTransitionProperty":return"msTransitionEnd"}}(),s=function(e,t){var n;if(t!==Object(t))return i&&console.warn("oriDomi: Must pass an object to extend with"),e;e!==Object(e)&&(e={});for(n in t)e[n]==null&&(e[n]=t[n]);return e},r={vPanels:3,hPanels:3,perspective:1e3,shading:"hard",speed:700,oriDomiClass:"oridomi",shadingIntensity:1,easingMethod:"",showOnStart:!1,forceAntialiasing:!1},t=function(){function t(f,c){var h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R,U,z,W,X,V,J,K,Q,G,Y,Z,et;this.el=f,i&&console.time("oridomiConstruction");if(!a)return this.el;if(!(this instanceof t))return new oriDomi(this.el,this.settings);this.settings=s(c,r);if(!this.el||this.el.nodeType!==1)return i&&console.warn("oriDomi: First argument must be a DOM element");this.cleanEl=this.el.cloneNode(!0),this.cleanEl.style.margin="0",this.cleanEl.style.position="absolute",this.cleanEl.style[n.transform]="translate3d(-9999px, 0, 0)",X=this.settings,this.shading=X.shading,this.shadingIntensity=X.shadingIntensity,this.vPanels=X.vPanels,this.hPanels=X.hPanels,g=l.getComputedStyle(this.el),this.displayStyle=g.display,this.displayStyle==="none"&&(this.displayStyle="block"),this.width=parseInt(g.width,10)+parseInt(g.paddingLeft,10)+parseInt(g.paddingRight,10)+parseInt(g.borderLeftWidth,10)+parseInt(g.borderRightWidth,10),this.height=parseInt(g.height,10)+parseInt(g.paddingTop,10)+parseInt(g.paddingBottom,10)+parseInt(g.borderTopWidth,10)+parseInt(g.borderBottomWidth,10),this.panelWidth=this.width/this.vPanels,this.panelHeight=this.height/this.hPanels,this.lastAngle=0,this.isFoldedUp=!1,this.isFrozen=!1,this.anchors=["left","right","top","bottom"],this.lastAnchor=this.anchors[0],this.panels={},this.stages={},N=document.createElement("div"),N.style.width=this.width+"px",N.style.height=this.height+"px",N.style.display="none",N.style.position="absolute",N.style.padding="0",N.style.margin="0",N.style[n.perspective]=this.settings.perspective+"px",V=this.anchors;for(M=0,H=V.length;M<H;M++)h=V[M],this.panels[h]=[],this.stages[h]=N.cloneNode(!1),this.stages[h].className="oridomi-stage-"+h;if(this.shading){this.shaders={},J=this.anchors;for(_=0,B=J.length;_<B;_++)h=J[_],this.shaders[h]={},h==="left"||h==="right"?(this.shaders[h].left=[],this.shaders[h].right=[]):(this.shaders[h].top=[],this.shaders[h].bottom=[]);T=document.createElement("div"),T.style[n.transitionProp]="opacity",T.style[n.transitionDuration]=this.settings.speed+"ms",T.style[n.transitionEasing]=this.settings.easingMethod,T.style.position="absolute",T.style.width="100%",T.style.height="100%",T.style.opacity="0",T.style.top="0",T.style.left="0"}m=this.el.cloneNode(!0),m.classList.add("oridomi-content"),m.style.margin="0",m.style.position="relative",m.style.float="none",y=document.createElement("div"),y.className="oridomi-mask-h",y.style.position="absolute",y.style.overflow="hidden",y.style.width="100%",y.style.height="100%",y.style[n.transform]="translate3d(0, 0, 0)",y.appendChild(m),this.shading&&(C=T.cloneNode(!1),C.className="oridomi-shader-top",C.style.background=this._getShaderGradient("top"),d=T.cloneNode(!1),d.className="oridomi-shader-bottom",d.style.background=this._getShaderGradient("bottom"),y.appendChild(C),y.appendChild(d)),p=2,b=document.createElement("div"),b.className="oridomi-panel-h",b.style.width="100%",b.style.height=this.panelHeight+p+"px",b.style.padding="0",b.style.position="relative",b.style[n.transitionProp]=n.transformProp,b.style[n.transitionDuration]=this.settings.speed+"ms",b.style[n.transitionEasing]=this.settings.easingMethod,b.style[n.origin]="top",b.style[n.transformStyle]="preserve-3d",b.style[n.backface]="hidden",this.settings.forceAntialiasing&&(b.style.outline="1px solid transparent"),b.appendChild(y),K=["top","bottom"];for(D=0,j=K.length;D<j;D++){h=K[D];for(w=P=0,Q=this.hPanels;0<=Q?P<Q:P>Q;w=0<=Q?++P:--P)S=b.cloneNode(!0),v=S.getElementsByClassName("oridomi-content")[0],h==="top"?(O=-(w*this.panelHeight),w===0?S.style.top="0":S.style.top=this.panelHeight+"px"):(S.style[n.origin]="bottom",O=-(this.hPanels*this.panelHeight-this.panelHeight*(w+1)),w===0?S.style.top=this.panelHeight*(this.vPanels-1)-p+"px":S.style.top=-this.panelHeight+"px"),v.style.top=O+"px",this.shading&&(this.shaders[h].top[w]=S.getElementsByClassName("oridomi-shader-top")[0],this.shaders[h].bottom[w]=S.getElementsByClassName("oridomi-shader-bottom")[0]),this.panels[h][w]=S,w!==0&&this.panels[h][w-1].appendChild(S);this.stages[h].appendChild(this.panels[h][0])}k=y.cloneNode(!0),k.className="oridomi-mask-v",this.shading&&(E=k.getElementsByClassName("oridomi-shader-top")[0],E.className="oridomi-shader-left",E.style.background=this._getShaderGradient("left"),x=k.getElementsByClassName("oridomi-shader-bottom")[0],x.className="oridomi-shader-right",x.style.background=this._getShaderGradient("right")),L=b.cloneNode(!1),L.className="oridomi-panel-v",L.style.width=this.panelWidth+p+"px",L.style.height="100%",L.style[n.origin]="left",L.appendChild(k),G=["left","right"];for(R=0,F=G.length;R<F;R++){h=G[R];for(w=U=0,Y=this.vPanels;0<=Y?U<Y:U>Y;w=0<=Y?++U:--U)S=L.cloneNode(!0),v=S.getElementsByClassName("oridomi-content")[0],h==="left"?(A=-(w*this.panelWidth),w===0?S.style.left="0":S.style.left=this.panelWidth+"px"):(S.style[n.origin]="right",A=-(this.vPanels*this.panelWidth-this.panelWidth*(w+1)),w===0?S.style.left=this.panelWidth*(this.vPanels-1)-1+"px":S.style.left=-this.panelWidth+"px"),v.style.left=A+"px",this.shading&&(this.shaders[h].left[w]=S.getElementsByClassName("oridomi-shader-left")[0],this.shaders[h].right[w]=S.getElementsByClassName("oridomi-shader-right")[0]),this.panels[h][w]=S,w!==0&&this.panels[h][w-1].appendChild(S);this.stages[h].appendChild(this.panels[h][0])}this.el.classList.add(this.settings.oriDomiClass),this.originalStyles={},Z=["padding","width","height","backgroundColor","backgroundImage","border","outline"];for(z=0,I=Z.length;z<I;z++)u=Z[z],this.originalStyles[u]=g[u];this.el.style.padding="0",this.el.style.width=this.width+"px",this.el.style.height=this.height+"px",this.el.style.backgroundColor="transparent",this.el.style.backgroundImage="none",this.el.style.border="none",this.el.style.outline="none",this.stages.left.style.display="block",this.stageEl=document.createElement("div"),et=this.anchors;for(W=0,q=et.length;W<q;W++)h=et[W],this.stageEl.appendChild(this.stages[h]);this.settings.showOnStart&&(this.el.style.display="block",this.el.style.visibility="visible"),this.el.innerHTML="",this.el.appendChild(this.cleanEl),this.el.appendChild(this.stageEl),e&&(this.$el=e(this.el)),o.push(this),this._callback(this.settings),i&&console.timeEnd("oridomiConstruction")}return t.prototype._callback=function(e){var t,r=this;if(typeof e.callback=="function")return t=function(r){return r.currentTarget.removeEventListener(n.transitionEnd,t,!1),e.callback()},this.lastAngle===0?e.callback():this.panels[this.lastAnchor][0].addEventListener(n.transitionEnd,t,!1)},t.prototype._transform=function(e,t){var n,r;switch(this.lastAnchor){case"left":n=[0,1,0,e];break;case"right":n=[0,1,0,-e];break;case"top":n=[1,0,0,-e];break;case"bottom":n=[1,0,0,e]}return t&&(r=[1,1,1],n[0]=r[0],n[1]=r[1],n[2]=r[2]),"rotate3d("+n[0]+", "+n[1]+", "+n[2]+", "+n[3]+"deg)"},t.prototype._normalizeAngle=function(e){return e=parseFloat(e,10),isNaN(e)?0:e>89?(i&&console.warn("oriDomi: Maximum value is 89"),89):e<-89?(i&&console.warn("oriDomi: Minimum value is -89"),-89):e},t.prototype._normalizeArgs=function(e,t){var n,r,i,o=this;return this.isFrozen&&this.unfreeze(),r=this._normalizeAngle(t[0]),n=this._getLonghandAnchor(t[1]),i=s(t[2],this._methodDefaults[e]),n!==this.lastAnchor||e==="foldUp"&&this.lastAngle!==0||this.isFoldedUp?(this.reset(function(){return o._showStage(n),setTimeout(function(){return e==="foldUp"&&t.shift(),o[e].apply(o,t)},0)}),!1):(this.lastAngle=r,[r,n,i])},t.prototype._setShader=function(e,t,n){var r,i,s,o;i=Math.abs(n),o=i/90*this.shadingIntensity,this.shading==="hard"?(o*=.15,this.lastAngle<0?n=i:n=-i):o*=.4;switch(t){case"left":case"top":n<0?(r=o,s=0):(r=0,s=o);break;case"right":case"bottom":n<0?(r=0,s=o):(r=o,s=0)}return t==="left"||t==="right"?(this.shaders[t].left[e].style.opacity=r,this.shaders[t].right[e].style.opacity=s):(this.shaders[t].top[e].style.opacity=r,this.shaders[t].bottom[e].style.opacity=s)},t.prototype._getShaderGradient=function(e){return""+n.gradientProp+"("+e+", rgba(0, 0, 0, .5) 0%, rgba(255, 255, 255, .35) 100%)"},t.prototype._showStage=function(e){return this.stages[e].style.display="block",this.stages[this.lastAnchor].style.display="none",this.lastAnchor=e},t.prototype._getPanelType=function(e){return e==="left"||e==="right"?this.vPanels:this.hPanels},t.prototype._getLonghandAnchor=function(e){switch(e){case"left":case"l":case"4":case 4:return"left";case"right":case"r":case"2":case 2:return"right";case"top":case"t":case"1":case 1:return"top";case"bottom":case"b":case"3":case 3:return"bottom";default:return"left"}},t.prototype._methodDefaults={accordion:{sticky:!1,stairs:!1,fracture:!1,twist:!1},curl:{twist:!1},ramp:{},foldUp:{}},t.prototype.reset=function(e){var t,r,i,s,o;if(this.isFoldedUp)return this.unfold(e);o=this.panels[this.lastAnchor];for(t=i=0,s=o.length;i<s;t=++i)r=o[t],r.style[n.transform]=this._transform(0),this.shading&&this._setShader(t,this.lastAnchor,0);return this._callback({callback:e})},t.prototype.freeze=function(e){var t=this;if(!this.isFrozen)return this.reset(function(){t.isFrozen=!0,t.stageEl.style[n.transform]="translate3d(-9999px, 0, 0)",t.cleanEl.style[n.transform]="translate3d(0, 0, 0)";if(typeof e=="function")return e()});if(typeof e=="function")return e()},t.prototype.unfreeze=function(){if(this.isFrozen)return this.isFrozen=!1,this.cleanEl.style[n.transform]="translate3d(-9999px, 0, 0)",this.stageEl.style[n.transform]="translate3d(0, 0, 0)",this.lastAngle=0},t.prototype.destroy=function(t){var n=this;return this.freeze(function(){var r;e&&e.data(n.el,"oriDomi",null),n.el.innerHTML=n.cleanEl.innerHTML,r=n.originalStyles;for(u in r)p=r[u],n.el.style[u]=p;o[o.indexOf(n)]=null;if(typeof t=="function")return t()})},t.prototype.accordion=function(e,t,r){var i,s,o,u,a,f,l;o=this._normalizeArgs("accordion",arguments);if(!o)return;e=o[0],t=o[1],r=o[2],l=this.panels[t];for(s=a=0,f=l.length;a<f;s=++a){u=l[s],s%2!==0&&!r.twist?i=-e:i=e;if(r.sticky){if(s===0)i=0;else if(s>1||r.stairs)i*=2}else s!==0&&(i*=2);r.stairs&&(i=-i),u.style[n.transform]=this._transform(i,r.fracture),this.shading&&(s!==0||!r.sticky)&&Math.abs(i)!==180&&this._setShader(s,t,i)}return this._callback(r)},t.prototype.curl=function(e,t,r){var i,s,o,u,a,f;s=this._normalizeArgs("curl",arguments);if(!s)return;e=s[0],t=s[1],r=s[2],e/=this._getPanelType(t),f=this.panels[t];for(i=u=0,a=f.length;u<a;i=++u)o=f[i],o.style[n.transform]=this._transform(e),this.shading&&this._setShader(i,t,0);return this._callback(r)},t.prototype.ramp=function(e,t,r){var i,s,o,u,a,f;s=this._normalizeArgs("ramp",arguments);if(!s)return;e=s[0],t=s[1],r=s[2],this.panels[t][1].style[n.transform]=this._transform(e),f=this.panels[t];for(i=u=0,a=f.length;u<a;i=++u)o=f[i],i>1&&(this.panels[t][i].style[n.transform]=this._transform(0)),this.shading&&this._setShader(i,t,0);return this._callback(r)},t.prototype.foldUp=function(e,t){var r,i,s,o,u,a=this;e?typeof e=="function"&&(t=e):e="left",o=this._normalizeArgs("foldUp",[0,e,{}]);if(!o)return;return e=o[1],this.isFoldedUp=!0,i=this.panels[e].length-1,r=100,s=function(){a.panels[e][i].addEventListener(n.transitionEnd,u,!1),a.panels[e][i].style[n.transform]=a._transform(r);if(a.shading)return a._setShader(i,e,r)},u=function(r){a.panels[e][i].removeEventListener(n.transitionEnd,u,!1),a.panels[e][i].style.display="none";if(--i!==0)return setTimeout(s,0);if(typeof t=="function")return t()},s()},t.prototype.unfold=function(e){var t,r,i,s,o=this;return this.isFoldedUp||typeof e=="function"&&e(),this.isFoldedUp=!1,r=1,t=0,i=function(){return o.panels[o.lastAnchor][r].style.display="block",setTimeout(function(){o.panels[o.lastAnchor][r].addEventListener(n.transitionEnd,s,!1),o.panels[o.lastAnchor][r].style[n.transform]=o._transform(t);if(o.shading)return o._setShader(r,o.lastAnchor,t)},0)},s=function(t){o.panels[o.lastAnchor][r].removeEventListener(n.transitionEnd,s,!1);if(++r!==o.panels[o.lastAnchor].length)return setTimeout(i,0);if(typeof e=="function")return e()},i()},t.prototype.collapse=function(e,t){return t==null&&(t={}),t.sticky=!1,this.accordion(-89,e,t)},t.prototype.collapseAlt=function(e,t){return t==null&&(t={}),t.sticky=!1,this.accordion(89,e,t)},t.prototype.reveal=function(e,t,n){return n==null&&(n={}),n.sticky=!0,this.accordion(e,t,n)},t.prototype.stairs=function(e,t,n){return n==null&&(n={}),n.stairs=!0,n.sticky=!0,this.accordion(e,t,n)},t.prototype.fracture=function(e,t,n){return n==null&&(n={}),n.fracture=!0,this.accordion(e,t,n)},t.prototype.twist=function(e,t,n){return n==null&&(n={}),n.fracture=!0,n.twist=!0,this.accordion(e/10,t,n)},t.VERSION="0.1.4",t.devMode=function(){return i=!0},t}(),l.OriDomi=t,e&&(e.fn.oriDomi=function(n){var r,s,o,u,f,l,c;if(!a)return this;if(typeof n=="string"){if(typeof t.prototype[n]!="function")return i&&console.warn("oriDomi: No such method '"+n+"'");for(u=0,l=this.length;u<l;u++){s=this[u],o=e.data(s,"oriDomi");if(o==null)return i&&console.warn("oriDomi: Can't call "+n+", oriDomi hasn't been initialized on this element");r=Array.prototype.slice.call(arguments),r.shift(),o[n].apply(o,r)}return this}for(f=0,c=this.length;f<c;f++){s=this[f],o=e.data(s,"oriDomi");if(o)return o;e.data(s,"oriDomi",new t(s,n))}return this})}).call(this);