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

Commit 85140f8

Browse files
mvheckeajoslin
authored andcommittedJan 29, 2014
feat(carousel): Support swipe for touchscreen devices
use ng-swipe-* directives. If ngTouch is included, it will be used. Closes #1686
1 parent 66cb03b commit 85140f8

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed
 

‎misc/demo/assets/app.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module('bootstrapDemoApp', ['ui.bootstrap', 'plunker'], function($httpProvider){
1+
angular.module('bootstrapDemoApp', ['ui.bootstrap', 'plunker', 'ngTouch'], function($httpProvider){
22
FastClick.attach(document.body);
33
delete $httpProvider.defaults.headers.common['X-Requested-With'];
44
});
@@ -19,7 +19,7 @@ function MainCtrl($scope, $http, $document, $modal, orderByFilter) {
1919
}
2020
});
2121
};
22-
22+
2323
$scope.showDownloadModal = function() {
2424
var modalInstance = $modal.open({
2525
templateUrl: 'downloadModal.html',
@@ -62,7 +62,7 @@ var DownloadCtrl = function($scope, $modalInstance) {
6262
minified: true,
6363
tpls: true
6464
};
65-
65+
6666
$scope.download = function (version) {
6767
var options = $scope.options;
6868

@@ -78,8 +78,8 @@ var DownloadCtrl = function($scope, $modalInstance) {
7878

7979
return downloadUrl.join('');
8080
};
81-
81+
8282
$scope.cancel = function () {
8383
$modalInstance.dismiss();
8484
};
85-
}
85+
}

‎misc/demo/index.html

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
<script src="http://cdnjs.cloudflare.com/ajax/libs/fastclick/0.6.7/fastclick.min.js"></script>
1212
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/<%= ngversion %>/angular.min.js"></script>
13+
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/<%= ngversion %>/angular-touch.min.js"></script>
1314
<script src="ui-bootstrap-tpls-<%= pkg.version%>.min.js"></script>
1415
<script src="assets/plunker.js"></script>
1516
<script src="assets/app.js"></script>
@@ -208,7 +209,7 @@ <h1><%= module.displayName %><small>
208209
<script><%= module.docs.js %></script>
209210
<% }); %>
210211
</div>
211-
</div>
212+
</div>
212213
</div><!-- /.container -->
213214
</div><!-- /.main -->
214215
<footer class="footer">
@@ -278,11 +279,11 @@ <h4 style="text-align: center;">{{buildErrorText}}</h4>
278279
<% if (i % 3 === 0) {%>
279280
<div class="btn-group" style="width: 100%;">
280281
<% } %>
281-
<button type="button" class="btn btn-default"
282+
<button type="button" class="btn btn-default"
282283
style="width: 33%; border-radius: 0;"
283-
ng-class="{'btn-primary': module.<%= module.name %>}"
284-
ng-model="module.<%= module.name %>"
285-
btn-checkbox
284+
ng-class="{'btn-primary': module.<%= module.name %>}"
285+
ng-model="module.<%= module.name %>"
286+
btn-checkbox
286287
ng-change="selectedChanged('<%= module.name %>', module.<%= module.name %>)">
287288
<%= module.displayName %>
288289
</button>

‎src/carousel/docs/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Carousel creates a carousel similar to bootstrap's image carousel.
22

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+
35
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.

‎src/carousel/test/carousel.spec.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
describe('carousel', function() {
2-
beforeEach(module('ui.bootstrap.carousel'));
2+
beforeEach(module('ui.bootstrap.carousel', function($compileProvider, $provide) {
3+
angular.forEach(['ngSwipeLeft', 'ngSwipeRight'], makeMock);
4+
function makeMock(name) {
5+
$provide.value(name + 'Directive', []); //remove existing directive if it exists
6+
$compileProvider.directive(name, function() {
7+
return function(scope, element, attr) {
8+
element.on(name, function() {
9+
scope.$apply(attr[name]);
10+
});
11+
};
12+
});
13+
}
14+
}));
315
beforeEach(module('template/carousel/carousel.html', 'template/carousel/slide.html'));
416

517
var $rootScope, $compile, $controller, $timeout;
@@ -114,6 +126,20 @@ describe('carousel', function() {
114126
testSlideActive(0);
115127
});
116128

129+
describe('swiping', function() {
130+
it('should go next on swipeLeft', function() {
131+
testSlideActive(0);
132+
elm.triggerHandler('ngSwipeLeft');
133+
testSlideActive(1);
134+
});
135+
136+
it('should go prev on swipeRight', function() {
137+
testSlideActive(0);
138+
elm.triggerHandler('ngSwipeRight');
139+
testSlideActive(2);
140+
});
141+
});
142+
117143
it('should select a slide when clicking on slide indicators', function () {
118144
var indicators = elm.find('ol.carousel-indicators > li');
119145
indicators.eq(1).click();

‎template/carousel/carousel.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel">
1+
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel" ng-swipe-right="prev()" ng-swipe-left="next()">
22
<ol class="carousel-indicators" ng-show="slides().length > 1">
33
<li ng-repeat="slide in slides()" ng-class="{active: isActive(slide)}" ng-click="select(slide)"></li>
44
</ol>

0 commit comments

Comments
 (0)