fix: prevent duplicate search triggers

if app.handleSearch is called from a plugin in action:ajaxify.end events are fired multiple time
v1.18.x
Barış Soner Uşaklı 5 years ago
parent 7f24200c73
commit 6f78113ee3

@ -574,12 +574,13 @@ app.cacheBuster = null;
var inputEl = options.inputEl;
var template = options.template || 'partials/quick-search-results';
var searchTimeoutId = 0;
inputEl.on('keyup', function () {
var currentVal = inputEl.val();
inputEl.off('keyup').on('keyup', function () {
if (searchTimeoutId) {
clearTimeout(searchTimeoutId);
searchTimeoutId = 0;
}
if (inputEl.val().length < 3) {
if (inputEl.val().length < 3 || inputEl.val() === currentVal) {
return;
}
@ -618,15 +619,15 @@ app.cacheBuster = null;
var searchInput = $('#search-fields input');
var quickSearchResults = $('#quick-search-results');
$('#search-form .advanced-search-link').on('mousedown', function () {
$('#search-form .advanced-search-link').off('mousedown').on('mousedown', function () {
ajaxify.go('/search');
});
$('#search-form').on('submit', function () {
$('#search-form').off('submit').on('submit', function () {
searchInput.blur();
});
searchInput.on('blur', dismissSearch);
searchInput.on('focus', function () {
searchInput.off('blur').on('blur', dismissSearch);
searchInput.off('focus').on('focus', function () {
if (searchInput.val() && quickSearchResults.children().length) {
quickSearchResults.removeClass('hidden').show();
}
@ -645,7 +646,7 @@ app.cacheBuster = null;
}, 200);
}
searchButton.on('click', function (e) {
searchButton.off('click').on('click', function (e) {
if (!config.loggedIn && !app.user.privileges['search:content']) {
app.alert({
message: '[[error:search-requires-login]]',
@ -660,7 +661,7 @@ app.cacheBuster = null;
return false;
});
$('#search-form').on('submit', function () {
$('#search-form').off('submit').on('submit', function () {
var input = $(this).find('input');
require(['search'], function (search) {
var data = search.getSearchPreferences();

Loading…
Cancel
Save