Sha256: 40e469a4b3be20067fea59d5c2494b5d00caf47e3bd492d8931913d60f43b15d

Contents?: true

Size: 1.42 KB

Versions: 5

Compression:

Stored size: 1.42 KB

Contents

// Controllers
import NavbarController from './app/javascript/navbar_controller'
// Bootstrap's toasts
import * as bootstrap from 'bootstrap'

window.Stimulus.register('navbar', NavbarController)

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

5 entries across 5 versions & 1 rubygems

Version Path
pg_rails-7.0.8.pre.alpha pg_layout/index.js
pg_rails-7.0.7 pg_layout/index.js
pg_rails-7.0.6 pg_layout/index.js
pg_rails-7.0.5 pg_layout/index.js
pg_rails-7.0.4 pg_layout/index.js