2
* The contents of this file are subject to the Mozilla Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/MPL/
7
* Software distributed under the License is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is mozilla.org code.
14
* The Initial Developer of the Original Code is Netscape
15
* Communications Corporation. Portions created by Netscape are
16
* Copyright (C) 1998 Netscape Communications Corporation. All
22
// Event handler for display togglers in Table of Contents
23
function toggleDisplay(event)
25
if (event.target.localName != "IMG")
27
var img = event.target;
28
var div = img.nextSibling.nextSibling;
30
// Change the display: property of the container to
31
// hide and show the container.
32
if (div.style.display == "none") {
33
div.style.display = "block";
34
img.src = "minus.gif";
37
div.style.display = "none";
42
// Function that recurses down the tree, looking for
43
// structural elements. For each structural element,
44
// a corresponding element is created in the table of
46
var searchTags = new Array("book", "chapter", "section");
47
var tocTags = new Array("level1", "level2", "level3");
48
function addToToc(root, tocFrame)
51
var newTocFrame = tocFrame;
52
var newTocElement = null;
53
var newTocLink = null;
55
for (i=0; i < searchTags.length; i++) {
56
if (root.tagName == searchTags[i]) {
57
// If we've found a structural element, create the
58
// equivalent TOC element.
59
newTocElement = document.createElement(tocTags[i]);
60
// Create the toclink element that is a link to the
61
// corresponding structural element.
62
newTocLink = document.createElement("toclink");
63
newTocLink.setAttributeNS("http://www.w3.org/1999/xlink","xlink:type", "simple");
64
newTocLink.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href", "#"+ root.getAttribute("id"));
65
newTocLink.setAttributeNS("http://www.w3.org/1999/xlink","xlink:show", "replace");
66
newTocElement.appendChild(newTocLink);
68
// Create the image and toggling container in the table of contents
69
if (i < searchTags.length-1) {
70
var img = document.createElementNS("http://www.w3.org/1999/xhtml","img");
71
img.src = "minus.gif";
72
newTocElement.insertBefore(img,newTocLink);
74
newTocFrame = document.createElementNS("http://www.w3.org/1999/xhtml","div");
75
newTocElement.appendChild(newTocFrame);
81
tocFrame.appendChild(newTocElement);
87
// Recurse down through the childNodes list
88
for (i=0; i < root.childNodes.length; i++) {
89
var child = root.childNodes[i];
90
if (child.nodeType == Node.ELEMENT_NODE) {
91
if ((newTocLink != null) && (child.tagName == "title")) {
92
var text = child.firstChild.cloneNode(true);
93
newTocLink.appendChild(text);
96
addToToc(child, newTocFrame);
102
// Create the root table of contents element (a fixed element)
106
if (document.getElementsByTagName("toc").length == 0) {
107
var toc = document.createElement("toc");
108
var title = document.createElement("title");
109
title.appendChild(document.createTextNode("Table of Contents"));
110
toc.appendChild(title);
112
// Recurse down and build up the document element
113
addToToc(document.documentElement, toc);
115
// Since we've created the toc element as a fixed element,
116
// insert a rule that shifts over the document element by
117
// the width of the toc element.
118
document.styleSheets[0].cssRules[0].style.marginLeft = "12em";
119
document.documentElement.appendChild(toc);
121
// Attach the event handler for table of contents buttons.
122
// This will only work for content that is already a part
123
// of a document, which is why we had to wait until here
125
toc.addEventListener("mouseup",toggleDisplay,1);
127
// Hide the table of contents.
128
// This is not very intelligent if we have a static document, we should
129
// just hide/show the toc via stylesheet mungling
130
document.documentElement.removeChild(document.getElementsByTagName("toc")[0]);
131
document.styleSheets[0].cssRules[0].style.marginLeft = "0em";