|
114 | 114 | function initSearch(searchIndex) {
|
115 | 115 | var currentResults, index, params = getQueryStringParams();
|
116 | 116 |
|
117 |
| - // Populate search bar with query string search term when provided. |
118 |
| - $(".search-input")[0].value = params.search || ''; |
| 117 | + // Populate search bar with query string search term when provided, |
| 118 | + // but only if the input bar is empty. This avoid the obnoxious issue |
| 119 | + // where you start trying to do a search, and the index loads, and |
| 120 | + // suddenly your search is gone! |
| 121 | + if ($(".search-input")[0].value === "") { |
| 122 | + $(".search-input")[0].value = params.search || ''; |
| 123 | + } |
119 | 124 |
|
120 | 125 | /**
|
121 | 126 | * Executes the query and builds an index of results
|
|
574 | 579 | // When browsing forward to search results the previous search will be repeated,
|
575 | 580 | // so the currentResults are cleared to ensure the search is successful.
|
576 | 581 | currentResults = null;
|
577 |
| - // Synchronize search bar with query string state and perform the search. |
578 |
| - $('.search-input').val(params.search); |
| 582 | + // Synchronize search bar with query string state and |
| 583 | + // perform the search, but don't empty the bar if there's |
| 584 | + // nothing there. |
| 585 | + if params.search !== undefined { |
| 586 | + $('.search-input').val(params.search); |
| 587 | + } |
579 | 588 | // Some browsers fire 'onpopstate' for every page load (Chrome), while others fire the
|
580 | 589 | // event only when actually popping a state (Firefox), which is why search() is called
|
581 | 590 | // both here and at the end of the startSearch() function.
|
|
0 commit comments