uni-webview.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. ! function (e, n) {
  2. "object" == typeof exports && "undefined" != typeof module ? module.exports = n() : "function" == typeof define && define.amd ? define(n) : (e = e || self).uni = n()
  3. }(this, (function () {
  4. "use strict";
  5. try {
  6. var e = {};
  7. Object.defineProperty(e, "passive", {
  8. get: function () {
  9. !0
  10. }
  11. }), window.addEventListener("test-passive", null, e)
  12. } catch (e) {}
  13. var n = Object.prototype.hasOwnProperty;
  14. function i(e, i) {
  15. return n.call(e, i)
  16. }
  17. var t = [];
  18. function r() {
  19. return window.__dcloud_weex_postMessage || window.__dcloud_weex_
  20. }
  21. var o = function (e, n) {
  22. var i = {
  23. options: {
  24. timestamp: +new Date
  25. },
  26. name: e,
  27. arg: n
  28. };
  29. if (r()) {
  30. if ("postMessage" === e) {
  31. var o = {
  32. data: [n]
  33. };
  34. return window.__dcloud_weex_postMessage ? window.__dcloud_weex_postMessage(o) : window.__dcloud_weex_.postMessage(JSON.stringify(o))
  35. }
  36. var a = {
  37. type: "WEB_INVOKE_APPSERVICE",
  38. args: {
  39. data: i,
  40. webviewIds: t
  41. }
  42. };
  43. window.__dcloud_weex_postMessage ? window.__dcloud_weex_postMessageToService(a) : window.__dcloud_weex_.postMessageToService(JSON.stringify(a))
  44. }
  45. if (!window.plus) return window.parent.postMessage({
  46. type: "WEB_INVOKE_APPSERVICE",
  47. data: i,
  48. pageId: ""
  49. }, "*");
  50. if (0 === t.length) {
  51. var d = plus.webview.currentWebview();
  52. if (!d) throw new Error("plus.webview.currentWebview() is undefined");
  53. var s = d.parent(),
  54. w = "";
  55. w = s ? s.id : d.id, t.push(w)
  56. }
  57. if (plus.webview.getWebviewById("__uniapp__service")) plus.webview.postMessageToUniNView({
  58. type: "WEB_INVOKE_APPSERVICE",
  59. args: {
  60. data: i,
  61. webviewIds: t
  62. }
  63. }, "__uniapp__service");
  64. else {
  65. var u = JSON.stringify(i);
  66. plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("'.concat("WEB_INVOKE_APPSERVICE", '",').concat(u, ",").concat(JSON.stringify(t), ");"))
  67. }
  68. },
  69. a = {
  70. navigateTo: function () {
  71. var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
  72. n = e.url;
  73. o("navigateTo", {
  74. url: encodeURI(n)
  75. })
  76. },
  77. navigateBack: function () {
  78. var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
  79. n = e.delta;
  80. o("navigateBack", {
  81. delta: parseInt(n) || 1
  82. })
  83. },
  84. switchTab: function () {
  85. var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
  86. n = e.url;
  87. o("switchTab", {
  88. url: encodeURI(n)
  89. })
  90. },
  91. reLaunch: function () {
  92. var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
  93. n = e.url;
  94. o("reLaunch", {
  95. url: encodeURI(n)
  96. })
  97. },
  98. redirectTo: function () {
  99. var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
  100. n = e.url;
  101. o("redirectTo", {
  102. url: encodeURI(n)
  103. })
  104. },
  105. getEnv: function (e) {
  106. r() ? e({
  107. nvue: !0
  108. }) : window.plus ? e({
  109. plus: !0
  110. }) : e({
  111. h5: !0
  112. })
  113. },
  114. postMessage: function () {
  115. var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
  116. o("postMessage", e.data || {})
  117. }
  118. },
  119. d = /uni-app/i.test(navigator.userAgent),
  120. s = /Html5Plus/i.test(navigator.userAgent),
  121. w = /complete|loaded|interactive/;
  122. var u = window.my && navigator.userAgent.indexOf(["t", "n", "e", "i", "l", "C", "y", "a", "p", "i", "l", "A"].reverse().join("")) > -1;
  123. var g = window.swan && window.swan.webView && /swan/i.test(navigator.userAgent);
  124. var v = window.qq && window.qq.miniProgram && /QQ/i.test(navigator.userAgent) && /miniProgram/i.test(navigator.userAgent);
  125. var c = window.tt && window.tt.miniProgram && /toutiaomicroapp/i.test(navigator.userAgent);
  126. var m = window.wx && window.wx.miniProgram && /micromessenger/i.test(navigator.userAgent) && /miniProgram/i.test(navigator.userAgent);
  127. var p = window.qa && /quickapp/i.test(navigator.userAgent);
  128. var f = window.ks && window.ks.miniProgram && /micromessenger/i.test(navigator.userAgent) && /miniProgram/i.test(navigator.userAgent);
  129. var l = window.tt && window.tt.miniProgram && /Lark|Feishu/i.test(navigator.userAgent);
  130. var _ = window.jd && window.jd.miniProgram && /micromessenger/i.test(navigator.userAgent) && /miniProgram/i.test(navigator.userAgent);
  131. var E = window.xhs && window.xhs.miniProgram && /xhsminiapp/i.test(navigator.userAgent);
  132. for (var h, P = function () {
  133. window.UniAppJSBridge = !0, document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady", {
  134. bubbles: !0,
  135. cancelable: !0
  136. }))
  137. }, b = [function (e) {
  138. if (d || s) return window.__dcloud_weex_postMessage || window.__dcloud_weex_ ? document.addEventListener("DOMContentLoaded", e) : window.plus && w.test(document.readyState) ? setTimeout(e, 0) : document.addEventListener("plusready", e), a
  139. }, function (e) {
  140. if (m) return window.WeixinJSBridge && window.WeixinJSBridge.invoke ? setTimeout(e, 0) : document.addEventListener("WeixinJSBridgeReady", e), window.wx.miniProgram
  141. }, function (e) {
  142. if (v) return window.QQJSBridge && window.QQJSBridge.invoke ? setTimeout(e, 0) : document.addEventListener("QQJSBridgeReady", e), window.qq.miniProgram
  143. }, function (e) {
  144. if (u) {
  145. document.addEventListener("DOMContentLoaded", e);
  146. var n = window.my;
  147. return {
  148. navigateTo: n.navigateTo,
  149. navigateBack: n.navigateBack,
  150. switchTab: n.switchTab,
  151. reLaunch: n.reLaunch,
  152. redirectTo: n.redirectTo,
  153. postMessage: n.postMessage,
  154. getEnv: n.getEnv
  155. }
  156. }
  157. }, function (e) {
  158. if (g) return document.addEventListener("DOMContentLoaded", e), window.swan.webView
  159. }, function (e) {
  160. if (c) return document.addEventListener("DOMContentLoaded", e), window.tt.miniProgram
  161. }, function (e) {
  162. if (p) {
  163. window.QaJSBridge && window.QaJSBridge.invoke ? setTimeout(e, 0) : document.addEventListener("QaJSBridgeReady", e);
  164. var n = window.qa;
  165. return {
  166. navigateTo: n.navigateTo,
  167. navigateBack: n.navigateBack,
  168. switchTab: n.switchTab,
  169. reLaunch: n.reLaunch,
  170. redirectTo: n.redirectTo,
  171. postMessage: n.postMessage,
  172. getEnv: n.getEnv
  173. }
  174. }
  175. }, function (e) {
  176. if (f) return window.WeixinJSBridge && window.WeixinJSBridge.invoke ? setTimeout(e, 0) : document.addEventListener("WeixinJSBridgeReady", e), window.ks.miniProgram
  177. }, function (e) {
  178. if (l) return document.addEventListener("DOMContentLoaded", e), window.tt.miniProgram
  179. }, function (e) {
  180. if (_) return window.JDJSBridgeReady && window.JDJSBridgeReady.invoke ? setTimeout(e, 0) : document.addEventListener("JDJSBridgeReady", e), window.jd.miniProgram
  181. }, function (e) {
  182. if (E) return window.xhs.miniProgram
  183. }, function (e) {
  184. return document.addEventListener("DOMContentLoaded", e), a
  185. }], y = 0; y < b.length && !(h = b[y](P)); y++);
  186. h || (h = {});
  187. var B = "undefined" != typeof uni ? uni : {};
  188. if (!B.navigateTo)
  189. for (var S in h) i(h, S) && (B[S] = h[S]);
  190. return B.webView = h, B
  191. }));