]>
git.wh0rd.org - tt-rss.git/blob - functions.js
276911598f7ab423cb2578a863d3a5ed108e0dc0
1 var hotkeys_enabled
= true;
2 var debug_mode_enabled
= false;
3 var xmlhttp_rpc
= Ajax
.getTransport();
5 /* add method to remove element from array */
7 Array
.prototype.remove = function(s
) {
8 for (var i
=0; i
< this.length
; i
++) {
9 if (s
== this[i
]) this.splice(i
, 1);
13 function browser_has_opacity() {
14 return navigator
.userAgent
.match("Gecko") != null ||
15 navigator
.userAgent
.match("Opera") != null;
19 return navigator
.userAgent
.match("MSIE");
23 return navigator
.userAgent
.match("Opera");
27 return navigator
.userAgent
.match("KHTML");
30 function is_safari() {
31 return navigator
.userAgent
.match("Safari");
34 function exception_error(location
, e
, silent
) {
38 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
40 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
41 "\nFunction: " + location
+ "()" +
42 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
45 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
48 debug("<b>EXCEPTION: " + msg
+ "</b>");
55 function disableHotkeys() {
56 hotkeys_enabled
= false;
59 function enableHotkeys() {
60 hotkeys_enabled
= true;
63 function xmlhttp_ready(obj
) {
64 return obj
.readyState
== 4 || obj
.readyState
== 0 || !obj
.readyState
;
67 function open_article_callback(transport
) {
70 if (transport
.responseXML
) {
71 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
72 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
75 window
.open(link
.firstChild
.nodeValue
, "_blank");
78 id
= id
.firstChild
.nodeValue
;
79 if (!document
.getElementById("headlinesList")) {
80 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
87 exception_error("open_article_callback", e
);
91 function param_escape(arg
) {
92 if (typeof encodeURIComponent
!= 'undefined')
93 return encodeURIComponent(arg
);
98 function param_unescape(arg
) {
99 if (typeof decodeURIComponent
!= 'undefined')
100 return decodeURIComponent(arg
);
102 return unescape(arg
);
105 function delay(gap
) {
107 then
=new Date().getTime();
109 while((now
-then
)<gap
) {
110 now
=new Date().getTime();
114 var notify_hide_timerid
= false;
116 function hide_notify() {
117 var n
= document
.getElementById("notify");
119 n
.style
.display
= "none";
123 function notify_real(msg
, no_hide
, n_type
) {
125 var n
= document
.getElementById("notify");
126 var nb
= document
.getElementById("notify_body");
128 if (!n
|| !nb
) return;
130 if (notify_hide_timerid
) {
131 window
.clearTimeout(notify_hide_timerid
);
135 if (n
.style
.display
== "block") {
136 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
140 n
.style
.display
= "block";
152 if (typeof __
!= 'undefined') {
157 n
.className
= "notify";
158 } else if (n_type
== 2) {
159 n
.className
= "notifyProgress";
160 msg
= "<img src='images/indicator_white.gif'> " + msg
;
161 } else if (n_type
== 3) {
162 n
.className
= "notifyError";
163 msg
= "<img src='images/sign_excl.gif'> " + msg
;
164 } else if (n_type
== 4) {
165 n
.className
= "notifyInfo";
166 msg
= "<img src='images/sign_info.gif'> " + msg
;
169 // msg = "<img src='images/live_com_loading.gif'> " + msg;
174 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
178 function notify(msg
, no_hide
) {
179 notify_real(msg
, no_hide
, 1);
182 function notify_progress(msg
, no_hide
) {
183 notify_real(msg
, no_hide
, 2);
186 function notify_error(msg
, no_hide
) {
187 notify_real(msg
, no_hide
, 3);
191 function notify_info(msg
, no_hide
) {
192 notify_real(msg
, no_hide
, 4);
195 function printLockingError() {
196 notify_info("Please wait until operation finishes.");
199 function hotkey_handler(e
) {
204 var shift_key
= false;
207 shift_key
= e
.shiftKey
;
212 if (!hotkeys_enabled
) return;
215 keycode
= window
.event
.keyCode
;
220 if (keycode
== 82) { // r
221 return scheduleFeedUpdate(true);
224 if (keycode
== 83) { // s
225 return displayDlg("search", getActiveFeedId());
228 if (keycode
== 85) { // u
229 if (getActiveFeedId()) {
230 return viewfeed(getActiveFeedId(), "ForceUpdate");
234 if (keycode
== 65) { // a
235 return toggleDispRead();
238 var feedlist
= document
.getElementById('feedList');
240 if (keycode
== 74) { // j
241 var feed
= getActiveFeedId();
242 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
243 if (new_feed
) viewfeed(new_feed
, '');
246 if (keycode
== 75) { // k
247 var feed
= getActiveFeedId();
248 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
249 if (new_feed
) viewfeed(new_feed
, '');
252 if (keycode
== 78 || keycode
== 40) { // n, down
253 if (typeof moveToPost
!= 'undefined') {
254 return moveToPost('next');
258 if (keycode
== 80 || keycode
== 38) { // p, up
259 if (typeof moveToPost
!= 'undefined') {
260 return moveToPost('prev');
264 if (keycode
== 68 && shift_key
) { // d
265 if (!debug_mode_enabled
) {
266 document
.getElementById('debug_output').style
.display
= 'block';
267 debug('debug mode activated');
269 document
.getElementById('debug_output').style
.display
= 'none';
272 debug_mode_enabled
= !debug_mode_enabled
;
275 if (keycode
== 190 && shift_key
) { // >
279 if (keycode
== 188 && shift_key
) { // <
283 if (keycode
== 191 && shift_key
) { // ?
287 if (keycode
== 69 && shift_key
) { // e
288 return editFeedDlg(getActiveFeedId());
291 if (keycode
== 70 && shift_key
) { // f
292 if (getActiveFeedId()) {
293 return catchupCurrentFeed();
297 if (keycode
== 80 && shift_key
) { // p
298 if (getActiveFeedId()) {
299 return catchupPage();
303 if (keycode
== 86) { // v
304 if (getActiveArticleId()) {
305 openArticleInNewWindow(getActiveArticleId());
309 if (keycode
== 84) { // t
311 var id
= getActiveArticleId();
315 var cb
= document
.getElementById("RCHK-" + id
);
318 cb
.checked
= !cb
.checked
;
319 toggleSelectRowById(cb
, "RROW-" + id
);
324 if (keycode
== 67) { // c
325 var id
= getActiveArticleId();
332 if (typeof localHotkeyHandler
!= 'undefined') {
334 return localHotkeyHandler(e
);
336 exception_error("hotkey_handler, local:", e
);
340 debug("KP=" + keycode
);
342 exception_error("hotkey_handler", e
);
346 function cleanSelectedList(element
) {
347 var content
= document
.getElementById(element
);
349 if (!document
.getElementById("feedCatHolder")) {
350 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
351 var child
= content
.childNodes
[i
];
353 child
.className
= child
.className
.replace("Selected", "");
359 for (i
= 0; i
< content
.childNodes
.length
; i
++) {
360 var child
= content
.childNodes
[i
];
361 if (child
.id
== "feedCatHolder") {
363 var fcat
= child
.lastChild
;
364 for (j
= 0; j
< fcat
.childNodes
.length
; j
++) {
365 var feed
= fcat
.childNodes
[j
];
366 feed
.className
= feed
.className
.replace("Selected", "");
374 function cleanSelected(element
) {
375 var content
= document
.getElementById(element
);
377 for (i
= 0; i
< content
.rows
.length
; i
++) {
378 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
382 function getVisibleUnreadHeadlines() {
383 var content
= document
.getElementById("headlinesList");
385 var rows
= new Array();
387 for (i
= 0; i
< content
.rows
.length
; i
++) {
388 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
389 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
396 function getVisibleHeadlineIds() {
398 var content
= document
.getElementById("headlinesList");
400 var rows
= new Array();
402 for (i
= 0; i
< content
.rows
.length
; i
++) {
403 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
404 if (row_id
.length
> 0) {
411 function getFirstVisibleHeadlineId() {
412 var rows
= getVisibleHeadlineIds();
416 function getLastVisibleHeadlineId() {
417 var rows
= getVisibleHeadlineIds();
418 return rows
[rows
.length
-1];
421 function markHeadline(id
) {
422 var row
= document
.getElementById("RROW-" + id
);
424 var is_active
= false;
426 if (row
.className
.match("Active")) {
429 row
.className
= row
.className
.replace("Selected", "");
430 row
.className
= row
.className
.replace("Active", "");
431 row
.className
= row
.className
.replace("Insensitive", "");
434 row
.className
= row
.className
= "Active";
437 var check
= document
.getElementById("RCHK-" + id
);
440 check
.checked
= true;
443 row
.className
= row
.className
+ "Selected";
448 function getFeedIds() {
449 var content
= document
.getElementById("feedsList");
451 var rows
= new Array();
453 for (i
= 0; i
< content
.rows
.length
; i
++) {
454 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
463 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
469 d
.setTime(d
.getTime() + (lifetime
* 1000));
472 debug("setCookie: " + name
+ " => " + value
+ ": " + d
);
474 int_setCookie(name
, value
, d
, path
, domain
, secure
);
478 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
479 document
.cookie
= name
+ "=" + escape(value
) +
480 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
481 ((path
) ? "; path=" + path
: "") +
482 ((domain
) ? "; domain=" + domain
: "") +
483 ((secure
) ? "; secure" : "");
486 function delCookie(name
, path
, domain
) {
487 if (getCookie(name
)) {
488 document
.cookie
= name
+ "=" +
489 ((path
) ? ";path=" + path
: "") +
490 ((domain
) ? ";domain=" + domain
: "" ) +
491 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
496 function getCookie(name
) {
498 var dc
= document
.cookie
;
499 var prefix
= name
+ "=";
500 var begin
= dc
.indexOf("; " + prefix
);
502 begin
= dc
.indexOf(prefix
);
503 if (begin
!= 0) return null;
508 var end
= document
.cookie
.indexOf(";", begin
);
512 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
515 function disableContainerChildren(id
, disable
, doc
) {
517 if (!doc
) doc
= document
;
519 var container
= doc
.getElementById(id
);
522 //alert("disableContainerChildren: element " + id + " not found");
526 for (var i
= 0; i
< container
.childNodes
.length
; i
++) {
527 var child
= container
.childNodes
[i
];
530 child
.disabled
= disable
;
536 if (child
.className
&& child
.className
.match("button")) {
537 child
.className
= "disabledButton";
540 if (child
.className
&& child
.className
.match("disabledButton")) {
541 child
.className
= "button";
548 function gotoPreferences() {
549 document
.location
.href
= "prefs.php";
552 function gotoMain() {
553 document
.location
.href
= "tt-rss.php";
556 function gotoExportOpml() {
557 document
.location
.href
= "opml.php?op=Export";
560 function getActiveFeedId() {
561 // return getCookie("ttrss_vf_actfeed");
563 debug("gAFID: " + active_feed_id
);
564 return active_feed_id
;
566 exception_error("getActiveFeedId", e
);
570 function activeFeedIsCat() {
571 return active_feed_is_cat
;
574 function setActiveFeedId(id
) {
575 // return setCookie("ttrss_vf_actfeed", id);
577 debug("sAFID(" + id
+ ")");
580 exception_error("setActiveFeedId", e
);
584 function parse_counters(reply
, scheduled_call
) {
589 var elems
= reply
.getElementsByTagName("counter");
591 for (var l
= 0; l
< elems
.length
; l
++) {
593 var id
= elems
[l
].getAttribute("id");
594 var t
= elems
[l
].getAttribute("type");
595 var ctr
= elems
[l
].getAttribute("counter");
596 var error
= elems
[l
].getAttribute("error");
597 var has_img
= elems
[l
].getAttribute("hi");
598 var updated
= elems
[l
].getAttribute("updated");
599 var title
= elems
[l
].getAttribute("title");
601 if (id
== "global-unread") {
607 if (id
== "subscribed-feeds") {
612 if (t
== "category") {
613 var catctr
= document
.getElementById("FCATCTR-" + id
);
615 catctr
.innerHTML
= "(" + ctr
+ ")";
617 catctr
.className
= "catCtrHasUnread";
619 catctr
.className
= "catCtrNoUnread";
625 var feedctr
= document
.getElementById("FEEDCTR-" + id
);
626 var feedu
= document
.getElementById("FEEDU-" + id
);
627 var feedr
= document
.getElementById("FEEDR-" + id
);
628 var feed_img
= document
.getElementById("FIMG-" + id
);
629 var feedlink
= document
.getElementById("FEEDL-" + id
);
630 var feedupd
= document
.getElementById("FLUPD-" + id
);
632 if (updated
&& feedlink
) {
634 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
636 feedlink
.title
= "Updated: " + updated
;
640 if (updated
&& feedupd
) {
642 feedupd
.innerHTML
= updated
+ " (Error)";
644 feedupd
.innerHTML
= updated
;
648 if (has_img
&& feed_img
&& !is_msie()) {
649 if (!feed_img
.src
.match(id
+ ".ico")) {
650 feed_img
.src
= getInitParam("icons_location") + "/" + id
+ ".ico";
654 if (feedlink
&& title
) {
655 feedlink
.innerHTML
= title
;
658 if (feedctr
&& feedu
&& feedr
) {
660 if (feedu
.innerHTML
!= ctr
&& id
== getActiveFeedId() && scheduled_call
) {
664 var row_needs_hl
= (ctr
> 0 && ctr
> parseInt(feedu
.innerHTML
));
666 feedu
.innerHTML
= ctr
;
669 feedr
.className
= feedr
.className
.replace("feed", "error");
671 feedr
.className
= feedr
.className
.replace("error", "feed");
675 feedctr
.className
= "odd";
676 if (!feedr
.className
.match("Unread")) {
677 var is_selected
= feedr
.className
.match("Selected");
679 feedr
.className
= feedr
.className
.replace("Selected", "");
680 feedr
.className
= feedr
.className
.replace("Unread", "");
682 feedr
.className
= feedr
.className
+ "Unread";
685 feedr
.className
= feedr
.className
+ "Selected";
691 new Effect
.Highlight(feedr
, {duration
: 1, startcolor
: "#fff7d5",
692 queue
: { position
:'end', scope
: 'EFQ-' + id
, limit
: 1 } } );
695 feedctr
.className
= "invisible";
696 feedr
.className
= feedr
.className
.replace("Unread", "");
701 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
703 var feeds_stored
= number_of_feeds
;
705 debug("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
707 if (feeds_stored
!= feeds_found
) {
708 number_of_feeds
= feeds_found
;
710 if (feeds_stored
!= 0 && feeds_found
!= 0) {
711 debug("Subscribed feed number changed, refreshing feedlist");
712 setTimeout('updateFeedList(false, false)', 50);
717 exception_error("parse_counters", e
);
721 function parse_counters_reply(transport
, scheduled_call
) {
723 if (!transport
.responseXML
) {
724 notify_error("Backend did not return valid XML", true);
728 var reply
= transport
.responseXML
.firstChild
;
731 notify_error("Backend did not return expected XML object", true);
736 var error_code
= false;
737 var error_msg
= false;
739 if (reply
.firstChild
) {
740 error_code
= reply
.firstChild
.getAttribute("error-code");
741 error_msg
= reply
.firstChild
.getAttribute("error-msg");
745 error_code
= reply
.getAttribute("error-code");
746 error_msg
= reply
.getAttribute("error-msg");
749 if (error_code
&& error_code
!= 0) {
750 debug("refetch_callback: got error code " + error_code
);
751 return fatalError(error_code
, error_msg
);
754 var counters
= reply
.getElementsByTagName("counters")[0];
756 parse_counters(counters
, scheduled_call
);
758 var runtime_info
= reply
.getElementsByTagName("runtime-info")[0];
760 parse_runtime_info(runtime_info
);
762 if (getInitParam("feeds_sort_by_unread") == 1) {
766 hideOrShowFeeds(document
, getInitParam("hide_read_feeds") == 1);
770 function all_counters_callback2(transport
) {
772 debug("<b>all_counters_callback2 IN: " + transport
+ "</b>");
773 parse_counters_reply(transport
);
774 debug("<b>all_counters_callback2 OUT: " + transport
+ "</b>");
777 exception_error("all_counters_callback2", e
);
781 function get_feed_entry_unread(doc
, elem
) {
783 var id
= elem
.id
.replace("FEEDR-", "");
790 return parseInt(doc
.getElementById("FEEDU-" + id
).innerHTML
);
796 function resort_category(doc
, node
) {
797 debug("resort_category: " + node
);
799 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
800 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
801 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
803 if (get_feed_entry_unread(doc
, node
.childNodes
[i
]) < 0) {
807 for (j
= i
+1; j
< node
.childNodes
.length
; j
++) {
808 if (node
.childNodes
[j
].nodeName
!= "LI") { continue; }
810 var tmp_val
= get_feed_entry_unread(doc
, node
.childNodes
[i
]);
811 var cur_val
= get_feed_entry_unread(doc
, node
.childNodes
[j
]);
813 if (cur_val
> tmp_val
) {
814 tempnode_i
= node
.childNodes
[i
].cloneNode(true);
815 tempnode_j
= node
.childNodes
[j
].cloneNode(true);
816 node
.replaceChild(tempnode_i
, node
.childNodes
[j
]);
817 node
.replaceChild(tempnode_j
, node
.childNodes
[i
]);
826 function resort_feedlist() {
827 debug("resort_feedlist");
831 if (fd
.getElementById("feedCatHolder")) {
833 var feeds
= fd
.getElementById("feedList");
834 var child
= feeds
.firstChild
;
838 if (child
.id
== "feedCatHolder") {
839 resort_category(fd
, child
.firstChild
);
842 child
= child
.nextSibling
;
846 resort_category(fd
, fd
.getElementById("feedList"));
850 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
851 * * @author Sundar Dorai-Raj
852 * * Email: sdoraira@vt.edu
853 * * This program is free software; you can redistribute it and/or
854 * * modify it under the terms of the GNU General Public License
855 * * as published by the Free Software Foundation; either version 2
856 * * of the License, or (at your option) any later version,
857 * * provided that any use properly credits the author.
858 * * This program is distributed in the hope that it will be useful,
859 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
860 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
861 * * GNU General Public License for more details at http://www.gnu.org * * */
863 var numbers
=".0123456789";
864 function isNumeric(x
) {
865 // is x a String or a character?
867 // remove negative sign
869 for(j
=0;j
<x
.length
;j
++) {
870 // call isNumeric recursively for each character
871 number
=isNumeric(x
.substring(j
,j
+1));
872 if(!number
) return number
;
877 // if x is number return true
878 if(numbers
.indexOf(x
)>=0) return true;
884 function hideOrShowFeeds(doc
, hide
) {
886 debug("hideOrShowFeeds: " + doc
+ ", " + hide
);
890 var list
= fd
.getElementById("feedList");
892 if (fd
.getElementById("feedCatHolder")) {
894 var feeds
= fd
.getElementById("feedList");
895 var child
= feeds
.firstChild
;
899 if (child
.id
== "feedCatHolder") {
900 hideOrShowFeedsCategory(fd
, child
.firstChild
, hide
, child
.previousSibling
);
903 child
= child
.nextSibling
;
907 hideOrShowFeedsCategory(fd
, fd
.getElementById("feedList"), hide
);
911 function hideOrShowFeedsCategory(doc
, node
, hide
, cat_node
) {
913 // debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
918 debug("hideOrShowFeeds: passed node is null, aborting");
922 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
923 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
924 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
926 if (node
.childNodes
[i
].style
!= undefined) {
928 var has_unread
= (node
.childNodes
[i
].className
!= "feed" &&
929 node
.childNodes
[i
].className
!= "label" &&
930 node
.childNodes
[i
].className
!= "virt" &&
931 node
.childNodes
[i
].className
!= "tag");
933 // debug(node.childNodes[i].id + " --> " + has_unread);
935 if (hide
&& !has_unread
) {
936 //node.childNodes[i].style.display = "none";
937 Effect
.Fade(node
.childNodes
[i
], {duration
: 0.3});
941 node
.childNodes
[i
].style
.display
= "list-item";
942 //Effect.Appear(node.childNodes[i], {duration : 0.3});
946 node
.childNodes
[i
].style
.display
= "list-item";
948 //Effect.Appear(node.childNodes[i], {duration : 0.3});
949 //Effect.Highlight(node.childNodes[i]);
955 if (cat_unread
== 0) {
956 if (cat_node
.style
== undefined) {
957 debug("ERROR: supplied cat_node " + cat_node
+
958 " has no styles. WTF?");
962 //cat_node.style.display = "none";
963 Effect
.Fade(cat_node
, {duration
: 0.3});
965 cat_node
.style
.display
= "list-item";
969 cat_node
.style
.display
= "list-item";
975 // debug("unread for category: " + cat_unread);
978 function selectTableRow(r
, do_select
) {
979 r
.className
= r
.className
.replace("Selected", "");
982 r
.className
= r
.className
+ "Selected";
986 function selectTableRowById(elem_id
, check_id
, do_select
) {
990 var row
= document
.getElementById(elem_id
);
993 selectTableRow(row
, do_select
);
996 var check
= document
.getElementById(check_id
);
999 check
.checked
= do_select
;
1002 exception_error("selectTableRowById", e
);
1006 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
1007 classcheck
, reset_others
) {
1009 var content
= document
.getElementById(content_id
);
1012 alert("[selectTableRows] Element " + content_id
+ " not found.");
1016 for (i
= 0; i
< content
.rows
.length
; i
++) {
1017 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
1019 if (content
.rows
[i
].id
.match(prefix
)) {
1020 selectTableRow(content
.rows
[i
], do_select
);
1022 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1023 var check
= document
.getElementById(check_prefix
+ row_id
);
1026 check
.checked
= do_select
;
1028 } else if (reset_others
) {
1029 selectTableRow(content
.rows
[i
], false);
1031 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1032 var check
= document
.getElementById(check_prefix
+ row_id
);
1035 check
.checked
= false;
1039 } else if (reset_others
) {
1040 selectTableRow(content
.rows
[i
], false);
1042 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
1043 var check
= document
.getElementById(check_prefix
+ row_id
);
1046 check
.checked
= false;
1053 function getSelectedTableRowIds(content_id
, prefix
) {
1055 var content
= document
.getElementById(content_id
);
1058 alert("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
1062 var sel_rows
= new Array();
1064 for (i
= 0; i
< content
.rows
.length
; i
++) {
1065 if (content
.rows
[i
].id
.match(prefix
) &&
1066 content
.rows
[i
].className
.match("Selected")) {
1068 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
1069 sel_rows
.push(row_id
);
1077 function toggleSelectRowById(sender
, id
) {
1078 var row
= document
.getElementById(id
);
1080 if (sender
.checked
) {
1081 if (!row
.className
.match("Selected")) {
1082 row
.className
= row
.className
+ "Selected";
1085 if (row
.className
.match("Selected")) {
1086 row
.className
= row
.className
.replace("Selected", "");
1091 function toggleSelectListRow(sender
) {
1092 var parent_row
= sender
.parentNode
;
1094 if (sender
.checked
) {
1095 if (!parent_row
.className
.match("Selected")) {
1096 parent_row
.className
= parent_row
.className
+ "Selected";
1099 if (parent_row
.className
.match("Selected")) {
1100 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1105 function tSR(sender
) {
1106 return toggleSelectRow(sender
);
1109 function toggleSelectRow(sender
) {
1110 var parent_row
= sender
.parentNode
.parentNode
;
1112 if (sender
.checked
) {
1113 if (!parent_row
.className
.match("Selected")) {
1114 parent_row
.className
= parent_row
.className
+ "Selected";
1117 if (parent_row
.className
.match("Selected")) {
1118 parent_row
.className
= parent_row
.className
.replace("Selected", "");
1123 function getRelativeFeedId(list
, id
, direction
, unread_only
) {
1124 var rows
= list
.getElementsByTagName("LI");
1125 var feeds
= new Array();
1127 for (var i
= 0; i
< rows
.length
; i
++) {
1128 if (rows
[i
].id
.match("FEEDR-")) {
1130 if (rows
[i
].id
== "FEEDR-" + id
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1133 (rows
[i
].className
.match("Unread") || rows
[i
].id
== "FEEDR-" + id
)) {
1134 feeds
.push(rows
[i
].id
.replace("FEEDR-", ""));
1141 if (direction
== "next") {
1142 return feeds
.shift();
1147 if (direction
== "next") {
1148 var idx
= feeds
.indexOf(id
);
1149 if (idx
!= -1 && idx
< feeds
.length
) {
1150 return feeds
[idx
+1];
1152 return getRelativeFeedId(list
, false, direction
, unread_only
);
1155 var idx
= feeds
.indexOf(id
);
1157 return feeds
[idx
-1];
1159 return getRelativeFeedId(list
, false, direction
, unread_only
);
1166 function showBlockElement(id
, h_id
) {
1167 var elem
= document
.getElementById(id
);
1170 elem
.style
.display
= "block";
1173 elem
= document
.getElementById(h_id
);
1175 elem
.style
.display
= "none";
1179 alert("[showBlockElement] can't find element with id " + id
);
1183 function appearBlockElement_afh(effect
) {
1187 function checkboxToggleElement(elem
, id
) {
1189 Effect
.SlideDown(id
, {duration
: 0.5});
1191 Effect
.SlideUp(id
, {duration
: 0.5});
1195 function appearBlockElement(id
, h_id
) {
1199 Effect
.SlideDown(id
, {duration
: 1.0, afterFinish
: appearBlockElement_afh
});
1201 exception_error("appearBlockElement", e
);
1207 function hideParentElement(e
) {
1208 e
.parentNode
.style
.display
= "none";
1211 function dropboxSelect(e
, v
) {
1212 for (i
= 0; i
< e
.length
; i
++) {
1213 if (e
[i
].value
== v
) {
1214 e
.selectedIndex
= i
;
1220 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1221 // bugfixed just a little bit :-)
1222 function getURLParam(strParamName
){
1224 var strHref
= window
.location
.href
;
1226 if (strHref
.indexOf("#") == strHref
.length
-1) {
1227 strHref
= strHref
.substring(0, strHref
.length
-1);
1230 if ( strHref
.indexOf("?") > -1 ){
1231 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1232 var aQueryString
= strQueryString
.split("&");
1233 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1234 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1235 var aParam
= aQueryString
[iParam
].split("=");
1236 strReturn
= aParam
[1];
1244 function leading_zero(p
) {
1246 if (s
.length
== 1) s
= "0" + s
;
1250 function closeInfoBox(cleanup
) {
1252 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1253 var overlay
= document
.getElementById("dialog_overlay");
1255 overlay
.style
.display
= "none";
1259 var box
= document
.getElementById('infoBox');
1260 var shadow
= document
.getElementById('infoBoxShadow');
1263 shadow
.style
.display
= "none";
1265 box
.style
.display
= "none";
1268 if (cleanup
) box
.innerHTML
= " ";
1276 function displayDlg(id
, param
) {
1278 notify_progress("Loading, please wait...", true);
1282 var query
= "backend.php?op=dlg&id=" +
1283 param_escape(id
) + "¶m=" + param_escape(param
);
1285 new Ajax
.Request(query
, {
1286 onComplete: function (transport
) {
1287 infobox_callback2(transport
);
1293 function infobox_submit_callback2(transport
) {
1297 // called from prefs, reload tab
1299 selectTab(active_tab
, false);
1303 if (transport
.responseText
) {
1304 notify_info(transport
.responseText
);
1308 function infobox_callback2(transport
) {
1311 debug("infobox_callback2");
1313 if (!is_msie() && !getInitParam("infobox_disable_overlay")) {
1314 var overlay
= document
.getElementById("dialog_overlay");
1316 overlay
.style
.display
= "block";
1320 var box
= document
.getElementById('infoBox');
1321 var shadow
= document
.getElementById('infoBoxShadow');
1324 /* if (!is_safari()) {
1325 new Draggable(shadow);
1328 box
.innerHTML
=transport
.responseText
;
1330 shadow
.style
.display
= "block";
1332 box
.style
.display
= "block";
1336 /* FIXME this needs to be moved out somewhere */
1338 if (document
.getElementById("tags_choices")) {
1339 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1340 "backend.php?op=rpc&subop=completeTags",
1341 { tokens
: ',', paramName
: "search" });
1346 exception_error("infobox_callback2", e
);
1350 function createFilter() {
1352 var form
= document
.forms
['filter_add_form'];
1353 var reg_exp
= form
.reg_exp
.value
;
1355 if (reg_exp
== "") {
1356 alert(__("Can't add filter: nothing to match on."));
1360 var query
= Form
.serialize("filter_add_form");
1362 new Ajax
.Request("backend.php?" + query
, {
1363 onComplete: function (transport
) {
1364 infobox_submit_callback2(transport
);
1370 function toggleSubmitNotEmpty(e
, submit_id
) {
1372 document
.getElementById(submit_id
).disabled
= (e
.value
== "")
1374 exception_error("toggleSubmitNotEmpty", e
);
1378 function isValidURL(s
) {
1379 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
1382 function subscribeToFeed() {
1384 var form
= document
.forms
['feed_add_form'];
1385 var feed_url
= form
.feed_url
.value
;
1387 if (feed_url
== "") {
1388 alert(__("Can't subscribe: no feed URL given."));
1392 notify_progress(__("Subscribing to feed..."), true);
1396 var feeds_doc
= document
;
1398 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
1400 var query
= Form
.serialize("feed_add_form");
1402 debug("subscribe q: " + query
);
1404 new Ajax
.Request("backend.php", {
1406 onComplete: function(transport
) {
1407 dlg_frefresh_callback(transport
);
1413 function filterCR(e
, f
)
1418 key
= window
.event
.keyCode
; //IE
1420 key
= e
.which
; //firefox
1423 if (typeof f
!= 'undefined') {
1434 function getMainContext() {
1438 function getFeedsContext() {
1442 function getContentContext() {
1446 function getHeadlinesContext() {
1450 var debug_last_class
= "even";
1452 function debug(msg
) {
1454 if (debug_last_class
== "even") {
1455 debug_last_class
= "odd";
1457 debug_last_class
= "even";
1460 var c
= document
.getElementById('debug_output');
1461 if (c
&& c
.style
.display
== "block") {
1462 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 100) {
1463 c
.removeChild(c
.lastChild
);
1467 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1468 ":" + leading_zero(d
.getSeconds());
1469 c
.innerHTML
= "<li class=\"" + debug_last_class
+ "\"><span class=\"debugTS\">[" + ts
+ "]</span> " +
1470 msg
+ "</li>" + c
.innerHTML
;
1474 function getInitParam(key
) {
1475 return init_params
[key
];
1478 function storeInitParam(key
, value
) {
1479 debug("<b>storeInitParam is OBSOLETE: " + key
+ " => " + value
+ "</b>");
1480 init_params
[key
] = value
;
1483 function fatalError(code
, message
) {
1487 window
.location
.href
= "tt-rss.php";
1488 } else if (code
== 5) {
1489 window
.location
.href
= "update.php";
1491 var fe
= document
.getElementById("fatal_error");
1492 var fc
= document
.getElementById("fatal_error_msg");
1494 if (message
== "") message
= "Unknown error";
1496 fc
.innerHTML
= "<img src='images/sign_excl.png'> " + message
+ " (Code " + code
+ ")";
1498 fe
.style
.display
= "block";
1502 exception_error("fatalError", e
);
1506 function getFeedName(id
, is_cat
) {
1507 var d
= getFeedsContext().document
;
1512 e
= d
.getElementById("FCATN-" + id
);
1514 e
= d
.getElementById("FEEDN-" + id
);
1517 return e
.innerHTML
.stripTags();
1523 function viewContentUrl(url
) {
1524 getContentContext().location
= url
;
1527 function filterDlgCheckAction(sender
) {
1531 var action
= sender
[sender
.selectedIndex
].value
;
1533 var form
= document
.forms
["filter_add_form"];
1536 form
= document
.forms
["filter_edit_form"];
1540 debug("filterDlgCheckAction: can't find form!");
1544 var action_param
= form
.action_param
;
1546 if (!action_param
) {
1547 debug("filterDlgCheckAction: can't find action param!");
1551 // if selected action supports parameters, enable params field
1553 action_param
.disabled
= false;
1555 action_param
.disabled
= true;
1559 exception_error(e
, "filterDlgCheckAction");
1564 function explainError(code
) {
1565 return displayDlg("explainError", code
);
1568 // this only searches loaded headlines list, not in CDM
1569 function getRelativePostIds(id
) {
1571 debug("getRelativePostIds: " + id
);
1573 var ids
= new Array();
1574 var container
= document
.getElementById("headlinesList");
1577 var rows
= container
.rows
;
1579 for (var i
= 0; i
< rows
.length
; i
++) {
1580 var r_id
= rows
[i
].id
.replace("RROW-", "");
1583 if (i
> 0) ids
.push(rows
[i
-1].id
.replace("RROW-", ""));
1584 if (i
> 1) ids
.push(rows
[i
-2].id
.replace("RROW-", ""));
1585 if (i
> 2) ids
.push(rows
[i
-3].id
.replace("RROW-", ""));
1587 if (i
< rows
.length
-1) ids
.push(rows
[i
+1].id
.replace("RROW-", ""));
1588 if (i
< rows
.length
-2) ids
.push(rows
[i
+2].id
.replace("RROW-", ""));
1589 if (i
< rows
.length
-3) ids
.push(rows
[i
+3].id
.replace("RROW-", ""));
1599 function openArticleInNewWindow(id
) {
1601 debug("openArticleInNewWindow: " + id
);
1603 var query
= "backend.php?op=rpc&subop=getArticleLink&id=" + id
;
1607 new Ajax
.Request(query
, {
1608 onComplete: function(transport
) {
1609 open_article_callback(transport
);
1614 exception_error("openArticleInNewWindow", e
);
1618 /* http://textsnippets.com/posts/show/835 */
1620 Position
.GetWindowSize = function(w
) {
1622 var width
= w
.innerWidth
|| (w
.document
.documentElement
.clientWidth
|| w
.document
.body
.clientWidth
);
1623 var height
= w
.innerHeight
|| (w
.document
.documentElement
.clientHeight
|| w
.document
.body
.clientHeight
);
1624 return [width
, height
]
1627 /* http://textsnippets.com/posts/show/836 */
1629 Position
.Center = function(element
, parent
) {
1631 var d
= Element
.getDimensions(element
);
1636 var ws
= Position
.GetWindowSize();
1640 pw
= parent
.offsetWidth
;
1641 ph
= parent
.offsetHeight
;
1643 element
.style
.top
= (ph
/2) - (h/2) - Position
.deltaY
+ "px";
1644 element
.style
.left
= (pw
/2) - (w/2) - Position
.deltaX
+ "px";
1648 function labeltest_callback(transport
) {
1650 var container
= document
.getElementById('label_test_result');
1652 container
.innerHTML
= transport
.responseText
;
1653 if (!Element
.visible(container
)) {
1654 Effect
.SlideDown(container
, { duration
: 0.5 });
1659 exception_error("labeltest_callback", e
);
1663 function labelTest() {
1666 var container
= document
.getElementById('label_test_result');
1668 var form
= document
.forms
['label_edit_form'];
1670 var sql_exp
= form
.sql_exp
.value
;
1671 var description
= form
.description
.value
;
1673 notify_progress("Loading, please wait...");
1675 var query
= "backend.php?op=pref-labels&subop=test&expr=" +
1676 param_escape(sql_exp
) + "&descr=" + param_escape(description
);
1678 new Ajax
.Request(query
, {
1679 onComplete: function (transport
) {
1680 labeltest_callback(transport
);
1686 exception_error("labelTest", e
);