about summary refs log tree commit diff
path: root/app/javascript/core/embed.js
blob: 6146e65929d6e276ffbedf2bf2f25e1456832a28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//  This file will be loaded on embed pages, regardless of theme.

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);
  }
});