Fine-tune use of let/const in spinner.js.
This commit is contained in:
parent
62e87c4b1a
commit
1f88b007cd
1 changed files with 11 additions and 10 deletions
|
@ -98,22 +98,28 @@ function init_button_with_spinner()
|
||||||
page, or two buttons which do opposite things and you only want one
|
page, or two buttons which do opposite things and you only want one
|
||||||
to run at a time.
|
to run at a time.
|
||||||
*/
|
*/
|
||||||
let buttons = Array.from(document.getElementsByClassName("button_with_spinner"));
|
const buttons = Array.from(document.getElementsByClassName("button_with_spinner"));
|
||||||
for (const button of buttons)
|
for (const button of buttons)
|
||||||
{
|
{
|
||||||
button.classList.remove("button_with_spinner");
|
button.classList.remove("button_with_spinner");
|
||||||
button.innerHTML = button.innerHTML.trim();
|
button.innerHTML = button.innerHTML.trim();
|
||||||
|
|
||||||
let holder = document.createElement("span");
|
const holder = document.createElement("span");
|
||||||
holder.classList.add("spinner_holder");
|
holder.classList.add("spinner_holder");
|
||||||
holder.classList.add(button.dataset.holderClass || "spinner_holder");
|
holder.classList.add(button.dataset.holderClass || "spinner_holder");
|
||||||
button.parentElement.insertBefore(holder, button);
|
button.parentElement.insertBefore(holder, button);
|
||||||
holder.appendChild(button);
|
holder.appendChild(button);
|
||||||
|
|
||||||
|
if (button.dataset.spinnerGroup)
|
||||||
|
{
|
||||||
|
spinner.add_to_spinner_group(button.dataset.spinnerGroup, button);
|
||||||
|
}
|
||||||
|
|
||||||
let spinner_element;
|
let spinner_element;
|
||||||
if (button.dataset.spinnerId)
|
if (button.dataset.spinnerId)
|
||||||
{
|
{
|
||||||
spinner_element = document.getElementById(button.dataset.spinnerId);
|
spinner_element = document.getElementById(button.dataset.spinnerId);
|
||||||
|
spinner_element.classList.add("hidden");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -123,13 +129,8 @@ function init_button_with_spinner()
|
||||||
holder.appendChild(spinner_element);
|
holder.appendChild(spinner_element);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (button.dataset.spinnerGroup)
|
const spin = new spinner.Spinner(spinner_element);
|
||||||
{
|
const spin_delay = parseFloat(button.dataset.spinnerDelay) || 0;
|
||||||
spinner.add_to_spinner_group(button.dataset.spinnerGroup, button);
|
|
||||||
}
|
|
||||||
|
|
||||||
let spin = new spinner.Spinner(spinner_element);
|
|
||||||
let spin_delay = parseFloat(button.dataset.spinnerDelay) || 0;
|
|
||||||
|
|
||||||
button.dataset.spinnerOpener = "spinner_opener_" + spinner.spinner_button_index;
|
button.dataset.spinnerOpener = "spinner_opener_" + spinner.spinner_button_index;
|
||||||
window[button.dataset.spinnerOpener] = function spinner_opener()
|
window[button.dataset.spinnerOpener] = function spinner_opener()
|
||||||
|
@ -148,7 +149,7 @@ function init_button_with_spinner()
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let wrapped_onclick = button.onclick;
|
const wrapped_onclick = button.onclick;
|
||||||
button.removeAttribute('onclick');
|
button.removeAttribute('onclick');
|
||||||
button.onclick = function()
|
button.onclick = function()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue