From bdb856888da23cc62553d005f5d7ab0c2251b341 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 20 Sep 2018 21:08:03 -0400 Subject: [PATCH] [mathjax] Add separate addon JS file - Use new footer hook to register script files --- mathjax/mathjax.js | 3 +++ mathjax/mathjax.php | 23 ++++++----------------- 2 files changed, 9 insertions(+), 17 deletions(-) create mode 100644 mathjax/mathjax.js diff --git a/mathjax/mathjax.js b/mathjax/mathjax.js new file mode 100644 index 00000000..6642ee29 --- /dev/null +++ b/mathjax/mathjax.js @@ -0,0 +1,3 @@ +document.addEventListener('postprocess_liveupdate', function () { + MathJax.Hub.Queue(['Typeset', MathJax.Hub]); +}); diff --git a/mathjax/mathjax.php b/mathjax/mathjax.php index 83f0405a..a4e8fe05 100644 --- a/mathjax/mathjax.php +++ b/mathjax/mathjax.php @@ -1,7 +1,7 @@ * Author: Hypolite Petovan @@ -15,14 +15,14 @@ use Friendica\Core\PConfig; function mathjax_install() { - Addon::registerHook('page_end' , __FILE__, 'mathjax_page_end'); + Addon::registerHook('footer' , __FILE__, 'mathjax_footer'); Addon::registerHook('addon_settings' , __FILE__, 'mathjax_settings'); Addon::registerHook('addon_settings_post', __FILE__, 'mathjax_settings_post'); } function mathjax_uninstall() { - Addon::unregisterHook('page_end' , __FILE__, 'mathjax_page_end'); + Addon::unregisterHook('footer' , __FILE__, 'mathjax_footer'); Addon::unregisterHook('addon_settings' , __FILE__, 'mathjax_settings'); Addon::unregisterHook('addon_settings_post', __FILE__, 'mathjax_settings_post'); @@ -69,23 +69,12 @@ function mathjax_settings(App $a, &$s) $s .= ''; } -/* we need to add one JavaScript include command to the html output - * note that you have to check the jsmath/easy/load.js too. - */ -function mathjax_page_end(App $a, &$b) +function mathjax_footer(App $a, &$b) { // if the visitor of the page is not a local_user, use MathJax // otherwise check the users settings. - $url = $a->get_baseurl() . '/addon/mathjax/asset/MathJax.js?config=TeX-MML-AM_CHTML'; - if (!local_user() || PConfig::get(local_user(), 'mathjax', 'use', false)) { - $b .= << - -HTML; + $a->registerFooterScript(__DIR__ . '/asset/MathJax.js?config=TeX-MML-AM_CHTML'); + $a->registerFooterScript(__DIR__ . '/mathjax.js'); } }