]>
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
, null, filename
, lineno
);
38 function exception_error(e
, e_compat
, filename
, lineno
, colno
) {
39 if (typeof e
== "string") e
= e_compat
;
41 if (!e
) return; // no exception object, nothing to report.
45 var msg
= e
.toString();
48 new Ajax
.Request("backend.php", {
49 parameters
: {op
: "rpc", method
: "log",
50 file
: e
.fileName
? e
.fileName
: filename
,
51 line
: e
.lineNumber
? e
.lineNumber
: lineno
,
52 msg
: msg
, context
: e
.stack
},
53 onComplete: function (transport
) {
54 console
.warn(transport
.responseText
);
58 console
.error("Exception while trying to log the error.", e
);
61 var content
= "<div class='fatalError'><p>" + msg
+ "</p>";
64 content
+= "<div><b>Stack trace:</b></div>" +
65 "<textarea name=\"stack\" readonly=\"1\">" + e
.stack
+ "</textarea>";
70 content
+= "<div class='dlgButtons'>";
72 content
+= "<button dojoType=\"dijit.form.Button\" "+
73 "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
74 __('Close') + "</button>";
77 if (dijit
.byId("exceptionDlg"))
78 dijit
.byId("exceptionDlg").destroyRecursive();
80 var dialog
= new dijit
.Dialog({
82 title
: "Unhandled exception",
83 style
: "width: 600px",
89 console
.error("Exception while trying to report an exception:", ei
);
90 console
.error("Original exception:", e
);
92 alert("Exception occured while trying to report an exception.\n" +
93 ei
.stack
+ "\n\nOriginal exception:\n" + e
.stack
);
98 function param_escape(arg
) {
99 if (typeof encodeURIComponent
!= 'undefined')
100 return encodeURIComponent(arg
);
105 function param_unescape(arg
) {
106 if (typeof decodeURIComponent
!= 'undefined')
107 return decodeURIComponent(arg
);
109 return unescape(arg
);
112 function notify_real(msg
, no_hide
, n_type
) {
118 if (notify_hide_timerid
) {
119 window
.clearTimeout(notify_hide_timerid
);
123 if (n
.hasClassName("visible")) {
124 notify_hide_timerid
= window
.setTimeout(function() {
125 n
.removeClassName("visible") }, 0);
139 msg
= "<span class=\"msg\"> " + __(msg
) + "</span>";
142 msg
= "<span><img src=\""+getInitParam("icon_indicator_white")+"\"></span>" + msg
;
144 } else if (n_type
== 3) {
145 msg
= "<span><img src=\""+getInitParam("icon_alert")+"\"></span>" + msg
;
146 } else if (n_type
== 4) {
147 msg
= "<span><img src=\""+getInitParam("icon_information")+"\"></span>" + msg
;
150 msg
+= " <span><img src=\""+getInitParam("icon_cross")+"\" class=\"close\" title=\"" +
151 __("Click to close") + "\" onclick=\"notify('')\"></span>";
155 window
.setTimeout(function() {
158 n
.className
= "notify notify_progress visible";
159 } else if (n_type
== 3) {
160 n
.className
= "notify notify_error visible";
161 msg
= "<span><img src='images/alert.png'></span>" + msg
;
162 } else if (n_type
== 4) {
163 n
.className
= "notify notify_info visible";
165 n
.className
= "notify visible";
169 notify_hide_timerid
= window
.setTimeout(function() {
170 n
.removeClassName("visible") }, 5*1000);
177 function notify(msg
, no_hide
) {
178 notify_real(msg
, no_hide
, 1);
181 function notify_progress(msg
, no_hide
) {
182 notify_real(msg
, no_hide
, 2);
185 function notify_error(msg
, no_hide
) {
186 notify_real(msg
, no_hide
, 3);
190 function notify_info(msg
, no_hide
) {
191 notify_real(msg
, no_hide
, 4);
194 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
200 d
.setTime(d
.getTime() + (lifetime
* 1000));
203 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
205 int_setCookie(name
, value
, d
, path
, domain
, secure
);
209 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
210 document
.cookie
= name
+ "=" + escape(value
) +
211 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
212 ((path
) ? "; path=" + path
: "") +
213 ((domain
) ? "; domain=" + domain
: "") +
214 ((secure
) ? "; secure" : "");
217 function delCookie(name
, path
, domain
) {
218 if (getCookie(name
)) {
219 document
.cookie
= name
+ "=" +
220 ((path
) ? ";path=" + path
: "") +
221 ((domain
) ? ";domain=" + domain
: "" ) +
222 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
227 function getCookie(name
) {
229 var dc
= document
.cookie
;
230 var prefix
= name
+ "=";
231 var begin
= dc
.indexOf("; " + prefix
);
233 begin
= dc
.indexOf(prefix
);
234 if (begin
!= 0) return null;
239 var end
= document
.cookie
.indexOf(";", begin
);
243 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
246 function gotoPreferences() {
247 document
.location
.href
= "prefs.php";
250 function gotoLogout() {
251 document
.location
.href
= "backend.php?op=logout";
254 function gotoMain() {
255 document
.location
.href
= "index.php";
258 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
259 * * @author Sundar Dorai-Raj
260 * * Email: sdoraira@vt.edu
261 * * This program is free software; you can redistribute it and/or
262 * * modify it under the terms of the GNU General Public License
263 * * as published by the Free Software Foundation; either version 2
264 * * of the License, or (at your option) any later version,
265 * * provided that any use properly credits the author.
266 * * This program is distributed in the hope that it will be useful,
267 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
268 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
269 * * GNU General Public License for more details at http://www.gnu.org * * */
271 var numbers
=".0123456789";
272 function isNumeric(x
) {
273 // is x a String or a character?
275 // remove negative sign
277 for(var j
=0;j
<x
.length
;j
++) {
278 // call isNumeric recursively for each character
279 number
=isNumeric(x
.substring(j
,j
+1));
280 if(!number
) return number
;
285 // if x is number return true
286 if(numbers
.indexOf(x
)>=0) return true;
292 function toggleSelectRowById(sender
, id
) {
294 return toggleSelectRow(sender
, row
);
297 function toggleSelectListRow(sender
) {
298 var row
= sender
.parentNode
;
299 return toggleSelectRow(sender
, row
);
302 /* this is for dijit Checkbox */
303 function toggleSelectListRow2(sender
) {
304 var row
= sender
.domNode
.parentNode
;
305 return toggleSelectRow(sender
, row
);
308 /* this is for dijit Checkbox */
309 function toggleSelectRow2(sender
, row
, is_cdm
) {
313 row
= sender
.domNode
.parentNode
.parentNode
;
315 row
= sender
.domNode
.parentNode
.parentNode
.parentNode
; // oh ffs
317 if (sender
.checked
&& !row
.hasClassName('Selected'))
318 row
.addClassName('Selected');
320 row
.removeClassName('Selected');
322 if (typeof updateSelectedPrompt
!= undefined)
323 updateSelectedPrompt();
327 function toggleSelectRow(sender
, row
) {
329 if (!row
) row
= sender
.parentNode
.parentNode
;
331 if (sender
.checked
&& !row
.hasClassName('Selected'))
332 row
.addClassName('Selected');
334 row
.removeClassName('Selected');
336 if (typeof updateSelectedPrompt
!= undefined)
337 updateSelectedPrompt();
340 function checkboxToggleElement(elem
, id
) {
342 Effect
.Appear(id
, {duration
: 0.5});
344 Effect
.Fade(id
, {duration
: 0.5});
348 function dropboxSelect(e
, v
) {
349 for (var i
= 0; i
< e
.length
; i
++) {
350 if (e
[i
].value
== v
) {
357 function getURLParam(param
){
358 return String(window
.location
.href
).parseQuery()[param
];
361 function closeInfoBox(cleanup
) {
362 dialog
= dijit
.byId("infoBox");
364 if (dialog
) dialog
.hide();
370 function displayDlg(title
, id
, param
, callback
) {
372 notify_progress("Loading, please wait...", true);
374 var query
= "?op=dlg&method=" +
375 param_escape(id
) + "¶m=" + param_escape(param
);
377 new Ajax
.Request("backend.php", {
379 onComplete: function (transport
) {
380 infobox_callback2(transport
, title
);
381 if (callback
) callback(transport
);
387 function infobox_callback2(transport
, title
) {
390 if (dijit
.byId("infoBox")) {
391 dialog
= dijit
.byId("infoBox");
394 //console.log("infobox_callback2");
397 var content
= transport
.responseText
;
400 dialog
= new dijit
.Dialog({
403 style
: "width: 600px",
404 onCancel: function() {
407 onExecute: function() {
410 onClose: function() {
415 dialog
.attr('title', title
);
416 dialog
.attr('content', content
);
424 function getInitParam(key
) {
425 return init_params
[key
];
428 function setInitParam(key
, value
) {
429 init_params
[key
] = value
;
432 function fatalError(code
, msg
, ext_info
) {
434 window
.location
.href
= "index.php";
435 } else if (code
== 5) {
436 window
.location
.href
= "public.php?op=dbupdate";
439 if (msg
== "") msg
= "Unknown error";
442 if (ext_info
.responseText
) {
443 ext_info
= ext_info
.responseText
;
447 if (ERRORS
&& ERRORS
[code
] && !msg
) {
451 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
452 "<p>" + msg
+ "</p>";
455 content
= content
+ "<div><b>Additional information:</b></div>" +
456 "<textarea style='width: 100%' readonly=\"1\">" +
457 ext_info
+ "</textarea>";
460 var dialog
= new dijit
.Dialog({
461 title
: "Fatal error",
462 style
: "width: 600px",
473 function filterDlgCheckAction(sender
) {
474 var action
= sender
.value
;
476 var action_param
= $("filterDlg_paramBox");
479 console
.log("filterDlgCheckAction: can't find action param box!");
483 // if selected action supports parameters, enable params field
484 if (action
== 4 || action
== 6 || action
== 7 || action
== 9) {
485 new Effect
.Appear(action_param
, {duration
: 0.5});
487 Element
.hide(dijit
.byId("filterDlg_actionParam").domNode
);
488 Element
.hide(dijit
.byId("filterDlg_actionParamLabel").domNode
);
489 Element
.hide(dijit
.byId("filterDlg_actionParamPlugin").domNode
);
492 Element
.show(dijit
.byId("filterDlg_actionParamLabel").domNode
);
493 } else if (action
== 9) {
494 Element
.show(dijit
.byId("filterDlg_actionParamPlugin").domNode
);
496 Element
.show(dijit
.byId("filterDlg_actionParam").domNode
);
500 Element
.hide(action_param
);
505 function explainError(code
) {
506 return displayDlg(__("Error explained"), "explainError", code
);
509 function loading_set_progress(p
) {
510 loading_progress
+= p
;
512 if (dijit
.byId("loading_bar"))
513 dijit
.byId("loading_bar").update({progress
: loading_progress
});
515 if (loading_progress
>= 90)
520 function remove_splash() {
522 if (Element
.visible("overlay")) {
523 console
.log("about to remove splash, OMG!");
524 Element
.hide("overlay");
525 console
.log("removed splash!");
529 function strip_tags(s
) {
530 return s
.replace(/<\/?[^>]+(>|$)/g, "");
533 function truncate_string(s
, length
) {
534 if (!length
) length
= 30;
535 var tmp
= s
.substring(0, length
);
536 if (s
.length
> length
) tmp
+= "…";
540 function hotkey_prefix_timeout() {
542 var date
= new Date();
543 var ts
= Math
.round(date
.getTime() / 1000);
545 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
546 console
.log("hotkey_prefix seems to be stuck, aborting");
547 hotkey_prefix_pressed
= false;
548 hotkey_prefix
= false;
549 Element
.hide('cmdline');
552 setTimeout(hotkey_prefix_timeout
, 1000);
556 function uploadIconHandler(rc
) {
559 notify_info("Upload complete.");
560 if (inPreferences()) {
563 setTimeout('updateFeedList(false, false)', 50);
567 notify_error("Upload failed: icon is too big.");
570 notify_error("Upload failed.");
575 function removeFeedIcon(id
) {
576 if (confirm(__("Remove stored feed icon?"))) {
577 var query
= "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id
);
581 notify_progress("Removing feed icon...", true);
583 new Ajax
.Request("backend.php", {
585 onComplete: function(transport
) {
586 notify_info("Feed icon removed.");
587 if (inPreferences()) {
590 setTimeout('updateFeedList(false, false)', 50);
598 function uploadFeedIcon() {
599 var file
= $("icon_file");
601 if (file
.value
.length
== 0) {
602 alert(__("Please select an image file to upload."));
604 if (confirm(__("Upload new icon for this feed?"))) {
605 notify_progress("Uploading, please wait...", true);
613 function addLabel(select
, callback
) {
615 var caption
= prompt(__("Please enter label caption:"), "");
617 if (caption
!= undefined) {
620 alert(__("Can't create label: missing caption."));
624 var query
= "?op=pref-labels&method=add&caption=" +
625 param_escape(caption
);
628 query
+= "&output=select";
630 notify_progress("Loading, please wait...", true);
632 if (inPreferences() && !select
) active_tab
= "labelConfig";
634 new Ajax
.Request("backend.php", {
636 onComplete: function(transport
) {
639 } else if (inPreferences()) {
650 function quickAddFeed() {
651 var query
= "backend.php?op=feeds&method=quickAddFeed";
653 // overlapping widgets
654 if (dijit
.byId("batchSubDlg")) dijit
.byId("batchSubDlg").destroyRecursive();
655 if (dijit
.byId("feedAddDlg")) dijit
.byId("feedAddDlg").destroyRecursive();
657 var dialog
= new dijit
.Dialog({
659 title
: __("Subscribe to Feed"),
660 style
: "width: 600px",
661 show_error: function(msg
) {
662 var elem
= $("fadd_error_message");
664 elem
.innerHTML
= msg
;
666 if (!Element
.visible(elem
))
667 new Effect
.Appear(elem
);
670 execute: function() {
671 if (this.validate()) {
672 console
.log(dojo
.objectToQuery(this.attr('value')));
674 var feed_url
= this.attr('value').feed
;
676 Element
.show("feed_add_spinner");
677 Element
.hide("fadd_error_message");
679 new Ajax
.Request("backend.php", {
680 parameters
: dojo
.objectToQuery(this.attr('value')),
681 onComplete: function(transport
) {
685 var reply
= JSON
.parse(transport
.responseText
);
687 Element
.hide("feed_add_spinner");
688 alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console."));
689 console
.log('quickAddFeed, backend returned:' + transport
.responseText
);
693 var rc
= reply
['result'];
696 Element
.hide("feed_add_spinner");
700 switch (parseInt(rc
['code'])) {
703 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
708 dialog
.show_error(__("Specified URL seems to be invalid."));
711 dialog
.show_error(__("Specified URL doesn't seem to contain any feeds."));
716 Element
.show("fadd_multiple_notify");
718 var select
= dijit
.byId("feedDlg_feedContainerSelect");
720 while (select
.getOptions().length
> 0)
721 select
.removeOption(0);
723 select
.addOption({value
: '', label
: __("Expand to select feed")});
726 for (var feedUrl
in feeds
) {
727 select
.addOption({value
: feedUrl
, label
: feeds
[feedUrl
]});
731 Effect
.Appear('feedDlg_feedsContainer', {duration
: 0.5});
735 dialog
.show_error(__("Couldn't download the specified URL: %s").
736 replace("%s", rc
['message']));
739 dialog
.show_error(__("XML validation failed: %s").
740 replace("%s", rc
['message']));
744 dialog
.show_error(__("You are already subscribed to this feed."));
749 console
.error(transport
.responseText
);
762 function createNewRuleElement(parentNode
, replaceNode
) {
763 var form
= document
.forms
["filter_new_rule_form"];
765 //form.reg_exp.value = form.reg_exp.value.replace(/(<([^>]+)>)/ig,"");
767 var query
= "backend.php?op=pref-filters&method=printrulename&rule="+
768 param_escape(dojo
.formToJson(form
));
772 new Ajax
.Request("backend.php", {
774 onComplete: function (transport
) {
776 var li
= dojo
.create("li");
778 var cb
= dojo
.create("input", { type
: "checkbox" }, li
);
780 new dijit
.form
.CheckBox({
781 onChange: function() {
782 toggleSelectListRow2(this) },
785 dojo
.create("input", { type
: "hidden",
787 value
: dojo
.formToJson(form
) }, li
);
789 dojo
.create("span", {
790 onclick: function() {
791 dijit
.byId('filterEditDlg').editRule(this);
793 innerHTML
: transport
.responseText
}, li
);
796 parentNode
.replaceChild(li
, replaceNode
);
798 parentNode
.appendChild(li
);
806 function createNewActionElement(parentNode
, replaceNode
) {
807 var form
= document
.forms
["filter_new_action_form"];
809 if (form
.action_id
.value
== 7) {
810 form
.action_param
.value
= form
.action_param_label
.value
;
811 } else if (form
.action_id
.value
== 9) {
812 form
.action_param
.value
= form
.action_param_plugin
.value
;
815 var query
= "backend.php?op=pref-filters&method=printactionname&action="+
816 param_escape(dojo
.formToJson(form
));
820 new Ajax
.Request("backend.php", {
822 onComplete: function (transport
) {
824 var li
= dojo
.create("li");
826 var cb
= dojo
.create("input", { type
: "checkbox" }, li
);
828 new dijit
.form
.CheckBox({
829 onChange: function() {
830 toggleSelectListRow2(this) },
833 dojo
.create("input", { type
: "hidden",
835 value
: dojo
.formToJson(form
) }, li
);
837 dojo
.create("span", {
838 onclick: function() {
839 dijit
.byId('filterEditDlg').editAction(this);
841 innerHTML
: transport
.responseText
}, li
);
844 parentNode
.replaceChild(li
, replaceNode
);
846 parentNode
.appendChild(li
);
856 function addFilterRule(replaceNode
, ruleStr
) {
857 if (dijit
.byId("filterNewRuleDlg"))
858 dijit
.byId("filterNewRuleDlg").destroyRecursive();
860 var query
= "backend.php?op=pref-filters&method=newrule&rule=" +
861 param_escape(ruleStr
);
863 var rule_dlg
= new dijit
.Dialog({
864 id
: "filterNewRuleDlg",
865 title
: ruleStr
? __("Edit rule") : __("Add rule"),
866 style
: "width: 600px",
867 execute: function() {
868 if (this.validate()) {
869 createNewRuleElement($("filterDlg_Matches"), replaceNode
);
878 function addFilterAction(replaceNode
, actionStr
) {
879 if (dijit
.byId("filterNewActionDlg"))
880 dijit
.byId("filterNewActionDlg").destroyRecursive();
882 var query
= "backend.php?op=pref-filters&method=newaction&action=" +
883 param_escape(actionStr
);
885 var rule_dlg
= new dijit
.Dialog({
886 id
: "filterNewActionDlg",
887 title
: actionStr
? __("Edit action") : __("Add action"),
888 style
: "width: 600px",
889 execute: function() {
890 if (this.validate()) {
891 createNewActionElement($("filterDlg_Actions"), replaceNode
);
900 function editFilterTest(query
) {
902 if (dijit
.byId("filterTestDlg"))
903 dijit
.byId("filterTestDlg").destroyRecursive();
905 var test_dlg
= new dijit
.Dialog({
907 title
: "Test Filter",
908 style
: "width: 600px",
912 getTestResults: function(query
, offset
) {
913 var updquery
= query
+ "&offset=" + offset
+ "&limit=" + test_dlg
.limit
;
915 console
.log("getTestResults:" + offset
);
917 new Ajax
.Request("backend.php", {
918 parameters
: updquery
,
919 onComplete: function (transport
) {
921 var result
= JSON
.parse(transport
.responseText
);
923 if (result
&& dijit
.byId("filterTestDlg") && dijit
.byId("filterTestDlg").open
) {
924 test_dlg
.results
+= result
.size();
926 console
.log("got results:" + result
.size());
928 $("prefFilterProgressMsg").innerHTML
= __("Looking for articles (%d processed, %f found)...")
929 .replace("%f", test_dlg
.results
)
930 .replace("%d", offset
);
932 console
.log(offset
+ " " + test_dlg
.max_offset
);
934 for (var i
= 0; i
< result
.size(); i
++) {
935 var tmp
= new Element("table");
936 tmp
.innerHTML
= result
[i
];
937 dojo
.parser
.parse(tmp
);
939 $("prefFilterTestResultList").innerHTML
+= tmp
.innerHTML
;
942 if (test_dlg
.results
< 30 && offset
< test_dlg
.max_offset
) {
944 // get the next batch
945 window
.setTimeout(function () {
946 test_dlg
.getTestResults(query
, offset
+ test_dlg
.limit
);
952 Element
.hide("prefFilterLoadingIndicator");
954 if (test_dlg
.results
== 0) {
955 $("prefFilterTestResultList").innerHTML
= "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
956 $("prefFilterProgressMsg").innerHTML
= "Articles matching this filter:";
958 $("prefFilterProgressMsg").innerHTML
= __("Found %d articles matching this filter:")
959 .replace("%d", test_dlg
.results
);
964 } else if (!result
) {
965 console
.log("getTestResults: can't parse results object");
967 Element
.hide("prefFilterLoadingIndicator");
969 notify_error("Error while trying to get filter test results.");
972 console
.log("getTestResults: dialog closed, bailing out.");
982 dojo
.connect(test_dlg
, "onLoad", null, function(e
) {
983 test_dlg
.getTestResults(query
, 0);
990 function quickAddFilter() {
992 if (!inPreferences()) {
993 query
= "backend.php?op=pref-filters&method=newfilter&feed=" +
994 param_escape(getActiveFeedId()) + "&is_cat=" +
995 param_escape(activeFeedIsCat());
997 query
= "backend.php?op=pref-filters&method=newfilter";
1002 if (dijit
.byId("feedEditDlg"))
1003 dijit
.byId("feedEditDlg").destroyRecursive();
1005 if (dijit
.byId("filterEditDlg"))
1006 dijit
.byId("filterEditDlg").destroyRecursive();
1008 dialog
= new dijit
.Dialog({
1009 id
: "filterEditDlg",
1010 title
: __("Create Filter"),
1011 style
: "width: 600px",
1013 var query
= "backend.php?" + dojo
.formToQuery("filter_new_form") + "&savemode=test";
1015 editFilterTest(query
);
1017 selectRules: function(select
) {
1018 $$("#filterDlg_Matches input[type=checkbox]").each(function(e
) {
1021 e
.parentNode
.addClassName("Selected");
1023 e
.parentNode
.removeClassName("Selected");
1026 selectActions: function(select
) {
1027 $$("#filterDlg_Actions input[type=checkbox]").each(function(e
) {
1031 e
.parentNode
.addClassName("Selected");
1033 e
.parentNode
.removeClassName("Selected");
1037 editRule: function(e
) {
1038 var li
= e
.parentNode
;
1039 var rule
= li
.getElementsByTagName("INPUT")[1].value
;
1040 addFilterRule(li
, rule
);
1042 editAction: function(e
) {
1043 var li
= e
.parentNode
;
1044 var action
= li
.getElementsByTagName("INPUT")[1].value
;
1045 addFilterAction(li
, action
);
1047 addAction: function() { addFilterAction(); },
1048 addRule: function() { addFilterRule(); },
1049 deleteAction: function() {
1050 $$("#filterDlg_Actions li.[class*=Selected]").each(function(e
) { e
.parentNode
.removeChild(e
) });
1052 deleteRule: function() {
1053 $$("#filterDlg_Matches li.[class*=Selected]").each(function(e
) { e
.parentNode
.removeChild(e
) });
1055 execute: function() {
1056 if (this.validate()) {
1058 var query
= dojo
.formToQuery("filter_new_form");
1062 new Ajax
.Request("backend.php", {
1064 onComplete: function (transport
) {
1065 if (inPreferences()) {
1075 if (!inPreferences()) {
1076 var selectedText
= getSelectionText();
1078 var lh
= dojo
.connect(dialog
, "onLoad", function(){
1079 dojo
.disconnect(lh
);
1081 if (selectedText
!= "") {
1083 var feed_id
= activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1086 var rule
= { reg_exp
: selectedText
, feed_id
: feed_id
, filter_type
: 1 };
1088 addFilterRule(null, dojo
.toJson(rule
));
1092 var query
= "op=rpc&method=getlinktitlebyid&id=" + getActiveArticleId();
1094 new Ajax
.Request("backend.php", {
1096 onComplete: function(transport
) {
1097 var reply
= JSON
.parse(transport
.responseText
);
1101 if (reply
&& reply
) title
= reply
.title
;
1103 if (title
|| getActiveFeedId() || activeFeedIsCat()) {
1105 console
.log(title
+ " " + getActiveFeedId());
1107 var feed_id
= activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) :
1110 var rule
= { reg_exp
: title
, feed_id
: feed_id
, filter_type
: 1 };
1112 addFilterRule(null, dojo
.toJson(rule
));
1126 function resetPubSub(feed_id
, title
) {
1128 var msg
= __("Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update.").replace("%s", title
);
1130 if (title
== undefined || confirm(msg
)) {
1131 notify_progress("Loading, please wait...");
1133 var query
= "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id
;
1135 new Ajax
.Request("backend.php", {
1137 onComplete: function(transport
) {
1138 dijit
.byId("pubsubReset_Btn").attr('disabled', true);
1139 notify_info("Subscription reset.");
1147 function unsubscribeFeed(feed_id
, title
) {
1149 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1151 if (title
== undefined || confirm(msg
)) {
1152 notify_progress("Removing feed...");
1154 var query
= "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id
;
1156 new Ajax
.Request("backend.php", {
1158 onComplete: function(transport
) {
1160 if (dijit
.byId("feedEditDlg")) dijit
.byId("feedEditDlg").hide();
1162 if (inPreferences()) {
1165 if (feed_id
== getActiveFeedId())
1166 setTimeout(function() { viewfeed({feed
:-5}) }, 100);
1168 if (feed_id
< 0) updateFeedList();
1178 function backend_sanity_check_callback(transport
) {
1180 if (sanity_check_done
) {
1181 fatalError(11, "Sanity check request received twice. This can indicate "+
1182 "presence of Firebug or some other disrupting extension. "+
1183 "Please disable it and try again.");
1187 var reply
= JSON
.parse(transport
.responseText
);
1190 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1194 var error_code
= reply
['error']['code'];
1196 if (error_code
&& error_code
!= 0) {
1197 return fatalError(error_code
, reply
['error']['message']);
1200 console
.log("sanity check ok");
1202 var params
= reply
['init-params'];
1205 console
.log('reading init-params...');
1208 console
.log("IP: " + k
+ " => " + JSON
.stringify(params
[k
]));
1209 if (k
== "label_base_index") _label_base_index
= parseInt(params
[k
]);
1212 init_params
= params
;
1214 // PluginHost might not be available on non-index pages
1215 window
.PluginHost
&& PluginHost
.run(PluginHost
.HOOK_PARAMS_LOADED
, init_params
);
1218 sanity_check_done
= true;
1220 init_second_stage();
1224 function quickAddCat(elem
) {
1225 var cat
= prompt(__("Please enter category title:"));
1229 var query
= "?op=rpc&method=quickAddCat&cat=" + param_escape(cat
);
1231 notify_progress("Loading, please wait...", true);
1233 new Ajax
.Request("backend.php", {
1235 onComplete: function (transport
) {
1236 var response
= transport
.responseXML
;
1237 var select
= response
.getElementsByTagName("select")[0];
1238 var options
= select
.getElementsByTagName("option");
1240 dropbox_replace_options(elem
, options
);
1249 function genUrlChangeKey(feed
, is_cat
) {
1250 var ok
= confirm(__("Generate new syndication address for this feed?"));
1254 notify_progress("Trying to change address...", true);
1256 var query
= "?op=pref-feeds&method=regenFeedKey&id=" + param_escape(feed
) +
1257 "&is_cat=" + param_escape(is_cat
);
1259 new Ajax
.Request("backend.php", {
1261 onComplete: function(transport
) {
1262 var reply
= JSON
.parse(transport
.responseText
);
1263 var new_link
= reply
.link
;
1265 var e
= $('gen_feed_url');
1269 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1270 "&key=" + new_link
);
1272 e
.href
= e
.href
.replace(/\&key=.*$/,
1273 "&key=" + new_link
);
1275 new Effect
.Highlight(e
);
1280 notify_error("Could not change feed URL.");
1287 function dropbox_replace_options(elem
, options
) {
1288 while (elem
.hasChildNodes())
1289 elem
.removeChild(elem
.firstChild
);
1293 for (var i
= 0; i
< options
.length
; i
++) {
1294 var text
= options
[i
].firstChild
.nodeValue
;
1295 var value
= options
[i
].getAttribute("value");
1297 if (value
== undefined) value
= text
;
1299 var issel
= options
[i
].getAttribute("selected") == "1";
1301 var option
= new Option(text
, value
, issel
);
1303 if (options
[i
].getAttribute("disabled"))
1304 option
.setAttribute("disabled", true);
1306 elem
.insert(option
);
1308 if (issel
) sel_idx
= i
;
1311 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1312 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1315 // mode = all, none, invert
1316 function selectTableRows(id
, mode
) {
1317 var rows
= $(id
).rows
;
1319 for (var i
= 0; i
< rows
.length
; i
++) {
1324 if (row
.id
&& row
.className
) {
1325 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1326 var inputs
= rows
[i
].getElementsByTagName("input");
1328 for (var j
= 0; j
< inputs
.length
; j
++) {
1329 var input
= inputs
[j
];
1331 if (input
.getAttribute("type") == "checkbox" &&
1332 input
.id
.match(bare_id
)) {
1335 dcb
= dijit
.getEnclosingWidget(cb
);
1341 var issel
= row
.hasClassName("Selected");
1343 if (mode
== "all" && !issel
) {
1344 row
.addClassName("Selected");
1346 if (dcb
) dcb
.set("checked", true);
1347 } else if (mode
== "none" && issel
) {
1348 row
.removeClassName("Selected");
1350 if (dcb
) dcb
.set("checked", false);
1352 } else if (mode
== "invert") {
1355 row
.removeClassName("Selected");
1357 if (dcb
) dcb
.set("checked", false);
1359 row
.addClassName("Selected");
1361 if (dcb
) dcb
.set("checked", true);
1370 function getSelectedTableRowIds(id
) {
1373 var elem_rows
= $(id
).rows
;
1375 for (var i
= 0; i
< elem_rows
.length
; i
++) {
1376 if (elem_rows
[i
].hasClassName("Selected")) {
1377 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1385 function editFeed(feed
, event
) {
1387 return alert(__("You can't edit this kind of feed."));
1389 var query
= "backend.php?op=pref-feeds&method=editfeed&id=" +
1394 if (dijit
.byId("filterEditDlg"))
1395 dijit
.byId("filterEditDlg").destroyRecursive();
1397 if (dijit
.byId("feedEditDlg"))
1398 dijit
.byId("feedEditDlg").destroyRecursive();
1400 dialog
= new dijit
.Dialog({
1402 title
: __("Edit Feed"),
1403 style
: "width: 600px",
1404 execute: function() {
1405 if (this.validate()) {
1406 // console.log(dojo.objectToQuery(this.attr('value')));
1408 notify_progress("Saving data...", true);
1410 new Ajax
.Request("backend.php", {
1411 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1412 onComplete: function(transport
) {
1424 function feedBrowser() {
1425 var query
= "backend.php?op=feeds&method=feedBrowser";
1427 if (dijit
.byId("feedAddDlg"))
1428 dijit
.byId("feedAddDlg").hide();
1430 if (dijit
.byId("feedBrowserDlg"))
1431 dijit
.byId("feedBrowserDlg").destroyRecursive();
1433 var dialog
= new dijit
.Dialog({
1434 id
: "feedBrowserDlg",
1435 title
: __("More Feeds"),
1436 style
: "width: 600px",
1437 getSelectedFeedIds: function () {
1438 var list
= $$("#browseFeedList li[id*=FBROW]");
1439 var selected
= new Array();
1441 list
.each(function (child
) {
1442 var id
= child
.id
.replace("FBROW-", "");
1444 if (child
.hasClassName('Selected')) {
1451 getSelectedFeeds: function () {
1452 var list
= $$("#browseFeedList li.Selected");
1453 var selected
= new Array();
1455 list
.each(function (child
) {
1456 var title
= child
.getElementsBySelector("span.fb_feedTitle")[0].innerHTML
;
1457 var url
= child
.getElementsBySelector("a.fb_feedUrl")[0].href
;
1459 selected
.push([title
, url
]);
1466 subscribe: function () {
1467 var mode
= this.attr('value').mode
;
1471 selected
= this.getSelectedFeeds();
1473 selected
= this.getSelectedFeedIds();
1475 if (selected
.length
> 0) {
1476 dijit
.byId("feedBrowserDlg").hide();
1478 notify_progress("Loading, please wait...", true);
1480 // we use dojo.toJson instead of JSON.stringify because
1481 // it somehow escapes everything TWICE, at least in Chrome 9
1483 var query
= "?op=rpc&method=massSubscribe&payload=" +
1484 param_escape(dojo
.toJson(selected
)) + "&mode=" + param_escape(mode
);
1488 new Ajax
.Request("backend.php", {
1490 onComplete: function (transport
) {
1497 alert(__("No feeds are selected."));
1501 update: function () {
1502 var query
= dojo
.objectToQuery(dialog
.attr('value'));
1504 Element
.show('feed_browser_spinner');
1506 new Ajax
.Request("backend.php", {
1508 onComplete: function (transport
) {
1511 Element
.hide('feed_browser_spinner');
1513 var c
= $("browseFeedList");
1515 var reply
= JSON
.parse(transport
.responseText
);
1517 var r
= reply
['content'];
1518 var mode
= reply
['mode'];
1524 dojo
.parser
.parse("browseFeedList");
1527 Element
.show(dijit
.byId('feed_archive_remove').domNode
);
1529 Element
.hide(dijit
.byId('feed_archive_remove').domNode
);
1535 removeFromArchive: function () {
1536 var selected
= this.getSelectedFeedIds();
1538 if (selected
.length
> 0) {
1540 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1543 Element
.show('feed_browser_spinner');
1545 var query
= "?op=rpc&method=remarchive&ids=" +
1546 param_escape(selected
.toString());
1549 new Ajax
.Request("backend.php", {
1551 onComplete: function (transport
) {
1558 execute: function () {
1559 if (this.validate()) {
1569 function showFeedsWithErrors() {
1570 var query
= "backend.php?op=pref-feeds&method=feedsWithErrors";
1572 if (dijit
.byId("errorFeedsDlg"))
1573 dijit
.byId("errorFeedsDlg").destroyRecursive();
1575 dialog
= new dijit
.Dialog({
1576 id
: "errorFeedsDlg",
1577 title
: __("Feeds with update errors"),
1578 style
: "width: 600px",
1579 getSelectedFeeds: function() {
1580 return getSelectedTableRowIds("prefErrorFeedList");
1582 removeSelected: function() {
1583 var sel_rows
= this.getSelectedFeeds();
1585 console
.log(sel_rows
);
1587 if (sel_rows
.length
> 0) {
1588 var ok
= confirm(__("Remove selected feeds?"));
1591 notify_progress("Removing selected feeds...", true);
1593 var query
= "?op=pref-feeds&method=remove&ids="+
1594 param_escape(sel_rows
.toString());
1596 new Ajax
.Request("backend.php", {
1598 onComplete: function(transport
) {
1606 alert(__("No feeds are selected."));
1609 execute: function() {
1610 if (this.validate()) {
1618 function get_timestamp() {
1619 var date
= new Date();
1620 return Math
.round(date
.getTime() / 1000);
1623 function helpDialog(topic
) {
1624 var query
= "backend.php?op=backend&method=help&topic=" + param_escape(topic
);
1626 if (dijit
.byId("helpDlg"))
1627 dijit
.byId("helpDlg").destroyRecursive();
1629 dialog
= new dijit
.Dialog({
1632 style
: "width: 600px",
1639 function htmlspecialchars_decode (string
, quote_style
) {
1640 // http://kevin.vanzonneveld.net
1641 // + original by: Mirek Slugen
1642 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1643 // + bugfixed by: Mateusz "loonquawl" Zalega
1644 // + input by: ReverseSyntax
1645 // + input by: Slawomir Kaniecki
1646 // + input by: Scott Cariss
1647 // + input by: Francois
1648 // + bugfixed by: Onno Marsman
1649 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1650 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1651 // + input by: Ratheous
1652 // + input by: Mailfaker (http://www.weedem.fr/)
1653 // + reimplemented by: Brett Zamir (http://brett-zamir.me)
1654 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
1655 // * example 1: htmlspecialchars_decode("<p>this -> "</p>", 'ENT_NOQUOTES');
1656 // * returns 1: '<p>this -> "</p>'
1657 // * example 2: htmlspecialchars_decode("&quot;");
1658 // * returns 2: '"'
1662 if (typeof quote_style
=== 'undefined') {
1665 string
= string
.toString().replace(/</g, '<').replace(/>/g, '>');
1668 'ENT_HTML_QUOTE_SINGLE': 1,
1669 'ENT_HTML_QUOTE_DOUBLE': 2,
1674 if (quote_style
=== 0) {
1677 if (typeof quote_style
!== 'number') { // Allow for a single string or an array of string flags
1678 quote_style
= [].concat(quote_style
);
1679 for (i
= 0; i
< quote_style
.length
; i
++) {
1680 // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
1681 if (OPTS
[quote_style
[i
]] === 0) {
1683 } else if (OPTS
[quote_style
[i
]]) {
1684 optTemp
= optTemp
| OPTS
[quote_style
[i
]];
1687 quote_style
= optTemp
;
1689 if (quote_style
& OPTS
.ENT_HTML_QUOTE_SINGLE
) {
1690 string
= string
.replace(/�*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
1691 // string = string.replace(/'|�*27;/g, "'"); // This would also be useful here, but not a part of PHP
1694 string
= string
.replace(/"/g, '"');
1696 // Put this in last place to avoid escape being double-decoded
1697 string
= string
.replace(/&/g, '&');
1703 function label_to_feed_id(label
) {
1704 return _label_base_index
- 1 - Math
.abs(label
);
1707 function feed_to_label_id(feed
) {
1708 return _label_base_index
- 1 + Math
.abs(feed
);
1711 // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac
1713 function getSelectionText() {
1716 if (typeof window
.getSelection
!= "undefined") {
1717 var sel
= window
.getSelection();
1718 if (sel
.rangeCount
) {
1719 var container
= document
.createElement("div");
1720 for (var i
= 0, len
= sel
.rangeCount
; i
< len
; ++i
) {
1721 container
.appendChild(sel
.getRangeAt(i
).cloneContents());
1723 text
= container
.innerHTML
;
1725 } else if (typeof document
.selection
!= "undefined") {
1726 if (document
.selection
.type
== "Text") {
1727 text
= document
.selection
.createRange().textText
;
1731 return text
.stripTags();
1734 function openUrlPopup(url
) {
1735 var w
= window
.open("");
1740 function openArticlePopup(id
) {
1741 var w
= window
.open("",
1742 "ttrss_article_popup",
1743 "height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no");
1746 w
.location
= "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id
+ "&csrf_token=" + getInitParam("csrf_token");