diff options
author | Egor Kislitsyn <egor@kislitsyn.com> | 2020-03-20 21:19:34 +0400 |
---|---|---|
committer | Egor Kislitsyn <egor@kislitsyn.com> | 2020-03-20 21:46:26 +0400 |
commit | cb8236cda62cddb72f4320af6347defae44b81ca (patch) | |
tree | 0e95535be69e8262c9ad3017a103083104330249 /priv/static/embed.js | |
parent | d74405fc1a27bb3d13f4ead2bc2369f23827a781 (diff) | |
download | pleroma-cb8236cda62cddb72f4320af6347defae44b81ca.tar.gz pleroma-cb8236cda62cddb72f4320af6347defae44b81ca.zip |
Add embeddable posts
Diffstat (limited to 'priv/static/embed.js')
-rw-r--r-- | priv/static/embed.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/priv/static/embed.js b/priv/static/embed.js new file mode 100644 index 000000000..f675f6417 --- /dev/null +++ b/priv/static/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 !== 'setHeightPleromaEmbed' || !iframes[data.id]) { + return + } + + iframes[data.id].height = data.height + }); + + [].forEach.call(document.querySelectorAll('iframe.pleroma-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: 'setHeightPleromaEmbed', + id: id + }, '*') + } + + iframe.onload() + }) + }) +})() |