2013-06-24 14:41:39 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor ContentEditable MWMathNode class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2013-08-03 14:17:16 +00:00
|
|
|
/*global MathJax */
|
2013-07-03 21:44:15 +00:00
|
|
|
|
2013-06-24 14:41:39 +00:00
|
|
|
/**
|
|
|
|
* ContentEditable MediaWiki math node.
|
|
|
|
*
|
|
|
|
* @class
|
2013-08-03 14:17:16 +00:00
|
|
|
* @extends ve.ce.MWExtensionNode
|
2013-06-24 14:41:39 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.dm.MWMathNode} model Model to observe
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-06-24 14:41:39 +00:00
|
|
|
*/
|
|
|
|
ve.ce.MWMathNode = function VeCeMWMathNode( model, config ) {
|
|
|
|
// Parent constructor
|
2013-08-03 14:17:16 +00:00
|
|
|
ve.ce.MWExtensionNode.call( this, model, config );
|
2013-06-24 14:41:39 +00:00
|
|
|
|
2013-08-28 22:55:35 +00:00
|
|
|
// DOM changes
|
2013-06-24 14:41:39 +00:00
|
|
|
this.$.addClass( 've-ce-mwMathNode' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.ce.MWMathNode, ve.ce.MWExtensionNode );
|
2013-06-24 14:41:39 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ce.MWMathNode.static.name = 'mwMath';
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2013-07-31 22:53:29 +00:00
|
|
|
/** */
|
2013-07-03 21:44:15 +00:00
|
|
|
ve.ce.MWMathNode.prototype.onParseSuccess = function ( deferred, response ) {
|
|
|
|
var data = response.visualeditor, contentNodes = $( data.content ).get();
|
2013-09-24 18:57:03 +00:00
|
|
|
if ( contentNodes[0] && contentNodes[0].childNodes ) {
|
|
|
|
contentNodes = Array.prototype.slice.apply( contentNodes[0].childNodes );
|
|
|
|
}
|
2013-07-03 21:44:15 +00:00
|
|
|
deferred.resolve( contentNodes );
|
2013-09-26 19:35:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** */
|
|
|
|
ve.ce.MWExtensionNode.prototype.afterRender = function ( domElements ) {
|
|
|
|
if ( $( domElements ).is( 'span.tex' ) ) {
|
2013-07-19 22:30:29 +00:00
|
|
|
// MathJax
|
2013-09-26 19:35:43 +00:00
|
|
|
MathJax.Hub.Queue(
|
2013-09-24 18:57:03 +00:00
|
|
|
[ 'Typeset', MathJax.Hub, this.$[0] ],
|
2013-09-26 19:35:43 +00:00
|
|
|
[ this, this.emit, 'rerender' ]
|
|
|
|
);
|
2013-07-19 22:30:29 +00:00
|
|
|
} else {
|
|
|
|
// Rerender after image load
|
2013-09-26 19:35:43 +00:00
|
|
|
this.$.find( 'img.tex' ).on( 'load', ve.bind( function () {
|
2013-07-19 22:30:29 +00:00
|
|
|
this.emit( 'rerender' );
|
|
|
|
}, this ) );
|
|
|
|
}
|
2013-06-24 14:41:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWMathNode );
|