]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
hide empty content preview
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194
AD
1var xmlhttp = false;
2
76798ff3 3var total_unread = 0;
525116d4 4var first_run = true;
76798ff3 5
8143ae1f
AD
6var display_tags = false;
7
fc69e641
AD
8var global_unread = 0;
9
21703604
AD
10var active_title_text = "";
11
12var current_subtitle = "";
13
1cd17194
AD
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.
18try {
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
29if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
30 xmlhttp = new XMLHttpRequest();
31}
32
8143ae1f
AD
33function 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
6de5d056 47function dlg_frefresh_callback() {
1cd17194 48 if (xmlhttp.readyState == 4) {
e2f8f7b4 49 updateFeedList(false, false);
f84a97a3 50 closeDlg();
c0e5a40e 51 }
1cd17194 52}
e2f8f7b4 53
f84a97a3
AD
54function dialog_refresh_callback() {
55 if (xmlhttp.readyState == 4) {
56 var dlg = document.getElementById("userDlg");
76332f3c 57 var dlg_s = document.getElementById("userDlgShadow");
f84a97a3
AD
58
59 dlg.innerHTML = xmlhttp.responseText;
76332f3c 60 dlg_s.style.display = "block";
f84a97a3
AD
61 }
62}
1a66d16e 63
8158c57a 64function refetch_callback() {
29fb8c70 65 if (xmlhttp.readyState == 4) {
7719618b 66 try {
310da49d 67
7719618b
AD
68 if (!xmlhttp.responseXML) {
69 notify("refetch_callback: backend did not return valid XML");
70 return;
71 }
72
73 var reply = xmlhttp.responseXML.firstChild;
262bd8ea 74
7719618b
AD
75 if (!reply) {
76 notify("refetch_callback: backend did not return expected XML object");
77 return;
78 }
262bd8ea 79
7719618b
AD
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) {
8143ae1f 104
7719618b
AD
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", "");
8143ae1f 115 }
090e250b 116 }
7719618b
AD
117 }
118
119 updateTitle("");
120 notify("All feeds updated.");
121 } catch (e) {
122 exception_error("refetch_callback", e);
123 }
090e250b
AD
124 }
125}
1a66d16e 126
295f9b42
AD
127function backend_sanity_check_callback() {
128
129 if (xmlhttp.readyState == 4) {
295f9b42 130
7719618b
AD
131 try {
132
133 if (!xmlhttp.responseXML) {
134 fatalError(3);
135 return;
136 }
295f9b42 137
7719618b
AD
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();
295f9b42 152
7719618b
AD
153 } catch (e) {
154 exception_error("backend_sanity_check_callback", e);
155 }
295f9b42
AD
156 }
157}
158
cb246176 159function scheduleFeedUpdate(force) {
525116d4
AD
160
161 notify("Updating feeds in background...");
162
fc69e641
AD
163// document.title = "Tiny Tiny RSS - Updating...";
164
21703604 165 updateTitle("Updating");
55193822 166
cb246176
AD
167 var query_str = "backend.php?op=rpc&subop=";
168
169 if (force) {
c3b81db0 170 query_str = query_str + "forceUpdateAllFeeds";
cb246176 171 } else {
c3b81db0 172 query_str = query_str + "updateAllFeeds";
cb246176 173 }
525116d4 174
9826bd2e
AD
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
29fb8c70
AD
185 if (xmlhttp_ready(xmlhttp)) {
186 xmlhttp.open("GET", query_str, true);
187 xmlhttp.onreadystatechange=refetch_callback;
188 xmlhttp.send(null);
525116d4
AD
189 } else {
190 printLockingError();
c0e5a40e 191 }
525116d4 192}
1cd17194 193
525116d4 194function updateFeedList(silent, fetch) {
c0e5a40e 195
1a66d16e
AD
196// if (silent != true) {
197// notify("Loading feed list...");
198// }
82baad4a 199
331900c6
AD
200 var query_str = "backend.php?op=feeds";
201
8143ae1f
AD
202 if (display_tags) {
203 query_str = query_str + "&tags=1";
204 }
205
86741347
AD
206 if (getActiveFeedId()) {
207 query_str = query_str + "&actid=" + getActiveFeedId();
175847de
AD
208 }
209
1a66d16e 210 if (fetch) query_str = query_str + "&fetch=yes";
e1123aee 211
1a66d16e 212 var feeds_frame = document.getElementById("feeds-frame");
e1123aee 213
1a66d16e
AD
214 feeds_frame.src = query_str;
215}
175847de 216
476cac42 217function catchupAllFeeds() {
076682aa 218
476cac42
AD
219 var query_str = "backend.php?op=feeds&subop=catchupAll";
220
221 notify("Marking all feeds as read...");
222
1a66d16e
AD
223 var feeds_frame = document.getElementById("feeds-frame");
224
225 feeds_frame.src = query_str;
476cac42 226
fc69e641 227 global_unread = 0;
21703604 228 updateTitle("");
fc69e641 229
476cac42 230}
1cd17194 231
f0601b87 232function viewCurrentFeed(skip, subop) {
1a66d16e 233
86741347
AD
234 if (getActiveFeedId()) {
235 viewfeed(getActiveFeedId(), skip, subop);
033e47e0
AD
236 } else {
237 disableContainerChildren("headlinesToolbar", false, document);
238 viewfeed(-1, skip, subop); // FIXME
f0601b87
AD
239 }
240}
241
476cac42 242function viewfeed(feed, skip, subop) {
db8d6f67
AD
243 var f = window.frames["feeds-frame"];
244 f.viewfeed(feed, skip, subop);
9cfc649a
AD
245}
246
40d13c28 247function timeout() {
05732aa0 248 scheduleFeedUpdate(false);
ac53063a 249 setTimeout("timeout()", 1800*1000);
ac53063a
AD
250}
251
c374a3fe 252function resetSearch() {
64c620ce
AD
253 var searchbox = document.getElementById("searchbox")
254
86741347 255 if (searchbox.value != "" && getActiveFeedId()) {
64c620ce 256 searchbox.value = "";
86741347 257 viewfeed(getActiveFeedId(), 0, "");
ac43eba1 258 }
c374a3fe 259}
ac53063a 260
f0601b87 261function search() {
4ce19859 262 viewCurrentFeed(0, "");
76798ff3 263}
1cd17194 264
13ad9102
AD
265function localPiggieFunction(enable) {
266 if (enable) {
267 var query_str = "backend.php?op=feeds&subop=piggie";
268
c0e5a40e 269 if (xmlhttp_ready(xmlhttp)) {
13ad9102
AD
270
271 xmlhttp.open("GET", query_str, true);
272 xmlhttp.onreadystatechange=feedlist_callback;
273 xmlhttp.send(null);
274 }
275 }
276}
277
9cfc649a
AD
278function localHotkeyHandler(keycode) {
279
f0601b87 280/* if (keycode == 78) {
c3a8d71a 281 return moveToPost('next');
9cfc649a
AD
282 }
283
284 if (keycode == 80) {
c3a8d71a 285 return moveToPost('prev');
f0601b87 286 } */
c3a8d71a 287
b623b3ed 288 if (keycode == 82) { // r
c3a8d71a
AD
289 return scheduleFeedUpdate(true);
290 }
291
b623b3ed
AD
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();
c3a8d71a
AD
300 }
301
302// notify("KC: " + keycode);
303
9cfc649a
AD
304}
305
fc69e641
AD
306function updateTitle(s) {
307 var tmp = "Tiny Tiny RSS";
21703604
AD
308
309 if (s && s.length > 0) {
310 current_subtitle = s;
311 }
312
fc69e641
AD
313 if (global_unread > 0) {
314 tmp = tmp + " (" + global_unread + ")";
315 }
316
317 if (s) {
21703604 318 tmp = tmp + " - " + current_subtitle;
fc69e641 319 }
21703604
AD
320
321 if (active_title_text.length > 0) {
322 tmp = tmp + " > " + active_title_text;
323 }
324
fc69e641
AD
325 document.title = tmp;
326}
327
22a93ad8 328function genericSanityCheck() {
ac43eba1 329
295f9b42
AD
330 if (!xmlhttp) fatalError(1);
331
332 setCookie("ttrss_vf_test", "TEST");
333
334 if (getCookie("ttrss_vf_test") != "TEST") {
335 fatalError(2);
336 }
337
22a93ad8
AD
338 return true;
339}
340
341function init() {
342
7719618b 343 try {
fe2f1970 344
7719618b 345 disableContainerChildren("headlinesToolbar", true);
70830c87 346
7719618b
AD
347 if (!genericSanityCheck())
348 return;
ac43eba1 349
7719618b
AD
350 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
351 xmlhttp.onreadystatechange=backend_sanity_check_callback;
352 xmlhttp.send(null);
47179952 353
7719618b
AD
354 } catch (e) {
355 exception_error("init", e);
a8d28f48 356 }
7719618b 357}
86741347 358
7719618b 359function init_second_stage() {
295f9b42 360
7719618b 361 try {
2f587484 362
7719618b
AD
363 setCookie("ttrss_vf_actfeed", "");
364
365 updateFeedList(false, false);
366 document.onkeydown = hotkey_handler;
367
368 var content = document.getElementById("content");
369
370 if (getCookie("ttrss_vf_vmode")) {
371 var viewbox = document.getElementById("viewbox");
372 viewbox.value = getCookie("ttrss_vf_vmode");
373 }
374
375 if (getCookie("ttrss_vf_limit")) {
376 var limitbox = document.getElementById("limitbox");
377 limitbox.value = getCookie("ttrss_vf_limit");
378 }
379
380 // if (getCookie("ttrss_vf_actfeed")) {
381 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
382 // }
383
384 // setTimeout("timeout()", 2*1000);
385 // scheduleFeedUpdate(true);
386
7719618b
AD
387 } catch (e) {
388 exception_error("init_second_stage", e);
2f587484 389 }
1cd17194 390}
ac43eba1 391
e2f8f7b4 392function quickMenuGo() {
e2f8f7b4 393
cbe45fa8
AD
394 var chooser = document.getElementById("quickMenuChooser");
395 var opid = chooser[chooser.selectedIndex].id;
e2f8f7b4 396
cbe45fa8 397 if (opid == "qmcPrefs") {
e2f8f7b4
AD
398 gotoPreferences();
399 }
400
cbe45fa8 401 if (opid == "qmcAdvSearch") {
033e47e0
AD
402 displayDlg("search");
403 return;
404 }
405
cbe45fa8 406 if (opid == "qmcAddFeed") {
f84a97a3 407 displayDlg("quickAddFeed");
6de5d056
AD
408 return;
409 }
410
cbe45fa8 411 if (opid == "qmcRemoveFeed") {
6de5d056
AD
412 var actid = getActiveFeedId();
413
414 if (!actid) {
415 notify("Please select some feed first.");
416 return;
417 }
418
419 displayDlg("quickDelFeed", actid);
420 return;
e2f8f7b4 421 }
7a991cac 422
cbe45fa8 423 if (opid == "qmcUpdateFeeds") {
7a991cac
AD
424 scheduleFeedUpdate(true);
425 return;
426 }
427
cbe45fa8 428 if (opid == "qmcCatchupAll") {
7a991cac
AD
429 catchupAllFeeds();
430 return;
431 }
432
cbe45fa8 433 if (opid == "qmcShowOnlyUnread") {
7a991cac
AD
434 toggleDispRead();
435 return;
436 }
437
e2f8f7b4
AD
438}
439
440function qafAdd() {
ac43eba1 441
e2f8f7b4
AD
442 if (!xmlhttp_ready(xmlhttp)) {
443 printLockingError();
444 return
445 }
446
447 var link = document.getElementById("qafInput");
448
449 if (link.value.length == 0) {
450 notify("Missing feed URL.");
451 } else {
452 notify("Adding feed...");
453
454 var feeds_doc = window.frames["feeds-frame"].document;
455
456 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
457
458 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
459 param_escape(link.value), true);
6de5d056 460 xmlhttp.onreadystatechange=dlg_frefresh_callback;
e2f8f7b4
AD
461 xmlhttp.send(null);
462
463 link.value = "";
464
465 }
f84a97a3
AD
466}
467
6de5d056 468function displayDlg(id, param) {
e2f8f7b4 469
40d601c5
AD
470 notify("");
471
f84a97a3 472 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
6de5d056 473 param_escape(id) + "&param=" + param_escape(param), true);
f84a97a3
AD
474 xmlhttp.onreadystatechange=dialog_refresh_callback;
475 xmlhttp.send(null);
e2f8f7b4
AD
476
477}
f84a97a3
AD
478
479function closeDlg() {
76332f3c 480 var dlg = document.getElementById("userDlgShadow");
f84a97a3
AD
481 dlg.style.display = "none";
482}
483
6de5d056
AD
484function qfdDelete(feed_id) {
485
486 notify("Removing feed...");
487
488 var feeds_doc = window.frames["feeds-frame"].document;
489 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
490
491 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
492 xmlhttp.onreadystatechange=dlg_frefresh_callback;
493 xmlhttp.send(null);
6de5d056 494}
033e47e0 495
3745788e
AD
496
497function allFeedsMenuGo() {
498 var chooser = document.getElementById("allFeedsChooser");
499
500 var opname = chooser[chooser.selectedIndex].text;
501
502 if (opname == "Update") {
503 scheduleFeedUpdate(true);
504 return;
505 }
506
507 if (opname == "Mark as read") {
508 catchupAllFeeds();
509 return;
510 }
511
bdf7f1bc 512 if (opname == "Show only unread") {
3745788e
AD
513 toggleDispRead();
514 return;
515 }
516
517}
518
21703604
AD
519function updateFeedTitle(t) {
520 active_title_text = t;
521 updateTitle();
522}
523
3745788e
AD
524function toggleDispRead() {
525 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
526
527 hide_read_feeds = !hide_read_feeds;
528
529 var feeds_doc = window.frames["feeds-frame"].document;
530
531 hideOrShowFeeds(feeds_doc, hide_read_feeds);
532
533 if (hide_read_feeds) {
534 setCookie("ttrss_vf_hreadf", 1);
535 } else {
536 setCookie("ttrss_vf_hreadf", 0);
537 }
538
539}
295f9b42
AD
540
541