-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverbatim.js
394 lines (361 loc) · 11.1 KB
/
verbatim.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
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
const Jax = function() {
const EOF = '\u000A';
/**
* Get URL to a callback function.
*
* @param {String} url
* @param {function} callback
* @returns
*/
function load(url, callback, type='text') {
let timeStart = new Date();
let xhr = new XMLHttpRequest();
xhr.responseType = type;
xhr.onprogress = function() {
// if sended by chunks
};
xhr.onload = function() {
var status = xhr.status;
if (status !== 200) {
// error ? do what ?
callback(xhr.response);
reject(Error(status + " " + url));
}
callback(xhr.response);
//
};
// loadend (load|error|abort)
xhr.onerror = function() {
console.log('[' + xhr.status + '] ' + url);
};
xhr.open('GET', url);
xhr.send();
return xhr;
}
return {
load: load,
}
}();
/*
// fast nav between texts ?
(function() {
const nav = document.getElementById('nav');
const doc = document.getElementById('doc');
Jax.load('html/tlg0057.tlg100.1st1K-grc1.html', function(html) {
doc.innerHTML = html;
});
Jax.load('nav.html', function(html) {
nav.innerHTML = html;
let els = nav.querySelectorAll('a');
for (let i = 0, len = els.length; i < len; ++i) {
let a = els[i];
a.onclick = (e) => {
e.preventDefault();
if (window.lastA) window.lastA.classList.remove('selected');
a.classList.add('selected');
window.lastA = a;
Jax.load(a.href, function(html) {
doc.innerHTML = html;
});
}
}
})
}());
*/
const Galenus = function() {
// https://www.biusante.parisdescartes.fr/iiif/2/bibnum:00039x04:0038/full/max/0/default.jpg
function wear(css, dat) {
if (!dat) return;
let els = document.querySelectorAll(css);
for (let i = 0; i < els.length; ++i) {
var span = document.createElement("span");
span.className = "pageview";
let p = els[i].dataset.n;
if (!p) p = els[i].dataset.page;
let url;
// has been seen, but no more used
// const pos = p.indexOf(".");
let pno;
let text = '[';
if (els[i].classList.contains('page1') || els[i].classList.contains('pbde')) {
text += '…';
}
let pdiff = dat['pdiff'];
if (dat['pholes']) {
for (const prop in dat['pholes']) {
if (p >= prop) {
pdiff = dat['pholes'][prop];
} else {
break;
}
}
}
text += dat['vol'] + '.' + p + ' ' + dat['abbr'];
// pad page number for biusante
pno = pad(parseInt(p) + parseInt(pdiff), 4);
url = dat['url'].replace('%%', pno);
text += ']';
span.innerText = text;
// els[i].parentNode.insertBefore(span, els[i].nextSibling);
els[i].appendChild(span);
span.onclick = function() {
if (pageViewer.spanLast) pageViewer.spanLast.classList.remove("selected");
this.classList.add("selected");
pageViewer.spanLast = this;
image.src = url;
let title = '';
if (dat.title) title = text + ' source : ' + dat.title.replace('%%', pno);
image.alt = title;
const header = document.getElementById('image_header');
if (header) header.innerHTML = title;
pageViewer.update();
pageViewer.resize();
}
if (first) {
span.click();
first = false;
}
}
}
function pad(num, width) {
var s = "000000000" + num;
return s.substring(s.length - width);
}
return {
wear: wear,
}
}();
const Verbatim = function()
{
const image = document.getElementById('image');
function pageUrl(dat, n)
{
let pdiff = dat['pdiff'];
if (dat['pholes']) {
for (const prop in dat['pholes']) {
if (n >= prop) {
pdiff = dat['pholes'][prop];
} else {
break;
}
}
}
// pad page number for biusante
pno = pad(parseInt(n) + parseInt(pdiff), 4);
url = dat['url'].replace('%%', pno);
return url;
}
function pad(num, width) {
var s = "000000000" + num;
return s.substring(s.length - width);
}
function pageClick()
{
let page = this.dataset.page;
const parts = page.split('.');
let n = null;
let vol = null;
// no volume, kühn centric,
if (parts.length == 1) {
p = parts[0];
return;
}
else if (parts.length == 2) {
vol = '' + parts[0];
n = parts[1];
}
else {
// error ?
return;
}
if (!vols) {
console.log("No volume info");
return;
}
// get url for volume
const dat = vols['pb'][vol];
const url = pageUrl(dat, n);
image.src = url;
}
/**
* light fast event
*/
function pageWear(css)
{
if (!image) return;
let els = document.querySelectorAll(css);
for (let i = 0; i < els.length; ++i) {
let el = els[i];
el.onclick = pageClick;
}
}
return {
pageWear: pageWear,
}
}();
(function()
{
Verbatim.pageWear('.pb');
}());
/**
* Do something with bâle chartier data
*/
const image = document.getElementById('image');
const div = document.getElementById('viewcont');
if (window.Viewer) {
// viewer override of resize
Viewer.prototype.resize = function() {
var _this3 = this;
if (!this.isShown || this.hiding) {
return;
}
if (this.fulled) {
this.close();
this.initBody();
this.open();
}
this.initContainer();
this.initViewer();
this.renderViewer();
this.renderList();
if (this.viewed) {
// do not resize image
/*
this.initImage(function() {
_this3.renderImage();
});
_this3.options.viewed();
*/
}
if (this.played) {
if (this.options.fullscreen && this.fulled && !(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement)) {
this.stop();
return;
}
forEach(this.player.getElementsByTagName('img'), function(image) {
addListener(image, EVENT_LOAD, _this3.loadImage.bind(_this3), {
once: true
});
dispatchEvent(image, EVENT_LOAD);
});
}
};
/*
var onViewed = function onViewed() {
var imageData = _this2.imageData;
var render = Array.isArray(options.title) ? options.title[1] : options.title;
// EDIT 2022-04, keep html in titles
title.innerHTML = isFunction(render) ? render.call(_this2, image, imageData) : "".concat(alt, " (").concat(imageData.naturalWidth, " \xD7 ").concat(imageData.naturalHeight, ")");
};
*/
Viewer.prototype.wheel = function(event) {
var _this4 = this;
if (!this.viewed) {
return;
}
event.preventDefault(); // Limit wheel speed to prevent zoom too fast
if (this.wheeling) {
return;
}
this.wheeling = true;
setTimeout(function() {
_this4.wheeling = false;
}, 50);
var ratio = Number(this.options.zoomRatio) || 0.1;
var delta = 1;
if (event.deltaY) {
delta = event.deltaY;
} else if (event.wheelDelta) {
delta = -event.wheelDelta;
} else if (event.detail) {
delta = event.detail;
}
this.move(0, -delta);
};
var pageViewer = new Viewer(div, {
title: function(image) {
// title sould not be html
return image.alt;
},
title: false,
transition: false,
inline: true,
navbar: 0,
zIndex: 4,
// minWidth: '100%',
toolbar: {
width: function() {
let cwidth = div.offsetWidth;
let iwidth = pageViewer.imageData.naturalWidth;
let zoom = cwidth / iwidth;
pageViewer.zoomTo(zoom);
pageViewer.moveTo(0, pageViewer.imageData.y);
},
zoomIn: true,
zoomOut: true,
oneToOne: true,
reset: true,
},
viewed() {
// default zoom on load, image width
let cwidth = div.offsetWidth;
let iwidth = pageViewer.imageData.naturalWidth;
let zoom = cwidth / iwidth;
pageViewer.zoomTo(zoom);
pageViewer.moveTo(0, 0);
},
});
}
(function() {
let first = true;
// const ed1 set, use data
if (typeof imgkuhn !== 'undefined') Galenus.wear(".pb", imgkuhn);
if (typeof imgbale !== 'undefined') Galenus.wear(".ed1page", imgbale);
if (typeof imgchartier !== 'undefined') Galenus.wear(".ed2page", imgchartier);
})();
(function() {
const id = 'selnav';
const select = document.getElementById(id);
if (!select) return;
function show(value) {
if (!select.last) select.last = document.getElementById('TitLa');
const show = document.getElementById(value);
if (!show) return;
localStorage.setItem(id, value);
select.last.style.display = 'none';
select.last = show;
show.style.display = 'block';
}
// on load last value
window.addEventListener("load", function(e) {
const value = localStorage.getItem(id);
if (value) {
select.value = value;
show(value);
}
})
select.addEventListener("change", function(e) {
const value = select.value;
show(value);
});
}());
(function() {
const navs = document.getElementById('navs');
if (!navs) return;
navs.addEventListener('click', function(e) {
let a = selfOrAncestor(e.target, 'a');
if (!a) return;
if (document.lasta) document.lasta.classList.remove('selected');
document.lasta = a;
a.classList.add('selected');
});
function selfOrAncestor(el, name) {
while (el.tagName.toLowerCase() != name) {
el = el.parentNode;
if (!el) return false;
let tag = el.tagName.toLowerCase();
if (tag == 'div' || tag == 'nav' || tag == 'body') return false;
}
return el;
}
}());