4
4
*
5
5
* Sphinx JavaScript utilities for the full-text search.
6
6
*
7
- * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
7
+ * :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
8
8
* :license: BSD, see LICENSE for details.
9
9
*
10
10
*/
@@ -248,7 +248,7 @@ var Search = {
248
248
// results left, load the summary and display it
249
249
if ( results . length ) {
250
250
var item = results . pop ( ) ;
251
- var listItem = $ ( '<li style="display:none" ></li>' ) ;
251
+ var listItem = $ ( '<li></li>' ) ;
252
252
var requestUrl = "" ;
253
253
var linkUrl = "" ;
254
254
if ( DOCUMENTATION_OPTIONS . BUILDER === 'dirhtml' ) {
@@ -273,9 +273,9 @@ var Search = {
273
273
if ( item [ 3 ] ) {
274
274
listItem . append ( $ ( '<span> (' + item [ 3 ] + ')</span>' ) ) ;
275
275
Search . output . append ( listItem ) ;
276
- listItem . slideDown ( 5 , function ( ) {
276
+ setTimeout ( function ( ) {
277
277
displayNextItem ( ) ;
278
- } ) ;
278
+ } , 5 ) ;
279
279
} else if ( DOCUMENTATION_OPTIONS . HAS_SOURCE ) {
280
280
$ . ajax ( { url : requestUrl ,
281
281
dataType : "text" ,
@@ -285,16 +285,16 @@ var Search = {
285
285
listItem . append ( Search . makeSearchSummary ( data , searchterms , hlterms ) ) ;
286
286
}
287
287
Search . output . append ( listItem ) ;
288
- listItem . slideDown ( 5 , function ( ) {
288
+ setTimeout ( function ( ) {
289
289
displayNextItem ( ) ;
290
- } ) ;
290
+ } , 5 ) ;
291
291
} } ) ;
292
292
} else {
293
293
// no source available, just display title
294
294
Search . output . append ( listItem ) ;
295
- listItem . slideDown ( 5 , function ( ) {
295
+ setTimeout ( function ( ) {
296
296
displayNextItem ( ) ;
297
- } ) ;
297
+ } , 5 ) ;
298
298
}
299
299
}
300
300
// search finished, update title and status message
@@ -379,6 +379,13 @@ var Search = {
379
379
return results ;
380
380
} ,
381
381
382
+ /**
383
+ * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
384
+ */
385
+ escapeRegExp : function ( string ) {
386
+ return string . replace ( / [ . * + \- ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ; // $& means the whole matched string
387
+ } ,
388
+
382
389
/**
383
390
* search for full-text terms in the index
384
391
*/
@@ -402,13 +409,14 @@ var Search = {
402
409
] ;
403
410
// add support for partial matches
404
411
if ( word . length > 2 ) {
412
+ var word_regex = this . escapeRegExp ( word ) ;
405
413
for ( var w in terms ) {
406
- if ( w . match ( word ) && ! terms [ word ] ) {
414
+ if ( w . match ( word_regex ) && ! terms [ word ] ) {
407
415
_o . push ( { files : terms [ w ] , score : Scorer . partialTerm } )
408
416
}
409
417
}
410
418
for ( var w in titleterms ) {
411
- if ( w . match ( word ) && ! titleterms [ word ] ) {
419
+ if ( w . match ( word_regex ) && ! titleterms [ word ] ) {
412
420
_o . push ( { files : titleterms [ w ] , score : Scorer . partialTitle } )
413
421
}
414
422
}
0 commit comments