From b2df0411650b508bd1c394294836fa4b2da994d6 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Tue, 21 May 2013 17:11:40 -0400 Subject: moved the "add a comment" button up to save vertical space --- askbot/media/js/post.js | 32 +++++++++++++++++++++++++------- askbot/media/style/style.css | 4 ++++ askbot/media/style/style.less | 8 ++++++-- askbot/templates/macros.html | 2 +- askbot/templates/question.html | 4 ++-- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/askbot/media/js/post.js b/askbot/media/js/post.js index f3a86618..ed4d596d 100644 --- a/askbot/media/js/post.js +++ b/askbot/media/js/post.js @@ -1544,7 +1544,7 @@ DeletePostLink.prototype.decorate = function(element){ var EditCommentForm = function(){ WrappedElement.call(this); this._comment = null; - this._comment_widget = null; + this._commentsWidget = null; this._element = null; this._editorReady = false; this._text = ''; @@ -1645,17 +1645,21 @@ EditCommentForm.prototype.startEditor = function() { } }; +EditCommentForm.prototype.getCommentsWidget = function() { + return this._commentsWidget; +}; + /** * attaches comment editor to a particular comment */ EditCommentForm.prototype.attachTo = function(comment, mode){ this._comment = comment; this._type = mode;//action: 'add' or 'edit' - this._comment_widget = comment.getContainerWidget(); + this._commentsWidget = comment.getContainerWidget(); this._text = comment.getText(); comment.getElement().after(this.getElement()); comment.getElement().hide(); - this._comment_widget.hideButton();//hide add comment button + this._commentsWidget.hideButton();//hide add comment button //fix up the comment submit button, depending on the mode if (this._type == 'add'){ this._submit_btn.html(gettext('add comment')); @@ -1746,10 +1750,12 @@ EditCommentForm.prototype.canCancel = function(){ }; EditCommentForm.prototype.getCancelHandler = function(){ - var form = this; + var me = this; return function(evt){ - if (form.canCancel()){ - form.detach(); + if (me.canCancel()){ + var widget = me.getCommentsWidget(); + widget.handleDeletedComment(); + me.detach(); evt.preventDefault(); } return false; @@ -2269,7 +2275,9 @@ Comment.prototype.getDeleteHandler = function(){ url: askbot['urls']['deleteComment'], data: { comment_id: comment.getId() }, success: function(json, textStatus, xhr) { + var widget = comment.getContainerWidget(); comment.dispose(); + widget.handleDeletedComment(); }, error: function(xhr, textStatus, exception) { comment.getElement().show() @@ -2326,6 +2334,15 @@ PostCommentsWidget.prototype.decorate = function(element){ this._comments = comments; }; +PostCommentsWidget.prototype.handleDeletedComment = function() { + /* if the widget does not have any comments, set + the 'empty' class on the widget element */ + if (this._cbox.children('.comment').length === 0) { + this._element.siblings('.comment-title').hide(); + this._element.addClass('empty'); + } +}; + PostCommentsWidget.prototype.getPostType = function(){ return this._post_type; }; @@ -2352,6 +2369,7 @@ PostCommentsWidget.prototype.startNewComment = function(){ }; var comment = new Comment(this, opts); this._cbox.append(comment.getElement()); + this._element.removeClass('empty'); comment.startEditing(); }; @@ -2380,7 +2398,7 @@ PostCommentsWidget.prototype.getActivateHandler = function(){ me.reloadAllComments(function(json){ me.reRenderComments(json); //2) change button text to "post a comment" - button.html(gettext('post a comment')); + button.html(askbot['messages']['addComment']); }); } else { diff --git a/askbot/media/style/style.css b/askbot/media/style/style.css index 8760f219..2f7d1992 100644 --- a/askbot/media/style/style.css +++ b/askbot/media/style/style.css @@ -2308,6 +2308,10 @@ ul#related-tags li { .question-page div.comments { padding: 0; } +.question-page div.comments.empty { + margin-top: -34px; + float: left; +} .question-page h2.comment-title { color: #7ea9b3; font-weight: bold; diff --git a/askbot/media/style/style.less b/askbot/media/style/style.less index ccf81e1e..6db2ce38 100644 --- a/askbot/media/style/style.less +++ b/askbot/media/style/style.less @@ -2428,6 +2428,10 @@ ul#related-tags li { div.comments { padding: 0; } + div.comments.empty { + margin-top: -34px; + float: left; + } h2.comment-title { color: @section-title; font-weight: bold; @@ -2747,10 +2751,10 @@ ul#related-tags li { .comments .button { background-color: #E6ECFF; - } + } .comments { background-color: #E6ECFF; - } + } } .answer-img-accept { diff --git a/askbot/templates/macros.html b/askbot/templates/macros.html index f7eab371..eff73565 100644 --- a/askbot/templates/macros.html +++ b/askbot/templates/macros.html @@ -396,7 +396,7 @@ for the purposes of the AJAX comment editor #}
{% endif %} {% set widget_id = 'comments-for-' + post.post_type + '-' + post.id|string %} -
+
{% if show_post == post and show_comment and show_comment_position > max_comments %} {% set comments = post.get_cached_comments()[:show_comment_position] %} diff --git a/askbot/templates/question.html b/askbot/templates/question.html index 7e8d33ef..13593adc 100644 --- a/askbot/templates/question.html +++ b/askbot/templates/question.html @@ -225,7 +225,7 @@ if (extra_comment_count > 0){ var text = "{% trans %}see more comments{% endtrans%}"; } else { - var text = "{% trans %}post a comment{% endtrans %}"; + var text = "{% trans %}add a comment{% endtrans %}"; } var add_comment_btn = document.getElementById('add-comment-to-post-' + post_id); add_comment_btn.innerHTML = text; @@ -328,7 +328,7 @@ askbot['data']['answersSortTab'] = '{{ tab_id }}'; askbot['data']['questionId'] = {{ question.id }}; askbot['data']['threadSlug'] = '{{ thread.title|slugify }}'; - askbot['messages']['addComment'] = '{% trans %}post a comment{% endtrans %}'; + askbot['messages']['addComment'] = '{% trans %}add a comment{% endtrans %}'; askbot['settings']['saveCommentOnEnter'] = {{ settings.SAVE_COMMENT_ON_ENTER|as_js_bool }}; askbot['settings']['tagSource'] = '{{ settings.TAG_SOURCE }}'; askbot['settings']['enableSharingGoogle'] = {{ settings.ENABLE_SHARING_GOOGLE|as_js_bool }}; -- cgit v1.2.3-1-g7c22