1 var hotkeys_enabled = true;
2 var notify_silent = false;
3 var last_progress_point = 0;
4 var async_counters_work = false;
6 /* add method to remove element from array */
8 Array.prototype.remove = function(s) {
9 for (var i=0; i < this.length; i++) {
10 if (s == this[i]) this.splice(i, 1);
18 function exception_error(location, e, ext_info) {
19 var msg = format_exception_error(location, e);
21 if (!ext_info) ext_info = "N/A";
27 var ebc = $("xebContent");
31 Element.show("dialog_overlay");
32 Element.show("errorBoxShadow");
35 if (ext_info.responseText) {
36 ext_info = ext_info.responseText;
41 "<div><b>Error message:</b></div>" +
42 "<pre>" + msg + "</pre>" +
43 "<div><b>Additional information:</b></div>" +
44 "<textarea readonly=\"1\">" + ext_info + "</textarea>";
57 function format_exception_error(location, e) {
61 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
63 msg = "Exception: " + e.name + ", " + e.message +
64 "\nFunction: " + location + "()" +
65 "\nLocation: " + base_fname + ":" + e.lineNumber;
67 } else if (e.description) {
68 msg = "Exception: " + e.description + "\nFunction: " + location + "()";
70 msg = "Exception: " + e + "\nFunction: " + location + "()";
73 debug("<b>EXCEPTION: " + msg + "</b>");
79 function disableHotkeys() {
80 hotkeys_enabled = false;
83 function enableHotkeys() {
84 hotkeys_enabled = true;
87 function open_article_callback(transport) {
90 if (transport.responseXML) {
92 var link = transport.responseXML.getElementsByTagName("link")[0];
93 var id = transport.responseXML.getElementsByTagName("id")[0];
95 debug("open_article_callback, received link: " + link);
99 var wname = "ttrss_article_" + id.firstChild.nodeValue;
101 debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
103 var w = window.open(link.firstChild.nodeValue, wname);
105 if (!w) { notify_error("Failed to load article in new window"); }
108 id = id.firstChild.nodeValue;
109 if (!$("headlinesList")) {
110 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
114 notify_error("Can't open article: received invalid article link");
117 notify_error("Can't open article: received invalid XML");
121 exception_error("open_article_callback", e);
125 function param_escape(arg) {
126 if (typeof encodeURIComponent != 'undefined')
127 return encodeURIComponent(arg);
132 function param_unescape(arg) {
133 if (typeof decodeURIComponent != 'undefined')
134 return decodeURIComponent(arg);
136 return unescape(arg);
139 function delay(gap) {
141 then=new Date().getTime();
143 while((now-then)<gap) {
144 now=new Date().getTime();
148 var notify_hide_timerid = false;
150 function hide_notify() {
153 n.style.display = "none";
157 function notify_silent_next() {
158 notify_silent = true;
161 function notify_real(msg, no_hide, n_type) {
164 notify_silent = false;
169 var nb = $("notify_body");
171 if (!n || !nb) return;
173 if (notify_hide_timerid) {
174 window.clearTimeout(notify_hide_timerid);
178 if (n.style.display == "block") {
179 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
183 n.style.display = "block";
195 if (typeof __ != 'undefined') {
200 n.className = "notify";
201 } else if (n_type == 2) {
202 n.className = "notifyProgress";
203 msg = "<img src='images/indicator_white.gif'> " + msg;
204 } else if (n_type == 3) {
205 n.className = "notifyError";
206 msg = "<img src='images/sign_excl.gif'> " + msg;
207 } else if (n_type == 4) {
208 n.className = "notifyInfo";
209 msg = "<img src='images/sign_info.gif'> " + msg;
212 // msg = "<img src='images/live_com_loading.gif'> " + msg;
217 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
221 function notify(msg, no_hide) {
222 notify_real(msg, no_hide, 1);
225 function notify_progress(msg, no_hide) {
226 notify_real(msg, no_hide, 2);
229 function notify_error(msg, no_hide) {
230 notify_real(msg, no_hide, 3);
234 function notify_info(msg, no_hide) {
235 notify_real(msg, no_hide, 4);
238 function printLockingError() {
239 notify_info("Please wait until operation finishes.");
242 function cleanSelected(element) {
243 var content = $(element);
245 for (i = 0; i < content.rows.length; i++) {
246 content.rows[i].className = content.rows[i].className.replace("Selected", "");
250 function getVisibleUnreadHeadlines() {
251 var content = $("headlinesList");
253 var rows = new Array();
255 if (!content) return rows;
257 for (i = 0; i < content.rows.length; i++) {
258 var row_id = content.rows[i].id.replace("RROW-", "");
259 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
266 function getVisibleHeadlineIds() {
268 var content = $("headlinesList");
270 var rows = new Array();
272 if (!content) return rows;
274 for (i = 0; i < content.rows.length; i++) {
275 var row_id = content.rows[i].id.replace("RROW-", "");
276 if (row_id.length > 0) {
283 function getFirstVisibleHeadlineId() {
285 var rows = cdmGetVisibleArticles();
288 var rows = getVisibleHeadlineIds();
293 function getLastVisibleHeadlineId() {
295 var rows = cdmGetVisibleArticles();
296 return rows[rows.length-1];
298 var rows = getVisibleHeadlineIds();
299 return rows[rows.length-1];
303 function markHeadline(id) {
304 var row = $("RROW-" + id);
306 var is_active = false;
308 if (row.className.match("Active")) {
311 row.className = row.className.replace("Selected", "");
312 row.className = row.className.replace("Active", "");
313 row.className = row.className.replace("Insensitive", "");
316 row.className = row.className = "Active";
319 var check = $("RCHK-" + id);
322 check.checked = true;
325 row.className = row.className + "Selected";
330 function getFeedIds() {
331 var content = $("feedsList");
333 var rows = new Array();
335 for (i = 0; i < content.rows.length; i++) {
336 var id = content.rows[i].id.replace("FEEDR-", "");
345 function setCookie(name, value, lifetime, path, domain, secure) {
351 d.setTime(d.getTime() + (lifetime * 1000));
354 debug("setCookie: " + name + " => " + value + ": " + d);
356 int_setCookie(name, value, d, path, domain, secure);
360 function int_setCookie(name, value, expires, path, domain, secure) {
361 document.cookie= name + "=" + escape(value) +
362 ((expires) ? "; expires=" + expires.toGMTString() : "") +
363 ((path) ? "; path=" + path : "") +
364 ((domain) ? "; domain=" + domain : "") +
365 ((secure) ? "; secure" : "");
368 function delCookie(name, path, domain) {
369 if (getCookie(name)) {
370 document.cookie = name + "=" +
371 ((path) ? ";path=" + path : "") +
372 ((domain) ? ";domain=" + domain : "" ) +
373 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
378 function getCookie(name) {
380 var dc = document.cookie;
381 var prefix = name + "=";
382 var begin = dc.indexOf("; " + prefix);
384 begin = dc.indexOf(prefix);
385 if (begin != 0) return null;
390 var end = document.cookie.indexOf(";", begin);
394 return unescape(dc.substring(begin + prefix.length, end));
397 function disableContainerChildren(id, disable, doc) {
399 if (!doc) doc = document;
401 var container = $(id);
404 //alert("disableContainerChildren: element " + id + " not found");
408 for (var i = 0; i < container.childNodes.length; i++) {
409 var child = container.childNodes[i];
412 child.disabled = disable;
418 if (child.className && child.className.match("button")) {
419 child.className = "disabledButton";
422 if (child.className && child.className.match("disabledButton")) {
423 child.className = "button";
430 function gotoPreferences() {
431 document.location.href = "prefs.php";
434 function gotoMain() {
435 document.location.href = "tt-rss.php";
438 function gotoExportOpml() {
439 document.location.href = "opml.php?op=Export";
442 function parse_counters(reply, scheduled_call) {
447 var elems = reply.getElementsByTagName("counter");
449 for (var l = 0; l < elems.length; l++) {
451 var id = elems[l].getAttribute("id");
452 var t = elems[l].getAttribute("type");
453 var ctr = elems[l].getAttribute("counter");
454 var error = elems[l].getAttribute("error");
455 var has_img = elems[l].getAttribute("hi");
456 var updated = elems[l].getAttribute("updated");
457 var title = elems[l].getAttribute("title");
458 var xmsg = elems[l].getAttribute("xmsg");
460 if (id == "global-unread") {
462 if (ctr > global_unread) {
463 offlineDownloadStart(1);
471 if (id == "subscribed-feeds") {
476 if (t == "category") {
477 var catctr = $("FCATCTR-" + id);
479 catctr.innerHTML = "(" + ctr + ")";
481 catctr.className = "catCtrHasUnread";
483 catctr.className = "catCtrNoUnread";
489 var feedctr = $("FEEDCTR-" + id);
490 var feedu = $("FEEDU-" + id);
491 var feedr = $("FEEDR-" + id);
492 var feed_img = $("FIMG-" + id);
493 var feedlink = $("FEEDL-" + id);
494 var feedupd = $("FLUPD-" + id);
496 if (updated && feedlink) {
498 feedlink.title = "Error: " + error + " (" + updated + ")";
500 feedlink.title = "Updated: " + updated;
505 if (!updated) updated = "";
509 feedupd.innerHTML = updated + " " + xmsg + " (Error)";
511 feedupd.innerHTML = updated + " (Error)";
515 feedupd.innerHTML = updated + " " + xmsg;
517 feedupd.innerHTML = updated;
522 if (has_img && feed_img) {
523 if (!feed_img.src.match(id + ".ico")) {
524 feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
528 if (feedlink && title) {
529 feedlink.innerHTML = title;
532 if (feedctr && feedu && feedr) {
534 if (parseInt(ctr) > 0 &&
535 parseInt(feedu.innerHTML) < parseInt(ctr) &&
536 id == getActiveFeedId() && scheduled_call) {
538 displayNewContentPrompt(id);
541 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
543 feedu.innerHTML = ctr;
546 feedr.className = feedr.className.replace("feed", "error");
548 feedr.className = feedr.className.replace("error", "feed");
552 feedctr.className = "feedCtrHasUnread";
553 if (!feedr.className.match("Unread")) {
554 var is_selected = feedr.className.match("Selected");
556 feedr.className = feedr.className.replace("Selected", "");
557 feedr.className = feedr.className.replace("Unread", "");
559 feedr.className = feedr.className + "Unread";
562 feedr.className = feedr.className + "Selected";
568 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
569 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
571 cache_invalidate("F:" + id);
574 feedctr.className = "feedCtrNoUnread";
575 feedr.className = feedr.className.replace("Unread", "");
580 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
582 var feeds_stored = number_of_feeds;
584 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
586 if (feeds_stored != feeds_found) {
587 number_of_feeds = feeds_found;
589 if (feeds_stored != 0 && feeds_found != 0) {
590 debug("Subscribed feed number changed, refreshing feedlist");
591 setTimeout('updateFeedList(false, false)', 50);
594 /* var fl = $("feeds-frame").innerHTML;
596 cache_invalidate("FEEDLIST");
597 cache_inject("FEEDLIST", fl, getInitParam("num_feeds"));
602 exception_error("parse_counters", e);
606 function parse_counters_reply(transport, scheduled_call) {
608 if (!transport.responseXML) {
609 notify_error("Backend did not return valid XML", true);
613 var reply = transport.responseXML.firstChild;
616 notify_error("Backend did not return expected XML object", true);
621 if (!transport_error_check(transport)) return;
623 var counters = reply.getElementsByTagName("counters")[0];
625 parse_counters(counters, scheduled_call);
627 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
629 parse_runtime_info(runtime_info);
631 if (feedsSortByUnread()) {
635 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
639 function all_counters_callback2(transport, async_call) {
641 if (async_call) async_counters_work = true;
643 if (offline_mode) return;
645 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
646 parse_counters_reply(transport);
647 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
650 exception_error("all_counters_callback2", e, transport);
654 function get_feed_unread(id) {
656 return parseInt($("FEEDU-" + id).innerHTML);
662 function get_cat_unread(id) {
664 var ctr = $("FCATCTR-" + id).innerHTML;
665 ctr = ctr.replace("(", "");
666 ctr = ctr.replace(")", "");
667 return parseInt(ctr);
673 function get_feed_entry_unread(elem) {
675 var id = elem.id.replace("FEEDR-", "");
682 return parseInt($("FEEDU-" + id).innerHTML);
688 function get_feed_entry_name(elem) {
689 var id = elem.id.replace("FEEDR-", "");
690 return getFeedName(id);
694 function resort_category(node) {
698 debug("resort_category: " + node);
700 var by_unread = feedsSortByUnread();
702 var list = node.getElementsByTagName("LI");
704 for (i = 0; i < list.length; i++) {
706 for (j = i+1; j < list.length; j++) {
708 var tmp_val = get_feed_entry_unread(list[i]);
709 var cur_val = get_feed_entry_unread(list[j]);
711 var tmp_name = get_feed_entry_name(list[i]);
712 var cur_name = get_feed_entry_name(list[j]);
714 if ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name))) {
715 tempnode_i = list[i].cloneNode(true);
716 tempnode_j = list[j].cloneNode(true);
717 node.replaceChild(tempnode_i, list[j]);
718 node.replaceChild(tempnode_j, list[i]);
724 exception_error("resort_category", e);
729 function resort_feedlist() {
730 debug("resort_feedlist");
732 if ($("FCATLIST--1")) {
734 var lists = document.getElementsByTagName("UL");
736 for (var i = 0; i < lists.length; i++) {
737 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
738 resort_category(lists[i]);
743 //resort_category($("feedList"));
747 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
748 * * @author Sundar Dorai-Raj
749 * * Email: sdoraira@vt.edu
750 * * This program is free software; you can redistribute it and/or
751 * * modify it under the terms of the GNU General Public License
752 * * as published by the Free Software Foundation; either version 2
753 * * of the License, or (at your option) any later version,
754 * * provided that any use properly credits the author.
755 * * This program is distributed in the hope that it will be useful,
756 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
757 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
758 * * GNU General Public License for more details at http://www.gnu.org * * */
760 var numbers=".0123456789";
761 function isNumeric(x) {
762 // is x a String or a character?
764 // remove negative sign
766 for(j=0;j<x.length;j++) {
767 // call isNumeric recursively for each character
768 number=isNumeric(x.substring(j,j+1));
769 if(!number) return number;
774 // if x is number return true
775 if(numbers.indexOf(x)>=0) return true;
781 function hideOrShowFeeds(hide) {
785 debug("hideOrShowFeeds: " + hide);
787 if ($("FCATLIST--1")) {
789 var lists = document.getElementsByTagName("UL");
791 for (var i = 0; i < lists.length; i++) {
792 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
794 var id = lists[i].id.replace("FCATLIST-", "");
795 hideOrShowFeedsCategory(id, hide);
800 hideOrShowFeedsCategory(null, hide);
804 exception_error("hideOrShowFeeds", e);
808 function hideOrShowFeedsCategory(id, hide) {
816 node = $("FCATLIST-" + id);
817 cat_node = $("FCAT-" + id);
819 node = $("feedList"); // no categories
822 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
827 debug("hideOrShowFeeds: passed node is null, aborting");
831 // debug("cat: " + node.id);
833 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
834 for (i = 0; i < node.childNodes.length; i++) {
835 if (node.childNodes[i].nodeName != "LI") { continue; }
837 if (node.childNodes[i].style != undefined) {
839 var has_unread = (node.childNodes[i].className != "feed" &&
840 node.childNodes[i].className != "label" &&
841 !(!getInitParam("hide_read_shows_special") &&
842 node.childNodes[i].className == "virt") &&
843 node.childNodes[i].className != "error" &&
844 node.childNodes[i].className != "tag");
846 // debug(node.childNodes[i].id + " --> " + has_unread);
848 if (hide && !has_unread) {
849 //node.childNodes[i].style.display = "none";
850 var id = node.childNodes[i].id;
851 Effect.Fade(node.childNodes[i], {duration : 0.3,
852 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
856 node.childNodes[i].style.display = "list-item";
857 //Effect.Appear(node.childNodes[i], {duration : 0.3});
861 node.childNodes[i].style.display = "list-item";
863 //Effect.Appear(node.childNodes[i], {duration : 0.3});
864 //Effect.Highlight(node.childNodes[i]);
870 // debug("end cat: " + node.id + " unread " + cat_unread);
874 if (cat_unread == 0) {
875 if (cat_node.style == undefined) {
876 debug("ERROR: supplied cat_node " + cat_node +
877 " has no styles. WTF?");
881 //cat_node.style.display = "none";
882 Effect.Fade(cat_node, {duration : 0.3,
883 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
885 cat_node.style.display = "list-item";
889 cat_node.style.display = "list-item";
896 // debug("unread for category: " + cat_unread);
899 exception_error("hideOrShowFeedsCategory", e);
903 function selectTableRow(r, do_select) {
904 r.className = r.className.replace("Selected", "");
907 r.className = r.className + "Selected";
911 function selectTableRowById(elem_id, check_id, do_select) {
915 var row = $(elem_id);
918 selectTableRow(row, do_select);
921 var check = $(check_id);
924 check.checked = do_select;
927 exception_error("selectTableRowById", e);
931 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
932 classcheck, reset_others) {
934 var content = $(content_id);
937 alert("[selectTableRows] Element " + content_id + " not found.");
941 for (i = 0; i < content.rows.length; i++) {
942 if (Element.visible(content.rows[i])) {
943 if (!classcheck || content.rows[i].className.match(classcheck)) {
945 if (content.rows[i].id.match(prefix)) {
946 selectTableRow(content.rows[i], do_select);
948 var row_id = content.rows[i].id.replace(prefix, "");
949 var check = $(check_prefix + row_id);
952 check.checked = do_select;
954 } else if (reset_others) {
955 selectTableRow(content.rows[i], false);
957 var row_id = content.rows[i].id.replace(prefix, "");
958 var check = $(check_prefix + row_id);
961 check.checked = false;
965 } else if (reset_others) {
966 selectTableRow(content.rows[i], false);
968 var row_id = content.rows[i].id.replace(prefix, "");
969 var check = $(check_prefix + row_id);
972 check.checked = false;
980 function getSelectedTableRowIds(content_id, prefix) {
982 var content = $(content_id);
985 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
989 var sel_rows = new Array();
991 for (i = 0; i < content.rows.length; i++) {
992 if (content.rows[i].id.match(prefix) &&
993 content.rows[i].className.match("Selected")) {
995 var row_id = content.rows[i].id.replace(prefix + "-", "");
996 sel_rows.push(row_id);
1004 function toggleSelectRowById(sender, id) {
1007 if (sender.checked) {
1008 if (!row.className.match("Selected")) {
1009 row.className = row.className + "Selected";
1012 if (row.className.match("Selected")) {
1013 row.className = row.className.replace("Selected", "");
1018 function toggleSelectListRow(sender) {
1019 var parent_row = sender.parentNode;
1021 if (sender.checked) {
1022 if (!parent_row.className.match("Selected")) {
1023 parent_row.className = parent_row.className + "Selected";
1026 if (parent_row.className.match("Selected")) {
1027 parent_row.className = parent_row.className.replace("Selected", "");
1032 function tSR(sender) {
1033 return toggleSelectRow(sender);
1036 function toggleSelectRow(sender) {
1037 var parent_row = sender.parentNode.parentNode;
1039 if (sender.checked) {
1040 if (!parent_row.className.match("Selected")) {
1041 parent_row.className = parent_row.className + "Selected";
1044 if (parent_row.className.match("Selected")) {
1045 parent_row.className = parent_row.className.replace("Selected", "");
1050 function getNextUnreadCat(id) {
1052 var rows = $("feedList").getElementsByTagName("LI");
1053 var feeds = new Array();
1055 var unread_only = true;
1058 for (var i = 0; i < rows.length; i++) {
1059 if (rows[i].id.match("FCAT-")) {
1060 if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1062 var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
1065 if (!unread_only || get_cat_unread(cat_id) > 0) {
1073 var idx = feeds.indexOf(id);
1074 if (idx != -1 && idx < feeds.length) {
1075 return feeds[idx+1];
1077 return feeds.shift();
1081 exception_error("getNextUnreadCat", e);
1085 function getRelativeFeedId2(id, is_cat, direction, unread_only) {
1088 // alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only);
1090 var rows = $("feedList").getElementsByTagName("LI");
1091 var feeds = new Array();
1093 for (var i = 0; i < rows.length; i++) {
1094 if (rows[i].id.match("FEEDR-")) {
1096 if (rows[i].id == "FEEDR-" + id && !is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1099 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1100 feeds.push(rows[i].id.replace("FEEDR-", ""));
1105 if (rows[i].id.match("FCAT-")) {
1106 if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1108 var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
1111 if (!unread_only || get_cat_unread(cat_id) > 0) {
1112 feeds.push("CAT:"+cat_id);
1119 // alert(feeds.toString());
1122 if (direction == "next") {
1123 return feeds.shift();
1128 if (direction == "next") {
1129 if (is_cat) id = "CAT:" + id;
1130 var idx = feeds.indexOf(id);
1131 if (idx != -1 && idx < feeds.length) {
1132 return feeds[idx+1];
1134 return getRelativeFeedId2(false, is_cat, direction, unread_only);
1137 if (is_cat) id = "CAT:" + id;
1138 var idx = feeds.indexOf(id);
1140 return feeds[idx-1];
1142 return getRelativeFeedId2(false, is_cat, direction, unread_only);
1149 exception_error("getRelativeFeedId2", e);
1154 function getRelativeFeedId(list, id, direction, unread_only) {
1155 var rows = list.getElementsByTagName("LI");
1156 var feeds = new Array();
1158 for (var i = 0; i < rows.length; i++) {
1159 if (rows[i].id.match("FEEDR-")) {
1161 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1164 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1165 feeds.push(rows[i].id.replace("FEEDR-", ""));
1172 if (direction == "next") {
1173 return feeds.shift();
1178 if (direction == "next") {
1179 var idx = feeds.indexOf(id);
1180 if (idx != -1 && idx < feeds.length) {
1181 return feeds[idx+1];
1183 return getRelativeFeedId(list, false, direction, unread_only);
1186 var idx = feeds.indexOf(id);
1188 return feeds[idx-1];
1190 return getRelativeFeedId(list, false, direction, unread_only);
1197 function showBlockElement(id, h_id) {
1201 elem.style.display = "block";
1206 elem.style.display = "none";
1210 alert("[showBlockElement] can't find element with id " + id);
1214 function appearBlockElement_afh(effect) {
1218 function checkboxToggleElement(elem, id) {
1220 Effect.Appear(id, {duration : 0.5});
1222 Effect.Fade(id, {duration : 0.5});
1226 function appearBlockElement(id, h_id) {
1232 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1234 exception_error("appearBlockElement", e);
1239 function hideParentElement(e) {
1240 e.parentNode.style.display = "none";
1243 function dropboxSelect(e, v) {
1244 for (i = 0; i < e.length; i++) {
1245 if (e[i].value == v) {
1246 e.selectedIndex = i;
1252 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1253 // bugfixed just a little bit :-)
1254 function getURLParam(strParamName){
1256 var strHref = window.location.href;
1258 if (strHref.indexOf("#") == strHref.length-1) {
1259 strHref = strHref.substring(0, strHref.length-1);
1262 if ( strHref.indexOf("?") > -1 ){
1263 var strQueryString = strHref.substr(strHref.indexOf("?"));
1264 var aQueryString = strQueryString.split("&");
1265 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1266 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1267 var aParam = aQueryString[iParam].split("=");
1268 strReturn = aParam[1];
1276 function leading_zero(p) {
1278 if (s.length == 1) s = "0" + s;
1282 function closeErrorBox() {
1284 if (Element.visible("errorBoxShadow")) {
1285 Element.hide("dialog_overlay");
1286 Element.hide("errorBoxShadow");
1294 function closeInfoBox(cleanup) {
1299 if (Element.visible("infoBoxShadow")) {
1300 Element.hide("dialog_overlay");
1301 Element.hide("infoBoxShadow");
1303 if (cleanup) $("infoBoxShadow").innerHTML = " ";
1306 exception_error("closeInfoBox", e);
1313 function displayDlg(id, param) {
1315 notify_progress("Loading, please wait...", true);
1319 var query = "backend.php?op=dlg&id=" +
1320 param_escape(id) + "¶m=" + param_escape(param);
1322 new Ajax.Request(query, {
1323 onComplete: function (transport) {
1324 infobox_callback2(transport);
1330 function infobox_submit_callback2(transport) {
1334 // called from prefs, reload tab
1335 if (typeof active_tab != 'undefined' && active_tab) {
1336 selectTab(active_tab, false);
1340 if (transport.responseText) {
1341 notify_info(transport.responseText);
1345 function infobox_callback2(transport) {
1348 debug("infobox_callback2");
1350 var box = $('infoBox');
1354 if (!getInitParam("infobox_disable_overlay")) {
1355 Element.show("dialog_overlay");
1358 box.innerHTML=transport.responseText;
1359 Element.show("infoBoxShadow");
1360 //Effect.SlideDown("infoBoxShadow", {duration : 1.0});
1365 /* FIXME this needs to be moved out somewhere */
1367 if ($("tags_choices")) {
1368 new Ajax.Autocompleter('tags_str', 'tags_choices',
1369 "backend.php?op=rpc&subop=completeTags",
1370 { tokens: ',', paramName: "search" });
1377 exception_error("infobox_callback2", e);
1381 function createFilter() {
1385 var form = document.forms['filter_add_form'];
1386 var reg_exp = form.reg_exp.value;
1388 if (reg_exp == "") {
1389 alert(__("Can't add filter: nothing to match on."));
1393 var query = Form.serialize("filter_add_form");
1395 // we can be called from some other tab in Prefs
1396 if (typeof active_tab != 'undefined' && active_tab) {
1397 active_tab = "filterConfig";
1400 new Ajax.Request("backend.php?" + query, {
1401 onComplete: function (transport) {
1402 infobox_submit_callback2(transport);
1408 exception_error("createFilter", e);
1412 function toggleSubmitNotEmpty(e, submit_id) {
1414 $(submit_id).disabled = (e.value == "")
1416 exception_error("toggleSubmitNotEmpty", e);
1420 function isValidURL(s) {
1421 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
1424 function subscribeToFeed() {
1426 var form = document.forms['feed_add_form'];
1427 var feed_url = form.feed_url.value;
1429 if (feed_url == "") {
1430 alert(__("Can't subscribe: no feed URL given."));
1434 notify_progress(__("Subscribing to feed..."), true);
1438 var feeds_doc = document;
1440 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1442 var query = Form.serialize("feed_add_form");
1444 debug("subscribe q: " + query);
1446 new Ajax.Request("backend.php", {
1448 onComplete: function(transport) {
1449 dlg_frefresh_callback(transport);
1455 function filterCR(e, f)
1460 key = window.event.keyCode; //IE
1462 key = e.which; //firefox
1465 if (typeof f != 'undefined') {
1476 var debug_last_class = "even";
1478 function debug(msg) {
1480 if (debug_last_class == "even") {
1481 debug_last_class = "odd";
1483 debug_last_class = "even";
1486 var c = $('debug_output');
1487 if (c && Element.visible(c)) {
1488 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1489 c.removeChild(c.lastChild);
1493 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1494 ":" + leading_zero(d.getSeconds());
1495 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1496 msg + "</li>" + c.innerHTML;
1500 function getInitParam(key) {
1501 return init_params[key];
1504 function storeInitParam(key, value) {
1505 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
1506 init_params[key] = value;
1509 function fatalError(code, msg, ext_info) {
1512 if (!ext_info) ext_info = "N/A";
1515 window.location.href = "tt-rss.php";
1516 } else if (code == 5) {
1517 window.location.href = "update.php";
1520 if (msg == "") msg = "Unknown error";
1522 var ebc = $("xebContent");
1526 Element.show("dialog_overlay");
1527 Element.show("errorBoxShadow");
1528 Element.hide("xebBtn");
1531 if (ext_info.responseText) {
1532 ext_info = ext_info.responseText;
1537 "<div><b>Error message:</b></div>" +
1538 "<pre>" + msg + "</pre>" +
1539 "<div><b>Additional information:</b></div>" +
1540 "<textarea readonly=\"1\">" + ext_info + "</textarea>";
1545 exception_error("fatalError", e);
1549 function getFeedName(id, is_cat) {
1553 e = $("FCATN-" + id);
1555 e = $("FEEDN-" + id);
1558 return e.innerHTML.stripTags();
1564 function filterDlgCheckType(sender) {
1568 var ftype = sender[sender.selectedIndex].value;
1570 var form = document.forms["filter_add_form"];
1573 form = document.forms["filter_edit_form"];
1577 debug("filterDlgCheckType: can't find form!");
1581 // if selected filter type is 5 (Date) enable the modifier dropbox
1583 Element.show("filter_dlg_date_mod_box");
1584 Element.show("filter_dlg_date_chk_box");
1586 Element.hide("filter_dlg_date_mod_box");
1587 Element.hide("filter_dlg_date_chk_box");
1592 exception_error("filterDlgCheckType", e);
1597 function filterDlgCheckAction(sender) {
1601 var action = sender[sender.selectedIndex].value;
1603 var form = document.forms["filter_add_form"];
1606 form = document.forms["filter_edit_form"];
1610 debug("filterDlgCheckAction: can't find form!");
1614 var action_param = $("filter_dlg_param_box");
1616 if (!action_param) {
1617 debug("filterDlgCheckAction: can't find action param box!");
1621 // if selected action supports parameters, enable params field
1622 if (action == 4 || action == 6 || action == 7) {
1623 Element.show(action_param);
1625 Element.show(form.action_param);
1626 Element.hide(form.action_param_label);
1628 Element.show(form.action_param_label);
1629 Element.hide(form.action_param);
1632 Element.hide(action_param);
1636 exception_error("filterDlgCheckAction", e);
1641 function filterDlgCheckDate() {
1643 var form = document.forms["filter_add_form"];
1646 form = document.forms["filter_edit_form"];
1650 debug("filterDlgCheckAction: can't find form!");
1654 var reg_exp = form.reg_exp.value;
1656 var query = "backend.php?op=rpc&subop=checkDate&date=" + reg_exp;
1658 new Ajax.Request(query, {
1659 onComplete: function(transport) {
1661 var form = document.forms["filter_add_form"];
1664 form = document.forms["filter_edit_form"];
1667 if (transport.responseXML) {
1668 var result = transport.responseXML.getElementsByTagName("result")[0];
1670 if (result && result.firstChild) {
1671 if (result.firstChild.nodeValue == "1") {
1673 new Effect.Highlight(form.reg_exp, {startcolor : '#00ff00'});
1680 new Effect.Highlight(form.reg_exp, {startcolor : '#ff0000'});
1686 exception_error("filterDlgCheckDate", e);
1690 function explainError(code) {
1691 return displayDlg("explainError", code);
1694 // this only searches loaded headlines list, not in CDM
1695 function getRelativePostIds(id, limit) {
1697 if (!limit) limit = 3;
1699 debug("getRelativePostIds: " + id + " limit=" + limit);
1701 var ids = new Array();
1702 var container = $("headlinesList");
1705 var rows = container.rows;
1707 for (var i = 0; i < rows.length; i++) {
1708 var r_id = rows[i].id.replace("RROW-", "");
1711 for (var k = 1; k <= limit; k++) {
1714 if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
1715 if (nid) ids.push(nid);
1717 if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
1718 if (nid) ids.push(nid);
1729 function openArticleInNewWindow(id) {
1731 debug("openArticleInNewWindow: " + id);
1733 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1734 var wname = "ttrss_article_" + id;
1736 debug(query + " " + wname);
1738 var w = window.open("", wname);
1740 if (!w) notify_error("Failed to open window for the article");
1742 new Ajax.Request(query, {
1743 onComplete: function(transport) {
1744 open_article_callback(transport);
1749 exception_error("openArticleInNewWindow", e);
1753 /* http://textsnippets.com/posts/show/835 */
1755 Position.GetWindowSize = function(w) {
1757 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1758 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1759 return [width, height]
1762 /* http://textsnippets.com/posts/show/836 */
1764 Position.Center = function(element, parent) {
1766 var d = Element.getDimensions(element);
1771 var ws = Position.GetWindowSize();
1775 pw = parent.offsetWidth;
1776 ph = parent.offsetHeight;
1778 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1779 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1783 function labeltest_callback(transport) {
1785 var container = $('label_test_result');
1787 container.innerHTML = transport.responseText;
1788 if (!Element.visible(container)) {
1789 Effect.SlideDown(container, { duration : 0.5 });
1794 exception_error("labeltest_callback", e);
1798 function labelTest() {
1801 var container = $('label_test_result');
1803 var form = document.forms['label_edit_form'];
1805 var sql_exp = form.sql_exp.value;
1806 var description = form.description.value;
1808 notify_progress("Loading, please wait...");
1810 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1811 param_escape(sql_exp) + "&descr=" + param_escape(description);
1813 new Ajax.Request(query, {
1814 onComplete: function (transport) {
1815 labeltest_callback(transport);
1821 exception_error("labelTest", e);
1825 function isCdmMode() {
1826 return !$("headlinesList");
1829 function getSelectedArticleIds2() {
1830 var rows = new Array();
1831 var cdm_mode = isCdmMode();
1834 rows = cdmGetSelectedArticles();
1836 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1839 var ids = new Array();
1841 for (var i = 0; i < rows.length; i++) {
1842 var chk = $("RCHK-" + rows[i]);
1843 if (chk && chk.checked) {
1851 function displayHelpInfobox(topic_id) {
1853 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1855 var w = window.open(url, "ttrss_help",
1856 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1860 function focus_element(id) {
1865 exception_error("focus_element", e);
1870 function loading_set_progress(p) {
1872 if (p < last_progress_point || !Element.visible("overlay")) return;
1874 debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
1876 var o = $("l_progress_i");
1878 // o.style.width = (p * 2) + "px";
1880 new Effect.Scale(o, p, {
1882 scaleFrom : last_progress_point,
1883 scaleMode: { originalWidth : 200 },
1884 queue: { position: 'end', scope: 'LSP-Q', limit: 3 } });
1886 last_progress_point = p;
1889 exception_error("loading_set_progress", e);
1893 function remove_splash() {
1894 if (Element.visible("overlay")) {
1895 debug("about to remove splash, OMG!");
1896 Element.hide("overlay");
1897 debug("removed splash!");
1901 function addLabelExample() {
1903 var form = document.forms["label_edit_form"];
1905 var text = form.sql_exp;
1906 var op = form.label_fields[form.label_fields.selectedIndex];
1907 var p = form.label_fields_param;
1914 if (text.value != "") {
1915 if (text.value.substring(text.value.length-3, 3).toUpperCase() != "AND") {
1922 if (op == "unread") {
1923 tmp = tmp + "unread = true";
1926 if (op == "updated") {
1927 tmp = tmp + "last_read is null and unread = false";
1930 if (op == "kw_title") {
1931 if (p.value == "") {
1932 alert("This action requires a parameter.");
1935 tmp = tmp + "ttrss_entries.title like '%"+p.value+"%'";
1938 if (op == "kw_content") {
1939 if (p.value == "") {
1940 alert("This action requires a parameter.");
1944 tmp = tmp + "ttrss_entries.content like '%"+p.value+"%'";
1947 if (op == "scoreE") {
1948 if (isNaN(parseInt(p.value))) {
1949 alert("This action expects numeric parameter.");
1952 tmp = tmp + "score = " + p.value;
1955 if (op == "scoreG") {
1956 if (isNaN(parseInt(p.value))) {
1957 alert("This action expects numeric parameter.");
1960 tmp = tmp + "score > " + p.value;
1963 if (op == "scoreL") {
1964 if (isNaN(parseInt(p.value))) {
1965 alert("This action expects numeric parameter.");
1968 tmp = tmp + "score < " + p.value;
1971 if (op == "newerD") {
1972 if (isNaN(parseInt(p.value))) {
1973 alert("This action expects numeric parameter.");
1976 tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" days'";
1979 if (op == "newerH") {
1980 if (isNaN(parseInt(p.value))) {
1981 alert("This action expects numeric parameter.");
1985 tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" hours'";
1988 text.value = text.value + tmp;
1995 exception_error("addLabelExample", e);
2001 function labelFieldsCheck(elem) {
2003 var op = elem[elem.selectedIndex].value;
2005 var p = document.forms["label_edit_form"].label_fields_param;
2007 if (op == "kw_title" || op == "kw_content" || op == "scoreL" ||
2008 op == "scoreG" || op == "scoreE" || op == "newerD" ||
2016 exception_error("labelFieldsCheck", e);
2021 function getSelectedFeedsFromBrowser() {
2023 var list = $("browseFeedList");
2024 if (!list) list = $("browseBigFeedList");
2026 var selected = new Array();
2028 for (i = 0; i < list.childNodes.length; i++) {
2029 var child = list.childNodes[i];
2030 if (child.id && child.id.match("FBROW-")) {
2031 var id = child.id.replace("FBROW-", "");
2033 var cb = $("FBCHK-" + id);
2044 function updateFeedBrowser() {
2047 var query = "backend.php?op=rpc&subop=feedBrowser";
2049 var search = $("feed_browser_search");
2050 var limit = $("feed_browser_limit");
2053 query = query + "&limit=" + limit[limit.selectedIndex].value;
2057 query = query + "&search=" + param_escape(search.value);
2060 //notify_progress("Loading, please wait...", true);
2062 Element.show('feed_browser_spinner');
2064 new Ajax.Request(query, {
2065 onComplete: function(transport) {
2068 Element.hide('feed_browser_spinner');
2070 var c = $("browseFeedList");
2071 var r = transport.responseXML.getElementsByTagName("content")[0];
2072 var nr = transport.responseXML.getElementsByTagName("num-results")[0];
2073 var sb = $("feed_browser_subscribe");
2076 c.innerHTML = r.firstChild.nodeValue;
2080 if (nr.getAttribute("value") > 0) {
2081 sb.disabled = false;
2091 exception_error("updateFeedBrowser", e);
2095 function browseFeeds(limit) {
2099 var query = "backend.php?op=pref-feeds&subop=browse";
2101 notify_progress("Loading, please wait...", true);
2103 new Ajax.Request(query, {
2104 onComplete: function(transport) {
2105 infobox_callback2(transport);
2110 exception_error("browseFeeds", e);
2114 function transport_error_check(transport) {
2116 if (transport.responseXML) {
2117 var error = transport.responseXML.getElementsByTagName("error")[0];
2120 var code = error.getAttribute("error-code");
2121 var msg = error.getAttribute("error-msg");
2123 fatalError(code, msg);
2129 exception_error("check_for_error_xml", e);
2134 function strip_tags(s) {
2135 return s.replace(/<\/?[^>]+(>|$)/g, "");
2138 function truncate_string(s, length) {
2139 if (!length) length = 30;
2140 var tmp = s.substring(0, length);
2141 if (s.length > length) tmp += "…";
2146 function switchToFlash(e) {
2149 if (!e) var e = window.event;
2150 if (e.target) targ = e.target;
2151 else if (e.srcElement) targ = e.srcElement;
2152 if (targ.nodeType == 3) // defeat Safari bug
2153 targ = targ.parentNode;
2155 //targ is the link that was clicked
2158 audioTag=audioTag.previousSibling;
2159 } while(audioTag && audioTag.nodeType != 1)
2161 var flashPlayer = audioTag.getElementsByTagName('span')[0];
2162 targ.parentNode.insertBefore(flashPlayer,targ);
2163 targ.parentNode.removeChild(targ);
2164 audioTag.parentNode.removeChild(audioTag);
2168 exception_error("switchToFlash", e);
2172 function html5AudioOrFlash(type) {
2173 var audioTag = document.createElement('audio');
2174 if(! audioTag.canPlayType || audioTag.canPlayType(type) == "no" ||
2175 audioTag.canPlayType(type) == ""){
2176 if($('switchToFlashLink')){
2177 switchToFlash($('switchToFlashLink'));
2182 function hotkey_prefix_timeout() {
2185 var date = new Date();
2186 var ts = Math.round(date.getTime() / 1000);
2188 if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) {
2189 debug("hotkey_prefix seems to be stuck, aborting");
2190 hotkey_prefix_pressed = false;
2191 hotkey_prefix = false;
2192 Element.hide('cmdline');
2195 setTimeout("hotkey_prefix_timeout()", 1000);
2198 exception_error("hotkey_prefix_timeout", e);
2202 function hideAuxDlg() {
2204 Element.hide('auxDlg');
2206 exception_error("hideAuxDlg", e);
2210 function displayNewContentPrompt(id) {
2212 var msg = __("New articles in «%s».") +
2213 " <a href='#' onclick='viewfeed("+id+")'>" + __('Click to view') + "</a>.";
2215 msg = msg.replace("%s", getFeedName(id));
2217 $('auxDlg').innerHTML = msg;
2219 Element.show('auxDlg');
2222 exception_error("displayNewContentPrompt", e);