User:Greenpickle/monobook.js: Difference between revisions
Jump to navigation
Jump to search
Greenpickle (talk | contribs) No edit summary |
Greenpickle (talk | contribs) No edit summary |
||
Line 10: | Line 10: | ||
RCNSTaftercheckbox = '\n'; | 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>'); | 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 = ''; | |||
var showImageURL = ''; | |||
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++) { | |||
var tag = children[i].tagName.toLowerCase() | |||
if (tag == 'td' || tag == 'th') 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++) { | |||
var table = tables[i]; | |||
// get first row | |||
var tr = table.getElementsByTagName('tr')[0] | |||
var colgroup = document.createElement('colgroup'); | |||
table.appendChild(colgroup); | |||
var ths = tr.childNodes; | |||
hiddenCols.push(Array(ths.length)); | |||
for (var j = 0; j < ths.length; j++) { | |||
// add col tag | |||
var col = document.createElement('col'); | |||
colgroup.appendChild(col); | |||
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); |
Revision as of 18:23, October 27, 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 = '';
var showImageURL = '';
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++) {
var tag = children[i].tagName.toLowerCase()
if (tag == 'td' || tag == 'th') 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++) {
var table = tables[i];
// get first row
var tr = table.getElementsByTagName('tr')[0]
var colgroup = document.createElement('colgroup');
table.appendChild(colgroup);
var ths = tr.childNodes;
hiddenCols.push(Array(ths.length));
for (var j = 0; j < ths.length; j++) {
// add col tag
var col = document.createElement('col');
colgroup.appendChild(col);
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);