From c74d49b785447fc2cf54d8ba5bad02623352e02e Mon Sep 17 00:00:00 2001 From: dewanakl Date: Fri, 27 Dec 2024 23:00:37 +0700 Subject: [PATCH] refactor: update html tag --- js/util.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/js/util.js b/js/util.js index 9e6a5e6..b2092ce 100644 --- a/js/util.js +++ b/js/util.js @@ -29,11 +29,15 @@ export const util = (() => { clear = setTimeout(c, timeout); }; + /** + * @param {HTMLElement} button + * @param {string} [message='Loading..'] + * @returns {object} + */ const disableButton = (button, message = 'Loading..') => { - button.disabled = true; const tmp = button.innerHTML; - button.innerHTML = `
${message}`; + button.innerHTML = `${message}`; return { restore: () => { @@ -43,12 +47,16 @@ export const util = (() => { }; }; + /** + * @param {HTMLElement} checkbox + * @returns {object} + */ const addLoadingCheckbox = (checkbox) => { checkbox.disabled = true; const label = document.querySelector(`label[for="${checkbox.id}"]`); const tmp = label.innerHTML; - label.innerHTML = `
${tmp}`; + label.innerHTML = `${tmp}`; return { restore: () => { @@ -66,10 +74,16 @@ export const util = (() => { */ const animate = (svg, timeout, classes) => timeOut(() => svg.classList.add(classes), timeout); + /** + * @param {HTMLElement} button + * @param {string} [message=null] + * @param {number} [timeout=1500] + * @returns {Promise} + */ const copy = async (button, message = null, timeout = 1500) => { - const copy = button.getAttribute('data-copy'); + const data = button.getAttribute('data-copy'); - if (!copy || copy.length == 0) { + if (!data || data.length == 0) { alert('Nothing to copy'); return; } @@ -77,7 +91,7 @@ export const util = (() => { button.disabled = true; try { - await navigator.clipboard.writeText(copy); + await navigator.clipboard.writeText(data); } catch { button.disabled = false; alert('Failed to copy');