mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 08:34:54 +00:00
671c7d3b25
MWMath and other simple extensions all behave in a similar way, e.g. <tagname>Foreign syntax</tagname>. This creates a base class that should make supporting such extensions, and editing their contents in a plain text box, very simple. Change-Id: Icc0acb33fe32704f71dacb552d9dfa3142eaef2b
58 lines
1.4 KiB
JavaScript
58 lines
1.4 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 */
|
|
|
|
/**
|
|
* ContentEditable MediaWiki math node.
|
|
*
|
|
* @class
|
|
* @extends ve.ce.MWExtensionNode
|
|
*
|
|
* @constructor
|
|
* @param {ve.dm.MWMathNode} model Model to observe
|
|
* @param {Object} [config] Config options
|
|
*/
|
|
ve.ce.MWMathNode = function VeCeMWMathNode( model, config ) {
|
|
// Parent constructor
|
|
ve.ce.MWExtensionNode.call( this, model, config );
|
|
|
|
// DOM Changes
|
|
this.$.addClass( 've-ce-mwMathNode' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ce.MWMathNode, ve.ce.MWExtensionNode );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.ce.MWMathNode.static.name = 'mwMath';
|
|
|
|
/* Methods */
|
|
|
|
/** */
|
|
ve.ce.MWMathNode.prototype.onParseSuccess = function ( deferred, response ) {
|
|
var data = response.visualeditor, contentNodes = $( data.content ).get();
|
|
// HACK: unwrap paragraph from PHP parser
|
|
contentNodes = Array.prototype.slice.apply( contentNodes[0].childNodes );
|
|
deferred.resolve( contentNodes );
|
|
if ( $( contentNodes ).is( 'span.tex' ) ) {
|
|
// MathJax
|
|
MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub ] );
|
|
} else {
|
|
// Rerender after image load
|
|
this.$.find( 'img' ).on( 'load', ve.bind( function () {
|
|
this.emit( 'rerender' );
|
|
}, this ) );
|
|
}
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWMathNode );
|