|
| 1 | +{% extends "djangocms_frontend/admin/base.html" %} |
| 2 | + |
| 3 | +{% block object-tools %} |
| 4 | + {{ block.super }}{% spaceless %} |
| 5 | + <script> |
| 6 | + django.jQuery(function () { |
| 7 | + // ace editor cannot be attached directly to a textarea |
| 8 | + var textarea = django.jQuery('textarea').css('display', 'none'); |
| 9 | + var settings = textarea.data(); |
| 10 | + var div = django.jQuery('<div>', { |
| 11 | + position: 'absolute', |
| 12 | + width: '100%', |
| 13 | + style: 'font-size: 14px', |
| 14 | + height: textarea.height() * 4, |
| 15 | + 'class': textarea.attr('class'), |
| 16 | + }).insertBefore(textarea); |
| 17 | + |
| 18 | + // init editor with settings |
| 19 | + var editor = ace.edit(div[0]); |
| 20 | + var darkMode; |
| 21 | + darkMode = window.parent.CMS.API.Helpers.getColorScheme() === 'dark'; |
| 22 | + if (darkMode) { |
| 23 | + editor.setTheme('ace/theme/tomorrow_night'); |
| 24 | + } else { |
| 25 | + editor.setTheme('ace/theme/xcode'); |
| 26 | + } |
| 27 | + editor.getSession().setValue(textarea.val()); |
| 28 | + editor.getSession().setMode('ace/mode/python'); |
| 29 | + editor.setOptions({ |
| 30 | + fontSize: '14px', |
| 31 | + cursorStyle: 'smooth' |
| 32 | + }); |
| 33 | + editor.renderer.setScrollMargin(5, 5); |
| 34 | + |
| 35 | + // send data back to textarea when submitting |
| 36 | + textarea.closest('form').submit(function () { |
| 37 | + textarea.val(editor.getSession().getValue()); |
| 38 | + }); |
| 39 | + |
| 40 | + // immediate update while typing inside CKEditor |
| 41 | + editor.getSession().on('change', function () { |
| 42 | + textarea.val(editor.getSession().getValue()); |
| 43 | + }); |
| 44 | + }); |
| 45 | + </script>{% endspaceless %} |
| 46 | +{% endblock %} |
0 commit comments