callapp-lib2
Version:
call native webview from webpage
2 lines (1 loc) • 9.41 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).CallApp=t()}(this,function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function t(e,t){return e(t={exports:{}},t.exports),t.exports}function v(r,o,e){if(!function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!")}(r),void 0===o)return r;switch(e){case 1:return function(e){return r.call(o,e)};case 2:return function(e,t){return r.call(o,e,t)};case 3:return function(e,t,n){return r.call(o,e,t,n)}}return function(){return r.apply(o,arguments)}}function o(e){return"object"==typeof e?null!==e:"function"==typeof e}function r(e){if(!o(e))throw TypeError(e+" is not an object!");return e}function n(e){try{return!!e()}catch(e){return!0}}function y(e,t){return s.call(e,t)}var m=t(function(e){var t=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=t)}),b=t(function(e){var t=e.exports={version:"2.6.11"};"number"==typeof __e&&(__e=t)}),p=(b.version,!n(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})),i=m.document,u=o(i)&&o(i.createElement),a=!p&&!n(function(){return 7!=Object.defineProperty(u?i.createElement("div"):{},"a",{get:function(){return 7}}).a}),c=Object.defineProperty,f={f:p?Object.defineProperty:function(e,t,n){if(r(e),t=function(e,t){if(!o(e))return e;var n,r;if(t&&"function"==typeof(n=e.toString)&&!o(r=n.call(e)))return r;if("function"==typeof(n=e.valueOf)&&!o(r=n.call(e)))return r;if(!t&&"function"==typeof(n=e.toString)&&!o(r=n.call(e)))return r;throw TypeError("Can't convert object to primitive value")}(t,!0),r(n),a)try{return c(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(e[t]=n.value),e}},g=p?function(e,t,n){return f.f(e,t,{enumerable:!((r=1)&r),configurable:!(2&r),writable:!(4&r),value:n});var r}:function(e,t,n){return e[t]=n,e},s={}.hasOwnProperty,O="prototype",w=function(e,t,n){var r,o,i,u=e&w.F,a=e&w.G,c=e&w.S,f=e&w.P,s=e&w.B,l=e&w.W,p=a?b:b[t]||(b[t]={}),d=p[O],h=a?m:c?m[t]:(m[t]||{})[O];for(r in a&&(n=t),n)(o=!u&&h&&void 0!==h[r])&&y(p,r)||(i=o?h[r]:n[r],p[r]=a&&"function"!=typeof h[r]?n[r]:s&&o?v(i,m):l&&h[r]==i?function(r){function e(e,t,n){if(this instanceof r){switch(arguments.length){case 0:return new r;case 1:return new r(e);case 2:return new r(e,t)}return new r(e,t,n)}return r.apply(this,arguments)}return e[O]=r[O],e}(i):f&&"function"==typeof i?v(Function.call,i):i,f&&((p.virtual||(p.virtual={}))[r]=i,e&w.R&&d&&!d[r]&&g(d,r,i)))};w.F=1,w.G=2,w.S=4,w.P=8,w.B=16,w.W=32,w.U=64,w.R=128;function l(e){if(null==e)throw TypeError("Can't call method on "+e);return e}function d(e){return T(l(e))}function h(e){return isNaN(e=+e)?0:(0<e?x:E)(e)}function _(e){return Object(l(e))}var k,j,S,C=w,M={}.toString,T=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==(t=e,M.call(t).slice(8,-1))?e.split(""):Object(e);var t},E=Math.ceil,x=Math.floor,I=Math.min,P=Math.max,F=Math.min,U=t(function(e){var t="__core-js_shared__",n=m[t]||(m[t]={});(e.exports=function(e,t){return n[e]||(n[e]=void 0!==t?t:{})})("versions",[]).push({version:b.version,mode:"pure",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})}),Q=0,A=Math.random(),q=U("keys"),z=(k=!1,function(e,t,n){var r,o,i,u,a=d(e),c=0<(r=a.length)?I(h(r),9007199254740991):0,f=(i=c,(o=h(o=n))<0?P(o+i,0):F(o,i));if(k&&t!=t){for(;f<c;)if((u=a[f++])!=u)return!0}else for(;f<c;f++)if((k||f in a)&&a[f]===t)return k||f||0;return!k&&-1}),R=q[j="IE_PROTO"]||(q[j]="Symbol(".concat(void 0===(S=j)?"":S,")_",(++Q+A).toString(36))),B="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(","),W=Object.keys||function(e){return function(e,t){var n,r=d(e),o=0,i=[];for(n in r)n!=R&&y(r,n)&&i.push(n);for(;t.length>o;)y(r,n=t[o++])&&(~z(i,n)||i.push(n));return i}(e,B)},L={f:Object.getOwnPropertySymbols},Y={f:{}.propertyIsEnumerable},G=Object.assign,H=!G||n(function(){var e={},t={},n=Symbol(),r="abcdefghijklmnopqrst";return e[n]=7,r.split("").forEach(function(e){t[e]=e}),7!=G({},e)[n]||Object.keys(G({},t)).join("")!=r})?function(e,t){for(var n=_(e),r=arguments.length,o=1,i=L.f,u=Y.f;o<r;)for(var a,c=T(arguments[o++]),f=i?W(c).concat(i(c)):W(c),s=f.length,l=0;l<s;)a=f[l++],p&&!u.call(c,a)||(n[a]=c[a]);return n}:G;C(C.S+C.F,"Object",{assign:H});var N=b.Object.assign,V=e(t(function(e){e.exports={default:N,__esModule:!0}})),D=e(t(function(e,t){t.__esModule=!0,t.default=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}}));C(C.S+C.F*!p,"Object",{defineProperty:f.f});function K(e,t,n){return $.defineProperty(e,t,n)}var $=b.Object,J=t(function(e){e.exports={default:K,__esModule:!0}});e(J);var X=e(t(function(e,t){t.__esModule=!0;var n,o=(n=J)&&n.__esModule?n:{default:n};function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),(0,o.default)(e,r.key,r)}}t.default=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}}));var Z,ee,te,ne;Z="keys",ee=function(){return function(e){return W(_(e))}},te=(b.Object||{})[Z]||Object[Z],(ne={})[Z]=ee(te),C(C.S+C.F*n(function(){te(1)}),"Object",ne);var re=b.Object.keys,oe=e(t(function(e){e.exports={default:re,__esModule:!0}}));function ie(e,t){var n=e.path,r=e.param,o=t.buildScheme;if(void 0!==o)return o(e,t);var i=t.scheme,u=i.host,a=i.port,c=i.protocol,f=u?u+(a?":"+a:"")+"/":"",s=void 0!==r?oe(r).map(function(e){return e+"="+r[e]}).join("&"):"";return c+"://"+f+n+(s?"?"+s:"")}function ue(e,t){var n=t.outChain,r=ie(e,t);void 0!==n&&n&&(r=n.protocol+"://"+n.path+"?"+n.key+"="+encodeURIComponent(r));return r}var ae=null;function ce(){var t=void 0;return"hidden"in document?"":(["webkit","moz","ms","o"].forEach(function(e){e+"Hidden"in document&&(t=e)}),t||!1)}function fe(e){e&&(window.top.location.href=e)}function se(e){ae||((ae=document.createElement("iframe")).frameborder="0",ae.style.cssText="display:none;border:0;width:0;height:0;",document.body.appendChild(ae)),ae.src=e}function le(t,e){var n,r=!1!==(n=ce())&&n+"visibilitychange",o=setTimeout(function(){var e;!1!==(e=ce())&&document[e?e+"Hidden":"hidden"]||t()},e);r?document.addEventListener(r,function(){clearTimeout(o)}):window.addEventListener("pagehide",function(){clearTimeout(o)})}function pe(e){D(this,pe);this.options=V({timeout:2e3},e)}return X(pe,[{key:"generateScheme",value:function(e){return ue(e,this.options)}},{key:"generateIntent",value:function(e){return function(e,t){var n=t.outChain,r=t.intent,o=t.fallback,i="#Intent;"+oe(r).map(function(e){return e+"="+r[e]+";"}).join("")+"S.browser_fallback_url="+encodeURIComponent(o)+";end;",u=ie(e,t);if(void 0!==n&&n){var a=t.outChain;return"intent://"+a.path+"?"+a.key+"="+encodeURIComponent(u)+i}return"intent://"+(u=u.slice(u.indexOf("//")+2))+i}(e,this.options)}},{key:"generateUniversalLink",value:function(e){return function(e,t){var n=t.universal;if(!n)return"";var r=n.host,o=n.pathKey,i=e.path,u=e.param,a=void 0!==u?oe(u).map(function(e){return e+"="+u[e]}).join("&"):"";return"https://"+r+"?"+o+"="+i+(a?"&"+a:"")}(e,this.options)}},{key:"generateYingYongBao",value:function(e){return function(e,t){if(!t.yingyongbao)return null;var n=ue(e,t);return t.yingyongbao+"&android_schema="+encodeURIComponent(n)}(e,this.options)}},{key:"checkOpen",value:function(e){return le(e,this.options.timeout)}},{key:"fallToAppStore",value:function(){var e=this;this.checkOpen(function(){fe(e.options.appstore)})}},{key:"fallToFbUrl",value:function(){var e=this;this.checkOpen(function(){fe(e.options.fallback)})}},{key:"fallToCustomCb",value:function(e){this.checkOpen(function(){e()})}},{key:"open",value:function(e){var t,n,r,o,i,u,a=(t=window.navigator.userAgent||"",n=/android/i.test(t),r=/iphone|ipad|ipod/i.test(t),{isAndroid:n,isIos:r,isWechat:/micromessenger\/([\d.]+)/i.test(t),isWeibo:/(weibo).*weibo__([\d.]+)/i.test(t),isQQ:/qq\/([\d.]+)/i.test(t),isQQBrowser:/(qqbrowser)\/([\d.]+)/i.test(t),isQzone:/qzone\/.*_qz_([\d.]+)/i.test(t),isOriginalChrome:/chrome\/[\d.]+ Mobile Safari\/[\d.]+/i.test(t)&&n,isSafari:/safari\/([\d.]+)$/i.test(t)&&r&&t.indexOf("Crios")<0&&0===t.indexOf("Mozilla")}),c=this.options,f=c.universal,s=c.appstore,l=c.logFunc,p=c.intent,d=e.callback,h=void 0!==f,v=this.generateScheme(e),y=null;void 0!==l&&l(),a.isIos?a.isWechat&&0<=function(e,t){for(var n=e.split("."),r=t.split("."),o=Math.max(n.length,r.length);n.length<o;)n.push("0");for(;r.length<o;)r.push("0");for(var i=0;i<o;i+=1){var u=parseInt(n[i],10),a=parseInt(r[i],10);if(a<u)return 1;if(u<a)return-1}return 0}(navigator.appVersion.match(/micromessenger\/(\d+\.\d+\.\d+)/i)[1]||"","7.0.5")||a.isQQ||a.isQQBrowser?fe(s):(u=navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/),parseInt(u[1],10)<9?(se(v),y=this.fallToAppStore):h?fe(this.generateUniversalLink(e)):(fe(v),y=this.fallToAppStore)):a.isWechat?fe(this.generateYingYongBao(e)):a.isOriginalChrome?void 0!==p?fe(this.generateIntent(e)):(o=v,(i=document.createElement("a")).setAttribute("href",o),i.style.display="none",document.body.appendChild(i),i.click(),y=this.fallToFbUrl):(se(v),y=this.fallToFbUrl),void 0===d?y&&y.call(this):this.fallToCustomCb(d)}}]),pe});