From 128c153b9e1e2c69d6fa7269395423ac07052ea9 Mon Sep 17 00:00:00 2001 From: korki <65349313+korki43@users.noreply.github.com> Date: Sun, 26 Mar 2023 19:09:17 +0300 Subject: [PATCH] docs: filter url by search query --- docs/assets/js/list.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/assets/js/list.js b/docs/assets/js/list.js index 7beb4f165f..4965fcef5a 100644 --- a/docs/assets/js/list.js +++ b/docs/assets/js/list.js @@ -3,7 +3,9 @@ (function () { 'use strict' - new List('icons-body', { + const searchInput = document.querySelector('#icons-body #search') + const query = new URLSearchParams(window.location.search).get('q') + const iconList = new List('icons-body', { searchDelay: 250, valueNames: [ 'name', { @@ -14,4 +16,23 @@ } ] }) + + if (query) { + document.querySelector('#content').scrollIntoView() + searchInput.value = query + iconList.search(query) + } + + iconList.on('searchComplete', () => { + const searchTerm = searchInput.value + const newUrl = new URL(window.location) + + if (searchTerm.length > 0) { + newUrl.searchParams.set('q', searchTerm) + } else { + newUrl.searchParams.delete('q') + } + + window.history.replaceState(null, null, newUrl) + }) })()