]>
Commit | Line | Data |
---|---|---|
760966c1 | 1 | var hotkeys_enabled = true; |
d96d11f4 | 2 | var debug_mode_enabled = false; |
a7565293 AD |
3 | var xmlhttp_rpc = Ajax.getTransport(); |
4 | ||
292a8a12 | 5 | function browser_has_opacity() { |
605f7d46 AD |
6 | return navigator.userAgent.match("Gecko") != null || |
7 | navigator.userAgent.match("Opera") != null; | |
292a8a12 AD |
8 | } |
9 | ||
7c620da8 AD |
10 | function is_opera() { |
11 | return navigator.userAgent.match("Opera"); | |
12 | } | |
13 | ||
55160955 | 14 | function exception_error(location, e, silent) { |
83f043bb AD |
15 | var msg; |
16 | ||
17 | if (e.fileName) { | |
18 | var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1); | |
19 | ||
20 | msg = "Exception: " + e.name + ", " + e.message + | |
21 | "\nFunction: " + location + "()" + | |
22 | "\nLocation: " + base_fname + ":" + e.lineNumber; | |
ee1f45f4 | 23 | |
83f043bb AD |
24 | } else { |
25 | msg = "Exception: " + e + "\nFunction: " + location + "()"; | |
26 | } | |
27 | ||
ee1f45f4 AD |
28 | debug("<b>EXCEPTION: " + msg + "</b>"); |
29 | ||
55160955 AD |
30 | if (!silent) { |
31 | alert(msg); | |
32 | } | |
7719618b AD |
33 | } |
34 | ||
760966c1 AD |
35 | function disableHotkeys() { |
36 | hotkeys_enabled = false; | |
37 | } | |
38 | ||
39 | function enableHotkeys() { | |
40 | hotkeys_enabled = true; | |
41 | } | |
42 | ||
c0e5a40e AD |
43 | function xmlhttp_ready(obj) { |
44 | return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState; | |
45 | } | |
46 | ||
9cfc649a AD |
47 | function notify_callback() { |
48 | var container = document.getElementById('notify'); | |
49 | if (xmlhttp.readyState == 4) { | |
50 | container.innerHTML=xmlhttp.responseText; | |
51 | } | |
52 | } | |
53 | ||
54 | function rpc_notify_callback() { | |
55 | var container = document.getElementById('notify'); | |
56 | if (xmlhttp_rpc.readyState == 4) { | |
57 | container.innerHTML=xmlhttp_rpc.responseText; | |
58 | } | |
59 | } | |
60 | ||
7726fa02 AD |
61 | function param_escape(arg) { |
62 | if (typeof encodeURIComponent != 'undefined') | |
63 | return encodeURIComponent(arg); | |
64 | else | |
65 | return escape(arg); | |
66 | } | |
67 | ||
68 | function param_unescape(arg) { | |
69 | if (typeof decodeURIComponent != 'undefined') | |
70 | return decodeURIComponent(arg); | |
71 | else | |
72 | return unescape(arg); | |
73 | } | |
74 | ||
508a81e1 AD |
75 | function delay(gap) { |
76 | var then,now; | |
77 | then=new Date().getTime(); | |
78 | now=then; | |
79 | while((now-then)<gap) { | |
80 | now=new Date().getTime(); | |
81 | } | |
82 | } | |
7726fa02 | 83 | |
ce3bf408 AD |
84 | var notify_hide_timerid = false; |
85 | var notify_last_doc = false; | |
86 | ||
d05514a4 | 87 | var notify_effect = false; |
59a543f0 | 88 | |
ce3bf408 AD |
89 | function hide_notify() { |
90 | if (notify_last_doc) { | |
91 | var n = notify_last_doc.getElementById("notify"); | |
d05514a4 AD |
92 | n.style.display = "none"; |
93 | ||
94 | /* if (browser_has_opacity()) { | |
ce3bf408 | 95 | if (notify_opacity >= 0) { |
0655a1d5 | 96 | notify_opacity = notify_opacity - 0.1; |
ce3bf408 | 97 | n.style.opacity = notify_opacity; |
292a8a12 | 98 | notify_hide_timerid = window.setTimeout("hide_notify()", 20); |
ce3bf408 AD |
99 | } else { |
100 | n.style.display = "none"; | |
292a8a12 | 101 | n.style.opacity = 1; |
ce3bf408 AD |
102 | } |
103 | } else { | |
104 | n.style.display = "none"; | |
d05514a4 | 105 | } */ |
8dcfffd0 | 106 | } |
d05514a4 | 107 | } |
c05608c2 | 108 | |
0530ddd8 | 109 | function notify_real(msg, doc, no_hide, is_err) { |
7726fa02 | 110 | |
ce3bf408 AD |
111 | var n = doc.getElementById("notify"); |
112 | var nb = doc.getElementById("notify_body"); | |
7726fa02 | 113 | |
c05608c2 | 114 | if (!n || !nb) return; |
f0601b87 | 115 | |
0655a1d5 AD |
116 | if (notify_hide_timerid) { |
117 | window.clearTimeout(notify_hide_timerid); | |
118 | } | |
119 | ||
120 | notify_last_doc = doc; | |
121 | notify_opacity = 1; | |
122 | ||
8dcfffd0 | 123 | if (msg == "") { |
0655a1d5 AD |
124 | if (n.style.display == "block") { |
125 | notify_hide_timerid = window.setTimeout("hide_notify()", 0); | |
126 | } | |
127 | return; | |
7726fa02 | 128 | } else { |
0ceded7a | 129 | n.style.display = "block"; |
8dcfffd0 | 130 | } |
7726fa02 | 131 | |
0530ddd8 | 132 | if (is_err) { |
f407c086 AD |
133 | n.className = "notifyError"; |
134 | // n.style.backgroundColor = "#ffcccc"; | |
135 | // n.style.color = "black"; | |
136 | // n.style.borderColor = "#ff0000"; | |
0530ddd8 | 137 | } else { |
f407c086 AD |
138 | n.className = "notify"; |
139 | // n.style.backgroundColor = "#fff7d5"; | |
140 | // n.style.borderColor = "#d7c47a"; | |
141 | // n.style.color = "black"; | |
0530ddd8 AD |
142 | } |
143 | ||
106689b0 AD |
144 | // msg = "<img src='images/live_com_loading.gif'> " + msg; |
145 | ||
0ceded7a AD |
146 | nb.innerHTML = msg; |
147 | ||
4d4200a8 | 148 | if (!no_hide) { |
292a8a12 | 149 | notify_hide_timerid = window.setTimeout("hide_notify()", 3000); |
4d4200a8 | 150 | } |
ce3bf408 AD |
151 | } |
152 | ||
0530ddd8 | 153 | function p_notify(msg, no_hide, is_err) { |
9cb99906 | 154 | notify_real(msg, document, no_hide, is_err); |
ce3bf408 AD |
155 | } |
156 | ||
0530ddd8 AD |
157 | function notify(msg, no_hide, is_err) { |
158 | notify_real(msg, document, no_hide, is_err); | |
7726fa02 AD |
159 | } |
160 | ||
508a81e1 | 161 | function printLockingError() { |
f0601b87 | 162 | notify("Please wait until operation finishes");} |
508a81e1 | 163 | |
13ad9102 | 164 | function hotkey_handler(e) { |
760966c1 | 165 | |
ee1f45f4 | 166 | try { |
2e02b896 | 167 | |
ee1f45f4 | 168 | var keycode; |
d96d11f4 AD |
169 | var shift_key = false; |
170 | ||
171 | try { | |
172 | shift_key = e.shiftKey; | |
173 | } catch (e) { | |
174 | ||
175 | } | |
ee1f45f4 AD |
176 | |
177 | if (!hotkeys_enabled) return; | |
178 | ||
179 | if (window.event) { | |
180 | keycode = window.event.keyCode; | |
181 | } else if (e) { | |
182 | keycode = e.which; | |
183 | } | |
d437c8cf | 184 | |
ee1f45f4 | 185 | if (keycode == 82) { // r |
0feab655 | 186 | return scheduleFeedUpdate(true); |
ee1f45f4 | 187 | } |
0a383013 | 188 | |
e3612080 | 189 | if (keycode == 83) { // s |
0feab655 | 190 | return displayDlg("search", getActiveFeedId()); |
0a383013 AD |
191 | } |
192 | ||
ee1f45f4 AD |
193 | if (keycode == 85) { // u |
194 | if (getActiveFeedId()) { | |
0feab655 | 195 | return viewfeed(getActiveFeedId(), "ForceUpdate"); |
ee1f45f4 AD |
196 | } |
197 | } | |
198 | ||
199 | if (keycode == 65) { // a | |
0feab655 | 200 | return toggleDispRead(); |
ee1f45f4 AD |
201 | } |
202 | ||
0feab655 | 203 | var feedlist = document.getElementById('feedList'); |
ee1f45f4 AD |
204 | |
205 | if (keycode == 74) { // j | |
206 | var feed = getActiveFeedId(); | |
207 | var new_feed = getRelativeFeedId(feedlist, feed, 'prev'); | |
767e2486 | 208 | if (new_feed) viewfeed(new_feed, ''); |
ee1f45f4 AD |
209 | } |
210 | ||
211 | if (keycode == 75) { // k | |
212 | var feed = getActiveFeedId(); | |
213 | var new_feed = getRelativeFeedId(feedlist, feed, 'next'); | |
767e2486 | 214 | if (new_feed) viewfeed(new_feed, ''); |
7b433d8c | 215 | } |
9cfc649a | 216 | |
ee1f45f4 | 217 | if (keycode == 78 || keycode == 40) { // n, down |
0feab655 AD |
218 | if (typeof moveToPost != 'undefined') { |
219 | return moveToPost('next'); | |
e59a2f12 | 220 | } |
ee1f45f4 AD |
221 | } |
222 | ||
223 | if (keycode == 80 || keycode == 38) { // p, up | |
0feab655 AD |
224 | if (typeof moveToPost != 'undefined') { |
225 | return moveToPost('prev'); | |
e59a2f12 | 226 | } |
ee1f45f4 AD |
227 | } |
228 | ||
d96d11f4 AD |
229 | if (keycode == 68 && shift_key) { // d |
230 | if (!debug_mode_enabled) { | |
231 | document.getElementById('debug_output').style.display = 'block'; | |
232 | debug('debug mode activated'); | |
233 | } else { | |
234 | document.getElementById('debug_output').style.display = 'none'; | |
235 | } | |
236 | ||
237 | debug_mode_enabled = !debug_mode_enabled; | |
238 | } | |
239 | ||
e46cdbb0 AD |
240 | if (keycode == 69 && shift_key) { |
241 | return editFeedDlg(getActiveFeedId()); | |
242 | } | |
243 | ||
1dc8dba0 AD |
244 | if (typeof localHotkeyHandler != 'undefined') { |
245 | try { | |
246 | return localHotkeyHandler(e); | |
247 | } catch (e) { | |
248 | exception_error("hotkey_handler, local:", e); | |
249 | } | |
250 | } | |
251 | ||
d96d11f4 | 252 | debug("KP=" + keycode); |
ee1f45f4 AD |
253 | } catch (e) { |
254 | exception_error("hotkey_handler", e); | |
255 | } | |
13ad9102 AD |
256 | } |
257 | ||
e828e31e | 258 | function cleanSelectedList(element) { |
f0601b87 AD |
259 | var content = document.getElementById(element); |
260 | ||
703b632e AD |
261 | if (!document.getElementById("feedCatHolder")) { |
262 | for (i = 0; i < content.childNodes.length; i++) { | |
263 | var child = content.childNodes[i]; | |
d0bb308e AD |
264 | try { |
265 | child.className = child.className.replace("Selected", ""); | |
266 | } catch (e) { | |
267 | // | |
268 | } | |
703b632e AD |
269 | } |
270 | } else { | |
271 | for (i = 0; i < content.childNodes.length; i++) { | |
272 | var child = content.childNodes[i]; | |
703b632e | 273 | if (child.id == "feedCatHolder") { |
9cb99906 | 274 | debug(child.id); |
c3f348c2 | 275 | var fcat = child.lastChild; |
703b632e | 276 | for (j = 0; j < fcat.childNodes.length; j++) { |
befc807f | 277 | var feed = fcat.childNodes[j]; |
703b632e AD |
278 | feed.className = feed.className.replace("Selected", ""); |
279 | } | |
280 | } | |
befc807f | 281 | } |
703b632e | 282 | } |
e828e31e AD |
283 | } |
284 | ||
285 | ||
286 | function cleanSelected(element) { | |
287 | var content = document.getElementById(element); | |
f0601b87 AD |
288 | |
289 | for (i = 0; i < content.rows.length; i++) { | |
290 | content.rows[i].className = content.rows[i].className.replace("Selected", ""); | |
291 | } | |
f0601b87 AD |
292 | } |
293 | ||
294 | function getVisibleUnreadHeadlines() { | |
295 | var content = document.getElementById("headlinesList"); | |
296 | ||
297 | var rows = new Array(); | |
298 | ||
299 | for (i = 0; i < content.rows.length; i++) { | |
300 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
301 | if (row_id.length > 0 && content.rows[i].className.match("Unread")) { | |
302 | rows.push(row_id); | |
303 | } | |
304 | } | |
305 | return rows; | |
306 | } | |
307 | ||
308 | function getVisibleHeadlineIds() { | |
309 | ||
310 | var content = document.getElementById("headlinesList"); | |
311 | ||
312 | var rows = new Array(); | |
313 | ||
314 | for (i = 0; i < content.rows.length; i++) { | |
315 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
316 | if (row_id.length > 0) { | |
317 | rows.push(row_id); | |
318 | } | |
319 | } | |
320 | return rows; | |
321 | } | |
322 | ||
323 | function getFirstVisibleHeadlineId() { | |
324 | var rows = getVisibleHeadlineIds(); | |
325 | return rows[0]; | |
326 | } | |
327 | ||
328 | function getLastVisibleHeadlineId() { | |
329 | var rows = getVisibleHeadlineIds(); | |
330 | return rows[rows.length-1]; | |
331 | } | |
332 | ||
333 | function markHeadline(id) { | |
334 | var row = document.getElementById("RROW-" + id); | |
335 | if (row) { | |
35f3c923 AD |
336 | var is_active = false; |
337 | ||
338 | if (row.className.match("Active")) { | |
339 | is_active = true; | |
340 | } | |
341 | row.className = row.className.replace("Selected", ""); | |
342 | row.className = row.className.replace("Active", ""); | |
343 | row.className = row.className.replace("Insensitive", ""); | |
344 | ||
345 | if (is_active) { | |
346 | row.className = row.className = "Active"; | |
347 | } | |
348 | ||
72020095 AD |
349 | var check = document.getElementById("RCHK-" + id); |
350 | ||
351 | if (check) { | |
352 | check.checked = true; | |
353 | } | |
354 | ||
35f3c923 AD |
355 | row.className = row.className + "Selected"; |
356 | ||
f0601b87 AD |
357 | } |
358 | } | |
359 | ||
360 | function getFeedIds() { | |
361 | var content = document.getElementById("feedsList"); | |
362 | ||
363 | var rows = new Array(); | |
364 | ||
365 | for (i = 0; i < content.rows.length; i++) { | |
366 | var id = content.rows[i].id.replace("FEEDR-", ""); | |
367 | if (id.length > 0) { | |
368 | rows.push(id); | |
369 | } | |
370 | } | |
371 | ||
372 | return rows; | |
373 | } | |
13ad9102 | 374 | |
76b4eae1 AD |
375 | function setCookie(name, value, lifetime, path, domain, secure) { |
376 | ||
377 | var d = false; | |
378 | ||
379 | if (lifetime) { | |
380 | d = new Date(); | |
381 | d.setTime(lifetime * 1000); | |
382 | } | |
383 | ||
384 | int_setCookie(name, value, d, path, domain, secure); | |
385 | ||
386 | } | |
387 | ||
388 | function int_setCookie(name, value, expires, path, domain, secure) { | |
ac43eba1 AD |
389 | document.cookie= name + "=" + escape(value) + |
390 | ((expires) ? "; expires=" + expires.toGMTString() : "") + | |
391 | ((path) ? "; path=" + path : "") + | |
392 | ((domain) ? "; domain=" + domain : "") + | |
393 | ((secure) ? "; secure" : ""); | |
394 | } | |
395 | ||
76b4eae1 AD |
396 | function delCookie(name, path, domain) { |
397 | if (getCookie(name)) { | |
398 | document.cookie = name + "=" + | |
399 | ((path) ? ";path=" + path : "") + | |
400 | ((domain) ? ";domain=" + domain : "" ) + | |
401 | ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; | |
402 | } | |
403 | } | |
404 | ||
405 | ||
ac43eba1 AD |
406 | function getCookie(name) { |
407 | ||
408 | var dc = document.cookie; | |
409 | var prefix = name + "="; | |
410 | var begin = dc.indexOf("; " + prefix); | |
411 | if (begin == -1) { | |
412 | begin = dc.indexOf(prefix); | |
413 | if (begin != 0) return null; | |
414 | } | |
415 | else { | |
416 | begin += 2; | |
417 | } | |
418 | var end = document.cookie.indexOf(";", begin); | |
419 | if (end == -1) { | |
420 | end = dc.length; | |
421 | } | |
422 | return unescape(dc.substring(begin + prefix.length, end)); | |
423 | } | |
424 | ||
1a66d16e AD |
425 | function disableContainerChildren(id, disable, doc) { |
426 | ||
427 | if (!doc) doc = document; | |
428 | ||
429 | var container = doc.getElementById(id); | |
ac43eba1 | 430 | |
4220b0bd AD |
431 | if (!container) { |
432 | //alert("disableContainerChildren: element " + id + " not found"); | |
433 | return; | |
434 | } | |
435 | ||
ac43eba1 AD |
436 | for (var i = 0; i < container.childNodes.length; i++) { |
437 | var child = container.childNodes[i]; | |
438 | ||
d5224f0d AD |
439 | try { |
440 | child.disabled = disable; | |
441 | } catch (E) { | |
442 | ||
443 | } | |
ac43eba1 AD |
444 | |
445 | if (disable) { | |
446 | if (child.className && child.className.match("button")) { | |
447 | child.className = "disabledButton"; | |
448 | } | |
449 | } else { | |
450 | if (child.className && child.className.match("disabledButton")) { | |
451 | child.className = "button"; | |
452 | } | |
d5224f0d | 453 | } |
ac43eba1 AD |
454 | } |
455 | ||
456 | } | |
7726fa02 | 457 | |
e828e31e AD |
458 | function gotoPreferences() { |
459 | document.location.href = "prefs.php"; | |
460 | } | |
461 | ||
462 | function gotoMain() { | |
463 | document.location.href = "tt-rss.php"; | |
464 | } | |
465 | ||
8158c57a AD |
466 | function gotoExportOpml() { |
467 | document.location.href = "opml.php?op=Export"; | |
468 | } | |
86741347 AD |
469 | |
470 | function getActiveFeedId() { | |
33d13e72 AD |
471 | // return getCookie("ttrss_vf_actfeed"); |
472 | try { | |
0feab655 AD |
473 | debug("gAFID: " + active_feed_id); |
474 | return active_feed_id; | |
33d13e72 AD |
475 | } catch (e) { |
476 | exception_error("getActiveFeedId", e); | |
477 | } | |
86741347 AD |
478 | } |
479 | ||
0a6c4846 | 480 | function activeFeedIsCat() { |
0feab655 | 481 | return active_feed_is_cat; |
0a6c4846 AD |
482 | } |
483 | ||
86741347 | 484 | function setActiveFeedId(id) { |
33d13e72 AD |
485 | // return setCookie("ttrss_vf_actfeed", id); |
486 | try { | |
5c365f60 | 487 | debug("sAFID(" + id + ")"); |
0feab655 | 488 | active_feed_id = id; |
33d13e72 AD |
489 | } catch (e) { |
490 | exception_error("setActiveFeedId", e); | |
491 | } | |
86741347 | 492 | } |
090e250b | 493 | |
ac378ad4 | 494 | function parse_counters(reply, scheduled_call) { |
1a6a9555 | 495 | try { |
ac378ad4 | 496 | |
9e397d0f AD |
497 | var feeds_found = 0; |
498 | ||
f54f515f AD |
499 | if (reply.firstChild && reply.firstChild.firstChild) { |
500 | debug("<b>wrong element passed to parse_counters, adjusting.</b>"); | |
501 | reply = reply.firstChild; | |
502 | } | |
503 | ||
1a6a9555 | 504 | for (var l = 0; l < reply.childNodes.length; l++) { |
9cbca41f AD |
505 | if (!reply.childNodes[l] || |
506 | typeof(reply.childNodes[l].getAttribute) == "undefined") { | |
6043fb7e AD |
507 | // where did this come from? |
508 | continue; | |
509 | } | |
510 | ||
1a6a9555 AD |
511 | var id = reply.childNodes[l].getAttribute("id"); |
512 | var t = reply.childNodes[l].getAttribute("type"); | |
513 | var ctr = reply.childNodes[l].getAttribute("counter"); | |
023fe037 AD |
514 | var error = reply.childNodes[l].getAttribute("error"); |
515 | var has_img = reply.childNodes[l].getAttribute("hi"); | |
fb1fb4ab | 516 | var updated = reply.childNodes[l].getAttribute("updated"); |
1a6a9555 AD |
517 | |
518 | if (id == "global-unread") { | |
0feab655 AD |
519 | global_unread = ctr; |
520 | updateTitle(); | |
1a6a9555 AD |
521 | continue; |
522 | } | |
7bf7e4d3 AD |
523 | |
524 | if (id == "subscribed-feeds") { | |
525 | feeds_found = ctr; | |
526 | continue; | |
527 | } | |
1a6a9555 AD |
528 | |
529 | if (t == "category") { | |
0feab655 | 530 | var catctr = document.getElementById("FCATCTR-" + id); |
1a6a9555 | 531 | if (catctr) { |
67dabe1a AD |
532 | catctr.innerHTML = "(" + ctr + ")"; |
533 | if (ctr > 0) { | |
534 | catctr.className = "catCtrHasUnread"; | |
535 | } else { | |
536 | catctr.className = "catCtrNoUnread"; | |
537 | } | |
1a6a9555 AD |
538 | } |
539 | continue; | |
540 | } | |
541 | ||
0feab655 AD |
542 | var feedctr = document.getElementById("FEEDCTR-" + id); |
543 | var feedu = document.getElementById("FEEDU-" + id); | |
544 | var feedr = document.getElementById("FEEDR-" + id); | |
545 | var feed_img = document.getElementById("FIMG-" + id); | |
546 | var feedlink = document.getElementById("FEEDL-" + id); | |
547 | var feedupd = document.getElementById("FLUPD-" + id); | |
fb1fb4ab AD |
548 | |
549 | if (updated && feedlink) { | |
550 | if (error) { | |
551 | feedlink.title = "Error: " + error + " (" + updated + ")"; | |
552 | } else { | |
553 | feedlink.title = "Updated: " + updated; | |
554 | } | |
555 | } | |
023fe037 | 556 | |
78d5212c AD |
557 | if (updated && feedupd) { |
558 | if (error) { | |
559 | feedupd.innerHTML = updated + " (Error)"; | |
560 | } else { | |
561 | feedupd.innerHTML = updated; | |
562 | } | |
563 | } | |
564 | ||
1a6a9555 | 565 | if (feedctr && feedu && feedr) { |
e8ef3b97 AD |
566 | |
567 | if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) { | |
5b064721 | 568 | viewCurrentFeed(); |
e8ef3b97 | 569 | } |
1a6a9555 AD |
570 | |
571 | feedu.innerHTML = ctr; | |
023fe037 | 572 | |
426d3c57 AD |
573 | if (error) { |
574 | feedr.className = feedr.className.replace("feed", "error"); | |
575 | } else if (id > 0) { | |
576 | feedr.className = feedr.className.replace("error", "feed"); | |
023fe037 | 577 | } |
1a6a9555 AD |
578 | |
579 | if (ctr > 0) { | |
580 | feedctr.className = "odd"; | |
581 | if (!feedr.className.match("Unread")) { | |
582 | var is_selected = feedr.className.match("Selected"); | |
583 | ||
584 | feedr.className = feedr.className.replace("Selected", ""); | |
585 | feedr.className = feedr.className.replace("Unread", ""); | |
586 | ||
587 | feedr.className = feedr.className + "Unread"; | |
588 | ||
589 | if (is_selected) { | |
590 | feedr.className = feedr.className + "Selected"; | |
591 | } | |
592 | ||
593 | } | |
594 | } else { | |
595 | feedctr.className = "invisible"; | |
596 | feedr.className = feedr.className.replace("Unread", ""); | |
597 | } | |
598 | } | |
599 | } | |
9e397d0f | 600 | |
0feab655 | 601 | hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); |
7553dd8b | 602 | |
0feab655 | 603 | var feeds_stored = number_of_feeds; |
9e397d0f AD |
604 | |
605 | debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored); | |
606 | ||
607 | if (feeds_stored != feeds_found) { | |
0feab655 | 608 | number_of_feeds = feeds_found; |
7bf7e4d3 AD |
609 | |
610 | if (feeds_stored != 0) { | |
9e397d0f | 611 | debug("Subscribed feed number changed, refreshing feedlist"); |
0e9dd1ba | 612 | setTimeout('updateFeedList(false, false)', 50); |
9e397d0f AD |
613 | } |
614 | } | |
615 | ||
1a6a9555 | 616 | } catch (e) { |
83f043bb | 617 | exception_error("parse_counters", e); |
1a6a9555 AD |
618 | } |
619 | } | |
620 | ||
3ac2f3c7 | 621 | function parse_counters_reply(xmlhttp, scheduled_call) { |
5854573a AD |
622 | |
623 | if (!xmlhttp.responseXML) { | |
624 | notify("refetch_callback: backend did not return valid XML", true, true); | |
625 | return; | |
626 | } | |
627 | ||
628 | var reply = xmlhttp.responseXML.firstChild; | |
629 | ||
630 | if (!reply) { | |
631 | notify("refetch_callback: backend did not return expected XML object", true, true); | |
632 | updateTitle(""); | |
633 | return; | |
634 | } | |
635 | ||
636 | var error_code = false; | |
637 | var error_msg = false; | |
638 | ||
639 | if (reply.firstChild) { | |
640 | error_code = reply.firstChild.getAttribute("error-code"); | |
641 | error_msg = reply.firstChild.getAttribute("error-msg"); | |
642 | } | |
643 | ||
644 | if (!error_code) { | |
645 | error_code = reply.getAttribute("error-code"); | |
646 | error_msg = reply.getAttribute("error-msg"); | |
647 | } | |
648 | ||
649 | if (error_code && error_code != 0) { | |
650 | debug("refetch_callback: got error code " + error_code); | |
651 | return fatalError(error_code, error_msg); | |
652 | } | |
653 | ||
654 | var counters = reply.firstChild; | |
655 | ||
3ac2f3c7 | 656 | parse_counters(counters, scheduled_call); |
5854573a AD |
657 | |
658 | var runtime_info = counters.nextSibling; | |
659 | ||
660 | parse_runtime_info(runtime_info); | |
661 | ||
662 | if (getInitParam("feeds_sort_by_unread") == 1) { | |
663 | resort_feedlist(); | |
664 | } | |
665 | ||
666 | hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); | |
667 | ||
668 | } | |
669 | ||
4f3a84f4 | 670 | function all_counters_callback() { |
090e250b | 671 | if (xmlhttp_rpc.readyState == 4) { |
7719618b | 672 | try { |
5854573a | 673 | /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) { |
b00ed196 | 674 | debug("[all_counters_callback] backend did not return valid XML"); |
7719618b AD |
675 | return; |
676 | } | |
894ebcf5 | 677 | |
6b4163cb | 678 | debug("in all_counters_callback : " + xmlhttp_rpc.responseXML); |
1cb7492d | 679 | |
7719618b | 680 | var reply = xmlhttp_rpc.responseXML.firstChild; |
280ee9a3 | 681 | |
f54f515f AD |
682 | var counters = reply.firstChild; |
683 | ||
684 | parse_counters(counters); | |
1cb7492d AD |
685 | |
686 | var runtime = counters.nextSibling; | |
687 | ||
688 | if (runtime) { | |
0feab655 | 689 | parse_runtime_info(runtime); |
1cb7492d | 690 | } |
c9268ed5 | 691 | |
cea51014 | 692 | if (getInitParam("feeds_sort_by_unread") == 1) { |
c9268ed5 AD |
693 | resort_feedlist(); |
694 | } | |
293fa942 | 695 | |
5854573a AD |
696 | hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */ |
697 | ||
698 | debug("in all_counters_callback"); | |
699 | ||
700 | parse_counters_reply(xmlhttp_rpc); | |
293fa942 | 701 | |
7719618b AD |
702 | } catch (e) { |
703 | exception_error("all_counters_callback", e); | |
090e250b AD |
704 | } |
705 | } | |
706 | } | |
707 | ||
c9268ed5 AD |
708 | function get_feed_entry_unread(doc, elem) { |
709 | ||
710 | var id = elem.id.replace("FEEDR-", ""); | |
711 | ||
712 | if (id <= 0) { | |
713 | return -1; | |
714 | } | |
715 | ||
716 | try { | |
717 | return parseInt(doc.getElementById("FEEDU-" + id).innerHTML); | |
718 | } catch (e) { | |
719 | return -1; | |
720 | } | |
721 | } | |
722 | ||
723 | function resort_category(doc, node) { | |
724 | debug("resort_category: " + node); | |
725 | ||
726 | if (node.hasChildNodes() && node.firstChild.nextSibling != false) { | |
727 | for (i = 0; i < node.childNodes.length; i++) { | |
728 | if (node.childNodes[i].nodeName != "LI") { continue; } | |
729 | ||
730 | if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) { | |
731 | continue; | |
732 | } | |
733 | ||
734 | for (j = i+1; j < node.childNodes.length; j++) { | |
735 | if (node.childNodes[j].nodeName != "LI") { continue; } | |
736 | ||
737 | var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]); | |
738 | var cur_val = get_feed_entry_unread(doc, node.childNodes[j]); | |
739 | ||
740 | if (cur_val > tmp_val) { | |
741 | tempnode_i = node.childNodes[i].cloneNode(true); | |
742 | tempnode_j = node.childNodes[j].cloneNode(true); | |
743 | node.replaceChild(tempnode_i, node.childNodes[j]); | |
744 | node.replaceChild(tempnode_j, node.childNodes[i]); | |
745 | } | |
746 | } | |
747 | ||
748 | } | |
749 | } | |
750 | ||
751 | } | |
752 | ||
753 | function resort_feedlist() { | |
754 | debug("resort_feedlist"); | |
755 | ||
0feab655 | 756 | var fd = document; |
c9268ed5 AD |
757 | |
758 | if (fd.getElementById("feedCatHolder")) { | |
759 | ||
760 | var feeds = fd.getElementById("feedList"); | |
761 | var child = feeds.firstChild; | |
762 | ||
763 | while (child) { | |
764 | ||
765 | if (child.id == "feedCatHolder") { | |
766 | resort_category(fd, child.firstChild); | |
767 | } | |
768 | ||
769 | child = child.nextSibling; | |
770 | } | |
771 | ||
772 | } else { | |
773 | resort_category(fd, fd.getElementById("feedList")); | |
774 | } | |
775 | } | |
776 | ||
4f3a84f4 | 777 | function update_all_counters(feed) { |
090e250b | 778 | if (xmlhttp_ready(xmlhttp_rpc)) { |
8143ae1f | 779 | var query = "backend.php?op=rpc&subop=getAllCounters"; |
e47cfe37 AD |
780 | |
781 | if (feed > 0) { | |
782 | query = query + "&aid=" + feed; | |
783 | } | |
784 | ||
cf4d339c AD |
785 | if (tagsAreDisplayed()) { |
786 | query = query + "&omode=lt"; | |
3fd7138f AD |
787 | } else { |
788 | query = query + "&omode=flc"; | |
cf4d339c AD |
789 | } |
790 | ||
791 | debug("update_all_counters QUERY: " + query); | |
792 | ||
090e250b | 793 | xmlhttp_rpc.open("GET", query, true); |
4f3a84f4 | 794 | xmlhttp_rpc.onreadystatechange=all_counters_callback; |
090e250b AD |
795 | xmlhttp_rpc.send(null); |
796 | } | |
797 | } | |
7dc66a61 AD |
798 | |
799 | function popupHelp(tid) { | |
800 | var w = window.open("backend.php?op=help&tid=" + tid, | |
801 | "Popup Help", | |
802 | "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no"); | |
803 | } | |
b6644d29 AD |
804 | |
805 | /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj | |
806 | * * @author Sundar Dorai-Raj | |
807 | * * Email: sdoraira@vt.edu | |
808 | * * This program is free software; you can redistribute it and/or | |
809 | * * modify it under the terms of the GNU General Public License | |
810 | * * as published by the Free Software Foundation; either version 2 | |
811 | * * of the License, or (at your option) any later version, | |
812 | * * provided that any use properly credits the author. | |
813 | * * This program is distributed in the hope that it will be useful, | |
814 | * * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
815 | * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
816 | * * GNU General Public License for more details at http://www.gnu.org * * */ | |
817 | ||
818 | var numbers=".0123456789"; | |
819 | function isNumeric(x) { | |
820 | // is x a String or a character? | |
821 | if(x.length>1) { | |
822 | // remove negative sign | |
823 | x=Math.abs(x)+""; | |
824 | for(j=0;j<x.length;j++) { | |
825 | // call isNumeric recursively for each character | |
826 | number=isNumeric(x.substring(j,j+1)); | |
827 | if(!number) return number; | |
828 | } | |
829 | return number; | |
830 | } | |
831 | else { | |
832 | // if x is number return true | |
833 | if(numbers.indexOf(x)>=0) return true; | |
834 | return false; | |
835 | } | |
836 | } | |
837 | ||
3745788e AD |
838 | |
839 | function hideOrShowFeeds(doc, hide) { | |
840 | ||
7553dd8b AD |
841 | debug("hideOrShowFeeds: " + doc + ", " + hide); |
842 | ||
0feab655 | 843 | var fd = document; |
293fa942 AD |
844 | |
845 | var list = fd.getElementById("feedList"); | |
846 | ||
847 | if (fd.getElementById("feedCatHolder")) { | |
848 | ||
849 | var feeds = fd.getElementById("feedList"); | |
850 | var child = feeds.firstChild; | |
851 | ||
852 | while (child) { | |
853 | ||
854 | if (child.id == "feedCatHolder") { | |
855 | hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling); | |
856 | } | |
857 | ||
858 | child = child.nextSibling; | |
859 | } | |
860 | ||
861 | } else { | |
862 | hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide); | |
863 | } | |
864 | } | |
865 | ||
866 | function hideOrShowFeedsCategory(doc, node, hide, cat_node) { | |
867 | ||
868 | // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")"); | |
3ed751d4 | 869 | |
293fa942 | 870 | var cat_unread = 0; |
3745788e | 871 | |
4724a093 AD |
872 | if (!node) { |
873 | debug("hideOrShowFeeds: passed node is null, aborting"); | |
874 | return; | |
875 | } | |
876 | ||
293fa942 AD |
877 | if (node.hasChildNodes() && node.firstChild.nextSibling != false) { |
878 | for (i = 0; i < node.childNodes.length; i++) { | |
879 | if (node.childNodes[i].nodeName != "LI") { continue; } | |
bbf4d0b2 | 880 | |
b31c2311 | 881 | if (node.childNodes[i].style != undefined) { |
293fa942 | 882 | |
b31c2311 AD |
883 | var has_unread = (node.childNodes[i].className != "feed"); |
884 | ||
885 | // debug(node.childNodes[i].id + " --> " + has_unread); | |
886 | ||
887 | if (hide && !has_unread) { | |
888 | node.childNodes[i].style.display = "none"; | |
889 | } | |
890 | ||
891 | if (!hide) { | |
892 | node.childNodes[i].style.display = "list-item"; | |
893 | } | |
894 | ||
895 | if (has_unread) { | |
7553dd8b | 896 | node.childNodes[i].style.display = "list-item"; |
b31c2311 AD |
897 | cat_unread++; |
898 | } | |
293fa942 | 899 | } |
3745788e | 900 | } |
b31c2311 | 901 | } |
3745788e | 902 | |
293fa942 | 903 | if (cat_unread == 0) { |
b31c2311 AD |
904 | if (cat_node.style == undefined) { |
905 | debug("ERROR: supplied cat_node " + cat_node + | |
906 | " has no styles. WTF?"); | |
907 | return; | |
908 | } | |
293fa942 AD |
909 | if (hide) { |
910 | cat_node.style.display = "none"; | |
911 | } else { | |
912 | cat_node.style.display = "list-item"; | |
913 | } | |
7553dd8b | 914 | } else { |
0ac2faea AD |
915 | try { |
916 | cat_node.style.display = "list-item"; | |
917 | } catch (e) { | |
918 | debug(e); | |
919 | } | |
293fa942 | 920 | } |
3745788e | 921 | |
293fa942 | 922 | // debug("unread for category: " + cat_unread); |
3745788e AD |
923 | } |
924 | ||
35f3c923 AD |
925 | function selectTableRow(r, do_select) { |
926 | r.className = r.className.replace("Selected", ""); | |
927 | ||
928 | if (do_select) { | |
929 | r.className = r.className + "Selected"; | |
930 | } | |
931 | } | |
932 | ||
6c12c809 AD |
933 | function selectTableRowById(elem_id, check_id, do_select) { |
934 | ||
935 | try { | |
936 | ||
937 | var row = document.getElementById(elem_id); | |
938 | ||
939 | if (row) { | |
940 | selectTableRow(row, do_select); | |
941 | } | |
942 | ||
943 | var check = document.getElementById(check_id); | |
944 | ||
945 | if (check) { | |
946 | check.checked = do_select; | |
947 | } | |
948 | } catch (e) { | |
949 | exception_error("selectTableRowById", e); | |
950 | } | |
951 | } | |
952 | ||
1572afe5 | 953 | function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select, |
649e0af9 | 954 | classcheck, reset_others) { |
3745788e | 955 | |
35f3c923 AD |
956 | var content = document.getElementById(content_id); |
957 | ||
958 | if (!content) { | |
959 | alert("[selectTableRows] Element " + content_id + " not found."); | |
960 | return; | |
961 | } | |
962 | ||
963 | for (i = 0; i < content.rows.length; i++) { | |
1572afe5 AD |
964 | if (!classcheck || content.rows[i].className.match(classcheck)) { |
965 | ||
966 | if (content.rows[i].id.match(prefix)) { | |
967 | selectTableRow(content.rows[i], do_select); | |
649e0af9 AD |
968 | |
969 | var row_id = content.rows[i].id.replace(prefix, ""); | |
970 | var check = document.getElementById(check_prefix + row_id); | |
3055bc41 | 971 | |
649e0af9 AD |
972 | if (check) { |
973 | check.checked = do_select; | |
974 | } | |
975 | } else if (reset_others) { | |
976 | selectTableRow(content.rows[i], false); | |
7d8d10c6 AD |
977 | |
978 | var row_id = content.rows[i].id.replace(prefix, ""); | |
979 | var check = document.getElementById(check_prefix + row_id); | |
980 | ||
981 | if (check) { | |
982 | check.checked = false; | |
983 | } | |
984 | ||
1572afe5 | 985 | } |
649e0af9 AD |
986 | } else if (reset_others) { |
987 | selectTableRow(content.rows[i], false); | |
7d8d10c6 AD |
988 | |
989 | var row_id = content.rows[i].id.replace(prefix, ""); | |
990 | var check = document.getElementById(check_prefix + row_id); | |
991 | ||
992 | if (check) { | |
993 | check.checked = false; | |
994 | } | |
995 | ||
3055bc41 | 996 | } |
35f3c923 | 997 | } |
295f9b42 | 998 | } |
91ff844a AD |
999 | |
1000 | function getSelectedTableRowIds(content_id, prefix) { | |
1001 | ||
1002 | var content = document.getElementById(content_id); | |
1003 | ||
1004 | if (!content) { | |
1005 | alert("[getSelectedTableRowIds] Element " + content_id + " not found."); | |
1006 | return; | |
1007 | } | |
1008 | ||
1009 | var sel_rows = new Array(); | |
1010 | ||
1011 | for (i = 0; i < content.rows.length; i++) { | |
1572afe5 AD |
1012 | if (content.rows[i].id.match(prefix) && |
1013 | content.rows[i].className.match("Selected")) { | |
1014 | ||
91ff844a AD |
1015 | var row_id = content.rows[i].id.replace(prefix + "-", ""); |
1016 | sel_rows.push(row_id); | |
1017 | } | |
1018 | } | |
1019 | ||
1020 | return sel_rows; | |
1021 | ||
1022 | } | |
1023 | ||
386cbf27 AD |
1024 | function toggleSelectRowById(sender, id) { |
1025 | var row = document.getElementById(id); | |
1026 | ||
1027 | if (sender.checked) { | |
1028 | if (!row.className.match("Selected")) { | |
1029 | row.className = row.className + "Selected"; | |
1030 | } | |
1031 | } else { | |
1032 | if (row.className.match("Selected")) { | |
1033 | row.className = row.className.replace("Selected", ""); | |
1034 | } | |
1035 | } | |
1036 | } | |
1037 | ||
b92e6209 AD |
1038 | function toggleSelectListRow(sender) { |
1039 | var parent_row = sender.parentNode; | |
1040 | ||
1041 | if (sender.checked) { | |
1042 | if (!parent_row.className.match("Selected")) { | |
1043 | parent_row.className = parent_row.className + "Selected"; | |
1044 | } | |
1045 | } else { | |
1046 | if (parent_row.className.match("Selected")) { | |
1047 | parent_row.className = parent_row.className.replace("Selected", ""); | |
1048 | } | |
1049 | } | |
1050 | } | |
1051 | ||
386cbf27 | 1052 | |
1572afe5 AD |
1053 | function toggleSelectRow(sender) { |
1054 | var parent_row = sender.parentNode.parentNode; | |
1055 | ||
1056 | if (sender.checked) { | |
1057 | if (!parent_row.className.match("Selected")) { | |
1058 | parent_row.className = parent_row.className + "Selected"; | |
1059 | } | |
1060 | } else { | |
1061 | if (parent_row.className.match("Selected")) { | |
1062 | parent_row.className = parent_row.className.replace("Selected", ""); | |
1063 | } | |
1064 | } | |
1065 | } | |
1066 | ||
3866b046 AD |
1067 | function openExternalUrl(url) { |
1068 | var w = window.open(url); | |
1069 | } | |
1572afe5 | 1070 | |
1da76274 | 1071 | function getRelativeFeedId(list, id, direction, unread_only) { |
7b433d8c AD |
1072 | if (!id) { |
1073 | if (direction == "next") { | |
1074 | for (i = 0; i < list.childNodes.length; i++) { | |
1075 | var child = list.childNodes[i]; | |
1da76274 | 1076 | if (child.id && child.id == "feedCatHolder") { |
c3f348c2 | 1077 | if (child.lastChild) { |
d05514a4 | 1078 | var cr = getRelativeFeedId(child.firstChild, id, direction, unread_only); |
7b433d8c AD |
1079 | if (cr) return cr; |
1080 | } | |
1da76274 | 1081 | } else if (child.id && child.id.match("FEEDR-")) { |
7b433d8c AD |
1082 | return child.id.replace('FEEDR-', ''); |
1083 | } | |
1084 | } | |
1085 | } | |
1086 | ||
1087 | // FIXME select last feed doesn't work when only unread feeds are visible | |
1088 | ||
1089 | if (direction == "prev") { | |
1090 | for (i = list.childNodes.length-1; i >= 0; i--) { | |
1091 | var child = list.childNodes[i]; | |
1092 | if (child.id == "feedCatHolder") { | |
1093 | if (child.firstChild) { | |
1094 | var cr = getRelativeFeedId(child.firstChild, id, direction); | |
1095 | if (cr) return cr; | |
1096 | } | |
1097 | } else if (child.id.match("FEEDR-")) { | |
1098 | ||
e8bd0da9 | 1099 | if (getInitParam("hide_read_feeds") == 1) { |
7b433d8c AD |
1100 | if (child.className != "feed") { |
1101 | alert(child.className); | |
1102 | return child.id.replace('FEEDR-', ''); | |
1103 | } | |
1104 | } else { | |
1105 | return child.id.replace('FEEDR-', ''); | |
1106 | } | |
1107 | } | |
1108 | } | |
1109 | } | |
1110 | } else { | |
1111 | ||
d05514a4 | 1112 | var feed = list.ownerDocument.getElementById("FEEDR-" + id); |
7b433d8c | 1113 | |
e8bd0da9 | 1114 | if (getInitParam("hide_read_feeds") == 1) { |
1da76274 AD |
1115 | unread_only = true; |
1116 | } | |
1117 | ||
7b433d8c AD |
1118 | if (direction == "next") { |
1119 | ||
1da76274 | 1120 | var e = feed; |
7b433d8c | 1121 | |
1da76274 | 1122 | while (e) { |
7b433d8c | 1123 | |
1da76274 AD |
1124 | if (e.nextSibling) { |
1125 | ||
1126 | e = e.nextSibling; | |
1127 | ||
1128 | } else if (e.parentNode.parentNode.nextSibling) { | |
7b433d8c | 1129 | |
1da76274 | 1130 | var this_cat = e.parentNode.parentNode; |
7b433d8c | 1131 | |
1da76274 | 1132 | e = false; |
7b433d8c | 1133 | |
1da76274 AD |
1134 | if (this_cat && this_cat.nextSibling) { |
1135 | while (!e && this_cat.nextSibling) { | |
1136 | this_cat = this_cat.nextSibling; | |
1137 | if (this_cat.id == "feedCatHolder") { | |
1138 | e = this_cat.firstChild.firstChild; | |
7b433d8c AD |
1139 | } |
1140 | } | |
7b433d8c | 1141 | } |
1da76274 AD |
1142 | |
1143 | } else { | |
1144 | e = false; | |
1145 | } | |
1146 | ||
1147 | if (e) { | |
d05514a4 | 1148 | if (!unread_only || (unread_only && e.className != "feed" && |
cabffe9d | 1149 | e.className.match("feed"))) { |
1da76274 AD |
1150 | return e.id.replace("FEEDR-", ""); |
1151 | } | |
1152 | } | |
7b433d8c | 1153 | } |
1da76274 | 1154 | |
7b433d8c AD |
1155 | } else if (direction == "prev") { |
1156 | ||
1da76274 | 1157 | var e = feed; |
7b433d8c | 1158 | |
1da76274 | 1159 | while (e) { |
7b433d8c | 1160 | |
1da76274 AD |
1161 | if (e.previousSibling) { |
1162 | ||
1163 | e = e.previousSibling; | |
1164 | ||
1165 | } else if (e.parentNode.parentNode.previousSibling) { | |
7b433d8c | 1166 | |
1da76274 | 1167 | var this_cat = e.parentNode.parentNode; |
7b433d8c | 1168 | |
1da76274 AD |
1169 | e = false; |
1170 | ||
1171 | if (this_cat && this_cat.previousSibling) { | |
1172 | while (!e && this_cat.previousSibling) { | |
1173 | this_cat = this_cat.previousSibling; | |
1174 | if (this_cat.id == "feedCatHolder") { | |
1175 | e = this_cat.firstChild.lastChild; | |
7b433d8c AD |
1176 | } |
1177 | } | |
7b433d8c | 1178 | } |
1da76274 AD |
1179 | |
1180 | } else { | |
1181 | e = false; | |
1182 | } | |
1183 | ||
1184 | if (e) { | |
e686782e | 1185 | if (!unread_only || (unread_only && e.className != "feed" && |
cabffe9d | 1186 | e.className.match("feed"))) { |
1da76274 AD |
1187 | return e.id.replace("FEEDR-", ""); |
1188 | } | |
1189 | } | |
1190 | } | |
7b433d8c AD |
1191 | } |
1192 | } | |
1193 | } | |
36aab70f AD |
1194 | |
1195 | function showBlockElement(id) { | |
1196 | var elem = document.getElementById(id); | |
1197 | ||
1198 | if (elem) { | |
1199 | elem.style.display = "block"; | |
1200 | } else { | |
1201 | alert("[showBlockElement] can't find element with id " + id); | |
1202 | } | |
1203 | } | |
1204 | ||
a9b0bfd5 AD |
1205 | function hideParentElement(e) { |
1206 | e.parentNode.style.display = "none"; | |
1207 | } | |
1b0809ae AD |
1208 | |
1209 | function dropboxSelect(e, v) { | |
1210 | for (i = 0; i < e.length; i++) { | |
1211 | if (e[i].value == v) { | |
1212 | e.selectedIndex = i; | |
1213 | break; | |
1214 | } | |
1215 | } | |
1216 | } | |
0ee1d1a0 AD |
1217 | |
1218 | // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z | |
1219 | // bugfixed just a little bit :-) | |
1220 | function getURLParam(strParamName){ | |
1221 | var strReturn = ""; | |
1222 | var strHref = window.location.href; | |
1223 | ||
1224 | if (strHref.indexOf("#") == strHref.length-1) { | |
1225 | strHref = strHref.substring(0, strHref.length-1); | |
1226 | } | |
1227 | ||
1228 | if ( strHref.indexOf("?") > -1 ){ | |
1229 | var strQueryString = strHref.substr(strHref.indexOf("?")); | |
1230 | var aQueryString = strQueryString.split("&"); | |
1231 | for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){ | |
1232 | if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){ | |
1233 | var aParam = aQueryString[iParam].split("="); | |
1234 | strReturn = aParam[1]; | |
1235 | break; | |
1236 | } | |
1237 | } | |
1238 | } | |
1239 | return strReturn; | |
1240 | } | |
1241 | ||
cf1bc085 AD |
1242 | function leading_zero(p) { |
1243 | var s = String(p); | |
1244 | if (s.length == 1) s = "0" + s; | |
1245 | return s; | |
1246 | } | |
c38c2b69 | 1247 | |
86b682ce | 1248 | function closeInfoBox(cleanup) { |
e5d758e3 AD |
1249 | var box = document.getElementById('infoBox'); |
1250 | var shadow = document.getElementById('infoBoxShadow'); | |
1251 | ||
1252 | if (shadow) { | |
1253 | shadow.style.display = "none"; | |
1254 | } else if (box) { | |
1255 | box.style.display = "none"; | |
1256 | } | |
1257 | ||
86b682ce AD |
1258 | if (cleanup) box.innerHTML = " "; |
1259 | ||
e5d758e3 | 1260 | enableHotkeys(); |
c14b5566 | 1261 | |
90ac84df | 1262 | return false; |
e5d758e3 AD |
1263 | } |
1264 | ||
1265 | ||
7b5c6012 AD |
1266 | function displayDlg(id, param) { |
1267 | ||
1268 | if (!xmlhttp_ready(xmlhttp)) { | |
1269 | printLockingError(); | |
1270 | return | |
1271 | } | |
1272 | ||
1273 | notify(""); | |
1274 | ||
1275 | xmlhttp.open("GET", "backend.php?op=dlg&id=" + | |
1276 | param_escape(id) + "¶m=" + param_escape(param), true); | |
e5d758e3 | 1277 | xmlhttp.onreadystatechange=infobox_callback; |
7b5c6012 AD |
1278 | xmlhttp.send(null); |
1279 | ||
1280 | disableHotkeys(); | |
2371c520 | 1281 | |
90ac84df | 1282 | return false; |
7b5c6012 AD |
1283 | } |
1284 | ||
e5d758e3 | 1285 | function infobox_submit_callback() { |
7b5c6012 | 1286 | if (xmlhttp.readyState == 4) { |
e5d758e3 | 1287 | closeInfoBox(); |
7b5c6012 | 1288 | |
6e6504bc AD |
1289 | try { |
1290 | // called from prefs, reload tab | |
1291 | if (active_tab) { | |
1292 | selectTab(active_tab, false); | |
1293 | } | |
1294 | } catch (e) { } | |
79f3553b AD |
1295 | |
1296 | notify(xmlhttp.responseText); | |
1297 | ||
7b5c6012 AD |
1298 | } |
1299 | } | |
1300 | ||
e5d758e3 | 1301 | function infobox_callback() { |
7b5c6012 | 1302 | if (xmlhttp.readyState == 4) { |
e5d758e3 AD |
1303 | var box = document.getElementById('infoBox'); |
1304 | var shadow = document.getElementById('infoBoxShadow'); | |
1305 | if (box) { | |
1306 | box.innerHTML=xmlhttp.responseText; | |
1307 | if (shadow) { | |
1308 | shadow.style.display = "block"; | |
1309 | } else { | |
1310 | box.style.display = "block"; | |
1311 | } | |
1312 | } | |
9c483746 | 1313 | notify(""); |
e5d758e3 | 1314 | } |
7b5c6012 AD |
1315 | } |
1316 | ||
1317 | function qaddFilter() { | |
1318 | ||
1319 | if (!xmlhttp_ready(xmlhttp)) { | |
1320 | printLockingError(); | |
1321 | return | |
1322 | } | |
1323 | ||
c91c2249 AD |
1324 | var form = document.forms['filter_add_form']; |
1325 | var reg_exp = form.reg_exp.value; | |
1326 | ||
1327 | if (reg_exp == "") { | |
1328 | alert("Can't add filter: nothing to match on."); | |
1329 | return false; | |
1330 | } | |
1331 | ||
79f3553b | 1332 | var query = Form.serialize("filter_add_form"); |
7b5c6012 | 1333 | |
79f3553b AD |
1334 | xmlhttp.open("GET", "backend.php?" + query, true); |
1335 | xmlhttp.onreadystatechange=infobox_submit_callback; | |
1336 | xmlhttp.send(null); | |
7b5c6012 | 1337 | |
c14b5566 | 1338 | return true; |
7b5c6012 AD |
1339 | } |
1340 | ||
2371c520 AD |
1341 | function toggleSubmitNotEmpty(e, submit_id) { |
1342 | try { | |
1343 | document.getElementById(submit_id).disabled = (e.value == "") | |
1344 | } catch (e) { | |
1345 | exception_error("toggleSubmitNotEmpty", e); | |
1346 | } | |
1347 | } | |
1d7bf5a0 | 1348 | |
605f7d46 AD |
1349 | function isValidURL(s) { |
1350 | return s.match("http://") != null || s.match("https://") != null; | |
1351 | } | |
07eb9178 AD |
1352 | |
1353 | function qafAdd() { | |
1354 | ||
1355 | if (!xmlhttp_ready(xmlhttp)) { | |
1356 | printLockingError(); | |
1357 | return | |
1358 | } | |
1359 | ||
c91c2249 AD |
1360 | var form = document.forms['feed_add_form']; |
1361 | var feed_url = form.feed_url.value; | |
1362 | ||
1363 | if (feed_url == "") { | |
1364 | alert("Can't subscribe: no feed URL given."); | |
1365 | return false; | |
1366 | } | |
1367 | ||
a58d997c | 1368 | notify("Adding feed...", true); |
07eb9178 AD |
1369 | |
1370 | closeInfoBox(); | |
1371 | ||
0feab655 | 1372 | var feeds_doc = document; |
07eb9178 | 1373 | |
80e4dc34 | 1374 | // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; |
07eb9178 AD |
1375 | |
1376 | var query = Form.serialize("feed_add_form"); | |
1377 | ||
1378 | xmlhttp.open("GET", "backend.php?" + query, true); | |
1379 | xmlhttp.onreadystatechange=dlg_frefresh_callback; | |
1380 | xmlhttp.send(null); | |
7bc4f251 AD |
1381 | |
1382 | return false; | |
07eb9178 AD |
1383 | } |
1384 | ||
6e6504bc | 1385 | function filterCR(e, f) |
86b682ce AD |
1386 | { |
1387 | var key; | |
1388 | ||
1389 | if(window.event) | |
1390 | key = window.event.keyCode; //IE | |
1391 | else | |
1392 | key = e.which; //firefox | |
1393 | ||
6e6504bc AD |
1394 | if (key == 13) { |
1395 | if (typeof f != 'undefined') { | |
1396 | f(); | |
1397 | return false; | |
1398 | } else { | |
1399 | return false; | |
1400 | } | |
1401 | } else { | |
1402 | return true; | |
1403 | } | |
86b682ce AD |
1404 | } |
1405 | ||
ac378ad4 | 1406 | function getMainContext() { |
6b4163cb | 1407 | return this.window; |
ac378ad4 AD |
1408 | } |
1409 | ||
33d13e72 | 1410 | function getFeedsContext() { |
6b4163cb | 1411 | return this.window; |
33d13e72 AD |
1412 | } |
1413 | ||
0bd411db | 1414 | function getContentContext() { |
6b4163cb | 1415 | return this.window; |
0bd411db AD |
1416 | } |
1417 | ||
ee1f45f4 | 1418 | function getHeadlinesContext() { |
6b4163cb | 1419 | return this.window; |
ee1f45f4 AD |
1420 | } |
1421 | ||
e8614131 AD |
1422 | var debug_last_class = "even"; |
1423 | ||
ac378ad4 | 1424 | function debug(msg) { |
ac378ad4 | 1425 | |
0feab655 AD |
1426 | if (debug_last_class == "even") { |
1427 | debug_last_class = "odd"; | |
e8614131 | 1428 | } else { |
0feab655 | 1429 | debug_last_class = "even"; |
e8614131 AD |
1430 | } |
1431 | ||
0feab655 | 1432 | var c = document.getElementById('debug_output'); |
ac378ad4 | 1433 | if (c && c.style.display == "block") { |
c9268ed5 | 1434 | while (c.lastChild != 'undefined' && c.childNodes.length > 100) { |
ac378ad4 AD |
1435 | c.removeChild(c.lastChild); |
1436 | } | |
1437 | ||
1438 | var d = new Date(); | |
1439 | var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) + | |
1440 | ":" + leading_zero(d.getSeconds()); | |
0feab655 | 1441 | c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " + |
e8614131 | 1442 | msg + "</li>" + c.innerHTML; |
ac378ad4 AD |
1443 | } |
1444 | } | |
1445 | ||
33d13e72 AD |
1446 | function getInitParam(key) { |
1447 | return getMainContext().init_params[key]; | |
1448 | } | |
3ac2b520 | 1449 | |
e8bd0da9 | 1450 | function storeInitParam(key, value, is_client) { |
33d13e72 | 1451 | try { |
e8bd0da9 | 1452 | if (!is_client) { |
1035fcec AD |
1453 | if (getMainContext().init_params[key] != value) { |
1454 | debug("storeInitParam: " + key + " => " + value); | |
0b7cb301 AD |
1455 | //new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" + |
1456 | // param_escape(key) + "&value=" + param_escape(value)); | |
1457 | var f = getMainContext().document.getElementById("backReqBox"); | |
1458 | f.src = "backend.php?op=rpc&subop=storeParam&key=" + | |
1459 | param_escape(key) + "&value=" + param_escape(value); | |
1035fcec | 1460 | } |
e8bd0da9 | 1461 | } |
1035fcec | 1462 | getMainContext().init_params[key] = value; |
33d13e72 AD |
1463 | } catch (e) { |
1464 | exception_error("storeInitParam", e); | |
1465 | } | |
1466 | } | |
a7565293 | 1467 | |
1035fcec AD |
1468 | /* |
1469 | function storeInitParams(params, is_client) { | |
1470 | try { | |
1471 | var s = ""; | |
1472 | ||
1473 | for (k in params) { | |
1474 | if (getMainContext().init_params[k] != params[k]) { | |
1475 | s += k + "=" + params[k] + ";"; | |
1476 | getMainContext().init_params[k] = params[k]; | |
1477 | } | |
1478 | } | |
1479 | ||
1480 | debug("storeInitParams: " + s); | |
1481 | ||
1482 | if (!is_client) { | |
1483 | new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s); | |
1484 | } | |
1485 | } catch (e) { | |
1486 | exception_error("storeInitParams", e); | |
1487 | } | |
1488 | }*/ | |
1489 | ||
a7565293 AD |
1490 | function fatalError(code, message) { |
1491 | try { | |
a7565293 | 1492 | |
4724a093 | 1493 | if (code != 6) { |
a7565293 | 1494 | |
4724a093 AD |
1495 | var fe = document.getElementById("fatal_error"); |
1496 | var fc = document.getElementById("fatal_error_msg"); | |
1497 | ||
1498 | fc.innerHTML = "Code " + code + ": " + message; | |
1499 | ||
1500 | fe.style.display = "block"; | |
1501 | } else { | |
1502 | window.location.href = "login.php?rt=none"; | |
1503 | } | |
a7565293 AD |
1504 | |
1505 | } catch (e) { | |
1506 | exception_error("fatalError", e); | |
1507 | } | |
1508 | } | |
1509 | ||
234e467c | 1510 | function getFeedName(id, is_cat) { |
64a2875d | 1511 | var d = getFeedsContext().document; |
234e467c AD |
1512 | |
1513 | var e; | |
1514 | ||
1515 | if (is_cat) { | |
1516 | e = d.getElementById("FCATN-" + id); | |
1517 | } else { | |
1518 | e = d.getElementById("FEEDN-" + id); | |
1519 | } | |
64a2875d AD |
1520 | if (e) { |
1521 | return e.innerHTML.stripTags(); | |
1522 | } else { | |
1523 | return null; | |
1524 | } | |
1525 | } | |
0bd411db AD |
1526 | |
1527 | function viewContentUrl(url) { | |
1528 | getContentContext().location = url; | |
1529 | } | |
350f0ad1 AD |
1530 | |
1531 | function filterDlgCheckAction(sender) { | |
1532 | ||
1533 | try { | |
1534 | ||
1535 | var action = sender[sender.selectedIndex].value; | |
1536 | ||
1537 | var form = document.forms["filter_add_form"]; | |
1538 | ||
1539 | if (!form) { | |
1540 | form = document.forms["filter_edit_form"]; | |
1541 | } | |
1542 | ||
1543 | if (!form) { | |
1544 | debug("filterDlgCheckAction: can't find form!"); | |
1545 | return; | |
1546 | } | |
1547 | ||
1548 | var action_param = form.action_param; | |
1549 | ||
1550 | if (!action_param) { | |
1551 | debug("filterDlgCheckAction: can't find action param!"); | |
1552 | return; | |
1553 | } | |
1554 | ||
1555 | // if selected action supports parameters, enable params field | |
1556 | if (action == 4) { | |
1557 | action_param.disabled = false; | |
1558 | } else { | |
1559 | action_param.disabled = true; | |
1560 | } | |
1561 | ||
1562 | } catch (e) { | |
1563 | exception_error(e, "filterDlgCheckAction"); | |
1564 | } | |
1565 | ||
1566 | } |