Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Note Types/AnKing MCAT/Back Template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- version 21d8b64 -->
<!-- version 52edd71 -->
<script>
// ############## HINT REVEAL SHORTCUTS ##############
// All shortcuts will also open with "H" if using the Hint Hotkeys add-on
Expand Down
2 changes: 1 addition & 1 deletion Note Types/AnKing MCAT/Front Template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- version 21d8b64 -->
<!-- version 52edd71 -->
<div id="text">{{cloze:Text}}</div>


Expand Down
2 changes: 1 addition & 1 deletion Note Types/AnKing/Back Template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- version 21d8b64 -->
<!-- version 52edd71 -->
<script>
// ############## HINT REVEAL SHORTCUTS ##############
// All shortcuts will also open with "H" if using the Hint Hotkeys add-on
Expand Down
2 changes: 1 addition & 1 deletion Note Types/AnKing/Front Template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- version 21d8b64 -->
<!-- version 52edd71 -->
<div id="text">{{cloze:Text}}</div>

<br>
Expand Down
2 changes: 1 addition & 1 deletion Note Types/AnKingAnkisthesia/Back Template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- version 21d8b64 -->
<!-- version 52edd71 -->
<script>
// ############## HINT REVEAL SHORTCUTS ##############
// Visit https://keycode.info/ to get the number/letter for the key you want to assign.
Expand Down
2 changes: 1 addition & 1 deletion Note Types/AnKingAnkisthesia/Front Template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- version 21d8b64 -->
<!-- version 52edd71 -->
<div id="text">{{cloze:Text}}</div>

<!-- ############## Text-to-speech ##############
Expand Down
45 changes: 35 additions & 10 deletions Note Types/AnKingDerm/Back Template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- version 21d8b64 -->
<!-- version 52edd71 -->
<script>
// ############## HINT REVEAL SHORTCUTS ##############
// All shortcuts will also open with "H" if using the Hint Hotkeys add-on
Expand Down Expand Up @@ -1115,7 +1115,7 @@
(() => {
const selectors = [".shuffle", "#dermpath,#dermoscopy,#visualdx,#dermnet,#fullspectrum,#additional"];
const shuffleMap = Persistence.getItem("shuffle") || {};
const shuffledWordClass = "shuffled-word";
const containerSelector = selectors.join(", ");

function isFront() {
const hasHrMarker = document.querySelector("hr[id=answer]");
Expand All @@ -1136,14 +1136,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('');
Expand All @@ -1159,7 +1184,7 @@

function shuffleList(listElement) {
const items = Array.from(listElement.querySelectorAll("li"));
shuffleElements(items);
shuffleElements(items, shuffleKey(listElement, "list", "ol, ul"));
}

/**
Expand Down Expand Up @@ -1220,11 +1245,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) {
Expand All @@ -1249,7 +1275,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")) {
Expand All @@ -1265,4 +1291,3 @@
</script>

<!-- END WRAPPER CODE -->

44 changes: 35 additions & 9 deletions Note Types/AnKingDerm/Front Template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- version 21d8b64 -->
<!-- version 52edd71 -->
<div id="text">{{cloze:Text}}</div>


Expand Down Expand Up @@ -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]");
Expand All @@ -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('');
Expand All @@ -344,7 +369,7 @@

function shuffleList(listElement) {
const items = Array.from(listElement.querySelectorAll("li"));
shuffleElements(items);
shuffleElements(items, shuffleKey(listElement, "list", "ol, ul"));
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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")) {
Expand Down
45 changes: 35 additions & 10 deletions Note Types/AnKingDermPath/Back Template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- version 21d8b64 -->
<!-- version 52edd71 -->
<script>
// ############## HINT REVEAL SHORTCUTS ##############
// All shortcuts will also open with "H" if using the Hint Hotkeys add-on
Expand Down Expand Up @@ -727,7 +727,7 @@
(() => {
const selectors = [".shuffle", "#front,#clinical,#dermoscopy,#visualdx,#dermnet,#fullspectrum,#additional"];
const shuffleMap = Persistence.getItem("shuffle") || {};
const shuffledWordClass = "shuffled-word";
const containerSelector = selectors.join(", ");

function isFront() {
const hasHrMarker = document.querySelector("hr[id=answer]");
Expand All @@ -748,14 +748,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('');
Expand All @@ -771,7 +796,7 @@

function shuffleList(listElement) {
const items = Array.from(listElement.querySelectorAll("li"));
shuffleElements(items);
shuffleElements(items, shuffleKey(listElement, "list", "ol, ul"));
}

/**
Expand Down Expand Up @@ -832,11 +857,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) {
Expand All @@ -861,7 +887,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")) {
Expand All @@ -877,4 +903,3 @@
</script>

<!-- END WRAPPER CODE -->

Loading
Loading