Browse Source

Add full text download tool and duplicate full text display for always

active display
pull/563/head
Beatrycze Volk 1 year ago
parent
commit
12355f4cd9
  1. 6
      Classes/Plugin/PageView.php
  2. 86
      Classes/Plugin/Tools/FulltextDownloadTool.php
  3. 86
      Classes/Plugin/Tools/FulltextOnTool.php
  4. 2
      Configuration/TypoScript/Toolbox/setup.txt
  5. 1
      Documentation/Plugins/Index.rst
  6. 26
      Resources/Private/Language/FulltextDownloadTool.xml
  7. 26
      Resources/Private/Language/FulltextOnTool.xml
  8. 4
      Resources/Private/Language/Labels.xml
  9. 12
      Resources/Private/Templates/FulltextDownloadTool.tmpl
  10. 38
      Resources/Public/Javascript/PageView/FulltextControl.js
  11. 93
      Resources/Public/Javascript/PageView/FulltextDownloadControl.js
  12. 379
      Resources/Public/Javascript/PageView/FulltextOnControl.js
  13. 4
      Resources/Public/Javascript/PageView/PageView.js
  14. 14
      ext_localconf.php

6
Classes/Plugin/PageView.php

@ -89,7 +89,11 @@ class PageView extends \Kitodo\Dlf\Common\AbstractPlugin
'Resources/Public/Javascript/PageView/AnnotationParser.js',
'Resources/Public/Javascript/PageView/AnnotationControl.js',
'Resources/Public/Javascript/PageView/ImageManipulationControl.js',
'Resources/Public/Javascript/PageView/FulltextControl.js',
'Resources/Public/Javascript/PageView/FulltextDownloadControl.js',
// full text with switch on/off
// 'Resources/Public/Javascript/PageView/FulltextControl.js',
// always active full text (DDB)
'Resources/Public/Javascript/PageView/FulltextOnControl.js',
'Resources/Public/Javascript/PageView/FullTextUtility.js',
'Resources/Public/Javascript/PageView/PageView.js'
];

86
Classes/Plugin/Tools/FulltextDownloadTool.php

@ -0,0 +1,86 @@
<?php
/**
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace Kitodo\Dlf\Plugin\Tools;
use Kitodo\Dlf\Common\Helper;
/**
* Fulltext Download tool for the plugin 'Toolbox' of the 'dlf' extension
*
* @author Beatrycze Volk <beatrycze.volk@slub-dresden.de>
* @package TYPO3
* @subpackage dlf
* @access public
*/
class FulltextDownloadTool extends \Kitodo\Dlf\Common\AbstractPlugin
{
public $scriptRelPath = 'Classes/Plugin/Tools/FulltextDownloadTool.php';
/**
* The main method of the PlugIn
*
* @access public
*
* @param string $content: The PlugIn content
* @param array $conf: The PlugIn configuration
*
* @return string The content that is displayed on the website
*/
public function main($content, $conf)
{
$this->init($conf);
// Merge configuration with conf array of toolbox.
if (!empty($this->cObj->data['conf'])) {
$this->conf = Helper::mergeRecursiveWithOverrule($this->cObj->data['conf'], $this->conf);
}
// Load current document.
$this->loadDocument();
if (
$this->doc === null
|| $this->doc->numPages < 1
|| empty($this->conf['fileGrpFulltext'])
) {
// Quit without doing anything if required variables are not set.
return $content;
} else {
if (!empty($this->piVars['logicalPage'])) {
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
// The logical page parameter should not appear again
unset($this->piVars['logicalPage']);
}
// Set default values if not set.
// $this->piVars['page'] may be integer or string (physical structure @ID)
if (
(int) $this->piVars['page'] > 0
|| empty($this->piVars['page'])
) {
$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
} else {
$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
}
$this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
}
// Load template file.
$this->getTemplate();
// Get text download.
$fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpFulltext']];
if (!empty($fullTextFile)) {
$markerArray['###FULLTEXT_DOWNLOAD###'] = '<a href="#" id="tx-dlf-tools-fulltextdownload" title="' . htmlspecialchars($this->pi_getLL('download-current-page', '')) . '">' . htmlspecialchars($this->pi_getLL('download-current-page', '')) . '</a>';
} else {
$markerArray['###FULLTEXT_DOWNLOAD###'] = '<span class="no-fulltext">' . htmlspecialchars($this->pi_getLL('fulltext-not-available', '')) . '</span>';
}
$content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
return $this->pi_wrapInBaseClass($content);
}
}

86
Classes/Plugin/Tools/FulltextOnTool.php

@ -0,0 +1,86 @@
<?php
/**
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace Kitodo\Dlf\Plugin\Tools;
use Kitodo\Dlf\Common\Helper;
/**
* Fulltext tool with always displayed text for the plugin 'Toolbox' of the 'dlf' extension
*
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* @author Alexander Bigga <alexander.bigga@slub-dresden.de>
* @author Beatrycze Volk <beatrycze.volk@slub-dresden.de>
* @package TYPO3
* @subpackage dlf
* @access public
*/
class FulltextOnTool extends \Kitodo\Dlf\Common\AbstractPlugin
{
public $scriptRelPath = 'Classes/Plugin/Tools/FulltextOnTool.php';
/**
* The main method of the PlugIn
*
* @access public
*
* @param string $content: The PlugIn content
* @param array $conf: The PlugIn configuration
*
* @return string The content that is displayed on the website
*/
public function main($content, $conf)
{
$this->init($conf);
// Merge configuration with conf array of toolbox.
if (!empty($this->cObj->data['conf'])) {
$this->conf = Helper::mergeRecursiveWithOverrule($this->cObj->data['conf'], $this->conf);
}
// Load current document.
$this->loadDocument();
if (
$this->doc === null
|| $this->doc->numPages < 1
|| empty($this->conf['fileGrpFulltext'])
) {
// Quit without doing anything if required variables are not set.
return $content;
} else {
if (!empty($this->piVars['logicalPage'])) {
$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
// The logical page parameter should not appear again
unset($this->piVars['logicalPage']);
}
// Set default values if not set.
// $this->piVars['page'] may be integer or string (physical structure @ID)
if (
(int) $this->piVars['page'] > 0
|| empty($this->piVars['page'])
) {
$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
} else {
$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
}
$this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
}
// Load template file.
$this->getTemplate();
$fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpFulltext']];
if (!empty($fullTextFile)) {
$markerArray['###FULLTEXT_SELECT###'] = '<a id="tx-dlf-tools-fulltext" title="' . htmlspecialchars($this->pi_getLL('fulltext', '')) . '">' . htmlspecialchars($this->pi_getLL('fulltext', '')) . '</a>';
} else {
$markerArray['###FULLTEXT_SELECT###'] = '<span class="no-fulltext">' . htmlspecialchars($this->pi_getLL('fulltext-not-available', '')) . '</span>';
}
$content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
return $this->pi_wrapInBaseClass($content);
}
}

2
Configuration/TypoScript/Toolbox/setup.txt

@ -1,5 +1,7 @@
plugin.tx_dlf_annotationtool.templateFile = EXT:dlf/Resources/Private/Templates/AnnotationTool.tmpl
plugin.tx_dlf_fulltextontool.templateFile = EXT:dlf/Resources/Private/Templates/FulltextOnTool.tmpl
plugin.tx_dlf_fulltexttool.templateFile = EXT:dlf/Resources/Private/Templates/FulltextTool.tmpl
plugin.tx_dlf_fulltextdownloadtool.templateFile = EXT:dlf/Resources/Private/Templates/FulltextDownloadTool.tmpl
plugin.tx_dlf_imagedownloadtool.templateFile = EXT:dlf/Resources/Private/Templates/ImageDownloadTool.tmpl
plugin.tx_dlf_imagemanipulationtool.templateFile = EXT:dlf/Resources/Private/Templates/ImageManipulationTool.tmpl
plugin.tx_dlf_pdfdownloadtool.templateFile = EXT:dlf/Resources/Private/Templates/PdfDownloadTool.tmpl

1
Documentation/Plugins/Index.rst

@ -1009,6 +1009,7 @@ Toolbox
* tx_dlf_imagedownloadtool
* tx_dlf_imagemanipulationtool
* tx_dlf_pdfdownloadtool
* tx_dlf_fulltextdownloadtool
* tx_dlf_searchindocumenttool
- :Property:

26
Resources/Private/Language/FulltextDownloadTool.xml

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<!--
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
-->
<T3locallang>
<meta type="array">
<type>module</type>
<description>Language labels for tool FulltextDownload</description>
</meta>
<data type="array">
<languageKey index="default" type="array">
<label index="download-current-page">Current page (TXT)</label>
<label index="fulltext-not-available">No Fulltext available</label>
</languageKey>
<languageKey index="de" type="array">
<label index="download-current-page">Aktuelle Seite (TXT)</label>
<label index="fulltext-not-available">Keine Volltexte vorhanden</label>
</languageKey>
</data>
</T3locallang>

26
Resources/Private/Language/FulltextOnTool.xml

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<!--
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
-->
<T3locallang>
<meta type="array">
<type>module</type>
<description>Language labels for tool Fulltext</description>
</meta>
<data type="array">
<languageKey index="default" type="array">
<label index="fulltext">Fulltext</label>
<label index="fulltext-not-available">No Fulltext available</label>
</languageKey>
<languageKey index="de" type="array">
<label index="fulltext">Volltext</label>
<label index="fulltext-not-available">Keine Volltexte vorhanden</label>
</languageKey>
</data>
</T3locallang>

4
Resources/Private/Language/Labels.xml

@ -151,8 +151,10 @@
<label index="tx_dlf_mail">Email</label>
<label index="tx_dlf_mail.mail">Address</label>
<label index="tx_dlf_mail.name">Name</label>
<label index="tx_dlf_toolbox.fulltextontool">Fulltext</label>
<label index="tx_dlf_toolbox.fulltexttool">Fulltext</label>
<label index="tx_dlf_toolbox.annotationtool">IIIF Annotations</label>
<label index="tx_dlf_toolbox.fulltextdownloadtool">Fulltext Download</label>
<label index="tx_dlf_toolbox.imagedownloadtool">Image Download</label>
<label index="tx_dlf_toolbox.imagemanipulationtool">Image Manipulation</label>
<label index="tx_dlf_toolbox.pdfdownloadtool">PDF Download</label>
@ -334,8 +336,10 @@
<label index="tx_dlf_mail">E-Mail</label>
<label index="tx_dlf_mail.mail">Adresse</label>
<label index="tx_dlf_mail.name">Name</label>
<label index="tx_dlf_toolbox.fulltextontool">Volltext</label>
<label index="tx_dlf_toolbox.fulltexttool">Volltext</label>
<label index="tx_dlf_toolbox.annotationtool">IIIF-Annotationen</label>
<label index="tx_dlf_toolbox.fulltextdownloadtool">Volltext-Download</label>
<label index="tx_dlf_toolbox.imagedownloadtool">Bild-Download</label>
<label index="tx_dlf_toolbox.imagemanipulationtool">Bildbearbeitung</label>
<label index="tx_dlf_toolbox.pdfdownloadtool">PDF-Download</label>

12
Resources/Private/Templates/FulltextDownloadTool.tmpl

@ -0,0 +1,12 @@
<!--
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
-->
<!-- ###TEMPLATE### -->
<span class="tx-dlf-tools-fulltextdownload">###FULLTEXT_DOWNLOAD###</span>
<!-- ###TEMPLATE### -->

38
Resources/Public/Javascript/PageView/FulltextControl.js

@ -122,23 +122,7 @@ var dlfViewerFullTextControl = function(map, image, fulltextUrl) {
return;
}
// highlight features
if (this.selectedFeature_) {
// remove old clicks
this.layers_.select.getSource().removeFeature(this.selectedFeature_);
}
if (feature) {
// remove hover for preventing an adding of styles
this.layers_.hoverTextblock.getSource().clear();
// add feature
this.layers_.select.getSource().addFeature(feature);
}
this.handleLayersForClick(feature);
this.selectedFeature_ = feature;
@ -210,6 +194,26 @@ var dlfViewerFullTextControl = function(map, image, fulltextUrl) {
};
/**
* Handle layers for click
* @param {ol.Feature|undefined} feature
*/
dlfViewerFullTextControl.prototype.handleLayersForClick = function(feature) {
// highlight features
if (this.selectedFeature_) {
// remove old clicks
this.layers_.select.getSource().removeFeature(this.selectedFeature_);
}
if (feature) {
// remove hover for preventing an adding of styles
this.layers_.hoverTextblock.getSource().clear();
// add feature
this.layers_.select.getSource().addFeature(feature);
}
};
/**
* Handle TextBlock elements
* @param {ol.Feature|undefined} textblockFeature
* @param {ol.Feature|undefined} selectSource_

93
Resources/Public/Javascript/PageView/FulltextDownloadControl.js

@ -0,0 +1,93 @@
var dlfViewerFullTextDownloadControl = function(map, image, fullTextUrl) {
/**
* @private
* @type {ol.Map}
*/
this.map = map;
/**
* @type {Object}
* @private
*/
this.image = image;
/**
* @type {string}
* @private
*/
this.url = fullTextUrl;
// add active / deactive behavior in case of click on control
var element = $('#tx-dlf-tools-fulltextdownload');
if (element.length > 0){
var downloadFullText = $.proxy(function(event) {
event.preventDefault();
this.downloadFullTextFile();
}, this);
element.on('click', downloadFullText);
element.on('touchstart', downloadFullText);
}
};
/**
* Method fetches the fulltext data from the server
*/
dlfViewerFullTextDownloadControl.prototype.downloadFullTextFile = function() {
var clickedElement = $('#tx-dlf-tools-fulltextdownload');
var element = $('<a/>');
element.attr('id', 'downloadFile');
element.attr('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(this.createFullTextFile()));
element.attr('download', 'fulltext.txt');
element.insertAfter(clickedElement);
$('#downloadFile').get(0).click();
$('#downloadFile').remove();
};
/**
* Activate Fulltext Features
*/
dlfViewerFullTextDownloadControl.prototype.createFullTextFile = function() {
var fullTextData = dlfFullTextUtils.fetchFullTextDataFromServer(this.url, this.image);
var features = fullTextData.getTextblocks();
var fileContent = '';
if (features !== undefined) {
for (feature of features) {
var textLines = feature.get('textlines');
for (textLine of textLines) {
fileContent = fileContent.concat(this.appendTextLine(textLine));
}
fileContent = fileContent.concat('\n\n');
}
}
return fileContent;
};
/**
* Append text line
*
* @param {string} textLine
*/
dlfViewerFullTextDownloadControl.prototype.appendTextLine = function(textLine) {
var fileContent = '';
var content = textLine.get('content');
for (item of content) {
var fullText = item.get('fulltext');
var fullTextLines = fullText.split(/\n/g);
for (const [i, fullTextLine] of fullTextLines.entries()) {
fileContent = fileContent.concat(fullTextLine);
if (i < fullTextLines.length - 1) {
fileContent = fileContent.concat('\n');
}
}
}
return fileContent.concat(fileContent);
};

379
Resources/Public/Javascript/PageView/FulltextOnControl.js

@ -0,0 +1,379 @@
/**
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
/**
* This is necessary to support the scrolling of the element into the viewport
* in case of text hover on the map.
*
* @param elem
* @param speed
* @returns {jQuery}
*/
jQuery.fn.scrollTo = function(elem, speed) {
var manualOffsetTop = $(elem).parent().height() / 2;
$(this).animate({
scrollTop: $(this).scrollTop() - $(this).offset().top + $(elem).offset().top - manualOffsetTop
}, speed === undefined ? 1000 : speed);
return this;
};
/**
* Encapsulates especially the fulltext behavior
* @constructor
* @param {ol.Map} map
* @param {Object} image
* @param {string} fulltextUrl
*/
var dlfViewerFullTextControl = function(map, image, fulltextUrl) {
/**
* @private
* @type {ol.Map}
*/
this.map = map;
/**
* @type {Object}
* @private
*/
this.image = image;
/**
* @type {string}
* @private
*/
this.url = fulltextUrl;
/**
* @type {ol.Feature|undefined}
* @private
*/
this.fulltextData_ = undefined;
/**
* @type {Object}
* @private
*/
this.layers_ = {
textblock: new ol.layer.Vector({
'source': new ol.source.Vector(),
'style': dlfViewerOL3Styles.defaultStyle()
}),
textline: new ol.layer.Vector({
'source': new ol.source.Vector(),
'style': dlfViewerOL3Styles.invisibleStyle()
}),
select: new ol.layer.Vector({
'source': new ol.source.Vector(),
'style': dlfViewerOL3Styles.selectStyle()
}),
hoverTextblock: new ol.layer.Vector({
'source': new ol.source.Vector(),
'style': dlfViewerOL3Styles.hoverStyle()
}),
hoverTextline: new ol.layer.Vector({
'source': new ol.source.Vector(),
'style': dlfViewerOL3Styles.textlineStyle()
})
};
/**
* @type {ol.Feature}
* @private
*/
this.selectedFeature_ = undefined;
/**
* @type {Object}
* @private
*/
this.handlers_ = {
mapClick: $.proxy(function(event) {
// the click handler adds the clicked feature to a
// select layer which could be used to create a highlight
// effect on the map
var feature = this.map.forEachFeatureAtPixel(event['pixel'], function(feature, layer) {
if (feature.get('type') === 'textblock') {
return feature;
}
});
// deselect all
if (feature === undefined) {
this.layers_.select.getSource().clear();
this.selectedFeature_ = undefined;
this.showFulltext(undefined);
return;
}
this.handleLayersForClick(feature);
this.selectedFeature_ = feature;
if (dlfUtils.exists(feature)) {
this.showFulltext([feature]);
}
},
this),
mapHover: $.proxy(function(event) {
// hover in case of dragging
if (event['dragging']) {
return;
}
var hoverSourceTextblock_ = this.layers_.hoverTextblock.getSource(),
hoverSourceTextline_ = this.layers_.hoverTextline.getSource(),
selectSource_ = this.layers_.select.getSource(),
map_ = this.map,
textblockFeature,
textlineFeature;
map_.forEachFeatureAtPixel(event['pixel'], function(feature, layer) {
if (feature.get('type') === 'textblock') {
textblockFeature = feature;
}
if (feature.get('type') === 'textline') {
textlineFeature = feature;
}
});
this.handleTextBlockElements(textblockFeature, selectSource_, hoverSourceTextblock_);
this.handleTextLineElements(textlineFeature, hoverSourceTextline_);
},
this)
};
// add active / deactive behavior in case of click on control
var anchorEl = $('#tx-dlf-tools-fulltext');
if (anchorEl.length > 0){
var toogleFulltext = $.proxy(function(event) {
event.preventDefault();
this.activate();
}, this);
anchorEl.on('click', toogleFulltext);
anchorEl.on('touchstart', toogleFulltext);
}
this.activate(anchorEl);
};
/**
* Handle layers for click
* @param {ol.Feature|undefined} feature
*/
dlfViewerFullTextControl.prototype.handleLayersForClick = function(feature) {
// highlight features
if (this.selectedFeature_) {
// remove old clicks
this.layers_.select.getSource().removeFeature(this.selectedFeature_);
}
if (feature) {
// remove hover for preventing an adding of styles
this.layers_.hoverTextblock.getSource().clear();
// add feature
this.layers_.select.getSource().addFeature(feature);
}
};
/**
* Handle TextBlock elements
* @param {ol.Feature|undefined} textblockFeature
* @param {ol.Feature|undefined} selectSource_
* @param {any} hoverSourceTextblock_
*/
dlfViewerFullTextControl.prototype.handleTextBlockElements = function(textblockFeature, selectSource_, hoverSourceTextblock_) {
var activeSelectTextBlockEl_ = dlfFullTextUtils.getFeature(selectSource_),
activeHoverTextBlockEl_ = dlfFullTextUtils.getFeature(hoverSourceTextblock_),
isFeatureEqualSelectFeature_ = dlfFullTextUtils.isFeatureEqual(activeSelectTextBlockEl_, textblockFeature),
isFeatureEqualToOldHoverFeature_ = dlfFullTextUtils.isFeatureEqual(activeHoverTextBlockEl_);
if (!isFeatureEqualToOldHoverFeature_ && !isFeatureEqualSelectFeature_) {
// remove old textblock hover features
hoverSourceTextblock_.clear();
if (textblockFeature) {
// add textblock feature to hover
hoverSourceTextblock_.addFeature(textblockFeature);
}
}
};
/**
* Handle TextLine elements
* @param {ol.Feature|undefined} textlineFeature
* @param {any} hoverSourceTextline_
*/
dlfViewerFullTextControl.prototype.handleTextLineElements = function(textlineFeature, hoverSourceTextline_) {
var activeHoverTextBlockEl_ = dlfFullTextUtils.getFeature(hoverSourceTextline_);
isFeatureEqualToOldHoverFeature_ = dlfFullTextUtils.isFeatureEqual(activeHoverTextBlockEl_, textlineFeature);
if (!isFeatureEqualToOldHoverFeature_) {
this.removeHighlightEffect(activeHoverTextBlockEl_, hoverSourceTextline_);
this.addHighlightEffect(textlineFeature, hoverSourceTextline_);
}
};
/**
* Remove highlight effect from full text view
* @param {ol.Feature|undefined} activeHoverTextBlockEl_
* @param {any} hoverSourceTextline_
*/
dlfViewerFullTextControl.prototype.removeHighlightEffect = function(activeHoverTextBlockEl_, hoverSourceTextline_) {
if (activeHoverTextBlockEl_) {
var oldTargetElem = $('#' + activeHoverTextBlockEl_.getId());
if (oldTargetElem.hasClass('highlight') ) {
oldTargetElem.removeClass('highlight');
}
// remove old textline hover features
hoverSourceTextline_.clear();
}
};
/**
* Add highlight effect from full text view
* @param {ol.Feature|undefined} textlineFeature
* @param {any} hoverSourceTextline_
*/
dlfViewerFullTextControl.prototype.addHighlightEffect = function(textlineFeature, hoverSourceTextline_) {
if (textlineFeature) {
var targetElem = $('#' + textlineFeature.getId());
if (targetElem.length > 0 && !targetElem.hasClass('highlight')) {
targetElem.addClass('highlight');
setTimeout(this.scrollToText, 1000, targetElem);
hoverSourceTextline_.addFeature(textlineFeature);
}
}
};
/**
* Check if full text element is highlighted
* @param {any} element
*/
dlfViewerFullTextControl.prototype.scrollToText = function(element) {
if (element.hasClass('highlight')) {
$('html, body').animate({
scrollTop: element.offset().top
}, 500);
}
};
/**
* Activate Fulltext Features
*/
dlfViewerFullTextControl.prototype.activate = function() {
var controlEl = $('#tx-dlf-tools-fulltext');
// if the activate method is called for the first time fetch
// fulltext data from server
if (this.fulltextData_ === undefined) {
this.fulltextData_ = dlfFullTextUtils.fetchFullTextDataFromServer(this.url, this.image);
if (this.fulltextData_ !== undefined) {
// add features to fulltext layer
this.layers_.textblock.getSource().addFeatures(this.fulltextData_.getTextblocks());
this.layers_.textline.getSource().addFeatures(this.fulltextData_.getTextlines());
// add first feature of textBlockFeatures to map
if (this.fulltextData_.getTextblocks().length > 0) {
this.layers_.select.getSource().addFeature(this.fulltextData_.getTextblocks()[0]);
this.selectedFeature_ = this.fulltextData_.getTextblocks()[0];
this.showFulltext(this.fulltextData_.getTextblocks());
}
}
}
// now activate the fulltext overlay and map behavior
this.enableFulltextSelect();
dlfUtils.setCookie("tx-dlf-pageview-fulltext-select", 'enabled');
$(controlEl).addClass('active');
// trigger event
$(this).trigger("activate-fulltext", this);
};
/**
* Activate Fulltext Features
*/
dlfViewerFullTextControl.prototype.enableFulltextSelect = function() {
// register event listeners
this.map.on('click', this.handlers_.mapClick);
this.map.on('pointermove', this.handlers_.mapHover);
// add layers to map
for (var key in this.layers_) {
if (this.layers_.hasOwnProperty(key)) {
this.map.addLayer(this.layers_[String(key)]);
}
}
// show fulltext container
var className = 'fulltext-visible';
$("#tx-dlf-tools-fulltext").addClass(className);
$('#tx-dlf-fulltextselection').addClass(className);
$('#tx-dlf-fulltextselection').show();
$('body').addClass(className);
};
/**
* Show full text
*
* @param {Array.<ol.Feature>|undefined} features
*/
dlfViewerFullTextControl.prototype.showFulltext = function(features) {
if (features !== undefined) {
$('#tx-dlf-fulltextselection').children().remove();
for (feature of features) {
var textLines = feature.get('textlines');
for (textLine of textLines) {
this.appendTextLineSpan(textLine);
}
$('#tx-dlf-fulltextselection').append('<br /><br />');
}
}
};
/**
* Append text line span
*
* @param {Object} textLine
*/
dlfViewerFullTextControl.prototype.appendTextLineSpan = function(textLine) {
var textLineSpan = $('<span class="textline" id="' + textLine.getId() + '">');
var content = textLine.get('content');
for (item of content) {
var span = $('<span class="' + item.get('type') + '" id="' + item.getId() + '"/>');
var spanText = item.get('fulltext');
var spanTextLines = spanText.split(/\n/g);
for (const [i, spanTextLine] of spanTextLines.entries()) {
span.append(document.createTextNode(spanTextLine));
if (i < spanTextLines.length - 1) {
span.append($('<br />'));
}
}
textLineSpan.append(span);
}
$('#tx-dlf-fulltextselection').append(textLineSpan);
};

4
Resources/Public/Javascript/PageView/PageView.js

@ -151,14 +151,16 @@ var dlfViewer = function(settings){
*/
dlfViewer.prototype.addCustomControls = function(controlNames) {
var fulltextControl = undefined,
fulltextDownloadControl = undefined,
annotationControl = undefined,
imageManipulationControl = undefined,
images = this.images;
// Adds fulltext behavior only if there is fulltext available and no double page
// Adds fulltext behavior and download only if there is fulltext available and no double page
// behavior is active
if (this.fulltexts[0] !== undefined && this.fulltexts[0].length !== 0 && this.fulltexts[0].url !== '' && this.images.length === 1) {
fulltextControl = new dlfViewerFullTextControl(this.map, this.images[0], this.fulltexts[0].url);
fulltextDownloadControl = new dlfViewerFullTextDownloadControl(this.map, this.images[0], this.fulltexts[0].url);
} else {
$('#tx-dlf-tools-fulltext').remove();
}

14
ext_localconf.php

@ -128,6 +128,12 @@ plugin.tx_dlf_validator {
}
tt_content.list.20.dlf_validator < plugin.tx_dlf_validator
plugin.tx_dlf_fulltextontool = USER
plugin.tx_dlf_fulltextontool {
userFunc = Kitodo\Dlf\Plugin\Tools\FulltextOnTool->main
}
tt_content.list.20.dlf_fulltextontool < plugin.tx_dlf_fulltextontool
plugin.tx_dlf_fulltexttool = USER
plugin.tx_dlf_fulltexttool {
userFunc = Kitodo\Dlf\Plugin\Tools\FulltextTool->main
@ -140,6 +146,12 @@ plugin.tx_dlf_annotationtool {
}
tt_content.list.20.dlf_annotationtool < plugin.tx_dlf_annotationtool
plugin.tx_dlf_fulltextdownloadtool = USER
plugin.tx_dlf_fulltextdownloadtool {
userFunc = Kitodo\Dlf\Plugin\Tools\FulltextDownloadTool->main
}
tt_content.list.20.dlf_fulltextdownloadtool < plugin.tx_dlf_fulltextdownloadtool
plugin.tx_dlf_imagedownloadtool = USER
plugin.tx_dlf_imagedownloadtool {
userFunc = Kitodo\Dlf\Plugin\Tools\ImageDownloadTool->main
@ -199,8 +211,10 @@ foreach ($iconArray as $key => $value) {
);
// Register tools for toolbox plugin.
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/Classes/Plugin/Toolbox.php']['tools'] = [];
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/Classes/Plugin/Toolbox.php']['tools'][\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getCN($_EXTKEY) . '_fulltextontool'] = 'LLL:EXT:dlf/Resources/Private/Language/Labels.xml:tx_dlf_toolbox.fulltextontool';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/Classes/Plugin/Toolbox.php']['tools'][\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getCN($_EXTKEY) . '_fulltexttool'] = 'LLL:EXT:dlf/Resources/Private/Language/Labels.xml:tx_dlf_toolbox.fulltexttool';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/Classes/Plugin/Toolbox.php']['tools'][\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getCN($_EXTKEY) . '_annotationtool'] = 'LLL:EXT:dlf/Resources/Private/Language/Labels.xml:tx_dlf_toolbox.annotationtool';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/Classes/Plugin/Toolbox.php']['tools'][\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getCN($_EXTKEY) . '_fulltextdownloadtool'] = 'LLL:EXT:dlf/Resources/Private/Language/Labels.xml:tx_dlf_toolbox.fulltextdownloadtool';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/Classes/Plugin/Toolbox.php']['tools'][\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getCN($_EXTKEY) . '_imagedownloadtool'] = 'LLL:EXT:dlf/Resources/Private/Language/Labels.xml:tx_dlf_toolbox.imagedownloadtool';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/Classes/Plugin/Toolbox.php']['tools'][\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getCN($_EXTKEY) . '_imagemanipulationtool'] = 'LLL:EXT:dlf/Resources/Private/Language/Labels.xml:tx_dlf_toolbox.imagemanipulationtool';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['dlf/Classes/Plugin/Toolbox.php']['tools'][\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getCN($_EXTKEY) . '_pdfdownloadtool'] = 'LLL:EXT:dlf/Resources/Private/Language/Labels.xml:tx_dlf_toolbox.pdfdownloadtool';

Loading…
Cancel
Save