User:Atelaes/QuoteHide.js
Jump to navigation
Jump to search
Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- This script lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • redirects • your own
/**
Hides quotations and example sentences within definitions. Only works in main namespace.
**/
function setupHiddenQuotes(li)
{
var HQToggle, liComp;
var HQShow = 'quotations ▼';
var HQHide = 'quotations ▲';
for (var k = 0; k < li.childNodes.length; k++) {
// Look at each component of the definition.
liComp = li.childNodes[k];
// If we find a ul or dl, we have quotes or example sentences, and thus need a button.
if (liComp.nodeName == 'UL' || liComp.nodeName == 'DL') {
HQToggle = newNode('a', {href: 'javascript:(function(){})()'}, '');
li.insertBefore(newNode('span', {'class': 'HQToggle', 'style': 'font-size:0.65em'}, ' [', HQToggle, ']'), liComp);
HQToggle.onclick = VisibilityToggles.register('quotations',
function show() {
HQToggle.innerHTML = HQHide;
for (var child = li.firstChild; child != null; child = child.nextSibling) {
if (/^(ul|UL|dl|DL)$/.test(child.nodeName)) {
child.style.display = 'block';
}
}
},
function hide() {
HQToggle.innerHTML = HQShow;
for (var child = li.firstChild; child != null; child = child.nextSibling) {
if (/^(ul|UL|dl|DL)$/.test(child.nodeName)) {
child.style.display = 'none';
}
}
});
break;
}
}
}
$( function ()
{
if (wgNamespaceNumber == 0) {
var ols, lis, li;
// First, find all the ordered lists, i.e. all the series of definitions.
var ols = document.getElementsByTagName('ol');
for(var i = 0; i < ols.length; i++) {
// Then, for every set, find all the individual definitions.
for (var j = 0; j < ols[i].childNodes.length; j++) {
li = ols[i].childNodes[j];
if (li.nodeName.toUpperCase() == 'LI') {
setupHiddenQuotes(li);
}
}
}
}
});