forked from getgrav/grav-plugin-bootstrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrapper.php
More file actions
85 lines (75 loc) · 2.56 KB
/
bootstrapper.php
File metadata and controls
85 lines (75 loc) · 2.56 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Grav\Plugin;
use \Grav\Common\Plugin;
use \Grav\Common\Grav;
use \Grav\Common\Page\Page;
class BootstrapperPlugin extends Plugin
{
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onThemeInitialized' => ['onThemeInitialized', 0]
];
}
/**
* Initialize configuration
*/
public function onThemeInitialized()
{
if ($this->isAdmin()) {
return;
}
$load_events = false;
// if not always_load see if the theme expects to load bootstrap plugin
if (!$this->config->get('plugins.bootstrapper.always_load')) {
$theme = $this->grav['theme'];
if (isset($theme->load_bootstrapper_plugin) && $theme->load_bootstrapper_plugin) {
$load_events = true;
}
} else {
$load_events = true;
}
if ($load_events) {
$this->enable([
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
]);
}
}
/**
* if enabled on this page, load the JS + CSS and set the selectors.
*/
public function onTwigSiteVariables()
{
$config = $this->config->get('plugins.bootstrapper');
$mode = $config['mode'] == 'production' ? '.min' : '';
$bootstrap_bits = [];
$currentVersion = '3.3.7';
if ($config['use_cdn']) {
if ($config['load_core_css']) {
$bootstrap_bits[] = "https://maxcdn.bootstrapcdn.com/bootstrap/{$currentVersion}/css/bootstrap{$mode}.css";
}
if ($config['load_theme_css']) {
$bootstrap_bits[] = "https://maxcdn.bootstrapcdn.com/bootstrap/{$currentVersion}/css/bootstrap-theme{$mode}.css";
}
if ($config['load_core_js']) {
$bootstrap_bits[] = "https://maxcdn.bootstrapcdn.com/bootstrap/{$currentVersion}/js/bootstrap{$mode}.js";
}
} else {
if ($config['load_core_css']) {
$bootstrap_bits[] = "plugin://bootstrapper/css/bootstrap{$mode}.css";
}
if ($config['load_theme_css']) {
$bootstrap_bits[] = "plugin://bootstrapper/css/bootstrap-theme{$mode}.css";
}
if ($config['load_core_js']) {
$bootstrap_bits[] = "plugin://bootstrapper/js/bootstrap{$mode}.js";
}
}
$assets = $this->grav['assets'];
$assets->registerCollection('bootstrap', $bootstrap_bits);
$assets->add('bootstrap', 100);
}
}