Skip to content

Commit

Permalink
enabled spellchecker automatically if used in tinymce
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenyfadeev committed Apr 11, 2013
1 parent ca2038b commit 3605bae
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions askbot/context.py
Expand Up @@ -52,6 +52,13 @@ def application_settings(request):
my_settings['ASKBOT_VERSION'] = askbot.get_version()
my_settings['LOGIN_URL'] = url_utils.get_login_url()
my_settings['LOGOUT_URL'] = url_utils.get_logout_url()

if my_settings['EDITOR_TYPE'] == 'tinymce':
tinymce_plugins = settings.TINYMCE_DEFAULT_CONFIG.get('plugins', '').split(',')
my_settings['TINYMCE_PLUGINS'] = map(lambda v: v.strip(), tinymce_plugins)
else:
my_settings['TINYMCE_PLUGINS'] = [];

my_settings['LOGOUT_REDIRECT_URL'] = url_utils.get_logout_redirect_url()
my_settings['USE_ASKBOT_LOGIN_SYSTEM'] = 'askbot.deps.django_authopenid' \
in settings.INSTALLED_APPS
Expand Down
15 changes: 15 additions & 0 deletions askbot/media/js/post.js
Expand Up @@ -2626,6 +2626,21 @@ var TinyMCE = function(config) {
};
inherits(TinyMCE, WrappedElement);

/*
* not passed onto prototoype on purpose!!!
*/
TinyMCE.onInitHook = function() {
//set initial content
tinyMCE.activeEditor.setContent(askbot['data']['editorContent'] || '');
//if we have spellchecker - enable it by default
if (inArray('spellchecker', askbot['settings']['tinyMCEPlugins'])) {
setTimeout(function() {
tinyMCE.activeEditor.controlManager.setActive('spellchecker', true);
tinymce.execCommand('mceSpellCheck', true);
}, 1);
}
};

/* 3 dummy functions to match WMD api */
TinyMCE.prototype.setEnabledButtons = function() {};

Expand Down
2 changes: 1 addition & 1 deletion askbot/setup_templates/settings.py
Expand Up @@ -274,7 +274,7 @@
'force_p_newlines': False,
'forced_root_block': '',
'mode' : 'textareas',
'oninit': "function(){ tinyMCE.activeEditor.setContent(askbot['data']['editorContent'] || ''); }",
'oninit': "TinyMCE.onInitHook",
'plugins': 'askbot_imageuploader,askbot_attachment',
'theme_advanced_toolbar_location' : 'top',
'theme_advanced_toolbar_align': 'left',
Expand Down
2 changes: 1 addition & 1 deletion askbot/setup_templates/settings.py.mustache
Expand Up @@ -270,7 +270,7 @@ TINYMCE_DEFAULT_CONFIG = {
'force_p_newlines': False,
'forced_root_block': '',
'mode' : 'textareas',
'oninit': "function(){ tinyMCE.activeEditor.setContent(askbot['data']['editorContent'] || ''); }",
'oninit': "TinyMCE.onInitHook",
'plugins': 'askbot_imageuploader,askbot_attachment',
'theme_advanced_toolbar_location' : 'top',
'theme_advanced_toolbar_align': 'left',
Expand Down
1 change: 1 addition & 0 deletions askbot/templates/meta/editor_data.html
Expand Up @@ -11,4 +11,5 @@
askbot['settings']['minQuestionBodyLength'] = {{ settings.MIN_QUESTION_BODY_LENGTH }};
askbot['settings']['minAnswerBodyLength'] = {{ settings.MIN_ANSWER_BODY_LENGTH }};
askbot['settings']['tag_editor'] = '{{ tag_editor_settings|escapejs }}';
askbot['settings']['tinyMCEPlugins'] = JSON.parse('{{ settings.TINYMCE_PLUGINS|as_json }}');
</script>

0 comments on commit 3605bae

Please sign in to comment.