]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
j,k navigate between feeds
[tt-rss.git] / tt-rss.js
1 var xmlhttp = false;
2
3 var total_unread = 0;
4 var first_run = true;
5
6 var display_tags = false;
7
8 var global_unread = 0;
9
10 var active_title_text = "";
11
12 var current_subtitle = "";
13
14 /*@cc_on @*/
15 /*@if (@_jscript_version >= 5)
16 // JScript gives us Conditional compilation, we can cope with old IE versions.
17 // and security blocked creation of the objects.
18 try {
19 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
20 } catch (e) {
21 try {
22 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
23 } catch (E) {
24 xmlhttp = false;
25 }
26 }
27 @end @*/
28
29 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
30 xmlhttp = new XMLHttpRequest();
31 }
32
33 function toggleTags() {
34 display_tags = !display_tags;
35
36 var p = document.getElementById("dispSwitchPrompt");
37
38 if (display_tags) {
39 p.innerHTML = "display feeds";
40 } else {
41 p.innerHTML = "display tags";
42 }
43
44 updateFeedList();
45 }
46
47 function dlg_frefresh_callback() {
48 if (xmlhttp.readyState == 4) {
49 updateFeedList(false, false);
50 closeDlg();
51 }
52 }
53
54 function dialog_refresh_callback() {
55 if (xmlhttp.readyState == 4) {
56 var dlg = document.getElementById("userDlg");
57 var dlg_s = document.getElementById("userDlgShadow");
58
59 dlg.innerHTML = xmlhttp.responseText;
60 dlg_s.style.display = "block";
61 }
62 }
63
64 function refetch_callback() {
65 if (xmlhttp.readyState == 4) {
66 try {
67
68 if (!xmlhttp.responseXML) {
69 notify("refetch_callback: backend did not return valid XML");
70 return;
71 }
72
73 var reply = xmlhttp.responseXML.firstChild;
74
75 if (!reply) {
76 notify("refetch_callback: backend did not return expected XML object");
77 return;
78 }
79
80 var error_code = reply.getAttribute("error-code");
81
82 if (error_code && error_code != 0) {
83 return fatalError(error_code);
84 }
85
86 var f_document = window.frames["feeds-frame"].document;
87
88 for (var l = 0; l < reply.childNodes.length; l++) {
89 var id = reply.childNodes[l].getAttribute("id");
90 var ctr = reply.childNodes[l].getAttribute("counter");
91
92 var feedctr = f_document.getElementById("FEEDCTR-" + id);
93 var feedu = f_document.getElementById("FEEDU-" + id);
94 var feedr = f_document.getElementById("FEEDR-" + id);
95
96 /* TODO figure out how to update this from viewfeed.js->view()
97 disabled for now...
98
99 if (id == "global-unread") {
100 global_unread = ctr;
101 } */
102
103 if (feedctr && feedu && feedr) {
104
105 feedu.innerHTML = ctr;
106
107 if (ctr > 0) {
108 feedctr.className = "odd";
109 if (!feedr.className.match("Unread")) {
110 feedr.className = feedr.className + "Unread";
111 }
112 } else {
113 feedctr.className = "invisible";
114 feedr.className = feedr.className.replace("Unread", "");
115 }
116 }
117 }
118
119 updateTitle("");
120 notify("All feeds updated.");
121 } catch (e) {
122 exception_error("refetch_callback", e);
123 }
124 }
125 }
126
127 function backend_sanity_check_callback() {
128
129 if (xmlhttp.readyState == 4) {
130
131 try {
132
133 if (!xmlhttp.responseXML) {
134 fatalError(3);
135 return;
136 }
137
138 var reply = xmlhttp.responseXML.firstChild;
139
140 if (!reply) {
141 fatalError(3);
142 return;
143 }
144
145 var error_code = reply.getAttribute("error-code");
146
147 if (error_code && error_code != 0) {
148 return fatalError(error_code);
149 }
150
151 init_second_stage();
152
153 } catch (e) {
154 exception_error("backend_sanity_check_callback", e);
155 }
156 }
157 }
158
159 function scheduleFeedUpdate(force) {
160
161 notify("Updating feeds in background...");
162
163 // document.title = "Tiny Tiny RSS - Updating...";
164
165 updateTitle("Updating");
166
167 var query_str = "backend.php?op=rpc&subop=";
168
169 if (force) {
170 query_str = query_str + "forceUpdateAllFeeds";
171 } else {
172 query_str = query_str + "updateAllFeeds";
173 }
174
175 var omode;
176
177 if (display_tags) {
178 omode = "t";
179 } else {
180 omode = "fl";
181 }
182
183 query_str = query_str + "&omode=" + omode;
184
185 if (xmlhttp_ready(xmlhttp)) {
186 xmlhttp.open("GET", query_str, true);
187 xmlhttp.onreadystatechange=refetch_callback;
188 xmlhttp.send(null);
189 } else {
190 printLockingError();
191 }
192 }
193
194 function updateFeedList(silent, fetch) {
195
196 // if (silent != true) {
197 // notify("Loading feed list...");
198 // }
199
200 var query_str = "backend.php?op=feeds";
201
202 if (display_tags) {
203 query_str = query_str + "&tags=1";
204 }
205
206 if (getActiveFeedId()) {
207 query_str = query_str + "&actid=" + getActiveFeedId();
208 }
209
210 if (fetch) query_str = query_str + "&fetch=yes";
211
212 var feeds_frame = document.getElementById("feeds-frame");
213
214 feeds_frame.src = query_str;
215 }
216
217 function catchupAllFeeds() {
218
219 var query_str = "backend.php?op=feeds&subop=catchupAll";
220
221 notify("Marking all feeds as read...");
222
223 var feeds_frame = document.getElementById("feeds-frame");
224
225 feeds_frame.src = query_str;
226
227 global_unread = 0;
228 updateTitle("");
229
230 }
231
232 function viewCurrentFeed(skip, subop) {
233
234 if (getActiveFeedId()) {
235 viewfeed(getActiveFeedId(), skip, subop);
236 } else {
237 disableContainerChildren("headlinesToolbar", false, document);
238 viewfeed(-1, skip, subop); // FIXME
239 }
240 }
241
242 function viewfeed(feed, skip, subop) {
243 var f = window.frames["feeds-frame"];
244 f.viewfeed(feed, skip, subop);
245 }
246
247 function timeout() {
248 scheduleFeedUpdate(false);
249 setTimeout("timeout()", 1800*1000);
250 }
251
252 function resetSearch() {
253 var searchbox = document.getElementById("searchbox")
254
255 if (searchbox.value != "" && getActiveFeedId()) {
256 searchbox.value = "";
257 viewfeed(getActiveFeedId(), 0, "");
258 }
259 }
260
261 function search() {
262 viewCurrentFeed(0, "");
263 }
264
265 function localPiggieFunction(enable) {
266 if (enable) {
267 var query_str = "backend.php?op=feeds&subop=piggie";
268
269 if (xmlhttp_ready(xmlhttp)) {
270
271 xmlhttp.open("GET", query_str, true);
272 xmlhttp.onreadystatechange=feedlist_callback;
273 xmlhttp.send(null);
274 }
275 }
276 }
277
278 function localHotkeyHandler(keycode) {
279
280 /* if (keycode == 78) {
281 return moveToPost('next');
282 }
283
284 if (keycode == 80) {
285 return moveToPost('prev');
286 } */
287
288 if (keycode == 82) { // r
289 return scheduleFeedUpdate(true);
290 }
291
292 if (keycode == 85) { // u
293 if (getActiveFeedId()) {
294 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
295 }
296 }
297
298 if (keycode == 65) { // a
299 return toggleDispRead();
300 }
301
302 var f_doc = window.frames["feeds-frame"].document;
303 var feedlist = f_doc.getElementById('feedList');
304
305 if (keycode == 74) { // j
306 var feed = getActiveFeedId();
307 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
308 if (new_feed) viewfeed(new_feed, 0, '');
309 }
310
311 if (keycode == 75) { // k
312 var feed = getActiveFeedId();
313 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
314 if (new_feed) viewfeed(new_feed, 0, '');
315 }
316
317 // notify("KC: " + keycode);
318
319 }
320
321 function updateTitle(s) {
322 var tmp = "Tiny Tiny RSS";
323
324 if (s && s.length > 0) {
325 current_subtitle = s;
326 }
327
328 if (global_unread > 0) {
329 tmp = tmp + " (" + global_unread + ")";
330 }
331
332 if (s) {
333 tmp = tmp + " - " + current_subtitle;
334 }
335
336 if (active_title_text.length > 0) {
337 tmp = tmp + " > " + active_title_text;
338 }
339
340 document.title = tmp;
341 }
342
343 function genericSanityCheck() {
344
345 if (!xmlhttp) fatalError(1);
346
347 setCookie("ttrss_vf_test", "TEST");
348
349 if (getCookie("ttrss_vf_test") != "TEST") {
350 fatalError(2);
351 }
352
353 return true;
354 }
355
356 function init() {
357
358 try {
359
360 disableContainerChildren("headlinesToolbar", true);
361
362 if (!genericSanityCheck())
363 return;
364
365 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
366 xmlhttp.onreadystatechange=backend_sanity_check_callback;
367 xmlhttp.send(null);
368
369 } catch (e) {
370 exception_error("init", e);
371 }
372 }
373
374 function init_second_stage() {
375
376 try {
377
378 setCookie("ttrss_vf_actfeed", "");
379
380 updateFeedList(false, false);
381 document.onkeydown = hotkey_handler;
382
383 var content = document.getElementById("content");
384
385 if (getCookie("ttrss_vf_vmode")) {
386 var viewbox = document.getElementById("viewbox");
387 viewbox.value = getCookie("ttrss_vf_vmode");
388 }
389
390 if (getCookie("ttrss_vf_limit")) {
391 var limitbox = document.getElementById("limitbox");
392 limitbox.value = getCookie("ttrss_vf_limit");
393 }
394
395 // if (getCookie("ttrss_vf_actfeed")) {
396 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
397 // }
398
399 // setTimeout("timeout()", 2*1000);
400 // scheduleFeedUpdate(true);
401
402 } catch (e) {
403 exception_error("init_second_stage", e);
404 }
405 }
406
407 function quickMenuGo() {
408
409 var chooser = document.getElementById("quickMenuChooser");
410 var opid = chooser[chooser.selectedIndex].id;
411
412 if (opid == "qmcPrefs") {
413 gotoPreferences();
414 }
415
416 if (opid == "qmcAdvSearch") {
417 displayDlg("search");
418 return;
419 }
420
421 if (opid == "qmcAddFeed") {
422 displayDlg("quickAddFeed");
423 return;
424 }
425
426 if (opid == "qmcRemoveFeed") {
427 var actid = getActiveFeedId();
428
429 if (!actid) {
430 notify("Please select some feed first.");
431 return;
432 }
433
434 displayDlg("quickDelFeed", actid);
435 return;
436 }
437
438 if (opid == "qmcUpdateFeeds") {
439 scheduleFeedUpdate(true);
440 return;
441 }
442
443 if (opid == "qmcCatchupAll") {
444 catchupAllFeeds();
445 return;
446 }
447
448 if (opid == "qmcShowOnlyUnread") {
449 toggleDispRead();
450 return;
451 }
452
453 }
454
455 function qafAdd() {
456
457 if (!xmlhttp_ready(xmlhttp)) {
458 printLockingError();
459 return
460 }
461
462 var link = document.getElementById("qafInput");
463
464 if (link.value.length == 0) {
465 notify("Missing feed URL.");
466 } else {
467 notify("Adding feed...");
468
469 var feeds_doc = window.frames["feeds-frame"].document;
470
471 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
472
473 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
474 param_escape(link.value), true);
475 xmlhttp.onreadystatechange=dlg_frefresh_callback;
476 xmlhttp.send(null);
477
478 link.value = "";
479
480 }
481 }
482
483 function displayDlg(id, param) {
484
485 notify("");
486
487 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
488 param_escape(id) + "&param=" + param_escape(param), true);
489 xmlhttp.onreadystatechange=dialog_refresh_callback;
490 xmlhttp.send(null);
491
492 }
493
494 function closeDlg() {
495 var dlg = document.getElementById("userDlgShadow");
496 dlg.style.display = "none";
497 }
498
499 function qfdDelete(feed_id) {
500
501 notify("Removing feed...");
502
503 var feeds_doc = window.frames["feeds-frame"].document;
504 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
505
506 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
507 xmlhttp.onreadystatechange=dlg_frefresh_callback;
508 xmlhttp.send(null);
509 }
510
511
512 function allFeedsMenuGo() {
513 var chooser = document.getElementById("allFeedsChooser");
514
515 var opname = chooser[chooser.selectedIndex].text;
516
517 if (opname == "Update") {
518 scheduleFeedUpdate(true);
519 return;
520 }
521
522 if (opname == "Mark as read") {
523 catchupAllFeeds();
524 return;
525 }
526
527 if (opname == "Show only unread") {
528 toggleDispRead();
529 return;
530 }
531
532 }
533
534 function updateFeedTitle(t) {
535 active_title_text = t;
536 updateTitle();
537 }
538
539 function toggleDispRead() {
540 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
541
542 hide_read_feeds = !hide_read_feeds;
543
544 var feeds_doc = window.frames["feeds-frame"].document;
545
546 hideOrShowFeeds(feeds_doc, hide_read_feeds);
547
548 if (hide_read_feeds) {
549 setCookie("ttrss_vf_hreadf", 1);
550 } else {
551 setCookie("ttrss_vf_hreadf", 0);
552 }
553
554 }
555
556