Browse Source

Template: Make [enter] keyboard shortcut modal compatible.

Nate 5 years ago
parent
commit
f9b8ba7b4b
1 changed files with 11 additions and 3 deletions
  1. 11 3
      themes/default/template.php

+ 11 - 3
themes/default/template.php

@@ -214,7 +214,7 @@
 		//key: [enter] - retain default behavior to submit form, when present - note: safari does not honor the first submit element when hiding it using 'display: none;' in the setAttribute method
 		//key: [enter] - retain default behavior to submit form, when present - note: safari does not honor the first submit element when hiding it using 'display: none;' in the setAttribute method
 			{if $settings.theme.keyboard_shortcut_submit_enabled}
 			{if $settings.theme.keyboard_shortcut_submit_enabled}
 				{literal}
 				{literal}
-				var action_bar_actions, first_form, first_submit;
+				var action_bar_actions, first_form, first_submit, modal_input_class, modal_continue_button;
 				action_bar_actions = document.querySelector('div#action_bar.action_bar > div.actions');
 				action_bar_actions = document.querySelector('div#action_bar.action_bar > div.actions');
 				first_form = document.querySelector('form#frm');
 				first_form = document.querySelector('form#frm');
 
 
@@ -226,9 +226,17 @@
 						first_submit.setAttribute('style','position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden;');
 						first_submit.setAttribute('style','position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden;');
 						first_form.prepend(first_submit);
 						first_form.prepend(first_submit);
 						window.addEventListener('keydown',function(e){
 						window.addEventListener('keydown',function(e){
+							modal_input_class = e.target.className;
 							if (e.which == 13 && (e.target.tagName == 'INPUT' || e.target.tagName == 'SELECT')) {
 							if (e.which == 13 && (e.target.tagName == 'INPUT' || e.target.tagName == 'SELECT')) {
-								if (typeof window.submit_form === 'function') { submit_form(); }
-								else { document.getElementById('frm').submit(); }
+								if (modal_input_class.includes('modal-input')) {
+									e.preventDefault();
+									modal_continue_button = document.getElementById(e.target.dataset.continue);
+									if (modal_continue_button) { modal_continue_button.click(); }
+								}
+								else {
+									if (typeof window.submit_form === 'function') { submit_form(); }
+									else { document.getElementById('frm').submit(); }
+								}
 							}
 							}
 						});
 						});
 					}
 					}