Expand all

ve.dm.Annotation

Extends

Constructor

new ve.dm.Annotation(element, store) #

Generic DataModel annotation.

This is an abstract class, annotations should extend this and call this constructor from their constructor. You should not instantiate this class directly.

Annotations in the linear model are instances of subclasses of this class. Subclasses should only override static properties and functions.

Parameters:

Name Type Description
element Object

Linear model annotation

store ve.dm.HashValueStore

Store used by annotation

Source:
Generic DataModel annotation.

Properties

applyToAppendedContentstatic #

Automatically apply annotation to content inserted after it.

Properties:

Type Description
boolean
Source:
See:
Automatically apply annotation to content inserted after it.

enableAboutGroupingstatic #

About grouping is not supported for annotations; setting this to true has no effect.

Properties:

Type Description
boolean
Source:
About grouping is not supported for annotations; setting this to true has no effect.

inferFromViewstatic #

Accept this annotation when the browser spontaneously adds it to view's DOM.

Properties:

Type Description
boolean
Source:
Accept this annotation when the browser spontaneously adds it to view's DOM.

removesstatic #

Annotations which are removed when this one is applied

Properties:

Type Description
Array.<string>
Source:
Annotations which are removed when this one is applied

trimWhitespacestatic #

Move whitespace at the edge of the transaction outside of it when converting

e.g. "foo bar baz" -> "foo bar baz"

Properties:

Type Description
boolean
Source:

Move whitespace at the edge of the transaction outside of it when converting

e.g.

Methods

compareTo(annotation) → {boolean} #

Compare two annotations using #getComparableObject

Parameters:

Name Type Description
annotation ve.dm.Annotation

Other annotation to compare against

Source:

Returns:

Annotation is comparable

Type
boolean
Compare two annotations using #getComparableObject

compareToForSerialization(annotation) → {boolean} #

FIXME T126039: Compare to another annotation for serialization

Compares two annotations using #getComparableObjectForSerialization, unless they are both generated annotations, in which case they must be identical.

Parameters:

Name Type Description
annotation ve.dm.Annotation

Annotation to compare to

Source:

Returns:

The other annotation is similar to this one

Type
boolean

FIXME T126039: Compare to another annotation for serialization

Compares two annotations using #getComparableObjectForSerialization, unless they are both generated annotations, in which case they must be identical.

describeAdded() → {Array} #

Describe the addition of this annotation to some text

Source:

Returns:

Descriptions, list of strings or Node arrays

Type
Array
Describe the addition of this annotation to some text

describeRemoved() → {Array} #

Describe the removal of this annotation from some text

Source:

Returns:

Descriptions, list of strings or Node arrays

Type
Array
Describe the removal of this annotation from some text

getAttribute(key) → {any} #

Get the value of an attribute.

Return value is by reference if array or object.

Parameters:

Name Type Description
key string

Name of attribute to get

Inherited from:
Source:

Returns:

Value of attribute, or undefined if no such attribute exists

Type
any
Get the value of an attribute.

getAttributes([prefix]) → {Object} #

Get a copy of all attributes.

Values are by reference if array or object, similar to using the getAttribute method.

Parameters:

Name Type Attributes Description
prefix string optional

Only return attributes with this prefix, and remove the prefix from them

Inherited from:
Source:

Returns:

Attributes

Type
Object
Get a copy of all attributes.

getClonedElement() → {Object} #

Get a clone of the model's linear model element.

The attributes object will be deep-copied.

Inherited from:
Source:

Returns:

Cloned element object

Type
Object
Get a clone of the model's linear model element.

getComparableHtmlAttributes() → {Object} #

FIXME T126037: This method strips data-parsoid & RESTBase IDs from HTML attributes for comparisons.

This should be removed once similar annotation merging is handled correctly by Parsoid.

Source:

Returns:

An object all HTML attributes except data-parsoid & RESTBase IDs

Type
Object
FIXME T126037: This method strips data-parsoid & RESTBase IDs from HTML attributes for comparisons.

getComparableObject() → {Object} #

Get an object containing comparable annotation properties.

This is used by the converter to merge adjacent annotations.

Source:

Returns:

An object containing a subset of the annotation's properties

Type
Object
Get an object containing comparable annotation properties.

getComparableObjectForSerialization() → {Object} #

FIXME T126038: This method adds in HTML attributes so comparable objects aren't serialized together if they have different HTML attributes.

This method needs to be different from #getComparableObject which is still used for editing annotations.

Source:

Returns:

An object containing a subset of the annotation's properties and HTML attributes

Type
Object

FIXME T126038: This method adds in HTML attributes so comparable objects aren't serialized together if they have different HTML attributes.

getElement() → {Object} #

Get a reference to the linear model element.

Inherited from:
Source:

Returns:

Linear model element passed to the constructor, by reference

Type
Object
Get a reference to the linear model element.

getHashObject() → {Object} #

Get the hash object of the linear model element.

The actual logic is in a static function as this needs to be accessible from ve.dm.Converter

This is a custom hash function for OO#getHash.

Inherited from:
Source:

Returns:

Hash object

Type
Object
Get the hash object of the linear model element.

getOriginalDomElements(store) → {Array.<HTMLElement>} #

Get the DOM element(s) this model was originally converted from, if any.

Parameters:

Name Type Description
store ve.dm.HashValueStore

Hash value store where the DOM elements are stored

Inherited from:
Source:

Returns:

DOM elements this model was converted from, empty if not applicable

Type
Array.<HTMLElement>
Get the DOM element(s) this model was originally converted from, if any.

getOriginalDomElementsHash() → {string|undefined} #

Get the DOM element(s) this model was originally converted from, if any.

Inherited from:
Source:

Returns:

Store hash of DOM elements this model was converted from

Type
string | undefined
Get the DOM element(s) this model was originally converted from, if any.

getStore() → {ve.dm.HashValueStore} #

Get a reference to the hash-value store used by the element.

Inherited from:
Source:

Returns:

Hash-value store

Type
ve.dm.HashValueStore
Get a reference to the hash-value store used by the element.

getType() → {string} #

Get the symbolic name of this model's type.

Inherited from:
Source:

Returns:

Type name

Type
string
Get the symbolic name of this model's type.

isDiffComparable(other) → {boolean} #

Check if this element is of the same type as another element for the purposes of diffing.

Elements which aren't of the same type will always be shown as removal and an insertion, whereas comarable elements will be shown as an attribute change.

Parameters:

Name Type Description
other Object

Another element

Inherited from:
Source:

Returns:

Elements are of a comparable type

Type
boolean
Check if this element is of the same type as another element for the purposes of diffing.

isEditable() → {boolean} #

Check whether this node can be edited by a context item

The default implementation always returns true. If your node type is uneditable in certain cases, you should override this function.

Inherited from:
Source:

Returns:

Whether this node is editable

Type
boolean

Check whether this node can be edited by a context item

The default implementation always returns true.

isGenerated() → {boolean} #

Check if the annotation was generated by the converter

Used by compareToForSerialization to avoid merging generated annotations.

Source:

Returns:

The annotation was generated

Type
boolean

Check if the annotation was generated by the converter

Used by compareToForSerialization to avoid merging generated annotations.

isInspectable() → {boolean} #

Check whether this node can be inspected by a context item.

The default implementation always returns true. If your node type is uninspectable in certain cases, you should override this function.

Inherited from:
Source:

Returns:

Whether this node is inspectable

Type
boolean
Check whether this node can be inspected by a context item.

toDomElements(dataElement, doc, converter, childDomElements) → {Array.<HTMLElement>}abstractstatic #

Static function to convert a linear model data element for this annotation type back to a DOM element.

As special facilities for annotations, the annotated content that the returned element will wrap around is passed in as childDomElements, and this function may return an empty array to indicate that the annotation should produce no output. In that case, the child DOM elements will not be wrapped in anything and will be inserted directly into this annotation's parent.

Parameters:

Name Type Description
dataElement Object | Array

Linear model element or array of linear model data

doc HTMLDocument

HTML document for creating elements

converter ve.dm.Converter

Converter object to optionally call .getDomSubtreeFromData() on

childDomElements Array.<Node>

Children that will be appended to the returned element

Source:

Returns:

Array of DOM elements; only the first element is used; may be empty

Type
Array.<HTMLElement>

Static function to convert a linear model data element for this annotation type back to a DOM element.