diff --git a/core/misc/dialog.ajax.js b/core/misc/dialog.ajax.js index bae03bf..8bb6599 100644 --- a/core/misc/dialog.ajax.js +++ b/core/misc/dialog.ajax.js @@ -9,6 +9,8 @@ Drupal.behaviors.dialog = { attach: function (context, settings) { + var $context = $(context); + // Provide a known 'drupal-modal' DOM element for Drupal-based modal // dialogs. Non-modal dialogs are responsible for creating their own // elements, since there can be multiple non-modal dialogs at a time. @@ -16,12 +18,19 @@ $('
').hide().appendTo('body'); } - // If a new form is being attached inside a dialog, remove and replace - // the dialog buttons with those from the new form. - var $dialog = $(context).closest('.ui-dialog-content'); - if ($dialog && $dialog.dialog('option', 'drupalAutoButtons')) { - var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog); - $dialog.dialog('option', 'buttons', buttons); + // Special behaviors specific when attaching content within a dialog. + // These behaviors usually fire after a validation error inside a dialog. + var $dialog = $context.closest('.ui-dialog-content'); + if ($dialog.length) { + // Remove and replace the dialog buttons with those from the new form. + if ($dialog.dialog('option', 'drupalAutoButtons')) { + var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog); + $dialog.dialog('option', 'buttons', buttons); + } + // Refocus the first input element after validation errors. + if ($context.find('form').length) { + $context.find('input:first').focus(); + } } }, detach: function (context, settings) { @@ -40,19 +49,29 @@ var buttons = []; var $buttons = $dialog.find('.form-actions input[type=submit]'); $buttons.each(function () { - var $originalButton = $(this).hide(); + // Hidden form buttons need special attention. For browser consistency, + // the button needs to be "visible" in order to have the enter key fire + // the form submit event. So instead of a simple "hide" or + // "display: none", we set its dimensions to zero. + // See http://mattsnider.com/how-forms-submit-when-pressing-enter/ + var $originalButton = $(this).css({ + width: 0, + height: 0, + padding: 0, + border: 0 + }); buttons.push({ 'text': $originalButton.html() || $originalButton.attr('value'), 'class': $originalButton.attr('class'), 'click': function (e) { - $originalButton.trigger('mousedown'); + $originalButton.trigger('click'); e.preventDefault(); } }); }); if ($buttons.length) { $dialog.find('form').on('submit.dialogSubmit', function (e) { - $buttons.first().trigger('mousedown'); + $buttons.first().trigger('click'); e.preventDefault(); }); } diff --git a/core/modules/edit/css/edit.module.css b/core/modules/edit/css/edit.module.css index 6a5ac83..bbe7d05 100644 --- a/core/modules/edit/css/edit.module.css +++ b/core/modules/edit/css/edit.module.css @@ -94,7 +94,7 @@ /* Highlighted (hovered) editable. */ .edit-editable.edit-highlighted { - z-index: 305; + z-index: 99; min-width: 200px; } .edit-field.edit-editable.edit-highlighted, @@ -221,7 +221,7 @@ border: 0; margin: 0; vertical-align: baseline; - z-index: 310; + z-index: 100; } .edit-toolbar-container { -webkit-user-select: none; diff --git a/core/modules/editor/lib/Drupal/editor/Form/EditorImageDialog.php b/core/modules/editor/lib/Drupal/editor/Form/EditorImageDialog.php index 0a913bd..0fa6249 100644 --- a/core/modules/editor/lib/Drupal/editor/Form/EditorImageDialog.php +++ b/core/modules/editor/lib/Drupal/editor/Form/EditorImageDialog.php @@ -101,6 +101,7 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_ '#submit' => array(), '#ajax' => array( 'callback' => array($this, 'submitForm'), + 'event' => 'click', ), ); diff --git a/core/modules/editor/lib/Drupal/editor/Form/EditorLinkDialog.php b/core/modules/editor/lib/Drupal/editor/Form/EditorLinkDialog.php index ce2b5c7..4e17831 100644 --- a/core/modules/editor/lib/Drupal/editor/Form/EditorLinkDialog.php +++ b/core/modules/editor/lib/Drupal/editor/Form/EditorLinkDialog.php @@ -68,6 +68,7 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_ '#submit' => array(), '#ajax' => array( 'callback' => array($this, 'submitForm'), + 'event' => 'click', ), );