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

Commit 3b677ee

Browse files
feat(carousel): add slide indicators
Closes #145
1 parent 2cae473 commit 3b677ee

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/carousel/carousel.js

+12
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
8585
return self.select(slides[newIndex], 'prev');
8686
};
8787

88+
$scope.select = function(slide) {
89+
self.select(slide);
90+
};
91+
92+
$scope.isActive = function(slide) {
93+
return self.currentSlide === slide;
94+
};
95+
96+
$scope.slides = function() {
97+
return slides;
98+
};
99+
88100
$scope.$watch('interval', restartTimer);
89101
function restartTimer() {
90102
if (currentTimeout) {

src/carousel/test/carousel.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ describe('carousel', function() {
5959
expect(navNext.length).toBe(1);
6060
});
6161

62+
it('should display clickable slide indicators', function () {
63+
var indicators = elm.find('ol.carousel-indicators > li');
64+
expect(indicators.length).toBe(3);
65+
});
66+
6267
it('should go to next when clicking next button', function() {
6368
var navNext = elm.find('a.right');
6469
testSlideActive(0);
@@ -81,6 +86,12 @@ describe('carousel', function() {
8186
testSlideActive(0);
8287
});
8388

89+
it('should select a slide when clicking on slide indicators', function () {
90+
var indicators = elm.find('ol.carousel-indicators > li');
91+
indicators.eq(1).click();
92+
testSlideActive(1);
93+
});
94+
8495
it('shouldnt go forward if interval is NaN or negative', function() {
8596
testSlideActive(0);
8697
scope.$apply('interval = -1');

template/carousel/carousel.html

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel">
2+
<ol class="carousel-indicators">
3+
<li ng-repeat="slide in slides()" ng-class="{active: isActive(slide)}" ng-click="select(slide)"></li>
4+
</ol>
25
<div class="carousel-inner" ng-transclude></div>
36
<a ng-click="prev()" class="carousel-control left">&lsaquo;</a>
47
<a ng-click="next()" class="carousel-control right">&rsaquo;</a>

0 commit comments

Comments
 (0)