@@ -16,8 +16,8 @@ var Search = Control.extend({
1616 //renderer stuff
1717 resultsRenderer : searchResultsRenderer ,
1818 pathPrefix : window . pathPrefix ,
19- searchMapHashUrl : window . pathPrefix + '/searchMapHash.json' ,
20- searchMapUrl : window . pathPrefix + '/searchMap.json' ,
19+ searchMapHashUrl : '/searchMapHash.json' ,
20+ searchMapUrl : '/searchMap.json' ,
2121
2222 //callbacks
2323 onResultsHide : null ,
@@ -33,7 +33,10 @@ var Search = Control.extend({
3333 minSearchLength : 3 ,
3434 searchTimeout : 400 ,
3535
36- localStorageKeyPrefix : "bit-docs-search"
36+ localStorageKeyPrefix : "bit-docs-search" ,
37+
38+ //whether or not to animate in upon initialization
39+ animateInOnStart : true
3740 }
3841} , {
3942
@@ -69,12 +72,16 @@ var Search = Control.extend({
6972 //hide the input until the search engine is ready
7073 this . $inputWrap . hide ( ) ;
7174
72- this . checkSearchMapHash ( this . options . searchMapHashUrl ) . then ( function ( searchMapHashChangedObject ) {
73- self . getSearchMap ( self . options . searchMapUrl , searchMapHashChangedObject ) . then ( function ( searchMap ) {
75+ this . checkSearchMapHash ( this . options . pathPrefix + this . options . searchMapHashUrl ) . then ( function ( searchMapHashChangedObject ) {
76+ self . getSearchMap ( self . options . pathPrefix + self . options . searchMapUrl , searchMapHashChangedObject ) . then ( function ( searchMap ) {
7477 self . initSearchEngine ( searchMap ) ;
7578
7679 //show the search input when the search engine is ready
77- self . $inputWrap . fadeIn ( 400 ) ;
80+ if ( self . options . animateInOnStart ) {
81+ self . $inputWrap . fadeIn ( 400 ) ;
82+ } else {
83+ self . $inputWrap . show ( ) ;
84+ }
7885
7986 //focus the search on init
8087 //only do stuff if we have an input to work with
@@ -222,23 +229,28 @@ var Search = Control.extend({
222229 // @returns thenable that resolves to true if localStorage was cleared and false otherwise
223230 checkSearchMapHash : function ( dataUrl ) {
224231 var self = this ,
225- returnDeferred = $ . Deferred ( ) ;
232+ returnDeferred = $ . Deferred ( ) ,
233+ localStorageKey = self . formatLocalStorageKey ( self . searchMapHashLocalStorageKey ) ,
234+ searchMapHashLocalStorage = self . getLocalStorageItem ( localStorageKey ) ,
235+ lsHash = searchMapHashLocalStorage && searchMapHashLocalStorage . hash ;
226236
227237 //no need to do anything if localStorage isn't present
228238 if ( ! window . localStorage ) {
229239 returnDeferred . resolve ( false ) ;
230240 return ;
231241 }
232242
243+
244+ localStorageKey = self . formatLocalStorageKey ( self . searchMapHashLocalStorageKey ) ;
245+ searchMapHashLocalStorage = self . getLocalStorageItem ( localStorageKey ) ;
246+ lsHash = searchMapHashLocalStorage && searchMapHashLocalStorage . hash ;
247+
233248 $ . ajax ( {
234249 url : dataUrl ,
235250 dataType : "json" ,
236251 cache : false
237252 } ) . then ( function ( data ) {
238- var localStorageKey = self . formatLocalStorageKey ( self . searchMapHashLocalStorageKey ) ,
239- searchMapHashLocalStorage = self . getLocalStorageItem ( localStorageKey ) ,
240- lsHash = searchMapHashLocalStorage && searchMapHashLocalStorage . hash ,
241- dataHash = data && data . hash ;
253+ var dataHash = data && data . hash ;
242254
243255 //no lsHash && no dataHash => resolve
244256 //lsHash && no dataHash => resolve
@@ -258,7 +270,14 @@ var Search = Control.extend({
258270 }
259271
260272 returnDeferred . resolve ( false ) ;
261- } , returnDeferred . reject ) ;
273+ } , function ( error ) {
274+ //if we have a localStorage item, use it
275+ if ( searchMapHashLocalStorage ) {
276+ returnDeferred . resolve ( false ) ;
277+ } else {
278+ returnDeferred . reject ( error ) ;
279+ }
280+ } ) ;
262281
263282 return returnDeferred ;
264283 } ,
@@ -490,15 +509,15 @@ var Search = Control.extend({
490509 } , {
491510 docUrl : function ( ) {
492511 if ( ! docObject . pathToRoot ) {
493- return self . url ;
512+ return this . url ;
494513 }
495514
496515 var root = joinURIs ( window . location . href , docObject . pathToRoot ) ;
497516 if ( root . substr ( - 1 ) === "/" ) {
498517 root = root . substr ( 0 , root . length - 1 ) ;
499518 }
500519
501- return root + "/" + self . url ;
520+ return root + "/" + this . url ;
502521 }
503522 } ) ;
504523
0 commit comments