MediaWiki:Common.js

//

/** * Add a link to one of the portlet menus on the page, including: * * p-cactions: Content actions (shown as tabs above the main content in Monobook) * p-personal: Personal tools (shown at the top right of the page in Monobook) * p-navigation: Navigation * p-tb: Toolbox * * This function exists for the convenience of custom JS authors. All * but the first three parameters are optional, though providing at * least an id and a tooltip is recommended. * * By default the new link will be added to the end of the list. To * add the link before a given existing item, pass the DOM node of * that item (easily obtained with document.getElementById) as the * nextnode parameter; to add the link _after_ an existing item, pass * the node's nextSibling instead. * * @param String portlet -- id of the target portlet ("p-cactions", "p-personal", "p-navigation" or "p-tb") * @param String href -- link URL * @param String text -- link text (will be automatically lowercased by CSS for p-cactions in Monobook) * @param String id -- id of the new item, should be unique and preferably have the appropriate prefix ("ca-", "pt-", "n-" or "t-") * @param String tooltip -- text to show when hovering over the link, without accesskey suffix * @param String accesskey -- accesskey to activate this link (one character, try to avoid conflicts) * @param Node nextnode -- the DOM node before which the new item should be added, should be another item in the same list * * @return Node -- the DOM node of the new item (an LI element) or null */ function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) { var node = document.getElementById(portlet); if ( !node ) return null; node = node.getElementsByTagName( "ul" )[0]; if ( !node ) return null;

var link = document.createElement( "a" ); link.appendChild( document.createTextNode( text ) ); link.href = href;

var item = document.createElement( "li" ); item.appendChild( link ); if ( id ) item.id = id;

if ( accesskey ) { link.setAttribute( "accesskey", accesskey ); tooltip += " ["+accesskey+"]"; }	if ( tooltip ) { link.setAttribute( "title", tooltip ); }	if ( accesskey && tooltip ) { updateTooltipAccessKeys( new Array( link ) ); }

if ( nextnode && nextnode.parentNode == node ) node.insertBefore( item, nextnode ); else node.appendChild( item ); // IE compatibility (?)

return item; }

function getInnerText(el) { if (typeof el == "string") return el; if (typeof el == "undefined") { return el }; if (el.textContent) return el.textContent; // not needed but it is faster if (el.innerText) return el.innerText;    // IE doesn't have textContent var str = "";

var cs = el.childNodes; var l = cs.length; for (var i = 0; i < l; i++) { switch (cs[i].nodeType) { case 1: //ELEMENT_NODE str += ts_getInnerText(cs[i]); break; case 3:	//TEXT_NODE str += cs[i].nodeValue; break; }	}	return str; }

/** * Set up accesskeys/tooltips from the deprecated ta array. If doId * is specified, only set up for that id. Note that this function is * deprecated and will not be supported indefinitely -- use * updateTooltipAccessKey instead. * * @param mixed doId string or null */ function akeytt( doId ) { // A lot of user scripts (and some of the code below) break if // ta isn't defined, so we make sure it is. Explictly using // window.ta avoids a "ta is not defined" error. if (!window.ta) window.ta = new Array;

// Make a local, possibly restricted, copy to avoid clobbering // the original. var ta; if ( doId ) { ta = [doId]; } else { ta = window.ta; }

// Now deal with evil deprecated ta var watchCheckboxExists = document.getElementById( 'wpWatchthis' ) ? true : false; for (var id in ta) { var n = document.getElementById(id); if (n) { var a = null; var ak = ''; // Are we putting accesskey in it			if (ta[id][0].length > 0) { // Is this object a object? If not assume it's the next child.

if (n.nodeName.toLowerCase == "a") { a = n;				} else { a = n.childNodes[0]; }			 	// Don't add an accesskey for the watch tab if the watch // checkbox is also available. if (a && ((id != 'ca-watch' && id != 'ca-unwatch') || !watchCheckboxExists)) { a.accessKey = ta[id][0]; ak = ' ['+tooltipAccessKeyPrefix+ta[id][0]+']'; }			} else { // We don't care what type the object is when assigning tooltip a = n;				ak = ''; }

if (a) { a.title = ta[id][1]+ak; }		}	} }

var checkboxes; var lastCheckbox;

function setupCheckboxShiftClick { checkboxes = []; lastCheckbox = null; var inputs = document.getElementsByTagName('input'); addCheckboxClickHandlers(inputs); }

function addCheckboxClickHandlers(inputs, start) { if ( !start) start = 0;

var finish = start + 250; if ( finish > inputs.length ) finish = inputs.length;

for ( var i = start; i < finish; i++ ) { var cb = inputs[i]; if ( !cb.type || cb.type.toLowerCase != 'checkbox' ) continue; var end = checkboxes.length; checkboxes[end] = cb; cb.index = end; cb.onclick = checkboxClickHandler; }

if ( finish < inputs.length ) { setTimeout( function {			addCheckboxClickHandlers(inputs, finish);		}, 200 ); } }

function checkboxClickHandler(e) { if (typeof e == 'undefined') { e = window.event; }	if ( !e.shiftKey || lastCheckbox === null ) { lastCheckbox = this.index; return true; }	var endState = this.checked; var start, finish; if ( this.index < lastCheckbox ) { start = this.index + 1; finish = lastCheckbox; } else { start = lastCheckbox; finish = this.index - 1; }	for (var i = start; i <= finish; ++i ) { checkboxes[i].checked = endState; if( i > start && typeof checkboxes[i].onchange == 'function' ) checkboxes[i].onchange; // fire triggers }	lastCheckbox = this.index; return true; }

function toggle_element_activation(ida,idb) { if (!document.getElementById) { return; }	document.getElementById(ida).disabled=true; document.getElementById(idb).disabled=false; }

function toggle_element_check(ida,idb) { if (!document.getElementById) { return; }	document.getElementById(ida).checked=true; document.getElementById(idb).checked=false; }

/*	Written by Jonathan Snook, http://www.snook.ca/jonathan Add-ons by Robert Nyman, http://www.robertnyman.com Author says "The credit comment is all it takes, no license. Go crazy with it!:-)"	From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/ function getElementsByClassName(oElm, strTagName, oClassNames){	var arrReturnElements = new Array;	if ( typeof( oElm.getElementsByClassName ) == "function" ) {		/* Use a native implementation where possible FF3, Saf3.2, Opera 9.5 */		var arrNativeReturn = oElm.getElementsByClassName( oClassNames );		if ( strTagName == "*" )			return arrNativeReturn;		for ( var h=0; h < arrNativeReturn.length; h++ ) {			if( arrNativeReturn[h].tagName.toLowerCase == strTagName.toLowerCase )				arrReturnElements[arrReturnElements.length] = arrNativeReturn[h];		}		return arrReturnElements;	}	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);	var arrRegExpClassNames = new Array;	if(typeof oClassNames == "object"){ for(var i=0; i<oClassNames.length; i++){ arrRegExpClassNames[arrRegExpClassNames.length] = new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"); }	}	else{ arrRegExpClassNames[arrRegExpClassNames.length] = new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"); }	var oElement; var bMatchesAll; for(var j=0; j<arrElements.length; j++){ oElement = arrElements[j]; bMatchesAll = true; for(var k=0; k<arrRegExpClassNames.length; k++){ if(!arrRegExpClassNames[k].test(oElement.className)){ bMatchesAll = false; break; }		}		if(bMatchesAll){ arrReturnElements[arrReturnElements.length] = oElement; }	}	return (arrReturnElements) }

function redirectToFragment(fragment) { var match = navigator.userAgent.match(/AppleWebKit\/(\d+)/); if (match) { var webKitVersion = parseInt(match[1]); if (webKitVersion < 420) { // Released Safari w/ WebKit 418.9.1 messes up horribly // Nightlies of 420+ are ok			return; }	}	if (is_gecko) { // Mozilla needs to wait until after load, otherwise the window doesn't scroll addOnloadHook(function {			if (window.location.hash == "")				window.location.hash = fragment;		}); } else { if (window.location.hash == "") window.location.hash = fragment; } }

/**************************************************************/ /* sliders using jquery by User:Tierrie in Dragon Age Wiki */ /**************************************************************/ //wsl.loadScript("http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"); //wsl.loadScript("http://dragonage.wikia.com/index.php?title=MediaWiki:Jquery-ui.min.js&action=raw&ctype=text/javascript");

mw.loader.using( ['jquery.ui.tabs'], function { $(document).ready(function { var $tabs = $("#portal_slider").tabs({ fx: {opacity:'toggle', duration:100} } ); $("[class^=portal_sliderlink]").click(function { // bind click event to link   $tabs.tabs('select', this.className.replace("portal_sliderlink_", ""));    return false;  }); $('#portal_next').click(function {   $tabs.tabs('select', ($tabs.tabs('option', 'selected') == ($tabs.tabs('length'))-1) ? 0 : $tabs.tabs('option', 'selected') + 1 ); // switch to next tab   return false;  }); $('#portal_prev').click(function { // bind click event to link   $tabs.tabs('select', ($tabs.tabs('option', 'selected') == 0) ? ($tabs.tabs('length')-1) : $tabs.tabs('option', 'selected') - 1 ); // switch to previous tab   return false;  }); }); });

// ************************************************** // Experimental javascript countdown timer (Splarka) // Version 0.0.3 // ************************************************** // // Usage example: // //  Only January 01 2007 00:00:00 PST until New years. // //  Javascript disabled. function updatetimer(i) { var now = new Date; var then = timers[i].eventdate; var diff = count=Math.floor((then.getTime-now.getTime)/1000); // catch bad date strings if(isNaN(diff)) { timers[i].firstChild.nodeValue = '** ' + timers[i].eventdate + ' **' ; return; } // determine plus/minus if(diff<0) { diff = -diff; var tpm = 'T plus '; } else { var tpm = 'T minus '; } // calcuate the diff var left = (diff%60) + ' seconds'; diff=Math.floor(diff/60); if(diff > 0) left = (diff%60) + ' minutes ' + left; diff=Math.floor(diff/60); if(diff > 0) left = (diff%24) + ' hours ' + left; diff=Math.floor(diff/24); if(diff > 0) left = diff + ' days ' + left timers[i].firstChild.nodeValue = tpm + left; // a setInterval is more efficient, but calling setTimeout // makes errors break the script rather than infinitely recurse timeouts[i] = setTimeout('updatetimer(' + i + ')',1000); } function checktimers { //hide 'nocountdown' and show 'countdown' var nocountdowns = getElementsByClassName(document, 'span', 'nocountdown'); for(var i in nocountdowns) nocountdowns[i].style.display = 'none' var countdowns = getElementsByClassName(document, 'span', 'countdown'); for(var i in countdowns) countdowns[i].style.display = 'inline' //set up global objects timers and timeouts. timers = getElementsByClassName(document, 'span', 'countdowndate'); //global timeouts = new Array; // generic holder for the timeouts, global if(timers.length == 0) return; for(var i in timers) { timers[i].eventdate = new Date(timers[i].firstChild.nodeValue); updatetimer(i); //start it up  } } addOnloadHook(checktimers); // ************************************************** // - end -  Experimental javascript countdown timer // **************************************************

/** Change "Patroller" to newGroup **/ if((wgPageName == 'User:Besty17') || (wgPageName == 'User_talk:Besty17') || (wgPageName == 'User_blog:Besty17') || (wgPageName == 'Special:Contributions/Besty17')) { $('.group').html('Patroller'); }