Fixed focus on show modal

This commit is contained in:
benweet 2014-08-31 18:24:35 +01:00
parent ab49793420
commit 3381f17330
2 changed files with 15 additions and 15 deletions

View File

@ -378,7 +378,7 @@ define([
// Other initialization that are not prioritary // Other initialization that are not prioritary
eventMgr.addListener("onReady", function() { eventMgr.addListener("onReady", function() {
$('.modal').on('shown.bs.modal', function() { $(document.body).on('shown.bs.modal', '.modal', function() {
var $elt = $(this); var $elt = $(this);
setTimeout(function() { setTimeout(function() {
// When modal opens focus on the first button // When modal opens focus on the first button
@ -388,12 +388,12 @@ define([
// Or on the first input if any // Or on the first input if any
$elt.find("input:enabled:visible:first").focus(); $elt.find("input:enabled:visible:first").focus();
}, 50); }, 50);
}).on('hidden.bs.modal', function() { }).on('hidden.bs.modal', '.modal', function() {
// Focus on the editor when modal is gone // Focus on the editor when modal is gone
editor.focus(); editor.focus();
// Revert to current theme when settings modal is closed // Revert to current theme when settings modal is closed
applyTheme(window.theme); applyTheme(window.theme);
}).keyup(function(e) { }).on('keyup', '.modal', function(e) {
// Handle enter key in modals // Handle enter key in modals
if(e.which == 13 && !$(e.target).is("textarea")) { if(e.which == 13 && !$(e.target).is("textarea")) {
$(this).find(".modal-footer a:last").click(); $(this).find(".modal-footer a:last").click();

View File

@ -387,6 +387,16 @@ define([
layout.init = function() { layout.init = function() {
var isModalShown = false;
$(document.body).on('show.bs.modal', '.modal', function() {
// Close panel if open
menuPanel.toggle(false);
documentPanel.toggle(false);
isModalShown = true;
}).on('hidden.bs.modal', '.modal', function() {
isModalShown = false;
});
// Tweak the body element // Tweak the body element
(function(bodyStyle) { (function(bodyStyle) {
bodyStyle.position = 'absolute'; bodyStyle.position = 'absolute';
@ -464,7 +474,7 @@ define([
// Focus on editor when document panel is closed // Focus on editor when document panel is closed
documentPanel.$elt.on('hidden.layout.toggle', function() { documentPanel.$elt.on('hidden.layout.toggle', function() {
editor.elt.focus(); isModalShown || editor.elt.focus();
}); });
menuPanel.isOpen = false; menuPanel.isOpen = false;
@ -482,7 +492,7 @@ define([
// Focus on editor when menu panel is closed // Focus on editor when menu panel is closed
menuPanel.$elt.on('hidden.layout.toggle', function() { menuPanel.$elt.on('hidden.layout.toggle', function() {
editor.elt.focus(); isModalShown || editor.elt.focus();
}); });
// Gesture // Gesture
@ -558,16 +568,6 @@ define([
previewButtons.$elt.find('.btn-group').toggleClass('dropup', windowSize.height / 2 > -previewButtons.y); previewButtons.$elt.find('.btn-group').toggleClass('dropup', windowSize.height / 2 > -previewButtons.y);
}); });
var isModalShown = false;
$('.modal').on('show.bs.modal', function() {
// Close panel if open
menuPanel.toggle(false);
documentPanel.toggle(false);
isModalShown = true;
}).on('hidden.bs.modal', function() {
isModalShown = false;
});
// Configure Mousetrap // Configure Mousetrap
mousetrap.stopCallback = function() { mousetrap.stopCallback = function() {
return menuPanel.isOpen || documentPanel.isOpen || isModalShown; return menuPanel.isOpen || documentPanel.isOpen || isModalShown;