jenkins-bot has submitted this change and it was merged.

Change subject: Defer loading of ZeroOverlay until needed
......................................................................


Defer loading of ZeroOverlay until needed

Remove ZeroInfo and oojs ui

Loading these modules unconditionally will increase first paint on all users
visiting us via Zero. This could be potentially impacting our first paint
graphs.

Bug: T114416
Bug: T114411
Change-Id: Ia60519e8dd5fa1ae6ff99f9a8c625269afe5c700
---
M ZeroBanner.php
D modules/ZeroInfo.js
M modules/interstitial.js
R modules/zerobanner.interstitial/ZeroOverlay.js
R modules/zerobanner.interstitial/interstitial.hogan
R modules/zerobanner.interstitial/interstitial.less
R modules/zerobanner.interstitial/zeroinfo.hogan
7 files changed, 61 insertions(+), 108 deletions(-)

Approvals:
  Jhobs: Looks good to me, but someone else must approve
  Yurik: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/ZeroBanner.php b/ZeroBanner.php
index aba96ec..14424be 100644
--- a/ZeroBanner.php
+++ b/ZeroBanner.php
@@ -69,31 +69,42 @@
        'styles' => 'modules/banner.css',
 );
 
-$wgResourceModules['zerobanner'] = array(
+$wgResourceModules['zerobanner.interstitial'] = array(
+       'localBasePath' => __DIR__,
+       'remoteExtPath' => $remoteExtPath,
+       'targets' => array(
+               'mobile'
+       ),
        'dependencies' => array(
                'mobile.overlays',
                'mobile.settings',
+       ),
+       'templates' => array(
+               'interstitial.hogan' => 
'modules/zerobanner.interstitial/interstitial.hogan',
+               'zeroinfo.hogan' => 
'modules/zerobanner.interstitial/zeroinfo.hogan'
+       ),
+       'scripts' => array(
+               'modules/zerobanner.interstitial/ZeroOverlay.js'
+       ),
+       'styles' => array(
+               'modules/zerobanner.interstitial/interstitial.less'
+       ),
+);
+
+$wgResourceModules['zerobanner'] = array(
+       'dependencies' => array(
+               'mobile.settings',
                'mobile.startup',
-               'oojs-ui',
                'zerobanner.styles'
        ),
        'localBasePath' => __DIR__,
        'remoteExtPath' => $remoteExtPath,
-       'templates' => array(
-               'interstitial.hogan' => 'templates/interstitial.hogan',
-               'zeroinfo.hogan' => 'templates/zeroinfo.hogan'
-       ),
        'targets' => array(
                'mobile'
        ),
        'scripts' => array(
                'modules/banner.js',
                'modules/interstitial.js',
-               'modules/ZeroInfo.js',
-               'modules/ZeroOverlay.js'
-       ),
-       'styles' => array(
-               'modules/interstitial.less'
        ),
        'messages' => array(
                'cancel',
diff --git a/modules/ZeroInfo.js b/modules/ZeroInfo.js
deleted file mode 100644
index 8af9cb6..0000000
--- a/modules/ZeroInfo.js
+++ /dev/null
@@ -1,70 +0,0 @@
-/* global mw, OO, jQuery */
-( function( M, $ ) {
-       'use strict';
-       var settings = M.require( 'mobile.settings/settings' ),
-               router = M.require( 'mobile.startup/router' ),
-               ZeroInfo,
-               windowManager;
-
-       ZeroInfo = function () {
-               this.windowManager = windowManager = new OO.ui.WindowManager();
-
-               function ProcessDialog( config ) {
-                       ProcessDialog.super.call( this, config );
-               }
-
-               OO.inheritClass( ProcessDialog, OO.ui.ProcessDialog );
-               ProcessDialog.static.title = mw.msg( 'zero-info-title' );
-               ProcessDialog.static.actions = [
-                       { label: 'X', flags: 'safe' }
-               ];
-               ProcessDialog.prototype.initialize = function () {
-                       ProcessDialog.super.prototype.initialize.apply( this, 
arguments );
-
-                       var conf = ( window && window.zeroGlobalConfig ) || 
false,
-                               warnHttps = conf && conf.warnHttps,
-                               tplData = {
-                                       intro: mw.msg( warnHttps ? 
'zero-info-https-warn' : 'zero-info-intro', conf.name ),
-                                       url: conf.bannerUrl,
-                                       moreInfo: mw.msg( 
'zero-info-buttonText' )
-                               };
-
-                       var content = mw.template.get( 'zerobanner', 
'zeroinfo.hogan' ).render( tplData );
-
-                       this.$body.append( content );
-                       if ( conf.bannerWarning && settings.get( 'zerodontask', 
true ) !== 'true' ) {
-                               $( '#banner-link' ).click( function ( ev ) {
-                                       ev.preventDefault();
-                                       M.require( 'ZeroOverlay' );
-                                       window.location.hash = '#/zerosite/' + 
this.href;
-                               } );
-                       }
-               };
-               ProcessDialog.prototype.getTeardownProcess = function ( data ) {
-                       // Parent method
-                       return 
ProcessDialog.super.prototype.getTeardownProcess.call( this, data )
-                               .first( function () {
-                                       if ( window.location.hash === 
'#/zeroinfo' ) {
-                                               history.replaceState('', 
document.title, window.location.pathname + location.search);
-                                       }
-                               }, this );
-               };
-
-               $( 'body' ).append( this.windowManager.$element );
-               var dialog = new ProcessDialog();
-               this.windowManager.addWindows( [dialog] );
-               this.windowManager.openWindow( dialog );
-
-               // Listen to router and hide dialog on URL change
-               router.once( 'route', function () {
-                       windowManager.clearWindows();
-               } );
-       };
-
-       router.route( /^\/zeroinfo/, function () {
-               return new ZeroInfo();
-       } );
-
-       M.define( 'ZeroInfo', ZeroInfo );
-
-}( mw.mobileFrontend, jQuery ) );
diff --git a/modules/interstitial.js b/modules/interstitial.js
index ce05974..39dcb6b 100644
--- a/modules/interstitial.js
+++ b/modules/interstitial.js
@@ -1,6 +1,9 @@
 /* global mw, jQuery */
 ( function ( M, $ ) {
        'use strict';
+       var router = M.require( 'mobile.startup/router' ),
+               settings = M.require( 'mobile.settings/settings' );
+
        $( function () {
                var config = window && window.zeroGlobalConfig || false,
                        hostname = document.location.hostname.toLowerCase(), // 
hostname of the current page
@@ -52,14 +55,6 @@
                } else {
                        /* We should avoid !important for these */
                        $( '.icon-uploads,.edit-page' ).hide();
-               }
-
-               if ( config && config.testInfoScreen ) {
-                       $( '#zero-rated-banner' ).on( 'click', function ( ev ) {
-                               ev.preventDefault();
-                               M.require( 'ZeroInfo' );
-                               window.location.hash = '#/zeroinfo';
-                       } );
                }
 
                // Disable other click event handlers for images/thumbnails, 
for example, the
@@ -202,4 +197,38 @@
                        }
                } );
        } );
+
+       /**
+        * @param {String} url that user is trying to access
+        * @param {Boolean} isImage whether that url is an image
+        * @ignore
+        */
+       function loadZeroOverlay( url, isImage ) {
+               var d = $.Deferred();
+               mw.loader.using( 'zerobanner.interstitial' ).done( function () {
+                       var ZeroOverlay = M.require( 
'zerobanner.interstitial/ZeroOverlay' ),
+                               overlay = new ZeroOverlay( { url: url, image: 
isImage } );
+
+                       overlay.show();
+                       d.resolve( overlay );
+               } );
+       }
+
+       router.route( /^\/zerosite\/(.*)/, function( url ) {
+               if ( settings.get( 'zerodontask', true ) ) {
+                       window.history.replaceState('', document.title, 
window.location.pathname);
+               } else {
+                       return loadZeroOverlay( url, false );
+               }
+       } );
+
+       router.route( /^\/zerofile\/(.*)/, function( url ) {
+               if ( settings.get( 'zerodontask', true ) ) {
+                       // FIXME: This will not work in older devices.
+                       window.history.replaceState('', document.title, 
window.location.pathname);
+               } else {
+                       return loadZeroOverlay( url, true );
+               }
+       } );
+
 }( mw.mobileFrontend, jQuery ) );
diff --git a/modules/ZeroOverlay.js 
b/modules/zerobanner.interstitial/ZeroOverlay.js
similarity index 72%
rename from modules/ZeroOverlay.js
rename to modules/zerobanner.interstitial/ZeroOverlay.js
index b326e51..d04901c 100644
--- a/modules/ZeroOverlay.js
+++ b/modules/zerobanner.interstitial/ZeroOverlay.js
@@ -20,7 +20,7 @@
                        dontWarnBtn: mw.msg( 'zero-dont-ask' )
                },
                templatePartials: $.extend( {}, 
ContentOverlay.prototype.templatePartials, {
-                       content: mw.template.get( 'zerobanner', 
'interstitial.hogan' )
+                       content: mw.template.get( 'zerobanner.interstitial', 
'interstitial.hogan' )
                } ),
                events: {
                        'click .zero-button-custom': 'onCustomButtonClick',
@@ -51,23 +51,6 @@
                }
        });
 
-       router.route( /^\/zerosite\/(.*)/, function( url ) {
-               if ( settings.get( 'zerodontask', true ) ) {
-                       window.history.replaceState('', document.title, 
window.location.pathname);
-               } else {
-                       var overlay = new ZeroOverlay( { url: url, image: false 
} );
-                       overlay.show();
-               }
-       } );
-       router.route( /^\/zerofile\/(.*)/, function( url ) {
-               if ( settings.get( 'zerodontask', true ) ) {
-                       window.history.replaceState('', document.title, 
window.location.pathname);
-               } else {
-                       var overlay = new ZeroOverlay( { url: url, image: true 
} );
-                       overlay.show();
-               }
-       } );
-
-       M.define( 'ZeroOverlay', ZeroOverlay );
+       M.define( 'zerobanner.interstitial/ZeroOverlay', ZeroOverlay );
 
 }( mw.mobileFrontend, jQuery ) );
diff --git a/templates/interstitial.hogan 
b/modules/zerobanner.interstitial/interstitial.hogan
similarity index 100%
rename from templates/interstitial.hogan
rename to modules/zerobanner.interstitial/interstitial.hogan
diff --git a/modules/interstitial.less 
b/modules/zerobanner.interstitial/interstitial.less
similarity index 100%
rename from modules/interstitial.less
rename to modules/zerobanner.interstitial/interstitial.less
diff --git a/templates/zeroinfo.hogan 
b/modules/zerobanner.interstitial/zeroinfo.hogan
similarity index 100%
rename from templates/zeroinfo.hogan
rename to modules/zerobanner.interstitial/zeroinfo.hogan

-- 
To view, visit https://gerrit.wikimedia.org/r/243014
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia60519e8dd5fa1ae6ff99f9a8c625269afe5c700
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/ZeroBanner
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jhobs <[email protected]>
Gerrit-Reviewer: Yurik <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to