-
Notifications
You must be signed in to change notification settings - Fork 3
/
mdict_browser.html
636 lines (585 loc) · 19.9 KB
/
mdict_browser.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
<!DOCTYPE html>
<!--
Copyright (c) 2018 by KnIfER
Released under the MIT license
based on: mdict-js
-->
<meta name="robots" content="noindex">
<html>
<head>
<meta name="description" content="MDict JS">
<script>
window.TextEncoder = window.TextDecoder = null;
</script>
<script src="MdbR/lib/encoding-indexes.js"></script>
<script src="MdbR/lib/encoding.js"></script>
<!--script src="require.js"></script-->
<!-- 破逼乎,关我提问,吃枣药丸></script-->
<!-- scrap bit-hoo,shut down my question,you go and frrrrrak your ceo's mother's daughter's son></script-->
<script src="MdbR/jquery-1.11.3.min.js"></script>
<script src="MdbR/listview/jquery.mousewheel.js"></script>
<script src="MdbR/listview/seekbar.js"></script>
<script src="MdbR/minilzo-decompress.js"></script>
<script src="MdbR/murmurhash3.js"></script>
<link rel="icon" href="MdbR/MdbR.png" type="image/x-icon" />
<link rel="shortcut icon" href="MdbR/MdbR.png" type="image/x-icon"/>
<link rel="stylesheet" type="text/css" href="MdbR/css/seekbar.css"/>
<style>
.cp:hover
{
background-color: #BBE8F2;
background-color:#397CCD;
}
html, body {
margin: 0;
padding: 0;
overflow: hidden;
width: 100%;
height: 100%;
}
#parentR {
position: relative;
height: 100%; /*NO!!!width: 100%;!!!*/
margin-left: 195px;
padding: 0;
}
.defP {
position:absolute;
top: 0px;
bottom: 0px;
margin-top:70px;
overflow:scroll;
background-color: #B3E5EE;
width: 100%; /*NO!!!height: 100%;!!!*/
}
.def {
position:absolute;
padding:4px 4px 100px 4px;
}
.navR {
margin: 0; padding: 0;
height: 70px;
width: 100%;
background-color: rgba(67, 163, 255, 0.65);
}
#fileBtn{
position: relative;
margin-left: 4px;
width: 25px;
height: 25px;
bottom: -37px;
border-radius: 30%;
color: white;
z-index: 2;
float: left;
vertical-align: bottom;
}
#fileName{
position: relative;
width: 1px;
bottom: -41px;
float:left;
white-space: nowrap;
color: white;
z-index: 1;
}
.cp2
{
top:0;
background-color:#397CCD;
width:50px;
margin:20px 25px 0 0px;
display: inline-block;
overflow-x:hidden;
padding:10px 0 0px 0;
vertical-align: top;
}
.cp2:hover
{
white-space: pre-wrap;
overflow: visible;
word-wrap: break-word;
z-index: 1;
margin-right:5px;
width:70px;
}
#dictsP{
white-space: nowrap;
position: absolute;
left:0;top:0;
margin-left: 30px;
margin-top:-15px;
overflow-y: hidden;
width:100%;
float: left;
vertical-align: top;
}
#ListView{
position: absolute; top: 0; left: 0;
width: 195px;
height: 100%;
box-sizing: border-box;
background: #191919;
white-space: nowrap;
overflow: hidden;
}
#lv {
position: absolute;
top:0;
right:20px;
float:left;
color: #dddddd;
overflow: hidden;
overflow-x:hidden;
white-space:nowrap;
padding: 0px;
padding-top:16px;
margin:0;
margin-left:5px;
margin-top: 10px;
}
p{
width:100%;
font-size: 16px;
position: relative;
top:0;
margin: 0 0 0 25px ;
padding:6px 0 6px 2px;
}
#seekbar_container {
position: absolute;
top: 0;
right: -3px;
height: 100%;
width: 30px;
float:right;
padding-left:0;
margin-top: 8px;
}
#drag_resizer{
position: absolute;
top:0;
right: 0px;
height: 100%;
width: 4px;
float:right;
padding:0;
cursor: ew-resize;
}
#wordP{
position: absolute;
top:0;
right:5px;
padding-left: 10px;
margin: 0 0 0 10px ;
height: 40px;
width: 100%;
overflow: hidden;
display: flex;
}
#word{
float: left;
margin: 4px 0 0 10px ;
height: 15px;
width: 100%;
overflow: hidden;
}
</style>
<script type="text/javascript">
/*
* jQuery.Drag-Resizable items via wuxinxi007 于 2011-5-14
* blog : http://wuxinxi007.cnblogs.com/
*/
$(function(){
//绑定需要拖拽改变大小的元素对象
bindResize(document.getElementById('drag_resizer'));
});
function bindResize(el){
console.log("mousedown: ",el);
var lvP = document.getElementById('ListView');
//初始化参数
var lvPs = lvP.style,
pRs = document.getElementById('parentR').style,
//鼠标的 X 和 Y 轴坐标
x = y = 0;
//邪恶的食指
$(el).mousedown(function(e){
console.log("mousedown");
//按下元素后,计算当前鼠标与对象计算后的坐标
x = e.clientX - lvP.offsetWidth;
//在支持 setCapture 做些东东
el.setCapture ? (
//捕捉焦点
el.setCapture(),
//设置事件
el.onmousemove = function(ev){
mouseMove(ev || event)
},
el.onmouseup = mouseUp
) : (
//绑定事件
$(document).bind("mousemove",mouseMove).bind("mouseup",mouseUp)
)
//防止默认事件发生
e.preventDefault()
});
//移动事件
function mouseMove(e){
//console.log("move");
//宇宙超级无敌运算中...
lvPs.width = e.clientX - x + 'px';
pRs.marginLeft = lvPs.width;
}
//停止事件
function mouseUp(){
//在支持 releaseCapture 做些东东
el.releaseCapture ? (
//释放焦点
el.releaseCapture(),
//移除事件
el.onmousemove = el.onmouseup = null
) : (
//卸载事件
$(document).unbind("mousemove", mouseMove).unbind("mouseup", mouseUp)
)
}
}
</script>
<script>
var
_cached_keys, // cache latest keys
_trail; // store latest visited record block & position when search for candidate keys
var lastDingX=0;
var pos = 0;
var lv = document.getElementById("lv");
var dictsP;
var seekBarmyCon = document.getElementById("seekbar_container");
var capacity = 30;
var listSize = 100;
var seekBarmy;
var lastTarget,lastSelection_;
var currentDict;var currentDicts=[];
var editText;
//bind mouse wheel
$(function() {
$('#lv').bind('mousewheel', function(event) {
event.preventDefault();
pos+=event.deltaY*-1;
//console.log("pos: "+pos);
seekBarmy.setValue(listSize-pos);
rePopulate();
});
});
//counterfeiting a listview
function rePopulate(){//TODO: optimise
//计算一屏能放下几行.对于不同缩放级别,误差在0-8之间,可以接受.
//哈哈我真厉害
var line_height=0;
var tmp = $("p").css("font-size");
if(tmp.indexOf("px")!=-1)
line_height = parseFloat(tmp.substring(0,tmp.length-2));
tmp = $("p").css("padding-top");
if(tmp.indexOf("px")!=-1)
line_height += parseFloat(tmp.substring(0,tmp.length-2));
capacity = Math.floor($(window).innerHeight()/line_height);
//console.log("line_height: "+line_height);
//console.log("capacity: "+capacity);
var lastSelection=-1;
if(lastTarget) lastSelection = parseInt(lastTarget.id);
else if(lastSelection_!=-1) lastSelection=lastSelection_;
if(lv.hasChildNodes()) {
var childs = lv.childNodes,
ln = childs.length;
for (var i = 0; i < ln; i++) {
lv.removeChild(childs[0]);
}
}
if(pos<0) pos=0;
if(pos>=listSize) pos = listSize-1;
var couterfeitCounter = pos+capacity;
//if(couterfeitCounter>=Number.MAX_SAFE_INTEGER){
// console.log("Integer Overflow Error! max is "+Number.MAX_SAFE_INTEGER);
// console.log("Integer Overflow Error! now has "+couterfeitCounter);
// console.log("Integer Overflow Error! delta is"+(couterfeitCounter-Number.MAX_SAFE_INTEGER));
// console.log("Integer Overflow Error! delta is"+(couterfeitCounter+100));
// couterfeitCounter = Number.MAX_SAFE_INTEGER;
//}
//if(couterfeitCounter>listSize) couterfeitCounter = listSize;
if(pos+capacity>listSize) capacity = listSize-pos;
if(currentDict)currentDict.populateEntrys(pos,capacity);
else{
for (var i=0; i<capacity; i++){
var item = document.createElement('p');
item.id = pos+i;
item.className="cp";
item.onclick = p;
item.innerText = "N/A " + (pos+i);
//lv.append(item);
if(lastSelection==pos+i){
lastTarget = item;
item.style.setProperty("background-color","#4296FA");
}
lv.appendChild(item);
}
lastSelection_=-1;
}
}
function p(e){
//console.log("p: "+e.target.id+typeof(e.target.id));
//console.log(e.target.style);
if(lastTarget)
//lastTarget.style.setProperty("background-color", "transparent");
lastTarget.removeAttribute("style");//有点喜欢上写页面了呢
lastTarget=e.target;
lastTarget.style.setProperty("background-color","#4296FA");
if(currentDict)
currentDict.renderDef(parseInt(e.target.id));
//e.target.background("#0000ff");
}
function p2(e){
if(currentDicts){
_cached_keys=_trail=undefined;
currentDicts[lastDingX].value().OldPos = pos;
currentDicts[lastDingX].value().OldKey = $("#word").val();
if(lastTarget)currentDicts[lastDingX].value().OldSel = parseInt(lastTarget.id);
if(e.target)
lastDingX = parseInt(e.target.id);
else
lastDingX = parseInt(e.id);
currentDict = currentDicts[lastDingX].value();
if(currentDict.OldKey){
$("#word").val(currentDict.OldKey);
} else $("#word").val("");
if(currentDict.OldSel){
lastSelection_ = currentDict.OldSel;
currentDict.renderDef(currentDict.OldSel)
} else $(".def").html("");
if(currentDict.OldPos)
pos=currentDict.OldPos;
else pos=0;
setListSize(currentDict._num_entries);
console.log("currdict: ",currentDict.filename);
//console.log("currdicts: ",currentDicts);
$("#fileName").empty().append(currentDict.filename);
}
try{
e.stopPropagation();
}catch(e){}
//e.target.background("#0000ff");
}
function Initialize() {
lv = document.getElementById("lv");
dictsP = document.getElementById("dictsP");
seekBarmyCon = document.getElementById("seekbar_container");
rePopulate();
seekBarmy = new Seekbar.Seekbar({
renderTo: "#seekbar_container",
minValue: 0, maxValue: 255,
valueListener: function (value) {
this.value = Math.round(value);
updateProgress();
//console.log("valueListener: ",value);
},
barSize:10,
needleSize:0.3,
thumbColor: '#00cccccc',
negativeColor: '#000',
positiveColor: '#000',
value: 0
});
seekBarmy.setValue(seekBarmy.maxValue)
setListSize(667);//900719925474101000
editText = document.getElementById("word");
if(document.all){
editText.onpropertychange=loookup;
}
else{
editText.oninput=loookup;
}
document.onkeydown = function(e) {
var keyCode = e.keyCode || e.which || e.charCode;
var ctrlKey = e.ctrlKey || e.metaKey;
//console.log("word isFocused:",$("#word").is(':focus'));
if($(':focus').length==0){
if(!ctrlKey &&((keyCode<=90&&keyCode>=65))){//abc keyboard
$("#word").val("");
$("#word").focus();
return true;
}
//if(keyCode==32){//space
// if(lastTarget){
// pos=parseInt(lastTarget.id);
// rePopulate();
// }
// return true;
//}
if(keyCode==8 ||keyCode==37||keyCode==39 ) {//left right
$("#word").focus();
return true;
}
}
if($(':focus').length==0 || $("#word").is(':focus'))
if(lastTarget){//up down
var re=false;
if(keyCode==38){
lastSelection_=parseInt(lastTarget.id)-1;
if(lastSelection_<0)
lastSelection_=0;
lastTarget=null;
re=true;
}
if(keyCode==40){
lastSelection_=parseInt(lastTarget.id)+1;
if(lastSelection_>=listSize)
lastSelection_=listSize-1;
lastTarget=null;
re=true;
}
if(re){
e.preventDefault();
if(lastSelection_<pos) pos=lastSelection_;
else{
var ca = capacity - 6;
if(lastSelection_>pos+ca)
pos=lastSelection_-ca;
}
if(currentDict){
//console.log(""+lastSelection_);
currentDict.renderDef(lastSelection_);
}
rePopulate();
return;
}
}else{
lastTarget=document.getElementById("0");
rePopulate();
}
return true;
}
$(document.body).bind({
paste: function(e) {
if($(':focus').length==0){/*defaulf paste receptor*/
var clipboardData = window.clipboardData; /*ie*/
if (!clipboardData) { /*Cr*/
clipboardData = e.originalEvent.clipboardData
}
var data = clipboardData.getData('Text');
//console.log("bindp: ",data);
$("#word").val(data);
loookup();
}
}
});
}
function setListSize(size){
listSize=size;
seekBarmy.maxValue=size;
seekBarmy.setValue(size);
lastTarget= undefined;
seekBarmy.refresh();
rePopulate();
}
function setListPos(p){
console.log("list pos is: ",listSize-p);
seekBarmy.setValue(listSize-p);
pos=p;
//seekBarmy.render();
rePopulate();
}
function setCurrMdict(mdict){
//
}
//scroll bar scrolled
function updateProgress() {
//console.log("updateProgress: "+seekBarmy.value);
if(!seekBarmy) return;
pos = listSize - seekBarmy.value.toString(10);
rePopulate();
// $("#color-code").html(red);
}
function loookup(){
var word = editText.value;
if(word.trim()==="")
return;
//console.log(word);
if(currentDict){
currentDict(word).then(function (res){//[idx,isPerfect]) {
//console.log("\n\nlookUp: ",idx);
if(res[1]){
//coin history!
lastTarget = document.createElement('p');
lastTarget.id = res[0];
}
setListPos(res[0]);
if(res[1]){
//console.log("isPerfectisPerfectisPerfect");
currentDict.renderDef(res[0]);
}
});
}
}
updateProgress();
//$(window).on('resize', 0, function() {
$(window).resize(function() {
if(seekBarmy){
if(seekBarmyCon.hasChildNodes()) {
//var childs = seekBarmyCon.childNodes,
// ln = childs.length;
//console.log("del: ",ln);
//for (var i = 0; i < ln; i++) {
// seekBarmyCon.removeChild(childs[0]);
//}
}
seekBarmy.refresh();
}
rePopulate();
// alert($(window).width()); //浏览器时下窗口可视区域宽度
// alert($(window).height()); //浏览器时下窗口可视区域高度
// alert($(document).height()); //浏览器时下窗口文档的高度
// alert($(document.body).height());//浏览器时下窗口文档body的高度
// alert($(document.body).outerHeight(true));//浏览器时下窗口文档body的总高度 包括border padding margin
//
// alert($(document).width());//浏览器时下窗口文档对于象宽度
// alert($(document.body).width());//浏览器时下窗口文档body的高度
// alert($(document.body).outerWidth(true));//浏览器时下窗口文档body的总宽度 包括border padding margin
////////////console.log("line: "+$(document).height());
////////////console.log("attr: "+document.getElementById("1").style.fontSize);
////////////console.log("attr2: "+document.getElementsByTagName("p")[1].getAttribute("font-size"));
////////////console.log("attr3: "+document.getElementsByTagName("p")[1].fontSize);
//////console.log("attr4: "+$("p").css("margin"));//16 0 16 15 px
//////console.log("attr4: "+$("p").css("font-size"));//16 0 16 15 px
////////console.log("attr5: "+$("html").css("height"));
//////console.log("attr6: "+$(window).outerHeight());
});
</script>
<link rel="stylesheet" type="text/css" href="">
<meta charset="utf-8">
<title>MDict Browser</title>
</head>
<!------------------------------------------------------------------>
<body id="body_" onload="Initialize()">
<div id="parentR">
<div class="navR">
<input id="fileBtn" type='button' value='+' OnClick='javascript:$("#dictfile").click();'/>
<div id="fileName" >...</div>
<div id="dictsP"></div>
<input id='dictfile' type='file' style="visibility:hidden" multiple= />
</div>
<div class="defP" id="defP">
<div class="def" id="def"></div>
</div>
</div>
<div id="ListView">
<p id="lv"> </p>
<p id="seekbar_container" ></p>
<p id="drag_resizer" ></p>
<div id="wordP">
<input id="word" type="text" value="" >
</div>
</div>
<!--div class="def">
</div-->
<script type="text/javascript" src="MdbR/conf.js"></script>
<script src="MdbR/require.js" data-main="MdbR/mdict"></script>
</body>
</html>