Store search data in lowercase and compare in lowercase

This way we can do the search case-sensitive after only converting
the search term to lowercase.
This commit is contained in:
Maximilian Krög
2020-02-13 23:53:14 +01:00
parent b9455bfad9
commit f7871d6103
2 changed files with 7 additions and 6 deletions

View File

@@ -29,7 +29,7 @@ $(function () {
var getSearchWeight = function (searchTerm, $matchedItem) {
let weight = 0;
// We could get smarter on the weight here
if ($matchedItem.data('shortname').toLowerCase() === searchTerm.toLowerCase()) {
if ($matchedItem.data('shortname') === searchTerm) {
weight++;
}
return weight;
@@ -48,7 +48,7 @@ $(function () {
.replace('module-', 'module:')
.replace(/_/g, '/')
.replace(/-/g, '~');
var $currentItem = $('.navigation .item[data-name*="' + longname + '"]:eq(0)');
var $currentItem = $('.navigation .item[data-name*="' + longname.toLowerCase() + '"]:eq(0)');
if ($currentItem.length) {
$currentItem
@@ -62,8 +62,9 @@ $(function () {
var $el = $('.navigation');
if (searchTerm.length > 1) {
searchTerm = searchTerm.toLowerCase();
const regexp = constructRegex(searchTerm, function (searchTerm) {
return new RegExp(searchTerm, 'i');
return new RegExp(searchTerm);
}, allowRegex);
$el.find('li, .member-list').hide();

View File

@@ -15,11 +15,11 @@ function getItemCssClass(type) {
}
const printList = v => { ?>
<li data-name="<?js= v.longname ?>"><?js
<li data-name="<?js= v.longname.toLowerCase() ?>"><?js
}
const printListWithStability = v => {
const cls = v.stability && v.stability !== 'stable' ? ' class="unstable"' : ''; ?>
<li data-name="<?js= v.longname ?>"<?js= cls ?>><?js
<li data-name="<?js= v.longname.toLowerCase() ?>"<?js= cls ?>><?js
}
function listContent(item, title, listItemPrinter) {
@@ -42,7 +42,7 @@ function listContent(item, title, listItemPrinter) {
</div>
<ul class="list"><?js
this.nav.forEach(function (item) { ?>
<li class="item" data-name="<?js= item.longname ?>" data-shortname="<?js= item.name.toLowerCase() ?>">
<li class="item" data-name="<?js= item.longname.toLowerCase() ?>" data-shortname="<?js= item.name.toLowerCase() ?>">
<span class="title">
<span class="glyphicon <?js= getItemCssClass(item.type) ?> toggle"></span>
<?js= self.linkto(item.longname, item.prettyname) ?>