Created
July 17, 2014 16:43
-
-
Save James1x0/b810e2d5b49c507164f5 to your computer and use it in GitHub Desktop.
Window Event Binder Mixin
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
import Ember from 'ember'; | |
// This mixin binds callbacks to events. | |
export default Ember.Mixin.create({ | |
/* | |
Mixin setup | |
NOTE: Must be implemented on init, didTransition, or didInsertElement hooks | |
*/ | |
setupWindowBindings: function () { | |
$(window).on('resize scroll', { emEl: this }, this._bindToProperties); | |
}, | |
/* | |
Mixin teardown | |
NOTE: Can be implemented on willTransition or willDestroyElement hooks | |
*/ | |
teardownWindowBindings: function () { | |
$(window).off('resize scroll', this._bindToProperties); | |
}, | |
_bindToProperties: function ( event ) { | |
event.data.emEl.set('did' + event.type.charAt(0).toUpperCase() + event.type.slice(1), true); | |
} | |
}); |
Author
James1x0
commented
Jul 17, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment