diff --git a/helper/syntax.php b/helper/syntax.php index 3937340..fffe2c8 100644 --- a/helper/syntax.php +++ b/helper/syntax.php @@ -215,10 +215,10 @@ public function renderList($pages, $flags, $pagelistflags) * * @param array $flags array with (all optional): * multi, chosen, tagimage, pagesearch, cacheage, nocache, rsort, nolabels, noneonclear, tagimagecolumn, - * tagcolumn, excludeNs, withTags, excludeTags, images, count, tagintersect, sortbypageid + * tagcolumn, excludeNs, withTags, excludeTags, images, count, tagintersect, sortbypageid, include * @return array tagfilter flags with: * multi, chosen, tagimage, pagesearch, pagesearchlabel, cache, rsort, labels, noneonclear, tagimagecolumn, - * tagcolumn (optional), excludeNs, withTags, excludeTags, images, count, tagintersect, sortbypageid + * tagcolumn (optional), excludeNs, withTags, excludeTags, images, count, tagintersect, sortbypageid, include */ public function parseFlags($flags) { @@ -239,7 +239,8 @@ public function parseFlags($flags) 'images' => false, 'count' => false, 'tagintersect' => false, - 'sortbypageid' => false + 'sortbypageid' => false, + 'include' => [], ]; if (!is_array($flags)) { return $conf; @@ -307,6 +308,9 @@ public function parseFlags($flags) case 'sortbypageid': $conf['sortbypageid'] = true; break; + case 'include': + $conf['include'] = explode(';', $value); + break; } } diff --git a/script.js b/script.js index 61ade40..4e6e8ff 100644 --- a/script.js +++ b/script.js @@ -90,80 +90,49 @@ function tagfilter_submit(id,ns,flags) }); } - if(pagesearch.length == 0 && page_idx == 0) { //nothings selected => show all - - jQuery('#tagfilter_ergebnis_'+id+'.tagfilter > ul li').each(function (){ - if(flags[1]['noneonclear']) { - var $tr = jQuery(this); - $tr.hide(); - } else { - jQuery(this).show(); - } - - }); - - jQuery('#tagfilter_ergebnis_'+id+'.tagfilter table tr').each(function (){ - if(flags[1]['noneonclear']) { - var $tr = jQuery(this); - var $link = $tr.find('td.page a'); - if($link.length == 0) { - $tr.show(); - return; - } - $tr.hide(); - } else { - jQuery(this).show(); - } - }); + let pages_filtered = pages.length == 0 ? [] : pages.reduce( + (accumulator, currentValue) => accumulator.filter(elt => currentValue.includes(elt)) + ); - } else { - - var pages_filtered = new Array(); - pages_filtered = pages.shift(); - jQuery.each(pages,function(index,page_r) { //intersect pages - pages_filtered = jQuery(pages_filtered).filter(page_r); - }); - - if(page_idx == 0 && pagesearch.length != 0) { + if (pagesearch.length != 0) { + if(page_idx == 0) { pages_filtered = pagesearch; - } else if (pagesearch.length != 0) { //intersect pagesearch - pages_filtered = jQuery(pages_filtered).filter(pagesearch); + } else { //intersect pagesearch + pages_filtered = pages_filtered.filter(elt => pagesearch.includes(elt)); } - - - //loop all found searchentries - jQuery('#tagfilter_ergebnis_'+id+'.tagfilter > ul li').each(function (e){ - var $tr = jQuery(this); - var $link = $tr.find('a'); - if($link.length == 0) { - $tr.show(); - return; - } - var id = $link.attr('title'); - - if(jQuery.inArray(id,pages_filtered) == -1) { - $tr.hide(); - } else { - $tr.show(); - } - }); - jQuery('#tagfilter_ergebnis_'+id+'.tagfilter table tr').each(function (){ - var $tr = jQuery(this); - var $link = $tr.find('a'); - if($link.length == 0) { - $tr.show(); - return; - } - var id = $link.attr('title'); - - if(jQuery.inArray(id,pages_filtered) == -1) { - $tr.hide(); - } else { - $tr.show(); - } - }); } + + const presentAll = pagesearch.length == 0 && page_idx == 0 && !flags[1]['noneonclear']; + + //loop all found searchentries + document + .querySelectorAll(` + #tagfilter_ergebnis_${id}.tagfilter > ul > li, + #tagfilter_ergebnis_${id}.tagfilter > div.table > table.inline tr, + #tagfilter_ergebnis_${id}.tagfilter > div.plugin_include_content + `) + .forEach(elt => { + let pageId; + switch(elt.nodeName) { + case 'DIV': // handling for include plugin + const prefix = 'plugin_include__'; + pageId = Array.from(elt.classList) + .filter(a => a.startsWith(prefix))[0] + .substring(prefix.length); + break; + case 'TR': // handling for pagelist plugin, style=table + case 'LI': // handling for pagelist plugin, style=simplelist + pageId = elt.querySelector('a')?.title; + break; + default: + throw new Error('Unexpected element:' + elt.nodeName); + } + + elt.style.display = (presentAll || pages_filtered.includes(pageId)) ? '' : 'none'; + }); + + if(flags[1]['count']) { if(jQuery('#tagfilter_ergebnis_'+id+' tr > td[class=page]').length > 0) { jQuery('#__tagfilter_'+id).find('.tagfilter_count_number').text( diff --git a/syntax/filter.php b/syntax/filter.php index f07065a..f68aa2d 100644 --- a/syntax/filter.php +++ b/syntax/filter.php @@ -215,15 +215,32 @@ public function render($format, Doku_Renderer $renderer, $opt) } } + if (empty($flags['include'])) { + if (!$htmlPerUserCache->useCache(['files' => [$filterDataCache->cache]])) { + $html = $this->htmlOutput($tagFilters, $allPageids, $preparedPages, $opt); + $htmlPerUserCache->storeCache($html); + } else { + $html = $htmlPerUserCache->retrieveCache(); + } - if (!$htmlPerUserCache->useCache(['files' => [$filterDataCache->cache]])) { - $html = $this->htmlOutput($tagFilters, $allPageids, $preparedPages, $opt); - $htmlPerUserCache->storeCache($html); + $renderer->doc .= $html; } else { - $html = $htmlPerUserCache->retrieveCache(); - } + // Use include plugin. Does not use the htmlPerUserCache. TODO? + + // attention: htmlPrepareOutput modifies $tagFilters, $allPageids, $preparedPages. + $this->htmlPrepareOutput($tagFilters, $allPageids, $preparedPages, $opt); + $renderer->doc .= $this->htmlFormOutput($tagFilters, $allPageids, $opt); + $renderer->doc .= "
"; - $renderer->doc .= $html; + $includeHelper = $this->loadHelper('include'); + $includeFlags = $includeHelper->get_flags($flags['include']); + + foreach($preparedPages as $page) { + $renderer->nest($includeHelper->_get_instructions($page['id'], '', 'page', 0, $includeFlags)); + } + + $renderer->doc .= "
"; + } } return true; } @@ -238,14 +255,20 @@ public function render($format, Doku_Renderer $renderer, $opt) * @return string */ private function htmlOutput($tagFilters, $allPageids, $preparedPages, array $opt) + { + // attention: htmlPrepareOutput modifies $tagFilters, $allPageids, $preparedPages. + $this->htmlPrepareOutput($tagFilters, $allPageids, $preparedPages, $opt); + + $output = $this->htmlFormOutput($tagFilters, $allPageids, $opt) + . $this->htmlPagelistOutput($preparedPages, $opt); + + return $output; + } + + private function htmlPrepareOutput(&$tagFilters, &$allPageids, &$preparedPages, array $opt) { /* @var helper_plugin_tagfilter $Htagfilter */ $Htagfilter = $this->loadHelper('tagfilter'); - /* @var helper_plugin_tagfilter_syntax $HtagfilterSyntax */ - $HtagfilterSyntax = $this->loadHelper('tagfilter_syntax'); - $flags = $opt['tagfilterFlags']; - - $output = ''; //check for read access foreach ($allPageids as $key => $pageid) { @@ -272,6 +295,14 @@ private function htmlOutput($tagFilters, $allPageids, $preparedPages, array $opt unset($preparedPages[$key]); } } + } + + private function htmlFormOutput($tagFilters, $allPageids, array $opt) { + /* @var helper_plugin_tagfilter $Htagfilter */ + $Htagfilter = $this->loadHelper('tagfilter'); + + $flags = $opt['tagfilterFlags']; + $output = ''; $form = new Doku_Form([ 'id' => 'tagdd_' . $opt['id'], @@ -386,12 +417,20 @@ private function htmlOutput($tagFilters, $allPageids, $preparedPages, array $opt $form->endFieldset(); $output .= $form->getForm();//Form Ausgeben + return $output; + } + + private function htmlPagelistOutput($preparedPages, array $opt) { + /* @var helper_plugin_tagfilter_syntax $HtagfilterSyntax */ + $HtagfilterSyntax = $this->loadHelper('tagfilter_syntax'); + + $output = ''; + $output .= "
"; //dbg($opt['pagelistFlags']); - $output .= $HtagfilterSyntax->renderList($preparedPages, $flags, $opt['pagelistFlags']); + $output .= $HtagfilterSyntax->renderList($preparedPages, $opt['tagfilterFlags'], $opt['pagelistFlags']); $output .= "
"; return $output; } - }