forked from skewten/PYE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.js
More file actions
39 lines (38 loc) · 997 Bytes
/
debug.js
File metadata and controls
39 lines (38 loc) · 997 Bytes
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
/*
debug.js
A convenient alternative to console
*/
String.prototype.hashCode = function() {
var hash = 0,
i,
chr,
len;
if (this.length == 0)
return hash;
for (i=0,len=this.length;i<len;i++){
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
var debug = {};
debug.log = function(msg){
debug.format(msg, "log");
}
debug.warn = function(msg){
debug.format(msg, "warn");
}
debug.error = function(msg){
debug.format(msg, "error");
}
debug.success = function(msg){
debug.format(msg, "success");
}
debug.format = function(msg, type){
var id = String(Date.now()+msg).hashCode();
$("#debug_console").append("<pre class='msg "+type+" id_"+id+"'></pre>");
$("#debug_console .id_"+id).html(msg);
$("#debug_console").scrollTop($("#debug_console")[0].scrollHeight);
window.console && console[type] && console[type](msg);
}