Skip to content

Commit

Permalink
add ability to await async callback functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahAlfaraj committed Feb 22, 2023
1 parent cba77e7 commit 2f28af2
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions thumbnail.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
class Thumbnail {
static wrapImgInContainer(img, container_style_class) {
const container = document.createElement('div');
container.className = container_style_class;
container.appendChild(img);
return container;
const container = document.createElement('div')
container.className = container_style_class
container.appendChild(img)
return container
}

static addSPButtonToContainer(container, button_id, title, callbackFunction, param1) {
const elem = document.getElementById(button_id);
const clone = elem.cloneNode(true);
static addSPButtonToContainer(
container,
button_id,
title,
callbackFunction,
param1
) {
const elem = document.getElementById(button_id)
const clone = elem.cloneNode(true)
const button = clone
button.style.display = null
button.removeAttribute('id')
button.setAttribute('title', title)

// Create button element
button.className = "thumbnail-image-button";
button.addEventListener('click', () => callbackFunction(param1))
button.className = 'thumbnail-image-button'
if (callbackFunction.constructor.name === 'AsyncFunction') {
button.addEventListener(
'click',
async () => await callbackFunction(param1)
)
} else {
button.addEventListener('click', () => callbackFunction(param1))
}

container.appendChild(button)
}

}

module.exports = {
Expand Down

0 comments on commit 2f28af2

Please sign in to comment.