]>
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 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({
90 onOpen: 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&subop=collapse&cid=" +
96 param_escape(cat_id
) + "&mode=0" } );
98 onClose: function (item
, node
) {
99 var id
= String(item
.id
);
100 var cat_id
= id
.substr(id
.indexOf(":")+1);
102 new Ajax
.Request("backend.php",
103 { parameters
: "backend.php?op=feeds&subop=collapse&cid=" +
104 param_escape(cat_id
) + "&mode=1" } );
107 onClick: function (item
, node
) {
108 var id
= String(item
.id
);
109 var is_cat
= id
.match("^CAT:");
110 var feed
= id
.substr(id
.indexOf(":")+1);
111 viewfeed(feed
, '', is_cat
);
119 /* var menu = new dijit.Menu({id: 'feedMenu'});
121 menu.addChild(new dijit.MenuItem({
122 label: "Simple menu item"
125 // menu.bindDomNode(tree.domNode); */
127 var tmph
= dojo
.connect(dijit
.byId('feedMenu'), '_openMyself', function (event
) {
128 console
.log(dijit
.getEnclosingWidget(event
.target
));
129 dojo
.disconnect(tmph
);
132 $("feeds-holder").appendChild(tree
.domNode
);
134 var tmph
= dojo
.connect(tree
, 'onLoad', function() {
135 dojo
.disconnect(tmph
);
136 Element
.hide("feedlistLoading");
138 tree
.collapseHiddenCats();
142 // var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
143 // menu.bindDomNode(node);
145 loading_set_progress(25);
151 exception_error("updateFeedList", e
);
155 function catchupAllFeeds() {
157 var str
= __("Mark all articles as read?");
159 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
161 var query_str
= "backend.php?op=feeds&subop=catchupAll";
163 notify_progress("Marking all feeds as read...");
165 //console.log("catchupAllFeeds Q=" + query_str);
167 new Ajax
.Request("backend.php", {
168 parameters
: query_str
,
169 onComplete: function(transport
) {
170 feedlist_callback2(transport
);
178 function viewCurrentFeed(subop
) {
180 if (getActiveFeedId() != undefined) {
181 viewfeed(getActiveFeedId(), subop
, activeFeedIsCat());
183 return false; // block unneeded form submits
187 if (getInitParam("bw_limit") == "1") return;
190 var date
= new Date();
191 var ts
= Math
.round(date
.getTime() / 1000);
193 if (ts
- last_scheduled_update
> 10 || _force_scheduled_update
) {
195 //console.log("timeout()");
197 window
.clearTimeout(counter_timeout_id
);
199 var query_str
= "?op=rpc&subop=getAllCounters&seq=" + next_seq();
203 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
204 firsttime_update
= false;
210 query_str
= query_str
+ "&omode=" + omode
;
212 if (!_force_scheduled_update
)
213 query_str
= query_str
+ "&last_article_id=" + getInitParam("last_article_id");
215 //console.log("[timeout]" + query_str);
217 new Ajax
.Request("backend.php", {
218 parameters
: query_str
,
219 onComplete: function(transport
) {
220 handle_rpc_reply(transport
, !_force_scheduled_update
);
221 _force_scheduled_update
= false;
224 last_scheduled_update
= ts
;
228 exception_error("timeout", e
);
231 setTimeout("timeout()", 3000);
235 var query
= "backend.php?op=dlg&id=search¶m=" +
236 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
238 if (dijit
.byId("searchDlg"))
239 dijit
.byId("searchDlg").destroyRecursive();
241 dialog
= new dijit
.Dialog({
244 style
: "width: 600px",
245 execute: function() {
246 if (this.validate()) {
247 _search_query
= dojo
.objectToQuery(this.attr('value'));
257 function updateTitle() {
258 var tmp
= "Tiny Tiny RSS";
260 if (global_unread
> 0) {
261 tmp
= tmp
+ " (" + global_unread
+ ")";
265 if (global_unread
> 0) {
266 window
.fluid
.dockBadge
= global_unread
;
268 window
.fluid
.dockBadge
= "";
272 document
.title
= tmp
;
275 function genericSanityCheck() {
276 setCookie("ttrss_test", "TEST");
278 if (getCookie("ttrss_test") != "TEST") {
287 //Form.disable("main_toolbar_form");
289 dojo
.require("dijit.layout.BorderContainer");
290 dojo
.require("dijit.layout.TabContainer");
291 dojo
.require("dijit.layout.ContentPane");
292 dojo
.require("dijit.Dialog");
293 dojo
.require("dijit.form.Button");
294 dojo
.require("dijit.Menu");
295 dojo
.require("dojo.data.ItemFileWriteStore");
296 dojo
.require("dijit.Tree");
297 dojo
.require("dijit.form.Select");
298 dojo
.require("dijit.form.TextBox");
299 dojo
.require("dijit.form.ValidationTextBox");
300 dojo
.require("dijit.form.FilteringSelect");
301 dojo
.require("dijit.form.CheckBox");
302 dojo
.require("dijit.form.SimpleTextarea");
303 dojo
.require("dijit.Toolbar");
304 dojo
.require("dijit.ProgressBar");
305 dojo
.require("dijit.Menu");
306 dojo
.require("dojo.parser");
308 dojo
.registerModulePath("fox", "../..");
310 dojo
.require("fox.FeedTree");
312 if (typeof themeBeforeLayout
== 'function') {
316 dojo
.addOnLoad(function() {
320 if (typeof themeAfterLayout
== 'function') {
326 if (!genericSanityCheck())
329 loading_set_progress(20);
331 new Ajax
.Request("backend.php", {
332 parameters
: {op
: "rpc", subop
: "sanityCheck"},
333 onComplete: function(transport
) {
334 backend_sanity_check_callback(transport
);
338 exception_error("init", e
);
342 function init_second_stage() {
346 delCookie("ttrss_test");
348 var toolbar
= document
.forms
["main_toolbar_form"];
350 dijit
.getEnclosingWidget(toolbar
.view_mode
).attr('value',
351 getInitParam("default_view_mode"));
353 dijit
.getEnclosingWidget(toolbar
.order_by
).attr('value',
354 getInitParam("default_view_order_by"));
356 feeds_sort_by_unread
= getInitParam("feeds_sort_by_unread") == 1;
358 loading_set_progress(30);
360 if (has_local_storage())
361 sessionStorage
.clear();
363 console
.log("second stage ok");
366 exception_error("init_second_stage", e
);
370 function quickMenuChange(elem
) {
371 quickMenuGo(elem
.value
);
372 elem
.attr('value', 'qmcDefault');
375 function quickMenuGo(opid
) {
378 if (opid
== "qmcPrefs") {
382 if (opid
== "qmcTagCloud") {
383 displayDlg("printTagCloud");
386 if (opid
== "qmcSearch") {
391 if (opid
== "qmcAddFeed") {
396 if (opid
== "qmcEditFeed") {
397 if (activeFeedIsCat())
398 alert(__("You can't edit this kind of feed."));
400 editFeed(getActiveFeedId());
404 if (opid
== "qmcRemoveFeed") {
405 var actid
= getActiveFeedId();
407 if (activeFeedIsCat()) {
408 alert(__("You can't unsubscribe from the category."));
413 alert(__("Please select some feed first."));
417 var fn
= getFeedName(actid
);
419 var pr
= __("Unsubscribe from %s?").replace("%s", fn
);
422 unsubscribeFeed(actid
);
428 if (opid
== "qmcCatchupAll") {
433 if (opid
== "qmcShowOnlyUnread") {
438 if (opid
== "qmcAddFilter") {
443 if (opid
== "qmcAddLabel") {
448 if (opid
== "qmcRescoreFeed") {
449 rescoreCurrentFeed();
453 if (opid
== "qmcHKhelp") {
454 //Element.show("hotkey_help_overlay");
455 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
459 exception_error("quickMenuGo", e
);
463 function toggleDispRead() {
466 var hide
= !(getInitParam("hide_read_feeds") == "1");
468 hideOrShowFeeds(hide
);
470 var query
= "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" +
473 setInitParam("hide_read_feeds", hide
);
475 new Ajax
.Request("backend.php", {
477 onComplete: function(transport
) {
481 exception_error("toggleDispRead", e
);
485 function parse_runtime_info(elem
) {
487 if (!elem
|| !elem
.firstChild
) {
488 console
.warn("parse_runtime_info: invalid node passed");
492 var data
= JSON
.parse(elem
.firstChild
.nodeValue
);
494 //console.log("parsing runtime info...");
499 // console.log("RI: " + k + " => " + v);
501 if (k
== "new_version_available") {
502 var icon
= $("newVersionIcon");
505 icon
.style
.display
= "inline";
507 icon
.style
.display
= "none";
515 if (k
== "daemon_is_running" && v
!= 1) {
516 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
520 if (k
== "daemon_stamp_ok" && v
!= 1) {
521 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
530 function catchupCurrentFeed() {
532 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
534 var str
= __("Mark all articles in %s as read?").replace("%s", fn
);
536 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
537 return viewCurrentFeed('MarkAllRead')
541 function catchupFeedInGroup(id
) {
545 var title
= getFeedName(id
);
547 var str
= __("Mark all articles in %s as read?").replace("%s", title
);
549 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str
)) {
550 return viewCurrentFeed('MarkAllReadGR:' + id
)
554 exception_error("catchupFeedInGroup", e
);
558 function collapse_feedlist() {
561 if (!Element
.visible('feeds-holder')) {
562 Element
.show('feeds-holder');
563 $("collapse_feeds_btn").innerHTML
= "<<";
565 Element
.hide('feeds-holder');
566 $("collapse_feeds_btn").innerHTML
= ">>";
569 dijit
.byId("main").resize();
571 query
= "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
572 new Ajax
.Request("backend.php", { parameters
: query
});
575 exception_error("collapse_feedlist", e
);
579 function viewModeChanged() {
581 return viewCurrentFeed('')
584 function viewLimitChanged() {
586 return viewCurrentFeed('')
589 /* function adjustArticleScore(id, score) {
592 var pr = prompt(__("Assign score to article:"), score);
594 if (pr != undefined) {
595 var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
597 new Ajax.Request("backend.php", {
599 onComplete: function(transport) {
605 exception_error("adjustArticleScore", e);
609 function rescoreCurrentFeed() {
611 var actid
= getActiveFeedId();
613 if (activeFeedIsCat() || actid
< 0) {
614 alert(__("You can't rescore this kind of feed."));
619 alert(__("Please select some feed first."));
623 var fn
= getFeedName(actid
);
624 var pr
= __("Rescore articles in %s?").replace("%s", fn
);
627 notify_progress("Rescoring articles...");
629 var query
= "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid
;
631 new Ajax
.Request("backend.php", {
633 onComplete: function(transport
) {
639 function hotkey_handler(e
) {
642 if (e
.target
.nodeName
== "INPUT") return;
645 var shift_key
= false;
647 var cmdline
= $('cmdline');
650 shift_key
= e
.shiftKey
;
656 keycode
= window
.event
.keyCode
;
661 var keychar
= String
.fromCharCode(keycode
);
663 if (keycode
== 27) { // escape
664 if (Element
.visible("hotkey_help_overlay")) {
665 Element
.hide("hotkey_help_overlay");
667 hotkey_prefix
= false;
671 if (keycode
== 16) return; // ignore lone shift
672 if (keycode
== 17) return; // ignore lone ctrl
674 if ((keycode
== 70 || keycode
== 67 || keycode
== 71)
677 var date
= new Date();
678 var ts
= Math
.round(date
.getTime() / 1000);
680 hotkey_prefix
= keycode
;
681 hotkey_prefix_pressed
= ts
;
683 cmdline
.innerHTML
= keychar
;
684 Element
.show(cmdline
);
686 console
.log("KP: PREFIX=" + keycode
+ " CHAR=" + keychar
+ " TS=" + ts
);
690 if (Element
.visible("hotkey_help_overlay")) {
691 Element
.hide("hotkey_help_overlay");
696 Element
.hide(cmdline
);
698 if (!hotkey_prefix
) {
700 if ((keycode
== 191 || keychar
== '?') && shift_key
) { // ?
701 if (!Element
.visible("hotkey_help_overlay")) {
702 Effect
.Appear("hotkey_help_overlay", {duration
: 0.3});
704 Element
.hide("hotkey_help_overlay");
709 if (keycode
== 191 || keychar
== '/') { // /
714 if (keycode
== 74) { // j
715 // TODO: move to previous feed
719 if (keycode
== 75) { // k
720 // TODO: move to next feed
724 if (shift_key
&& keycode
== 40) { // shift-down
725 catchupRelativeToArticle(1);
729 if (shift_key
&& keycode
== 38) { // shift-up
730 catchupRelativeToArticle(0);
734 if (shift_key
&& keycode
== 78) { // N
739 if (shift_key
&& keycode
== 80) { // P
744 if (keycode
== 68 && shift_key
) { // shift-D
745 dismissSelectedArticles();
748 if (keycode
== 88 && shift_key
) { // shift-X
749 dismissReadArticles();
752 if (keycode
== 78 || keycode
== 40) { // n, down
753 if (typeof moveToPost
!= 'undefined') {
759 if (keycode
== 80 || keycode
== 38) { // p, up
760 if (typeof moveToPost
!= 'undefined') {
766 if (keycode
== 83 && shift_key
) { // S
767 selectionTogglePublished(undefined, false, true);
771 if (keycode
== 83) { // s
772 selectionToggleMarked(undefined, false, true);
777 if (keycode
== 85) { // u
778 selectionToggleUnread(undefined, false, true)
782 if (keycode
== 84 && shift_key
) { // T
783 var id
= getActiveArticleId();
785 editArticleTags(id
, getActiveFeedId(), isCdmMode());
790 if (keycode
== 9) { // tab
791 var id
= getArticleUnderPointer();
793 var cb
= $("RCHK-" + id
);
796 cb
.checked
= !cb
.checked
;
797 toggleSelectRowById(cb
, "RROW-" + id
);
803 if (keycode
== 79) { // o
804 if (getActiveArticleId()) {
805 openArticleInNewWindow(getActiveArticleId());
810 if (keycode
== 81 && shift_key
) { // Q
811 if (typeof catchupAllFeeds
!= 'undefined') {
817 if (keycode
== 88) { // x
818 if (activeFeedIsCat()) {
819 toggleCollapseCat(getActiveFeedId());
826 if (hotkey_prefix
== 70) { // f
828 hotkey_prefix
= false;
830 if (keycode
== 81) { // q
831 if (getActiveFeedId()) {
832 catchupCurrentFeed();
837 if (keycode
== 82) { // r
838 if (getActiveFeedId()) {
839 viewfeed(getActiveFeedId(), "ForceUpdate", activeFeedIsCat());
844 if (keycode
== 65) { // a
849 if (keycode
== 85) { // u
850 if (getActiveFeedId()) {
851 viewfeed(getActiveFeedId(), "ForceUpdate");
856 if (keycode
== 69) { // e
858 if (activeFeedIsCat())
859 alert(__("You can't edit this kind of feed."));
861 editFeed(getActiveFeedId());
867 if (keycode
== 83) { // s
872 if (keycode
== 67 && shift_key
) { // C
873 if (typeof catchupAllFeeds
!= 'undefined') {
879 if (keycode
== 67) { // c
880 if (getActiveFeedId()) {
881 catchupCurrentFeed();
886 if (keycode
== 87) { // w
887 feeds_sort_by_unread
= !feeds_sort_by_unread
;
888 return resort_feedlist();
891 if (keycode
== 88) { // x
892 reverseHeadlineOrder();
899 if (hotkey_prefix
== 67) { // c
900 hotkey_prefix
= false;
902 if (keycode
== 70) { // f
907 if (keycode
== 76) { // l
912 if (keycode
== 83) { // s
913 if (typeof collapse_feedlist
!= 'undefined') {
919 if (keycode
== 77) { // m
920 // TODO: sortable feedlist
924 if (keycode
== 78) { // n
925 catchupRelativeToArticle(1);
929 if (keycode
== 80) { // p
930 catchupRelativeToArticle(0);
939 if (hotkey_prefix
== 71) { // g
941 hotkey_prefix
= false;
944 if (keycode
== 65) { // a
949 if (keycode
== 83) { // s
954 if (keycode
== 80 && shift_key
) { // P
959 if (keycode
== 80) { // p
964 if (keycode
== 70) { // f
969 if (keycode
== 84 && shift_key
) { // T
977 if (hotkey_prefix
== 224 || hotkey_prefix
== 91) { // f
978 hotkey_prefix
= false;
983 console
.log("KP: PREFIX=" + hotkey_prefix
+ " CODE=" + keycode
+ " CHAR=" + keychar
);
985 console
.log("KP: CODE=" + keycode
+ " CHAR=" + keychar
);
990 exception_error("hotkey_handler", e
);
994 function inPreferences() {
998 function reverseHeadlineOrder() {
1001 var query_str
= "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1003 new Ajax
.Request("backend.php", {
1004 parameters
: query_str
,
1005 onComplete: function(transport
) {
1010 exception_error("reverseHeadlineOrder", e
);
1014 function showFeedsWithErrors() {
1015 displayDlg('feedUpdateErrors');
1018 function handle_rpc_reply(transport
, scheduled_call
) {
1020 if (transport
.responseXML
) {
1022 if (!transport_error_check(transport
)) return false;
1024 var seq
= transport
.responseXML
.getElementsByTagName("seq")[0];
1027 seq
= seq
.firstChild
.nodeValue
;
1029 if (get_seq() != seq
) {
1030 //console.log("[handle_rpc_reply] sequence mismatch: " + seq);
1035 var message
= transport
.responseXML
.getElementsByTagName("message")[0];
1038 message
= message
.firstChild
.nodeValue
;
1040 if (message
== "UPDATE_COUNTERS") {
1041 console
.log("need to refresh counters...");
1042 setInitParam("last_article_id", -1);
1043 _force_scheduled_update
= true;
1047 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
1050 parse_counters(counters
, scheduled_call
);
1052 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info")[0];
1055 parse_runtime_info(runtime_info
);
1057 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1060 notify_error("Error communicating with server.");
1064 exception_error("handle_rpc_reply", e
, transport
);
1070 function scheduleFeedUpdate(id
, is_cat
) {
1073 id
= getActiveFeedId();
1074 is_cat
= activeFeedIsCat();
1078 alert(__("Please select some feed first."));
1082 var query
= "?op=rpc&subop=scheduleFeedUpdate&id=" +
1084 "&is_cat=" + param_escape(is_cat
);
1088 new Ajax
.Request("backend.php", {
1090 onComplete: function(transport
) {
1092 if (transport
.responseXML
) {
1093 var message
= transport
.responseXML
.getElementsByTagName("message")[0];
1096 notify_info(message
.firstChild
.nodeValue
);
1101 notify_error("Error communicating with server.");
1107 exception_error("scheduleFeedUpdate", e
);
1111 function newVersionDlg() {
1113 var query
= "backend.php?op=dlg&id=newVersion";
1115 if (dijit
.byId("newVersionDlg"))
1116 dijit
.byId("newVersionDlg").destroyRecursive();
1118 dialog
= new dijit
.Dialog({
1119 id
: "newVersionDlg",
1120 title
: __("New version available!"),
1121 style
: "width: 600px",
1128 exception_error("newVersionDlg", e
);