mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
Replace old js files with modern code
This commit is contained in:
parent
c8a9c9b84e
commit
06e8308dc2
@ -21,7 +21,7 @@ Module.register("alert",{
|
|||||||
welcome_message: false,
|
welcome_message: false,
|
||||||
},
|
},
|
||||||
getScripts: function() {
|
getScripts: function() {
|
||||||
return ["classie.js", "modernizr.custom.js", "notificationFx.js"];
|
return ["notificationFx.js"];
|
||||||
},
|
},
|
||||||
getStyles: function() {
|
getStyles: function() {
|
||||||
return ["ns-default.css", "font-awesome.css"];
|
return ["ns-default.css", "font-awesome.css"];
|
||||||
@ -36,7 +36,7 @@ Module.register("alert",{
|
|||||||
},
|
},
|
||||||
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;}
|
||||||
msg = "";
|
let msg = "";
|
||||||
if (message.title) {
|
if (message.title) {
|
||||||
msg += "<span class='thin dimmed medium'>" + message.title + "</span>";
|
msg += "<span class='thin dimmed medium'>" + message.title + "</span>";
|
||||||
}
|
}
|
||||||
@ -55,20 +55,19 @@ Module.register("alert",{
|
|||||||
}).show();
|
}).show();
|
||||||
},
|
},
|
||||||
show_alert: function(params, sender) {
|
show_alert: function(params, sender) {
|
||||||
var self = this;
|
let image = "";
|
||||||
//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" && typeof params.imageFA === "undefined") {
|
if (typeof params.imageUrl === "undefined" && typeof params.imageFA === "undefined") {
|
||||||
params.imageUrl = null;
|
params.imageUrl = null;
|
||||||
image = "";
|
|
||||||
} else if (typeof params.imageFA === "undefined"){
|
} else if (typeof params.imageFA === "undefined"){
|
||||||
image = "<img src='" + (params.imageUrl).toString() + "' height='" + (params.imageHeight).toString() + "' style='margin-bottom: 10px;'/><br />";
|
image = "<img src='" + (params.imageUrl).toString() + "' height='" + (params.imageHeight).toString() + "' style='margin-bottom: 10px;'/><br />";
|
||||||
} else if (typeof params.imageUrl === "undefined"){
|
} else if (typeof params.imageUrl === "undefined"){
|
||||||
image = "<span class='bright " + "fa fa-" + params.imageFA + "' style='margin-bottom: 10px;font-size:" + (params.imageHeight).toString() + ";'/></span><br />";
|
image = "<span class='bright " + "fa fa-" + params.imageFA + "' style='margin-bottom: 10px;font-size:" + (params.imageHeight).toString() + ";'/></span><br />";
|
||||||
}
|
}
|
||||||
//Create overlay
|
//Create overlay
|
||||||
var overlay = document.createElement("div");
|
const 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);
|
||||||
@ -79,7 +78,7 @@ Module.register("alert",{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Display title and message only if they are provided in notification parameters
|
//Display title and message only if they are provided in notification parameters
|
||||||
var message = "";
|
let message = "";
|
||||||
if (params.title) {
|
if (params.title) {
|
||||||
message += "<span class='light dimmed medium'>" + params.title + "</span>";
|
message += "<span class='light dimmed medium'>" + params.title + "</span>";
|
||||||
}
|
}
|
||||||
@ -102,8 +101,8 @@ Module.register("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(() => {
|
||||||
self.hide_alert(sender);
|
this.hide_alert(sender);
|
||||||
}, params.timer);
|
}, params.timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,13 +113,13 @@ Module.register("alert",{
|
|||||||
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");
|
const 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");
|
const 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;}";}
|
||||||
|
@ -1,79 +0,0 @@
|
|||||||
/*!
|
|
||||||
* 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) {
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// class helper functions from bonzo https://github.com/ded/bonzo
|
|
||||||
|
|
||||||
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), " ");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
// transport
|
|
||||||
if (typeof define === "function" && define.amd) {
|
|
||||||
// AMD
|
|
||||||
define(classie);
|
|
||||||
} else {
|
|
||||||
// browser global
|
|
||||||
window.classie = classie;
|
|
||||||
}
|
|
||||||
|
|
||||||
})(window);
|
|
File diff suppressed because one or more lines are too long
@ -1,4 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
|
* Code originally from
|
||||||
|
*
|
||||||
* notificationFx.js v1.0.0
|
* notificationFx.js v1.0.0
|
||||||
* http://www.codrops.com
|
* http://www.codrops.com
|
||||||
*
|
*
|
||||||
@ -8,40 +10,13 @@
|
|||||||
* Copyright 2014, Codrops
|
* Copyright 2014, Codrops
|
||||||
* http://www.codrops.com
|
* http://www.codrops.com
|
||||||
*/
|
*/
|
||||||
// jscs:disable
|
|
||||||
;(function(window) {
|
;(function(window) {
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var docElem = window.document.documentElement,
|
|
||||||
support = {animations: Modernizr.cssanimations},
|
|
||||||
animEndEventNames = {
|
|
||||||
"WebkitAnimation": "webkitAnimationEnd",
|
|
||||||
"OAnimation": "oAnimationEnd",
|
|
||||||
"msAnimation": "MSAnimationEnd",
|
|
||||||
"animation": "animationend"
|
|
||||||
},
|
|
||||||
// animation end event name
|
|
||||||
animEndEventName = animEndEventNames[ Modernizr.prefixed("animation") ];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* extend obj function
|
|
||||||
*/
|
|
||||||
function extend(a, b) {
|
|
||||||
for (var key in b) {
|
|
||||||
if (b.hasOwnProperty(key)) {
|
|
||||||
a[key] = b[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NotificationFx function
|
* NotificationFx function
|
||||||
*/
|
*/
|
||||||
function NotificationFx(options) {
|
function NotificationFx(options) {
|
||||||
this.options = extend({}, this.options);
|
this.options = { ...this.options, ...options };
|
||||||
extend(this.options, options);
|
|
||||||
this._init();
|
this._init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +57,7 @@
|
|||||||
// 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\">";
|
let 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;
|
||||||
@ -91,13 +66,12 @@
|
|||||||
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;
|
|
||||||
if (this.options.ttl) {
|
if (this.options.ttl) {
|
||||||
this.dismissttl = setTimeout(function() {
|
this.dismissttl = setTimeout(() => {
|
||||||
if (self.active) {
|
if (this.active) {
|
||||||
self.dismiss();
|
this.dismiss();
|
||||||
}
|
}
|
||||||
}, this.options.ttl);
|
}, this.options.ttl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// init events
|
// init events
|
||||||
@ -108,9 +82,8 @@
|
|||||||
* init events
|
* init events
|
||||||
*/
|
*/
|
||||||
NotificationFx.prototype._initEvents = function() {
|
NotificationFx.prototype._initEvents = function() {
|
||||||
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", () => { this.dismiss(); });
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,8 +91,8 @@
|
|||||||
*/
|
*/
|
||||||
NotificationFx.prototype.show = function() {
|
NotificationFx.prototype.show = function() {
|
||||||
this.active = true;
|
this.active = true;
|
||||||
classie.remove(this.ntf, "ns-hide");
|
this.ntf.classList.remove("ns-hide");
|
||||||
classie.add(this.ntf, "ns-show");
|
this.ntf.classList.add("ns-show");
|
||||||
this.options.onOpen();
|
this.options.onOpen();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -127,34 +100,27 @@
|
|||||||
* dismiss the notification
|
* dismiss the notification
|
||||||
*/
|
*/
|
||||||
NotificationFx.prototype.dismiss = function() {
|
NotificationFx.prototype.dismiss = function() {
|
||||||
var self = this;
|
|
||||||
this.active = false;
|
this.active = false;
|
||||||
clearTimeout(this.dismissttl);
|
clearTimeout(this.dismissttl);
|
||||||
classie.remove(this.ntf, "ns-show");
|
this.ntf.classList.remove("ns-show");
|
||||||
setTimeout(function() {
|
setTimeout(() => {
|
||||||
classie.add(self.ntf, "ns-hide");
|
this.ntf.classList.add("ns-hide");
|
||||||
|
|
||||||
// callback
|
// callback
|
||||||
self.options.onClose();
|
this.options.onClose();
|
||||||
}, 25);
|
}, 25);
|
||||||
|
|
||||||
// after animation ends remove ntf from the DOM
|
// after animation ends remove ntf from the DOM
|
||||||
var onEndAnimationFn = function(ev) {
|
const onEndAnimationFn = (ev) => {
|
||||||
if (support.animations) {
|
if (ev.target !== this.ntf) return false;
|
||||||
if (ev.target !== self.ntf) return false;
|
this.ntf.removeEventListener("animationend", onEndAnimationFn);
|
||||||
this.removeEventListener(animEndEventName, onEndAnimationFn);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.parentNode === self.options.wrapper) {
|
if (ev.target.parentNode === this.options.wrapper) {
|
||||||
self.options.wrapper.removeChild(this);
|
this.options.wrapper.removeChild(this.ntf);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (support.animations) {
|
this.ntf.addEventListener("animationend", onEndAnimationFn);
|
||||||
this.ntf.addEventListener(animEndEventName, onEndAnimationFn);
|
|
||||||
} else {
|
|
||||||
onEndAnimationFn();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user