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
b7ec6ddd
Commit
b7ec6ddd
authored
Nov 23, 2012
by
Dave Methvin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #12868. Use native focus/blur to get event order right.
parent
1fb2f92c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
1 deletion
+63
-1
event.js
src/event.js
+19
-1
event.js
test/unit/event.js
+44
-0
No files found.
src/event.js
View file @
b7ec6ddd
...
...
@@ -526,16 +526,34 @@ jQuery.event = {
click
:
{
// For checkbox, fire native event so checked state will be right
trigger
:
function
()
{
if
(
jQuery
.
nodeName
(
this
,
"input"
)
&&
this
.
type
===
"checkbox"
&&
this
.
click
)
{
if
(
jQuery
.
nodeName
(
this
,
"input"
)
&&
this
.
type
===
"checkbox"
&&
this
.
click
)
{
this
.
click
();
return
false
;
}
}
},
focus
:
{
// Fire native event if possible so blur/focus sequence is correct
trigger
:
function
()
{
if
(
this
!==
document
.
activeElement
&&
this
.
focus
)
{
try
{
this
.
focus
();
return
false
;
}
catch
(
e
)
{
// IE<9 dies on focus to hidden element (#1486,#12518)
// If this happens, let .trigger() run the handlers
}
}
},
delegateType
:
"focusin"
},
blur
:
{
trigger
:
function
()
{
if
(
this
===
document
.
activeElement
&&
this
.
blur
)
{
this
.
blur
();
return
false
;
}
},
delegateType
:
"focusout"
},
...
...
test/unit/event.js
View file @
b7ec6ddd
...
...
@@ -2860,6 +2860,50 @@ test("checkbox state (#3827)", function() {
jQuery
(
cb
).
triggerHandler
(
"click"
);
});
test
(
"focus-blur order (#12868)"
,
function
()
{
expect
(
5
);
var
$text
=
jQuery
(
"#text1"
),
$radio
=
jQuery
(
"#radio1"
).
focus
(),
order
;
// IE6-10 fire focus/blur events asynchronously; this is the resulting mess.
// IE's browser window must be topmost for this to work properly!!
stop
();
$radio
[
0
].
focus
();
setTimeout
(
function
()
{
$text
.
on
(
"focus"
,
function
(){
equal
(
order
++
,
1
,
"text focus"
);
})
.
on
(
"blur"
,
function
(){
equal
(
order
++
,
0
,
"text blur"
);
});
$radio
.
on
(
"focus"
,
function
(){
equal
(
order
++
,
1
,
"radio focus"
);
})
.
on
(
"blur"
,
function
(){
equal
(
order
++
,
0
,
"radio blur"
);
});
// Enabled input getting focus
order
=
0
;
equal
(
document
.
activeElement
,
$radio
[
0
],
"radio has focus"
);
$text
.
focus
();
setTimeout
(
function
()
{
equal
(
document
.
activeElement
,
$text
[
0
],
"text has focus"
);
// Run handlers without native method on an input
order
=
1
;
$radio
.
triggerHandler
(
"focus"
);
start
();
},
50
);
},
50
);
});
test
(
"fixHooks extensions"
,
function
()
{
expect
(
2
);
...
...
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