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);
15 return navigator.userAgent.match("MSIE");
22 function exception_error(location, e, silent) {
26 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
28 msg = "Exception: " + e.name + ", " + e.message +
29 "\nFunction: " + location + "()" +
30 "\nLocation: " + base_fname + ":" + e.lineNumber;
33 msg = "Exception: " + e + "\nFunction: " + location + "()";
36 debug("<b>EXCEPTION: " + msg + "</b>");
43 function disableHotkeys() {
44 hotkeys_enabled = false;
47 function enableHotkeys() {
48 hotkeys_enabled = true;
51 function xmlhttp_ready(obj) {
52 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
55 function open_article_callback(transport) {
58 if (transport.responseXML) {
60 var link = transport.responseXML.getElementsByTagName("link")[0];
61 var id = transport.responseXML.getElementsByTagName("id")[0];
63 debug("open_article_callback, received link: " + link);
67 var wname = "ttrss_article_" + id.firstChild.nodeValue;
69 debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
71 var w = window.open(link.firstChild.nodeValue, wname);
73 if (!w) { notify_error("Failed to load article in new window"); }
76 id = id.firstChild.nodeValue;
77 if (!document.getElementById("headlinesList")) {
78 window.setTimeout("toggleUnread(" + id + ", 0)", 100);
82 notify_error("Can't open article: received invalid article link");
85 notify_error("Can't open article: received invalid XML");
89 exception_error("open_article_callback", e);
93 function param_escape(arg) {
94 if (typeof encodeURIComponent != 'undefined')
95 return encodeURIComponent(arg);
100 function param_unescape(arg) {
101 if (typeof decodeURIComponent != 'undefined')
102 return decodeURIComponent(arg);
104 return unescape(arg);
107 function delay(gap) {
109 then=new Date().getTime();
111 while((now-then)<gap) {
112 now=new Date().getTime();
116 var notify_hide_timerid = false;
118 function hide_notify() {
119 var n = document.getElementById("notify");
121 n.style.display = "none";
125 function notify_silent_next() {
126 notify_silent = true;
129 function notify_real(msg, no_hide, n_type) {
132 notify_silent = false;
136 var n = document.getElementById("notify");
137 var nb = document.getElementById("notify_body");
139 if (!n || !nb) return;
141 if (notify_hide_timerid) {
142 window.clearTimeout(notify_hide_timerid);
146 if (n.style.display == "block") {
147 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
151 n.style.display = "block";
163 if (typeof __ != 'undefined') {
168 n.className = "notify";
169 } else if (n_type == 2) {
170 n.className = "notifyProgress";
171 msg = "<img src='images/indicator_white.gif'> " + msg;
172 } else if (n_type == 3) {
173 n.className = "notifyError";
174 msg = "<img src='images/sign_excl.gif'> " + msg;
175 } else if (n_type == 4) {
176 n.className = "notifyInfo";
177 msg = "<img src='images/sign_info.gif'> " + msg;
180 // msg = "<img src='images/live_com_loading.gif'> " + msg;
185 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
189 function notify(msg, no_hide) {
190 notify_real(msg, no_hide, 1);
193 function notify_progress(msg, no_hide) {
194 notify_real(msg, no_hide, 2);
197 function notify_error(msg, no_hide) {
198 notify_real(msg, no_hide, 3);
202 function notify_info(msg, no_hide) {
203 notify_real(msg, no_hide, 4);
206 function printLockingError() {
207 notify_info("Please wait until operation finishes.");
210 function cleanSelectedList(element) {
211 var content = document.getElementById(element);
213 if (!document.getElementById("feedCatHolder")) {
214 for (i = 0; i < content.childNodes.length; i++) {
215 var child = content.childNodes[i];
217 child.className = child.className.replace("Selected", "");
223 for (i = 0; i < content.childNodes.length; i++) {
224 var child = content.childNodes[i];
225 if (child.id == "feedCatHolder") {
227 var fcat = child.lastChild;
228 for (j = 0; j < fcat.childNodes.length; j++) {
229 var feed = fcat.childNodes[j];
230 feed.className = feed.className.replace("Selected", "");
238 function cleanSelected(element) {
239 var content = document.getElementById(element);
241 for (i = 0; i < content.rows.length; i++) {
242 content.rows[i].className = content.rows[i].className.replace("Selected", "");
246 function getVisibleUnreadHeadlines() {
247 var content = document.getElementById("headlinesList");
249 var rows = new Array();
251 if (!content) return rows;
253 for (i = 0; i < content.rows.length; i++) {
254 var row_id = content.rows[i].id.replace("RROW-", "");
255 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
262 function getVisibleHeadlineIds() {
264 var content = document.getElementById("headlinesList");
266 var rows = new Array();
268 if (!content) return rows;
270 for (i = 0; i < content.rows.length; i++) {
271 var row_id = content.rows[i].id.replace("RROW-", "");
272 if (row_id.length > 0) {
279 function getFirstVisibleHeadlineId() {
281 var rows = cdmGetVisibleArticles();
284 var rows = getVisibleHeadlineIds();
289 function getLastVisibleHeadlineId() {
291 var rows = cdmGetVisibleArticles();
292 return rows[rows.length-1];
294 var rows = getVisibleHeadlineIds();
295 return rows[rows.length-1];
299 function markHeadline(id) {
300 var row = document.getElementById("RROW-" + id);
302 var is_active = false;
304 if (row.className.match("Active")) {
307 row.className = row.className.replace("Selected", "");
308 row.className = row.className.replace("Active", "");
309 row.className = row.className.replace("Insensitive", "");
312 row.className = row.className = "Active";
315 var check = document.getElementById("RCHK-" + id);
318 check.checked = true;
321 row.className = row.className + "Selected";
326 function getFeedIds() {
327 var content = document.getElementById("feedsList");
329 var rows = new Array();
331 for (i = 0; i < content.rows.length; i++) {
332 var id = content.rows[i].id.replace("FEEDR-", "");
341 function setCookie(name, value, lifetime, path, domain, secure) {
347 d.setTime(d.getTime() + (lifetime * 1000));
350 debug("setCookie: " + name + " => " + value + ": " + d);
352 int_setCookie(name, value, d, path, domain, secure);
356 function int_setCookie(name, value, expires, path, domain, secure) {
357 document.cookie= name + "=" + escape(value) +
358 ((expires) ? "; expires=" + expires.toGMTString() : "") +
359 ((path) ? "; path=" + path : "") +
360 ((domain) ? "; domain=" + domain : "") +
361 ((secure) ? "; secure" : "");
364 function delCookie(name, path, domain) {
365 if (getCookie(name)) {
366 document.cookie = name + "=" +
367 ((path) ? ";path=" + path : "") +
368 ((domain) ? ";domain=" + domain : "" ) +
369 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
374 function getCookie(name) {
376 var dc = document.cookie;
377 var prefix = name + "=";
378 var begin = dc.indexOf("; " + prefix);
380 begin = dc.indexOf(prefix);
381 if (begin != 0) return null;
386 var end = document.cookie.indexOf(";", begin);
390 return unescape(dc.substring(begin + prefix.length, end));
393 function disableContainerChildren(id, disable, doc) {
395 if (!doc) doc = document;
397 var container = doc.getElementById(id);
400 //alert("disableContainerChildren: element " + id + " not found");
404 for (var i = 0; i < container.childNodes.length; i++) {
405 var child = container.childNodes[i];
408 child.disabled = disable;
414 if (child.className && child.className.match("button")) {
415 child.className = "disabledButton";
418 if (child.className && child.className.match("disabledButton")) {
419 child.className = "button";
426 function gotoPreferences() {
427 document.location.href = "prefs.php";
430 function gotoMain() {
431 document.location.href = "tt-rss.php";
434 function gotoExportOpml() {
435 document.location.href = "opml.php?op=Export";
438 function getActiveFeedId() {
439 // return getCookie("ttrss_vf_actfeed");
441 debug("gAFID: " + active_feed_id);
442 return active_feed_id;
444 exception_error("getActiveFeedId", e);
448 function activeFeedIsCat() {
449 return active_feed_is_cat;
452 function setActiveFeedId(id) {
453 // return setCookie("ttrss_vf_actfeed", id);
455 debug("sAFID(" + id + ")");
458 exception_error("setActiveFeedId", e);
462 function parse_counters(reply, scheduled_call) {
467 var elems = reply.getElementsByTagName("counter");
469 for (var l = 0; l < elems.length; l++) {
471 var id = elems[l].getAttribute("id");
472 var t = elems[l].getAttribute("type");
473 var ctr = elems[l].getAttribute("counter");
474 var error = elems[l].getAttribute("error");
475 var has_img = elems[l].getAttribute("hi");
476 var updated = elems[l].getAttribute("updated");
477 var title = elems[l].getAttribute("title");
478 var xmsg = elems[l].getAttribute("xmsg");
480 if (id == "global-unread") {
486 if (id == "subscribed-feeds") {
491 if (t == "category") {
492 var catctr = document.getElementById("FCATCTR-" + id);
494 catctr.innerHTML = "(" + ctr + ")";
496 catctr.className = "catCtrHasUnread";
498 catctr.className = "catCtrNoUnread";
504 var feedctr = document.getElementById("FEEDCTR-" + id);
505 var feedu = document.getElementById("FEEDU-" + id);
506 var feedr = document.getElementById("FEEDR-" + id);
507 var feed_img = document.getElementById("FIMG-" + id);
508 var feedlink = document.getElementById("FEEDL-" + id);
509 var feedupd = document.getElementById("FLUPD-" + id);
511 if (updated && feedlink) {
513 feedlink.title = "Error: " + error + " (" + updated + ")";
515 feedlink.title = "Updated: " + updated;
520 if (!updated) updated = "";
524 feedupd.innerHTML = updated + " " + xmsg + " (Error)";
526 feedupd.innerHTML = updated + " (Error)";
530 feedupd.innerHTML = updated + " " + xmsg;
532 feedupd.innerHTML = updated;
537 if (has_img && feed_img && !is_msie()) {
538 if (!feed_img.src.match(id + ".ico")) {
539 feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
543 if (feedlink && title) {
544 feedlink.innerHTML = title;
547 if (feedctr && feedu && feedr) {
549 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
553 var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
555 feedu.innerHTML = ctr;
558 feedr.className = feedr.className.replace("feed", "error");
560 feedr.className = feedr.className.replace("error", "feed");
564 feedctr.className = "odd";
565 if (!feedr.className.match("Unread")) {
566 var is_selected = feedr.className.match("Selected");
568 feedr.className = feedr.className.replace("Selected", "");
569 feedr.className = feedr.className.replace("Unread", "");
571 feedr.className = feedr.className + "Unread";
574 feedr.className = feedr.className + "Selected";
580 new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
581 queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
584 feedctr.className = "invisible";
585 feedr.className = feedr.className.replace("Unread", "");
590 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
592 var feeds_stored = number_of_feeds;
594 debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
596 if (feeds_stored != feeds_found) {
597 number_of_feeds = feeds_found;
599 if (feeds_stored != 0 && feeds_found != 0) {
600 debug("Subscribed feed number changed, refreshing feedlist");
601 setTimeout('updateFeedList(false, false)', 50);
606 exception_error("parse_counters", e);
610 function parse_counters_reply(transport, scheduled_call) {
612 if (!transport.responseXML) {
613 notify_error("Backend did not return valid XML", true);
617 var reply = transport.responseXML.firstChild;
620 notify_error("Backend did not return expected XML object", true);
625 var error_code = false;
626 var error_msg = false;
628 if (reply.firstChild) {
629 error_code = reply.firstChild.getAttribute("error-code");
630 error_msg = reply.firstChild.getAttribute("error-msg");
634 error_code = reply.getAttribute("error-code");
635 error_msg = reply.getAttribute("error-msg");
638 if (error_code && error_code != 0) {
639 debug("refetch_callback: got error code " + error_code);
640 return fatalError(error_code, error_msg);
643 var counters = reply.getElementsByTagName("counters")[0];
645 parse_counters(counters, scheduled_call);
647 var runtime_info = reply.getElementsByTagName("runtime-info")[0];
649 parse_runtime_info(runtime_info);
651 if (getInitParam("feeds_sort_by_unread") == 1) {
655 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
659 function all_counters_callback2(transport) {
661 debug("<b>all_counters_callback2 IN: " + transport + "</b>");
662 parse_counters_reply(transport);
663 debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
666 exception_error("all_counters_callback2", e);
670 function get_feed_unread(id) {
672 return parseInt(document.getElementById("FEEDU-" + id).innerHTML);
674 exception_error("get_feed_unread", e, true);
679 function get_feed_entry_unread(doc, elem) {
681 var id = elem.id.replace("FEEDR-", "");
688 return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
694 function resort_category(doc, node) {
695 debug("resort_category: " + node);
697 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
698 for (i = 0; i < node.childNodes.length; i++) {
699 if (node.childNodes[i].nodeName != "LI") { continue; }
701 if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
705 for (j = i+1; j < node.childNodes.length; j++) {
706 if (node.childNodes[j].nodeName != "LI") { continue; }
708 var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
709 var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
711 if (cur_val > tmp_val) {
712 tempnode_i = node.childNodes[i].cloneNode(true);
713 tempnode_j = node.childNodes[j].cloneNode(true);
714 node.replaceChild(tempnode_i, node.childNodes[j]);
715 node.replaceChild(tempnode_j, node.childNodes[i]);
724 function resort_feedlist() {
725 debug("resort_feedlist");
729 if (fd.getElementById("feedCatHolder")) {
731 var feeds = fd.getElementById("feedList");
732 var child = feeds.firstChild;
736 if (child.id == "feedCatHolder") {
737 resort_category(fd, child.firstChild);
740 child = child.nextSibling;
744 resort_category(fd, fd.getElementById("feedList"));
748 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
749 * * @author Sundar Dorai-Raj
750 * * Email: sdoraira@vt.edu
751 * * This program is free software; you can redistribute it and/or
752 * * modify it under the terms of the GNU General Public License
753 * * as published by the Free Software Foundation; either version 2
754 * * of the License, or (at your option) any later version,
755 * * provided that any use properly credits the author.
756 * * This program is distributed in the hope that it will be useful,
757 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
758 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
759 * * GNU General Public License for more details at http://www.gnu.org * * */
761 var numbers=".0123456789";
762 function isNumeric(x) {
763 // is x a String or a character?
765 // remove negative sign
767 for(j=0;j<x.length;j++) {
768 // call isNumeric recursively for each character
769 number=isNumeric(x.substring(j,j+1));
770 if(!number) return number;
775 // if x is number return true
776 if(numbers.indexOf(x)>=0) return true;
782 function hideOrShowFeeds(doc, hide) {
784 debug("hideOrShowFeeds: " + doc + ", " + hide);
788 var list = fd.getElementById("feedList");
790 if (fd.getElementById("feedCatHolder")) {
792 var feeds = fd.getElementById("feedList");
793 var child = feeds.firstChild;
797 if (child.id == "feedCatHolder") {
798 hideOrShowFeedsCategory(fd, child.firstChild, hide, child.previousSibling);
801 child = child.nextSibling;
805 hideOrShowFeedsCategory(fd, fd.getElementById("feedList"), hide);
809 function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
811 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
816 debug("hideOrShowFeeds: passed node is null, aborting");
820 // debug("cat: " + node.id);
822 if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
823 for (i = 0; i < node.childNodes.length; i++) {
824 if (node.childNodes[i].nodeName != "LI") { continue; }
826 if (node.childNodes[i].style != undefined) {
828 var has_unread = (node.childNodes[i].className != "feed" &&
829 node.childNodes[i].className != "label" &&
830 !(!getInitParam("hide_read_shows_special") &&
831 node.childNodes[i].className == "virt") &&
832 node.childNodes[i].className != "error" &&
833 node.childNodes[i].className != "tag");
835 // debug(node.childNodes[i].id + " --> " + has_unread);
837 if (hide && !has_unread) {
838 //node.childNodes[i].style.display = "none";
839 var id = node.childNodes[i].id;
840 Effect.Fade(node.childNodes[i], {duration : 0.3,
841 queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
845 node.childNodes[i].style.display = "list-item";
846 //Effect.Appear(node.childNodes[i], {duration : 0.3});
850 node.childNodes[i].style.display = "list-item";
852 //Effect.Appear(node.childNodes[i], {duration : 0.3});
853 //Effect.Highlight(node.childNodes[i]);
859 // debug("end cat: " + node.id + " unread " + cat_unread);
861 if (cat_unread == 0) {
862 if (cat_node.style == undefined) {
863 debug("ERROR: supplied cat_node " + cat_node +
864 " has no styles. WTF?");
868 //cat_node.style.display = "none";
869 Effect.Fade(cat_node, {duration : 0.3,
870 queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
872 cat_node.style.display = "list-item";
876 cat_node.style.display = "list-item";
882 // debug("unread for category: " + cat_unread);
885 function selectTableRow(r, do_select) {
886 r.className = r.className.replace("Selected", "");
889 r.className = r.className + "Selected";
893 function selectTableRowById(elem_id, check_id, do_select) {
897 var row = document.getElementById(elem_id);
900 selectTableRow(row, do_select);
903 var check = document.getElementById(check_id);
906 check.checked = do_select;
909 exception_error("selectTableRowById", e);
913 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
914 classcheck, reset_others) {
916 var content = document.getElementById(content_id);
919 alert("[selectTableRows] Element " + content_id + " not found.");
923 for (i = 0; i < content.rows.length; i++) {
924 if (Element.visible(content.rows[i])) {
925 if (!classcheck || content.rows[i].className.match(classcheck)) {
927 if (content.rows[i].id.match(prefix)) {
928 selectTableRow(content.rows[i], do_select);
930 var row_id = content.rows[i].id.replace(prefix, "");
931 var check = document.getElementById(check_prefix + row_id);
934 check.checked = do_select;
936 } else if (reset_others) {
937 selectTableRow(content.rows[i], false);
939 var row_id = content.rows[i].id.replace(prefix, "");
940 var check = document.getElementById(check_prefix + row_id);
943 check.checked = false;
947 } else if (reset_others) {
948 selectTableRow(content.rows[i], false);
950 var row_id = content.rows[i].id.replace(prefix, "");
951 var check = document.getElementById(check_prefix + row_id);
954 check.checked = false;
962 function getSelectedTableRowIds(content_id, prefix) {
964 var content = document.getElementById(content_id);
967 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
971 var sel_rows = new Array();
973 for (i = 0; i < content.rows.length; i++) {
974 if (content.rows[i].id.match(prefix) &&
975 content.rows[i].className.match("Selected")) {
977 var row_id = content.rows[i].id.replace(prefix + "-", "");
978 sel_rows.push(row_id);
986 function toggleSelectRowById(sender, id) {
987 var row = document.getElementById(id);
989 if (sender.checked) {
990 if (!row.className.match("Selected")) {
991 row.className = row.className + "Selected";
994 if (row.className.match("Selected")) {
995 row.className = row.className.replace("Selected", "");
1000 function toggleSelectListRow(sender) {
1001 var parent_row = sender.parentNode;
1003 if (sender.checked) {
1004 if (!parent_row.className.match("Selected")) {
1005 parent_row.className = parent_row.className + "Selected";
1008 if (parent_row.className.match("Selected")) {
1009 parent_row.className = parent_row.className.replace("Selected", "");
1014 function tSR(sender) {
1015 return toggleSelectRow(sender);
1018 function toggleSelectRow(sender) {
1019 var parent_row = sender.parentNode.parentNode;
1021 if (sender.checked) {
1022 if (!parent_row.className.match("Selected")) {
1023 parent_row.className = parent_row.className + "Selected";
1026 if (parent_row.className.match("Selected")) {
1027 parent_row.className = parent_row.className.replace("Selected", "");
1032 function getRelativeFeedId(list, id, direction, unread_only) {
1033 var rows = list.getElementsByTagName("LI");
1034 var feeds = new Array();
1036 for (var i = 0; i < rows.length; i++) {
1037 if (rows[i].id.match("FEEDR-")) {
1039 if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
1042 (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
1043 feeds.push(rows[i].id.replace("FEEDR-", ""));
1050 if (direction == "next") {
1051 return feeds.shift();
1056 if (direction == "next") {
1057 var idx = feeds.indexOf(id);
1058 if (idx != -1 && idx < feeds.length) {
1059 return feeds[idx+1];
1061 return getRelativeFeedId(list, false, direction, unread_only);
1064 var idx = feeds.indexOf(id);
1066 return feeds[idx-1];
1068 return getRelativeFeedId(list, false, direction, unread_only);
1075 function showBlockElement(id, h_id) {
1076 var elem = document.getElementById(id);
1079 elem.style.display = "block";
1082 elem = document.getElementById(h_id);
1084 elem.style.display = "none";
1088 alert("[showBlockElement] can't find element with id " + id);
1092 function appearBlockElement_afh(effect) {
1096 function checkboxToggleElement(elem, id) {
1098 Effect.SlideDown(id, {duration : 0.5});
1100 Effect.SlideUp(id, {duration : 0.5});
1104 function appearBlockElement(id, h_id) {
1110 Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
1112 exception_error("appearBlockElement", e);
1117 function hideParentElement(e) {
1118 e.parentNode.style.display = "none";
1121 function dropboxSelect(e, v) {
1122 for (i = 0; i < e.length; i++) {
1123 if (e[i].value == v) {
1124 e.selectedIndex = i;
1130 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1131 // bugfixed just a little bit :-)
1132 function getURLParam(strParamName){
1134 var strHref = window.location.href;
1136 if (strHref.indexOf("#") == strHref.length-1) {
1137 strHref = strHref.substring(0, strHref.length-1);
1140 if ( strHref.indexOf("?") > -1 ){
1141 var strQueryString = strHref.substr(strHref.indexOf("?"));
1142 var aQueryString = strQueryString.split("&");
1143 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
1144 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
1145 var aParam = aQueryString[iParam].split("=");
1146 strReturn = aParam[1];
1154 function leading_zero(p) {
1156 if (s.length == 1) s = "0" + s;
1160 function closeInfoBox(cleanup) {
1162 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1163 var overlay = document.getElementById("dialog_overlay");
1165 overlay.style.display = "none";
1169 var box = document.getElementById('infoBox');
1170 var shadow = document.getElementById('infoBoxShadow');
1173 shadow.style.display = "none";
1175 box.style.display = "none";
1178 if (cleanup) box.innerHTML = " ";
1186 function displayDlg(id, param) {
1188 notify_progress("Loading, please wait...", true);
1192 var query = "backend.php?op=dlg&id=" +
1193 param_escape(id) + "¶m=" + param_escape(param);
1195 new Ajax.Request(query, {
1196 onComplete: function (transport) {
1197 infobox_callback2(transport);
1203 function infobox_submit_callback2(transport) {
1207 // called from prefs, reload tab
1208 if (typeof active_tab != 'undefined' && active_tab) {
1209 selectTab(active_tab, false);
1213 if (transport.responseText) {
1214 notify_info(transport.responseText);
1218 function infobox_callback2(transport) {
1221 debug("infobox_callback2");
1223 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1224 var overlay = document.getElementById("dialog_overlay");
1226 overlay.style.display = "block";
1230 var box = document.getElementById('infoBox');
1231 var shadow = document.getElementById('infoBoxShadow');
1234 box.innerHTML=transport.responseText;
1236 shadow.style.display = "block";
1238 box.style.display = "block";
1242 /* FIXME this needs to be moved out somewhere */
1244 if (document.getElementById("tags_choices")) {
1245 new Ajax.Autocompleter('tags_str', 'tags_choices',
1246 "backend.php?op=rpc&subop=completeTags",
1247 { tokens: ',', paramName: "search" });
1254 exception_error("infobox_callback2", e);
1258 function createFilter() {
1262 var form = document.forms['filter_add_form'];
1263 var reg_exp = form.reg_exp.value;
1265 if (reg_exp == "") {
1266 alert(__("Can't add filter: nothing to match on."));
1270 var query = Form.serialize("filter_add_form");
1272 // we can be called from some other tab in Prefs
1273 if (typeof active_tab != 'undefined' && active_tab) {
1274 active_tab = "filterConfig";
1277 new Ajax.Request("backend.php?" + query, {
1278 onComplete: function (transport) {
1279 infobox_submit_callback2(transport);
1285 exception_error("createFilter", e);
1289 function toggleSubmitNotEmpty(e, submit_id) {
1291 document.getElementById(submit_id).disabled = (e.value == "")
1293 exception_error("toggleSubmitNotEmpty", e);
1297 function isValidURL(s) {
1298 return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
1301 function subscribeToFeed() {
1303 var form = document.forms['feed_add_form'];
1304 var feed_url = form.feed_url.value;
1306 if (feed_url == "") {
1307 alert(__("Can't subscribe: no feed URL given."));
1311 notify_progress(__("Subscribing to feed..."), true);
1315 var feeds_doc = document;
1317 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1319 var query = Form.serialize("feed_add_form");
1321 debug("subscribe q: " + query);
1323 new Ajax.Request("backend.php", {
1325 onComplete: function(transport) {
1326 dlg_frefresh_callback(transport);
1332 function filterCR(e, f)
1337 key = window.event.keyCode; //IE
1339 key = e.which; //firefox
1342 if (typeof f != 'undefined') {
1353 function getMainContext() {
1357 function getFeedsContext() {
1361 function getContentContext() {
1365 function getHeadlinesContext() {
1369 var debug_last_class = "even";
1371 function debug(msg) {
1373 if (debug_last_class == "even") {
1374 debug_last_class = "odd";
1376 debug_last_class = "even";
1379 var c = document.getElementById('debug_output');
1380 if (c && Element.visible(c)) {
1381 while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
1382 c.removeChild(c.lastChild);
1386 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1387 ":" + leading_zero(d.getSeconds());
1388 c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " +
1389 msg + "</li>" + c.innerHTML;
1393 function getInitParam(key) {
1394 return init_params[key];
1397 function storeInitParam(key, value) {
1398 debug("<b>storeInitParam is OBSOLETE: " + key + " => " + value + "</b>");
1399 init_params[key] = value;
1402 function fatalError(code, message) {
1406 window.location.href = "tt-rss.php";
1407 } else if (code == 5) {
1408 window.location.href = "update.php";
1410 var fe = document.getElementById("fatal_error");
1411 var fc = document.getElementById("fatal_error_msg");
1413 if (message == "") message = "Unknown error";
1415 fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
1417 fe.style.display = "block";
1421 exception_error("fatalError", e);
1425 function getFeedName(id, is_cat) {
1426 var d = getFeedsContext().document;
1431 e = d.getElementById("FCATN-" + id);
1433 e = d.getElementById("FEEDN-" + id);
1436 return e.innerHTML.stripTags();
1442 function viewContentUrl(url) {
1443 getContentContext().location = url;
1446 function filterDlgCheckAction(sender) {
1450 var action = sender[sender.selectedIndex].value;
1452 var form = document.forms["filter_add_form"];
1455 form = document.forms["filter_edit_form"];
1459 debug("filterDlgCheckAction: can't find form!");
1463 var action_param = form.action_param;
1465 if (!action_param) {
1466 debug("filterDlgCheckAction: can't find action param!");
1470 // if selected action supports parameters, enable params field
1471 if (action == 4 || action == 6) {
1472 action_param.disabled = false;
1474 action_param.disabled = true;
1478 exception_error("filterDlgCheckAction", e);
1483 function explainError(code) {
1484 return displayDlg("explainError", code);
1487 // this only searches loaded headlines list, not in CDM
1488 function getRelativePostIds(id, limit) {
1490 if (!limit) limit = 3;
1492 debug("getRelativePostIds: " + id + " limit=" + limit);
1494 var ids = new Array();
1495 var container = document.getElementById("headlinesList");
1498 var rows = container.rows;
1500 for (var i = 0; i < rows.length; i++) {
1501 var r_id = rows[i].id.replace("RROW-", "");
1504 for (var k = 1; k <= limit; k++) {
1507 if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
1508 if (nid) ids.push(nid);
1510 if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
1511 if (nid) ids.push(nid);
1522 function openArticleInNewWindow(id) {
1524 debug("openArticleInNewWindow: " + id);
1526 var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
1527 var wname = "ttrss_article_" + id;
1529 debug(query + " " + wname);
1531 var w = window.open("", wname);
1533 if (!w) notify_error("Failed to open window for the article");
1535 new Ajax.Request(query, {
1536 onComplete: function(transport) {
1537 open_article_callback(transport);
1542 exception_error("openArticleInNewWindow", e);
1546 /* http://textsnippets.com/posts/show/835 */
1548 Position.GetWindowSize = function(w) {
1550 var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
1551 var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
1552 return [width, height]
1555 /* http://textsnippets.com/posts/show/836 */
1557 Position.Center = function(element, parent) {
1559 var d = Element.getDimensions(element);
1564 var ws = Position.GetWindowSize();
1568 pw = parent.offsetWidth;
1569 ph = parent.offsetHeight;
1571 element.style.top = (ph/2) - (h/2) - Position.deltaY + "px";
1572 element.style.left = (pw/2) - (w/2) - Position.deltaX + "px";
1576 function labeltest_callback(transport) {
1578 var container = document.getElementById('label_test_result');
1580 container.innerHTML = transport.responseText;
1581 if (!Element.visible(container)) {
1582 Effect.SlideDown(container, { duration : 0.5 });
1587 exception_error("labeltest_callback", e);
1591 function labelTest() {
1594 var container = document.getElementById('label_test_result');
1596 var form = document.forms['label_edit_form'];
1598 var sql_exp = form.sql_exp.value;
1599 var description = form.description.value;
1601 notify_progress("Loading, please wait...");
1603 var query = "backend.php?op=pref-labels&subop=test&expr=" +
1604 param_escape(sql_exp) + "&descr=" + param_escape(description);
1606 new Ajax.Request(query, {
1607 onComplete: function (transport) {
1608 labeltest_callback(transport);
1614 exception_error("labelTest", e);
1618 function isCdmMode() {
1619 return !document.getElementById("headlinesList");
1622 function getSelectedArticleIds2() {
1623 var rows = new Array();
1624 var cdm_mode = isCdmMode();
1627 rows = cdmGetSelectedArticles();
1629 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1632 var ids = new Array();
1634 for (var i = 0; i < rows.length; i++) {
1635 var chk = document.getElementById("RCHK-" + rows[i]);
1636 if (chk && chk.checked) {
1644 function displayHelpInfobox(topic_id) {
1646 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
1648 var w = window.open(url, "ttrss_help",
1649 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1654 function focus_element(id) {
1656 var e = document.getElementById(id);
1659 exception_error("focus_element", e);
1664 function loading_set_progress(p) {
1666 if (p < last_progress_point || !Element.visible("overlay")) return;
1668 debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
1670 var o = document.getElementById("l_progress_i");
1672 // o.style.width = (p * 2) + "px";
1674 new Effect.Scale(o, p, {
1676 scaleFrom : last_progress_point,
1677 scaleMode: { originalWidth : 200 },
1678 queue: { position: 'end', scope: 'LSP-Q', limit: 3 } });
1680 last_progress_point = p;
1683 exception_error("loading_set_progress", e);
1687 function remove_splash() {
1688 if (Element.visible("overlay")) {
1689 debug("about to remove splash, OMG!");
1690 Element.hide("overlay");
1691 debug("removed splash!");