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.27 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.26 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.25 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.24 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.24.pre.5 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.24.pre.4 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.24.pre.3 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.23 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.22 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.22.pre.3 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.22.pre.2 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.22.pre.1 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.21 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.21.pre.11 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.21.pre.10 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.21.pre.9 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.21.pre.8 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.21.pre.7 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.21.pre.6 pg_layout/app/javascript/controllers/tooltip_controller.js
pg_rails-7.6.21.pre.5 pg_layout/app/javascript/controllers/tooltip_controller.js