PluginProbe
AI Builder – Generate pages, blocks, images & translate with AI / 2.1.3
AI Builder – Generate pages, blocks, images & translate with AI v2.1.3
2.8.0 2.7.10 2.7.9 2.7.8 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 All 123 releases
ai-builder / assets / js / src / editor-blocks / fixed-bg-group / editor-styles.js

editor-styles.js in AI Builder – Generate pages, blocks, images & translate with AI 2.1.3, at assets/js/src/editor-blocks/fixed-bg-group/editor-styles.js

99 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // Gestion des styles dynamiques pour le Fixed Background Group dans l'éditeur
2
3 const applyFixedBgStyles = (blockElement, attributes) => {
4 if (!blockElement || !attributes.fixedBg) return;
5
6 const { fixedBgImage, fixedBgOverlay } = attributes;
7
8 // Appliquer l'image de fond
9 if (fixedBgImage && fixedBgImage.url) {
10 blockElement.style.backgroundImage = `url(${fixedBgImage.url})`;
11 } else {
12 // Image par défaut si aucune image n'est sélectionnée
13 blockElement.style.backgroundImage = `url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800"><defs><linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" style="stop-color:%236366f1;stop-opacity:1" /><stop offset="100%" style="stop-color:%239f7aea;stop-opacity:1" /></linearGradient></defs><rect width="100%" height="100%" fill="url(%23grad)"/></svg>')`;
14 }
15
16 // Appliquer la couleur d'overlay
17 if (fixedBgOverlay) {
18 // Créer ou mettre à jour l'overlay
19 let overlay = blockElement.querySelector(".fixed-bg-overlay");
20 if (!overlay) {
21 overlay = document.createElement("div");
22 overlay.className = "fixed-bg-overlay";
23 overlay.style.cssText = `
24 position: absolute;
25 top: 0;
26 left: 0;
27 width: 100%;
28 height: 100%;
29 z-index: 0;
30 pointer-events: none;
31 `;
32 blockElement.insertBefore(overlay, blockElement.firstChild);
33 }
34 overlay.style.backgroundColor = fixedBgOverlay;
35 }
36
37 // Ajouter la classe fixed-bg-section
38 blockElement.classList.add("fixed-bg-section");
39 };
40
41 // Observer pour détecter les changements dans l'éditeur
42 const observeEditorChanges = () => {
43 if (!window.wp || !window.wp.data) return;
44
45 const { select, subscribe } = window.wp.data;
46
47 subscribe(() => {
48 const blocks = select("core/block-editor").getBlocks();
49
50 blocks.forEach((block) => {
51 if (
52 block.name === "core/group" &&
53 block.attributes.className &&
54 block.attributes.className.includes("aibui-group-block") &&
55 block.attributes.fixedBg
56 ) {
57 // Trouver l'élément DOM du bloc
58 const blockElement = document.querySelector(
59 `[data-block="${block.clientId}"]`
60 );
61 if (blockElement) {
62 applyFixedBgStyles(blockElement, block.attributes);
63 }
64 }
65 });
66 });
67 };
68
69 // Initialiser l'observateur quand l'éditeur est prêt
70 if (document.readyState === "loading") {
71 document.addEventListener("DOMContentLoaded", observeEditorChanges);
72 } else {
73 observeEditorChanges();
74 }
75
76 // Fonction pour appliquer les styles aux blocs existants
77 const applyStylesToExistingBlocks = () => {
78 const fixedBgGroups = document.querySelectorAll(
79 ".aibui-group-block[data-block]"
80 );
81
82 fixedBgGroups.forEach((group) => {
83 const blockId = group.getAttribute("data-block");
84 if (blockId && window.wp && window.wp.data) {
85 const block = window.wp.data
86 .select("core/block-editor")
87 .getBlock(blockId);
88 if (block && block.attributes.fixedBg) {
89 applyFixedBgStyles(group, block.attributes);
90 }
91 }
92 });
93 };
94
95 // Appliquer les styles aux blocs existants
96 setTimeout(applyStylesToExistingBlocks, 1000);
97
98 export { applyFixedBgStyles, applyStylesToExistingBlocks };
99