@@ -156,152 +156,154 @@ function hideThemeButtonState() {
156156 "use strict" ;
157157
158158 window . searchState = {
159- loadingText : "Loading search results..." ,
160- input : document . getElementsByClassName ( "search-input" ) [ 0 ] ,
161- outputElement : function ( ) {
162- return document . getElementById ( "search" ) ;
163- } ,
164- title : null ,
165- titleBeforeSearch : document . title ,
166- timeout : null ,
167- // On the search screen, so you remain on the last tab you opened.
168- //
169- // 0 for "In Names"
170- // 1 for "In Parameters"
171- // 2 for "In Return Types"
172- currentTab : 0 ,
173- mouseMovedAfterSearch : true ,
174- clearInputTimeout : function ( ) {
175- if ( searchState . timeout !== null ) {
176- clearTimeout ( searchState . timeout ) ;
177- searchState . timeout = null ;
178- }
179- } ,
180- // Sets the focus on the search bar at the top of the page
181- focus : function ( ) {
182- searchState . input . focus ( ) ;
183- } ,
184- // Removes the focus from the search bar.
185- defocus : function ( ) {
186- searchState . input . blur ( ) ;
187- } ,
188- showResults : function ( search ) {
189- if ( search === null || typeof search === 'undefined' ) {
190- search = searchState . outputElement ( ) ;
191- }
192- addClass ( main , "hidden" ) ;
193- removeClass ( search , "hidden" ) ;
194- searchState . mouseMovedAfterSearch = false ;
195- document . title = searchState . title ;
196- } ,
197- hideResults : function ( search ) {
198- if ( search === null || typeof search === 'undefined' ) {
199- search = searchState . outputElement ( ) ;
200- }
201- addClass ( search , "hidden" ) ;
202- removeClass ( main , "hidden" ) ;
203- document . title = searchState . titleBeforeSearch ;
204- // We also remove the query parameter from the URL.
205- if ( searchState . browserSupportsHistoryApi ( ) ) {
206- history . replaceState ( "" , window . currentCrate + " - Rust" ,
207- getNakedUrl ( ) + window . location . hash ) ;
208- }
209- } ,
210- getQueryStringParams : function ( ) {
211- var params = { } ;
212- window . location . search . substring ( 1 ) . split ( "&" ) .
213- map ( function ( s ) {
214- var pair = s . split ( "=" ) ;
215- params [ decodeURIComponent ( pair [ 0 ] ) ] =
216- typeof pair [ 1 ] === "undefined" ? null : decodeURIComponent ( pair [ 1 ] ) ;
217- } ) ;
218- return params ;
219- } ,
220- putBackSearch : function ( search_input ) {
221- var search = searchState . outputElement ( ) ;
222- if ( search_input . value !== "" && hasClass ( search , "hidden" ) ) {
223- searchState . showResults ( search ) ;
224- if ( searchState . browserSupportsHistoryApi ( ) ) {
225- var extra = "?search=" + encodeURIComponent ( search_input . value ) ;
226- history . replaceState ( search_input . value , "" ,
227- getNakedUrl ( ) + extra + window . location . hash ) ;
159+ loadingText : "Loading search results..." ,
160+ input : document . getElementsByClassName ( "search-input" ) [ 0 ] ,
161+ outputElement : function ( ) {
162+ return document . getElementById ( "search" ) ;
163+ } ,
164+ title : null ,
165+ titleBeforeSearch : document . title ,
166+ timeout : null ,
167+ // On the search screen, so you remain on the last tab you opened.
168+ //
169+ // 0 for "In Names"
170+ // 1 for "In Parameters"
171+ // 2 for "In Return Types"
172+ currentTab : 0 ,
173+ mouseMovedAfterSearch : true ,
174+ clearInputTimeout : function ( ) {
175+ if ( searchState . timeout !== null ) {
176+ clearTimeout ( searchState . timeout ) ;
177+ searchState . timeout = null ;
178+ }
179+ } ,
180+ // Sets the focus on the search bar at the top of the page
181+ focus : function ( ) {
182+ searchState . input . focus ( ) ;
183+ } ,
184+ // Removes the focus from the search bar.
185+ defocus : function ( ) {
186+ searchState . input . blur ( ) ;
187+ } ,
188+ showResults : function ( search ) {
189+ if ( search === null || typeof search === 'undefined' ) {
190+ search = searchState . outputElement ( ) ;
228191 }
192+ addClass ( main , "hidden" ) ;
193+ removeClass ( search , "hidden" ) ;
194+ searchState . mouseMovedAfterSearch = false ;
229195 document . title = searchState . title ;
230- }
231- } ,
232- browserSupportsHistoryApi : function ( ) {
233- return window . history && typeof window . history . pushState === "function" ;
234- } ,
235- setup : function ( ) {
236- var search_input = searchState . input ;
237- if ( ! searchState . input ) {
238- return ;
239- }
240- function loadScript ( url ) {
241- var script = document . createElement ( 'script' ) ;
242- script . src = url ;
243- document . head . append ( script ) ;
244- }
245-
246- var searchLoaded = false ;
247- function loadSearch ( ) {
248- if ( ! searchLoaded ) {
249- searchLoaded = true ;
250- loadScript ( window . searchJS ) ;
251- loadScript ( window . searchIndexJS ) ;
196+ } ,
197+ hideResults : function ( search ) {
198+ if ( search === null || typeof search === 'undefined' ) {
199+ search = searchState . outputElement ( ) ;
200+ }
201+ addClass ( search , "hidden" ) ;
202+ removeClass ( main , "hidden" ) ;
203+ document . title = searchState . titleBeforeSearch ;
204+ // We also remove the query parameter from the URL.
205+ if ( searchState . browserSupportsHistoryApi ( ) ) {
206+ history . replaceState ( "" , window . currentCrate + " - Rust" ,
207+ getNakedUrl ( ) + window . location . hash ) ;
208+ }
209+ } ,
210+ getQueryStringParams : function ( ) {
211+ var params = { } ;
212+ window . location . search . substring ( 1 ) . split ( "&" ) .
213+ map ( function ( s ) {
214+ var pair = s . split ( "=" ) ;
215+ params [ decodeURIComponent ( pair [ 0 ] ) ] =
216+ typeof pair [ 1 ] === "undefined" ? null : decodeURIComponent ( pair [ 1 ] ) ;
217+ } ) ;
218+ return params ;
219+ } ,
220+ putBackSearch : function ( search_input ) {
221+ var search = searchState . outputElement ( ) ;
222+ if ( search_input . value !== "" && hasClass ( search , "hidden" ) ) {
223+ searchState . showResults ( search ) ;
224+ if ( searchState . browserSupportsHistoryApi ( ) ) {
225+ var extra = "?search=" + encodeURIComponent ( search_input . value ) ;
226+ history . replaceState ( search_input . value , "" ,
227+ getNakedUrl ( ) + extra + window . location . hash ) ;
228+ }
229+ document . title = searchState . title ;
230+ }
231+ } ,
232+ browserSupportsHistoryApi : function ( ) {
233+ return window . history && typeof window . history . pushState === "function" ;
234+ } ,
235+ setup : function ( ) {
236+ var search_input = searchState . input ;
237+ if ( ! searchState . input ) {
238+ return ;
239+ }
240+ function loadScript ( url ) {
241+ var script = document . createElement ( 'script' ) ;
242+ script . src = url ;
243+ document . head . append ( script ) ;
252244 }
253- }
254245
255- search_input . addEventListener ( "focus" , function ( ) {
256- searchState . putBackSearch ( this ) ;
257- search_input . origPlaceholder = searchState . input . placeholder ;
258- search_input . placeholder = "Type your search here." ;
259- loadSearch ( ) ;
260- } ) ;
261- search_input . addEventListener ( "blur" , function ( ) {
262- search_input . placeholder = searchState . input . origPlaceholder ;
263- } ) ;
246+ var searchLoaded = false ;
247+ function loadSearch ( ) {
248+ if ( ! searchLoaded ) {
249+ searchLoaded = true ;
250+ loadScript ( window . searchJS ) ;
251+ loadScript ( window . searchIndexJS ) ;
252+ }
253+ }
264254
265- document . addEventListener ( "mousemove" , function ( ) {
266- searchState . mouseMovedAfterSearch = true ;
267- } ) ;
255+ search_input . addEventListener ( "focus" , function ( ) {
256+ searchState . putBackSearch ( this ) ;
257+ search_input . origPlaceholder = searchState . input . placeholder ;
258+ search_input . placeholder = "Type your search here." ;
259+ loadSearch ( ) ;
260+ } ) ;
261+ search_input . addEventListener ( "blur" , function ( ) {
262+ search_input . placeholder = searchState . input . origPlaceholder ;
263+ } ) ;
268264
269- search_input . removeAttribute ( 'disabled' ) ;
265+ document . addEventListener ( "mousemove" , function ( ) {
266+ searchState . mouseMovedAfterSearch = true ;
267+ } ) ;
270268
271- // `crates{version}.js` should always be loaded before this script, so we can use it safely.
272- searchState . addCrateDropdown ( window . ALL_CRATES ) ;
273- var params = searchState . getQueryStringParams ( ) ;
274- if ( params . search !== undefined ) {
275- var search = searchState . outputElement ( ) ;
276- search . innerHTML = "<h3 style=\"text-align: center;\">" +
277- searchState . loadingText + "</h3>" ;
278- searchState . showResults ( search ) ;
279- loadSearch ( ) ;
280- }
281- } ,
282- addCrateDropdown : function ( crates ) {
283- var elem = document . getElementById ( "crate-search" ) ;
269+ search_input . removeAttribute ( 'disabled' ) ;
270+
271+ // `crates{version}.js` should always be loaded before this script, so we can use it
272+ // safely.
273+ searchState . addCrateDropdown ( window . ALL_CRATES ) ;
274+ var params = searchState . getQueryStringParams ( ) ;
275+ if ( params . search !== undefined ) {
276+ var search = searchState . outputElement ( ) ;
277+ search . innerHTML = "<h3 style=\"text-align: center;\">" +
278+ searchState . loadingText + "</h3>" ;
279+ searchState . showResults ( search ) ;
280+ loadSearch ( ) ;
281+ }
282+ } ,
283+ addCrateDropdown : function ( crates ) {
284+ var elem = document . getElementById ( "crate-search" ) ;
284285
285- if ( ! elem ) {
286- return ;
287- }
288- var savedCrate = getSettingValue ( "saved-filter-crate" ) ;
289- for ( var i = 0 , len = crates . length ; i < len ; ++ i ) {
290- var option = document . createElement ( "option" ) ;
291- option . value = crates [ i ] ;
292- option . innerText = crates [ i ] ;
293- elem . appendChild ( option ) ;
294- // Set the crate filter from saved storage, if the current page has the saved crate
295- // filter.
296- //
297- // If not, ignore the crate filter -- we want to support filtering for crates on sites
298- // like doc.rust-lang.org where the crates may differ from page to page while on the
299- // same domain.
300- if ( crates [ i ] === savedCrate ) {
301- elem . value = savedCrate ;
286+ if ( ! elem ) {
287+ return ;
302288 }
303- }
304- } ,
289+ var savedCrate = getSettingValue ( "saved-filter-crate" ) ;
290+ for ( var i = 0 , len = crates . length ; i < len ; ++ i ) {
291+ var option = document . createElement ( "option" ) ;
292+ option . value = crates [ i ] ;
293+ option . innerText = crates [ i ] ;
294+ elem . appendChild ( option ) ;
295+ // Set the crate filter from saved storage, if the current page has the saved crate
296+ // filter.
297+ //
298+ // If not, ignore the crate filter -- we want to support filtering for crates on
299+ // sites like doc.rust-lang.org where the crates may differ from page to page while
300+ // on the
301+ // same domain.
302+ if ( crates [ i ] === savedCrate ) {
303+ elem . value = savedCrate ;
304+ }
305+ }
306+ } ,
305307 } ;
306308
307309 function getPageId ( ) {
0 commit comments