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

Commit 9d53957

Browse files
JumpLinkrevolunet
authored andcommitted
feature: add rn-carousel-swipe boolean attribute
- controls the carousel swipe-ability dynamically
1 parent 46b021d commit 9d53957

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

index.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ <h3>Standard carousel with thumbs navigation </h3>
7070

7171
<h3>buffered ngRepeat carousel with custom controls</h3>
7272
<div class="details">Custom controls demo, just update the rn-carousel-index index binding</div>
73-
<ul rn-carousel rn-carousel-buffered rn-carousel-indicator rn-carousel-index="slideIndex" class="my-slider ng-cloak">
73+
<ul rn-carousel rn-carousel-buffered rn-carousel-indicator rn-carousel-index="slideIndex" rn-carousel-swipe="{{swipe}}" class="my-slider ng-cloak">
7474
<li ng-repeat="slide in slides4" ng-style="{'background-image': 'url(' + slide.img + ')'}">
7575
<div class="debug">
7676
{{ slide.label }} / {{ slides4.length }}
@@ -85,6 +85,7 @@ <h3>buffered ngRepeat carousel with custom controls</h3>
8585
<span>{{ slideIndex + 1 }} / {{ slides4.length }}</span>
8686
<button class="button grey" ng-click="next()" ng-disabled="slideIndex==slides4.length-1" >next</button>
8787
<button class="button grey" ng-click="pushSlide()">add 3 slides</button>
88+
<button class="button grey" ng-click="toggleSwipe()">toggle swipe ({{ swipe?'on':'off' }})</button>
8889
</div>
8990

9091
<h3>object-based ngRepeat carousel with indicators</h3>
@@ -112,9 +113,13 @@ <h3>Other demos</h3>
112113
</ul>
113114
<br><br>
114115
</body>
115-
<script src="//code.angularjs.org/1.2.7/angular.min.js"></script>
116-
<script src="//code.angularjs.org/1.2.7/angular-touch.min.js"></script>
116+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
117+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular-touch.min.js"></script>
117118
<script src="./dist/angular-carousel.js"></script>
119+
<!--<script src="./src/angular-carousel.js"></script>
120+
<script src="./src/directives/rn-carousel.js"></script>
121+
<script src="./src/directives/rn-carousel-indicators.js"></script>
122+
<script src="./src/directives/sliceFilter.js"></script>-->
118123
<script>
119124
angular.module('DemoApp', [
120125
'angular-carousel'
@@ -161,6 +166,10 @@ <h3>Other demos</h3>
161166
$scope.next = function() {
162167
$scope.slideIndex++;
163168
}
169+
$scope.swipe = true;
170+
$scope.toggleSwipe = function() {
171+
$scope.swipe = !$scope.swipe;
172+
}
164173

165174
// 4rd demo, object based iterable
166175
$scope.slideIndex3 = 2;

src/directives/rn-carousel.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@
131131
});
132132
} else {
133133
slidesCount = iElement.children().length;
134+
updateIndicatorArray();
134135
updateContainerWidth();
135136
}
136137

137138
function updateIndicatorArray() {
138-
// generate an arrat to be used by the indicators
139+
// generate an array to be used by the indicators
139140
var items = [];
140141
for (var i = 0; i < slidesCount; i++) items[i] = i;
141142
scope.carouselIndicatorArray = items;
@@ -327,12 +328,20 @@
327328
return false;
328329
}
329330

330-
$swipe.bind(carousel, {
331-
start: swipeStart,
332-
move: swipeMove,
333-
end: swipeEnd,
334-
cancel: function(event) {
335-
swipeEnd({}, event);
331+
iAttributes.$observe('rnCarouselSwipe', function(newValue, oldValue) {
332+
// only bind swipe when it's not switched off
333+
if(newValue !== 'false' && newValue !== 'off') {
334+
$swipe.bind(carousel, {
335+
start: swipeStart,
336+
move: swipeMove,
337+
end: swipeEnd,
338+
cancel: function(event) {
339+
swipeEnd({}, event);
340+
}
341+
});
342+
} else {
343+
// unbind swipe when it's switched off
344+
carousel.unbind();
336345
}
337346
});
338347

0 commit comments

Comments
 (0)