MediaWiki:Common.js
From Memory Alpha, the free Star Trek reference
Note: After saving, you have to bypass your browser's cache to see the changes.
- Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
- Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
- Opera users have to clear their caches through Tools→Preferences
- Konqueror and Safari users can just click the Reload button.
- Chrome: press Ctrl+F5 or Shift+F5
/*
Tools: [http://memory-alpha.org/en/index.php?title=-&action=raw&smaxage=0&gen=js reload cache]
<pre><nowiki>
*/
/* tooltips and access keys */
ta = new Object();
ta['pt-userpage'] = new Array('.','My user page');
ta['pt-anonuserpage'] = new Array('.','The user page for the ip you\'re editing as');
ta['pt-mytalk'] = new Array('n','My talk page');
ta['pt-anontalk'] = new Array('n','Discussion about edits from this ip address');
ta['pt-preferences'] = new Array('','My preferences');
ta['pt-watchlist'] = new Array('l','List of pages I\'m monitoring for changes');
ta['pt-mycontris'] = new Array('y','List of my contributions');
ta['pt-login'] = new Array('o','You are encouraged to log in; it is not mandatory, however');
ta['pt-anonlogin'] = new Array('o','You are encouraged to log in; it is not mandatory, however');
ta['pt-logout'] = new Array('o','Log out');
ta['ca-talk'] = new Array('t','Discussion about the content page');
ta['ca-edit'] = new Array('e','You can edit this page; please use the preview button before saving');
ta['ca-addsection'] = new Array('+','Add a comment to this discussion');
ta['ca-viewsource'] = new Array('e','This page is protected; you can view its source');
ta['ca-history'] = new Array('h','Past versions of this page');
ta['ca-protect'] = new Array('=','Protect this page');
ta['ca-delete'] = new Array('d','Delete this page');
ta['ca-undelete'] = new Array('d','Restore the edits done to this page before it was deleted');
ta['ca-move'] = new Array('m','Move this page');
ta['ca-nomove'] = new Array('','You don\'t have the permissions to move this page');
ta['ca-watch'] = new Array('w','Add this page to your watchlist');
ta['ca-unwatch'] = new Array('w','Remove this page from your watchlist');
ta['search'] = new Array('','Search Memory Alpha');
ta['p-logo'] = new Array('z','Main Page');
ta['n-mainpage'] = new Array('z','Visit the Main Page');
ta['n-Main-page'] = new Array('z','Visit the Main Page');
ta['n-portal'] = new Array('','About the project, what you can do, where to find things');
ta['n-Chat'] = new Array('','IRC, the place to chat');
ta['n-currentevents'] = new Array('','Find background information on current events');
ta['n-recentchanges'] = new Array('r','The list of recent changes in the wiki');
ta['n-randompage'] = new Array('x','Load a random page');
ta['n-help'] = new Array('/','The place to find out information');
ta['n-sitesupport'] = new Array('','Support us');
ta['t-whatlinkshere'] = new Array('j','List of all wiki pages that link here');
ta['t-recentchangeslinked'] = new Array('k','Recent changes in pages linking to this page');
ta['feed-rss'] = new Array('','RSS feed for this page');
ta['feed-atom'] = new Array('','Atom feed for this page');
ta['t-contributions'] = new Array('','View the list of contributions of this user');
ta['t-emailuser'] = new Array('','Send a mail to this user');
ta['t-upload'] = new Array('u','Upload images or media files');
ta['t-specialpages'] = new Array('q','List of all special pages');
ta['ca-nstab-main'] = new Array('c','View the content page');
ta['ca-nstab-user'] = new Array('c','View the user page');
ta['ca-nstab-media'] = new Array('c','View the media page');
ta['ca-nstab-special'] = new Array('','This is a special page; you can\'t edit the page itself.');
ta['ca-nstab-wp'] = new Array('c','View the project page');
ta['ca-nstab-image'] = new Array('c','View the image page');
ta['ca-nstab-mediawiki'] = new Array('c','View the system message');
ta['ca-nstab-template'] = new Array('c','View the template');
ta['ca-nstab-help'] = new Array('c','View the help page');
ta['ca-nstab-category'] = new Array('c','View the category page');
//********************************************************************************
// Start "Hidden appearances section/interactive tree" script; by [[User:Bp]]
//********************************************************************************
function toggleAppearancesPane(eid) {
e = document.getElementById(eid);
if (e) { e.className = (e.className == "hiddenlist") ? "visiblelist" : "hiddenlist"; }
}
function showAppearancesPane(eid) {
e = document.getElementById(eid);
if (e) { e.className = "visiblelist"; }
}
function hideAppearancesPane(eid) {
e = document.getElementById(eid);
if (e) { e.className = "hiddenlist"; }
}
// -----
var tree = 0;
var pane = 0;
var paneListForThisTree = new Array();
var descriptionString = new String("This list contains %d items."); //%d is where the number of items is inserted
var smallTreeCount = 8; // less leaves than this, the tree will be open at first
var interactiveTrees = 1; // set this to 0 in user.js to turn this off
function button(text,onclick,cls) {
var b = document.createElement('a');
b.innerHTML = text;
b.href="javascript:"+onclick;
b.className = cls;
return b;
}
function recursiveCountAndMark(e, depth, nocount) {
var si = e.firstChild;
var total = 0;
while(si) {
var tn = (si.tagName) ? si.tagName.toLowerCase() : '';
if (tn == "li") { total++; }
var subtotal = recursiveCountAndMark(si, depth+1, nocount);
if (tn == "ul" || tn == "ol") {
if (depth > 1) {
si.id = "Pane" + pane++;
paneListForThisTree.push(si.id);
si.className = "hiddenlist";
si.parentNode.insertBefore(document.createTextNode('('), si);
si.parentNode.insertBefore(button( (nocount) ? "+/-" : subtotal, "toggleAppearancesPane(\""+si.id+"\")", "listexpand"), si);
si.parentNode.insertBefore(document.createTextNode(')'), si);
total--; // don't count the li that this ul/ol is in
} else {
// we are finished and this is the top ul/ol
if (subtotal < smallTreeCount) { // this small enough they can be visible right away
for (var i=0;i<paneListForThisTree.length;i++) {
toggleAppearancesPane(paneListForThisTree[i]);
}
}
var allonexec = '{';
var alloffexec = '{';
for (var i=0;i<paneListForThisTree.length;i++) {
allonexec += "showAppearancesPane(\""+paneListForThisTree[i]+"\"); ";
alloffexec += "hideAppearancesPane(\""+paneListForThisTree[i]+"\"); ";
}
allonexec += '}'; alloffexec += '}';
var ds = (nocount) ? "" : descriptionString.replace(/\%d/g, subtotal);
si.parentNode.insertBefore(document.createTextNode(ds + ' ('), si);
si.parentNode.insertBefore(button("show all", allonexec, "listexpand"), si);
si.parentNode.insertBefore(document.createTextNode(' • '), si);
si.parentNode.insertBefore(button("hide all", alloffexec, "listexpand"), si);
si.parentNode.insertBefore(document.createTextNode(')'), si);
}
}
total += subtotal;
si = si.nextSibling;
}
return total;
}
function doAppearancesTrees() {
if (!interactiveTrees) { return; }
var divs = document.getElementsByTagName("div");
for (var i = 0; i < divs.length; i++) {
if (divs[i].className.match(/\bappear\b/)) {
recursiveCountAndMark(divs[i], 0, (divs[i].className.match(/\bnocount\b/)) ? 1 : 0);
paneListForThisTree = new Array();
tree++;
}
}
// fix a bug noticed by renegade54
// jump to the named anchor again
if (window.location.hash && tree > 0) {
// still won't work 100% in safari and khtml
if (navigator.userAgent.indexOf("MSIE") != -1) {
window.location = window.location.hash; // -- causes Firefox to fire onload events
} else {
window.location.hash = window.location.hash;
}
}
}
hookEvent("load", doAppearancesTrees);
// End "Hidden Appearances section" script
//********************************************************************************
// Start "Interactive quotes" script; by [[User:Bp]]
//********************************************************************************
function speakerLabel(text) {
var spkr = document.createElement('span');
spkr.innerHTML = text + ": ";
spkr.className = "speaker-label";
return spkr;
}
function explicitQuoteOn(event, e) {
var si = (e) ? e.firstChild : this.firstChild;
while(si) {
explicitQuoteOn(event, si);
if (si.className == "dialogue-inside") {
si.className = "dialogue-inside-highlight";
} else if (si.className == "quoteline") {
if (si.childNodes[0].className != "speaker-label") {
if (si.title != '') {
si.insertBefore(speakerLabel(si.title), si.childNodes[0]);
si.title = '';
}
}
if (si.childNodes[0].className == "speaker-label") {
si.childNodes[0].style.display = "inline";
}
}
si = si = si.nextSibling;
}
}
function explicitQuoteOff(event, e) {
var si = (e) ? e.firstChild : this.firstChild;
while(si) {
explicitQuoteOff(event, si);
if (si.className == "dialogue-inside-highlight") {
si.className = "dialogue-inside";
} else if (si.className == "quoteline") {
if (si.childNodes[0].className == "speaker-label") {
si.childNodes[0].style.display = "none";
}
}
si = si = si.nextSibling;
}
}
var explicitQuotes = 0;
function doQuotes() {
if (!explicitQuotes) { return; }
var dumbevent;
var divs = document.getElementsByTagName("div");
for (var i = 0; i < divs.length; i++) {
if (divs[i].className == 'dialogue') {
if (explicitQuotes == 1) {
divs[i].onmouseover = explicitQuoteOn;
divs[i].onmouseout = explicitQuoteOff;
} else {
explicitQuoteOn(dumbevent, divs[i]);
}
}
}
}
hookEvent("load", doQuotes);
// End "Interactive quotes" script
//********************************************************************************
// Start "Articletype positioning" script; by [[User:Bp]]
//********************************************************************************
function moveArticletypeDiv() {
var fooel = document.getElementById('ma-article-type');
if (fooel!=null) {
var artel = document.getElementById('article');
var titel = document.getElementById('top');
fooel = fooel.parentNode.removeChild(fooel);
if (artel!=null) {
artel.parentNode.insertBefore(fooel,artel);
} else {
//fall back to a position before H1 - useful for monobook skin
titel.parentNode.insertBefore(fooel,titel);
}
}
}
hookEvent("load", moveArticletypeDiv);
// End "Articletype positioning" script
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// ADVANCED AUTO REFRESHING RECENT CHANGES AND WATCHLIST
// Code courtesy of "pcj" of WoWWiki.
// INDIVIDUAL USE
// This is a modified version of the WoWWiki site-wide version.
// This version is designed for Special:Mypage/global.js use.
// WIKI-WIDE USE
// If you add it to a wiki's MediaWiki:Common.js it *should* work - however, this is untested.
// It should not conflict with your own global.js.
// WHAT IT DOES
// The code adds a checkbox at the top of Special:RecentChanges and Special:Watchlist, next to the header.
// Ticking this sets a cookie (specific to each wiki) and starts updating the list.
// This occurs silently every 60 seconds without a full page reload occurring.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
ajaxPages="Special:RecentChanges,Special:Watchlist,";
function setCookie(c_name,value,expiredays) {
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
function getCookie(c_name) {
if (document.cookie.length>0) {
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1) {
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ""
}
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest(); //Not Internet Explorer
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP"); //Internet Explorer
} else {
//fail silently
}
}
getRCDataRO = getXmlHttpRequestObject();
var cr = new RegExp("\r", "gm");
var lf = new RegExp("\n", "gm");
var endText = new RegExp('</div>[\t\s]*?<!-- end content -->[\t\s]*?<div class="visualClear">', "mi");
var rcTimer;
var rcRefresh = 60000;
function preloadAJAXRC() {
if (skin == "monaco") {
s = 1;
} else {
s = 0;
}
ajaxRCCookie = (getCookie("ajaxload-"+wgPageName)=="on") ? true:false;
document.getElementsByTagName("h1")[0].innerHTML += ' <span style="font-size: xx-small; border-bottom: 1px dotted; cursor:help;" title="Enable auto-refreshing page loads">AJAX:</span><input type="checkbox" id="ajaxRCtoggle" onClick="toggleRC();">';
document.getElementById("ajaxRCtoggle").checked = ajaxRCCookie;
if (getCookie("ajaxload-"+wgPageName)=="on") loadRCData();
}
function toggleRC() {
if (document.getElementById("ajaxRCtoggle").checked == true) {
setCookie("ajaxload-"+wgPageName, "on", 30);
loadRCData();
} else {
setCookie("ajaxload-"+wgPageName, "off", 30);
clearTimeout(rcTimer);
}
}
function loadRCData() {
if (getRCDataRO.readyState == 4 || getRCDataRO.readyState == 0) {
if (location.href.indexOf("/wiki/")) {
rcURL = "http://" + location.hostname + "/wiki/" + wgPageName + location.search;
} else {
rcURL = "http://" + location.hostname + "/" + wgPageName + location.search;
}
getRCDataRO.open("GET", rcURL, true);
getRCDataRO.onreadystatechange = parseRCdata;
getRCDataRO.send(null);
}
}
function parseRCdata() {
if (getRCDataRO.readyState == 4) {
textFilter = new RegExp('<div id="bodyContent">.*?</div>[\t\s]*?<!-- end content -->[\t\s]*?<div class="visualClear">', "i");
rawRCdata = getRCDataRO.responseText.replace(cr, "").replace(lf, "");
filteredRCdata = textFilter.exec(rawRCdata);
updatedText = filteredRCdata[0].replace('<div id="bodyContent">', "").replace(endText, "");
document.getElementById("bodyContent").innerHTML = updatedText;
rcTimer = setTimeout("loadRCData();", rcRefresh);
}
}
if (ajaxPages.indexOf(wgPageName)!=-1) addOnloadHook(preloadAJAXRC);
/** 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);
};
})();
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// END OF CODE
///////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
</nowiki></pre>
*/
