Chore: move window.location use to client

Move window.location manipulation from ImageOverlay view to MinervaNeue.
Also, don't leave a hanging empty URL fragment when closing the overlay.

Bug: T173539
Related: I292c0578716ff56e0e069aa8006f840025d78a88
Change-Id: I56ba9217aa9cd4e0a925c623060022392e3021c7
This commit is contained in:
Stephen Niedzielski 2018-03-05 14:42:00 -06:00
parent 973b40c5ad
commit 27bc7e7212
1 changed files with 29 additions and 6 deletions

View File

@ -19,7 +19,15 @@
*/
function onClickImage( ev ) {
ev.preventDefault();
router.navigate( '#/media/' + encodeURIComponent( $( this ).data( 'thumb' ).getFileName() ) );
routeThumbnail( $( this ).data( 'thumb' ) );
}
/**
* @param {jQuery.Element} thumbnail
* @ignore
*/
function routeThumbnail( thumbnail ) {
router.navigate( '#/media/' + encodeURIComponent( thumbnail.getFileName() ) );
}
/**
@ -98,12 +106,27 @@
return $.Deferred().reject();
} else {
return loader.loadModule( 'mobile.mediaViewer' ).then( function () {
var ImageOverlay = M.require( 'mobile.mediaViewer/ImageOverlay' );
return new ImageOverlay( {
api: new mw.Api(),
thumbnails: thumbs,
title: decodeURIComponent( title )
var ImageOverlay = M.require( 'mobile.mediaViewer/ImageOverlay' ),
imageOverlay = new ImageOverlay( {
api: new mw.Api(),
thumbnails: thumbs,
title: decodeURIComponent( title )
} );
imageOverlay.on( ImageOverlay.EVENT_EXIT, function ( ev ) {
// Prevent going back in browser's history.
// See T94188 & T94363.
ev.preventDefault();
ev.stopPropagation();
// Manually close the overlay (OverlayManager does not expose a method
// to hide the active overlay).
imageOverlay.hide();
// Update the URL by clearing fragment.
router.navigate( '' );
} );
imageOverlay.on( ImageOverlay.EVENT_SLIDE, function ( nextThumbnail ) {
routeThumbnail( nextThumbnail );
} );
return imageOverlay;
} );
}
}