Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
toc_js
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
toc_js
Merge requests
!39
Issue
#3521869
by mably, thamas: Allow usage of a CSS variable for the sticky offset setting
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3521869
by mably, thamas: Allow usage of a CSS variable for the sticky offset setting
issue/toc_js-3521869:3521869-allow-usage-of
into
3.x
Overview
0
Commits
2
Pipelines
4
Changes
5
Merged
Frank Mably
requested to merge
issue/toc_js-3521869:3521869-allow-usage-of
into
3.x
2 months ago
Overview
0
Commits
2
Pipelines
4
Changes
5
Expand
Closes
#3521869
0
0
Merge request reports
Compare
3.x
version 3
8917b205
2 months ago
version 2
07c137f1
2 months ago
version 1
7a4bc85d
2 months ago
3.x (base)
and
latest version
latest version
65b040c9
2 commits,
2 months ago
version 3
8917b205
2 commits,
2 months ago
version 2
07c137f1
2 commits,
2 months ago
version 1
7a4bc85d
1 commit,
2 months ago
5 files
+
78
−
52
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
assets/js/tocjs.js
+
2
−
44
Options
@@ -314,39 +314,6 @@
return
1
;
}
/**
* Retrieves the value of a CSS property from a CSS variable.
*
* If the CSS variable contains a fallback value, it will be used
* if the CSS variable is not defined.
*
* @param {string} styleValueSetting - The value of the CSS variable or a string containing `var(--variable, fallback)`.
* @param {string} [containerSelector='body'] - The selector for the container element to retrieve the CSS variable from.
* @return {string} - The value of the CSS property or the fallback value if defined.
*/
function
getStyleValueFromCssProperty
(
styleValueSetting
,
containerSelector
=
'
body
'
,
)
{
let
styleValue
=
styleValueSetting
;
// Check if it's a CSS variable reference with optional fallback.
const
variableMatch
=
styleValueSetting
.
match
(
/^var
\((
--
[
a-zA-Z0-9-_
]
+
)(?:
,
\s
*
([^
)
]
+
))?\)
$/
,
);
if
(
variableMatch
)
{
const
propertyName
=
variableMatch
[
1
];
const
fallback
=
variableMatch
[
2
]?.
trim
();
const
container
=
document
.
querySelector
(
containerSelector
);
styleValue
=
getComputedStyle
(
container
)
.
getPropertyValue
(
propertyName
)
.
trim
();
if
(
!
styleValue
&&
fallback
)
{
styleValue
=
fallback
;
}
}
return
styleValue
;
}
/**
* @param {TocObject} tocObj - The tocObj object.
*/
@@ -360,15 +327,6 @@
$tocNav
.
find
(
'
ul
'
).
remove
();
let
lastLi
=
$tocNav
[
0
];
// Determine scroll offset.
let
scrollToOffset
;
if
(
opts
.
scrollToOffset
)
{
scrollToOffset
=
getStyleValueFromCssProperty
(
opts
.
scrollToOffset
,
opts
.
container
||
'
body
'
,
);
}
$headings
.
each
((
i
,
heading
)
=>
{
// Skip invisible headings if specified in configuration.
if
(
opts
.
skipInvisibleHeadings
)
{
@@ -385,8 +343,8 @@
}
// Apply scroll offset.
if
(
scrollToOffset
)
{
heading
.
style
.
scrollMarginTop
=
scrollToOffset
;
if
(
opts
.
scrollToOffset
)
{
heading
.
style
.
scrollMarginTop
=
opts
.
scrollToOffset
;
}
// build TOC item
Loading