changeset 929:cebeedfa034f

serve: Don't start the admin panel SSE until the window is ready.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 04 Oct 2017 09:08:31 -0700
parents 41db689d36b6
children 21d491ef30fe
files piecrust/admin/assets/js/foodtruck.js
diffstat 1 files changed, 10 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/piecrust/admin/assets/js/foodtruck.js	Sun Oct 01 20:38:43 2017 -0700
+++ b/piecrust/admin/assets/js/foodtruck.js	Wed Oct 04 09:08:31 2017 -0700
@@ -26,6 +26,16 @@
     closePublogBtn.on('click', function() {
         publogEl.fadeOut(200);
     });
+
+    if (!!window.EventSource) {
+        // TODO: this only works when the Foodtruck blueprint is added under `/pc-admin`.
+        var source = new EventSource('/pc-admin/publish-log');
+        source.onerror = function(e) {
+            console.log("Error with SSE, closing.", e);
+            source.close();
+        };
+        source.addEventListener('message', onPublishEvent);
+    }
 });
 
 var onPublishEvent = function(e) {
@@ -55,14 +65,3 @@
     containerEl.append(msgEl);
 };
 
-if (!!window.EventSource) {
-    // TODO: this only works when the Foodtruck blueprint is added under `/pc-admin`.
-    var source = new EventSource('/pc-admin/publish-log');
-    source.onerror = function(e) {
-        console.log("Error with SSE, closing.", e);
-        source.close();
-    };
-    source.addEventListener('message', onPublishEvent);
-}
-
-