Merge pull request #2071 from nschonni/autocomplete-js-cleaning

Autocomplete js cleaning
This commit is contained in:
Régis Hanol 2014-03-10 17:06:51 +01:00
commit 455ff61626

View File

@ -31,19 +31,16 @@ shiftMap[32] = " ";
function mapKeyPressToActualCharacter(isShiftKey, characterCode) { function mapKeyPressToActualCharacter(isShiftKey, characterCode) {
if ( characterCode === 27 || characterCode === 8 || characterCode === 9 || characterCode === 20 || characterCode === 16 || characterCode === 17 || characterCode === 91 || characterCode === 13 || characterCode === 92 || characterCode === 18 ) { return false; } if ( characterCode === 27 || characterCode === 8 || characterCode === 9 || characterCode === 20 || characterCode === 16 || characterCode === 17 || characterCode === 91 || characterCode === 13 || characterCode === 92 || characterCode === 18 ) { return false; }
if (isShiftKey) { // Lookup non-letter keypress while holding shift
if ( characterCode >= 65 && characterCode <= 90 ) { if (isShiftKey && ( characterCode < 65 || characterCode > 90 )) {
return String.fromCharCode(characterCode);
} else {
return shiftMap[characterCode]; return shiftMap[characterCode];
} }
} else {
if ( characterCode >= 65 && characterCode <= 90 ) { var stringValue = String.fromCharCode(characterCode);
return String.fromCharCode(characterCode).toLowerCase(); if ( !isShiftKey ) {
} else { stringValue = stringValue.toLowerCase();
return String.fromCharCode(characterCode);
}
} }
return stringValue;
} }
$.fn.autocomplete = function(options) { $.fn.autocomplete = function(options) {
@ -268,8 +265,7 @@ $.fn.autocomplete = function(options) {
var prevChar = me.val().charAt(caretPosition - 1); var prevChar = me.val().charAt(caretPosition - 1);
if (!prevChar || /\s/.test(prevChar)) { if (!prevChar || /\s/.test(prevChar)) {
completeStart = completeEnd = caretPosition; completeStart = completeEnd = caretPosition;
var term = ""; updateAutoComplete(options.dataSource(""));
updateAutoComplete(options.dataSource(term));
} }
} }
}); });
@ -401,11 +397,9 @@ $.fn.autocomplete = function(options) {
term += (e.shiftKey) ? "|" : "]"; term += (e.shiftKey) ? "|" : "]";
} else if (e.which === 222) { } else if (e.which === 222) {
term += (e.shiftKey) ? "\"" : "'"; term += (e.shiftKey) ? "\"" : "'";
} else { } else if (e.which !== 8) {
if (e.which !== 8) {
term += ","; term += ",";
} }
}
updateAutoComplete(options.dataSource(term)); updateAutoComplete(options.dataSource(term));
return true; return true;