MediaWiki:Common.js

From Bugwoodwiki

Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh); Konqueror: click Reload or press F5; Opera: clear the cache in Tools → Preferences; Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

/* Any JavaScript here will be loaded for all users on every page load. */
if (mwCustomEditButtons) {
 
    mwCustomEditButtons[mwCustomEditButtons.length] = {
        "imageFile": "skins/common/images/Button_Author.png",
        "speedTip": "Add an Author line in the preferred format. 3 tildes (~) for author will enter your user nickname and link to your user page when the page is saved.",
        "tagOpen": "''Author:",
        "tagClose": "''",
        "sampleText": "[[User:UserName|Full Name]], Organization"};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "skins/common/images/Button_redirect.png",
     "speedTip": "Redirect a user from one article to a common article",
     "tagOpen": "#REDIRECT [[",
     "tagClose": "]]",
     "sampleText": "Valid Page Name"}
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "skins/common/images/Button_sub_letter.png",
     "speedTip": "Subscript",
     "tagOpen": "<sub>",
     "tagClose": "</sub>",
     "sampleText": "#######"}
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "skins/common/images/Button_sup_letter.png",
     "speedTip": "Superscript",
     "tagOpen": "<sup>",
     "tagClose": "</sup>",
     "sampleText": "#######"}
    mwCustomEditButtons[mwCustomEditButtons.length] = {
        "imageFile": "skins/common/images/Button_center.png",
        "speedTip": "Center a section of text",
        "tagOpen": "<center>",
        "tagClose": "</center>",
        "sampleText": "Text you want centered"};
    mwCustomEditButtons[mwCustomEditButtons.length] = {
        "imageFile": "skins/common/images/Button_small.png",
        "speedTip": "Make text small for captions",
        "tagOpen": "<small>",
        "tagClose": "</small>",
        "sampleText": "Text you want small"};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "skins/common/images/Button_bimage.png",
     "speedTip": "Use a 7-digit image number to add a BugwoodIDS Image",
     "tagOpen": "<bimage>",
     "tagClose": "</bimage>",
     "sampleText": "#######"}
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "skins/common/images/Button_Taxobox.png",
     "speedTip": "Use a 7-digit image number to add a BugwoodIDS Image with taxonomy listed",
     "tagOpen": "<btaxobox imgnum=",
     "tagClose": "/>",
     "sampleText": "#######"}
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "skins/common/images/Button_Bsubjectgallery.png",
     "speedTip": "Add a gallery of images selected by Bugwood using the Subject ID Number",
     "tagOpen": "<bsubjectgallery subject=",
     "tagClose": "/>",
     "sampleText": "####"}
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "skins/common/images/Button_Busergallery.png",
     "speedTip": "Add a gallery of images selected by a user using the Collection ID Number",
     "tagOpen": "<bgallery collection=",
     "tagClose": "/>",
     "sampleText": "####"}
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "skins/common/images/Button_insert_table.png",
     "speedTip": "Insert the basic structure for a table",
     "tagOpen": '{| class="wikitable"\n|-\n',
     "tagClose": "\n|}",
     "sampleText": "! header 1\n! header 2\n! header 3\n|-\n| row 1, cell 1\n| row 1, cell 2\n| row 1, cell 3\n|-\n| row 2, cell 1\n| row 2, cell 2\n| row 2, cell 3"};
    mwCustomEditButtons[mwCustomEditButtons.length] = {
        "imageFile": "skins/common/images/Button_reflink.png",
        "speedTip": "Insert an in-line reference",
        "tagOpen": "<ref>",
        "tagClose": "</ref>",
        "sampleText": "Insert footnote text here"};
    mwCustomEditButtons[mwCustomEditButtons.length] = {
        "imageFile": "skins/common/images/Button_Insert_REF.png",
        "speedTip": "Insert list of references from in-line citations",
        "tagOpen": "",
        "tagClose": "<references/>",
        "sampleText": ""};
    mwCustomEditButtons[mwCustomEditButtons.length] = {
        "imageFile": "skins/common/images/Button_HPIPM.png",
        "speedTip": "Create internal link to High Plains IPM Article",
        "tagOpen": "[[HPIPM:",
        "tagClose": "]]",
        "sampleText": "Article name|Text to appear"};
 
}
 
/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *               [[**DOCUMENTATION LINK**]].
 *  Maintainers: [[**MAINTAINERS**]]
 */
 
var autoCollapse = 2;
var collapseCaption = "hide";
var expandCaption = "show";
 
function collapseTable( tableIndex )
{
    var Button = document.getElementById( "collapseButton" + tableIndex );
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
 
    if ( !Table || !Button ) {
        return false;
    }
 
    var Rows = Table.rows;
 
    if ( Button.firstChild.data == collapseCaption ) {
        for ( var i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = "none";
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( var i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
}
 
function createCollapseButtons()
{
    var tableIndex = 0;
    var NavigationBoxes = new Object();
    var Tables = document.getElementsByTagName( "table" );
 
    for ( var i = 0; i < Tables.length; i++ ) {
        if ( hasClass( Tables[i], "collapsible" ) ) {
 
            /* only add button and increment count if there is a header row to work with */
            var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
            if (!HeaderRow) continue;
            var Header = HeaderRow.getElementsByTagName( "th" )[0];
            if (!Header) continue;
 
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
 
            var Button     = document.createElement( "span" );
            var ButtonLink = document.createElement( "a" );
            var ButtonText = document.createTextNode( collapseCaption );
 
            Button.className = "collapseButton";  //Styles are declared in Common.css
 
            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
            ButtonLink.appendChild( ButtonText );
 
            Button.appendChild( document.createTextNode( "[" ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( "]" ) );
 
            Header.insertBefore( Button, Header.childNodes[0] );
            tableIndex++;
        }
    }
 
    for ( var i = 0;  i < tableIndex; i++ ) {
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
            collapseTable( i );
        } 
    }
}
 
addOnloadHook( createCollapseButtons );
 
/** Test if an element has a certain class **************************************
  *
  * Description: Uses regular expressions and caching for better performance.
  * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
  */
 
var hasClass = (function () {
	var reCache = {};
	return function (element, className) {
		return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
	};
})();
 
 
/** Dynamic Navigation Bars (experimental) *************************************
 *
 * From English Wikipedia, 2008-09-15
 *
 *  Description: See [[Wikipedia:NavFrame]].
 *  Maintainers: UNMAINTAINED
 */
 
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
 
// shows and hides content and picture (if available) of navigation bars
// Parameters:
//     indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar( indexNavigationBar ){
	var NavToggle = document.getElementById('NavToggle' + indexNavigationBar);
	var NavFrame = document.getElementById('NavFrame' + indexNavigationBar);
 
	if( !NavFrame || !NavToggle ) {
		return false;
	}
 
	// if shown now
	if( NavToggle.firstChild.data == NavigationBarHide ) {
		for( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
			if ( hasClass( NavChild, 'NavPic' ) ) {
				NavChild.style.display = 'none';
			}
			if ( hasClass( NavChild, 'NavContent') ) {
				NavChild.style.display = 'none';
			}
		}
	NavToggle.firstChild.data = NavigationBarShow;
 
	// if hidden now
	} else if( NavToggle.firstChild.data == NavigationBarShow) {
		for( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
			if( hasClass( NavChild, 'NavPic' ) ) {
				NavChild.style.display = 'block';
			}
			if( hasClass( NavChild, 'NavContent' ) ) {
				NavChild.style.display = 'block';
			}
		}
		NavToggle.firstChild.data = NavigationBarHide;
	}
}
 
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton(){
	var indexNavigationBar = 0;
	// iterate over all < div >-elements
	var divs = document.getElementsByTagName('div');
	for( var i = 0; NavFrame = divs[i]; i++ ) {
		// if found a navigation bar
		if( hasClass( NavFrame, 'NavFrame' ) ) {
			indexNavigationBar++;
			var NavToggle = document.createElement("a");
			NavToggle.className = 'NavToggle';
			NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
			NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
 
			var NavToggleText = document.createTextNode(NavigationBarHide);
			for( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
				if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
					if( NavChild.style.display == 'none' ) {
						NavToggleText = document.createTextNode(NavigationBarShow);
						break;
					}
				}
			}
 
			NavToggle.appendChild(NavToggleText);
			// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
			for( var j=0; j < NavFrame.childNodes.length; j++) {
				if( hasClass( NavFrame.childNodes[j], 'NavHead' ) ) {
					NavFrame.childNodes[j].appendChild(NavToggle);
				}
			}
			NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
		}
	}
} 
addOnloadHook( createNavigationBarToggleButton );
 
/** Main Page layout fixes *********************************************************
 *
 *  Description: Adds an additional link to the complete list of languages available.
 *  Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
 */
 
if (wgPageName == 'Main_Page' || wgPageName == 'Talk:Main_Page') 
    addOnloadHook(function () {
        addPortletLink('p-lang', 'http://meta.wikimedia.org/wiki/List_of_Wikipedias',
                 'Complete list', 'interwiki-completelist', 'Complete list of Wikipedias')
        var nstab = document.getElementById('ca-nstab-main')
        if (nstab && wgUserLanguage=='en') {
            while (nstab.firstChild) nstab = nstab.firstChild
            nstab.nodeValue = 'Main Page'
        }
    }
)
Personal tools
Export Current Page