<form method="get" id="searchform" autocomplete="off" onsubmit="return false;" class="search-bar">
<div id="searchContainer" class="search-result-wrp">
<!-- <div class="page_navigation"></div>-->
<div id="searchResult" data-search-result></div>
<div id="pagination" class="pagination"></div>
</div>
<label>
<input type="search" placeholder="Suche" class="input-input font-light searchtext" name="s" type="text"/>
</label>
<div class="autocomplete-suggestions"></div>
</form>
<img src="/bundles/app/static/frontend/images/icons/lupe_neg.svg" alt="Lupe" class="lupe"/>
<script type="text/javascript">
(function () {
var moduleName = 'main_module'; // naming convention XXX_module
if (typeof selt === 'undefined') {
selt = {
modules: {}
};
} else if (!selt.modules) {
selt.modules = {};
}
selt.modules[moduleName] = {
name: moduleName,
init: function () {
initSearchBar();
paginage();
initSearch();
}
};
function initSearchBar() {
var searchBarInput = $('[type="search"], .search-bar'),
searchBar = $('.lupe'),
searchContainer = $('main #searchContainer'),
searchContainer2 = $('aside #searchContainer');
searchBar.on('click', function (e) {
searchBarInput.toggleClass('focus');
e.stopImmediatePropagation();
});
}
function initSearch() {
// get status modifier element
var searchResult = $('main #searchResult'),
searchResult2 = $('aside #searchResult'),
searchContainer = $('main #searchContainer'),
searchContainer2 = $('aside #searchContainer'),
searchform = $('main #searchform'),
searchform2 = $('aside #searchform'),
searchtext = searchform.find('.searchtext'),
searchtext2 = searchform2.find('.searchtext');
// searchtext.on('keyup', function (e) {
// instantSearch('keyupEvent', this.value);
// });
searchform.on('submit', function (e) {
instantSearch('submit');
});
searchform2.on('submit', function (e) {
instantSearch2('submit');
});
// auto complete
var xhr;
var ac = new autoComplete({
selector: 'input[name="s"]',
minChars: 2,
source: function (term, response) {
try {
xhr.abort();
} catch (e) {
}
xhr = $.getJSON('/search/autocomplete?render=1', {q: term}, function (data) {
response(data);
});
},
onSelect: function (e, term, item) {
instantSearch('submit');
},
onSuggest: function () {
searchContainer.stop(true, true).fadeOut();
}
});
function instantSearch(welchesEvent, keyword) {
var ausgabe = true;
if (welchesEvent === 'submit') {
keyword = searchtext.val();
}
searchContainer.stop(true, true).fadeIn();
ac.hide();
// Falls bereits eine Suche ausgeführt wurde oder noch läuft wird die Anzeige zurück auf
// animierte punkte gesetzt
searchResult.html('<svg version="1.1" id="L4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 52 12" width="50">\n' +
' <circle fill="#000" stroke="none" cx="6" cy="6" r="6">\n' +
' <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.1"></animate>\n' +
' </circle>\n' +
' <circle fill="#000" stroke="none" cx="26" cy="6" r="6">\n' +
' <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.2"></animate>\n' +
' </circle>\n' +
' <circle fill="#000" stroke="none" cx="46" cy="6" r="6">\n' +
' <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.3"></animate>\n' +
' </circle>\n' +
'</svg>');
// In diesem nächsten Schritt erzeugen wir ein jQuery Get Objekt
// und übermitteln die Such-Keywords
var searchServiceUrl = '/search/list?q=' + keyword + '&render=1&lang='+$('html').attr('data-language');
$.get(searchServiceUrl, function (data, success) {
// Wenn der Parameter success auch success zurück gibt
// wurde die GET Anfrage erfolgreich übertragen und Werte zurück geliefert
if (success == 'success') {
console.log(data);
if (data.indexOf('search-result-item') >= 0) {
searchResult.html(data);
paginage();
} else {
searchContainer.stop(true, true).fadeOut();
}
}
});
}
function instantSearch2(welchesEvent, keyword) {
var ausgabe = true;
if (welchesEvent === 'submit') {
keyword = searchtext2.val();
}
searchContainer2.stop(true, true).fadeIn();
ac.hide();
// Falls bereits eine Suche ausgeführt wurde oder noch läuft wird die Anzeige zurück auf
// animierte punkte gesetzt
searchResult2.html('<svg version="1.1" id="L4" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 52 12" width="50">\n' +
' <circle fill="#000" stroke="none" cx="6" cy="6" r="6">\n' +
' <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.1"></animate>\n' +
' </circle>\n' +
' <circle fill="#000" stroke="none" cx="26" cy="6" r="6">\n' +
' <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.2"></animate>\n' +
' </circle>\n' +
' <circle fill="#000" stroke="none" cx="46" cy="6" r="6">\n' +
' <animate attributeName="opacity" dur="1s" values="0;1;0" repeatCount="indefinite" begin="0.3"></animate>\n' +
' </circle>\n' +
'</svg>');
// In diesem nächsten Schritt erzeugen wir ein jQuery Get Objekt
// und übermitteln die Such-Keywords
var searchServiceUrl = '/search/list?q=' + keyword + '&render=1&lang='+$('html').attr('data-language');
$.get(searchServiceUrl, function (data, success) {
// Wenn der Parameter success auch success zurück gibt
// wurde die GET Anfrage erfolgreich übertragen und Werte zurück geliefert
if (success == 'success') {
console.log(data);
if (data.indexOf('search-result-item') >= 0) {
searchResult2.html(data);
paginage();
} else {
searchContainer2.stop(true, true).fadeOut();
}
}
});
}
}
function paginage() {
var searchResultCollection = document.querySelectorAll('main #searchResult li'),
searchResultCollection2 = document.querySelectorAll('aside #searchResult li'),
itemsPerPage = 10,
numberOfItems = searchResultCollection.length,
pageCountFloat = numberOfItems / itemsPerPage,
pageCount = Math.ceil(pageCountFloat),
paginationCell = document.querySelector('main #pagination');
paginationCell2 = document.querySelector('aside #pagination');
function updateResult() {
var showFrom = (this.page - 1) * itemsPerPage,
showTo = showFrom + itemsPerPage;
searchResultCollection.forEach(function (item, index) {
item.classList.remove('show');
if (index >= showFrom && index < showTo) {
item.classList.add('show');
}
});
searchResultCollection2.forEach(function (item, index) {
item.classList.remove('show');
if (index >= showFrom && index < showTo) {
item.classList.add('show');
}
});
paginationCell.classList.add('hide');
if (pageCount > 1) {
paginationCell.classList.remove('hide');
}
paginationCell2.classList.add('hide');
if (pageCount > 1) {
paginationCell.classList.remove('hide');
}
}
selt.pagination.Init(document.querySelector('main #pagination'), {
size: pageCount
}, updateResult);
selt.pagination.Init(document.querySelector('aside #pagination'), {
size: pageCount
}, updateResult);
}
}());//EOS
</script>