From 153f7b034daef6043b253f4c5bb5a6b1bc39f3d4 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 19 May 2017 16:04:01 +0200 Subject: [PATCH] Allow extension nodes to convert to a specified type of dataElement Sub-classes want to dynamically change type, e.g. inlineFoo/blockFoo, but doing this after storeGeneratedContents invalidates the cache, so ensure this is done as soon as the element is generated. Bug: T151130 Change-Id: I80e2f2587cff8e9d9fe6ded5d8581263268deaa8 --- modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js index bb49eaa02c..9ffe0a48e0 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js @@ -59,13 +59,19 @@ ve.dm.MWExtensionNode.static.getMatchRdfaTypes = function () { return [ 'mw:Extension/' + this.extensionName ]; }; -ve.dm.MWExtensionNode.static.toDataElement = function ( domElements, converter ) { +/** + * @inheritdoc + * @param {Node[]} domElements + * @param {ve.dm.Converter} converter + * @param {string} [type] Type to give dataElement, defaults to static.name + */ +ve.dm.MWExtensionNode.static.toDataElement = function ( domElements, converter, type ) { var dataElement, mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ), mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {}; dataElement = { - type: this.name, + type: type || this.name, attributes: { mw: mwData, originalMw: mwDataJSON @@ -73,6 +79,7 @@ ve.dm.MWExtensionNode.static.toDataElement = function ( domElements, converter ) }; this.storeGeneratedContents( dataElement, domElements, converter.getStore() ); + // Sub-classes should not modify dataElement beyond this point as it will invalidate the cache return dataElement; };