rename autoComplete directive as tabComplete to avoid confusion with the autocomplete html attribute

This commit is contained in:
Matthew Hodgson 2014-08-22 01:33:05 +01:00
parent 019f3a66f6
commit ab27b49ded

View file

@ -17,30 +17,30 @@
'use strict'; 'use strict';
angular.module('RoomController') angular.module('RoomController')
.directive('autoComplete', ['$timeout', function ($timeout) { .directive('tabComplete', ['$timeout', function ($timeout) {
return function (scope, element, attrs) { return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) { element.bind("keydown keypress", function (event) {
// console.log("event: " + event.which); // console.log("event: " + event.which);
if (event.which === 9) { if (event.which === 9) {
if (!scope.autoCompleting) { // cache our starting text if (!scope.tabCompleting) { // cache our starting text
// console.log("caching " + element[0].value); // console.log("caching " + element[0].value);
scope.autoCompleteOriginal = element[0].value; scope.tabCompleteOriginal = element[0].value;
scope.autoCompleting = true; scope.tabCompleting = true;
} }
if (event.shiftKey) { if (event.shiftKey) {
scope.autoCompleteIndex--; scope.tabCompleteIndex--;
if (scope.autoCompleteIndex < 0) { if (scope.tabCompleteIndex < 0) {
scope.autoCompleteIndex = 0; scope.tabCompleteIndex = 0;
} }
} }
else { else {
scope.autoCompleteIndex++; scope.tabCompleteIndex++;
} }
var searchIndex = 0; var searchIndex = 0;
var targetIndex = scope.autoCompleteIndex; var targetIndex = scope.tabCompleteIndex;
var text = scope.autoCompleteOriginal; var text = scope.tabCompleteOriginal;
// console.log("targetIndex: " + targetIndex + ", text=" + text); // console.log("targetIndex: " + targetIndex + ", text=" + text);
@ -90,17 +90,17 @@ angular.module('RoomController')
element[0].className = ""; element[0].className = "";
}, 150); }, 150);
element[0].value = text; element[0].value = text;
scope.autoCompleteIndex = 0; scope.tabCompleteIndex = 0;
} }
} }
else { else {
scope.autoCompleteIndex = 0; scope.tabCompleteIndex = 0;
} }
event.preventDefault(); event.preventDefault();
} }
else if (event.which !== 16 && scope.autoCompleting) { else if (event.which !== 16 && scope.tabCompleting) {
scope.autoCompleting = false; scope.tabCompleting = false;
scope.autoCompleteIndex = 0; scope.tabCompleteIndex = 0;
} }
}); });
}; };