[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [FIX] AutoTOC invalid heading IDs breaking ScrollSpy

"Jean-Marc Kadimba \(@jmkadimba\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <697a17fed65e7_3b2c13e94278ad@gitlab-sidekiq-low-urgency-cpu-bound-v2-866b69f9fb-t6hvv.mail>

Jean-Marc Kadimba pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
e78dc255 by Yves Ngalamulume at 2026-01-28T15:57:49+02:00
[FIX] AutoTOC invalid heading IDs breaking ScrollSpy
---
* [FIX] AutoTOC invalid heading IDs breaking ScrollSpy
---
* [FIX] AutoTOC invalid heading IDs breaking ScrollSpy

* [FIX] AutoTOC invalid heading IDs breaking ScrollSpy

See merge request tikiwiki/tiki!9381

See merge request tikiwiki/tiki!9414

- - - - -


1 changed file:

- lib/jquery_tiki/autoToc.js


Changes:

=====================================
lib/jquery_tiki/autoToc.js
=====================================
@@ -157,8 +157,16 @@ $.genAutoToc = function () {
                     var id = children[i].getAttribute("id");
 
                     if (!id) {
-                        id = processId(headerText.replace(/\W/g, "_"));
+                        id = headerText;
                     }
+                    //process the id to make it valid
+                    id = processId(
+                        id
+                            .toLowerCase()
+                            .trim()
+                            .replace(/[^\w\- ]+/g, '')  // remove invalid chars (., :, accents, etc.)
+                            .replace(/\s+/g, '_')       // spaces  _
+                    );
                     //set the element's id to the constructed ID
                     children[i].setAttribute("id", id);
                     //construct the anchor URL with chars jquery doesn't like escaped
@@ -328,26 +336,38 @@ function countHeadings(children) {
 $(function () {
     $.genAutoToc();
     $('#autotoc').on('click', 'a[href^="#"]', function (e) {
+        var target = this.hash;
+        var $target = $(target);
+
+        if (! $target.length) {
+            return;
+        }
+
         e.preventDefault();
+
+        // Update active state
         $('#autotoc a').removeClass('active');
         $(this).addClass('active');
+
         $('#autotoc li').removeClass('open');
         $(this).parents('li').addClass('open');
 
-        var target = this.hash;
-        var $target = $(target);
-
-        if ($target.length) {
-            if (typeof parentNode !== 'undefined') {
-                var parent = document.querySelector(target).parentNode;
-                $('.tabs a[href="#' + parent.id + '"]').tab('show');
-            }
-
-            $('html, body').stop().animate({
+        // If inside tabs, ensure tab is shown before scrolling
+        var parent = $target.closest('.tab-pane');
+        if (parent.length) {
+            $('.tabs a[href="#' + parent.attr('id') + '"]').tab('show');
+
+            // Delay scroll until tab is visible
+            setTimeout(function () {
+                $('html, body').animate({
+                    scrollTop: $target.offset().top
+                }, 400);
+            }, 50);
+        } else {
+            $('html, body').animate({
                 scrollTop: $target.offset().top
-            }, 900, function() {
-                window.location.hash = target;
-            });
+            }, 400);
         }
     });
+
 });



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e78dc255ff7a35672b489d241acd1d63186e3e12

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e78dc255ff7a35672b489d241acd1d63186e3e12
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.