From 387c8ea1b5efaf8b1ab5c6fc533ee0366741ab23 Mon Sep 17 00:00:00 2001 From: Arjun Singh Date: Fri, 14 Sep 2012 12:46:48 -0700 Subject: [PATCH] make wmd editor for comments --- .../views/discussion_thread_view.coffee | 1 + .../views/response_comment_show_view.coffee | 3 -- .../views/thread_response_view.coffee | 29 ++++++++++++++----- .../discussion/_underscore_templates.html | 10 +++++-- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/lms/static/coffee/src/discussion/views/discussion_thread_view.coffee b/lms/static/coffee/src/discussion/views/discussion_thread_view.coffee index d7ca9d045b..cb549f1088 100644 --- a/lms/static/coffee/src/discussion/views/discussion_thread_view.coffee +++ b/lms/static/coffee/src/discussion/views/discussion_thread_view.coffee @@ -76,6 +76,7 @@ if Backbone? view.on "comment:endorse", @endorseThread view.render() @$el.find(".responses").append(view.el) + view.afterInsert() addComment: => @model.comment() diff --git a/lms/static/coffee/src/discussion/views/response_comment_show_view.coffee b/lms/static/coffee/src/discussion/views/response_comment_show_view.coffee index 2fb85f8f96..65150e0260 100644 --- a/lms/static/coffee/src/discussion/views/response_comment_show_view.coffee +++ b/lms/static/coffee/src/discussion/views/response_comment_show_view.coffee @@ -25,9 +25,6 @@ if Backbone? convertMath: -> body = @$el.find(".response-body") body.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight body.html() - # This removes paragraphs so that comments are more compact - body.children("p").each (index, elem) -> - $(elem).replaceWith($(elem).html()) MathJax.Hub.Queue ["Typeset", MathJax.Hub, body[0]] markAsStaff: -> diff --git a/lms/static/coffee/src/discussion/views/thread_response_view.coffee b/lms/static/coffee/src/discussion/views/thread_response_view.coffee index 7ff1b1a157..0c7f13f919 100644 --- a/lms/static/coffee/src/discussion/views/thread_response_view.coffee +++ b/lms/static/coffee/src/discussion/views/thread_response_view.coffee @@ -3,7 +3,8 @@ if Backbone? tagName: "li" events: - "submit .comment-form": "submitComment" + "click .discussion-submit-comment": "submitComment" + "focus .wmd-input": "showEditorChrome" $: (selector) -> @$el.find(selector) @@ -13,7 +14,10 @@ if Backbone? renderTemplate: -> @template = _.template($("#thread-response-template").html()) - @template(@model.toJSON()) + + templateData = @model.toJSON() + templateData.wmdId = @model.id ? (new Date()).getTime() + @template(templateData) render: -> @$el.html(@renderTemplate()) @@ -25,6 +29,18 @@ if Backbone? @renderComments() @ + afterInsert: -> + @makeWmdEditor "comment-body" + @hideEditorChrome() + + hideEditorChrome: -> + @$('.wmd-button-row').hide() + @$('.wmd-preview').hide() + + showEditorChrome: -> + @$('.wmd-button-row').show() + @$('.wmd-preview').show() + renderComments: -> comments = new Comments() comments.comparator = (comment) -> @@ -42,19 +58,18 @@ if Backbone? comment.set('thread', @model.get('thread')) view = new ResponseCommentView(model: comment) view.render() - @$el.find(".comments li:last").before(view.el) + @$el.find(".comments .new-comment").before(view.el) view submitComment: (event) -> event.preventDefault() url = @model.urlFor('reply') - body = @$(".comment-form-input").val() - if not body.trim().length - return + body = @getWmdContent("comment-body") + return if not body.trim().length + @setWmdContent("comment-body", "") comment = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username"), user_id: window.user.get("id"), id:"unsaved") view = @renderComment(comment) @trigger "comment:add", comment - @$(".comment-form-input").val("") DiscussionUtil.safeAjax $elem: $(event.target) diff --git a/lms/templates/discussion/_underscore_templates.html b/lms/templates/discussion/_underscore_templates.html index d9c7b51de0..f031883db7 100644 --- a/lms/templates/discussion/_underscore_templates.html +++ b/lms/templates/discussion/_underscore_templates.html @@ -76,9 +76,13 @@