User:Greenpickle/monobook.js: Difference between revisions

From Pikipedia, the Pikmin wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEdDiff.js&action=raw&ctype=text/javascript&"><\/script>\n<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js&action=raw&ctype=text/javascript"><\/script>');
/*
var RCNSTStartHidden = ['User', 'User talk', 'User creation log'];


include = false;
document.write('<script type="text/javascript" src="https://pikminwiki.com/index.php?title=User:Greenpickle/rcnst.js&action=raw&ctype=text/javascript"><\/script>');
RCNSTList = ['User', 'User talk', 'User blog', 'User blog talk', 'User blog comment', 'User blog comment talk', 'User avatar log', 'User creation log'];
*/
RCNSTPageListInclude = [];
RCNSTPageListExclude = [];
RCNSTbeforecheckboxes = '<span id="rcnst"><hr />\n';
RCNSTaftercheckboxes = '</span>';
RCNSTbeforecheckbox = '';
RCNSTaftercheckbox = '\n';
document.write('<script type="text/javascript" src="http://pikminwiki.com/index.php?title=User:Greenpickle/rcnst.js&action=raw&ctype=text/javascript"><\/script>');


 
var patrol = $('.patrollink');
var hideImageURL = 'hide.png';
if (patrol && patrol.length) patrol[0].children[0].setAttribute('accesskey', 'g');
var showImageURL = 'show.png';
var hideableHeaderLinkClass = 'hideheader';
var hideableTableClass = 'colshideable';
var hideableHeaderClass = 'hideable';
var hiddenHeaderClass = 'hidden';
 
Element.prototype.indexOf = function (o) {
    var children = this.childNodes;
    var i = children.length;
    while (i--) {
        if (children[i] === o) return i;
    }
    return -1;
}
 
function getCells (tr) {
    var cells = [];
    var children = tr.childNodes;
    for (var i = 0; i < children.length; i++) {
        if (children[i].constructor === HTMLTableCellElement) cells.push(children[i]);
    }
    return cells;
}
 
function initHideable () {
    var tables = getElementsByClassName(document, 'table', hideableTableClass);
    window.tables = tables;
    var hiddenCols = [];
    window.hiddenCols = hiddenCols;
    for (var i = 0; i < tables.length; i++) {
        // operate on first row
        var tr = tables[i].getElementsByTagName('tr')[0]
        var ths = getCells(tr);
        hiddenCols.push(Array(ths.length));
        for (var j = 0; j < ths.length; j++) {
            if (hasClass(ths[j], hideableHeaderClass)) {
                // add show/hide button
                var lnk = document.createElement('a');
                lnk.className = hideableHeaderLinkClass;
                lnk.setAttribute('href', '#');
                lnk.setAttribute('onclick', 'toggleColHidden(' + i
                                + ', ' + j + '); return false;');
                var img = document.createElement('img');
                img.setAttribute('alt', 'hide');
                img.src = hideImageURL;
                lnk.appendChild(img);
                ths[j].appendChild(lnk);
                // hide column now if marked
                if (hasClass(ths[j], hiddenHeaderClass)) toggleColHidden(i, j);
            }
        }
    }
}
 
function toggleColHidden (tableNum, col) {
    var hidden = hiddenCols[tableNum];
    var table = tables[tableNum];
    var rows = table.getElementsByTagName('tr');
    if (hidden[col] === undefined) {
        // replace each cell with an empty one
        hidden = hidden[col] = [];
        for (var i = 0; i < rows.length; i++) {
            var oldCell = getCells(rows[i])[col];
            if (i == 0) {
                // create 'show' link
                var cell = document.createElement(oldCell.tagName);
                var lnk = document.createElement('a');
                lnk.className = hideableHeaderLinkClass;
                lnk.setAttribute('href', '#');
                lnk.setAttribute('onclick', 'toggleColHidden('
                                + tableNum + ', ' + col + '); return false;');
                var img = document.createElement('img');
                img.setAttribute('alt', 'show');
                img.src = showImageURL;
                lnk.appendChild(img);
                cell.appendChild(lnk);
            } else {
                var cell = document.createElement('td');
                cell.style.border = 'none';
            }
            hidden[i] = rows[i].replaceChild(cell, oldCell);
        }
    } else {
        // restore replaced cells
        hidden[col];
        for (var i = 0; i < rows.length; i++) {
            var oldCell = getCells(rows[i])[col];
            rows[i].replaceChild(hidden[col][i], oldCell);
        }
        hidden[col] = undefined;
    }
}
 
// initialise on page load
addOnloadHook(initHideable);

Latest revision as of 15:21, August 13, 2018

/*
var RCNSTStartHidden = ['User', 'User talk', 'User creation log'];

document.write('<script type="text/javascript" src="https://pikminwiki.com/index.php?title=User:Greenpickle/rcnst.js&action=raw&ctype=text/javascript"><\/script>');
*/

var patrol = $('.patrollink');
if (patrol && patrol.length) patrol[0].children[0].setAttribute('accesskey', 'g');