Make sure multiple bound events have their namespaces and data maintained. Fixes #3549.
This commit is contained in:
parent
e01ff6cda1
commit
0474917c9d
2 changed files with 46 additions and 3 deletions
15
src/event.js
15
src/event.js
|
@ -71,19 +71,28 @@ jQuery.event = {
|
||||||
// Handle multiple events separated by a space
|
// Handle multiple events separated by a space
|
||||||
// jQuery(...).bind("mouseover mouseout", fn);
|
// jQuery(...).bind("mouseover mouseout", fn);
|
||||||
types = types.split( /\s+/ );
|
types = types.split( /\s+/ );
|
||||||
var type, i=0;
|
|
||||||
|
var type, i = 0;
|
||||||
|
|
||||||
while ( (type = types[ i++ ]) ) {
|
while ( (type = types[ i++ ]) ) {
|
||||||
// Namespaced event handlers
|
// Namespaced event handlers
|
||||||
var namespaces = type.split(".");
|
var namespaces = type.split(".");
|
||||||
type = namespaces.shift();
|
type = namespaces.shift();
|
||||||
|
|
||||||
|
if ( i > 1 ) {
|
||||||
|
handler = jQuery.proxy( handler );
|
||||||
|
|
||||||
|
if ( data !== undefined ) {
|
||||||
|
handler.data = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handler.type = namespaces.slice(0).sort().join(".");
|
handler.type = namespaces.slice(0).sort().join(".");
|
||||||
|
|
||||||
// Get the current list of functions bound to this event
|
// Get the current list of functions bound to this event
|
||||||
var handlers = events[ type ],
|
var handlers = events[ type ],
|
||||||
special = this.special[ type ] || {};
|
special = this.special[ type ] || {};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Init the event handler queue
|
// Init the event handler queue
|
||||||
if ( !handlers ) {
|
if ( !handlers ) {
|
||||||
handlers = events[ type ] = {};
|
handlers = events[ type ] = {};
|
||||||
|
|
|
@ -37,6 +37,40 @@ test("bind(), multiple events at once", function() {
|
||||||
equals( mouseoverCounter, 1, "bind() with multiple events at once" );
|
equals( mouseoverCounter, 1, "bind() with multiple events at once" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("bind(), multiple events at once and namespaces", function() {
|
||||||
|
expect(7);
|
||||||
|
|
||||||
|
var cur, obj = {};
|
||||||
|
|
||||||
|
var div = jQuery("<div/>").bind("focusin.a", function(e) {
|
||||||
|
equals( e.type, cur, "Verify right single event was fired." );
|
||||||
|
});
|
||||||
|
|
||||||
|
cur = "focusin";
|
||||||
|
div.trigger("focusin.a");
|
||||||
|
|
||||||
|
div = jQuery("<div/>").bind("click mouseover", obj, function(e) {
|
||||||
|
equals( e.type, cur, "Verify right multi event was fired." );
|
||||||
|
equals( e.data, obj, "Make sure the data came in correctly." );
|
||||||
|
});
|
||||||
|
|
||||||
|
cur = "click";
|
||||||
|
div.trigger("click");
|
||||||
|
|
||||||
|
cur = "mouseover";
|
||||||
|
div.trigger("mouseover");
|
||||||
|
|
||||||
|
div = jQuery("<div/>").bind("focusin.a focusout.b", function(e) {
|
||||||
|
equals( e.type, cur, "Verify right multi event was fired." );
|
||||||
|
});
|
||||||
|
|
||||||
|
cur = "focusin";
|
||||||
|
div.trigger("focusin.a");
|
||||||
|
|
||||||
|
cur = "focusout";
|
||||||
|
div.trigger("focusout.b");
|
||||||
|
});
|
||||||
|
|
||||||
test("bind(), no data", function() {
|
test("bind(), no data", function() {
|
||||||
expect(1);
|
expect(1);
|
||||||
var handler = function(event) {
|
var handler = function(event) {
|
||||||
|
|
Loading…
Reference in a new issue