0
0
Fork 0

Add script to make embedded iframes autosize (#4853)

This commit is contained in:
Eugen Rochko 2017-09-09 16:23:44 +02:00 committed by GitHub
parent bdc8b4fd91
commit 6867681c7c
5 changed files with 76 additions and 10 deletions

43
public/embed.js Normal file
View file

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