-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtroubleshooter.js
242 lines (225 loc) · 7.77 KB
/
troubleshooter.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
var page = 0;
var prevBtn
var nextBtn
var book
var chapter
var paper1
var paper2
var paper3
var paper4
var paper5
var paper6
var paper7
var paper8
var paper9
var paper10
var pageList
// Business Logic
let currentLocation = 1
let numOfPapers = 10
let maxLocation = numOfPapers + 1
$(document).ready(function($) {
prevBtn = document.getElementById("prev-btn")
nextBtn = document.getElementById("next-btn")
book = document.getElementById("book")
chapter = document.getElementById("chapter-cover")
paper1 = document.getElementById("p1")
paper2 = document.getElementById("p2")
pageList = [document.getElementById("page1"), document.getElementById("page2"),
document.getElementById("page3")]
// Event Listener
prevBtn.addEventListener("click", goPrevPage)
nextBtn.addEventListener("click", goNextPage)
})
function openBook() {
book.style.transform = "translateX(50%)"
prevBtn.style.transform = "translateX(-180px)"
nextBtn.style.transform = "translateX(180px)"
prevBtn.style.display = "inherit"
nextBtn.style.display = "inherit"
}
function closeBook(isAtBeginning) {
if(isAtBeginning) {
book.style.transform = "translateX(0%)"
currentLocation = 1
page = 0
} else {
book.style.transform = "translateX(100%)"
currentLocation = 11
page = 20
}
if(isAtBeginning) {
prevBtn.style.display = "none"
nextBtn.style.display = "inherit"
} else {
nextBtn.style.display = "none"
prevBtn.style.display = "inherit"
}
prevBtn.style.transform = "translateX(0px)"
nextBtn.style.transform = "translateX(0px)"
chapter.style.transition = "transform .5s"
chapter.style.transform = "scale(1)"
}
function goNextPage() {
if(currentLocation < maxLocation) {
prevBtn.style.display = "inherit"
nextBtn.style.display = "inherit"
page += 2
switch(currentLocation) {
case 1:
openBook()
paper1.classList.add("flipped")
paper1.style.zIndex = 1
currentLocation++
break
case 2:
paper2.classList.add("flipped")
paper2.style.zIndex = 2
currentLocation++
break
default:
throw new Error("unknown state")
}
if (currentLocation > numOfPapers) {
closeBook(false)
}
}
}
function goPrevPage() {
if(currentLocation > 1) {
var mobile = false
page -= 2
if (window.innerWidth <= 750) {
mobile = true
page += 1
}
switch(currentLocation) {
case 2:
if (mobile && mobileFlip) {
document.getElementById("page2").innerHTML = chapterList[0]
mobileFlip = false
} else {
mobileFlip = true
paper1.classList.remove("flipped")
paper1.style.zIndex = 10
currentLocation--
closeBook(true)
}
break
case 3:
if (mobile && mobileFlip) {
document.getElementById("page4").innerHTML = chapterList[2]
mobileFlip = false
} else {
mobileFlip = true
document.getElementById("page2").innerHTML = chapterList[1]
paper2.classList.remove("flipped")
paper2.style.zIndex = 9
currentLocation--
}
break
case 4:
if (mobile && mobileFlip) {
document.getElementById("page6").innerHTML = chapterList[4]
mobileFlip = false
} else {
mobileFlip = true
document.getElementById("page4").innerHTML = chapterList[3]
paper3.classList.remove("flipped")
paper3.style.zIndex = 8
currentLocation--
}
break
case 5:
if (mobile && mobileFlip) {
document.getElementById("page8").innerHTML = chapterList[6]
mobileFlip = false
} else {
mobileFlip = true
document.getElementById("page6").innerHTML = chapterList[5]
paper4.classList.remove("flipped")
paper4.style.zIndex = 7
currentLocation--
}
break
case 6:
if (mobile && mobileFlip) {
document.getElementById("page10").innerHTML = chapterList[8]
mobileFlip = false
} else {
mobileFlip = true
document.getElementById("page8").innerHTML = chapterList[7]
paper5.classList.remove("flipped")
paper5.style.zIndex = 6
currentLocation--
}
break
case 7:
if (mobile && mobileFlip) {
document.getElementById("page12").innerHTML = chapterList[10]
mobileFlip = false
} else {
mobileFlip = true
document.getElementById("page10").innerHTML = chapterList[9]
paper6.classList.remove("flipped")
paper6.style.zIndex = 5
currentLocation--
}
break
case 8:
if (mobile && mobileFlip) {
document.getElementById("page14").innerHTML = chapterList[12]
mobileFlip = false
} else {
mobileFlip = true
document.getElementById("page12").innerHTML = chapterList[11]
paper7.classList.remove("flipped")
paper7.style.zIndex = 4
currentLocation--
}
break
case 9:
if (mobile && mobileFlip) {
document.getElementById("page16").innerHTML = chapterList[14]
mobileFlip = false
} else {
mobileFlip = true
document.getElementById("page14").innerHTML = chapterList[13]
paper8.classList.remove("flipped")
paper8.style.zIndex = 3
currentLocation--
}
break
case 10:
if (mobile && mobileFlip) {
document.getElementById("page18").innerHTML = chapterList[16]
mobileFlip = false
} else {
mobileFlip = true
document.getElementById("page16").innerHTML = chapterList[15]
paper9.classList.remove("flipped")
paper9.style.zIndex = 2
currentLocation--
}
break
case 11:
paper10.classList.remove("flipped")
paper10.style.zIndex = 1
if (mobile) {
mobileFlip = true
document.getElementById("page18").innerHTML = chapterList[17]
}
currentLocation--
break
default:
throw new Error("unknown state")
}
if ((chapterList[page - 2] == `` && !mobile) || (chapterList[page - 1] ==`` && mobile)) {
mobileFlip = false
checkPagesReverse(mobile)
}
if (currentLocation == numOfPapers) {
openBook()
}
}
}