add onEdit function for js and rework token-counter.js to use it

This commit is contained in:
AUTOMATIC1111
2023-10-01 10:15:23 +03:00
parent 7026b96476
commit c7e810a985
3 changed files with 27 additions and 17 deletions

View File

@@ -366,3 +366,20 @@ function switchWidthHeight(tabname) {
updateInput(height);
return [];
}
var onEditTimers = {};
// calls func after afterMs milliseconds has passed since the input elem has beed enited by user
function onEdit(editId, elem, afterMs, func) {
var edited = function() {
var existingTimer = onEditTimers[editId];
if (existingTimer) clearTimeout(existingTimer);
onEditTimers[editId] = setTimeout(func, afterMs);
};
elem.addEventListener("input", edited);
return edited;
}