Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (self.AMP=self.AMP||[]).push({n:"amp-geo",v:"1528391646530",f:(function(AMP){function g(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 h(a,b){b=void 0===b?"":b;try{return decodeURIComponent(a)}catch(c){return b}};var k=/(?:^[#?]?|&)([^=&]+)(?:=([^&]*))?/g;function l(a){var b=Object.create(null);if(!a)return b;for(var c;c=k.exec(a);){var d=h(c[1],c[1]),e=c[2]?h(c[2],c[2]):"";b[d]=e}return b};var m="";function n(a){var b=a||self,c;if(b.AMP_MODE)c=b.AMP_MODE;else{c=b;var d=l(c.location.originalHash||c.location.hash),e=l(c.location.search);m||(m=c.AMP_CONFIG&&c.AMP_CONFIG.v?c.AMP_CONFIG.v:"011528391646530");c=b.AMP_MODE={localDev:!1,development:!("1"!=d.development&&!c.AMP_DEV_MODE),examiner:"2"==d.development,filter:d.filter,geoOverride:d["amp-geo"],minified:!0,lite:void 0!=e.amp_lite,test:!1,log:d.log,version:"1528391646530",rtvVersion:m}}return c};var p=Object.prototype.toString;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};var w=self.AMP_CONFIG||{},x=("string"==typeof w.cdnProxyRegex?new RegExp(w.cdnProxyRegex):w.cdnProxyRegex)||/^https:\/\/([a-zA-Z0-9_-]+\.)?cdn\.ampproject\.org$/;function y(a){this.w=a;this.m=this.o=0;this.j=Object.create(null)}y.prototype.has=function(a){return!!this.j[a]};y.prototype.get=function(a){var b=this.j[a];if(b)return b.access=++this.m,b.payload};
- y.prototype.put=function(a,b){this.has(a)||this.o++;this.j[a]={payload:b,access:this.m};if(!(this.o<=this.w)){if(q.dev)a=q.dev;else throw Error("failed to call initLogConstructor");a.warn("lru-cache","Trimming LRU cache");a=this.j;var c=this.m+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.o--)}};var z,A;function B(){var a,b;this.promise=new Promise(function(c,d){a=c;b=d});this.resolve=a;this.reject=b};/*
- https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
- function C(a,b,c){if(b(a))c();else{var d=a.ownerDocument.defaultView;if(d.MutationObserver){var e=new d.MutationObserver(function(){b(a)&&(e.disconnect(),c())});e.observe(a,{childList:!0})}else var f=d.setInterval(function(){b(a)&&(d.clearInterval(f),c())},5)}}function D(a,b){C(a.documentElement,function(){return!!a.body},b)}function E(a){return new Promise(function(b){D(a,b)})}function F(a){return"SCRIPT"==a.tagName&&"APPLICATION/JSON"==a.getAttribute("type").toUpperCase()};var G=/amp-iso-country-(\w+)/;function H(a){a=AMP.BaseElement.call(this,a)||this;a.l=0;a.c="unknown";a.h=[];return a}g(H,AMP.BaseElement);H.prototype.buildCallback=function(){var a=this.element.children;a.length&&r().assert(1===a.length&&F(a[0]),'amp-geo can only have one <script type="application/json"> child');var b=I(this,a.length?JSON.parse(a[0].textContent):{});J.resolve(b)};
- function K(a,b){var c=b.body.className.match(G),d;if(d=c){b=b.location;if("string"==typeof b){z||(z=self.document.createElement("a"),A=self.UrlCache||(self.UrlCache=new y(100)));d=A;var e=z;if(d&&d.has(b))b=d.get(b);else{e.href=b;e.protocol||(e.href=e.href);var f={href:e.href,protocol:e.protocol,host:e.host,hostname:e.hostname,port:"0"==e.port?"":e.port,pathname:e.pathname,search:e.search,hash:e.hash,origin:null};"/"!==f.pathname[0]&&(f.pathname="/"+f.pathname);if("http:"==f.protocol&&80==f.port||
- "https:"==f.protocol&&443==f.port)f.port="",f.host=f.hostname;f.origin=e.origin&&"null"!=e.origin?e.origin:"data:"!=f.protocol&&f.host?f.protocol+"//"+f.host:f.href;d&&d.put(b,f);b=f}}d=!x.test(b.origin)}d?(a.l=1,a.c=c[1]):(a.l=0,a.c="cn ".trim(),2!==a.c.length&&(a.c="unknown"));if(b=n(a.win).geoOverride)b=a.win,b=!(!b.AMP_CONFIG||!b.AMP_CONFIG.canary);b&&/^\w+$/.test(n(a.win).geoOverride)&&(a.l=2,a.c=n(a.win).geoOverride.toLowerCase())}
- function L(a,b){var c=b.ISOCountryGroups,d="<amp-geo> ISOCountryGroups";c&&(r().assert("[object Object]"===p.call(c),d+" must be an object"),Object.keys(c).forEach(function(b){r().assert(/^[a-z]+[a-z0-9]*$/i.test(b)&&!/^amp/.test(b),d+"["+b+"] name is invalid");r().assert(Array.isArray(c[b]),d+"["+b+"] must be an array");c[b]=c[b].map(function(a){return a.toLowerCase()});c[b].includes(a.c)&&a.h.push(b)}))}
- function M(a){var b=a.body.classList,c=[],d=/^amp-iso-country-|^amp-geo-group-/i;for(a=b.length-1;0<a;a--)d.test(b[a])&&c.push(b[a]);return c}
- function I(a,b){var c=a.win.document,d={};return E(c).then(function(){K(a,c);L(a,b);var e=[];switch(a.l){case 2:e=M(c);case 0:d.ISOCountry=a.c;var f=a.h.map(function(a){d[a]=!0;return"amp-geo-group-"+a});a.h.length||f.push("amp-geo-no-group");d.ISOCountryGroups=a.h;f.push("amp-iso-country-"+a.c);a.mutateElement(function(){var a=c.body.classList;e.push("amp-geo-pending");e.forEach(function(b){return a.remove(b)});f.forEach(function(b){return a.add(b)});if(b.AmpBind){var t=c.getElementById("ampGeo");
- t&&t.parentNode.removeChild(t);var u=c.createElement("amp-state"),v=c.createElement("script");v.setAttribute("type","application/json");v.textContent=JSON.stringify(d);u.appendChild(v);u.id="ampGeo";c.body.appendChild(u)}},c.body)}return{ISOCountry:a.c,ISOCountryGroups:a.h}})}var J=null;(function(a){J=new B;a.registerElement("amp-geo",H);a.registerServiceForDoc("geo",function(){return J.promise})})(self.AMP);
- })});
- //# sourceMappingURL=amp-geo-0.1.js.map
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement