Browse Source

Add option to put JS in template

pull/507/head
Sebastian Meyer 2 years ago
parent
commit
42ebd6aa3f
  1. 67
      Classes/Plugin/PageView.php
  2. 10
      Configuration/Flexforms/PageView.xml
  3. 2
      Resources/Private/Language/PageView.xml
  4. 1
      Resources/Private/Templates/PageView.tmpl

67
Classes/Plugin/PageView.php

@ -66,30 +66,33 @@ class PageView extends \Kitodo\Dlf\Common\AbstractPlugin
*
* @access protected
*
* @return void
* @return string The output string for the ###JAVASCRIPT### template marker
*/
protected function addViewerJS()
{
$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
// Add OpenLayers library.
$pageRenderer->addCssFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/OpenLayers/ol3.css');
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/OpenLayers/glif.min.js');
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/OpenLayers/ol3-dlf.js');
// Add viewer library.
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/PageView/Utility.js');
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/PageView/OL3.js');
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/PageView/OL3Styles.js');
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/PageView/OL3Sources.js');
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/PageView/AltoParser.js');
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/PageView/ImageManipulationControl.js');
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/PageView/FulltextControl.js');
if ($this->doc instanceof IiifManifest) {
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/PageView/AnnotationParser.js');
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/PageView/AnnotationControl.js');
}
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/PageView/PageView.js');
// Add viewer configuration.
$markerArray = '';
// CSS files.
$cssFiles = [
'Resources/Public/Javascript/OpenLayers/ol3.css'
];
// Javascript files.
$jsFiles = [
// OpenLayers
'Resources/Public/Javascript/OpenLayers/glif.min.js',
'Resources/Public/Javascript/OpenLayers/ol3-dlf.js',
// Viewer
'Resources/Public/Javascript/PageView/Utility.js',
'Resources/Public/Javascript/PageView/OL3.js',
'Resources/Public/Javascript/PageView/OL3Styles.js',
'Resources/Public/Javascript/PageView/OL3Sources.js',
'Resources/Public/Javascript/PageView/AltoParser.js',
'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/PageView.js'
];
// Viewer configuration.
$viewerConfiguration = '
$(document).ready(function() {
if (dlfUtils.exists(dlfViewer)) {
@ -103,8 +106,24 @@ class PageView extends \Kitodo\Dlf\Common\AbstractPlugin
});
}
});
';
$pageRenderer->addJsFooterInlineCode('kitodo-pageview-configuration', $viewerConfiguration);
';
// Add Javascript to page footer if not configured otherwise.
if (empty($this->conf['addJStoBody'])) {
$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
foreach ($cssFiles as $cssFile) {
$pageRenderer->addCssFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . $cssFile);
}
foreach ($jsFiles as $jsFile) {
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . $jsFile);
}
$pageRenderer->addJsFooterInlineCode('kitodo-pageview-configuration', $viewerConfiguration);
} else {
foreach ($jsFiles as $jsFile) {
$markerArray['###JAVASCRIPT###'] .= '<script>' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . $jsFile . '</script>' . "\n";
}
$markerArray['###JAVASCRIPT###'] .= '<script>' . $viewerConfiguration . '</script>';
}
return $markerArray;
}
/**
@ -351,8 +370,8 @@ class PageView extends \Kitodo\Dlf\Common\AbstractPlugin
// Get the controls for the map.
$this->controls = explode(',', $this->conf['features']);
// Fill in the template markers.
$this->addViewerJS();
$markerArray = array_merge($this->addInteraction(), $this->addBasketForm());
$markerArray['###JAVASCRIPT###'] = $this->addViewerJS();
$content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
return $this->pi_wrapInBaseClass($content);
}

10
Configuration/Flexforms/PageView.xml

@ -84,6 +84,16 @@
</config>
</TCEforms>
</elementId>
<addJStoBody>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/PageView.xml:tt_content.pi_flexform.addJStoBody</label>
<config>
<type>check</type>
<default>0</default>
</config>
</TCEforms>
</addJStoBody>
<crop>
<TCEforms>
<exclude>1</exclude>

2
Resources/Private/Language/PageView.xml

@ -22,6 +22,7 @@
<label index="tt_content.pi_flexform.features.overviewmap">Overview Image</label>
<label index="tt_content.pi_flexform.features.zoompanel">Zoom Panel</label>
<label index="tt_content.pi_flexform.elementId">@ID value of the HTML element for the page view</label>
<label index="tt_content.pi_flexform.addJStoBody">Add Javascript files to ###JAVASCRIPT### template marker instead of page footer?</label>
<label index="tt_content.pi_flexform.templateFile">Template file</label>
<label index="tt_content.pi_flexform.useInternalProxy">Use Internal Proxy</label>
<label index="tt_content.pi_flexform.crop">Enable cropping</label>
@ -41,6 +42,7 @@
<label index="tt_content.pi_flexform.features.overviewmap">Übersichtsbild</label>
<label index="tt_content.pi_flexform.features.zoompanel">Zoom-Knöpfe</label>
<label index="tt_content.pi_flexform.elementId">@ID-Wert des HTML-Elements für die Seitenansicht</label>
<label index="tt_content.pi_flexform.addJStoBody">Javascript-Dateien im ###JAVASCRIPT### Template-Marker anstatt im Footer ausgeben?</label>
<label index="tt_content.pi_flexform.templateFile">HTML-Template</label>
<label index="tt_content.pi_flexform.useInternalProxy">Internen Proxy verwenden</label>
<label index="tt_content.pi_flexform.crop">Funktion zum Erstellen eines Bildausschnitts aktivieren</label>

1
Resources/Private/Templates/PageView.tmpl

@ -17,4 +17,5 @@
<div class="tx-dlf-navigation-editRemove">###EDITREMOVE###</div>
<div class="tx-dlf-navigation-magnifier">###MAGNIFIER###</div>
<div class="tx-dlf-interaction-addbasket">###BASKETBUTTON###</div>
###JAVASCRIPT###
<!-- ###TEMPLATE### -->

Loading…
Cancel
Save