MediaWiki:Common.js: Difference between revisions

From Azyrah
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
 
(5 intermediate revisions by the same user 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. */
// Tabber functionality
$(document).ready(function() {
    // Function to handle tab click
    $('.button').click(function() {
        // Get the tab position
        var position = $(this).data('position');
       
        // Remove active class from other buttons and add to the clicked one
        $('.button').removeClass('tabber-active');
        $(this).addClass('tabber-active');
       
        // Hide all tab contents and show the relevant one
        $('.tabber-container > :last-child > div').hide();
        $('.tabber-container > :last-child > div').eq(position).show();
    });
});
function ModifySidebar( action, section, name, link ) {
function ModifySidebar( action, section, name, link ) {
try {
try {
Line 69: Line 86:


jQuery( CustomizeModificationsOfSidebar );
jQuery( CustomizeModificationsOfSidebar );
var hasClass = ( function() {
        var reCache = {};
        return function( element, className ) {
                return ( reCache[className] ? reCache[className] : ( reCache[className] = new RegExp( "(?:\\s|^)" + className + "(?:\\s|$)" ) ) ).test( element.className );
        };
})();

Latest revision as of 22:39, 23 September 2023

/* Any JavaScript here will be loaded for all users on every page load. */
// Tabber functionality
$(document).ready(function() {
    // Function to handle tab click
    $('.button').click(function() {
        // Get the tab position
        var position = $(this).data('position');
        
        // Remove active class from other buttons and add to the clicked one
        $('.button').removeClass('tabber-active');
        $(this).addClass('tabber-active');
        
        // Hide all tab contents and show the relevant one
        $('.tabber-container > :last-child > div').hide();
        $('.tabber-container > :last-child > div').eq(position).show();
    });
});

function ModifySidebar( action, section, name, link ) {
	try {
		switch ( section ) {
			case 'languages':
				var target = 'p-lang';
				break;
			case 'toolbox':
				var target = 'p-tb';
				break;
			case 'navigation':
				var target = 'p-navigation';
				break;
			default:
				var target = 'p-' + section;
				break;
		}

		if ( action == 'add' ) {
			var node = document.getElementById( target )
							   .getElementsByTagName( 'div' )[0]
							   .getElementsByTagName( 'ul' )[0];

			var aNode = document.createElement( 'a' );
			var liNode = document.createElement( 'li' );

			aNode.appendChild( document.createTextNode( name ) );
			aNode.setAttribute( 'href', link );
			liNode.appendChild( aNode );
			liNode.className = 'plainlinks';
			node.appendChild( liNode );
		}

		if ( action == 'remove' ) {
			var list = document.getElementById( target )
							   .getElementsByTagName( 'div' )[0]
							   .getElementsByTagName( 'ul' )[0];

			var listelements = list.getElementsByTagName( 'li' );

			for ( var i = 0; i < listelements.length; i++ ) {
				if (
					listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name ||
					listelements[i].getElementsByTagName( 'a' )[0].href == link
				)
				{
					list.removeChild( listelements[i] );
				}
			}
		}


	} catch( e ) {
		// let's just ignore what's happened
		return;
	}
}

function CustomizeModificationsOfSidebar() {
	// adds [[Special:CategoryTree|Special:CategoryTree]] to toolbox
	// removes [[Special:Upload|Special:Upload]] from toolbox
	ModifySidebar( 'remove', 'toolbox', 'Page information', 'https://en.wikipedia.org/wiki/Special:Page_Information' );
    ModifySidebar( 'remove', 'toolbox', 'What links here', 'https://en.wikipedia.org/wiki/Special:What_links_here' );
    ModifySidebar( 'remove', 'toolbox', 'Related changes', 'https://en.wikipedia.org/wiki/Special:Related_changes' );
    ModifySidebar( 'remove', 'toolbox', 'Special pages', 'https://en.wikipedia.org/wiki/Special:Special_pages' );
    ModifySidebar( 'remove', 'toolbox', 'Printable version', 'https://en.wikipedia.org/wiki/Special:Printable_version' );
    ModifySidebar( 'remove', 'toolbox', 'Permanent link', 'https://en.wikipedia.org/wiki/Special:Permanent_link' );
}

jQuery( CustomizeModificationsOfSidebar );