Difference between revisions of "MediaWiki:Jony.js"

From The iPhone Wiki
Jump to: navigation, search
m (meh)
m (i messed up)
 
(2 intermediate revisions by the same user not shown)
Line 8: Line 8:
 
// Automatically adds the "nobborderplz" class to applicable table cells
 
// Automatically adds the "nobborderplz" class to applicable table cells
 
function autoAddNoBBorderPlzClass() {
 
function autoAddNoBBorderPlzClass() {
var tables = $("table[class=wikitable]");
+
$(".wikitable").each(function () {
  +
var children = this.children;
 
  +
if (children.length > 0 && children[0].localName == "tbody")
for (var tableIdx = 0; tableIdx < tables.length; tableIdx++) {
 
var children = tables[tableIdx].children;
 
if (children.length > 0 && children[0].localName == "tbody") {
 
 
children = children[0].children; // skip the tbody tag
 
children = children[0].children; // skip the tbody tag
  +
}
 
 
var height = children.length;
 
var height = children.length;
 
for (var rowIdx = 0; rowIdx < height; rowIdx++) {
 
for (var rowIdx = 0; rowIdx < height; rowIdx++) {
Line 24: Line 22:
 
if (cell.rowSpan != 1 && cell.rowSpan == dist) {
 
if (cell.rowSpan != 1 && cell.rowSpan == dist) {
 
// this is the last cell in a column, and it has a rowspan reaching the bottom of the table
 
// this is the last cell in a column, and it has a rowspan reaching the bottom of the table
if (cell.className == undefined || cell.className == "") {
+
$(cell).addClass("nobborderplz");
cell.className = "nobborderplz";
 
} else {
 
cell.className = cell.className + " nobborderplz";
 
}
 
 
}
 
}
 
}
 
}
 
}
 
}
}
+
});
 
}
 
}
   
Line 41: Line 35:
 
var fixedCorner = false;
 
var fixedCorner = false;
 
var children = tables[tableIdx].children;
 
var children = tables[tableIdx].children;
if (children.length > 0 && children[0].localName == "tbody") {
+
if (children.length > 0 && children[0].localName == "tbody")
 
children = children[0].children; // skip the tbody tag
 
children = children[0].children; // skip the tbody tag
  +
}
 
 
var height = children.length;
 
var height = children.length;
 
for (var rowIdx = 0; rowIdx < height; rowIdx++) {
 
for (var rowIdx = 0; rowIdx < height; rowIdx++) {
Line 53: Line 47:
 
// this is the last cell in a row, and it has a rowspan reaching the bottom of the table
 
// this is the last cell in a row, and it has a rowspan reaching the bottom of the table
 
fixedCorner = true;
 
fixedCorner = true;
if (cell.style == undefined || cell.style == "") {
+
cell.style.borderBottomRightRadius = "6px";
cell.style = "border-bottom-right-radius: 6px";
 
} else {
 
cell.style = cell.style + ";border-bottom-right-radius: 6px";
 
}
 
 
}
 
}
 
}
 
}
Line 64: Line 54:
 
// unround the last row's last column's corner
 
// unround the last row's last column's corner
 
var lastRow = children[height - 1].children;
 
var lastRow = children[height - 1].children;
var lastColumnCell = lastRow[lastRow.length - 1];
+
lastRow[lastRow.length - 1].style.borderBottomRightRadius = "0px";
if (lastColumnCell.style == undefined || lastColumnCell.style == "") {
 
lastColumnCell.style = "border-bottom-right-radius: 0px";
 
} else {
 
lastColumnCell.style = lastColumnCell.style + ";border-bottom-right-radius: 0px";
 
}
 
 
}
 
}
 
}
 
}
Line 80: Line 65:
 
var fixedCorner = false;
 
var fixedCorner = false;
 
var children = tables[tableIdx].children;
 
var children = tables[tableIdx].children;
if (children.length > 0 && children[0].localName == "tbody") {
+
if (children.length > 0 && children[0].localName == "tbody")
 
children = children[0].children; // skip the tbody tag
 
children = children[0].children; // skip the tbody tag
  +
}
 
 
var height = children.length;
 
var height = children.length;
 
for (var rowIdx = 0; rowIdx < height; rowIdx++) {
 
for (var rowIdx = 0; rowIdx < height; rowIdx++) {
Line 92: Line 77:
 
// this is the first cell in a row, and it has a rowspan reaching the bottom of the table
 
// this is the first cell in a row, and it has a rowspan reaching the bottom of the table
 
fixedCorner = true;
 
fixedCorner = true;
if (cell.style == undefined || cell.style == "") {
+
cell.style.borderBottomLeftRadius = "6px";
cell.style = "border-bottom-left-radius: 6px";
 
} else {
 
cell.style = cell.style + ";border-bottom-left-radius: 6px";
 
}
 
 
}
 
}
 
}
 
}
Line 104: Line 85:
 
var lastRow = children[height - 1].children;
 
var lastRow = children[height - 1].children;
 
var firstColumnCell = lastRow[0];
 
var firstColumnCell = lastRow[0];
if (firstColumnCell.style == undefined || firstColumnCell.style == "") {
+
lastRow[0].style.borderBottomLeftRadius = "0px";
firstColumnCell.style = "border-bottom-left-radius: 0px";
 
} else {
 
firstColumnCell.style = firstColumnCell.style + ";border-bottom-left-radius: 0px";
 
}
 
 
}
 
}
 
}
 
}

Latest revision as of 21:31, 28 November 2018

/**
 * The iPhone Wiki MediaWiki:jony.js
 *   - JavaScript to fix issues regarding the Jony theme
 * Copyright (c) 2013-2018 Cole Johnson <coleharrisjohnson@gmail.com>
 * Licensed under CC BY-SA 4.0 <http://creativecommons.org/licenses/by-sa/4.0/>
 **/

// Automatically adds the "nobborderplz" class to applicable table cells
function autoAddNoBBorderPlzClass() {
    $(".wikitable").each(function () {
        var children = this.children;
        if (children.length > 0 && children[0].localName == "tbody")
            children = children[0].children; // skip the tbody tag

        var height = children.length;
        for (var rowIdx = 0; rowIdx < height; rowIdx++) {
            var row = children[rowIdx].children;
            var width = row.length; // not true number of columns if there's a rowspan spanning through
            var dist = height - rowIdx;
            for (var colIdx = 0; colIdx < width; colIdx++) {
                var cell = row[colIdx];
                if (cell.rowSpan != 1 && cell.rowSpan == dist) {
                    // this is the last cell in a column, and it has a rowspan reaching the bottom of the table
                    $(cell).addClass("nobborderplz");
                }
            }
        }
    });
}

function fixBottomRightTableCorners() {
    var tables = $("table[class=wikitable]");
    
    for (var tableIdx = 0; tableIdx < tables.length; tableIdx++) {
        var fixedCorner = false;
        var children = tables[tableIdx].children;
        if (children.length > 0 && children[0].localName == "tbody")
            children = children[0].children; // skip the tbody tag

        var height = children.length;
        for (var rowIdx = 0; rowIdx < height; rowIdx++) {
            var row = children[rowIdx].children;
            var width = row.length; // not true number of columns if there's a rowspan spanning through
            var dist = height - rowIdx;
            var cell = row[width - 1];
            if (cell.rowSpan != 1 && cell.rowSpan == dist) {
                // this is the last cell in a row, and it has a rowspan reaching the bottom of the table
                fixedCorner = true;
                cell.style.borderBottomRightRadius = "6px";
            }
        }
        
        if (fixedCorner) {
            // unround the last row's last column's corner
            var lastRow = children[height - 1].children;
            lastRow[lastRow.length - 1].style.borderBottomRightRadius = "0px";
        }
    }
}

function fixBottomLeftTableCorners() {
    var tables = $("table[class=wikitable]");
    
    for (var tableIdx = 0; tableIdx < tables.length; tableIdx++) {
        var fixedCorner = false;
        var children = tables[tableIdx].children;
        if (children.length > 0 && children[0].localName == "tbody")
            children = children[0].children; // skip the tbody tag

        var height = children.length;
        for (var rowIdx = 0; rowIdx < height; rowIdx++) {
            var row = children[rowIdx].children;
            //var width = row.length; // not true number of columns if there's a rowspan spanning through
            var dist = height - rowIdx;
            var cell = row[0];
            if (cell.rowSpan != 1 && cell.rowSpan == dist) {
                // this is the first cell in a row, and it has a rowspan reaching the bottom of the table
                fixedCorner = true;
                cell.style.borderBottomLeftRadius = "6px";
            }
        }
        
        if (fixedCorner) {
            // unround the last row's first column's corner
            var lastRow = children[height - 1].children;
            var firstColumnCell = lastRow[0];
            lastRow[0].style.borderBottomLeftRadius = "0px";
        }
    }
}

autoAddNoBBorderPlzClass();
fixBottomRightTableCorners();
fixBottomLeftTableCorners();