Skip to content

Commit 9b56ae5

Browse files
committed
Merge branch 'master' of https://github.com/stoimen/angularjs-slider into stoimen-master
2 parents 1e1f96e + 8f9bf55 commit 9b56ae5

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

rzslider.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ function throttle(func, wait, options) {
194194
{
195195
var self = this;
196196

197+
this.unbinders = [];
198+
197199
if(this.scope.rzSliderTranslate)
198200
{
199201
this.customTrFn = this.scope.rzSliderTranslate();
@@ -218,7 +220,7 @@ function throttle(func, wait, options) {
218220
this.scope.$on('reCalcViewDimensions', angular.bind(this, this.calcViewDimensions));
219221

220222
// Recalculate stuff if view port dimensions have changed
221-
angular.element(window).on('resize', angular.bind(this, this.calcViewDimensions));
223+
angular.element(window).on('resize.rzslider', angular.bind(this, this.calcViewDimensions));
222224

223225
this.initRun = true;
224226

@@ -255,28 +257,41 @@ function throttle(func, wait, options) {
255257

256258
// Watchers
257259

258-
this.scope.$watch('rzSliderModel', function(newValue, oldValue)
260+
this.unbinders.push(this.scope.$watch('rzSliderModel', function(newValue, oldValue)
259261
{
260262
if(newValue === oldValue) return;
261263
thrLow();
262-
});
264+
}));
263265

264-
this.scope.$watch('rzSliderHigh', function(newValue, oldValue)
266+
this.unbinders.push(this.scope.$watch('rzSliderHigh', function(newValue, oldValue)
265267
{
266268
if(newValue === oldValue) return;
267269
thrHigh();
268-
});
270+
}));
269271

270-
this.scope.$watch('rzSliderFloor', function(newValue, oldValue)
272+
this.unbinders.push(this.scope.$watch('rzSliderFloor', function(newValue, oldValue)
271273
{
272274
if(newValue === oldValue) return;
273275
self.resetSlider();
274-
});
276+
}));
275277

276-
this.scope.$watch('rzSliderCeil', function(newValue, oldValue)
278+
this.unbinders.push(this.scope.$watch('rzSliderCeil', function(newValue, oldValue)
277279
{
278280
if(newValue === oldValue) return;
279281
self.resetSlider();
282+
}));
283+
284+
this.sliderElem.on('$destroy', function() {
285+
self.minH.off('.rzslider');
286+
self.maxH.off('.rzslider');
287+
$document.off('.rzslider');
288+
angular.element(window).off('.rzslider');
289+
});
290+
291+
this.scope.$on('$destroy', function() {
292+
self.unbinders.map(function(unbind) {
293+
unbind();
294+
});
280295
});
281296
},
282297

@@ -753,11 +768,11 @@ function throttle(func, wait, options) {
753768
*/
754769
bindEvents: function()
755770
{
756-
this.minH.on('mousedown', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
757-
if(this.range) { this.maxH.on('mousedown', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh')) }
771+
this.minH.on('mousedown.rzslider', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
772+
if(this.range) { this.maxH.on('mousedown.rzslider', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh')) }
758773

759-
this.minH.on('touchstart', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
760-
if(this.range) { this.maxH.on('touchstart', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh')) }
774+
this.minH.on('touchstart.rzslider', angular.bind(this, this.onStart, this.minH, 'rzSliderModel'));
775+
if(this.range) { this.maxH.on('touchstart.rzslider', angular.bind(this, this.onStart, this.maxH, 'rzSliderHigh')) }
761776
},
762777

763778
/**

0 commit comments

Comments
 (0)