Initial commit: Memind H5 portal with MindSpace, Plaza, and agent jobs.
Track application source and tests; exclude local env, user workspaces, and runtime data via .gitignore. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* Plaza iframe embed helpers — full-page iframe height sync for publication pages.
|
||||
*/
|
||||
|
||||
export const PLAZA_EMBED_QUERY = 'embed=plaza';
|
||||
|
||||
export function isPlazaEmbedRequest(query = {}) {
|
||||
return String(query?.embed ?? '').toLowerCase() === 'plaza';
|
||||
}
|
||||
|
||||
export function publishedPageCspForEmbed(isFullHtml) {
|
||||
if (isFullHtml) {
|
||||
return "default-src 'none'; style-src 'unsafe-inline' https:; img-src data: https:; font-src https: data:; base-uri 'none'; form-action 'self'; frame-ancestors *; script-src 'unsafe-inline'";
|
||||
}
|
||||
return "default-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors *; script-src 'unsafe-inline'";
|
||||
}
|
||||
|
||||
const EMBED_BOOTSTRAP = `<script id="plaza-embed-bootstrap">(function(){
|
||||
if(window.parent===window)return;
|
||||
var d=document;
|
||||
function blocks(){
|
||||
var out=[],hero=d.querySelector('.hero');
|
||||
if(hero)out.push(hero);
|
||||
d.querySelectorAll('.section,.quote-section').forEach(function(el){out.push(el);});
|
||||
var foot=d.querySelector('.footer');
|
||||
if(foot)out.push(foot);
|
||||
return out.length?out:[d.body];
|
||||
}
|
||||
function fullHeight(){
|
||||
return Math.min(d.documentElement.scrollHeight,16000);
|
||||
}
|
||||
function restoreBlock(block){
|
||||
if(!block)return;
|
||||
block.querySelectorAll('[data-plaza-defer-bg]').forEach(function(el){
|
||||
el.style.backgroundImage=el.dataset.plazaDeferBg;
|
||||
delete el.dataset.plazaDeferBg;
|
||||
});
|
||||
block.querySelectorAll('[data-plaza-defer-hero-bg]').forEach(function(el){
|
||||
var bg=el.dataset.plazaDeferHeroBg;
|
||||
if(!bg)return;
|
||||
if(bg.indexOf('url(')>=0)el.style.backgroundImage=bg;
|
||||
else el.style.background=bg;
|
||||
delete el.dataset.plazaDeferHeroBg;
|
||||
});
|
||||
}
|
||||
function reportHeight(){
|
||||
var b=blocks();
|
||||
window.parent.postMessage({
|
||||
type:'plaza:embed-section',
|
||||
count:b.length,
|
||||
height:fullHeight(),
|
||||
total:b.length
|
||||
},'*');
|
||||
}
|
||||
function showAll(){
|
||||
var b=blocks();
|
||||
for(var i=0;i<b.length;i++){
|
||||
b[i].style.display='';
|
||||
b[i].style.visibility='';
|
||||
restoreBlock(b[i]);
|
||||
}
|
||||
reportHeight();
|
||||
}
|
||||
var style=d.createElement('style');
|
||||
style.textContent='html,body{overflow:hidden!important;margin:0}';
|
||||
d.head.appendChild(style);
|
||||
function scheduleReport(){
|
||||
showAll();
|
||||
requestAnimationFrame(function(){
|
||||
requestAnimationFrame(function(){
|
||||
reportHeight();
|
||||
});
|
||||
});
|
||||
}
|
||||
if(d.readyState==='loading'){
|
||||
d.addEventListener('DOMContentLoaded',scheduleReport);
|
||||
}else{
|
||||
scheduleReport();
|
||||
}
|
||||
window.addEventListener('load',function(){scheduleReport();});
|
||||
new ResizeObserver(function(){reportHeight();}).observe(d.documentElement);
|
||||
})();</script>`;
|
||||
|
||||
export function injectPlazaEmbedBootstrap(html) {
|
||||
const source = String(html ?? '');
|
||||
if (source.includes('id="plaza-embed-bootstrap"')) return source;
|
||||
if (/<\/body>/i.test(source)) {
|
||||
return source.replace(/<\/body>/i, `${EMBED_BOOTSTRAP}</body>`);
|
||||
}
|
||||
return `${source}${EMBED_BOOTSTRAP}`;
|
||||
}
|
||||
|
||||
export function appendPlazaEmbedQuery(url) {
|
||||
const value = String(url ?? '').trim();
|
||||
if (!value) return value;
|
||||
if (value.includes(PLAZA_EMBED_QUERY)) return value;
|
||||
return value.includes('?') ? `${value}&${PLAZA_EMBED_QUERY}` : `${value}?${PLAZA_EMBED_QUERY}`;
|
||||
}
|
||||
Reference in New Issue
Block a user