Permalink
Browse files

correct slider to use _on, and guard the unbinding test

  • Loading branch information...
johnbender committed Aug 7, 2012
1 parent a5ad657 commit f64ae536a68e85c754a9af91ee0698af122e7807
Showing with 20 additions and 19 deletions.
  1. +2 −7 js/widgets/forms/slider.js
  2. +18 −12 tests/unit/slider/slider_events.js
@@ -173,7 +173,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
}
}
$( document ).bind( "vmousemove", this._preventDocumentDrag );
this._on( $( document ), { "vmousemove": this._preventDocumentDrag });
// it appears the clicking the up and down buttons in chrome on
// range/number inputs doesn't trigger a change until the field is
@@ -230,7 +230,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
}
};
slider.add( document ).bind( "vmouseup", this._sliderMouseUp );
this._on( slider.add( document ), { "vmouseup": this._sliderMouseUp });
slider.insertAfter( control );
// Only add focus class to toggle switch, sliders get it automatically from ui-btn
@@ -323,11 +323,6 @@ $.widget( "mobile.slider", $.mobile.widget, {
parseFloat( this.element.val() ) : this.element[0].selectedIndex;
},
_destroy: function() {
$( document ).unbind( "vmousemove", this._preventDocumentDrag );
$( document ).unbind( "vmouseup", this._sliderMouseUp );
},
refresh: function( val, isfromControl, preventInputUpdate ) {
// NOTE: we don't return here because we want to support programmatic
@@ -397,22 +397,28 @@
], 500);
});
test( "slider should detach event", function() {
var slider = $( "#remove-events-slider" ),
// NOTE this test isn't run because the event data isn't easily accessible
// and with the advent of the widget _on method we are actually testing the
// widget from UI which has it's own test suite for these sorts of things
// ie, don't test your dependencies / framework
if( !( $.fn.jquery.match(/^1.8/) )){
test( "slider should detach event", function() {
var slider = $( "#remove-events-slider" ),
doc = $( document ),
vmouseupLength,
vmousemoveLength;
function getDocumentEventsLength( name ){
return (doc.data( 'events' )[name] || []).length;
}
function getDocumentEventsLength( name ){
return (doc.data( 'events' )[name] || []).length;
}
vmouseupLength = getDocumentEventsLength( "vmouseup" );
vmousemoveLength = getDocumentEventsLength( "vmousemove" );
vmouseupLength = getDocumentEventsLength( "vmouseup" );
vmousemoveLength = getDocumentEventsLength( "vmousemove" );
slider.remove();
equal(getDocumentEventsLength( "vmouseup" ), (vmouseupLength - 1), 'vmouseup event was removed');
equal(getDocumentEventsLength( "vmousemove" ), (vmousemoveLength - 1), 'vmousemove event was removed');
});
slider.remove();
equal(getDocumentEventsLength( "vmouseup" ), (vmouseupLength - 1), 'vmouseup event was removed');
equal(getDocumentEventsLength( "vmousemove" ), (vmousemoveLength - 1), 'vmousemove event was removed');
});
}
})(jQuery);

0 comments on commit f64ae53

Please sign in to comment.