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

Version Path
formstrap-0.4.5 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
headmin-0.6.3 app/assets/javascripts/headmin/controllers/infinite_scroller_controller.js
formstrap-0.4.4 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.4.3 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.4.2 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.3.5 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.3.4 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.3.3 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.3.2 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.3.1 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.3.0 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.2.1 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.2.0 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.1.3 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.1.2 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.1.1 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js
formstrap-0.1.0 app/assets/javascripts/formstrap/controllers/infinite_scroller_controller.js