mediawiki-extensions-Visual.../modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
Ed Sanders 8c87882633 Use a smarter comparison of annotations when creating open/close tags
Currently we just compare by store index, but a bold annotation
with data-parsoid attributes set should merge with a new clean bold
annotation. Similar rules apply to link annotations.

Bug: 48110
Change-Id: I93586919002c78732228e08b134e67e1a94f8ad7
2013-05-05 20:41:53 +01:00

60 lines
1.3 KiB
JavaScript

/*!
* VisualEditor DataModel LinkAnnotation class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* DataModel link annotation.
*
* Represents `<a>` tags that don't have a specific type.
*
* @class
* @extends ve.dm.Annotation
* @constructor
* @param {Object} element
*/
ve.dm.LinkAnnotation = function VeDmLinkAnnotation( element ) {
// Parent constructor
ve.dm.Annotation.call( this, element );
};
/* Inheritance */
ve.inheritClass( ve.dm.LinkAnnotation, ve.dm.Annotation );
/* Static Properties */
ve.dm.LinkAnnotation.static.name = 'link';
ve.dm.LinkAnnotation.static.matchTagNames = ['a'];
ve.dm.LinkAnnotation.static.toDataElement = function ( domElements ) {
return {
'type': 'link',
'attributes': {
'href': domElements[0].getAttribute( 'href' )
}
};
};
ve.dm.LinkAnnotation.static.toDomElements = function ( dataElement, doc ) {
var domElement = doc.createElement( 'a' );
domElement.setAttribute( 'href', dataElement.attributes.href );
return [ domElement ];
};
/* Methods */
ve.dm.LinkAnnotation.prototype.getComparableObject = function () {
return {
'type': this.getType(),
'href': this.getAttribute( 'href' )
};
};
/* Registration */
ve.dm.modelRegistry.register( ve.dm.LinkAnnotation );