-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsc3d.console.js
149 lines (128 loc) · 4.89 KB
/
jsc3d.console.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* @preserve Copyright (c) 2011~2014 Humu <[email protected]>
* This file is part of jsc3d project, which is freely distributable under the
* terms of the MIT license.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* @namespace JSC3D
*/
var JSC3D = JSC3D || {};
/**
The console instance where to display debugging informations.
Based upon code originally provided by X3DOM project, under the MIT license.
*/
JSC3D.console = (function() {
var _container = null;
var _isActive = true;
var _icons = {
info: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAj0lEQVQ4jc2SMRKEIAxFUzokZ7Ky8hjW3kQ+VpQWHs/IHdxqZ2eJIp1mJlV4j5BA9LpQuD6B1xTk+EvwqnB9GQ4yGjBLDTJe35wd/taM5KyTBF5qBQm8WMFN61fyoqCm9iKBeonVW/ASjWCbuKsd4DZxZwRERAo33H4kuOEU/j2laXfwnIM7eFbftEX4kfgAqhIisuNA6JsAAAAASUVORK5CYII=',
warn: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAgElEQVQ4jWNgGNTgTQ9XwJsergCyNL/u5Vn/po/n/5s+nv+ve3nWk6T5VR+3B0wzDL/q4/Yg2fb7DQwC9xsYBEhyBbLtMDGSXIHsd2QXEOWK1908Duh+R8evu3kccBqArpiQOEHb0b2A1xWEnE7QFa/7uM8Sq/l1H/dZvIE5tAAANzDIfYoSrJQAAAAASUVORK5CYII=',
error: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAo0lEQVQ4jc2RPQ6DMAyFPSLsMzExcQqUmZsQh4mRgeNhcod2Ka1LfppOYMlDJL/vPTsAtyvhuvOMq3f0+GrGVbju8mJHQyA8tTga0s4/xG9ILIlnXNSAAQA43i8Do9ZZQoByUKnMAUvNRAE6ReBeDsD+A8D+L4AWalAWIJbm0iOKpTkAbCO2pd+4jdgGgNSxcseNQ2zV7IzTWbgzTmKrJiu+pJ5VHxECVZ0hewAAAABJRU5ErkJggg=='
};
function _setup(parentElement, height, activate) {
var parent = (typeof(parentElement) == 'string') ? document.getElementById(parentElement) : parentElement;
if(!parent)
return;
_container = document.createElement('div');
_container.id = 'jsc3d_console';
_container.style.border = '2px solid olivedrab';
_container.style.height = (height != undefined) ? height : '150px';
_container.style.padding = '4px';
_container.style.overflow = 'auto';
_container.style.whiteSpace = 'pre-wrap';
_container.style.fontFamily = 'sans-serif';
_container.style.fontSize = 'small';
_container.style.color = '#00ff00';
_container.style.backgroundColor = 'black';
_container.style.clear = 'both';
parent.appendChild(_container);
_isActive = (activate != undefined) ? activate : true;
}
function _activate(isActive) {
_isActive = (isActive != undefined) ? isActive : true;
}
function _logInfo(msg) {
_doLogMessage(msg, 'info');
}
function _logWarning(msg) {
_doLogMessage(msg, 'warn');
}
function _logError(msg) {
_doLogMessage(msg, 'error');
}
function _doLogMessage(msg, type) {
if(!_isActive) {
return false;
}
if(_container) {
var newLine = document.createElement('p');
newLine.style.margin = '0px';
//newLine.style.height = '16px';
newLine.style.clear = 'both';
switch(type) {
case 'info':
newLine.innerHTML = '<img src=' + _icons.info + ' style="float:left;">' + msg;
break;
case 'warn':
newLine.innerHTML = '<img src=' + _icons.warn + ' style="float:left;">' + msg;
break;
case 'error':
newLine.style.color = '#ff0000';
newLine.innerHTML = '<img src=' + _icons.error + ' style="float:left;">' + msg;
break;
default:
break;
}
_container.appendChild(newLine);
newLine.scrollIntoView(true);
}
else if(window['console']) {
switch(type) {
case 'info':
console.info(msg);
break;
case 'warn':
console.warn(msg);
break;
case 'error':
console.error(msg);
break;
default:
break;
}
}
}
function _clear() {
if(_isActive && _container != null) {
while(_container.lastChild) {
_container.removeChild(_container.lastChild);
}
}
}
return {
setup: _setup,
activate: _activate,
logInfo: _logInfo,
logWarning: _logWarning,
logError: _logError,
clear: _clear
};
}) ();