Skip to content

Commit ee0854f

Browse files
dmethvinmarkelog
authored andcommitted
Event: Move .bind() and .delegate() to deprecated
Fixes gh-2288 Closes gh-2624
1 parent 9748e43 commit ee0854f

File tree

4 files changed

+63
-18
lines changed

4 files changed

+63
-18
lines changed

src/deprecated.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
11
define( function() {
2+
3+
jQuery.fn.extend( {
4+
5+
bind: function( types, data, fn ) {
6+
return this.on( types, null, data, fn );
7+
},
8+
unbind: function( types, fn ) {
9+
return this.off( types, null, fn );
10+
},
11+
12+
delegate: function( selector, types, data, fn ) {
13+
return this.on( types, selector, data, fn );
14+
},
15+
undelegate: function( selector, types, fn ) {
16+
17+
// ( namespace ) or ( selector, types [, fn] )
18+
return arguments.length === 1 ?
19+
this.off( selector, "**" ) :
20+
this.off( types, selector || "**", fn );
21+
}
22+
} );
23+
224
} );

src/event/alias.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,6 @@ jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
1919
jQuery.fn.extend( {
2020
hover: function( fnOver, fnOut ) {
2121
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
22-
},
23-
24-
bind: function( types, data, fn ) {
25-
return this.on( types, null, data, fn );
26-
},
27-
unbind: function( types, fn ) {
28-
return this.off( types, null, fn );
29-
},
30-
31-
delegate: function( selector, types, data, fn ) {
32-
return this.on( types, selector, data, fn );
33-
},
34-
undelegate: function( selector, types, fn ) {
35-
36-
// ( namespace ) or ( selector, types [, fn] )
37-
return arguments.length === 1 ?
38-
this.off( selector, "**" ) :
39-
this.off( types, selector || "**", fn );
4022
}
4123
} );
4224

test/data/testinit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ this.loadTests = function() {
286286
"unit/core.js",
287287
"unit/callbacks.js",
288288
"unit/deferred.js",
289+
"unit/deprecated.js",
289290
"unit/support.js",
290291
"unit/data.js",
291292
"unit/queue.js",

test/unit/deprecated.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
11
QUnit.module( "deprecated", { teardown: moduleTeardown } );
22

3+
4+
QUnit.test( "bind/unbind", function( assert ) {
5+
assert.expect( 4 );
6+
7+
var markup = jQuery(
8+
"<div><p><span><b>b</b></span></p></div>"
9+
);
10+
11+
markup
12+
.find( "b" )
13+
.bind( "click", { bindData: 19 }, function( e, trig ) {
14+
assert.equal( e.type, "click", "correct event type" );
15+
assert.equal( e.data.bindData, 19, "correct trigger data" );
16+
assert.equal( trig, 42, "correct bind data" );
17+
assert.equal( e.target.nodeName.toLowerCase(), "b" , "correct element" );
18+
} )
19+
.trigger( "click", [ 42 ] )
20+
.unbind( "click" )
21+
.trigger( "click" )
22+
.remove();
23+
} );
24+
25+
QUnit.test( "delegate/undelegate", function( assert ) {
26+
assert.expect( 2 );
27+
28+
var markup = jQuery(
29+
"<div><p><span><b>b</b></span></p></div>"
30+
);
31+
32+
markup
33+
.delegate( "b", "click", function( e ) {
34+
assert.equal( e.type, "click", "correct event type" );
35+
assert.equal( e.target.nodeName.toLowerCase(), "b" , "correct element" );
36+
} )
37+
.find( "b" )
38+
.trigger( "click" )
39+
.end()
40+
.undelegate( "b", "click" )
41+
.remove();
42+
} );

0 commit comments

Comments
 (0)