useBubbleHeader.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ref } from 'vue'
  3. export const useBubbleHeader = () => {
  4. const showMetaInformation = ref(false)
  5. const isInteractiveTarget = (target: HTMLElement) => {
  6. if (!target) return false
  7. const interactiveElements = new Set(['A', 'BUTTON'])
  8. // Parent interactive or traversed nodes
  9. const hasInteractiveElements = target.closest(
  10. Array.from(interactiveElements).join(','),
  11. )
  12. return interactiveElements.has(target.tagName) || hasInteractiveElements
  13. }
  14. const hasSelectionRange = (target: HTMLElement) => {
  15. if (!target) return false
  16. const selection = window.getSelection()
  17. if (!selection || selection.type !== 'Range') return false
  18. return true
  19. }
  20. const toggleHeader = (event: MouseEvent) => {
  21. if (
  22. isInteractiveTarget(event.target as HTMLElement) ||
  23. hasSelectionRange(event.target as HTMLElement)
  24. )
  25. return
  26. showMetaInformation.value = !showMetaInformation.value
  27. }
  28. return {
  29. showMetaInformation,
  30. toggleHeader,
  31. }
  32. }