]> git.wh0rd.org - tt-rss.git/blame - feedlist.js
add separate class for virtual cats to prevent resorting
[tt-rss.git] / feedlist.js
CommitLineData
a49f5e05 1var _feed_cur_page = 0;
29dfb258 2var _infscroll_disable = 0;
82764a41 3var _infscroll_request_sent = 0;
3a40e8a2 4var feed_under_pointer = undefined;
ac541432 5
cfd58e50
AD
6var mouse_is_down = false;
7var mouse_y = 0;
8var mouse_x = 0;
9
94047498 10var resize_enabled = false;
9922d56b 11var counters_last_request = 0;
91cdbe52 12
ff2c6e6a 13function viewCategory(cat) {
0feab655 14 active_feed_is_cat = true;
767e2486 15 viewfeed(cat, '', true);
0c3d1219 16 return false;
ff2c6e6a
AD
17}
18
0df398da
AD
19function feedlist_callback2(transport) {
20 try {
21 debug("feedlist_callback2");
6b4163cb 22 var f = document.getElementById("feeds-frame");
0df398da 23 f.innerHTML = transport.responseText;
80e4dc34 24 feedlist_init();
0df398da
AD
25 } catch (e) {
26 exception_error("feedlist_callback2", e);
6b4163cb
AD
27 }
28}
29
ac541432
AD
30function viewNextFeedPage() {
31 try {
2a8534a0 32 //if (!getActiveFeedId()) return;
ac541432 33
2a8534a0
AD
34 debug("viewNextFeedPage: calling viewfeed(), p: " + _feed_cur_page+1);
35
36 viewfeed(getActiveFeedId(), undefined, activeFeedIsCat(), undefined,
29dfb258 37 undefined, _feed_cur_page+1);
ac541432
AD
38
39 } catch (e) {
8b365031 40 exception_error("viewNextFeedPage", e);
ac541432
AD
41 }
42}
43
203de776 44function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
7719618b 45 try {
6b4163cb 46
ac541432 47// if (!offset) page_offset = 0;
c50e2b30 48
32f0c8b0 49 last_requested_article = 0;
9922d56b 50 counters_last_request = 0;
32f0c8b0 51
b8e6acea
AD
52 if (feed == getActiveFeedId()) {
53 cache_invalidate("F:" + feed);
54 }
55
0b6cffa8 56/* if (getInitParam("theme") == "" || getInitParam("theme") == "compact") {
d6918e1d
AD
57 if (getInitParam("hide_feedlist") == 1) {
58 Element.hide("feeds-holder");
59 }
0b6cffa8 60 } */
24c1e1c1 61
52d7e7da
AD
62 var force_nocache = false;
63
b3c67a48
AD
64 var page_offset = 0;
65
ac541432 66 if (offset > 0) {
c50e2b30 67 page_offset = offset;
ac541432
AD
68 } else {
69 page_offset = 0;
a49f5e05 70 _feed_cur_page = 0;
29dfb258 71 _infscroll_disable = 0;
ac541432
AD
72 }
73
74 if (getActiveFeedId() != feed) {
a49f5e05 75 _feed_cur_page = 0;
457c494a 76 active_post_id = 0;
29dfb258 77 _infscroll_disable = 0;
c50e2b30 78 }
203de776 79
82764a41
AD
80 if (page_offset != 0 && !subop) {
81 var date = new Date();
82 var timestamp = Math.round(date.getTime() / 1000);
83
84 debug("<b>" + _infscroll_request_sent + " : " + timestamp + "</b>");
85
86 if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) {
87 debug("infscroll request in progress, aborting");
88 return;
89 }
90
91 _infscroll_request_sent = timestamp;
92 }
93
7719618b 94 enableHotkeys();
0a6c4846 95
0979b696
AD
96 closeInfoBox();
97
fd98576c
AD
98 Form.enable("main_toolbar_form");
99
6b4163cb 100 var toolbar_form = document.forms["main_toolbar_form"];
fd98576c 101 var toolbar_query = Form.serialize("main_toolbar_form");
86b682ce 102
4764c27e 103 if (toolbar_form.query) {
52d7e7da
AD
104 if (toolbar_form.query.value != "") {
105 force_nocache = true;
106 }
f31673f7 107 toolbar_form.query.value = "";
164f4738
AD
108 }
109
86b682ce
AD
110 var query = "backend.php?op=viewfeed&feed=" + feed + "&" +
111 toolbar_query + "&subop=" + param_escape(subop);
112
9cb99906
AD
113 if (document.getElementById("search_form")) {
114 var search_query = Form.serialize("search_form");
86b682ce 115 query = query + "&" + search_query;
9cb99906 116 closeInfoBox(true);
52d7e7da 117 force_nocache = true;
86b682ce
AD
118 }
119
6c3b0198 120// debug("IS_CAT_STORED: " + activeFeedIsCat() + ", IS_CAT: " + is_cat);
0a6c4846 121
7719618b 122 if (subop == "MarkAllRead") {
e0998414 123
e0998414
AD
124 var feedlist = document.getElementById('feedList');
125
126 var next_unread_feed = getRelativeFeedId(feedlist,
6c3b0198 127 feed, "next", true);
e0998414 128
d05514a4
AD
129 if (!next_unread_feed) {
130 next_unread_feed = getRelativeFeedId(feedlist,
6c3b0198 131 -3, "next", true);
d05514a4
AD
132 }
133
9cb99906 134 var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
3ac2b520 135
5c365f60 136 if (next_unread_feed && show_next_feed && !activeFeedIsCat()) {
e0998414 137 query = query + "&nuf=" + param_escape(next_unread_feed);
18075368
AD
138 //setActiveFeedId(next_unread_feed);
139 feed = next_unread_feed;
e0998414 140 }
7719618b 141 }
ff2c6e6a 142
6c3b0198 143 if (is_cat) {
ff2c6e6a
AD
144 query = query + "&cat=1";
145 }
99ff73f4 146
c50e2b30
AD
147 if (page_offset != 0) {
148 query = query + "&skip=" + page_offset;
60d4df4d
AD
149
150 // to prevent duplicate feed titles when showing grouped vfeeds
151 if (vgroup_last_feed) {
152 query = query + "&vgrlf=" + param_escape(vgroup_last_feed);
153 }
203de776
AD
154 }
155
a51193e2
AD
156 var date = new Date();
157 var timestamp = Math.round(date.getTime() / 1000);
158 query = query + "&ts=" + timestamp
7719618b 159
6b4163cb
AD
160 disableContainerChildren("headlinesToolbar", false);
161 Form.enable("main_toolbar_form");
162
3de0261a
AD
163 // for piggybacked counters
164
165 if (tagsAreDisplayed()) {
166 query = query + "&omode=lt";
167 } else {
168 query = query + "&omode=flc";
169 }
170
6cc1fab3
AD
171 if (!async_counters_work) {
172 query = query + "&csync=true";
173 }
174
081e527d
AD
175 debug(query);
176
19815594 177 var container = document.getElementById("headlinesInnerContainer");
59cc876c 178
f60cc761 179/* if (container && page_offset == 0 && !isCdmMode()) {
19815594 180 new Effect.Fade(container, {duration: 1, to: 0.01,
df2b1e26 181 queue: { position:'end', scope: 'FEEDL-' + feed, limit: 1 } } );
f60cc761 182 } */
a49f5e05 183
8e9dd206 184 var unread_ctr = get_feed_unread(feed);
e19c1824
AD
185 var cache_check = false;
186
8e9dd206 187 if (unread_ctr != -1 && !page_offset && !force_nocache && !subop) {
dd5865d4
AD
188
189 var cache_prefix = "";
190
191 if (is_cat) {
192 cache_prefix = "C:";
193 } else {
194 cache_prefix = "F:";
195 }
196
197 cache_check = cache_check_param(cache_prefix + feed, unread_ctr);
198 debug("headline cache check: " + cache_check);
e19c1824
AD
199 }
200
201 if (cache_check) {
202 var f = document.getElementById("headlines-frame");
203
204 clean_feed_selections();
205
206 setActiveFeedId(feed);
207
208 if (is_cat != undefined) {
209 active_feed_is_cat = is_cat;
210 }
211
212 if (!is_cat) {
213 var feedr = document.getElementById("FEEDR-" + feed);
214 if (feedr && !feedr.className.match("Selected")) {
215 feedr.className = feedr.className + "Selected";
216 }
217 }
218
dd5865d4 219 f.innerHTML = cache_find_param(cache_prefix + feed, unread_ctr);
e19c1824 220
5aaf9b34 221 request_counters();
e19c1824
AD
222
223 } else {
224
225 if (!page_offset) {
226 notify_progress("Loading, please wait...", true);
227 }
228
229 new Ajax.Request(query, {
230 onComplete: function(transport) {
231 headlines_callback2(transport, feed, is_cat, page_offset);
232 } });
233 }
6b4163cb 234
7719618b
AD
235 } catch (e) {
236 exception_error("viewfeed", e);
237 }
1a66d16e
AD
238}
239
1d5e9fb9
AD
240function toggleCollapseCat_af(effect) {
241 //var caption = elem.id.replace("FCATLIST-", "");
242
243 try {
244
245 var elem = effect.element;
246 var cat = elem.id.replace("FCATLIST-", "");
247 var cap = document.getElementById("FCAP-" + cat);
66a251f9 248
1d5e9fb9 249 if (Element.visible(elem)) {
66a251f9 250 cap.innerHTML = cap.innerHTML.replace("…", "");
1d5e9fb9 251 } else {
66a251f9
AD
252 if (cap.innerHTML.lastIndexOf("…") != cap.innerHTML.length-3) {
253 cap.innerHTML = cap.innerHTML + "…";
1d5e9fb9
AD
254 }
255 }
256
257 } catch (e) {
258 exception_error("toggleCollapseCat_af", e);
259 }
260}
261
fe14aeb8
AD
262function toggleCollapseCat(cat) {
263 try {
fe14aeb8
AD
264
265 var cat_elem = document.getElementById("FCAT-" + cat);
96737ce9 266 var cat_list = document.getElementById("FCATLIST-" + cat).parentNode;
99ff73f4 267 var caption = document.getElementById("FCAP-" + cat);
fe14aeb8 268
225ec0d4 269/* if (cat_list.className.match("invisible")) {
fe14aeb8
AD
270 cat_list.className = "";
271 caption.innerHTML = caption.innerHTML.replace("...", "");
65f85814
AD
272 if (cat == 0) {
273 setCookie("ttrss_vf_uclps", "0");
274 }
fe14aeb8
AD
275 } else {
276 cat_list.className = "invisible";
277 caption.innerHTML = caption.innerHTML + "...";
65f85814
AD
278 if (cat == 0) {
279 setCookie("ttrss_vf_uclps", "1");
225ec0d4
AD
280 }
281
282 } */
283
731b05f4
AD
284 if (cat == 0) {
285 if (Element.visible("FCATLIST-" + cat)) {
286 setCookie("ttrss_vf_uclps", "1");
287 } else {
288 setCookie("ttrss_vf_uclps", "0");
289 }
290 }
291
bd64489f
AD
292 if (cat == -2) {
293 if (Element.visible("FCATLIST-" + cat)) {
294 setCookie("ttrss_vf_lclps", "1");
295 } else {
296 setCookie("ttrss_vf_lclps", "0");
297 }
298 }
299
3b086176
AD
300 if (cat == -1) {
301 if (Element.visible("FCATLIST-" + cat)) {
302 setCookie("ttrss_vf_vclps", "1");
303 } else {
304 setCookie("ttrss_vf_vclps", "0");
305 }
306 }
307
1d5e9fb9
AD
308 Effect.toggle('FCATLIST-' + cat, 'blind', { duration: 0.5,
309 afterFinish: toggleCollapseCat_af });
fe14aeb8 310
e8bd0da9
AD
311 new Ajax.Request("backend.php?op=feeds&subop=collapse&cid=" +
312 param_escape(cat));
fe14aeb8
AD
313
314 } catch (e) {
83f043bb 315 exception_error("toggleCollapseCat", e);
fe14aeb8
AD
316 }
317}
318
9d393c84
AD
319function feedlist_dragsorted(ctr) {
320 try {
321 var elem = document.getElementById("feedList");
322
323 var cats = elem.getElementsByTagName("LI");
324 var ordered_cats = new Array();
325
326 for (var i = 0; i < cats.length; i++) {
327 if (cats[i].id && cats[i].id.match("FCAT-")) {
328 ordered_cats.push(cats[i].id.replace("FCAT-", ""));
329 }
330 }
331
332 if (ordered_cats.length > 0) {
333
334 var query = "backend.php?op=feeds&subop=catsort&corder=" +
335 param_escape(ordered_cats.toString());
336
337 debug(query);
338
339 new Ajax.Request(query);
340 }
341
342 } catch (e) {
343 exception_error("feedlist_init", e);
344 }
345}
346
6b4163cb 347function feedlist_init() {
1b0809ae 348 try {
6e0c9275
AD
349// if (arguments.callee.done) return;
350// arguments.callee.done = true;
a38f09cf 351
99509451 352 loading_set_progress(90);
730dbf19 353
80e4dc34 354 debug("in feedlist init");
a38f09cf 355
60ea2377 356 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1b0809ae 357 document.onkeydown = hotkey_handler;
f3169d7e
AD
358 document.onmousemove = mouse_move_handler;
359 document.onmousedown = mouse_down_handler;
360 document.onmouseup = mouse_up_handler;
80e4dc34 361 setTimeout("timeout()", 0);
2055d4a6 362
935f235d
AD
363 if (typeof correctPNG != 'undefined') {
364 correctPNG();
365 }
366
7086277c 367 if (getActiveFeedId()) {
18bcd715
AD
368 //debug("some feed is open on feedlist refresh, reloading");
369 //setTimeout("viewCurrentFeed()", 100);
2d24f032 370 } else {
99509451 371 if (getInitParam("cdm_auto_catchup") != 1 && get_feed_unread(-3) > 0) {
730dbf19 372 notify_silent_next();
e1dfd280 373 setTimeout("viewfeed(-3)", 100);
730dbf19
AD
374 } else {
375 remove_splash();
e1dfd280 376 }
2d24f032 377 }
7086277c 378
22e06406 379 if (getInitParam("theme") == "") {
af9964d3 380 setTimeout("hide_footer()", 5000);
58daed52 381 }
22e06406 382
0b6cffa8 383 init_collapsable_feedlist(getInitParam("theme"));
37b29ac9 384
364e391e 385 Sortable.create('feedList', {onChange: feedlist_dragsorted, only: "feedCat"});
782ddd70 386
1b0809ae 387 } catch (e) {
bbf4d0b2 388 exception_error("feedlist/init", e);
1b0809ae 389 }
3745788e 390}
22e06406
AD
391
392function hide_footer_af(effect) {
393 try {
394 var c = document.getElementById("content-frame");
395
396 if (c) {
397 c.style.bottom = "0px";
398 } else {
399 var h = document.getElementById("headlines-frame");
400
401 if (h) {
402 h.style.bottom = "0px";
403 }
404 }
405
406 } catch (e) {
407 exception_error("hide_footer_af", e);
408 }
409}
410
411function hide_footer() {
412 try {
413 if (Element.visible("footer")) {
414 new Effect.Fade("footer", { afterFinish: hide_footer_af });
415 }
416 } catch (e) {
417 exception_error("hide_footer", e);
418 }
419}
37b29ac9 420
0b6cffa8 421/*
58daed52 422function init_hidden_feedlist(theme) {
37b29ac9 423 try {
24c1e1c1
AD
424 debug("init_hidden_feedlist");
425
d6918e1d 426 if (theme != "" && theme != "compact") return;
58daed52 427
37b29ac9
AD
428 var fl = document.getElementById("feeds-holder");
429 var fh = document.getElementById("headlines-frame");
24c1e1c1
AD
430 var fc = document.getElementById("content-frame");
431 var ft = document.getElementById("toolbar");
432 var ff = document.getElementById("footer");
d6918e1d
AD
433 var fhdr = document.getElementById("header");
434
24c1e1c1 435 var fbtn = document.getElementById("toggle_feeds_btn");
37b29ac9 436
24c1e1c1
AD
437 if (fbtn) Element.show(fbtn);
438
439 fl.style.top = fh.offsetTop + "px";
440 fl.style.backgroundColor = "white"; //FIXME
37b29ac9 441
24c1e1c1
AD
442 Element.hide(fl);
443
444 fh.style.left = "0px";
445 ft.style.left = "0px";
446 if (fc) fc.style.left = "0px";
447 if (ff) ff.style.left = "0px";
37b29ac9 448
d6918e1d
AD
449 if (theme == "compact") {
450 fhdr.style.left = "10px";
451 fl.style.top = (fh.offsetTop + 1) + "px";
452 }
453
37b29ac9
AD
454 } catch (e) {
455 exception_error("init_hidden_feedlist", e);
456 }
0b6cffa8 457} */
8389b150 458
58daed52 459function init_collapsable_feedlist(theme) {
8389b150
AD
460 try {
461 debug("init_collapsable_feedlist");
462
33aeea94
AD
463 if (theme != "" && theme != "compact" && theme != "graycube" &&
464 theme != "compat") return;
58daed52 465
8389b150
AD
466 var fbtn = document.getElementById("collapse_feeds_btn");
467
468 if (fbtn) Element.show(fbtn);
469
22936abb
AD
470 if (getCookie("ttrss_vf_fclps") == 1) {
471 collapse_feedlist();
472 }
473
8389b150
AD
474 } catch (e) {
475 exception_error("init_hidden_feedlist", e);
476 }
477
478}
730dbf19 479
f3169d7e
AD
480function mouse_move_handler(e) {
481 try {
482 var client_y;
dee4a409 483 var client_x;
f3169d7e
AD
484
485 if (window.event) {
486 client_y = window.event.clientY;
dee4a409 487 client_x = window.event.clientX;
f3169d7e 488 } else if (e) {
0fb6ae04
AD
489 client_x = e.screenX;
490 client_y = e.screenY;
f3169d7e
AD
491 }
492
43dbb07f 493 if (mouse_is_down) {
f3169d7e 494
dee4a409
AD
495 if (mouse_y == 0) mouse_y = client_y;
496 if (mouse_x == 0) mouse_x = client_x;
f3169d7e 497
dee4a409 498 resize_headlines(mouse_x - client_x, mouse_y - client_y);
a3f762ae
AD
499
500 mouse_y = client_y;
501 mouse_x = client_x;
502
f3169d7e
AD
503 return false;
504 }
505
506 } catch (e) {
507 exception_error("mouse_move_handler", e);
508 }
509}
510
94047498
AD
511function enable_resize(b) {
512 resize_enabled = b;
91cdbe52
AD
513}
514
f3169d7e
AD
515function mouse_down_handler(e) {
516 try {
94047498 517 if (resize_enabled) {
a3f762ae
AD
518 mouse_is_down = true;
519 mouse_x = 0;
520 mouse_y = 0;
a2be67cd 521 document.onselectstart = function() { return false; };
17042fc0 522 return false;
a3f762ae 523 }
f3169d7e
AD
524 } catch (e) {
525 exception_error("mouse_move_handler", e);
526 }
527}
528
529function mouse_up_handler(e) {
530 try {
f3169d7e 531 mouse_is_down = false;
a2be67cd 532 document.onselectstart = null;
f3169d7e
AD
533 } catch (e) {
534 exception_error("mouse_move_handler", e);
535 }
536}
5aaf9b34 537
997d9d7c 538function request_counters_real() {
5aaf9b34
AD
539
540 try {
06c88b8d
AD
541
542 debug("requesting counters...");
543
5aaf9b34
AD
544 var query = "backend.php?op=rpc&subop=getAllCounters";
545
546 if (tagsAreDisplayed()) {
547 query = query + "&omode=tl";
548 } else {
549 query = query + "&omode=flc";
550 }
551
552 new Ajax.Request(query, {
553 onComplete: function(transport) {
554 try {
6cc1fab3 555 all_counters_callback2(transport, true);
5aaf9b34
AD
556 } catch (e) {
557 exception_error("viewfeed/getcounters", e);
558 }
559 } });
560
997d9d7c
AD
561 } catch (e) {
562 exception_error("request_counters_real", e);
563 }
564}
565
997d9d7c
AD
566
567function request_counters() {
568
569 try {
570
a598370d
AD
571 if (getInitParam("bw_limit") == "1") return;
572
997d9d7c
AD
573 var date = new Date();
574 var timestamp = Math.round(date.getTime() / 1000);
575
d234a2e3
AD
576// if (getInitParam("sync_counters") == "1" ||
577// timestamp - counters_last_request > 10) {
578
997d9d7c 579 if (timestamp - counters_last_request > 10) {
d234a2e3 580
997d9d7c 581 debug("scheduling request of counters...");
06c88b8d 582 window.setTimeout("request_counters_real()", 1000);
997d9d7c
AD
583 counters_last_request = timestamp;
584 } else {
585 debug("request_counters: rate limit reached: " + (timestamp - counters_last_request));
586 }
587
5aaf9b34
AD
588 } catch (e) {
589 exception_error("request_counters", e);
590 }
591}