index.html 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Lee Morgan</title>
  6. <link rel="stylesheet" href="/travel/style">
  7. </head>
  8. <body>
  9. <h1 id="title"></h1>
  10. <div id="images"></div>
  11. <div id="fullPage" style="display:none">
  12. <svg id="closeImg" width="50" height="50" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
  13. <line x1="18" y1="6" x2="6" y2="18"></line>
  14. <line x1="6" y1="6" x2="18" y2="18"></line>
  15. </svg>
  16. <svg id="nextImg" width="50" height="50" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
  17. <line x1="5" y1="12" x2="19" y2="12"></line>
  18. <polyline points="12 5 19 12 12 19"></polyline>
  19. </svg>
  20. <svg id="previousImg" width="50" height="50" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
  21. <line x1="19" y1="12" x2="5" y2="12"></line>
  22. <polyline points="12 19 5 12 12 5"></polyline>
  23. </svg>
  24. </div>
  25. <script>
  26. let fullPage = document.getElementById("fullPage");
  27. let container = document.getElementById("images");
  28. let path = window.location.pathname
  29. .split("/")
  30. .slice(2)
  31. .join("/");
  32. window.imageIndex = 0;
  33. fetch(`/travel/images/${path}`)
  34. .then(response => response.json())
  35. .then((response)=>{
  36. for(let i = 0; i < response.length; i++){
  37. let img = document.createElement("img");
  38. img.src = response[i];
  39. img.alt = "A picture";
  40. img.onclick = ()=>{
  41. imageIndex = i;
  42. let newImg = img.cloneNode(true);
  43. fullPage.appendChild(newImg);
  44. fullPage.style.display = "flex";
  45. newImg.onclick = ()=>{event.stopPropagation()}
  46. };
  47. container.appendChild(img);
  48. }
  49. })
  50. .catch(err => {});
  51. let newPath = path.split("/");
  52. let title = "";
  53. for(let i = newPath.length - 1; i >= 0; i--){
  54. if(newPath[i] === "") continue;
  55. title += `${newPath[i].replaceAll("-", " ")}, `;
  56. }
  57. document.getElementById("title").innerText = title.substring(0, title.length-2);
  58. document.getElementById("fullPage").onclick = ()=>{
  59. fullPage.removeChild(document.querySelector("#fullPage img"));
  60. fullPage.style.display = "none";
  61. };
  62. document.getElementById("nextImg").onclick = ()=>{
  63. event.stopPropagation();
  64. if(imageIndex >= container.children.length - 1) return;
  65. imageIndex++;
  66. let newImg = container.children[imageIndex].cloneNode(true);
  67. newImg.onclick = ()=>{event.stopPropagation()};
  68. fullPage.removeChild(document.querySelector("#fullPage img"));
  69. fullPage.appendChild(newImg);
  70. }
  71. document.getElementById("previousImg").onclick = ()=>{
  72. event.stopPropagation();
  73. if(imageIndex <= 0) return;
  74. imageIndex--;
  75. let newImg = container.children[imageIndex].cloneNode(true);
  76. newImg.onclick = ()=>{event.stopPropagation()};
  77. fullPage.removeChild(document.querySelector("#fullPage img"));
  78. fullPage.appendChild(newImg);
  79. }
  80. </script>
  81. </body>
  82. </html>