-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchampion-table-handler.js
More file actions
70 lines (55 loc) · 2.32 KB
/
champion-table-handler.js
File metadata and controls
70 lines (55 loc) · 2.32 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
const path = window.location.pathname;
const pathArray = path.split('/');
const page = pathArray[pathArray.length - 1];
const championName = page.split('.')[0];
IMMUTABLE_STATS = ["attack-range", "speed", "attack-vamp", "power-vamp", "armor-breach", "shield-breach", "critical-chance", "critical-damage"];
const baseStats = BASE_STATS[championName];
const statsPerLevel = STATS_PER_LEVEL[championName];
console.log(statsPerLevel);
window.onload = function() {
for (let stat in baseStats) {
if (baseStats.hasOwnProperty(stat)) {
let className = `${stat}-value`;
let statElement = document.querySelector(`.${className}`);
let baseStat = baseStats[stat];
if (statElement) {
statElement.innerHTML = baseStat;
}
}
}
// add mobile nav handler here cause two window.onload scripts cant be used on one page
const mobileNavOpenBtn = document.getElementById('mobile-nav-open-btn');
const mobileNavCloseBtn = document.getElementById('mobile-nav-close');
const mobileNav = document.getElementById('mobile-nav');
mobileNavOpenBtn.addEventListener('click', function() {
mobileNav.style.left = '0';
mobileNavOpenBtn.style.display = 'none';
});
mobileNavCloseBtn.addEventListener('click', function() {
mobileNav.style.left = '-100%';
mobileNavOpenBtn.style.display = 'flex';
});
}
const selectElement = document.querySelector('.champion-level-select');
selectElement.addEventListener('change', ()=>{
const level = selectElement.value;
const levelInt = level.split(' ')[1];
for (let stat in baseStats) {
if (baseStats.hasOwnProperty(stat)) {
if (IMMUTABLE_STATS.includes(stat)) continue;
let newStat;
if (levelInt == 1) {
newStat = baseStats[stat];
} else if (stat == "attack-speed") {
newStat = baseStats[stat] - (statsPerLevel[stat] * (levelInt - 1));
} else {
newStat = baseStats[stat] + (statsPerLevel[stat] * (levelInt - 1));
}
let className = `${stat}-value`;
let statElement = document.querySelector(`.${className}`);
if (selectElement) {
statElement.innerHTML = newStat;
}
}
}
})