diff --git a/core/modules/editor/js/editor.js b/core/modules/editor/js/editor.js index 41348cc..30331f9 100644 --- a/core/modules/editor/js/editor.js +++ b/core/modules/editor/js/editor.js @@ -24,21 +24,18 @@ } /** - * Changes the text editor on the text area for the given text format selector. + * Changes the text editor on a text area. * - * @param jQuery $formatSelector - * A text format selector DOM element. * @param DOM field - * The associated text area DOM element. - * @param String activeFormatID - * The currently active text format; its associated text editor will be - * detached. + * The text area DOM element. * @param String newFormatID - * The text format we're changing to; its associated text editor will be - * attached. + * The text format we're changing to; the text editor for the currently + * active text format will be detached, and the text editor for the new text + * format will be attached. */ - function changeTextEditor($formatSelector, field, activeFormatID, newFormatID) { - var originalFormatID = activeFormatID; + function changeTextEditor(field, newFormatID) { + var activeFormatID = field.getAttribute('data-editor-active-text-format'); + // Detach the current editor (if any) and attach a new editor. if (drupalSettings.editor.formats[activeFormatID]) { Drupal.editorDetach(field, drupalSettings.editor.formats[activeFormatID]); @@ -47,14 +44,15 @@ else if (!drupalSettings.editor.formats[activeFormatID]) { $(field).off('.editor'); } - activeFormatID = newFormatID; // Attach the new text editor (if any). - if (drupalSettings.editor.formats[activeFormatID]) { - var format = drupalSettings.editor.formats[activeFormatID]; - filterXssWhenSwitching(field, format, originalFormatID, Drupal.editorAttach); + if (drupalSettings.editor.formats[newFormatID]) { + var format = drupalSettings.editor.formats[newFormatID]; + filterXssWhenSwitching(field, format, activeFormatID, Drupal.editorAttach); } - $formatSelector.attr('data-editor-active-text-format', newFormatID); + + // Store the new active format. + field.setAttribute('data-editor-active-text-format', newFormatID); } /** @@ -64,9 +62,9 @@ */ function onTextFormatChange(event) { var $select = $(event.target); - var activeFormatID = $select.attr('data-editor-active-text-format'); - var newFormatID = $select.val(); var field = event.data.field; + var activeFormatID = field.getAttribute('data-editor-active-text-format'); + var newFormatID = $select.val(); // Prevent double-attaching if the change event is triggered manually. if (newFormatID === activeFormatID) { @@ -93,7 +91,7 @@ text: Drupal.t('Continue'), 'class': 'button button--primary', click: function () { - changeTextEditor($select, field, activeFormatID, newFormatID); + changeTextEditor(field, newFormatID); confirmationDialog.close(); } }, @@ -125,7 +123,7 @@ confirmationDialog.showModal(); } else { - changeTextEditor($select, field, activeFormatID, newFormatID); + changeTextEditor(field, newFormatID); } } @@ -154,7 +152,7 @@ // Store the current active format. var activeFormatID = $this.val(); - $this.attr('data-editor-active-text-format', activeFormatID); + field.setAttribute('data-editor-active-text-format', activeFormatID); // Directly attach this text editor, if the text format is enabled. if (settings.editor.formats[activeFormatID]) {