summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '_static/searchtools.js')
-rw-r--r--_static/searchtools.js30
1 files changed, 19 insertions, 11 deletions
diff --git a/_static/searchtools.js b/_static/searchtools.js
index 261ecaa..e09f926 100644
--- a/_static/searchtools.js
+++ b/_static/searchtools.js
@@ -4,7 +4,7 @@
*
* Sphinx JavaScript utilities for the full-text search.
*
- * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
+ * :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
@@ -248,7 +248,7 @@ var Search = {
// results left, load the summary and display it
if (results.length) {
var item = results.pop();
- var listItem = $('<li style="display:none"></li>');
+ var listItem = $('<li></li>');
var requestUrl = "";
var linkUrl = "";
if (DOCUMENTATION_OPTIONS.BUILDER === 'dirhtml') {
@@ -273,9 +273,9 @@ var Search = {
if (item[3]) {
listItem.append($('<span> (' + item[3] + ')</span>'));
Search.output.append(listItem);
- listItem.slideDown(5, function() {
+ setTimeout(function() {
displayNextItem();
- });
+ }, 5);
} else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
$.ajax({url: requestUrl,
dataType: "text",
@@ -285,16 +285,16 @@ var Search = {
listItem.append(Search.makeSearchSummary(data, searchterms, hlterms));
}
Search.output.append(listItem);
- listItem.slideDown(5, function() {
+ setTimeout(function() {
displayNextItem();
- });
+ }, 5);
}});
} else {
// no source available, just display title
Search.output.append(listItem);
- listItem.slideDown(5, function() {
+ setTimeout(function() {
displayNextItem();
- });
+ }, 5);
}
}
// search finished, update title and status message
@@ -380,6 +380,13 @@ var Search = {
},
/**
+ * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
+ */
+ escapeRegExp : function(string) {
+ return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
+ },
+
+ /**
* search for full-text terms in the index
*/
performTermsSearch : function(searchterms, excluded, terms, titleterms) {
@@ -402,13 +409,14 @@ var Search = {
];
// add support for partial matches
if (word.length > 2) {
+ var word_regex = this.escapeRegExp(word);
for (var w in terms) {
- if (w.match(word) && !terms[word]) {
+ if (w.match(word_regex) && !terms[word]) {
_o.push({files: terms[w], score: Scorer.partialTerm})
}
}
for (var w in titleterms) {
- if (w.match(word) && !titleterms[word]) {
+ if (w.match(word_regex) && !titleterms[word]) {
_o.push({files: titleterms[w], score: Scorer.partialTitle})
}
}
@@ -501,7 +509,7 @@ var Search = {
var excerpt = ((start > 0) ? '...' : '') +
$.trim(text.substr(start, 240)) +
((start + 240 - text.length) ? '...' : '');
- var rv = $('<div class="context"></div>').text(excerpt);
+ var rv = $('<p class="context"></p>').text(excerpt);
$.each(hlwords, function() {
rv = rv.highlightText(this, 'highlighted');
});