MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */

/* */ if (wgAction == "edit" || wgAction == "submit") { /***** Custom edit buttons *****/ if (mwCustomEditButtons) { mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images.wikia.com/central/images/c/c8/Button_redirect.png", "speedTip": "Redirect", "tagOpen": "#REDIRECT ", "tagClose": "", "sampleText": "Insert text"}; mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images3.wikia.nocookie.net/central/images/4/4a/Button_table.png", "speedTip": "Insert 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": "http://images2.wikia.nocookie.net/central/images/1/13/Button_enter.png", "speedTip": "Line break", "tagOpen": " ", "tagClose": "", "sampleText": ""}; mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images2.wikia.nocookie.net/central/images/1/12/Button_gallery.png", "speedTip": "Insert a picture gallery", "tagOpen": '\n ", "sampleText": "Image:Example.jpg|Caption1\nImage:Example.jpg|Caption2"}; } } // ===================================================================== // Collapsible Tables // // Description: Allows tables to be collapsed, showing only the header. // Reference:   Wikipedia:Wikipedia:NavFrame //              Wikipedia:Help:Collapsing // Maintainers: Wikipedia:User:R. Koot // // ===================================================================== var autoCollapse = 2; var collapseCaption = "hide"; var expandCaption = "show"; var maxHeight = 300; function collapseTable(tableIndex) { var Button = document.getElementById("collapseButton" + tableIndex); var Table = document.getElementById("collapsibleTable" + tableIndex); if (!Table || !Button) return false; var Rows = Table.getElementsByTagName("tr"); 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 navBoxes = 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; navBoxes[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.style.styleFloat = "right"; Button.style.cssFloat = "right"; Button.style.fontSize = "90%"; Button.style.fontWeight = "normal"; Button.style.textAlign = "right"; Button.style.width = "6em"; 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++; } } var j = 0; for (var i = 0; i < tableIndex; i++) { if (hasClass(navBoxes[i], "navbox") && hasClass(navBoxes[i], "collapsible") && hasClass(navBoxes[i], "autocollapse")) j++; var h = 0; if (hasClass(navBoxes[i], "navbox") && hasClass(navBoxes[i], "collapsible")) h = navBoxes[i].clientHeight; if(h == null || h == undefined) h = 0; // Collapses if: //  1. Contains "collapsed" //  2. If j>autoCollapse, and contains "navbox collapsible autocollapse" //  3. If table height > maxHeight, and contains "navbox collapsible" //  4. If there are "innercollapse" tables in "outercollapse" tables */ if (hasClass(navBoxes[i], "collapsed") || (j > autoCollapse) || (h > maxHeight)) { collapseTable(i); } else if (hasClass(navBoxes[i], "innercollapse")) { var element = navBoxes[i]; while (element = element.parentNode) { if (hasClass(element, "outercollapse")) { collapseTable(i); break; } } } } } addOnloadHook(createCollapseButtons); // ===================================================================== // End of Collapsible Tables // =====================================================================

// ============================================================ function createCheckboxes { var items = getElementsByClassName(document, "span", "checklistitem"); for (var ti = 0; ti < items.length ; ti++) { items[ti].innerHTML = "" + items[ti].innerHTML; } } addOnloadHook( createCheckboxes ); // ============================================================

// ===================================================================== // Pagetitle rewrite // // Rewrites the page's title, used by Template:Title // by Sikon // // ===================================================================== function rewriteTitle { if(typeof(SKIP_TITLE_REWRITE) != 'undefined' && SKIP_TITLE_REWRITE) return; var titleDiv = document.getElementById('title-meta'); if(titleDiv == null || titleDiv == undefined) return; // For the title in the Monaco masthead if (skin == "monaco" && (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk")) { var mastheadUser = document.getElementById("user_masthead_head"); var mastheadSince = document.getElementById("user_masthead_since"); var titleString = ' ' + titleDiv.innerHTML; titleString += '' + mastheadSince.innerHTML; titleString += ' '; mastheadUser.innerHTML = titleString; } else { var cloneNode = titleDiv.cloneNode(true); var firstHeading = getElementsByClass('firstHeading', document.getElementById('content'), 'h1')[0]; var node = firstHeading.childNodes[0]; // new, then old! firstHeading.replaceChild(cloneNode, node); cloneNode.style.display = "inline"; var titleAlign = document.getElementById('title-align'); firstHeading.style.textAlign = titleAlign.childNodes[0].nodeValue; } } addOnloadHook(rewriteTitle, 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' // ============================================================ // wikiSiteMeter // // Function: Adds a counter from http://www.sitemeter.com/ // ============================================================ function wikiSiteMeter { if(skin == "monobook") { var sidebar = document.getElementById("p-wikicities-nav"); if(sidebar == null) return; var comboString = " wiki site meter "; comboString += "  "; sidebar.innerHTML += comboString; } if(skin == "monaco") { var sidebar = document.getElementById("widget_101"); if(sidebar == null) return; var comboString = " Wiki Site Meter"; comboString += " "; sidebar.innerHTML += comboString; } } addOnloadHook(wikiSiteMeter); // ============================================================ // End of wikiSiteMeter // ============================================================

//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 // **************************************************

// ================================================================== // Added SiteNotice Functionality // // Functions: //  * Moves the dismiss link into the SiteNotice table. //  * Saves the show/hide status of the SiteNotice in a cookie. //  * Automatically expands the SiteNotice when the ID is updated. // ================================================================== var dCookieName = "dismissSiteNotice="; var msgClose = "dismiss"; var hCookieName = "hideSiteNotice="; var hCookiePos = document.cookie.indexOf(hCookieName); var hCookieValue = ""; function editSiteNotice { var snbox = document.getElementById('mw-dismissable-notice'); if (snbox != null){ if (hCookiePos > -1) { hCookiePos = hCookiePos + hCookieName.length; var hideEndPos = document.cookie.indexOf(";", hCookiePos); if (hideEndPos > -1) { hCookieValue = document.cookie.substring(hCookiePos, hideEndPos); } else { hCookieValue = document.cookie.substring(hCookiePos); }       }        var newLink = document.createElement('a'); newLink.setAttribute('href', "javascript:dismissNotice;"); newLink.setAttribute('title', 'Dismiss this notice.'); newLink.innerHTML = msgClose; var hideLink = document.getElementById( "collapseButton" + "0" ); hideLink.href = "javascript:hideSiteNotice;" hideLink.parentNode.style.width = "12em"; hideLink.parentNode.appendChild(document.createTextNode(' [')); hideLink.parentNode.appendChild(newLink); hideLink.parentNode.appendChild(document.createTextNode(']')); snbox.tBodies[0].rows[0].deleteCell(1); if (hCookieValue != siteNoticeID && hideLink.innerHTML == "show") { collapseTable(0); }       if (hCookieValue == siteNoticeID && hideLink.innerHTML == "hide") { collapseTable(0); }   } } function hideSiteNotice { var hideLink = document.getElementById( "collapseButton" + "0" ); var date = new Date; if (hideLink.innerHTML == 'hide'){ date.setTime(date.getTime + 30*86400*1000); } else { date.setTime(date.getTime - 30*86400*1000); }   document.cookie = hCookieName + siteNoticeID + "; expires="+date.toGMTString + "; path=/"; collapseTable(0); } addOnloadHook(editSiteNotice); // ================================================================== // End of Added SiteNotice Functionality // ==================================================================

// ================================================================== // Insert username // ================================================================== function UserNameReplace { if(typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || wgUserName == null) return; $("span.insertusername").html(wgUserName); } addOnloadHook(UserNameReplace);

/* */