-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add customer code block #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): The Ace editor setup targets all textareas, which can cause issues if the form has multiple textarea fields. Since this binds Ace to every textarea, it can interfere with other fields now or in the future. Please scope the selector to the specific |
||
| 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 %} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| {% load i18n cms_tags frontend %} | ||
| <div class="mb-5 card {% if instance.dark_mode %}bg-dark{% else %}bg-light{% endif %}"> | ||
| {% if instance.heading %} | ||
| <div class="card-header bg-primary"> | ||
| <p><span class="overline">{% inline_field instance "heading" %}</span></p> | ||
| </div> | ||
| {% endif %} | ||
| <div class="card-body{% if instance.dark_mode %} text-light{% endif %}"> | ||
| <pre{{ instance.get_attributes }}><code>{{ instance.code_content }}</code></pre> | ||
| </div> | ||
| </div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): The
ready()hook may run before the plugin is registered, causing this customization to be silently skipped.Because plugin registration timing can vary,
get_plugin("CodeBlockPlugin")may returnNonehere and the template override will never take effect. To avoid this, either ensure the module that registers the plugin is imported inready()(e.g., import the app’scms_pluginsthere), or move this customization alongside the plugin definition so it’s applied at registration time.