Browse Source

#2266, minCharacterLength should be part of query, not throttled input event

pull/2300/head
jlukic 9 years ago
parent
commit
f1b84555cb
1 changed files with 25 additions and 26 deletions
  1. 51
      src/definitions/modules/search.js

51
src/definitions/modules/search.js

@ -84,7 +84,7 @@ $.fn.search = function(parameters) {
module.verbose('Binding events to search');
if(settings.automatic) {
$module
.on(module.get.inputEvent() + eventNamespace, selector.prompt, module.throttle)
.on(module.get.inputEvent() + eventNamespace, selector.prompt, module.event.input)
;
$prompt
.attr('autocomplete', 'off')
@ -116,6 +116,10 @@ $.fn.search = function(parameters) {
},
event: {
input: function() {
clearTimeout(module.timer);
module.timer = setTimeout(module.query, settings.searchDelay);
},
focus: function() {
module.set.focus();
if( module.has.minimumCharacters() ) {
@ -385,24 +389,29 @@ $.fn.search = function(parameters) {
searchTerm = module.get.value(),
cache = module.read.cache(searchTerm)
;
if(cache) {
module.debug('Reading result from cache', searchTerm);
module.save.results(cache.results);
module.addResults(cache.html);
module.inject.id(cache.results);
}
else {
module.debug('Querying for', searchTerm);
if($.isPlainObject(settings.source) || $.isArray(settings.source)) {
module.search.local(searchTerm);
}
else if( module.can.useAPI() ) {
module.search.remote(searchTerm);
if( module.has.minimumCharacters() ) {
if(cache) {
module.debug('Reading result from cache', searchTerm);
module.save.results(cache.results);
module.addResults(cache.html);
module.inject.id(cache.results);
}
else {
module.error(error.source);
module.debug('Querying for', searchTerm);
if($.isPlainObject(settings.source) || $.isArray(settings.source)) {
module.search.local(searchTerm);
}
else if( module.can.useAPI() ) {
module.search.remote(searchTerm);
}
else {
module.error(error.source);
}
settings.onSearchQuery.call(element, searchTerm);
}
settings.onSearchQuery.call(element, searchTerm);
}
else {
module.hideResults();
}
},
@ -556,16 +565,6 @@ $.fn.search = function(parameters) {
}
},
throttle: function() {
clearTimeout(module.timer);
if(module.has.minimumCharacters()) {
module.timer = setTimeout(module.query, settings.searchDelay);
}
else {
module.hideResults();
}
},
cancel: {
query: function() {
if( module.can.useAPI() ) {

Loading…
Cancel
Save