about summary refs log tree commit diff
path: root/app/javascript/core/embed.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/javascript/core/embed.js')
-rw-r--r--app/javascript/core/embed.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/javascript/core/embed.js b/app/javascript/core/embed.js
new file mode 100644
index 000000000..9083eb7a3
--- /dev/null
+++ b/app/javascript/core/embed.js
@@ -0,0 +1,25 @@
+//  This file will be loaded on embed pages, regardless of theme.
+
+import 'packs/public-path';
+
+window.addEventListener('message', e => {
+  const data = e.data || {};
+
+  if (!window.parent || data.type !== 'setHeight') {
+    return;
+  }
+
+  function setEmbedHeight () {
+    window.parent.postMessage({
+      type: 'setHeight',
+      id: data.id,
+      height: document.getElementsByTagName('html')[0].scrollHeight,
+    }, '*');
+  };
+
+  if (['interactive', 'complete'].includes(document.readyState)) {
+    setEmbedHeight();
+  } else {
+    document.addEventListener('DOMContentLoaded', setEmbedHeight);
+  }
+});