]>
Commit | Line | Data |
---|---|---|
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 counter_timeout_id = false; | |
7 | ||
8 | var resize_enabled = false; | |
9 | var selection_disabled = false; | |
10 | var counters_last_request = 0; | |
11 | ||
12 | var feeds_sort_by_unread = false; | |
13 | var feedlist_sortable_enabled = false; | |
14 | ||
15 | function toggle_sortable_feedlist(enabled) { | |
16 | /* try { | |
17 | ||
18 | if (enabled) { | |
19 | Sortable.create('feedList', {onChange: feedlist_dragsorted, only: "feedCat"}); | |
20 | } else { | |
21 | Sortable.destroy('feedList'); | |
22 | } | |
23 | ||
24 | } catch (e) { | |
25 | exception_error("toggle_sortable_feedlist", e); | |
26 | } */ | |
27 | } | |
28 | ||
29 | function viewCategory(cat) { | |
30 | viewfeed(cat, '', true); | |
31 | return false; | |
32 | } | |
33 | ||
34 | function viewNextFeedPage() { | |
35 | try { | |
36 | //if (!getActiveFeedId()) return; | |
37 | ||
38 | console.log("viewNextFeedPage: calling viewfeed(), p: " + parseInt(_feed_cur_page+1)); | |
39 | ||
40 | viewfeed(getActiveFeedId(), '', activeFeedIsCat(), parseInt(_feed_cur_page+1)); | |
41 | ||
42 | } catch (e) { | |
43 | exception_error("viewNextFeedPage", e); | |
44 | } | |
45 | } | |
46 | ||
47 | ||
48 | function viewfeed(feed, subop, is_cat, offset) { | |
49 | try { | |
50 | if (is_cat == undefined) is_cat = false; | |
51 | ||
52 | // if (!offset) page_offset = 0; | |
53 | ||
54 | last_requested_article = 0; | |
55 | //counters_last_request = 0; | |
56 | ||
57 | if (feed == getActiveFeedId()) { | |
58 | cache_invalidate("F:" + feed); | |
59 | } | |
60 | ||
61 | /* if (getInitParam("theme") == "" || getInitParam("theme") == "compact") { | |
62 | if (getInitParam("hide_feedlist") == 1) { | |
63 | Element.hide("feeds-holder"); | |
64 | } | |
65 | } */ | |
66 | ||
67 | dijit.byId("content-tabs").selectChild( | |
68 | dijit.byId("content-tabs").getChildren()[0]); | |
69 | ||
70 | var force_nocache = false; | |
71 | ||
72 | var page_offset = 0; | |
73 | ||
74 | if (offset > 0) { | |
75 | page_offset = offset; | |
76 | } else { | |
77 | page_offset = 0; | |
78 | _feed_cur_page = 0; | |
79 | _infscroll_disable = 0; | |
80 | } | |
81 | ||
82 | if (getActiveFeedId() != feed) { | |
83 | _feed_cur_page = 0; | |
84 | active_post_id = 0; | |
85 | _infscroll_disable = 0; | |
86 | } | |
87 | ||
88 | if (page_offset != 0 && !subop) { | |
89 | var date = new Date(); | |
90 | var timestamp = Math.round(date.getTime() / 1000); | |
91 | ||
92 | console.log(_infscroll_request_sent + " : " + timestamp); | |
93 | ||
94 | if (_infscroll_request_sent && _infscroll_request_sent + 30 > timestamp) { | |
95 | console.log("infscroll request in progress, aborting"); | |
96 | return; | |
97 | } | |
98 | ||
99 | _infscroll_request_sent = timestamp; | |
100 | } | |
101 | ||
102 | enableHotkeys(); | |
103 | hideAuxDlg(); | |
104 | closeInfoBox(); | |
105 | ||
106 | Form.enable("main_toolbar_form"); | |
107 | ||
108 | var toolbar_form = document.forms["main_toolbar_form"]; | |
109 | var toolbar_query = Form.serialize("main_toolbar_form"); | |
110 | ||
111 | if (toolbar_form.query) { | |
112 | if (toolbar_form.query.value != "") { | |
113 | force_nocache = true; | |
114 | } | |
115 | toolbar_form.query.value = ""; | |
116 | } | |
117 | ||
118 | var query = "?op=viewfeed&feed=" + feed + "&" + | |
119 | toolbar_query + "&subop=" + param_escape(subop); | |
120 | ||
121 | if ($("search_form")) { | |
122 | var search_query = Form.serialize("search_form"); | |
123 | query = query + "&" + search_query; | |
124 | $("search_form").query.value = ""; | |
125 | closeInfoBox(true); | |
126 | force_nocache = true; | |
127 | } | |
128 | ||
129 | // console.log("IS_CAT_STORED: " + activeFeedIsCat() + ", IS_CAT: " + is_cat); | |
130 | ||
131 | if (subop == "MarkAllRead") { | |
132 | ||
133 | var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; | |
134 | ||
135 | if (show_next_feed) { | |
136 | ||
137 | if (!activeFeedIsCat()) { | |
138 | ||
139 | var feedlist = $('feedList'); | |
140 | ||
141 | var next_unread_feed = getRelativeFeedId2(feed, false, | |
142 | "next", true); | |
143 | ||
144 | /* gRFI2 also returns categories which we don't really | |
145 | * need here, so we skip them */ | |
146 | ||
147 | while (next_unread_feed && next_unread_feed.match("CAT:")) | |
148 | next_unread_feed = getRelativeFeedId2( | |
149 | next_unread_feed.replace("CAT:", ""), | |
150 | true, "next", true); | |
151 | ||
152 | if (!next_unread_feed) { | |
153 | next_unread_feed = getRelativeFeedId2(-3, true, | |
154 | "next", true); | |
155 | } | |
156 | ||
157 | if (next_unread_feed) { | |
158 | query = query + "&nuf=" + param_escape(next_unread_feed); | |
159 | //setActiveFeedId(next_unread_feed); | |
160 | feed = next_unread_feed; | |
161 | } | |
162 | } else { | |
163 | ||
164 | var next_unread_feed = getNextUnreadCat(feed); | |
165 | ||
166 | /* we don't need to specify that our next feed is actually | |
167 | a category, because we're in the is_cat mode by definition | |
168 | already */ | |
169 | ||
170 | if (next_unread_feed && show_next_feed) { | |
171 | query = query + "&nuf=" + param_escape(next_unread_feed); | |
172 | feed = next_unread_feed; | |
173 | } | |
174 | ||
175 | } | |
176 | } | |
177 | } | |
178 | ||
179 | if (is_cat) { | |
180 | query = query + "&cat=1"; | |
181 | } | |
182 | ||
183 | if (page_offset != 0) { | |
184 | query = query + "&skip=" + page_offset; | |
185 | ||
186 | // to prevent duplicate feed titles when showing grouped vfeeds | |
187 | if (vgroup_last_feed) { | |
188 | query = query + "&vgrlf=" + param_escape(vgroup_last_feed); | |
189 | } | |
190 | } | |
191 | ||
192 | Form.enable("main_toolbar_form"); | |
193 | ||
194 | console.log(query); | |
195 | ||
196 | var container = $("headlinesInnerContainer"); | |
197 | ||
198 | var unread_ctr = -1; | |
199 | ||
200 | if (!is_cat) unread_ctr = get_feed_unread(feed); | |
201 | ||
202 | var cache_check = false; | |
203 | ||
204 | if (unread_ctr != -1 && !page_offset && !force_nocache && !subop) { | |
205 | ||
206 | var cache_prefix = ""; | |
207 | ||
208 | if (is_cat) { | |
209 | cache_prefix = "C:"; | |
210 | } else { | |
211 | cache_prefix = "F:"; | |
212 | } | |
213 | ||
214 | cache_check = cache_check_param(cache_prefix + feed, unread_ctr); | |
215 | console.log("headline cache check: " + cache_check); | |
216 | } | |
217 | ||
218 | if (cache_check) { | |
219 | ||
220 | setActiveFeedId(feed, is_cat); | |
221 | ||
222 | $("headlines-frame").innerHTML = cache_find_param(cache_prefix + feed, | |
223 | unread_ctr); | |
224 | ||
225 | request_counters(); | |
226 | remove_splash(); | |
227 | ||
228 | } else { | |
229 | ||
230 | if (!is_cat) | |
231 | if (!setFeedExpandoIcon(feed, is_cat, 'images/indicator_white.gif')) | |
232 | notify_progress("Loading, please wait...", true); | |
233 | ||
234 | new Ajax.Request("backend.php", { | |
235 | parameters: query, | |
236 | onComplete: function(transport) { | |
237 | setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); | |
238 | headlines_callback2(transport, page_offset); | |
239 | } }); | |
240 | } | |
241 | ||
242 | } catch (e) { | |
243 | exception_error("viewfeed", e); | |
244 | } | |
245 | } | |
246 | ||
247 | ||
248 | function feedlist_dragsorted(ctr) { | |
249 | try { | |
250 | var cats = $$("#feedList > li[id*=FCAT-]"); | |
251 | var ordered_cats = []; | |
252 | ||
253 | cats.each(function(cat) { | |
254 | ordered_cats.push(cat.id.replace("FCAT-", "")); | |
255 | }); | |
256 | ||
257 | if (ordered_cats.length > 0) { | |
258 | ||
259 | var query = "?op=feeds&subop=catsort&corder=" + | |
260 | param_escape(ordered_cats.toString()); | |
261 | ||
262 | //console.log(query); | |
263 | ||
264 | new Ajax.Request("backend.php", { parameters: query }); | |
265 | } | |
266 | ||
267 | } catch (e) { | |
268 | exception_error("feedlist_dragsorted", e); | |
269 | } | |
270 | } | |
271 | ||
272 | function feedlist_init() { | |
273 | try { | |
274 | loading_set_progress(90); | |
275 | ||
276 | console.log("in feedlist init"); | |
277 | ||
278 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
279 | document.onkeydown = hotkey_handler; | |
280 | setTimeout("hotkey_prefix_timeout()", 5*1000); | |
281 | ||
282 | if (getActiveFeedId()) { | |
283 | //console.log("some feed is open on feedlist refresh, reloading"); | |
284 | //setTimeout("viewCurrentFeed()", 100); | |
285 | } else { | |
286 | if (getInitParam("cdm_auto_catchup") != 1) { | |
287 | setTimeout("viewfeed(-3)", 100); | |
288 | } else { | |
289 | setTimeout("viewfeed(-5)", 100); | |
290 | remove_splash(); | |
291 | } | |
292 | } | |
293 | ||
294 | console.log("T:" + | |
295 | getInitParam("cdm_auto_catchup") + " " + get_feed_unread(-3)); | |
296 | ||
297 | toggle_sortable_feedlist(isFeedlistSortable()); | |
298 | ||
299 | } catch (e) { | |
300 | exception_error("feedlist/init", e); | |
301 | } | |
302 | } | |
303 | ||
304 | function enable_selection(b) { | |
305 | selection_disabled = !b; | |
306 | } | |
307 | ||
308 | function enable_resize(b) { | |
309 | resize_enabled = b; | |
310 | } | |
311 | ||
312 | function request_counters_real() { | |
313 | try { | |
314 | console.log("requesting counters..."); | |
315 | ||
316 | var query = "?op=rpc&subop=getAllCounters&seq=" + next_seq(); | |
317 | ||
318 | query = query + "&omode=flc"; | |
319 | ||
320 | new Ajax.Request("backend.php", { | |
321 | parameters: query, | |
322 | onComplete: function(transport) { | |
323 | try { | |
324 | handle_rpc_reply(transport); | |
325 | } catch (e) { | |
326 | exception_error("viewfeed/getcounters", e); | |
327 | } | |
328 | } }); | |
329 | ||
330 | } catch (e) { | |
331 | exception_error("request_counters_real", e); | |
332 | } | |
333 | } | |
334 | ||
335 | ||
336 | function request_counters() { | |
337 | ||
338 | try { | |
339 | ||
340 | if (getInitParam("bw_limit") == "1") return; | |
341 | ||
342 | var date = new Date(); | |
343 | var timestamp = Math.round(date.getTime() / 1000); | |
344 | ||
345 | if (timestamp - counters_last_request > 5) { | |
346 | console.log("scheduling request of counters..."); | |
347 | ||
348 | window.clearTimeout(counter_timeout_id); | |
349 | counter_timeout_id = window.setTimeout("request_counters_real()", 1000); | |
350 | ||
351 | counters_last_request = timestamp; | |
352 | } else { | |
353 | console.log("request_counters: rate limit reached: " + (timestamp - counters_last_request)); | |
354 | } | |
355 | ||
356 | } catch (e) { | |
357 | exception_error("request_counters", e); | |
358 | } | |
359 | } | |
360 | ||
361 | function displayNewContentPrompt(id) { | |
362 | try { | |
363 | ||
364 | var msg = "<a href='#' onclick='viewfeed("+id+")'>" + | |
365 | __("New articles available in this feed (click to show)") + "</a>"; | |
366 | ||
367 | msg = msg.replace("%s", getFeedName(id)); | |
368 | ||
369 | $('auxDlg').innerHTML = msg; | |
370 | ||
371 | new Effect.Appear('auxDlg', {duration : 0.5}); | |
372 | ||
373 | } catch (e) { | |
374 | exception_error("displayNewContentPrompt", e); | |
375 | } | |
376 | } | |
377 | ||
378 | function parse_counters(reply, scheduled_call) { | |
379 | try { | |
380 | ||
381 | var feeds_found = 0; | |
382 | ||
383 | var elems = JSON.parse(reply.firstChild.nodeValue); | |
384 | ||
385 | for (var l = 0; l < elems.length; l++) { | |
386 | ||
387 | var id = elems[l].id | |
388 | var kind = elems[l].kind; | |
389 | var ctr = parseInt(elems[l].counter) | |
390 | var error = elems[l].error; | |
391 | var has_img = elems[l].has_img; | |
392 | var updated = elems[l].updated; | |
393 | var title = elems[l].title; | |
394 | var xmsg = elems[l].xmsg; | |
395 | ||
396 | if (id == "global-unread") { | |
397 | global_unread = ctr; | |
398 | updateTitle(); | |
399 | continue; | |
400 | } | |
401 | ||
402 | if (id == "subscribed-feeds") { | |
403 | feeds_found = ctr; | |
404 | continue; | |
405 | } | |
406 | ||
407 | var treeItem; | |
408 | ||
409 | setFeedUnread(id, (kind == "cat"), ctr); | |
410 | ||
411 | if (kind != "cat") { | |
412 | //setFeedValue(id, false, 'error', error); | |
413 | setFeedValue(id, false, 'updated', updated); | |
414 | ||
415 | if (id > 0) { | |
416 | if (has_img) { | |
417 | setFeedIcon(id, false, | |
418 | getInitParam("icons_url") + "/" + id + ".ico"); | |
419 | } else { | |
420 | setFeedIcon(id, false, 'images/blank_icon.gif'); | |
421 | } | |
422 | } | |
423 | } | |
424 | } | |
425 | ||
426 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
427 | ||
428 | var feeds_stored = number_of_feeds; | |
429 | ||
430 | if (feeds_stored != feeds_found) { | |
431 | number_of_feeds = feeds_found; | |
432 | ||
433 | if (feeds_stored != 0 && feeds_found != 0) { | |
434 | console.log("Subscribed feed number changed, refreshing feedlist"); | |
435 | setTimeout('updateFeedList()', 50); | |
436 | } | |
437 | } | |
438 | ||
439 | } catch (e) { | |
440 | exception_error("parse_counters", e); | |
441 | } | |
442 | } | |
443 | ||
444 | function get_feed_unread(feed, is_cat) { | |
445 | try { | |
446 | if (is_cat) | |
447 | treeItem = treeModel.store._itemsByIdentity['CAT:' + feed]; | |
448 | else | |
449 | treeItem = treeModel.store._itemsByIdentity['FEED:' + feed]; | |
450 | ||
451 | if (treeItem) | |
452 | return treeModel.store.getValue(treeItem, 'unread'); | |
453 | ||
454 | } catch (e) { | |
455 | // | |
456 | } | |
457 | ||
458 | return -1; | |
459 | } | |
460 | ||
461 | function get_cat_unread(id) { | |
462 | return get_feed_unread(id, true); | |
463 | } | |
464 | ||
465 | function get_feed_entry_unread(elem) { | |
466 | ||
467 | var id = elem.id.replace("FEEDR-", ""); | |
468 | ||
469 | if (id <= 0) { | |
470 | return -1; | |
471 | } | |
472 | ||
473 | try { | |
474 | return parseInt($("FEEDU-" + id).innerHTML); | |
475 | } catch (e) { | |
476 | return -1; | |
477 | } | |
478 | } | |
479 | ||
480 | function get_feed_entry_name(elem) { | |
481 | var id = elem.id.replace("FEEDR-", ""); | |
482 | return getFeedName(id); | |
483 | } | |
484 | ||
485 | ||
486 | function resort_category(node, cat_mode) { | |
487 | ||
488 | try { | |
489 | ||
490 | //console.log("resort_category: " + node + " CM=" + cat_mode); | |
491 | ||
492 | var by_unread = feedsSortByUnread(); | |
493 | ||
494 | var list = node.getElementsByTagName("LI"); | |
495 | ||
496 | for (i = 0; i < list.length; i++) { | |
497 | ||
498 | for (j = i+1; j < list.length; j++) { | |
499 | ||
500 | var tmp_val = get_feed_entry_unread(list[i]); | |
501 | var cur_val = get_feed_entry_unread(list[j]); | |
502 | ||
503 | //console.log(list[i].id + " vs " + list[j].id); | |
504 | ||
505 | var tmp_name = get_feed_entry_name(list[i]).toLowerCase(); | |
506 | var cur_name = get_feed_entry_name(list[j]).toLowerCase(); | |
507 | ||
508 | /* we don't want to match FEEDR-0 - e.g. Archived articles */ | |
509 | ||
510 | var valid_pair = cat_mode || (list[i].id.match(/FEEDR-[1-9]/) && | |
511 | list[j].id.match(/FEEDR-[1-9]/)); | |
512 | ||
513 | if (valid_pair && ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name)))) { | |
514 | tempnode_i = list[i].cloneNode(true); | |
515 | tempnode_j = list[j].cloneNode(true); | |
516 | node.replaceChild(tempnode_i, list[j]); | |
517 | node.replaceChild(tempnode_j, list[i]); | |
518 | } | |
519 | } | |
520 | } | |
521 | ||
522 | } catch (e) { | |
523 | exception_error("resort_category", e); | |
524 | } | |
525 | ||
526 | } | |
527 | ||
528 | function resort_feedlist() { | |
529 | return; | |
530 | ||
531 | console.log("resort_feedlist"); | |
532 | ||
533 | if ($("FCATLIST--1")) { | |
534 | ||
535 | var lists = $$("#feedList ul[id*=FCATLIST]"); | |
536 | ||
537 | lists.each(function(list) { | |
538 | if (list.id != "FCATLIST--1") resort_category(list, true); | |
539 | }); | |
540 | ||
541 | } else { | |
542 | resort_category($("feedList"), false); | |
543 | } | |
544 | } | |
545 | ||
546 | function hideOrShowFeeds(hide) { | |
547 | var tree = dijit.byId("feedTree"); | |
548 | ||
549 | if (!tree) return; | |
550 | ||
551 | if (getInitParam("enable_feed_cats")) { | |
552 | ||
553 | var cats = tree.model.store._arrayOfTopLevelItems; | |
554 | ||
555 | cats.each(function(cat) { | |
556 | var cat_unread = hideOrShowFeedsCategory(cat.items, hide); | |
557 | ||
558 | var id = String(cat.id); | |
559 | var node = tree._itemNodesMap[id]; | |
560 | ||
561 | if (node) { | |
562 | if (hide && cat_unread == 0) { | |
563 | Effect.Fade(node[0].rowNode, {duration : 0.3, | |
564 | queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }}); | |
565 | } else { | |
566 | Element.show(node[0].rowNode); | |
567 | ++cat_unread; | |
568 | } | |
569 | } | |
570 | ||
571 | }); | |
572 | ||
573 | } else { | |
574 | hideOrShowFeedsCategory(tree.model.store._arrayOfTopLevelItems, hide); | |
575 | } | |
576 | ||
577 | /* try { | |
578 | ||
579 | if ($("FCATLIST--1")) { | |
580 | ||
581 | var lists = $$("#feedList ul[id*=FCATLIST]"); | |
582 | ||
583 | lists.each(function(list) { | |
584 | hideOrShowFeedsCategory(list.id.replace("FCATLIST-", ""), hide); | |
585 | }); | |
586 | ||
587 | } else { | |
588 | hideOrShowFeedsCategory(null, hide); | |
589 | } | |
590 | ||
591 | } catch (e) { | |
592 | exception_error("hideOrShowFeeds", e); | |
593 | } */ | |
594 | } | |
595 | ||
596 | function hideOrShowFeedsCategory(feeds, hide) { | |
597 | try { | |
598 | //console.warn("hideOrShowFeedsCategory: function not implemented"); | |
599 | var tree = dijit.byId("feedTree"); | |
600 | ||
601 | if (!tree) return; | |
602 | ||
603 | var cat_unread = 0; | |
604 | ||
605 | feeds.each(function(feed) { | |
606 | var id = String(feed.id); | |
607 | var bare_id = parseInt(id.substr(id.indexOf(":")+1)); | |
608 | ||
609 | var unread = feed.unread[0]; | |
610 | var node = tree._itemNodesMap[id]; | |
611 | ||
612 | if (node) { | |
613 | if (hide && unread == 0 && (bare_id > 0 || !getInitParam("hide_read_shows_special"))) { | |
614 | Effect.Fade(node[0].rowNode, {duration : 0.3, | |
615 | queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }}); | |
616 | } else { | |
617 | Element.show(node[0].rowNode); | |
618 | ++cat_unread; | |
619 | } | |
620 | } | |
621 | }); | |
622 | ||
623 | return cat_unread; | |
624 | ||
625 | /* var nodes; | |
626 | var cat_node; | |
627 | ||
628 | if (cat_id) { | |
629 | nodes = $$("#FCATLIST-" + cat_id + " > li"); | |
630 | cat_node = $("FCAT-" + cat_id); | |
631 | } else { | |
632 | nodes = $$("#feedList li"); | |
633 | } | |
634 | ||
635 | var cat_unread = 0; | |
636 | ||
637 | nodes.each(function(node) { | |
638 | ||
639 | var is_unread = node.hasClassName("Unread") || | |
640 | node.hasClassName("Selected") || | |
641 | (node.hasClassName("virt") && | |
642 | getInitParam("hide_read_shows_special")); | |
643 | ||
644 | if (hide && !is_unread) { | |
645 | Effect.Fade(node, {duration : 0.3, | |
646 | queue: { position: 'end', scope: 'FFADE-' + node.id, limit: 1 }}); | |
647 | } else { | |
648 | Element.show(node); | |
649 | ++cat_unread; | |
650 | } | |
651 | ||
652 | }); | |
653 | ||
654 | if (cat_node) { | |
655 | if (hide && cat_unread == 0 && !cat_node.hasClassName("Selected")) { | |
656 | Effect.Fade(cat_node, {duration : 0.3, | |
657 | queue: { position: 'end', scope: 'CFADE-' + cat_node.id, limit: 1 }}); | |
658 | } else { | |
659 | Element.show(cat_node); | |
660 | } | |
661 | } */ | |
662 | ||
663 | } catch (e) { | |
664 | exception_error("hideOrShowFeedsCategory", e); | |
665 | } | |
666 | } | |
667 | ||
668 | function getFeedName(feed, is_cat) { | |
669 | return getFeedValue(feed, is_cat, 'name'); | |
670 | } | |
671 | ||
672 | function getFeedValue(feed, is_cat, key) { | |
673 | ||
674 | try { | |
675 | if (is_cat) | |
676 | treeItem = treeModel.store._itemsByIdentity['CAT:' + feed]; | |
677 | else | |
678 | treeItem = treeModel.store._itemsByIdentity['FEED:' + feed]; | |
679 | ||
680 | if (treeItem) | |
681 | return treeModel.store.getValue(treeItem, key); | |
682 | ||
683 | } catch (e) { | |
684 | // | |
685 | } | |
686 | ||
687 | return ''; | |
688 | } | |
689 | ||
690 | function getNextUnreadCat(id) { | |
691 | try { | |
692 | var rows = $$("#feedList li[id*=FCAT]"); | |
693 | var unread_cats = []; | |
694 | ||
695 | rows.each(function(row) { | |
696 | var cat_id = row.id.replace("FCAT-", ""); | |
697 | ||
698 | if (Element.visible(row) && get_cat_unread(cat_id) > 0) | |
699 | unread_cats.push(parseInt(cat_id)); | |
700 | }); | |
701 | ||
702 | console.log(unread_cats); | |
703 | ||
704 | var idx = unread_cats.indexOf(id); | |
705 | ||
706 | if (idx != -1 && idx < unread_cats.length-1) { | |
707 | return unread_cats[idx+1]; | |
708 | } else { | |
709 | return unread_cats[0]; | |
710 | } | |
711 | ||
712 | } catch (e) { | |
713 | exception_error("getNextUnreadCat", e); | |
714 | } | |
715 | } | |
716 | ||
717 | function getRelativeFeedId2(id, is_cat, direction, unread_only) { | |
718 | try { | |
719 | ||
720 | // alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only); | |
721 | ||
722 | var rows = $$("#feedList li"); | |
723 | var feeds = new Array(); | |
724 | ||
725 | for (var i = 0; i < rows.length; i++) { | |
726 | if (rows[i].id.match("FEEDR-")) { | |
727 | ||
728 | if (rows[i].id == "FEEDR-" + id && !is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) { | |
729 | ||
730 | if (!unread_only || | |
731 | (rows[i].hasClassName("Unread") || rows[i].id == "FEEDR-" + id)) { | |
732 | feeds.push(rows[i].id.replace("FEEDR-", "")); | |
733 | } | |
734 | } | |
735 | } | |
736 | ||
737 | if (rows[i].id.match("FCAT-")) { | |
738 | if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) { | |
739 | ||
740 | var cat_id = parseInt(rows[i].id.replace("FCAT-", "")); | |
741 | ||
742 | if (cat_id >= 0) { | |
743 | if (!unread_only || get_cat_unread(cat_id) > 0) { | |
744 | feeds.push("CAT:"+cat_id); | |
745 | } | |
746 | } | |
747 | } | |
748 | } | |
749 | } | |
750 | ||
751 | // alert(feeds.toString()); | |
752 | ||
753 | if (!id) { | |
754 | if (direction == "next") { | |
755 | return feeds.shift(); | |
756 | } else { | |
757 | return feeds.pop(); | |
758 | } | |
759 | } else { | |
760 | if (direction == "next") { | |
761 | if (is_cat) id = "CAT:" + id; | |
762 | var idx = feeds.indexOf(id); | |
763 | if (idx != -1 && idx < feeds.length) { | |
764 | return feeds[idx+1]; | |
765 | } else { | |
766 | return getRelativeFeedId2(false, is_cat, direction, unread_only); | |
767 | } | |
768 | } else { | |
769 | if (is_cat) id = "CAT:" + id; | |
770 | var idx = feeds.indexOf(id); | |
771 | if (idx > 0) { | |
772 | return feeds[idx-1]; | |
773 | } else { | |
774 | return getRelativeFeedId2(false, is_cat, direction, unread_only); | |
775 | } | |
776 | } | |
777 | ||
778 | } | |
779 | ||
780 | } catch (e) { | |
781 | exception_error("getRelativeFeedId2", e); | |
782 | } | |
783 | } | |
784 | ||
785 | function feedsSortByUnread() { | |
786 | return feeds_sort_by_unread; | |
787 | } | |
788 | ||
789 | function setFeedUnread(feed, is_cat, unread) { | |
790 | try { | |
791 | setFeedValue(feed, is_cat, 'unread', parseInt(unread)); | |
792 | } catch (e) { | |
793 | exception_error("setFeedUnread", e); | |
794 | } | |
795 | } | |
796 | ||
797 | function setFeedValue(feed, is_cat, key, value) { | |
798 | try { | |
799 | if (!value) value = ''; | |
800 | ||
801 | if (is_cat) | |
802 | treeItem = treeModel.store._itemsByIdentity['CAT:' + feed]; | |
803 | else | |
804 | treeItem = treeModel.store._itemsByIdentity['FEED:' + feed]; | |
805 | ||
806 | if (treeItem) | |
807 | treeModel.store.setValue(treeItem, key, value); | |
808 | ||
809 | } catch (e) { | |
810 | console.log(e); | |
811 | //exception_error("setFeedValue", e); | |
812 | } | |
813 | } | |
814 | ||
815 | function toggleCollapseCat(id) { | |
816 | console.warn("toggleCollapseCat: function not implemented"); | |
817 | } | |
818 | ||
819 | function selectFeed(feed, is_cat) { | |
820 | try { | |
821 | var tree = dijit.byId("feedTree"); | |
822 | ||
823 | if (!tree) return; | |
824 | ||
825 | if (is_cat) | |
826 | treeNode = tree._itemNodesMap['CAT:' + feed]; | |
827 | else | |
828 | treeNode = tree._itemNodesMap['FEED:' + feed]; | |
829 | ||
830 | if (treeNode) { | |
831 | treeNode = treeNode[0]; | |
832 | if (!is_cat) tree._expandNode(treeNode); | |
833 | tree._selectNode(treeNode); | |
834 | } | |
835 | ||
836 | } catch (e) { | |
837 | exception_error("selectFeed", e); | |
838 | } | |
839 | } | |
840 | ||
841 | function setFeedIcon(feed, is_cat, src) { | |
842 | try { | |
843 | var tree = dijit.byId("feedTree"); | |
844 | ||
845 | if (!tree) return; | |
846 | ||
847 | if (is_cat) | |
848 | treeNode = tree._itemNodesMap['CAT:' + feed]; | |
849 | else | |
850 | treeNode = tree._itemNodesMap['FEED:' + feed]; | |
851 | ||
852 | if (treeNode) { | |
853 | treeNode = treeNode[0]; | |
854 | treeNode.iconNode.src = src; | |
855 | } | |
856 | ||
857 | } catch (e) { | |
858 | exception_error("setFeedIcon", e); | |
859 | } | |
860 | } | |
861 | ||
862 | function setFeedExpandoIcon(feed, is_cat, src) { | |
863 | try { | |
864 | var tree = dijit.byId("feedTree"); | |
865 | ||
866 | if (!tree) return; | |
867 | ||
868 | if (is_cat) | |
869 | treeNode = tree._itemNodesMap['CAT:' + feed]; | |
870 | else | |
871 | treeNode = tree._itemNodesMap['FEED:' + feed]; | |
872 | ||
873 | if (treeNode) { | |
874 | treeNode = treeNode[0]; | |
875 | treeNode.expandoNode.src = src; | |
876 | return true; | |
877 | } | |
878 | ||
879 | } catch (e) { | |
880 | exception_error("setFeedIcon", e); | |
881 | } | |
882 | return false; | |
883 | } |