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 (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
538 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
540 feedu.innerHTML = ctr;
543 feedr.className = feedr.className.replace("feed", "error");
545 feedr.className = feedr.className.replace("error", "feed");
549 feedctr.className = "feedCtrHasUnread";
550 if (!feedr.className.match("Unread")) {
551 var is_selected = feedr.className.match("Selected");
553 feedr.className = feedr.className.replace("Selected", "");
554 feedr.className = feedr.className.replace("Unread", "");
556 feedr.className = feedr.className + "Unread";
559 feedr.className = feedr.className + "Selected";
565 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
566 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
569 feedctr.className = "feedCtrNoUnread";
570 feedr.className = feedr.className.replace("Unread", "");
575 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
577 var feeds_stored = number_of_feeds;
579 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
581 if (feeds_stored != feeds_found) {
582 number_of_feeds = feeds_found;
584 if (feeds_stored != 0 && feeds_found != 0) {
585 debug("Subscribed feed number changed, refreshing feedlist");
586 setTimeout('updateFeedList(false, false)', 50);
589 /* var fl = $("feeds-frame").innerHTML;
591 cache_invalidate("FEEDLIST");
592 cache_inject("FEEDLIST", fl, getInitParam("num_feeds"));
597 exception_error("parse_counters", e);
601 function parse_counters_reply(transport, scheduled_call) {
603 if (!transport.responseXML) {
604 notify_error("Backend did not return valid XML", true);
608 var reply = transport.responseXML.firstChild;
611 notify_error("Backend did not return expected XML object", true);
616 if (!transport_error_check(transport)) return;
618 var counters = reply.getElementsByTagName("counters")[0];
620 parse_counters(counters, scheduled_call);
622 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
624 parse_runtime_info(runtime_info);
626 if (feedsSortByUnread()) {
630 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
634 function all_counters_callback2(transport, async_call) {
636 if (async_call) async_counters_work = true;
638 if (offline_mode) return;
640 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
641 parse_counters_reply(transport);
642 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
645 exception_error("all_counters_callback2", e, transport);
649 function get_feed_unread(id) {
651 return parseInt($("FEEDU-" + id).innerHTML);
657 function get_cat_unread(id) {
659 var ctr = $("FCATCTR-" + id).innerHTML;
660 ctr = ctr.replace("(", "");
661 ctr = ctr.replace(")", "");
662 return parseInt(ctr);
668 function get_feed_entry_unread(elem) {
670 var id = elem.id.replace("FEEDR-", "");
677 return parseInt($("FEEDU-" + id).innerHTML);
683 function get_feed_entry_name(elem) {
684 var id = elem.id.replace("FEEDR-", "");
685 return getFeedName(id);
689 function resort_category(node) {
693 debug("resort_category: " + node);
695 var by_unread = feedsSortByUnread();
697 var list = node.getElementsByTagName("LI");
699 for (i = 0; i < list.length; i++) {
701 for (j = i+1; j < list.length; j++) {
703 var tmp_val = get_feed_entry_unread(list[i]);
704 var cur_val = get_feed_entry_unread(list[j]);
706 var tmp_name = get_feed_entry_name(list[i]);
707 var cur_name = get_feed_entry_name(list[j]);
709 if ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name))) {
710 tempnode_i = list[i].cloneNode(true);
711 tempnode_j = list[j].cloneNode(true);
712 node.replaceChild(tempnode_i, list[j]);
713 node.replaceChild(tempnode_j, list[i]);
719 exception_error("resort_category", e);
724 function resort_feedlist() {
725 debug("resort_feedlist");
727 if ($("FCATLIST--1")) {
729 var lists = document.getElementsByTagName("UL");
731 for (var i = 0; i < lists.length; i++) {
732 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
733 resort_category(lists[i]);
738 resort_category($("feedList"));
742 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
743 * * @author Sundar Dorai-Raj
744 * * Email: sdoraira@vt.edu
745 * * This program is free software; you can redistribute it and/or
746 * * modify it under the terms of the GNU General Public License
747 * * as published by the Free Software Foundation; either version 2
748 * * of the License, or (at your option) any later version,
749 * * provided that any use properly credits the author.
750 * * This program is distributed in the hope that it will be useful,
751 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
752 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
753 * * GNU General Public License for more details at http://www.gnu.org * * */
755 var numbers=".0123456789";
756 function isNumeric(x) {
757 // is x a String or a character?
759 // remove negative sign
761 for(j=0;j<x.length;j++) {
762 // call isNumeric recursively for each character
763 number=isNumeric(x.substring(j,j+1));
764 if(!number) return number;
769 // if x is number return true
770 if(numbers.indexOf(x)>=0) return true;
776 function hideOrShowFeeds(hide) {
780 debug("hideOrShowFeeds: " + hide);
782 if ($("FCATLIST--1")) {
784 var lists = document.getElementsByTagName("UL");
786 for (var i = 0; i < lists.length; i++) {
787 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
789 var id = lists[i].id.replace("FCATLIST-", "");
790 hideOrShowFeedsCategory(id, hide);
795 hideOrShowFeedsCategory(null, hide);
799 exception_error("hideOrShowFeeds", e);
803 function hideOrShowFeedsCategory(id, hide) {
811 node = $("FCATLIST-" + id);
812 cat_node = $("FCAT-" + id);
814 node = $("feedList"); // no categories
817 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
822 debug("hideOrShowFeeds: passed node is null, aborting");
826 // debug("cat: " + node.id);
828 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
829 for (i = 0; i < node.childNodes.length; i++) {
830 if (node.childNodes[i].nodeName != "LI") { continue; }
832 if (node.childNodes[i].style != undefined) {
834 var has_unread = (node.childNodes[i].className != "feed" &&
835 node.childNodes[i].className != "label" &&
836 !(!getInitParam("hide_read_shows_special") &&
837 node.childNodes[i].className == "virt") &&
838 node.childNodes[i].className != "error" &&
839 node.childNodes[i].className != "tag");
841 // debug(node.childNodes[i].id + " --> " + has_unread);
843 if (hide && !has_unread) {
844 //node.childNodes[i].style.display = "none";
845 var id = node.childNodes[i].id;
846 Effect.Fade(node.childNodes[i], {duration : 0.3,
847 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
851 node.childNodes[i].style.display = "list-item";
852 //Effect.Appear(node.childNodes[i], {duration : 0.3});
856 node.childNodes[i].style.display = "list-item";
858 //Effect.Appear(node.childNodes[i], {duration : 0.3});
859 //Effect.Highlight(node.childNodes[i]);
865 // debug("end cat: " + node.id + " unread " + cat_unread);
869 if (cat_unread == 0) {
870 if (cat_node.style == undefined) {
871 debug("ERROR: supplied cat_node " + cat_node +
872 " has no styles. WTF?");
876 //cat_node.style.display = "none";
877 Effect.Fade(cat_node, {duration : 0.3,
878 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
880 cat_node.style.display = "list-item";
884 cat_node.style.display = "list-item";
891 // debug("unread for category: " + cat_unread);
894 exception_error("hideOrShowFeedsCategory", e);
898 function selectTableRow(r, do_select) {
899 r.className = r.className.replace("Selected", "");
902 r.className = r.className + "Selected";
906 function selectTableRowById(elem_id, check_id, do_select) {
910 var row = $(elem_id);
913 selectTableRow(row, do_select);
916 var check = $(check_id);
919 check.checked = do_select;
922 exception_error("selectTableRowById", e);
926 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
927 classcheck, reset_others) {
929 var content = $(content_id);
932 alert("[selectTableRows] Element " + content_id + " not found.");
936 for (i = 0; i < content.rows.length; i++) {
937 if (Element.visible(content.rows[i])) {
938 if (!classcheck || content.rows[i].className.match(classcheck)) {
940 if (content.rows[i].id.match(prefix)) {
941 selectTableRow(content.rows[i], do_select);
943 var row_id = content.rows[i].id.replace(prefix, "");
944 var check = $(check_prefix + row_id);
947 check.checked = do_select;
949 } else if (reset_others) {
950 selectTableRow(content.rows[i], false);
952 var row_id = content.rows[i].id.replace(prefix, "");
953 var check = $(check_prefix + row_id);
956 check.checked = false;
960 } else if (reset_others) {
961 selectTableRow(content.rows[i], false);
963 var row_id = content.rows[i].id.replace(prefix, "");
964 var check = $(check_prefix + row_id);
967 check.checked = false;
975 function getSelectedTableRowIds(content_id, prefix) {
977 var content = $(content_id);
980 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
984 var sel_rows = new Array();
986 for (i = 0; i < content.rows.length; i++) {
987 if (content.rows[i].id.match(prefix) &&
988 content.rows[i].className.match("Selected")) {
990 var row_id = content.rows[i].id.replace(prefix + "-", "");
991 sel_rows.push(row_id);
999 function toggleSelectRowById(sender, id) {
1002 if (sender.checked) {
1003 if (!row.className.match("Selected")) {
1004 row.className = row.className + "Selected";
1007 if (row.className.match("Selected")) {
1008 row.className = row.className.replace("Selected", "");
1013 function toggleSelectListRow(sender) {
1014 var parent_row = sender.parentNode;
1016 if (sender.checked) {
1017 if (!parent_row.className.match("Selected")) {
1018 parent_row.className = parent_row.className + "Selected";
1021 if (parent_row.className.match("Selected")) {
1022 parent_row.className = parent_row.className.replace("Selected", "");
1027 function tSR(sender) {
1028 return toggleSelectRow(sender);
1031 function toggleSelectRow(sender) {
1032 var parent_row = sender.parentNode.parentNode;
1034 if (sender.checked) {
1035 if (!parent_row.className.match("Selected")) {
1036 parent_row.className = parent_row.className + "Selected";
1039 if (parent_row.className.match("Selected")) {
1040 parent_row.className = parent_row.className.replace("Selected", "");
1045 function getNextUnreadCat(id) {
1047 var rows = $("feedList").getElementsByTagName("LI");
1048 var feeds = new Array();
1050 var unread_only = true;
1053 for (var i = 0; i < rows.length; i++) {
1054 if (rows[i].id.match("FCAT-")) {
1055 if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1057 var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
1060 if (!unread_only || get_cat_unread(cat_id) > 0) {
1068 var idx = feeds.indexOf(id);
1069 if (idx != -1 && idx < feeds.length) {
1070 return feeds[idx+1];
1072 return feeds.shift();
1076 exception_error("getNextUnreadCat", e);
1080 function getRelativeFeedId2(id, is_cat, direction, unread_only) {
1083 // alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only);
1085 var rows = $("feedList").getElementsByTagName("LI");
1086 var feeds = new Array();
1088 for (var i = 0; i < rows.length; i++) {
1089 if (rows[i].id.match("FEEDR-")) {
1091 if (rows[i].id == "FEEDR-" + id && !is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1094 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1095 feeds.push(rows[i].id.replace("FEEDR-", ""));
1100 if (rows[i].id.match("FCAT-")) {
1101 if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1103 var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
1106 if (!unread_only || get_cat_unread(cat_id) > 0) {
1107 feeds.push("CAT:"+cat_id);
1114 // alert(feeds.toString());
1117 if (direction == "next") {
1118 return feeds.shift();
1123 if (direction == "next") {
1124 if (is_cat) id = "CAT:" + id;
1125 var idx = feeds.indexOf(id);
1126 if (idx != -1 && idx < feeds.length) {
1127 return feeds[idx+1];
1129 return getRelativeFeedId2(false, is_cat, direction, unread_only);
1132 if (is_cat) id = "CAT:" + id;
1133 var idx = feeds.indexOf(id);
1135 return feeds[idx-1];
1137 return getRelativeFeedId2(false, is_cat, direction, unread_only);
1144 exception_error("getRelativeFeedId2", e);
1149 function getRelativeFeedId(list, id, direction, unread_only) {
1150 var rows = list.getElementsByTagName("LI");
1151 var feeds = new Array();
1153 for (var i = 0; i < rows.length; i++) {
1154 if (rows[i].id.match("FEEDR-")) {
1156 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1159 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1160 feeds.push(rows[i].id.replace("FEEDR-", ""));
1167 if (direction == "next") {
1168 return feeds.shift();
1173 if (direction == "next") {
1174 var idx = feeds.indexOf(id);
1175 if (idx != -1 && idx < feeds.length) {
1176 return feeds[idx+1];
1178 return getRelativeFeedId(list, false, direction, unread_only);
1181 var idx = feeds.indexOf(id);
1183 return feeds[idx-1];
1185 return getRelativeFeedId(list, false, direction, unread_only);
1192 function showBlockElement(id, h_id) {
1196 elem.style.display = "block";
1201 elem.style.display = "none";
1205 alert("[showBlockElement] can't find element with id " + id);
1209 function appearBlockElement_afh(effect) {
1213 function checkboxToggleElement(elem, id) {
1215 Effect.Appear(id, {duration : 0.5});
1217 Effect.Fade(id, {duration : 0.5});
1221 function appearBlockElement(id, h_id) {
1227 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1229 exception_error("appearBlockElement", e);
1234 function hideParentElement(e) {
1235 e.parentNode.style.display = "none";
1238 function dropboxSelect(e, v) {
1239 for (i = 0; i < e.length; i++) {
1240 if (e[i].value == v) {
1241 e.selectedIndex = i;
1247 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1248 // bugfixed just a little bit :-)
1249 function getURLParam(strParamName){
1251 var strHref = window.location.href;
1253 if (strHref.indexOf("#") == strHref.length-1) {
1254 strHref = strHref.substring(0, strHref.length-1);
1257 if ( strHref.indexOf("?") > -1 ){
1258 var strQueryString = strHref.substr(strHref.indexOf("?"));
1259 var aQueryString = strQueryString.split("&");
1260 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1261 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1262 var aParam = aQueryString[iParam].split("=");
1263 strReturn = aParam[1];
1271 function leading_zero(p) {
1273 if (s.length == 1) s = "0" + s;
1277 function closeErrorBox() {
1279 if (Element.visible("errorBoxShadow")) {
1280 Element.hide("dialog_overlay");
1281 Element.hide("errorBoxShadow");
1289 function closeInfoBox(cleanup) {
1291 if (Element.visible("infoBoxShadow")) {
1292 Element.hide("dialog_overlay");
1294 var shadow = $('infoBoxShadow');
1295 var box = $('infoBoxShadow');
1297 Element.hide(shadow);
1299 if (cleanup) box.innerHTML = " ";
1308 function displayDlg(id, param) {
1310 notify_progress("Loading, please wait...", true);
1314 var query = "backend.php?op=dlg&id=" +
1315 param_escape(id) + "¶m=" + param_escape(param);
1317 new Ajax.Request(query, {
1318 onComplete: function (transport) {
1319 infobox_callback2(transport);
1325 function infobox_submit_callback2(transport) {
1329 // called from prefs, reload tab
1330 if (typeof active_tab != 'undefined' && active_tab) {
1331 selectTab(active_tab, false);
1335 if (transport.responseText) {
1336 notify_info(transport.responseText);
1340 function infobox_callback2(transport) {
1343 debug("infobox_callback2");
1345 if (!getInitParam("infobox_disable_overlay")) {
1346 Element.show("dialog_overlay");
1349 var box = $('infoBox');
1350 var shadow = $('infoBoxShadow');
1353 box.innerHTML=transport.responseText;
1355 shadow.style.display = "block";
1357 box.style.display = "block";
1361 /* FIXME this needs to be moved out somewhere */
1363 if ($("tags_choices")) {
1364 new Ajax.Autocompleter('tags_str', 'tags_choices',
1365 "backend.php?op=rpc&subop=completeTags",
1366 { tokens: ',', paramName: "search" });
1373 exception_error("infobox_callback2", e);
1377 function createFilter() {
1381 var form = document.forms['filter_add_form'];
1382 var reg_exp = form.reg_exp.value;
1384 if (reg_exp == "") {
1385 alert(__("Can't add filter: nothing to match on."));
1389 var query = Form.serialize("filter_add_form");
1391 // we can be called from some other tab in Prefs
1392 if (typeof active_tab != 'undefined' && active_tab) {
1393 active_tab = "filterConfig";
1396 new Ajax.Request("backend.php?" + query, {
1397 onComplete: function (transport) {
1398 infobox_submit_callback2(transport);
1404 exception_error("createFilter", e);
1408 function toggleSubmitNotEmpty(e, submit_id) {
1410 $(submit_id).disabled = (e.value == "")
1412 exception_error("toggleSubmitNotEmpty", e);
1416 function isValidURL(s) {
1417 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
1420 function subscribeToFeed() {
1422 var form = document.forms['feed_add_form'];
1423 var feed_url = form.feed_url.value;
1425 if (feed_url == "") {
1426 alert(__("Can't subscribe: no feed URL given."));
1430 notify_progress(__("Subscribing to feed..."), true);
1434 var feeds_doc = document;
1436 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1438 var query = Form.serialize("feed_add_form");
1440 debug("subscribe q: " + query);
1442 new Ajax.Request("backend.php", {
1444 onComplete: function(transport) {
1445 dlg_frefresh_callback(transport);
1451 function filterCR(e, f)
1456 key = window.event.keyCode; //IE
1458 key = e.which; //firefox
1461 if (typeof f != 'undefined') {
1472 var debug_last_class = "even";
1474 function debug(msg) {
1476 if (debug_last_class == "even") {
1477 debug_last_class = "odd";
1479 debug_last_class = "even";
1482 var c = $('debug_output');
1483 if (c && Element.visible(c)) {
1484 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1485 c.removeChild(c.lastChild);
1489 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1490 ":" + leading_zero(d.getSeconds());
1491 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1492 msg + "</li>" + c.innerHTML;
1496 function getInitParam(key) {
1497 return init_params[key];
1500 function storeInitParam(key, value) {
1501 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
1502 init_params[key] = value;
1505 function fatalError(code, msg, ext_info) {
1508 if (!ext_info) ext_info = "N/A";
1511 window.location.href = "tt-rss.php";
1512 } else if (code == 5) {
1513 window.location.href = "update.php";
1516 if (msg == "") msg = "Unknown error";
1518 var ebc = $("xebContent");
1522 Element.show("dialog_overlay");
1523 Element.show("errorBoxShadow");
1524 Element.hide("xebBtn");
1527 if (ext_info.responseText) {
1528 ext_info = ext_info.responseText;
1533 "<div><b>Error message:</b></div>" +
1534 "<pre>" + msg + "</pre>" +
1535 "<div><b>Additional information:</b></div>" +
1536 "<textarea readonly=\"1\">" + ext_info + "</textarea>";
1541 exception_error("fatalError", e);
1545 function getFeedName(id, is_cat) {
1549 e = $("FCATN-" + id);
1551 e = $("FEEDN-" + id);
1554 return e.innerHTML.stripTags();
1560 function filterDlgCheckType(sender) {
1564 var ftype = sender[sender.selectedIndex].value;
1566 var form = document.forms["filter_add_form"];
1569 form = document.forms["filter_edit_form"];
1573 debug("filterDlgCheckType: can't find form!");
1577 // if selected filter type is 5 (Date) enable the modifier dropbox
1579 Element.show("filter_dlg_date_mod_box");
1580 Element.show("filter_dlg_date_chk_box");
1582 Element.hide("filter_dlg_date_mod_box");
1583 Element.hide("filter_dlg_date_chk_box");
1588 exception_error("filterDlgCheckType", e);
1593 function filterDlgCheckAction(sender) {
1597 var action = sender[sender.selectedIndex].value;
1599 var form = document.forms["filter_add_form"];
1602 form = document.forms["filter_edit_form"];
1606 debug("filterDlgCheckAction: can't find form!");
1610 var action_param = $("filter_dlg_param_box");
1612 if (!action_param) {
1613 debug("filterDlgCheckAction: can't find action param box!");
1617 // if selected action supports parameters, enable params field
1618 if (action == 4 || action == 6 || action == 7) {
1619 Element.show(action_param);
1621 Element.show(form.action_param);
1622 Element.hide(form.action_param_label);
1624 Element.show(form.action_param_label);
1625 Element.hide(form.action_param);
1628 Element.hide(action_param);
1632 exception_error("filterDlgCheckAction", e);
1637 function filterDlgCheckDate() {
1639 var form = document.forms["filter_add_form"];
1642 form = document.forms["filter_edit_form"];
1646 debug("filterDlgCheckAction: can't find form!");
1650 var reg_exp = form.reg_exp.value;
1652 var query = "backend.php?op=rpc&subop=checkDate&date=" + reg_exp;
1654 new Ajax.Request(query, {
1655 onComplete: function(transport) {
1657 var form = document.forms["filter_add_form"];
1660 form = document.forms["filter_edit_form"];
1663 if (transport.responseXML) {
1664 var result = transport.responseXML.getElementsByTagName("result")[0];
1666 if (result && result.firstChild) {
1667 if (result.firstChild.nodeValue == "1") {
1669 new Effect.Highlight(form.reg_exp, {startcolor : '#00ff00'});
1676 new Effect.Highlight(form.reg_exp, {startcolor : '#ff0000'});
1682 exception_error("filterDlgCheckDate", e);
1686 function explainError(code) {
1687 return displayDlg("explainError", code);
1690 // this only searches loaded headlines list, not in CDM
1691 function getRelativePostIds(id, limit) {
1693 if (!limit) limit = 3;
1695 debug("getRelativePostIds: " + id + " limit=" + limit);
1697 var ids = new Array();
1698 var container = $("headlinesList");
1701 var rows = container.rows;
1703 for (var i = 0; i < rows.length; i++) {
1704 var r_id = rows[i].id.replace("RROW-", "");
1707 for (var k = 1; k <= limit; k++) {
1710 if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
1711 if (nid) ids.push(nid);
1713 if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
1714 if (nid) ids.push(nid);
1725 function openArticleInNewWindow(id) {
1727 debug("openArticleInNewWindow: " + id);
1729 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1730 var wname = "ttrss_article_" + id;
1732 debug(query + " " + wname);
1734 var w = window.open("", wname);
1736 if (!w) notify_error("Failed to open window for the article");
1738 new Ajax.Request(query, {
1739 onComplete: function(transport) {
1740 open_article_callback(transport);
1745 exception_error("openArticleInNewWindow", e);
1749 /* http://textsnippets.com/posts/show/835 */
1751 Position.GetWindowSize = function(w) {
1753 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1754 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1755 return [width, height]
1758 /* http://textsnippets.com/posts/show/836 */
1760 Position.Center = function(element, parent) {
1762 var d = Element.getDimensions(element);
1767 var ws = Position.GetWindowSize();
1771 pw = parent.offsetWidth;
1772 ph = parent.offsetHeight;
1774 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1775 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1779 function labeltest_callback(transport) {
1781 var container = $('label_test_result');
1783 container.innerHTML = transport.responseText;
1784 if (!Element.visible(container)) {
1785 Effect.SlideDown(container, { duration : 0.5 });
1790 exception_error("labeltest_callback", e);
1794 function labelTest() {
1797 var container = $('label_test_result');
1799 var form = document.forms['label_edit_form'];
1801 var sql_exp = form.sql_exp.value;
1802 var description = form.description.value;
1804 notify_progress("Loading, please wait...");
1806 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1807 param_escape(sql_exp) + "&descr=" + param_escape(description);
1809 new Ajax.Request(query, {
1810 onComplete: function (transport) {
1811 labeltest_callback(transport);
1817 exception_error("labelTest", e);
1821 function isCdmMode() {
1822 return !$("headlinesList");
1825 function getSelectedArticleIds2() {
1826 var rows = new Array();
1827 var cdm_mode = isCdmMode();
1830 rows = cdmGetSelectedArticles();
1832 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1835 var ids = new Array();
1837 for (var i = 0; i < rows.length; i++) {
1838 var chk = $("RCHK-" + rows[i]);
1839 if (chk && chk.checked) {
1847 function displayHelpInfobox(topic_id) {
1849 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1851 var w = window.open(url, "ttrss_help",
1852 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1856 function focus_element(id) {
1861 exception_error("focus_element", e);
1866 function loading_set_progress(p) {
1868 if (p < last_progress_point || !Element.visible("overlay")) return;
1870 debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
1872 var o = $("l_progress_i");
1874 // o.style.width = (p * 2) + "px";
1876 new Effect.Scale(o, p, {
1878 scaleFrom : last_progress_point,
1879 scaleMode: { originalWidth : 200 },
1880 queue: { position: 'end', scope: 'LSP-Q', limit: 3 } });
1882 last_progress_point = p;
1885 exception_error("loading_set_progress", e);
1889 function remove_splash() {
1890 if (Element.visible("overlay")) {
1891 debug("about to remove splash, OMG!");
1892 Element.hide("overlay");
1893 debug("removed splash!");
1897 function addLabelExample() {
1899 var form = document.forms["label_edit_form"];
1901 var text = form.sql_exp;
1902 var op = form.label_fields[form.label_fields.selectedIndex];
1903 var p = form.label_fields_param;
1910 if (text.value != "") {
1911 if (text.value.substring(text.value.length-3, 3).toUpperCase() != "AND") {
1918 if (op == "unread") {
1919 tmp = tmp + "unread = true";
1922 if (op == "updated") {
1923 tmp = tmp + "last_read is null and unread = false";
1926 if (op == "kw_title") {
1927 if (p.value == "") {
1928 alert("This action requires a parameter.");
1931 tmp = tmp + "ttrss_entries.title like '%"+p.value+"%'";
1934 if (op == "kw_content") {
1935 if (p.value == "") {
1936 alert("This action requires a parameter.");
1940 tmp = tmp + "ttrss_entries.content like '%"+p.value+"%'";
1943 if (op == "scoreE") {
1944 if (isNaN(parseInt(p.value))) {
1945 alert("This action expects numeric parameter.");
1948 tmp = tmp + "score = " + p.value;
1951 if (op == "scoreG") {
1952 if (isNaN(parseInt(p.value))) {
1953 alert("This action expects numeric parameter.");
1956 tmp = tmp + "score > " + p.value;
1959 if (op == "scoreL") {
1960 if (isNaN(parseInt(p.value))) {
1961 alert("This action expects numeric parameter.");
1964 tmp = tmp + "score < " + p.value;
1967 if (op == "newerD") {
1968 if (isNaN(parseInt(p.value))) {
1969 alert("This action expects numeric parameter.");
1972 tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" days'";
1975 if (op == "newerH") {
1976 if (isNaN(parseInt(p.value))) {
1977 alert("This action expects numeric parameter.");
1981 tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" hours'";
1984 text.value = text.value + tmp;
1991 exception_error("addLabelExample", e);
1997 function labelFieldsCheck(elem) {
1999 var op = elem[elem.selectedIndex].value;
2001 var p = document.forms["label_edit_form"].label_fields_param;
2003 if (op == "kw_title" || op == "kw_content" || op == "scoreL" ||
2004 op == "scoreG" || op == "scoreE" || op == "newerD" ||
2012 exception_error("labelFieldsCheck", e);
2017 function getSelectedFeedsFromBrowser() {
2019 var list = $("browseFeedList");
2020 if (!list) list = $("browseBigFeedList");
2022 var selected = new Array();
2024 for (i = 0; i < list.childNodes.length; i++) {
2025 var child = list.childNodes[i];
2026 if (child.id && child.id.match("FBROW-")) {
2027 var id = child.id.replace("FBROW-", "");
2029 var cb = $("FBCHK-" + id);
2040 function updateFeedBrowser() {
2043 var query = "backend.php?op=rpc&subop=feedBrowser";
2045 var search = $("feed_browser_search");
2046 var limit = $("feed_browser_limit");
2049 query = query + "&limit=" + limit[limit.selectedIndex].value;
2053 query = query + "&search=" + param_escape(search.value);
2056 notify_progress("Loading, please wait...", true);
2058 new Ajax.Request(query, {
2059 onComplete: function(transport) {
2062 var c = $("browseFeedList");
2063 var r = transport.responseXML.getElementsByTagName("content")[0];
2064 var nr = transport.responseXML.getElementsByTagName("num-results")[0];
2065 var sb = $("feed_browser_subscribe");
2068 c.innerHTML = r.firstChild.nodeValue;
2072 if (nr.getAttribute("value") > 0) {
2073 sb.disabled = false;
2083 exception_error("updateFeedBrowser", e);
2087 function browseFeeds(limit) {
2091 var query = "backend.php?op=pref-feeds&subop=browse";
2093 notify_progress("Loading, please wait...", true);
2095 new Ajax.Request(query, {
2096 onComplete: function(transport) {
2097 infobox_callback2(transport);
2102 exception_error("browseFeeds", e);
2106 function transport_error_check(transport) {
2108 if (transport.responseXML) {
2109 var error = transport.responseXML.getElementsByTagName("error")[0];
2112 var code = error.getAttribute("error-code");
2113 var msg = error.getAttribute("error-msg");
2115 fatalError(code, msg);
2121 exception_error("check_for_error_xml", e);
2126 function strip_tags(s) {
2127 return s.replace(/<\/?[^>]+(>|$)/g, "");
2130 function truncate_string(s, length) {
2131 if (!length) length = 30;
2132 var tmp = s.substring(0, length);
2133 if (s.length > length) tmp += "…";
2138 function switchToFlash(e) {
2141 if (!e) var e = window.event;
2142 if (e.target) targ = e.target;
2143 else if (e.srcElement) targ = e.srcElement;
2144 if (targ.nodeType == 3) // defeat Safari bug
2145 targ = targ.parentNode;
2147 //targ is the link that was clicked
2150 audioTag=audioTag.previousSibling;
2151 } while(audioTag && audioTag.nodeType != 1)
2153 var flashPlayer = audioTag.getElementsByTagName('span')[0];
2154 targ.parentNode.insertBefore(flashPlayer,targ);
2155 targ.parentNode.removeChild(targ);
2156 audioTag.parentNode.removeChild(audioTag);
2160 exception_error("switchToFlash", e);
2164 function html5AudioOrFlash(type) {
2165 var audioTag = document.createElement('audio');
2166 if(! audioTag.canPlayType || audioTag.canPlayType(type) == "no" ||
2167 audioTag.canPlayType(type) == ""){
2168 if($('switchToFlashLink')){
2169 switchToFlash($('switchToFlashLink'));