Created
April 8, 2016 17:06
-
-
Save mitchell-garcia/d16ad52c03c17902bc42e5e5158145f9 to your computer and use it in GitHub Desktop.
Example of binding attribute to style
This file contains 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
export default Ember.Component.extend({ | |
attributeBindings: ['background:style'], | |
size: 'medium', | |
background: computed('user.[]', function() { | |
const email = this.get('user.email'); | |
const size = this.get('size'); | |
const defaultAvatar = `//www.gravatar.com/avatar/${md5(email)}.jpg`; | |
const avatar_path = this.get('user.avatar') ? this.get('user.avatar') : defaultAvatar; | |
const color = this.get('calculateTheColor'); | |
let string = ''; | |
if(avatar_path) { | |
string = 'background:url(' + avatar_path + ') no-repeat center; background-size:cover;'; | |
} else { | |
string = 'background:' + color + ';'; | |
} | |
let value = Ember.Handlebars.Utils.escapeExpression(string); | |
return Ember.String.htmlSafe(value); | |
}), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment