File tree Expand file tree Collapse file tree 5 files changed +36
-4
lines changed
templates/djangocms_snippet/admin Expand file tree Collapse file tree 5 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ Changelog
55unreleased
66==========
77
8+ * Add support for ace editor loaded from static files through djangocms-static-ace
9+ * Add dark mode support
810
9113.0.0 (2020-09-02)
1012==================
Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ For a manual install:
6262* add ``djangocms_snippet `` to your ``INSTALLED_APPS ``
6363* run ``python manage.py migrate djangocms_snippet ``
6464
65+ Djangocms-snippet uses the ace code editor which normally is loaded from a CDN.
66+ If you prefer your application to provide the editor locally, you can change
67+ the requirement from `djangocms_snippet ` to `djangocms_snippet[static-ace] ` and
68+ add `djangocms_static_ace ` to your project's `INSTALLED_APPS `.
69+
6570
6671Configuration
6772-------------
Original file line number Diff line number Diff line change 77
88
99class SnippetAdmin (admin .ModelAdmin ):
10+ class Media :
11+ js = (
12+ "admin/vendor/ace/ace.js"
13+ if "djangocms_static_ace" in settings .INSTALLED_APPS
14+ else "https://cdnjs.cloudflare.com/ajax/libs/ace/1.9.6/ace.js" ,
15+ )
16+
1017 list_display = ('slug' , 'name' )
1118 search_fields = ['slug' , 'name' ]
1219 prepopulated_fields = {'slug' : ('name' ,)}
Original file line number Diff line number Diff line change 33
44{% block object-tools %}
55{{ block.super }}
6-
7- < script src ="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ace.js "> </ script >
86< script >
97django . jQuery ( function ( ) {
108 // ace editor cannot be attached directly to a textarea
1917
2018 // init editor with settings
2119 var editor = ace . edit ( div [ 0 ] ) ;
22- editor . setTheme ( 'ace/theme/' + settings . theme ) ;
20+ var darkMode ;
21+ if ( window . CMS ) {
22+ if ( CMS . API . Helpers . getColorScheme ) {
23+ darkMode = CMS . API . Helpers . getColorScheme ( ) === 'dark' ;
24+ } else {
25+ // django CMS pre-3.11.1
26+ darkMode = window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ;
27+ }
28+ } else if ( window . localStorage ) {
29+ // CMS not loaded: set color scheme for admin site / popup window according to settings
30+ darkMode = JSON . parse ( localStorage . getItem ( 'cms_cookie' ) || '{}' ) . color_scheme === 'dark' ;
31+ }
32+ if ( darkMode ) {
33+ editor . setTheme ( 'ace/theme/tomorrow_night' ) ;
34+ } else {
35+ editor . setTheme ( settings . theme ? 'ace/theme/' + settings . theme : 'ace/theme/github' ) ;
36+ }
2337 editor . getSession ( ) . setValue ( textarea . val ( ) ) ;
2438 editor . getSession ( ) . setMode ( 'ace/mode/' + settings . mode ) ;
2539 editor . setOptions ( {
2640 fontSize : '14px' ,
2741 cursorStyle : 'smooth'
2842 } ) ;
29- editor . renderer . setScrollMargin ( 5 , 5 ) ;
3043
3144 // send data back to textarea when submitting
3245 textarea . closest ( 'form' ) . submit ( function ( ) {
Original file line number Diff line number Diff line change 1111 'django-treebeard>=4.3,<4.5' ,
1212]
1313
14+ EXTRA_REQUIREMENTS = {
15+ 'static-ace' : ['djangocms-static-ace' , ],
16+ }
17+
1418
1519CLASSIFIERS = [
1620 'Development Status :: 5 - Production/Stable' ,
5761 include_package_data = True ,
5862 zip_safe = False ,
5963 install_requires = REQUIREMENTS ,
64+ extras_require = EXTRA_REQUIREMENTS ,
6065 classifiers = CLASSIFIERS ,
6166 test_suite = 'tests.settings.run' ,
6267)
You can’t perform that action at this time.
0 commit comments