MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
imported>Kittymmeow No edit summary |
imported>Kittymmeow No edit summary |
||
Line 1: | Line 1: | ||
/* | /* improved gadgets-definition page */ | ||
$(function() { | |||
if (mw.config.get('wgPageName') != 'MediaWiki:Gadgets-definition') return; | |||
var urlPrefix = mw.config.get('wgServer') + '/MediaWiki:Gadget-'; | |||
function replaceWithLink(str) { | |||
var link = document.createElement('a'); | |||
$(link).attr('href', urlPrefix + str); | |||
(function() { | $(link).html(str); | ||
return link.outerHTML; | |||
} | |||
$('#mw-content-text li').each(function() { | |||
var html = $(this).html(); | |||
var htmlParts = html.split('|'); | |||
for (i in htmlParts) { | |||
if (htmlParts[i].endsWith('css') || htmlParts[i].endsWith('js')) { | |||
htmlParts[i] = replaceWithLink(htmlParts[i]); | |||
} | |||
} | |||
var text = htmlParts.join('|'); | |||
var firstPart = text.match(/^([^\|\[]*)/)[0]; | |||
if (firstPart) text = text.replace(firstPart, replaceWithLink(firstPart)); | |||
$(this).html(text); | |||
}); | }); | ||
$('#mw-content-text h2 .mw-headline').each(function() { | |||
$(this).html(replaceWithLink('section-' + $(this).html())); | |||
}); | }); | ||
}); | |||
} | |||
/** | /** |
Revision as of 07:19, 14 August 2019
/* improved gadgets-definition page */
$(function() {
if (mw.config.get('wgPageName') != 'MediaWiki:Gadgets-definition') return;
var urlPrefix = mw.config.get('wgServer') + '/MediaWiki:Gadget-';
function replaceWithLink(str) {
var link = document.createElement('a');
$(link).attr('href', urlPrefix + str);
$(link).html(str);
return link.outerHTML;
}
$('#mw-content-text li').each(function() {
var html = $(this).html();
var htmlParts = html.split('|');
for (i in htmlParts) {
if (htmlParts[i].endsWith('css') || htmlParts[i].endsWith('js')) {
htmlParts[i] = replaceWithLink(htmlParts[i]);
}
}
var text = htmlParts.join('|');
var firstPart = text.match(/^([^\|\[]*)/)[0];
if (firstPart) text = text.replace(firstPart, replaceWithLink(firstPart));
$(this).html(text);
});
$('#mw-content-text h2 .mw-headline').each(function() {
$(this).html(replaceWithLink('section-' + $(this).html()));
});
});
/**
* Pause MCUI templates (e.g. [[Template:Crafting Table]]) on mouseover
*
* This is so people have a chance to look at each image on the cell
* and click on pages they want to view.
*/
$( '#mw-content-text' ).on( 'mouseenter mouseleave', '.mcui', function( e ) {
$( this ).find( '.animated' ).toggleClass( 'animated-paused', e.type === 'mouseenter' );
} );