catalog-search.js: format

This commit is contained in:
Zankaria 2024-08-05 19:08:28 +02:00
parent d9feb5cfa7
commit d9d05ddbf5

View File

@ -8,21 +8,21 @@
* $config['additional_javascript'][] = 'js/comment-toolbar.js'; * $config['additional_javascript'][] = 'js/comment-toolbar.js';
*/ */
if (active_page == 'catalog') { if (active_page == 'catalog') {
onready(function () { onready(function() {
'use strict'; 'use strict';
// 'true' = enable shortcuts // 'true' = enable shortcuts
var useKeybinds = true; let useKeybinds = true;
// trigger the search 400ms after last keystroke // trigger the search 400ms after last keystroke
var delay = 400; let delay = 400;
var timeoutHandle; let timeoutHandle;
//search and hide none matching threads // search and hide none matching threads
function filter(search_term) { function filter(search_term) {
$('.replies').each(function () { $('.replies').each(function () {
var subject = $(this).children('.intro').text().toLowerCase(); let subject = $(this).children('.intro').text().toLowerCase();
var comment = $(this).clone().children().remove(':lt(2)').end().text().trim().toLowerCase(); let comment = $(this).clone().children().remove(':lt(2)').end().text().trim().toLowerCase();
search_term = search_term.toLowerCase(); search_term = search_term.toLowerCase();
if (subject.indexOf(search_term) == -1 && comment.indexOf(search_term) == -1) { if (subject.indexOf(search_term) == -1 && comment.indexOf(search_term) == -1) {
@ -34,7 +34,7 @@ if (active_page == 'catalog') {
} }
function searchToggle() { function searchToggle() {
var button = $('#catalog_search_button'); let button = $('#catalog_search_button');
if (!button.data('expanded')) { if (!button.data('expanded')) {
button.data('expanded', '1'); button.data('expanded', '1');
@ -59,7 +59,7 @@ if (active_page == 'catalog') {
}); });
if (useKeybinds) { if (useKeybinds) {
// 's' // 's'
$('body').on('keydown', function (e) { $('body').on('keydown', function (e) {
if (e.which === 83 && e.target.tagName === 'BODY' && !(e.ctrlKey || e.altKey || e.shiftKey)) { if (e.which === 83 && e.target.tagName === 'BODY' && !(e.ctrlKey || e.altKey || e.shiftKey)) {
e.preventDefault(); e.preventDefault();
@ -70,7 +70,7 @@ if (active_page == 'catalog') {
} }
} }
}); });
// 'esc' // 'esc'
$('.catalog_search').on('keydown', 'input#search_field', function (e) { $('.catalog_search').on('keydown', 'input#search_field', function (e) {
if (e.which === 27 && !(e.ctrlKey || e.altKey || e.shiftKey)) { if (e.which === 27 && !(e.ctrlKey || e.altKey || e.shiftKey)) {
window.clearTimeout(timeoutHandle); window.clearTimeout(timeoutHandle);