diff options
author | Simon Rettberg | 2017-05-10 17:36:05 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-05-10 17:36:05 +0200 |
commit | 47657731433248410e681640b2a53c0783651134 (patch) | |
tree | 3ee31a268b89ec154be6169c0139067f066495c0 /inc/module.inc.php | |
parent | [locationinfo] install: Match table column type to referenced table (diff) | |
download | slx-admin-47657731433248410e681640b2a53c0783651134.tar.gz slx-admin-47657731433248410e681640b2a53c0783651134.tar.xz slx-admin-47657731433248410e681640b2a53c0783651134.zip |
Add support to declare multiple css/js per module with loading condition:
A css/js can be declared to only load if the module in question is the
page module being rendered, or to always be loaded even if the module
is just a dependency. The second case is useful for plugin type
modules. See one of the config.json files updated in this commit on
how to specify css/js to load. true = always load, false = only if page
module.
Diffstat (limited to 'inc/module.inc.php')
-rw-r--r-- | inc/module.inc.php | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/inc/module.inc.php b/inc/module.inc.php index 597cfb57..52646983 100644 --- a/inc/module.inc.php +++ b/inc/module.inc.php @@ -142,13 +142,23 @@ class Module private $activated = false; private $dependencies = array(); private $name; + /** + * @var array assoc list of 'filename.css' => true|false (true = always load, false = only if module is main module) + */ + private $css = array(); + /** + * @var array assoc list of 'filename.js' => true|false (true = always load, false = only if module is main module) + */ + private $scripts = array(); private function __construct($name) { $file = 'modules/' . $name . '/config.json'; $json = @json_decode(@file_get_contents($file), true); - if (isset($json['dependencies']) && is_array($json['dependencies'])) { - $this->dependencies = $json['dependencies']; + foreach (['dependencies', 'css', 'scripts'] as $key) { + if (isset($json[$key]) && is_array($json[$key])) { + $this->$key = $json[$key]; + } } if (isset($json['category']) && is_string($json['category'])) { $this->category = $json['category']; @@ -251,4 +261,29 @@ class Module return 'modules/' . $this->name; } + public function getScripts($externalOnly) + { + error_log($this->getIdentifier() . ' = ' . ($externalOnly ? 'true' : 'false')); + if (!$externalOnly) { + if (!isset($this->scripts['clientscript.js']) && file_exists($this->getDir() . '/clientscript.js')) { + $this->scripts['clientscript.js'] = false; + } + return array_keys($this->scripts); + } + error_log('Pre: ' . implode(', ', array_keys($this->scripts))); + error_log('Post: ' . implode(', ', array_keys(array_filter($this->scripts)))); + return array_keys(array_filter($this->scripts)); + } + + public function getCss($externalOnly) + { + if (!$externalOnly) { + if (!isset($this->css['style.css']) && file_exists($this->getDir() . '/style.css')) { + $this->css['style.css'] = false; + } + return array_keys($this->css); + } + return array_keys(array_filter($this->css)); + } + } |