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(transport) {
70 if (transport.responseXML) {
71 var link = transport.responseXML.getElementsByTagName("link")[0];
72 var id = transport.responseXML.getElementsByTagName("id")[0];
75 window.open(link.firstChild.nodeValue, "_blank");
78 id = id.firstChild.nodeValue;
79 if (!document.getElementById("headlinesList")) {
80 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
87 exception_error("open_article_callback", e);
91 function param_escape(arg) {
92 if (typeof encodeURIComponent != 'undefined')
93 return encodeURIComponent(arg);
98 function param_unescape(arg) {
99 if (typeof decodeURIComponent != 'undefined')
100 return decodeURIComponent(arg);
102 return unescape(arg);
105 function delay(gap) {
107 then=new Date().getTime();
109 while((now-then)<gap) {
110 now=new Date().getTime();
114 var notify_hide_timerid = false;
116 function hide_notify() {
117 var n = document.getElementById("notify");
119 n.style.display = "none";
123 function notify_real(msg, no_hide, n_type) {
125 var n = document.getElementById("notify");
126 var nb = document.getElementById("notify_body");
128 if (!n || !nb) return;
130 if (notify_hide_timerid) {
131 window.clearTimeout(notify_hide_timerid);
135 if (n.style.display == "block") {
136 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
140 n.style.display = "block";
152 if (typeof __ != 'undefined') {
157 n.className = "notify";
158 } else if (n_type == 2) {
159 n.className = "notifyProgress";
160 msg = "<img src='images/indicator_white.gif'> " + msg;
161 } else if (n_type == 3) {
162 n.className = "notifyError";
163 msg = "<img src='images/sign_excl.gif'> " + msg;
164 } else if (n_type == 4) {
165 n.className = "notifyInfo";
166 msg = "<img src='images/sign_info.gif'> " + msg;
169 // msg = "<img src='images/live_com_loading.gif'> " + msg;
174 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
178 function notify(msg, no_hide) {
179 notify_real(msg, no_hide, 1);
182 function notify_progress(msg, no_hide) {
183 notify_real(msg, no_hide, 2);
186 function notify_error(msg, no_hide) {
187 notify_real(msg, no_hide, 3);
191 function notify_info(msg, no_hide) {
192 notify_real(msg, no_hide, 4);
195 function printLockingError() {
196 notify_info("Please wait until operation finishes.");
199 function hotkey_handler(e) {
204 var shift_key = false;
207 shift_key = e.shiftKey;
212 if (!hotkeys_enabled) {
213 debug("hotkeys disabled");
218 keycode = window.event.keyCode;
223 if (keycode == 82) { // r
224 return scheduleFeedUpdate(true);
227 if (keycode == 83) { // s
228 return displayDlg("search", getActiveFeedId());
231 if (keycode == 85) { // u
232 if (getActiveFeedId()) {
233 return viewfeed(getActiveFeedId(), "ForceUpdate");
237 if (keycode == 65) { // a
238 return toggleDispRead();
241 var feedlist = document.getElementById('feedList');
243 if (keycode == 74) { // j
244 var feed = getActiveFeedId();
245 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
246 if (new_feed) viewfeed(new_feed, '');
249 if (keycode == 75) { // k
250 var feed = getActiveFeedId();
251 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
252 if (new_feed) viewfeed(new_feed, '');
255 if (keycode == 78 || keycode == 40) { // n, down
256 if (typeof moveToPost != 'undefined') {
257 return moveToPost('next');
261 if (keycode == 80 || keycode == 38) { // p, up
262 if (typeof moveToPost != 'undefined') {
263 return moveToPost('prev');
267 if (keycode == 68 && shift_key) { // d
268 if (!debug_mode_enabled) {
269 document.getElementById('debug_output').style.display = 'block';
270 debug('debug mode activated');
272 document.getElementById('debug_output').style.display = 'none';
275 debug_mode_enabled = !debug_mode_enabled;
278 if (keycode == 190 && shift_key) { // >
282 if (keycode == 188 && shift_key) { // <
286 if (keycode == 191 && shift_key) { // ?
290 if (keycode == 69 && shift_key) { // e
291 return editFeedDlg(getActiveFeedId());
294 if (keycode == 70 && shift_key) { // f
295 if (getActiveFeedId()) {
296 return catchupCurrentFeed();
300 if (keycode == 80 && shift_key) { // p
301 if (getActiveFeedId()) {
302 return catchupPage();
306 if (keycode == 86) { // v
307 if (getActiveArticleId()) {
308 openArticleInNewWindow(getActiveArticleId());
312 if (keycode == 84) { // t
314 var id = getActiveArticleId();
318 var cb = document.getElementById("RCHK-" + id);
321 cb.checked = !cb.checked;
322 toggleSelectRowById(cb, "RROW-" + id);
327 if (keycode == 67) { // c
328 var id = getActiveArticleId();
335 if (keycode == 67 && shift_key) { // c
336 if (typeof collapse_feedlist != 'undefined') {
337 return collapse_feedlist();
341 if (typeof localHotkeyHandler != 'undefined') {
343 return localHotkeyHandler(e);
345 exception_error("hotkey_handler, local:", e);
349 debug("KP=" + keycode);
351 exception_error("hotkey_handler", e);
355 function cleanSelectedList(element) {
356 var content = document.getElementById(element);
358 if (!document.getElementById("feedCatHolder")) {
359 for (i = 0; i < content.childNodes.length; i++) {
360 var child = content.childNodes[i];
362 child.className = child.className.replace("Selected", "");
368 for (i = 0; i < content.childNodes.length; i++) {
369 var child = content.childNodes[i];
370 if (child.id == "feedCatHolder") {
372 var fcat = child.lastChild;
373 for (j = 0; j < fcat.childNodes.length; j++) {
374 var feed = fcat.childNodes[j];
375 feed.className = feed.className.replace("Selected", "");
383 function cleanSelected(element) {
384 var content = document.getElementById(element);
386 for (i = 0; i < content.rows.length; i++) {
387 content.rows[i].className = content.rows[i].className.replace("Selected", "");
391 function getVisibleUnreadHeadlines() {
392 var content = document.getElementById("headlinesList");
394 var rows = new Array();
396 for (i = 0; i < content.rows.length; i++) {
397 var row_id = content.rows[i].id.replace("RROW-", "");
398 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
405 function getVisibleHeadlineIds() {
407 var content = document.getElementById("headlinesList");
409 var rows = new Array();
411 for (i = 0; i < content.rows.length; i++) {
412 var row_id = content.rows[i].id.replace("RROW-", "");
413 if (row_id.length > 0) {
420 function getFirstVisibleHeadlineId() {
421 var rows = getVisibleHeadlineIds();
425 function getLastVisibleHeadlineId() {
426 var rows = getVisibleHeadlineIds();
427 return rows[rows.length-1];
430 function markHeadline(id) {
431 var row = document.getElementById("RROW-" + id);
433 var is_active = false;
435 if (row.className.match("Active")) {
438 row.className = row.className.replace("Selected", "");
439 row.className = row.className.replace("Active", "");
440 row.className = row.className.replace("Insensitive", "");
443 row.className = row.className = "Active";
446 var check = document.getElementById("RCHK-" + id);
449 check.checked = true;
452 row.className = row.className + "Selected";
457 function getFeedIds() {
458 var content = document.getElementById("feedsList");
460 var rows = new Array();
462 for (i = 0; i < content.rows.length; i++) {
463 var id = content.rows[i].id.replace("FEEDR-", "");
472 function setCookie(name, value, lifetime, path, domain, secure) {
478 d.setTime(d.getTime() + (lifetime * 1000));
481 debug("setCookie: " + name + " => " + value + ": " + d);
483 int_setCookie(name, value, d, path, domain, secure);
487 function int_setCookie(name, value, expires, path, domain, secure) {
488 document.cookie= name + "=" + escape(value) +
489 ((expires) ? "; expires=" + expires.toGMTString() : "") +
490 ((path) ? "; path=" + path : "") +
491 ((domain) ? "; domain=" + domain : "") +
492 ((secure) ? "; secure" : "");
495 function delCookie(name, path, domain) {
496 if (getCookie(name)) {
497 document.cookie = name + "=" +
498 ((path) ? ";path=" + path : "") +
499 ((domain) ? ";domain=" + domain : "" ) +
500 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
505 function getCookie(name) {
507 var dc = document.cookie;
508 var prefix = name + "=";
509 var begin = dc.indexOf("; " + prefix);
511 begin = dc.indexOf(prefix);
512 if (begin != 0) return null;
517 var end = document.cookie.indexOf(";", begin);
521 return unescape(dc.substring(begin + prefix.length, end));
524 function disableContainerChildren(id, disable, doc) {
526 if (!doc) doc = document;
528 var container = doc.getElementById(id);
531 //alert("disableContainerChildren: element " + id + " not found");
535 for (var i = 0; i < container.childNodes.length; i++) {
536 var child = container.childNodes[i];
539 child.disabled = disable;
545 if (child.className && child.className.match("button")) {
546 child.className = "disabledButton";
549 if (child.className && child.className.match("disabledButton")) {
550 child.className = "button";
557 function gotoPreferences() {
558 document.location.href = "prefs.php";
561 function gotoMain() {
562 document.location.href = "tt-rss.php";
565 function gotoExportOpml() {
566 document.location.href = "opml.php?op=Export";
569 function getActiveFeedId() {
570 // return getCookie("ttrss_vf_actfeed");
572 debug("gAFID: " + active_feed_id);
573 return active_feed_id;
575 exception_error("getActiveFeedId", e);
579 function activeFeedIsCat() {
580 return active_feed_is_cat;
583 function setActiveFeedId(id) {
584 // return setCookie("ttrss_vf_actfeed", id);
586 debug("sAFID(" + id + ")");
589 exception_error("setActiveFeedId", e);
593 function parse_counters(reply, scheduled_call) {
598 var elems = reply.getElementsByTagName("counter");
600 for (var l = 0; l < elems.length; l++) {
602 var id = elems[l].getAttribute("id");
603 var t = elems[l].getAttribute("type");
604 var ctr = elems[l].getAttribute("counter");
605 var error = elems[l].getAttribute("error");
606 var has_img = elems[l].getAttribute("hi");
607 var updated = elems[l].getAttribute("updated");
608 var title = elems[l].getAttribute("title");
610 if (id == "global-unread") {
616 if (id == "subscribed-feeds") {
621 if (t == "category") {
622 var catctr = document.getElementById("FCATCTR-" + id);
624 catctr.innerHTML = "(" + ctr + ")";
626 catctr.className = "catCtrHasUnread";
628 catctr.className = "catCtrNoUnread";
634 var feedctr = document.getElementById("FEEDCTR-" + id);
635 var feedu = document.getElementById("FEEDU-" + id);
636 var feedr = document.getElementById("FEEDR-" + id);
637 var feed_img = document.getElementById("FIMG-" + id);
638 var feedlink = document.getElementById("FEEDL-" + id);
639 var feedupd = document.getElementById("FLUPD-" + id);
641 if (updated && feedlink) {
643 feedlink.title = "Error: " + error + " (" + updated + ")";
645 feedlink.title = "Updated: " + updated;
649 if (updated && feedupd) {
651 feedupd.innerHTML = updated + " (Error)";
653 feedupd.innerHTML = updated;
657 if (has_img && feed_img && !is_msie()) {
658 if (!feed_img.src.match(id + ".ico")) {
659 feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
663 if (feedlink && title) {
664 feedlink.innerHTML = title;
667 if (feedctr && feedu && feedr) {
669 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
673 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
675 feedu.innerHTML = ctr;
678 feedr.className = feedr.className.replace("feed", "error");
680 feedr.className = feedr.className.replace("error", "feed");
684 feedctr.className = "odd";
685 if (!feedr.className.match("Unread")) {
686 var is_selected = feedr.className.match("Selected");
688 feedr.className = feedr.className.replace("Selected", "");
689 feedr.className = feedr.className.replace("Unread", "");
691 feedr.className = feedr.className + "Unread";
694 feedr.className = feedr.className + "Selected";
700 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
701 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
704 feedctr.className = "invisible";
705 feedr.className = feedr.className.replace("Unread", "");
710 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
712 var feeds_stored = number_of_feeds;
714 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
716 if (feeds_stored != feeds_found) {
717 number_of_feeds = feeds_found;
719 if (feeds_stored != 0 && feeds_found != 0) {
720 debug("Subscribed feed number changed, refreshing feedlist");
721 setTimeout('updateFeedList(false, false)', 50);
726 exception_error("parse_counters", e);
730 function parse_counters_reply(transport, scheduled_call) {
732 if (!transport.responseXML) {
733 notify_error("Backend did not return valid XML", true);
737 var reply = transport.responseXML.firstChild;
740 notify_error("Backend did not return expected XML object", true);
745 var error_code = false;
746 var error_msg = false;
748 if (reply.firstChild) {
749 error_code = reply.firstChild.getAttribute("error-code");
750 error_msg = reply.firstChild.getAttribute("error-msg");
754 error_code = reply.getAttribute("error-code");
755 error_msg = reply.getAttribute("error-msg");
758 if (error_code && error_code != 0) {
759 debug("refetch_callback: got error code " + error_code);
760 return fatalError(error_code, error_msg);
763 var counters = reply.getElementsByTagName("counters")[0];
765 parse_counters(counters, scheduled_call);
767 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
769 parse_runtime_info(runtime_info);
771 if (getInitParam("feeds_sort_by_unread") == 1) {
775 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
779 function all_counters_callback2(transport) {
781 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
782 parse_counters_reply(transport);
783 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
786 exception_error("all_counters_callback2", e);
790 function get_feed_unread(id) {
792 return parseInt(document.getElementById("FEEDU-" + id).innerHTML);
794 exception_error("get_feed_unread", e, true);
799 function get_feed_entry_unread(doc, elem) {
801 var id = elem.id.replace("FEEDR-", "");
808 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
814 function resort_category(doc, node) {
815 debug("resort_category: " + node);
817 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
818 for (i = 0; i < node.childNodes.length; i++) {
819 if (node.childNodes[i].nodeName != "LI") { continue; }
821 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
825 for (j = i+1; j < node.childNodes.length; j++) {
826 if (node.childNodes[j].nodeName != "LI") { continue; }
828 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
829 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
831 if (cur_val > tmp_val) {
832 tempnode_i = node.childNodes[i].cloneNode(true);
833 tempnode_j = node.childNodes[j].cloneNode(true);
834 node.replaceChild(tempnode_i, node.childNodes[j]);
835 node.replaceChild(tempnode_j, node.childNodes[i]);
844 function resort_feedlist() {
845 debug("resort_feedlist");
849 if (fd.getElementById("feedCatHolder")) {
851 var feeds = fd.getElementById("feedList");
852 var child = feeds.firstChild;
856 if (child.id == "feedCatHolder") {
857 resort_category(fd, child.firstChild);
860 child = child.nextSibling;
864 resort_category(fd, fd.getElementById("feedList"));
868 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
869 * * @author Sundar Dorai-Raj
870 * * Email: sdoraira@vt.edu
871 * * This program is free software; you can redistribute it and/or
872 * * modify it under the terms of the GNU General Public License
873 * * as published by the Free Software Foundation; either version 2
874 * * of the License, or (at your option) any later version,
875 * * provided that any use properly credits the author.
876 * * This program is distributed in the hope that it will be useful,
877 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
878 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
879 * * GNU General Public License for more details at http://www.gnu.org * * */
881 var numbers=".0123456789";
882 function isNumeric(x) {
883 // is x a String or a character?
885 // remove negative sign
887 for(j=0;j<x.length;j++) {
888 // call isNumeric recursively for each character
889 number=isNumeric(x.substring(j,j+1));
890 if(!number) return number;
895 // if x is number return true
896 if(numbers.indexOf(x)>=0) return true;
902 function hideOrShowFeeds(doc, hide) {
904 debug("hideOrShowFeeds: " + doc + ", " + hide);
908 var list = fd.getElementById("feedList");
910 if (fd.getElementById("feedCatHolder")) {
912 var feeds = fd.getElementById("feedList");
913 var child = feeds.firstChild;
917 if (child.id == "feedCatHolder") {
918 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
921 child = child.nextSibling;
925 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
929 function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
931 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
936 debug("hideOrShowFeeds: passed node is null, aborting");
940 // debug("cat: " + node.id);
942 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
943 for (i = 0; i < node.childNodes.length; i++) {
944 if (node.childNodes[i].nodeName != "LI") { continue; }
946 if (node.childNodes[i].style != undefined) {
948 var has_unread = (node.childNodes[i].className != "feed" &&
949 node.childNodes[i].className != "label" &&
950 !(!getInitParam("hide_read_shows_special") &&
951 node.childNodes[i].className == "virt") &&
952 node.childNodes[i].className != "error" &&
953 node.childNodes[i].className != "tag");
955 // debug(node.childNodes[i].id + " --> " + has_unread);
957 if (hide && !has_unread) {
958 //node.childNodes[i].style.display = "none";
959 var id = node.childNodes[i].id;
960 Effect.Fade(node.childNodes[i], {duration : 0.3,
961 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
965 node.childNodes[i].style.display = "list-item";
966 //Effect.Appear(node.childNodes[i], {duration : 0.3});
970 node.childNodes[i].style.display = "list-item";
972 //Effect.Appear(node.childNodes[i], {duration : 0.3});
973 //Effect.Highlight(node.childNodes[i]);
979 // debug("end cat: " + node.id + " unread " + cat_unread);
981 if (cat_unread == 0) {
982 if (cat_node.style == undefined) {
983 debug("ERROR: supplied cat_node " + cat_node +
984 " has no styles. WTF?");
988 //cat_node.style.display = "none";
989 Effect.Fade(cat_node, {duration : 0.3,
990 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
992 cat_node.style.display = "list-item";
996 cat_node.style.display = "list-item";
1002 // debug("unread for category: " + cat_unread);
1005 function selectTableRow(r, do_select) {
1006 r.className = r.className.replace("Selected", "");
1009 r.className = r.className + "Selected";
1013 function selectTableRowById(elem_id, check_id, do_select) {
1017 var row = document.getElementById(elem_id);
1020 selectTableRow(row, do_select);
1023 var check = document.getElementById(check_id);
1026 check.checked = do_select;
1029 exception_error("selectTableRowById", e);
1033 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
1034 classcheck, reset_others) {
1036 var content = document.getElementById(content_id);
1039 alert("[selectTableRows] Element " + content_id + " not found.");
1043 for (i = 0; i < content.rows.length; i++) {
1044 if (!classcheck || content.rows[i].className.match(classcheck)) {
1046 if (content.rows[i].id.match(prefix)) {
1047 selectTableRow(content.rows[i], do_select);
1049 var row_id = content.rows[i].id.replace(prefix, "");
1050 var check = document.getElementById(check_prefix + row_id);
1053 check.checked = do_select;
1055 } else if (reset_others) {
1056 selectTableRow(content.rows[i], false);
1058 var row_id = content.rows[i].id.replace(prefix, "");
1059 var check = document.getElementById(check_prefix + row_id);
1062 check.checked = false;
1066 } else if (reset_others) {
1067 selectTableRow(content.rows[i], false);
1069 var row_id = content.rows[i].id.replace(prefix, "");
1070 var check = document.getElementById(check_prefix + row_id);
1073 check.checked = false;
1080 function getSelectedTableRowIds(content_id, prefix) {
1082 var content = document.getElementById(content_id);
1085 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
1089 var sel_rows = new Array();
1091 for (i = 0; i < content.rows.length; i++) {
1092 if (content.rows[i].id.match(prefix) &&
1093 content.rows[i].className.match("Selected")) {
1095 var row_id = content.rows[i].id.replace(prefix + "-", "");
1096 sel_rows.push(row_id);
1104 function toggleSelectRowById(sender, id) {
1105 var row = document.getElementById(id);
1107 if (sender.checked) {
1108 if (!row.className.match("Selected")) {
1109 row.className = row.className + "Selected";
1112 if (row.className.match("Selected")) {
1113 row.className = row.className.replace("Selected", "");
1118 function toggleSelectListRow(sender) {
1119 var parent_row = sender.parentNode;
1121 if (sender.checked) {
1122 if (!parent_row.className.match("Selected")) {
1123 parent_row.className = parent_row.className + "Selected";
1126 if (parent_row.className.match("Selected")) {
1127 parent_row.className = parent_row.className.replace("Selected", "");
1132 function tSR(sender) {
1133 return toggleSelectRow(sender);
1136 function toggleSelectRow(sender) {
1137 var parent_row = sender.parentNode.parentNode;
1139 if (sender.checked) {
1140 if (!parent_row.className.match("Selected")) {
1141 parent_row.className = parent_row.className + "Selected";
1144 if (parent_row.className.match("Selected")) {
1145 parent_row.className = parent_row.className.replace("Selected", "");
1150 function getRelativeFeedId(list, id, direction, unread_only) {
1151 var rows = list.getElementsByTagName("LI");
1152 var feeds = new Array();
1154 for (var i = 0; i < rows.length; i++) {
1155 if (rows[i].id.match("FEEDR-")) {
1157 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1160 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1161 feeds.push(rows[i].id.replace("FEEDR-", ""));
1168 if (direction == "next") {
1169 return feeds.shift();
1174 if (direction == "next") {
1175 var idx = feeds.indexOf(id);
1176 if (idx != -1 && idx < feeds.length) {
1177 return feeds[idx+1];
1179 return getRelativeFeedId(list, false, direction, unread_only);
1182 var idx = feeds.indexOf(id);
1184 return feeds[idx-1];
1186 return getRelativeFeedId(list, false, direction, unread_only);
1193 function showBlockElement(id, h_id) {
1194 var elem = document.getElementById(id);
1197 elem.style.display = "block";
1200 elem = document.getElementById(h_id);
1202 elem.style.display = "none";
1206 alert("[showBlockElement] can't find element with id " + id);
1210 function appearBlockElement_afh(effect) {
1214 function checkboxToggleElement(elem, id) {
1216 Effect.SlideDown(id, {duration : 0.5});
1218 Effect.SlideUp(id, {duration : 0.5});
1222 function appearBlockElement(id, h_id) {
1228 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1230 exception_error("appearBlockElement", e);
1235 function hideParentElement(e) {
1236 e.parentNode.style.display = "none";
1239 function dropboxSelect(e, v) {
1240 for (i = 0; i < e.length; i++) {
1241 if (e[i].value == v) {
1242 e.selectedIndex = i;
1248 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1249 // bugfixed just a little bit :-)
1250 function getURLParam(strParamName){
1252 var strHref = window.location.href;
1254 if (strHref.indexOf("#") == strHref.length-1) {
1255 strHref = strHref.substring(0, strHref.length-1);
1258 if ( strHref.indexOf("?") > -1 ){
1259 var strQueryString = strHref.substr(strHref.indexOf("?"));
1260 var aQueryString = strQueryString.split("&");
1261 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1262 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1263 var aParam = aQueryString[iParam].split("=");
1264 strReturn = aParam[1];
1272 function leading_zero(p) {
1274 if (s.length == 1) s = "0" + s;
1278 function closeInfoBox(cleanup) {
1280 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1281 var overlay = document.getElementById("dialog_overlay");
1283 overlay.style.display = "none";
1287 var box = document.getElementById('infoBox');
1288 var shadow = document.getElementById('infoBoxShadow');
1291 shadow.style.display = "none";
1293 box.style.display = "none";
1296 if (cleanup) box.innerHTML = " ";
1304 function displayDlg(id, param) {
1306 notify_progress("Loading, please wait...", true);
1310 var query = "backend.php?op=dlg&id=" +
1311 param_escape(id) + "¶m=" + param_escape(param);
1313 new Ajax.Request(query, {
1314 onComplete: function (transport) {
1315 infobox_callback2(transport);
1321 function infobox_submit_callback2(transport) {
1325 // called from prefs, reload tab
1327 selectTab(active_tab, false);
1331 if (transport.responseText) {
1332 notify_info(transport.responseText);
1336 function infobox_callback2(transport) {
1339 debug("infobox_callback2");
1341 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1342 var overlay = document.getElementById("dialog_overlay");
1344 overlay.style.display = "block";
1348 var box = document.getElementById('infoBox');
1349 var shadow = document.getElementById('infoBoxShadow');
1352 /* if (!is_safari()) {
1353 new Draggable(shadow);
1356 box.innerHTML=transport.responseText;
1358 shadow.style.display = "block";
1360 box.style.display = "block";
1364 /* FIXME this needs to be moved out somewhere */
1366 if (document.getElementById("tags_choices")) {
1367 new Ajax.Autocompleter('tags_str', 'tags_choices',
1368 "backend.php?op=rpc&subop=completeTags",
1369 { tokens: ',', paramName: "search" });
1374 exception_error("infobox_callback2", e);
1378 function createFilter() {
1380 var form = document.forms['filter_add_form'];
1381 var reg_exp = form.reg_exp.value;
1383 if (reg_exp == "") {
1384 alert(__("Can't add filter: nothing to match on."));
1388 var query = Form.serialize("filter_add_form");
1390 new Ajax.Request("backend.php?" + query, {
1391 onComplete: function (transport) {
1392 infobox_submit_callback2(transport);
1398 function toggleSubmitNotEmpty(e, submit_id) {
1400 document.getElementById(submit_id).disabled = (e.value == "")
1402 exception_error("toggleSubmitNotEmpty", e);
1406 function isValidURL(s) {
1407 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
1410 function subscribeToFeed() {
1412 var form = document.forms['feed_add_form'];
1413 var feed_url = form.feed_url.value;
1415 if (feed_url == "") {
1416 alert(__("Can't subscribe: no feed URL given."));
1420 notify_progress(__("Subscribing to feed..."), true);
1424 var feeds_doc = document;
1426 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1428 var query = Form.serialize("feed_add_form");
1430 debug("subscribe q: " + query);
1432 new Ajax.Request("backend.php", {
1434 onComplete: function(transport) {
1435 dlg_frefresh_callback(transport);
1441 function filterCR(e, f)
1446 key = window.event.keyCode; //IE
1448 key = e.which; //firefox
1451 if (typeof f != 'undefined') {
1462 function getMainContext() {
1466 function getFeedsContext() {
1470 function getContentContext() {
1474 function getHeadlinesContext() {
1478 var debug_last_class = "even";
1480 function debug(msg) {
1482 if (debug_last_class == "even") {
1483 debug_last_class = "odd";
1485 debug_last_class = "even";
1488 var c = document.getElementById('debug_output');
1489 if (c && c.style.display == "block") {
1490 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1491 c.removeChild(c.lastChild);
1495 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1496 ":" + leading_zero(d.getSeconds());
1497 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1498 msg + "</li>" + c.innerHTML;
1502 function getInitParam(key) {
1503 return init_params[key];
1506 function storeInitParam(key, value) {
1507 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
1508 init_params[key] = value;
1511 function fatalError(code, message) {
1515 window.location.href = "tt-rss.php";
1516 } else if (code == 5) {
1517 window.location.href = "update.php";
1519 var fe = document.getElementById("fatal_error");
1520 var fc = document.getElementById("fatal_error_msg");
1522 if (message == "") message = "Unknown error";
1524 fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
1526 fe.style.display = "block";
1530 exception_error("fatalError", e);
1534 function getFeedName(id, is_cat) {
1535 var d = getFeedsContext().document;
1540 e = d.getElementById("FCATN-" + id);
1542 e = d.getElementById("FEEDN-" + id);
1545 return e.innerHTML.stripTags();
1551 function viewContentUrl(url) {
1552 getContentContext().location = url;
1555 function filterDlgCheckAction(sender) {
1559 var action = sender[sender.selectedIndex].value;
1561 var form = document.forms["filter_add_form"];
1564 form = document.forms["filter_edit_form"];
1568 debug("filterDlgCheckAction: can't find form!");
1572 var action_param = form.action_param;
1574 if (!action_param) {
1575 debug("filterDlgCheckAction: can't find action param!");
1579 // if selected action supports parameters, enable params field
1581 action_param.disabled = false;
1583 action_param.disabled = true;
1587 exception_error(e, "filterDlgCheckAction");
1592 function explainError(code) {
1593 return displayDlg("explainError", code);
1596 // this only searches loaded headlines list, not in CDM
1597 function getRelativePostIds(id) {
1599 debug("getRelativePostIds: " + id);
1601 var ids = new Array();
1602 var container = document.getElementById("headlinesList");
1605 var rows = container.rows;
1607 for (var i = 0; i < rows.length; i++) {
1608 var r_id = rows[i].id.replace("RROW-", "");
1611 if (i > 0) ids.push(rows[i-1].id.replace("RROW-", ""));
1612 if (i > 1) ids.push(rows[i-2].id.replace("RROW-", ""));
1613 if (i > 2) ids.push(rows[i-3].id.replace("RROW-", ""));
1615 if (i < rows.length-1) ids.push(rows[i+1].id.replace("RROW-", ""));
1616 if (i < rows.length-2) ids.push(rows[i+2].id.replace("RROW-", ""));
1617 if (i < rows.length-3) ids.push(rows[i+3].id.replace("RROW-", ""));
1627 function openArticleInNewWindow(id) {
1629 debug("openArticleInNewWindow: " + id);
1631 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1635 new Ajax.Request(query, {
1636 onComplete: function(transport) {
1637 open_article_callback(transport);
1642 exception_error("openArticleInNewWindow", e);
1646 /* http://textsnippets.com/posts/show/835 */
1648 Position.GetWindowSize = function(w) {
1650 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1651 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1652 return [width, height]
1655 /* http://textsnippets.com/posts/show/836 */
1657 Position.Center = function(element, parent) {
1659 var d = Element.getDimensions(element);
1664 var ws = Position.GetWindowSize();
1668 pw = parent.offsetWidth;
1669 ph = parent.offsetHeight;
1671 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1672 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1676 function labeltest_callback(transport) {
1678 var container = document.getElementById('label_test_result');
1680 container.innerHTML = transport.responseText;
1681 if (!Element.visible(container)) {
1682 Effect.SlideDown(container, { duration : 0.5 });
1687 exception_error("labeltest_callback", e);
1691 function labelTest() {
1694 var container = document.getElementById('label_test_result');
1696 var form = document.forms['label_edit_form'];
1698 var sql_exp = form.sql_exp.value;
1699 var description = form.description.value;
1701 notify_progress("Loading, please wait...");
1703 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1704 param_escape(sql_exp) + "&descr=" + param_escape(description);
1706 new Ajax.Request(query, {
1707 onComplete: function (transport) {
1708 labeltest_callback(transport);
1714 exception_error("labelTest", e);
1718 function isCdmMode() {
1719 return !document.getElementById("headlinesList");
1722 function getSelectedArticleIds2() {
1723 var rows = new Array();
1724 var cdm_mode = isCdmMode();
1727 rows = cdmGetSelectedArticles();
1729 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1732 var ids = new Array();
1734 for (var i = 0; i < rows.length; i++) {
1735 var chk = document.getElementById("RCHK-" + rows[i]);
1736 if (chk && chk.checked) {
1744 function displayHelpInfobox(topic_id) {
1746 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1748 var w = window.open(url, "ttrss_help",
1749 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1754 // http://www.dynamic-tools.net/toolbox/copyToClipboard/
1757 function copyToClipboard(s)
1759 if( window.clipboardData && clipboardData.setData )
1761 clipboardData.setData("Text", s);
1765 // You have to sign the code to enable this or allow the action in about:config by changing
1766 user_pref("signed.applets.codebase_principal_support", true);
1767 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1769 var clip Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
1772 // create a transferable
1773 var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
1776 // specify the data we wish to handle. Plaintext in this case.
1777 trans.addDataFlavor('text/unicode');
1779 // To get the data from the transferable we need two new objects
1780 var str = new Object();
1781 var len = new Object();
1783 var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);
1785 var copytext=meintext;
1789 trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);
1791 var clipid=Components.interfaces.nsIClipboard;
1793 if (!clip) return false;
1795 clip.setData(trans,null,clipid.kGlobalClipboard);