]>
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 hotkey_prefix
= false;
7 var hotkey_prefix_pressed
= false;
9 var _force_scheduled_update
= false;
10 var last_scheduled_update
= false;
23 function activeFeedIsCat() {
24 return _active_feed_is_cat
;
27 function getActiveFeedId() {
29 //console.log("gAFID: " + _active_feed_id);
30 return _active_feed_id
;
32 exception_error("getActiveFeedId", e
);
36 function setActiveFeedId(id
, is_cat
) {
40 if (is_cat
!= undefined) {
41 _active_feed_is_cat
= is_cat
;
44 selectFeed(id
, is_cat
);
47 exception_error("setActiveFeedId", e
);
52 function updateFeedList() {
55 // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
56 // __("Loading, please wait...") + "</div>";
58 Element
.show("feedlistLoading");
60 if (dijit
.byId("feedTree")) {
61 dijit
.byId("feedTree").destroyRecursive();
64 var store
= new dojo
.data
.ItemFileWriteStore({
65 url
: "backend.php?op=feeds"});
67 var treeModel
= new fox
.FeedStoreModel({
74 childrenAttrs
: ["items"]
77 var tree
= new fox
.FeedTree({
80 onOpen: function (item
, node
) {
81 var id
= String(item
.id
);
82 var cat_id
= id
.substr(id
.indexOf(":")+1);
84 new Ajax
.Request("backend.php",
85 { parameters
: "backend.php?op=feeds&subop=collapse&cid=" +
86 param_escape(cat_id
) + "&mode=0" } );
88 onClose: function (item
, node
) {
89 var id
= String(item
.id
);
90 var cat_id
= id
.substr(id
.indexOf(":")+1);
92 new Ajax
.Request("backend.php",
93 { parameters
: "backend.php?op=feeds&subop=collapse&cid=" +
94 param_escape(cat_id
) + "&mode=1" } );
97 onClick: function (item
, node
) {
98 var id
= String(item
.id
);
99 var is_cat
= id
.match("^CAT:");
100 var feed
= id
.substr(id
.indexOf(":")+1);
101 viewfeed(feed
, '', is_cat
);
109 /* var menu = new dijit.Menu({id: 'feedMenu'});
111 menu.addChild(new dijit.MenuItem({
112 label: "Simple menu item"
115 // menu.bindDomNode(tree.domNode); */
117 var tmph
= dojo
.connect(dijit
.byId('feedMenu'), '_openMyself', function (event
) {
118 console
.log(dijit
.getEnclosingWidget(event
.target
));
119 dojo
.disconnect(tmph
);
122 $("feeds-holder").appendChild(tree
.domNode
);
124 var tmph
= dojo
.connect(tree
, 'onLoad', function() {
125 dojo
.disconnect(tmph
);
126 Element
.hide("feedlistLoading");
128 tree
.collapseHiddenCats();
132 // var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
133 // menu.bindDomNode(node);
135 loading_set_progress(25);
141 exception_error("updateFeedList", e
);
145 function catchupAllFeeds() {
147 var str
= __("Mark all articles as read?");
149 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
151 var query_str
= "backend.php?op=feeds&subop=catchupAll";
153 notify_progress("Marking all feeds as read...");
155 //console.log("catchupAllFeeds Q=" + query_str);
157 new Ajax
.Request("backend.php", {
158 parameters
: query_str
,
159 onComplete: function(transport
) {
160 feedlist_callback2(transport
);
168 function viewCurrentFeed(subop
) {
170 if (getActiveFeedId() != undefined) {
171 viewfeed(getActiveFeedId(), subop
, activeFeedIsCat());
173 return false; // block unneeded form submits
177 if (getInitParam("bw_limit") == "1") return;
180 var date
= new Date();
181 var ts
= Math
.round(date
.getTime() / 1000);
183 if (ts
- last_scheduled_update
> 10 || _force_scheduled_update
) {
185 //console.log("timeout()");
187 window
.clearTimeout(counter_timeout_id
);
189 var query_str
= "?op=rpc&subop=getAllCounters&seq=" + next_seq();
193 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
194 firsttime_update
= false;
200 query_str
= query_str
+ "&omode=" + omode
;
202 if (!_force_scheduled_update
)
203 query_str
= query_str
+ "&last_article_id=" + getInitParam("last_article_id");
205 //console.log("[timeout]" + query_str);
207 new Ajax
.Request("backend.php", {
208 parameters
: query_str
,
209 onComplete: function(transport
) {
210 handle_rpc_json(transport
, !_force_scheduled_update
);
211 _force_scheduled_update
= false;
214 last_scheduled_update
= ts
;
218 exception_error("timeout", e
);
221 setTimeout("timeout()", 3000);
225 var query
= "backend.php?op=dlg&id=search¶m=" +
226 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
228 if (dijit
.byId("searchDlg"))
229 dijit
.byId("searchDlg").destroyRecursive();
231 dialog
= new dijit
.Dialog({
234 style
: "width: 600px",
235 execute: function() {
236 if (this.validate()) {
237 _search_query
= dojo
.objectToQuery(this.attr('value'));
247 function updateTitle() {
248 var tmp
= "Tiny Tiny RSS";
250 if (global_unread
> 0) {
251 tmp
= tmp
+ " (" + global_unread
+ ")";
255 if (global_unread
> 0) {
256 window
.fluid
.dockBadge
= global_unread
;
258 window
.fluid
.dockBadge
= "";
262 document
.title
= tmp
;
265 function genericSanityCheck() {
266 setCookie("ttrss_test", "TEST");
268 if (getCookie("ttrss_test") != "TEST") {
269 return fatalError(2);
277 dojo
.registerModulePath("fox", "../..");
279 dojo
.require("fox.FeedTree");
281 if (typeof themeBeforeLayout
== 'function') {
287 dojo
.addOnLoad(function() {
291 if (typeof themeAfterLayout
== 'function') {
297 if (!genericSanityCheck())
300 loading_set_progress(20);
302 var hasAudio
= !!((myAudioTag
= document
.createElement('audio')).canPlayType
);
304 new Ajax
.Request("backend.php", {
305 parameters
: {op
: "rpc", subop
: "sanityCheck", hasAudio
: hasAudio
},
306 onComplete: function(transport
) {
307 backend_sanity_check_callback(transport
);
311 exception_error("init", e
);
315 function init_second_stage() {
319 delCookie("ttrss_test");
321 var toolbar
= document
.forms
["main_toolbar_form"];
323 dijit
.getEnclosingWidget(toolbar
.view_mode
).attr('value',
324 getInitParam("default_view_mode"));
326 dijit
.getEnclosingWidget(toolbar
.order_by
).attr('value',
327 getInitParam("default_view_order_by"));
329 feeds_sort_by_unread
= getInitParam("feeds_sort_by_unread") == 1;
331 loading_set_progress(30);
333 // can't use cache_clear() here because viewfeed might not have initialized yet
334 if ('sessionStorage' in window
&& window
['sessionStorage'] !== null)
335 sessionStorage
.clear();
337 console
.log("second stage ok");
340 exception_error("init_second_stage", e
);
344 function quickMenuGo(opid
) {
346 if (opid
== "qmcPrefs") {
350 if (opid
== "qmcTagCloud") {
351 displayDlg("printTagCloud");
354 if (opid
== "qmcTagSelect") {
355 displayDlg("printTagSelect");
358 if (opid
== "qmcSearch") {
363 if (opid
== "qmcAddFeed") {
368 if (opid
== "qmcDigest") {
369 window
.location
.href
= "digest.php";
373 if (opid
== "qmcEditFeed") {
374 if (activeFeedIsCat())
375 alert(__("You can't edit this kind of feed."));
377 editFeed(getActiveFeedId());
381 if (opid
== "qmcRemoveFeed") {
382 var actid
= getActiveFeedId();
384 if (activeFeedIsCat()) {
385 alert(__("You can't unsubscribe from the category."));
390 alert(__("Please select some feed first."));
394 var fn
= getFeedName(actid
);
396 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
399 unsubscribeFeed(actid
);
405 if (opid
== "qmcCatchupAll") {
410 if (opid
== "qmcShowOnlyUnread") {
415 if (opid
== "qmcAddFilter") {
420 if (opid
== "qmcAddLabel") {
425 if (opid
== "qmcRescoreFeed") {
426 rescoreCurrentFeed();
430 if (opid
== "qmcHKhelp") {
431 //Element.show("hotkey_help_overlay");
432 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
435 if (opid
== "qmcAbout") {
436 dialog
= new dijit
.Dialog({
437 title
: __("About..."),
438 style
: "width: 400px",
439 href
: "backend.php?op=dlg&id=about",
446 exception_error("quickMenuGo", e
);
450 function toggleDispRead() {
453 var hide
= !(getInitParam("hide_read_feeds") == "1");
455 hideOrShowFeeds(hide
);
457 var query
= "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" +
460 setInitParam("hide_read_feeds", hide
);
462 new Ajax
.Request("backend.php", {
464 onComplete: function(transport
) {
468 exception_error("toggleDispRead", e
);
472 function parse_runtime_info(data
) {
474 //console.log("parsing runtime info...");
479 // console.log("RI: " + k + " => " + v);
481 if (k
== "new_version_available") {
482 var icon
= $("newVersionIcon");
485 icon
.style
.display
= "inline";
487 icon
.style
.display
= "none";
495 if (k
== "daemon_is_running" && v
!= 1) {
496 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
500 if (k
== "daemon_stamp_ok" && v
!= 1) {
501 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
505 if (k
== "max_feed_id" || k
== "num_feeds") {
506 if (init_params
[k
] != v
) {
507 console
.log("feed count changed, need to reload feedlist.");
517 function catchupCurrentFeed() {
519 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
521 var str
= __("Mark all articles in %s as read?").replace("%s", fn
);
523 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
524 return viewCurrentFeed('MarkAllRead')
528 function catchupFeedInGroup(id
) {
532 var title
= getFeedName(id
);
534 var str
= __("Mark all articles in %s as read?").replace("%s", title
);
536 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
537 return viewCurrentFeed('MarkAllReadGR:' + id
)
541 exception_error("catchupFeedInGroup", e
);
545 function collapse_feedlist() {
548 if (!Element
.visible('feeds-holder')) {
549 Element
.show('feeds-holder');
550 Element
.show('feeds-holder_splitter');
551 $("collapse_feeds_btn").innerHTML
= "<<";
553 Element
.hide('feeds-holder');
554 Element
.hide('feeds-holder_splitter');
555 $("collapse_feeds_btn").innerHTML
= ">>";
558 dijit
.byId("main").resize();
560 query
= "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
561 new Ajax
.Request("backend.php", { parameters
: query
});
564 exception_error("collapse_feedlist", e
);
568 function viewModeChanged() {
569 return viewCurrentFeed('')
572 function viewLimitChanged() {
573 return viewCurrentFeed('')
576 /* function adjustArticleScore(id, score) {
579 var pr = prompt(__("Assign score to article:"), score);
581 if (pr != undefined) {
582 var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
584 new Ajax.Request("backend.php", {
586 onComplete: function(transport) {
592 exception_error("adjustArticleScore", e);
596 function rescoreCurrentFeed() {
598 var actid
= getActiveFeedId();
600 if (activeFeedIsCat() || actid
< 0) {
601 alert(__("You can't rescore this kind of feed."));
606 alert(__("Please select some feed first."));
610 var fn
= getFeedName(actid
);
611 var pr
= __("Rescore articles in %s?").replace("%s", fn
);
614 notify_progress("Rescoring articles...");
616 var query
= "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid
;
618 new Ajax
.Request("backend.php", {
620 onComplete: function(transport
) {
626 function hotkey_handler(e
) {
629 if (e
.target
.nodeName
== "INPUT" || e
.target
.nodeName
== "TEXTAREA") return;
632 var shift_key
= false;
634 var cmdline
= $('cmdline');
637 shift_key
= e
.shiftKey
;
643 keycode
= window
.event
.keyCode
;
648 var keychar
= String
.fromCharCode(keycode
);
650 if (keycode
== 27) { // escape
651 if (Element
.visible("hotkey_help_overlay")) {
652 Element
.hide("hotkey_help_overlay");
654 hotkey_prefix
= false;
657 if (keycode
== 16) return; // ignore lone shift
658 if (keycode
== 17) return; // ignore lone ctrl
660 if ((keycode
== 70 || keycode
== 67 || keycode
== 71 || keycode
== 65)
663 var date
= new Date();
664 var ts
= Math
.round(date
.getTime() / 1000);
666 hotkey_prefix
= keycode
;
667 hotkey_prefix_pressed
= ts
;
669 cmdline
.innerHTML
= keychar
;
670 Element
.show(cmdline
);
672 console
.log("KP: PREFIX=" + keycode
+ " CHAR=" + keychar
+ " TS=" + ts
);
676 if (Element
.visible("hotkey_help_overlay")) {
677 Element
.hide("hotkey_help_overlay");
682 Element
.hide(cmdline
);
684 if (!hotkey_prefix
) {
686 if (keycode
== 69) { // e
687 var id
= getActiveArticleId();
691 if ((keycode
== 191 || keychar
== '?') && shift_key
) { // ?
692 if (!Element
.visible("hotkey_help_overlay")) {
693 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
695 Element
.hide("hotkey_help_overlay");
700 if (keycode
== 191 || keychar
== '/') { // /
705 if (keycode
== 74 && !shift_key
) { // j
706 var rv
= dijit
.byId("feedTree").getPreviousFeed(
707 getActiveFeedId(), activeFeedIsCat());
709 if (rv
) viewfeed(rv
[0], '', rv
[1]);
714 if (keycode
== 75) { // k
715 var rv
= dijit
.byId("feedTree").getNextFeed(
716 getActiveFeedId(), activeFeedIsCat());
718 if (rv
) viewfeed(rv
[0], '', rv
[1]);
723 if (shift_key
&& keycode
== 40) { // shift-down
724 catchupRelativeToArticle(1);
728 if (shift_key
&& keycode
== 38) { // shift-up
729 catchupRelativeToArticle(0);
733 if (shift_key
&& keycode
== 78) { // N
738 if (shift_key
&& keycode
== 80) { // P
743 if (keycode
== 68 && shift_key
) { // shift-D
744 dismissSelectedArticles();
748 if (keycode
== 88 && shift_key
) { // shift-X
749 dismissReadArticles();
753 if (keycode
== 78 || keycode
== 40) { // n, down
754 if (typeof moveToPost
!= 'undefined') {
760 if (keycode
== 80 || keycode
== 38) { // p, up
761 if (typeof moveToPost
!= 'undefined') {
767 if (keycode
== 83 && shift_key
) { // S
768 selectionTogglePublished(undefined, false, true);
772 if (keycode
== 83) { // s
773 selectionToggleMarked(undefined, false, true);
777 if (keycode
== 85) { // u
778 selectionToggleUnread(undefined, false, true)
782 if (keycode
== 84 && shift_key
) { // T
783 var id
= getActiveArticleId();
785 editArticleTags(id
, getActiveFeedId(), isCdmMode());
790 if (keycode
== 9) { // tab
791 var id
= getArticleUnderPointer();
793 var cb
= $("RCHK-" + id
);
796 cb
.checked
= !cb
.checked
;
797 toggleSelectRowById(cb
, "RROW-" + id
);
803 if (keycode
== 79) { // o
804 if (getActiveArticleId()) {
805 openArticleInNewWindow(getActiveArticleId());
810 if (keycode
== 81 && shift_key
) { // Q
811 if (typeof catchupAllFeeds
!= 'undefined') {
817 if (keycode
== 88 && !shift_key
) { // x
818 if (activeFeedIsCat()) {
819 dijit
.byId("feedTree").collapseCat(getActiveFeedId());
827 if (hotkey_prefix
== 65) { // a
828 hotkey_prefix
= false;
830 if (keycode
== 65) { // a
831 selectArticles('all');
835 if (keycode
== 85) { // u
836 selectArticles('unread');
840 if (keycode
== 73) { // i
841 selectArticles('invert');
845 if (keycode
== 78) { // n
846 selectArticles('none');
854 if (hotkey_prefix
== 70) { // f
856 hotkey_prefix
= false;
858 if (keycode
== 81) { // q
859 if (getActiveFeedId()) {
860 catchupCurrentFeed();
865 if (keycode
== 82) { // r
866 if (getActiveFeedId()) {
867 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
872 if (keycode
== 65) { // a
877 if (keycode
== 85) { // u
878 if (getActiveFeedId()) {
879 viewfeed(getActiveFeedId(), '');
884 if (keycode
== 69) { // e
886 if (activeFeedIsCat())
887 alert(__("You can't edit this kind of feed."));
889 editFeed(getActiveFeedId());
895 if (keycode
== 83) { // s
900 if (keycode
== 67 && shift_key
) { // C
901 if (typeof catchupAllFeeds
!= 'undefined') {
907 if (keycode
== 67) { // c
908 if (getActiveFeedId()) {
909 catchupCurrentFeed();
914 if (keycode
== 87) { // w
915 feeds_sort_by_unread
= !feeds_sort_by_unread
;
916 return resort_feedlist();
919 if (keycode
== 88) { // x
920 reverseHeadlineOrder();
927 if (hotkey_prefix
== 67) { // c
928 hotkey_prefix
= false;
930 if (keycode
== 70) { // f
935 if (keycode
== 76) { // l
940 if (keycode
== 83) { // s
941 if (typeof collapse_feedlist
!= 'undefined') {
947 if (keycode
== 77) { // m
948 // TODO: sortable feedlist
952 if (keycode
== 78) { // n
953 catchupRelativeToArticle(1);
957 if (keycode
== 80) { // p
958 catchupRelativeToArticle(0);
967 if (hotkey_prefix
== 71) { // g
969 hotkey_prefix
= false;
972 if (keycode
== 65) { // a
977 if (keycode
== 83) { // s
982 if (keycode
== 80 && shift_key
) { // P
987 if (keycode
== 80) { // p
992 if (keycode
== 70) { // f
997 if (keycode
== 84) { // t
998 displayDlg("printTagCloud");
1005 if (hotkey_prefix
== 224 || hotkey_prefix
== 91) { // f
1006 hotkey_prefix
= false;
1010 if (hotkey_prefix
) {
1011 console
.log("KP: PREFIX=" + hotkey_prefix
+ " CODE=" + keycode
+ " CHAR=" + keychar
);
1013 console
.log("KP: CODE=" + keycode
+ " CHAR=" + keychar
);
1018 exception_error("hotkey_handler", e
);
1022 function inPreferences() {
1026 function reverseHeadlineOrder() {
1029 var query_str
= "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1031 new Ajax
.Request("backend.php", {
1032 parameters
: query_str
,
1033 onComplete: function(transport
) {
1038 exception_error("reverseHeadlineOrder", e
);
1042 function scheduleFeedUpdate(id
, is_cat
) {
1045 id
= getActiveFeedId();
1046 is_cat
= activeFeedIsCat();
1050 alert(__("Please select some feed first."));
1054 var query
= "?op=rpc&subop=scheduleFeedUpdate&id=" +
1056 "&is_cat=" + param_escape(is_cat
);
1060 new Ajax
.Request("backend.php", {
1062 onComplete: function(transport
) {
1063 handle_rpc_json(transport
);
1065 var reply
= JSON
.parse(transport
.responseText
);
1066 var message
= reply
['message'];
1069 notify_info(message
);
1077 exception_error("scheduleFeedUpdate", e
);
1081 function newVersionDlg() {
1083 var query
= "backend.php?op=dlg&id=newVersion";
1085 if (dijit
.byId("newVersionDlg"))
1086 dijit
.byId("newVersionDlg").destroyRecursive();
1088 dialog
= new dijit
.Dialog({
1089 id
: "newVersionDlg",
1090 title
: __("New version available!"),
1091 style
: "width: 600px",
1098 exception_error("newVersionDlg", e
);
1102 function handle_rpc_json(transport
, scheduled_call
) {
1104 var reply
= JSON
.parse(transport
.responseText
);
1108 var error
= reply
['error'];
1111 var code
= error
['code'];
1112 var msg
= error
['msg'];
1114 console
.warn("[handle_rpc_json] received fatal error " + code
+ "/" + msg
);
1117 fatalError(code
, msg
);
1122 var seq
= reply
['seq'];
1125 if (get_seq() != seq
) {
1126 console
.log("[handle_rpc_json] sequence mismatch: " + seq
+
1127 " (want: " + get_seq() + ")");
1132 var message
= reply
['message'];
1135 if (message
== "UPDATE_COUNTERS") {
1136 console
.log("need to refresh counters...");
1137 setInitParam("last_article_id", -1);
1138 _force_scheduled_update
= true;
1142 var counters
= reply
['counters'];
1145 parse_counters(counters
, scheduled_call
);
1147 var runtime_info
= reply
['runtime-info'];;
1150 parse_runtime_info(runtime_info
);
1152 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1155 notify_error("Error communicating with server.");
1159 notify_error("Error communicating with server.");
1161 //exception_error("handle_rpc_json", e, transport);