Skip to content

Commit

Permalink
Item13450: Add support for famfamfam buttons
Browse files Browse the repository at this point in the history
Adds a render parameter to the SUBSCRIBE tag to choose icon vs. text
based template.
  • Loading branch information
gac410 committed Jul 15, 2015
1 parent e15d6f2 commit 2bb0e7c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
7 changes: 7 additions & 0 deletions FamFamFamContrib/templates/subscribe.famfamfam.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%TMPL:DEF{spi:subscribe}%<a href="#" class="subscribe_link" data-topic="$topic" data-subscriber="$subscriber" data-remove="$remove" data-validation-key="?$nonce" rel="nofollow" title='%MAKETEXT{"Subscribe to this topic"}%' >
<img alt='%MAKETEXT{"Subscribe to this topic (s)"}%' src='%PUBURL%/%SYSTEMWEB%/DocumentGraphics/notify.png' width='16' height='16' /></a>%TMPL:END%
%{----------------------------------------
Link for an "unsubscribe" request. Note that REST parameters are encoded in
data-subscribe
}%%TMPL:DEF{spi:unsubscribe}%<a href='#' class='subscribe_link' data-topic='$topic' data-subscriber='$subscriber' data-remove='$remove' data-validation-key='?$nonce' rel='nofollow' title='%MAKETEXT{"Unsubscribe from this topic"}%'>
<img alt='%MAKETEXT{"Unsubscribe from this topic (s)"}%' src='%PUBURL%/%SYSTEMWEB%/DocumentGraphics/notify.png' width='16' height='16' /></a>%TMPL:END%
2 changes: 1 addition & 1 deletion FamFamFamContrib/templates/view.famfamfam.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</a></span>%TMPL:END%

%TMPL:DEF{"top:toolbarbutton_subscribe"}%<span>
%SUBSCRIBE{format="<a href='#' class='subscribe_link' data-topic='$topic' data-subscriber='$subscriber' data-remove='$remove' data-validation-key='?$nonce' rel='nofollow' title='%MAKETEXT{"Subscribe to this topic (s)"}%'>
%SUBSCRIBE{render="icon" format="<a href='#' class='subscribe_link' data-topic='$topic' data-subscriber='$subscriber' data-remove='$remove' data-validation-key='?$nonce' rel='nofollow' title='%MAKETEXT{"Subscribe to this topic (s)"}%'>
<img alt='%MAKETEXT{"Subscribe to this topic (s)"}%' src='%PUBURL%/%SYSTEMWEB%/DocumentGraphics/notify.png' width='16' height='16' />
</a>" formatunsubscribe="<a href='#' class='subscribe_link' data-topic='$topic' data-subscriber='$subscriber' data-remove='$remove' data-validation-key='?$nonce' rel='nofollow' title='%MAKETEXT{"Unsubscribe from this topic (s)"}%'>
<img alt='%MAKETEXT{"Unsubscribe from this topic (s)"}%' src='%PUBURL%/%SYSTEMWEB%/DocumentGraphics/notify.png' width='16' height='16' />
Expand Down
14 changes: 11 additions & 3 deletions SubscribePlugin/lib/Foswiki/Plugins/SubscribePlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ sub _SUBSCRIBE {
unless ( Foswiki::Func::getContext()->{'SubscribePluginAllowed'} );

my $cur_user = Foswiki::Func::getWikiName();
my $who = $params->{who} || $cur_user;
my $who = $params->{who} || $cur_user;
my $render = $params->{render} || 'text'; # Rendering icon or text link

# Guest user cannot subscribe
return '' if ( $who eq $Foswiki::cfg{DefaultUserWikiName} );
Expand All @@ -88,7 +89,8 @@ sub _SUBSCRIBE {
$topic ) ) ? 1 : 0;
my $doUnsubscribe = Foswiki::isTrue($unsubscribe);

my $tmpl = _template_text( ( $doUnsubscribe ? 'un' : '' ) . 'subscribe' );
my $tmpl =
_template_text( ( $doUnsubscribe ? 'un' : '' ) . 'subscribe', $render );

my $action =
$session->i18n->maketext( $doUnsubscribe ? "Unsubscribe" : "Subscribe" );
Expand Down Expand Up @@ -190,8 +192,14 @@ sub _getNonce {

sub _template_text {
my $def = shift;
my $t = '';

if ( $_[0] =~ m/^(text|icon)$/ ) {
$t = substr( $_[0], 0, 1 );
}

$tmpls = Foswiki::Func::loadTemplate('subscribe') unless defined $tmpls;
$def = "sp:$def";
$def = "sp$t:$def";

my $text = Foswiki::Func::expandTemplate($def);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ jQuery(function($) {
data: params,
url: url,
success: function(response) {
$this.text(response.message);
/**
* famfamfam skin uses an icon instead of a text button
* so don't overlay the image with text if it didn't start
* out as text. change the title .
*/
if ($this.text() == "\n" ) {
$this.attr("title",response.message);
}
else {
$this.text(response.message);
}
params.remove = response.remove;
},
error: function(jqXHR) {
Expand Down
4 changes: 2 additions & 2 deletions SubscribePlugin/templates/subscribe.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Link for a "subscribe" request. Note that REST parameters are encoded in
data-subscribe
}%
%TMPL:DEF{sp:subscribe}%
%TMPL:DEF{spt:subscribe}%
<a href="#" class="subscribe_link" data-topic="$topic" data-subscriber="$subscriber" data-remove="$remove" data-validation-key="?$nonce" rel="nofollow" title="%MAKETEXT{"Subscribe to this topic"}%" >%MAKETEXT{"Subscribe"}%</a>
%TMPL:END%
%{----------------------------------------
Link for an "unsubscribe" request. Note that REST parameters are encoded in
data-subscribe
}%%TMPL:DEF{sp:unsubscribe}%
}%%TMPL:DEF{spt:unsubscribe}%
<a href="#" class="subscribe_link" data-topic="$topic" data-subscriber="$subscriber" data-remove="$remove" data-validation-key="?$nonce" rel="nofollow" title="%MAKETEXT{"Unsubscribe from this topic"}%" >%MAKETEXT{"Unsubscribe"}%</a>
%TMPL:END%
%{----------------------------------------
Expand Down

0 comments on commit 2bb0e7c

Please sign in to comment.