This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree 5 files changed +67
-2
lines changed
5 files changed +67
-2
lines changed Original file line number Diff line number Diff line change @@ -83,12 +83,22 @@ angular.module('ui.bootstrap.carousel', [])
83
83
$scope . next = function ( ) {
84
84
var newIndex = ( self . getCurrentIndex ( ) + 1 ) % slides . length ;
85
85
86
+ if ( newIndex === 0 && $scope . noWrap ( ) ) {
87
+ $scope . pause ( ) ;
88
+ return ;
89
+ }
90
+
86
91
return self . select ( getSlideByIndex ( newIndex ) , 'next' ) ;
87
92
} ;
88
93
89
94
$scope . prev = function ( ) {
90
95
var newIndex = self . getCurrentIndex ( ) - 1 < 0 ? slides . length - 1 : self . getCurrentIndex ( ) - 1 ;
91
96
97
+ if ( $scope . noWrap ( ) && newIndex === slides . length - 1 ) {
98
+ $scope . pause ( ) ;
99
+ return ;
100
+ }
101
+
92
102
return self . select ( getSlideByIndex ( newIndex ) , 'prev' ) ;
93
103
} ;
94
104
@@ -225,7 +235,8 @@ angular.module('ui.bootstrap.carousel', [])
225
235
scope : {
226
236
interval : '=' ,
227
237
noTransition : '=' ,
228
- noPause : '='
238
+ noPause : '=' ,
239
+ noWrap : '&'
229
240
}
230
241
} ;
231
242
} ] )
Original file line number Diff line number Diff line change @@ -3,3 +3,5 @@ Carousel creates a carousel similar to bootstrap's image carousel.
3
3
The carousel also offers support for touchscreen devices in the form of swiping. To enable swiping, load the ` ngTouch ` module as a dependency.
4
4
5
5
Use a ` <carousel> ` element with ` <slide> ` elements inside it. It will automatically cycle through the slides at a given rate, and a current-index variable will be kept in sync with the currently visible slide.
6
+
7
+ Use the no-wrap attribute on a ` <carousel> ` element to control the looping of slides; setting no-wrap to an expression which evaluates to a truthy value will prevent looping
Original file line number Diff line number Diff line change 1
1
< div ng-controller ="CarouselDemoCtrl ">
2
2
< div style ="height: 305px ">
3
- < carousel interval ="myInterval ">
3
+ < carousel interval ="myInterval " no-wrap =" noWrapSlides " >
4
4
< slide ng-repeat ="slide in slides " active ="slide.active ">
5
5
< img ng-src ="{{slide.image}} " style ="margin:auto; ">
6
6
< div class ="carousel-caption ">
@@ -13,6 +13,12 @@ <h4>Slide {{$index}}</h4>
13
13
< div class ="row ">
14
14
< div class ="col-md-6 ">
15
15
< button type ="button " class ="btn btn-info " ng-click ="addSlide() "> Add Slide</ button >
16
+ < div class ="checkbox ">
17
+ < label >
18
+ < input type ="checkbox " ng-model ="noWrapSlides ">
19
+ Disable Slide Looping
20
+ </ label >
21
+ </ div >
16
22
</ div >
17
23
< div class ="col-md-6 ">
18
24
Interval, in milliseconds: < input type ="number " class ="form-control " ng-model ="myInterval ">
Original file line number Diff line number Diff line change 1
1
angular . module ( 'ui.bootstrap.demo' ) . controller ( 'CarouselDemoCtrl' , function ( $scope ) {
2
2
$scope . myInterval = 5000 ;
3
+ $scope . noWrapSlides = false ;
3
4
var slides = $scope . slides = [ ] ;
4
5
$scope . addSlide = function ( ) {
5
6
var newWidth = 600 + slides . length + 1 ;
Original file line number Diff line number Diff line change @@ -73,6 +73,51 @@ describe('carousel', function() {
73
73
expect ( indicators . length ) . toBe ( 3 ) ;
74
74
} ) ;
75
75
76
+ it ( 'should stop cycling slides forward when noWrap is truthy' , function ( ) {
77
+ elm = $compile (
78
+ '<carousel interval="interval" no-wrap="noWrap">' +
79
+ '<slide ng-repeat="slide in slides" active="slide.active">' +
80
+ '{{slide.content}}' +
81
+ '</slide>' +
82
+ '</carousel>'
83
+ ) ( scope ) ;
84
+
85
+ scope . noWrap = true ;
86
+ scope . $apply ( ) ;
87
+
88
+ scope = elm . isolateScope ( ) ;
89
+ spyOn ( scope , 'pause' ) ;
90
+
91
+ for ( var i = 0 ; i < scope . slides . length - 1 ; ++ i ) {
92
+ scope . next ( ) ;
93
+ }
94
+ testSlideActive ( scope . slides . length - 1 ) ;
95
+ scope . next ( ) ;
96
+ testSlideActive ( scope . slides . length - 1 ) ;
97
+ expect ( scope . pause ) . toHaveBeenCalled ( ) ;
98
+ } ) ;
99
+
100
+ it ( 'should stop cycling slides backward when noWrap is truthy' , function ( ) {
101
+ elm = $compile (
102
+ '<carousel interval="interval" no-wrap="noWrap">' +
103
+ '<slide ng-repeat="slide in slides" active="slide.active">' +
104
+ '{{slide.content}}' +
105
+ '</slide>' +
106
+ '</carousel>'
107
+ ) ( scope ) ;
108
+
109
+ scope . noWrap = true ;
110
+ scope . $apply ( ) ;
111
+
112
+ scope = elm . isolateScope ( ) ;
113
+ spyOn ( scope , 'pause' ) ;
114
+
115
+ testSlideActive ( 0 ) ;
116
+ scope . prev ( ) ;
117
+ testSlideActive ( 0 ) ;
118
+ expect ( scope . pause ) . toHaveBeenCalled ( ) ;
119
+ } ) ;
120
+
76
121
it ( 'should hide navigation when only one slide' , function ( ) {
77
122
scope . slides = [ { active :false , content :'one' } ] ;
78
123
scope . $apply ( ) ;
You can’t perform that action at this time.
0 commit comments