]>
git.wh0rd.org - tt-rss.git/blob - js/functions.js
1 var loading_progress
= 0;
2 var sanity_check_done
= false;
4 var _label_base_index
= -1024;
5 var notify_hide_timerid
= false;
7 Ajax
.Base
.prototype.initialize
= Ajax
.Base
.prototype.initialize
.wrap(
8 function (callOriginal
, options
) {
10 if (getInitParam("csrf_token") != undefined) {
11 Object
.extend(options
, options
|| { });
13 if (Object
.isString(options
.parameters
))
14 options
.parameters
= options
.parameters
.toQueryParams();
15 else if (Object
.isHash(options
.parameters
))
16 options
.parameters
= options
.parameters
.toObject();
18 options
.parameters
["csrf_token"] = getInitParam("csrf_token");
21 return callOriginal(options
);
25 /* add method to remove element from array */
27 Array
.prototype.remove = function(s
) {
28 for (var i
=0; i
< this.length
; i
++) {
29 if (s
== this[i
]) this.splice(i
, 1);
34 function report_error(message
, filename
, lineno
, colno
, error
) {
35 exception_error(error
);
38 function exception_error(e
, e_compat
) {
39 if (typeof e
== "string") e
= e_compat
;
41 if (!e
) return; // no exception object, nothing to report.
46 new Ajax
.Request("backend.php", {
47 parameters
: {op
: "rpc", method
: "log", logmsg
: msg
},
48 onComplete: function (transport
) {
49 console
.log(transport
.responseText
);
53 console
.error("Exception while trying to log the error.", e
);
56 var msg
= e
.toString();
60 var content
= "<div class='fatalError'><p>" + msg
+ "</p>";
63 content
+= "<div><b>Stack trace:</b></div>" +
64 "<textarea name=\"stack\" readonly=\"1\">" + e
.stack
+ "</textarea>";
69 content
+= "<div class='dlgButtons'>";
71 content
+= "<button dojoType=\"dijit.form.Button\" "+
72 "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
73 __('Close') + "</button>";
76 if (dijit
.byId("exceptionDlg"))
77 dijit
.byId("exceptionDlg").destroyRecursive();
79 var dialog
= new dijit
.Dialog({
81 title
: "Unhandled exception",
82 style
: "width: 600px",
88 console
.error("Exception while trying to report an exception:", ei
);
89 console
.error("Original exception:", e
);
91 alert("Exception occured while trying to report an exception.\n" +
92 ei
.stack
+ "\n\nOriginal exception:\n" + e
.stack
);
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 function notify_real(msg
, no_hide
, n_type
) {
117 if (notify_hide_timerid
) {
118 window
.clearTimeout(notify_hide_timerid
);
122 if (n
.hasClassName("visible")) {
123 notify_hide_timerid
= window
.setTimeout(function() {
124 n
.removeClassName("visible") }, 0);
138 msg
= "<span class=\"msg\"> " + __(msg
) + "</span>";
141 msg
= "<span><img src=\""+getInitParam("icon_indicator_white")+"\"></span>" + msg
;
143 } else if (n_type
== 3) {
144 msg
= "<span><img src=\""+getInitParam("icon_alert")+"\"></span>" + msg
;
145 } else if (n_type
== 4) {
146 msg
= "<span><img src=\""+getInitParam("icon_information")+"\"></span>" + msg
;
149 msg
+= " <span><img src=\""+getInitParam("icon_cross")+"\" class=\"close\" title=\"" +
150 __("Click to close") + "\" onclick=\"notify('')\"></span>";
154 window
.setTimeout(function() {
157 n
.className
= "notify notify_progress visible";
158 } else if (n_type
== 3) {
159 n
.className
= "notify notify_error visible";
160 msg
= "<span><img src='images/alert.png'></span>" + msg
;
161 } else if (n_type
== 4) {
162 n
.className
= "notify notify_info visible";
164 n
.className
= "notify visible";
168 notify_hide_timerid
= window
.setTimeout(function() {
169 n
.removeClassName("visible") }, 5*1000);
176 function notify(msg
, no_hide
) {
177 notify_real(msg
, no_hide
, 1);
180 function notify_progress(msg
, no_hide
) {
181 notify_real(msg
, no_hide
, 2);
184 function notify_error(msg
, no_hide
) {
185 notify_real(msg
, no_hide
, 3);
189 function notify_info(msg
, no_hide
) {
190 notify_real(msg
, no_hide
, 4);
193 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
199 d
.setTime(d
.getTime() + (lifetime
* 1000));
202 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
204 int_setCookie(name
, value
, d
, path
, domain
, secure
);
208 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
209 document
.cookie
= name
+ "=" + escape(value
) +
210 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
211 ((path
) ? "; path=" + path
: "") +
212 ((domain
) ? "; domain=" + domain
: "") +
213 ((secure
) ? "; secure" : "");
216 function delCookie(name
, path
, domain
) {
217 if (getCookie(name
)) {
218 document
.cookie
= name
+ "=" +
219 ((path
) ? ";path=" + path
: "") +
220 ((domain
) ? ";domain=" + domain
: "" ) +
221 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
226 function getCookie(name
) {
228 var dc
= document
.cookie
;
229 var prefix
= name
+ "=";
230 var begin
= dc
.indexOf("; " + prefix
);
232 begin
= dc
.indexOf(prefix
);
233 if (begin
!= 0) return null;
238 var end
= document
.cookie
.indexOf(";", begin
);
242 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
245 function gotoPreferences() {
246 document
.location
.href
= "prefs.php";
249 function gotoLogout() {
250 document
.location
.href
= "backend.php?op=logout";
253 function gotoMain() {
254 document
.location
.href
= "index.php";
257 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
258 * * @author Sundar Dorai-Raj
259 * * Email: sdoraira@vt.edu
260 * * This program is free software; you can redistribute it and/or
261 * * modify it under the terms of the GNU General Public License
262 * * as published by the Free Software Foundation; either version 2
263 * * of the License, or (at your option) any later version,
264 * * provided that any use properly credits the author.
265 * * This program is distributed in the hope that it will be useful,
266 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
267 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
268 * * GNU General Public License for more details at http://www.gnu.org * * */
270 var numbers
=".0123456789";
271 function isNumeric(x
) {
272 // is x a String or a character?
274 // remove negative sign
276 for(var j
=0;j
<x
.length
;j
++) {
277 // call isNumeric recursively for each character
278 number
=isNumeric(x
.substring(j
,j
+1));
279 if(!number
) return number
;
284 // if x is number return true
285 if(numbers
.indexOf(x
)>=0) return true;
291 function toggleSelectRowById(sender
, id
) {
293 return toggleSelectRow(sender
, row
);
296 function toggleSelectListRow(sender
) {
297 var row
= sender
.parentNode
;
298 return toggleSelectRow(sender
, row
);
301 /* this is for dijit Checkbox */
302 function toggleSelectListRow2(sender
) {
303 var row
= sender
.domNode
.parentNode
;
304 return toggleSelectRow(sender
, row
);
307 /* this is for dijit Checkbox */
308 function toggleSelectRow2(sender
, row
, is_cdm
) {
312 row
= sender
.domNode
.parentNode
.parentNode
;
314 row
= sender
.domNode
.parentNode
.parentNode
.parentNode
; // oh ffs
316 if (sender
.checked
&& !row
.hasClassName('Selected'))
317 row
.addClassName('Selected');
319 row
.removeClassName('Selected');
321 if (typeof updateSelectedPrompt
!= undefined)
322 updateSelectedPrompt();
326 function toggleSelectRow(sender
, row
) {
328 if (!row
) row
= sender
.parentNode
.parentNode
;
330 if (sender
.checked
&& !row
.hasClassName('Selected'))
331 row
.addClassName('Selected');
333 row
.removeClassName('Selected');
335 if (typeof updateSelectedPrompt
!= undefined)
336 updateSelectedPrompt();
339 function checkboxToggleElement(elem
, id
) {
341 Effect
.Appear(id
, {duration
: 0.5});
343 Effect
.Fade(id
, {duration
: 0.5});
347 function dropboxSelect(e
, v
) {
348 for (var i
= 0; i
< e
.length
; i
++) {
349 if (e
[i
].value
== v
) {
356 function getURLParam(param
){
357 return String(window
.location
.href
).parseQuery()[param
];
360 function closeInfoBox(cleanup
) {
361 dialog
= dijit
.byId("infoBox");
363 if (dialog
) dialog
.hide();
369 function displayDlg(title
, id
, param
, callback
) {
371 notify_progress("Loading, please wait...", true);
373 var query
= "?op=dlg&method=" +
374 param_escape(id
) + "¶m=" + param_escape(param
);
376 new Ajax
.Request("backend.php", {
378 onComplete: function (transport
) {
379 infobox_callback2(transport
, title
);
380 if (callback
) callback(transport
);
386 function infobox_callback2(transport
, title
) {
389 if (dijit
.byId("infoBox")) {
390 dialog
= dijit
.byId("infoBox");
393 //console.log("infobox_callback2");
396 var content
= transport
.responseText
;
399 dialog
= new dijit
.Dialog({
402 style
: "width: 600px",
403 onCancel: function() {
406 onExecute: function() {
409 onClose: function() {
414 dialog
.attr('title', title
);
415 dialog
.attr('content', content
);
423 function getInitParam(key
) {
424 return init_params
[key
];
427 function setInitParam(key
, value
) {
428 init_params
[key
] = value
;
431 function fatalError(code
, msg
, ext_info
) {
433 window
.location
.href
= "index.php";
434 } else if (code
== 5) {
435 window
.location
.href
= "public.php?op=dbupdate";
438 if (msg
== "") msg
= "Unknown error";
441 if (ext_info
.responseText
) {
442 ext_info
= ext_info
.responseText
;
446 if (ERRORS
&& ERRORS
[code
] && !msg
) {
450 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
451 "<p>" + msg
+ "</p>";
454 content
= content
+ "<div><b>Additional information:</b></div>" +
455 "<textarea style='width: 100%' readonly=\"1\">" +
456 ext_info
+ "</textarea>";
459 var dialog
= new dijit
.Dialog({
460 title
: "Fatal error",
461 style
: "width: 600px",
472 function filterDlgCheckAction(sender
) {
473 var action
= sender
.value
;
475 var action_param
= $("filterDlg_paramBox");
478 console
.log("filterDlgCheckAction: can't find action param box!");
482 // if selected action supports parameters, enable params field
483 if (action
== 4 || action
== 6 || action
== 7 || action
== 9) {
484 new Effect
.Appear(action_param
, {duration
: 0.5});
486 Element
.hide(dijit
.byId("filterDlg_actionParam").domNode
);
487 Element
.hide(dijit
.byId("filterDlg_actionParamLabel").domNode
);
488 Element
.hide(dijit
.byId("filterDlg_actionParamPlugin").domNode
);
491 Element
.show(dijit
.byId("filterDlg_actionParamLabel").domNode
);
492 } else if (action
== 9) {
493 Element
.show(dijit
.byId("filterDlg_actionParamPlugin").domNode
);
495 Element
.show(dijit
.byId("filterDlg_actionParam").domNode
);
499 Element
.hide(action_param
);
504 function explainError(code
) {
505 return displayDlg(__("Error explained"), "explainError", code
);
508 function loading_set_progress(p
) {
509 loading_progress
+= p
;
511 if (dijit
.byId("loading_bar"))
512 dijit
.byId("loading_bar").update({progress
: loading_progress
});
514 if (loading_progress
>= 90)
519 function remove_splash() {
521 if (Element
.visible("overlay")) {
522 console
.log("about to remove splash, OMG!");
523 Element
.hide("overlay");
524 console
.log("removed splash!");
528 function strip_tags(s
) {
529 return s
.replace(/<\/?[^>]+(>|$)/g, "");
532 function truncate_string(s
, length
) {
533 if (!length
) length
= 30;
534 var tmp
= s
.substring(0, length
);
535 if (s
.length
> length
) tmp
+= "…";
539 function hotkey_prefix_timeout() {
541 var date
= new Date();
542 var ts
= Math
.round(date
.getTime() / 1000);
544 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
545 console
.log("hotkey_prefix seems to be stuck, aborting");
546 hotkey_prefix_pressed
= false;
547 hotkey_prefix
= false;
548 Element
.hide('cmdline');
551 setTimeout(hotkey_prefix_timeout
, 1000);
555 function uploadIconHandler(rc
) {
558 notify_info("Upload complete.");
559 if (inPreferences()) {
562 setTimeout('updateFeedList(false, false)', 50);
566 notify_error("Upload failed: icon is too big.");
569 notify_error("Upload failed.");
574 function removeFeedIcon(id
) {
575 if (confirm(__("Remove stored feed icon?"))) {
576 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id
);
580 notify_progress("Removing feed icon...", true);
582 new Ajax
.Request("backend.php", {
584 onComplete: function(transport
) {
585 notify_info("Feed icon removed.");
586 if (inPreferences()) {
589 setTimeout('updateFeedList(false, false)', 50);
597 function uploadFeedIcon() {
598 var file
= $("icon_file");
600 if (file
.value
.length
== 0) {
601 alert(__("Please select an image file to upload."));
603 if (confirm(__("Upload new icon for this feed?"))) {
604 notify_progress("Uploading, please wait...", true);
612 function addLabel(select
, callback
) {
614 var caption
= prompt(__("Please enter label caption:"), "");
616 if (caption
!= undefined) {
619 alert(__("Can't create label: missing caption."));
623 var query
= "?op=pref-labels&method=add&caption=" +
624 param_escape(caption
);
627 query
+= "&output=select";
629 notify_progress("Loading, please wait...", true);
631 if (inPreferences() && !select
) active_tab
= "labelConfig";
633 new Ajax
.Request("backend.php", {
635 onComplete: function(transport
) {
638 } else if (inPreferences()) {
649 function quickAddFeed() {
650 var query
= "backend.php?op=feeds&method=quickAddFeed";
652 // overlapping widgets
653 if (dijit
.byId("batchSubDlg")) dijit
.byId("batchSubDlg").destroyRecursive();
654 if (dijit
.byId("feedAddDlg")) dijit
.byId("feedAddDlg").destroyRecursive();
656 var dialog
= new dijit
.Dialog({
658 title
: __("Subscribe to Feed"),
659 style
: "width: 600px",
660 show_error: function(msg
) {
661 var elem
= $("fadd_error_message");
663 elem
.innerHTML
= msg
;
665 if (!Element
.visible(elem
))
666 new Effect
.Appear(elem
);
669 execute: function() {
670 if (this.validate()) {
671 console
.log(dojo
.objectToQuery(this.attr('value')));
673 var feed_url
= this.attr('value').feed
;
675 Element
.show("feed_add_spinner");
676 Element
.hide("fadd_error_message");
678 new Ajax
.Request("backend.php", {
679 parameters
: dojo
.objectToQuery(this.attr('value')),
680 onComplete: function(transport
) {
684 var reply
= JSON
.parse(transport
.responseText
);
686 Element
.hide("feed_add_spinner");
687 alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console."));
688 console
.log('quickAddFeed, backend returned:' + transport
.responseText
);
692 var rc
= reply
['result'];
695 Element
.hide("feed_add_spinner");
699 switch (parseInt(rc
['code'])) {
702 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
707 dialog
.show_error(__("Specified URL seems to be invalid."));
710 dialog
.show_error(__("Specified URL doesn't seem to contain any feeds."));
715 Element
.show("fadd_multiple_notify");
717 var select
= dijit
.byId("feedDlg_feedContainerSelect");
719 while (select
.getOptions().length
> 0)
720 select
.removeOption(0);
722 select
.addOption({value
: '', label
: __("Expand to select feed")});
725 for (var feedUrl
in feeds
) {
726 select
.addOption({value
: feedUrl
, label
: feeds
[feedUrl
]});
730 Effect
.Appear('feedDlg_feedsContainer', {duration
: 0.5});
734 dialog
.show_error(__("Couldn't download the specified URL: %s").
735 replace("%s", rc
['message']));
738 dialog
.show_error(__("XML validation failed: %s").
739 replace("%s", rc
['message']));
743 dialog
.show_error(__("You are already subscribed to this feed."));
748 console
.error(transport
.responseText
);
761 function createNewRuleElement(parentNode
, replaceNode
) {
762 var form
= document
.forms
["filter_new_rule_form"];
764 //form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
766 var query
= "backend.php?op=pref-filters&method=printrulename&rule="+
767 param_escape(dojo
.formToJson(form
));
771 new Ajax
.Request("backend.php", {
773 onComplete: function (transport
) {
775 var li
= dojo
.create("li");
777 var cb
= dojo
.create("input", { type
: "checkbox" }, li
);
779 new dijit
.form
.CheckBox({
780 onChange: function() {
781 toggleSelectListRow2(this) },
784 dojo
.create("input", { type
: "hidden",
786 value
: dojo
.formToJson(form
) }, li
);
788 dojo
.create("span", {
789 onclick: function() {
790 dijit
.byId('filterEditDlg').editRule(this);
792 innerHTML
: transport
.responseText
}, li
);
795 parentNode
.replaceChild(li
, replaceNode
);
797 parentNode
.appendChild(li
);
805 function createNewActionElement(parentNode
, replaceNode
) {
806 var form
= document
.forms
["filter_new_action_form"];
808 if (form
.action_id
.value
== 7) {
809 form
.action_param
.value
= form
.action_param_label
.value
;
810 } else if (form
.action_id
.value
== 9) {
811 form
.action_param
.value
= form
.action_param_plugin
.value
;
814 var query
= "backend.php?op=pref-filters&method=printactionname&action="+
815 param_escape(dojo
.formToJson(form
));
819 new Ajax
.Request("backend.php", {
821 onComplete: function (transport
) {
823 var li
= dojo
.create("li");
825 var cb
= dojo
.create("input", { type
: "checkbox" }, li
);
827 new dijit
.form
.CheckBox({
828 onChange: function() {
829 toggleSelectListRow2(this) },
832 dojo
.create("input", { type
: "hidden",
834 value
: dojo
.formToJson(form
) }, li
);
836 dojo
.create("span", {
837 onclick: function() {
838 dijit
.byId('filterEditDlg').editAction(this);
840 innerHTML
: transport
.responseText
}, li
);
843 parentNode
.replaceChild(li
, replaceNode
);
845 parentNode
.appendChild(li
);
855 function addFilterRule(replaceNode
, ruleStr
) {
856 if (dijit
.byId("filterNewRuleDlg"))
857 dijit
.byId("filterNewRuleDlg").destroyRecursive();
859 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
860 param_escape(ruleStr
);
862 var rule_dlg
= new dijit
.Dialog({
863 id
: "filterNewRuleDlg",
864 title
: ruleStr
? __("Edit rule") : __("Add rule"),
865 style
: "width: 600px",
866 execute: function() {
867 if (this.validate()) {
868 createNewRuleElement($("filterDlg_Matches"), replaceNode
);
877 function addFilterAction(replaceNode
, actionStr
) {
878 if (dijit
.byId("filterNewActionDlg"))
879 dijit
.byId("filterNewActionDlg").destroyRecursive();
881 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
882 param_escape(actionStr
);
884 var rule_dlg
= new dijit
.Dialog({
885 id
: "filterNewActionDlg",
886 title
: actionStr
? __("Edit action") : __("Add action"),
887 style
: "width: 600px",
888 execute: function() {
889 if (this.validate()) {
890 createNewActionElement($("filterDlg_Actions"), replaceNode
);
899 function editFilterTest(query
) {
901 if (dijit
.byId("filterTestDlg"))
902 dijit
.byId("filterTestDlg").destroyRecursive();
904 var test_dlg
= new dijit
.Dialog({
906 title
: "Test Filter",
907 style
: "width: 600px",
911 getTestResults: function(query
, offset
) {
912 var updquery
= query
+ "&offset=" + offset
+ "&limit=" + test_dlg
.limit
;
914 console
.log("getTestResults:" + offset
);
916 new Ajax
.Request("backend.php", {
917 parameters
: updquery
,
918 onComplete: function (transport
) {
920 var result
= JSON
.parse(transport
.responseText
);
922 if (result
&& dijit
.byId("filterTestDlg") && dijit
.byId("filterTestDlg").open
) {
923 test_dlg
.results
+= result
.size();
925 console
.log("got results:" + result
.size());
927 $("prefFilterProgressMsg").innerHTML
= __("Looking for articles (%d processed, %f found)...")
928 .replace("%f", test_dlg
.results
)
929 .replace("%d", offset
);
931 console
.log(offset
+ " " + test_dlg
.max_offset
);
933 for (var i
= 0; i
< result
.size(); i
++) {
934 var tmp
= new Element("table");
935 tmp
.innerHTML
= result
[i
];
936 dojo
.parser
.parse(tmp
);
938 $("prefFilterTestResultList").innerHTML
+= tmp
.innerHTML
;
941 if (test_dlg
.results
< 30 && offset
< test_dlg
.max_offset
) {
943 // get the next batch
944 window
.setTimeout(function () {
945 test_dlg
.getTestResults(query
, offset
+ test_dlg
.limit
);
951 Element
.hide("prefFilterLoadingIndicator");
953 if (test_dlg
.results
== 0) {
954 $("prefFilterTestResultList").innerHTML
= "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
955 $("prefFilterProgressMsg").innerHTML
= "Articles matching this filter:";
957 $("prefFilterProgressMsg").innerHTML
= __("Found %d articles matching this filter:")
958 .replace("%d", test_dlg
.results
);
963 } else if (!result
) {
964 console
.log("getTestResults: can't parse results object");
966 Element
.hide("prefFilterLoadingIndicator");
968 notify_error("Error while trying to get filter test results.");
971 console
.log("getTestResults: dialog closed, bailing out.");
981 dojo
.connect(test_dlg
, "onLoad", null, function(e
) {
982 test_dlg
.getTestResults(query
, 0);
989 function quickAddFilter() {
991 if (!inPreferences()) {
992 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
993 param_escape(getActiveFeedId()) + "&is_cat=" +
994 param_escape(activeFeedIsCat());
996 query
= "backend.php?op=pref-filters&method=newfilter";
1001 if (dijit
.byId("feedEditDlg"))
1002 dijit
.byId("feedEditDlg").destroyRecursive();
1004 if (dijit
.byId("filterEditDlg"))
1005 dijit
.byId("filterEditDlg").destroyRecursive();
1007 dialog
= new dijit
.Dialog({
1008 id
: "filterEditDlg",
1009 title
: __("Create Filter"),
1010 style
: "width: 600px",
1012 var query
= "backend.php?" + dojo
.formToQuery("filter_new_form") + "&savemode=test";
1014 editFilterTest(query
);
1016 selectRules: function(select
) {
1017 $$("#filterDlg_Matches input[type=checkbox]").each(function(e
) {
1020 e
.parentNode
.addClassName("Selected");
1022 e
.parentNode
.removeClassName("Selected");
1025 selectActions: function(select
) {
1026 $$("#filterDlg_Actions input[type=checkbox]").each(function(e
) {
1030 e
.parentNode
.addClassName("Selected");
1032 e
.parentNode
.removeClassName("Selected");
1036 editRule: function(e
) {
1037 var li
= e
.parentNode
;
1038 var rule
= li
.getElementsByTagName("INPUT")[1].value
;
1039 addFilterRule(li
, rule
);
1041 editAction: function(e
) {
1042 var li
= e
.parentNode
;
1043 var action
= li
.getElementsByTagName("INPUT")[1].value
;
1044 addFilterAction(li
, action
);
1046 addAction: function() { addFilterAction(); },
1047 addRule: function() { addFilterRule(); },
1048 deleteAction: function() {
1049 $$("#filterDlg_Actions li.[class*=Selected]").each(function(e
) { e
.parentNode
.removeChild(e
) });
1051 deleteRule: function() {
1052 $$("#filterDlg_Matches li.[class*=Selected]").each(function(e
) { e
.parentNode
.removeChild(e
) });
1054 execute: function() {
1055 if (this.validate()) {
1057 var query
= dojo
.formToQuery("filter_new_form");
1061 new Ajax
.Request("backend.php", {
1063 onComplete: function (transport
) {
1064 if (inPreferences()) {
1074 if (!inPreferences()) {
1075 var selectedText
= getSelectionText();
1077 var lh
= dojo
.connect(dialog
, "onLoad", function(){
1078 dojo
.disconnect(lh
);
1080 if (selectedText
!= "") {
1082 var feed_id
= activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1085 var rule
= { reg_exp
: selectedText
, feed_id
: feed_id
, filter_type
: 1 };
1087 addFilterRule(null, dojo
.toJson(rule
));
1091 var query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
1093 new Ajax
.Request("backend.php", {
1095 onComplete: function(transport
) {
1096 var reply
= JSON
.parse(transport
.responseText
);
1100 if (reply
&& reply
) title
= reply
.title
;
1102 if (title
|| getActiveFeedId() || activeFeedIsCat()) {
1104 console
.log(title
+ " " + getActiveFeedId());
1106 var feed_id
= activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1109 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1111 addFilterRule(null, dojo
.toJson(rule
));
1125 function resetPubSub(feed_id
, title
) {
1127 var msg
= __("Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update.").replace("%s", title
);
1129 if (title
== undefined || confirm(msg
)) {
1130 notify_progress("Loading, please wait...");
1132 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1134 new Ajax
.Request("backend.php", {
1136 onComplete: function(transport
) {
1137 dijit
.byId("pubsubReset_Btn").attr('disabled', true);
1138 notify_info("Subscription reset.");
1146 function unsubscribeFeed(feed_id
, title
) {
1148 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1150 if (title
== undefined || confirm(msg
)) {
1151 notify_progress("Removing feed...");
1153 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1155 new Ajax
.Request("backend.php", {
1157 onComplete: function(transport
) {
1159 if (dijit
.byId("feedEditDlg")) dijit
.byId("feedEditDlg").hide();
1161 if (inPreferences()) {
1164 if (feed_id
== getActiveFeedId())
1165 setTimeout(function() { viewfeed({feed
:-5}) }, 100);
1167 if (feed_id
< 0) updateFeedList();
1177 function backend_sanity_check_callback(transport
) {
1179 if (sanity_check_done
) {
1180 fatalError(11, "Sanity check request received twice. This can indicate "+
1181 "presence of Firebug or some other disrupting extension. "+
1182 "Please disable it and try again.");
1186 var reply
= JSON
.parse(transport
.responseText
);
1189 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1193 var error_code
= reply
['error']['code'];
1195 if (error_code
&& error_code
!= 0) {
1196 return fatalError(error_code
, reply
['error']['message']);
1199 console
.log("sanity check ok");
1201 var params
= reply
['init-params'];
1204 console
.log('reading init-params...');
1207 console
.log("IP: " + k
+ " => " + JSON
.stringify(params
[k
]));
1208 if (k
== "label_base_index") _label_base_index
= parseInt(params
[k
]);
1211 init_params
= params
;
1213 // PluginHost might not be available on non-index pages
1214 window
.PluginHost
&& PluginHost
.run(PluginHost
.HOOK_PARAMS_LOADED
, init_params
);
1217 sanity_check_done
= true;
1219 init_second_stage();
1223 function quickAddCat(elem
) {
1224 var cat
= prompt(__("Please enter category title:"));
1228 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape(cat
);
1230 notify_progress("Loading, please wait...", true);
1232 new Ajax
.Request("backend.php", {
1234 onComplete: function (transport
) {
1235 var response
= transport
.responseXML
;
1236 var select
= response
.getElementsByTagName("select")[0];
1237 var options
= select
.getElementsByTagName("option");
1239 dropbox_replace_options(elem
, options
);
1248 function genUrlChangeKey(feed
, is_cat
) {
1249 var ok
= confirm(__("Generate new syndication address for this feed?"));
1253 notify_progress("Trying to change address...", true);
1255 var query
= "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed
) +
1256 "&is_cat=" + param_escape(is_cat
);
1258 new Ajax
.Request("backend.php", {
1260 onComplete: function(transport
) {
1261 var reply
= JSON
.parse(transport
.responseText
);
1262 var new_link
= reply
.link
;
1264 var e
= $('gen_feed_url');
1268 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1269 "&key=" + new_link
);
1271 e
.href
= e
.href
.replace(/\&key=.*$/,
1272 "&key=" + new_link
);
1274 new Effect
.Highlight(e
);
1279 notify_error("Could not change feed URL.");
1286 function dropbox_replace_options(elem
, options
) {
1287 while (elem
.hasChildNodes())
1288 elem
.removeChild(elem
.firstChild
);
1292 for (var i
= 0; i
< options
.length
; i
++) {
1293 var text
= options
[i
].firstChild
.nodeValue
;
1294 var value
= options
[i
].getAttribute("value");
1296 if (value
== undefined) value
= text
;
1298 var issel
= options
[i
].getAttribute("selected") == "1";
1300 var option
= new Option(text
, value
, issel
);
1302 if (options
[i
].getAttribute("disabled"))
1303 option
.setAttribute("disabled", true);
1305 elem
.insert(option
);
1307 if (issel
) sel_idx
= i
;
1310 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1311 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1314 // mode = all, none, invert
1315 function selectTableRows(id
, mode
) {
1316 var rows
= $(id
).rows
;
1318 for (var i
= 0; i
< rows
.length
; i
++) {
1323 if (row
.id
&& row
.className
) {
1324 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1325 var inputs
= rows
[i
].getElementsByTagName("input");
1327 for (var j
= 0; j
< inputs
.length
; j
++) {
1328 var input
= inputs
[j
];
1330 if (input
.getAttribute("type") == "checkbox" &&
1331 input
.id
.match(bare_id
)) {
1334 dcb
= dijit
.getEnclosingWidget(cb
);
1340 var issel
= row
.hasClassName("Selected");
1342 if (mode
== "all" && !issel
) {
1343 row
.addClassName("Selected");
1345 if (dcb
) dcb
.set("checked", true);
1346 } else if (mode
== "none" && issel
) {
1347 row
.removeClassName("Selected");
1349 if (dcb
) dcb
.set("checked", false);
1351 } else if (mode
== "invert") {
1354 row
.removeClassName("Selected");
1356 if (dcb
) dcb
.set("checked", false);
1358 row
.addClassName("Selected");
1360 if (dcb
) dcb
.set("checked", true);
1369 function getSelectedTableRowIds(id
) {
1372 var elem_rows
= $(id
).rows
;
1374 for (var i
= 0; i
< elem_rows
.length
; i
++) {
1375 if (elem_rows
[i
].hasClassName("Selected")) {
1376 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1384 function editFeed(feed
, event
) {
1386 return alert(__("You can't edit this kind of feed."));
1388 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1393 if (dijit
.byId("filterEditDlg"))
1394 dijit
.byId("filterEditDlg").destroyRecursive();
1396 if (dijit
.byId("feedEditDlg"))
1397 dijit
.byId("feedEditDlg").destroyRecursive();
1399 dialog
= new dijit
.Dialog({
1401 title
: __("Edit Feed"),
1402 style
: "width: 600px",
1403 execute: function() {
1404 if (this.validate()) {
1405 // console.log(dojo.objectToQuery(this.attr('value')));
1407 notify_progress("Saving data...", true);
1409 new Ajax
.Request("backend.php", {
1410 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1411 onComplete: function(transport
) {
1423 function feedBrowser() {
1424 var query
= "backend.php?op=feeds&method=feedBrowser";
1426 if (dijit
.byId("feedAddDlg"))
1427 dijit
.byId("feedAddDlg").hide();
1429 if (dijit
.byId("feedBrowserDlg"))
1430 dijit
.byId("feedBrowserDlg").destroyRecursive();
1432 var dialog
= new dijit
.Dialog({
1433 id
: "feedBrowserDlg",
1434 title
: __("More Feeds"),
1435 style
: "width: 600px",
1436 getSelectedFeedIds: function () {
1437 var list
= $$("#browseFeedList li[id*=FBROW]");
1438 var selected
= new Array();
1440 list
.each(function (child
) {
1441 var id
= child
.id
.replace("FBROW-", "");
1443 if (child
.hasClassName('Selected')) {
1450 getSelectedFeeds: function () {
1451 var list
= $$("#browseFeedList li.Selected");
1452 var selected
= new Array();
1454 list
.each(function (child
) {
1455 var title
= child
.getElementsBySelector("span.fb_feedTitle")[0].innerHTML
;
1456 var url
= child
.getElementsBySelector("a.fb_feedUrl")[0].href
;
1458 selected
.push([title
, url
]);
1465 subscribe: function () {
1466 var mode
= this.attr('value').mode
;
1470 selected
= this.getSelectedFeeds();
1472 selected
= this.getSelectedFeedIds();
1474 if (selected
.length
> 0) {
1475 dijit
.byId("feedBrowserDlg").hide();
1477 notify_progress("Loading, please wait...", true);
1479 // we use dojo.toJson instead of JSON.stringify because
1480 // it somehow escapes everything TWICE, at least in Chrome 9
1482 var query
= "?op=rpc&method=massSubscribe&payload=" +
1483 param_escape(dojo
.toJson(selected
)) + "&mode=" + param_escape(mode
);
1487 new Ajax
.Request("backend.php", {
1489 onComplete: function (transport
) {
1496 alert(__("No feeds are selected."));
1500 update: function () {
1501 var query
= dojo
.objectToQuery(dialog
.attr('value'));
1503 Element
.show('feed_browser_spinner');
1505 new Ajax
.Request("backend.php", {
1507 onComplete: function (transport
) {
1510 Element
.hide('feed_browser_spinner');
1512 var c
= $("browseFeedList");
1514 var reply
= JSON
.parse(transport
.responseText
);
1516 var r
= reply
['content'];
1517 var mode
= reply
['mode'];
1523 dojo
.parser
.parse("browseFeedList");
1526 Element
.show(dijit
.byId('feed_archive_remove').domNode
);
1528 Element
.hide(dijit
.byId('feed_archive_remove').domNode
);
1534 removeFromArchive: function () {
1535 var selected
= this.getSelectedFeedIds();
1537 if (selected
.length
> 0) {
1539 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1542 Element
.show('feed_browser_spinner');
1544 var query
= "?op=rpc&method=remarchive&ids=" +
1545 param_escape(selected
.toString());
1548 new Ajax
.Request("backend.php", {
1550 onComplete: function (transport
) {
1557 execute: function () {
1558 if (this.validate()) {
1568 function showFeedsWithErrors() {
1569 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors";
1571 if (dijit
.byId("errorFeedsDlg"))
1572 dijit
.byId("errorFeedsDlg").destroyRecursive();
1574 dialog
= new dijit
.Dialog({
1575 id
: "errorFeedsDlg",
1576 title
: __("Feeds with update errors"),
1577 style
: "width: 600px",
1578 getSelectedFeeds: function() {
1579 return getSelectedTableRowIds("prefErrorFeedList");
1581 removeSelected: function() {
1582 var sel_rows
= this.getSelectedFeeds();
1584 console
.log(sel_rows
);
1586 if (sel_rows
.length
> 0) {
1587 var ok
= confirm(__("Remove selected feeds?"));
1590 notify_progress("Removing selected feeds...", true);
1592 var query
= "?op=pref-feeds&method=remove&ids="+
1593 param_escape(sel_rows
.toString());
1595 new Ajax
.Request("backend.php", {
1597 onComplete: function(transport
) {
1605 alert(__("No feeds are selected."));
1608 execute: function() {
1609 if (this.validate()) {
1617 function get_timestamp() {
1618 var date
= new Date();
1619 return Math
.round(date
.getTime() / 1000);
1622 function helpDialog(topic
) {
1623 var query
= "backend.php?op=backend&method=help&topic=" + param_escape(topic
);
1625 if (dijit
.byId("helpDlg"))
1626 dijit
.byId("helpDlg").destroyRecursive();
1628 dialog
= new dijit
.Dialog({
1631 style
: "width: 600px",
1638 function htmlspecialchars_decode (string
, quote_style
) {
1639 // http://kevin.vanzonneveld.net
1640 // + original by: Mirek Slugen
1641 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1642 // + bugfixed by: Mateusz "loonquawl" Zalega
1643 // + input by: ReverseSyntax
1644 // + input by: Slawomir Kaniecki
1645 // + input by: Scott Cariss
1646 // + input by: Francois
1647 // + bugfixed by: Onno Marsman
1648 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1649 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1650 // + input by: Ratheous
1651 // + input by: Mailfaker (http://www.weedem.fr/)
1652 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1653 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1654 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1655 // * returns 1: '<p>this -> "</p>'
1656 // * example 2: htmlspecialchars_decode("&quot;");
1657 // * returns 2: '"'
1661 if (typeof quote_style
=== 'undefined') {
1664 string
= string
.toString().replace(/</g, '<').replace(/>/g, '>');
1667 'ENT_HTML_QUOTE_SINGLE': 1,
1668 'ENT_HTML_QUOTE_DOUBLE': 2,
1673 if (quote_style
=== 0) {
1676 if (typeof quote_style
!== 'number') { // Allow for a single string or an array of string flags
1677 quote_style
= [].concat(quote_style
);
1678 for (i
= 0; i
< quote_style
.length
; i
++) {
1679 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1680 if (OPTS
[quote_style
[i
]] === 0) {
1682 } else if (OPTS
[quote_style
[i
]]) {
1683 optTemp
= optTemp
| OPTS
[quote_style
[i
]];
1686 quote_style
= optTemp
;
1688 if (quote_style
& OPTS
.ENT_HTML_QUOTE_SINGLE
) {
1689 string
= string
.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
1690 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1693 string
= string
.replace(/"/g, '"');
1695 // Put this in last place to avoid escape being double-decoded
1696 string
= string
.replace(/&/g, '&');
1702 function label_to_feed_id(label
) {
1703 return _label_base_index
- 1 - Math
.abs(label
);
1706 function feed_to_label_id(feed
) {
1707 return _label_base_index
- 1 + Math
.abs(feed
);
1710 // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
1712 function getSelectionText() {
1715 if (typeof window
.getSelection
!= "undefined") {
1716 var sel
= window
.getSelection();
1717 if (sel
.rangeCount
) {
1718 var container
= document
.createElement("div");
1719 for (var i
= 0, len
= sel
.rangeCount
; i
< len
; ++i
) {
1720 container
.appendChild(sel
.getRangeAt(i
).cloneContents());
1722 text
= container
.innerHTML
;
1724 } else if (typeof document
.selection
!= "undefined") {
1725 if (document
.selection
.type
== "Text") {
1726 text
= document
.selection
.createRange().textText
;
1730 return text
.stripTags();
1733 function openUrlPopup(url
) {
1734 var w
= window
.open("");
1739 function openArticlePopup(id
) {
1740 var w
= window
.open("",
1741 "ttrss_article_popup",
1742 "height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no");
1745 w
.location
= "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id
+ "&csrf_token=" + getInitParam("csrf_token");