Sha256: 944a29ec603b5a27ee5dc2db824a7d2edb9b8ae3f1a1c81336b2e0e1c19369b5

Contents?: true

Size: 918 Bytes

Versions: 51

Compression:

Stored size: 918 Bytes

Contents

import { Controller } from '@hotwired/stimulus'
import * as bootstrap from 'bootstrap'

export default class extends Controller {
  tooltip = null

  connect () {
    if (this.element.dataset.bsTrigger === 'contextmenu') {
      this.element.addEventListener('contextmenu', (ev) => {
        ev.preventDefault()
        if (!this.tooltip) {
          this.tooltip = new bootstrap.Tooltip(this.element, {
            trigger: 'focus'
          })
          this.tooltip.show()
        }
      })
    } else {
      this.tooltip = new bootstrap.Tooltip(this.element)
    }
  }

  setContent (content) {
    this.tooltip.setContent({ '.tooltip-inner': content })
  }

  hide () {
    this.tooltip.hide()
  }

  disconnect () {
    if (this.tooltip) {
      // setTimeout because of:
      // https://github.com/twbs/bootstrap/issues/37474
      setTimeout(() => {
        this.tooltip.dispose()
      }, 300)
    }
  }
}

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
pg_rails-7.6.4 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.3 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.2 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.1 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.0 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.5.7 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.5.6 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.5.5 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.5.4 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.5.3 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.5.2 pg_layout/app/javascript/controllers/tooltip_controller.js