Merge pull request #6948 from bollwyvl/graceful-mathjax-widgets

Ignore failure of widget MathJax typesetting
Min RK 11 years ago
commit befb16ebe3

@ -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.

@ -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);
};
/**

@ -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);
};

@ -387,7 +387,7 @@ define(["widgets/js/manager",
} else {
this.on('displayed', callback, context);
}
},
}
});
@ -574,6 +574,10 @@ define(["widgets/js/manager",
}
return elements;
},
typeset: function(element, text){
utils.typeset.apply(null, arguments);
},
});

@ -62,8 +62,7 @@ define([
if (description.trim().length === 0) {
this.$label.hide();
} else {
this.$label.text(description);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
this.typeset(this.$label, description);
this.$label.show();
}
}

@ -319,8 +319,7 @@ define([
if (description.trim().length === 0) {
this.$title.html(" "); // Preserve title height
} else {
this.$title.text(description);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$title.get(0)]);
this.typeset(this.$title, description);
}
var button_text = this.model.get('button_text');

@ -155,8 +155,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
this.$label.text(description);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
this.typeset(this.$label, description);
this.$label.show();
}
@ -323,8 +322,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
this.$label.text(description);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
this.typeset(this.$label, description);
this.$label.show();
}
}
@ -443,8 +441,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
this.$label.text(description);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
this.typeset(this.$label, description);
this.$label.show();
}
return ProgressView.__super__.update.apply(this);

@ -97,8 +97,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
this.$label.text(description);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
this.typeset(this.$label, description);
this.$label.show();
}
}
@ -231,7 +230,7 @@ define([
this.$label.hide();
} else {
this.$label.text(description);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
this.typeset(this.$label, description);
this.$label.show();
}
}
@ -345,8 +344,8 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
this.$label.text(description);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
this.$label.text();
this.typeset(this.$label, description);
this.$label.show();
}
}
@ -468,8 +467,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
this.$label.text(description);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
this.typeset(this.$label, description);
this.$label.show();
}
}

@ -43,9 +43,7 @@ define([
* Called when the model is changed. The model may have been
* changed by another view or by a state update from the back-end.
*/
this.$el.text(this.model.get('value'));
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$el.get(0)]);
this.typeset(this.$el, this.model.get('value'));
return LatexView.__super__.update.apply(this);
},
});
@ -116,8 +114,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
this.$label.text(description);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
this.typeset(this.$label, description);
this.$label.show();
}
}
@ -200,8 +197,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
this.$label.text(description);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
this.typeset(this.$label, description);
this.$label.show();
}
}

Loading…
Cancel
Save