-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtestV5.html
371 lines (359 loc) · 10.5 KB
/
testV5.html
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#59b" />
<meta name="author" content="M A Eyler, Istanbul, 2020" />
<meta name="description" content="Reader for the Quran" />
<link rel="apple-touch-icon" href="image/icon.png">
<link rel="manifest" href="manifest.json">
<link rel="icon" href="image/icon.png">
<title>Iqra V4</title>
<style>
body {
margin: 0;
background-color: #59b;
min-height: 90vh;
}
iframe {
/* display: inline-block; */
position: absolute;
box-sizing: border-box;
border: none;
height: 100%;
min-width: 100px;
margin: auto;
transition: all 0.8s ease-out;
}
button {
position: fixed;
background-color: #ff7;
transition: all 0.8s ease-out;
border: 1px solid black;
border-radius: 15px;
cursor: pointer;
user-select: none;
}
#lang {
height: 28px; width: 28px;
top: 3px; left: 0;
/* flaticon.com/free-icon/language_1246334 */
background-image: url(image/language.png);
background-size: contain;
background-repeat: no-repeat;
border: none;
}
#lang:hover {
height: 32px; width: 32px;
}
#openM {
height: 28px; width: 28px;
top: 3px; right: 0;
font-weight: bold;
}
#openM:hover {
width: 36px;
}
#openM.upside {
transform: rotate(180deg);
}
#sizer {
box-sizing: border-box;
bottom: 3px;
border-radius: 5px;
font-weight: bold;
cursor: col-resize;
}
#ruler.sizing {
position: absolute;
width: 0px; height: 99vh;
border: 2px solid #ff7;
}
@media screen and (min-width: 851px) {
#findFrm {
/* resize: both; Chrome bug not resolved */
width: 50%;
max-height: 100%;
border-left: 1px solid #59b;
border-right: 1px solid #59b;
}
}
</style>
</head>
<body>
<iframe id=findFrm src='start.html'
name=finder title="Arama paneli"></iframe>
<iframe id=readFrm src='reader.html'
name=iqra title="Mushaf paneli"></iframe>
<button id=lang onclick="langMgr.nextLanguage()"
title="Language / اللغة / Dil 
English / العربي / Türkçe"></button>
<button id=openM>></button>
<button id=sizer>⇔</button>
<div id=ruler></div>
<p id=dummy hidden></p>
<script src="code/languages.js"></script>
<script>//localization strings
const localization = {};
localization.tr =
`openM title Arama panelini göster/gizle
sizer title Arama paneli genişliğini ayarla`
localization.en =
`openM title Hide/show the search panel
sizer title Adjust the panel width`
localization.ar =
`openM title عد لنافذة البحث
sizer title ضبط عرض النافذة`
let langMgr = new LangManager()
function applyLanguage() {
// console.log('applyLanguage', currentLanguage())
langMgr.applyLanguage()
iqra.postMessage("language", "*")
finder.postMessage("language", "*")
}
function applyTranslation() {
let k = getStorage('settings', 'source')
// console.log('applyTranslation', k)
iqra.postMessage("translation", "*")
finder.postMessage("translation", "*")
}
</script>
<script src="code/common.js"></script>
<script src="code/model.js"></script>
<script src="code/utilities.js"></script>
<script>
const TEST_VERSION = 'Test.5';
const swipe = new TouchHandler({dragStart, dragEnd}, dummy)
var lastPath, // finder location
hashInProgress = false,
finderIsShown = true,
WIDTH = Math.min(window.innerWidth, screen.width),
finderWidth = Number(getStorage('iqra', 'finderWidth') || WIDTH/2);
sizer.hidden = true
function dragStart(evt) {
// console.log("dragStart", window.name)
return true
}
function dragEnd(a) { //delegate all work to parent listener
console.log("dragEnd", a)
switch (a) {
case 0: case 12: //swipe left
case 6: //swipe right
if (parent.toggleFinder)
parent.toggleFinder() //yellow button
return true
case 3: //swipe up
window.open('start.html', 'finder')
return true
default: //angle not supported
return false
}
}
function addListener(frm) {
frm.contentWindow.addEventListener('hashchange', reportHash)
console.log('* addListener *', frm.name)
if (frm.name !== 'finder') return
let b = finder.document.querySelector('body')
b.ontouchstart = dummy.ontouchstart
b.ontouchend = dummy.ontouchend
}
function reportHash(e) { //hashchange in one of the panes
let s = '[Iqra]', h = ''
if (e.target.name == 'iqra') {
s = e.target.document.title
h = e.target.location.hash
console.log('hash:', h, ' curPage:', iqra.curPage)
if (hashToPage(h) === iqra.curPage) return
if (finderIsShown && singlePanel()) hideFinder()
} else { // finder
// lang.hidden = !isStartPage
if (e.target.document) {
s = e.target.document.title
h = e.target.location.hash
}
if (!finderIsShown) showFinder()
}
document.title = VERSION +' '+ s
// console.log('* reportHash *', h, location.hash)
if (h=='' || window.location.hash == h) return
window.location.hash = h
hashInProgress = true
}
function hashModified() {
let h = decodedHash()
// console.log('** hashInProgress='+hashInProgress, h)
if (hashInProgress || !h || h.length<3) {
hashInProgress = false; return
}
let [c, d] = h.split('=')
switch (c) { //first char
case 'p': case 'v':
window.open('reader.html#'+h, 'iqra'); hideFinder()
break;
case 'r':
window.open('mujam.html#'+h, 'finder')
break;
case 'b': case 'w': case 't':
window.open('/Rehber/finder.html#'+h, 'finder')
break
case 'c':
window.open('/Kitap/cuma/'+d+'.html', 'finder')
break;
case 'd':
window.open('/Kitap/ders/'+d+'.html', 'finder')
break;
case 'g':
window.open('/Kitap/garibce/'+d+'.html', 'finder')
break;
case 'm':
window.open('/Kitap/rama/'+d+'.html', 'finder')
break;
default:
if (c.length > 1)
window.open('konular.html#'+h, 'finder')
else console.error('wrong char '+c)
}
}
function toggleFinder() {
if (finderIsShown) hideFinder()
else showFinder()
}
function hideFinder() {
finderIsShown = false
// closeM.hidden=true; openM.hidden=false
resize()
}
function showFinder() {
finderIsShown = true
// closeM.hidden=false; openM.hidden=true
resize()
}
function setPosition(e, x, w) {
e.style.left = (x == 0)? 0 : x+'px'
if (w) e.style.width = (w == WIDTH)? '100%' : w+'px'
// if (e===readFrm) console.log('setPosition', x, w)
}
function singlePanel() {
return (WIDTH <= 850)
}
function threePanels() {
return (WIDTH > finderWidth+850)
}
function resize() {
WIDTH = Math.min(window.innerWidth, screen.width)
if (!singlePanel()) { //two or three panels
let x = (threePanels() || finderIsShown)? finderWidth : 0
setPosition(findFrm, x-finderWidth, finderWidth)
setPosition(readFrm, x, WIDTH-x)
readFrm.style.opacity = 1
readFrm.hidden = false
} else if (finderIsShown) { //findFrm is full width
setPosition(findFrm, 0, WIDTH)
readFrm.style.opacity = 0
setTimeout(() => {readFrm.hidden = true}, 800)
} else { //readFrm is full width
setPosition(findFrm, -finderWidth, finderWidth)
setPosition(readFrm, 0, WIDTH)
readFrm.hidden = false
setTimeout(() => {readFrm.style.opacity = 1}, 100)
}
lang.hidden = singlePanel() && finderIsShown
lang.style.left = readFrm.style.left
openM.hidden = threePanels()
if (finderIsShown)
openM.classList.add('upside')
else openM.classList.remove('upside')
if (readFrm.style.left.startsWith('0')) {
sizer.hidden = true
} else {
sizer.hidden = false
setPosition(sizer, finderWidth-15, 28)
}
}
function sourceChanged(e) {
try {
let p = finder.location.pathname
if (lastPath != p) {
lastPath = p; addListener(findFrm)
}
} catch (err) {
lastPath = null // cannot read location
}
console.log('* sourceChanged *', lastPath)
reportHash(e)
}
function initReader(e) { // Window.postMessage()
console.log('* initReader *', iqra.location.hash)
if (e.data !== "initialized") return
addListener(readFrm)
// if (singlePanel() && iqra.location.hash)
// hideFinder() else
showFinder()
hashModified()
iqra.vers1.textContent = TEST_VERSION
iqra.vers2.textContent = TEST_VERSION
}
console.log('* start *', location.hash)
// readFrm.style.display = 'none' //hide iqra frame
window.name = 'iqraTop'
window.onresize = resize
window.onhashchange = hashModified
openM.onclick = toggleFinder //showFinder
// readFrm.onload = initReader
findFrm.onload = sourceChanged
iqra.addEventListener('hashchange', reportHash)
var id //indicates a drag event is active
var x0 //clientX of the latest drag
var num //of drag events
function resizeStart(e) {
if (e.target !== sizer) return
let p = e.touches? e.touches[0] : e
x0 = Math.round(p.clientX)
id = setTimeout(resizeEnd, 1500) //global
num = 0
console.log(e.type, finderWidth, x0)
sizer.classList.add('sizing')
setPosition(sizer, finderWidth-60, 120)
ruler.classList.add('sizing')
}
function drag(e) {
// e.preventDefault()
if (!id) return
clearTimeout(id); num++
id = setTimeout(resizeEnd, 1000) //global
let p = e.touches? e.touches[0] : e
let x1 = Math.round(p.clientX)
let f0 = finderWidth
let fw = f0 + (x1 - x0); x0 = x1
let W = Math.min(window.innerWidth, screen.width)
finderWidth = Math.min(Math.max(fw, 350), W-350)
if (fw !== f0) setPosition(ruler, finderWidth-2)
//resize() no need to display each step
// console.log(e.type, fw)
}
function resizeEnd(e) {
// if (e) e.preventDefault()
if (!id) return
clearTimeout(id); id = undefined
setStorage('iqra', 'finderWidth', finderWidth)
console.log(e? e.type : 'cancel', finderWidth, num)
sizer.classList.remove('sizing')
ruler.classList.remove('sizing')
resize() //once at the end of resize
}
sizer.onmousedown = resizeStart
sizer.onmousemove = drag
sizer.onmouseup = resizeEnd
sizer.ontouchstart = resizeStart
sizer.ontouchmove = drag
sizer.ontouchend = resizeEnd
// resizable iframe has a bug
// new ResizeObserver(setWidth).observe(findFrm)
window.addEventListener("message", initReader)
window.onbeforeinstallprompt = (e) => {
iqra.beforeinstallCB(e)
console.log('beforeinstallprompt event')
}
</script>
</body>
</html>