fsek / web

The website of the F-guild at TLTH
https://fsektionen.se
MIT License
17 stars 4 forks source link

Javascripts loading twice #597

Open navro opened 7 years ago

navro commented 7 years ago

Visit https://fsektionen.se/kalender or a page with a select2 controller. Navigate to another page. Press the back button in the browser. The calendar/select2 controller is now duplicated!

How do we fix this? Any idea @davidwessman? I love turbolinks 5...

davidwessman commented 7 years ago

There are some fancy discussions in this Issue, regarding making the scripts idempotent.

For the calendar scripts I would say: $('#event_calendar').html(""); In the beginning of the initialisations should help!

I bet you could do something similar with Select2.

davidwessman commented 7 years ago

You can add:

$(document).addEventListener("turbolinks:before-cache", function() {
  $('.select2').select2('destroy');
  $('.select2_tags').select2('destroy');
})

To the select2-loader and it should do the trick :). Based on:

davidwessman commented 7 years ago

Might be nicer to solve the fullcalendar-issue the same way, but then you need another destroy method :)

navro commented 7 years ago

Got the calendar to work using $('#event_calendar').html("");, but not select2 😞

davidwessman commented 7 years ago

@navro did you try the turbolinks:before-cache?

navro commented 7 years ago

@navro did you try the turbolinks:before-cache?

Yes, that's the one i tried

davidwessman commented 7 years ago

I found the solution!

You should not use select2 as the classname for loading select2 on, then you get issues. https://github.com/aldeed/meteor-autoform-select2/issues/44#issuecomment-231216235

navro commented 6 years ago

We really should fix this little bug... Thanks for the solution @davidwessman, don't know why we haven't fixed it yet 😞