Jdlrobson has uploaded a new change for review.

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


Change subject: Regression: Remove OverlayManager, Fix photo uploads
......................................................................

Regression: Remove OverlayManager, Fix photo uploads

a better way to do this is for Overlay's when created to specify a
parent. If a parent is specified closing the overlay will show the
parent overlay. If an overlay has no parent when hiding it will switch
from overlay mode to article mode.

This seems neater. Fix call to non-existant close to trigger hide.

Change-Id: Ie8dfe4d833c96b16eee05a84fcf6787782f18504
---
M javascripts/common/mf-navigation.js
M javascripts/modules/mf-photo.js
M tests/js/common/mf-navigation.js
3 files changed, 26 insertions(+), 57 deletions(-)


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

diff --git a/javascripts/common/mf-navigation.js 
b/javascripts/common/mf-navigation.js
index e32ca47..f343191 100644
--- a/javascripts/common/mf-navigation.js
+++ b/javascripts/common/mf-navigation.js
@@ -5,7 +5,6 @@
                u = M.utils, mfePrefix = M.prefix,
                inBeta = mw.config.get( 'wgMFMode' ) === 'beta',
                Overlay,
-               OverlayManager,
                Drawer, CtaDrawer;
 
        Drawer = View.extend( {
@@ -57,70 +56,45 @@
                template: M.template.get( 'ctaDrawer' )
        } );
 
-       OverlayManager = function() {};
-
-       OverlayManager.prototype = {
-               stack: [],
-               getTopOverlay: function() {
-                       return this.stack[ this.stack.length - 1 ];
-               },
-               pop: function() {
-                       var overlay = this.stack.pop(); // assume the overlay 
being escaped is the topmost one
-                       // Make sure all open overlays are closed before 
returning to article
-                       if ( this.stack.length === 0 ) {
-                               $( 'html' ).removeClass( 'overlay' );
-                               // return to last known scroll position
-                               window.scrollTo( document.body.scrollLeft, 
overlay.scrollTop );
-                               return true;
-                       } else {
-                               this.getTopOverlay().show();
-                               return false;
-                       }
-               },
-               push: function( overlay ) {
-                       // hide the current open overlay
-                       var top = this.getTopOverlay();
-                       if ( top ) {
-                               top.hide();
-                       }
-
-                       this.stack.push( overlay );
-                       $( 'html' ).addClass( 'overlay' ).
-                               removeClass( 'navigationEnabled' );
-
-                       // skip the URL bar if possible
-                       window.scrollTo( 0, 1 );
-               }
-       };
-
        Overlay = View.extend( {
                defaults: {
                        heading: '',
                        content: '',
                        closeMsg: mw.msg( 'mobile-frontend-overlay-escape' )
                },
+               parent: null,
                template: M.template.get( 'overlay' ),
                className: 'mw-mf-overlay',
-               initialize: function() {
+               initialize: function( options ) {
                        var self = this;
+                       this.parent = options.parent;
                        this.isOpened = false;
                        this.$( '.cancel' ).click( function( ev ) {
                                ev.preventDefault();
                                self.hide();
-                               self.isOpened = false;
-                               M.emit( 'overlay-closed' );
                        } );
                },
                show: function() {
+                       if ( this.parent ) {
+                               this.parent.hide();
+                       }
                        this.$el.appendTo( 'body' );
                        this.scrollTop = document.body.scrollTop;
-                       if ( !this.isOpened ) {
-                               this.isOpened = true;
-                               M.emit( 'overlay-opened', this );
-                       }
+                       $( 'html' ).addClass( 'overlay' ).
+                               removeClass( 'navigationEnabled' );
+
+                       // skip the URL bar if possible
+                       window.scrollTo( 0, 1 );
                },
                hide: function() {
                        this.$el.detach();
+                       if ( !this.parent ) {
+                               $( 'html' ).removeClass( 'overlay' );
+                               // return to last known scroll position
+                               window.scrollTo( document.body.scrollLeft, 
this.scrollTop );
+                       } else {
+                               this.parent.show();
+                       }
                }
        } );
 
@@ -141,7 +115,7 @@
        }
 
        function init() {
-               var manager,
+               var
                        search = document.getElementById(  mfePrefix + 'search' 
);
 
                $( '#mw-mf-menu-main a' ).click( function() {
@@ -199,15 +173,6 @@
                        if ( !inBeta || $( window ).width() < 700 ) {
                                u( document.documentElement ).removeClass( 
'navigationEnabled' );
                        }
-               } );
-
-               // events
-               manager = new OverlayManager();
-               M.on( 'overlay-opened', function( overlay ) {
-                       manager.push( overlay );
-               } );
-               M.on( 'overlay-closed', function() {
-                       manager.pop();
                } );
        }
 
diff --git a/javascripts/modules/mf-photo.js b/javascripts/modules/mf-photo.js
index 3760327..3941bfd 100644
--- a/javascripts/modules/mf-photo.js
+++ b/javascripts/modules/mf-photo.js
@@ -296,11 +296,14 @@
                },
 
                setImageUrl: function( url ) {
+                       var self = this;
                        this.imageUrl = url;
                        this.overlay.$( '.loading' ).remove();
                        this.overlay.$( 'a.help' ).on( 'click', function( ev ) {
                                ev.preventDefault(); // avoid setting #
-                               var overlay = new CopyrightOverlay();
+                               var overlay = new CopyrightOverlay( {
+                                       parent: self.overlay
+                               } );
                                overlay.show();
                        } );
                        $( '<img>' ).attr( 'src', url ).prependTo( 
this.overlay.$( '.photoPreview' ) );
@@ -461,7 +464,7 @@
                                progressPopup = new PhotoUploadProgress();
 
                        this.emit( 'start' );
-                       this.preview.overlay.close();
+                       this.preview.overlay.hide();
                        popup.show( progressPopup.$el, 'locked noButton 
loading' );
                        progressPopup.on( 'cancel', function() {
                                api.abort();
diff --git a/tests/js/common/mf-navigation.js b/tests/js/common/mf-navigation.js
index 4fe2fc4..378c5f6 100644
--- a/tests/js/common/mf-navigation.js
+++ b/tests/js/common/mf-navigation.js
@@ -26,7 +26,8 @@
 
 test( 'Stacked overlays', function() {
        var overlay = new nav.Overlay( { heading: 'Overlay 1', content: 'Text' 
} ),
-               overlayTwo = new nav.Overlay( { heading: 'Overlay 2', content: 
'Text <button class="cancel">cancel</button>' } );
+               overlayTwo = new nav.Overlay( { heading: 'Overlay 2', content: 
'Text <button class="cancel">cancel</button>',
+                       parent: overlay } );
        overlay.show();
        overlayTwo.show();
        strictEqual( $( 'html' ).hasClass( 'overlay' ), true, 'In overlay mode' 
);

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

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