little refactoring

This commit is contained in:
Athou
2013-05-29 10:48:47 +02:00
parent e6cf48d4f6
commit 2c6c432e7f

View File

@@ -725,20 +725,21 @@ function($scope, $stateParams, $http, $route, $window, EntryService, SettingsSer
} }
}; };
var _currentIndex = function() { var getCurrentIndex = function() {
if (!$scope.current) { var index = -1;
return -1; if ($scope.current) {
}
for (var i = 0; i < $scope.entries.length; i++) { for (var i = 0; i < $scope.entries.length; i++) {
if ($scope.current == $scope.entries[i]) { if ($scope.current == $scope.entries[i]) {
return i; index = i;
break;
} }
} }
return -1; }
return index;
}; };
var _getNextEntry = function() { var getNextEntry = function() {
var index = _currentIndex(); var index = getCurrentIndex();
if (index >= 0) { if (index >= 0) {
index = index + 1; index = index + 1;
if (index < $scope.entries.length) { if (index < $scope.entries.length) {
@@ -750,8 +751,8 @@ function($scope, $stateParams, $http, $route, $window, EntryService, SettingsSer
return null; return null;
}; };
var _getPreviousEntry = function() { var getPreviousEntry = function() {
var index = _currentIndex(); var index = getCurrentIndex();
if (index >= 1) { if (index >= 1) {
return $scope.entries[index - 1]; return $scope.entries[index - 1];
} }
@@ -759,21 +760,21 @@ function($scope, $stateParams, $http, $route, $window, EntryService, SettingsSer
}; };
var openNextEntry = function(event) { var openNextEntry = function(event) {
var entry = _getNextEntry(); var entry = getNextEntry();
if (entry) { if (entry) {
$scope.entryClicked(entry, event); $scope.entryClicked(entry, event);
} }
}; };
var openPreviousEntry = function(event) { var openPreviousEntry = function(event) {
var entry = _getPreviousEntry(); var entry = getPreviousEntry();
if (entry) { if (entry) {
$scope.entryClicked(entry, event); $scope.entryClicked(entry, event);
} }
}; };
var focusNextEntry = function(event) { var focusNextEntry = function(event) {
var entry = _getNextEntry(); var entry = getNextEntry();
if (entry) { if (entry) {
$scope.navigationMode = 'click'; $scope.navigationMode = 'click';
$scope.current = entry; $scope.current = entry;
@@ -781,7 +782,7 @@ function($scope, $stateParams, $http, $route, $window, EntryService, SettingsSer
}; };
var focusPreviousEntry = function(event) { var focusPreviousEntry = function(event) {
var entry = _getPreviousEntry(); var entry = getPreviousEntry();
if (entry) { if (entry) {
$scope.navigationMode = 'click'; $scope.navigationMode = 'click';
$scope.current = entry; $scope.current = entry;