forked from zaclys/searxng
[simple theme] refactor search form
* update search input form params; inspiried by whoogle * remove autofocus from result page input form (JS impl. as well as input param) -> autofocus on landing page still works only on desktop and tablet with JS impl. * update landing page margins on mobile * rework border and radius for search form to 0.8rem and outline * remove positioning from autocomplete JS lib and use CSS impl. * match search box and autocomplete width * rework search form to a google like design on mobile * fix settings icon display withg RTL on mobile on result page when search input is empty
This commit is contained in:
parent
b14ed494fb
commit
47dcf876ff
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
var firstFocus = true, qinput_id = "q", qinput;
|
var firstFocus = true, qinput_id = "q", qinput;
|
||||||
|
|
||||||
|
const isMobile = window.matchMedia("only screen and (max-width: 50em)").matches;
|
||||||
|
|
||||||
function placeCursorAtEnd (element) {
|
function placeCursorAtEnd (element) {
|
||||||
if (element.setSelectionRange) {
|
if (element.setSelectionRange) {
|
||||||
var len = element.value.length;
|
var len = element.value.length;
|
||||||
|
@ -68,12 +70,7 @@
|
||||||
},
|
},
|
||||||
MinChars: 4,
|
MinChars: 4,
|
||||||
Delay: 300,
|
Delay: 300,
|
||||||
_Position: function () {
|
_Position: function () {},
|
||||||
this.DOMResults.setAttribute("class", "autocomplete");
|
|
||||||
this.DOMResults.style.top = (this.Input.offsetTop + this.Input.offsetHeight) + "px";
|
|
||||||
this.DOMResults.style.left = this.Input.offsetLeft + "px";
|
|
||||||
this.DOMResults.style.width = this.Input.clientWidth + "px";
|
|
||||||
},
|
|
||||||
_Open: function () {
|
_Open: function () {
|
||||||
var params = this;
|
var params = this;
|
||||||
Array.prototype.forEach.call(this.DOMResults.getElementsByTagName("li"), function (li) {
|
Array.prototype.forEach.call(this.DOMResults.getElementsByTagName("li"), function (li) {
|
||||||
|
@ -85,16 +82,13 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}, "#" + qinput_id);
|
}, "#" + qinput_id);
|
||||||
|
|
||||||
// hack, see : https://github.com/autocompletejs/autocomplete.js/issues/37
|
|
||||||
w.addEventListener('resize', function () {
|
|
||||||
var event = new CustomEvent("position");
|
|
||||||
qinput.dispatchEvent(event);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qinput.addEventListener('focus', placeCursorAtEndOnce, false);
|
qinput.addEventListener('focus', placeCursorAtEndOnce, false);
|
||||||
qinput.focus();
|
|
||||||
|
if (!isMobile) {
|
||||||
|
qinput.focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// vanilla js version of search_on_category_select.js
|
// vanilla js version of search_on_category_select.js
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
.autocomplete {
|
.autocomplete {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
width: @search-width;
|
||||||
max-height: 0;
|
max-height: 0;
|
||||||
overflow-y: hidden;
|
overflow-y: hidden;
|
||||||
.ltr-text-align-left();
|
.ltr-text-align-left();
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
|
|
||||||
> li {
|
> li {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem 1rem;
|
||||||
|
|
||||||
&.active,
|
&.active,
|
||||||
&:active,
|
&:active,
|
||||||
|
@ -51,9 +52,10 @@
|
||||||
background-color: var(--color-autocomplete-background);
|
background-color: var(--color-autocomplete-background);
|
||||||
color: var(--color-autocomplete-font);
|
color: var(--color-autocomplete-font);
|
||||||
border: 1px solid var(--color-autocomplete-border);
|
border: 1px solid var(--color-autocomplete-border);
|
||||||
max-height: 500px;
|
max-height: 32rem;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
|
margin-top: 3.2rem;
|
||||||
|
|
||||||
&:empty {
|
&:empty {
|
||||||
display: none;
|
display: none;
|
||||||
|
@ -63,11 +65,10 @@
|
||||||
|
|
||||||
@media screen and (max-width: @phone) {
|
@media screen and (max-width: @phone) {
|
||||||
.autocomplete {
|
.autocomplete {
|
||||||
bottom: 0;
|
width: 100%;
|
||||||
}
|
|
||||||
|
|
||||||
.autocomplete > ul > li {
|
> ul > li {
|
||||||
border-bottom: 1px solid var(--color-result-top-border);
|
padding: 1rem;
|
||||||
text-align: left;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,7 +242,7 @@
|
||||||
@result-padding: 1rem;
|
@result-padding: 1rem;
|
||||||
@results-image-row-height: 12rem;
|
@results-image-row-height: 12rem;
|
||||||
@results-image-row-height-phone: 6rem;
|
@results-image-row-height-phone: 6rem;
|
||||||
@search-width: 40rem;
|
@search-width: 44rem;
|
||||||
// heigh of #search, see detail.less
|
// heigh of #search, see detail.less
|
||||||
@search-height: 7.6rem;
|
@search-height: 7.6rem;
|
||||||
|
|
||||||
|
|
|
@ -49,9 +49,3 @@
|
||||||
margin-top: 6em;
|
margin-top: 6em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: @phone) {
|
|
||||||
#main_index {
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -89,10 +89,14 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.search_box {
|
#search_view {
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
grid-area: search;
|
grid-area: search;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search_box {
|
||||||
|
border: 1px solid var(--color-search-border);
|
||||||
|
border-radius: 0.8rem;
|
||||||
|
width: @search-width;
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
@ -102,18 +106,14 @@
|
||||||
display: block;
|
display: block;
|
||||||
border-collapse: separate;
|
border-collapse: separate;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
width: 1.8em;
|
width: 1.8rem;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 8px 2px;
|
padding: 0.8rem 0.2rem;
|
||||||
background: none repeat scroll 0 0 var(--color-search-background);
|
background: none repeat scroll 0 0 var(--color-search-background);
|
||||||
border-top: 1px solid var(--color-search-border);
|
border: none;
|
||||||
border-bottom: 1px solid var(--color-search-border);
|
|
||||||
border-right: none;
|
|
||||||
border-left: none;
|
|
||||||
border-radius: 0;
|
|
||||||
outline: none;
|
outline: none;
|
||||||
color: var(--color-search-font);
|
color: var(--color-search-font);
|
||||||
font-size: 16px;
|
font-size: 1.1rem;
|
||||||
z-index: 10000;
|
z-index: 10000;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
|
@ -131,27 +131,22 @@ html.no-js #clear_search.hide_if_nojs {
|
||||||
|
|
||||||
#q,
|
#q,
|
||||||
#send_search {
|
#send_search {
|
||||||
display: block !important;
|
display: block;
|
||||||
border-collapse: separate;
|
|
||||||
box-sizing: border-box;
|
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 10px;
|
padding: 0.8rem;
|
||||||
background: none repeat scroll 0 0 var(--color-search-background);
|
background: none repeat scroll 0 0 var(--color-search-background);
|
||||||
border: 1px solid var(--color-search-border);
|
border: none;
|
||||||
border-radius: 0;
|
|
||||||
outline: none;
|
outline: none;
|
||||||
color: var(--color-search-font);
|
color: var(--color-search-font);
|
||||||
font-size: 16px;
|
font-size: 1.1rem;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#q {
|
#q {
|
||||||
outline: medium none;
|
width: 100%;
|
||||||
.ltr-padding-left(12px);
|
.ltr-padding-left(1rem);
|
||||||
.ltr-padding-right(0) !important;
|
.ltr-padding-right(0) !important;
|
||||||
.ltr-border-right(none);
|
.ltr-rounded-left-corners(0.8rem);
|
||||||
width: @search-width;
|
|
||||||
.ltr-rounded-left-corners(10px);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#q::-ms-clear,
|
#q::-ms-clear,
|
||||||
|
@ -160,8 +155,7 @@ html.no-js #clear_search.hide_if_nojs {
|
||||||
}
|
}
|
||||||
|
|
||||||
#send_search {
|
#send_search {
|
||||||
.ltr-border-left(none);
|
.ltr-rounded-right-corners(0.8rem);
|
||||||
.ltr-rounded-right-corners(10px);
|
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -174,7 +168,6 @@ html.no-js #clear_search.hide_if_nojs {
|
||||||
.no-js #send_search {
|
.no-js #send_search {
|
||||||
width: auto !important;
|
width: auto !important;
|
||||||
.ltr-border-left(1px solid var(--color-search-border));
|
.ltr-border-left(1px solid var(--color-search-border));
|
||||||
padding: 10px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.search_filters {
|
.search_filters {
|
||||||
|
@ -259,10 +252,9 @@ html.no-js #clear_search.hide_if_nojs {
|
||||||
}
|
}
|
||||||
|
|
||||||
.search_box {
|
.search_box {
|
||||||
// hack, should be 100% ?
|
width: 98%;
|
||||||
width: 99%;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
#q {
|
#q {
|
||||||
|
@ -270,11 +262,6 @@ html.no-js #clear_search.hide_if_nojs {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#main_results #q:placeholder-shown ~ #send_search {
|
|
||||||
margin-right: 2.6rem;
|
|
||||||
transition: margin-right 0.1s; // FIX RTL
|
|
||||||
}
|
|
||||||
|
|
||||||
.search_filters {
|
.search_filters {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
@ -285,7 +272,7 @@ html.no-js #clear_search.hide_if_nojs {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
||||||
label {
|
label {
|
||||||
padding: 0.8rem !important;
|
padding: 1rem !important;
|
||||||
margin: 0 !important;
|
margin: 0 !important;
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
|
@ -293,6 +280,38 @@ html.no-js #clear_search.hide_if_nojs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#search_view:focus-within {
|
||||||
|
display: block;
|
||||||
|
background-color: var(--color-base-background);
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
z-index: 10000;
|
||||||
|
|
||||||
|
.search_box {
|
||||||
|
border-top: none;
|
||||||
|
border-left: none;
|
||||||
|
border-right: none;
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 0;
|
||||||
|
|
||||||
|
#send_search {
|
||||||
|
.ltr-margin-right(0) !important; // Delete when send_search button is disabled on mobile.
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
border: none;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#main_results #q:placeholder-shown ~ #send_search {
|
||||||
|
.ltr-margin-right(2.6rem);
|
||||||
|
transition: margin 0.1s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: @ultra-small-phone) {
|
@media screen and (max-width: @ultra-small-phone) {
|
||||||
|
|
|
@ -4,10 +4,12 @@
|
||||||
<span hidden>SearXNG</span>
|
<span hidden>SearXNG</span>
|
||||||
{% include '__common__/searxng-wordmark.min.svg' without context %}
|
{% include '__common__/searxng-wordmark.min.svg' without context %}
|
||||||
</a>
|
</a>
|
||||||
<div class="search_box">
|
<div id="search_view">
|
||||||
<input id="q" autofocus name="q" type="text" placeholder="{{ _('Search for...') }}" autocomplete="off" spellcheck="false" dir="auto" value="{{ q or '' }}">
|
<div class="search_box">
|
||||||
<button id="clear_search" type="reset" aria-label="{{ _('clear') }}" class="hide_if_nojs"><span>{{ icon_big('close') }}</span><span class="show_if_nojs">{{ _('clear') }}</span></button>
|
<input id="q" name="q" type="text" placeholder="{{ _('Search for...') }}" autocomplete="off" autocapitalize="none" spellcheck="false" autocorrect="off" dir="auto" value="{{ q or '' }}">
|
||||||
<button id="send_search" type="submit" aria-label="{{ _('search') }}"><span class="hide_if_nojs">{{ icon_big('search-outline') }}</span><span class="show_if_nojs">{{ _('search') }}</span></button>
|
<button id="clear_search" type="reset" aria-label="{{ _('clear') }}" class="hide_if_nojs"><span>{{ icon_big('close') }}</span><span class="show_if_nojs">{{ _('clear') }}</span></button>
|
||||||
|
<button id="send_search" type="submit" aria-label="{{ _('search') }}"><span class="hide_if_nojs">{{ icon_big('search-outline') }}</span><span class="show_if_nojs">{{ _('search') }}</span></button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% set display_tooltip = true %}
|
{% set display_tooltip = true %}
|
||||||
{% include 'simple/categories.html' %}
|
{% include 'simple/categories.html' %}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
<form id="search" method="{{ method or 'POST' }}" action="{{ url_for('search') }}" role="search">
|
<form id="search" method="{{ method or 'POST' }}" action="{{ url_for('search') }}" role="search">
|
||||||
<div id="search_header">
|
<div id="search_header">
|
||||||
<div class="search_box">
|
<div id="search_view">
|
||||||
<input id="q" autofocus name="q" type="text" placeholder="{{ _('Search for...') }}" autocomplete="off" spellcheck="false" dir="auto" value="{{ q or '' }}">
|
<div class="search_box">
|
||||||
<button id="clear_search" type="reset" aria-label="{{ _('clear') }}"><span class="hide_if_nojs">{{ icon_big('close') }}</span><span class="show_if_nojs">{{ _('clear') }}</span></button>
|
<input id="q" name="q" type="text" placeholder="{{ _('Search for...') }}" autocomplete="off" autocapitalize="none" spellcheck="false" autocorrect="off" dir="auto" value="{{ q or '' }}">
|
||||||
<button id="send_search" type="submit" aria-label="{{ _('search') }}"><span class="hide_if_nojs">{{ icon_big('search-outline') }}</span><span class="show_if_nojs">{{ _('search') }}</span></button>
|
<button id="clear_search" type="reset" aria-label="{{ _('clear') }}"><span class="hide_if_nojs">{{ icon_big('close') }}</span><span class="show_if_nojs">{{ _('clear') }}</span></button>
|
||||||
|
<button id="send_search" type="submit" aria-label="{{ _('search') }}"><span class="hide_if_nojs">{{ icon_big('search-outline') }}</span><span class="show_if_nojs">{{ _('search') }}</span></button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue