]>
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;
29 if (ext_info
.responseText
) {
30 ext_info
= ext_info
.responseText
;
34 var content
= "<div class=\"fatalError\">" +
35 "<pre>" + msg
+ "</pre>";
38 content
+= "<div><b>Additional information:</b></div>" +
39 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
42 content
+= "<div><b>Stack trace:</b></div>" +
43 "<textarea readonly=\"1\">" + e
.stack
+ "</textarea>";
45 // content += "<div style='text-align : center'>" +
46 // "<button onclick=\"closeInfoBox()\">" +
47 // "Close this window" + "</button></div>";
51 // TODO: add code to automatically report errors to tt-rss.org
53 var dialog
= new dijit
.Dialog({
54 title
: "Unhandled exception",
55 style
: "width: 600px",
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 setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
206 d
.setTime(d
.getTime() + (lifetime
* 1000));
209 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
211 int_setCookie(name
, value
, d
, path
, domain
, secure
);
215 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
216 document
.cookie
= name
+ "=" + escape(value
) +
217 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
218 ((path
) ? "; path=" + path
: "") +
219 ((domain
) ? "; domain=" + domain
: "") +
220 ((secure
) ? "; secure" : "");
223 function delCookie(name
, path
, domain
) {
224 if (getCookie(name
)) {
225 document
.cookie
= name
+ "=" +
226 ((path
) ? ";path=" + path
: "") +
227 ((domain
) ? ";domain=" + domain
: "" ) +
228 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
233 function getCookie(name
) {
235 var dc
= document
.cookie
;
236 var prefix
= name
+ "=";
237 var begin
= dc
.indexOf("; " + prefix
);
239 begin
= dc
.indexOf(prefix
);
240 if (begin
!= 0) return null;
245 var end
= document
.cookie
.indexOf(";", begin
);
249 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
252 function gotoPreferences() {
253 document
.location
.href
= "prefs.php";
256 function gotoMain() {
257 document
.location
.href
= "tt-rss.php";
260 function gotoExportOpml() {
261 document
.location
.href
= "opml.php?op=Export";
265 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
266 * * @author Sundar Dorai-Raj
267 * * Email: sdoraira@vt.edu
268 * * This program is free software; you can redistribute it and/or
269 * * modify it under the terms of the GNU General Public License
270 * * as published by the Free Software Foundation; either version 2
271 * * of the License, or (at your option) any later version,
272 * * provided that any use properly credits the author.
273 * * This program is distributed in the hope that it will be useful,
274 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
275 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
276 * * GNU General Public License for more details at http://www.gnu.org * * */
278 var numbers
=".0123456789";
279 function isNumeric(x
) {
280 // is x a String or a character?
282 // remove negative sign
284 for(j
=0;j
<x
.length
;j
++) {
285 // call isNumeric recursively for each character
286 number
=isNumeric(x
.substring(j
,j
+1));
287 if(!number
) return number
;
292 // if x is number return true
293 if(numbers
.indexOf(x
)>=0) return true;
299 function toggleSelectRowById(sender
, id
) {
301 return toggleSelectRow(sender
, row
);
304 function toggleSelectListRow(sender
) {
305 var row
= sender
.parentNode
;
306 return toggleSelectRow(sender
, row
);
309 function tSR(sender
, row
) {
310 return toggleSelectRow(sender
, row
);
313 function toggleSelectRow(sender
, row
) {
315 if (!row
) row
= sender
.parentNode
.parentNode
;
317 if (sender
.checked
&& !row
.hasClassName('Selected'))
318 row
.addClassName('Selected');
320 row
.removeClassName('Selected');
323 function checkboxToggleElement(elem
, id
) {
325 Effect
.Appear(id
, {duration
: 0.5});
327 Effect
.Fade(id
, {duration
: 0.5});
331 function dropboxSelect(e
, v
) {
332 for (i
= 0; i
< e
.length
; i
++) {
333 if (e
[i
].value
== v
) {
340 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
341 // bugfixed just a little bit :-)
342 function getURLParam(strParamName
){
344 var strHref
= window
.location
.href
;
346 if (strHref
.indexOf("#") == strHref
.length
-1) {
347 strHref
= strHref
.substring(0, strHref
.length
-1);
350 if ( strHref
.indexOf("?") > -1 ){
351 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
352 var aQueryString
= strQueryString
.split("&");
353 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
354 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
355 var aParam
= aQueryString
[iParam
].split("=");
356 strReturn
= aParam
[1];
364 function leading_zero(p
) {
366 if (s
.length
== 1) s
= "0" + s
;
370 function make_timestamp() {
373 return leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
374 ":" + leading_zero(d
.getSeconds());
378 function closeErrorBox() {
380 if (Element
.visible("errorBoxShadow")) {
381 Element
.hide("dialog_overlay");
382 Element
.hide("errorBoxShadow");
390 function closeInfoBox(cleanup
) {
394 dialog
= dijit
.byId("infoBox");
396 if (dialog
) dialog
.hide();
399 //exception_error("closeInfoBox", e);
405 function displayDlg(id
, param
, callback
) {
407 notify_progress("Loading, please wait...", true);
409 var query
= "?op=dlg&id=" +
410 param_escape(id
) + "¶m=" + param_escape(param
);
412 new Ajax
.Request("backend.php", {
414 onComplete: function (transport
) {
415 infobox_callback2(transport
);
416 if (callback
) callback(transport
);
422 function infobox_submit_callback2(transport
) {
426 // called from prefs, reload tab
427 if (typeof active_tab
!= 'undefined' && active_tab
) {
428 selectTab(active_tab
, false);
432 if (transport
.responseText
) {
433 notify_info(transport
.responseText
);
437 function infobox_callback2(transport
) {
441 if (dijit
.byId("infoBox")) {
442 dialog
= dijit
.byId("infoBox");
445 //console.log("infobox_callback2");
449 var dtitle
= "Dialog";
451 if (transport
.responseXML
) {
452 var dlg
= transport
.responseXML
.getElementsByTagName("dlg")[0];
454 var title
= transport
.responseXML
.getElementsByTagName("title")[0];
456 title
= title
.firstChild
.nodeValue
;
458 var content
= transport
.responseXML
.getElementsByTagName("content")[0];
460 content
= content
.firstChild
.nodeValue
;
463 content
= transport
.responseText
;
467 dialog
= new dijit
.Dialog({
470 style
: "width: 600px",
471 onCancel: function() {
474 onExecute: function() {
477 onClose: function() {
482 dialog
.attr('title', title
);
483 dialog
.attr('content', content
);
490 exception_error("infobox_callback2", e
);
494 function createFilter() {
498 var form
= document
.forms
['filter_add_form'];
499 var reg_exp
= form
.reg_exp
.value
;
502 alert(__("Can't add filter: nothing to match on."));
506 var query
= "?op=rpc&subop=verifyRegexp®_exp=" + param_escape(reg_exp
);
508 notify_progress("Verifying regular expression...");
510 new Ajax
.Request("backend.php", {
512 onComplete: function(transport
) {
513 handle_rpc_reply(transport
);
515 var response
= transport
.responseXML
;
518 var s
= response
.getElementsByTagName("status")[0].firstChild
.nodeValue
;
522 if (s
== "INVALID") {
523 alert("Match regular expression seems to be invalid.");
527 var query
= Form
.serialize("filter_add_form");
529 // we can be called from some other tab in Prefs
530 if (typeof active_tab
!= 'undefined' && active_tab
) {
531 active_tab
= "filterConfig";
534 new Ajax
.Request("backend.php?" + query
, {
535 onComplete: function (transport
) {
536 infobox_submit_callback2(transport
);
546 exception_error("createFilter", e
);
550 function isValidURL(s
) {
551 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
554 function subscribeToFeed() {
558 var form
= document
.forms
['feed_add_form'];
559 var feed_url
= form
.feed_url
.value
;
561 if (feed_url
== "") {
562 alert(__("Can't subscribe: no feed URL given."));
566 notify_progress(__("Subscribing to feed..."), true);
568 var query
= Form
.serialize("feed_add_form");
570 console
.log("subscribe q: " + query
);
572 Form
.disable("feed_add_form");
574 new Ajax
.Request("backend.php", {
576 onComplete: function(transport
) {
579 if (!transport
.responseXML
) {
580 console
.log(transport
.responseText
);
581 alert(__("Server error while trying to subscribe to specified feed."));
585 var result
= transport
.responseXML
.getElementsByTagName('result')[0];
586 var rc
= parseInt(result
.getAttribute('code'));
588 Form
.enable("feed_add_form");
595 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
597 if (inPreferences()) {
600 setTimeout('updateFeedList(false, false)', 50);
604 alert(__("Specified URL seems to be invalid."));
607 alert(__("Specified URL doesn't seem to contain any feeds."));
610 new Ajax
.Request("backend.php", {
611 parameters
: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url
),
612 onComplete: function(transport
) {
613 var result
= transport
.responseXML
.getElementsByTagName('urls')[0];
614 var feeds
= JSON
.parse(result
.firstChild
.nodeValue
);
615 var select
= document
.getElementById("faad_feeds_container_select");
617 while (select
.hasChildNodes()) {
618 select
.removeChild(elem
.firstChild
);
621 for (var feedUrl
in feeds
) {
622 select
.insert(new Option(feeds
[feedUrl
], feedUrl
, false));
625 if (count
> 5) count
= 5;
628 Effect
.Appear('fadd_feeds_container', {duration
: 0.5});
633 alert(__("Couldn't download the specified URL."));
636 alert(__("You are already subscribed to this feed."));
641 exception_error("subscribeToFeed", e
);
647 exception_error("subscribeToFeed", e
);
653 function filterCR(e
, f
)
658 key
= window
.event
.keyCode
; //IE
660 key
= e
.which
; //firefox
663 if (typeof f
!= 'undefined') {
674 function getInitParam(key
) {
675 return init_params
[key
];
678 function setInitParam(key
, value
) {
679 init_params
[key
] = value
;
682 function fatalError(code
, msg
, ext_info
) {
685 if (!ext_info
) ext_info
= "N/A";
688 window
.location
.href
= "tt-rss.php";
689 } else if (code
== 5) {
690 window
.location
.href
= "db-updater.php";
693 if (msg
== "") msg
= "Unknown error";
695 var ebc
= $("xebContent");
699 Element
.show("dialog_overlay");
700 Element
.show("errorBoxShadow");
701 Element
.hide("xebBtn");
704 if (ext_info
.responseText
) {
705 ext_info
= ext_info
.responseText
;
710 "<div><b>Error message:</b></div>" +
711 "<pre>" + msg
+ "</pre>" +
712 "<div><b>Additional information:</b></div>" +
713 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
718 exception_error("fatalError", e
);
722 function filterDlgCheckType(sender
) {
726 var ftype
= sender
[sender
.selectedIndex
].value
;
728 var form
= document
.forms
["filter_add_form"];
731 form
= document
.forms
["filter_edit_form"];
735 console
.log("filterDlgCheckType: can't find form!");
739 // if selected filter type is 5 (Date) enable the modifier dropbox
741 Element
.show("filter_dlg_date_mod_box");
742 Element
.show("filter_dlg_date_chk_box");
744 Element
.hide("filter_dlg_date_mod_box");
745 Element
.hide("filter_dlg_date_chk_box");
750 exception_error("filterDlgCheckType", e
);
755 function filterDlgCheckAction(sender
) {
759 var action
= sender
[sender
.selectedIndex
].value
;
761 var form
= document
.forms
["filter_add_form"];
764 form
= document
.forms
["filter_edit_form"];
768 console
.log("filterDlgCheckAction: can't find form!");
772 var action_param
= $("filter_dlg_param_box");
775 console
.log("filterDlgCheckAction: can't find action param box!");
779 // if selected action supports parameters, enable params field
780 if (action
== 4 || action
== 6 || action
== 7) {
781 Element
.show(action_param
);
783 Element
.show(form
.action_param
);
784 Element
.hide(form
.action_param_label
);
786 Element
.show(form
.action_param_label
);
787 Element
.hide(form
.action_param
);
790 Element
.hide(action_param
);
794 exception_error("filterDlgCheckAction", e
);
799 function filterDlgCheckDate() {
801 var form
= document
.forms
["filter_add_form"];
804 form
= document
.forms
["filter_edit_form"];
808 console
.log("filterDlgCheckAction: can't find form!");
812 var reg_exp
= form
.reg_exp
.value
;
814 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
816 new Ajax
.Request("backend.php", {
818 onComplete: function(transport
) {
820 var form
= document
.forms
["filter_add_form"];
823 form
= document
.forms
["filter_edit_form"];
826 if (transport
.responseXML
) {
827 var result
= transport
.responseXML
.getElementsByTagName("result")[0];
829 if (result
&& result
.firstChild
) {
830 if (result
.firstChild
.nodeValue
== "1") {
832 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#00ff00'});
839 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#ff0000'});
845 exception_error("filterDlgCheckDate", e
);
849 function explainError(code
) {
850 return displayDlg("explainError", code
);
853 function displayHelpInfobox(topic_id
) {
855 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
857 var w
= window
.open(url
, "ttrss_help",
858 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
862 function loading_set_progress(p
) {
864 if (p
< last_progress_point
|| !Element
.visible("overlay")) return;
866 console
.log("loading_set_progress : " + p
+ " (" + last_progress_point
+ ")");
868 var o
= $("l_progress_i");
870 // o.style.width = (p * 2) + "px";
872 new Effect
.Scale(o
, p
, {
874 scaleFrom
: last_progress_point
,
875 scaleMode
: { originalWidth
: 200 },
876 queue
: { position
: 'end', scope
: 'LSP-Q', limit
: 3 } });
878 last_progress_point
= p
;
881 exception_error("loading_set_progress", e
);
885 function remove_splash() {
886 if (Element
.visible("overlay")) {
887 console
.log("about to remove splash, OMG!");
888 Element
.hide("overlay");
889 console
.log("removed splash!");
893 function getSelectedFeedsFromBrowser() {
895 var list
= $$("#browseFeedList li[id*=FBROW]");
897 var selected
= new Array();
899 list
.each(function(child
) {
900 var id
= child
.id
.replace("FBROW-", "");
901 var cb
= $("FBCHK-" + id
);
911 function updateFeedBrowser() {
914 var query
= Form
.serialize("feed_browser");
916 Element
.show('feed_browser_spinner');
918 new Ajax
.Request("backend.php", {
920 onComplete: function(transport
) {
923 Element
.hide('feed_browser_spinner');
925 var c
= $("browseFeedList");
926 var r
= transport
.responseXML
.getElementsByTagName("content")[0];
927 var nr
= transport
.responseXML
.getElementsByTagName("num-results")[0];
928 var mode
= transport
.responseXML
.getElementsByTagName("mode")[0];
931 c
.innerHTML
= r
.firstChild
.nodeValue
;
934 if (parseInt(mode
.getAttribute("value")) == 2) {
935 Element
.show('feed_archive_remove');
937 Element
.hide('feed_archive_remove');
943 exception_error("updateFeedBrowser", e
);
948 function transport_error_check(transport
) {
950 if (transport
.responseXML
) {
951 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
954 var code
= error
.getAttribute("error-code");
955 var msg
= error
.getAttribute("error-msg");
957 fatalError(code
, msg
);
963 exception_error("check_for_error_xml", e
);
968 function strip_tags(s
) {
969 return s
.replace(/<\/?[^>]+(>|$)/g, "");
972 function truncate_string(s
, length
) {
973 if (!length
) length
= 30;
974 var tmp
= s
.substring(0, length
);
975 if (s
.length
> length
) tmp
+= "…";
979 function hotkey_prefix_timeout() {
982 var date
= new Date();
983 var ts
= Math
.round(date
.getTime() / 1000);
985 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
986 console
.log("hotkey_prefix seems to be stuck, aborting");
987 hotkey_prefix_pressed
= false;
988 hotkey_prefix
= false;
989 Element
.hide('cmdline');
992 setTimeout("hotkey_prefix_timeout()", 1000);
995 exception_error("hotkey_prefix_timeout", e
);
999 function hideAuxDlg() {
1001 Element
.hide('auxDlg');
1003 exception_error("hideAuxDlg", e
);
1007 function feedBrowserSubscribe() {
1010 var selected
= getSelectedFeedsFromBrowser();
1012 var mode
= document
.forms
['feed_browser'].mode
;
1014 mode
= mode
[mode
.selectedIndex
].value
;
1016 if (selected
.length
> 0) {
1019 notify_progress("Loading, please wait...", true);
1021 var query
= "?op=rpc&subop=massSubscribe&ids="+
1022 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1024 new Ajax
.Request("backend.php", {
1026 onComplete: function(transport
) {
1028 var nf
= transport
.responseXML
.getElementsByTagName('num-feeds')[0];
1029 var nf_value
= nf
.getAttribute("value");
1031 notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value
));
1033 if (inPreferences()) {
1036 setTimeout('updateFeedList(false, false)', 50);
1041 alert(__("No feeds are selected."));
1045 exception_error("feedBrowserSubscribe", e
);
1049 function feedArchiveRemove() {
1052 var selected
= getSelectedFeedsFromBrowser();
1054 if (selected
.length
> 0) {
1056 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1059 Element
.show('feed_browser_spinner');
1061 var query
= "?op=rpc&subop=remarchived&ids=" +
1062 param_escape(selected
.toString());;
1064 new Ajax
.Request("backend.php", {
1066 onComplete: function(transport
) {
1067 updateFeedBrowser();
1072 alert(__("No feeds are selected."));
1076 exception_error("feedArchiveRemove", e
);
1080 function uploadIconHandler(rc
) {
1084 notify_info("Upload complete.");
1085 if (inPreferences()) {
1088 setTimeout('updateFeedList(false, false)', 50);
1092 notify_error("Upload failed: icon is too big.");
1095 notify_error("Upload failed.");
1100 exception_error("uploadIconHandler", e
);
1104 function removeFeedIcon(id
) {
1108 if (confirm(__("Remove stored feed icon?"))) {
1109 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
1113 notify_progress("Removing feed icon...", true);
1115 new Ajax
.Request("backend.php", {
1117 onComplete: function(transport
) {
1118 notify_info("Feed icon removed.");
1119 if (inPreferences()) {
1122 setTimeout('updateFeedList(false, false)', 50);
1129 exception_error("uploadFeedIcon", e
);
1133 function uploadFeedIcon() {
1137 var file
= $("icon_file");
1139 if (file
.value
.length
== 0) {
1140 alert(__("Please select an image file to upload."));
1142 if (confirm(__("Upload new icon for this feed?"))) {
1143 notify_progress("Uploading, please wait...", true);
1151 exception_error("uploadFeedIcon", e
);
1155 function addLabel(select
, callback
) {
1159 var caption
= prompt(__("Please enter label caption:"), "");
1161 if (caption
!= undefined) {
1163 if (caption
== "") {
1164 alert(__("Can't create label: missing caption."));
1168 var query
= "?op=pref-labels&subop=add&caption=" +
1169 param_escape(caption
);
1172 query
+= "&output=select";
1174 notify_progress("Loading, please wait...", true);
1176 if (inPreferences() && !select
) active_tab
= "labelConfig";
1178 new Ajax
.Request("backend.php", {
1180 onComplete: function(transport
) {
1182 callback(transport
);
1183 } else if (inPreferences()) {
1184 infobox_submit_callback2(transport
);
1193 exception_error("addLabel", e
);
1197 function quickAddFeed() {
1198 displayDlg('quickAddFeed', '',
1199 function () {$('feed_url').focus();});
1202 function quickAddFilter() {
1203 displayDlg('quickAddFilter', '',
1204 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
1207 function unsubscribeFeed(feed_id
, title
) {
1209 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1211 if (title
== undefined || confirm(msg
)) {
1212 notify_progress("Removing feed...");
1214 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1216 new Ajax
.Request("backend.php", {
1218 onComplete: function(transport
) {
1222 if (inPreferences()) {
1225 dlg_frefresh_callback(transport
, feed_id
);
1235 function backend_sanity_check_callback(transport
) {
1239 if (sanity_check_done
) {
1240 fatalError(11, "Sanity check request received twice. This can indicate "+
1241 "presence of Firebug or some other disrupting extension. "+
1242 "Please disable it and try again.");
1246 if (!transport
.responseXML
) {
1248 fatalError(3, "Sanity check: Received reply is not XML",
1249 transport
.responseText
);
1254 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1257 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1261 var error_code
= reply
.getAttribute("error-code");
1263 if (error_code
&& error_code
!= 0) {
1264 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1267 console
.log("sanity check ok");
1269 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1272 console
.log('reading init-params...');
1274 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1279 console
.log("IP: " + k
+ " => " + v
);
1283 init_params
= params
;
1286 sanity_check_done
= true;
1288 init_second_stage();
1291 exception_error("backend_sanity_check_callback", e
, transport
);
1295 function has_local_storage() {
1298 return 'localStorage' in window && window['localStorage'] != null;
1304 function catSelectOnChange(elem
) {
1306 var value
= elem
[elem
.selectedIndex
].value
;
1307 var def
= elem
.getAttribute('default');
1309 if (value
== "ADD_CAT") {
1312 dropboxSelect(elem
, def
);
1314 elem
.selectedIndex
= 0;
1320 exception_error("catSelectOnChange", e
);
1324 function quickAddCat(elem
) {
1326 var cat
= prompt(__("Please enter category title:"));
1330 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1332 notify_progress("Loading, please wait...", true);
1334 new Ajax
.Request("backend.php", {
1336 onComplete: function (transport
) {
1337 var response
= transport
.responseXML
;
1338 var select
= response
.getElementsByTagName("select")[0];
1339 var options
= select
.getElementsByTagName("option");
1341 dropbox_replace_options(elem
, options
);
1350 exception_error("quickAddCat", e
);
1354 function genUrlChangeKey(feed
, is_cat
) {
1357 var ok
= confirm(__("Generate new syndication address for this feed?"));
1361 notify_progress("Trying to change address...", true);
1363 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1364 "&is_cat=" + param_escape(is_cat
);
1366 new Ajax
.Request("backend.php", {
1368 onComplete: function(transport
) {
1369 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
1371 var e
= $('gen_feed_url');
1375 new_link
= new_link
.firstChild
.nodeValue
;
1377 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1378 "&key=" + new_link
);
1380 e
.href
= e
.href
.replace(/\&key=.*$/,
1381 "&key=" + new_link
);
1383 new Effect
.Highlight(e
);
1388 notify_error("Could not change feed URL.");
1393 exception_error("genUrlChangeKey", e
);
1398 function labelSelectOnChange(elem
) {
1400 var value
= elem
[elem
.selectedIndex
].value
;
1401 var def
= elem
.getAttribute('default');
1403 if (value
== "ADD_LABEL") {
1406 dropboxSelect(elem
, def
);
1408 elem
.selectedIndex
= 0;
1410 addLabel(elem
, function(transport
) {
1414 var response
= transport
.responseXML
;
1415 var select
= response
.getElementsByTagName("select")[0];
1416 var options
= select
.getElementsByTagName("option");
1418 dropbox_replace_options(elem
, options
);
1422 exception_error("addLabel", e
);
1428 exception_error("labelSelectOnChange", e
);
1432 function dropbox_replace_options(elem
, options
) {
1435 while (elem
.hasChildNodes())
1436 elem
.removeChild(elem
.firstChild
);
1440 for (var i
= 0; i
< options
.length
; i
++) {
1441 var text
= options
[i
].firstChild
.nodeValue
;
1442 var value
= options
[i
].getAttribute("value");
1444 if (value
== undefined) value
= text
;
1446 var issel
= options
[i
].getAttribute("selected") == "1";
1448 var option
= new Option(text
, value
, issel
);
1450 if (options
[i
].getAttribute("disabled"))
1451 option
.setAttribute("disabled", true);
1453 elem
.insert(option
);
1455 if (issel
) sel_idx
= i
;
1458 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1459 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1462 exception_error("dropbox_replace_options", e
);
1466 // mode = all, none, invert
1467 function selectTableRows(id
, mode
) {
1469 var rows
= $(id
).rows
;
1471 for (var i
= 0; i
< rows
.length
; i
++) {
1475 if (row
.id
&& row
.className
) {
1476 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1477 var inputs
= rows
[i
].getElementsByTagName("input");
1479 for (var j
= 0; j
< inputs
.length
; j
++) {
1480 var input
= inputs
[j
];
1482 if (input
.getAttribute("type") == "checkbox" &&
1483 input
.id
.match(bare_id
)) {
1491 var issel
= row
.hasClassName("Selected");
1493 if (mode
== "all" && !issel
) {
1494 row
.addClassName("Selected");
1496 } else if (mode
== "none" && issel
) {
1497 row
.removeClassName("Selected");
1499 } else if (mode
== "invert") {
1502 row
.removeClassName("Selected");
1505 row
.addClassName("Selected");
1514 exception_error("selectTableRows", e
);
1519 function getSelectedTableRowIds(id
) {
1523 var elem_rows
= $(id
).rows
;
1525 for (i
= 0; i
< elem_rows
.length
; i
++) {
1526 if (elem_rows
[i
].hasClassName("Selected")) {
1527 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1533 exception_error("getSelectedTableRowIds", e
);