Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
[popup] Restrict focus to elements inside the popup -- Fixes #5130
Browse files Browse the repository at this point in the history
Caveat: This kind of focus restriction can still be circumvented using FF's type-to-search feature
  • Loading branch information
Gabriel Schulhof committed Oct 9, 2012
1 parent 823e54a commit 39aea2b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions js/widgets/popup.js
Expand Up @@ -143,6 +143,18 @@ define( [ "jquery",
}
},

// When the popup is open, attempting to focus on an element that is not a child of the popup will redirect focus to the popup
_handleDocumentFocusIn: function( e ) {
if ( this._isOpen &&
e.target !== this._ui.container[ 0 ] &&
0 === $( e.target ).parents().filter( this._ui.container[ 0 ] ).length ) {
this._ui.container.focus();
e.preventDefault();
e.stopImmediatePropagation();
return false;
}
},

_create: function() {
var ui = {
screen: $( "<div class='ui-screen-hidden ui-popup-screen'></div>" ),
Expand Down Expand Up @@ -208,6 +220,9 @@ define( [ "jquery",
resize: $.proxy( this, "_handleWindowResize" ),
keyup: $.proxy( this, "_handleWindowKeyUp" )
});
this._on( $( document ), {
focusin: $.proxy( this, "_handleDocumentFocusIn" )
});
},

_applyTheme: function( dst, theme, prefix ) {
Expand Down

0 comments on commit 39aea2b

Please sign in to comment.