Use vanilla js for search

This commit is contained in:
DariusIII
2024-02-16 11:59:35 +01:00
parent 7c8fe68de1
commit 8f18c5f5c2
2 changed files with 26 additions and 8 deletions
File diff suppressed because one or more lines are too long
+25 -7
View File
@@ -505,21 +505,39 @@ jQuery(function ($) {
// headermenu.tpl
$('#headsearch')
.focus(function () {
if (this.value == 'Search...') this.value = '';
if (this.value === 'Search...') this.value = '';
else this.select();
})
.blur(function () {
if (this.value == '') this.value = 'Search...';
if (this.value === '') this.value = 'Search...';
});
$('#headsearch_form').submit(function () {
$('#headsearch_go').trigger('click');
return false;
});
$('#headsearch_go').click(function () {
if ($('#headsearch').val() && $('#headsearch').val() != 'Search...') {
let sText = $('#headsearch').val();
let sCat = $('#headcat').val() != -1 ? '&t=' + $('#headcat').val() : '';
document.location = base_url + '/search?id=' + sText + sCat;
document.getElementById('headsearch_go').addEventListener('click', function () {
let searchInput = document.getElementById('headsearch');
let categoryInput = document.getElementById('headcat');
if (searchInput.value && searchInput.value != 'Search...') {
let sText = searchInput.value;
let sCat = categoryInput.value !== '-1' ? '&t=' + categoryInput.value : 't=-1';
window.location.href = base_url + '/search?' + sCat + '&search=' + sText;
} else {
PNotify.defaults.icons = 'fontawesome5';
PNotify.alert({
title: 'You need to enter a search term!',
type: 'error',
icon: 'fa fa-info fa-3x',
Animate: {
animate: true,
in_class: 'bounceInLeft',
out_class: 'bounceOutRight',
},
desktop: {
desktop: true,
fallback: true,
},
});
}
});