useArticleSeen.ts 487 B

123456789101112131415161718192021
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { useIntersectionObserver } from '@vueuse/core'
  3. import type { Ref } from 'vue'
  4. export const useArticleSeen = (
  5. element: Ref<HTMLElement | undefined>,
  6. emit: (...args: any[]) => void,
  7. ) => {
  8. const observer = useIntersectionObserver(
  9. element,
  10. ([{ isIntersecting }]) => {
  11. if (isIntersecting) {
  12. emit('seen')
  13. observer.stop()
  14. }
  15. },
  16. { threshold: 0.4 },
  17. )
  18. }