]>
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 async_counters_work
= false;
5 var sanity_check_done
= false;
7 /* add method to remove element from array */
9 Array
.prototype.remove = function(s
) {
10 for (var i
=0; i
< this.length
; i
++) {
11 if (s
== this[i
]) this.splice(i
, 1);
15 /* create console.log if it doesn't exist */
17 if (!window
.console
) console
= {};
18 console
.log
= console
.log
|| function(msg
) { };
19 console
.warn
= console
.warn
|| function(msg
) { };
20 console
.error
= console
.error
|| function(msg
) { };
22 function exception_error(location
, e
, ext_info
) {
23 var msg
= format_exception_error(location
, e
);
25 if (!ext_info
) ext_info
= false;
31 var ebc
= $("xebContent");
35 Element
.show("dialog_overlay");
36 Element
.show("errorBoxShadow");
39 if (ext_info
.responseText
) {
40 ext_info
= ext_info
.responseText
;
45 "<div><b>Error message:</b></div>" +
46 "<pre>" + msg
+ "</pre>";
49 ebc
.innerHTML
+= "<div><b>Additional information:</b></div>" +
50 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
53 ebc
.innerHTML
+= "<div><b>Stack trace:</b></div>" +
54 "<textarea readonly=\"1\">" + e
.stack
+ "</textarea>";
67 function format_exception_error(location
, e
) {
71 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
73 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
74 "\nFunction: " + location
+ "()" +
75 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
77 } else if (e
.description
) {
78 msg
= "Exception: " + e
.description
+ "\nFunction: " + location
+ "()";
80 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
83 console
.error("EXCEPTION: " + msg
);
89 function disableHotkeys() {
90 hotkeys_enabled
= false;
93 function enableHotkeys() {
94 hotkeys_enabled
= true;
97 function param_escape(arg
) {
98 if (typeof encodeURIComponent
!= 'undefined')
99 return encodeURIComponent(arg
);
104 function param_unescape(arg
) {
105 if (typeof decodeURIComponent
!= 'undefined')
106 return decodeURIComponent(arg
);
108 return unescape(arg
);
111 function delay(gap
) {
113 then
=new Date().getTime();
115 while((now
-then
)<gap
) {
116 now
=new Date().getTime();
120 var notify_hide_timerid
= false;
122 function hide_notify() {
125 n
.style
.display
= "none";
129 function notify_silent_next() {
130 notify_silent
= true;
133 function notify_real(msg
, no_hide
, n_type
) {
136 notify_silent
= false;
141 var nb
= $("notify_body");
143 if (!n
|| !nb
) return;
145 if (notify_hide_timerid
) {
146 window
.clearTimeout(notify_hide_timerid
);
150 if (n
.style
.display
== "block") {
151 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
155 n
.style
.display
= "block";
167 if (typeof __
!= 'undefined') {
172 n
.className
= "notify";
173 } else if (n_type
== 2) {
174 n
.className
= "notifyProgress";
175 msg
= "<img src='"+getInitParam("sign_progress")+"'> " + msg
;
176 } else if (n_type
== 3) {
177 n
.className
= "notifyError";
178 msg
= "<img src='"+getInitParam("sign_excl")+"'> " + msg
;
179 } else if (n_type
== 4) {
180 n
.className
= "notifyInfo";
181 msg
= "<img src='"+getInitParam("sign_info")+"'> " + msg
;
184 // msg = "<img src='images/live_com_loading.gif'> " + msg;
189 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
193 function notify(msg
, no_hide
) {
194 notify_real(msg
, no_hide
, 1);
197 function notify_progress(msg
, no_hide
) {
198 notify_real(msg
, no_hide
, 2);
201 function notify_error(msg
, no_hide
) {
202 notify_real(msg
, no_hide
, 3);
206 function notify_info(msg
, no_hide
) {
207 notify_real(msg
, no_hide
, 4);
210 function printLockingError() {
211 notify_info("Please wait until operation finishes.");
214 function cleanSelected(element
) {
215 var content
= $(element
);
217 for (i
= 0; i
< content
.rows
.length
; i
++) {
218 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
222 function getVisibleUnreadHeadlines() {
223 var content
= $("headlinesList");
225 var rows
= new Array();
227 if (!content
) return rows
;
229 for (i
= 0; i
< content
.rows
.length
; i
++) {
230 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
231 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
238 function getVisibleHeadlineIds() {
240 var content
= $("headlinesList");
242 var rows
= new Array();
244 if (!content
) return rows
;
246 for (i
= 0; i
< content
.rows
.length
; i
++) {
247 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
248 if (row_id
.length
> 0) {
255 function getFirstVisibleHeadlineId() {
257 var rows
= cdmGetVisibleArticles();
260 var rows
= getVisibleHeadlineIds();
265 function getLastVisibleHeadlineId() {
267 var rows
= cdmGetVisibleArticles();
268 return rows
[rows
.length
-1];
270 var rows
= getVisibleHeadlineIds();
271 return rows
[rows
.length
-1];
275 function markHeadline(id
) {
276 var row
= $("RROW-" + id
);
278 var is_active
= false;
280 if (row
.className
.match("Active")) {
283 row
.className
= row
.className
.replace("Selected", "");
284 row
.className
= row
.className
.replace("Active", "");
285 row
.className
= row
.className
.replace("Insensitive", "");
288 row
.className
= row
.className
= "Active";
291 var check
= $("RCHK-" + id
);
294 check
.checked
= true;
297 row
.className
= row
.className
+ "Selected";
302 function getFeedIds() {
303 var content
= $("feedsList");
305 var rows
= new Array();
307 for (i
= 0; i
< content
.rows
.length
; i
++) {
308 var id
= content
.rows
[i
].id
.replace("FEEDR-", "");
317 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
323 d
.setTime(d
.getTime() + (lifetime
* 1000));
326 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
328 int_setCookie(name
, value
, d
, path
, domain
, secure
);
332 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
333 document
.cookie
= name
+ "=" + escape(value
) +
334 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
335 ((path
) ? "; path=" + path
: "") +
336 ((domain
) ? "; domain=" + domain
: "") +
337 ((secure
) ? "; secure" : "");
340 function delCookie(name
, path
, domain
) {
341 if (getCookie(name
)) {
342 document
.cookie
= name
+ "=" +
343 ((path
) ? ";path=" + path
: "") +
344 ((domain
) ? ";domain=" + domain
: "" ) +
345 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
350 function getCookie(name
) {
352 var dc
= document
.cookie
;
353 var prefix
= name
+ "=";
354 var begin
= dc
.indexOf("; " + prefix
);
356 begin
= dc
.indexOf(prefix
);
357 if (begin
!= 0) return null;
362 var end
= document
.cookie
.indexOf(";", begin
);
366 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
369 function gotoPreferences() {
370 document
.location
.href
= "prefs.php";
373 function gotoMain() {
374 document
.location
.href
= "tt-rss.php";
377 function gotoExportOpml() {
378 document
.location
.href
= "opml.php?op=Export";
381 function parse_counters(reply
, scheduled_call
) {
386 var elems
= JSON
.parse(reply
.firstChild
.nodeValue
);
388 for (var l
= 0; l
< elems
.length
; l
++) {
391 var kind
= elems
[l
].kind
;
392 var ctr
= parseInt(elems
[l
].counter
)
393 var error
= elems
[l
].error
;
394 var has_img
= elems
[l
].has_img
;
395 var updated
= elems
[l
].updated
;
396 var title
= elems
[l
].title
;
397 var xmsg
= elems
[l
].xmsg
;
399 if (id
== "global-unread") {
401 if (ctr
> global_unread
) {
402 offlineDownloadStart(1);
410 if (id
== "subscribed-feeds") {
415 if (kind
&& kind
== "cat") {
416 var catctr
= $("FCATCTR-" + id
);
418 catctr
.innerHTML
= "(" + ctr
+ ")";
420 catctr
.className
= "catCtrHasUnread";
422 catctr
.className
= "catCtrNoUnread";
428 var feedctr
= $("FEEDCTR-" + id
);
429 var feedu
= $("FEEDU-" + id
);
430 var feedr
= $("FEEDR-" + id
);
431 var feed_img
= $("FIMG-" + id
);
432 var feedlink
= $("FEEDL-" + id
);
433 var feedupd
= $("FLUPD-" + id
);
435 if (updated
&& feedlink
) {
437 feedlink
.title
= "Error: " + error
+ " (" + updated
+ ")";
439 feedlink
.title
= "Updated: " + updated
;
444 if (!updated
) updated
= "";
448 feedupd
.innerHTML
= updated
+ " " + xmsg
+ " (Error)";
450 feedupd
.innerHTML
= updated
+ " (Error)";
454 feedupd
.innerHTML
= updated
+ " " + xmsg
;
456 feedupd
.innerHTML
= updated
;
461 if (has_img
&& feed_img
) {
462 if (!feed_img
.src
.match(id
+ ".ico")) {
463 feed_img
.src
= getInitParam("icons_url") + "/" + id
+ ".ico";
467 if (feedlink
&& title
) {
468 feedlink
.innerHTML
= title
;
471 if (feedctr
&& feedu
&& feedr
) {
473 if (parseInt(ctr
) > 0 &&
474 parseInt(feedu
.innerHTML
) < parseInt(ctr
) &&
475 id
== getActiveFeedId() && scheduled_call
) {
477 displayNewContentPrompt(id
);
480 var row_needs_hl
= (ctr
> 0 && ctr
> parseInt(feedu
.innerHTML
));
482 feedu
.innerHTML
= ctr
;
485 feedr
.className
= feedr
.className
.replace("feed", "error");
487 feedr
.className
= feedr
.className
.replace("error", "feed");
491 feedctr
.className
= "feedCtrHasUnread";
492 if (!feedr
.className
.match("Unread")) {
493 var is_selected
= feedr
.className
.match("Selected");
495 feedr
.className
= feedr
.className
.replace("Selected", "");
496 feedr
.className
= feedr
.className
.replace("Unread", "");
498 feedr
.className
= feedr
.className
+ "Unread";
501 feedr
.className
= feedr
.className
+ "Selected";
507 !getInitParam("theme_options").match('no_highlights')) {
508 new Effect
.Highlight(feedr
, {duration
: 1, startcolor
: "#fff7d5",
509 queue
: { position
:'end', scope
: 'EFQ-' + id
, limit
: 1 } } );
511 cache_invalidate("F:" + id
);
514 feedctr
.className
= "feedCtrNoUnread";
515 feedr
.className
= feedr
.className
.replace("Unread", "");
520 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
522 var feeds_stored
= number_of_feeds
;
524 console
.log("Feed counters, C: " + feeds_found
+ ", S:" + feeds_stored
);
526 if (feeds_stored
!= feeds_found
) {
527 number_of_feeds
= feeds_found
;
529 if (feeds_stored
!= 0 && feeds_found
!= 0) {
530 console
.log("Subscribed feed number changed, refreshing feedlist");
531 setTimeout('updateFeedList(false, false)', 50);
534 /* var fl = $("feeds-frame").innerHTML;
536 cache_invalidate("FEEDLIST");
537 cache_inject("FEEDLIST", fl, getInitParam("num_feeds"));
542 exception_error("parse_counters", e
);
546 function parse_counters_reply(transport
, scheduled_call
) {
548 if (!transport
.responseXML
) {
549 notify_error("Backend did not return valid XML", true);
553 var reply
= transport
.responseXML
.firstChild
;
556 notify_error("Backend did not return expected XML object", true);
561 if (!transport_error_check(transport
)) return;
563 var counters
= reply
.getElementsByTagName("counters")[0];
566 parse_counters(counters
, scheduled_call
);
568 var runtime_info
= reply
.getElementsByTagName("runtime-info")[0];
571 parse_runtime_info(runtime_info
);
573 if (feedsSortByUnread()) {
577 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
581 function all_counters_callback2(transport
, async_call
) {
583 if (async_call
) async_counters_work
= true;
584 if (offline_mode
) return;
586 parse_counters_reply(transport
);
589 exception_error("all_counters_callback2", e
, transport
);
593 function get_feed_unread(id
) {
595 return parseInt($("FEEDU-" + id
).innerHTML
);
601 function get_cat_unread(id
) {
603 var ctr
= $("FCATCTR-" + id
).innerHTML
;
604 ctr
= ctr
.replace("(", "");
605 ctr
= ctr
.replace(")", "");
606 return parseInt(ctr
);
612 function get_feed_entry_unread(elem
) {
614 var id
= elem
.id
.replace("FEEDR-", "");
621 return parseInt($("FEEDU-" + id
).innerHTML
);
627 function get_feed_entry_name(elem
) {
628 var id
= elem
.id
.replace("FEEDR-", "");
629 return getFeedName(id
);
633 function resort_category(node
, cat_mode
) {
637 console
.log("resort_category: " + node
+ " CM=" + cat_mode
);
639 var by_unread
= feedsSortByUnread();
641 var list
= node
.getElementsByTagName("LI");
643 for (i
= 0; i
< list
.length
; i
++) {
645 for (j
= i
+1; j
< list
.length
; j
++) {
647 var tmp_val
= get_feed_entry_unread(list
[i
]);
648 var cur_val
= get_feed_entry_unread(list
[j
]);
650 var tmp_name
= get_feed_entry_name(list
[i
]);
651 var cur_name
= get_feed_entry_name(list
[j
]);
653 /* we don't want to match FEEDR-0 - e.g. Archived articles */
655 var valid_pair
= cat_mode
|| (list
[i
].id
.match(/FEEDR-[1-9]/) &&
656 list
[j
].id
.match(/FEEDR-[1-9]/));
658 if (valid_pair
&& ((by_unread
&& (cur_val
> tmp_val
)) || (!by_unread
&& (cur_name
< tmp_name
)))) {
659 tempnode_i
= list
[i
].cloneNode(true);
660 tempnode_j
= list
[j
].cloneNode(true);
661 node
.replaceChild(tempnode_i
, list
[j
]);
662 node
.replaceChild(tempnode_j
, list
[i
]);
668 exception_error("resort_category", e
);
673 function resort_feedlist() {
674 console
.log("resort_feedlist");
676 if ($("FCATLIST--1")) {
678 var lists
= document
.getElementsByTagName("UL");
680 for (var i
= 0; i
< lists
.length
; i
++) {
681 if (lists
[i
].id
&& lists
[i
].id
.match("FCATLIST-")) {
682 resort_category(lists
[i
], true);
687 resort_category($("feedList"), false);
691 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
692 * * @author Sundar Dorai-Raj
693 * * Email: sdoraira@vt.edu
694 * * This program is free software; you can redistribute it and/or
695 * * modify it under the terms of the GNU General Public License
696 * * as published by the Free Software Foundation; either version 2
697 * * of the License, or (at your option) any later version,
698 * * provided that any use properly credits the author.
699 * * This program is distributed in the hope that it will be useful,
700 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
701 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
702 * * GNU General Public License for more details at http://www.gnu.org * * */
704 var numbers
=".0123456789";
705 function isNumeric(x
) {
706 // is x a String or a character?
708 // remove negative sign
710 for(j
=0;j
<x
.length
;j
++) {
711 // call isNumeric recursively for each character
712 number
=isNumeric(x
.substring(j
,j
+1));
713 if(!number
) return number
;
718 // if x is number return true
719 if(numbers
.indexOf(x
)>=0) return true;
725 function hideOrShowFeeds(hide
) {
729 console
.log("hideOrShowFeeds: " + hide
);
731 if ($("FCATLIST--1")) {
733 var lists
= document
.getElementsByTagName("UL");
735 for (var i
= 0; i
< lists
.length
; i
++) {
736 if (lists
[i
].id
&& lists
[i
].id
.match("FCATLIST-")) {
738 var id
= lists
[i
].id
.replace("FCATLIST-", "");
739 hideOrShowFeedsCategory(id
, hide
);
744 hideOrShowFeedsCategory(null, hide
);
748 exception_error("hideOrShowFeeds", e
);
752 function hideOrShowFeedsCategory(id
, hide
) {
760 node
= $("FCATLIST-" + id
);
761 cat_node
= $("FCAT-" + id
);
763 node
= $("feedList"); // no categories
766 // console.log("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
771 console
.log("hideOrShowFeeds: passed node is null, aborting");
775 // console.log("cat: " + node.id);
777 if (node
.hasChildNodes() && node
.firstChild
.nextSibling
!= false) {
778 for (i
= 0; i
< node
.childNodes
.length
; i
++) {
779 if (node
.childNodes
[i
].nodeName
!= "LI") { continue; }
781 if (node
.childNodes
[i
].style
!= undefined) {
783 var has_unread
= (node
.childNodes
[i
].className
!= "feed" &&
784 node
.childNodes
[i
].className
!= "label" &&
785 !(!getInitParam("hide_read_shows_special") &&
786 node
.childNodes
[i
].className
== "virt") &&
787 node
.childNodes
[i
].className
!= "error" &&
788 node
.childNodes
[i
].className
!= "tag");
790 // console.log(node.childNodes[i].id + " --> " + has_unread);
792 if (hide
&& !has_unread
) {
793 //node.childNodes[i].style.display = "none";
794 var id
= node
.childNodes
[i
].id
;
795 Effect
.Fade(node
.childNodes
[i
], {duration
: 0.3,
796 queue
: { position
: 'end', scope
: 'FFADE-' + id
, limit
: 1 }});
800 node
.childNodes
[i
].style
.display
= "list-item";
801 //Effect.Appear(node.childNodes[i], {duration : 0.3});
805 node
.childNodes
[i
].style
.display
= "list-item";
807 //Effect.Appear(node.childNodes[i], {duration : 0.3});
808 //Effect.Highlight(node.childNodes[i]);
814 // console.log("end cat: " + node.id + " unread " + cat_unread);
818 if (cat_unread
== 0) {
819 if (cat_node
.style
== undefined) {
820 console
.log("ERROR: supplied cat_node " + cat_node
+
821 " has no styles. WTF?");
825 //cat_node.style.display = "none";
826 Effect
.Fade(cat_node
, {duration
: 0.3,
827 queue
: { position
: 'end', scope
: 'CFADE-' + node
.id
, limit
: 1 }});
829 cat_node
.style
.display
= "list-item";
833 cat_node
.style
.display
= "list-item";
840 // console.log("unread for category: " + cat_unread);
843 exception_error("hideOrShowFeedsCategory", e
);
847 function selectTableRow(r
, do_select
) {
848 r
.className
= r
.className
.replace("Selected", "");
851 r
.className
= r
.className
+ "Selected";
855 function selectTableRowById(elem_id
, check_id
, do_select
) {
859 var row
= $(elem_id
);
862 selectTableRow(row
, do_select
);
865 var check
= $(check_id
);
868 check
.checked
= do_select
;
871 exception_error("selectTableRowById", e
);
875 function selectTableRowsByIdPrefix(content_id
, prefix
, check_prefix
, do_select
,
876 classcheck
, reset_others
) {
878 var content
= $(content_id
);
881 console
.log("[selectTableRows] Element " + content_id
+ " not found.");
885 for (i
= 0; i
< content
.rows
.length
; i
++) {
886 if (Element
.visible(content
.rows
[i
])) {
887 if (!classcheck
|| content
.rows
[i
].className
.match(classcheck
)) {
889 if (content
.rows
[i
].id
.match(prefix
)) {
890 selectTableRow(content
.rows
[i
], do_select
);
892 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
893 var check
= $(check_prefix
+ row_id
);
896 check
.checked
= do_select
;
898 } else if (reset_others
) {
899 selectTableRow(content
.rows
[i
], false);
901 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
902 var check
= $(check_prefix
+ row_id
);
905 check
.checked
= false;
909 } else if (reset_others
) {
910 selectTableRow(content
.rows
[i
], false);
912 var row_id
= content
.rows
[i
].id
.replace(prefix
, "");
913 var check
= $(check_prefix
+ row_id
);
916 check
.checked
= false;
924 function getSelectedTableRowIds(content_id
, prefix
) {
926 var content
= $(content_id
);
929 console
.log("[getSelectedTableRowIds] Element " + content_id
+ " not found.");
933 var sel_rows
= new Array();
935 for (i
= 0; i
< content
.rows
.length
; i
++) {
936 if (content
.rows
[i
].id
.match(prefix
) &&
937 content
.rows
[i
].className
.match("Selected")) {
939 var row_id
= content
.rows
[i
].id
.replace(prefix
+ "-", "");
940 sel_rows
.push(row_id
);
948 function toggleSelectRowById(sender
, id
) {
951 if (sender
.checked
) {
952 if (!row
.className
.match("Selected")) {
953 row
.className
= row
.className
+ "Selected";
956 if (row
.className
.match("Selected")) {
957 row
.className
= row
.className
.replace("Selected", "");
962 function toggleSelectListRow(sender
) {
963 var parent_row
= sender
.parentNode
;
965 if (sender
.checked
) {
966 if (!parent_row
.className
.match("Selected")) {
967 parent_row
.className
= parent_row
.className
+ "Selected";
970 if (parent_row
.className
.match("Selected")) {
971 parent_row
.className
= parent_row
.className
.replace("Selected", "");
976 function tSR(sender
) {
977 return toggleSelectRow(sender
);
980 function toggleSelectRow(sender
) {
981 var parent_row
= sender
.parentNode
.parentNode
;
983 if (sender
.checked
) {
984 if (!parent_row
.className
.match("Selected")) {
985 parent_row
.className
= parent_row
.className
+ "Selected";
988 if (parent_row
.className
.match("Selected")) {
989 parent_row
.className
= parent_row
.className
.replace("Selected", "");
994 function getNextUnreadCat(id
) {
996 var rows
= $("feedList").getElementsByTagName("LI");
997 var feeds
= new Array();
999 var unread_only
= true;
1002 for (var i
= 0; i
< rows
.length
; i
++) {
1003 if (rows
[i
].id
.match("FCAT-")) {
1004 if (rows
[i
].id
== "FCAT-" + id
&& is_cat
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1006 var cat_id
= parseInt(rows
[i
].id
.replace("FCAT-", ""));
1009 if (!unread_only
|| get_cat_unread(cat_id
) > 0) {
1017 var idx
= feeds
.indexOf(id
);
1018 if (idx
!= -1 && idx
< feeds
.length
) {
1019 return feeds
[idx
+1];
1021 return feeds
.shift();
1025 exception_error("getNextUnreadCat", e
);
1029 function getRelativeFeedId2(id
, is_cat
, direction
, unread_only
) {
1032 // alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only);
1034 var rows
= $("feedList").getElementsByTagName("LI");
1035 var feeds
= new Array();
1037 for (var i
= 0; i
< rows
.length
; i
++) {
1038 if (rows
[i
].id
.match("FEEDR-")) {
1040 if (rows
[i
].id
== "FEEDR-" + id
&& !is_cat
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1043 (rows
[i
].className
.match("Unread") || rows
[i
].id
== "FEEDR-" + id
)) {
1044 feeds
.push(rows
[i
].id
.replace("FEEDR-", ""));
1049 if (rows
[i
].id
.match("FCAT-")) {
1050 if (rows
[i
].id
== "FCAT-" + id
&& is_cat
|| (Element
.visible(rows
[i
]) && Element
.visible(rows
[i
].parentNode
))) {
1052 var cat_id
= parseInt(rows
[i
].id
.replace("FCAT-", ""));
1055 if (!unread_only
|| get_cat_unread(cat_id
) > 0) {
1056 feeds
.push("CAT:"+cat_id
);
1063 // alert(feeds.toString());
1066 if (direction
== "next") {
1067 return feeds
.shift();
1072 if (direction
== "next") {
1073 if (is_cat
) id
= "CAT:" + id
;
1074 var idx
= feeds
.indexOf(id
);
1075 if (idx
!= -1 && idx
< feeds
.length
) {
1076 return feeds
[idx
+1];
1078 return getRelativeFeedId2(false, is_cat
, direction
, unread_only
);
1081 if (is_cat
) id
= "CAT:" + id
;
1082 var idx
= feeds
.indexOf(id
);
1084 return feeds
[idx
-1];
1086 return getRelativeFeedId2(false, is_cat
, direction
, unread_only
);
1093 exception_error("getRelativeFeedId2", e
);
1097 function checkboxToggleElement(elem
, id
) {
1099 Effect
.Appear(id
, {duration
: 0.5});
1101 Effect
.Fade(id
, {duration
: 0.5});
1105 function dropboxSelect(e
, v
) {
1106 for (i
= 0; i
< e
.length
; i
++) {
1107 if (e
[i
].value
== v
) {
1108 e
.selectedIndex
= i
;
1114 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
1115 // bugfixed just a little bit :-)
1116 function getURLParam(strParamName
){
1118 var strHref
= window
.location
.href
;
1120 if (strHref
.indexOf("#") == strHref
.length
-1) {
1121 strHref
= strHref
.substring(0, strHref
.length
-1);
1124 if ( strHref
.indexOf("?") > -1 ){
1125 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
1126 var aQueryString
= strQueryString
.split("&");
1127 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
1128 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
1129 var aParam
= aQueryString
[iParam
].split("=");
1130 strReturn
= aParam
[1];
1138 function leading_zero(p
) {
1140 if (s
.length
== 1) s
= "0" + s
;
1144 function make_timestamp() {
1147 return leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
1148 ":" + leading_zero(d
.getSeconds());
1152 function closeErrorBox() {
1154 if (Element
.visible("errorBoxShadow")) {
1155 Element
.hide("dialog_overlay");
1156 Element
.hide("errorBoxShadow");
1164 function closeInfoBox(cleanup
) {
1169 if (Element
.visible("infoBoxShadow")) {
1170 Element
.hide("dialog_overlay");
1171 Element
.hide("infoBoxShadow");
1173 if (cleanup
) $("infoBox").innerHTML
= " ";
1176 exception_error("closeInfoBox", e
);
1183 function displayDlg(id
, param
, callback
) {
1185 notify_progress("Loading, please wait...", true);
1189 var query
= "?op=dlg&id=" +
1190 param_escape(id
) + "¶m=" + param_escape(param
);
1192 new Ajax
.Request("backend.php", {
1194 onComplete: function (transport
) {
1195 infobox_callback2(transport
);
1196 if (callback
) callback(transport
);
1202 function infobox_submit_callback2(transport
) {
1206 // called from prefs, reload tab
1207 if (typeof active_tab
!= 'undefined' && active_tab
) {
1208 selectTab(active_tab
, false);
1212 if (transport
.responseText
) {
1213 notify_info(transport
.responseText
);
1217 function infobox_callback2(transport
) {
1220 console
.log("infobox_callback2");
1222 var box
= $('infoBox');
1226 if (!getInitParam("infobox_disable_overlay")) {
1227 Element
.show("dialog_overlay");
1230 box
.innerHTML
=transport
.responseText
;
1231 Element
.show("infoBoxShadow");
1232 //Effect.SlideDown("infoBoxShadow", {duration : 1.0});
1241 exception_error("infobox_callback2", e
);
1245 function createFilter() {
1249 var form
= document
.forms
['filter_add_form'];
1250 var reg_exp
= form
.reg_exp
.value
;
1252 if (reg_exp
== "") {
1253 alert(__("Can't add filter: nothing to match on."));
1257 var query
= Form
.serialize("filter_add_form");
1259 // we can be called from some other tab in Prefs
1260 if (typeof active_tab
!= 'undefined' && active_tab
) {
1261 active_tab
= "filterConfig";
1264 new Ajax
.Request("backend.php?" + query
, {
1265 onComplete: function (transport
) {
1266 infobox_submit_callback2(transport
);
1272 exception_error("createFilter", e
);
1276 function isValidURL(s
) {
1277 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
1280 function subscribeToFeed() {
1284 var form
= document
.forms
['feed_add_form'];
1285 var feed_url
= form
.feed_url
.value
;
1287 if (feed_url
== "") {
1288 alert(__("Can't subscribe: no feed URL given."));
1292 notify_progress(__("Subscribing to feed..."), true);
1294 var query
= Form
.serialize("feed_add_form");
1296 console
.log("subscribe q: " + query
);
1298 Form
.disable("feed_add_form");
1300 new Ajax
.Request("backend.php", {
1302 onComplete: function(transport
) {
1303 //dlg_frefresh_callback(transport);
1307 if (!transport
.responseXML
)
1308 console
.log(transport
.responseText
);
1310 var result
= transport
.responseXML
.getElementsByTagName('result')[0];
1311 var rc
= parseInt(result
.getAttribute('code'));
1313 Form
.enable("feed_add_form");
1320 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
1322 if (inPreferences()) {
1325 setTimeout('updateFeedList(false, false)', 50);
1329 alert(__("Specified URL seems to be invalid."));
1332 alert(__("Specified URL doesn't seem to contain any feeds."));
1335 new Ajax
.Request("backend.php", {
1336 parameters
: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url
),
1337 onComplete: function(transport
) {
1338 var result
= transport
.responseXML
.getElementsByTagName('urls')[0];
1339 var feeds
= JSON
.parse(result
.firstChild
.nodeValue
);
1340 var select
= document
.getElementById("faad_feeds_container_select");
1342 while (select
.hasChildNodes()) {
1343 select
.removeChild(elem
.firstChild
);
1346 for (var feedUrl
in feeds
) {
1347 select
.insert(new Option(feeds
[feedUrl
], feedUrl
, false));
1350 if (count
> 5) count
= 5;
1351 select
.size
= count
;
1353 Effect
.Appear('fadd_feeds_container', {duration
: 0.5});
1358 alert(__("Couldn't download the specified URL."));
1361 alert(__("You are already subscribed to this feed."));
1366 exception_error("subscribeToFeed", e
);
1372 exception_error("subscribeToFeed", e
);
1378 function filterCR(e
, f
)
1383 key
= window
.event
.keyCode
; //IE
1385 key
= e
.which
; //firefox
1388 if (typeof f
!= 'undefined') {
1399 function getInitParam(key
) {
1400 return init_params
[key
];
1403 function setInitParam(key
, value
) {
1404 init_params
[key
] = value
;
1407 function fatalError(code
, msg
, ext_info
) {
1410 if (!ext_info
) ext_info
= "N/A";
1413 window
.location
.href
= "tt-rss.php";
1414 } else if (code
== 5) {
1415 window
.location
.href
= "db-updater.php";
1418 if (msg
== "") msg
= "Unknown error";
1420 var ebc
= $("xebContent");
1424 Element
.show("dialog_overlay");
1425 Element
.show("errorBoxShadow");
1426 Element
.hide("xebBtn");
1429 if (ext_info
.responseText
) {
1430 ext_info
= ext_info
.responseText
;
1435 "<div><b>Error message:</b></div>" +
1436 "<pre>" + msg
+ "</pre>" +
1437 "<div><b>Additional information:</b></div>" +
1438 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
1443 exception_error("fatalError", e
);
1447 function getFeedName(id
, is_cat
) {
1451 e
= $("FCATN-" + id
);
1453 e
= $("FEEDN-" + id
);
1456 return e
.innerHTML
.stripTags();
1462 function filterDlgCheckType(sender
) {
1466 var ftype
= sender
[sender
.selectedIndex
].value
;
1468 var form
= document
.forms
["filter_add_form"];
1471 form
= document
.forms
["filter_edit_form"];
1475 console
.log("filterDlgCheckType: can't find form!");
1479 // if selected filter type is 5 (Date) enable the modifier dropbox
1481 Element
.show("filter_dlg_date_mod_box");
1482 Element
.show("filter_dlg_date_chk_box");
1484 Element
.hide("filter_dlg_date_mod_box");
1485 Element
.hide("filter_dlg_date_chk_box");
1490 exception_error("filterDlgCheckType", e
);
1495 function filterDlgCheckAction(sender
) {
1499 var action
= sender
[sender
.selectedIndex
].value
;
1501 var form
= document
.forms
["filter_add_form"];
1504 form
= document
.forms
["filter_edit_form"];
1508 console
.log("filterDlgCheckAction: can't find form!");
1512 var action_param
= $("filter_dlg_param_box");
1514 if (!action_param
) {
1515 console
.log("filterDlgCheckAction: can't find action param box!");
1519 // if selected action supports parameters, enable params field
1520 if (action
== 4 || action
== 6 || action
== 7) {
1521 Element
.show(action_param
);
1523 Element
.show(form
.action_param
);
1524 Element
.hide(form
.action_param_label
);
1526 Element
.show(form
.action_param_label
);
1527 Element
.hide(form
.action_param
);
1530 Element
.hide(action_param
);
1534 exception_error("filterDlgCheckAction", e
);
1539 function filterDlgCheckDate() {
1541 var form
= document
.forms
["filter_add_form"];
1544 form
= document
.forms
["filter_edit_form"];
1548 console
.log("filterDlgCheckAction: can't find form!");
1552 var reg_exp
= form
.reg_exp
.value
;
1554 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
1556 new Ajax
.Request("backend.php", {
1558 onComplete: function(transport
) {
1560 var form
= document
.forms
["filter_add_form"];
1563 form
= document
.forms
["filter_edit_form"];
1566 if (transport
.responseXML
) {
1567 var result
= transport
.responseXML
.getElementsByTagName("result")[0];
1569 if (result
&& result
.firstChild
) {
1570 if (result
.firstChild
.nodeValue
== "1") {
1572 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#00ff00'});
1579 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#ff0000'});
1585 exception_error("filterDlgCheckDate", e
);
1589 function explainError(code
) {
1590 return displayDlg("explainError", code
);
1593 // this only searches loaded headlines list, not in CDM
1594 function getRelativePostIds(id
, limit
) {
1596 if (!limit
) limit
= 3;
1598 console
.log("getRelativePostIds: " + id
+ " limit=" + limit
);
1600 var ids
= new Array();
1601 var container
= $("headlinesList");
1604 var rows
= container
.rows
;
1606 for (var i
= 0; i
< rows
.length
; i
++) {
1607 var r_id
= rows
[i
].id
.replace("RROW-", "");
1610 for (var k
= 1; k
<= limit
; k
++) {
1613 if (i
> k
-1) var nid
= rows
[i
-k
].id
.replace("RROW-", "");
1614 if (nid
) ids
.push(nid
);
1616 if (i
< rows
.length
-k
) nid
= rows
[i
+k
].id
.replace("RROW-", "");
1617 if (nid
) ids
.push(nid
);
1628 function openArticleInNewWindow(id
) {
1630 console
.log("openArticleInNewWindow: " + id
);
1632 var query
= "?op=rpc&subop=getArticleLink&id=" + id
;
1633 var wname
= "ttrss_article_" + id
;
1635 console
.log(query
+ " " + wname
);
1637 var w
= window
.open("", wname
);
1639 if (!w
) notify_error("Failed to open window for the article");
1641 new Ajax
.Request("backend.php", {
1643 onComplete: function(transport
) {
1645 var link
= transport
.responseXML
.getElementsByTagName("link")[0];
1646 var id
= transport
.responseXML
.getElementsByTagName("id")[0];
1648 console
.log("open_article received link: " + link
);
1652 var wname
= "ttrss_article_" + id
.firstChild
.nodeValue
;
1654 console
.log("link url: " + link
.firstChild
.nodeValue
+ ", wname " + wname
);
1656 var w
= window
.open(link
.firstChild
.nodeValue
, wname
);
1658 if (!w
) { notify_error("Failed to load article in new window"); }
1661 id
= id
.firstChild
.nodeValue
;
1662 if (!$("headlinesList")) {
1663 window
.setTimeout("toggleUnread(" + id
+ ", 0)", 100);
1667 notify_error("Can't open article: received invalid article link");
1672 exception_error("openArticleInNewWindow", e
);
1676 function isCdmMode() {
1677 return !$("headlinesList");
1680 function getSelectedArticleIds2() {
1681 var rows
= new Array();
1682 var cdm_mode
= isCdmMode();
1685 rows
= cdmGetSelectedArticles();
1687 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1690 var ids
= new Array();
1692 for (var i
= 0; i
< rows
.length
; i
++) {
1693 var chk
= $("RCHK-" + rows
[i
]);
1694 if (chk
&& chk
.checked
) {
1702 function displayHelpInfobox(topic_id
) {
1704 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
1706 var w
= window
.open(url
, "ttrss_help",
1707 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
1711 function loading_set_progress(p
) {
1713 if (p
< last_progress_point
|| !Element
.visible("overlay")) return;
1715 console
.log("loading_set_progress : " + p
+ " (" + last_progress_point
+ ")");
1717 var o
= $("l_progress_i");
1719 // o.style.width = (p * 2) + "px";
1721 new Effect
.Scale(o
, p
, {
1723 scaleFrom
: last_progress_point
,
1724 scaleMode
: { originalWidth
: 200 },
1725 queue
: { position
: 'end', scope
: 'LSP-Q', limit
: 3 } });
1727 last_progress_point
= p
;
1730 exception_error("loading_set_progress", e
);
1734 function remove_splash() {
1735 if (Element
.visible("overlay")) {
1736 console
.log("about to remove splash, OMG!");
1737 Element
.hide("overlay");
1738 console
.log("removed splash!");
1742 function getSelectedFeedsFromBrowser() {
1744 var list
= $("browseFeedList");
1746 var selected
= new Array();
1748 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
1749 var child
= list
.childNodes
[i
];
1750 if (child
.id
&& child
.id
.match("FBROW-")) {
1751 var id
= child
.id
.replace("FBROW-", "");
1753 var cb
= $("FBCHK-" + id
);
1764 function updateFeedBrowser() {
1767 var query
= Form
.serialize("feed_browser");
1769 Element
.show('feed_browser_spinner');
1771 new Ajax
.Request("backend.php", {
1773 onComplete: function(transport
) {
1776 Element
.hide('feed_browser_spinner');
1778 var c
= $("browseFeedList");
1779 var r
= transport
.responseXML
.getElementsByTagName("content")[0];
1780 var nr
= transport
.responseXML
.getElementsByTagName("num-results")[0];
1781 var mode
= transport
.responseXML
.getElementsByTagName("mode")[0];
1784 c
.innerHTML
= r
.firstChild
.nodeValue
;
1787 if (parseInt(mode
.getAttribute("value")) == 2) {
1788 Element
.show('feed_archive_remove');
1790 Element
.hide('feed_archive_remove');
1796 exception_error("updateFeedBrowser", e
);
1801 function transport_error_check(transport
) {
1803 if (transport
.responseXML
) {
1804 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
1807 var code
= error
.getAttribute("error-code");
1808 var msg
= error
.getAttribute("error-msg");
1810 fatalError(code
, msg
);
1816 exception_error("check_for_error_xml", e
);
1821 function strip_tags(s
) {
1822 return s
.replace(/<\/?[^>]+(>|$)/g, "");
1825 function truncate_string(s
, length
) {
1826 if (!length
) length
= 30;
1827 var tmp
= s
.substring(0, length
);
1828 if (s
.length
> length
) tmp
+= "…";
1832 function hotkey_prefix_timeout() {
1835 var date
= new Date();
1836 var ts
= Math
.round(date
.getTime() / 1000);
1838 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
1839 console
.log("hotkey_prefix seems to be stuck, aborting");
1840 hotkey_prefix_pressed
= false;
1841 hotkey_prefix
= false;
1842 Element
.hide('cmdline');
1845 setTimeout("hotkey_prefix_timeout()", 1000);
1848 exception_error("hotkey_prefix_timeout", e
);
1852 function hideAuxDlg() {
1854 Element
.hide('auxDlg');
1856 exception_error("hideAuxDlg", e
);
1860 function displayNewContentPrompt(id
) {
1863 var msg
= "<a href='#' onclick='viewfeed("+id
+")'>" +
1864 __("New articles available in this feed (click to show)") + "</a>";
1866 msg
= msg
.replace("%s", getFeedName(id
));
1868 $('auxDlg').innerHTML
= msg
;
1870 new Effect
.Appear('auxDlg', {duration
: 0.5});
1873 exception_error("displayNewContentPrompt", e
);
1877 function feedBrowserSubscribe() {
1880 var selected
= getSelectedFeedsFromBrowser();
1882 var mode
= document
.forms
['feed_browser'].mode
;
1884 mode
= mode
[mode
.selectedIndex
].value
;
1886 if (selected
.length
> 0) {
1889 notify_progress("Loading, please wait...", true);
1891 var query
= "?op=rpc&subop=massSubscribe&ids="+
1892 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1894 new Ajax
.Request("backend.php", {
1896 onComplete: function(transport
) {
1898 var nf
= transport
.responseXML
.getElementsByTagName('num-feeds')[0];
1899 var nf_value
= nf
.getAttribute("value");
1901 notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value
));
1903 if (inPreferences()) {
1906 setTimeout('updateFeedList(false, false)', 50);
1911 alert(__("No feeds are selected."));
1915 exception_error("feedBrowserSubscribe", e
);
1919 function feedArchiveRemove() {
1922 var selected
= getSelectedFeedsFromBrowser();
1924 if (selected
.length
> 0) {
1926 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1929 Element
.show('feed_browser_spinner');
1931 var query
= "?op=rpc&subop=remarchived&ids=" +
1932 param_escape(selected
.toString());;
1934 new Ajax
.Request("backend.php", {
1936 onComplete: function(transport
) {
1937 updateFeedBrowser();
1942 alert(__("No feeds are selected."));
1946 exception_error("feedArchiveRemove", e
);
1950 function uploadIconHandler(rc
) {
1954 notify_info("Upload complete.");
1955 if (inPreferences()) {
1958 setTimeout('updateFeedList(false, false)', 50);
1962 notify_error("Upload failed: icon is too big.");
1965 notify_error("Upload failed.");
1970 exception_error("uploadIconHandler", e
);
1974 function removeFeedIcon(id
) {
1978 if (confirm(__("Remove stored feed icon?"))) {
1979 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
1983 notify_progress("Removing feed icon...", true);
1985 new Ajax
.Request("backend.php", {
1987 onComplete: function(transport
) {
1988 notify_info("Feed icon removed.");
1989 if (inPreferences()) {
1992 setTimeout('updateFeedList(false, false)', 50);
1999 exception_error("uploadFeedIcon", e
);
2003 function uploadFeedIcon() {
2007 var file
= $("icon_file");
2009 if (file
.value
.length
== 0) {
2010 alert(__("Please select an image file to upload."));
2012 if (confirm(__("Upload new icon for this feed?"))) {
2013 notify_progress("Uploading, please wait...", true);
2021 exception_error("uploadFeedIcon", e
);
2025 function addLabel(select
, callback
) {
2029 var caption
= prompt(__("Please enter label caption:"), "");
2031 if (caption
!= undefined) {
2033 if (caption
== "") {
2034 alert(__("Can't create label: missing caption."));
2038 var query
= "?op=pref-labels&subop=add&caption=" +
2039 param_escape(caption
);
2042 query
+= "&output=select";
2044 notify_progress("Loading, please wait...", true);
2046 if (inPreferences() && !select
) active_tab
= "labelConfig";
2048 new Ajax
.Request("backend.php", {
2050 onComplete: function(transport
) {
2052 callback(transport
);
2053 } else if (inPreferences()) {
2054 infobox_submit_callback2(transport
);
2063 exception_error("addLabel", e
);
2067 function quickAddFeed() {
2068 displayDlg('quickAddFeed', '',
2069 function () {$('feed_url').focus();});
2072 function quickAddFilter() {
2073 displayDlg('quickAddFilter', '',
2074 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
2077 function unsubscribeFeed(feed_id
, title
) {
2079 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
2081 if (title
== undefined || confirm(msg
)) {
2082 notify_progress("Removing feed...");
2084 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
2086 new Ajax
.Request("backend.php", {
2088 onComplete: function(transport
) {
2092 if (inPreferences()) {
2095 dlg_frefresh_callback(transport
, feed_id
);
2105 function backend_sanity_check_callback(transport
) {
2109 if (sanity_check_done
) {
2110 fatalError(11, "Sanity check request received twice. This can indicate "+
2111 "presence of Firebug or some other disrupting extension. "+
2112 "Please disable it and try again.");
2116 if (!transport
.responseXML
) {
2118 fatalError(3, "Sanity check: Received reply is not XML",
2119 transport
.responseText
);
2127 if (getURLParam("offline")) {
2128 return init_offline();
2131 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
2134 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
2138 var error_code
= reply
.getAttribute("error-code");
2140 if (error_code
&& error_code
!= 0) {
2141 return fatalError(error_code
, reply
.getAttribute("error-msg"));
2144 console
.log("sanity check ok");
2146 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
2149 console
.log('reading init-params...');
2151 params
= JSON
.parse(params
.firstChild
.nodeValue
);
2154 for (var i
= 0; i
< params
.length
; i
++) {
2156 var k
= params
[i
].param
;
2157 var v
= params
[i
].value
;
2159 if (getURLParam('debug')) console
.log(k
+ " => " + v
);
2163 db
.execute("DELETE FROM init_params WHERE key = ?", [k
]);
2164 db
.execute("INSERT INTO init_params (key,value) VALUES (?, ?)",
2171 sanity_check_done
= true;
2173 init_second_stage();
2176 exception_error("backend_sanity_check_callback", e
, transport
);
2180 function has_local_storage() {
2182 return 'localStorage' in window
&& window
['localStorage'] != null;
2188 function catSelectOnChange(elem
) {
2190 var value
= elem
[elem
.selectedIndex
].value
;
2191 var def
= elem
.getAttribute('default');
2193 if (value
== "ADD_CAT") {
2196 dropboxSelect(elem
, def
);
2198 elem
.selectedIndex
= 0;
2204 exception_error("catSelectOnChange", e
);
2208 function quickAddCat(elem
) {
2210 var cat
= prompt(__("Please enter category title:"));
2214 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
2216 notify_progress("Loading, please wait...", true);
2218 new Ajax
.Request("backend.php", {
2220 onComplete: function (transport
) {
2221 var response
= transport
.responseXML
;
2222 var select
= response
.getElementsByTagName("select")[0];
2223 var options
= select
.getElementsByTagName("option");
2225 dropbox_replace_options(elem
, options
);
2234 exception_error("quickAddCat", e
);
2238 function genUrlChangeKey(feed
, is_cat
) {
2241 var ok
= confirm(__("Generate new syndication address for this feed?"));
2245 notify_progress("Trying to change address...", true);
2247 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
2248 "&is_cat=" + param_escape(is_cat
);
2250 new Ajax
.Request("backend.php", {
2252 onComplete: function(transport
) {
2253 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
2255 var e
= $('gen_feed_url');
2259 new_link
= new_link
.firstChild
.nodeValue
;
2261 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
2262 "&key=" + new_link
);
2264 e
.href
= e
.href
.replace(/\&key=.*$/,
2265 "&key=" + new_link
);
2267 new Effect
.Highlight(e
);
2272 notify_error("Could not change feed URL.");
2277 exception_error("genUrlChangeKey", e
);
2282 function labelSelectOnChange(elem
) {
2284 var value
= elem
[elem
.selectedIndex
].value
;
2285 var def
= elem
.getAttribute('default');
2287 if (value
== "ADD_LABEL") {
2290 dropboxSelect(elem
, def
);
2292 elem
.selectedIndex
= 0;
2294 addLabel(elem
, function(transport
) {
2298 var response
= transport
.responseXML
;
2299 var select
= response
.getElementsByTagName("select")[0];
2300 var options
= select
.getElementsByTagName("option");
2302 dropbox_replace_options(elem
, options
);
2306 exception_error("addLabel", e
);
2312 exception_error("labelSelectOnChange", e
);
2316 function dropbox_replace_options(elem
, options
) {
2319 while (elem
.hasChildNodes())
2320 elem
.removeChild(elem
.firstChild
);
2324 for (var i
= 0; i
< options
.length
; i
++) {
2325 var text
= options
[i
].firstChild
.nodeValue
;
2326 var value
= options
[i
].getAttribute("value");
2328 if (value
== undefined) value
= text
;
2330 var issel
= options
[i
].getAttribute("selected") == "1";
2332 var option
= new Option(text
, value
, issel
);
2334 if (options
[i
].getAttribute("disabled"))
2335 option
.setAttribute("disabled", true);
2337 elem
.insert(option
);
2339 if (issel
) sel_idx
= i
;
2342 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
2343 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
2346 exception_error("dropbox_replace_options", e
);