mediawiki-extensions-Math/modules/VisualEditor/ve.ce.MWMathNode.js
Ed Sanders 31df8ff3a8 Emit rerender on math node if Tex image is not present
This happens with then empty tag is rendered.

Bug: 63093
Change-Id: I5cf731cedda134d2542946da82997bddf58b00b5
2014-03-31 16:07:59 -07:00

77 lines
1.8 KiB
JavaScript

/*!
* 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
* @extends ve.ce.MWExtensionNode
*
* @constructor
* @param {ve.dm.MWMathNode} model Model to observe
* @param {Object} [config] Configuration options
*/
ve.ce.MWMathNode = function VeCeMWMathNode( model, config ) {
// Parent constructor
ve.ce.MWExtensionNode.call( this, model, config );
// DOM changes
this.$element.addClass( 've-ce-mwMathNode' );
};
/* Inheritance */
OO.inheritClass( ve.ce.MWMathNode, ve.ce.MWExtensionNode );
/* Static Properties */
ve.ce.MWMathNode.static.name = 'mwMath';
ve.ce.MWMathNode.static.primaryCommandName = 'math';
/* 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 );
};
/** */
ve.ce.MWMathNode.prototype.afterRender = function ( domElements ) {
var $img;
if ( this.$( domElements ).is( 'span.tex' ) ) {
// MathJax
MathJax.Hub.Queue(
[ 'Typeset', MathJax.Hub, this.$element[0] ],
[ this, this.emit, 'rerender' ]
);
} else {
$img = this.$element.find( 'img.tex' );
// Rerender after image load
if ( $img.length ) {
$img.on( 'load', ve.bind( function () {
this.emit( 'rerender' );
}, this ) );
} else {
// Passing an empty string returns no image, so rerender immediately
this.emit( 'rerender' );
}
}
};
/* Registration */
ve.ce.nodeFactory.register( ve.ce.MWMathNode );