@@ -194,6 +194,8 @@ function throttle(func, wait, options) {
194
194
{
195
195
var self = this ;
196
196
197
+ this . unbinders = [ ] ;
198
+
197
199
if ( this . scope . rzSliderTranslate )
198
200
{
199
201
this . customTrFn = this . scope . rzSliderTranslate ( ) ;
@@ -218,7 +220,7 @@ function throttle(func, wait, options) {
218
220
this . scope . $on ( 'reCalcViewDimensions' , angular . bind ( this , this . calcViewDimensions ) ) ;
219
221
220
222
// 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 ) ) ;
222
224
223
225
this . initRun = true ;
224
226
@@ -255,28 +257,41 @@ function throttle(func, wait, options) {
255
257
256
258
// Watchers
257
259
258
- this . scope . $watch ( 'rzSliderModel' , function ( newValue , oldValue )
260
+ this . unbinders . push ( this . scope . $watch ( 'rzSliderModel' , function ( newValue , oldValue )
259
261
{
260
262
if ( newValue === oldValue ) return ;
261
263
thrLow ( ) ;
262
- } ) ;
264
+ } ) ) ;
263
265
264
- this . scope . $watch ( 'rzSliderHigh' , function ( newValue , oldValue )
266
+ this . unbinders . push ( this . scope . $watch ( 'rzSliderHigh' , function ( newValue , oldValue )
265
267
{
266
268
if ( newValue === oldValue ) return ;
267
269
thrHigh ( ) ;
268
- } ) ;
270
+ } ) ) ;
269
271
270
- this . scope . $watch ( 'rzSliderFloor' , function ( newValue , oldValue )
272
+ this . unbinders . push ( this . scope . $watch ( 'rzSliderFloor' , function ( newValue , oldValue )
271
273
{
272
274
if ( newValue === oldValue ) return ;
273
275
self . resetSlider ( ) ;
274
- } ) ;
276
+ } ) ) ;
275
277
276
- this . scope . $watch ( 'rzSliderCeil' , function ( newValue , oldValue )
278
+ this . unbinders . push ( this . scope . $watch ( 'rzSliderCeil' , function ( newValue , oldValue )
277
279
{
278
280
if ( newValue === oldValue ) return ;
279
281
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
+ } ) ;
280
295
} ) ;
281
296
} ,
282
297
@@ -753,11 +768,11 @@ function throttle(func, wait, options) {
753
768
*/
754
769
bindEvents : function ( )
755
770
{
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' ) ) }
758
773
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' ) ) }
761
776
} ,
762
777
763
778
/**
0 commit comments