Skip to content

Commit abcfb8a

Browse files
author
Gabriel Schulhof
committed
[popup] Confine tab navigation to popup while it is open
1 parent b022349 commit abcfb8a

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

js/jquery.mobile.popup.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,40 @@ define( [ "jquery",
6969

7070
ui.screen.bind( "vclick", function( e ) { eatEventAndClose( e ); });
7171

72-
$( window ).bind( "resize", function( e ) {
73-
if ( self._isOpen ) {
74-
self._resizeScreen();
72+
// St00pid browser, y u no tell me where focus go?
73+
ui.container.bind( "focusout focusin", function( e ) {
74+
function maybeClearTimeout() {
75+
if ( self._focusTimeout ) {
76+
clearTimeout( self._focusTimeout );
77+
self._focusTimeout = 0;
78+
}
7579
}
76-
});
7780

78-
$( window ).bind( "keyup", function( e ) {
79-
if ( self._isOpen && e.keyCode === $.mobile.keyCode.ESCAPE ) {
80-
eatEventAndClose( e );
81+
if ( self._isOpen ) {
82+
if ( e.type === "focusout" ) {
83+
maybeClearTimeout();
84+
self._focusTimeout = setTimeout( function() {
85+
self._ui.container.focus();
86+
}, 100 );
87+
}
88+
else
89+
if ( e.type === "focusin" ) {
90+
maybeClearTimeout();
91+
}
8192
}
8293
});
94+
95+
$( window )
96+
.bind( "resize", function( e ) {
97+
if ( self._isOpen ) {
98+
self._resizeScreen();
99+
}
100+
})
101+
.bind( "keyup", function( e ) {
102+
if ( self._isOpen && e.keyCode === $.mobile.keyCode.ESCAPE ) {
103+
eatEventAndClose( e );
104+
}
105+
});
83106
},
84107

85108
_resizeScreen: function() {
@@ -290,6 +313,7 @@ define( [ "jquery",
290313
},
291314
function() {
292315
self._isOpen = true;
316+
self._ui.container.attr("tabindex", "0" ).focus();
293317
self.element.trigger( "opened" );
294318
});
295319

@@ -338,6 +362,7 @@ define( [ "jquery",
338362
.removeAttr( "style" );
339363
},
340364
function() {
365+
self._ui.container.removeAttr( "tabindex" );
341366
self.element.trigger( "closed" );
342367
});
343368

0 commit comments

Comments
 (0)