Skip to content

Instantly share code, notes, and snippets.

@venkatd
Created February 24, 2014 21:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save venkatd/9197007 to your computer and use it in GitHub Desktop.
Save venkatd/9197007 to your computer and use it in GitHub Desktop.
Ember.StyleBinding = Ember.Mixin.create({
concatenatedProperties: ['styleBindings'],
styleBindings: [],
_attachStyleBindings: function() {
var properties = this.get('styleBindings');
// initialize getting properties so the observers start firing
this.getProperties(properties);
properties.forEach(function(property) {
this.addObserver(property, this, this._stylePropertyDidChange);
}, this);
// trigger change event to set initial values
this._stylePropertyDidChange();
}.on('didInsertElement'),
_detachStyleBindings: function() {
var properties = this.get('styleBindings');
properties.forEach(function(property) {
this.removeObserver(property, this, this._stylePropertyDidChange);
}, this);
}.on('willDestroyElement'),
_stylePropertyDidChange: function() {
Ember.run.scheduleOnce('render', this, this._updateStyleProperties);
},
_updateStyleProperties: function() {
var keys = this.get('styleBindings');
var properties = this.getProperties(keys);
this.$().css(properties);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment