mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Event: Move .bind() and .delegate() to deprecated
Cherry-picked from ee0854f85b
Fixes gh-2288
Closes gh-2624
This commit is contained in:
parent
15f79201c4
commit
7e78c2ec81
@ -1,2 +1,24 @@
|
||||
define( function() {
|
||||
|
||||
jQuery.fn.extend( {
|
||||
|
||||
bind: function( types, data, fn ) {
|
||||
return this.on( types, null, data, fn );
|
||||
},
|
||||
unbind: function( types, fn ) {
|
||||
return this.off( types, null, fn );
|
||||
},
|
||||
|
||||
delegate: function( selector, types, data, fn ) {
|
||||
return this.on( types, selector, data, fn );
|
||||
},
|
||||
undelegate: function( selector, types, fn ) {
|
||||
|
||||
// ( namespace ) or ( selector, types [, fn] )
|
||||
return arguments.length === 1 ?
|
||||
this.off( selector, "**" ) :
|
||||
this.off( types, selector || "**", fn );
|
||||
}
|
||||
} );
|
||||
|
||||
} );
|
||||
|
@ -19,24 +19,6 @@ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
|
||||
jQuery.fn.extend( {
|
||||
hover: function( fnOver, fnOut ) {
|
||||
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
|
||||
},
|
||||
|
||||
bind: function( types, data, fn ) {
|
||||
return this.on( types, null, data, fn );
|
||||
},
|
||||
unbind: function( types, fn ) {
|
||||
return this.off( types, null, fn );
|
||||
},
|
||||
|
||||
delegate: function( selector, types, data, fn ) {
|
||||
return this.on( types, selector, data, fn );
|
||||
},
|
||||
undelegate: function( selector, types, fn ) {
|
||||
|
||||
// ( namespace ) or ( selector, types [, fn] )
|
||||
return arguments.length === 1 ?
|
||||
this.off( selector, "**" ) :
|
||||
this.off( types, selector || "**", fn );
|
||||
}
|
||||
} );
|
||||
|
||||
|
@ -286,6 +286,7 @@ this.loadTests = function() {
|
||||
"unit/core.js",
|
||||
"unit/callbacks.js",
|
||||
"unit/deferred.js",
|
||||
"unit/deprecated.js",
|
||||
"unit/support.js",
|
||||
"unit/data.js",
|
||||
"unit/queue.js",
|
||||
|
@ -1,2 +1,42 @@
|
||||
QUnit.module( "deprecated", { teardown: moduleTeardown } );
|
||||
|
||||
|
||||
QUnit.test( "bind/unbind", function( assert ) {
|
||||
assert.expect( 4 );
|
||||
|
||||
var markup = jQuery(
|
||||
"<div><p><span><b>b</b></span></p></div>"
|
||||
);
|
||||
|
||||
markup
|
||||
.find( "b" )
|
||||
.bind( "click", { bindData: 19 }, function( e, trig ) {
|
||||
assert.equal( e.type, "click", "correct event type" );
|
||||
assert.equal( e.data.bindData, 19, "correct trigger data" );
|
||||
assert.equal( trig, 42, "correct bind data" );
|
||||
assert.equal( e.target.nodeName.toLowerCase(), "b" , "correct element" );
|
||||
} )
|
||||
.trigger( "click", [ 42 ] )
|
||||
.unbind( "click" )
|
||||
.trigger( "click" )
|
||||
.remove();
|
||||
} );
|
||||
|
||||
QUnit.test( "delegate/undelegate", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var markup = jQuery(
|
||||
"<div><p><span><b>b</b></span></p></div>"
|
||||
);
|
||||
|
||||
markup
|
||||
.delegate( "b", "click", function( e ) {
|
||||
assert.equal( e.type, "click", "correct event type" );
|
||||
assert.equal( e.target.nodeName.toLowerCase(), "b" , "correct element" );
|
||||
} )
|
||||
.find( "b" )
|
||||
.trigger( "click" )
|
||||
.end()
|
||||
.undelegate( "b", "click" )
|
||||
.remove();
|
||||
} );
|
Loading…
Reference in New Issue
Block a user