|
12 | 12 | const ALL_ITEMS = 'all items'; |
13 | 13 | let accessScope = $state(ACCESSIBLE_ITEMS); |
14 | 14 | let isFullView = $state(true); |
| 15 | + let dropdownSelected = $state(false); |
15 | 16 |
|
16 | 17 | //updates UI when 'Collection' or 'Website' is selected in search options |
| 18 | + // sets a boolean for whether or not the dropdown for collection/website was selected |
17 | 19 | let _updateSelect = function (event) { |
18 | | - _root.dataset.index = event.target.value; |
19 | 20 | index = event.target.value; |
| 21 | + _root.dataset.index = event.target.value; |
| 22 | + dropdownSelected = true; |
20 | 23 | }; |
21 | 24 |
|
22 | 25 | function isSiteBabel() { |
|
50 | 53 |
|
51 | 54 | //updates search hint message when use selects search type |
52 | 55 | function _updateSearchType() { |
53 | | - let value = _searchtype.value; |
54 | | - _root.dataset.field = value; |
55 | | - let menuItem = _searchtype.options[_searchtype.selectedIndex]; |
56 | | - // window._s1 = _searchtype; |
57 | | - console.log('-- updateSearchType', value, _searchtype, menuItem); |
58 | | - fieldValue = menuItem.text; |
| 56 | + if (_searchtype) { |
| 57 | + let value = _searchtype.value; |
| 58 | + _root.dataset.field = value; |
| 59 | + let menuItem = _searchtype.options[_searchtype.selectedIndex]; |
| 60 | + console.log('-- updateSearchType', value, _searchtype, menuItem); |
| 61 | + fieldValue = menuItem.text; |
| 62 | + } |
59 | 63 | } |
60 | 64 |
|
61 | 65 | let SERVICE_DOMAIN = $state('babel.hathitrust.org'); |
|
111 | 115 | if (isSiteBabel() || isWebsiteHome()) { |
112 | 116 | _searchtypeValue = 'everything'; |
113 | 117 | _selectValue = 'library'; |
| 118 | + if (dropdownSelected) { |
| 119 | + _selectValue = index; |
| 120 | + } |
114 | 121 | // set _inputValue to q1 IF this is ls AND it's not a mondo collection |
115 | 122 | if (location.pathname.match('/cgi/ls') && !searchParams.has('c')) { |
116 | 123 | _inputValue = searchParams.get('q1'); |
|
120 | 127 | _searchtypeValue = searchParams.get('searchtype') || 'all'; |
121 | 128 | _selectValue = 'library'; |
122 | 129 | _inputValue = searchParams.get('lookfor') || searchParams.get('lookfor[]') || ''; |
| 130 | + if (dropdownSelected) { |
| 131 | + _selectValue = index; |
| 132 | + } |
123 | 133 | if (location.pathname == '/Record' && searchParams.has('ft')) { |
124 | 134 | // default to isFullView=true if /Record does not have an ft parameter |
125 | 135 | isFullView = searchParams.get('ft') == 'ft'; |
|
128 | 138 | } |
129 | 139 | } else { |
130 | 140 | _searchtypeValue = 'everything'; |
131 | | - if (location.pathname.startsWith('/search/')) { |
| 141 | + if (dropdownSelected == false && location.pathname.startsWith('/search/')) { |
132 | 142 | _selectValue = 'website'; |
133 | 143 | index = 'website'; |
134 | 144 | let tmp = location.pathname.split('/').slice(2); |
135 | 145 | tmp = tmp.pop(); |
136 | 146 | _inputValue = decodeURI(tmp); |
| 147 | + } else if (dropdownSelected == true && index == 'library') { |
| 148 | + _selectValue = 'library'; |
| 149 | + index = 'library'; |
| 150 | + _inputValue = ''; |
137 | 151 | } else { |
138 | 152 | _selectValue = 'website'; |
139 | 153 | index = 'website'; |
|
147 | 161 | } |
148 | 162 | } |
149 | 163 |
|
150 | | - _searchtype.value = _searchtypeValue; |
| 164 | + if (_searchtype) _searchtype.value = _searchtypeValue; |
151 | 165 | _select.value = _selectValue; |
152 | 166 | _input.value = _inputValue; |
153 | 167 | accessScope = isFullView ? ACCESSIBLE_ITEMS : ALL_ITEMS; |
|
0 commit comments