search on changed query only

linting
pull/4089/head
LB 2017-11-19 00:24:06 +08:00 zatwierdzone przez Janneke Janssen
rodzic 2cd6086f0b
commit 7c54c14709
3 zmienionych plików z 33 dodań i 17 usunięć

Wyświetl plik

@ -34,6 +34,7 @@ Changelog
* Fix: PostgreSQL search backend now removes duplicate page instances from the database (Bertrand Bordage)
* Fix: `FormSubmissionsPanel` now recognises custom form submission classes (LB (Ben Johnston))
* Fix: Prevent the footer and revisions link from unnecessarily collapsing on mobile (Jack Paine)
* Fix: Empty searches were activated when paginating through images and documents (LB (Ben Johnston))
1.13.1 (17.11.2017)

Wyświetl plik

@ -52,6 +52,7 @@ Bug fixes
* PostgreSQL search backend now removes duplicate page instances from the database (Bertrand Bordage)
* ``FormSubmissionsPanel`` now recognises custom form submission classes (LB (Ben Johnston))
* Prevent the footer and revisions link from unnecessarily collapsing on mobile (Jack Paine)
* Empty searches were activated when paginating through images and documents (LB (Ben Johnston))
Upgrade considerations

Wyświetl plik

@ -219,7 +219,7 @@ $(function() {
var searchCurrentIndex = 0;
var searchNextIndex = 0;
$(window.headerSearch.termInput).on('keyup cut paste', function() {
$(window.headerSearch.termInput).on('keyup cut paste change', function() {
clearTimeout($.data(this, 'timer'));
var wait = setTimeout(search, 200);
$(this).data('timer', wait);
@ -231,25 +231,39 @@ $(function() {
function search() {
var workingClasses = 'icon-spinner';
$(window.headerSearch.termInput).parent().addClass(workingClasses);
searchNextIndex++;
var index = searchNextIndex;
$.ajax({
url: window.headerSearch.url,
data: {q: $(window.headerSearch.termInput).val()},
success: function(data, status) {
if (index > searchCurrentIndex) {
searchCurrentIndex = index;
$(window.headerSearch.targetOutput).html(data).slideDown(800);
window.history.pushState(null, 'Search results', '?q=' + $(window.headerSearch.termInput).val());
var newQuery = $(window.headerSearch.termInput).val();
var currentQuery = getURLParam('q');
// only do the query if it has changed for trimmed queries
// eg. " " === "" and "firstword " ==== "firstword"
if (currentQuery.trim() !== newQuery.trim()) {
$(window.headerSearch.termInput).parent().addClass(workingClasses);
searchNextIndex++;
var index = searchNextIndex;
$.ajax({
url: window.headerSearch.url,
data: {q: newQuery},
success: function(data, status) {
if (index > searchCurrentIndex) {
searchCurrentIndex = index;
$(window.headerSearch.targetOutput).html(data).slideDown(800);
window.history.pushState(null, 'Search results', '?q=' + newQuery);
}
},
complete: function() {
$(window.headerSearch.termInput).parent().removeClass(workingClasses);
}
},
});
}
};
complete: function() {
$(window.headerSearch.termInput).parent().removeClass(workingClasses);
}
});
getURLParam = function(name) {
var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.search);
if (results) {
return results[1];
}
return '';
}
}
/* Functions that need to run/rerun when active tabs are changed */