Skip to content
This repository
Browse code

[slider] Move _preventDocumentDrag function into the widget prototype…

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

Showing 1 changed file with 22 additions and 23 deletions. Show diff stats Hide diff stats

  1. 45  js/widgets/forms/slider.js
45  js/widgets/forms/slider.js
@@ -152,28 +152,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
152 152
 				self.refresh( val(), true );
153 153
 			});
154 154
 
155  
-		this._preventDocumentDrag = function( event ) {
156  
-			// NOTE: we don't do this in refresh because we still want to
157  
-			//       support programmatic alteration of disabled inputs
158  
-			if ( self.dragging && !self.options.disabled ) {
159  
-
160  
-				// self.mouseMoved must be updated before refresh() because it will be used in the control "change" event
161  
-				self.mouseMoved = true;
162  
-
163  
-				if ( cType === "select" ) {
164  
-					// make the handle move in sync with the mouse
165  
-					handle.removeClass( "ui-slider-handle-snapping" );
166  
-				}
167  
-
168  
-				self.refresh( event );
169  
-
170  
-				// only after refresh() you can calculate self.userModified
171  
-				self.userModified = self.beforeStart !== control[0].selectedIndex;
172  
-				return false;
173  
-			}
174  
-		}
175  
-
176  
-		$( document ).bind( "vmousemove", this._preventDocumentDrag );
  155
+		this._on( document, { "vmousemove": "_preventDocumentDrag" } );
177 156
 
178 157
 		// it appears the clicking the up and down buttons in chrome on
179 158
 		// range/number inputs doesn't trigger a change until the field is
@@ -312,6 +291,27 @@ $.widget( "mobile.slider", $.mobile.widget, {
312 291
 		this.refresh( undefined, undefined, true );
313 292
 	},
314 293
 
  294
+	_preventDocumentDrag: function( event ) {
  295
+		// NOTE: we don't do this in refresh because we still want to
  296
+		//       support programmatic alteration of disabled inputs
  297
+		if ( this.dragging && !this.options.disabled ) {
  298
+
  299
+			// self.mouseMoved must be updated before refresh() because it will be used in the control "change" event
  300
+			this.mouseMoved = true;
  301
+
  302
+			if ( this._type === "select" ) {
  303
+				// make the handle move in sync with the mouse
  304
+				this.handle.removeClass( "ui-slider-handle-snapping" );
  305
+			}
  306
+
  307
+			this.refresh( event );
  308
+
  309
+			// only after refresh() you can calculate self.userModified
  310
+			this.userModified = this.beforeStart !== this.element[0].selectedIndex;
  311
+			return false;
  312
+		}
  313
+	},
  314
+
315 315
 	_checkedRefresh: function() {
316 316
 		if( this.value != this._value() ){
317 317
 			this.refresh( this._value() );
@@ -324,7 +324,6 @@ $.widget( "mobile.slider", $.mobile.widget, {
324 324
 	},
325 325
 
326 326
 	_destroy: function() {
327  
-		$( document ).unbind( "vmousemove", this._preventDocumentDrag );
328 327
 		$( document ).unbind( "vmouseup", this._sliderMouseUp );
329 328
 	},
330 329
 

0 notes on commit 8275474

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