diff --git a/js/angular/controller/slideBoxController.js b/js/angular/controller/slideBoxController.js index e491d7200d..d5dad42fb9 100644 --- a/js/angular/controller/slideBoxController.js +++ b/js/angular/controller/slideBoxController.js @@ -36,6 +36,7 @@ function(scope, element, $$ionicAttachDrag, $interval) { self.loop = slideList.loop; self.delta = slideList.delta; + self.update = update; self.enableSlide = enableSlide; self.autoPlay = autoPlay; self.add = add; @@ -73,6 +74,18 @@ function(scope, element, $$ionicAttachDrag, $interval) { return slideList.next(index); } + function update() { + var selectedIndex = scope.selectedIndex; + for (var i = self.count() - 1; i >= 0; i--) { + slideList.remove(i); + } + var slideNodes = element[0].querySelectorAll('ion-slide'); + for (var j = 0, jj = slideNodes.length; j < jj; j++) { + slideList.add(jqLite(slideNodes[j]).controller('ionSlide')); + } + self.select(selectedIndex); + } + function enableSlide(isEnabled) { if (arguments.length) { self.dragDisabled = !isEnabled; @@ -95,7 +108,7 @@ function(scope, element, $$ionicAttachDrag, $interval) { */ function add(slide, index) { var newIndex = slideList.add(slide, index); - slide.onAdded(slidesParent); + slide.onAdded(); // If we are waiting for a certain scope.selectedIndex and this is it, // select the slide @@ -126,12 +139,12 @@ function(scope, element, $$ionicAttachDrag, $interval) { if (index === -1) return; // If the slide is current, next, or previous, save so we can re-select after moving. - var isRelevant = self.isRelevant(targetIndex); + var isRelevant = self.selected() === index || self.isRelevant(targetIndex); slideList.remove(index); slideList.add(slide, targetIndex); if (isRelevant) { - enqueueRefresh(); + self.select(targetIndex); } } diff --git a/js/angular/controller/slideController.js b/js/angular/controller/slideController.js index fbf878be82..8754c27d5a 100644 --- a/js/angular/controller/slideController.js +++ b/js/angular/controller/slideController.js @@ -26,9 +26,7 @@ function(scope, element, $q) { // Public Methods // *** - function onAdded(parentElement) { - self.parentElement = parentElement; - + function onAdded() { // Set default state self.setState('detached'); } @@ -85,19 +83,21 @@ function(scope, element, $q) { // *** function attachSlide() { - if (!self.element[0].parentNode) { - self.parentElement.append(self.element); - ionic.Utils.reconnectScope(scope); - } + // if (!self.element[0].parentNode) { + // self.parentElement.append(self.element); + // ionic.Utils.reconnectScope(scope); + // } + ionic.Utils.reconnectScope(scope); } function detachSlide() { // Don't use self.element.remove(), that will destroy the element's data - var parent = self.element[0].parentNode; - if (parent) { - parent.removeChild(self.element[0]); - ionic.Utils.disconnectScope(scope); - } + // var parent = self.element[0].parentNode; + // if (parent) { + // parent.removeChild(self.element[0]); + // ionic.Utils.disconnectScope(scope); + // } + ionic.Utils.disconnectScope(scope); } var transitionDeferred; diff --git a/js/angular/directive/slide.js b/js/angular/directive/slide.js index 10368d7755..6aeecc404e 100644 --- a/js/angular/directive/slide.js +++ b/js/angular/directive/slide.js @@ -38,18 +38,6 @@ IonicModule slideBoxCtrl.remove(slideCtrl); }); - element.one('$animate:after', watchNgRepeatIndexOnInsertElement); - element.on('$animate:after', refreshStateOnInsertElement); - - // If this element is inserted later by an ng-if or ng-repeat, remove it - // from the DOM again if it's irrelevant (not selected or adjacent). - function refreshStateOnInsertElement() { - var slideIndex = slideBoxCtrl.indexOf(slideCtrl); - if (!slideBoxCtrl.isRelevant(slideIndex)) { - slideCtrl.setState('detached'); - } - } - // Move with ng-repeat if this slide is part of ng-repeat. // scope.$index only appears after the first time ng-repaet inserts the element. function watchNgRepeatIndexOnInsertElement() { diff --git a/js/angular/service/slideBoxDelegate.js b/js/angular/service/slideBoxDelegate.js index 4f4db0b9d2..dcba460e30 100644 --- a/js/angular/service/slideBoxDelegate.js +++ b/js/angular/service/slideBoxDelegate.js @@ -88,7 +88,16 @@ IonicModule * @name $ionicSlideBoxDelegate#count * @returns `number` The number of slides there are currently. */ - 'count' + 'count', + /** + * @ngdoc method + * @name $ionicSlideBoxDelegate#update + * @description Causes the slidebox to re-scan all of the child slide + * elements and reorganize itself again. + * You only need to call update if you are moving slides around in the DOM + * (for example, ng-repeat moving an element from the middle to the end). + */ + 'update', /** * @ngdoc method * @name $ionicSlideBoxDelegate#$getByHandle diff --git a/test/html/slideBox.html b/test/html/slideBox.html index ec84422c4a..ac0b92594a 100644 --- a/test/html/slideBox.html +++ b/test/html/slideBox.html @@ -41,7 +41,7 @@ } -
+