Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (self.AMP=self.AMP||[]).push({n:"amp-consent",v:"1528391646530",f:(function(AMP){var h;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]}function m(a,b){b=void 0===b?"":b;try{return decodeURIComponent(a)}catch(c){return b}};var p=/(?:^[#?]?|&)([^=&]+)(?:=([^&]*))?/g;var aa=Object.prototype.toString;function ba(a){return"number"===typeof a&&isFinite(a)}function ca(a){var b=da,c;for(c in b)if(b[c]===a)return!0;return!1};self.log=self.log||{user:null,dev:null,userForEmbed:null};var q=self.log;function r(){if(!q.user)throw Error("failed to call initLogConstructor");return q.user}function t(){if(q.dev)return q.dev;throw Error("failed to call initLogConstructor");};var ea=Object.prototype.hasOwnProperty;function u(){var a,b=Object.create(null);a&&Object.assign(b,a);return b};function v(a){this.ha=a;this.R=this.Y=0;this.G=Object.create(null)}v.prototype.has=function(a){return!!this.G[a]};v.prototype.get=function(a){var b=this.G[a];if(b)return b.access=++this.R,b.payload};v.prototype.put=function(a,b){this.has(a)||this.Y++;this.G[a]={payload:b,access:this.R};if(!(this.Y<=this.ha)){t().warn("lru-cache","Trimming LRU cache");a=this.G;var c=this.R+1,d,e;for(e in a){var f=a[e].access;f<c&&(c=f,d=e)}void 0!==d&&(delete a[d],this.Y--)}};var w,x;
- function fa(a){if("string"==typeof a){w||(w=self.document.createElement("a"),x=self.UrlCache||(self.UrlCache=new v(100)));var b=x,c=w;if(b&&b.has(a))a=b.get(a);else{c.href=a;c.protocol||(c.href=c.href);var d={href:c.href,protocol:c.protocol,host:c.host,hostname:c.hostname,port:"0"==c.port?"":c.port,pathname:c.pathname,search:c.search,hash:c.hash,origin:null};"/"!==d.pathname[0]&&(d.pathname="/"+d.pathname);if("http:"==d.protocol&&80==d.port||"https:"==d.protocol&&443==d.port)d.port="",d.host=d.hostname;
- d.origin=c.origin&&"null"!=c.origin?c.origin:"data:"!=d.protocol&&d.host?d.protocol+"//"+d.host:d.href;b&&b.put(a,d);a=d}}(b="https:"==a.protocol||"localhost"==a.hostname)||(a=a.hostname,b=a.length-10,b=0<=b&&a.indexOf(".localhost",b)==b);return b}
- function ga(a,b){var c;c=void 0===c?"source":c;r().assert(null!=a,"%s %s must be available",b,c);var d=a;r().assert(fa(d)||/^(\/\/)/.test(d),'%s %s must start with "https://" or "//" or be relative and served from either https or from localhost. Invalid value: %s',b,c,d)};function y(a,b){var c;if(a.__AMP__EXPERIMENT_TOGGLES)c=a.__AMP__EXPERIMENT_TOGGLES;else{a.__AMP__EXPERIMENT_TOGGLES=Object.create(null);c=a.__AMP__EXPERIMENT_TOGGLES;if(a.AMP_CONFIG)for(var d in a.AMP_CONFIG){var e=a.AMP_CONFIG[d];"number"===typeof e&&0<=e&&1>=e&&(c[d]=Math.random()<e)}if(a.AMP_CONFIG&&Array.isArray(a.AMP_CONFIG["allow-doc-opt-in"])&&0<a.AMP_CONFIG["allow-doc-opt-in"].length&&(d=a.AMP_CONFIG["allow-doc-opt-in"],e=a.document.head.querySelector('meta[name="amp-experiments-opt-in"]')))for(var e=
- e.getAttribute("content").split(","),f=0;f<e.length;f++)-1!=d.indexOf(e[f])&&(c[e[f]]=!0);Object.assign(c,ha(a));if(a.AMP_CONFIG&&Array.isArray(a.AMP_CONFIG["allow-url-opt-in"])&&0<a.AMP_CONFIG["allow-url-opt-in"].length){d=a.AMP_CONFIG["allow-url-opt-in"];e=a.location.originalHash||a.location.hash;a=Object.create(null);if(e)for(var g;g=p.exec(e);)f=m(g[1],g[1]),g=g[2]?m(g[2],g[2]):"",a[f]=g;for(e=0;e<d.length;e++)f=a["e-"+d[e]],"1"==f&&(c[d[e]]=!0),"0"==f&&(c[d[e]]=!1)}}var l=c;return!!l[b]}
- function ha(a){a:{var b;try{b=a.document.cookie}catch(l){b=""}if(a=b)for(a=a.split(";"),b=0;b<a.length;b++){var c=a[b].trim(),d=c.indexOf("="),e;if(e=-1!=d)e=c.substring(0,d).trim(),e="AMP_EXP"==m(e,void 0);if(e){a=c.substring(d+1).trim();a=m(a,a);break a}}a=null}var f=a,g=f?f.split(/\s*,\s*/g):[];a=Object.create(null);for(b=0;b<g.length;b++)0!=g[b].length&&("-"==g[b][0]?a[g[b].substr(1)]=!1:a[g[b]]=!0);return a};function z(){var a,b;this.promise=new Promise(function(c,d){a=c;b=d});this.resolve=a;this.reject=b};function A(a,b){a=a.__AMP_TOP||a;return B(a,b)}function ia(a){a=C(a);a=D(a);return B(a,"viewer")}function E(a,b){a=D(a);var c=F(a,b);if(!c){var d=new z,c=d.promise,d=d.resolve;G(a)[b]={obj:null,promise:c,resolve:d,context:null,ctor:null}}b=c;return b}function C(a){return a.nodeType?A((a.ownerDocument||a).defaultView,"ampdoc").getAmpDoc(a):a}function D(a){a=C(a);return a.isSingleDoc()?a.win:a}
- function B(a,b){var c=G(a);a=c[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 F(a,b){var c=G(a)[b];if(c){if(c.promise)return c.promise;B(a,b);return c.promise=Promise.resolve(c.obj)}return null}function G(a){var b=a.services;b||(b=a.services={});return b};/*
- https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
- var H;function ja(a){return"SCRIPT"==a.tagName&&"APPLICATION/JSON"==a.getAttribute("type").toUpperCase()};var ka=[];function la(a){var b=C(a),c=F(D(a),"geo");return c?c:b.whenBodyAvailable().then(function(){return ma(b.win)}).then(function(){return F(D(a),"geo")})}function ma(a){return Promise.resolve().then(function(){if(ka.includes("amp-geo")){var b=A(a,"extensions");return b.waitForExtension(a,"amp-geo")}})};var I,J="Webkit webkit Moz moz ms O o".split(" ");function K(a,b,c){if(2>b.length?0:0==b.lastIndexOf("--",0))return b;I||(I=u());var d=I[b];if(!d||c){d=b;if(void 0===a[b]){var e=b.charAt(0).toUpperCase()+b.slice(1);a:{for(var f=0;f<J.length;f++){var g=J[f]+e;if(void 0!==a[g]){e=g;break a}}e=""}var l=e;void 0!==a[l]&&(d=l)}c||(I[b]=d)}return d}function M(a,b){for(var c in b)a.style.setProperty(K(b,c),b[c].toString(),"important")}
- function N(a){var b=!0;if(void 0===b){var c;c=(c=K(a.style,"display",void 0))?a.style[c]:void 0;b="none"==c}c=b?"":"none";var d=K(a.style,"display",void 0);d&&(a.style[d]=c)};function O(){this.m=null}h=O.prototype;h.add=function(a){var b=this;this.m||(this.m=[]);this.m.push(a);return function(){b.remove(a)}};h.remove=function(a){this.m&&(a=this.m.indexOf(a),-1<a&&this.m.splice(a,1))};h.removeAll=function(){this.m&&(this.m.length=0)};h.fire=function(a){if(this.m)for(var b=this.m,c=0;c<b.length;c++)(0,b[c])(a)};h.getHandlerCount=function(){return this.m?this.m.length:0};function P(){this.C=0;this.da=Promise.resolve();this.ba=function(){};this.ca=function(){}}P.prototype.onQueueEmpty=function(a){this.ba=a;0==this.C&&a()};P.prototype.onQueueNotEmpty=function(a){this.ca=a;0<this.C&&a()};P.prototype.registerUI=function(a){var b=this;0==this.C&&this.ca();this.C++;var c=this.da.then(function(){return a().then(function(){b.C--;0==b.C&&b.ba()})});return this.da=c};var da={ACCEPTED:1,REJECTED:2,DISMISSED:3,NOT_REQUIRED:4,UNKNOWN:5};function Q(a){this.B=a;this.h={};this.H={};this.J={};this.I={}}h=Q.prototype;h.registerConsentInstance=function(a){this.h[a]?t().error("CONSENT-STATE-MANAGER","instance "+a+" already registered"):(this.h[a]=new R(this.B,a),this.H[a]=new O,this.J[a]&&(this.J[a](),this.I[a]=null,this.J[a]=null))};
- h.updateConsentInstanceState=function(a,b){this.h[a]&&this.H[a]?(this.H[a].fire(b),this.h[a].update(b)):t().error("CONSENT-STATE-MANAGER","instance "+a+" not registered")};h.getConsentInstanceState=function(a){return this.h[a].get()};h.onConsentStateChange=function(a,b){var c=this.H[a].add(b);this.getConsentInstanceState(a).then(function(a){b(a)});return c};h.setConsentInstanceSharedData=function(a,b){this.h[a].sharedDataPromise=b};h.getConsentInstanceSharedData=function(a){return this.h[a].sharedDataPromise};
- h.whenConsentReady=function(a){if(this.h[a])return Promise.resolve();if(!this.I[a]){var b=new z;this.I[a]=b.promise;this.J[a]=b.resolve}return this.I[a]};function R(a,b){this.sharedDataPromise=null;this.fa=E(a,"storage");this.l=null;this.ea="amp-consent:"+b}R.prototype.update=function(a){var b=this;ca(a)||(a=5);if(3==a)this.l=this.l||5;else if(4==a)this.l&&5!=this.l||(this.l=4);else if(a!==this.l&&(this.l=a,5!=a)){var c=1==a;this.fa.then(function(d){a==b.l&&d.set(b.ea,c)})}};
- R.prototype.get=function(){var a=this;return this.l?Promise.resolve(this.l):this.fa.then(function(b){return b.get(a.ea)}).then(function(b){if(a.l)return a.l;a.l=void 0===b?5:b?1:2;return a.l}).catch(function(a){t().error("CONSENT-STATE-MANAGER","Failed to read storage",a);return 5})};var S={"default":!0,_if_responded:!0,_if_accepted:!0,_auto_reject:!0};function T(a){this.B=a;this.N=u();this.M=u();this.h=u();this.$=E(this.B,"consentStateManager");a=new z;this.ga=a.promise;this.S=a.resolve}h=T.prototype;
- h.registerConsentPolicyInstance=function(a,b){var c=this;this.h[a]&&t().error("consent-policy-manager","policy "+a+" already registered");var d=Object.keys(b.waitFor||{}),e=new U(b);this.h[a]=e;this.M[a]&&(this.M[a](),this.M[a]=null,this.N[a]=null);var f=[];this.$.then(function(a){for(var b={},g=0;g<d.length;b={consentId:b.consentId,resolver:b.resolver},g++){b.consentId=d[g];var L=new z,na=L.promise;b.resolver=L.resolve;a.whenConsentReady(b.consentId).then(function(b){return function(){a.onConsentStateChange(b.consentId,
- function(a){b.resolver&&(b.resolver(),b.resolver=null);e.consentStateChangeHandler(b.consentId,a)})}}(b));f.push(na)}c.ga.then(function(){Promise.all(f).then(function(){e.startTimeout(c.B.win)})})})};h.enableTimeout=function(){this.S&&this.S();this.S=null};
- h.whenPolicyResolved=function(a){var b=this;return y(this.B.win,"multi-consent")||S[a]?V(this,a).then(function(){return b.h[a].getReadyPromise().then(function(){return b.h[a].getCurrentPolicyStatus()})}):(r().error("consent-policy-manager","can not find defined policy "+a+", only supported predefined policy supported now"),Promise.resolve(4))};
- h.whenPolicyUnblock=function(a){var b=this;return y(this.B.win,"multi-consent")||S[a]?V(this,a).then(function(){return b.h[a].getReadyPromise().then(function(){return b.h[a].shouldBlock()})}):(r().error("consent-policy-manager","can not find defined policy "+a+", only supported predefined policy supported now"),Promise.resolve(!1))};
- h.getMergedSharedData=function(a){var b=this;return this.whenPolicyResolved(a).then(function(){return b.$}).then(function(c){var d=b.h[a].getConsentInstanceIds().map(function(a){return c.getConsentInstanceSharedData(a)});return Promise.all(d)}).then(function(a){a.unshift({});return Object.assign.apply(null,a)})};function V(a,b){if(a.h[b])return Promise.resolve();if(!a.N[b]){var c=new z;a.N[b]=c.promise;a.M[b]=c.resolve}return a.N[b]}
- function U(a){var b=Object.keys(a.waitFor||{});this.ia=a;this.j=u();var c=new z;this.ja=c.promise;this.X=c.resolve;this.Z=4;this.la=a.unblockOn||[1,3];this.V(b)}h=U.prototype;h.V=function(a){for(var b=0;b<a.length;b++)this.j[a[b]]=null};h.getConsentInstanceIds=function(){return Object.keys(this.j)};
- h.startTimeout=function(a){var b=this,c=this.ia.timeout,d=null,e;void 0!=c&&("[object Object]"===aa.call(c)?(c.fallbackAction&&"reject"==c.fallbackAction?e=2:c.fallbackAction&&"dismiss"!=c.fallbackAction&&r().error("consent-policy-manager","unsupported fallbackAction "+c.fallbackAction),d=c.seconds):d=c,r().assert(ba(d),"invalid timeout value "+d));null!=d&&a.setTimeout(function(){W(b,!0,e)},1E3*d)};
- h.consentStateChangeHandler=function(a,b){if(!ea.call(this.j,a))t().error("consent-policy-manager","cannot find "+a+" in policy state");else if(5!=b){if(4==b){var c=1!=this.j[a]&&2!=this.j[a];c&&(this.j[a]=4)}else 3==b?null===this.j[a]&&(this.j[a]=5):this.j[a]=b;W(this)}};
- function W(a,b,c){b=void 0===b?!1:b;for(var d=!0,e=!0,f=!1,g=Object.keys(a.j),l=0;l<g.length;l++){var n=g[l];if(null===a.j[n])if(b)a.j[n]=c||5;else return;4==a.j[n]&&(d=!1);2==a.j[n]&&(e=d=!1);5==a.j[n]&&(e=d=!1,f=!0)}a.Z=d?1:e?3:f?4:2;a.X&&(a.X(),a.X=null)}h.getReadyPromise=function(){return this.ja};h.getCurrentPolicyStatus=function(){return this.Z};h.shouldBlock=function(){return-1<this.la.indexOf(this.Z)};function X(a){a=AMP.BaseElement.call(this,a)||this;a.w=null;a.T=null;a.D=null;a.K=u();a.A={};a.o={};a.aa=u();a.O=!1;a.c=null;a.F=null;a.L=u();a.U=u();a.W=!1;a.P=a.getVsync();return a}k(X,AMP.BaseElement);X.prototype.getConsentPolicy=function(){return null};
- X.prototype.buildCallback=function(){var a=this;if(y(this.win,"amp-consent")){this.W=y(this.win,"multi-consent");r().assert(this.element.getAttribute("id"),"amp-consent should have an id");oa(this);for(var b=this.getRealChildren(),c=0;c<b.length;c++)this.setAsOwner(b[c]);var d=E(this.getAmpDoc(),"consentPolicyManager").then(function(b){a.T=b;var c=Object.keys(a.A);b={};for(var d=0;d<c.length;d++)b[c[d]]=void 0;var c={waitFor:b},d=[4,1,2,3],e={waitFor:b,timeout:{seconds:0,fallbackAction:"reject"},
- unblockOn:d};a.o._if_responded={waitFor:b,unblockOn:d};a.o._if_accepted=c;a.o._auto_reject=e;a.o&&a.o["default"]||(a.o["default"]=c);var f=Object.keys(a.o);for(b=0;b<f.length;b++)a.T.registerConsentPolicyInstance(f[b],a.o[f[b]])}),e=E(this.getAmpDoc(),"consentStateManager").then(function(b){a.w=b}),f=E(this.getAmpDoc(),"notificationUIManager").then(function(b){a.D=b});Promise.all([e,f,d]).then(function(){a.V()})}};
- function pa(a){a.registerAction("accept",function(){return Y(a,0)});a.registerAction("reject",function(){return Y(a,1)});a.registerAction("dismiss",function(){return Y(a,2)});a.registerAction("prompt",function(b){var c=b.args,d=c&&c.consent;a.W||(d=Object.keys(a.A)[0]);d=d||"";r().assert(a.A[d],"consent with id "+d+" not found");Z(a,d)})}function Z(a,b){a.D||t().error("amp-consent","notification ui manager not found");!a.U[b]&&a.K[b]&&(a.U[b]=!0,a.D.registerUI(a.ka.bind(a,b)))}
- X.prototype.ka=function(a){var b=this;this.c&&t().error("amp-consent","other consent instance on display "+this.c);this.P.mutate(function(){b.O||(b.O=!0,N(b.element));b.element.classList.remove("amp-hidden");b.element.classList.add("amp-active");b.getViewport().addToFixedLayer(b.element);b.c=a;var c=b.K[b.c];M(c,{display:"block"});b.scheduleLayout(c)});var c=new z;this.L[a]=c.resolve;return c.promise};
- function qa(a){var b=a.c&&a.K[a.c];a.P.mutate(function(){a.element.classList.add("amp-hidden");a.element.classList.remove("amp-active");a.getViewport().removeFromFixedLayer(a.element);b||t().error("amp-consent",a.c+" no consent ui to hide");M(b,{display:"none"})});a.L[a.c]&&(a.L[a.c](),a.L[a.c]=null);a.U[a.c]=!1;a.c=null}
- function Y(a,b){a.c?a.w?(0==b?a.w.updateConsentInstanceState(a.c,1):1==b?a.w.updateConsentInstanceState(a.c,2):2==b&&a.w.updateConsentInstanceState(a.c,3),qa(a)):t().error("amp-consent","No consent state manager"):t().error("amp-consent","No consent ui is displaying, consent id "+a.c)}
- X.prototype.V=function(){for(var a=this,b=Object.keys(this.A),c=[],d={},e=0;e<b.length;d={instanceId:d.instanceId},e++){d.instanceId=b[e];this.w.registerConsentInstance(d.instanceId);var f=ra(this,d.instanceId,this.A[d.instanceId]),g=f.then(function(b){return function(){return sa(a,b.instanceId)}}(d)).catch(function(){});c.push(g)}Promise.all(c).then(function(){ta(a);a.T.enableTimeout()});pa(this)};
- function ra(a,b,c){r().assert(c.checkConsentHref||c.promptIfUnknownForGeoGroup,"neither checkConsentHref nor promptIfUnknownForGeoGroup is defined");var d=Promise.resolve(null);c.checkConsentHref&&(d=ua(a,b),va(a,b,d));var e=Promise.resolve();if(c.promptIfUnknownForGeoGroup)var f=c.promptIfUnknownForGeoGroup,e=wa(a,f);return e.then(function(c){return d.then(function(d){var e=a.aa,f=c;d&&1==d.promptIfUnknown?f=!0:d&&0==d.promptIfUnknown?f=!1:void 0==f&&(f=!1);e[b]=f})})}
- function va(a,b,c){var d=c.then(function(a){return a&&void 0!==a.sharedData?a.sharedData:null});a.w.setConsentInstanceSharedData(b,d)}function wa(a,b){return la(a.element).then(function(a){r().assert(a,"requires <amp-geo> to use promptIfUnknownForGeoGroup");return 0<=a.ISOCountryGroups.indexOf(b)})}
- function ua(a,b){var c={credentials:"include",method:"POST",body:{consentInstanceId:b},requireAmpResponseSourceOrigin:!1},d=a.A[b].checkConsentHref;ga(d,a.element);var e=ia(a.getAmpDoc());return e.whenFirstVisible().then(function(){return A(a.win,"xhr").fetchJson(d,c).then(function(a){return a.json()})})}
- function oa(a){var b;b=a.element;if(null==H){var c=b.ownerDocument;try{var d=c.createElement("div"),e=c.createElement("div");d.appendChild(e);H=d.querySelector(":scope div")===e}catch(L){H=!1}}H?b=b.querySelectorAll(":scope > script"):(b.classList.add("i-amphtml-scoped"),c=b.querySelectorAll(".i-amphtml-scoped > script"),b.classList.remove("i-amphtml-scoped"),b=c);var f=b;r().assert(1==f.length,"amp-consent should have (only) one <script> child");var g=f[0];r().assert(ja(g),'amp-consent consent instance config should be put in a <script>tag with type= "application/json"');
- b=JSON.parse(g.textContent);var l=b.consents;r().assert(l,"amp-consent: consents config is required");r().assert(0!=Object.keys(l).length,"amp-consent: can't find consent instance");if(!a.W&&(r().assert(1>=Object.keys(l).length,"amp-consent: only single consent instance is supported"),b.policy))for(var n=Object.keys(b.policy),c=0;c<n.length;c++)"default"!=n[c]&&(r().warn("amp-consent","policy "+n[c]+" is currently not supportedand will be ignored"),delete b.policy[n[c]]);a.A=l;b.postPromptUI&&(a.F=
- a.getAmpDoc().getElementById(b.postPromptUI));a.o=b.policy||a.o}function sa(a,b){var c=a.A[b].promptUI,d=a.getAmpDoc().getElementById(c);a.K[b]=d;return a.w.getConsentInstanceState(b).then(function(c){5==c&&(a.aa[b]?Z(a,b):a.w.updateConsentInstanceState(b,4))})}
- function ta(a){var b=a.element.classList;a.D.onQueueEmpty(function(){a.F&&a.P.mutate(function(){a.O||(a.O=!0,N(a.element));b.add("amp-active");b.remove("amp-hidden");a.getViewport().addToFixedLayer(a.element);M(a.F,{display:"block"})})});a.D.onQueueNotEmpty(function(){a.F&&a.P.mutate(function(){a.c||(b.add("amp-hidden"),b.remove("amp-active"));a.getViewport().removeFromFixedLayer(a.element);M(a.F,{display:"none"})})})}
- (function(a){a.registerElement("amp-consent",X,"amp-consent{position:fixed;bottom:0;left:0;overflow:hidden!important;background:hsla(0,0%,100%,0.7);z-index:1000;width:100%}amp-consent>*{display:none!important;max-height:100vh!important}amp-consent.amp-active{visibility:visible}amp-consent.amp-hidden{visibility:hidden}\n/*# sourceURL=/extensions/amp-consent/0.1/amp-consent.css*/");a.registerServiceForDoc("notificationUIManager",P);a.registerServiceForDoc("consentStateManager",Q);a.registerServiceForDoc("consentPolicyManager",
- T)})(self.AMP);
- })});
- //# sourceMappingURL=amp-consent-0.1.js.map
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement