]> git.wh0rd.org - tt-rss.git/blobdiff - plugins/digest/digest.js
move db-updater functionality to public, remove db-updater.php
[tt-rss.git] / plugins / digest / digest.js
index 522d354534cdbb5f37e20e9c56a4726575171965..e3cb1e299ed3b9d3b6359d7488befc48341a5485 100644 (file)
@@ -1,5 +1,8 @@
 var last_feeds = [];
 var init_params = {};
+var hotkeys_map = false;
+var hotkey_prefix = false;
+var mobile_mode = false;
 
 var _active_feed_id = false;
 var _update_timeout = false;
@@ -26,7 +29,7 @@ function catchup_feed(feed_id, callback) {
 
                        if (feed_id < 0) is_cat = "true"; // KLUDGE
 
-                       var query = "?op=rpc&method=catchupFeed&feed_id=" +
+                       var query = "op=rpc&method=catchupFeed&feed_id=" +
                                feed_id + "&is_cat=" + is_cat;
 
                        new Ajax.Request("backend.php", {
@@ -66,9 +69,9 @@ function catchup_visible_articles(callback) {
 
                var ids = get_visible_article_ids();
 
-               if (confirm(__("Mark %d displayed articles as read?").replace("%d", ids.length))) {
+               if (confirm(ngettext("Mark %d displayed article as read?", "Mark %d displayed articles as read?", ids.length).replace("%d", ids.length))) {
 
-                       var query = "?op=rpc&method=catchupSelected" +
+                       var query = "op=rpc&method=catchupSelected" +
                                "&cmode=0&ids=" + param_escape(ids);
 
                        new Ajax.Request("backend.php", {
@@ -88,7 +91,7 @@ function catchup_visible_articles(callback) {
 
 function catchup_article(article_id, callback) {
        try {
-               var query = "?op=rpc&method=catchupSelected" +
+               var query = "op=rpc&method=catchupSelected" +
                        "&cmode=0&ids=" + article_id;
 
                new Ajax.Request("backend.php", {
@@ -120,7 +123,7 @@ function set_selected_article(article_id) {
                });
 
        } catch (e) {
-               exception_error("mark_selected_feed", e);
+               exception_error("set_selected_article", e);
        }
 }
 
@@ -139,7 +142,7 @@ function set_selected_feed(feed_id) {
                _active_feed_id = feed_id;
 
        } catch (e) {
-               exception_error("mark_selected_feed", e);
+               exception_error("set_selected_feed", e);
        }
 }
 
@@ -169,7 +172,7 @@ function update(callback) {
                window.clearTimeout(_update_timeout);
 
                new Ajax.Request("backend.php", {
-                       parameters: "?op=digest&method=digestinit",
+                       parameters: "op=digest&method=digestinit",
                        onComplete: function(transport) {
                                fatal_error_check(transport);
                                parse_feeds(transport);
@@ -220,7 +223,7 @@ function view(article_id) {
                        }, 500);
 
                new Ajax.Request("backend.php", {
-                       parameters: "?op=digest&method=digestgetcontents&article_id=" +
+                       parameters: "op=digest&method=digestgetcontents&article_id=" +
                                article_id,
                        onComplete: function(transport) {
                                fatal_error_check(transport);
@@ -252,14 +255,14 @@ function view(article_id) {
                                        }
 
                                        if (article.marked)
-                                               mark_part = "<img title='"+ __("Unstar article")+"' onclick=\"toggle_mark(this, "+article.id+")\" src='images/mark_set.png'>";
+                                               mark_part = "<img title='"+ __("Unstar article")+"' onclick=\"toggle_mark(this, "+article.id+")\" src='images/mark_set.svg'>";
                                        else
-                                               mark_part =     "<img title='"+__("Star article")+"' onclick=\"toggle_mark(this, "+article.id+")\" src='images/mark_unset.png'>";
+                                               mark_part =     "<img title='"+__("Star article")+"' onclick=\"toggle_mark(this, "+article.id+")\" src='images/mark_unset.svg'>";
 
                                        if (article.published)
-                                               publ_part = "<img title='"+__("Unpublish article")+"' onclick=\"toggle_pub(this, "+article.id+")\" src='images/pub_set.png'>";
+                                               publ_part = "<img title='"+__("Unpublish article")+"' onclick=\"toggle_pub(this, "+article.id+")\" src='images/pub_set.svg'>";
                                        else
-                                               publ_part =     "<img title='"+__("Publish article")+"' onclick=\"toggle_pub(this, "+article.id+")\" src='images/pub_unset.png'>";
+                                               publ_part =     "<img title='"+__("Publish article")+"' onclick=\"toggle_pub(this, "+article.id+")\" src='images/pub_unset.svg'>";
 
                                        var tmp = "<div id=\"inner\">" +
                                                "<div id=\"ops\">" +
@@ -296,6 +299,20 @@ function view(article_id) {
        }
 }
 
+function close_feed() {
+       $("headlines").removeClassName("move");
+
+       if (mobile_mode) set_selected_feed(false);
+}
+
+function go_back() {
+       if ($("article").hasClassName("visible")) {
+               close_article();
+       } else {
+               close_feed();
+       }
+}
+
 function close_article() {
        $("content").removeClassName("move");
        $("article").removeClassName("visible");
@@ -304,6 +321,8 @@ function close_article() {
 function viewfeed(feed_id, offset, replace, no_effects, no_indicator, callback) {
        try {
 
+               $("headlines").addClassName("move");
+
                if (!feed_id) feed_id = _active_feed_id;
                if (offset == undefined) offset = 0;
                if (replace == undefined) replace = (offset == 0);
@@ -312,7 +331,7 @@ function viewfeed(feed_id, offset, replace, no_effects, no_indicator, callback)
 
                if (!offset) $("headlines").scrollTop = 0;
 
-               var query = "backend.php?op=digest&method=digestupdate&feed_id=" +
+               var query = "op=digest&method=digestupdate&feed_id=" +
                                param_escape(feed_id) + "&offset=" + offset +
                                "&seq=" + _update_seq;
 
@@ -385,10 +404,10 @@ function get_feed_icon(feed) {
                        return getInitParam('icons_url') + "/" + feed.id + '.ico';
 
                if (feed.id == -1)
-                       return 'images/mark_set.png';
+                       return 'images/mark_set.svg';
 
                if (feed.id == -2)
-                       return 'images/pub_set.png';
+                       return 'images/pub_set.svg';
 
                if (feed.id == -3)
                        return 'images/fresh.png';
@@ -417,9 +436,9 @@ function add_feed_entry(feed) {
                        feed.title;
 
                var tmp_html = "<li id=\"F-"+feed.id+"\" onclick=\"viewfeed("+feed.id+")\">" +
+                       "<div class='unread-ctr'>" + "<span class=\"unread\">" + feed.unread + "</span></div>" +
                        icon_part + title +
-                       "<div class='unread-ctr'>" + "<span class=\"unread\">" + feed.unread + "</span>" +
-                       "</div>" + "</li>";
+                       "</li>";
 
                $("feeds-content").innerHTML += tmp_html;
 
@@ -452,8 +471,6 @@ function add_headline_entry(article, feed, no_effects) {
                if (d.getTime() / 1000 - article.updated < fresh_max)
                        li_class = "fresh";
 
-               //"<img title='" + __("Mark as read") + "' onclick=\"view("+article.id+", true)\" src='images/digest_checkbox.png'>" +
-
                var checkbox_part = "<input type=\"checkbox\" class=\"cb\" onclick=\"toggle_select_article(this)\"/>";
 
                var date = new Date(article.updated * 1000);
@@ -515,7 +532,7 @@ function redraw_feedlist(feeds) {
                        $('feeds-content').innerHTML += "<li id='F-MORE-PROMPT'>" +
                                "<img src='images/blank_icon.gif'>" +
                                "<a href=\"#\" onclick=\"expand_feeds()\">" +
-                               __("%d more...").replace("%d", feeds.length-10) +
+                               ngettext("%d more...", "%d more...", feeds.length-10).replace("%d", feeds.length-10) +
                                "</a>" + "</li>";
                }
 
@@ -565,8 +582,13 @@ function parse_feeds(transport) {
                        redraw_feedlist(feeds);
                }
 
+               if (reply['hotkeys']) {
+                       hotkeys_map = reply['hotkeys'];
+               }
+
        } catch (e) {
-               exception_error("parse_feeds", e);
+               console.log(e);
+               //exception_error("parse_feeds", e);
        }
 }
 
@@ -647,25 +669,26 @@ function parse_headlines(transport, replace, no_effects) {
 function init_second_stage() {
        try {
                new Ajax.Request("backend.php", {
-                       parameters: "backend.php?op=digest&method=digestinit",
+                       parameters: "op=digest&method=digestinit&init=1",
                        onComplete: function(transport) {
                                parse_feeds(transport);
                                Element.hide("overlay");
 
                                document.onkeydown = hotkey_handler;
 
-                               window.setTimeout('viewfeed(-4)', 100);
-                               _update_timeout = window.setTimeout('update()', 5*1000);
-                               } });
+                               if (!mobile_mode)
+                                       window.setTimeout('viewfeed(-4)', 100);
+                                       _update_timeout = window.setTimeout('update()', 5*1000);
+                                       } });
 
        } catch (e) {
                exception_error("init_second_stage", e);
        }
 }
 
-function init() {
+function init(mobile) {
        try {
-               dojo.require("dijit.Dialog");
+               mobile_mode = mobile;
 
                new Ajax.Request("backend.php", {
                        parameters: {op: "rpc", method: "sanityCheck"},
@@ -682,7 +705,7 @@ function toggle_mark(img, id) {
 
        try {
 
-               var query = "?op=rpc&id=" + id + "&method=mark";
+               var query = "op=rpc&id=" + id + "&method=mark";
 
                if (!img) return;
 
@@ -711,7 +734,7 @@ function toggle_pub(img, id, note) {
 
        try {
 
-               var query = "?op=rpc&id=" + id + "&method=publ";
+               var query = "op=rpc&id=" + id + "&method=publ";
 
                if (note != undefined) {
                        query = query + "&note=" + param_escape(note);
@@ -749,7 +772,7 @@ function fatal_error(code, msg) {
                if (code == 6) {
                        window.location.href = "digest.php";
                } else if (code == 5) {
-                       window.location.href = "db-updater.php";
+                       window.location.href = "public.php?op=dbupdate";
                } else {
 
                        if (msg == "") msg = "Unknown error";
@@ -834,15 +857,64 @@ function hotkey_handler(e) {
 
                var keychar = String.fromCharCode(keycode);
 
+               if (!shift_key) keychar = keychar.toLowerCase();
+
                if (keycode == 16) return; // ignore lone shift
                if (keycode == 17) return; // ignore lone ctrl
 
+               var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
+               hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
+               hotkey_prefix = false;
+
+               var hotkey_action = false;
+               var hotkeys = getInitParam("hotkeys");
+
+               for (sequence in hotkeys[1]) {
+                       if (sequence == hotkey) {
+                               hotkey_action = hotkeys[1][sequence];
+                               break;
+                       }
+               }
+
                switch (keycode) {
                case 27: // esc
-                       close_article();
-                       break;
+                       go_back();
+                       return false;
+               }
+
+               switch (hotkey_action) {
+               case "next_feed":
+                       var feeds = $$("#feeds li");
+                       for (var i = 0; i < feeds.length; i++) {
+                               var base_id = feeds[i].id.replace("F-", "");
+
+                               if (base_id == _active_feed_id) {
+                                       if (feeds[i+1]) {
+                                               viewfeed(feeds[i+1].id.replace("F-", ""));
+                                       }
+                                       break;
+                               }
+                       }
+                       return false;
+               case "prev_feed":
+                       var feeds = $$("#feeds li");
+                       for (var i = 0; i < feeds.length; i++) {
+                               var base_id = feeds[i].id.replace("F-", "");
+
+                               if (base_id == _active_feed_id) {
+                                       if (feeds[i-1]) {
+                                               viewfeed(feeds[i-1].id.replace("F-", ""));
+                                       }
+                                       break;
+                               }
+                       }
+                       return false;
+               case "next_article":
+                       return false;
+               case "prev_article":
+                       return false;
                default:
-                       console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
+                       console.log("unhandled action: " + hotkey_action + "; hotkey: " + hotkey);
                }