events:
'click textarea': 'composeComment'
'click .submit': 'submit'
'blur textarea': 'textareaBlur'
'resize article': 'repositionBoards'
repositionBoards: ->
#this is my own function, i just need it to be called everytime an article's size changes
board.align()
How do I get my repositionBoards
method called on resize events?
The resize
event is sent to window
:
The
resize
event is sent to thewindow
element when the size of the browser window changes
But a Backbone view's events are bound to the view's el
using delegate
. The view's el
won't get a resize
event so putting 'resize articule': 'repositionBoards'
in your view's events
won't do any good.
If you need to get the resize
event in your view, you'll have to bind it to window
yourself:
initialize: (options) ->
$(window).on('resize', this.repositionBoards)
remove: ->
$(window).off('resize', this.repositionBoards) # Clean up after yourself.
@$el.remove() # The default implementation does this.
@
repositionBoards: ->
# Use => if you need to worry about what `@` is
board.align()
Also note the addition of a remove
so that you can unbind your resize
handler. You will, of course, want to use view.remove()
to remove your view or just don't worry about it if that view is your whole application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With