diff --git a/core/modules/ckeditor/src/Tests/CKEditorLoadingTest.php b/core/modules/ckeditor/src/Tests/CKEditorLoadingTest.php index 7f51130..05b00b9 100644 --- a/core/modules/ckeditor/src/Tests/CKEditorLoadingTest.php +++ b/core/modules/ckeditor/src/Tests/CKEditorLoadingTest.php @@ -105,8 +105,8 @@ function testLoading() { $this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.'); $this->assertTrue(count($body) === 1, 'A body field exists.'); $this->assertTrue(count($format_selector) === 1, 'A single text format selector exists on the page.'); - $specific_format_selector = $this->xpath('//select[contains(@class, "filter-list") and contains(@class, "editor") and @data-editor-for="edit-body-0-value"]'); - $this->assertTrue(count($specific_format_selector) === 1, 'A single text format selector exists on the page and has the "editor" class and a "data-editor-for" attribute with the correct value.'); + $specific_format_selector = $this->xpath('//select[contains(@class, "filter-list") and @data-editor-for="edit-body-0-value"]'); + $this->assertTrue(count($specific_format_selector) === 1, 'A single text format selector exists on the page and has a "data-editor-for" attribute with the correct value.'); $this->assertTrue(isset($settings['ajaxPageState']['js']['core/modules/ckeditor/js/ckeditor.js']), 'CKEditor glue JS is present.'); $this->assertTrue(isset($settings['ajaxPageState']['js']['core/assets/vendor/ckeditor/ckeditor.js']), 'CKEditor lib JS is present.'); diff --git a/core/modules/editor/js/editor.js b/core/modules/editor/js/editor.js index 88f8592..41348cc 100644 --- a/core/modules/editor/js/editor.js +++ b/core/modules/editor/js/editor.js @@ -14,10 +14,12 @@ * A text format selector DOM element. * * @return DOM - * The text area DOM element. + * The text area DOM element, if it was found. */ function findFieldForFormatSelector($formatSelector) { var field_id = $formatSelector.attr('data-editor-for'); + // This selector will only find text areas in the top-level document. We do + // not support attaching editors on text areas within iframes. return $('#' + field_id).get(0); } @@ -142,15 +144,18 @@ return; } - $(context).find('.editor').once('editor', function () { + $(context).find('[data-editor-for]').once('editor', function () { var $this = $(this); - var activeFormatID = $this.val(); - $this.attr('data-editor-active-text-format', activeFormatID); var field = findFieldForFormatSelector($this); - + // Opt-out if no supported text area was found. if (!field) { return; } + + // Store the current active format. + var activeFormatID = $this.val(); + $this.attr('data-editor-active-text-format', activeFormatID); + // Directly attach this text editor, if the text format is enabled. if (settings.editor.formats[activeFormatID]) { // XSS protection for the current text format/editor is performed on the @@ -193,10 +198,10 @@ if (trigger === 'serialize') { // Removing the editor-processed class guarantees that the editor will // be reattached. Only do this if we're planning to destroy the editor. - editors = $(context).find('.editor-processed'); + editors = $(context).find('.editor-processed[data-editor-for]'); } else { - editors = $(context).find('.editor').removeOnce('editor'); + editors = $(context).find('[data-editor-for]').removeOnce('editor'); } editors.each(function () { diff --git a/core/modules/editor/src/Element.php b/core/modules/editor/src/Element.php index f0b97bf..868dce0 100644 --- a/core/modules/editor/src/Element.php +++ b/core/modules/editor/src/Element.php @@ -67,7 +67,6 @@ function preRenderTextFormat(array $element) { '#name' => $element['format']['format']['#name'], '#value' => $format_id, '#attributes' => array( - 'class' => array('editor'), 'data-editor-for' => $field_id, ), ); diff --git a/core/modules/editor/src/Tests/EditorLoadingTest.php b/core/modules/editor/src/Tests/EditorLoadingTest.php index 910f6fa..d9c53e2 100644 --- a/core/modules/editor/src/Tests/EditorLoadingTest.php +++ b/core/modules/editor/src/Tests/EditorLoadingTest.php @@ -98,8 +98,8 @@ public function testLoading() { $this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.'); $this->assertTrue(count($body) === 1, 'A body field exists.'); $this->assertTrue(count($format_selector) === 1, 'A single text format selector exists on the page.'); - $specific_format_selector = $this->xpath('//select[contains(@class, "filter-list") and contains(@class, "editor") and @data-editor-for="edit-body-0-value"]'); - $this->assertTrue(count($specific_format_selector) === 1, 'A single text format selector exists on the page and has the "editor" class and a "data-editor-for" attribute with the correct value.'); + $specific_format_selector = $this->xpath('//select[contains(@class, "filter-list") and @data-editor-for="edit-body-0-value"]'); + $this->assertTrue(count($specific_format_selector) === 1, 'A single text format selector exists on the page and has a "data-editor-for" attribute with the correct value.'); $this->drupalLogout($this->privileged_user); // Also associate a text editor with the "Plain Text" text format. @@ -127,8 +127,8 @@ public function testLoading() { $this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.'); $this->assertTrue(count($body) === 1, 'A body field exists.'); $this->assertTrue(count($format_selector) === 0, 'No text format selector exists on the page.'); - $hidden_input = $this->xpath('//input[@type="hidden" and @value="plain_text" and contains(@class, "editor") and @data-editor-for="edit-body-0-value"]'); - $this->assertTrue(count($hidden_input) === 1, 'A single text format hidden input exists on the page and has the "editor" class and a "data-editor-for" attribute with the correct value.'); + $hidden_input = $this->xpath('//input[@type="hidden" and @value="plain_text" and @data-editor-for="edit-body-0-value"]'); + $this->assertTrue(count($hidden_input) === 1, 'A single text format hidden input exists on the page and has a "data-editor-for" attribute with the correct value.'); // Create an "article" node that users the full_html text format, then try // to let the untrusted user edit it.