From 7e419352d848ec9b989366916926ba3959c591ea Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 5 Aug 2023 00:18:08 +0200 Subject: Polish collation-based comparators for name and club filters Fixes #20 --- http/_res/ranking.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'http') diff --git a/http/_res/ranking.js b/http/_res/ranking.js index c85df2b..2038e71 100644 --- a/http/_res/ranking.js +++ b/http/_res/ranking.js @@ -100,15 +100,31 @@ var ranking = { filterRows : function(params) { $('table.data-table tbody tr').remove(); var displayRows = []; + const collator = new Intl.Collator('pl', {sensitivity: 'base', usage: 'search'}); + var contains = function(haystack, needle) { + if (needle.length === 0) { + return true; + } + haystack = haystack.normalize('NFC'); + needle = needle.normalize('NFC'); + let scan = 0; + for (; scan + needle.length <= haystack.length; scan += 1) { + const slice = haystack.slice(scan, scan + needle.length); + if (collator.compare(needle, slice) === 0) { + return true; + } + } + return false; + }; ranking.rankingData.forEach(function(row) { var hidden = false; params.forEach(function(value, param) { if (param == 'name') { - if (row['player'].trim().toLowerCase().search(value.join('')) == -1) { + if (!contains(row['player'].trim(), value.join(''))) { hidden = true; } } else if (param == 'club') { - if (row['club'].trim().toLowerCase().search(value.join('')) == -1) { + if (!contains(row['club'].trim(), value.join(''))) { hidden = true; } } else if (param.substr(0, 4) != 'page') { -- cgit v1.2.3