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

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

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


Commits:
d6161b5f by Yves Ngalamulume at 2026-01-29T09:18:32+02:00
[BP][FIX] AutoTOC invalid heading IDs breaking ScrollSpy
---
* [BP][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

* [FIX] AutoTOC invalid heading IDs breaking ScrollSpy

See merge request tikiwiki/tiki!9381

See merge request tikiwiki/tiki!9414

See merge request tikiwiki/tiki!9429

See merge request tikiwiki/tiki!9435

- - - - -


1 changed file:

- lib/jquery_tiki/autoToc.js


Changes:

=====================================
lib/jquery_tiki/autoToc.js
=====================================
@@ -144,8 +144,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
@@ -315,17 +323,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 (typeof parentNode !== 'undefined') {
-            var parent = document.querySelector(target).parentNode;
-            $('.tabs a[href="#'+parent.id+'"]').tab('show');
+        // 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
+            }, 400);
         }
     });
-});
\ No newline at end of file
+
+});



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

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