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
5
5
unreleased
6
6
==========
7
7
8
+ * Add support for ace editor loaded from static files through djangocms-static-ace
9
+ * Add dark mode support
8
10
9
11
3.0.0 (2020-09-02)
10
12
==================
Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ For a manual install:
62
62
* add ``djangocms_snippet `` to your ``INSTALLED_APPS ``
63
63
* run ``python manage.py migrate djangocms_snippet ``
64
64
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
+
65
70
66
71
Configuration
67
72
-------------
Original file line number Diff line number Diff line change 7
7
8
8
9
9
class 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
+
10
17
list_display = ('slug' , 'name' )
11
18
search_fields = ['slug' , 'name' ]
12
19
prepopulated_fields = {'slug' : ('name' ,)}
Original file line number Diff line number Diff line change 3
3
4
4
{% block object-tools %}
5
5
{{ block.super }}
6
-
7
- < script src ="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ace.js "> </ script >
8
6
< script >
9
7
django . jQuery ( function ( ) {
10
8
// ace editor cannot be attached directly to a textarea
19
17
20
18
// init editor with settings
21
19
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
+ }
23
37
editor . getSession ( ) . setValue ( textarea . val ( ) ) ;
24
38
editor . getSession ( ) . setMode ( 'ace/mode/' + settings . mode ) ;
25
39
editor . setOptions ( {
26
40
fontSize : '14px' ,
27
41
cursorStyle : 'smooth'
28
42
} ) ;
29
- editor . renderer . setScrollMargin ( 5 , 5 ) ;
30
43
31
44
// send data back to textarea when submitting
32
45
textarea . closest ( 'form' ) . submit ( function ( ) {
Original file line number Diff line number Diff line change 11
11
'django-treebeard>=4.3,<4.5' ,
12
12
]
13
13
14
+ EXTRA_REQUIREMENTS = {
15
+ 'static-ace' : ['djangocms-static-ace' , ],
16
+ }
17
+
14
18
15
19
CLASSIFIERS = [
16
20
'Development Status :: 5 - Production/Stable' ,
57
61
include_package_data = True ,
58
62
zip_safe = False ,
59
63
install_requires = REQUIREMENTS ,
64
+ extras_require = EXTRA_REQUIREMENTS ,
60
65
classifiers = CLASSIFIERS ,
61
66
test_suite = 'tests.settings.run' ,
62
67
)
You can’t perform that action at this time.
0 commit comments