Make MathJax a setting and load it only if enabled
This commit is contained in:
parent
5740c647d6
commit
be8ab42b7c
3 changed files with 45 additions and 15 deletions
|
@ -36,7 +36,8 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
'fontsize': '14px',
|
||||
'fontfamily': (utils.isMobileUi() ? 'sans-serif' : 'Inconsolata, Consolas, Monaco, Ubuntu Mono, monospace'),
|
||||
'readlineBindings': false,
|
||||
'enableJSEmoji': false
|
||||
'enableJSEmoji': false,
|
||||
'enableMathjax': false,
|
||||
});
|
||||
$scope.settings = settings;
|
||||
|
||||
|
@ -393,6 +394,30 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
|||
}
|
||||
});
|
||||
|
||||
// To prevent unnecessary loading times for users who don't
|
||||
// want MathJax, load it only if the setting is enabled.
|
||||
// This also fires when the page is loaded if enabled.
|
||||
settings.addCallback('enableMathjax', function(enabled) {
|
||||
if (enabled && !$rootScope.mathjax_init) {
|
||||
// Load MathJax only once
|
||||
$rootScope.mathjax_init = true;
|
||||
(function () {
|
||||
var head = document.getElementsByTagName("head")[0], script;
|
||||
script = document.createElement("script");
|
||||
script.type = "text/x-mathjax-config";
|
||||
script[(window.opera ? "innerHTML" : "text")] =
|
||||
"MathJax.Hub.Config({\n" +
|
||||
" tex2jax: { inlineMath: [['$$','$$'], ['\\\\(','\\\\)']], displayMath: [['\\\\[','\\\\]']] },\n" +
|
||||
"});";
|
||||
head.appendChild(script);
|
||||
script = document.createElement("script");
|
||||
script.type = "text/javascript";
|
||||
script.src = "//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML";
|
||||
head.appendChild(script);
|
||||
})();
|
||||
}
|
||||
});
|
||||
|
||||
// Update font family when changed
|
||||
settings.addCallback('fontfamily', function(fontfamily) {
|
||||
utils.changeClassStyle('favorite-font', 'fontFamily', fontfamily);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue