Difference between revisions of "MediaWiki:Jony.js"

From The iPhone Wiki
Jump to: navigation, search
m (begin work on fixing rounded table corners)
Line 36: Line 36:
   
 
function fixRoundedTableCorners() {
 
function fixRoundedTableCorners() {
/* border-bottom-right-radius: 6px */
 
 
var tables = $("table[class=wikitable]");
 
var tables = $("table[class=wikitable]");
 
 
Line 43: Line 42:
 
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;
  +
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
  +
if (cell.style == undefined || cell.style == "") {
  +
cell.style = "border-bottom-right-radius: 6px";
  +
} else {
  +
cell.style = cell.style + ";border-bottom-right-radius: 6px";
  +
}
  +
}
  +
}
 
}
 
}
 
}
 
}
Line 48: Line 64:
   
 
autoAddNoBBorderPlzClass();
 
autoAddNoBBorderPlzClass();
  +
fixRoundedTableCorners();

Revision as of 19:09, 10 October 2018

/**
 * The iPhone Wiki MediaWiki:jony.js
 *   - JavaScript to fix issues regarding the iOS 7 theme
 * Copyright (c) 2013-2017 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() {
    var tables = $("table[class=wikitable]");
    
    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
        }
        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
                    if (cell.className == undefined || cell.className == "") {
                        cell.className = "nobborderplz";
                    } else {
                        cell.className = cell.className + " nobborderplz";
                    }
                }
            }
        }
    }
}

function fixRoundedTableCorners() {
    var tables = $("table[class=wikitable]");
    
    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
        }
        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
                    if (cell.style == undefined || cell.style == "") {
                        cell.style = "border-bottom-right-radius: 6px";
                    } else {
                        cell.style = cell.style + ";border-bottom-right-radius: 6px";
                    }
                }
            }
        }
    }
}

autoAddNoBBorderPlzClass();
fixRoundedTableCorners();