shouldCreate = true;
elem = $( "<div>" )
- .bind( "testwidgetcreate", function() {
+ .on( "testwidgetcreate", function() {
ok( shouldCreate, "create event triggered on instantiation" );
})
.testWidget();
_create: function() {
var uuid = this.uuid;
this.element = {
- bind: function( event, handler ) {
+ on: function( event, handler ) {
equal( event, "click.testWidget" + uuid );
ok( $.isFunction(handler) );
},
};
this.widget = function() {
return {
- delegate: function( selector, event, handler ) {
+ on: function( event, selector, handler ) {
equal( selector, "a" );
equal( event, "click.testWidget" + uuid );
ok( $.isFunction(handler) );
});
this.widget = function() {
return {
- delegate: function( selector, event, handler ) {
+ on: function( event, selector, handler ) {
equal( selector, "form fieldset > input" );
equal( event, "change.testWidget" + uuid );
ok( $.isFunction(handler) );
widget._on( element, { foo: function() {
ok( shouldTriggerWidget, "foo called from _on" );
}});
- element.bind( "foo", function() {
+ element.on( "foo", function() {
ok( shouldTriggerOther, "foo called from bind" );
});
shouldTriggerWidget = true;
ok( shouldTriggerWidget, "bar called from _on" );
}
});
- element.bind( "foo bar", function( event ) {
+ element.on( "foo bar", function( event ) {
ok( shouldTriggerOther, event.type + " called from bind" );
});
shouldTriggerWidget = true;
ok( shouldTriggerWidget, "bar called from _on" );
}
});
- element.bind( "foo bar", function( event ) {
+ element.on( "foo bar", function( event ) {
ok( shouldTriggerOther, event.type + " called from bind" );
});
shouldTriggerWidget = true;
}
});
$( document ).add( "#widget-wrapper" ).add( "#widget" )
- .bind( "testwidgetfoo", function( event, ui ) {
+ .on( "testwidgetfoo", function( event, ui ) {
deepEqual( ui, {}, "empty ui hash passed" );
handlers.push( this );
});
"callback"
], "event bubbles and then invokes callback" );
- $( document ).unbind( "testwidgetfoo" );
+ $( document ).off( "testwidgetfoo" );
});
test( "._trigger() - cancelled event", function() {
ok( true, "callback invoked even if event is cancelled" );
}
})
- .bind( "testwidgetfoo", function() {
+ .on( "testwidgetfoo", function() {
ok( true, "event was triggered" );
return false;
});
}, "ui object modified" );
}
});
- $( "#widget" ).bind( "testwidgetfoo", function( event, ui ) {
+ $( "#widget" ).on( "testwidgetfoo", function( event, ui ) {
equal( event.originalEvent, originalEvent, "original event object passed" );
deepEqual( ui, {
foo: "bar",
}, "ui hash passed" );
ui.foo = "notbar";
});
- $( "#widget-wrapper" ).bind( "testwidgetfoo", function( event, ui ) {
+ $( "#widget-wrapper" ).on( "testwidgetfoo", function( event, ui ) {
equal( event.originalEvent, originalEvent, "original event object passed" );
deepEqual( ui, {
foo: "notbar",
this._trigger( "foo", null, [ ui, extra ] );
}
});
- $( "#widget" ).bind( "testwidgetfoo", function( event, ui, extra ) {
+ $( "#widget" ).on( "testwidgetfoo", function( event, ui, extra ) {
deepEqual( ui, {
foo: "bar",
baz: {
deepEqual( ui, { foo: "bar" }, "ui object passed to callback" );
}
});
- $( instance ).bind( "testwidgetfoo", function( event, ui ) {
+ $( instance ).on( "testwidgetfoo", function( event, ui ) {
equal( event.type, "testwidgetfoo", "event object passed to event handler" );
deepEqual( ui, { foo: "bar" }, "ui object passed to event handler" );
});
// we can probably remove the unbind calls in 2.0
// all event bindings should go through this._on()
this.element
- .unbind( this.eventNamespace )
+ .off( this.eventNamespace )
.removeData( this.widgetFullName );
this.widget()
- .unbind( this.eventNamespace )
+ .off( this.eventNamespace )
.removeAttr( "aria-disabled" );
// clean up events and states
- this.bindings.unbind( this.eventNamespace );
+ this.bindings.off( this.eventNamespace );
},
_destroy: $.noop,
eventName = match[ 1 ] + instance.eventNamespace,
selector = match[ 2 ];
if ( selector ) {
- delegateElement.delegate( selector, eventName, handlerProxy );
+ delegateElement.on( eventName, selector, handlerProxy );
} else {
- element.bind( eventName, handlerProxy );
+ element.on( eventName, handlerProxy );
}
} );
},
_off: function( element, eventName ) {
eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
this.eventNamespace;
- element.unbind( eventName ).undelegate( eventName );
+ element.off( eventName ).off( eventName );
// Clear the stack to avoid memory leaks (#10056)
this.bindings = $( this.bindings.not( element ).get() );