Skip to content
This repository
Browse code

[slider] Move _sliderMouseUp function into the widget prototype and a…

…ttach it with ._on() to ensure removal upon destroy()
  • Loading branch information...
commit 3593a889333a1a60e0e3ad66d9a5067b1e374682 1 parent 8275474
Gabriel "_|Nix|_" Schulhof authored August 02, 2012

Showing 1 changed file with 30 additions and 34 deletions. Show diff stats Hide diff stats

  1. 64  js/widgets/forms/slider.js
64  js/widgets/forms/slider.js
@@ -180,36 +180,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
180 180
 		})
181 181
 		.bind( "vclick", false );
182 182
 
183  
-		this._sliderMouseUp = function() {
184  
-			if ( self.dragging ) {
185  
-				self.dragging = false;
186  
-
187  
-				if ( cType === "select") {
188  
-					// make the handle move with a smooth transition
189  
-					handle.addClass( "ui-slider-handle-snapping" );
190  
-
191  
-					if ( self.mouseMoved ) {
192  
-						// this is a drag, change the value only if user dragged enough
193  
-						if ( self.userModified ) {
194  
-						    self.refresh( self.beforeStart === 0 ? 1 : 0 );
195  
-						}
196  
-						else {
197  
-						    self.refresh( self.beforeStart );
198  
-						}
199  
-					}
200  
-					else {
201  
-						// this is just a click, change the value
202  
-						self.refresh( self.beforeStart === 0 ? 1 : 0 );
203  
-					}
204  
-				}
205  
-
206  
-				self.mouseMoved = false;
207  
-				self._trigger( "stop" );
208  
-				return false;
209  
-			}
210  
-		};
211  
-
212  
-		slider.add( document ).bind( "vmouseup", this._sliderMouseUp );
  183
+		this._on( slider.add( document ), { "vmouseup": "_sliderMouseUp" } );
213 184
 		slider.insertAfter( control );
214 185
 
215 186
 		// Only add focus class to toggle switch, sliders get it automatically from ui-btn
@@ -291,6 +262,35 @@ $.widget( "mobile.slider", $.mobile.widget, {
291 262
 		this.refresh( undefined, undefined, true );
292 263
 	},
293 264
 
  265
+	_sliderMouseUp: function() {
  266
+		if ( this.dragging ) {
  267
+			this.dragging = false;
  268
+
  269
+			if ( this._type === "select") {
  270
+				// make the handle move with a smooth transition
  271
+				this.handle.addClass( "ui-slider-handle-snapping" );
  272
+
  273
+				if ( this.mouseMoved ) {
  274
+					// this is a drag, change the value only if user dragged enough
  275
+					if ( this.userModified ) {
  276
+						  this.refresh( this.beforeStart === 0 ? 1 : 0 );
  277
+					}
  278
+					else {
  279
+						  this.refresh( this.beforeStart );
  280
+					}
  281
+				}
  282
+				else {
  283
+					// this is just a click, change the value
  284
+					this.refresh( this.beforeStart === 0 ? 1 : 0 );
  285
+				}
  286
+			}
  287
+
  288
+			this.mouseMoved = false;
  289
+			this._trigger( "stop" );
  290
+			return false;
  291
+		}
  292
+	},
  293
+
294 294
 	_preventDocumentDrag: function( event ) {
295 295
 		// NOTE: we don't do this in refresh because we still want to
296 296
 		//       support programmatic alteration of disabled inputs
@@ -323,10 +323,6 @@ $.widget( "mobile.slider", $.mobile.widget, {
323 323
 			parseFloat( this.element.val() ) : this.element[0].selectedIndex;
324 324
 	},
325 325
 
326  
-	_destroy: function() {
327  
-		$( document ).unbind( "vmouseup", this._sliderMouseUp );
328  
-	},
329  
-
330 326
 	refresh: function( val, isfromControl, preventInputUpdate ) {
331 327
 
332 328
 		// NOTE: we don't return here because we want to support programmatic

0 notes on commit 3593a88

Please sign in to comment.
Something went wrong with that request. Please try again.