CheckBadValues should run on the first sample as well
[supercollider.git] / HelpSource / Search.html
bloba2f0b4dfd56aea6030d60f06976db5ffa7254854
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 ext = 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,ext:ext});
147 function onLoad() {
148 helpRoot="."; fixTOC();
149 newinput = document.getElementById("search_input").value;
151 checkboxes = [];
152 for(var i=0;i<fields.length;i++) {
153 checkboxes[i] = document.getElementById("check_"+fields[i]);
154 checkboxes[i].onchange = doSearch;
157 var x = ["check_extensions", "check_methods","ignore_case","check_word","check_prefix","check_suffix"];
158 for(var i=0;i<x.length;i++) {
159 document.getElementById(x[i]).onchange = doSearch;
162 document.getElementById("check_regexp").onchange = function(e) {
163 var x = document.getElementsByClassName("nonregex");
164 for(var i=0;i<x.length;i++) {
165 x[i].disabled = e.target.checked;
167 doSearch();
170 document.getElementById("search_input").focus();
172 node = document.getElementById("search_results");
174 checkHash();
176 buildMethodList();
178 filter = document.getElementById("menu_filter");
179 filter.onchange = doSearch;
181 setInterval(delayed_update,250);
184 function checkHash() {
185 var x = unescape(window.location.hash.slice(1));
186 if(x!="" && newinput!=x) {
187 document.getElementById("search_input").value = x;
188 newinput = x;
189 window.location.hash = "";
193 function SearchKeyPressed(e) {
194 newinput = e.value;
195 if(newinput != input) {
196 document.getElementById("search_results").innerHTML = "Searching...";
200 /*function updateHash() {
201 if(window.location.hash != input)
202 window.location.hash = input;
203 return true;
206 function matchDoc(doc,file,folder,re) {
207 doc.matched_kw = null;
209 if(filter.value != "all") {
210 if(folder.toLowerCase() != filter.value)
211 return false;
214 if(doc.installed=="extension" && !document.getElementById("check_extensions").checked)
215 return false;
217 for(var i=0;i<fields.length;i++) {
218 var f = fields[i];
219 if(checkboxes[i].checked && doc.hasOwnProperty(f) && re.test(doc[f])) {
220 doc.match_weight = i;
221 return true;
225 if(doc.hasOwnProperty('keywords')) {
226 for(var i=0;i<doc.keywords.length;i++) {
227 var kw = doc.keywords[i];
228 if(re.test(kw)) {
229 doc.matched_kw = kw;
230 doc.match_weight = fields.length;
231 return true;
236 return false;
239 var cindex;
240 var cindex2;
241 var mindex;
242 var inProgress = false;
243 var foundMets;
244 var mets;
245 var docs;
246 var re;
247 var node;
248 var subclassCache = {};
250 function getSubClasses(doc) {
251 var a = [];
252 if(doc.subclasses) {
253 for(var i=0;i<doc.subclasses.length;i++) {
254 var x = doc.subclasses[i];
255 var v = docmap["Classes/"+x];
256 a.push(x);
257 if(v)
258 a = a.concat(getSubClasses(v));
261 return a;
264 function doPrint() {
265 var now = Date.now();
266 inProgress = false;
267 for(; cindex<docs.length; cindex++) {
268 var k = docs[cindex][0];
269 var c = docs[cindex][1];
270 if(cindex2==0) {
271 var div = document.createElement("div");
272 div.className="result_category";
273 if(!k) k = "(uncategorized)";
274 div.innerHTML = k;
275 node.appendChild(div);
277 for(;cindex2<c.length;cindex2++) {
278 var v = c[cindex2];
279 var x = v.path.split("/");
280 var div = document.createElement("div");
281 div.className = "result_item";
283 var n = document.createElement("a");
284 if(v.matched_kw) {
285 n.setAttribute("href",v.path+".html#kw_"+v.matched_kw);
286 } else {
287 n.setAttribute("href",v.path+".html");
289 n.innerHTML = v.title;
290 div.appendChild(n);
291 div.appendChild(document.createTextNode(" - "+v.summary+" "));
293 if(v.installed!="standard") {
294 var n = document.createElement("span");
295 n.className = "soft";
296 var res = "[";
297 if(v.installed=="extension")
298 res += "+";
299 else if(v.installed=="missing")
300 res += "missing!";
301 n.innerHTML = res+"]";
303 div.appendChild(n);
306 node.appendChild(div);
308 if(Date.now()-now > 200) {
309 inProgress = true;
310 return;
314 cindex2=0;
317 if(foundMets) {
318 if(mindex==0) {
319 var div = document.createElement("div");
320 div.className="result_category";
321 div.innerHTML = "Methods";
322 node.appendChild(div);
325 for(;mindex<mets.length; mindex++) {
326 var mname = mets[mindex][0]; //name
327 var div = document.createElement("div");
328 div.className = "result_item";
329 var x = document.createElement("div");
330 x.appendChild(document.createTextNode(mname));
331 x.className = "result_met";
332 div.appendChild(x);
334 var x = mets[mindex][1].sort(function(a,b) { //document list
335 a = a.pfx + a.doc.title;
336 b = b.pfx + b.doc.title;
337 if(a<b) return -1;
338 else
339 if(a>b) return +1;
340 else
341 return 0;
344 for(var i=0;i<x.length;i++) {
345 var m = x[i];
346 var v = m.doc;
348 var div2 = document.createElement("div");
349 div2.className = "met_docs";
350 div.appendChild(div2);
352 var p = m.pfx;
353 if(p==".") p=" ";
354 div2.appendChild(document.createTextNode(p+" "));
355 var a = document.createElement("a");
356 a.setAttribute("href",helpRoot+"/"+v.path+".html#"+m.pfx+mname);
357 a.innerHTML = v.title;
358 div2.appendChild(a);
359 if(m.ext)
360 div2.appendChild(document.createTextNode("+"));
361 div2.appendChild(document.createTextNode(" - "+v.summary+" "));
362 var n = document.createElement("span");
363 n.className = "soft";
364 var res = "["+v.path.split("/")[0];
365 if(v.installed=="extension")
366 res += " +";
367 else if(v.installed=="missing")
368 res += " - missing!";
369 n.innerHTML = res+"]";
370 div2.appendChild(n);
371 if(v.path=="Classes/Object") {
372 var n = document.createElement("div");
373 n.className = "met_subclasses";
374 n.appendChild(document.createTextNode("Inherited by: All classes"));
375 div2.appendChild(n);
376 } else {
377 if(v.subclasses && v.subclasses.length>0) {
378 var n;
379 if(subclassCache[v.path]) {
380 n = subclassCache[v.path].cloneNode(true);
381 } else {
382 var subs = getSubClasses(v);
383 n = document.createElement("div");
384 var m = n;
385 n.className = "met_subclasses";
386 n.appendChild(document.createTextNode("Inherited by: "));
387 for(var j=0;j<subs.length;j++) {
388 var a = document.createElement("a");
389 a.setAttribute("href", helpRoot+"/Classes/"+subs[j]+".html");
390 if(j==10 && subs.length > 14) {
391 m = document.createElement("span");
392 m.className = "hiddenspan";
393 m.style.display = "none";
394 n.appendChild(m);
395 var a2 = document.createElement("a");
396 a2.setAttribute("href","#");
397 a2.className = "seemore";
398 a2.innerHTML = "&hellip; see "+(subs.length-10)+" more";
399 n.appendChild(document.createTextNode(" "));
400 n.appendChild(a2);
402 if(j>0)
403 m.appendChild(document.createTextNode(", "));
404 a.innerHTML = subs[j];
405 m.appendChild(a);
407 subclassCache[v.path] = n;
409 (function() {
410 var a = n.getElementsByClassName("seemore")[0];
411 if(a) {
412 var m = n.getElementsByClassName("hiddenspan")[0];
413 a.onclick = function() {
414 m.style.display = "";
415 a.parentNode.removeChild(a);
416 return false;
419 })();
420 div2.appendChild(n);
425 node.appendChild(div);
427 if(Date.now()-now > 200) {
428 inProgress = true;
429 return;
435 function randomDoc() {
436 while(node.hasChildNodes())
437 node.removeChild(node.lastChild);
439 cindex = 0;
440 cindex2 = 0;
441 mindex = 0;
442 foundMets = false;
443 mets = [];
445 document.getElementById("search_input").value = "";
447 var list = [];
448 for(var k in docmap) {
449 if(docmap.hasOwnProperty(k))
450 list.push(docmap[k]);
453 for(var i=0;i<100;i++) {
454 var v = list[Math.floor(Math.random()*list.length)];
455 if(! /Undocumented classes/.test(v.categories)) {
456 docs = [[v.path.split("/")[0],[v]]];
457 break;
461 doPrint();
463 document.getElementById("search_count").innerHTML = "random document";
466 function doSearch() {
467 var count = 0;
469 while(node.hasChildNodes())
470 node.removeChild(node.lastChild);
472 cindex = 0;
473 cindex2 = 0;
474 mindex = 0;
475 foundMets = false;
476 cats = [];
477 mets = [];
479 if(input!="") {
481 // setup regexp
482 try {
483 var str = input;
484 if(!document.getElementById("check_regexp").checked) {
485 str = escape_regexp(str); //escape special chars
486 if(document.getElementById("check_word").checked)
487 str = "\\b" + str + "\\b";
488 if(document.getElementById("check_prefix").checked)
489 str = "^" + str;
490 if(document.getElementById("check_suffix").checked)
491 str = str + "$";
493 re = RegExp(str,document.getElementById("ignore_case").checked?"i":"");
494 } catch(err) {
495 document.getElementById("search_count").innerHTML = "Invalid regexp";
496 document.getElementById("search_results").innerHTML = err;
497 return;
500 // search docmap
501 docs = {};
502 for(var k in docmap) {
503 var v = docmap[k];
504 var x = v.path.split("/");
505 var folder = x[0];
506 var file = x[x.length-1];
508 if(matchDoc(v,file,folder,re)) {
509 if(!docs.hasOwnProperty(folder))
510 docs[folder]=[];
511 docs[folder].push(v);
512 count++;
515 var tmp = []; for(var k in docs) tmp.push(
516 [k, docs[k].sort(function(a,b) {
517 a = a.match_weight;
518 b = b.match_weight;
519 if(a<b) return -1;
520 else
521 if(a>b) return 1;
522 else
523 return 0;
526 var order = { Classes:1, Reference:2, Overviews:3, Guides:4, Tutorials:5 };
527 docs = tmp.sort(function(a,b) {
528 a = order[a[0]] || 10;
529 b = order[b[0]] || 10;
530 if(a<b) return -1;
531 else
532 if(a>b) return 1;
533 else
534 return 0;
537 // search methods
538 var include_ext_classes = document.getElementById("check_extensions").checked;
539 var filter_val = filter.value;
540 if(document.getElementById("check_methods").checked) {
541 for(var mname in methods) {
542 var m = methods[mname];
543 if(re.test(mname)) {
544 var c = [];
545 for(var i=0;i<m.length;i++) {
546 var doc = m[i].doc;
547 if(!doc) continue;
548 if(doc.installed == "extension" && !include_ext_classes) continue;
549 if(filter_val != "all" && doc.path.split("/")[0].toLowerCase() != filter_val) continue
550 c.push(m[i]);
552 if(c.length>0) {
553 mets.push([mname,c]);
554 foundMets = true;
555 count++;
561 doPrint();
564 document.getElementById("search_count").innerHTML = count+" results";
567 function delayed_update() {
568 if(input != newinput) {
569 input = newinput;
570 doSearch();
571 } else if(inProgress) {
572 doPrint();
575 window.onhashchange = checkHash;
576 </script>
578 </head>
580 <ul id="menubar"></ul>
581 <body onload="onLoad()">
582 <div class='contents'>
583 <div class='header'>
584 <div id='label'>SuperCollider</div>
585 <h1>Search</h1>
586 <div id='summary'>Search all documents</div>
587 </div>
588 <div id="search_checks0">
589 Filter:
590 <select id="menu_filter">
591 <option SELECTED value="all">All documents</option>
592 <option value="classes">Classes only</option>
593 <option value="reference">Reference only</option>
594 <option value="guides">Guides only</option>
595 <option value="tutorials">Tutorials only</option>
596 <option value="overviews">Overviews only</option>
597 <option value="other">Other only</option>
598 </select>
599 <input type="checkbox" id="check_extensions" checked="true">Include extensions</input>
600 </div>
602 <div id="search_box">
603 Search text:<input type="text" id="search_input" value="" size="40" onkeyup="SearchKeyPressed(this)"/>
604 </div>
606 <table id="search_settings">
607 <td>Options:
608 <td>
609 <div id="search_checks">
610 <input type="checkbox" id="ignore_case" checked="true">Ignore case</input>
611 <input class="nonregex" type="checkbox" id="check_word">Whole word</input>
612 <input class="nonregex" type="checkbox" id="check_prefix">Starts with</input>
613 <input class="nonregex" type="checkbox" id="check_suffix">Ends with</input>
614 <input type="checkbox" id="check_regexp">Regexp</input>
615 </div>
616 <tr>
617 <td>Match:
618 <td>
619 <div id="search_checks">
620 <input type="checkbox" id="check_title" checked="true">Title/Class</input>
621 <input type="checkbox" id="check_summary" checked="true">Summary</input>
622 <input type="checkbox" id="check_categories">Categories</input>
623 <input type="checkbox" id="check_methods" checked="true">Methods</input>
624 </div>
625 </table>
626 <div id="random"><a href="javascript:randomDoc()">random page</a></div>
627 <div id="search_count">0 results</div>
628 <div id="search_results"></div>
629 <div id="js_error"></div>
630 </div>
631 </body>
632 </html>