Fire function at timed interval from within an function (coffeescript)

I have a function that equalise element heights on older browsers with javascript. The problem is that I have to run that function at a 3 second interval or so due to ajax content. I cant use the callback function on the content update since it is build into a CMS I cant touch.

I have the following coffeescript file:

class window.ApplicationController
  constructor: ->
    #fire code
    @equalColumnHeight()
  #......
  equalColumnHeight: ->
    console.log "equal height"
    colLeft = 0
    if @browserwidth > 1024
      colLeft = (@columnPageTreeNav + @columnSidebarA)
    colHeight = Math.max(colLeft, @columnPageTreeNav, @columnContent, @columnSidebarA, @columnSidebarB)
    $("#content, #sidebar_a, #sidebar_b").height colHeight
    $("#sidebar_a").css "top", (@columnPageTreeNav + 190)

My initial idea was to fire the function at an interval like this:

class window.ApplicationController
  constructor: ->
    #fire code
    @equalColumnHeight()
    setInterval @equalColumnHeight(), 3000
  #......
  equalColumnHeight: ->
    colLeft = 0
    if @browserwidth > 1024
      colLeft = (@columnPageTreeNav + @columnSidebarA)
    colHeight = Math.max(colLeft, @columnPageTreeNav, @columnContent, @columnSidebarA, @columnSidebarB)
    $("#content, #sidebar_a, #sidebar_b").height colHeight
    $("#sidebar_a").css "top", (@columnPageTreeNav + 190)

But that does not work, any ideas?

Upvotes: 0

Views: 242

Answers (1)

Eugene
Eugene

Reputation: 732

setInterval (=> @equalColumnHeight()), 3000

setInterval accepts function for the first argument, but you pass the result of equalColumnHeight

Upvotes: 2

Related Questions