1
|
|
|
/** |
2
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
3
|
|
|
* |
4
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
5
|
|
|
* |
6
|
|
|
* @license GNU General Public License version 3 or later. |
7
|
|
|
* For the full copyright and license information, please read the |
8
|
|
|
* LICENSE.txt file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* This is necessary to support the scrolling of the element into the viewport |
13
|
|
|
* in case of text hover on the map. |
14
|
|
|
* |
15
|
|
|
* @param elem |
16
|
|
|
* @param speed |
17
|
|
|
* @returns {jQuery} |
18
|
|
|
*/ |
19
|
|
|
jQuery.fn.scrollTo = function(elem, speed) { |
20
|
|
|
var manualOffsetTop = $(elem).parent().height() / 2; |
21
|
|
|
$(this).animate({ |
22
|
|
|
scrollTop: $(this).scrollTop() - $(this).offset().top + $(elem).offset().top - manualOffsetTop |
23
|
|
|
}, speed == undefined ? 1000 : speed); |
24
|
|
|
return this; |
25
|
|
|
}; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Encapsulates especially the fulltext behavior |
29
|
|
|
* @constructor |
30
|
|
|
* @param {ol.Map} map |
31
|
|
|
* @param {Object} image |
32
|
|
|
* @param {string} fulltextUrl |
33
|
|
|
*/ |
34
|
|
|
var dlfViewerFullTextControl = function(map, image, fulltextUrl) { |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @private |
38
|
|
|
* @type {ol.Map} |
39
|
|
|
*/ |
40
|
|
|
this.map = map; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @type {Object} |
44
|
|
|
* @private |
45
|
|
|
*/ |
46
|
|
|
this.image = image; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @type {string} |
50
|
|
|
* @private |
51
|
|
|
*/ |
52
|
|
|
this.url = fulltextUrl; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @type {Object} |
56
|
|
|
* @private |
57
|
|
|
*/ |
58
|
|
|
this.dic = $('#tx-dlf-tools-fulltext').length > 0 && $('#tx-dlf-tools-fulltext').attr('data-dic') ? |
59
|
|
|
dlfUtils.parseDataDic($('#tx-dlf-tools-fulltext')) : |
|
|
|
|
60
|
|
|
{'fulltext-on':'Activate Fulltext','fulltext-off':'Dectivate Fulltext'}; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @type {ol.Feature|undefined} |
64
|
|
|
* @private |
65
|
|
|
*/ |
66
|
|
|
this.fulltextData_ = undefined; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @type {Object} |
70
|
|
|
* @private |
71
|
|
|
*/ |
72
|
|
|
this.layers_ = { |
73
|
|
|
textblock: new ol.layer.Vector({ |
|
|
|
|
74
|
|
|
'source': new ol.source.Vector(), |
75
|
|
|
'style': dlfViewerOL3Styles.defaultStyle() |
|
|
|
|
76
|
|
|
}), |
77
|
|
|
textline: new ol.layer.Vector({ |
78
|
|
|
'source': new ol.source.Vector(), |
79
|
|
|
'style': dlfViewerOL3Styles.invisibleStyle() |
80
|
|
|
}), |
81
|
|
|
select: new ol.layer.Vector({ |
82
|
|
|
'source': new ol.source.Vector(), |
83
|
|
|
'style': dlfViewerOL3Styles.selectStyle() |
84
|
|
|
}), |
85
|
|
|
hoverTextblock: new ol.layer.Vector({ |
86
|
|
|
'source': new ol.source.Vector(), |
87
|
|
|
'style': dlfViewerOL3Styles.hoverStyle() |
88
|
|
|
}), |
89
|
|
|
hoverTextline: new ol.layer.Vector({ |
90
|
|
|
'source': new ol.source.Vector(), |
91
|
|
|
'style': dlfViewerOL3Styles.textlineStyle() |
92
|
|
|
}) |
93
|
|
|
}; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @type {ol.Feature} |
97
|
|
|
* @private |
98
|
|
|
*/ |
99
|
|
|
this.selectedFeature_ = undefined; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @type {Object} |
103
|
|
|
* @private |
104
|
|
|
*/ |
105
|
|
|
this.handlers_ = { |
106
|
|
|
mapClick: $.proxy(function(event) { |
107
|
|
|
// the click handler adds the clicked feature to a |
108
|
|
|
// select layer which could be used to create a highlight |
109
|
|
|
// effect on the map |
110
|
|
|
|
111
|
|
|
var feature = this.map.forEachFeatureAtPixel(event['pixel'], function(feature, layer) { |
|
|
|
|
112
|
|
|
if (feature.get('type') === 'textblock') |
|
|
|
|
113
|
|
|
return feature; |
|
|
|
|
114
|
|
|
}); |
115
|
|
|
|
116
|
|
|
// deselect all |
117
|
|
|
if (feature === undefined) { |
118
|
|
|
this.layers_.select.getSource().clear(); |
119
|
|
|
this.selectedFeature_ = undefined; |
120
|
|
|
this.showFulltext(undefined); |
121
|
|
|
return; |
122
|
|
|
}; |
123
|
|
|
|
124
|
|
|
// highlight features |
125
|
|
|
if (this.selectedFeature_) { |
126
|
|
|
|
127
|
|
|
// remove old clicks |
128
|
|
|
this.layers_.select.getSource().removeFeature(this.selectedFeature_); |
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
if (feature) { |
133
|
|
|
|
134
|
|
|
// remove hover for preventing an adding of styles |
135
|
|
|
this.layers_.hoverTextblock.getSource().clear(); |
136
|
|
|
|
137
|
|
|
// add feature |
138
|
|
|
this.layers_.select.getSource().addFeature(feature); |
139
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
this.selectedFeature_ = feature; |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
if (dlfUtils.exists(feature)) |
|
|
|
|
146
|
|
|
this.showFulltext([feature]); |
|
|
|
|
147
|
|
|
|
148
|
|
|
}, |
149
|
|
|
this), |
150
|
|
|
mapHover: $.proxy(function(event) { |
151
|
|
|
// hover in case of dragging |
152
|
|
|
if (event['dragging']) { |
153
|
|
|
return; |
154
|
|
|
}; |
155
|
|
|
|
156
|
|
|
var hoverSourceTextblock_ = this.layers_.hoverTextblock.getSource(), |
157
|
|
|
hoverSourceTextline_ = this.layers_.hoverTextline.getSource(), |
158
|
|
|
selectSource_ = this.layers_.select.getSource(), |
159
|
|
|
map_ = this.map, |
160
|
|
|
textblockFeature, |
161
|
|
|
textlineFeature; |
162
|
|
|
|
163
|
|
|
map_.forEachFeatureAtPixel(event['pixel'], function(feature, layer) { |
|
|
|
|
164
|
|
|
if (feature.get('type') === 'textblock') |
165
|
|
|
textblockFeature = feature; |
|
|
|
|
166
|
|
|
if (feature.get('type') === 'textline') |
167
|
|
|
textlineFeature = feature; |
|
|
|
|
168
|
|
|
}); |
169
|
|
|
|
170
|
|
|
// |
171
|
|
|
// Handle TextBlock elements |
172
|
|
|
// |
173
|
|
|
var activeSelectTextBlockEl_ = selectSource_.getFeatures().length > 0 ? |
174
|
|
|
selectSource_.getFeatures()[0] : undefined, |
175
|
|
|
activeHoverTextBlockEl_ = hoverSourceTextblock_.getFeatures().length > 0 ? |
176
|
|
|
hoverSourceTextblock_.getFeatures()[0] : undefined, |
177
|
|
|
isFeatureEqualSelectFeature_ = activeSelectTextBlockEl_ !== undefined && textblockFeature !== undefined && |
178
|
|
|
activeSelectTextBlockEl_.getId() === textblockFeature.getId() ? true : false, |
179
|
|
|
isFeatureEqualToOldHoverFeature_ = activeHoverTextBlockEl_ !== undefined && textblockFeature !== undefined && |
180
|
|
|
activeHoverTextBlockEl_.getId() === textblockFeature.getId() ? true : false; |
181
|
|
|
|
182
|
|
|
if (!isFeatureEqualToOldHoverFeature_ && !isFeatureEqualSelectFeature_) { |
183
|
|
|
|
184
|
|
|
// remove old textblock hover features |
185
|
|
|
hoverSourceTextblock_.clear(); |
186
|
|
|
|
187
|
|
|
if (textblockFeature) { |
188
|
|
|
// add textblock feature to hover |
189
|
|
|
hoverSourceTextblock_.addFeature(textblockFeature); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
// |
195
|
|
|
// Handle TextLine elements |
196
|
|
|
// |
197
|
|
|
var activeHoverTextBlockEl_ = hoverSourceTextline_.getFeatures().length > 0 ? |
|
|
|
|
198
|
|
|
hoverSourceTextline_.getFeatures()[0] : undefined, |
199
|
|
|
isFeatureEqualToOldHoverFeature_ = activeHoverTextBlockEl_ !== undefined && textlineFeature !== undefined && |
|
|
|
|
200
|
|
|
activeHoverTextBlockEl_.getId() === textlineFeature.getId() ? true : false; |
201
|
|
|
|
202
|
|
|
if (!isFeatureEqualToOldHoverFeature_) { |
203
|
|
|
|
204
|
|
|
if (activeHoverTextBlockEl_) { |
205
|
|
|
|
206
|
|
|
// remove highlight effect on fulltext view |
207
|
|
|
var oldTargetElem = $('#' + activeHoverTextBlockEl_.getId()); |
208
|
|
|
|
209
|
|
|
if (oldTargetElem.hasClass('highlight') ) { |
210
|
|
|
oldTargetElem.removeClass('highlight'); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
// remove old textline hover features |
214
|
|
|
hoverSourceTextline_.clear(); |
215
|
|
|
|
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
if (textlineFeature) { |
219
|
|
|
|
220
|
|
|
// add highlight effect to fulltext view |
221
|
|
|
var targetElem = $('#' + textlineFeature.getId()); |
222
|
|
|
|
223
|
|
|
if (targetElem.length > 0 && !targetElem.hasClass('highlight')) { |
224
|
|
|
targetElem.addClass('highlight'); |
225
|
|
|
$('#tx-dlf-fulltextselection').scrollTo(targetElem, 50); |
226
|
|
|
hoverSourceTextline_.addFeature(textlineFeature); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
}, |
234
|
|
|
this) |
235
|
|
|
}; |
236
|
|
|
|
237
|
|
|
// add active / deactive behavior in case of click on control |
238
|
|
|
var anchorEl = $('#tx-dlf-tools-fulltext'); |
239
|
|
|
if (anchorEl.length > 0){ |
240
|
|
|
var toogleFulltext = $.proxy(function(event) { |
241
|
|
|
event.preventDefault(); |
242
|
|
|
|
243
|
|
|
if ($(event.target).hasClass('active')){ |
244
|
|
|
this.deactivate(); |
245
|
|
|
return; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
this.activate(); |
249
|
|
|
}, this); |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
anchorEl.on('click', toogleFulltext); |
253
|
|
|
anchorEl.on('touchstart', toogleFulltext); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
// set initial title of fulltext element |
257
|
|
|
$("#tx-dlf-tools-fulltext") |
258
|
|
|
.text(this.dic['fulltext-on']) |
259
|
|
|
.attr('title', this.dic['fulltext-on']); |
260
|
|
|
|
261
|
|
|
// if fulltext is activated via cookie than run activation methode |
262
|
|
|
if (dlfUtils.getCookie("tx-dlf-pageview-fulltext-select") == 'enabled') { |
|
|
|
|
263
|
|
|
// activate the fulltext behavior |
264
|
|
|
this.activate(anchorEl); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
}; |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Activate Fulltext Features |
271
|
|
|
*/ |
272
|
|
|
dlfViewerFullTextControl.prototype.activate = function() { |
273
|
|
|
|
274
|
|
|
var controlEl = $('#tx-dlf-tools-fulltext'); |
275
|
|
|
|
276
|
|
|
// if the activate method is called for the first time fetch |
277
|
|
|
// fulltext data from server |
278
|
|
|
if (this.fulltextData_ === undefined) { |
279
|
|
|
this.fulltextData_ = dlfViewerFullTextControl.fetchFulltextDataFromServer(this.url, this.image); |
280
|
|
|
|
281
|
|
|
if (this.fulltextData_ !== undefined) { |
282
|
|
|
// add features to fulltext layer |
283
|
|
|
this.layers_.textblock.getSource().addFeatures(this.fulltextData_.getTextblocks()); |
284
|
|
|
this.layers_.textline.getSource().addFeatures(this.fulltextData_.getTextlines()); |
285
|
|
|
|
286
|
|
|
// add first feature of textBlockFeatures to map |
287
|
|
|
if (this.fulltextData_.getTextblocks().length > 0) { |
288
|
|
|
this.layers_.select.getSource().addFeature(this.fulltextData_.getTextblocks()[0]); |
289
|
|
|
this.selectedFeature_ = this.fulltextData_.getTextblocks()[0]; |
290
|
|
|
this.showFulltext(this.fulltextData_.getTextblocks()); |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
// now activate the fulltext overlay and map behavior |
296
|
|
|
this.enableFulltextSelect(); |
297
|
|
|
dlfUtils.setCookie("tx-dlf-pageview-fulltext-select", 'enabled'); |
|
|
|
|
298
|
|
|
$(controlEl).addClass('active'); |
299
|
|
|
|
300
|
|
|
// trigger event |
301
|
|
|
$(this).trigger("activate-fulltext", this); |
302
|
|
|
}; |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Activate Fulltext Features |
306
|
|
|
*/ |
307
|
|
|
dlfViewerFullTextControl.prototype.deactivate = function() { |
308
|
|
|
|
309
|
|
|
var controlEl = $('#tx-dlf-tools-fulltext'); |
310
|
|
|
|
311
|
|
|
// deactivate fulltext |
312
|
|
|
this.disableFulltextSelect(); |
313
|
|
|
dlfUtils.setCookie("tx-dlf-pageview-fulltext-select", 'disabled'); |
|
|
|
|
314
|
|
|
$(controlEl).removeClass('active'); |
315
|
|
|
|
316
|
|
|
// trigger event |
317
|
|
|
$(this).trigger("deactivate-fulltext", this); |
318
|
|
|
}; |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Disable Fulltext Features |
322
|
|
|
* |
323
|
|
|
* @return void |
324
|
|
|
*/ |
325
|
|
|
dlfViewerFullTextControl.prototype.disableFulltextSelect = function() { |
326
|
|
|
|
327
|
|
|
// register event listeners |
328
|
|
|
this.map.un('click', this.handlers_.mapClick); |
329
|
|
|
this.map.un('pointermove', this.handlers_.mapHover); |
330
|
|
|
|
331
|
|
|
// remove layers |
332
|
|
|
for (var key in this.layers_) { |
333
|
|
|
if (this.layers_.hasOwnProperty(key)) { |
334
|
|
|
this.map.removeLayer(this.layers_[key]); |
335
|
|
|
} |
336
|
|
|
}; |
337
|
|
|
|
338
|
|
|
var className = 'fulltext-visible'; |
339
|
|
|
$("#tx-dlf-tools-fulltext").removeClass(className) |
340
|
|
|
.text(this.dic['fulltext-on']) |
341
|
|
|
.attr('title', this.dic['fulltext-on']); |
342
|
|
|
|
343
|
|
|
$('#tx-dlf-fulltextselection').removeClass(className); |
344
|
|
|
$('#tx-dlf-fulltextselection').hide(); |
345
|
|
|
$('body').removeClass(className); |
346
|
|
|
|
347
|
|
|
}; |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Activate Fulltext Features |
351
|
|
|
* @param {Array.<ol.Feature>} textBlockFeatures |
352
|
|
|
* @þaram {Array.<ol.Feature>} textLineFeatures |
353
|
|
|
*/ |
354
|
|
|
dlfViewerFullTextControl.prototype.enableFulltextSelect = function(textBlockFeatures, textLineFeatures) { |
|
|
|
|
355
|
|
|
|
356
|
|
|
// register event listeners |
357
|
|
|
this.map.on('click', this.handlers_.mapClick); |
358
|
|
|
this.map.on('pointermove', this.handlers_.mapHover); |
359
|
|
|
|
360
|
|
|
// add layers to map |
361
|
|
|
for (var key in this.layers_) { |
362
|
|
|
if (this.layers_.hasOwnProperty(key)) { |
363
|
|
|
this.map.addLayer(this.layers_[key]); |
364
|
|
|
} |
365
|
|
|
}; |
366
|
|
|
|
367
|
|
|
// show fulltext container |
368
|
|
|
var className = 'fulltext-visible'; |
369
|
|
|
$("#tx-dlf-tools-fulltext").addClass(className) |
370
|
|
|
.text(this.dic['fulltext-off']) |
371
|
|
|
.attr('title', this.dic['fulltext-off']); |
372
|
|
|
|
373
|
|
|
$('#tx-dlf-fulltextselection').addClass(className); |
374
|
|
|
$('#tx-dlf-fulltextselection').show(); |
375
|
|
|
$('body').addClass(className); |
376
|
|
|
}; |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Method fetches the fulltext data from the server |
380
|
|
|
* @param {string} url |
381
|
|
|
* @param {Object} image |
382
|
|
|
* @param {number=} opt_offset |
383
|
|
|
* @return {ol.Feature|undefined} |
384
|
|
|
* @static |
385
|
|
|
*/ |
386
|
|
|
dlfViewerFullTextControl.fetchFulltextDataFromServer = function(url, image, opt_offset){ |
387
|
|
|
// fetch data from server |
388
|
|
|
var request = $.ajax({ |
389
|
|
|
url: url, |
390
|
|
|
async: false |
391
|
|
|
}); |
392
|
|
|
|
393
|
|
|
// parse alto data |
394
|
|
|
var offset = dlfUtils.exists(opt_offset) ? opt_offset : undefined, |
|
|
|
|
395
|
|
|
parser = new dlfAltoParser(image, undefined, undefined, offset), |
|
|
|
|
396
|
|
|
fulltextCoordinates = request.responseXML ? parser.parseFeatures(request.responseXML) : |
397
|
|
|
request.responseText ? parser.parseFeatures(request.responseText) : []; |
398
|
|
|
|
399
|
|
|
if (fulltextCoordinates.length > 0) { |
400
|
|
|
return fulltextCoordinates[0]; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
return undefined; |
404
|
|
|
}; |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* Activate Fulltext Features |
408
|
|
|
* |
409
|
|
|
* @param {Array.<ol.Feature>|undefined} features |
410
|
|
|
*/ |
411
|
|
|
dlfViewerFullTextControl.prototype.showFulltext = function(features) { |
412
|
|
|
|
413
|
|
|
var popupHTML = '', |
414
|
|
|
/** |
415
|
|
|
* Functions wraps fulltext context of a given textblock to a html string |
416
|
|
|
* @param {ol.Feature} feature |
417
|
|
|
* @return {string} |
418
|
|
|
*/ |
419
|
|
|
appendHTML = function(feature) { |
420
|
|
|
var html = '', |
421
|
|
|
textlines = feature.get('textlines'); |
422
|
|
|
|
423
|
|
|
for (var i = 0; i < textlines.length; i++) { |
424
|
|
|
|
425
|
|
|
html = html + '<span class="textline" id="' + textlines[i].getId() + '">'; |
426
|
|
|
|
427
|
|
|
var content = textlines[i].get('content'); |
428
|
|
|
for (var j = 0; j < content.length; j++) { |
429
|
|
|
html = html + '<span class="' + content[j].get('type') + '" id="' + content[j].getId() |
430
|
|
|
+ '">' + content[j].get('fulltext').replace(/\n/g, '<br />') + '</span>'; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
html = html + '</span>'; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
return html; |
437
|
|
|
}; |
438
|
|
|
|
439
|
|
|
// iterate over given textblocks |
440
|
|
|
if (features !== undefined) { |
441
|
|
|
|
442
|
|
|
for (var i = 0; i < features.length; i++) { |
443
|
|
|
popupHTML = popupHTML + appendHTML(features[i]) + '<br /><br />'; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
}; |
447
|
|
|
|
448
|
|
|
$('#tx-dlf-fulltextselection').html(popupHTML); |
449
|
|
|
|
450
|
|
|
}; |
451
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.