]>
git.wh0rd.org - tt-rss.git/blob - tt-rss.js
2 var global_unread
= -1;
3 var firsttime_update
= true;
4 var _active_feed_id
= 0;
5 var _active_feed_is_cat
= false;
6 var number_of_feeds
= 0;
7 var hotkey_prefix
= false;
8 var hotkey_prefix_pressed
= false;
10 var _force_scheduled_update
= false;
11 var last_scheduled_update
= false;
24 function activeFeedIsCat() {
25 return _active_feed_is_cat
;
28 function getActiveFeedId() {
30 //console.log("gAFID: " + _active_feed_id);
31 return _active_feed_id
;
33 exception_error("getActiveFeedId", e
);
37 function setActiveFeedId(id
, is_cat
) {
41 if (is_cat
!= undefined) {
42 _active_feed_is_cat
= is_cat
;
45 selectFeed(id
, is_cat
);
48 exception_error("setActiveFeedId", e
);
53 function dlg_frefresh_callback(transport
, deleted_feed
) {
54 if (getActiveFeedId() == deleted_feed
) {
55 setTimeout("viewfeed(-5)", 100);
58 setTimeout('updateFeedList()', 50);
62 function updateFeedList() {
65 // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
66 // __("Loading, please wait...") + "</div>";
68 Element
.show("feedlistLoading");
70 if (dijit
.byId("feedTree")) {
71 dijit
.byId("feedTree").destroyRecursive();
74 var store
= new dojo
.data
.ItemFileWriteStore({
75 url
: "backend.php?op=feeds"});
77 var treeModel
= new fox
.FeedStoreModel({
84 childrenAttrs
: ["items"]
87 var tree
= new fox
.FeedTree({
89 onOpen: function (item
, node
) {
90 var id
= String(item
.id
);
91 var cat_id
= id
.substr(id
.indexOf(":")+1);
93 new Ajax
.Request("backend.php",
94 { parameters
: "backend.php?op=feeds&subop=collapse&cid=" +
95 param_escape(cat_id
) + "&mode=1" } );
97 onClose: function (item
, node
) {
98 var id
= String(item
.id
);
99 var cat_id
= id
.substr(id
.indexOf(":")+1);
101 new Ajax
.Request("backend.php",
102 { parameters
: "backend.php?op=feeds&subop=collapse&cid=" +
103 param_escape(cat_id
) + "&mode=0" } );
106 onClick: function (item
, node
) {
107 var id
= String(item
.id
);
108 var is_cat
= id
.match("^CAT:");
109 var feed
= id
.substr(id
.indexOf(":")+1);
110 viewfeed(feed
, '', is_cat
);
118 $("feeds-holder").appendChild(tree
.domNode
);
120 var tmph
= dojo
.connect(tree
, 'onLoad', function() {
121 dojo
.disconnect(tmph
);
122 Element
.hide("feedlistLoading");
123 loading_set_progress(25);
129 exception_error("updateFeedList", e
);
133 function catchupAllFeeds() {
135 var str
= __("Mark all articles as read?");
137 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
139 var query_str
= "backend.php?op=feeds&subop=catchupAll";
141 notify_progress("Marking all feeds as read...");
143 //console.log("catchupAllFeeds Q=" + query_str);
145 new Ajax
.Request("backend.php", {
146 parameters
: query_str
,
147 onComplete: function(transport
) {
148 feedlist_callback2(transport
);
156 function viewCurrentFeed(subop
) {
158 if (getActiveFeedId() != undefined) {
159 viewfeed(getActiveFeedId(), subop
, activeFeedIsCat());
161 return false; // block unneeded form submits
165 if (getInitParam("bw_limit") == "1") return;
168 var date
= new Date();
169 var ts
= Math
.round(date
.getTime() / 1000);
171 if (ts
- last_scheduled_update
> 10 || _force_scheduled_update
) {
173 //console.log("timeout()");
175 window
.clearTimeout(counter_timeout_id
);
177 var query_str
= "?op=rpc&subop=getAllCounters&seq=" + next_seq();
181 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
182 firsttime_update
= false;
188 query_str
= query_str
+ "&omode=" + omode
;
190 if (!_force_scheduled_update
)
191 query_str
= query_str
+ "&last_article_id=" + getInitParam("last_article_id");
193 //console.log("[timeout]" + query_str);
195 new Ajax
.Request("backend.php", {
196 parameters
: query_str
,
197 onComplete: function(transport
) {
198 handle_rpc_reply(transport
, !_force_scheduled_update
);
199 _force_scheduled_update
= false;
202 last_scheduled_update
= ts
;
206 exception_error("timeout", e
);
209 setTimeout("timeout()", 3000);
217 function updateTitle() {
218 var tmp
= "Tiny Tiny RSS";
220 if (global_unread
> 0) {
221 tmp
= tmp
+ " (" + global_unread
+ ")";
225 if (global_unread
> 0) {
226 window
.fluid
.dockBadge
= global_unread
;
228 window
.fluid
.dockBadge
= "";
232 document
.title
= tmp
;
235 function genericSanityCheck() {
236 setCookie("ttrss_test", "TEST");
238 if (getCookie("ttrss_test") != "TEST") {
247 Form
.disable("main_toolbar_form");
249 dojo
.require("dijit.layout.BorderContainer");
250 dojo
.require("dijit.layout.TabContainer");
251 dojo
.require("dijit.layout.ContentPane");
252 dojo
.require("dijit.Dialog");
253 dojo
.require("dijit.form.Button");
254 dojo
.require("dojo.data.ItemFileWriteStore");
255 dojo
.require("dijit.Tree");
256 dojo
.require("dijit.form.Select");
257 dojo
.require("dijit.Toolbar");
258 dojo
.require("dijit.ProgressBar");
259 dojo
.require("dojo.parser");
261 dojo
.registerModulePath("fox", "../..");
263 dojo
.require("fox.FeedTree");
265 if (typeof themeBeforeLayout
== 'function') {
269 dojo
.addOnLoad(function() {
273 if (typeof themeAfterLayout
== 'function') {
279 if (!genericSanityCheck())
282 var params
= "&ua=" + param_escape(navigator
.userAgent
);
284 loading_set_progress(20);
286 new Ajax
.Request("backend.php", {
287 parameters
: "backend.php?op=rpc&subop=sanityCheck" + params
,
288 onComplete: function(transport
) {
289 backend_sanity_check_callback(transport
);
293 exception_error("init", e
);
297 function init_second_stage() {
301 delCookie("ttrss_test");
303 var toolbar
= document
.forms
["main_toolbar_form"];
305 dropboxSelect(toolbar
.view_mode
, getInitParam("default_view_mode"));
306 dropboxSelect(toolbar
.order_by
, getInitParam("default_view_order_by"));
308 feeds_sort_by_unread
= getInitParam("feeds_sort_by_unread") == 1;
310 loading_set_progress(30);
312 if (has_local_storage())
313 localStorage
.clear();
316 setTimeout("timeout()", 3000);
318 console
.log("second stage ok");
321 exception_error("init_second_stage", e
);
325 function quickMenuChange() {
326 var chooser
= $("quickMenuChooser");
327 var opid
= chooser
[chooser
.selectedIndex
].value
;
329 chooser
.selectedIndex
= 0;
333 function quickMenuGo(opid
) {
336 if (opid
== "qmcPrefs") {
340 if (opid
== "qmcTagCloud") {
341 displayDlg("printTagCloud");
344 if (opid
== "qmcSearch") {
345 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(),
347 document
.forms
['search_form'].query
.focus();
352 if (opid
== "qmcAddFeed") {
357 if (opid
== "qmcEditFeed") {
358 editFeedDlg(getActiveFeedId());
361 if (opid
== "qmcRemoveFeed") {
362 var actid
= getActiveFeedId();
364 if (activeFeedIsCat()) {
365 alert(__("You can't unsubscribe from the category."));
370 alert(__("Please select some feed first."));
374 var fn
= getFeedName(actid
);
376 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
379 unsubscribeFeed(actid
);
385 if (opid
== "qmcCatchupAll") {
390 if (opid
== "qmcShowOnlyUnread") {
395 if (opid
== "qmcAddFilter") {
396 displayDlg('quickAddFilter', '',
397 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
400 if (opid
== "qmcAddLabel") {
404 if (opid
== "qmcRescoreFeed") {
405 rescoreCurrentFeed();
408 if (opid
== "qmcHKhelp") {
409 //Element.show("hotkey_help_overlay");
410 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
414 exception_error("quickMenuGo", e
);
418 function toggleDispRead() {
421 var hide
= !(getInitParam("hide_read_feeds") == "1");
423 hideOrShowFeeds(hide
);
425 var query
= "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" +
428 setInitParam("hide_read_feeds", hide
);
430 new Ajax
.Request("backend.php", {
432 onComplete: function(transport
) {
436 exception_error("toggleDispRead", e
);
440 function parse_runtime_info(elem
) {
442 if (!elem
|| !elem
.firstChild
) {
443 console
.warn("parse_runtime_info: invalid node passed");
447 var data
= JSON
.parse(elem
.firstChild
.nodeValue
);
449 //console.log("parsing runtime info...");
454 // console.log("RI: " + k + " => " + v);
456 if (k
== "new_version_available") {
457 var icon
= $("newVersionIcon");
460 icon
.style
.display
= "inline";
462 icon
.style
.display
= "none";
470 if (k
== "daemon_is_running" && v
!= 1) {
471 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
475 if (k
== "daemon_stamp_ok" && v
!= 1) {
476 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
485 function catchupCurrentFeed() {
487 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
489 var str
= __("Mark all articles in %s as read?").replace("%s", fn
);
491 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
492 return viewCurrentFeed('MarkAllRead')
496 function catchupFeedInGroup(id
) {
500 var title
= getFeedName(id
);
502 var str
= __("Mark all articles in %s as read?").replace("%s", title
);
504 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
505 return viewCurrentFeed('MarkAllReadGR:' + id
)
509 exception_error("catchupFeedInGroup", e
);
513 function editFeedDlg(feed
) {
517 alert(__("Please select some feed first."));
521 if ((feed
<= 0) || activeFeedIsCat()) {
522 alert(__("You can't edit this kind of feed."));
529 query
= "?op=pref-feeds&subop=editfeed&id=" + param_escape(feed
);
531 query
= "?op=pref-labels&subop=edit&id=" + param_escape(-feed
-11);
536 notify_progress("Loading, please wait...", true);
538 new Ajax
.Request("backend.php", {
540 onComplete: function(transport
) {
541 infobox_callback2(transport
);
542 document
.forms
["edit_feed_form"].title
.focus();
546 exception_error("editFeedDlg", e
);
550 /* this functions duplicate those of prefs.js feed editor, with
551 some differences because there is no feedlist */
553 function feedEditCancel() {
558 function feedEditSave() {
562 // FIXME: add parameter validation
564 var query
= Form
.serialize("edit_feed_form");
566 notify_progress("Saving feed...");
568 new Ajax
.Request("backend.php", {
570 onComplete: function(transport
) {
571 dlg_frefresh_callback(transport
);
580 exception_error("feedEditSave (main)", e
);
584 function collapse_feedlist() {
587 if (!Element
.visible('feeds-holder')) {
588 Element
.show('feeds-holder');
589 $("collapse_feeds_btn").innerHTML
= "<<";
591 Element
.hide('feeds-holder');
592 $("collapse_feeds_btn").innerHTML
= ">>";
595 dijit
.byId("main").resize();
597 query
= "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
598 new Ajax
.Request("backend.php", { parameters
: query
});
601 exception_error("collapse_feedlist", e
);
605 function viewModeChanged() {
607 return viewCurrentFeed('')
610 function viewLimitChanged() {
612 return viewCurrentFeed('')
615 /* function adjustArticleScore(id, score) {
618 var pr = prompt(__("Assign score to article:"), score);
620 if (pr != undefined) {
621 var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
623 new Ajax.Request("backend.php", {
625 onComplete: function(transport) {
631 exception_error("adjustArticleScore", e);
635 function rescoreCurrentFeed() {
637 var actid
= getActiveFeedId();
639 if (activeFeedIsCat() || actid
< 0) {
640 alert(__("You can't rescore this kind of feed."));
645 alert(__("Please select some feed first."));
649 var fn
= getFeedName(actid
);
650 var pr
= __("Rescore articles in %s?").replace("%s", fn
);
653 notify_progress("Rescoring articles...");
655 var query
= "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid
;
657 new Ajax
.Request("backend.php", {
659 onComplete: function(transport
) {
665 function hotkey_handler(e
) {
670 var shift_key
= false;
672 var cmdline
= $('cmdline');
675 shift_key
= e
.shiftKey
;
681 keycode
= window
.event
.keyCode
;
686 var keychar
= String
.fromCharCode(keycode
);
688 if (keycode
== 27) { // escape
689 if (Element
.visible("hotkey_help_overlay")) {
690 Element
.hide("hotkey_help_overlay");
692 hotkey_prefix
= false;
696 var dialog
= dijit
.byId("infoBox");
697 var dialog_visible
= false;
700 dialog_visible
= Element
.visible(dialog
.domNode
);
702 if (dialog_visible
|| !hotkeys_enabled
) {
703 console
.log("hotkeys disabled");
707 if (keycode
== 16) return; // ignore lone shift
708 if (keycode
== 17) return; // ignore lone ctrl
710 if ((keycode
== 70 || keycode
== 67 || keycode
== 71)
713 var date
= new Date();
714 var ts
= Math
.round(date
.getTime() / 1000);
716 hotkey_prefix
= keycode
;
717 hotkey_prefix_pressed
= ts
;
719 cmdline
.innerHTML
= keychar
;
720 Element
.show(cmdline
);
722 console
.log("KP: PREFIX=" + keycode
+ " CHAR=" + keychar
+ " TS=" + ts
);
726 if (Element
.visible("hotkey_help_overlay")) {
727 Element
.hide("hotkey_help_overlay");
732 Element
.hide(cmdline
);
734 if (!hotkey_prefix
) {
736 if ((keycode
== 191 || keychar
== '?') && shift_key
) { // ?
737 if (!Element
.visible("hotkey_help_overlay")) {
738 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
740 Element
.hide("hotkey_help_overlay");
745 if (keycode
== 191 || keychar
== '/') { // /
746 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(),
748 document
.forms
['search_form'].query
.focus();
753 if (keycode
== 74) { // j
754 // TODO: move to previous feed
758 if (keycode
== 75) { // k
759 // TODO: move to next feed
763 if (shift_key
&& keycode
== 40) { // shift-down
764 catchupRelativeToArticle(1);
768 if (shift_key
&& keycode
== 38) { // shift-up
769 catchupRelativeToArticle(0);
773 if (shift_key
&& keycode
== 78) { // N
778 if (shift_key
&& keycode
== 80) { // P
783 if (keycode
== 68 && shift_key
) { // shift-D
784 dismissSelectedArticles();
787 if (keycode
== 88 && shift_key
) { // shift-X
788 dismissReadArticles();
791 if (keycode
== 78 || keycode
== 40) { // n, down
792 if (typeof moveToPost
!= 'undefined') {
798 if (keycode
== 80 || keycode
== 38) { // p, up
799 if (typeof moveToPost
!= 'undefined') {
805 if (keycode
== 83 && shift_key
) { // S
806 selectionTogglePublished(undefined, false, true);
810 if (keycode
== 83) { // s
811 selectionToggleMarked(undefined, false, true);
816 if (keycode
== 85) { // u
817 selectionToggleUnread(undefined, false, true)
821 if (keycode
== 84 && shift_key
) { // T
822 var id
= getActiveArticleId();
824 editArticleTags(id
, getActiveFeedId(), isCdmMode());
829 if (keycode
== 9) { // tab
830 var id
= getArticleUnderPointer();
832 var cb
= $("RCHK-" + id
);
835 cb
.checked
= !cb
.checked
;
836 toggleSelectRowById(cb
, "RROW-" + id
);
842 if (keycode
== 79) { // o
843 if (getActiveArticleId()) {
844 openArticleInNewWindow(getActiveArticleId());
849 if (keycode
== 81 && shift_key
) { // Q
850 if (typeof catchupAllFeeds
!= 'undefined') {
856 if (keycode
== 88) { // x
857 if (activeFeedIsCat()) {
858 toggleCollapseCat(getActiveFeedId());
865 if (hotkey_prefix
== 70) { // f
867 hotkey_prefix
= false;
869 if (keycode
== 81) { // q
870 if (getActiveFeedId()) {
871 catchupCurrentFeed();
876 if (keycode
== 82) { // r
877 if (getActiveFeedId()) {
878 viewfeed(getActiveFeedId(), "ForceUpdate", activeFeedIsCat());
883 if (keycode
== 65) { // a
888 if (keycode
== 85) { // u
889 if (getActiveFeedId()) {
890 viewfeed(getActiveFeedId(), "ForceUpdate");
895 if (keycode
== 69) { // e
896 editFeedDlg(getActiveFeedId());
900 if (keycode
== 83) { // s
905 if (keycode
== 67 && shift_key
) { // C
906 if (typeof catchupAllFeeds
!= 'undefined') {
912 if (keycode
== 67) { // c
913 if (getActiveFeedId()) {
914 catchupCurrentFeed();
919 if (keycode
== 87) { // w
920 feeds_sort_by_unread
= !feeds_sort_by_unread
;
921 return resort_feedlist();
924 if (keycode
== 88) { // x
925 reverseHeadlineOrder();
932 if (hotkey_prefix
== 67) { // c
933 hotkey_prefix
= false;
935 if (keycode
== 70) { // f
936 displayDlg('quickAddFilter', '',
937 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
941 if (keycode
== 76) { // l
946 if (keycode
== 83) { // s
947 if (typeof collapse_feedlist
!= 'undefined') {
953 if (keycode
== 77) { // m
954 // TODO: sortable feedlist
958 if (keycode
== 78) { // n
959 catchupRelativeToArticle(1);
963 if (keycode
== 80) { // p
964 catchupRelativeToArticle(0);
973 if (hotkey_prefix
== 71) { // g
975 hotkey_prefix
= false;
978 if (keycode
== 65) { // a
983 if (keycode
== 83) { // s
988 if (keycode
== 80 && shift_key
) { // P
993 if (keycode
== 80) { // p
998 if (keycode
== 70) { // f
1003 if (keycode
== 84 && shift_key
) { // T
1011 if (hotkey_prefix
== 224 || hotkey_prefix
== 91) { // f
1012 hotkey_prefix
= false;
1016 if (hotkey_prefix
) {
1017 console
.log("KP: PREFIX=" + hotkey_prefix
+ " CODE=" + keycode
+ " CHAR=" + keychar
);
1019 console
.log("KP: CODE=" + keycode
+ " CHAR=" + keychar
);
1024 exception_error("hotkey_handler", e
);
1028 function inPreferences() {
1032 function reverseHeadlineOrder() {
1035 var query_str
= "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1037 new Ajax
.Request("backend.php", {
1038 parameters
: query_str
,
1039 onComplete: function(transport
) {
1044 exception_error("reverseHeadlineOrder", e
);
1048 function showFeedsWithErrors() {
1049 displayDlg('feedUpdateErrors');
1052 function handle_rpc_reply(transport
, scheduled_call
) {
1054 if (transport
.responseXML
) {
1056 if (!transport_error_check(transport
)) return false;
1058 var seq
= transport
.responseXML
.getElementsByTagName("seq")[0];
1061 seq
= seq
.firstChild
.nodeValue
;
1063 if (get_seq() != seq
) {
1064 //console.log("[handle_rpc_reply] sequence mismatch: " + seq);
1069 var message
= transport
.responseXML
.getElementsByTagName("message")[0];
1072 message
= message
.firstChild
.nodeValue
;
1074 if (message
== "UPDATE_COUNTERS") {
1075 console
.log("need to refresh counters...");
1076 setInitParam("last_article_id", -1);
1077 _force_scheduled_update
= true;
1081 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
1084 parse_counters(counters
, scheduled_call
);
1086 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info")[0];
1089 parse_runtime_info(runtime_info
);
1091 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1094 notify_error("Error communicating with server.");
1098 exception_error("handle_rpc_reply", e
, transport
);
1104 function scheduleFeedUpdate() {
1107 if (!getActiveFeedId()) {
1108 alert(__("Please select some feed first."));
1112 var query
= "?op=rpc&subop=scheduleFeedUpdate&id=" +
1113 param_escape(getActiveFeedId()) +
1114 "&is_cat=" + param_escape(activeFeedIsCat());
1118 new Ajax
.Request("backend.php", {
1120 onComplete: function(transport
) {
1122 if (transport
.responseXML
) {
1123 var message
= transport
.responseXML
.getElementsByTagName("message")[0];
1126 notify_info(message
.firstChild
.nodeValue
);
1131 notify_error("Error communicating with server.");
1137 exception_error("scheduleFeedUpdate", e
);