-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
101 lines (80 loc) · 2.71 KB
/
logger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//var LOGGER = LOGGER || {};
/*=====================================================================================================
* LOGGER Module
*======================================================================================================*/
LOGGER = function () {
var init = function () {
console.log("LOGGER.init");
$("#consolerHolder").html('<div class="col-lg-24" id="consoler"><div class="row"><div class="col-lg-24" id="executor"><input type="text" id="command" class="input-sm"><span class="label label-danger" id="executorBtn">Send</span></div></div></div>');
$("#angulosoConsoler").click(function () {
showHide();
});
bindExecutor();
info("LOGGER.init.success");
};
function bindExecutor() {
$("#command").keyup(function (event) {
if (event.keyCode == 13) {
var command = $("#command").val();
try {
var result = jQuery.globalEval(command);
LOGGER.info(toString(result));
} catch (err) {
LOGGER.error(err);
}
}
});
$("#executorBtn").click(function () {
var command = $("#command").val();
try {
var result = eval(command);
LOGGER.info(toString(result));
} catch (err) {
LOGGER.error(err);
}
});
};
function toString(result) {
return result;
};
function info(message) {
appendLog("info", message);
};
function error(message) {
appendLog("error", message);
};
var appendLog = function (level, message) {
$("#consoler").append('<div class="row"><div class="col-lg-24 ' + getCssClassFromLogLevel(level) + '"><span class="label label-warning consoler-close">X</span> ' + message + '</div></div>');
$(".consoler-close").click(function () {
$(this).parent().parent().remove();
});
};
var getCssClassFromLogLevel = function (level) {
if (level === "info") {
return "text-primary";
}
if (level === "error") {
return "text-danger";
}
}
var showHide = function () {
if ($("#consolerHolder").is(":hidden")) {
show();
} else {
hide();
}
};
var show = function () {
$("#consolerHolder").slideDown();
$("#angulosoConsoleBtn").html("Console ⦿");
}
var hide = function () {
$("#consolerHolder").slideUp();
$("#angulosoConsoleBtn").html("⦿");
}
return {
init: init,
info: info,
error: error
}
}();