Show More
@@ -766,6 +766,33 b' define([' | |||||
766 | }; |
|
766 | }; | |
767 | }; |
|
767 | }; | |
768 |
|
768 | |||
|
769 | var typeset = function(element, text) { | |||
|
770 | /** | |||
|
771 | * Apply MathJax rendering to an element, and optionally set its text | |||
|
772 | * | |||
|
773 | * If MathJax is not available, make no changes. | |||
|
774 | * | |||
|
775 | * Returns the output any number of typeset elements, or undefined if | |||
|
776 | * MathJax was not available. | |||
|
777 | * | |||
|
778 | * Parameters | |||
|
779 | * ---------- | |||
|
780 | * element: Node, NodeList, or jQuery selection | |||
|
781 | * text: option string | |||
|
782 | */ | |||
|
783 | if(!window.MathJax){ | |||
|
784 | return; | |||
|
785 | } | |||
|
786 | var $el = element.jquery ? element : $(element); | |||
|
787 | if(arguments.length > 1){ | |||
|
788 | $el.text(text); | |||
|
789 | } | |||
|
790 | return $el.map(function(){ | |||
|
791 | // MathJax takes a DOM node: $.map makes `this` the context | |||
|
792 | return MathJax.Hub.Queue(["Typeset", MathJax.Hub, this]); | |||
|
793 | }); | |||
|
794 | }; | |||
|
795 | ||||
769 | var utils = { |
|
796 | var utils = { | |
770 | regex_split : regex_split, |
|
797 | regex_split : regex_split, | |
771 | uuid : uuid, |
|
798 | uuid : uuid, | |
@@ -799,6 +826,7 b' define([' | |||||
799 | load_class: load_class, |
|
826 | load_class: load_class, | |
800 | resolve_promises_dict: resolve_promises_dict, |
|
827 | resolve_promises_dict: resolve_promises_dict, | |
801 | reject: reject, |
|
828 | reject: reject, | |
|
829 | typeset: typeset, | |||
802 | }; |
|
830 | }; | |
803 |
|
831 | |||
804 | // Backwards compatability. |
|
832 | // Backwards compatability. |
@@ -220,10 +220,7 b' define([' | |||||
220 | * @method typeset |
|
220 | * @method typeset | |
221 | */ |
|
221 | */ | |
222 | Cell.prototype.typeset = function () { |
|
222 | Cell.prototype.typeset = function () { | |
223 | if (window.MathJax) { |
|
223 | utils.typeset(this.element); | |
224 | var cell_math = this.element.get(0); |
|
|||
225 | MathJax.Hub.Queue(["Typeset", MathJax.Hub, cell_math]); |
|
|||
226 | } |
|
|||
227 | }; |
|
224 | }; | |
228 |
|
225 | |||
229 | /** |
|
226 | /** |
@@ -199,9 +199,7 b' define([' | |||||
199 |
|
199 | |||
200 | // typeset with MathJax if MathJax is available |
|
200 | // typeset with MathJax if MathJax is available | |
201 | OutputArea.prototype.typeset = function () { |
|
201 | OutputArea.prototype.typeset = function () { | |
202 | if (window.MathJax){ |
|
202 | utils.typeset(this.element); | |
203 | MathJax.Hub.Queue(["Typeset",MathJax.Hub]); |
|
|||
204 | } |
|
|||
205 | }; |
|
203 | }; | |
206 |
|
204 | |||
207 |
|
205 |
@@ -577,19 +577,7 b' define(["widgets/js/manager",' | |||||
577 | }, |
|
577 | }, | |
578 |
|
578 | |||
579 | typeset: function(element, text){ |
|
579 | typeset: function(element, text){ | |
580 | // after (optionally) updating a node(list) or jQuery selection's |
|
580 | utils.typeset.apply(null, arguments); | |
581 | // text, check if MathJax is available and typeset it |
|
|||
582 | var $el = element.jquery ? element : $(element); |
|
|||
583 |
|
||||
584 | if(arguments.length > 1){ |
|
|||
585 | $el.text(text); |
|
|||
586 | } |
|
|||
587 | if(!window.MathJax){ |
|
|||
588 | return; |
|
|||
589 | } |
|
|||
590 | return $el.map(function(){ |
|
|||
591 | return MathJax.Hub.Queue(["Typeset", MathJax.Hub, this]); |
|
|||
592 | }); |
|
|||
593 | }, |
|
581 | }, | |
594 | }); |
|
582 | }); | |
595 |
|
583 |
General Comments 0
You need to be logged in to leave comments.
Login now