This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from ckeditor/t/162
Other: Removed LinkElement, using custom properties instead. Closes #162.
- Loading branch information
Showing
8 changed files
with
103 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @module link/utils | ||
*/ | ||
|
||
import AttributeElement from '@ckeditor/ckeditor5-engine/src/view/attributeelement'; | ||
|
||
const linkElementSymbol = Symbol( 'linkElement' ); | ||
|
||
/** | ||
* Returns `true` if a given view node is the link element. | ||
* | ||
* @param {module:engine/view/node~Node} node | ||
* @return {Boolean} | ||
*/ | ||
export function isLinkElement( node ) { | ||
return node.is( 'attributeElement' ) && !!node.getCustomProperty( linkElementSymbol ); | ||
} | ||
|
||
/** | ||
* Creates link {@link module:engine/view/attributeelement~AttributeElement} with provided `href` attribute. | ||
* | ||
* @param {String} href | ||
* @return {module:engine/view/attributeelement~AttributeElement} | ||
*/ | ||
export function createLinkElement( href ) { | ||
const linkElement = new AttributeElement( 'a', { href } ); | ||
linkElement.setCustomProperty( linkElementSymbol, true ); | ||
|
||
// https://github.com/ckeditor/ckeditor5-link/issues/121 | ||
linkElement.priority = 5; | ||
|
||
return linkElement; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import AttributeElement from '@ckeditor/ckeditor5-engine/src/view/attributeelement'; | ||
import ContainerElement from '@ckeditor/ckeditor5-engine/src/view/containerelement'; | ||
import Text from '@ckeditor/ckeditor5-engine/src/view/text'; | ||
|
||
import { createLinkElement, isLinkElement } from '../src/utils'; | ||
|
||
describe( 'utils', () => { | ||
describe( 'isLinkElement', () => { | ||
it( 'should return true for elements created by createLinkElement', () => { | ||
const element = createLinkElement( 'http://ckeditor.com' ); | ||
|
||
expect( isLinkElement( element ) ).to.be.true; | ||
} ); | ||
|
||
it( 'should return false for other AttributeElements', () => { | ||
expect( isLinkElement( new AttributeElement( 'a' ) ) ).to.be.false; | ||
} ); | ||
|
||
it( 'should return false for ContainerElements', () => { | ||
expect( isLinkElement( new ContainerElement( 'p' ) ) ).to.be.false; | ||
} ); | ||
|
||
it( 'should return false for text nodes', () => { | ||
expect( isLinkElement( new Text( 'foo' ) ) ).to.be.false; | ||
} ); | ||
} ); | ||
|
||
describe( 'createLinkElement', () => { | ||
it( 'should create link AttributeElement', () => { | ||
const element = createLinkElement( 'http://cksource.com' ); | ||
|
||
expect( isLinkElement( element ) ).to.be.true; | ||
expect( element.priority ).to.equal( 5 ); | ||
expect( element.getAttribute( 'href' ) ).to.equal( 'http://cksource.com' ); | ||
expect( element.name ).to.equal( 'a' ); | ||
} ); | ||
} ); | ||
} ); |