preview-only.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. export default (signed = false, forDownload = false, filename="contract-signed.html") => {
  2. if (!forDownload) {
  3. if (signed) return ''
  4. if (!signed) return `
  5. <script type="module">
  6. // ! PREVIEW ONLY
  7. // Handle submit button in preview
  8. //document.querySelector("#submit-btn")?.addEventListener("click", (e) => {
  9. document.querySelector("#signature_form").addEventListener("submit", (e) => {
  10. setTimeout(function() {
  11. // 📡 Send message to notify the parent window (received in preview.js)
  12. window.top.postMessage('previewAfterClientSigned', '*')
  13. }, 1500)
  14. e.preventDefault()
  15. })
  16. </script>`
  17. } else {
  18. if (signed) return `
  19. <script type="module">
  20. // ! PREVIEW ONLY
  21. let el = document.querySelector("#hk")
  22. let client_signature = localStorage.getItem("client_signature")
  23. el.src = client_signature
  24. // update timestamp and IP here
  25. // for both dev and client
  26. </script>`
  27. if (!signed) return `
  28. <script type="module">
  29. // ! PREVIEW ONLY
  30. // Handle submit button in preview
  31. //document.querySelector("#submit-btn")?.addEventListener("click", (e) => {
  32. document.querySelector("#signature_form").addEventListener("submit", (e) => {
  33. setTimeout(function() {
  34. window.location.assign("${filename}#hk")
  35. }, 1500)
  36. e.preventDefault()
  37. })
  38. </script>`
  39. }
  40. }