]>
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;
31 if (ext_info
.responseText
) {
32 ext_info
= ext_info
.responseText
;
36 var content
= "<div class=\"fatalError\">" +
37 "<pre>" + msg
+ "</pre>";
40 content
+= "<div><b>Additional information:</b></div>" +
41 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
44 content
+= "<div><b>Stack trace:</b></div>" +
45 "<textarea readonly=\"1\">" + e
.stack
+ "</textarea>";
47 content
+= "<div style='text-align : center'>" +
48 "<button onclick=\"closeInfoBox()\">" +
49 "Close this window" + "</button></div>";
51 // TODO: add code to automatically report errors to tt-rss.org
53 Modalbox
.show(content
, {title
: "Unhandled exception", width
: 600,
54 resizeDuration
: 0, transitions
: false});
62 function format_exception_error(location
, e
) {
66 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
68 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
69 "\nFunction: " + location
+ "()" +
70 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
72 } else if (e
.description
) {
73 msg
= "Exception: " + e
.description
+ "\nFunction: " + location
+ "()";
75 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
78 console
.error("EXCEPTION: " + msg
);
84 function disableHotkeys() {
85 hotkeys_enabled
= false;
88 function enableHotkeys() {
89 hotkeys_enabled
= true;
92 function param_escape(arg
) {
93 if (typeof encodeURIComponent
!= 'undefined')
94 return encodeURIComponent(arg
);
99 function param_unescape(arg
) {
100 if (typeof decodeURIComponent
!= 'undefined')
101 return decodeURIComponent(arg
);
103 return unescape(arg
);
106 var notify_hide_timerid
= false;
108 function hide_notify() {
111 n
.style
.display
= "none";
115 function notify_silent_next() {
116 notify_silent
= true;
119 function notify_real(msg
, no_hide
, n_type
) {
122 notify_silent
= false;
127 var nb
= $("notify_body");
129 if (!n
|| !nb
) return;
131 if (notify_hide_timerid
) {
132 window
.clearTimeout(notify_hide_timerid
);
136 if (n
.style
.display
== "block") {
137 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
141 n
.style
.display
= "block";
153 if (typeof __
!= 'undefined') {
158 n
.className
= "notify";
159 } else if (n_type
== 2) {
160 n
.className
= "notifyProgress";
161 msg
= "<img src='"+getInitParam("sign_progress")+"'> " + msg
;
162 } else if (n_type
== 3) {
163 n
.className
= "notifyError";
164 msg
= "<img src='"+getInitParam("sign_excl")+"'> " + msg
;
165 } else if (n_type
== 4) {
166 n
.className
= "notifyInfo";
167 msg
= "<img src='"+getInitParam("sign_info")+"'> " + msg
;
170 // msg = "<img src='images/live_com_loading.gif'> " + msg;
175 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
179 function notify(msg
, no_hide
) {
180 notify_real(msg
, no_hide
, 1);
183 function notify_progress(msg
, no_hide
) {
184 notify_real(msg
, no_hide
, 2);
187 function notify_error(msg
, no_hide
) {
188 notify_real(msg
, no_hide
, 3);
192 function notify_info(msg
, no_hide
) {
193 notify_real(msg
, no_hide
, 4);
196 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
202 d
.setTime(d
.getTime() + (lifetime
* 1000));
205 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
207 int_setCookie(name
, value
, d
, path
, domain
, secure
);
211 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
212 document
.cookie
= name
+ "=" + escape(value
) +
213 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
214 ((path
) ? "; path=" + path
: "") +
215 ((domain
) ? "; domain=" + domain
: "") +
216 ((secure
) ? "; secure" : "");
219 function delCookie(name
, path
, domain
) {
220 if (getCookie(name
)) {
221 document
.cookie
= name
+ "=" +
222 ((path
) ? ";path=" + path
: "") +
223 ((domain
) ? ";domain=" + domain
: "" ) +
224 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
229 function getCookie(name
) {
231 var dc
= document
.cookie
;
232 var prefix
= name
+ "=";
233 var begin
= dc
.indexOf("; " + prefix
);
235 begin
= dc
.indexOf(prefix
);
236 if (begin
!= 0) return null;
241 var end
= document
.cookie
.indexOf(";", begin
);
245 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
248 function gotoPreferences() {
249 document
.location
.href
= "prefs.php";
252 function gotoMain() {
253 document
.location
.href
= "tt-rss.php";
256 function gotoExportOpml() {
257 document
.location
.href
= "opml.php?op=Export";
261 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
262 * * @author Sundar Dorai-Raj
263 * * Email: sdoraira@vt.edu
264 * * This program is free software; you can redistribute it and/or
265 * * modify it under the terms of the GNU General Public License
266 * * as published by the Free Software Foundation; either version 2
267 * * of the License, or (at your option) any later version,
268 * * provided that any use properly credits the author.
269 * * This program is distributed in the hope that it will be useful,
270 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
271 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
272 * * GNU General Public License for more details at http://www.gnu.org * * */
274 var numbers
=".0123456789";
275 function isNumeric(x
) {
276 // is x a String or a character?
278 // remove negative sign
280 for(j
=0;j
<x
.length
;j
++) {
281 // call isNumeric recursively for each character
282 number
=isNumeric(x
.substring(j
,j
+1));
283 if(!number
) return number
;
288 // if x is number return true
289 if(numbers
.indexOf(x
)>=0) return true;
295 function toggleSelectRowById(sender
, id
) {
297 return toggleSelectRow(sender
, row
);
300 function toggleSelectListRow(sender
) {
301 var row
= sender
.parentNode
;
302 return toggleSelectRow(sender
, row
);
305 function tSR(sender
, row
) {
306 return toggleSelectRow(sender
, row
);
309 function toggleSelectRow(sender
, row
) {
311 if (!row
) row
= sender
.parentNode
.parentNode
;
313 if (sender
.checked
&& !row
.hasClassName('Selected'))
314 row
.addClassName('Selected');
316 row
.removeClassName('Selected');
319 function checkboxToggleElement(elem
, id
) {
321 Effect
.Appear(id
, {duration
: 0.5,
322 afterSetup: function() {
323 Modalbox
.resizeToContent();
326 Effect
.Fade(id
, {duration
: 0.5});
330 function dropboxSelect(e
, v
) {
331 for (i
= 0; i
< e
.length
; i
++) {
332 if (e
[i
].value
== v
) {
339 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
340 // bugfixed just a little bit :-)
341 function getURLParam(strParamName
){
343 var strHref
= window
.location
.href
;
345 if (strHref
.indexOf("#") == strHref
.length
-1) {
346 strHref
= strHref
.substring(0, strHref
.length
-1);
349 if ( strHref
.indexOf("?") > -1 ){
350 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
351 var aQueryString
= strQueryString
.split("&");
352 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
353 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
354 var aParam
= aQueryString
[iParam
].split("=");
355 strReturn
= aParam
[1];
363 function leading_zero(p
) {
365 if (s
.length
== 1) s
= "0" + s
;
369 function make_timestamp() {
372 return leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
373 ":" + leading_zero(d
.getSeconds());
377 function closeErrorBox() {
379 if (Element
.visible("errorBoxShadow")) {
380 Element
.hide("dialog_overlay");
381 Element
.hide("errorBoxShadow");
389 function closeInfoBox(cleanup
) {
396 //exception_error("closeInfoBox", e);
402 function displayDlg(id
, param
, callback
) {
405 notify_progress("Loading, please wait...", true);
407 var query
= "?op=dlg&id=" +
408 param_escape(id
) + "¶m=" + param_escape(param
);
410 new Ajax
.Request("backend.php", {
412 onComplete: function (transport
) {
413 infobox_callback2(transport
);
414 if (callback
) callback(transport
);
420 function infobox_submit_callback2(transport
) {
424 // called from prefs, reload tab
425 if (typeof active_tab
!= 'undefined' && active_tab
) {
426 selectTab(active_tab
, false);
430 if (transport
.responseText
) {
431 notify_info(transport
.responseText
);
435 function infobox_callback2(transport
) {
438 //console.log("infobox_callback2");
442 var dtitle
= "Dialog";
444 if (transport
.responseXML
) {
445 var dlg
= transport
.responseXML
.getElementsByTagName("dlg")[0];
447 var title
= transport
.responseXML
.getElementsByTagName("title")[0];
449 dtitle
= title
.firstChild
.nodeValue
;
451 var content
= transport
.responseXML
.getElementsByTagName("content")[0];
453 content
= content
.firstChild
.nodeValue
;
456 content
= transport
.responseText
;
459 Modalbox
.show(content
, {title
: dtitle
, width
: 600,
460 transitions
: true, resizeDuration
: 0 });
466 exception_error("infobox_callback2", e
);
470 function createFilter() {
474 var form
= document
.forms
['filter_add_form'];
475 var reg_exp
= form
.reg_exp
.value
;
478 alert(__("Can't add filter: nothing to match on."));
482 var query
= "?op=rpc&subop=verifyRegexp®_exp=" + param_escape(reg_exp
);
484 notify_progress("Verifying regular expression...");
486 new Ajax
.Request("backend.php", {
488 onComplete: function(transport
) {
489 handle_rpc_reply(transport
);
491 var response
= transport
.responseXML
;
494 var s
= response
.getElementsByTagName("status")[0].firstChild
.nodeValue
;
498 if (s
== "INVALID") {
499 alert("Match regular expression seems to be invalid.");
503 var query
= Form
.serialize("filter_add_form");
505 // we can be called from some other tab in Prefs
506 if (typeof active_tab
!= 'undefined' && active_tab
) {
507 active_tab
= "filterConfig";
510 new Ajax
.Request("backend.php?" + query
, {
511 onComplete: function (transport
) {
512 infobox_submit_callback2(transport
);
522 exception_error("createFilter", e
);
526 function isValidURL(s
) {
527 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
530 function subscribeToFeed() {
534 var form
= document
.forms
['feed_add_form'];
535 var feed_url
= form
.feed_url
.value
;
537 if (feed_url
== "") {
538 alert(__("Can't subscribe: no feed URL given."));
542 notify_progress(__("Subscribing to feed..."), true);
544 var query
= Form
.serialize("feed_add_form");
546 console
.log("subscribe q: " + query
);
548 Form
.disable("feed_add_form");
550 new Ajax
.Request("backend.php", {
552 onComplete: function(transport
) {
553 //dlg_frefresh_callback(transport);
557 if (!transport
.responseXML
) {
558 console
.log(transport
.responseText
);
559 alert(__("Server error while trying to subscribe to specified feed."));
563 var result
= transport
.responseXML
.getElementsByTagName('result')[0];
564 var rc
= parseInt(result
.getAttribute('code'));
566 Form
.enable("feed_add_form");
573 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
575 if (inPreferences()) {
578 setTimeout('updateFeedList(false, false)', 50);
582 alert(__("Specified URL seems to be invalid."));
585 alert(__("Specified URL doesn't seem to contain any feeds."));
588 new Ajax
.Request("backend.php", {
589 parameters
: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url
),
590 onComplete: function(transport
) {
591 var result
= transport
.responseXML
.getElementsByTagName('urls')[0];
592 var feeds
= JSON
.parse(result
.firstChild
.nodeValue
);
593 var select
= document
.getElementById("faad_feeds_container_select");
595 while (select
.hasChildNodes()) {
596 select
.removeChild(elem
.firstChild
);
599 for (var feedUrl
in feeds
) {
600 select
.insert(new Option(feeds
[feedUrl
], feedUrl
, false));
603 if (count
> 5) count
= 5;
606 Effect
.Appear('fadd_feeds_container', {duration
: 0.5,
607 afterSetup: function() {
608 Modalbox
.resizeToContent()
614 alert(__("Couldn't download the specified URL."));
617 alert(__("You are already subscribed to this feed."));
622 exception_error("subscribeToFeed", e
);
628 exception_error("subscribeToFeed", e
);
634 function filterCR(e
, f
)
639 key
= window
.event
.keyCode
; //IE
641 key
= e
.which
; //firefox
644 if (typeof f
!= 'undefined') {
655 function getInitParam(key
) {
656 return init_params
[key
];
659 function setInitParam(key
, value
) {
660 init_params
[key
] = value
;
663 function fatalError(code
, msg
, ext_info
) {
666 if (!ext_info
) ext_info
= "N/A";
669 window
.location
.href
= "tt-rss.php";
670 } else if (code
== 5) {
671 window
.location
.href
= "db-updater.php";
674 if (msg
== "") msg
= "Unknown error";
676 var ebc
= $("xebContent");
680 Element
.show("dialog_overlay");
681 Element
.show("errorBoxShadow");
682 Element
.hide("xebBtn");
685 if (ext_info
.responseText
) {
686 ext_info
= ext_info
.responseText
;
691 "<div><b>Error message:</b></div>" +
692 "<pre>" + msg
+ "</pre>" +
693 "<div><b>Additional information:</b></div>" +
694 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
699 exception_error("fatalError", e
);
703 function filterDlgCheckType(sender
) {
707 var ftype
= sender
[sender
.selectedIndex
].value
;
709 var form
= document
.forms
["filter_add_form"];
712 form
= document
.forms
["filter_edit_form"];
716 console
.log("filterDlgCheckType: can't find form!");
720 // if selected filter type is 5 (Date) enable the modifier dropbox
722 Element
.show("filter_dlg_date_mod_box");
723 Element
.show("filter_dlg_date_chk_box");
725 Element
.hide("filter_dlg_date_mod_box");
726 Element
.hide("filter_dlg_date_chk_box");
731 exception_error("filterDlgCheckType", e
);
736 function filterDlgCheckAction(sender
) {
740 var action
= sender
[sender
.selectedIndex
].value
;
742 var form
= document
.forms
["filter_add_form"];
745 form
= document
.forms
["filter_edit_form"];
749 console
.log("filterDlgCheckAction: can't find form!");
753 var action_param
= $("filter_dlg_param_box");
756 console
.log("filterDlgCheckAction: can't find action param box!");
760 // if selected action supports parameters, enable params field
761 if (action
== 4 || action
== 6 || action
== 7) {
762 Element
.show(action_param
);
764 Element
.show(form
.action_param
);
765 Element
.hide(form
.action_param_label
);
767 Element
.show(form
.action_param_label
);
768 Element
.hide(form
.action_param
);
771 Element
.hide(action_param
);
775 exception_error("filterDlgCheckAction", e
);
780 function filterDlgCheckDate() {
782 var form
= document
.forms
["filter_add_form"];
785 form
= document
.forms
["filter_edit_form"];
789 console
.log("filterDlgCheckAction: can't find form!");
793 var reg_exp
= form
.reg_exp
.value
;
795 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
797 new Ajax
.Request("backend.php", {
799 onComplete: function(transport
) {
801 var form
= document
.forms
["filter_add_form"];
804 form
= document
.forms
["filter_edit_form"];
807 if (transport
.responseXML
) {
808 var result
= transport
.responseXML
.getElementsByTagName("result")[0];
810 if (result
&& result
.firstChild
) {
811 if (result
.firstChild
.nodeValue
== "1") {
813 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#00ff00'});
820 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#ff0000'});
826 exception_error("filterDlgCheckDate", e
);
830 function explainError(code
) {
831 return displayDlg("explainError", code
);
834 function displayHelpInfobox(topic_id
) {
836 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
838 var w
= window
.open(url
, "ttrss_help",
839 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
843 function loading_set_progress(p
) {
845 if (p
< last_progress_point
|| !Element
.visible("overlay")) return;
847 console
.log("loading_set_progress : " + p
+ " (" + last_progress_point
+ ")");
849 var o
= $("l_progress_i");
851 // o.style.width = (p * 2) + "px";
853 new Effect
.Scale(o
, p
, {
855 scaleFrom
: last_progress_point
,
856 scaleMode
: { originalWidth
: 200 },
857 queue
: { position
: 'end', scope
: 'LSP-Q', limit
: 3 } });
859 last_progress_point
= p
;
862 exception_error("loading_set_progress", e
);
866 function remove_splash() {
867 if (Element
.visible("overlay")) {
868 console
.log("about to remove splash, OMG!");
869 Element
.hide("overlay");
870 console
.log("removed splash!");
874 function getSelectedFeedsFromBrowser() {
876 var list
= $$("#browseFeedList li[id*=FBROW]");
878 var selected
= new Array();
880 list
.each(function(child
) {
881 var id
= child
.id
.replace("FBROW-", "");
882 var cb
= $("FBCHK-" + id
);
892 function updateFeedBrowser() {
895 var query
= Form
.serialize("feed_browser");
897 Element
.show('feed_browser_spinner');
899 new Ajax
.Request("backend.php", {
901 onComplete: function(transport
) {
904 Element
.hide('feed_browser_spinner');
906 var c
= $("browseFeedList");
907 var r
= transport
.responseXML
.getElementsByTagName("content")[0];
908 var nr
= transport
.responseXML
.getElementsByTagName("num-results")[0];
909 var mode
= transport
.responseXML
.getElementsByTagName("mode")[0];
912 c
.innerHTML
= r
.firstChild
.nodeValue
;
915 if (parseInt(mode
.getAttribute("value")) == 2) {
916 Element
.show('feed_archive_remove');
918 Element
.hide('feed_archive_remove');
924 exception_error("updateFeedBrowser", e
);
929 function transport_error_check(transport
) {
931 if (transport
.responseXML
) {
932 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
935 var code
= error
.getAttribute("error-code");
936 var msg
= error
.getAttribute("error-msg");
938 fatalError(code
, msg
);
944 exception_error("check_for_error_xml", e
);
949 function strip_tags(s
) {
950 return s
.replace(/<\/?[^>]+(>|$)/g, "");
953 function truncate_string(s
, length
) {
954 if (!length
) length
= 30;
955 var tmp
= s
.substring(0, length
);
956 if (s
.length
> length
) tmp
+= "…";
960 function hotkey_prefix_timeout() {
963 var date
= new Date();
964 var ts
= Math
.round(date
.getTime() / 1000);
966 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
967 console
.log("hotkey_prefix seems to be stuck, aborting");
968 hotkey_prefix_pressed
= false;
969 hotkey_prefix
= false;
970 Element
.hide('cmdline');
973 setTimeout("hotkey_prefix_timeout()", 1000);
976 exception_error("hotkey_prefix_timeout", e
);
980 function hideAuxDlg() {
982 Element
.hide('auxDlg');
984 exception_error("hideAuxDlg", e
);
988 function feedBrowserSubscribe() {
991 var selected
= getSelectedFeedsFromBrowser();
993 var mode
= document
.forms
['feed_browser'].mode
;
995 mode
= mode
[mode
.selectedIndex
].value
;
997 if (selected
.length
> 0) {
1000 notify_progress("Loading, please wait...", true);
1002 var query
= "?op=rpc&subop=massSubscribe&ids="+
1003 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1005 new Ajax
.Request("backend.php", {
1007 onComplete: function(transport
) {
1009 var nf
= transport
.responseXML
.getElementsByTagName('num-feeds')[0];
1010 var nf_value
= nf
.getAttribute("value");
1012 notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value
));
1014 if (inPreferences()) {
1017 setTimeout('updateFeedList(false, false)', 50);
1022 alert(__("No feeds are selected."));
1026 exception_error("feedBrowserSubscribe", e
);
1030 function feedArchiveRemove() {
1033 var selected
= getSelectedFeedsFromBrowser();
1035 if (selected
.length
> 0) {
1037 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1040 Element
.show('feed_browser_spinner');
1042 var query
= "?op=rpc&subop=remarchived&ids=" +
1043 param_escape(selected
.toString());;
1045 new Ajax
.Request("backend.php", {
1047 onComplete: function(transport
) {
1048 updateFeedBrowser();
1053 alert(__("No feeds are selected."));
1057 exception_error("feedArchiveRemove", e
);
1061 function uploadIconHandler(rc
) {
1065 notify_info("Upload complete.");
1066 if (inPreferences()) {
1069 setTimeout('updateFeedList(false, false)', 50);
1073 notify_error("Upload failed: icon is too big.");
1076 notify_error("Upload failed.");
1081 exception_error("uploadIconHandler", e
);
1085 function removeFeedIcon(id
) {
1089 if (confirm(__("Remove stored feed icon?"))) {
1090 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
1094 notify_progress("Removing feed icon...", true);
1096 new Ajax
.Request("backend.php", {
1098 onComplete: function(transport
) {
1099 notify_info("Feed icon removed.");
1100 if (inPreferences()) {
1103 setTimeout('updateFeedList(false, false)', 50);
1110 exception_error("uploadFeedIcon", e
);
1114 function uploadFeedIcon() {
1118 var file
= $("icon_file");
1120 if (file
.value
.length
== 0) {
1121 alert(__("Please select an image file to upload."));
1123 if (confirm(__("Upload new icon for this feed?"))) {
1124 notify_progress("Uploading, please wait...", true);
1132 exception_error("uploadFeedIcon", e
);
1136 function addLabel(select
, callback
) {
1140 var caption
= prompt(__("Please enter label caption:"), "");
1142 if (caption
!= undefined) {
1144 if (caption
== "") {
1145 alert(__("Can't create label: missing caption."));
1149 var query
= "?op=pref-labels&subop=add&caption=" +
1150 param_escape(caption
);
1153 query
+= "&output=select";
1155 notify_progress("Loading, please wait...", true);
1157 if (inPreferences() && !select
) active_tab
= "labelConfig";
1159 new Ajax
.Request("backend.php", {
1161 onComplete: function(transport
) {
1163 callback(transport
);
1164 } else if (inPreferences()) {
1165 infobox_submit_callback2(transport
);
1174 exception_error("addLabel", e
);
1178 function quickAddFeed() {
1179 displayDlg('quickAddFeed', '',
1180 function () {$('feed_url').focus();});
1183 function quickAddFilter() {
1184 displayDlg('quickAddFilter', '',
1185 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
1188 function unsubscribeFeed(feed_id
, title
) {
1190 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1192 if (title
== undefined || confirm(msg
)) {
1193 notify_progress("Removing feed...");
1195 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1197 new Ajax
.Request("backend.php", {
1199 onComplete: function(transport
) {
1203 if (inPreferences()) {
1206 dlg_frefresh_callback(transport
, feed_id
);
1216 function backend_sanity_check_callback(transport
) {
1220 if (sanity_check_done
) {
1221 fatalError(11, "Sanity check request received twice. This can indicate "+
1222 "presence of Firebug or some other disrupting extension. "+
1223 "Please disable it and try again.");
1227 if (!transport
.responseXML
) {
1229 fatalError(3, "Sanity check: Received reply is not XML",
1230 transport
.responseText
);
1235 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1238 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1242 var error_code
= reply
.getAttribute("error-code");
1244 if (error_code
&& error_code
!= 0) {
1245 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1248 console
.log("sanity check ok");
1250 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1253 console
.log('reading init-params...');
1255 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1260 console
.log("IP: " + k
+ " => " + v
);
1264 init_params
= params
;
1267 sanity_check_done
= true;
1269 init_second_stage();
1272 exception_error("backend_sanity_check_callback", e
, transport
);
1276 function has_local_storage() {
1279 return 'localStorage' in window && window['localStorage'] != null;
1285 function catSelectOnChange(elem
) {
1287 var value
= elem
[elem
.selectedIndex
].value
;
1288 var def
= elem
.getAttribute('default');
1290 if (value
== "ADD_CAT") {
1293 dropboxSelect(elem
, def
);
1295 elem
.selectedIndex
= 0;
1301 exception_error("catSelectOnChange", e
);
1305 function quickAddCat(elem
) {
1307 var cat
= prompt(__("Please enter category title:"));
1311 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1313 notify_progress("Loading, please wait...", true);
1315 new Ajax
.Request("backend.php", {
1317 onComplete: function (transport
) {
1318 var response
= transport
.responseXML
;
1319 var select
= response
.getElementsByTagName("select")[0];
1320 var options
= select
.getElementsByTagName("option");
1322 dropbox_replace_options(elem
, options
);
1331 exception_error("quickAddCat", e
);
1335 function genUrlChangeKey(feed
, is_cat
) {
1338 var ok
= confirm(__("Generate new syndication address for this feed?"));
1342 notify_progress("Trying to change address...", true);
1344 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1345 "&is_cat=" + param_escape(is_cat
);
1347 new Ajax
.Request("backend.php", {
1349 onComplete: function(transport
) {
1350 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
1352 var e
= $('gen_feed_url');
1356 new_link
= new_link
.firstChild
.nodeValue
;
1358 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1359 "&key=" + new_link
);
1361 e
.href
= e
.href
.replace(/\&key=.*$/,
1362 "&key=" + new_link
);
1364 new Effect
.Highlight(e
);
1369 notify_error("Could not change feed URL.");
1374 exception_error("genUrlChangeKey", e
);
1379 function labelSelectOnChange(elem
) {
1381 var value
= elem
[elem
.selectedIndex
].value
;
1382 var def
= elem
.getAttribute('default');
1384 if (value
== "ADD_LABEL") {
1387 dropboxSelect(elem
, def
);
1389 elem
.selectedIndex
= 0;
1391 addLabel(elem
, function(transport
) {
1395 var response
= transport
.responseXML
;
1396 var select
= response
.getElementsByTagName("select")[0];
1397 var options
= select
.getElementsByTagName("option");
1399 dropbox_replace_options(elem
, options
);
1403 exception_error("addLabel", e
);
1409 exception_error("labelSelectOnChange", e
);
1413 function dropbox_replace_options(elem
, options
) {
1416 while (elem
.hasChildNodes())
1417 elem
.removeChild(elem
.firstChild
);
1421 for (var i
= 0; i
< options
.length
; i
++) {
1422 var text
= options
[i
].firstChild
.nodeValue
;
1423 var value
= options
[i
].getAttribute("value");
1425 if (value
== undefined) value
= text
;
1427 var issel
= options
[i
].getAttribute("selected") == "1";
1429 var option
= new Option(text
, value
, issel
);
1431 if (options
[i
].getAttribute("disabled"))
1432 option
.setAttribute("disabled", true);
1434 elem
.insert(option
);
1436 if (issel
) sel_idx
= i
;
1439 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1440 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1443 exception_error("dropbox_replace_options", e
);
1447 // mode = all, none, invert
1448 function selectTableRows(id
, mode
) {
1450 var rows
= $(id
).rows
;
1452 for (var i
= 0; i
< rows
.length
; i
++) {
1456 if (row
.id
&& row
.className
) {
1457 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1458 var inputs
= rows
[i
].getElementsByTagName("input");
1460 for (var j
= 0; j
< inputs
.length
; j
++) {
1461 var input
= inputs
[j
];
1463 if (input
.getAttribute("type") == "checkbox" &&
1464 input
.id
.match(bare_id
)) {
1472 var issel
= row
.hasClassName("Selected");
1474 if (mode
== "all" && !issel
) {
1475 row
.addClassName("Selected");
1477 } else if (mode
== "none" && issel
) {
1478 row
.removeClassName("Selected");
1480 } else if (mode
== "invert") {
1483 row
.removeClassName("Selected");
1486 row
.addClassName("Selected");
1495 exception_error("selectTableRows", e
);
1500 function getSelectedTableRowIds(id
) {
1504 var elem_rows
= $(id
).rows
;
1506 for (i
= 0; i
< elem_rows
.length
; i
++) {
1507 if (elem_rows
[i
].hasClassName("Selected")) {
1508 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1514 exception_error("getSelectedTableRowIds", e
);