@@ -2067,12 +2067,11 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
20672067 aniShow : 'slide-in-right'
20682068 } ;
20692069 //若执行了显示动画初始化操作,则要覆盖默认配置
2070- if ( $ . options . show ) {
2070+ if ( $ . options . show ) {
20712071 defaultShow = $ . extend ( true , defaultShow , $ . options . show ) ;
20722072 }
20732073
20742074 $ . currentWebview = null ;
2075- $ . isHomePage = false ;
20762075
20772076 $ . extend ( true , $ . global , defaultOptions ) ;
20782077 $ . extend ( true , $ . options , defaultOptions ) ;
@@ -2085,7 +2084,7 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
20852084 return $ . extend ( true , { } , {
20862085 autoShow : true ,
20872086 title : '' ,
2088- modal :false
2087+ modal : false
20892088 } , options ) ;
20902089 } ;
20912090 /**
@@ -2113,7 +2112,7 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
21132112 * @returns {_L6.$ }
21142113 */
21152114 $ . plusReady = function ( callback ) {
2116- if ( window . plus ) {
2115+ if ( window . plus ) {
21172116 setTimeout ( function ( ) { //解决callback与plusready事件的执行时机问题(典型案例:showWaiting,closeWaiting)
21182117 callback ( ) ;
21192118 } , 0 ) ;
@@ -2132,12 +2131,14 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
21322131 * @returns {undefined }
21332132 */
21342133 $ . fire = function ( webview , eventType , data ) {
2135- if ( webview ) {
2136- if ( data !== '' ) {
2137- data = data || { } ;
2138- if ( $ . isPlainObject ( data ) ) {
2139- data = JSON . stringify ( data || { } ) . replace ( / \' / g, "\\u0027" ) . replace ( / \\ / g, "\\u005c" ) ;
2140- }
2134+ if ( webview ) {
2135+ if ( typeof data === 'undefined' ) {
2136+ data = '' ;
2137+ } else if ( typeof data === 'boolean' || typeof data === 'number' ) {
2138+ webview . evalJS ( "typeof mui!=='undefined'&&mui.receive('" + eventType + "'," + data + ")" ) ;
2139+ return ;
2140+ } else if ( $ . isPlainObject ( data ) ) {
2141+ data = JSON . stringify ( data || { } ) . replace ( / \' / g, "\\u0027" ) . replace ( / \\ / g, "\\u005c" ) ;
21412142 }
21422143 webview . evalJS ( "typeof mui!=='undefined'&&mui.receive('" + eventType + "','" + data + "')" ) ;
21432144 }
@@ -2149,39 +2150,39 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
21492150 * @returns {undefined }
21502151 */
21512152 $ . receive = function ( eventType , data ) {
2152- if ( eventType ) {
2153+ if ( eventType ) {
21532154 try {
2154- if ( data ) {
2155+ if ( data && typeof data === 'string' ) {
21552156 data = JSON . parse ( data ) ;
21562157 }
2157- } catch ( e ) { }
2158+ } catch ( e ) { }
21582159 $ . trigger ( document , eventType , data ) ;
21592160 }
21602161 } ;
21612162 var triggerPreload = function ( webview ) {
2162- if ( ! webview . preloaded ) {
2163+ if ( ! webview . preloaded ) {
21632164 $ . fire ( webview , 'preload' ) ;
21642165 var list = webview . children ( ) ;
2165- for ( var i = 0 ; i < list . length ; i ++ ) {
2166+ for ( var i = 0 ; i < list . length ; i ++ ) {
21662167 $ . fire ( list [ i ] , 'preload' ) ;
21672168 }
21682169 webview . preloaded = true ;
21692170 }
21702171 } ;
21712172 var trigger = function ( webview , eventType , timeChecked ) {
2172- if ( timeChecked ) {
2173- if ( ! webview [ eventType + 'ed' ] ) {
2173+ if ( timeChecked ) {
2174+ if ( ! webview [ eventType + 'ed' ] ) {
21742175 $ . fire ( webview , eventType ) ;
21752176 var list = webview . children ( ) ;
2176- for ( var i = 0 ; i < list . length ; i ++ ) {
2177+ for ( var i = 0 ; i < list . length ; i ++ ) {
21772178 $ . fire ( list [ i ] , eventType ) ;
21782179 }
21792180 webview [ eventType + 'ed' ] = true ;
21802181 }
21812182 } else {
21822183 $ . fire ( webview , eventType ) ;
21832184 var list = webview . children ( ) ;
2184- for ( var i = 0 ; i < list . length ; i ++ ) {
2185+ for ( var i = 0 ; i < list . length ; i ++ ) {
21852186 $ . fire ( list [ i ] , eventType ) ;
21862187 }
21872188 }
@@ -2194,28 +2195,28 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
21942195 * @param {object } options 可选:参数,等待,窗口,显示配置{params:{},waiting:{},styles:{},show:{} }
21952196 */
21962197 $ . openWindow = function ( url , id , options ) {
2197- if ( typeof url === 'object' ) {
2198+ if ( typeof url === 'object' ) {
21982199 options = url ;
21992200 url = options . url ;
22002201 id = options . id || url ;
22012202 } else {
2202- if ( typeof id === 'object' ) {
2203+ if ( typeof id === 'object' ) {
22032204 options = id ;
22042205 id = url ;
22052206 } else {
22062207 id = id || url ;
22072208 }
22082209 }
2209- if ( ! $ . os . plus ) {
2210+ if ( ! $ . os . plus ) {
22102211 //TODO 先临时这么处理:手机上顶层跳,PC上parent跳
2211- if ( $ . os . ios || $ . os . android ) {
2212+ if ( $ . os . ios || $ . os . android ) {
22122213 window . top . location . href = url ;
22132214 } else {
22142215 window . parent . location . href = url ;
22152216 }
22162217 return ;
22172218 }
2218- if ( ! window . plus ) {
2219+ if ( ! window . plus ) {
22192220 return ;
22202221 }
22212222
@@ -2225,15 +2226,15 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
22252226 webviewCache = null ,
22262227 nShow , nWaiting ;
22272228
2228- if ( $ . webviews [ id ] ) {
2229+ if ( $ . webviews [ id ] ) {
22292230 webviewCache = $ . webviews [ id ] ;
22302231 //webview真实存在,才能获取
2231- if ( plus . webview . getWebviewById ( id ) ) {
2232+ if ( plus . webview . getWebviewById ( id ) ) {
22322233 webview = webviewCache . webview ;
22332234 }
22342235 }
22352236
2236- if ( webviewCache && webview ) { //已缓存
2237+ if ( webviewCache && webview ) { //已缓存
22372238 //每次show都需要传递动画参数;
22382239 //预加载的动画参数优先级:openWindow配置>preloadPages配置>mui默认配置;
22392240 nShow = webviewCache . show ;
@@ -2246,24 +2247,24 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
22462247 webviewCache . afterShowMethodName && webview . evalJS ( webviewCache . afterShowMethodName + '(\'' + JSON . stringify ( params ) + '\')' ) ;
22472248 return webview ;
22482249 } else { //新窗口
2249- if ( options . createNew !== true ) {
2250+ if ( options . createNew !== true ) {
22502251 webview = plus . webview . getWebviewById ( id ) ;
2251- if ( webview ) { //如果已存在
2252+ if ( webview ) { //如果已存在
22522253 nShow = $ . showOptions ( options . show ) ;
22532254 nShow . autoShow && webview . show ( nShow . aniShow , nShow . duration , function ( ) {
22542255 triggerPreload ( webview ) ;
22552256 trigger ( webview , 'pagebeforeshow' , false ) ;
22562257 } ) ;
22572258 return webview ;
22582259 } else {
2259- if ( ! url ) {
2260+ if ( ! url ) {
22602261 throw new Error ( 'webview[' + id + '] does not exist' ) ;
22612262 }
22622263 }
22632264 }
22642265 //显示waiting
22652266 var waitingConfig = $ . waitingOptions ( options . waiting ) ;
2266- if ( waitingConfig . autoShow ) {
2267+ if ( waitingConfig . autoShow ) {
22672268 nWaiting = plus . nativeUI . showWaiting ( waitingConfig . title , waitingConfig . options ) ;
22682269 }
22692270 //创建页面
@@ -2275,10 +2276,10 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
22752276 webview = $ . createWindow ( options ) ;
22762277 //显示
22772278 nShow = $ . showOptions ( options . show ) ;
2278- if ( nShow . autoShow ) {
2279+ if ( nShow . autoShow ) {
22792280 var showWebview = function ( ) {
22802281 //关闭等待框
2281- if ( nWaiting ) {
2282+ if ( nWaiting ) {
22822283 nWaiting . close ( ) ;
22832284 }
22842285 //显示页面
@@ -2291,14 +2292,13 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
22912292 options . afterShowMethodName && webview . evalJS ( options . afterShowMethodName + '(\'' + JSON . stringify ( params ) + '\')' ) ;
22922293 } ;
22932294 //TODO 能走到这一步,应该不用判断url了吧?
2294- if ( ! url ) {
2295+ if ( ! url ) {
22952296 showWebview ( ) ;
22962297 } else {
2297- // webview.addEventListener("loaded", showWebview, false);
22982298 //titleUpdate触发时机早于loaded,更换为titleUpdate后,可以更早的显示webview
22992299 webview . addEventListener ( "titleUpdate" , showWebview , false ) ;
23002300 //loaded事件发生后,触发预加载和pagebeforeshow事件
2301- webview . addEventListener ( "loaded" , function ( ) {
2301+ webview . addEventListener ( "loaded" , function ( ) {
23022302 triggerPreload ( webview ) ;
23032303 trigger ( webview , 'pagebeforeshow' , false ) ;
23042304 } , false ) ;
@@ -2314,32 +2314,32 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
23142314 * @returns {webview }
23152315 */
23162316 $ . createWindow = function ( options , isCreate ) {
2317- if ( ! window . plus ) {
2317+ if ( ! window . plus ) {
23182318 return ;
23192319 }
23202320 var id = options . id || options . url ;
23212321 var webview ;
2322- if ( options . preload ) {
2323- if ( $ . webviews [ id ] && $ . webviews [ id ] . webview . getURL ( ) ) { //已经cache
2322+ if ( options . preload ) {
2323+ if ( $ . webviews [ id ] && $ . webviews [ id ] . webview . getURL ( ) ) { //已经cache
23242324 webview = $ . webviews [ id ] . webview ;
23252325 } else { //新增预加载窗口
23262326 //preload
23272327 //判断是否携带createNew参数,默认为false
2328- if ( options . createNew !== true ) {
2328+ if ( options . createNew !== true ) {
23292329 webview = plus . webview . getWebviewById ( id ) ;
23302330 }
23312331
23322332 //之前没有,那就新创建
2333- if ( ! webview ) {
2333+ if ( ! webview ) {
23342334 webview = plus . webview . create ( options . url , id , $ . windowOptions ( options . styles ) , $ . extend ( {
23352335 preload : true
23362336 } , options . extras ) ) ;
2337- if ( options . subpages ) {
2337+ if ( options . subpages ) {
23382338 $ . each ( options . subpages , function ( index , subpage ) {
23392339 var subpageId = subpage . id || subpage . url ;
2340- if ( subpageId ) { //过滤空对象
2340+ if ( subpageId ) { //过滤空对象
23412341 var subWebview = plus . webview . getWebviewById ( subpageId ) ;
2342- if ( ! subWebview ) { //如果该webview不存在,则创建
2342+ if ( ! subWebview ) { //如果该webview不存在,则创建
23432343 subWebview = plus . webview . create ( subpage . url , subpageId , $ . windowOptions ( subpage . styles ) , $ . extend ( {
23442344 preload : true
23452345 } , subpage . extras ) ) ;
@@ -2361,15 +2361,15 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
23612361 //索引该预加载窗口
23622362 var preloads = $ . data . preloads ;
23632363 var index = preloads . indexOf ( id ) ;
2364- if ( ~ index ) { //删除已存在的(变相调整插入位置)
2364+ if ( ~ index ) { //删除已存在的(变相调整插入位置)
23652365 preloads . splice ( index , 1 ) ;
23662366 }
23672367 preloads . push ( id ) ;
2368- if ( preloads . length > $ . options . preloadLimit ) {
2368+ if ( preloads . length > $ . options . preloadLimit ) {
23692369 //先进先出
23702370 var first = $ . data . preloads . shift ( ) ;
23712371 var webviewCache = $ . webviews [ first ] ;
2372- if ( webviewCache && webviewCache . webview ) {
2372+ if ( webviewCache && webviewCache . webview ) {
23732373 //需要将自己打开的所有页面,全部close;
23742374 //关闭该预加载webview
23752375 $ . closeAll ( webviewCache . webview ) ;
@@ -2378,13 +2378,13 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
23782378 delete $ . webviews [ first ] ;
23792379 }
23802380 } else {
2381- if ( isCreate !== false ) { //直接创建非预加载窗口
2381+ if ( isCreate !== false ) { //直接创建非预加载窗口
23822382 webview = plus . webview . create ( options . url , id , $ . windowOptions ( options . styles ) , options . extras ) ;
2383- if ( options . subpages ) {
2383+ if ( options . subpages ) {
23842384 $ . each ( options . subpages , function ( index , subpage ) {
23852385 var subpageId = subpage . id || subpage . url ;
23862386 var subWebview = plus . webview . getWebviewById ( subpageId ) ;
2387- if ( ! subWebview ) {
2387+ if ( ! subWebview ) {
23882388 subWebview = plus . webview . create ( subpage . url , subpageId , $ . windowOptions ( subpage . styles ) , subpage . extras ) ;
23892389 }
23902390 webview . append ( subWebview ) ;
@@ -2400,7 +2400,7 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
24002400 */
24012401 $ . preload = function ( options ) {
24022402 //调用预加载函数,不管是否传递preload参数,强制变为true
2403- if ( ! options . preload ) {
2403+ if ( ! options . preload ) {
24042404 options . preload = true ;
24052405 }
24062406 return $ . createWindow ( options ) ;
@@ -2411,18 +2411,18 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
24112411 */
24122412 $ . closeOpened = function ( webview ) {
24132413 var opened = webview . opened ( ) ;
2414- if ( opened ) {
2415- for ( var i = 0 , len = opened . length ; i < len ; i ++ ) {
2414+ if ( opened ) {
2415+ for ( var i = 0 , len = opened . length ; i < len ; i ++ ) {
24162416 var openedWebview = opened [ i ] ;
24172417 var open_open = openedWebview . opened ( ) ;
2418- if ( open_open && open_open . length > 0 ) {
2418+ if ( open_open && open_open . length > 0 ) {
24192419 //关闭打开的webview
24202420 $ . closeOpened ( openedWebview ) ;
24212421 //关闭自己
24222422 openedWebview . close ( "none" ) ;
24232423 } else {
24242424 //如果直接孩子节点,就不用关闭了,因为父关闭的时候,会自动关闭子;
2425- if ( openedWebview . parent ( ) !== webview ) {
2425+ if ( openedWebview . parent ( ) !== webview ) {
24262426 openedWebview . close ( 'none' ) ;
24272427 }
24282428 }
@@ -2431,7 +2431,7 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
24312431 } ;
24322432 $ . closeAll = function ( webview , aniShow ) {
24332433 $ . closeOpened ( webview ) ;
2434- if ( aniShow ) {
2434+ if ( aniShow ) {
24352435 webview . close ( aniShow ) ;
24362436 } else {
24372437 webview . close ( ) ;
@@ -2455,14 +2455,14 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
24552455 * @returns {webview }
24562456 */
24572457 $ . appendWebview = function ( options ) {
2458- if ( ! window . plus ) {
2458+ if ( ! window . plus ) {
24592459 return ;
24602460 }
24612461 var id = options . id || options . url ;
24622462 var webview ;
2463- if ( ! $ . webviews [ id ] ) { //保证执行一遍
2463+ if ( ! $ . webviews [ id ] ) { //保证执行一遍
24642464 //TODO 这里也有隐患,比如某个webview不是作为subpage创建的,而是作为target webview的话;
2465- if ( ! plus . webview . getWebviewById ( id ) ) {
2465+ if ( ! plus . webview . getWebviewById ( id ) ) {
24662466 webview = plus . webview . create ( options . url , id , options . styles , options . extras ) ;
24672467 }
24682468 //之前的实现方案:子窗口loaded之后再append到父窗口中;
@@ -2493,29 +2493,28 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
24932493 handle : function ( ) {
24942494 var options = $ . options ;
24952495 var subpages = options . subpages || [ ] ;
2496- if ( $ . os . plus ) {
2496+ if ( $ . os . plus ) {
24972497 $ . plusReady ( function ( ) {
24982498 //TODO 这里需要判断一下,最好等子窗口加载完毕后,再调用主窗口的show方法;
24992499 //或者:在openwindow方法中,监听实现;
25002500 $ . each ( subpages , function ( index , subpage ) {
25012501 $ . appendWebview ( subpage ) ;
25022502 } ) ;
25032503 //判断是否首页
2504- if ( plus . webview . currentWebview ( ) === plus . webview . getWebviewById ( plus . runtime . appid ) ) {
2505- $ . isHomePage = true ;
2504+ if ( plus . webview . currentWebview ( ) === plus . webview . getWebviewById ( plus . runtime . appid ) ) {
25062505 //首页需要自己激活预加载;
25072506 //timeout因为子页面loaded之后才append的,防止子页面尚未append、从而导致其preload未触发的问题;
25082507 setTimeout ( function ( ) {
25092508 triggerPreload ( plus . webview . currentWebview ( ) ) ;
25102509 } , 300 ) ;
25112510 }
25122511 //设置ios顶部状态栏颜色;
2513- if ( $ . os . ios && $ . options . statusBarBackground ) {
2512+ if ( $ . os . ios && $ . options . statusBarBackground ) {
25142513 plus . navigator . setStatusBarBackground ( $ . options . statusBarBackground ) ;
25152514 }
2516- if ( $ . os . android && parseFloat ( $ . os . version ) < 4.4 ) {
2515+ if ( $ . os . android && parseFloat ( $ . os . version ) < 4.4 ) {
25172516 //解决Android平台4.4版本以下,resume后,父窗体标题延迟渲染的问题;
2518- if ( plus . webview . currentWebview ( ) . parent ( ) == null ) {
2517+ if ( plus . webview . currentWebview ( ) . parent ( ) == null ) {
25192518 document . addEventListener ( "resume" , function ( ) {
25202519 var body = document . body ;
25212520 body . style . display = 'none' ;
@@ -2564,7 +2563,7 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
25642563 } ;
25652564 $ . ready ( function ( ) {
25662565 //标识当前环境支持statusbar
2567- if ( $ . supportStatusbarOffset ( ) ) {
2566+ if ( $ . supportStatusbarOffset ( ) ) {
25682567 document . body . classList . add ( 'mui-statusbar' ) ;
25692568 }
25702569 } ) ;
0 commit comments