[mathjax] Add separate addon JS file

- Use new footer hook to register script files
This commit is contained in:
Hypolite Petovan 2018-09-20 21:08:03 -04:00
parent 02fe3efcdc
commit bdb856888d
2 changed files with 9 additions and 17 deletions

3
mathjax/mathjax.js Normal file
View file

@ -0,0 +1,3 @@
document.addEventListener('postprocess_liveupdate', function () {
MathJax.Hub.Queue(['Typeset', MathJax.Hub]);
});

View file

@ -1,7 +1,7 @@
<?php <?php
/** /**
* Name: MathJax * Name: MathJax
* Description: Addon for Friendika to include MathJax (LaTeX math syntax) * Description: Addon for Friendica to include MathJax (LaTeX math syntax)
* Version: 2.0 * Version: 2.0
* Author: Tobias Diekershoff <https://social.diekershoff.de/profile/tobias> * Author: Tobias Diekershoff <https://social.diekershoff.de/profile/tobias>
* Author: Hypolite Petovan <https://friendica.mrpetovan.com/profile/hypolite> * Author: Hypolite Petovan <https://friendica.mrpetovan.com/profile/hypolite>
@ -15,14 +15,14 @@ use Friendica\Core\PConfig;
function mathjax_install() 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' , __FILE__, 'mathjax_settings');
Addon::registerHook('addon_settings_post', __FILE__, 'mathjax_settings_post'); Addon::registerHook('addon_settings_post', __FILE__, 'mathjax_settings_post');
} }
function mathjax_uninstall() 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' , __FILE__, 'mathjax_settings');
Addon::unregisterHook('addon_settings_post', __FILE__, 'mathjax_settings_post'); Addon::unregisterHook('addon_settings_post', __FILE__, 'mathjax_settings_post');
@ -69,23 +69,12 @@ function mathjax_settings(App $a, &$s)
$s .= '</div>'; $s .= '</div>';
} }
/* we need to add one JavaScript include command to the html output function mathjax_footer(App $a, &$b)
* note that you have to check the jsmath/easy/load.js too.
*/
function mathjax_page_end(App $a, &$b)
{ {
// if the visitor of the page is not a local_user, use MathJax // if the visitor of the page is not a local_user, use MathJax
// otherwise check the users settings. // 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)) { if (!local_user() || PConfig::get(local_user(), 'mathjax', 'use', false)) {
$b .= <<<HTML $a->registerFooterScript(__DIR__ . '/asset/MathJax.js?config=TeX-MML-AM_CHTML');
<script type="text/javascript" src="{$url}"></script> $a->registerFooterScript(__DIR__ . '/mathjax.js');
<script type="text/javascript">
document.addEventListener('postprocess_liveupdate', function () {
MathJax.Hub.Queue(['Typeset', MathJax.Hub]);
});
</script>
HTML;
} }
} }