MediaWiki:Common.js: Difference between revisions

From BalisongWiki
Jump to navigation Jump to search
No edit summary
Tag: Reverted
test new code
Tag: Reverted
Line 24: Line 24:


// Toolbar customization code
// Toolbar customization code
// Check if we're editing a page.
$(function() {
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
    // Example: remove "What links here"
// Add a hook handler.
    $('#t-whatlinkshere').remove();
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
 
// Configure a new toolbar entry on the given $textarea jQuery object.
    // Example: add a custom tool
$textarea.wikiEditor( 'addToToolbar', {
    mw.util.addPortletLink(
section: 'advanced',
        'p-tb',                             // Target portlet ID: p-tb = Tools
group: 'format',
        '/wiki/Special:Random',             // Link target
tools: {
        'Random Page',                     // Link text
hline: {
        't-randompage',                     // Link ID
label: 'Horizontal line',
        'Go to a random article',           // Tooltip
type: 'button',
        null,                              // Access key
icon: 'https://upload.wikimedia.org/wikipedia/commons/a/a4/H-line_icon.png',
        '#t-upload'                         // Insert before this element
action: {
    );
type: 'encapsulate',
});
options: {
pre: '----',
ownline: true
}
}
}
}
} );
} );
}

Revision as of 04:26, 5 July 2025

/* Any JavaScript here will be loaded for all users on every page load. */

/**
 * Auto-number headings
 *
 * @source https://www.mediawiki.org/wiki/Snippets/Auto-number_headings
 * @author Krinkle
 * @version 2024-07-28
 */
var toc = document.querySelector('#toc');
if (toc) {
  document.body.classList.add('tpl-autonum-attr');
  // Support legacy Parser: <h2><span class=mw-headline id=…>
  // Support Parsoid: <section><div class=mw-heading><h2 id…>
  document.querySelectorAll('.mw-parser-output :is(h1,h2,h3,h4,h5,h6) .mw-headline[id], .mw-parser-output .mw-heading [id]:is(h1,h2,h3,h4,h5,h6)').forEach(function (headline) {
    var num = toc.querySelector('a[href="#' + CSS.escape(headline.id) + '"] .tocnumber');
    if (num) headline.setAttribute('data-autonum', num.textContent);
  });
} else {
  document.body.classList.add('tpl-autonum');
}



// Toolbar customization code
$(function() {
    // Example: remove "What links here"
    $('#t-whatlinkshere').remove();

    // Example: add a custom tool
    mw.util.addPortletLink(
        'p-tb',                              // Target portlet ID: p-tb = Tools
        '/wiki/Special:Random',             // Link target
        'Random Page',                      // Link text
        't-randompage',                     // Link ID
        'Go to a random article',           // Tooltip
        null,                               // Access key
        '#t-upload'                         // Insert before this element
    );
});