-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparisonClass.js
42 lines (40 loc) · 1.53 KB
/
comparisonClass.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
class Comparison{
constructor(){
this.symbols = [];
this.clicked = false;
this.compareDiv = document.getElementById('compareDiv');
this.compareButton = document.getElementById('compareButton');
}
compareHandler(buttonId, symbol){
document.getElementById(buttonId).addEventListener('click', (e) =>{
console.log(this.compareDiv.childNodes.length);
if(this.compareDiv.childNodes.length > 1){
compareButton.disabled = false;
}
if(this.compareDiv.childNodes.length < 4){
this.symbols.push(symbol);
let button = document.createElement('button');
this.compareDiv.appendChild(button);
button.textContent = symbol + " X";
this.compareListbutton(button, compareDiv);
this.disabled = false;
}
});
}
compare(){
this.compareButton.addEventListener('click', (e)=>{
let symbolsToCompare = this.symbols.toString().split(",");
window.location.href = `https://shaibenshoushan.github.io/Stonks/compare.html?symbols=${symbolsToCompare}`
})
}
compareListbutton(button, parent){
button.addEventListener('click', (e)=>{
console.log(this.compareDiv.childNodes.length);
if(this.compareDiv.childNodes.length < 4){
compareButton.disabled = true;
}
parent.removeChild(button);
this.symbols.pop();
});
}
}