-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
177 lines (125 loc) · 5.4 KB
/
index.js
File metadata and controls
177 lines (125 loc) · 5.4 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
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
const navAni = document.querySelector('.Nav-header');
navAni.addEventListener('mouseover', function(event){
event.target.style.color = 'blue';
setTimeout(function() {
event.target.style.color = '#212529';
},1000)
},false)
/*const dblClicker = document.querySelector('.btn');
dblClicker.addEventListener('dblclick', function(e){
event.preventDefault();
event.target.style.color = 'blue';
})
const hover = document.querySelector('.Profile-info');
hover.addEventListener('mouseover', function(evenrt){
event.target.style.color = 'red';
setTimeout(function() {
event.target.style.color = 'purple';
},1000)
},false)
const large = document.querySelectorAll('.profile');
large.addEventListener('dblclick', function(e){
large.classlist.toggle('.grow');
})*/
/*
class TabLink {
constructor (tab) {
this.tab = tab;
this.tabData = this.tab.dataset.tab;
this.tabContent = document.querySelectorAll(`.content[data-tab="${this.tabData}"]`)
this.tabContent = Array.from(this.tabContent).map(content => new TabContent(content));
this.tabElement.addEventListener('click', () => this.tabClick());
}
tabClick() {
const tabs = document.querySelectorAll('.tab-links')
tabs.forEach( function (tab) {
tabs.classList.remove('.active-tab')
})
const contents = document.querySelectorAll('.content')
contents.forEach(function (content) {
content.style.display = 'none';
console.log(content)
})
this.tabElement.classList.add('.active-tab');
console.log(this.tabElement)
this.contents.forEach(content => content.selectCard());
console.log(this.contents)
}
}
class TabContent {
constructor (content) {
this.content = content;
}
toggleContent() {
this.content.classlist.toggle('.change')
}
}
const tabs = document.querySelectorAll('.tab-links .link')
.forEach(tab => new TabLink(tab))
const tabContentCards = document.querySelectorAll('.content')
tabContentCards.forEach( card => {
//prepend the image to the card
})
*/
class TabLink {
constructor(tabElement){
// assign this.tabElement to the tabElement DOM reference
this.tabElement = tabElement;
console.log(this.tabElement)
// Get the `data-tab` value from this.tabElement and store it here
this.tabData = this.tabElement.dataset.tab;
console.log(this.tabData)
// We need to find out if a user clicked 'all' cards or a specific category. Follow the instructions below to accomplish this task:
// Check to see if this.tabData is equal to 'all'
if(this.tabData == 'all'){
// If `all` is true, select all cards regardless of their data attribute values
this.cards = document.querySelectorAll('.card');
} else {
// else if `all` is false, only select the cards with matching this.tabData values
this.cards = document.querySelectorAll(`.card[data-tab="${this.tabData}"]`);
}
// Map over the newly converted NodeList we just created in our if statement above. Convert each this.cards element into a new instance of the TabCard class. Pass in a card object to the TabCard class.
this.cards = Array.from(this.cards).map(card => new TabCard(card));
// Add a click event that invokes this.selectTab
this.tabElement.addEventListener('click', () => this.selectTab());
}
selectTab(){
// Select all elements with the .tab class on them
const tabs = document.querySelectorAll('.tab');
// Iterate through the NodeList removing the .active-tab class from each element
tabs.forEach(function (tab) {
tab.classList.remove('active-tab')
} )
// Select all of the elements with the .card class on them
const cards = document.querySelectorAll('.card');
// Iterate through the NodeList setting the display style each one to 'none'
cards.forEach(function (card) {
card.style.display = 'none';
console.log(cards)
})
// Add a class of ".active-tab" to this.tabElement
this.tabElement.classList.add('.active-tab');
console.log(this.tabElement)
// Notice we are looping through the this.cards array and invoking selectCard() from the TabCard class. Just un-comment the code and study what is happening here.
this.cards.forEach(card => card.selectCard());
console.log(this.cards)
}
}
class TabCard {
constructor(cardElement){
// Assign this.cardElement to the cardElement DOM reference
this.cardElement = cardElement
}
selectCard(){
// Update the style of this.cardElement to display = "flex"
this.cardElement.style.display = "flex";
console.log(this.cardElement)
}
}
//START HERE:
//Select all classes named ".tab" and assign that value to the tabs variable
let tabs = document.querySelectorAll('.tab')
tabs.forEach(tab => new TabLink(tab))
console.log(tabs)
//With your selection in place, now chain a .forEach() method onto the tabs variable to iterate over the DOM NodeList
//In your .forEach() method's callback function, return a new instance of TabLink and pass in each tab as a parameter