Skip to content

Commit 75df701

Browse files
committed
fix(slides): compile cloned nodes. Fixes #4764
1 parent 72f2fb8 commit 75df701

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

Diff for: js/angular/directive/slides.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ function($animate, $timeout) {
5555
this.update = function() {
5656
$timeout(function() {
5757
_this.__slider.update();
58-
_this.__slider.createLoop();
58+
if(_this._options.loop) {
59+
_this.__slider.createLoop();
60+
}
5961

6062
// Don't allow pager to show with > 10 slides
6163
if (_this.__slider.slides.length > 10) {
@@ -81,8 +83,10 @@ function($animate, $timeout) {
8183
preloadImages: false
8284
}, options);
8385

86+
this._options = newOptions;
87+
8488
$timeout(function() {
85-
var slider = new ionic.views.Swiper($element.children()[0], newOptions);
89+
var slider = new ionic.views.Swiper($element.children()[0], newOptions, $scope);
8690

8791
_this.__slider = slider;
8892
$scope.slider = _this.__slider;
@@ -102,15 +106,18 @@ function($animate, $timeout) {
102106
}
103107
};
104108
}])
105-
.directive('ionSlidePage', [function() {
109+
.directive('ionSlidePage', ['$timeout', function($timeout) {
106110
return {
107111
restrict: 'E',
108112
require: '?^ionSlides',
109113
transclude: true,
110114
replace: true,
111115
template: '<div class="swiper-slide" ng-transclude></div>',
112116
link: function($scope, $element, $attr, ionSlidesCtrl) {
113-
ionSlidesCtrl.rapidUpdate();
117+
$timeout(function() {
118+
ionSlidesCtrl.rapidUpdate();
119+
})
120+
114121
}
115122
};
116123
}]);

Diff for: js/views/slidesView.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Swiper
2222
===========================*/
2323
var Swiper = function (container, params) {
24+
2425
if (!(this instanceof Swiper)) return new Swiper(container, params);
2526

2627
var defaults = {
@@ -418,6 +419,9 @@
418419
// Velocity
419420
s.velocity = 0;
420421

422+
// Remove duplicated slides
423+
var $compile = angular.element(s.wrapper).injector().get('$compile');
424+
421425
/*=========================
422426
Locks, unlocks
423427
===========================*/
@@ -2048,7 +2052,7 @@
20482052
===========================*/
20492053
// Create looped slides
20502054
s.createLoop = function () {
2051-
// Remove duplicated slides
2055+
20522056
s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
20532057

20542058
var slides = s.wrapper.children('.' + s.params.slideClass);
@@ -2061,18 +2065,32 @@
20612065
s.loopedSlides = slides.length;
20622066
}
20632067

2064-
var prependSlides = [], appendSlides = [], i;
2068+
var prependSlides = [], appendSlides = [], i, scope, newNode;
20652069
slides.each(function (index, el) {
20662070
var slide = $(this);
20672071
if (index < s.loopedSlides) appendSlides.push(el);
20682072
if (index < slides.length && index >= slides.length - s.loopedSlides) prependSlides.push(el);
20692073
slide.attr('data-swiper-slide-index', index);
20702074
});
20712075
for (i = 0; i < appendSlides.length; i++) {
2072-
s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
2076+
newNode = angular.element(appendSlides[i]).clone().addClass(s.params.slideDuplicateClass);
2077+
newNode.removeAttr('ng-transclude');
2078+
newNode.removeAttr('ng-repeat');
2079+
scope = angular.element(appendSlides[i]).scope();
2080+
newNode = $compile(newNode)(scope);
2081+
angular.element(s.wrapper).append(newNode);
2082+
//s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
20732083
}
20742084
for (i = prependSlides.length - 1; i >= 0; i--) {
2075-
s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
2085+
//s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
2086+
2087+
newNode = angular.element(prependSlides[i]).clone().addClass(s.params.slideDuplicateClass);
2088+
newNode.removeAttr('ng-transclude');
2089+
newNode.removeAttr('ng-repeat');
2090+
2091+
scope = angular.element(prependSlides[i]).scope();
2092+
newNode = $compile(newNode)(scope);
2093+
angular.element(s.wrapper).prepend(newNode);
20762094
}
20772095
};
20782096
s.destroyLoop = function () {

Diff for: test/html/slides.html

+7-15
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,12 @@ <h2>Journey to HD 219134 b</h2>
2727
<p>
2828
<img src="exoplanet.jpg" style="max-width: 100%" />
2929
</p>
30-
<p>
31-
<img src="exoplanet.jpg" style="max-width: 100%" />
32-
</p>
33-
<p>
34-
<img src="exoplanet.jpg" style="max-width: 100%" />
35-
</p>
36-
<p>
37-
<img src="exoplanet.jpg" style="max-width: 100%" />
38-
</p>
39-
<p>
40-
<img src="exoplanet.jpg" style="max-width: 100%" />
41-
</p>
42-
<p>
43-
<img src="exoplanet.jpg" style="max-width: 100%" />
44-
</p>
4530
<div style="text-align: center">
4631
<small style="font-style: italic">An artist's rendering of your new home.</small>
4732
</div>
33+
<div>
34+
<button class="button button-assertive" ng-click="doClick()">Tap</button>
35+
</div>
4836
</ion-content>
4937
</ion-slide-page>
5038
<ion-slide-page>
@@ -131,6 +119,10 @@ <h2>Life on HD 219134 b</h2>
131119
//$scope.slider.slideNext();
132120
}, 1000)
133121

122+
$scope.doClick = function() {
123+
console.log('CLICK');
124+
}
125+
134126
/*
135127
$scope.extraSlides = [];
136128
var i = 0;

0 commit comments

Comments
 (0)