Skip to content

Simplify typeset function. #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 7 additions & 27 deletions jupyter-js-widgets/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,42 +143,22 @@ function reject(message, log) {
}

/**
* Apply MathJax rendering to an element, and optionally set its 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 as an array or undefined if
* MathJax was not available.
*
* Parameters
* ----------
* element: Node, NodeList, or jQuery selection
* text: option string
* element: Node
* text: optional string
*/
function typeset(element, text) {
if (arguments.length > 1) {
if (element.length) {
for (var i = 0; i < element.length; ++i) {
var el = element[i];
el.textContent = text;
}
} else {
element.textContent = text;
}
if (text !== void 0) {
element.textContent = text;
}
if (!window.MathJax) {
return;
}
var output = [];
if (element.length) {
for (var i = 0; i < element.length; ++i) {
var el = element[i];
output.push(MathJax.Hub.Queue(['Typeset', MathJax.Hub, el]));
}
} else {
output.push(MathJax.Hub.Queue(['Typeset', MathJax.Hub, element]));
if (window.MathJax) {
MathJax.Hub.Queue(['Typeset', MathJax.Hub, element]);
}
return output;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion jupyter-js-widgets/src/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ var DOMWidgetViewMixin = {
},

typeset: function(element, text){
utils.typeset.apply(null, arguments);
utils.typeset(element, text);
}
};

Expand Down