Newer
Older
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
<!DOCTYPE html><head><meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Universal Dependencies on 論語</title>
<script src="conllusvgview.js"></script>
<script src="conllusvgload.js"></script>
<script>
var Lunyu=new Object();
Lunyu.url="/gitlab/api/v4/projects/Kanbun%2Fud-kanbun/repository/";
Lunyu.init=function(){
var t=document.getElementById("top").cloneNode(true);
t.style.position="static";
t.style.visibility="hidden";
document.body.appendChild(t);
Lunyu.svg=new Array();
Lunyu.pre=new Array();
Lunyu.timer=setTimeout("clearTimeout(Lunyu.timer);Lunyu.checkview()",200);
Lunyu.volchange();
}
Lunyu.checkview=function(){
var t,r,b,i,x;
Lunyu.timer=setTimeout("clearTimeout(Lunyu.timer);Lunyu.checkview()",200);
if(Lunyu.curr==null)
return;
if(Lunyu.svg[Lunyu.curr]==null||Lunyu.pre[Lunyu.curr]==null){
Lunyu.buildup(Lunyu.curr);
Lunyu.lastTop=null;
return;
}
if(Lunyu.svg[Lunyu.curr].style.position=="absolute"){
Lunyu.svg[Lunyu.curr].style.position="static";
Lunyu.svg[Lunyu.curr].style.visibility="visible";
}
conllusvg.rewrite("pre"+Lunyu.curr);
r=Lunyu.svg[Lunyu.curr].getBoundingClientRect();
t=r.top;
b=r.bottom;
r=document.getElementById("top").getBoundingClientRect().bottom;
x=Lunyu.curr;
if(t-r>20){
while(t-r>0){
i=Lunyu.svg[Lunyu.curr-1];
if(i==null)
break;
if(i.style.position=="absolute")
break;
Lunyu.curr--;
if(Lunyu.curr==0)
break;
t=i.getBoundingClientRect().top;
}
}
else if(b<r){
while(b<r){
i=Lunyu.svg[Lunyu.curr+1];
if(i==null)
break;
if(i.style.position=="absolute")
break;
Lunyu.curr++;
if(Lunyu.curr==Lunyu.currmax)
break;
b=i.getBoundingClientRect().bottom;
}
}
Lunyu.lastTop=Lunyu.svg[Lunyu.curr].getBoundingClientRect().top;
if(Lunyu.curr!=x)
document.getElementById("count").value=Lunyu.curr;
for(i=Lunyu.curr+1;i<=Lunyu.currmax;i++){
if(Lunyu.svg[i]==null||Lunyu.pre[i]==null){
Lunyu.buildup(i);
break;
}
if(Lunyu.svg[i].style.position=="absolute"){
Lunyu.svg[i].style.position="static";
Lunyu.svg[i].style.visibility="visible";
}
conllusvg.rewrite("pre"+i);
r=Lunyu.svg[i].getBoundingClientRect();
if(r.top-window.innerHeight-1000>0)
break;
}
for(i=Lunyu.curr-1;i>=0;i--){
if(Lunyu.svg[i]==null||Lunyu.pre[i]==null){
Lunyu.buildup(i);
break;
}
if(Lunyu.svg[i].style.position=="absolute"){
if(Lunyu.pre[i].textContent>""){
Lunyu.svg[i].style.position="static";
Lunyu.svg[i].style.visibility="visible";
}
else
break;
}
conllusvg.rewrite("pre"+i);
r=Lunyu.svg[Lunyu.curr].getBoundingClientRect().top;
if(Math.abs(r-Lunyu.lastTop)>5){
if(document.scrollingElement==null)
document.documentElement.scrollTop+=r-Lunyu.lastTop;
else
document.scrollingElement.scrollTop+=r-Lunyu.lastTop;
Lunyu.lastTop=r;
}
r=Lunyu.svg[i].getBoundingClientRect();
if(parseInt(r.bottom,10)<-300)
break;
}
}
Lunyu.buildup=function(x){
var t,i;
if(Lunyu.svg[x]==null){
t=document.createElementNS("http://www.w3.org/2000/svg","svg");
for(i=parseInt(x,10)+1;i<=Lunyu.currmax;i++){
if(Lunyu.svg[i]!=null)
break;
}
t.style.position="absolute";
t.style.visibility="hidden";
if(i>Lunyu.currmax)
document.body.appendChild(t);
else
document.body.insertBefore(t,Lunyu.svg[i]);
Lunyu.svg[x]=t;
t.addEventListener("mousedown",Lunyu.onmousedown);
t.addEventListener("touchstart",Lunyu.onmousedown);
}
if(Lunyu.pre[x]==null){
t=document.createElement("pre");
t.style.display="none";
t.setAttribute("id","pre"+x);
document.body.appendChild(t);
Lunyu.pre[x]=t;
if(conllusvg.main["pre"+x]==null)
conllusvg.view(Lunyu.svg[x],"pre"+x);
i=Lunyu.volpath+"/"+("000"+x).slice(-3)+".txt";
conllusvg.loadRemote("pre"+x,Lunyu.url+"files/"+encodeURIComponent(i)+"/raw?ref=master");
}
}
Lunyu.volchange=function(){
var s,x;
Lunyu.clearSVG();
for(s in Lunyu.pre){
if(Lunyu.pre[s]!=null){
document.body.removeChild(Lunyu.pre[s]);
}
Lunyu.pre[s]=null;
}
s=document.getElementById("vol");
Lunyu.volpath=s.options[s.selectedIndex].value;
if(Lunyu.tail==null)
Lunyu.tail=new Array();
if(Lunyu.tail[Lunyu.volpath]==null)
Lunyu.gettree();
else
Lunyu.writeSVG();
}
Lunyu.gettree=function(){
var p;
if(Lunyu.request==null){
Lunyu.request=new XMLHttpRequest();
Lunyu.request.onload=Lunyu.ongettree;
}
if(Lunyu.tail[Lunyu.volpath]==null)
p=1;
else
p=Math.floor(parseInt(Lunyu.tail[Lunyu.volpath],10)/100)+2;
Lunyu.request.open("GET",Lunyu.url+"tree?per_page=100&path="+Lunyu.volpath+"&page="+p);
Lunyu.request.send();
}
Lunyu.ongettree=function(e){
var i,s;
if(Lunyu.request.status==200){
s=Lunyu.request.responseText;
i=s.lastIndexOf('.txt"');
if(i<0)
Lunyu.writeSVG();
else{
Lunyu.tail[Lunyu.volpath]=s.substring(i-3,i);
Lunyu.gettree();
}
}
}
Lunyu.writeSVG=function(){
var c=document.getElementById("count");
Lunyu.clearSVG();
Lunyu.currmax=parseInt(Lunyu.tail[Lunyu.volpath],10);
Lunyu.curr=parseInt(c.value,10);
if(Lunyu.curr<0)
Lunyu.curr=0;
if(Lunyu.curr>Lunyu.currmax)
Lunyu.curr=Lunyu.currmax;
c.value=Lunyu.curr;
Lunyu.lastTop=null;
}
Lunyu.clearSVG=function(){
var x;
Lunyu.curr=Lunyu.lastTop=null;
if(Lunyu.svg!=null){
for(x in Lunyu.svg){
if(Lunyu.svg[x]!=null){
Lunyu.svg[x].style.position="absolute";
Lunyu.svg[x].style.visibility="hidden";
}
}
}
if(document.scrollingElement==null)
document.documentElement.scrollTop=0;
else
document.scrollingElement.scrollTop=0;
}
Lunyu.onmousedown=function(e){
var x,y;
if(Lunyu.lastX==null){
Lunyu.lastX=e.clientX;
Lunyu.lastY=e.clientY;
return;
}
x=e.clientX-Lunyu.lastX;
y=e.clientY-Lunyu.lastY;
if(x*x+y*y>9){
Lunyu.lastX=e.clientX;
Lunyu.lastY=e.clientY;
return;
}
Lunyu.lastX=null;
x=e.currentTarget;
for(y in Lunyu.svg){
if(Lunyu.svg[y]==x){
x=Lunyu.volpath+"/"+("000"+y).slice(-3)+".txt";
window.open("editor-kanbun.html#"+Lunyu.url+"files/"+encodeURIComponent(x)+"/raw?ref=master");
break;
}
}
}
Lunyu.reload=function(){
var i,r;
for(i=Lunyu.curr;i<=Lunyu.currmax;i++){
if(Lunyu.svg[i]==null||Lunyu.pre[i]==null)
return;
r=Lunyu.svg[i].getBoundingClientRect();
if(r.top>window.innerHeight||r.bottom<0)
return;
r=Lunyu.volpath+"/"+("000"+i).slice(-3)+".txt";
conllusvg.loadRemote("pre"+i,Lunyu.url+"files/"+encodeURIComponent(r)+"/raw?ref=master");
}
}
Lunyu.gitlab=function(){
var r=Lunyu.volpath+"/"+("000"+Lunyu.curr).slice(-3)+".txt";
window.open("/gitlab/Kanbun/ud-kanbun/blob/master/"+r);
}
</script>
<body onload="Lunyu.init()">
<div id="top" style="position:fixed; top:0px; left:0px; padding:10px; width:100%; background:white">
<font size="+3"><b>論語</b></font>
<select id="vol" onchange="Lunyu.volchange()">
<option value="kanripo/kR1h0004/001">學而篇第一</option>
<option value="kanripo/kR1h0004/002">為政篇第二</option>
<option value="kanripo/kR1h0004/003">八佾篇第三</option>
<option value="kanripo/kR1h0004/004">里仁篇第四</option>
<option value="kanripo/kR1h0004/005">公冶長篇第五</option>
<option value="kanripo/kR1h0004/006">雍也篇第六</option>
<option value="kanripo/kR1h0004/007">述而篇第七</option>
<option value="kanripo/kR1h0004/008">泰伯篇第八</option>
<option value="kanripo/kR1h0004/009">子罕篇第九</option>
<option value="kanripo/kR1h0004/010">鄉黨篇第十</option>
<option value="kanripo/kR1h0004/011">先進篇第十一</option>
<option value="kanripo/kR1h0004/012">顏淵篇第十二</option>
<option value="kanripo/kR1h0004/013">子路篇第十三</option>
<option value="kanripo/kR1h0004/014">憲問篇第十四</option>
<option value="kanripo/kR1h0004/015">衛靈公篇第十五</option>
<option value="kanripo/kR1h0004/016">季氏篇第十六</option>
<option value="kanripo/kR1h0004/017">陽貨篇第十七</option>
<option value="kanripo/kR1h0004/018">微子篇第十八</option>
<option value="kanripo/kR1h0004/019">子張篇第十九</option>
<option value="kanripo/kR1h0004/020">堯曰篇第二十</option>
</select>
<input type="text" id="count" size=3 value=0 style="text-align:right" onchange="Lunyu.writeSVG()" />
<input type="button" value="GitLab" onclick="Lunyu.gitlab()" />
<input type="button" value="Reload" onclick="Lunyu.reload()" />
</div>
</body>