summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorJeremy Lin <jjlin@cs.stanford.edu>2020-02-08 11:36:37 -0800
committerGitHub <noreply@github.com>2020-02-08 12:36:37 -0700
commit98bbc54fdcd05a2f53c10e81be7cf94d1dc62522 (patch)
tree310ca9b88654f109c1a2d6dc4efc829f3d90d39f /modules
parent9bdd6caa0bcced5caf30872548700277f2db1877 (diff)
browse: allow filter init via `filter` query param (#3027)
This allows creating links that display only a subset of files in a directory.
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/fileserver/browsetpl.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/modules/caddyhttp/fileserver/browsetpl.go b/modules/caddyhttp/fileserver/browsetpl.go
index 14d3996..567e8dd 100644
--- a/modules/caddyhttp/fileserver/browsetpl.go
+++ b/modules/caddyhttp/fileserver/browsetpl.go
@@ -228,7 +228,7 @@ footer {
}
</style>
</head>
- <body onload='filter()'>
+ <body onload='initFilter()'>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="0" width="0" style="position: absolute;">
<defs>
<!-- Folder -->
@@ -379,6 +379,16 @@ footer {
var filterEl = document.getElementById('filter');
filterEl.focus();
+ function initFilter() {
+ if (!filterEl.value) {
+ var filterParam = new URL(window.location.href).searchParams.get('filter');
+ if (filterParam) {
+ filterEl.value = filterParam;
+ }
+ }
+ filter();
+ }
+
function filter() {
var q = filterEl.value.trim().toLowerCase();
var elems = document.querySelectorAll('tr.file');