|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>GrapesJS Example</title> |
|
|
|
<link rel="stylesheet" href="https://unpkg.com/grapesjs/dist/css/grapes.min.css"> |
|
</head> |
|
<body> |
|
<div id="gjs"></div> |
|
|
|
|
|
<script src="https://unpkg.com/grapesjs"></script> |
|
|
|
<script> |
|
const editor = grapesjs.init({ |
|
container: '#gjs', |
|
fromElement: true, |
|
height: '100vh', |
|
storageManager: { type: 0 }, |
|
plugins: [], |
|
pluginsOpts: {}, |
|
selectorManager: { |
|
componentFirst: true, |
|
}, |
|
}); |
|
|
|
|
|
const script = function() { |
|
alert('Hi'); |
|
console.log('the element', this); |
|
}; |
|
|
|
|
|
editor.Components.addType('comp-with-js', { |
|
model: { |
|
defaults: { |
|
script, |
|
|
|
style: { |
|
width: '100px', |
|
height: '100px', |
|
background: 'red', |
|
}, |
|
components: ` |
|
<button onclick="alert('Ещё')" style="margin: 10px;">Ещё</button> |
|
`, |
|
} |
|
} |
|
}); |
|
|
|
|
|
editor.Blocks.add('test-block', { |
|
label: 'Test block', |
|
attributes: { class: 'fa fa-text' }, |
|
content: { type: 'comp-with-js' }, |
|
}); |
|
</script> |
|
</body> |
|
</html> |