This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
activities.min.js
53 lines (48 loc) · 18.1 KB
/
activities.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(function(){/*
Copyright 2017 The Web Activities Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var c;function k(a,b,d,e,f,g){this.code=a;this.data="ok"==a?b:null;this.mode=d;this.origin=e;this.originVerified=f;this.secureChannel=g;this.ok="ok"==a;this.error="failed"==a?Error(String(b)||""):null};var l=/^https?\:/i,r;function t(a){r||(r=document.createElement("a"));r.href=a;return r}function u(a){if(a.origin)return a.origin;var b=a.protocol,d=a.host;"https:"==b&&d.indexOf(":443")==d.length-4?d=d.replace(":443",""):"http:"==b&&d.indexOf(":80")==d.length-3&&(d=d.replace(":80",""));return b+"//"+d}function v(a){var b=a.indexOf("#");return-1==b?a:a.substring(0,b)}
function x(a){return a?(/^[?#]/.test(a)?a.slice(1):a).split("&").reduce(function(a,d){var b=d.split("=");d=decodeURIComponent(b[0]||"");var f=decodeURIComponent(b[1]||"");d&&(a[d]=f);return a},{}):{}}function z(a){var b={requestId:a.requestId,returnUrl:a.returnUrl,args:a.args};void 0!==a.origin&&(b.origin=a.origin);void 0!==a.originVerified&&(b.originVerified=a.originVerified);return JSON.stringify(b)}
function A(a,b,d){if(b.ok)d(b);else{var e;if(!(e=b.error)){e=null;if("function"==typeof a.DOMException){a=a.DOMException;try{e=new a("AbortError","AbortError")}catch(f){}}e||(e=Error("AbortError"),e.name="AbortError",e.code=20)}a=e;a.activityResult=b;d(Promise.reject(a))}}function B(a){var b=a.navigator;return/Trident|MSIE|IEMobile/i.test(b&&b.userAgent)}function C(a){a=a.navigator;return/Edge/i.test(a&&a.userAgent)}function aa(a){setTimeout(function(){throw a;})};function D(a,b,d,e){this.a=a;this.X=b;this.c=d;this.ma=e;this.F=null;this.Y=!1;this.v=this.S=this.w=this.j=null;this.Z=this.ja.bind(this)}c=D.prototype;c.connect=function(a){if(this.w)throw Error("already connected");this.w=a;this.a.addEventListener("message",this.Z)};c.disconnect=function(){if(this.w&&(this.w=null,this.j&&(E(this.j),this.j=null),this.a.removeEventListener("message",this.Z),this.v)){for(var a in this.v){var b=this.v[a];b.port1&&E(b.port1);b.port2&&E(b.port2)}this.v=null}};
c.isConnected=function(){return null!=this.c};c.getTarget=function(){var a=G(this);if(!a)throw Error("not connected");return a};function G(a){a.w&&!a.F&&(a.F="function"==typeof a.X?a.X():a.X);return a.F}c.getTargetOrigin=function(){if(null==this.c)throw Error("not connected");return this.c};c.sendConnectCommand=function(){var a=B(this.a)||C(this.a);this.sendCommand("connect",{acceptsChannel:a})};
c.sendStartCommand=function(a){var b=null;this.Y&&"function"==typeof this.a.MessageChannel&&(b=new this.a.MessageChannel);b?(this.sendCommand("start",a,[b.port2]),H(this,b.port1)):this.sendCommand("start",a)};c.sendCommand=function(a,b,d){var e={sentinel:"__ACTIVITIES__",cmd:a,payload:b||null};if(this.j)this.j.postMessage(e,d||void 0);else{var f=this.getTarget(),g="connect"==a?null!=this.c?this.c:"*":this.getTargetOrigin();f.postMessage(e,g,d||void 0)}};
c.customMessage=function(a){this.sendCommand("msg",a)};c.onCustomMessage=function(a){this.S=a};c.startChannel=function(a){a=a||"";var b=I(this,a);if(!b.port1){var d=new this.a.MessageChannel;b.port1=d.port1;b.port2=d.port2;b.resolver(b.port1)}b.port2&&(this.sendCommand("cnset",{name:a},[b.port2]),b.port2=null);return b.promise};c.askChannel=function(a){a=a||"";var b=I(this,a);b.port1||this.sendCommand("cnget",{name:a});return b.promise};
function I(a,b){a.v||(a.v={});var d=a.v[b];if(!d){var e,f=new Promise(function(a){e=a}),d={port1:null,port2:null,resolver:e,promise:f};a.v[b]=d}return d}function H(a,b){a.j&&E(a.j);a.j=b;a.j.onmessage=function(b){var d=b.data,f=d&&d.cmd,d=d&&d.payload||null;f&&a.u(f,d,b)}}
c.ja=function(a){if(!this.ma||G(this)==a.source){var b=a.data;if(b&&"__ACTIVITIES__"==b.sentinel){var d=b.cmd;if(!this.j||"connect"==d||"start"==d){var e=a.origin,b=b.payload||null;null==this.c&&"start"==d&&(this.c=e);null==this.c&&a.source&&G(this)==a.source&&(this.c=e);e==this.c&&this.u(d,b,a)}}}};
c.u=function(a,b,d){"connect"==a?(this.j&&(E(this.j),this.j=null),this.Y=b&&b.acceptsChannel||!1,this.w(a,b)):"start"==a?((d=d.ports&&d.ports[0])&&H(this,d),this.w(a,b)):"msg"==a?null!=this.S&&null!=b&&this.S(b):"cnget"==a?this.startChannel(b.name):"cnset"==a?(a=d.ports[0],b=I(this,b.name),b.port1=a,b.resolver(a)):this.w(a,b)};function E(a){try{a.close()}catch(b){}};function J(a){var b=this;this.a=a;this.F=a.parent;this.b=new D(this.a,this.F,null,!1);this.i=null;this.f=!1;this.g=null;this.B=new Promise(function(a){b.g=a});this.h=!1;this.s=this.m=null;this.K=this.ba=0;this.$=this.na.bind(this)}c=J.prototype;c.connect=function(){this.h=this.f=!1;this.b.connect(this.u.bind(this));this.b.sendConnectCommand();return this.B};c.disconnect=function(){this.h=this.f=!1;this.b.disconnect();this.a.removeEventListener("resize",this.$)};
c.getRequestString=function(){K(this);return null};c.getMode=function(){return"iframe"};c.getTargetOrigin=function(){K(this);return this.b.getTargetOrigin()};c.isTargetOriginVerified=function(){K(this);return!0};c.isSecureChannel=function(){return!0};c.accept=function(){K(this);this.h=!0};c.getArgs=function(){K(this);return this.i};c.ready=function(){L(this);this.b.sendCommand("ready");this.I();this.a.addEventListener("resize",this.$)};c.setSizeContainer=function(a){this.s=a};
c.onResizeComplete=function(a){this.m=a};c.resized=function(){var a=this;setTimeout(function(){return a.I()},50)};c.isMessagingSupported=function(){return!0};c.message=function(a){L(this);this.b.customMessage(a)};c.onMessage=function(a){L(this);this.b.onCustomMessage(a)};c.messageChannel=function(a){L(this);return this.b.startChannel(a)};c.result=function(a){this.o("ok",a)};c.cancel=function(){this.o("canceled",null)};c.failed=function(a){this.o("failed",String(a))};
function K(a){if(!a.f)throw Error("not connected");}function L(a){if(!a.h)throw Error("not accepted");}c.o=function(a,b){"ok"==a?L(this):K(this);this.b.sendCommand("result",{code:a,data:b})};c.u=function(a,b){if("start"==a)this.i=b,this.f=!0,this.g(this),this.g=null;else if("close"==a)this.disconnect();else if("resized"==a){var d=b.height;this.m&&this.m(d,this.K,d<this.K)}};c.I=function(){if(this.s){var a=this.s.scrollHeight;a!=this.K&&(this.K=a,this.b.sendCommand("resize",{height:this.K}))}};
c.na=function(){var a=this.a.innerWidth;this.ba!=a&&(this.ba=a,this.resized())};function M(a){var b=this;if(!a.opener||a.opener==a)throw Error("No window.opener");this.a=a;this.F=a.opener;this.b=new D(this.a,this.F,null,!1);this.i=null;this.f=!1;this.g=null;this.B=new Promise(function(a){b.g=a});this.h=!1;this.s=this.m=null;this.U=new N(this.a);this.ea=null;this.G=this.oa.bind(this)}c=M.prototype;
c.connect=function(a){var b=this;this.h=this.f=!1;var d;return this.U.connect(a).then(function(){b.ea=b.U.getRequestString()},function(a){d=a}).then(function(){b.b.connect(b.u.bind(b));b.b.sendConnectCommand();setTimeout(function(){b.g&&(d?b.g(Promise.reject(d)):b.g(b.U),b.g=null)},5E3);return b.B})};c.disconnect=function(){this.h=this.f=!1;this.b.disconnect();this.a.removeEventListener("unload",this.G);this.a.removeEventListener("beforeunload",this.G);try{this.a.close()}catch(a){}};
c.getRequestString=function(){K(this);return this.ea};c.getMode=function(){return"popup"};c.getTargetOrigin=function(){K(this);return this.b.getTargetOrigin()};c.isTargetOriginVerified=function(){K(this);return!0};c.isSecureChannel=function(){return!0};c.accept=function(){K(this);this.h=!0};c.getArgs=function(){K(this);return this.i};c.ready=function(){L(this);this.b.sendCommand("ready")};c.setSizeContainer=function(a){this.s=a};c.onResizeComplete=function(a){this.m=a};
c.resized=function(){var a=this;setTimeout(function(){return a.I()},50)};c.isMessagingSupported=function(){return!0};c.message=function(a){L(this);this.b.customMessage(a)};c.onMessage=function(a){L(this);this.b.onCustomMessage(a)};c.messageChannel=function(a){L(this);return this.b.startChannel(a)};c.result=function(a){this.o("ok",a)};c.cancel=function(){this.o("canceled",null)};c.failed=function(a){this.o("failed",String(a))};c.ia=function(){if(!this.f)throw Error("not connected");};
c.ha=function(){if(!this.h)throw Error("not accepted");};c.o=function(a,b){"ok"==a?L(this):K(this);this.b.sendCommand("result",{code:a,data:b});this.a.removeEventListener("unload",this.G);this.a.removeEventListener("beforeunload",this.G)};c.u=function(a,b){"start"==a?(this.i=b,this.f=!0,this.g(this),this.a.addEventListener("unload",this.G),this.a.addEventListener("beforeunload",this.G)):"close"==a&&this.disconnect()};
c.I=function(){if(this.s){var a=this.s.scrollHeight,b=this.a.innerHeight;this.m&&this.m(b,a,b<a)}};c.oa=function(){this.b.sendCommand("check",{})};function N(a){this.a=a;this.c=this.P=this.L=null;this.J=!1;this.i=null;this.h=this.f=!1;this.s=this.m=null}c=N.prototype;
c.connect=function(a){var b=this;return Promise.resolve().then(function(){b.f=!1;b.h=!1;var d;if(a&&"object"==typeof a)d=a;else{var e=!1,f;if(a&&"string"==typeof a)e=!0,f=a;else{var g=x(b.a.location.hash).__WA__;g&&(f=g)}if(f)if(d=e,d=void 0===d?!1:d,f){f=JSON.parse(f);var h={requestId:f.requestId,returnUrl:f.returnUrl,args:f.args||null};d&&(h.origin=f.origin||void 0,h.originVerified=f.originVerified||void 0);d=h}else d=null}if(!d||!d.requestId||!d.returnUrl)throw Error("Request must have requestId and returnUrl");
b.L=d.requestId;b.i=d.args;if((f=d.returnUrl)&&-1!=t(f).protocol.indexOf("script"))throw Error('unsafe "'+f+'"');b.P=f;if(d.origin)b.c=d.origin,b.J=d.originVerified||!1;else{b.c=u(t(d.returnUrl));var q=b.a.document.referrer&&u(t(b.a.document.referrer));b.J=q==b.c}b.f=!0;return b})};c.disconnect=function(){this.h=this.f=!1};c.getRequestString=function(){K(this);return z({requestId:this.L,returnUrl:this.P,args:this.i,origin:this.c,originVerified:this.J})};c.getMode=function(){return"redirect"};
c.getTargetOrigin=function(){K(this);return this.c};c.isTargetOriginVerified=function(){K(this);return this.J};c.isSecureChannel=function(){return!1};c.accept=function(){K(this);this.h=!0};c.getArgs=function(){K(this);return this.i};c.ready=function(){L(this)};c.setSizeContainer=function(a){this.s=a};c.onResizeComplete=function(a){this.m=a};c.resized=function(){var a=this;setTimeout(function(){return a.I()},50)};c.isMessagingSupported=function(){return!1};c.message=function(){L(this)};
c.onMessage=function(){L(this)};c.messageChannel=function(){L(this);throw Error("not supported");};c.result=function(a){this.o("ok",a)};c.cancel=function(){this.o("canceled",null)};c.failed=function(a){this.o("failed",String(a))};c.ia=function(){if(!this.f)throw Error("not connected");};c.ha=function(){if(!this.h)throw Error("not accepted");};
c.o=function(a,b){"ok"==a?L(this):K(this);var d=this.L,e;e=this.a;e=e.origin||u(e.location);a={requestId:d,origin:e,code:a,data:b};if(this.h)b=this.P;else if(b=this.P,!l.test(b))throw Error("must be http(s)");var f=b,g=f+(-1==f.indexOf("#")?"#":"&")+"__WA_RES__="+encodeURIComponent(JSON.stringify(a));a=g;this.a.location.replace?this.a.location.replace(a):this.a.location.assign(a)};c.I=function(){if(this.s){var a=this.s.scrollHeight,b=this.a.innerHeight;this.m&&this.m(b,a,b<a)}};function O(a){this.version="1.24";this.a=a}O.prototype.connectHost=function(a){return(this.a.top!=this.a?new J(this.a):this.a.opener&&this.a.opener!=this.a&&!this.a.opener.closed?new M(this.a):new N(this.a)).connect(a)};function P(a,b,d){var e=this;this.H=a;this.R=b;this.i=d||null;this.a=this.H.ownerDocument.defaultView;this.c=u(t(b));this.f=!1;this.g=null;this.B=new Promise(function(a){e.g=a});this.M=null;this.ka=new Promise(function(a){e.M=a});this.l=null;this.O=new Promise(function(a){e.l=a});this.N=this.T=null;this.b=new D(this.a,function(){return e.H.contentWindow},this.c,!0)}c=P.prototype;c.getMode=function(){return"iframe"};
c.connect=function(){var a;a=this.H;if("isConnected"in a)a=a.isConnected;else{var b=a.ownerDocument&&a.ownerDocument.documentElement;a=b&&b.contains(a)||!1}if(!a)throw Error("iframe must be in DOM");this.b.connect(this.u.bind(this));this.H.src=this.R;return this.B};c.disconnect=function(){this.f=!1;this.b.disconnect()};c.acceptResult=function(){return this.O};c.getTargetWin=function(){return this.H.contentWindow||null};c.message=function(a){this.b.customMessage(a)};c.onMessage=function(a){this.b.onCustomMessage(a)};
c.messageChannel=function(a){return this.b.askChannel(a)};c.whenReady=function(){return this.ka};c.onResizeRequest=function(a){var b=this;this.T=a;Promise.resolve().then(function(){null!=b.N&&a(b.N)})};c.resized=function(){this.f&&this.b.sendCommand("resized",{height:this.H.offsetHeight})};
c.u=function(a,b){"connect"==a?(this.f=!0,this.b.sendStartCommand(this.i),this.g()):"result"==a?this.l&&(a=b.code,b=new k(a,"failed"==a?Error(b.data||""):b.data,"iframe",this.b.getTargetOrigin(),!0,!0),A(this.a,b,this.l),this.l=null,this.b.sendCommand("close"),this.disconnect()):"ready"==a?this.M&&(this.M(),this.M=null):"resize"==a&&(this.N=b.height,this.T&&this.T(this.N))};function Q(a,b,d,e,f,g){var h=this,q=e&&("_blank"==e||"_top"==e||"_"!=e[0]);if(!q)throw Error('The only allowed targets are "_blank", "_top" and name targets');this.a=a;this.L=b;this.R=d;this.ca=e;this.i=f||null;this.D=g||{};this.g=null;this.B=new Promise(function(a){h.g=a});this.l=null;this.O=new Promise(function(a){h.l=a});this.b=this.C=this.A=null}c=Q.prototype;c.getMode=function(){return"_top"==this.ca?"redirect":"popup"};c.open=function(){return ba(this)};c.whenConnected=function(){return this.B};
c.disconnect=function(){this.C&&(this.a.clearInterval(this.C),this.C=null);this.b&&(this.b.disconnect(),this.b=null);if(this.A){try{this.A.close()}catch(a){}this.A=null}this.l=null};c.getTargetWin=function(){return this.A};c.acceptResult=function(){return this.O};c.message=function(a){this.b.customMessage(a)};c.onMessage=function(a){this.b.onCustomMessage(a)};c.messageChannel=function(a){return this.b.askChannel(a)};
function ba(a){var b=ca(a),d=a.R;if(!a.D.skipRequestInUrl)var e=a.D.returnUrl||v(a.a.location.href),e=z({requestId:a.L,returnUrl:e,args:a.i}),d=d+(-1==d.indexOf("#")?"#":"&")+encodeURIComponent("__WA__")+"="+encodeURIComponent(e);var f,g=a.ca;"_top"!=g&&B(a.a)&&(g="_top");try{f=a.a.open(d,g,b)}catch(h){}if(!f&&"_top"!=g&&!a.D.disableRedirectFallback){g="_top";try{f=a.a.open(d,g)}catch(h){}}f?(a.A=f,"_top"!=g&&da(a)):R(a,Error("failed to open window"));return a.O.catch(function(){})}
function ca(a){var b=a.a.screen,d=b.availWidth||b.width,e=b.availHeight||b.height,f=a.a==a.a.top,g=C(a.a),h=f&&a.a.outerWidth>a.a.innerWidth?Math.min(100,a.a.outerWidth-a.a.innerWidth):g?100:0,q=f&&a.a.outerHeight>a.a.innerHeight?Math.min(100,a.a.outerHeight-a.a.innerHeight):g?100:0,m=Math.max(d-h,.5*d),y=Math.max(e-q,.5*e),n=Math.floor(Math.min(600,.9*m)),p=Math.floor(Math.min(600,.9*y));a.D.width&&(n=Math.min(a.D.width,m));a.D.height&&(p=Math.min(a.D.height,y));a=Math.floor((b.width-n)/2);b=Math.floor((b.height-
p)/2);n={height:p,width:n,resizable:"yes",scrollbars:"yes"};g||(n.left=a,n.top=b);var p="",w;for(w in n)p&&(p+=","),p+=w+"="+n[w];return p}function da(a){a.C=a.a.setInterval(function(){S(a,!0)},500);a.b=new D(a.a,a.A,null,!0);a.b.connect(a.u.bind(a))}function S(a,b){if(!a.A||a.A.closed)a.C&&(a.a.clearInterval(a.C),a.C=null),a.a.setTimeout(function(){try{T(a,"canceled",null)}catch(d){R(a,d)}},b?3E3:0)}function R(a,b){a.l&&a.l(Promise.reject(b));a.disconnect()}
function T(a,b,d){if(a.l){var e=a.b.isConnected();b=new k(b,d,"popup",e?a.b.getTargetOrigin():u(t(a.R)),e,e);A(a.a,b,a.l);a.l=null}a.b&&a.b.sendCommand("close");a.disconnect()}c.u=function(a,b){var d=this;"connect"==a?(this.b.sendStartCommand(this.i),this.g()):"result"==a?(a=b.code,T(this,a,"failed"==a?Error(b.data||""):b.data)):"check"==a&&this.a.setTimeout(function(){return S(d)},200)};function U(a,b,d,e,f){this.a=a;this.fa=b;this.ga=d;this.c=e;this.J=f}U.prototype.getMode=function(){return"redirect"};
U.prototype.acceptResult=function(){var a=this,b=new k(this.fa,this.ga,"redirect",this.c,this.J,!1);return new Promise(function(d){A(a.a,b,d)})};function X(a){var b=this;this.version="1.24";this.a=a;this.aa=a.location.hash;this.V={};this.W={};this.da=null;this.la=new Promise(function(a){b.da=a})}c=X.prototype;c.openIframe=function(a,b,d){var e=new P(a,b,d);return e.connect().then(function(){return e})};c.open=function(a,b,d,e,f){return{targetWin:Y(this,a,b,d,e,f).getTargetWin()}};c.openWithMessaging=function(a,b,d,e,f){var g=Y(this,a,b,d,e,f);return g.whenConnected().then(function(){return g})};
c.onResult=function(a,b){var d=this.V[a];d||(d=[],this.V[a]=d);d.push(b);var e=this.W[a];if(!e&&this.aa){try{var f=this.a,g=x(this.aa).__WA_RES__;if(g){var h=JSON.parse(g);if(h&&h.requestId==a){var q;var m=f.location.hash;if(m){var y=encodeURIComponent("__WA_RES__")+"=",g=-1;do if(g=m.indexOf(y,g),-1!=g){var n=0<g?m.substring(g-1,g):"";if(""==n||"?"==n||"#"==n||"&"==n){var p=m.indexOf("&",g+1);-1==p&&(p=m.length);m=m.substring(0,g)+m.substring(p+1)}else g++}while(-1!=g&&g<m.length)}q=m;q=q||"";if(q!=
f.location.hash&&f.history&&f.history.replaceState)try{f.history.replaceState(f.history.state,"",q)}catch(F){}var w=h.code,ea=h.data,V=h.origin,fa=f.document.referrer&&u(t(f.document.referrer)),e=new U(f,w,ea,V,V==fa)}else e=null}else e=null}catch(F){aa(F),this.da(F)}e&&(this.W[a]=e)}var W=e;W&&Z(W,b)};c.onRedirectError=function(a){this.la.then(a)};function Y(a,b,d,e,f,g){var h=new Q(a.a,b,d,e,f,g);h.open().then(function(){ga(a,b,h)});return h}
function Z(a,b){Promise.resolve().then(function(){b(a)})}function ga(a,b,d){var e=a.V[b];e&&e.forEach(function(a){Z(d,a)});a.W[b]=d};(function(a){function b(a){Promise.resolve().then(function(){a(f)})}var d=new X(a),e=new O(a),f={};Object.defineProperty(f,"version",{value:"1.24",configurable:!1});Object.defineProperty(f,"ports",{get:function(){return d}});Object.defineProperty(f,"hosts",{get:function(){return e}});var g=a.ACTIVITIES,h={};Object.defineProperty(h,"push",{get:function(){return b},configurable:!1});a.ACTIVITIES=h;g&&g.forEach(b)})(self);})();
//# sourceMappingURL=activities.min.js.map