1 var hotkeys_enabled = true;
2 var xmlhttp_rpc = Ajax.getTransport();
3 var notify_silent = false;
4 var last_progress_point = 0;
6 /* add method to remove element from array */
8 Array.prototype.remove = function(s) {
9 for (var i=0; i < this.length; i++) {
10 if (s == this[i]) this.splice(i, 1);
18 function exception_error(location, e, silent) {
22 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
24 msg = "Exception: " + e.name + ", " + e.message +
25 "\nFunction: " + location + "()" +
26 "\nLocation: " + base_fname + ":" + e.lineNumber;
28 } else if (e.description) {
29 msg = "Exception: " + e.description + "\nFunction: " + location + "()";
31 msg = "Exception: " + e + "\nFunction: " + location + "()";
34 debug("<b>EXCEPTION: " + msg + "</b>");
41 function disableHotkeys() {
42 hotkeys_enabled = false;
45 function enableHotkeys() {
46 hotkeys_enabled = true;
49 function xmlhttp_ready(obj) {
50 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
53 function open_article_callback(transport) {
56 if (transport.responseXML) {
58 var link = transport.responseXML.getElementsByTagName("link")[0];
59 var id = transport.responseXML.getElementsByTagName("id")[0];
61 debug("open_article_callback, received link: " + link);
65 var wname = "ttrss_article_" + id.firstChild.nodeValue;
67 debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
69 var w = window.open(link.firstChild.nodeValue, wname);
71 if (!w) { notify_error("Failed to load article in new window"); }
74 id = id.firstChild.nodeValue;
75 if (!document.getElementById("headlinesList")) {
76 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
80 notify_error("Can't open article: received invalid article link");
83 notify_error("Can't open article: received invalid XML");
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_silent_next() {
124 notify_silent = true;
127 function notify_real(msg, no_hide, n_type) {
130 notify_silent = false;
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 cleanSelected(element) {
209 var content = document.getElementById(element);
211 for (i = 0; i < content.rows.length; i++) {
212 content.rows[i].className = content.rows[i].className.replace("Selected", "");
216 function getVisibleUnreadHeadlines() {
217 var content = document.getElementById("headlinesList");
219 var rows = new Array();
221 if (!content) return rows;
223 for (i = 0; i < content.rows.length; i++) {
224 var row_id = content.rows[i].id.replace("RROW-", "");
225 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
232 function getVisibleHeadlineIds() {
234 var content = document.getElementById("headlinesList");
236 var rows = new Array();
238 if (!content) return rows;
240 for (i = 0; i < content.rows.length; i++) {
241 var row_id = content.rows[i].id.replace("RROW-", "");
242 if (row_id.length > 0) {
249 function getFirstVisibleHeadlineId() {
251 var rows = cdmGetVisibleArticles();
254 var rows = getVisibleHeadlineIds();
259 function getLastVisibleHeadlineId() {
261 var rows = cdmGetVisibleArticles();
262 return rows[rows.length-1];
264 var rows = getVisibleHeadlineIds();
265 return rows[rows.length-1];
269 function markHeadline(id) {
270 var row = document.getElementById("RROW-" + id);
272 var is_active = false;
274 if (row.className.match("Active")) {
277 row.className = row.className.replace("Selected", "");
278 row.className = row.className.replace("Active", "");
279 row.className = row.className.replace("Insensitive", "");
282 row.className = row.className = "Active";
285 var check = document.getElementById("RCHK-" + id);
288 check.checked = true;
291 row.className = row.className + "Selected";
296 function getFeedIds() {
297 var content = document.getElementById("feedsList");
299 var rows = new Array();
301 for (i = 0; i < content.rows.length; i++) {
302 var id = content.rows[i].id.replace("FEEDR-", "");
311 function setCookie(name, value, lifetime, path, domain, secure) {
317 d.setTime(d.getTime() + (lifetime * 1000));
320 debug("setCookie: " + name + " => " + value + ": " + d);
322 int_setCookie(name, value, d, path, domain, secure);
326 function int_setCookie(name, value, expires, path, domain, secure) {
327 document.cookie= name + "=" + escape(value) +
328 ((expires) ? "; expires=" + expires.toGMTString() : "") +
329 ((path) ? "; path=" + path : "") +
330 ((domain) ? "; domain=" + domain : "") +
331 ((secure) ? "; secure" : "");
334 function delCookie(name, path, domain) {
335 if (getCookie(name)) {
336 document.cookie = name + "=" +
337 ((path) ? ";path=" + path : "") +
338 ((domain) ? ";domain=" + domain : "" ) +
339 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
344 function getCookie(name) {
346 var dc = document.cookie;
347 var prefix = name + "=";
348 var begin = dc.indexOf("; " + prefix);
350 begin = dc.indexOf(prefix);
351 if (begin != 0) return null;
356 var end = document.cookie.indexOf(";", begin);
360 return unescape(dc.substring(begin + prefix.length, end));
363 function disableContainerChildren(id, disable, doc) {
365 if (!doc) doc = document;
367 var container = doc.getElementById(id);
370 //alert("disableContainerChildren: element " + id + " not found");
374 for (var i = 0; i < container.childNodes.length; i++) {
375 var child = container.childNodes[i];
378 child.disabled = disable;
384 if (child.className && child.className.match("button")) {
385 child.className = "disabledButton";
388 if (child.className && child.className.match("disabledButton")) {
389 child.className = "button";
396 function gotoPreferences() {
397 document.location.href = "prefs.php";
400 function gotoMain() {
401 document.location.href = "tt-rss.php";
404 function gotoExportOpml() {
405 document.location.href = "opml.php?op=Export";
408 function getActiveFeedId() {
409 // return getCookie("ttrss_vf_actfeed");
411 debug("gAFID: " + active_feed_id);
412 return active_feed_id;
414 exception_error("getActiveFeedId", e);
418 function activeFeedIsCat() {
419 return active_feed_is_cat;
422 function setActiveFeedId(id) {
423 // return setCookie("ttrss_vf_actfeed", id);
425 debug("sAFID(" + id + ")");
428 exception_error("setActiveFeedId", e);
432 function parse_counters(reply, scheduled_call) {
437 var elems = reply.getElementsByTagName("counter");
439 for (var l = 0; l < elems.length; l++) {
441 var id = elems[l].getAttribute("id");
442 var t = elems[l].getAttribute("type");
443 var ctr = elems[l].getAttribute("counter");
444 var error = elems[l].getAttribute("error");
445 var has_img = elems[l].getAttribute("hi");
446 var updated = elems[l].getAttribute("updated");
447 var title = elems[l].getAttribute("title");
448 var xmsg = elems[l].getAttribute("xmsg");
450 if (id == "global-unread") {
456 if (id == "subscribed-feeds") {
461 if (t == "category") {
462 var catctr = document.getElementById("FCATCTR-" + id);
464 catctr.innerHTML = "(" + ctr + ")";
466 catctr.className = "catCtrHasUnread";
468 catctr.className = "catCtrNoUnread";
474 var feedctr = document.getElementById("FEEDCTR-" + id);
475 var feedu = document.getElementById("FEEDU-" + id);
476 var feedr = document.getElementById("FEEDR-" + id);
477 var feed_img = document.getElementById("FIMG-" + id);
478 var feedlink = document.getElementById("FEEDL-" + id);
479 var feedupd = document.getElementById("FLUPD-" + id);
481 if (updated && feedlink) {
483 feedlink.title = "Error: " + error + " (" + updated + ")";
485 feedlink.title = "Updated: " + updated;
490 if (!updated) updated = "";
494 feedupd.innerHTML = updated + " " + xmsg + " (Error)";
496 feedupd.innerHTML = updated + " (Error)";
500 feedupd.innerHTML = updated + " " + xmsg;
502 feedupd.innerHTML = updated;
507 if (has_img && feed_img) {
508 if (!feed_img.src.match(id + ".ico")) {
509 feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
513 if (feedlink && title) {
514 feedlink.innerHTML = title;
517 if (feedctr && feedu && feedr) {
519 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
523 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
525 feedu.innerHTML = ctr;
528 feedr.className = feedr.className.replace("feed", "error");
530 feedr.className = feedr.className.replace("error", "feed");
534 feedctr.className = "odd";
535 if (!feedr.className.match("Unread")) {
536 var is_selected = feedr.className.match("Selected");
538 feedr.className = feedr.className.replace("Selected", "");
539 feedr.className = feedr.className.replace("Unread", "");
541 feedr.className = feedr.className + "Unread";
544 feedr.className = feedr.className + "Selected";
550 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
551 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
554 feedctr.className = "invisible";
555 feedr.className = feedr.className.replace("Unread", "");
560 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
562 var feeds_stored = number_of_feeds;
564 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
566 if (feeds_stored != feeds_found) {
567 number_of_feeds = feeds_found;
569 if (feeds_stored != 0 && feeds_found != 0) {
570 debug("Subscribed feed number changed, refreshing feedlist");
571 setTimeout('updateFeedList(false, false)', 50);
576 exception_error("parse_counters", e);
580 function parse_counters_reply(transport, scheduled_call) {
582 if (!transport.responseXML) {
583 notify_error("Backend did not return valid XML", true);
587 var reply = transport.responseXML.firstChild;
590 notify_error("Backend did not return expected XML object", true);
595 var error_code = false;
596 var error_msg = false;
598 if (reply.firstChild) {
599 error_code = reply.firstChild.getAttribute("error-code");
600 error_msg = reply.firstChild.getAttribute("error-msg");
604 error_code = reply.getAttribute("error-code");
605 error_msg = reply.getAttribute("error-msg");
608 if (error_code && error_code != 0) {
609 debug("refetch_callback: got error code " + error_code);
610 return fatalError(error_code, error_msg);
613 var counters = reply.getElementsByTagName("counters")[0];
615 parse_counters(counters, scheduled_call);
617 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
619 parse_runtime_info(runtime_info);
621 if (feedsSortByUnread()) {
625 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
629 function all_counters_callback2(transport) {
631 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
632 parse_counters_reply(transport);
633 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
636 exception_error("all_counters_callback2", e);
640 function get_feed_unread(id) {
642 return parseInt(document.getElementById("FEEDU-" + id).innerHTML);
644 exception_error("get_feed_unread", e, true);
649 function get_feed_entry_unread(elem) {
651 var id = elem.id.replace("FEEDR-", "");
658 return parseInt(document.getElementById("FEEDU-" + id).innerHTML);
664 function get_feed_entry_name(elem) {
665 var id = elem.id.replace("FEEDR-", "");
666 return getFeedName(id);
670 function resort_category(node) {
671 debug("resort_category: " + node);
673 var by_unread = feedsSortByUnread();
675 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
676 for (i = 0; i < node.childNodes.length; i++) {
677 if (node.childNodes[i].nodeName != "LI") { continue; }
679 if (get_feed_entry_unread(node.childNodes[i]) < 0) {
683 for (j = i+1; j < node.childNodes.length; j++) {
684 if (node.childNodes[j].nodeName != "LI") { continue; }
686 var tmp_val = get_feed_entry_unread(node.childNodes[i]);
687 var cur_val = get_feed_entry_unread(node.childNodes[j]);
689 var tmp_name = get_feed_entry_name(node.childNodes[i]);
690 var cur_name = get_feed_entry_name(node.childNodes[j]);
692 if ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name))) {
693 tempnode_i = node.childNodes[i].cloneNode(true);
694 tempnode_j = node.childNodes[j].cloneNode(true);
695 node.replaceChild(tempnode_i, node.childNodes[j]);
696 node.replaceChild(tempnode_j, node.childNodes[i]);
705 function resort_feedlist() {
706 debug("resort_feedlist");
708 if (document.getElementById("FCATLIST--1")) {
710 var lists = document.getElementsByTagName("UL");
712 for (var i = 0; i < lists.length; i++) {
713 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
714 resort_category(lists[i]);
719 resort_category(document.getElementById("feedList"));
723 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
724 * * @author Sundar Dorai-Raj
725 * * Email: sdoraira@vt.edu
726 * * This program is free software; you can redistribute it and/or
727 * * modify it under the terms of the GNU General Public License
728 * * as published by the Free Software Foundation; either version 2
729 * * of the License, or (at your option) any later version,
730 * * provided that any use properly credits the author.
731 * * This program is distributed in the hope that it will be useful,
732 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
733 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
734 * * GNU General Public License for more details at http://www.gnu.org * * */
736 var numbers=".0123456789";
737 function isNumeric(x) {
738 // is x a String or a character?
740 // remove negative sign
742 for(j=0;j<x.length;j++) {
743 // call isNumeric recursively for each character
744 number=isNumeric(x.substring(j,j+1));
745 if(!number) return number;
750 // if x is number return true
751 if(numbers.indexOf(x)>=0) return true;
757 function hideOrShowFeeds(hide) {
761 debug("hideOrShowFeeds: " + hide);
763 if (document.getElementById("FCATLIST--1")) {
765 var lists = document.getElementsByTagName("UL");
767 for (var i = 0; i < lists.length; i++) {
768 if (lists[i].id && lists[i].id.match("FCATLIST-")) {
770 var id = lists[i].id.replace("FCATLIST-", "");
771 hideOrShowFeedsCategory(id, hide);
776 hideOrShowFeedsCategory(null, hide);
780 exception_error("hideOrShowFeeds", e);
784 function hideOrShowFeedsCategory(id, hide) {
792 node = document.getElementById("FCATLIST-" + id);
793 cat_node = document.getElementById("FCAT-" + id);
795 node = document.getElementById("feedList"); // no categories
798 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
803 debug("hideOrShowFeeds: passed node is null, aborting");
807 // debug("cat: " + node.id);
809 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
810 for (i = 0; i < node.childNodes.length; i++) {
811 if (node.childNodes[i].nodeName != "LI") { continue; }
813 if (node.childNodes[i].style != undefined) {
815 var has_unread = (node.childNodes[i].className != "feed" &&
816 node.childNodes[i].className != "label" &&
817 !(!getInitParam("hide_read_shows_special") &&
818 node.childNodes[i].className == "virt") &&
819 node.childNodes[i].className != "error" &&
820 node.childNodes[i].className != "tag");
822 // debug(node.childNodes[i].id + " --> " + has_unread);
824 if (hide && !has_unread) {
825 //node.childNodes[i].style.display = "none";
826 var id = node.childNodes[i].id;
827 Effect.Fade(node.childNodes[i], {duration : 0.3,
828 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
832 node.childNodes[i].style.display = "list-item";
833 //Effect.Appear(node.childNodes[i], {duration : 0.3});
837 node.childNodes[i].style.display = "list-item";
839 //Effect.Appear(node.childNodes[i], {duration : 0.3});
840 //Effect.Highlight(node.childNodes[i]);
846 // debug("end cat: " + node.id + " unread " + cat_unread);
848 if (cat_unread == 0) {
849 if (cat_node.style == undefined) {
850 debug("ERROR: supplied cat_node " + cat_node +
851 " has no styles. WTF?");
855 //cat_node.style.display = "none";
856 Effect.Fade(cat_node, {duration : 0.3,
857 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
859 cat_node.style.display = "list-item";
863 cat_node.style.display = "list-item";
869 // debug("unread for category: " + cat_unread);
872 exception_error("hideOrShowFeedsCategory", e);
876 function selectTableRow(r, do_select) {
877 r.className = r.className.replace("Selected", "");
880 r.className = r.className + "Selected";
884 function selectTableRowById(elem_id, check_id, do_select) {
888 var row = document.getElementById(elem_id);
891 selectTableRow(row, do_select);
894 var check = document.getElementById(check_id);
897 check.checked = do_select;
900 exception_error("selectTableRowById", e);
904 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
905 classcheck, reset_others) {
907 var content = document.getElementById(content_id);
910 alert("[selectTableRows] Element " + content_id + " not found.");
914 for (i = 0; i < content.rows.length; i++) {
915 if (Element.visible(content.rows[i])) {
916 if (!classcheck || content.rows[i].className.match(classcheck)) {
918 if (content.rows[i].id.match(prefix)) {
919 selectTableRow(content.rows[i], do_select);
921 var row_id = content.rows[i].id.replace(prefix, "");
922 var check = document.getElementById(check_prefix + row_id);
925 check.checked = do_select;
927 } else if (reset_others) {
928 selectTableRow(content.rows[i], false);
930 var row_id = content.rows[i].id.replace(prefix, "");
931 var check = document.getElementById(check_prefix + row_id);
934 check.checked = false;
938 } else if (reset_others) {
939 selectTableRow(content.rows[i], false);
941 var row_id = content.rows[i].id.replace(prefix, "");
942 var check = document.getElementById(check_prefix + row_id);
945 check.checked = false;
953 function getSelectedTableRowIds(content_id, prefix) {
955 var content = document.getElementById(content_id);
958 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
962 var sel_rows = new Array();
964 for (i = 0; i < content.rows.length; i++) {
965 if (content.rows[i].id.match(prefix) &&
966 content.rows[i].className.match("Selected")) {
968 var row_id = content.rows[i].id.replace(prefix + "-", "");
969 sel_rows.push(row_id);
977 function toggleSelectRowById(sender, id) {
978 var row = document.getElementById(id);
980 if (sender.checked) {
981 if (!row.className.match("Selected")) {
982 row.className = row.className + "Selected";
985 if (row.className.match("Selected")) {
986 row.className = row.className.replace("Selected", "");
991 function toggleSelectListRow(sender) {
992 var parent_row = sender.parentNode;
994 if (sender.checked) {
995 if (!parent_row.className.match("Selected")) {
996 parent_row.className = parent_row.className + "Selected";
999 if (parent_row.className.match("Selected")) {
1000 parent_row.className = parent_row.className.replace("Selected", "");
1005 function tSR(sender) {
1006 return toggleSelectRow(sender);
1009 function toggleSelectRow(sender) {
1010 var parent_row = sender.parentNode.parentNode;
1012 if (sender.checked) {
1013 if (!parent_row.className.match("Selected")) {
1014 parent_row.className = parent_row.className + "Selected";
1017 if (parent_row.className.match("Selected")) {
1018 parent_row.className = parent_row.className.replace("Selected", "");
1023 function getRelativeFeedId(list, id, direction, unread_only) {
1024 var rows = list.getElementsByTagName("LI");
1025 var feeds = new Array();
1027 for (var i = 0; i < rows.length; i++) {
1028 if (rows[i].id.match("FEEDR-")) {
1030 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1033 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1034 feeds.push(rows[i].id.replace("FEEDR-", ""));
1041 if (direction == "next") {
1042 return feeds.shift();
1047 if (direction == "next") {
1048 var idx = feeds.indexOf(id);
1049 if (idx != -1 && idx < feeds.length) {
1050 return feeds[idx+1];
1052 return getRelativeFeedId(list, false, direction, unread_only);
1055 var idx = feeds.indexOf(id);
1057 return feeds[idx-1];
1059 return getRelativeFeedId(list, false, direction, unread_only);
1066 function showBlockElement(id, h_id) {
1067 var elem = document.getElementById(id);
1070 elem.style.display = "block";
1073 elem = document.getElementById(h_id);
1075 elem.style.display = "none";
1079 alert("[showBlockElement] can't find element with id " + id);
1083 function appearBlockElement_afh(effect) {
1087 function checkboxToggleElement(elem, id) {
1089 Effect.SlideDown(id, {duration : 0.5});
1091 Effect.SlideUp(id, {duration : 0.5});
1095 function appearBlockElement(id, h_id) {
1101 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1103 exception_error("appearBlockElement", e);
1108 function hideParentElement(e) {
1109 e.parentNode.style.display = "none";
1112 function dropboxSelect(e, v) {
1113 for (i = 0; i < e.length; i++) {
1114 if (e[i].value == v) {
1115 e.selectedIndex = i;
1121 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1122 // bugfixed just a little bit :-)
1123 function getURLParam(strParamName){
1125 var strHref = window.location.href;
1127 if (strHref.indexOf("#") == strHref.length-1) {
1128 strHref = strHref.substring(0, strHref.length-1);
1131 if ( strHref.indexOf("?") > -1 ){
1132 var strQueryString = strHref.substr(strHref.indexOf("?"));
1133 var aQueryString = strQueryString.split("&");
1134 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1135 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1136 var aParam = aQueryString[iParam].split("=");
1137 strReturn = aParam[1];
1145 function leading_zero(p) {
1147 if (s.length == 1) s = "0" + s;
1151 function closeInfoBox(cleanup) {
1153 Element.hide("dialog_overlay");
1155 var box = document.getElementById('infoBox');
1156 var shadow = document.getElementById('infoBoxShadow');
1159 shadow.style.display = "none";
1161 box.style.display = "none";
1164 if (cleanup) box.innerHTML = " ";
1172 function displayDlg(id, param) {
1174 notify_progress("Loading, please wait...", true);
1178 var query = "backend.php?op=dlg&id=" +
1179 param_escape(id) + "¶m=" + param_escape(param);
1181 new Ajax.Request(query, {
1182 onComplete: function (transport) {
1183 infobox_callback2(transport);
1189 function infobox_submit_callback2(transport) {
1193 // called from prefs, reload tab
1194 if (typeof active_tab != 'undefined' && active_tab) {
1195 selectTab(active_tab, false);
1199 if (transport.responseText) {
1200 notify_info(transport.responseText);
1204 function infobox_callback2(transport) {
1207 debug("infobox_callback2");
1209 if (!getInitParam("infobox_disable_overlay")) {
1210 Element.show("dialog_overlay");
1213 var box = document.getElementById('infoBox');
1214 var shadow = document.getElementById('infoBoxShadow');
1217 box.innerHTML=transport.responseText;
1219 shadow.style.display = "block";
1221 box.style.display = "block";
1225 /* FIXME this needs to be moved out somewhere */
1227 if (document.getElementById("tags_choices")) {
1228 new Ajax.Autocompleter('tags_str', 'tags_choices',
1229 "backend.php?op=rpc&subop=completeTags",
1230 { tokens: ',', paramName: "search" });
1237 exception_error("infobox_callback2", e);
1241 function createFilter() {
1245 var form = document.forms['filter_add_form'];
1246 var reg_exp = form.reg_exp.value;
1248 if (reg_exp == "") {
1249 alert(__("Can't add filter: nothing to match on."));
1253 var query = Form.serialize("filter_add_form");
1255 // we can be called from some other tab in Prefs
1256 if (typeof active_tab != 'undefined' && active_tab) {
1257 active_tab = "filterConfig";
1260 new Ajax.Request("backend.php?" + query, {
1261 onComplete: function (transport) {
1262 infobox_submit_callback2(transport);
1268 exception_error("createFilter", e);
1272 function toggleSubmitNotEmpty(e, submit_id) {
1274 document.getElementById(submit_id).disabled = (e.value == "")
1276 exception_error("toggleSubmitNotEmpty", e);
1280 function isValidURL(s) {
1281 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
1284 function subscribeToFeed() {
1286 var form = document.forms['feed_add_form'];
1287 var feed_url = form.feed_url.value;
1289 if (feed_url == "") {
1290 alert(__("Can't subscribe: no feed URL given."));
1294 notify_progress(__("Subscribing to feed..."), true);
1298 var feeds_doc = document;
1300 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1302 var query = Form.serialize("feed_add_form");
1304 debug("subscribe q: " + query);
1306 new Ajax.Request("backend.php", {
1308 onComplete: function(transport) {
1309 dlg_frefresh_callback(transport);
1315 function filterCR(e, f)
1320 key = window.event.keyCode; //IE
1322 key = e.which; //firefox
1325 if (typeof f != 'undefined') {
1336 function getMainContext() {
1340 function getFeedsContext() {
1344 function getContentContext() {
1348 function getHeadlinesContext() {
1352 var debug_last_class = "even";
1354 function debug(msg) {
1356 if (debug_last_class == "even") {
1357 debug_last_class = "odd";
1359 debug_last_class = "even";
1362 var c = document.getElementById('debug_output');
1363 if (c && Element.visible(c)) {
1364 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1365 c.removeChild(c.lastChild);
1369 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1370 ":" + leading_zero(d.getSeconds());
1371 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1372 msg + "</li>" + c.innerHTML;
1376 function getInitParam(key) {
1377 return init_params[key];
1380 function storeInitParam(key, value) {
1381 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
1382 init_params[key] = value;
1385 function fatalError(code, message) {
1389 window.location.href = "tt-rss.php";
1390 } else if (code == 5) {
1391 window.location.href = "update.php";
1393 var fe = document.getElementById("fatal_error");
1394 var fc = document.getElementById("fatal_error_msg");
1396 if (message == "") message = "Unknown error";
1398 fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
1400 fe.style.display = "block";
1404 exception_error("fatalError", e);
1408 function getFeedName(id, is_cat) {
1409 var d = getFeedsContext().document;
1414 e = d.getElementById("FCATN-" + id);
1416 e = d.getElementById("FEEDN-" + id);
1419 return e.innerHTML.stripTags();
1425 function viewContentUrl(url) {
1426 getContentContext().location = url;
1429 function filterDlgCheckAction(sender) {
1433 var action = sender[sender.selectedIndex].value;
1435 var form = document.forms["filter_add_form"];
1438 form = document.forms["filter_edit_form"];
1442 debug("filterDlgCheckAction: can't find form!");
1446 var action_param = form.action_param;
1448 if (!action_param) {
1449 debug("filterDlgCheckAction: can't find action param!");
1453 // if selected action supports parameters, enable params field
1454 if (action == 4 || action == 6) {
1455 action_param.disabled = false;
1457 action_param.disabled = true;
1461 exception_error("filterDlgCheckAction", e);
1466 function explainError(code) {
1467 return displayDlg("explainError", code);
1470 // this only searches loaded headlines list, not in CDM
1471 function getRelativePostIds(id, limit) {
1473 if (!limit) limit = 3;
1475 debug("getRelativePostIds: " + id + " limit=" + limit);
1477 var ids = new Array();
1478 var container = document.getElementById("headlinesList");
1481 var rows = container.rows;
1483 for (var i = 0; i < rows.length; i++) {
1484 var r_id = rows[i].id.replace("RROW-", "");
1487 for (var k = 1; k <= limit; k++) {
1490 if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
1491 if (nid) ids.push(nid);
1493 if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
1494 if (nid) ids.push(nid);
1505 function openArticleInNewWindow(id) {
1507 debug("openArticleInNewWindow: " + id);
1509 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1510 var wname = "ttrss_article_" + id;
1512 debug(query + " " + wname);
1514 var w = window.open("", wname);
1516 if (!w) notify_error("Failed to open window for the article");
1518 new Ajax.Request(query, {
1519 onComplete: function(transport) {
1520 open_article_callback(transport);
1525 exception_error("openArticleInNewWindow", e);
1529 /* http://textsnippets.com/posts/show/835 */
1531 Position.GetWindowSize = function(w) {
1533 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1534 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1535 return [width, height]
1538 /* http://textsnippets.com/posts/show/836 */
1540 Position.Center = function(element, parent) {
1542 var d = Element.getDimensions(element);
1547 var ws = Position.GetWindowSize();
1551 pw = parent.offsetWidth;
1552 ph = parent.offsetHeight;
1554 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1555 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1559 function labeltest_callback(transport) {
1561 var container = document.getElementById('label_test_result');
1563 container.innerHTML = transport.responseText;
1564 if (!Element.visible(container)) {
1565 Effect.SlideDown(container, { duration : 0.5 });
1570 exception_error("labeltest_callback", e);
1574 function labelTest() {
1577 var container = document.getElementById('label_test_result');
1579 var form = document.forms['label_edit_form'];
1581 var sql_exp = form.sql_exp.value;
1582 var description = form.description.value;
1584 notify_progress("Loading, please wait...");
1586 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1587 param_escape(sql_exp) + "&descr=" + param_escape(description);
1589 new Ajax.Request(query, {
1590 onComplete: function (transport) {
1591 labeltest_callback(transport);
1597 exception_error("labelTest", e);
1601 function isCdmMode() {
1602 return !document.getElementById("headlinesList");
1605 function getSelectedArticleIds2() {
1606 var rows = new Array();
1607 var cdm_mode = isCdmMode();
1610 rows = cdmGetSelectedArticles();
1612 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1615 var ids = new Array();
1617 for (var i = 0; i < rows.length; i++) {
1618 var chk = document.getElementById("RCHK-" + rows[i]);
1619 if (chk && chk.checked) {
1627 function displayHelpInfobox(topic_id) {
1629 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1631 var w = window.open(url, "ttrss_help",
1632 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1637 function focus_element(id) {
1639 var e = document.getElementById(id);
1642 exception_error("focus_element", e);
1647 function loading_set_progress(p) {
1649 if (p < last_progress_point || !Element.visible("overlay")) return;
1651 debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
1653 var o = document.getElementById("l_progress_i");
1655 // o.style.width = (p * 2) + "px";
1657 new Effect.Scale(o, p, {
1659 scaleFrom : last_progress_point,
1660 scaleMode: { originalWidth : 200 },
1661 queue: { position: 'end', scope: 'LSP-Q', limit: 3 } });
1663 last_progress_point = p;
1666 exception_error("loading_set_progress", e);
1670 function remove_splash() {
1671 if (Element.visible("overlay")) {
1672 debug("about to remove splash, OMG!");
1673 Element.hide("overlay");
1674 debug("removed splash!");