mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-28 20:56:44 +00:00
44623c9b2a
These have been pointing to the same method for a while now, we can safely remove these obsolete aliases and just use it as generic copy. * Each file touched by my editor had its new line at EOF fixed where absent * Don't copy an otherwise unused empty object (ve.dm.Converter) * Use common ve#copy syntax instead to create a link (ve.dm.Document, ve.dm.example) * Remove redundant conditionals for isArray/copyArray/copyObject (ve.dm.example) Change-Id: If560e658dc1fb59bf01f702c97e3e82a50a8a255
76 lines
1.9 KiB
JavaScript
76 lines
1.9 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWMathNode class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* DataModel MediaWiki math node.
|
|
*
|
|
* @class
|
|
* @extends ve.dm.LeafNode
|
|
* @constructor
|
|
*/
|
|
ve.dm.MWMathNode = function VeDmMWMathNode( length, element ) {
|
|
// Parent constructor
|
|
ve.dm.LeafNode.call( this, 0, element );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.dm.MWMathNode, ve.dm.LeafNode );
|
|
|
|
/* Static members */
|
|
|
|
ve.dm.MWMathNode.static.name = 'mwMath';
|
|
|
|
ve.dm.MWMathNode.static.enableAboutGrouping = true;
|
|
|
|
ve.dm.MWMathNode.static.matchTagNames = null;
|
|
|
|
ve.dm.MWMathNode.static.matchRdfaTypes = [ 'mw:Extension/math' ];
|
|
|
|
ve.dm.MWMathNode.static.isContent = true;
|
|
|
|
ve.dm.MWMathNode.static.toDataElement = function ( domElements ) {
|
|
var dataElement,
|
|
mwDataJSON = domElements[0].getAttribute( 'data-mw' ),
|
|
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {},
|
|
extsrc = mwData.body.extsrc,
|
|
alt = domElements[0].getAttribute( 'alt' ),
|
|
src = domElements[0].getAttribute( 'src' );
|
|
|
|
dataElement = {
|
|
'type': 'mwMath',
|
|
'attributes': {
|
|
'mw': mwData,
|
|
'originalMw': mwDataJSON,
|
|
'extsrc': extsrc,
|
|
'alt': alt,
|
|
'src': src
|
|
}
|
|
};
|
|
return dataElement;
|
|
};
|
|
|
|
ve.dm.MWMathNode.static.toDomElements = function ( dataElement, doc ) {
|
|
var el = doc.createElement( 'img' ),
|
|
mwData = ve.copy( dataElement.attributes.mw ),
|
|
originalMw = dataElement.attributes.originalMw;
|
|
|
|
mwData.body.extsrc = dataElement.attributes.extsrc;
|
|
if ( originalMw && ve.compare( mwData, JSON.parse( originalMw ) ) ) {
|
|
el.setAttribute( 'data-mw', originalMw );
|
|
} else {
|
|
el.setAttribute( 'data-mw', JSON.stringify( mwData ) );
|
|
}
|
|
el.setAttribute( 'alt', dataElement.attributes.alt );
|
|
el.setAttribute( 'src', dataElement.attributes.src );
|
|
return [ el ];
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWMathNode );
|