Advertisement
Chriser_

amp-lightbox-0.1.js

Jun 10th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (self.AMP=self.AMP||[]).push({n:"amp-lightbox",v:"1528391646530",f:(function(AMP){var f;function l(a,b){function c(){}c.prototype=b.prototype;a.prototype=new c;a.prototype.constructor=a;for(var d in b)if(Object.defineProperties){var e=Object.getOwnPropertyDescriptor(b,d);e&&Object.defineProperty(a,d,e)}else a[d]=b[d]}function n(a,b){b=void 0===b?"":b;try{return decodeURIComponent(a)}catch(c){return b}};var p=/(?:^[#?]?|&)([^=&]+)(?:=([^&]*))?/g;function q(a){var b=Object.create(null);if(!a)return b;for(var c;c=p.exec(a);){var d=n(c[1],c[1]),e=c[2]?n(c[2],c[2]):"";b[d]=e}return b};var r="";self.log=self.log||{user:null,dev:null,userForEmbed:null};var t=self.log;function u(){var a,b=Object.create(null);a&&Object.assign(b,a);return b};function v(a,b){a=a.__AMP_TOP||a;return w(a,b)}function x(a,b){a=y(a);a=y(a);a=a.isSingleDoc()?a.win:a;return w(a,b)}function y(a){return a.nodeType?v((a.ownerDocument||a).defaultView,"ampdoc").getAmpDoc(a):a}function w(a,b){z(a,b);var c=a.services;c||(c=a.services={});var d=c;a=d[b];a.obj||(a.obj=new a.ctor(a.context),a.ctor=null,a.context=null,a.resolve&&a.resolve(a.obj));return a.obj}function z(a,b){a=a.services&&a.services[b];return!(!a||!a.ctor&&!a.obj)};/*
  2.  https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
  3. var A,B="Webkit webkit Moz moz ms O o".split(" ");function C(a,b,c){if(2>b.length?0:0==b.lastIndexOf("--",0))return b;A||(A=u());var d=A[b];if(!d||c){d=b;if(void 0===a[b]){var e=b.charAt(0).toUpperCase()+b.slice(1);a:{for(var g=0;g<B.length;g++){var m=B[g]+e;if(void 0!==a[m]){e=m;break a}}e=""}var h=e;void 0!==a[h]&&(d=h)}c||(A[b]=d)}return d}function D(a,b,c){var d;(b=C(a.style,b,void 0))&&(a.style[b]=d?c+d:c)}
  4. function aa(a){var b={display:"",opacity:0,transition:"opacity 0.1s ease-in"},c;for(c in b)D(a,c,b[c])};function E(){this.l=null}f=E.prototype;f.add=function(a){var b=this;this.l||(this.l=[]);this.l.push(a);return function(){b.remove(a)}};f.remove=function(a){this.l&&(a=this.l.indexOf(a),-1<a&&this.l.splice(a,1))};f.removeAll=function(){this.l&&(this.l.length=0)};f.fire=function(a){if(this.l)for(var b=this.l,c=0;c<b.length;c++)(0,b[c])(a)};f.getHandlerCount=function(){return this.l?this.l.length:0};function ba(a,b){function c(){d=0;var m=500-(a.Date.now()-e);if(0<m)d=a.setTimeout(c,m);else{var h=g;g=null;b.apply(null,h)}}var d=0,e=0,g=null;return function(b){for(var h=[],k=0;k<arguments.length;++k)h[k-0]=arguments[k];e=a.Date.now();g=h;d||(d=a.setTimeout(c,500))}};function ca(a,b){for(var c=0;c<a.length;c++)if(b(a[c],c,a))return c;return-1};function F(a,b,c){var d=this;this.pa=v(a,"timer");this.ta=b;this.sa=c||0;this.J=-1;this.Y=0;this.ca=!1;this.qa=function(){return d.T()}}F.prototype.isPending=function(){return-1!=this.J};F.prototype.schedule=function(a){var b=a||this.sa;this.ca&&10>b&&(b=10);var c=Date.now()+b;return!this.isPending()||-10>c-this.Y?(this.cancel(),this.Y=c,this.J=this.pa.delay(this.qa,b),!0):!1};F.prototype.T=function(){this.J=-1;this.Y=0;this.ca=!0;this.ta();this.ca=!1};
  5. F.prototype.cancel=function(){this.isPending()&&(this.pa.cancel(this.J),this.J=-1)};function da(a,b,c,d){this.type=a;this.data=b;this.time=c;this.event=d}
  6. function G(a,b){this.w=a;this.c=[];this.C=[];this.m=[];this.h=[];this.j=null;this.ya=b;this.V=!1;this.T=new F(a.ownerDocument.defaultView,this.ka.bind(this));this.ma=new E;this.I=Object.create(null);this.ja=this.xa.bind(this);this.ha=this.va.bind(this);this.ia=this.wa.bind(this);this.ga=this.ua.bind(this);this.w.addEventListener("touchstart",this.ja);this.w.addEventListener("touchend",this.ha);this.w.addEventListener("touchmove",this.ia);this.w.addEventListener("touchcancel",this.ga);this.Z=!1}
  7. function ea(a){var b;b=void 0===b?!1:b;var c=a.__AMP_Gestures;c||(c=new G(a,b),a.__AMP_Gestures=c);return c}f=G.prototype;f.cleanup=function(){this.w.removeEventListener("touchstart",this.ja);this.w.removeEventListener("touchend",this.ha);this.w.removeEventListener("touchmove",this.ia);this.w.removeEventListener("touchcancel",this.ga);delete this.w.__AMP_Gestures;this.T.cancel()};f.onGesture=function(a,b){var c=new a(this),d=c.getType(),e=this.I[d];e||(this.c.push(c),e=new E,this.I[d]=e);return e.add(b)};
  8. f.removeGesture=function(a){var b=(new a(this)).getType();if(a=this.I[b]){a.removeAll();a=ca(this.c,function(a){return a.getType()==b});if(0>a)return!1;this.c.splice(a,1);this.m.splice(a,1);this.h.splice(a,1);this.C.splice(a,1);delete this.I[b];return!0}return!1};f.onPointerDown=function(a){return this.ma.add(a)};
  9. f.xa=function(a){var b=Date.now();this.V=!1;this.ma.fire(a);for(var c=0;c<this.c.length;c++)if(!this.m[c]&&(this.h[c]&&this.h[c]<b&&H(this,c),this.c[c].onTouchStart(a))){var d=c;this.C[d]=!0;this.h[d]=0}I(this,a)};f.wa=function(a){for(var b=Date.now(),c=0;c<this.c.length;c++)this.C[c]&&(this.h[c]&&this.h[c]<b?H(this,c):this.c[c].onTouchMove(a)||H(this,c));I(this,a)};
  10. f.va=function(a){for(var b=Date.now(),c=0;c<this.c.length;c++)this.C[c]&&(this.h[c]&&this.h[c]<b?H(this,c):(this.c[c].onTouchEnd(a),(!this.h[c]||this.h[c]<b)&&H(this,c)));I(this,a)};f.ua=function(a){for(var b=0;b<this.c.length;b++){var c=b;this.m[c]=0;H(this,c)}I(this,a)};function I(a,b){var c=!!a.j||a.V;a.V=!1;if(!c)for(var d=Date.now(),e=0;e<a.c.length;e++)if(a.m[e]||a.h[e]&&a.h[e]>=d){c=!0;break}c&&(b.stopPropagation(),a.ya||b.preventDefault());a.Z&&(a.Z=!1,a.ka())}
  11. f.ka=function(){for(var a=Date.now(),b=-1,c=0;c<this.c.length;c++)if(!this.m[c])this.h[c]&&this.h[c]<a&&H(this,c);else if(-1==b||this.m[c]>this.m[b])b=c;if(-1!=b){for(var d=0,c=0;c<this.c.length;c++)!this.m[c]&&this.C[c]&&(d=Math.max(d,this.h[c]-a));if(2>d){for(var a=b,c=this.c[a],e=0;e<this.c.length;e++)if(e!=a){var g=e;this.m[g]=0;H(this,g)}this.m[a]=0;this.h[a]=0;this.j=c;c.acceptStart()}else this.T.schedule(d)}};function H(a,b){a.C[b]=!1;a.h[b]=0;a.m[b]||a.c[b].acceptCancel()}
  12. function J(a,b){this.za=a;this.S=b}f=J.prototype;f.getType=function(){return this.za};f.signalReady=function(a){var b=this.S;if(b.j)this.acceptCancel();else{for(var c=Date.now(),d=0;d<b.c.length;d++)b.c[d]==this&&(b.m[d]=c+a,b.h[d]=0);b.Z=!0}};f.signalPending=function(a){var b=this.S;if(b.j)this.acceptCancel();else for(var c=Date.now(),d=0;d<b.c.length;d++)b.c[d]==this&&(b.h[d]=c+a)};f.signalEnd=function(){var a=this.S;a.j==this&&(a.j=null,a.V=!0)};
  13. f.signalEmit=function(a,b){var c=this.S.I[this.getType()];c&&c.fire(new da(this.getType(),a,Date.now(),b))};f.acceptStart=function(){};f.acceptCancel=function(){};f.onTouchStart=function(){return!1};f.onTouchMove=function(){return!1};f.onTouchEnd=function(){};function K(a,b,c){1>b&&(b=1);var d=a/b,e=.5+Math.min(b/33.34,.5);return d*e+c*(1-e)};function L(a,b,c,d){J.call(this,a,b);this.P=c;this.U=d;this.j=!1;this.F=this.D=this.$=this.R=this.oa=this.ba=this.aa=this.H=this.G=this.L=this.K=0}l(L,J);f=L.prototype;f.onTouchStart=function(a){return(a=a.touches)&&1==a.length?(this.oa=Date.now(),this.K=a[0].clientX,this.L=a[0].clientY,!0):!1};
  14. f.onTouchMove=function(a){var b=a.touches;if(b&&1==b.length){var c=b[0],b=c.clientX,c=c.clientY;this.G=b;this.H=c;if(this.j)M(this,!1,!1,a);else if(a=Math.abs(b-this.K),b=Math.abs(c-this.L),this.P&&this.U)(8<=a||8<=b)&&this.signalReady(-10);else if(this.P)if(8<=a&&a>b)this.signalReady(-10);else{if(8<=b)return!1}else if(this.U)if(8<=b&&b>a)this.signalReady(-10);else{if(8<=a)return!1}else return!1;return!0}return!1};f.onTouchEnd=function(a){this.j&&(this.j=!1,M(this,!1,!0,a),this.signalEnd())};
  15. f.acceptStart=function(){this.j=!0;this.aa=this.K;this.ba=this.L;this.$=this.oa;this.K=this.G;this.L=this.H;M(this,!0,!1,null)};f.acceptCancel=function(){this.j=!1};function M(a,b,c,d){a.R=Date.now();var e=a.R-a.$;if(!c&&4<e||c&&16<e)a.D=K(a.G-a.aa,e,a.D),a.F=K(a.H-a.ba,e,a.F),a.D=1E-4<Math.abs(a.D)?a.D:0,a.F=1E-4<Math.abs(a.F)?a.F:0,a.aa=a.G,a.ba=a.H,a.$=a.R;a.signalEmit({first:b,last:c,time:a.R,deltaX:a.P?a.G-a.K:0,deltaY:a.U?a.H-a.L:0,velocityX:a.P?a.D:0,velocityY:a.U?a.F:0},d)}
  16. function N(a){L.call(this,"swipe-xy",a,!0,!0)}l(N,L);function O(a){var b;b=AMP.BaseElement.call(this,a)||this;b.ea=null;b.o=null;b.fa=null;b.W=null;b.X=-1;b.M=!1;b.N=null;b.B=!1;b.A=0;b.la=0;b.da=null;b.O=ba(b.win,function(){var a=b.o;b.scheduleLayout(a);b.scheduleResume(a)});return b}l(O,AMP.BaseElement);f=O.prototype;
  17. f.buildCallback=function(){this.element.classList.add("i-amphtml-overlay");var a;a:{a=this.element;if(a.nodeType){var b=(a.ownerDocument||a).defaultView;if(b=b!=(b.__AMP_TOP||b)&&z(b,"action")?w(b,"action"):null){a=b;break a}}a=x(a,"action")}this.fa=a;this.getAmpDoc().win!=this.win&&P(this.getAmpDoc().win,this.win.document.body);this.registerAction("open",this.activate.bind(this));this.registerAction("close",this.close.bind(this))};function Q(a){R(a,!0).forEach(function(b){a.setAsOwner(b)})}
  18. function R(a,b){if(!a.W||b){var c;if(c=a.element.getElementsByClassName("i-amphtml-element")){for(var d=Array(c.length),e=0;e<c.length;e++)d[e]=c[e];c=d}else c=[];a.W=c}return a.W}
  19. function fa(a){if(!a.o){a.B=a.element.hasAttribute("scrollable");var b=a.getRealChildren();a.o=a.element.ownerDocument.createElement("div");a.B||a.applyFillContent(a.o);a.element.appendChild(a.o);b.forEach(function(b){a.o.appendChild(b)});a.B&&(Q(a),a.element.addEventListener("amp:dom-update",function(){Q(a);S(a,a.A,a.A)}),a.element.addEventListener("scroll",a.na.bind(a)));if(!a.B){var c=ea(a.element);c.onGesture(N,function(){})}}}f.layoutCallback=function(){return Promise.resolve()};
  20. f.activate=function(){var a=this;this.M||(fa(this),this.N=this.ra.bind(this),this.win.document.documentElement.addEventListener("keydown",this.N),this.getViewport().enterLightboxMode(this.element).then(function(){return ga(a)}))};function ha(a){var b=a.o.querySelector("[autofocus]");if(b)try{b.focus()}catch(c){}}
  21. function ga(a){a.B&&D(a.element,"webkitOverflowScrolling","touch");aa(a.element);ha(a);a.mutateElement(function(){D(a.element,"opacity","")});var b=a.o;a.B?(a.na(),S(a,a.A,a.A)):a.updateInViewport(b,!0);a.element.addEventListener("transitionend",a.O);a.element.addEventListener("animationend",a.O);a.scheduleLayout(b);a.scheduleResume(b);T(a,"lightboxOpen");x(a.getAmpDoc(),"history").push(a.close.bind(a)).then(function(b){a.X=b});a.M=!0}f.ra=function(a){27==a.keyCode&&this.close()};
  22. f.close=function(){var a=this;this.M&&(this.B&&D(this.element,"webkitOverflowScrolling",""),this.getViewport().leaveLightboxMode(this.element).then(function(){a.collapse();-1!=a.X&&x(a.getAmpDoc(),"history").pop(a.X);a.win.document.documentElement.removeEventListener("keydown",a.N);a.element.removeEventListener("transitionend",a.O);a.element.removeEventListener("animationend",a.O);a.N=null;a.schedulePause(a.o);a.M=!1;T(a,"lightboxClose")}))};
  23. f.na=function(){var a=this.element.scrollTop||1;this.A=this.element.scrollTop=a;null===this.da&&U(this,a)};function U(a,b){a.da=v(a.win,"timer").delay(function(){if(30>Math.abs(b-a.A)){a.da=null;var c=a.A;S(a,c,a.la);a.la=c;a.A=c}else U(a,a.A)},100)}function S(a,b,c){var d=[];V(a,b,function(b){d.push(b);a.updateInViewport(b,!0);a.scheduleLayout(b)});c!=b&&V(a,c,function(b){d.includes(b)||a.updateInViewport(b,!1)})}
  24. function V(a,b,c){a.ea||(a.ea={width:a.element.clientWidth,height:a.element.clientHeight});for(var d=a.ea.height,e=R(a),g=0;g<e.length;g++){for(var m=e[g],h=0,k=m;k&&a.element.contains(k);k=k.offsetParent)h+=k.offsetTop;var Y=2*d;h+m.offsetHeight>=b-Y&&h<=b+Y&&c(m)}}
  25. function T(a,b){var c;var d=a.win;c="amp-lightbox."+b;var e={},g={detail:e};Object.assign(g,void 0);"function"==typeof d.CustomEvent?c=new d.CustomEvent(c,g):(d=d.document.createEvent("CustomEvent"),d.initCustomEvent(c,!!g.bubbles,!!g.cancelable,e),c=d);a.fa.trigger(a.element,b,c,100)}
  26. function P(a,b){v(a,"vsync").run({measure:function(c){c.alreadyTransparent="rgba(0, 0, 0, 0)"==(a.getComputedStyle(b)||u())["background-color"]},mutate:function(a){if(!a.alreadyTransparent){if(!t.user)throw Error("failed to call initLogConstructor");t.user.warn("amp-lightbox","The background of the <body> element has been forced to transparent. If you need to set background, use an intermediate container.")}a={background:"transparent"};for(var c in a)b.style.setProperty(C(a,c),a[c].toString(),"important")}},
  27. {})}var W=self,X;if(W.AMP_MODE)X=W.AMP_MODE;else{var Z=q(W.location.originalHash||W.location.hash),ia=q(W.location.search);r||(r=W.AMP_CONFIG&&W.AMP_CONFIG.v?W.AMP_CONFIG.v:"011528391646530");X=W.AMP_MODE={localDev:!1,development:!("1"!=Z.development&&!W.AMP_DEV_MODE),examiner:"2"==Z.development,filter:Z.filter,geoOverride:Z["amp-geo"],minified:!0,lite:void 0!=ia.amp_lite,test:!1,log:Z.log,version:"1528391646530",rtvVersion:r}}"inabox"==X.runtime&&P(window,document.body);
  28. (function(a){a.registerElement("amp-lightbox",O,"amp-lightbox{display:none;position:fixed!important;z-index:1000;top:0!important;left:0!important;bottom:0!important;right:0!important}amp-lightbox[scrollable]{overflow-y:auto!important;overflow-x:hidden!important}\n/*# sourceURL=/extensions/amp-lightbox/0.1/amp-lightbox.css*/")})(self.AMP);
  29. })});
  30. //# sourceMappingURL=amp-lightbox-0.1.js.map
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement