| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 List libraryList; | 5 List libraryList; |
| 6 InputElement searchInput; | 6 InputElement searchInput; |
| 7 DivElement dropdown; | 7 DivElement dropdown; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Update the search drop down based on the current search text. | 10 * Update the search drop down based on the current search text. |
| 11 */ | 11 */ |
| 12 updateDropDown(Event event) { | 12 updateDropDown(Event event) { |
| 13 if (libraryList == null) return; | 13 if (libraryList == null) return; |
| 14 if (searchInput == null) return; | 14 if (searchInput == null) return; |
| 15 if (dropdown == null) return; | 15 if (dropdown == null) return; |
| 16 | 16 |
| 17 var results = <Result>[]; | 17 var results = <Result>[]; |
| 18 String text = searchInput.value; | 18 String text = searchInput.value; |
| 19 if (text == currentSearchText) { | 19 if (text == currentSearchText) { |
| 20 return; | 20 return; |
| 21 } | 21 } |
| 22 if (text.isEmpty()) { | 22 if (text.isEmpty) { |
| 23 updateResults(text, results); | 23 updateResults(text, results); |
| 24 hideDropDown(); | 24 hideDropDown(); |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 if (text.contains('.')) { | 27 if (text.contains('.')) { |
| 28 // Search type members. | 28 // Search type members. |
| 29 String typeText = text.substring(0, text.indexOf('.')); | 29 String typeText = text.substring(0, text.indexOf('.')); |
| 30 String memberText = text.substring(text.indexOf('.') + 1); | 30 String memberText = text.substring(text.indexOf('.') + 1); |
| 31 | 31 |
| 32 if (typeText.isEmpty() && memberText.isEmpty()) { | 32 if (typeText.isEmpty && memberText.isEmpty) { |
| 33 // Don't search on '.'. | 33 // Don't search on '.'. |
| 34 } else if (typeText.isEmpty()) { | 34 } else if (typeText.isEmpty) { |
| 35 // Search text is of the form '.id' => Look up members. | 35 // Search text is of the form '.id' => Look up members. |
| 36 matchAllMembers(results, memberText); | 36 matchAllMembers(results, memberText); |
| 37 } else if (memberText.isEmpty()) { | 37 } else if (memberText.isEmpty) { |
| 38 // Search text is of the form 'Type.' => Look up members in 'Type'. | 38 // Search text is of the form 'Type.' => Look up members in 'Type'. |
| 39 matchAllMembersInType(results, typeText, memberText); | 39 matchAllMembersInType(results, typeText, memberText); |
| 40 } else { | 40 } else { |
| 41 // Search text is of the form 'Type.id' => Look up member 'id' in 'Type'. | 41 // Search text is of the form 'Type.id' => Look up member 'id' in 'Type'. |
| 42 matchMembersInType(results, text, typeText, memberText); | 42 matchMembersInType(results, text, typeText, memberText); |
| 43 } | 43 } |
| 44 } else { | 44 } else { |
| 45 // Search all entities. | 45 // Search all entities. |
| 46 var searchText = new SearchText(text); | 46 var searchText = new SearchText(text); |
| 47 for (Map<String,Dynamic> library in libraryList) { | 47 for (Map<String,Dynamic> library in libraryList) { |
| 48 matchLibrary(results, searchText, library); | 48 matchLibrary(results, searchText, library); |
| 49 matchLibraryMembers(results, searchText, library); | 49 matchLibraryMembers(results, searchText, library); |
| 50 matchTypes(results, searchText, library); | 50 matchTypes(results, searchText, library); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 var elements = <Element>[]; | 53 var elements = <Element>[]; |
| 54 var table = new TableElement(); | 54 var table = new TableElement(); |
| 55 table.classes.add('drop-down-table'); | 55 table.classes.add('drop-down-table'); |
| 56 elements.add(table); | 56 elements.add(table); |
| 57 | 57 |
| 58 if (results.isEmpty()) { | 58 if (results.isEmpty) { |
| 59 var row = table.insertRow(0); | 59 var row = table.insertRow(0); |
| 60 row.innerHTML = "<tr><td>No matches found for '$text'.</td></tr>"; | 60 row.innerHTML = "<tr><td>No matches found for '$text'.</td></tr>"; |
| 61 } else { | 61 } else { |
| 62 results.sort(resultComparator); | 62 results.sort(resultComparator); |
| 63 | 63 |
| 64 var count = 0; | 64 var count = 0; |
| 65 for (Result result in results) { | 65 for (Result result in results) { |
| 66 result.addRow(table); | 66 result.addRow(table); |
| 67 if (++count >= 10) { | 67 if (++count >= 10) { |
| 68 break; | 68 break; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 String currentSearchText; | 235 String currentSearchText; |
| 236 Result _currentResult; | 236 Result _currentResult; |
| 237 List<Result> currentResults = const <Result>[]; | 237 List<Result> currentResults = const <Result>[]; |
| 238 | 238 |
| 239 void updateResults(String searchText, List<Result> results) { | 239 void updateResults(String searchText, List<Result> results) { |
| 240 currentSearchText = searchText; | 240 currentSearchText = searchText; |
| 241 currentResults = results; | 241 currentResults = results; |
| 242 if (currentResults.isEmpty()) { | 242 if (currentResults.isEmpty) { |
| 243 _currentResultIndex = -1; | 243 _currentResultIndex = -1; |
| 244 currentResult = null; | 244 currentResult = null; |
| 245 } else { | 245 } else { |
| 246 _currentResultIndex = 0; | 246 _currentResultIndex = 0; |
| 247 currentResult = currentResults[0]; | 247 currentResult = currentResults[0]; |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 int _currentResultIndex; | 251 int _currentResultIndex; |
| 252 | 252 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 if (currentResult != null) { | 298 if (currentResult != null) { |
| 299 window.location.href = currentResult.url; | 299 window.location.href = currentResult.url; |
| 300 event.preventDefault(); | 300 event.preventDefault(); |
| 301 hideDropDown(); | 301 hideDropDown(); |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 /** Show the search drop down unless there are no current results. */ | 306 /** Show the search drop down unless there are no current results. */ |
| 307 void showDropDown() { | 307 void showDropDown() { |
| 308 if (currentResults.isEmpty()) { | 308 if (currentResults.isEmpty) { |
| 309 hideDropDown(); | 309 hideDropDown(); |
| 310 } else { | 310 } else { |
| 311 dropdown.style.visibility = 'visible'; | 311 dropdown.style.visibility = 'visible'; |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 | 314 |
| 315 /** Used to prevent hiding the drop down when it is clicked. */ | 315 /** Used to prevent hiding the drop down when it is clicked. */ |
| 316 bool hideDropDownSuspend = false; | 316 bool hideDropDownSuspend = false; |
| 317 | 317 |
| 318 /** Hide the search drop down unless suspended. */ | 318 /** Hide the search drop down unless suspended. */ |
| (...skipping 28 matching lines...) Expand all Loading... |
| 347 searchInput = query('#q'); | 347 searchInput = query('#q'); |
| 348 dropdown = query('#drop-down'); | 348 dropdown = query('#drop-down'); |
| 349 | 349 |
| 350 searchInput.on.keyDown.add(handleUpDown); | 350 searchInput.on.keyDown.add(handleUpDown); |
| 351 searchInput.on.keyUp.add(updateDropDown); | 351 searchInput.on.keyUp.add(updateDropDown); |
| 352 searchInput.on.change.add(updateDropDown); | 352 searchInput.on.change.add(updateDropDown); |
| 353 searchInput.on.reset.add(updateDropDown); | 353 searchInput.on.reset.add(updateDropDown); |
| 354 searchInput.on.focus.add((event) => showDropDown()); | 354 searchInput.on.focus.add((event) => showDropDown()); |
| 355 searchInput.on.blur.add((event) => hideDropDown()); | 355 searchInput.on.blur.add((event) => hideDropDown()); |
| 356 } | 356 } |
| OLD | NEW |