diff --git a/Note Types/AnKing MCAT/Back Template.html b/Note Types/AnKing MCAT/Back Template.html
index 1dcd78b5..e726e97f 100644
--- a/Note Types/AnKing MCAT/Back Template.html
+++ b/Note Types/AnKing MCAT/Back Template.html
@@ -1,4 +1,4 @@
-
+
-
diff --git a/Note Types/AnKingDerm/Front Template.html b/Note Types/AnKingDerm/Front Template.html
index 95a1a931..9271cfbd 100644
--- a/Note Types/AnKingDerm/Front Template.html
+++ b/Note Types/AnKingDerm/Front Template.html
@@ -1,4 +1,4 @@
-
+
{{cloze:Text}}
@@ -300,7 +300,7 @@
(() => {
const selectors = [".shuffle"];
const shuffleMap = Persistence.getItem("shuffle") || {};
- const shuffledWordClass = "shuffled-word";
+ const containerSelector = selectors.join(", ");
function isFront() {
const hasHrMarker = document.querySelector("hr[id=answer]");
@@ -321,14 +321,39 @@
}
}
- function shuffleElements(elements) {
+ function getNearestIdElement(element) {
+ let current = element;
+ while (current && current !== document.body) {
+ if (current.id) {
+ return current;
+ }
+ current = current.parentElement;
+ }
+ return null;
+ }
+
+ function getScopedIndex(element, selector) {
+ const scope = getNearestIdElement(element);
+ const candidates = scope
+ ? Array.from(scope.querySelectorAll(selector))
+ : Array.from(document.querySelectorAll(selector));
+ const index = candidates.indexOf(element);
+ return index === -1 ? 0 : index;
+ }
+
+ function shuffleKey(element, groupType, selector) {
+ const scope = getNearestIdElement(element);
+ const scopeKey = scope ? `${scope.tagName.toLowerCase()}#${scope.id}` : "document";
+ const index = selector ? getScopedIndex(element, selector) : 0;
+ return `${scopeKey}:${groupType}:${index}`;
+ }
+
+ function shuffleElements(elements, mapKey) {
elements = elements.filter(e => !e.matches(".no-shuffle *"));
if (elements.length === 0) {
return;
}
const shuffledElements = Array.from(elements);
- // Assuming elements[0] is not also the first element in a different list to shuffle
- const mapKey = shuffledElements[0];
const indexMap = shuffleMap[mapKey] || {};
elements = elements.map(el => {
const placeholder = document.createTextNode('');
@@ -344,7 +369,7 @@
function shuffleList(listElement) {
const items = Array.from(listElement.querySelectorAll("li"));
- shuffleElements(items);
+ shuffleElements(items, shuffleKey(listElement, "list", "ol, ul"));
}
/**
@@ -405,11 +430,12 @@
return item.replace(/,\s*(?=<\/|$)/g, '');
});
- const indexMap = shuffleMap[element] || {};
+ const mapKey = shuffleKey(element, "sentence", ".shuffle-sentence");
+ const indexMap = shuffleMap[mapKey] || {};
const itemsToShuffle = [...cleanedItems];
shuffle(itemsToShuffle, indexMap);
- shuffleMap[element] = indexMap;
+ shuffleMap[mapKey] = indexMap;
let newHTML;
if (itemsToShuffle.length === 2) {
@@ -434,7 +460,7 @@
shuffleList(parentElement);
}
const images = Array.from(container.querySelectorAll("img"));
- shuffleElements(images);
+ shuffleElements(images, shuffleKey(container, "images", containerSelector));
}
}
for (const element of document.querySelectorAll(".shuffle-sentence")) {
diff --git a/Note Types/AnKingDermPath/Back Template.html b/Note Types/AnKingDermPath/Back Template.html
index 9448a24d..d1637426 100644
--- a/Note Types/AnKingDermPath/Back Template.html
+++ b/Note Types/AnKingDermPath/Back Template.html
@@ -1,4 +1,4 @@
-
+
-
diff --git a/Note Types/AnKingDermPath/Front Template.html b/Note Types/AnKingDermPath/Front Template.html
index ef8b41f2..1210217e 100644
--- a/Note Types/AnKingDermPath/Front Template.html
+++ b/Note Types/AnKingDermPath/Front Template.html
@@ -1,4 +1,4 @@
-
+
{{edit:Front}}
Above Image(s) provided courtesy of Tammie Ferringer, MD
@@ -361,7 +361,7 @@
(() => {
const selectors = [".shuffle", "#front"];
const shuffleMap = Persistence.getItem("shuffle") || {};
- const shuffledWordClass = "shuffled-word";
+ const containerSelector = selectors.join(", ");
function isFront() {
const hasHrMarker = document.querySelector("hr[id=answer]");
@@ -382,14 +382,39 @@
}
}
- function shuffleElements(elements) {
+ function getNearestIdElement(element) {
+ let current = element;
+ while (current && current !== document.body) {
+ if (current.id) {
+ return current;
+ }
+ current = current.parentElement;
+ }
+ return null;
+ }
+
+ function getScopedIndex(element, selector) {
+ const scope = getNearestIdElement(element);
+ const candidates = scope
+ ? Array.from(scope.querySelectorAll(selector))
+ : Array.from(document.querySelectorAll(selector));
+ const index = candidates.indexOf(element);
+ return index === -1 ? 0 : index;
+ }
+
+ function shuffleKey(element, groupType, selector) {
+ const scope = getNearestIdElement(element);
+ const scopeKey = scope ? `${scope.tagName.toLowerCase()}#${scope.id}` : "document";
+ const index = selector ? getScopedIndex(element, selector) : 0;
+ return `${scopeKey}:${groupType}:${index}`;
+ }
+
+ function shuffleElements(elements, mapKey) {
elements = elements.filter(e => !e.matches(".no-shuffle *"));
if (elements.length === 0) {
return;
}
const shuffledElements = Array.from(elements);
- // Assuming elements[0] is not also the first element in a different list to shuffle
- const mapKey = shuffledElements[0];
const indexMap = shuffleMap[mapKey] || {};
elements = elements.map(el => {
const placeholder = document.createTextNode('');
@@ -405,7 +430,7 @@
function shuffleList(listElement) {
const items = Array.from(listElement.querySelectorAll("li"));
- shuffleElements(items);
+ shuffleElements(items, shuffleKey(listElement, "list", "ol, ul"));
}
/**
@@ -466,11 +491,12 @@
return item.replace(/,\s*(?=<\/|$)/g, '');
});
- const indexMap = shuffleMap[element] || {};
+ const mapKey = shuffleKey(element, "sentence", ".shuffle-sentence");
+ const indexMap = shuffleMap[mapKey] || {};
const itemsToShuffle = [...cleanedItems];
shuffle(itemsToShuffle, indexMap);
- shuffleMap[element] = indexMap;
+ shuffleMap[mapKey] = indexMap;
let newHTML;
if (itemsToShuffle.length === 2) {
@@ -495,7 +521,7 @@
shuffleList(parentElement);
}
const images = Array.from(container.querySelectorAll("img"));
- shuffleElements(images);
+ shuffleElements(images, shuffleKey(container, "images", containerSelector));
}
}
for (const element of document.querySelectorAll(".shuffle-sentence")) {
diff --git a/Note Types/AnKingOverhaul/Back Template.html b/Note Types/AnKingOverhaul/Back Template.html
index e68b8e0b..0275a17f 100644
--- a/Note Types/AnKingOverhaul/Back Template.html
+++ b/Note Types/AnKingOverhaul/Back Template.html
@@ -1,4 +1,4 @@
-
+