##// END OF EJS Templates
moving typeset to utils, usage in cell and outputarea
Nicholas Bollweg (Nick) -
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 796 var utils = {
770 797 regex_split : regex_split,
771 798 uuid : uuid,
@@ -799,6 +826,7 b' define(['
799 826 load_class: load_class,
800 827 resolve_promises_dict: resolve_promises_dict,
801 828 reject: reject,
829 typeset: typeset,
802 830 };
803 831
804 832 // Backwards compatability.
@@ -220,10 +220,7 b' define(['
220 220 * @method typeset
221 221 */
222 222 Cell.prototype.typeset = function () {
223 if (window.MathJax) {
224 var cell_math = this.element.get(0);
225 MathJax.Hub.Queue(["Typeset", MathJax.Hub, cell_math]);
226 }
223 utils.typeset(this.element);
227 224 };
228 225
229 226 /**
@@ -199,9 +199,7 b' define(['
199 199
200 200 // typeset with MathJax if MathJax is available
201 201 OutputArea.prototype.typeset = function () {
202 if (window.MathJax){
203 MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
204 }
202 utils.typeset(this.element);
205 203 };
206 204
207 205
@@ -577,19 +577,7 b' define(["widgets/js/manager",'
577 577 },
578 578
579 579 typeset: function(element, text){
580 // after (optionally) updating a node(list) or jQuery selection's
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 });
580 utils.typeset.apply(null, arguments);
593 581 },
594 582 });
595 583
General Comments 0
You need to be logged in to leave comments. Login now