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