mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2024-11-21 21:23:40 +00:00
[highlightjs] Use new 'head'/'footer' hooks
- Create separate addon javascript file - Register stylesheet and Javascript files
This commit is contained in:
parent
0afab99d84
commit
27a48ae84a
2 changed files with 18 additions and 24 deletions
6
highlightjs/highlightjs.js
Normal file
6
highlightjs/highlightjs.js
Normal file
|
@ -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);
|
||||||
|
});
|
|
@ -11,41 +11,29 @@ use Friendica\Core\Addon;
|
||||||
|
|
||||||
function highlightjs_install()
|
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()
|
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') {
|
if ($a->getCurrentTheme() == 'frio') {
|
||||||
$style = 'bootstrap';
|
$style = 'bootstrap';
|
||||||
} else {
|
} else {
|
||||||
$style = 'default';
|
$style = 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
$a->page['htmlhead'] .= <<< HTML
|
$a->registerStylesheet(__DIR__ . '/asset/styles/' . $style . '.css');
|
||||||
|
}
|
||||||
<link rel="stylesheet" href="{$basedir}/styles/{$style}.css">
|
|
||||||
|
function highlightjs_footer(App $a, &$b)
|
||||||
HTML;
|
{
|
||||||
|
$a->registerFooterScript(__DIR__ . '/asset/highlight.pack.js');
|
||||||
$b .= <<< HTML
|
$a->registerFooterScript(__DIR__ . '/highlightjs.js');
|
||||||
|
|
||||||
<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>
|
|
||||||
|
|
||||||
HTML;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue