about summary refs log tree commit diff
path: root/public
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-09-09 16:23:44 +0200
committerGitHub <noreply@github.com>2017-09-09 16:23:44 +0200
commit6867681c7c0b4a5ec48511c013c3f3aa8684bdae (patch)
treeece9c081ceed9ee2b81ac9a6e44a8d72ae361b2d /public
parentbdc8b4fd91aa90c624bca6cd6fe202876b4f654f (diff)
Add script to make embedded iframes autosize (#4853)
Diffstat (limited to 'public')
-rw-r--r--public/embed.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/public/embed.js b/public/embed.js
new file mode 100644
index 000000000..dac507453
--- /dev/null
+++ b/public/embed.js
@@ -0,0 +1,43 @@
+(function() {
+  'use strict';
+
+  var ready = function(loaded) {
+    if (['interactive', 'complete'].indexOf(document.readyState) !== -1) {
+      loaded();
+    } else {
+      document.addEventListener('DOMContentLoaded', loaded);
+    }
+  };
+
+  ready(function() {
+    var iframes = [];
+
+    window.addEventListener('message', function(e) {
+      var data = e.data || {};
+
+      if (data.type !== 'setHeight' || !iframes[data.id]) {
+        return;
+      }
+
+      iframes[data.id].height = data.height;
+    });
+
+    [].forEach.call(document.querySelectorAll('iframe.mastodon-embed'), function(iframe) {
+      iframe.scrolling      = 'no';
+      iframe.style.overflow = 'hidden';
+
+      iframes.push(iframe);
+
+      var id = iframes.length - 1;
+
+      iframe.onload = function() {
+        iframe.contentWindow.postMessage({
+          type: 'setHeight',
+          id: id,
+        }, '*');
+      };
+
+      iframe.onload();
+    });
+  });
+})();