From 98bbc54fdcd05a2f53c10e81be7cf94d1dc62522 Mon Sep 17 00:00:00 2001 From: Jeremy Lin Date: Sat, 8 Feb 2020 11:36:37 -0800 Subject: browse: allow filter init via `filter` query param (#3027) This allows creating links that display only a subset of files in a directory. --- modules/caddyhttp/fileserver/browsetpl.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'modules') 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 { } - + @@ -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'); -- cgit v1.2.3