From 58174064e51ac68f5f730f7cdc4f63383b79a165 Mon Sep 17 00:00:00 2001
From: Julian Leucker <leuckerj@gmail.com>
Date: Mon, 26 Jul 2021 13:59:56 +0200
Subject: [PATCH] Hide and show search loader using jquery

---
 aleksis/core/static/js/search.js      | 16 ++++------------
 aleksis/core/templates/core/base.html |  1 +
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/aleksis/core/static/js/search.js b/aleksis/core/static/js/search.js
index 6fc1b021a..169ffabca 100644
--- a/aleksis/core/static/js/search.js
+++ b/aleksis/core/static/js/search.js
@@ -13,7 +13,7 @@ var Autocomplete = function (options) {
     this.form_elem = null;
     this.query_box = null;
     this.selected_element = null;
-    this.loader_shown = false;
+    this.loader = $("#search-loader");
 };
 
 Autocomplete.prototype.setup = function () {
@@ -133,18 +133,10 @@ Autocomplete.prototype.setSelectedResult = function (element) {
 Autocomplete.prototype.setLoader = function (value) {
     var self = this;
     if (typeof value === "boolean"){
-        if (self.loader_shown === value) {
-            return
+        if (value) {
+            self.loader.show();
         } else {
-            self.loader_shown = value
-
-            if (!value) {
-                $("#search-loader").remove();
-            } else {
-                this.query_box.after(
-                    $('<div class="progress" id="search-loader"><div class="indeterminate"></div></div>')
-                );
-            }
+            self.loader.hide();
         }
     }
 }
diff --git a/aleksis/core/templates/core/base.html b/aleksis/core/templates/core/base.html
index 27744b77a..7b3736d43 100644
--- a/aleksis/core/templates/core/base.html
+++ b/aleksis/core/templates/core/base.html
@@ -84,6 +84,7 @@
             <button class="btn btn-flat search-button" type="submit" aria-label="{% trans "Search" %}">
               <i class="material-icons">search</i>
             </button>
+            <div class="progress" style="display: none;" id="search-loader"><div class="indeterminate"></div></div>
           </div>
         </form>
       </li>
-- 
GitLab