-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode_block.html
More file actions
46 lines (42 loc) · 1.72 KB
/
code_block.html
File metadata and controls
46 lines (42 loc) · 1.72 KB
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
{% extends "djangocms_frontend/admin/base.html" %}
{% block object-tools %}
{{ block.super }}{% spaceless %}
<script>
django.jQuery(function () {
// ace editor cannot be attached directly to a textarea
var textarea = django.jQuery('textarea').css('display', 'none');
var settings = textarea.data();
var div = django.jQuery('<div>', {
position: 'absolute',
width: '100%',
style: 'font-size: 14px',
height: textarea.height() * 4,
'class': textarea.attr('class'),
}).insertBefore(textarea);
// init editor with settings
var editor = ace.edit(div[0]);
var darkMode;
darkMode = window.parent.CMS.API.Helpers.getColorScheme() === 'dark';
if (darkMode) {
editor.setTheme('ace/theme/tomorrow_night');
} else {
editor.setTheme('ace/theme/xcode');
}
editor.getSession().setValue(textarea.val());
editor.getSession().setMode('ace/mode/python');
editor.setOptions({
fontSize: '14px',
cursorStyle: 'smooth'
});
editor.renderer.setScrollMargin(5, 5);
// send data back to textarea when submitting
textarea.closest('form').submit(function () {
textarea.val(editor.getSession().getValue());
});
// immediate update while typing inside CKEditor
editor.getSession().on('change', function () {
textarea.val(editor.getSession().getValue());
});
});
</script>{% endspaceless %}
{% endblock %}