2014-01-06 09:07:24 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor ContentEditable MWMathNode class.
|
|
|
|
*
|
2015-01-16 12:06:38 +00:00
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
2014-01-06 09:07:24 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*global MathJax, ve, OO */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ContentEditable MediaWiki math node.
|
|
|
|
*
|
|
|
|
* @class
|
2014-05-20 14:52:46 +00:00
|
|
|
* @extends ve.ce.MWInlineExtensionNode
|
2014-01-06 09:07:24 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.dm.MWMathNode} model Model to observe
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ce.MWMathNode = function VeCeMWMathNode( model, config ) {
|
|
|
|
// Parent constructor
|
2014-05-20 14:52:46 +00:00
|
|
|
ve.ce.MWInlineExtensionNode.call( this, model, config );
|
2014-01-06 09:07:24 +00:00
|
|
|
|
|
|
|
// DOM changes
|
|
|
|
this.$element.addClass( 've-ce-mwMathNode' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2014-05-20 14:52:46 +00:00
|
|
|
OO.inheritClass( ve.ce.MWMathNode, ve.ce.MWInlineExtensionNode );
|
2014-01-06 09:07:24 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ce.MWMathNode.static.name = 'mwMath';
|
|
|
|
|
2014-03-20 02:31:41 +00:00
|
|
|
ve.ce.MWMathNode.static.primaryCommandName = 'math';
|
|
|
|
|
2014-01-06 09:07:24 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/** */
|
|
|
|
ve.ce.MWMathNode.prototype.onParseSuccess = function ( deferred, response ) {
|
|
|
|
var data = response.visualeditor, contentNodes = this.$( data.content ).get();
|
|
|
|
if ( contentNodes[0] && contentNodes[0].childNodes ) {
|
|
|
|
contentNodes = Array.prototype.slice.apply( contentNodes[0].childNodes );
|
|
|
|
}
|
|
|
|
deferred.resolve( contentNodes );
|
|
|
|
};
|
|
|
|
|
|
|
|
/** */
|
2014-07-10 21:42:28 +00:00
|
|
|
ve.ce.MWMathNode.prototype.afterRender = function () {
|
2014-11-20 02:51:40 +00:00
|
|
|
var $img,
|
|
|
|
node = this;
|
2014-03-31 23:07:59 +00:00
|
|
|
|
2014-07-10 21:42:28 +00:00
|
|
|
if ( this.$element.is( 'span.tex' ) ) {
|
2014-01-06 09:07:24 +00:00
|
|
|
// MathJax
|
|
|
|
MathJax.Hub.Queue(
|
|
|
|
[ 'Typeset', MathJax.Hub, this.$element[0] ],
|
|
|
|
[ this, this.emit, 'rerender' ]
|
|
|
|
);
|
|
|
|
} else {
|
2014-07-10 21:42:28 +00:00
|
|
|
$img = this.$element.filter( 'img.tex' );
|
2014-01-06 09:07:24 +00:00
|
|
|
// Rerender after image load
|
2014-03-31 23:07:59 +00:00
|
|
|
if ( $img.length ) {
|
2014-11-20 02:51:40 +00:00
|
|
|
$img.on( 'load', function () {
|
|
|
|
node.emit( 'rerender' );
|
|
|
|
} );
|
2014-03-31 23:07:59 +00:00
|
|
|
} else {
|
|
|
|
// Passing an empty string returns no image, so rerender immediately
|
2014-01-06 09:07:24 +00:00
|
|
|
this.emit( 'rerender' );
|
2014-03-31 23:07:59 +00:00
|
|
|
}
|
2014-01-06 09:07:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWMathNode );
|