Scope TOC to article body only and use language string for title

- Move data-toc-scope from outer column to .article-content div so
  the TOC only sees headings inside the article body, ignoring page
  headers and article titles.
- Pass $scope explicitly in the JS auto-init so headings outside the
  article content are never picked up.
- Replace hardcoded article title in TOC heading with a
  TPL_MOKOCASSIOPEIA_TOC_TITLE language string ("Table of Contents").
- Add Text use statement to both toc-left.php and toc-right.php.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-04 11:28:45 -05:00
parent 93e9d3a88c
commit 81e89db88c
5 changed files with 12 additions and 7 deletions

View File

@@ -12,6 +12,7 @@ defined('_JEXEC') or die;
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
// Load Bootstrap TOC assets // Load Bootstrap TOC assets
@@ -36,13 +37,13 @@ $assocParam = (Associations::isEnabled() && $params->get('show_associations'));
<div class="col-lg-3 col-md-4 order-md-1 mb-4"> <div class="col-lg-3 col-md-4 order-md-1 mb-4">
<div class="sticky-top toc-wrapper" style="top: 20px;"> <div class="sticky-top toc-wrapper" style="top: 20px;">
<nav id="toc" data-toggle="toc" class="toc-container"> <nav id="toc" data-toggle="toc" class="toc-container">
<h5 class="toc-title"><?php echo HTMLHelper::_('string.truncate', $this->item->title, 50); ?></h5> <h5 class="toc-title"><?php echo Text::_('TPL_MOKOCASSIOPEIA_TOC_TITLE'); ?></h5>
</nav> </nav>
</div> </div>
</div> </div>
<!-- Article Content --> <!-- Article Content -->
<div class="col-lg-9 col-md-8 order-md-2" data-toc-scope> <div class="col-lg-9 col-md-8 order-md-2">
<meta itemprop="inLanguage" content="<?php echo ($this->item->language === '*') ? Factory::getApplication()->get('language') : $this->item->language; ?>" /> <meta itemprop="inLanguage" content="<?php echo ($this->item->language === '*') ? Factory::getApplication()->get('language') : $this->item->language; ?>" />
<?php if ($this->params->get('show_page_heading')) : ?> <?php if ($this->params->get('show_page_heading')) : ?>
@@ -84,7 +85,7 @@ $assocParam = (Associations::isEnabled() && $params->get('show_associations'));
<?php echo LayoutHelper::render('joomla.content.tags', $this->item->tags->itemTags); ?> <?php echo LayoutHelper::render('joomla.content.tags', $this->item->tags->itemTags); ?>
<?php endif; ?> <?php endif; ?>
<div class="article-content" itemprop="articleBody"> <div class="article-content" itemprop="articleBody" data-toc-scope>
<?php echo $this->item->text; ?> <?php echo $this->item->text; ?>
</div> </div>

View File

@@ -12,6 +12,7 @@ defined('_JEXEC') or die;
use Joomla\CMS\Factory; use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Layout\LayoutHelper;
// Load Bootstrap TOC assets // Load Bootstrap TOC assets
@@ -33,7 +34,7 @@ $assocParam = (Associations::isEnabled() && $params->get('show_associations'));
<div class="com-content-article item-page<?php echo $this->pageclass_sfx; ?>"> <div class="com-content-article item-page<?php echo $this->pageclass_sfx; ?>">
<div class="row"> <div class="row">
<!-- Article Content --> <!-- Article Content -->
<div class="col-lg-9 col-md-8 order-md-1" data-toc-scope> <div class="col-lg-9 col-md-8 order-md-1">
<meta itemprop="inLanguage" content="<?php echo ($this->item->language === '*') ? Factory::getApplication()->get('language') : $this->item->language; ?>" /> <meta itemprop="inLanguage" content="<?php echo ($this->item->language === '*') ? Factory::getApplication()->get('language') : $this->item->language; ?>" />
<?php if ($this->params->get('show_page_heading')) : ?> <?php if ($this->params->get('show_page_heading')) : ?>
@@ -75,7 +76,7 @@ $assocParam = (Associations::isEnabled() && $params->get('show_associations'));
<?php echo LayoutHelper::render('joomla.content.tags', $this->item->tags->itemTags); ?> <?php echo LayoutHelper::render('joomla.content.tags', $this->item->tags->itemTags); ?>
<?php endif; ?> <?php endif; ?>
<div class="article-content" itemprop="articleBody"> <div class="article-content" itemprop="articleBody" data-toc-scope>
<?php echo $this->item->text; ?> <?php echo $this->item->text; ?>
</div> </div>
@@ -101,7 +102,7 @@ $assocParam = (Associations::isEnabled() && $params->get('show_associations'));
<div class="col-lg-3 col-md-4 order-md-2 mb-4"> <div class="col-lg-3 col-md-4 order-md-2 mb-4">
<div class="sticky-top toc-wrapper" style="top: 20px;"> <div class="sticky-top toc-wrapper" style="top: 20px;">
<nav id="toc" data-toggle="toc" class="toc-container"> <nav id="toc" data-toggle="toc" class="toc-container">
<h5 class="toc-title"><?php echo HTMLHelper::_('string.truncate', $this->item->title, 50); ?></h5> <h5 class="toc-title"><?php echo Text::_('TPL_MOKOCASSIOPEIA_TOC_TITLE'); ?></h5>
</nav> </nav>
</div> </div>
</div> </div>

View File

@@ -66,6 +66,7 @@ TPL_MOKOCASSIOPEIA_FONT_NOTE_TEXT="Loading fonts from external sources might be
; ===== Header & navigation (Theme tab) ===== ; ===== Header & navigation (Theme tab) =====
TPL_MOKOCASSIOPEIA_STICKY_LABEL="Sticky Header" TPL_MOKOCASSIOPEIA_STICKY_LABEL="Sticky Header"
TPL_MOKOCASSIOPEIA_BACKTOTOP="Back to Top" TPL_MOKOCASSIOPEIA_BACKTOTOP="Back to Top"
TPL_MOKOCASSIOPEIA_TOC_TITLE="Table of Contents"
TPL_MOKOCASSIOPEIA_BACKTOTOP_LABEL="Back-to-top Link" TPL_MOKOCASSIOPEIA_BACKTOTOP_LABEL="Back-to-top Link"
TPL_MOKOCASSIOPEIA_TOC="Table of Contents" TPL_MOKOCASSIOPEIA_TOC="Table of Contents"

View File

@@ -66,6 +66,7 @@ TPL_MOKOCASSIOPEIA_FONT_NOTE_TEXT="Loading fonts from external sources might be
; ===== Header & navigation (Theme tab) ===== ; ===== Header & navigation (Theme tab) =====
TPL_MOKOCASSIOPEIA_STICKY_LABEL="Sticky Header" TPL_MOKOCASSIOPEIA_STICKY_LABEL="Sticky Header"
TPL_MOKOCASSIOPEIA_BACKTOTOP="Back to Top" TPL_MOKOCASSIOPEIA_BACKTOTOP="Back to Top"
TPL_MOKOCASSIOPEIA_TOC_TITLE="Table of Contents"
TPL_MOKOCASSIOPEIA_BACKTOTOP_LABEL="Back-to-top Link" TPL_MOKOCASSIOPEIA_BACKTOTOP_LABEL="Back-to-top Link"
TPL_MOKOCASSIOPEIA_TOC="Table of Contents" TPL_MOKOCASSIOPEIA_TOC="Table of Contents"

View File

@@ -178,7 +178,8 @@
$(function() { $(function() {
$('nav[data-toggle="toc"]').each(function(i, el) { $('nav[data-toggle="toc"]').each(function(i, el) {
var $nav = $(el); var $nav = $(el);
Toc.init($nav); var $scope = $('[data-toc-scope]');
Toc.init({ $nav: $nav, $scope: $scope.length ? $scope : $(document.body) });
}); });
}); });
})(jQuery); })(jQuery);