Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
0474917c
Commit
0474917c
authored
Jan 25, 2010
by
jeresig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure multiple bound events have their namespaces and data maintained. Fixes #3549.
parent
e01ff6cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
3 deletions
+46
-3
event.js
src/event.js
+12
-3
event.js
test/unit/event.js
+34
-0
No files found.
src/event.js
View file @
0474917c
...
@@ -71,19 +71,28 @@ jQuery.event = {
...
@@ -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 ] = {};
...
...
test/unit/event.js
View file @
0474917c
...
@@ -37,6 +37,40 @@ test("bind(), multiple events at once", function() {
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment