]> git.wh0rd.org - tt-rss.git/blobdiff - viewfeed.js
add post header menu
[tt-rss.git] / viewfeed.js
index cdb09864f0f44d730ac5092feb38e741ef5c2fc7..dadbe94852fd021e8234a4b18abdb93a5bba8953 100644 (file)
@@ -35,7 +35,7 @@ function headlines_callback2(transport, feed_cur_page) {
 
                if (!handle_rpc_reply(transport)) return;
 
-               loading_set_progress(100);
+               loading_set_progress(25);
 
                console.log("headlines_callback2 [page=" + feed_cur_page + "]");
 
@@ -98,11 +98,13 @@ function headlines_callback2(transport, feed_cur_page) {
        
                        if (feed_cur_page == 0) {
                                if (headlines) {
-                                       $("headlinesInnerContainer").innerHTML = headlines_content.firstChild.nodeValue;
-                                       $("headlines-toolbar").innerHTML = headlines_toolbar.firstChild.nodeValue;
+                                       dijit.byId("headlines-frame").attr('content', 
+                                               headlines_content.firstChild.nodeValue);
 
-                                       dojo.parser.parse("headlines-toolbar");
-                                       //dijit.byId("main").resize();
+                                       dijit.byId("headlines-toolbar").attr('content',
+                                               headlines_toolbar.firstChild.nodeValue);
+
+                                       initHeadlinesMenu();
 
                                        var cache_prefix = "";
 
@@ -121,19 +123,21 @@ function headlines_callback2(transport, feed_cur_page) {
 
                                } else {
                                        console.warn("headlines_callback: returned no data");
-                               $('headlinesInnerContainer').innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
+                                       dijit.byId("headlines-frame").attr('content', 
+                                               "<div class='whiteBox'>" + 
+                                               __('Could not update headlines (missing XML data)') + "</div>");
        
                                }
                        } else {
                                if (headlines) {
                                        if (headlines_count > 0) {
                                                console.log("adding some more headlines...");
-       
-                                               c = $("headlinesInnerContainer");
 
+                                               var c = dijit.byId("headlines-frame");  
                                                var ids = getSelectedArticleIds2();
        
-                                               c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
+                                               c.attr('content', c.attr('content') + 
+                                                       headlines_content.firstChild.nodeValue);
 
                                                console.log("restore selected ids: " + ids);
 
@@ -141,6 +145,8 @@ function headlines_callback2(transport, feed_cur_page) {
                                                        markHeadline(ids[i]);
                                                }
 
+                                               initHeadlinesMenu();
+
                                        } else {
                                                console.log("no new headlines received");
                                        }
@@ -172,7 +178,8 @@ function headlines_callback2(transport, feed_cur_page) {
        
                } else {
                        console.warn("headlines_callback: returned no XML object");
-                       $('headlinesInnerContainer').innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
+                       dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" + 
+                                       __('Could not update headlines (missing XML object)') + "</div>");
                }
        
 
@@ -193,8 +200,6 @@ function headlines_callback2(transport, feed_cur_page) {
 
                notify("");
 
-               remove_splash();
-
        } catch (e) {
                exception_error("headlines_callback2", e, transport);
        }
@@ -202,23 +207,18 @@ function headlines_callback2(transport, feed_cur_page) {
 
 function render_article(article) {
        try {
-               var f = $("content-frame");
-               try {
-                       f.scrollTop = 0;
-               } catch (e) { };
-
                dijit.byId("headlines-wrap-inner").addChild(
                                dijit.byId("content-insert"));
 
-               var fi = $("content-insert");
+               var c = dijit.byId("content-insert");
 
                try {
-                       fi.scrollTop = 0;
+                       c.domNode.scrollTop = 0;
                } catch (e) { };
                
-               fi.innerHTML = article;
-               
-//             article.evalScripts();          
+               c.attr('content', article);
+
+               correctHeadlinesOffset(getActiveArticleId());           
 
        } catch (e) {
                exception_error("render_article", e);
@@ -269,7 +269,7 @@ function showArticleInHeadlines(id) {
 
                        cache_inject(cache_prefix + getActiveFeedId(),
                                $("headlines-frame").innerHTML,
-                               get_feed_unread(getActiveFeedId()));
+                               getFeedUnread(getActiveFeedId()));
 
                } else if (article_is_unread && view_mode == "all_articles") {
 
@@ -277,7 +277,7 @@ function showArticleInHeadlines(id) {
 
                        cache_inject(cache_prefix + getActiveFeedId(),
                                $("headlines-frame").innerHTML,
-                               get_feed_unread(getActiveFeedId())-1);
+                               getFeedUnread(getActiveFeedId())-1);
 
                } else if (article_is_unread) {
                        cache_invalidate(cache_prefix + getActiveFeedId());
@@ -873,7 +873,7 @@ function getSelectedArticleIds2() {
 
        var rv = [];
 
-       $$("#headlinesInnerContainer > div[id*=RROW][class*=Selected]").each(
+       $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
                function(child) {
                        rv.push(child.id.replace("RROW-", ""));
                });
@@ -884,7 +884,7 @@ function getSelectedArticleIds2() {
 function getLoadedArticleIds() {
        var rv = [];
 
-       var children = $$("#headlinesInnerContainer > div[id*=RROW-]");
+       var children = $$("#headlines-frame > div[id*=RROW-]");
 
        children.each(function(child) {
                        rv.push(child.id.replace("RROW-", ""));
@@ -898,7 +898,7 @@ function getLoadedArticleIds() {
 function selectArticles(mode) {
        try {
 
-               var children = $$("#headlinesInnerContainer > div[id*=RROW]");
+               var children = $$("#headlines-frame > div[id*=RROW]");
 
                children.each(function(child) {
                        var id = child.id.replace("RROW-", "");
@@ -1171,7 +1171,7 @@ function cdmWatchdog() {
 
        try {
 
-               var ctr = $("headlinesInnerContainer");
+               var ctr = $("headlines-frame");
 
                if (!ctr) return;
 
@@ -1518,16 +1518,9 @@ function postMouseOut(id) {
        }
 }
 
-function headlines_scroll_handler() {
+function headlines_scroll_handler(e) {
        try {
 
-               var e = $("headlinesInnerContainer");
-
-               var toolbar_form = document.forms["main_toolbar_form"];
-
-//             console.log((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
-//                     _infscroll_disable);
-
                if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
                        if (!_infscroll_disable) {
                                viewNextFeedPage();
@@ -1716,19 +1709,17 @@ function getArticleUnderPointer() {
        return post_under_pointer;
 }
 
-function zoomToArticle(id) {
+function zoomToArticle(event, id) {
        try {
-               /* var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id), 
-                       "ttrss_zoom_" + id,
-                       "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0"); */
-
                var cached_article = cache_find(id);
 
                if (dijit.byId("ATAB-" + id))
-                       return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
+                       if (!event || !event.shiftKey)
+                               return dijit.byId("content-tabs").selectChild(dijit.byId("ATAB-" + id));
 
                if (cached_article) {
-                       
+                       //closeArticlePanel();
+               
                        var article_pane = new dijit.layout.ContentPane({ 
                                title: __("Loading...") , content: cached_article, 
                                style: 'padding : 0px;',
@@ -1736,7 +1727,9 @@ function zoomToArticle(id) {
                                closable: true });
        
                        dijit.byId("content-tabs").addChild(article_pane);
-                       dijit.byId("content-tabs").selectChild(article_pane);
+
+                       if (!event || !event.shiftKey)
+                               dijit.byId("content-tabs").selectChild(article_pane);
 
                        if ($("PTITLE-" + id))
                                article_pane.attr('title', $("PTITLE-" + id).innerHTML);
@@ -1753,7 +1746,7 @@ function zoomToArticle(id) {
                                        notify('');
        
                                        if (transport.responseXML) {
-                                               closeArticlePanel();
+                                               //closeArticlePanel();
        
                                                var article = transport.responseXML.getElementsByTagName("article")[0];
                                                var content = article.firstChild.nodeValue;
@@ -1765,7 +1758,9 @@ function zoomToArticle(id) {
                                                        closable: true });
        
                                                dijit.byId("content-tabs").addChild(article_pane);
-                                               dijit.byId("content-tabs").selectChild(article_pane);
+
+                                               if (!event || !event.shiftKey)
+                                                       dijit.byId("content-tabs").selectChild(article_pane);
 
                                                if ($("PTITLE-" + id))
                                                        article_pane.attr('title', $("PTITLE-" + id).innerHTML);
@@ -1787,7 +1782,7 @@ function scrollArticle(offset) {
                                ci.scrollTop += offset;
                        }
                } else {
-                       var hi = $("headlinesInnerContainer");
+                       var hi = $("headlines-frame");
                        if (hi) {
                                hi.scrollTop += offset;
                        }
@@ -2062,7 +2057,7 @@ function cdmClicked(event, id) {
                } else {
                        toggleSelected(id, true);
                        toggleUnread(id, 0, false);
-                       zoomToArticle(id);
+                       zoomToArticle(event, id);
                }
 
        } catch (e) {
@@ -2072,6 +2067,31 @@ function cdmClicked(event, id) {
        return false;
 }
 
+function postClicked(event, id) {
+       try {
+
+               if (!event.ctrlKey) {
+                       return true;
+               } else {
+                       postOpenInNewTab(event, id);
+                       return false;
+               }
+
+       } catch (e) {
+               exception_error("postClicked");
+       }
+}
+
+function hlOpenInNewTab(event, id) {
+       toggleUnread(id, 0, false);
+       zoomToArticle(event, id);
+}
+
+function postOpenInNewTab(event, id) {
+       closeArticlePanel(id);
+       zoomToArticle(event, id);
+}
+
 function hlClicked(event, id) {
        try {
 
@@ -2079,17 +2099,15 @@ function hlClicked(event, id) {
                        view(id);
                        return true;
                } else {
-                       toggleSelected(id, true);
+                       toggleSelected(id);
                        toggleUnread(id, 0, false);
-                       zoomToArticle(id);
+                       zoomToArticle(event, id);
                        return false;
                }
 
        } catch (e) {
                exception_error("hlClicked");
        }
-
-       return false;
 }
 
 function getFirstVisibleHeadlineId() {
@@ -2104,49 +2122,8 @@ function getLastVisibleHeadlineId() {
 }
 
 function openArticleInNewWindow(id) {
-       try {
-               console.log("openArticleInNewWindow: " + id);
-
-               var query = "?op=rpc&subop=getArticleLink&id=" + id;
-               var wname = "ttrss_article_" + id;
-
-               console.log(query + " " + wname);
-
-               var w = window.open("", wname);
-
-               if (!w) notify_error("Failed to open window for the article");
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) { 
-
-                                       var link = transport.responseXML.getElementsByTagName("link")[0];
-                                       var id = transport.responseXML.getElementsByTagName("id")[0];
-               
-                                       console.log("open_article received link: " + link);
-               
-                                       if (link && id) {
-               
-                                               var wname = "ttrss_article_" + id.firstChild.nodeValue;
-               
-                                               console.log("link url: " + link.firstChild.nodeValue + ", wname " + wname);
-               
-                                               var w = window.open(link.firstChild.nodeValue, wname);
-               
-                                               if (!w) { notify_error("Failed to load article in new window"); }
-               
-                                               if (id) {
-                                                       id = id.firstChild.nodeValue;
-                                                       window.setTimeout("toggleUnread(" + id + ", 0)", 100);
-                                               }
-                                       } else {
-                                               notify_error("Can't open article: received invalid article link");
-                                       }
-                               } });
-
-       } catch (e) {
-               exception_error("openArticleInNewWindow", e);
-       }
+       toggleUnread(id, 0, false);
+       window.open("backend.php?op=la&id=" + id);
 }
 
 function isCdmMode() {
@@ -2226,24 +2203,79 @@ function correctHeadlinesOffset(id) {
 
 function headlineActionsChange(elem) {
        try {
-               var op = elem[elem.selectedIndex].value;
-
-               eval(op);
-
+               eval(elem.value);
                elem.selectedIndex = 0;
-
        } catch (e) {
                exception_error("headlineActionsChange", e);
        }
 }
 
-function closeArticlePanel(id) {
+function closeArticlePanel() {
 
-       if (id)
-               if (dijit.byId("ATAB-" + id))
-                       return dijit.byId("content-tabs").removeChild(dijit.byId("ATAB-" + id));
+       var tabs = dijit.byId("content-tabs");
+       var child = tabs.selectedChildWidget;
+
+       if (child && tabs.getIndexOfChild(child) > 0) {
+               tabs.removeChild(child);
+               child.destroy();
+       } else {
+               if (dijit.byId("content-insert"))
+                       dijit.byId("headlines-wrap-inner").removeChild(
+                               dijit.byId("content-insert"));
+       }
+}
+
+function initHeadlinesMenu() {
+       try {
+               if (dijit.byId("headlinesMenu"))
+                       dijit.byId("headlinesMenu").destroyRecursive();
+
+               var ids = [];
+               var nodes = $$("#headlines-frame > div[id*=RROW]");
+
+               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;
 
-       if (dijit.byId("content-insert"))
-               dijit.byId("headlines-wrap-inner").removeChild(
-                       dijit.byId("content-insert"));
+                       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]);
+
+               });
+
+               menu.addChild(new dijit.MenuItem({
+                       label: __("View article"),
+                       onClick: function(event) {
+                               view(this.getParent().callerRowId);
+                       }}));
+
+               menu.addChild(new dijit.MenuItem({
+                       label: __("View in a new tab"),
+                       onClick: function(event) {
+                               hlOpenInNewTab(event, this.getParent().callerRowId);
+                       }}));
+
+               menu.addChild(new dijit.MenuItem({
+                       label: __("Open original article"),
+                       onClick: function(event) {
+                               openArticleInNewWindow(this.getParent().callerRowId);
+                       }}));
+
+               menu.startup();
+
+       } catch (e) {
+               exception_error("initHeadlinesMenu", e);
+       }
 }