2013-08-03 14:17:16 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWExtensionNode class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel MediaWiki Extension node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.dm.LeafNode
|
|
|
|
* @mixins ve.dm.GeneratedContentNode
|
|
|
|
*
|
|
|
|
* @constructor
|
2013-10-17 13:24:00 +00:00
|
|
|
* @param {number} [length] Length of content data (ignored, forced to 0)
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
2013-08-03 14:17:16 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWExtensionNode = function VeDmMWExtensionNode( length, element ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.dm.LeafNode.call( this, 0, element );
|
|
|
|
|
|
|
|
// Mixin constructors
|
|
|
|
ve.dm.GeneratedContentNode.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.dm.MWExtensionNode, ve.dm.LeafNode );
|
2013-08-03 14:17:16 +00:00
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.mixinClass( ve.dm.MWExtensionNode, ve.dm.GeneratedContentNode );
|
2013-08-03 14:17:16 +00:00
|
|
|
|
|
|
|
/* Static members */
|
|
|
|
|
|
|
|
ve.dm.MWExtensionNode.static.enableAboutGrouping = true;
|
|
|
|
|
|
|
|
ve.dm.MWExtensionNode.static.matchTagNames = null;
|
|
|
|
|
|
|
|
ve.dm.MWExtensionNode.static.isContent = true;
|
|
|
|
|
|
|
|
ve.dm.MWExtensionNode.static.tagName = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the extension and the parser tag name.
|
|
|
|
* @static
|
|
|
|
* @property {string} static.extensionName
|
|
|
|
* @inheritable
|
|
|
|
*/
|
|
|
|
ve.dm.MWExtensionNode.static.extensionName = null;
|
|
|
|
|
|
|
|
ve.dm.MWExtensionNode.static.getMatchRdfaTypes = function () {
|
|
|
|
return [ 'mw:Extension/' + this.extensionName ];
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.MWExtensionNode.static.toDataElement = function ( domElements, converter ) {
|
|
|
|
var dataElement, index,
|
|
|
|
mwDataJSON = domElements[0].getAttribute( 'data-mw' ),
|
|
|
|
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
|
|
|
|
|
|
|
|
dataElement = {
|
|
|
|
'type': this.name,
|
|
|
|
'attributes': {
|
|
|
|
'mw': mwData,
|
|
|
|
'originalDomElements': ve.copy( domElements ),
|
|
|
|
'originalMw': mwDataJSON
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-15 17:37:03 +00:00
|
|
|
index = this.storeGeneratedContents( dataElement, domElements, converter.getStore() );
|
2013-08-03 14:17:16 +00:00
|
|
|
dataElement.attributes.originalIndex = index;
|
|
|
|
|
|
|
|
return dataElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.MWExtensionNode.static.toDomElements = function ( dataElement, doc, converter ) {
|
|
|
|
var el,
|
|
|
|
index = converter.getStore().indexOfHash( ve.getHash( this.getHashObject( dataElement ) ) ),
|
|
|
|
originalMw = dataElement.attributes.originalMw;
|
|
|
|
|
|
|
|
// If the transclusion is unchanged just send back the
|
|
|
|
// original DOM elements so selser can skip over it
|
|
|
|
if (
|
|
|
|
index === dataElement.attributes.originalIndex ||
|
|
|
|
( originalMw && ve.compare( dataElement.attributes.mw, JSON.parse( originalMw ) ) )
|
|
|
|
) {
|
|
|
|
// The object in the store is also used for CE rendering so return a copy
|
|
|
|
return ve.copyDomElements( dataElement.attributes.originalDomElements, doc );
|
|
|
|
} else {
|
|
|
|
el = doc.createElement( this.tagName );
|
2013-08-30 23:23:18 +00:00
|
|
|
el.setAttribute( 'typeof', 'mw:Extension/' + this.getExtensionName( dataElement ) );
|
2013-08-03 14:17:16 +00:00
|
|
|
el.setAttribute( 'data-mw', JSON.stringify( dataElement.attributes.mw ) );
|
|
|
|
return [ el ];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.MWExtensionNode.static.getHashObject = function ( dataElement ) {
|
|
|
|
return {
|
|
|
|
type: dataElement.type,
|
|
|
|
mw: dataElement.attributes.mw
|
|
|
|
};
|
|
|
|
};
|
2013-08-15 09:40:58 +00:00
|
|
|
|
2013-08-30 23:23:18 +00:00
|
|
|
/**
|
|
|
|
* Get the extension's name
|
|
|
|
*
|
|
|
|
* Static version for toDomElements
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @param {Object} dataElement Data element
|
|
|
|
* @returns {string} Extension name
|
|
|
|
*/
|
|
|
|
ve.dm.MWExtensionNode.static.getExtensionName = function () {
|
|
|
|
return this.extensionName;
|
|
|
|
};
|
|
|
|
|
2013-08-15 09:40:58 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the extension's name
|
2013-08-30 23:23:18 +00:00
|
|
|
* @method
|
2013-08-15 09:40:58 +00:00
|
|
|
* @returns {string} Extension name
|
|
|
|
*/
|
|
|
|
ve.dm.MWExtensionNode.prototype.getExtensionName = function () {
|
2013-08-30 23:23:18 +00:00
|
|
|
return this.constructor.static.getExtensionName( this.element );
|
|
|
|
};
|