mediawiki-extensions-Visual.../modules/ve/dm/annotations/ve.dm.LinkAnnotation.js
Ed Sanders fdf30b1ac8 Store data in LinearData class with an index-value store for objects
Created an IndexValueStore class which can store any object and return
an integer index to its hash map.

Linear data is now stored in ve.dm.LinearData instances. Two subclasses
for element and meta data contain methods specific to those data types
(ElementLinearData and MetaLinearData).

The static methods in ve.dm.Document that inspected data at a given
offset are now instance methods of ve.dm.ElementLinearData.

AnnotationSets (which are no longer OrderedHashSets) have been moved
to /dm and also have to be instantiated with a pointer the store.

Bug: 46320
Change-Id: I249a5d48726093d1cb3e36351893f4bff85f52e2
2013-03-30 10:06:34 +00:00

97 lines
2.2 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 {HTMLElement|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 */
/**
* @static
* @property static.name
* @inheritdoc
*/
ve.dm.LinkAnnotation.static.name = 'link';
/**
* @static
* @property static.matchTagNames
* @inheritdoc
*/
ve.dm.LinkAnnotation.static.matchTagNames = ['a'];
/* Methods */
/**
* Get annotation data, especially the href of the link.
*
* @method
* @param {HTMLElement} element
* @returns {Object} Annotation data, containing href property
*/
ve.dm.LinkAnnotation.prototype.getAnnotationData = function( element ) {
return { 'href': element.getAttribute( 'href' ) };
};
/**
* Convert to an object with HTML element information.
*
* @method
* @returns {Object} HTML element information, including tag and attributes properties
*/
ve.dm.LinkAnnotation.prototype.toHTML = function () {
var parentResult = ve.dm.Annotation.prototype.toHTML.call( this );
parentResult.tag = 'a';
parentResult.attributes.href = this.data.href;
return parentResult;
};
/**
* Get a hash of the link annotation.
*
* This extends the basic annotation hash by adding htmlAttributes.rel
* if it present.
*
* This is a custom hash function for ve#getHash.
*
* @method
* @returns {string} Hash string
*/
ve.dm.LinkAnnotation.prototype.getHash = function () {
var keys = [ 'name', 'data' ], obj = {}, i;
for ( i = 0; i < keys.length; i++ ) {
if ( this[keys[i]] !== undefined ) {
obj[keys[i]] = this[keys[i]];
}
}
if ( this.htmlAttributes && this.htmlAttributes.rel ) {
obj.htmlAttributes = {};
obj.htmlAttributes.rel = this.htmlAttributes.rel;
}
return ve.getHash( obj );
};
/* Registration */
ve.dm.modelRegistry.register( ve.dm.LinkAnnotation );