Skip to content

Commit 5aaa9cb

Browse files
Copilotmmcky
andcommitted
Implement single bottom bar collapse toggle for better UX
Replace separate "Show more/Show less" toggle links with integrated clickable bar at bottom of code cells. Maintains dynamic height control while providing more intuitive expand/collapse interaction. Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com>
1 parent 489ca0e commit 5aaa9cb

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/quantecon_book_theme/assets/scripts/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,34 +258,35 @@ document.addEventListener("DOMContentLoaded", function () {
258258
collapsableCodeBlocks[i].classList.forEach((el) => {
259259
collapseAccToHeight(el, collapsableCodeBlocksH);
260260
});
261-
const toggleContainer = document.createElement("div");
262-
toggleContainer.innerHTML =
263-
'<a href="#" class="toggle toggle-less" style="display:none;"><span class="icon icon-angle-double-up"></span><em>Show less...</em></a><a href="#" class="toggle toggle-more"><span class="icon icon-angle-double-down"></span><em>Show more...</em></a>';
261+
const toggleBar = document.createElement("div");
262+
toggleBar.className = "collapse-toggle-bar";
263+
toggleBar.innerHTML =
264+
'<span class="collapse-indicator">Click to expand code</span>';
264265
collapsableCodeBlocksH.parentNode.insertBefore(
265-
toggleContainer,
266+
toggleBar,
266267
collapsableCodeBlocksH.nextSibling,
267268
);
268269
}
269270

270271
const collapsableCodeToggles = document.querySelectorAll(
271-
"div[class^='cell tag_collapse'] .toggle",
272+
"div[class^='cell tag_collapse'] .collapse-toggle-bar",
272273
);
273274
for (var i = 0; i < collapsableCodeToggles.length; i++) {
274275
collapsableCodeToggles[i].addEventListener("click", function (e) {
275276
e.preventDefault();
276277
var codeBlock = this.closest('div[class^="cell tag_collapse"]');
277278
codeBlockH = codeBlock.querySelector(".highlight");
279+
var indicator = this.querySelector(".collapse-indicator");
280+
278281
if (codeBlock.classList.contains("expanded")) {
279282
codeBlock.classList.remove("expanded");
280-
this.style.display = "none";
281-
this.nextSibling.style.display = "block";
283+
indicator.textContent = "Click to expand code";
282284
codeBlock.classList.forEach((el) => {
283285
collapseAccToHeight(el, codeBlockH);
284286
});
285287
} else {
286288
codeBlock.classList.add("expanded");
287-
this.style.display = "none";
288-
this.previousSibling.style.display = "block";
289+
indicator.textContent = "Click to collapse code";
289290
codeBlockH.style.height = "auto";
290291
}
291292
});

src/quantecon_book_theme/assets/styles/index.scss

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,28 +1126,31 @@ tt {
11261126
}
11271127

11281128
div[class^="cell tag_collapse"] {
1129-
.toggle {
1129+
.collapse-toggle-bar {
11301130
display: block;
11311131
border: 1px solid #ddd;
11321132
border-width: 0px 1px 1px 1px;
11331133
padding: 0.5rem 25px;
11341134
outline: 0;
11351135
position: relative;
11361136
text-align: center;
1137+
cursor: pointer;
1138+
background-color: #f9f9f9;
1139+
transition: background-color 0.2s ease;
1140+
11371141
&:hover {
11381142
text-decoration: none;
1139-
background: #f7f7f7;
1140-
}
1141-
span {
1142-
color: #444;
1143-
position: relative;
1144-
top: 3px;
1145-
left: -5px;
1143+
background: #f0f0f0;
11461144
}
1147-
em {
1148-
font-style: normal;
1145+
1146+
.collapse-indicator {
1147+
color: #0072bc;
1148+
font-size: 0.9rem;
1149+
font-weight: 500;
1150+
user-select: none;
11491151
}
11501152
}
1153+
11511154
.highlight {
11521155
overflow: hidden;
11531156
margin-bottom: 0;

0 commit comments

Comments
 (0)