]>
git.wh0rd.org - tt-rss.git/blob - functions.js
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 if (transport
.responseXML
) {
611 var result
= transport
.responseXML
.getElementsByTagName("result")[0];
613 if (result
&& result
.firstChild
) {
614 if (result
.firstChild
.nodeValue
== "1") {
615 alert(__("Date syntax appears to be correct."));
621 alert(__("Date syntax is incorrect."));
627 exception_error("filterDlgCheckDate", e
);
631 function explainError(code
) {
632 return displayDlg("explainError", code
);
635 function displayHelpInfobox(topic_id
) {
637 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
639 var w
= window
.open(url
, "ttrss_help",
640 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
644 function loading_set_progress(p
) {
646 loading_progress
+= p
;
648 if (dijit
.byId("loading_bar"))
649 dijit
.byId("loading_bar").update({progress
: loading_progress
});
651 if (loading_progress
>= 90)
655 exception_error("loading_set_progress", e
);
659 function remove_splash() {
661 if (Element
.visible("overlay")) {
662 console
.log("about to remove splash, OMG!");
663 Element
.hide("overlay");
664 console
.log("removed splash!");
668 function transport_error_check(transport
) {
670 if (transport
.responseXML
) {
671 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
674 var code
= error
.getAttribute("error-code");
675 var msg
= error
.getAttribute("error-msg");
677 fatalError(code
, msg
);
683 exception_error("check_for_error_xml", e
);
688 function strip_tags(s
) {
689 return s
.replace(/<\/?[^>]+(>|$)/g, "");
692 function truncate_string(s
, length
) {
693 if (!length
) length
= 30;
694 var tmp
= s
.substring(0, length
);
695 if (s
.length
> length
) tmp
+= "…";
699 function hotkey_prefix_timeout() {
702 var date
= new Date();
703 var ts
= Math
.round(date
.getTime() / 1000);
705 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
706 console
.log("hotkey_prefix seems to be stuck, aborting");
707 hotkey_prefix_pressed
= false;
708 hotkey_prefix
= false;
709 Element
.hide('cmdline');
712 setTimeout("hotkey_prefix_timeout()", 1000);
715 exception_error("hotkey_prefix_timeout", e
);
719 function hideAuxDlg() {
721 Element
.hide('auxDlg');
723 exception_error("hideAuxDlg", e
);
728 function uploadIconHandler(rc
) {
732 notify_info("Upload complete.");
733 if (inPreferences()) {
736 setTimeout('updateFeedList(false, false)', 50);
740 notify_error("Upload failed: icon is too big.");
743 notify_error("Upload failed.");
748 exception_error("uploadIconHandler", e
);
752 function removeFeedIcon(id
) {
756 if (confirm(__("Remove stored feed icon?"))) {
757 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
761 notify_progress("Removing feed icon...", true);
763 new Ajax
.Request("backend.php", {
765 onComplete: function(transport
) {
766 notify_info("Feed icon removed.");
767 if (inPreferences()) {
770 setTimeout('updateFeedList(false, false)', 50);
777 exception_error("uploadFeedIcon", e
);
781 function uploadFeedIcon() {
785 var file
= $("icon_file");
787 if (file
.value
.length
== 0) {
788 alert(__("Please select an image file to upload."));
790 if (confirm(__("Upload new icon for this feed?"))) {
791 notify_progress("Uploading, please wait...", true);
799 exception_error("uploadFeedIcon", e
);
803 function addLabel(select
, callback
) {
807 var caption
= prompt(__("Please enter label caption:"), "");
809 if (caption
!= undefined) {
812 alert(__("Can't create label: missing caption."));
816 var query
= "?op=pref-labels&subop=add&caption=" +
817 param_escape(caption
);
820 query
+= "&output=select";
822 notify_progress("Loading, please wait...", true);
824 if (inPreferences() && !select
) active_tab
= "labelConfig";
826 new Ajax
.Request("backend.php", {
828 onComplete: function(transport
) {
831 } else if (inPreferences()) {
841 exception_error("addLabel", e
);
845 function quickAddFeed() {
847 var query
= "backend.php?op=dlg&id=quickAddFeed";
849 if (dijit
.byId("feedAddDlg"))
850 dijit
.byId("feedAddDlg").destroyRecursive();
852 var dialog
= new dijit
.Dialog({
854 title
: __("Subscribe to Feed"),
855 style
: "width: 600px",
856 execute: function() {
857 if (this.validate()) {
858 console
.log(dojo
.objectToQuery(this.attr('value')));
860 var feed_url
= this.attr('value').feed
;
862 notify_progress(__("Subscribing to feed..."), true);
864 new Ajax
.Request("backend.php", {
865 parameters
: dojo
.objectToQuery(this.attr('value')),
866 onComplete: function(transport
) {
869 var reply
= JSON
.parse(transport
.responseText
);
871 var rc
= parseInt(reply
['result']);
875 console
.log("GOT RC: " + rc
);
880 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
885 alert(__("Specified URL seems to be invalid."));
888 alert(__("Specified URL doesn't seem to contain any feeds."));
891 notify_progress("Searching for feed urls...", true);
893 new Ajax
.Request("backend.php", {
894 parameters
: 'op=rpc&subop=extractfeedurls&url=' + param_escape(feed_url
),
895 onComplete: function(transport
, dialog
, feed_url
) {
899 var reply
= JSON
.parse(transport
.responseText
);
901 var feeds
= reply
['urls'];
903 console
.log(transport
.responseText
);
905 var select
= dijit
.byId("feedDlg_feedContainerSelect");
907 while (select
.getOptions().length
> 0)
908 select
.removeOption(0);
911 for (var feedUrl
in feeds
) {
912 select
.addOption({value
: feedUrl
, label
: feeds
[feedUrl
]});
916 // if (count > 5) count = 5;
917 // select.size = count;
919 Effect
.Appear('feedDlg_feedsContainer', {duration
: 0.5});
924 alert(__("Couldn't download the specified URL."));
927 alert(__("You are already subscribed to this feed."));
932 exception_error("subscribeToFeed", e
);
943 exception_error("quickAddFeed", e
);
947 function quickAddFilter() {
949 var query
= "backend.php?op=dlg&id=quickAddFilter";
951 if (dijit
.byId("filterEditDlg"))
952 dijit
.byId("filterEditDlg").destroyRecursive();
954 dialog
= new dijit
.Dialog({
956 title
: __("Create Filter"),
957 style
: "width: 600px",
958 execute: function() {
959 if (this.validate()) {
961 var query
= "?op=rpc&subop=verifyRegexp®_exp=" +
962 param_escape(dialog
.attr('value').reg_exp
);
964 notify_progress("Verifying regular expression...");
966 new Ajax
.Request("backend.php", {
968 onComplete: function(transport
) {
969 handle_rpc_reply(transport
);
970 var response
= transport
.responseXML
;
973 var s
= response
.getElementsByTagName("status")[0].firstChild
.nodeValue
;
977 if (s
== "INVALID") {
978 alert("Match regular expression seems to be invalid.");
981 notify_progress("Saving data...", true);
983 console
.log(dojo
.objectToQuery(dialog
.attr('value')));
985 new Ajax
.Request("backend.php", {
986 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
987 onComplete: function(transport
) {
989 notify_info(transport
.responseText
);
990 if (inPreferences()) {
1003 exception_error("quickAddFilter", e
);
1007 function unsubscribeFeed(feed_id
, title
) {
1009 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1011 if (title
== undefined || confirm(msg
)) {
1012 notify_progress("Removing feed...");
1014 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1016 new Ajax
.Request("backend.php", {
1018 onComplete: function(transport
) {
1020 if (dijit
.byId("feedEditDlg")) dijit
.byId("feedEditDlg").hide();
1022 if (inPreferences()) {
1025 if (feed_id
== getActiveFeedId())
1026 setTimeout("viewfeed(-5)", 100);
1036 function backend_sanity_check_callback(transport
) {
1040 if (sanity_check_done
) {
1041 fatalError(11, "Sanity check request received twice. This can indicate "+
1042 "presence of Firebug or some other disrupting extension. "+
1043 "Please disable it and try again.");
1047 if (!transport
.responseXML
) {
1049 fatalError(3, "Sanity check: Received reply is not XML",
1050 transport
.responseText
);
1055 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1058 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1062 var error_code
= reply
.getAttribute("error-code");
1064 if (error_code
&& error_code
!= 0) {
1065 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1068 console
.log("sanity check ok");
1070 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1073 console
.log('reading init-params...');
1075 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1080 console
.log("IP: " + k
+ " => " + v
);
1084 init_params
= params
;
1087 sanity_check_done
= true;
1089 init_second_stage();
1092 exception_error("backend_sanity_check_callback", e
, transport
);
1096 function has_local_storage() {
1098 return 'sessionStorage' in window
&& window
['sessionStorage'] != null;
1104 function catSelectOnChange(elem
) {
1106 /* var value = elem[elem.selectedIndex].value;
1107 var def = elem.getAttribute('default');
1109 if (value == "ADD_CAT") {
1112 dropboxSelect(elem, def);
1114 elem.selectedIndex = 0;
1120 exception_error("catSelectOnChange", e
);
1124 function quickAddCat(elem
) {
1126 var cat
= prompt(__("Please enter category title:"));
1130 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1132 notify_progress("Loading, please wait...", true);
1134 new Ajax
.Request("backend.php", {
1136 onComplete: function (transport
) {
1137 var response
= transport
.responseXML
;
1138 var select
= response
.getElementsByTagName("select")[0];
1139 var options
= select
.getElementsByTagName("option");
1141 dropbox_replace_options(elem
, options
);
1150 exception_error("quickAddCat", e
);
1154 function genUrlChangeKey(feed
, is_cat
) {
1157 var ok
= confirm(__("Generate new syndication address for this feed?"));
1161 notify_progress("Trying to change address...", true);
1163 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1164 "&is_cat=" + param_escape(is_cat
);
1166 new Ajax
.Request("backend.php", {
1168 onComplete: function(transport
) {
1169 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
1171 var e
= $('gen_feed_url');
1175 new_link
= new_link
.firstChild
.nodeValue
;
1177 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1178 "&key=" + new_link
);
1180 e
.href
= e
.href
.replace(/\&key=.*$/,
1181 "&key=" + new_link
);
1183 new Effect
.Highlight(e
);
1188 notify_error("Could not change feed URL.");
1193 exception_error("genUrlChangeKey", e
);
1198 function labelSelectOnChange(elem
) {
1200 /* var value = elem[elem.selectedIndex].value;
1201 var def = elem.getAttribute('default');
1203 if (value == "ADD_LABEL") {
1206 dropboxSelect(elem, def);
1208 elem.selectedIndex = 0;
1210 addLabel(elem, function(transport) {
1214 var response = transport.responseXML;
1215 var select = response.getElementsByTagName("select")[0];
1216 var options = select.getElementsByTagName("option");
1218 dropbox_replace_options(elem, options);
1222 exception_error("addLabel", e);
1228 exception_error("labelSelectOnChange", e
);
1232 function dropbox_replace_options(elem
, options
) {
1235 while (elem
.hasChildNodes())
1236 elem
.removeChild(elem
.firstChild
);
1240 for (var i
= 0; i
< options
.length
; i
++) {
1241 var text
= options
[i
].firstChild
.nodeValue
;
1242 var value
= options
[i
].getAttribute("value");
1244 if (value
== undefined) value
= text
;
1246 var issel
= options
[i
].getAttribute("selected") == "1";
1248 var option
= new Option(text
, value
, issel
);
1250 if (options
[i
].getAttribute("disabled"))
1251 option
.setAttribute("disabled", true);
1253 elem
.insert(option
);
1255 if (issel
) sel_idx
= i
;
1258 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1259 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1262 exception_error("dropbox_replace_options", e
);
1266 // mode = all, none, invert
1267 function selectTableRows(id
, mode
) {
1269 var rows
= $(id
).rows
;
1271 for (var i
= 0; i
< rows
.length
; i
++) {
1275 if (row
.id
&& row
.className
) {
1276 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1277 var inputs
= rows
[i
].getElementsByTagName("input");
1279 for (var j
= 0; j
< inputs
.length
; j
++) {
1280 var input
= inputs
[j
];
1282 if (input
.getAttribute("type") == "checkbox" &&
1283 input
.id
.match(bare_id
)) {
1291 var issel
= row
.hasClassName("Selected");
1293 if (mode
== "all" && !issel
) {
1294 row
.addClassName("Selected");
1296 } else if (mode
== "none" && issel
) {
1297 row
.removeClassName("Selected");
1299 } else if (mode
== "invert") {
1302 row
.removeClassName("Selected");
1305 row
.addClassName("Selected");
1314 exception_error("selectTableRows", e
);
1319 function getSelectedTableRowIds(id
) {
1323 var elem_rows
= $(id
).rows
;
1325 for (i
= 0; i
< elem_rows
.length
; i
++) {
1326 if (elem_rows
[i
].hasClassName("Selected")) {
1327 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1333 exception_error("getSelectedTableRowIds", e
);
1339 function editFeed(feed
, event
) {
1342 return alert(__("You can't edit this kind of feed."));
1344 var query
= "backend.php?op=pref-feeds&subop=editfeed&id=" +
1349 if (dijit
.byId("feedEditDlg"))
1350 dijit
.byId("feedEditDlg").destroyRecursive();
1352 dialog
= new dijit
.Dialog({
1354 title
: __("Edit Feed"),
1355 style
: "width: 600px",
1356 execute: function() {
1357 if (this.validate()) {
1358 // console.log(dojo.objectToQuery(this.attr('value')));
1360 notify_progress("Saving data...", true);
1362 new Ajax
.Request("backend.php", {
1363 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1364 onComplete: function(transport
) {
1375 exception_error("editFeed", e
);
1379 function feedBrowser() {
1381 var query
= "backend.php?op=dlg&id=feedBrowser";
1383 if (dijit
.byId("feedAddDlg"))
1384 dijit
.byId("feedAddDlg").hide();
1386 if (dijit
.byId("feedBrowserDlg"))
1387 dijit
.byId("feedBrowserDlg").destroyRecursive();
1389 var dialog
= new dijit
.Dialog({
1390 id
: "feedBrowserDlg",
1391 title
: __("More Feeds"),
1392 style
: "width: 600px",
1393 getSelectedFeeds: function() {
1394 var list
= $$("#browseFeedList li[id*=FBROW]");
1395 var selected
= new Array();
1397 list
.each(function(child
) {
1398 var id
= child
.id
.replace("FBROW-", "");
1400 if (child
.hasClassName('Selected')) {
1407 subscribe: function() {
1408 var selected
= this.getSelectedFeeds();
1409 var mode
= this.attr('value').mode
;
1411 if (selected
.length
> 0) {
1412 dijit
.byId("feedBrowserDlg").hide();
1414 notify_progress("Loading, please wait...", true);
1416 var query
= "?op=rpc&subop=massSubscribe&ids="+
1417 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1421 new Ajax
.Request("backend.php", {
1423 onComplete: function(transport
) {
1425 var nf
= transport
.responseXML
.getElementsByTagName('num-feeds')[0];
1426 var nf_value
= nf
.getAttribute("value");
1428 notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value
));
1430 if (inPreferences()) {
1436 alert(__("No feeds are selected."));
1440 update: function() {
1441 var query
= dojo
.objectToQuery(dialog
.attr('value'));
1443 Element
.show('feed_browser_spinner');
1445 new Ajax
.Request("backend.php", {
1447 onComplete: function(transport
) {
1450 Element
.hide('feed_browser_spinner');
1452 var c
= $("browseFeedList");
1453 var r
= transport
.responseXML
.getElementsByTagName("content")[0];
1454 var nr
= transport
.responseXML
.getElementsByTagName("num-results")[0];
1455 var mode
= transport
.responseXML
.getElementsByTagName("mode")[0];
1458 c
.innerHTML
= r
.firstChild
.nodeValue
;
1461 dojo
.parser
.parse("browseFeedList");
1463 if (parseInt(mode
.getAttribute("value")) == 2) {
1464 Element
.show(dijit
.byId('feed_archive_remove').domNode
);
1466 Element
.hide(dijit
.byId('feed_archive_remove').domNode
);
1471 removeFromArchive: function() {
1472 var selected
= this.getSelectedFeeds();
1474 if (selected
.length
> 0) {
1476 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1479 Element
.show('feed_browser_spinner');
1481 var query
= "?op=rpc&subop=remarchived&ids=" +
1482 param_escape(selected
.toString());;
1484 new Ajax
.Request("backend.php", {
1486 onComplete: function(transport
) {
1492 execute: function() {
1493 if (this.validate()) {
1502 exception_error("editFeed", e
);