2013-08-03 14:17:16 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWExtensionNode class.
|
|
|
|
*
|
2017-01-03 16:58:33 +00:00
|
|
|
* @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
|
2013-08-03 14:17:16 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-05-20 11:56:37 +00:00
|
|
|
* DataModel MediaWiki extension node.
|
2013-08-03 14:17:16 +00:00
|
|
|
*
|
|
|
|
* @class
|
2014-05-20 11:56:37 +00:00
|
|
|
* @abstract
|
2015-03-23 15:49:38 +00:00
|
|
|
* @extends ve.dm.LeafNode
|
2014-09-17 00:33:39 +00:00
|
|
|
* @mixins ve.dm.FocusableNode
|
2013-08-03 14:17:16 +00:00
|
|
|
* @mixins ve.dm.GeneratedContentNode
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
*/
|
2014-06-07 03:17:26 +00:00
|
|
|
ve.dm.MWExtensionNode = function VeDmMWExtensionNode() {
|
2015-03-23 15:49:38 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.dm.MWExtensionNode.super.apply( this, arguments );
|
|
|
|
|
2013-08-03 14:17:16 +00:00
|
|
|
// Mixin constructors
|
|
|
|
ve.dm.GeneratedContentNode.call( this );
|
2014-09-17 00:33:39 +00:00
|
|
|
ve.dm.FocusableNode.call( this );
|
2013-08-03 14:17:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-03-23 15:49:38 +00:00
|
|
|
OO.inheritClass( ve.dm.MWExtensionNode, ve.dm.LeafNode );
|
2014-09-17 00:33:39 +00:00
|
|
|
OO.mixinClass( ve.dm.MWExtensionNode, ve.dm.FocusableNode );
|
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;
|
|
|
|
|
2014-06-10 01:01:42 +00:00
|
|
|
ve.dm.MWExtensionNode.static.childNodeTypes = [];
|
|
|
|
|
2014-01-27 21:45:46 +00:00
|
|
|
/**
|
|
|
|
* HTML tag name.
|
|
|
|
* @static
|
|
|
|
* @property {string}
|
|
|
|
* @inheritable
|
|
|
|
*/
|
2013-08-03 14:17:16 +00:00
|
|
|
ve.dm.MWExtensionNode.static.tagName = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the extension and the parser tag name.
|
|
|
|
* @static
|
2013-11-19 08:32:37 +00:00
|
|
|
* @property {string}
|
2013-08-03 14:17:16 +00:00
|
|
|
* @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 ) {
|
2015-10-02 10:39:40 +00:00
|
|
|
var dataElement,
|
2015-08-19 17:33:02 +00:00
|
|
|
mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
|
2013-08-03 14:17:16 +00:00
|
|
|
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
|
|
|
|
|
|
|
|
dataElement = {
|
2014-08-22 20:50:48 +00:00
|
|
|
type: this.name,
|
|
|
|
attributes: {
|
|
|
|
mw: mwData,
|
|
|
|
originalMw: mwDataJSON
|
2013-08-03 14:17:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-02 10:39:40 +00:00
|
|
|
this.storeGeneratedContents( dataElement, domElements, converter.getStore() );
|
2013-08-03 14:17:16 +00:00
|
|
|
|
|
|
|
return dataElement;
|
|
|
|
};
|
|
|
|
|
2016-02-07 18:28:04 +00:00
|
|
|
/** */
|
|
|
|
ve.dm.MWExtensionNode.static.cloneElement = function () {
|
2016-05-04 13:43:27 +00:00
|
|
|
// Parent method
|
|
|
|
var clone = ve.dm.MWExtensionNode.super.static.cloneElement.apply( this, arguments );
|
2016-02-07 18:28:04 +00:00
|
|
|
delete clone.attributes.originalMw;
|
|
|
|
return clone;
|
|
|
|
};
|
|
|
|
|
2013-08-03 14:17:16 +00:00
|
|
|
ve.dm.MWExtensionNode.static.toDomElements = function ( dataElement, doc, converter ) {
|
2016-08-17 19:50:55 +00:00
|
|
|
var el, els, value,
|
2015-10-02 10:39:40 +00:00
|
|
|
store = converter.getStore(),
|
2013-08-03 14:17:16 +00:00
|
|
|
originalMw = dataElement.attributes.originalMw;
|
|
|
|
|
|
|
|
// If the transclusion is unchanged just send back the
|
|
|
|
// original DOM elements so selser can skip over it
|
|
|
|
if (
|
2016-08-17 19:50:55 +00:00
|
|
|
dataElement.originalDomElementsIndex &&
|
2016-05-04 13:43:27 +00:00
|
|
|
originalMw && ve.compare( dataElement.attributes.mw, JSON.parse( originalMw ) )
|
2013-08-03 14:17:16 +00:00
|
|
|
) {
|
2015-10-02 10:39:40 +00:00
|
|
|
// originalDomElements is also used for CE rendering so return a copy
|
2016-08-17 19:50:55 +00:00
|
|
|
els = ve.copyDomElements( converter.getStore().value( dataElement.originalDomElementsIndex ), doc );
|
2013-08-03 14:17:16 +00:00
|
|
|
} else {
|
2015-10-02 10:39:40 +00:00
|
|
|
if (
|
|
|
|
converter.isForClipboard() &&
|
|
|
|
// Use getHashObjectForRendering to get the rendering from the store
|
2016-08-17 19:50:55 +00:00
|
|
|
( value = store.value( store.indexOfValue( null, OO.getHash( [ this.getHashObjectForRendering( dataElement ), undefined ] ) ) ) )
|
2015-10-02 10:39:40 +00:00
|
|
|
) {
|
2015-09-09 09:41:39 +00:00
|
|
|
// For the clipboard use the current DOM contents so the user has something
|
|
|
|
// meaningful to paste into external applications
|
2016-08-17 19:50:55 +00:00
|
|
|
els = ve.copyDomElements( value, doc );
|
2015-09-09 09:41:39 +00:00
|
|
|
} else {
|
|
|
|
el = doc.createElement( this.tagName );
|
|
|
|
el.setAttribute( 'typeof', 'mw:Extension/' + this.getExtensionName( dataElement ) );
|
|
|
|
el.setAttribute( 'data-mw', JSON.stringify( dataElement.attributes.mw ) );
|
|
|
|
els = [ el ];
|
|
|
|
}
|
2013-08-03 14:17:16 +00:00
|
|
|
}
|
2015-09-09 10:02:44 +00:00
|
|
|
if ( converter.isForClipboard() ) {
|
2015-09-15 12:44:52 +00:00
|
|
|
// Resolve attributes
|
2015-09-15 13:28:22 +00:00
|
|
|
ve.resolveAttributes( $( els ), doc, ve.dm.Converter.static.computedAttributes );
|
2015-09-09 10:02:44 +00:00
|
|
|
}
|
|
|
|
return els;
|
2013-08-03 14:17:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.MWExtensionNode.static.getHashObject = function ( dataElement ) {
|
|
|
|
return {
|
|
|
|
type: dataElement.type,
|
2015-10-01 14:57:49 +00:00
|
|
|
mw: ve.copy( dataElement.attributes.mw )
|
2013-08-03 14:17:16 +00:00
|
|
|
};
|
|
|
|
};
|
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
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Extension name
|
2013-08-30 23:23:18 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWExtensionNode.static.getExtensionName = function () {
|
|
|
|
return this.extensionName;
|
|
|
|
};
|
|
|
|
|
2013-08-15 09:40:58 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the extension's name
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2013-08-30 23:23:18 +00:00
|
|
|
* @method
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {string} Extension name
|
2013-08-15 09:40:58 +00:00
|
|
|
*/
|
|
|
|
ve.dm.MWExtensionNode.prototype.getExtensionName = function () {
|
2013-08-30 23:23:18 +00:00
|
|
|
return this.constructor.static.getExtensionName( this.element );
|
|
|
|
};
|
2014-05-20 11:56:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel MediaWiki inline extension node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
2015-03-23 15:49:38 +00:00
|
|
|
* @extends ve.dm.MWExtensionNode
|
2014-05-20 11:56:37 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
|
|
|
*/
|
|
|
|
ve.dm.MWInlineExtensionNode = function VeDmMWInlineExtensionNode() {
|
|
|
|
// Parent constructor
|
2015-03-23 15:49:38 +00:00
|
|
|
ve.dm.MWInlineExtensionNode.super.apply( this, arguments );
|
2014-05-20 11:56:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-03-23 15:49:38 +00:00
|
|
|
OO.inheritClass( ve.dm.MWInlineExtensionNode, ve.dm.MWExtensionNode );
|
2014-05-20 11:56:37 +00:00
|
|
|
|
|
|
|
/* Static members */
|
|
|
|
|
|
|
|
ve.dm.MWInlineExtensionNode.static.isContent = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel MediaWiki block extension node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
2015-03-23 15:49:38 +00:00
|
|
|
* @extends ve.dm.MWExtensionNode
|
2014-05-20 11:56:37 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
|
|
|
* @param {ve.dm.Node[]} [children]
|
|
|
|
*/
|
2015-03-23 15:49:38 +00:00
|
|
|
ve.dm.MWBlockExtensionNode = function VeDmMWBlockExtensionNode() {
|
2014-05-20 11:56:37 +00:00
|
|
|
// Parent constructor
|
2015-03-23 15:49:38 +00:00
|
|
|
ve.dm.MWBlockExtensionNode.super.apply( this, arguments );
|
2014-05-20 11:56:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-03-23 15:49:38 +00:00
|
|
|
OO.inheritClass( ve.dm.MWBlockExtensionNode, ve.dm.MWExtensionNode );
|