Files
foundryvtt-reve-de-dragon/templates/scripts/autocomplete-script.hbs
T
fabres a5843888c0 fix: migration V14 et corrections diverses
migration v14:
- remplace CONFIG.Dice.rollModes → CONFIG.ChatMessage.modes
- canvas optionnel (?.tokens) dans ~27 fichiers
- async/await migrations, waitForRoll, effet draconique
- supprime _warnedAppV1, data-message-id→data-document-id
- corrige sheet registration Items.registerSheet

tmr:
- bouton Lancer un Sort visible en mode visu
- _ensureTMRButtons() en fallback JS
- await d'animation avant render
- corrigé doublon carteTMR.js

css:
- scrollbar (.item-sheet-scrollable-body) sur les 44 fiches item
- normalisation multiligne de tous les less/item/*.less
- style du dialogue description aléatoire (app-personnage-aleatoire)
- hr-sorts et sort réserves en flex-row

dialogue description:
- type=button sur les boutons (évite submit form → crash)
- randomControl passe this.actor au lieu de this.current
- DEFINITION_HEURES : ajout propriété manquante heure

d意:
- supprime 6 fichiers debug (phase*.txt/png, sheets-*.txt/png)
- system.json nom anglais→français
- token-hud : guard token undefined
- item-sort.js : guard sort?.system dans helpers Handlebars
2026-07-22 00:29:56 +02:00

99 lines
3.3 KiB
Handlebars

<script>
function autocomplete(input, proposals) {
var currentFocus;
function createCompletionContainer(id) {
let div = document.createElement("DIV");
div.setAttribute("id", id + "autocomplete-list");
div.setAttribute("class", "autocomplete-items");
return div;
}
function createCompletionProposal(inputElement, incomplete, complete) {
let div = document.createElement("DIV");
const start = complete.toUpperCase().indexOf(incomplete.toUpperCase());
div.appendChild(document.createTextNode(complete.substr(0, start)));
const strong = document.createElement("strong");
strong.textContent = complete.substr(start, incomplete.length);
div.appendChild(strong);
div.appendChild(document.createTextNode(complete.substr(start + incomplete.length)));
const hidden = document.createElement("input");
hidden.type = "hidden";
hidden.value = complete;
div.appendChild(hidden);
div.addEventListener("click", function(e) {
inputElement.value = this.getElementsByTagName("input")[0].value;
closeAllOpenedLists();
});
return div;
}
function addActive(x) {
if (!x) return false;
removeActive(x);
if (currentFocus >= x.length) currentFocus = 0;
if (currentFocus < 0) currentFocus = (x.length - 1);
x[currentFocus].classList.add("autocomplete-active");
}
function removeActive(x) {
for (var i = 0; i < x.length; i++) {
x[i].classList.remove("autocomplete-active");
}
}
function closeAllOpenedLists(elmnt) {
/*close all autocomplete lists in the document, except the one passed as an argument:*/
var x = document.getElementsByClassName("autocomplete-items");
for (var i = 0; i < x.length; i++) {
if (elmnt != x[i] && elmnt != input) {
x[i].parentNode.removeChild(x[i]);
}
}
}
/*execute a function when someone writes in the text field:*/
input.addEventListener("input", function(e) {
const incomplete = this.value;
closeAllOpenedLists();
if (!incomplete) { return false; }
currentFocus = -1;
const container = createCompletionContainer(this.id)
this.parentNode.appendChild(container);
/*for each item in the array...*/
for (let i = 0; i < proposals.length; i++) {
/*check if the item starts with the same letters as the text field value:*/
if (proposals[i].toUpperCase().includes(incomplete.toUpperCase())) {
/*create a DIV element for each matching element:*/
container.appendChild(createCompletionProposal(input, incomplete, proposals[i]));
}
}
});
/*execute a function presses a key on the keyboard:*/
input.addEventListener("keydown", function(e) {
var container = document.getElementById(this.id + "autocomplete-list")?.getElementsByTagName("div");
if (e.keyCode == 40) {
currentFocus++;
addActive(container);
} else if (e.keyCode == 38) { //up
currentFocus--;
addActive(container);
} else if (e.keyCode == 13) {
if (currentFocus > -1 && container) {
container[currentFocus].click();
}
}
});
/*execute a function when someone clicks in the document:*/
if (!autocomplete._listenerAdded) {
document.addEventListener("click", function (e) {
closeAllOpenedLists(e.target);
});
autocomplete._listenerAdded = true;
}
}
</script>