moving typeset to utils, usage in cell and outputarea

This commit is contained in:
Nicholas Bollweg (Nick) 2014-12-04 21:06:34 -05:00
parent c95a9aaf80
commit 83757b6a0e
4 changed files with 31 additions and 20 deletions

View File

@ -766,6 +766,33 @@ define([
};
};
var typeset = function(element, text) {
/**
* Apply MathJax rendering to an element, and optionally set its text
*
* If MathJax is not available, make no changes.
*
* Returns the output any number of typeset elements, or undefined if
* MathJax was not available.
*
* Parameters
* ----------
* element: Node, NodeList, or jQuery selection
* text: option string
*/
if(!window.MathJax){
return;
}
var $el = element.jquery ? element : $(element);
if(arguments.length > 1){
$el.text(text);
}
return $el.map(function(){
// MathJax takes a DOM node: $.map makes `this` the context
return MathJax.Hub.Queue(["Typeset", MathJax.Hub, this]);
});
};
var utils = {
regex_split : regex_split,
uuid : uuid,
@ -799,6 +826,7 @@ define([
load_class: load_class,
resolve_promises_dict: resolve_promises_dict,
reject: reject,
typeset: typeset,
};
// Backwards compatability.

View File

@ -220,10 +220,7 @@ define([
* @method typeset
*/
Cell.prototype.typeset = function () {
if (window.MathJax) {
var cell_math = this.element.get(0);
MathJax.Hub.Queue(["Typeset", MathJax.Hub, cell_math]);
}
utils.typeset(this.element);
};
/**

View File

@ -199,9 +199,7 @@ define([
// typeset with MathJax if MathJax is available
OutputArea.prototype.typeset = function () {
if (window.MathJax){
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
utils.typeset(this.element);
};

View File

@ -577,19 +577,7 @@ define(["widgets/js/manager",
},
typeset: function(element, text){
// after (optionally) updating a node(list) or jQuery selection's
// text, check if MathJax is available and typeset it
var $el = element.jquery ? element : $(element);
if(arguments.length > 1){
$el.text(text);
}
if(!window.MathJax){
return;
}
return $el.map(function(){
return MathJax.Hub.Queue(["Typeset", MathJax.Hub, this]);
});
utils.typeset.apply(null, arguments);
},
});