How to add a resize event to an article in the trunk?

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 size changes
    board.align()

How do I get a method repositionBoardscalled by resize events?

+5
source share
1 answer

Event sent to : resizewindow

An event is resizedispatched to an element windowwhen the browser window is resized.

But Backbone view events are tied to the view elusing delegate. The view elwill not receive the event resize, so posting 'resize articule': 'repositionBoards'in your view eventswill not be beneficial.

If you need to get an event resizein your view, you have to bind it to windowyourself:

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()

remove, resize. , view.remove() , - .

+8

All Articles