index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Botao de voltar para o topo da pagina
  2. let btnVoltar = document.getElementById("ifr__btn__backToTop");
  3. window.onscroll = function () {
  4. scrollFunction();
  5. };
  6. function scrollFunction() {
  7. if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
  8. btnVoltar.style.display = "block";
  9. } else {
  10. btnVoltar.style.display = "none";
  11. }
  12. }
  13. function backToTop() {
  14. document.body.scrollTop = 0;
  15. document.documentElement.scrollTop = 0;
  16. }
  17. // Insere em todos rodapés
  18. let footer = document.getElementById("footer");
  19. footer.innerHTML =
  20. "<p>Atualizado pela ultima vez em: 3 de Outubro de 2023 -- por <a href='http://www.ime.usp.br/~laira'>Laira</a>.</p>";
  21. // Cria menu de navegação
  22. let nav = document.querySelector(".navbar");
  23. nav.innerHTML = `
  24. <div class="container-fluid">
  25. <a class="navbar-brand" aria-current="page" target="_self" href="index.html">iFractions</a>
  26. <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown"
  27. aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
  28. <span class="navbar-toggler-icon"></span>
  29. </button>
  30. <div class="collapse navbar-collapse" id="navbarNavDropdown">
  31. <ul class="navbar-nav">
  32. <li class="nav-item">
  33. <a class="nav-link" target="_self" href="index.html#download">Download</a>
  34. </li>
  35. <li class="nav-item">
  36. <a class="nav-link" target="_self" href="./paginas/sobre/page_1.html">Conhecendo o iFractions</a>
  37. </li>
  38. <li class="nav-item dropdown">
  39. <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button"
  40. data-bs-toggle="dropdown" aria-expanded="false"> Documentação
  41. </a>
  42. <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
  43. <li><a class="dropdown-item" target="_self" href='./paginas/documentacao.html'>Início</a>
  44. </li>
  45. <li><a class="dropdown-item" target="_self" href='./paginas/documentacao.html#sou-prof'>Sou Professor</a>
  46. </li>
  47. <li><a class="dropdown-item" target="_self" href='./paginas/documentacao.html#sou-admin'>Sou
  48. Administrador Moodle</a>
  49. </li>
  50. <li><a class="dropdown-item" target="_self" href='./paginas/documentacao.html#sou-dev'>Sou
  51. Desenvolvedor</a>
  52. </li>
  53. </ul>
  54. </li>
  55. <li class="nav-item">
  56. <a class="nav-link" target="_self" href="./paginas/publicacoes.html">Publicações</a>
  57. </li>
  58. </ul>
  59. </div>
  60. </div>
  61. `;
  62. // Coloca imagem no modal
  63. const modal = document.getElementById("myModal");
  64. let img = document.getElementsByClassName("ifr__img");
  65. for (let i = 0; i < img.length; i++) {
  66. img[i].addEventListener("click", function () {
  67. modal.style.display = "block";
  68. document.getElementById("myModal-img").src = img[i].src;
  69. document.getElementById("caption").innerHTML = this.alt;
  70. });
  71. }
  72. let span = document.getElementsByClassName("close")[0];
  73. span.onclick = () => (modal.style.display = "none");
  74. // Gera indice
  75. const toc = document.querySelector(".ifr__toc");
  76. if (toc) {
  77. const sections_all = document.querySelectorAll("section");
  78. sections_all.forEach((section_h2) => {
  79. const h2 = section_h2.querySelectorAll("h2")[0];
  80. if (h2) {
  81. const h2_ul = document.createElement("ul");
  82. const h2_li = document.createElement("li");
  83. const h3_ul = document.createElement("ul");
  84. const sections_h3 = section_h2.querySelectorAll("section");
  85. sections_h3.forEach((section_h3) => {
  86. const h3 = section_h3.querySelectorAll("h3")[0];
  87. if (h3) {
  88. const h3_li = document.createElement("li");
  89. h3_li.innerHTML = `<a href="#${section_h3.id}" target="_self">${h3.innerHTML}</a>`;
  90. h3_ul.appendChild(h3_li);
  91. }
  92. });
  93. h2_li.innerHTML = `<a href="#${section_h2.id}" target="_self">${h2.innerHTML}</a>`;
  94. h2_ul.appendChild(h2_li);
  95. h2_ul.appendChild(h3_ul);
  96. toc.appendChild(h2_ul);
  97. }
  98. });
  99. }
  100. // Insere em todos rodapés
  101. const updateMenu = (depth) => {
  102. const path = depth == 1 ? "../" : "../../";
  103. const semiPath = depth == 1 ? "./" : "../";
  104. nav.innerHTML = `
  105. <div class="container-fluid">
  106. <a class="navbar-brand" aria-current="page" target="_self" href="${path}index.html">iFractions</a>
  107. <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown"
  108. aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
  109. <span class="navbar-toggler-icon"></span>
  110. </button>
  111. <div class="collapse navbar-collapse" id="navbarNavDropdown">
  112. <ul class="navbar-nav">
  113. <li class="nav-item">
  114. <a class="nav-link" target="_self" href="${path}index.html#download">Download</a>
  115. </li>
  116. <li class="nav-item">
  117. <a class="nav-link" target="_self" href="${semiPath}sobre/page_1.html">Conhecendo o iFractions</a>
  118. </li>
  119. <li class="nav-item dropdown">
  120. <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button"
  121. data-bs-toggle="dropdown" aria-expanded="false"> Documentação
  122. </a>
  123. <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
  124. <li><a class="dropdown-item" target="_self" href='${semiPath}documentacao.html'>Início</a>
  125. </li>
  126. <li><a class="dropdown-item" target="_self" href='${semiPath}documentacao.html#sou-prof'>Sou Professor</a>
  127. </li>
  128. <li><a class="dropdown-item" target="_self" href='${semiPath}documentacao.html#sou-dev'>Sou
  129. Administrador Moodle</a>
  130. </li>
  131. <li><a class="dropdown-item" target="_self" href='${semiPath}documentacao.html#sou-admin'>Sou
  132. Desenvolvedor</a>
  133. </li>
  134. </ul>
  135. </li>
  136. <li class="nav-item">
  137. <a class="nav-link" target="_self" href="${semiPath}publicacoes.html">Publicações</a>
  138. </li>
  139. </ul>
  140. </div>
  141. </div>
  142. `;
  143. };