From f7cf820ff91427dc44f33c72f7a657aa6aa5a4fe Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Wed, 28 Jul 2021 17:06:36 +0100 Subject: [PATCH] Optimize selectors Former-commit-id: c69f7d46f0fb4d982ddca56a01a5525e8769e124 [formerly 4c3764fd5c1d34dec21f4ea92454c8f5434bbd07 [formerly d0f7b7222c6d095b7a54c7c85dd36294c8d71613]] Former-commit-id: 920ce199d387f1f0c74a6382e50c3a692782283c Former-commit-id: d236c52bd45068fb30eec8a9b225f858006877f9 --- www/js/lib/kiwixServe.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/www/js/lib/kiwixServe.js b/www/js/lib/kiwixServe.js index 87e3a126..5ff28a44 100644 --- a/www/js/lib/kiwixServe.js +++ b/www/js/lib/kiwixServe.js @@ -612,12 +612,13 @@ define([], function () { if (subjID && langEntries[i].dataset.kiwixsubject !== subjID && subjID !== "All") langEntries[i].style.display = "none"; if (dateID && langEntries[i].dataset.kiwixdate !== dateID && dateID !== "All") langEntries[i].style.display = "none"; } + var visibleZIMs = langPanel.innerText.match(/^.*?\.zi[mp]/mgi); // Prune date list if (dateID === 'All') { var dateList = dateArray.join('\r\n'); dateList = dateList.replace(/^(.*)[\r\n]*/mg, function (p0, p1) { - // DEV: innerText doesn't include hidden items - if (p1 !== 'All' && !~langPanel.innerText.indexOf('_' + p1)) return ''; + var rgxDate = new RegExp('_' + p1 + '\\.zi', 'i'); + if (p1 !== 'All' && !rgxDate.test(visibleZIMs)) return ''; return ''; }); dateSel.innerHTML = dateList; @@ -628,7 +629,7 @@ define([], function () { subjList = subjList.replace(/^(.*)[\r\n]*/mg, function (p0, p1) { // DEV: innerText doesn't include hidden items var rgxSubject = new RegExp('_?' + p1 + '[._]', 'i'); - if (p1 !== 'All' && !rgxSubject.test(langPanel.innerText)) return ''; + if (p1 !== 'All' && !rgxSubject.test(visibleZIMs)) return ''; return ''; }); subjSel.innerHTML = subjList; @@ -657,6 +658,7 @@ define([], function () { if (langID && subjEntries[i].lang !== langID && langID !== "All") subjEntries[i].style.display = "none"; if (dateID && subjEntries[i].dataset.kiwixdate !== dateID && dateID !== "All") subjEntries[i].style.display = "none"; } + var visibleZIMs = langPanel.innerText.match(/^.*?\.zi[mp]/mgi); // Prune the language list if (langID === 'All') { var langList = langArray.join('\r\n'); @@ -673,8 +675,8 @@ define([], function () { if (dateID === 'All') { var dateList = dateArray.join('\r\n'); dateList = dateList.replace(/^(.*)[\r\n]*/mg, function (p0, p1) { - // DEV: innerText doesn't include hidden items - if (p1 !== 'All' && !~langPanel.innerText.indexOf('_' + p1)) return ''; + var rgxDate = new RegExp('_' + p1 + '\\.zi', 'i'); + if (p1 !== 'All' && !rgxDate.test(visibleZIMs)) return ''; return ''; }); dateSel.innerHTML = dateList; @@ -703,6 +705,7 @@ define([], function () { if (langID && dateEntries[i].lang != langID && langID != "All") dateEntries[i].style.display = "none"; if (subjID && dateEntries[i].dataset.kiwixsubject !== subjID && subjID !== "All") dateEntries[i].style.display = "none"; } + var visibleZIMs = langPanel.innerText.match(/^.*?\.zi[mp]/mgi); // Prune the language list if (langID === 'All') { var langList = langArray.join('\r\n'); @@ -721,7 +724,7 @@ define([], function () { subjList = subjList.replace(/^(.*)[\r\n]*/mg, function (p0, p1) { // DEV: innerText doesn't include hidden items var rgxSubject = new RegExp('_?' + p1 + '[._]', 'i'); - if (p1 !== 'All' && !rgxSubject.test(langPanel.innerText)) return ''; + if (p1 !== 'All' && !rgxSubject.test(visibleZIMs)) return ''; return ''; }); subjSel.innerHTML = subjList; @@ -845,4 +848,4 @@ define([], function () { //langCodes: langCodes, requestXhttpData: requestXhttpData }; -}); \ No newline at end of file +});