Skip to content
Snippets Groups Projects
Commit c7de9da2 authored by Eike Cochu's avatar Eike Cochu
Browse files

added revolve select directive

parent 5728b691
Branches
No related tags found
No related merge requests found
......@@ -218,4 +218,50 @@
};
}]);
app.directive('revolveSelect', function() {
return {
scope: {
ngModel: '=',
values: '='
},
require: 'ngModel',
template: '<a ng-bind="label" ng-click="next()"></a>',
link: function($scope, $elem, $attrs, $ctrl) {
var hasObjects = false;
if($scope.values && $scope.values.length)
hasObjects = angular.isObject($scope.values[0]);
var index = function() {
if(hasObjects) {
for(var i = 0; i < $scope.values.length; i++) {
if($scope.values[i].value === $scope.ngModel)
return i;
}
return -1;
} else {
return $scope.values.indexOf($scope.ngModel);
}
};
var select = function(i) {
if(i < 0 || i >= $scope.values.length) return;
if(hasObjects) {
$scope.ngModel = $scope.values[i].value;
$scope.label = $scope.values[i].label;
} else {
$scope.ngModel = $scope.label = $scope.values[i];
}
};
$scope.next = function() {
select((index() + 1) % $scope.values.length)
};
$scope.$watch('ngModel', function() {
select(index());
});
}
};
});
})();
\ No newline at end of file
......@@ -246,6 +246,11 @@ ul.dashed {
padding-bottom: 10px;
}
revolve-select, [revolve-select] {
.noselect;
cursor: pointer;
}
[sort-by] {
.noselect;
cursor: pointer;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment