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

Force initial carouselIndex #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
20 changes: 16 additions & 4 deletions dist/angular-carousel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Angular Carousel - Mobile friendly touch carousel for AngularJS
* @version v0.3.10 - 2015-02-11
* @version v0.3.10 - 2015-03-11
* @link http://revolunet.github.com/angular-carousel
* @author Julien Bouquillon <[email protected]>
* @license MIT License, http://www.opensource.org/licenses/MIT
Expand Down Expand Up @@ -472,8 +472,12 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
};
}

var shouldInitialySlideTo = null;
if (iAttributes.rnCarouselIndex) {
var updateParentIndex = function(value) {
if (value < 0) {
return;
}
indexModel.assign(scope.$parent, value);
};
var indexModel = $parse(iAttributes.rnCarouselIndex);
Expand All @@ -482,10 +486,12 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
scope.$watch('carouselIndex', function(newValue) {
updateParentIndex(newValue);
});
scope.$parent.$watch(indexModel, function(newValue, oldValue) {

scope.$parent.$watch(function () {
return indexModel(scope.$parent);
}, function(newValue, oldValue) {
shouldInitialySlideTo = newValue;
if (newValue !== undefined && newValue !== null) {
if (currentSlides && newValue >= currentSlides.length) {
if (currentSlides && currentSlides.length > 0 && newValue >= currentSlides.length) {
newValue = currentSlides.length - 1;
updateParentIndex(newValue);
} else if (currentSlides && newValue < 0) {
Expand Down Expand Up @@ -533,6 +539,12 @@ angular.module('angular-carousel').run(['$templateCache', function($templateCach
scope[deepWatch?'$watch':'$watchCollection'](repeatCollection, function(newValue, oldValue) {
//console.log('repeatCollection', currentSlides);
currentSlides = newValue;
// This will force the required initial carouselIndex
// specified with `rn-carousel-index` on carousel initialization.
if (shouldInitialySlideTo) {
scope.carouselIndex = shouldInitialySlideTo;
shouldInitialySlideTo = null;
}
// if deepWatch ON ,manually compare objects to guess the new position
if (deepWatch && angular.isArray(newValue)) {
var activeElement = oldValue[scope.carouselIndex];
Expand Down
Loading