]> git.wh0rd.org - tt-rss.git/blob - feedlist.js
cf41f3ba13902d0b2d3112ce2cbb202ba6173285
[tt-rss.git] / feedlist.js
1 var _feed_cur_page = 0;
2 var _infscroll_disable = 0;
3 var _infscroll_request_sent = 0;
4 var feed_under_pointer = undefined;
5
6 var mouse_is_down = false;
7 var mouse_y = 0;
8 var mouse_x = 0;
9
10 var enable_resize = false;
11
12 function viewCategory(cat) {
13 active_feed_is_cat = true;
14 viewfeed(cat, '', true);
15 return false;
16 }
17
18 function feedlist_callback2(transport) {
19 try {
20 debug("feedlist_callback2");
21 var f = document.getElementById("feeds-frame");
22 f.innerHTML = transport.responseText;
23 feedlist_init();
24 } catch (e) {
25 exception_error("feedlist_callback2", e);
26 }
27 }
28
29 function viewNextFeedPage() {
30 try {
31 //if (!getActiveFeedId()) return;
32
33 debug("viewNextFeedPage: calling viewfeed(), p: " + _feed_cur_page+1);
34
35 viewfeed(getActiveFeedId(), undefined, activeFeedIsCat(), undefined,
36 undefined, _feed_cur_page+1);
37
38 } catch (e) {
39 exception_error("viewNextFeedPage", e);
40 }
41 }
42
43 function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
44 try {
45
46 // if (!offset) page_offset = 0;
47
48 if (feed == getActiveFeedId()) {
49 cache_invalidate("F:" + feed);
50 }
51
52 /* if (getInitParam("theme") == "" || getInitParam("theme") == "compact") {
53 if (getInitParam("hide_feedlist") == 1) {
54 Element.hide("feeds-holder");
55 }
56 } */
57
58 var force_nocache = false;
59
60 var page_offset = 0;
61
62 if (offset > 0) {
63 page_offset = offset;
64 } else {
65 page_offset = 0;
66 _feed_cur_page = 0;
67 _infscroll_disable = 0;
68 }
69
70 if (getActiveFeedId() != feed) {
71 _feed_cur_page = 0;
72 active_post_id = 0;
73 _infscroll_disable = 0;
74 }
75
76 if (page_offset != 0 && !subop) {
77 var date = new Date();
78 var timestamp = Math.round(date.getTime() / 1000);
79
80 debug("<b>" + _infscroll_request_sent + " : " + timestamp + "</b>");
81
82 if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) {
83 debug("infscroll request in progress, aborting");
84 return;
85 }
86
87 _infscroll_request_sent = timestamp;
88 }
89
90 enableHotkeys();
91
92 closeInfoBox();
93
94 Form.enable("main_toolbar_form");
95
96 var toolbar_form = document.forms["main_toolbar_form"];
97 var toolbar_query = Form.serialize("main_toolbar_form");
98
99 if (toolbar_form.query) {
100 if (toolbar_form.query.value != "") {
101 force_nocache = true;
102 }
103 toolbar_form.query.value = "";
104 }
105
106 var query = "backend.php?op=viewfeed&feed=" + feed + "&" +
107 toolbar_query + "&subop=" + param_escape(subop);
108
109 if (document.getElementById("search_form")) {
110 var search_query = Form.serialize("search_form");
111 query = query + "&" + search_query;
112 closeInfoBox(true);
113 force_nocache = true;
114 }
115
116 // debug("IS_CAT_STORED: " + activeFeedIsCat() + ", IS_CAT: " + is_cat);
117
118 if (subop == "MarkAllRead") {
119
120 var feedlist = document.getElementById('feedList');
121
122 var next_unread_feed = getRelativeFeedId(feedlist,
123 feed, "next", true);
124
125 if (!next_unread_feed) {
126 next_unread_feed = getRelativeFeedId(feedlist,
127 -3, "next", true);
128 }
129
130 var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
131
132 if (next_unread_feed && show_next_feed && !activeFeedIsCat()) {
133 query = query + "&nuf=" + param_escape(next_unread_feed);
134 //setActiveFeedId(next_unread_feed);
135 feed = next_unread_feed;
136 }
137 }
138
139 if (is_cat) {
140 query = query + "&cat=1";
141 }
142
143 if (page_offset != 0) {
144 query = query + "&skip=" + page_offset;
145
146 // to prevent duplicate feed titles when showing grouped vfeeds
147 if (vgroup_last_feed) {
148 query = query + "&vgrlf=" + param_escape(vgroup_last_feed);
149 }
150 }
151
152 var date = new Date();
153 var timestamp = Math.round(date.getTime() / 1000);
154 query = query + "&ts=" + timestamp
155
156 disableContainerChildren("headlinesToolbar", false);
157 Form.enable("main_toolbar_form");
158
159 // for piggybacked counters
160
161 if (tagsAreDisplayed()) {
162 query = query + "&omode=lt";
163 } else {
164 query = query + "&omode=flc";
165 }
166
167 debug(query);
168
169 var container = document.getElementById("headlinesInnerContainer");
170
171 /* if (container && page_offset == 0 && !isCdmMode()) {
172 new Effect.Fade(container, {duration: 1, to: 0.01,
173 queue: { position:'end', scope: 'FEEDL-' + feed, limit: 1 } } );
174 } */
175
176 var unread_ctr = get_feed_unread(feed);
177 var cache_check = false;
178
179 if (unread_ctr != -1 && !page_offset && !force_nocache && !subop) {
180
181 var cache_prefix = "";
182
183 if (is_cat) {
184 cache_prefix = "C:";
185 } else {
186 cache_prefix = "F:";
187 }
188
189 cache_check = cache_check_param(cache_prefix + feed, unread_ctr);
190 debug("headline cache check: " + cache_check);
191 }
192
193 if (cache_check) {
194 var f = document.getElementById("headlines-frame");
195
196 clean_feed_selections();
197
198 setActiveFeedId(feed);
199
200 if (is_cat != undefined) {
201 active_feed_is_cat = is_cat;
202 }
203
204 if (!is_cat) {
205 var feedr = document.getElementById("FEEDR-" + feed);
206 if (feedr && !feedr.className.match("Selected")) {
207 feedr.className = feedr.className + "Selected";
208 }
209 }
210
211 f.innerHTML = cache_find_param(cache_prefix + feed, unread_ctr);
212
213 var query = "backend.php?op=rpc&subop=getAllCounters";
214
215 if (tagsAreDisplayed()) {
216 query = query + "&omode=tl";
217 } else {
218 query = query + "&omode=flc";
219 }
220
221 new Ajax.Request(query, {
222 onComplete: function(transport) {
223 try {
224 all_counters_callback2(transport);
225 } catch (e) {
226 exception_error("viewfeed/getcounters", e);
227 }
228 } });
229
230 } else {
231
232 if (!page_offset) {
233 notify_progress("Loading, please wait...", true);
234 }
235
236 new Ajax.Request(query, {
237 onComplete: function(transport) {
238 headlines_callback2(transport, feed, is_cat, page_offset);
239 } });
240 }
241
242 } catch (e) {
243 exception_error("viewfeed", e);
244 }
245 }
246
247 function toggleCollapseCat_af(effect) {
248 //var caption = elem.id.replace("FCATLIST-", "");
249
250 try {
251
252 var elem = effect.element;
253 var cat = elem.id.replace("FCATLIST-", "");
254 var cap = document.getElementById("FCAP-" + cat);
255
256 if (Element.visible(elem)) {
257 cap.innerHTML = cap.innerHTML.replace("…", "");
258 } else {
259 if (cap.innerHTML.lastIndexOf("…") != cap.innerHTML.length-3) {
260 cap.innerHTML = cap.innerHTML + "…";
261 }
262 }
263
264 } catch (e) {
265 exception_error("toggleCollapseCat_af", e);
266 }
267 }
268
269 function toggleCollapseCat(cat) {
270 try {
271
272 var cat_elem = document.getElementById("FCAT-" + cat);
273 var cat_list = document.getElementById("FCATLIST-" + cat).parentNode;
274 var caption = document.getElementById("FCAP-" + cat);
275
276 /* if (cat_list.className.match("invisible")) {
277 cat_list.className = "";
278 caption.innerHTML = caption.innerHTML.replace("...", "");
279 if (cat == 0) {
280 setCookie("ttrss_vf_uclps", "0");
281 }
282 } else {
283 cat_list.className = "invisible";
284 caption.innerHTML = caption.innerHTML + "...";
285 if (cat == 0) {
286 setCookie("ttrss_vf_uclps", "1");
287 }
288
289 } */
290
291 if (cat == 0) {
292 if (Element.visible("FCATLIST-" + cat)) {
293 setCookie("ttrss_vf_uclps", "1");
294 } else {
295 setCookie("ttrss_vf_uclps", "0");
296 }
297 }
298
299 if (cat == -2) {
300 if (Element.visible("FCATLIST-" + cat)) {
301 setCookie("ttrss_vf_lclps", "1");
302 } else {
303 setCookie("ttrss_vf_lclps", "0");
304 }
305 }
306
307 if (cat == -1) {
308 if (Element.visible("FCATLIST-" + cat)) {
309 setCookie("ttrss_vf_vclps", "1");
310 } else {
311 setCookie("ttrss_vf_vclps", "0");
312 }
313 }
314
315 Effect.toggle('FCATLIST-' + cat, 'blind', { duration: 0.5,
316 afterFinish: toggleCollapseCat_af });
317
318 new Ajax.Request("backend.php?op=feeds&subop=collapse&cid=" +
319 param_escape(cat));
320
321 } catch (e) {
322 exception_error("toggleCollapseCat", e);
323 }
324 }
325
326 function feedlist_init() {
327 try {
328 // if (arguments.callee.done) return;
329 // arguments.callee.done = true;
330
331 loading_set_progress(90);
332
333 debug("in feedlist init");
334
335 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
336 document.onkeydown = hotkey_handler;
337 document.onmousemove = mouse_move_handler;
338 document.onmousedown = mouse_down_handler;
339 document.onmouseup = mouse_up_handler;
340 setTimeout("timeout()", 0);
341
342 /* debug("about to remove splash, OMG!");
343
344 var o = document.getElementById("overlay");
345
346 if (o) {
347 o.style.display = "none";
348 debug("removed splash!");
349 } */
350
351 if (typeof correctPNG != 'undefined') {
352 correctPNG();
353 }
354
355 if (getActiveFeedId()) {
356 debug("some feed is open on feedlist refresh, reloading");
357 setTimeout("viewCurrentFeed()", 100);
358 } else {
359 if (getInitParam("cdm_auto_catchup") != 1 && get_feed_unread(-3) > 0) {
360 notify_silent_next();
361 setTimeout("viewfeed(-3)", 100);
362 } else {
363 remove_splash();
364 }
365 }
366
367 if (getInitParam("theme") == "") {
368 setTimeout("hide_footer()", 5000);
369 }
370
371 /* if (getInitParam("hide_feedlist") == 1) {
372 init_hidden_feedlist(getInitParam("theme"));
373 } else {
374 init_collapsable_feedlist(getInitParam("theme"));
375 } */
376
377 init_collapsable_feedlist(getInitParam("theme"));
378
379 } catch (e) {
380 exception_error("feedlist/init", e);
381 }
382 }
383
384 function hide_footer_af(effect) {
385 try {
386 var c = document.getElementById("content-frame");
387
388 if (c) {
389 c.style.bottom = "0px";
390 } else {
391 var h = document.getElementById("headlines-frame");
392
393 if (h) {
394 h.style.bottom = "0px";
395 }
396 }
397
398 } catch (e) {
399 exception_error("hide_footer_af", e);
400 }
401 }
402
403 function hide_footer() {
404 try {
405 if (Element.visible("footer")) {
406 new Effect.Fade("footer", { afterFinish: hide_footer_af });
407 }
408 } catch (e) {
409 exception_error("hide_footer", e);
410 }
411 }
412
413 /*
414 function init_hidden_feedlist(theme) {
415 try {
416 debug("init_hidden_feedlist");
417
418 if (theme != "" && theme != "compact") return;
419
420 var fl = document.getElementById("feeds-holder");
421 var fh = document.getElementById("headlines-frame");
422 var fc = document.getElementById("content-frame");
423 var ft = document.getElementById("toolbar");
424 var ff = document.getElementById("footer");
425 var fhdr = document.getElementById("header");
426
427 var fbtn = document.getElementById("toggle_feeds_btn");
428
429 if (fbtn) Element.show(fbtn);
430
431 fl.style.top = fh.offsetTop + "px";
432 fl.style.backgroundColor = "white"; //FIXME
433
434 Element.hide(fl);
435
436 fh.style.left = "0px";
437 ft.style.left = "0px";
438 if (fc) fc.style.left = "0px";
439 if (ff) ff.style.left = "0px";
440
441 if (theme == "compact") {
442 fhdr.style.left = "10px";
443 fl.style.top = (fh.offsetTop + 1) + "px";
444 }
445
446 } catch (e) {
447 exception_error("init_hidden_feedlist", e);
448 }
449 } */
450
451 function init_collapsable_feedlist(theme) {
452 try {
453 debug("init_collapsable_feedlist");
454
455 if (theme != "" && theme != "compact" && theme != "graycube" &&
456 theme != "compat") return;
457
458 var fbtn = document.getElementById("collapse_feeds_btn");
459
460 if (fbtn) Element.show(fbtn);
461
462 if (getCookie("ttrss_vf_fclps") == 1) {
463 collapse_feedlist();
464 }
465
466 } catch (e) {
467 exception_error("init_hidden_feedlist", e);
468 }
469
470 }
471
472 function mouse_move_handler(e) {
473 try {
474 var client_y;
475 var client_x;
476
477 if (window.event) {
478 client_y = window.event.clientY;
479 client_x = window.event.clientX;
480 } else if (e) {
481 client_x = e.screenX;
482 client_y = e.screenY;
483 }
484
485 if (mouse_is_down) {
486
487 if (mouse_y == 0) mouse_y = client_y;
488 if (mouse_x == 0) mouse_x = client_x;
489
490 resize_headlines(mouse_x - client_x, mouse_y - client_y);
491 return false;
492 }
493
494 } catch (e) {
495 exception_error("mouse_move_handler", e);
496 }
497 }
498
499 function resize_enabled(b) {
500 enable_resize = b;
501 }
502
503 function mouse_down_handler(e) {
504 try {
505 if (enable_resize) mouse_is_down = true;
506 } catch (e) {
507 exception_error("mouse_move_handler", e);
508 }
509 }
510
511 function mouse_up_handler(e) {
512 try {
513 mouse_is_down = false;
514 } catch (e) {
515 exception_error("mouse_move_handler", e);
516 }
517 }