Created
February 24, 2014 21:03
-
-
Save venkatd/9197007 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
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