From c7e4bf16d22007b2f76139ec629d5ce9ae3fca1a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 27 Apr 2019 15:42:02 -0700 Subject: [PATCH] Pull spinner code into own file spinner.js. For the purposes of editor.js this does not bring much improvement, but now I can easily make spinners for other things. --- frontends/etiquette_flask/static/js/editor.js | 17 +++++----- .../etiquette_flask/static/js/spinner.js | 31 +++++++++++++++++++ .../etiquette_flask/templates/album.html | 1 + .../etiquette_flask/templates/bookmarks.html | 1 + frontends/etiquette_flask/templates/tags.html | 1 + 5 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 frontends/etiquette_flask/static/js/spinner.js diff --git a/frontends/etiquette_flask/static/js/editor.js b/frontends/etiquette_flask/static/js/editor.js index 19339de..b4716fc 100644 --- a/frontends/etiquette_flask/static/js/editor.js +++ b/frontends/etiquette_flask/static/js/editor.js @@ -60,7 +60,7 @@ function Editor(elements, on_open, on_save, on_cancel) this.hide_spinner = function() { - this.spinner.classList.add("hidden"); + this.spinner.hide(); }; this.open = function() @@ -115,10 +115,10 @@ function Editor(elements, on_open, on_save, on_cancel) this.error_message.classList.remove("hidden"); }; - this.show_spinner = function() + this.show_spinner = function(delay) { this.hide_error(); - this.spinner.classList.remove("hidden"); + this.spinner.show(delay); }; this.display_elements = []; @@ -245,11 +245,12 @@ function Editor(elements, on_open, on_save, on_cancel) this.error_message.classList.add("hidden"); toolbox.appendChild(this.error_message); - this.spinner = document.createElement("span"); - this.spinner.innerText = "Submitting..."; - this.spinner.classList.add("editor_spinner"); - this.spinner.classList.add("hidden"); - toolbox.appendChild(this.spinner); + spinner_element = document.createElement("span"); + spinner_element.innerText = "Submitting..."; + spinner_element.classList.add("editor_spinner"); + spinner_element.classList.add("hidden"); + this.spinner = new spinner.Spinner(spinner_element); + toolbox.appendChild(spinner_element); for (var index = 0; index < this.edit_elements.length; index += 1) { diff --git a/frontends/etiquette_flask/static/js/spinner.js b/frontends/etiquette_flask/static/js/spinner.js new file mode 100644 index 0000000..e364c6e --- /dev/null +++ b/frontends/etiquette_flask/static/js/spinner.js @@ -0,0 +1,31 @@ +var spinner = {}; + +spinner.Spinner = +function Spinner(element) +{ + this.show = function(delay) + { + clearTimeout(this.delayed_showing_timeout); + this.delayed_showing_timeout = null; + + if (! delay) + { + this.element.classList.remove("hidden"); + } + else + { + this.delayed_showing_timeout = setTimeout(this.show, delay); + } + } + + this.hide = function() + { + clearTimeout(this.delayed_showing_timeout); + this.delayed_showing_timeout = null; + + this.element.classList.add("hidden"); + } + + this.delayed_showing_timeout = null; + this.element = element; +} diff --git a/frontends/etiquette_flask/templates/album.html b/frontends/etiquette_flask/templates/album.html index c168868..bc8b372 100644 --- a/frontends/etiquette_flask/templates/album.html +++ b/frontends/etiquette_flask/templates/album.html @@ -153,6 +153,7 @@ ALBUM_ID = undefined; + diff --git a/frontends/etiquette_flask/templates/bookmarks.html b/frontends/etiquette_flask/templates/bookmarks.html index 1e24fbf..f5500ad 100644 --- a/frontends/etiquette_flask/templates/bookmarks.html +++ b/frontends/etiquette_flask/templates/bookmarks.html @@ -8,6 +8,7 @@ +