From d358438cf9ae60c8c5f4043c3a1e76eac38d3565 Mon Sep 17 00:00:00 2001
From: Tira Odhner <pair+aodhner@pivotal.io>
Date: Mon, 20 Mar 2017 15:03:12 -0400
Subject: [PATCH 1/3] move the hide spinner method so it can be tested

---
 web/pgadmin/browser/templates/browser/index.html | 40 +-------------------
 web/pgadmin/static/js/hide_spinner.js            | 48 ++++++++++++++++++++++++
 web/pgadmin/templates/base.html                  |  1 +
 3 files changed, 50 insertions(+), 39 deletions(-)
 create mode 100644 web/pgadmin/static/js/hide_spinner.js

diff --git a/web/pgadmin/browser/templates/browser/index.html b/web/pgadmin/browser/templates/browser/index.html
index 5bd054a2..0f0a9352 100644
--- a/web/pgadmin/browser/templates/browser/index.html
+++ b/web/pgadmin/browser/templates/browser/index.html
@@ -22,45 +22,7 @@ console.log(err);
  * http://stackoverflow.com/questions/15581563/requirejs-load-script-progress
  * Little bit tweaked as per need
  */
-require.onResourceLoad = function (context, map, depMaps) {
-  var loadingStatusEl = panel = document.getElementById('pg-spinner');
-  if (loadingStatusEl) {
-    if (!context) {
-      // we will call onResourceLoad(false) by ourselves when requirejs
-      // is not loading anything hide the indicator and exit
-      setTimeout(function() {
-        if (panel != null) {
-          $(panel).remove();
-          return;
-        }
-      }, 500);
-    }
-
-    // show indicator when any module is loaded and
-    // shedule requirejs status (loading/idle) check
-    panel.style.display = "";
-    clearTimeout(panel.ttimer);
-    panel.ttimer = setTimeout(function () {
-      var context = require.s.contexts._;
-      var inited = true;
-      for (name in context.registry) {
-        var m = context.registry[name];
-        if (m.inited !== true) {
-          inited = false;
-          break;
-        }
-      }
-
-      // here the "inited" variable will be true, if requirejs is "idle",
-      // false if "loading"
-      if (inited) {
-        // will fire if module loads in 400ms. TODO: reset this timer
-        // for slow module loading
-        require.onResourceLoad(false);
-      }
-    }, 400)
-  }
-};
+require.onResourceLoad = window.hideRequireJsLoadingSpinner;
 {% endblock %}
 {% block body %}
 <style>
diff --git a/web/pgadmin/static/js/hide_spinner.js b/web/pgadmin/static/js/hide_spinner.js
new file mode 100644
index 00000000..e30cf23f
--- /dev/null
+++ b/web/pgadmin/static/js/hide_spinner.js
@@ -0,0 +1,48 @@
+/*************************************************************************
+*
+* pgAdmin 4 - PostgreSQL Tools
+*
+* Copyright (C) 2013 - 2017, The pgAdmin Development Team
+* This software is released under the PostgreSQL Licence
+*
+**************************************************************************/
+
+window.hideRequireJsLoadingSpinner = function (context, map, depMaps) {
+  var loadingStatusEl = panel = document.getElementById('pg-spinner');
+  if (loadingStatusEl) {
+    if (!context) {
+      // we will call onResourceLoad(false) by ourselves when requirejs
+      // is not loading anything hide the indicator and exit
+      setTimeout(function() {
+        if (panel != null) {
+          $(panel).remove();
+          return;
+        }
+      }, 500);
+    }
+
+    // show indicator when any module is loaded and
+    // shedule requirejs status (loading/idle) check
+    panel.style.display = "";
+    clearTimeout(panel.ttimer);
+    panel.ttimer = setTimeout(function () {
+      var context = require.s.contexts._;
+      var inited = true;
+      for (name in context.registry) {
+        var m = context.registry[name];
+        if (m.inited !== true) {
+          inited = false;
+          break;
+        }
+      }
+
+      // here the "inited" variable will be true, if requirejs is "idle",
+      // false if "loading"
+      if (inited) {
+        // will fire if module loads in 400ms. TODO: reset this timer
+        // for slow module loading
+        require.onResourceLoad(false);
+      }
+    }, 400)
+  }
+};
\ No newline at end of file
diff --git a/web/pgadmin/templates/base.html b/web/pgadmin/templates/base.html
index 375b39d7..5debc869 100755
--- a/web/pgadmin/templates/base.html
+++ b/web/pgadmin/templates/base.html
@@ -205,6 +205,7 @@
 <![endif]-->
 
 {% block body %}{% endblock %}
+<script src="/static/js/hide_spinner.js" type="application/javascript"></script>
 <script>
             {% block init_script %}{% endblock %}
 
-- 
2.12.0

