MediaWiki:Jony.js

From The iPhone Wiki
Revision as of 22:14, 7 January 2015 by 5urd (talk | contribs)
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/**
 * The iPhone Wiki MediaWiki:ios7.js
 *   - JavaScript to fix issues regarding the iOS 7 theme
 * Copyright (c) 2013 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 tabel = 0; tabel < tables.length; tabel++) {
        var children = tables[tabel].children;
        if (children.length > 0 && children[0].localName == "tbody") {
            children = children[0].children; // skip the tbody tag
        }
        var height = children.length;
        for (var tr = 0; tr < height; tr++) {
            var row = children[tr].children;
            var width = row.length;
            // on a four row table, the second row, this equation will be "3 - 1" (0 based) or 2
            var dist = height - tr;
            for (var td = 0; td < width; td++) {
                var this_cell = row[td];
                if (this_cell.rowSpan != 1 && this_cell.rowSpan == dist) {
                    // this is the last cell in a column, and it has a rowspan
                    if (this_cell.className == undefined || this_cell.className == "") {
                        this_cell.className = "nobborderplz";
                    } else {
                        this_cell.className = this_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();