OXYGENHUB
# c95446a17fdd oxygenhub / assets / report-frame.js
1.1 KiB · JavaScript · last changed Reports: cards with a kind icon and health, frames that fit and share the hub's look 25 days ago source blame history raw
1
/* OxygenHub report frame (oxygenhub#127): the hub adds this to a report's
2
   HTML pages. It tells the page around the frame how tall the report is,
3
   so the frame grows to fit instead of scrolling, and takes the hub's
4
   theme (data-theme="dark" or "light" on <html>) for report.css. It sends
5
   nothing but sizes, and reads nothing but the theme. */
6
(function () {
7
  if (window.parent === window) return;
8
  var root = document.documentElement, last = 0;
9
  var send = function () {
10
    var h = Math.ceil(Math.max(root.scrollHeight, document.body ? document.body.scrollHeight : 0));
11
    if (h && h !== last) {
12
      last = h;
13
      window.parent.postMessage({ oxygenhubReport: { height: h } }, "*");
14
    }
15
  };
16
  window.addEventListener("message", function (e) {
17
    if (e.source !== window.parent) return;
18
    var t = e.data && e.data.oxygenhubTheme;
19
    if (t === "dark" || t === "light") root.dataset.theme = t;
20
  });
21
  window.addEventListener("load", send);
22
  if (window.ResizeObserver) new ResizeObserver(send).observe(root);
23
  else setInterval(send, 500);
24
  window.parent.postMessage({ oxygenhubReport: { ready: true } }, "*");
25
})();