when adding tooltips, do not scan whole document and instead only scan added elements

This commit is contained in:
AUTOMATIC 2023-05-17 18:26:46 +03:00
parent 3c81d184c0
commit 216b0fa6c9

View File

@ -115,9 +115,7 @@ titles = {
"Negative Guidance minimum sigma": "Skip negative prompt for steps where image is already mostly denoised; the higher this value, the more skips there will be; provides increased performance in exchange for minor quality reduction."
}
onUiUpdate(function(){
gradioApp().querySelectorAll('span, button, select, p').forEach(function(span){
function updateTooltipForSpan(span){
if (span.title) return; // already has a title
let tooltip = localization[titles[span.textContent]] || titles[span.textContent];
@ -138,13 +136,32 @@ onUiUpdate(function(){
if(tooltip){
span.title = tooltip;
}
})
}
gradioApp().querySelectorAll('select').forEach(function(select){
function updateTooltipForSelect(select){
if (select.onchange != null) return;
select.onchange = function(){
select.title = localization[titles[select.value]] || titles[select.value] || "";
}
}
observedTooltipElements = {"SPAN": 1, "BUTTON": 1, "SELECT": 1, "P": 1}
onUiUpdate(function(m){
m.forEach(function(record){
record.addedNodes.forEach(function(node){
if(observedTooltipElements[node.tagName]){
updateTooltipForSpan(node)
}
if(node.tagName == "SELECT"){
updateTooltipForSelect(node)
}
if(node.querySelectorAll){
node.querySelectorAll('span, button, select, p').forEach(updateTooltipForSpan)
node.querySelectorAll('select').forEach(updateTooltipForSelect)
}
})
})
})