diff --git a/r2/r2/templates/link.compact b/r2/r2/templates/link.compact
index f1b87cee2..e278aa02c 100644
--- a/r2/r2/templates/link.compact
+++ b/r2/r2/templates/link.compact
@@ -28,7 +28,7 @@
<%namespace file="printable.html" import="arrow, score"/>
<%namespace file="link.html" import="tagline"/>
<%namespace file="utils.html" import="plain_link" />
-<%namespace file="utils.compact" import="icon_button" />
+<%namespace file="utils.compact" import="icon_button, toggle_button" />
<%namespace file="printablebuttons.html" import="state_button" />
@@ -124,23 +124,11 @@ there's also a discussion going on here:
<%def name="hide_button()">
%if c.user_is_loggedin:
- %if thing.hidden:
- ${icon_button("Hide","hide-icon", onclick="change_state(this, 'hide', hide_thing)", outer_class="hide-button", style="display: none;")}
- ${icon_button("Unhide","unhide-icon", onclick="change_state(this, 'unhide', hide_thing)", outer_class="unhide-button")}
- %else:
- ${icon_button("Hide","hide-icon", onclick="change_state(this, 'hide', hide_thing)", outer_class="hide-button", herp="derp")}
- ${icon_button("Unhide","unhide-icon", onclick="change_state(this, 'unhide', hide_thing)", outer_class="unhide-button", style="display: none;")}
- %endif
+ ${toggle_button("hide", thing.hidden)}
%endif
%def>
<%def name="save_button()">
%if c.user_is_loggedin:
- %if thing.saved:
- ${icon_button("Unsave", "unsave-icon", onclick="change_state(this, 'unsave', unsave_thing, true)", outer_class="unsave-button")}
- ${icon_button("Save", "save-icon", onclick="change_state(this, 'save', save_thing, true)", outer_class="save-button", style="display: none;")}
- %else:
- ${icon_button("Unsave", "unsave-icon", onclick="change_state(this, 'unsave', unsave_thing, true)", outer_class="unsave-button", style="display: none;")}
- ${icon_button("Save", "save-icon", onclick="change_state(this, 'save', save_thing, true)", outer_class="save-button")}
- %endif
+ ${toggle_button("save", thing.saved)}
%endif
%def>
\ No newline at end of file
diff --git a/r2/r2/templates/utils.compact b/r2/r2/templates/utils.compact
index 6cd5c2475..a6abeec03 100644
--- a/r2/r2/templates/utils.compact
+++ b/r2/r2/templates/utils.compact
@@ -19,7 +19,9 @@
## All portions of the code written by CondeNet are Copyright (c) 2006-2010
## CondeNet, Inc. All Rights Reserved.
################################################################################
-
+<%!
+ import string
+%>
<%def name="icon_button(text, css_class, href='javascript:void(0)', outer_class='', **kw)">
${text}
%def>
+<%def name="toggle_button(togglename, toggled=False)">
+ <%
+ if toggled:
+ togglestyle = {"style": "display: none;"}
+ untogglestyle = {}
+ else:
+ togglestyle = {}
+ untogglestyle = {"style": "display: none;"}
+ endif
+
+ if togglename == "hide":
+ untext = ""
+ else:
+ untext = "un"
+ endif
+ %>
+ ##Hide/Save
+ ${icon_button( string.capitalize(togglename), togglename + "-icon", onclick="change_state(this,'" + togglename + "', " + togglename + "_thing)", outer_class=togglename + "-button", **togglestyle)}
+ ##Unhide/Unsave
+ ${icon_button( "Un" + togglename, "un" + togglename + "-icon", onclick="change_state(this,'un" + togglename + "', " + untext + togglename + "_thing)", outer_class= "un" + togglename + "-button", **untogglestyle)}
+%def>