Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitddfa837

Browse files
gibson042mgol
authored andcommitted
Event: Fix handling of multiple async focus events
(cherry-picked from24d71ac)Fixesgh-4350Closesgh-4354
1 parentb8d4712 commitddfa837

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

‎src/event.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,13 @@ function leverageNative( el, type, expectSync ) {
554554
if((event.isTrigger&1)&&this[type]){
555555

556556
// Interrupt processing of the outer synthetic .trigger()ed event
557-
if(!saved){
557+
// Saved data should be false in such cases, but might be a leftover capture object
558+
// from an async native handler (gh-4350)
559+
if(!saved.length){
558560

559561
// Store arguments for use when handling the inner native event
562+
// There will always be at least one argument (an event object), so this array
563+
// will not be confused with a leftover capture object.
560564
saved=slice.call(arguments);
561565
dataPriv.set(this,type,saved);
562566

@@ -569,14 +573,14 @@ function leverageNative( el, type, expectSync ) {
569573
if(saved!==result||notAsync){
570574
dataPriv.set(this,type,false);
571575
}else{
572-
result=undefined;
576+
result={};
573577
}
574578
if(saved!==result){
575579

576580
// Cancel the outer synthetic event
577581
event.stopImmediatePropagation();
578582
event.preventDefault();
579-
returnresult;
583+
returnresult.value;
580584
}
581585

582586
// If this is an inner synthetic event for an event with a bubbling surrogate
@@ -591,17 +595,19 @@ function leverageNative( el, type, expectSync ) {
591595

592596
// If this is a native event triggered above, everything is now in order
593597
// Fire an inner synthetic event with the original arguments
594-
}elseif(saved){
598+
}elseif(saved.length){
595599

596600
// ...and capture the result
597-
dataPriv.set(this,type,jQuery.event.trigger(
598-
599-
// Support: IE <=9 - 11+
600-
// Extend with the prototype to reset the above stopImmediatePropagation()
601-
jQuery.extend(saved.shift(),jQuery.Event.prototype),
602-
saved,
603-
this
604-
));
601+
dataPriv.set(this,type,{
602+
value:jQuery.event.trigger(
603+
604+
// Support: IE <=9 - 11+
605+
// Extend with the prototype to reset the above stopImmediatePropagation()
606+
jQuery.extend(saved[0],jQuery.Event.prototype),
607+
saved.slice(1),
608+
this
609+
)
610+
});
605611

606612
// Abort handling of the native event
607613
event.stopImmediatePropagation();

‎test/unit/event.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,6 +3041,49 @@ QUnit.test( "focus-blur order (#12868)", function( assert ) {
30413041
},50);
30423042
});
30433043

3044+
QUnit.test("Event handling works with multiple async focus events (gh-4350)",function(assert){
3045+
assert.expect(3);
3046+
3047+
varremaining=3,
3048+
input=jQuery("#name"),
3049+
3050+
// Support: IE <=9 - 11+
3051+
// focus and blur events are asynchronous; this is the resulting mess.
3052+
// The browser window must be topmost for this to work properly!!
3053+
done=assert.async();
3054+
3055+
input
3056+
.on("focus",function(){
3057+
remaining--;
3058+
assert.ok(true,"received focus event, expecting "+remaining+" more");
3059+
if(remaining>0){
3060+
input.trigger("blur");
3061+
}else{
3062+
done();
3063+
}
3064+
})
3065+
.on("blur",function(){
3066+
setTimeout(function(){
3067+
input.trigger("focus");
3068+
});
3069+
});
3070+
3071+
// gain focus
3072+
input.trigger("focus");
3073+
3074+
// DOM focus is unreliable in TestSwarm
3075+
setTimeout(function(){
3076+
if(QUnit.isSwarm&&remaining===3){
3077+
assert.ok(true,"GAP: Could not observe focus change");
3078+
assert.ok(true,"GAP: Could not observe focus change");
3079+
assert.ok(true,"GAP: Could not observe focus change");
3080+
setTimeout(function(){
3081+
done();
3082+
});
3083+
}
3084+
});
3085+
});
3086+
30443087
QUnit.test("native-backed events preserve trigger data (gh-1741, gh-4139)",function(assert){
30453088
assert.expect(17);
30463089

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp