]>
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 var notify_hide_timerid
= false;
112 function hide_notify() {
115 n
.style
.display
= "none";
119 function notify_silent_next() {
120 notify_silent
= true;
123 function notify_real(msg
, no_hide
, n_type
) {
126 notify_silent
= false;
131 var nb
= $("notify_body");
133 if (!n
|| !nb
) return;
135 if (notify_hide_timerid
) {
136 window
.clearTimeout(notify_hide_timerid
);
140 if (n
.style
.display
== "block") {
141 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
145 n
.style
.display
= "block";
157 if (typeof __
!= 'undefined') {
162 n
.className
= "notify";
163 } else if (n_type
== 2) {
164 n
.className
= "notifyProgress";
165 msg
= "<img src='"+getInitParam("sign_progress")+"'> " + msg
;
166 } else if (n_type
== 3) {
167 n
.className
= "notifyError";
168 msg
= "<img src='"+getInitParam("sign_excl")+"'> " + msg
;
169 } else if (n_type
== 4) {
170 n
.className
= "notifyInfo";
171 msg
= "<img src='"+getInitParam("sign_info")+"'> " + msg
;
174 // msg = "<img src='images/live_com_loading.gif'> " + msg;
179 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
183 function notify(msg
, no_hide
) {
184 notify_real(msg
, no_hide
, 1);
187 function notify_progress(msg
, no_hide
) {
188 notify_real(msg
, no_hide
, 2);
191 function notify_error(msg
, no_hide
) {
192 notify_real(msg
, no_hide
, 3);
196 function notify_info(msg
, no_hide
) {
197 notify_real(msg
, no_hide
, 4);
200 function cleanSelected(element
) {
201 var content
= $(element
);
203 for (i
= 0; i
< content
.rows
.length
; i
++) {
204 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
208 function getVisibleUnreadHeadlines() {
209 var content
= $("headlinesList");
211 var rows
= new Array();
213 if (!content
) return rows
;
215 for (i
= 0; i
< content
.rows
.length
; i
++) {
216 var row_id
= content
.rows
[i
].id
.replace("RROW-", "");
217 if (row_id
.length
> 0 && content
.rows
[i
].className
.match("Unread")) {
224 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
230 d
.setTime(d
.getTime() + (lifetime
* 1000));
233 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
235 int_setCookie(name
, value
, d
, path
, domain
, secure
);
239 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
240 document
.cookie
= name
+ "=" + escape(value
) +
241 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
242 ((path
) ? "; path=" + path
: "") +
243 ((domain
) ? "; domain=" + domain
: "") +
244 ((secure
) ? "; secure" : "");
247 function delCookie(name
, path
, domain
) {
248 if (getCookie(name
)) {
249 document
.cookie
= name
+ "=" +
250 ((path
) ? ";path=" + path
: "") +
251 ((domain
) ? ";domain=" + domain
: "" ) +
252 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
257 function getCookie(name
) {
259 var dc
= document
.cookie
;
260 var prefix
= name
+ "=";
261 var begin
= dc
.indexOf("; " + prefix
);
263 begin
= dc
.indexOf(prefix
);
264 if (begin
!= 0) return null;
269 var end
= document
.cookie
.indexOf(";", begin
);
273 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
276 function gotoPreferences() {
277 document
.location
.href
= "prefs.php";
280 function gotoMain() {
281 document
.location
.href
= "tt-rss.php";
284 function gotoExportOpml() {
285 document
.location
.href
= "opml.php?op=Export";
289 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
290 * * @author Sundar Dorai-Raj
291 * * Email: sdoraira@vt.edu
292 * * This program is free software; you can redistribute it and/or
293 * * modify it under the terms of the GNU General Public License
294 * * as published by the Free Software Foundation; either version 2
295 * * of the License, or (at your option) any later version,
296 * * provided that any use properly credits the author.
297 * * This program is distributed in the hope that it will be useful,
298 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
299 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
300 * * GNU General Public License for more details at http://www.gnu.org * * */
302 var numbers
=".0123456789";
303 function isNumeric(x
) {
304 // is x a String or a character?
306 // remove negative sign
308 for(j
=0;j
<x
.length
;j
++) {
309 // call isNumeric recursively for each character
310 number
=isNumeric(x
.substring(j
,j
+1));
311 if(!number
) return number
;
316 // if x is number return true
317 if(numbers
.indexOf(x
)>=0) return true;
323 function toggleSelectRowById(sender
, id
) {
326 if (sender
.checked
) {
327 if (!row
.className
.match("Selected")) {
328 row
.className
= row
.className
+ "Selected";
331 if (row
.className
.match("Selected")) {
332 row
.className
= row
.className
.replace("Selected", "");
337 function toggleSelectListRow(sender
) {
338 var parent_row
= sender
.parentNode
;
340 if (sender
.checked
) {
341 if (!parent_row
.className
.match("Selected")) {
342 parent_row
.className
= parent_row
.className
+ "Selected";
345 if (parent_row
.className
.match("Selected")) {
346 parent_row
.className
= parent_row
.className
.replace("Selected", "");
351 function tSR(sender
) {
352 return toggleSelectRow(sender
);
355 function toggleSelectRow(sender
) {
356 var parent_row
= sender
.parentNode
.parentNode
;
358 if (sender
.checked
) {
359 if (!parent_row
.className
.match("Selected")) {
360 parent_row
.className
= parent_row
.className
+ "Selected";
363 if (parent_row
.className
.match("Selected")) {
364 parent_row
.className
= parent_row
.className
.replace("Selected", "");
369 function checkboxToggleElement(elem
, id
) {
371 Effect
.Appear(id
, {duration
: 0.5});
373 Effect
.Fade(id
, {duration
: 0.5});
377 function dropboxSelect(e
, v
) {
378 for (i
= 0; i
< e
.length
; i
++) {
379 if (e
[i
].value
== v
) {
386 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
387 // bugfixed just a little bit :-)
388 function getURLParam(strParamName
){
390 var strHref
= window
.location
.href
;
392 if (strHref
.indexOf("#") == strHref
.length
-1) {
393 strHref
= strHref
.substring(0, strHref
.length
-1);
396 if ( strHref
.indexOf("?") > -1 ){
397 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
398 var aQueryString
= strQueryString
.split("&");
399 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
400 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
401 var aParam
= aQueryString
[iParam
].split("=");
402 strReturn
= aParam
[1];
410 function leading_zero(p
) {
412 if (s
.length
== 1) s
= "0" + s
;
416 function make_timestamp() {
419 return leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
420 ":" + leading_zero(d
.getSeconds());
424 function closeErrorBox() {
426 if (Element
.visible("errorBoxShadow")) {
427 Element
.hide("dialog_overlay");
428 Element
.hide("errorBoxShadow");
436 function closeInfoBox(cleanup
) {
441 if (Element
.visible("infoBoxShadow")) {
442 Element
.hide("dialog_overlay");
443 Element
.hide("infoBoxShadow");
445 if (cleanup
) $("infoBox").innerHTML
= " ";
448 exception_error("closeInfoBox", e
);
455 function displayDlg(id
, param
, callback
) {
457 notify_progress("Loading, please wait...", true);
461 var query
= "?op=dlg&id=" +
462 param_escape(id
) + "¶m=" + param_escape(param
);
464 new Ajax
.Request("backend.php", {
466 onComplete: function (transport
) {
467 infobox_callback2(transport
);
468 if (callback
) callback(transport
);
474 function infobox_submit_callback2(transport
) {
478 // called from prefs, reload tab
479 if (typeof active_tab
!= 'undefined' && active_tab
) {
480 selectTab(active_tab
, false);
484 if (transport
.responseText
) {
485 notify_info(transport
.responseText
);
489 function infobox_callback2(transport
) {
492 console
.log("infobox_callback2");
494 var box
= $('infoBox');
498 if (!getInitParam("infobox_disable_overlay")) {
499 Element
.show("dialog_overlay");
502 box
.innerHTML
=transport
.responseText
;
503 Element
.show("infoBoxShadow");
504 //Effect.SlideDown("infoBoxShadow", {duration : 1.0});
513 exception_error("infobox_callback2", e
);
517 function createFilter() {
521 var form
= document
.forms
['filter_add_form'];
522 var reg_exp
= form
.reg_exp
.value
;
525 alert(__("Can't add filter: nothing to match on."));
529 var query
= "?op=rpc&subop=verifyRegexp®_exp=" + param_escape(reg_exp
);
531 notify_progress("Verifying regular expression...");
533 new Ajax
.Request("backend.php", {
535 onComplete: function(transport
) {
536 handle_rpc_reply(transport
);
538 var response
= transport
.responseXML
;
541 var s
= response
.getElementsByTagName("status")[0].firstChild
.nodeValue
;
545 if (s
== "INVALID") {
546 alert("Match regular expression seems to be invalid.");
550 var query
= Form
.serialize("filter_add_form");
552 // we can be called from some other tab in Prefs
553 if (typeof active_tab
!= 'undefined' && active_tab
) {
554 active_tab
= "filterConfig";
557 new Ajax
.Request("backend.php?" + query
, {
558 onComplete: function (transport
) {
559 infobox_submit_callback2(transport
);
569 exception_error("createFilter", e
);
573 function isValidURL(s
) {
574 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
577 function subscribeToFeed() {
581 var form
= document
.forms
['feed_add_form'];
582 var feed_url
= form
.feed_url
.value
;
584 if (feed_url
== "") {
585 alert(__("Can't subscribe: no feed URL given."));
589 notify_progress(__("Subscribing to feed..."), true);
591 var query
= Form
.serialize("feed_add_form");
593 console
.log("subscribe q: " + query
);
595 Form
.disable("feed_add_form");
597 new Ajax
.Request("backend.php", {
599 onComplete: function(transport
) {
600 //dlg_frefresh_callback(transport);
604 if (!transport
.responseXML
)
605 console
.log(transport
.responseText
);
607 var result
= transport
.responseXML
.getElementsByTagName('result')[0];
608 var rc
= parseInt(result
.getAttribute('code'));
610 Form
.enable("feed_add_form");
617 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
619 if (inPreferences()) {
622 setTimeout('updateFeedList(false, false)', 50);
626 alert(__("Specified URL seems to be invalid."));
629 alert(__("Specified URL doesn't seem to contain any feeds."));
632 new Ajax
.Request("backend.php", {
633 parameters
: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url
),
634 onComplete: function(transport
) {
635 var result
= transport
.responseXML
.getElementsByTagName('urls')[0];
636 var feeds
= JSON
.parse(result
.firstChild
.nodeValue
);
637 var select
= document
.getElementById("faad_feeds_container_select");
639 while (select
.hasChildNodes()) {
640 select
.removeChild(elem
.firstChild
);
643 for (var feedUrl
in feeds
) {
644 select
.insert(new Option(feeds
[feedUrl
], feedUrl
, false));
647 if (count
> 5) count
= 5;
650 Effect
.Appear('fadd_feeds_container', {duration
: 0.5});
655 alert(__("Couldn't download the specified URL."));
658 alert(__("You are already subscribed to this feed."));
663 exception_error("subscribeToFeed", e
);
669 exception_error("subscribeToFeed", e
);
675 function filterCR(e
, f
)
680 key
= window
.event
.keyCode
; //IE
682 key
= e
.which
; //firefox
685 if (typeof f
!= 'undefined') {
696 function getInitParam(key
) {
697 return init_params
[key
];
700 function setInitParam(key
, value
) {
701 init_params
[key
] = value
;
704 function fatalError(code
, msg
, ext_info
) {
707 if (!ext_info
) ext_info
= "N/A";
710 window
.location
.href
= "tt-rss.php";
711 } else if (code
== 5) {
712 window
.location
.href
= "db-updater.php";
715 if (msg
== "") msg
= "Unknown error";
717 var ebc
= $("xebContent");
721 Element
.show("dialog_overlay");
722 Element
.show("errorBoxShadow");
723 Element
.hide("xebBtn");
726 if (ext_info
.responseText
) {
727 ext_info
= ext_info
.responseText
;
732 "<div><b>Error message:</b></div>" +
733 "<pre>" + msg
+ "</pre>" +
734 "<div><b>Additional information:</b></div>" +
735 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
740 exception_error("fatalError", e
);
744 function filterDlgCheckType(sender
) {
748 var ftype
= sender
[sender
.selectedIndex
].value
;
750 var form
= document
.forms
["filter_add_form"];
753 form
= document
.forms
["filter_edit_form"];
757 console
.log("filterDlgCheckType: can't find form!");
761 // if selected filter type is 5 (Date) enable the modifier dropbox
763 Element
.show("filter_dlg_date_mod_box");
764 Element
.show("filter_dlg_date_chk_box");
766 Element
.hide("filter_dlg_date_mod_box");
767 Element
.hide("filter_dlg_date_chk_box");
772 exception_error("filterDlgCheckType", e
);
777 function filterDlgCheckAction(sender
) {
781 var action
= sender
[sender
.selectedIndex
].value
;
783 var form
= document
.forms
["filter_add_form"];
786 form
= document
.forms
["filter_edit_form"];
790 console
.log("filterDlgCheckAction: can't find form!");
794 var action_param
= $("filter_dlg_param_box");
797 console
.log("filterDlgCheckAction: can't find action param box!");
801 // if selected action supports parameters, enable params field
802 if (action
== 4 || action
== 6 || action
== 7) {
803 Element
.show(action_param
);
805 Element
.show(form
.action_param
);
806 Element
.hide(form
.action_param_label
);
808 Element
.show(form
.action_param_label
);
809 Element
.hide(form
.action_param
);
812 Element
.hide(action_param
);
816 exception_error("filterDlgCheckAction", e
);
821 function filterDlgCheckDate() {
823 var form
= document
.forms
["filter_add_form"];
826 form
= document
.forms
["filter_edit_form"];
830 console
.log("filterDlgCheckAction: can't find form!");
834 var reg_exp
= form
.reg_exp
.value
;
836 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
838 new Ajax
.Request("backend.php", {
840 onComplete: function(transport
) {
842 var form
= document
.forms
["filter_add_form"];
845 form
= document
.forms
["filter_edit_form"];
848 if (transport
.responseXML
) {
849 var result
= transport
.responseXML
.getElementsByTagName("result")[0];
851 if (result
&& result
.firstChild
) {
852 if (result
.firstChild
.nodeValue
== "1") {
854 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#00ff00'});
861 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#ff0000'});
867 exception_error("filterDlgCheckDate", e
);
871 function explainError(code
) {
872 return displayDlg("explainError", code
);
875 function displayHelpInfobox(topic_id
) {
877 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
879 var w
= window
.open(url
, "ttrss_help",
880 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
884 function loading_set_progress(p
) {
886 if (p
< last_progress_point
|| !Element
.visible("overlay")) return;
888 console
.log("loading_set_progress : " + p
+ " (" + last_progress_point
+ ")");
890 var o
= $("l_progress_i");
892 // o.style.width = (p * 2) + "px";
894 new Effect
.Scale(o
, p
, {
896 scaleFrom
: last_progress_point
,
897 scaleMode
: { originalWidth
: 200 },
898 queue
: { position
: 'end', scope
: 'LSP-Q', limit
: 3 } });
900 last_progress_point
= p
;
903 exception_error("loading_set_progress", e
);
907 function remove_splash() {
908 if (Element
.visible("overlay")) {
909 console
.log("about to remove splash, OMG!");
910 Element
.hide("overlay");
911 console
.log("removed splash!");
915 function getSelectedFeedsFromBrowser() {
917 var list
= $("browseFeedList");
919 var selected
= new Array();
921 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
922 var child
= list
.childNodes
[i
];
923 if (child
.id
&& child
.id
.match("FBROW-")) {
924 var id
= child
.id
.replace("FBROW-", "");
926 var cb
= $("FBCHK-" + id
);
937 function updateFeedBrowser() {
940 var query
= Form
.serialize("feed_browser");
942 Element
.show('feed_browser_spinner');
944 new Ajax
.Request("backend.php", {
946 onComplete: function(transport
) {
949 Element
.hide('feed_browser_spinner');
951 var c
= $("browseFeedList");
952 var r
= transport
.responseXML
.getElementsByTagName("content")[0];
953 var nr
= transport
.responseXML
.getElementsByTagName("num-results")[0];
954 var mode
= transport
.responseXML
.getElementsByTagName("mode")[0];
957 c
.innerHTML
= r
.firstChild
.nodeValue
;
960 if (parseInt(mode
.getAttribute("value")) == 2) {
961 Element
.show('feed_archive_remove');
963 Element
.hide('feed_archive_remove');
969 exception_error("updateFeedBrowser", e
);
974 function transport_error_check(transport
) {
976 if (transport
.responseXML
) {
977 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
980 var code
= error
.getAttribute("error-code");
981 var msg
= error
.getAttribute("error-msg");
983 fatalError(code
, msg
);
989 exception_error("check_for_error_xml", e
);
994 function strip_tags(s
) {
995 return s
.replace(/<\/?[^>]+(>|$)/g, "");
998 function truncate_string(s
, length
) {
999 if (!length
) length
= 30;
1000 var tmp
= s
.substring(0, length
);
1001 if (s
.length
> length
) tmp
+= "…";
1005 function hotkey_prefix_timeout() {
1008 var date
= new Date();
1009 var ts
= Math
.round(date
.getTime() / 1000);
1011 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
1012 console
.log("hotkey_prefix seems to be stuck, aborting");
1013 hotkey_prefix_pressed
= false;
1014 hotkey_prefix
= false;
1015 Element
.hide('cmdline');
1018 setTimeout("hotkey_prefix_timeout()", 1000);
1021 exception_error("hotkey_prefix_timeout", e
);
1025 function hideAuxDlg() {
1027 Element
.hide('auxDlg');
1029 exception_error("hideAuxDlg", e
);
1033 function feedBrowserSubscribe() {
1036 var selected
= getSelectedFeedsFromBrowser();
1038 var mode
= document
.forms
['feed_browser'].mode
;
1040 mode
= mode
[mode
.selectedIndex
].value
;
1042 if (selected
.length
> 0) {
1045 notify_progress("Loading, please wait...", true);
1047 var query
= "?op=rpc&subop=massSubscribe&ids="+
1048 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1050 new Ajax
.Request("backend.php", {
1052 onComplete: function(transport
) {
1054 var nf
= transport
.responseXML
.getElementsByTagName('num-feeds')[0];
1055 var nf_value
= nf
.getAttribute("value");
1057 notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value
));
1059 if (inPreferences()) {
1062 setTimeout('updateFeedList(false, false)', 50);
1067 alert(__("No feeds are selected."));
1071 exception_error("feedBrowserSubscribe", e
);
1075 function feedArchiveRemove() {
1078 var selected
= getSelectedFeedsFromBrowser();
1080 if (selected
.length
> 0) {
1082 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1085 Element
.show('feed_browser_spinner');
1087 var query
= "?op=rpc&subop=remarchived&ids=" +
1088 param_escape(selected
.toString());;
1090 new Ajax
.Request("backend.php", {
1092 onComplete: function(transport
) {
1093 updateFeedBrowser();
1098 alert(__("No feeds are selected."));
1102 exception_error("feedArchiveRemove", e
);
1106 function uploadIconHandler(rc
) {
1110 notify_info("Upload complete.");
1111 if (inPreferences()) {
1114 setTimeout('updateFeedList(false, false)', 50);
1118 notify_error("Upload failed: icon is too big.");
1121 notify_error("Upload failed.");
1126 exception_error("uploadIconHandler", e
);
1130 function removeFeedIcon(id
) {
1134 if (confirm(__("Remove stored feed icon?"))) {
1135 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
1139 notify_progress("Removing feed icon...", true);
1141 new Ajax
.Request("backend.php", {
1143 onComplete: function(transport
) {
1144 notify_info("Feed icon removed.");
1145 if (inPreferences()) {
1148 setTimeout('updateFeedList(false, false)', 50);
1155 exception_error("uploadFeedIcon", e
);
1159 function uploadFeedIcon() {
1163 var file
= $("icon_file");
1165 if (file
.value
.length
== 0) {
1166 alert(__("Please select an image file to upload."));
1168 if (confirm(__("Upload new icon for this feed?"))) {
1169 notify_progress("Uploading, please wait...", true);
1177 exception_error("uploadFeedIcon", e
);
1181 function addLabel(select
, callback
) {
1185 var caption
= prompt(__("Please enter label caption:"), "");
1187 if (caption
!= undefined) {
1189 if (caption
== "") {
1190 alert(__("Can't create label: missing caption."));
1194 var query
= "?op=pref-labels&subop=add&caption=" +
1195 param_escape(caption
);
1198 query
+= "&output=select";
1200 notify_progress("Loading, please wait...", true);
1202 if (inPreferences() && !select
) active_tab
= "labelConfig";
1204 new Ajax
.Request("backend.php", {
1206 onComplete: function(transport
) {
1208 callback(transport
);
1209 } else if (inPreferences()) {
1210 infobox_submit_callback2(transport
);
1219 exception_error("addLabel", e
);
1223 function quickAddFeed() {
1224 displayDlg('quickAddFeed', '',
1225 function () {$('feed_url').focus();});
1228 function quickAddFilter() {
1229 displayDlg('quickAddFilter', '',
1230 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
1233 function unsubscribeFeed(feed_id
, title
) {
1235 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1237 if (title
== undefined || confirm(msg
)) {
1238 notify_progress("Removing feed...");
1240 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1242 new Ajax
.Request("backend.php", {
1244 onComplete: function(transport
) {
1248 if (inPreferences()) {
1251 dlg_frefresh_callback(transport
, feed_id
);
1261 function backend_sanity_check_callback(transport
) {
1265 if (sanity_check_done
) {
1266 fatalError(11, "Sanity check request received twice. This can indicate "+
1267 "presence of Firebug or some other disrupting extension. "+
1268 "Please disable it and try again.");
1272 if (!transport
.responseXML
) {
1274 fatalError(3, "Sanity check: Received reply is not XML",
1275 transport
.responseText
);
1283 if (getURLParam("offline")) {
1284 return init_offline();
1287 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1290 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1294 var error_code
= reply
.getAttribute("error-code");
1296 if (error_code
&& error_code
!= 0) {
1297 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1300 console
.log("sanity check ok");
1302 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1305 console
.log('reading init-params...');
1307 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1314 console
.log("IP: " + k
+ " => " + v
);
1317 db
.execute("DELETE FROM init_params WHERE key = ?", [k
]);
1318 db
.execute("INSERT INTO init_params (key,value) VALUES (?, ?)",
1324 init_params
= params
;
1327 sanity_check_done
= true;
1329 init_second_stage();
1332 exception_error("backend_sanity_check_callback", e
, transport
);
1336 function has_local_storage() {
1339 return 'localStorage' in window && window['localStorage'] != null;
1345 function catSelectOnChange(elem
) {
1347 var value
= elem
[elem
.selectedIndex
].value
;
1348 var def
= elem
.getAttribute('default');
1350 if (value
== "ADD_CAT") {
1353 dropboxSelect(elem
, def
);
1355 elem
.selectedIndex
= 0;
1361 exception_error("catSelectOnChange", e
);
1365 function quickAddCat(elem
) {
1367 var cat
= prompt(__("Please enter category title:"));
1371 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1373 notify_progress("Loading, please wait...", true);
1375 new Ajax
.Request("backend.php", {
1377 onComplete: function (transport
) {
1378 var response
= transport
.responseXML
;
1379 var select
= response
.getElementsByTagName("select")[0];
1380 var options
= select
.getElementsByTagName("option");
1382 dropbox_replace_options(elem
, options
);
1391 exception_error("quickAddCat", e
);
1395 function genUrlChangeKey(feed
, is_cat
) {
1398 var ok
= confirm(__("Generate new syndication address for this feed?"));
1402 notify_progress("Trying to change address...", true);
1404 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1405 "&is_cat=" + param_escape(is_cat
);
1407 new Ajax
.Request("backend.php", {
1409 onComplete: function(transport
) {
1410 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
1412 var e
= $('gen_feed_url');
1416 new_link
= new_link
.firstChild
.nodeValue
;
1418 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1419 "&key=" + new_link
);
1421 e
.href
= e
.href
.replace(/\&key=.*$/,
1422 "&key=" + new_link
);
1424 new Effect
.Highlight(e
);
1429 notify_error("Could not change feed URL.");
1434 exception_error("genUrlChangeKey", e
);
1439 function labelSelectOnChange(elem
) {
1441 var value
= elem
[elem
.selectedIndex
].value
;
1442 var def
= elem
.getAttribute('default');
1444 if (value
== "ADD_LABEL") {
1447 dropboxSelect(elem
, def
);
1449 elem
.selectedIndex
= 0;
1451 addLabel(elem
, function(transport
) {
1455 var response
= transport
.responseXML
;
1456 var select
= response
.getElementsByTagName("select")[0];
1457 var options
= select
.getElementsByTagName("option");
1459 dropbox_replace_options(elem
, options
);
1463 exception_error("addLabel", e
);
1469 exception_error("labelSelectOnChange", e
);
1473 function dropbox_replace_options(elem
, options
) {
1476 while (elem
.hasChildNodes())
1477 elem
.removeChild(elem
.firstChild
);
1481 for (var i
= 0; i
< options
.length
; i
++) {
1482 var text
= options
[i
].firstChild
.nodeValue
;
1483 var value
= options
[i
].getAttribute("value");
1485 if (value
== undefined) value
= text
;
1487 var issel
= options
[i
].getAttribute("selected") == "1";
1489 var option
= new Option(text
, value
, issel
);
1491 if (options
[i
].getAttribute("disabled"))
1492 option
.setAttribute("disabled", true);
1494 elem
.insert(option
);
1496 if (issel
) sel_idx
= i
;
1499 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1500 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1503 exception_error("dropbox_replace_options", e
);
1507 // mode = all, none, invert
1508 function selectTableRows(id
, mode
) {
1510 var rows
= $(id
).rows
;
1512 for (var i
= 0; i
< rows
.length
; i
++) {
1516 if (row
.id
&& row
.className
) {
1517 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1518 var inputs
= rows
[i
].getElementsByTagName("input");
1520 for (var j
= 0; j
< inputs
.length
; j
++) {
1521 var input
= inputs
[j
];
1523 if (input
.getAttribute("type") == "checkbox" &&
1524 input
.id
.match(bare_id
)) {
1532 var issel
= row
.className
.match("Selected");
1534 if (mode
== "all" && !issel
) {
1535 row
.className
+= "Selected";
1537 } else if (mode
== "none" && issel
) {
1538 row
.className
= row
.className
.replace("Selected", "");
1540 } else if (mode
== "invert") {
1543 row
.className
= row
.className
.replace("Selected", "");
1546 row
.className
+= "Selected";
1555 exception_error("selectTableRows", e
);
1560 function getSelectedTableRowIds(id
) {
1564 var elem_rows
= $(id
).rows
;
1566 for (i
= 0; i
< elem_rows
.length
; i
++) {
1567 if (elem_rows
[i
].className
.match("Selected")) {
1568 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1574 exception_error("getSelectedTableRowIds", e
);