]>
git.wh0rd.org - tt-rss.git/blob - functions.js
615d59fc3aec5cf19a17be44c1487f020fc2399b
1 var notify_silent
= false;
2 var loading_progress
= 0;
3 var sanity_check_done
= false;
5 /* add method to remove element from array */
7 Array
.prototype.remove = function(s
) {
8 for (var i
=0; i
< this.length
; i
++) {
9 if (s
== this[i
]) this.splice(i
, 1);
13 /* create console.log if it doesn't exist */
15 if (!window
.console
) console
= {};
16 console
.log
= console
.log
|| function(msg
) { };
17 console
.warn
= console
.warn
|| function(msg
) { };
18 console
.error
= console
.error
|| function(msg
) { };
20 function exception_error(location
, e
, ext_info
) {
21 var msg
= format_exception_error(location
, e
);
23 if (!ext_info
) ext_info
= false;
28 if (ext_info
.responseText
) {
29 ext_info
= ext_info
.responseText
;
33 var content
= "<div class=\"fatalError\">" +
34 "<pre>" + msg
+ "</pre>";
37 content
+= "<div><b>Additional information:</b></div>" +
38 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
41 content
+= "<div><b>Stack trace:</b></div>" +
42 "<textarea readonly=\"1\">" + e
.stack
+ "</textarea>";
46 // TODO: add code to automatically report errors to tt-rss.org
48 var dialog
= new dijit
.Dialog({
49 title
: "Unhandled exception",
50 style
: "width: 600px",
61 function format_exception_error(location
, e
) {
65 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
67 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
68 "\nFunction: " + location
+ "()" +
69 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
71 } else if (e
.description
) {
72 msg
= "Exception: " + e
.description
+ "\nFunction: " + location
+ "()";
74 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
77 console
.error("EXCEPTION: " + msg
);
82 function param_escape(arg
) {
83 if (typeof encodeURIComponent
!= 'undefined')
84 return encodeURIComponent(arg
);
89 function param_unescape(arg
) {
90 if (typeof decodeURIComponent
!= 'undefined')
91 return decodeURIComponent(arg
);
96 var notify_hide_timerid
= false;
98 function hide_notify() {
101 n
.style
.display
= "none";
105 function notify_silent_next() {
106 notify_silent
= true;
109 function notify_real(msg
, no_hide
, n_type
) {
112 notify_silent
= false;
117 var nb
= $("notify_body");
119 if (!n
|| !nb
) return;
121 if (notify_hide_timerid
) {
122 window
.clearTimeout(notify_hide_timerid
);
126 if (n
.style
.display
== "block") {
127 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
131 n
.style
.display
= "block";
143 if (typeof __
!= 'undefined') {
148 n
.className
= "notify";
149 } else if (n_type
== 2) {
150 n
.className
= "notifyProgress";
151 msg
= "<img src='"+getInitParam("sign_progress")+"'> " + msg
;
152 } else if (n_type
== 3) {
153 n
.className
= "notifyError";
154 msg
= "<img src='"+getInitParam("sign_excl")+"'> " + msg
;
155 } else if (n_type
== 4) {
156 n
.className
= "notifyInfo";
157 msg
= "<img src='"+getInitParam("sign_info")+"'> " + msg
;
160 // msg = "<img src='images/live_com_loading.gif'> " + msg;
165 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
169 function notify(msg
, no_hide
) {
170 notify_real(msg
, no_hide
, 1);
173 function notify_progress(msg
, no_hide
) {
174 notify_real(msg
, no_hide
, 2);
177 function notify_error(msg
, no_hide
) {
178 notify_real(msg
, no_hide
, 3);
182 function notify_info(msg
, no_hide
) {
183 notify_real(msg
, no_hide
, 4);
186 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
192 d
.setTime(d
.getTime() + (lifetime
* 1000));
195 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
197 int_setCookie(name
, value
, d
, path
, domain
, secure
);
201 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
202 document
.cookie
= name
+ "=" + escape(value
) +
203 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
204 ((path
) ? "; path=" + path
: "") +
205 ((domain
) ? "; domain=" + domain
: "") +
206 ((secure
) ? "; secure" : "");
209 function delCookie(name
, path
, domain
) {
210 if (getCookie(name
)) {
211 document
.cookie
= name
+ "=" +
212 ((path
) ? ";path=" + path
: "") +
213 ((domain
) ? ";domain=" + domain
: "" ) +
214 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
219 function getCookie(name
) {
221 var dc
= document
.cookie
;
222 var prefix
= name
+ "=";
223 var begin
= dc
.indexOf("; " + prefix
);
225 begin
= dc
.indexOf(prefix
);
226 if (begin
!= 0) return null;
231 var end
= document
.cookie
.indexOf(";", begin
);
235 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
238 function gotoPreferences() {
239 document
.location
.href
= "prefs.php";
242 function gotoMain() {
243 document
.location
.href
= "tt-rss.php";
246 function gotoExportOpml() {
247 document
.location
.href
= "opml.php?op=Export";
251 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
252 * * @author Sundar Dorai-Raj
253 * * Email: sdoraira@vt.edu
254 * * This program is free software; you can redistribute it and/or
255 * * modify it under the terms of the GNU General Public License
256 * * as published by the Free Software Foundation; either version 2
257 * * of the License, or (at your option) any later version,
258 * * provided that any use properly credits the author.
259 * * This program is distributed in the hope that it will be useful,
260 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
261 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
262 * * GNU General Public License for more details at http://www.gnu.org * * */
264 var numbers
=".0123456789";
265 function isNumeric(x
) {
266 // is x a String or a character?
268 // remove negative sign
270 for(j
=0;j
<x
.length
;j
++) {
271 // call isNumeric recursively for each character
272 number
=isNumeric(x
.substring(j
,j
+1));
273 if(!number
) return number
;
278 // if x is number return true
279 if(numbers
.indexOf(x
)>=0) return true;
285 function toggleSelectRowById(sender
, id
) {
287 return toggleSelectRow(sender
, row
);
290 function toggleSelectListRow(sender
) {
291 var row
= sender
.parentNode
;
292 return toggleSelectRow(sender
, row
);
295 /* this is for dijit Checkbox */
296 function toggleSelectListRow2(sender
) {
297 var row
= sender
.domNode
.parentNode
;
298 return toggleSelectRow(sender
, row
);
301 function tSR(sender
, row
) {
302 return toggleSelectRow(sender
, row
);
305 /* this is for dijit Checkbox */
306 function toggleSelectRow2(sender
, row
) {
308 if (!row
) row
= sender
.domNode
.parentNode
.parentNode
;
310 if (sender
.checked
&& !row
.hasClassName('Selected'))
311 row
.addClassName('Selected');
313 row
.removeClassName('Selected');
317 function toggleSelectRow(sender
, row
) {
319 if (!row
) row
= sender
.parentNode
.parentNode
;
321 if (sender
.checked
&& !row
.hasClassName('Selected'))
322 row
.addClassName('Selected');
324 row
.removeClassName('Selected');
327 function checkboxToggleElement(elem
, id
) {
329 Effect
.Appear(id
, {duration
: 0.5});
331 Effect
.Fade(id
, {duration
: 0.5});
335 function dropboxSelect(e
, v
) {
336 for (i
= 0; i
< e
.length
; i
++) {
337 if (e
[i
].value
== v
) {
344 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
345 // bugfixed just a little bit :-)
346 function getURLParam(strParamName
){
348 var strHref
= window
.location
.href
;
350 if (strHref
.indexOf("#") == strHref
.length
-1) {
351 strHref
= strHref
.substring(0, strHref
.length
-1);
354 if ( strHref
.indexOf("?") > -1 ){
355 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
356 var aQueryString
= strQueryString
.split("&");
357 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
358 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
359 var aParam
= aQueryString
[iParam
].split("=");
360 strReturn
= aParam
[1];
368 function leading_zero(p
) {
370 if (s
.length
== 1) s
= "0" + s
;
374 function make_timestamp() {
377 return leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
378 ":" + leading_zero(d
.getSeconds());
382 function closeErrorBox() {
384 if (Element
.visible("errorBoxShadow")) {
385 Element
.hide("dialog_overlay");
386 Element
.hide("errorBoxShadow");
392 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_callback2(transport
) {
426 if (dijit
.byId("infoBox")) {
427 dialog
= dijit
.byId("infoBox");
430 //console.log("infobox_callback2");
434 var dtitle
= "Dialog";
436 var dlg
= transport
.responseXML
.getElementsByTagName("dlg")[0];
438 var title
= transport
.responseXML
.getElementsByTagName("title")[0];
440 title
= title
.firstChild
.nodeValue
;
442 var content
= transport
.responseXML
.getElementsByTagName("content")[0];
444 content
= content
.firstChild
.nodeValue
;
447 dialog
= new dijit
.Dialog({
450 style
: "width: 600px",
451 onCancel: function() {
454 onExecute: function() {
457 onClose: function() {
462 dialog
.attr('title', title
);
463 dialog
.attr('content', content
);
470 exception_error("infobox_callback2", e
);
474 function filterCR(e
, f
)
479 key
= window
.event
.keyCode
; //IE
481 key
= e
.which
; //firefox
484 if (typeof f
!= 'undefined') {
495 function getInitParam(key
) {
496 return init_params
[key
];
499 function setInitParam(key
, value
) {
500 init_params
[key
] = value
;
503 function fatalError(code
, msg
, ext_info
) {
506 if (!ext_info
) ext_info
= "N/A";
509 window
.location
.href
= "tt-rss.php";
510 } else if (code
== 5) {
511 window
.location
.href
= "db-updater.php";
514 if (msg
== "") msg
= "Unknown error";
516 var ebc
= $("xebContent");
520 Element
.show("dialog_overlay");
521 Element
.show("errorBoxShadow");
522 Element
.hide("xebBtn");
525 if (ext_info
.responseText
) {
526 ext_info
= ext_info
.responseText
;
531 "<div><b>Error message:</b></div>" +
532 "<pre>" + msg
+ "</pre>" +
533 "<div><b>Additional information:</b></div>" +
534 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
539 exception_error("fatalError", e
);
543 function filterDlgCheckType(sender
) {
547 var ftype
= sender
.value
;
549 // if selected filter type is 5 (Date) enable the modifier dropbox
551 Element
.show("filterDlg_dateModBox");
552 Element
.show("filterDlg_dateChkBox");
554 Element
.hide("filterDlg_dateModBox");
555 Element
.hide("filterDlg_dateChkBox");
560 exception_error("filterDlgCheckType", e
);
565 function filterDlgCheckAction(sender
) {
569 var action
= sender
.value
;
571 var action_param
= $("filterDlg_paramBox");
574 console
.log("filterDlgCheckAction: can't find action param box!");
578 // if selected action supports parameters, enable params field
579 if (action
== 4 || action
== 6 || action
== 7) {
580 new Effect
.Appear(action_param
, {duration
: 0.5});
582 Element
.show(dijit
.byId("filterDlg_actionParam").domNode
);
583 Element
.hide(dijit
.byId("filterDlg_actionParamLabel").domNode
);
585 Element
.show(dijit
.byId("filterDlg_actionParamLabel").domNode
);
586 Element
.hide(dijit
.byId("filterDlg_actionParam").domNode
);
589 Element
.hide(action_param
);
593 exception_error("filterDlgCheckAction", e
);
598 function filterDlgCheckDate() {
600 var dialog
= dijit
.byId("filterEditDlg");
602 var reg_exp
= dialog
.attr('value').reg_exp
;
604 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
606 new Ajax
.Request("backend.php", {
608 onComplete: function(transport
) {
610 var reply
= JSON
.parse(transport
.responseText
);
612 if (reply
['result'] == true) {
613 alert(__("Date syntax appears to be correct."));
616 alert(__("Date syntax is incorrect."));
623 exception_error("filterDlgCheckDate", e
);
627 function explainError(code
) {
628 return displayDlg("explainError", code
);
631 function displayHelpInfobox(topic_id
) {
633 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
635 var w
= window
.open(url
, "ttrss_help",
636 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
640 function loading_set_progress(p
) {
642 loading_progress
+= p
;
644 if (dijit
.byId("loading_bar"))
645 dijit
.byId("loading_bar").update({progress
: loading_progress
});
647 if (loading_progress
>= 90)
651 exception_error("loading_set_progress", e
);
655 function remove_splash() {
657 if (Element
.visible("overlay")) {
658 console
.log("about to remove splash, OMG!");
659 Element
.hide("overlay");
660 console
.log("removed splash!");
664 function transport_error_check(transport
) {
666 if (transport
.responseXML
) {
667 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
670 var code
= error
.getAttribute("error-code");
671 var msg
= error
.getAttribute("error-msg");
673 fatalError(code
, msg
);
679 exception_error("check_for_error_xml", e
);
684 function strip_tags(s
) {
685 return s
.replace(/<\/?[^>]+(>|$)/g, "");
688 function truncate_string(s
, length
) {
689 if (!length
) length
= 30;
690 var tmp
= s
.substring(0, length
);
691 if (s
.length
> length
) tmp
+= "…";
695 function hotkey_prefix_timeout() {
698 var date
= new Date();
699 var ts
= Math
.round(date
.getTime() / 1000);
701 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
702 console
.log("hotkey_prefix seems to be stuck, aborting");
703 hotkey_prefix_pressed
= false;
704 hotkey_prefix
= false;
705 Element
.hide('cmdline');
708 setTimeout("hotkey_prefix_timeout()", 1000);
711 exception_error("hotkey_prefix_timeout", e
);
715 function hideAuxDlg() {
717 Element
.hide('auxDlg');
719 exception_error("hideAuxDlg", e
);
724 function uploadIconHandler(rc
) {
728 notify_info("Upload complete.");
729 if (inPreferences()) {
732 setTimeout('updateFeedList(false, false)', 50);
736 notify_error("Upload failed: icon is too big.");
739 notify_error("Upload failed.");
744 exception_error("uploadIconHandler", e
);
748 function removeFeedIcon(id
) {
752 if (confirm(__("Remove stored feed icon?"))) {
753 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
757 notify_progress("Removing feed icon...", true);
759 new Ajax
.Request("backend.php", {
761 onComplete: function(transport
) {
762 notify_info("Feed icon removed.");
763 if (inPreferences()) {
766 setTimeout('updateFeedList(false, false)', 50);
773 exception_error("uploadFeedIcon", e
);
777 function uploadFeedIcon() {
781 var file
= $("icon_file");
783 if (file
.value
.length
== 0) {
784 alert(__("Please select an image file to upload."));
786 if (confirm(__("Upload new icon for this feed?"))) {
787 notify_progress("Uploading, please wait...", true);
795 exception_error("uploadFeedIcon", e
);
799 function addLabel(select
, callback
) {
803 var caption
= prompt(__("Please enter label caption:"), "");
805 if (caption
!= undefined) {
808 alert(__("Can't create label: missing caption."));
812 var query
= "?op=pref-labels&subop=add&caption=" +
813 param_escape(caption
);
816 query
+= "&output=select";
818 notify_progress("Loading, please wait...", true);
820 if (inPreferences() && !select
) active_tab
= "labelConfig";
822 new Ajax
.Request("backend.php", {
824 onComplete: function(transport
) {
827 } else if (inPreferences()) {
837 exception_error("addLabel", e
);
841 function quickAddFeed() {
843 var query
= "backend.php?op=dlg&id=quickAddFeed";
845 if (dijit
.byId("feedAddDlg"))
846 dijit
.byId("feedAddDlg").destroyRecursive();
848 var dialog
= new dijit
.Dialog({
850 title
: __("Subscribe to Feed"),
851 style
: "width: 600px",
852 execute: function() {
853 if (this.validate()) {
854 console
.log(dojo
.objectToQuery(this.attr('value')));
856 var feed_url
= this.attr('value').feed
;
858 notify_progress(__("Subscribing to feed..."), true);
860 new Ajax
.Request("backend.php", {
861 parameters
: dojo
.objectToQuery(this.attr('value')),
862 onComplete: function(transport
) {
865 var reply
= JSON
.parse(transport
.responseText
);
867 var rc
= parseInt(reply
['result']);
871 console
.log("GOT RC: " + rc
);
876 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
881 alert(__("Specified URL seems to be invalid."));
884 alert(__("Specified URL doesn't seem to contain any feeds."));
887 notify_progress("Searching for feed urls...", true);
889 new Ajax
.Request("backend.php", {
890 parameters
: 'op=rpc&subop=extractfeedurls&url=' + param_escape(feed_url
),
891 onComplete: function(transport
, dialog
, feed_url
) {
895 var reply
= JSON
.parse(transport
.responseText
);
897 var feeds
= reply
['urls'];
899 console
.log(transport
.responseText
);
901 var select
= dijit
.byId("feedDlg_feedContainerSelect");
903 while (select
.getOptions().length
> 0)
904 select
.removeOption(0);
907 for (var feedUrl
in feeds
) {
908 select
.addOption({value
: feedUrl
, label
: feeds
[feedUrl
]});
912 // if (count > 5) count = 5;
913 // select.size = count;
915 Effect
.Appear('feedDlg_feedsContainer', {duration
: 0.5});
920 alert(__("Couldn't download the specified URL."));
923 alert(__("You are already subscribed to this feed."));
928 exception_error("subscribeToFeed", e
);
939 exception_error("quickAddFeed", e
);
943 function quickAddFilter() {
945 var query
= "backend.php?op=dlg&id=quickAddFilter";
947 if (dijit
.byId("filterEditDlg"))
948 dijit
.byId("filterEditDlg").destroyRecursive();
950 dialog
= new dijit
.Dialog({
952 title
: __("Create Filter"),
953 style
: "width: 600px",
954 execute: function() {
955 if (this.validate()) {
957 var query
= "?op=rpc&subop=verifyRegexp®_exp=" +
958 param_escape(dialog
.attr('value').reg_exp
);
960 notify_progress("Verifying regular expression...");
962 new Ajax
.Request("backend.php", {
964 onComplete: function(transport
) {
965 handle_rpc_reply(transport
);
966 var response
= transport
.responseXML
;
969 var s
= response
.getElementsByTagName("status")[0].firstChild
.nodeValue
;
973 if (s
== "INVALID") {
974 alert("Match regular expression seems to be invalid.");
977 notify_progress("Saving data...", true);
979 console
.log(dojo
.objectToQuery(dialog
.attr('value')));
981 new Ajax
.Request("backend.php", {
982 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
983 onComplete: function(transport
) {
985 notify_info(transport
.responseText
);
986 if (inPreferences()) {
999 exception_error("quickAddFilter", e
);
1003 function unsubscribeFeed(feed_id
, title
) {
1005 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1007 if (title
== undefined || confirm(msg
)) {
1008 notify_progress("Removing feed...");
1010 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1012 new Ajax
.Request("backend.php", {
1014 onComplete: function(transport
) {
1016 if (dijit
.byId("feedEditDlg")) dijit
.byId("feedEditDlg").hide();
1018 if (inPreferences()) {
1021 if (feed_id
== getActiveFeedId())
1022 setTimeout("viewfeed(-5)", 100);
1032 function backend_sanity_check_callback(transport
) {
1036 if (sanity_check_done
) {
1037 fatalError(11, "Sanity check request received twice. This can indicate "+
1038 "presence of Firebug or some other disrupting extension. "+
1039 "Please disable it and try again.");
1043 if (!transport
.responseXML
) {
1045 fatalError(3, "Sanity check: Received reply is not XML",
1046 transport
.responseText
);
1051 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1054 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1058 var error_code
= reply
.getAttribute("error-code");
1060 if (error_code
&& error_code
!= 0) {
1061 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1064 console
.log("sanity check ok");
1066 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1069 console
.log('reading init-params...');
1071 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1076 console
.log("IP: " + k
+ " => " + v
);
1080 init_params
= params
;
1083 sanity_check_done
= true;
1085 init_second_stage();
1088 exception_error("backend_sanity_check_callback", e
, transport
);
1092 function has_local_storage() {
1094 return 'sessionStorage' in window
&& window
['sessionStorage'] != null;
1100 function catSelectOnChange(elem
) {
1102 /* var value = elem[elem.selectedIndex].value;
1103 var def = elem.getAttribute('default');
1105 if (value == "ADD_CAT") {
1108 dropboxSelect(elem, def);
1110 elem.selectedIndex = 0;
1116 exception_error("catSelectOnChange", e
);
1120 function quickAddCat(elem
) {
1122 var cat
= prompt(__("Please enter category title:"));
1126 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1128 notify_progress("Loading, please wait...", true);
1130 new Ajax
.Request("backend.php", {
1132 onComplete: function (transport
) {
1133 var response
= transport
.responseXML
;
1134 var select
= response
.getElementsByTagName("select")[0];
1135 var options
= select
.getElementsByTagName("option");
1137 dropbox_replace_options(elem
, options
);
1146 exception_error("quickAddCat", e
);
1150 function genUrlChangeKey(feed
, is_cat
) {
1153 var ok
= confirm(__("Generate new syndication address for this feed?"));
1157 notify_progress("Trying to change address...", true);
1159 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1160 "&is_cat=" + param_escape(is_cat
);
1162 new Ajax
.Request("backend.php", {
1164 onComplete: function(transport
) {
1165 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
1167 var e
= $('gen_feed_url');
1171 new_link
= new_link
.firstChild
.nodeValue
;
1173 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1174 "&key=" + new_link
);
1176 e
.href
= e
.href
.replace(/\&key=.*$/,
1177 "&key=" + new_link
);
1179 new Effect
.Highlight(e
);
1184 notify_error("Could not change feed URL.");
1189 exception_error("genUrlChangeKey", e
);
1194 function labelSelectOnChange(elem
) {
1196 /* var value = elem[elem.selectedIndex].value;
1197 var def = elem.getAttribute('default');
1199 if (value == "ADD_LABEL") {
1202 dropboxSelect(elem, def);
1204 elem.selectedIndex = 0;
1206 addLabel(elem, function(transport) {
1210 var response = transport.responseXML;
1211 var select = response.getElementsByTagName("select")[0];
1212 var options = select.getElementsByTagName("option");
1214 dropbox_replace_options(elem, options);
1218 exception_error("addLabel", e);
1224 exception_error("labelSelectOnChange", e
);
1228 function dropbox_replace_options(elem
, options
) {
1231 while (elem
.hasChildNodes())
1232 elem
.removeChild(elem
.firstChild
);
1236 for (var i
= 0; i
< options
.length
; i
++) {
1237 var text
= options
[i
].firstChild
.nodeValue
;
1238 var value
= options
[i
].getAttribute("value");
1240 if (value
== undefined) value
= text
;
1242 var issel
= options
[i
].getAttribute("selected") == "1";
1244 var option
= new Option(text
, value
, issel
);
1246 if (options
[i
].getAttribute("disabled"))
1247 option
.setAttribute("disabled", true);
1249 elem
.insert(option
);
1251 if (issel
) sel_idx
= i
;
1254 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1255 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1258 exception_error("dropbox_replace_options", e
);
1262 // mode = all, none, invert
1263 function selectTableRows(id
, mode
) {
1265 var rows
= $(id
).rows
;
1267 for (var i
= 0; i
< rows
.length
; i
++) {
1271 if (row
.id
&& row
.className
) {
1272 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1273 var inputs
= rows
[i
].getElementsByTagName("input");
1275 for (var j
= 0; j
< inputs
.length
; j
++) {
1276 var input
= inputs
[j
];
1278 if (input
.getAttribute("type") == "checkbox" &&
1279 input
.id
.match(bare_id
)) {
1287 var issel
= row
.hasClassName("Selected");
1289 if (mode
== "all" && !issel
) {
1290 row
.addClassName("Selected");
1292 } else if (mode
== "none" && issel
) {
1293 row
.removeClassName("Selected");
1295 } else if (mode
== "invert") {
1298 row
.removeClassName("Selected");
1301 row
.addClassName("Selected");
1310 exception_error("selectTableRows", e
);
1315 function getSelectedTableRowIds(id
) {
1319 var elem_rows
= $(id
).rows
;
1321 for (i
= 0; i
< elem_rows
.length
; i
++) {
1322 if (elem_rows
[i
].hasClassName("Selected")) {
1323 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1329 exception_error("getSelectedTableRowIds", e
);
1335 function editFeed(feed
, event
) {
1338 return alert(__("You can't edit this kind of feed."));
1340 var query
= "backend.php?op=pref-feeds&subop=editfeed&id=" +
1345 if (dijit
.byId("feedEditDlg"))
1346 dijit
.byId("feedEditDlg").destroyRecursive();
1348 dialog
= new dijit
.Dialog({
1350 title
: __("Edit Feed"),
1351 style
: "width: 600px",
1352 execute: function() {
1353 if (this.validate()) {
1354 // console.log(dojo.objectToQuery(this.attr('value')));
1356 notify_progress("Saving data...", true);
1358 new Ajax
.Request("backend.php", {
1359 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1360 onComplete: function(transport
) {
1371 exception_error("editFeed", e
);
1375 function feedBrowser() {
1377 var query
= "backend.php?op=dlg&id=feedBrowser";
1379 if (dijit
.byId("feedAddDlg"))
1380 dijit
.byId("feedAddDlg").hide();
1382 if (dijit
.byId("feedBrowserDlg"))
1383 dijit
.byId("feedBrowserDlg").destroyRecursive();
1385 var dialog
= new dijit
.Dialog({
1386 id
: "feedBrowserDlg",
1387 title
: __("More Feeds"),
1388 style
: "width: 600px",
1389 getSelectedFeeds: function() {
1390 var list
= $$("#browseFeedList li[id*=FBROW]");
1391 var selected
= new Array();
1393 list
.each(function(child
) {
1394 var id
= child
.id
.replace("FBROW-", "");
1396 if (child
.hasClassName('Selected')) {
1403 subscribe: function() {
1404 var selected
= this.getSelectedFeeds();
1405 var mode
= this.attr('value').mode
;
1407 if (selected
.length
> 0) {
1408 dijit
.byId("feedBrowserDlg").hide();
1410 notify_progress("Loading, please wait...", true);
1412 var query
= "?op=rpc&subop=massSubscribe&ids="+
1413 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1417 new Ajax
.Request("backend.php", {
1419 onComplete: function(transport
) {
1420 if (inPreferences()) {
1426 alert(__("No feeds are selected."));
1430 update: function() {
1431 var query
= dojo
.objectToQuery(dialog
.attr('value'));
1433 Element
.show('feed_browser_spinner');
1435 new Ajax
.Request("backend.php", {
1437 onComplete: function(transport
) {
1440 Element
.hide('feed_browser_spinner');
1442 var c
= $("browseFeedList");
1444 var reply
= JSON
.parse(transport
.responseText
);
1446 var r
= reply
['content'];
1447 var mode
= reply
['mode'];
1453 dojo
.parser
.parse("browseFeedList");
1456 Element
.show(dijit
.byId('feed_archive_remove').domNode
);
1458 Element
.hide(dijit
.byId('feed_archive_remove').domNode
);
1463 removeFromArchive: function() {
1464 var selected
= this.getSelectedFeeds();
1466 if (selected
.length
> 0) {
1468 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1471 Element
.show('feed_browser_spinner');
1473 var query
= "?op=rpc&subop=remarchived&ids=" +
1474 param_escape(selected
.toString());;
1476 new Ajax
.Request("backend.php", {
1478 onComplete: function(transport
) {
1484 execute: function() {
1485 if (this.validate()) {
1494 exception_error("editFeed", e
);