Skip to content

Commit eb21421

Browse files
rkdarstcholdgraf
andauthored
IMPROVE: Allow clicking on whole admonition title (#29)
Co-authored-by: Chris Holdgraf <[email protected]> Co-authored-by: Chris Holdgraf <[email protected]>
1 parent 063b864 commit eb21421

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

sphinx_togglebutton/_static/togglebutton.css_t

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Visibility of the target */
2-
.toggle, div.admonition.toggle .admonition-title ~ * {
2+
.toggle, .admonition.toggle .admonition-title ~ * {
33
transition: opacity .5s, height .5s;
44
}
55

@@ -14,12 +14,12 @@
1414
/* Overrides for admonition toggles */
1515

1616
/* Titles should cut off earlier to avoid overlapping w/ button */
17-
div.admonition.toggle p.admonition-title {
17+
.admonition.toggle p.admonition-title {
1818
padding-right: 25%;
1919
}
2020

2121
/* hides all the content of a page until de-toggled */
22-
div.admonition.toggle-hidden .admonition-title ~ * {
22+
.admonition.toggle-hidden .admonition-title ~ * {
2323
height: 0;
2424
margin: 0;
2525
float: left; /* so they overlap when hidden */
@@ -32,6 +32,11 @@ div.admonition.toggle-hidden .admonition-title ~ * {
3232
position: relative;
3333
}
3434

35+
/* Clicking the title will toggle the admonition, so a pointer makes this clearer */
36+
.toggle.admonition .admonition-title {
37+
cursor: pointer;
38+
}
39+
3540
.toggle.admonition.admonition-title:after {
3641
content: "" !important;
3742
}

sphinx_togglebutton/_static/togglebutton.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ var initToggleItems = () => {
2424
item.insertAdjacentHTML('beforebegin', collapseButton);
2525
}
2626

27-
thisButton = $(`#${buttonID}`);
27+
thisButton = document.getElementById(buttonID);
2828
thisButton.on('click', toggleClickHandler);
29+
// If admonition has a single direct-child title make it clickable.
30+
admonitionTitle = document.querySelector(`#${toggleID} > .admonition-title`)
31+
if (admonitionTitle) {
32+
admonitionTitle.on('click', toggleClickHandler);
33+
admonitionTitle.dataset.target = toggleID
34+
admonitionTitle.dataset.button = buttonID
35+
}
2936
if (!item.classList.contains("toggle-shown")) {
3037
toggleHidden(thisButton[0]);
3138
}

0 commit comments

Comments
 (0)