Update builder.html
Browse files- builder.html +22 -98
builder.html
CHANGED
@@ -26,111 +26,35 @@
|
|
26 |
},
|
27 |
});
|
28 |
|
29 |
-
|
30 |
-
const
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
},
|
38 |
-
});
|
39 |
-
|
40 |
-
// Add blocks for the second example
|
41 |
-
bm.add('cmp-a-block', {
|
42 |
-
label: 'Component A',
|
43 |
-
content: {
|
44 |
-
type: 'cmp-a',
|
45 |
-
},
|
46 |
-
});
|
47 |
-
|
48 |
-
bm.add('cmp-b-block', {
|
49 |
-
label: 'Component B',
|
50 |
-
content: {
|
51 |
-
type: 'cmp-b',
|
52 |
-
},
|
53 |
-
});
|
54 |
-
|
55 |
-
bm.add('component-css-block-2', {
|
56 |
-
label: 'Component with CSS 2',
|
57 |
-
content: {
|
58 |
-
type: 'component-css',
|
59 |
-
},
|
60 |
-
});
|
61 |
-
|
62 |
-
// Define component types
|
63 |
-
domc.addType('component-css', {
|
64 |
model: {
|
65 |
defaults: {
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
components: `
|
68 |
-
<
|
69 |
-
<div class="cmp-css-a">Component A</div>
|
70 |
-
<div class="cmp-css-b">Component B</div>
|
71 |
-
`,
|
72 |
-
styles: `
|
73 |
-
.cmp-css { color: red }
|
74 |
-
.cmp-css-a { color: green }
|
75 |
-
.cmp-css-b { color: blue }
|
76 |
-
|
77 |
-
@media (max-width: 992px) {
|
78 |
-
.cmp-css{ color: darkred; }
|
79 |
-
.cmp-css-a { color: darkgreen }
|
80 |
-
.cmp-css-b { color: darkblue }
|
81 |
-
}
|
82 |
-
`,
|
83 |
-
},
|
84 |
-
},
|
85 |
-
});
|
86 |
-
|
87 |
-
domc.addType('cmp-a', {
|
88 |
-
model: {
|
89 |
-
defaults: {
|
90 |
-
attributes: { class: 'cmp-css-a' },
|
91 |
-
components: 'Component A',
|
92 |
-
styles: `
|
93 |
-
.cmp-css-a { color: green }
|
94 |
-
@media (max-width: 992px) {
|
95 |
-
.cmp-css-a { color: darkgreen }
|
96 |
-
}
|
97 |
-
`,
|
98 |
-
}
|
99 |
-
},
|
100 |
-
});
|
101 |
-
|
102 |
-
domc.addType('cmp-b', {
|
103 |
-
model: {
|
104 |
-
defaults: {
|
105 |
-
attributes: { class: 'cmp-css-b' },
|
106 |
-
components: 'Component B',
|
107 |
-
styles: `
|
108 |
-
.cmp-css-b { color: blue }
|
109 |
-
@media (max-width: 992px) {
|
110 |
-
.cmp-css-b { color: darkblue }
|
111 |
-
}
|
112 |
`,
|
113 |
}
|
114 |
-
}
|
115 |
});
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
'<span>Component with styles<span>',
|
123 |
-
{ type: 'cmp-a' },
|
124 |
-
{ type: 'cmp-b' },
|
125 |
-
],
|
126 |
-
styles: `
|
127 |
-
.cmp-css { color: red }
|
128 |
-
@media (max-width: 992px) {
|
129 |
-
.cmp-css{ color: darkred; }
|
130 |
-
}
|
131 |
-
`,
|
132 |
-
},
|
133 |
-
},
|
134 |
});
|
135 |
</script>
|
136 |
</body>
|
|
|
26 |
},
|
27 |
});
|
28 |
|
29 |
+
// Define a custom script
|
30 |
+
const script = function() {
|
31 |
+
alert('Hi');
|
32 |
+
console.log('the element', this);
|
33 |
+
};
|
34 |
+
|
35 |
+
// Define a new custom component
|
36 |
+
editor.Components.addType('comp-with-js', {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
model: {
|
38 |
defaults: {
|
39 |
+
script,
|
40 |
+
// Add some style, just to make the component visible
|
41 |
+
style: {
|
42 |
+
width: '100px',
|
43 |
+
height: '100px',
|
44 |
+
background: 'red',
|
45 |
+
},
|
46 |
components: `
|
47 |
+
<button onclick="alert('Ещё')" style="margin: 10px;">Ещё</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
`,
|
49 |
}
|
50 |
+
}
|
51 |
});
|
52 |
|
53 |
+
// Create a block for the component, so we can drop it easily
|
54 |
+
editor.Blocks.add('test-block', {
|
55 |
+
label: 'Test block',
|
56 |
+
attributes: { class: 'fa fa-text' },
|
57 |
+
content: { type: 'comp-with-js' },
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
});
|
59 |
</script>
|
60 |
</body>
|