jenkins-bot has submitted this change and it was merged.

Change subject: Pass the converter object to the node handler in toDataElement()
......................................................................


Pass the converter object to the node handler in toDataElement()

This will allow node handlers to recursively invoke getDataFromDomRecursion()

Change-Id: I12cd4b31614a549bfbe8fbdc7d0607ece32aa98a
---
M modules/ve/dm/nodes/ve.dm.AlienNode.js
M modules/ve/dm/ve.dm.Converter.js
M modules/ve/dm/ve.dm.Model.js
3 files changed, 17 insertions(+), 17 deletions(-)

Approvals:
  Esanders: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve/dm/nodes/ve.dm.AlienNode.js 
b/modules/ve/dm/nodes/ve.dm.AlienNode.js
index 29132f4..a414b37 100644
--- a/modules/ve/dm/nodes/ve.dm.AlienNode.js
+++ b/modules/ve/dm/nodes/ve.dm.AlienNode.js
@@ -30,7 +30,7 @@
 
 ve.dm.AlienNode.static.storeHtmlAttributes = false;
 
-ve.dm.AlienNode.static.toDataElement = function ( domElements, context ) {
+ve.dm.AlienNode.static.toDataElement = function ( domElements, converter ) {
        var i, isInline, allTagsInline, type, html;
        // Check whether all elements are inline elements
        allTagsInline = true;
@@ -46,9 +46,9 @@
        // but to generate an alienInline element.
        isInline =
                // Force inline in content locations (but not wrappers)
-               ( context.expectingContent && !context.inWrapper ) ||
+               ( converter.isExpectingContent() && !converter.isInWrapper() ) 
||
                // Also force inline in wrappers that we can't close
-               ( context.inWrapper && !context.canCloseWrapper ) ||
+               ( converter.isInWrapper() && !converter.canCloseWrapper() ) ||
                // Look at the tag names otherwise
                allTagsInline;
        type = isInline ? 'alienInline' : 'alienBlock';
diff --git a/modules/ve/dm/ve.dm.Converter.js b/modules/ve/dm/ve.dm.Converter.js
index 0928c1c..59d38ec 100644
--- a/modules/ve/dm/ve.dm.Converter.js
+++ b/modules/ve/dm/ve.dm.Converter.js
@@ -239,13 +239,11 @@
  * Create a data element from a DOM element.
  * @param {ve.dm.Model} modelClass Model class to use for conversion
  * @param {HTMLElement[]} domElements DOM elements to convert
- * @param {Object} context Converter context to pass to toDataElement() (will 
be cloned)
- * @param {ve.dm.IndexValueStore} store Index-value store
  * @returns {Object} Data element
  */
-ve.dm.Converter.prototype.createDataElement = function ( modelClass, 
domElements, context, store ) {
+ve.dm.Converter.prototype.createDataElement = function ( modelClass, 
domElements ) {
        var i, j, dataElement, dataElementAttributes, domElementAttributes, 
domElementAttribute;
-       dataElement = modelClass.static.toDataElement( domElements, 
ve.copyObject( context ), store );
+       dataElement = modelClass.static.toDataElement( domElements, this );
        if ( modelClass.static.storeHtmlAttributes && dataElement ) {
                for ( i = 0; i < domElements.length; i++ ) {
                        domElementAttributes = domElements[i].attributes;
@@ -422,7 +420,7 @@
                                modelName = this.modelRegistry.matchElement( 
childDomElement );
                                modelClass = this.modelRegistry.lookup( 
modelName ) || ve.dm.AlienNode;
                                if ( modelClass.prototype instanceof 
ve.dm.Annotation ) {
-                                       annotationData = 
this.createDataElement( modelClass, [ childDomElement ], context );
+                                       annotationData = 
this.createDataElement( modelClass, [ childDomElement ] );
                                }
                                if ( modelClass.prototype instanceof 
ve.dm.Annotation && annotationData ) {
                                        annotation = 
this.annotationFactory.create( modelName, annotationData );
@@ -442,7 +440,7 @@
                                        aboutGroup = getAboutGroup( 
childDomElement );
                                        childDomElements = 
modelClass.static.enableAboutGrouping ?
                                                aboutGroup : [ childDomElement 
];
-                                       childDataElement = 
this.createDataElement( modelClass, childDomElements, context, this.store );
+                                       childDataElement = 
this.createDataElement( modelClass, childDomElements );
 
                                        if ( modelClass.prototype instanceof 
ve.dm.MetaItem ) {
                                                // No additional processing 
needed
@@ -468,7 +466,7 @@
                                                        modelClass = 
ve.dm.AlienNode;
                                                        childDomElements = 
modelClass.static.enableAboutGrouping ?
                                                                aboutGroup : [ 
childDomElement ];
-                                                       childDataElement = 
this.createDataElement( modelClass, childDomElements, context, this.store );
+                                                       childDataElement = 
this.createDataElement( modelClass, childDomElements );
                                                        childIsContent = 
this.nodeFactory.isNodeContent( childDataElement.type );
                                                }
                                        }
diff --git a/modules/ve/dm/ve.dm.Model.js b/modules/ve/dm/ve.dm.Model.js
index 729ad60..9990b59 100644
--- a/modules/ve/dm/ve.dm.Model.js
+++ b/modules/ve/dm/ve.dm.Model.js
@@ -74,6 +74,13 @@
  * 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:
  *
@@ -103,15 +110,10 @@
  * @inheritable
  * @method
  * @param {HTMLElement[]} domElements DOM elements to convert. Usually only 
one element
- * @param {Object} context Object describing the current state of the converter
- * @param {boolean} context.expectingContent Whether this function is expected 
to return a content element
- * @param {boolean} context.inWrapper Whether this element is in a wrapper 
paragraph generated by the converter;
- *  can only be true if context.expectingContent is also true
- * @param {boolean} context.canCloseWrapper Whether the current wrapper 
paragraph can be closed;
- *  can only be true if context.inWrapper is also true
+ * @param {ve.dm.Converter} converter Converter object
  * @returns {Object|null} Linear model element, or null to alienate
  */
-ve.dm.Model.static.toDataElement = function ( /*domElements, context*/ ) {
+ve.dm.Model.static.toDataElement = function ( /*domElements, converter*/ ) {
        throw new Error( 've.dm.Model subclass must implement toDataElement' );
 };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/58643
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I12cd4b31614a549bfbe8fbdc7d0607ece32aa98a
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to