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

Commit ecbbb78

Browse files
committed
chore: update build
1 parent 1d08d7d commit ecbbb78

File tree

4 files changed

+68
-70
lines changed

4 files changed

+68
-70
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-carousel",
33
"description": "Angular Carousel - Mobile friendly touch carousel for AngularJS",
4-
"version": "0.3.7",
4+
"version": "0.3.8",
55
"homepage": "http://revolunet.github.com/angular-carousel",
66
"author": "Julien Bouquillon <[email protected]>",
77
"repository": {

dist/angular-carousel.js

Lines changed: 64 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Angular Carousel - Mobile friendly touch carousel for AngularJS
3-
* @version v0.3.7 - 2014-11-11
3+
* @version v0.3.8 - 2015-01-26
44
* @link http://revolunet.github.com/angular-carousel
55
* @author Julien Bouquillon <[email protected]>
66
* @license MIT License, http://www.opensource.org/licenses/MIT
@@ -20,57 +20,36 @@ angular.module('angular-carousel', [
2020

2121
angular.module('angular-carousel')
2222

23-
.directive('rnCarouselAutoSlide', ['$timeout', function($timeout) {
23+
.directive('rnCarouselAutoSlide', ['$interval', function($interval) {
2424
return {
2525
restrict: 'A',
2626
link: function (scope, element, attrs) {
27-
var delay = Math.round(parseFloat(attrs.rnCarouselAutoSlide) * 1000),
28-
timer = increment = false, slidesCount = element.children().length;
29-
30-
if(!scope.carouselExposedIndex){
31-
scope.carouselExposedIndex = 0;
32-
}
33-
stopAutoplay = function () {
34-
if (angular.isDefined(timer)) {
35-
$timeout.cancel(timer);
27+
var stopAutoPlay = function() {
28+
if (scope.autoSlider) {
29+
$interval.cancel(scope.autoSlider);
30+
scope.autoSlider = null;
3631
}
37-
timer = undefined;
3832
};
39-
40-
increment = function () {
41-
if (scope.carouselExposedIndex < slidesCount - 1) {
42-
scope.carouselExposedIndex = scope.carouselExposedIndex + 1;
43-
} else {
44-
scope.carouselExposedIndex = 0;
45-
}
33+
var restartTimer = function() {
34+
scope.autoSlide();
4635
};
4736

48-
restartTimer = function (){
49-
stopAutoplay();
50-
timer = $timeout(increment, delay);
51-
};
52-
53-
scope.$watch('carouselIndex', function(){
54-
restartTimer();
55-
});
56-
57-
restartTimer();
58-
if (attrs.rnCarouselPauseOnHover && attrs.rnCarouselPauseOnHover != 'false'){
59-
element.on('mouseenter', stopAutoplay);
37+
scope.$watch('carouselIndex', restartTimer);
6038

39+
if (attrs.hasOwnProperty('rnCarouselPauseOnHover') && attrs.rnCarouselPauseOnHover !== 'false'){
40+
element.on('mouseenter', stopAutoPlay);
6141
element.on('mouseleave', restartTimer);
6242
}
6343

6444
scope.$on('$destroy', function(){
65-
stopAutoplay();
66-
element.off('mouseenter', stopAutoplay);
45+
stopAutoPlay();
46+
element.off('mouseenter', stopAutoPlay);
6747
element.off('mouseleave', restartTimer);
6848
});
69-
70-
7149
}
7250
};
7351
}]);
52+
7453
angular.module('angular-carousel')
7554

7655
.directive('rnCarouselIndicators', ['$parse', function($parse) {
@@ -306,23 +285,15 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
306285
destination,
307286
swipeMoved = false,
308287
//animOnIndexChange = true,
309-
currentSlides,
288+
currentSlides = [],
310289
elWidth = null,
311290
elX = null,
312291
animateTransitions = true,
313292
intialState = true,
314293
animating = false,
294+
mouseUpBound = false,
315295
locked = false;
316296

317-
if(iAttributes.rnCarouselControls!==undefined) {
318-
// dont use a directive for this
319-
var tpl = '<div class="rn-carousel-controls">\n' +
320-
' <span class="rn-carousel-control rn-carousel-control-prev" ng-click="prevSlide()" ng-if="carouselIndex > 0"></span>\n' +
321-
' <span class="rn-carousel-control rn-carousel-control-next" ng-click="nextSlide()" ng-if="carouselIndex < ' + repeatCollection + '.length - 1"></span>\n' +
322-
'</div>';
323-
iElement.append($compile(angular.element(tpl))(scope));
324-
}
325-
326297
$swipe.bind(iElement, {
327298
start: swipeStart,
328299
move: swipeMove,
@@ -403,11 +374,13 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
403374
updateSlidesPosition(state.x);
404375
},
405376
finish: function() {
406-
locked = false;
407377
scope.$apply(function() {
408378
scope.carouselIndex = index;
409379
offset = index * -100;
410380
updateBufferIndex();
381+
$timeout(function () {
382+
locked = false;
383+
}, 0, false);
411384
});
412385
}
413386
});
@@ -422,9 +395,25 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
422395
elWidth = getContainerWidth();
423396
}
424397

398+
function bindMouseUpEvent() {
399+
if (!mouseUpBound) {
400+
mouseUpBound = true;
401+
$document.bind('mouseup', documentMouseUpEvent);
402+
}
403+
}
404+
405+
function unbindMouseUpEvent() {
406+
if (mouseUpBound) {
407+
mouseUpBound = false;
408+
$document.unbind('mouseup', documentMouseUpEvent);
409+
}
410+
}
411+
425412
function swipeStart(coords, event) {
426413
// console.log('swipeStart', coords, event);
427-
$document.bind('mouseup', documentMouseUpEvent);
414+
if (locked || currentSlides.length <= 1) {
415+
return;
416+
}
428417
updateContainerWidth();
429418
elX = iElement[0].querySelector('li').getBoundingClientRect().left;
430419
pressed = true;
@@ -434,10 +423,8 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
434423

435424
function swipeMove(coords, event) {
436425
//console.log('swipeMove', coords, event);
437-
if (locked) {
438-
return;
439-
}
440426
var x, delta;
427+
bindMouseUpEvent();
441428
if (pressed) {
442429
x = coords.x;
443430
delta = startX - x;
@@ -461,14 +448,29 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
461448
});
462449
}
463450

464-
var autoSlider;
451+
if (iAttributes.rnCarouselControls!==undefined) {
452+
// dont use a directive for this
453+
var nextSlideIndexCompareValue = isRepeatBased ? repeatCollection.replace('::', '') + '.length - 1' : currentSlides.length - 1;
454+
var tpl = '<div class="rn-carousel-controls">\n' +
455+
' <span class="rn-carousel-control rn-carousel-control-prev" ng-click="prevSlide()" ng-if="carouselIndex > 0"></span>\n' +
456+
' <span class="rn-carousel-control rn-carousel-control-next" ng-click="nextSlide()" ng-if="carouselIndex < ' + nextSlideIndexCompareValue + '"></span>\n' +
457+
'</div>';
458+
iElement.append($compile(angular.element(tpl))(scope));
459+
}
460+
465461
if (iAttributes.rnCarouselAutoSlide!==undefined) {
466462
var duration = parseInt(iAttributes.rnCarouselAutoSlide, 10) || options.autoSlideDuration;
467-
autoSlider = $interval(function() {
468-
if (!locked && !pressed) {
469-
scope.nextSlide();
463+
scope.autoSlide = function() {
464+
if (scope.autoSlider) {
465+
$interval.cancel(scope.autoSlider);
466+
scope.autoSlider = null;
470467
}
471-
}, duration * 1000);
468+
scope.autoSlider = $interval(function() {
469+
if (!locked && !pressed) {
470+
scope.nextSlide();
471+
}
472+
}, duration * 1000);
473+
};
472474
}
473475

474476
if (iAttributes.rnCarouselIndex) {
@@ -479,10 +481,7 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
479481
if (angular.isFunction(indexModel.assign)) {
480482
/* check if this property is assignable then watch it */
481483
scope.$watch('carouselIndex', function(newValue) {
482-
if (!locked) {
483-
updateParentIndex(newValue);
484-
}
485-
484+
updateParentIndex(newValue);
486485
});
487486
scope.$parent.$watch(indexModel, function(newValue, oldValue) {
488487

@@ -534,7 +533,6 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
534533

535534
scope[deepWatch?'$watch':'$watchCollection'](repeatCollection, function(newValue, oldValue) {
536535
//console.log('repeatCollection', currentSlides);
537-
var oldSlides = (currentSlides || newValue).slice();
538536
currentSlides = newValue;
539537
// if deepWatch ON ,manually compare objects to guess the new position
540538
if (deepWatch && angular.isArray(newValue)) {
@@ -553,8 +551,7 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
553551
if (event && !swipeMoved) {
554552
return;
555553
}
556-
557-
$document.unbind('mouseup', documentMouseUpEvent);
554+
unbindMouseUpEvent();
558555
pressed = false;
559556
swipeMoved = false;
560557
destination = startX - coords.x;
@@ -593,7 +590,7 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
593590
}
594591

595592
scope.$on('$destroy', function() {
596-
$document.unbind('mouseup', documentMouseUpEvent);
593+
unbindMouseUpEvent();
597594
});
598595

599596
scope.carouselBufferIndex = 0;
@@ -640,7 +637,7 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
640637
winEl.bind('resize', onOrientationChange);
641638

642639
scope.$on('$destroy', function() {
643-
$document.unbind('mouseup', documentMouseUpEvent);
640+
unbindMouseUpEvent();
644641
winEl.unbind('orientationchange', onOrientationChange);
645642
winEl.unbind('resize', onOrientationChange);
646643
});
@@ -1135,8 +1132,9 @@ angular.module('angular-carousel.shifty', [])
11351132
// CommonJS
11361133
module.exports = Tweenable;
11371134
} else if (typeof define === 'function' && define.amd) {
1138-
// AMD
1139-
define(function () {return Tweenable;});
1135+
// AMD: define it as a named module to avoid the mismatched error(http://requirejs.org/docs/errors.html#mismatch)
1136+
define('shifty', [], function () {return Tweenable;});
1137+
root.Tweenable = Tweenable;
11401138
} else if (typeof root.Tweenable === 'undefined') {
11411139
// Browser: Make `Tweenable` globally accessible.
11421140
root.Tweenable = Tweenable;

0 commit comments

Comments
 (0)