Rename spinner.js -> spinners.js.

It has been frustrating when I want to name a variable spinner.
This commit is contained in:
voussoir 2022-03-15 13:49:20 -07:00
parent 9d1dd60644
commit ebe6fcb07d
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
9 changed files with 39 additions and 39 deletions

View file

@ -241,7 +241,7 @@ function Editor(element_argss, on_open, on_save, on_cancel)
spinner_element.innerText = "Submitting...";
spinner_element.classList.add("editor_spinner");
spinner_element.classList.add("hidden");
this.spinner = new spinner.Spinner(spinner_element);
this.spinner = new spinners.Spinner(spinner_element);
toolbox.appendChild(spinner_element);
for (const element of Object.values(this.elements))

View file

@ -1,18 +1,18 @@
const spinner = {};
const spinners = {};
/*
In general, spinners are used for functions that launch a callback, and the
callback will close the spinner after it runs. But, if your initial function
decides not to launch the callback (insufficient parameters, failed clientside
checks, etc.), you can have it return spinner.BAIL and the spinners will close
checks, etc.), you can have it return spinners.BAIL and the spinners will close
immediately. Of course, you're always welcome to use
window[button.dataset.spinnerCloser](), but this return value means you don't
need to pull the button into a variable, as long as you weren't using the
return value anyway.
*/
spinner.BAIL = "spinner.BAIL";
spinners.BAIL = "spinners.BAIL";
spinner.Spinner =
spinners.Spinner =
function Spinner(element)
{
this.show = function(delay)
@ -42,50 +42,50 @@ function Spinner(element)
this.element = element;
}
spinner.spinner_button_index = 0;
spinner.button_spinner_groups = {};
spinners.spinner_button_index = 0;
spinners.button_spinner_groups = {};
/*
When a group member is closing, it will call the closer on all other members
in the group. Of course, this would recurse forever without some kind of
flagging, so this dict will hold group_id:true if a close is in progress,
and be empty otherwise.
*/
spinner.spinner_group_closing = {};
spinners.spinner_group_closing = {};
spinner.add_to_spinner_group =
spinners.add_to_spinner_group =
function add_to_spinner_group(group_id, button)
{
if (!(group_id in spinner.button_spinner_groups))
if (!(group_id in spinners.button_spinner_groups))
{
spinner.button_spinner_groups[group_id] = [];
spinners.button_spinner_groups[group_id] = [];
}
spinner.button_spinner_groups[group_id].push(button);
spinners.button_spinner_groups[group_id].push(button);
}
spinner.close_grouped_spinners =
spinners.close_grouped_spinners =
function close_grouped_spinners(group_id)
{
if (group_id && !(spinner.spinner_group_closing[group_id]))
if (group_id && !(spinners.spinner_group_closing[group_id]))
{
spinner.spinner_group_closing[group_id] = true;
for (const button of spinner.button_spinner_groups[group_id])
spinners.spinner_group_closing[group_id] = true;
for (const button of spinners.button_spinner_groups[group_id])
{
window[button.dataset.spinnerCloser]();
}
delete spinner.spinner_group_closing[group_id];
delete spinners.spinner_group_closing[group_id];
}
}
spinner.open_grouped_spinners =
spinners.open_grouped_spinners =
function open_grouped_spinners(group_id)
{
for (const button of spinner.button_spinner_groups[group_id])
for (const button of spinners.button_spinner_groups[group_id])
{
window[button.dataset.spinnerOpener]();
}
}
spinner.init_button_with_spinner =
spinners.init_button_with_spinner =
function init_button_with_spinner()
{
/*
@ -126,7 +126,7 @@ function init_button_with_spinner()
if (button.dataset.spinnerGroup)
{
spinner.add_to_spinner_group(button.dataset.spinnerGroup, button);
spinners.add_to_spinner_group(button.dataset.spinnerGroup, button);
}
let spinner_element;
@ -143,10 +143,10 @@ function init_button_with_spinner()
holder.appendChild(spinner_element);
}
const spin = new spinner.Spinner(spinner_element);
const spin = new spinners.Spinner(spinner_element);
const spin_delay = parseFloat(button.dataset.spinnerDelay) || 0;
button.dataset.spinnerOpener = "spinner_opener_" + spinner.spinner_button_index;
button.dataset.spinnerOpener = "spinner_opener_" + spinners.spinner_button_index;
window[button.dataset.spinnerOpener] = function spinner_opener()
{
spin.show(spin_delay);
@ -155,10 +155,10 @@ function init_button_with_spinner()
// It is expected that the function referenced by onclick will call
// window[button.dataset.spinnerCloser]() when appropriate, since from
// our perspective we cannot be sure when to close the spinner.
button.dataset.spinnerCloser = "spinner_closer_" + spinner.spinner_button_index;
button.dataset.spinnerCloser = "spinner_closer_" + spinners.spinner_button_index;
window[button.dataset.spinnerCloser] = function spinner_closer()
{
spinner.close_grouped_spinners(button.dataset.spinnerGroup);
spinners.close_grouped_spinners(button.dataset.spinnerGroup);
spin.hide();
button.disabled = false;
}
@ -169,27 +169,27 @@ function init_button_with_spinner()
{
if (button.dataset.spinnerGroup)
{
spinner.open_grouped_spinners(button.dataset.spinnerGroup);
spinners.open_grouped_spinners(button.dataset.spinnerGroup);
}
else
{
window[button.dataset.spinnerOpener]();
}
const ret = wrapped_onclick(event);
if (ret === spinner.BAIL)
if (ret === spinners.BAIL)
{
window[button.dataset.spinnerCloser]();
}
return ret;
}
spinner.spinner_button_index += 1;
spinners.spinner_button_index += 1;
}
}
spinner.on_pageload =
spinners.on_pageload =
function on_pageload()
{
spinner.init_button_with_spinner();
spinners.init_button_with_spinner();
}
document.addEventListener("DOMContentLoaded", spinner.on_pageload);
document.addEventListener("DOMContentLoaded", spinners.on_pageload);

View file

@ -149,7 +149,7 @@ const ALBUM_ID = undefined;
<script src="/static/js/album_autocomplete.js"></script>
<script src="/static/js/cards.js"></script>
<script src="/static/js/contextmenus.js"></script>
<script src="/static/js/spinner.js"></script>
<script src="/static/js/spinners.js"></script>
<script src="/static/js/editor.js"></script>
<script src="/static/js/hotkeys.js"></script>
<script src="/static/js/photo_clipboard.js"></script>

View file

@ -13,7 +13,7 @@
<script src="/static/js/common.js"></script>
<script src="/static/js/api.js"></script>
<script src="/static/js/cards.js"></script>
<script src="/static/js/spinner.js"></script>
<script src="/static/js/spinners.js"></script>
<script src="/static/js/editor.js"></script>
<style>

View file

@ -16,7 +16,7 @@
<script src="/static/js/cards.js"></script>
<script src="/static/js/hotkeys.js"></script>
<script src="/static/js/photo_clipboard.js"></script>
<script src="/static/js/spinner.js"></script>
<script src="/static/js/spinners.js"></script>
<script src="/static/js/tag_autocomplete.js"></script>
<style>
@ -353,7 +353,7 @@ function refresh_metadata_form()
{
if (photo_clipboard.clipboard.size == 0)
{
return spinner.BAIL;
return spinners.BAIL;
}
const photo_ids = Array.from(photo_clipboard.clipboard);

View file

@ -14,7 +14,7 @@
<script src="/static/js/api.js"></script>
<script src="/static/js/hotkeys.js"></script>
<script src="/static/js/photo_clipboard.js"></script>
<script src="/static/js/spinner.js"></script>
<script src="/static/js/spinners.js"></script>
<script src="/static/js/tag_autocomplete.js"></script>
<style>

View file

@ -16,7 +16,7 @@
<script src="/static/js/cards.js"></script>
<script src="/static/js/hotkeys.js"></script>
<script src="/static/js/photo_clipboard.js"></script>
<script src="/static/js/spinner.js"></script>
<script src="/static/js/spinners.js"></script>
<script src="/static/js/tag_autocomplete.js"></script>
<style>

View file

@ -17,7 +17,7 @@
<script src="/static/js/common.js"></script>
<script src="/static/js/api.js"></script>
<script src="/static/js/editor.js"></script>
<script src="/static/js/spinner.js"></script>
<script src="/static/js/spinners.js"></script>
<script src="/static/js/tag_autocomplete.js"></script>
<style>

View file

@ -13,7 +13,7 @@
<script src="/static/js/common.js"></script>
<script src="/static/js/api.js"></script>
<script src="/static/js/editor.js"></script>
<script src="/static/js/spinner.js"></script>
<script src="/static/js/spinners.js"></script>
<style>
#content_body