Please post your improvements to this if you make any.
I would also like to do this. There are at least two ways. One is to keep a dictionary of terms to remove. The other is to use rules to identify terms to remove. At the bottom is a script that implements three common rules in English to act on the terms that appear in the navigation panel when the Glossary tab is selected.
At the moment I have the script placed in Default.htm (or the whatever the main file's name). I added an onclick to the tab to fire the script. But it doesn't fire until it is clicked a second time. Meaning the tab is shown and then clicked again. If you find a better way to fire the script, let me know.
In the body:
Code: Select all
<div class="tabs">
<ul class="tabs-nav clearfix">
<li id="TocTab" class="needs-pie tabs-nav-active">Contents</li>
<li id="IndexTab" class="needs-pie">Index</li>
<li id="GlossaryTab" class="needs-pie" onclick="removePlurals()">Glossary</li>
</ul>
And in the head:
Code: Select all
<script type="text/javascript">
function getFirstChild(el) {
//Not all nodes are elements. This ensures the returned nodes are only elements.
//http://stackoverflow.com/questions/2299807/element-firstchild-is-returning-textnode-instead-of-an-object-in-ff
var firstChild = el.firstChild;
while (firstChild != null && firstChild.nodeType !== 1) {
firstChild = firstChild.nextSibling;
}
return firstChild;
}
function removePlurals() {
var glossary = document.getElementById("glossary").getElementsByTagName("li");
var itemsToRemove = [];
glossary.length
var i = 0;
while (i < glossary.length) {
//Looking at each item in glossary. Consider this the current one.
var curr = getFirstChild(getFirstChild(glossary[i])).textContent;
//Don't check for the previous on the first iteration.
//This part checks for two types of plurals in English. Examples:
//Current: fancy Previous: fancies
//Current: monies Previous: money
var prev = '';
var j = i - 1;
if (!(i == 0)) {
prev = getFirstChild(getFirstChild(glossary[j])).textContent;
if ((prev.substring(curr.length - 3) == 'ey') && (curr.substring(curr.length - 3) == 'ies') && (prev.substring(0, curr.length - 3) == curr.substring(0, curr.length - 3))) {
itemsToRemove.push(glossary[i]);
}
if ((curr.substring(curr.length - 1) == 'y') && (prev.substring(curr.length - 1) == 'ies') && (prev.substring(0, curr.length - 1) == curr.substring(0, curr.length - 1))) {
itemsToRemove.push(glossary[j]);
}
}
//This part checks for the most common type of plural in English. Example:
//Current: Term Next: Terms
var next = '';
var k = i + 1;
if (i < glossary.length - 1) {
next = getFirstChild(getFirstChild(glossary[k])).textContent;
if ((next.substring(curr.length) == 's') && (next.substring(0, curr.length) == curr)) {
itemsToRemove.push(glossary[k]);
}
}
i++;
}
while (itemsToRemove.length > 0) {
var r = itemsToRemove.pop();
r.parentNode.removeChild(r);
}
}
</script>