Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Use with turbolinks #52

Closed
jclusso opened this issue May 6, 2016 · 3 comments
Closed

Use with turbolinks #52

jclusso opened this issue May 6, 2016 · 3 comments

Comments

@jclusso
Copy link

jclusso commented May 6, 2016

I'm trying to use turbolinks in our application and I can't figure out how to make it so I don't get multiple calendar objects. Is there a way to destroy the calendar? I've tried doing like

if window.calendar == undefined
      window.calendar = new Calendar(
        element: $('.daterange--double')
        earliest_date: moment(createdAt)
        latest_date: loadEndDate
        start_date: loadStartDate
        end_date: loadEndDate
        callback: ->
          updateCharts(@start_date, @end_date)
        )

The issue is the Calendar no longer works after I do that...

@jclusso
Copy link
Author

jclusso commented May 6, 2016

I ended up doing this... not sure if it's the best way to go about the problem though. Btw, ignore the tabbing. It's coffeescript and It's just pasting in a little weird

if window.calendar != undefined
      $('.daterange.daterange--double').children().remove()
    window.calendar = new Calendar(
      element: $('.daterange--double')
      earliest_date: moment(@createdAt)
      latest_date: @loadEndDate()
      start_date: @loadStartDate()
      end_date: @loadEndDate()
      callback: (@start_date, @end_date) =>
        @updateChart(@start_date, @end_date)
      )

@kalepail
Copy link
Contributor

kalepail commented May 6, 2016

@jclusso What I typically do is test for the existence of the calendar object and if it doesn't exist I create it. So rather then destroy it every time you ensure you only create it once. Either way though sounds like you got it working.

@kalepail kalepail closed this as completed May 6, 2016
@jclusso
Copy link
Author

jclusso commented May 7, 2016

Well checking if it existed stopped it from making a new one, but I think because the events are not bound to the document it doesn't work anymore after a page change.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants