implement support for multiple pub/mark buttons, add plugin which adds a separate mark button to article botton in combined mode (closes #382)

This commit is contained in:
Andrew Dolgov 2013-04-09 16:13:32 +04:00
parent af4204def2
commit 035d7a5a8f
4 changed files with 95 additions and 44 deletions

View File

@ -343,34 +343,33 @@ class Feeds extends Handler_Protected {
array_push($topmost_article_ids, $id); array_push($topmost_article_ids, $id);
} }
if ($line["unread"] == "t" || $line["unread"] == "1") { if (sql_bool_to_bool($line["unread"])) {
$class .= " Unread"; $class .= " Unread";
++$num_unread; ++$num_unread;
$is_unread = true;
} else {
$is_unread = false;
} }
if ($line["marked"] == "t" || $line["marked"] == "1") { if (sql_bool_to_bool($line["marked"])) {
$marked_pic = "<img id=\"FMPIC-$id\" $marked_pic = "<img
src=\"images/mark_set.svg\" src=\"images/mark_set.svg\"
class=\"markedPic\" alt=\"Unstar article\" class=\"markedPic\" alt=\"Unstar article\"
onclick='javascript:toggleMark($id)'>"; onclick='toggleMark($id)'>";
$class .= " marked";
} else { } else {
$marked_pic = "<img id=\"FMPIC-$id\" $marked_pic = "<img
src=\"images/mark_unset.svg\" src=\"images/mark_unset.svg\"
class=\"markedPic\" alt=\"Star article\" class=\"markedPic\" alt=\"Star article\"
onclick='javascript:toggleMark($id)'>"; onclick='toggleMark($id)'>";
} }
if ($line["published"] == "t" || $line["published"] == "1") { if (sql_bool_to_bool($line["published"])) {
$published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_set.svg\" $published_pic = "<img src=\"images/pub_set.svg\"
class=\"markedPic\" class=\"pubPic\"
alt=\"Unpublish article\" onclick='javascript:togglePub($id)'>"; alt=\"Unpublish article\" onclick='togglePub($id)'>";
$class .= " published";
} else { } else {
$published_pic = "<img id=\"FPPIC-$id\" src=\"images/pub_unset.svg\" $published_pic = "<img src=\"images/pub_unset.svg\"
class=\"markedPic\" class=\"pubPic\"
alt=\"Publish article\" onclick='javascript:togglePub($id)'>"; alt=\"Publish article\" onclick='togglePub($id)'>";
} }
# $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" . # $content_link = "<a target=\"_blank\" href=\"".$line["link"]."\">" .
@ -706,6 +705,9 @@ class Feeds extends Handler_Protected {
$reply['content'] .= "<div style=\"float : right\">"; $reply['content'] .= "<div style=\"float : right\">";
// $reply['content'] .= "$marked_pic";
// $reply['content'] .= "$published_pic";
foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON) as $p) { foreach ($pluginhost->get_hooks($pluginhost::HOOK_ARTICLE_BUTTON) as $p) {
$reply['content'] .= $p->hook_article_button($line); $reply['content'] .= $p->hook_article_button($line);
} }

View File

@ -442,21 +442,27 @@ function toggleMark(id, client_only) {
try { try {
var query = "?op=rpc&id=" + id + "&method=mark"; 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")) { for (i = 0; i < imgs.length; i++) {
img.src = img.src.replace("mark_unset", "mark_set"); var img = imgs[i];
img.alt = __("Unstar article");
query = query + "&mark=1";
} else { if (!row.hasClassName("marked")) {
img.src = img.src.replace("mark_set", "mark_unset"); img.src = img.src.replace("mark_unset", "mark_set");
img.alt = __("Star article"); img.alt = __("Unstar article");
query = query + "&mark=0"; 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) { if (!client_only) {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
@ -480,22 +486,30 @@ function togglePub(id, client_only, no_effects, note) {
query = query + "&note=undefined"; query = query + "&note=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) { for (i = 0; i < imgs.length; i++) {
img.src = img.src.replace("pub_unset", "pub_set"); var img = imgs[i];
img.alt = __("Unpublish article");
query = query + "&pub=1";
} else { if (!row.hasClassName("published") || note != undefined) {
img.src = img.src.replace("pub_set", "pub_unset"); img.src = img.src.replace("pub_unset", "pub_set");
img.alt = __("Publish article"); img.alt = __("Unpublish article");
query = query + "&pub=1";
query = query + "&pub=0"; } 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) { if (!client_only) {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
@ -915,9 +929,7 @@ function selectArticles(mode) {
if (cb) cb.attr("checked", false); if (cb) cb.attr("checked", false);
} }
} else if (mode == "marked") { } else if (mode == "marked") {
var img = $("FMPIC-" + child.id.replace("RROW-", "")); if (child.hasClassName("marked")) {
if (img && img.src.match("mark_set")) {
child.addClassName("Selected"); child.addClassName("Selected");
if (cb) cb.attr("checked", true); if (cb) cb.attr("checked", true);
} else { } else {
@ -925,9 +937,7 @@ function selectArticles(mode) {
if (cb) cb.attr("checked", false); if (cb) cb.attr("checked", false);
} }
} else if (mode == "published") { } else if (mode == "published") {
var img = $("FPPIC-" + child.id.replace("RROW-", "")); if (child.hasClassName("published")) {
if (img && img.src.match("pub_set")) {
child.addClassName("Selected"); child.addClassName("Selected");
if (cb) cb.attr("checked", true); if (cb) cb.attr("checked", true);
} else { } else {

View File

@ -0,0 +1,39 @@
<?php
class Mark_Button extends Plugin {
private $link;
private $host;
function init($host) {
$this->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 = "<img
src=\"images/mark_set.svg\"
class=\"markedPic\" alt=\"Unstar article\"
onclick='toggleMark($id)'>";
} else {
$marked_pic = "<img
src=\"images/mark_unset.svg\"
class=\"markedPic\" alt=\"Star article\"
onclick='toggleMark($id)'>";
}
}
return $marked_pic;
}
}
?>

View File

@ -402,7 +402,7 @@ div.hlFeed a:hover {
color : #4684ff; color : #4684ff;
} }
img.markedPic { img.markedPic, img.pubPic {
cursor : pointer; cursor : pointer;
vertical-align : middle; vertical-align : middle;
} }