Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# angular-carousel.js 1.2.0
# angular-carousel.js 1.2.1

A simple very generic AngularJS carousel. Features:

Expand Down
4 changes: 2 additions & 2 deletions angular-carousel.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license AngularJS v1.2.0
/*!
* @license AngularJS v1.2.1
* (c) 2015 Lifely
* License: MIT
*/
Expand Down
124 changes: 63 additions & 61 deletions angular-carousel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @license AngularJS v1.2.0
* @license AngularJS v1.2.1
* (c) 2015 Lifely
* License: MIT
*/
Expand Down Expand Up @@ -216,82 +216,84 @@ angular.module('angular-carousel', [])
removeOldVirtualSlides();
slides = element.find('slide');

// Add slides before and after the current slides
if(slides.length > 0) {
// Create new carousel and duplicate slides
name = attrs.ngCarouselName;
currentCarousel = Carousel.add(slides.length, attrs.ngCarouselName, scope, {
looping: looping
});
angular.forEach(savedCallbacks, function(savedCallback) {
currentCarousel.onSlideChange(savedCallback);
currentCarousel.unbindOnSlideChangeCallback(0);
});

// Create new carousel and duplicate slides
name = attrs.ngCarouselName;
currentCarousel = Carousel.add(slides.length, attrs.ngCarouselName, scope, {
looping: looping
});
angular.forEach(savedCallbacks, function(savedCallback) {
currentCarousel.onSlideChange(savedCallback);
currentCarousel.unbindOnSlideChangeCallback(0);
});
// Duplicate first and last slide (for infinite effect)
var refreshVirtualSlides = function() {
removeOldVirtualSlides();

// Duplicate first and last slide (for infinite effect)
var refreshVirtualSlides = function() {
removeOldVirtualSlides();
slides = element.find('slide');
if(slides.length < 1){
return;
}

if(looping) {
copyFirstAndLastSlide();
}
else {
makeFirstAndLastSlideEmpty();
}
slides = element.find('slide');

firstSlideCopy.addClass('carousel-slide-copy');
lastSlideCopy.addClass('carousel-slide-copy');
slideContainer.append(firstSlideCopy);
slideContainer.prepend(lastSlideCopy);
slideContainer.addClass('carousel-ignore-first-slide');
if(looping) {
copyFirstAndLastSlide();
}
else {
makeFirstAndLastSlideEmpty();
}

};
firstSlideCopy.addClass('carousel-slide-copy');
lastSlideCopy.addClass('carousel-slide-copy');
slideContainer.append(firstSlideCopy);
slideContainer.prepend(lastSlideCopy);
slideContainer.addClass('carousel-ignore-first-slide');

refreshVirtualSlides();
};

refreshVirtualSlides();

// On slide change, move the slideContainer
var onSlideChangeCallback = function(slideIndex, wrapping) {
var newSlideIndex = slideIndex + 1; // because the first slide doesn't count
// On slide change, move the slideContainer
var onSlideChangeCallback = function(slideIndex, wrapping) {
var newSlideIndex = slideIndex + 1; // because the first slide doesn't count

if(wrapping === 'left') {
newSlideIndex = 0; // first slide
} else if(wrapping === 'right') {
newSlideIndex = slides.length + 1; // last slide
}

move(newSlideIndex, true, function() {
if(wrapping === 'left') {
newSlideIndex = 0; // first slide
move(slides.length, false);
} else if(wrapping === 'right') {
newSlideIndex = slides.length + 1; // last slide
move(1, false);
}
});

setNextSlideTimeout();
refreshVirtualSlides();
};

move(newSlideIndex, true, function() {
if(wrapping === 'left') {
move(slides.length, false);
} else if(wrapping === 'right') {
move(1, false);
}
});

setNextSlideTimeout();
refreshVirtualSlides();
};
if(currentCarousel.onSlideChange){
currentCarousel.onSlideChange(onSlideChangeCallback);
}

// If new slide was out of range, move to the new assigned one
if(savedSlideIndex !== false && currentCarousel.currentSlide !== savedSlideIndex) {
onSlideChangeCallback(currentCarousel.currentSlide, false);
currentCarousel.toIndex(savedSlideIndex);
}
// If new slide was out of range, move to the new assigned one
if(savedSlideIndex !== false && currentCarousel.currentSlide !== savedSlideIndex) {
onSlideChangeCallback(currentCarousel.currentSlide, false);
currentCarousel.toIndex(savedSlideIndex);
}

// Option: random
if(random) {
var randomSlide = Math.floor(Math.random() * currentCarousel.slidesCount);
currentCarousel.toIndex(randomSlide);
}
// Option: random
if(random) {
var randomSlide = Math.floor(Math.random() * currentCarousel.slidesCount);
currentCarousel.toIndex(randomSlide);
}

// Option: interval
if (interval && currentCarousel.slidesCount >= 2) {
setNextSlideTimeout();
}
} else {
console.log('ng-carousel error: No slides found')
// Option: interval
if (interval && currentCarousel.slidesCount >= 2) {
setNextSlideTimeout();
}

// Initialize Hammer
Expand Down
7 changes: 3 additions & 4 deletions angular-carousel.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions angular-carousel.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-carousel",
"description": "Touch-optimized carousel for Angular",
"version": "1.2.0",
"version": "1.2.1",
"keywords": [
"carousel",
"angular",
Expand Down
21 changes: 20 additions & 1 deletion examples/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,31 @@ <h2>Carousel with looping disabled</h2>
</div>
</section>

<section>
<h2>Carousel with adding/removing slides via ng-repeat</h2>

<p>
<button ng-click="addSlide(slideTitle)">Add</button>
<button ng-click="removeSlide(slideTitle)">Remove</button>
<input ng-model="slideTitle"/>
</p>

<div ng-carousel ng-carousel-name="example-carousel5" ng-carousel-watch="dynamicSlides">
<slidecontainer>
<slide ng-repeat="slide in dynamicSlides">{{slide}}</slide>
</slidecontainer>
</div>
</section>


</article>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script>
<script src="http://hammerjs.github.io/dist/hammer.min.js"></script>

<script src="../angular-carousel.js"></script>
<script src="demo.js"></script>
<script src="demo.js"></script>Add Remove
H

</body>
</html>
Loading