User:Gary Queen/layout.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. |
![]() | Documentation for this user script can be added at User:Gary Queen/layout. |
/*
hook
*/
addOnloadHook(function()
{
/*
variables
*/
content = $('content');
bodyContent = $('bodyContent');
cactions = $('p-cactions');
caEdit = $('ca-edit');
caMain = $('ca-nstab-main');
contentSub = $('contentSub');
diff = content.getElementsByClassName('diff')[0];
globalWrapper = $('globalWrapper');
h2 = content.getElementsByTagName('h2');
jumpToNav = $('jump-to-nav');
afterJumpToNav = jumpToNav.nextSibling.nextSibling.nextSibling.nextSibling;
paragraphs = content.getElementsByTagName('p');
pBody = $('p-personal').getElementsByClassName('pBody')[0];
pendingChanges = $('mw-fr-revisiontag');
pPersonal = $('p-personal')
relLinks = content.getElementsByClassName('rellink');
section0 = $('section-0');
siteSub = $('siteSub');
toc = $('toc');
tPrint = $('t-print');
userMessages = content.getElementsByClassName('usermessage');
wikiPreview = $('wikiPreview');
wikitables = content.getElementsByClassName('wikitable');
pagesLayout();
});
/*
useful functions
*/
function $(element)
{
return document.getElementById(element);
}
Object.prototype.addClass = function(newClass)
{
element = this;
if (element.className)
{
classes = element.className.split(' ');
classes.push(newClass);
return element.className = classes.join(' ');
}
else return element.className = newClass;
}
Object.prototype.hasClass = function(classToCheck)
{
element = this;
if (!element.className) return false;
classes = element.className.split(' ');
for (var i = 0; i < classes.length; i++)
{
if (classes[i] == classToCheck)
return true;
}
return false;
}
Object.prototype.removeClass = function(oldClass)
{
element = this;
if (!element.className) return false;
classes = element.className.split(' ');
newClasses = [];
for (var i = 0; i < classes.length; i++)
{
if (classes[i] != oldClass)
newClasses.push(classes[i]);
}
return element.className = newClasses;
}
String.prototype.trim = function()
{
return this.replace(/^[\s|\n]+|[\s|\n]+$/g, '');
}
String.prototype.ltrim = function()
{
return this.replace(/^[\s|\n]+/, '');
}
String.prototype.rtrim = function()
{
return this.replace(/[\s|\n]+$/, '');
}
/*
do page layout
*/
function pagesLayout()
{
/*
Layout
*/
// Fatter pages except when it would exceed page width
if (window.innerWidth > 1425) globalWrapper.style.width = cactions.style.width = pBody.style.width = '1400px';
else globalWrapper.style.width = cactions.style.width = pBody.style.width = (window.innerWidth - 25) + 'px';
// Thinner page width for articles (1000 pixels wide)
var thinnerPage = false;
var fatterPage = false;
// TODO fatterPages
// fatterPageTerms
if (typeof(fatterPageTerms) == 'object' && fatterPageTerms.length > 0)
{
for (var i = 0; i < fatterPageTerms.length; i++)
{
if (wgPageName.replace(/_/g, ' ').indexOf(fatterPageTerms[i]) != -1)
{
fatterPage = true;
break;
}
}
}
// thinnerPages
if (typeof(thinnerPages) == 'object' && thinnerPages.length > 0)
{
for (var i = 0; i < thinnerPages.length; i++)
{
if (wgPageName.indexOf(thinnerPages[i].replace(/ /g, '_')) == 0)
{
thinnerPage = true;
break;
}
}
}
// TODO thinnerPageTerms
// Thinner pages for articles
if (window.innerWidth > 1025 && fatterPage == false && (wgCanonicalNamespace == '' || thinnerPage) && (wgAction == 'view' || wgAction == 'submit' || wgAction == 'edit' || wgAction == 'purge') && (location.href.indexOf('title=') && location.href.indexOf('diff=')) == -1 && !(wgCanonicalNamespace == '' && wgTitle == wgMainPageTitle))
globalWrapper.style.width = cactions.style.width = pBody.style.width = '1000px';
// Shorter search text (searchGoButton, mw-searchButton)
$('searchGoButton').value = 'G';
$('mw-searchButton').value = 'S';
// remove the extra space after editsections
var editSections = document.getElementsByClassName('editsection');
var nextSibling;
for (var i = 0; i < editSections.length; i++)
{
nextSibling = editSections[i].nextSibling;
if (nextSibling && nextSibling.nodeType == 3 && nextSibling.nodeValue == ' ')
nextSibling.parentNode.removeChild(nextSibling);
}
}