From 65f0eb01aae3ae01b0f8a3b4e33683b717d8d3e5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 11 Jul 2013 16:49:25 +0400 Subject: [PATCH] support headlines context menu in floating title --- classes/feeds.php | 2 +- js/viewfeed.js | 120 ++++++++++++++++++++++++++++------------------ 2 files changed, 74 insertions(+), 48 deletions(-) diff --git a/classes/feeds.php b/classes/feeds.php index c57328fe..e71be4e5 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -316,7 +316,7 @@ class Feeds extends Handler_Protected { if (!is_array($labels)) $labels = get_article_labels($id); - $labels_str = ""; + $labels_str = ""; $labels_str .= format_article_labels($labels, $id); $labels_str .= ""; diff --git a/js/viewfeed.js b/js/viewfeed.js index 1785fe3f..57989eed 100644 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -1599,9 +1599,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) { @@ -1916,58 +1916,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]"); - } - - nodes.each(function(node) { - ids.push(node.id); - }); + if (dijit.byId("floatingMenu")) + dijit.byId("floatingMenu").destroyRecursive(); - var menu = new dijit.Menu({ - id: "headlinesMenu", - targetNodeIds: ids, - }); + var menu = new dijit.Menu({ + id: "floatingMenu", + targetNodeIds: ["floatingTitle"] + }); - var tmph = dojo.connect(menu, '_openMyself', function (event) { - var callerNode = event.target, match = null, tries = 0; + var id = $("floatingTitle").getAttribute("rowid").replace("RROW-", ""); - while (match == null && callerNode && tries <= 3) { - match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$"); - callerNode = callerNode.parentNode; - ++tries; - } + headlinesMenuCommon(menu, id); - if (match) this.callerRowId = parseInt(match[1]); - - }); + 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()); @@ -1977,7 +1958,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]; selectionToggleUnread(undefined, false, true, ids); @@ -1988,7 +1969,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]; selectionToggleMarked(undefined, false, true, ids); @@ -1999,7 +1980,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); @@ -2010,13 +1991,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); }})); @@ -2042,7 +2023,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]; @@ -2055,7 +2036,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]; @@ -2076,6 +2057,49 @@ 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(); } catch (e) { @@ -2252,6 +2276,8 @@ function updateFloatingTitle() { $("floatingTitle").innerHTML = header.innerHTML; $("floatingTitle").firstChild.innerHTML = "" + $("floatingTitle").firstChild.innerHTML; + initFloatingMenu(); + PluginHost.run(PluginHost.HOOK_FLOATING_TITLE, child); } -- 2.39.5