authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-08-06 15:09:26+02:00
committergravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-08-06 15:15:59+02:00
logdf8cfb1273e7b99ff5de0164c676d291191a72c6
treebe16c931dcab16ba1eb5f4e5b3e56ca01ed33ad4
parent6354851909749d9741d520ead2d1f9e517df3548

feat: new search placeholder

This new search placeholder looks much nicer because it allows HTML inside it which the `placeholder` attribute on `<input>`s doesn't allow. I tested it for all kinds of cases and it seems to work pretty well.

2 files changed, 22 insertions(+), 7 deletions(-)

lib/docs/index.html+10-7
......@@ -190,11 +190,11 @@
190190 box-shadow: 0 0.3em 1em 0.125em var(--search-sh-color);
191191 }
192192
193 .docs .search::placeholder {
194 font-size: 1rem;
195 font-family: var(--ui);
196 color: var(--tx-color);
197 opacity: 0.5;
193 #searchPlaceholder {
194 position: absolute;
195 pointer-events: none;
196 top: 5px;
197 left: 5px;
198198 }
199199
200200 .docs a {
......@@ -334,7 +334,7 @@
334334 margin-right: 0.5em;
335335 }
336336
337 .help-modal kbd {
337 kbd {
338338 display: inline-block;
339339 padding: 0.3em 0.2em;
340340 font-size: 1.2em;
......@@ -614,7 +614,10 @@
614614 <div class="flex-right">
615615 <div class="wrap">
616616 <section class="docs">
617 <input type="search" class="search" id="search" autocomplete="off" spellcheck="false" placeholder="`s` to search, `?` to see more options">
617 <div style="position: relative">
618 <span id="searchPlaceholder"><kbd>S</kbd> to search, <kbd>?</kbd> for more options</span>
619 <input type="search" class="search" id="search" autocomplete="off" spellcheck="false">
620 </div>
618621 <p id="status">Loading...</p>
619622 <div id="sectNav" class="hidden"><ul id="listNav"></ul></div>
620623 <div id="fnProto" class="hidden">
lib/docs/main.js+12
......@@ -49,6 +49,7 @@ var zigAnalysis;
4949 let domTdZigVer = document.getElementById("tdZigVer");
5050 let domHdrName = document.getElementById("hdrName");
5151 let domHelpModal = document.getElementById("helpModal");
52 const domSearchPlaceholder = document.getElementById("searchPlaceholder");
5253
5354 let searchTimer = null;
5455
......@@ -103,6 +104,13 @@ var zigAnalysis;
103104 // let nodesToCallsMap = indexNodesToCalls();
104105
105106 domSearch.addEventListener("keydown", onSearchKeyDown, false);
107 domSearch.addEventListener("focus", ev => {
108 domSearchPlaceholder.classList.add("hidden");
109 });
110 domSearch.addEventListener("blur", ev => {
111 if (domSearch.value.length == 0)
112 domSearchPlaceholder.classList.remove("hidden");
113 });
106114 domPrivDeclsBox.addEventListener(
107115 "change",
108116 function () {
......@@ -2623,6 +2631,10 @@ var zigAnalysis;
26232631 updateCurNav();
26242632 if (domSearch.value !== curNavSearch) {
26252633 domSearch.value = curNavSearch;
2634 if (domSearch.value.length == 0)
2635 domSearchPlaceholder.classList.remove("hidden");
2636 else
2637 domSearchPlaceholder.classList.add("hidden");
26262638 }
26272639 render();
26282640 if (imFeelingLucky) {