source: presentations/trunk/Tools/Javascript/slidy-toc.js@ 318

Last change on this file since 318 was 274, checked in by garnier, 17 years ago

remodelage

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1/*
2
3Slidy-Toc generates a table of contents for slidy show.
4Usage see: http://www.w3c.de/PubPraes/slidy-toc.html
5
6slidy-toc.js must be placed behind slidy.js. Internal dependancies:
7
8 * it overwrites document.onload with its own initialisation routine
9 * it relies that the initialisation routine of slidy.js is named startup
10 * it relies that the variable slides holds an array of all slides of the presentation
11 * it uses the clickedAnchor routine for anchor click events
12 * variable ns_pos is used as in slidy to meet MSIE's need to see "classname" instead of "class" for ?etAttribute
13
14Klaus Birkenbihl, 2005-09-16
15Copyright ᅵ 2005 W3C (MIT, ERCIM, Keio)
16
17*/
18
19window.onload = SltocStartup;
20
21// initialize
22function SltocStartup()
23 {
24 startup(); // init slidy
25 SltocFilltoc(); // fill table of contents
26 }
27
28// fill table of contents
29function SltocFilltoc()
30 {
31 var toc = 0;
32 var name = ns_pos ? "class" : "className"; // to serve MSIE
33 var page; // URL of presentation
34 var ip = location.href.indexOf("#");
35 if (ip > 0)
36 page = location.href.substr(0, ip);
37 else
38 page = location.href;
39
40 for (var i = 0; i < slides.length; ++i) // find slide to contain the toc (class="toc")
41 {
42 if (hasToken(slides[i].getAttribute(name), "toc"))
43 {
44 toc = slides[i];
45 i = slides.length;
46 }
47 }
48// toc = slides[1];
49 if (toc) // no toc found => we're done
50 {
51 for (var i = 0; i < slides.length; ++i) // look at every slide
52
53 {
54 var h = slides[i].getElementsByTagName("h1")[0]; // is there a <h{1-3}>?
55 if (h == null)
56 h = slides[i].getElementsByTagName("h2")[0];
57 if (h == null)
58 h = slides[i].getElementsByTagName("h3")[0];
59 if (h != null) // if not we'll generate no entry for this slide
60 {
61 var div1 = document.createElement("div"); // create div to contain link to slide
62 var a = document.createElement("a");
63 div1.appendChild(a);
64 toc.appendChild(div1);
65 a.setAttribute("href", page + "#("+(i+1)+")"); // generate link to slide
66 div1.setAttribute(name, "tocref");
67 a.appendChild(document.createTextNode(i+1));
68 var div = document.createElement("div"); // create div with contents of <h?>
69 div.setAttribute(name, "tocentry");
70 toc.appendChild(div);
71 for(var j=0; j < h.childNodes.length; ++j) // collect all childs of <h?>
72 div.appendChild(h.childNodes[j].cloneNode(true));
73 a.onclick = clickedAnchor; // make sure that anchor works
74 }
75 }
76 toc.appendChild(document.createElement("br")); // cosmetics
77 }
78 }
79
Note: See TracBrowser for help on using the repository browser.