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