-
Notifications
You must be signed in to change notification settings - Fork 0
/
jmpress.impress.min.js
12 lines (12 loc) · 17.9 KB
/
jmpress.impress.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*!
* jmpress.js v0.4.5
* http://jmpressjs.github.com/jmpress.js
*
* A jQuery plugin to build a website on the infinite canvas.
*
* Copyright 2014 Kyle Robinson Young @shama & Tobias Koppers @sokra
* Licensed MIT
* http://www.opensource.org/licenses/mit-license.php
*
* Based on the foundation laid by Bartek Szopka @bartaz
*/!function(a,b,c,d){"use strict";function e(a){if(a){var b=1+a.substr(1).search(/[A-Z]/),c=a.substr(0,b).toLowerCase(),d=a.substr(b).toLowerCase();return"-"+c+"-"+d}}function f(a){return a?a+",":""}function g(a){return a.length>0?a:null}function h(e){function f(b,c){var d=l(b),e={oldStyle:a(b).attr("style")||""},f={data:d,stepData:e};m.call(this,"beforeInitStep",a(b),f),e.delegate=d.delegate,m.call(this,"initStep",a(b),f),a(b).data("stepData",e),a(b).attr("id")||a(b).attr("id","step-"+(c+1)),m.call(this,"applyStep",a(b),f)}function h(b){var c=a(b).data("stepData");a(b).attr("style",c.oldStyle),m.call(this,"unapplyStep",a(b),{stepData:c})}function i(b){m.call(this,"unapplyStep",a(b),{stepData:b.data("stepData")}),m.call(this,"applyStep",a(b),{stepData:b.data("stepData")})}function j(){L&&m.call(this,"setInactive",L,{stepData:a(L).data("stepData"),reason:"deinit"}),K.jmpressClass&&a(F).removeClass(K.jmpressClass),m.call(this,"beforeDeinit",a(this),{}),a(E.stepSelector,F).each(function(){h.call(F,this)}),G.attr("style",I.container),E.fullscreen&&a("html").attr("style",""),H.attr("style",I.area),a(J).children().each(function(){F.append(a(this))}),E.fullscreen?J.remove():(J.remove(),H.remove()),m.call(this,"afterDeinit",a(this),{}),a(F).data("jmpressmethods",!1)}function m(b,c,d){d.settings=E,d.current=K,d.container=G,d.parents=c?n(c):null,d.current=K,d.jmpress=this;var e={};return a.each(E[b],function(a,b){e.value=b.call(F,c,d)||e.value}),e.value}function n(b){return a(b).parentsUntil(F).not(F).filter(E.stepSelector)}function q(a){return r({step:L,substep:M},a)}function r(b,c){var e;if(a.isPlainObject(b)&&(e=b.substep,b=b.step),"string"==typeof b&&(b=F.find(b).first()),!b||!a(b).data("stepData"))return!1;s.call(this);var f=a(b).data("stepData"),h=!1;if(m.call(this,"beforeChange",b,{stepData:f,reason:c,cancel:function(){h=!0}}),h)return d;var i={},j=b;a(b).data("stepData").delegate&&(j=g(a(b).parentsUntil(F).filter(E.stepSelector).filter(f.delegate))||g(a(b).near(f.delegate))||g(a(b).near(f.delegate,!0))||g(a(f.delegate,F)),j?f=j.data("stepData"):j=b),N&&m.call(this,"setInactive",N,{stepData:a(N).data("stepData"),delegatedFrom:L,reason:c,target:i,nextStep:j,nextSubstep:e,nextStepData:f});var k={stepData:f,delegatedFrom:b,reason:c,target:i,substep:e,prevStep:N,prevSubstep:M,prevStepData:N&&a(N).data("stepData")};return m.call(this,"beforeActive",j,k),m.call(this,"setActive",j,k),K.jmpressClass&&a(F).removeClass(K.jmpressClass),a(F).addClass(K.jmpressClass="step-"+a(j).attr("id")),K.jmpressDelegatedClass&&a(F).removeClass(K.jmpressDelegatedClass),a(F).addClass(K.jmpressDelegatedClass="delegating-step-"+a(b).attr("id")),m.call(this,"applyTarget",j,a.extend({canvas:J,area:H,beforeActive:N},k)),L=b,M=k.substep,N=j,K.idleTimeout&&clearTimeout(K.idleTimeout),K.idleTimeout=setTimeout(function(){m.call(this,"idle",j,k)},Math.max(1,E.transitionDuration-100)),j}function s(){!function b(){function d(){(0!==a(G).scrollTop()||0!==a(G).scrollLeft())&&b()}if("BODY"===a(G)[0].tagName)try{c.scrollTo(0,0)}catch(e){}a(G).scrollTop(0),a(G).scrollLeft(0),setTimeout(d,1),setTimeout(d,10),setTimeout(d,100),setTimeout(d,200),setTimeout(d,400)}()}function t(a){return r.call(this,a,"jump")}function u(){return r.call(this,m.call(this,"selectNext",L,{stepData:a(L).data("stepData"),substep:M}),"next")}function v(){return r.call(this,m.call(this,"selectPrev",L,{stepData:a(L).data("stepData"),substep:M}),"prev")}function w(){return r.call(this,m.call(this,"selectHome",L,{stepData:a(L).data("stepData")}),"home")}function x(){return r.call(this,m.call(this,"selectEnd",L,{stepData:a(L).data("stepData")}),"end")}function y(b){return k(J,b||{}),a(J)}function z(){return N&&a(N)}function A(b,c,d){return p[b]?m.call(this,b,c,d):(a.error("callback "+b+" is not registered."),void 0)}function B(){var a=navigator.userAgent.toLowerCase();return-1===a.search(/(iphone)|(ipod)|(android)/)||-1!==a.search(/(chrome)/)}e=a.extend(!0,{},e||{});var C={},D=null;for(D in p)C[D]=a.isFunction(e[D])?[e[D]]:e[D],e[D]=[];var E=a.extend(!0,{},o,e);for(D in p)C[D]&&Array.prototype.push.apply(E[D],C[D]);var F=a(this),G=null,H=null,I={container:"",area:""},J=null,K=null,L=!1,M=null,N=!1;if(F.data("jmpressmethods",{select:r,reselect:q,scrollFix:s,goTo:t,next:u,prev:v,home:w,end:x,canvas:y,container:function(){return G},settings:function(){return E},active:z,current:function(){return K},fire:A,init:function(b){f.call(this,a(b),K.nextIdNumber++)},deinit:function(b){b?h.call(this,a(b)):j.call(this)},reapply:i}),B()===!1)return E.notSupportedClass&&F.addClass(E.notSupportedClass),void 0;E.notSupportedClass&&F.removeClass(E.notSupportedClass);var O=a(E.stepSelector,F);G=F,H=a("<div />"),J=a("<div />"),a(F).children().filter(O).each(function(){J.append(a(this))}),E.fullscreen&&(G=a("body"),a("html").css({overflow:"hidden"}),H=F),I.area=H.attr("style")||"",I.container=G.attr("style")||"",E.fullscreen?(G.css({height:"100%"}),F.append(J)):(G.css({position:"relative"}),H.append(J),F.append(H)),a(G).addClass(E.containerClass),a(H).addClass(E.areaClass),a(J).addClass(E.canvasClass),b.documentElement.style.height="100%",G.css({overflow:"hidden"});var P={position:"absolute",transitionDuration:"0s"};P=a.extend({},E.animation,P),k(H,P),k(H,{top:"50%",left:"50%",perspective:"1000px"}),k(J,P),K={},m.call(this,"beforeInit",null,{}),O.each(function(a){f.call(F,this,a)}),K.nextIdNumber=O.length,m.call(this,"afterInit",null,{}),r.call(this,m.call(this,"selectInitialStep","init",{})),E.initClass&&a(O).removeClass(E.initClass)}function i(){return o}function j(b,c){a.isFunction(c)?r[b]?a.error("function "+b+" is already registered."):r[b]=c:p[b]?a.error("callback "+b+" is already registered."):(p[b]=1,o[b]=[])}function k(b,c){var d,e,f={};for(d in c)c.hasOwnProperty(d)&&(e=n(d),null!==e&&(f[e]=c[d]));return a(b).css(f),b}function l(b){function c(a){a=a.split("-");for(var b=1;b<a.length;b++)a[b]=a[b].substr(0,1).toUpperCase()+a[b].substr(1);return a.join("")}if(a(b)[0].dataset)return a.extend({},a(b)[0].dataset);var d={},e=a(b)[0].attributes;return a.each(e,function(a,b){"data-"===b.nodeName.substr(0,5)&&(d[c(b.nodeName.substr(5))]=b.nodeValue)}),d}function m(){return!!a(this).data("jmpressmethods")}var n=function(){var a=b.createElement("dummy").style,c="Webkit Moz O ms Khtml".split(" "),e={};return function(b){if("undefined"==typeof e[b]){var f=b.charAt(0).toUpperCase()+b.substr(1),g=(b+" "+c.join(f+" ")+f).split(" ");e[b]=null;for(var h in g)if(a[g[h]]!==d){e[b]=g[h];break}}return e[b]}}(),o={stepSelector:".step",containerClass:"",canvasClass:"",areaClass:"",notSupportedClass:"not-supported",fullscreen:!0,animation:{transformOrigin:"top left",transitionProperty:f(e(n("transform")))+f(e(n("perspective")))+"opacity",transitionDuration:"1s",transitionDelay:"500ms",transitionTimingFunction:"ease-in-out",transformStyle:"preserve-3d"},transitionDuration:1500},p={beforeChange:1,beforeInitStep:1,initStep:1,beforeInit:1,afterInit:1,beforeDeinit:1,afterDeinit:1,applyStep:1,unapplyStep:1,setInactive:1,beforeActive:1,setActive:1,selectInitialStep:1,selectPrev:1,selectNext:1,selectHome:1,selectEnd:1,idle:1,applyTarget:1};for(var q in p)o[q]=[];var r={init:h,initialized:m,deinit:function(){},css:k,pfx:n,defaults:i,register:j,dataset:l};a.fn.jmpress=function(b){function c(){var c=a(this).data("jmpressmethods");if(c&&c[b])return c[b].apply(this,Array.prototype.slice.call(arguments,1));if(r[b])return r[b].apply(this,Array.prototype.slice.call(arguments,1));if(p[b]&&c){var d=c.settings(),e=Array.prototype.slice.call(arguments,1)[0];a.isFunction(e)&&(d[b]=d[b]||[],d[b].push(e))}else{if("object"==typeof b||!b)return h.apply(this,arguments);a.error("Method "+b+" does not exist on jQuery.jmpress")}return this}var d,e=arguments;return a(this).each(function(a,b){d=c.apply(b,e)}),d},a.extend({jmpress:function(b){if(r[b])return r[b].apply(this,Array.prototype.slice.call(arguments,1));if(p[b]){var c=Array.prototype.slice.call(arguments,1)[0];a.isFunction(c)?o[b].push(c):a.error("Second parameter should be a function: $.jmpress( callbackName, callbackFunction )")}else a.error("Method "+b+" does not exist on jQuery.jmpress")}})}(jQuery,document,window),function(a){"use strict";function b(b,c,d,e){var f;return b.each(function(b,g){return e&&(f=c(g,d,e))?!1:a(g).is(d)?(f=g,!1):!e&&(f=c(g,d,e))?!1:void 0}),f}function c(d,e,f){var g=a(d).children();return f&&(g=a(g.get().reverse())),b(g,c,e,f)}function d(d,e,f){return b(a(d)[f?"prevAll":"nextAll"](),c,e,f)}function e(b,c,e){var f,g=a(b).parents();return g=a(g.get()),a.each(g.get(),function(b,g){return e&&a(g).is(c)?(f=g,!1):(f=d(g,c,e),f?!1:void 0)}),f}a.fn.near=function(b,f){var g=[];return a(this).each(function(a,h){var i=(f?!1:c(h,b,f))||d(h,b,f)||e(h,b,f);i&&g.push(i)}),a(g)}}(jQuery,document,window),function(a,b,c,d){"use strict";function e(a){return Math.round(1e4*a)/1e4+""}var f={3:{transform:function(b,c){var d="translate(-50%,-50%)";a.each(c,function(a,b){var c,f=["X","Y","Z"];if("translate"===b[0])d+=" translate3d("+e(b[1]||0)+"px,"+e(b[2]||0)+"px,"+e(b[3]||0)+"px)";else if("rotate"===b[0]){var g=b[4]?[1,2,3]:[3,2,1];for(c=0;3>c;c++)d+=" rotate"+f[g[c]-1]+"("+e(b[g[c]]||0)+"deg)"}else if("scale"===b[0])for(c=0;3>c;c++)d+=" scale"+f[c]+"("+e(b[c+1]||1)+")"}),a.jmpress("css",b,a.extend({},{transform:d}))}},2:{transform:function(b,c){var d="translate(-50%,-50%)";a.each(c,function(a,b){var c=["X","Y"];if("translate"===b[0])d+=" translate("+e(b[1]||0)+"px,"+e(b[2]||0)+"px)";else if("rotate"===b[0])d+=" rotate("+e(b[3]||0)+"deg)";else if("scale"===b[0])for(var f=0;2>f;f++)d+=" scale"+c[f]+"("+e(b[f+1]||1)+")"}),a.jmpress("css",b,a.extend({},{transform:d}))}},1:{transform:function(b,c){var d={top:0,left:0};a.each(c,function(a,b){"translate"===b[0]&&(d.left=Math.round(b[1]||0)+"px",d.top=Math.round(b[2]||0)+"px")}),b.animate(d,1e3)}}},g=function(){return a.jmpress("pfx","perspective")?f[3]:a.jmpress("pfx","transform")?f[2]:f[1]}();a.jmpress("defaults").reasonableAnimation={},a.jmpress("initStep",function(b,c){var d=c.data,e=c.stepData,f=parseFloat;a.extend(e,{x:f(d.x)||0,y:f(d.y)||0,z:f(d.z)||0,r:f(d.r)||0,phi:f(d.phi)||0,rotate:f(d.rotate)||0,rotateX:f(d.rotateX)||0,rotateY:f(d.rotateY)||0,rotateZ:f(d.rotateZ)||0,revertRotate:!1,scale:f(d.scale)||1,scaleX:f(d.scaleX)||!1,scaleY:f(d.scaleY)||!1,scaleZ:f(d.scaleZ)||1})}),a.jmpress("afterInit",function(b,c){var d=c.settings.stepSelector,e=c.current;e.perspectiveScale=1,e.maxNestedDepth=0;for(var f=a(c.jmpress).find(d).children(d);f.length;)e.maxNestedDepth++,f=f.children(d)}),a.jmpress("applyStep",function(b,c){a.jmpress("css",a(b),{position:"absolute",transformStyle:"preserve-3d"}),c.parents.length>0&&a.jmpress("css",a(b),{top:"50%",left:"50%"});var d=c.stepData,e=[["translate",d.x||d.r*Math.sin(d.phi*Math.PI/180),d.y||-d.r*Math.cos(d.phi*Math.PI/180),d.z],["rotate",d.rotateX,d.rotateY,d.rotateZ||d.rotate,!0],["scale",d.scaleX||d.scale,d.scaleY||d.scale,d.scaleZ||d.scale]];g.transform(b,e)}),a.jmpress("setActive",function(b,c){var e=c.target,f=c.stepData,g=e.transform=[];e.perspectiveScale=1;for(var h=c.current.maxNestedDepth;h>(c.parents.length||0);h--)g.push(["scale"],["rotate"],["translate"]);g.push(["scale",1/(f.scaleX||f.scale),1/(f.scaleY||f.scale),1/f.scaleZ]),g.push(["rotate",-f.rotateX,-f.rotateY,-(f.rotateZ||f.rotate)]),g.push(["translate",-(f.x||f.r*Math.sin(f.phi*Math.PI/180)),-(f.y||-f.r*Math.cos(f.phi*Math.PI/180)),-f.z]),e.perspectiveScale*=f.scaleX||f.scale,a.each(c.parents,function(b,c){var d=a(c).data("stepData");g.push(["scale",1/(d.scaleX||d.scale),1/(d.scaleY||d.scale),1/d.scaleZ]),g.push(["rotate",-d.rotateX,-d.rotateY,-(d.rotateZ||d.rotate)]),g.push(["translate",-(d.x||d.r*Math.sin(d.phi*Math.PI/180)),-(d.y||-d.r*Math.cos(d.phi*Math.PI/180)),-d.z]),e.perspectiveScale*=d.scaleX||d.scale}),a.each(g,function(a,b){function e(e){c.current["rotate"+e+"-"+a]===d&&(c.current["rotate"+e+"-"+a]=b[e]||0);var f=c.current["rotate"+e+"-"+a],g=b[e]||0,h=f%360,i=g%360;0>h&&(h+=360),0>i&&(i+=360);var j=i-h;-180>j?j+=360:j>180&&(j-=360),c.current["rotate"+e+"-"+a]=b[e]=f+j}"rotate"===b[0]&&(e(1),e(2),e(3))})}),a.jmpress("applyTarget",function(b,c){var d,e=c.target,f=(c.stepData,c.settings),h=1.3*e.perspectiveScale<c.current.perspectiveScale,i=e.perspectiveScale>1.3*c.current.perspectiveScale,j=-1;a.each(e.transform,function(a,b){return b.length<=1||"rotate"===b[0]&&0===b[1]%360&&0===b[2]%360&&0===b[3]%360?void 0:"scale"!==b[0]?!1:(j=a,void 0)}),j!==c.current.oldLastScale&&(h=i=!1,c.current.oldLastScale=j);var k=[];if(-1!==j)for(;j>=0;)"scale"===e.transform[j][0]&&(k.push(e.transform[j]),e.transform[j]=["scale"]),j--;var l=f.animation;f.reasonableAnimation[c.reason]&&(l=a.extend({},l,f.reasonableAnimation[c.reason])),d={perspective:Math.round(1e3*e.perspectiveScale)+"px"},d=a.extend({},l,d),h||(d.transitionDelay="0s"),c.beforeActive||(d.transitionDuration="0s",d.transitionDelay="0s"),a.jmpress("css",c.area,d),g.transform(c.area,k),d=a.extend({},l),i||(d.transitionDelay="0s"),c.beforeActive||(d.transitionDuration="0s",d.transitionDelay="0s"),c.current.perspectiveScale=e.perspectiveScale,a.jmpress("css",c.canvas,d),g.transform(c.canvas,e.transform)})}(jQuery,document,window),function(a){"use strict";var b=a.jmpress,c="activeClass",d="nestedActiveClass",e=b("defaults");e[d]="nested-active",e[c]="active",b("setInactive",function(b,e){var f=e.settings,g=f[c],h=f[d];g&&a(b).removeClass(g),h&&a.each(e.parents,function(b,c){a(c).removeClass(h)})}),b("setActive",function(b,e){var f=e.settings,g=f[c],h=f[d];g&&a(b).addClass(g),h&&a.each(e.parents,function(b,c){a(c).addClass(h)})})}(jQuery,document,window),function(a){"use strict";function b(b,c){return a(this).find(c.settings.stepSelector).first()}function c(b,c,d,e){if(!c)return!1;var f=d.settings.stepSelector;c=a(c);do{var g=c.near(f,e);if((0===g.length||0===g.closest(b).length)&&(g=a(b).find(f)[e?"last":"first"]()),!g.length)return!1;c=g}while(c.data("stepData").exclude);return c}var d=a.jmpress;d("initStep",function(a,b){b.stepData.exclude=b.data.exclude&&-1===["false","no"].indexOf(b.data.exclude)}),d("selectInitialStep",b),d("selectHome",b),d("selectEnd",function(b,c){return a(this).find(c.settings.stepSelector).last()}),d("selectPrev",function(a,b){return c(this,a,b,!0)}),d("selectNext",function(a,b){return c(this,a,b)})}(jQuery,document,window),function(a,b,c,d){"use strict";function e(){return""+Math.round(1e5*Math.random(),0)}function f(b){try{var e=a("#"+c.location.hash.replace(/^#\/?/,""));return e.length>0&&e.is(b.stepSelector)?e:d}catch(f){}}function g(a){var b="#/"+a;c.history&&c.history.pushState?c.location.hash!==b&&c.history.pushState({},"",b):c.location.hash!==b&&(c.location.hash=b)}var h=a.jmpress,i="a[href^=#]";h("defaults").hash={use:!0,update:!0,bindChange:!0},h("selectInitialStep",function(b,d){var h=d.settings,j=h.hash,k=d.current,l=a(this);return d.current.hashNamespace=".jmpress-"+e(),j.use?(j.bindChange&&(a(c).bind("hashchange"+k.hashNamespace,function(a){var b=f(h);l.jmpress("initialized")&&l.jmpress("scrollFix"),b&&b.length&&(b.attr("id")!==l.jmpress("active").attr("id")&&l.jmpress("select",b),g(b.attr("id"))),a.preventDefault()}),a(i).on("click"+k.hashNamespace,function(b){var c=a(this).attr("href");try{a(c).is(h.stepSelector)&&(l.jmpress("select",c),b.preventDefault(),b.stopPropagation())}catch(d){}})),f(h)):void 0}),h("afterDeinit",function(b,d){a(i).off(d.current.hashNamespace),a(c).unbind(d.current.hashNamespace)}),h("setActive",function(b,c){var d=c.settings,e=c.current;d.hash.use&&d.hash.update&&(clearTimeout(e.hashtimeout),e.hashtimeout=setTimeout(function(){g(a(c.delegatedFrom).attr("id"))},d.transitionDuration+200))})}(jQuery,document,window),function(a,b,c,d){"use strict";function e(){return""+Math.round(1e5*Math.random(),0)}function f(a){a.preventDefault(),a.stopPropagation()}var g=a.jmpress,h="next",i="prev";g("defaults").keyboard={use:!0,keys:{33:i,37:i,38:i,9:h+":"+i,32:h,34:h,39:h,40:h,36:"home",35:"end"},ignore:{INPUT:[32,37,38,39,40],TEXTAREA:[32,37,38,39,40],SELECT:[38,40]},tabSelector:"a[href]:visible, :input:visible"},g("afterInit",function(c,g){var h=g.settings,i=h.keyboard,j=i.ignore,k=g.current,l=a(this);h.fullscreen||l.attr("tabindex",0),k.keyboardNamespace=".jmpress-"+e(),a(h.fullscreen?b:l).bind("keypress"+k.keyboardNamespace,function(a){for(var b in j)if(a.target.nodeName===b&&-1!==j[b].indexOf(a.which))return;(a.which>=37&&a.which<=40||32===a.which)&&f(a)}),a(h.fullscreen?b:l).bind("keydown"+k.keyboardNamespace,function(b){var c=a(b.target);if((h.fullscreen||c.closest(l).length)&&i.use){for(var e in j)if(c[0].nodeName===e&&-1!==j[e].indexOf(b.which))return;var g,k=!1;if(9===b.which){if(c.closest(l.jmpress("active")).length?(g=c.near(i.tabSelector,b.shiftKey),a(g).closest(h.stepSelector).is(l.jmpress("active"))||(g=d)):b.shiftKey?k=!0:g=l.jmpress("active").find("a[href], :input").filter(":visible").first(),g&&g.length>0)return g.focus(),l.jmpress("scrollFix"),f(b),void 0;b.shiftKey&&(k=!0)}var m=i.keys[b.which];"string"==typeof m?(-1!==m.indexOf(":")&&(m=m.split(":"),m=b.shiftKey?m[1]:m[0]),l.jmpress(m),f(b)):a.isFunction(m)?m.call(l,b):m&&(l.jmpress.apply(l,m),f(b)),k&&(g=l.jmpress("active").find("a[href], :input").filter(":visible").last(),g.focus(),l.jmpress("scrollFix"))}})}),g("afterDeinit",function(c,d){a(b).unbind(d.current.keyboardNamespace)})}(jQuery,document,window),function(a){"use strict";function b(){return""+Math.round(1e5*Math.random(),0)}var c=a.jmpress;c("defaults").mouse={clickSelects:!0},c("afterInit",function(c,d){var e=d.settings,f=e.stepSelector,g=d.current,h=a(this);g.clickableStepsNamespace=".jmpress-"+b(),h.bind("click"+g.clickableStepsNamespace,function(b){if(e.mouse.clickSelects&&!g.userZoom){var c=a(b.target).closest(f);c.is(h.jmpress("active"))||c.length&&(h.jmpress("select",c[0],"click"),b.preventDefault(),b.stopPropagation())}})}),c("afterDeinit",function(b,c){a(this).unbind(c.current.clickableStepsNamespace)})}(jQuery,document,window);