2014-01-06 09:07:24 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor ContentEditable MWMathNode class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @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
|
|
|
|
2014-03-20 02:31:41 +00:00
|
|
|
|
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-03-31 23:07:59 +00:00
|
|
|
ve.ce.MWMathNode.prototype.afterRender = function ( domElements ) {
|
|
|
|
var $img;
|
|
|
|
|
2014-01-06 09:07:24 +00:00
|
|
|
if ( this.$( domElements ).is( 'span.tex' ) ) {
|
|
|
|
// MathJax
|
|
|
|
MathJax.Hub.Queue(
|
|
|
|
[ 'Typeset', MathJax.Hub, this.$element[0] ],
|
|
|
|
[ this, this.emit, 'rerender' ]
|
|
|
|
);
|
|
|
|
} else {
|
2014-03-31 23:07:59 +00:00
|
|
|
$img = this.$element.find( '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 ) {
|
|
|
|
$img.on( 'load', ve.bind( function () {
|
|
|
|
this.emit( 'rerender' );
|
|
|
|
}, this ) );
|
|
|
|
} 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 );
|