Skip to content

Commit

Permalink
Merge pull request #11774 from nanaya/chart-init-reset
Browse files Browse the repository at this point in the history
Reset changelog chart before creating a new one
  • Loading branch information
notbakaneko authored Jan 14, 2025
2 parents ecfa30b + 48a59b6 commit b412e07
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions resources/js/core-legacy/changelog-chart-loader.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@
import ChangelogChart from 'charts/changelog-chart'

export default class ChangelogChartLoader
container: document.getElementsByClassName('js-changelog-chart')

constructor: ->
$(window).on 'resize', @resize
$(document).on 'turbo:load', @initialize
document.addEventListener 'turbo:load', @initialize
document.addEventListener 'turbo:before-cache', @reset


initialize: =>
return if !@container[0]?
container = document.querySelector('.js-changelog-chart')

return unless container?

# reset existing chart
container.innerHTML = ''

@chart = new ChangelogChart container
@chart.loadData()
window.addEventListener 'resize', @resize


reset: =>
@chart = null
window.removeEventListener 'resize', @resize

@container[0]._chart = new ChangelogChart @container[0]
@container[0]._chart.loadData()

resize: =>
@container[0]?._chart.resize()
@chart.resize()

0 comments on commit b412e07

Please sign in to comment.