Add options to AudioPlayer

This commit is contained in:
Sebastian Meyer 2020-04-23 16:58:26 +02:00
parent 23faa46d94
commit f9dab2ec59
4 changed files with 58 additions and 22 deletions

View File

@ -37,17 +37,25 @@ class AudioPlayer extends \Kitodo\Dlf\Common\AbstractPlugin
*
* @access protected
*
* @return void
* @return string The output string for the ###JAVASCRIPT### template marker
*/
protected function addPlayerJS()
{
$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
// Add AudioPlayer library.
$pageRenderer->addCssFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/jPlayer/blue.monday/css/jplayer.blue.monday.min.css');
$pageRenderer->addCssInlineBlock('kitodo-audioplayer-configuration', '#tx-dlf-audio { width: 100px; height: 100px; }');
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/jPlayer/jquery.jplayer.min.js');
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . 'Resources/Public/Javascript/AudioPlayer/AudioPlayer.js');
// Add AudioPlayer configuration.
$markerArray = '';
// CSS files.
$cssFiles = [
'Resources/Public/Javascript/jPlayer/blue.monday/css/jplayer.blue.monday.min.css'
];
// Inline CSS.
$inlineCSS = '#tx-dlf-audio { width: 100px; height: 100px; }';
//Javascript files.
$jsFiles = [
// jPlayer
'Resources/Public/Javascript/jPlayer/jquery.jplayer.min.js',
// AudioPlayer
'Resources/Public/Javascript/AudioPlayer/AudioPlayer.js'
];
// AudioPlayer configuration.
$audioplayerConfiguration = '
$(document).ready(function() {
AudioPlayer = new dlfAudioPlayer({
@ -61,7 +69,24 @@ class AudioPlayer extends \Kitodo\Dlf\Common\AbstractPlugin
});
});
';
// 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);
}
$pageRenderer->addCssInlineBlock('kitodo-audioplayer-configuration', $inlineCSS);
foreach ($jsFiles as $jsFile) {
$pageRenderer->addJsFooterFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . $jsFile);
}
$pageRenderer->addJsFooterInlineCode('kitodo-audioplayer-configuration', $audioplayerConfiguration);
} else {
foreach ($jsFiles as $jsFile) {
$markerArray .= '<script>' . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey) . $jsFile . '</script>' . "\n";
}
$markerArray .= '<script>' . $audioplayerConfiguration . '</script>';
}
return $markerArray;
}
/**
@ -105,15 +130,13 @@ class AudioPlayer extends \Kitodo\Dlf\Common\AbstractPlugin
$this->audio['label'] = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['label'];
$this->audio['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpAudio']]);
// Add jPlayer javascript.
$this->addPlayerJS();
$markerArray['###JAVASCRIPT###'] = $this->addPlayerJS();
} else {
// Quit without doing anything if required variables are not set.
return $content;
}
// Load template file.
$this->getTemplate();
// Fill in the template markers (currently: none).
$markerArray = [];
$content .= $this->templateService->substituteMarkerArray($this->template, $markerArray);
return $this->pi_wrapInBaseClass($content);
}

View File

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

View File

@ -18,12 +18,14 @@
<label index="tt_content.pi_flexform.sheet_general">Options</label>
<label index="tt_content.pi_flexform.excludeOther">Show only documents from the selected page</label>
<label index="tt_content.pi_flexform.elementId">@ID value of the HTML element for the audio player</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>
</languageKey>
<languageKey index="de" type="array">
<label index="tt_content.pi_flexform.sheet_general">Einstellungen</label>
<label index="tt_content.pi_flexform.excludeOther">Nur Dokumente der ausgewählten Seite anzeigen</label>
<label index="tt_content.pi_flexform.elementId">@ID-Wert des HTML-Elements für den Audioplayer</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>
</languageKey>
</data>

View File

@ -9,4 +9,5 @@
-->
<!-- ###TEMPLATE### -->
<div id="tx-dlf-audio" class="tx-dlf-audio"></div>
###JAVASCRIPT###
<!-- ###TEMPLATE### -->