forked from l0bster2/pocket-platformer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabPagination.js
59 lines (53 loc) · 2.26 KB
/
TabPagination.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
class TabPagination extends TabNavigation {
static staticConstructor() {
this.paginationLeft = document.getElementById("tabPaginationLeft");
this.paginationRight = document.getElementById("tabPaginationRight");
this.setPaginationToDefault();
}
static setPaginationToDefault() {
this.currentPages = {
[SpritePixelArrays.customType]: 1
}
Object.values(SpritePixelArrays.SPRITE_TYPES).map(spriteType =>
this.currentPages[spriteType] = 1);
}
static changePaginationVisibility(name) {
/*
extra amount, because pagination for custom tiles starts, when a page is full
and you can create new tiles on the next page
*/
const extaItemAmount = name === SpritePixelArrays.customType ? 1 : 0;
const pagesAmount = Math.ceil((this.selectableSprites.length + extaItemAmount) / this.maxSpritesPerTab);
if (pagesAmount > 1) {
document.getElementById("currentPage").innerHTML = this.currentPages[name];
if (this.currentPages[name] === 1) {
this.setPaginationNaviVisibility("none", "block")
}
else if (this.currentPages[name] === pagesAmount) {
this.setPaginationNaviVisibility("block", "none")
}
else {
this.setPaginationNaviVisibility("block", "block")
}
}
else {
document.getElementById("currentPage").innerHTML = "";
this.setPaginationNaviVisibility("none", "none")
}
}
static setPaginationNaviVisibility(leftStyle, rightStyle) {
this.paginationLeft.style.display = leftStyle;
this.paginationRight.style.display = rightStyle;
}
static changePage(amount) {
this.currentPages[this.currentSelectedTab] += amount;
this.changePaginationVisibility(this.currentSelectedTab);
this.drawSpritesByType();
TabNavigation.removeOldDeleteIcons();
TabNavigation.drawDeleteIconsForCustomSprites();
TabNavigation.positionNewSpriteButton();
}
static getPageOffset() {
return (this.currentPages[this.currentSelectedTab] - 1) * this.maxSpritesPerTab;
}
}