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);
79 var wname = "ttrss_article_" + id.firstChild.nodeValue;
81 debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
83 var w = window.open(link.firstChild.nodeValue, wname);
85 if (!w) { notify_error("Failed to load article in new window"); }
88 id = id.firstChild.nodeValue;
89 if (!document.getElementById("headlinesList")) {
90 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
94 notify_error("Can't open article: received invalid article link");
97 notify_error("Can't open article: received invalid XML");
101 exception_error("open_article_callback", e);
105 function param_escape(arg) {
106 if (typeof encodeURIComponent != 'undefined')
107 return encodeURIComponent(arg);
112 function param_unescape(arg) {
113 if (typeof decodeURIComponent != 'undefined')
114 return decodeURIComponent(arg);
116 return unescape(arg);
119 function delay(gap) {
121 then=new Date().getTime();
123 while((now-then)<gap) {
124 now=new Date().getTime();
128 var notify_hide_timerid = false;
130 function hide_notify() {
131 var n = document.getElementById("notify");
133 n.style.display = "none";
137 function notify_real(msg, no_hide, n_type) {
139 var n = document.getElementById("notify");
140 var nb = document.getElementById("notify_body");
142 if (!n || !nb) return;
144 if (notify_hide_timerid) {
145 window.clearTimeout(notify_hide_timerid);
149 if (n.style.display == "block") {
150 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
154 n.style.display = "block";
166 if (typeof __ != 'undefined') {
171 n.className = "notify";
172 } else if (n_type == 2) {
173 n.className = "notifyProgress";
174 msg = "<img src='images/indicator_white.gif'> " + msg;
175 } else if (n_type == 3) {
176 n.className = "notifyError";
177 msg = "<img src='images/sign_excl.gif'> " + msg;
178 } else if (n_type == 4) {
179 n.className = "notifyInfo";
180 msg = "<img src='images/sign_info.gif'> " + msg;
183 // msg = "<img src='images/live_com_loading.gif'> " + msg;
188 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
192 function notify(msg, no_hide) {
193 notify_real(msg, no_hide, 1);
196 function notify_progress(msg, no_hide) {
197 notify_real(msg, no_hide, 2);
200 function notify_error(msg, no_hide) {
201 notify_real(msg, no_hide, 3);
205 function notify_info(msg, no_hide) {
206 notify_real(msg, no_hide, 4);
209 function printLockingError() {
210 notify_info("Please wait until operation finishes.");
213 function cleanSelectedList(element) {
214 var content = document.getElementById(element);
216 if (!document.getElementById("feedCatHolder")) {
217 for (i = 0; i < content.childNodes.length; i++) {
218 var child = content.childNodes[i];
220 child.className = child.className.replace("Selected", "");
226 for (i = 0; i < content.childNodes.length; i++) {
227 var child = content.childNodes[i];
228 if (child.id == "feedCatHolder") {
230 var fcat = child.lastChild;
231 for (j = 0; j < fcat.childNodes.length; j++) {
232 var feed = fcat.childNodes[j];
233 feed.className = feed.className.replace("Selected", "");
241 function cleanSelected(element) {
242 var content = document.getElementById(element);
244 for (i = 0; i < content.rows.length; i++) {
245 content.rows[i].className = content.rows[i].className.replace("Selected", "");
249 function getVisibleUnreadHeadlines() {
250 var content = document.getElementById("headlinesList");
252 var rows = new Array();
254 for (i = 0; i < content.rows.length; i++) {
255 var row_id = content.rows[i].id.replace("RROW-", "");
256 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
263 function getVisibleHeadlineIds() {
265 var content = document.getElementById("headlinesList");
267 var rows = new Array();
269 for (i = 0; i < content.rows.length; i++) {
270 var row_id = content.rows[i].id.replace("RROW-", "");
271 if (row_id.length > 0) {
278 function getFirstVisibleHeadlineId() {
280 var rows = cdmGetVisibleArticles();
283 var rows = getVisibleHeadlineIds();
288 function getLastVisibleHeadlineId() {
290 var rows = cdmGetVisibleArticles();
291 return rows[rows.length-1];
293 var rows = getVisibleHeadlineIds();
294 return rows[rows.length-1];
298 function markHeadline(id) {
299 var row = document.getElementById("RROW-" + id);
301 var is_active = false;
303 if (row.className.match("Active")) {
306 row.className = row.className.replace("Selected", "");
307 row.className = row.className.replace("Active", "");
308 row.className = row.className.replace("Insensitive", "");
311 row.className = row.className = "Active";
314 var check = document.getElementById("RCHK-" + id);
317 check.checked = true;
320 row.className = row.className + "Selected";
325 function getFeedIds() {
326 var content = document.getElementById("feedsList");
328 var rows = new Array();
330 for (i = 0; i < content.rows.length; i++) {
331 var id = content.rows[i].id.replace("FEEDR-", "");
340 function setCookie(name, value, lifetime, path, domain, secure) {
346 d.setTime(d.getTime() + (lifetime * 1000));
349 debug("setCookie: " + name + " => " + value + ": " + d);
351 int_setCookie(name, value, d, path, domain, secure);
355 function int_setCookie(name, value, expires, path, domain, secure) {
356 document.cookie= name + "=" + escape(value) +
357 ((expires) ? "; expires=" + expires.toGMTString() : "") +
358 ((path) ? "; path=" + path : "") +
359 ((domain) ? "; domain=" + domain : "") +
360 ((secure) ? "; secure" : "");
363 function delCookie(name, path, domain) {
364 if (getCookie(name)) {
365 document.cookie = name + "=" +
366 ((path) ? ";path=" + path : "") +
367 ((domain) ? ";domain=" + domain : "" ) +
368 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
373 function getCookie(name) {
375 var dc = document.cookie;
376 var prefix = name + "=";
377 var begin = dc.indexOf("; " + prefix);
379 begin = dc.indexOf(prefix);
380 if (begin != 0) return null;
385 var end = document.cookie.indexOf(";", begin);
389 return unescape(dc.substring(begin + prefix.length, end));
392 function disableContainerChildren(id, disable, doc) {
394 if (!doc) doc = document;
396 var container = doc.getElementById(id);
399 //alert("disableContainerChildren: element " + id + " not found");
403 for (var i = 0; i < container.childNodes.length; i++) {
404 var child = container.childNodes[i];
407 child.disabled = disable;
413 if (child.className && child.className.match("button")) {
414 child.className = "disabledButton";
417 if (child.className && child.className.match("disabledButton")) {
418 child.className = "button";
425 function gotoPreferences() {
426 document.location.href = "prefs.php";
429 function gotoMain() {
430 document.location.href = "tt-rss.php";
433 function gotoExportOpml() {
434 document.location.href = "opml.php?op=Export";
437 function getActiveFeedId() {
438 // return getCookie("ttrss_vf_actfeed");
440 debug("gAFID: " + active_feed_id);
441 return active_feed_id;
443 exception_error("getActiveFeedId", e);
447 function activeFeedIsCat() {
448 return active_feed_is_cat;
451 function setActiveFeedId(id) {
452 // return setCookie("ttrss_vf_actfeed", id);
454 debug("sAFID(" + id + ")");
457 exception_error("setActiveFeedId", e);
461 function parse_counters(reply, scheduled_call) {
466 var elems = reply.getElementsByTagName("counter");
468 for (var l = 0; l < elems.length; l++) {
470 var id = elems[l].getAttribute("id");
471 var t = elems[l].getAttribute("type");
472 var ctr = elems[l].getAttribute("counter");
473 var error = elems[l].getAttribute("error");
474 var has_img = elems[l].getAttribute("hi");
475 var updated = elems[l].getAttribute("updated");
476 var title = elems[l].getAttribute("title");
478 if (id == "global-unread") {
484 if (id == "subscribed-feeds") {
489 if (t == "category") {
490 var catctr = document.getElementById("FCATCTR-" + id);
492 catctr.innerHTML = "(" + ctr + ")";
494 catctr.className = "catCtrHasUnread";
496 catctr.className = "catCtrNoUnread";
502 var feedctr = document.getElementById("FEEDCTR-" + id);
503 var feedu = document.getElementById("FEEDU-" + id);
504 var feedr = document.getElementById("FEEDR-" + id);
505 var feed_img = document.getElementById("FIMG-" + id);
506 var feedlink = document.getElementById("FEEDL-" + id);
507 var feedupd = document.getElementById("FLUPD-" + id);
509 if (updated && feedlink) {
511 feedlink.title = "Error: " + error + " (" + updated + ")";
513 feedlink.title = "Updated: " + updated;
517 if (updated && feedupd) {
519 feedupd.innerHTML = updated + " (Error)";
521 feedupd.innerHTML = updated;
525 if (has_img && feed_img && !is_msie()) {
526 if (!feed_img.src.match(id + ".ico")) {
527 feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
531 if (feedlink && title) {
532 feedlink.innerHTML = title;
535 if (feedctr && feedu && feedr) {
537 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
541 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
543 feedu.innerHTML = ctr;
546 feedr.className = feedr.className.replace("feed", "error");
548 feedr.className = feedr.className.replace("error", "feed");
552 feedctr.className = "odd";
553 if (!feedr.className.match("Unread")) {
554 var is_selected = feedr.className.match("Selected");
556 feedr.className = feedr.className.replace("Selected", "");
557 feedr.className = feedr.className.replace("Unread", "");
559 feedr.className = feedr.className + "Unread";
562 feedr.className = feedr.className + "Selected";
568 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
569 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
572 feedctr.className = "invisible";
573 feedr.className = feedr.className.replace("Unread", "");
578 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
580 var feeds_stored = number_of_feeds;
582 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
584 if (feeds_stored != feeds_found) {
585 number_of_feeds = feeds_found;
587 if (feeds_stored != 0 && feeds_found != 0) {
588 debug("Subscribed feed number changed, refreshing feedlist");
589 setTimeout('updateFeedList(false, false)', 50);
594 exception_error("parse_counters", e);
598 function parse_counters_reply(transport, scheduled_call) {
600 if (!transport.responseXML) {
601 notify_error("Backend did not return valid XML", true);
605 var reply = transport.responseXML.firstChild;
608 notify_error("Backend did not return expected XML object", true);
613 var error_code = false;
614 var error_msg = false;
616 if (reply.firstChild) {
617 error_code = reply.firstChild.getAttribute("error-code");
618 error_msg = reply.firstChild.getAttribute("error-msg");
622 error_code = reply.getAttribute("error-code");
623 error_msg = reply.getAttribute("error-msg");
626 if (error_code && error_code != 0) {
627 debug("refetch_callback: got error code " + error_code);
628 return fatalError(error_code, error_msg);
631 var counters = reply.getElementsByTagName("counters")[0];
633 parse_counters(counters, scheduled_call);
635 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
637 parse_runtime_info(runtime_info);
639 if (getInitParam("feeds_sort_by_unread") == 1) {
643 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
647 function all_counters_callback2(transport) {
649 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
650 parse_counters_reply(transport);
651 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
654 exception_error("all_counters_callback2", e);
658 function get_feed_unread(id) {
660 return parseInt(document.getElementById("FEEDU-" + id).innerHTML);
662 exception_error("get_feed_unread", e, true);
667 function get_feed_entry_unread(doc, elem) {
669 var id = elem.id.replace("FEEDR-", "");
676 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
682 function resort_category(doc, node) {
683 debug("resort_category: " + node);
685 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
686 for (i = 0; i < node.childNodes.length; i++) {
687 if (node.childNodes[i].nodeName != "LI") { continue; }
689 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
693 for (j = i+1; j < node.childNodes.length; j++) {
694 if (node.childNodes[j].nodeName != "LI") { continue; }
696 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
697 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
699 if (cur_val > tmp_val) {
700 tempnode_i = node.childNodes[i].cloneNode(true);
701 tempnode_j = node.childNodes[j].cloneNode(true);
702 node.replaceChild(tempnode_i, node.childNodes[j]);
703 node.replaceChild(tempnode_j, node.childNodes[i]);
712 function resort_feedlist() {
713 debug("resort_feedlist");
717 if (fd.getElementById("feedCatHolder")) {
719 var feeds = fd.getElementById("feedList");
720 var child = feeds.firstChild;
724 if (child.id == "feedCatHolder") {
725 resort_category(fd, child.firstChild);
728 child = child.nextSibling;
732 resort_category(fd, fd.getElementById("feedList"));
736 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
737 * * @author Sundar Dorai-Raj
738 * * Email: sdoraira@vt.edu
739 * * This program is free software; you can redistribute it and/or
740 * * modify it under the terms of the GNU General Public License
741 * * as published by the Free Software Foundation; either version 2
742 * * of the License, or (at your option) any later version,
743 * * provided that any use properly credits the author.
744 * * This program is distributed in the hope that it will be useful,
745 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
746 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
747 * * GNU General Public License for more details at http://www.gnu.org * * */
749 var numbers=".0123456789";
750 function isNumeric(x) {
751 // is x a String or a character?
753 // remove negative sign
755 for(j=0;j<x.length;j++) {
756 // call isNumeric recursively for each character
757 number=isNumeric(x.substring(j,j+1));
758 if(!number) return number;
763 // if x is number return true
764 if(numbers.indexOf(x)>=0) return true;
770 function hideOrShowFeeds(doc, hide) {
772 debug("hideOrShowFeeds: " + doc + ", " + hide);
776 var list = fd.getElementById("feedList");
778 if (fd.getElementById("feedCatHolder")) {
780 var feeds = fd.getElementById("feedList");
781 var child = feeds.firstChild;
785 if (child.id == "feedCatHolder") {
786 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
789 child = child.nextSibling;
793 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
797 function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
799 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
804 debug("hideOrShowFeeds: passed node is null, aborting");
808 // debug("cat: " + node.id);
810 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
811 for (i = 0; i < node.childNodes.length; i++) {
812 if (node.childNodes[i].nodeName != "LI") { continue; }
814 if (node.childNodes[i].style != undefined) {
816 var has_unread = (node.childNodes[i].className != "feed" &&
817 node.childNodes[i].className != "label" &&
818 !(!getInitParam("hide_read_shows_special") &&
819 node.childNodes[i].className == "virt") &&
820 node.childNodes[i].className != "error" &&
821 node.childNodes[i].className != "tag");
823 // debug(node.childNodes[i].id + " --> " + has_unread);
825 if (hide && !has_unread) {
826 //node.childNodes[i].style.display = "none";
827 var id = node.childNodes[i].id;
828 Effect.Fade(node.childNodes[i], {duration : 0.3,
829 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
833 node.childNodes[i].style.display = "list-item";
834 //Effect.Appear(node.childNodes[i], {duration : 0.3});
838 node.childNodes[i].style.display = "list-item";
840 //Effect.Appear(node.childNodes[i], {duration : 0.3});
841 //Effect.Highlight(node.childNodes[i]);
847 // debug("end cat: " + node.id + " unread " + cat_unread);
849 if (cat_unread == 0) {
850 if (cat_node.style == undefined) {
851 debug("ERROR: supplied cat_node " + cat_node +
852 " has no styles. WTF?");
856 //cat_node.style.display = "none";
857 Effect.Fade(cat_node, {duration : 0.3,
858 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
860 cat_node.style.display = "list-item";
864 cat_node.style.display = "list-item";
870 // debug("unread for category: " + cat_unread);
873 function selectTableRow(r, do_select) {
874 r.className = r.className.replace("Selected", "");
877 r.className = r.className + "Selected";
881 function selectTableRowById(elem_id, check_id, do_select) {
885 var row = document.getElementById(elem_id);
888 selectTableRow(row, do_select);
891 var check = document.getElementById(check_id);
894 check.checked = do_select;
897 exception_error("selectTableRowById", e);
901 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
902 classcheck, reset_others) {
904 var content = document.getElementById(content_id);
907 alert("[selectTableRows] Element " + content_id + " not found.");
911 for (i = 0; i < content.rows.length; i++) {
912 if (Element.visible(content.rows[i])) {
913 if (!classcheck || content.rows[i].className.match(classcheck)) {
915 if (content.rows[i].id.match(prefix)) {
916 selectTableRow(content.rows[i], do_select);
918 var row_id = content.rows[i].id.replace(prefix, "");
919 var check = document.getElementById(check_prefix + row_id);
922 check.checked = do_select;
924 } else if (reset_others) {
925 selectTableRow(content.rows[i], false);
927 var row_id = content.rows[i].id.replace(prefix, "");
928 var check = document.getElementById(check_prefix + row_id);
931 check.checked = false;
935 } else if (reset_others) {
936 selectTableRow(content.rows[i], false);
938 var row_id = content.rows[i].id.replace(prefix, "");
939 var check = document.getElementById(check_prefix + row_id);
942 check.checked = false;
950 function getSelectedTableRowIds(content_id, prefix) {
952 var content = document.getElementById(content_id);
955 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
959 var sel_rows = new Array();
961 for (i = 0; i < content.rows.length; i++) {
962 if (content.rows[i].id.match(prefix) &&
963 content.rows[i].className.match("Selected")) {
965 var row_id = content.rows[i].id.replace(prefix + "-", "");
966 sel_rows.push(row_id);
974 function toggleSelectRowById(sender, id) {
975 var row = document.getElementById(id);
977 if (sender.checked) {
978 if (!row.className.match("Selected")) {
979 row.className = row.className + "Selected";
982 if (row.className.match("Selected")) {
983 row.className = row.className.replace("Selected", "");
988 function toggleSelectListRow(sender) {
989 var parent_row = sender.parentNode;
991 if (sender.checked) {
992 if (!parent_row.className.match("Selected")) {
993 parent_row.className = parent_row.className + "Selected";
996 if (parent_row.className.match("Selected")) {
997 parent_row.className = parent_row.className.replace("Selected", "");
1002 function tSR(sender) {
1003 return toggleSelectRow(sender);
1006 function toggleSelectRow(sender) {
1007 var parent_row = sender.parentNode.parentNode;
1009 if (sender.checked) {
1010 if (!parent_row.className.match("Selected")) {
1011 parent_row.className = parent_row.className + "Selected";
1014 if (parent_row.className.match("Selected")) {
1015 parent_row.className = parent_row.className.replace("Selected", "");
1020 function getRelativeFeedId(list, id, direction, unread_only) {
1021 var rows = list.getElementsByTagName("LI");
1022 var feeds = new Array();
1024 for (var i = 0; i < rows.length; i++) {
1025 if (rows[i].id.match("FEEDR-")) {
1027 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1030 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1031 feeds.push(rows[i].id.replace("FEEDR-", ""));
1038 if (direction == "next") {
1039 return feeds.shift();
1044 if (direction == "next") {
1045 var idx = feeds.indexOf(id);
1046 if (idx != -1 && idx < feeds.length) {
1047 return feeds[idx+1];
1049 return getRelativeFeedId(list, false, direction, unread_only);
1052 var idx = feeds.indexOf(id);
1054 return feeds[idx-1];
1056 return getRelativeFeedId(list, false, direction, unread_only);
1063 function showBlockElement(id, h_id) {
1064 var elem = document.getElementById(id);
1067 elem.style.display = "block";
1070 elem = document.getElementById(h_id);
1072 elem.style.display = "none";
1076 alert("[showBlockElement] can't find element with id " + id);
1080 function appearBlockElement_afh(effect) {
1084 function checkboxToggleElement(elem, id) {
1086 Effect.SlideDown(id, {duration : 0.5});
1088 Effect.SlideUp(id, {duration : 0.5});
1092 function appearBlockElement(id, h_id) {
1098 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1100 exception_error("appearBlockElement", e);
1105 function hideParentElement(e) {
1106 e.parentNode.style.display = "none";
1109 function dropboxSelect(e, v) {
1110 for (i = 0; i < e.length; i++) {
1111 if (e[i].value == v) {
1112 e.selectedIndex = i;
1118 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1119 // bugfixed just a little bit :-)
1120 function getURLParam(strParamName){
1122 var strHref = window.location.href;
1124 if (strHref.indexOf("#") == strHref.length-1) {
1125 strHref = strHref.substring(0, strHref.length-1);
1128 if ( strHref.indexOf("?") > -1 ){
1129 var strQueryString = strHref.substr(strHref.indexOf("?"));
1130 var aQueryString = strQueryString.split("&");
1131 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1132 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1133 var aParam = aQueryString[iParam].split("=");
1134 strReturn = aParam[1];
1142 function leading_zero(p) {
1144 if (s.length == 1) s = "0" + s;
1148 function closeInfoBox(cleanup) {
1150 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1151 var overlay = document.getElementById("dialog_overlay");
1153 overlay.style.display = "none";
1157 var box = document.getElementById('infoBox');
1158 var shadow = document.getElementById('infoBoxShadow');
1161 shadow.style.display = "none";
1163 box.style.display = "none";
1166 if (cleanup) box.innerHTML = " ";
1174 function displayDlg(id, param) {
1176 notify_progress("Loading, please wait...", true);
1180 var query = "backend.php?op=dlg&id=" +
1181 param_escape(id) + "¶m=" + param_escape(param);
1183 new Ajax.Request(query, {
1184 onComplete: function (transport) {
1185 infobox_callback2(transport);
1191 function infobox_submit_callback2(transport) {
1195 // called from prefs, reload tab
1197 selectTab(active_tab, false);
1201 if (transport.responseText) {
1202 notify_info(transport.responseText);
1206 function infobox_callback2(transport) {
1209 debug("infobox_callback2");
1211 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1212 var overlay = document.getElementById("dialog_overlay");
1214 overlay.style.display = "block";
1218 var box = document.getElementById('infoBox');
1219 var shadow = document.getElementById('infoBoxShadow');
1222 /* if (!is_safari()) {
1223 new Draggable(shadow);
1226 box.innerHTML=transport.responseText;
1228 shadow.style.display = "block";
1230 box.style.display = "block";
1234 /* FIXME this needs to be moved out somewhere */
1236 if (document.getElementById("tags_choices")) {
1237 new Ajax.Autocompleter('tags_str', 'tags_choices',
1238 "backend.php?op=rpc&subop=completeTags",
1239 { tokens: ',', paramName: "search" });
1246 exception_error("infobox_callback2", e);
1250 function createFilter() {
1252 var form = document.forms['filter_add_form'];
1253 var reg_exp = form.reg_exp.value;
1255 if (reg_exp == "") {
1256 alert(__("Can't add filter: nothing to match on."));
1260 var query = Form.serialize("filter_add_form");
1262 // we can be called from some other tab in Prefs
1263 if (active_tab) active_tab = "filterConfig";
1265 new Ajax.Request("backend.php?" + query, {
1266 onComplete: function (transport) {
1267 infobox_submit_callback2(transport);
1273 function toggleSubmitNotEmpty(e, submit_id) {
1275 document.getElementById(submit_id).disabled = (e.value == "")
1277 exception_error("toggleSubmitNotEmpty", e);
1281 function isValidURL(s) {
1282 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
1285 function subscribeToFeed() {
1287 var form = document.forms['feed_add_form'];
1288 var feed_url = form.feed_url.value;
1290 if (feed_url == "") {
1291 alert(__("Can't subscribe: no feed URL given."));
1295 notify_progress(__("Subscribing to feed..."), true);
1299 var feeds_doc = document;
1301 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1303 var query = Form.serialize("feed_add_form");
1305 debug("subscribe q: " + query);
1307 new Ajax.Request("backend.php", {
1309 onComplete: function(transport) {
1310 dlg_frefresh_callback(transport);
1316 function filterCR(e, f)
1321 key = window.event.keyCode; //IE
1323 key = e.which; //firefox
1326 if (typeof f != 'undefined') {
1337 function getMainContext() {
1341 function getFeedsContext() {
1345 function getContentContext() {
1349 function getHeadlinesContext() {
1353 var debug_last_class = "even";
1355 function debug(msg) {
1357 if (debug_last_class == "even") {
1358 debug_last_class = "odd";
1360 debug_last_class = "even";
1363 var c = document.getElementById('debug_output');
1364 if (c && c.style.display == "block") {
1365 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1366 c.removeChild(c.lastChild);
1370 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1371 ":" + leading_zero(d.getSeconds());
1372 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1373 msg + "</li>" + c.innerHTML;
1377 function getInitParam(key) {
1378 return init_params[key];
1381 function storeInitParam(key, value) {
1382 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
1383 init_params[key] = value;
1386 function fatalError(code, message) {
1390 window.location.href = "tt-rss.php";
1391 } else if (code == 5) {
1392 window.location.href = "update.php";
1394 var fe = document.getElementById("fatal_error");
1395 var fc = document.getElementById("fatal_error_msg");
1397 if (message == "") message = "Unknown error";
1399 fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
1401 fe.style.display = "block";
1405 exception_error("fatalError", e);
1409 function getFeedName(id, is_cat) {
1410 var d = getFeedsContext().document;
1415 e = d.getElementById("FCATN-" + id);
1417 e = d.getElementById("FEEDN-" + id);
1420 return e.innerHTML.stripTags();
1426 function viewContentUrl(url) {
1427 getContentContext().location = url;
1430 function filterDlgCheckAction(sender) {
1434 var action = sender[sender.selectedIndex].value;
1436 var form = document.forms["filter_add_form"];
1439 form = document.forms["filter_edit_form"];
1443 debug("filterDlgCheckAction: can't find form!");
1447 var action_param = form.action_param;
1449 if (!action_param) {
1450 debug("filterDlgCheckAction: can't find action param!");
1454 // if selected action supports parameters, enable params field
1455 if (action == 4 || action == 6) {
1456 action_param.disabled = false;
1458 action_param.disabled = true;
1462 exception_error(e, "filterDlgCheckAction");
1467 function explainError(code) {
1468 return displayDlg("explainError", code);
1471 // this only searches loaded headlines list, not in CDM
1472 function getRelativePostIds(id) {
1474 debug("getRelativePostIds: " + id);
1476 var ids = new Array();
1477 var container = document.getElementById("headlinesList");
1480 var rows = container.rows;
1482 for (var i = 0; i < rows.length; i++) {
1483 var r_id = rows[i].id.replace("RROW-", "");
1486 if (i > 0) ids.push(rows[i-1].id.replace("RROW-", ""));
1487 if (i > 1) ids.push(rows[i-2].id.replace("RROW-", ""));
1488 if (i > 2) ids.push(rows[i-3].id.replace("RROW-", ""));
1490 if (i < rows.length-1) ids.push(rows[i+1].id.replace("RROW-", ""));
1491 if (i < rows.length-2) ids.push(rows[i+2].id.replace("RROW-", ""));
1492 if (i < rows.length-3) ids.push(rows[i+3].id.replace("RROW-", ""));
1502 function openArticleInNewWindow(id) {
1504 debug("openArticleInNewWindow: " + id);
1506 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1507 var wname = "ttrss_article_" + id;
1509 debug(query + " " + wname);
1511 var w = window.open("", wname);
1513 if (!w) notify_error("Failed to open window for the article");
1515 new Ajax.Request(query, {
1516 onComplete: function(transport) {
1517 open_article_callback(transport);
1522 exception_error("openArticleInNewWindow", e);
1526 /* http://textsnippets.com/posts/show/835 */
1528 Position.GetWindowSize = function(w) {
1530 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1531 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1532 return [width, height]
1535 /* http://textsnippets.com/posts/show/836 */
1537 Position.Center = function(element, parent) {
1539 var d = Element.getDimensions(element);
1544 var ws = Position.GetWindowSize();
1548 pw = parent.offsetWidth;
1549 ph = parent.offsetHeight;
1551 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1552 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1556 function labeltest_callback(transport) {
1558 var container = document.getElementById('label_test_result');
1560 container.innerHTML = transport.responseText;
1561 if (!Element.visible(container)) {
1562 Effect.SlideDown(container, { duration : 0.5 });
1567 exception_error("labeltest_callback", e);
1571 function labelTest() {
1574 var container = document.getElementById('label_test_result');
1576 var form = document.forms['label_edit_form'];
1578 var sql_exp = form.sql_exp.value;
1579 var description = form.description.value;
1581 notify_progress("Loading, please wait...");
1583 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1584 param_escape(sql_exp) + "&descr=" + param_escape(description);
1586 new Ajax.Request(query, {
1587 onComplete: function (transport) {
1588 labeltest_callback(transport);
1594 exception_error("labelTest", e);
1598 function isCdmMode() {
1599 return !document.getElementById("headlinesList");
1602 function getSelectedArticleIds2() {
1603 var rows = new Array();
1604 var cdm_mode = isCdmMode();
1607 rows = cdmGetSelectedArticles();
1609 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1612 var ids = new Array();
1614 for (var i = 0; i < rows.length; i++) {
1615 var chk = document.getElementById("RCHK-" + rows[i]);
1616 if (chk && chk.checked) {
1624 function displayHelpInfobox(topic_id) {
1626 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1628 var w = window.open(url, "ttrss_help",
1629 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1634 function focus_element(id) {
1636 var e = document.getElementById(id);
1639 exception_error(e, "focus_element");