import "./polyfills/closest" import "./apply-theme" import 'abortcontroller-polyfill/dist/polyfill-patch-fetch' import Alpine from 'alpinejs' import "./liveview/live_socket" import comboBox from "./liveview/combo-box" import dropdown from "./liveview/dropdown" import "./liveview/phx_events" Alpine.data('dropdown', dropdown) Alpine.data('comboBox', comboBox) Alpine.start() const triggers = document.querySelectorAll('[data-dropdown-trigger]') for (const trigger of triggers) { trigger.addEventListener('click', function(e) { e.stopPropagation() e.currentTarget.nextElementSibling.classList.remove('hidden') }) } if (triggers.length > 0) { document.addEventListener('click', function(e) { const dropdown = e.target.closest('[data-dropdown]') if (dropdown && e.target.tagName === 'A') { dropdown.classList.add('hidden') } }) document.addEventListener('click', function(e) { const clickedInDropdown = e.target.closest('[data-dropdown]') if (!clickedInDropdown) { for (const dropdown of document.querySelectorAll('[data-dropdown]')) { dropdown.classList.add('hidden') } } }) } const changelogNotification = document.getElementById('changelog-notification') if (changelogNotification) { showChangelogNotification(changelogNotification) fetch('https://plausible.io/changes.txt', { headers: { 'Content-Type': 'text/plain' } }) .then((res) => res.text()) .then((res) => { localStorage.lastChangelogUpdate = new Date(res).getTime() showChangelogNotification(changelogNotification) }) } function showChangelogNotification(el) { const lastUpdated = Number(localStorage.lastChangelogUpdate) const lastChecked = Number(localStorage.lastChangelogClick) const hasNewUpdateSinceLastClicked = lastUpdated > lastChecked const notOlderThanThreeDays = Date.now() - lastUpdated < 1000 * 60 * 60 * 72 if ((!lastChecked || hasNewUpdateSinceLastClicked) && notOlderThanThreeDays) { el.innerHTML = ` ` const link = el.getElementsByTagName('a')[0] link.addEventListener('click', function() { localStorage.lastChangelogClick = Date.now() setTimeout(() => { link.remove() }, 100) }) } } const embedButton = document.getElementById('generate-embed') if (embedButton) { embedButton.addEventListener('click', function(_e) { const baseUrl = document.getElementById('base-url').value const embedCode = document.getElementById('embed-code') const theme = document.getElementById('theme').value.toLowerCase() const background = document.getElementById('background').value try { const embedLink = new URL(document.getElementById('embed-link').value) embedLink.searchParams.set('embed', 'true') embedLink.searchParams.set('theme', theme) if (background) { embedLink.searchParams.set('background', background) } embedCode.value = `