]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
hide postHeader padding from IE
[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 refetch_callback() {
76 if (xmlhttp.readyState == 4) {
77 try {
78
79 if (!xmlhttp.responseXML) {
80 notify("refetch_callback: backend did not return valid XML");
81 return;
82 }
83
84 var reply = xmlhttp.responseXML.firstChild;
85
86 if (!reply) {
87 notify("refetch_callback: backend did not return expected XML object");
88 return;
89 }
90
91 var error_code = reply.getAttribute("error-code");
92
93 if (error_code && error_code != 0) {
94 return fatalError(error_code);
95 }
96
97 var f_document = window.frames["feeds-frame"].document;
98
99 parse_counters(reply, f_document);
100
101 updateTitle("");
102 notify("All feeds updated.");
103 } catch (e) {
104 exception_error("refetch_callback", e);
105 }
106 }
107 }
108
109 function backend_sanity_check_callback() {
110
111 if (xmlhttp.readyState == 4) {
112
113 try {
114
115 if (!xmlhttp.responseXML) {
116 fatalError(3);
117 return;
118 }
119
120 var reply = xmlhttp.responseXML.firstChild;
121
122 if (!reply) {
123 fatalError(3);
124 return;
125 }
126
127 var error_code = reply.getAttribute("error-code");
128
129 if (error_code && error_code != 0) {
130 return fatalError(error_code);
131 }
132
133 init_second_stage();
134
135 } catch (e) {
136 exception_error("backend_sanity_check_callback", e);
137 }
138 }
139 }
140
141 function scheduleFeedUpdate(force) {
142
143 notify("Updating feeds in background...");
144
145 // document.title = "Tiny Tiny RSS - Updating...";
146
147 updateTitle("Updating");
148
149 var query_str = "backend.php?op=rpc&subop=";
150
151 if (force) {
152 query_str = query_str + "forceUpdateAllFeeds";
153 } else {
154 query_str = query_str + "updateAllFeeds";
155 }
156
157 var omode;
158
159 if (display_tags) {
160 omode = "t";
161 } else {
162 omode = "fl";
163 }
164
165 query_str = query_str + "&omode=" + omode;
166
167 if (xmlhttp_ready(xmlhttp)) {
168 xmlhttp.open("GET", query_str, true);
169 xmlhttp.onreadystatechange=refetch_callback;
170 xmlhttp.send(null);
171 } else {
172 printLockingError();
173 }
174 }
175
176 function updateFeedList(silent, fetch) {
177
178 // if (silent != true) {
179 // notify("Loading feed list...");
180 // }
181
182 var query_str = "backend.php?op=feeds";
183
184 if (display_tags) {
185 query_str = query_str + "&tags=1";
186 }
187
188 if (getActiveFeedId()) {
189 query_str = query_str + "&actid=" + getActiveFeedId();
190 }
191
192 if (fetch) query_str = query_str + "&fetch=yes";
193
194 var feeds_frame = document.getElementById("feeds-frame");
195
196 feeds_frame.src = query_str;
197 }
198
199 function catchupAllFeeds() {
200
201 var query_str = "backend.php?op=feeds&subop=catchupAll";
202
203 notify("Marking all feeds as read...");
204
205 var feeds_frame = document.getElementById("feeds-frame");
206
207 feeds_frame.src = query_str;
208
209 global_unread = 0;
210 updateTitle("");
211
212 }
213
214 function viewCurrentFeed(skip, subop) {
215
216 if (getActiveFeedId()) {
217 viewfeed(getActiveFeedId(), skip, subop);
218 } else {
219 disableContainerChildren("headlinesToolbar", false, document);
220 viewfeed(-1, skip, subop); // FIXME
221 }
222 }
223
224 function viewfeed(feed, skip, subop) {
225 var f = window.frames["feeds-frame"];
226 f.viewfeed(feed, skip, subop);
227 }
228
229 function timeout() {
230 scheduleFeedUpdate(false);
231 setTimeout("timeout()", 900*1000);
232 }
233
234 function resetSearch() {
235 var searchbox = document.getElementById("searchbox")
236
237 if (searchbox.value != "" && getActiveFeedId()) {
238 searchbox.value = "";
239 viewfeed(getActiveFeedId(), 0, "");
240 }
241 }
242
243 function search() {
244 viewCurrentFeed(0, "");
245 }
246
247 function localPiggieFunction(enable) {
248 if (enable) {
249 var query_str = "backend.php?op=feeds&subop=piggie";
250
251 if (xmlhttp_ready(xmlhttp)) {
252
253 xmlhttp.open("GET", query_str, true);
254 xmlhttp.onreadystatechange=feedlist_callback;
255 xmlhttp.send(null);
256 }
257 }
258 }
259
260 function localHotkeyHandler(keycode) {
261
262 /* if (keycode == 78) {
263 return moveToPost('next');
264 }
265
266 if (keycode == 80) {
267 return moveToPost('prev');
268 } */
269
270 if (keycode == 82) { // r
271 return scheduleFeedUpdate(true);
272 }
273
274 if (keycode == 85) { // u
275 if (getActiveFeedId()) {
276 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
277 }
278 }
279
280 if (keycode == 65) { // a
281 return toggleDispRead();
282 }
283
284 var f_doc = window.frames["feeds-frame"].document;
285 var feedlist = f_doc.getElementById('feedList');
286
287 if (keycode == 74) { // j
288 var feed = getActiveFeedId();
289 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
290 if (new_feed) viewfeed(new_feed, 0, '');
291 }
292
293 if (keycode == 75) { // k
294 var feed = getActiveFeedId();
295 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
296 if (new_feed) viewfeed(new_feed, 0, '');
297 }
298
299 // notify("KC: " + keycode);
300
301 }
302
303 // if argument is undefined, current subtitle is not updated
304 // use blank string to clear subtitle
305 function updateTitle(s) {
306 var tmp = "Tiny Tiny RSS";
307
308 if (s && s.length > 0) {
309 current_subtitle = s;
310 }
311
312 if (global_unread > 0) {
313 tmp = tmp + " (" + global_unread + ")";
314 }
315
316 if (s) {
317 tmp = tmp + " - " + current_subtitle;
318 }
319
320 if (active_title_text.length > 0) {
321 tmp = tmp + " > " + active_title_text;
322 }
323
324 document.title = tmp;
325 }
326
327 function genericSanityCheck() {
328
329 if (!xmlhttp) fatalError(1);
330
331 setCookie("ttrss_vf_test", "TEST");
332
333 if (getCookie("ttrss_vf_test") != "TEST") {
334 fatalError(2);
335 }
336
337 return true;
338 }
339
340 function init() {
341
342 try {
343
344 disableContainerChildren("headlinesToolbar", true);
345
346 if (!genericSanityCheck())
347 return;
348
349 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
350 xmlhttp.onreadystatechange=backend_sanity_check_callback;
351 xmlhttp.send(null);
352
353 } catch (e) {
354 exception_error("init", e);
355 }
356 }
357
358 function init_second_stage() {
359
360 try {
361
362 setCookie("ttrss_vf_actfeed", "");
363
364 updateFeedList(false, false);
365 document.onkeydown = hotkey_handler;
366
367 var viewbox = document.getElementById("viewbox");
368 var limitbox = document.getElementById("limitbox");
369
370 dropboxSelect(viewbox, getCookie("ttrss_vf_vmode"));
371 dropboxSelect(limitbox, getCookie("ttrss_vf_limit"));
372
373 } catch (e) {
374 exception_error("init_second_stage", e);
375 }
376 }
377
378 function quickMenuGo() {
379
380 var chooser = document.getElementById("quickMenuChooser");
381 var opid = chooser[chooser.selectedIndex].id;
382
383 if (opid == "qmcPrefs") {
384 gotoPreferences();
385 }
386
387 if (opid == "qmcAdvSearch") {
388 displayDlg("search");
389 return;
390 }
391
392 if (opid == "qmcAddFeed") {
393 displayDlg("quickAddFeed");
394 return;
395 }
396
397 if (opid == "qmcRemoveFeed") {
398 var actid = getActiveFeedId();
399
400 if (!actid) {
401 notify("Please select some feed first.");
402 return;
403 }
404
405 if (confirm("Remove current feed?")) {
406 qfdDelete(actid);
407 }
408
409 return;
410 }
411
412 if (opid == "qmcUpdateFeeds") {
413 scheduleFeedUpdate(true);
414 return;
415 }
416
417 if (opid == "qmcCatchupAll") {
418 catchupAllFeeds();
419 return;
420 }
421
422 if (opid == "qmcShowOnlyUnread") {
423 toggleDispRead();
424 return;
425 }
426
427 if (opid == "qmcAddFilter") {
428 displayDlg("quickAddFilter", getActiveFeedId());
429 }
430
431 }
432
433 function qafAdd() {
434
435 if (!xmlhttp_ready(xmlhttp)) {
436 printLockingError();
437 return
438 }
439
440 var link = document.getElementById("qafInput");
441
442 if (link.value.length == 0) {
443 notify("Missing feed URL.");
444 } else {
445 notify("Adding feed...");
446
447 var cat = document.getElementById("qafCat");
448 var cat_id = "";
449
450 if (cat) {
451 cat_id = cat[cat.selectedIndex].id;
452 } else {
453 cat_id = 0;
454 }
455
456 var feeds_doc = window.frames["feeds-frame"].document;
457
458 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
459
460 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
461 param_escape(link.value) + "&cid=" + param_escape(cat_id), true);
462 xmlhttp.onreadystatechange=dlg_frefresh_callback;
463 xmlhttp.send(null);
464
465 link.value = "";
466
467 }
468 }
469
470 function qaddFilter() {
471
472 if (!xmlhttp_ready(xmlhttp)) {
473 printLockingError();
474 return
475 }
476
477 var regexp = document.getElementById("fadd_regexp");
478 var match = document.getElementById("fadd_match");
479 var feed = document.getElementById("fadd_feed");
480 var action = document.getElementById("fadd_action");
481
482 if (regexp.value.length == 0) {
483 notify("Missing filter expression.");
484 } else {
485 notify("Adding filter...");
486
487 var v_match = match[match.selectedIndex].text;
488 var feed_id = feed[feed.selectedIndex].id;
489 var action_id = action[action.selectedIndex].id;
490
491 xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add&regexp=" +
492 param_escape(regexp.value) + "&match=" + v_match +
493 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
494
495 xmlhttp.onreadystatechange=dlg_submit_callback;
496 xmlhttp.send(null);
497
498 regexp.value = "";
499 }
500
501 }
502
503
504 function displayDlg(id, param) {
505
506 notify("");
507
508 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
509 param_escape(id) + "&param=" + param_escape(param), true);
510 xmlhttp.onreadystatechange=dlg_display_callback;
511 xmlhttp.send(null);
512
513 disableHotkeys();
514 }
515
516 function closeDlg() {
517 var dlg = document.getElementById("userDlgShadow");
518 dlg.style.display = "none";
519 enableHotkeys();
520 }
521
522 function qfdDelete(feed_id) {
523
524 notify("Removing feed...");
525
526 // var feeds_doc = window.frames["feeds-frame"].document;
527 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
528
529 _qfd_deleted_feed = feed_id;
530
531 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
532 xmlhttp.onreadystatechange=dlg_frefresh_callback;
533 xmlhttp.send(null);
534 }
535
536
537 function allFeedsMenuGo() {
538 var chooser = document.getElementById("allFeedsChooser");
539
540 var opname = chooser[chooser.selectedIndex].text;
541
542 if (opname == "Update") {
543 scheduleFeedUpdate(true);
544 return;
545 }
546
547 if (opname == "Mark as read") {
548 catchupAllFeeds();
549 return;
550 }
551
552 if (opname == "Show only unread") {
553 toggleDispRead();
554 return;
555 }
556
557 }
558
559 function updateFeedTitle(t) {
560 active_title_text = t;
561 updateTitle();
562 }
563
564 function toggleDispRead() {
565 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
566
567 hide_read_feeds = !hide_read_feeds;
568
569 var feeds_doc = window.frames["feeds-frame"].document;
570
571 hideOrShowFeeds(feeds_doc, hide_read_feeds);
572
573 if (hide_read_feeds) {
574 setCookie("ttrss_vf_hreadf", 1);
575 } else {
576 setCookie("ttrss_vf_hreadf", 0);
577 }
578
579 }
580