1 var hotkeys_enabled = true;
3 function exception_error(location, e) {
7 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
9 msg = "Exception: " + e.name + ", " + e.message +
10 "\nFunction: " + location + "()" +
11 "\nLocation: " + base_fname + ":" + e.lineNumber;
13 msg = "Exception: " + e + "\nFunction: " + location + "()";
19 function disableHotkeys() {
20 hotkeys_enabled = false;
23 function enableHotkeys() {
24 hotkeys_enabled = true;
27 function xmlhttp_ready(obj) {
28 return obj.readyState == 4 || obj.readyState == 0 || !obj.readyState;
32 function notify_callback() {
33 var container = document.getElementById('notify');
34 if (xmlhttp.readyState == 4) {
35 container.innerHTML=xmlhttp.responseText;
39 function rpc_notify_callback() {
40 var container = document.getElementById('notify');
41 if (xmlhttp_rpc.readyState == 4) {
42 container.innerHTML=xmlhttp_rpc.responseText;
46 function rpc_pnotify_callback() {
47 var container = parent.document.getElementById('notify');
48 if (xmlhttp_rpc.readyState == 4) {
49 container.innerHTML=xmlhttp_rpc.responseText;
53 function param_escape(arg) {
54 if (typeof encodeURIComponent != 'undefined')
55 return encodeURIComponent(arg);
60 function param_unescape(arg) {
61 if (typeof decodeURIComponent != 'undefined')
62 return decodeURIComponent(arg);
69 then=new Date().getTime();
71 while((now-then)<gap) {
72 now=new Date().getTime();
76 function p_notify(msg) {
78 var n = parent.document.getElementById("notify");
79 var nb = parent.document.getElementById("notify_body");
81 if (!n || !nb) return;
84 nb.innerHTML = " ";
85 // n.style.background = "#ffffff";
88 // n.style.background = "#fffff0";
92 function notify(msg) {
94 var n = document.getElementById("notify");
95 var nb = document.getElementById("notify_body");
97 if (!n || !nb) return;
100 nb.innerHTML = " ";
101 // n.style.background = "#ffffff";
104 // n.style.background = "#fffff0";
109 function printLockingError() {
110 notify("Please wait until operation finishes");}
114 function hotkey_handler(e) {
118 if (!hotkeys_enabled) return;
121 keycode = window.event.keyCode;
126 if (keycode == 13 || keycode == 27) {
129 seq = seq + "" + keycode;
132 if (seq.match("807371717369")) {
134 localPiggieFunction(true);
136 localPiggieFunction(false);
139 if (typeof localHotkeyHandler != 'undefined') {
141 localHotkeyHandler(keycode);
143 exception_error("hotkey_handler", e);
149 function cleanSelectedList(element) {
150 var content = document.getElementById(element);
152 if (!document.getElementById("feedCatHolder")) {
153 for (i = 0; i < content.childNodes.length; i++) {
154 var child = content.childNodes[i];
155 child.className = child.className.replace("Selected", "");
158 for (i = 0; i < content.childNodes.length; i++) {
159 var child = content.childNodes[i];
161 if (child.id == "feedCatHolder") {
162 var fcat = child.lastChild;
163 for (j = 0; j < fcat.childNodes.length; j++) {
164 var feed = fcat.childNodes[j];
165 feed.className = feed.className.replace("Selected", "");
174 function cleanSelected(element) {
175 var content = document.getElementById(element);
177 for (i = 0; i < content.rows.length; i++) {
178 content.rows[i].className = content.rows[i].className.replace("Selected", "");
183 function getVisibleUnreadHeadlines() {
184 var content = document.getElementById("headlinesList");
186 var rows = new Array();
188 for (i = 0; i < content.rows.length; i++) {
189 var row_id = content.rows[i].id.replace("RROW-", "");
190 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
197 function getVisibleHeadlineIds() {
199 var content = document.getElementById("headlinesList");
201 var rows = new Array();
203 for (i = 0; i < content.rows.length; i++) {
204 var row_id = content.rows[i].id.replace("RROW-", "");
205 if (row_id.length > 0) {
212 function getFirstVisibleHeadlineId() {
213 var rows = getVisibleHeadlineIds();
217 function getLastVisibleHeadlineId() {
218 var rows = getVisibleHeadlineIds();
219 return rows[rows.length-1];
222 function markHeadline(id) {
223 var row = document.getElementById("RROW-" + id);
225 var is_active = false;
227 if (row.className.match("Active")) {
230 row.className = row.className.replace("Selected", "");
231 row.className = row.className.replace("Active", "");
232 row.className = row.className.replace("Insensitive", "");
235 row.className = row.className = "Active";
238 row.className = row.className + "Selected";
243 function getFeedIds() {
244 var content = document.getElementById("feedsList");
246 var rows = new Array();
248 for (i = 0; i < content.rows.length; i++) {
249 var id = content.rows[i].id.replace("FEEDR-", "");
258 function setCookie(name, value, expires, path, domain, secure) {
259 document.cookie= name + "=" + escape(value) +
260 ((expires) ? "; expires=" + expires.toGMTString() : "") +
261 ((path) ? "; path=" + path : "") +
262 ((domain) ? "; domain=" + domain : "") +
263 ((secure) ? "; secure" : "");
266 function getCookie(name) {
268 var dc = document.cookie;
269 var prefix = name + "=";
270 var begin = dc.indexOf("; " + prefix);
272 begin = dc.indexOf(prefix);
273 if (begin != 0) return null;
278 var end = document.cookie.indexOf(";", begin);
282 return unescape(dc.substring(begin + prefix.length, end));
285 function disableContainerChildren(id, disable, doc) {
287 if (!doc) doc = document;
289 var container = doc.getElementById(id);
291 for (var i = 0; i < container.childNodes.length; i++) {
292 var child = container.childNodes[i];
295 child.disabled = disable;
301 if (child.className && child.className.match("button")) {
302 child.className = "disabledButton";
305 if (child.className && child.className.match("disabledButton")) {
306 child.className = "button";
313 function gotoPreferences() {
314 document.location.href = "prefs.php";
317 function gotoMain() {
318 document.location.href = "tt-rss.php";
321 function gotoExportOpml() {
322 document.location.href = "opml.php?op=Export";
325 function getActiveFeedId() {
326 return getCookie("ttrss_vf_actfeed");
329 function setActiveFeedId(id) {
330 return setCookie("ttrss_vf_actfeed", id);
333 var xmlhttp_rpc = false;
336 /*@if (@_jscript_version >= 5)
337 // JScript gives us Conditional compilation, we can cope with old IE versions.
338 // and security blocked creation of the objects.
340 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
343 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
350 if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
351 xmlhttp_rpc = new XMLHttpRequest();
354 function parse_counters(reply, f_document, title_obj) {
356 for (var l = 0; l < reply.childNodes.length; l++) {
357 if (!reply.childNodes[l] ||
358 typeof(reply.childNodes[l].getAttribute) == "undefined") {
359 // where did this come from?
363 var id = reply.childNodes[l].getAttribute("id");
364 var t = reply.childNodes[l].getAttribute("type");
365 var ctr = reply.childNodes[l].getAttribute("counter");
366 var error = reply.childNodes[l].getAttribute("error");
367 var has_img = reply.childNodes[l].getAttribute("hi");
369 if (id == "global-unread") {
370 title_obj.global_unread = ctr;
371 title_obj.updateTitle();
375 if (t == "category") {
376 var catctr = f_document.getElementById("FCATCTR-" + id);
378 catctr.innerHTML = "(" + ctr + " unread)";
383 var feedctr = f_document.getElementById("FEEDCTR-" + id);
384 var feedu = f_document.getElementById("FEEDU-" + id);
385 var feedr = f_document.getElementById("FEEDR-" + id);
386 var feed_img = f_document.getElementById("FIMG-" + id);
388 if (feedctr && feedu && feedr) {
390 feedu.innerHTML = ctr;
393 feedr.className = feedr.className.replace("feed", "error");
395 feedr.className = feedr.className.replace("error", "feed");
399 feedctr.className = "odd";
400 if (!feedr.className.match("Unread")) {
401 var is_selected = feedr.className.match("Selected");
403 feedr.className = feedr.className.replace("Selected", "");
404 feedr.className = feedr.className.replace("Unread", "");
406 feedr.className = feedr.className + "Unread";
409 feedr.className = feedr.className + "Selected";
414 feedctr.className = "invisible";
415 feedr.className = feedr.className.replace("Unread", "");
420 exception_error("parse_counters", e);
424 // this one is called from feedlist context
425 // thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
427 function all_counters_callback() {
428 if (xmlhttp_rpc.readyState == 4) {
430 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
431 notify("[all_counters_callback] backend did not return valid XML");
435 var reply = xmlhttp_rpc.responseXML.firstChild;
436 var f_document = parent.frames["feeds-frame"].document;
438 parse_counters(reply, f_document, parent);
441 exception_error("all_counters_callback", e);
446 function update_all_counters(feed) {
447 if (xmlhttp_ready(xmlhttp_rpc)) {
448 var query = "backend.php?op=rpc&subop=getAllCounters";
451 query = query + "&aid=" + feed;
454 xmlhttp_rpc.open("GET", query, true);
455 xmlhttp_rpc.onreadystatechange=all_counters_callback;
456 xmlhttp_rpc.send(null);
460 function popupHelp(tid) {
461 var w = window.open("backend.php?op=help&tid=" + tid,
463 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
466 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
467 * * @author Sundar Dorai-Raj
468 * * Email: sdoraira@vt.edu
469 * * This program is free software; you can redistribute it and/or
470 * * modify it under the terms of the GNU General Public License
471 * * as published by the Free Software Foundation; either version 2
472 * * of the License, or (at your option) any later version,
473 * * provided that any use properly credits the author.
474 * * This program is distributed in the hope that it will be useful,
475 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
476 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
477 * * GNU General Public License for more details at http://www.gnu.org * * */
479 var numbers=".0123456789";
480 function isNumeric(x) {
481 // is x a String or a character?
483 // remove negative sign
485 for(j=0;j<x.length;j++) {
486 // call isNumeric recursively for each character
487 number=isNumeric(x.substring(j,j+1));
488 if(!number) return number;
493 // if x is number return true
494 if(numbers.indexOf(x)>=0) return true;
500 function hideOrShowFeeds(doc, hide) {
502 if (!doc.styleSheets) return;
504 var css_rules = doc.styleSheets[0].cssRules;
506 if (!css_rules || !css_rules.length) return;
508 for (i = 0; i < css_rules.length; i++) {
509 var rule = css_rules[i];
511 if (rule.selectorText == "ul.feedList li.feed") {
513 rule.style.display = "block";
515 rule.style.display = "none";
523 function fatalError(code, params) {
525 window.location = "error.php?c=" + param_escape(code);
527 window.location = "error.php?c=" + param_escape(code) +
528 "&p=" + param_escape(params);
532 function selectTableRow(r, do_select) {
533 r.className = r.className.replace("Selected", "");
536 r.className = r.className + "Selected";
540 function selectTableRowById(elem_id, check_id, do_select) {
544 var row = document.getElementById(elem_id);
547 selectTableRow(row, do_select);
550 var check = document.getElementById(check_id);
553 check.checked = do_select;
556 exception_error("selectTableRowById", e);
560 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
561 classcheck, reset_others) {
563 var content = document.getElementById(content_id);
566 alert("[selectTableRows] Element " + content_id + " not found.");
570 for (i = 0; i < content.rows.length; i++) {
571 if (!classcheck || content.rows[i].className.match(classcheck)) {
573 if (content.rows[i].id.match(prefix)) {
574 selectTableRow(content.rows[i], do_select);
576 var row_id = content.rows[i].id.replace(prefix, "");
577 var check = document.getElementById(check_prefix + row_id);
580 check.checked = do_select;
582 } else if (reset_others) {
583 selectTableRow(content.rows[i], false);
585 var row_id = content.rows[i].id.replace(prefix, "");
586 var check = document.getElementById(check_prefix + row_id);
589 check.checked = false;
593 } else if (reset_others) {
594 selectTableRow(content.rows[i], false);
596 var row_id = content.rows[i].id.replace(prefix, "");
597 var check = document.getElementById(check_prefix + row_id);
600 check.checked = false;
607 function getSelectedTableRowIds(content_id, prefix) {
609 var content = document.getElementById(content_id);
612 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
616 var sel_rows = new Array();
618 for (i = 0; i < content.rows.length; i++) {
619 if (content.rows[i].id.match(prefix) &&
620 content.rows[i].className.match("Selected")) {
622 var row_id = content.rows[i].id.replace(prefix + "-", "");
623 sel_rows.push(row_id);
631 function toggleSelectRowById(sender, id) {
632 var row = document.getElementById(id);
634 if (sender.checked) {
635 if (!row.className.match("Selected")) {
636 row.className = row.className + "Selected";
639 if (row.className.match("Selected")) {
640 row.className = row.className.replace("Selected", "");
645 function toggleSelectListRow(sender) {
646 var parent_row = sender.parentNode;
648 if (sender.checked) {
649 if (!parent_row.className.match("Selected")) {
650 parent_row.className = parent_row.className + "Selected";
653 if (parent_row.className.match("Selected")) {
654 parent_row.className = parent_row.className.replace("Selected", "");
660 function toggleSelectRow(sender) {
661 var parent_row = sender.parentNode.parentNode;
663 if (sender.checked) {
664 if (!parent_row.className.match("Selected")) {
665 parent_row.className = parent_row.className + "Selected";
668 if (parent_row.className.match("Selected")) {
669 parent_row.className = parent_row.className.replace("Selected", "");
674 function openExternalUrl(url) {
675 var w = window.open(url);
679 function getRelativeFeedId(list, id, direction) {
681 if (direction == "next") {
682 for (i = 0; i < list.childNodes.length; i++) {
683 var child = list.childNodes[i];
684 if (child.id == "feedCatHolder") {
685 if (child.lastChild) {
686 var cr = getRelativeFeedId(child.firstChild, id, direction);
689 } else if (child.id.match("FEEDR-")) {
690 return child.id.replace('FEEDR-', '');
695 // FIXME select last feed doesn't work when only unread feeds are visible
697 if (direction == "prev") {
698 for (i = list.childNodes.length-1; i >= 0; i--) {
699 var child = list.childNodes[i];
700 if (child.id == "feedCatHolder") {
701 if (child.firstChild) {
702 var cr = getRelativeFeedId(child.firstChild, id, direction);
705 } else if (child.id.match("FEEDR-")) {
707 if (getCookie("ttrss_vf_hreadf") == 1) {
708 if (child.className != "feed") {
709 alert(child.className);
710 return child.id.replace('FEEDR-', '');
713 return child.id.replace('FEEDR-', '');
720 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
722 if (direction == "next") {
724 if (feed.nextSibling) {
726 var next_feed = feed.nextSibling;
728 while (!next_feed.id && next_feed.nextSibling) {
729 next_feed = next_feed.nextSibling;
732 if (getCookie("ttrss_vf_hreadf") == 1) {
733 while (next_feed && next_feed.className == "feed") {
734 next_feed = next_feed.nextSibling;
738 if (next_feed && next_feed.id.match("FEEDR-")) {
739 return next_feed.id.replace("FEEDR-", "");
743 var this_cat = feed.parentNode.parentNode;
745 if (this_cat && this_cat.nextSibling) {
746 while (this_cat = this_cat.nextSibling) {
747 if (this_cat.firstChild && this_cat.firstChild.firstChild) {
748 var next_feed = this_cat.firstChild.firstChild;
749 if (getCookie("ttrss_vf_hreadf") == 1) {
750 while (next_feed && next_feed.className == "feed") {
751 next_feed = next_feed.nextSibling;
754 if (next_feed && next_feed.id.match("FEEDR-")) {
755 return next_feed.id.replace("FEEDR-", "");
760 } else if (direction == "prev") {
762 if (feed.previousSibling) {
764 var prev_feed = feed.previousSibling;
766 if (getCookie("ttrss_vf_hreadf") == 1) {
767 while (prev_feed && prev_feed.className == "feed") {
768 prev_feed = prev_feed.previousSibling;
772 while (!prev_feed.id && prev_feed.previousSibling) {
773 prev_feed = prev_feed.previousSibling;
776 if (prev_feed && prev_feed.id.match("FEEDR-")) {
777 return prev_feed.id.replace("FEEDR-", "");
781 var this_cat = feed.parentNode.parentNode;
783 if (this_cat && this_cat.previousSibling) {
784 while (this_cat = this_cat.previousSibling) {
785 if (this_cat.lastChild && this_cat.firstChild.lastChild) {
786 var prev_feed = this_cat.firstChild.lastChild;
787 if (getCookie("ttrss_vf_hreadf") == 1) {
788 while (prev_feed && prev_feed.className == "feed") {
789 prev_feed = prev_feed.previousSibling;
792 if (prev_feed && prev_feed.id.match("FEEDR-")) {
793 return prev_feed.id.replace("FEEDR-", "");
802 function showBlockElement(id) {
803 var elem = document.getElementById(id);
806 elem.style.display = "block";
808 alert("[showBlockElement] can't find element with id " + id);
812 function hideParentElement(e) {
813 e.parentNode.style.display = "none";
816 function dropboxSelect(e, v) {
817 for (i = 0; i < e.length; i++) {
818 if (e[i].value == v) {