MediaWiki:Common.js: Difference between revisions

From Moonlight Design
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 10: Line 10:
     var rows;
     var rows;
     for (var t = 0; t < tables.length; t++) {
     for (var t = 0; t < tables.length; t++) {
         if (tables[t].className.indexOf("software") >= 0) {
         if (tables[t].className.indexOf("software") >= 0 && tables[t].rows && tables[t].rows.length > 1) {
             grayRows(tables[t]);
             grayRows(tables[t]);


Line 19: Line 19:
                 if (rows[r].lastChild && rows[r].lastChild.previousSibling) {
                 if (rows[r].lastChild && rows[r].lastChild.previousSibling) {
                     var secondToLast = rows[r].lastChild.previousSibling;
                     var secondToLast = rows[r].lastChild.previousSibling;
                     secondToLast.style.width = "6em";
                     if (secondToLast.style) {
                    if (secondToLast.tagName.toLowerCase() == "td") {
                        secondToLast.style.width = "6em";
                        secondToLast.style.textAlign = "right";
                        if (secondToLast.tagName.toLowerCase() == "td") {
                    }
                            secondToLast.style.textAlign = "right";
                    if (secondToLast.previousSibling) {
                        }
                        secondToLast.previousSibling.style.width = "15em";
                        if (secondToLast.previousSibling) {
                            secondToLast.previousSibling.style.width = "15em";
                        }
                     }
                     }
                 }
                 }

Latest revision as of 16:37, 30 April 2011

/* Any JavaScript here will be loaded for all users on every page load. */

// Highlight every other line in the software tables
var orig_onload = window.onload;
window.onload = function(e) {
    if (orig_onload != null) {
        orig_onload(e);
    }
    var tables = document.getElementsByTagName("table");
    var rows;
    for (var t = 0; t < tables.length; t++) {
        if (tables[t].className.indexOf("software") >= 0 && tables[t].rows && tables[t].rows.length > 1) {
            grayRows(tables[t]);

            // Give the third-to-last cell a width of 15em (CSS lets us do this, but, sadly, browsers don't implement nth-child)
            // and the second-to-last cell a width of 6em
            rows = tables[t].rows;
            for (var r = 0; r < rows.length; r++) {
                if (rows[r].lastChild && rows[r].lastChild.previousSibling) {
                    var secondToLast = rows[r].lastChild.previousSibling;
                    if (secondToLast.style) {
                        secondToLast.style.width = "6em";
                        if (secondToLast.tagName.toLowerCase() == "td") {
                            secondToLast.style.textAlign = "right";
                        }
                        if (secondToLast.previousSibling) {
                            secondToLast.previousSibling.style.width = "15em";
                        }
                    }
                }
            }
        }
    }
}

function grayRows(table) {
    var rows = table.rows;
    for (var r = 0; r < rows.length; r++) {
        if (r % 2 == 1) {
            rows[r].className = "grayrow";
        } else {
            rows[r].className = "";
        }
    }
}

var orig_ts_resortTable = ts_resortTable;
ts_resortTable = function(evt) {
    orig_ts_resortTable(evt);

    // Find the table
    var table = evt;
    while (table && table.tagName.toLowerCase() != "table") {
        table = table.parentNode;
    }
    if (table && (table.className.indexOf("software") >= 0)) {
        grayRows(table);
    }
}