-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
159 lines (130 loc) · 4.4 KB
/
main.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
const nav = document.getElementsByTagName('nav')[0];
const cssAtivo = 'ativo';
const topoNav = nav.offsetTop;
const menuSections = document.querySelectorAll('.navSection');
const menuItens = document.querySelectorAll('nav div ul li');
const email = document.getElementsByClassName('social')[0];
const showArea = document.querySelector('.showArea');
const exitArea = document.querySelector('.exitArea');
const btnGenericos = document.querySelector('#btnGenericos');
const btnExemplos = document.querySelector('#btnExemplos');
import {gerarPosterGenerico, gerarPosterExemplo, smoothScrollTo} from './components/components.js';
email.addEventListener('click', (e)=>{
e.preventDefault();
let endereco = document.createElement('textarea');
endereco.value = "gileadeateixeira@gmail.com";
document.body.appendChild(endereco);
endereco.select();
document.execCommand("copy", false, `${endereco.value}`);
document.body.removeChild(endereco);
alert("O e-mail foi copiado: " + endereco.value);
});
window.addEventListener('scroll', ()=>{
fixarMenuNoTopo();
let current = '';
menuSections.forEach((section)=>{
const top = section.offsetTop;
const height = section.clientHeight;
if (window.pageYOffset >= top) {
current = section.getAttribute('id');
} else if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
//Chegou no fim da página
current = 'footer';
}
});
menuItens.forEach((item)=>{
item.classList.remove(cssAtivo);
if (item.classList.contains(current)) {
item.classList.add(cssAtivo);
};
});
});
const fixarMenuNoTopo = ()=> {
if(window.pageYOffset >= topoNav){
nav.classList.add('fixoNoTopo');
}
else{
nav.classList.remove('fixoNoTopo');
};
}
menuItens.forEach(
(item) => {
item.addEventListener('click', (event)=>{
scrollOnClick(event);
for (let index = 0; index < menuItens.length; index++) {
menuItens[index].classList.remove(cssAtivo);
};
item.classList.add(cssAtivo);
});
}
);
const scrollOnClick = (event)=>{
event.preventDefault();
const to = getTopByRef(event.target);
scrolToPosition(to);
};
const getTopByRef = (element)=>{
const id = element.getAttribute('href');
return document.querySelector(id).offsetTop;
};
const scrolToPosition = (to)=>{
/*
window.scroll({
top: to,
behavior: 'smooth',
});
*/
smoothScrollTo(0, to);
};
btnGenericos.addEventListener('click', (e)=>{
e.preventDefault();
showArea.innerHTML = "";
exitArea.innerHTML = "";
for (let index = 1; index <= 6; index++) {
const movie = document.createElement('div');
const generico = gerarPosterGenerico({index});
movie.classList.add('movies');
movie.innerHTML = generico.html;
movie.addEventListener('click', (e)=>{
e.preventDefault();
window.open(generico.url, '_blank').focus();
});
showArea.appendChild(movie);
};
const btn = document.createElement('button');
btn.id = 'btnExit';
btn.innerHTML = 'X';
btn.addEventListener('click', (e)=>{
e.preventDefault();
showArea.innerHTML = "";
exitArea.innerHTML = "";
});
exitArea.appendChild(btn);
});
btnExemplos.addEventListener('click', (e)=>{
e.preventDefault();
showArea.innerHTML = "";
exitArea.innerHTML = "";
for (let index = 1; index <= 6; index++) {
const background_color = Math.floor(Math.random()*16777215).toString(16);
const text_color = Math.floor(Math.random()*16777215).toString(16);
const movie = document.createElement('div');
const exemplo = gerarPosterExemplo({background_color, text_color, index});
movie.classList.add('movies');
movie.innerHTML = exemplo.html;
movie.addEventListener('click', (e)=>{
e.preventDefault();
window.open(exemplo.url, '_blank').focus();
});
showArea.appendChild(movie);
};
const btn = document.createElement('button');
btn.id = 'btnExit';
btn.innerHTML = 'X';
btn.addEventListener('click', (e)=>{
e.preventDefault();
showArea.innerHTML = "";
exitArea.innerHTML = "";
});
exitArea.appendChild(btn);
});