Skip to content
This repository has been archived by the owner on Jun 14, 2020. It is now read-only.

Commit

Permalink
Fixed modal input focus prevention issue. Thanks texel
Browse files Browse the repository at this point in the history
  • Loading branch information
Craga89 committed Sep 7, 2011
1 parent 6aca6ce commit e16454e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/jquery.qtip.basic.js
Expand Up @@ -9,7 +9,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
* Date: Wed Sep 7 00:51:23 2011 +0100
* Date: Wed Sep 7 01:08:28 2011 +0100
*/

/*jslint browser: true, onevar: true, undef: true, nomen: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: true */
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.qtip.css
Expand Up @@ -9,7 +9,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
* Date: Wed Sep 7 00:51:23 2011 +0100
* Date: Wed Sep 7 01:08:28 2011 +0100
*/

/* Core qTip styles */
Expand Down
17 changes: 13 additions & 4 deletions dist/jquery.qtip.js
Expand Up @@ -9,7 +9,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
* Date: Wed Sep 7 00:51:23 2011 +0100
* Date: Wed Sep 7 01:08:28 2011 +0100
*/

/*jslint browser: true, onevar: true, undef: true, nomen: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: true */
Expand Down Expand Up @@ -2449,9 +2449,18 @@ function Modal(api)
overlay.toggleClass('blurs', options.blur);

// Make sure we can't focus anything outside the tooltip
docBody.delegate('*', 'focusin'+namespace, function(event) {
if($(event.target).closest(selector)[0] !== tooltip[0]) {
$('a, :input, img', tooltip).add(tooltip).focus();
docBody.bind('focusin'+namespace, function(event) {
var target = $(event.target),
container = target.closest('.qtip'),

// Determine if input container target is above this
targetOnTop = container.length < 1 ? FALSE :
(parseInt(container[0].style.zIndex, 10) > parseInt(tooltip[0].style.zIndex, 10));

// If we're showing a modal, but focus has landed on an input below
// this modal, divert focus to the first visible input in this modal
if(!targetOnTop && ($(event.target).closest(selector)[0] !== tooltip[0])) {
tooltip.find('input:visible').filter(':first').focus();
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.qtip.min.js

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions src/modal/modal.js
Expand Up @@ -164,9 +164,18 @@ function Modal(api)
overlay.toggleClass('blurs', options.blur);

// Make sure we can't focus anything outside the tooltip
docBody.delegate('*', 'focusin'+namespace, function(event) {
if($(event.target).closest(selector)[0] !== tooltip[0]) {
$('a, :input, img', tooltip).add(tooltip).focus();
docBody.bind('focusin'+namespace, function(event) {
var target = $(event.target),
container = target.closest('.qtip'),

// Determine if input container target is above this
targetOnTop = container.length < 1 ? FALSE :
(parseInt(container[0].style.zIndex, 10) > parseInt(tooltip[0].style.zIndex, 10));

// If we're showing a modal, but focus has landed on an input below
// this modal, divert focus to the first visible input in this modal
if(!targetOnTop && ($(event.target).closest(selector)[0] !== tooltip[0])) {
tooltip.find('input:visible').filter(':first').focus();
}
});
}
Expand Down

0 comments on commit e16454e

Please sign in to comment.