mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Removed sweetalert added custom alerts
This commit is contained in:
@@ -11,6 +11,8 @@ Module.register('alert',{
|
||||
defaults: {
|
||||
// scale|slide|genie|jelly|flip|bouncyflip|exploader
|
||||
effect: "slide",
|
||||
// scale|slide|genie|jelly|flip|bouncyflip|exploader
|
||||
alert_effect:"jelly",
|
||||
//time a notification is displayed
|
||||
display_time: 3500,
|
||||
//Position
|
||||
@@ -19,10 +21,10 @@ Module.register('alert',{
|
||||
welcome_message: "Welcome, start was successfull!"
|
||||
},
|
||||
getScripts: function() {
|
||||
return ["classie.js", "modernizr.custom.js", 'notificationFx.js', 'sweetalert.js'];
|
||||
return ["classie.js", "modernizr.custom.js", 'notificationFx.js'];
|
||||
},
|
||||
getStyles: function() {
|
||||
return ['ns-default.css', 'sweetalert.css'];
|
||||
return ['ns-default.css'];
|
||||
},
|
||||
show_notification: function (message) {
|
||||
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>"
|
||||
@@ -33,26 +35,57 @@ Module.register('alert',{
|
||||
ttl: this.config.display_time
|
||||
}).show();
|
||||
},
|
||||
show_alert: function (params) {
|
||||
if (typeof params["type"] === 'undefined') { params["type"] = null; }
|
||||
if (typeof params["imageUrl"] === 'undefined') { params["imageUrl"] = null; }
|
||||
if (typeof params["imageSize"] === 'undefined') { params["imageSize"] = null; }
|
||||
if (typeof params["timer"] === 'undefined') { params["timer"] = null; }
|
||||
swal({
|
||||
title: params["title"],
|
||||
imageUrl: params["imageUrl"],
|
||||
imageSize: params["imageSize"],
|
||||
type: params["type"],
|
||||
text: params["message"],
|
||||
timer: params["timer"],
|
||||
html: true,
|
||||
showConfirmButton: false
|
||||
});
|
||||
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') {
|
||||
params.imageUrl = null;
|
||||
image = ""
|
||||
}
|
||||
else {
|
||||
image = "<img src='" + params["imageUrl"] + "' height=" + params.imageHeight + " style='margin-bottom: 10px;'/><br />"
|
||||
}
|
||||
//Create overlay
|
||||
var overlay = document.createElement("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)
|
||||
}
|
||||
|
||||
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,
|
||||
ttl: null,
|
||||
al_no: "ns-alert"
|
||||
});
|
||||
//Show alert
|
||||
this.alerts[sender.name].show()
|
||||
//Add timer to dismiss alert and overlay
|
||||
if (params.timer) {
|
||||
setTimeout( function() {
|
||||
self.hide_alert(sender)
|
||||
}, params.timer );
|
||||
}
|
||||
|
||||
},
|
||||
hide_alert: function () {
|
||||
swal.close()
|
||||
hide_alert: function (sender) {
|
||||
//Dismiss alert and remove from this.alerts
|
||||
this.alerts[sender.name].dismiss()
|
||||
this.alerts[sender.name] = null
|
||||
//Remove overlay
|
||||
var overlay = document.getElementById("overlay");
|
||||
overlay.parentNode.removeChild(overlay);
|
||||
},
|
||||
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;}";}
|
||||
@@ -65,17 +98,18 @@ Module.register('alert',{
|
||||
this.show_notification(payload)
|
||||
}
|
||||
else if (notification === 'SHOW_ALERT') {
|
||||
this.show_alert(payload)
|
||||
this.show_alert(payload, sender)
|
||||
}
|
||||
else if (notification === 'HIDE_ALERT') {
|
||||
this.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.setPosition(this.config.position)
|
||||
Log.info('Starting module: ' + this.name);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user