Skip to content

Commit c7e322c

Browse files
committed
added DRACEDITOR_ENABLE_CONFIGS
1 parent 21ccb71 commit c7e322c

File tree

4 files changed

+57
-24
lines changed

4 files changed

+57
-24
lines changed

draceditor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
__VERSION__ = '1.0.7'
3+
__VERSION__ = '1.0.8'
44
__AUTHOR__ = 'Agus Makmun (Summon Agus)'
55
__AUTHOR_EMAIL__ = '[email protected]'

draceditor/settings.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
from django.conf import settings
22

3+
# Global draceditor settings
4+
# Input: string boolean, `true/false`
5+
DRACEDITOR_ENABLE_CONFIGS = getattr(
6+
settings, 'DRACEDITOR_ENABLE_CONFIGS', {
7+
'imgur': 'true', # to enable/disable imgur uploader.
8+
'mention': 'false', # to enable/disable mention
9+
'jquery': 'true', # to include/revoke jquery (require for admin default django)
10+
}
11+
)
12+
313
# Imgur API Keys
414
DRACEDITOR_IMGUR_CLIENT_ID = getattr(
515
settings, 'DRACEDITOR_IMGUR_CLIENT_ID', ''
@@ -31,8 +41,8 @@
3141

3242
# Custom markdown extensions.
3343
'draceditor.extensions.urlize',
34-
'draceditor.extensions.mention',
35-
'draceditor.extensions.emoji',
44+
'draceditor.extensions.mention', # to parse markdown mention
45+
'draceditor.extensions.emoji', # to parse markdown emoji
3646
]
3747
)
3848

@@ -43,10 +53,10 @@
4353

4454
# Markdown urls
4555
DRACEDITOR_UPLOAD_URL = getattr(
46-
settings, 'DRACEDITOR_UPLOAD_URL', '/draceditor/uploader/'
56+
settings, 'DRACEDITOR_UPLOAD_URL', '/draceditor/uploader/' # for imgur
4757
)
4858
DRACEDITOR_SEARCH_USERS_URL = getattr(
49-
settings, 'DRACEDITOR_SEARCH_USERS_URL', '/draceditor/search-user/'
59+
settings, 'DRACEDITOR_SEARCH_USERS_URL', '/draceditor/search-user/' # for mention
5060
)
5161

5262
# Markdown Extensions

draceditor/static/js/draceditor.js

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Name : DracEditor v1.0.7
2+
* Name : DracEditor v1.0.8
33
* Created by : Agus Makmun (Summon Agus)
44
* Release date : 2-Jan-2017
55
* Official : https://dracos-linux.org
@@ -132,7 +132,11 @@
132132
}
133133
}
134134
// Set autocomplete for ace editor
135-
editor.completers = [emojiWordCompleter, mentionWordCompleter]
135+
if (draceditor.data('enable-configs').mention === 'true') {
136+
editor.completers = [emojiWordCompleter, mentionWordCompleter]
137+
}else {
138+
editor.completers = [emojiWordCompleter]
139+
}
136140

137141
// win/linux: Ctrl+B, mac: Command+B
138142
var markdownToBold = function() {
@@ -541,14 +545,16 @@
541545
},
542546
readOnly: true
543547
});
544-
editor.commands.addCommand({
545-
name: 'markdownToMention',
546-
bindKey: {win: 'Ctrl-M', mac: 'Command-M'},
547-
exec: function(editor) {
548-
markdownToMention()
549-
},
550-
readOnly: true
551-
});
548+
if (draceditor.data('enable-configs').mention === 'true') {
549+
editor.commands.addCommand({
550+
name: 'markdownToMention',
551+
bindKey: {win: 'Ctrl-M', mac: 'Command-M'},
552+
exec: function(editor) {
553+
markdownToMention()
554+
},
555+
readOnly: true
556+
});
557+
}
552558

553559
// Trigger Click
554560
$('.markdown-bold').click(function(){
@@ -590,14 +596,27 @@
590596
$('.markdown-image-link').click(function(){
591597
markdownToImageLink();
592598
});
593-
$('.markdown-direct-mention').click(function(){
594-
markdownToMention();
595-
});
596-
// To Upload Image
597-
$('.markdown-image-upload').on('change', function(evt){
598-
evt.preventDefault();
599-
markdownToUploadImage();
600-
});
599+
600+
// Custom decission for toolbar buttons.
601+
var btnMention = $('.markdown-direct-mention'); // To Direct Mention
602+
var btnUpload = $('.markdown-image-upload'); // To Upload Image
603+
var configs = draceditor.data('enable-configs');
604+
if (configs.mention === 'true') {
605+
btnMention.click(function(){
606+
markdownToMention();
607+
});
608+
}else if (configs.imgur === 'true') {
609+
btnUpload.on('change', function(evt){
610+
evt.preventDefault();
611+
markdownToUploadImage();
612+
});
613+
}else {
614+
btnMention.remove();
615+
btnUpload.remove();
616+
// Disable help of `mention`
617+
$('.markdown-reference tbody tr')[1].remove();
618+
}
619+
601620
// Modal Popup for Help Guide & Emoji Cheat Sheet
602621
$('.markdown-help').click(function(){
603622
$('.modal-help-guide').modal('show');

draceditor/widgets.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.contrib.admin import widgets
44

55
from .settings import (
6+
DRACEDITOR_ENABLE_CONFIGS,
67
DRACEDITOR_UPLOAD_URL,
78
DRACEDITOR_MARKDOWNIFY_URL,
89
DRACEDITOR_SEARCH_USERS_URL,
@@ -20,6 +21,7 @@ def render(self, name, value, attrs=None):
2021
else:
2122
attrs.update({'class': 'draceditor'})
2223

24+
attrs['data-enable-configs'] = DRACEDITOR_ENABLE_CONFIGS
2325
attrs['data-upload-url'] = DRACEDITOR_UPLOAD_URL
2426
attrs['data-markdownfy-url'] = DRACEDITOR_MARKDOWNIFY_URL
2527
attrs['data-search-users-url'] = DRACEDITOR_SEARCH_USERS_URL
@@ -42,7 +44,7 @@ class Media:
4244
)
4345
}
4446
js = (
45-
'plugins/js/jquery.min.js',
47+
#'plugins/js/jquery.min.js',
4648
'plugins/js/ace.js',
4749
'plugins/js/semantic.min.js',
4850
'plugins/js/mode-markdown.js',
@@ -53,6 +55,8 @@ class Media:
5355
'plugins/js/emojis.min.js',
5456
'js/draceditor.js',
5557
)
58+
if DRACEDITOR_ENABLE_CONFIGS['jquery'] == 'true':
59+
js = ('plugins/js/jquery.min.js',).__add__(js)
5660

5761

5862
class AdminDraceditorWidget(DraceditorWidget, widgets.AdminTextareaWidget):

0 commit comments

Comments
 (0)