From b5fe8d61dd14552d8e8673e79701ca1ba0850ea3 Mon Sep 17 00:00:00 2001 From: Pascal Deklerck Date: Thu, 7 Jun 2018 22:37:40 +0200 Subject: [PATCH 1/4] 5118 Implement MathJax JS hook to update contents after live update --- mathjax/mathjax.js | 5 +++++ mathjax/mathjax.php | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 mathjax/mathjax.js diff --git a/mathjax/mathjax.js b/mathjax/mathjax.js new file mode 100644 index 00000000..1ab5531b --- /dev/null +++ b/mathjax/mathjax.js @@ -0,0 +1,5 @@ +Addon_registerHook("postprocess","mathjax_postprocess_liveupdate"); +function mathjax_postprocess_liveupdate() +{ + MathJax.Hub.Queue(["Typeset",MathJax.Hub]); +} diff --git a/mathjax/mathjax.php b/mathjax/mathjax.php index 7d1a8134..37b2748c 100644 --- a/mathjax/mathjax.php +++ b/mathjax/mathjax.php @@ -16,12 +16,19 @@ function mathjax_install() { Addon::registerHook('page_header', 'addon/mathjax/mathjax.php', 'mathjax_page_header'); Addon::registerHook('addon_settings', 'addon/mathjax/mathjax.php', 'mathjax_settings'); Addon::registerHook('addon_settings_post', 'addon/mathjax/mathjax.php', 'mathjax_settings_post'); + Addon::registerHook('template_vars','addon/mathjax/mathjax.php', 'mathjax_template_vars'); logger('installed js_math addon'); } + +function mathjax_template_vars($a, &$arr) { + $arr['vars']['addon_hooks'][] = "mathjax"; +} + function mathjax_uninstall() { Addon::unregisterHook('page_header', 'addon/mathjax/mathjax.php', 'mathjax_page_header'); Addon::unregisterHook('addon_settings', 'addon/mathjax/mathjax.php', 'mathjax_settings'); Addon::unregisterHook('addon_settings_post', 'addon/mathjax/mathjax.php', 'mathjax_settings_post'); + Addon::unregisterHook('template_vars','addon/mathjax/mathjax.php', 'mathjax_template_vars'); } function mathjax_settings_post ($a, $post) { if (! local_user()) From fd894984cf3692e682034f410e11553aa970c9cd Mon Sep 17 00:00:00 2001 From: Pascal Deklerck Date: Wed, 13 Jun 2018 09:06:14 +0200 Subject: [PATCH 2/4] Code standards update for mathjax add-on changes (5118) --- mathjax/mathjax.js | 4 ++-- mathjax/mathjax.php | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mathjax/mathjax.js b/mathjax/mathjax.js index 1ab5531b..686f21bb 100644 --- a/mathjax/mathjax.js +++ b/mathjax/mathjax.js @@ -1,5 +1,5 @@ -Addon_registerHook("postprocess","mathjax_postprocess_liveupdate"); +Addon_registerHook("postprocess_liveupdate", "mathjax_postprocess_liveupdate"); function mathjax_postprocess_liveupdate() { - MathJax.Hub.Queue(["Typeset",MathJax.Hub]); + MathJax.Hub.Queue(["Typeset", MathJax.Hub]); } diff --git a/mathjax/mathjax.php b/mathjax/mathjax.php index 37b2748c..ebc49d98 100644 --- a/mathjax/mathjax.php +++ b/mathjax/mathjax.php @@ -16,20 +16,21 @@ function mathjax_install() { Addon::registerHook('page_header', 'addon/mathjax/mathjax.php', 'mathjax_page_header'); Addon::registerHook('addon_settings', 'addon/mathjax/mathjax.php', 'mathjax_settings'); Addon::registerHook('addon_settings_post', 'addon/mathjax/mathjax.php', 'mathjax_settings_post'); - Addon::registerHook('template_vars','addon/mathjax/mathjax.php', 'mathjax_template_vars'); + Addon::registerHook('template_vars', 'addon/mathjax/mathjax.php', 'mathjax_template_vars'); logger('installed js_math addon'); } -function mathjax_template_vars($a, &$arr) { - $arr['vars']['addon_hooks'][] = "mathjax"; -} - function mathjax_uninstall() { Addon::unregisterHook('page_header', 'addon/mathjax/mathjax.php', 'mathjax_page_header'); Addon::unregisterHook('addon_settings', 'addon/mathjax/mathjax.php', 'mathjax_settings'); Addon::unregisterHook('addon_settings_post', 'addon/mathjax/mathjax.php', 'mathjax_settings_post'); Addon::unregisterHook('template_vars','addon/mathjax/mathjax.php', 'mathjax_template_vars'); } + +function mathjax_template_vars($a, &$arr) { + $arr['vars']['addon_hooks'][] = "mathjax"; +} + function mathjax_settings_post ($a, $post) { if (! local_user()) return; From d48f0010dd50718fc0f974eae40aadf34fc02c2f Mon Sep 17 00:00:00 2001 From: Pascal Deklerck Date: Wed, 13 Jun 2018 09:09:33 +0200 Subject: [PATCH 3/4] Another code standards update for mathjax add-on changes (5118) --- mathjax/mathjax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathjax/mathjax.php b/mathjax/mathjax.php index ebc49d98..6f4dd395 100644 --- a/mathjax/mathjax.php +++ b/mathjax/mathjax.php @@ -24,7 +24,7 @@ function mathjax_uninstall() { Addon::unregisterHook('page_header', 'addon/mathjax/mathjax.php', 'mathjax_page_header'); Addon::unregisterHook('addon_settings', 'addon/mathjax/mathjax.php', 'mathjax_settings'); Addon::unregisterHook('addon_settings_post', 'addon/mathjax/mathjax.php', 'mathjax_settings_post'); - Addon::unregisterHook('template_vars','addon/mathjax/mathjax.php', 'mathjax_template_vars'); + Addon::unregisterHook('template_vars', 'addon/mathjax/mathjax.php', 'mathjax_template_vars'); } function mathjax_template_vars($a, &$arr) { From 7ef81f909fc04e261a7c04d4822d79dd7fce6e65 Mon Sep 17 00:00:00 2001 From: Pascal Deklerck Date: Wed, 13 Jun 2018 21:57:59 +0200 Subject: [PATCH 4/4] Defensive code for the case when addon_hooks key does not exist --- mathjax/mathjax.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mathjax/mathjax.php b/mathjax/mathjax.php index 6f4dd395..91a6a066 100644 --- a/mathjax/mathjax.php +++ b/mathjax/mathjax.php @@ -27,7 +27,12 @@ function mathjax_uninstall() { Addon::unregisterHook('template_vars', 'addon/mathjax/mathjax.php', 'mathjax_template_vars'); } -function mathjax_template_vars($a, &$arr) { +function mathjax_template_vars($a, &$arr) +{ + if (!array_key_exists('addon_hooks',$arr['vars'])) + { + $arr['vars']['addon_hooks'] = array(); + } $arr['vars']['addon_hooks'][] = "mathjax"; }