From 3605bae1cb71e6188b010ce52c8e6cbf95aa1cfa Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Thu, 11 Apr 2013 14:59:58 -0400 Subject: enabled spellchecker automatically if used in tinymce --- askbot/context.py | 7 +++++++ askbot/media/js/post.js | 15 +++++++++++++++ askbot/setup_templates/settings.py | 2 +- askbot/setup_templates/settings.py.mustache | 2 +- askbot/templates/meta/editor_data.html | 1 + 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/askbot/context.py b/askbot/context.py index abd283e1..d98b8737 100644 --- a/askbot/context.py +++ b/askbot/context.py @@ -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 diff --git a/askbot/media/js/post.js b/askbot/media/js/post.js index ad641076..755ce158 100644 --- a/askbot/media/js/post.js +++ b/askbot/media/js/post.js @@ -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() {}; diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py index 7020b612..7ca177a5 100644 --- a/askbot/setup_templates/settings.py +++ b/askbot/setup_templates/settings.py @@ -274,7 +274,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', diff --git a/askbot/setup_templates/settings.py.mustache b/askbot/setup_templates/settings.py.mustache index a879a5be..8265f728 100644 --- a/askbot/setup_templates/settings.py.mustache +++ b/askbot/setup_templates/settings.py.mustache @@ -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', diff --git a/askbot/templates/meta/editor_data.html b/askbot/templates/meta/editor_data.html index d7328b7d..3d047415 100644 --- a/askbot/templates/meta/editor_data.html +++ b/askbot/templates/meta/editor_data.html @@ -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 }}'); -- cgit v1.2.3-1-g7c22