MediaWiki:Common.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
function toggler(id)
{
var toBeToggled = togglers[id];
if (!toBeToggled)
return;
// if some element is in list more than once, it will be toggled multiple times
for (var i = 0; i < toBeToggled.length; i++)
{
// get array of elements to operate on
var toggles = toBeToggled[i][1];
if (typeof(toggles) == "string")
{
if (toggles.charAt(0) == '-')
{
// treat as an element ID, not as class
toggles = document.getElementById(toggles.substring(1));
if (toggles)
toggles = new Array(toggles);
}
else
toggles = allClasses[toggles];
}
if (!toggles || !toggles.length)
continue;
var op = toBeToggled[i][0]; // what the operation will be
switch (op)
{
case "_reset":
for (var j in toggles)
toggles[j].style.display = toggles[j]._toggle_original_display;
break;
case "_show":
for (var j in toggles)
toggles[j].style.display = '';
break;
case "_hide":
for (var j in toggles)
toggles[j].style.display = 'none';
break;
case "":
default:
// Toggle
for (var j in toggles)
toggles[j].style.display = ((toggles[j].style.display == 'none') ? '' : 'none');
break;
}
}
}
function createTogglerLink(toggler, id)
{
var toggle = document.createElement("a");
toggle.className = 'toggler-link';
toggle.setAttribute('id', 'toggler' + id);
toggle.setAttribute('href', 'javascript:toggler("' + id + '");');
var child = toggler.firstChild;
toggler.removeChild(child);
toggle.appendChild(child);
toggler.insertBefore(toggle, toggler.firstChild);
}
function toggleInit()
{
var togglerElems = new Array();
var toggleGroup = new Array();
// initialize/clear any old information
togglers = new Array();
allClasses = new Object();
allClasses.watch = undefined;
allClasses.unwatch = undefined;
// make list of all document classes
var elems = document.getElementsByTagName("*");
var numelems = elems.length;
for (var i = 0; i < elems.length; i++)
{
var elem = elems[i];
if (!elem.className)
continue;
elem._toggle_original_display = elem.style.display;
var togglerID = -1;
var elemClasses = elem.className.split(' '); // get list of classes
for (var j = 0; j < elemClasses.length; j++)
{
var elemClass = elemClasses[j];
if (! allClasses[elemClass])
allClasses[elemClass] = new Array();
allClasses[elemClass].push(elem);
// all the special classes begin with _toggle
if (elemClass.substring(0, 7) != "_toggle")
continue;
if (elemClass == "_togglegroup")
toggleGroup = new Array();
else if (elemClass == "_toggle")
toggleGroup.push(elem);
else if (elemClass.substring(0, 12) == "_toggle_init")
{
// set initial value for display (ignore the original CSS set value)
// understands _toggle_initshow and _toggle_inithide
var disp = elemClass.substring(12);
if (disp == "show")
elem.style.display = '';
else if (disp == "hide")
elem.style.display = 'none';
elem._toggle_original_display = disp;
}
else if (elemClass.substring(0, 8) == "_toggler")
{
if (togglerID == -1)
{
togglerID = togglers.length;
togglers[togglerID] = new Array();
togglerElems[togglerID] = elem;
}
// all classes are of form _toggler_op-CLASS
// figure out what class we're toggling
// if none is specified, then we use the current toggle group
var toBeToggled;
var hyphen = elemClass.indexOf('-');
if (hyphen != -1)
toBeToggled = elemClass.substring(hyphen+1);
else
{
toBeToggled = toggleGroup;
hyphen = elemClass.length;
}
var op = elemClass.substring(8, hyphen);
togglers[togglerID].push(new Array(op, toBeToggled));
}
}
}
// add javascript links to all toggler elements
for (var i = 0; i < togglerElems.length; i++)
createTogglerLink(togglerElems[i], i);
}
function owwsitesearch(f){
f.q.value='site:http://openwetware.org/wiki/'+
f.base.value+'++'+f.qfront.value
}
addOnloadHook(toggleInit);
// </syntax>
/** Archive edit tab disabling *************************************
* Disables the edit tab on old forum topic pages to stop new people bumping old topics.
* Page can still be edited by going via the edit tab on the history etc, or by
* typing the edit address manually.
* By [[User:Spang|Spang]]
* Monaco support by [[User:Uberfuzzy|Uberfuzzy]]
* Oasis support by [[User:Uberfuzzy|Uberfuzzy]]
*/
if(wgNamespaceNumber == 110) {
function disableOldForumEdit() {
if( typeof( enableOldForumEdit ) != 'undefined' && enableOldForumEdit ) {
return;
}
if( !document.getElementById('old-forum-warning') ) {
return;
}
if( skin == 'oasis' )
{
$("#WikiaPageHeader .wikia-menu-button li a:first").html('Archived').removeAttr('href' );
$('#WikiaPageHeader .wikia-button').html('Archived').removeAttr('href');
return;
}
if( !document.getElementById('ca-edit') ) {
return;
}
var editLink = null;
if( skin == 'monaco' )
{
editLink = document.getElementById('ca-edit');
}
else if( skin == 'monobook' )
{
editLink = document.getElementById('ca-edit').firstChild;
}
else
{
return;
}
editLink.removeAttribute('href', 0);
editLink.removeAttribute('title', 0);
editLink.style.color = 'gray';
editLink.innerHTML = 'Archived';
$('span.editsection-upper').remove();
}
addOnloadHook( disableOldForumEdit );
}
//=============================================================================
// IRC support
// from http://dev.wikia.com/wiki/Freenode_IRC#Embedding_Wikia.27s_IRC_gateway
//=============================================================================
function onloadhookcustomirc() {
var replace = document.getElementById("JRChatReplace");
if (null != replace) {
replace.innerHTML='<iframe src="http://webchat.freenode.net/?channels=wikia-onepiece" width="450" height="400"></iframe>';
if (window.attachEvent) window.attachEvent("onbeforeunload",confirmexitjrchat);
else window.onbeforeunload = confirmexitjrchat;
}
//alert(document.getElementById("JRChatReplace").innerHTML);
}
if (window.addEventListener) window.addEventListener("load",onloadhookcustomirc,false);
else if (window.attachEvent) window.attachEvent("onload",onloadhookcustomirc);
/* Auto Refresh */
AjaxRCRefreshText = 'Auto-refresh';
AjaxRCRefreshHoverText = 'Automatically refresh the page';
ajaxPages = ["Special:RecentChanges","Special:WikiActivity"];
importArticles({
type: 'script',
articles: [
"u:dev:AjaxRC/code.js",
"u:dev:WallGreetingButton/code.js",
"u:dev:BackToTopButton/code.js",
"u:dev:ShowHide/code.js",
"MediaWiki:Common.js/displayTimer.js",
"MediaWiki:Common.js/Toggler.js",
"MediaWiki:FloatingRail.js",
"w:c:dev:ReferencePopups/code.js", /* Balloon pop-up references */
"MediaWiki:Common.js/ElementTestClass.js"
]
});
importScriptURI('http://anime.wikia.com/index.php?title=MediaWiki:Anime-Common.js&action=raw&ctype=text/javascript&dontcountme=s&smaxage=86400&templates=expand');
// BEGINNING: JavaScript for placing the fair use rationale template inside the summary box on [[Special:Upload]]. Code by "[[wikipedia:User:Pinky49]]", created and coded specifically for [[wikia:c:cdnmilitary|Duty & Valour]].
function FairUseRationale() {
if((wgPageName == 'Special:Upload') && document.getElementById('wpDestFile').value == '') {
document.getElementById('wpUploadDescription').value = '{{Fairuse}}';
}
}
addOnloadHook(FairUseRationale);
// ****** END: JavaScript for [[Special:Upload]] ******
// **************************************************
// Experimental javascript countdown timer (Splarka)
// Version 0.0.3
// **************************************************
//
// Usage example:
// <span class="countdown" style="display:none;">
// Only <span class="countdowndate">January 01 2007 00:00:00 PST</span> until New years.
// </span>
// <span class="nocountdown">Javascript disabled.</span>
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 = ' ';
} else {
var tpm = ' ';
}
// 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
// **************************************************
addOnloadHook(function() {$('head').append('<style type="text/css">' + $('#css').html() + '</style>');});
//Imports
importArticles({
type: "script",
articles: [
"w:c:dev:EditcountTag/code.js",
"w:c:dev:UserTags/code.js"
]
});
//User tags
window.UserTagsJS = {
modules: {},
tags: {
editmaster: { u:'JoJolion Head Editor', title:'This user is in charge of editting the JoJolion Articles' },
}
};
UserTagsJS.modules.custom = {
'Death-dodger is you!': ['editmaster'],
};
// insertusername
function UserNameReplace() {
if(typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || wgUserName == null) return;
$("span.insertusername").html(wgUserName);
}
addOnloadHook(UserNameReplace);
/* =============
MOS box
from Brickipedia
==============
This is the little box underneath the
search bar and article tally, which has the
Seal of Rassilon in it.
===============
Keep at end of common.js, but before
any addOnloadHooks.
================ */
importScript('MediaWiki:Common.js/mosbox.js');