X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;ds=sidebyside;f=js%2Fviewfeed.js;h=dfbf8bced9a22438009ad372ee8807a9fcfa9038;hb=829d478f1b054c8ce1eeb4f15170dc4a1abb3e47;hp=cb9a3c646ef4fdb7b74421743aaf025c41239f0a;hpb=2e35b3bd6bb54da3284b8a06b025b39972a756a0;p=tt-rss.git diff --git a/js/viewfeed.js b/js/viewfeed.js old mode 100644 new mode 100755 index cb9a3c64..dfbf8bce --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -13,6 +13,10 @@ var catchup_timeout_id = false; var cids_requested = []; var loaded_article_ids = []; var _last_headlines_update = 0; +var _headlines_scroll_offset = 0; +var current_first_id = 0; + +var _catchup_request_sent = false; var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null; @@ -45,7 +49,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) { return; } - if (feed_id != getActiveFeedId() || is_cat != activeFeedIsCat()) + if (feed_id != -7 && (feed_id != getActiveFeedId() || is_cat != activeFeedIsCat())) return; /* dijit.getEnclosingWidget( @@ -56,8 +60,8 @@ function headlines_callback2(transport, offset, background, infscroll_req) { if (infscroll_req == false) { $("headlines-frame").scrollTop = 0; - Element.hide("floatingTitle"); - $("floatingTitle").setAttribute("rowid", 0); + $("floatingTitle").style.visibility = "hidden"; + $("floatingTitle").setAttribute("data-article-id", 0); $("floatingTitle").innerHTML = ""; } } catch (e) { }; @@ -77,6 +81,7 @@ function headlines_callback2(transport, offset, background, infscroll_req) { _infscroll_disable = 0; } + current_first_id = reply['headlines']['first_id']; var counters = reply['counters']; var articles = reply['articles']; //var runtime_info = reply['runtime-info']; @@ -84,19 +89,33 @@ function headlines_callback2(transport, offset, background, infscroll_req) { if (infscroll_req == false) { loaded_article_ids = []; - dijit.byId("headlines-frame").attr('content', - reply['headlines']['content']); + dojo.html.set($("headlines-toolbar"), + reply['headlines']['toolbar'], + {parseContent: true}); - dijit.byId("headlines-toolbar").attr('content', - reply['headlines']['toolbar']); + /*dojo.html.set($("headlines-frame"), + reply['headlines']['content'], + {parseContent: true}); + + $$("#headlines-frame div[id*='RROW']").each(function(row) { + loaded_article_ids.push(row.id); + });*/ + + $("headlines-frame").innerHTML = ''; + + var tmp = new Element("div"); + tmp.innerHTML = reply['headlines']['content']; + dojo.parser.parse(tmp); + + while (tmp.hasChildNodes()) { + var row = tmp.removeChild(tmp.firstChild); + + if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("cdmFeedTitle")) { + dijit.byId("headlines-frame").domNode.appendChild(row); - $$("#headlines-frame > div[id*=RROW]").each(function(row) { - if (loaded_article_ids.indexOf(row.id) != -1) { - row.parentNode.removeChild(row); - } else { loaded_article_ids.push(row.id); } - }); + } var hsp = $("headlines-spacer"); if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); @@ -104,6 +123,10 @@ function headlines_callback2(transport, offset, background, infscroll_req) { initHeadlinesMenu(); + if (_infscroll_disable) + hsp.innerHTML = "" + + __("Click to open next unread feed.") + ""; + if (_search_query) { $("feed_title").innerHTML += "" + " (" + __("Cancel search") + ")" + @@ -117,40 +140,42 @@ function headlines_callback2(transport, offset, background, infscroll_req) { var c = dijit.byId("headlines-frame"); var ids = getSelectedArticleIds2(); - var new_elems = []; - - $("headlines-tmp").innerHTML = reply['headlines']['content']; var hsp = $("headlines-spacer"); if (hsp) c.domNode.removeChild(hsp); - $$("#headlines-tmp > div").each(function(row) { - if (row.className == 'cdmFeedTitle') { - row.style.display = 'none'; - c.domNode.appendChild(row); - new_elems.push(row); - } else if (loaded_article_ids.indexOf(row.id) == -1) { - row.style.display = 'none'; - c.domNode.appendChild(row); - new_elems.push(row); + var tmp = new Element("div"); + tmp.innerHTML = reply['headlines']['content']; + dojo.parser.parse(tmp); + + var new_rows = []; + + while (tmp.hasChildNodes()) { + var row = tmp.removeChild(tmp.firstChild); + + if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("cdmFeedTitle")) { + dijit.byId("headlines-frame").domNode.appendChild(row); + loaded_article_ids.push(row.id); - } else { - row.parentNode.removeChild(row); - } - }); - if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); + if (!isCdmMode() || row.hasClassName("cdmFeedTitle")) { + new_rows.push(row); + } else if (isCdmMode()) { + var titleWrap = $$("#" + row.id + " .titleWrap")[0]; - if (getInitParam("cdm_auto_catchup") == 1) { - c.domNode.appendChild(hsp); + if (titleWrap) { + new_rows.push(titleWrap); + } + } + } } - console.log("added " + new_elems.size() + " headlines"); + if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); + c.domNode.appendChild(hsp); - if (new_elems.size() == 0) - _infscroll_disable = true; + if (headlines_count < 30) _infscroll_disable = true; console.log("restore selected ids: " + ids); @@ -158,21 +183,32 @@ function headlines_callback2(transport, offset, background, infscroll_req) { markHeadline(ids[i]); } - initHeadlinesMenu(); + initHeadlinesMenu(new_rows); - new_elems.each(function(child) { - dojo.parser.parse(child); - - if (!Element.visible(child)) - new Effect.Appear(child, { duration : 0.5 }); - }); + if (_infscroll_disable) { + hsp.innerHTML = "" + + __("Click to open next unread feed.") + ""; + } } else { console.log("no new headlines received"); + var first_id_changed = reply['headlines']['first_id_changed']; + console.log("first id changed:" + first_id_changed); + var hsp = $("headlines-spacer"); - if (hsp) hsp.innerHTML = ""; + if (hsp) { + if (first_id_changed) { + hsp.innerHTML = "" + + __("New articles found, reload feed to continue.") + ""; + } else { + hsp.innerHTML = "" + + __("Click to open next unread feed.") + ""; + } + + } + } } @@ -190,14 +226,11 @@ function headlines_callback2(transport, offset, background, infscroll_req) { else request_counters(true); - } else if (transport.responseText) { + } else { console.error("Invalid object received: " + transport.responseText); dijit.byId("headlines-frame").attr('content', "
" + __('Could not update headlines (invalid object received - see error console for details)') + "
"); - } else { - //notify_error("Error communicating with server."); - Element.show(dijit.byId("net-alert").domNode); } _infscroll_request_sent = 0; @@ -224,6 +257,8 @@ function headlines_callback2(transport, offset, background, infscroll_req) { function render_article(article) { try { + cleanup_memory("content-insert"); + dijit.byId("headlines-wrap-inner").addChild( dijit.byId("content-insert")); @@ -233,9 +268,8 @@ function render_article(article) { c.domNode.scrollTop = 0; } catch (e) { }; - PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, article); - c.attr('content', article); + PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode); correctHeadlinesOffset(getActiveArticleId()); @@ -251,34 +285,18 @@ function render_article(article) { function showArticleInHeadlines(id, noexpand) { try { - selectArticles("none"); - - var crow = $("RROW-" + id); - - if (!crow) return; - - var article_is_unread = crow.hasClassName("Unread"); + var row = $("RROW-" + id); + if (!row) return; if (!noexpand) - crow.removeClassName("Unread"); - crow.addClassName("active"); - - selectArticles('none'); + row.removeClassName("Unread"); - var view_mode = false; + row.addClassName("active"); - try { - view_mode = document.forms['main_toolbar_form'].view_mode; - view_mode = view_mode[view_mode.selectedIndex].value; - } catch (e) { - // - } + selectArticles('none'); markHeadline(id); - if (article_is_unread && !noexpand) - _force_scheduled_update = true; - } catch (e) { exception_error("showArticleInHeadlines", e); } @@ -314,30 +332,16 @@ function article_callback2(transport, id) { // return; // } - } else if (transport.responseText) { + } else { console.error("Invalid object received: " + transport.responseText); render_article("
" + __('Could not display article (invalid object received - see error console for details)') + "
"); - } else { - Element.show(dijit.byId("net-alert").domNode); } var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length request_counters(unread_in_buffer == 0); - //headlines_scroll_handler($("headlines-frame")); - -/* try { - if (!_infscroll_disable && - $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) { - - loadMoreHeadlines(); - } - } catch (e) { - console.warn(e); - } */ - notify(""); } catch (e) { exception_error("article_callback2", e, transport); @@ -403,19 +407,6 @@ function view(id, activefeed, noexpand) { // if we don't need to request any relative ids, we might as well skip // the server roundtrip altogether if (cids_to_request.length == 0) { - -/* try { - if (!_infscroll_disable && - $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) { - - loadMoreHeadlines(); - } - } catch (e) { - console.warn(e); - } */ - - //headlines_scroll_handler($("headlines-frame")); - return; } } @@ -457,7 +448,7 @@ function toggleMark(id, client_only) { var ft = $("floatingTitle"); - if (ft && ft.getAttribute("rowid") == "RROW-" + id) { + if (ft && ft.getAttribute("data-article-id") == id) { var fte = ft.getElementsByClassName("markedPic"); for (var i = 0; i < fte.length; i++) @@ -515,7 +506,7 @@ function togglePub(id, client_only, no_effects, note) { var ft = $("floatingTitle"); - if (ft && ft.getAttribute("rowid") == "RROW-" + id) { + if (ft && ft.getAttribute("data-article-id") == id) { var fte = ft.getElementsByClassName("pubPic"); for (var i = 0; i < fte.length; i++) @@ -558,7 +549,7 @@ function moveToPost(mode, noscroll, noexpand) { try { - var rows = getVisibleArticleIds(); + var rows = getLoadedArticleIds(); var prev_id = false; var next_id = false; @@ -588,6 +579,8 @@ function moveToPost(mode, noscroll, noexpand) { } } + console.log("cur: " + getActiveArticleId() + " next: " + next_id); + if (mode == "next") { if (next_id || getActiveArticleId()) { if (isCdmMode()) { @@ -697,22 +690,13 @@ function updateSelectedPrompt() { } } -function toggleUnread_afh(effect) { - try { - - var elem = effect.element; - elem.style.backgroundColor = ""; - - } catch (e) { - exception_error("toggleUnread_afh", e); - } -} - function toggleUnread(id, cmode, effect) { try { var row = $("RROW-" + id); if (row) { + var tmpClassName = row.className; + if (cmode == undefined || cmode == 2) { if (row.hasClassName("Unread")) { row.removeClassName("Unread"); @@ -736,11 +720,14 @@ function toggleUnread(id, cmode, effect) { // notify_progress("Loading, please wait..."); - new Ajax.Request("backend.php", { - parameters: query, - onComplete: function(transport) { - handle_rpc_json(transport); - } }); + if (tmpClassName != row.className) { + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function (transport) { + handle_rpc_json(transport); + } + }); + } } @@ -941,7 +928,7 @@ function getSelectedArticleIds2() { $$("#headlines-frame > div[id*=RROW][class*=Selected]").each( function(child) { - rv.push(child.id.replace("RROW-", "")); + rv.push(child.getAttribute("data-article-id")); }); return rv; @@ -953,21 +940,25 @@ function getLoadedArticleIds() { var children = $$("#headlines-frame > div[id*=RROW-]"); children.each(function(child) { - rv.push(child.id.replace("RROW-", "")); - }); + if (Element.visible(child)) { + rv.push(child.getAttribute("data-article-id")); + } + }); return rv; } // mode = all,none,unread,invert,marked,published -function selectArticles(mode) { +function selectArticles(mode, query) { try { - var children = $$("#headlines-frame > div[id*=RROW]"); + if (!query) query = "#headlines-frame > div[id*=RROW]"; + + var children = $$(query); children.each(function(child) { - var id = child.id.replace("RROW-", ""); + var id = child.getAttribute("data-article-id"); var cb = dijit.getEnclosingWidget( child.getElementsByClassName("rchk")[0]); @@ -1190,11 +1181,11 @@ function editArticleTags(id) { }}); } }, - href: query, + href: query }); var tmph = dojo.connect(dialog, 'onLoad', function() { - dojo.disconnect(tmph); + dojo.disconnect(tmph); new Ajax.Autocompleter('tags_str', 'tags_choices', "backend.php?op=article&method=completeTags", @@ -1225,6 +1216,8 @@ function cdmScrollToArticleId(id, force) { } function setActiveArticleId(id) { + console.log("setActiveArticleId:" + id); + _active_article_id = id; PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, _active_article_id); } @@ -1243,22 +1236,23 @@ function postMouseOut(id) { function unpackVisibleHeadlines() { try { - if (!isCdmMode()) return; + if (!isCdmMode() || !getInitParam("cdm_expanded")) return; - $$("#headlines-frame > div[id*=RROW]").each( + $$("#headlines-frame span.cencw[id]").each( function(child) { - if (child.offsetTop <= $("headlines-frame").scrollTop + + var row = $("RROW-" + child.id.replace("CENCW-", "")); + + if (row && row.offsetTop <= $("headlines-frame").scrollTop + $("headlines-frame").offsetHeight) { - var cencw = $("CENCW-" + child.id.replace("RROW-", "")); + //console.log("unpacking: " + child.id); - if (cencw) { - PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, child); + child.innerHTML = htmlspecialchars_decode(child.innerHTML); + child.removeAttribute('id'); - cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML); - cencw.setAttribute('id', ''); - Element.show(cencw); - } + PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, row); + + Element.show(child); } } ); @@ -1270,6 +1264,14 @@ function unpackVisibleHeadlines() { function headlines_scroll_handler(e) { try { + + // rate-limit in case of smooth scrolling and similar abominations + if (Math.max(e.scrollTop, _headlines_scroll_offset) - Math.min(e.scrollTop, _headlines_scroll_offset) < 25) { + return; + } + + _headlines_scroll_offset = e.scrollTop; + var hsp = $("headlines-spacer"); unpackVisibleHeadlines(); @@ -1278,6 +1280,7 @@ function headlines_scroll_handler(e) { if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 && getSelectedArticleIds2().length <= 1 && getInitParam("cdm_expanded")) { + var rows = $$("#headlines-frame > div[id*=RROW]"); for (var i = 0; i < rows.length; i++) { @@ -1285,14 +1288,14 @@ function headlines_scroll_handler(e) { if ($("headlines-frame").scrollTop <= child.offsetTop && child.offsetTop - $("headlines-frame").scrollTop < 100 && - child.id.replace("RROW-", "") != _active_article_id) { + child.getAttribute("data-article-id") != _active_article_id) { if (_active_article_id) { var row = $("RROW-" + _active_article_id); if (row) row.removeClassName("active"); } - _active_article_id = child.id.replace("RROW-", ""); + _active_article_id = child.getAttribute("data-article-id"); showArticleInHeadlines(_active_article_id, true); updateSelectedPrompt(); break; @@ -1301,26 +1304,23 @@ function headlines_scroll_handler(e) { } if (!_infscroll_disable) { - if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) || - (e.scrollHeight != 0 && - ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) { + if (hsp && hsp.offsetTop - 250 <= e.scrollTop + e.offsetHeight) { - if (hsp) - hsp.innerHTML = " " + - __("Loading, please wait..."); + hsp.innerHTML = " " + + __("Loading, please wait...") + ""; loadMoreHeadlines(); return; } - } else { - if (hsp) hsp.innerHTML = ""; } if (isCdmMode()) { updateFloatingTitle(); } + catchupCurrentBatchIfNeeded(); + if (getInitParam("cdm_auto_catchup") == 1) { // let's get DOM some time to settle down @@ -1332,7 +1332,7 @@ function headlines_scroll_handler(e) { if (child.hasClassName("Unread") && $("headlines-frame").scrollTop > (child.offsetTop + child.offsetHeight/2)) { - var id = child.id.replace("RROW-", ""); + var id = child.getAttribute("data-article-id") if (catchup_id_batch.indexOf(id) == -1) catchup_id_batch.push(id); @@ -1342,12 +1342,17 @@ function headlines_scroll_handler(e) { }); - if (catchup_id_batch.length > 0) { - window.clearTimeout(catchup_timeout_id); + if (_infscroll_disable) { + var child = $$("#headlines-frame div[id*=RROW]").last(); + + if (child && $("headlines-frame").scrollTop > + (child.offsetTop + child.offsetHeight - 50)) { + + console.log("we seem to be at an end"); - if (!_infscroll_request_sent) { - catchup_timeout_id = window.setTimeout('catchupBatchedArticles()', - 500); + if (getInitParam("on_catchup_show_next_feed") == "1") { + openNextUnreadFeed(); + } } } } @@ -1357,9 +1362,21 @@ function headlines_scroll_handler(e) { } } +function openNextUnreadFeed() { + try { + var is_cat = activeFeedIsCat(); + var nuf = getNextUnreadFeed(getActiveFeedId(), is_cat); + if (nuf) viewfeed({feed: nuf, is_cat: is_cat}); + } catch (e) { + exception_error("openNextUnreadFeed", e); + } +} + function catchupBatchedArticles() { try { - if (catchup_id_batch.length > 0 && !_infscroll_request_sent) { + if (catchup_id_batch.length > 0 && !_infscroll_request_sent && !_catchup_request_sent) { + + console.log("catchupBatchedArticles: working"); // make a copy of the array var batch = catchup_id_batch.slice(); @@ -1368,11 +1385,15 @@ function catchupBatchedArticles() { console.log(query); + _catchup_request_sent = true; + new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { handle_rpc_json(transport); + _catchup_request_sent = false; + reply = JSON.parse(transport.responseText); var batch = reply.ids; @@ -1404,7 +1425,7 @@ function catchupRelativeToArticle(below, id) { return; } - var visible_ids = getVisibleArticleIds(); + var visible_ids = getLoadedArticleIds(); var ids_to_mark = new Array(); @@ -1497,8 +1518,8 @@ function cdmCollapseArticle(event, id, unmark) { if (row.offsetTop < $("headlines-frame").scrollTop) scrollToRowId(row.id); - Element.hide("floatingTitle"); - $("floatingTitle").setAttribute("rowid", false); + $("floatingTitle").style.visibility = "hidden"; + $("floatingTitle").setAttribute("data-article-id", 0); } } catch (e) { @@ -1560,8 +1581,13 @@ function cdmExpandArticle(id, noexpand) { if (old_offset > new_offset) $("headlines-frame").scrollTop -= (old_offset-new_offset); - if (!noexpand) - toggleUnread(id, 0, true); + if (!noexpand) { + if (catchup_id_batch.indexOf(id) == -1) + catchup_id_batch.push(id); + + catchupCurrentBatchIfNeeded(); + } + toggleSelected(id); $("RROW-" + id).addClassName("active"); @@ -1613,117 +1639,11 @@ function show_labels_in_headlines(transport) { } } -function dismissArticle(id) { - try { - var elem = $("RROW-" + id); - - if (!elem) return; - - toggleUnread(id, 0, true); - - new Effect.Fade(elem, {duration : 0.5}); - - // Remove the content, too - var elem_content = $("CICD-" + id); - if (elem_content) { - Element.remove(elem_content); - } - - if (id == getActiveArticleId()) { - setActiveArticleId(0); - } - - } catch (e) { - exception_error("dismissArticle", e); - } -} - -function dismissSelectedArticles() { - try { - - var ids = getVisibleArticleIds(); - var tmp = []; - var sel = []; - - for (var i = 0; i < ids.length; i++) { - var elem = $("RROW-" + ids[i]); - - if (elem.className && elem.hasClassName("Selected") && - ids[i] != getActiveArticleId()) { - new Effect.Fade(elem, {duration : 0.5}); - sel.push(ids[i]); - - // Remove the content, too - var elem_content = $("CICD-" + ids[i]); - if (elem_content) { - Element.remove(elem_content); - } - } else { - tmp.push(ids[i]); - } - } - - if (sel.length > 0) - selectionToggleUnread(false); - - - } catch (e) { - exception_error("dismissSelectedArticles", e); - } -} - -function dismissReadArticles() { - try { - - var ids = getVisibleArticleIds(); - var tmp = []; - - for (var i = 0; i < ids.length; i++) { - var elem = $("RROW-" + ids[i]); - - if (elem.className && !elem.hasClassName("Unread") && - !elem.hasClassName("Selected")) { - - new Effect.Fade(elem, {duration : 0.5}); - - // Remove the content, too - var elem_content = $("CICD-" + ids[i]); - if (elem_content) { - Element.remove(elem_content); - } - } else { - tmp.push(ids[i]); - } - } - - } catch (e) { - exception_error("dismissReadArticles", e); - } -} - -function getVisibleArticleIds() { - var ids = []; - - try { - - getLoadedArticleIds().each(function(id) { - var elem = $("RROW-" + id); - if (elem && Element.visible(elem)) - ids.push(id); - }); - - } catch (e) { - exception_error("getVisibleArticleIds", e); - } - - return ids; -} - function cdmClicked(event, id) { try { //var shift_key = event.shiftKey; - if (!event.ctrlKey) { + if (!event.ctrlKey && !event.metaKey) { if (!getInitParam("cdm_expanded")) { return cdmExpandArticle(id); @@ -1761,7 +1681,8 @@ function cdmClicked(event, id) { return !event.shiftKey; } - } else { + } else if (event.target.parents(".cdmHeader").length > 0) { + toggleSelected(id, true); var elem = $("RROW-" + id); @@ -1791,7 +1712,7 @@ function hlClicked(event, id) { if (event.which == 2) { view(id); return true; - } else if (event.ctrlKey) { + } else if (event.ctrlKey || event.metaKey) { toggleSelected(id, true); toggleUnread(id, 0, false); openArticleInNewWindow(id); @@ -1806,20 +1727,12 @@ function hlClicked(event, id) { } } -function getFirstVisibleHeadlineId() { - var rows = getVisibleArticleIds(); - return rows[0]; - -} - -function getLastVisibleHeadlineId() { - var rows = getVisibleArticleIds(); - return rows[rows.length-1]; -} - function openArticleInNewWindow(id) { toggleUnread(id, 0, false); - window.open("backend.php?op=article&method=redirect&id=" + id); + + var w = window.open(""); + w.opener = null; + w.location = "backend.php?op=article&method=redirect&id=" + id; } function isCdmMode() { @@ -1853,7 +1766,7 @@ function getRelativePostIds(id, limit) { if (!limit) limit = 6; //3 - var ids = getVisibleArticleIds(); + var ids = getLoadedArticleIds(); for (var i = 0; i < ids.length; i++) { if (ids[i] == id) { @@ -1923,37 +1836,49 @@ function closeArticlePanel() { function initFloatingMenu() { try { - if (dijit.byId("floatingMenu")) - dijit.byId("floatingMenu").destroyRecursive(); + if (!dijit.byId("floatingMenu")) { var menu = new dijit.Menu({ id: "floatingMenu", targetNodeIds: ["floatingTitle"] }); - var id = $("floatingTitle").getAttribute("rowid").replace("RROW-", ""); + var tmph = dojo.connect(menu, '_openMyself', function (event) { + var callerNode = event.target, match = null, tries = 0; + + while (match == null && callerNode && tries <= 3) { + match = callerNode.getAttribute("data-article-id"); + callerNode = callerNode.parentNode; + ++tries; + } + + if (match) this.callerRowId = match; - headlinesMenuCommon(menu, id); + }); + + headlinesMenuCommon(menu); menu.startup(); + } + } catch (e) { exception_error("initFloatingMenu", e); } } -function headlinesMenuCommon(menu, base_id) { +function headlinesMenuCommon(menu) { try { menu.addChild(new dijit.MenuItem({ label: __("Open original article"), onClick: function(event) { - openArticleInNewWindow(base_id ? base_id : this.getParent().callerRowId); + openArticleInNewWindow(this.getParent().callerRowId); }})); menu.addChild(new dijit.MenuItem({ label: __("Display article URL"), onClick: function(event) { - displayArticleUrl(base_id ? base_id : this.getParent().callerRowId); + displayArticleUrl(this.getParent().callerRowId); }})); menu.addChild(new dijit.MenuSeparator()); @@ -1963,7 +1888,7 @@ function headlinesMenuCommon(menu, base_id) { onClick: function(event) { var ids = getSelectedArticleIds2(); // cast to string - var id = (base_id ? base_id : this.getParent().callerRowId) + ""; + var id = (this.getParent().callerRowId) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; selectionToggleUnread(undefined, false, true, ids); @@ -1974,7 +1899,7 @@ function headlinesMenuCommon(menu, base_id) { onClick: function(event) { var ids = getSelectedArticleIds2(); // cast to string - var id = (base_id ? base_id : this.getParent().callerRowId) + ""; + var id = (this.getParent().callerRowId) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; selectionToggleMarked(undefined, false, true, ids); @@ -1985,7 +1910,7 @@ function headlinesMenuCommon(menu, base_id) { onClick: function(event) { var ids = getSelectedArticleIds2(); // cast to string - var id = (base_id ? base_id : this.getParent().callerRowId) + ""; + var id = (this.getParent().callerRowId) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; selectionTogglePublished(undefined, false, true, ids); @@ -1996,13 +1921,13 @@ function headlinesMenuCommon(menu, base_id) { menu.addChild(new dijit.MenuItem({ label: __("Mark above as read"), onClick: function(event) { - catchupRelativeToArticle(0, base_id ? base_id : this.getParent().callerRowId); + catchupRelativeToArticle(0, this.getParent().callerRowId); }})); menu.addChild(new dijit.MenuItem({ label: __("Mark below as read"), onClick: function(event) { - catchupRelativeToArticle(1, base_id ? base_id : this.getParent().callerRowId); + catchupRelativeToArticle(1, this.getParent().callerRowId); }})); @@ -2028,7 +1953,7 @@ function headlinesMenuCommon(menu, base_id) { onClick: function(event) { var ids = getSelectedArticleIds2(); // cast to string - var id = (base_id ? base_id : this.getParent().ownerMenu.callerRowId) + ""; + var id = (this.getParent().ownerMenu.callerRowId) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -2041,7 +1966,7 @@ function headlinesMenuCommon(menu, base_id) { onClick: function(event) { var ids = getSelectedArticleIds2(); // cast to string - var id = (base_id ? base_id : this.getParent().ownerMenu.callerRowId) + ""; + var id = (this.getParent().ownerMenu.callerRowId) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -2052,12 +1977,12 @@ function headlinesMenuCommon(menu, base_id) { menu.addChild(new dijit.PopupMenuItem({ label: __("Assign label"), - popup: labelAddMenu, + popup: labelAddMenu })); menu.addChild(new dijit.PopupMenuItem({ label: __("Remove label"), - popup: labelDelMenu, + popup: labelDelMenu })); } @@ -2068,44 +1993,138 @@ function headlinesMenuCommon(menu, base_id) { } } -function initHeadlinesMenu() { +function initHeadlinesMenu(append_rows) { try { - if (dijit.byId("headlinesMenu")) - dijit.byId("headlinesMenu").destroyRecursive(); + if (!append_rows) { - var ids = []; + if (dijit.byId("headlinesMenu")) + dijit.byId("headlinesMenu").destroyRecursive(); + + var ids = []; + + if (!isCdmMode()) { + nodes = $$("#headlines-frame > div[id*=RROW]"); + } else { + nodes = $$("#headlines-frame span[id*=RTITLE]"); + } + + nodes.each(function (node) { + ids.push(node.id); + }); + + var menu = new dijit.Menu({ + id: "headlinesMenu", + targetNodeIds: ids + }); + + var tmph = dojo.connect(menu, '_openMyself', function (event) { + var callerNode = event.target, match = null, tries = 0; + + while (match == null && callerNode && tries <= 3) { + + match = callerNode.getAttribute("data-article-id") + callerNode = callerNode.parentNode; + ++tries; + } + + if (match) this.callerRowId = match; + + }); + + headlinesMenuCommon(menu); + + menu.startup(); - if (!isCdmMode()) { - nodes = $$("#headlines-frame > div[id*=RROW]"); } else { - nodes = $$("#headlines-frame span[id*=RTITLE]"); + var menu = dijit.byId("headlinesMenu"); + + append_rows.each(function (row) { + if (!row.hasClassName("cdmFeedTitle")) { + menu.bindDomNode(row); + } + }); } - nodes.each(function(node) { - ids.push(node.id); - }); + /* vgroup feed title menu */ - var menu = new dijit.Menu({ - id: "headlinesMenu", - targetNodeIds: ids, - }); + if (!append_rows) { - var tmph = dojo.connect(menu, '_openMyself', function (event) { - var callerNode = event.target, match = null, tries = 0; + var nodes = $$("#headlines-frame > div[class='cdmFeedTitle']"); + var ids = []; - while (match == null && callerNode && tries <= 3) { - match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$"); - callerNode = callerNode.parentNode; - ++tries; - } + nodes.each(function(node) { + ids.push(node.id); + }); - if (match) this.callerRowId = parseInt(match[1]); + if (ids.length > 0) { + if (dijit.byId("headlinesFeedTitleMenu")) + dijit.byId("headlinesFeedTitleMenu").destroyRecursive(); - }); + var menu = new dijit.Menu({ + id: "headlinesFeedTitleMenu", + targetNodeIds: ids + }); + + var tmph = dojo.connect(menu, '_openMyself', function (event) { + var callerNode = event.target, match = null, tries = 0; + + while (match == null && callerNode && tries <= 3) { + match = callerNode.getAttribute("data-feed-id") + callerNode = callerNode.parentNode; + ++tries; + } + + if (match) this.callerRowId = match; + + }); + + menu.addChild(new dijit.MenuItem({ + label: __("Select articles in group"), + onClick: function (event) { + selectArticles("all", + "#headlines-frame > div[id*=RROW]" + + "[data-orig-feed-id='" + menu.callerRowId + "']"); - headlinesMenuCommon(menu, false); + } + })); - menu.startup(); + menu.addChild(new dijit.MenuItem({ + label: __("Mark group as read"), + onClick: function (event) { + selectArticles("none"); + selectArticles("all", + "#headlines-frame > div[id*=RROW]" + + "[data-orig-feed-id='" + menu.callerRowId + "']"); + + catchupSelection(); + } + })); + + menu.addChild(new dijit.MenuItem({ + label: __("Mark feed as read"), + onClick: function (event) { + catchupFeedInGroup(menu.callerRowId); + } + })); + + menu.addChild(new dijit.MenuItem({ + label: __("Edit feed"), + onClick: function (event) { + editFeed(menu.callerRowId); + } + })); + + menu.startup(); + } + } else { + var menu = dijit.byId("headlinesFeedTitleMenu"); + + append_rows.each(function (row) { + if (row.hasClassName("cdmFeedTitle")) { + menu.bindDomNode(row); + } + }); + } } catch (e) { exception_error("initHeadlinesMenu", e); @@ -2191,6 +2210,34 @@ function setSelectionScore() { } } +function updateScore(id) { + try { + var pic = $$("#RROW-" + id + " .hlScorePic")[0]; + + if (pic) { + + var query = "op=article&method=getScore&id=" + param_escape(id); + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + console.log(transport.responseText); + + var reply = JSON.parse(transport.responseText); + + if (reply) { + pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); + pic.setAttribute("score", reply["score"]); + pic.setAttribute("title", reply["score"]); + } + } }); + } + + } catch (e) { + exception_error("updateScore", e); + } +} + function changeScore(id, pic) { try { var score = pic.getAttribute("score"); @@ -2210,6 +2257,7 @@ function changeScore(id, pic) { if (reply) { pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]); pic.setAttribute("score", new_score); + pic.setAttribute("title", new_score); } } }); } @@ -2236,26 +2284,12 @@ function displayArticleUrl(id) { } } -function openSelectedAttachment(elem) { - try { - var url = elem[elem.selectedIndex].value; - - if (url) { - window.open(url); - elem.selectedIndex = 0; - } - - } catch (e) { - exception_error("openSelectedAttachment", e); - } -} - function scrollToRowId(id) { try { var row = $(id); if (row) - $("headlines-frame").scrollTop = row.offsetTop; + $("headlines-frame").scrollTop = row.offsetTop - 4; } catch (e) { exception_error("scrollToRowId", e); @@ -2278,9 +2312,10 @@ function updateFloatingTitle(unread_only) { var header = child.getElementsByClassName("cdmHeader")[0]; - if (unread_only || child.id != $("floatingTitle").getAttribute("rowid")) { - if (child.id != $("floatingTitle").getAttribute("rowid")) { - $("floatingTitle").setAttribute("rowid", child.id); + if (unread_only || child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) { + if (child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) { + + $("floatingTitle").setAttribute("data-article-id", child.getAttribute("data-article-id")); $("floatingTitle").innerHTML = header.innerHTML; $("floatingTitle").firstChild.innerHTML = "" + $("floatingTitle").firstChild.innerHTML; @@ -2300,11 +2335,12 @@ function updateFloatingTitle(unread_only) { PluginHost.run(PluginHost.HOOK_FLOATING_TITLE, child); } - if (child.offsetTop < hf.scrollTop - header.offsetHeight && - child.offsetTop + child.offsetHeight - hf.scrollTop > header.offsetHeight) - Element.show("floatingTitle"); + $("floatingTitle").style.marginRight = hf.offsetWidth - child.offsetWidth + "px"; + if (header.offsetTop + header.offsetHeight < hf.scrollTop + $("floatingTitle").offsetHeight - 5 && + child.offsetTop + child.offsetHeight >= hf.scrollTop + $("floatingTitle").offsetHeight - 5) + $("floatingTitle").style.visibility = "visible"; else - Element.hide("floatingTitle"); + $("floatingTitle").style.visibility = "hidden"; return; @@ -2315,3 +2351,18 @@ function updateFloatingTitle(unread_only) { exception_error("updateFloatingTitle", e); } } + +function catchupCurrentBatchIfNeeded() { + if (catchup_id_batch.length > 0) { + window.clearTimeout(catchup_timeout_id); + catchup_timeout_id = window.setTimeout(catchupBatchedArticles, 1000); + + if (catchup_id_batch.length >= 10) { + catchupBatchedArticles(); + } + } +} + +function cdmFooterClick(event) { + event.stopPropagation(); +} \ No newline at end of file