Merge pull request #5052 from pixelfed/staging

Update profile embed, fix height bug
This commit is contained in:
daniel 2024-04-20 05:59:25 -06:00 committed by GitHub
commit ae60c99679
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -76,21 +76,33 @@
.then(res => res.json())
.then(res => {
let parent = document.querySelector('.embed-row');
res.filter(res => res.pf_type == 'photo' && !res.sensitive && res.visibility === 'public')
res.filter(post => post.pf_type == 'photo' && !post.sensitive && post.visibility === 'public')
.slice(0, 9)
.forEach(post => {
.forEach((post, idx) => {
let mediaUrl = post.media_attachments[0].preview_url ? post.media_attachments[0].preview_url : post.media_attachments[0].url;
let el = document.createElement('template')
el.innerHTML = `<div class="col-4 mt-2 px-0"><a class="card info-overlay card-md-border-0 px-1 shadow-none" href="${post.url}" target="_blank"><div class="square"><div class="square-content" style="background-image: url('${mediaUrl}')"></div></div></a></div>`;
parent.append(el.content);
let html = `<div class="col-4 mt-2 px-0"><a class="card info-overlay card-md-border-0 px-1 shadow-none" href="${post.url}" target="_blank"><div class="square"><div class="square-content" style="background-image: url('${mediaUrl}')"></div></div></a></div>`;
let el = document.createElement('div');
el.innerHTML = html;
parent.appendChild(el.firstChild);
});
})
}).then(() => {
window.addEventListener("message",e=>{const t=e.data||{};window.parent&&"setHeight"===t.type&&window.parent.postMessage({type:"setHeight",id:t.id,height:document.getElementsByTagName("html")[0].scrollHeight},"*")});
window.addEventListener("message", e => {
const t = e.data || {};
if (window.parent && t.type === 'setHeight') {
updateHeight(t.id)
}
});
function updateHeight(id) {
setTimeout(() => {
window.addEventListener("message",e=>{const t=e.data||{};window.parent&&"setHeight"===t.type&&window.parent.postMessage({type:"setHeight",id:t.id,height:document.getElementsByTagName("html")[0].scrollHeight},"*")});
}, 5000);
})
window.parent.postMessage({
type: 'setHeight',
id: id,
height: document.documentElement.scrollHeight
}, "*");
}, 2500)
}
</script>
</body>
</html>