Update builder2.html
Browse files- builder2.html +100 -50
builder2.html
CHANGED
@@ -1,58 +1,108 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
</head>
|
17 |
<body>
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
id: "open-code",
|
54 |
-
},
|
55 |
-
]);
|
56 |
-
</script>
|
57 |
</body>
|
58 |
-
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="en">
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>GrapesJS with Script Editor</title>
|
7 |
+
<link href="https://unpkg.com/grapesjs/dist/css/grapes.min.css" rel="stylesheet">
|
8 |
+
<link href="https://unpkg.com/grapesjs-script-editor/dist/grapesjs-script-editor.min.css" rel="stylesheet">
|
9 |
+
<script src="https://unpkg.com/grapesjs"></script>
|
10 |
+
<script src="https://unpkg.com/grapesjs-script-editor"></script>
|
11 |
+
<style>
|
12 |
+
body, html {
|
13 |
+
margin: 0;
|
14 |
+
height: 100%;
|
15 |
+
}
|
16 |
+
#gjs {
|
17 |
+
height: 100vh;
|
18 |
+
}
|
19 |
+
.controls-container {
|
20 |
+
background-color: #302f2f;
|
21 |
+
padding: 15px 0;
|
22 |
+
text-align: center;
|
23 |
+
}
|
24 |
+
.controls-container label,
|
25 |
+
.controls-container button {
|
26 |
+
margin-left: 15px;
|
27 |
+
}
|
28 |
+
#export-html {
|
29 |
+
background-color: #ccc;
|
30 |
+
color: #000;
|
31 |
+
border: none;
|
32 |
+
padding: 10px 15px;
|
33 |
+
font-size: 16px;
|
34 |
+
cursor: pointer;
|
35 |
+
border-radius: 5px;
|
36 |
+
transition: background-color 0.3s ease;
|
37 |
+
}
|
38 |
+
#export-html:hover {
|
39 |
+
background-color: #bbb;
|
40 |
+
}
|
41 |
+
.controls-container label {
|
42 |
+
color: #fff;
|
43 |
+
}
|
44 |
+
</style>
|
45 |
</head>
|
46 |
<body>
|
47 |
+
<div id="gjs"></div>
|
48 |
+
<div class="controls-container">
|
49 |
+
<button id="export-html">Скачать HTML</button>
|
50 |
+
</div>
|
51 |
+
|
52 |
+
<script>
|
53 |
+
const editor = grapesjs.init({
|
54 |
+
container: '#gjs',
|
55 |
+
height: '100%',
|
56 |
+
fromElement: true,
|
57 |
+
storageManager: false,
|
58 |
+
plugins: ['grapesjs-script-editor'],
|
59 |
+
pluginsOpts: {
|
60 |
+
'grapesjs-script-editor': {
|
61 |
+
toolbarIcon: '<i class="fa fa-puzzle-piece"></i>', // Иконка в панели инструментов
|
62 |
+
scriptTypesSupport: ['default', 'text', 'textnode'], // Поддержка скриптов для текстовых блоков
|
63 |
+
modalTitle: 'Script Editor', // Заголовок модального окна
|
64 |
+
buttonLabel: 'Save', // Текст кнопки сохранения
|
65 |
+
onRun: () => console.log('Script is valid'), // Логика при успешной проверке
|
66 |
+
onError: err => console.log('Error:', err) // Логика при ошибке
|
67 |
+
}
|
68 |
+
},
|
69 |
+
panels: {
|
70 |
+
defaults: [
|
71 |
+
{
|
72 |
+
id: 'views',
|
73 |
+
buttons: [
|
74 |
+
{
|
75 |
+
attributes: { title: 'Open Script Editor' },
|
76 |
+
className: 'fa fa-puzzle-piece',
|
77 |
+
command: 'edit-script',
|
78 |
+
id: 'edit-script'
|
79 |
+
}
|
80 |
+
],
|
81 |
+
appendTo: '.gjs-pn-views-container'
|
82 |
+
}
|
83 |
+
]
|
84 |
+
}
|
85 |
+
});
|
86 |
|
87 |
+
// Команда для открытия редактора скриптов
|
88 |
+
editor.Commands.add('edit-script', {
|
89 |
+
run: function(editor) {
|
90 |
+
editor.runCommand('script-editor');
|
91 |
+
}
|
92 |
+
});
|
93 |
|
94 |
+
// Обработчик для кнопки экспорта
|
95 |
+
document.getElementById('export-html').addEventListener('click', function() {
|
96 |
+
const html = editor.getHtml();
|
97 |
+
const css = editor.getCss();
|
98 |
+
const blob = new Blob(['<html><head><style>' + css + '</style></head><body>' + html + '</body></html>'], { type: 'text/html' });
|
99 |
+
const link = document.createElement('a');
|
100 |
+
link.href = URL.createObjectURL(blob);
|
101 |
+
link.download = 'page.html';
|
102 |
+
document.body.appendChild(link);
|
103 |
+
link.click();
|
104 |
+
document.body.removeChild(link);
|
105 |
+
});
|
106 |
+
</script>
|
|
|
|
|
|
|
|
|
107 |
</body>
|
108 |
+
</html>
|