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 (document.getElementById("piggie")) {
134 if (seq.match("807371717369")) {
136 localPiggieFunction(true);
138 localPiggieFunction(false);
142 if (typeof localHotkeyHandler != 'undefined') {
144 localHotkeyHandler(keycode);
146 exception_error("hotkey_handler", e);
152 function cleanSelectedList(element) {
153 var content = document.getElementById(element);
155 if (!document.getElementById("feedCatHolder")) {
156 for (i = 0; i < content.childNodes.length; i++) {
157 var child = content.childNodes[i];
159 child.className = child.className.replace("Selected", "");
165 for (i = 0; i < content.childNodes.length; i++) {
166 var child = content.childNodes[i];
168 if (child.id == "feedCatHolder") {
169 var fcat = child.lastChild;
170 for (j = 0; j < fcat.childNodes.length; j++) {
171 var feed = fcat.childNodes[j];
172 feed.className = feed.className.replace("Selected", "");
181 function cleanSelected(element) {
182 var content = document.getElementById(element);
184 for (i = 0; i < content.rows.length; i++) {
185 content.rows[i].className = content.rows[i].className.replace("Selected", "");
189 function getVisibleUnreadHeadlines() {
190 var content = document.getElementById("headlinesList");
192 var rows = new Array();
194 for (i = 0; i < content.rows.length; i++) {
195 var row_id = content.rows[i].id.replace("RROW-", "");
196 if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
203 function getVisibleHeadlineIds() {
205 var content = document.getElementById("headlinesList");
207 var rows = new Array();
209 for (i = 0; i < content.rows.length; i++) {
210 var row_id = content.rows[i].id.replace("RROW-", "");
211 if (row_id.length > 0) {
218 function getFirstVisibleHeadlineId() {
219 var rows = getVisibleHeadlineIds();
223 function getLastVisibleHeadlineId() {
224 var rows = getVisibleHeadlineIds();
225 return rows[rows.length-1];
228 function markHeadline(id) {
229 var row = document.getElementById("RROW-" + id);
231 var is_active = false;
233 if (row.className.match("Active")) {
236 row.className = row.className.replace("Selected", "");
237 row.className = row.className.replace("Active", "");
238 row.className = row.className.replace("Insensitive", "");
241 row.className = row.className = "Active";
244 var check = document.getElementById("RCHK-" + id);
247 check.checked = true;
250 row.className = row.className + "Selected";
255 function getFeedIds() {
256 var content = document.getElementById("feedsList");
258 var rows = new Array();
260 for (i = 0; i < content.rows.length; i++) {
261 var id = content.rows[i].id.replace("FEEDR-", "");
270 function setCookie(name, value, lifetime, path, domain, secure) {
276 d.setTime(lifetime * 1000);
279 int_setCookie(name, value, d, path, domain, secure);
283 function int_setCookie(name, value, expires, path, domain, secure) {
284 document.cookie= name + "=" + escape(value) +
285 ((expires) ? "; expires=" + expires.toGMTString() : "") +
286 ((path) ? "; path=" + path : "") +
287 ((domain) ? "; domain=" + domain : "") +
288 ((secure) ? "; secure" : "");
291 function delCookie(name, path, domain) {
292 if (getCookie(name)) {
293 document.cookie = name + "=" +
294 ((path) ? ";path=" + path : "") +
295 ((domain) ? ";domain=" + domain : "" ) +
296 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
301 function getCookie(name) {
303 var dc = document.cookie;
304 var prefix = name + "=";
305 var begin = dc.indexOf("; " + prefix);
307 begin = dc.indexOf(prefix);
308 if (begin != 0) return null;
313 var end = document.cookie.indexOf(";", begin);
317 return unescape(dc.substring(begin + prefix.length, end));
320 function disableContainerChildren(id, disable, doc) {
322 if (!doc) doc = document;
324 var container = doc.getElementById(id);
326 for (var i = 0; i < container.childNodes.length; i++) {
327 var child = container.childNodes[i];
330 child.disabled = disable;
336 if (child.className && child.className.match("button")) {
337 child.className = "disabledButton";
340 if (child.className && child.className.match("disabledButton")) {
341 child.className = "button";
348 function gotoPreferences() {
349 document.location.href = "prefs.php";
352 function gotoMain() {
353 document.location.href = "tt-rss.php";
356 function gotoExportOpml() {
357 document.location.href = "opml.php?op=Export";
360 function getActiveFeedId() {
361 return getCookie("ttrss_vf_actfeed");
364 function setActiveFeedId(id) {
365 return setCookie("ttrss_vf_actfeed", id);
368 var xmlhttp_rpc = false;
371 /*@if (@_jscript_version >= 5)
372 // JScript gives us Conditional compilation, we can cope with old IE versions.
373 // and security blocked creation of the objects.
375 xmlhttp_rpc = new ActiveXObject("Msxml2.XMLHTTP");
378 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
385 if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
386 xmlhttp_rpc = new XMLHttpRequest();
389 function parse_counters(reply, f_document, title_obj, scheduled_call) {
391 for (var l = 0; l < reply.childNodes.length; l++) {
392 if (!reply.childNodes[l] ||
393 typeof(reply.childNodes[l].getAttribute) == "undefined") {
394 // where did this come from?
398 var id = reply.childNodes[l].getAttribute("id");
399 var t = reply.childNodes[l].getAttribute("type");
400 var ctr = reply.childNodes[l].getAttribute("counter");
401 var error = reply.childNodes[l].getAttribute("error");
402 var has_img = reply.childNodes[l].getAttribute("hi");
404 if (id == "global-unread") {
405 title_obj.global_unread = ctr;
406 title_obj.updateTitle();
410 if (t == "category") {
411 var catctr = f_document.getElementById("FCATCTR-" + id);
413 catctr.innerHTML = "(" + ctr + " unread)";
418 var feedctr = f_document.getElementById("FEEDCTR-" + id);
419 var feedu = f_document.getElementById("FEEDU-" + id);
420 var feedr = f_document.getElementById("FEEDR-" + id);
421 var feed_img = f_document.getElementById("FIMG-" + id);
423 if (feedctr && feedu && feedr) {
425 if (feedu.innerHTML != ctr && id == getActiveFeedId() && scheduled_call) {
426 var hf = title_obj.parent.frames["headlines-frame"];
427 hf.location.reload(true);
430 feedu.innerHTML = ctr;
433 feedr.className = feedr.className.replace("feed", "error");
435 feedr.className = feedr.className.replace("error", "feed");
439 feedctr.className = "odd";
440 if (!feedr.className.match("Unread")) {
441 var is_selected = feedr.className.match("Selected");
443 feedr.className = feedr.className.replace("Selected", "");
444 feedr.className = feedr.className.replace("Unread", "");
446 feedr.className = feedr.className + "Unread";
449 feedr.className = feedr.className + "Selected";
454 feedctr.className = "invisible";
455 feedr.className = feedr.className.replace("Unread", "");
460 exception_error("parse_counters", e);
464 // this one is called from feedlist context
465 // thus title_obj passed to parse_counters is parent (e.g. main ttrss window)
467 function all_counters_callback() {
468 if (xmlhttp_rpc.readyState == 4) {
470 if (!xmlhttp_rpc.responseXML || !xmlhttp_rpc.responseXML.firstChild) {
471 notify("[all_counters_callback] backend did not return valid XML");
475 if (!parent.frames["feeds-frame"]) {
476 notify("[all_counters_callback] no parent feeds-frame");
480 var reply = xmlhttp_rpc.responseXML.firstChild;
481 var f_document = parent.frames["feeds-frame"].document;
483 parse_counters(reply, f_document, parent);
486 exception_error("all_counters_callback", e);
491 function update_all_counters(feed) {
492 if (xmlhttp_ready(xmlhttp_rpc)) {
493 var query = "backend.php?op=rpc&subop=getAllCounters";
496 query = query + "&aid=" + feed;
499 xmlhttp_rpc.open("GET", query, true);
500 xmlhttp_rpc.onreadystatechange=all_counters_callback;
501 xmlhttp_rpc.send(null);
505 function popupHelp(tid) {
506 var w = window.open("backend.php?op=help&tid=" + tid,
508 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
511 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
512 * * @author Sundar Dorai-Raj
513 * * Email: sdoraira@vt.edu
514 * * This program is free software; you can redistribute it and/or
515 * * modify it under the terms of the GNU General Public License
516 * * as published by the Free Software Foundation; either version 2
517 * * of the License, or (at your option) any later version,
518 * * provided that any use properly credits the author.
519 * * This program is distributed in the hope that it will be useful,
520 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
521 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
522 * * GNU General Public License for more details at http://www.gnu.org * * */
524 var numbers=".0123456789";
525 function isNumeric(x) {
526 // is x a String or a character?
528 // remove negative sign
530 for(j=0;j<x.length;j++) {
531 // call isNumeric recursively for each character
532 number=isNumeric(x.substring(j,j+1));
533 if(!number) return number;
538 // if x is number return true
539 if(numbers.indexOf(x)>=0) return true;
545 function hideOrShowFeeds(doc, hide) {
547 if (!doc.styleSheets) return;
549 var css_rules = doc.styleSheets[0].cssRules;
551 if (!css_rules || !css_rules.length) return;
553 for (i = 0; i < css_rules.length; i++) {
554 var rule = css_rules[i];
556 if (rule.selectorText == "ul.feedList li.feed") {
558 rule.style.display = "block";
560 rule.style.display = "none";
568 function fatalError(code, params) {
570 window.location = "error.php?c=" + param_escape(code);
572 window.location = "error.php?c=" + param_escape(code) +
573 "&p=" + param_escape(params);
577 function selectTableRow(r, do_select) {
578 r.className = r.className.replace("Selected", "");
581 r.className = r.className + "Selected";
585 function selectTableRowById(elem_id, check_id, do_select) {
589 var row = document.getElementById(elem_id);
592 selectTableRow(row, do_select);
595 var check = document.getElementById(check_id);
598 check.checked = do_select;
601 exception_error("selectTableRowById", e);
605 function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
606 classcheck, reset_others) {
608 var content = document.getElementById(content_id);
611 alert("[selectTableRows] Element " + content_id + " not found.");
615 for (i = 0; i < content.rows.length; i++) {
616 if (!classcheck || content.rows[i].className.match(classcheck)) {
618 if (content.rows[i].id.match(prefix)) {
619 selectTableRow(content.rows[i], do_select);
621 var row_id = content.rows[i].id.replace(prefix, "");
622 var check = document.getElementById(check_prefix + row_id);
625 check.checked = do_select;
627 } else if (reset_others) {
628 selectTableRow(content.rows[i], false);
630 var row_id = content.rows[i].id.replace(prefix, "");
631 var check = document.getElementById(check_prefix + row_id);
634 check.checked = false;
638 } else if (reset_others) {
639 selectTableRow(content.rows[i], false);
641 var row_id = content.rows[i].id.replace(prefix, "");
642 var check = document.getElementById(check_prefix + row_id);
645 check.checked = false;
652 function getSelectedTableRowIds(content_id, prefix) {
654 var content = document.getElementById(content_id);
657 alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
661 var sel_rows = new Array();
663 for (i = 0; i < content.rows.length; i++) {
664 if (content.rows[i].id.match(prefix) &&
665 content.rows[i].className.match("Selected")) {
667 var row_id = content.rows[i].id.replace(prefix + "-", "");
668 sel_rows.push(row_id);
676 function toggleSelectRowById(sender, id) {
677 var row = document.getElementById(id);
679 if (sender.checked) {
680 if (!row.className.match("Selected")) {
681 row.className = row.className + "Selected";
684 if (row.className.match("Selected")) {
685 row.className = row.className.replace("Selected", "");
690 function toggleSelectListRow(sender) {
691 var parent_row = sender.parentNode;
693 if (sender.checked) {
694 if (!parent_row.className.match("Selected")) {
695 parent_row.className = parent_row.className + "Selected";
698 if (parent_row.className.match("Selected")) {
699 parent_row.className = parent_row.className.replace("Selected", "");
705 function toggleSelectRow(sender) {
706 var parent_row = sender.parentNode.parentNode;
708 if (sender.checked) {
709 if (!parent_row.className.match("Selected")) {
710 parent_row.className = parent_row.className + "Selected";
713 if (parent_row.className.match("Selected")) {
714 parent_row.className = parent_row.className.replace("Selected", "");
719 function openExternalUrl(url) {
720 var w = window.open(url);
724 function getRelativeFeedId(list, id, direction) {
726 if (direction == "next") {
727 for (i = 0; i < list.childNodes.length; i++) {
728 var child = list.childNodes[i];
729 if (child.id == "feedCatHolder") {
730 if (child.lastChild) {
731 var cr = getRelativeFeedId(child.firstChild, id, direction);
734 } else if (child.id.match("FEEDR-")) {
735 return child.id.replace('FEEDR-', '');
740 // FIXME select last feed doesn't work when only unread feeds are visible
742 if (direction == "prev") {
743 for (i = list.childNodes.length-1; i >= 0; i--) {
744 var child = list.childNodes[i];
745 if (child.id == "feedCatHolder") {
746 if (child.firstChild) {
747 var cr = getRelativeFeedId(child.firstChild, id, direction);
750 } else if (child.id.match("FEEDR-")) {
752 if (getCookie("ttrss_vf_hreadf") == 1) {
753 if (child.className != "feed") {
754 alert(child.className);
755 return child.id.replace('FEEDR-', '');
758 return child.id.replace('FEEDR-', '');
765 var feed = list.ownerDocument.getElementById("FEEDR-" + getActiveFeedId());
767 if (direction == "next") {
769 if (feed.nextSibling) {
771 var next_feed = feed.nextSibling;
773 while (!next_feed.id && next_feed.nextSibling) {
774 next_feed = next_feed.nextSibling;
777 if (getCookie("ttrss_vf_hreadf") == 1) {
778 while (next_feed && next_feed.className == "feed") {
779 next_feed = next_feed.nextSibling;
783 if (next_feed && next_feed.id.match("FEEDR-")) {
784 return next_feed.id.replace("FEEDR-", "");
788 var this_cat = feed.parentNode.parentNode;
790 if (this_cat && this_cat.nextSibling) {
791 while (this_cat = this_cat.nextSibling) {
792 if (this_cat.firstChild && this_cat.firstChild.firstChild) {
793 var next_feed = this_cat.firstChild.firstChild;
794 if (getCookie("ttrss_vf_hreadf") == 1) {
795 while (next_feed && next_feed.className == "feed") {
796 next_feed = next_feed.nextSibling;
799 if (next_feed && next_feed.id.match("FEEDR-")) {
800 return next_feed.id.replace("FEEDR-", "");
805 } else if (direction == "prev") {
807 if (feed.previousSibling) {
809 var prev_feed = feed.previousSibling;
811 if (getCookie("ttrss_vf_hreadf") == 1) {
812 while (prev_feed && prev_feed.className == "feed") {
813 prev_feed = prev_feed.previousSibling;
817 while (!prev_feed.id && prev_feed.previousSibling) {
818 prev_feed = prev_feed.previousSibling;
821 if (prev_feed && prev_feed.id.match("FEEDR-")) {
822 return prev_feed.id.replace("FEEDR-", "");
826 var this_cat = feed.parentNode.parentNode;
828 if (this_cat && this_cat.previousSibling) {
829 while (this_cat = this_cat.previousSibling) {
830 if (this_cat.lastChild && this_cat.firstChild.lastChild) {
831 var prev_feed = this_cat.firstChild.lastChild;
832 if (getCookie("ttrss_vf_hreadf") == 1) {
833 while (prev_feed && prev_feed.className == "feed") {
834 prev_feed = prev_feed.previousSibling;
837 if (prev_feed && prev_feed.id.match("FEEDR-")) {
838 return prev_feed.id.replace("FEEDR-", "");
847 function showBlockElement(id) {
848 var elem = document.getElementById(id);
851 elem.style.display = "block";
853 alert("[showBlockElement] can't find element with id " + id);
857 function hideParentElement(e) {
858 e.parentNode.style.display = "none";
861 function dropboxSelect(e, v) {
862 for (i = 0; i < e.length; i++) {
863 if (e[i].value == v) {
870 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
871 // bugfixed just a little bit :-)
872 function getURLParam(strParamName){
874 var strHref = window.location.href;
876 if (strHref.indexOf("#") == strHref.length-1) {
877 strHref = strHref.substring(0, strHref.length-1);
880 if ( strHref.indexOf("?") > -1 ){
881 var strQueryString = strHref.substr(strHref.indexOf("?"));
882 var aQueryString = strQueryString.split("&");
883 for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
884 if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
885 var aParam = aQueryString[iParam].split("=");
886 strReturn = aParam[1];
894 function leading_zero(p) {
896 if (s.length == 1) s = "0" + s;
900 function center_element(e) {
903 var c_width = document.body.clientWidth;
904 var c_height = document.body.clientHeight;
906 var c_scroll = document.body.scrollTop;
908 var e_width = e.clientWidth;
909 var e_height = e.clientHeight;
911 var set_y = (c_height / 2) + c_scroll - (e_height / 2);
912 var set_x = (c_width / 2) - (e_width / 2);
914 e.style.top = set_y + "px";
915 e.style.left = set_x + "px";
917 exception_error("center_element", e);