]>
git.wh0rd.org - tt-rss.git/blob - functions.js
1 var hotkeys_enabled
= true;
3 var xmlhttp_rpc
= Ajax
.getTransport();
5 function browser_has_opacity() {
6 return navigator
.userAgent
.match("Gecko") != null ||
7 navigator
.userAgent
.match("Opera") != null;
10 function exception_error(location
, e
) {
14 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
16 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
17 "\nFunction: " + location
+ "()" +
18 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
21 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
24 debug("<b>EXCEPTION: " + msg
+ "</b>");
29 function disableHotkeys() {
30 hotkeys_enabled
= false;
33 function enableHotkeys() {
34 hotkeys_enabled
= true;
37 function xmlhttp_ready(obj
) {
38 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
41 function notify_callback() {
42 var container
= document
.getElementById('notify');
43 if (xmlhttp
.readyState
== 4) {
44 container
.innerHTML
=xmlhttp
.responseText
;
48 function rpc_notify_callback() {
49 var container
= document
.getElementById('notify');
50 if (xmlhttp_rpc
.readyState
== 4) {
51 container
.innerHTML
=xmlhttp_rpc
.responseText
;
55 function param_escape(arg
) {
56 if (typeof encodeURIComponent
!= 'undefined')
57 return encodeURIComponent(arg
);
62 function param_unescape(arg
) {
63 if (typeof decodeURIComponent
!= 'undefined')
64 return decodeURIComponent(arg
);
71 then
=new Date().getTime();
73 while((now
-then
)<gap
) {
74 now
=new Date().getTime();
78 var notify_hide_timerid
= false;
79 var notify_last_doc
= false;
81 var notify_effect
= false;
83 function hide_notify() {
84 if (notify_last_doc
) {
85 var n
= notify_last_doc
.getElementById("notify");
86 if (browser_has_opacity()) {
87 if (notify_opacity
>= 0) {
88 notify_opacity
= notify_opacity
- 0.1;
89 n
.style
.opacity
= notify_opacity
;
90 notify_hide_timerid
= window
.setTimeout("hide_notify()", 20);
92 n
.style
.display
= "none";
96 n
.style
.display
= "none";
101 function notify_real(msg
, doc
, no_hide
, is_err
) {
103 var n
= doc
.getElementById("notify");
104 var nb
= doc
.getElementById("notify_body");
106 if (!n
|| !nb
) return;
108 if (notify_hide_timerid
) {
109 window
.clearTimeout(notify_hide_timerid
);
112 notify_last_doc
= doc
;
116 if (n
.style
.display
== "block") {
117 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
121 n
.style
.display
= "block";
125 n
.style
.backgroundColor
= "#ffcccc";
126 n
.style
.color
= "black";
127 n
.style
.borderColor
= "#ff0000";
129 n
.style
.backgroundColor
= "#fff7d5";
130 n
.style
.borderColor
= "#d7c47a";
131 n
.style
.color
= "black";
137 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
141 function p_notify(msg
, no_hide
, is_err
) {
142 notify_real(msg
, parent
.document
, no_hide
, is_err
);
145 function notify(msg
, no_hide
, is_err
) {
146 notify_real(msg
, document
, no_hide
, is_err
);
149 function printLockingError() {
150 notify("Please wait until operation finishes");}
154 function hotkey_handler(e
) {
160 if (!hotkeys_enabled
) return;
163 keycode
= window
.event
.keyCode
;
168 if (keycode
== 13 || keycode
== 27) {
171 seq
= seq
+ "" + keycode
;
174 var m_ctx
= getMainContext();
175 var f_ctx
= getFeedsContext();
176 var h_ctx
= getHeadlinesContext();
178 if (keycode
== 82) { // r
179 return m_ctx
.scheduleFeedUpdate(true);
182 if (keycode
== 83) { // r
183 return m_ctx
.displayDlg("search", getActiveFeedId());
186 if (keycode
== 85) { // u
187 if (getActiveFeedId()) {
188 return f_ctx
.viewfeed(getActiveFeedId(), 0, "ForceUpdate");
192 if (keycode
== 65) { // a
193 return m_ctx
.toggleDispRead();
196 var f_doc
= m_ctx
.frames
["feeds-frame"].document
;
197 var feedlist
= f_doc
.getElementById('feedList');
199 if (keycode
== 74) { // j
200 var feed
= getActiveFeedId();
201 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
202 if (new_feed
) viewfeed(new_feed
, 0, '');
205 if (keycode
== 75) { // k
206 var feed
= getActiveFeedId();
207 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
208 if (new_feed
) viewfeed(new_feed
, 0, '');
211 if (keycode
== 78 || keycode
== 40) { // n, down
212 return h_ctx
.moveToPost('next');
215 if (keycode
== 80 || keycode
== 38) { // p, up
216 return h_ctx
.moveToPost('prev');
219 if (document
.getElementById("piggie")) {
221 if (seq
.match("807371717369")) {
223 localPiggieFunction(true);
225 localPiggieFunction(false);
229 if (typeof localHotkeyHandler
!= 'undefined') {
231 localHotkeyHandler(keycode
);
233 exception_error("hotkey_handler, local:", e
);
237 exception_error("hotkey_handler", e
);
241 function cleanSelectedList(element
) {
242 var content
= document
.getElementById(element
);
244 if (!document
.getElementById("feedCatHolder")) {
245 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
246 var child
= content
.childNodes
[i
];
248 child
.className
= child
.className
.replace("Selected", "");
254 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
255 var child
= content
.childNodes
[i
];
256 if (child
.id
== "feedCatHolder") {
257 parent
.debug(child
.id
);
258 var fcat
= child
.lastChild
;
259 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
260 var feed
= fcat
.childNodes
[j
];
261 feed
.className
= feed
.className
.replace("Selected", "");
269 function cleanSelected(element
) {
270 var content
= document
.getElementById(element
);
272 for (i
= 0; i
< content
.rows
.length
; i
++) {
273 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
277 function getVisibleUnreadHeadlines() {
278 var content
= document
.getElementById("headlinesList");
280 var rows
= new Array();
282 for (i
= 0; i
< content
.rows
.length
; i
++) {
283 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
284 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
291 function getVisibleHeadlineIds() {
293 var content
= document
.getElementById("headlinesList");
295 var rows
= new Array();
297 for (i
= 0; i
< content
.rows
.length
; i
++) {
298 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
299 if (row_id
.length
> 0) {
306 function getFirstVisibleHeadlineId() {
307 var rows
= getVisibleHeadlineIds();
311 function getLastVisibleHeadlineId() {
312 var rows
= getVisibleHeadlineIds();
313 return rows
[rows
.length
-1];
316 function markHeadline(id
) {
317 var row
= document
.getElementById("RROW-" + id
);
319 var is_active
= false;
321 if (row
.className
.match("Active")) {
324 row
.className
= row
.className
.replace("Selected", "");
325 row
.className
= row
.className
.replace("Active", "");
326 row
.className
= row
.className
.replace("Insensitive", "");
329 row
.className
= row
.className
= "Active";
332 var check
= document
.getElementById("RCHK-" + id
);
335 check
.checked
= true;
338 row
.className
= row
.className
+ "Selected";
343 function getFeedIds() {
344 var content
= document
.getElementById("feedsList");
346 var rows
= new Array();
348 for (i
= 0; i
< content
.rows
.length
; i
++) {
349 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
358 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
364 d
.setTime(lifetime
* 1000);
367 int_setCookie(name
, value
, d
, path
, domain
, secure
);
371 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
372 document
.cookie
= name
+ "=" + escape(value
) +
373 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
374 ((path
) ? "; path=" + path
: "") +
375 ((domain
) ? "; domain=" + domain
: "") +
376 ((secure
) ? "; secure" : "");
379 function delCookie(name
, path
, domain
) {
380 if (getCookie(name
)) {
381 document
.cookie
= name
+ "=" +
382 ((path
) ? ";path=" + path
: "") +
383 ((domain
) ? ";domain=" + domain
: "" ) +
384 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
389 function getCookie(name
) {
391 var dc
= document
.cookie
;
392 var prefix
= name
+ "=";
393 var begin
= dc
.indexOf("; " + prefix
);
395 begin
= dc
.indexOf(prefix
);
396 if (begin
!= 0) return null;
401 var end
= document
.cookie
.indexOf(";", begin
);
405 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
408 function disableContainerChildren(id
, disable
, doc
) {
410 if (!doc
) doc
= document
;
412 var container
= doc
.getElementById(id
);
415 //alert("disableContainerChildren: element " + id + " not found");
419 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
420 var child
= container
.childNodes
[i
];
423 child
.disabled
= disable
;
429 if (child
.className
&& child
.className
.match("button")) {
430 child
.className
= "disabledButton";
433 if (child
.className
&& child
.className
.match("disabledButton")) {
434 child
.className
= "button";
441 function gotoPreferences() {
442 document
.location
.href
= "prefs.php";
445 function gotoMain() {
446 document
.location
.href
= "tt-rss.php";
449 function gotoExportOpml() {
450 document
.location
.href
= "opml.php?op=Export";
453 function getActiveFeedId() {
454 // return getCookie("ttrss_vf_actfeed");
456 debug("gAFID: " + getMainContext().active_feed_id
);
457 return getMainContext().active_feed_id
;
459 exception_error("getActiveFeedId", e
);
463 function setActiveFeedId(id
) {
464 // return setCookie("ttrss_vf_actfeed", id);
466 getMainContext().active_feed_id
= id
;
468 exception_error("setActiveFeedId", e
);
472 function parse_counters(reply
, scheduled_call
) {
474 var f_document
= getFeedsContext().document
;
475 var title_obj
= getMainContext();
477 if (reply
.firstChild
&& reply
.firstChild
.firstChild
) {
478 debug("<b>wrong element passed to parse_counters, adjusting.</b>");
479 reply
= reply
.firstChild
;
482 debug("F_DOC: " + f_document
+ ", T_OBJ: " + title_obj
);
484 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
485 if (!reply
.childNodes
[l
] ||
486 typeof(reply
.childNodes
[l
].getAttribute
) == "undefined") {
487 // where did this come from?
491 var id
= reply
.childNodes
[l
].getAttribute("id");
492 var t
= reply
.childNodes
[l
].getAttribute("type");
493 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
494 var error
= reply
.childNodes
[l
].getAttribute("error");
495 var has_img
= reply
.childNodes
[l
].getAttribute("hi");
496 var updated
= reply
.childNodes
[l
].getAttribute("updated");
498 if (id
== "global-unread") {
499 title_obj
.global_unread
= ctr
;
500 title_obj
.updateTitle();
504 if (t
== "category") {
505 var catctr
= f_document
.getElementById("FCATCTR-" + id
);
507 catctr
.innerHTML
= "(" + ctr
+ " unread)";
512 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
513 var feedu
= f_document
.getElementById("FEEDU-" + id
);
514 var feedr
= f_document
.getElementById("FEEDR-" + id
);
515 var feed_img
= f_document
.getElementById("FIMG-" + id
);
516 var feedlink
= f_document
.getElementById("FEEDL-" + id
);
517 var feedupd
= f_document
.getElementById("FLUPD-" + id
);
519 if (updated
&& feedlink
) {
521 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
523 feedlink
.title
= "Updated: " + updated
;
527 if (updated
&& feedupd
) {
529 feedupd
.innerHTML
= updated
+ " (Error)";
531 feedupd
.innerHTML
= updated
;
535 if (feedctr
&& feedu
&& feedr
) {
537 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
538 var hf
= title_obj
.parent
.frames
["headlines-frame"];
539 hf
.location
.reload(true);
542 feedu
.innerHTML
= ctr
;
545 feedr
.className
= feedr
.className
.replace("feed", "error");
547 feedr
.className
= feedr
.className
.replace("error", "feed");
551 feedctr
.className
= "odd";
552 if (!feedr
.className
.match("Unread")) {
553 var is_selected
= feedr
.className
.match("Selected");
555 feedr
.className
= feedr
.className
.replace("Selected", "");
556 feedr
.className
= feedr
.className
.replace("Unread", "");
558 feedr
.className
= feedr
.className
+ "Unread";
561 feedr
.className
= feedr
.className
+ "Selected";
566 feedctr
.className
= "invisible";
567 feedr
.className
= feedr
.className
.replace("Unread", "");
572 exception_error("parse_counters", e
);
576 function all_counters_callback() {
577 if (xmlhttp_rpc
.readyState
== 4) {
579 if (!xmlhttp_rpc
.responseXML
|| !xmlhttp_rpc
.responseXML
.firstChild
) {
580 debug("[all_counters_callback] backend did not return valid XML");
584 debug("in all_counters_callback");
586 var reply
= xmlhttp_rpc
.responseXML
.firstChild
;
588 var counters
= reply
.firstChild
;
590 parse_counters(counters
);
592 var runtime
= counters
.nextSibling
;
595 getMainContext().parse_runtime_info(runtime
);
598 if (getInitParam("feeds_sort_by_unread") == 1) {
602 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
605 exception_error("all_counters_callback", e
);
610 function get_feed_entry_unread(doc
, elem
) {
612 var id
= elem
.id
.replace("FEEDR-", "");
619 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
625 function resort_category(doc
, node
) {
626 debug("resort_category: " + node
);
628 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
629 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
630 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
632 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
636 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
637 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
639 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
640 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
642 if (cur_val
> tmp_val
) {
643 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
644 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
645 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
646 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
655 function resort_feedlist() {
656 debug("resort_feedlist");
658 var fd
= getFeedsContext().document
;
660 if (fd
.getElementById("feedCatHolder")) {
662 var feeds
= fd
.getElementById("feedList");
663 var child
= feeds
.firstChild
;
667 if (child
.id
== "feedCatHolder") {
668 resort_category(fd
, child
.firstChild
);
671 child
= child
.nextSibling
;
675 resort_category(fd
, fd
.getElementById("feedList"));
679 function update_all_counters(feed
) {
680 if (xmlhttp_ready(xmlhttp_rpc
)) {
681 var query
= "backend.php?op=rpc&subop=getAllCounters";
684 query
= query
+ "&aid=" + feed
;
687 xmlhttp_rpc
.open("GET", query
, true);
688 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
689 xmlhttp_rpc
.send(null);
693 function popupHelp(tid
) {
694 var w
= window
.open("backend.php?op=help&tid=" + tid
,
696 "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
699 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
700 * * @author Sundar Dorai-Raj
701 * * Email: sdoraira@vt.edu
702 * * This program is free software; you can redistribute it and/or
703 * * modify it under the terms of the GNU General Public License
704 * * as published by the Free Software Foundation; either version 2
705 * * of the License, or (at your option) any later version,
706 * * provided that any use properly credits the author.
707 * * This program is distributed in the hope that it will be useful,
708 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
709 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
710 * * GNU General Public License for more details at http://www.gnu.org * * */
712 var numbers
=".0123456789";
713 function isNumeric(x
) {
714 // is x a String or a character?
716 // remove negative sign
718 for(j
=0;j
<x
.length
;j
++) {
719 // call isNumeric recursively for each character
720 number
=isNumeric(x
.substring(j
,j
+1));
721 if(!number
) return number
;
726 // if x is number return true
727 if(numbers
.indexOf(x
)>=0) return true;
733 function hideOrShowFeeds(doc
, hide
) {
735 var fd
= getFeedsContext().document
;
737 var list
= fd
.getElementById("feedList");
739 if (fd
.getElementById("feedCatHolder")) {
741 var feeds
= fd
.getElementById("feedList");
742 var child
= feeds
.firstChild
;
746 if (child
.id
== "feedCatHolder") {
747 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
750 child
= child
.nextSibling
;
754 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
758 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
760 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
764 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
765 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
766 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
768 var has_unread
= (node
.childNodes
[i
].className
!= "feed");
770 // debug(node.childNodes[i].id + " --> " + has_unread);
772 if (hide
&& !has_unread
) {
773 node
.childNodes
[i
].style
.display
= "none";
777 node
.childNodes
[i
].style
.display
= "list-item";
787 if (cat_unread
== 0) {
789 cat_node
.style
.display
= "none";
791 cat_node
.style
.display
= "list-item";
795 // debug("unread for category: " + cat_unread);
798 function selectTableRow(r
, do_select
) {
799 r
.className
= r
.className
.replace("Selected", "");
802 r
.className
= r
.className
+ "Selected";
806 function selectTableRowById(elem_id
, check_id
, do_select
) {
810 var row
= document
.getElementById(elem_id
);
813 selectTableRow(row
, do_select
);
816 var check
= document
.getElementById(check_id
);
819 check
.checked
= do_select
;
822 exception_error("selectTableRowById", e
);
826 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
827 classcheck
, reset_others
) {
829 var content
= document
.getElementById(content_id
);
832 alert("[selectTableRows] Element " + content_id
+ " not found.");
836 for (i
= 0; i
< content
.rows
.length
; i
++) {
837 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
839 if (content
.rows
[i
].id
.match(prefix
)) {
840 selectTableRow(content
.rows
[i
], do_select
);
842 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
843 var check
= document
.getElementById(check_prefix
+ row_id
);
846 check
.checked
= do_select
;
848 } else if (reset_others
) {
849 selectTableRow(content
.rows
[i
], false);
851 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
852 var check
= document
.getElementById(check_prefix
+ row_id
);
855 check
.checked
= false;
859 } else if (reset_others
) {
860 selectTableRow(content
.rows
[i
], false);
862 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
863 var check
= document
.getElementById(check_prefix
+ row_id
);
866 check
.checked
= false;
873 function getSelectedTableRowIds(content_id
, prefix
) {
875 var content
= document
.getElementById(content_id
);
878 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
882 var sel_rows
= new Array();
884 for (i
= 0; i
< content
.rows
.length
; i
++) {
885 if (content
.rows
[i
].id
.match(prefix
) &&
886 content
.rows
[i
].className
.match("Selected")) {
888 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
889 sel_rows
.push(row_id
);
897 function toggleSelectRowById(sender
, id
) {
898 var row
= document
.getElementById(id
);
900 if (sender
.checked
) {
901 if (!row
.className
.match("Selected")) {
902 row
.className
= row
.className
+ "Selected";
905 if (row
.className
.match("Selected")) {
906 row
.className
= row
.className
.replace("Selected", "");
911 function toggleSelectListRow(sender
) {
912 var parent_row
= sender
.parentNode
;
914 if (sender
.checked
) {
915 if (!parent_row
.className
.match("Selected")) {
916 parent_row
.className
= parent_row
.className
+ "Selected";
919 if (parent_row
.className
.match("Selected")) {
920 parent_row
.className
= parent_row
.className
.replace("Selected", "");
926 function toggleSelectRow(sender
) {
927 var parent_row
= sender
.parentNode
.parentNode
;
929 if (sender
.checked
) {
930 if (!parent_row
.className
.match("Selected")) {
931 parent_row
.className
= parent_row
.className
+ "Selected";
934 if (parent_row
.className
.match("Selected")) {
935 parent_row
.className
= parent_row
.className
.replace("Selected", "");
940 function openExternalUrl(url
) {
941 var w
= window
.open(url
);
944 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
946 if (direction
== "next") {
947 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
948 var child
= list
.childNodes
[i
];
949 if (child
.id
&& child
.id
== "feedCatHolder") {
950 if (child
.lastChild
) {
951 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
954 } else if (child
.id
&& child
.id
.match("FEEDR-")) {
955 return child
.id
.replace('FEEDR-', '');
960 // FIXME select last feed doesn't work when only unread feeds are visible
962 if (direction
== "prev") {
963 for (i
= list
.childNodes
.length
-1; i
>= 0; i
--) {
964 var child
= list
.childNodes
[i
];
965 if (child
.id
== "feedCatHolder") {
966 if (child
.firstChild
) {
967 var cr
= getRelativeFeedId(child
.firstChild
, id
, direction
);
970 } else if (child
.id
.match("FEEDR-")) {
972 if (getInitParam("hide_read_feeds") == 1) {
973 if (child
.className
!= "feed") {
974 alert(child
.className
);
975 return child
.id
.replace('FEEDR-', '');
978 return child
.id
.replace('FEEDR-', '');
985 var feed
= list
.ownerDocument
.getElementById("FEEDR-" + getActiveFeedId());
987 if (getInitParam("hide_read_feeds") == 1) {
991 if (direction
== "next") {
1001 } else if (e
.parentNode
.parentNode
.nextSibling
) {
1003 var this_cat
= e
.parentNode
.parentNode
;
1007 if (this_cat
&& this_cat
.nextSibling
) {
1008 while (!e
&& this_cat
.nextSibling
) {
1009 this_cat
= this_cat
.nextSibling
;
1010 if (this_cat
.id
== "feedCatHolder") {
1011 e
= this_cat
.firstChild
.firstChild
;
1021 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1022 e
.className
!= "error")) {
1023 return e
.id
.replace("FEEDR-", "");
1028 } else if (direction
== "prev") {
1034 if (e
.previousSibling
) {
1036 e
= e
.previousSibling
;
1038 } else if (e
.parentNode
.parentNode
.previousSibling
) {
1040 var this_cat
= e
.parentNode
.parentNode
;
1044 if (this_cat
&& this_cat
.previousSibling
) {
1045 while (!e
&& this_cat
.previousSibling
) {
1046 this_cat
= this_cat
.previousSibling
;
1047 if (this_cat
.id
== "feedCatHolder") {
1048 e
= this_cat
.firstChild
.lastChild
;
1058 if (!unread_only
|| (unread_only
&& e
.className
!= "feed" &&
1059 e
.className
!= "error")) {
1060 return e
.id
.replace("FEEDR-", "");
1068 function showBlockElement(id
) {
1069 var elem
= document
.getElementById(id
);
1072 elem
.style
.display
= "block";
1074 alert("[showBlockElement] can't find element with id " + id
);
1078 function hideParentElement(e
) {
1079 e
.parentNode
.style
.display
= "none";
1082 function dropboxSelect(e
, v
) {
1083 for (i
= 0; i
< e
.length
; i
++) {
1084 if (e
[i
].value
== v
) {
1085 e
.selectedIndex
= i
;
1091 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1092 // bugfixed just a little bit :-)
1093 function getURLParam(strParamName
){
1095 var strHref
= window
.location
.href
;
1097 if (strHref
.indexOf("#") == strHref
.length
-1) {
1098 strHref
= strHref
.substring(0, strHref
.length
-1);
1101 if ( strHref
.indexOf("?") > -1 ){
1102 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1103 var aQueryString
= strQueryString
.split("&");
1104 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1105 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1106 var aParam
= aQueryString
[iParam
].split("=");
1107 strReturn
= aParam
[1];
1115 function leading_zero(p
) {
1117 if (s
.length
== 1) s
= "0" + s
;
1121 function closeInfoBox(cleanup
) {
1122 var box
= document
.getElementById('infoBox');
1123 var shadow
= document
.getElementById('infoBoxShadow');
1126 shadow
.style
.display
= "none";
1128 box
.style
.display
= "none";
1131 if (cleanup
) box
.innerHTML
= " ";
1138 function displayDlg(id
, param
) {
1140 if (!xmlhttp_ready(xmlhttp
)) {
1141 printLockingError();
1147 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
1148 param_escape(id
) + "¶m=" + param_escape(param
), true);
1149 xmlhttp
.onreadystatechange
=infobox_callback
;
1156 function infobox_submit_callback() {
1157 if (xmlhttp
.readyState
== 4) {
1160 // called from prefs, reload tab
1162 selectTab(active_tab
, false);
1165 notify(xmlhttp
.responseText
);
1170 function infobox_callback() {
1171 if (xmlhttp
.readyState
== 4) {
1172 var box
= document
.getElementById('infoBox');
1173 var shadow
= document
.getElementById('infoBoxShadow');
1175 box
.innerHTML
=xmlhttp
.responseText
;
1177 shadow
.style
.display
= "block";
1179 box
.style
.display
= "block";
1185 function qaddFilter() {
1187 if (!xmlhttp_ready(xmlhttp
)) {
1188 printLockingError();
1192 var query
= Form
.serialize("filter_add_form");
1194 xmlhttp
.open("GET", "backend.php?" + query
, true);
1195 xmlhttp
.onreadystatechange
=infobox_submit_callback
;
1201 function toggleSubmitNotEmpty(e
, submit_id
) {
1203 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1205 exception_error("toggleSubmitNotEmpty", e
);
1209 function isValidURL(s
) {
1210 return s
.match("http://") != null || s
.match("https://") != null;
1215 if (!xmlhttp_ready(xmlhttp
)) {
1216 printLockingError();
1220 notify("Adding feed...");
1224 var feeds_doc
= getFeedsContext().document
;
1226 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
1228 var query
= Form
.serialize("feed_add_form");
1230 xmlhttp
.open("GET", "backend.php?" + query
, true);
1231 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
1235 function filterCR(e
)
1240 key
= window
.event
.keyCode
; //IE
1242 key
= e
.which
; //firefox
1250 function getMainContext() {
1251 if (parent
.window
!= window
) {
1252 return parent
.window
;
1258 function getFeedsContext() {
1260 return getMainContext().frames
["feeds-frame"];
1262 exception_error("getFeedsContext", e
);
1267 function getHeadlinesContext() {
1269 return getMainContext().frames
["headlines-frame"];
1271 exception_error("getHeadlinesContext", e
);
1275 var debug_last_class
= "even";
1277 function debug(msg
) {
1278 var ctx
= getMainContext();
1280 if (ctx
.debug_last_class
== "even") {
1281 ctx
.debug_last_class
= "odd";
1283 ctx
.debug_last_class
= "even";
1286 var c
= ctx
.document
.getElementById('debug_output');
1287 if (c
&& c
.style
.display
== "block") {
1288 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1289 c
.removeChild(c
.lastChild
);
1293 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1294 ":" + leading_zero(d
.getSeconds());
1295 c
.innerHTML
= "<li class=\"" + ctx
.debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1296 msg
+ "</li>" + c
.innerHTML
;
1300 function getInitParam(key
) {
1301 return getMainContext().init_params
[key
];
1304 function storeInitParam(key
, value
, is_client
) {
1307 if (getMainContext().init_params
[key
] != value
) {
1308 debug("storeInitParam: " + key
+ " => " + value
);
1309 new Ajax
.Request("backend.php?op=rpc&subop=storeParam&key=" +
1310 param_escape(key
) + "&value=" + param_escape(value
));
1313 getMainContext().init_params
[key
] = value
;
1315 exception_error("storeInitParam", e
);
1320 function storeInitParams(params, is_client) {
1325 if (getMainContext().init_params[k] != params[k]) {
1326 s += k + "=" + params[k] + ";";
1327 getMainContext().init_params[k] = params[k];
1331 debug("storeInitParams: " + s);
1334 new Ajax.Request("backend.php?op=rpc&subop=storeParams&str=" + s);
1337 exception_error("storeInitParams", e);
1341 function fatalError(code
, message
) {
1343 var fe
= document
.getElementById("fatal_error");
1344 var fc
= document
.getElementById("fatal_error_msg");
1346 fc
.innerHTML
= "Code " + code
+ ": " + message
;
1348 fe
.style
.display
= "block";
1351 exception_error("fatalError", e
);
1355 function getFeedName(id
) {
1356 var d
= getFeedsContext().document
;
1357 var e
= d
.getElementById("FEEDN-" + id
);
1359 return e
.innerHTML
.stripTags();