Sha256: 389617f8f642391688d7ba5a5a9bbd7721690e0aad820325d2542e19c13ae92c
Contents?: true
Size: 774 Bytes
Versions: 17
Compression:
Stored size: 774 Bytes
Contents
import { Controller } from '@hotwired/stimulus' export default class extends Controller { connect () { this.clickWhenInViewport() document.querySelector('.modal-body').addEventListener('scroll', () => { this.clickWhenInViewport() }) } clickWhenInViewport () { if (!this.isLoading() && this.isInViewport()) { this.element.setAttribute('clicked', 1) this.element.click() } } isLoading () { return this.element.hasAttribute('clicked') } isInViewport () { const rect = this.element.getBoundingClientRect() return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth) } }
Version data entries
17 entries across 17 versions & 2 rubygems