source: tspsg-svn/trunk/docs/html/search/search.js @ 112

Last change on this file since 112 was 112, checked in by laleppa, 14 years ago

Updated translations and regenerated documentation.

File size: 20.4 KB
Line 
1// Search script generated by doxygen
2// Copyright (C) 2009 by Dimitri van Heesch.
3
4// The code in this file is loosly based on main.js, part of Natural Docs,
5// which is Copyright (C) 2003-2008 Greg Valure
6// Natural Docs is licensed under the GPL.
7
8var indexSectionsWithContent =
9{
10  0: "000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111100000",
11  1: "000000000000000000000000000000000000000000000000000000000000000001011111010101111101111100000000",
12  2: "000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000",
13  3: "000000000000000000000000000000000000000000000000000000000000000000001001000001011111101000000000",
14  4: "000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111100000",
15  5: "000000000000000000000000000000000000000000000000000000000000000001010000000001101000000000000000",
16  6: "000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000",
17  7: "000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000",
18  8: "000000000000000000000000000000000000000000000000000000000000000000000000000010100010000000000000",
19  9: "000000000000000000000000000000000000000000000000000000000000000001101000010001011100101000100000"
20};
21
22var indexSectionNames =
23{
24  0: "all",
25  1: "classes",
26  2: "namespaces",
27  3: "files",
28  4: "functions",
29  5: "variables",
30  6: "typedefs",
31  7: "enums",
32  8: "enumvalues",
33  9: "defines"
34};
35
36function convertToId(search)
37{
38  var result = '';
39  for (i=0;i<search.length;i++)
40  {
41    var c = search.charAt(i);
42    var cn = c.charCodeAt(0);
43    if (c.match(/[a-z0-9]/))
44    {
45      result+=c;
46    }
47    else if (cn<16) 
48    {
49      result+="_0"+cn.toString(16);
50    }
51    else 
52    {
53      result+="_"+cn.toString(16);
54    }
55  }
56  return result;
57}
58
59function getXPos(item)
60{
61  var x = 0;
62  if (item.offsetWidth)
63  {
64    while (item && item!=document.body)
65    {
66      x   += item.offsetLeft;
67      item = item.offsetParent;
68    }
69  }
70  return x;
71}
72
73function getYPos(item)
74{
75  var y = 0;
76  if (item.offsetWidth)
77  {
78     while (item && item!=document.body)
79     {
80       y   += item.offsetTop;
81       item = item.offsetParent;
82     }
83  }
84  return y;
85}
86
87/* A class handling everything associated with the search panel.
88
89   Parameters:
90   name - The name of the global variable that will be
91          storing this instance.  Is needed to be able to set timeouts.
92   resultPath - path to use for external files
93*/
94function SearchBox(name, resultsPath, inFrame, label)
95{
96  if (!name || !resultsPath) {  alert("Missing parameters to SearchBox."); }
97   
98  // ---------- Instance variables
99  this.name                  = name;
100  this.resultsPath           = resultsPath;
101  this.keyTimeout            = 0;
102  this.keyTimeoutLength      = 500;
103  this.closeSelectionTimeout = 300;
104  this.lastSearchValue       = "";
105  this.lastResultsPage       = "";
106  this.hideTimeout           = 0;
107  this.searchIndex           = 0;
108  this.searchActive          = false;
109  this.insideFrame           = inFrame;
110  this.searchLabel           = label;
111
112  // ----------- DOM Elements
113
114  this.DOMSearchField = function()
115  {  return document.getElementById("MSearchField");  }
116
117  this.DOMSearchSelect = function()
118  {  return document.getElementById("MSearchSelect");  }
119
120  this.DOMSearchSelectWindow = function()
121  {  return document.getElementById("MSearchSelectWindow");  }
122
123  this.DOMPopupSearchResults = function()
124  {  return document.getElementById("MSearchResults");  }
125
126  this.DOMPopupSearchResultsWindow = function()
127  {  return document.getElementById("MSearchResultsWindow");  }
128
129  this.DOMSearchClose = function()
130  {  return document.getElementById("MSearchClose"); }
131
132  this.DOMSearchBox = function()
133  {  return document.getElementById("MSearchBox");  }
134
135  // ------------ Event Handlers
136
137  // Called when focus is added or removed from the search field.
138  this.OnSearchFieldFocus = function(isActive)
139  {
140    this.Activate(isActive);
141  }
142
143  this.OnSearchSelectShow = function()
144  {
145    var searchSelectWindow = this.DOMSearchSelectWindow();
146    var searchField        = this.DOMSearchSelect();
147
148    if (this.insideFrame)
149    {
150      var left = getXPos(searchField);
151      var top  = getYPos(searchField);
152      left += searchField.offsetWidth + 6;
153      top += searchField.offsetHeight;
154
155      // show search selection popup
156      searchSelectWindow.style.display='block';
157      left -= searchSelectWindow.offsetWidth;
158      searchSelectWindow.style.left =  left + 'px';
159      searchSelectWindow.style.top  =  top  + 'px';
160    }
161    else
162    {
163      var left = getXPos(searchField);
164      var top  = getYPos(searchField);
165      top += searchField.offsetHeight;
166
167      // show search selection popup
168      searchSelectWindow.style.display='block';
169      searchSelectWindow.style.left =  left + 'px';
170      searchSelectWindow.style.top  =  top  + 'px';
171    }
172
173    // stop selection hide timer
174    if (this.hideTimeout) 
175    {
176      clearTimeout(this.hideTimeout);
177      this.hideTimeout=0;
178    }
179    return false; // to avoid "image drag" default event
180  }
181
182  this.OnSearchSelectHide = function()
183  {
184    this.hideTimeout = setTimeout(this.name +".CloseSelectionWindow()",
185                                  this.closeSelectionTimeout);
186  }
187
188  // Called when the content of the search field is changed.
189  this.OnSearchFieldChange = function(evt)
190  {
191    if (this.keyTimeout) // kill running timer
192    {
193      clearTimeout(this.keyTimeout);
194      this.keyTimeout = 0;
195    }
196
197    var e  = (evt) ? evt : window.event; // for IE
198    if (e.keyCode==40 || e.keyCode==13)
199    {
200      if (e.shiftKey==1)
201      {
202        this.OnSearchSelectShow();
203        var win=this.DOMSearchSelectWindow(); 
204        for (i=0;i<win.childNodes.length;i++)
205        {
206          var child = win.childNodes[i]; // get span within a
207          if (child.className=='SelectItem')
208          {
209            child.focus();
210            return;
211          }
212        }
213        return;
214      }
215      else if (window.frames.MSearchResults.searchResults)
216      {
217        var elem = window.frames.MSearchResults.searchResults.NavNext(0);
218        if (elem) elem.focus();
219      }
220    }
221    else if (e.keyCode==27) // Escape out of the search field
222    {
223      this.DOMSearchField().blur();
224      this.DOMPopupSearchResultsWindow().style.display = 'none';
225      this.DOMSearchClose().style.display = 'none';
226      this.lastSearchValue = '';
227      this.Activate(false);
228      return;
229    }
230
231    // strip whitespaces
232    var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
233
234    if (searchValue != this.lastSearchValue) // search value has changed
235    {
236      if (searchValue != "") // non-empty search
237      {
238        // set timer for search update
239        this.keyTimeout = setTimeout(this.name + '.Search()',
240                                     this.keyTimeoutLength);
241      }
242      else // empty search field
243      {
244        this.DOMPopupSearchResultsWindow().style.display = 'none';
245        this.DOMSearchClose().style.display = 'none';
246        this.lastSearchValue = '';
247      }
248    }
249  }
250
251  this.SelectItemCount = function(id)
252  {
253    var count=0;
254    var win=this.DOMSearchSelectWindow(); 
255    for (i=0;i<win.childNodes.length;i++)
256    {
257      var child = win.childNodes[i]; // get span within a
258      if (child.className=='SelectItem')
259      {
260        count++;
261      }
262    }
263    return count;
264  }
265
266  this.SelectItemSet = function(id)
267  {
268    var i,j=0;
269    var win=this.DOMSearchSelectWindow(); 
270    for (i=0;i<win.childNodes.length;i++)
271    {
272      var child = win.childNodes[i]; // get span within a
273      if (child.className=='SelectItem')
274      {
275        var node = child.firstChild;
276        if (j==id)
277        {
278          node.innerHTML='&bull;';
279        } 
280        else
281        {
282          node.innerHTML='&nbsp;';
283        }
284        j++;
285      }
286    }
287  }
288
289  // Called when an search filter selection is made.
290  // set item with index id as the active item
291  this.OnSelectItem = function(id)
292  {
293    this.searchIndex = id;
294    this.SelectItemSet(id);
295    var searchValue = this.DOMSearchField().value.replace(/ +/g, "");
296    if (searchValue!="" && this.searchActive) // something was found -> do a search
297    {
298      this.Search();
299    }
300  }
301
302  this.OnSearchSelectKey = function(evt)
303  {
304    var e = (evt) ? evt : window.event; // for IE
305    if (e.keyCode==40 && this.searchIndex<this.SelectItemCount()) // Down
306    {
307      this.searchIndex++;
308      this.OnSelectItem(this.searchIndex);
309    }
310    else if (e.keyCode==38 && this.searchIndex>0) // Up
311    {
312      this.searchIndex--;
313      this.OnSelectItem(this.searchIndex);
314    }
315    else if (e.keyCode==13 || e.keyCode==27)
316    {
317      this.OnSelectItem(this.searchIndex);
318      this.CloseSelectionWindow();
319      this.DOMSearchField().focus();
320    }
321    return false;
322  }
323
324  // --------- Actions
325
326  // Closes the results window.
327  this.CloseResultsWindow = function()
328  {
329    this.DOMPopupSearchResultsWindow().style.display = 'none';
330    this.DOMSearchClose().style.display = 'none';
331    this.Activate(false);
332  }
333
334  this.CloseSelectionWindow = function()
335  {
336    this.DOMSearchSelectWindow().style.display = 'none';
337  }
338
339  // Performs a search.
340  this.Search = function()
341  {
342    this.keyTimeout = 0;
343
344    // strip leading whitespace
345    var searchValue = this.DOMSearchField().value.replace(/^ +/, "");
346
347    var code = searchValue.toLowerCase().charCodeAt(0);
348    var hexCode;
349    if (code<16) 
350    {
351      hexCode="0"+code.toString(16);
352    }
353    else 
354    {
355      hexCode=code.toString(16);
356    }
357
358    var resultsPage;
359    var resultsPageWithSearch;
360    var hasResultsPage;
361
362    if (indexSectionsWithContent[this.searchIndex].charAt(code-32) == '1')
363    {
364       resultsPage = this.resultsPath + '/' + indexSectionNames[this.searchIndex] + '_' + hexCode + '.html';
365       resultsPageWithSearch = resultsPage+'?'+escape(searchValue);
366       hasResultsPage = true;
367    }
368    else // nothing available for this search term
369    {
370       resultsPage = this.resultsPath + '/nomatches.html';
371       resultsPageWithSearch = resultsPage;
372       hasResultsPage = false;
373    }
374
375    window.frames.MSearchResults.location.href = resultsPageWithSearch; 
376    var domPopupSearchResultsWindow = this.DOMPopupSearchResultsWindow();
377
378    if (domPopupSearchResultsWindow.style.display!='block')
379    {
380       var domSearchBox = this.DOMSearchBox();
381       this.DOMSearchClose().style.display = 'inline';
382       if (this.insideFrame)
383       {
384         var domPopupSearchResults = this.DOMPopupSearchResults();
385         domPopupSearchResultsWindow.style.position = 'relative';
386         domPopupSearchResultsWindow.style.display  = 'block';
387         var width = document.body.clientWidth - 8; // the -8 is for IE :-(
388         domPopupSearchResultsWindow.style.width    = width + 'px';
389         domPopupSearchResults.style.width          = width + 'px';
390       }
391       else
392       {
393         var domPopupSearchResults = this.DOMPopupSearchResults();
394         var left = getXPos(domSearchBox) + domSearchBox.offsetWidth;
395         var top  = getYPos(domSearchBox) + domSearchBox.offsetHeight + 1;
396         domPopupSearchResultsWindow.style.display = 'block';
397         left -= domPopupSearchResults.offsetWidth;
398         domPopupSearchResultsWindow.style.top     = top  + 'px';
399         domPopupSearchResultsWindow.style.left    = left + 'px';
400       }
401    }
402
403    this.lastSearchValue = searchValue;
404    this.lastResultsPage = resultsPage;
405  }
406
407  // -------- Activation Functions
408
409  // Activates or deactivates the search panel, resetting things to
410  // their default values if necessary.
411  this.Activate = function(isActive)
412  {
413    if (isActive || // open it
414        this.DOMPopupSearchResultsWindow().style.display == 'block' 
415       )
416    {
417      this.DOMSearchBox().className = 'MSearchBoxActive';
418
419      var searchField = this.DOMSearchField();
420
421      if (searchField.value == this.searchLabel) // clear "Search" term upon entry
422      { 
423        searchField.value = ''; 
424        this.searchActive = true;
425      }
426    }
427    else if (!isActive) // directly remove the panel
428    {
429      this.DOMSearchBox().className = 'MSearchBoxInactive';
430      this.DOMSearchField().value   = this.searchLabel;
431      this.searchActive             = false;
432      this.lastSearchValue          = ''
433      this.lastResultsPage          = '';
434    }
435  }
436}
437
438// -----------------------------------------------------------------------
439
440// The class that handles everything on the search results page.
441function SearchResults(name)
442{
443    // The number of matches from the last run of <Search()>.
444    this.lastMatchCount = 0;
445    this.lastKey = 0;
446    this.repeatOn = false;
447
448    // Toggles the visibility of the passed element ID.
449    this.FindChildElement = function(id)
450    {
451      var parentElement = document.getElementById(id);
452      var element = parentElement.firstChild;
453
454      while (element && element!=parentElement)
455      {
456        if (element.nodeName == 'DIV' && element.className == 'SRChildren')
457        {
458          return element;
459        }
460
461        if (element.nodeName == 'DIV' && element.hasChildNodes())
462        { 
463           element = element.firstChild; 
464        }
465        else if (element.nextSibling)
466        { 
467           element = element.nextSibling; 
468        }
469        else
470        {
471          do
472          {
473            element = element.parentNode;
474          }
475          while (element && element!=parentElement && !element.nextSibling);
476
477          if (element && element!=parentElement)
478          { 
479            element = element.nextSibling; 
480          }
481        }
482      }
483    }
484
485    this.Toggle = function(id)
486    {
487      var element = this.FindChildElement(id);
488      if (element)
489      {
490        if (element.style.display == 'block')
491        { 
492          element.style.display = 'none'; 
493        }
494        else
495        { 
496          element.style.display = 'block'; 
497        }
498      }
499    }
500
501    // Searches for the passed string.  If there is no parameter,
502    // it takes it from the URL query.
503    //
504    // Always returns true, since other documents may try to call it
505    // and that may or may not be possible.
506    this.Search = function(search)
507    {
508      if (!search) // get search word from URL
509      {
510        search = window.location.search;
511        search = search.substring(1);  // Remove the leading '?'
512        search = unescape(search);
513      }
514
515      search = search.replace(/^ +/, ""); // strip leading spaces
516      search = search.replace(/ +$/, ""); // strip trailing spaces
517      search = search.toLowerCase();
518      search = convertToId(search);
519
520      var resultRows = document.getElementsByTagName("div");
521      var matches = 0;
522
523      var i = 0;
524      while (i < resultRows.length)
525      {
526        var row = resultRows.item(i);
527        if (row.className == "SRResult")
528        {
529          var rowMatchName = row.id.toLowerCase();
530          rowMatchName = rowMatchName.replace(/^sr\d*_/, ''); // strip 'sr123_'
531
532          if (search.length<=rowMatchName.length && 
533             rowMatchName.substr(0, search.length)==search)
534          {
535            row.style.display = 'block';
536            matches++;
537          }
538          else
539          { 
540            row.style.display = 'none'; 
541          }
542        }
543        i++;
544      }
545      document.getElementById("Searching").style.display='none';
546      if (matches == 0) // no results
547      { 
548        document.getElementById("NoMatches").style.display='block'; 
549      }
550      else // at least one result
551      { 
552        document.getElementById("NoMatches").style.display='none'; 
553      }
554      this.lastMatchCount = matches;
555      return true;
556    }
557
558    // return the first item with index index or higher that is visible
559    this.NavNext = function(index)
560    {
561      var focusItem;
562      while (1)
563      {
564        var focusName = 'Item'+index;
565        focusItem = document.getElementById(focusName);
566        if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
567        {
568          break;
569        }
570        else if (!focusItem) // last element
571        {
572          break;
573        }
574        focusItem=null;
575        index++;
576      }
577      return focusItem;
578    }
579
580    this.NavPrev = function(index)
581    {
582      var focusItem;
583      while (1)
584      {
585        var focusName = 'Item'+index;
586        focusItem = document.getElementById(focusName);
587        if (focusItem && focusItem.parentNode.parentNode.style.display=='block')
588        {
589          break;
590        }
591        else if (!focusItem) // last element
592        {
593          break;
594        }
595        focusItem=null;
596        index--;
597      }
598      return focusItem;
599    }
600
601    this.ProcessKeys = function(e)
602    {
603      if (e.type == "keydown") 
604      {
605        this.repeatOn = false;
606        this.lastKey = e.keyCode;
607      }
608      else if (e.type == "keypress")
609      {
610        if (!this.repeatOn)
611        {
612          if (this.lastKey) this.repeatOn = true;
613          return false; // ignore first keypress after keydown
614        }
615      }
616      else if (e.type == "keyup")
617      {
618        this.lastKey = 0;
619        this.repeatOn = false;
620      }
621      return this.lastKey!=0;
622    }
623
624    this.Nav = function(evt,itemIndex) 
625    {
626      var e  = (evt) ? evt : window.event; // for IE
627      if (e.keyCode==13) return true;
628      if (!this.ProcessKeys(e)) return false;
629
630      if (this.lastKey==38) // Up
631      {
632        var newIndex = itemIndex-1;
633        var focusItem = this.NavPrev(newIndex);
634        if (focusItem)
635        {
636          var child = this.FindChildElement(focusItem.parentNode.parentNode.id);
637          if (child && child.style.display == 'block') // children visible
638          { 
639            var n=0;
640            var tmpElem;
641            while (1) // search for last child
642            {
643              tmpElem = document.getElementById('Item'+newIndex+'_c'+n);
644              if (tmpElem) 
645              {
646                focusItem = tmpElem; 
647              }
648              else // found it!
649              {
650                break;
651              }
652              n++;
653            }
654          }
655        }
656        if (focusItem)
657        {
658          focusItem.focus();
659        }
660        else // return focus to search field
661        {
662           parent.document.getElementById("MSearchField").focus();
663        }
664      }
665      else if (this.lastKey==40) // Down
666      {
667        var newIndex = itemIndex+1;
668        var focusItem;
669        var item = document.getElementById('Item'+itemIndex);
670        var elem = this.FindChildElement(item.parentNode.parentNode.id);
671        if (elem && elem.style.display == 'block') // children visible
672        {
673          focusItem = document.getElementById('Item'+itemIndex+'_c0');
674        }
675        if (!focusItem) focusItem = this.NavNext(newIndex);
676        if (focusItem)  focusItem.focus();
677      }
678      else if (this.lastKey==39) // Right
679      {
680        var item = document.getElementById('Item'+itemIndex);
681        var elem = this.FindChildElement(item.parentNode.parentNode.id);
682        if (elem) elem.style.display = 'block';
683      }
684      else if (this.lastKey==37) // Left
685      {
686        var item = document.getElementById('Item'+itemIndex);
687        var elem = this.FindChildElement(item.parentNode.parentNode.id);
688        if (elem) elem.style.display = 'none';
689      }
690      else if (this.lastKey==27) // Escape
691      {
692        parent.searchBox.CloseResultsWindow();
693        parent.document.getElementById("MSearchField").focus();
694      }
695      else if (this.lastKey==13) // Enter
696      {
697        return true;
698      }
699      return false;
700    }
701
702    this.NavChild = function(evt,itemIndex,childIndex)
703    {
704      var e  = (evt) ? evt : window.event; // for IE
705      if (e.keyCode==13) return true;
706      if (!this.ProcessKeys(e)) return false;
707
708      if (this.lastKey==38) // Up
709      {
710        if (childIndex>0)
711        {
712          var newIndex = childIndex-1;
713          document.getElementById('Item'+itemIndex+'_c'+newIndex).focus();
714        }
715        else // already at first child, jump to parent
716        {
717          document.getElementById('Item'+itemIndex).focus();
718        }
719      }
720      else if (this.lastKey==40) // Down
721      {
722        var newIndex = childIndex+1;
723        var elem = document.getElementById('Item'+itemIndex+'_c'+newIndex);
724        if (!elem) // last child, jump to parent next parent
725        {
726          elem = this.NavNext(itemIndex+1);
727        }
728        if (elem)
729        {
730          elem.focus();
731        } 
732      }
733      else if (this.lastKey==27) // Escape
734      {
735        parent.searchBox.CloseResultsWindow();
736        parent.document.getElementById("MSearchField").focus();
737      }
738      else if (this.lastKey==13) // Enter
739      {
740        return true;
741      }
742      return false;
743    }
744}
Note: See TracBrowser for help on using the repository browser.