Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
const now = new Date().getTime();
if (!previous && options.leading === false) previous = now;
const remaining = wait - (now - previous);
context = this;

Check warning on line 273 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected aliasing of 'this' to local variable
if (remaining <= 0) {
clearTimeout(timeout);
timeout = null;
Expand All @@ -283,4 +283,46 @@
return result;
};
}

/**
* Renders confirm/close buttons with callback function
*/
static createConfirmationContainer(
container: HTMLElement,
confirmText: string,
cancelText: string,
onConfirm: (Function: object) => void,
onCancel: (Function: object) => void
): void {
const confirmationButtonsContainer = document.createElement('div');
confirmationButtonsContainer.classList.add('confirmation-btns');
container.append(confirmationButtonsContainer);

this.createButton(confirmationButtonsContainer, cancelText, ['btn-cancel'], true, onCancel);
this.createButton(confirmationButtonsContainer, confirmText, ['btn-confirm'], true, onConfirm);
}

/**
* Renders a button with optional callback function
*/
static createButton(
container: HTMLElement,
text: string,
className: string[] = [],
visibility: boolean = true,
callback: (Function: object) => void = null
): void {
className = className.concat(['btn', 'waves-effect', 'text']);
const button = document.createElement('button');
button.className = className.join(' ');
button.style.visibility = visibility ? 'visible' : 'hidden';
button.type = 'button';
button.tabIndex = !!visibility ? 0 : -1;
button.innerText = text;
button.addEventListener('click', callback);
button.addEventListener('keypress', (e) => {
if (Utils.keys.ENTER.includes(e.key)) callback(e);
});
container.append(button);
}
}
Loading