User:Greenpickle/monobook.js: Difference between revisions
Jump to navigation
Jump to search
Greenpickle (talk | contribs) No edit summary |
Greenpickle (talk | contribs) mNo edit summary |
||
Line 12: | Line 12: | ||
var hideImageURL = 'hide.png'; | var hideImageURL = 'http://img87.imageshack.us/img87/5183/hide.png'; | ||
var showImageURL = ' | var showImageURL = 'http://img87.imageshack.us/img87/2237/showg.png'; | ||
var hideableHeaderLinkClass = 'hideheader'; | var hideableHeaderLinkClass = 'hideheader'; | ||
var hideableTableClass = 'colshideable'; | var hideableTableClass = 'colshideable'; |
Revision as of 03:57, October 28, 2010
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>');
include = false;
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 hideImageURL = 'http://img87.imageshack.us/img87/5183/hide.png';
var showImageURL = 'http://img87.imageshack.us/img87/2237/showg.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);