]> git.mxchange.org Git - friendica-addons.git/commitdiff
[highlightjs] Use new 'head'/'footer' hooks
authorHypolite Petovan <mrpetovan@gmail.com>
Fri, 21 Sep 2018 01:32:47 +0000 (21:32 -0400)
committerHypolite Petovan <mrpetovan@gmail.com>
Fri, 21 Sep 2018 01:32:47 +0000 (21:32 -0400)
- Create separate addon javascript file
- Register stylesheet and Javascript files

highlightjs/highlightjs.js [new file with mode: 0644]
highlightjs/highlightjs.php

diff --git a/highlightjs/highlightjs.js b/highlightjs/highlightjs.js
new file mode 100644 (file)
index 0000000..b198c70
--- /dev/null
@@ -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);
+});
index e8b5fe019bf04b49623b6ea3c6548df6ce433897..8d05453b6b6d7ef219748d82da12ae4dccc905c6 100644 (file)
@@ -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
-
-<link rel="stylesheet" href="{$basedir}/styles/{$style}.css">
-
-HTML;
-
-       $b .= <<< HTML
-
-<script type="text/javascript" src="{$basedir}/highlight.pack.js"></script>
-<script type="text/javascript">
-       hljs.initHighlightingOnLoad();
-
-       document.addEventListener('postprocess_liveupdate', function () {
-               var blocks = document.querySelectorAll('pre code:not(.hljs)');
-               Array.prototype.forEach.call(blocks, hljs.highlightBlock);
-       });
-</script>
+       $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');
 }