@innovastudio/contentbox 1.5.58 → 1.5.60
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +6 -3
- package/public/contentbox/contentbox.css +3 -0
- package/public/contentbox/contentbox.esm.js +12110 -2652
- package/public/contentbox/contentbox.min.js +302 -10
- package/public/contentbox/lang/en.js +14 -1
- package/readme.txt +86 -7
- package/README.md +0 -965
package/README.md
DELETED
@@ -1,965 +0,0 @@
|
|
1
|
-
# ContentBox.js
|
2
|
-
|
3
|
-
ContentBox.js is a web page designer. It uses ContentBuilder.js as its HTML editor with added features for page designing. You can use it to create your own CMS or online site builder.
|
4
|
-
|
5
|
-
![Screenshot](docs/contentbox.png)
|
6
|
-
|
7
|
-
## Getting Started
|
8
|
-
|
9
|
-
Include the ContentBuilder css files:
|
10
|
-
|
11
|
-
```html
|
12
|
-
<link href="assets/minimalist-blocks/content.css" rel="stylesheet" type="text/css" /> <!-- for snippets -->
|
13
|
-
<link href="contentbuilder/contentbuilder.css" rel="stylesheet" type="text/css" />
|
14
|
-
```
|
15
|
-
|
16
|
-
and the main ContentBox css file:
|
17
|
-
|
18
|
-
```html
|
19
|
-
<link href="contentbox/contentbox.css" rel="stylesheet" type="text/css" />
|
20
|
-
```
|
21
|
-
|
22
|
-
#### Install as Web Library
|
23
|
-
|
24
|
-
Include the js file:
|
25
|
-
|
26
|
-
```html
|
27
|
-
<script src="contentbox/contentbox.min.js" type="text/javascript"></script>
|
28
|
-
```
|
29
|
-
|
30
|
-
#### Or Install with NPM
|
31
|
-
|
32
|
-
```
|
33
|
-
npm install @innovastudio/contentbox
|
34
|
-
```
|
35
|
-
|
36
|
-
Then import into your project:
|
37
|
-
|
38
|
-
```javascript
|
39
|
-
import ContentBox from '@innovastudio/contentbox';
|
40
|
-
```
|
41
|
-
|
42
|
-
### Asset Files
|
43
|
-
|
44
|
-
Asset files (eg. template or snippet files) are also needed to run the ContentBox. They are located in the **assets** folder in the package.
|
45
|
-
|
46
|
-
**Note**: location of asset related files are flexible and can be configured. For example, you can move the asset files on different server (eg. CDN server).
|
47
|
-
|
48
|
-
## Additional Includes for Viewing Content
|
49
|
-
|
50
|
-
For viewing content, additional includes are also needed.
|
51
|
-
|
52
|
-
On the head section:
|
53
|
-
|
54
|
-
```html
|
55
|
-
<link href="box/box-flex.css" rel="stylesheet" type="text/css" />
|
56
|
-
```
|
57
|
-
|
58
|
-
Before the end of the body tag:
|
59
|
-
|
60
|
-
```html
|
61
|
-
<script src="box/box-flex.js" type="text/javascript"></script>
|
62
|
-
```
|
63
|
-
|
64
|
-
#### If you are upgrading from the previous version of ContentBox
|
65
|
-
|
66
|
-
(this is the same as in the previous version)
|
67
|
-
|
68
|
-
On the head section:
|
69
|
-
|
70
|
-
```html
|
71
|
-
<link href="box/box.css" rel="stylesheet" type="text/css" />
|
72
|
-
```
|
73
|
-
|
74
|
-
Before the end of the body tag:
|
75
|
-
|
76
|
-
```html
|
77
|
-
<script src="path-to/jquery.min.js"></script> /* for running the slider */
|
78
|
-
<script src="box/box.js" type="text/javascript"></script>
|
79
|
-
```
|
80
|
-
|
81
|
-
The JQuery include is needed here because the previous version of ContentBox includes predesigned Sliders (using Slick slider) that require JQuery to run.
|
82
|
-
If you are not using the slider in your content, then you do not need JQuery include and you can change the **box.css** & **box.js** includes with the **box-flex.css** & **box-flex.js** which exclude the JQuery dependency.
|
83
|
-
|
84
|
-
|
85
|
-
## Usage
|
86
|
-
|
87
|
-
```html
|
88
|
-
<div class="is-wrapper">
|
89
|
-
</div>
|
90
|
-
```
|
91
|
-
|
92
|
-
```javascript
|
93
|
-
const builder = new ContentBox({
|
94
|
-
wrapper: '.is-wrapper',
|
95
|
-
});
|
96
|
-
```
|
97
|
-
|
98
|
-
To get the edited content:
|
99
|
-
|
100
|
-
1) Get the HTML content
|
101
|
-
|
102
|
-
```javascript
|
103
|
-
let html = builder.html();
|
104
|
-
```
|
105
|
-
|
106
|
-
2) Get the styles
|
107
|
-
|
108
|
-
```javascript
|
109
|
-
let mainCss = builder.mainCss(); // Returns the default typography style for the page.
|
110
|
-
let sectioncss = builder.sectioncss(); // Returns the typography styles for specific sections on the page
|
111
|
-
```
|
112
|
-
|
113
|
-
Then you can do anything with the content, for example, posting it to the server for saving, etc.
|
114
|
-
|
115
|
-
In production, the saved HTML content should be rendered with its styles.
|
116
|
-
|
117
|
-
### Examples (HTML, PHP, React, Vue)
|
118
|
-
|
119
|
-
ContentBox.js is written in pure Javascript (ES6) so you can use it in most situations. Sample use in simple HTML, PHP, React and Vue projects are included.
|
120
|
-
|
121
|
-
React and Vue project examples are provided in separate downloads in the user area.
|
122
|
-
|
123
|
-
To run the HTML example, open using your browser: **public/example.html** from localhost or from your server.
|
124
|
-
|
125
|
-
## Folder Structure
|
126
|
-
|
127
|
-
- public/
|
128
|
-
- assets/
|
129
|
-
- box/
|
130
|
-
- contentbox/
|
131
|
-
- contentbuilder/
|
132
|
-
- uploads/
|
133
|
-
- example.html (HTML example)
|
134
|
-
- example.php (PHP example)
|
135
|
-
- example-bootstrap.html (using Bootstrap framework)
|
136
|
-
- example-foundation.html (using Foundation framework)
|
137
|
-
- example-jquery.html (HTML example from the previous version using JQuery)
|
138
|
-
- src/
|
139
|
-
- contentbox/ (Only provided in Source Code package)
|
140
|
-
- scss/ (Only provided in Source Code package)
|
141
|
-
- docs/
|
142
|
-
- README.md (Documentation)
|
143
|
-
- readme.txt (Readme file)
|
144
|
-
- readme-sourcecode.txt (Readme file for Source Code package)
|
145
|
-
- ...
|
146
|
-
|
147
|
-
|
148
|
-
## Templates (Predesigned Sections)
|
149
|
-
|
150
|
-
To start building a page, you can click the (+) button on the top left sidebar. This will open a selection of predesigned sections that you can add into your page.
|
151
|
-
|
152
|
-
![Simple Start](docs/predesigned-sections.png)
|
153
|
-
|
154
|
-
![Quick Start](docs/predesigned-sections2.png)
|
155
|
-
|
156
|
-
![All Categories](docs/section-categories.png)
|
157
|
-
|
158
|
-
If you click **ALL CATEGORIES**, 2 sets of templates will be displayed:
|
159
|
-
|
160
|
-
- Simple Start (to start from a basic/clean design)
|
161
|
-
- Quick Start (to start with examples)
|
162
|
-
|
163
|
-
These 2 set of templates are located in the folder:
|
164
|
-
|
165
|
-
- **assets/simplestart/**
|
166
|
-
- **assets/quickstart/**
|
167
|
-
|
168
|
-
Each folder contains:
|
169
|
-
|
170
|
-
- templates.js (a JSON file containing a list of ready made designs)
|
171
|
-
- images/ (contains assets for the designs)
|
172
|
-
- preview/ (contains design thumbnails)
|
173
|
-
|
174
|
-
The templates are loaded using the following configuration:
|
175
|
-
|
176
|
-
```javascript
|
177
|
-
const builder = new ContentBox({
|
178
|
-
wrapper: '.is-wrapper',
|
179
|
-
templates: [
|
180
|
-
{
|
181
|
-
url: 'assets/simplestart/templates.js',
|
182
|
-
path: 'assets/simplestart/',
|
183
|
-
pathReplace: [ ]
|
184
|
-
},
|
185
|
-
{
|
186
|
-
url: 'assets/quickstart/templates.js',
|
187
|
-
path: 'assets/quickstart/',
|
188
|
-
pathReplace: [ ]
|
189
|
-
},
|
190
|
-
],
|
191
|
-
});
|
192
|
-
```
|
193
|
-
Using the **templates** parameter, you can configure the template file (**url**), the asset location (**path**), and optionally, use **pathReplace** property to replace string found on the template file.
|
194
|
-
|
195
|
-
Here is an example of a different assets location:
|
196
|
-
|
197
|
-
```javascript
|
198
|
-
const builder = new ContentBox({
|
199
|
-
wrapper: '.is-wrapper',
|
200
|
-
templates: [
|
201
|
-
{
|
202
|
-
url: 'https://path-to/assets/simplestart/templates.js',
|
203
|
-
path: 'https://path-to/assets/simplestart/',
|
204
|
-
pathReplace: [ ]
|
205
|
-
},
|
206
|
-
{
|
207
|
-
url: 'https://path-to/assets/quickstart/templates.js',
|
208
|
-
path: 'https://path-to/assets/quickstart/',
|
209
|
-
pathReplace: [ ]
|
210
|
-
},
|
211
|
-
],
|
212
|
-
});
|
213
|
-
```
|
214
|
-
|
215
|
-
#### For old version of ContentBox
|
216
|
-
|
217
|
-
In the old ContentBox, you can configure the template location by setting the **designUrl1**, **designUrl2** and **designPath** parameters. These still work. Note that in the old version, templates are located in **assets/designs/** folder.
|
218
|
-
|
219
|
-
```javascript
|
220
|
-
const builder = new ContentBox({
|
221
|
-
wrapper: '.is-wrapper',
|
222
|
-
designUrl1: 'assets/designs/basic.js',
|
223
|
-
designUrl2: 'assets/designs/examples.js',
|
224
|
-
designPath: 'assets/designs/',
|
225
|
-
});
|
226
|
-
```
|
227
|
-
In case of a different assets location, path adjustment may be needed. Here you can use the **designPathReplace** parameter.
|
228
|
-
|
229
|
-
Example:
|
230
|
-
|
231
|
-
```javascript
|
232
|
-
const builder = new ContentBox({
|
233
|
-
wrapper: '.is-wrapper',
|
234
|
-
designUrl1: 'https://path-to/assets/designs/basic.js',
|
235
|
-
designUrl2: 'https://path-to/assets/designs/examples.js',
|
236
|
-
designPath: 'https://path-to/assets/designs/',
|
237
|
-
designPathReplace: ['assets/designs/', 'https://path-to/assets/designs/'], // replace the default path to the new location
|
238
|
-
});
|
239
|
-
```
|
240
|
-
In this example, the default location is changed to https://path-to/assets/designs/
|
241
|
-
|
242
|
-
With this, you can place all the assets in a separate server or different host (e.g. from a CDN).
|
243
|
-
|
244
|
-
### Template Files
|
245
|
-
|
246
|
-
Let’s see one of the template file, the Simple Start template: assets/simplestart/templates.js.
|
247
|
-
|
248
|
-
```javascript
|
249
|
-
var data_templates = {
|
250
|
-
name: 'Simple Start',
|
251
|
-
categories: [
|
252
|
-
{ id: 1, name: 'Basic' },
|
253
|
-
{ id: 2, name: 'Slider' },
|
254
|
-
{ id: 3, name: 'Video' },
|
255
|
-
{ id: 4, name: 'Custom' },
|
256
|
-
],
|
257
|
-
designs: [
|
258
|
-
|
259
|
-
{
|
260
|
-
'thumbnail': 'preview/simple-01.png',
|
261
|
-
'category': '1',
|
262
|
-
'contentCss': 'type-poppins.css',
|
263
|
-
'contentClass': 'type-poppins',
|
264
|
-
'html': `
|
265
|
-
<div class="is-section is-box is-section-100 type-poppins">
|
266
|
-
...
|
267
|
-
</div>`
|
268
|
-
},
|
269
|
-
// ...
|
270
|
-
|
271
|
-
]
|
272
|
-
};
|
273
|
-
|
274
|
-
try {
|
275
|
-
template_list.push(data_templates);
|
276
|
-
} catch(e) {
|
277
|
-
//
|
278
|
-
}
|
279
|
-
```
|
280
|
-
|
281
|
-
With the same format, you can create your own template set and load it in ContentBox.
|
282
|
-
|
283
|
-
In this JSON format, you can define the template set **name**, **categories**, and the template collection (**designs**).
|
284
|
-
|
285
|
-
Ini this set, we have 4 categories:
|
286
|
-
1. Basic
|
287
|
-
2. Slider
|
288
|
-
3. Video
|
289
|
-
4. Custom
|
290
|
-
|
291
|
-
For each section template, you need to specify:
|
292
|
-
|
293
|
-
- **thumbnail**
|
294
|
-
- **category**: see the **categories** definition **id**.
|
295
|
-
- **contentCss**: css file for typography (there are many css files you can choose from **assets/styles/** folder. Please choose the file with prefix **type-*****.
|
296
|
-
- **contentClass**: css class name (just use the css file name without extension)
|
297
|
-
- **html**: the HTML template.
|
298
|
-
Within the html, you can use **[%IMAGE_PATH%]** tag that will be replaced with the asset location/path. For example:
|
299
|
-
```html
|
300
|
-
<img src="[%IMAGE_PATH%]images/photo.jpg">
|
301
|
-
```
|
302
|
-
will become:
|
303
|
-
```html
|
304
|
-
<img src="assets/simplestart/images/photo.jpg">
|
305
|
-
```
|
306
|
-
|
307
|
-
Let's the other template file, the Quick Start template: **assets/quickstart/templates.js**.
|
308
|
-
|
309
|
-
```javascript
|
310
|
-
var data_templates = {
|
311
|
-
name: 'Simple Start',
|
312
|
-
categories: [
|
313
|
-
{ id: 1, name: 'Basic' },
|
314
|
-
{ id: 2, name: 'Slider' },
|
315
|
-
{ id: 3, name: 'Video' },
|
316
|
-
{ id: 4, name: 'Custom' },
|
317
|
-
],
|
318
|
-
designs: [
|
319
|
-
|
320
|
-
{
|
321
|
-
'thumbnail': 'preview/simple-01.png',
|
322
|
-
'category': '1',
|
323
|
-
'contentCss': 'type-poppins.css',
|
324
|
-
'contentClass': 'type-poppins',
|
325
|
-
'html': `
|
326
|
-
<div class="is-section is-box is-section-100 type-poppins">
|
327
|
-
...
|
328
|
-
</div>`
|
329
|
-
},
|
330
|
-
// ...
|
331
|
-
|
332
|
-
]
|
333
|
-
};
|
334
|
-
|
335
|
-
try {
|
336
|
-
template_list.push(data_templates);
|
337
|
-
} catch(e) {
|
338
|
-
//
|
339
|
-
}
|
340
|
-
```
|
341
|
-
|
342
|
-
Ini this set, we have 18 categories, from Header, Article, to Footer.
|
343
|
-
|
344
|
-
The two template files (**assets/simplestart/templates.js** and **assets/quickstart/templates.js**) are loaded by registering them in the **templates** parameter:
|
345
|
-
|
346
|
-
|
347
|
-
```javascript
|
348
|
-
const builder = new ContentBox({
|
349
|
-
wrapper: '.is-wrapper',
|
350
|
-
templates: [
|
351
|
-
{
|
352
|
-
url: 'assets/simplestart/templates.js',
|
353
|
-
path: 'assets/simplestart/',
|
354
|
-
pathReplace: [ ]
|
355
|
-
},
|
356
|
-
{
|
357
|
-
url: 'assets/quickstart/templates.js',
|
358
|
-
path: 'assets/quickstart/',
|
359
|
-
pathReplace: [ ]
|
360
|
-
},
|
361
|
-
],
|
362
|
-
});
|
363
|
-
```
|
364
|
-
|
365
|
-
Template loading is asynchronous so it won’t block the initial page loading. In this configuration, we load the **simplestart/templates.js** set first and then the **quickstart/templates.js**.
|
366
|
-
|
367
|
-
#### Featuring Certain Categories
|
368
|
-
|
369
|
-
You can feature certain categories that will be displayed on the front using **featuredCategories** parameter:
|
370
|
-
|
371
|
-
```javascript
|
372
|
-
const builder = new ContentBox({
|
373
|
-
// ...
|
374
|
-
|
375
|
-
featuredCategories: [
|
376
|
-
{ id: 1, designId: 1, name: 'Basic' },
|
377
|
-
{ id: 2, designId: 1, name: 'Slider' },
|
378
|
-
{ id: 1, designId: 2, name: 'Header' },
|
379
|
-
{ id: 2, designId: 2, name: 'Article' },
|
380
|
-
{ id: 3, designId: 2, name: 'Photos' },
|
381
|
-
],
|
382
|
-
});
|
383
|
-
```
|
384
|
-
|
385
|
-
The **simplestart** set has designId=1 and the **quickstart** set has designId=2 (according to the load order).
|
386
|
-
|
387
|
-
The **id** refers to the category id.
|
388
|
-
|
389
|
-
Then choose which category to display on the first open:
|
390
|
-
|
391
|
-
```javascript
|
392
|
-
const builder = new ContentBox({
|
393
|
-
// ...
|
394
|
-
|
395
|
-
defaultCategory: {
|
396
|
-
id: 1,
|
397
|
-
designId: 1
|
398
|
-
},
|
399
|
-
});
|
400
|
-
```
|
401
|
-
|
402
|
-
Here we choose the **Basic** category (id: 1), from the **simplestart** set (designId: 1).
|
403
|
-
|
404
|
-
![Featured Categories](docs/featured-categories.png)
|
405
|
-
|
406
|
-
#### Adjusting the thumbnail size
|
407
|
-
|
408
|
-
To adjust the template’s thumbnail size, use **templateThumbnailSize** parameter:
|
409
|
-
|
410
|
-
```javascript
|
411
|
-
const builder = new ContentBox({
|
412
|
-
...
|
413
|
-
|
414
|
-
templateThumbnailSize: 'small',
|
415
|
-
});
|
416
|
-
```
|
417
|
-
|
418
|
-
The default is empty string (means dynamic or auto adjust based on the screen size).
|
419
|
-
For specific size, use: **small**, **medium**, or **large**.
|
420
|
-
|
421
|
-
![Small](docs/template-small.png)
|
422
|
-
|
423
|
-
Small
|
424
|
-
|
425
|
-
![Medium](docs/template-medium.png)
|
426
|
-
|
427
|
-
Medium
|
428
|
-
|
429
|
-
![Large](docs/template-large.png)
|
430
|
-
|
431
|
-
Large
|
432
|
-
|
433
|
-
## Snippets
|
434
|
-
|
435
|
-
Snippets are predesigned blocks that you can add or drag & drop into your content.
|
436
|
-
|
437
|
-
Snippet selection can be opened from the left sidebar.
|
438
|
-
|
439
|
-
![Snippets](docs/snippets.png)
|
440
|
-
|
441
|
-
Snippet files are located in the folder:
|
442
|
-
|
443
|
-
assets/minimalist-blocks/
|
444
|
-
|
445
|
-
It contains:
|
446
|
-
- content.js (snippets JSON file)
|
447
|
-
- content.css (snippets css file)
|
448
|
-
- images (contains assets for the snippets)
|
449
|
-
- preview (contains snippet thumbnails)
|
450
|
-
|
451
|
-
You can configure the snippets location by setting the **snippetUrl** and **snippetPath** parameters:
|
452
|
-
|
453
|
-
```javascript
|
454
|
-
const builder = new ContentBox({
|
455
|
-
wrapper: '.is-wrapper',
|
456
|
-
snippetUrl: 'assets/minimalist-blocks/content.js', // Snippet file
|
457
|
-
snippetPath: 'assets/minimalist-blocks/', // Location of snippets' assets
|
458
|
-
});
|
459
|
-
```
|
460
|
-
|
461
|
-
In case of a different location, path adjustment may be needed. Here you can use the **snippetPathReplace** parameter.
|
462
|
-
|
463
|
-
Example:
|
464
|
-
|
465
|
-
```javascript
|
466
|
-
const builder = new ContentBox({
|
467
|
-
wrapper: '.is-wrapper',
|
468
|
-
snippetUrl: 'https://path-to/assets/minimalist-blocks/content.js', // Snippet file
|
469
|
-
snippetPath: 'https://path-to/assets/minimalist-blocks/', // Location of snippets' assets
|
470
|
-
snippetPathReplace: ['assets/', 'https://path-to/assets/'], // replace the default path to the new location
|
471
|
-
});
|
472
|
-
```
|
473
|
-
|
474
|
-
In this example, the default location is changed to https://path-to/assets/minimalist-blocks/
|
475
|
-
|
476
|
-
With this, you can place all the snippet assets in a separate server or different host (e.g. from a CDN).
|
477
|
-
|
478
|
-
## Typography Styles
|
479
|
-
|
480
|
-
A selection of typography styles is provided for you to choose to format your page. The selection can be opened from the left sidebar.
|
481
|
-
|
482
|
-
![Typography Styles](docs/typography.png)
|
483
|
-
|
484
|
-
The style can be used to format the entire page or just a specific section of your page.
|
485
|
-
|
486
|
-
To apply the typography style to a specific box area, open the Box Settings dialog, select the 'Text' tab and click 'Change Style'.
|
487
|
-
|
488
|
-
![Apply to a specific section](docs/typography2.png)
|
489
|
-
|
490
|
-
This will re-open the typography selection and your selection will be applied to the chosen box area only.
|
491
|
-
|
492
|
-
Typography style files are located in the folder:
|
493
|
-
|
494
|
-
**assets/styles/**
|
495
|
-
|
496
|
-
It contains all the css needed and its preview images. You can change its location using the **contentStylePath** parameter.
|
497
|
-
|
498
|
-
```javascript
|
499
|
-
const builder = new ContentBox({
|
500
|
-
wrapper: '.is-wrapper',
|
501
|
-
contentStylePath: 'assets/styles/',
|
502
|
-
});
|
503
|
-
```
|
504
|
-
|
505
|
-
### Slider Feature
|
506
|
-
|
507
|
-
The new version includes predesigned slider templates (using Glide slider) that require some includes:
|
508
|
-
|
509
|
-
```html
|
510
|
-
<link href="assets/scripts/glide/css/glide.core.css" rel="stylesheet" type="text/css" />
|
511
|
-
<link href="assets/scripts/glide/css/glide.theme.css" rel="stylesheet" type="text/css" />
|
512
|
-
<script src="assets/scripts/glide/glide.js" type="text/javascript"></script>
|
513
|
-
```
|
514
|
-
To enable the slider:
|
515
|
-
|
516
|
-
```javascript
|
517
|
-
const builder = new ContentBox({
|
518
|
-
/*...*/
|
519
|
-
slider: 'glide' // default: 'slick' (old version slider)
|
520
|
-
});
|
521
|
-
```
|
522
|
-
|
523
|
-
Values:
|
524
|
-
- '' (default) => not using slider
|
525
|
-
- 'glide'
|
526
|
-
- 'slick' => previous version slider (requires JQuery)
|
527
|
-
|
528
|
-
## Language File
|
529
|
-
|
530
|
-
With the Language file, you can translate the ContentBox.js interface into another language.
|
531
|
-
|
532
|
-
The language file is located in:
|
533
|
-
|
534
|
-
- contentbuilder/lang/en.js
|
535
|
-
|
536
|
-
To enable the language file, you need to add the file before including ContentBox.js:
|
537
|
-
|
538
|
-
```javascript
|
539
|
-
<script src="contentbox/lang/en.js" type="text/javascript"></script>
|
540
|
-
```
|
541
|
-
|
542
|
-
Here is the language file content as seen on en.js:
|
543
|
-
```javascript
|
544
|
-
var _txt = new Array();
|
545
|
-
_txt['Bold'] = 'Bold';
|
546
|
-
_txt['Italic'] = 'Italic';
|
547
|
-
```
|
548
|
-
|
549
|
-
You can create your own language file by copying/modifying this file.
|
550
|
-
|
551
|
-
## Adding Custom Buttons on the Sidebar
|
552
|
-
|
553
|
-
To add custom buttons on the sidebar, use the **addButton** method.
|
554
|
-
|
555
|
-
Here is an example of adding the Undo & Redo button. For the undo and redo operation, we call the **undo()** and **redo()** methods.
|
556
|
-
|
557
|
-
```javascript
|
558
|
-
builder.addButton({
|
559
|
-
'pos': 2, // button position
|
560
|
-
'title': 'Undo', // title
|
561
|
-
'html': '<svg class="is-icon-flex" style="width:14px;height:14px;"><use xlink:href="#ion-ios-undo"></use></svg>', // icon
|
562
|
-
'onClick': ()=>{
|
563
|
-
builder.undo();
|
564
|
-
}
|
565
|
-
});
|
566
|
-
|
567
|
-
builder.addButton({
|
568
|
-
'pos': 3, // button position
|
569
|
-
'title': 'Redo', // title
|
570
|
-
'html': '<svg class="is-icon-flex" style="width:14px;height:14px;"><use xlink:href="#ion-ios-redo"></use></svg>', // icon
|
571
|
-
'onClick': ()=>{
|
572
|
-
builder.redo();
|
573
|
-
}
|
574
|
-
});
|
575
|
-
```
|
576
|
-
|
577
|
-
The **addButton** method has 4 parameters:
|
578
|
-
|
579
|
-
- pos (position of the button)
|
580
|
-
- title
|
581
|
-
- html (to specify the icon for the button)
|
582
|
-
- onClick
|
583
|
-
|
584
|
-
Here is another example for adding a Preview button. If clicked, the button will open a separate page (**preview.html**) that we use to preview our edited page as in production.
|
585
|
-
|
586
|
-
```javascript
|
587
|
-
builder.addButton({
|
588
|
-
'pos': 5,
|
589
|
-
'title': 'Preview',
|
590
|
-
'html': '<svg class="is-icon-flex" style="width:16px;height:16px;"><use xlink:href="#ion-eye"></use></svg>',
|
591
|
-
'onClick': ()=>{
|
592
|
-
|
593
|
-
var html = builder.html();
|
594
|
-
localStorage.setItem('preview-html', html);
|
595
|
-
var mainCss = builder.mainCss();
|
596
|
-
localStorage.setItem('preview-maincss', mainCss);
|
597
|
-
var sectionCss = builder.sectionCss();
|
598
|
-
localStorage.setItem('preview-sectioncss', sectionCss);
|
599
|
-
|
600
|
-
window.open('/preview.html', '_blank').focus();
|
601
|
-
}
|
602
|
-
});
|
603
|
-
```
|
604
|
-
|
605
|
-
Here we get the content and its styles using the **html()**, **mainCss()**, and **sectionCss()** methods and save them into the browser's local storage. The content will then be used in the **preview.html** for viewing.
|
606
|
-
|
607
|
-
## Embedding Box Cover (Background) Image
|
608
|
-
|
609
|
-
In the Box Settings, you can specify a box's cover or background image.
|
610
|
-
|
611
|
-
![Box Cover](docs/box-cover.png)
|
612
|
-
|
613
|
-
However, to quickly upload an image without opening the Box Settings, you can click the box image button. This allows you to browse local images and select an image to upload as a box image cover (background).
|
614
|
-
|
615
|
-
![Box Cover](docs/box-cover2.png)
|
616
|
-
|
617
|
-
![Box Cover](docs/box-cover3.png)
|
618
|
-
|
619
|
-
There are 2 methods for uploading cover image:
|
620
|
-
|
621
|
-
1. Form Method
|
622
|
-
2. AJAX Post Method
|
623
|
-
|
624
|
-
#### Form Method
|
625
|
-
|
626
|
-
Here we use the **coverImageHandler** parameter to specify the upload handler for saving images on the server.
|
627
|
-
|
628
|
-
```javascript
|
629
|
-
const builder = new ContentBox({
|
630
|
-
wrapper: '.is-wrapper',
|
631
|
-
coverImageHandler: 'savecover.php',
|
632
|
-
});
|
633
|
-
```
|
634
|
-
|
635
|
-
As examples, you can use the provided handler:
|
636
|
-
|
637
|
-
- savecover.php (for PHP)
|
638
|
-
- savecover.ashx (for ASP.NET)
|
639
|
-
|
640
|
-
|
641
|
-
#### AJAX Post Method
|
642
|
-
|
643
|
-
Here we use the **onUploadCoverImage** parameter to specify a custom upload function.
|
644
|
-
|
645
|
-
```javascript
|
646
|
-
const builder = new ContentBox({
|
647
|
-
wrapper: '.is-wrapper',
|
648
|
-
onUploadCoverImage: (e) => {
|
649
|
-
uploadFile(e, (response)=>{
|
650
|
-
const uploadedImageUrl = response.url; // get saved image url
|
651
|
-
builder.boxImage(uploadedImageUrl); // change cover image
|
652
|
-
});
|
653
|
-
},
|
654
|
-
});
|
655
|
-
|
656
|
-
function uploadFile(e, callback) {
|
657
|
-
|
658
|
-
const selectedFile = e.target.files[0];
|
659
|
-
|
660
|
-
const formData = new FormData();
|
661
|
-
formData.append('file', selectedFile);
|
662
|
-
fetch('/upload', {
|
663
|
-
method: 'POST',
|
664
|
-
body: formData,
|
665
|
-
})
|
666
|
-
.then(response=>response.json())
|
667
|
-
.then(response=>{
|
668
|
-
console.log(response)
|
669
|
-
if(callback) callback(response);
|
670
|
-
});
|
671
|
-
}
|
672
|
-
```
|
673
|
-
|
674
|
-
The example above uses the **boxImage(url)** method to apply the image url as a background cover.
|
675
|
-
|
676
|
-
In the example, the image is posted to an endpoint: **/upload**
|
677
|
-
If you’re using Node.js, you can implement the endpoint to save the image using:
|
678
|
-
|
679
|
-
```javascript
|
680
|
-
const express = require('express');
|
681
|
-
const fs = require('fs');
|
682
|
-
const app = express();
|
683
|
-
const path = require('path');
|
684
|
-
const cors = require('cors');
|
685
|
-
const serveStatic = require('serve-static');
|
686
|
-
const formidable = require('formidable-serverless');
|
687
|
-
const sharp = require('sharp');
|
688
|
-
|
689
|
-
//Specify url path
|
690
|
-
var $path = __dirname + '/public/uploads/'; // Physical path
|
691
|
-
var $urlpath = 'uploads/'; // URL path
|
692
|
-
|
693
|
-
app.use(cors());
|
694
|
-
app.use(express.urlencoded({
|
695
|
-
extended: true
|
696
|
-
}));
|
697
|
-
app.use(express.json({ limit: '50mb' }));
|
698
|
-
app.use(serveStatic(path.join(__dirname, '/public')));
|
699
|
-
|
700
|
-
app.post('/upload', (req, res) => {
|
701
|
-
|
702
|
-
const form = new formidable.IncomingForm();
|
703
|
-
form.parse(req, async (err, fields, files) => {
|
704
|
-
|
705
|
-
if (err) return res.status(500).json({ ok:true, status: 500, error: 'Something went wrong.' });
|
706
|
-
|
707
|
-
let extension = path.extname(files.file.name).toLowerCase();
|
708
|
-
if(extension !== '.jpeg' && extension !== '.jpg' && extension !== '.png' && extension !== '.gif' && extension !== '.webp' && extension !== '.webm' && extension !== '.mp4') {
|
709
|
-
res.status(500).json({ ok:true, status: 500, error: 'File type not allowed.' });
|
710
|
-
return;
|
711
|
-
}
|
712
|
-
|
713
|
-
const file = fs.readFileSync(files.file.path);
|
714
|
-
|
715
|
-
let imageFile = file;
|
716
|
-
if(extension === '.jpeg' || extension === '.jpg') {
|
717
|
-
imageFile = await sharp(files.file.path).resize(1600, 1600, {
|
718
|
-
fit: sharp.fit.inside,
|
719
|
-
withoutEnlargement: true,
|
720
|
-
})
|
721
|
-
.jpeg({ quality: 80, progressive: true, force: false })
|
722
|
-
.toBuffer();
|
723
|
-
}
|
724
|
-
|
725
|
-
fs.writeFile($path + files.file.name, imageFile, async (err)=>{
|
726
|
-
if (err) {
|
727
|
-
res.status(500).json({ ok:true, status: 500, error: 'Something went wrong.' });
|
728
|
-
return
|
729
|
-
}
|
730
|
-
res.status(200).json({ ok:true, status: 200, url: $urlpath + files.file.name});
|
731
|
-
});
|
732
|
-
|
733
|
-
});
|
734
|
-
|
735
|
-
});
|
736
|
-
```
|
737
|
-
|
738
|
-
## Programmatically Load the Content
|
739
|
-
|
740
|
-
Content consists of HTML and its styles (e.g. typography styles/css includes). As explained previously, you get the edited content using the following methods:
|
741
|
-
|
742
|
-
1) To get the HTML
|
743
|
-
|
744
|
-
```javascript
|
745
|
-
let html = builder.html();
|
746
|
-
```
|
747
|
-
|
748
|
-
2) To get the styles
|
749
|
-
|
750
|
-
```javascript
|
751
|
-
let mainCss = builder.mainCss(); // Returns the default typography style for the page.
|
752
|
-
let sectioncss = builder.sectioncss(); // Returns the typography styles for specific sections on the page
|
753
|
-
```
|
754
|
-
You can save the HTML and its styles above into a database. And when you need to load the content back for editing, use the **loadHtml()** and **loadStyles** methods.
|
755
|
-
|
756
|
-
```javascript
|
757
|
-
builder.loadHtml(html);
|
758
|
-
builder.loadStyles(mainCss, sectionCss);
|
759
|
-
```
|
760
|
-
|
761
|
-
## Undo & Redo
|
762
|
-
|
763
|
-
You can programmatically perform an undo or redo action.
|
764
|
-
|
765
|
-
To undo:
|
766
|
-
|
767
|
-
```javascript
|
768
|
-
builder.undo();
|
769
|
-
```
|
770
|
-
|
771
|
-
To redo:
|
772
|
-
|
773
|
-
```javascript
|
774
|
-
builder.redo();
|
775
|
-
```
|
776
|
-
|
777
|
-
## Destroy
|
778
|
-
|
779
|
-
To destroy the ContentBox:
|
780
|
-
|
781
|
-
```javascript
|
782
|
-
builder.destroy();
|
783
|
-
```
|
784
|
-
|
785
|
-
## ContentBuilder.js Features
|
786
|
-
|
787
|
-
ContentBox.js uses ContentBuilder.js as its HTML editor. So most of the ContentBuilder.js options/parameters can be accessed through the ContentBox.js object.
|
788
|
-
|
789
|
-
For example, to specify a custom file browser (or Asset Manager):
|
790
|
-
|
791
|
-
```javascript
|
792
|
-
const builder = new ContentBox({
|
793
|
-
wrapper: '.is-wrapper',
|
794
|
-
imageSelect: 'assets.html',
|
795
|
-
fileSelect: 'assets.html',
|
796
|
-
videoSelect: 'assets.html',
|
797
|
-
});
|
798
|
-
```
|
799
|
-
|
800
|
-
And to specify custom upload functions:
|
801
|
-
|
802
|
-
```javascript
|
803
|
-
const builder = new ContentBox({
|
804
|
-
wrapper: '.is-wrapper',
|
805
|
-
|
806
|
-
onMediaUpload: (e)=>{
|
807
|
-
...
|
808
|
-
},
|
809
|
-
onVideoUpload: (e)=>{
|
810
|
-
...
|
811
|
-
},
|
812
|
-
});
|
813
|
-
```
|
814
|
-
|
815
|
-
#### Preview
|
816
|
-
|
817
|
-
The editing toolbar from ContentBuilder.js has a **Preview** button to view the page result in a modal.
|
818
|
-
In ContentBox, you can define the preview URL using **previewURL** parameter. The default value is ‘preview.html’.
|
819
|
-
|
820
|
-
```javascript
|
821
|
-
const builder = new ContentBox({
|
822
|
-
wrapper: '.is-wrapper',
|
823
|
-
|
824
|
-
previewURL: 'preview.html'
|
825
|
-
});
|
826
|
-
```
|
827
|
-
|
828
|
-
![Preview Button](docs/cb-preview.png)
|
829
|
-
|
830
|
-
The preview.html is used to view the edited page result (without the builder). The file is located in **public** folder.
|
831
|
-
|
832
|
-
More configuration options can be found in the ContentBuilder.js documentation:
|
833
|
-
|
834
|
-
https://innovastudio.com/docs/contentbuilder.pdf
|
835
|
-
|
836
|
-
## Extending ContentBox with Custom Panel for Adding Custom Content
|
837
|
-
|
838
|
-
We will look on how to add a button on the sidebar that opens a custom panel. You can create your own custom panel by creating a simple html page. In this example, we will have a panel with multiple buttons that can add a custom content/section into your page. You can try the example in the package by opening: **public/example-custom.html**. (from localhost or from your server).
|
839
|
-
|
840
|
-
![Extending ContentBox](docs/extending.png)
|
841
|
-
|
842
|
-
Click the buttons to try adding a new custom content/section into the page.
|
843
|
-
|
844
|
-
Let’s look at the code.
|
845
|
-
|
846
|
-
To add a button on the sidebar, use **addButton()** method (this method has been explained in the previous chapter: **Adding Custom Buttons on the Sidebar**):
|
847
|
-
|
848
|
-
```javascript
|
849
|
-
builder.addButton({
|
850
|
-
'pos': 0,
|
851
|
-
'title': 'Products',
|
852
|
-
'src': 'mypanel.html',
|
853
|
-
'html': '<svg style="width:17px;height:17px;" viewBox="0 0 2048 2048" xmlns="http://www.w3.org/2000/svg">' +
|
854
|
-
'<g id="document" transform="matrix(1,0,0,1,1024.0,1024.0)"><path d="M178.271,508.452 L303.32,508.452 L303.32,-735.688 L178.271,-735.688 L178.271,508.452 Z " fill="#000000" fill-opacity="1.00" /><path d="M862.865,-51.0932 L862.865,-176.143 L-381.274,-176.143 L-381.274,-51.0933 L862.865,-51.0932 Z " fill="#000000" fill-opacity="1.00" /><path d="M-1020.43,275.099 L-1020.43,400.148 L-85.2735,400.148 L-85.2735,275.099 L-1020.43,275.099 Z " fill="#000000" fill-opacity="1.00" /><path d="M-1020.43,559.907 L-1020.43,684.956 L-85.2735,684.956 L-85.2735,559.907 L-1020.43,559.907 Z " fill="#000000" fill-opacity="1.00" /><path d="M-1024,844.714 L-1024,969.764 L-88.8389,969.764 L-88.8389,844.714 L-1024,844.714 Z " fill="#000000" fill-opacity="1.00" /></g>' +
|
855
|
-
'</svg>',
|
856
|
-
'class': 'sidebar-sections'
|
857
|
-
});
|
858
|
-
```
|
859
|
-
|
860
|
-
The **src** property is set with your custom html page, **mypanel.html**. This simple html page contains the buttons for adding content. Each button simply calls the **addSection()** method.
|
861
|
-
|
862
|
-
|
863
|
-
```javascript
|
864
|
-
parent.contentbox.addSection(html, css)
|
865
|
-
```
|
866
|
-
|
867
|
-
The **addSection()** method accepts two parameters:
|
868
|
-
|
869
|
-
- **html**: your content
|
870
|
-
- **css**: css file for typography that you can choose from the folder **assets/styles/**
|
871
|
-
(choose the file with prefix **type-**).
|
872
|
-
|
873
|
-
Example:
|
874
|
-
|
875
|
-
```javascript
|
876
|
-
parent.contentbox.addSection(`
|
877
|
-
<div class="is-section is-box is-section-100 type-rufina-oxygen">
|
878
|
-
<div class="is-boxes">
|
879
|
-
<div class="is-box-centered">
|
880
|
-
|
881
|
-
<div class="is-container v2 is-content-960 leading-13 size-17">
|
882
|
-
<div class="row">
|
883
|
-
<div class="column full">
|
884
|
-
<h1 class="text-center leading-09 size-92">Product One</h1>
|
885
|
-
</div>
|
886
|
-
</div>
|
887
|
-
</div>
|
888
|
-
|
889
|
-
</div>
|
890
|
-
</div>
|
891
|
-
</div>
|
892
|
-
`, 'type-rufina-oxygen.css');
|
893
|
-
```
|
894
|
-
|
895
|
-
Here we choose **type-rufina-oxygen.css** for the typography css. Then we added **type-rufina-oxygen** class in the **div.is-section** element. This will format the content with the Rufina & Oxygen fonts.
|
896
|
-
|
897
|
-
```html
|
898
|
-
<div class="is-section is-box is-section-100 type-rufina-oxygen">
|
899
|
-
...
|
900
|
-
</div>
|
901
|
-
```
|
902
|
-
|
903
|
-
Use the same format as in the example if you want to create your own content. Please leave the other classes in the example as they are needed by ContentBox to format the content.
|
904
|
-
|
905
|
-
To make the content protected (non editable), please add **protected** class on the **div.is-section**. and do not use **is-container** class. The **is-container** class is used for text content inside the section and it is always editable.
|
906
|
-
|
907
|
-
```html
|
908
|
-
<div class="is-section is-box is-section-100 type-rufina-oxygen protected">
|
909
|
-
...
|
910
|
-
</div>
|
911
|
-
```
|
912
|
-
|
913
|
-
If you need to add custom Javascript, please use the following format:
|
914
|
-
|
915
|
-
```html
|
916
|
-
<div class="is-section is-box is-section-100 type-rufina-oxygen protected">
|
917
|
-
<div class="is-overlay">
|
918
|
-
<div class="is-overlay-content"
|
919
|
-
data-module="code"
|
920
|
-
data-module-desc="My Code"
|
921
|
-
data-html="[... encoded custom script here ...]">
|
922
|
-
</div>
|
923
|
-
</div>
|
924
|
-
</div>
|
925
|
-
```
|
926
|
-
|
927
|
-
Here is an example:
|
928
|
-
|
929
|
-
```javascript
|
930
|
-
parent.contentbox.addSection(`
|
931
|
-
<div class="is-section is-box is-section-100 is-light-text type-rufina-oxygen protected">
|
932
|
-
<div class="is-overlay">
|
933
|
-
<div class="is-overlay-content"
|
934
|
-
data-module="code"
|
935
|
-
data-module-desc="Custom HTML or Javascript "
|
936
|
-
data-html="${encodeURIComponent(`
|
937
|
-
|
938
|
-
<!-- custom script here -->
|
939
|
-
|
940
|
-
`)}">
|
941
|
-
|
942
|
-
</div>
|
943
|
-
</div>
|
944
|
-
</div>
|
945
|
-
`, 'type-rufina-oxygen.css');
|
946
|
-
```
|
947
|
-
|
948
|
-
For the complete code, please open the **mypanel.html** with your code editor.
|
949
|
-
|
950
|
-
|
951
|
-
## Credits
|
952
|
-
|
953
|
-
#### Libraries
|
954
|
-
|
955
|
-
- CodeMirror, Copyright (C) 2017 by Marijn Haverbeke <marijnh@gmail.com> and others (MIT license), https://github.com/codemirror/CodeMirror
|
956
|
-
- Cropper.js, Copyright 2015-present Chen Fengyuan (MIT license), https://fengyuanchen.github.io/cropperjs/
|
957
|
-
- Glide.js, Copyright (c) 2013-present Jędrzej Chałubek (MIT license), https://github.com/glidejs/glide
|
958
|
-
- Ionicons, Copyright (c) 2015-present Ionic (http://ionic.io/) (MIT license), https://ionic.io/ionicons/v1
|
959
|
-
- js-beautify, Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors (MIT license), https://github.com/beautify-web/js-beautify
|
960
|
-
- Moveable, Copyright (c) 2019 Daybrush (MIT license), https://github.com/daybrush/moveable
|
961
|
-
- Pace, Copyright (c) 2013 HubSpot, Inc. (MIT license), https://codebyzach.github.io/pace/
|
962
|
-
- Slick, Copyright (c) 2017 Ken Wheeler (MIT license), https://github.com/kenwheeler/slick/
|
963
|
-
- Sortable, Copyright (c) 2019 All contributors to Sortable (MIT license), https://github.com/SortableJS/Sortable
|
964
|
-
- Tabler Icons, Copyright (c) 2020 Paweł Kuna (MIT license), https://github.com/tabler/tabler-icons
|
965
|
-
|