Team:Valencia UPV/Core:JS/gwdpagedeck min.js

From 2014.igem.org

Revision as of 12:06, 11 October 2014 by Alejovigno (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

(function(){"use strict";var k=["-ms-","-moz-","-webkit-",""],l=function(a,c){for(var b,d,e=0;e<k.length;++e)b=k[e]+"transition-duration",d=""+c,a.style.setProperty(b,d)};function m(a,c,b,d,e,g,f){this.h=a;this.e=c;this.o=b;a=d||"none";this.i=e="none"===a?0:e||1E3;this.d=g||"linear";this.f=[];if(e){g=f||"top";if(f=this.h){f.classList.add("gwd-page");f.classList.add("center");f="center";if("push"==a)switch(g){case "top":f="top";break;case "bottom":f="bottom";break;case "left":f="left";break;case "right":f="right"}this.f.push(f);"fade"==a&&this.f.push("transparent")}f=this.e;e="center";if("none"!=a&&"fade"!=a)switch(g){case "top":e="bottom";break;case "bottom":e="top"; break;case "left":e="right";break;case "right":e="left"}f.classList.add(e);f.classList.add("gwd-page");"fade"==a&&f.classList.add("transparent")}}m.prototype.start=function(){if(this.i){var a=this.h,c=this.e;n(c,this.r.bind(this));a&&(l(a,this.i+"ms"),a.classList.add(this.d));l(c,this.i+"ms");c.classList.add(this.d);c.setAttribute("gwd-reflow",c.offsetWidth);if(a)for(var b=0;b<this.f.length;++b)a.classList.add(this.f[b]);p(c)}else this.o()}; var q=function(a,c,b,d){b="transform: matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,"+b+","+d+",0,1);";return a+"."+c+"{-webkit-"+b+"-moz-"+b+"-ms-"+b+b+"}"},r="center top bottom left right transparent".split(" "),p=function(a){r.forEach(function(c){a.classList.remove(c)})},n=function(a,c){var b=function(){a.removeEventListener("webkitTransitionEnd",b);a.removeEventListener("transitionend",b);c()};a.addEventListener("webkitTransitionEnd",b);a.addEventListener("transitionend",b)}; m.prototype.r=function(){var a=this.h;a&&(p(a),l(a,0),a.classList.remove(this.d));l(this.e,0);this.e.classList.remove(this.d);this.o()};var s=function(a,c,b){var d;b?(d=document.createEvent("CustomEvent"),d.initCustomEvent(a,!0,!0,b)):(d=document.createEvent("Event"),d.initEvent(a,!0,!0));c.dispatchEvent(d)};document.registerElement&&document.registerElement("gwd-pagedeck",{prototype:Object.create(HTMLDivElement.prototype,{createdCallback:{value:function(){window.addEventListener("WebComponentsReady",this.handleWebComponentsReadyEvent_.bind(this),!1);this.l=this.forwardDeviceEventsToCurrentPage_.bind(this,"shake");this.k=this.forwardDeviceEventsToCurrentPage_.bind(this,"rotatetoportrait");this.j=this.forwardDeviceEventsToCurrentPage_.bind(this,"rotatetolandscape");this.a=[];this.m=this.handlePageLoaded_.bind(this); this.q=this.endPageTransition_.bind(this);this.c=this.n=null;this.b=-1;this.g=!1;this.classList.add("gwd-pagedeck")},enumerable:!0},handleWebComponentsReadyEvent_:{value:function(){this.a=Array.prototype.slice.call(this.querySelectorAll("div[is=gwd-page]"));for(this.a.forEach(function(a){a.classList.add("gwd-page")});this.firstChild;)this.removeChild(this.firstChild);-1==this.b&&void 0!==this.p&&this.goToPage(this.p)},enumerable:!1},attachedCallback:{value:function(){if(!this.n){var a;a=this.offsetWidth; var c=this.offsetHeight,b;b=this.id;b=(b&&"#")+b+".gwd-pagedeck > .gwd-page";a=q(b,"center",0,0)+q(b,"top",0,c)+q(b,"bottom",0,-c)+q(b,"left",a,0)+q(b,"right",-a,0);c=document.createElement("style");void 0!==c.cssText?c.cssText=a:c.innerHTML=a;document.head.appendChild(c);this.n=c}this.addEventListener("pageload",this.m,!1);document.body.addEventListener("shake",this.l,!0);document.body.addEventListener("rotatetoportrait",this.k,!0);document.body.addEventListener("rotatetolandscape",this.j,!0)},enumerable:!0}, detachedCallback:{value:function(){this.removeEventListener("pageload",this.m,!1);document.body.removeEventListener("shake",this.l,!0);document.body.removeEventListener("rotatetoportrait",this.k,!0);document.body.removeEventListener("rotatetolandscape",this.j,!0)},enumerable:!0},goToPageImpl_:{value:function(a,c,b,d,e){if(!(this.b==a||0>a||a>this.a.length-1||this.c)){var g=this.a[this.b],f=this.a[a];this.b=a;this.c=new m(g,f,this.q,c,b,d,e);this.appendChild(f);var h=f.gwdLoad&&!f.gwdIsLoaded();this.g= h;setTimeout(function(){h?f.gwdLoad():this.startPageTransition_()}.bind(this),0)}},enumerable:!1},handlePageLoaded_:{value:function(a){this.g&&a.target.parentNode==this&&(this.startPageTransition_(),this.g=!1)}},startPageTransition_:{value:function(){s("pagetransitionstart",this);this.c.start()},enumerable:!1},endPageTransition_:{value:function(){this.c&&(this.c=null);var a=this.firstChild,c=this.lastChild,b=a==c;s("pagetransitionend",this,{outgoingPage:b?null:a,incomingPage:c});b||this.removeChild(a); c.gwdPresent()},enumerable:!1},findPageIndexByAttributeValue:{value:function(a,c){for(var b=this.a.length,d,e=0;e=this.a.length&&(f=a?0:g);this.goToPageImpl_(f,c,b,d,e)},enumerable:!0},goToPreviousPage:{value:function(a,c,b,d,e){var g=this.b,f=this.a.length,h=g-1;0>h&&(h=a?f-1:g);this.goToPageImpl_(h,c, b,d,e)},enumerable:!0},goToPage:{value:function(a,c,b,d,e){this.a.length?(a="number"==typeof a?a:this.findPageIndexByAttributeValue("id",a),0<=a&&this.goToPageImpl_(a,c,b,d,e)):this.p=a},enumerable:!0},currentIndex:{get:function(){return 0<=this.b?this.b:void 0},enumerable:!0},getPage:{value:function(a){if("number"!=typeof a){if(!a)return null;a=this.findPageIndexByAttributeValue("id",a)}return 0>a||a>this.a.length-1?null:this.a[a]},enumerable:!0},getDefaultPage:{value:function(){var a=this.getAttribute("default-page"); return a?this.getPage(this.findPageIndexByAttributeValue("id",a)):this.getPage(0)},enumerable:!0},getOrientationSpecificPage:{value:function(a,c){var b=this.getPage(c),d=b.getAttribute("alt-orientation-page");if(!d)return b;var e=b.isPortrait(),g=1==a,d=this.getPage(d);return g==e?b:d},enumerable:!0},forwardDeviceEventsToCurrentPage_:{value:function(a,c){if(c.target==document.body){var b=this.getPage(this.b);s(a,b)}},enumerable:!1}}),"extends":"div"});})()