diff --git a/assets/js/src/modal.js b/assets/js/src/modal.js index d8a8cc7e44..7a1573d60d 100644 --- a/assets/js/src/modal.js +++ b/assets/js/src/modal.js @@ -63,7 +63,7 @@ define('modal', ['mailpoet', 'jquery'], overlay: false, // focus upon displaying - focus: false, + focus: true, // highlighted elements highlight: null, @@ -91,11 +91,11 @@ define('modal', ['mailpoet', 'jquery'], '', panel: '
'+ ''+ - '
'+ + '
'+ '
'+ '
'+ '
', - subpanel: '
'+ + subpanel: '
'+ '
'+ '
' }, @@ -257,6 +257,11 @@ define('modal', ['mailpoet', 'jquery'], // add sub panel content jQuery('.mailpoet_'+this.options.type+'_body').last() .html(this.subpanels[(this.subpanels.length - 1)].element); + + // focus on sub panel + if(this.options.focus) { + this.focus(); + } } else if (this.options.element) { jQuery('.mailpoet_'+this.options.type+'_body').empty(); jQuery('.mailpoet_'+this.options.type+'_body') @@ -398,7 +403,7 @@ define('modal', ['mailpoet', 'jquery'], } if(this.options.focus) { - jQuery('#mailpoet_'+this.options.type).focus(); + this.focus(); } // set popup as opened @@ -411,6 +416,16 @@ define('modal', ['mailpoet', 'jquery'], return this; }, + focus: function() { + if(this.options.type == 'popup') { + jQuery('#mailpoet_'+this.options.type).focus(); + } else { + // panel and subpanel + jQuery('#mailpoet_'+this.options.type+' .mailpoet_panel_wrapper') + .filter(':visible').focus(); + } + return this; + }, highlightOn: function(element) { jQuery(element).addClass('mailpoet_modal_highlight'); return this; @@ -450,8 +465,6 @@ define('modal', ['mailpoet', 'jquery'], options.type = 'popup'; // set overlay state options.overlay = options.overlay || true; - // set focus state - options.focus = options.focus || true; // initialize modal this.init(options); // open modal @@ -594,6 +607,11 @@ define('modal', ['mailpoet', 'jquery'], // remove last subpanels this.subpanels.pop(); + // focus on previous panel + if(this.options.focus) { + this.focus(); + } + return this; }