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