Properties
allowedRdfaTypesstatic
#
Extra RDFa types that the element is allowed to have (but don't by
themselves trigger a match).
Empty array means none, null means any.
For more information about element matching, see ve.dm
.ModelRegistry.
Properties:
- Source:
Extra RDFa types that the element is allowed to have (but don't by themselves trigger a match).
enableAboutGroupingstatic
#
Whether this model supports about grouping. When a DOM element matches a model type that has about grouping enabled, the converter will look for adjacent siblings with the same value for the about attribute, and ask #toDataElement to produce a single data element for all of those DOM nodes combined.
The converter doesn't descend into about groups, i.e. it doesn't convert the children of the DOM elements that make up the about group. This means the resulting linear model element will be childless.
Properties:
Type | Description |
---|---|
boolean |
- Source:
matchFunctionstatic
#
Optional function to determine whether this model should match a given element.
Takes a Node and returns true or false.
This function is only called if this model has a chance of "winning"; see
ve.dm
.ModelRegistry for more information about element matching.
If set to null, this property is ignored. Setting this to null is not the same as unconditionally
returning true, because the presence or absence of a matchFunction affects the model's
specificity.
NOTE: This function is NOT a method, within this function "this" will not refer to an instance of this class (or to anything reasonable, for that matter).
Properties:
Type | Description |
---|---|
function |
- Source:
matchRdfaTypesstatic
#
Array of RDFa types that this model should be a match candidate for.
Any other types the element might have must be specified in allowedRdfaTypes.
Empty array means none, null means any.
For more information about element matching, see ve.dm
.ModelRegistry.
Properties:
- Source:
matchTagNamesstatic
#
namestatic
#
Symbolic name for this model class. Must be set to a unique string by every subclass.
Properties:
Type | Description |
---|---|
string |
- Source:
preserveHtmlAttributesstatic
#
Which HTML attributes should be preserved for this model type. When converting back to DOM, these HTML attributes will be restored except for attributes that were already set by #toDomElements.
The value of this property can be one of the following:
- true, to preserve all attributes (default)
- false, to preserve none
- a function that takes an attribute name and returns true or false
Properties:
Type | Description |
---|---|
boolean | function |
- Source:
Methods
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 |
- Source:
Returns:
Value of attribute, or undefined if no such attribute exists
- Type
- any
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 |
- Source:
Returns:
Attributes
- Type
- Object
getClonedElement() → {Object}
#
Get a clone of the model's linear model element.
The attributes object will be deep-copied.
- Source:
Returns:
Cloned element object
- Type
- Object
getElement() → {Object}
#
Get a reference to the linear model element.
- Source:
Returns:
Linear model element passed to the constructor, by reference
- Type
- Object
getHashObject() → {Object}
#
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 |
- Source:
Returns:
DOM elements this model was converted from, empty if not applicable
- Type
- Array.<HTMLElement>
getOriginalDomElementsHash() → {string|undefined
}
#
undefined
}
#
Get the DOM element(s) this model was originally converted from, if any.
- Source:
Returns:
Store hash of DOM elements this model was converted from
- Type
-
string
|
undefined
getStore() → {ve.dm.HashValueStore}
#
Get a reference to the hash-value store used by the element.
- Source:
Returns:
Hash-value store
- Type
- ve.dm.HashValueStore
getType() → {string}
#
Get the symbolic name of this model's type.
- Source:
Returns:
Type name
- Type
- string
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 |
- Source:
Returns:
Elements are of a comparable type
- Type
- boolean
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.
- 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.
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.
- Source:
Returns:
Whether this node is inspectable
- Type
- boolean
describeChange(key, change) → {string|Array.<Node>|null
}static
#
null
}static
#
Describe a single attribute change in the model
Parameters:
Name | Type | Description |
---|---|---|
key |
string | Attribute key |
change |
Object | Change object with from and to properties |
- Source:
Returns:
Description (string or Node array), or null if nothing to describe
describeChanges(attributeChanges, attributes, element) → {Array}static
#
Describe attribute changes in the model
Parameters:
Name | Type | Description |
---|---|---|
attributeChanges |
Object | Attribute changes, keyed list containing objects with from and to properties |
attributes |
Object | New attributes |
element |
Object | New element |
- Source:
Returns:
Descriptions, list of strings or Node arrays
- Type
- Array
getAllowedRdfaTypes() → {Array.<(string|RegExp)>|null
}static
#
null
}static
#
Extra RDFa types that the element is allowed to have.
- Source:
Returns:
Array of strings or regular expressions
getAttributeDiff(oldText, newText, [allowRemoveInsert]) → {HTMLElement|null
}static
#
null
}static
#
Compare two attribute strings and return an HTML diff
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
oldText |
string | Old attribute text |
|
newText |
string | New attribute text |
|
allowRemoveInsert |
boolean |
optional |
Allow the diff to be a full remove insert |
- Source:
Returns:
An HTML diff in a span element, or null if the diff was a simple remove-insert, and allowRemoveInsert wasn't set.
- Type
-
HTMLElement
|
null
getHashObject(dataElement) → {Object}static
#
getMatchRdfaTypes() → {Array.<(string|RegExp)>|null
}static
#
null
}static
#
Array of RDFa types that this model should be a match candidate for.
- Source:
Returns:
Array of strings or regular expressions
isDiffComparable(element, other, elementStore, otherStore) → {boolean}static
#
Check if this element is of the same type as another element for the purposes of diffing.
Parameters:
Name | Type | Description |
---|---|---|
element |
Object | This element |
other |
Object | Another element |
elementStore |
ve.dm.HashValueStore | Store used by this element |
otherStore |
ve.dm.HashValueStore | Store used by other elements |
- Source:
Returns:
Elements are of a comparable type
- Type
- boolean
toDataElement(domElements, converter) → {Object|Array|null
}static
#
null
}static
#
Static function to convert a DOM element or set of sibling DOM elements to a linear model element for this model type.
This function is only called if this model "won" the matching for the first DOM element, so domElements[0] will match this model's matching rule. There is usually only one DOM node in domElements[]. Multiple elements will only be passed if this model supports about groups. If there are multiple nodes, the nodes are all adjacent siblings in the same about group (i.e. they are grouped together because they have the same value for the about attribute).
The converter has some state variables that can be obtained by this function:
- if converter.isExpectingContent() returns true, the converter expects a content element
- if converter.isInWrapper() returns true, the returned element will be put in a wrapper paragraph generated by the converter (this is only relevant if isExpectingContent() is true)
- converter.canCloseWrapper() returns true if the current wrapper paragraph can be closed, and false if it can't be closed or if there is no active wrapper
This function is allowed to return a content element when context indicates that a non-content element is expected or vice versa. If that happens, the converter deals with it in the following way:
- if a non-content element is expected but a content element is returned:
- open a wrapper paragraph
- put the returned element in the wrapper
- if a content element is expected but a non-content element is returned:
- if we are in a wrapper paragraph:
- if we can close the wrapper:
- close the wrapper
- insert the returned element right after the end of the wrapper
- if we can't close the wrapper:
- alienate the element
- if we can close the wrapper:
- if we aren't in a wrapper paragraph:
- alienate the element
- if we are in a wrapper paragraph:
For these purposes, annotations are considered content. Meta-items can occur anywhere, so if
a meta-element is returned no special action is taken. Note that "alienate" always means an alien
node (ve.dm
.AlienNode) will be generated, never an alien meta-item (ve.dm
.AlienMetaItem),
regardless of whether the subclass attempting the conversion is a node or a meta-item.
The returned linear model element must have a type property set to a registered model name (usually the model's own .static.name, but that's not required). It may optionally have an attributes property set to an object with key-value pairs. Any other properties are not allowed.
This function may return a single linear model element, or an array of balanced linear model data. If this function needs to recursively convert a DOM node (e.g. a child of one of the DOM elements passed in), it can call converter.getDataFromDomSubtree( domElement ). Note that if an array is returned, the converter will not descend into the DOM node's children; the model will be assumed to have handled those children.
Parameters:
Name | Type | Description |
---|---|---|
domElements |
Array.<Node> | DOM elements to convert. Usually only one element |
converter |
ve.dm.Converter |
- Source:
Returns:
Linear model element, or array with linear model data, or null to alienate
Static function to convert a DOM element or set of sibling DOM elements to a linear model element for this model type.
toDomElements(dataElement, doc, converter) → {Array.<Node>}static
#
Static function to convert a linear model data element for this model type back to one or more DOM elements.
If this model is a node with handlesOwnChildren set to true, dataElement will be an array of
the linear model data of this node and all of its children, rather than a single element.
In this case, this function may want to recursively convert linear model data to DOM, which can
be done with ve.dm
.Converter#getDomSubtreeFromData.
NOTE: If this function returns multiple DOM elements, the DOM elements produced by the children of this model (if it's a node and has children) will be attached to the first DOM element in the array. For annotations, only the first element is used, and any additional elements are ignored.
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 |
- Source:
Returns:
DOM elements
Static function to convert a linear model data element for this model type back to one or more DOM elements.
wrapText(tag, text) → {HTMLElement}static
#
Utility function for wrapping text in a tag, equivalent to $( '<tag>' ).text( text )
Parameters:
Name | Type | Description |
---|---|---|
tag |
string | Wrapping element's tag |
text |
string |
- Source:
Returns:
Element wrapping text
- Type
- HTMLElement
$( '<tag>' ).text( text )