Borrow categories layout from com_contact

This commit is contained in:
Tuan Pham Ngoc 2021-07-09 23:05:55 +07:00
parent 02baa68d28
commit c2084a7ff9
2 changed files with 60 additions and 61 deletions

View File

@ -9,22 +9,22 @@
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
// Add strings for translations in Javascript.
Text::script('JGLOBAL_EXPAND_CATEGORIES');
Text::script('JGLOBAL_COLLAPSE_CATEGORIES');
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->getRegistry()->addExtensionRegistryFile('com_categories');
$wa->useScript('com_categories.shared-categories-accordion');
Factory::getDocument()->addScriptDeclaration("
jQuery(function($) {
$('.categories-list').find('[id^=category-btn-]').each(function(index, btn) {
var btn = $(btn);
btn.on('click', function() {
btn.find('span').toggleClass('icon-plus');
btn.find('span').toggleClass('icon-minus');
});
});
});");
?>
<div class="categories-list<?php echo $this->pageclass_sfx;?>">
<div class="com-weblinks-categories categories-list">
<?php
echo JLayoutHelper::render('joomla.content.categories_default', $this);
echo $this->loadTemplate('items');
echo LayoutHelper::render('joomla.content.categories_default', $this);
echo $this->loadTemplate('items');
?>
</div>

View File

@ -10,59 +10,58 @@
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
HTMLHelper::_('bootstrap.tooltip');
$class = ' class="first"';
if (count($this->items[$this->parent->id]) > 0 && $this->maxLevelcat != 0) :
if ($this->maxLevelcat != 0 && count($this->items[$this->parent->id]) > 0) :
?>
<?php foreach($this->items[$this->parent->id] as $id => $item) : ?>
<?php
if ($this->params->get('show_empty_categories_cat') || $item->numitems || count($item->getChildren())) :
if (!isset($this->items[$this->parent->id][$id + 1]))
{
$class = ' class="last"';
}
?>
<div <?php echo $class; ?> >
<?php $class = ''; ?>
<h3 class="page-header item-title">
<a href="<?php echo Route::_(RouteHelper::getCategoryRoute($item->id));?>">
<?php foreach ($this->items[$this->parent->id] as $id => $item) : ?>
<?php if ($this->params->get('show_empty_categories_cat') || $item->numitems || count($item->getChildren())) : ?>
<div class="com-weblinks-categories__items">
<h3 class="page-header item-title">
<a href="<?php echo Route::_(RouteHelper::getCategoryRoute($item->id, $item->language)); ?>">
<?php echo $this->escape($item->title); ?></a>
<?php if ($this->params->get('show_cat_num_links_cat') == 1) :?>
<span class="badge badge-info tip hasTooltip" title="<?php echo HTMLHelper::tooltipText('COM_WEBLINKS_NUM_ITEMS'); ?>">
<?php if ($this->params->get('show_cat_items_cat') == 1) :?>
<span class="badge bg-info">
<?php echo Text::_('COM_WEBLINKS_NUM_ITEMS'); ?>&nbsp;
<?php echo $item->numitems; ?>
</span>
<?php endif; ?>
<?php if (count($item->getChildren()) > 0 && $this->maxLevelcat > 1) : ?>
<a id="category-btn-<?php echo $item->id;?>" href="#category-<?php echo $item->id;?>"
data-toggle="collapse" data-toggle="button" class="btn btn-mini pull-right"><span class="icon-plus"></span></a>
<?php endif;?>
</h3>
<?php if ($this->params->get('show_subcat_desc_cat') == 1) :?>
<?php if ($item->description) : ?>
<div class="category-desc">
<?php echo HTMLHelper::_('content.prepare', $item->description, '', 'com_weblinks.categories'); ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) : ?>
<button
type="button"
id="category-btn-<?php echo $item->id; ?>"
data-bs-target="#category-<?php echo $item->id; ?>"
data-bs-toggle="collapse"
class="btn btn-secondary btn-sm float-end"
aria-label="<?php echo Text::_('JGLOBAL_EXPAND_CATEGORIES'); ?>"
>
<span class="icon-plus" aria-hidden="true"></span>
</button>
<?php endif; ?>
</h3>
<?php if ($this->params->get('show_subcat_desc_cat') == 1) : ?>
<?php if ($item->description) : ?>
<div class="category-desc">
<?php echo HTMLHelper::_('content.prepare', $item->description, '', 'com_weblinks.categories'); ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php if (count($item->getChildren()) > 0 && $this->maxLevelcat > 1) :?>
<div class="collapse fade" id="category-<?php echo $item->id;?>">
<?php
$this->items[$item->id] = $item->getChildren();
$this->parent = $item;
$this->maxLevelcat--;
echo $this->loadTemplate('items');
$this->parent = $item->getParent();
$this->maxLevelcat++;
?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if ($this->maxLevelcat > 1 && count($item->getChildren()) > 0) : ?>
<div class="collapse fade" id="category-<?php echo $item->id; ?>">
<?php
$this->items[$item->id] = $item->getChildren();
$this->parent = $item;
$this->maxLevelcat--;
echo $this->loadTemplate('items');
$this->parent = $item->getParent();
$this->maxLevelcat++;
?>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>