User:Nihiltres/vector.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | The accompanying .css page for this skin is at User:Nihiltres/vector.css. |
//DEFINE STUFF IN ITS OWN LITTLE HIERARCHY HERE (hierarchy currently messy, needs cleanup, but better than raw code floating around)
nothingthree = {
util: {
linkFix: function(id, text) {
// Tab name fixer, originally copied from User:Anomie/fix-tab-text.js, credit to Anomie :)
/* A simple javascript function to change the text in various tabs at the top of the
* page.
*/
var el=document.getElementById(id);
if (!el) return;
for(el=el.firstChild; el && el.nodeName!='A'; el=el.nextSibling);
if(!el) return;
while(el.firstChild) el.removeChild(el.firstChild);
el.appendChild(document.createTextNode(text));
}, //end linkfix
cookie: { //These cookie functions are copied from [[User:Quarl/cookie.js]], which as of the copy had only been edited by Quarl.
set: function(name, value, days, path) { //Creates a given cookie.
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
} //end if
else {var expires = "";}
// use path="" for no path; path=null defaults to root
if (path == null) {path = "/";}
if (path) {path = "; path="+path;}
else {path = "";}
document.cookie = name + "=" + value + expires + path;
}, //end set
get: function(name) { //Gets a stored cookie.
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) {return c.substring(nameEQ.length,c.length);}
} //end for
return null;
}, //end get
erase: function(name) { //Deletes a stored cookie.
createCookie(name,"",-1);
} //end erase
}, //end cookie
isMobile: function() { //really rather basic mobile-device detection here, but can be improved as needed. Mostly useful for tidy code.
if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) {return true;}
else {return false;}
}, //end isMobile
rmClass: function(classRemovalObject, rmClass) { //Removes a given class from an object and strips whitespace from the ends of the class string.
if (!classRemovalObject) {return;}
if (classRemovalObject.className.indexOf(rmClass) == -1) {return;}
else {
rmClassRegex = new RegExp ("(^" + rmClass + "($| )| " + rmClass + "($|(?= )))", "igm");
classRemovalObject.className = classRemovalObject.className.replace(rmClassRegex, "");
whiteSpaceStrippingRegex = new RegExp ("(^ *| *$)", "igm");
classRemovalObject.className = classRemovalObject.className.replace(whiteSpaceStrippingRegex, "");
} //end else
} //end rmClass
}, //end util
tabAdd: { //Collection of independent tab-addition routines.
log: function() {
//Adds a link to the log of actions performed by the user. Mainly useful for administrators.
addPortletLink('p-personal','/wiki/Special:Log?user=' + wgUserName,'Log','pt-log','Log of your non-edit actions','',document.getElementById('pt-mycontris'));
if (wgPageName == "Special:Log" && document.getElementById('mw-log-user').value == wgUserName) {document.getElementById('pt-log').className='active';}
}, //end log
sandbox: function() {
//Adds a link to the user's very own sandbox page, where the sandbox is equivalent to [[Special:MyPage/Sandbox]].
addPortletLink('p-personal','/wiki/User:' + wgUserName +'/Sandbox','Sandbox','pt-sandbox','Your sandbox','',document.getElementById('pt-preferences'));
if (wgPageName == 'User:' + wgUserName + '/Sandbox') {document.getElementById('pt-sandbox').className='active'; }
}, //end sandbox
purge: function() {
//Adds a link to purge the current page.
if (wgCanonicalNamespace != 'Special') {
addPortletLink('p-cactions', wgServer + wgScript + '?title=' + encodeURI(wgPageName) + '&action=purge', 'Purge', 'ca-purge', 'Purge the server cache of this page', null, (document.getElementById('ca-watch') ? document.getElementById('ca-watch') : document.getElementById('ca-unwatch')));
} //end if
// if (wgAction == "purge") {document.getElementById('ca-purge').className='selected';}
// above is disabled as it doesn't make sense in Vector, but I *should* write some stuff so that it works when it's in p-views.
} //end purge
}, //end tabAdd
watchMediawikiSpaceEdits: function() { //Automatically checks the "Watch this page" button when editing MediaWiki-namespace pages.
if (wgCanonicalNamespace == 'MediaWiki' && wgAction == "edit") {document.getElementById('wpWatchthis').checked = true;}
}, //end watchMediawikiSpaceEdits
tabMove: { //Tab-moving routines, and custom bits that make use of them.
core: function(id, followingElement) { //THIS BIT IS REALLY, REALLY UGLY. I want to use the Usability team one as soon as I can make it work properly. Does the actual moving part, for moving actions out of the menu.
var itemToBeMoved = document.getElementById(id);
if (!itemToBeMoved || !document.getElementById("p-views") ) return;
document.getElementById("p-views").getElementsByTagName("ul")[0].insertBefore(document.getElementById(id), document.getElementById(followingElement));
itemToBeMoved.firstChild.innerHTML = "<span>" + itemToBeMoved.firstChild.innerHTML + "</span>"; //so that it looks pretty… :|
}, //end core
protection: function() {
//if the page is protected, show the unprotect button; serves also as an indicator for protection, indicating the value in the title. Disabled on iPod as generally unhelpful there.
if ( (wgRestrictionEdit.concat( wgRestrictionMove )).length > 0 ) {
nothingthree.tabMove.core("ca-unprotect", "ca-history");
if ( wgRestrictionEdit.length > 0 ) {
var EditRestrictionString = "edit: [" + wgRestrictionEdit.join(", ") + "]";
}
else {
var EditRestrictionString = "";
}
if ( wgRestrictionMove.length > 0 ) {
var MoveRestrictionString = "move: [" + wgRestrictionMove.join(", ") + "]";
}
else {
var MoveRestrictionString = "";
}
var RestrictionStringsArray = new Array();
if (EditRestrictionString != "") {
RestrictionStringsArray.push(EditRestrictionString)
}
if (MoveRestrictionString != "") {
RestrictionStringsArray.push(MoveRestrictionString)
}
document.getElementById("ca-unprotect").firstChild.title = ("Unprotect this page (" + RestrictionStringsArray.join(", ") + ")");
}
}, //end protection
deletion: function() { //If the page contains a deletion template, or a redlinked redirect, move out the delete tab. If it's a redlinked redirect, give an automatic, useful deletion summary.
if (document.getElementsByClassName("ambox-speedy").length >= 1 || document.getElementsByClassName("ambox-delete").length >= 1 || document.getElementsByClassName("ombox-speedy").length >= 1 || document.getElementsByClassName("ombox-delete").length >= 1 || document.getElementsByClassName("imbox-speedy").length >= 1 || document.getElementsByClassName("imbox-delete").length >= 1 || document.getElementsByClassName("cmbox-speedy").length >= 1 || document.getElementsByClassName("cmbox-delete").length >= 1 || document.getElementsByClassName("tmbox-speedy").length >= 1 || document.getElementsByClassName("tmbox-delete").length >= 1 ) {
nothingthree.tabMove.core("ca-delete", "ca-history");
}
else { //This part handles the redirect case, if applicable.
if (document.getElementsByClassName("redirectText").length == false) return;
if (document.getElementsByClassName("redirectText").item(0).firstChild.href.search("redlink=1") != -1) {
nothingthree.tabMove.core("ca-delete", "ca-history");
var cadeletelinks = document.getElementById("ca-delete").getElementsByTagName("a");
if (cadeletelinks.length != 1) return;
cadeletelinks.item(0).href = cadeletelinks.item(0).href + "&wpReason=%5B%5BWP%3ACSD%23G8%7CG8%5D%5D%3A%20Redirect%20to%20a%20deleted%20page";
} //end if
} //end else
}, //end deletion
watch: function() { //This bit moves the watch tab back into the menu after removing its icon status. Quick and dirty. Should fail silently if applicable.
try {
nothingthree.util.rmClass((document.getElementById('ca-watch') ? document.getElementById('ca-watch') : document.getElementById('ca-unwatch')), "icon");
document.getElementById("p-cactions").getElementsByClassName("menu")[0].firstElementChild.appendChild((document.getElementById('ca-watch') ? document.getElementById('ca-watch') : document.getElementById('ca-unwatch')));
} //end try
catch(err) {return;}
} //end watch
}, //end tabMove
sidebar: { //A collection of functions for playing with the sidebar, mostly to collapse or expand it.
collapse: function() { //Collapses the sidebar.
var ct = document.getElementById("content");
var ln = document.getElementById("left-navigation");
var pn = document.getElementById("panel");
var hb = document.getElementById("head-base");
var ft = document.getElementById("footer");
if (!ct || !ln || !pn || !hb || !ft) return;
pn.style.display = "none";
ct.style.marginLeft = "0";
ct.style.backgroundImage = "none";
hb.style.marginLeft = "0";
ft.style.marginLeft = "0";
ln.style.left = "1em";
nothingthree.util.cookie.set("sideBarCollapsed", "collapsed", "365", null);
if (!document.getElementById("ca-sidebar")) {return;}
else {
var cs = document.getElementById("ca-sidebar");
cs.firstChild.href = "javascript:nothingthree.sidebar.expand()"
} //end else
}, //end collapse
expand: function() { //Expands the sidebar.
var ct = document.getElementById("content");
var ln = document.getElementById("left-navigation");
var pn = document.getElementById("panel");
var hb = document.getElementById("head-base");
var ft = document.getElementById("footer");
if (!ct || !ln || !pn || !hb || !ft) return;
pn.style.display = "block";
ct.style.marginLeft = "10em";
ct.style.backgroundImage = "url('http://bits.wikimedia.org/skins-1.5/vector/images/border.png')";
hb.style.marginLeft = "10em";
ft.style.marginLeft = "10em";
ln.style.left = "10em";
nothingthree.util.cookie.set("sideBarCollapsed", "expanded", "365", null);
if (!document.getElementById("ca-sidebar")) {return;}
else {
var cs = document.getElementById("ca-sidebar");
cs.firstChild.href = "javascript:nothingthree.sidebar.collapse()"
} //end else
}, //end expand
toggleTab: function() { //Adds a tab to the menu to allow the collapsed status to be easily toggled.
addPortletLink('p-cactions', 'javascript:nothingthree.sidebar.collapse()', 'Toggle sidebar', 'ca-sidebar', 'Hide or show the sidebar', null, 'ca-purge');
}, //end toggleTab
remember: function() { //Collapses the sidebar if it was previously collapsed.
if (nothingthree.util.cookie.get("sideBarCollapsed") == "collapsed") {nothingthree.sidebar.collapse();}
} //end remember
}, //end sidebar
tops: { //A collection of functions designed to allow the visibility of (top) edits on contribution pages to be toggled.
hide: function() { //Hides (top) edits.
var cul = document.getElementById("bodyContent").getElementsByTagName("ul")[0];
var cli = cul.getElementsByTagName("li");
var lin = 0;
for (lin=0; lin < cli.length; lin++) {
if (cli[lin].innerHTML.indexOf('<span class="mw-uctop">') != -1) {
cli[lin].style.visibility = "hidden";
} //end if
} //end for
if (!document.getElementById("ca-tops")) {return;}
else {
document.getElementById("ca-tops").firstChild.href = "javascript:nothingthree.tops.show()";
}
}, //end hide
show: function() { //Shows (top) edits.
var cul = document.getElementById("bodyContent").getElementsByTagName("ul")[0];
var cli = cul.getElementsByTagName("li");
var lin = 0;
for (lin=0; lin < cli.length; lin++) {
if (cli[lin].innerHTML.indexOf('<span class="mw-uctop">') != -1) {
cli[lin].style.visibility = "visible";
} //end if
} //end for
if (!document.getElementById("ca-tops")) {return;}
else {
document.getElementById("ca-tops").firstChild.href = "javascript:nothingthree.tops.hide()";
}
}, //end show
toggleTab: function() { //Adds a tab to the menu allowing the visibility of (top) edits to be toggled.
if (document.body.className.indexOf("page-Special_Contributions") != -1 ) {
addPortletLink('p-cactions', 'javascript:nothingthree.tops.hide()', 'Toggle (top) entries', 'ca-tops', 'Hide or show the (top) entries', null, 'ca-sidebar');
} //end if
} //end toggleTab
} //end tops
} //end nothingthree
//ENABLE STUFF FOR USE HERE
addOnloadHook(function() {
if (!nothingthree.util.isMobile() ) { //in the usual case…
//First, fix some links, using linkFix
nothingthree.util.linkFix('pt-preferences', 'Preferences');
nothingthree.util.linkFix('pt-watchlist', 'Watchlist');
nothingthree.util.linkFix('pt-mytalk', 'Talk');
nothingthree.util.linkFix('pt-mycontris', 'Contributions');
//Second, add the tabs as desired
nothingthree.tabAdd.log();
nothingthree.tabAdd.sandbox();
nothingthree.tabAdd.purge();
//Some miscellaneous additions…
nothingthree.watchMediawikiSpaceEdits();
nothingthree.tabMove.protection();
nothingthree.tabMove.deletion();
nothingthree.sidebar.toggleTab();
nothingthree.sidebar.remember();
nothingthree.tops.toggleTab();
nothingthree.tabMove.watch();
}
else { //if it's a mobile browser as defined by nothingthree.util.isMobile() …
//Mobile-specific CSS! (Mobile-specific JS is handled here.)
importStylesheet('User:' + wgUserName + '/vector-ipod.css');
//the next bit *would be* importScript('User:' + wgUserName + '/vector-ipod.css'); …
nothingthree.util.linkFix('pt-preferences', 'Preferences');
nothingthree.util.linkFix('pt-watchlist', 'Watchlist');
nothingthree.util.linkFix('pt-mytalk', 'Talk');
nothingthree.util.linkFix('pt-mycontris', 'Contributions');
//Second, add the tabs as desired
nothingthree.tabAdd.log();
nothingthree.tabAdd.sandbox();
nothingthree.tabAdd.purge();
//Some miscellaneous additions…
nothingthree.watchMediawikiSpaceEdits();
nothingthree.tabMove.protection();
nothingthree.tabMove.deletion();
nothingthree.sidebar.collapse();
nothingthree.sidebar.toggleTab();
}
});