Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/80684


Change subject: Nearby bug fixes
......................................................................

Nearby bug fixes

Fixes the following problems
* Remove the rendered emitted event - doesn't seem to work
* Instead pull in code dependant on mode to reenable watch star in alpha
and previews in beta and alpha (bug 53125)
* restructure the PagePreviewOverlay
* Stop usage of nearby module in prep for FIXME
* rename Nearby to SpecialNearby to avoid confusion with generic Nearby module
* Fix middle click on desktop (bug 53188)

Change-Id: I5caf740f628d58d7c8c9d854fd2f95e24b453225
---
M includes/Resources.php
M includes/specials/SpecialNearby.php
D javascripts/specials/nearby-watchstar.js
M javascripts/specials/nearby.js
R javascripts/specials/overlays/PagePreviewOverlay.js
5 files changed, 54 insertions(+), 67 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/84/80684/1

diff --git a/includes/Resources.php b/includes/Resources.php
index 485c633..6ec5e3e 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -574,17 +574,7 @@
                        'mobile-frontend-nearby-link',
                ),
                'scripts' => array(
-                       'javascripts/specials/overlays/preview.js',
-               ),
-       ),
-
-       'mobile.nearby.watchstar' => $wgMFMobileResourceBoilerplate + array(
-               'dependencies' => array(
-                       'mobile.nearby.scripts',
-                       'mobile.stable',
-               ),
-               'scripts' => array(
-                       'javascripts/specials/nearby-watchstar.js',
+                       'javascripts/specials/overlays/PagePreviewOverlay.js',
                ),
        ),
 
diff --git a/includes/specials/SpecialNearby.php 
b/includes/specials/SpecialNearby.php
index ac32c7f..39159da 100644
--- a/includes/specials/SpecialNearby.php
+++ b/includes/specials/SpecialNearby.php
@@ -20,9 +20,6 @@
                $ctx = MobileContext::singleton();
                if ( $ctx->shouldDisplayMobileView() && 
$ctx->isBetaGroupMember() ) {
                        $output->addModules( 'mobile.nearby.previews' );
-                       if ( $ctx->isAlphaGroupMember() ) {
-                               $output->addModules( 'mobile.nearby.watchstar' 
);
-                       }
                } else {
                        // Only the Minerva skin loads this module so make sure 
we load it for desktop
                        $output->addModuleStyles( 'mobile.pagelist.styles' );
diff --git a/javascripts/specials/nearby-watchstar.js 
b/javascripts/specials/nearby-watchstar.js
deleted file mode 100644
index c559a72..0000000
--- a/javascripts/specials/nearby-watchstar.js
+++ /dev/null
@@ -1,9 +0,0 @@
-( function( M ) {
-var nearby = M.require( 'nearby' ),
-       watchstar = M.require( 'watchstar' );
-
-nearby.getOverlay().on( 'rendered', function( $el ) {
-       watchstar.initWatchListIconList( $el.find( 'ul' ) );
-} );
-
-}( mw.mobileFrontend ) );
diff --git a/javascripts/specials/nearby.js b/javascripts/specials/nearby.js
index 83e9a1b..0808536 100644
--- a/javascripts/specials/nearby.js
+++ b/javascripts/specials/nearby.js
@@ -3,13 +3,10 @@
 var CACHE_KEY_RESULTS = 'mfNearbyLastSearchResult',
        endpoint = mw.config.get( 'wgMFNearbyEndpoint' ),
        overlay,
+       wgMFMode = mw.config.get( 'wgMFMode' ),
        NearbyApi = M.require( 'modules/nearby/NearbyApi' ),
        api = new NearbyApi(),
        CACHE_KEY_LAST_LOCATION = 'mfNearbyLastKnownLocation';
-
-function getOverlay() {
-       return overlay;
-}
 
 $( function() {
        var supported = M.supportsGeoLocation(),
@@ -38,7 +35,8 @@
                lastKnownLocation = M.settings.getUserSetting( 
CACHE_KEY_LAST_LOCATION ),
                cache = M.settings.saveUserSetting,
                lastSearchResult = M.settings.getUserSetting( CACHE_KEY_RESULTS 
),
-               Nearby = View.extend( {
+               // FIXME: Adapt modules/nearby/Nearby.js and use that instead
+               SpecialNearby = View.extend( {
                        template: M.template.get( 'articleList' ),
                        /**
                         * Renders an error in the existing view
@@ -48,25 +46,41 @@
                        renderError: function( type ) {
                                this.render( { error: errorMessages[ type ] } );
                        },
-                       openPage: function( ev ) {
-                               // help back button work
-                               window.location.hash = '#' + $( 
ev.currentTarget ).attr( 'name' );
-                               window.location = $( ev.currentTarget ).attr( 
'href' );
-                       },
                        postRender: function() {
                                var self = this;
-                               // use mouseup to allow right click
-                               this.$( 'a' ).on( 'mouseup', function( ev ) {
+                               this.$( 'a' ).on( 'click', function( ev ) {
+                                       var $a = $( ev.currentTarget );
                                        // name funnel for watchlists to catch 
subsequent uploads
                                        $.cookie( 'mwUploadsFunnel', 'nearby', 
{ expires: new Date( new Date().getTime() + 60000) } );
-                                       self.openPage( ev );
+                                       if ( wgMFMode === 'stable' ) {
+                                               window.location.hash = '#' + $( 
ev.currentTarget ).attr( 'name' );
+                                       } else {
+                                               ev.preventDefault();
+
+                                               // Trigger preview mode
+                                               mw.loader.using( 
'mobile.nearby.previews', function() {
+                                                               var 
PagePreviewOverlay = M.require( 'PagePreviewOverlay' );
+                                                               new 
PagePreviewOverlay( {
+                                                                       
endpoint: endpoint,
+                                                                       
latLngString: $a.data( 'latlng' ),
+                                                                       img: $( 
'<div>' ).append( $a.find( '.listThumb' ).clone() ).html(),
+                                                                       title: 
$a.find( 'h2' ).text()
+                                                               } );
+                                               } );
+                                       }
                                } );
-                               self.emit( 'rendered', this.$el );
+
+                               // Load watch stars in alpha
+                               if ( wgMFMode === 'alpha' ) {
+                                       mw.loader.using( 'mobile.stable', 
function() {
+                                               M.require( 'watchstar' 
).initWatchListIconList( self.$( 'ul' ) );
+                                       } );
+                               }
                        }
                } ),
                pendingQuery = false, btn;
 
-               overlay = new Nearby( {
+               overlay = new SpecialNearby( {
                        el: $( '#mw-mf-nearby' )
                } );
 
@@ -150,11 +164,5 @@
        // FIXME: i18n
        btn = $( '<button class="refresh">' ).on( 'click', refresh ).appendTo( 
'.header' );
 } );
-
-M.define( 'nearby', {
-       endpoint: endpoint,
-       getOverlay: getOverlay
-} );
-
 
 }( mw.mobileFrontend, jQuery ) );
diff --git a/javascripts/specials/overlays/preview.js 
b/javascripts/specials/overlays/PagePreviewOverlay.js
similarity index 74%
rename from javascripts/specials/overlays/preview.js
rename to javascripts/specials/overlays/PagePreviewOverlay.js
index e3923a3..d34a6d5 100644
--- a/javascripts/specials/overlays/preview.js
+++ b/javascripts/specials/overlays/PagePreviewOverlay.js
@@ -5,14 +5,33 @@
                device = 'unknown',
                Page = M.require( 'page' ),
                LoadingOverlay = Overlay.extend( {
+                       // FIXME: workaround for bug 53282
+                       appendTo: document.body,
                        defaults: {
                                msg: mw.msg( 
'mobile-frontend-ajax-preview-loading' )
                        },
                        template: M.template.get( 'overlays/loading' )
                } ),
                PagePreviewOverlay = Overlay.extend( {
+                       // FIXME: workaround for bug 53282
+                       appendTo: document.body,
                        template: M.template.get( 'overlays/pagePreview' ),
+                       initialize: function( options ) {
+                               this._super( options );
+                               var self = this, loader = new LoadingOverlay();
+                               loader.show();
+                               M.history.retrievePage( options.title, 
options.endpoint, true ).done( function( page ) {
+                                       options.page = new Page( page );
+                                       loader.hide();
+                                       self.render( options ).show();
+                               } ).fail( function() {
+                                       loader.hide(); // FIXME: do something 
more meaningful e.g. error overlay
+                               } );
+                       },
                        preRender: function( options ) {
+                               if ( !options.page ) {
+                                       return;
+                               }
                                var directionUrl;
                                options.heading = options.page.title;
                                options.preview = options.page.lead;
@@ -37,6 +56,9 @@
                                }
                        },
                        postRender: function( options ) {
+                               if ( !options.page ) {
+                                       return;
+                               }
                                var $preview, nodes;
                                this._super( options );
                                $preview = this.$( '.preview' );
@@ -53,9 +75,7 @@
                                // Display the first content node
                                $preview.append( nodes[0] );
                        }
-               } ),
-               module = M.require( 'nearby' ),
-               endpoint = module.endpoint;
+               } );
 
        if ( ua.match( /OS [0-9]+_[0-9]+ like Mac OS X/ ) ) {
                device = 'iphone';
@@ -65,24 +85,5 @@
                device = 'wp';
        }
 
-       $( function() {
-               // FIXME: temporary code, replace if previews get to stable or 
are removed
-               module.getOverlay().openPage = 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 ),
-                                       latLngString: $a.data( 'latlng' ),
-                                       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.define( 'PagePreviewOverlay', PagePreviewOverlay );
 }( mw.mobileFrontend, jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5caf740f628d58d7c8c9d854fd2f95e24b453225
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

Reply via email to