From 5cfd93ed8b8b678d6589523b64766390d0066c91 Mon Sep 17 00:00:00 2001 From: "A. Darian" Date: Tue, 3 May 2016 19:52:49 +0100 Subject: [PATCH 1/3] Simply typeset function. --- jupyter-js-widgets/src/utils.js | 25 +++---------------------- jupyter-js-widgets/src/widget.js | 2 +- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/jupyter-js-widgets/src/utils.js b/jupyter-js-widgets/src/utils.js index 4cabd41009..46f09b10d4 100644 --- a/jupyter-js-widgets/src/utils.js +++ b/jupyter-js-widgets/src/utils.js @@ -156,29 +156,10 @@ function reject(message, log) { * text: option 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 (!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])); + element.textContent = text; + if (window.MathJax) { + MathJax.Hub.Queue(['Typeset', MathJax.Hub, element]); } - return output; } /** diff --git a/jupyter-js-widgets/src/widget.js b/jupyter-js-widgets/src/widget.js index ce7ec32172..d498af12ab 100644 --- a/jupyter-js-widgets/src/widget.js +++ b/jupyter-js-widgets/src/widget.js @@ -759,7 +759,7 @@ var DOMWidgetViewMixin = { }, typeset: function(element, text){ - utils.typeset.apply(null, arguments); + utils.typeset(element, text); } }; From 3e3df886b36dafb5e5f3304b25e2c438302281a9 Mon Sep 17 00:00:00 2001 From: "A. Darian" Date: Tue, 3 May 2016 21:18:26 +0100 Subject: [PATCH 2/3] Update doc string and check for empty text param. --- jupyter-js-widgets/src/utils.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/jupyter-js-widgets/src/utils.js b/jupyter-js-widgets/src/utils.js index 46f09b10d4..3988131312 100644 --- a/jupyter-js-widgets/src/utils.js +++ b/jupyter-js-widgets/src/utils.js @@ -143,20 +143,19 @@ 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) { - element.textContent = text; + if (text) { + element.textContent = text; + } if (window.MathJax) { MathJax.Hub.Queue(['Typeset', MathJax.Hub, element]); } From 39c409034db22e26c99a2d728a5a7b8822f6da60 Mon Sep 17 00:00:00 2001 From: "A. Darian" Date: Tue, 3 May 2016 22:03:58 +0100 Subject: [PATCH 3/3] If text is an empty string, use it. --- jupyter-js-widgets/src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter-js-widgets/src/utils.js b/jupyter-js-widgets/src/utils.js index 3988131312..e615dde171 100644 --- a/jupyter-js-widgets/src/utils.js +++ b/jupyter-js-widgets/src/utils.js @@ -153,7 +153,7 @@ function reject(message, log) { * text: optional string */ function typeset(element, text) { - if (text) { + if (text !== void 0) { element.textContent = text; } if (window.MathJax) {