1 function function_ref(fn
) {
2 return A({"href": fn
[1], "class": "mochiref reference"}, fn
[0], BR());
5 function toggle_docs() {
6 toggleElementClass("invisible", "show_index", "function_index");
10 function create_toc() {
11 if (getElement("distribution")) {
12 return global_index();
14 if (getElement("api-reference")) {
15 return module_index();
19 function doXHTMLRequest(url
) {
20 var d
= doXHR(url
, {mimeType
: 'text/xml'});
21 return d
.addCallback(function (res
) {
22 if (res
.responseXML
.documentElement
) {
23 return res
.responseXML
.documentElement
;
25 var container
= document
.createElement('div');
26 container
.innerHTML
= res
.responseText
;
32 function load_request(href
, div
, doc
) {
33 var functions
= withDocument(doc
, spider_doc
);
34 forEach(functions
, function (func
) {
36 if (func
[1].charAt(0) == "#") {
37 func
[1] = href
+ func
[1];
38 } else if (func
[1].lastIndexOf("#") != -1) {
39 func
[1] = href
+ "#" + func
[1].split("#")[1];
42 var showLink
= A({"class": "force-pointer"}, "[+]");
43 var hideLink
= A({"class": "force-pointer"}, "[\u2013]");
44 var functionIndex
= DIV({"id": "function_index", "class": "invisible"},
46 P(null, map(function_ref
, functions
))
48 var toggleFunc
= function (e
) {
49 toggleElementClass("invisible", showLink
, functionIndex
);
51 connect(showLink
, "onclick", toggleFunc
);
52 connect(hideLink
, "onclick", toggleFunc
);
53 replaceChildNodes(div
,
57 return [showLink
, toggleFunc
];
60 function global_index() {
61 var distList
= getElementsByTagAndClassName("ul")[0];
62 var bullets
= getElementsByTagAndClassName("li", null, distList
);
64 for (var i
= 0; i
< bullets
.length
; i
++) {
66 var firstLink
= getElementsByTagAndClassName("a", "mochiref", tag
)[0];
67 var href
= getNodeAttribute(firstLink
, "href");
68 var div
= DIV(null, "[\u2026]");
69 appendChildNodes(tag
, BR(), div
);
70 lst
.push(doXHTMLRequest(href
).addCallback(load_request
, href
, div
));
73 var loadingNode
= DIV(null, "[loading index\u2026]");
74 distList
.parentNode
.insertBefore(P(null, loadingNode
), distList
);
76 var dl
= gatherResults(lst
).addCallback(function (res
) {
77 var toggleFunc
= function (e
) {
78 for (var i
= 0; i
< res
.length
; i
++) {
80 if (!hasElementClass(item
[0], "invisible")) {
85 var node
= A({"class": "force-pointer"}, "[click to expand all]");
86 swapDOM(loadingNode
, node
);
87 connect(node
, "onclick", toggleFunc
);
91 function spider_doc() {
94 return [scrapeText(tag
), getNodeAttribute(tag
, "href")];
96 getElementsByTagAndClassName("a", "mochidef")
100 function module_index() {
101 var sections
= getElementsByTagAndClassName("div", "section");
102 var ptr
= sections
[1];
103 var ref
= DIV({"class": "section"},
104 H1(null, "Function Index"),
105 A({"id": "show_index", "href": "#", "onclick": toggle_docs
}, "[show]"),
106 DIV({"id": "function_index", "class": "invisible"},
107 A({"href":"#", "onclick": toggle_docs
}, "[hide]"),
108 P(null, map(function_ref
, spider_doc()))));
109 ptr
.parentNode
.insertBefore(ref
, ptr
);
112 connect(window
, 'onload', create_toc
);