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);
37 function popOutTOC(original_toc, p0) {
38 var t = original_toc.cloneNode(true);
40 var c = document.getElementsByClassName("contents")[0];
41 var left = c.style.marginLeft;
42 c.style.marginLeft = "20.5em";
43 document.body.insertBefore(t,c);
45 t.style.top = menubar.clientHeight;
46 t.style.maxHeight = "none";
47 t.style.display = "block";
49 var p = t.getElementsByClassName("popoutlink")[0];
50 p.innerHTML = "close";
51 p.onclick = function() {
52 t.parentNode.removeChild(t);
53 c.style.marginLeft = left;
54 p0.style.display = "";
56 sessionStorage.popToc = "no";
59 var x = document.createElement("div");
61 x.innerHTML = "Table of contents";
62 t.insertBefore(x,p.nextSibling);
63 p0.style.display = "none";
67 sessionStorage.popToc = "yes";
70 function resize_handler() {
71 var height = window.innerHeight - menubar.clientHeight - 20;
73 sidetoc.style.height = height;
75 toc.style.maxHeight = height * 0.75;
78 function addInheritedMethods() {
79 if(! /\/Classes\/[^\/]+/.test(window.location.pathname)) return; // skip this if not a class doc
80 var doc = docmap["Classes/"+document.title];
83 var sups = docmap["Classes/"+doc.implementor].superclasses;
85 var sups = doc.superclasses;
88 var divs = [document.getElementById("inheritedclassmets"), document.getElementById("inheritedinstmets")];
89 for(var i=0;i<sups.length;i++) {
90 var s = docmap["Classes/"+sups[i]];
92 for(var j=0;j<2;j++) {
93 d[j] = document.createElement("ul");
94 d[j].className = "inheritedmets";
95 d[j].style.display = "none";
97 var mets = s.methods.sort();
98 for(var j=0;j<mets.length;j++) {
100 if(doc.methods.indexOf(m)<0) { // ignore methods already documented in this helpfile
101 var li = document.createElement("li");
102 li.innerHTML = "<a href='"+helpRoot+"/"+s.path+".html#"+m.slice(1)+"'>"+m.slice(2)+"</a>";
104 d[0].appendChild(li);
107 d[1].appendChild(li);
111 for(var j=0;j<2;j++) {
112 var count = d[j].childElementCount;
114 var x = document.createElement("div");
115 var show = "► show";
116 var hide = "▼ hide";
117 x.className = "inheritedmets_class";
118 x.innerHTML = count+" methods from <a href='"+helpRoot+"/"+s.path+".html'>"+s.title+"</a> ";
119 divs[j].appendChild(x);
121 var a = document.createElement("a");
122 a.className = "inheritedmets_toggle";
123 a.setAttribute("href","#");
125 a.onclick = function() {
126 if(z.style.display == "none") {
127 z.style.display = "block";
130 z.style.display = "none";
137 divs[j].appendChild(d[j]);
143 function showAllSubclasses(a) {
144 var e = document.getElementById("hiddensubclasses");
145 e.style.display = "";
146 a.style.display = "none";
150 This key event handler selects the whole line when pressing shift/ctrl-enter with no selection.
151 But the problem is that it does not update the selection sent to the client.
152 This is probably because the WebView catches the key event before javascript does!
153 A fix might be to expose a function to JS that evaluates selection, and call it here.
154 Or can the WebView make sure that JS has responded to all key events before getting the selection?
156 function selectLine() {
157 var s = window.getSelection();
158 var r = s.getRangeAt();
160 function findleft(p) {
163 if(p.nodeName == "BR")
165 if(p.childNodes.length>0) {
166 for(var i=p.childNodes.length-1;i>=0;i--) {
167 y = findleft(p.childNodes[i]);
171 p = p.previousSibling;
176 function findright(p) {
179 if(p.nodeName == "BR")
181 for(var i=0;i<p.childNodes.length;i++) {
182 y = findright(p.childNodes[i]);
192 var r2 = document.createRange();
193 var top = r.startContainer;
194 while(top && top.nodeName != "PRE")
195 top = top.parentNode;
197 var p = r.startContainer;
198 while(!p.previousSibling && p != top) {
202 r2.setStartBefore(top.firstChild);
204 var found = findleft(p.previousSibling);
206 r2.setStartAfter(found[0]);
208 r2.setStartBefore(top.firstChild);
211 var p = r.startContainer;
212 while(!p.nextSibling && p != top) {
216 r2.setEndAfter(top.lastChild);
218 var found = findright(p.nextSibling);
220 r2.setEndBefore(found[0]);
222 r2.setEndAfter(top.lastChild);
230 function countChar(str,chr) {
232 for(var i=0;i<str.length;i++) {
234 if(a==undefined) a = i;
239 // return count, first occurence and last occurence
243 function selectParens(ev) {
244 var s = window.getSelection();
245 var r = s.getRangeAt();
246 var r2 = document.createRange();
249 // FIXME: it always selects from the left paren, so clicking on the right-par does not select from the matching left-par
250 // need to abort lpar search if rpar was found and then start with the rpar to the right (or closest) instead
251 function findlpar(x) {
255 if(j = p.nodeValue) {
256 j = countChar(j,"(");
261 for(var i=0;i<p.childNodes.length;i++) {
262 y = findlpar(p.childNodes[i]);
265 p = p.previousSibling;
270 function findrpar(x,count) {
273 count = count || [0];
275 if(j = p.nodeValue) {
276 count[0] += countChar(j,"(")[0];
277 j = countChar(j,")");
285 for(var i=0;i<p.childNodes.length;i++) {
286 y = findrpar(p.childNodes[i],count);
294 var p = r.startContainer;
295 if(p.nodeValue && (j = p.nodeValue.indexOf("("))>=0) {
297 p = p.parentNode.nextSibling;
299 while(!p.previousSibling && p != ev.target) {
304 var found = findlpar(p);
306 r2.setStart(found[0],found[1]+1);
309 var found = findrpar(p);
311 r2.setEnd(found[0],found[1]);
318 var x = document.getElementsByClassName("lang-sc");
319 for(var i=0;i<x.length;i++) {
322 // make all code examples editable!
323 e.setAttribute("contentEditable",true);
325 // select parenthesis on double-click
326 e.ondblclick = selectParens;
329 addInheritedMethods();
331 if(sessionStorage == undefined)
337 var toggleMenu = function(e) {
339 openMenu.style.display = 'none';
342 e.style.display = 'block';
345 openMenu = undefined;
350 document.onclick = function() {
351 if(openMenu && !inMenu) {
352 openMenu.style.display = 'none';
353 openMenu = undefined;
360 var bar = document.getElementById("menubar");
362 var nav = ["Home","Browse","Search"];
363 var url = ["Help.html","Browse.html","Search.html"];
364 for(var i=0;i<nav.length;i++) {
365 var li = document.createElement("li");
366 li.className = "menuitem";
367 var a = document.createElement("a");
368 a.innerHTML = nav[i];
369 a.setAttribute("href",helpRoot+"/"+url[i]);
370 a.className = "navLink";
375 var li = document.createElement("li");
376 li.className = "menuitem";
377 var a = document.createElement("a");
378 a.innerHTML = "Indexes ▼";
379 a.setAttribute("href","#");
380 var m1 = document.createElement("div");
381 m1.className = "submenu";
382 m1.style.display = "none";
383 a.onclick = function() {
387 var nav = ["Documents","Classes","Methods"];
388 for(var i=0;i<nav.length;i++) {
389 var b = document.createElement("a");
390 b.setAttribute("href",helpRoot+"/Overviews/"+nav[i]+".html");
391 b.innerHTML = nav[i];
398 var li = document.createElement("li");
399 li.className = "menuitem";
400 var x = document.createElement("span");
401 x.id = "topdoctitle";
402 x.appendChild(document.createTextNode(document.title));
403 x.onclick = function() {
410 var t = document.getElementById("toc");
413 x.appendChild(document.createTextNode(" - "));
414 t.style.display = 'none';
415 t.onclick = function() {
416 t.style.display = 'none';
417 openMenu = undefined;
421 var a = document.createElement("a");
422 a.setAttribute("href","#");
423 a.innerHTML = "Table of contents ▼";
425 a.onclick = function() {
429 li.appendChild(t.parentNode.removeChild(t));
430 var p = document.createElement("a");
431 p.setAttribute("href","#");
432 p.className = "popoutlink";
433 p.innerHTML = "pop out";
434 p.onclick = function() {
439 t.insertBefore(p,t.firstChild);
441 if(sessionStorage.popToc == "yes") {
445 window.onresize = resize_handler;