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

"Jean-Marc Kadimba \(@jmkadimba\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6978602143def_3b183cec840e7@gitlab-sidekiq-low-urgency-cpu-bound-v2-5f545cf475-z7h6v.mail>

Jean-Marc Kadimba pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
33d15eb0 by Yves Ngalamulume at 2026-01-27T08:41:49+02:00
[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

- - - - -


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/33d15eb068df1d08212f07d57b7ad384a86cdfde

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/33d15eb068df1d08212f07d57b7ad384a86cdfde
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.