Skip to content

Commit

Permalink
fix jump-to-first ref button order
Browse files Browse the repository at this point in the history
  • Loading branch information
vincerubinetti committed Feb 4, 2021
1 parent 6201821 commit a1919a5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions build/plugins/jump-to-first.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

// start script
function start() {
if (references !== "false")
makeButtons("ref-", ":first-child", "reference");
if (references !== "false") makeButtons("ref-", "p", "reference");
if (figures !== "false") makeButtons("fig:", "figcaption", "figure");
if (tables !== "false") makeButtons("tbl:", "caption", "table");
}
Expand Down Expand Up @@ -45,15 +44,15 @@
}

// add button next to each reference entry, figure, or table
function makeButtons(query, slotQuery, subject) {
function makeButtons(query, containerQuery, subject) {
const elements = document.querySelectorAll(`[id^="${query}"`);
for (const element of elements) {
const id = element.id;
const buttonSlot = element.querySelector(slotQuery);
const buttonContainer = element.querySelector(containerQuery);
const first = getFirstOccurrence(id);

// if can't find link to reference or place to put button, ignore
if (!first || !buttonSlot) continue;
if (!first || !buttonContainer) continue;

// make jump button
let button = document.createElement("button");
Expand All @@ -63,8 +62,8 @@
button.innerHTML = icon.innerHTML;
button.dataset.id = id;
button.dataset.ignore = "true";
buttonSlot.insertBefore(button, buttonSlot.firstElementChild);
button.addEventListener("click", onButtonClick);
buttonContainer.prepend(button);
}
}

Expand Down

0 comments on commit a1919a5

Please sign in to comment.