Skip to content

Commit 639d6df

Browse files
author
Dan Bucholtz
committed
backing up
1 parent 9ef2623 commit 639d6df

File tree

5 files changed

+419
-17
lines changed

5 files changed

+419
-17
lines changed

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

+79-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ function($animate, $timeout, $compile) {
6161
'</div>',
6262
controller: ['$scope', '$element', function($scope, $element) {
6363
var _this = this;
64+
var _watchHandler = null;
65+
var _enterHandler = null;
66+
var _afterLeaveHandler = null;
67+
var _modalRemovedHandler = null;
68+
var _modalPresentedHandler = null;
6469

6570
this.update = function() {
6671
$timeout(function() {
@@ -91,6 +96,52 @@ function($animate, $timeout, $compile) {
9196
_this.update();
9297
}, 50);
9398

99+
this.updateLoop = ionic.debounce(function(){
100+
if ( _this._options.loop ){
101+
_this.__slider.updateLoop();
102+
}
103+
}, 50);
104+
105+
this.watchForChanges = function(){
106+
if ( ! _watchHandler ){
107+
// if we're not already watching, start watching
108+
_watchHandler = $scope.$watch(function(){
109+
console.log("Watch triggered");
110+
_this.updateLoop();
111+
});
112+
}
113+
}
114+
115+
this.stopWatching = function(){
116+
if ( _watchHandler ){
117+
console.log("Stopping watching...");
118+
_watchHandler();
119+
_watchHandler = null;
120+
}
121+
}
122+
123+
this.cleanUpEventHandlers = function(){
124+
if ( _enterHandler ){
125+
_enterHandler();
126+
_enterHandler = null;
127+
}
128+
129+
if ( _afterLeaveHandler ){
130+
_afterLeaveHandler();
131+
_afterLeaveHandler = null;
132+
}
133+
134+
if ( _modalRemovedHandler ){
135+
_modalRemovedHandler();
136+
_modalRemovedHandler = null;
137+
}
138+
139+
if ( _modalPresentedHandler ){
140+
_modalPresentedHandler();
141+
_modalPresentedHandler = null;
142+
}
143+
}
144+
94145
this.getSlider = function() {
95146
return _this.__slider;
96147
};
@@ -113,15 +164,41 @@ function($animate, $timeout, $compile) {
113164
$scope.slider = _this.__slider;
114165

115166
$scope.$on('$destroy', function() {
167+
alert("scope destroy event");
116168
slider.destroy();
117169
_this.__slider = null;
170+
_this.stopWatching();
171+
_this.cleanUpEventHandlers();
172+
118173
});
174+
175+
_this.watchForChanges();
176+
177+
_enterHandler = $scope.$on("$ionicView.enter", function(){
178+
console.log("enter");
179+
_this.watchForChanges();
180+
});
181+
182+
_afterLeaveHandler = $scope.$on("$ionicView.afterLeave", function(){
183+
console.log("after leave");
184+
_this.stopWatching();
185+
});
186+
187+
_modalRemovedHandler = $scope.$on("$ionic.modalRemoved", function(){
188+
console.log("Modal removed");
189+
_this.stopWatching();
190+
});
191+
192+
_modalPresentedHandler = $scope.$on("$ionic.modalPresented", function(){
193+
console.log("Modal presented");
194+
_this.watchForChanges();
195+
});
196+
119197
});
120198

121199
}],
122200

123-
124-
link: function($scope) {
201+
link: function($scope, element, attrs) {
125202
$scope.showPager = true;
126203
// Disable ngAnimate for slidebox and its children
127204
//$animate.enabled(false, $element);

Diff for: js/angular/service/modal.js

+3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ function($rootScope, $ionicBody, $compile, $timeout, $ionicPlatform, $ionicTempl
182182
self.el.classList.add('active');
183183
self.scope.$broadcast('$ionicHeader.align');
184184
self.scope.$broadcast('$ionicFooter.align');
185+
self.scope.$broadcast('$ionic.modalPresented');
185186
}, 20);
186187

187188
return $timeout(function() {
@@ -224,6 +225,8 @@ function($rootScope, $ionicBody, $compile, $timeout, $ionicPlatform, $ionicTempl
224225
if (self._isShown) return;
225226
modalEl.addClass('ng-leave-active')
226227
.removeClass('ng-enter ng-enter-active active');
228+
229+
self.scope.$broadcast('$ionic.modalRemoved');
227230
}, 20, false);
228231

229232
self.$el.off('click');

Diff for: js/views/slidesView.js

+30-7
Original file line numberDiff line numberDiff line change
@@ -2044,14 +2044,35 @@
20442044
}
20452045
s.observers = [];
20462046
};
2047+
2048+
s.updateLoop = function(){
2049+
// this is an Ionic custom function
2050+
var duplicates = s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass);
2051+
var slides = s.wrapper.children('.' + s.params.slideClass);
2052+
for ( var i = 0; i < duplicates.length; i++ ){
2053+
var duplicate = duplicates[i];
2054+
var swiperSlideIndex = angular.element(duplicate).attr("data-swiper-slide-index");
2055+
// loop through each slide
2056+
for ( var j = 0; i < slides.length; j++ ){
2057+
// if it's not a duplicate, and the data swiper slide index matches the duplicate value
2058+
var slide = slides[j]
2059+
if ( !angular.element(slide).hasClass(s.params.slideDuplicateClass) && angular.element(slide).attr("data-swiper-slide-index") === swiperSlideIndex ){
2060+
// sweet, it's a match
2061+
duplicate.innerHTML = slide.innerHTML;
2062+
break;
2063+
}
2064+
}
2065+
}
2066+
}
20472067
/*=========================
20482068
Loop
20492069
===========================*/
20502070
// Create looped slides
20512071
s.createLoop = function () {
2052-
2053-
var toRemove = s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass);
2054-
angular.element(toRemove).remove();
2072+
//console.log("Slider create loop method");
2073+
//var toRemove = s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass);
2074+
//angular.element(toRemove).remove();
2075+
s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
20552076

20562077
var slides = s.wrapper.children('.' + s.params.slideClass);
20572078

@@ -2071,24 +2092,26 @@
20712092
slide.attr('data-swiper-slide-index', index);
20722093
});
20732094
for (i = 0; i < appendSlides.length; i++) {
2074-
newNode = angular.element(appendSlides[i]).clone().addClass(s.params.slideDuplicateClass);
2095+
/*newNode = angular.element(appendSlides[i]).clone().addClass(s.params.slideDuplicateClass);
20752096
newNode.removeAttr('ng-transclude');
20762097
newNode.removeAttr('ng-repeat');
20772098
scope = angular.element(appendSlides[i]).scope();
20782099
newNode = $compile(newNode)(scope);
20792100
angular.element(s.wrapper).append(newNode);
2080-
//s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
2101+
*/
2102+
s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
20812103
}
20822104
for (i = prependSlides.length - 1; i >= 0; i--) {
2083-
//s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
2105+
s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
20842106

2085-
newNode = angular.element(prependSlides[i]).clone().addClass(s.params.slideDuplicateClass);
2107+
/*newNode = angular.element(prependSlides[i]).clone().addClass(s.params.slideDuplicateClass);
20862108
newNode.removeAttr('ng-transclude');
20872109
newNode.removeAttr('ng-repeat');
20882110
20892111
scope = angular.element(prependSlides[i]).scope();
20902112
newNode = $compile(newNode)(scope);
20912113
angular.element(s.wrapper).prepend(newNode);
2114+
*/
20922115
}
20932116
};
20942117
s.destroyLoop = function () {

0 commit comments

Comments
 (0)