提交 515d2b7e 编写于 作者: d-u-a's avatar d-u-a

update: runtime web-view 修改监听DOMContentLoaded事件时机

上级 f810c035
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).uni=n()}(this,function(){"use strict";function i(e,n){var i={options:{timestamp:+new Date},name:e,arg:n};if(!window.plus)return window.parent.postMessage({type:s,data:i,pageId:""},"*");if(0===d.length){var t=plus.webview.currentWebview();if(!t)throw new Error("plus.webview.currentWebview() is undefined");var o=t.parent(),a="";a=o?o.id:t.id,d.push(a)}var r=JSON.stringify(i);plus.webview.getWebviewById(u)?plus.webview.postMessageToUniNView({type:s,args:{data:i,webviewIds:d}},u):plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("'.concat(s,'",').concat(r,",").concat(JSON.stringify(d),");"))}var d=[],u="__uniapp__service",s="WEB_INVOKE_APPSERVICE",n={navigateTo:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("navigateTo",{url:encodeURI(n)})},navigateBack:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).delta;i("navigateBack",{delta:parseInt(n)||1})},switchTab:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("switchTab",{url:encodeURI(n)})},reLaunch:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("reLaunch",{url:encodeURI(n)})},redirectTo:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("redirectTo",{url:encodeURI(n)})},getEnv:function(e){window.plus?e({plus:!0}):e({h5:!0})},postMessage:function(e){i("postMessage",(0<arguments.length&&void 0!==e?e:{}).data||{})}},t=/uni-app/i.test(navigator.userAgent),o=/complete|loaded|interactive/;var a=window.my&&-1<navigator.userAgent.indexOf("AlipayClient");var r=window.swan&&window.swan.webView&&/swan-baiduboxapp/i.test(navigator.userAgent);var w=window.qq&&window.qq.miniProgram&&/QQ/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);var c=window.tt&&window.tt.miniProgram&&/toutiaomicroapp/i.test(navigator.userAgent);var g=window.wx&&window.wx.miniProgram&&/micromessenger/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);for(var e,v=function(){window.UniAppJSBridge=!0,document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady",{bubbles:!0,cancelable:!0}))},f=[function(e){if(t)return setTimeout(function(){window.plus&&o.test(document.readyState)?e():document.addEventListener("plusready",e)},0),n},function(e){if(g)return setTimeout(function(){window.WeixinJSBridge&&window.WeixinJSBridge.invoke?e():document.addEventListener("WeixinJSBridgeReady",e)},0),window.wx.miniProgram},function(e){if(w)return setTimeout(function(){window.QQJSBridge&&window.QQJSBridge.invoke?e():document.addEventListener("QQJSBridgeReady",e)},0),window.qq.miniProgram},function(e){if(a){setTimeout(function(){document.addEventListener("DOMContentLoaded",e)},0);var n=window.my;return{navigateTo:n.navigateTo,navigateBack:n.navigateBack,switchTab:n.switchTab,reLaunch:n.reLaunch,redirectTo:n.redirectTo,postMessage:n.postMessage,getEnv:n.getEnv}}},function(e){if(r)return setTimeout(function(){document.addEventListener("DOMContentLoaded",e)},0),window.swan.webView},function(e){if(c)return setTimeout(function(){document.addEventListener("DOMContentLoaded",e)},0),window.tt.miniProgram},function(e){return setTimeout(function(){document.addEventListener("DOMContentLoaded",e)},0),n}],m=0;m<f.length&&!(e=f[m](v));m++);e=e||{};var p="undefined"!=typeof uni?uni:{};return p.navigateTo?p.miniProgram=e:Object.assign(p,e,{miniProgram:e}),p});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).uni=n()}(this,function(){"use strict";function i(e,n){var i={options:{timestamp:+new Date},name:e,arg:n};if(!window.plus)return window.parent.postMessage({type:s,data:i,pageId:""},"*");if(0===d.length){var t=plus.webview.currentWebview();if(!t)throw new Error("plus.webview.currentWebview() is undefined");var a=t.parent(),r="";r=a?a.id:t.id,d.push(r)}var o=JSON.stringify(i);plus.webview.getWebviewById(u)?plus.webview.postMessageToUniNView({type:s,args:{data:i,webviewIds:d}},u):plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("'.concat(s,'",').concat(o,",").concat(JSON.stringify(d),");"))}var d=[],u="__uniapp__service",s="WEB_INVOKE_APPSERVICE",n={navigateTo:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("navigateTo",{url:encodeURI(n)})},navigateBack:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).delta;i("navigateBack",{delta:parseInt(n)||1})},switchTab:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("switchTab",{url:encodeURI(n)})},reLaunch:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("reLaunch",{url:encodeURI(n)})},redirectTo:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("redirectTo",{url:encodeURI(n)})},getEnv:function(e){window.plus?e({plus:!0}):e({h5:!0})},postMessage:function(e){i("postMessage",(0<arguments.length&&void 0!==e?e:{}).data||{})}},t=/uni-app/i.test(navigator.userAgent),a=/complete|loaded|interactive/;var r=window.my&&-1<navigator.userAgent.indexOf("AlipayClient");var o=window.swan&&window.swan.webView&&/swan/i.test(navigator.userAgent);var w=window.qq&&window.qq.miniProgram&&/QQ/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);var g=window.tt&&window.tt.miniProgram&&/toutiaomicroapp/i.test(navigator.userAgent);var c=window.wx&&window.wx.miniProgram&&/micromessenger/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);for(var e,v=function(){window.UniAppJSBridge=!0,document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady",{bubbles:!0,cancelable:!0}))},m=[function(e){if(t)return window.plus&&a.test(document.readyState)?setTimeout(e,0):document.addEventListener("plusready",e),n},function(e){if(c)return window.WeixinJSBridge&&window.WeixinJSBridge.invoke?setTimeout(e,0):document.addEventListener("WeixinJSBridgeReady",e),window.wx.miniProgram},function(e){if(w)return window.QQJSBridge&&window.QQJSBridge.invoke?setTimeout(e,0):document.addEventListener("QQJSBridgeReady",e),window.qq.miniProgram},function(e){if(r){document.addEventListener("DOMContentLoaded",e);var n=window.my;return{navigateTo:n.navigateTo,navigateBack:n.navigateBack,switchTab:n.switchTab,reLaunch:n.reLaunch,redirectTo:n.redirectTo,postMessage:n.postMessage,getEnv:n.getEnv}}},function(e){if(o)return document.addEventListener("DOMContentLoaded",e),window.swan.webView},function(e){if(g)return document.addEventListener("DOMContentLoaded",e),window.tt.miniProgram},function(e){return document.addEventListener("DOMContentLoaded",e),n}],p=0;p<m.length&&!(e=m[p](v));p++);e=e||{};var f="undefined"!=typeof uni?uni:{};return f.navigateTo?f.miniProgram=e:Object.assign(f,e,{miniProgram:e}),f});
......@@ -7,13 +7,11 @@ const readyRE = /complete|loaded|interactive/
export function initWebviewApi (readyCallback) {
if (!isAppPlus) {
return
}
if (window.plus && readyRE.test(document.readyState)) {
setTimeout(readyCallback, 0)
} else {
document.addEventListener('plusready', readyCallback)
}
setTimeout(() => {
if (window.plus && readyRE.test(document.readyState)) {
readyCallback()
} else {
document.addEventListener('plusready', readyCallback)
}
}, 0)
return api
}
import api from '../../app-plus/runtime/web-view-api'
export function initWebviewApi (readyCallback) {
setTimeout(() => {
document.addEventListener('DOMContentLoaded', readyCallback)
}, 0)
document.addEventListener('DOMContentLoaded', readyCallback)
return api
}
const isAlipay = window.my && navigator.userAgent.indexOf('AlipayClient') > -1
export function initWebviewApi (readyCallback) {
if (!isAlipay) {
export function initWebviewApi (readyCallback) {
if (!isAlipay) {
return
}
setTimeout(() => {
document.addEventListener('DOMContentLoaded', readyCallback)
}, 0)
}
document.addEventListener('DOMContentLoaded', readyCallback)
const {
navigateTo,
navigateBack,
......
const isBaidu = window.swan &&
window.swan.webView &&
/swan-baiduboxapp/i.test(navigator.userAgent)
/swan/i.test(navigator.userAgent)
export function initWebviewApi (readyCallback) {
if (!isBaidu) {
return
}
setTimeout(() => {
document.addEventListener('DOMContentLoaded', readyCallback)
}, 0)
document.addEventListener('DOMContentLoaded', readyCallback)
return window.swan.webView
}
......@@ -6,13 +6,11 @@ const isQQ = window.qq &&
export function initWebviewApi (readyCallback) {
if (!isQQ) {
return
}
if (window.QQJSBridge && window.QQJSBridge.invoke) {
setTimeout(readyCallback, 0)
} else {
document.addEventListener('QQJSBridgeReady', readyCallback)
}
setTimeout(() => {
if (window.QQJSBridge && window.QQJSBridge.invoke) {
readyCallback()
} else {
document.addEventListener('QQJSBridgeReady', readyCallback)
}
}, 0)
return window.qq.miniProgram
}
......@@ -6,8 +6,6 @@ export function initWebviewApi (readyCallback) {
if (!isToutiao) {
return
}
setTimeout(() => {
document.addEventListener('DOMContentLoaded', readyCallback)
}, 0)
document.addEventListener('DOMContentLoaded', readyCallback)
return window.tt.miniProgram
}
......@@ -6,13 +6,12 @@ const isWeixin = window.wx &&
export function initWebviewApi (readyCallback) {
if (!isWeixin) {
return
}
if (window.WeixinJSBridge && window.WeixinJSBridge.invoke) {
setTimeout(readyCallback, 0)
} else {
document.addEventListener('WeixinJSBridgeReady', readyCallback)
}
setTimeout(() => {
if (window.WeixinJSBridge && window.WeixinJSBridge.invoke) {
readyCallback()
} else {
document.addEventListener('WeixinJSBridgeReady', readyCallback)
}
}, 0)
return window.wx.miniProgram
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册