Skip to content
Snippets Groups Projects

Resolve "Global search"

Merged Nik | Klampfradler requested to merge 208-global-search into master
3 files
+ 37
1
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -20,11 +20,35 @@ Autocomplete.prototype.setup = function() {
this.form_elem = $(this.form_selector);
this.query_box = this.form_elem.find('input[name=q]');
// Trigger the "keyup" event if input gets focused
this.query_box.focus(function () {
self.query_box.trigger("keyup");
});
// Remove search results if input field isn't focused anymore
$('body').click(function (evt) {
if (evt.target.id in ["search", "search-results"])
return;
//For descendants of search-results being clicked, remove this check if you do not want to put constraint on descendants.
let distance = $(evt.target).closest('#search-results').length;
console.log(distance);
if (0 < distance && distance <= 2) {
console.log("clicked on a search result");
return;
}
//Do processing of click event here for every element except with id search-results
$('#search-results').remove();
});
// Watch the input box.
this.query_box.on('keyup', function() {
var query = self.query_box.val();
if(query.length < self.minimum_length) {
$("#search-results").remove();
return false;
}
Loading