MathJax: Add a renderTex hook to render elements on demand

Example usage: $('#wikiPreview').renderTex();

This supersedes: https://gerrit.wikimedia.org/r/23073
Bug: 35478

Change-Id: I18e2f089d56e42b8e603ac45d726942bb478580b
This commit is contained in:
Derk-Jan Hartman 2013-04-27 15:53:10 +02:00 committed by Gerrit Code Review
parent 691d1b3186
commit 6d99438a7c
1 changed files with 25 additions and 0 deletions

View File

@ -36,6 +36,31 @@
MathJax.OutputJax.fontDir = mw.config.get('wgExtensionAssetsPath') + '/Math/modules/MathJax/fonts';
};
/**
* Renders all Math TeX inside the given elements.
* @param {function} callback to be executed after text elements have rendered [optional]
*/
$.fn.renderTex = function ( callback ) {
var elem = this.find( '.tex' ).parent().toArray();
if ( !$.isFunction( callback ) ) {
callback = $.noop;
}
function render () {
MathJax.Hub.Queue( ['Typeset', MathJax.Hub, elem, callback] );
}
mw.loader.using( 'ext.math.mathjax', function () {
if ( MathJax.isReady ) {
render();
} else {
MathJax.Hub.Startup.signal.MessageHook( 'End', render );
}
});
return this;
};
mathJax.Load = function () {
var config, script;
if (this.loaded) {