]>
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 //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&method=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&method=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";
493 if (k
== "daemon_is_running" && v
!= 1) {
494 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
498 if (k
== "daemon_stamp_ok" && v
!= 1) {
499 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
503 if (k
== "max_feed_id" || k
== "num_feeds") {
504 if (init_params
[k
] != v
) {
505 console
.log("feed count changed, need to reload feedlist.");
515 function catchupCurrentFeed() {
517 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
519 var str
= __("Mark all articles in %s as read?").replace("%s", fn
);
521 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
522 return viewCurrentFeed('MarkAllRead');
526 function catchupFeedInGroup(id
) {
530 var title
= getFeedName(id
);
532 var str
= __("Mark all articles in %s as read?").replace("%s", title
);
534 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
535 return viewCurrentFeed('MarkAllReadGR:' + id
);
539 exception_error("catchupFeedInGroup", e
);
543 function collapse_feedlist() {
546 if (!Element
.visible('feeds-holder')) {
547 Element
.show('feeds-holder');
548 Element
.show('feeds-holder_splitter');
549 $("collapse_feeds_btn").innerHTML
= "<<";
551 Element
.hide('feeds-holder');
552 Element
.hide('feeds-holder_splitter');
553 $("collapse_feeds_btn").innerHTML
= ">>";
556 dijit
.byId("main").resize();
558 query
= "?op=rpc&method=setpref&key=_COLLAPSED_FEEDLIST&value=true";
559 new Ajax
.Request("backend.php", { parameters
: query
});
562 exception_error("collapse_feedlist", e
);
566 function viewModeChanged() {
567 return viewCurrentFeed('');
570 function viewLimitChanged() {
571 return viewCurrentFeed('');
574 /* function adjustArticleScore(id, score) {
577 var pr = prompt(__("Assign score to article:"), score);
579 if (pr != undefined) {
580 var query = "?op=rpc&method=setScore&id=" + id + "&score=" + pr;
582 new Ajax.Request("backend.php", {
584 onComplete: function(transport) {
590 exception_error("adjustArticleScore", e);
594 function rescoreCurrentFeed() {
596 var actid
= getActiveFeedId();
598 if (activeFeedIsCat() || actid
< 0) {
599 alert(__("You can't rescore this kind of feed."));
604 alert(__("Please select some feed first."));
608 var fn
= getFeedName(actid
);
609 var pr
= __("Rescore articles in %s?").replace("%s", fn
);
612 notify_progress("Rescoring articles...");
614 var query
= "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid
;
616 new Ajax
.Request("backend.php", {
618 onComplete: function(transport
) {
624 function hotkey_handler(e
) {
627 if (e
.target
.nodeName
== "INPUT" || e
.target
.nodeName
== "TEXTAREA") return;
630 var shift_key
= false;
632 var cmdline
= $('cmdline');
635 shift_key
= e
.shiftKey
;
641 keycode
= window
.event
.keyCode
;
646 var keychar
= String
.fromCharCode(keycode
);
648 if (keycode
== 27) { // escape
649 if (Element
.visible("hotkey_help_overlay")) {
650 Element
.hide("hotkey_help_overlay");
652 hotkey_prefix
= false;
655 if (keycode
== 16) return; // ignore lone shift
656 if (keycode
== 17) return; // ignore lone ctrl
658 if ((keycode
== 70 || keycode
== 67 || keycode
== 71 || keycode
== 65)
661 var date
= new Date();
662 var ts
= Math
.round(date
.getTime() / 1000);
664 hotkey_prefix
= keycode
;
665 hotkey_prefix_pressed
= ts
;
667 cmdline
.innerHTML
= keychar
;
668 Element
.show(cmdline
);
670 console
.log("KP: PREFIX=" + keycode
+ " CHAR=" + keychar
+ " TS=" + ts
);
674 if (Element
.visible("hotkey_help_overlay")) {
675 Element
.hide("hotkey_help_overlay");
680 Element
.hide(cmdline
);
682 if (!hotkey_prefix
) {
684 if (keycode
== 27) { // escape
689 if (keycode
== 69) { // e
690 var id
= getActiveArticleId();
694 if ((keycode
== 191 || keychar
== '?') && shift_key
) { // ?
695 if (!Element
.visible("hotkey_help_overlay")) {
696 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3, to
: 0.9});
698 Element
.hide("hotkey_help_overlay");
703 if (keycode
== 191 || keychar
== '/') { // /
708 if (keycode
== 74 && !shift_key
) { // j
709 var rv
= dijit
.byId("feedTree").getPreviousFeed(
710 getActiveFeedId(), activeFeedIsCat());
712 if (rv
) viewfeed(rv
[0], '', rv
[1]);
717 if (keycode
== 75) { // k
718 var rv
= dijit
.byId("feedTree").getNextFeed(
719 getActiveFeedId(), activeFeedIsCat());
721 if (rv
) viewfeed(rv
[0], '', rv
[1]);
726 if (shift_key
&& keycode
== 40) { // shift-down
727 catchupRelativeToArticle(1);
731 if (shift_key
&& keycode
== 38) { // shift-up
732 catchupRelativeToArticle(0);
736 if (shift_key
&& keycode
== 78) { // N
741 if (shift_key
&& keycode
== 80) { // P
746 if (keycode
== 68 && shift_key
) { // shift-D
747 dismissSelectedArticles();
751 if (keycode
== 88 && shift_key
) { // shift-X
752 dismissReadArticles();
756 if (keycode
== 78 || keycode
== 40) { // n, down
757 if (typeof moveToPost
!= 'undefined') {
763 if (keycode
== 80 || keycode
== 38) { // p, up
764 if (typeof moveToPost
!= 'undefined') {
770 if (keycode
== 83 && shift_key
) { // S
771 selectionTogglePublished(undefined, false, true);
775 if (keycode
== 83) { // s
776 selectionToggleMarked(undefined, false, true);
780 if (keycode
== 85) { // u
781 selectionToggleUnread(undefined, false, true);
785 if (keycode
== 84 && shift_key
) { // T
786 var id
= getActiveArticleId();
788 editArticleTags(id
, getActiveFeedId(), isCdmMode());
793 if (keycode
== 9) { // tab
794 var id
= getArticleUnderPointer();
796 var cb
= $("RCHK-" + id
);
799 cb
.checked
= !cb
.checked
;
800 toggleSelectRowById(cb
, "RROW-" + id
);
806 if (keycode
== 79) { // o
807 if (getActiveArticleId()) {
808 openArticleInNewWindow(getActiveArticleId());
813 if (keycode
== 81 && shift_key
) { // Q
814 if (typeof catchupAllFeeds
!= 'undefined') {
820 if (keycode
== 88 && !shift_key
) { // x
821 if (activeFeedIsCat()) {
822 dijit
.byId("feedTree").collapseCat(getActiveFeedId());
830 if (hotkey_prefix
== 65) { // a
831 hotkey_prefix
= false;
833 if (keycode
== 65) { // a
834 selectArticles('all');
838 if (keycode
== 85) { // u
839 selectArticles('unread');
843 if (keycode
== 73) { // i
844 selectArticles('invert');
848 if (keycode
== 78) { // n
849 selectArticles('none');
857 if (hotkey_prefix
== 70) { // f
859 hotkey_prefix
= false;
861 if (keycode
== 81) { // q
862 if (getActiveFeedId()) {
863 catchupCurrentFeed();
868 if (keycode
== 82) { // r
869 if (getActiveFeedId()) {
870 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
875 if (keycode
== 65) { // a
880 if (keycode
== 85) { // u
881 if (getActiveFeedId()) {
882 viewfeed(getActiveFeedId(), '');
887 if (keycode
== 69) { // e
889 if (activeFeedIsCat())
890 alert(__("You can't edit this kind of feed."));
892 editFeed(getActiveFeedId());
898 if (keycode
== 83) { // s
903 if (keycode
== 67 && shift_key
) { // C
904 if (typeof catchupAllFeeds
!= 'undefined') {
910 if (keycode
== 67) { // c
911 if (getActiveFeedId()) {
912 catchupCurrentFeed();
917 if (keycode
== 88) { // x
918 reverseHeadlineOrder();
925 if (hotkey_prefix
== 67) { // c
926 hotkey_prefix
= false;
928 if (keycode
== 70) { // f
933 if (keycode
== 76) { // l
938 if (keycode
== 83) { // s
939 if (typeof collapse_feedlist
!= 'undefined') {
945 if (keycode
== 77) { // m
946 // TODO: sortable feedlist
950 if (keycode
== 78) { // n
951 catchupRelativeToArticle(1);
955 if (keycode
== 80) { // p
956 catchupRelativeToArticle(0);
965 if (hotkey_prefix
== 71) { // g
967 hotkey_prefix
= false;
970 if (keycode
== 65) { // a
975 if (keycode
== 83) { // s
980 if (keycode
== 80 && shift_key
) { // P
985 if (keycode
== 80) { // p
990 if (keycode
== 70) { // f
995 if (keycode
== 84) { // t
996 displayDlg("printTagCloud");
1003 if (hotkey_prefix
== 224 || hotkey_prefix
== 91) { // f
1004 hotkey_prefix
= false;
1008 if (hotkey_prefix
) {
1009 console
.log("KP: PREFIX=" + hotkey_prefix
+ " CODE=" + keycode
+ " CHAR=" + keychar
);
1011 console
.log("KP: CODE=" + keycode
+ " CHAR=" + keychar
);
1016 exception_error("hotkey_handler", e
);
1020 function inPreferences() {
1024 function reverseHeadlineOrder() {
1027 var query_str
= "?op=rpc&method=togglepref&key=REVERSE_HEADLINES";
1029 new Ajax
.Request("backend.php", {
1030 parameters
: query_str
,
1031 onComplete: function(transport
) {
1036 exception_error("reverseHeadlineOrder", e
);
1040 function scheduleFeedUpdate(id
, is_cat
) {
1043 id
= getActiveFeedId();
1044 is_cat
= activeFeedIsCat();
1048 alert(__("Please select some feed first."));
1052 var query
= "?op=rpc&method=scheduleFeedUpdate&id=" +
1054 "&is_cat=" + param_escape(is_cat
);
1058 new Ajax
.Request("backend.php", {
1060 onComplete: function(transport
) {
1061 handle_rpc_json(transport
);
1063 var reply
= JSON
.parse(transport
.responseText
);
1064 var message
= reply
['message'];
1067 notify_info(message
);
1075 exception_error("scheduleFeedUpdate", e
);
1079 function newVersionDlg() {
1081 var query
= "backend.php?op=dlg&method=newVersion";
1083 if (dijit
.byId("newVersionDlg"))
1084 dijit
.byId("newVersionDlg").destroyRecursive();
1086 dialog
= new dijit
.Dialog({
1087 id
: "newVersionDlg",
1088 title
: __("New version available!"),
1089 style
: "width: 600px",
1096 exception_error("newVersionDlg", e
);
1100 function handle_rpc_json(transport
, scheduled_call
) {
1102 var reply
= JSON
.parse(transport
.responseText
);
1106 var error
= reply
['error'];
1109 var code
= error
['code'];
1110 var msg
= error
['msg'];
1112 console
.warn("[handle_rpc_json] received fatal error " + code
+ "/" + msg
);
1115 fatalError(code
, msg
);
1120 var seq
= reply
['seq'];
1123 if (get_seq() != seq
) {
1124 console
.log("[handle_rpc_json] sequence mismatch: " + seq
+
1125 " (want: " + get_seq() + ")");
1130 var message
= reply
['message'];
1133 if (message
== "UPDATE_COUNTERS") {
1134 console
.log("need to refresh counters...");
1135 setInitParam("last_article_id", -1);
1136 _force_scheduled_update
= true;
1140 var counters
= reply
['counters'];
1143 parse_counters(counters
, scheduled_call
);
1145 var runtime_info
= reply
['runtime-info'];;
1148 parse_runtime_info(runtime_info
);
1150 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1153 notify_error("Error communicating with server.");
1157 notify_error("Error communicating with server.");
1159 //exception_error("handle_rpc_json", e, transport);