From 47ec05f8c892944bd217418d3efdd13c049fa751 Mon Sep 17 00:00:00 2001 From: Bruce511 Date: Tue, 24 May 2011 19:46:00 +0200 Subject: [PATCH] Dialog: Force a blur on the element which had focus when the dialog opens, and reset the focus to that element when the dialog closes. Fixed #5265 - button: When opening dialog button keeps focus. --- ui/jquery.ui.dialog.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 496118761d0..c57e8e3400c 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -68,7 +68,8 @@ $.widget("ui.dialog", { stack: true, title: "", width: 300, - zIndex: 1000 + zIndex: 1000, + focusOnClose: false }, _create: function() { @@ -228,6 +229,10 @@ $.widget("ui.dialog", { }); $.ui.dialog.maxZ = maxZ; } + // restore focus of underlying page, unless overidden at some point while the dialog is open. + if (self.options.focusOnClose){ + $(self.options.focusOnClose).focus(); + } return self; }, @@ -281,6 +286,10 @@ $.widget("ui.dialog", { options = self.options, uiDialog = self.uiDialog; + // store the element with the current focus, so it can be restored when the dialog closes. Also force a Blur event to it. requires jquery core 1.6 + self.options.focusOnClose = $(":focus"); + $(self.options.focusOnClose).blur(); + self._size(); self._position( options.position ); uiDialog.show( options.show );