Jdlrobson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/64999
Change subject: Allow nearby to run at top to avoid flash of unstyled content
......................................................................
Allow nearby to run at top to avoid flash of unstyled content
RL nearby modules: Tweak dependencies and load position
beta.common is only needed by page previews due to the requirement of
the Page view and no longer needing animations
Move nearby to top of page so that when loading from cache there is no
flash of unstyled content
Make sure nearby only runs when jQuery is ready
Adjustments to navigation so it can run from top of page and to previews
Change-Id: I434a81af904a9db896abc6eb635ee7be86a6d502
---
M includes/Resources.php
M javascripts/common/mf-navigation.js
M javascripts/specials/nearby.js
M javascripts/specials/overlays/preview.js
4 files changed, 74 insertions(+), 64 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/99/64999/1
diff --git a/includes/Resources.php b/includes/Resources.php
index c36a86f..aa3eebc 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -495,6 +495,7 @@
'mobile.nearby.previews' => $wgMFMobileResourceBoilerplate + array(
'dependencies' => array(
'mobile.nearby.scripts',
+ 'mobile.beta.common',
),
'messages' => array(
// preview.js
@@ -524,10 +525,10 @@
'mobile.nearby.scripts' => $wgMFMobileResourceBoilerplate + array(
'dependencies' => array(
+ 'mobile.stable',
'mobile.nearby.styles',
'mobile.nearby.plumbing',
'jquery.json',
- 'mobile.beta.common',
),
'messages' => array(
'mobile-frontend-nearby-error',
@@ -544,6 +545,8 @@
'scripts' => array(
'javascripts/specials/nearby.js',
),
+ // stop flash of unstyled content when loading from cache
+ 'position' => 'top',
),
'mobile.search.styles' => $wgMFMobileSpecialPageResourceBoilerplate +
array(
'styles' => array(
diff --git a/javascripts/common/mf-navigation.js
b/javascripts/common/mf-navigation.js
index 2bbd2ef..5669054 100644
--- a/javascripts/common/mf-navigation.js
+++ b/javascripts/common/mf-navigation.js
@@ -115,7 +115,16 @@
}
}
- function init() {
+
+ function openNavigation() {
+ $( 'body' ).addClass( 'navigation-enabled' );
+ }
+
+ function closeNavigation() {
+ $( 'body' ).removeClass( 'navigation-enabled' );
+ }
+
+ $( function() {
var
search = document.getElementById( 'searchInput' );
@@ -128,14 +137,6 @@
M.on( 'page-loaded', function( curPage ) {
enableEditing( curPage.title );
} );
- }
-
- function openNavigation() {
- $( 'body' ).addClass( 'navigation-enabled' );
- }
-
- function closeNavigation() {
- $( 'body' ).removeClass( 'navigation-enabled' );
}
function isOpen() {
@@ -176,13 +177,12 @@
closeNavigation();
}
} );
- return {
- close: closeNavigation,
- open: openNavigation
- };
- }
+ } );
- menu = init();
+ menu = {
+ close: closeNavigation,
+ open: openNavigation
+ };
return {
CtaDrawer: CtaDrawer,
diff --git a/javascripts/specials/nearby.js b/javascripts/specials/nearby.js
index b107af3..15a78e7 100644
--- a/javascripts/specials/nearby.js
+++ b/javascripts/specials/nearby.js
@@ -1,14 +1,44 @@
( function( M, $ ) {
var CACHE_KEY_RESULTS = 'mfNearbyLastSearchResult',
+ endpoint = mw.config.get( 'wgMFNearbyEndpoint' ),
+ overlay,
CACHE_KEY_LAST_LOCATION = 'mfNearbyLastKnownLocation';
-( function() {
+function getOverlay() {
+ return overlay;
+}
+
+function distanceMessage( d ) {
+ var msg = 'mobile-frontend-nearby-distance';
+ if ( d < 1 ) {
+ d *= 100;
+ d = Math.ceil( d ) * 10;
+ if ( d === 1000 ) {
+ d = 1;
+ } else {
+ msg = 'mobile-frontend-nearby-distance-meters';
+ }
+ d = d + '';
+ } else {
+ if ( d > 2 ) {
+ d *= 10;
+ d = Math.ceil( d ) / 10;
+ d = d.toFixed( 1 );
+ } else {
+ d *= 100;
+ d = Math.ceil( d ) / 100;
+ d = d.toFixed( 2 );
+ }
+ }
+ return mw.msg( msg, d );
+}
+
+$( function() {
var supported = M.supportsGeoLocation(),
popup = M.require( 'notifications' ),
nav = M.require( 'navigation' ),
View = M.require( 'view' ),
errorHtml = $( '#mw-mf-nearby' ).html(),
- endpoint = mw.config.get( 'wgMFNearbyEndpoint' ),
curLocation,
lastKnownLocation = M.settings.getUserSetting(
CACHE_KEY_LAST_LOCATION ),
cache = M.settings.saveUserSetting,
@@ -29,7 +59,8 @@
self.emit( 'postRender', this.$el );
}
} ),
- pendingQuery = false, btn, menu,
+ pendingQuery = false, btn, menu;
+
overlay = new Nearby( {
el: $( '#mw-mf-nearby' )
} );
@@ -59,31 +90,6 @@
return 2 * radius * Math.asin( Math.sqrt( a ) );
}
return distance;
- }
-
- function distanceMessage( d ) {
- var msg = 'mobile-frontend-nearby-distance';
- if ( d < 1 ) {
- d *= 100;
- d = Math.ceil( d ) * 10;
- if ( d === 1000 ) {
- d = 1;
- } else {
- msg = 'mobile-frontend-nearby-distance-meters';
- }
- d = d + '';
- } else {
- if ( d > 2 ) {
- d *= 10;
- d = Math.ceil( d ) / 10;
- d = d.toFixed( 1 );
- } else {
- d *= 100;
- d = Math.ceil( d ) / 100;
- d = d.toFixed( 2 );
- }
- }
- return mw.msg( msg, d );
}
function render( $content, pages ) {
@@ -215,13 +221,13 @@
menu = $( '<li>' ).appendTo( nav.getPageMenu() );
btn = $( '<button class="refresh">refresh</button></li>' ).on( 'click',
refresh ).appendTo( menu );
+} );
- M.define( 'nearby', {
- distanceMessage: distanceMessage,
- endpoint: endpoint,
- overlay: overlay
- } );
-}() );
+M.define( 'nearby', {
+ distanceMessage: distanceMessage,
+ endpoint: endpoint,
+ getOverlay: getOverlay
+} );
}( mw.mobileFrontend, jQuery ) );
diff --git a/javascripts/specials/overlays/preview.js
b/javascripts/specials/overlays/preview.js
index d6c3214..315c960 100644
--- a/javascripts/specials/overlays/preview.js
+++ b/javascripts/specials/overlays/preview.js
@@ -31,22 +31,23 @@
}
} ),
module = M.require( 'nearby' ),
- endpoint = module.endpoint,
- nearby = module.overlay;
+ endpoint = module.endpoint;
- nearby.on( 'page-click', function( ev ) {
- ev.preventDefault();
- var loader = new LoadingOverlay(),
- $a = $( ev.currentTarget ),
- title = $a.find( 'h2' ).text();
- loader.show();
+ $( function() {
+ module.getOverlay().on( 'page-click', function( ev ) {
+ ev.preventDefault();
+ var loader = new LoadingOverlay(),
+ $a = $( ev.currentTarget ),
+ title = $a.find( 'h2' ).text();
+ loader.show();
- M.history.retrievePage( title, endpoint, true ).done( function(
page ) {
- var preview = new PagePreviewOverlay( { page: new Page(
page ), img: $( '<div>' ).append( $a.find( '.listThumb' ).clone() ).html() } );
- loader.hide();
- preview.show();
- } ).fail( function() {
- loader.hide(); // FIXME: do something more meaningful
e.g. error overlay
+ M.history.retrievePage( title, endpoint, true ).done(
function( page ) {
+ var preview = new PagePreviewOverlay( { page:
new Page( page ), img: $( '<div>' ).append( $a.find( '.listThumb' ).clone()
).html() } );
+ loader.hide();
+ preview.show();
+ } ).fail( function() {
+ loader.hide(); // FIXME: do something more
meaningful e.g. error overlay
+ } );
} );
} );
--
To view, visit https://gerrit.wikimedia.org/r/64999
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I434a81af904a9db896abc6eb635ee7be86a6d502
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits