Event: Move .bind() and .delegate() to deprecated

Fixes gh-2288
Closes gh-2624
This commit is contained in:
Dave Methvin 2015-10-01 16:03:10 -04:00 committed by Oleg Gaidarenko
parent 9748e436ad
commit ee0854f85b
4 changed files with 63 additions and 18 deletions

View File

@ -1,2 +1,24 @@
define( function() { 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 );
}
} );
} ); } );

View File

@ -19,24 +19,6 @@ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
jQuery.fn.extend( { jQuery.fn.extend( {
hover: function( fnOver, fnOut ) { hover: function( fnOver, fnOut ) {
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); 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 );
} }
} ); } );

View File

@ -286,6 +286,7 @@ this.loadTests = function() {
"unit/core.js", "unit/core.js",
"unit/callbacks.js", "unit/callbacks.js",
"unit/deferred.js", "unit/deferred.js",
"unit/deprecated.js",
"unit/support.js", "unit/support.js",
"unit/data.js", "unit/data.js",
"unit/queue.js", "unit/queue.js",

View File

@ -1,2 +1,42 @@
QUnit.module( "deprecated", { teardown: moduleTeardown } ); 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();
} );