]> git.mxchange.org Git - friendica-addons.git/blobdiff - highlightjs/highlightjs.php
IT translation update blackout addon THX Sylke Vicious
[friendica-addons.git] / highlightjs / highlightjs.php
index e8b5fe019bf04b49623b6ea3c6548df6ce433897..c46c26aed7bef7f628d198f940542aa94f2396de 100644 (file)
@@ -7,45 +7,28 @@
  */
 
 use Friendica\App;
-use Friendica\Core\Addon;
+use Friendica\Core\Hook;
+use Friendica\DI;
 
 function highlightjs_install()
 {
-       Addon::registerHook('page_end', __FILE__, 'highlightjs_page_end');
+       Hook::register('head'  , __FILE__, 'highlightjs_head');
+       Hook::register('footer', __FILE__, 'highlightjs_footer');
 }
 
-function highlightjs_uninstall()
+function highlightjs_head(App $a, &$b)
 {
-       Addon::unregisterHook('page_end', __FILE__, 'highlightjs_page_end');
-}
-
-function highlightjs_page_end(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>
+       DI::page()->registerStylesheet(__DIR__ . '/asset/styles/' . $style . '.css');
+}
 
-HTML;
+function highlightjs_footer(App $a, &$b)
+{
+       DI::page()->registerFooterScript(__DIR__ . '/asset/highlight.pack.js');
+       DI::page()->registerFooterScript(__DIR__ . '/highlightjs.js');
 }