1 var hotkeys_enabled = true;
3 function browser_has_opacity() {
4 return navigator.userAgent.match("Gecko") || navigator.userAgent.match("Opera");
7 function exception_error(location, e) {
11 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
13 msg = "Exception: " + e.name + ", " + e.message +
14 "\nFunction: " + location + "()" +
15 "\nLocation: " + base_fname + ":" + e.lineNumber;
17 msg = "Exception: " + e + "\nFunction: " + location + "()";
23 function disableHotkeys() {
24 hotkeys_enabled = false;
27 function enableHotkeys() {
28 hotkeys_enabled = true;
31 function xmlhttp_ready(obj) {
32 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
35 function notify_callback() {
36 var container = document.getElementById('notify');
37 if (xmlhttp.readyState == 4) {
38 container.innerHTML=xmlhttp.responseText;
42 function rpc_notify_callback() {
43 var container = document.getElementById('notify');
44 if (xmlhttp_rpc.readyState == 4) {
45 container.innerHTML=xmlhttp_rpc.responseText;
49 function rpc_pnotify_callback() {
50 var container = parent.document.getElementById('notify');
51 if (xmlhttp_rpc.readyState == 4) {
52 container.innerHTML=xmlhttp_rpc.responseText;
56 function param_escape(arg) {
57 if (typeof encodeURIComponent != 'undefined')
58 return encodeURIComponent(arg);
63 function param_unescape(arg) {
64 if (typeof decodeURIComponent != 'undefined')
65 return decodeURIComponent(arg);
72 then=new Date().getTime();
74 while((now-then)<gap) {
75 now=new Date().getTime();
79 var notify_hide_timerid = false;
80 var notify_last_doc = false;
82 function hide_notify() {
83 if (notify_last_doc) {
84 var n = notify_last_doc.getElementById("notify");
85 if (browser_has_opacity()) {
86 if (notify_opacity >= 0) {
87 notify_opacity = notify_opacity - 0.2;
88 n.style.opacity = notify_opacity;
89 notify_hide_timerid = window.setTimeout("hide_notify()", 20);
91 n.style.display = "none";
95 n.style.display = "none";
100 function notify_real(msg, doc, no_hide, is_err) {
102 var n = doc.getElementById("notify");
103 var nb = doc.getElementById("notify_body");
105 if (!n || !nb) return;
108 n.style.display = "none";
110 n.style.display = "block";
114 n.style.backgroundColor = "#ffaaaa";
115 n.style.color = "white";
116 n.style.borderColor = "#ff0000";
118 n.style.backgroundColor = "#fff7d5";
119 n.style.borderColor = "#d7c47a";
120 n.style.color = "black";
125 if (notify_hide_timerid) {
126 window.clearTimeout(notify_hide_timerid);
129 notify_last_doc = doc;
133 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
137 function p_notify(msg, no_hide, is_err) {
138 notify_real(msg, parent.document, no_hide, is_err);
141 function notify(msg, no_hide, is_err) {
142 notify_real(msg, document, no_hide, is_err);
145 function printLockingError() {
146 notify("Please wait until operation finishes");}
150 function hotkey_handler(e) {
154 if (!hotkeys_enabled) return;
157 keycode = window.event.keyCode;
162 if (keycode == 13 || keycode == 27) {
165 seq = seq + "" + keycode;
168 if (document.getElementById("piggie")) {
170 if (seq.match("807371717369")) {
172 localPiggieFunction(true);
174 localPiggieFunction(false);
178 if (typeof localHotkeyHandler != 'undefined') {
180 localHotkeyHandler(keycode);
182 exception_error("hotkey_handler", e);
188 function cleanSelectedList(element) {
189 var content = document.getElementById(element);
191 if (!document.getElementById("feedCatHolder")) {
192 for (i = 0; i < content.childNodes.length; i++) {
193 var child = content.childNodes[i];
195 child.className = child.className.replace("Selected", "");
201 for (i = 0; i < content.childNodes.length; i++) {
202 var child = content.childNodes[i];
203 if (child.id == "feedCatHolder") {
204 parent.debug(child.id);
205 var fcat = child.lastChild;
206 for (j = 0; j < fcat.childNodes.length; j++) {
207 var feed = fcat.childNodes[j];
208 feed.className = feed.className.replace("Selected", "");
216 function cleanSelected(element) {
217 var content = document.getElementById(element);
219 for (i = 0; i < content.rows.length; i++) {
220 content.rows[i].className = content.rows[i].className.replace("Selected", "");
224 function getVisibleUnreadHeadlines() {
225 var content = document.getElementById("headlinesList");
227 var rows = new Array();
229 for (i = 0; i < content.rows.length; i++) {
230 var row_id = content.rows[i].id.replace("RROW-", "");
231 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
238 function getVisibleHeadlineIds() {
240 var content = document.getElementById("headlinesList");
242 var rows = new Array();
244 for (i = 0; i < content.rows.length; i++) {
245 var row_id = content.rows[i].id.replace("RROW-", "");
246 if (row_id.length > 0) {
253 function getFirstVisibleHeadlineId() {
254 var rows = getVisibleHeadlineIds();
258 function getLastVisibleHeadlineId() {
259 var rows = getVisibleHeadlineIds();
260 return rows[rows.length-1];
263 function markHeadline(id) {
264 var row = document.getElementById("RROW-" + id);
266 var is_active = false;
268 if (row.className.match("Active")) {
271 row.className = row.className.replace("Selected", "");
272 row.className = row.className.replace("Active", "");
273 row.className = row.className.replace("Insensitive", "");
276 row.className = row.className = "Active";
279 var check = document.getElementById("RCHK-" + id);
282 check.checked = true;
285 row.className = row.className + "Selected";
290 function getFeedIds() {
291 var content = document.getElementById("feedsList");
293 var rows = new Array();
295 for (i = 0; i < content.rows.length; i++) {
296 var id = content.rows[i].id.replace("FEEDR-", "");
305 function setCookie(name, value, lifetime, path, domain, secure) {
311 d.setTime(lifetime * 1000);
314 int_setCookie(name, value, d, path, domain, secure);
318 function int_setCookie(name, value, expires, path, domain, secure) {
319 document.cookie= name + "=" + escape(value) +
320 ((expires) ? "; expires=" + expires.toGMTString() : "") +
321 ((path) ? "; path=" + path : "") +
322 ((domain) ? "; domain=" + domain : "") +
323 ((secure) ? "; secure" : "");
326 function delCookie(name, path, domain) {
327 if (getCookie(name)) {
328 document.cookie = name + "=" +
329 ((path) ? ";path=" + path : "") +
330 ((domain) ? ";domain=" + domain : "" ) +
331 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
336 function getCookie(name) {
338 var dc = document.cookie;
339 var prefix = name + "=";
340 var begin = dc.indexOf("; " + prefix);
342 begin = dc.indexOf(prefix);
343 if (begin != 0) return null;
348 var end = document.cookie.indexOf(";", begin);
352 return unescape(dc.substring(begin + prefix.length, end));
355 function disableContainerChildren(id, disable, doc) {
357 if (!doc) doc = document;
359 var container = doc.getElementById(id);
361 for (var i = 0; i < container.childNodes.length; i++) {
362 var child = container.childNodes[i];
365 child.disabled = disable;
371 if (child.className && child.className.match("button")) {
372 child.className = "disabledButton";
375 if (child.className && child.className.match("disabledButton")) {
376 child.className = "button";
383 function gotoPreferences() {
384 document.location.href = "prefs.php";
387 function gotoMain() {
388 document.location.href = "tt-rss.php";
391 function gotoExportOpml() {
392 document.location.href = "opml.php?op=Export";
395 function getActiveFeedId() {
396 return getCookie("ttrss_vf_actfeed");
399 function setActiveFeedId(id) {
400 return setCookie("ttrss_vf_actfeed", id);
403 var xmlhttp_rpc = false;
406 /*@if (@_jscript_version >= 5)
407 // JScript gives us Conditional compilation, we can cope with old IE versions.
408 // and security blocked creation of the objects.
410 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
413 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
420 if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
421 xmlhttp_rpc = new XMLHttpRequest();
424 function parse_counters(reply, f_document, title_obj, scheduled_call) {
426 for (var l = 0; l < reply.childNodes.length; l++) {
427 if (!reply.childNodes[l] ||
428 typeof(reply.childNodes[l].getAttribute) == "undefined") {
429 // where did this come from?
433 var id = reply.childNodes[l].getAttribute("id");
434 var t = reply.childNodes[l].getAttribute("type");
435 var ctr = reply.childNodes[l].getAttribute("counter");
436 var error = reply.childNodes[l].getAttribute("error");
437 var has_img = reply.childNodes[l].getAttribute("hi");
438 var updated = reply.childNodes[l].getAttribute("updated");
440 if (id == "global-unread") {
441 title_obj.global_unread = ctr;
442 title_obj.updateTitle();
446 if (t == "category") {
447 var catctr = f_document.getElementById("FCATCTR-" + id);
449 catctr.innerHTML = "(" + ctr + " unread)";
454 var feedctr = f_document.getElementById("FEEDCTR-" + id);
455 var feedu = f_document.getElementById("FEEDU-" + id);
456 var feedr = f_document.getElementById("FEEDR-" + id);
457 var feed_img = f_document.getElementById("FIMG-" + id);
458 var feedlink = f_document.getElementById("FEEDL-" + id);
460 if (updated && feedlink) {
462 feedlink.title = "Error: " + error + " (" + updated + ")";
464 feedlink.title = "Updated: " + updated;
468 if (feedctr && feedu && feedr) {
470 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
471 var hf = title_obj.parent.frames["headlines-frame"];
472 hf.location.reload(true);
475 feedu.innerHTML = ctr;
478 feedr.className = feedr.className.replace("feed", "error");
480 feedr.className = feedr.className.replace("error", "feed");
484 feedctr.className = "odd";
485 if (!feedr.className.match("Unread")) {
486 var is_selected = feedr.className.match("Selected");
488 feedr.className = feedr.className.replace("Selected", "");
489 feedr.className = feedr.className.replace("Unread", "");
491 feedr.className = feedr.className + "Unread";
494 feedr.className = feedr.className + "Selected";
499 feedctr.className = "invisible";
500 feedr.className = feedr.className.replace("Unread", "");
505 exception_error("parse_counters", e);
509 // this one is called from feedlist context
510 // thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
512 function all_counters_callback() {
513 if (xmlhttp_rpc.readyState == 4) {
515 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
516 notify("[all_counters_callback] backend did not return valid XML");
520 if (!parent.frames["feeds-frame"]) {
521 notify("[all_counters_callback] no parent feeds-frame");
525 var reply = xmlhttp_rpc.responseXML.firstChild;
526 var f_document = parent.frames["feeds-frame"].document;
528 parse_counters(reply, f_document, parent);
531 exception_error("all_counters_callback", e);
536 function update_all_counters(feed) {
537 if (xmlhttp_ready(xmlhttp_rpc)) {
538 var query = "backend.php?op=rpc&subop=getAllCounters";
541 query = query + "&aid=" + feed;
544 xmlhttp_rpc.open("GET", query, true);
545 xmlhttp_rpc.onreadystatechange=all_counters_callback;
546 xmlhttp_rpc.send(null);
550 function popupHelp(tid) {
551 var w = window.open("backend.php?op=help&tid=" + tid,
553 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
556 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
557 * * @author Sundar Dorai-Raj
558 * * Email: sdoraira@vt.edu
559 * * This program is free software; you can redistribute it and/or
560 * * modify it under the terms of the GNU General Public License
561 * * as published by the Free Software Foundation; either version 2
562 * * of the License, or (at your option) any later version,
563 * * provided that any use properly credits the author.
564 * * This program is distributed in the hope that it will be useful,
565 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
566 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
567 * * GNU General Public License for more details at http://www.gnu.org * * */
569 var numbers=".0123456789";
570 function isNumeric(x) {
571 // is x a String or a character?
573 // remove negative sign
575 for(j=0;j<x.length;j++) {
576 // call isNumeric recursively for each character
577 number=isNumeric(x.substring(j,j+1));
578 if(!number) return number;
583 // if x is number return true
584 if(numbers.indexOf(x)>=0) return true;
590 function hideOrShowFeeds(doc, hide) {
592 if (!doc.styleSheets) return;
594 var css_rules = doc.styleSheets[0].cssRules;
596 if (!css_rules || !css_rules.length) return;
598 for (i = 0; i < css_rules.length; i++) {
599 var rule = css_rules[i];
601 if (rule.selectorText == "ul.feedList li.feed") {
603 rule.style.display = "block";
605 rule.style.display = "none";
613 function selectTableRow(r, do_select) {
614 r.className = r.className.replace("Selected", "");
617 r.className = r.className + "Selected";
621 function selectTableRowById(elem_id, check_id, do_select) {
625 var row = document.getElementById(elem_id);
628 selectTableRow(row, do_select);
631 var check = document.getElementById(check_id);
634 check.checked = do_select;
637 exception_error("selectTableRowById", e);
641 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
642 classcheck, reset_others) {
644 var content = document.getElementById(content_id);
647 alert("[selectTableRows] Element " + content_id + " not found.");
651 for (i = 0; i < content.rows.length; i++) {
652 if (!classcheck || content.rows[i].className.match(classcheck)) {
654 if (content.rows[i].id.match(prefix)) {
655 selectTableRow(content.rows[i], do_select);
657 var row_id = content.rows[i].id.replace(prefix, "");
658 var check = document.getElementById(check_prefix + row_id);
661 check.checked = do_select;
663 } else if (reset_others) {
664 selectTableRow(content.rows[i], false);
666 var row_id = content.rows[i].id.replace(prefix, "");
667 var check = document.getElementById(check_prefix + row_id);
670 check.checked = false;
674 } else if (reset_others) {
675 selectTableRow(content.rows[i], false);
677 var row_id = content.rows[i].id.replace(prefix, "");
678 var check = document.getElementById(check_prefix + row_id);
681 check.checked = false;
688 function getSelectedTableRowIds(content_id, prefix) {
690 var content = document.getElementById(content_id);
693 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
697 var sel_rows = new Array();
699 for (i = 0; i < content.rows.length; i++) {
700 if (content.rows[i].id.match(prefix) &&
701 content.rows[i].className.match("Selected")) {
703 var row_id = content.rows[i].id.replace(prefix + "-", "");
704 sel_rows.push(row_id);
712 function toggleSelectRowById(sender, id) {
713 var row = document.getElementById(id);
715 if (sender.checked) {
716 if (!row.className.match("Selected")) {
717 row.className = row.className + "Selected";
720 if (row.className.match("Selected")) {
721 row.className = row.className.replace("Selected", "");
726 function toggleSelectListRow(sender) {
727 var parent_row = sender.parentNode;
729 if (sender.checked) {
730 if (!parent_row.className.match("Selected")) {
731 parent_row.className = parent_row.className + "Selected";
734 if (parent_row.className.match("Selected")) {
735 parent_row.className = parent_row.className.replace("Selected", "");
741 function toggleSelectRow(sender) {
742 var parent_row = sender.parentNode.parentNode;
744 if (sender.checked) {
745 if (!parent_row.className.match("Selected")) {
746 parent_row.className = parent_row.className + "Selected";
749 if (parent_row.className.match("Selected")) {
750 parent_row.className = parent_row.className.replace("Selected", "");
755 function openExternalUrl(url) {
756 var w = window.open(url);
759 function getRelativeFeedId(list, id, direction, unread_only) {
761 if (direction == "next") {
762 for (i = 0; i < list.childNodes.length; i++) {
763 var child = list.childNodes[i];
764 if (child.id && child.id == "feedCatHolder") {
765 if (child.lastChild) {
766 var cr = getRelativeFeedId(child.firstChild, id, direction);
769 } else if (child.id && child.id.match("FEEDR-")) {
770 return child.id.replace('FEEDR-', '');
775 // FIXME select last feed doesn't work when only unread feeds are visible
777 if (direction == "prev") {
778 for (i = list.childNodes.length-1; i >= 0; i--) {
779 var child = list.childNodes[i];
780 if (child.id == "feedCatHolder") {
781 if (child.firstChild) {
782 var cr = getRelativeFeedId(child.firstChild, id, direction);
785 } else if (child.id.match("FEEDR-")) {
787 if (getCookie("ttrss_vf_hreadf") == 1) {
788 if (child.className != "feed") {
789 alert(child.className);
790 return child.id.replace('FEEDR-', '');
793 return child.id.replace('FEEDR-', '');
800 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
802 if (getCookie("ttrss_vf_hreadf") == 1) {
806 if (direction == "next") {
816 } else if (e.parentNode.parentNode.nextSibling) {
818 var this_cat = e.parentNode.parentNode;
822 if (this_cat && this_cat.nextSibling) {
823 while (!e && this_cat.nextSibling) {
824 this_cat = this_cat.nextSibling;
825 if (this_cat.id == "feedCatHolder") {
826 e = this_cat.firstChild.firstChild;
836 if (!unread_only || (unread_only && e.className != "feed" &&
837 e.className != "error")) {
838 return e.id.replace("FEEDR-", "");
843 } else if (direction == "prev") {
849 if (e.previousSibling) {
851 e = e.previousSibling;
853 } else if (e.parentNode.parentNode.previousSibling) {
855 var this_cat = e.parentNode.parentNode;
859 if (this_cat && this_cat.previousSibling) {
860 while (!e && this_cat.previousSibling) {
861 this_cat = this_cat.previousSibling;
862 if (this_cat.id == "feedCatHolder") {
863 e = this_cat.firstChild.lastChild;
873 if (!unread_only || (unread_only && e.className != "feed" &&
874 e.className != "error")) {
875 return e.id.replace("FEEDR-", "");
883 function showBlockElement(id) {
884 var elem = document.getElementById(id);
887 elem.style.display = "block";
889 alert("[showBlockElement] can't find element with id " + id);
893 function hideParentElement(e) {
894 e.parentNode.style.display = "none";
897 function dropboxSelect(e, v) {
898 for (i = 0; i < e.length; i++) {
899 if (e[i].value == v) {
906 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
907 // bugfixed just a little bit :-)
908 function getURLParam(strParamName){
910 var strHref = window.location.href;
912 if (strHref.indexOf("#") == strHref.length-1) {
913 strHref = strHref.substring(0, strHref.length-1);
916 if ( strHref.indexOf("?") > -1 ){
917 var strQueryString = strHref.substr(strHref.indexOf("?"));
918 var aQueryString = strQueryString.split("&");
919 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
920 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
921 var aParam = aQueryString[iParam].split("=");
922 strReturn = aParam[1];
930 function leading_zero(p) {
932 if (s.length == 1) s = "0" + s;
936 function center_element(e) {
939 var c_width = document.body.clientWidth;
940 var c_height = document.body.clientHeight;
942 var c_scroll = document.body.scrollTop;
944 var e_width = e.clientWidth;
945 var e_height = e.clientHeight;
947 var set_y = (c_height / 2) + c_scroll - (e_height / 2);
948 var set_x = (c_width / 2) - (e_width / 2);
950 e.style.top = set_y + "px";
951 e.style.left = set_x + "px";
953 exception_error("center_element", e);
957 function closeInfoBox() {
958 var box = document.getElementById('infoBox');
959 var shadow = document.getElementById('infoBoxShadow');
962 shadow.style.display = "none";
964 box.style.display = "none";
971 function displayDlg(id, param) {
973 if (!xmlhttp_ready(xmlhttp)) {
980 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
981 param_escape(id) + "¶m=" + param_escape(param), true);
982 xmlhttp.onreadystatechange=infobox_callback;
989 function infobox_submit_callback() {
990 if (xmlhttp.readyState == 4) {
991 notify(xmlhttp.responseText);
994 // called from prefs, reload tab
996 selectTab(active_tab, false);
1001 function infobox_callback() {
1002 if (xmlhttp.readyState == 4) {
1003 var box = document.getElementById('infoBox');
1004 var shadow = document.getElementById('infoBoxShadow');
1006 box.innerHTML=xmlhttp.responseText;
1008 shadow.style.display = "block";
1010 box.style.display = "block";
1016 function qaddFilter() {
1018 if (!xmlhttp_ready(xmlhttp)) {
1019 printLockingError();
1023 var regexp = document.getElementById("fadd_regexp");
1024 var match = document.getElementById("fadd_match");
1025 var feed = document.getElementById("fadd_feed");
1026 var action = document.getElementById("fadd_action");
1028 if (regexp.value.length == 0) {
1029 alert("Missing filter expression.");
1031 notify("Adding filter...");
1033 var v_match = match[match.selectedIndex].text;
1034 var feed_id = feed[feed.selectedIndex].id;
1035 var action_id = action[action.selectedIndex].id;
1037 xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" +
1038 param_escape(regexp.value) + "&match=" + v_match +
1039 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
1041 xmlhttp.onreadystatechange=infobox_submit_callback;
1049 function toggleSubmitNotEmpty(e, submit_id) {
1051 document.getElementById(submit_id).disabled = (e.value == "")
1053 exception_error("toggleSubmitNotEmpty", e);