diff --git a/GanjooRazor/Pages/Index.cshtml b/GanjooRazor/Pages/Index.cshtml index 0ecf333a..687743dc 100644 --- a/GanjooRazor/Pages/Index.cshtml +++ b/GanjooRazor/Pages/Index.cshtml @@ -57,7 +57,10 @@ else
- + + + + -
-
دسته‌بندی بر اساس قرن
diff --git a/GanjooRazor/wwwroot/css/p8.css b/GanjooRazor/wwwroot/css/p8.css index 6468b40e..0b0204a4 100644 --- a/GanjooRazor/wwwroot/css/p8.css +++ b/GanjooRazor/wwwroot/css/p8.css @@ -303,6 +303,45 @@ select { text-align: left } +/* #searchhorm input, #searchhorm select, #searchhorm label (further below in this file) float + them all right, which is how the search box's input/combo/button end up in the right order in + this RTL layout - each one floats to the right of the one before it. Wrapping the text input in + this span for the clear button moved it out from under that rule (a plain, non-floated span + isn't selected by "#searchhorm input"), which is what reshuffled the search box the first time + this shipped. Floating the wrapper itself the same way, and cancelling the float that still lands + on the nested input, restores the original left-to-right float order. */ +#searchhorm .home-search-input-wrap { + position: relative; + float: right; + margin: 1px; +} + +#searchhorm .home-search-input-wrap input { + float: none; + margin: 0; +} + +#searchhorm .home-search-input-wrap .inputText { + padding-inline-end: 20px; +} + +.home-search-clear { + position: absolute; + inset-inline-end: 4px; + top: 50%; + transform: translateY(-50%); + cursor: pointer; + font-size: 1.1em; + line-height: 1; + color: var(--text-muted); + padding: 0 3px; + user-select: none; +} + +.home-search-clear:hover { + color: var(--ink-black); +} + #guides { max-width: 860px; display: block; diff --git a/GanjooRazor/wwwroot/js/bk.js b/GanjooRazor/wwwroot/js/bk.js index 06997999..64f71c57 100644 --- a/GanjooRazor/wwwroot/js/bk.js +++ b/GanjooRazor/wwwroot/js/bk.js @@ -1554,6 +1554,55 @@ function persianizeNumerals(value) { .replace(/9/gi, "۹"); } +// Home page (Index.cshtml) only: the top search box (#s) used to just submit a full poem search +// (POST-free GET to /search) and the home page separately had its own "جستجوی سخنور" inline box +// (#findpoet, now removed) that filtered the poet list live as you typed. This merges that second +// behavior into the top box: typing filters poets live (same underlying match as onInlineSearch, +// against every ".poet" element's data-value), while submitting the form (Enter / the "بیاب" button) +// still does the original full poem search unchanged - so nothing about submission itself changes. +function onHomeSearchInput(value) { + var clearBtn = document.getElementById('home-search-clear'); + var popularRow = document.getElementById('home-popular-poets-row'); + var foundNode = document.getElementById('home-found-poets'); + var hintNode = document.getElementById('home-search-hint'); + if (!foundNode) return; + + var hasValue = value.length > 0; + if (clearBtn) clearBtn.style.display = hasValue ? 'inline' : 'none'; + if (popularRow) popularRow.style.display = hasValue ? 'none' : ''; + if (hintNode) hintNode.style.display = hasValue ? 'block' : 'none'; + + foundNode.innerHTML = ''; + if (!hasValue) { + foundNode.style.display = 'none'; + return; + } + + var replaced = persianizeNumerals(value); + // querySelectorAll (not getElementsByClassName) is required here: getElementsByClassName + // returns a LIVE collection, and the clones we append below also carry class="poet" and land + // earlier in document order than the originals (home-found-poets sits above the poet lists) - + // every append was reshuffling the live collection's indices so the same source element kept + // reappearing at the loop's current index forever, hanging the page. querySelectorAll takes a + // static snapshot up front, so appends during the loop can't affect it. + var poets = document.querySelectorAll('.poet'); + for (var i = 0; i < poets.length; i++) { + var dataValue = poets[i].getAttribute('data-value'); + if (dataValue != null && dataValue.indexOf(replaced) !== -1) { + foundNode.appendChild(poets[i].cloneNode(true)); + } + } + foundNode.style.display = foundNode.childElementCount > 0 ? '' : 'none'; +} + +function clearHomeSearch() { + var input = document.getElementById('s'); + if (!input) return; + input.value = ''; + onHomeSearchInput(''); + input.focus(); +} + function onInlineSearch(value, resultBlockId, itemsClass) { const foundPoetsNode = document.getElementById(resultBlockId); foundPoetsNode.innerHTML = '';