1// Haddock JavaScript utilities
6function spaced(s) { return (" " + s + " ").replace(rspace, " "); }
7function trim(s) { return s.replace(rtrim, ""); }
9function hasClass(elem, value) {
10 var className = spaced(elem.className || "");
11 return className.indexOf( " " + value + " " ) >= 0;
14function addClass(elem, value) {
15 var className = spaced(elem.className || "");
16 if ( className.indexOf( " " + value + " " ) < 0 ) {
17 elem.className = trim(className + " " + value);
21function removeClass(elem, value) {
22 var className = spaced(elem.className || "");
23 className = className.replace(" " + value + " ", " ");
24 elem.className = trim(className);
27function 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);
41function makeClassToggle(valueOn, valueOff)
43 return function(elem, bool) {
44 return toggleClass(elem, valueOn, valueOff, bool);
48toggleShow = makeClassToggle("show", "hide");
49toggleCollapser = makeClassToggle("collapser", "expander");
51function toggleSection(id)
53 var b = toggleShow(document.getElementById("section." + id));
54 toggleCollapser(document.getElementById("control." + id), b);
55 rememberCollapsed(id, b);
60function rememberCollapsed(id, b)
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('+'));
77function restoreCollapsed()
79 var cookie = getCookie("collapsed");
83 var ids = cookie.split('+');
86 if(document.getElementById("section." + ids[i]))
87 toggleSection(ids[i]);
91function setCookie(name, value) {
92 document.cookie = name + "=" + escape(value) + ";path=/;";
95function clearCookie(name) {
96 document.cookie = name + "=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT;";
99function 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));
114var max_results = 75; // 50 is not enough to search for map in the base libraries
115var shown_range = null;
116var last_search = null;
118function quick_search()
120 perform_search(false);
123function full_search()
125 perform_search(true);
129function 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
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);
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
223 var s = children[i].firstChild.firstChild.data;
224 if (s.indexOf(' ') == -1)
227 return ""; // should never be reached
231function 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;
242function addMenuItem(html) {
243 var menu = document.getElementById("page-menu");
245 var btn = menu.firstChild.cloneNode(false);
246 btn.innerHTML = html;
247 menu.appendChild(btn);
251function 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";
270function 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) {
288function addStyleMenu() {
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>"
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>"
305function 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");
326function resetStyle() {
327 var s = getCookie("haddock-style");
328 if (s) setActiveStyleSheet(s);
332function styleMenu(show) {
333 var m = document.getElementById('style-menu');
334 if (m) toggleShow(m, show);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list