Skip to content

Commit

Permalink
Merge pull request #2858 from Automattic/update/gravatar-fallback
Browse files Browse the repository at this point in the history
OFFLINE: Gravatar fallback for offline
  • Loading branch information
artpi committed Jan 30, 2016
2 parents c5c4afe + 6b1f1a3 commit f35273d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion client/components/gravatar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ module.exports = React.createClass( {
};
},

getInitialState: function() {
return {
failedToLoad: false
}
},

_getResizedImageURL: function( imageURL ) {
var parsedURL, query;

Expand All @@ -44,18 +50,24 @@ module.exports = React.createClass( {
return url.format( parsedURL );
},

onError: function() {
this.setState( { failedToLoad: true } );
},

render: function() {
const size = this.props.size;

if ( ! this.props.user ) {
return <span className="gravatar is-placeholder" style={ { width: size, height: size } } />;
} else if ( this.state.failedToLoad ) {
return <span className="gravatar is-missing" />;
}

const alt = this.props.alt || this.props.user.display_name;
const avatarURL = this._getResizedImageURL( safeImageURL( this.props.user.avatar_URL ) );

return (
<img alt={ alt } className="gravatar" src={ avatarURL } width={ size } height={ size } />
<img alt={ alt } className="gravatar" src={ avatarURL } width={ size } height={ size } onError={ this.onError } />
);
}

Expand Down

0 comments on commit f35273d

Please sign in to comment.