mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Standardize: TO JSCS!
This commit is contained in:
@@ -7,12 +7,12 @@
|
||||
* MIT Licensed.
|
||||
*/
|
||||
|
||||
Module.register('alert',{
|
||||
Module.register("alert",{
|
||||
defaults: {
|
||||
// scale|slide|genie|jelly|flip|bouncyflip|exploader
|
||||
effect: "slide",
|
||||
// scale|slide|genie|jelly|flip|bouncyflip|exploader
|
||||
alert_effect:"jelly",
|
||||
alert_effect: "jelly",
|
||||
//time a notification is displayed in seconds
|
||||
display_time: 3500,
|
||||
//Position
|
||||
@@ -21,100 +21,97 @@ Module.register('alert',{
|
||||
welcome_message: "Welcome, start was successfull!"
|
||||
},
|
||||
getScripts: function() {
|
||||
return ["classie.js", "modernizr.custom.js", 'notificationFx.js'];
|
||||
return ["classie.js", "modernizr.custom.js", "notificationFx.js"];
|
||||
},
|
||||
getStyles: function() {
|
||||
return ['ns-default.css'];
|
||||
return ["ns-default.css"];
|
||||
},
|
||||
show_notification: function (message) {
|
||||
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>"
|
||||
show_notification: function(message) {
|
||||
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>";
|
||||
new NotificationFx({
|
||||
message : message,
|
||||
layout : "growl",
|
||||
effect : this.config.effect,
|
||||
message: message,
|
||||
layout: "growl",
|
||||
effect: this.config.effect,
|
||||
ttl: this.config.display_time
|
||||
}).show();
|
||||
},
|
||||
show_alert: function (params, sender) {
|
||||
var self = this
|
||||
show_alert: function(params, sender) {
|
||||
var self = this;
|
||||
//Set standard params if not provided by module
|
||||
if (typeof params.timer === 'undefined') { params.timer = null; }
|
||||
if (typeof params.imageHeight === 'undefined') { params.imageHeight = "80px"; }
|
||||
if (typeof params.imageUrl === 'undefined') {
|
||||
if (typeof params.timer === "undefined") { params.timer = null; }
|
||||
if (typeof params.imageHeight === "undefined") { params.imageHeight = "80px"; }
|
||||
if (typeof params.imageUrl === "undefined") {
|
||||
params.imageUrl = null;
|
||||
image = ""
|
||||
}
|
||||
else {
|
||||
image = "<img src='" + params["imageUrl"] + "' height=" + params.imageHeight + " style='margin-bottom: 10px;'/><br />"
|
||||
image = "";
|
||||
} else {
|
||||
image = "<img src='" + (params.imageUrl).toString() + "' height=" + (params.imageHeight).toString() + " style='margin-bottom: 10px;'/><br />";
|
||||
}
|
||||
//Create overlay
|
||||
var overlay = document.createElement("div");
|
||||
overlay.id = "overlay"
|
||||
overlay.innerHTML += '<div class="black_overlay"></div>';
|
||||
overlay.id = "overlay";
|
||||
overlay.innerHTML += "<div class=\"black_overlay\"></div>";
|
||||
document.body.insertBefore(overlay, document.body.firstChild);
|
||||
|
||||
|
||||
//If module already has an open alert close it
|
||||
if (this.alerts[sender.name]){
|
||||
this.hide_alert(sender)
|
||||
if (this.alerts[sender.name]) {
|
||||
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
|
||||
this.alerts[sender.name] = new NotificationFx({
|
||||
message : image + message,
|
||||
effect : this.config.alert_effect,
|
||||
message: image + message,
|
||||
effect: this.config.alert_effect,
|
||||
ttl: params.timer,
|
||||
al_no: "ns-alert"
|
||||
});
|
||||
//Show alert
|
||||
this.alerts[sender.name].show()
|
||||
this.alerts[sender.name].show();
|
||||
//Add timer to dismiss alert and overlay
|
||||
if (params.timer) {
|
||||
setTimeout( function() {
|
||||
self.hide_alert(sender)
|
||||
}, params.timer );
|
||||
setTimeout(function() {
|
||||
self.hide_alert(sender);
|
||||
}, params.timer);
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
hide_alert: function (sender) {
|
||||
hide_alert: function(sender) {
|
||||
//Dismiss alert and remove from this.alerts
|
||||
this.alerts[sender.name].dismiss()
|
||||
this.alerts[sender.name] = null
|
||||
this.alerts[sender.name].dismiss();
|
||||
this.alerts[sender.name] = null;
|
||||
//Remove overlay
|
||||
var overlay = document.getElementById("overlay");
|
||||
overlay.parentNode.removeChild(overlay);
|
||||
},
|
||||
setPosition: function (pos) {
|
||||
setPosition: function(pos) {
|
||||
//Add css to body depending on the set position for notifications
|
||||
var sheet = document.createElement('style')
|
||||
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 == "left"){sheet.innerHTML = ".ns-box {margin-right: auto;text-align: left;}";}
|
||||
var sheet = document.createElement("style");
|
||||
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 == "left") {sheet.innerHTML = ".ns-box {margin-right: auto;text-align: left;}";}
|
||||
document.body.appendChild(sheet);
|
||||
|
||||
|
||||
},
|
||||
notificationReceived: function(notification, payload, sender) {
|
||||
if (notification === 'SHOW_ALERT') {
|
||||
if (typeof payload.type === 'undefined') { payload.type = "alert"; }
|
||||
if (payload.type == "alert"){
|
||||
this.show_alert(payload, sender)
|
||||
if (notification === "SHOW_ALERT") {
|
||||
if (typeof payload.type === "undefined") { payload.type = "alert"; }
|
||||
if (payload.type == "alert") {
|
||||
this.show_alert(payload, sender);
|
||||
} else if (payload.type = "notification") {
|
||||
this.show_notification(payload);
|
||||
}
|
||||
else if (payload.type = "notification"){
|
||||
this.show_notification(payload)
|
||||
}
|
||||
}
|
||||
else if (notification === 'HIDE_ALERT') {
|
||||
this.hide_alert(sender)
|
||||
} else if (notification === "HIDE_ALERT") {
|
||||
this.hide_alert(sender);
|
||||
}
|
||||
},
|
||||
start: function() {
|
||||
this.alerts = {}
|
||||
this.setPosition(this.config.position)
|
||||
if (this.config.welcome_message){
|
||||
this.show_notification({title: "MagicMirror Notification", message: this.config.welcome_message})
|
||||
this.alerts = {};
|
||||
this.setPosition(this.config.position);
|
||||
if (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);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
@@ -1,80 +1,79 @@
|
||||
/*!
|
||||
* classie - class helper functions
|
||||
* from bonzo https://github.com/ded/bonzo
|
||||
*
|
||||
*
|
||||
* classie.has( elem, 'my-class' ) -> true/false
|
||||
* classie.add( elem, 'my-new-class' )
|
||||
* classie.remove( elem, 'my-unwanted-class' )
|
||||
* classie.toggle( elem, 'my-class' )
|
||||
*/
|
||||
|
||||
// jscs:disable
|
||||
/*jshint browser: true, strict: true, undef: true */
|
||||
/*global define: false */
|
||||
|
||||
( function( window ) {
|
||||
(function(window) {
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
// class helper functions from bonzo https://github.com/ded/bonzo
|
||||
|
||||
function classReg( className ) {
|
||||
return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
|
||||
function classReg(className) {
|
||||
return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
|
||||
}
|
||||
|
||||
// classList support for class management
|
||||
// altho to be fair, the api sucks because it won't accept multiple classes at once
|
||||
var hasClass, addClass, removeClass;
|
||||
|
||||
if ( 'classList' in document.documentElement ) {
|
||||
hasClass = function( elem, c ) {
|
||||
return elem.classList.contains( c );
|
||||
};
|
||||
addClass = function( elem, c ) {
|
||||
elem.classList.add( c );
|
||||
};
|
||||
removeClass = function( elem, c ) {
|
||||
elem.classList.remove( c );
|
||||
};
|
||||
}
|
||||
else {
|
||||
hasClass = function( elem, c ) {
|
||||
return classReg( c ).test( elem.className );
|
||||
};
|
||||
addClass = function( elem, c ) {
|
||||
if ( !hasClass( elem, c ) ) {
|
||||
elem.className = elem.className + ' ' + c;
|
||||
}
|
||||
};
|
||||
removeClass = function( elem, c ) {
|
||||
elem.className = elem.className.replace( classReg( c ), ' ' );
|
||||
};
|
||||
if ("classList" in document.documentElement) {
|
||||
hasClass = function(elem, c) {
|
||||
return elem.classList.contains(c);
|
||||
};
|
||||
addClass = function(elem, c) {
|
||||
elem.classList.add(c);
|
||||
};
|
||||
removeClass = function(elem, c) {
|
||||
elem.classList.remove(c);
|
||||
};
|
||||
} else {
|
||||
hasClass = function(elem, c) {
|
||||
return classReg(c).test(elem.className);
|
||||
};
|
||||
addClass = function(elem, c) {
|
||||
if (!hasClass(elem, c)) {
|
||||
elem.className = elem.className + " " + c;
|
||||
}
|
||||
};
|
||||
removeClass = function(elem, c) {
|
||||
elem.className = elem.className.replace(classReg(c), " ");
|
||||
};
|
||||
}
|
||||
|
||||
function toggleClass( elem, c ) {
|
||||
var fn = hasClass( elem, c ) ? removeClass : addClass;
|
||||
fn( elem, c );
|
||||
function toggleClass(elem, c) {
|
||||
var fn = hasClass(elem, c) ? removeClass : addClass;
|
||||
fn(elem, c);
|
||||
}
|
||||
|
||||
var classie = {
|
||||
// full names
|
||||
hasClass: hasClass,
|
||||
addClass: addClass,
|
||||
removeClass: removeClass,
|
||||
toggleClass: toggleClass,
|
||||
// short names
|
||||
has: hasClass,
|
||||
add: addClass,
|
||||
remove: removeClass,
|
||||
toggle: toggleClass
|
||||
// full names
|
||||
hasClass: hasClass,
|
||||
addClass: addClass,
|
||||
removeClass: removeClass,
|
||||
toggleClass: toggleClass,
|
||||
// short names
|
||||
has: hasClass,
|
||||
add: addClass,
|
||||
remove: removeClass,
|
||||
toggle: toggleClass
|
||||
};
|
||||
|
||||
// transport
|
||||
if ( typeof define === 'function' && define.amd ) {
|
||||
// AMD
|
||||
define( classie );
|
||||
if (typeof define === "function" && define.amd) {
|
||||
// AMD
|
||||
define(classie);
|
||||
} else {
|
||||
// browser global
|
||||
window.classie = classie;
|
||||
// browser global
|
||||
window.classie = classie;
|
||||
}
|
||||
|
||||
})( window );
|
||||
})(window);
|
||||
|
File diff suppressed because one or more lines are too long
@@ -4,31 +4,32 @@
|
||||
*
|
||||
* Licensed under the MIT license.
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
*
|
||||
* Copyright 2014, Codrops
|
||||
* http://www.codrops.com
|
||||
*/
|
||||
;( function( window ) {
|
||||
|
||||
'use strict';
|
||||
// jscs:disable
|
||||
;(function(window) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var docElem = window.document.documentElement,
|
||||
support = { animations : Modernizr.cssanimations },
|
||||
support = {animations: Modernizr.cssanimations},
|
||||
animEndEventNames = {
|
||||
'WebkitAnimation' : 'webkitAnimationEnd',
|
||||
'OAnimation' : 'oAnimationEnd',
|
||||
'msAnimation' : 'MSAnimationEnd',
|
||||
'animation' : 'animationend'
|
||||
"WebkitAnimation": "webkitAnimationEnd",
|
||||
"OAnimation": "oAnimationEnd",
|
||||
"msAnimation": "MSAnimationEnd",
|
||||
"animation": "animationend"
|
||||
},
|
||||
// animation end event name
|
||||
animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ];
|
||||
|
||||
animEndEventName = animEndEventNames[ Modernizr.prefixed("animation") ];
|
||||
|
||||
/**
|
||||
* extend obj function
|
||||
*/
|
||||
function extend( a, b ) {
|
||||
for( var key in b ) {
|
||||
if( b.hasOwnProperty( key ) ) {
|
||||
function extend(a, b) {
|
||||
for (var key in b) {
|
||||
if (b.hasOwnProperty(key)) {
|
||||
a[key] = b[key];
|
||||
}
|
||||
}
|
||||
@@ -38,9 +39,9 @@
|
||||
/**
|
||||
* NotificationFx function
|
||||
*/
|
||||
function NotificationFx( options ) {
|
||||
this.options = extend( {}, this.options );
|
||||
extend( this.options, options );
|
||||
function NotificationFx(options) {
|
||||
this.options = extend({}, this.options);
|
||||
extend(this.options, options);
|
||||
this._init();
|
||||
}
|
||||
|
||||
@@ -50,28 +51,28 @@
|
||||
NotificationFx.prototype.options = {
|
||||
// element to which the notification will be appended
|
||||
// defaults to the document.body
|
||||
wrapper : document.body,
|
||||
wrapper: document.body,
|
||||
// the message
|
||||
message : 'yo!',
|
||||
message: "yo!",
|
||||
// layout type: growl|attached|bar|other
|
||||
layout : 'growl',
|
||||
layout: "growl",
|
||||
// effects for the specified layout:
|
||||
// for growl layout: scale|slide|genie|jelly
|
||||
// for attached layout: flip|bouncyflip
|
||||
// for other layout: boxspinner|cornerexpand|loadingcircle|thumbslider
|
||||
// ...
|
||||
effect : 'slide',
|
||||
effect: "slide",
|
||||
// notice, warning, error, success
|
||||
// will add class ns-type-warning, ns-type-error or ns-type-success
|
||||
type : 'notice',
|
||||
// if the user doesn´t close the notification then we remove it
|
||||
type: "notice",
|
||||
// if the user doesn´t close the notification then we remove it
|
||||
// after the following time
|
||||
ttl : 6000,
|
||||
ttl: 6000,
|
||||
al_no: "ns-box",
|
||||
// callbacks
|
||||
onClose : function() { return false; },
|
||||
onOpen : function() { return false; }
|
||||
}
|
||||
onClose: function() { return false; },
|
||||
onOpen: function() { return false; }
|
||||
};
|
||||
|
||||
/**
|
||||
* init function
|
||||
@@ -79,29 +80,29 @@
|
||||
*/
|
||||
NotificationFx.prototype._init = function() {
|
||||
// create HTML structure
|
||||
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;
|
||||
var strinner = '<div class="ns-box-inner">';
|
||||
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;
|
||||
var strinner = "<div class=\"ns-box-inner\">";
|
||||
strinner += this.options.message;
|
||||
strinner += '</div>';
|
||||
strinner += "</div>";
|
||||
this.ntf.innerHTML = strinner;
|
||||
|
||||
// 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
|
||||
var self = this;
|
||||
if (this.options.ttl){
|
||||
this.dismissttl = setTimeout( function() {
|
||||
if( self.active ) {
|
||||
if (this.options.ttl) {
|
||||
this.dismissttl = setTimeout(function() {
|
||||
if (self.active) {
|
||||
self.dismiss();
|
||||
}
|
||||
}, this.options.ttl );
|
||||
}, this.options.ttl);
|
||||
}
|
||||
|
||||
// init events
|
||||
this._initEvents();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* init events
|
||||
@@ -109,18 +110,18 @@
|
||||
NotificationFx.prototype._initEvents = function() {
|
||||
var self = this;
|
||||
// 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
|
||||
*/
|
||||
NotificationFx.prototype.show = function() {
|
||||
this.active = true;
|
||||
classie.remove( this.ntf, 'ns-hide' );
|
||||
classie.add( this.ntf, 'ns-show' );
|
||||
classie.remove(this.ntf, "ns-hide");
|
||||
classie.add(this.ntf, "ns-show");
|
||||
this.options.onOpen();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* dismiss the notification
|
||||
@@ -128,35 +129,34 @@
|
||||
NotificationFx.prototype.dismiss = function() {
|
||||
var self = this;
|
||||
this.active = false;
|
||||
clearTimeout( this.dismissttl );
|
||||
classie.remove( this.ntf, 'ns-show' );
|
||||
setTimeout( function() {
|
||||
classie.add( self.ntf, 'ns-hide' );
|
||||
|
||||
clearTimeout(this.dismissttl);
|
||||
classie.remove(this.ntf, "ns-show");
|
||||
setTimeout(function() {
|
||||
classie.add(self.ntf, "ns-hide");
|
||||
|
||||
// callback
|
||||
self.options.onClose();
|
||||
}, 25 );
|
||||
}, 25);
|
||||
|
||||
// after animation ends remove ntf from the DOM
|
||||
var onEndAnimationFn = function( ev ) {
|
||||
if( support.animations ) {
|
||||
if( ev.target !== self.ntf ) return false;
|
||||
this.removeEventListener( animEndEventName, onEndAnimationFn );
|
||||
var onEndAnimationFn = function(ev) {
|
||||
if (support.animations) {
|
||||
if (ev.target !== self.ntf) return false;
|
||||
this.removeEventListener(animEndEventName, onEndAnimationFn);
|
||||
}
|
||||
self.options.wrapper.removeChild( this );
|
||||
self.options.wrapper.removeChild(this);
|
||||
};
|
||||
|
||||
if( support.animations ) {
|
||||
this.ntf.addEventListener( animEndEventName, onEndAnimationFn );
|
||||
}
|
||||
else {
|
||||
if (support.animations) {
|
||||
this.ntf.addEventListener(animEndEventName, onEndAnimationFn);
|
||||
} else {
|
||||
onEndAnimationFn();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* add to global namespace
|
||||
*/
|
||||
window.NotificationFx = NotificationFx;
|
||||
|
||||
} )( window );
|
||||
})(window);
|
||||
|
Reference in New Issue
Block a user