]>
git.wh0rd.org - tt-rss.git/blob - js/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&method=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&method=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&method=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(method
) {
170 if (getActiveFeedId() != undefined) {
171 viewfeed(getActiveFeedId(), method
, 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&method=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&method=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", "../../js/");
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", method
: "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 new Ajax
.Request("backend.php", {
432 parameters
: "?op=backend&method=help&topic=main",
433 onComplete: function(transport
) {
434 $("hotkey_help_overlay").innerHTML
= transport
.responseText
;
435 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
440 exception_error("quickMenuGo", e
);
444 function toggleDispRead() {
447 var hide
= !(getInitParam("hide_read_feeds") == "1");
449 hideOrShowFeeds(hide
);
451 var query
= "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" +
454 setInitParam("hide_read_feeds", hide
);
456 new Ajax
.Request("backend.php", {
458 onComplete: function(transport
) {
462 exception_error("toggleDispRead", e
);
466 function parse_runtime_info(data
) {
468 //console.log("parsing runtime info...");
473 // console.log("RI: " + k + " => " + v);
475 if (k
== "new_version_available") {
476 var icon
= $("newVersionIcon");
479 icon
.style
.display
= "inline";
481 icon
.style
.display
= "none";
487 if (k
== "daemon_is_running" && v
!= 1) {
488 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
492 if (k
== "daemon_stamp_ok" && v
!= 1) {
493 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
497 if (k
== "max_feed_id" || k
== "num_feeds") {
498 if (init_params
[k
] != v
) {
499 console
.log("feed count changed, need to reload feedlist.");
509 function catchupCurrentFeed() {
511 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
513 var str
= __("Mark all articles in %s as read?").replace("%s", fn
);
515 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
516 return viewCurrentFeed('MarkAllRead');
520 function catchupFeedInGroup(id
) {
524 var title
= getFeedName(id
);
526 var str
= __("Mark all articles in %s as read?").replace("%s", title
);
528 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
529 return viewCurrentFeed('MarkAllReadGR:' + id
);
533 exception_error("catchupFeedInGroup", e
);
537 function collapse_feedlist() {
540 if (!Element
.visible('feeds-holder')) {
541 Element
.show('feeds-holder');
542 Element
.show('feeds-holder_splitter');
543 $("collapse_feeds_btn").innerHTML
= "<<";
545 Element
.hide('feeds-holder');
546 Element
.hide('feeds-holder_splitter');
547 $("collapse_feeds_btn").innerHTML
= ">>";
550 dijit
.byId("main").resize();
552 query
= "?op=rpc&method=setpref&key=_COLLAPSED_FEEDLIST&value=true";
553 new Ajax
.Request("backend.php", { parameters
: query
});
556 exception_error("collapse_feedlist", e
);
560 function viewModeChanged() {
561 return viewCurrentFeed('');
564 function viewLimitChanged() {
565 return viewCurrentFeed('');
568 /* function adjustArticleScore(id, score) {
571 var pr = prompt(__("Assign score to article:"), score);
573 if (pr != undefined) {
574 var query = "?op=rpc&method=setScore&id=" + id + "&score=" + pr;
576 new Ajax.Request("backend.php", {
578 onComplete: function(transport) {
584 exception_error("adjustArticleScore", e);
588 function rescoreCurrentFeed() {
590 var actid
= getActiveFeedId();
592 if (activeFeedIsCat() || actid
< 0) {
593 alert(__("You can't rescore this kind of feed."));
598 alert(__("Please select some feed first."));
602 var fn
= getFeedName(actid
);
603 var pr
= __("Rescore articles in %s?").replace("%s", fn
);
606 notify_progress("Rescoring articles...");
608 var query
= "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid
;
610 new Ajax
.Request("backend.php", {
612 onComplete: function(transport
) {
618 function hotkey_handler(e
) {
621 if (e
.target
.nodeName
== "INPUT" || e
.target
.nodeName
== "TEXTAREA") return;
624 var shift_key
= false;
626 var cmdline
= $('cmdline');
629 shift_key
= e
.shiftKey
;
635 keycode
= window
.event
.keyCode
;
640 var keychar
= String
.fromCharCode(keycode
);
642 if (keycode
== 27) { // escape
643 if (Element
.visible("hotkey_help_overlay")) {
644 Element
.hide("hotkey_help_overlay");
646 hotkey_prefix
= false;
649 if (keycode
== 16) return; // ignore lone shift
650 if (keycode
== 17) return; // ignore lone ctrl
652 if ((keycode
== 70 || keycode
== 67 || keycode
== 71 || keycode
== 65)
655 var date
= new Date();
656 var ts
= Math
.round(date
.getTime() / 1000);
658 hotkey_prefix
= keycode
;
659 hotkey_prefix_pressed
= ts
;
661 cmdline
.innerHTML
= keychar
;
662 Element
.show(cmdline
);
664 console
.log("KP: PREFIX=" + keycode
+ " CHAR=" + keychar
+ " TS=" + ts
);
668 if (Element
.visible("hotkey_help_overlay")) {
669 Element
.hide("hotkey_help_overlay");
674 Element
.hide(cmdline
);
676 if (!hotkey_prefix
) {
678 if (keycode
== 27) { // escape
683 if (keycode
== 69) { // e
684 var id
= getActiveArticleId();
688 if ((keycode
== 191 || keychar
== '?') && shift_key
) { // ?
689 if (!Element
.visible("hotkey_help_overlay")) {
690 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3, to
: 0.9});
692 Element
.hide("hotkey_help_overlay");
697 if (keycode
== 191 || keychar
== '/') { // /
702 if (keycode
== 74 && !shift_key
) { // j
703 var rv
= dijit
.byId("feedTree").getPreviousFeed(
704 getActiveFeedId(), activeFeedIsCat());
706 if (rv
) viewfeed(rv
[0], '', rv
[1]);
711 if (keycode
== 75) { // k
712 var rv
= dijit
.byId("feedTree").getNextFeed(
713 getActiveFeedId(), activeFeedIsCat());
715 if (rv
) viewfeed(rv
[0], '', rv
[1]);
720 if (shift_key
&& keycode
== 40) { // shift-down
721 catchupRelativeToArticle(1);
725 if (shift_key
&& keycode
== 38) { // shift-up
726 catchupRelativeToArticle(0);
730 if (shift_key
&& keycode
== 78) { // N
735 if (shift_key
&& keycode
== 80) { // P
740 if (keycode
== 68 && shift_key
) { // shift-D
741 dismissSelectedArticles();
745 if (keycode
== 88 && shift_key
) { // shift-X
746 dismissReadArticles();
750 if (keycode
== 78 || keycode
== 40) { // n, down
751 if (typeof moveToPost
!= 'undefined') {
757 if (keycode
== 80 || keycode
== 38) { // p, up
758 if (typeof moveToPost
!= 'undefined') {
764 if (keycode
== 83 && shift_key
) { // S
765 selectionTogglePublished(undefined, false, true);
769 if (keycode
== 83) { // s
770 selectionToggleMarked(undefined, false, true);
774 if (keycode
== 85) { // u
775 selectionToggleUnread(undefined, false, true);
779 if (keycode
== 84 && shift_key
) { // T
780 var id
= getActiveArticleId();
782 editArticleTags(id
, getActiveFeedId(), isCdmMode());
787 if (keycode
== 9) { // tab
788 var id
= getArticleUnderPointer();
790 var cb
= $("RCHK-" + id
);
793 cb
.checked
= !cb
.checked
;
794 toggleSelectRowById(cb
, "RROW-" + id
);
800 if (keycode
== 79) { // o
801 if (getActiveArticleId()) {
802 openArticleInNewWindow(getActiveArticleId());
807 if (keycode
== 81 && shift_key
) { // Q
808 if (typeof catchupAllFeeds
!= 'undefined') {
814 if (keycode
== 88 && !shift_key
) { // x
815 if (activeFeedIsCat()) {
816 dijit
.byId("feedTree").collapseCat(getActiveFeedId());
824 if (hotkey_prefix
== 65) { // a
825 hotkey_prefix
= false;
827 if (keycode
== 65) { // a
828 selectArticles('all');
832 if (keycode
== 85) { // u
833 selectArticles('unread');
837 if (keycode
== 73) { // i
838 selectArticles('invert');
842 if (keycode
== 78) { // n
843 selectArticles('none');
851 if (hotkey_prefix
== 70) { // f
853 hotkey_prefix
= false;
855 if (keycode
== 81) { // q
856 if (getActiveFeedId()) {
857 catchupCurrentFeed();
862 if (keycode
== 82) { // r
863 if (getActiveFeedId()) {
864 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
869 if (keycode
== 65) { // a
874 if (keycode
== 85) { // u
875 if (getActiveFeedId()) {
876 viewfeed(getActiveFeedId(), '');
881 if (keycode
== 69) { // e
883 if (activeFeedIsCat())
884 alert(__("You can't edit this kind of feed."));
886 editFeed(getActiveFeedId());
892 if (keycode
== 83) { // s
897 if (keycode
== 67 && shift_key
) { // C
898 if (typeof catchupAllFeeds
!= 'undefined') {
904 if (keycode
== 67) { // c
905 if (getActiveFeedId()) {
906 catchupCurrentFeed();
911 if (keycode
== 88) { // x
912 reverseHeadlineOrder();
919 if (hotkey_prefix
== 67) { // c
920 hotkey_prefix
= false;
922 if (keycode
== 70) { // f
927 if (keycode
== 76) { // l
932 if (keycode
== 83) { // s
933 if (typeof collapse_feedlist
!= 'undefined') {
939 if (keycode
== 77) { // m
940 // TODO: sortable feedlist
944 if (keycode
== 78) { // n
945 catchupRelativeToArticle(1);
949 if (keycode
== 80) { // p
950 catchupRelativeToArticle(0);
959 if (hotkey_prefix
== 71) { // g
961 hotkey_prefix
= false;
964 if (keycode
== 65) { // a
969 if (keycode
== 83) { // s
974 if (keycode
== 80 && shift_key
) { // P
979 if (keycode
== 80) { // p
984 if (keycode
== 70) { // f
989 if (keycode
== 84) { // t
990 displayDlg("printTagCloud");
997 if (hotkey_prefix
== 224 || hotkey_prefix
== 91) { // f
998 hotkey_prefix
= false;
1002 if (hotkey_prefix
) {
1003 console
.log("KP: PREFIX=" + hotkey_prefix
+ " CODE=" + keycode
+ " CHAR=" + keychar
);
1005 console
.log("KP: CODE=" + keycode
+ " CHAR=" + keychar
);
1010 exception_error("hotkey_handler", e
);
1014 function inPreferences() {
1018 function reverseHeadlineOrder() {
1021 var query_str
= "?op=rpc&method=togglepref&key=REVERSE_HEADLINES";
1023 new Ajax
.Request("backend.php", {
1024 parameters
: query_str
,
1025 onComplete: function(transport
) {
1030 exception_error("reverseHeadlineOrder", e
);
1034 function scheduleFeedUpdate(id
, is_cat
) {
1037 id
= getActiveFeedId();
1038 is_cat
= activeFeedIsCat();
1042 alert(__("Please select some feed first."));
1046 var query
= "?op=rpc&method=scheduleFeedUpdate&id=" +
1048 "&is_cat=" + param_escape(is_cat
);
1052 new Ajax
.Request("backend.php", {
1054 onComplete: function(transport
) {
1055 handle_rpc_json(transport
);
1057 var reply
= JSON
.parse(transport
.responseText
);
1058 var message
= reply
['message'];
1061 notify_info(message
);
1069 exception_error("scheduleFeedUpdate", e
);
1073 function newVersionDlg() {
1075 var query
= "backend.php?op=dlg&method=newVersion";
1077 if (dijit
.byId("newVersionDlg"))
1078 dijit
.byId("newVersionDlg").destroyRecursive();
1080 dialog
= new dijit
.Dialog({
1081 id
: "newVersionDlg",
1082 title
: __("New version available!"),
1083 style
: "width: 600px",
1090 exception_error("newVersionDlg", e
);
1094 function handle_rpc_json(transport
, scheduled_call
) {
1096 var reply
= JSON
.parse(transport
.responseText
);
1100 var error
= reply
['error'];
1103 var code
= error
['code'];
1104 var msg
= error
['msg'];
1106 console
.warn("[handle_rpc_json] received fatal error " + code
+ "/" + msg
);
1109 fatalError(code
, msg
);
1114 var seq
= reply
['seq'];
1117 if (get_seq() != seq
) {
1118 console
.log("[handle_rpc_json] sequence mismatch: " + seq
+
1119 " (want: " + get_seq() + ")");
1124 var message
= reply
['message'];
1127 if (message
== "UPDATE_COUNTERS") {
1128 console
.log("need to refresh counters...");
1129 setInitParam("last_article_id", -1);
1130 _force_scheduled_update
= true;
1134 var counters
= reply
['counters'];
1137 parse_counters(counters
, scheduled_call
);
1139 var runtime_info
= reply
['runtime-info'];;
1142 parse_runtime_info(runtime_info
);
1144 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1147 notify_error("Error communicating with server.");
1151 notify_error("Error communicating with server.");
1153 //exception_error("handle_rpc_json", e, transport);