-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathframes.html
More file actions
183 lines (179 loc) · 5.22 KB
/
Copy pathframes.html
File metadata and controls
183 lines (179 loc) · 5.22 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
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
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="cyan" />
<meta name="author" content="M A Eyler, Istanbul, 2020" />
<meta name="description" content="Reader for the Quran" />
<link rel="manifest" href="manifest.json">
<link rel="icon" href="image/icon.png">
<title>Iqra V4</title>
<style>
body {
margin: 0;
background-color: #8ff;
}
iframe {
display: inline-block;
position: absolute;
box-sizing: border-box;
border: none;
height: 100%;
}
button {
position: fixed;
top: 8px; right: 0;
background-color: pink;
}
</style>
</head>
<body>
<iframe id=findFrm src='start.html' name=finder></iframe>
<iframe id=readFrm src='reader.html' name=iqra></iframe>
<button id=closeM title='Arama panelini kapat'>x</button>
<button id=openM hidden title='Arama paneline dön'>A</button>
<script src="code/common.js"></script>
<script>
function addListener(frm) {
frm.contentWindow.addEventListener('hashchange', reportHash)
console.log('* addListener *', frm.name)
}
function reportHash(e) { //hashchange in one of the panes
let s = '[Dış kaynak]', h = ''
if (e.target.name == 'iqra') {
if (skipEvent) {
skipEvent = false; return
}
if (readFrm.style.display == 'none') hideFinder()
s = e.target.document.title
h = e.target.location.hash
} else { // finder
try {
let p = finder.location.pathname //may fail
isStartPage = p.includes("start.html")
} catch (e) {
isStartPage = false //external page
}
if (lastPath != null && e.target.document) {
s = e.target.document.title
h = e.target.location.hash
}
if (findFrm.style.display == 'none') 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
} else switch (h.substring(0, 2)) { //new address entered
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(FINDER+'#'+h, 'finder')
break
default:
console.log('unknown hash entered', h)
}
}
function startPane() {
if (isStartPage) hideFinder()
else {
window.open('start.html', 'finder')
isStartPage = true
}
}
function hideFinder() {
closeM.hidden=true; openM.hidden=false
resize()
}
function showFinder() {
closeM.hidden=false; openM.hidden=true
// if (!findFrm.src) findFrm.src = 'mujam.html'
resize()
}
var WIDTH = 500 //can be modified in dev tools
function resize() {
const HIDE = 'none', SHOW = ''
let W = Math.min(window.innerWidth, screen.width)
if (closeM.hidden) { //hideFinder
setStyle(findFrm.style, HIDE)
let x2 = 0, w2 = W
if (W>600 && W<=850) { //single column
x2 = Math.trunc((W-WIDTH)/2); w2 = WIDTH
}
setStyle(readFrm.style, SHOW, x2, w2)
} else { //showFinder
if (W <= 850) { //single column
setStyle(findFrm.style, SHOW, 0, W)
setStyle(readFrm.style, HIDE)
closeM.style.right = ''
} else { //two columns
findFrm.style.borderRight = '1px solid cyan'
let w2 = WIDTH, x2 = W - w2
setStyle(findFrm.style, SHOW, 0, x2)
setStyle(readFrm.style, SHOW, x2, w2)
closeM.style.right = w2+'px'
}
}
function setStyle(s, d, x, w) {
s.display = d; if (d == HIDE) return
s.left = (x == 0)? 0 : x+'px'
s.width = (w == W)? '100%' : w+'px'
}
}
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() {
console.log('* initReader *', initialHash)
if (!iqra.initialized) { //good idea, poor practice
setTimeout(initReader, 500); return
}
resize(); addListener(readFrm); //hashModified()
if (!initialHash) return
window.location.hash = initialHash
initialHash = null
}
var lastPath // finder location
var isStartPage = true // is shown?
var hashInProgress = false
var initialHash = decodedHash()
var skipEvent = !initialHash
console.log('* start *', initialHash, location.hash)
readFrm.style.display = 'none' //hide iqra frame
window.name = 'iqraTop'
window.onresize = resize
window.onhashchange = hashModified
closeM.onclick = startPane //hideFinder
openM.onclick = showFinder
readFrm.onload = initReader
findFrm.onload = sourceChanged
iqra.addEventListener('hashchange', reportHash)
window.onerror = console.log
window.onbeforeinstallprompt = (e) => {
iqra.beforeinstallCB(e)
console.log('beforeinstallprompt event')
}
</script>
</body>
</html>