-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
159 lines (141 loc) · 4.32 KB
/
scripts.js
File metadata and controls
159 lines (141 loc) · 4.32 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
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
150
151
152
153
154
155
156
157
158
/* scripts.js */
try { console.debug("loading scripts.js."); } catch (e){ }
/** definitions to save some exceptions that needn't happen */
defineThings = function(){
if(typeof console != "undefined" && typeof console.info != "undefined"){ info = function(msg){ console.info(msg); }}
if(typeof console != "undefined" && typeof console.debug != "undefined"){ debug = function(msg){ console.debug(msg); }}
if(typeof console != "undefined" && typeof console.log != "undefined"){log = function(msg){console.log(msg);}}
if(typeof console != "undefined" && typeof console.warn != "undefined"){warn = function(msg){console.warn(msg);}}
if(typeof console != "undefined" && typeof console.error != "undefined"){error = function(msg){console.error(msg);}}
if(typeof body == "undefined"){body = document.body;}
if(typeof DEBUG == "undefined"){DEBUG = false;}
if(typeof tmp == "undefined"){tmp = null;}
}
defineThings();
/**
* For console.info, .debug, .log, .warn, and .error,
* create new shortcuts to them without the "console.".
*/
__initLoggerShortcuts = function(){
if(typeof console != "undefined"){
if(typeof console.info != "undefined"){
info = function(msg){
console.info(msg);
};
}
if(typeof console.debug != "undefined"){
debug = function(msg){
console.debug(msg);
};
}
if(typeof console.log != "undefined"){
log = function(msg){
console.log(msg);
};
}
if(typeof console.warn != "undefined"){
warn = function(msg){
console.warn(msg);
};
}
if(typeof console.error != "undefined"){
error = function(msg){
console.error(msg);
};
}
}
}
__initLoggerShortcuts();
/**
* Toggle the visibility of an object or array or list of objects.
* In writing this function, I expected the object(s) in question
* to be a visible DOM element.
*
* I'm not sure whether current the jQuery-marked-up objects behave
* properly or not.
* @TESTME toggleVisibility :: jQuery
*
*/
toggleVisibility = function(x){
/* if there is no parameter passed, log a warning about it. */
if(typeof x == "undefined"){
console.warn("toggleVisibiity(): undefined param.");
return;
}
// if the object is an array or list
if(typeof x.length != "undefined"){
for(i = 0; i < x.length; i++){
o=x[i];
o.style["display"] = (o.style["display"]=="none") ? "" : "none";
}
}
// if the object is just one thing.
else {
x.style["display"] = (x.style["display"]=="none") ? "" : "none";
}
}
/** Pass in a DOM block element, and enable or disable its visibility.
* @param x the object of which to assign [in]visibility.
* @param visible a boolean, designating whether to display the element.
*/
setVisibility = function(x,visible){
if(typeof x == "undefined") return;
x.style["display"] = (typeof visible == "undefined" || visible == true) ? "" : "none";
}
// Prototype for general objects (? -- TODO TEST IT)
if("undefined" == typeof Object.prototype.setVisibility){
Object.prototype.setVisibility = function(visible){
setVisibility(this, visible);
}
}
/** This is a singleton object to perform document creation
* (and possibly some more stuff later).
*/
sir = {
lastReturn : null,
debug : (typeof DEBUG !== "undefined" ? DEBUG : true),
};
/**
* Creates a new TEXT node, and if defined, the first argument
* becomes its content.
* @returns the new text node (does not add it to the document).
*/
sir.textNode = function(msg){
var node;
if (typeof msg !== "undefined"){
node = document.createTextNode(msg);
if(DEBUG) debug("creating text node with text \"" + msg + "\".");
}
else{
node = document.createTextNode("");
if(DEBUG) debug("creating text node with empty string.");
}
this.lastReturn = node;
return node;
}
/**
* Appends a div to document.body, and returns that new DIV.
* One optional argument: becomes the HTML inside the new DIV.
*/
sir.appendDiv = function(html){
var div;
div = document.createElement("div");
if (typeof html !== "undefined"){
div.innerHTML = html;
if(DEBUG)
console.debug("setting innerHTML of div to \"" + html + "\".");
}
else{
if(DEBUG)
console.debug("creating empty DIV and appending.");
}
document.body.appendChild(div);
this.lastReturn = div;
return div;
}
var intervalIDs = [];
var theTime;
intervalIDs.push(setInterval(function(){
theTime = Date();
}, 900));
try { console.debug("done loading scripts.js."); } catch (e) {}