1 var gSelectedIndex = -1;
3 var gMatches = new Array();
6 var gInitialized = false;
7 var DEFAULT_TEXT = "search developer docs";
9 function set_row_selected(row, selected)
11 var c1 = row.cells[0];
12 // var c2 = row.cells[1];
14 c1.className = "jd-autocomplete jd-selected";
15 // c2.className = "jd-autocomplete jd-selected jd-linktype";
17 c1.className = "jd-autocomplete";
18 // c2.className = "jd-autocomplete jd-linktype";
22 function set_row_values(toroot, row, match)
24 var link = row.cells[0].childNodes[0];
25 link.innerHTML = match.label;
26 link.href = toroot + match.link
27 // row.cells[1].innerHTML = match.type;
30 function sync_selection_table(toroot)
32 var filtered = document.getElementById("search_filtered");
33 var r; //TR DOM object
37 filtered.onmouseover = function() {
38 if(gSelectedIndex >= 0) {
39 set_row_selected(this.rows[gSelectedIndex], false);
44 //initialize the table; draw it for the first time (but not visible).
46 for (i=0; i<ROW_COUNT; i++) {
47 var r = filtered.insertRow(-1);
48 var c1 = r.insertCell(-1);
49 // var c2 = r.insertCell(-1);
50 c1.className = "jd-autocomplete";
51 // c2.className = "jd-autocomplete jd-linktype";
52 var link = document.createElement("a");
53 c1.onmousedown = function() {
54 window.location = this.firstChild.getAttribute("href");
56 c1.onmouseover = function() {
57 this.className = this.className + " jd-selected";
59 c1.onmouseout = function() {
60 this.className = "jd-autocomplete";
64 /* var r = filtered.insertRow(-1);
65 var c1 = r.insertCell(-1);
66 c1.className = "jd-autocomplete jd-linktype";
71 //if we have results, make the table visible and initialize result info
72 if (gMatches.length > 0) {
73 document.getElementById("search_filtered_div").className = "showing";
74 var N = gMatches.length < ROW_COUNT ? gMatches.length : ROW_COUNT;
77 r.className = "show-row";
78 set_row_values(toroot, r, gMatches[i]);
79 set_row_selected(r, i == gSelectedIndex);
80 if (i == gSelectedIndex) {
81 gSelectedID = gMatches[i].id;
84 //start hiding rows that are no longer matches
85 for (; i<ROW_COUNT; i++) {
87 r.className = "no-display";
89 //if there are more results we're not showing, so say so.
90 /* if (gMatches.length > ROW_COUNT) {
91 r = filtered.rows[ROW_COUNT];
92 r.className = "show-row";
94 c1.innerHTML = "plus " + (gMatches.length-ROW_COUNT) + " more";
96 filtered.rows[ROW_COUNT].className = "hide-row";
98 //if we have no results, hide the table
100 document.getElementById("search_filtered_div").className = "no-display";
104 function search_changed(e, kd, toroot)
106 var search = document.getElementById("search_autocomplete");
107 var text = search.value;
110 if (!kd && (e.keyCode == 13)) {
111 document.getElementById("search_filtered_div").className = "no-display";
112 if (gSelectedIndex >= 0) {
113 window.location = toroot + gMatches[gSelectedIndex].link;
118 else if (kd && (e.keyCode == 38)) {
119 if (gSelectedIndex >= 0) {
122 sync_selection_table(toroot);
126 else if (kd && (e.keyCode == 40)) {
127 if (gSelectedIndex < gMatches.length-1
128 && gSelectedIndex < ROW_COUNT-1) {
131 sync_selection_table(toroot);
135 gMatches = new Array();
138 for (i=0; i<DATA.length; i++) {
140 if (text.length != 0 && s.label.indexOf(text) != -1) {
141 gMatches[matchedCount] = s;
142 if (gSelectedID == s.id) {
143 gSelectedIndex = matchedCount;
148 sync_selection_table(toroot);
149 return true; // allow the event to bubble up to the search api
153 function search_focus_changed(obj, focused)
156 if(obj.value == DEFAULT_TEXT){
158 obj.style.color="#000000";
162 obj.value = DEFAULT_TEXT;
163 obj.style.color="#aaaaaa";
165 document.getElementById("search_filtered_div").className = "no-display";
169 function submit_search() {
170 var query = document.getElementById('search_autocomplete').value;
171 document.location = toRoot + 'search.html#q=' + query + '&t=0';