X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=js%2Fviewfeed.js;h=9672c47ba6acdebbf5998d6f8b5fdc34992f0c67;hb=6472dd11a2b7d00421a2c3fa93f7de4fcbc88832;hp=da3628349bb0ccc8945c6d2dcd83f6df7665bd1a;hpb=da3077d1b10571f8c10d548071a0c4171dd90485;p=tt-rss.git diff --git a/js/viewfeed.js b/js/viewfeed.js index da362834..9672c47b 100644 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -55,9 +55,18 @@ function headlines_callback2(transport, offset, background, infscroll_req) { try { if (infscroll_req == false) { $("headlines-frame").scrollTop = 0; + + Element.hide("floatingTitle"); + $("floatingTitle").setAttribute("rowid", 0); + $("floatingTitle").innerHTML = ""; } } catch (e) { }; + $("headlines-frame").removeClassName("cdm"); + $("headlines-frame").removeClassName("normal"); + + $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal"); + var headlines_count = reply['headlines-info']['count']; vgroup_last_feed = reply['headlines-info']['vgroup_last_feed']; @@ -78,8 +87,12 @@ function headlines_callback2(transport, offset, background, infscroll_req) { dijit.byId("headlines-frame").attr('content', reply['headlines']['content']); - dijit.byId("headlines-toolbar").attr('content', - reply['headlines']['toolbar']); + //dijit.byId("headlines-toolbar").attr('content', + // reply['headlines']['toolbar']); + + dojo.html.set($("headlines-toolbar"), + reply['headlines']['toolbar'], + {parseContent: true}); $$("#headlines-frame > div[id*=RROW]").each(function(row) { if (loaded_article_ids.indexOf(row.id) != -1) { @@ -181,14 +194,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; @@ -305,13 +315,11 @@ 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 @@ -439,7 +447,21 @@ function toggleMark(id, client_only) { var row = $("RROW-" + id); if (!row) return; - var imgs = row.getElementsByClassName("markedPic"); + var imgs = []; + + var row_imgs = row.getElementsByClassName("markedPic"); + + for (var i = 0; i < row_imgs.length; i++) + imgs.push(row_imgs[i]); + + var ft = $("floatingTitle"); + + if (ft && ft.getAttribute("rowid") == "RROW-" + id) { + var fte = ft.getElementsByClassName("markedPic"); + + for (var i = 0; i < fte.length; i++) + imgs.push(fte[i]); + } for (i = 0; i < imgs.length; i++) { var img = imgs[i]; @@ -483,7 +505,21 @@ function togglePub(id, client_only, no_effects, note) { var row = $("RROW-" + id); if (!row) return; - var imgs = row.getElementsByClassName("pubPic"); + var imgs = []; + + var row_imgs = row.getElementsByClassName("pubPic"); + + for (var i = 0; i < row_imgs.length; i++) + imgs.push(row_imgs[i]); + + var ft = $("floatingTitle"); + + if (ft && ft.getAttribute("rowid") == "RROW-" + id) { + var fte = ft.getElementsByClassName("pubPic"); + + for (var i = 0; i < fte.length; i++) + imgs.push(fte[i]); + } for (i = 0; i < imgs.length; i++) { var img = imgs[i]; @@ -585,7 +621,7 @@ function moveToPost(mode, noscroll, noexpand) { if (!getInitParam("cdm_expanded")) { - if (!noscroll && article.offsetTop < ctr.scrollTop) { + if (!noscroll && article && article.offsetTop < ctr.scrollTop) { scrollArticle(-ctr.offsetHeight/4); } else { cdmExpandArticle(prev_id, noexpand); @@ -798,6 +834,8 @@ function selectionToggleUnread(set_state, callback, no_error, ids) { } } + updateFloatingTitle(true); + if (rows.length > 0) { var cmode = ""; @@ -922,10 +960,12 @@ function getLoadedArticleIds() { } // 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-", ""); @@ -1204,7 +1244,7 @@ function postMouseOut(id) { function unpackVisibleHeadlines() { try { - if (!isCdmMode()) return; + if (!isCdmMode() || !getInitParam("cdm_expanded")) return; $$("#headlines-frame > div[id*=RROW]").each( function(child) { @@ -1235,6 +1275,32 @@ function headlines_scroll_handler(e) { unpackVisibleHeadlines(); + // set topmost child in the buffer as active + 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++) { + var child = rows[i]; + + if ($("headlines-frame").scrollTop <= child.offsetTop && + child.offsetTop - $("headlines-frame").scrollTop < 100 && + child.id.replace("RROW-", "") != _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-", ""); + showArticleInHeadlines(_active_article_id, true); + updateSelectedPrompt(); + break; + } + } + } + if (!_infscroll_disable) { if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) || (e.scrollHeight != 0 && @@ -1252,6 +1318,10 @@ function headlines_scroll_handler(e) { if (hsp) hsp.innerHTML = ""; } + if (isCdmMode()) { + updateFloatingTitle(); + } + if (getInitParam("cdm_auto_catchup") == 1) { // let's get DOM some time to settle down @@ -1270,6 +1340,7 @@ function headlines_scroll_handler(e) { //console.log("auto_catchup_batch: " + catchup_id_batch.toString()); } + }); if (catchup_id_batch.length > 0) { @@ -1313,6 +1384,8 @@ function catchupBatchedArticles() { catchup_id_batch.remove(id); }); + updateFloatingTitle(true); + } }); } @@ -1421,6 +1494,12 @@ function cdmCollapseArticle(event, id, unmark) { if (event) Event.stop(event); PluginHost.run(PluginHost.HOOK_ARTICLE_COLLAPSED, id); + + if (row.offsetTop < $("headlines-frame").scrollTop) + scrollToRowId(row.id); + + Element.hide("floatingTitle"); + $("floatingTitle").setAttribute("rowid", false); } } catch (e) { @@ -1525,9 +1604,9 @@ function show_labels_in_headlines(transport) { if (data) { data['info-for-headlines'].each(function(elem) { - var ctr = $("HLLCTR-" + elem.id); - - if (ctr) ctr.innerHTML = elem.labels; + $$(".HLLCTR-" + elem.id).each(function(ctr) { + ctr.innerHTML = elem.labels; + }); }); } } catch (e) { @@ -1545,6 +1624,12 @@ function dismissArticle(id) { 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); } @@ -1568,6 +1653,12 @@ function dismissSelectedArticles() { 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]); } @@ -1595,13 +1686,19 @@ function dismissReadArticles() { !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("dismissSelectedArticles", e); + exception_error("dismissReadArticles", e); } } @@ -1650,6 +1747,7 @@ function cdmClicked(event, id) { if (article_is_unread) { decrementFeedCounter(getActiveFeedId(), activeFeedIsCat()); + updateFloatingTitle(true); } var query = "?op=rpc&method=catchupSelected" + @@ -1664,7 +1762,8 @@ function cdmClicked(event, id) { return !event.shiftKey; } - } else { + } else if (event.target.parents(".cdmHeader").length > 0) { + toggleSelected(id, true); var elem = $("RROW-" + id); @@ -1824,58 +1923,39 @@ function closeArticlePanel() { dijit.byId("content-insert")); } -function initHeadlinesMenu() { +function initFloatingMenu() { try { - 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]"); - } + if (dijit.byId("floatingMenu")) + dijit.byId("floatingMenu").destroyRecursive(); - 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; + var menu = new dijit.Menu({ + id: "floatingMenu", + targetNodeIds: ["floatingTitle"] + }); - while (match == null && callerNode && tries <= 3) { - match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$"); - callerNode = callerNode.parentNode; - ++tries; - } + var id = $("floatingTitle").getAttribute("rowid").replace("RROW-", ""); - if (match) this.callerRowId = parseInt(match[1]); + headlinesMenuCommon(menu, id); - }); + menu.startup(); + } catch (e) { + exception_error("initFloatingMenu", e); + } +} -/* if (!isCdmMode()) - menu.addChild(new dijit.MenuItem({ - label: __("View article"), - onClick: function(event) { - view(this.getParent().callerRowId); - }})); */ +function headlinesMenuCommon(menu, base_id) { + try { menu.addChild(new dijit.MenuItem({ label: __("Open original article"), onClick: function(event) { - openArticleInNewWindow(this.getParent().callerRowId); + openArticleInNewWindow(base_id ? base_id : this.getParent().callerRowId); }})); menu.addChild(new dijit.MenuItem({ label: __("Display article URL"), onClick: function(event) { - displayArticleUrl(this.getParent().callerRowId); + displayArticleUrl(base_id ? base_id : this.getParent().callerRowId); }})); menu.addChild(new dijit.MenuSeparator()); @@ -1885,18 +1965,18 @@ function initHeadlinesMenu() { onClick: function(event) { var ids = getSelectedArticleIds2(); // cast to string - var id = this.getParent().callerRowId + ""; + var id = (base_id ? base_id : this.getParent().callerRowId) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; selectionToggleUnread(undefined, false, true, ids); }})); menu.addChild(new dijit.MenuItem({ - label: __("Toggle marked"), + label: __("Toggle starred"), onClick: function(event) { var ids = getSelectedArticleIds2(); // cast to string - var id = this.getParent().callerRowId + ""; + var id = (base_id ? base_id : this.getParent().callerRowId) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; selectionToggleMarked(undefined, false, true, ids); @@ -1907,7 +1987,7 @@ function initHeadlinesMenu() { onClick: function(event) { var ids = getSelectedArticleIds2(); // cast to string - var id = this.getParent().callerRowId + ""; + var id = (base_id ? base_id : this.getParent().callerRowId) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; selectionTogglePublished(undefined, false, true, ids); @@ -1918,13 +1998,13 @@ function initHeadlinesMenu() { menu.addChild(new dijit.MenuItem({ label: __("Mark above as read"), onClick: function(event) { - catchupRelativeToArticle(0, this.getParent().callerRowId); + catchupRelativeToArticle(0, base_id ? base_id : this.getParent().callerRowId); }})); menu.addChild(new dijit.MenuItem({ label: __("Mark below as read"), onClick: function(event) { - catchupRelativeToArticle(1, this.getParent().callerRowId); + catchupRelativeToArticle(1, base_id ? base_id : this.getParent().callerRowId); }})); @@ -1950,7 +2030,7 @@ function initHeadlinesMenu() { onClick: function(event) { var ids = getSelectedArticleIds2(); // cast to string - var id = this.getParent().ownerMenu.callerRowId + ""; + var id = (base_id ? base_id : this.getParent().ownerMenu.callerRowId) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -1963,7 +2043,7 @@ function initHeadlinesMenu() { onClick: function(event) { var ids = getSelectedArticleIds2(); // cast to string - var id = this.getParent().ownerMenu.callerRowId + ""; + var id = (base_id ? base_id : this.getParent().ownerMenu.callerRowId) + ""; ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -1984,8 +2064,117 @@ function initHeadlinesMenu() { } + + } catch (e) { + exception_error("headlinesMenuCommon", e); + } +} + +function initHeadlinesMenu() { + try { + 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.id.match("^[A-Z]+[-]([0-9]+)$"); + callerNode = callerNode.parentNode; + ++tries; + } + + if (match) this.callerRowId = parseInt(match[1]); + + }); + + headlinesMenuCommon(menu, false); + menu.startup(); + /* vgroup feed title menu */ + + var nodes = $$("#headlines-frame > div[class='cdmFeedTitle']"); + var ids = []; + + nodes.each(function(node) { + ids.push(node.id); + }); + + 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) { + console.log(callerNode.id); + + match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$"); + callerNode = callerNode.parentNode; + ++tries; + + console.log(match[1]); + } + + if (match) this.callerRowId = parseInt(match[1]); + + }); + + menu.addChild(new dijit.MenuItem({ + label: __("Select articles in group"), + onClick: function(event) { + selectArticles("all", + "#headlines-frame > div[id*=RROW]"+ + "[orig-feed-id='"+menu.callerRowId+"']"); + + }})); + + menu.addChild(new dijit.MenuItem({ + label: __("Mark group as read"), + onClick: function(event) { + selectArticles("none"); + selectArticles("all", + "#headlines-frame > div[id*=RROW]"+ + "[orig-feed-id='"+menu.callerRowId+"']"); + + catchupSelection(); + }})); + + + menu.addChild(new dijit.MenuItem({ + label: __("Mark feed as read"), + onClick: function(event) { + catchupFeedInGroup(menu.callerRowId); + }})); + + menu.startup(); + + } + } catch (e) { exception_error("initHeadlinesMenu", e); } @@ -2128,3 +2317,69 @@ function openSelectedAttachment(elem) { exception_error("openSelectedAttachment", e); } } + +function scrollToRowId(id) { + try { + var row = $(id); + + if (row) + $("headlines-frame").scrollTop = row.offsetTop; + + } catch (e) { + exception_error("scrollToRowId", e); + } +} + +function updateFloatingTitle(unread_only) { + try { + if (!isCdmMode()) return; + + var hf = $("headlines-frame"); + + var elems = $$("#headlines-frame > div[id*=RROW]"); + + for (var i = 0; i < elems.length; i++) { + + var child = elems[i]; + + if (child && child.offsetTop + child.offsetHeight > hf.scrollTop) { + + 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); + $("floatingTitle").innerHTML = header.innerHTML; + $("floatingTitle").firstChild.innerHTML = "" + $("floatingTitle").firstChild.innerHTML; + + initFloatingMenu(); + + var cb = $$("#floatingTitle .dijitCheckBox")[0]; + + if (cb) + cb.parentNode.removeChild(cb); + } + + if (child.hasClassName("Unread")) + $("floatingTitle").addClassName("Unread"); + else + $("floatingTitle").removeClassName("Unread"); + + 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"); + else + Element.hide("floatingTitle"); + + return; + + } + } + + } catch (e) { + exception_error("updateFloatingTitle", e); + } +}