Added external css and js dependencies to module loader

This commit is contained in:
Paul-Vincent Roll
2016-01-27 21:40:04 +01:00
parent 5638d03c46
commit daa9664676
3 changed files with 50 additions and 5 deletions

View File

@@ -1,11 +1,36 @@
<?php
$modules = array_filter(glob('modules/*'), 'is_dir');
foreach ($modules as &$module) {
//Add JS file of module
print_r('<script src="'.$module.'/main.js" type="text/javascript"></script>'."\xA");
//Add CSS file of module
print_r('<link rel="stylesheet" type="text/css" href="'.$module.'/style.css">'."\xA");
//Load files to include
$include_files = include($module."/include.php");
//Add Javascript files
foreach ($include_files["js_files"] as $file) {
//Check if js file is hosted on a remote server
if (preg_match('#^https?://#i', $file) === 1) {
print_r('<script src="'.$file.'"></script>'."\xA");
}
//add local path to module folder
else{
print_r('<script src="modules/'.$module.'/'.$file.'"></script>'."\xA");
}
};
//Add CSS files
foreach ($include_files["css_files"] as $file) {
//Check if css file is hosted on a remote server
if (preg_match('#^https?://#i', $file) === 1) {
print_r('<link rel="stylesheet" type="text/css" href="'.$file.'">'."\xA");
}
//add local path to module folder
else{
print_r('<link rel="stylesheet" type="text/css" href="/modules/'.$module.'/'.$file.'">'."\xA");
}
};
//Get and add HTML Elements
print_r(file_get_contents($module.'/elements.html'));
//Add the modules JS file
print_r('<script src="'.$module.'/main.js" type="text/javascript"></script>'."\xA");
//Add the modules CSS file
print_r('<link rel="stylesheet" type="text/css" href="'.$module.'/style.css">'."\xA");
}
?>

View File

@@ -2,9 +2,16 @@ MagicMirror
===========
##Modules
A module has to contain three files: main.js, style.css and elements.html
A module has to contain four files: main.js, style.css, elements.html and include.php
Other files can be loaded from within those.
### include.php
If you happen to need any other css or js file from remote host or a local file you can add it in include.php.
It will be loaded before the plugins main javascript, the plugins css and the plugins elements.
Local files starting without http or https will be loaded from the root of the module folder.
If you have a file called test.js in your module just add test.js if you have the same file but in a folder called js inside your module folder add js/test.js. Same is valid for css files. Remote files will be loaded normally from the remote host, no need to specify anything.
### elements.html
Put your custom divs and other html elements in this file (don't include any body or header tags)

View File

@@ -0,0 +1,13 @@
<?php
//Local files starting without http or https will be loaded from the root of the module folder. If you have a file called test.js in your module just add test.js if you have the same file but in a folder called js inside your module folder add js/test.js. Same is valid for css files. Remote files will be loaded normally from the remote host, no need to specify anything.
return array(
'js_files' => array(
//"http://spiegel.local:1234/socket.io/socket.io.js",
//"js/somefile.js"
),
'css_files' => array(
//"css/randomfile.css",
//"https://example.com/test.css"
)
);
?>