uni.webview.1.5.2.js 6.9 KB

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