DmitrMakeev commited on
Commit
60a5e51
·
verified ·
1 Parent(s): abc4e01

Update builder.html

Browse files
Files changed (1) hide show
  1. builder.html +82 -21
builder.html CHANGED
@@ -5,10 +5,9 @@
5
  <title>GrapesJS</title>
6
  <link rel="stylesheet" href="https://unpkg.com/grapesjs/dist/css/grapes.min.css">
7
  <script src="https://unpkg.com/grapesjs"></script>
8
-
9
- <script src="https://unpkg.com/grapesjs-custom-code/dist/grapesjs-custom-code.min.js"></script>
10
-
11
-
12
  <style>
13
  body,
14
  html {
@@ -32,7 +31,8 @@
32
  This is a demo content from index.html. For the development, you shouldn't edit this file, instead you can
33
  copy and rename it to _index.html, on next server start the new file will be served, and it will be ignored by git.
34
  </div>
35
- <button class="add-button">Ещё добавь</button>
 
36
  </div>
37
  <style>
38
  .panel {
@@ -125,13 +125,11 @@
125
  ],
126
  },
127
  });
128
-
129
  // Add blocks for each element
130
  editor.BlockManager.add('welcome-block', {
131
  label: 'Welcome Title',
132
  content: `<h1 class="welcome">Welcome to</h1>`
133
  });
134
-
135
  editor.BlockManager.add('big-title-block', {
136
  label: 'Big Title',
137
  content: `
@@ -143,33 +141,96 @@
143
  </div>
144
  `
145
  });
146
-
147
  editor.BlockManager.add('description-block', {
148
  label: 'Description',
149
  content: `<div class="description">This is a demo content from index.html. For the development, you shouldn't edit this file, instead you can copy and rename it to _index.html, on next server start the new file will be served, and it will be ignored by git.</div>`
150
  });
151
-
152
  editor.BlockManager.add('button-block', {
153
  label: 'Add Button',
154
  content: `<button class="add-button">Ещё добавь</button>`
155
  });
156
  </script>
157
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
- <script type="text/javascript">
161
- var editor = grapesjs.init({
162
- container : '#gjs',
163
- ...
164
- plugins: ['grapesjs-custom-code'],
165
- pluginsOpts: {
166
- 'grapesjs-custom-code': {
167
- // options
168
  }
169
- }
170
- });
171
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
-
 
 
 
 
 
 
 
 
174
  </body>
175
  </html>
 
5
  <title>GrapesJS</title>
6
  <link rel="stylesheet" href="https://unpkg.com/grapesjs/dist/css/grapes.min.css">
7
  <script src="https://unpkg.com/grapesjs"></script>
8
+ <script src="https://unpkg.com/grapesjs-custom-code/dist/grapesjs-custom-code.min.js"></script>
9
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
10
+ <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
 
11
  <style>
12
  body,
13
  html {
 
31
  This is a demo content from index.html. For the development, you shouldn't edit this file, instead you can
32
  copy and rename it to _index.html, on next server start the new file will be served, and it will be ignored by git.
33
  </div>
34
+ <button class="add-button" onclick="addCustomScript()">Добавить свой скрипт</button>
35
+ <button class="add-button" onclick="exportHtml()">Скачать HTML</button>
36
  </div>
37
  <style>
38
  .panel {
 
125
  ],
126
  },
127
  });
 
128
  // Add blocks for each element
129
  editor.BlockManager.add('welcome-block', {
130
  label: 'Welcome Title',
131
  content: `<h1 class="welcome">Welcome to</h1>`
132
  });
 
133
  editor.BlockManager.add('big-title-block', {
134
  label: 'Big Title',
135
  content: `
 
141
  </div>
142
  `
143
  });
 
144
  editor.BlockManager.add('description-block', {
145
  label: 'Description',
146
  content: `<div class="description">This is a demo content from index.html. For the development, you shouldn't edit this file, instead you can copy and rename it to _index.html, on next server start the new file will be served, and it will be ignored by git.</div>`
147
  });
 
148
  editor.BlockManager.add('button-block', {
149
  label: 'Add Button',
150
  content: `<button class="add-button">Ещё добавь</button>`
151
  });
152
  </script>
153
 
154
+ <script type="text/javascript">
155
+ var editor = grapesjs.init({
156
+ container : '#gjs',
157
+ ...
158
+ plugins: ['grapesjs-custom-code'],
159
+ pluginsOpts: {
160
+ 'grapesjs-custom-code': {
161
+ // options
162
+ }
163
+ }
164
+ });
165
+ </script>
166
 
167
+ <script>
168
+ function addCustomScript() {
169
+ Swal.fire({
170
+ title: 'Добавить свой скрипт',
171
+ input: 'textarea',
172
+ inputPlaceholder: 'Введите ваш скрипт здесь...',
173
+ showCancelButton: true,
174
+ confirmButtonText: 'Добавить',
175
+ cancelButtonText: 'Отмена',
176
+ inputValidator: (value) => {
177
+ if (!value) {
178
+ return 'Вы должны ввести скрипт!'
179
+ }
180
+ }
181
+ }).then((result) => {
182
+ if (result.isConfirmed) {
183
+ const script = `<script>${result.value}<\/script>`;
184
+ const htmlCode = editor.getHtml();
185
+ const newHtml = htmlCode + script;
186
+ editor.setComponents(newHtml);
187
+ }
188
+ });
189
+ }
190
+
191
+ function exportHtml() {
192
+ const htmlCode = editor.getHtml();
193
+ const cssCode = editor.getCss();
194
+ const jsCode = editor.getJs();
195
 
196
+ // Собираем выбранные скрипты
197
+ const selectedScripts = [];
198
+ if (document.getElementById('script1-checkbox').checked) {
199
+ selectedScripts.push(document.getElementById('script1-checkbox').value);
 
 
 
 
200
  }
201
+ if (document.getElementById('script2-checkbox').checked) {
202
+ selectedScripts.push(document.getElementById('script2-checkbox').value);
203
+ }
204
+ if (document.getElementById('script3-checkbox').checked) {
205
+ selectedScripts.push(document.getElementById('script3-checkbox').value);
206
+ }
207
+
208
+ // Собираем дополнительные скрипты
209
+ const additionalScripts = selectedScripts.map(script => `<script src="${script}"><\/script>`).join('');
210
+
211
+ // Объединение всего в один HTML-файл
212
+ const fullHtml = `
213
+ <!DOCTYPE html>
214
+ <html>
215
+ <head>
216
+ <style>${cssCode}</style>
217
+ </head>
218
+ <body>
219
+ ${htmlCode}
220
+ <script>${jsCode}<\/script>
221
+ ${additionalScripts}
222
+ </body>
223
+ </html>
224
+ `;
225
 
226
+ // Сохранение HTML-файла
227
+ const blob = new Blob([fullHtml], { type: 'text/html' });
228
+ const url = URL.createObjectURL(blob);
229
+ const a = document.createElement('a');
230
+ a.href = url;
231
+ a.download = 'page.html';
232
+ a.click();
233
+ }
234
+ </script>
235
  </body>
236
  </html>