Difference between revisions of "MediaWiki:Jony.js"

From The iPhone Wiki
Jump to: navigation, search
(Created page with "/** * The iPhone Wiki MediaWiki:ios7.js * - JavaScript to fix issues regarding the iOS 7 theme * Copyright (c) 2013 Cole Johnson <coleharrisjohnson@gmail.com> * Licensed...")
 
m (i messed up)
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
/**
 
/**
* The iPhone Wiki MediaWiki:ios7.js
+
* The iPhone Wiki MediaWiki:jony.js
* - JavaScript to fix issues regarding the iOS 7 theme
+
* - JavaScript to fix issues regarding the Jony theme
* Copyright (c) 2013 Cole Johnson <coleharrisjohnson@gmail.com>
+
* Copyright (c) 2013-2018 Cole Johnson <coleharrisjohnson@gmail.com>
* Licensed under CC BY-SA 3.0 <http://creativecommons.org/licenses/by-sa/3.0/>
+
* Licensed under CC BY-SA 4.0 <http://creativecommons.org/licenses/by-sa/4.0/>
 
**/
 
**/
   
// This function exists also at [[MediaWiki:ios6.js]], so if you change it here, change it there also (be sure to test on both skins seperatly first)
 
 
// Automatically adds the "nobborderplz" class to applicable table cells
 
// Automatically adds the "nobborderplz" class to applicable table cells
 
function autoAddNoBBorderPlzClass() {
 
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]");
 
var tables = $("table[class=wikitable]");
 
 
  +
for (var tableIdx = 0; tableIdx < tables.length; tableIdx++) {
// "table" appears to have another purpose (at least in Chrome's console)
 
  +
var fixedCorner = false;
for (var tabel = 0; tabel < tables.length; tabel++) {
 
var children = tables[tabel].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;
  +
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;
 
var height = children.length;
for (var tr = 0; tr < height; tr++) {
+
for (var rowIdx = 0; rowIdx < height; rowIdx++) {
var row = children[tr].children;
+
var row = children[rowIdx].children;
var width = row.length;
+
//var width = row.length; // not true number of columns if there's a rowspan spanning through
  +
var dist = height - rowIdx;
// on a four row table, the second row, this equation will be "3 - 1" (0 based) or 2
 
  +
// this is the first cell in a row, and it has a rowspan reaching the bottom of the table
var this_cell = row[td];
 
var dist = height - tr;
+
var cell = row[0];
for (var td = 0; td < width; td++) {
+
if (cell.rowSpan != 1 && cell.rowSpan == dist) {
if (this_cell.rowSpan != 1 && this_cell.rowSpan == dist) {
+
fixedCorner = true;
// this is the last cell in a column, and it has a rowspan
+
cell.style.borderBottomLeftRadius = "6px";
if (this_cell.className == undefined || this_cell.className == "") {
 
this_cell.className = "nobborderplz";
 
} else {
 
this_cell.className = this_cell.className + " nobborderplz";
 
}
 
}
 
 
}
 
}
  +
}
  +
  +
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";
 
}
 
}
 
}
 
}
Line 39: Line 91:
   
 
autoAddNoBBorderPlzClass();
 
autoAddNoBBorderPlzClass();
  +
fixBottomRightTableCorners();
  +
fixBottomLeftTableCorners();

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();