mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 21:00:57 +00:00
Standardize: TO JSCS!
This commit is contained in:
44
js/loader.js
44
js/loader.js
@@ -2,7 +2,6 @@
|
||||
/* jshint unused:false */
|
||||
/* jshint -W061 */
|
||||
|
||||
|
||||
/* Magic Mirror
|
||||
* Module and File loaders.
|
||||
*
|
||||
@@ -18,10 +17,8 @@ var Loader = (function() {
|
||||
var loadedFiles = [];
|
||||
var moduleObjects = [];
|
||||
|
||||
|
||||
/* Private Methods */
|
||||
|
||||
|
||||
/* loadModules()
|
||||
* Loops thru all modules and requests load for every module.
|
||||
*/
|
||||
@@ -79,33 +76,31 @@ var Loader = (function() {
|
||||
var moduleData = modules[m];
|
||||
var module = moduleData.module;
|
||||
|
||||
var elements = module.split('/');
|
||||
var elements = module.split("/");
|
||||
var moduleName = elements[elements.length - 1];
|
||||
var moduleFolder = config.paths.modules + '/' + module;
|
||||
var moduleFolder = config.paths.modules + "/" + module;
|
||||
|
||||
if (defaultModules.indexOf(moduleName) !== -1) {
|
||||
moduleFolder = config.paths.modules + '/default/' + module;
|
||||
moduleFolder = config.paths.modules + "/default/" + module;
|
||||
}
|
||||
|
||||
moduleFiles.push({
|
||||
index: m,
|
||||
identifier: 'module_' + m + '_' + module,
|
||||
identifier: "module_" + m + "_" + module,
|
||||
name: moduleName,
|
||||
path: moduleFolder + '/' ,
|
||||
file: moduleName + '.js',
|
||||
path: moduleFolder + "/" ,
|
||||
file: moduleName + ".js",
|
||||
position: moduleData.position,
|
||||
header: moduleData.header,
|
||||
config: moduleData.config,
|
||||
classes: (typeof moduleData.classes !== 'undefined') ? moduleData.classes + ' ' + module : module
|
||||
classes: (typeof moduleData.classes !== "undefined") ? moduleData.classes + " " + module : module
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
return moduleFiles;
|
||||
};
|
||||
|
||||
|
||||
/* loadModule(module)
|
||||
* Load modules via ajax request and create module objects.
|
||||
*
|
||||
@@ -113,7 +108,7 @@ var Loader = (function() {
|
||||
* argument module object - Information about the module we want to load.
|
||||
*/
|
||||
var loadModule = function(module, callback) {
|
||||
var url = module.path + '/' + module.file;
|
||||
var url = module.path + "/" + module.file;
|
||||
|
||||
var afterLoad = function() {
|
||||
var moduleObject = Module.create(module.name);
|
||||
@@ -141,21 +136,20 @@ var Loader = (function() {
|
||||
* argument callback function - Function called when done.
|
||||
*/
|
||||
var bootstrapModule = function(module, mObj, callback) {
|
||||
Log.info('Bootstrapping module: ' + module.name);
|
||||
Log.info("Bootstrapping module: " + module.name);
|
||||
|
||||
mObj.setData(module);
|
||||
|
||||
mObj.loadScripts(function() {
|
||||
Log.log('Scripts loaded for: ' + module.name);
|
||||
mObj.loadStyles(function(){
|
||||
Log.log('Styles loaded for: ' + module.name);
|
||||
Log.log("Scripts loaded for: " + module.name);
|
||||
mObj.loadStyles(function() {
|
||||
Log.log("Styles loaded for: " + module.name);
|
||||
|
||||
moduleObjects.push(mObj);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
/* loadFile(fileName)
|
||||
@@ -170,27 +164,27 @@ var Loader = (function() {
|
||||
|
||||
switch (extension.toLowerCase()) {
|
||||
case "js":
|
||||
Log.log('Load script: ' + fileName);
|
||||
Log.log("Load script: " + fileName);
|
||||
|
||||
var script = document.createElement("script");
|
||||
script.type = "text/javascript";
|
||||
script.src = fileName;
|
||||
script.onload = function() {
|
||||
if (typeof callback === 'function') {callback();}
|
||||
if (typeof callback === "function") {callback();}
|
||||
};
|
||||
|
||||
document.getElementsByTagName("body")[0].appendChild(script);
|
||||
break;
|
||||
|
||||
case "css":
|
||||
Log.log('Load stylesheet: ' + fileName);
|
||||
Log.log("Load stylesheet: " + fileName);
|
||||
|
||||
var stylesheet = document.createElement("link");
|
||||
stylesheet.rel = "stylesheet";
|
||||
stylesheet.type = "text/css";
|
||||
stylesheet.href = fileName;
|
||||
stylesheet.onload = function() {
|
||||
if (typeof callback === 'function') {callback();}
|
||||
if (typeof callback === "function") {callback();}
|
||||
};
|
||||
|
||||
document.getElementsByTagName("head")[0].appendChild(stylesheet);
|
||||
@@ -220,12 +214,12 @@ var Loader = (function() {
|
||||
loadFile: function(fileName, module, callback) {
|
||||
|
||||
if (loadedFiles.indexOf(fileName.toLowerCase()) !== -1) {
|
||||
Log.log('File already loaded: ' + fileName);
|
||||
Log.log("File already loaded: " + fileName);
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
if (fileName.indexOf('http://') === 0 || fileName.indexOf('https://') === 0 || fileName.indexOf('/') !== -1) {
|
||||
if (fileName.indexOf("http://") === 0 || fileName.indexOf("https://") === 0 || fileName.indexOf("/") !== -1) {
|
||||
// This is an absolute or relative path.
|
||||
// Load it and then return.
|
||||
loadedFiles.push(fileName.toLowerCase());
|
||||
@@ -237,7 +231,7 @@ var Loader = (function() {
|
||||
// This file is available in the vendor folder.
|
||||
// Load it from this vendor folder.
|
||||
loadedFiles.push(fileName.toLowerCase());
|
||||
loadFile(config.paths.vendor+'/'+vendor[fileName], callback);
|
||||
loadFile(config.paths.vendor + "/" + vendor[fileName], callback);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user