MediaWiki:Common.js: Difference between revisions
m (presentation cleanup) |
m (selected fix) |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
/** | /** | ||
Line 83: | Line 7: | ||
* Description: Uses regular expressions and caching for better performance. | * Description: Uses regular expressions and caching for better performance. | ||
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]] | * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]] | ||
* | * | ||
var hasClass = ( function() { | var hasClass = ( function() { | ||
var reCache = {}; | var reCache = {}; | ||
Line 90: | Line 14: | ||
}; | }; | ||
})(); | })(); | ||
** */ | |||
/** | |||
* Test if an element has a certain class | |||
* @deprecated: Use $(element).hasClass() instead. | |||
*/ | |||
mw.log.deprecate( window, 'hasClass', function ( element, className ) { | |||
return $( element ).hasClass( className ); | |||
}, 'Use jQuery.hasClass() instead' ); | |||
/* Template:Infobox/image */ | |||
window.addOnloadHook(function() { | |||
$('.infobox-image .infobox-gallery > *:first-child img').addClass('selected'); | |||
$('.infobox-preview:first-child').show(); | |||
$('.infobox-image .infobox-gallery > *').click(function() { | |||
var index = $(this).index(); | |||
var previews = $(this).closest('.infobox-image').find('.infobox-preview'); | |||
if (index < previews.length) { | |||
$(this).parent().find('img').removeClass('selected'); | |||
$(this).addClass('selected'); | |||
previews.hide(); | |||
$(previews[index]).show(); | |||
} | |||
}); | |||
}); |
Latest revision as of 10:23, 6 January 2024
/* Any JavaScript here will be loaded for all users on every page load. */
/**
* Test if an element has a certain class
*
* Description: Uses regular expressions and caching for better performance.
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
*
var hasClass = ( function() {
var reCache = {};
return function( element, className ) {
return ( reCache[className] ? reCache[className] : ( reCache[className] = new RegExp( "(?:\\s|^)" + className + "(?:\\s|$)" ) ) ).test( element.className );
};
})();
** */
/**
* Test if an element has a certain class
* @deprecated: Use $(element).hasClass() instead.
*/
mw.log.deprecate( window, 'hasClass', function ( element, className ) {
return $( element ).hasClass( className );
}, 'Use jQuery.hasClass() instead' );
/* Template:Infobox/image */
window.addOnloadHook(function() {
$('.infobox-image .infobox-gallery > *:first-child img').addClass('selected');
$('.infobox-preview:first-child').show();
$('.infobox-image .infobox-gallery > *').click(function() {
var index = $(this).index();
var previews = $(this).closest('.infobox-image').find('.infobox-preview');
if (index < previews.length) {
$(this).parent().find('img').removeClass('selected');
$(this).addClass('selected');
previews.hide();
$(previews[index]).show();
}
});
});