MediaWiki:Common.js: Difference between revisions

Find traditional instrumental music
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: /** Dynamic Navigation Bars (experimental) ************************************* * * Description: ...")
 
No edit summary
Tag: Manual revert
 
(60 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. */
document.getElementById('searchform').action = '/w/index.php';
document.getElementsByName('search')[0].id = 'searchInput';


var customizeToolbar = function() {
// TOOLBAR  ('#free_text').wikiEditor, just as they exist for ('#wpTextbox1').wikiEditor
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'sections': {
                'annotations': {
                        'type': 'toolbar', // Can also be 'booklet'
                        'label': 'Annotations'
                        // or 'labelMsg': 'section-emoticons-label' for a localized label
                }
        }
} );
//GROUP
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'annotations',
        'groups': {
                'properties': {
                        'label': 'Properties' // or use labelMsg for a localized label, see above
                }
        }
} );


/** Dynamic Navigation Bars (experimental) *************************************
//BUTTONS       
*
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
*  Description: See [[Wikipedia:NavFrame]].
        'section': 'annotations',
*  Maintainers: UNMAINTAINED
        'group': 'properties',
*/
        'tools': {
                'aka': {
// set up the words in your language
                        label: 'Also know as', // or use labelMsg for a localized label, see above
var NavigationBarHide = '[' + collapseCaption + ']';
                        type: 'button',
var NavigationBarShow = '[' + expandCaption + ']';
                        icon: 'http://tunearch.org/w/images/icons8-music-15.png',
                        action: {
// shows and hides content and picture (if available) of navigation bars
                                type: 'encapsulate',
// Parameters:
                                options: {
//    indexNavigationBar: the index of navigation bar to be toggled
                                        pre: "[[Is_also_known_as::",
function toggleNavigationBar(indexNavigationBar){
                                        post: "]]"
    var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
                                }
    var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
                        }
                }
    if (!NavFrame || !NavToggle) {
        }
         return false;
} );
    }
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
         'section': 'annotations',
    // if shown now
        'group': 'properties',
    if (NavToggle.firstChild.data == NavigationBarHide) {
        'tools': {
        for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
              'appears': {
            if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
                        label: 'Appears in', // or use labelMsg for a localized label, see above
                 NavChild.style.display = 'none';
                        type: 'button',
            }
                        icon: 'http://tunearch.org/w/images/icons8-book-15.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "[[Appears_in::",
                                        post: "]]"
                                }
                        }
                 }
         }
         }
    NavToggle.firstChild.data = NavigationBarShow;
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
    // if hidden now
         'section': 'annotations',
    } else if (NavToggle.firstChild.data == NavigationBarShow) {
        'group': 'properties',
         for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
        'tools': {
            if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) {
              'appears': {
                NavChild.style.display = 'block';
                        label: 'Composed by', // or use labelMsg for a localized label, see above
            }
                        type: 'button',
                        icon: 'http://tunearch.org/w/images/icons8-important-property-15.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "[[Was composed by::",
                                        post: "]]"
                                }
                        }
                }
         }
         }
        NavToggle.firstChild.data = NavigationBarHide;
} );
    }
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
}
         'section': 'annotations',
         'group': 'properties',
// adds show/hide-button to navigation bars
        'tools': {
function createNavigationBarToggleButton(){
              'appears': {
    var indexNavigationBar = 0;
                        label: 'Come from', // or use labelMsg for a localized label, see above
    // iterate over all < div >-elements
                        type: 'button',
    var divs = document.getElementsByTagName("div");
                        icon: 'http://tunearch.org/w/images/icons8-origin-15.png',
    for (var i = 0; NavFrame = divs[i]; i++) {
                        action: {
         // if found a navigation bar
                                type: 'encapsulate',
         if (hasClass(NavFrame, "NavFrame")) {
                                options: {
                                        pre: "[[It comes from::",
            indexNavigationBar++;
                                        post: "]]"
            var NavToggle = document.createElement("a");
                                }
            NavToggle.className = 'NavToggle';
                         }
            NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
            NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
            var isCollapsed = hasClass( NavFrame, "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 (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
                if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
                    if ( NavChild.style.display == 'none' ) {
                         isCollapsed = true;
                    }
                 }
                 }
            }
        }
            if (isCollapsed) {
} );
                for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
                    if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
        'section': 'annotations',
                         NavChild.style.display = 'none';
        'group': 'properties',
                    }
        'tools': {
              'appears': {
                         label: 'Genre', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://tunearch.org/w/images/icons8-musical-notes-15.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "[[Has genre::",
                                        post: "]]"
                                }
                        }
                 }
                 }
            }
        }
            var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
} );  
            NavToggle.appendChild(NavToggleText);
/* Your code goes here */
 
};
   
   
            // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
/* Check if we are in edit mode and the required modules are available and then customize the toolbar */
            for(var j=0; j < NavFrame.childNodes.length; j++) {
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
                 if (hasClass(NavFrame.childNodes[j], "NavHead")) {
        mw.loader.using( 'user.options', function () {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                 if ( mw.user.options.get('usebetatoolbar') ) {
                    NavFrame.childNodes[j].appendChild(NavToggle);
                        mw.loader.using( 'ext.wikiEditor.toolbar', function () {
                                $(document).ready( customizeToolbar );
                        } );
                 }
                 }
            }
        } );
            NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
        }
 
    }
 
/* ************** */
 
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() {
ModifySidebar( 'remove', 'toolbox', 'What links here', 'https://tunearch.org/wiki/Special:WhatLinksHere' );
        ModifySidebar( 'remove', 'toolbox', 'Cite this page', 'https://tunearch.org/wiki/Special:CiteThisPage' );
        ModifySidebar( 'remove', 'toolbox', 'Related changes', 'https://tunearch.org/wiki/Special:RecentChangesLinked' );
        ModifySidebar( 'remove', 'toolbox', 'Upload file', 'https://tunearch.org/wiki/Special:Upload' );
        ModifySidebar( 'remove', 'toolbox', 'Browse properties', 'https://tunearch.org/wiki/Special:Browse' );
        ModifySidebar( 'remove', 'toolbox', 'Browse properties', 'https://tunearch.org/wiki/Special:Browse' );
        ModifySidebar( 'remove', 'toolbox', 'Page information', 'https://tunearch.org/w/index.php?title=TTA&action=info' );
 
}
}
 
$( createNavigationBarToggleButton );
jQuery( CustomizeModificationsOfSidebar );

Latest revision as of 12:33, 17 December 2024

document.getElementById('searchform').action = '/w/index.php';
document.getElementsByName('search')[0].id = 'searchInput';

var customizeToolbar = function() {
// TOOLBAR  ('#free_text').wikiEditor, just as they exist for ('#wpTextbox1').wikiEditor
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'sections': {
                'annotations': {
                        'type': 'toolbar', // Can also be 'booklet'
                        'label': 'Annotations'
                        // or 'labelMsg': 'section-emoticons-label' for a localized label
                }
        }
} );

//GROUP
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'annotations',
        'groups': {
                'properties': {
                        'label': 'Properties' // or use labelMsg for a localized label, see above
                }
        }
} );

//BUTTONS        
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'annotations',
        'group': 'properties',
        'tools': {
                'aka': {
                        label: 'Also know as', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://tunearch.org/w/images/icons8-music-15.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "[[Is_also_known_as::",
                                        post: "]]"
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'annotations',
        'group': 'properties',
        'tools': {
              'appears': {
                        label: 'Appears in', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://tunearch.org/w/images/icons8-book-15.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "[[Appears_in::",
                                        post: "]]"
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'annotations',
        'group': 'properties',
        'tools': {
              'appears': {
                        label: 'Composed by', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://tunearch.org/w/images/icons8-important-property-15.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "[[Was composed by::",
                                        post: "]]"
                                }
                        }
                }
        }
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'annotations',
        'group': 'properties',
        'tools': {
              'appears': {
                        label: 'Come from', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://tunearch.org/w/images/icons8-origin-15.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "[[It comes from::",
                                        post: "]]"
                                }
                        }
                }
        }
} ); 
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'annotations',
        'group': 'properties',
        'tools': {
              'appears': {
                        label: 'Genre', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'http://tunearch.org/w/images/icons8-musical-notes-15.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "[[Has genre::",
                                        post: "]]"
                                }
                        }
                }
        }
} ); 
/* Your code goes here */

};
 
/* Check if we are in edit mode and the required modules are available and then customize the toolbar */
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
        mw.loader.using( 'user.options', function () {
                if ( mw.user.options.get('usebetatoolbar') ) {
                        mw.loader.using( 'ext.wikiEditor.toolbar', function () {
                                $(document).ready( customizeToolbar );
                        } );
                }
        } );
}


/* ************** */

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() {
	ModifySidebar( 'remove', 'toolbox', 'What links here', 'https://tunearch.org/wiki/Special:WhatLinksHere' );
        ModifySidebar( 'remove', 'toolbox', 'Cite this page', 'https://tunearch.org/wiki/Special:CiteThisPage' );
        ModifySidebar( 'remove', 'toolbox', 'Related changes', 'https://tunearch.org/wiki/Special:RecentChangesLinked' );
        ModifySidebar( 'remove', 'toolbox', 'Upload file', 'https://tunearch.org/wiki/Special:Upload' );
        ModifySidebar( 'remove', 'toolbox', 'Browse properties', 'https://tunearch.org/wiki/Special:Browse' );
        ModifySidebar( 'remove', 'toolbox', 'Browse properties', 'https://tunearch.org/wiki/Special:Browse' );
        ModifySidebar( 'remove', 'toolbox', 'Page information', 'https://tunearch.org/w/index.php?title=TTA&action=info' );

}

jQuery( CustomizeModificationsOfSidebar );