generated from maxii1996/BaduCalculator-Online
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro.js
187 lines (143 loc) · 4.79 KB
/
intro.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
let slideIndex = 0;
let currentElement = null;
let hasUserSeenSpotlight = false;
document.addEventListener('DOMContentLoaded', function() {
const popup = document.getElementById('popup');
const closeBtn = document.getElementById('close');
const prevBtn = document.getElementById('prev');
const nextBtn = document.getElementById('next');
const slides = document.querySelector('.slides');
const hasSeenInfoBox = localStorage.getItem('hasSeenInfoBox');
if (hasSeenInfoBox) {
const popup = document.getElementById('popup');
popup.style.display = 'none';
const spotlight = document.querySelector('.spotlight');
if (spotlight) {
spotlight.style.display = 'none';
}
}
closeBtn.addEventListener('click', function() {
if (currentElement) {
currentElement.classList.remove('focused');
}
const spotlightElement = document.querySelector('.spotlight');
if (spotlightElement) {
spotlightElement.classList.remove('spotlight');
}
const spotlight = document.querySelector('.spotlight');
if (spotlight) {
spotlight.style.display = 'none';
}
popup.style.display = 'none';
localStorage.setItem('hasSeenInfoBox', 'true');
});
prevBtn.addEventListener('click', function() {
slideIndex = Math.max(0, slideIndex - 1);
updateSlide();
});
nextBtn.addEventListener('click', function() {
slideIndex = Math.min(slides.children.length - 1, slideIndex + 1);
updateSlide();
});
function updateSlide() {
const slideWidth = slides.children[0].offsetWidth;
slides.style.transform = `translateX(-${slideWidth * slideIndex}px)`;
const animatedTexts = document.querySelectorAll('.animated-text');
animatedTexts.forEach(text => {
text.classList.remove('slide-1-animation');
});
const currentSlide = slides.children[slideIndex];
const currentAnimatedTexts = currentSlide.querySelectorAll('.animated-text');
currentAnimatedTexts.forEach((text, index) => {
setTimeout(() => {
text.classList.add('slide-1-animation');
}, 200 * (index + 1));
});
if (slideIndex === 0) {
prevBtn.style.display = 'none';
} else {
prevBtn.style.display = 'inline-block';
}
if (slideIndex === slides.children.length - 1) {
nextBtn.style.display = 'none';
closeBtn.style.display = 'inline-block';
} else {
nextBtn.style.display = 'inline-block';
closeBtn.style.display = 'none';
}
}
updateSlide();
});
function setSpotlight(element) {
if (currentElement) {
if (currentElement.classList.contains('toggle-label')) {
currentElement.parentElement.classList.remove('focused');
} else {
currentElement.classList.remove('focused');
}
}
if (!element) {
currentElement = null;
return;
}
currentElement = element;
if (currentElement.classList.contains('toggle-label')) {
currentElement.parentElement.classList.add('focused');
} else {
currentElement.classList.add('focused');
}
}
function updateSpotlight() {
const hasSeenHelp = localStorage.getItem('hasSeenHelp');
if (hasSeenHelp === 'true') {
return;
}
setTimeout(() => {
const currentIndex = getCurrentSlideIndex();
if (hasUserSeenSpotlight) {
setSpotlight(null);
return;
}
if (currentIndex === 0) {
setSpotlight(null);
} else if (currentIndex === 1) {
setSpotlight(document.getElementById('modal-btn'));
} else if (currentIndex === 2) {
setSpotlight(document.getElementById('toggleAgregarProducto'));
} else if (currentIndex === 3) {
setSpotlight(document.querySelector('.toggle-switch'));
setSpotlight(document.querySelector('.toggle-label'));
} else if (currentIndex === 4) {
setSpotlight(document.getElementById('facturar-btn'));
}
}, 150);
}
document.getElementById('next').addEventListener('click', () => {
updateSpotlight();
});
document.getElementById('prev').addEventListener('click', () => {
updateSpotlight();
});
document.getElementById('close').addEventListener('click', () => {
localStorage.setItem('hasSeenInfoBox', true);
});
function getCurrentSlideIndex() {
return slideIndex;
}
function hideSpotlight() {
const spotlightElement = document.querySelector('.spotlight');
if (spotlightElement) {
spotlightElement.classList.remove('spotlight');
}
hasUserSeenSpotlight = true;
}
try {
const entendidoButton = document.getElementById('entendido');
if (entendidoButton) {
entendidoButton.addEventListener('click', () => {
localStorage.setItem('hasSeenInfoBox', true);
});
}
} catch (error) {
}
updateSpotlight();