usePrintMode.ts 655 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ref } from 'vue'
  3. const getRoot = () => document.querySelector(':root') as HTMLElement
  4. export const usePrintMode = () => {
  5. const isPrintMode = ref(false)
  6. const turnOnPrintMode = () => {
  7. getRoot().dataset.printMode = 'true'
  8. isPrintMode.value = true
  9. }
  10. const turnOffPrintMode = () => {
  11. delete getRoot().dataset.printMode
  12. isPrintMode.value = false
  13. }
  14. const printPage = () => {
  15. turnOnPrintMode()
  16. window?.print()
  17. turnOffPrintMode()
  18. }
  19. return {
  20. isPrintMode,
  21. turnOnPrintMode,
  22. turnOffPrintMode,
  23. printPage,
  24. }
  25. }