mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Standardize: TO JSCS!
This commit is contained in:
92
js/class.js
92
js/class.js
@@ -4,66 +4,66 @@
|
||||
*/
|
||||
|
||||
// Inspired by base2 and Prototype
|
||||
(function(){
|
||||
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
||||
(function() {
|
||||
var initializing = false;
|
||||
var fnTest = /xyz/.test(function() {xyz;}) ? /\b_super\b/ : /.*/;
|
||||
|
||||
// The base Class implementation (does nothing)
|
||||
this.Class = function(){};
|
||||
// The base Class implementation (does nothing)
|
||||
this.Class = function() {};
|
||||
|
||||
// Create a new Class that inherits from this class
|
||||
Class.extend = function(prop) {
|
||||
var _super = this.prototype;
|
||||
// Create a new Class that inherits from this class
|
||||
Class.extend = function(prop) {
|
||||
var _super = this.prototype;
|
||||
|
||||
// Instantiate a base class (but only create the instance,
|
||||
// don't run the init constructor)
|
||||
initializing = true;
|
||||
var prototype = new this();
|
||||
initializing = false;
|
||||
// Instantiate a base class (but only create the instance,
|
||||
// don't run the init constructor)
|
||||
initializing = true;
|
||||
var prototype = new this();
|
||||
initializing = false;
|
||||
|
||||
// Copy the properties over onto the new prototype
|
||||
for (var name in prop) {
|
||||
// Check if we're overwriting an existing function
|
||||
prototype[name] = typeof prop[name] == "function" &&
|
||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||
(function(name, fn){
|
||||
return function() {
|
||||
var tmp = this._super;
|
||||
// Copy the properties over onto the new prototype
|
||||
for (var name in prop) {
|
||||
// Check if we're overwriting an existing function
|
||||
prototype[name] = typeof prop[name] == "function" &&
|
||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||
(function(name, fn) {
|
||||
return function() {
|
||||
var tmp = this._super;
|
||||
|
||||
// Add a new ._super() method that is the same method
|
||||
// but on the super-class
|
||||
this._super = _super[name];
|
||||
// Add a new ._super() method that is the same method
|
||||
// but on the super-class
|
||||
this._super = _super[name];
|
||||
|
||||
// The method only need to be bound temporarily, so we
|
||||
// remove it when we're done executing
|
||||
var ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
// The method only need to be bound temporarily, so we
|
||||
// remove it when we're done executing
|
||||
var ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
|
||||
return ret;
|
||||
};
|
||||
return ret;
|
||||
};
|
||||
})(name, prop[name]) :
|
||||
prop[name];
|
||||
}
|
||||
}
|
||||
|
||||
// The dummy class constructor
|
||||
function Class() {
|
||||
// All construction is actually done in the init method
|
||||
if ( !initializing && this.init )
|
||||
this.init.apply(this, arguments);
|
||||
}
|
||||
// The dummy class constructor
|
||||
function Class() {
|
||||
// All construction is actually done in the init method
|
||||
if (!initializing && this.init)
|
||||
this.init.apply(this, arguments);
|
||||
}
|
||||
|
||||
// Populate our constructed prototype object
|
||||
Class.prototype = prototype;
|
||||
// Populate our constructed prototype object
|
||||
Class.prototype = prototype;
|
||||
|
||||
// Enforce the constructor to be what we expect
|
||||
Class.prototype.constructor = Class;
|
||||
// Enforce the constructor to be what we expect
|
||||
Class.prototype.constructor = Class;
|
||||
|
||||
// And make this class extendable
|
||||
Class.extend = arguments.callee;
|
||||
// And make this class extendable
|
||||
Class.extend = arguments.callee;
|
||||
|
||||
return Class;
|
||||
};
|
||||
return Class;
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== 'undefined') {module.exports = Class;}
|
||||
if (typeof module !== "undefined") {module.exports = Class;}
|
||||
|
@@ -10,49 +10,48 @@
|
||||
var defaults = {
|
||||
port: 8080,
|
||||
|
||||
language: 'en',
|
||||
language: "en",
|
||||
timeFormat: 24,
|
||||
|
||||
modules: [
|
||||
{
|
||||
module: 'helloworld',
|
||||
position: 'upper_third',
|
||||
module: "helloworld",
|
||||
position: "upper_third",
|
||||
config: {
|
||||
text: 'Magic Mirror V2',
|
||||
classes: 'large thin'
|
||||
text: "Magic Mirror V2",
|
||||
classes: "large thin"
|
||||
}
|
||||
},
|
||||
{
|
||||
module: 'helloworld',
|
||||
position: 'middle_center',
|
||||
module: "helloworld",
|
||||
position: "middle_center",
|
||||
config: {
|
||||
text: 'Please create a config file.'
|
||||
text: "Please create a config file."
|
||||
}
|
||||
},
|
||||
{
|
||||
module: 'helloworld',
|
||||
position: 'middle_center',
|
||||
module: "helloworld",
|
||||
position: "middle_center",
|
||||
config: {
|
||||
text: 'See README for more information.',
|
||||
classes: 'small dimmed'
|
||||
text: "See README for more information.",
|
||||
classes: "small dimmed"
|
||||
}
|
||||
},
|
||||
{
|
||||
module: 'helloworld',
|
||||
position: 'bottom_bar',
|
||||
module: "helloworld",
|
||||
position: "bottom_bar",
|
||||
config: {
|
||||
text: 'www.michaelteeuw.nl',
|
||||
classes: 'xsmall dimmed'
|
||||
text: "www.michaelteeuw.nl",
|
||||
classes: "xsmall dimmed"
|
||||
}
|
||||
},
|
||||
],
|
||||
|
||||
paths: {
|
||||
modules: 'modules',
|
||||
vendor: 'vendor'
|
||||
modules: "modules",
|
||||
vendor: "vendor"
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== 'undefined') {module.exports = defaults;}
|
||||
if (typeof module !== "undefined") {module.exports = defaults;}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
//load modules
|
||||
const walk = require('walk');
|
||||
const fs = require('fs');
|
||||
const Server = require(__dirname + '/server.js');
|
||||
const spawn = require('child_process').spawn;
|
||||
const electron = require('electron');
|
||||
const defaultModules = require(__dirname + '/../modules/default/defaultmodules.js');
|
||||
const path = require('path');
|
||||
const walk = require("walk");
|
||||
const fs = require("fs");
|
||||
const Server = require(__dirname + "/server.js");
|
||||
const spawn = require("child_process").spawn;
|
||||
const electron = require("electron");
|
||||
const defaultModules = require(__dirname + "/../modules/default/defaultmodules.js");
|
||||
const path = require("path");
|
||||
|
||||
// Config
|
||||
var config = {};
|
||||
@@ -22,19 +22,19 @@ var nodeHelpers = [];
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainWindow;
|
||||
|
||||
function createWindow () {
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({width: 800, height: 600, fullscreen: true, autoHideMenuBar: true, webPreferences: {nodeIntegration: false}});
|
||||
|
||||
// and load the index.html of the app.
|
||||
//mainWindow.loadURL('file://' + __dirname + '../../index.html');
|
||||
mainWindow.loadURL('http://localhost:' + config.port);
|
||||
mainWindow.loadURL("http://localhost:" + config.port);
|
||||
|
||||
// Open the DevTools.
|
||||
//mainWindow.webContents.openDevTools();
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', function() {
|
||||
mainWindow.on("closed", function() {
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
@@ -42,36 +42,36 @@ function createWindow () {
|
||||
});
|
||||
}
|
||||
|
||||
function loadConfig (callback) {
|
||||
function loadConfig(callback) {
|
||||
console.log("Loading config ...");
|
||||
var defaults = require(__dirname + '/defaults.js');
|
||||
var configFilename = __dirname + '/../config/config.js';
|
||||
var defaults = require(__dirname + "/defaults.js");
|
||||
var configFilename = __dirname + "/../config/config.js";
|
||||
|
||||
try {
|
||||
fs.accessSync(configFilename, fs.R_OK);
|
||||
var c = require(configFilename);
|
||||
fs.accessSync(configFilename, fs.R_OK);
|
||||
var c = require(configFilename);
|
||||
var config = Object.assign(defaults, c);
|
||||
callback(config);
|
||||
} catch (e) {
|
||||
callback(defaults);
|
||||
callback(defaults);
|
||||
}
|
||||
}
|
||||
|
||||
function loadModule(module) {
|
||||
|
||||
var elements = module.split('/');
|
||||
var elements = module.split("/");
|
||||
var moduleName = elements[elements.length - 1];
|
||||
var moduleFolder = __dirname + '/../modules/' + module;
|
||||
var moduleFolder = __dirname + "/../modules/" + module;
|
||||
|
||||
if (defaultModules.indexOf(moduleName) !== -1) {
|
||||
moduleFolder = __dirname + '/../modules/default/' + module;
|
||||
moduleFolder = __dirname + "/../modules/default/" + module;
|
||||
}
|
||||
|
||||
var helperPath = moduleFolder + '/node_helper.js';
|
||||
var helperPath = moduleFolder + "/node_helper.js";
|
||||
|
||||
var loadModule = true;
|
||||
try {
|
||||
fs.accessSync(helperPath, fs.R_OK);
|
||||
fs.accessSync(helperPath, fs.R_OK);
|
||||
} catch (e) {
|
||||
loadModule = false;
|
||||
console.log("No helper found for module: " + moduleName + ".");
|
||||
@@ -80,9 +80,9 @@ function loadModule(module) {
|
||||
if (loadModule) {
|
||||
var Module = require(helperPath);
|
||||
var m = new Module();
|
||||
m.setName(moduleName);
|
||||
m.setPath(path.resolve(moduleFolder));
|
||||
nodeHelpers.push(m);
|
||||
m.setName(moduleName);
|
||||
m.setPath(path.resolve(moduleFolder));
|
||||
nodeHelpers.push(m);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ loadConfig(function(c) {
|
||||
loadModules(modules);
|
||||
|
||||
var server = new Server(config, function(app, io) {
|
||||
console.log('Server started ...');
|
||||
console.log("Server started ...");
|
||||
|
||||
for (var h in nodeHelpers) {
|
||||
var nodeHelper = nodeHelpers[h];
|
||||
@@ -120,28 +120,28 @@ loadConfig(function(c) {
|
||||
nodeHelper.start();
|
||||
}
|
||||
|
||||
console.log('Sockets connected & modules started ...');
|
||||
console.log("Sockets connected & modules started ...");
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
app.on('ready', function() {
|
||||
console.log('Launching application.');
|
||||
app.on("ready", function() {
|
||||
console.log("Launching application.");
|
||||
createWindow();
|
||||
});
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', function () {
|
||||
app.on("window-all-closed", function() {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', function () {
|
||||
app.on("activate", function() {
|
||||
// On OS X it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (mainWindow === null) {
|
||||
|
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;
|
||||
}
|
||||
|
||||
|
@@ -8,11 +8,9 @@
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
|
||||
// This logger is very simple, but needs to be extended.
|
||||
// This system can eventually be used to push the log messages to an external target.
|
||||
|
||||
|
||||
var Log = (function() {
|
||||
return {
|
||||
info: function(message) {
|
||||
|
70
js/main.js
70
js/main.js
@@ -22,7 +22,7 @@ var MM = (function() {
|
||||
for (var m in modules) {
|
||||
var module = modules[m];
|
||||
|
||||
if (typeof module.data.position === 'string') {
|
||||
if (typeof module.data.position === "string") {
|
||||
|
||||
var wrapper = selectWrapper(module.data.position);
|
||||
|
||||
@@ -30,14 +30,14 @@ var MM = (function() {
|
||||
dom.id = module.identifier;
|
||||
dom.className = module.name;
|
||||
|
||||
if (typeof module.data.classes === 'string') {
|
||||
dom.className = 'module '+ dom.className + ' ' + module.data.classes;
|
||||
if (typeof module.data.classes === "string") {
|
||||
dom.className = "module " + dom.className + " " + module.data.classes;
|
||||
}
|
||||
|
||||
dom.opacity = 0;
|
||||
wrapper.appendChild(dom);
|
||||
|
||||
if (typeof module.data.header !== 'undefined' && module.data.header !== '') {
|
||||
if (typeof module.data.header !== "undefined" && module.data.header !== "") {
|
||||
var moduleHeader = document.createElement("header");
|
||||
moduleHeader.innerHTML = module.data.header;
|
||||
dom.appendChild(moduleHeader);
|
||||
@@ -51,7 +51,7 @@ var MM = (function() {
|
||||
}
|
||||
}
|
||||
|
||||
sendNotification('DOM_OBJECTS_CREATED');
|
||||
sendNotification("DOM_OBJECTS_CREATED");
|
||||
};
|
||||
|
||||
/* selectWrapper(position)
|
||||
@@ -60,10 +60,10 @@ var MM = (function() {
|
||||
* argument position string - The name of the position.
|
||||
*/
|
||||
var selectWrapper = function(position) {
|
||||
var classes = position.replace('_',' ');
|
||||
var classes = position.replace("_"," ");
|
||||
var parentWrapper = document.getElementsByClassName(classes);
|
||||
if (parentWrapper.length > 0) {
|
||||
var wrapper = parentWrapper[0].getElementsByClassName('container');
|
||||
var wrapper = parentWrapper[0].getElementsByClassName("container");
|
||||
if (wrapper.length > 0) {
|
||||
return wrapper[0];
|
||||
}
|
||||
@@ -117,7 +117,6 @@ var MM = (function() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* moduleNeedsUpdate(module, newContent)
|
||||
* Check if the content has changed.
|
||||
*
|
||||
@@ -128,9 +127,9 @@ var MM = (function() {
|
||||
*/
|
||||
var moduleNeedsUpdate = function(module, newContent) {
|
||||
var moduleWrapper = document.getElementById(module.identifier);
|
||||
var contentWrapper = moduleWrapper.getElementsByClassName('module-content')[0];
|
||||
var contentWrapper = moduleWrapper.getElementsByClassName("module-content")[0];
|
||||
|
||||
var tempWrapper = document.createElement('div');
|
||||
var tempWrapper = document.createElement("div");
|
||||
tempWrapper.appendChild(newContent);
|
||||
|
||||
return tempWrapper.innerHTML !== contentWrapper.innerHTML;
|
||||
@@ -144,7 +143,7 @@ var MM = (function() {
|
||||
*/
|
||||
var updateModuleContent = function(module, content) {
|
||||
var moduleWrapper = document.getElementById(module.identifier);
|
||||
var contentWrapper = moduleWrapper.getElementsByClassName('module-content')[0];
|
||||
var contentWrapper = moduleWrapper.getElementsByClassName("module-content")[0];
|
||||
|
||||
contentWrapper.innerHTML = null;
|
||||
contentWrapper.appendChild(content);
|
||||
@@ -168,9 +167,9 @@ var MM = (function() {
|
||||
// since it's fade out anyway, we can see it lay above or
|
||||
// below other modules. This works way better than adjusting
|
||||
// the .display property.
|
||||
moduleWrapper.style.position = 'absolute';
|
||||
moduleWrapper.style.position = "absolute";
|
||||
|
||||
if (typeof callback === 'function') { callback(); }
|
||||
if (typeof callback === "function") { callback(); }
|
||||
}, speed);
|
||||
}
|
||||
};
|
||||
@@ -187,11 +186,11 @@ var MM = (function() {
|
||||
if (moduleWrapper !== null) {
|
||||
moduleWrapper.style.transition = "opacity " + speed / 1000 + "s";
|
||||
// Restore the postition. See hideModule() for more info.
|
||||
moduleWrapper.style.position = 'static';
|
||||
moduleWrapper.style.position = "static";
|
||||
moduleWrapper.style.opacity = 1;
|
||||
|
||||
setTimeout(function() {
|
||||
if (typeof callback === 'function') { callback(); }
|
||||
if (typeof callback === "function") { callback(); }
|
||||
}, speed);
|
||||
|
||||
}
|
||||
@@ -201,9 +200,9 @@ var MM = (function() {
|
||||
* Loads the core config and combines it with de system defaults.
|
||||
*/
|
||||
var loadConfig = function() {
|
||||
if (typeof config === 'undefined') {
|
||||
if (typeof config === "undefined") {
|
||||
config = defaults;
|
||||
Log.error('Config file is missing! Please create a config file.');
|
||||
Log.error("Config file is missing! Please create a config file.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -228,13 +227,13 @@ var MM = (function() {
|
||||
var newModules = [];
|
||||
|
||||
var searchClasses = className;
|
||||
if (typeof className === 'string') {
|
||||
searchClasses = className.split(' ');
|
||||
if (typeof className === "string") {
|
||||
searchClasses = className.split(" ");
|
||||
}
|
||||
|
||||
for (var m in modules) {
|
||||
var module = modules[m];
|
||||
var classes = module.data.classes.toLowerCase().split(' ');
|
||||
var classes = module.data.classes.toLowerCase().split(" ");
|
||||
|
||||
for (var c in searchClasses) {
|
||||
var searchClass = searchClasses[c];
|
||||
@@ -259,13 +258,13 @@ var MM = (function() {
|
||||
var newModules = [];
|
||||
|
||||
var searchClasses = className;
|
||||
if (typeof className === 'string') {
|
||||
searchClasses = className.split(' ');
|
||||
if (typeof className === "string") {
|
||||
searchClasses = className.split(" ");
|
||||
}
|
||||
|
||||
for (var m in modules) {
|
||||
var module = modules[m];
|
||||
var classes = module.data.classes.toLowerCase().split(' ');
|
||||
var classes = module.data.classes.toLowerCase().split(" ");
|
||||
var foundClass = false;
|
||||
for (var c in searchClasses) {
|
||||
var searchClass = searchClasses[c];
|
||||
@@ -316,13 +315,12 @@ var MM = (function() {
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof modules.withClass === 'undefined') { Object.defineProperty(modules, 'withClass', {value: withClass, enumerable: false}); }
|
||||
if (typeof modules.exceptWithClass === 'undefined') { Object.defineProperty(modules, 'exceptWithClass', {value: exceptWithClass, enumerable: false}); }
|
||||
if (typeof modules.exceptModule === 'undefined') { Object.defineProperty(modules, 'exceptModule', {value: exceptModule, enumerable: false}); }
|
||||
if (typeof modules.enumerate === 'undefined') { Object.defineProperty(modules, 'enumerate', {value: enumerate, enumerable: false}); }
|
||||
if (typeof modules.withClass === "undefined") { Object.defineProperty(modules, "withClass", {value: withClass, enumerable: false}); }
|
||||
if (typeof modules.exceptWithClass === "undefined") { Object.defineProperty(modules, "exceptWithClass", {value: exceptWithClass, enumerable: false}); }
|
||||
if (typeof modules.exceptModule === "undefined") { Object.defineProperty(modules, "exceptModule", {value: exceptModule, enumerable: false}); }
|
||||
if (typeof modules.enumerate === "undefined") { Object.defineProperty(modules, "enumerate", {value: enumerate, enumerable: false}); }
|
||||
};
|
||||
|
||||
|
||||
return {
|
||||
/* Public Methods */
|
||||
|
||||
@@ -330,7 +328,7 @@ var MM = (function() {
|
||||
* Main init method.
|
||||
*/
|
||||
init: function() {
|
||||
Log.info('Initializing MagicMirror.');
|
||||
Log.info("Initializing MagicMirror.");
|
||||
loadConfig();
|
||||
Loader.loadModules();
|
||||
},
|
||||
@@ -347,8 +345,8 @@ var MM = (function() {
|
||||
modules[module.data.index] = module;
|
||||
}
|
||||
|
||||
Log.info('All modules started!');
|
||||
sendNotification('ALL_MODULES_STARTED');
|
||||
Log.info("All modules started!");
|
||||
sendNotification("ALL_MODULES_STARTED");
|
||||
|
||||
createDomObjects();
|
||||
},
|
||||
@@ -362,17 +360,17 @@ var MM = (function() {
|
||||
*/
|
||||
sendNotification: function(notification, payload, sender) {
|
||||
if (arguments.length < 3) {
|
||||
Log.error('sendNotification: Missing arguments.');
|
||||
Log.error("sendNotification: Missing arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof notification !== 'string') {
|
||||
Log.error('sendNotification: Notification should be a string.');
|
||||
if (typeof notification !== "string") {
|
||||
Log.error("sendNotification: Notification should be a string.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(sender instanceof Module)) {
|
||||
Log.error('sendNotification: Sender should be a module.');
|
||||
Log.error("sendNotification: Sender should be a module.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -388,7 +386,7 @@ var MM = (function() {
|
||||
*/
|
||||
updateDom: function(module, speed) {
|
||||
if (!(module instanceof Module)) {
|
||||
Log.error('updateDom: Sender should be a module.');
|
||||
Log.error("updateDom: Sender should be a module.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
31
js/module.js
31
js/module.js
@@ -28,7 +28,7 @@ var Module = Class.extend({
|
||||
* Is called when the module is started.
|
||||
*/
|
||||
start: function() {
|
||||
Log.info('Starting module: ' + this.name);
|
||||
Log.info("Starting module: " + this.name);
|
||||
},
|
||||
|
||||
/* getScripts()
|
||||
@@ -82,9 +82,9 @@ var Module = Class.extend({
|
||||
*/
|
||||
notificationReceived: function(notification, payload, sender) {
|
||||
if (sender) {
|
||||
Log.log(this.name + ' received a module notification: ' + notification + ' from sender: ' + sender.name);
|
||||
Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
|
||||
} else {
|
||||
Log.log(this.name + ' received a system notification: ' + notification);
|
||||
Log.log(this.name + " received a system notification: " + notification);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -95,10 +95,9 @@ var Module = Class.extend({
|
||||
* argument payload mixed - The payload of the notification.
|
||||
*/
|
||||
socketNotificationReceived: function(notification, payload) {
|
||||
Log.log(this.name + ' received a socket notification: ' + notification + ' - Payload: ' + payload);
|
||||
Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
|
||||
},
|
||||
|
||||
|
||||
/*********************************************
|
||||
* The methods below don't need subclassing. *
|
||||
*********************************************/
|
||||
@@ -131,7 +130,7 @@ var Module = Class.extend({
|
||||
* It also registers the notification callback.
|
||||
*/
|
||||
socket: function() {
|
||||
if (typeof this._socket === 'undefined') {
|
||||
if (typeof this._socket === "undefined") {
|
||||
this._socket = this._socket = new MMSocket(this.name);
|
||||
}
|
||||
|
||||
@@ -151,7 +150,7 @@ var Module = Class.extend({
|
||||
* return string - File path.
|
||||
*/
|
||||
file: function(file) {
|
||||
return this.data.path + '/' + file;
|
||||
return this.data.path + "/" + file;
|
||||
},
|
||||
|
||||
/* loadStyles()
|
||||
@@ -258,16 +257,16 @@ Module.create = function(name) {
|
||||
|
||||
//Define the clone method for later use.
|
||||
function cloneObject(obj) {
|
||||
if (obj === null || typeof obj !== 'object') {
|
||||
return obj;
|
||||
}
|
||||
if (obj === null || typeof obj !== "object") {
|
||||
return obj;
|
||||
}
|
||||
|
||||
var temp = obj.constructor(); // give temp the original obj's constructor
|
||||
for (var key in obj) {
|
||||
temp[key] = cloneObject(obj[key]);
|
||||
}
|
||||
var temp = obj.constructor(); // give temp the original obj's constructor
|
||||
for (var key in obj) {
|
||||
temp[key] = cloneObject(obj[key]);
|
||||
}
|
||||
|
||||
return temp;
|
||||
return temp;
|
||||
}
|
||||
|
||||
var moduleDefinition = Module.definitions[name];
|
||||
@@ -281,6 +280,6 @@ Module.create = function(name) {
|
||||
};
|
||||
|
||||
Module.register = function(name, moduleDefinition) {
|
||||
Log.log('Module registered: ' + name);
|
||||
Log.log("Module registered: " + name);
|
||||
Module.definitions[name] = moduleDefinition;
|
||||
};
|
||||
|
28
js/server.js
28
js/server.js
@@ -5,28 +5,28 @@
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
var express = require('express');
|
||||
var app = require('express')();
|
||||
var server = require('http').Server(app);
|
||||
var io = require('socket.io')(server);
|
||||
var path = require('path');
|
||||
var express = require("express");
|
||||
var app = require("express")();
|
||||
var server = require("http").Server(app);
|
||||
var io = require("socket.io")(server);
|
||||
var path = require("path");
|
||||
|
||||
var Server = function(config, callback) {
|
||||
console.log("Starting server op port " + config.port + " ... ");
|
||||
|
||||
server.listen(config.port);
|
||||
app.use('/js', express.static(__dirname));
|
||||
app.use('/config', express.static(path.resolve(__dirname + '/../config')));
|
||||
app.use('/css', express.static(path.resolve(__dirname + '/../css')));
|
||||
app.use('/fonts', express.static(path.resolve(__dirname + '/../fonts')));
|
||||
app.use('/modules', express.static(path.resolve(__dirname + '/../modules')));
|
||||
app.use('/vendor', express.static(path.resolve(__dirname + '/../vendor')));
|
||||
app.use("/js", express.static(__dirname));
|
||||
app.use("/config", express.static(path.resolve(__dirname + "/../config")));
|
||||
app.use("/css", express.static(path.resolve(__dirname + "/../css")));
|
||||
app.use("/fonts", express.static(path.resolve(__dirname + "/../fonts")));
|
||||
app.use("/modules", express.static(path.resolve(__dirname + "/../modules")));
|
||||
app.use("/vendor", express.static(path.resolve(__dirname + "/../vendor")));
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.sendFile(path.resolve(__dirname + '/../index.html'));
|
||||
app.get("/", function(req, res) {
|
||||
res.sendFile(path.resolve(__dirname + "/../index.html"));
|
||||
});
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
if (typeof callback === "function") {
|
||||
callback(app, io);
|
||||
}
|
||||
};
|
||||
|
13
js/socket.js
13
js/socket.js
@@ -11,22 +11,21 @@ var MMSocket = function(moduleName) {
|
||||
|
||||
var self = this;
|
||||
|
||||
if (typeof moduleName !== 'string') {
|
||||
throw new Error('Please set the module name for the MMSocket.');
|
||||
if (typeof moduleName !== "string") {
|
||||
throw new Error("Please set the module name for the MMSocket.");
|
||||
}
|
||||
|
||||
self.moduleName = moduleName;
|
||||
|
||||
|
||||
self.socket = io('http://localhost:8080');
|
||||
self.socket.on('notification', function (data) {
|
||||
self.socket = io("http://localhost:8080");
|
||||
self.socket.on("notification", function(data) {
|
||||
MM.sendNotification(data.notification, data.payload, Socket);
|
||||
});
|
||||
|
||||
return {
|
||||
sendMessage: function(notification, payload, sender) {
|
||||
Log.log('Send socket message: ' + notification);
|
||||
self.socket.emit('notification', {
|
||||
Log.log("Send socket message: " + notification);
|
||||
self.socket.emit("notification", {
|
||||
notification: notification,
|
||||
sender: sender,
|
||||
payload: payload
|
||||
|
@@ -1,40 +1,39 @@
|
||||
var MMSocket = function(moduleName) {
|
||||
var self = this;
|
||||
|
||||
if (typeof moduleName !== 'string') {
|
||||
throw new Error('Please set the module name for the MMSocket.');
|
||||
if (typeof moduleName !== "string") {
|
||||
throw new Error("Please set the module name for the MMSocket.");
|
||||
}
|
||||
|
||||
self.moduleName = moduleName;
|
||||
|
||||
// Private Methods
|
||||
socket = io.connect('/' + self.moduleName);
|
||||
socket = io.connect("/" + self.moduleName);
|
||||
var notificationCallback = function() {};
|
||||
|
||||
var onevent = socket.onevent;
|
||||
socket.onevent = function (packet) {
|
||||
socket.onevent = function(packet) {
|
||||
var args = packet.data || [];
|
||||
onevent.call (this, packet); // original call
|
||||
onevent.call(this, packet); // original call
|
||||
packet.data = ["*"].concat(args);
|
||||
onevent.call(this, packet); // additional call to catch-all
|
||||
};
|
||||
|
||||
// register catch all.
|
||||
socket.on('*', function (notification, payload) {
|
||||
if (notification !== '*') {
|
||||
socket.on("*", function(notification, payload) {
|
||||
if (notification !== "*") {
|
||||
//console.log('Received notification: ' + notification +', payload: ' + payload);
|
||||
notificationCallback(notification, payload);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Public Methods
|
||||
this.setNotificationCallback = function(callback) {
|
||||
notificationCallback = callback;
|
||||
};
|
||||
|
||||
this.sendNotification = function(notification, payload) {
|
||||
if (typeof payload === 'undefined') {
|
||||
if (typeof payload === "undefined") {
|
||||
payload = {};
|
||||
}
|
||||
socket.emit(notification, payload);
|
||||
|
Reference in New Issue
Block a user