MediaWiki:Timeless.js: Revizyonlar arasındaki fark

Fen Ansiklopedisi sitesinden
Değişiklik özeti yok
Değişiklik özeti yok
1. satır: 1. satır:
/**
* Adds show/hide-button to navigation bars.
*
* @param {jQuery} $content
*/
function createNavigationBarToggleButton( $content ) {
var i, j, navChild, navToggle, navToggleText, isCollapsed,
indexNavigationBar = 0;
// Iterate over all < div >-elements
var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' );
$divs.each( function ( i, navFrame ) {
indexNavigationBar++;
navToggle = document.createElement( 'a' );
navToggle.className = 'NavToggle';
navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
navToggle.setAttribute( 'href', '#' );
$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );


isCollapsed = $( navFrame ).hasClass( 'collapsed' );
/**
* Check if any children are already hidden.  This loop is here for backwards compatibility:
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
* to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "collapsed" to the NavFrame itself, just like with collapsible tables.
*/
for ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) {
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
if ( navChild.style.display === 'none' ) {
isCollapsed = true;
}
}
}
if ( isCollapsed ) {
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
navChild.style.display = 'none';
}
}
}
navToggleText = document.createTextNode( isCollapsed ? navigationBarShow : navigationBarHide );
navToggle.appendChild( navToggleText );
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for ( j = 0; j < navFrame.childNodes.length; j++ ) {
if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
navToggle.style.color = navFrame.childNodes[j].style.color;
navFrame.childNodes[j].appendChild( navToggle );
}
}
navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
} );
}
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );


function ModifySidebar( action, section, name, link ) {
function ModifySidebar( action, section, name, link ) {
59. satır: 113. satır:


function CustomizeModificationsOfSidebar() {
function CustomizeModificationsOfSidebar() {
// adds [[Special:CategoryTree|Special:CategoryTree]] to toolbox
// removes [[Special:RecentChangesLinked|Special:RecentChangesLinked]] from toolbox
ModifySidebar( 'add', 'toolbox', 'Kategori Ara', 'https://fenpedia.com/index.php/Special:CategoryTree' );
ModifySidebar( 'remove', 'toolbox', 'Related changes', 'https://rammwiki.net/wiki/Special:RecentChangesLinked' );
// removes [[Special:Upload|Special:Upload]] from toolbox
// removes [[UPLOAD|Special:Upload]] from toolbox
ModifySidebar( 'remove', 'toolbox', 'Special Pages', 'https://fenpedia.com/index.php/Special:SpecialPages' );
ModifySidebar( 'remove', 'toolbox', 'Upload file', 'https://rammwiki.net/wiki/Special:Upload' );
// removes [[SPECIALPAGES|specialpages]] from toolbox
ModifySidebar( 'remove', 'toolbox', 'Special pages', 'https://rammwiki.net/wiki/Special:SpecialPages' );
// adds [[Rules|Rules]] to toolbox
ModifySidebar( 'add', 'toolbox', 'Rules', 'https://rammwiki.net/wiki/Rules' );
// adds [[Special:ReplaceText|Replace text]] to toolbox
ModifySidebar( 'add', 'toolbox', 'Replace text', 'https://rammwiki.net/wiki/Special:ReplaceText' );
// adds [[Special:BatchUpload|Upload files]] to toolbox
ModifySidebar( 'add', 'toolbox', 'Upload files', 'https://rammwiki.net/wiki/Special:BatchUpload' );
// adds [[SPECIALPAGES|specialpages]] from toolbox
ModifySidebar( 'add', 'toolbox', 'Special pages', 'https://rammwiki.net/wiki/Special:SpecialPages' );
}
}


jQuery( CustomizeModificationsOfSidebar );
jQuery( CustomizeModificationsOfSidebar );

14.19, 29 Eylül 2021 tarihindeki hâli

/**
 * Adds show/hide-button to navigation bars.
 *
 * @param {jQuery} $content
 */
function createNavigationBarToggleButton( $content ) {
	var i, j, navChild, navToggle, navToggleText, isCollapsed,
		indexNavigationBar = 0;
	// Iterate over all < div >-elements
	var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' );
	$divs.each( function ( i, navFrame ) {
		indexNavigationBar++;
		navToggle = document.createElement( 'a' );
		navToggle.className = 'NavToggle';
		navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
		navToggle.setAttribute( 'href', '#' );
		$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );

		isCollapsed = $( navFrame ).hasClass( 'collapsed' );
		/**
		 * Check if any children are already hidden.  This loop is here for backwards compatibility:
		 * the old way of making NavFrames start out collapsed was to manually add style="display:none"
		 * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
		 * the content visible without JavaScript support), the new recommended way is to add the class
		 * "collapsed" to the NavFrame itself, just like with collapsible tables.
		 */
		for ( navChild = navFrame.firstChild; navChild !== null && !isCollapsed; navChild = navChild.nextSibling ) {
			if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
				if ( navChild.style.display === 'none' ) {
					isCollapsed = true;
				}
			}
		}
		if ( isCollapsed ) {
			for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
				if ( $( navChild ).hasClass( 'NavPic' ) || $( navChild ).hasClass( 'NavContent' ) ) {
					navChild.style.display = 'none';
				}
			}
		}
		navToggleText = document.createTextNode( isCollapsed ? navigationBarShow : navigationBarHide );
		navToggle.appendChild( navToggleText );

		// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
		for ( j = 0; j < navFrame.childNodes.length; j++ ) {
			if ( $( navFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
				navToggle.style.color = navFrame.childNodes[j].style.color;
				navFrame.childNodes[j].appendChild( navToggle );
			}
		}
		navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
	} );
}

mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );

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() {
	// removes [[Special:RecentChangesLinked|Special:RecentChangesLinked]] from toolbox
	ModifySidebar( 'remove', 'toolbox', 'Related changes', 'https://rammwiki.net/wiki/Special:RecentChangesLinked' );
	// removes [[UPLOAD|Special:Upload]] from toolbox
	ModifySidebar( 'remove', 'toolbox', 'Upload file', 'https://rammwiki.net/wiki/Special:Upload' );
	// removes [[SPECIALPAGES|specialpages]] from toolbox
	ModifySidebar( 'remove', 'toolbox', 'Special pages', 'https://rammwiki.net/wiki/Special:SpecialPages' );
	// adds [[Rules|Rules]] to toolbox
	ModifySidebar( 'add', 'toolbox', 'Rules', 'https://rammwiki.net/wiki/Rules' );	
	// adds [[Special:ReplaceText|Replace text]] to toolbox
	ModifySidebar( 'add', 'toolbox', 'Replace text', 'https://rammwiki.net/wiki/Special:ReplaceText' );
	// adds [[Special:BatchUpload|Upload files]] to toolbox
	ModifySidebar( 'add', 'toolbox', 'Upload files', 'https://rammwiki.net/wiki/Special:BatchUpload' );
	// adds [[SPECIALPAGES|specialpages]] from toolbox
	ModifySidebar( 'add', 'toolbox', 'Special pages', 'https://rammwiki.net/wiki/Special:SpecialPages' );
}

jQuery( CustomizeModificationsOfSidebar );