uni.webview.1.5.2.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. ! function(e, n) {
  2. "object" == typeof exports && "undefined" != typeof module ? module.exports = n() : "function" == typeof define &&
  3. define.amd ? define(n) : (e = e || self).uni = n()
  4. }(this, function() {
  5. "use strict";
  6. function i(e, n) {
  7. var i = {
  8. options: {
  9. timestamp: +new Date
  10. },
  11. name: e,
  12. arg: n
  13. };
  14. if (window.__dcloud_weex_postMessage || window.__dcloud_weex_) {
  15. if ("postMessage" === e) {
  16. var t = {
  17. data: [n]
  18. };
  19. return window.__dcloud_weex_postMessage ? window.__dcloud_weex_postMessage(t) : window.__dcloud_weex_.postMessage(
  20. JSON.stringify(t))
  21. }
  22. var o = {
  23. type: c,
  24. args: {
  25. data: i,
  26. webviewIds: w
  27. }
  28. };
  29. window.__dcloud_weex_postMessage ? window.__dcloud_weex_postMessageToService(o) : window.__dcloud_weex_.postMessageToService(
  30. JSON.stringify(o))
  31. }
  32. if (!window.plus) return window.parent.postMessage({
  33. type: c,
  34. data: i,
  35. pageId: ""
  36. }, "*");
  37. if (0 === w.length) {
  38. var a = plus.webview.currentWebview();
  39. if (!a) throw new Error("plus.webview.currentWebview() is undefined");
  40. var d = a.parent(),
  41. r = "";
  42. r = d ? d.id : a.id, w.push(r)
  43. }
  44. if (plus.webview.getWebviewById(u)) plus.webview.postMessageToUniNView({
  45. type: c,
  46. args: {
  47. data: i,
  48. webviewIds: w
  49. }
  50. }, u);
  51. else {
  52. var s = JSON.stringify(i);
  53. plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("'.concat(c, '",').concat(s, ",").concat(
  54. JSON.stringify(w), ");"))
  55. }
  56. }
  57. var w = [],
  58. u = "__uniapp__service",
  59. c = "WEB_INVOKE_APPSERVICE",
  60. n = {
  61. navigateTo: function(e) {
  62. var n = (0 < arguments.length && void 0 !== e ? e : {}).url;
  63. i("navigateTo", {
  64. url: encodeURI(n)
  65. })
  66. },
  67. navigateBack: function(e) {
  68. var n = (0 < arguments.length && void 0 !== e ? e : {}).delta;
  69. i("navigateBack", {
  70. delta: parseInt(n) || 1
  71. })
  72. },
  73. switchTab: function(e) {
  74. var n = (0 < arguments.length && void 0 !== e ? e : {}).url;
  75. i("switchTab", {
  76. url: encodeURI(n)
  77. })
  78. },
  79. reLaunch: function(e) {
  80. var n = (0 < arguments.length && void 0 !== e ? e : {}).url;
  81. i("reLaunch", {
  82. url: encodeURI(n)
  83. })
  84. },
  85. redirectTo: function(e) {
  86. var n = (0 < arguments.length && void 0 !== e ? e : {}).url;
  87. i("redirectTo", {
  88. url: encodeURI(n)
  89. })
  90. },
  91. getEnv: function(e) {
  92. window.plus ? e({
  93. plus: !0
  94. }) : e({
  95. h5: !0
  96. })
  97. },
  98. postMessage: function(e) {
  99. i("postMessage", (0 < arguments.length && void 0 !== e ? e : {}).data || {})
  100. }
  101. },
  102. t = /uni-app/i.test(navigator.userAgent),
  103. o = /complete|loaded|interactive/;
  104. var a = window.my && -1 < navigator.userAgent.indexOf("AlipayClient");
  105. var d = window.swan && window.swan.webView && /swan/i.test(navigator.userAgent);
  106. var r = window.qq && window.qq.miniProgram && /QQ/i.test(navigator.userAgent) && /miniProgram/i.test(navigator.userAgent);
  107. var s = window.tt && window.tt.miniProgram && /toutiaomicroapp/i.test(navigator.userAgent);
  108. var g = window.wx && window.wx.miniProgram && /micromessenger/i.test(navigator.userAgent) && /miniProgram/i.test(
  109. navigator.userAgent);
  110. for (var e, v = function() {
  111. window.UniAppJSBridge = !0, document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady", {
  112. bubbles: !0,
  113. cancelable: !0
  114. }))
  115. }, p = [function(e) {
  116. if (t) return window.__dcloud_weex_postMessage || window.__dcloud_weex_ ? document.addEventListener(
  117. "DOMContentLoaded", e) : window.plus && o.test(document.readyState) ? setTimeout(e, 0) : document.addEventListener(
  118. "plusready", e), n
  119. }, function(e) {
  120. if (g) return window.WeixinJSBridge && window.WeixinJSBridge.invoke ? setTimeout(e, 0) : document.addEventListener(
  121. "WeixinJSBridgeReady", e), window.wx.miniProgram
  122. }, function(e) {
  123. if (r) return window.QQJSBridge && window.QQJSBridge.invoke ? setTimeout(e, 0) : document.addEventListener(
  124. "QQJSBridgeReady", e), window.qq.miniProgram
  125. }, function(e) {
  126. if (a) {
  127. document.addEventListener("DOMContentLoaded", e);
  128. var n = window.my;
  129. return {
  130. navigateTo: n.navigateTo,
  131. navigateBack: n.navigateBack,
  132. switchTab: n.switchTab,
  133. reLaunch: n.reLaunch,
  134. redirectTo: n.redirectTo,
  135. postMessage: n.postMessage,
  136. getEnv: n.getEnv
  137. }
  138. }
  139. }, function(e) {
  140. if (d) return document.addEventListener("DOMContentLoaded", e), window.swan.webView
  141. }, function(e) {
  142. if (s) return document.addEventListener("DOMContentLoaded", e), window.tt.miniProgram
  143. }, function(e) {
  144. return document.addEventListener("DOMContentLoaded", e), n
  145. }], l = 0; l < p.length && !(e = p[l](v)); l++);
  146. e = e || {};
  147. var f = "undefined" != typeof uni ? uni : {};
  148. return f.navigateTo ? f.webView = e : Object.assign(f, e, {
  149. webView: e
  150. }), f
  151. });