Fix code style and add missing semicolons

This commit is contained in:
dhrubomoy
2017-06-21 15:29:28 -04:00
parent 17a067752f
commit f20c8b7d99
3 changed files with 37 additions and 37 deletions

View File

@ -39,18 +39,24 @@ define(
}, },
autocompleteInputElement = $element[0].getElementsByClassName('autocompleteInput')[0]; autocompleteInputElement = $element[0].getElementsByClassName('autocompleteInput')[0];
if($scope.options[0].name) { if ($scope.options[0].name) {
// If "options" include name, value pair // If "options" include name, value pair
$scope.optionNames = $scope.options.map(function(opt) { $scope.optionNames = $scope.options.map(function (opt) {
return opt.name; return opt.name;
}) });
} else { } else {
// If options is only an array of string. // If options is only an array of string.
$scope.optionNames = $scope.options; $scope.optionNames = $scope.options;
} }
function fillInputWithIndexedOption() {
if ($scope.filteredOptions[$scope.optionIndex]) {
$scope.ngModel[$scope.field] = $scope.filteredOptions[$scope.optionIndex].name;
}
}
function decrementOptionIndex() { function decrementOptionIndex() {
if($scope.optionIndex === 0) { if ($scope.optionIndex === 0) {
$scope.optionIndex = $scope.filteredOptions.length; $scope.optionIndex = $scope.filteredOptions.length;
} }
$scope.optionIndex--; $scope.optionIndex--;
@ -58,7 +64,7 @@ define(
} }
function incrementOptionIndex() { function incrementOptionIndex() {
if($scope.optionIndex === $scope.filteredOptions.length-1) { if ($scope.optionIndex === $scope.filteredOptions.length - 1) {
$scope.optionIndex = -1; $scope.optionIndex = -1;
} }
$scope.optionIndex++; $scope.optionIndex++;
@ -70,22 +76,16 @@ define(
$scope.ngModel[$scope.field] = string; $scope.ngModel[$scope.field] = string;
} }
function fillInputWithIndexedOption() {
if($scope.filteredOptions[$scope.optionIndex]) {
$scope.ngModel[$scope.field] = $scope.filteredOptions[$scope.optionIndex].name;
}
}
function showOptions(string) { function showOptions(string) {
$scope.hideOptions = false; $scope.hideOptions = false;
$scope.filterOptions(string); $scope.filterOptions(string);
$scope.optionIndex = 0; $scope.optionIndex = 0;
} }
$scope.keyDown = function($event) { $scope.keyDown = function ($event) {
if($scope.filteredOptions) { if ($scope.filteredOptions) {
var keyCode = $event.keyCode; var keyCode = $event.keyCode;
switch(keyCode) { switch (keyCode) {
case key.down: case key.down:
incrementOptionIndex(); incrementOptionIndex();
break; break;
@ -94,42 +94,42 @@ define(
decrementOptionIndex(); decrementOptionIndex();
break; break;
case key.enter: case key.enter:
if($scope.filteredOptions[$scope.optionIndex]) { if ($scope.filteredOptions[$scope.optionIndex]) {
fillInputWithString($scope.filteredOptions[$scope.optionIndex].name); fillInputWithString($scope.filteredOptions[$scope.optionIndex].name);
} }
} }
} }
} };
$scope.filterOptions = function(string) { $scope.filterOptions = function (string) {
$scope.hideOptions = false; $scope.hideOptions = false;
$scope.filteredOptions = $scope.optionNames.filter(function(option) { $scope.filteredOptions = $scope.optionNames.filter(function (option) {
return option.toLowerCase().indexOf(string.toLowerCase()) >= 0; return option.toLowerCase().indexOf(string.toLowerCase()) >= 0;
}).map(function(option, index) { }).map(function (option, index) {
return { return {
optionId: index, optionId: index,
name: option name: option
} };
}); });
} };
$scope.inputClicked = function() { $scope.inputClicked = function () {
autocompleteInputElement.select(); autocompleteInputElement.select();
showOptions(autocompleteInputElement.value); showOptions(autocompleteInputElement.value);
} };
$scope.arrowClicked = function() { $scope.arrowClicked = function () {
autocompleteInputElement.select(); autocompleteInputElement.select();
showOptions(''); showOptions('');
} };
$scope.fillInput = function(string) { $scope.fillInput = function (string) {
fillInputWithString(string); fillInputWithString(string);
} };
$scope.optionMouseover = function(optionId) { $scope.optionMouseover = function (optionId) {
$scope.optionIndex = optionId; $scope.optionIndex = optionId;
} };
} }
return AutocompleteController; return AutocompleteController;

View File

@ -41,8 +41,8 @@ define(
it("filters options by returning array containing optionId and name", function () { it("filters options by returning array containing optionId and name", function () {
mockScope.filterOptions('Asia'); mockScope.filterOptions('Asia');
var filteredOptions = [ { optionId : 0, name : 'Asia/Dhaka' }, var filteredOptions = [{ optionId : 0, name : 'Asia/Dhaka' },
{ optionId : 1, name : 'Asia/Shanghai' } ]; { optionId : 1, name : 'Asia/Shanghai' }];
expect(mockScope.filteredOptions).toEqual(filteredOptions); expect(mockScope.filteredOptions).toEqual(filteredOptions);
}); });