forked from jsbin/jsbin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.js
More file actions
86 lines (75 loc) · 2.38 KB
/
console.js
File metadata and controls
86 lines (75 loc) · 2.38 KB
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
var _console = (function () {
var body = document.getElementsByTagName('body')[0],
holding = null;
function createHolding() {
if (!holding) {
var el = document.createElement('div');
el.style.backgroundColor = '#ccc';
el.style.border = '1px solid #ccc';
el.style.borderBottom = 'none';
el.style.fontSize = '13px';
el.style.fontFamily = 'helvetica, arial';
el.style.position = 'fixed';
el.style.bottom = '0';
el.style.left = '0';
el.style.width = '100%';
el.style.maxHeight = '150px';
el.style.overflowY = 'auto';
body.appendChild(el);
holding = el;
var con = p('<strong>Console</strong>');
con.style.backgroundColor = '#ccc';
con.style.padding = '5px 10px';
}
}
function p(html, color) {
var el = document.createElement('p');
el.style.padding = '10px';
el.style.margin = '1px 0';
el.style.backgroundColor = '#FFFFD5';
el.style.color = color || '#000';
el.innerHTML = html;
holding.appendChild(el);
return el;
}
return {
error: function (e) {
var sourceEl = null;
var line = null;
var ua = navigator.userAgent.toLowerCase();
createHolding();
var el = p('<strong>Exception thrown:</strong> ' + e.message, '#f00');
if (e.lineNumber) {
line = e.lineNumber;
} else if (e['opera#sourceloc']) {
line = e['opera#sourceloc'];
} else {
line = e.line;
}
var oline = line;
// Firefox counts 1 less
// Safari counts 3 less
// Opera counts from inside the body element
if (/opera/.test(ua)) {
sourceEl = body;
line++;
} else if (/webkit/.test(ua)) {
// if the error is on the last line it confuses the debugger... :(
sourceEl = document.getElementsByTagName('html')[0];
line -= 4;
} else {
sourceEl = document.getElementsByTagName('html')[0];
line -= 2;
}
if (line) {
el.innerHTML += '<br />Caused by line (' + oline + '/' + line + '): <code>' + sourceEl.innerHTML.split(/\n/)[line] + '</code>';
}
// body.appendChild(el);
},
log: function () {
// window.top.console.log.apply(window.top, arguments);
createHolding();
p(Array.prototype.join.call(arguments, ', '), '#000');
}
};
})();