From 3381f173301695d5b164622f9486d2aa019c8a91 Mon Sep 17 00:00:00 2001 From: benweet Date: Sun, 31 Aug 2014 18:24:35 +0100 Subject: [PATCH] Fixed focus on show modal --- public/res/core.js | 6 +++--- public/res/layout.js | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/public/res/core.js b/public/res/core.js index ca9751e3..d992960e 100644 --- a/public/res/core.js +++ b/public/res/core.js @@ -378,7 +378,7 @@ define([ // Other initialization that are not prioritary eventMgr.addListener("onReady", function() { - $('.modal').on('shown.bs.modal', function() { + $(document.body).on('shown.bs.modal', '.modal', function() { var $elt = $(this); setTimeout(function() { // When modal opens focus on the first button @@ -388,12 +388,12 @@ define([ // Or on the first input if any $elt.find("input:enabled:visible:first").focus(); }, 50); - }).on('hidden.bs.modal', function() { + }).on('hidden.bs.modal', '.modal', function() { // Focus on the editor when modal is gone editor.focus(); // Revert to current theme when settings modal is closed applyTheme(window.theme); - }).keyup(function(e) { + }).on('keyup', '.modal', function(e) { // Handle enter key in modals if(e.which == 13 && !$(e.target).is("textarea")) { $(this).find(".modal-footer a:last").click(); diff --git a/public/res/layout.js b/public/res/layout.js index b41159e8..03916862 100644 --- a/public/res/layout.js +++ b/public/res/layout.js @@ -387,6 +387,16 @@ define([ 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 (function(bodyStyle) { bodyStyle.position = 'absolute'; @@ -464,7 +474,7 @@ define([ // Focus on editor when document panel is closed documentPanel.$elt.on('hidden.layout.toggle', function() { - editor.elt.focus(); + isModalShown || editor.elt.focus(); }); menuPanel.isOpen = false; @@ -482,7 +492,7 @@ define([ // Focus on editor when menu panel is closed menuPanel.$elt.on('hidden.layout.toggle', function() { - editor.elt.focus(); + isModalShown || editor.elt.focus(); }); // Gesture @@ -558,16 +568,6 @@ define([ 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 mousetrap.stopCallback = function() { return menuPanel.isOpen || documentPanel.isOpen || isModalShown;