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) {
72 var link = transport.responseXML.getElementsByTagName("link")[0];
73 var id = transport.responseXML.getElementsByTagName("id")[0];
75 debug("open_article_callback, received link: " + link);
78 debug("link url: " + link.firstChild.nodeValue);
80 window.open(link.firstChild.nodeValue, "_blank");
83 id = id.firstChild.nodeValue;
84 if (!document.getElementById("headlinesList")) {
85 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
89 notify_error("Can't open article: received invalid article link");
92 notify_error("Can't open article: received invalid XML");
96 exception_error("open_article_callback", e);
100 function param_escape(arg) {
101 if (typeof encodeURIComponent != 'undefined')
102 return encodeURIComponent(arg);
107 function param_unescape(arg) {
108 if (typeof decodeURIComponent != 'undefined')
109 return decodeURIComponent(arg);
111 return unescape(arg);
114 function delay(gap) {
116 then=new Date().getTime();
118 while((now-then)<gap) {
119 now=new Date().getTime();
123 var notify_hide_timerid = false;
125 function hide_notify() {
126 var n = document.getElementById("notify");
128 n.style.display = "none";
132 function notify_real(msg, no_hide, n_type) {
134 var n = document.getElementById("notify");
135 var nb = document.getElementById("notify_body");
137 if (!n || !nb) return;
139 if (notify_hide_timerid) {
140 window.clearTimeout(notify_hide_timerid);
144 if (n.style.display == "block") {
145 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
149 n.style.display = "block";
161 if (typeof __ != 'undefined') {
166 n.className = "notify";
167 } else if (n_type == 2) {
168 n.className = "notifyProgress";
169 msg = "<img src='images/indicator_white.gif'> " + msg;
170 } else if (n_type == 3) {
171 n.className = "notifyError";
172 msg = "<img src='images/sign_excl.gif'> " + msg;
173 } else if (n_type == 4) {
174 n.className = "notifyInfo";
175 msg = "<img src='images/sign_info.gif'> " + msg;
178 // msg = "<img src='images/live_com_loading.gif'> " + msg;
183 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
187 function notify(msg, no_hide) {
188 notify_real(msg, no_hide, 1);
191 function notify_progress(msg, no_hide) {
192 notify_real(msg, no_hide, 2);
195 function notify_error(msg, no_hide) {
196 notify_real(msg, no_hide, 3);
200 function notify_info(msg, no_hide) {
201 notify_real(msg, no_hide, 4);
204 function printLockingError() {
205 notify_info("Please wait until operation finishes.");
208 function hotkey_handler(e) {
213 var shift_key = false;
216 shift_key = e.shiftKey;
221 if (!hotkeys_enabled) {
222 debug("hotkeys disabled");
227 keycode = window.event.keyCode;
232 if (keycode == 82) { // r
233 return scheduleFeedUpdate(true);
236 if (keycode == 83) { // s
237 return displayDlg("search", getActiveFeedId());
240 if (keycode == 85) { // u
241 if (getActiveFeedId()) {
242 return viewfeed(getActiveFeedId(), "ForceUpdate");
246 if (keycode == 65) { // a
247 return toggleDispRead();
250 var feedlist = document.getElementById('feedList');
252 if (keycode == 74) { // j
253 var feed = getActiveFeedId();
254 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
255 if (new_feed) viewfeed(new_feed, '');
258 if (keycode == 75) { // k
259 var feed = getActiveFeedId();
260 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
261 if (new_feed) viewfeed(new_feed, '');
264 if (shift_key && (keycode == 78 || keycode == 40)) { // shift - n, down
265 return catchupRelativeToArticle(1);
268 if (shift_key && (keycode == 80 || keycode == 38)) { // shift - p, up
269 return catchupRelativeToArticle(0);
272 if (keycode == 78 || keycode == 40) { // n, down
273 if (typeof moveToPost != 'undefined') {
274 return moveToPost('next');
278 if (keycode == 80 || keycode == 38) { // p, up
279 if (typeof moveToPost != 'undefined') {
280 return moveToPost('prev');
284 if (keycode == 68 && shift_key) { // d
285 if (!debug_mode_enabled) {
286 document.getElementById('debug_output').style.display = 'block';
287 debug('debug mode activated');
289 document.getElementById('debug_output').style.display = 'none';
292 debug_mode_enabled = !debug_mode_enabled;
295 if (keycode == 190 && shift_key) { // >
299 if (keycode == 188 && shift_key) { // <
303 if (keycode == 191 && shift_key) { // ?
307 if (keycode == 69 && shift_key) { // e
308 return editFeedDlg(getActiveFeedId());
311 if (keycode == 70 && shift_key) { // f
312 if (getActiveFeedId()) {
313 return catchupCurrentFeed();
317 if (keycode == 80 && shift_key) { // p
318 if (getActiveFeedId()) {
319 return catchupPage();
323 if (keycode == 86) { // v
324 if (getActiveArticleId()) {
325 openArticleInNewWindow(getActiveArticleId());
329 if (keycode == 84) { // t
331 var id = getActiveArticleId();
335 var cb = document.getElementById("RCHK-" + id);
338 cb.checked = !cb.checked;
339 toggleSelectRowById(cb, "RROW-" + id);
344 if (keycode == 67) { // c
345 var id = getActiveArticleId();
352 if (keycode == 67 && shift_key) { // c
353 if (typeof collapse_feedlist != 'undefined') {
354 return collapse_feedlist();
358 if (keycode == 81 && shift_key) { // shift + q
359 if (typeof catchupAllFeeds != 'undefined') {
360 return catchupAllFeeds();
364 if (keycode == 73 && shift_key) { // shift + i
365 if (document.getElementById("subtoolbar_search")) {
366 if (Element.visible("subtoolbar_search")) {
367 Element.hide("subtoolbar_search");
368 Element.show("subtoolbar_ftitle");
369 setTimeout("Element.focus('subtoolbar_search_box')", 100);
371 Element.show("subtoolbar_search");
372 Element.hide("subtoolbar_ftitle");
377 if (typeof localHotkeyHandler != 'undefined') {
379 return localHotkeyHandler(e);
381 exception_error("hotkey_handler, local:", e);
385 debug("KP=" + keycode);
387 exception_error("hotkey_handler", e);
391 function cleanSelectedList(element) {
392 var content = document.getElementById(element);
394 if (!document.getElementById("feedCatHolder")) {
395 for (i = 0; i < content.childNodes.length; i++) {
396 var child = content.childNodes[i];
398 child.className = child.className.replace("Selected", "");
404 for (i = 0; i < content.childNodes.length; i++) {
405 var child = content.childNodes[i];
406 if (child.id == "feedCatHolder") {
408 var fcat = child.lastChild;
409 for (j = 0; j < fcat.childNodes.length; j++) {
410 var feed = fcat.childNodes[j];
411 feed.className = feed.className.replace("Selected", "");
419 function cleanSelected(element) {
420 var content = document.getElementById(element);
422 for (i = 0; i < content.rows.length; i++) {
423 content.rows[i].className = content.rows[i].className.replace("Selected", "");
427 function getVisibleUnreadHeadlines() {
428 var content = document.getElementById("headlinesList");
430 var rows = new Array();
432 for (i = 0; i < content.rows.length; i++) {
433 var row_id = content.rows[i].id.replace("RROW-", "");
434 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
441 function getVisibleHeadlineIds() {
443 var content = document.getElementById("headlinesList");
445 var rows = new Array();
447 for (i = 0; i < content.rows.length; i++) {
448 var row_id = content.rows[i].id.replace("RROW-", "");
449 if (row_id.length > 0) {
456 function getFirstVisibleHeadlineId() {
457 var rows = getVisibleHeadlineIds();
461 function getLastVisibleHeadlineId() {
462 var rows = getVisibleHeadlineIds();
463 return rows[rows.length-1];
466 function markHeadline(id) {
467 var row = document.getElementById("RROW-" + id);
469 var is_active = false;
471 if (row.className.match("Active")) {
474 row.className = row.className.replace("Selected", "");
475 row.className = row.className.replace("Active", "");
476 row.className = row.className.replace("Insensitive", "");
479 row.className = row.className = "Active";
482 var check = document.getElementById("RCHK-" + id);
485 check.checked = true;
488 row.className = row.className + "Selected";
493 function getFeedIds() {
494 var content = document.getElementById("feedsList");
496 var rows = new Array();
498 for (i = 0; i < content.rows.length; i++) {
499 var id = content.rows[i].id.replace("FEEDR-", "");
508 function setCookie(name, value, lifetime, path, domain, secure) {
514 d.setTime(d.getTime() + (lifetime * 1000));
517 debug("setCookie: " + name + " => " + value + ": " + d);
519 int_setCookie(name, value, d, path, domain, secure);
523 function int_setCookie(name, value, expires, path, domain, secure) {
524 document.cookie= name + "=" + escape(value) +
525 ((expires) ? "; expires=" + expires.toGMTString() : "") +
526 ((path) ? "; path=" + path : "") +
527 ((domain) ? "; domain=" + domain : "") +
528 ((secure) ? "; secure" : "");
531 function delCookie(name, path, domain) {
532 if (getCookie(name)) {
533 document.cookie = name + "=" +
534 ((path) ? ";path=" + path : "") +
535 ((domain) ? ";domain=" + domain : "" ) +
536 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
541 function getCookie(name) {
543 var dc = document.cookie;
544 var prefix = name + "=";
545 var begin = dc.indexOf("; " + prefix);
547 begin = dc.indexOf(prefix);
548 if (begin != 0) return null;
553 var end = document.cookie.indexOf(";", begin);
557 return unescape(dc.substring(begin + prefix.length, end));
560 function disableContainerChildren(id, disable, doc) {
562 if (!doc) doc = document;
564 var container = doc.getElementById(id);
567 //alert("disableContainerChildren: element " + id + " not found");
571 for (var i = 0; i < container.childNodes.length; i++) {
572 var child = container.childNodes[i];
575 child.disabled = disable;
581 if (child.className && child.className.match("button")) {
582 child.className = "disabledButton";
585 if (child.className && child.className.match("disabledButton")) {
586 child.className = "button";
593 function gotoPreferences() {
594 document.location.href = "prefs.php";
597 function gotoMain() {
598 document.location.href = "tt-rss.php";
601 function gotoExportOpml() {
602 document.location.href = "opml.php?op=Export";
605 function getActiveFeedId() {
606 // return getCookie("ttrss_vf_actfeed");
608 debug("gAFID: " + active_feed_id);
609 return active_feed_id;
611 exception_error("getActiveFeedId", e);
615 function activeFeedIsCat() {
616 return active_feed_is_cat;
619 function setActiveFeedId(id) {
620 // return setCookie("ttrss_vf_actfeed", id);
622 debug("sAFID(" + id + ")");
625 exception_error("setActiveFeedId", e);
629 function parse_counters(reply, scheduled_call) {
634 var elems = reply.getElementsByTagName("counter");
636 for (var l = 0; l < elems.length; l++) {
638 var id = elems[l].getAttribute("id");
639 var t = elems[l].getAttribute("type");
640 var ctr = elems[l].getAttribute("counter");
641 var error = elems[l].getAttribute("error");
642 var has_img = elems[l].getAttribute("hi");
643 var updated = elems[l].getAttribute("updated");
644 var title = elems[l].getAttribute("title");
646 if (id == "global-unread") {
652 if (id == "subscribed-feeds") {
657 if (t == "category") {
658 var catctr = document.getElementById("FCATCTR-" + id);
660 catctr.innerHTML = "(" + ctr + ")";
662 catctr.className = "catCtrHasUnread";
664 catctr.className = "catCtrNoUnread";
670 var feedctr = document.getElementById("FEEDCTR-" + id);
671 var feedu = document.getElementById("FEEDU-" + id);
672 var feedr = document.getElementById("FEEDR-" + id);
673 var feed_img = document.getElementById("FIMG-" + id);
674 var feedlink = document.getElementById("FEEDL-" + id);
675 var feedupd = document.getElementById("FLUPD-" + id);
677 if (updated && feedlink) {
679 feedlink.title = "Error: " + error + " (" + updated + ")";
681 feedlink.title = "Updated: " + updated;
685 if (updated && feedupd) {
687 feedupd.innerHTML = updated + " (Error)";
689 feedupd.innerHTML = updated;
693 if (has_img && feed_img && !is_msie()) {
694 if (!feed_img.src.match(id + ".ico")) {
695 feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
699 if (feedlink && title) {
700 feedlink.innerHTML = title;
703 if (feedctr && feedu && feedr) {
705 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
709 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
711 feedu.innerHTML = ctr;
714 feedr.className = feedr.className.replace("feed", "error");
716 feedr.className = feedr.className.replace("error", "feed");
720 feedctr.className = "odd";
721 if (!feedr.className.match("Unread")) {
722 var is_selected = feedr.className.match("Selected");
724 feedr.className = feedr.className.replace("Selected", "");
725 feedr.className = feedr.className.replace("Unread", "");
727 feedr.className = feedr.className + "Unread";
730 feedr.className = feedr.className + "Selected";
736 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
737 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
740 feedctr.className = "invisible";
741 feedr.className = feedr.className.replace("Unread", "");
746 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
748 var feeds_stored = number_of_feeds;
750 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
752 if (feeds_stored != feeds_found) {
753 number_of_feeds = feeds_found;
755 if (feeds_stored != 0 && feeds_found != 0) {
756 debug("Subscribed feed number changed, refreshing feedlist");
757 setTimeout('updateFeedList(false, false)', 50);
762 exception_error("parse_counters", e);
766 function parse_counters_reply(transport, scheduled_call) {
768 if (!transport.responseXML) {
769 notify_error("Backend did not return valid XML", true);
773 var reply = transport.responseXML.firstChild;
776 notify_error("Backend did not return expected XML object", true);
781 var error_code = false;
782 var error_msg = false;
784 if (reply.firstChild) {
785 error_code = reply.firstChild.getAttribute("error-code");
786 error_msg = reply.firstChild.getAttribute("error-msg");
790 error_code = reply.getAttribute("error-code");
791 error_msg = reply.getAttribute("error-msg");
794 if (error_code && error_code != 0) {
795 debug("refetch_callback: got error code " + error_code);
796 return fatalError(error_code, error_msg);
799 var counters = reply.getElementsByTagName("counters")[0];
801 parse_counters(counters, scheduled_call);
803 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
805 parse_runtime_info(runtime_info);
807 if (getInitParam("feeds_sort_by_unread") == 1) {
811 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
815 function all_counters_callback2(transport) {
817 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
818 parse_counters_reply(transport);
819 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
822 exception_error("all_counters_callback2", e);
826 function get_feed_unread(id) {
828 return parseInt(document.getElementById("FEEDU-" + id).innerHTML);
830 exception_error("get_feed_unread", e, true);
835 function get_feed_entry_unread(doc, elem) {
837 var id = elem.id.replace("FEEDR-", "");
844 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
850 function resort_category(doc, node) {
851 debug("resort_category: " + node);
853 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
854 for (i = 0; i < node.childNodes.length; i++) {
855 if (node.childNodes[i].nodeName != "LI") { continue; }
857 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
861 for (j = i+1; j < node.childNodes.length; j++) {
862 if (node.childNodes[j].nodeName != "LI") { continue; }
864 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
865 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
867 if (cur_val > tmp_val) {
868 tempnode_i = node.childNodes[i].cloneNode(true);
869 tempnode_j = node.childNodes[j].cloneNode(true);
870 node.replaceChild(tempnode_i, node.childNodes[j]);
871 node.replaceChild(tempnode_j, node.childNodes[i]);
880 function resort_feedlist() {
881 debug("resort_feedlist");
885 if (fd.getElementById("feedCatHolder")) {
887 var feeds = fd.getElementById("feedList");
888 var child = feeds.firstChild;
892 if (child.id == "feedCatHolder") {
893 resort_category(fd, child.firstChild);
896 child = child.nextSibling;
900 resort_category(fd, fd.getElementById("feedList"));
904 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
905 * * @author Sundar Dorai-Raj
906 * * Email: sdoraira@vt.edu
907 * * This program is free software; you can redistribute it and/or
908 * * modify it under the terms of the GNU General Public License
909 * * as published by the Free Software Foundation; either version 2
910 * * of the License, or (at your option) any later version,
911 * * provided that any use properly credits the author.
912 * * This program is distributed in the hope that it will be useful,
913 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
914 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
915 * * GNU General Public License for more details at http://www.gnu.org * * */
917 var numbers=".0123456789";
918 function isNumeric(x) {
919 // is x a String or a character?
921 // remove negative sign
923 for(j=0;j<x.length;j++) {
924 // call isNumeric recursively for each character
925 number=isNumeric(x.substring(j,j+1));
926 if(!number) return number;
931 // if x is number return true
932 if(numbers.indexOf(x)>=0) return true;
938 function hideOrShowFeeds(doc, hide) {
940 debug("hideOrShowFeeds: " + doc + ", " + hide);
944 var list = fd.getElementById("feedList");
946 if (fd.getElementById("feedCatHolder")) {
948 var feeds = fd.getElementById("feedList");
949 var child = feeds.firstChild;
953 if (child.id == "feedCatHolder") {
954 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
957 child = child.nextSibling;
961 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
965 function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
967 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
972 debug("hideOrShowFeeds: passed node is null, aborting");
976 // debug("cat: " + node.id);
978 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
979 for (i = 0; i < node.childNodes.length; i++) {
980 if (node.childNodes[i].nodeName != "LI") { continue; }
982 if (node.childNodes[i].style != undefined) {
984 var has_unread = (node.childNodes[i].className != "feed" &&
985 node.childNodes[i].className != "label" &&
986 !(!getInitParam("hide_read_shows_special") &&
987 node.childNodes[i].className == "virt") &&
988 node.childNodes[i].className != "error" &&
989 node.childNodes[i].className != "tag");
991 // debug(node.childNodes[i].id + " --> " + has_unread);
993 if (hide && !has_unread) {
994 //node.childNodes[i].style.display = "none";
995 var id = node.childNodes[i].id;
996 Effect.Fade(node.childNodes[i], {duration : 0.3,
997 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
1001 node.childNodes[i].style.display = "list-item";
1002 //Effect.Appear(node.childNodes[i], {duration : 0.3});
1006 node.childNodes[i].style.display = "list-item";
1008 //Effect.Appear(node.childNodes[i], {duration : 0.3});
1009 //Effect.Highlight(node.childNodes[i]);
1015 // debug("end cat: " + node.id + " unread " + cat_unread);
1017 if (cat_unread == 0) {
1018 if (cat_node.style == undefined) {
1019 debug("ERROR: supplied cat_node " + cat_node +
1020 " has no styles. WTF?");
1024 //cat_node.style.display = "none";
1025 Effect.Fade(cat_node, {duration : 0.3,
1026 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
1028 cat_node.style.display = "list-item";
1032 cat_node.style.display = "list-item";
1038 // debug("unread for category: " + cat_unread);
1041 function selectTableRow(r, do_select) {
1042 r.className = r.className.replace("Selected", "");
1045 r.className = r.className + "Selected";
1049 function selectTableRowById(elem_id, check_id, do_select) {
1053 var row = document.getElementById(elem_id);
1056 selectTableRow(row, do_select);
1059 var check = document.getElementById(check_id);
1062 check.checked = do_select;
1065 exception_error("selectTableRowById", e);
1069 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
1070 classcheck, reset_others) {
1072 var content = document.getElementById(content_id);
1075 alert("[selectTableRows] Element " + content_id + " not found.");
1079 for (i = 0; i < content.rows.length; i++) {
1080 if (Element.visible(content.rows[i])) {
1081 if (!classcheck || content.rows[i].className.match(classcheck)) {
1083 if (content.rows[i].id.match(prefix)) {
1084 selectTableRow(content.rows[i], do_select);
1086 var row_id = content.rows[i].id.replace(prefix, "");
1087 var check = document.getElementById(check_prefix + row_id);
1090 check.checked = do_select;
1092 } else if (reset_others) {
1093 selectTableRow(content.rows[i], false);
1095 var row_id = content.rows[i].id.replace(prefix, "");
1096 var check = document.getElementById(check_prefix + row_id);
1099 check.checked = false;
1103 } else if (reset_others) {
1104 selectTableRow(content.rows[i], false);
1106 var row_id = content.rows[i].id.replace(prefix, "");
1107 var check = document.getElementById(check_prefix + row_id);
1110 check.checked = false;
1118 function getSelectedTableRowIds(content_id, prefix) {
1120 var content = document.getElementById(content_id);
1123 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
1127 var sel_rows = new Array();
1129 for (i = 0; i < content.rows.length; i++) {
1130 if (content.rows[i].id.match(prefix) &&
1131 content.rows[i].className.match("Selected")) {
1133 var row_id = content.rows[i].id.replace(prefix + "-", "");
1134 sel_rows.push(row_id);
1142 function toggleSelectRowById(sender, id) {
1143 var row = document.getElementById(id);
1145 if (sender.checked) {
1146 if (!row.className.match("Selected")) {
1147 row.className = row.className + "Selected";
1150 if (row.className.match("Selected")) {
1151 row.className = row.className.replace("Selected", "");
1156 function toggleSelectListRow(sender) {
1157 var parent_row = sender.parentNode;
1159 if (sender.checked) {
1160 if (!parent_row.className.match("Selected")) {
1161 parent_row.className = parent_row.className + "Selected";
1164 if (parent_row.className.match("Selected")) {
1165 parent_row.className = parent_row.className.replace("Selected", "");
1170 function tSR(sender) {
1171 return toggleSelectRow(sender);
1174 function toggleSelectRow(sender) {
1175 var parent_row = sender.parentNode.parentNode;
1177 if (sender.checked) {
1178 if (!parent_row.className.match("Selected")) {
1179 parent_row.className = parent_row.className + "Selected";
1182 if (parent_row.className.match("Selected")) {
1183 parent_row.className = parent_row.className.replace("Selected", "");
1188 function getRelativeFeedId(list, id, direction, unread_only) {
1189 var rows = list.getElementsByTagName("LI");
1190 var feeds = new Array();
1192 for (var i = 0; i < rows.length; i++) {
1193 if (rows[i].id.match("FEEDR-")) {
1195 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1198 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1199 feeds.push(rows[i].id.replace("FEEDR-", ""));
1206 if (direction == "next") {
1207 return feeds.shift();
1212 if (direction == "next") {
1213 var idx = feeds.indexOf(id);
1214 if (idx != -1 && idx < feeds.length) {
1215 return feeds[idx+1];
1217 return getRelativeFeedId(list, false, direction, unread_only);
1220 var idx = feeds.indexOf(id);
1222 return feeds[idx-1];
1224 return getRelativeFeedId(list, false, direction, unread_only);
1231 function showBlockElement(id, h_id) {
1232 var elem = document.getElementById(id);
1235 elem.style.display = "block";
1238 elem = document.getElementById(h_id);
1240 elem.style.display = "none";
1244 alert("[showBlockElement] can't find element with id " + id);
1248 function appearBlockElement_afh(effect) {
1252 function checkboxToggleElement(elem, id) {
1254 Effect.SlideDown(id, {duration : 0.5});
1256 Effect.SlideUp(id, {duration : 0.5});
1260 function appearBlockElement(id, h_id) {
1266 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1268 exception_error("appearBlockElement", e);
1273 function hideParentElement(e) {
1274 e.parentNode.style.display = "none";
1277 function dropboxSelect(e, v) {
1278 for (i = 0; i < e.length; i++) {
1279 if (e[i].value == v) {
1280 e.selectedIndex = i;
1286 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1287 // bugfixed just a little bit :-)
1288 function getURLParam(strParamName){
1290 var strHref = window.location.href;
1292 if (strHref.indexOf("#") == strHref.length-1) {
1293 strHref = strHref.substring(0, strHref.length-1);
1296 if ( strHref.indexOf("?") > -1 ){
1297 var strQueryString = strHref.substr(strHref.indexOf("?"));
1298 var aQueryString = strQueryString.split("&");
1299 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1300 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1301 var aParam = aQueryString[iParam].split("=");
1302 strReturn = aParam[1];
1310 function leading_zero(p) {
1312 if (s.length == 1) s = "0" + s;
1316 function closeInfoBox(cleanup) {
1318 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1319 var overlay = document.getElementById("dialog_overlay");
1321 overlay.style.display = "none";
1325 var box = document.getElementById('infoBox');
1326 var shadow = document.getElementById('infoBoxShadow');
1329 shadow.style.display = "none";
1331 box.style.display = "none";
1334 if (cleanup) box.innerHTML = " ";
1342 function displayDlg(id, param) {
1344 notify_progress("Loading, please wait...", true);
1348 var query = "backend.php?op=dlg&id=" +
1349 param_escape(id) + "¶m=" + param_escape(param);
1351 new Ajax.Request(query, {
1352 onComplete: function (transport) {
1353 infobox_callback2(transport);
1359 function infobox_submit_callback2(transport) {
1363 // called from prefs, reload tab
1365 selectTab(active_tab, false);
1369 if (transport.responseText) {
1370 notify_info(transport.responseText);
1374 function infobox_callback2(transport) {
1377 debug("infobox_callback2");
1379 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1380 var overlay = document.getElementById("dialog_overlay");
1382 overlay.style.display = "block";
1386 var box = document.getElementById('infoBox');
1387 var shadow = document.getElementById('infoBoxShadow');
1390 /* if (!is_safari()) {
1391 new Draggable(shadow);
1394 box.innerHTML=transport.responseText;
1396 shadow.style.display = "block";
1398 box.style.display = "block";
1402 /* FIXME this needs to be moved out somewhere */
1404 if (document.getElementById("tags_choices")) {
1405 new Ajax.Autocompleter('tags_str', 'tags_choices',
1406 "backend.php?op=rpc&subop=completeTags",
1407 { tokens: ',', paramName: "search" });
1412 exception_error("infobox_callback2", e);
1416 function createFilter() {
1418 var form = document.forms['filter_add_form'];
1419 var reg_exp = form.reg_exp.value;
1421 if (reg_exp == "") {
1422 alert(__("Can't add filter: nothing to match on."));
1426 var query = Form.serialize("filter_add_form");
1428 new Ajax.Request("backend.php?" + query, {
1429 onComplete: function (transport) {
1430 infobox_submit_callback2(transport);
1436 function toggleSubmitNotEmpty(e, submit_id) {
1438 document.getElementById(submit_id).disabled = (e.value == "")
1440 exception_error("toggleSubmitNotEmpty", e);
1444 function isValidURL(s) {
1445 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
1448 function subscribeToFeed() {
1450 var form = document.forms['feed_add_form'];
1451 var feed_url = form.feed_url.value;
1453 if (feed_url == "") {
1454 alert(__("Can't subscribe: no feed URL given."));
1458 notify_progress(__("Subscribing to feed..."), true);
1462 var feeds_doc = document;
1464 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1466 var query = Form.serialize("feed_add_form");
1468 debug("subscribe q: " + query);
1470 new Ajax.Request("backend.php", {
1472 onComplete: function(transport) {
1473 dlg_frefresh_callback(transport);
1479 function filterCR(e, f)
1484 key = window.event.keyCode; //IE
1486 key = e.which; //firefox
1489 if (typeof f != 'undefined') {
1500 function getMainContext() {
1504 function getFeedsContext() {
1508 function getContentContext() {
1512 function getHeadlinesContext() {
1516 var debug_last_class = "even";
1518 function debug(msg) {
1520 if (debug_last_class == "even") {
1521 debug_last_class = "odd";
1523 debug_last_class = "even";
1526 var c = document.getElementById('debug_output');
1527 if (c && c.style.display == "block") {
1528 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1529 c.removeChild(c.lastChild);
1533 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1534 ":" + leading_zero(d.getSeconds());
1535 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1536 msg + "</li>" + c.innerHTML;
1540 function getInitParam(key) {
1541 return init_params[key];
1544 function storeInitParam(key, value) {
1545 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
1546 init_params[key] = value;
1549 function fatalError(code, message) {
1553 window.location.href = "tt-rss.php";
1554 } else if (code == 5) {
1555 window.location.href = "update.php";
1557 var fe = document.getElementById("fatal_error");
1558 var fc = document.getElementById("fatal_error_msg");
1560 if (message == "") message = "Unknown error";
1562 fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
1564 fe.style.display = "block";
1568 exception_error("fatalError", e);
1572 function getFeedName(id, is_cat) {
1573 var d = getFeedsContext().document;
1578 e = d.getElementById("FCATN-" + id);
1580 e = d.getElementById("FEEDN-" + id);
1583 return e.innerHTML.stripTags();
1589 function viewContentUrl(url) {
1590 getContentContext().location = url;
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 = form.action_param;
1612 if (!action_param) {
1613 debug("filterDlgCheckAction: can't find action param!");
1617 // if selected action supports parameters, enable params field
1618 if (action == 4 || action == 6) {
1619 action_param.disabled = false;
1621 action_param.disabled = true;
1625 exception_error(e, "filterDlgCheckAction");
1630 function explainError(code) {
1631 return displayDlg("explainError", code);
1634 // this only searches loaded headlines list, not in CDM
1635 function getRelativePostIds(id) {
1637 debug("getRelativePostIds: " + id);
1639 var ids = new Array();
1640 var container = document.getElementById("headlinesList");
1643 var rows = container.rows;
1645 for (var i = 0; i < rows.length; i++) {
1646 var r_id = rows[i].id.replace("RROW-", "");
1649 if (i > 0) ids.push(rows[i-1].id.replace("RROW-", ""));
1650 if (i > 1) ids.push(rows[i-2].id.replace("RROW-", ""));
1651 if (i > 2) ids.push(rows[i-3].id.replace("RROW-", ""));
1653 if (i < rows.length-1) ids.push(rows[i+1].id.replace("RROW-", ""));
1654 if (i < rows.length-2) ids.push(rows[i+2].id.replace("RROW-", ""));
1655 if (i < rows.length-3) ids.push(rows[i+3].id.replace("RROW-", ""));
1665 function openArticleInNewWindow(id) {
1667 debug("openArticleInNewWindow: " + id);
1669 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1673 new Ajax.Request(query, {
1674 onComplete: function(transport) {
1675 open_article_callback(transport);
1680 exception_error("openArticleInNewWindow", e);
1684 /* http://textsnippets.com/posts/show/835 */
1686 Position.GetWindowSize = function(w) {
1688 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1689 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1690 return [width, height]
1693 /* http://textsnippets.com/posts/show/836 */
1695 Position.Center = function(element, parent) {
1697 var d = Element.getDimensions(element);
1702 var ws = Position.GetWindowSize();
1706 pw = parent.offsetWidth;
1707 ph = parent.offsetHeight;
1709 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1710 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1714 function labeltest_callback(transport) {
1716 var container = document.getElementById('label_test_result');
1718 container.innerHTML = transport.responseText;
1719 if (!Element.visible(container)) {
1720 Effect.SlideDown(container, { duration : 0.5 });
1725 exception_error("labeltest_callback", e);
1729 function labelTest() {
1732 var container = document.getElementById('label_test_result');
1734 var form = document.forms['label_edit_form'];
1736 var sql_exp = form.sql_exp.value;
1737 var description = form.description.value;
1739 notify_progress("Loading, please wait...");
1741 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1742 param_escape(sql_exp) + "&descr=" + param_escape(description);
1744 new Ajax.Request(query, {
1745 onComplete: function (transport) {
1746 labeltest_callback(transport);
1752 exception_error("labelTest", e);
1756 function isCdmMode() {
1757 return !document.getElementById("headlinesList");
1760 function getSelectedArticleIds2() {
1761 var rows = new Array();
1762 var cdm_mode = isCdmMode();
1765 rows = cdmGetSelectedArticles();
1767 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1770 var ids = new Array();
1772 for (var i = 0; i < rows.length; i++) {
1773 var chk = document.getElementById("RCHK-" + rows[i]);
1774 if (chk && chk.checked) {
1782 function displayHelpInfobox(topic_id) {
1784 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1786 var w = window.open(url, "ttrss_help",
1787 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");