]>
git.wh0rd.org - tt-rss.git/blob - functions.js
1 var hotkeys_enabled
= true;
2 var notify_silent
= false;
3 var last_progress_point
= 0;
4 var sanity_check_done
= false;
6 /* add method to remove element from array */
8 Array
.prototype.remove = function(s
) {
9 for (var i
=0; i
< this.length
; i
++) {
10 if (s
== this[i
]) this.splice(i
, 1);
14 /* create console.log if it doesn't exist */
16 if (!window
.console
) console
= {};
17 console
.log
= console
.log
|| function(msg
) { };
18 console
.warn
= console
.warn
|| function(msg
) { };
19 console
.error
= console
.error
|| function(msg
) { };
21 function exception_error(location
, e
, ext_info
) {
22 var msg
= format_exception_error(location
, e
);
24 if (!ext_info
) ext_info
= false;
30 var ebc
= $("xebContent");
34 Element
.show("dialog_overlay");
35 Element
.show("errorBoxShadow");
38 if (ext_info
.responseText
) {
39 ext_info
= ext_info
.responseText
;
44 "<div><b>Error message:</b></div>" +
45 "<pre>" + msg
+ "</pre>";
48 ebc
.innerHTML
+= "<div><b>Additional information:</b></div>" +
49 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
52 ebc
.innerHTML
+= "<div><b>Stack trace:</b></div>" +
53 "<textarea readonly=\"1\">" + e
.stack
+ "</textarea>";
66 function format_exception_error(location
, e
) {
70 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
72 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
73 "\nFunction: " + location
+ "()" +
74 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
76 } else if (e
.description
) {
77 msg
= "Exception: " + e
.description
+ "\nFunction: " + location
+ "()";
79 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
82 console
.error("EXCEPTION: " + msg
);
88 function disableHotkeys() {
89 hotkeys_enabled
= false;
92 function enableHotkeys() {
93 hotkeys_enabled
= true;
96 function param_escape(arg
) {
97 if (typeof encodeURIComponent
!= 'undefined')
98 return encodeURIComponent(arg
);
103 function param_unescape(arg
) {
104 if (typeof decodeURIComponent
!= 'undefined')
105 return decodeURIComponent(arg
);
107 return unescape(arg
);
110 var notify_hide_timerid
= false;
112 function hide_notify() {
115 n
.style
.display
= "none";
119 function notify_silent_next() {
120 notify_silent
= true;
123 function notify_real(msg
, no_hide
, n_type
) {
126 notify_silent
= false;
131 var nb
= $("notify_body");
133 if (!n
|| !nb
) return;
135 if (notify_hide_timerid
) {
136 window
.clearTimeout(notify_hide_timerid
);
140 if (n
.style
.display
== "block") {
141 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
145 n
.style
.display
= "block";
157 if (typeof __
!= 'undefined') {
162 n
.className
= "notify";
163 } else if (n_type
== 2) {
164 n
.className
= "notifyProgress";
165 msg
= "<img src='"+getInitParam("sign_progress")+"'> " + msg
;
166 } else if (n_type
== 3) {
167 n
.className
= "notifyError";
168 msg
= "<img src='"+getInitParam("sign_excl")+"'> " + msg
;
169 } else if (n_type
== 4) {
170 n
.className
= "notifyInfo";
171 msg
= "<img src='"+getInitParam("sign_info")+"'> " + msg
;
174 // msg = "<img src='images/live_com_loading.gif'> " + msg;
179 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
183 function notify(msg
, no_hide
) {
184 notify_real(msg
, no_hide
, 1);
187 function notify_progress(msg
, no_hide
) {
188 notify_real(msg
, no_hide
, 2);
191 function notify_error(msg
, no_hide
) {
192 notify_real(msg
, no_hide
, 3);
196 function notify_info(msg
, no_hide
) {
197 notify_real(msg
, no_hide
, 4);
200 function cleanSelected(element
) {
201 var content
= $(element
);
203 for (i
= 0; i
< content
.rows
.length
; i
++) {
204 content
.rows
[i
].className
= content
.rows
[i
].className
.replace("Selected", "");
208 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
214 d
.setTime(d
.getTime() + (lifetime
* 1000));
217 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
219 int_setCookie(name
, value
, d
, path
, domain
, secure
);
223 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
224 document
.cookie
= name
+ "=" + escape(value
) +
225 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
226 ((path
) ? "; path=" + path
: "") +
227 ((domain
) ? "; domain=" + domain
: "") +
228 ((secure
) ? "; secure" : "");
231 function delCookie(name
, path
, domain
) {
232 if (getCookie(name
)) {
233 document
.cookie
= name
+ "=" +
234 ((path
) ? ";path=" + path
: "") +
235 ((domain
) ? ";domain=" + domain
: "" ) +
236 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
241 function getCookie(name
) {
243 var dc
= document
.cookie
;
244 var prefix
= name
+ "=";
245 var begin
= dc
.indexOf("; " + prefix
);
247 begin
= dc
.indexOf(prefix
);
248 if (begin
!= 0) return null;
253 var end
= document
.cookie
.indexOf(";", begin
);
257 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
260 function gotoPreferences() {
261 document
.location
.href
= "prefs.php";
264 function gotoMain() {
265 document
.location
.href
= "tt-rss.php";
268 function gotoExportOpml() {
269 document
.location
.href
= "opml.php?op=Export";
273 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
274 * * @author Sundar Dorai-Raj
275 * * Email: sdoraira@vt.edu
276 * * This program is free software; you can redistribute it and/or
277 * * modify it under the terms of the GNU General Public License
278 * * as published by the Free Software Foundation; either version 2
279 * * of the License, or (at your option) any later version,
280 * * provided that any use properly credits the author.
281 * * This program is distributed in the hope that it will be useful,
282 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
283 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
284 * * GNU General Public License for more details at http://www.gnu.org * * */
286 var numbers
=".0123456789";
287 function isNumeric(x
) {
288 // is x a String or a character?
290 // remove negative sign
292 for(j
=0;j
<x
.length
;j
++) {
293 // call isNumeric recursively for each character
294 number
=isNumeric(x
.substring(j
,j
+1));
295 if(!number
) return number
;
300 // if x is number return true
301 if(numbers
.indexOf(x
)>=0) return true;
307 function toggleSelectRowById(sender
, id
) {
310 if (sender
.checked
) {
311 if (!row
.className
.match("Selected")) {
312 row
.className
= row
.className
+ "Selected";
315 if (row
.className
.match("Selected")) {
316 row
.className
= row
.className
.replace("Selected", "");
321 function toggleSelectListRow(sender
) {
322 var parent_row
= sender
.parentNode
;
324 if (sender
.checked
) {
325 if (!parent_row
.className
.match("Selected")) {
326 parent_row
.className
= parent_row
.className
+ "Selected";
329 if (parent_row
.className
.match("Selected")) {
330 parent_row
.className
= parent_row
.className
.replace("Selected", "");
335 function tSR(sender
) {
336 return toggleSelectRow(sender
);
339 function toggleSelectRow(sender
) {
340 var parent_row
= sender
.parentNode
.parentNode
;
342 if (sender
.checked
) {
343 if (!parent_row
.className
.match("Selected")) {
344 parent_row
.className
= parent_row
.className
+ "Selected";
347 if (parent_row
.className
.match("Selected")) {
348 parent_row
.className
= parent_row
.className
.replace("Selected", "");
353 function checkboxToggleElement(elem
, id
) {
355 Effect
.Appear(id
, {duration
: 0.5});
357 Effect
.Fade(id
, {duration
: 0.5});
361 function dropboxSelect(e
, v
) {
362 for (i
= 0; i
< e
.length
; i
++) {
363 if (e
[i
].value
== v
) {
370 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
371 // bugfixed just a little bit :-)
372 function getURLParam(strParamName
){
374 var strHref
= window
.location
.href
;
376 if (strHref
.indexOf("#") == strHref
.length
-1) {
377 strHref
= strHref
.substring(0, strHref
.length
-1);
380 if ( strHref
.indexOf("?") > -1 ){
381 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
382 var aQueryString
= strQueryString
.split("&");
383 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
384 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
385 var aParam
= aQueryString
[iParam
].split("=");
386 strReturn
= aParam
[1];
394 function leading_zero(p
) {
396 if (s
.length
== 1) s
= "0" + s
;
400 function make_timestamp() {
403 return leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
404 ":" + leading_zero(d
.getSeconds());
408 function closeErrorBox() {
410 if (Element
.visible("errorBoxShadow")) {
411 Element
.hide("dialog_overlay");
412 Element
.hide("errorBoxShadow");
420 function closeInfoBox(cleanup
) {
425 if (Element
.visible("infoBoxShadow")) {
426 Element
.hide("dialog_overlay");
427 Element
.hide("infoBoxShadow");
429 if (cleanup
) $("infoBox").innerHTML
= " ";
432 exception_error("closeInfoBox", e
);
439 function displayDlg(id
, param
, callback
) {
441 notify_progress("Loading, please wait...", true);
445 var query
= "?op=dlg&id=" +
446 param_escape(id
) + "¶m=" + param_escape(param
);
448 new Ajax
.Request("backend.php", {
450 onComplete: function (transport
) {
451 infobox_callback2(transport
);
452 if (callback
) callback(transport
);
458 function infobox_submit_callback2(transport
) {
462 // called from prefs, reload tab
463 if (typeof active_tab
!= 'undefined' && active_tab
) {
464 selectTab(active_tab
, false);
468 if (transport
.responseText
) {
469 notify_info(transport
.responseText
);
473 function infobox_callback2(transport
) {
476 console
.log("infobox_callback2");
478 var box
= $('infoBox');
482 if (!getInitParam("infobox_disable_overlay")) {
483 Element
.show("dialog_overlay");
486 box
.innerHTML
=transport
.responseText
;
487 Element
.show("infoBoxShadow");
488 //Effect.SlideDown("infoBoxShadow", {duration : 1.0});
497 exception_error("infobox_callback2", e
);
501 function createFilter() {
505 var form
= document
.forms
['filter_add_form'];
506 var reg_exp
= form
.reg_exp
.value
;
509 alert(__("Can't add filter: nothing to match on."));
513 var query
= "?op=rpc&subop=verifyRegexp®_exp=" + param_escape(reg_exp
);
515 notify_progress("Verifying regular expression...");
517 new Ajax
.Request("backend.php", {
519 onComplete: function(transport
) {
520 handle_rpc_reply(transport
);
522 var response
= transport
.responseXML
;
525 var s
= response
.getElementsByTagName("status")[0].firstChild
.nodeValue
;
529 if (s
== "INVALID") {
530 alert("Match regular expression seems to be invalid.");
534 var query
= Form
.serialize("filter_add_form");
536 // we can be called from some other tab in Prefs
537 if (typeof active_tab
!= 'undefined' && active_tab
) {
538 active_tab
= "filterConfig";
541 new Ajax
.Request("backend.php?" + query
, {
542 onComplete: function (transport
) {
543 infobox_submit_callback2(transport
);
553 exception_error("createFilter", e
);
557 function isValidURL(s
) {
558 return s
.match("http://") != null || s
.match("https://") != null || s
.match("feed://") != null;
561 function subscribeToFeed() {
565 var form
= document
.forms
['feed_add_form'];
566 var feed_url
= form
.feed_url
.value
;
568 if (feed_url
== "") {
569 alert(__("Can't subscribe: no feed URL given."));
573 notify_progress(__("Subscribing to feed..."), true);
575 var query
= Form
.serialize("feed_add_form");
577 console
.log("subscribe q: " + query
);
579 Form
.disable("feed_add_form");
581 new Ajax
.Request("backend.php", {
583 onComplete: function(transport
) {
584 //dlg_frefresh_callback(transport);
588 if (!transport
.responseXML
)
589 console
.log(transport
.responseText
);
591 var result
= transport
.responseXML
.getElementsByTagName('result')[0];
592 var rc
= parseInt(result
.getAttribute('code'));
594 Form
.enable("feed_add_form");
601 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
603 if (inPreferences()) {
606 setTimeout('updateFeedList(false, false)', 50);
610 alert(__("Specified URL seems to be invalid."));
613 alert(__("Specified URL doesn't seem to contain any feeds."));
616 new Ajax
.Request("backend.php", {
617 parameters
: 'op=rpc&subop=extractfeedurls&url=' + encodeURIComponent(feed_url
),
618 onComplete: function(transport
) {
619 var result
= transport
.responseXML
.getElementsByTagName('urls')[0];
620 var feeds
= JSON
.parse(result
.firstChild
.nodeValue
);
621 var select
= document
.getElementById("faad_feeds_container_select");
623 while (select
.hasChildNodes()) {
624 select
.removeChild(elem
.firstChild
);
627 for (var feedUrl
in feeds
) {
628 select
.insert(new Option(feeds
[feedUrl
], feedUrl
, false));
631 if (count
> 5) count
= 5;
634 Effect
.Appear('fadd_feeds_container', {duration
: 0.5});
639 alert(__("Couldn't download the specified URL."));
642 alert(__("You are already subscribed to this feed."));
647 exception_error("subscribeToFeed", e
);
653 exception_error("subscribeToFeed", e
);
659 function filterCR(e
, f
)
664 key
= window
.event
.keyCode
; //IE
666 key
= e
.which
; //firefox
669 if (typeof f
!= 'undefined') {
680 function getInitParam(key
) {
681 return init_params
[key
];
684 function setInitParam(key
, value
) {
685 init_params
[key
] = value
;
688 function fatalError(code
, msg
, ext_info
) {
691 if (!ext_info
) ext_info
= "N/A";
694 window
.location
.href
= "tt-rss.php";
695 } else if (code
== 5) {
696 window
.location
.href
= "db-updater.php";
699 if (msg
== "") msg
= "Unknown error";
701 var ebc
= $("xebContent");
705 Element
.show("dialog_overlay");
706 Element
.show("errorBoxShadow");
707 Element
.hide("xebBtn");
710 if (ext_info
.responseText
) {
711 ext_info
= ext_info
.responseText
;
716 "<div><b>Error message:</b></div>" +
717 "<pre>" + msg
+ "</pre>" +
718 "<div><b>Additional information:</b></div>" +
719 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
724 exception_error("fatalError", e
);
728 function filterDlgCheckType(sender
) {
732 var ftype
= sender
[sender
.selectedIndex
].value
;
734 var form
= document
.forms
["filter_add_form"];
737 form
= document
.forms
["filter_edit_form"];
741 console
.log("filterDlgCheckType: can't find form!");
745 // if selected filter type is 5 (Date) enable the modifier dropbox
747 Element
.show("filter_dlg_date_mod_box");
748 Element
.show("filter_dlg_date_chk_box");
750 Element
.hide("filter_dlg_date_mod_box");
751 Element
.hide("filter_dlg_date_chk_box");
756 exception_error("filterDlgCheckType", e
);
761 function filterDlgCheckAction(sender
) {
765 var action
= sender
[sender
.selectedIndex
].value
;
767 var form
= document
.forms
["filter_add_form"];
770 form
= document
.forms
["filter_edit_form"];
774 console
.log("filterDlgCheckAction: can't find form!");
778 var action_param
= $("filter_dlg_param_box");
781 console
.log("filterDlgCheckAction: can't find action param box!");
785 // if selected action supports parameters, enable params field
786 if (action
== 4 || action
== 6 || action
== 7) {
787 Element
.show(action_param
);
789 Element
.show(form
.action_param
);
790 Element
.hide(form
.action_param_label
);
792 Element
.show(form
.action_param_label
);
793 Element
.hide(form
.action_param
);
796 Element
.hide(action_param
);
800 exception_error("filterDlgCheckAction", e
);
805 function filterDlgCheckDate() {
807 var form
= document
.forms
["filter_add_form"];
810 form
= document
.forms
["filter_edit_form"];
814 console
.log("filterDlgCheckAction: can't find form!");
818 var reg_exp
= form
.reg_exp
.value
;
820 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
822 new Ajax
.Request("backend.php", {
824 onComplete: function(transport
) {
826 var form
= document
.forms
["filter_add_form"];
829 form
= document
.forms
["filter_edit_form"];
832 if (transport
.responseXML
) {
833 var result
= transport
.responseXML
.getElementsByTagName("result")[0];
835 if (result
&& result
.firstChild
) {
836 if (result
.firstChild
.nodeValue
== "1") {
838 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#00ff00'});
845 new Effect
.Highlight(form
.reg_exp
, {startcolor
: '#ff0000'});
851 exception_error("filterDlgCheckDate", e
);
855 function explainError(code
) {
856 return displayDlg("explainError", code
);
859 function displayHelpInfobox(topic_id
) {
861 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
863 var w
= window
.open(url
, "ttrss_help",
864 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
868 function loading_set_progress(p
) {
870 if (p
< last_progress_point
|| !Element
.visible("overlay")) return;
872 console
.log("loading_set_progress : " + p
+ " (" + last_progress_point
+ ")");
874 var o
= $("l_progress_i");
876 // o.style.width = (p * 2) + "px";
878 new Effect
.Scale(o
, p
, {
880 scaleFrom
: last_progress_point
,
881 scaleMode
: { originalWidth
: 200 },
882 queue
: { position
: 'end', scope
: 'LSP-Q', limit
: 3 } });
884 last_progress_point
= p
;
887 exception_error("loading_set_progress", e
);
891 function remove_splash() {
892 if (Element
.visible("overlay")) {
893 console
.log("about to remove splash, OMG!");
894 Element
.hide("overlay");
895 console
.log("removed splash!");
899 function getSelectedFeedsFromBrowser() {
901 var list
= $("browseFeedList");
903 var selected
= new Array();
905 for (i
= 0; i
< list
.childNodes
.length
; i
++) {
906 var child
= list
.childNodes
[i
];
907 if (child
.id
&& child
.id
.match("FBROW-")) {
908 var id
= child
.id
.replace("FBROW-", "");
910 var cb
= $("FBCHK-" + id
);
921 function updateFeedBrowser() {
924 var query
= Form
.serialize("feed_browser");
926 Element
.show('feed_browser_spinner');
928 new Ajax
.Request("backend.php", {
930 onComplete: function(transport
) {
933 Element
.hide('feed_browser_spinner');
935 var c
= $("browseFeedList");
936 var r
= transport
.responseXML
.getElementsByTagName("content")[0];
937 var nr
= transport
.responseXML
.getElementsByTagName("num-results")[0];
938 var mode
= transport
.responseXML
.getElementsByTagName("mode")[0];
941 c
.innerHTML
= r
.firstChild
.nodeValue
;
944 if (parseInt(mode
.getAttribute("value")) == 2) {
945 Element
.show('feed_archive_remove');
947 Element
.hide('feed_archive_remove');
953 exception_error("updateFeedBrowser", e
);
958 function transport_error_check(transport
) {
960 if (transport
.responseXML
) {
961 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
964 var code
= error
.getAttribute("error-code");
965 var msg
= error
.getAttribute("error-msg");
967 fatalError(code
, msg
);
973 exception_error("check_for_error_xml", e
);
978 function strip_tags(s
) {
979 return s
.replace(/<\/?[^>]+(>|$)/g, "");
982 function truncate_string(s
, length
) {
983 if (!length
) length
= 30;
984 var tmp
= s
.substring(0, length
);
985 if (s
.length
> length
) tmp
+= "…";
989 function hotkey_prefix_timeout() {
992 var date
= new Date();
993 var ts
= Math
.round(date
.getTime() / 1000);
995 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
996 console
.log("hotkey_prefix seems to be stuck, aborting");
997 hotkey_prefix_pressed
= false;
998 hotkey_prefix
= false;
999 Element
.hide('cmdline');
1002 setTimeout("hotkey_prefix_timeout()", 1000);
1005 exception_error("hotkey_prefix_timeout", e
);
1009 function hideAuxDlg() {
1011 Element
.hide('auxDlg');
1013 exception_error("hideAuxDlg", e
);
1017 function feedBrowserSubscribe() {
1020 var selected
= getSelectedFeedsFromBrowser();
1022 var mode
= document
.forms
['feed_browser'].mode
;
1024 mode
= mode
[mode
.selectedIndex
].value
;
1026 if (selected
.length
> 0) {
1029 notify_progress("Loading, please wait...", true);
1031 var query
= "?op=rpc&subop=massSubscribe&ids="+
1032 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1034 new Ajax
.Request("backend.php", {
1036 onComplete: function(transport
) {
1038 var nf
= transport
.responseXML
.getElementsByTagName('num-feeds')[0];
1039 var nf_value
= nf
.getAttribute("value");
1041 notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value
));
1043 if (inPreferences()) {
1046 setTimeout('updateFeedList(false, false)', 50);
1051 alert(__("No feeds are selected."));
1055 exception_error("feedBrowserSubscribe", e
);
1059 function feedArchiveRemove() {
1062 var selected
= getSelectedFeedsFromBrowser();
1064 if (selected
.length
> 0) {
1066 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1069 Element
.show('feed_browser_spinner');
1071 var query
= "?op=rpc&subop=remarchived&ids=" +
1072 param_escape(selected
.toString());;
1074 new Ajax
.Request("backend.php", {
1076 onComplete: function(transport
) {
1077 updateFeedBrowser();
1082 alert(__("No feeds are selected."));
1086 exception_error("feedArchiveRemove", e
);
1090 function uploadIconHandler(rc
) {
1094 notify_info("Upload complete.");
1095 if (inPreferences()) {
1098 setTimeout('updateFeedList(false, false)', 50);
1102 notify_error("Upload failed: icon is too big.");
1105 notify_error("Upload failed.");
1110 exception_error("uploadIconHandler", e
);
1114 function removeFeedIcon(id
) {
1118 if (confirm(__("Remove stored feed icon?"))) {
1119 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
1123 notify_progress("Removing feed icon...", true);
1125 new Ajax
.Request("backend.php", {
1127 onComplete: function(transport
) {
1128 notify_info("Feed icon removed.");
1129 if (inPreferences()) {
1132 setTimeout('updateFeedList(false, false)', 50);
1139 exception_error("uploadFeedIcon", e
);
1143 function uploadFeedIcon() {
1147 var file
= $("icon_file");
1149 if (file
.value
.length
== 0) {
1150 alert(__("Please select an image file to upload."));
1152 if (confirm(__("Upload new icon for this feed?"))) {
1153 notify_progress("Uploading, please wait...", true);
1161 exception_error("uploadFeedIcon", e
);
1165 function addLabel(select
, callback
) {
1169 var caption
= prompt(__("Please enter label caption:"), "");
1171 if (caption
!= undefined) {
1173 if (caption
== "") {
1174 alert(__("Can't create label: missing caption."));
1178 var query
= "?op=pref-labels&subop=add&caption=" +
1179 param_escape(caption
);
1182 query
+= "&output=select";
1184 notify_progress("Loading, please wait...", true);
1186 if (inPreferences() && !select
) active_tab
= "labelConfig";
1188 new Ajax
.Request("backend.php", {
1190 onComplete: function(transport
) {
1192 callback(transport
);
1193 } else if (inPreferences()) {
1194 infobox_submit_callback2(transport
);
1203 exception_error("addLabel", e
);
1207 function quickAddFeed() {
1208 displayDlg('quickAddFeed', '',
1209 function () {$('feed_url').focus();});
1212 function quickAddFilter() {
1213 displayDlg('quickAddFilter', '',
1214 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
1217 function unsubscribeFeed(feed_id
, title
) {
1219 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1221 if (title
== undefined || confirm(msg
)) {
1222 notify_progress("Removing feed...");
1224 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1226 new Ajax
.Request("backend.php", {
1228 onComplete: function(transport
) {
1232 if (inPreferences()) {
1235 dlg_frefresh_callback(transport
, feed_id
);
1245 function backend_sanity_check_callback(transport
) {
1249 if (sanity_check_done
) {
1250 fatalError(11, "Sanity check request received twice. This can indicate "+
1251 "presence of Firebug or some other disrupting extension. "+
1252 "Please disable it and try again.");
1256 if (!transport
.responseXML
) {
1258 fatalError(3, "Sanity check: Received reply is not XML",
1259 transport
.responseText
);
1267 if (getURLParam("offline")) {
1268 return init_offline();
1271 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1274 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1278 var error_code
= reply
.getAttribute("error-code");
1280 if (error_code
&& error_code
!= 0) {
1281 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1284 console
.log("sanity check ok");
1286 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1289 console
.log('reading init-params...');
1291 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1298 console
.log("IP: " + k
+ " => " + v
);
1301 db
.execute("DELETE FROM init_params WHERE key = ?", [k
]);
1302 db
.execute("INSERT INTO init_params (key,value) VALUES (?, ?)",
1308 init_params
= params
;
1311 sanity_check_done
= true;
1313 init_second_stage();
1316 exception_error("backend_sanity_check_callback", e
, transport
);
1320 function has_local_storage() {
1323 return 'localStorage' in window && window['localStorage'] != null;
1329 function catSelectOnChange(elem
) {
1331 var value
= elem
[elem
.selectedIndex
].value
;
1332 var def
= elem
.getAttribute('default');
1334 if (value
== "ADD_CAT") {
1337 dropboxSelect(elem
, def
);
1339 elem
.selectedIndex
= 0;
1345 exception_error("catSelectOnChange", e
);
1349 function quickAddCat(elem
) {
1351 var cat
= prompt(__("Please enter category title:"));
1355 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1357 notify_progress("Loading, please wait...", true);
1359 new Ajax
.Request("backend.php", {
1361 onComplete: function (transport
) {
1362 var response
= transport
.responseXML
;
1363 var select
= response
.getElementsByTagName("select")[0];
1364 var options
= select
.getElementsByTagName("option");
1366 dropbox_replace_options(elem
, options
);
1375 exception_error("quickAddCat", e
);
1379 function genUrlChangeKey(feed
, is_cat
) {
1382 var ok
= confirm(__("Generate new syndication address for this feed?"));
1386 notify_progress("Trying to change address...", true);
1388 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1389 "&is_cat=" + param_escape(is_cat
);
1391 new Ajax
.Request("backend.php", {
1393 onComplete: function(transport
) {
1394 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
1396 var e
= $('gen_feed_url');
1400 new_link
= new_link
.firstChild
.nodeValue
;
1402 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1403 "&key=" + new_link
);
1405 e
.href
= e
.href
.replace(/\&key=.*$/,
1406 "&key=" + new_link
);
1408 new Effect
.Highlight(e
);
1413 notify_error("Could not change feed URL.");
1418 exception_error("genUrlChangeKey", e
);
1423 function labelSelectOnChange(elem
) {
1425 var value
= elem
[elem
.selectedIndex
].value
;
1426 var def
= elem
.getAttribute('default');
1428 if (value
== "ADD_LABEL") {
1431 dropboxSelect(elem
, def
);
1433 elem
.selectedIndex
= 0;
1435 addLabel(elem
, function(transport
) {
1439 var response
= transport
.responseXML
;
1440 var select
= response
.getElementsByTagName("select")[0];
1441 var options
= select
.getElementsByTagName("option");
1443 dropbox_replace_options(elem
, options
);
1447 exception_error("addLabel", e
);
1453 exception_error("labelSelectOnChange", e
);
1457 function dropbox_replace_options(elem
, options
) {
1460 while (elem
.hasChildNodes())
1461 elem
.removeChild(elem
.firstChild
);
1465 for (var i
= 0; i
< options
.length
; i
++) {
1466 var text
= options
[i
].firstChild
.nodeValue
;
1467 var value
= options
[i
].getAttribute("value");
1469 if (value
== undefined) value
= text
;
1471 var issel
= options
[i
].getAttribute("selected") == "1";
1473 var option
= new Option(text
, value
, issel
);
1475 if (options
[i
].getAttribute("disabled"))
1476 option
.setAttribute("disabled", true);
1478 elem
.insert(option
);
1480 if (issel
) sel_idx
= i
;
1483 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1484 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1487 exception_error("dropbox_replace_options", e
);
1491 // mode = all, none, invert
1492 function selectTableRows(id
, mode
) {
1494 var rows
= $(id
).rows
;
1496 for (var i
= 0; i
< rows
.length
; i
++) {
1500 if (row
.id
&& row
.className
) {
1501 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1502 var inputs
= rows
[i
].getElementsByTagName("input");
1504 for (var j
= 0; j
< inputs
.length
; j
++) {
1505 var input
= inputs
[j
];
1507 if (input
.getAttribute("type") == "checkbox" &&
1508 input
.id
.match(bare_id
)) {
1516 var issel
= row
.className
.match("Selected");
1518 if (mode
== "all" && !issel
) {
1519 row
.className
+= "Selected";
1521 } else if (mode
== "none" && issel
) {
1522 row
.className
= row
.className
.replace("Selected", "");
1524 } else if (mode
== "invert") {
1527 row
.className
= row
.className
.replace("Selected", "");
1530 row
.className
+= "Selected";
1539 exception_error("selectTableRows", e
);
1544 function getSelectedTableRowIds(id
) {
1548 var elem_rows
= $(id
).rows
;
1550 for (i
= 0; i
< elem_rows
.length
; i
++) {
1551 if (elem_rows
[i
].className
.match("Selected")) {
1552 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1558 exception_error("getSelectedTableRowIds", e
);