diff --git a/js/angular/directive/slides.js b/js/angular/directive/slides.js index 9d35c3726e3..63bce13ea23 100644 --- a/js/angular/directive/slides.js +++ b/js/angular/directive/slides.js @@ -55,7 +55,9 @@ function($animate, $timeout) { this.update = function() { $timeout(function() { _this.__slider.update(); - _this.__slider.createLoop(); + if(_this._options.loop) { + _this.__slider.createLoop(); + } // Don't allow pager to show with > 10 slides if (_this.__slider.slides.length > 10) { @@ -81,8 +83,10 @@ function($animate, $timeout) { preloadImages: false }, options); + this._options = newOptions; + $timeout(function() { - var slider = new ionic.views.Swiper($element.children()[0], newOptions); + var slider = new ionic.views.Swiper($element.children()[0], newOptions, $scope); _this.__slider = slider; $scope.slider = _this.__slider; @@ -102,7 +106,7 @@ function($animate, $timeout) { } }; }]) -.directive('ionSlidePage', [function() { +.directive('ionSlidePage', ['$timeout', function($timeout) { return { restrict: 'E', require: '?^ionSlides', @@ -110,7 +114,10 @@ function($animate, $timeout) { replace: true, template: '
', link: function($scope, $element, $attr, ionSlidesCtrl) { - ionSlidesCtrl.rapidUpdate(); + $timeout(function() { + ionSlidesCtrl.rapidUpdate(); + }) + } }; }]); diff --git a/js/views/slidesView.js b/js/views/slidesView.js index c151c015941..1bdd77f71fb 100644 --- a/js/views/slidesView.js +++ b/js/views/slidesView.js @@ -21,6 +21,7 @@ Swiper ===========================*/ var Swiper = function (container, params) { + if (!(this instanceof Swiper)) return new Swiper(container, params); var defaults = { @@ -418,6 +419,9 @@ // Velocity s.velocity = 0; + // Remove duplicated slides + var $compile = angular.element(s.wrapper).injector().get('$compile'); + /*========================= Locks, unlocks ===========================*/ @@ -2048,7 +2052,7 @@ ===========================*/ // Create looped slides s.createLoop = function () { - // Remove duplicated slides + s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove(); var slides = s.wrapper.children('.' + s.params.slideClass); @@ -2061,7 +2065,7 @@ s.loopedSlides = slides.length; } - var prependSlides = [], appendSlides = [], i; + var prependSlides = [], appendSlides = [], i, scope, newNode; slides.each(function (index, el) { var slide = $(this); if (index < s.loopedSlides) appendSlides.push(el); @@ -2069,10 +2073,24 @@ slide.attr('data-swiper-slide-index', index); }); for (i = 0; i < appendSlides.length; i++) { - s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass)); + newNode = angular.element(appendSlides[i]).clone().addClass(s.params.slideDuplicateClass); + newNode.removeAttr('ng-transclude'); + newNode.removeAttr('ng-repeat'); + scope = angular.element(appendSlides[i]).scope(); + newNode = $compile(newNode)(scope); + angular.element(s.wrapper).append(newNode); + //s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass)); } for (i = prependSlides.length - 1; i >= 0; i--) { - s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass)); + //s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass)); + + newNode = angular.element(prependSlides[i]).clone().addClass(s.params.slideDuplicateClass); + newNode.removeAttr('ng-transclude'); + newNode.removeAttr('ng-repeat'); + + scope = angular.element(prependSlides[i]).scope(); + newNode = $compile(newNode)(scope); + angular.element(s.wrapper).prepend(newNode); } }; s.destroyLoop = function () { diff --git a/test/html/slides.html b/test/html/slides.html index b6cc5b66d33..e6754f0483b 100644 --- a/test/html/slides.html +++ b/test/html/slides.html @@ -27,24 +27,12 @@-
- -
-- -
-- -
-- -
-- -