]>
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;
8 var _force_scheduled_update
= false;
9 var last_scheduled_update
= false;
22 function activeFeedIsCat() {
23 return _active_feed_is_cat
;
26 function getActiveFeedId() {
28 //console.log("gAFID: " + _active_feed_id);
29 return _active_feed_id
;
31 exception_error("getActiveFeedId", e
);
35 function setActiveFeedId(id
, is_cat
) {
39 if (is_cat
!= undefined) {
40 _active_feed_is_cat
= is_cat
;
43 selectFeed(id
, is_cat
);
46 exception_error("setActiveFeedId", e
);
51 function updateFeedList() {
54 // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
55 // __("Loading, please wait...") + "</div>";
57 Element
.show("feedlistLoading");
59 if (dijit
.byId("feedTree")) {
60 dijit
.byId("feedTree").destroyRecursive();
63 var store
= new dojo
.data
.ItemFileWriteStore({
64 url
: "backend.php?op=feeds"});
66 var treeModel
= new fox
.FeedStoreModel({
73 childrenAttrs
: ["items"]
76 var tree
= new fox
.FeedTree({
79 onOpen: function (item
, node
) {
80 var id
= String(item
.id
);
81 var cat_id
= id
.substr(id
.indexOf(":")+1);
83 new Ajax
.Request("backend.php",
84 { parameters
: "backend.php?op=feeds&method=collapse&cid=" +
85 param_escape(cat_id
) + "&mode=0" } );
87 onClose: function (item
, node
) {
88 var id
= String(item
.id
);
89 var cat_id
= id
.substr(id
.indexOf(":")+1);
91 new Ajax
.Request("backend.php",
92 { parameters
: "backend.php?op=feeds&method=collapse&cid=" +
93 param_escape(cat_id
) + "&mode=1" } );
96 onClick: function (item
, node
) {
97 var id
= String(item
.id
);
98 var is_cat
= id
.match("^CAT:");
99 var feed
= id
.substr(id
.indexOf(":")+1);
100 viewfeed(feed
, '', is_cat
);
108 /* var menu = new dijit.Menu({id: 'feedMenu'});
110 menu.addChild(new dijit.MenuItem({
111 label: "Simple menu item"
114 // menu.bindDomNode(tree.domNode); */
116 var tmph
= dojo
.connect(dijit
.byId('feedMenu'), '_openMyself', function (event
) {
117 console
.log(dijit
.getEnclosingWidget(event
.target
));
118 dojo
.disconnect(tmph
);
121 $("feeds-holder").appendChild(tree
.domNode
);
123 var tmph
= dojo
.connect(tree
, 'onLoad', function() {
124 dojo
.disconnect(tmph
);
125 Element
.hide("feedlistLoading");
127 tree
.collapseHiddenCats();
131 // var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
132 // menu.bindDomNode(node);
134 loading_set_progress(25);
140 exception_error("updateFeedList", e
);
144 function catchupAllFeeds() {
146 var str
= __("Mark all articles as read?");
148 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
150 var query_str
= "backend.php?op=feeds&method=catchupAll";
152 notify_progress("Marking all feeds as read...");
154 //console.log("catchupAllFeeds Q=" + query_str);
156 new Ajax
.Request("backend.php", {
157 parameters
: query_str
,
158 onComplete: function(transport
) {
159 feedlist_callback2(transport
);
167 function viewCurrentFeed(method
) {
169 if (getActiveFeedId() != undefined) {
170 viewfeed(getActiveFeedId(), method
, activeFeedIsCat());
172 return false; // block unneeded form submits
176 if (getInitParam("bw_limit") == "1") return;
179 var date
= new Date();
180 var ts
= Math
.round(date
.getTime() / 1000);
182 if (ts
- last_scheduled_update
> 10 || _force_scheduled_update
) {
184 //console.log("timeout()");
186 window
.clearTimeout(counter_timeout_id
);
188 var query_str
= "?op=rpc&method=getAllCounters&seq=" + next_seq();
192 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
193 firsttime_update
= false;
199 query_str
= query_str
+ "&omode=" + omode
;
201 if (!_force_scheduled_update
)
202 query_str
= query_str
+ "&last_article_id=" + getInitParam("last_article_id");
204 //console.log("[timeout]" + query_str);
206 new Ajax
.Request("backend.php", {
207 parameters
: query_str
,
208 onComplete: function(transport
) {
209 handle_rpc_json(transport
, !_force_scheduled_update
);
210 _force_scheduled_update
= false;
213 last_scheduled_update
= ts
;
217 exception_error("timeout", e
);
220 setTimeout("timeout()", 3000);
224 var query
= "backend.php?op=dlg&method=search¶m=" +
225 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
227 if (dijit
.byId("searchDlg"))
228 dijit
.byId("searchDlg").destroyRecursive();
230 dialog
= new dijit
.Dialog({
233 style
: "width: 600px",
234 execute: function() {
235 if (this.validate()) {
236 _search_query
= dojo
.objectToQuery(this.attr('value'));
246 function updateTitle() {
247 var tmp
= "Tiny Tiny RSS";
249 if (global_unread
> 0) {
250 tmp
= tmp
+ " (" + global_unread
+ ")";
254 if (global_unread
> 0) {
255 window
.fluid
.dockBadge
= global_unread
;
257 window
.fluid
.dockBadge
= "";
261 document
.title
= tmp
;
264 function genericSanityCheck() {
265 setCookie("ttrss_test", "TEST");
267 if (getCookie("ttrss_test") != "TEST") {
268 return fatalError(2);
276 //dojo.registerModulePath("fox", "../../js/");
278 dojo
.require("fox.FeedTree");
280 if (typeof themeBeforeLayout
== 'function') {
286 if (!genericSanityCheck())
289 loading_set_progress(20);
291 var hasAudio
= !!((myAudioTag
= document
.createElement('audio')).canPlayType
);
293 new Ajax
.Request("backend.php", {
294 parameters
: {op
: "rpc", method
: "sanityCheck", hasAudio
: hasAudio
},
295 onComplete: function(transport
) {
296 backend_sanity_check_callback(transport
);
300 exception_error("init", e
);
304 function init_second_stage() {
307 dojo
.addOnLoad(function() {
311 if (typeof themeAfterLayout
== 'function') {
317 delCookie("ttrss_test");
319 var toolbar
= document
.forms
["main_toolbar_form"];
321 dijit
.getEnclosingWidget(toolbar
.view_mode
).attr('value',
322 getInitParam("default_view_mode"));
324 dijit
.getEnclosingWidget(toolbar
.order_by
).attr('value',
325 getInitParam("default_view_order_by"));
327 feeds_sort_by_unread
= getInitParam("feeds_sort_by_unread") == 1;
329 loading_set_progress(30);
331 // can't use cache_clear() here because viewfeed might not have initialized yet
332 if ('sessionStorage' in window
&& window
['sessionStorage'] !== null)
333 sessionStorage
.clear();
335 console
.log("second stage ok");
338 exception_error("init_second_stage", e
);
342 function quickMenuGo(opid
) {
344 if (opid
== "qmcPrefs") {
348 if (opid
== "qmcTagCloud") {
349 displayDlg("printTagCloud");
352 if (opid
== "qmcTagSelect") {
353 displayDlg("printTagSelect");
356 if (opid
== "qmcSearch") {
361 if (opid
== "qmcAddFeed") {
366 if (opid
== "qmcDigest") {
367 window
.location
.href
= "digest.php";
371 if (opid
== "qmcEditFeed") {
372 if (activeFeedIsCat())
373 alert(__("You can't edit this kind of feed."));
375 editFeed(getActiveFeedId());
379 if (opid
== "qmcRemoveFeed") {
380 var actid
= getActiveFeedId();
382 if (activeFeedIsCat()) {
383 alert(__("You can't unsubscribe from the category."));
388 alert(__("Please select some feed first."));
392 var fn
= getFeedName(actid
);
394 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
397 unsubscribeFeed(actid
);
403 if (opid
== "qmcCatchupAll") {
408 if (opid
== "qmcShowOnlyUnread") {
413 if (opid
== "qmcAddFilter") {
418 if (opid
== "qmcAddLabel") {
423 if (opid
== "qmcRescoreFeed") {
424 rescoreCurrentFeed();
428 if (opid
== "qmcHKhelp") {
429 new Ajax
.Request("backend.php", {
430 parameters
: "?op=backend&method=help&topic=main",
431 onComplete: function(transport
) {
432 $("hotkey_help_overlay").innerHTML
= transport
.responseText
;
433 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
438 exception_error("quickMenuGo", e
);
442 function toggleDispRead() {
445 var hide
= !(getInitParam("hide_read_feeds") == "1");
447 hideOrShowFeeds(hide
);
449 var query
= "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" +
452 setInitParam("hide_read_feeds", hide
);
454 new Ajax
.Request("backend.php", {
456 onComplete: function(transport
) {
460 exception_error("toggleDispRead", e
);
464 function parse_runtime_info(data
) {
466 //console.log("parsing runtime info...");
471 // console.log("RI: " + k + " => " + v);
473 if (k
== "new_version_available") {
474 var icon
= $("newVersionIcon");
477 icon
.style
.display
= "inline";
479 icon
.style
.display
= "none";
485 if (k
== "daemon_is_running" && v
!= 1) {
486 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
490 if (k
== "daemon_stamp_ok" && v
!= 1) {
491 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
495 if (k
== "max_feed_id" || k
== "num_feeds") {
496 if (init_params
[k
] != v
) {
497 console
.log("feed count changed, need to reload feedlist.");
507 function catchupCurrentFeed() {
509 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
511 var str
= __("Mark all articles in %s as read?").replace("%s", fn
);
513 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
514 return viewCurrentFeed('MarkAllRead');
518 function catchupFeedInGroup(id
) {
522 var title
= getFeedName(id
);
524 var str
= __("Mark all articles in %s as read?").replace("%s", title
);
526 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
527 return viewCurrentFeed('MarkAllReadGR:' + id
);
531 exception_error("catchupFeedInGroup", e
);
535 function collapse_feedlist() {
538 if (!Element
.visible('feeds-holder')) {
539 Element
.show('feeds-holder');
540 Element
.show('feeds-holder_splitter');
541 $("collapse_feeds_btn").innerHTML
= "<<";
543 Element
.hide('feeds-holder');
544 Element
.hide('feeds-holder_splitter');
545 $("collapse_feeds_btn").innerHTML
= ">>";
548 dijit
.byId("main").resize();
550 query
= "?op=rpc&method=setpref&key=_COLLAPSED_FEEDLIST&value=true";
551 new Ajax
.Request("backend.php", { parameters
: query
});
554 exception_error("collapse_feedlist", e
);
558 function viewModeChanged() {
559 return viewCurrentFeed('');
562 function viewLimitChanged() {
563 return viewCurrentFeed('');
566 /* function adjustArticleScore(id, score) {
569 var pr = prompt(__("Assign score to article:"), score);
571 if (pr != undefined) {
572 var query = "?op=rpc&method=setScore&id=" + id + "&score=" + pr;
574 new Ajax.Request("backend.php", {
576 onComplete: function(transport) {
582 exception_error("adjustArticleScore", e);
586 function rescoreCurrentFeed() {
588 var actid
= getActiveFeedId();
590 if (activeFeedIsCat() || actid
< 0) {
591 alert(__("You can't rescore this kind of feed."));
596 alert(__("Please select some feed first."));
600 var fn
= getFeedName(actid
);
601 var pr
= __("Rescore articles in %s?").replace("%s", fn
);
604 notify_progress("Rescoring articles...");
606 var query
= "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid
;
608 new Ajax
.Request("backend.php", {
610 onComplete: function(transport
) {
616 function hotkey_handler(e
) {
619 if (e
.target
.nodeName
== "INPUT" || e
.target
.nodeName
== "TEXTAREA") return;
622 var shift_key
= false;
624 var cmdline
= $('cmdline');
627 shift_key
= e
.shiftKey
;
633 keycode
= window
.event
.keyCode
;
638 var keychar
= String
.fromCharCode(keycode
);
640 if (keycode
== 27) { // escape
641 if (Element
.visible("hotkey_help_overlay")) {
642 Element
.hide("hotkey_help_overlay");
644 hotkey_prefix
= false;
647 if (keycode
== 16) return; // ignore lone shift
648 if (keycode
== 17) return; // ignore lone ctrl
650 if ((keycode
== 70 || keycode
== 67 || keycode
== 71 || keycode
== 65)
653 var date
= new Date();
654 var ts
= Math
.round(date
.getTime() / 1000);
656 hotkey_prefix
= keycode
;
657 hotkey_prefix_pressed
= ts
;
659 cmdline
.innerHTML
= keychar
;
660 Element
.show(cmdline
);
662 console
.log("KP: PREFIX=" + keycode
+ " CHAR=" + keychar
+ " TS=" + ts
);
666 if (Element
.visible("hotkey_help_overlay")) {
667 Element
.hide("hotkey_help_overlay");
672 Element
.hide(cmdline
);
674 if (!hotkey_prefix
) {
676 if (keycode
== 27) { // escape
681 if (keycode
== 69) { // e
682 var id
= getActiveArticleId();
686 if ((keycode
== 191 || keychar
== '?') && shift_key
) { // ?
688 new Ajax
.Request("backend.php", {
689 parameters
: "?op=backend&method=help&topic=main",
690 onComplete: function(transport
) {
691 $("hotkey_help_overlay").innerHTML
= transport
.responseText
;
692 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
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);