]>
git.wh0rd.org - tt-rss.git/blob - tt-rss.js
5409fe89915643d8de58b8faa439387776d5e364
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 number_of_feeds
= 0;
7 var hotkey_prefix
= false;
8 var hotkey_prefix_pressed
= false;
10 var _force_scheduled_update
= false;
11 var last_scheduled_update
= false;
24 function activeFeedIsCat() {
25 return _active_feed_is_cat
;
28 function getActiveFeedId() {
30 //console.log("gAFID: " + _active_feed_id);
31 return _active_feed_id
;
33 exception_error("getActiveFeedId", e
);
37 function setActiveFeedId(id
, is_cat
) {
41 if (is_cat
!= undefined) {
42 _active_feed_is_cat
= is_cat
;
45 selectFeed(id
, is_cat
);
48 exception_error("setActiveFeedId", e
);
53 function dlg_frefresh_callback(transport
, deleted_feed
) {
54 if (getActiveFeedId() == deleted_feed
) {
55 setTimeout("viewfeed(-5)", 100);
58 setTimeout('updateFeedList()', 50);
62 function updateFeedList() {
65 // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
66 // __("Loading, please wait...") + "</div>";
68 Element
.show("feedlistLoading");
70 if (dijit
.byId("feedTree")) {
71 dijit
.byId("feedTree").destroyRecursive();
74 var store
= new dojo
.data
.ItemFileWriteStore({
75 url
: "backend.php?op=feeds"});
77 var treeModel
= new fox
.FeedStoreModel({
84 childrenAttrs
: ["items"]
87 var tree
= new fox
.FeedTree({
89 onOpen: function (item
, node
) {
90 var id
= String(item
.id
);
91 var cat_id
= id
.substr(id
.indexOf(":")+1);
93 new Ajax
.Request("backend.php",
94 { parameters
: "backend.php?op=feeds&subop=collapse&cid=" +
95 param_escape(cat_id
) + "&mode=0" } );
97 onClose: function (item
, node
) {
98 var id
= String(item
.id
);
99 var cat_id
= id
.substr(id
.indexOf(":")+1);
101 new Ajax
.Request("backend.php",
102 { parameters
: "backend.php?op=feeds&subop=collapse&cid=" +
103 param_escape(cat_id
) + "&mode=1" } );
106 onClick: function (item
, node
) {
107 var id
= String(item
.id
);
108 var is_cat
= id
.match("^CAT:");
109 var feed
= id
.substr(id
.indexOf(":")+1);
110 viewfeed(feed
, '', is_cat
);
118 /* var menu = new dijit.Menu({id: 'feedMenu'});
120 menu.addChild(new dijit.MenuItem({
121 label: "Simple menu item"
124 // menu.bindDomNode(tree.domNode); */
126 var tmph
= dojo
.connect(dijit
.byId('feedMenu'), '_openMyself', function (event
) {
127 console
.log(dijit
.getEnclosingWidget(event
.target
));
128 dojo
.disconnect(tmph
);
131 $("feeds-holder").appendChild(tree
.domNode
);
133 var tmph
= dojo
.connect(tree
, 'onLoad', function() {
134 dojo
.disconnect(tmph
);
135 Element
.hide("feedlistLoading");
137 tree
.collapseHiddenCats();
141 // var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
142 // menu.bindDomNode(node);
144 loading_set_progress(25);
150 exception_error("updateFeedList", e
);
154 function catchupAllFeeds() {
156 var str
= __("Mark all articles as read?");
158 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
160 var query_str
= "backend.php?op=feeds&subop=catchupAll";
162 notify_progress("Marking all feeds as read...");
164 //console.log("catchupAllFeeds Q=" + query_str);
166 new Ajax
.Request("backend.php", {
167 parameters
: query_str
,
168 onComplete: function(transport
) {
169 feedlist_callback2(transport
);
177 function viewCurrentFeed(subop
) {
179 if (getActiveFeedId() != undefined) {
180 viewfeed(getActiveFeedId(), subop
, activeFeedIsCat());
182 return false; // block unneeded form submits
186 if (getInitParam("bw_limit") == "1") return;
189 var date
= new Date();
190 var ts
= Math
.round(date
.getTime() / 1000);
192 if (ts
- last_scheduled_update
> 10 || _force_scheduled_update
) {
194 //console.log("timeout()");
196 window
.clearTimeout(counter_timeout_id
);
198 var query_str
= "?op=rpc&subop=getAllCounters&seq=" + next_seq();
202 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
203 firsttime_update
= false;
209 query_str
= query_str
+ "&omode=" + omode
;
211 if (!_force_scheduled_update
)
212 query_str
= query_str
+ "&last_article_id=" + getInitParam("last_article_id");
214 //console.log("[timeout]" + query_str);
216 new Ajax
.Request("backend.php", {
217 parameters
: query_str
,
218 onComplete: function(transport
) {
219 handle_rpc_reply(transport
, !_force_scheduled_update
);
220 _force_scheduled_update
= false;
223 last_scheduled_update
= ts
;
227 exception_error("timeout", e
);
230 setTimeout("timeout()", 3000);
238 function updateTitle() {
239 var tmp
= "Tiny Tiny RSS";
241 if (global_unread
> 0) {
242 tmp
= tmp
+ " (" + global_unread
+ ")";
246 if (global_unread
> 0) {
247 window
.fluid
.dockBadge
= global_unread
;
249 window
.fluid
.dockBadge
= "";
253 document
.title
= tmp
;
256 function genericSanityCheck() {
257 setCookie("ttrss_test", "TEST");
259 if (getCookie("ttrss_test") != "TEST") {
268 Form
.disable("main_toolbar_form");
270 dojo
.require("dijit.layout.BorderContainer");
271 dojo
.require("dijit.layout.TabContainer");
272 dojo
.require("dijit.layout.ContentPane");
273 dojo
.require("dijit.Dialog");
274 dojo
.require("dijit.form.Button");
275 dojo
.require("dijit.Menu");
276 dojo
.require("dojo.data.ItemFileWriteStore");
277 dojo
.require("dijit.Tree");
278 dojo
.require("dijit.form.Select");
279 dojo
.require("dijit.form.TextBox");
280 dojo
.require("dijit.form.ValidationTextBox");
281 dojo
.require("dijit.form.FilteringSelect");
282 dojo
.require("dijit.Toolbar");
283 dojo
.require("dijit.ProgressBar");
284 dojo
.require("dijit.Menu");
286 dojo
.registerModulePath("fox", "../..");
288 dojo
.require("fox.FeedTree");
290 if (typeof themeBeforeLayout
== 'function') {
294 dojo
.addOnLoad(function() {
298 if (typeof themeAfterLayout
== 'function') {
304 if (!genericSanityCheck())
307 loading_set_progress(20);
309 new Ajax
.Request("backend.php", {
310 parameters
: {op
: "rpc", subop
: "sanityCheck"},
311 onComplete: function(transport
) {
312 backend_sanity_check_callback(transport
);
316 exception_error("init", e
);
320 function init_second_stage() {
324 delCookie("ttrss_test");
326 var toolbar
= document
.forms
["main_toolbar_form"];
328 dropboxSelect(toolbar
.view_mode
, getInitParam("default_view_mode"));
329 dropboxSelect(toolbar
.order_by
, getInitParam("default_view_order_by"));
331 feeds_sort_by_unread
= getInitParam("feeds_sort_by_unread") == 1;
333 loading_set_progress(30);
335 if (has_local_storage())
336 localStorage
.clear();
338 console
.log("second stage ok");
341 exception_error("init_second_stage", e
);
345 function quickMenuChange() {
346 var chooser
= $("quickMenuChooser");
347 var opid
= chooser
[chooser
.selectedIndex
].value
;
349 chooser
.selectedIndex
= 0;
353 function quickMenuGo(opid
) {
356 if (opid
== "qmcPrefs") {
360 if (opid
== "qmcTagCloud") {
361 displayDlg("printTagCloud");
364 if (opid
== "qmcSearch") {
365 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(),
367 document
.forms
['search_form'].query
.focus();
372 if (opid
== "qmcAddFeed") {
377 if (opid
== "qmcEditFeed") {
378 editFeedDlg(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") {
416 displayDlg('quickAddFilter', '',
417 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
420 if (opid
== "qmcAddLabel") {
424 if (opid
== "qmcRescoreFeed") {
425 rescoreCurrentFeed();
428 if (opid
== "qmcHKhelp") {
429 //Element.show("hotkey_help_overlay");
430 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
434 exception_error("quickMenuGo", e
);
438 function toggleDispRead() {
441 var hide
= !(getInitParam("hide_read_feeds") == "1");
443 hideOrShowFeeds(hide
);
445 var query
= "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" +
448 setInitParam("hide_read_feeds", hide
);
450 new Ajax
.Request("backend.php", {
452 onComplete: function(transport
) {
456 exception_error("toggleDispRead", e
);
460 function parse_runtime_info(elem
) {
462 if (!elem
|| !elem
.firstChild
) {
463 console
.warn("parse_runtime_info: invalid node passed");
467 var data
= JSON
.parse(elem
.firstChild
.nodeValue
);
469 //console.log("parsing runtime info...");
474 // console.log("RI: " + k + " => " + v);
476 if (k
== "new_version_available") {
477 var icon
= $("newVersionIcon");
480 icon
.style
.display
= "inline";
482 icon
.style
.display
= "none";
490 if (k
== "daemon_is_running" && v
!= 1) {
491 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
495 if (k
== "daemon_stamp_ok" && v
!= 1) {
496 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
505 function catchupCurrentFeed() {
507 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
509 var str
= __("Mark all articles in %s as read?").replace("%s", fn
);
511 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
512 return viewCurrentFeed('MarkAllRead')
516 function catchupFeedInGroup(id
) {
520 var title
= getFeedName(id
);
522 var str
= __("Mark all articles in %s as read?").replace("%s", title
);
524 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
525 return viewCurrentFeed('MarkAllReadGR:' + id
)
529 exception_error("catchupFeedInGroup", e
);
533 function editFeedDlg(feed
) {
537 alert(__("Please select some feed first."));
541 if ((feed
<= 0) || activeFeedIsCat()) {
542 alert(__("You can't edit this kind of feed."));
549 query
= "?op=pref-feeds&subop=editfeed&id=" + param_escape(feed
);
551 query
= "?op=pref-labels&subop=edit&id=" + param_escape(-feed
-11);
556 notify_progress("Loading, please wait...", true);
558 new Ajax
.Request("backend.php", {
560 onComplete: function(transport
) {
561 infobox_callback2(transport
);
562 document
.forms
["edit_feed_form"].title
.focus();
566 exception_error("editFeedDlg", e
);
570 /* this functions duplicate those of prefs.js feed editor, with
571 some differences because there is no feedlist */
573 function feedEditCancel() {
578 function feedEditSave() {
582 // FIXME: add parameter validation
584 var query
= Form
.serialize("edit_feed_form");
586 notify_progress("Saving feed...");
588 new Ajax
.Request("backend.php", {
590 onComplete: function(transport
) {
591 dlg_frefresh_callback(transport
);
600 exception_error("feedEditSave (main)", e
);
604 function collapse_feedlist() {
607 if (!Element
.visible('feeds-holder')) {
608 Element
.show('feeds-holder');
609 $("collapse_feeds_btn").innerHTML
= "<<";
611 Element
.hide('feeds-holder');
612 $("collapse_feeds_btn").innerHTML
= ">>";
615 dijit
.byId("main").resize();
617 query
= "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
618 new Ajax
.Request("backend.php", { parameters
: query
});
621 exception_error("collapse_feedlist", e
);
625 function viewModeChanged() {
627 return viewCurrentFeed('')
630 function viewLimitChanged() {
632 return viewCurrentFeed('')
635 /* function adjustArticleScore(id, score) {
638 var pr = prompt(__("Assign score to article:"), score);
640 if (pr != undefined) {
641 var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
643 new Ajax.Request("backend.php", {
645 onComplete: function(transport) {
651 exception_error("adjustArticleScore", e);
655 function rescoreCurrentFeed() {
657 var actid
= getActiveFeedId();
659 if (activeFeedIsCat() || actid
< 0) {
660 alert(__("You can't rescore this kind of feed."));
665 alert(__("Please select some feed first."));
669 var fn
= getFeedName(actid
);
670 var pr
= __("Rescore articles in %s?").replace("%s", fn
);
673 notify_progress("Rescoring articles...");
675 var query
= "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid
;
677 new Ajax
.Request("backend.php", {
679 onComplete: function(transport
) {
685 function hotkey_handler(e
) {
690 var shift_key
= false;
692 var cmdline
= $('cmdline');
695 shift_key
= e
.shiftKey
;
701 keycode
= window
.event
.keyCode
;
706 var keychar
= String
.fromCharCode(keycode
);
708 if (keycode
== 27) { // escape
709 if (Element
.visible("hotkey_help_overlay")) {
710 Element
.hide("hotkey_help_overlay");
712 hotkey_prefix
= false;
716 var dialog
= dijit
.byId("infoBox");
717 var dialog_visible
= false;
720 dialog_visible
= Element
.visible(dialog
.domNode
);
722 if (dialog_visible
|| !hotkeys_enabled
) {
723 console
.log("hotkeys disabled");
727 if (keycode
== 16) return; // ignore lone shift
728 if (keycode
== 17) return; // ignore lone ctrl
730 if ((keycode
== 70 || keycode
== 67 || keycode
== 71)
733 var date
= new Date();
734 var ts
= Math
.round(date
.getTime() / 1000);
736 hotkey_prefix
= keycode
;
737 hotkey_prefix_pressed
= ts
;
739 cmdline
.innerHTML
= keychar
;
740 Element
.show(cmdline
);
742 console
.log("KP: PREFIX=" + keycode
+ " CHAR=" + keychar
+ " TS=" + ts
);
746 if (Element
.visible("hotkey_help_overlay")) {
747 Element
.hide("hotkey_help_overlay");
752 Element
.hide(cmdline
);
754 if (!hotkey_prefix
) {
756 if ((keycode
== 191 || keychar
== '?') && shift_key
) { // ?
757 if (!Element
.visible("hotkey_help_overlay")) {
758 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
760 Element
.hide("hotkey_help_overlay");
765 if (keycode
== 191 || keychar
== '/') { // /
766 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(),
768 document
.forms
['search_form'].query
.focus();
773 if (keycode
== 74) { // j
774 // TODO: move to previous feed
778 if (keycode
== 75) { // k
779 // TODO: move to next feed
783 if (shift_key
&& keycode
== 40) { // shift-down
784 catchupRelativeToArticle(1);
788 if (shift_key
&& keycode
== 38) { // shift-up
789 catchupRelativeToArticle(0);
793 if (shift_key
&& keycode
== 78) { // N
798 if (shift_key
&& keycode
== 80) { // P
803 if (keycode
== 68 && shift_key
) { // shift-D
804 dismissSelectedArticles();
807 if (keycode
== 88 && shift_key
) { // shift-X
808 dismissReadArticles();
811 if (keycode
== 78 || keycode
== 40) { // n, down
812 if (typeof moveToPost
!= 'undefined') {
818 if (keycode
== 80 || keycode
== 38) { // p, up
819 if (typeof moveToPost
!= 'undefined') {
825 if (keycode
== 83 && shift_key
) { // S
826 selectionTogglePublished(undefined, false, true);
830 if (keycode
== 83) { // s
831 selectionToggleMarked(undefined, false, true);
836 if (keycode
== 85) { // u
837 selectionToggleUnread(undefined, false, true)
841 if (keycode
== 84 && shift_key
) { // T
842 var id
= getActiveArticleId();
844 editArticleTags(id
, getActiveFeedId(), isCdmMode());
849 if (keycode
== 9) { // tab
850 var id
= getArticleUnderPointer();
852 var cb
= $("RCHK-" + id
);
855 cb
.checked
= !cb
.checked
;
856 toggleSelectRowById(cb
, "RROW-" + id
);
862 if (keycode
== 79) { // o
863 if (getActiveArticleId()) {
864 openArticleInNewWindow(getActiveArticleId());
869 if (keycode
== 81 && shift_key
) { // Q
870 if (typeof catchupAllFeeds
!= 'undefined') {
876 if (keycode
== 88) { // x
877 if (activeFeedIsCat()) {
878 toggleCollapseCat(getActiveFeedId());
885 if (hotkey_prefix
== 70) { // f
887 hotkey_prefix
= false;
889 if (keycode
== 81) { // q
890 if (getActiveFeedId()) {
891 catchupCurrentFeed();
896 if (keycode
== 82) { // r
897 if (getActiveFeedId()) {
898 viewfeed(getActiveFeedId(), "ForceUpdate", activeFeedIsCat());
903 if (keycode
== 65) { // a
908 if (keycode
== 85) { // u
909 if (getActiveFeedId()) {
910 viewfeed(getActiveFeedId(), "ForceUpdate");
915 if (keycode
== 69) { // e
916 editFeedDlg(getActiveFeedId());
920 if (keycode
== 83) { // s
925 if (keycode
== 67 && shift_key
) { // C
926 if (typeof catchupAllFeeds
!= 'undefined') {
932 if (keycode
== 67) { // c
933 if (getActiveFeedId()) {
934 catchupCurrentFeed();
939 if (keycode
== 87) { // w
940 feeds_sort_by_unread
= !feeds_sort_by_unread
;
941 return resort_feedlist();
944 if (keycode
== 88) { // x
945 reverseHeadlineOrder();
952 if (hotkey_prefix
== 67) { // c
953 hotkey_prefix
= false;
955 if (keycode
== 70) { // f
956 displayDlg('quickAddFilter', '',
957 function () {document
.forms
['filter_add_form'].reg_exp
.focus();});
961 if (keycode
== 76) { // l
966 if (keycode
== 83) { // s
967 if (typeof collapse_feedlist
!= 'undefined') {
973 if (keycode
== 77) { // m
974 // TODO: sortable feedlist
978 if (keycode
== 78) { // n
979 catchupRelativeToArticle(1);
983 if (keycode
== 80) { // p
984 catchupRelativeToArticle(0);
993 if (hotkey_prefix
== 71) { // g
995 hotkey_prefix
= false;
998 if (keycode
== 65) { // a
1003 if (keycode
== 83) { // s
1008 if (keycode
== 80 && shift_key
) { // P
1013 if (keycode
== 80) { // p
1018 if (keycode
== 70) { // f
1023 if (keycode
== 84 && shift_key
) { // T
1031 if (hotkey_prefix
== 224 || hotkey_prefix
== 91) { // f
1032 hotkey_prefix
= false;
1036 if (hotkey_prefix
) {
1037 console
.log("KP: PREFIX=" + hotkey_prefix
+ " CODE=" + keycode
+ " CHAR=" + keychar
);
1039 console
.log("KP: CODE=" + keycode
+ " CHAR=" + keychar
);
1044 exception_error("hotkey_handler", e
);
1048 function inPreferences() {
1052 function reverseHeadlineOrder() {
1055 var query_str
= "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1057 new Ajax
.Request("backend.php", {
1058 parameters
: query_str
,
1059 onComplete: function(transport
) {
1064 exception_error("reverseHeadlineOrder", e
);
1068 function showFeedsWithErrors() {
1069 displayDlg('feedUpdateErrors');
1072 function handle_rpc_reply(transport
, scheduled_call
) {
1074 if (transport
.responseXML
) {
1076 if (!transport_error_check(transport
)) return false;
1078 var seq
= transport
.responseXML
.getElementsByTagName("seq")[0];
1081 seq
= seq
.firstChild
.nodeValue
;
1083 if (get_seq() != seq
) {
1084 //console.log("[handle_rpc_reply] sequence mismatch: " + seq);
1089 var message
= transport
.responseXML
.getElementsByTagName("message")[0];
1092 message
= message
.firstChild
.nodeValue
;
1094 if (message
== "UPDATE_COUNTERS") {
1095 console
.log("need to refresh counters...");
1096 setInitParam("last_article_id", -1);
1097 _force_scheduled_update
= true;
1101 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
1104 parse_counters(counters
, scheduled_call
);
1106 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info")[0];
1109 parse_runtime_info(runtime_info
);
1111 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1114 notify_error("Error communicating with server.");
1118 exception_error("handle_rpc_reply", e
, transport
);
1124 function scheduleFeedUpdate(id
, is_cat
) {
1127 id
= getActiveFeedId();
1128 is_cat
= activeFeedIsCat();
1132 alert(__("Please select some feed first."));
1136 var query
= "?op=rpc&subop=scheduleFeedUpdate&id=" +
1138 "&is_cat=" + param_escape(is_cat
);
1142 new Ajax
.Request("backend.php", {
1144 onComplete: function(transport
) {
1146 if (transport
.responseXML
) {
1147 var message
= transport
.responseXML
.getElementsByTagName("message")[0];
1150 notify_info(message
.firstChild
.nodeValue
);
1155 notify_error("Error communicating with server.");
1161 exception_error("scheduleFeedUpdate", e
);