mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-24 08:13:38 +00:00
Fix issues with file page link
TIL about setup/teardown in qunit Change-Id: Ib283285bea401be251ec3f46a2dbd01623fe895e Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/452
This commit is contained in:
parent
9a8e67040a
commit
68bb702eaa
|
@ -133,6 +133,7 @@
|
|||
var $thumbCaption,
|
||||
caption,
|
||||
bs = this,
|
||||
alwaysOpen = false,
|
||||
$thumb = $( thumb ),
|
||||
$link = $thumb.closest( 'a.image' ),
|
||||
$thumbContain = $link.closest( '.thumb' ),
|
||||
|
@ -175,6 +176,9 @@
|
|||
.text( mw.message( 'multimediaviewer-view-expanded' ).text() )
|
||||
)
|
||||
.appendTo( $( '.fullMedia' ) );
|
||||
|
||||
// Ignore the preference, open anyway
|
||||
alwaysOpen = true;
|
||||
}
|
||||
|
||||
// This is the data that will be passed onto the mmv
|
||||
|
@ -193,7 +197,7 @@
|
|||
}
|
||||
|
||||
$link.add( $enlarge ).click( function ( e ) {
|
||||
return bs.click( this, e, title );
|
||||
return bs.click( this, e, title, alwaysOpen );
|
||||
} );
|
||||
// now that we have set up our real click handler we can we can remove the temporary
|
||||
// handler added in mmv.head.js which just replays clicks to the real handler
|
||||
|
@ -207,9 +211,11 @@
|
|||
* @param {Object} element Clicked element
|
||||
* @param {jQuery.Event} e jQuery event object
|
||||
* @param {string} title File title
|
||||
* @param {boolean} overridePreference Whether to ignore global preferences and open
|
||||
* the lightbox on this click event.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
MMVB.click = function ( element, e, title ) {
|
||||
MMVB.click = function ( element, e, title, overridePreference ) {
|
||||
var $element = $( element );
|
||||
|
||||
// Do not interfere with non-left clicks or if modifier keys are pressed.
|
||||
|
@ -218,7 +224,7 @@
|
|||
}
|
||||
|
||||
// Don't load if someone has specifically stopped us from doing so
|
||||
if ( mw.config.get( 'wgMediaViewerOnClick' ) !== true ) {
|
||||
if ( mw.config.get( 'wgMediaViewerOnClick' ) !== true && overridePreference !== true ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
( function ( mw, $ ) {
|
||||
QUnit.module( 'mmv.bootstrap', QUnit.newMwEnvironment() );
|
||||
var backup = {};
|
||||
|
||||
QUnit.module( 'mmv.bootstrap', QUnit.newMwEnvironment( {
|
||||
setup: function () {
|
||||
backup.onclick = mw.config.get( 'wgMediaViewerOnClick' );
|
||||
mw.config.set( 'wgMediaViewerOnClick', true );
|
||||
},
|
||||
|
||||
teardown: function () {
|
||||
mw.config.set( 'wgMediaViewerOnClick', backup.onclick );
|
||||
} } ) );
|
||||
|
||||
function createGallery( imageSrc ) {
|
||||
var div = $( '<div>' ).addClass( 'gallery' ).appendTo( '#qunit-fixture' ),
|
||||
|
@ -82,7 +92,7 @@
|
|||
} );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Check viewer invoked when clicking on legit image links', 7, function ( assert ) {
|
||||
QUnit.test( 'Check viewer invoked when clicking on legit image links', 9, function ( assert ) {
|
||||
// TODO: Is <div class="gallery"><span class="image"><img/></span></div> valid ???
|
||||
var div, link, link2, link3, link4, bootstrap,
|
||||
viewer = { initWithThumbs : $.noop };
|
||||
|
@ -132,6 +142,11 @@
|
|||
// Click on legit link
|
||||
link4.trigger( { type: 'click', which: 1 } );
|
||||
|
||||
// Click on legit link even when preference says not to
|
||||
mw.config.set( 'wgMediaViewerOnClick', false );
|
||||
link4.trigger( { type: 'click', which: 1 } );
|
||||
mw.config.set( 'wgMediaViewerOnClick', true );
|
||||
|
||||
bootstrap.setupOverlay = function () {
|
||||
assert.ok( false, 'Overlay was not set up' );
|
||||
};
|
||||
|
@ -142,6 +157,11 @@
|
|||
|
||||
// Click on non-legit link
|
||||
link3.trigger( { type : 'click', which : 1 } );
|
||||
|
||||
// Click on legit links with preference off
|
||||
mw.config.set( 'wgMediaViewerOnClick', false );
|
||||
link.trigger( { type : 'click', which : 1 } );
|
||||
link2.trigger( { type : 'click', which : 1 } );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Skip images with invalid extensions', 0, function ( assert ) {
|
||||
|
|
Loading…
Reference in a new issue