Sha256: 6d916fcd2a35a0dd5bc598cd821cc3d06cafd1dcd6378be05bb804b9e7714ca5

Contents?: true

Size: 759 Bytes

Versions: 117

Compression:

Stored size: 759 Bytes

Contents

import { Controller } from '@hotwired/stimulus'

// Connects to data-controller="switcher"
export default class extends Controller {
  connect () {
    if (this.element.checked) {
      this.show()
    }
    this.element.setAttribute('data-action', `${this.element.getAttribute('data-action') || ''} switcher#show`)
  }

  show () {
    const elemToShow = document.querySelector(this.element.dataset.target)
    this.getSiblings(elemToShow).forEach((el) => {
      el.classList.add('d-none')
      el.classList.remove('d-block')
    })
    elemToShow.classList.remove('d-none')
    elemToShow.classList.add('d-block')
  }

  getSiblings (el) {
    const childrenArray = [...el.parentNode.children]
    return childrenArray.filter(child => child !== el)
  }
}

Version data entries

117 entries across 117 versions & 1 rubygems

Version Path
pg_rails-7.6.28 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.27 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.26 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.25 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.24 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.24.pre.5 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.24.pre.4 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.24.pre.3 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.23 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.22 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.22.pre.3 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.22.pre.2 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.22.pre.1 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.21 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.21.pre.11 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.21.pre.10 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.21.pre.9 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.21.pre.8 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.21.pre.7 pg_layout/app/javascript/controllers/switcher_controller.js
pg_rails-7.6.21.pre.6 pg_layout/app/javascript/controllers/switcher_controller.js