1 var hotkeys_enabled = true;
3 function browser_has_opacity() {
4 return navigator.userAgent.match("Gecko") != null ||
5 navigator.userAgent.match("Opera") != null;
8 function exception_error(location, e) {
12 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
14 msg = "Exception: " + e.name + ", " + e.message +
15 "\nFunction: " + location + "()" +
16 "\nLocation: " + base_fname + ":" + e.lineNumber;
18 msg = "Exception: " + e + "\nFunction: " + location + "()";
24 function disableHotkeys() {
25 hotkeys_enabled = false;
28 function enableHotkeys() {
29 hotkeys_enabled = true;
32 function xmlhttp_ready(obj) {
33 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
36 function notify_callback() {
37 var container = document.getElementById('notify');
38 if (xmlhttp.readyState == 4) {
39 container.innerHTML=xmlhttp.responseText;
43 function rpc_notify_callback() {
44 var container = document.getElementById('notify');
45 if (xmlhttp_rpc.readyState == 4) {
46 container.innerHTML=xmlhttp_rpc.responseText;
50 function param_escape(arg) {
51 if (typeof encodeURIComponent != 'undefined')
52 return encodeURIComponent(arg);
57 function param_unescape(arg) {
58 if (typeof decodeURIComponent != 'undefined')
59 return decodeURIComponent(arg);
66 then=new Date().getTime();
68 while((now-then)<gap) {
69 now=new Date().getTime();
73 var notify_hide_timerid = false;
74 var notify_last_doc = false;
76 var notify_effect = false;
78 function hide_notify() {
79 if (notify_last_doc) {
80 var n = notify_last_doc.getElementById("notify");
81 if (browser_has_opacity()) {
82 if (notify_opacity >= 0) {
83 notify_opacity = notify_opacity - 0.1;
84 n.style.opacity = notify_opacity;
85 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
87 n.style.display = "none";
91 n.style.display = "none";
96 function notify_real(msg, doc, no_hide, is_err) {
98 var n = doc.getElementById("notify");
99 var nb = doc.getElementById("notify_body");
101 if (!n || !nb) return;
103 if (notify_hide_timerid) {
104 window.clearTimeout(notify_hide_timerid);
107 notify_last_doc = doc;
111 if (n.style.display == "block") {
112 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
116 n.style.display = "block";
120 n.style.backgroundColor = "#ffcccc";
121 n.style.color = "black";
122 n.style.borderColor = "#ff0000";
124 n.style.backgroundColor = "#fff7d5";
125 n.style.borderColor = "#d7c47a";
126 n.style.color = "black";
132 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
136 function p_notify(msg, no_hide, is_err) {
137 notify_real(msg, parent.document, no_hide, is_err);
140 function notify(msg, no_hide, is_err) {
141 notify_real(msg, document, no_hide, is_err);
144 function printLockingError() {
145 notify("Please wait until operation finishes");}
149 function hotkey_handler(e) {
153 if (!hotkeys_enabled) return;
156 keycode = window.event.keyCode;
161 if (keycode == 13 || keycode == 27) {
164 seq = seq + "" + keycode;
167 if (document.getElementById("piggie")) {
169 if (seq.match("807371717369")) {
171 localPiggieFunction(true);
173 localPiggieFunction(false);
177 if (typeof localHotkeyHandler != 'undefined') {
179 localHotkeyHandler(keycode);
181 exception_error("hotkey_handler", e);
187 function cleanSelectedList(element) {
188 var content = document.getElementById(element);
190 if (!document.getElementById("feedCatHolder")) {
191 for (i = 0; i < content.childNodes.length; i++) {
192 var child = content.childNodes[i];
194 child.className = child.className.replace("Selected", "");
200 for (i = 0; i < content.childNodes.length; i++) {
201 var child = content.childNodes[i];
202 if (child.id == "feedCatHolder") {
203 parent.debug(child.id);
204 var fcat = child.lastChild;
205 for (j = 0; j < fcat.childNodes.length; j++) {
206 var feed = fcat.childNodes[j];
207 feed.className = feed.className.replace("Selected", "");
215 function cleanSelected(element) {
216 var content = document.getElementById(element);
218 for (i = 0; i < content.rows.length; i++) {
219 content.rows[i].className = content.rows[i].className.replace("Selected", "");
223 function getVisibleUnreadHeadlines() {
224 var content = document.getElementById("headlinesList");
226 var rows = new Array();
228 for (i = 0; i < content.rows.length; i++) {
229 var row_id = content.rows[i].id.replace("RROW-", "");
230 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
237 function getVisibleHeadlineIds() {
239 var content = document.getElementById("headlinesList");
241 var rows = new Array();
243 for (i = 0; i < content.rows.length; i++) {
244 var row_id = content.rows[i].id.replace("RROW-", "");
245 if (row_id.length > 0) {
252 function getFirstVisibleHeadlineId() {
253 var rows = getVisibleHeadlineIds();
257 function getLastVisibleHeadlineId() {
258 var rows = getVisibleHeadlineIds();
259 return rows[rows.length-1];
262 function markHeadline(id) {
263 var row = document.getElementById("RROW-" + id);
265 var is_active = false;
267 if (row.className.match("Active")) {
270 row.className = row.className.replace("Selected", "");
271 row.className = row.className.replace("Active", "");
272 row.className = row.className.replace("Insensitive", "");
275 row.className = row.className = "Active";
278 var check = document.getElementById("RCHK-" + id);
281 check.checked = true;
284 row.className = row.className + "Selected";
289 function getFeedIds() {
290 var content = document.getElementById("feedsList");
292 var rows = new Array();
294 for (i = 0; i < content.rows.length; i++) {
295 var id = content.rows[i].id.replace("FEEDR-", "");
304 function setCookie(name, value, lifetime, path, domain, secure) {
310 d.setTime(lifetime * 1000);
313 int_setCookie(name, value, d, path, domain, secure);
317 function int_setCookie(name, value, expires, path, domain, secure) {
318 document.cookie= name + "=" + escape(value) +
319 ((expires) ? "; expires=" + expires.toGMTString() : "") +
320 ((path) ? "; path=" + path : "") +
321 ((domain) ? "; domain=" + domain : "") +
322 ((secure) ? "; secure" : "");
325 function delCookie(name, path, domain) {
326 if (getCookie(name)) {
327 document.cookie = name + "=" +
328 ((path) ? ";path=" + path : "") +
329 ((domain) ? ";domain=" + domain : "" ) +
330 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
335 function getCookie(name) {
337 var dc = document.cookie;
338 var prefix = name + "=";
339 var begin = dc.indexOf("; " + prefix);
341 begin = dc.indexOf(prefix);
342 if (begin != 0) return null;
347 var end = document.cookie.indexOf(";", begin);
351 return unescape(dc.substring(begin + prefix.length, end));
354 function disableContainerChildren(id, disable, doc) {
356 if (!doc) doc = document;
358 var container = doc.getElementById(id);
361 //alert("disableContainerChildren: element " + id + " not found");
365 for (var i = 0; i < container.childNodes.length; i++) {
366 var child = container.childNodes[i];
369 child.disabled = disable;
375 if (child.className && child.className.match("button")) {
376 child.className = "disabledButton";
379 if (child.className && child.className.match("disabledButton")) {
380 child.className = "button";
387 function gotoPreferences() {
388 document.location.href = "prefs.php";
391 function gotoMain() {
392 document.location.href = "tt-rss.php";
395 function gotoExportOpml() {
396 document.location.href = "opml.php?op=Export";
399 function getActiveFeedId() {
400 // return getCookie("ttrss_vf_actfeed");
402 debug("gAFID: " + getMainContext().active_feed_id);
403 return getMainContext().active_feed_id;
405 exception_error("getActiveFeedId", e);
409 function setActiveFeedId(id) {
410 // return setCookie("ttrss_vf_actfeed", id);
412 getMainContext().active_feed_id = id;
414 exception_error("setActiveFeedId", e);
418 var xmlhttp_rpc = Ajax.getTransport();
420 function parse_counters(reply, scheduled_call) {
422 var f_document = getFeedsContext().document;
423 var title_obj = getMainContext();
425 debug("F_DOC: " + f_document + ", T_OBJ: " + title_obj);
427 for (var l = 0; l < reply.childNodes.length; l++) {
428 if (!reply.childNodes[l] ||
429 typeof(reply.childNodes[l].getAttribute) == "undefined") {
430 // where did this come from?
434 var id = reply.childNodes[l].getAttribute("id");
435 var t = reply.childNodes[l].getAttribute("type");
436 var ctr = reply.childNodes[l].getAttribute("counter");
437 var error = reply.childNodes[l].getAttribute("error");
438 var has_img = reply.childNodes[l].getAttribute("hi");
439 var updated = reply.childNodes[l].getAttribute("updated");
441 if (id == "global-unread") {
442 title_obj.global_unread = ctr;
443 title_obj.updateTitle();
447 if (t == "category") {
448 var catctr = f_document.getElementById("FCATCTR-" + id);
450 catctr.innerHTML = "(" + ctr + " unread)";
455 var feedctr = f_document.getElementById("FEEDCTR-" + id);
456 var feedu = f_document.getElementById("FEEDU-" + id);
457 var feedr = f_document.getElementById("FEEDR-" + id);
458 var feed_img = f_document.getElementById("FIMG-" + id);
459 var feedlink = f_document.getElementById("FEEDL-" + id);
461 if (updated && feedlink) {
463 feedlink.title = "Error: " + error + " (" + updated + ")";
465 feedlink.title = "Updated: " + updated;
469 if (feedctr && feedu && feedr) {
471 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
472 var hf = title_obj.parent.frames["headlines-frame"];
473 hf.location.reload(true);
476 feedu.innerHTML = ctr;
479 feedr.className = feedr.className.replace("feed", "error");
481 feedr.className = feedr.className.replace("error", "feed");
485 feedctr.className = "odd";
486 if (!feedr.className.match("Unread")) {
487 var is_selected = feedr.className.match("Selected");
489 feedr.className = feedr.className.replace("Selected", "");
490 feedr.className = feedr.className.replace("Unread", "");
492 feedr.className = feedr.className + "Unread";
495 feedr.className = feedr.className + "Selected";
500 feedctr.className = "invisible";
501 feedr.className = feedr.className.replace("Unread", "");
506 exception_error("parse_counters", e);
510 function all_counters_callback() {
511 if (xmlhttp_rpc.readyState == 4) {
513 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
514 notify("[all_counters_callback] backend did not return valid XML");
518 var reply = xmlhttp_rpc.responseXML.firstChild;
520 parse_counters(reply);
523 exception_error("all_counters_callback", e);
528 function update_all_counters(feed) {
529 if (xmlhttp_ready(xmlhttp_rpc)) {
530 var query = "backend.php?op=rpc&subop=getAllCounters";
533 query = query + "&aid=" + feed;
536 xmlhttp_rpc.open("GET", query, true);
537 xmlhttp_rpc.onreadystatechange=all_counters_callback;
538 xmlhttp_rpc.send(null);
542 function popupHelp(tid) {
543 var w = window.open("backend.php?op=help&tid=" + tid,
545 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
548 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
549 * * @author Sundar Dorai-Raj
550 * * Email: sdoraira@vt.edu
551 * * This program is free software; you can redistribute it and/or
552 * * modify it under the terms of the GNU General Public License
553 * * as published by the Free Software Foundation; either version 2
554 * * of the License, or (at your option) any later version,
555 * * provided that any use properly credits the author.
556 * * This program is distributed in the hope that it will be useful,
557 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
558 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
559 * * GNU General Public License for more details at http://www.gnu.org * * */
561 var numbers=".0123456789";
562 function isNumeric(x) {
563 // is x a String or a character?
565 // remove negative sign
567 for(j=0;j<x.length;j++) {
568 // call isNumeric recursively for each character
569 number=isNumeric(x.substring(j,j+1));
570 if(!number) return number;
575 // if x is number return true
576 if(numbers.indexOf(x)>=0) return true;
582 function hideOrShowFeeds(doc, hide) {
584 if (!doc.styleSheets) return;
586 var css_rules = doc.styleSheets[0].cssRules;
588 if (!css_rules || !css_rules.length) return;
590 for (i = 0; i < css_rules.length; i++) {
591 var rule = css_rules[i];
593 if (rule.selectorText == "ul.feedList li.feed") {
595 rule.style.display = "block";
597 rule.style.display = "none";
605 function selectTableRow(r, do_select) {
606 r.className = r.className.replace("Selected", "");
609 r.className = r.className + "Selected";
613 function selectTableRowById(elem_id, check_id, do_select) {
617 var row = document.getElementById(elem_id);
620 selectTableRow(row, do_select);
623 var check = document.getElementById(check_id);
626 check.checked = do_select;
629 exception_error("selectTableRowById", e);
633 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
634 classcheck, reset_others) {
636 var content = document.getElementById(content_id);
639 alert("[selectTableRows] Element " + content_id + " not found.");
643 for (i = 0; i < content.rows.length; i++) {
644 if (!classcheck || content.rows[i].className.match(classcheck)) {
646 if (content.rows[i].id.match(prefix)) {
647 selectTableRow(content.rows[i], do_select);
649 var row_id = content.rows[i].id.replace(prefix, "");
650 var check = document.getElementById(check_prefix + row_id);
653 check.checked = do_select;
655 } else if (reset_others) {
656 selectTableRow(content.rows[i], false);
658 var row_id = content.rows[i].id.replace(prefix, "");
659 var check = document.getElementById(check_prefix + row_id);
662 check.checked = false;
666 } else if (reset_others) {
667 selectTableRow(content.rows[i], false);
669 var row_id = content.rows[i].id.replace(prefix, "");
670 var check = document.getElementById(check_prefix + row_id);
673 check.checked = false;
680 function getSelectedTableRowIds(content_id, prefix) {
682 var content = document.getElementById(content_id);
685 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
689 var sel_rows = new Array();
691 for (i = 0; i < content.rows.length; i++) {
692 if (content.rows[i].id.match(prefix) &&
693 content.rows[i].className.match("Selected")) {
695 var row_id = content.rows[i].id.replace(prefix + "-", "");
696 sel_rows.push(row_id);
704 function toggleSelectRowById(sender, id) {
705 var row = document.getElementById(id);
707 if (sender.checked) {
708 if (!row.className.match("Selected")) {
709 row.className = row.className + "Selected";
712 if (row.className.match("Selected")) {
713 row.className = row.className.replace("Selected", "");
718 function toggleSelectListRow(sender) {
719 var parent_row = sender.parentNode;
721 if (sender.checked) {
722 if (!parent_row.className.match("Selected")) {
723 parent_row.className = parent_row.className + "Selected";
726 if (parent_row.className.match("Selected")) {
727 parent_row.className = parent_row.className.replace("Selected", "");
733 function toggleSelectRow(sender) {
734 var parent_row = sender.parentNode.parentNode;
736 if (sender.checked) {
737 if (!parent_row.className.match("Selected")) {
738 parent_row.className = parent_row.className + "Selected";
741 if (parent_row.className.match("Selected")) {
742 parent_row.className = parent_row.className.replace("Selected", "");
747 function openExternalUrl(url) {
748 var w = window.open(url);
751 function getRelativeFeedId(list, id, direction, unread_only) {
753 if (direction == "next") {
754 for (i = 0; i < list.childNodes.length; i++) {
755 var child = list.childNodes[i];
756 if (child.id && child.id == "feedCatHolder") {
757 if (child.lastChild) {
758 var cr = getRelativeFeedId(child.firstChild, id, direction);
761 } else if (child.id && child.id.match("FEEDR-")) {
762 return child.id.replace('FEEDR-', '');
767 // FIXME select last feed doesn't work when only unread feeds are visible
769 if (direction == "prev") {
770 for (i = list.childNodes.length-1; i >= 0; i--) {
771 var child = list.childNodes[i];
772 if (child.id == "feedCatHolder") {
773 if (child.firstChild) {
774 var cr = getRelativeFeedId(child.firstChild, id, direction);
777 } else if (child.id.match("FEEDR-")) {
779 if (getInitParam("hide_read_feeds") == 1) {
780 if (child.className != "feed") {
781 alert(child.className);
782 return child.id.replace('FEEDR-', '');
785 return child.id.replace('FEEDR-', '');
792 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
794 if (getInitParam("hide_read_feeds") == 1) {
798 if (direction == "next") {
808 } else if (e.parentNode.parentNode.nextSibling) {
810 var this_cat = e.parentNode.parentNode;
814 if (this_cat && this_cat.nextSibling) {
815 while (!e && this_cat.nextSibling) {
816 this_cat = this_cat.nextSibling;
817 if (this_cat.id == "feedCatHolder") {
818 e = this_cat.firstChild.firstChild;
828 if (!unread_only || (unread_only && e.className != "feed" &&
829 e.className != "error")) {
830 return e.id.replace("FEEDR-", "");
835 } else if (direction == "prev") {
841 if (e.previousSibling) {
843 e = e.previousSibling;
845 } else if (e.parentNode.parentNode.previousSibling) {
847 var this_cat = e.parentNode.parentNode;
851 if (this_cat && this_cat.previousSibling) {
852 while (!e && this_cat.previousSibling) {
853 this_cat = this_cat.previousSibling;
854 if (this_cat.id == "feedCatHolder") {
855 e = this_cat.firstChild.lastChild;
865 if (!unread_only || (unread_only && e.className != "feed" &&
866 e.className != "error")) {
867 return e.id.replace("FEEDR-", "");
875 function showBlockElement(id) {
876 var elem = document.getElementById(id);
879 elem.style.display = "block";
881 alert("[showBlockElement] can't find element with id " + id);
885 function hideParentElement(e) {
886 e.parentNode.style.display = "none";
889 function dropboxSelect(e, v) {
890 for (i = 0; i < e.length; i++) {
891 if (e[i].value == v) {
898 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
899 // bugfixed just a little bit :-)
900 function getURLParam(strParamName){
902 var strHref = window.location.href;
904 if (strHref.indexOf("#") == strHref.length-1) {
905 strHref = strHref.substring(0, strHref.length-1);
908 if ( strHref.indexOf("?") > -1 ){
909 var strQueryString = strHref.substr(strHref.indexOf("?"));
910 var aQueryString = strQueryString.split("&");
911 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
912 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
913 var aParam = aQueryString[iParam].split("=");
914 strReturn = aParam[1];
922 function leading_zero(p) {
924 if (s.length == 1) s = "0" + s;
928 function closeInfoBox(cleanup) {
929 var box = document.getElementById('infoBox');
930 var shadow = document.getElementById('infoBoxShadow');
933 shadow.style.display = "none";
935 box.style.display = "none";
938 if (cleanup) box.innerHTML = " ";
945 function displayDlg(id, param) {
947 if (!xmlhttp_ready(xmlhttp)) {
954 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
955 param_escape(id) + "¶m=" + param_escape(param), true);
956 xmlhttp.onreadystatechange=infobox_callback;
963 function infobox_submit_callback() {
964 if (xmlhttp.readyState == 4) {
967 // called from prefs, reload tab
969 selectTab(active_tab, false);
972 notify(xmlhttp.responseText);
977 function infobox_callback() {
978 if (xmlhttp.readyState == 4) {
979 var box = document.getElementById('infoBox');
980 var shadow = document.getElementById('infoBoxShadow');
982 box.innerHTML=xmlhttp.responseText;
984 shadow.style.display = "block";
986 box.style.display = "block";
992 function qaddFilter() {
994 if (!xmlhttp_ready(xmlhttp)) {
999 var query = Form.serialize("filter_add_form");
1001 xmlhttp.open("GET", "backend.php?" + query, true);
1002 xmlhttp.onreadystatechange=infobox_submit_callback;
1008 function toggleSubmitNotEmpty(e, submit_id) {
1010 document.getElementById(submit_id).disabled = (e.value == "")
1012 exception_error("toggleSubmitNotEmpty", e);
1016 function isValidURL(s) {
1017 return s.match("http://") != null || s.match("https://") != null;
1022 if (!xmlhttp_ready(xmlhttp)) {
1023 printLockingError();
1027 notify("Adding feed...");
1031 var feeds_doc = getFeedsContext().document;
1033 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1035 var query = Form.serialize("feed_add_form");
1037 xmlhttp.open("GET", "backend.php?" + query, true);
1038 xmlhttp.onreadystatechange=dlg_frefresh_callback;
1042 function filterCR(e)
1047 key = window.event.keyCode; //IE
1049 key = e.which; //firefox
1057 function getMainContext() {
1058 if (parent.window != window) {
1059 return parent.window;
1065 function getFeedsContext() {
1067 return getMainContext().frames["feeds-frame"];
1069 exception_error("getFeedsContext", e);
1073 function debug(msg) {
1074 var ctx = getMainContext();
1076 var c = ctx.document.getElementById('debug_output');
1077 if (c && c.style.display == "block") {
1078 while (c.lastChild != 'undefined' && c.childNodes.length > 20) {
1079 c.removeChild(c.lastChild);
1083 var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
1084 ":" + leading_zero(d.getSeconds());
1085 c.innerHTML = "<li>[" + ts + "] " + msg + "</li>" + c.innerHTML;
1089 function getInitParam(key) {
1090 return getMainContext().init_params[key];
1094 function storeInitParam(key, value, is_client) {
1096 getMainContext().init_params[key] = value;
1098 new Ajax.Request("backend.php?op=rpc&subop=storeParam&key=" +
1099 param_escape(key) + "&value=" + param_escape(value));
1102 exception_error("storeInitParam", e);