oupala / apaxy

a simple, customisable theme for your apache directory listing
https://oupala.github.io/apaxy/
GNU General Public License v3.0
1.86k stars 256 forks source link

search bar filter should be case sensitive? #126

Closed oupala closed 5 years ago

oupala commented 5 years ago

Describe the bug The search bar is currently case insensitive.

To Reproduce Steps to reproduce the behavior:

  1. Open a page modified by apaxy
  2. Fill the search bar with a string
  3. See that the search bar is currently case insensitive

Expected behavior I think that the search bar should be case sensitive, while I'm not sure this would be the best setting.

I'm asking opinions about that: should the search bar be case insensitive or case sensitive?

oupala commented 5 years ago

@woodrowbarlow Do you have an opinion about that?

woodrowbarlow commented 5 years ago

@oupala

my opinion is that case-insensitive is a sane default. apaxy is essentially a file browser, and if you open up any mainstream file browser with a graphical UI and search bar (finder, explorer, nautilus), these all use case-insensitive search. most don't even offer an option for case-sensitive search.

do you plan on adding some sort of config system? if you don't add a full-blown config system, there's still a middle ground: add a const variable to the top of apaxy.js so that users can set that variable to true or false.

woodrowbarlow commented 5 years ago
diff --git a/apaxy/theme/apaxy.js b/apaxy/theme/apaxy.js
index 2cc43b8..ed6120e 100644
--- a/apaxy/theme/apaxy.js
+++ b/apaxy/theme/apaxy.js
@@ -1,3 +1,5 @@
+const FILTER_CASE_SENSITIVE = false;
+
 // fix links when not adding a / at the end of the URI
 var uri = window.location.pathname.substr(1);
 if (uri.substring(uri.length - 1) !== '/') {
@@ -38,8 +40,13 @@ if (uri.substring(uri.length - 1) !== '/') {
            }

            // only check the 'name' field
-           var text = row.getElementsByTagName('td')[1].textContent.toLowerCase();
-           var val = _input.value.toLowerCase();
+           var text = row.getElementsByTagName('td')[1].textContent;
+           var val = _input.value;
+
+           if (!FILTER_CASE_SENSITIVE) {
+               text = text.toLowerCase();
+               val = val.toLowerCase();
+           }

            // change display type to show / hide this row
            row.style.display = text.indexOf(val) === -1 ? 'none' : 'table-row';
oupala commented 5 years ago

Thanks a lot @woodrowbarlow for your answer and for the patch.

I'm convinced by what you said about other file browsers. Meanwhile, a config system might a good idea.

Let's wait a little bit what does the community thinks about the case-sensitivity of the search.