From daa9664676fd1e646f08cb51a081b6a058318d77 Mon Sep 17 00:00:00 2001 From: Paul-Vincent Roll Date: Wed, 27 Jan 2016 21:40:04 +0100 Subject: [PATCH] Added external css and js dependencies to module loader --- controllers/modules.php | 33 +++++++++++++++++++++++++++++---- modules/README.md | 9 ++++++++- modules/test-module/include.php | 13 +++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 modules/test-module/include.php diff --git a/controllers/modules.php b/controllers/modules.php index 8477cc48..63d966c0 100644 --- a/controllers/modules.php +++ b/controllers/modules.php @@ -1,11 +1,36 @@ '."\xA"); - //Add CSS file of module - print_r(''."\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(''."\xA"); + } + //add local path to module folder + else{ + print_r(''."\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(''."\xA"); + } + //add local path to module folder + else{ + print_r(''."\xA"); + } + }; + //Get and add HTML Elements print_r(file_get_contents($module.'/elements.html')); + //Add the modules JS file + print_r(''."\xA"); + //Add the modules CSS file + print_r(''."\xA"); } ?> \ No newline at end of file diff --git a/modules/README.md b/modules/README.md index ef5c8ed9..7ce11bec 100644 --- a/modules/README.md +++ b/modules/README.md @@ -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) diff --git a/modules/test-module/include.php b/modules/test-module/include.php new file mode 100644 index 00000000..de275f93 --- /dev/null +++ b/modules/test-module/include.php @@ -0,0 +1,13 @@ + array( + //"http://spiegel.local:1234/socket.io/socket.io.js", + //"js/somefile.js" + ), + 'css_files' => array( + //"css/randomfile.css", + //"https://example.com/test.css" + ) +); +?> \ No newline at end of file