Created
November 20, 2013 14:41
-
-
Save denisnazarov/7564274 to your computer and use it in GitHub Desktop.
Interacting with jQuery events in Ember.js Views
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
// 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