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
1d8bf0a2
Commit
1d8bf0a2
authored
Aug 08, 2012
by
Dave Methvin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #12203. .undelegate() should not remove direcly bound events.
parent
37e8b448
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
5 deletions
+11
-5
event.js
src/event.js
+1
-1
event.js
test/unit/event.js
+10
-4
No files found.
src/event.js
View file @
1d8bf0a2
...
@@ -973,7 +973,7 @@ jQuery.fn.extend({
...
@@ -973,7 +973,7 @@ jQuery.fn.extend({
},
},
undelegate
:
function
(
selector
,
types
,
fn
)
{
undelegate
:
function
(
selector
,
types
,
fn
)
{
// ( namespace ) or ( selector, types [, fn] )
// ( namespace ) or ( selector, types [, fn] )
return
arguments
.
length
==
1
?
this
.
off
(
selector
,
"**"
)
:
this
.
off
(
types
,
selector
,
fn
);
return
arguments
.
length
==
1
?
this
.
off
(
selector
,
"**"
)
:
this
.
off
(
types
,
selector
||
"**"
,
fn
);
},
},
trigger
:
function
(
type
,
data
)
{
trigger
:
function
(
type
,
data
)
{
...
...
test/unit/event.js
View file @
1d8bf0a2
...
@@ -2376,18 +2376,24 @@ test("stopPropagation() stops directly-bound events on delegated target", functi
...
@@ -2376,18 +2376,24 @@ test("stopPropagation() stops directly-bound events on delegated target", functi
});
});
test
(
"undelegate all bound events"
,
function
(){
test
(
"undelegate all bound events"
,
function
(){
expect
(
1
);
expect
(
2
);
var
count
=
0
;
var
count
=
0
,
var
div
=
jQuery
(
"#body"
);
clicks
=
0
,
div
=
jQuery
(
"#body"
);
div
.
delegate
(
"div#nothiddendivchild"
,
"click submit"
,
function
(){
count
++
;
});
div
.
delegate
(
"div#nothiddendivchild"
,
"click submit"
,
function
(){
count
++
;
}
);
div
.
bind
(
"click"
,
function
(){
clicks
++
;
}
);
div
.
undelegate
();
div
.
undelegate
();
jQuery
(
"div#nothiddendivchild"
).
trigger
(
"click"
);
jQuery
(
"div#nothiddendivchild"
).
trigger
(
"click"
);
jQuery
(
"div#nothiddendivchild"
).
trigger
(
"submit"
);
jQuery
(
"div#nothiddendivchild"
).
trigger
(
"submit"
);
equal
(
count
,
0
,
"Make sure no events were triggered."
);
equal
(
count
,
0
,
"Make sure no events were triggered."
);
div
.
trigger
(
"click"
);
equal
(
clicks
,
2
,
"Make sure delegated and directly bound event occurred."
);
div
.
unbind
(
"click"
);
});
});
test
(
"delegate with multiple events"
,
function
(){
test
(
"delegate with multiple events"
,
function
(){
...
...
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