about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-01-10 15:13:30 +0100
committerEugen Rochko <eugen@zeonfederated.com>2019-01-10 15:13:30 +0100
commit70801b850c78d7879182eeba4eae509af42fafeb (patch)
tree43982d6fd0cff61a96ba01188c441224a913f2b7
parent5104b61b6bb9a8ddadc1a950fa10aeb43c44515c (diff)
Postpone scroll-to-detailed status after react components are loaded (#9773)
-rw-r--r--app/javascript/packs/public.js28
1 files changed, 18 insertions, 10 deletions
diff --git a/app/javascript/packs/public.js b/app/javascript/packs/public.js
index 6ba37c049..a9a3d738a 100644
--- a/app/javascript/packs/public.js
+++ b/app/javascript/packs/public.js
@@ -33,6 +33,17 @@ function main() {
   const Rellax = require('rellax');
   const createHistory = require('history').createBrowserHistory;
 
+  const scrollToDetailedStatus = () => {
+    const history = createHistory();
+    const detailedStatuses = document.querySelectorAll('.public-layout .detailed-status');
+    const location = history.location;
+
+    if (detailedStatuses.length === 1 && (!location.state || !location.state.scrolledToDetailedStatus)) {
+      detailedStatuses[0].scrollIntoView();
+      history.replace(location.pathname, { ...location.state, scrolledToDetailedStatus: true });
+    }
+  };
+
   ready(() => {
     const locale = document.documentElement.lang;
 
@@ -76,8 +87,14 @@ function main() {
 
           ReactDOM.render(<MediaContainer locale={locale} components={reactComponents} />, content);
           document.body.appendChild(content);
+          scrollToDetailedStatus();
         })
-        .catch(error => console.error(error));
+        .catch(error => {
+          console.error(error);
+          scrollToDetailedStatus();
+        });
+    } else {
+      scrollToDetailedStatus();
     }
 
     const parallaxComponents = document.querySelectorAll('.parallax');
@@ -85,15 +102,6 @@ function main() {
     if (parallaxComponents.length > 0 ) {
       new Rellax('.parallax', { speed: -1 });
     }
-
-    const history = createHistory();
-    const detailedStatuses = document.querySelectorAll('.public-layout .detailed-status');
-    const location = history.location;
-
-    if (detailedStatuses.length === 1 && (!location.state || !location.state.scrolledToDetailedStatus)) {
-      detailedStatuses[0].scrollIntoView();
-      history.replace(location.pathname, { ...location.state, scrolledToDetailedStatus: true });
-    }
   });
 
   delegate(document, '.webapp-btn', 'click', ({ target, button }) => {