uni.webview.1.5.4.js 7.5 KB

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