Restore focus on previously focused element after closing a modal box [MAILPOET-724]

This commit is contained in:
Alexey Stoletniy
2017-02-14 15:15:02 +03:00
parent 4439111a44
commit 66990d62c2

View File

@ -28,6 +28,9 @@ define('modal', ['mailpoet', 'jquery'],
opened: false,
locked: false,
// previously focused element
prevFocus: null,
// sub panels
subpanels: [],
@ -372,6 +375,9 @@ define('modal', ['mailpoet', 'jquery'],
// set modal dimensions
this.setDimensions();
// remember the previously focused element
this.prevFocus = jQuery(':focus');
// add a flag on the body so that we can prevent scrolling
jQuery('body').addClass('mailpoet_modal_opened');
@ -600,6 +606,11 @@ define('modal', ['mailpoet', 'jquery'],
// destroy modal element
this.destroy();
// restore the previously focused element
if(this.prevFocus !== undefined){
this.prevFocus.focus();
}
// reset options
this.options = {
onSuccess: null,