Skip to content

Commit

Permalink
improve handling of contributors gravatars
Browse files Browse the repository at this point in the history
Place the gravatars inside the links, so when active the gravatars still
show.  Also make the javascript idempotent, and handle the gravatar not
existing.
  • Loading branch information
haarg committed Sep 19, 2014
1 parent c73e9d1 commit b6ed077
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
39 changes: 24 additions & 15 deletions root/static/js/contributors.js
Expand Up @@ -10,22 +10,31 @@ $(function(){
if ( typeof data.name == 'undefined' ) {
return;
}
// TODO make this an :before pseudo-class
var gravatar = data.gravatar_url;
gravatar = gravatar.replace(
"^https?://([a-z0-9.-]+\.)?gravatar\.com/",
"https://secure.gravatar.com/",
"i"
).replace(
/s=\d+/,
's=20'
);
var $img = $('<img />').attr( 'src', gravatar )
.attr( 'width', 20 )
.attr( 'height', 20 );
$anchor.attr( 'data-cpan-author', data.pauseid );
$anchor.attr( 'href', '/author/' + data.pauseid );
$anchor.text( data.name );
$anchor.parent().addClass('gravatar');
$anchor.before( $img );

var gravatar = data.gravatar_url;
if (gravatar) {
gravatar = gravatar.replace(
"^https?://([a-z0-9.-]+\.)?gravatar\.com/",
"https://secure.gravatar.com/",
"i"
).replace(
/s=\d+/,
's=20'
);

var $img = $anchor.find('img.gravatar');
if (!$img.length) {
$img = $('<img />')
.attr( 'width', 20 )
.attr( 'height', 20 );
$anchor.prepend( $img );
}
$img.addClass( 'gravatar' );
$img.attr( 'src', gravatar )
}
});
});
});
3 changes: 2 additions & 1 deletion root/static/less/global.less
Expand Up @@ -255,8 +255,9 @@ ul {
position: relative;
text-align: left;
padding-left: 22px;
min-height: 20px;

&.gravatar img {
img.gravatar {
left: 0;
position: absolute;
}
Expand Down

0 comments on commit b6ed077

Please sign in to comment.