-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
134 lines (115 loc) · 4.22 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Wysiwyg</title>
<!-- Include jQuery library -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css" />
<script src="//netdna.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.js"></script>
<!-- codemirror -->
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.css">
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/theme/monokai.css">
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/mode/xml/xml.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/codemirror/2.36.0/formatting.js"></script>
<!-- add summernote -->
<link href="//cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.css" rel="stylesheet">
<script src="//cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.min.js"></script>
<!-- Include the Custom Elements API-->
<script src="https://app.kontent.ai/js-api/custom-element.js"></script>
<!-- Custom element CSS styles -->
<style>
/* We recommended you always set margin to zero to avoid problems when displaying the element in UI */
body {
margin: 0;
}
div.wysiwyg-box {
width: 100%;
padding: 0;
z-index: 1;
}
.wysiwyg.static {
display: inline-block !important;
position: static !important;
top: 0 !important;
left: 0 !important;
}
.note-group-select-from-files {
display: none;
}
.disabled_overlay {
position: fixed;
background-color: #777;
z-index: 10;
cursor: not-allowed;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0.1;
}
</style>
</head>
<body>
<!-- Custom element HTML -->
<div class="disabled_overlay"></div>
<div class="wysiwyg-box">
<div id="wysiwyg"></div>
</div>
<!-- Custom logic of the Custom element -->
<script>
function updateDisabled(disabled) {
if (disabled) {
$('.disabled_overlay').show();
$('#wysiwyg').summernote('destroy');
}
else {
$('.disabled_overlay').hide();
startEditor();
}
updateSize();
}
function setupWysiwyg(value) {
$('#wysiwyg').html(value);
startEditor();
$('#wysiwyg').on('summernote.change', function (we, contents, $editable) {
CustomElement.setValue(contents);
});
}
function startEditor() {
$('#wysiwyg').summernote({
height: 400,
placeholder: 'Start typing here...'
});
}
function updateSize() {
var height = 400;
try {
height = parseInt($("html").height());
} catch (err) {
console.error(err);
}
CustomElement.setHeight(height);
}
function initCustomElement() {
try {
CustomElement.init((element, _context) => {
// Setup with initial value and disabled state
setupWysiwyg(element.value);
updateDisabled(element.disabled);
updateSize();
});
// React when the disabled state changes (e.g. when publishing the item)
CustomElement.onDisabledChanged(updateDisabled);
} catch (err) {
// Initialization with the Custom elements API failed
// (page displayed outside of the Kentico Kontent UI)
console.error(err);
updateDisabled(true);
}
}
initCustomElement();
</script>
</body>
</html>