MediaWiki:Gadget-lefteditlinks.js

From OpenWetWare

Jump to: navigation, search

Note - After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh); Konqueror: click Reload or press F5; Opera: clear the cache in Tools → Preferences; Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

/*  _____________________________________________________________________________
 * |                                                                             |
 * |                    === WARNING: GLOBAL GADGET FILE ===                      |
 * |                  Changes to this page affect many users.                    |
 * | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. |
 * |_____________________________________________________________________________|
 *
 * Moves edit links next to section headers, see [[User:Drilnoth/lefteditlinks.js/doc]]
*/
 
// user customizable variables via monobook.js:
 
// font-size css definition for edit link span
if (typeof(leftEditLinkFontSize) == 'undefined') { var leftEditLinkFontSize = 'small'; }
 
// css definition for spacing after heading text span
if (typeof(leftEditLinkSpacing) == 'undefined') { var leftEditLinkSpacing = '0.2em'; }
 
 
// main program
var LeftEditLinkMain = function() {
 
// recursively fix all spans inside headings
    var content = document.getElementById('content');
    var LeftEditLink = function(level) {
 
// get all heading of this level
        var headings = content.getElementsByTagName('h' + level);
        for (var i = 0; i < headings.length; i ++) {
            var heading = headings[i];
 
// get edit span
            var editSpan = heading.firstChild;
            if (editSpan == null) { continue }
            if (editSpan.className != 'editsection') { continue }
 
// get blank
            var blank = editSpan.nextSibling;
            if (blank == null) { continue }
            if (blank.nodeValue != ' ') { continue }
 
// get heading span
            var headingSpan = blank.nextSibling;
            if (headingSpan == null) { continue }
            if (headingSpan.nodeName != 'SPAN') { continue }
 
// move blank after heading text
            heading.appendChild(blank);
 
// move edit span after blank
            heading.appendChild(editSpan);
 
// get rid of evil edit span floating
            editSpan.style.styleFloat = 'none';
            editSpan.style.cssFloat = 'none';
 
// set edit span font size
            editSpan.style.fontSize = leftEditLinkFontSize;
 
// set heading span right margin
            headingSpan.style.marginRight = leftEditLinkSpacing;
        }
 
// recurse through heading levels
        if (level < 6) {
            LeftEditLink(level + 1);
        }
        return;
    };
 
// call recursive function
    LeftEditLink(1);
 
};
 
addOnloadHook(LeftEditLinkMain);
Personal tools