]>
git.wh0rd.org - tt-rss.git/blob - functions.js
1 var hotkeys_enabled
= true;
2 var notify_silent
= false;
3 var last_progress_point
= 0;
4 var sanity_check_done
= false;
6 /* add method to remove element from array */
8 Array
.prototype.remove = function(s
) {
9 for (var i
=0; i
< this.length
; i
++) {
10 if (s
== this[i
]) this.splice(i
, 1);
14 /* create console.log if it doesn't exist */
16 if (!window
.console
) console
= {};
17 console
.log
= console
.log
|| function(msg
) { };
18 console
.warn
= console
.warn
|| function(msg
) { };
19 console
.error
= console
.error
|| function(msg
) { };
21 function exception_error(location
, e
, ext_info
) {
22 var msg
= format_exception_error(location
, e
);
24 if (!ext_info
) ext_info
= false;
30 var ebc
= $("xebContent");
34 Element
.show("dialog_overlay");
35 Element
.show("errorBoxShadow");
38 if (ext_info
.responseText
) {
39 ext_info
= ext_info
.responseText
;
44 "<div><b>Error message:</b></div>" +
45 "<pre>" + msg
+ "</pre>";
48 ebc
.innerHTML
+= "<div><b>Additional information:</b></div>" +
49 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
52 ebc
.innerHTML
+= "<div><b>Stack trace:</b></div>" +
53 "<textarea readonly=\"1\">" + e
.stack
+ "</textarea>";
66 function format_exception_error(location
, e
) {
70 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
72 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
73 "\nFunction: " + location
+ "()" +
74 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
76 } else if (e
.description
) {
77 msg
= "Exception: " + e
.description
+ "\nFunction: " + location
+ "()";
79 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
82 console
.error("EXCEPTION: " + msg
);
88 function disableHotkeys() {
89 hotkeys_enabled
= false;
92 function enableHotkeys() {
93 hotkeys_enabled
= true;
96 function param_escape(arg
) {
97 if (typeof encodeURIComponent
!= 'undefined')
98 return encodeURIComponent(arg
);
103 function param_unescape(arg
) {
104 if (typeof decodeURIComponent
!= 'undefined')
105 return decodeURIComponent(arg
);
107 return unescape(arg
);
110 function delay(gap
) {
112 then
=new Date().getTime();
114 while((now
-then
)<gap
) {
115 now
=new Date().getTime();
119 var notify_hide_timerid
= false;
121 function hide_notify() {
124 n
.style
.display
= "none";
128 function notify_silent_next() {
129 notify_silent
= true;
132 function notify_real(msg
, no_hide
, n_type
) {
135 notify_silent
= false;
140 var nb
= $("notify_body");
142 if (!n
|| !nb
) return;
144 if (notify_hide_timerid
) {
145 window
.clearTimeout(notify_hide_timerid
);
149 if (n
.style
.display
== "block") {
150 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
154 n
.style
.display
= "block";
166 if (typeof __
!= 'undefined') {
171 n
.className
= "notify";
172 } else if (n_type
== 2) {
173 n
.className
= "notifyProgress";
174 msg
= "<img src='"+getInitParam("sign_progress")+"'> " + msg
;
175 } else if (n_type
== 3) {
176 n
.className
= "notifyError";
177 msg
= "<img src='"+getInitParam("sign_excl")+"'> " + msg
;
178 } else if (n_type
== 4) {
179 n
.className
= "notifyInfo";
180 msg
= "<img src='"+getInitParam("sign_info")+"'> " + msg
;
183 // msg = "<img src='images/live_com_loading.gif'> " + msg;
188 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
192 function notify(msg
, no_hide
) {
193 notify_real(msg
, no_hide
, 1);
196 function notify_progress(msg
, no_hide
) {
197 notify_real(msg
, no_hide
, 2);
200 function notify_error(msg
, no_hide
) {
201 notify_real(msg
, no_hide
, 3);
205 function notify_info(msg
, no_hide
) {
206 notify_real(msg
, no_hide
, 4);
209 function printLockingError() {
210 notify_info("Please wait until operation finishes.");
213 function cleanSelected(element
) {
214 var content
= $(element
);
216 for (i
= 0; i
< content
.rows
.length
; i
++) {
217 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
221 function getVisibleUnreadHeadlines() {
222 var content
= $("headlinesList");
224 var rows
= new Array();
226 if (!content
) return rows
;
228 for (i
= 0; i
< content
.rows
.length
; i
++) {
229 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
230 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
237 function getVisibleHeadlineIds() {
239 var content
= $("headlinesList");
241 var rows
= new Array();
243 if (!content
) return rows
;
245 for (i
= 0; i
< content
.rows
.length
; i
++) {
246 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
247 if (row_id
.length
> 0) {
254 function getFirstVisibleHeadlineId() {
256 var rows
= cdmGetVisibleArticles();
259 var rows
= getVisibleHeadlineIds();
264 function getLastVisibleHeadlineId() {
266 var rows
= cdmGetVisibleArticles();
267 return rows
[rows
.length
-1];
269 var rows
= getVisibleHeadlineIds();
270 return rows
[rows
.length
-1];
274 function markHeadline(id
) {
275 var row
= $("RROW-" + id
);
277 var is_active
= false;
279 if (row
.className
.match("Active")) {
282 row
.className
= row
.className
.replace("Selected", "");
283 row
.className
= row
.className
.replace("Active", "");
284 row
.className
= row
.className
.replace("Insensitive", "");
287 row
.className
= row
.className
= "Active";
290 var check
= $("RCHK-" + id
);
293 check
.checked
= true;
296 row
.className
= row
.className
+ "Selected";
301 function getFeedIds() {
302 var content
= $("feedsList");
304 var rows
= new Array();
306 for (i
= 0; i
< content
.rows
.length
; i
++) {
307 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
316 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
322 d
.setTime(d
.getTime() + (lifetime
* 1000));
325 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
327 int_setCookie(name
, value
, d
, path
, domain
, secure
);
331 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
332 document
.cookie
= name
+ "=" + escape(value
) +
333 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
334 ((path
) ? "; path=" + path
: "") +
335 ((domain
) ? "; domain=" + domain
: "") +
336 ((secure
) ? "; secure" : "");
339 function delCookie(name
, path
, domain
) {
340 if (getCookie(name
)) {
341 document
.cookie
= name
+ "=" +
342 ((path
) ? ";path=" + path
: "") +
343 ((domain
) ? ";domain=" + domain
: "" ) +
344 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
349 function getCookie(name
) {
351 var dc
= document
.cookie
;
352 var prefix
= name
+ "=";
353 var begin
= dc
.indexOf("; " + prefix
);
355 begin
= dc
.indexOf(prefix
);
356 if (begin
!= 0) return null;
361 var end
= document
.cookie
.indexOf(";", begin
);
365 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
368 function gotoPreferences() {
369 document
.location
.href
= "prefs.php";
372 function gotoMain() {
373 document
.location
.href
= "tt-rss.php";
376 function gotoExportOpml() {
377 document
.location
.href
= "opml.php?op=Export";
380 function parse_counters(reply
, scheduled_call
) {
385 var elems
= JSON
.parse(reply
.firstChild
.nodeValue
);
387 for (var l
= 0; l
< elems
.length
; l
++) {
390 var kind
= elems
[l
].kind
;
391 var ctr
= parseInt(elems
[l
].counter
)
392 var error
= elems
[l
].error
;
393 var has_img
= elems
[l
].has_img
;
394 var updated
= elems
[l
].updated
;
395 var title
= elems
[l
].title
;
396 var xmsg
= elems
[l
].xmsg
;
398 if (id
== "global-unread") {
400 if (ctr
> global_unread
) {
401 offlineDownloadStart(1);
409 if (id
== "subscribed-feeds") {
414 if (kind
&& kind
== "cat") {
415 var catctr
= $("FCATCTR-" + id
);
417 catctr
.innerHTML
= "(" + ctr
+ ")";
419 catctr
.className
= "catCtrHasUnread";
421 catctr
.className
= "catCtrNoUnread";
427 var feedctr
= $("FEEDCTR-" + id
);
428 var feedu
= $("FEEDU-" + id
);
429 var feedr
= $("FEEDR-" + id
);
430 var feed_img
= $("FIMG-" + id
);
431 var feedlink
= $("FEEDL-" + id
);
432 var feedupd
= $("FLUPD-" + id
);
434 if (updated
&& feedlink
) {
436 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
438 feedlink
.title
= "Updated: " + updated
;
443 if (!updated
) updated
= "";
447 feedupd
.innerHTML
= updated
+ " " + xmsg
+ " (Error)";
449 feedupd
.innerHTML
= updated
+ " (Error)";
453 feedupd
.innerHTML
= updated
+ " " + xmsg
;
455 feedupd
.innerHTML
= updated
;
460 if (has_img
&& feed_img
) {
461 if (!feed_img
.src
.match(id
+ ".ico")) {
462 feed_img
.src
= getInitParam("icons_url") + "/" + id
+ ".ico";
466 if (feedlink
&& title
) {
467 feedlink
.innerHTML
= title
;
470 if (feedctr
&& feedu
&& feedr
) {
472 if (parseInt(ctr
) > 0 &&
473 parseInt(feedu
.innerHTML
) < parseInt(ctr
) &&
474 id
== getActiveFeedId() && scheduled_call
) {
476 displayNewContentPrompt(id
);
479 var row_needs_hl
= (ctr
> 0 && ctr
> parseInt(feedu
.innerHTML
));
481 feedu
.innerHTML
= ctr
;
484 feedr
.className
= feedr
.className
.replace("feed", "error");
486 feedr
.className
= feedr
.className
.replace("error", "feed");
490 feedctr
.className
= "feedCtrHasUnread";
491 if (!feedr
.className
.match("Unread")) {
492 var is_selected
= feedr
.className
.match("Selected");
494 feedr
.className
= feedr
.className
.replace("Selected", "");
495 feedr
.className
= feedr
.className
.replace("Unread", "");
497 feedr
.className
= feedr
.className
+ "Unread";
500 feedr
.className
= feedr
.className
+ "Selected";
506 !getInitParam("theme_options").match('no_highlights')) {
507 new Effect
.Highlight(feedr
, {duration
: 1, startcolor
: "#fff7d5",
508 queue
: { position
:'end', scope
: 'EFQ-' + id
, limit
: 1 } } );
510 cache_invalidate("F:" + id
);
513 feedctr
.className
= "feedCtrNoUnread";
514 feedr
.className
= feedr
.className
.replace("Unread", "");
519 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
521 var feeds_stored
= number_of_feeds
;
523 console
.log("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
525 if (feeds_stored
!= feeds_found
) {
526 number_of_feeds
= feeds_found
;
528 if (feeds_stored
!= 0 && feeds_found
!= 0) {
529 console
.log("Subscribed feed number changed, refreshing feedlist");
530 setTimeout('updateFeedList(false, false)', 50);
533 /* var fl = $("feeds-frame").innerHTML;
535 cache_invalidate("FEEDLIST");
536 cache_inject("FEEDLIST", fl, getInitParam("num_feeds"));
541 exception_error("parse_counters", e
);
545 function parse_counters_reply(transport
, scheduled_call
) {
547 if (!transport
.responseXML
) {
548 notify_error("Backend did not return valid XML", true);
552 var reply
= transport
.responseXML
.firstChild
;
555 notify_error("Backend did not return expected XML object", true);
560 if (!transport_error_check(transport
)) return;
562 var counters
= reply
.getElementsByTagName("counters")[0];
565 parse_counters(counters
, scheduled_call
);
567 var runtime_info
= reply
.getElementsByTagName("runtime-info")[0];
570 parse_runtime_info(runtime_info
);
572 if (feedsSortByUnread()) {
576 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
580 function all_counters_callback2(transport
) {
582 if (offline_mode
) return;
584 parse_counters_reply(transport
);
587 exception_error("all_counters_callback2", e
, transport
);
591 function get_feed_unread(id
) {
593 return parseInt($("FEEDU-" + id
).innerHTML
);
599 function get_cat_unread(id
) {
601 var ctr
= $("FCATCTR-" + id
).innerHTML
;
602 ctr
= ctr
.replace("(", "");
603 ctr
= ctr
.replace(")", "");
604 return parseInt(ctr
);
610 function get_feed_entry_unread(elem
) {
612 var id
= elem
.id
.replace("FEEDR-", "");
619 return parseInt($("FEEDU-" + id
).innerHTML
);
625 function get_feed_entry_name(elem
) {
626 var id
= elem
.id
.replace("FEEDR-", "");
627 return getFeedName(id
);
631 function resort_category(node
, cat_mode
) {
635 console
.log("resort_category: " + node
+ " CM=" + cat_mode
);
637 var by_unread
= feedsSortByUnread();
639 var list
= node
.getElementsByTagName("LI");
641 for (i
= 0; i
< list
.length
; i
++) {
643 for (j
= i
+1; j
< list
.length
; j
++) {
645 var tmp_val
= get_feed_entry_unread(list
[i
]);
646 var cur_val
= get_feed_entry_unread(list
[j
]);
648 var tmp_name
= get_feed_entry_name(list
[i
]);
649 var cur_name
= get_feed_entry_name(list
[j
]);
651 /* we don't want to match FEEDR-0 - e.g. Archived articles */
653 var valid_pair
= cat_mode
|| (list
[i
].id
.match(/FEEDR-[1-9]/) &&
654 list
[j
].id
.match(/FEEDR-[1-9]/));
656 if (valid_pair
&& ((by_unread
&& (cur_val
> tmp_val
)) || (!by_unread
&& (cur_name
< tmp_name
)))) {
657 tempnode_i
= list
[i
].cloneNode(true);
658 tempnode_j
= list
[j
].cloneNode(true);
659 node
.replaceChild(tempnode_i
, list
[j
]);
660 node
.replaceChild(tempnode_j
, list
[i
]);
666 exception_error("resort_category", e
);
671 function resort_feedlist() {
672 console
.log("resort_feedlist");
674 if ($("FCATLIST--1")) {
676 var lists
= document
.getElementsByTagName("UL");
678 for (var i
= 0; i
< lists
.length
; i
++) {
679 if (lists
[i
].id
&& lists
[i
].id
.match("FCATLIST-")) {
680 resort_category(lists
[i
], true);
685 resort_category($("feedList"), false);
689 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
690 * * @author Sundar Dorai-Raj
691 * * Email: sdoraira@vt.edu
692 * * This program is free software; you can redistribute it and/or
693 * * modify it under the terms of the GNU General Public License
694 * * as published by the Free Software Foundation; either version 2
695 * * of the License, or (at your option) any later version,
696 * * provided that any use properly credits the author.
697 * * This program is distributed in the hope that it will be useful,
698 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
699 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
700 * * GNU General Public License for more details at http://www.gnu.org * * */
702 var numbers
=".0123456789";
703 function isNumeric(x
) {
704 // is x a String or a character?
706 // remove negative sign
708 for(j
=0;j
<x
.length
;j
++) {
709 // call isNumeric recursively for each character
710 number
=isNumeric(x
.substring(j
,j
+1));
711 if(!number
) return number
;
716 // if x is number return true
717 if(numbers
.indexOf(x
)>=0) return true;
723 function hideOrShowFeeds(hide
) {
727 console
.log("hideOrShowFeeds: " + hide
);
729 if ($("FCATLIST--1")) {
731 var lists
= document
.getElementsByTagName("UL");
733 for (var i
= 0; i
< lists
.length
; i
++) {
734 if (lists
[i
].id
&& lists
[i
].id
.match("FCATLIST-")) {
736 var id
= lists
[i
].id
.replace("FCATLIST-", "");
737 hideOrShowFeedsCategory(id
, hide
);
742 hideOrShowFeedsCategory(null, hide
);
746 exception_error("hideOrShowFeeds", e
);
750 function hideOrShowFeedsCategory(id
, hide
) {
758 node
= $("FCATLIST-" + id
);
759 cat_node
= $("FCAT-" + id
);
761 node
= $("feedList"); // no categories
764 // console.log("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
769 console
.log("hideOrShowFeeds: passed node is null, aborting");
773 // console.log("cat: " + node.id);
775 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
776 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
777 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
779 if (node
.childNodes
[i
].style
!= undefined) {
781 var has_unread
= (node
.childNodes
[i
].className
!= "feed" &&
782 node
.childNodes
[i
].className
!= "label" &&
783 !(!getInitParam("hide_read_shows_special") &&
784 node
.childNodes
[i
].className
== "virt") &&
785 node
.childNodes
[i
].className
!= "error" &&
786 node
.childNodes
[i
].className
!= "tag");
788 // console.log(node.childNodes[i].id + " --> " + has_unread);
790 if (hide
&& !has_unread
) {
791 //node.childNodes[i].style.display = "none";
792 var id
= node
.childNodes
[i
].id
;
793 Effect
.Fade(node
.childNodes
[i
], {duration
: 0.3,
794 queue
: { position
: 'end', scope
: 'FFADE-' + id
, limit
: 1 }});
798 node
.childNodes
[i
].style
.display
= "list-item";
799 //Effect.Appear(node.childNodes[i], {duration : 0.3});
803 node
.childNodes
[i
].style
.display
= "list-item";
805 //Effect.Appear(node.childNodes[i], {duration : 0.3});
806 //Effect.Highlight(node.childNodes[i]);
812 // console.log("end cat: " + node.id + " unread " + cat_unread);
816 if (cat_unread
== 0) {
817 if (cat_node
.style
== undefined) {
818 console
.log("ERROR: supplied cat_node " + cat_node
+
819 " has no styles. WTF?");
823 //cat_node.style.display = "none";
824 Effect
.Fade(cat_node
, {duration
: 0.3,
825 queue
: { position
: 'end', scope
: 'CFADE-' + node
.id
, limit
: 1 }});
827 cat_node
.style
.display
= "list-item";
831 cat_node
.style
.display
= "list-item";
838 // console.log("unread for category: " + cat_unread);
841 exception_error("hideOrShowFeedsCategory", e
);
845 function selectTableRow(r
, do_select
) {
846 r
.className
= r
.className
.replace("Selected", "");
849 r
.className
= r
.className
+ "Selected";
853 function selectTableRowById(elem_id
, check_id
, do_select
) {
857 var row
= $(elem_id
);
860 selectTableRow(row
, do_select
);
863 var check
= $(check_id
);
866 check
.checked
= do_select
;
869 exception_error("selectTableRowById", e
);
873 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
874 classcheck
, reset_others
) {
876 var content
= $(content_id
);
879 console
.log("[selectTableRows] Element " + content_id
+ " not found.");
883 for (i
= 0; i
< content
.rows
.length
; i
++) {
884 if (Element
.visible(content
.rows
[i
])) {
885 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
887 if (content
.rows
[i
].id
.match(prefix
)) {
888 selectTableRow(content
.rows
[i
], do_select
);
890 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
891 var check
= $(check_prefix
+ row_id
);
894 check
.checked
= do_select
;
896 } else if (reset_others
) {
897 selectTableRow(content
.rows
[i
], false);
899 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
900 var check
= $(check_prefix
+ row_id
);
903 check
.checked
= false;
907 } else if (reset_others
) {
908 selectTableRow(content
.rows
[i
], false);
910 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
911 var check
= $(check_prefix
+ row_id
);
914 check
.checked
= false;
922 function getSelectedTableRowIds(content_id
, prefix
) {
924 var content
= $(content_id
);
927 console
.log("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
931 var sel_rows
= new Array();
933 for (i
= 0; i
< content
.rows
.length
; i
++) {
934 if (content
.rows
[i
].id
.match(prefix
) &&
935 content
.rows
[i
].className
.match("Selected")) {
937 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
938 sel_rows
.push(row_id
);
946 function toggleSelectRowById(sender
, id
) {
949 if (sender
.checked
) {
950 if (!row
.className
.match("Selected")) {
951 row
.className
= row
.className
+ "Selected";
954 if (row
.className
.match("Selected")) {
955 row
.className
= row
.className
.replace("Selected", "");
960 function toggleSelectListRow(sender
) {
961 var parent_row
= sender
.parentNode
;
963 if (sender
.checked
) {
964 if (!parent_row
.className
.match("Selected")) {
965 parent_row
.className
= parent_row
.className
+ "Selected";
968 if (parent_row
.className
.match("Selected")) {
969 parent_row
.className
= parent_row
.className
.replace("Selected", "");
974 function tSR(sender
) {
975 return toggleSelectRow(sender
);
978 function toggleSelectRow(sender
) {
979 var parent_row
= sender
.parentNode
.parentNode
;
981 if (sender
.checked
) {
982 if (!parent_row
.className
.match("Selected")) {
983 parent_row
.className
= parent_row
.className
+ "Selected";
986 if (parent_row
.className
.match("Selected")) {
987 parent_row
.className
= parent_row
.className
.replace("Selected", "");
992 function getNextUnreadCat(id
) {
994 var rows
= $("feedList").getElementsByTagName("LI");
995 var feeds
= new Array();
997 var unread_only
= true;
1000 for (var i
= 0; i
< rows
.length
; i
++) {
1001 if (rows
[i
].id
.match("FCAT-")) {
1002 if (rows
[i
].id
== "FCAT-" + id
&& is_cat
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1004 var cat_id
= parseInt(rows
[i
].id
.replace("FCAT-", ""));
1007 if (!unread_only
|| get_cat_unread(cat_id
) > 0) {
1015 var idx
= feeds
.indexOf(id
);
1016 if (idx
!= -1 && idx
< feeds
.length
) {
1017 return feeds
[idx
+1];
1019 return feeds
.shift();
1023 exception_error("getNextUnreadCat", e
);
1027 function getRelativeFeedId2(id
, is_cat
, direction
, unread_only
) {
1030 // alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only);
1032 var rows
= $("feedList").getElementsByTagName("LI");
1033 var feeds
= new Array();
1035 for (var i
= 0; i
< rows
.length
; i
++) {
1036 if (rows
[i
].id
.match("FEEDR-")) {
1038 if (rows
[i
].id
== "FEEDR-" + id
&& !is_cat
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1041 (rows
[i
].className
.match("Unread") || rows
[i
].id
== "FEEDR-" + id
)) {
1042 feeds
.push(rows
[i
].id
.replace("FEEDR-", ""));
1047 if (rows
[i
].id
.match("FCAT-")) {
1048 if (rows
[i
].id
== "FCAT-" + id
&& is_cat
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1050 var cat_id
= parseInt(rows
[i
].id
.replace("FCAT-", ""));
1053 if (!unread_only
|| get_cat_unread(cat_id
) > 0) {
1054 feeds
.push("CAT:"+cat_id
);
1061 // alert(feeds.toString());
1064 if (direction
== "next") {
1065 return feeds
.shift();
1070 if (direction
== "next") {
1071 if (is_cat
) id
= "CAT:" + id
;
1072 var idx
= feeds
.indexOf(id
);
1073 if (idx
!= -1 && idx
< feeds
.length
) {
1074 return feeds
[idx
+1];
1076 return getRelativeFeedId2(false, is_cat
, direction
, unread_only
);
1079 if (is_cat
) id
= "CAT:" + id
;
1080 var idx
= feeds
.indexOf(id
);
1082 return feeds
[idx
-1];
1084 return getRelativeFeedId2(false, is_cat
, direction
, unread_only
);
1091 exception_error("getRelativeFeedId2", e
);
1095 function checkboxToggleElement(elem
, id
) {
1097 Effect
.Appear(id
, {duration
: 0.5});
1099 Effect
.Fade(id
, {duration
: 0.5});
1103 function dropboxSelect(e
, v
) {
1104 for (i
= 0; i
< e
.length
; i
++) {
1105 if (e
[i
].value
== v
) {
1106 e
.selectedIndex
= i
;
1112 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1113 // bugfixed just a little bit :-)
1114 function getURLParam(strParamName
){
1116 var strHref
= window
.location
.href
;
1118 if (strHref
.indexOf("#") == strHref
.length
-1) {
1119 strHref
= strHref
.substring(0, strHref
.length
-1);
1122 if ( strHref
.indexOf("?") > -1 ){
1123 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1124 var aQueryString
= strQueryString
.split("&");
1125 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1126 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1127 var aParam
= aQueryString
[iParam
].split("=");
1128 strReturn
= aParam
[1];
1136 function leading_zero(p
) {
1138 if (s
.length
== 1) s
= "0" + s
;
1142 function make_timestamp() {
1145 return leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1146 ":" + leading_zero(d
.getSeconds());
1150 function closeErrorBox() {
1152 if (Element
.visible("errorBoxShadow")) {
1153 Element
.hide("dialog_overlay");
1154 Element
.hide("errorBoxShadow");
1162 function closeInfoBox(cleanup
) {
1167 if (Element
.visible("infoBoxShadow")) {
1168 Element
.hide("dialog_overlay");
1169 Element
.hide("infoBoxShadow");
1171 if (cleanup
) $("infoBox").innerHTML
= " ";
1174 exception_error("closeInfoBox", e
);
1181 function displayDlg(id
, param
, callback
) {
1183 notify_progress("Loading, please wait...", true);
1187 var query
= "?op=dlg&id=" +
1188 param_escape(id
) + "¶m=" + param_escape(param
);
1190 new Ajax
.Request("backend.php", {
1192 onComplete: function (transport
) {
1193 infobox_callback2(transport
);
1194 if (callback
) callback(transport
);
1200 function infobox_submit_callback2(transport
) {
1204 // called from prefs, reload tab
1205 if (typeof active_tab
!= 'undefined' && active_tab
) {
1206 selectTab(active_tab
, false);
1210 if (transport
.responseText
) {
1211 notify_info(transport
.responseText
);
1215 function infobox_callback2(transport
) {
1218 console
.log("infobox_callback2");
1220 var box
= $('infoBox');
1224 if (!getInitParam("infobox_disable_overlay")) {
1225 Element
.show("dialog_overlay");
1228 box
.innerHTML
=transport
.responseText
;
1229 Element
.show("infoBoxShadow");
1230 //Effect.SlideDown("infoBoxShadow", {duration : 1.0});
1239 exception_error("infobox_callback2", e
);
1243 function createFilter() {
1247 var form
= document
.forms
['filter_add_form'];
1248 var reg_exp
= form
.reg_exp
.value
;
1250 if (reg_exp
== "") {
1251 alert(__("Can't add filter: nothing to match on."));
1255 var query
= Form
.serialize("filter_add_form");
1257 // we can be called from some other tab in Prefs
1258 if (typeof active_tab
!= 'undefined' && active_tab
) {
1259 active_tab
= "filterConfig";
1262 new Ajax
.Request("backend.php?" + query
, {
1263 onComplete: function (transport
) {
1264 infobox_submit_callback2(transport
);
1270 exception_error("createFilter", e
);
1274 function isValidURL(s
) {
1275 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
1278 function subscribeToFeed() {
1282 var form
= document
.forms
['feed_add_form'];
1283 var feed_url
= form
.feed_url
.value
;
1285 if (feed_url
== "") {
1286 alert(__("Can't subscribe: no feed URL given."));
1290 notify_progress(__("Subscribing to feed..."), true);
1292 var query
= Form
.serialize("feed_add_form");
1294 console
.log("subscribe q: " + query
);
1296 Form
.disable("feed_add_form");
1298 new Ajax
.Request("backend.php", {
1300 onComplete: function(transport
) {
1301 //dlg_frefresh_callback(transport);
1305 if (!transport
.responseXML
)
1306 console
.log(transport
.responseText
);
1308 var result
= transport
.responseXML
.getElementsByTagName('result')[0];
1309 var rc
= parseInt(result
.getAttribute('code'));
1311 Form
.enable("feed_add_form");
1318 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
1320 if (inPreferences()) {
1323 setTimeout('updateFeedList(false, false)', 50);
1327 alert(__("Specified URL seems to be invalid."));
1330 alert(__("Specified URL doesn't seem to contain any feeds."));
1333 new Ajax
.Request("backend.php", {
1334 parameters
: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url
),
1335 onComplete: function(transport
) {
1336 var result
= transport
.responseXML
.getElementsByTagName('urls')[0];
1337 var feeds
= JSON
.parse(result
.firstChild
.nodeValue
);
1338 var select
= document
.getElementById("faad_feeds_container_select");
1340 while (select
.hasChildNodes()) {
1341 select
.removeChild(elem
.firstChild
);
1344 for (var feedUrl
in feeds
) {
1345 select
.insert(new Option(feeds
[feedUrl
], feedUrl
, false));
1348 if (count
> 5) count
= 5;
1349 select
.size
= count
;
1351 Effect
.Appear('fadd_feeds_container', {duration
: 0.5});
1356 alert(__("Couldn't download the specified URL."));
1359 alert(__("You are already subscribed to this feed."));
1364 exception_error("subscribeToFeed", e
);
1370 exception_error("subscribeToFeed", e
);
1376 function filterCR(e
, f
)
1381 key
= window
.event
.keyCode
; //IE
1383 key
= e
.which
; //firefox
1386 if (typeof f
!= 'undefined') {
1397 function getInitParam(key
) {
1398 return init_params
[key
];
1401 function setInitParam(key
, value
) {
1402 init_params
[key
] = value
;
1405 function fatalError(code
, msg
, ext_info
) {
1408 if (!ext_info
) ext_info
= "N/A";
1411 window
.location
.href
= "tt-rss.php";
1412 } else if (code
== 5) {
1413 window
.location
.href
= "db-updater.php";
1416 if (msg
== "") msg
= "Unknown error";
1418 var ebc
= $("xebContent");
1422 Element
.show("dialog_overlay");
1423 Element
.show("errorBoxShadow");
1424 Element
.hide("xebBtn");
1427 if (ext_info
.responseText
) {
1428 ext_info
= ext_info
.responseText
;
1433 "<div><b>Error message:</b></div>" +
1434 "<pre>" + msg
+ "</pre>" +
1435 "<div><b>Additional information:</b></div>" +
1436 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
1441 exception_error("fatalError", e
);
1445 function getFeedName(id
, is_cat
) {
1449 e
= $("FCATN-" + id
);
1451 e
= $("FEEDN-" + id
);
1454 return e
.innerHTML
.stripTags();
1460 function filterDlgCheckType(sender
) {
1464 var ftype
= sender
[sender
.selectedIndex
].value
;
1466 var form
= document
.forms
["filter_add_form"];
1469 form
= document
.forms
["filter_edit_form"];
1473 console
.log("filterDlgCheckType: can't find form!");
1477 // if selected filter type is 5 (Date) enable the modifier dropbox
1479 Element
.show("filter_dlg_date_mod_box");
1480 Element
.show("filter_dlg_date_chk_box");
1482 Element
.hide("filter_dlg_date_mod_box");
1483 Element
.hide("filter_dlg_date_chk_box");
1488 exception_error("filterDlgCheckType", e
);
1493 function filterDlgCheckAction(sender
) {
1497 var action
= sender
[sender
.selectedIndex
].value
;
1499 var form
= document
.forms
["filter_add_form"];
1502 form
= document
.forms
["filter_edit_form"];
1506 console
.log("filterDlgCheckAction: can't find form!");
1510 var action_param
= $("filter_dlg_param_box");
1512 if (!action_param
) {
1513 console
.log("filterDlgCheckAction: can't find action param box!");
1517 // if selected action supports parameters, enable params field
1518 if (action
== 4 || action
== 6 || action
== 7) {
1519 Element
.show(action_param
);
1521 Element
.show(form
.action_param
);
1522 Element
.hide(form
.action_param_label
);
1524 Element
.show(form
.action_param_label
);
1525 Element
.hide(form
.action_param
);
1528 Element
.hide(action_param
);
1532 exception_error("filterDlgCheckAction", e
);
1537 function filterDlgCheckDate() {
1539 var form
= document
.forms
["filter_add_form"];
1542 form
= document
.forms
["filter_edit_form"];
1546 console
.log("filterDlgCheckAction: can't find form!");
1550 var reg_exp
= form
.reg_exp
.value
;
1552 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
1554 new Ajax
.Request("backend.php", {
1556 onComplete: function(transport
) {
1558 var form
= document
.forms
["filter_add_form"];
1561 form
= document
.forms
["filter_edit_form"];
1564 if (transport
.responseXML
) {
1565 var result
= transport
.responseXML
.getElementsByTagName("result")[0];
1567 if (result
&& result
.firstChild
) {
1568 if (result
.firstChild
.nodeValue
== "1") {
1570 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#00ff00'});
1577 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#ff0000'});
1583 exception_error("filterDlgCheckDate", e
);
1587 function explainError(code
) {
1588 return displayDlg("explainError", code
);
1591 // this only searches loaded headlines list, not in CDM
1592 function getRelativePostIds(id
, limit
) {
1594 if (!limit
) limit
= 3;
1596 console
.log("getRelativePostIds: " + id
+ " limit=" + limit
);
1598 var ids
= new Array();
1599 var container
= $("headlinesList");
1602 var rows
= container
.rows
;
1604 for (var i
= 0; i
< rows
.length
; i
++) {
1605 var r_id
= rows
[i
].id
.replace("RROW-", "");
1608 for (var k
= 1; k
<= limit
; k
++) {
1611 if (i
> k
-1) var nid
= rows
[i
-k
].id
.replace("RROW-", "");
1612 if (nid
) ids
.push(nid
);
1614 if (i
< rows
.length
-k
) nid
= rows
[i
+k
].id
.replace("RROW-", "");
1615 if (nid
) ids
.push(nid
);
1626 function openArticleInNewWindow(id
) {
1628 console
.log("openArticleInNewWindow: " + id
);
1630 var query
= "?op=rpc&subop=getArticleLink&id=" + id
;
1631 var wname
= "ttrss_article_" + id
;
1633 console
.log(query
+ " " + wname
);
1635 var w
= window
.open("", wname
);
1637 if (!w
) notify_error("Failed to open window for the article");
1639 new Ajax
.Request("backend.php", {
1641 onComplete: function(transport
) {
1643 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
1644 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
1646 console
.log("open_article received link: " + link
);
1650 var wname
= "ttrss_article_" + id
.firstChild
.nodeValue
;
1652 console
.log("link url: " + link
.firstChild
.nodeValue
+ ", wname " + wname
);
1654 var w
= window
.open(link
.firstChild
.nodeValue
, wname
);
1656 if (!w
) { notify_error("Failed to load article in new window"); }
1659 id
= id
.firstChild
.nodeValue
;
1660 if (!$("headlinesList")) {
1661 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
1665 notify_error("Can't open article: received invalid article link");
1670 exception_error("openArticleInNewWindow", e
);
1674 function isCdmMode() {
1675 return !$("headlinesList");
1678 function getSelectedArticleIds2() {
1679 var rows
= new Array();
1680 var cdm_mode
= isCdmMode();
1683 rows
= cdmGetSelectedArticles();
1685 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1688 var ids
= new Array();
1690 for (var i
= 0; i
< rows
.length
; i
++) {
1691 var chk
= $("RCHK-" + rows
[i
]);
1692 if (chk
&& chk
.checked
) {
1700 function displayHelpInfobox(topic_id
) {
1702 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
1704 var w
= window
.open(url
, "ttrss_help",
1705 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1709 function loading_set_progress(p
) {
1711 if (p
< last_progress_point
|| !Element
.visible("overlay")) return;
1713 console
.log("loading_set_progress : " + p
+ " (" + last_progress_point
+ ")");
1715 var o
= $("l_progress_i");
1717 // o.style.width = (p * 2) + "px";
1719 new Effect
.Scale(o
, p
, {
1721 scaleFrom
: last_progress_point
,
1722 scaleMode
: { originalWidth
: 200 },
1723 queue
: { position
: 'end', scope
: 'LSP-Q', limit
: 3 } });
1725 last_progress_point
= p
;
1728 exception_error("loading_set_progress", e
);
1732 function remove_splash() {
1733 if (Element
.visible("overlay")) {
1734 console
.log("about to remove splash, OMG!");
1735 Element
.hide("overlay");
1736 console
.log("removed splash!");
1740 function getSelectedFeedsFromBrowser() {
1742 var list
= $("browseFeedList");
1744 var selected
= new Array();
1746 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
1747 var child
= list
.childNodes
[i
];
1748 if (child
.id
&& child
.id
.match("FBROW-")) {
1749 var id
= child
.id
.replace("FBROW-", "");
1751 var cb
= $("FBCHK-" + id
);
1762 function updateFeedBrowser() {
1765 var query
= Form
.serialize("feed_browser");
1767 Element
.show('feed_browser_spinner');
1769 new Ajax
.Request("backend.php", {
1771 onComplete: function(transport
) {
1774 Element
.hide('feed_browser_spinner');
1776 var c
= $("browseFeedList");
1777 var r
= transport
.responseXML
.getElementsByTagName("content")[0];
1778 var nr
= transport
.responseXML
.getElementsByTagName("num-results")[0];
1779 var mode
= transport
.responseXML
.getElementsByTagName("mode")[0];
1782 c
.innerHTML
= r
.firstChild
.nodeValue
;
1785 if (parseInt(mode
.getAttribute("value")) == 2) {
1786 Element
.show('feed_archive_remove');
1788 Element
.hide('feed_archive_remove');
1794 exception_error("updateFeedBrowser", e
);
1799 function transport_error_check(transport
) {
1801 if (transport
.responseXML
) {
1802 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
1805 var code
= error
.getAttribute("error-code");
1806 var msg
= error
.getAttribute("error-msg");
1808 fatalError(code
, msg
);
1814 exception_error("check_for_error_xml", e
);
1819 function strip_tags(s
) {
1820 return s
.replace(/<\/?[^>]+(>|$)/g, "");
1823 function truncate_string(s
, length
) {
1824 if (!length
) length
= 30;
1825 var tmp
= s
.substring(0, length
);
1826 if (s
.length
> length
) tmp
+= "…";
1830 function hotkey_prefix_timeout() {
1833 var date
= new Date();
1834 var ts
= Math
.round(date
.getTime() / 1000);
1836 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
1837 console
.log("hotkey_prefix seems to be stuck, aborting");
1838 hotkey_prefix_pressed
= false;
1839 hotkey_prefix
= false;
1840 Element
.hide('cmdline');
1843 setTimeout("hotkey_prefix_timeout()", 1000);
1846 exception_error("hotkey_prefix_timeout", e
);
1850 function hideAuxDlg() {
1852 Element
.hide('auxDlg');
1854 exception_error("hideAuxDlg", e
);
1858 function displayNewContentPrompt(id
) {
1861 var msg
= "<a href='#' onclick='viewfeed("+id
+")'>" +
1862 __("New articles available in this feed (click to show)") + "</a>";
1864 msg
= msg
.replace("%s", getFeedName(id
));
1866 $('auxDlg').innerHTML
= msg
;
1868 new Effect
.Appear('auxDlg', {duration
: 0.5});
1871 exception_error("displayNewContentPrompt", e
);
1875 function feedBrowserSubscribe() {
1878 var selected
= getSelectedFeedsFromBrowser();
1880 var mode
= document
.forms
['feed_browser'].mode
;
1882 mode
= mode
[mode
.selectedIndex
].value
;
1884 if (selected
.length
> 0) {
1887 notify_progress("Loading, please wait...", true);
1889 var query
= "?op=rpc&subop=massSubscribe&ids="+
1890 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1892 new Ajax
.Request("backend.php", {
1894 onComplete: function(transport
) {
1896 var nf
= transport
.responseXML
.getElementsByTagName('num-feeds')[0];
1897 var nf_value
= nf
.getAttribute("value");
1899 notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value
));
1901 if (inPreferences()) {
1904 setTimeout('updateFeedList(false, false)', 50);
1909 alert(__("No feeds are selected."));
1913 exception_error("feedBrowserSubscribe", e
);
1917 function feedArchiveRemove() {
1920 var selected
= getSelectedFeedsFromBrowser();
1922 if (selected
.length
> 0) {
1924 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1927 Element
.show('feed_browser_spinner');
1929 var query
= "?op=rpc&subop=remarchived&ids=" +
1930 param_escape(selected
.toString());;
1932 new Ajax
.Request("backend.php", {
1934 onComplete: function(transport
) {
1935 updateFeedBrowser();
1940 alert(__("No feeds are selected."));
1944 exception_error("feedArchiveRemove", e
);
1948 function uploadIconHandler(rc
) {
1952 notify_info("Upload complete.");
1953 if (inPreferences()) {
1956 setTimeout('updateFeedList(false, false)', 50);
1960 notify_error("Upload failed: icon is too big.");
1963 notify_error("Upload failed.");
1968 exception_error("uploadIconHandler", e
);
1972 function removeFeedIcon(id
) {
1976 if (confirm(__("Remove stored feed icon?"))) {
1977 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
1981 notify_progress("Removing feed icon...", true);
1983 new Ajax
.Request("backend.php", {
1985 onComplete: function(transport
) {
1986 notify_info("Feed icon removed.");
1987 if (inPreferences()) {
1990 setTimeout('updateFeedList(false, false)', 50);
1997 exception_error("uploadFeedIcon", e
);
2001 function uploadFeedIcon() {
2005 var file
= $("icon_file");
2007 if (file
.value
.length
== 0) {
2008 alert(__("Please select an image file to upload."));
2010 if (confirm(__("Upload new icon for this feed?"))) {
2011 notify_progress("Uploading, please wait...", true);
2019 exception_error("uploadFeedIcon", e
);
2023 function addLabel(select
, callback
) {
2027 var caption
= prompt(__("Please enter label caption:"), "");
2029 if (caption
!= undefined) {
2031 if (caption
== "") {
2032 alert(__("Can't create label: missing caption."));
2036 var query
= "?op=pref-labels&subop=add&caption=" +
2037 param_escape(caption
);
2040 query
+= "&output=select";
2042 notify_progress("Loading, please wait...", true);
2044 if (inPreferences() && !select
) active_tab
= "labelConfig";
2046 new Ajax
.Request("backend.php", {
2048 onComplete: function(transport
) {
2050 callback(transport
);
2051 } else if (inPreferences()) {
2052 infobox_submit_callback2(transport
);
2061 exception_error("addLabel", e
);
2065 function quickAddFeed() {
2066 displayDlg('quickAddFeed', '',
2067 function () {$('feed_url').focus();});
2070 function quickAddFilter() {
2071 displayDlg('quickAddFilter', '',
2072 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
2075 function unsubscribeFeed(feed_id
, title
) {
2077 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
2079 if (title
== undefined || confirm(msg
)) {
2080 notify_progress("Removing feed...");
2082 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
2084 new Ajax
.Request("backend.php", {
2086 onComplete: function(transport
) {
2090 if (inPreferences()) {
2093 dlg_frefresh_callback(transport
, feed_id
);
2103 function backend_sanity_check_callback(transport
) {
2107 if (sanity_check_done
) {
2108 fatalError(11, "Sanity check request received twice. This can indicate "+
2109 "presence of Firebug or some other disrupting extension. "+
2110 "Please disable it and try again.");
2114 if (!transport
.responseXML
) {
2116 fatalError(3, "Sanity check: Received reply is not XML",
2117 transport
.responseText
);
2125 if (getURLParam("offline")) {
2126 return init_offline();
2129 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
2132 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
2136 var error_code
= reply
.getAttribute("error-code");
2138 if (error_code
&& error_code
!= 0) {
2139 return fatalError(error_code
, reply
.getAttribute("error-msg"));
2142 console
.log("sanity check ok");
2144 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
2147 console
.log('reading init-params...');
2149 params
= JSON
.parse(params
.firstChild
.nodeValue
);
2156 console
.log("IP: " + k
+ " => " + v
);
2159 db
.execute("DELETE FROM init_params WHERE key = ?", [k
]);
2160 db
.execute("INSERT INTO init_params (key,value) VALUES (?, ?)",
2166 init_params
= params
;
2169 sanity_check_done
= true;
2171 init_second_stage();
2174 exception_error("backend_sanity_check_callback", e
, transport
);
2178 function has_local_storage() {
2180 return 'localStorage' in window
&& window
['localStorage'] != null;
2186 function catSelectOnChange(elem
) {
2188 var value
= elem
[elem
.selectedIndex
].value
;
2189 var def
= elem
.getAttribute('default');
2191 if (value
== "ADD_CAT") {
2194 dropboxSelect(elem
, def
);
2196 elem
.selectedIndex
= 0;
2202 exception_error("catSelectOnChange", e
);
2206 function quickAddCat(elem
) {
2208 var cat
= prompt(__("Please enter category title:"));
2212 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
2214 notify_progress("Loading, please wait...", true);
2216 new Ajax
.Request("backend.php", {
2218 onComplete: function (transport
) {
2219 var response
= transport
.responseXML
;
2220 var select
= response
.getElementsByTagName("select")[0];
2221 var options
= select
.getElementsByTagName("option");
2223 dropbox_replace_options(elem
, options
);
2232 exception_error("quickAddCat", e
);
2236 function genUrlChangeKey(feed
, is_cat
) {
2239 var ok
= confirm(__("Generate new syndication address for this feed?"));
2243 notify_progress("Trying to change address...", true);
2245 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
2246 "&is_cat=" + param_escape(is_cat
);
2248 new Ajax
.Request("backend.php", {
2250 onComplete: function(transport
) {
2251 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
2253 var e
= $('gen_feed_url');
2257 new_link
= new_link
.firstChild
.nodeValue
;
2259 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
2260 "&key=" + new_link
);
2262 e
.href
= e
.href
.replace(/\&key=.*$/,
2263 "&key=" + new_link
);
2265 new Effect
.Highlight(e
);
2270 notify_error("Could not change feed URL.");
2275 exception_error("genUrlChangeKey", e
);
2280 function labelSelectOnChange(elem
) {
2282 var value
= elem
[elem
.selectedIndex
].value
;
2283 var def
= elem
.getAttribute('default');
2285 if (value
== "ADD_LABEL") {
2288 dropboxSelect(elem
, def
);
2290 elem
.selectedIndex
= 0;
2292 addLabel(elem
, function(transport
) {
2296 var response
= transport
.responseXML
;
2297 var select
= response
.getElementsByTagName("select")[0];
2298 var options
= select
.getElementsByTagName("option");
2300 dropbox_replace_options(elem
, options
);
2304 exception_error("addLabel", e
);
2310 exception_error("labelSelectOnChange", e
);
2314 function dropbox_replace_options(elem
, options
) {
2317 while (elem
.hasChildNodes())
2318 elem
.removeChild(elem
.firstChild
);
2322 for (var i
= 0; i
< options
.length
; i
++) {
2323 var text
= options
[i
].firstChild
.nodeValue
;
2324 var value
= options
[i
].getAttribute("value");
2326 if (value
== undefined) value
= text
;
2328 var issel
= options
[i
].getAttribute("selected") == "1";
2330 var option
= new Option(text
, value
, issel
);
2332 if (options
[i
].getAttribute("disabled"))
2333 option
.setAttribute("disabled", true);
2335 elem
.insert(option
);
2337 if (issel
) sel_idx
= i
;
2340 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
2341 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
2344 exception_error("dropbox_replace_options", e
);