PluginProbe
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts / trunk
Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts vtrunk
2.8.14 2.8.13 2.8.12 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.11 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 trunk 1.0.1 1.0.2 1.1.0 1.1.1 All 147 releases
content-blocks-builder / src / utils / editor.js

editor.js in Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts trunk, at src/utils/editor.js

46 lines 991 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Get the owner document (considering editor iframe).
3 *
4 * @param {Document} document
5 * @returns {Document}
6 */
7 export const getDocument = (document) => {
8 let previewDoc = document;
9
10 const editorCanvas = document.querySelector('iframe[name="editor-canvas"]');
11 if (editorCanvas) {
12 previewDoc = editorCanvas.contentWindow.document;
13 }
14
15 return previewDoc;
16 };
17
18 /**
19 * Update live-style
20 *
21 * @param {String} id
22 * @param {String} content
23 * @param {Boolean} remove
24 */
25 export const updateDynamicStyle = (id, content, remove = false) => {
26 let previewDoc = getDocument(document);
27
28 let styleElement = previewDoc.getElementById(id);
29
30 if (remove) {
31 if (styleElement) {
32 styleElement.remove();
33 }
34 } else {
35 // Create a new one if don't have one
36 if (!styleElement) {
37 styleElement = previewDoc.createElement("style");
38 styleElement.id = id;
39
40 previewDoc.head.appendChild(styleElement);
41 }
42
43 styleElement.textContent = content;
44 }
45 };
46