52 |
53 |
54 |
55 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/scripts/js.js:
--------------------------------------------------------------------------------
1 | //Code copyright (c) Brenton Fletcher 2006-2007.
2 | //Check out my portfolio at http://i.budgetwebdesign.org
3 |
4 | function $(ele)
5 | {
6 | var t = document.getElementById(ele);
7 | if(t == null) t = document.getElementsByName(ele);
8 | if(t.length == 1) t = t.item(0);
9 | return t;
10 | }
11 |
12 | function pad(str)
13 | {
14 | str = str + "";
15 | if(str.length == 0) return "00";
16 | if(str.length == 1) return "0" + str;
17 | if(str.length == 2) return str;
18 | }
19 |
20 | var http = null;
21 | var callback = null;
22 |
23 | function loadURL(str, inCallback)
24 | {
25 | callback = inCallback;
26 | http.open("get", str, true);
27 | http.onreadystatechange = gotURL;
28 | http.send(null);
29 | }
30 |
31 | function gotURL()
32 | {
33 | if(http.readyState == 4)
34 | {
35 | if(callback != null)
36 | {
37 | callback(http.responseText);
38 | }
39 | }
40 | }
41 |
42 | function editTitle()
43 | {
44 | title = (document.all ? $("counttitle").innerText : $("counttitle").textContent);
45 | $("titleinput").value = title;
46 | $("counttitle").style.display = "none";
47 | $("titleinput").style.display = "inline";
48 |
49 | setTimeout(function() { $("titleinput").focus(); }, 50);
50 | }
51 |
52 | function finishedEditTitle()
53 | {
54 | title = $("titleinput").value;
55 |
56 | $("counttitle").innerText = title;
57 | $("counttitle").textContent = title;
58 | $("counttitle").style.display = "inline";
59 | $("titleinput").style.display = "none";
60 |
61 | loadURL("link.php?mode=edittitle&title=" + title, null);
62 | }
63 |
64 | function initDates()
65 | {
66 | nodes = $("counttablebody").childNodes;
67 | for(i = 0; i < nodes.length; i++)
68 | {
69 | tr = nodes.item(i);
70 | if(tr.tagName != "TR") continue;
71 |
72 | when = new Date(parseInt(tr.childNodes.item(3).innerHTML));
73 | tr.childNodes.item(2).innerHTML = pad(when.getDate()) + "-" + pad(when.getMonth() + 1) + "-" + when.getFullYear() + " "
74 | + pad(when.getHours() > 12 ? when.getHours() - 12 : (when.getHours() == 0 ? 12 : when.getHours())) + ":"
75 | + pad(when.getMinutes()) + ":" + pad(when.getSeconds()) + " " + (when.getHours() > 11 ? "PM" : "AM");
76 | }
77 | }
78 |
79 | var currentWidth = 0;
80 | function initTableWrap()
81 | {
82 | if($("counttable").offsetWidth == currentWidth) return;
83 |
84 | $("counttablewrap").style.width = $("counttable").offsetWidth + 20 + "px";
85 | currentWindth = $("counttable").offsetWidth;
86 | }
87 |
88 | var allDisabled = false;
89 |
90 | function disableAll()
91 | {
92 | $("bumpbutton").disabled = "disabled";
93 | $("resetbutton").disabled = "disabled";
94 | $("changebutton").disabled = "disabled";
95 |
96 | var imgs = document.getElementsByTagName("img");
97 | for(i = 0; i < imgs.length; i++)
98 | {
99 | if(imgs[i].src == "images/remove.png") imgs[i].src = "images/remove-off.png";
100 | }
101 |
102 | allDisabled = true;
103 | }
104 |
105 | function enableAll()
106 | {
107 | $("bumpbutton").disabled = null;
108 | $("resetbutton").disabled = null;
109 | $("changebutton").disabled = null;
110 |
111 | var imgs = document.getElementsByTagName("img");
112 | for(i = 0; i < imgs.length; i++)
113 | {
114 | if(imgs[i].src == "images/remove-off.png") imgs[i].src = "images/remove.png";
115 | }
116 |
117 | allDisabled = false;
118 | }
119 |
120 | function bumpCounter()
121 | {
122 | disableAll();
123 |
124 | when = new Date();
125 | $("count").innerHTML = parseInt($("count").innerHTML) + 1 + "";
126 |
127 | var row = $("counttablebody").insertRow(0);
128 |
129 | var count = row.insertCell(-1);
130 | count.innerHTML = $("count").innerHTML;
131 |
132 | var type = row.insertCell(-1);
133 | type.innerHTML = "Bump";
134 |
135 | var whentd = row.insertCell(-1);
136 | whentd.innerHTML = pad(when.getDate()) + "-" + pad(when.getMonth() + 1) + "-" + when.getFullYear() + " "
137 | + pad(when.getHours() > 11 ? when.getHours() - 12 : when.getHours()) + ":" + pad(when.getMinutes()) + ":" + pad(when.getSeconds())
138 | + " " + (when.getHours() > 11 ? "PM" : "AM");
139 |
140 | var whentd2 = row.insertCell(-1);
141 | whentd2.innerHTML = when.getTime();
142 | whentd2.className = "hidden";
143 |
144 | var rem = row.insertCell(-1);
145 | rem.innerHTML = "

";
146 |
147 | loadURL("link.php?mode=bump×tamp=" + when.getTime(), function (str) { enableAll(); });
148 | }
149 |
150 | function resetCounter()
151 | {
152 | disableAll();
153 |
154 | when = new Date();
155 | $("count").innerHTML = "0";
156 |
157 | var row = $("counttablebody").insertRow(0);
158 |
159 | var count = row.insertCell(-1);
160 | count.innerHTML = "0";
161 |
162 | var type = row.insertCell(-1);
163 | type.innerHTML = "Reset";
164 |
165 | var whentd = row.insertCell(-1);
166 | whentd.innerHTML = pad(when.getDate()) + "-" + pad(when.getMonth() + 1) + "-" + when.getFullYear() + " "
167 | + pad(when.getHours() > 11 ? when.getHours() - 12 : when.getHours()) + ":" + pad(when.getMinutes()) + ":" + pad(when.getSeconds())
168 | + " " + (when.getHours() > 11 ? "PM" : "AM");
169 |
170 | var whentd2 = row.insertCell(-1);
171 | whentd2.innerHTML = when.getTime();
172 | whentd2.className = "hidden";
173 |
174 | var rem = row.insertCell(-1);
175 | rem.innerHTML = "

";
176 |
177 | loadURL("link.php?mode=reset×tamp=" + when.getTime(), function (str) { enableAll(); });
178 | }
179 |
180 | function createCounter()
181 | {
182 | disableAll();
183 |
184 | when = new Date();
185 |
186 | var row = $("counttablebody").insertRow(0);
187 |
188 | var count = row.insertCell(-1);
189 | count.innerHTML = "0";
190 |
191 | var type = row.insertCell(-1);
192 | type.innerHTML = "Creation";
193 |
194 | var whentd = row.insertCell(-1);
195 | whentd.innerHTML = pad(when.getDate()) + "-" + pad(when.getMonth() + 1) + "-" + when.getFullYear() + " "
196 | + pad(when.getHours() > 11 ? when.getHours() - 12 : when.getHours()) + ":" + pad(when.getMinutes()) + ":" + pad(when.getSeconds())
197 | + " " + (when.getHours() > 11 ? "PM" : "AM");
198 |
199 | var whentd2 = row.insertCell(-1);
200 | whentd2.innerHTML = when.getTime();
201 | whentd2.className = "hidden";
202 |
203 | var rem = row.insertCell(-1);
204 | rem.innerHTML = "

";
205 |
206 | loadURL("link.php?mode=create×tamp=" + when.getTime(), function (str) { enableAll(); });
207 | }
208 |
209 | function remove(node)
210 | {
211 | if(allDisabled) return;
212 | disableAll();
213 |
214 | nodes = node.childNodes;
215 | if(nodes.item(1).innerHTML == "Bump")
216 | {
217 | $("count").innerHTML = parseInt($("count").innerHTML) - 1 + "";
218 |
219 | tr = node.previousSibling;
220 | while(tr && tr.tagName && tr.tagName == "TR")
221 | {
222 | if(tr.childNodes.item(1).innerHTML == "Bump")
223 | {
224 | tr.childNodes.item(0).innerHTML = parseInt(tr.childNodes.item(0).innerHTML) - 1 + "";
225 | }
226 | else
227 | {
228 | break;
229 | }
230 |
231 | tr = tr.previousSibling;
232 | }
233 |
234 | loadURL("link.php?mode=remove&type=bump×tamp=" + nodes.item(3).innerHTML, function (str) { enableAll(); });
235 | }
236 | else if(nodes.item(1).innerHTML == "Reset")
237 | {
238 | hits = 0;
239 |
240 | tr = nodes.item(1).nextSibling;
241 | if(tr && (tr.childNodes.item(1).innerHTML == "Bump")) hits = parseInt(tr.childNodes.item(0).innerHTML) + 1;
242 |
243 | tr = node.previousSibling;
244 | while(tr && tr.tagName && tr.tagName == "TR")
245 | {
246 | if(tr.childNodes.item(1).innerHTML == "Bump")
247 | {
248 | tr.childNodes.item(0).innerHTML = hits + "";
249 | hits++;
250 | }
251 | else
252 | {
253 | break;
254 | }
255 |
256 | tr = tr.previousSibling;
257 | }
258 |
259 | if(hits == 0) hits = 1;
260 | $("count").innerHTML = hits - 1 + "";
261 |
262 | loadURL("link.php?mode=remove&type=reset×tamp=" + nodes.item(3).innerHTML, function (str) { enableAll(); });
263 | }
264 |
265 | $("counttablebody").removeChild(node);
266 | }
267 |
268 | function changeComputer()
269 | {
270 | alert("To use this counter on another computer, use this URL:\nhttp://countr.budgetwebdesign.org/" + (document.all ? $("id").innerText : $("id").textContent));
271 | }
272 |
273 | function load()
274 | {
275 | if(arguments.callee.done) return;
276 | arguments.callee.done = true;
277 |
278 | try
279 | {
280 | http = new ActiveXObject("Microsoft.XMLHTTP");
281 | }
282 | catch(e)
283 | {
284 | try
285 | {
286 | http = new XMLHttpRequest();
287 | }
288 | catch(e)
289 | {
290 | }
291 | }
292 |
293 | initDates();
294 | setInterval(initTableWrap, 10);
295 |
296 | if($("counttitle").innerHTML == "") editTitle();
297 | if($("counttablebody").childNodes.length <= 1) createCounter();
298 | }
299 |
300 | // for Internet Explorer (using conditional comments)
301 | /*@cc_on @*/
302 | /*@if (@_win32)
303 | document.write("