Explorar o código

Introduced LinkElement class.

Oskar Wrobel %!s(int64=9) %!d(string=hai) anos
pai
achega
a7ad86a637

+ 3 - 2
packages/ckeditor5-link/src/link.js

@@ -4,8 +4,9 @@
  */
 
 import Feature from '../core/feature.js';
-import LinkEngine from './linkengine.js';
 import ClickObserver from '../engine/view/observer/clickobserver.js';
+import LinkEngine from './linkengine.js';
+import LinkElement from './linkelement.js';
 
 import Model from '../ui/model.js';
 
@@ -223,7 +224,7 @@ export default class Link extends Feature {
 
 		const viewSelectionParent = viewDocument.selection.getFirstPosition().parent;
 		const viewSelectionParentAncestors = viewSelectionParent.getAncestors();
-		const linkElement = viewSelectionParentAncestors.find( ( ancestor ) => ancestor.name === 'a' );
+		const linkElement = viewSelectionParentAncestors.find( ( ancestor ) => ancestor instanceof LinkElement );
 
 		// When selection is inside link element, then attach panel to this element.
 		if ( linkElement ) {

+ 16 - 0
packages/ckeditor5-link/src/linkelement.js

@@ -0,0 +1,16 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import AttributeElement from '../engine/view/attributeelement.js';
+
+/**
+ * This class is to identifying that specified {@link engine.view.Node} is a {@link link.LinkElement} instance.
+ * E.g. There could be a situation when different features will create nodes with the same names, and we need to identify them.
+ *
+ * @memberOf link
+ * @extends engine.view.AttributeElement
+ */
+export default class LinkElement extends AttributeElement {
+}

+ 2 - 2
packages/ckeditor5-link/src/linkengine.js

@@ -6,7 +6,7 @@
 import Feature from '../core/feature.js';
 import buildModelConverter from '../engine/conversion/buildmodelconverter.js';
 import buildViewConverter from '../engine/conversion/buildviewconverter.js';
-import AttributeElement from '../engine/view/attributeelement.js';
+import LinkElement from './linkelement.js';
 import LinkCommand from './linkcommand.js';
 import UnlinkCommand from './unlinkcommand.js';
 
@@ -33,7 +33,7 @@ export default class LinkEngine extends Feature {
 		// Build converter from model to view for data and editing pipelines.
 		buildModelConverter().for( data.modelToView, editing.modelToView )
 			.fromAttribute( 'linkHref' )
-			.toElement( ( linkHref ) => new AttributeElement( 'a', { href: linkHref } ) );
+			.toElement( ( linkHref ) => new LinkElement( 'a', { href: linkHref } ) );
 
 		// Build converter from view to model for data pipeline.
 		buildViewConverter().for( data.viewToModel )

+ 13 - 0
packages/ckeditor5-link/tests/linkelement.js

@@ -0,0 +1,13 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import LinkElement from '/ckeditor5/link/linkelement.js';
+import AttributeElement from '/ckeditor5/engine/view/attributeelement.js';
+
+describe( 'LinkElement', () => {
+	it( 'should extend AttributeElement', () => {
+		expect( new LinkElement( 'a' ) ).to.instanceof( AttributeElement );
+	} );
+} );

+ 7 - 0
packages/ckeditor5-link/tests/linkengine.js

@@ -5,6 +5,7 @@
 
 import LinkEngine from '/ckeditor5/link/linkengine.js';
 import LinkCommand from '/ckeditor5/link/linkcommand.js';
+import LinkElement from '/ckeditor5/link/linkelement.js';
 import UnlinkCommand from '/ckeditor5/link/unlinkcommand.js';
 import VirtualTestEditor from '/tests/core/_utils/virtualtesteditor.js';
 import { getData as getModelData, setData as setModelData } from '/tests/engine/_utils/model.js';
@@ -67,5 +68,11 @@ describe( 'LinkEngine', () => {
 
 			expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<a href="url">foo</a>bar' );
 		} );
+
+		it( 'should convert to `LinkElement` instance', () => {
+			setModelData( doc, '<$text linkHref="url">foo</$text>bar' );
+
+			expect( editor.editing.view.getRoot().getChild( 0 ) ).to.be.instanceof( LinkElement );
+		} );
 	} );
 } );