|
|
ef5584 |
// Used for dynamically updating the height of a textarea
|
|
|
ef5584 |
function resizeTextArea(id, rows) {
|
|
|
ef5584 |
var textarea = document.getElementById(id);
|
|
|
ef5584 |
if (!textarea || (typeof(textarea.rows) == "undefined")) return;
|
|
|
ef5584 |
textarea.rows = rows;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// A better way than for example hardcoding foo.onload
|
|
|
ef5584 |
function addEvent(element, type, func){
|
|
|
ef5584 |
if (element.addEventListener) {
|
|
|
ef5584 |
element.addEventListener(type, func, false);
|
|
|
ef5584 |
return true;
|
|
|
ef5584 |
} else if (element.attachEvent) {
|
|
|
ef5584 |
return element.attachEvent("on" + type, func);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
return false;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// Convenience function for the nearest ancestor element with a specific tag
|
|
|
ef5584 |
// name
|
|
|
ef5584 |
function getAncestorByTagName(e, tagName) {
|
|
|
ef5584 |
tagName = tagName.toLowerCase();
|
|
|
ef5584 |
do {
|
|
|
ef5584 |
e = e.parentNode;
|
|
|
ef5584 |
} while ((e.nodeType == 1) && (e.tagName.toLowerCase() != tagName));
|
|
|
ef5584 |
return (e.nodeType == 1) ? e : null;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// Adapted from http://www.kryogenix.org/code/browser/searchhi/
|
|
|
ef5584 |
function searchHighlight() {
|
|
|
ef5584 |
if (!document.createElement) return;
|
|
|
ef5584 |
|
|
|
ef5584 |
var div = document.getElementById("searchable");
|
|
|
ef5584 |
if (!div) return;
|
|
|
ef5584 |
|
|
|
ef5584 |
function getSearchWords(url) {
|
|
|
ef5584 |
if (url.indexOf('?') == -1) return [];
|
|
|
ef5584 |
var queryString = url.substr(url.indexOf('?') + 1);
|
|
|
ef5584 |
var params = queryString.split('&';;
|
|
|
ef5584 |
for (var p in params) {
|
|
|
ef5584 |
var param = params[p].split('=');
|
|
|
ef5584 |
if (param.length < 2) continue;
|
|
|
ef5584 |
if (param[0] == 'q' || param[0] == 'p') { // q= for Google, p= for Yahoo
|
|
|
ef5584 |
var query = decodeURIComponent(param[1].replace(/\+/g, ' '));
|
|
|
ef5584 |
if (query[0] == '!') query = query.slice(1);
|
|
|
ef5584 |
words = query.split(/(".*?")|('.*?')|(\s+)/);
|
|
|
ef5584 |
var words2 = new Array();
|
|
|
ef5584 |
for (var w in words) {
|
|
|
ef5584 |
words[w] = words[w].replace(/^\s+$/, '');
|
|
|
ef5584 |
if (words[w] != '') {
|
|
|
ef5584 |
words2.push(words[w].replace(/^['"]/, '').replace(/['"]$/, ''));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
return words2;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
return [];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
function highlightWord(node, word, searchwordindex) {
|
|
|
ef5584 |
// If this node is a text node and contains the search word, highlight it by
|
|
|
ef5584 |
// surrounding it with a span element
|
|
|
ef5584 |
if (node.nodeType == 3) { // Node.TEXT_NODE
|
|
|
ef5584 |
var pos = node.nodeValue.toLowerCase().indexOf(word.toLowerCase());
|
|
|
ef5584 |
if (pos >= 0 && !/^searchword\d$/.test(node.parentNode.className)) {
|
|
|
ef5584 |
var span = document.createElement("span");
|
|
|
ef5584 |
span.className = "searchword" + (searchwordindex % 5);
|
|
|
ef5584 |
span.appendChild(document.createTextNode(
|
|
|
ef5584 |
node.nodeValue.substr(pos, word.length)));
|
|
|
ef5584 |
node.parentNode.insertBefore(span, node.parentNode.insertBefore(
|
|
|
ef5584 |
document.createTextNode(node.nodeValue.substr(pos + word.length)),
|
|
|
ef5584 |
node.nextSibling));
|
|
|
ef5584 |
node.nodeValue = node.nodeValue.substr(0, pos);
|
|
|
ef5584 |
return true;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
} else if (!node.nodeName.match(/button|select|textarea/i)) {
|
|
|
ef5584 |
// Recurse into child nodes
|
|
|
ef5584 |
for (var i = 0; i < node.childNodes.length; i++) {
|
|
|
ef5584 |
if (highlightWord(node.childNodes[i], word, searchwordindex)) i++;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
return false;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
var words = getSearchWords(document.URL);
|
|
|
ef5584 |
if (!words.length) words = getSearchWords(document.referrer);
|
|
|
ef5584 |
if (words.length) {
|
|
|
ef5584 |
for (var w in words) {
|
|
|
ef5584 |
if (words[w].length) highlightWord(div, words[w], w);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
function enableControl(id, enabled) {
|
|
|
ef5584 |
if (typeof(enabled) == "undefined") enabled = true;
|
|
|
ef5584 |
var control = document.getElementById(id);
|
|
|
ef5584 |
if (!control) return;
|
|
|
ef5584 |
control.disabled = !enabled;
|
|
|
ef5584 |
var label = getAncestorByTagName(control, "label");
|
|
|
ef5584 |
if (label) {
|
|
|
ef5584 |
label.className = enabled ? "enabled" : "disabled";
|
|
|
ef5584 |
} else {
|
|
|
ef5584 |
var labels = document.getElementsByTagName("label");
|
|
|
ef5584 |
for (var i = 0; i < labels.length; i++) {
|
|
|
ef5584 |
if (labels[i].htmlFor == id) {
|
|
|
ef5584 |
labels[i].className = enabled ? "enabled" : "disabled";
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
function addHeadingLinks(container, title) {
|
|
|
ef5584 |
var base = document.location.pathname;
|
|
|
ef5584 |
function addLinks(elems) {
|
|
|
ef5584 |
for (var i = 0; i < elems.length; i++) {
|
|
|
ef5584 |
var hn = elems[i];
|
|
|
ef5584 |
if (hn.id) {
|
|
|
ef5584 |
var link = document.createElement('a');
|
|
|
ef5584 |
link.href = base + '#' + hn.id;
|
|
|
ef5584 |
link.className = 'anchor';
|
|
|
ef5584 |
link.title = title.replace(/\$id/, hn.id);
|
|
|
ef5584 |
link.appendChild(document.createTextNode(" \u00B6"));
|
|
|
ef5584 |
hn.appendChild(link);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
for (var lvl = 0; lvl <= 6; lvl++) {
|
|
|
ef5584 |
addLinks(container.getElementsByTagName('h' + lvl));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|