Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (self.AMP=self.AMP||[]).push({n:"amp-user-notification",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 l(a){for(var b=null,c="",d=0;d<arguments.length;d++){var e=arguments[d];if(e instanceof Error&&!b){var b=void 0,f=e.message,g=String(Math.random());e.message=g;if(e.message===g)e.message=f,b=e;else{f=Error(e.message);for(b in e)f[b]=e[b];f.stack=e.stack;b=f}}else c&&(c+=" "),c+=e}b?c&&(b.message=c+": "+b.message):b=Error(c);return b}function m(a){var b=l.apply(null,arguments);setTimeout(function(){self.reportError(b);throw b;})}self.log=self.log||{user:null,dev:null,userForEmbed:null};
- var p=self.log;function q(){if(!p.user)throw Error("failed to call initLogConstructor");return p.user}function r(){if(p.dev)return p.dev;throw Error("failed to call initLogConstructor");};function t(a){return a||{}};function u(a){this.R=a;this.w=this.C=0;this.o=Object.create(null)}u.prototype.has=function(a){return!!this.o[a]};u.prototype.get=function(a){var b=this.o[a];if(b)return b.access=++this.w,b.payload};u.prototype.put=function(a,b){this.has(a)||this.C++;this.o[a]={payload:b,access:this.w};if(!(this.C<=this.R)){r().warn("lru-cache","Trimming LRU cache");a=this.o;var c=this.w+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.C--)}};t({c:!0,v:!0,a:!0,ad:!0});var v,w;
- function x(a){if("string"==typeof a){v||(v=self.document.createElement("a"),w=self.UrlCache||(self.UrlCache=new u(100)));var b=w,c=v;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 y(a,b){var c;c=void 0===c?"source":c;q().assert(null!=a,"%s %s must be available",b,c);var d=a;q().assert(x(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 z(){var a,b;this.promise=new Promise(function(c,d){a=c;b=d});this.resolve=a;this.reject=b};function A(a){if(a.nodeType){var b=(a.ownerDocument||a).defaultView;if(b=b!=(b.__AMP_TOP||b)&&B(b,"url-replace")?D(b,"url-replace"):null)return b}return E(a,"url-replace")}function F(a,b){a=a.__AMP_TOP||a;return D(a,b)}function E(a,b){a=G(a);a=H(a);return D(a,b)}function G(a){return a.nodeType?F((a.ownerDocument||a).defaultView,"ampdoc").getAmpDoc(a):a}function H(a){a=G(a);return a.isSingleDoc()?a.win:a}
- function D(a,b){B(a,b);var c=I(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 J(a,b){var c;(c=I(a)[b])?c.promise?c=c.promise:(D(a,b),c=c.promise=Promise.resolve(c.obj)):c=null;var d=c;if(d)return d;var e=new z,f=e;c=f.promise;f=f.resolve;I(a)[b]={obj:null,promise:c,resolve:f,context:null,ctor:null};return c}function I(a){var b=a.services;b||(b=a.services={});return b}
- function B(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 */
- var K,L="Webkit webkit Moz moz ms O o".split(" ");function M(){this.h=0;this.N=Promise.resolve();this.L=function(){};this.M=function(){}}M.prototype.onQueueEmpty=function(a){this.L=a;0==this.h&&a()};M.prototype.onQueueNotEmpty=function(a){this.M=a;0<this.h&&a()};M.prototype.registerUI=function(a){var b=this;0==this.h&&this.M();this.h++;var c=this.N.then(function(){return a().then(function(){b.h--;0==b.h&&b.L()})});return this.N=c};function N(a){a=AMP.BaseElement.call(this,a)||this;a.G=null;a.l=null;var b=new z;a.H=b.promise;a.I=b.resolve;a.j=null;a.B=!1;a.m=null;a.D="";a.F=null;a.P=null;return a}k(N,AMP.BaseElement);h=N.prototype;h.isAlwaysFixed=function(){return!0};
- h.buildCallback=function(){var a=this,b=this.getAmpDoc();this.P=A(b);this.F=J(H(b),"storage");this.l=q().assert(this.element.id,"amp-user-notification should have an id.");this.D="amp-user-notification:"+this.l;(this.m=this.element.getAttribute("data-show-if-href"))&&y(this.m,this.element);(this.j=this.element.getAttribute("data-dismiss-href"))&&y(this.j,this.element);var c=this.element.getAttribute("role");c||this.element.setAttribute("role","alert");var d=this.element.getAttribute("data-persist-dismissal");
- this.B="false"!=d&&"no"!=d;this.registerAction("dismiss",function(){return a.dismiss(!1)});this.registerAction("optoutOfCid",function(){return O(a)});var e=J(H(b),"userNotificationManager");e.then(function(b){b.registerUserNotification(a.l,a)})};
- function P(a,b){var c=a.m;return a.P.expandUrlAsync(c).then(function(c){var d;d={elementId:a.l,ampUserId:b};var f=[],g;for(g in d){var n=d[g];if(null!=n)if(Array.isArray(n))for(var C=0;C<n.length;C++){var S=n[C];f.push(encodeURIComponent(g)+"="+encodeURIComponent(S))}else f.push(encodeURIComponent(g)+"="+encodeURIComponent(n))}d=f.join("&");f=c;d?(f=f.split("#",2),g=f[0].split("?",2),d=g[0]+(g[1]?"?"+g[1]+"&"+d:"?"+d),d+=f[1]?"#"+f[1]:""):d=f;return d})}
- h.S=function(a){var b=this;this.G=a;return P(this,a).then(function(a){var c={credentials:"include",requireAmpResponseSourceOrigin:!1};return F(b.win,"xhr").fetchJson(a,c).then(function(a){return a.json()})})};function Q(a){var b=a.element.getAttribute("enctype")||"application/json;charset=utf-8";F(a.win,"xhr").fetchJson(a.j,{method:"POST",credentials:"include",requireAmpResponseSourceOrigin:!1,body:t({elementId:a.l,ampUserId:a.G}),headers:{"Content-Type":b}})}
- h.U=function(a){q().assert("boolean"==typeof a.showNotification,'`showNotification` should be a boolean. Got "%s" which is of type %s.',a.showNotification,typeof a.showNotification);a.showNotification||this.I();return Promise.resolve(a.showNotification)};function O(a){return J(H(a.element),"cid").then(function(a){return a.optOut()}).then(function(){return a.dismiss(!1)},function(b){r().error("amp-user-notification","Failed to opt out of Cid",b);a.dismiss(!0)})}
- function R(a){return J(H(a.element),"cid").then(function(b){return b.get({scope:"amp-user-notification",createCookieIfNotPresent:!0},Promise.resolve(),a.H)})}h.shouldShow=function(){var a=this;return this.isDismissed().then(function(b){return b?!1:a.m?R(a).then(a.S.bind(a)).then(a.U.bind(a)):!0})};
- h.show=function(){var a=this.element,b;b=a.style;K||(K=Object.create(null));var c=K.display;if(!c){c="display";if(void 0===b.display){var d;b:{for(d=0;d<L.length;d++){var e=L[d]+"Display";if(void 0!==b[e]){d=e;break b}}d=""}void 0!==b[d]&&(c=d)}K.display=c}b=c;b&&(a.style[b]="");this.element.classList.add("amp-active");this.getViewport().addToFixedLayer(this.element);return this.H};
- h.isDismissed=function(){var a=this;return this.B?this.F.then(function(b){return b.get(a.D)}).then(function(a){return!!a},function(a){r().error("amp-user-notification","Failed to read storage",a);return!1}):Promise.resolve(!1)};h.activate=function(){this.dismiss(!1)};
- h.dismiss=function(a){var b=this;this.element.classList.remove("amp-active");this.element.classList.add("amp-hidden");this.I();this.getViewport().removeFromFixedLayer(this.element);this.B&&!a&&this.F.then(function(a){a.set(b.D,!0)});this.j&&Q(this)};function T(a){this.ampdoc=a;this.O=Object.create(null);this.A=Object.create(null);this.V=E(this.ampdoc,"viewer");this.J=this.ampdoc.whenReady();this.K=Promise.all([this.V.whenFirstVisible(),this.J]);this.T=J(H(this.ampdoc),"notificationUIManager")}
- T.prototype.get=function(a){var b=this;this.K.then(function(){null==b.ampdoc.getElementById(a)&&q().warn("amp-user-notification","Did not find amp-user-notification element "+a+".")});return U(this,a).promise};T.prototype.getNotification=function(a){var b=this;return this.J.then(function(){return b.O[a]})};
- T.prototype.registerUserNotification=function(a,b){var c=this;this.O[a]=b;var d=U(this,a);return this.K.then(function(){return b.shouldShow()}).then(function(a){if(a)return c.T.then(function(a){return a.registerUI(b.show.bind(b))})}).then(d.resolve.bind(this,b)).catch(m.bind(null,"Notification service failed amp-user-notification",a))};function U(a,b){if(a.A[b])return a.A[b];var c=new z;return a.A[b]={promise:c.promise,resolve:c.resolve}}
- (function(a){a.registerServiceForDoc("userNotificationManager",T);a.registerServiceForDoc("notificationUIManager",M);a.registerElement("amp-user-notification",N,"amp-user-notification{position:fixed!important;bottom:0;left:0;overflow:hidden!important;visibility:hidden;background:hsla(0,0%,100%,0.7);z-index:1000;width:100%}amp-user-notification.amp-active{visibility:visible}amp-user-notification.amp-hidden{visibility:hidden}\n/*# sourceURL=/extensions/amp-user-notification/0.1/amp-user-notification.css*/")})(self.AMP);
- })});
- //# sourceMappingURL=amp-user-notification-0.1.js.map
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement