You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.3 KiB

  1. window.addEventListener("scroll", function (e) {
  2. if (document.querySelector("body").clientWidth > 767) {
  3. let rightcolumn = document.querySelector(".rightcolumn");
  4. let mantletitle =
  5. document.querySelector(".mantletitle") ||
  6. document.querySelector(".crusttitle") ||
  7. false;
  8. if (!mantletitle) {
  9. return;
  10. }
  11. let mantlebar = document.querySelector(".mantlebar");
  12. let grid = document.querySelector(".grid");
  13. let gridrect = mantletitle.getBoundingClientRect();
  14. if (
  15. document.querySelector("body").clientHeight -
  16. (grid.clientHeight + mantletitle.clientHeight + 32) <
  17. window.innerHeight
  18. ) {
  19. return;
  20. }
  21. if (gridrect.top < 20 && !grid.classList.contains("moved")) {
  22. grid.classList.add("moved");
  23. mantlebar.style.display = "inline";
  24. mantletitle.style.visibility = "hidden";
  25. } else if (gridrect.top > 21 && grid.classList.contains("moved")) {
  26. grid.classList.remove("moved");
  27. mantletitle.style.visibility = "visible";
  28. mantlebar.style.display = "none";
  29. }
  30. } else {
  31. let rightcolumn = document.querySelector(".rightcolumn");
  32. let mantletitle =
  33. document.querySelector(".mantletitle") ||
  34. document.querySelector(".crusttitle") ||
  35. false;
  36. if (!mantletitle) {
  37. return;
  38. }
  39. let mantlebar = document.querySelector(".mantlebar");
  40. let grid = document.querySelector(".grid");
  41. let gridrect = mantletitle.getBoundingClientRect();
  42. if (gridrect.top < 20 && !grid.classList.contains("moved")) {
  43. grid.classList.add("moved");
  44. mantlebar.style.display = "inline";
  45. mantletitle.style.visibility = "hidden";
  46. } else if (gridrect.top > 21 && grid.classList.contains("moved")) {
  47. grid.classList.remove("moved");
  48. mantletitle.style.visibility = "visible";
  49. mantlebar.style.display = "none";
  50. }
  51. }
  52. });
  53. function editPage(repoJsId) {
  54. let relPath = "../".repeat(relPathDepth - 1);
  55. var el = document.createElement('script');
  56. el.onload = ()=> {
  57. console.log("loading...")
  58. console.log(repo)
  59. }
  60. el.src = `${relPath}js/repo/${repoJsId}.js`
  61. document.body.appendChild(el)
  62. document.location.href = `${relPath}edit/index.html#${repoJsId}`
  63. ev}
  64. window.addEventListener("keyup", (e)=> {
  65. if (e.key == "e" && location.protocol == "file:") {
  66. editPage(sandpointsPageId)
  67. }
  68. })
  69. window.addEventListener("DOMContentLoaded", (e) => {
  70. if (location.protocol == "file:") {
  71. document.querySelectorAll(".svedit").forEach((i) => {
  72. i.style.display = "inline";
  73. })
  74. }
  75. document.querySelectorAll('.triadlink').forEach((i) => {
  76. console.log(i)
  77. i.addEventListener("click", (ev) => {
  78. if (ev.ctrlKey) {
  79. ev.preventDefault()
  80. editPage(ev.target.getAttribute("repoid"))
  81. }
  82. })
  83. })
  84. let preview = document.querySelector("#preview");
  85. if (
  86. location.pathname.split("/").includes("_preview") ||
  87. location.hash.startsWith("#/_edit")
  88. ) {
  89. preview.style.display = "flex";
  90. }
  91. let par = document.querySelector(
  92. "#TableOfContents > ol:first-child > li:first-child"
  93. );
  94. if (par) {
  95. let s = document.createElement("span");
  96. s.appendChild(par.cloneNode(true));
  97. par.remove();
  98. document
  99. .querySelector("#TableOfContents > ol:first-child")
  100. .insertBefore(
  101. s,
  102. document.querySelector("#TableOfContents > ol:first-child").firstChild
  103. );
  104. }
  105. if (document.querySelector(".soundcite")) {
  106. let relPath = "../".repeat(relPathDepth - 1);
  107. var popcorn = document.createElement("script");
  108. popcorn.src = `${relPath}js/popcorn.min.js`;
  109. document.body.appendChild(popcorn);
  110. var soundcite = document.createElement("script");
  111. soundcite.src = `${relPath}js/soundcite.min.js`;
  112. document.body.appendChild(soundcite);
  113. }
  114. document
  115. .querySelectorAll(
  116. "#TableOfContents a, .anchorz, .footnote-backref, .footnote-ref"
  117. )
  118. .forEach((i) => {
  119. i.addEventListener("click", (e) => {
  120. setTimeout(() => {
  121. window.scrollBy({
  122. top: document.querySelector(".header").clientHeight * -1.25,
  123. behavior: "smooth",
  124. });
  125. }, 50);
  126. });
  127. });
  128. });
  129. toggleAllLinks = function () {
  130. document.querySelectorAll("details").forEach((i) => {
  131. if (i.open) {
  132. i.removeAttribute("open");
  133. } else {
  134. i.setAttribute("open", true);
  135. }
  136. });
  137. };