Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (self.AMP=self.AMP||[]).push({n:"amp-accordion",v:"1528391646530",f:(function(AMP){function k(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]};self.log=self.log||{user:null,dev:null,userForEmbed:null};var l=self.log;function m(){if(!l.user)throw Error("failed to call initLogConstructor");return l.user}function n(){if(l.dev)return l.dev;throw Error("failed to call initLogConstructor");};function p(){var a,b;this.promise=new Promise(function(c,d){a=c;b=d});this.resolve=a;this.reject=b};function q(a){if(a.nodeType){var b=(a.ownerDocument||a).defaultView;if(b=b!=(b.__AMP_TOP||b)&&r(b,"action")?t(b,"action"):null)return b}b=u(a);b=u(b);b=b.isSingleDoc()?b.win:b;return t(b,"action")}function v(a,b){a=a.__AMP_TOP||a;return t(a,b)}function u(a){return a.nodeType?v((a.ownerDocument||a).defaultView,"ampdoc").getAmpDoc(a):a}
- function t(a,b){r(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 r(a,b){a=a.services&&a.services[b];return!(!a||!a.ctor&&!a.obj)};/*
- https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
- function w(a,b,c){for(var d=a;d&&d!==c;d=d.parentElement)if(b(d))return d;return null};var x,y="Webkit webkit Moz moz ms O o".split(" ");function z(a,b,c){var d;var e=a.style;if(2>b.length||0!=b.lastIndexOf("--",0)){x||(x=Object.create(null));var f=x[b];if(!f){f=b;if(void 0===e[b]){var g=b.charAt(0).toUpperCase()+b.slice(1);b:{for(var h=0;h<y.length;h++){var F=y[h]+g;if(void 0!==e[F]){g=F;break b}}g=""}void 0!==e[g]&&(f=g)}x[b]=f}b=f}b&&(a.style[b]=d?c+d:c)}function A(a,b){for(var c in b)z(a,c,b[c])};function B(a,b,c,d){var e=new C(0,0,a,b,c,d,1,1);return e.solveYValueFromXValue.bind(e)}function C(a,b,c,d,e,f,g,h){this.x0=a;this.y0=b;this.x1=c;this.y1=d;this.x2=e;this.y2=f;this.x3=g;this.y3=h}C.prototype.solveYValueFromXValue=function(a){return this.getPointY(this.solvePositionFromXValue(a))};
- C.prototype.solvePositionFromXValue=function(a){var b=1E-6,c=(a-this.x0)/(this.x3-this.x0);if(0>=c)return 0;if(1<=c)return 1;for(var d=0,e=1,f=0,g=0;8>g;g++){var f=this.getPointX(c),h=(this.getPointX(c+b)-f)/b;if(Math.abs(f-a)<b)return c;if(Math.abs(h)<b)break;else f<a?d=c:e=c,c-=(f-a)/h}for(g=0;Math.abs(f-a)>b&&8>g;g++)f<a?(d=c,c=(c+e)/2):(e=c,c=(c+d)/2),f=this.getPointX(c);return c};
- C.prototype.getPointX=function(a){if(0==a)return this.x0;if(1==a)return this.x3;var b=this.lerp(this.x0,this.x1,a),c=this.lerp(this.x1,this.x2,a),d=this.lerp(this.x2,this.x3,a),b=this.lerp(b,c,a),c=this.lerp(c,d,a);return this.lerp(b,c,a)};C.prototype.getPointY=function(a){if(0==a)return this.y0;if(1==a)return this.y3;var b=this.lerp(this.y0,this.y1,a),c=this.lerp(this.y1,this.y2,a),d=this.lerp(this.y2,this.y3,a),b=this.lerp(b,c,a),c=this.lerp(c,d,a);return this.lerp(b,c,a)};
- C.prototype.lerp=function(a,b,c){return a+c*(b-a)};var D=B(.25,.1,.25,1),E=B(.42,0,1,1),G=B(0,0,.58,1),H=B(.42,0,.58,1),I={linear:function(a){return a},ease:D,"ease-in":E,"ease-out":G,"ease-in-out":H};function J(a){if(!a)return null;if("string"==typeof a){if(-1!=a.indexOf("cubic-bezier")){var b=a.match(/cubic-bezier\((.+)\)/);if(b&&(b=b[1].split(",").map(parseFloat),4==b.length)){for(var c=0;4>c;c++)if(isNaN(b[c]))return null;return B(b[0],b[1],b[2],b[3])}return null}return I[a]}return a};function K(){}function L(a,b){this.j=a;(a=b)||(a=v(self,"vsync"));this.o=a;this.D=null;this.c=[]}function M(a,b,c,d){return(new L(a)).setCurve(d).add(0,b,1).start(c)}L.prototype.setCurve=function(a){a&&(this.D=J(a));return this};L.prototype.add=function(a,b,c,d){this.c.push({delay:a,func:b,duration:c,curve:J(d)});return this};L.prototype.start=function(a){var b=new N(this.o,this.j,this.c,this.D,a);return b};
- function N(a,b,c,d,e){this.o=a;this.j=b;this.c=[];for(b=0;b<c.length;b++){var f=c[b];this.c.push({delay:f.delay,func:f.func,duration:f.duration,curve:f.curve||d,started:!1,completed:!1})}this.J=e;this.N=Date.now();this.w=!0;this.G={};e=new p;this.F=e.promise;this.M=e.resolve;this.L=e.reject;this.H=this.o.createAnimTask(this.j,{mutate:this.O.bind(this)});this.o.canAnimate(this.j)?this.H(this.G):(n().warn("Animation","cannot animate"),O(this,!1,0))}
- N.prototype.then=function(a,b){return a||b?this.F.then(a,b):this.F};N.prototype.thenAlways=function(a){a=a||K;return this.then(a,a)};N.prototype.halt=function(a){O(this,!1,a||0)};function O(a,b,c){if(a.w){a.w=!1;if(0!=c){1<a.c.length&&a.c.sort(function(a,b){return a.delay+a.duration-(b.delay+b.duration)});try{if(0<c)for(c=0;c<a.c.length;c++)a.c[c].func(1,!0);else for(var d=a.c.length-1;0<=d;d--)a.c[d].func(0,!1)}catch(e){n().error("Animation","completion failed: "+e,e),b=!1}}b?a.M():a.L()}}
- N.prototype.O=function(){if(this.w){for(var a=Date.now(),b=Math.min((a-this.N)/this.J,1),c=0;c<this.c.length;c++){var d=this.c[c];!d.started&&b>=d.delay&&(d.started=!0)}for(c=0;c<this.c.length;c++)if(d=this.c[c],d.started&&!d.completed)a:{var e,f;if(0<d.duration){if(e=f=Math.min((b-d.delay)/d.duration,1),d.curve&&1!=e)try{e=d.curve(f)}catch(g){n().error("Animation","step curve failed: "+g,g);O(this,!1,0);break a}}else e=f=1;1==f&&(d.completed=!0);try{d.func(e,d.completed)}catch(g){n().error("Animation",
- "step mutate failed: "+g,g),O(this,!1,0)}}1==b?O(this,!0,0):this.o.canAnimate(this.j)?this.H(this.G):(n().warn("Animation","cancel animation"),O(this,!1,0))}};function P(a,b){return function(c,d){for(var e in b)z(a,e,b[e](c,d))}}function Q(a,b){return function(c){return a+(b-a)*c}}function R(a){return function(b){return a(b)+"px"}};var S=B(.47,0,.745,.715),T=B(.39,.575,.565,1);function U(a){a=AMP.BaseElement.call(this,a)||this;a.m=[];a.A=null;a.l=null;a.B=!1;a.h=null;a.C=null;return a}k(U,AMP.BaseElement);U.prototype.isLayoutSupported=function(a){return"container"==a};
- U.prototype.buildCallback=function(){var a=this;this.C=q(this.element);this.B=this.element.hasAttribute("disable-session-states");this.A=V(this);this.l=W(this);this.h=this.getRealChildren();this.h.forEach(function(b,c){m().assert("section"==b.tagName.toLowerCase(),"Sections should be enclosed in a <section> tag, See https://github.com/ampproject/amphtml/blob/master/extensions/amp-accordion/amp-accordion.md. Found in: %s",a.element);var d=b.children;m().assert(2==d.length,"Each section must have exactly two children. See https://github.com/ampproject/amphtml/blob/master/extensions/amp-accordion/amp-accordion.md. Found in: %s",
- a.element);var e=d[1];e.classList.add("i-amphtml-accordion-content");var f=e.getAttribute("id");f||(f=a.element.id+"_AMP_content_"+c,e.setAttribute("id",f));a.registerAction("toggle",function(b){if(b.args){var c=b.args.section,d=a.getAmpDoc().getElementById(c);m().assertElement(d,"No element found with id:"+c);X(a,d)}else for(var e=0;e<a.h.length;e++)X(a,a.h[e])});a.registerAction("expand",function(b){if(b.args){b=b.args.section;var c=a.getAmpDoc().getElementById(b);m().assertElement(c,"No element found with id:"+
- b);X(a,c,!0)}else for(b=0;b<a.h.length;b++)X(a,a.h[b],!0)});a.registerAction("collapse",function(b){if(b.args){b=b.args.section;var c=a.getAmpDoc().getElementById(b);m().assertElement(c,"No element found with id:"+b);X(a,c,!1)}else for(b=0;b<a.h.length;b++)X(a,a.h[b],!1)});a.l[f]?b.setAttribute("expanded",""):!1===a.l[f]&&b.removeAttribute("expanded");a.mutateElement(function(){});c=d[0];c.classList.add("i-amphtml-accordion-header");c.setAttribute("role","button");c.setAttribute("aria-controls",f);
- c.setAttribute("aria-expanded",b.hasAttribute("expanded").toString());c.hasAttribute("tabindex")||c.setAttribute("tabindex",0);a.m.push(c);c.addEventListener("click",a.I.bind(a));c.addEventListener("keydown",a.K.bind(a))})};function V(a){var b=a.element.id||a.element.getResourceId();a=a.win.location.href;var c=a.indexOf("#");a=-1==c?a:a.substring(0,c);return"amp-"+b+"-"+a}function W(a){if(a.B)return{};try{var b=a.win.sessionStorage.getItem(a.A);return b?JSON.parse(b):{}}catch(c){return{}}}
- function aa(a){if(!a.B){var b=JSON.stringify(a.l);try{a.win.sessionStorage.setItem(a.A,b)}catch(c){}}}
- function X(a,b,c){var d=b.children,e=d[0],d=d[1].getAttribute("id"),f=b.hasAttribute("expanded"),g=void 0==c?!b.hasAttribute("expanded"):c;a.element.hasAttribute("animate")?g?(e.setAttribute("aria-expanded","true"),ba(a,b),a.element.hasAttribute("expand-single-section")&&a.h.forEach(function(c){c!=b&&(Y(a,c),c.children[0].setAttribute("aria-expanded","false"))})):(e.setAttribute("aria-expanded","false"),Y(a,b)):a.mutateElement(function(){g?(b.setAttribute("expanded",""),e.setAttribute("aria-expanded",
- "true"),a.element.hasAttribute("expand-single-section")&&a.h.forEach(function(a){a!=b&&(a.removeAttribute("expanded"),a.children[0].setAttribute("aria-expanded","false"))})):(b.removeAttribute("expanded"),e.setAttribute("aria-expanded","false"))},b);a.l[d]=!f;aa(a)}
- function ba(a,b){var c,d,e=b.children[1];a.mutateElement(function(){A(e,{opacity:0,position:"fixed"});b.setAttribute("expanded","")}).then(function(){return a.measureMutateElement(function(){c=e.offsetHeight;var b=a.getViewport().getHeight();d=Z(Math.abs(c),b)},function(){A(e,{opacity:"",height:0,position:""})})}).then(function(){return M(a.element,P(e,{height:R(Q(0,c)),opacity:Q(0,1)}),d,S).thenAlways(function(){a.mutateElement(function(){A(e,{height:"",opacity:""})})})})}
- function Y(a,b){var c,d,e=b.children[1];a.measureElement(function(){c=b.offsetHeight;var e=a.getViewport().getSize().height;d=Z(Math.abs(c),e)}).then(function(){return M(e,P(e,{height:R(Q(c,0))}),d,T).thenAlways(function(){return a.mutateElement(function(){b.removeAttribute("expanded");A(e,{height:""})})})})}function Z(a,b){var c,d;c=void 0===c?200:c;d=void 0===d?500:d;var e=Math.abs(a)/b*d;return Math.min(Math.max(e,c),d)}U.prototype.I=function(a){ca(this,a)&&(a.preventDefault(),X(this,a.currentTarget.parentElement))};
- function ca(a,b){var c=b.target;b=b.currentTarget;var d=!!w(c,function(a){return"A"==a.tagName},b),e=a.C.hasAction(c,"tap",b);return!d&&!e}U.prototype.K=function(a){if(!a.defaultPrevented){var b=a.keyCode;switch(b){case 38:case 40:var c=this.m.indexOf(a.currentTarget);if(-1!==c){a.preventDefault();a=(c+(38==a.keyCode?-1:1))%this.m.length;0>a&&(a+=this.m.length);try{this.m[a].focus()}catch(d){}}break;case 13:case 32:a.target==a.currentTarget&&(a.preventDefault(),X(this,a.currentTarget.parentElement))}}};
- (function(a){a.registerElement("amp-accordion",U)})(self.AMP);
- })});
- //# sourceMappingURL=amp-accordion-0.1.js.map
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement