Skip to content
This repository
Browse code

correct slider to use _on, and guard the unbinding test

  • Loading branch information...
commit f64ae536a68e85c754a9af91ee0698af122e7807 1 parent a5ad657
John Bender authored August 06, 2012
9  js/widgets/forms/slider.js
@@ -173,7 +173,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
173 173
 			}
174 174
 		}
175 175
 
176  
-		$( document ).bind( "vmousemove", this._preventDocumentDrag );
  176
+		this._on( $( document ), { "vmousemove": this._preventDocumentDrag });
177 177
 
178 178
 		// it appears the clicking the up and down buttons in chrome on
179 179
 		// range/number inputs doesn't trigger a change until the field is
@@ -230,7 +230,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
230 230
 			}
231 231
 		};
232 232
 
233  
-		slider.add( document ).bind( "vmouseup", this._sliderMouseUp );
  233
+		this._on( slider.add( document ), { "vmouseup": this._sliderMouseUp });
234 234
 		slider.insertAfter( control );
235 235
 
236 236
 		// Only add focus class to toggle switch, sliders get it automatically from ui-btn
@@ -323,11 +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( "vmousemove", this._preventDocumentDrag );
328  
-		$( document ).unbind( "vmouseup", this._sliderMouseUp );
329  
-	},
330  
-
331 326
 	refresh: function( val, isfromControl, preventInputUpdate ) {
332 327
 
333 328
 		// NOTE: we don't return here because we want to support programmatic
30  tests/unit/slider/slider_events.js
@@ -397,22 +397,28 @@
397 397
 		], 500);
398 398
 	});
399 399
 
400  
-	test( "slider should detach event", function() {
401  
-		var slider = $( "#remove-events-slider" ),
  400
+	// NOTE this test isn't run because the event data isn't easily accessible
  401
+	// and with the advent of the widget _on method we are actually testing the
  402
+	// widget from UI which has it's own test suite for these sorts of things
  403
+	// ie, don't test your dependencies / framework
  404
+	if( !( $.fn.jquery.match(/^1.8/) )){
  405
+		test( "slider should detach event", function() {
  406
+			var slider = $( "#remove-events-slider" ),
402 407
 			doc = $( document ),
403 408
 			vmouseupLength,
404 409
 			vmousemoveLength;
405 410
 
406  
-		function getDocumentEventsLength( name ){
407  
-			return (doc.data( 'events' )[name] || []).length;
408  
-		}
  411
+			function getDocumentEventsLength( name ){
  412
+				return (doc.data( 'events' )[name] || []).length;
  413
+			}
409 414
 
410  
-		vmouseupLength = getDocumentEventsLength( "vmouseup" );
411  
-		vmousemoveLength = getDocumentEventsLength( "vmousemove" );
  415
+			vmouseupLength = getDocumentEventsLength( "vmouseup" );
  416
+			vmousemoveLength = getDocumentEventsLength( "vmousemove" );
412 417
 
413  
-		slider.remove();
414  
-		
415  
-		equal(getDocumentEventsLength( "vmouseup" ), (vmouseupLength - 1), 'vmouseup event was removed');
416  
-		equal(getDocumentEventsLength( "vmousemove" ), (vmousemoveLength - 1), 'vmousemove event was removed');
417  
-	});
  418
+			slider.remove();
  419
+
  420
+			equal(getDocumentEventsLength( "vmouseup" ), (vmouseupLength - 1), 'vmouseup event was removed');
  421
+			equal(getDocumentEventsLength( "vmousemove" ), (vmousemoveLength - 1), 'vmousemove event was removed');
  422
+		});
  423
+	}
418 424
 })(jQuery);

0 notes on commit f64ae53

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