Created
March 13, 2014 15:17
-
-
Save meirish/9530391 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GetSmart.UserAvatarComponent = Ember.Component.extend({ | |
GRADIENTS: [ | |
'nikki-sixx', | |
'dee-snider', | |
'david-lee-roth', | |
'axel-rose' | |
], | |
user: null, | |
classNames: ['user-avatar'], | |
classNameBindings: ['backgroundClass'], | |
/** | |
* Internal: Map user to a background class. | |
* | |
* Returns a class string. | |
*/ | |
backgroundClass: function() { | |
if (this.get('user.avatar_url')) { return null; } | |
return this.GRADIENTS[this.userHash()]; | |
}.property(), | |
/** | |
* Internal: Hash the user's name to a number between 0 and 3. | |
* | |
* Returns a number. | |
*/ | |
userHash: function() { | |
var uid = this.get('user.name'), | |
total = 0; | |
// get rid of this once it's all working | |
return Math.round(Math.random() * 3); | |
for (var i=0,l=uid.length; i<l; i++) { | |
total += uid.charCodeAt(i); | |
} | |
return total % this.GRADIENTS.length; | |
}, | |
initials: function() { | |
return 'PH'; | |
}.property() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment