-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.js
More file actions
72 lines (64 loc) · 2.99 KB
/
service.js
File metadata and controls
72 lines (64 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
document.addEventListener("DOMContentLoaded", function () {
const backToTopButton = document.getElementById("backToTop");
const nav = document.querySelector("nav");
const hamburgerMenu = document.getElementById("hamburgerMenu");
const buInput = document.getElementById("bu-input");
const buToggle = document.getElementById("buToggle");
// Almacenar el valor original de {{BU}} en un atributo data-original
const buElements = document.querySelectorAll("[data-bu]");
buElements.forEach((element) => {
element.setAttribute("data-original", element.textContent); // Guardar el valor original
});
// Cargar el valor guardado en localStorage (si existe)
const savedBUValue = localStorage.getItem("buValue");
if (savedBUValue) {
buInput.value = savedBUValue; // Establecer el valor en el input
updateBUValue(savedBUValue); // Actualizar los elementos con el valor guardado
}
// Función para reemplazar {{BU}} en el HTML
function updateBUValue(buValue) {
buElements.forEach((element) => {
const originalText = element.getAttribute("data-original"); // Obtener el valor original
if (buValue) {
// Reemplazar {{BU}} con el valor del input
element.textContent = originalText.replace(/{{BU}}/g, buValue);
} else {
// Restaurar el valor original si el input está vacío
element.textContent = originalText;
}
});
}
// Escuchar cambios en el input
buInput.addEventListener("input", function () {
const buValue = buInput.value.trim();
localStorage.setItem("buValue", buValue); // Guardar el valor en localStorage
updateBUValue(buValue); // Actualizar los elementos con el nuevo valor
});
window.addEventListener("scroll", function () {
const navHeight = nav.offsetHeight;
if (window.scrollY > navHeight) {
nav.classList.add("fixed-nav");
hamburgerMenu.classList.add("hamburguer-menu-fadeIn");
hamburgerMenu.classList.remove("hamburguer-menu-fadeOut");
buToggle.classList.remove("hidden");
} else {
nav.classList.remove("fixed-nav");
hamburgerMenu.classList.add("hamburguer-menu-fadeOut");
hamburgerMenu.classList.remove("hamburguer-menu-fadeIn");
buToggle.classList.add("hidden"); // Ocultar el icono
}
if (window.scrollY > navHeight) {
backToTopButton.classList.add("fadeIn");
backToTopButton.classList.remove("fadeOut");
} else {
backToTopButton.classList.add("fadeOut");
backToTopButton.classList.remove("fadeIn");
}
});
backToTopButton.addEventListener("click", function () {
window.scrollTo({
top: 0,
behavior: "smooth",
});
});
});