@@ -16,8 +16,8 @@ var Search = Control.extend({
16
16
//renderer stuff
17
17
resultsRenderer : searchResultsRenderer ,
18
18
pathPrefix : window . pathPrefix ,
19
- searchMapHashUrl : window . pathPrefix + '/searchMapHash.json' ,
20
- searchMapUrl : window . pathPrefix + '/searchMap.json' ,
19
+ searchMapHashUrl : '/searchMapHash.json' ,
20
+ searchMapUrl : '/searchMap.json' ,
21
21
22
22
//callbacks
23
23
onResultsHide : null ,
@@ -33,7 +33,10 @@ var Search = Control.extend({
33
33
minSearchLength : 3 ,
34
34
searchTimeout : 400 ,
35
35
36
- localStorageKeyPrefix : "bit-docs-search"
36
+ localStorageKeyPrefix : "bit-docs-search" ,
37
+
38
+ //whether or not to animate in upon initialization
39
+ animateInOnStart : true
37
40
}
38
41
} , {
39
42
@@ -69,12 +72,16 @@ var Search = Control.extend({
69
72
//hide the input until the search engine is ready
70
73
this . $inputWrap . hide ( ) ;
71
74
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 ) {
74
77
self . initSearchEngine ( searchMap ) ;
75
78
76
79
//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
+ }
78
85
79
86
//focus the search on init
80
87
//only do stuff if we have an input to work with
@@ -222,23 +229,28 @@ var Search = Control.extend({
222
229
// @returns thenable that resolves to true if localStorage was cleared and false otherwise
223
230
checkSearchMapHash : function ( dataUrl ) {
224
231
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 ;
226
236
227
237
//no need to do anything if localStorage isn't present
228
238
if ( ! window . localStorage ) {
229
239
returnDeferred . resolve ( false ) ;
230
240
return ;
231
241
}
232
242
243
+
244
+ localStorageKey = self . formatLocalStorageKey ( self . searchMapHashLocalStorageKey ) ;
245
+ searchMapHashLocalStorage = self . getLocalStorageItem ( localStorageKey ) ;
246
+ lsHash = searchMapHashLocalStorage && searchMapHashLocalStorage . hash ;
247
+
233
248
$ . ajax ( {
234
249
url : dataUrl ,
235
250
dataType : "json" ,
236
251
cache : false
237
252
} ) . 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 ;
242
254
243
255
//no lsHash && no dataHash => resolve
244
256
//lsHash && no dataHash => resolve
@@ -258,7 +270,14 @@ var Search = Control.extend({
258
270
}
259
271
260
272
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
+ } ) ;
262
281
263
282
return returnDeferred ;
264
283
} ,
@@ -490,15 +509,15 @@ var Search = Control.extend({
490
509
} , {
491
510
docUrl : function ( ) {
492
511
if ( ! docObject . pathToRoot ) {
493
- return self . url ;
512
+ return this . url ;
494
513
}
495
514
496
515
var root = joinURIs ( window . location . href , docObject . pathToRoot ) ;
497
516
if ( root . substr ( - 1 ) === "/" ) {
498
517
root = root . substr ( 0 , root . length - 1 ) ;
499
518
}
500
519
501
- return root + "/" + self . url ;
520
+ return root + "/" + this . url ;
502
521
}
503
522
} ) ;
504
523
0 commit comments