// eslint-disable-next-line import/no-extraneous-dependencies import 'core-js/stable' // eslint-disable-next-line import/no-extraneous-dependencies import 'regenerator-runtime/runtime' import * as ActiveStorage from '@rails/activestorage' import * as Mousetrap from 'mousetrap' import { Turbo } from '@hotwired/turbo-rails' import Rails from '@rails/ujs' import tippy from 'tippy.js' import 'chartkick/chart.js/chart.esm' import './js/active-storage' import './js/controllers' import './js/custom-stream-actions' Rails.start() window.Turbolinks = Turbo let scrollTop = null Mousetrap.bind('r r r', () => { // Cpture scroll position scrollTop = document.scrollingElement.scrollTop Turbo.visit(window.location.href, { action: 'replace' }) }) function isMac() { const isMac = window.navigator.userAgent.indexOf('Mac OS X') if (isMac >= 0) { document.body.classList.add('os-mac') document.body.classList.remove('os-pc') } else { document.body.classList.add('os-pc') document.body.classList.remove('os-mac') } } function initTippy() { tippy('[data-tippy="tooltip"]', { theme: 'light', content(reference) { const title = reference.getAttribute('title') reference.removeAttribute('title') reference.removeAttribute('data-tippy') return title }, }) } window.initTippy = initTippy ActiveStorage.start() document.addEventListener('turbo:load', () => { initTippy() isMac() // Restore scroll position after r r r turbo reload if (scrollTop) { setTimeout(() => { document.scrollingElement.scrollTo(0, scrollTop) scrollTop = 0 }, 50) } setTimeout(() => { document.body.classList.remove('turbo-loading') }, 1) }) document.addEventListener('turbo:frame-load', () => { initTippy() }) document.addEventListener('turbo:before-fetch-response', async (e) => { if (e.detail.fetchResponse.response.status === 500) { const { id, src } = e.target // Don't try to redirect to failed to load if this is alread a redirection to failed to load and crashed somewhere. // You'll end up with a request loop. if (!e.detail.fetchResponse?.response?.url?.includes('/failed_to_load')) { e.target.src = `${window.Avo.configuration.root_path}/failed_to_load?turbo_frame=${id}&src=${src}` } } }) document.addEventListener('turbo:visit', () => document.body.classList.add('turbo-loading')) document.addEventListener('turbo:submit-start', () => document.body.classList.add('turbo-loading')) document.addEventListener('turbo:submit-end', () => document.body.classList.remove('turbo-loading')) document.addEventListener('turbo:before-cache', () => { document.querySelectorAll('[data-turbo-remove-before-cache]').forEach((element) => element.remove()) }) window.Avo = window.Avo || { configuration: {} } window.Avo.menus = { resetCollapsedState() { Array.from(document.querySelectorAll('[data-menu-key-param]')) .map((i) => i.getAttribute('data-menu-key-param')) .filter(Boolean) .forEach((key) => { window.localStorage.removeItem(key) }) }, }