fix console toast

This commit is contained in:
Namhyeon Go 2020-11-04 18:32:25 +09:00
parent 2f57d4860f
commit 512b8e845f
2 changed files with 32 additions and 16 deletions

20
app.js
View File

@ -36,38 +36,32 @@ var exit = function(status) {
if (typeof(WScript) !== "undefined") { if (typeof(WScript) !== "undefined") {
WScript.quit(status); WScript.quit(status);
} }
console.warn("Exit caused by: " + status); console.warn("Exit caused: " + status);
}; };
var console = { var console = {
_messages: [], _messages: [],
_echo: function(msg) { _echo: function(msg, type) {
msg = (typeof(type) !== "undefined" ? type + ": " : "") + msg;
if (typeof(WScript) !== "undefined") { if (typeof(WScript) !== "undefined") {
WScript.echo(msg); WScript.echo(msg);
} else if (typeof(window) !== "undefined") {
//window.alert(msg);
} }
this._messages.push(msg); this._messages.push(msg);
}, },
log: function(msg) { log: function(msg) {
this._echo(msg); this._echo(msg);
}, },
error: function(msg) { error: function(msg) {
var msg = "[ERROR] " + msg; this._echo(msg, "error");
this._echo(msg);
}, },
info: function(msg) { info: function(msg) {
var msg = "[INFO] " + msg; this._echo(msg, "info");
this._echo(msg);
}, },
warn: function(msg) { warn: function(msg) {
var msg = "[WARN] " + msg; this._echo(msg, "warn");
this._echo(msg);
}, },
debug: function(msg) { debug: function(msg) {
var msg = "[DEBUG] " + msg; this._echo(msg, "debug");
this._echo(msg);
} }
}; };

View File

@ -7,12 +7,34 @@ var OldBrowser = require("lib/oldbrowser");
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Override global.console._echo() // Override global.console._echo()
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
global.console._echo = function(msg) { global.console._echo = function(msg, type) {
var heading, icon;
switch(type) {
case "error":
heading = "Error";
icon = "error";
break;
case "warning":
heading = "Warning";
icon = "warning";
break;
case "info":
heading = "Information";
icon = "info";
default:
heading = "Message";
icon = "success";
}
if (typeof(window.jQuery) !== "undefined") { if (typeof(window.jQuery) !== "undefined") {
window.jQuery.toast({ window.jQuery.toast({
heading: "Information", heading: heading,
text: msg, text: msg,
icon: "info" icon: icon
}); });
} else { } else {
window.alert(msg); window.alert(msg);