[TikiWiki-commits] [Git][tikiwiki/tiki][28.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 | <697afed5365d9_3b183c9c694e8@gitlab-sidekiq-low-urgency-cpu-bound-v2-5b5686f8d9-6d54l.mail> |
Jean-Marc Kadimba pushed to branch 28.x at Tiki Wiki CMS Groupware / Tiki
Commits:
42068502 by Yves Ngalamulume at 2026-01-29T08:24:58+02:00
[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
- - - - -
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/420685025f6c985f56ad5837747c36656512ed09
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/420685025f6c985f56ad5837747c36656512ed09
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