2013-06-24 14:41:39 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor ContentEditable MWMathNode class.
|
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
2013-06-24 14:41:39 +00:00
|
|
|
* @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-11-01 19:45:59 +00:00
|
|
|
this.$element.addClass( 've-ce-mwMathNode' );
|
2013-06-24 14:41:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 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 ) {
|
2013-11-01 19:45:59 +00:00
|
|
|
var data = response.visualeditor, contentNodes = this.$( 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 ) {
|
2013-11-01 19:45:59 +00:00
|
|
|
if ( this.$( 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-11-01 19:45:59 +00:00
|
|
|
[ 'Typeset', MathJax.Hub, this.$element[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-11-01 19:45:59 +00:00
|
|
|
this.$element.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 );
|