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

Commit

Permalink
Add new modal.stealfocus option to let the modal prevent focusing on …
Browse files Browse the repository at this point in the history
…elements outside it during show
  • Loading branch information
Craga89 committed May 29, 2012
1 parent 0021618 commit f61a615
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 34 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: Tue May 29 17:23:05 2012 +0100
* Date: Tue May 29 19:43:44 2012 +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: Tue May 29 17:23:05 2012 +0100
* Date: Tue May 29 19:43:44 2012 +0100
*/

/* Core qTip styles */
Expand Down
38 changes: 23 additions & 15 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: Tue May 29 17:23:05 2012 +0100
* Date: Tue May 29 19:43:44 2012 +0100
*/

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

// Make sure we can't focus anything outside the tooltip
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();
}
});
if(options.stealfocus !== FALSE) {
docBody.bind('focusin'+namespace, function(event) {
var target = $(event.target),
container = target.closest('.qtip'),
targetOnTop, inputs;

// 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
// or if we can't find one... the tooltip itself
if(!targetOnTop && ($(event.target).closest(selector)[0] !== tooltip[0])) {
inputs = tooltip.find('input:visible')

if(inputs.length < 1) { target.blur(); }
else { inputs.first().focus(); }
}
});
}
}
else {
// Undelegate focus handler
Expand Down Expand Up @@ -2664,6 +2671,7 @@ $.extend(TRUE, QTIP.defaults, {
on: FALSE,
effect: TRUE,
blur: TRUE,
stealfocus: TRUE,
escape: TRUE
}
}
Expand Down
6 changes: 3 additions & 3 deletions dist/jquery.qtip.min.js

Large diffs are not rendered by default.

36 changes: 22 additions & 14 deletions src/modal/modal.js
Expand Up @@ -169,20 +169,27 @@ function Modal(api)
overlay.toggleClass('blurs', options.blur);

// Make sure we can't focus anything outside the tooltip
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();
}
});
if(options.stealfocus !== FALSE) {
docBody.bind('focusin'+namespace, function(event) {
var target = $(event.target),
container = target.closest('.qtip'),
targetOnTop, inputs;

// 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
// or if we can't find one... the tooltip itself
if(!targetOnTop && ($(event.target).closest(selector)[0] !== tooltip[0])) {
inputs = tooltip.find('input:visible')

if(inputs.length < 1) { target.blur(); }
else { inputs.first().focus(); }
}
});
}
}
else {
// Undelegate focus handler
Expand Down Expand Up @@ -279,6 +286,7 @@ $.extend(TRUE, QTIP.defaults, {
on: FALSE,
effect: TRUE,
blur: TRUE,
stealfocus: TRUE,
escape: TRUE
}
}
Expand Down

0 comments on commit f61a615

Please sign in to comment.