view.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. clearInterval(typeof intervalId == 'undefined' ? 0 : intervalId)
  2. // Copy HTML to clipboard
  3. document.querySelector('#copyHTML').addEventListener('click', e => {
  4. let iconContainer = e.currentTarget.querySelector('.icon');
  5. navigator.clipboard.writeText(document.querySelector('.content-body').innerHTML.trim()).then(
  6. () => {
  7. iconContainer.innerHTML = icon('clipboard-check');
  8. setTimeout(
  9. () => {
  10. iconContainer.innerHTML = icon('clipboard');
  11. },
  12. 3000
  13. );
  14. },
  15. () => {
  16. iconContainer.innerHTML = icon('clipboard-x');
  17. setTimeout(
  18. () => {
  19. iconContainer.innerHTML = icon('clipboard');
  20. },
  21. 3000
  22. );
  23. }
  24. );
  25. });
  26. // Edit Post form
  27. document.querySelector('#edit').addEventListener('click', event => {
  28. const endPoint = event.currentTarget.id == 'new' ? '/posts/new' : `/posts/${event.currentTarget.dataset.id}/${event.currentTarget.id}`
  29. doFetch(endPoint)
  30. })
  31. loadScript('https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.5.0/build/highlight.min.js')
  32. .then(
  33. async () => {
  34. if (document.querySelector('.language-nginx')) {
  35. await loadScript('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.1/languages/nginx.min.js')
  36. }
  37. hljs.highlightAll({ ignoreUnescapedHTML: true })
  38. }
  39. )