mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 20:22:53 +00:00
Standardize: TO JSCS!
This commit is contained in:
parent
18390503b5
commit
426728058c
8
.jscsrc
Normal file
8
.jscsrc
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"preset": "google",
|
||||||
|
"validateIndentation": "\t",
|
||||||
|
"validateQuoteMarks": "\"",
|
||||||
|
"maximumLineLength": 250,
|
||||||
|
"requireCurlyBraces": [],
|
||||||
|
"requireCamelCaseOrUpperCaseIdentifiers": false
|
||||||
|
}
|
92
js/class.js
92
js/class.js
@ -4,66 +4,66 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Inspired by base2 and Prototype
|
// Inspired by base2 and Prototype
|
||||||
(function(){
|
(function() {
|
||||||
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
var initializing = false;
|
||||||
|
var fnTest = /xyz/.test(function() {xyz;}) ? /\b_super\b/ : /.*/;
|
||||||
|
|
||||||
// The base Class implementation (does nothing)
|
// The base Class implementation (does nothing)
|
||||||
this.Class = function(){};
|
this.Class = function() {};
|
||||||
|
|
||||||
// Create a new Class that inherits from this class
|
// Create a new Class that inherits from this class
|
||||||
Class.extend = function(prop) {
|
Class.extend = function(prop) {
|
||||||
var _super = this.prototype;
|
var _super = this.prototype;
|
||||||
|
|
||||||
// Instantiate a base class (but only create the instance,
|
// Instantiate a base class (but only create the instance,
|
||||||
// don't run the init constructor)
|
// don't run the init constructor)
|
||||||
initializing = true;
|
initializing = true;
|
||||||
var prototype = new this();
|
var prototype = new this();
|
||||||
initializing = false;
|
initializing = false;
|
||||||
|
|
||||||
// Copy the properties over onto the new prototype
|
// Copy the properties over onto the new prototype
|
||||||
for (var name in prop) {
|
for (var name in prop) {
|
||||||
// Check if we're overwriting an existing function
|
// Check if we're overwriting an existing function
|
||||||
prototype[name] = typeof prop[name] == "function" &&
|
prototype[name] = typeof prop[name] == "function" &&
|
||||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||||
(function(name, fn){
|
(function(name, fn) {
|
||||||
return function() {
|
return function() {
|
||||||
var tmp = this._super;
|
var tmp = this._super;
|
||||||
|
|
||||||
// Add a new ._super() method that is the same method
|
// Add a new ._super() method that is the same method
|
||||||
// but on the super-class
|
// but on the super-class
|
||||||
this._super = _super[name];
|
this._super = _super[name];
|
||||||
|
|
||||||
// The method only need to be bound temporarily, so we
|
// The method only need to be bound temporarily, so we
|
||||||
// remove it when we're done executing
|
// remove it when we're done executing
|
||||||
var ret = fn.apply(this, arguments);
|
var ret = fn.apply(this, arguments);
|
||||||
this._super = tmp;
|
this._super = tmp;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
})(name, prop[name]) :
|
})(name, prop[name]) :
|
||||||
prop[name];
|
prop[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
// The dummy class constructor
|
// The dummy class constructor
|
||||||
function Class() {
|
function Class() {
|
||||||
// All construction is actually done in the init method
|
// All construction is actually done in the init method
|
||||||
if ( !initializing && this.init )
|
if (!initializing && this.init)
|
||||||
this.init.apply(this, arguments);
|
this.init.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate our constructed prototype object
|
// Populate our constructed prototype object
|
||||||
Class.prototype = prototype;
|
Class.prototype = prototype;
|
||||||
|
|
||||||
// Enforce the constructor to be what we expect
|
// Enforce the constructor to be what we expect
|
||||||
Class.prototype.constructor = Class;
|
Class.prototype.constructor = Class;
|
||||||
|
|
||||||
// And make this class extendable
|
// And make this class extendable
|
||||||
Class.extend = arguments.callee;
|
Class.extend = arguments.callee;
|
||||||
|
|
||||||
return Class;
|
return Class;
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
/*************** 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 = {
|
var defaults = {
|
||||||
port: 8080,
|
port: 8080,
|
||||||
|
|
||||||
language: 'en',
|
language: "en",
|
||||||
timeFormat: 24,
|
timeFormat: 24,
|
||||||
|
|
||||||
modules: [
|
modules: [
|
||||||
{
|
{
|
||||||
module: 'helloworld',
|
module: "helloworld",
|
||||||
position: 'upper_third',
|
position: "upper_third",
|
||||||
config: {
|
config: {
|
||||||
text: 'Magic Mirror V2',
|
text: "Magic Mirror V2",
|
||||||
classes: 'large thin'
|
classes: "large thin"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
module: 'helloworld',
|
module: "helloworld",
|
||||||
position: 'middle_center',
|
position: "middle_center",
|
||||||
config: {
|
config: {
|
||||||
text: 'Please create a config file.'
|
text: "Please create a config file."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
module: 'helloworld',
|
module: "helloworld",
|
||||||
position: 'middle_center',
|
position: "middle_center",
|
||||||
config: {
|
config: {
|
||||||
text: 'See README for more information.',
|
text: "See README for more information.",
|
||||||
classes: 'small dimmed'
|
classes: "small dimmed"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
module: 'helloworld',
|
module: "helloworld",
|
||||||
position: 'bottom_bar',
|
position: "bottom_bar",
|
||||||
config: {
|
config: {
|
||||||
text: 'www.michaelteeuw.nl',
|
text: "www.michaelteeuw.nl",
|
||||||
classes: 'xsmall dimmed'
|
classes: "xsmall dimmed"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
paths: {
|
paths: {
|
||||||
modules: 'modules',
|
modules: "modules",
|
||||||
vendor: 'vendor'
|
vendor: "vendor"
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
/*************** 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
|
//load modules
|
||||||
const walk = require('walk');
|
const walk = require("walk");
|
||||||
const fs = require('fs');
|
const fs = require("fs");
|
||||||
const Server = require(__dirname + '/server.js');
|
const Server = require(__dirname + "/server.js");
|
||||||
const spawn = require('child_process').spawn;
|
const spawn = require("child_process").spawn;
|
||||||
const electron = require('electron');
|
const electron = require("electron");
|
||||||
const defaultModules = require(__dirname + '/../modules/default/defaultmodules.js');
|
const defaultModules = require(__dirname + "/../modules/default/defaultmodules.js");
|
||||||
const path = require('path');
|
const path = require("path");
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
var config = {};
|
var config = {};
|
||||||
@ -22,19 +22,19 @@ var nodeHelpers = [];
|
|||||||
// be closed automatically when the JavaScript object is garbage collected.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
function createWindow () {
|
function createWindow() {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
mainWindow = new BrowserWindow({width: 800, height: 600, fullscreen: true, autoHideMenuBar: true, webPreferences: {nodeIntegration: false}});
|
mainWindow = new BrowserWindow({width: 800, height: 600, fullscreen: true, autoHideMenuBar: true, webPreferences: {nodeIntegration: false}});
|
||||||
|
|
||||||
// and load the index.html of the app.
|
// and load the index.html of the app.
|
||||||
//mainWindow.loadURL('file://' + __dirname + '../../index.html');
|
//mainWindow.loadURL('file://' + __dirname + '../../index.html');
|
||||||
mainWindow.loadURL('http://localhost:' + config.port);
|
mainWindow.loadURL("http://localhost:" + config.port);
|
||||||
|
|
||||||
// Open the DevTools.
|
// Open the DevTools.
|
||||||
//mainWindow.webContents.openDevTools();
|
//mainWindow.webContents.openDevTools();
|
||||||
|
|
||||||
// Emitted when the window is closed.
|
// Emitted when the window is closed.
|
||||||
mainWindow.on('closed', function() {
|
mainWindow.on("closed", function() {
|
||||||
// Dereference the window object, usually you would store windows
|
// Dereference the window object, usually you would store windows
|
||||||
// in an array if your app supports multi windows, this is the time
|
// in an array if your app supports multi windows, this is the time
|
||||||
// when you should delete the corresponding element.
|
// when you should delete the corresponding element.
|
||||||
@ -42,36 +42,36 @@ function createWindow () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadConfig (callback) {
|
function loadConfig(callback) {
|
||||||
console.log("Loading config ...");
|
console.log("Loading config ...");
|
||||||
var defaults = require(__dirname + '/defaults.js');
|
var defaults = require(__dirname + "/defaults.js");
|
||||||
var configFilename = __dirname + '/../config/config.js';
|
var configFilename = __dirname + "/../config/config.js";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs.accessSync(configFilename, fs.R_OK);
|
fs.accessSync(configFilename, fs.R_OK);
|
||||||
var c = require(configFilename);
|
var c = require(configFilename);
|
||||||
var config = Object.assign(defaults, c);
|
var config = Object.assign(defaults, c);
|
||||||
callback(config);
|
callback(config);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
callback(defaults);
|
callback(defaults);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadModule(module) {
|
function loadModule(module) {
|
||||||
|
|
||||||
var elements = module.split('/');
|
var elements = module.split("/");
|
||||||
var moduleName = elements[elements.length - 1];
|
var moduleName = elements[elements.length - 1];
|
||||||
var moduleFolder = __dirname + '/../modules/' + module;
|
var moduleFolder = __dirname + "/../modules/" + module;
|
||||||
|
|
||||||
if (defaultModules.indexOf(moduleName) !== -1) {
|
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;
|
var loadModule = true;
|
||||||
try {
|
try {
|
||||||
fs.accessSync(helperPath, fs.R_OK);
|
fs.accessSync(helperPath, fs.R_OK);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
loadModule = false;
|
loadModule = false;
|
||||||
console.log("No helper found for module: " + moduleName + ".");
|
console.log("No helper found for module: " + moduleName + ".");
|
||||||
@ -80,9 +80,9 @@ function loadModule(module) {
|
|||||||
if (loadModule) {
|
if (loadModule) {
|
||||||
var Module = require(helperPath);
|
var Module = require(helperPath);
|
||||||
var m = new Module();
|
var m = new Module();
|
||||||
m.setName(moduleName);
|
m.setName(moduleName);
|
||||||
m.setPath(path.resolve(moduleFolder));
|
m.setPath(path.resolve(moduleFolder));
|
||||||
nodeHelpers.push(m);
|
nodeHelpers.push(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ loadConfig(function(c) {
|
|||||||
loadModules(modules);
|
loadModules(modules);
|
||||||
|
|
||||||
var server = new Server(config, function(app, io) {
|
var server = new Server(config, function(app, io) {
|
||||||
console.log('Server started ...');
|
console.log("Server started ...");
|
||||||
|
|
||||||
for (var h in nodeHelpers) {
|
for (var h in nodeHelpers) {
|
||||||
var nodeHelper = nodeHelpers[h];
|
var nodeHelper = nodeHelpers[h];
|
||||||
@ -120,28 +120,28 @@ loadConfig(function(c) {
|
|||||||
nodeHelper.start();
|
nodeHelper.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Sockets connected & modules started ...');
|
console.log("Sockets connected & modules started ...");
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
app.on('ready', function() {
|
app.on("ready", function() {
|
||||||
console.log('Launching application.');
|
console.log("Launching application.");
|
||||||
createWindow();
|
createWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// 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
|
// On OS X it is common for applications and their menu bar
|
||||||
// to stay active until the user quits explicitly with Cmd + Q
|
// to stay active until the user quits explicitly with Cmd + Q
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== "darwin") {
|
||||||
app.quit();
|
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
|
// 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.
|
// dock icon is clicked and there are no other windows open.
|
||||||
if (mainWindow === null) {
|
if (mainWindow === null) {
|
||||||
|
44
js/loader.js
44
js/loader.js
@ -2,7 +2,6 @@
|
|||||||
/* jshint unused:false */
|
/* jshint unused:false */
|
||||||
/* jshint -W061 */
|
/* jshint -W061 */
|
||||||
|
|
||||||
|
|
||||||
/* Magic Mirror
|
/* Magic Mirror
|
||||||
* Module and File loaders.
|
* Module and File loaders.
|
||||||
*
|
*
|
||||||
@ -18,10 +17,8 @@ var Loader = (function() {
|
|||||||
var loadedFiles = [];
|
var loadedFiles = [];
|
||||||
var moduleObjects = [];
|
var moduleObjects = [];
|
||||||
|
|
||||||
|
|
||||||
/* Private Methods */
|
/* Private Methods */
|
||||||
|
|
||||||
|
|
||||||
/* loadModules()
|
/* loadModules()
|
||||||
* Loops thru all modules and requests load for every module.
|
* Loops thru all modules and requests load for every module.
|
||||||
*/
|
*/
|
||||||
@ -79,33 +76,31 @@ var Loader = (function() {
|
|||||||
var moduleData = modules[m];
|
var moduleData = modules[m];
|
||||||
var module = moduleData.module;
|
var module = moduleData.module;
|
||||||
|
|
||||||
var elements = module.split('/');
|
var elements = module.split("/");
|
||||||
var moduleName = elements[elements.length - 1];
|
var moduleName = elements[elements.length - 1];
|
||||||
var moduleFolder = config.paths.modules + '/' + module;
|
var moduleFolder = config.paths.modules + "/" + module;
|
||||||
|
|
||||||
if (defaultModules.indexOf(moduleName) !== -1) {
|
if (defaultModules.indexOf(moduleName) !== -1) {
|
||||||
moduleFolder = config.paths.modules + '/default/' + module;
|
moduleFolder = config.paths.modules + "/default/" + module;
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleFiles.push({
|
moduleFiles.push({
|
||||||
index: m,
|
index: m,
|
||||||
identifier: 'module_' + m + '_' + module,
|
identifier: "module_" + m + "_" + module,
|
||||||
name: moduleName,
|
name: moduleName,
|
||||||
path: moduleFolder + '/' ,
|
path: moduleFolder + "/" ,
|
||||||
file: moduleName + '.js',
|
file: moduleName + ".js",
|
||||||
position: moduleData.position,
|
position: moduleData.position,
|
||||||
header: moduleData.header,
|
header: moduleData.header,
|
||||||
config: moduleData.config,
|
config: moduleData.config,
|
||||||
classes: (typeof moduleData.classes !== 'undefined') ? moduleData.classes + ' ' + module : module
|
classes: (typeof moduleData.classes !== "undefined") ? moduleData.classes + " " + module : module
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return moduleFiles;
|
return moduleFiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* loadModule(module)
|
/* loadModule(module)
|
||||||
* Load modules via ajax request and create module objects.
|
* 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.
|
* argument module object - Information about the module we want to load.
|
||||||
*/
|
*/
|
||||||
var loadModule = function(module, callback) {
|
var loadModule = function(module, callback) {
|
||||||
var url = module.path + '/' + module.file;
|
var url = module.path + "/" + module.file;
|
||||||
|
|
||||||
var afterLoad = function() {
|
var afterLoad = function() {
|
||||||
var moduleObject = Module.create(module.name);
|
var moduleObject = Module.create(module.name);
|
||||||
@ -141,21 +136,20 @@ var Loader = (function() {
|
|||||||
* argument callback function - Function called when done.
|
* argument callback function - Function called when done.
|
||||||
*/
|
*/
|
||||||
var bootstrapModule = function(module, mObj, callback) {
|
var bootstrapModule = function(module, mObj, callback) {
|
||||||
Log.info('Bootstrapping module: ' + module.name);
|
Log.info("Bootstrapping module: " + module.name);
|
||||||
|
|
||||||
mObj.setData(module);
|
mObj.setData(module);
|
||||||
|
|
||||||
mObj.loadScripts(function() {
|
mObj.loadScripts(function() {
|
||||||
Log.log('Scripts loaded for: ' + module.name);
|
Log.log("Scripts loaded for: " + module.name);
|
||||||
mObj.loadStyles(function(){
|
mObj.loadStyles(function() {
|
||||||
Log.log('Styles loaded for: ' + module.name);
|
Log.log("Styles loaded for: " + module.name);
|
||||||
|
|
||||||
moduleObjects.push(mObj);
|
moduleObjects.push(mObj);
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* loadFile(fileName)
|
/* loadFile(fileName)
|
||||||
@ -170,27 +164,27 @@ var Loader = (function() {
|
|||||||
|
|
||||||
switch (extension.toLowerCase()) {
|
switch (extension.toLowerCase()) {
|
||||||
case "js":
|
case "js":
|
||||||
Log.log('Load script: ' + fileName);
|
Log.log("Load script: " + fileName);
|
||||||
|
|
||||||
var script = document.createElement("script");
|
var script = document.createElement("script");
|
||||||
script.type = "text/javascript";
|
script.type = "text/javascript";
|
||||||
script.src = fileName;
|
script.src = fileName;
|
||||||
script.onload = function() {
|
script.onload = function() {
|
||||||
if (typeof callback === 'function') {callback();}
|
if (typeof callback === "function") {callback();}
|
||||||
};
|
};
|
||||||
|
|
||||||
document.getElementsByTagName("body")[0].appendChild(script);
|
document.getElementsByTagName("body")[0].appendChild(script);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "css":
|
case "css":
|
||||||
Log.log('Load stylesheet: ' + fileName);
|
Log.log("Load stylesheet: " + fileName);
|
||||||
|
|
||||||
var stylesheet = document.createElement("link");
|
var stylesheet = document.createElement("link");
|
||||||
stylesheet.rel = "stylesheet";
|
stylesheet.rel = "stylesheet";
|
||||||
stylesheet.type = "text/css";
|
stylesheet.type = "text/css";
|
||||||
stylesheet.href = fileName;
|
stylesheet.href = fileName;
|
||||||
stylesheet.onload = function() {
|
stylesheet.onload = function() {
|
||||||
if (typeof callback === 'function') {callback();}
|
if (typeof callback === "function") {callback();}
|
||||||
};
|
};
|
||||||
|
|
||||||
document.getElementsByTagName("head")[0].appendChild(stylesheet);
|
document.getElementsByTagName("head")[0].appendChild(stylesheet);
|
||||||
@ -220,12 +214,12 @@ var Loader = (function() {
|
|||||||
loadFile: function(fileName, module, callback) {
|
loadFile: function(fileName, module, callback) {
|
||||||
|
|
||||||
if (loadedFiles.indexOf(fileName.toLowerCase()) !== -1) {
|
if (loadedFiles.indexOf(fileName.toLowerCase()) !== -1) {
|
||||||
Log.log('File already loaded: ' + fileName);
|
Log.log("File already loaded: " + fileName);
|
||||||
callback();
|
callback();
|
||||||
return;
|
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.
|
// This is an absolute or relative path.
|
||||||
// Load it and then return.
|
// Load it and then return.
|
||||||
loadedFiles.push(fileName.toLowerCase());
|
loadedFiles.push(fileName.toLowerCase());
|
||||||
@ -237,7 +231,7 @@ var Loader = (function() {
|
|||||||
// This file is available in the vendor folder.
|
// This file is available in the vendor folder.
|
||||||
// Load it from this vendor folder.
|
// Load it from this vendor folder.
|
||||||
loadedFiles.push(fileName.toLowerCase());
|
loadedFiles.push(fileName.toLowerCase());
|
||||||
loadFile(config.paths.vendor+'/'+vendor[fileName], callback);
|
loadFile(config.paths.vendor + "/" + vendor[fileName], callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,11 +8,9 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// This logger is very simple, but needs to be extended.
|
// 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.
|
// This system can eventually be used to push the log messages to an external target.
|
||||||
|
|
||||||
|
|
||||||
var Log = (function() {
|
var Log = (function() {
|
||||||
return {
|
return {
|
||||||
info: function(message) {
|
info: function(message) {
|
||||||
|
70
js/main.js
70
js/main.js
@ -22,7 +22,7 @@ var MM = (function() {
|
|||||||
for (var m in modules) {
|
for (var m in modules) {
|
||||||
var module = modules[m];
|
var module = modules[m];
|
||||||
|
|
||||||
if (typeof module.data.position === 'string') {
|
if (typeof module.data.position === "string") {
|
||||||
|
|
||||||
var wrapper = selectWrapper(module.data.position);
|
var wrapper = selectWrapper(module.data.position);
|
||||||
|
|
||||||
@ -30,14 +30,14 @@ var MM = (function() {
|
|||||||
dom.id = module.identifier;
|
dom.id = module.identifier;
|
||||||
dom.className = module.name;
|
dom.className = module.name;
|
||||||
|
|
||||||
if (typeof module.data.classes === 'string') {
|
if (typeof module.data.classes === "string") {
|
||||||
dom.className = 'module '+ dom.className + ' ' + module.data.classes;
|
dom.className = "module " + dom.className + " " + module.data.classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
dom.opacity = 0;
|
dom.opacity = 0;
|
||||||
wrapper.appendChild(dom);
|
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");
|
var moduleHeader = document.createElement("header");
|
||||||
moduleHeader.innerHTML = module.data.header;
|
moduleHeader.innerHTML = module.data.header;
|
||||||
dom.appendChild(moduleHeader);
|
dom.appendChild(moduleHeader);
|
||||||
@ -51,7 +51,7 @@ var MM = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendNotification('DOM_OBJECTS_CREATED');
|
sendNotification("DOM_OBJECTS_CREATED");
|
||||||
};
|
};
|
||||||
|
|
||||||
/* selectWrapper(position)
|
/* selectWrapper(position)
|
||||||
@ -60,10 +60,10 @@ var MM = (function() {
|
|||||||
* argument position string - The name of the position.
|
* argument position string - The name of the position.
|
||||||
*/
|
*/
|
||||||
var selectWrapper = function(position) {
|
var selectWrapper = function(position) {
|
||||||
var classes = position.replace('_',' ');
|
var classes = position.replace("_"," ");
|
||||||
var parentWrapper = document.getElementsByClassName(classes);
|
var parentWrapper = document.getElementsByClassName(classes);
|
||||||
if (parentWrapper.length > 0) {
|
if (parentWrapper.length > 0) {
|
||||||
var wrapper = parentWrapper[0].getElementsByClassName('container');
|
var wrapper = parentWrapper[0].getElementsByClassName("container");
|
||||||
if (wrapper.length > 0) {
|
if (wrapper.length > 0) {
|
||||||
return wrapper[0];
|
return wrapper[0];
|
||||||
}
|
}
|
||||||
@ -117,7 +117,6 @@ var MM = (function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* moduleNeedsUpdate(module, newContent)
|
/* moduleNeedsUpdate(module, newContent)
|
||||||
* Check if the content has changed.
|
* Check if the content has changed.
|
||||||
*
|
*
|
||||||
@ -128,9 +127,9 @@ var MM = (function() {
|
|||||||
*/
|
*/
|
||||||
var moduleNeedsUpdate = function(module, newContent) {
|
var moduleNeedsUpdate = function(module, newContent) {
|
||||||
var moduleWrapper = document.getElementById(module.identifier);
|
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);
|
tempWrapper.appendChild(newContent);
|
||||||
|
|
||||||
return tempWrapper.innerHTML !== contentWrapper.innerHTML;
|
return tempWrapper.innerHTML !== contentWrapper.innerHTML;
|
||||||
@ -144,7 +143,7 @@ var MM = (function() {
|
|||||||
*/
|
*/
|
||||||
var updateModuleContent = function(module, content) {
|
var updateModuleContent = function(module, content) {
|
||||||
var moduleWrapper = document.getElementById(module.identifier);
|
var moduleWrapper = document.getElementById(module.identifier);
|
||||||
var contentWrapper = moduleWrapper.getElementsByClassName('module-content')[0];
|
var contentWrapper = moduleWrapper.getElementsByClassName("module-content")[0];
|
||||||
|
|
||||||
contentWrapper.innerHTML = null;
|
contentWrapper.innerHTML = null;
|
||||||
contentWrapper.appendChild(content);
|
contentWrapper.appendChild(content);
|
||||||
@ -168,9 +167,9 @@ var MM = (function() {
|
|||||||
// since it's fade out anyway, we can see it lay above or
|
// since it's fade out anyway, we can see it lay above or
|
||||||
// below other modules. This works way better than adjusting
|
// below other modules. This works way better than adjusting
|
||||||
// the .display property.
|
// the .display property.
|
||||||
moduleWrapper.style.position = 'absolute';
|
moduleWrapper.style.position = "absolute";
|
||||||
|
|
||||||
if (typeof callback === 'function') { callback(); }
|
if (typeof callback === "function") { callback(); }
|
||||||
}, speed);
|
}, speed);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -187,11 +186,11 @@ var MM = (function() {
|
|||||||
if (moduleWrapper !== null) {
|
if (moduleWrapper !== null) {
|
||||||
moduleWrapper.style.transition = "opacity " + speed / 1000 + "s";
|
moduleWrapper.style.transition = "opacity " + speed / 1000 + "s";
|
||||||
// Restore the postition. See hideModule() for more info.
|
// Restore the postition. See hideModule() for more info.
|
||||||
moduleWrapper.style.position = 'static';
|
moduleWrapper.style.position = "static";
|
||||||
moduleWrapper.style.opacity = 1;
|
moduleWrapper.style.opacity = 1;
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
if (typeof callback === 'function') { callback(); }
|
if (typeof callback === "function") { callback(); }
|
||||||
}, speed);
|
}, speed);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -201,9 +200,9 @@ var MM = (function() {
|
|||||||
* Loads the core config and combines it with de system defaults.
|
* Loads the core config and combines it with de system defaults.
|
||||||
*/
|
*/
|
||||||
var loadConfig = function() {
|
var loadConfig = function() {
|
||||||
if (typeof config === 'undefined') {
|
if (typeof config === "undefined") {
|
||||||
config = defaults;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,13 +227,13 @@ var MM = (function() {
|
|||||||
var newModules = [];
|
var newModules = [];
|
||||||
|
|
||||||
var searchClasses = className;
|
var searchClasses = className;
|
||||||
if (typeof className === 'string') {
|
if (typeof className === "string") {
|
||||||
searchClasses = className.split(' ');
|
searchClasses = className.split(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var m in modules) {
|
for (var m in modules) {
|
||||||
var module = modules[m];
|
var module = modules[m];
|
||||||
var classes = module.data.classes.toLowerCase().split(' ');
|
var classes = module.data.classes.toLowerCase().split(" ");
|
||||||
|
|
||||||
for (var c in searchClasses) {
|
for (var c in searchClasses) {
|
||||||
var searchClass = searchClasses[c];
|
var searchClass = searchClasses[c];
|
||||||
@ -259,13 +258,13 @@ var MM = (function() {
|
|||||||
var newModules = [];
|
var newModules = [];
|
||||||
|
|
||||||
var searchClasses = className;
|
var searchClasses = className;
|
||||||
if (typeof className === 'string') {
|
if (typeof className === "string") {
|
||||||
searchClasses = className.split(' ');
|
searchClasses = className.split(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var m in modules) {
|
for (var m in modules) {
|
||||||
var module = modules[m];
|
var module = modules[m];
|
||||||
var classes = module.data.classes.toLowerCase().split(' ');
|
var classes = module.data.classes.toLowerCase().split(" ");
|
||||||
var foundClass = false;
|
var foundClass = false;
|
||||||
for (var c in searchClasses) {
|
for (var c in searchClasses) {
|
||||||
var searchClass = searchClasses[c];
|
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.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.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.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.enumerate === "undefined") { Object.defineProperty(modules, "enumerate", {value: enumerate, enumerable: false}); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/* Public Methods */
|
/* Public Methods */
|
||||||
|
|
||||||
@ -330,7 +328,7 @@ var MM = (function() {
|
|||||||
* Main init method.
|
* Main init method.
|
||||||
*/
|
*/
|
||||||
init: function() {
|
init: function() {
|
||||||
Log.info('Initializing MagicMirror.');
|
Log.info("Initializing MagicMirror.");
|
||||||
loadConfig();
|
loadConfig();
|
||||||
Loader.loadModules();
|
Loader.loadModules();
|
||||||
},
|
},
|
||||||
@ -347,8 +345,8 @@ var MM = (function() {
|
|||||||
modules[module.data.index] = module;
|
modules[module.data.index] = module;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.info('All modules started!');
|
Log.info("All modules started!");
|
||||||
sendNotification('ALL_MODULES_STARTED');
|
sendNotification("ALL_MODULES_STARTED");
|
||||||
|
|
||||||
createDomObjects();
|
createDomObjects();
|
||||||
},
|
},
|
||||||
@ -362,17 +360,17 @@ var MM = (function() {
|
|||||||
*/
|
*/
|
||||||
sendNotification: function(notification, payload, sender) {
|
sendNotification: function(notification, payload, sender) {
|
||||||
if (arguments.length < 3) {
|
if (arguments.length < 3) {
|
||||||
Log.error('sendNotification: Missing arguments.');
|
Log.error("sendNotification: Missing arguments.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof notification !== 'string') {
|
if (typeof notification !== "string") {
|
||||||
Log.error('sendNotification: Notification should be a string.');
|
Log.error("sendNotification: Notification should be a string.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(sender instanceof Module)) {
|
if (!(sender instanceof Module)) {
|
||||||
Log.error('sendNotification: Sender should be a module.');
|
Log.error("sendNotification: Sender should be a module.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +386,7 @@ var MM = (function() {
|
|||||||
*/
|
*/
|
||||||
updateDom: function(module, speed) {
|
updateDom: function(module, speed) {
|
||||||
if (!(module instanceof Module)) {
|
if (!(module instanceof Module)) {
|
||||||
Log.error('updateDom: Sender should be a module.');
|
Log.error("updateDom: Sender should be a module.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
js/module.js
31
js/module.js
@ -28,7 +28,7 @@ var Module = Class.extend({
|
|||||||
* Is called when the module is started.
|
* Is called when the module is started.
|
||||||
*/
|
*/
|
||||||
start: function() {
|
start: function() {
|
||||||
Log.info('Starting module: ' + this.name);
|
Log.info("Starting module: " + this.name);
|
||||||
},
|
},
|
||||||
|
|
||||||
/* getScripts()
|
/* getScripts()
|
||||||
@ -82,9 +82,9 @@ var Module = Class.extend({
|
|||||||
*/
|
*/
|
||||||
notificationReceived: function(notification, payload, sender) {
|
notificationReceived: function(notification, payload, sender) {
|
||||||
if (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 {
|
} 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.
|
* argument payload mixed - The payload of the notification.
|
||||||
*/
|
*/
|
||||||
socketNotificationReceived: function(notification, payload) {
|
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. *
|
* The methods below don't need subclassing. *
|
||||||
*********************************************/
|
*********************************************/
|
||||||
@ -131,7 +130,7 @@ var Module = Class.extend({
|
|||||||
* It also registers the notification callback.
|
* It also registers the notification callback.
|
||||||
*/
|
*/
|
||||||
socket: function() {
|
socket: function() {
|
||||||
if (typeof this._socket === 'undefined') {
|
if (typeof this._socket === "undefined") {
|
||||||
this._socket = this._socket = new MMSocket(this.name);
|
this._socket = this._socket = new MMSocket(this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +150,7 @@ var Module = Class.extend({
|
|||||||
* return string - File path.
|
* return string - File path.
|
||||||
*/
|
*/
|
||||||
file: function(file) {
|
file: function(file) {
|
||||||
return this.data.path + '/' + file;
|
return this.data.path + "/" + file;
|
||||||
},
|
},
|
||||||
|
|
||||||
/* loadStyles()
|
/* loadStyles()
|
||||||
@ -258,16 +257,16 @@ Module.create = function(name) {
|
|||||||
|
|
||||||
//Define the clone method for later use.
|
//Define the clone method for later use.
|
||||||
function cloneObject(obj) {
|
function cloneObject(obj) {
|
||||||
if (obj === null || typeof obj !== 'object') {
|
if (obj === null || typeof obj !== "object") {
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
var temp = obj.constructor(); // give temp the original obj's constructor
|
var temp = obj.constructor(); // give temp the original obj's constructor
|
||||||
for (var key in obj) {
|
for (var key in obj) {
|
||||||
temp[key] = cloneObject(obj[key]);
|
temp[key] = cloneObject(obj[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
var moduleDefinition = Module.definitions[name];
|
var moduleDefinition = Module.definitions[name];
|
||||||
@ -281,6 +280,6 @@ Module.create = function(name) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Module.register = function(name, moduleDefinition) {
|
Module.register = function(name, moduleDefinition) {
|
||||||
Log.log('Module registered: ' + name);
|
Log.log("Module registered: " + name);
|
||||||
Module.definitions[name] = moduleDefinition;
|
Module.definitions[name] = moduleDefinition;
|
||||||
};
|
};
|
||||||
|
28
js/server.js
28
js/server.js
@ -5,28 +5,28 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var express = require('express');
|
var express = require("express");
|
||||||
var app = require('express')();
|
var app = require("express")();
|
||||||
var server = require('http').Server(app);
|
var server = require("http").Server(app);
|
||||||
var io = require('socket.io')(server);
|
var io = require("socket.io")(server);
|
||||||
var path = require('path');
|
var path = require("path");
|
||||||
|
|
||||||
var Server = function(config, callback) {
|
var Server = function(config, callback) {
|
||||||
console.log("Starting server op port " + config.port + " ... ");
|
console.log("Starting server op port " + config.port + " ... ");
|
||||||
|
|
||||||
server.listen(config.port);
|
server.listen(config.port);
|
||||||
app.use('/js', express.static(__dirname));
|
app.use("/js", express.static(__dirname));
|
||||||
app.use('/config', express.static(path.resolve(__dirname + '/../config')));
|
app.use("/config", express.static(path.resolve(__dirname + "/../config")));
|
||||||
app.use('/css', express.static(path.resolve(__dirname + '/../css')));
|
app.use("/css", express.static(path.resolve(__dirname + "/../css")));
|
||||||
app.use('/fonts', express.static(path.resolve(__dirname + '/../fonts')));
|
app.use("/fonts", express.static(path.resolve(__dirname + "/../fonts")));
|
||||||
app.use('/modules', express.static(path.resolve(__dirname + '/../modules')));
|
app.use("/modules", express.static(path.resolve(__dirname + "/../modules")));
|
||||||
app.use('/vendor', express.static(path.resolve(__dirname + '/../vendor')));
|
app.use("/vendor", express.static(path.resolve(__dirname + "/../vendor")));
|
||||||
|
|
||||||
app.get('/', function (req, res) {
|
app.get("/", function(req, res) {
|
||||||
res.sendFile(path.resolve(__dirname + '/../index.html'));
|
res.sendFile(path.resolve(__dirname + "/../index.html"));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === "function") {
|
||||||
callback(app, io);
|
callback(app, io);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
13
js/socket.js
13
js/socket.js
@ -11,22 +11,21 @@ var MMSocket = function(moduleName) {
|
|||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (typeof moduleName !== 'string') {
|
if (typeof moduleName !== "string") {
|
||||||
throw new Error('Please set the module name for the MMSocket.');
|
throw new Error("Please set the module name for the MMSocket.");
|
||||||
}
|
}
|
||||||
|
|
||||||
self.moduleName = moduleName;
|
self.moduleName = moduleName;
|
||||||
|
|
||||||
|
self.socket = io("http://localhost:8080");
|
||||||
self.socket = io('http://localhost:8080');
|
self.socket.on("notification", function(data) {
|
||||||
self.socket.on('notification', function (data) {
|
|
||||||
MM.sendNotification(data.notification, data.payload, Socket);
|
MM.sendNotification(data.notification, data.payload, Socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sendMessage: function(notification, payload, sender) {
|
sendMessage: function(notification, payload, sender) {
|
||||||
Log.log('Send socket message: ' + notification);
|
Log.log("Send socket message: " + notification);
|
||||||
self.socket.emit('notification', {
|
self.socket.emit("notification", {
|
||||||
notification: notification,
|
notification: notification,
|
||||||
sender: sender,
|
sender: sender,
|
||||||
payload: payload
|
payload: payload
|
||||||
|
@ -1,40 +1,39 @@
|
|||||||
var MMSocket = function(moduleName) {
|
var MMSocket = function(moduleName) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (typeof moduleName !== 'string') {
|
if (typeof moduleName !== "string") {
|
||||||
throw new Error('Please set the module name for the MMSocket.');
|
throw new Error("Please set the module name for the MMSocket.");
|
||||||
}
|
}
|
||||||
|
|
||||||
self.moduleName = moduleName;
|
self.moduleName = moduleName;
|
||||||
|
|
||||||
// Private Methods
|
// Private Methods
|
||||||
socket = io.connect('/' + self.moduleName);
|
socket = io.connect("/" + self.moduleName);
|
||||||
var notificationCallback = function() {};
|
var notificationCallback = function() {};
|
||||||
|
|
||||||
var onevent = socket.onevent;
|
var onevent = socket.onevent;
|
||||||
socket.onevent = function (packet) {
|
socket.onevent = function(packet) {
|
||||||
var args = packet.data || [];
|
var args = packet.data || [];
|
||||||
onevent.call (this, packet); // original call
|
onevent.call(this, packet); // original call
|
||||||
packet.data = ["*"].concat(args);
|
packet.data = ["*"].concat(args);
|
||||||
onevent.call(this, packet); // additional call to catch-all
|
onevent.call(this, packet); // additional call to catch-all
|
||||||
};
|
};
|
||||||
|
|
||||||
// register catch all.
|
// register catch all.
|
||||||
socket.on('*', function (notification, payload) {
|
socket.on("*", function(notification, payload) {
|
||||||
if (notification !== '*') {
|
if (notification !== "*") {
|
||||||
//console.log('Received notification: ' + notification +', payload: ' + payload);
|
//console.log('Received notification: ' + notification +', payload: ' + payload);
|
||||||
notificationCallback(notification, payload);
|
notificationCallback(notification, payload);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Public Methods
|
// Public Methods
|
||||||
this.setNotificationCallback = function(callback) {
|
this.setNotificationCallback = function(callback) {
|
||||||
notificationCallback = callback;
|
notificationCallback = callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.sendNotification = function(notification, payload) {
|
this.sendNotification = function(notification, payload) {
|
||||||
if (typeof payload === 'undefined') {
|
if (typeof payload === "undefined") {
|
||||||
payload = {};
|
payload = {};
|
||||||
}
|
}
|
||||||
socket.emit(notification, payload);
|
socket.emit(notification, payload);
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Module.register('alert',{
|
Module.register("alert",{
|
||||||
defaults: {
|
defaults: {
|
||||||
// scale|slide|genie|jelly|flip|bouncyflip|exploader
|
// scale|slide|genie|jelly|flip|bouncyflip|exploader
|
||||||
effect: "slide",
|
effect: "slide",
|
||||||
// scale|slide|genie|jelly|flip|bouncyflip|exploader
|
// scale|slide|genie|jelly|flip|bouncyflip|exploader
|
||||||
alert_effect:"jelly",
|
alert_effect: "jelly",
|
||||||
//time a notification is displayed in seconds
|
//time a notification is displayed in seconds
|
||||||
display_time: 3500,
|
display_time: 3500,
|
||||||
//Position
|
//Position
|
||||||
@ -21,100 +21,97 @@ Module.register('alert',{
|
|||||||
welcome_message: "Welcome, start was successfull!"
|
welcome_message: "Welcome, start was successfull!"
|
||||||
},
|
},
|
||||||
getScripts: function() {
|
getScripts: function() {
|
||||||
return ["classie.js", "modernizr.custom.js", 'notificationFx.js'];
|
return ["classie.js", "modernizr.custom.js", "notificationFx.js"];
|
||||||
},
|
},
|
||||||
getStyles: function() {
|
getStyles: function() {
|
||||||
return ['ns-default.css'];
|
return ["ns-default.css"];
|
||||||
},
|
},
|
||||||
show_notification: function (message) {
|
show_notification: function(message) {
|
||||||
if (this.config.effect == "slide"){this.config.effect=this.config.effect + "-" + this.config.position}
|
if (this.config.effect == "slide") {this.config.effect = this.config.effect + "-" + this.config.position;}
|
||||||
message = "<span class='thin' style='line-height: 35px; font-size:24px' color='#4A4A4A'>" + message.title + "</span><br /><span class='light' style='font-size:28px;line-height: 30px;'>" + message.message + "</span>"
|
message = "<span class='thin' style='line-height: 35px; font-size:24px' color='#4A4A4A'>" + message.title + "</span><br /><span class='light' style='font-size:28px;line-height: 30px;'>" + message.message + "</span>";
|
||||||
new NotificationFx({
|
new NotificationFx({
|
||||||
message : message,
|
message: message,
|
||||||
layout : "growl",
|
layout: "growl",
|
||||||
effect : this.config.effect,
|
effect: this.config.effect,
|
||||||
ttl: this.config.display_time
|
ttl: this.config.display_time
|
||||||
}).show();
|
}).show();
|
||||||
},
|
},
|
||||||
show_alert: function (params, sender) {
|
show_alert: function(params, sender) {
|
||||||
var self = this
|
var self = this;
|
||||||
//Set standard params if not provided by module
|
//Set standard params if not provided by module
|
||||||
if (typeof params.timer === 'undefined') { params.timer = null; }
|
if (typeof params.timer === "undefined") { params.timer = null; }
|
||||||
if (typeof params.imageHeight === 'undefined') { params.imageHeight = "80px"; }
|
if (typeof params.imageHeight === "undefined") { params.imageHeight = "80px"; }
|
||||||
if (typeof params.imageUrl === 'undefined') {
|
if (typeof params.imageUrl === "undefined") {
|
||||||
params.imageUrl = null;
|
params.imageUrl = null;
|
||||||
image = ""
|
image = "";
|
||||||
}
|
} else {
|
||||||
else {
|
image = "<img src='" + (params.imageUrl).toString() + "' height=" + (params.imageHeight).toString() + " style='margin-bottom: 10px;'/><br />";
|
||||||
image = "<img src='" + params["imageUrl"] + "' height=" + params.imageHeight + " style='margin-bottom: 10px;'/><br />"
|
|
||||||
}
|
}
|
||||||
//Create overlay
|
//Create overlay
|
||||||
var overlay = document.createElement("div");
|
var overlay = document.createElement("div");
|
||||||
overlay.id = "overlay"
|
overlay.id = "overlay";
|
||||||
overlay.innerHTML += '<div class="black_overlay"></div>';
|
overlay.innerHTML += "<div class=\"black_overlay\"></div>";
|
||||||
document.body.insertBefore(overlay, document.body.firstChild);
|
document.body.insertBefore(overlay, document.body.firstChild);
|
||||||
|
|
||||||
//If module already has an open alert close it
|
//If module already has an open alert close it
|
||||||
if (this.alerts[sender.name]){
|
if (this.alerts[sender.name]) {
|
||||||
this.hide_alert(sender)
|
this.hide_alert(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
message = "<span class='light' style='line-height: 35px; font-size:30px' color='#4A4A4A'>" + params.title + "</span><br /><span class='thin' style='font-size:22px;line-height: 30px;'>" + params.message + "</span>"
|
message = "<span class='light' style='line-height: 35px; font-size:30px' color='#4A4A4A'>" + params.title + "</span><br /><span class='thin' style='font-size:22px;line-height: 30px;'>" + params.message + "</span>";
|
||||||
//Store alert in this.alerts
|
//Store alert in this.alerts
|
||||||
this.alerts[sender.name] = new NotificationFx({
|
this.alerts[sender.name] = new NotificationFx({
|
||||||
message : image + message,
|
message: image + message,
|
||||||
effect : this.config.alert_effect,
|
effect: this.config.alert_effect,
|
||||||
ttl: params.timer,
|
ttl: params.timer,
|
||||||
al_no: "ns-alert"
|
al_no: "ns-alert"
|
||||||
});
|
});
|
||||||
//Show alert
|
//Show alert
|
||||||
this.alerts[sender.name].show()
|
this.alerts[sender.name].show();
|
||||||
//Add timer to dismiss alert and overlay
|
//Add timer to dismiss alert and overlay
|
||||||
if (params.timer) {
|
if (params.timer) {
|
||||||
setTimeout( function() {
|
setTimeout(function() {
|
||||||
self.hide_alert(sender)
|
self.hide_alert(sender);
|
||||||
}, params.timer );
|
}, params.timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
hide_alert: function (sender) {
|
hide_alert: function(sender) {
|
||||||
//Dismiss alert and remove from this.alerts
|
//Dismiss alert and remove from this.alerts
|
||||||
this.alerts[sender.name].dismiss()
|
this.alerts[sender.name].dismiss();
|
||||||
this.alerts[sender.name] = null
|
this.alerts[sender.name] = null;
|
||||||
//Remove overlay
|
//Remove overlay
|
||||||
var overlay = document.getElementById("overlay");
|
var overlay = document.getElementById("overlay");
|
||||||
overlay.parentNode.removeChild(overlay);
|
overlay.parentNode.removeChild(overlay);
|
||||||
},
|
},
|
||||||
setPosition: function (pos) {
|
setPosition: function(pos) {
|
||||||
//Add css to body depending on the set position for notifications
|
//Add css to body depending on the set position for notifications
|
||||||
var sheet = document.createElement('style')
|
var sheet = document.createElement("style");
|
||||||
if (pos == "center"){sheet.innerHTML = ".ns-box {margin-left: auto; margin-right: auto;text-align: center;}";}
|
if (pos == "center") {sheet.innerHTML = ".ns-box {margin-left: auto; margin-right: auto;text-align: center;}";}
|
||||||
if (pos == "right"){sheet.innerHTML = ".ns-box {margin-left: auto;text-align: right;}";}
|
if (pos == "right") {sheet.innerHTML = ".ns-box {margin-left: auto;text-align: right;}";}
|
||||||
if (pos == "left"){sheet.innerHTML = ".ns-box {margin-right: auto;text-align: left;}";}
|
if (pos == "left") {sheet.innerHTML = ".ns-box {margin-right: auto;text-align: left;}";}
|
||||||
document.body.appendChild(sheet);
|
document.body.appendChild(sheet);
|
||||||
|
|
||||||
},
|
},
|
||||||
notificationReceived: function(notification, payload, sender) {
|
notificationReceived: function(notification, payload, sender) {
|
||||||
if (notification === 'SHOW_ALERT') {
|
if (notification === "SHOW_ALERT") {
|
||||||
if (typeof payload.type === 'undefined') { payload.type = "alert"; }
|
if (typeof payload.type === "undefined") { payload.type = "alert"; }
|
||||||
if (payload.type == "alert"){
|
if (payload.type == "alert") {
|
||||||
this.show_alert(payload, sender)
|
this.show_alert(payload, sender);
|
||||||
|
} else if (payload.type = "notification") {
|
||||||
|
this.show_notification(payload);
|
||||||
}
|
}
|
||||||
else if (payload.type = "notification"){
|
} else if (notification === "HIDE_ALERT") {
|
||||||
this.show_notification(payload)
|
this.hide_alert(sender);
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (notification === 'HIDE_ALERT') {
|
|
||||||
this.hide_alert(sender)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
start: function() {
|
start: function() {
|
||||||
this.alerts = {}
|
this.alerts = {};
|
||||||
this.setPosition(this.config.position)
|
this.setPosition(this.config.position);
|
||||||
if (this.config.welcome_message){
|
if (this.config.welcome_message) {
|
||||||
this.show_notification({title: "MagicMirror Notification", message: this.config.welcome_message})
|
this.show_notification({title: "MagicMirror Notification", message: this.config.welcome_message});
|
||||||
}
|
}
|
||||||
Log.info('Starting module: ' + this.name);
|
Log.info("Starting module: " + this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
@ -7,74 +7,73 @@
|
|||||||
* classie.remove( elem, 'my-unwanted-class' )
|
* classie.remove( elem, 'my-unwanted-class' )
|
||||||
* classie.toggle( elem, 'my-class' )
|
* classie.toggle( elem, 'my-class' )
|
||||||
*/
|
*/
|
||||||
|
// jscs:disable
|
||||||
/*jshint browser: true, strict: true, undef: true */
|
/*jshint browser: true, strict: true, undef: true */
|
||||||
/*global define: false */
|
/*global define: false */
|
||||||
|
|
||||||
( function( window ) {
|
(function(window) {
|
||||||
|
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
// class helper functions from bonzo https://github.com/ded/bonzo
|
// class helper functions from bonzo https://github.com/ded/bonzo
|
||||||
|
|
||||||
function classReg( className ) {
|
function classReg(className) {
|
||||||
return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
|
return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// classList support for class management
|
// classList support for class management
|
||||||
// altho to be fair, the api sucks because it won't accept multiple classes at once
|
// altho to be fair, the api sucks because it won't accept multiple classes at once
|
||||||
var hasClass, addClass, removeClass;
|
var hasClass, addClass, removeClass;
|
||||||
|
|
||||||
if ( 'classList' in document.documentElement ) {
|
if ("classList" in document.documentElement) {
|
||||||
hasClass = function( elem, c ) {
|
hasClass = function(elem, c) {
|
||||||
return elem.classList.contains( c );
|
return elem.classList.contains(c);
|
||||||
};
|
};
|
||||||
addClass = function( elem, c ) {
|
addClass = function(elem, c) {
|
||||||
elem.classList.add( c );
|
elem.classList.add(c);
|
||||||
};
|
};
|
||||||
removeClass = function( elem, c ) {
|
removeClass = function(elem, c) {
|
||||||
elem.classList.remove( c );
|
elem.classList.remove(c);
|
||||||
};
|
};
|
||||||
}
|
} else {
|
||||||
else {
|
hasClass = function(elem, c) {
|
||||||
hasClass = function( elem, c ) {
|
return classReg(c).test(elem.className);
|
||||||
return classReg( c ).test( elem.className );
|
};
|
||||||
};
|
addClass = function(elem, c) {
|
||||||
addClass = function( elem, c ) {
|
if (!hasClass(elem, c)) {
|
||||||
if ( !hasClass( elem, c ) ) {
|
elem.className = elem.className + " " + c;
|
||||||
elem.className = elem.className + ' ' + c;
|
}
|
||||||
}
|
};
|
||||||
};
|
removeClass = function(elem, c) {
|
||||||
removeClass = function( elem, c ) {
|
elem.className = elem.className.replace(classReg(c), " ");
|
||||||
elem.className = elem.className.replace( classReg( c ), ' ' );
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleClass( elem, c ) {
|
function toggleClass(elem, c) {
|
||||||
var fn = hasClass( elem, c ) ? removeClass : addClass;
|
var fn = hasClass(elem, c) ? removeClass : addClass;
|
||||||
fn( elem, c );
|
fn(elem, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
var classie = {
|
var classie = {
|
||||||
// full names
|
// full names
|
||||||
hasClass: hasClass,
|
hasClass: hasClass,
|
||||||
addClass: addClass,
|
addClass: addClass,
|
||||||
removeClass: removeClass,
|
removeClass: removeClass,
|
||||||
toggleClass: toggleClass,
|
toggleClass: toggleClass,
|
||||||
// short names
|
// short names
|
||||||
has: hasClass,
|
has: hasClass,
|
||||||
add: addClass,
|
add: addClass,
|
||||||
remove: removeClass,
|
remove: removeClass,
|
||||||
toggle: toggleClass
|
toggle: toggleClass
|
||||||
};
|
};
|
||||||
|
|
||||||
// transport
|
// transport
|
||||||
if ( typeof define === 'function' && define.amd ) {
|
if (typeof define === "function" && define.amd) {
|
||||||
// AMD
|
// AMD
|
||||||
define( classie );
|
define(classie);
|
||||||
} else {
|
} else {
|
||||||
// browser global
|
// browser global
|
||||||
window.classie = classie;
|
window.classie = classie;
|
||||||
}
|
}
|
||||||
|
|
||||||
})( window );
|
})(window);
|
||||||
|
File diff suppressed because one or more lines are too long
@ -8,27 +8,28 @@
|
|||||||
* Copyright 2014, Codrops
|
* Copyright 2014, Codrops
|
||||||
* http://www.codrops.com
|
* http://www.codrops.com
|
||||||
*/
|
*/
|
||||||
;( function( window ) {
|
// jscs:disable
|
||||||
|
;(function(window) {
|
||||||
|
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
var docElem = window.document.documentElement,
|
var docElem = window.document.documentElement,
|
||||||
support = { animations : Modernizr.cssanimations },
|
support = {animations: Modernizr.cssanimations},
|
||||||
animEndEventNames = {
|
animEndEventNames = {
|
||||||
'WebkitAnimation' : 'webkitAnimationEnd',
|
"WebkitAnimation": "webkitAnimationEnd",
|
||||||
'OAnimation' : 'oAnimationEnd',
|
"OAnimation": "oAnimationEnd",
|
||||||
'msAnimation' : 'MSAnimationEnd',
|
"msAnimation": "MSAnimationEnd",
|
||||||
'animation' : 'animationend'
|
"animation": "animationend"
|
||||||
},
|
},
|
||||||
// animation end event name
|
// animation end event name
|
||||||
animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ];
|
animEndEventName = animEndEventNames[ Modernizr.prefixed("animation") ];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* extend obj function
|
* extend obj function
|
||||||
*/
|
*/
|
||||||
function extend( a, b ) {
|
function extend(a, b) {
|
||||||
for( var key in b ) {
|
for (var key in b) {
|
||||||
if( b.hasOwnProperty( key ) ) {
|
if (b.hasOwnProperty(key)) {
|
||||||
a[key] = b[key];
|
a[key] = b[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,9 +39,9 @@
|
|||||||
/**
|
/**
|
||||||
* NotificationFx function
|
* NotificationFx function
|
||||||
*/
|
*/
|
||||||
function NotificationFx( options ) {
|
function NotificationFx(options) {
|
||||||
this.options = extend( {}, this.options );
|
this.options = extend({}, this.options);
|
||||||
extend( this.options, options );
|
extend(this.options, options);
|
||||||
this._init();
|
this._init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,28 +51,28 @@
|
|||||||
NotificationFx.prototype.options = {
|
NotificationFx.prototype.options = {
|
||||||
// element to which the notification will be appended
|
// element to which the notification will be appended
|
||||||
// defaults to the document.body
|
// defaults to the document.body
|
||||||
wrapper : document.body,
|
wrapper: document.body,
|
||||||
// the message
|
// the message
|
||||||
message : 'yo!',
|
message: "yo!",
|
||||||
// layout type: growl|attached|bar|other
|
// layout type: growl|attached|bar|other
|
||||||
layout : 'growl',
|
layout: "growl",
|
||||||
// effects for the specified layout:
|
// effects for the specified layout:
|
||||||
// for growl layout: scale|slide|genie|jelly
|
// for growl layout: scale|slide|genie|jelly
|
||||||
// for attached layout: flip|bouncyflip
|
// for attached layout: flip|bouncyflip
|
||||||
// for other layout: boxspinner|cornerexpand|loadingcircle|thumbslider
|
// for other layout: boxspinner|cornerexpand|loadingcircle|thumbslider
|
||||||
// ...
|
// ...
|
||||||
effect : 'slide',
|
effect: "slide",
|
||||||
// notice, warning, error, success
|
// notice, warning, error, success
|
||||||
// will add class ns-type-warning, ns-type-error or ns-type-success
|
// will add class ns-type-warning, ns-type-error or ns-type-success
|
||||||
type : 'notice',
|
type: "notice",
|
||||||
// if the user doesn´t close the notification then we remove it
|
// if the user doesn´t close the notification then we remove it
|
||||||
// after the following time
|
// after the following time
|
||||||
ttl : 6000,
|
ttl: 6000,
|
||||||
al_no: "ns-box",
|
al_no: "ns-box",
|
||||||
// callbacks
|
// callbacks
|
||||||
onClose : function() { return false; },
|
onClose: function() { return false; },
|
||||||
onOpen : function() { return false; }
|
onOpen: function() { return false; }
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init function
|
* init function
|
||||||
@ -79,29 +80,29 @@
|
|||||||
*/
|
*/
|
||||||
NotificationFx.prototype._init = function() {
|
NotificationFx.prototype._init = function() {
|
||||||
// create HTML structure
|
// create HTML structure
|
||||||
this.ntf = document.createElement( 'div' );
|
this.ntf = document.createElement("div");
|
||||||
this.ntf.className = this.options.al_no + ' ns-' + this.options.layout + ' ns-effect-' + this.options.effect + ' ns-type-' + this.options.type;
|
this.ntf.className = this.options.al_no + " ns-" + this.options.layout + " ns-effect-" + this.options.effect + " ns-type-" + this.options.type;
|
||||||
var strinner = '<div class="ns-box-inner">';
|
var strinner = "<div class=\"ns-box-inner\">";
|
||||||
strinner += this.options.message;
|
strinner += this.options.message;
|
||||||
strinner += '</div>';
|
strinner += "</div>";
|
||||||
this.ntf.innerHTML = strinner;
|
this.ntf.innerHTML = strinner;
|
||||||
|
|
||||||
// append to body or the element specified in options.wrapper
|
// append to body or the element specified in options.wrapper
|
||||||
this.options.wrapper.insertBefore( this.ntf, this.options.wrapper.nextSibling );
|
this.options.wrapper.insertBefore(this.ntf, this.options.wrapper.nextSibling);
|
||||||
|
|
||||||
// dismiss after [options.ttl]ms
|
// dismiss after [options.ttl]ms
|
||||||
var self = this;
|
var self = this;
|
||||||
if (this.options.ttl){
|
if (this.options.ttl) {
|
||||||
this.dismissttl = setTimeout( function() {
|
this.dismissttl = setTimeout(function() {
|
||||||
if( self.active ) {
|
if (self.active) {
|
||||||
self.dismiss();
|
self.dismiss();
|
||||||
}
|
}
|
||||||
}, this.options.ttl );
|
}, this.options.ttl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// init events
|
// init events
|
||||||
this._initEvents();
|
this._initEvents();
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init events
|
* init events
|
||||||
@ -109,18 +110,18 @@
|
|||||||
NotificationFx.prototype._initEvents = function() {
|
NotificationFx.prototype._initEvents = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
// dismiss notification by tapping on it if someone has a touchscreen
|
// dismiss notification by tapping on it if someone has a touchscreen
|
||||||
this.ntf.querySelector( '.ns-box-inner' ).addEventListener( 'click', function() { self.dismiss(); } );
|
this.ntf.querySelector(".ns-box-inner").addEventListener("click", function() { self.dismiss(); });
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* show the notification
|
* show the notification
|
||||||
*/
|
*/
|
||||||
NotificationFx.prototype.show = function() {
|
NotificationFx.prototype.show = function() {
|
||||||
this.active = true;
|
this.active = true;
|
||||||
classie.remove( this.ntf, 'ns-hide' );
|
classie.remove(this.ntf, "ns-hide");
|
||||||
classie.add( this.ntf, 'ns-show' );
|
classie.add(this.ntf, "ns-show");
|
||||||
this.options.onOpen();
|
this.options.onOpen();
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dismiss the notification
|
* dismiss the notification
|
||||||
@ -128,35 +129,34 @@
|
|||||||
NotificationFx.prototype.dismiss = function() {
|
NotificationFx.prototype.dismiss = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.active = false;
|
this.active = false;
|
||||||
clearTimeout( this.dismissttl );
|
clearTimeout(this.dismissttl);
|
||||||
classie.remove( this.ntf, 'ns-show' );
|
classie.remove(this.ntf, "ns-show");
|
||||||
setTimeout( function() {
|
setTimeout(function() {
|
||||||
classie.add( self.ntf, 'ns-hide' );
|
classie.add(self.ntf, "ns-hide");
|
||||||
|
|
||||||
// callback
|
// callback
|
||||||
self.options.onClose();
|
self.options.onClose();
|
||||||
}, 25 );
|
}, 25);
|
||||||
|
|
||||||
// after animation ends remove ntf from the DOM
|
// after animation ends remove ntf from the DOM
|
||||||
var onEndAnimationFn = function( ev ) {
|
var onEndAnimationFn = function(ev) {
|
||||||
if( support.animations ) {
|
if (support.animations) {
|
||||||
if( ev.target !== self.ntf ) return false;
|
if (ev.target !== self.ntf) return false;
|
||||||
this.removeEventListener( animEndEventName, onEndAnimationFn );
|
this.removeEventListener(animEndEventName, onEndAnimationFn);
|
||||||
}
|
}
|
||||||
self.options.wrapper.removeChild( this );
|
self.options.wrapper.removeChild(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
if( support.animations ) {
|
if (support.animations) {
|
||||||
this.ntf.addEventListener( animEndEventName, onEndAnimationFn );
|
this.ntf.addEventListener(animEndEventName, onEndAnimationFn);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
onEndAnimationFn();
|
onEndAnimationFn();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add to global namespace
|
* add to global namespace
|
||||||
*/
|
*/
|
||||||
window.NotificationFx = NotificationFx;
|
window.NotificationFx = NotificationFx;
|
||||||
|
|
||||||
} )( window );
|
})(window);
|
||||||
|
@ -7,55 +7,55 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Module.register('calendar',{
|
Module.register("calendar",{
|
||||||
|
|
||||||
// Define module defaults
|
// Define module defaults
|
||||||
defaults: {
|
defaults: {
|
||||||
maximumEntries: 10, // Total Maximum Entries
|
maximumEntries: 10, // Total Maximum Entries
|
||||||
maximumNumberOfDays: 365,
|
maximumNumberOfDays: 365,
|
||||||
displaySymbol: true,
|
displaySymbol: true,
|
||||||
defaultSymbol: 'calendar', // Fontawsome Symbol see http://fontawesome.io/cheatsheet/
|
defaultSymbol: "calendar", // Fontawsome Symbol see http://fontawesome.io/cheatsheet/
|
||||||
maxTitleLength: 25,
|
maxTitleLength: 25,
|
||||||
fetchInterval: 5 * 60 * 1000, // Update every 5 minutes.
|
fetchInterval: 5 * 60 * 1000, // Update every 5 minutes.
|
||||||
animationSpeed: 2000,
|
animationSpeed: 2000,
|
||||||
fade: true,
|
fade: true,
|
||||||
fadePoint: 0.25, // Start on 1/4th of the list.
|
fadePoint: 0.25, // Start on 1/4th of the list.
|
||||||
calendars: [
|
calendars: [
|
||||||
{
|
{
|
||||||
symbol: 'calendar',
|
symbol: "calendar",
|
||||||
url: 'http://www.calendarlabs.com/templates/ical/US-Holidays.ics',
|
url: "http://www.calendarlabs.com/templates/ical/US-Holidays.ics",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
titleReplace: {
|
titleReplace: {
|
||||||
'De verjaardag van ' : ''
|
"De verjaardag van ": ""
|
||||||
},
|
},
|
||||||
loadingText: 'Loading events …',
|
loadingText: "Loading events …",
|
||||||
emptyCalendarText: 'No upcoming events.',
|
emptyCalendarText: "No upcoming events.",
|
||||||
|
|
||||||
// TODO: It would be nice if there is a way to get this from the Moment.js locale.
|
// TODO: It would be nice if there is a way to get this from the Moment.js locale.
|
||||||
todayText: 'Today'
|
todayText: "Today"
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getStyles: function() {
|
getStyles: function() {
|
||||||
return ['calendar.css', 'font-awesome.css'];
|
return ["calendar.css", "font-awesome.css"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function() {
|
getScripts: function() {
|
||||||
return ['moment.js'];
|
return ["moment.js"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Override start method.
|
// Override start method.
|
||||||
start: function() {
|
start: function() {
|
||||||
Log.log('Starting module: ' + this.name);
|
Log.log("Starting module: " + this.name);
|
||||||
|
|
||||||
// Set locale.
|
// Set locale.
|
||||||
moment.locale(config.language);
|
moment.locale(config.language);
|
||||||
|
|
||||||
for (var c in this.config.calendars) {
|
for (var c in this.config.calendars) {
|
||||||
var calendar = this.config.calendars[c];
|
var calendar = this.config.calendars[c];
|
||||||
calendar.url = calendar.url.replace('webcal://', 'http://');
|
calendar.url = calendar.url.replace("webcal://", "http://");
|
||||||
this.addCalendar(calendar.url);
|
this.addCalendar(calendar.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,17 +65,17 @@ Module.register('calendar',{
|
|||||||
|
|
||||||
// Override socket notification handler.
|
// Override socket notification handler.
|
||||||
socketNotificationReceived: function(notification, payload) {
|
socketNotificationReceived: function(notification, payload) {
|
||||||
if (notification === 'CALENDAR_EVENTS') {
|
if (notification === "CALENDAR_EVENTS") {
|
||||||
if (this.hasCalendarURL(payload.url)) {
|
if (this.hasCalendarURL(payload.url)) {
|
||||||
this.calendarData[payload.url] = payload.events;
|
this.calendarData[payload.url] = payload.events;
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
} else if(notification === 'FETCH_ERROR') {
|
} else if (notification === "FETCH_ERROR") {
|
||||||
Log.error('Calendar Error. Could not fetch calendar: ' + payload.url);
|
Log.error("Calendar Error. Could not fetch calendar: " + payload.url);
|
||||||
} else if(notification === 'INCORRECT_URL') {
|
} else if (notification === "INCORRECT_URL") {
|
||||||
Log.error('Calendar Error. Incorrect url: ' + payload.url);
|
Log.error("Calendar Error. Incorrect url: " + payload.url);
|
||||||
} else {
|
} else {
|
||||||
Log.log('Calendar received an unknown socket notification: '+notification);
|
Log.log("Calendar received an unknown socket notification: " + notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateDom(this.config.animationSpeed);
|
this.updateDom(this.config.animationSpeed);
|
||||||
@ -115,7 +115,7 @@ Module.register('calendar',{
|
|||||||
eventWrapper.appendChild(titleWrapper);
|
eventWrapper.appendChild(titleWrapper);
|
||||||
|
|
||||||
var timeWrapper = document.createElement("td");
|
var timeWrapper = document.createElement("td");
|
||||||
timeWrapper.innerHTML = (event.today) ? this.config.todayText : moment(event.startDate,'x').fromNow();
|
timeWrapper.innerHTML = (event.today) ? this.config.todayText : moment(event.startDate,"x").fromNow();
|
||||||
// timeWrapper.innerHTML = moment(event.startDate,'x').format('lll');
|
// timeWrapper.innerHTML = moment(event.startDate,'x').format('lll');
|
||||||
timeWrapper.className = "time light";
|
timeWrapper.className = "time light";
|
||||||
eventWrapper.appendChild(timeWrapper);
|
eventWrapper.appendChild(timeWrapper);
|
||||||
@ -164,7 +164,7 @@ Module.register('calendar',{
|
|||||||
*/
|
*/
|
||||||
createEventList: function() {
|
createEventList: function() {
|
||||||
var events = [];
|
var events = [];
|
||||||
var today = moment().startOf('day');
|
var today = moment().startOf("day");
|
||||||
for (var c in this.calendarData) {
|
for (var c in this.calendarData) {
|
||||||
var calendar = this.calendarData[c];
|
var calendar = this.calendarData[c];
|
||||||
for (var e in calendar) {
|
for (var e in calendar) {
|
||||||
@ -175,7 +175,7 @@ Module.register('calendar',{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
events.sort(function(a,b) {
|
events.sort(function(a, b) {
|
||||||
return a.startDate - b.startDate;
|
return a.startDate - b.startDate;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ Module.register('calendar',{
|
|||||||
* argument url sting - Url to add.
|
* argument url sting - Url to add.
|
||||||
*/
|
*/
|
||||||
addCalendar: function(url) {
|
addCalendar: function(url) {
|
||||||
this.sendSocketNotification('ADD_CALENDAR', {
|
this.sendSocketNotification("ADD_CALENDAR", {
|
||||||
url: url,
|
url: url,
|
||||||
maximumEntries: this.config.maximumEntries,
|
maximumEntries: this.config.maximumEntries,
|
||||||
maximumNumberOfDays: this.config.maximumNumberOfDays,
|
maximumNumberOfDays: this.config.maximumNumberOfDays,
|
||||||
@ -206,7 +206,7 @@ Module.register('calendar',{
|
|||||||
symbolForUrl: function(url) {
|
symbolForUrl: function(url) {
|
||||||
for (var c in this.config.calendars) {
|
for (var c in this.config.calendars) {
|
||||||
var calendar = this.config.calendars[c];
|
var calendar = this.config.calendars[c];
|
||||||
if (calendar.url === url && typeof calendar.symbol === 'string') {
|
if (calendar.url === url && typeof calendar.symbol === "string") {
|
||||||
return calendar.symbol;
|
return calendar.symbol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var NodeHelper = require('node_helper');
|
var NodeHelper = require("node_helper");
|
||||||
var ical = require('ical');
|
var ical = require("ical");
|
||||||
var moment = require('moment');
|
var moment = require("moment");
|
||||||
var validUrl = require('valid-url');
|
var validUrl = require("valid-url");
|
||||||
|
|
||||||
var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumberOfDays) {
|
var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumberOfDays) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -27,7 +27,6 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
|
|||||||
clearTimeout(reloadTimer);
|
clearTimeout(reloadTimer);
|
||||||
reloadTimer = null;
|
reloadTimer = null;
|
||||||
|
|
||||||
|
|
||||||
ical.fromURL(url, {}, function(err, data) {
|
ical.fromURL(url, {}, function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
fetchFailedCallback(self, err);
|
fetchFailedCallback(self, err);
|
||||||
@ -38,12 +37,12 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
|
|||||||
//console.log(data);
|
//console.log(data);
|
||||||
newEvents = [];
|
newEvents = [];
|
||||||
|
|
||||||
var limitFunction = function (date, i){return i < maximumEntries;};
|
var limitFunction = function(date, i) {return i < maximumEntries;};
|
||||||
|
|
||||||
for (var e in data) {
|
for (var e in data) {
|
||||||
var event = data[e];
|
var event = data[e];
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
var today = moment().startOf('day');
|
var today = moment().startOf("day");
|
||||||
|
|
||||||
//console.log(event);
|
//console.log(event);
|
||||||
|
|
||||||
@ -51,19 +50,19 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
|
|||||||
// Ugly fix to solve the facebook birthday issue.
|
// Ugly fix to solve the facebook birthday issue.
|
||||||
// Otherwise, the recurring events only show the birthday for next year.
|
// Otherwise, the recurring events only show the birthday for next year.
|
||||||
var isFacebookBirthday = false;
|
var isFacebookBirthday = false;
|
||||||
if (typeof event.uid !== 'undefined') {
|
if (typeof event.uid !== "undefined") {
|
||||||
if (event.uid.indexOf('@facebook.com') !== -1) {
|
if (event.uid.indexOf("@facebook.com") !== -1) {
|
||||||
isFacebookBirthday = true;
|
isFacebookBirthday = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type === 'VEVENT') {
|
if (event.type === "VEVENT") {
|
||||||
var startDate = (event.start.length === 8) ? moment(event.start, 'YYYYMMDD') : moment(new Date(event.start));
|
var startDate = (event.start.length === 8) ? moment(event.start, "YYYYMMDD") : moment(new Date(event.start));
|
||||||
if (event.start.length === 8) {
|
if (event.start.length === 8) {
|
||||||
startDate = startDate.startOf('day');
|
startDate = startDate.startOf("day");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof event.rrule != 'undefined' && !isFacebookBirthday) {
|
if (typeof event.rrule != "undefined" && !isFacebookBirthday) {
|
||||||
var rule = event.rrule;
|
var rule = event.rrule;
|
||||||
|
|
||||||
// Check if the timeset is set to this current time.
|
// Check if the timeset is set to this current time.
|
||||||
@ -71,33 +70,32 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
|
|||||||
// This causes the times of the recurring event to be incorrect.
|
// This causes the times of the recurring event to be incorrect.
|
||||||
// By adjusting the timeset property, this issue is solved.
|
// By adjusting the timeset property, this issue is solved.
|
||||||
|
|
||||||
|
|
||||||
if (rule.timeset[0].hour == now.getHours(),
|
if (rule.timeset[0].hour == now.getHours(),
|
||||||
rule.timeset[0].minute == now.getMinutes(),
|
rule.timeset[0].minute == now.getMinutes(),
|
||||||
rule.timeset[0].second == now.getSeconds()) {
|
rule.timeset[0].second == now.getSeconds()) {
|
||||||
|
|
||||||
rule.timeset[0].hour = startDate.format('H');
|
rule.timeset[0].hour = startDate.format("H");
|
||||||
rule.timeset[0].minute = startDate.format('m');
|
rule.timeset[0].minute = startDate.format("m");
|
||||||
rule.timeset[0].second = startDate.format('s');
|
rule.timeset[0].second = startDate.format("s");
|
||||||
}
|
}
|
||||||
|
|
||||||
var dates = rule.between(today, today.add(maximumNumberOfDays, 'days') , true, limitFunction);
|
var dates = rule.between(today, today.add(maximumNumberOfDays, "days") , true, limitFunction);
|
||||||
console.log(dates);
|
console.log(dates);
|
||||||
for (var d in dates) {
|
for (var d in dates) {
|
||||||
startDate = moment(new Date(dates[d]));
|
startDate = moment(new Date(dates[d]));
|
||||||
newEvents.push({
|
newEvents.push({
|
||||||
title: (typeof event.summary.val !== 'undefined') ? event.summary.val : event.summary,
|
title: (typeof event.summary.val !== "undefined") ? event.summary.val : event.summary,
|
||||||
startDate: startDate.format('x'),
|
startDate: startDate.format("x"),
|
||||||
fullDayEvent: (event.start.length === 8)
|
fullDayEvent: (event.start.length === 8)
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Single event.
|
// Single event.
|
||||||
if (startDate >= today && startDate <= today.add(maximumNumberOfDays, 'days')) {
|
if (startDate >= today && startDate <= today.add(maximumNumberOfDays, "days")) {
|
||||||
newEvents.push({
|
newEvents.push({
|
||||||
title: (typeof event.summary.val !== 'undefined') ? event.summary.val : event.summary,
|
title: (typeof event.summary.val !== "undefined") ? event.summary.val : event.summary,
|
||||||
startDate: startDate.format('x'),
|
startDate: startDate.format("x"),
|
||||||
fullDayEvent: (event.start.length === 8)
|
fullDayEvent: (event.start.length === 8)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -105,7 +103,7 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newEvents.sort(function(a,b) {
|
newEvents.sort(function(a, b) {
|
||||||
return a.startDate - b.startDate;
|
return a.startDate - b.startDate;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -190,14 +188,13 @@ module.exports = NodeHelper.create({
|
|||||||
|
|
||||||
this.fetchers = [];
|
this.fetchers = [];
|
||||||
|
|
||||||
console.log('Starting node helper for: ' + this.name);
|
console.log("Starting node helper for: " + this.name);
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Override socketNotificationReceived method.
|
// Override socketNotificationReceived method.
|
||||||
socketNotificationReceived: function(notification, payload) {
|
socketNotificationReceived: function(notification, payload) {
|
||||||
if (notification === 'ADD_CALENDAR') {
|
if (notification === "ADD_CALENDAR") {
|
||||||
//console.log('ADD_CALENDAR: ');
|
//console.log('ADD_CALENDAR: ');
|
||||||
this.createFetcher(payload.url, payload.fetchInterval, payload.maximumEntries, payload.maximumNumberOfDays);
|
this.createFetcher(payload.url, payload.fetchInterval, payload.maximumEntries, payload.maximumNumberOfDays);
|
||||||
}
|
}
|
||||||
@ -214,28 +211,28 @@ module.exports = NodeHelper.create({
|
|||||||
createFetcher: function(url, fetchInterval, maximumEntries, maximumNumberOfDays) {
|
createFetcher: function(url, fetchInterval, maximumEntries, maximumNumberOfDays) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (!validUrl.isUri(url)){
|
if (!validUrl.isUri(url)) {
|
||||||
self.sendSocketNotification('INCORRECT_URL', {url:url});
|
self.sendSocketNotification("INCORRECT_URL", {url: url});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fetcher;
|
var fetcher;
|
||||||
if (typeof self.fetchers[url] === 'undefined') {
|
if (typeof self.fetchers[url] === "undefined") {
|
||||||
console.log('Create new calendar fetcher for url: ' + url + ' - Interval: ' + fetchInterval);
|
console.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval);
|
||||||
fetcher = new CalendarFetcher(url, fetchInterval, maximumEntries, maximumNumberOfDays);
|
fetcher = new CalendarFetcher(url, fetchInterval, maximumEntries, maximumNumberOfDays);
|
||||||
|
|
||||||
fetcher.onReceive(function(fetcher) {
|
fetcher.onReceive(function(fetcher) {
|
||||||
//console.log('Broadcast events.');
|
//console.log('Broadcast events.');
|
||||||
//console.log(fetcher.events());
|
//console.log(fetcher.events());
|
||||||
|
|
||||||
self.sendSocketNotification('CALENDAR_EVENTS', {
|
self.sendSocketNotification("CALENDAR_EVENTS", {
|
||||||
url: fetcher.url(),
|
url: fetcher.url(),
|
||||||
events: fetcher.events()
|
events: fetcher.events()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
fetcher.onError(function(fetcher, error) {
|
fetcher.onError(function(fetcher, error) {
|
||||||
self.sendSocketNotification('FETCH_ERROR', {
|
self.sendSocketNotification("FETCH_ERROR", {
|
||||||
url: fetcher.url(),
|
url: fetcher.url(),
|
||||||
error: error
|
error: error
|
||||||
});
|
});
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Module.register('clock',{
|
Module.register("clock",{
|
||||||
|
|
||||||
// Module config defaults.
|
// Module config defaults.
|
||||||
defaults: {
|
defaults: {
|
||||||
@ -17,12 +17,12 @@ Module.register('clock',{
|
|||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function() {
|
getScripts: function() {
|
||||||
return ['moment.js'];
|
return ["moment.js"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define start sequence.
|
// Define start sequence.
|
||||||
start: function() {
|
start: function() {
|
||||||
Log.info('Starting module: ' + this.name);
|
Log.info("Starting module: " + this.name);
|
||||||
|
|
||||||
// Schedule update interval.
|
// Schedule update interval.
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -34,7 +34,6 @@ Module.register('clock',{
|
|||||||
moment.locale(config.language);
|
moment.locale(config.language);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// Override dom generator.
|
// Override dom generator.
|
||||||
getDom: function() {
|
getDom: function() {
|
||||||
// Create wrappers.
|
// Create wrappers.
|
||||||
@ -49,9 +48,9 @@ Module.register('clock',{
|
|||||||
secondsWrapper.className = "dimmed";
|
secondsWrapper.className = "dimmed";
|
||||||
|
|
||||||
// Set content of wrappers.
|
// Set content of wrappers.
|
||||||
dateWrapper.innerHTML = moment().format('dddd, LL');
|
dateWrapper.innerHTML = moment().format("dddd, LL");
|
||||||
timeWrapper.innerHTML = moment().format((this.config.timeFormat === 24) ? 'HH:mm' : ('hh:mm'));
|
timeWrapper.innerHTML = moment().format((this.config.timeFormat === 24) ? "HH:mm" : ("hh:mm"));
|
||||||
secondsWrapper.innerHTML = moment().format('ss');
|
secondsWrapper.innerHTML = moment().format("ss");
|
||||||
|
|
||||||
// Combine wrappers.
|
// Combine wrappers.
|
||||||
wrapper.appendChild(dateWrapper);
|
wrapper.appendChild(dateWrapper);
|
||||||
|
@ -7,26 +7,26 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Module.register('compliments',{
|
Module.register("compliments",{
|
||||||
|
|
||||||
// Module config defaults.
|
// Module config defaults.
|
||||||
defaults: {
|
defaults: {
|
||||||
compliments: {
|
compliments: {
|
||||||
morning: [
|
morning: [
|
||||||
'Good morning, handsome!',
|
"Good morning, handsome!",
|
||||||
'Enjoy your day!',
|
"Enjoy your day!",
|
||||||
'How was your sleep?'
|
"How was your sleep?"
|
||||||
],
|
],
|
||||||
afternoon: [
|
afternoon: [
|
||||||
'Hello, beauty!',
|
"Hello, beauty!",
|
||||||
'You look sexy!',
|
"You look sexy!",
|
||||||
'Looking good today!'
|
"Looking good today!"
|
||||||
],
|
],
|
||||||
evening: [
|
evening: [
|
||||||
'Wow, you look hot!',
|
"Wow, you look hot!",
|
||||||
'You look nice!',
|
"You look nice!",
|
||||||
'Hi, sexy!'
|
"Hi, sexy!"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
updateInterval: 30000,
|
updateInterval: 30000,
|
||||||
fadeSpeed: 4000
|
fadeSpeed: 4000
|
||||||
@ -34,12 +34,12 @@ Module.register('compliments',{
|
|||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function() {
|
getScripts: function() {
|
||||||
return ['moment.js'];
|
return ["moment.js"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define start sequence.
|
// Define start sequence.
|
||||||
start: function() {
|
start: function() {
|
||||||
Log.info('Starting module: ' + this.name);
|
Log.info("Starting module: " + this.name);
|
||||||
|
|
||||||
this.lastComplimentIndex = -1;
|
this.lastComplimentIndex = -1;
|
||||||
|
|
||||||
@ -50,7 +50,6 @@ Module.register('compliments',{
|
|||||||
}, this.config.updateInterval);
|
}, this.config.updateInterval);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/* randomIndex(compliments)
|
/* randomIndex(compliments)
|
||||||
* Generate a random index for a list of compliments.
|
* Generate a random index for a list of compliments.
|
||||||
*
|
*
|
||||||
@ -113,7 +112,7 @@ Module.register('compliments',{
|
|||||||
|
|
||||||
var compliment = document.createTextNode(complimentText);
|
var compliment = document.createTextNode(complimentText);
|
||||||
var wrapper = document.createElement("div");
|
var wrapper = document.createElement("div");
|
||||||
wrapper.className = 'thin xlarge bright';
|
wrapper.className = "thin xlarge bright";
|
||||||
wrapper.appendChild(compliment);
|
wrapper.appendChild(compliment);
|
||||||
|
|
||||||
return wrapper;
|
return wrapper;
|
||||||
|
@ -7,61 +7,60 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Module.register('currentweather',{
|
Module.register("currentweather",{
|
||||||
|
|
||||||
// Default module config.
|
// Default module config.
|
||||||
defaults: {
|
defaults: {
|
||||||
location: '',
|
location: "",
|
||||||
appid: '',
|
appid: "",
|
||||||
units: 'metric',
|
units: "metric",
|
||||||
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
||||||
animationSpeed: 1000,
|
animationSpeed: 1000,
|
||||||
timeFormat: config.timeFormat,
|
timeFormat: config.timeFormat,
|
||||||
lang: config.language,
|
lang: config.language,
|
||||||
|
|
||||||
initialLoadDelay: 0, // 0 seconds delay
|
initialLoadDelay: 0, // 0 seconds delay
|
||||||
retryDelay: 2500,
|
retryDelay: 2500,
|
||||||
|
|
||||||
apiVersion: '2.5',
|
apiVersion: "2.5",
|
||||||
apiBase: 'http://api.openweathermap.org/data/',
|
apiBase: "http://api.openweathermap.org/data/",
|
||||||
weatherEndpoint: 'weather',
|
weatherEndpoint: "weather",
|
||||||
|
|
||||||
iconTable: {
|
iconTable: {
|
||||||
'01d':'wi-day-sunny',
|
"01d": "wi-day-sunny",
|
||||||
'02d':'wi-day-cloudy',
|
"02d": "wi-day-cloudy",
|
||||||
'03d':'wi-cloudy',
|
"03d": "wi-cloudy",
|
||||||
'04d':'wi-cloudy-windy',
|
"04d": "wi-cloudy-windy",
|
||||||
'09d':'wi-showers',
|
"09d": "wi-showers",
|
||||||
'10d':'wi-rain',
|
"10d": "wi-rain",
|
||||||
'11d':'wi-thunderstorm',
|
"11d": "wi-thunderstorm",
|
||||||
'13d':'wi-snow',
|
"13d": "wi-snow",
|
||||||
'50d':'wi-fog',
|
"50d": "wi-fog",
|
||||||
'01n':'wi-night-clear',
|
"01n": "wi-night-clear",
|
||||||
'02n':'wi-night-cloudy',
|
"02n": "wi-night-cloudy",
|
||||||
'03n':'wi-night-cloudy',
|
"03n": "wi-night-cloudy",
|
||||||
'04n':'wi-night-cloudy',
|
"04n": "wi-night-cloudy",
|
||||||
'09n':'wi-night-showers',
|
"09n": "wi-night-showers",
|
||||||
'10n':'wi-night-rain',
|
"10n": "wi-night-rain",
|
||||||
'11n':'wi-night-thunderstorm',
|
"11n": "wi-night-thunderstorm",
|
||||||
'13n':'wi-night-snow',
|
"13n": "wi-night-snow",
|
||||||
'50n':'wi-night-alt-cloudy-windy'
|
"50n": "wi-night-alt-cloudy-windy"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function() {
|
getScripts: function() {
|
||||||
return ['moment.js'];
|
return ["moment.js"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getStyles: function() {
|
getStyles: function() {
|
||||||
return ['weather-icons.css', 'currentweather.css'];
|
return ["weather-icons.css", "currentweather.css"];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// Define start sequence.
|
// Define start sequence.
|
||||||
start: function() {
|
start: function() {
|
||||||
Log.info('Starting module: ' + this.name);
|
Log.info("Starting module: " + this.name);
|
||||||
|
|
||||||
// Set locale.
|
// Set locale.
|
||||||
moment.locale(config.language);
|
moment.locale(config.language);
|
||||||
@ -83,13 +82,13 @@ Module.register('currentweather',{
|
|||||||
getDom: function() {
|
getDom: function() {
|
||||||
var wrapper = document.createElement("div");
|
var wrapper = document.createElement("div");
|
||||||
|
|
||||||
if (this.config.appid === '') {
|
if (this.config.appid === "") {
|
||||||
wrapper.innerHTML = "Please set the correct openweather <i>appid</i> in the config for module: " + this.name + ".";
|
wrapper.innerHTML = "Please set the correct openweather <i>appid</i> in the config for module: " + this.name + ".";
|
||||||
wrapper.className = "dimmed light small";
|
wrapper.className = "dimmed light small";
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.config.location === '') {
|
if (this.config.location === "") {
|
||||||
wrapper.innerHTML = "Please set the openweather <i>location</i> in the config for module: " + this.name + ".";
|
wrapper.innerHTML = "Please set the openweather <i>location</i> in the config for module: " + this.name + ".";
|
||||||
wrapper.className = "dimmed light small";
|
wrapper.className = "dimmed light small";
|
||||||
return wrapper;
|
return wrapper;
|
||||||
@ -101,7 +100,6 @@ Module.register('currentweather',{
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var small = document.createElement("div");
|
var small = document.createElement("div");
|
||||||
small.className = "normal medium";
|
small.className = "normal medium";
|
||||||
|
|
||||||
@ -134,7 +132,7 @@ Module.register('currentweather',{
|
|||||||
|
|
||||||
var temperature = document.createElement("span");
|
var temperature = document.createElement("span");
|
||||||
temperature.className = "bright";
|
temperature.className = "bright";
|
||||||
temperature.innerHTML = " " + this.temperature + '°';
|
temperature.innerHTML = " " + this.temperature + "°";
|
||||||
large.appendChild(temperature);
|
large.appendChild(temperature);
|
||||||
|
|
||||||
wrapper.appendChild(small);
|
wrapper.appendChild(small);
|
||||||
@ -142,36 +140,35 @@ Module.register('currentweather',{
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/* updateWeather(compliments)
|
/* updateWeather(compliments)
|
||||||
* Requests new data from openweather.org.
|
* Requests new data from openweather.org.
|
||||||
* Calls processWeather on succesfull response.
|
* Calls processWeather on succesfull response.
|
||||||
*/
|
*/
|
||||||
updateWeather: function() {
|
updateWeather: function() {
|
||||||
var url = this.config.apiBase + this.config.apiVersion + '/' + this.config.weatherEndpoint + this.getParams();
|
var url = this.config.apiBase + this.config.apiVersion + "/" + this.config.weatherEndpoint + this.getParams();
|
||||||
var self = this;
|
var self = this;
|
||||||
var retry = true;
|
var retry = true;
|
||||||
|
|
||||||
var weatherRequest = new XMLHttpRequest();
|
var weatherRequest = new XMLHttpRequest();
|
||||||
weatherRequest.open("GET", url, true);
|
weatherRequest.open("GET", url, true);
|
||||||
weatherRequest.onreadystatechange = function() {
|
weatherRequest.onreadystatechange = function() {
|
||||||
if(this.readyState === 4) {
|
if (this.readyState === 4) {
|
||||||
if(this.status === 200) {
|
if (this.status === 200) {
|
||||||
self.processWeather(JSON.parse(this.response));
|
self.processWeather(JSON.parse(this.response));
|
||||||
} else if (this.status === 401) {
|
} else if (this.status === 401) {
|
||||||
self.config.appid = '';
|
self.config.appid = "";
|
||||||
self.updateDom(self.config.animationSpeed);
|
self.updateDom(self.config.animationSpeed);
|
||||||
|
|
||||||
Log.error(self.name + ": Incorrect APPID.");
|
Log.error(self.name + ": Incorrect APPID.");
|
||||||
retry = false;
|
retry = false;
|
||||||
} else {
|
} else {
|
||||||
Log.error(self.name + ": Could not load weather.");
|
Log.error(self.name + ": Could not load weather.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retry) {
|
if (retry) {
|
||||||
self.scheduleUpdate((self.loaded) ? -1 : self.config.retryDelay);
|
self.scheduleUpdate((self.loaded) ? -1 : self.config.retryDelay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
weatherRequest.send();
|
weatherRequest.send();
|
||||||
},
|
},
|
||||||
@ -183,10 +180,10 @@ Module.register('currentweather',{
|
|||||||
*/
|
*/
|
||||||
getParams: function() {
|
getParams: function() {
|
||||||
var params = "?";
|
var params = "?";
|
||||||
params += 'q=' + this.config.location;
|
params += "q=" + this.config.location;
|
||||||
params += '&units=' + this.config.units;
|
params += "&units=" + this.config.units;
|
||||||
params += '&lang=' + this.config.lang;
|
params += "&lang=" + this.config.lang;
|
||||||
params += '&APPID=' + this.config.appid;
|
params += "&APPID=" + this.config.appid;
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
},
|
},
|
||||||
@ -201,19 +198,16 @@ Module.register('currentweather',{
|
|||||||
this.windSpeed = this.ms2Beaufort(this.roundValue(data.wind.speed));
|
this.windSpeed = this.ms2Beaufort(this.roundValue(data.wind.speed));
|
||||||
this.weatherType = this.config.iconTable[data.weather[0].icon];
|
this.weatherType = this.config.iconTable[data.weather[0].icon];
|
||||||
|
|
||||||
|
var now = moment().format("x");
|
||||||
|
var sunrise = moment(data.sys.sunrise * 1000).format("x");
|
||||||
var now = moment().format('x');
|
var sunset = moment(data.sys.sunset * 1000).format("x");
|
||||||
var sunrise = moment(data.sys.sunrise*1000).format('x');
|
|
||||||
var sunset = moment(data.sys.sunset*1000).format('x');
|
|
||||||
|
|
||||||
|
|
||||||
if (sunrise < now && sunset > now) {
|
if (sunrise < now && sunset > now) {
|
||||||
this.sunriseSunsetTime = moment(data.sys.sunset*1000).format((this.config.timeFormat === 24) ? 'HH:mm' : 'hh:mm a');
|
this.sunriseSunsetTime = moment(data.sys.sunset * 1000).format((this.config.timeFormat === 24) ? "HH:mm" : "hh:mm a");
|
||||||
this.sunriseSunsetIcon = 'wi-sunset';
|
this.sunriseSunsetIcon = "wi-sunset";
|
||||||
} else {
|
} else {
|
||||||
this.sunriseSunsetTime = moment(data.sys.sunrise*1000).format((this.config.timeFormat === 24) ? 'HH:mm' : 'hh:mm a');
|
this.sunriseSunsetTime = moment(data.sys.sunrise * 1000).format((this.config.timeFormat === 24) ? "HH:mm" : "hh:mm a");
|
||||||
this.sunriseSunsetIcon = 'wi-sunrise';
|
this.sunriseSunsetIcon = "wi-sunrise";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +222,7 @@ Module.register('currentweather',{
|
|||||||
*/
|
*/
|
||||||
scheduleUpdate: function(delay) {
|
scheduleUpdate: function(delay) {
|
||||||
var nextLoad = this.config.updateInterval;
|
var nextLoad = this.config.updateInterval;
|
||||||
if (typeof delay !== 'undefined' && delay >= 0) {
|
if (typeof delay !== "undefined" && delay >= 0) {
|
||||||
nextLoad = delay;
|
nextLoad = delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +258,7 @@ Module.register('currentweather',{
|
|||||||
*
|
*
|
||||||
* return number - Rounded Temperature.
|
* return number - Rounded Temperature.
|
||||||
*/
|
*/
|
||||||
roundValue: function (temperature) {
|
roundValue: function(temperature) {
|
||||||
return parseFloat(temperature).toFixed(1);
|
return parseFloat(temperature).toFixed(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -8,16 +8,15 @@
|
|||||||
// Modules listed below can be loaded without the 'default/' prefix. Omitting the default folder name.
|
// Modules listed below can be loaded without the 'default/' prefix. Omitting the default folder name.
|
||||||
|
|
||||||
var defaultModules = [
|
var defaultModules = [
|
||||||
'alert',
|
"alert",
|
||||||
'calendar',
|
"calendar",
|
||||||
'clock',
|
"clock",
|
||||||
'compliments',
|
"compliments",
|
||||||
'currentweather',
|
"currentweather",
|
||||||
'helloworld',
|
"helloworld",
|
||||||
'newsfeed',
|
"newsfeed",
|
||||||
'weatherforecast'
|
"weatherforecast"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||||
if (typeof module !== 'undefined') {module.exports = defaultModules;}
|
if (typeof module !== "undefined") {module.exports = defaultModules;}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Module.register('helloworld',{
|
Module.register("helloworld",{
|
||||||
|
|
||||||
// Default module config.
|
// Default module config.
|
||||||
defaults: {
|
defaults: {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var NewsFetcher = require('./newsfetcher.js');
|
var NewsFetcher = require("./newsfetcher.js");
|
||||||
|
|
||||||
/* Fetcher
|
/* Fetcher
|
||||||
* Responsible for requesting an update on the set interval and broadcasting the data.
|
* Responsible for requesting an update on the set interval and broadcasting the data.
|
||||||
|
@ -7,26 +7,26 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Module.register('newsfeed',{
|
Module.register("newsfeed",{
|
||||||
|
|
||||||
// Default module config.
|
// Default module config.
|
||||||
defaults: {
|
defaults: {
|
||||||
feedUrl: 'http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml',
|
feedUrl: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",
|
||||||
showPublishDate: true,
|
showPublishDate: true,
|
||||||
reloadInterval: 5 * 60 * 1000, // every 5 minutes
|
reloadInterval: 5 * 60 * 1000, // every 5 minutes
|
||||||
updateInterval: 7.5 * 1000,
|
updateInterval: 7.5 * 1000,
|
||||||
animationSpeed: 2.5 * 1000,
|
animationSpeed: 2.5 * 1000,
|
||||||
encoding: 'UTF-8' //ISO-8859-1
|
encoding: "UTF-8" //ISO-8859-1
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function() {
|
getScripts: function() {
|
||||||
return ['moment.js'];
|
return ["moment.js"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define start sequence.
|
// Define start sequence.
|
||||||
start: function() {
|
start: function() {
|
||||||
Log.info('Starting module: ' + this.name);
|
Log.info("Starting module: " + this.name);
|
||||||
|
|
||||||
// Set locale.
|
// Set locale.
|
||||||
moment.locale(config.language);
|
moment.locale(config.language);
|
||||||
@ -41,7 +41,7 @@ Module.register('newsfeed',{
|
|||||||
|
|
||||||
// Override socket notification handler.
|
// Override socket notification handler.
|
||||||
socketNotificationReceived: function(notification, payload) {
|
socketNotificationReceived: function(notification, payload) {
|
||||||
if (notification === 'NEWS_ITEMS') {
|
if (notification === "NEWS_ITEMS") {
|
||||||
if (payload.url === this.config.feedUrl) {
|
if (payload.url === this.config.feedUrl) {
|
||||||
this.newsItems = payload.items;
|
this.newsItems = payload.items;
|
||||||
if (!this.loaded) {
|
if (!this.loaded) {
|
||||||
@ -73,7 +73,7 @@ Module.register('newsfeed',{
|
|||||||
if (this.config.showPublishDate) {
|
if (this.config.showPublishDate) {
|
||||||
var timestamp = document.createElement("div");
|
var timestamp = document.createElement("div");
|
||||||
timestamp.className = "light small dimmed";
|
timestamp.className = "light small dimmed";
|
||||||
timestamp.innerHTML = this.capitalizeFirstLetter(moment(new Date(this.newsItems[this.activeItem].pubdate)).fromNow() + ':');
|
timestamp.innerHTML = this.capitalizeFirstLetter(moment(new Date(this.newsItems[this.activeItem].pubdate)).fromNow() + ":");
|
||||||
//timestamp.innerHTML = this.config.feedUrl;
|
//timestamp.innerHTML = this.config.feedUrl;
|
||||||
wrapper.appendChild(timestamp);
|
wrapper.appendChild(timestamp);
|
||||||
}
|
}
|
||||||
@ -95,8 +95,8 @@ Module.register('newsfeed',{
|
|||||||
* Requests new data from news proxy.
|
* Requests new data from news proxy.
|
||||||
*/
|
*/
|
||||||
fetchNews: function() {
|
fetchNews: function() {
|
||||||
Log.log('Add news feed to fetcher: ' + this.config.feedUrl);
|
Log.log("Add news feed to fetcher: " + this.config.feedUrl);
|
||||||
this.sendSocketNotification('ADD_FEED', {
|
this.sendSocketNotification("ADD_FEED", {
|
||||||
url: this.config.feedUrl,
|
url: this.config.feedUrl,
|
||||||
reloadInterval: this.config.reloadInterval,
|
reloadInterval: this.config.reloadInterval,
|
||||||
encoding: this.config.encoding
|
encoding: this.config.encoding
|
||||||
@ -125,6 +125,6 @@ Module.register('newsfeed',{
|
|||||||
* return string - Capitalized output string.
|
* return string - Capitalized output string.
|
||||||
*/
|
*/
|
||||||
capitalizeFirstLetter: function(string) {
|
capitalizeFirstLetter: function(string) {
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -5,15 +5,15 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var FeedMe = require('feedme');
|
var FeedMe = require("feedme");
|
||||||
var request = require('request');
|
var request = require("request");
|
||||||
var iconv = require('iconv-lite');
|
var iconv = require("iconv-lite");
|
||||||
|
|
||||||
var NewsFetcher = function() {
|
var NewsFetcher = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.successCallback = function(){};
|
self.successCallback = function() {};
|
||||||
self.errorCallback = function(){};
|
self.errorCallback = function() {};
|
||||||
|
|
||||||
self.items = [];
|
self.items = [];
|
||||||
|
|
||||||
@ -30,22 +30,22 @@ var NewsFetcher = function() {
|
|||||||
|
|
||||||
var parser = new FeedMe();
|
var parser = new FeedMe();
|
||||||
|
|
||||||
parser.on('item', function(item) {
|
parser.on("item", function(item) {
|
||||||
self.items.push({
|
self.items.push({
|
||||||
title: item.title,
|
title: item.title,
|
||||||
pubdate: item.pubdate,
|
pubdate: item.pubdate,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.on('end', function(item) {
|
parser.on("end", function(item) {
|
||||||
self.successCallback(self.items);
|
self.successCallback(self.items);
|
||||||
});
|
});
|
||||||
|
|
||||||
parser.on('error', function(error) {
|
parser.on("error", function(error) {
|
||||||
self.errorCallback(error);
|
self.errorCallback(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
request({uri:url, encoding:null}).pipe(iconv.decodeStream(encoding)).pipe(parser);
|
request({uri: url, encoding: null}).pipe(iconv.decodeStream(encoding)).pipe(parser);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,21 +5,21 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var NodeHelper = require('node_helper');
|
var NodeHelper = require("node_helper");
|
||||||
var validUrl = require('valid-url');
|
var validUrl = require("valid-url");
|
||||||
var Fetcher = require('./fetcher.js');
|
var Fetcher = require("./fetcher.js");
|
||||||
|
|
||||||
module.exports = NodeHelper.create({
|
module.exports = NodeHelper.create({
|
||||||
// Subclass start method.
|
// Subclass start method.
|
||||||
start: function() {
|
start: function() {
|
||||||
console.log('Starting module: ' + this.name);
|
console.log("Starting module: " + this.name);
|
||||||
|
|
||||||
this.fetchers = [];
|
this.fetchers = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Subclass socketNotificationReceived received.
|
// Subclass socketNotificationReceived received.
|
||||||
socketNotificationReceived: function(notification, payload) {
|
socketNotificationReceived: function(notification, payload) {
|
||||||
if(notification === 'ADD_FEED') {
|
if (notification === "ADD_FEED") {
|
||||||
this.createFetcher(payload.url, payload.reloadInterval, payload.encoding);
|
this.createFetcher(payload.url, payload.reloadInterval, payload.encoding);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -35,25 +35,25 @@ module.exports = NodeHelper.create({
|
|||||||
createFetcher: function(url, reloadInterval, encoding) {
|
createFetcher: function(url, reloadInterval, encoding) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (!validUrl.isUri(url)){
|
if (!validUrl.isUri(url)) {
|
||||||
self.sendSocketNotification('INCORRECT_URL', url);
|
self.sendSocketNotification("INCORRECT_URL", url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fetcher;
|
var fetcher;
|
||||||
if (typeof self.fetchers[url] === 'undefined') {
|
if (typeof self.fetchers[url] === "undefined") {
|
||||||
console.log('Create new news fetcher for url: ' + url + ' - Interval: ' + reloadInterval);
|
console.log("Create new news fetcher for url: " + url + " - Interval: " + reloadInterval);
|
||||||
fetcher = new Fetcher(url, reloadInterval, encoding);
|
fetcher = new Fetcher(url, reloadInterval, encoding);
|
||||||
|
|
||||||
fetcher.onReceive(function(fetcher) {
|
fetcher.onReceive(function(fetcher) {
|
||||||
self.sendSocketNotification('NEWS_ITEMS', {
|
self.sendSocketNotification("NEWS_ITEMS", {
|
||||||
url: fetcher.url(),
|
url: fetcher.url(),
|
||||||
items: fetcher.items()
|
items: fetcher.items()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
fetcher.onError(function(fetcher, error) {
|
fetcher.onError(function(fetcher, error) {
|
||||||
self.sendSocketNotification('FETCH_ERROR', {
|
self.sendSocketNotification("FETCH_ERROR", {
|
||||||
url: fetcher.url(),
|
url: fetcher.url(),
|
||||||
error: error
|
error: error
|
||||||
});
|
});
|
||||||
@ -61,7 +61,7 @@ module.exports = NodeHelper.create({
|
|||||||
|
|
||||||
self.fetchers[url] = fetcher;
|
self.fetchers[url] = fetcher;
|
||||||
} else {
|
} else {
|
||||||
console.log('Use exsisting news fetcher for url: ' + url);
|
console.log("Use exsisting news fetcher for url: " + url);
|
||||||
fetcher = self.fetchers[url];
|
fetcher = self.fetchers[url];
|
||||||
fetcher.setReloadInterval(reloadInterval);
|
fetcher.setReloadInterval(reloadInterval);
|
||||||
fetcher.broadcastItems();
|
fetcher.broadcastItems();
|
||||||
|
@ -7,16 +7,16 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Module.register('weatherforecast',{
|
Module.register("weatherforecast",{
|
||||||
|
|
||||||
// Default module config.
|
// Default module config.
|
||||||
defaults: {
|
defaults: {
|
||||||
location: '',
|
location: "",
|
||||||
appid: '',
|
appid: "",
|
||||||
units: 'metric',
|
units: "metric",
|
||||||
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
updateInterval: 10 * 60 * 1000, // every 10 minutes
|
||||||
animationSpeed: 1000,
|
animationSpeed: 1000,
|
||||||
timeFormat: config.timeFormat,
|
timeFormat: config.timeFormat,
|
||||||
lang: config.language,
|
lang: config.language,
|
||||||
fade: true,
|
fade: true,
|
||||||
fadePoint: 0.25, // Start on 1/4th of the list.
|
fadePoint: 0.25, // Start on 1/4th of the list.
|
||||||
@ -24,46 +24,45 @@ Module.register('weatherforecast',{
|
|||||||
initialLoadDelay: 2500, // 2.5 seconds delay. This delay is used to keep the OpenWeather API happy.
|
initialLoadDelay: 2500, // 2.5 seconds delay. This delay is used to keep the OpenWeather API happy.
|
||||||
retryDelay: 2500,
|
retryDelay: 2500,
|
||||||
|
|
||||||
apiVersion: '2.5',
|
apiVersion: "2.5",
|
||||||
apiBase: 'http://api.openweathermap.org/data/',
|
apiBase: "http://api.openweathermap.org/data/",
|
||||||
forecastEndpoint: 'forecast/daily',
|
forecastEndpoint: "forecast/daily",
|
||||||
|
|
||||||
iconTable: {
|
iconTable: {
|
||||||
'01d':'wi-day-sunny',
|
"01d": "wi-day-sunny",
|
||||||
'02d':'wi-day-cloudy',
|
"02d": "wi-day-cloudy",
|
||||||
'03d':'wi-cloudy',
|
"03d": "wi-cloudy",
|
||||||
'04d':'wi-cloudy-windy',
|
"04d": "wi-cloudy-windy",
|
||||||
'09d':'wi-showers',
|
"09d": "wi-showers",
|
||||||
'10d':'wi-rain',
|
"10d": "wi-rain",
|
||||||
'11d':'wi-thunderstorm',
|
"11d": "wi-thunderstorm",
|
||||||
'13d':'wi-snow',
|
"13d": "wi-snow",
|
||||||
'50d':'wi-fog',
|
"50d": "wi-fog",
|
||||||
'01n':'wi-night-clear',
|
"01n": "wi-night-clear",
|
||||||
'02n':'wi-night-cloudy',
|
"02n": "wi-night-cloudy",
|
||||||
'03n':'wi-night-cloudy',
|
"03n": "wi-night-cloudy",
|
||||||
'04n':'wi-night-cloudy',
|
"04n": "wi-night-cloudy",
|
||||||
'09n':'wi-night-showers',
|
"09n": "wi-night-showers",
|
||||||
'10n':'wi-night-rain',
|
"10n": "wi-night-rain",
|
||||||
'11n':'wi-night-thunderstorm',
|
"11n": "wi-night-thunderstorm",
|
||||||
'13n':'wi-night-snow',
|
"13n": "wi-night-snow",
|
||||||
'50n':'wi-night-alt-cloudy-windy'
|
"50n": "wi-night-alt-cloudy-windy"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getScripts: function() {
|
getScripts: function() {
|
||||||
return ['moment.js'];
|
return ["moment.js"];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Define required scripts.
|
// Define required scripts.
|
||||||
getStyles: function() {
|
getStyles: function() {
|
||||||
return ['weather-icons.css', 'weatherforecast.css'];
|
return ["weather-icons.css", "weatherforecast.css"];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// Define start sequence.
|
// Define start sequence.
|
||||||
start: function() {
|
start: function() {
|
||||||
Log.info('Starting module: ' + this.name);
|
Log.info("Starting module: " + this.name);
|
||||||
|
|
||||||
// Set locale.
|
// Set locale.
|
||||||
moment.locale(config.language);
|
moment.locale(config.language);
|
||||||
@ -80,13 +79,13 @@ Module.register('weatherforecast',{
|
|||||||
getDom: function() {
|
getDom: function() {
|
||||||
var wrapper = document.createElement("div");
|
var wrapper = document.createElement("div");
|
||||||
|
|
||||||
if (this.config.appid === '') {
|
if (this.config.appid === "") {
|
||||||
wrapper.innerHTML = "Please set the correct openweather <i>appid</i> in the config for module: " + this.name + ".";
|
wrapper.innerHTML = "Please set the correct openweather <i>appid</i> in the config for module: " + this.name + ".";
|
||||||
wrapper.className = "dimmed light small";
|
wrapper.className = "dimmed light small";
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.config.location === '') {
|
if (this.config.location === "") {
|
||||||
wrapper.innerHTML = "Please set the openweather <i>location</i> in the config for module: " + this.name + ".";
|
wrapper.innerHTML = "Please set the openweather <i>location</i> in the config for module: " + this.name + ".";
|
||||||
wrapper.className = "dimmed light small";
|
wrapper.className = "dimmed light small";
|
||||||
return wrapper;
|
return wrapper;
|
||||||
@ -98,7 +97,6 @@ Module.register('weatherforecast',{
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var table = document.createElement("table");
|
var table = document.createElement("table");
|
||||||
table.className = "small";
|
table.className = "small";
|
||||||
|
|
||||||
@ -109,7 +107,7 @@ Module.register('weatherforecast',{
|
|||||||
table.appendChild(row);
|
table.appendChild(row);
|
||||||
|
|
||||||
var dayCell = document.createElement("td");
|
var dayCell = document.createElement("td");
|
||||||
dayCell.className = 'day';
|
dayCell.className = "day";
|
||||||
dayCell.innerHTML = forecast.day;
|
dayCell.innerHTML = forecast.day;
|
||||||
row.appendChild(dayCell);
|
row.appendChild(dayCell);
|
||||||
|
|
||||||
@ -123,15 +121,14 @@ Module.register('weatherforecast',{
|
|||||||
|
|
||||||
var maxTempCell = document.createElement("td");
|
var maxTempCell = document.createElement("td");
|
||||||
maxTempCell.innerHTML = forecast.maxTemp;
|
maxTempCell.innerHTML = forecast.maxTemp;
|
||||||
maxTempCell.className = 'align-right bright max-temp';
|
maxTempCell.className = "align-right bright max-temp";
|
||||||
row.appendChild(maxTempCell);
|
row.appendChild(maxTempCell);
|
||||||
|
|
||||||
var minTempCell = document.createElement("td");
|
var minTempCell = document.createElement("td");
|
||||||
minTempCell.innerHTML = forecast.minTemp;
|
minTempCell.innerHTML = forecast.minTemp;
|
||||||
minTempCell.className = 'align-right min-temp';
|
minTempCell.className = "align-right min-temp";
|
||||||
row.appendChild(minTempCell);
|
row.appendChild(minTempCell);
|
||||||
|
|
||||||
|
|
||||||
if (this.config.fade && this.config.fadePoint < 1) {
|
if (this.config.fade && this.config.fadePoint < 1) {
|
||||||
if (this.config.fadePoint < 0) {
|
if (this.config.fadePoint < 0) {
|
||||||
this.config.fadePoint = 0;
|
this.config.fadePoint = 0;
|
||||||
@ -144,45 +141,40 @@ Module.register('weatherforecast',{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/* updateWeather(compliments)
|
/* updateWeather(compliments)
|
||||||
* Requests new data from openweather.org.
|
* Requests new data from openweather.org.
|
||||||
* Calls processWeather on succesfull response.
|
* Calls processWeather on succesfull response.
|
||||||
*/
|
*/
|
||||||
updateWeather: function() {
|
updateWeather: function() {
|
||||||
var url = this.config.apiBase + this.config.apiVersion + '/' + this.config.forecastEndpoint + this.getParams();
|
var url = this.config.apiBase + this.config.apiVersion + "/" + this.config.forecastEndpoint + this.getParams();
|
||||||
var self = this;
|
var self = this;
|
||||||
var retry = true;
|
var retry = true;
|
||||||
|
|
||||||
var weatherRequest = new XMLHttpRequest();
|
var weatherRequest = new XMLHttpRequest();
|
||||||
weatherRequest.open("GET", url, true);
|
weatherRequest.open("GET", url, true);
|
||||||
weatherRequest.onreadystatechange = function() {
|
weatherRequest.onreadystatechange = function() {
|
||||||
if(this.readyState === 4) {
|
if (this.readyState === 4) {
|
||||||
if(this.status === 200) {
|
if (this.status === 200) {
|
||||||
self.processWeather(JSON.parse(this.response));
|
self.processWeather(JSON.parse(this.response));
|
||||||
} else if (this.status === 401) {
|
} else if (this.status === 401) {
|
||||||
self.config.appid = '';
|
self.config.appid = "";
|
||||||
self.updateDom(self.config.animationSpeed);
|
self.updateDom(self.config.animationSpeed);
|
||||||
|
|
||||||
Log.error(self.name + ": Incorrect APPID.");
|
Log.error(self.name + ": Incorrect APPID.");
|
||||||
retry = false;
|
retry = false;
|
||||||
} else {
|
} else {
|
||||||
Log.error(self.name + ": Could not load weather.");
|
Log.error(self.name + ": Could not load weather.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retry) {
|
if (retry) {
|
||||||
self.scheduleUpdate((self.loaded) ? -1 : self.config.retryDelay);
|
self.scheduleUpdate((self.loaded) ? -1 : self.config.retryDelay);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
weatherRequest.send();
|
weatherRequest.send();
|
||||||
},
|
},
|
||||||
@ -194,10 +186,10 @@ Module.register('weatherforecast',{
|
|||||||
*/
|
*/
|
||||||
getParams: function() {
|
getParams: function() {
|
||||||
var params = "?";
|
var params = "?";
|
||||||
params += 'q=' + this.config.location;
|
params += "q=" + this.config.location;
|
||||||
params += '&units=' + this.config.units;
|
params += "&units=" + this.config.units;
|
||||||
params += '&lang=' + this.config.lang;
|
params += "&lang=" + this.config.lang;
|
||||||
params += '&APPID=' + this.config.appid;
|
params += "&APPID=" + this.config.appid;
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
},
|
},
|
||||||
@ -215,7 +207,7 @@ Module.register('weatherforecast',{
|
|||||||
var forecast = data.list[i];
|
var forecast = data.list[i];
|
||||||
this.forecast.push({
|
this.forecast.push({
|
||||||
|
|
||||||
day: moment(forecast.dt, 'X').format('ddd.'),
|
day: moment(forecast.dt, "X").format("ddd."),
|
||||||
icon: this.config.iconTable[forecast.weather[0].icon],
|
icon: this.config.iconTable[forecast.weather[0].icon],
|
||||||
maxTemp: this.roundValue(forecast.temp.max),
|
maxTemp: this.roundValue(forecast.temp.max),
|
||||||
minTemp: this.roundValue(forecast.temp.min)
|
minTemp: this.roundValue(forecast.temp.min)
|
||||||
@ -236,7 +228,7 @@ Module.register('weatherforecast',{
|
|||||||
*/
|
*/
|
||||||
scheduleUpdate: function(delay) {
|
scheduleUpdate: function(delay) {
|
||||||
var nextLoad = this.config.updateInterval;
|
var nextLoad = this.config.updateInterval;
|
||||||
if (typeof delay !== 'undefined' && delay >= 0) {
|
if (typeof delay !== "undefined" && delay >= 0) {
|
||||||
nextLoad = delay;
|
nextLoad = delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +265,7 @@ Module.register('weatherforecast',{
|
|||||||
*
|
*
|
||||||
* return number - Rounded Temperature.
|
* return number - Rounded Temperature.
|
||||||
*/
|
*/
|
||||||
roundValue: function (temperature) {
|
roundValue: function(temperature) {
|
||||||
return parseFloat(temperature).toFixed(1);
|
return parseFloat(temperature).toFixed(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
29
modules/node_modules/node_helper/index.js
generated
vendored
29
modules/node_modules/node_helper/index.js
generated
vendored
@ -5,17 +5,17 @@
|
|||||||
* MIT Licensed.
|
* MIT Licensed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Class = require('../../../js/class.js');
|
var Class = require("../../../js/class.js");
|
||||||
var express = require('express');
|
var express = require("express");
|
||||||
var path = require('path');
|
var path = require("path");
|
||||||
|
|
||||||
NodeHelper = Class.extend({
|
NodeHelper = Class.extend({
|
||||||
init: function() {
|
init: function() {
|
||||||
console.log('Initializing new module helper ...');
|
console.log("Initializing new module helper ...");
|
||||||
},
|
},
|
||||||
|
|
||||||
start: function() {
|
start: function() {
|
||||||
console.log('Staring module helper: ' + this.name);
|
console.log("Staring module helper: " + this.name);
|
||||||
},
|
},
|
||||||
|
|
||||||
/* socketNotificationReceived(notification, payload)
|
/* socketNotificationReceived(notification, payload)
|
||||||
@ -25,7 +25,7 @@ NodeHelper = Class.extend({
|
|||||||
* argument payload mixed - The payload of the notification.
|
* argument payload mixed - The payload of the notification.
|
||||||
*/
|
*/
|
||||||
socketNotificationReceived: function(notification, payload) {
|
socketNotificationReceived: function(notification, payload) {
|
||||||
console.log(this.name + ' received a socket notification: ' + notification + ' - Payload: ' + payload);
|
console.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
|
||||||
},
|
},
|
||||||
|
|
||||||
/* setName(name)
|
/* setName(name)
|
||||||
@ -56,7 +56,6 @@ NodeHelper = Class.extend({
|
|||||||
this.io.of(this.name).emit(notification, payload);
|
this.io.of(this.name).emit(notification, payload);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/* setExpressApp(app)
|
/* setExpressApp(app)
|
||||||
* Sets the express app object for this module.
|
* Sets the express app object for this module.
|
||||||
* This allows you to host files from the created webserver.
|
* This allows you to host files from the created webserver.
|
||||||
@ -66,8 +65,8 @@ NodeHelper = Class.extend({
|
|||||||
setExpressApp: function(app) {
|
setExpressApp: function(app) {
|
||||||
this.expressApp = app;
|
this.expressApp = app;
|
||||||
|
|
||||||
var publicPath = this.path + '/public';
|
var publicPath = this.path + "/public";
|
||||||
app.use('/' + this.name, express.static(publicPath));
|
app.use("/" + this.name, express.static(publicPath));
|
||||||
},
|
},
|
||||||
|
|
||||||
/* setSocketIO(io)
|
/* setSocketIO(io)
|
||||||
@ -80,21 +79,21 @@ NodeHelper = Class.extend({
|
|||||||
var self = this;
|
var self = this;
|
||||||
self.io = io;
|
self.io = io;
|
||||||
|
|
||||||
console.log('Connecting socket for: ' + this.name);
|
console.log("Connecting socket for: " + this.name);
|
||||||
var namespace = this.name;
|
var namespace = this.name;
|
||||||
io.of(namespace).on('connection', function (socket) {
|
io.of(namespace).on("connection", function(socket) {
|
||||||
// add a catch all event.
|
// add a catch all event.
|
||||||
var onevent = socket.onevent;
|
var onevent = socket.onevent;
|
||||||
socket.onevent = function (packet) {
|
socket.onevent = function(packet) {
|
||||||
var args = packet.data || [];
|
var args = packet.data || [];
|
||||||
onevent.call (this, packet); // original call
|
onevent.call(this, packet); // original call
|
||||||
packet.data = ["*"].concat(args);
|
packet.data = ["*"].concat(args);
|
||||||
onevent.call(this, packet); // additional call to catch-all
|
onevent.call(this, packet); // additional call to catch-all
|
||||||
};
|
};
|
||||||
|
|
||||||
// register catch all.
|
// register catch all.
|
||||||
socket.on('*', function (notification, payload) {
|
socket.on("*", function(notification, payload) {
|
||||||
if (notification !== '*')
|
if (notification !== "*")
|
||||||
//console.log('received message in namespace: ' + namespace);
|
//console.log('received message in namespace: ' + namespace);
|
||||||
self.socketNotificationReceived(notification, payload);
|
self.socketNotificationReceived(notification, payload);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user