aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/scripts/script.js
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2005-12-10 20:37:09 +0100
committerAndreas Gohr <andi@splitbrain.org>2005-12-10 20:37:09 +0100
commit00540a38be97858e71163f53dddf8dee53185b1d (patch)
treeb59b8c1c5943804090e4f07eed708e658d78805b /lib/scripts/script.js
parent0a6ead412a67d6ce56895e3c5e8dd6612acac398 (diff)
downloaddokuwiki-00540a38be97858e71163f53dddf8dee53185b1d.tar.gz
dokuwiki-00540a38be97858e71163f53dddf8dee53185b1d.zip
unobstrusive JS for TOC, better onload handling
This path adds more unobstrusive JavaScript for the TOC handling. It also loads JavaScript initialiezers as soon as the DOM is parsed for Mozilla-based Browsers as described at http://dean.edwards.name/weblog/2005/09/busted/ - a IE solution was not chosen yet. darcs-hash:20051210193709-7ad00-771461e56d9661caf9ca733a6d617f009e24d0b7.gz
Diffstat (limited to 'lib/scripts/script.js')
-rw-r--r--lib/scripts/script.js65
1 files changed, 43 insertions, 22 deletions
diff --git a/lib/scripts/script.js b/lib/scripts/script.js
index b91859265..d589aa0b4 100644
--- a/lib/scripts/script.js
+++ b/lib/scripts/script.js
@@ -98,6 +98,19 @@ function escapeQuotes(text) {
}
/**
+ * Adds a node as the first childenode to the given parent
+ *
+ * @see appendChild()
+ */
+function prependChild(parent,element) {
+ if(!parent.firstChild){
+ parent.appendChild(element);
+ }else{
+ parent.insertBefore(element,parent.firstChild);
+ }
+}
+
+/**
* Prints a animated gif to show the search is performed
*
* @author Andreas Gohr <andi@splitbrain.org>
@@ -143,37 +156,45 @@ function suggestWikiname(){
}
/**
- * This prints the switch to toggle the Table of Contents
+ * Adds the toggle switch to the TOC
*/
-function showTocToggle(showtxt,hidetxt) {
- if(document.getElementById) {
- show = '<img src="'+DOKU_BASE+'lib/images/arrow_down.gif" alt="'+showtxt+'">';
- hide = '<img src="'+DOKU_BASE+'lib/images/arrow_up.gif" alt="'+hidetxt+'">';
-
- document.writeln('<div class=\'toctoggle\'><a href="javascript:toggleToc()" class="toc">' +
- '<span id="showlink" style="display:none;">' + show + '</span>' +
- '<span id="hidelink">' + hide + '</span>' +
- '</a></div>');
- }
+function addTocToggle() {
+ if(!document.getElementById) return;
+ var header = document.getElementById('toc__header');
+ if(!header) return;
+
+ var showimg = document.createElement('img');
+ showimg.id = 'toc__show';
+ showimg.src = DOKU_BASE+'lib/images/arrow_down.gif';
+ showimg.alt = '+';
+ showimg.onclick = toggleToc;
+ showimg.style.display = 'none';
+
+ var hideimg = document.createElement('img');
+ hideimg.id = 'toc__hide';
+ hideimg.src = DOKU_BASE+'lib/images/arrow_up.gif';
+ hideimg.alt = '-';
+ hideimg.onclick = toggleToc;
+
+ prependChild(header,showimg);
+ prependChild(header,hideimg);
}
/**
* This toggles the visibility of the Table of Contents
*/
function toggleToc() {
- var toc = document.getElementById('tocinside');
- var showlink=document.getElementById('showlink');
- var hidelink=document.getElementById('hidelink');
+ var toc = document.getElementById('toc__inside');
+ var showimg = document.getElementById('toc__show');
+ var hideimg = document.getElementById('toc__hide');
if(toc.style.display == 'none') {
- toc.style.display = tocWas;
- hidelink.style.display='';
- showlink.style.display='none';
+ toc.style.display = '';
+ hideimg.style.display = '';
+ showimg.style.display = 'none';
} else {
- tocWas = toc.style.display;
- toc.style.display = 'none';
- hidelink.style.display='none';
- showlink.style.display='';
-
+ toc.style.display = 'none';
+ hideimg.style.display = 'none';
+ showimg.style.display = '';
}
}