]> git.wh0rd.org - tt-rss.git/blobdiff - digest.js
update.php & daemon: chdir to script directory using __FILE__ magic constant
[tt-rss.git] / digest.js
index cb42633b6111ffd496856535ef1f1e0d72079dee..1b62b14183be603948071c4da50a24d829851ed5 100644 (file)
--- a/digest.js
+++ b/digest.js
@@ -1,9 +1,6 @@
 var last_feeds = [];
 var init_params = {};
 
-var db = false;
-var store = false;
-
 var _active_feed_id = false;
 var _active_feed_offset = false;
 var _update_timeout = false;
@@ -47,9 +44,8 @@ function catchup_feed(feed_id, callback) {
        }
 }
 
-function catchup_visible_articles(callback) {
+function get_visible_article_ids() {
        try {
-
                var elems = $("headlines-content").getElementsByTagName("LI");
                var ids = [];
                        
@@ -59,6 +55,18 @@ function catchup_visible_articles(callback) {
                        }
                }
 
+               return ids;
+
+       } catch (e) {
+               exception_error("get_visible_article_ids", e);
+       }
+}
+
+function catchup_visible_articles(callback) {
+       try {
+
+               var ids = get_visible_article_ids();
+
                if (confirm(__("Mark %d displayed articles as read?").replace("%d", ids.length))) {
 
                        var query = "?op=rpc&subop=catchupSelected" +
@@ -126,9 +134,12 @@ function zoom(elem, article_id) {
                        onComplete: function(transport) {
                                fatal_error_check(transport);
 
-                               if (transport.responseXML) {
-                                       var article = transport.responseXML.getElementsByTagName('article')[0];
-                                       elem.innerHTML = article.firstChild.nodeValue;
+                               var reply = JSON.parse(transport.responseText);
+
+                               if (reply) {
+                                       var article = reply['article'];
+
+                                       elem.innerHTML = article.content;
 
                                        new Effect.BlindDown(elem, {duration : 0.5});
 
@@ -253,11 +264,13 @@ function viewfeed(feed_id, offset, replace, no_effects, no_indicator, callback)
 
                console.log(query);
 
-               var img = $("F-" + feed_id).getElementsByTagName("IMG")[0];
+               if ($("F-" + feed_id)) {
+                       var img = $("F-" + feed_id).getElementsByTagName("IMG")[0];
 
-               if (img && !no_indicator) {
-                       img.setAttribute("orig_src", img.src);
-                       img.src = 'images/indicator_tiny.gif';
+                       if (img && !no_indicator) {
+                               img.setAttribute("orig_src", img.src);
+                               img.src = 'images/indicator_tiny.gif';
+                       }
                }
 
                new Ajax.Request("backend.php", {
@@ -313,7 +326,7 @@ function find_feed(feeds, feed_id) {
 function get_feed_icon(feed) {
        try {
                if (feed.has_icon)
-                       return getInitParam('icons_location') + "/" + feed.id + '.ico';
+                       return getInitParam('icons_url') + "/" + feed.id + '.ico';
 
                if (feed.id == -1)
                        return 'images/mark_set.png';
@@ -419,6 +432,7 @@ function add_headline_entry(article, feed, no_effects) {
                        "<div class='digest-check'>" +
                                mark_part +
                                publ_part +
+                               "<img title='" + __("Share on Twitter") + "' onclick=\"tweet_article("+article.id+", true)\" src='images/art-tweet.png'>" +
                                "<img title='" + __("Mark as read") + "' onclick=\"view("+article.id+", true)\" src='images/digest_checkbox.png'>" +
                        "</div>" + 
                        "<a target=\"_blank\" href=\""+article.link+"\""+
@@ -474,6 +488,12 @@ function redraw_feedlist(feeds) {
                                "</a>" + "</li>";
                }
 
+               if (feeds.length == 0) {
+                       $('feeds-content').innerHTML = 
+                               "<div class='insensitive' style='text-align : center'>" + 
+                                       __("No unread feeds.") + "</div>";
+               }
+
        } catch (e) {
                exception_error("redraw_feedlist", e);
        }
@@ -481,13 +501,13 @@ function redraw_feedlist(feeds) {
 
 function parse_feeds(transport) {
        try {
+               var reply = JSON.parse(transport.responseText);
 
-               if (!transport.responseXML) return;
+               if (!reply) return;
 
-               var feeds = transport.responseXML.getElementsByTagName('feeds')[0];
+               var feeds = reply['feeds'];
 
                if (feeds) {
-                       feeds = eval("(" + feeds.firstChild.nodeValue + ")");
 
                        feeds.sort( function (a,b) 
                                { 
@@ -518,12 +538,12 @@ function parse_feeds(transport) {
 
 function parse_headlines(transport, replace, no_effects) {
        try {
-               if (!transport.responseXML) return;
+               var reply = JSON.parse(transport.responseText);
+               if (!reply) return;
 
-               var seq = transport.responseXML.getElementsByTagName('seq')[0];
+               var seq = reply['seq'];
 
                if (seq) {
-                       seq = seq.firstChild.nodeValue;
                        if (seq != _update_seq) {
                                console.log("parse_headlines: wrong sequence received.");
                                return;
@@ -532,15 +552,11 @@ function parse_headlines(transport, replace, no_effects) {
                        return;
                }
 
-               var headlines = transport.responseXML.getElementsByTagName('headlines')[0];
-               var headlines_title = transport.responseXML.getElementsByTagName('headlines-title')[0];
+               var headlines = reply['headlines']['content'];
+               var headlines_title = reply['headlines']['title'];
 
                if (headlines && headlines_title) {
-                       headlines = eval("(" + headlines.firstChild.nodeValue + ")");
-
-                       var title = headlines_title.firstChild.nodeValue;
-
-                       $("headlines-title").innerHTML = title;
+                       $("headlines-title").innerHTML = headlines_title
 
                        if (replace) {
                                $('headlines-content').innerHTML = '';
@@ -563,19 +579,25 @@ function parse_headlines(transport, replace, no_effects) {
                                }
                        }
 
-                       if (pr) {
-                               $('headlines-content').appendChild(pr);
-                               if (!no_effects) new Effect.ScrollTo(inserted);
-                       } else {
-                               $('headlines-content').innerHTML += "<li id='H-MORE-PROMPT'>" +
-                                       "<div class='body'>" +
-                                       "<a href=\"javascript:catchup_visible_articles()\">" +
-                                       __("Mark as read") + "</a> | " + 
-                                       "<a href=\"javascript:load_more()\">" +
-                                       __("Load more...") + "</a>" + 
-                                       "<img style=\"display : none\" "+
+                       var ids = get_visible_article_ids();
+
+                       if (ids.length > 0) {
+                               if (pr) {
+                                       $('headlines-content').appendChild(pr);
+                                       if (!no_effects && inserted) new Effect.ScrollTo(inserted);
+                               } else {
+                                       $('headlines-content').innerHTML += "<li id='H-MORE-PROMPT'>" +
+                                               "<div class='body'>" +
+                                               "<a href=\"#\" onclick=\"catchup_visible_articles()\">" +
+                                               __("Mark as read") + "</a> | " + 
+                                               "<a href=\"#\" onclick=\"load_more()\">" +
+                                               __("Load more...") + "</a>" + 
+                                               "<img style=\"display : none\" "+
                                                "id=\"H-LOADING-IMG\" src='images/indicator_tiny.gif'>" +
-                                       "</div></li>";
+                                               "</div></li>";
+                               }
+                       } else {
+                               // FIXME : display some kind of "nothing to see here" prompt here
                        }
 
                        if (replace && !no_effects) 
@@ -606,6 +628,7 @@ function init_second_stage() {
 
 function init() {
        try {
+               dojo.require("dijit.Dialog");
 
                new Ajax.Request("backend.php", {
                        parameters: "?op=rpc&subop=sanityCheck",
@@ -618,27 +641,22 @@ function init() {
        }
 }
 
-function toggle_mark(mark_img, id) {
+function toggle_mark(img, id) {
 
        try {
 
                var query = "?op=rpc&id=" + id + "&subop=mark";
-       
-               query = query + "&afid=" + _active_feed_id;
-               query = query + "&omode=c";
 
-               if (!mark_img) return;
+               if (!img) return;
 
-               if (mark_img.src.match("mark_unset")) {
-                       mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
-                       mark_img.alt = __("Unstar article");
+               if (img.src.match("mark_unset")) {
+                       img.src = img.src.replace("mark_unset", "mark_set");
+                       img.alt = __("Unstar article");
                        query = query + "&mark=1";
                } else {
-                       mark_img.alt = __("Please wait...");
+                       img.src = img.src.replace("mark_set", "mark_unset");
+                       img.alt = __("Star article");
                        query = query + "&mark=0";
-       
-                       mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
-                       mark_img.alt = __("Star article");
                }
 
                new Ajax.Request("backend.php", {
@@ -652,35 +670,29 @@ function toggle_mark(mark_img, id) {
        }
 }
 
-function toggle_pub(mark_img, id, note) {
+function toggle_pub(img, id, note) {
 
        try {
 
                var query = "?op=rpc&id=" + id + "&subop=publ";
        
-               query = query + "&afid=" + _active_feed_id;
-
                if (note != undefined) {
                        query = query + "&note=" + param_escape(note);
                } else {
                        query = query + "&note=undefined";
                }
 
-               query = query + "&omode=c";
+               if (!img) return;
 
-               if (!mark_img) return;
-
-               if (mark_img.src.match("pub_unset") || note != undefined) {
-                       mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
-                       mark_img.alt = __("Unpublish article");
+               if (img.src.match("pub_unset") || note != undefined) {
+                       img.src = img.src.replace("pub_unset", "pub_set");
+                       img.alt = __("Unpublish article");
                        query = query + "&pub=1";
 
                } else {
-                       mark_img.alt = __("Please wait...");
+                       img.src = img.src.replace("pub_set", "pub_unset");
+                       img.alt = __("Publish article");
                        query = query + "&pub=0";
-       
-                       mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
-                       mark_img.alt = __("Publish article");
                }
 
                new Ajax.Request("backend.php", {
@@ -700,7 +712,7 @@ function fatal_error(code, msg) {
                if (code == 6) {
                        window.location.href = "digest.php";
                } else if (code == 5) {
-                       window.location.href = "update.php";
+                       window.location.href = "db-updater.php";
                } else {
        
                        if (msg == "") msg = "Unknown error";
@@ -788,3 +800,33 @@ function update_title(unread) {
        }
 }
 
+function tweet_article(id) {
+       try {
+
+               var query = "?op=rpc&subop=getTweetInfo&id=" + param_escape(id);
+
+               console.log(query);
+
+               var d = new Date();
+      var ts = d.getTime();
+
+               var w = window.open('backend.php?op=loading', 'ttrss_tweet',
+                       "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");
+
+               new Ajax.Request("backend.php", {
+                       parameters: query, 
+                       onComplete: function(transport) {
+                               var ti = JSON.parse(transport.responseText);
+
+                               var share_url = "http://twitter.com/share?_=" + ts +
+                                       "&text=" + param_escape(ti.title) + 
+                                       "&url=" + param_escape(ti.link);
+                                               
+                               w.location.href = share_url;
+
+                       } });
+
+       } catch (e) {
+               exception_error("tweet_article", e);
+       }
+}