Sha256: 1526ec84f6460a199ab2f080f1971616a5a30ed4dcd4329f95d09908b1ab96ac

Contents?: true

Size: 782 Bytes

Versions: 13

Compression:

Stored size: 782 Bytes

Contents

import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static get targets() {
    return [ "button", "container" ]
  }

  connect() {
    this.scrollElement.addEventListener("scroll", this.load.bind(this))
    this.load() // Initial load
  }

  disconnect() {
    this.scrollElement.removeEventListener("scroll", this.load.bind(this))
  }
  
  load() {
    if (this.hasButtonTarget) {
      let top = this.buttonTarget.getBoundingClientRect().top
      if (top < window.innerHeight + 500) {
        this.buttonTarget.click()
        this.buttonTarget.remove()
      }
    }
  }
  
  get scrollElement() {
    if (this.hasContainerTarget) {
      return this.containerTarget
    } else {
      return document.getElementById("main")
    }
  }

}

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
spina-2.18.0 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.17.0 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.16.0 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.15.1 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.15.0 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.14.0 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.13.1 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.13.0 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.12.0 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.11.0 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.10.0 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.9.1 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js
spina-2.9.0 app/assets/javascripts/spina/controllers/infinite_scroll_controller.js