Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
feat(carousel): add slide indicators
Browse files Browse the repository at this point in the history
Closes #145
  • Loading branch information
pkozlowski-opensource committed Feb 25, 2013
1 parent 2cae473 commit 3b677ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
return self.select(slides[newIndex], 'prev');
};

$scope.select = function(slide) {
self.select(slide);
};

$scope.isActive = function(slide) {
return self.currentSlide === slide;
};

$scope.slides = function() {
return slides;
};

$scope.$watch('interval', restartTimer);
function restartTimer() {
if (currentTimeout) {
Expand Down
11 changes: 11 additions & 0 deletions src/carousel/test/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ describe('carousel', function() {
expect(navNext.length).toBe(1);
});

it('should display clickable slide indicators', function () {
var indicators = elm.find('ol.carousel-indicators > li');
expect(indicators.length).toBe(3);
});

it('should go to next when clicking next button', function() {
var navNext = elm.find('a.right');
testSlideActive(0);
Expand All @@ -81,6 +86,12 @@ describe('carousel', function() {
testSlideActive(0);
});

it('should select a slide when clicking on slide indicators', function () {
var indicators = elm.find('ol.carousel-indicators > li');
indicators.eq(1).click();
testSlideActive(1);
});

it('shouldnt go forward if interval is NaN or negative', function() {
testSlideActive(0);
scope.$apply('interval = -1');
Expand Down
3 changes: 3 additions & 0 deletions template/carousel/carousel.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel">
<ol class="carousel-indicators">
<li ng-repeat="slide in slides()" ng-class="{active: isActive(slide)}" ng-click="select(slide)"></li>
</ol>
<div class="carousel-inner" ng-transclude></div>
<a ng-click="prev()" class="carousel-control left">&lsaquo;</a>
<a ng-click="next()" class="carousel-control right">&rsaquo;</a>
Expand Down

0 comments on commit 3b677ee

Please sign in to comment.