1 function toggle_visibility(e) {
2 if(e.style.display == 'none') {
3 e.style.display = 'block';
6 e.style.display = 'none';
12 function createCookie(name,value,days) {
14 var date = new Date();
15 date.setTime(date.getTime()+(days*24*60*60*1000));
16 var expires = "; expires="+date.toGMTString();
18 else var expires = "";
19 document.cookie = name+"="+value+expires+"; path=/";
22 function readCookie(name) {
23 var nameEQ = name + "=";
24 var ca = document.cookie.split(';');
25 for(var i=0;i < ca.length;i++) {
27 while (c.charAt(0)==' ') c = c.substring(1,c.length);
28 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
38 function popOutTOC(original_toc, p0) {
39 var t = original_toc.cloneNode(true);
41 var c = document.getElementsByClassName("contents")[0];
42 var left = c.style.marginLeft;
43 c.style.marginLeft = "20.5em";
44 document.body.insertBefore(t,c);
46 t.getElementsByClassName("toc_search")[0].getElementsByTagName("input")[0].onkeyup = toc_search;
48 t.style.top = menubar.clientHeight;
49 t.style.maxHeight = "none";
50 t.style.display = "block";
52 var p = t.getElementsByClassName("popoutlink")[0];
53 p.innerHTML = "close";
54 p.onclick = function() {
55 t.parentNode.removeChild(t);
56 c.style.marginLeft = left;
57 p0.style.display = "";
59 allItems = toc.getElementsByTagName("ul")[0].getElementsByTagName("li");
60 sessionStorage.popToc = "no";
63 var x = document.createElement("div");
65 x.innerHTML = "Table of contents";
66 t.insertBefore(x,p.nextSibling);
67 p0.style.display = "none";
70 allItems = t.getElementsByTagName("ul")[0].getElementsByTagName("li");
72 sessionStorage.popToc = "yes";
75 function resize_handler() {
76 var height = window.innerHeight - menubar.clientHeight - 20;
78 sidetoc.style.height = height;
80 toc.style.maxHeight = height * 0.75;
83 function addInheritedMethods() {
84 if(! /\/Classes\/[^\/]+/.test(window.location.pathname)) return; // skip this if not a class doc
85 var doc = docmap["Classes/"+document.title];
88 var sups = docmap["Classes/"+doc.implementor].superclasses;
90 var sups = doc.superclasses;
93 var divs = [document.getElementById("inheritedclassmets"), document.getElementById("inheritedinstmets")];
94 for(var i=0;i<sups.length;i++) {
95 var s = docmap["Classes/"+sups[i]];
97 for(var j=0;j<2;j++) {
98 d[j] = document.createElement("ul");
99 d[j].className = "inheritedmets";
100 d[j].style.display = "none";
102 var mets = s.methods.sort();
103 for(var j=0;j<mets.length;j++) {
105 if(doc.methods.indexOf(m)<0) { // ignore methods already documented in this helpfile
106 var li = document.createElement("li");
107 li.innerHTML = "<a href='"+helpRoot+"/"+s.path+".html#"+m.slice(1)+"'>"+m.slice(2)+"</a>";
109 d[0].appendChild(li);
112 d[1].appendChild(li);
116 for(var j=0;j<2;j++) {
117 var count = d[j].childElementCount;
119 var x = document.createElement("div");
120 var show = "► show";
121 var hide = "▼ hide";
122 x.className = "inheritedmets_class";
123 x.innerHTML = count+" methods from <a href='"+helpRoot+"/"+s.path+".html'>"+s.title+"</a> ";
124 divs[j].appendChild(x);
126 var a = document.createElement("a");
127 a.className = "inheritedmets_toggle";
128 a.setAttribute("href","#");
130 a.onclick = function() {
131 if(z.style.display == "none") {
132 z.style.display = "block";
135 z.style.display = "none";
142 divs[j].appendChild(d[j]);
148 function showAllSubclasses(a) {
149 var e = document.getElementById("hiddensubclasses");
150 e.style.display = "";
151 a.style.display = "none";
155 This key event handler selects the whole line when pressing shift/ctrl-enter with no selection.
156 But the problem is that it does not update the selection sent to the client.
157 This is probably because the WebView catches the key event before javascript does!
158 A fix might be to expose a function to JS that evaluates selection, and call it here.
159 Or can the WebView make sure that JS has responded to all key events before getting the selection?
161 function selectLine() {
162 var s = window.getSelection();
163 var r = s.getRangeAt();
165 function findleft(p) {
168 if(p.nodeName == "BR")
170 if(p.childNodes.length>0) {
171 for(var i=p.childNodes.length-1;i>=0;i--) {
172 y = findleft(p.childNodes[i]);
176 p = p.previousSibling;
181 function findright(p) {
184 if(p.nodeName == "BR")
186 for(var i=0;i<p.childNodes.length;i++) {
187 y = findright(p.childNodes[i]);
197 var r2 = document.createRange();
198 var top = r.startContainer;
199 while(top && top.nodeName != "PRE")
200 top = top.parentNode;
202 var p = r.startContainer;
203 while(!p.previousSibling && p != top) {
207 r2.setStartBefore(top.firstChild);
209 var found = findleft(p.previousSibling);
211 r2.setStartAfter(found[0]);
213 r2.setStartBefore(top.firstChild);
216 var p = r.startContainer;
217 while(!p.nextSibling && p != top) {
221 r2.setEndAfter(top.lastChild);
223 var found = findright(p.nextSibling);
225 r2.setEndBefore(found[0]);
227 r2.setEndAfter(top.lastChild);
235 function countChar(str,chr) {
237 for(var i=0;i<str.length;i++) {
239 if(a==undefined) a = i;
244 // return count, first occurence and last occurence
248 function selectParens(ev) {
249 var s = window.getSelection();
250 var r = s.getRangeAt();
251 var r2 = document.createRange();
254 // FIXME: it always selects from the left paren, so clicking on the right-par does not select from the matching left-par
255 // need to abort lpar search if rpar was found and then start with the rpar to the right (or closest) instead
256 function findlpar(x) {
260 if(j = p.nodeValue) {
261 j = countChar(j,"(");
266 for(var i=0;i<p.childNodes.length;i++) {
267 y = findlpar(p.childNodes[i]);
270 p = p.previousSibling;
275 function findrpar(x,count) {
278 count = count || [0];
280 if(j = p.nodeValue) {
281 count[0] += countChar(j,"(")[0];
282 j = countChar(j,")");
290 for(var i=0;i<p.childNodes.length;i++) {
291 y = findrpar(p.childNodes[i],count);
299 var p = r.startContainer;
300 if(p.nodeValue && (j = p.nodeValue.indexOf("("))>=0) {
302 p = p.parentNode.nextSibling;
304 while(!p.previousSibling && p != ev.target) {
309 var found = findlpar(p);
311 r2.setStart(found[0],found[1]+1);
314 var found = findrpar(p);
316 r2.setEnd(found[0],found[1]);
322 escape_regexp = function(str) {
323 var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); // .*+?|()[]{}\
324 return str.replace(specials, "\\$&");
327 function toc_search(ev) {
328 //TODO: on enter, go to first match
329 var re = RegExp("^"+escape_regexp(ev.target.value),"i");
330 for(var i=0;i<allItems.length;i++) {
331 var li = allItems[i];
332 var a = li.firstChild;
333 if(re.test(a.innerHTML)) {
334 li.style.display = "";
335 var lev = li.className[3];
336 for(var i2 = i-1;i2>=0;i2--) {
337 var e = allItems[i2];
338 if(e.className[3]<lev) {
339 e.style.display = "";
342 if(e.className[3]==1) break;
345 li.style.display = "none";
351 var x = document.getElementsByClassName("lang-sc");
352 for(var i=0;i<x.length;i++) {
355 // make all code examples editable!
356 e.setAttribute("contentEditable",true);
358 // select parenthesis on double-click
359 e.ondblclick = selectParens;
362 addInheritedMethods();
364 if(sessionStorage == undefined)
370 var toggleMenu = function(e) {
372 openMenu.style.display = 'none';
375 e.style.display = 'block';
378 openMenu = undefined;
383 document.onclick = function(e) {
384 if(openMenu && !inMenu && e.target.id!="toc_search") {
385 openMenu.style.display = 'none';
386 openMenu = undefined;
393 var bar = document.getElementById("menubar");
395 var nav = ["Home","Browse","Search"];
396 var url = ["Help.html","Browse.html","Search.html"];
397 for(var i=0;i<nav.length;i++) {
398 var li = document.createElement("li");
399 li.className = "menuitem";
400 var a = document.createElement("a");
401 a.innerHTML = nav[i];
402 a.setAttribute("href",helpRoot+"/"+url[i]);
403 a.className = "navLink";
408 var li = document.createElement("li");
409 li.className = "menuitem";
410 var a = document.createElement("a");
411 a.innerHTML = "Indexes ▼";
412 a.setAttribute("href","#");
413 var m1 = document.createElement("div");
414 m1.className = "submenu";
415 m1.style.display = "none";
416 a.onclick = function() {
420 var nav = ["Documents","Classes","Methods"];
421 for(var i=0;i<nav.length;i++) {
422 var b = document.createElement("a");
423 b.setAttribute("href",helpRoot+"/Overviews/"+nav[i]+".html");
424 b.innerHTML = nav[i];
431 var li = document.createElement("li");
432 li.className = "menuitem";
433 var x = document.createElement("span");
434 x.id = "topdoctitle";
435 x.appendChild(document.createTextNode(document.title));
436 x.onclick = function() {
443 var t = document.getElementById("toc");
446 var div = document.createElement("span");
447 div.className = "toc_search";
448 var ts = document.createElement("input");
450 ts.id = "toc_search";
452 ts.style.border = "1px solid #ddd";
453 allItems = toc.getElementsByTagName("ul")[0].getElementsByTagName("li");
454 ts.onkeyup = toc_search;
455 div.appendChild(document.createTextNode("Find:"));
457 t.insertBefore(div,t.firstChild);
459 x.appendChild(document.createTextNode(" - "));
460 t.style.display = 'none';
462 var a = document.createElement("a");
463 a.setAttribute("href","#");
464 a.innerHTML = "Table of contents ▼";
466 a.onclick = function() {
471 li.appendChild(t.parentNode.removeChild(t));
472 var p = document.createElement("a");
473 p.setAttribute("href","#");
474 p.className = "popoutlink";
475 p.innerHTML = "pop out";
476 p.onclick = function() {
481 t.insertBefore(p,t.firstChild);
483 if(sessionStorage.popToc == "yes") {
487 window.onresize = resize_handler;