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