mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
N°1420 - Autocomplete fix keyboard behavior
This commit is contained in:
@@ -78,7 +78,7 @@
|
|||||||
// Create $ object for input element
|
// Create $ object for input element
|
||||||
var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass);
|
var $input = $(input).attr("autocomplete", "off").addClass(options.inputClass);
|
||||||
|
|
||||||
var timeout;
|
var timeout = new Timer(function() {}, 1);
|
||||||
var previousValue = "";
|
var previousValue = "";
|
||||||
var cache = $.Autocompleter.Cache(options);
|
var cache = $.Autocompleter.Cache(options);
|
||||||
var hasFocus = 0;
|
var hasFocus = 0;
|
||||||
@@ -149,17 +149,16 @@
|
|||||||
case options.multiple && $.trim(options.multipleSeparator) == "," && KEY.COMMA:
|
case options.multiple && $.trim(options.multipleSeparator) == "," && KEY.COMMA:
|
||||||
case KEY.TAB:
|
case KEY.TAB:
|
||||||
case KEY.RETURN:
|
case KEY.RETURN:
|
||||||
// Do not select value while background request pending
|
|
||||||
if(bPendingRequest === true) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( selectCurrent() ) {
|
if( selectCurrent() ) {
|
||||||
// stop default to prevent a form submit, Opera needs special handling
|
// stop default to prevent a form submit, Opera needs special handling
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
blockSubmit = true;
|
blockSubmit = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Do not select value while background request pending
|
||||||
|
if ((bPendingRequest === true) || timeout.isRunning()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KEY.ESC:
|
case KEY.ESC:
|
||||||
@@ -167,8 +166,8 @@
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
clearTimeout(timeout);
|
timeout.stop();
|
||||||
timeout = setTimeout(onChange, options.delay);
|
timeout = new Timer(onChange, options.delay);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}).focus(function(){
|
}).focus(function(){
|
||||||
@@ -279,8 +278,10 @@
|
|||||||
currentValue = lastWord(currentValue);
|
currentValue = lastWord(currentValue);
|
||||||
if ( currentValue.length >= options.minChars) {
|
if ( currentValue.length >= options.minChars) {
|
||||||
$input.addClass(options.loadingClass);
|
$input.addClass(options.loadingClass);
|
||||||
if (!options.matchCase)
|
if (!options.matchCase) {
|
||||||
currentValue = currentValue.toLowerCase();
|
currentValue = currentValue.toLowerCase();
|
||||||
|
}
|
||||||
|
bPendingRequest = true; // used for autocomplete requests only
|
||||||
request(currentValue, receiveData, hideResultsNow);
|
request(currentValue, receiveData, hideResultsNow);
|
||||||
} else {
|
} else {
|
||||||
stopLoading();
|
stopLoading();
|
||||||
@@ -328,14 +329,14 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function hideResults() {
|
function hideResults() {
|
||||||
clearTimeout(timeout);
|
timeout.stop();
|
||||||
timeout = setTimeout(hideResultsNow, 200);
|
timeout = new Timer(hideResultsNow, 200);
|
||||||
};
|
};
|
||||||
|
|
||||||
function hideResultsNow() {
|
function hideResultsNow() {
|
||||||
var wasVisible = select.visible();
|
var wasVisible = select.visible();
|
||||||
select.hide();
|
select.hide();
|
||||||
clearTimeout(timeout);
|
timeout.stop();
|
||||||
stopLoading();
|
stopLoading();
|
||||||
if (options.mustMatch) {
|
if (options.mustMatch) {
|
||||||
// call search and run callback
|
// call search and run callback
|
||||||
@@ -372,7 +373,6 @@
|
|||||||
if (!options.matchCase)
|
if (!options.matchCase)
|
||||||
term = term.toLowerCase();
|
term = term.toLowerCase();
|
||||||
|
|
||||||
bPendingRequest = true;
|
|
||||||
var data = cache.load(term);
|
var data = cache.load(term);
|
||||||
// recieve the cached data
|
// recieve the cached data
|
||||||
if (data) {
|
if (data) {
|
||||||
@@ -445,6 +445,31 @@
|
|||||||
bPendingRequest = false;
|
bPendingRequest = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function Timer(callback, delay) {
|
||||||
|
let id, running;
|
||||||
|
|
||||||
|
this.start = function() {
|
||||||
|
running = true;
|
||||||
|
id = setTimeout(this.doCallback, delay);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.doCallback = function () {
|
||||||
|
running = false;
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.stop = function() {
|
||||||
|
running = false;
|
||||||
|
clearTimeout(id);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.isRunning = function() {
|
||||||
|
return running;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.start();
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$.Autocompleter.defaults = {
|
$.Autocompleter.defaults = {
|
||||||
|
|||||||
Reference in New Issue
Block a user