1 var hotkeys_enabled = true;
2 var debug_mode_enabled = false;
3 var xmlhttp_rpc = Ajax.getTransport();
5 /* add method to remove element from array */
7 Array.prototype.remove = function(s) {
8 for (var i=0; i < this.length; i++) {
9 if (s == this[i]) this.splice(i, 1);
13 function browser_has_opacity() {
14 return navigator.userAgent.match("Gecko") != null ||
15 navigator.userAgent.match("Opera") != null;
19 return navigator.userAgent.match("MSIE");
23 return navigator.userAgent.match("Opera");
27 return navigator.userAgent.match("KHTML");
30 function is_safari() {
31 return navigator.userAgent.match("Safari");
34 function exception_error(location, e, silent) {
38 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
40 msg = "Exception: " + e.name + ", " + e.message +
41 "\nFunction: " + location + "()" +
42 "\nLocation: " + base_fname + ":" + e.lineNumber;
45 msg = "Exception: " + e + "\nFunction: " + location + "()";
48 debug("<b>EXCEPTION: " + msg + "</b>");
55 function disableHotkeys() {
56 hotkeys_enabled = false;
59 function enableHotkeys() {
60 hotkeys_enabled = true;
63 function xmlhttp_ready(obj) {
64 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
67 function open_article_callback() {
68 if (xmlhttp_rpc.readyState == 4) {
71 if (xmlhttp_rpc.responseXML) {
72 var link = xmlhttp_rpc.responseXML.getElementsByTagName("link")[0];
75 window.open(link.firstChild.nodeValue, "_blank");
80 exception_error("open_article_callback", e);
85 function logout_callback() {
86 var container = document.getElementById('notify');
87 if (xmlhttp.readyState == 4) {
89 var date = new Date();
90 var timestamp = Math.round(date.getTime() / 1000);
91 window.location.href = "tt-rss.php";
93 exception_error("logout_callback", e);
98 function notify_callback() {
99 var container = document.getElementById('notify');
100 if (xmlhttp.readyState == 4) {
101 container.innerHTML=xmlhttp.responseText;
105 function rpc_notify_callback() {
106 var container = document.getElementById('notify');
107 if (xmlhttp_rpc.readyState == 4) {
108 container.innerHTML=xmlhttp_rpc.responseText;
112 function param_escape(arg) {
113 if (typeof encodeURIComponent != 'undefined')
114 return encodeURIComponent(arg);
119 function param_unescape(arg) {
120 if (typeof decodeURIComponent != 'undefined')
121 return decodeURIComponent(arg);
123 return unescape(arg);
126 function delay(gap) {
128 then=new Date().getTime();
130 while((now-then)<gap) {
131 now=new Date().getTime();
135 var notify_hide_timerid = false;
137 function hide_notify() {
138 var n = document.getElementById("notify");
140 n.style.display = "none";
144 function notify_real(msg, no_hide, n_type) {
146 var n = document.getElementById("notify");
147 var nb = document.getElementById("notify_body");
149 if (!n || !nb) return;
151 if (notify_hide_timerid) {
152 window.clearTimeout(notify_hide_timerid);
156 if (n.style.display == "block") {
157 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
161 n.style.display = "block";
173 if (typeof __ != 'undefined') {
178 n.className = "notify";
179 } else if (n_type == 2) {
180 n.className = "notifyProgress";
181 msg = "<img src='images/indicator_white.gif'> " + msg;
182 } else if (n_type == 3) {
183 n.className = "notifyError";
184 msg = "<img src='images/sign_excl.png'> " + msg;
185 } else if (n_type == 4) {
186 n.className = "notifyInfo";
187 msg = "<img src='images/sign_info.png'> " + msg;
190 // msg = "<img src='images/live_com_loading.gif'> " + msg;
195 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
199 function notify(msg, no_hide) {
200 notify_real(msg, no_hide, 1);
203 function notify_progress(msg, no_hide) {
204 notify_real(msg, no_hide, 2);
207 function notify_error(msg, no_hide) {
208 notify_real(msg, no_hide, 3);
212 function notify_info(msg, no_hide) {
213 notify_real(msg, no_hide, 4);
216 function printLockingError() {
217 notify_info("Please wait until operation finishes.");
220 function hotkey_handler(e) {
225 var shift_key = false;
228 shift_key = e.shiftKey;
233 if (!hotkeys_enabled) return;
236 keycode = window.event.keyCode;
241 if (keycode == 82) { // r
242 return scheduleFeedUpdate(true);
245 if (keycode == 83) { // s
246 return displayDlg("search", getActiveFeedId());
249 if (keycode == 85) { // u
250 if (getActiveFeedId()) {
251 return viewfeed(getActiveFeedId(), "ForceUpdate");
255 if (keycode == 65) { // a
256 return toggleDispRead();
259 var feedlist = document.getElementById('feedList');
261 if (keycode == 74) { // j
262 var feed = getActiveFeedId();
263 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
264 if (new_feed) viewfeed(new_feed, '');
267 if (keycode == 75) { // k
268 var feed = getActiveFeedId();
269 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
270 if (new_feed) viewfeed(new_feed, '');
273 if (keycode == 78 || keycode == 40) { // n, down
274 if (typeof moveToPost != 'undefined') {
275 return moveToPost('next');
279 if (keycode == 80 || keycode == 38) { // p, up
280 if (typeof moveToPost != 'undefined') {
281 return moveToPost('prev');
285 if (keycode == 68 && shift_key) { // d
286 if (!debug_mode_enabled) {
287 document.getElementById('debug_output').style.display = 'block';
288 debug('debug mode activated');
290 document.getElementById('debug_output').style.display = 'none';
293 debug_mode_enabled = !debug_mode_enabled;
296 if (keycode == 190 && shift_key) { // >
300 if (keycode == 188 && shift_key) { // <
304 if (keycode == 191 && shift_key) { // ?
308 if (keycode == 69 && shift_key) { // e
309 return editFeedDlg(getActiveFeedId());
312 if (keycode == 70 && shift_key) { // f
313 if (getActiveFeedId()) {
314 return catchupCurrentFeed();
318 if (keycode == 80 && shift_key) { // p
319 if (getActiveFeedId()) {
320 return catchupPage();
324 if (keycode == 86) { // v
325 if (getActiveArticleId()) {
326 openArticleInNewWindow(getActiveArticleId());
330 if (typeof localHotkeyHandler != 'undefined') {
332 return localHotkeyHandler(e);
334 exception_error("hotkey_handler, local:", e);
338 debug("KP=" + keycode);
340 exception_error("hotkey_handler", e);
344 function cleanSelectedList(element) {
345 var content = document.getElementById(element);
347 if (!document.getElementById("feedCatHolder")) {
348 for (i = 0; i < content.childNodes.length; i++) {
349 var child = content.childNodes[i];
351 child.className = child.className.replace("Selected", "");
357 for (i = 0; i < content.childNodes.length; i++) {
358 var child = content.childNodes[i];
359 if (child.id == "feedCatHolder") {
361 var fcat = child.lastChild;
362 for (j = 0; j < fcat.childNodes.length; j++) {
363 var feed = fcat.childNodes[j];
364 feed.className = feed.className.replace("Selected", "");
372 function cleanSelected(element) {
373 var content = document.getElementById(element);
375 for (i = 0; i < content.rows.length; i++) {
376 content.rows[i].className = content.rows[i].className.replace("Selected", "");
380 function getVisibleUnreadHeadlines() {
381 var content = document.getElementById("headlinesList");
383 var rows = new Array();
385 for (i = 0; i < content.rows.length; i++) {
386 var row_id = content.rows[i].id.replace("RROW-", "");
387 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
394 function getVisibleHeadlineIds() {
396 var content = document.getElementById("headlinesList");
398 var rows = new Array();
400 for (i = 0; i < content.rows.length; i++) {
401 var row_id = content.rows[i].id.replace("RROW-", "");
402 if (row_id.length > 0) {
409 function getFirstVisibleHeadlineId() {
410 var rows = getVisibleHeadlineIds();
414 function getLastVisibleHeadlineId() {
415 var rows = getVisibleHeadlineIds();
416 return rows[rows.length-1];
419 function markHeadline(id) {
420 var row = document.getElementById("RROW-" + id);
422 var is_active = false;
424 if (row.className.match("Active")) {
427 row.className = row.className.replace("Selected", "");
428 row.className = row.className.replace("Active", "");
429 row.className = row.className.replace("Insensitive", "");
432 row.className = row.className = "Active";
435 var check = document.getElementById("RCHK-" + id);
438 check.checked = true;
441 row.className = row.className + "Selected";
446 function getFeedIds() {
447 var content = document.getElementById("feedsList");
449 var rows = new Array();
451 for (i = 0; i < content.rows.length; i++) {
452 var id = content.rows[i].id.replace("FEEDR-", "");
461 function setCookie(name, value, lifetime, path, domain, secure) {
467 d.setTime(d.getTime() + (lifetime * 1000));
470 debug("setCookie: " + name + " => " + value + ": " + d);
472 int_setCookie(name, value, d, path, domain, secure);
476 function int_setCookie(name, value, expires, path, domain, secure) {
477 document.cookie= name + "=" + escape(value) +
478 ((expires) ? "; expires=" + expires.toGMTString() : "") +
479 ((path) ? "; path=" + path : "") +
480 ((domain) ? "; domain=" + domain : "") +
481 ((secure) ? "; secure" : "");
484 function delCookie(name, path, domain) {
485 if (getCookie(name)) {
486 document.cookie = name + "=" +
487 ((path) ? ";path=" + path : "") +
488 ((domain) ? ";domain=" + domain : "" ) +
489 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
494 function getCookie(name) {
496 var dc = document.cookie;
497 var prefix = name + "=";
498 var begin = dc.indexOf("; " + prefix);
500 begin = dc.indexOf(prefix);
501 if (begin != 0) return null;
506 var end = document.cookie.indexOf(";", begin);
510 return unescape(dc.substring(begin + prefix.length, end));
513 function disableContainerChildren(id, disable, doc) {
515 if (!doc) doc = document;
517 var container = doc.getElementById(id);
520 //alert("disableContainerChildren: element " + id + " not found");
524 for (var i = 0; i < container.childNodes.length; i++) {
525 var child = container.childNodes[i];
528 child.disabled = disable;
534 if (child.className && child.className.match("button")) {
535 child.className = "disabledButton";
538 if (child.className && child.className.match("disabledButton")) {
539 child.className = "button";
546 function gotoPreferences() {
547 document.location.href = "prefs.php";
550 function gotoMain() {
551 document.location.href = "tt-rss.php";
554 function gotoExportOpml() {
555 document.location.href = "opml.php?op=Export";
558 function getActiveFeedId() {
559 // return getCookie("ttrss_vf_actfeed");
561 debug("gAFID: " + active_feed_id);
562 return active_feed_id;
564 exception_error("getActiveFeedId", e);
568 function activeFeedIsCat() {
569 return active_feed_is_cat;
572 function setActiveFeedId(id) {
573 // return setCookie("ttrss_vf_actfeed", id);
575 debug("sAFID(" + id + ")");
578 exception_error("setActiveFeedId", e);
582 function parse_counters(reply, scheduled_call) {
587 if (reply.firstChild && reply.firstChild.firstChild) {
588 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
589 reply = reply.firstChild;
592 for (var l = 0; l < reply.childNodes.length; l++) {
593 if (!reply.childNodes[l] ||
594 typeof(reply.childNodes[l].getAttribute) == "undefined") {
595 // where did this come from?
599 var id = reply.childNodes[l].getAttribute("id");
600 var t = reply.childNodes[l].getAttribute("type");
601 var ctr = reply.childNodes[l].getAttribute("counter");
602 var error = reply.childNodes[l].getAttribute("error");
603 var has_img = reply.childNodes[l].getAttribute("hi");
604 var updated = reply.childNodes[l].getAttribute("updated");
606 if (id == "global-unread") {
612 if (id == "subscribed-feeds") {
617 if (t == "category") {
618 var catctr = document.getElementById("FCATCTR-" + id);
620 catctr.innerHTML = "(" + ctr + ")";
622 catctr.className = "catCtrHasUnread";
624 catctr.className = "catCtrNoUnread";
630 var feedctr = document.getElementById("FEEDCTR-" + id);
631 var feedu = document.getElementById("FEEDU-" + id);
632 var feedr = document.getElementById("FEEDR-" + id);
633 var feed_img = document.getElementById("FIMG-" + id);
634 var feedlink = document.getElementById("FEEDL-" + id);
635 var feedupd = document.getElementById("FLUPD-" + id);
637 if (updated && feedlink) {
639 feedlink.title = "Error: " + error + " (" + updated + ")";
641 feedlink.title = "Updated: " + updated;
645 if (updated && feedupd) {
647 feedupd.innerHTML = updated + " (Error)";
649 feedupd.innerHTML = updated;
653 if (feedctr && feedu && feedr) {
655 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
659 feedu.innerHTML = ctr;
662 feedr.className = feedr.className.replace("feed", "error");
664 feedr.className = feedr.className.replace("error", "feed");
668 feedctr.className = "odd";
669 if (!feedr.className.match("Unread")) {
670 var is_selected = feedr.className.match("Selected");
672 feedr.className = feedr.className.replace("Selected", "");
673 feedr.className = feedr.className.replace("Unread", "");
675 feedr.className = feedr.className + "Unread";
678 feedr.className = feedr.className + "Selected";
683 feedctr.className = "invisible";
684 feedr.className = feedr.className.replace("Unread", "");
689 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
691 var feeds_stored = number_of_feeds;
693 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
695 if (feeds_stored != feeds_found) {
696 number_of_feeds = feeds_found;
698 if (feeds_stored != 0) {
699 debug("Subscribed feed number changed, refreshing feedlist");
700 setTimeout('updateFeedList(false, false)', 50);
705 exception_error("parse_counters", e);
709 function parse_counters_reply(xmlhttp, scheduled_call) {
711 if (!xmlhttp.responseXML) {
712 notify_error("Backend did not return valid XML", true);
716 var reply = xmlhttp.responseXML.firstChild;
719 notify_error("Backend did not return expected XML object", true);
724 var error_code = false;
725 var error_msg = false;
727 if (reply.firstChild) {
728 error_code = reply.firstChild.getAttribute("error-code");
729 error_msg = reply.firstChild.getAttribute("error-msg");
733 error_code = reply.getAttribute("error-code");
734 error_msg = reply.getAttribute("error-msg");
737 if (error_code && error_code != 0) {
738 debug("refetch_callback: got error code " + error_code);
739 return fatalError(error_code, error_msg);
742 var counters = reply.firstChild;
744 parse_counters(counters, scheduled_call);
746 var runtime_info = counters.nextSibling;
748 parse_runtime_info(runtime_info);
750 if (getInitParam("feeds_sort_by_unread") == 1) {
754 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
758 function all_counters_callback() {
759 if (xmlhttp_rpc.readyState == 4) {
761 /* if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
762 debug("[all_counters_callback] backend did not return valid XML");
766 debug("in all_counters_callback : " + xmlhttp_rpc.responseXML);
768 var reply = xmlhttp_rpc.responseXML.firstChild;
770 var counters = reply.firstChild;
772 parse_counters(counters);
774 var runtime = counters.nextSibling;
777 parse_runtime_info(runtime);
780 if (getInitParam("feeds_sort_by_unread") == 1) {
784 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1); */
786 debug("in all_counters_callback");
788 parse_counters_reply(xmlhttp_rpc);
791 exception_error("all_counters_callback", e);
796 function get_feed_entry_unread(doc, elem) {
798 var id = elem.id.replace("FEEDR-", "");
805 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
811 function resort_category(doc, node) {
812 debug("resort_category: " + node);
814 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
815 for (i = 0; i < node.childNodes.length; i++) {
816 if (node.childNodes[i].nodeName != "LI") { continue; }
818 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
822 for (j = i+1; j < node.childNodes.length; j++) {
823 if (node.childNodes[j].nodeName != "LI") { continue; }
825 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
826 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
828 if (cur_val > tmp_val) {
829 tempnode_i = node.childNodes[i].cloneNode(true);
830 tempnode_j = node.childNodes[j].cloneNode(true);
831 node.replaceChild(tempnode_i, node.childNodes[j]);
832 node.replaceChild(tempnode_j, node.childNodes[i]);
841 function resort_feedlist() {
842 debug("resort_feedlist");
846 if (fd.getElementById("feedCatHolder")) {
848 var feeds = fd.getElementById("feedList");
849 var child = feeds.firstChild;
853 if (child.id == "feedCatHolder") {
854 resort_category(fd, child.firstChild);
857 child = child.nextSibling;
861 resort_category(fd, fd.getElementById("feedList"));
865 function update_all_counters(feed) {
866 if (xmlhttp_ready(xmlhttp_rpc)) {
867 var query = "backend.php?op=rpc&subop=getAllCounters";
870 query = query + "&aid=" + feed;
873 if (tagsAreDisplayed()) {
874 query = query + "&omode=lt";
876 query = query + "&omode=flc";
879 debug("update_all_counters QUERY: " + query);
881 var date = new Date();
882 var timestamp = Math.round(date.getTime() / 1000);
883 query = query + "&ts=" + timestamp
885 xmlhttp_rpc.open("GET", query, true);
886 xmlhttp_rpc.onreadystatechange=all_counters_callback;
887 xmlhttp_rpc.send(null);
891 function popupHelp(tid) {
892 var w = window.open("backend.php?op=help&tid=" + tid,
894 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
897 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
898 * * @author Sundar Dorai-Raj
899 * * Email: sdoraira@vt.edu
900 * * This program is free software; you can redistribute it and/or
901 * * modify it under the terms of the GNU General Public License
902 * * as published by the Free Software Foundation; either version 2
903 * * of the License, or (at your option) any later version,
904 * * provided that any use properly credits the author.
905 * * This program is distributed in the hope that it will be useful,
906 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
907 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
908 * * GNU General Public License for more details at http://www.gnu.org * * */
910 var numbers=".0123456789";
911 function isNumeric(x) {
912 // is x a String or a character?
914 // remove negative sign
916 for(j=0;j<x.length;j++) {
917 // call isNumeric recursively for each character
918 number=isNumeric(x.substring(j,j+1));
919 if(!number) return number;
924 // if x is number return true
925 if(numbers.indexOf(x)>=0) return true;
931 function hideOrShowFeeds(doc, hide) {
933 debug("hideOrShowFeeds: " + doc + ", " + hide);
937 var list = fd.getElementById("feedList");
939 if (fd.getElementById("feedCatHolder")) {
941 var feeds = fd.getElementById("feedList");
942 var child = feeds.firstChild;
946 if (child.id == "feedCatHolder") {
947 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
950 child = child.nextSibling;
954 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
958 function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
960 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
965 debug("hideOrShowFeeds: passed node is null, aborting");
969 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
970 for (i = 0; i < node.childNodes.length; i++) {
971 if (node.childNodes[i].nodeName != "LI") { continue; }
973 if (node.childNodes[i].style != undefined) {
975 var has_unread = (node.childNodes[i].className != "feed" &&
976 node.childNodes[i].className != "tag");
978 // debug(node.childNodes[i].id + " --> " + has_unread);
980 if (hide && !has_unread) {
981 node.childNodes[i].style.display = "none";
985 node.childNodes[i].style.display = "list-item";
989 node.childNodes[i].style.display = "list-item";
996 if (cat_unread == 0) {
997 if (cat_node.style == undefined) {
998 debug("ERROR: supplied cat_node " + cat_node +
999 " has no styles. WTF?");
1003 cat_node.style.display = "none";
1005 cat_node.style.display = "list-item";
1009 cat_node.style.display = "list-item";
1015 // debug("unread for category: " + cat_unread);
1018 function selectTableRow(r, do_select) {
1019 r.className = r.className.replace("Selected", "");
1022 r.className = r.className + "Selected";
1026 function selectTableRowById(elem_id, check_id, do_select) {
1030 var row = document.getElementById(elem_id);
1033 selectTableRow(row, do_select);
1036 var check = document.getElementById(check_id);
1039 check.checked = do_select;
1042 exception_error("selectTableRowById", e);
1046 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
1047 classcheck, reset_others) {
1049 var content = document.getElementById(content_id);
1052 alert("[selectTableRows] Element " + content_id + " not found.");
1056 for (i = 0; i < content.rows.length; i++) {
1057 if (!classcheck || content.rows[i].className.match(classcheck)) {
1059 if (content.rows[i].id.match(prefix)) {
1060 selectTableRow(content.rows[i], do_select);
1062 var row_id = content.rows[i].id.replace(prefix, "");
1063 var check = document.getElementById(check_prefix + row_id);
1066 check.checked = do_select;
1068 } else if (reset_others) {
1069 selectTableRow(content.rows[i], false);
1071 var row_id = content.rows[i].id.replace(prefix, "");
1072 var check = document.getElementById(check_prefix + row_id);
1075 check.checked = false;
1079 } else if (reset_others) {
1080 selectTableRow(content.rows[i], false);
1082 var row_id = content.rows[i].id.replace(prefix, "");
1083 var check = document.getElementById(check_prefix + row_id);
1086 check.checked = false;
1093 function getSelectedTableRowIds(content_id, prefix) {
1095 var content = document.getElementById(content_id);
1098 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
1102 var sel_rows = new Array();
1104 for (i = 0; i < content.rows.length; i++) {
1105 if (content.rows[i].id.match(prefix) &&
1106 content.rows[i].className.match("Selected")) {
1108 var row_id = content.rows[i].id.replace(prefix + "-", "");
1109 sel_rows.push(row_id);
1117 function toggleSelectRowById(sender, id) {
1118 var row = document.getElementById(id);
1120 if (sender.checked) {
1121 if (!row.className.match("Selected")) {
1122 row.className = row.className + "Selected";
1125 if (row.className.match("Selected")) {
1126 row.className = row.className.replace("Selected", "");
1131 function toggleSelectListRow(sender) {
1132 var parent_row = sender.parentNode;
1134 if (sender.checked) {
1135 if (!parent_row.className.match("Selected")) {
1136 parent_row.className = parent_row.className + "Selected";
1139 if (parent_row.className.match("Selected")) {
1140 parent_row.className = parent_row.className.replace("Selected", "");
1145 function tSR(sender) {
1146 return toggleSelectRow(sender);
1149 function toggleSelectRow(sender) {
1150 var parent_row = sender.parentNode.parentNode;
1152 if (sender.checked) {
1153 if (!parent_row.className.match("Selected")) {
1154 parent_row.className = parent_row.className + "Selected";
1157 if (parent_row.className.match("Selected")) {
1158 parent_row.className = parent_row.className.replace("Selected", "");
1163 function openExternalUrl(url) {
1164 var w = window.open(url);
1167 function getRelativeFeedId(list, id, direction, unread_only) {
1169 if (direction == "next") {
1170 for (i = 0; i < list.childNodes.length; i++) {
1171 var child = list.childNodes[i];
1172 if (child.id && child.id == "feedCatHolder") {
1173 if (child.lastChild) {
1174 var cr = getRelativeFeedId(child.firstChild, id, direction, unread_only);
1177 } else if (child.id && child.id.match("FEEDR-")) {
1178 return child.id.replace('FEEDR-', '');
1183 // FIXME select last feed doesn't work when only unread feeds are visible
1185 if (direction == "prev") {
1186 for (i = list.childNodes.length-1; i >= 0; i--) {
1187 var child = list.childNodes[i];
1188 if (child.id == "feedCatHolder" && child.className != "invisible") {
1189 if (child.firstChild) {
1190 var cr = getRelativeFeedId(child.firstChild, id, direction);
1193 } else if (child.id.match("FEEDR-")) {
1195 if (getInitParam("hide_read_feeds") == 1) {
1196 if (child.className != "feed") {
1197 // alert(child.className);
1198 return child.id.replace('FEEDR-', '');
1201 return child.id.replace('FEEDR-', '');
1208 var feed = list.ownerDocument.getElementById("FEEDR-" + id);
1210 if (getInitParam("hide_read_feeds") == 1) {
1214 if (direction == "next") {
1220 if (e.nextSibling) {
1224 } else if (e.parentNode.parentNode.nextSibling) {
1226 var this_cat = e.parentNode.parentNode;
1230 if (this_cat && this_cat.nextSibling) {
1231 while (!e && this_cat.nextSibling) {
1232 this_cat = this_cat.nextSibling;
1233 if (this_cat.id == "feedCatHolder") {
1234 e = this_cat.firstChild.firstChild;
1244 if (!unread_only || (unread_only && e.className != "feed" &&
1245 e.className.match("feed"))) {
1246 if (e.parentNode.parentNode && e.parentNode.parentNode.className
1248 return e.id.replace("FEEDR-", "");
1254 } else if (direction == "prev") {
1260 if (e.previousSibling) {
1262 e = e.previousSibling;
1264 } else if (e.parentNode.parentNode.previousSibling) {
1266 var this_cat = e.parentNode.parentNode;
1270 if (this_cat && this_cat.previousSibling) {
1271 while (!e && this_cat.previousSibling) {
1272 this_cat = this_cat.previousSibling;
1273 if (this_cat.id == "feedCatHolder") {
1274 e = this_cat.firstChild.lastChild;
1284 if (!unread_only || (unread_only && e.className != "feed" &&
1285 e.className.match("feed"))) {
1286 if (e.parentNode.parentNode && e.parentNode.parentNode.className
1288 return e.id.replace("FEEDR-", "");
1297 function showBlockElement(id, h_id) {
1298 var elem = document.getElementById(id);
1301 elem.style.display = "block";
1304 elem = document.getElementById(h_id);
1306 elem.style.display = "none";
1310 alert("[showBlockElement] can't find element with id " + id);
1314 function hideParentElement(e) {
1315 e.parentNode.style.display = "none";
1318 function dropboxSelect(e, v) {
1319 for (i = 0; i < e.length; i++) {
1320 if (e[i].value == v) {
1321 e.selectedIndex = i;
1327 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1328 // bugfixed just a little bit :-)
1329 function getURLParam(strParamName){
1331 var strHref = window.location.href;
1333 if (strHref.indexOf("#") == strHref.length-1) {
1334 strHref = strHref.substring(0, strHref.length-1);
1337 if ( strHref.indexOf("?") > -1 ){
1338 var strQueryString = strHref.substr(strHref.indexOf("?"));
1339 var aQueryString = strQueryString.split("&");
1340 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1341 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1342 var aParam = aQueryString[iParam].split("=");
1343 strReturn = aParam[1];
1351 function leading_zero(p) {
1353 if (s.length == 1) s = "0" + s;
1357 function closeInfoBox(cleanup) {
1359 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1360 var overlay = document.getElementById("dialog_overlay");
1362 overlay.style.display = "none";
1366 var box = document.getElementById('infoBox');
1367 var shadow = document.getElementById('infoBoxShadow');
1370 shadow.style.display = "none";
1372 box.style.display = "none";
1375 if (cleanup) box.innerHTML = " ";
1383 function displayDlg(id, param) {
1385 if (!xmlhttp_ready(xmlhttp)) {
1386 printLockingError();
1390 notify_progress("Loading, please wait...", true);
1392 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
1393 param_escape(id) + "¶m=" + param_escape(param), true);
1394 xmlhttp.onreadystatechange=infobox_callback;
1402 function infobox_submit_callback() {
1403 if (xmlhttp.readyState == 4) {
1407 // called from prefs, reload tab
1409 selectTab(active_tab, false);
1413 if (xmlhttp.responseText) {
1414 notify_info(xmlhttp.responseText);
1420 function infobox_callback() {
1421 if (xmlhttp.readyState == 4) {
1425 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1426 var overlay = document.getElementById("dialog_overlay");
1428 overlay.style.display = "block";
1432 var box = document.getElementById('infoBox');
1433 var shadow = document.getElementById('infoBoxShadow');
1435 box.innerHTML=xmlhttp.responseText;
1437 shadow.style.display = "block";
1439 box.style.display = "block";
1444 exception_error("infobox_callback", e);
1449 function helpbox_callback() {
1450 if (xmlhttp.readyState == 4) {
1451 var box = document.getElementById('helpBox');
1452 var shadow = document.getElementById('helpBoxShadow');
1454 box.innerHTML=xmlhttp.responseText;
1456 shadow.style.display = "block";
1458 box.style.display = "block";
1465 function addFilter() {
1467 if (!xmlhttp_ready(xmlhttp)) {
1468 printLockingError();
1472 var form = document.forms['filter_add_form'];
1473 var reg_exp = form.reg_exp.value;
1475 if (reg_exp == "") {
1476 alert("Can't add filter: nothing to match on.");
1480 var query = Form.serialize("filter_add_form");
1482 xmlhttp.open("GET", "backend.php?" + query, true);
1483 xmlhttp.onreadystatechange=infobox_submit_callback;
1489 function toggleSubmitNotEmpty(e, submit_id) {
1491 document.getElementById(submit_id).disabled = (e.value == "")
1493 exception_error("toggleSubmitNotEmpty", e);
1497 function isValidURL(s) {
1498 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
1501 function qaddFeed() {
1503 if (!xmlhttp_ready(xmlhttp)) {
1504 printLockingError();
1508 var form = document.forms['feed_add_form'];
1509 var feed_url = form.feed_url.value;
1511 if (feed_url == "") {
1512 alert("Can't subscribe: no feed URL given.");
1516 notify_progress(__("Subscribing to feed..."), true);
1520 var feeds_doc = document;
1522 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1524 var query = Form.serialize("feed_add_form");
1526 debug("subscribe q: " + query);
1528 /* xmlhttp.open("GET", "backend.php?" + query, true);
1529 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1530 xmlhttp.send(null); */
1532 xmlhttp.open("POST", "backend.php", true);
1533 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1534 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1535 xmlhttp.send(query);
1540 function filterCR(e, f)
1545 key = window.event.keyCode; //IE
1547 key = e.which; //firefox
1550 if (typeof f != 'undefined') {
1561 function getMainContext() {
1565 function getFeedsContext() {
1569 function getContentContext() {
1573 function getHeadlinesContext() {
1577 var debug_last_class = "even";
1579 function debug(msg) {
1581 if (debug_last_class == "even") {
1582 debug_last_class = "odd";
1584 debug_last_class = "even";
1587 var c = document.getElementById('debug_output');
1588 if (c && c.style.display == "block") {
1589 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1590 c.removeChild(c.lastChild);
1594 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1595 ":" + leading_zero(d.getSeconds());
1596 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1597 msg + "</li>" + c.innerHTML;
1601 function getInitParam(key) {
1602 return init_params[key];
1605 function storeInitParam(key, value) {
1606 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
1607 init_params[key] = value;
1610 function fatalError(code, message) {
1614 window.location.href = "tt-rss.php";
1615 } else if (code == 5) {
1616 window.location.href = "update.php";
1618 var fe = document.getElementById("fatal_error");
1619 var fc = document.getElementById("fatal_error_msg");
1621 if (message == "") message = "Unknown error";
1623 fc.innerHTML = "<img src='images/sign_excl.png'> " + message + " (Code " + code + ")";
1625 fe.style.display = "block";
1629 exception_error("fatalError", e);
1633 function getFeedName(id, is_cat) {
1634 var d = getFeedsContext().document;
1639 e = d.getElementById("FCATN-" + id);
1641 e = d.getElementById("FEEDN-" + id);
1644 return e.innerHTML.stripTags();
1650 function viewContentUrl(url) {
1651 getContentContext().location = url;
1654 function filterDlgCheckAction(sender) {
1658 var action = sender[sender.selectedIndex].value;
1660 var form = document.forms["filter_add_form"];
1663 form = document.forms["filter_edit_form"];
1667 debug("filterDlgCheckAction: can't find form!");
1671 var action_param = form.action_param;
1673 if (!action_param) {
1674 debug("filterDlgCheckAction: can't find action param!");
1678 // if selected action supports parameters, enable params field
1680 action_param.disabled = false;
1682 action_param.disabled = true;
1686 exception_error(e, "filterDlgCheckAction");
1691 function explainError(code) {
1692 return displayDlg("explainError", code);
1695 function logoutUser() {
1697 if (xmlhttp_ready(xmlhttp_rpc)) {
1699 notify_progress("Logging out, please wait...", true);
1701 xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=logout", true);
1702 xmlhttp_rpc.onreadystatechange=logout_callback;
1703 xmlhttp_rpc.send(null);
1705 printLockingError();
1708 exception_error("logoutUser", e);
1712 // this only searches loaded headlines list, not in CDM
1713 function getRelativePostIds(id) {
1715 debug("getRelativePostIds: " + id);
1717 var ids = new Array();
1718 var container = document.getElementById("headlinesList");
1721 var rows = container.rows;
1723 for (var i = 0; i < rows.length; i++) {
1724 var r_id = rows[i].id.replace("RROW-", "");
1727 if (i > 0) ids.push(rows[i-1].id.replace("RROW-", ""));
1728 if (i > 1) ids.push(rows[i-2].id.replace("RROW-", ""));
1729 if (i > 2) ids.push(rows[i-3].id.replace("RROW-", ""));
1731 if (i < rows.length-1) ids.push(rows[i+1].id.replace("RROW-", ""));
1732 if (i < rows.length-2) ids.push(rows[i+2].id.replace("RROW-", ""));
1733 if (i < rows.length-3) ids.push(rows[i+3].id.replace("RROW-", ""));
1743 function openArticleInNewWindow(id) {
1746 if (!xmlhttp_ready(xmlhttp_rpc)) {
1747 printLockingError();
1751 debug("openArticleInNewWindow: " + id);
1753 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1757 xmlhttp_rpc.open("GET", query, true);
1758 xmlhttp_rpc.onreadystatechange=open_article_callback;
1759 xmlhttp_rpc.send(null);
1762 exception_error("openArticleInNewWindow", e);