| 1 |
;(function ($) { |
| 2 |
$(document).ready(function () { |
| 3 |
const overlay = $('.bbpc-search-overlay'); |
| 4 |
|
| 5 |
// Show overlay on input or result click |
| 6 |
$('#searchInput, #bbpc-search-result, .bbpc-search-keyword ul li a').on('click', function () { |
| 7 |
overlay.css('display', 'block').addClass('active'); |
| 8 |
}); |
| 9 |
|
| 10 |
// Hide overlay |
| 11 |
overlay.on('click', function () { |
| 12 |
overlay.css('display', 'none').removeClass('active'); |
| 13 |
}); |
| 14 |
|
| 15 |
// Focus in search input |
| 16 |
$('.bbpc_search_form_wrapper').on('focusin', function () { |
| 17 |
$('.body_dark #searchInput').addClass('input_focused'); |
| 18 |
if ($('#bbpc-search-result.ajax-search').length > 0) { |
| 19 |
$('.body_dark #searchInput').addClass('input_focused'); |
| 20 |
} |
| 21 |
}); |
| 22 |
|
| 23 |
// Focus out search input |
| 24 |
$('.bbpc_search_form_wrapper').on('focusout', function () { |
| 25 |
if ($('#bbpc-search-result.ajax-search').length > 0) { |
| 26 |
$('.body_dark #searchInput').addClass('input_focused'); |
| 27 |
} else { |
| 28 |
$('.body_dark #searchInput').removeClass('input_focused'); |
| 29 |
} |
| 30 |
}); |
| 31 |
|
| 32 |
$('#searchInput').on('keyup', function () { |
| 33 |
$('.click_capture').css({ 'opacity': '0', 'visibility': 'hidden' }); |
| 34 |
}); |
| 35 |
|
| 36 |
// Debounced AJAX search |
| 37 |
let debounceTimer; |
| 38 |
$('#searchInput').on('keyup', function () { |
| 39 |
$('.not-found-text').hide(); |
| 40 |
clearTimeout(debounceTimer); |
| 41 |
const searchInput = $(this).val(); |
| 42 |
const ajax_url = bbpc_localize_script.ajaxurl; |
| 43 |
|
| 44 |
debounceTimer = setTimeout(function () { |
| 45 |
if (searchInput !== '') { |
| 46 |
$.ajax({ |
| 47 |
url: ajax_url, |
| 48 |
method: 'POST', |
| 49 |
data: { |
| 50 |
action: 'bbpc_search_data_fetch', |
| 51 |
keyword: searchInput |
| 52 |
}, |
| 53 |
beforeSend: function () { |
| 54 |
$('.spinner').show(); |
| 55 |
}, |
| 56 |
success: function (data) { |
| 57 |
$('#bbpc-search-result').html(data).addClass('ajax-search'); |
| 58 |
$('.spinner').hide(); |
| 59 |
|
| 60 |
const no_result = $('.tab-item.active.all-active').attr('data-noresult'); |
| 61 |
if (no_result) { |
| 62 |
const msg = no_result.replace(/-/g, ' '); |
| 63 |
$('#bbpc-search-result').html('<h5 class="bbpc-not-found-text">' + msg + '</h5>'); |
| 64 |
$('.bbpc-not-found-text').show(); |
| 65 |
} |
| 66 |
} |
| 67 |
}); |
| 68 |
} |
| 69 |
}, 1000); |
| 70 |
}); |
| 71 |
|
| 72 |
// Keyword click handler — OUTSIDE of previous click |
| 73 |
$('.bbpc-search-keyword ul li a').on('click', function (e) { |
| 74 |
e.preventDefault(); |
| 75 |
const content = $(this).text(); |
| 76 |
const ajax_url = bbpc_localize_script.ajaxurl; |
| 77 |
$('#searchInput').val(content).focus(); |
| 78 |
|
| 79 |
if (content !== '') { |
| 80 |
$.ajax({ |
| 81 |
url: ajax_url, |
| 82 |
method: 'POST', |
| 83 |
data: { |
| 84 |
action: 'bbpc_search_data_fetch', |
| 85 |
keyword: content |
| 86 |
}, |
| 87 |
beforeSend: function () { |
| 88 |
$('.spinner').show(); |
| 89 |
}, |
| 90 |
success: function (data) { |
| 91 |
$('#bbpc-search-result').html(data).addClass('ajax-search'); |
| 92 |
$('.spinner').hide(); |
| 93 |
|
| 94 |
const no_result = $('.tab-item.active.all-active').attr('data-noresult'); |
| 95 |
if (no_result) { |
| 96 |
const msg = no_result.replace(/-/g, ' '); |
| 97 |
$('#bbpc-search-result').html('<h5 class="bbpc-not-found-text">' + msg + '</h5>'); |
| 98 |
$('.bbpc-not-found-text').show(); |
| 99 |
} |
| 100 |
} |
| 101 |
}); |
| 102 |
} |
| 103 |
}); |
| 104 |
|
| 105 |
// Clear search input |
| 106 |
$('#searchInput').on('input', function () { |
| 107 |
if (this.value === '') { |
| 108 |
$('#bbpc-search-result').removeClass('ajax-search'); |
| 109 |
} |
| 110 |
}); |
| 111 |
|
| 112 |
// Overlay behavior |
| 113 |
$("#searchInput").on('focus', function () { |
| 114 |
$('body').addClass('bbpc-search-overlay'); |
| 115 |
$('form.bbpc_search_form_wrapper').css('z-index', '999'); |
| 116 |
}); |
| 117 |
|
| 118 |
$(".bbpc-search-overlay").on('click', function () { |
| 119 |
$('body').removeClass('bbpc-search-overlay'); |
| 120 |
$('form.bbpc_search_form_wrapper').css('z-index', 'unset'); |
| 121 |
}); |
| 122 |
}); |
| 123 |
})(jQuery); |
| 124 |
|