]>
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;
7 /* add method to remove element from array */
9 Array
.prototype.remove = function(s
) {
10 for (var i
=0; i
< this.length
; i
++) {
11 if (s
== this[i
]) this.splice(i
, 1);
15 /* create console.log if it doesn't exist */
17 if (!window
.console
) console
= {};
18 console
.log
= console
.log
|| function(msg
) { };
19 console
.warn
= console
.warn
|| function(msg
) { };
20 console
.error
= console
.error
|| function(msg
) { };
22 function exception_error(location
, e
, ext_info
) {
23 var msg
= format_exception_error(location
, e
);
25 if (!ext_info
) ext_info
= false;
30 if (ext_info
.responseText
) {
31 ext_info
= ext_info
.responseText
;
35 var content
= "<div class=\"fatalError\">" +
36 "<pre>" + msg
+ "</pre>";
39 content
+= "<div><b>Additional information:</b></div>" +
40 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
43 content
+= "<div><b>Stack trace:</b></div>" +
44 "<textarea readonly=\"1\">" + e
.stack
+ "</textarea>";
46 // content += "<div style='text-align : center'>" +
47 // "<button onclick=\"closeInfoBox()\">" +
48 // "Close this window" + "</button></div>";
52 // TODO: add code to automatically report errors to tt-rss.org
54 var dialog
= new dijit
.Dialog({
55 title
: "Unhandled exception",
56 style
: "width: 600px",
67 function format_exception_error(location
, e
) {
71 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
73 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
74 "\nFunction: " + location
+ "()" +
75 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
77 } else if (e
.description
) {
78 msg
= "Exception: " + e
.description
+ "\nFunction: " + location
+ "()";
80 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
83 console
.error("EXCEPTION: " + msg
);
89 function disableHotkeys() {
90 hotkeys_enabled
= false;
93 function enableHotkeys() {
94 hotkeys_enabled
= true;
97 function param_escape(arg
) {
98 if (typeof encodeURIComponent
!= 'undefined')
99 return encodeURIComponent(arg
);
104 function param_unescape(arg
) {
105 if (typeof decodeURIComponent
!= 'undefined')
106 return decodeURIComponent(arg
);
108 return unescape(arg
);
111 var notify_hide_timerid
= false;
113 function hide_notify() {
116 n
.style
.display
= "none";
120 function notify_silent_next() {
121 notify_silent
= true;
124 function notify_real(msg
, no_hide
, n_type
) {
127 notify_silent
= false;
132 var nb
= $("notify_body");
134 if (!n
|| !nb
) return;
136 if (notify_hide_timerid
) {
137 window
.clearTimeout(notify_hide_timerid
);
141 if (n
.style
.display
== "block") {
142 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
146 n
.style
.display
= "block";
158 if (typeof __
!= 'undefined') {
163 n
.className
= "notify";
164 } else if (n_type
== 2) {
165 n
.className
= "notifyProgress";
166 msg
= "<img src='"+getInitParam("sign_progress")+"'> " + msg
;
167 } else if (n_type
== 3) {
168 n
.className
= "notifyError";
169 msg
= "<img src='"+getInitParam("sign_excl")+"'> " + msg
;
170 } else if (n_type
== 4) {
171 n
.className
= "notifyInfo";
172 msg
= "<img src='"+getInitParam("sign_info")+"'> " + msg
;
175 // msg = "<img src='images/live_com_loading.gif'> " + msg;
180 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
184 function notify(msg
, no_hide
) {
185 notify_real(msg
, no_hide
, 1);
188 function notify_progress(msg
, no_hide
) {
189 notify_real(msg
, no_hide
, 2);
192 function notify_error(msg
, no_hide
) {
193 notify_real(msg
, no_hide
, 3);
197 function notify_info(msg
, no_hide
) {
198 notify_real(msg
, no_hide
, 4);
201 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
207 d
.setTime(d
.getTime() + (lifetime
* 1000));
210 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
212 int_setCookie(name
, value
, d
, path
, domain
, secure
);
216 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
217 document
.cookie
= name
+ "=" + escape(value
) +
218 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
219 ((path
) ? "; path=" + path
: "") +
220 ((domain
) ? "; domain=" + domain
: "") +
221 ((secure
) ? "; secure" : "");
224 function delCookie(name
, path
, domain
) {
225 if (getCookie(name
)) {
226 document
.cookie
= name
+ "=" +
227 ((path
) ? ";path=" + path
: "") +
228 ((domain
) ? ";domain=" + domain
: "" ) +
229 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
234 function getCookie(name
) {
236 var dc
= document
.cookie
;
237 var prefix
= name
+ "=";
238 var begin
= dc
.indexOf("; " + prefix
);
240 begin
= dc
.indexOf(prefix
);
241 if (begin
!= 0) return null;
246 var end
= document
.cookie
.indexOf(";", begin
);
250 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
253 function gotoPreferences() {
254 document
.location
.href
= "prefs.php";
257 function gotoMain() {
258 document
.location
.href
= "tt-rss.php";
261 function gotoExportOpml() {
262 document
.location
.href
= "opml.php?op=Export";
266 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
267 * * @author Sundar Dorai-Raj
268 * * Email: sdoraira@vt.edu
269 * * This program is free software; you can redistribute it and/or
270 * * modify it under the terms of the GNU General Public License
271 * * as published by the Free Software Foundation; either version 2
272 * * of the License, or (at your option) any later version,
273 * * provided that any use properly credits the author.
274 * * This program is distributed in the hope that it will be useful,
275 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
276 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
277 * * GNU General Public License for more details at http://www.gnu.org * * */
279 var numbers
=".0123456789";
280 function isNumeric(x
) {
281 // is x a String or a character?
283 // remove negative sign
285 for(j
=0;j
<x
.length
;j
++) {
286 // call isNumeric recursively for each character
287 number
=isNumeric(x
.substring(j
,j
+1));
288 if(!number
) return number
;
293 // if x is number return true
294 if(numbers
.indexOf(x
)>=0) return true;
300 function toggleSelectRowById(sender
, id
) {
302 return toggleSelectRow(sender
, row
);
305 function toggleSelectListRow(sender
) {
306 var row
= sender
.parentNode
;
307 return toggleSelectRow(sender
, row
);
310 function tSR(sender
, row
) {
311 return toggleSelectRow(sender
, row
);
314 function toggleSelectRow(sender
, row
) {
316 if (!row
) row
= sender
.parentNode
.parentNode
;
318 if (sender
.checked
&& !row
.hasClassName('Selected'))
319 row
.addClassName('Selected');
321 row
.removeClassName('Selected');
324 function checkboxToggleElement(elem
, id
) {
326 Effect
.Appear(id
, {duration
: 0.5});
328 Effect
.Fade(id
, {duration
: 0.5});
332 function dropboxSelect(e
, v
) {
333 for (i
= 0; i
< e
.length
; i
++) {
334 if (e
[i
].value
== v
) {
341 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
342 // bugfixed just a little bit :-)
343 function getURLParam(strParamName
){
345 var strHref
= window
.location
.href
;
347 if (strHref
.indexOf("#") == strHref
.length
-1) {
348 strHref
= strHref
.substring(0, strHref
.length
-1);
351 if ( strHref
.indexOf("?") > -1 ){
352 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
353 var aQueryString
= strQueryString
.split("&");
354 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
355 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
356 var aParam
= aQueryString
[iParam
].split("=");
357 strReturn
= aParam
[1];
365 function leading_zero(p
) {
367 if (s
.length
== 1) s
= "0" + s
;
371 function make_timestamp() {
374 return leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
375 ":" + leading_zero(d
.getSeconds());
379 function closeErrorBox() {
381 if (Element
.visible("errorBoxShadow")) {
382 Element
.hide("dialog_overlay");
383 Element
.hide("errorBoxShadow");
391 function closeInfoBox(cleanup
) {
395 var dialog
= dialogs
.pop();
401 //exception_error("closeInfoBox", e);
407 function displayDlg(id
, param
, callback
) {
409 notify_progress("Loading, please wait...", true);
411 var query
= "?op=dlg&id=" +
412 param_escape(id
) + "¶m=" + param_escape(param
);
414 new Ajax
.Request("backend.php", {
416 onComplete: function (transport
) {
417 infobox_callback2(transport
);
418 if (callback
) callback(transport
);
424 function infobox_submit_callback2(transport
) {
428 // called from prefs, reload tab
429 if (typeof active_tab
!= 'undefined' && active_tab
) {
430 selectTab(active_tab
, false);
434 if (transport
.responseText
) {
435 notify_info(transport
.responseText
);
439 function infobox_callback2(transport
) {
442 //console.log("infobox_callback2");
446 var dtitle
= "Dialog";
448 if (transport
.responseXML
) {
449 var dlg
= transport
.responseXML
.getElementsByTagName("dlg")[0];
451 var title
= transport
.responseXML
.getElementsByTagName("title")[0];
453 title
= title
.firstChild
.nodeValue
;
455 var content
= transport
.responseXML
.getElementsByTagName("content")[0];
457 content
= content
.firstChild
.nodeValue
;
460 content
= transport
.responseText
;
463 var dialog
= new dijit
.Dialog({
465 style
: "width: 600px",
466 onCancel: function() {
467 dialogs
.remove(this);
470 onExecute: function() {
471 dialogs
.remove(this);
474 onClose: function() {
475 dialogs
.remove(this);
482 dialogs
.push(dialog
);
486 exception_error("infobox_callback2", e
);
490 function createFilter() {
494 var form
= document
.forms
['filter_add_form'];
495 var reg_exp
= form
.reg_exp
.value
;
498 alert(__("Can't add filter: nothing to match on."));
502 var query
= "?op=rpc&subop=verifyRegexp®_exp=" + param_escape(reg_exp
);
504 notify_progress("Verifying regular expression...");
506 new Ajax
.Request("backend.php", {
508 onComplete: function(transport
) {
509 handle_rpc_reply(transport
);
511 var response
= transport
.responseXML
;
514 var s
= response
.getElementsByTagName("status")[0].firstChild
.nodeValue
;
518 if (s
== "INVALID") {
519 alert("Match regular expression seems to be invalid.");
523 var query
= Form
.serialize("filter_add_form");
525 // we can be called from some other tab in Prefs
526 if (typeof active_tab
!= 'undefined' && active_tab
) {
527 active_tab
= "filterConfig";
530 new Ajax
.Request("backend.php?" + query
, {
531 onComplete: function (transport
) {
532 infobox_submit_callback2(transport
);
542 exception_error("createFilter", e
);
546 function isValidURL(s
) {
547 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
550 function subscribeToFeed() {
554 var form
= document
.forms
['feed_add_form'];
555 var feed_url
= form
.feed_url
.value
;
557 if (feed_url
== "") {
558 alert(__("Can't subscribe: no feed URL given."));
562 notify_progress(__("Subscribing to feed..."), true);
564 var query
= Form
.serialize("feed_add_form");
566 console
.log("subscribe q: " + query
);
568 Form
.disable("feed_add_form");
570 new Ajax
.Request("backend.php", {
572 onComplete: function(transport
) {
573 //dlg_frefresh_callback(transport);
577 if (!transport
.responseXML
) {
578 console
.log(transport
.responseText
);
579 alert(__("Server error while trying to subscribe to specified feed."));
583 var result
= transport
.responseXML
.getElementsByTagName('result')[0];
584 var rc
= parseInt(result
.getAttribute('code'));
586 Form
.enable("feed_add_form");
593 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
595 if (inPreferences()) {
598 setTimeout('updateFeedList(false, false)', 50);
602 alert(__("Specified URL seems to be invalid."));
605 alert(__("Specified URL doesn't seem to contain any feeds."));
608 new Ajax
.Request("backend.php", {
609 parameters
: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url
),
610 onComplete: function(transport
) {
611 var result
= transport
.responseXML
.getElementsByTagName('urls')[0];
612 var feeds
= JSON
.parse(result
.firstChild
.nodeValue
);
613 var select
= document
.getElementById("faad_feeds_container_select");
615 while (select
.hasChildNodes()) {
616 select
.removeChild(elem
.firstChild
);
619 for (var feedUrl
in feeds
) {
620 select
.insert(new Option(feeds
[feedUrl
], feedUrl
, false));
623 if (count
> 5) count
= 5;
626 Effect
.Appear('fadd_feeds_container', {duration
: 0.5});
631 alert(__("Couldn't download the specified URL."));
634 alert(__("You are already subscribed to this feed."));
639 exception_error("subscribeToFeed", e
);
645 exception_error("subscribeToFeed", e
);
651 function filterCR(e
, f
)
656 key
= window
.event
.keyCode
; //IE
658 key
= e
.which
; //firefox
661 if (typeof f
!= 'undefined') {
672 function getInitParam(key
) {
673 return init_params
[key
];
676 function setInitParam(key
, value
) {
677 init_params
[key
] = value
;
680 function fatalError(code
, msg
, ext_info
) {
683 if (!ext_info
) ext_info
= "N/A";
686 window
.location
.href
= "tt-rss.php";
687 } else if (code
== 5) {
688 window
.location
.href
= "db-updater.php";
691 if (msg
== "") msg
= "Unknown error";
693 var ebc
= $("xebContent");
697 Element
.show("dialog_overlay");
698 Element
.show("errorBoxShadow");
699 Element
.hide("xebBtn");
702 if (ext_info
.responseText
) {
703 ext_info
= ext_info
.responseText
;
708 "<div><b>Error message:</b></div>" +
709 "<pre>" + msg
+ "</pre>" +
710 "<div><b>Additional information:</b></div>" +
711 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
716 exception_error("fatalError", e
);
720 function filterDlgCheckType(sender
) {
724 var ftype
= sender
[sender
.selectedIndex
].value
;
726 var form
= document
.forms
["filter_add_form"];
729 form
= document
.forms
["filter_edit_form"];
733 console
.log("filterDlgCheckType: can't find form!");
737 // if selected filter type is 5 (Date) enable the modifier dropbox
739 Element
.show("filter_dlg_date_mod_box");
740 Element
.show("filter_dlg_date_chk_box");
742 Element
.hide("filter_dlg_date_mod_box");
743 Element
.hide("filter_dlg_date_chk_box");
748 exception_error("filterDlgCheckType", e
);
753 function filterDlgCheckAction(sender
) {
757 var action
= sender
[sender
.selectedIndex
].value
;
759 var form
= document
.forms
["filter_add_form"];
762 form
= document
.forms
["filter_edit_form"];
766 console
.log("filterDlgCheckAction: can't find form!");
770 var action_param
= $("filter_dlg_param_box");
773 console
.log("filterDlgCheckAction: can't find action param box!");
777 // if selected action supports parameters, enable params field
778 if (action
== 4 || action
== 6 || action
== 7) {
779 Element
.show(action_param
);
781 Element
.show(form
.action_param
);
782 Element
.hide(form
.action_param_label
);
784 Element
.show(form
.action_param_label
);
785 Element
.hide(form
.action_param
);
788 Element
.hide(action_param
);
792 exception_error("filterDlgCheckAction", e
);
797 function filterDlgCheckDate() {
799 var form
= document
.forms
["filter_add_form"];
802 form
= document
.forms
["filter_edit_form"];
806 console
.log("filterDlgCheckAction: can't find form!");
810 var reg_exp
= form
.reg_exp
.value
;
812 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
814 new Ajax
.Request("backend.php", {
816 onComplete: function(transport
) {
818 var form
= document
.forms
["filter_add_form"];
821 form
= document
.forms
["filter_edit_form"];
824 if (transport
.responseXML
) {
825 var result
= transport
.responseXML
.getElementsByTagName("result")[0];
827 if (result
&& result
.firstChild
) {
828 if (result
.firstChild
.nodeValue
== "1") {
830 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#00ff00'});
837 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#ff0000'});
843 exception_error("filterDlgCheckDate", e
);
847 function explainError(code
) {
848 return displayDlg("explainError", code
);
851 function displayHelpInfobox(topic_id
) {
853 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
855 var w
= window
.open(url
, "ttrss_help",
856 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
860 function loading_set_progress(p
) {
862 if (p
< last_progress_point
|| !Element
.visible("overlay")) return;
864 console
.log("loading_set_progress : " + p
+ " (" + last_progress_point
+ ")");
866 var o
= $("l_progress_i");
868 // o.style.width = (p * 2) + "px";
870 new Effect
.Scale(o
, p
, {
872 scaleFrom
: last_progress_point
,
873 scaleMode
: { originalWidth
: 200 },
874 queue
: { position
: 'end', scope
: 'LSP-Q', limit
: 3 } });
876 last_progress_point
= p
;
879 exception_error("loading_set_progress", e
);
883 function remove_splash() {
884 if (Element
.visible("overlay")) {
885 console
.log("about to remove splash, OMG!");
886 Element
.hide("overlay");
887 console
.log("removed splash!");
891 function getSelectedFeedsFromBrowser() {
893 var list
= $$("#browseFeedList li[id*=FBROW]");
895 var selected
= new Array();
897 list
.each(function(child
) {
898 var id
= child
.id
.replace("FBROW-", "");
899 var cb
= $("FBCHK-" + id
);
909 function updateFeedBrowser() {
912 var query
= Form
.serialize("feed_browser");
914 Element
.show('feed_browser_spinner');
916 new Ajax
.Request("backend.php", {
918 onComplete: function(transport
) {
921 Element
.hide('feed_browser_spinner');
923 var c
= $("browseFeedList");
924 var r
= transport
.responseXML
.getElementsByTagName("content")[0];
925 var nr
= transport
.responseXML
.getElementsByTagName("num-results")[0];
926 var mode
= transport
.responseXML
.getElementsByTagName("mode")[0];
929 c
.innerHTML
= r
.firstChild
.nodeValue
;
932 if (parseInt(mode
.getAttribute("value")) == 2) {
933 Element
.show('feed_archive_remove');
935 Element
.hide('feed_archive_remove');
941 exception_error("updateFeedBrowser", e
);
946 function transport_error_check(transport
) {
948 if (transport
.responseXML
) {
949 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
952 var code
= error
.getAttribute("error-code");
953 var msg
= error
.getAttribute("error-msg");
955 fatalError(code
, msg
);
961 exception_error("check_for_error_xml", e
);
966 function strip_tags(s
) {
967 return s
.replace(/<\/?[^>]+(>|$)/g, "");
970 function truncate_string(s
, length
) {
971 if (!length
) length
= 30;
972 var tmp
= s
.substring(0, length
);
973 if (s
.length
> length
) tmp
+= "…";
977 function hotkey_prefix_timeout() {
980 var date
= new Date();
981 var ts
= Math
.round(date
.getTime() / 1000);
983 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
984 console
.log("hotkey_prefix seems to be stuck, aborting");
985 hotkey_prefix_pressed
= false;
986 hotkey_prefix
= false;
987 Element
.hide('cmdline');
990 setTimeout("hotkey_prefix_timeout()", 1000);
993 exception_error("hotkey_prefix_timeout", e
);
997 function hideAuxDlg() {
999 Element
.hide('auxDlg');
1001 exception_error("hideAuxDlg", e
);
1005 function feedBrowserSubscribe() {
1008 var selected
= getSelectedFeedsFromBrowser();
1010 var mode
= document
.forms
['feed_browser'].mode
;
1012 mode
= mode
[mode
.selectedIndex
].value
;
1014 if (selected
.length
> 0) {
1017 notify_progress("Loading, please wait...", true);
1019 var query
= "?op=rpc&subop=massSubscribe&ids="+
1020 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1022 new Ajax
.Request("backend.php", {
1024 onComplete: function(transport
) {
1026 var nf
= transport
.responseXML
.getElementsByTagName('num-feeds')[0];
1027 var nf_value
= nf
.getAttribute("value");
1029 notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value
));
1031 if (inPreferences()) {
1034 setTimeout('updateFeedList(false, false)', 50);
1039 alert(__("No feeds are selected."));
1043 exception_error("feedBrowserSubscribe", e
);
1047 function feedArchiveRemove() {
1050 var selected
= getSelectedFeedsFromBrowser();
1052 if (selected
.length
> 0) {
1054 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1057 Element
.show('feed_browser_spinner');
1059 var query
= "?op=rpc&subop=remarchived&ids=" +
1060 param_escape(selected
.toString());;
1062 new Ajax
.Request("backend.php", {
1064 onComplete: function(transport
) {
1065 updateFeedBrowser();
1070 alert(__("No feeds are selected."));
1074 exception_error("feedArchiveRemove", e
);
1078 function uploadIconHandler(rc
) {
1082 notify_info("Upload complete.");
1083 if (inPreferences()) {
1086 setTimeout('updateFeedList(false, false)', 50);
1090 notify_error("Upload failed: icon is too big.");
1093 notify_error("Upload failed.");
1098 exception_error("uploadIconHandler", e
);
1102 function removeFeedIcon(id
) {
1106 if (confirm(__("Remove stored feed icon?"))) {
1107 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
1111 notify_progress("Removing feed icon...", true);
1113 new Ajax
.Request("backend.php", {
1115 onComplete: function(transport
) {
1116 notify_info("Feed icon removed.");
1117 if (inPreferences()) {
1120 setTimeout('updateFeedList(false, false)', 50);
1127 exception_error("uploadFeedIcon", e
);
1131 function uploadFeedIcon() {
1135 var file
= $("icon_file");
1137 if (file
.value
.length
== 0) {
1138 alert(__("Please select an image file to upload."));
1140 if (confirm(__("Upload new icon for this feed?"))) {
1141 notify_progress("Uploading, please wait...", true);
1149 exception_error("uploadFeedIcon", e
);
1153 function addLabel(select
, callback
) {
1157 var caption
= prompt(__("Please enter label caption:"), "");
1159 if (caption
!= undefined) {
1161 if (caption
== "") {
1162 alert(__("Can't create label: missing caption."));
1166 var query
= "?op=pref-labels&subop=add&caption=" +
1167 param_escape(caption
);
1170 query
+= "&output=select";
1172 notify_progress("Loading, please wait...", true);
1174 if (inPreferences() && !select
) active_tab
= "labelConfig";
1176 new Ajax
.Request("backend.php", {
1178 onComplete: function(transport
) {
1180 callback(transport
);
1181 } else if (inPreferences()) {
1182 infobox_submit_callback2(transport
);
1191 exception_error("addLabel", e
);
1195 function quickAddFeed() {
1196 displayDlg('quickAddFeed', '',
1197 function () {$('feed_url').focus();});
1200 function quickAddFilter() {
1201 displayDlg('quickAddFilter', '',
1202 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
1205 function unsubscribeFeed(feed_id
, title
) {
1207 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1209 if (title
== undefined || confirm(msg
)) {
1210 notify_progress("Removing feed...");
1212 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1214 new Ajax
.Request("backend.php", {
1216 onComplete: function(transport
) {
1220 if (inPreferences()) {
1223 dlg_frefresh_callback(transport
, feed_id
);
1233 function backend_sanity_check_callback(transport
) {
1237 if (sanity_check_done
) {
1238 fatalError(11, "Sanity check request received twice. This can indicate "+
1239 "presence of Firebug or some other disrupting extension. "+
1240 "Please disable it and try again.");
1244 if (!transport
.responseXML
) {
1246 fatalError(3, "Sanity check: Received reply is not XML",
1247 transport
.responseText
);
1252 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1255 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1259 var error_code
= reply
.getAttribute("error-code");
1261 if (error_code
&& error_code
!= 0) {
1262 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1265 console
.log("sanity check ok");
1267 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1270 console
.log('reading init-params...');
1272 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1277 console
.log("IP: " + k
+ " => " + v
);
1281 init_params
= params
;
1284 sanity_check_done
= true;
1286 init_second_stage();
1289 exception_error("backend_sanity_check_callback", e
, transport
);
1293 function has_local_storage() {
1296 return 'localStorage' in window && window['localStorage'] != null;
1302 function catSelectOnChange(elem
) {
1304 var value
= elem
[elem
.selectedIndex
].value
;
1305 var def
= elem
.getAttribute('default');
1307 if (value
== "ADD_CAT") {
1310 dropboxSelect(elem
, def
);
1312 elem
.selectedIndex
= 0;
1318 exception_error("catSelectOnChange", e
);
1322 function quickAddCat(elem
) {
1324 var cat
= prompt(__("Please enter category title:"));
1328 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1330 notify_progress("Loading, please wait...", true);
1332 new Ajax
.Request("backend.php", {
1334 onComplete: function (transport
) {
1335 var response
= transport
.responseXML
;
1336 var select
= response
.getElementsByTagName("select")[0];
1337 var options
= select
.getElementsByTagName("option");
1339 dropbox_replace_options(elem
, options
);
1348 exception_error("quickAddCat", e
);
1352 function genUrlChangeKey(feed
, is_cat
) {
1355 var ok
= confirm(__("Generate new syndication address for this feed?"));
1359 notify_progress("Trying to change address...", true);
1361 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1362 "&is_cat=" + param_escape(is_cat
);
1364 new Ajax
.Request("backend.php", {
1366 onComplete: function(transport
) {
1367 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
1369 var e
= $('gen_feed_url');
1373 new_link
= new_link
.firstChild
.nodeValue
;
1375 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1376 "&key=" + new_link
);
1378 e
.href
= e
.href
.replace(/\&key=.*$/,
1379 "&key=" + new_link
);
1381 new Effect
.Highlight(e
);
1386 notify_error("Could not change feed URL.");
1391 exception_error("genUrlChangeKey", e
);
1396 function labelSelectOnChange(elem
) {
1398 var value
= elem
[elem
.selectedIndex
].value
;
1399 var def
= elem
.getAttribute('default');
1401 if (value
== "ADD_LABEL") {
1404 dropboxSelect(elem
, def
);
1406 elem
.selectedIndex
= 0;
1408 addLabel(elem
, function(transport
) {
1412 var response
= transport
.responseXML
;
1413 var select
= response
.getElementsByTagName("select")[0];
1414 var options
= select
.getElementsByTagName("option");
1416 dropbox_replace_options(elem
, options
);
1420 exception_error("addLabel", e
);
1426 exception_error("labelSelectOnChange", e
);
1430 function dropbox_replace_options(elem
, options
) {
1433 while (elem
.hasChildNodes())
1434 elem
.removeChild(elem
.firstChild
);
1438 for (var i
= 0; i
< options
.length
; i
++) {
1439 var text
= options
[i
].firstChild
.nodeValue
;
1440 var value
= options
[i
].getAttribute("value");
1442 if (value
== undefined) value
= text
;
1444 var issel
= options
[i
].getAttribute("selected") == "1";
1446 var option
= new Option(text
, value
, issel
);
1448 if (options
[i
].getAttribute("disabled"))
1449 option
.setAttribute("disabled", true);
1451 elem
.insert(option
);
1453 if (issel
) sel_idx
= i
;
1456 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1457 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1460 exception_error("dropbox_replace_options", e
);
1464 // mode = all, none, invert
1465 function selectTableRows(id
, mode
) {
1467 var rows
= $(id
).rows
;
1469 for (var i
= 0; i
< rows
.length
; i
++) {
1473 if (row
.id
&& row
.className
) {
1474 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1475 var inputs
= rows
[i
].getElementsByTagName("input");
1477 for (var j
= 0; j
< inputs
.length
; j
++) {
1478 var input
= inputs
[j
];
1480 if (input
.getAttribute("type") == "checkbox" &&
1481 input
.id
.match(bare_id
)) {
1489 var issel
= row
.hasClassName("Selected");
1491 if (mode
== "all" && !issel
) {
1492 row
.addClassName("Selected");
1494 } else if (mode
== "none" && issel
) {
1495 row
.removeClassName("Selected");
1497 } else if (mode
== "invert") {
1500 row
.removeClassName("Selected");
1503 row
.addClassName("Selected");
1512 exception_error("selectTableRows", e
);
1517 function getSelectedTableRowIds(id
) {
1521 var elem_rows
= $(id
).rows
;
1523 for (i
= 0; i
< elem_rows
.length
; i
++) {
1524 if (elem_rows
[i
].hasClassName("Selected")) {
1525 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1531 exception_error("getSelectedTableRowIds", e
);