From c1c4ed1535ca1b8fe603c47eb1e94ec6fe0a6baa Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Sat, 20 Apr 2013 06:12:35 -0400 Subject: improved commenting function --- askbot/conf/forum_data_rules.py | 11 +++++ askbot/media/js/post.js | 74 ++++++++++++++++++++++------------ askbot/media/style/style.css | 3 +- askbot/media/style/style.less | 3 +- askbot/templates/meta/editor_data.html | 1 + 5 files changed, 65 insertions(+), 27 deletions(-) diff --git a/askbot/conf/forum_data_rules.py b/askbot/conf/forum_data_rules.py index 28a1b7b4..96cb0ea0 100644 --- a/askbot/conf/forum_data_rules.py +++ b/askbot/conf/forum_data_rules.py @@ -164,6 +164,17 @@ settings.register( ) ) +settings.register( + livesettings.IntegerValue( + FORUM_DATA_RULES, + 'MIN_COMMENT_BODY_LENGTH', + default=10, + description=_( + 'Minimum length of comment (number of characters)' + ) + ) +) + settings.register( livesettings.BooleanValue( FORUM_DATA_RULES, diff --git a/askbot/media/js/post.js b/askbot/media/js/post.js index 2af9a15d..ada053c6 100644 --- a/askbot/media/js/post.js +++ b/askbot/media/js/post.js @@ -1590,7 +1590,7 @@ EditCommentForm.prototype.startTinyMCEEditor = function() { theme_advanced_path: false, plugins: '', width: '100%', - height: '60px' + height: '70' }; var editor = new TinyMCE(opts); editor.setId(editorId); @@ -1674,8 +1674,11 @@ EditCommentForm.prototype.attachTo = function(comment, mode){ this.enableForm(); this.startEditor(); this._editor.setText(this._text); - this._editor.focus(); - this._editor.putCursorAtEnd(); + var ed = this._editor + var onFocus = function() { + ed.putCursorAtEnd(); + }; + this._editor.focus(onFocus); setupButtonEventHandlers(this._submit_btn, this.getSaveHandler()); setupButtonEventHandlers(this._cancel_btn, this.getCancelHandler()); }; @@ -1868,7 +1871,7 @@ EditCommentForm.prototype.getSaveHandler = function(){ me.disableForm(); var text = editor.getText(); - if (text.length < 10){ + if (text.length < askbot['settings']['minCommentBodyLength']){ editor.focus(); return false; } @@ -2121,7 +2124,7 @@ Comment.prototype.setContent = function(data){ this._comment_body = $('
'); this._contentBox.append(this._comment_body); } - if (askbot['settings']['editorType'] === 'tinymce') { + if (EditCommentForm.prototype.getEditorType() === 'tinymce') { var theComment = $('
'); theComment.html(this._data['html']); //sanitize, just in case @@ -2611,8 +2614,11 @@ var SimpleEditor = function(attrs) { }; inherits(SimpleEditor, WrappedElement); -SimpleEditor.prototype.focus = function() { +SimpleEditor.prototype.focus = function(onFocus) { this._textarea.focus(); + if (onFocus) { + onFocus(); + } }; SimpleEditor.prototype.putCursorAtEnd = function() { @@ -2753,12 +2759,13 @@ inherits(TinyMCE, WrappedElement); */ TinyMCE.onInitHook = function() { //set initial content - tinyMCE.activeEditor.setContent(askbot['data']['editorContent'] || ''); + var ed = tinyMCE.activeEditor; + ed.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); + ed.controlManager.setActive('spellchecker', true); + tinyMCE.execCommand('mceSpellCheck', true); }, 1); } }; @@ -2780,29 +2787,46 @@ TinyMCE.prototype.start = function() { }; TinyMCE.prototype.setPreviewerEnabled = function() {}; TinyMCE.prototype.setHighlight = function() {}; -TinyMCE.prototype.putCursorAtEnd = function() {}; -TinyMCE.prototype.focus = function() { - var editorId = this._id; - setTimeout(function() { - tinymce.execCommand('mceFocus', false, editorId); - }, - 100 - ); +TinyMCE.prototype.putCursorAtEnd = function() { + var ed = tinyMCE.activeEditor; + //add an empty span with a unique id + var endId = tinymce.DOM.uniqueId(); + ed.dom.add(ed.getBody(), 'span', {'id': endId}, ''); + //select that span + var newNode = ed.dom.select('span#' + endId); + ed.selection.select(newNode[0]); +}; - //@todo: make this general to all editors +TinyMCE.prototype.focus = function(onFocus) { + var editorId = this._id; var winH = $(window).height(); var winY = $(window).scrollTop(); var edY = this._element.offset().top; var edH = this._element.height(); - //if editor bottom is below viewport - var isBelow = ((edY + edH) > (winY + winH)); - var isAbove = (edY < winY); - if (isBelow || isAbove) { - //then center on screen - $(window).scrollTop(edY - edH/2 - winY/2); - } + //@todo: the fallacy of this method is timeout - should instead use queue + //because at the time of calling focus() the editor may not be initialized yet + setTimeout( + function() { + tinyMCE.execCommand('mceFocus', false, editorId); + + //@todo: make this general to all editors + + //if editor bottom is below viewport + var isBelow = ((edY + edH) > (winY + winH)); + var isAbove = (edY < winY); + if (isBelow || isAbove) { + //then center on screen + $(window).scrollTop(edY - edH/2 - winY/2); + } + if (onFocus) { + onFocus(); + } + }, + 100 + ); + }; diff --git a/askbot/media/style/style.css b/askbot/media/style/style.css index cae896cc..06de580a 100644 --- a/askbot/media/style/style.css +++ b/askbot/media/style/style.css @@ -2472,7 +2472,8 @@ ul#related-tags li { font-size: 13px; font-weight: normal; line-height: 13px; - margin: 0 0 0 8px; + margin: 0 0 3px 8px; + vertical-align: middle; -webkit-box-shadow: 0 0 0 #929292; -moz-box-shadow: 0 0 0 #929292; box-shadow: 0 0 0 #929292; diff --git a/askbot/media/style/style.less b/askbot/media/style/style.less index 261edefb..23c172df 100644 --- a/askbot/media/style/style.less +++ b/askbot/media/style/style.less @@ -2579,7 +2579,8 @@ ul#related-tags li { font-size: 13px; font-weight: normal; line-height: 13px; - margin: 0 0 0 8px; + margin: 0 0 3px 8px; + vertical-align: middle; .box-shadow(0, 0, 0); .text-shadow(0, 0, 0); } diff --git a/askbot/templates/meta/editor_data.html b/askbot/templates/meta/editor_data.html index 3d047415..c8960156 100644 --- a/askbot/templates/meta/editor_data.html +++ b/askbot/templates/meta/editor_data.html @@ -10,6 +10,7 @@ askbot['settings']['minTitleLength'] = {{ settings.MIN_TITLE_LENGTH }}; askbot['settings']['minQuestionBodyLength'] = {{ settings.MIN_QUESTION_BODY_LENGTH }}; askbot['settings']['minAnswerBodyLength'] = {{ settings.MIN_ANSWER_BODY_LENGTH }}; + askbot['settings']['minCommentBodyLength'] = {{ settings.MIN_COMMENT_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