Forgot a help fix: Drag a dock's title bar, not divider, to reposition
[supercollider.git] / HelpSource / Search.html
blob11ada6d709812db5d5362d0090ea175a9e593281
1 <html>
2 <head>
3 <title>Search</title>
4 <link rel='stylesheet' href='./scdoc.css' type='text/css' />
5 <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
6 <script src="docmap.js" type="text/javascript"></script>
7 <script src="scdoc.js" type="text/javascript"></script>
8 <!-- <script src="methods.js" type="text/javascript"></script>-->
9 <style>
10 div#search_box {
11 margin: 1.5em;
12 text-align: center;
14 #search_input {
15 border: 1px solid #aaa;
16 background: #eee;
17 margin-left: 0.5em;
19 div#search_count {
20 border-bottom: 2px solid #aaa;
21 color: #333;
24 div.result_item {
25 margin-bottom: 0.1em;
26 margin-left: 2em;
28 .result_met {
29 font-family: Andale Mono, monospace;
30 font-size: 9.5pt;
31 margin-top: 1em;
32 margin-left: -1em;
33 margin-bottom: 0.5em;
35 div.result_category {
36 color: #555;
37 margin-top: 1em;
38 margin-bottom: 0.5em;
39 /* font-size: 9.5pt;
40 border-bottom: 1px solid #ccc;*/
41 font-weight: bold;
42 /* font-size: 11pt;*/
44 div.met_docs {
45 margin-bottom: 0.2em;
46 /* margin-left: 2em;*/
48 div.met_subclasses {
49 font-size: 9pt;
50 color: #777;
51 margin-left: 3em;
52 text-align: left;
54 div.met_subclasses a {
55 color: #444;
57 div.met_subclasses a.seemore {
58 margin-left: 0.2em;
59 color: #558;
61 #search_checks {
62 padding: 0.5em;
63 padding-top: 0.25em;
64 padding-bottom: 0.25em;
65 font-size: 9pt;
66 color: #555;
67 background: #eee;
69 #search_checks0 {
70 font-size: 9pt;
71 color: #555;
72 border-bottom: 1px solid #ddd;
73 margin-top: 1em;
74 padding-bottom: 1em;
76 table#search_settings {
77 font-size: 9pt;
78 color: #555;
79 width: 100%;
80 margin-left: 0px;
81 margin-right: 0px;*/
82 margin: 0px;
83 padding: 0px;
84 border-collapse: collapse;
86 #search_settings td {
87 border: none;
88 padding: 2px;
90 #random {
91 text-align: right;
92 font-size: 9pt;
94 #js_error {
95 font-family: Andale Mono, monospace;
96 font-size: 9pt;
97 color: red;
100 </style>
101 <noscript>
102 <p>The search page needs JavaScript.
103 </noscript>
105 <script type="text/javascript">
106 var input = "";
107 var newinput = "";
108 var checkboxes;
109 var fields = ["title","summary","categories"];
110 var filter;
111 //var docmapdict = {};
113 escape_regexp = function(str) {
114 var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); // .*+?|()[]{}\
115 return str.replace(specials, "\\$&");
118 function debug(str) {
119 document.getElementById("js_error").innerHTML += str + "<br>"
122 var methods;
123 function buildMethodList() {
124 methods = {};
125 for(var k in docmap) {
126 var doc = docmap[k];
127 var mets = doc.methods;
128 if(mets) {
129 for(var j=0;j<mets.length;j++) {
130 var m = mets[j];
131 var mname = m.slice(2);
132 var pfx = m[1];
133 var undoc = m[0]=="?";
134 if(!methods.hasOwnProperty(mname))
135 methods[mname] = [];
136 if(!methods[mname].push) {
137 debug("Problem with method '"+mname+"' in "+doc.path);
138 debug(methods[mname].toString());
139 } else {
140 methods[mname].push({doc:doc,pfx:pfx,undoc:undoc});
147 function getQuerystring(key)
149 key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
150 var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
151 var qs = regex.exec(window.location.href);
152 if(qs == null)
153 return null;
154 else
155 return qs[1];
158 function onLoad() {
159 helpRoot="."; fixTOC();
160 newinput = document.getElementById("search_input").value;
162 checkboxes = [];
163 for(var i=0;i<fields.length;i++) {
164 checkboxes[i] = document.getElementById("check_"+fields[i]);
167 var x = ["check_extensions", "check_methods","ignore_case","check_word","check_prefix","check_suffix","check_title","check_summary","check_categories"];
168 for(var i=0;i<x.length;i++) {
169 document.getElementById(x[i]).onchange = doSearch;
172 for(var i=0;i<x.length;i++) {
173 var name = x[i];
174 var val = getQuerystring(name);
175 if(val == "true")
176 document.getElementById(name).checked = true;
177 else if(val == "false")
178 document.getElementById(name).checked = false;
181 document.getElementById("check_regexp").onchange = function(e) {
182 var x = document.getElementsByClassName("nonregex");
183 for(var i=0;i<x.length;i++) {
184 x[i].disabled = e.target.checked;
186 doSearch();
189 document.getElementById("search_input").focus();
191 node = document.getElementById("search_results");
193 checkHash();
195 buildMethodList();
197 filter = document.getElementById("menu_filter");
198 filter.onchange = doSearch;
200 setInterval(delayed_update,250);
203 function checkHash() {
204 var x = unescape(window.location.hash.slice(1));
205 if(x!="" && newinput!=x) {
206 document.getElementById("search_input").value = x;
207 newinput = x;
208 // window.location.hash = "";
212 function SearchKeyPressed(e) {
213 newinput = e.value;
214 if(newinput != input) {
215 document.getElementById("search_results").innerHTML = "Searching...";
219 /*function updateHash() {
220 if(window.location.hash != input)
221 window.location.hash = input;
222 return true;
225 function matchDoc(doc,file,folder,re) {
226 doc.matched_kw = null;
228 if(filter.value != "all") {
229 if(folder.toLowerCase() != filter.value)
230 return false;
233 if(doc.installed=="extension" && !document.getElementById("check_extensions").checked)
234 return false;
236 for(var i=0;i<fields.length;i++) {
237 var f = fields[i];
238 if(checkboxes[i].checked && doc.hasOwnProperty(f) && re.test(doc[f])) {
239 doc.match_weight = i;
240 return true;
244 if(doc.hasOwnProperty('path') && checkboxes[0].checked && re.test(file)) {
245 return true;
248 if(doc.hasOwnProperty('keywords')) {
249 for(var i=0;i<doc.keywords.length;i++) {
250 var kw = doc.keywords[i];
251 if(re.test(kw)) {
252 doc.matched_kw = kw;
253 doc.match_weight = fields.length;
254 return true;
259 return false;
262 var cindex;
263 var cindex2;
264 var mindex;
265 var inProgress = false;
266 var foundMets;
267 var mets;
268 var docs;
269 var re;
270 var node;
271 var subclassCache = {};
273 function strCmp(a,b) {
274 if(a<b) return -1;
275 else
276 if(a>b) return 1;
277 else
278 return 0;
281 function getSubClasses(doc) {
282 var a = [];
283 if(doc.subclasses) {
284 for(var i=0;i<doc.subclasses.length;i++) {
285 var x = doc.subclasses[i];
286 var v = docmap["Classes/"+x];
287 a.push(x);
288 if(v)
289 a = a.concat(getSubClasses(v));
292 return a;
295 function doPrint() {
296 var now = Date.now();
297 inProgress = false;
298 for(; cindex<docs.length; cindex++) {
299 var k = docs[cindex][0];
300 var c = docs[cindex][1];
301 if(cindex2==0) {
302 var div = document.createElement("div");
303 div.className="result_category";
304 if(!k) k = "(uncategorized)";
305 div.innerHTML = k;
306 node.appendChild(div);
308 for(;cindex2<c.length;cindex2++) {
309 var v = c[cindex2];
310 var x = v.path.split("/");
311 var div = document.createElement("div");
312 div.className = "result_item";
314 var n = document.createElement("a");
315 if(v.matched_kw) {
316 n.setAttribute("href",v.path+".html#kw_"+v.matched_kw);
317 } else {
318 var link = v.hasOwnProperty("oldhelp")?v.oldhelp:(v.path+".html");
319 n.setAttribute("href",link);
321 n.innerHTML = v.title;
322 div.appendChild(n);
323 if(/Undocumented classes/.test(v.categories)) {
324 n.className = "undoc";
325 div.appendChild(document.createTextNode(" - "));
326 } else {
327 div.appendChild(document.createTextNode(" - "+v.summary+" "));
330 if(v.installed!="standard") {
331 var n = document.createElement("span");
332 n.className = "soft";
333 var res = "[";
334 if(v.installed=="extension")
335 res += "+";
336 else if(v.installed=="missing")
337 res += "missing!";
338 n.innerHTML = res+"]";
340 div.appendChild(n);
343 node.appendChild(div);
345 if(Date.now()-now > 200) {
346 inProgress = true;
347 return;
351 cindex2=0;
354 if(foundMets) {
355 if(mindex==0) {
356 var div = document.createElement("div");
357 div.className="result_category";
358 div.innerHTML = "Methods";
359 node.appendChild(div);
362 for(;mindex<mets.length; mindex++) {
363 var mname = mets[mindex][0]; //name
364 var div = document.createElement("div");
365 div.className = "result_item";
366 var x = document.createElement("div");
367 x.appendChild(document.createTextNode(mname));
368 x.className = "result_met";
369 div.appendChild(x);
370 var cnt = document.createElement("span");
371 cnt.className = "soft";
372 cnt.innerHTML = " ("+mets[mindex][1].length+" matches)";
373 x.appendChild(cnt);
375 var x = mets[mindex][1].sort(function(a,b) { //document list
376 a = a.pfx + a.doc.title;
377 b = b.pfx + b.doc.title;
378 return strCmp(a,b);
381 for(var i=0;i<x.length;i++) {
382 var m = x[i];
383 var v = m.doc;
385 var div2 = document.createElement("div");
387 div2.className = "met_docs";
389 div.appendChild(div2);
391 var p = m.pfx;
392 if(p==".") p=" ";
393 div2.appendChild(document.createTextNode(p+" "));
394 var a = document.createElement("a");
395 a.setAttribute("href",helpRoot+"/"+v.path+".html#"+m.pfx+mname);
396 a.innerHTML = v.title;
397 if(m.undoc)
398 a.className = "undoc";
399 div2.appendChild(a);
401 if(/Undocumented classes/.test(v.categories)) {
402 div2.appendChild(document.createTextNode(" - "));
403 } else {
404 div2.appendChild(document.createTextNode(" - "+v.summary+" "));
407 var n = document.createElement("span");
408 n.className = "soft";
409 var res = "["+v.path.split("/")[0];
410 if(v.installed=="extension")
411 res += " +";
412 else if(v.installed=="missing")
413 res += " - missing!";
414 n.innerHTML = res+"]";
415 div2.appendChild(n);
416 if(v.path=="Classes/Object") {
417 var n = document.createElement("div");
418 n.className = "met_subclasses";
419 n.appendChild(document.createTextNode("Inherited by: All classes"));
420 div2.appendChild(n);
421 } else {
422 if(v.subclasses && v.subclasses.length>0) {
423 var n;
424 if(subclassCache[v.path]) {
425 n = subclassCache[v.path].cloneNode(true);
426 } else {
427 var subs = getSubClasses(v);
428 n = document.createElement("div");
429 var m = n;
430 n.className = "met_subclasses";
431 n.appendChild(document.createTextNode("Inherited by: "));
432 for(var j=0;j<subs.length;j++) {
433 var a = document.createElement("a");
434 a.setAttribute("href", helpRoot+"/Classes/"+subs[j]+".html");
435 if(j==10 && subs.length > 14) {
436 m = document.createElement("span");
437 m.className = "hiddenspan";
438 m.style.display = "none";
439 n.appendChild(m);
440 var a2 = document.createElement("a");
441 a2.setAttribute("href","#");
442 a2.className = "seemore";
443 a2.innerHTML = "&hellip; see "+(subs.length-10)+" more";
444 n.appendChild(document.createTextNode(" "));
445 n.appendChild(a2);
447 if(j>0)
448 m.appendChild(document.createTextNode(", "));
449 a.innerHTML = subs[j];
450 m.appendChild(a);
452 subclassCache[v.path] = n;
454 (function() {
455 var a = n.getElementsByClassName("seemore")[0];
456 if(a) {
457 var m = n.getElementsByClassName("hiddenspan")[0];
458 a.onclick = function() {
459 m.style.display = "";
460 a.parentNode.removeChild(a);
461 return false;
464 })();
465 div2.appendChild(n);
470 node.appendChild(div);
472 if(Date.now()-now > 200) {
473 inProgress = true;
474 return;
480 function randomDoc() {
481 while(node.hasChildNodes())
482 node.removeChild(node.lastChild);
484 cindex = 0;
485 cindex2 = 0;
486 mindex = 0;
487 foundMets = false;
488 mets = [];
490 document.getElementById("search_input").value = "";
492 var list = [];
493 for(var k in docmap) {
494 if(docmap.hasOwnProperty(k))
495 list.push(docmap[k]);
498 for(var i=0;i<100;i++) {
499 var v = list[Math.floor(Math.random()*list.length)];
500 if(! /Undocumented classes/.test(v.categories)) {
501 docs = [[v.path.split("/")[0],[v]]];
502 break;
506 doPrint();
508 document.getElementById("search_count").innerHTML = "random document";
511 function doSearch() {
512 var count = 0;
514 while(node.hasChildNodes())
515 node.removeChild(node.lastChild);
517 cindex = 0;
518 cindex2 = 0;
519 mindex = 0;
520 foundMets = false;
521 cats = [];
522 mets = [];
524 if(input!="") {
526 // setup regexp
527 try {
528 var str = input;
529 if(!document.getElementById("check_regexp").checked) {
530 str = escape_regexp(str); //escape special chars
531 if(document.getElementById("check_word").checked)
532 str = "\\b" + str + "\\b";
533 if(document.getElementById("check_prefix").checked)
534 str = "^" + str;
535 if(document.getElementById("check_suffix").checked)
536 str = str + "$";
538 re = RegExp(str,document.getElementById("ignore_case").checked?"i":"");
539 } catch(err) {
540 document.getElementById("search_count").innerHTML = "Invalid regexp";
541 document.getElementById("search_results").innerHTML = err;
542 return;
545 // search docmap
546 docs = {};
547 for(var k in docmap) {
548 var v = docmap[k];
549 var x = v.path.split("/");
550 var folder = x[0];
551 var file = x[x.length-1];
553 if(matchDoc(v,file,folder,re)) {
554 if(!docs.hasOwnProperty(folder))
555 docs[folder]=[];
556 docs[folder].push(v);
557 count++;
560 var tmp = []; for(var k in docs) tmp.push(
561 [k, docs[k].sort(function(a,b) {
562 a = a.title;
563 b = b.title;
564 return strCmp(a,b);
567 var order = { Classes:1, Reference:2, Overviews:3, Guides:4, Tutorials:5 };
568 docs = tmp.sort(function(a,b) {
569 a = order[a[0]] || 10;
570 b = order[b[0]] || 10;
571 return strCmp(a,b);
574 // search methods
575 var include_ext_classes = document.getElementById("check_extensions").checked;
576 var filter_val = filter.value;
577 if(document.getElementById("check_methods").checked) {
578 for(var mname in methods) {
579 var m = methods[mname];
580 if(re.test(mname)) {
581 var c = [];
582 for(var i=0;i<m.length;i++) {
583 var doc = m[i].doc;
584 if(!doc) continue;
585 if(doc.installed == "extension" && !include_ext_classes) continue;
586 if(filter_val != "all" && doc.path.split("/")[0].toLowerCase() != filter_val) continue
587 c.push(m[i]);
589 if(c.length>0) {
590 mets.push([mname,c]);
591 foundMets = true;
592 count++;
596 mets = mets.sort(function(a,b) {
597 a = a[0];
598 b = b[0];
599 return strCmp(a,b);
603 doPrint();
606 document.getElementById("search_count").innerHTML = count+" results";
609 function delayed_update() {
610 if(input != newinput) {
611 input = newinput;
612 doSearch();
613 } else if(inProgress) {
614 doPrint();
617 window.onhashchange = checkHash;
618 </script>
620 </head>
622 <ul id="menubar"></ul>
623 <body onload="onLoad()">
624 <div class='contents'>
625 <div class='header'>
626 <div id='label'>SuperCollider</div>
627 <h1>Search</h1>
628 <div id='summary'>Search all documents</div>
629 </div>
630 <div id="search_checks0">
631 Filter:
632 <select id="menu_filter">
633 <option SELECTED value="all">All documents</option>
634 <option value="classes">Classes only</option>
635 <option value="reference">Reference only</option>
636 <option value="guides">Guides only</option>
637 <option value="tutorials">Tutorials only</option>
638 <option value="overviews">Overviews only</option>
639 <option value="other">Other only</option>
640 </select>
641 <input type="checkbox" id="check_extensions" checked="true">Include extensions</input>
642 </div>
644 <div id="search_box">
645 Search text:<input type="text" id="search_input" value="" size="40" onkeyup="SearchKeyPressed(this)"/>
646 </div>
648 <table id="search_settings">
649 <td>Options:
650 <td>
651 <div id="search_checks">
652 <input type="checkbox" id="ignore_case" checked="true">Ignore case</input>
653 <input class="nonregex" type="checkbox" id="check_word">Whole word</input>
654 <input class="nonregex" type="checkbox" id="check_prefix">Starts with</input>
655 <input class="nonregex" type="checkbox" id="check_suffix">Ends with</input>
656 <input type="checkbox" id="check_regexp">Regexp</input>
657 </div>
658 <tr>
659 <td>Match:
660 <td>
661 <div id="search_checks">
662 <input type="checkbox" id="check_title" checked="true">Title/Filename</input>
663 <input type="checkbox" id="check_summary" checked="true">Summary</input>
664 <input type="checkbox" id="check_categories">Categories</input>
665 <input type="checkbox" id="check_methods" checked="true">Methods</input>
666 </div>
667 </table>
668 <div id="random"><a href="javascript:randomDoc()">random page</a></div>
669 <div id="search_count">0 results</div>
670 <div id="search_results"></div>
671 <div id="js_error"></div>
672 </div>
673 </body>
674 </html>