-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-assets.php
58 lines (49 loc) · 1.54 KB
/
custom-assets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
/**
* Class CustomCSSPlugin
* @package Grav\Plugin
*/
class CustomAssetsPlugin extends Plugin
{
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0],
'onPageInitialized' => ['onPageInitialized', 0],
];
}
/**
* Initialize the plugin
*/
public function onPluginsInitialized()
{
// Don't proceed if we are in the admin plugin
if ($this->isAdmin()) {
return;
}
$this->enable([
'onAssetsInitialized' => ['onAssetsInitialized', 0]
]);
}
public function onAssetsInitialized()
{
$this->grav['assets']->addInlineCss($this->config->get('plugins.custom-assets.css_inline'));
foreach($this->config->get('plugins.custom-assets.css_files', []) as $file) {
$this->grav['assets']->add($file['path'], isset($file['priority']) ? $file['priority'] : null);
}
}
public function onPageInitialized()
{
if ($this->grav['uri']->path() === '/admin/plugins/custom-assets') {
$this->grav['assets']->addJs('plugin://custom-assets/js/autocomplete.js', ['loading' => 'defer']);
$this->grav['assets']->addCss('plugin://custom-assets/css/autocomplete.css');
$this->grav['assets']->addJs('plugin://custom-assets/js/app.js', 2);
}
}
}