Add maxheight for listings
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled

This commit is contained in:
2026-01-06 09:14:40 +01:00
parent 490a483df1
commit 9664dbb256
3 changed files with 75 additions and 17 deletions

View File

@@ -27,15 +27,11 @@ class Output
public function renderAsList($params)
{
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
$this->renderer->doc .= '<div class="filetools-plugin">';
}
$this->openContainer($params);
$this->renderListItems($this->files, $params);
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
$this->renderer->doc .= '</div>';
}
$this->closeContainer();
}
/**
@@ -79,16 +75,12 @@ class Output
*/
public function renderAsTable($params)
{
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
$this->renderer->doc .= '<div class="filetools-plugin">';
}
$this->openContainer($params);
$items = $this->flattenResultTree($this->files);
$this->renderTableItems($items, $params);
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
$this->renderer->doc .= '</div>';
}
$this->closeContainer();
}
/**
@@ -99,15 +91,53 @@ class Output
*/
public function renderAsFlatTable($params)
{
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
$this->renderer->doc .= '<div class="filetools-plugin">';
}
$this->openContainer($params);
$this->renderTableItems($this->files, $params);
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
$this->closeContainer();
}
/**
* Open the wrapping container with an optional max-height and scroll behaviour.
*/
protected function openContainer($params): void
{
if (!($this->renderer instanceof \Doku_Renderer_xhtml)) {
return;
}
$style = $this->containerStyle($params);
$this->renderer->doc .= '<div class="filetools-plugin"' . $style . '>';
}
/**
* Close the wrapping container if XHTML renderer is in use.
*/
protected function closeContainer(): void
{
if (!($this->renderer instanceof \Doku_Renderer_xhtml)) {
return;
}
$this->renderer->doc .= '</div>';
}
/**
* Build the inline style attribute for the container based on the maxheight param.
*/
protected function containerStyle($params): string
{
if (!isset($params['maxheight'])) {
return '';
}
$maxHeight = (int)$params['maxheight'];
if ($maxHeight < 0) {
return '';
}
return ' style="max-height: ' . $maxHeight . 'px; overflow-y: auto;"';
}

View File

@@ -193,6 +193,33 @@ class plugin_luxtools_test extends DokuWikiTest
$this->structureCheck($doc, $structure);
}
public function test_default_maxheight_applies_scroll()
{
$instructions = p_get_instructions('{{files>' . TMP_DIR . '/filelistdata/*&style=list&direct=1&recursive=1}}');
$xhtml = p_render('xhtml', $instructions, $info);
$doc = new Document();
$doc->html($xhtml);
$style = (string)$doc->find('div.filetools-plugin')->attr('style');
$this->assertStringContainsString('max-height: 500px', $style);
$this->assertStringContainsString('overflow-y: auto', $style);
}
public function test_maxheight_can_be_disabled()
{
$instructions = p_get_instructions('{{files>' . TMP_DIR . '/filelistdata/*&style=table&direct=1&recursive=1&maxheight=-1}}');
$xhtml = p_render('xhtml', $instructions, $info);
$doc = new Document();
$doc->html($xhtml);
$style = $doc->find('div.filetools-plugin')->attr('style');
$this->assertTrue($style === null || $style === '');
}
/**
* This function checks that the images syntax renders a thumbnail gallery.
*/

View File

@@ -139,6 +139,7 @@ abstract class syntax_plugin_luxtools_abstract extends SyntaxPlugin
'showsize' => 0,
'showdate' => 0,
'listsep' => ', ',
'maxheight' => 500,
];
// Merge with handler-specific defaults