]>
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 if (has_local_storage())
334 sessionStorage
.clear();
336 console
.log("second stage ok");
339 exception_error("init_second_stage", e
);
343 function quickMenuGo(opid
) {
345 if (opid
== "qmcPrefs") {
349 if (opid
== "qmcTagCloud") {
350 displayDlg("printTagCloud");
353 if (opid
== "qmcSearch") {
358 if (opid
== "qmcAddFeed") {
363 if (opid
== "qmcDigest") {
364 window
.location
.href
= "digest.php";
368 if (opid
== "qmcEditFeed") {
369 if (activeFeedIsCat())
370 alert(__("You can't edit this kind of feed."));
372 editFeed(getActiveFeedId());
376 if (opid
== "qmcRemoveFeed") {
377 var actid
= getActiveFeedId();
379 if (activeFeedIsCat()) {
380 alert(__("You can't unsubscribe from the category."));
385 alert(__("Please select some feed first."));
389 var fn
= getFeedName(actid
);
391 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
394 unsubscribeFeed(actid
);
400 if (opid
== "qmcCatchupAll") {
405 if (opid
== "qmcShowOnlyUnread") {
410 if (opid
== "qmcAddFilter") {
415 if (opid
== "qmcAddLabel") {
420 if (opid
== "qmcRescoreFeed") {
421 rescoreCurrentFeed();
425 if (opid
== "qmcHKhelp") {
426 //Element.show("hotkey_help_overlay");
427 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
431 exception_error("quickMenuGo", e
);
435 function toggleDispRead() {
438 var hide
= !(getInitParam("hide_read_feeds") == "1");
440 hideOrShowFeeds(hide
);
442 var query
= "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" +
445 setInitParam("hide_read_feeds", hide
);
447 new Ajax
.Request("backend.php", {
449 onComplete: function(transport
) {
453 exception_error("toggleDispRead", e
);
457 function parse_runtime_info(data
) {
459 //console.log("parsing runtime info...");
464 // console.log("RI: " + k + " => " + v);
466 if (k
== "new_version_available") {
467 var icon
= $("newVersionIcon");
470 icon
.style
.display
= "inline";
472 icon
.style
.display
= "none";
480 if (k
== "daemon_is_running" && v
!= 1) {
481 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
485 if (k
== "daemon_stamp_ok" && v
!= 1) {
486 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
490 if (k
== "max_feed_id" || k
== "num_feeds") {
491 if (init_params
[k
] != v
) {
492 console
.log("feed count changed, need to reload feedlist.");
502 function catchupCurrentFeed() {
504 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
506 var str
= __("Mark all articles in %s as read?").replace("%s", fn
);
508 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
509 return viewCurrentFeed('MarkAllRead')
513 function catchupFeedInGroup(id
) {
517 var title
= getFeedName(id
);
519 var str
= __("Mark all articles in %s as read?").replace("%s", title
);
521 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
522 return viewCurrentFeed('MarkAllReadGR:' + id
)
526 exception_error("catchupFeedInGroup", e
);
530 function collapse_feedlist() {
533 if (!Element
.visible('feeds-holder')) {
534 Element
.show('feeds-holder');
535 Element
.show('feeds-holder_splitter');
536 $("collapse_feeds_btn").innerHTML
= "<<";
538 Element
.hide('feeds-holder');
539 Element
.hide('feeds-holder_splitter');
540 $("collapse_feeds_btn").innerHTML
= ">>";
543 dijit
.byId("main").resize();
545 query
= "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
546 new Ajax
.Request("backend.php", { parameters
: query
});
549 exception_error("collapse_feedlist", e
);
553 function viewModeChanged() {
555 return viewCurrentFeed('')
558 function viewLimitChanged() {
560 return viewCurrentFeed('')
563 /* function adjustArticleScore(id, score) {
566 var pr = prompt(__("Assign score to article:"), score);
568 if (pr != undefined) {
569 var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
571 new Ajax.Request("backend.php", {
573 onComplete: function(transport) {
579 exception_error("adjustArticleScore", e);
583 function rescoreCurrentFeed() {
585 var actid
= getActiveFeedId();
587 if (activeFeedIsCat() || actid
< 0) {
588 alert(__("You can't rescore this kind of feed."));
593 alert(__("Please select some feed first."));
597 var fn
= getFeedName(actid
);
598 var pr
= __("Rescore articles in %s?").replace("%s", fn
);
601 notify_progress("Rescoring articles...");
603 var query
= "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid
;
605 new Ajax
.Request("backend.php", {
607 onComplete: function(transport
) {
613 function hotkey_handler(e
) {
616 if (e
.target
.nodeName
== "INPUT" || e
.target
.nodeName
== "TEXTAREA") return;
619 var shift_key
= false;
621 var cmdline
= $('cmdline');
624 shift_key
= e
.shiftKey
;
630 keycode
= window
.event
.keyCode
;
635 var keychar
= String
.fromCharCode(keycode
);
637 if (keycode
== 27) { // escape
638 if (Element
.visible("hotkey_help_overlay")) {
639 Element
.hide("hotkey_help_overlay");
641 hotkey_prefix
= false;
644 if (keycode
== 16) return; // ignore lone shift
645 if (keycode
== 17) return; // ignore lone ctrl
647 if ((keycode
== 70 || keycode
== 67 || keycode
== 71)
650 var date
= new Date();
651 var ts
= Math
.round(date
.getTime() / 1000);
653 hotkey_prefix
= keycode
;
654 hotkey_prefix_pressed
= ts
;
656 cmdline
.innerHTML
= keychar
;
657 Element
.show(cmdline
);
659 console
.log("KP: PREFIX=" + keycode
+ " CHAR=" + keychar
+ " TS=" + ts
);
663 if (Element
.visible("hotkey_help_overlay")) {
664 Element
.hide("hotkey_help_overlay");
669 Element
.hide(cmdline
);
671 if (!hotkey_prefix
) {
673 if ((keycode
== 191 || keychar
== '?') && shift_key
) { // ?
674 if (!Element
.visible("hotkey_help_overlay")) {
675 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
677 Element
.hide("hotkey_help_overlay");
682 if (keycode
== 191 || keychar
== '/') { // /
687 if (keycode
== 74) { // j
688 var rv
= dijit
.byId("feedTree").getPreviousFeed(
689 getActiveFeedId(), activeFeedIsCat());
691 if (rv
) viewfeed(rv
[0], '', rv
[1]);
696 if (keycode
== 75) { // k
697 var rv
= dijit
.byId("feedTree").getNextFeed(
698 getActiveFeedId(), activeFeedIsCat());
700 if (rv
) viewfeed(rv
[0], '', rv
[1]);
705 if (shift_key
&& keycode
== 40) { // shift-down
706 catchupRelativeToArticle(1);
710 if (shift_key
&& keycode
== 38) { // shift-up
711 catchupRelativeToArticle(0);
715 if (shift_key
&& keycode
== 78) { // N
720 if (shift_key
&& keycode
== 80) { // P
725 if (keycode
== 68 && shift_key
) { // shift-D
726 dismissSelectedArticles();
730 if (keycode
== 88 && shift_key
) { // shift-X
731 dismissReadArticles();
735 if (keycode
== 78 || keycode
== 40) { // n, down
736 if (typeof moveToPost
!= 'undefined') {
742 if (keycode
== 80 || keycode
== 38) { // p, up
743 if (typeof moveToPost
!= 'undefined') {
749 if (keycode
== 83 && shift_key
) { // S
750 selectionTogglePublished(undefined, false, true);
754 if (keycode
== 83) { // s
755 selectionToggleMarked(undefined, false, true);
760 if (keycode
== 85) { // u
761 selectionToggleUnread(undefined, false, true)
765 if (keycode
== 84 && shift_key
) { // T
766 var id
= getActiveArticleId();
768 editArticleTags(id
, getActiveFeedId(), isCdmMode());
773 if (keycode
== 9) { // tab
774 var id
= getArticleUnderPointer();
776 var cb
= $("RCHK-" + id
);
779 cb
.checked
= !cb
.checked
;
780 toggleSelectRowById(cb
, "RROW-" + id
);
786 if (keycode
== 79) { // o
787 if (getActiveArticleId()) {
788 openArticleInNewWindow(getActiveArticleId());
793 if (keycode
== 81 && shift_key
) { // Q
794 if (typeof catchupAllFeeds
!= 'undefined') {
800 if (keycode
== 88 && !shift_key
) { // x
801 if (activeFeedIsCat()) {
802 dijit
.byId("feedTree").collapseCat(getActiveFeedId());
810 if (hotkey_prefix
== 70) { // f
812 hotkey_prefix
= false;
814 if (keycode
== 81) { // q
815 if (getActiveFeedId()) {
816 catchupCurrentFeed();
821 if (keycode
== 82) { // r
822 if (getActiveFeedId()) {
823 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
828 if (keycode
== 65) { // a
833 if (keycode
== 85) { // u
834 if (getActiveFeedId()) {
835 viewfeed(getActiveFeedId(), '');
840 if (keycode
== 69) { // e
842 if (activeFeedIsCat())
843 alert(__("You can't edit this kind of feed."));
845 editFeed(getActiveFeedId());
851 if (keycode
== 83) { // s
856 if (keycode
== 67 && shift_key
) { // C
857 if (typeof catchupAllFeeds
!= 'undefined') {
863 if (keycode
== 67) { // c
864 if (getActiveFeedId()) {
865 catchupCurrentFeed();
870 if (keycode
== 87) { // w
871 feeds_sort_by_unread
= !feeds_sort_by_unread
;
872 return resort_feedlist();
875 if (keycode
== 88) { // x
876 reverseHeadlineOrder();
883 if (hotkey_prefix
== 67) { // c
884 hotkey_prefix
= false;
886 if (keycode
== 70) { // f
891 if (keycode
== 76) { // l
896 if (keycode
== 83) { // s
897 if (typeof collapse_feedlist
!= 'undefined') {
903 if (keycode
== 77) { // m
904 // TODO: sortable feedlist
908 if (keycode
== 78) { // n
909 catchupRelativeToArticle(1);
913 if (keycode
== 80) { // p
914 catchupRelativeToArticle(0);
923 if (hotkey_prefix
== 71) { // g
925 hotkey_prefix
= false;
928 if (keycode
== 65) { // a
933 if (keycode
== 83) { // s
938 if (keycode
== 80 && shift_key
) { // P
943 if (keycode
== 80) { // p
948 if (keycode
== 70) { // f
953 if (keycode
== 84 && shift_key
) { // T
961 if (hotkey_prefix
== 224 || hotkey_prefix
== 91) { // f
962 hotkey_prefix
= false;
967 console
.log("KP: PREFIX=" + hotkey_prefix
+ " CODE=" + keycode
+ " CHAR=" + keychar
);
969 console
.log("KP: CODE=" + keycode
+ " CHAR=" + keychar
);
974 exception_error("hotkey_handler", e
);
978 function inPreferences() {
982 function reverseHeadlineOrder() {
985 var query_str
= "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
987 new Ajax
.Request("backend.php", {
988 parameters
: query_str
,
989 onComplete: function(transport
) {
994 exception_error("reverseHeadlineOrder", e
);
998 function scheduleFeedUpdate(id
, is_cat
) {
1001 id
= getActiveFeedId();
1002 is_cat
= activeFeedIsCat();
1006 alert(__("Please select some feed first."));
1010 var query
= "?op=rpc&subop=scheduleFeedUpdate&id=" +
1012 "&is_cat=" + param_escape(is_cat
);
1016 new Ajax
.Request("backend.php", {
1018 onComplete: function(transport
) {
1019 handle_rpc_json(transport
);
1021 var reply
= JSON
.parse(transport
.responseText
);
1022 var message
= reply
['message'];
1025 notify_info(message
);
1033 exception_error("scheduleFeedUpdate", e
);
1037 function newVersionDlg() {
1039 var query
= "backend.php?op=dlg&id=newVersion";
1041 if (dijit
.byId("newVersionDlg"))
1042 dijit
.byId("newVersionDlg").destroyRecursive();
1044 dialog
= new dijit
.Dialog({
1045 id
: "newVersionDlg",
1046 title
: __("New version available!"),
1047 style
: "width: 600px",
1054 exception_error("newVersionDlg", e
);
1058 function handle_rpc_json(transport
, scheduled_call
) {
1060 var reply
= JSON
.parse(transport
.responseText
);
1064 var error
= reply
['error'];
1067 var code
= error
['code'];
1068 var msg
= error
['msg'];
1070 console
.warn("[handle_rpc_json] received fatal error " + code
+ "/" + msg
);
1073 fatalError(code
, msg
);
1078 var seq
= reply
['seq'];
1081 if (get_seq() != seq
) {
1082 console
.log("[handle_rpc_json] sequence mismatch: " + seq
+
1083 " (want: " + get_seq() + ")");
1088 var message
= reply
['message'];
1091 if (message
== "UPDATE_COUNTERS") {
1092 console
.log("need to refresh counters...");
1093 setInitParam("last_article_id", -1);
1094 _force_scheduled_update
= true;
1098 var counters
= reply
['counters'];
1101 parse_counters(counters
, scheduled_call
);
1103 var runtime_info
= reply
['runtime-info'];;
1106 parse_runtime_info(runtime_info
);
1108 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1111 notify_error("Error communicating with server.");
1115 notify_error("Error communicating with server.");
1117 //exception_error("handle_rpc_json", e, transport);