Allow plugin buttons for image overlay to decide whether they should be displayed or not

This commit is contained in:
cmdr2
2022-10-19 20:10:45 +05:30
parent 5fa3a7ca44
commit af05d94198
2 changed files with 14 additions and 2 deletions

View File

@ -381,18 +381,25 @@ function showImages(reqBody, res, outputContainer, livePreview) {
Object.assign(buttons, PLUGINS['IMAGE_INFO_BUTTONS'])
const imgItemInfo = imageItemElem.querySelector('.imgItemInfo')
const img = imageItemElem.querySelector('img')
const createButton = function(name, btnInfo) {
const newButton = document.createElement('button')
newButton.classList.add(name)
newButton.classList.add('tasksBtns')
newButton.innerText = btnInfo.text
newButton.addEventListener('click', function() {
let img = imageItemElem.querySelector('img')
btnInfo.on_click(req, img)
})
imgItemInfo.appendChild(newButton)
}
Object.keys(buttons).forEach((name) => createButton(name, buttons[name]))
Object.keys(buttons).forEach((name) => {
const btn = buttons[name]
if (btn.filter && btn.filter(req, img) === false) {
return
}
createButton(name, btn)
})
}
})
}