Sha256: 48bd1835862e7857ffc72fc621a25eb6b9582aeec84658260157853a99e39fe1
Contents?: true
Size: 1.65 KB
Versions: 8
Compression:
Stored size: 1.65 KB
Contents
// Controllers import NavbarController from './app/javascript/navbar_controller' import NestedController from './app/javascript/nested_controller' import PgFormController from './app/javascript/pg_form_controller' // Bootstrap's toasts import * as bootstrap from 'bootstrap' window.Stimulus.register('navbar', NavbarController) window.Stimulus.register('nested', NestedController) window.Stimulus.register('pg_form', PgFormController) document.addEventListener('turbo:load', function () { const toastElList = document.querySelectorAll('.toast:not(.hide):not(.show)') Array.from(toastElList).map(toastEl => new bootstrap.Toast(toastEl).show()) // Select the node that will be observed for mutations const targetNode = document.getElementById('flash') // Options for the observer (which mutations to observe) const config = { attributes: true, childList: true, subtree: true } // Callback function to execute when mutations are observed const callback = (mutationList, observer) => { for (const mutation of mutationList) { if (mutation.type === 'childList') { console.log('A child node has been added or removed.') const toastElList = document.querySelectorAll('.toast:not(.hide):not(.show)') Array.from(toastElList).map(toastEl => new bootstrap.Toast(toastEl).show()) } else if (mutation.type === 'attributes') { console.log(`The ${mutation.attributeName} attribute was modified.`) } } } // Create an observer instance linked to the callback function const observer = new MutationObserver(callback) // Start observing the target node for configured mutations observer.observe(targetNode, config) })
Version data entries
8 entries across 8 versions & 1 rubygems