v4
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/* DONA_REPLY_FLOATING_V1: carte texte latérale sans recouvrir le moteur d'animations. */
|
||||
(() => {
|
||||
'use strict';
|
||||
if (window.__donaReplyFloatingV1) return;
|
||||
window.__donaReplyFloatingV1 = true;
|
||||
|
||||
function setup() {
|
||||
const main = document.getElementById('alfredMainV1');
|
||||
const stage = document.getElementById('stage');
|
||||
const content = document.getElementById('content');
|
||||
if (!main || !stage || !content) return;
|
||||
|
||||
let queued = false;
|
||||
function isRich() {
|
||||
// Les vues calendrier/météo, cartes, vidéo, images et modules spécialisés
|
||||
// conservent la grande scène et tous leurs contrôles.
|
||||
if (content.classList.contains('alfred-view')) return true;
|
||||
if (content.querySelector('.alfred-view,.view-pane,.cards,.hero,iframe,video,canvas,img,table,.dona-dynamic-grid,.dona-dynamic-dashboard,[data-dona-rich]')) return true;
|
||||
if (content.querySelector('.dh-response')) return false;
|
||||
const nodes = [...content.children];
|
||||
return !nodes.length || nodes.some(n => !['H1','H2','H3','P','PRE','BLOCKQUOTE'].includes(n.tagName));
|
||||
}
|
||||
function update() {
|
||||
queued = false;
|
||||
const focused = main.classList.contains('is-focused');
|
||||
const compact = focused && !isRich();
|
||||
const expanded = compact && content.querySelector('.dh-more[aria-expanded="true"]') !== null;
|
||||
stage.classList.toggle('dona-reply-compact', compact);
|
||||
stage.classList.toggle('dona-reply-expanded', expanded);
|
||||
main.classList.toggle('dona-reply-background-visible', compact && !expanded);
|
||||
stage.setAttribute('data-dona-reply-mode', compact ? (expanded ? 'expanded':'compact') : 'full');
|
||||
}
|
||||
function queue() {
|
||||
if (queued) return;
|
||||
queued = true;
|
||||
requestAnimationFrame(update);
|
||||
}
|
||||
new MutationObserver(queue).observe(content, {childList:true,subtree:true,attributes:true,attributeFilter:['aria-expanded','class']});
|
||||
new MutationObserver(queue).observe(main, {attributes:true,attributeFilter:['class']});
|
||||
// Le renderer transforme parfois la réponse brute en carte au frame suivant.
|
||||
window.alfredSocket?.on('alfred_render', queue);
|
||||
stage.addEventListener('click', e => {
|
||||
if (e.target.closest('.dh-more')) setTimeout(queue, 0);
|
||||
});
|
||||
queue();
|
||||
}
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', setup, {once:true});
|
||||
else setup();
|
||||
})();
|
||||
Reference in New Issue
Block a user