]>
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
);
45 dijit
.byId("include_children").attr("disabled", !(is_cat
&& id
> 0));
49 exception_error("setActiveFeedId", e
);
54 function updateFeedList() {
57 // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
58 // __("Loading, please wait...") + "</div>";
60 Element
.show("feedlistLoading");
62 if (dijit
.byId("feedTree")) {
63 dijit
.byId("feedTree").destroyRecursive();
66 var store
= new dojo
.data
.ItemFileWriteStore({
67 url
: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"});
69 var treeModel
= new fox
.FeedStoreModel({
72 "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
76 childrenAttrs
: ["items"]
79 var tree
= new fox
.FeedTree({
82 onOpen: function (item
, node
) {
83 var id
= String(item
.id
);
84 var cat_id
= id
.substr(id
.indexOf(":")+1);
86 new Ajax
.Request("backend.php",
87 { parameters
: "backend.php?op=feeds&method=collapse&cid=" +
88 param_escape(cat_id
) + "&mode=0" } );
90 onClose: function (item
, node
) {
91 var id
= String(item
.id
);
92 var cat_id
= id
.substr(id
.indexOf(":")+1);
94 new Ajax
.Request("backend.php",
95 { parameters
: "backend.php?op=feeds&method=collapse&cid=" +
96 param_escape(cat_id
) + "&mode=1" } );
99 onClick: function (item
, node
) {
100 var id
= String(item
.id
);
101 var is_cat
= id
.match("^CAT:");
102 var feed
= id
.substr(id
.indexOf(":")+1);
103 viewfeed(feed
, '', is_cat
);
111 _force_scheduled_update
= true;
113 /* var menu = new dijit.Menu({id: 'feedMenu'});
115 menu.addChild(new dijit.MenuItem({
116 label: "Simple menu item"
119 // menu.bindDomNode(tree.domNode); */
121 var tmph
= dojo
.connect(dijit
.byId('feedMenu'), '_openMyself', function (event
) {
122 console
.log(dijit
.getEnclosingWidget(event
.target
));
123 dojo
.disconnect(tmph
);
126 $("feeds-holder").appendChild(tree
.domNode
);
128 var tmph
= dojo
.connect(tree
, 'onLoad', function() {
129 dojo
.disconnect(tmph
);
130 Element
.hide("feedlistLoading");
132 tree
.collapseHiddenCats();
136 // var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
137 // menu.bindDomNode(node);
139 loading_set_progress(25);
145 exception_error("updateFeedList", e
);
149 function catchupAllFeeds() {
151 var str
= __("Mark all articles as read?");
153 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
155 var query_str
= "backend.php?op=feeds&method=catchupAll";
157 notify_progress("Marking all feeds as read...");
159 //console.log("catchupAllFeeds Q=" + query_str);
161 new Ajax
.Request("backend.php", {
162 parameters
: query_str
,
163 onComplete: function(transport
) {
164 feedlist_callback2(transport
);
172 function viewCurrentFeed(method
) {
174 if (getActiveFeedId() != undefined) {
175 viewfeed(getActiveFeedId(), method
, activeFeedIsCat());
177 return false; // block unneeded form submits
181 if (getInitParam("bw_limit") == "1") return;
184 var date
= new Date();
185 var ts
= Math
.round(date
.getTime() / 1000);
187 if (ts
- last_scheduled_update
> 10 || _force_scheduled_update
) {
189 //console.log("timeout()");
191 window
.clearTimeout(counter_timeout_id
);
193 var query_str
= "?op=rpc&method=getAllCounters&seq=" + next_seq();
197 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
198 firsttime_update
= false;
204 query_str
= query_str
+ "&omode=" + omode
;
206 if (!_force_scheduled_update
)
207 query_str
= query_str
+ "&last_article_id=" + getInitParam("last_article_id");
209 //console.log("[timeout]" + query_str);
211 new Ajax
.Request("backend.php", {
212 parameters
: query_str
,
213 onComplete: function(transport
) {
214 handle_rpc_json(transport
, !_force_scheduled_update
);
215 _force_scheduled_update
= false;
218 last_scheduled_update
= ts
;
222 exception_error("timeout", e
);
225 setTimeout("timeout()", 3000);
229 var query
= "backend.php?op=dlg&method=search¶m=" +
230 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
232 if (dijit
.byId("searchDlg"))
233 dijit
.byId("searchDlg").destroyRecursive();
235 dialog
= new dijit
.Dialog({
238 style
: "width: 600px",
239 execute: function() {
240 if (this.validate()) {
241 _search_query
= dojo
.objectToQuery(this.attr('value'));
251 function updateTitle() {
252 var tmp
= "Tiny Tiny RSS";
254 if (global_unread
> 0) {
255 tmp
= tmp
+ " (" + global_unread
+ ")";
259 if (global_unread
> 0) {
260 window
.fluid
.dockBadge
= global_unread
;
262 window
.fluid
.dockBadge
= "";
266 document
.title
= tmp
;
269 function genericSanityCheck() {
270 setCookie("ttrss_test", "TEST");
272 if (getCookie("ttrss_test") != "TEST") {
273 return fatalError(2);
281 //dojo.registerModulePath("fox", "../../js/");
283 dojo
.require("fox.FeedTree");
285 if (typeof themeBeforeLayout
== 'function') {
289 dojo
.require("dijit.ColorPalette");
290 dojo
.require("dijit.Dialog");
291 dojo
.require("dijit.form.Button");
292 dojo
.require("dijit.form.CheckBox");
293 dojo
.require("dijit.form.DropDownButton");
294 dojo
.require("dijit.form.FilteringSelect");
295 dojo
.require("dijit.form.Form");
296 dojo
.require("dijit.form.RadioButton");
297 dojo
.require("dijit.form.Select");
298 dojo
.require("dijit.form.SimpleTextarea");
299 dojo
.require("dijit.form.TextBox");
300 dojo
.require("dijit.form.ValidationTextBox");
301 dojo
.require("dijit.InlineEditBox");
302 dojo
.require("dijit.layout.AccordionContainer");
303 dojo
.require("dijit.layout.BorderContainer");
304 dojo
.require("dijit.layout.ContentPane");
305 dojo
.require("dijit.layout.TabContainer");
306 dojo
.require("dijit.Menu");
307 dojo
.require("dijit.ProgressBar");
308 dojo
.require("dijit.ProgressBar");
309 dojo
.require("dijit.Toolbar");
310 dojo
.require("dijit.Tree");
311 dojo
.require("dijit.tree.dndSource");
312 dojo
.require("dojo.data.ItemFileWriteStore");
316 if (!genericSanityCheck())
319 loading_set_progress(20);
321 var hasAudio
= !!((myAudioTag
= document
.createElement('audio')).canPlayType
);
323 new Ajax
.Request("backend.php", {
324 parameters
: {op
: "rpc", method
: "sanityCheck", hasAudio
: hasAudio
},
325 onComplete: function(transport
) {
326 backend_sanity_check_callback(transport
);
330 exception_error("init", e
);
334 function init_second_stage() {
337 dojo
.addOnLoad(function() {
341 if (typeof themeAfterLayout
== 'function') {
347 delCookie("ttrss_test");
349 var toolbar
= document
.forms
["main_toolbar_form"];
351 dijit
.getEnclosingWidget(toolbar
.view_mode
).attr('value',
352 getInitParam("default_view_mode"));
354 dijit
.getEnclosingWidget(toolbar
.order_by
).attr('value',
355 getInitParam("default_view_order_by"));
358 if (getInitParam("enable_feed_cats") == 0)
359 Element
.hide(dijit
.byId("include_children").domNode
);
361 dijit
.byId("include_children").attr("checked",
362 getInitParam("default_include_children"));
364 feeds_sort_by_unread
= getInitParam("feeds_sort_by_unread") == 1;
366 loading_set_progress(30);
368 // can't use cache_clear() here because viewfeed might not have initialized yet
369 if ('sessionStorage' in window
&& window
['sessionStorage'] !== null)
370 sessionStorage
.clear();
372 console
.log("second stage ok");
375 exception_error("init_second_stage", e
);
379 function quickMenuGo(opid
) {
381 if (opid
== "qmcPrefs") {
385 if (opid
== "qmcTagCloud") {
386 displayDlg("printTagCloud");
389 if (opid
== "qmcTagSelect") {
390 displayDlg("printTagSelect");
393 if (opid
== "qmcSearch") {
398 if (opid
== "qmcAddFeed") {
403 if (opid
== "qmcDigest") {
404 window
.location
.href
= "digest.php";
408 if (opid
== "qmcEditFeed") {
409 if (activeFeedIsCat())
410 alert(__("You can't edit this kind of feed."));
412 editFeed(getActiveFeedId());
416 if (opid
== "qmcRemoveFeed") {
417 var actid
= getActiveFeedId();
419 if (activeFeedIsCat()) {
420 alert(__("You can't unsubscribe from the category."));
425 alert(__("Please select some feed first."));
429 var fn
= getFeedName(actid
);
431 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
434 unsubscribeFeed(actid
);
440 if (opid
== "qmcCatchupAll") {
445 if (opid
== "qmcShowOnlyUnread") {
450 if (opid
== "qmcAddFilter") {
455 if (opid
== "qmcAddLabel") {
460 if (opid
== "qmcRescoreFeed") {
461 rescoreCurrentFeed();
465 if (opid
== "qmcHKhelp") {
466 new Ajax
.Request("backend.php", {
467 parameters
: "?op=backend&method=help&topic=main",
468 onComplete: function(transport
) {
469 $("hotkey_help_overlay").innerHTML
= transport
.responseText
;
470 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
475 exception_error("quickMenuGo", e
);
479 function toggleDispRead() {
482 var hide
= !(getInitParam("hide_read_feeds") == "1");
484 hideOrShowFeeds(hide
);
486 var query
= "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" +
489 setInitParam("hide_read_feeds", hide
);
491 new Ajax
.Request("backend.php", {
493 onComplete: function(transport
) {
497 exception_error("toggleDispRead", e
);
501 function parse_runtime_info(data
) {
503 //console.log("parsing runtime info...");
508 // console.log("RI: " + k + " => " + v);
510 if (k
== "new_version_available") {
511 var icon
= $("newVersionIcon");
514 icon
.style
.display
= "inline";
516 icon
.style
.display
= "none";
522 if (k
== "daemon_is_running" && v
!= 1) {
523 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
527 if (k
== "daemon_stamp_ok" && v
!= 1) {
528 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
532 if (k
== "max_feed_id" || k
== "num_feeds") {
533 if (init_params
[k
] != v
) {
534 console
.log("feed count changed, need to reload feedlist.");
544 function collapse_feedlist() {
547 if (!Element
.visible('feeds-holder')) {
548 Element
.show('feeds-holder');
549 Element
.show('feeds-holder_splitter');
550 $("collapse_feeds_btn").innerHTML
= "<<";
552 Element
.hide('feeds-holder');
553 Element
.hide('feeds-holder_splitter');
554 $("collapse_feeds_btn").innerHTML
= ">>";
557 dijit
.byId("main").resize();
559 query
= "?op=rpc&method=setpref&key=_COLLAPSED_FEEDLIST&value=true";
560 new Ajax
.Request("backend.php", { parameters
: query
});
563 exception_error("collapse_feedlist", e
);
567 function viewModeChanged() {
568 return viewCurrentFeed('');
571 function viewLimitChanged() {
572 return viewCurrentFeed('');
575 /* function adjustArticleScore(id, score) {
578 var pr = prompt(__("Assign score to article:"), score);
580 if (pr != undefined) {
581 var query = "?op=rpc&method=setScore&id=" + id + "&score=" + pr;
583 new Ajax.Request("backend.php", {
585 onComplete: function(transport) {
591 exception_error("adjustArticleScore", e);
595 function rescoreCurrentFeed() {
597 var actid
= getActiveFeedId();
599 if (activeFeedIsCat() || actid
< 0) {
600 alert(__("You can't rescore this kind of feed."));
605 alert(__("Please select some feed first."));
609 var fn
= getFeedName(actid
);
610 var pr
= __("Rescore articles in %s?").replace("%s", fn
);
613 notify_progress("Rescoring articles...");
615 var query
= "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid
;
617 new Ajax
.Request("backend.php", {
619 onComplete: function(transport
) {
625 function hotkey_handler(e
) {
628 if (e
.target
.nodeName
== "INPUT" || e
.target
.nodeName
== "TEXTAREA") return;
631 var shift_key
= false;
633 var cmdline
= $('cmdline');
636 shift_key
= e
.shiftKey
;
642 keycode
= window
.event
.keyCode
;
647 var keychar
= String
.fromCharCode(keycode
);
649 if (keycode
== 27) { // escape
650 if (Element
.visible("hotkey_help_overlay")) {
651 Element
.hide("hotkey_help_overlay");
653 hotkey_prefix
= false;
656 if (keycode
== 16) return; // ignore lone shift
657 if (keycode
== 17) return; // ignore lone ctrl
659 if ((keycode
== 70 || keycode
== 67 || keycode
== 71 || keycode
== 65)
662 var date
= new Date();
663 var ts
= Math
.round(date
.getTime() / 1000);
665 hotkey_prefix
= keycode
;
666 hotkey_prefix_pressed
= ts
;
668 cmdline
.innerHTML
= keychar
;
669 Element
.show(cmdline
);
671 console
.log("KP: PREFIX=" + keycode
+ " CHAR=" + keychar
+ " TS=" + ts
);
675 if (Element
.visible("hotkey_help_overlay")) {
676 Element
.hide("hotkey_help_overlay");
681 Element
.hide(cmdline
);
683 if (!hotkey_prefix
) {
685 if (keycode
== 27) { // escape
690 if (keycode
== 69) { // e
691 var id
= getActiveArticleId();
695 if ((keycode
== 191 || keychar
== '?') && shift_key
) { // ?
697 new Ajax
.Request("backend.php", {
698 parameters
: "?op=backend&method=help&topic=main",
699 onComplete: function(transport
) {
700 $("hotkey_help_overlay").innerHTML
= transport
.responseText
;
701 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
706 if (keycode
== 191 || keychar
== '/') { // /
711 if (keycode
== 74 && !shift_key
) { // j
712 var rv
= dijit
.byId("feedTree").getPreviousFeed(
713 getActiveFeedId(), activeFeedIsCat());
715 if (rv
) viewfeed(rv
[0], '', rv
[1]);
720 if (keycode
== 75) { // k
721 var rv
= dijit
.byId("feedTree").getNextFeed(
722 getActiveFeedId(), activeFeedIsCat());
724 if (rv
) viewfeed(rv
[0], '', rv
[1]);
729 if (shift_key
&& keycode
== 40) { // shift-down
730 catchupRelativeToArticle(1);
734 if (shift_key
&& keycode
== 38) { // shift-up
735 catchupRelativeToArticle(0);
739 if (shift_key
&& keycode
== 78) { // N
744 if (shift_key
&& keycode
== 80) { // P
749 if (keycode
== 68 && shift_key
) { // shift-D
750 dismissSelectedArticles();
754 if (keycode
== 88 && shift_key
) { // shift-X
755 dismissReadArticles();
759 if (keycode
== 78 || keycode
== 40) { // n, down
760 if (typeof moveToPost
!= 'undefined') {
766 if (keycode
== 80 || keycode
== 38) { // p, up
767 if (typeof moveToPost
!= 'undefined') {
773 if (keycode
== 83 && shift_key
) { // S
774 selectionTogglePublished(undefined, false, true);
778 if (keycode
== 83) { // s
779 selectionToggleMarked(undefined, false, true);
783 if (keycode
== 85) { // u
784 selectionToggleUnread(undefined, false, true);
788 if (keycode
== 84 && shift_key
) { // T
789 var id
= getActiveArticleId();
791 editArticleTags(id
, getActiveFeedId(), isCdmMode());
796 if (keycode
== 9) { // tab
797 var id
= getArticleUnderPointer();
799 var cb
= $("RCHK-" + id
);
802 cb
.checked
= !cb
.checked
;
803 toggleSelectRowById(cb
, "RROW-" + id
);
809 if (keycode
== 79) { // o
810 if (getActiveArticleId()) {
811 openArticleInNewWindow(getActiveArticleId());
816 if (keycode
== 81 && shift_key
) { // Q
817 if (typeof catchupAllFeeds
!= 'undefined') {
823 if (keycode
== 88 && !shift_key
) { // x
824 if (activeFeedIsCat()) {
825 dijit
.byId("feedTree").collapseCat(getActiveFeedId());
833 if (hotkey_prefix
== 65) { // a
834 hotkey_prefix
= false;
836 if (keycode
== 65) { // a
837 selectArticles('all');
841 if (keycode
== 85) { // u
842 selectArticles('unread');
846 if (keycode
== 73) { // i
847 selectArticles('invert');
851 if (keycode
== 78) { // n
852 selectArticles('none');
860 if (hotkey_prefix
== 70) { // f
862 hotkey_prefix
= false;
864 if (keycode
== 81) { // q
865 if (getActiveFeedId()) {
866 catchupCurrentFeed();
871 if (keycode
== 82) { // r
872 if (getActiveFeedId()) {
873 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
878 if (keycode
== 65) { // a
883 if (keycode
== 85) { // u
884 if (getActiveFeedId()) {
885 viewfeed(getActiveFeedId(), '');
890 if (keycode
== 69) { // e
892 if (activeFeedIsCat())
893 alert(__("You can't edit this kind of feed."));
895 editFeed(getActiveFeedId());
901 if (keycode
== 83) { // s
906 if (keycode
== 67 && shift_key
) { // C
907 if (typeof catchupAllFeeds
!= 'undefined') {
913 if (keycode
== 67) { // c
914 if (getActiveFeedId()) {
915 catchupCurrentFeed();
920 if (keycode
== 88) { // x
921 reverseHeadlineOrder();
928 if (hotkey_prefix
== 67) { // c
929 hotkey_prefix
= false;
931 if (keycode
== 70) { // f
936 if (keycode
== 76) { // l
941 if (keycode
== 83) { // s
942 if (typeof collapse_feedlist
!= 'undefined') {
948 if (keycode
== 77) { // m
949 // TODO: sortable feedlist
953 if (keycode
== 78) { // n
954 catchupRelativeToArticle(1);
958 if (keycode
== 80) { // p
959 catchupRelativeToArticle(0);
968 if (hotkey_prefix
== 71) { // g
970 hotkey_prefix
= false;
973 if (keycode
== 65) { // a
978 if (keycode
== 83) { // s
983 if (keycode
== 80 && shift_key
) { // P
988 if (keycode
== 80) { // p
993 if (keycode
== 70) { // f
998 if (keycode
== 84) { // t
999 displayDlg("printTagCloud");
1006 if (hotkey_prefix
== 224 || hotkey_prefix
== 91) { // f
1007 hotkey_prefix
= false;
1011 if (hotkey_prefix
) {
1012 console
.log("KP: PREFIX=" + hotkey_prefix
+ " CODE=" + keycode
+ " CHAR=" + keychar
);
1014 console
.log("KP: CODE=" + keycode
+ " CHAR=" + keychar
);
1019 exception_error("hotkey_handler", e
);
1023 function inPreferences() {
1027 function reverseHeadlineOrder() {
1030 var query_str
= "?op=rpc&method=togglepref&key=REVERSE_HEADLINES";
1032 new Ajax
.Request("backend.php", {
1033 parameters
: query_str
,
1034 onComplete: function(transport
) {
1039 exception_error("reverseHeadlineOrder", e
);
1043 function scheduleFeedUpdate(id
, is_cat
) {
1046 id
= getActiveFeedId();
1047 is_cat
= activeFeedIsCat();
1051 alert(__("Please select some feed first."));
1055 var query
= "?op=rpc&method=scheduleFeedUpdate&id=" +
1057 "&is_cat=" + param_escape(is_cat
);
1061 new Ajax
.Request("backend.php", {
1063 onComplete: function(transport
) {
1064 handle_rpc_json(transport
);
1066 var reply
= JSON
.parse(transport
.responseText
);
1067 var message
= reply
['message'];
1070 notify_info(message
);
1078 exception_error("scheduleFeedUpdate", e
);
1082 function newVersionDlg() {
1084 var query
= "backend.php?op=dlg&method=newVersion";
1086 if (dijit
.byId("newVersionDlg"))
1087 dijit
.byId("newVersionDlg").destroyRecursive();
1089 dialog
= new dijit
.Dialog({
1090 id
: "newVersionDlg",
1091 title
: __("New version available!"),
1092 style
: "width: 600px",
1099 exception_error("newVersionDlg", e
);
1103 function handle_rpc_json(transport
, scheduled_call
) {
1105 var reply
= JSON
.parse(transport
.responseText
);
1109 var error
= reply
['error'];
1112 var code
= error
['code'];
1113 var msg
= error
['msg'];
1115 console
.warn("[handle_rpc_json] received fatal error " + code
+ "/" + msg
);
1118 fatalError(code
, msg
);
1123 var seq
= reply
['seq'];
1126 if (get_seq() != seq
) {
1127 console
.log("[handle_rpc_json] sequence mismatch: " + seq
+
1128 " (want: " + get_seq() + ")");
1133 var message
= reply
['message'];
1136 if (message
== "UPDATE_COUNTERS") {
1137 console
.log("need to refresh counters...");
1138 setInitParam("last_article_id", -1);
1139 _force_scheduled_update
= true;
1143 var counters
= reply
['counters'];
1146 parse_counters(counters
, scheduled_call
);
1148 var runtime_info
= reply
['runtime-info'];;
1151 parse_runtime_info(runtime_info
);
1153 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1156 notify_error("Error communicating with server.");
1160 notify_error("Error communicating with server.");
1162 //exception_error("handle_rpc_json", e, transport);