From 035d7a5a8fae5620e9b6121a5b5fa270184096ba Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 9 Apr 2013 16:13:32 +0400 Subject: [PATCH] implement support for multiple pub/mark buttons, add plugin which adds a separate mark button to article botton in combined mode (closes #382) --- classes/feeds.php | 34 ++++++++++--------- js/viewfeed.js | 64 +++++++++++++++++++++--------------- plugins/mark_button/init.php | 39 ++++++++++++++++++++++ tt-rss.css | 2 +- 4 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 plugins/mark_button/init.php diff --git a/classes/feeds.php b/classes/feeds.php index ed0785c0..521aec70 100644 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -343,34 +343,33 @@ class Feeds extends Handler_Protected { array_push($topmost_article_ids, $id); } - if ($line["unread"] == "t" || $line["unread"] == "1") { + if (sql_bool_to_bool($line["unread"])) { $class .= " Unread"; ++$num_unread; - $is_unread = true; - } else { - $is_unread = false; } - if ($line["marked"] == "t" || $line["marked"] == "1") { - $marked_pic = "\"Unstar"; + onclick='toggleMark($id)'>"; + $class .= " marked"; } else { - $marked_pic = "\"Star"; + onclick='toggleMark($id)'>"; } - if ($line["published"] == "t" || $line["published"] == "1") { - $published_pic = "\"Unpublish"; + if (sql_bool_to_bool($line["published"])) { + $published_pic = "\"Unpublish"; + $class .= " published"; } else { - $published_pic = "\"Publish"; + $published_pic = "\"Publish"; } # $content_link = "" . @@ -706,6 +705,9 @@ class Feeds extends Handler_Protected { $reply['content'] .= "
"; +// $reply['content'] .= "$marked_pic"; +// $reply['content'] .= "$published_pic"; + foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON) as $p) { $reply['content'] .= $p->hook_article_button($line); } diff --git a/js/viewfeed.js b/js/viewfeed.js index f8a7f373..da5ded64 100644 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -442,21 +442,27 @@ function toggleMark(id, client_only) { try { var query = "?op=rpc&id=" + id + "&method=mark"; - var img = $("FMPIC-" + id); + var row = $("RROW-" + id); + if (!row) return; - if (!img) return; + var imgs = row.getElementsByClassName("markedPic"); - if (img.src.match("mark_unset")) { - img.src = img.src.replace("mark_unset", "mark_set"); - img.alt = __("Unstar article"); - query = query + "&mark=1"; + for (i = 0; i < imgs.length; i++) { + var img = imgs[i]; - } else { - img.src = img.src.replace("mark_set", "mark_unset"); - img.alt = __("Star article"); - query = query + "&mark=0"; + if (!row.hasClassName("marked")) { + img.src = img.src.replace("mark_unset", "mark_set"); + img.alt = __("Unstar article"); + query = query + "&mark=1"; + } else { + img.src = img.src.replace("mark_set", "mark_unset"); + img.alt = __("Star article"); + query = query + "&mark=0"; + } } + row.toggleClassName("marked"); + if (!client_only) { new Ajax.Request("backend.php", { parameters: query, @@ -480,22 +486,30 @@ function togglePub(id, client_only, no_effects, note) { query = query + "¬e=undefined"; } - var img = $("FPPIC-" + id); + var row = $("RROW-" + id); + if (!row) return; - if (!img) return; + var imgs = row.getElementsByClassName("pubPic"); - 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"; + for (i = 0; i < imgs.length; i++) { + var img = imgs[i]; - } else { - img.src = img.src.replace("pub_set", "pub_unset"); - img.alt = __("Publish article"); - - query = query + "&pub=0"; + if (!row.hasClassName("published") || note != undefined) { + img.src = img.src.replace("pub_unset", "pub_set"); + img.alt = __("Unpublish article"); + query = query + "&pub=1"; + } else { + img.src = img.src.replace("pub_set", "pub_unset"); + img.alt = __("Publish article"); + query = query + "&pub=0"; + } } + if (note != undefined) + row.addClassName("published"); + else + row.toggleClassName("published"); + if (!client_only) { new Ajax.Request("backend.php", { parameters: query, @@ -915,9 +929,7 @@ function selectArticles(mode) { if (cb) cb.attr("checked", false); } } else if (mode == "marked") { - var img = $("FMPIC-" + child.id.replace("RROW-", "")); - - if (img && img.src.match("mark_set")) { + if (child.hasClassName("marked")) { child.addClassName("Selected"); if (cb) cb.attr("checked", true); } else { @@ -925,9 +937,7 @@ function selectArticles(mode) { if (cb) cb.attr("checked", false); } } else if (mode == "published") { - var img = $("FPPIC-" + child.id.replace("RROW-", "")); - - if (img && img.src.match("pub_set")) { + if (child.hasClassName("published")) { child.addClassName("Selected"); if (cb) cb.attr("checked", true); } else { diff --git a/plugins/mark_button/init.php b/plugins/mark_button/init.php new file mode 100644 index 00000000..9227a5d1 --- /dev/null +++ b/plugins/mark_button/init.php @@ -0,0 +1,39 @@ +link = $host->get_link(); + $this->host = $host; + + $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); + } + + function about() { + return array(1.0, + "Bottom un/star button for the combined mode", + "fox"); + } + + function hook_article_button($line) { + $marked_pic = ""; + + if (get_pref($this->link, "COMBINED_DISPLAY_MODE")) { + if (sql_bool_to_bool($line["marked"])) { + $marked_pic = "\"Unstar"; + } else { + $marked_pic = "\"Star"; + } + } + + return $marked_pic; + } +} +?> diff --git a/tt-rss.css b/tt-rss.css index 8ab776f4..2f2e2fb7 100644 --- a/tt-rss.css +++ b/tt-rss.css @@ -402,7 +402,7 @@ div.hlFeed a:hover { color : #4684ff; } -img.markedPic { +img.markedPic, img.pubPic { cursor : pointer; vertical-align : middle; }