@@ -0,0 +1,344 @@
1+// Haddock JavaScript utilities
6+function spaced(s) { return (" " + s + " ").replace(rspace, " "); }
7+function trim(s) { return s.replace(rtrim, ""); }
9+function hasClass(elem, value) {
10+ var className = spaced(elem.className || "");
11+ return className.indexOf( " " + value + " " ) >= 0;
14+function addClass(elem, value) {
15+ var className = spaced(elem.className || "");
16+ if ( className.indexOf( " " + value + " " ) < 0 ) {
17+ elem.className = trim(className + " " + value);
21+function removeClass(elem, value) {
22+ var className = spaced(elem.className || "");
23+ className = className.replace(" " + value + " ", " ");
24+ elem.className = trim(className);
27+function toggleClass(elem, valueOn, valueOff, bool) {
28+ if (bool == null) { bool = ! hasClass(elem, valueOn); }
30+ removeClass(elem, valueOff);
31+ addClass(elem, valueOn);
34+ removeClass(elem, valueOn);
35+ addClass(elem, valueOff);
41+function makeClassToggle(valueOn, valueOff)
43+ return function(elem, bool) {
44+ return toggleClass(elem, valueOn, valueOff, bool);
48+toggleShow = makeClassToggle("show", "hide");
49+toggleCollapser = makeClassToggle("collapser", "expander");
51+function toggleSection(id)
53+ var b = toggleShow(document.getElementById("section." + id));
54+ toggleCollapser(document.getElementById("control." + id), b);
55+ rememberCollapsed(id, b);
60+function rememberCollapsed(id, b)
65+ collapsed[id] = null;
68+ for(var i in collapsed)
70+ if(collapsed.hasOwnProperty(i))
73+ // cookie specific to this page; don't use setCookie which sets path=/
74+ document.cookie = "collapsed=" + escape(sections.join('+'));
77+function restoreCollapsed()
79+ var cookie = getCookie("collapsed");
83+ var ids = cookie.split('+');
86+ if(document.getElementById("section." + ids[i]))
87+ toggleSection(ids[i]);
91+function setCookie(name, value) {
92+ document.cookie = name + "=" + escape(value) + ";path=/;";
95+function clearCookie(name) {
96+ document.cookie = name + "=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT;";
99+function getCookie(name) {
100+ var nameEQ = name + "=";
101+ var ca = document.cookie.split(';');
102+ for(var i=0;i < ca.length;i++) {
104+ while (c.charAt(0)==' ') c = c.substring(1,c.length);
105+ if (c.indexOf(nameEQ) == 0) {
106+ return unescape(c.substring(nameEQ.length,c.length));
114+var max_results = 75; // 50 is not enough to search for map in the base libraries
115+var shown_range = null;
116+var last_search = null;
118+function quick_search()
120+ perform_search(false);
123+function full_search()
125+ perform_search(true);
129+function perform_search(full)
131+ var text = document.getElementById("searchbox").value.toLowerCase();
132+ if (text == last_search && !full) return;
135+ var table = document.getElementById("indexlist");
136+ var status = document.getElementById("searchmsg");
137+ var children = table.firstChild.childNodes;
139+ // first figure out the first node with the prefix
140+ var first = bisect(-1);
141+ var last = (first == -1 ? -1 : bisect(1));
145+ table.className = "";
146+ status.innerHTML = "No results found, displaying all";
148+ else if (first == 0 && last == children.length - 1)
150+ table.className = "";
151+ status.innerHTML = "";
153+ else if (last - first >= max_results && !full)
155+ table.className = "";
156+ status.innerHTML = "More than " + max_results + ", press Search to display";
160+ // decide what you need to clear/show
162+ setclass(shown_range[0], shown_range[1], "indexrow");
163+ setclass(first, last, "indexshow");
164+ shown_range = [first, last];
165+ table.className = "indexsearch";
166+ status.innerHTML = "";
170+ function setclass(first, last, status)
172+ for (var i = first; i <= last; i++)
174+ children[i].className = status;
179+ // do a binary search, treating 0 as ...
180+ // return either -1 (no 0's found) or location of most far match
181+ function bisect(dir)
183+ var first = 0, finish = children.length - 1;
184+ var mid, success = false;
186+ while (finish - first > 3)
188+ mid = Math.floor((finish + first) / 2);
190+ var i = checkitem(mid);
191+ if (i == 0) i = dir;
197+ var a = (dir == 1 ? first : finish);
198+ var b = (dir == 1 ? finish : first);
199+ for (var i = b; i != a - dir; i -= dir)
201+ if (checkitem(i) == 0) return i;
207+ // from an index, decide what the result is
208+ // 0 = match, -1 is lower, 1 is higher
209+ function checkitem(i)
211+ var s = getitem(i).toLowerCase().substr(0, text.length);
212+ if (s == text) return 0;
213+ else return (s > text ? -1 : 1);
217+ // from an index, get its string
218+ // this abstracts over alternates
221+ for ( ; i >= 0; i--)
223+ var s = children[i].firstChild.firstChild.data;
224+ if (s.indexOf(' ') == -1)
227+ return ""; // should never be reached
231+function setSynopsis(filename) {
232+ if (parent.window.synopsis) {
233+ if (parent.window.synopsis.location.replace) {
234+ // In Firefox this avoids adding the change to the history.
235+ parent.window.synopsis.location.replace(filename);
237+ parent.window.synopsis.location = filename;
242+function addMenuItem(html) {
243+ var menu = document.getElementById("page-menu");
245+ var btn = menu.firstChild.cloneNode(false);
246+ btn.innerHTML = html;
247+ menu.appendChild(btn);
251+function adjustForFrames() {
254+ if (parent.location.href == window.location.href) {
255+ // not in frames, so add Frames button
256+ addMenuItem("<a href='#' onclick='reframe();return true;'>Frames</a>");
257+ bodyCls = "no-frame";
260+ bodyCls = "in-frame";
262+ addClass(document.body, bodyCls);
266+ setCookie("haddock-reframe", document.URL);
267+ window.location = "frames.html";
270+function postReframe() {
271+ var s = getCookie("haddock-reframe");
273+ parent.window.main.location = s;
274+ clearCookie("haddock-reframe");
279+ var i, a, es = document.getElementsByTagName("link"), rs = [];
280+ for (i = 0; a = es[i]; i++) {
281+ if(a.rel.indexOf("style") != -1 && a.title) {
288+function addStyleMenu() {
290+ var i, a, btns = "";
291+ for(i=0; a = as[i]; i++) {
292+ btns += "<li><a href='#' onclick=\"setActiveStyleSheet('"
293+ + a.title + "'); return false;\">"
294+ + a.title + "</a></li>"
296+ if (as.length > 1) {
297+ var h = "<div id='style-menu-holder'>"
298+ + "<a href='#' onclick='styleMenu(); return false;'>Style ▾</a>"
299+ + "<ul id='style-menu' class='hide'>" + btns + "</ul>"
305+function setActiveStyleSheet(title) {
308+ for(i=0; a = as[i]; i++) {
310+ // need to do this always, some browsers are edge triggered
311+ if(a.title == title) {
316+ found.disabled = false;
317+ setCookie("haddock-style", title);
320+ as[0].disabled = false;
321+ clearCookie("haddock-style");
326+function resetStyle() {
327+ var s = getCookie("haddock-style");
328+ if (s) setActiveStyleSheet(s);
332+function styleMenu(show) {
333+ var m = document.getElementById('style-menu');
334+ if (m) toggleShow(m, show);
338+function pageLoad() {