浏览代码

Used the dataset API in the ElementApiMixin#secureSourceElement().

Aleksander Nowodzinski 6 年之前
父节点
当前提交
109185ffea

+ 3 - 5
packages/ckeditor5-core/src/editor/utils/elementapimixin.js

@@ -10,8 +10,6 @@ import setDataInElement from '@ckeditor/ckeditor5-utils/src/dom/setdatainelement
  * @module core/editor/utils/elementapimixin
  */
 
-const SECURE_SOURCE_ELEMENT_ATTRIBUTE = 'data-ckeditor5-element';
-
 /**
  * Implementation of the {@link module:core/editor/utils/elementapimixin~ElementApi}.
  *
@@ -56,7 +54,7 @@ const ElementApiMixin = {
 			return;
 		}
 
-		if ( sourceElement.hasAttribute( SECURE_SOURCE_ELEMENT_ATTRIBUTE ) ) {
+		if ( sourceElement.dataset.ckeditorSecuredElement ) {
 			/**
 			 * A DOM element used to create the editor (e.g.
 			 * {@link module:editor-classic/classiceditor~ClassicEditor.create `ClassicEditor.create()`})
@@ -71,10 +69,10 @@ const ElementApiMixin = {
 			);
 		}
 
-		sourceElement.setAttribute( SECURE_SOURCE_ELEMENT_ATTRIBUTE, 'true' );
+		sourceElement.dataset.ckeditorSecuredElement = true;
 
 		this.once( 'destroy', () => {
-			sourceElement.removeAttribute( SECURE_SOURCE_ELEMENT_ATTRIBUTE );
+			delete sourceElement.dataset.ckeditorSecuredElement;
 		} );
 	}
 };

+ 3 - 3
packages/ckeditor5-core/tests/editor/utils/elementapimixin.js

@@ -81,7 +81,7 @@ describe( 'ElementApiMixin', () => {
 		it( 'sets the data attribute after initializing the editor', () => {
 			editor.secureSourceElement();
 
-			expect( sourceElement.hasAttribute( 'data-ckeditor5-element' ) ).to.equal( true );
+			expect( sourceElement.dataset.ckeditorSecuredElement ).to.equal( 'true' );
 		} );
 
 		it( 'removes the data attribute after destroying the editor', () => {
@@ -89,12 +89,12 @@ describe( 'ElementApiMixin', () => {
 
 			return editor.destroy()
 				.then( () => {
-					expect( sourceElement.hasAttribute( 'data-ckeditor5-element' ) ).to.equal( false );
+					expect( sourceElement.dataset.ckeditorSecuredElement ).to.be.undefined;
 				} );
 		} );
 
 		it( 'throws an error if the same element was used twice', () => {
-			sourceElement.setAttribute( 'data-ckeditor5-element', 'true' );
+			sourceElement.dataset.ckeditorSecuredElement = true;
 
 			expectToThrowCKEditorError(
 				() => editor.secureSourceElement(),