-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
56 lines (49 loc) · 1.42 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
54
55
56
<!doctype html>
<head>
<link href="https://unpkg.com/contentful-ui-extensions-sdk@3/dist/cf-extension.css" rel="stylesheet">
<link href="https://contentful.github.io/extensions/libs/alloy-editor/assets/alloy-editor-ocean-min.css" rel="stylesheet">
<script src="https://contentful.github.io/extensions/libs/alloy-editor/alloy-editor-all-min.js"></script>
<script src="https://unpkg.com/contentful-ui-extensions-sdk@3"></script>
<style>
body {
margin: 0;
border: 1px solid #ccc;
border-radius: 4px;
overflow: hidden;
}
#content {
outline: 0;
padding: 1em;
margin-left: 3em;
margin-top: -1px;
margin-bottom: -1px;
min-height: 30em;
}
</style>
</head>
<body>
<div id="content"></div>
<script>
var cfExt = window.contentfulExtension || window.contentfulWidget
const AlloyEditor = window.AlloyEditor
cfExt.init(function (ext) {
var currentValue
ext.window.startAutoResizer()
const editor = AlloyEditor.editable('content')._editor
editor.setData(ext.field.getValue())
ext.field.onValueChanged(function(value) {
if (value !== currentValue) {
currentValue = value
editor.setData(value)
}
})
editor.on('change', function() {
const value = editor.getData()
if (currentValue !== value) {
currentValue = value
ext.field.setValue(value)
}
})
})
</script>
</body>