Skip to content

Commit

Permalink
fix duplicate expand/collapse buttons in HTML
Browse files Browse the repository at this point in the history
- in ReSpec outputs, there are two sets of expand all/collapse all
  buttons as ReSpec exports the rendered HTML and the common.js code
  creates these buttons again
- this is an error, as other than the aesthetic issue of seeing
  duplicate buttons, one set of buttons doesn't work
- the fix is to remove all buttons at the start in common.js - this
  approach is better as some documents may not have these buttons if
  they are in draft mode and are not respect outputs
  • Loading branch information
coolharsh55 committed Aug 17, 2024
1 parent d98bf1b commit 1d344d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 18 additions & 1 deletion 2.0/diagrams/common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
window.addEventListener("load", () => {

// ReSpec adds duplicate buttons as it saves the rendered page. This removes those buttons.
document.querySelectorAll('.btn-hierarchy').forEach(e => e.remove());

/* --- List Hierarchy management --- */

for (let list of document.querySelectorAll(".concept-list ul li ul")) {
Expand Down Expand Up @@ -50,4 +53,18 @@ window.addEventListener("load", () => {
item.href = '#' + ref;
}
}
});
});

window.addEventListener("load", () => {
for (let aside of document.querySelectorAll(".example")) {
const div = document.createElement('button');
div.classList.add('copy-icon');
div.innerText = "copy";
aside.appendChild(div);
div.onclick = copyToClipboard;
}
});

function copyToClipboard(ele) {
navigator.clipboard.writeText(ele.target.previousElementSibling.previousElementSibling.innerText);
}
3 changes: 3 additions & 0 deletions 2.1-dev/diagrams/common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
window.addEventListener("load", () => {

// ReSpec adds duplicate buttons as it saves the rendered page. This removes those buttons.
document.querySelectorAll('.btn-hierarchy').forEach(e => e.remove());

/* --- List Hierarchy management --- */

for (let list of document.querySelectorAll(".concept-list ul li ul")) {
Expand Down

0 comments on commit 1d344d3

Please sign in to comment.