mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
JSCS Says Goodbye
This commit is contained in:
parent
0252495eca
commit
15887994fe
6
.eslintignore
Normal file
6
.eslintignore
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
vendor/
|
||||||
|
!/vendor/vendor.js
|
||||||
|
/modules/**
|
||||||
|
!/modules/default/**
|
||||||
|
!/modules/node_helper
|
||||||
|
!/modules/node_helper/**
|
14
.eslintrc.json
Normal file
14
.eslintrc.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"rules": {
|
||||||
|
"indent": ["error", "tab"],
|
||||||
|
"quotes": ["error", "double"],
|
||||||
|
"max-len": ["error", 250],
|
||||||
|
"curly": "error",
|
||||||
|
"camelcase": ["error", {"properties": "never"}]
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"node": true,
|
||||||
|
"es6": true
|
||||||
|
}
|
||||||
|
}
|
9
.jscsrc
9
.jscsrc
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"preset": "google",
|
|
||||||
"validateIndentation": "\t",
|
|
||||||
"validateQuoteMarks": "\"",
|
|
||||||
"maximumLineLength": 250,
|
|
||||||
"requireCurlyBraces": [],
|
|
||||||
"requireCamelCaseOrUpperCaseIdentifiers": false,
|
|
||||||
"excludeFiles": [".jscsrc"],
|
|
||||||
}
|
|
16
js/app.js
16
js/app.js
@ -12,11 +12,11 @@ var path = require("path");
|
|||||||
|
|
||||||
// The next part is here to prevent a major exception when there
|
// The next part is here to prevent a major exception when there
|
||||||
// is no internet connection. This could probable be solved better.
|
// is no internet connection. This could probable be solved better.
|
||||||
process.on('uncaughtException', function (err) {
|
process.on("uncaughtException", function (err) {
|
||||||
console.log("Whoops! There was an uncaught exception...");
|
console.log("Whoops! There was an uncaught exception...");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
console.log("MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?");
|
console.log("MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?");
|
||||||
console.log("If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues");
|
console.log("If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues");
|
||||||
});
|
});
|
||||||
|
|
||||||
/* App - The core app.
|
/* App - The core app.
|
||||||
@ -41,7 +41,7 @@ var App = function() {
|
|||||||
var config = Object.assign(defaults, c);
|
var config = Object.assign(defaults, c);
|
||||||
callback(config);
|
callback(config);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('WARNING! Could not find config. Please create one.');
|
console.error("WARNING! Could not find config. Please create one.");
|
||||||
callback(defaults);
|
callback(defaults);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -98,7 +98,7 @@ var App = function() {
|
|||||||
/* start(callback)
|
/* start(callback)
|
||||||
* This methods starts the core app.
|
* This methods starts the core app.
|
||||||
* It loads the config, then it loads all modules.
|
* It loads the config, then it loads all modules.
|
||||||
* When it's done it executs the callback with the config as argument.
|
* When it"s done it executs the callback with the config as argument.
|
||||||
*
|
*
|
||||||
* argument callback function - The callback function.
|
* argument callback function - The callback function.
|
||||||
*/
|
*/
|
||||||
@ -130,7 +130,7 @@ var App = function() {
|
|||||||
|
|
||||||
console.log("Sockets connected & modules started ...");
|
console.log("Sockets connected & modules started ...");
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === "function") {
|
||||||
callback(config);
|
callback(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,8 +48,9 @@
|
|||||||
// 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
|
||||||
|
46
js/loader.js
46
js/loader.js
@ -1,7 +1,4 @@
|
|||||||
/* global config, vendor, MM, Log, Module */
|
/* global config, vendor, MM, Log, Module */
|
||||||
/* jshint unused:false */
|
|
||||||
/* jshint -W061 */
|
|
||||||
|
|
||||||
/* Magic Mirror
|
/* Magic Mirror
|
||||||
* Module and File loaders.
|
* Module and File loaders.
|
||||||
*
|
*
|
||||||
@ -165,31 +162,26 @@ var Loader = (function() {
|
|||||||
var extension = fileName.slice((Math.max(0, fileName.lastIndexOf(".")) || Infinity) + 1);
|
var extension = fileName.slice((Math.max(0, fileName.lastIndexOf(".")) || Infinity) + 1);
|
||||||
|
|
||||||
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");
|
||||||
|
stylesheet.rel = "stylesheet";
|
||||||
var stylesheet = document.createElement("link");
|
stylesheet.type = "text/css";
|
||||||
stylesheet.rel = "stylesheet";
|
stylesheet.href = fileName;
|
||||||
stylesheet.type = "text/css";
|
stylesheet.onload = function() {
|
||||||
stylesheet.href = fileName;
|
if (typeof callback === "function") {callback();}
|
||||||
stylesheet.onload = function() {
|
};
|
||||||
if (typeof callback === "function") {callback();}
|
document.getElementsByTagName("head")[0].appendChild(stylesheet);
|
||||||
};
|
|
||||||
|
|
||||||
document.getElementsByTagName("head")[0].appendChild(stylesheet);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
js/main.js
27
js/main.js
@ -1,5 +1,4 @@
|
|||||||
/* global Log, Loader, Module, config, defaults */
|
/* global Log, Loader, Module, config, defaults */
|
||||||
/* jshint -W020 */
|
|
||||||
|
|
||||||
/* Magic Mirror
|
/* Magic Mirror
|
||||||
* Main System
|
* Main System
|
||||||
@ -165,7 +164,7 @@ var MM = (function() {
|
|||||||
clearTimeout(module.showHideTimer);
|
clearTimeout(module.showHideTimer);
|
||||||
module.showHideTimer = setTimeout(function() {
|
module.showHideTimer = setTimeout(function() {
|
||||||
// To not take up any space, we just make the position absolute.
|
// To not take up any space, we just make the position absolute.
|
||||||
// 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";
|
||||||
@ -434,7 +433,27 @@ var MM = (function() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
// Add polyfill for Object.assign.
|
// Add polyfill for Object.assign.
|
||||||
if (typeof Object.assign != 'function') { (function () { Object.assign = function (target) { 'use strict'; if (target === undefined || target === null) { throw new TypeError('Cannot convert undefined or null to object'); } var output = Object(target); for (var index = 1; index < arguments.length; index++) { var source = arguments[index]; if (source !== undefined && source !== null) { for (var nextKey in source) { if (source.hasOwnProperty(nextKey)) { output[nextKey] = source[nextKey]; } } } } return output; }; })(); }
|
if (typeof Object.assign != "function") {
|
||||||
|
(function() {
|
||||||
|
Object.assign = function(target) {
|
||||||
|
"use strict";
|
||||||
|
if (target === undefined || target === null) {
|
||||||
|
throw new TypeError("Cannot convert undefined or null to object");
|
||||||
|
}
|
||||||
|
var output = Object(target);
|
||||||
|
for (var index = 1; index < arguments.length; index++) {
|
||||||
|
var source = arguments[index];
|
||||||
|
if (source !== undefined && source !== null) {
|
||||||
|
for (var nextKey in source) {
|
||||||
|
if (source.hasOwnProperty(nextKey)) {
|
||||||
|
output[nextKey] = source[nextKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
MM.init();
|
MM.init();
|
||||||
|
12
js/module.js
12
js/module.js
@ -111,7 +111,7 @@ var Module = Class.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
/*********************************************
|
/*********************************************
|
||||||
* The methods below don't need subclassing. *
|
* The methods below don"t need subclassing. *
|
||||||
*********************************************/
|
*********************************************/
|
||||||
|
|
||||||
/* setData(data)
|
/* setData(data)
|
||||||
@ -138,7 +138,7 @@ var Module = Class.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
/* socket()
|
/* socket()
|
||||||
* Returns a socket object. If it doesn't exsist, it's created.
|
* Returns a socket object. If it doesn"t exsist, it"s created.
|
||||||
* It also registers the notification callback.
|
* It also registers the notification callback.
|
||||||
*/
|
*/
|
||||||
socket: function() {
|
socket: function() {
|
||||||
@ -223,9 +223,9 @@ var Module = Class.extend({
|
|||||||
var translations = this.getTranslations();
|
var translations = this.getTranslations();
|
||||||
var translationFile = translations && (translations[config.language.toLowerCase()] || translations.en) || undefined;
|
var translationFile = translations && (translations[config.language.toLowerCase()] || translations.en) || undefined;
|
||||||
if(translationFile) {
|
if(translationFile) {
|
||||||
Translator.load(this, translationFile, callback);
|
Translator.load(this, translationFile, callback);
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ var Module = Class.extend({
|
|||||||
* argument defaultValue string - The default value if no translation was found. (Optional)
|
* argument defaultValue string - The default value if no translation was found. (Optional)
|
||||||
*/
|
*/
|
||||||
translate: function(key, defaultValue) {
|
translate: function(key, defaultValue) {
|
||||||
return Translator.translate(this, key) || defaultValue || '';
|
return Translator.translate(this, key) || defaultValue || "";
|
||||||
},
|
},
|
||||||
|
|
||||||
/* updateDom(speed)
|
/* updateDom(speed)
|
||||||
@ -299,7 +299,7 @@ Module.create = function(name) {
|
|||||||
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]);
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ var Translator = (function() {
|
|||||||
_loadJSON: function(file, callback) {
|
_loadJSON: function(file, callback) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.overrideMimeType("application/json");
|
xhr.overrideMimeType("application/json");
|
||||||
xhr.open('GET', file, true);
|
xhr.open("GET", file, true);
|
||||||
xhr.onreadystatechange = function () {
|
xhr.onreadystatechange = function () {
|
||||||
if (xhr.readyState == 4 && xhr.status == "200") {
|
if (xhr.readyState == 4 && xhr.status == "200") {
|
||||||
callback(JSON.parse(xhr.responseText));
|
callback(JSON.parse(xhr.responseText));
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
var app = require('../js/app.js');
|
var app = require("../js/app.js");
|
||||||
app.start(function(config) {
|
app.start(function(config) {
|
||||||
console.log('');
|
console.log("");
|
||||||
console.log('Ready to go! Please point your browser to: http://localhost:' + config.port);
|
console.log("Ready to go! Please point your browser to: http://localhost:" + config.port);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user