From: Hypolite Petovan Date: Fri, 21 Sep 2018 01:32:47 +0000 (-0400) Subject: [highlightjs] Use new 'head'/'footer' hooks X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=27a48ae84a5452ad74f610c4c039b043fc12d20d;p=friendica-addons.git [highlightjs] Use new 'head'/'footer' hooks - Create separate addon javascript file - Register stylesheet and Javascript files --- diff --git a/highlightjs/highlightjs.js b/highlightjs/highlightjs.js new file mode 100644 index 00000000..b198c705 --- /dev/null +++ b/highlightjs/highlightjs.js @@ -0,0 +1,6 @@ +hljs.initHighlightingOnLoad(); + +document.addEventListener('postprocess_liveupdate', function () { + var blocks = document.querySelectorAll('pre code:not(.hljs)'); + Array.prototype.forEach.call(blocks, hljs.highlightBlock); +}); diff --git a/highlightjs/highlightjs.php b/highlightjs/highlightjs.php index e8b5fe01..8d05453b 100644 --- a/highlightjs/highlightjs.php +++ b/highlightjs/highlightjs.php @@ -11,41 +11,29 @@ use Friendica\Core\Addon; function highlightjs_install() { - Addon::registerHook('page_end', __FILE__, 'highlightjs_page_end'); + Addon::registerHook('head' , __FILE__, 'highlightjs_head'); + Addon::registerHook('footer', __FILE__, 'highlightjs_footer'); } function highlightjs_uninstall() { - Addon::unregisterHook('page_end', __FILE__, 'highlightjs_page_end'); + Addon::unregisterHook('head' , __FILE__, 'highlightjs_head'); + Addon::unregisterHook('footer', __FILE__, 'highlightjs_footer'); } -function highlightjs_page_end(App $a, &$b) +function highlightjs_head(App $a, &$b) { - $basedir = $a->get_baseurl() . '/addon/highlightjs/asset'; - if ($a->getCurrentTheme() == 'frio') { $style = 'bootstrap'; } else { $style = 'default'; } - $a->page['htmlhead'] .= <<< HTML - - - -HTML; - - $b .= <<< HTML - - - + $a->registerStylesheet(__DIR__ . '/asset/styles/' . $style . '.css'); +} -HTML; +function highlightjs_footer(App $a, &$b) +{ + $a->registerFooterScript(__DIR__ . '/asset/highlight.pack.js'); + $a->registerFooterScript(__DIR__ . '/highlightjs.js'); }