jenkins-bot has submitted this change and it was merged.
Change subject: Pass child DOM elements to annotations' toDomElements()
......................................................................
Pass child DOM elements to annotations' toDomElements()
This is special-cased for annotations but should be supported for
all model types once the converter is rewritten to be bottom-up
entirely.
Add a toDomElements() stub to ve.dm.Annotation overriding the stub
in ve.dm.Model so there's a place for the new parameter to be documented.
Change-Id: Id81da87b8b83d556a3618cc6187b22443a1e37e6
---
M modules/ve/dm/ve.dm.Annotation.js
M modules/ve/dm/ve.dm.Converter.js
2 files changed, 26 insertions(+), 3 deletions(-)
Approvals:
Esanders: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/dm/ve.dm.Annotation.js
b/modules/ve/dm/ve.dm.Annotation.js
index 0f8ccc4..d0e5623 100644
--- a/modules/ve/dm/ve.dm.Annotation.js
+++ b/modules/ve/dm/ve.dm.Annotation.js
@@ -48,6 +48,26 @@
*/
ve.dm.Annotation.static.applyToAppendedContent = true;
+/**
+ * Static function to convert a linear model data element for this annotation
type back to
+ * a DOM element.
+ *
+ * As a special facility for annotations, the annotated content that the
returned element will
+ * wrap around is passed in as childDomElements.
+ *
+ * @static
+ * @inheritable
+ * @method
+ * @param {Object|Array} dataElement Linear model element or array of linear
model data
+ * @param {HTMLDocument} doc HTML document for creating elements
+ * @param {ve.dm.Converter} converter Converter object to optionally call
.getDomSubtreeFromData() on
+ * @param {HTMLElement[]} childDomElements Children that will be appended to
the returned element
+ * @returns {HTMLElement[]} DOM elements; only the first element is used
+ */
+ve.dm.Annotation.static.toDomElements = function ( /*dataElement, doc,
converter, childDomElements*/ ) {
+ throw new Error( 've.dm.Annotation subclass must implement
toDomElements' );
+};
+
/* Methods */
/**
diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js
index 4556823..7631889 100644
--- a/modules/ve/dm/ve.dm.Converter.js
+++ b/modules/ve/dm/ve.dm.Converter.js
@@ -294,9 +294,10 @@
* @method
* @param {Object|Array} dataElement Linear model element or data slice
* @param {HTMLDocument} doc Document to create DOM elements in
+ * @param {HTMLElement[]} [childDomElements] Array of child DOM elements to
pass in (annotations only)
* @returns {HTMLElement|boolean} DOM element, or false if the element cannot
be converted
*/
-ve.dm.Converter.prototype.getDomElementsFromDataElement = function (
dataElements, doc ) {
+ve.dm.Converter.prototype.getDomElementsFromDataElement = function (
dataElements, doc, childDomElements ) {
var domElements,
dataElement = ve.isArray( dataElements ) ? dataElements[0] :
dataElements,
nodeClass = this.modelRegistry.lookup( dataElement.type );
@@ -307,7 +308,7 @@
if ( nodeClass.static.isInternal ) {
return false;
}
- domElements = nodeClass.static.toDomElements( dataElements, doc, this );
+ domElements = nodeClass.static.toDomElements( dataElements, doc, this,
childDomElements );
if ( !domElements || !domElements.length ) {
throw new Error( 'toDomElements() failed to return an array
when converting element of type ' + dataElement.type );
}
@@ -1005,7 +1006,9 @@
annotatedChildDomElements = annotatedDomElementStack.pop();
annotatedDomElements =
annotatedDomElementStack[annotatedDomElementStack.length - 1];
- annotationElement = conv.getDomElementsFromDataElement(
annotation.getElement(), doc )[0];
+ annotationElement = conv.getDomElementsFromDataElement(
+ annotation.getElement(), doc, annotatedChildDomElements
+ )[0];
for ( i = 0, len = annotatedChildDomElements.length; i < len;
i++ ) {
annotationElement.appendChild(
annotatedChildDomElements[i] );
}
--
To view, visit https://gerrit.wikimedia.org/r/74067
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id81da87b8b83d556a3618cc6187b22443a1e37e6
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits