Yurik has uploaded a new change for review.
https://gerrit.wikimedia.org/r/244737
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(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ZeroBanner
refs/changes/37/244737/1
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/244737
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia60519e8dd5fa1ae6ff99f9a8c625269afe5c700
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ZeroBanner
Gerrit-Branch: wmf/1.27.0-wmf.2
Gerrit-Owner: Yurik <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits