-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathurlWindow.js
111 lines (86 loc) · 2.04 KB
/
urlWindow.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
class UrlWindow {
$paginator;
constructor($paginator) {
this.$paginator = $paginator;
}
static make($paginator) {
return (new this($paginator)).get();
}
get() {
const $onEachSide = this.$paginator.$onEachSide;
if (this.$paginator.lastPage() < ($onEachSide * 2) + 8) {
return this.getSmallSlider();
}
return this.getUrlSlider($onEachSide);
}
getSmallSlider() {
return {
'first': this.$paginator.getUrlRange(1, this.lastPage()),
'slider': null,
'last': null,
};
}
getUrlSlider($onEachSide) {
const $window = $onEachSide + 4;
if (!this.hasPages()) {
return { 'first': null, 'slider': null, 'last': null };
}
if (this.currentPage() <= $window) {
return this.getSliderTooCloseToBeginning($window, $onEachSide);
}
else if (this.currentPage() > (this.lastPage() - $window)) {
return this.getSliderTooCloseToEnding($window, $onEachSide);
}
return this.getFullSlider($onEachSide);
}
getSliderTooCloseToBeginning($window, $onEachSide) {
return {
'first': this.$paginator.getUrlRange(1, $window + $onEachSide),
'slider': null,
'last': this.getFinish(),
};
}
getSliderTooCloseToEnding($window, $onEachSide) {
const $last = this.$paginator.getUrlRange(
this.lastPage() - ($window + ($onEachSide - 1)),
this.lastPage()
);
return {
'first': this.getStart(),
'slider': null,
'last': $last,
};
}
getFullSlider($onEachSide) {
return {
'first': this.getStart(),
'slider': this.getAdjacentUrlRange($onEachSide),
'last': this.getFinish(),
};
}
getAdjacentUrlRange($onEachSide) {
return this.$paginator.getUrlRange(
this.currentPage() - $onEachSide,
this.currentPage() + $onEachSide
);
}
getStart() {
return this.$paginator.getUrlRange(1, 2);
}
getFinish() {
return this.$paginator.getUrlRange(
this.lastPage() - 1,
this.lastPage()
);
}
hasPages() {
return this.$paginator.lastPage() > 1;
}
currentPage() {
return this.$paginator.currentPage();
}
lastPage() {
return this.$paginator.lastPage();
}
}
module.exports = UrlWindow;