1(function (global, factory) { 2 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 3 typeof define === 'function' && define.amd ? define(factory) : 4 (global = global || self, global.CallApp = factory()); 5}(this, (function () { 'use strict'; 6 7 function _classCallCheck(instance, Constructor) { 8 if (!(instance instanceof Constructor)) { 9 throw new TypeError("Cannot call a class as a function"); 10 } 11 } 12 13 function _defineProperties(target, props) { 14 for (var i = 0; i < props.length; i++) { 15 var descriptor = props[i]; 16 descriptor.enumerable = descriptor.enumerable || false; 17 descriptor.configurable = true; 18 if ("value" in descriptor) descriptor.writable = true; 19 Object.defineProperty(target, descriptor.key, descriptor); 20 } 21 } 22 23 function _createClass(Constructor, protoProps, staticProps) { 24 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 25 if (staticProps) _defineProperties(Constructor, staticProps); 26 return Constructor; 27 } 28 29 function _defineProperty(obj, key, value) { 30 if (key in obj) { 31 Object.defineProperty(obj, key, { 32 value: value, 33 enumerable: true, 34 configurable: true, 35 writable: true 36 }); 37 } else { 38 obj[key] = value; 39 } 40 41 return obj; 42 } 43 44 function _extends() { 45 _extends = Object.assign || function (target) { 46 for (var i = 1; i < arguments.length; i++) { 47 var source = arguments[i]; 48 49 for (var key in source) { 50 if (Object.prototype.hasOwnProperty.call(source, key)) { 51 target[key] = source[key]; 52 } 53 } 54 } 55 56 return target; 57 }; 58 59 return _extends.apply(this, arguments); 60 } 61 62 var ua = navigator.userAgent || ''; // çæ¬å·æ¯è¾ 63 64 var semverCompare = function semverCompare(verionA, versionB) { 65 var isNaN = Number.isNaN; 66 var splitA = verionA.split('.'); 67 var splitB = versionB.split('.'); 68 69 for (var i = 0; i < 3; i++) { 70 var snippetA = Number(splitA[i]); 71 var snippetB = Number(splitB[i]); 72 if (snippetA >
72 snippetB) return 1; 73 if (snippetB > snippetA) return -1; // e.g. '1.0.0-rc' -- Number('0-rc') = NaN 74 75 if (!isNaN(snippetA) && isNaN(snippetB)) return 1; 76 if (isNaN(snippetA) && !isNaN(snippetB)) return -1; 77 } 78 79 return 0; 80 }; 81 /** 82 * è·å ios å¤§çæ¬å· 83 */ 84 85 var getIOSVersion = function getIOSVersion() { 86 var version = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/); 87 return Number.parseInt(version[1], 10); 88 }; 89 /** 90 * è·å 微信 çæ¬å· 91 */ 92 93 var getWeChatVersion = function getWeChatVersion() { 94 var version = navigator.appVersion.match(/micromessenger\/(\d+\.\d+\.\d+)/i); 95 return version[1]; 96 }; 97 var isAndroid = /android/i.test(ua); 98 var isIos = /iphone|ipad|ipod/i.test(ua); 99 var isWechat = /micromessenger\/([\d.]+)/i.test(ua); 100 var isWeibo = /(weibo).*weibo__([\d.]+)/i.test(ua); 101 var isBaidu = /(baiduboxapp)\/([\d.]+)/i.test(ua); 102 var isQQ = /qq\/([\d.]+)/i.test(ua); 103 var isQQBrowser = /(qqbrowser)\/([\d.]+)/i.test(ua); 104 var isQzone = /qzone\/.*_qz_([\d.]+)/i.test(ua); // å®å chrome æµè§å¨ï¼å å« åçchromeæµè§å¨ã䏿èªå¸¦æµè§å¨ã360æµè§å¨ä»¥åæ©æå½å ååèªå¸¦æµè§å¨ 105 var isUC = /UCBrowser/i.test(ua); 106 var isFF = /Firefox/i.test(ua); 107 var isChrome = /Chrome/i.test(ua); 108 //var isOpera = /AppleWeb/i.test(ua); 109 110 var isOriginalChrome = /chrome\/[\d.]+ mobile safari\/[\d.]+/i.test(ua) && isA
110ndroid && ua.indexOf('Version') < 0; // chrome for ios å safari çåºå«ä» ä» æ¯å° Version/<VersionNum> æ¿æ¢æäº CriOS/<ChromeRevision> 111 // ios ä¸å¾å¤ app é½å å« safari æ è¯ï¼ä½å®ä»¬é½æ¯ä»¥èªå·±ç app æ è¯å¼å¤´ï¼è䏿¯ Mozilla 112 113 var isSafari = /safari\/([\d.]+)$/i.test(ua) && isIos && ua.indexOf('Crios') < 0 && ua.indexOf('Mozilla') === 0; 114 115 // çæåºæ¬ç url scheme 116 function buildScheme(config, options) { 117 var path = config.path, 118 param = config.param; 119 var customBuildScheme = options.buildScheme; 120 121 if (typeof customBuildScheme !== 'undefined') { 122 return customBuildScheme(config, options); 123 } 124 125 var _options$scheme = options.scheme, 126 host = _options$scheme.host, 127 port = _options$scheme.port, 128 protocol = _options$scheme.protocol; 129 var portPart = port ? ":".concat(port) : ''; 130 var hostPort = host ? "".concat(host).concat(portPart, "/") : ''; 131 var query = typeof param !== 'undefined' ? Object.keys(param).map(function (key) { 132 return "".concat(key, "=").concat(param[key]); 133 }).join('&') : ''; 134 var urlQuery = query ? "?".concat(query) : ''; 135 return "".concat(protocol, "://").concat(hostPort).concat(path).concat(urlQuery); 136 } // çæä¸å¡éè¦ç url schemeï¼åºåæ¯å¦æ¯å¤é¾ï¼ 137 138 function generateScheme(config, options) { 139 var outChain = options.outChain; 140 var uri = buildScheme(config, options); 141 142 if (typeof outChain !== 'undefined' && outChain) { 143 var protocol = outChain.protocol, 144 path = outChain.path, 145 key = outChain.key; 146 uri = "".concat(protocol, "://").concat(path, "?").concat(key, "=").concat(encodeURIComponent(uri)); 147 } 148 149 return uri; 150 } // çæ android intent 151 152 function generateIntent(config, options) { 153 var outChain = options.outChain; 154 var intent = options.intent, 155 fallback = options.fallback; 156 if (typeof intent === 'undefined') return ''; 157 var keys = Object.keys(intent); 158 var encode = options.encode; 159 var intentParam = keys.map(function (key) { 160 return "".concat(key, "=").concat(intent[key], ";"); 161 }).join(''); 162 var intentTail = "#Intent;".concat(intentParam, "S.browser_fallback_url=").concat(encodeURIComponent(fallback), ";end;"); 163 if(fallback=='####' && !isChrome){ 164 intentTail = "#Intent;".concat(intentParam, "S.browser_fallback_url=").concat(fallback, ";end;"); 165 } 166 if(isChrome){ 167 if(encode) { 168 intentTail = "#Intent;".concat(intentParam, "S.browser_fallback_url=").concat(encodeURIComponent(fallback), ";end;"); 169 } else { 170 intentTail = "#Intent;".concat(intentParam, "S.browser_fallback_url=").concat(fallback, ";end;"); 171 } 172 } 173 var urlPath = buildScheme(config, options); 174 175 if (typeof outChain !== 'undefined' && outChain) { 176 var path = outChain.path, 177 key = outChain.key; 178 return "intent://".concat(path, "?").concat(key, "=").concat(encodeURIComponent(urlPath)).concat(intentTail); 179 } 180 181 urlPath = urlPath.slice(urlPath.indexOf('//') + 2); 182 // alert("intent://".concat(urlPath).concat(intentTail)); 183 return "intent://".concat(urlPath).concat(intentTail); 184 } // çæ universalLink 185 186 function generateUniversalLink(config, options) { 187 var universal = options.universal; 188 if (typeof universal === 'undefined') return ''; 189 var host = universal.host, 190 pathKey = universal.pathKey; 191 var path = config.path, 192 param = config.param; 193 var query = typeof param !== 'undefined' ? Object.keys(param).map(function (key) { 194 return "".concat(key, "=").concat(param[key]); 195 }).join('&') : ''; 196 var urlQuery = query ? "&".concat(query) : ''; 197 return "https://".concat(host, "?").concat(pathKey, "=").concat(path).concat(urlQuery); 198 } // çæ åºç¨å®é¾æ¥ 199 200 function generateYingYongBao(config, options) { 201 var url = generateScheme(config, options); // æ¯æ AppLink 202 203 return "".concat(options.yingyongbao, "&android_schema=").concat(encodeURIComponent(url)); 204 } 205 206 var hidden; 207 var visibilityChange; 208 var iframe; 209
210 function getSupportedProperty() { 211 if (typeof document.hidden !== 'undefined') { 212 // Opera 12.10 and Firefox 18 and later support 213 hidden = 'hidden'; 214 visibilityChange = 'visibilitychange'; 215 } else if (typeof document.msHidden !== 'undefined') { 216 hidden = 'msHidden'; 217 visibilityChange = 'msvisibilitychange'; 218 } else if (typeof document.webkitHidden !== 'undefined') { 219 hidden = 'webkitHidden'; 220 visibilityChange = 'webkitvisibilitychange'; 221 } 222 } 223 224 getSupportedProperty(); 225 /** 226 * 夿页颿¯å¦éèï¼è¿å ¥åå°ï¼ 227 */ 228 229 function isPageHidden() { 230 if (typeof hidden === 'undefined') return false; 231 return document[hidden]; 232 } 233 /** 234 * éè¿ top.location.href 跳转 235 * ä½¿ç¨ top æ¯å ä¸ºå¨ qq 䏿å¼ç页é¢ä¸å±äºé¡¶çº§é¡µé¢(iframe级å«) 236 * èªèº« url åæ´æ æ³è§¦å¨å¤ç«¯æä½ 237 * @param {string}} [uri] - éè¦æå¼çå°å 238 */ 239 240 241 function evokeByLocation(uri) { 242 window.top.location.href = uri; 243 } 244 /** 245 * éè¿ iframe å¤èµ· 246 * @param {string}} [uri] - éè¦æå¼çå°å 247 */ 248 249 function evokeByIFrame(uri) { 250 if (!iframe) { 251 iframe = document.createElement('iframe'); 252 iframe.frameBorder = '0'; 253 iframe.style.cssText = 'display:none;border:0;width:0;height:0;'; 254 document.body.append(iframe); 255 } 256 257 iframe.src = uri; 258 } 259 /** 260 * æ£æµæ¯å¦å¤ç«¯æå 261 * @param cb - å¤ç«¯å¤±è´¥åè°å½æ° 262 * @param timeout 263 */ 264 265 function checkOpen(cb, timeout) { 266 var timer = setTimeout(function () { 267 var pageHidden = isPageHidden(); 268 269 if (!pageHidden) { 270 cb(); 271 } 272 }, timeout); 273 274 if (typeof visibilityChange !== 'undefined') { 275 document.addEventListener(visibilityChange, function () { 276 clearTimeout(timer); 277 }); 278 } else { 279 window.addEventListener('pagehide', function () { 280 clearTimeout(timer); 281 }); 282 } 283 } 284 285 var CallApp = /*#__PURE__*/function () { 286 // Create an instance of CallApp 287 function CallApp(options) { 288 _classCallCheck(this, CallApp); 289 290 _defineProperty(this, "options", void 0); 291 292 var defaultOptions = { 293 timeout: 5000 294 }; 295 this.options = _extends(defaultOptions, options); 296 } 297 /** 298 * 注åä¸ºæ¹æ³ 299 * generateScheme | generateIntent | generateUniversalLink | generateYingYongBao | checkOpen 300 */ 301 302 303 _createClass(CallApp, [{ 304 key: "generateScheme", 305 value: function generateScheme$1(config) { 306 return generateScheme(config, this.options); 307 } 308 }, { 309 key: "generateIntent", 310 value: function generateIntent$1(config) { 311 return generateIntent(config, this.options); 312 } 313 }, { 314 key: "generateUniversalLink", 315 value: function generateUniversalLink$1(config) { 316 return generateUniversalLink(config, this.options); 317 } 318 }, { 319 key: "generateYingYongBao", 320 value: function generateYingYongBao$1(config) { 321 return generateYingYongBao(config, this.options); 322 } 323 }, { 324 key: "checkOpen", 325 value: function checkOpen$1(cb) { 326 return checkOpen(cb, this.options.timeout); 327 } // å¤ç«¯å¤±è´¥è·³è½¬ app store 328 329 }, { 330 key: "fallToAppStore", 331 value: function fallToAppStore() { 332 var _this = this; 333 334 this.checkOpen(function () { 335 evokeByLocation(_this.options.appstore); 336 }); 337 } // å¤ç«¯å¤±è´¥è·³è½¬éç¨(ä¸è½½)页 338 339 }, { 340 key: "fallToFbUrl", 341 value: function fallToFbUrl() { 342 var _this2 = this; 343 344 this.checkOpen(function () { 345 evokeByLocation(_this2.options.fallback); 346 }); 347 } // å¤ç«¯å¤±è´¥è°ç¨èªå®ä¹åè°å½æ° 348 349 }, { 350 key: "fallToCustomCb", 351 value: function fallToCustomCb(callback) { 352 this.checkOpen(function () { 353 callback(); 354 }); 355 } 356 /** 357 * å¤èµ·å®¢æ·ç«¯ 358 * æ ¹æ®ä¸å browser æ§è¡ä¸åå¤ç«¯çç¥ 359 */ 360 361 }, { 362 key: "open", 363 value: function open(config) { 364 var _this$options = this.options, 365 universal = _this$options.universal, 366 appstore = _this$options.appstore, 367 logFunc = _this$options.logFunc, 368 intent = _this$options.intent; 369 var callback = config.callback; 370 var supportUniversal = typeof universal !== 'undefined'; 371 var schemeURL = this.generateScheme(config, this.options); 372 var checkOpenFall; 373 374 if (typeof logFunc !== 'undefined') { 375 logFunc(); 376 } 377 378 if (isIos) { 379 // ios qq ç¦æ¢äº scheme å universalLink å¤èµ·appï¼å®åä¸åå½±å - 18å¹´12æ23æ¥ 380 // ios qq æµè§å¨ç¦æ¢äº universalLink - 2019å¹´5æ1æ¥ 381 // ios å¾®ä¿¡èª 7.0.5 çæ¬æ¾å¼äº Universal Link çéå¶ 382 // ios å¾®åç¦æ¢äº universalLink 383 if (isWechat && semverCompare(getWeChatVersion(), '7.0.5') === -1 || isQQ || isWeibo) { 384 evokeByLocation(appstore); 385 } else if (getIOSVersion() < 9) { 386 evokeByIFrame(schemeURL); 387 checkOpenFall = this.fallToAppStore; 388 } else if (!supportUniversal || isQQBrowser || isQzone) { 389 evokeByLocation(schemeURL); 390 checkOpenFall = this.fallToAppStore; 391 } else { 392 evokeByLocation(this.generateUniversalLink(config)); 393 } // Android 394 // å¨å¾®ä¿¡ä¸ä¸é ç½®äºåºç¨å®é¾æ¥ 395 396 } else if (isWechat && typeof this.options.yingyongbao !== 'undefined') { 397 evokeByLocation(this.generateYingYongBao(config)); 398 } else if (isOriginalChrome) { 399 if (typeof intent !== 'undefined') {
400 evokeByLocation(this.generateIntent(config)); 401 } else { 402 // scheme å¨ andriod chrome 25+ çæ¬ä¸iframeæ æ³æ£å¸¸æèµ· 403 evokeByLocation(schemeURL); 404 checkOpenFall = this.fallToFbUrl; 405 } 406 } else if (isWechat || isBaidu || isWeibo || isQzone) { 407 evokeByLocation(this.options.fallback); 408 } else if (isUC) { 409 //evokeByIFrame(schemeURL); 410 window.location.href=schemeURL; 411 //window.open(schemeURL); 412 checkOpenFall = this.fallToFbUrl; 413 } else if (isFF) { 414 window.location.href=schemeURL; 415 checkOpenFall = this.fallToFbUrl; 416 } else { 417 //window.location.href=schemeURL; 418 evokeByIFrame(schemeURL); 419 checkOpenFall = this.fallToFbUrl; 420 } 421 422 if (typeof callback !== 'undefined') { 423 this.fallToCustomCb(callback); 424 return; 425 } 426 427 if (!checkOpenFall) return; 428 checkOpenFall.call(this); 429 } 430 }]); 431 432 return CallApp; 433 }(); 434 435 return CallApp; 436 437})));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.