add ability to await async callback functions
parent
cba77e73e1
commit
2f28af29dd
33
thumbnail.js
33
thumbnail.js
|
|
@ -1,25 +1,38 @@
|
||||||
class Thumbnail {
|
class Thumbnail {
|
||||||
static wrapImgInContainer(img, container_style_class) {
|
static wrapImgInContainer(img, container_style_class) {
|
||||||
const container = document.createElement('div');
|
const container = document.createElement('div')
|
||||||
container.className = container_style_class;
|
container.className = container_style_class
|
||||||
container.appendChild(img);
|
container.appendChild(img)
|
||||||
return container;
|
return container
|
||||||
}
|
}
|
||||||
|
|
||||||
static addSPButtonToContainer(container, button_id, title, callbackFunction, param1) {
|
static addSPButtonToContainer(
|
||||||
const elem = document.getElementById(button_id);
|
container,
|
||||||
const clone = elem.cloneNode(true);
|
button_id,
|
||||||
|
title,
|
||||||
|
callbackFunction,
|
||||||
|
param1
|
||||||
|
) {
|
||||||
|
const elem = document.getElementById(button_id)
|
||||||
|
const clone = elem.cloneNode(true)
|
||||||
const button = clone
|
const button = clone
|
||||||
button.style.display = null
|
button.style.display = null
|
||||||
button.removeAttribute('id')
|
button.removeAttribute('id')
|
||||||
button.setAttribute('title', title)
|
button.setAttribute('title', title)
|
||||||
|
|
||||||
// Create button element
|
// Create button element
|
||||||
button.className = "thumbnail-image-button";
|
button.className = 'thumbnail-image-button'
|
||||||
button.addEventListener('click', () => callbackFunction(param1))
|
if (callbackFunction.constructor.name === 'AsyncFunction') {
|
||||||
|
button.addEventListener(
|
||||||
|
'click',
|
||||||
|
async () => await callbackFunction(param1)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
button.addEventListener('click', () => callbackFunction(param1))
|
||||||
|
}
|
||||||
|
|
||||||
container.appendChild(button)
|
container.appendChild(button)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue