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