Merge "Make MediaViewer ignore images which are in 'noviewer' class"

This commit is contained in:
jenkins-bot 2014-06-13 23:34:23 +00:00 committed by Gerrit Code Review
commit a4e2dc6962
2 changed files with 39 additions and 8 deletions

View file

@ -159,6 +159,20 @@
}
};
/**
* Check if this thumbnail should be handled by MediaViewer
* @param {jQuery} $thumb the thumbnail (an `<img>` element) in question
* @return {boolean}
*/
MMVB.isAllowedThumb = function ( $thumb ) {
// .metadata means this is inside an informational template like {{refimprove}} on enwiki.
// .noviewer means MediaViewer has been specifically disabled for this image
// .noarticletext means we are on an error page for a non-existing article, the image is part of some
// template // FIXME this should be handled by .metadata
return $thumb.closest( '.metadata, .noviewer, .noarticletext' ).length === 0;
};
/**
* Processes a thumb
* @param {Object} thumb
@ -179,14 +193,7 @@
return;
}
if (
// This is almost certainly an icon for an informational template like
// {{refimprove}} on enwiki.
$thumb.closest( '.metadata' ).length > 0 ||
// This is an article with no text.
$thumb.closest( '.noarticletext' ).length > 0
) {
if ( !bs.isAllowedThumb( $thumb ) ) {
return;
}

View file

@ -403,4 +403,28 @@
assert.ok( mw.loader.load.called, 'Dependencies should be preloaded if the thumb is hovered long enough' );
} );
QUnit.test( 'isAllowedThumb', 5, function ( assert ) {
var $container = $( '<div>' ),
$thumb = $( '<img>' ).appendTo( $container ),
bootstrap = createBootstrap();
assert.ok( bootstrap.isAllowedThumb( $thumb ), 'Normal image in a div is allowed.' );
$container.addClass( 'metadata' );
assert.strictEqual( bootstrap.isAllowedThumb( $thumb ), false, 'Image in a metadata container is disallowed.' );
$container.prop( 'class', '' );
$container.addClass( 'noviewer' );
assert.strictEqual( bootstrap.isAllowedThumb( $thumb ), false, 'Image in a noviewer container is disallowed.' );
$container.prop( 'class', '' );
$container.addClass( 'noarticletext' );
assert.strictEqual( bootstrap.isAllowedThumb( $thumb ), false, 'Image in an empty article is disallowed.' );
$container.prop( 'class', '' );
$thumb.addClass( 'noviewer' );
assert.strictEqual( bootstrap.isAllowedThumb( $thumb ), false, 'Image with a noviewer class is disallowed.' );
} );
}( mediaWiki, jQuery ) );