Commit 121ce1d9 authored by Thomas Löffler's avatar Thomas Löffler
Browse files

[TASK] Add delay on suggest and extensions section

parent ec80c09b
Pipeline #20059 failed with stages
in 1 minute and 46 seconds
......@@ -6,11 +6,11 @@
<f:if condition="{documents}">
<f:then>
<f:for each="{documents}" as="document">
<p class="mb-3">
<a href="{document.fields.url}">
{document.fields.title}
</a>
</p>
<a class="small" href="{document.fields.url}">
<p class="mb-3">
{document.fields.title} &mdash; {document.fields.content -> f:format.crop(maxCharacters: 40)}
</p>
</a>
</f:for>
</f:then>
<f:else>
......@@ -23,11 +23,11 @@
<f:if condition="{documents}">
<f:then>
<f:for each="{documents}" as="document">
<p class="mb-3">
<a href="{document.fields.url}">
{document.fields.title} ({document.fields.datetime_intS -> f:format.date(format: 'd.m.Y')})
</a>
</p>
<a class="small" href="{document.fields.url}">
<p class="mb-3">
{document.fields.datetime_intS -> f:format.date(format: 'd.m.Y')} &mdash; {document.fields.title}
</p>
</a>
</f:for>
</f:then>
<f:else>
......@@ -40,11 +40,28 @@
<f:if condition="{documents}">
<f:then>
<f:for each="{documents}" as="document">
<p class="mb-3">
<a href="{document.fields.url}">
{document.fields.title} ({document.fields.startdate_intS -> f:format.date(format: 'd.m.Y')})
</a>
</p>
<a class="small" href="{document.fields.url}">
<p class="mb-3">
{document.fields.startdate_intS -> f:format.date(format: 'd.m.Y')} &mdash; {document.fields.title}
</p>
</a>
</f:for>
</f:then>
<f:else>
No results found.
</f:else>
</f:if>
</f:section>
<f:section name="tx_terfe2_domain_model_extension">
<h3>Top 5 extensions</h3>
<f:if condition="{documents}">
<f:then>
<f:for each="{documents}" as="document">
<a class="small" href="{document.fields.url}">
<p class="mb-3">
{document.fields.extensionKey_stringS} &mdash; {document.fields.title}
</p>
</a>
</f:for>
</f:then>
<f:else>
......
let _searchPages = null;
let _searchNews = null;
let _searchEvents = null;
let _searchExtensions = null;
function delay(fn, ms) {
let timer = 0
return function (...args) {
clearTimeout(timer)
timer = setTimeout(fn.bind(this, ...args), ms || 0)
}
}
function doSearch(_searchQuery) {
_searchPages = $.ajax(
......@@ -45,6 +54,20 @@ function doSearch(_searchQuery) {
}
}
);
_searchExtensions = $.ajax(
{
type: "GET",
url: "/",
data: {
"q": _searchQuery,
"ajaxsearch": 1,
"type": "tx_terfe2_domain_model_extension"
},
success: function (response) {
$('.results-list-insert-extensions').html(response);
}
}
);
$('.show-results').on('click', function () {
$('.main-nav__solr-form').submit();
......@@ -54,9 +77,9 @@ function doSearch(_searchQuery) {
$(document).ready(function () {
$('.js__full-width-dropdown__search').html('<div class="container"><div class="mt-4 mb-4 row"><div class="col search-result-list results-list-insert-pages"></div><div class="col search-result-list results-list-insert-news"></div><div class="col search-result-list results-list-insert-events"></div></div><div><a class="btn btn-secondary show-results" hidden>Show all results</a> </div></div></div>')
$('.js__full-width-dropdown__search').html('<div class="container"><div class="mt-4 mb-2 row"><div class="col search-result-list results-list-insert-pages"></div><div class="col search-result-list results-list-insert-news"></div><div class="col search-result-list results-list-insert-events"></div><div class="col search-result-list results-list-insert-extensions"></div></div><div class="text-right"><a class="btn btn-secondary show-results" hidden>Show all results</a> </div></div></div>')
$(".js__main-nav__solr-form_input").keyup(function (e) {
$(".js__main-nav__solr-form_input").keyup(delay(function (e) {
var search = $(this).val();
if (search.length > 2) {
......@@ -69,6 +92,9 @@ $(document).ready(function () {
if (_searchEvents) {
_searchEvents.abort();
}
if (_searchExtensions) {
_searchExtensions.abort();
}
doSearch(search);
} else {
......@@ -81,9 +107,13 @@ $(document).ready(function () {
if (_searchEvents) {
_searchEvents.abort();
}
if (_searchExtensions) {
_searchExtensions.abort();
}
$('.results-list-insert-pages').html('');
$('.results-list-insert-news').html('');
$('.results-list-insert-events').html('');
$('.results-list-insert-extensions').html('');
}
});
}, 500));
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment