Difference between revisions of "MediaWiki:Jony.js"

From The iPhone Wiki
Jump to: navigation, search
m
Line 2: Line 2:
 
* The iPhone Wiki MediaWiki:ios7.js
 
* The iPhone Wiki MediaWiki:ios7.js
 
* - JavaScript to fix issues regarding the iOS 7 theme
 
* - JavaScript to fix issues regarding the iOS 7 theme
* Copyright (c) 2013 Cole Johnson <coleharrisjohnson@gmail.com>
+
* Copyright (c) 2013-2015 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 3.0 <http://creativecommons.org/licenses/by-sa/3.0/>
 
**/
 
**/
Line 12: Line 12:
 
 
 
// "table" appears to have another purpose (at least in Chrome's console)
 
// "table" appears to have another purpose (at least in Chrome's console)
for (var tabel = 0; tabel < tables.length; tabel++) {
+
for (var tableIdx = 0; tableIdx < tables.length; tableIdx++) {
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;
 
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
 
var dist = height - tr;
+
for (var colIdx = 0; colIdx < width; colIdx++) {
for (var td = 0; td < width; td++) {
+
var cell = row[colIdx];
var this_cell = row[td];
+
if (cell.rowSpan != 1 && cell.rowSpan == dist) {
if (this_cell.rowSpan != 1 && this_cell.rowSpan == dist) {
 
 
// this is the last cell in a column, and it has a rowspan
 
// this is the last cell in a column, and it has a rowspan
if (this_cell.className == undefined || this_cell.className == "") {
+
if (cell.className == undefined || cell.className == "") {
this_cell.className = "nobborderplz";
+
cell.className = "nobborderplz";
 
} else {
 
} else {
this_cell.className = this_cell.className + " nobborderplz";
+
cell.className = cell.className + " nobborderplz";
 
}
 
}
 
}
 
}

Revision as of 18:19, 13 January 2015

/**
 * The iPhone Wiki MediaWiki:ios7.js
 *   - JavaScript to fix issues regarding the iOS 7 theme
 * Copyright (c) 2013-2015 Cole Johnson <coleharrisjohnson@gmail.com>
 * Licensed under CC BY-SA 3.0 <http://creativecommons.org/licenses/by-sa/3.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
function autoAddNoBBorderPlzClass() {
    var tables = $("table[class=wikitable]");
    
    // "table" appears to have another purpose (at least in Chrome's console)
    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";
                    }
                }
            }
        }
    }
}

// If on an iPhone or iPod touch, add some custom CSS tweaks
function addMobileTweaks() {
    // Should probably switch to using http://detectmobilebrowsers.com/
    if (navigator.userAgent.match(/iP(od|hone)/) != undefined) {
        var elem = document.createElement("link");
        elem.rel = "stylesheet";
        elem.href = "http://theiphonewiki.com/w/index.php?title=MediaWiki:Ios7.css/mobile&action=raw";
        document.head.appendChild(elem);
    }
}

autoAddNoBBorderPlzClass();
addMobileTweaks();