]> git.wh0rd.org - tt-rss.git/blobdiff - viewfeed.js
add post header menu
[tt-rss.git] / viewfeed.js
index 91502279a129321b57bf2516c6f184d4314c742b..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,20 +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);
@@ -266,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") {
 
@@ -274,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());
@@ -433,40 +436,6 @@ function tPub(id) {
        return togglePub(id);
 }
 
-function tMark_afh_off(effect) {
-       try {
-               var elem = effect.effects[0].element;
-
-               //console.log("tMark_afh_off : " + elem.id);
-
-               if (elem) {
-                       elem.src = elem.src.replace("mark_set", "mark_unset");
-                       elem.alt = __("Star article");
-                       Element.show(elem);
-               }
-
-       } catch (e) {
-               exception_error("tMark_afh_off", e);
-       }
-}
-
-function tPub_afh_off(effect) {
-       try {
-               var elem = effect.effects[0].element;
-
-               //console.log("tPub_afh_off : " + elem.id);
-
-               if (elem) {
-                       elem.src = elem.src.replace("pub_set", "pub_unset");
-                       elem.alt = __("Publish article");
-                       Element.show(elem);
-               }
-
-       } catch (e) {
-               exception_error("tPub_afh_off", e);
-       }
-}
-
 function toggleMark(id, client_only) {
        try {
                var query = "?op=rpc&id=" + id + "&subop=mark";
@@ -616,14 +585,14 @@ function moveToPost(mode) {
        }
 }
 
-function toggleSelected(id) {
+function toggleSelected(id, force_on) {
        try {
        
                var cb = $("RCHK-" + id);
                var row = $("RROW-" + id);
 
                if (row) {
-                       if (row.hasClassName('Selected')) {
+                       if (row.hasClassName('Selected') && !force_on) {
                                row.removeClassName('Selected');
                                if (cb) cb.checked = false;
                        } else {
@@ -904,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-", ""));
                });
@@ -915,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-", ""));
@@ -929,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-", "");
@@ -1125,7 +1094,7 @@ function editTagsSave() {
 
        query = "?op=rpc&subop=setArticleTags&" + query;
 
-       //console.log(query);
+       console.log(query);
 
        new Ajax.Request("backend.php", {
                parameters: query,
@@ -1202,7 +1171,7 @@ function cdmWatchdog() {
 
        try {
 
-               var ctr = $("headlinesInnerContainer");
+               var ctr = $("headlines-frame");
 
                if (!ctr) return;
 
@@ -1549,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();
@@ -1747,11 +1709,65 @@ 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))
+                       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;',
+                               id: 'ATAB-' + id,
+                               closable: true });
+       
+                       dijit.byId("content-tabs").addChild(article_pane);
+
+                       if (!event || !event.shiftKey)
+                               dijit.byId("content-tabs").selectChild(article_pane);
+
+                       if ($("PTITLE-" + id))
+                               article_pane.attr('title', $("PTITLE-" + id).innerHTML);
+
+               } else {
+
+                       var query = "?op=rpc&subop=getArticles&ids=" + param_escape(id);
+       
+                       notify_progress("Loading, please wait...", true);
+       
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) { 
+                                       notify('');
+       
+                                       if (transport.responseXML) {
+                                               //closeArticlePanel();
+       
+                                               var article = transport.responseXML.getElementsByTagName("article")[0];
+                                               var content = article.firstChild.nodeValue;
+       
+                                               var article_pane = new dijit.layout.ContentPane({ 
+                                                       title: "article-" + id , content: content, 
+                                                       style: 'padding : 0px;',
+                                                       id: 'ATAB-' + id,
+                                                       closable: true });
+       
+                                               dijit.byId("content-tabs").addChild(article_pane);
+
+                                               if (!event || !event.shiftKey)
+                                                       dijit.byId("content-tabs").selectChild(article_pane);
+
+                                               if ($("PTITLE-" + id))
+                                                       article_pane.attr('title', $("PTITLE-" + id).innerHTML);
+                                       }
+       
+                               } });
+                       }
 
        } catch (e) {
                exception_error("zoomToArticle", e);
@@ -1766,7 +1782,7 @@ function scrollArticle(offset) {
                                ci.scrollTop += offset;
                        }
                } else {
-                       var hi = $("headlinesInnerContainer");
+                       var hi = $("headlines-frame");
                        if (hi) {
                                hi.scrollTop += offset;
                        }
@@ -2005,43 +2021,75 @@ function cdmClicked(event, id) {
                hideAuxDlg();
 
                if (!event.ctrlKey) {
-                       selectArticles("none");
-                       toggleSelected(id);
 
-                       var elem = $("RROW-" + id);
-
-                       if (elem)
-                               elem.removeClassName("Unread");
-
-                       var upd_img_pic = $("FUPDPIC-" + id);
-
-                       if (upd_img_pic && (upd_img_pic.src.match("updated.png") || 
-                                       upd_img_pic.src.match("fresh_sign.png"))) {
+                       if (!getInitParam("cdm_expanded")) {
+                               return cdmExpandArticle(id);
+                       } else {
 
-                               upd_img_pic.src = "images/blank_icon.gif";
+                               selectArticles("none");
+                               toggleSelected(id);
+       
+                               var elem = $("RROW-" + id);
+       
+                               if (elem)
+                                       elem.removeClassName("Unread");
+       
+                               var upd_img_pic = $("FUPDPIC-" + id);
+       
+                               if (upd_img_pic && (upd_img_pic.src.match("updated.png") || 
+                                               upd_img_pic.src.match("fresh_sign.png"))) {
+       
+                                       upd_img_pic.src = "images/blank_icon.gif";
+                               }
+       
+                               active_post_id = id;
+       
+                               var query = "?op=rpc&subop=catchupSelected" +
+                                       "&cmode=0&ids=" + param_escape(id);
+       
+                               new Ajax.Request("backend.php", {
+                                       parameters: query,
+                                       onComplete: function(transport) { 
+                                               handle_rpc_reply(transport); 
+                                       } });
                        }
 
-                       active_post_id = id;
+               } else {
+                       toggleSelected(id, true);
+                       toggleUnread(id, 0, false);
+                       zoomToArticle(event, id);
+               }
 
-                       var query = "?op=rpc&subop=catchupSelected" +
-                               "&cmode=0&ids=" + param_escape(id);
+       } catch (e) {
+               exception_error("cdmClicked");
+       }
 
-                       new Ajax.Request("backend.php", {
-                               parameters: query,
-                               onComplete: function(transport) { 
-                                       handle_rpc_reply(transport); 
-                               } });
+       return false;
+}
+
+function postClicked(event, id) {
+       try {
 
+               if (!event.ctrlKey) {
                        return true;
                } else {
-                       toggleSelected(id);
+                       postOpenInNewTab(event, id);
+                       return false;
                }
 
        } catch (e) {
-               exception_error("cdmClicked");
+               exception_error("postClicked");
        }
+}
 
-       return false;
+function hlOpenInNewTab(event, id) {
+       toggleUnread(id, 0, false);
+       zoomToArticle(event, id);
+}
+
+function postOpenInNewTab(event, id) {
+       closeArticlePanel(id);
+       zoomToArticle(event, id);
 }
 
 function hlClicked(event, id) {
@@ -2052,14 +2100,14 @@ function hlClicked(event, id) {
                        return true;
                } else {
                        toggleSelected(id);
+                       toggleUnread(id, 0, false);
+                       zoomToArticle(event, id);
                        return false;
                }
 
        } catch (e) {
                exception_error("hlClicked");
        }
-
-       return false;
 }
 
 function getFirstVisibleHeadlineId() {
@@ -2074,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() {
@@ -2196,13 +2203,79 @@ function correctHeadlinesOffset(id) {
 
 function headlineActionsChange(elem) {
        try {
-               var op = elem[elem.selectedIndex].value;
+               eval(elem.value);
+               elem.selectedIndex = 0;
+       } catch (e) {
+               exception_error("headlineActionsChange", e);
+       }
+}
 
-               eval(op);
+function closeArticlePanel() {
 
-               elem.selectedIndex = 0;
+       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;
+
+                       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("headlineActionsChange", e);
+               exception_error("initHeadlinesMenu", e);
        }
 }