]>
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 /* this is for dijit Checkbox */
310 function toggleSelectListRow2(sender
) {
311 var row
= sender
.domNode
.parentNode
;
312 return toggleSelectRow(sender
, row
);
315 function tSR(sender
, row
) {
316 return toggleSelectRow(sender
, row
);
319 /* this is for dijit Checkbox */
320 function toggleSelectRow2(sender
, row
) {
322 if (!row
) row
= sender
.domNode
.parentNode
.parentNode
;
324 if (sender
.checked
&& !row
.hasClassName('Selected'))
325 row
.addClassName('Selected');
327 row
.removeClassName('Selected');
331 function toggleSelectRow(sender
, row
) {
333 if (!row
) row
= sender
.parentNode
.parentNode
;
335 if (sender
.checked
&& !row
.hasClassName('Selected'))
336 row
.addClassName('Selected');
338 row
.removeClassName('Selected');
341 function checkboxToggleElement(elem
, id
) {
343 Effect
.Appear(id
, {duration
: 0.5});
345 Effect
.Fade(id
, {duration
: 0.5});
349 function dropboxSelect(e
, v
) {
350 for (i
= 0; i
< e
.length
; i
++) {
351 if (e
[i
].value
== v
) {
358 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
359 // bugfixed just a little bit :-)
360 function getURLParam(strParamName
){
362 var strHref
= window
.location
.href
;
364 if (strHref
.indexOf("#") == strHref
.length
-1) {
365 strHref
= strHref
.substring(0, strHref
.length
-1);
368 if ( strHref
.indexOf("?") > -1 ){
369 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
370 var aQueryString
= strQueryString
.split("&");
371 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
372 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
373 var aParam
= aQueryString
[iParam
].split("=");
374 strReturn
= aParam
[1];
382 function leading_zero(p
) {
384 if (s
.length
== 1) s
= "0" + s
;
388 function make_timestamp() {
391 return leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
392 ":" + leading_zero(d
.getSeconds());
396 function closeErrorBox() {
398 if (Element
.visible("errorBoxShadow")) {
399 Element
.hide("dialog_overlay");
400 Element
.hide("errorBoxShadow");
408 function closeInfoBox(cleanup
) {
412 dialog
= dijit
.byId("infoBox");
414 if (dialog
) dialog
.hide();
417 //exception_error("closeInfoBox", e);
423 function displayDlg(id
, param
, callback
) {
425 notify_progress("Loading, please wait...", true);
427 var query
= "?op=dlg&id=" +
428 param_escape(id
) + "¶m=" + param_escape(param
);
430 new Ajax
.Request("backend.php", {
432 onComplete: function (transport
) {
433 infobox_callback2(transport
);
434 if (callback
) callback(transport
);
440 function infobox_submit_callback2(transport
) {
444 // called from prefs, reload tab
445 if (typeof active_tab
!= 'undefined' && active_tab
) {
446 selectTab(active_tab
, false);
450 if (transport
.responseText
) {
451 notify_info(transport
.responseText
);
455 function infobox_callback2(transport
) {
459 if (dijit
.byId("infoBox")) {
460 dialog
= dijit
.byId("infoBox");
463 //console.log("infobox_callback2");
467 var dtitle
= "Dialog";
469 if (transport
.responseXML
) {
470 var dlg
= transport
.responseXML
.getElementsByTagName("dlg")[0];
472 var title
= transport
.responseXML
.getElementsByTagName("title")[0];
474 title
= title
.firstChild
.nodeValue
;
476 var content
= transport
.responseXML
.getElementsByTagName("content")[0];
478 content
= content
.firstChild
.nodeValue
;
481 content
= transport
.responseText
;
485 dialog
= new dijit
.Dialog({
488 style
: "width: 600px",
489 onCancel: function() {
492 onExecute: function() {
495 onClose: function() {
500 dialog
.attr('title', title
);
501 dialog
.attr('content', content
);
508 exception_error("infobox_callback2", e
);
512 function createFilter() {
516 var form
= document
.forms
['filter_add_form'];
517 var reg_exp
= form
.reg_exp
.value
;
520 alert(__("Can't add filter: nothing to match on."));
524 var query
= "?op=rpc&subop=verifyRegexp®_exp=" + param_escape(reg_exp
);
526 notify_progress("Verifying regular expression...");
528 new Ajax
.Request("backend.php", {
530 onComplete: function(transport
) {
531 handle_rpc_reply(transport
);
533 var response
= transport
.responseXML
;
536 var s
= response
.getElementsByTagName("status")[0].firstChild
.nodeValue
;
540 if (s
== "INVALID") {
541 alert("Match regular expression seems to be invalid.");
545 var query
= Form
.serialize("filter_add_form");
547 // we can be called from some other tab in Prefs
548 if (typeof active_tab
!= 'undefined' && active_tab
) {
549 active_tab
= "filterConfig";
552 new Ajax
.Request("backend.php?" + query
, {
553 onComplete: function (transport
) {
554 infobox_submit_callback2(transport
);
564 exception_error("createFilter", e
);
568 function isValidURL(s
) {
569 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
572 function subscribeToFeed() {
576 var form
= document
.forms
['feed_add_form'];
577 var feed_url
= form
.feed_url
.value
;
579 if (feed_url
== "") {
580 alert(__("Can't subscribe: no feed URL given."));
584 notify_progress(__("Subscribing to feed..."), true);
586 var query
= Form
.serialize("feed_add_form");
588 console
.log("subscribe q: " + query
);
590 Form
.disable("feed_add_form");
592 new Ajax
.Request("backend.php", {
594 onComplete: function(transport
) {
597 if (!transport
.responseXML
) {
598 console
.log(transport
.responseText
);
599 alert(__("Server error while trying to subscribe to specified feed."));
603 var result
= transport
.responseXML
.getElementsByTagName('result')[0];
604 var rc
= parseInt(result
.getAttribute('code'));
606 Form
.enable("feed_add_form");
613 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
615 if (inPreferences()) {
618 setTimeout('updateFeedList(false, false)', 50);
622 alert(__("Specified URL seems to be invalid."));
625 alert(__("Specified URL doesn't seem to contain any feeds."));
628 new Ajax
.Request("backend.php", {
629 parameters
: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url
),
630 onComplete: function(transport
) {
631 var result
= transport
.responseXML
.getElementsByTagName('urls')[0];
632 var feeds
= JSON
.parse(result
.firstChild
.nodeValue
);
633 var select
= document
.getElementById("faad_feeds_container_select");
635 while (select
.hasChildNodes()) {
636 select
.removeChild(elem
.firstChild
);
639 for (var feedUrl
in feeds
) {
640 select
.insert(new Option(feeds
[feedUrl
], feedUrl
, false));
643 if (count
> 5) count
= 5;
646 Effect
.Appear('fadd_feeds_container', {duration
: 0.5});
651 alert(__("Couldn't download the specified URL."));
654 alert(__("You are already subscribed to this feed."));
659 exception_error("subscribeToFeed", e
);
665 exception_error("subscribeToFeed", e
);
671 function filterCR(e
, f
)
676 key
= window
.event
.keyCode
; //IE
678 key
= e
.which
; //firefox
681 if (typeof f
!= 'undefined') {
692 function getInitParam(key
) {
693 return init_params
[key
];
696 function setInitParam(key
, value
) {
697 init_params
[key
] = value
;
700 function fatalError(code
, msg
, ext_info
) {
703 if (!ext_info
) ext_info
= "N/A";
706 window
.location
.href
= "tt-rss.php";
707 } else if (code
== 5) {
708 window
.location
.href
= "db-updater.php";
711 if (msg
== "") msg
= "Unknown error";
713 var ebc
= $("xebContent");
717 Element
.show("dialog_overlay");
718 Element
.show("errorBoxShadow");
719 Element
.hide("xebBtn");
722 if (ext_info
.responseText
) {
723 ext_info
= ext_info
.responseText
;
728 "<div><b>Error message:</b></div>" +
729 "<pre>" + msg
+ "</pre>" +
730 "<div><b>Additional information:</b></div>" +
731 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
736 exception_error("fatalError", e
);
740 function filterDlgCheckType(sender
) {
744 var ftype
= sender
[sender
.selectedIndex
].value
;
746 var form
= document
.forms
["filter_add_form"];
749 form
= document
.forms
["filter_edit_form"];
753 console
.log("filterDlgCheckType: can't find form!");
757 // if selected filter type is 5 (Date) enable the modifier dropbox
759 Element
.show("filter_dlg_date_mod_box");
760 Element
.show("filter_dlg_date_chk_box");
762 Element
.hide("filter_dlg_date_mod_box");
763 Element
.hide("filter_dlg_date_chk_box");
768 exception_error("filterDlgCheckType", e
);
773 function filterDlgCheckAction(sender
) {
777 var action
= sender
[sender
.selectedIndex
].value
;
779 var form
= document
.forms
["filter_add_form"];
782 form
= document
.forms
["filter_edit_form"];
786 console
.log("filterDlgCheckAction: can't find form!");
790 var action_param
= $("filter_dlg_param_box");
793 console
.log("filterDlgCheckAction: can't find action param box!");
797 // if selected action supports parameters, enable params field
798 if (action
== 4 || action
== 6 || action
== 7) {
799 Element
.show(action_param
);
801 Element
.show(form
.action_param
);
802 Element
.hide(form
.action_param_label
);
804 Element
.show(form
.action_param_label
);
805 Element
.hide(form
.action_param
);
808 Element
.hide(action_param
);
812 exception_error("filterDlgCheckAction", e
);
817 function filterDlgCheckDate() {
819 var form
= document
.forms
["filter_add_form"];
822 form
= document
.forms
["filter_edit_form"];
826 console
.log("filterDlgCheckAction: can't find form!");
830 var reg_exp
= form
.reg_exp
.value
;
832 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
834 new Ajax
.Request("backend.php", {
836 onComplete: function(transport
) {
838 var form
= document
.forms
["filter_add_form"];
841 form
= document
.forms
["filter_edit_form"];
844 if (transport
.responseXML
) {
845 var result
= transport
.responseXML
.getElementsByTagName("result")[0];
847 if (result
&& result
.firstChild
) {
848 if (result
.firstChild
.nodeValue
== "1") {
850 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#00ff00'});
857 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#ff0000'});
863 exception_error("filterDlgCheckDate", e
);
867 function explainError(code
) {
868 return displayDlg("explainError", code
);
871 function displayHelpInfobox(topic_id
) {
873 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
875 var w
= window
.open(url
, "ttrss_help",
876 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
880 function loading_set_progress(p
) {
882 if (p
< last_progress_point
|| !Element
.visible("overlay")) return;
884 console
.log("loading_set_progress : " + p
+ " (" + last_progress_point
+ ")");
886 var o
= $("l_progress_i");
888 // o.style.width = (p * 2) + "px";
890 new Effect
.Scale(o
, p
, {
892 scaleFrom
: last_progress_point
,
893 scaleMode
: { originalWidth
: 200 },
894 queue
: { position
: 'end', scope
: 'LSP-Q', limit
: 3 } });
896 last_progress_point
= p
;
899 exception_error("loading_set_progress", e
);
903 function remove_splash() {
904 if (Element
.visible("overlay")) {
905 console
.log("about to remove splash, OMG!");
906 Element
.hide("overlay");
907 console
.log("removed splash!");
911 function getSelectedFeedsFromBrowser() {
913 var list
= $$("#browseFeedList li[id*=FBROW]");
915 var selected
= new Array();
917 list
.each(function(child
) {
918 var id
= child
.id
.replace("FBROW-", "");
919 var cb
= $("FBCHK-" + id
);
929 function updateFeedBrowser() {
932 var query
= Form
.serialize("feed_browser");
934 Element
.show('feed_browser_spinner');
936 new Ajax
.Request("backend.php", {
938 onComplete: function(transport
) {
941 Element
.hide('feed_browser_spinner');
943 var c
= $("browseFeedList");
944 var r
= transport
.responseXML
.getElementsByTagName("content")[0];
945 var nr
= transport
.responseXML
.getElementsByTagName("num-results")[0];
946 var mode
= transport
.responseXML
.getElementsByTagName("mode")[0];
949 c
.innerHTML
= r
.firstChild
.nodeValue
;
952 if (parseInt(mode
.getAttribute("value")) == 2) {
953 Element
.show('feed_archive_remove');
955 Element
.hide('feed_archive_remove');
961 exception_error("updateFeedBrowser", e
);
966 function transport_error_check(transport
) {
968 if (transport
.responseXML
) {
969 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
972 var code
= error
.getAttribute("error-code");
973 var msg
= error
.getAttribute("error-msg");
975 fatalError(code
, msg
);
981 exception_error("check_for_error_xml", e
);
986 function strip_tags(s
) {
987 return s
.replace(/<\/?[^>]+(>|$)/g, "");
990 function truncate_string(s
, length
) {
991 if (!length
) length
= 30;
992 var tmp
= s
.substring(0, length
);
993 if (s
.length
> length
) tmp
+= "…";
997 function hotkey_prefix_timeout() {
1000 var date
= new Date();
1001 var ts
= Math
.round(date
.getTime() / 1000);
1003 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
1004 console
.log("hotkey_prefix seems to be stuck, aborting");
1005 hotkey_prefix_pressed
= false;
1006 hotkey_prefix
= false;
1007 Element
.hide('cmdline');
1010 setTimeout("hotkey_prefix_timeout()", 1000);
1013 exception_error("hotkey_prefix_timeout", e
);
1017 function hideAuxDlg() {
1019 Element
.hide('auxDlg');
1021 exception_error("hideAuxDlg", e
);
1025 function feedBrowserSubscribe() {
1028 var selected
= getSelectedFeedsFromBrowser();
1030 var mode
= document
.forms
['feed_browser'].mode
;
1032 mode
= mode
[mode
.selectedIndex
].value
;
1034 if (selected
.length
> 0) {
1037 notify_progress("Loading, please wait...", true);
1039 var query
= "?op=rpc&subop=massSubscribe&ids="+
1040 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1042 new Ajax
.Request("backend.php", {
1044 onComplete: function(transport
) {
1046 var nf
= transport
.responseXML
.getElementsByTagName('num-feeds')[0];
1047 var nf_value
= nf
.getAttribute("value");
1049 notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value
));
1051 if (inPreferences()) {
1054 setTimeout('updateFeedList(false, false)', 50);
1059 alert(__("No feeds are selected."));
1063 exception_error("feedBrowserSubscribe", e
);
1067 function feedArchiveRemove() {
1070 var selected
= getSelectedFeedsFromBrowser();
1072 if (selected
.length
> 0) {
1074 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1077 Element
.show('feed_browser_spinner');
1079 var query
= "?op=rpc&subop=remarchived&ids=" +
1080 param_escape(selected
.toString());;
1082 new Ajax
.Request("backend.php", {
1084 onComplete: function(transport
) {
1085 updateFeedBrowser();
1090 alert(__("No feeds are selected."));
1094 exception_error("feedArchiveRemove", e
);
1098 function uploadIconHandler(rc
) {
1102 notify_info("Upload complete.");
1103 if (inPreferences()) {
1106 setTimeout('updateFeedList(false, false)', 50);
1110 notify_error("Upload failed: icon is too big.");
1113 notify_error("Upload failed.");
1118 exception_error("uploadIconHandler", e
);
1122 function removeFeedIcon(id
) {
1126 if (confirm(__("Remove stored feed icon?"))) {
1127 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
1131 notify_progress("Removing feed icon...", true);
1133 new Ajax
.Request("backend.php", {
1135 onComplete: function(transport
) {
1136 notify_info("Feed icon removed.");
1137 if (inPreferences()) {
1140 setTimeout('updateFeedList(false, false)', 50);
1147 exception_error("uploadFeedIcon", e
);
1151 function uploadFeedIcon() {
1155 var file
= $("icon_file");
1157 if (file
.value
.length
== 0) {
1158 alert(__("Please select an image file to upload."));
1160 if (confirm(__("Upload new icon for this feed?"))) {
1161 notify_progress("Uploading, please wait...", true);
1169 exception_error("uploadFeedIcon", e
);
1173 function addLabel(select
, callback
) {
1177 var caption
= prompt(__("Please enter label caption:"), "");
1179 if (caption
!= undefined) {
1181 if (caption
== "") {
1182 alert(__("Can't create label: missing caption."));
1186 var query
= "?op=pref-labels&subop=add&caption=" +
1187 param_escape(caption
);
1190 query
+= "&output=select";
1192 notify_progress("Loading, please wait...", true);
1194 if (inPreferences() && !select
) active_tab
= "labelConfig";
1196 new Ajax
.Request("backend.php", {
1198 onComplete: function(transport
) {
1200 callback(transport
);
1201 } else if (inPreferences()) {
1202 infobox_submit_callback2(transport
);
1211 exception_error("addLabel", e
);
1215 function quickAddFeed() {
1216 displayDlg('quickAddFeed', '',
1217 function () {$('feed_url').focus();});
1220 function quickAddFilter() {
1221 displayDlg('quickAddFilter', '',
1222 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
1225 function unsubscribeFeed(feed_id
, title
) {
1227 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1229 if (title
== undefined || confirm(msg
)) {
1230 notify_progress("Removing feed...");
1232 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1234 new Ajax
.Request("backend.php", {
1236 onComplete: function(transport
) {
1240 if (inPreferences()) {
1243 dlg_frefresh_callback(transport
, feed_id
);
1253 function backend_sanity_check_callback(transport
) {
1257 if (sanity_check_done
) {
1258 fatalError(11, "Sanity check request received twice. This can indicate "+
1259 "presence of Firebug or some other disrupting extension. "+
1260 "Please disable it and try again.");
1264 if (!transport
.responseXML
) {
1266 fatalError(3, "Sanity check: Received reply is not XML",
1267 transport
.responseText
);
1272 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1275 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1279 var error_code
= reply
.getAttribute("error-code");
1281 if (error_code
&& error_code
!= 0) {
1282 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1285 console
.log("sanity check ok");
1287 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1290 console
.log('reading init-params...');
1292 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1297 console
.log("IP: " + k
+ " => " + v
);
1301 init_params
= params
;
1304 sanity_check_done
= true;
1306 init_second_stage();
1309 exception_error("backend_sanity_check_callback", e
, transport
);
1313 function has_local_storage() {
1316 return 'localStorage' in window && window['localStorage'] != null;
1322 function catSelectOnChange(elem
) {
1324 var value
= elem
[elem
.selectedIndex
].value
;
1325 var def
= elem
.getAttribute('default');
1327 if (value
== "ADD_CAT") {
1330 dropboxSelect(elem
, def
);
1332 elem
.selectedIndex
= 0;
1338 exception_error("catSelectOnChange", e
);
1342 function quickAddCat(elem
) {
1344 var cat
= prompt(__("Please enter category title:"));
1348 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1350 notify_progress("Loading, please wait...", true);
1352 new Ajax
.Request("backend.php", {
1354 onComplete: function (transport
) {
1355 var response
= transport
.responseXML
;
1356 var select
= response
.getElementsByTagName("select")[0];
1357 var options
= select
.getElementsByTagName("option");
1359 dropbox_replace_options(elem
, options
);
1368 exception_error("quickAddCat", e
);
1372 function genUrlChangeKey(feed
, is_cat
) {
1375 var ok
= confirm(__("Generate new syndication address for this feed?"));
1379 notify_progress("Trying to change address...", true);
1381 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1382 "&is_cat=" + param_escape(is_cat
);
1384 new Ajax
.Request("backend.php", {
1386 onComplete: function(transport
) {
1387 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
1389 var e
= $('gen_feed_url');
1393 new_link
= new_link
.firstChild
.nodeValue
;
1395 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1396 "&key=" + new_link
);
1398 e
.href
= e
.href
.replace(/\&key=.*$/,
1399 "&key=" + new_link
);
1401 new Effect
.Highlight(e
);
1406 notify_error("Could not change feed URL.");
1411 exception_error("genUrlChangeKey", e
);
1416 function labelSelectOnChange(elem
) {
1418 var value
= elem
[elem
.selectedIndex
].value
;
1419 var def
= elem
.getAttribute('default');
1421 if (value
== "ADD_LABEL") {
1424 dropboxSelect(elem
, def
);
1426 elem
.selectedIndex
= 0;
1428 addLabel(elem
, function(transport
) {
1432 var response
= transport
.responseXML
;
1433 var select
= response
.getElementsByTagName("select")[0];
1434 var options
= select
.getElementsByTagName("option");
1436 dropbox_replace_options(elem
, options
);
1440 exception_error("addLabel", e
);
1446 exception_error("labelSelectOnChange", e
);
1450 function dropbox_replace_options(elem
, options
) {
1453 while (elem
.hasChildNodes())
1454 elem
.removeChild(elem
.firstChild
);
1458 for (var i
= 0; i
< options
.length
; i
++) {
1459 var text
= options
[i
].firstChild
.nodeValue
;
1460 var value
= options
[i
].getAttribute("value");
1462 if (value
== undefined) value
= text
;
1464 var issel
= options
[i
].getAttribute("selected") == "1";
1466 var option
= new Option(text
, value
, issel
);
1468 if (options
[i
].getAttribute("disabled"))
1469 option
.setAttribute("disabled", true);
1471 elem
.insert(option
);
1473 if (issel
) sel_idx
= i
;
1476 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1477 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1480 exception_error("dropbox_replace_options", e
);
1484 // mode = all, none, invert
1485 function selectTableRows(id
, mode
) {
1487 var rows
= $(id
).rows
;
1489 for (var i
= 0; i
< rows
.length
; i
++) {
1493 if (row
.id
&& row
.className
) {
1494 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1495 var inputs
= rows
[i
].getElementsByTagName("input");
1497 for (var j
= 0; j
< inputs
.length
; j
++) {
1498 var input
= inputs
[j
];
1500 if (input
.getAttribute("type") == "checkbox" &&
1501 input
.id
.match(bare_id
)) {
1509 var issel
= row
.hasClassName("Selected");
1511 if (mode
== "all" && !issel
) {
1512 row
.addClassName("Selected");
1514 } else if (mode
== "none" && issel
) {
1515 row
.removeClassName("Selected");
1517 } else if (mode
== "invert") {
1520 row
.removeClassName("Selected");
1523 row
.addClassName("Selected");
1532 exception_error("selectTableRows", e
);
1537 function getSelectedTableRowIds(id
) {
1541 var elem_rows
= $(id
).rows
;
1543 for (i
= 0; i
< elem_rows
.length
; i
++) {
1544 if (elem_rows
[i
].hasClassName("Selected")) {
1545 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1551 exception_error("getSelectedTableRowIds", e
);