You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
5.8 KiB
1 lines
5.8 KiB
(function(a,b,c,d){a.fn.origami=function(b){var h,c=a(this),e=a.extend(!0,{},a.fn.origami.settings,b),f=arguments[0],g=[].slice.call(arguments,1);return c.each(function(){var j,k,t,b=a(this),c=b.find(e.selector.box),i=b.find(e.selector.side),m=(b.selector||"",this),n=b.data("module-"+e.namespace),o="string"==typeof f,p="transitionend msTransitionEnd oTransitionEnd",q=e.namespace,s=(e.metadata,e.className);t={initialize:function(){t.verbose("Initializing module for",m),t.set.defaultSide(),b.data("module-"+q,t)},destroy:function(){t.verbose("Destroying previous module for",m),b.off("."+q)},refresh:function(){t.verbose("Refreshing selector cache for",m),b=a(m),c=a(this).find(e.selector.box),i=a(this).find(e.selector.side)},repaint:function(){b.get(0).offsetWidth},animate:function(a){t.verbose("Animating box with properties",a);var d=function(){t.reset(),t.set.active()};e.useCSS?(t.verbose("Using CSS transitions to animate"),b.addClass(s.animating),t.set.stageSize(),t.repaint(),b.addClass(s.css),j.addClass(s.hidden),c.css(a).one(p,d)):(t.verbose("Using javascript to animate"),b.addClass(s.animating).removeClass(s.css),t.set.stageSize(),t.repaint(),j.animate({opacity:0},e.duration,e.easing),c.animate(a,e.duration,e.easing,d))},reset:function(){t.verbose("Animating states reset"),b.removeClass(s.css).removeClass(s.animating).removeAttr("style"),c.removeAttr("style"),i.removeAttr("style").removeClass(s.hidden),k.removeClass(s.animating).removeAttr("style")},set:{defaultSide:function(){j=b.find("."+e.className.active),k=j.next(e.selector.side).size()>0?j.next(e.selector.side):b.find(e.selector.side).first(),t.verbose("Active side set to",j),t.verbose("Next side set to",k)},stageSize:function(){b.css({width:k.outerWidth(),height:k.outerHeight()})},nextSide:function(a){k=b.find(a),t.verbose("Next side manually set to",k)},active:function(){t.verbose("Setting new side to active",k),i.removeClass(s.active),k.addClass(s.active),t.set.defaultSide()}},getTransform:{up:function(){var a={y:-((j.outerHeight()-k.outerHeight())/2),z:-(j.outerHeight()/2)};return{transform:"translateY("+a.y+"px) translateZ("+a.z+"px) rotateX(-90deg)"}},down:function(){var a={y:-((j.outerHeight()-k.outerHeight())/2),z:-(j.outerHeight()/2)};return{transform:"translateY("+a.y+"px) translateZ("+a.z+"px) rotateX(90deg)"}},left:function(){var a={x:-((j.outerWidth()-k.outerWidth())/2),z:-(j.outerWidth()/2)};return{transform:"translateX("+a.x+"px) translateZ("+a.z+"px) rotateY(90deg)"}},right:function(){var a={x:-((j.outerWidth()-k.outerWidth())/2),z:-(j.outerWidth()/2)};return{transform:"translateX("+a.x+"px) translateZ("+a.z+"px) rotateY(-90deg)"}}},stage:{above:function(){var a={origin:(j.outerHeight()-k.outerHeight())/2,depth:{active:k.outerHeight()/2,next:j.outerHeight()/2}};t.verbose("Setting the initial animation position as above",k,a),j.css({transform:"rotateY(0deg) translateZ("+a.depth.active+"px)"}),k.addClass(s.animating).css({display:"block",top:a.origin+"px",transform:"rotateX(90deg) translateZ("+a.depth.next+"px)"})},below:function(){var a={origin:(j.outerHeight()-k.outerHeight())/2,depth:{active:k.outerHeight()/2,next:j.outerHeight()/2}};t.verbose("Setting the initial animation position as below",k,a),j.css({transform:"rotateY(0deg) translateZ("+a.depth.active+"px)"}),k.addClass(s.animating).css({display:"block",top:a.origin+"px",transform:"rotateX(-90deg) translateZ("+a.depth.next+"px)"})},left:function(){var a={origin:(j.outerWidth()-k.outerWidth())/2,depth:{active:k.outerWidth()/2,next:j.outerWidth()/2}};t.verbose("Setting the initial animation position as left",k,a),j.css({transform:"rotateY(0deg) translateZ("+a.depth.active+"px)"}),k.addClass(s.animating).css({display:"block",left:a.origin+"px",transform:"rotateY(-90deg) translateZ("+a.depth.next+"px)"})},right:function(){var a={origin:(j.outerWidth()-k.outerWidth())/2,depth:{active:k.outerWidth()/2,next:j.outerWidth()/2}};t.verbose("Setting the initial animation position as left",k,a),j.css({transform:"rotateY(0deg) translateZ("+a.depth.active+"px)"}),k.addClass(s.animating).css({display:"block",left:a.origin+"px",transform:"rotateY(90deg) translateZ("+a.depth.next+"px)"})}},flip:{up:function(){t.debug("Flipping up",k),t.stage.above(),t.animate(t.getTransform.up(),m)},down:function(){t.debug("Flipping down",k),t.stage.below(),t.animate(t.getTransform.down(),m)},left:function(){t.debug("Flipping left",k),t.stage.left(),t.animate(t.getTransform.left(),m)},right:function(){t.debug("Flipping right",k),t.stage.right(),t.animate(t.getTransform.right(),m)}},setting:function(a,b){return b===d?e[a]:(e[a]=b,d)},verbose:function(){e.verbose&&t.debug.apply(this,arguments)},debug:function(){var a=[],b=e.moduleName+": "+arguments[0],c=[].slice.call(arguments,1),d=console.info||console.log||function(){};d=Function.prototype.bind.call(d,console),e.debug&&(a.push(b),d.apply(console,a.concat(c)))},error:function(){var a=[],b=e.moduleName+": "+arguments[0],c=[].slice.call(arguments,1),d=console.warn||console.log||function(){};d=Function.prototype.bind.call(d,console),e.debug&&(a.push(b),a.concat(c),d.apply(console,a.concat(c)))},invoke:function(b,c,f){var g,h;return f=f||[].slice.call(arguments,2),"string"==typeof b&&n!==d&&(b=b.split("."),g=b.length-1,a.each(b,function(b,c){return a.isPlainObject(n[c])&&b!=g?(n=n[c],!0):n[c]!==d?(h=n[c],!0):(t.error(e.errors.method),!1)})),a.isFunction(h)?h.apply(c,f):h}},o?h=t.invoke(f,this,g):(n!==d&&t.destroy(),t.initialize())}),h!==d?h:this},a.fn.origami.settings={moduleName:"Origami Module",debug:!0,verbose:!0,namespace:"origami",onChange:function(){},useCSS:!0,duration:1e3,easing:"easeInOutQuad",errors:{api:"You tried to switch to a side that does not exist.",method:"The method you called is not defined"},metadata:{},className:{css:"css",animating:"animating",hidden:"hidden",active:"active"},selector:{box:".box",side:".side"}}})(jQuery,window,document);
|