/* I Hate Floating Icons, No One Should Ever Rely On the h1.firstHeading Location, version [0.0.0]
Originally from: http://en.wikipedia.org/wiki/User:Splarka/topiconfix.js
This is a dirty dirty hack. A much more comprehenstive and all-skin-encompassing solution should be worked out.
But not by me. Ugh.
This checks for
* No sitenotice
* h1.firstHeading
** id="coordinates"
** id="protected-icon"
** all class="topicon"
And then removes the things giving it vague h1.firstHeading positions and inserts them into the h1 simply floating.
This encompasses the following templates (which will break when anything changes in them):
* [[Template:Coor at d]] [[Template:Coor at dm]] [[Template:Coor at dms]] [[Template:Coor title d]]
* [[Template:Coor title dm]] [[Template:Coor title dms]] [[Template:Core article]] [[Template:Featured article]]
* [[Template:Featured list]] [[Template:Featured portal]] [[Template:FeaturedPicture]] [[Template:FeaturedPictureSet]]
* [[Template:FeaturedSound]] [[Template:Pp-meta]] [[Template:Pp-meta/sandbox]] [[Template:Spoken Wikipedia boilerplate]]
*/
if((wgAction == 'edit' || wgAction == 'view') && wgNamespaceNumber > -1) addOnloadHook(fixTopiconSucky)
function fixTopiconSucky() {
if(!document.getElementById('siteNotice') && !window.siteNoticeValue && !window.wgNotice) return
var h1 = getElementsByClassName(document,'h1','firstHeading');
if(h1.length == 0) return //lol wut
h1 = h1[0];
var coord = document.getElementById('coordinates');
if(coord) {
appendCSS('h1.firstHeading #coordinatesH1 {border: none;background: none;float: right;margin: 0.0em;padding: 0.0em;line-height: 1.5em;text-align: right;text-indent: 0;font-size: 45%;text-transform: none;white-space: nowrap;}')
var nc = coord.cloneNode(true);
coord.parentNode.removeChild(coord);
nc.id = 'coordinatesH1';
h1.appendChild(nc); // stick at the end
}
appendCSS('h1.firstHeading .topiconJS {float:right; display: block !important;margin-right:4px;}')
var prot = document.getElementById('protected-icon');
if(prot) {
var np = prot.cloneNode(true);
prot.parentNode.removeChild(prot);
np.style.position = '';
np.style.right = '';
np.style.top = '';
np.className += ' topiconJS';
try {
h1.insertBefore(np,h1.firstChild);
} catch (e) {
h1.appendChild(np);
}
}
var topi = getElementsByClassName(document,'*','topicon');
for(var i=topi.length-1;i>=0;i--) /* work backwards when removing */ {
var nt = topi[i].cloneNode(true);
topi[i].parentNode.removeChild(topi[i]);
nt.className = nt.className.replace(/topicon/ig,'topiconJS');
nt.style.right = '';
try {
h1.insertBefore(nt,h1.firstChild);
} catch (e) {
h1.appendChild(nt);
}
}
}