Commit f4b91f7a authored by Phil Hughes's avatar Phil Hughes

Merge branch 'axios-get-render-math' into 'master'

Replace $.get in render math with axios

See merge request gitlab-org/gitlab-ce!16697
parents 078dac42 c41fffdb
...@@ -7,7 +7,12 @@ ...@@ -7,7 +7,12 @@
// //
// <code class="js-render-math"></div> // <code class="js-render-math"></div>
// //
// Only load once
import { __ } from './locale';
import axios from './lib/utils/axios_utils';
import flash from './flash';
// Only load once
let katexLoaded = false; let katexLoaded = false;
// Loop over all math elements and render math // Loop over all math elements and render math
...@@ -33,19 +38,26 @@ export default function renderMath($els) { ...@@ -33,19 +38,26 @@ export default function renderMath($els) {
if (katexLoaded) { if (katexLoaded) {
renderWithKaTeX($els); renderWithKaTeX($els);
} else { } else {
$.get(gon.katex_css_url, () => { axios.get(gon.katex_css_url)
.then(() => {
const css = $('<link>', { const css = $('<link>', {
rel: 'stylesheet', rel: 'stylesheet',
type: 'text/css', type: 'text/css',
href: gon.katex_css_url, href: gon.katex_css_url,
}); });
css.appendTo('head'); css.appendTo('head');
})
// Load KaTeX js .then(() => axios.get(gon.katex_js_url, {
$.getScript(gon.katex_js_url, () => { responseType: 'text',
}))
.then(({ data }) => {
// Add katex js to our document
$.globalEval(data);
})
.then(() => {
katexLoaded = true; katexLoaded = true;
renderWithKaTeX($els); // Run KaTeX renderWithKaTeX($els); // Run KaTeX
}); })
}); .catch(() => flash(__('An error occurred while rendering KaTeX')));
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment