Skip to content

Instantly share code, notes, and snippets.

@denisnazarov
Created November 20, 2013 14:41
Show Gist options
  • Save denisnazarov/7564274 to your computer and use it in GitHub Desktop.
Save denisnazarov/7564274 to your computer and use it in GitHub Desktop.
Interacting with jQuery events in Ember.js Views
// jQuery event handler in the View
didInsertElement: function () {
var self = this;
this._boundApplyResize = function(){
self.applyResize();
}
$(window).on('resize', this._boundApplyResize);
},
willDestroyElement: function(){
$(window).off('resize', this._boundApplyResize);
}
// When to use Ember.run
fade: function(opacity, callback) {
var self = this;
var currentOpacity = this.$().css('opacity');
if (currentOpacity === opacity){
return callback();
}
this.$().css('opacity', opacity);
this.$().on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd', function(){
self.$().off('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd');
Ember.run(function(){
callback();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment