mediawiki-extensions-Visual.../modules/ve-mw/dm/nodes/ve.dm.MWMathNode.js
Trevor Parscal 37240aca59 Math Node UI
Show an inspector with inputwidget when the user clicks a math
node. The data of the math equation is shown in the
edit box, it can re-render the math tag image when
the inspector is closed, and save the change when
saving the page.

TODO:
* Change the icon from link to math
* Translate title by translatewiki in i18n
* Other further UI improvements

Change-Id: I4d7533af25186cc39cc4bc6a4326d222ffd6db19
2013-07-07 07:32:11 +00:00

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.copyObject( 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 );