| 1 |
/* vim:fileencoding=utf-8 |
| 2 |
* |
| 3 |
* Copyright (C) 2019 Kovid Goyal <kovid at kovidgoyal.net> |
| 4 |
* |
| 5 |
* Distributed under terms of the GPLv3 license |
| 6 |
*/ |
| 7 |
/*jshint esversion: 6 */ |
| 8 |
|
| 9 |
(function() { |
| 10 |
"use strict"; |
| 11 |
var base = document.currentScript ? document.currentScript.getAttribute('data-mathjax-path') : null; |
| 12 |
var for_pdf_renderer = !!base; |
| 13 |
|
| 14 |
function on_mathjax_finish() { |
| 15 |
if (for_pdf_renderer) document.title = "mathjax-load-complete"; |
| 16 |
else document.documentElement.dispatchEvent(new CustomEvent("calibre-mathjax-typeset-done")); |
| 17 |
} |
| 18 |
// also do any changes in mathjax.pyj for the in-browser reader |
| 19 |
window.MathJax = {}; |
| 20 |
window.MathJax.options = { |
| 21 |
renderActions: { |
| 22 |
// disable the mathjax context menu |
| 23 |
addMenu: [0, '', ''], |
| 24 |
}, |
| 25 |
}; |
| 26 |
window.MathJax.loader = { |
| 27 |
load: ['input/tex-full', 'input/asciimath', 'input/mml', 'output/chtml'], |
| 28 |
}; |
| 29 |
window.MathJax.startup = { |
| 30 |
ready: () => { |
| 31 |
MathJax.startup.defaultReady(); |
| 32 |
MathJax.startup.promise.then(on_mathjax_finish); |
| 33 |
}, |
| 34 |
}; |
| 35 |
for (const s of document.scripts) { |
| 36 |
if (s.type === "text/x-mathjax-config") { |
| 37 |
var es = document.createElement('script'); |
| 38 |
es.text = s.text; |
| 39 |
document.head.appendChild(es); |
| 40 |
document.head.removeChild(es); |
| 41 |
} |
| 42 |
} |
| 43 |
if (for_pdf_renderer) { |
| 44 |
if (!base.endsWith('/')) base += '/'; |
| 45 |
var script = document.createElement('script'); |
| 46 |
script.type = 'text/javascript'; |
| 47 |
script.setAttribute('async', 'async'); |
| 48 |
script.onerror = function (ev) { |
| 49 |
console.log('Failed to load MathJax script: ' + ev.target.src); |
| 50 |
}; |
| 51 |
script.src = base + 'startup.js'; |
| 52 |
document.head.appendChild(script); |
| 53 |
} |
| 54 |
})(); |