-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.js
56 lines (48 loc) · 1.42 KB
/
debug.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
/* Birdcage Builder
*
* Debug Helpers
*
* Douglas Brantner
* 27 April 2023
* NYU Langone Health
* cai2r.net
*/
// TODO make this a class?
// set these in GUI handler:
// these get overridden by BBGuiHandler.js - these are just default values
// set the actual values in BBGuiHandler.js
var DEBUG_ENABLE = false; // bool; enable or disable debug printing to DOM
var DEBUG_ID; // DOM ID for debug output
var DEBUG_OUTPUT = "CONSOLE"; // 'CONSOLE' or 'DOM' or 'BOTH'
// CONSOLE = use console.log (hidden from users - use for production!)
// DOM = populate DEBUG_ID field in actual HTML page (debugging only)
function debug(s) {
/* Append a string s to the DEBUG_ID DOM element if global DEBUG_ENABLE is true
* UPDATE: follows the DEBUG_OUTPUT global and prints to console and/or DOM
*
* s = string to print
*
* Automatically adds a newline/<br> tag to create a new line for DOM output
*/
if (DEBUG_ENABLE) {
if (DEBUG_OUTPUT === "CONSOLE" || DEBUG_OUTPUT === "BOTH") {
console.log(s);
}
if (DEBUG_OUTPUT === "DOM" || DEBUG_OUTPUT === "BOTH") {
document.getElementById(DEBUG_ID).innerHTML += s + '<br>';
}
}
}
function debug1 (s) {
/* print 1 debug statement with NO newline at the end
* (DOM only)
*
*/
if (DEBUG_ENABLE) {
document.getElementById(DEBUG_ID).innerHTML += s;
}
}
function debug_clear() {
/* Clear the DEBUG_ID field (DOM only) */
document.getElementById(DEBUG_ID).innerHTML = '';
}