Commit 387c8ea1 by Arjun Singh

make wmd editor for comments

parent c72dafa9
...@@ -76,6 +76,7 @@ if Backbone? ...@@ -76,6 +76,7 @@ if Backbone?
view.on "comment:endorse", @endorseThread view.on "comment:endorse", @endorseThread
view.render() view.render()
@$el.find(".responses").append(view.el) @$el.find(".responses").append(view.el)
view.afterInsert()
addComment: => addComment: =>
@model.comment() @model.comment()
......
...@@ -25,9 +25,6 @@ if Backbone? ...@@ -25,9 +25,6 @@ if Backbone?
convertMath: -> convertMath: ->
body = @$el.find(".response-body") body = @$el.find(".response-body")
body.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight body.html() 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]] MathJax.Hub.Queue ["Typeset", MathJax.Hub, body[0]]
markAsStaff: -> markAsStaff: ->
......
...@@ -3,7 +3,8 @@ if Backbone? ...@@ -3,7 +3,8 @@ if Backbone?
tagName: "li" tagName: "li"
events: events:
"submit .comment-form": "submitComment" "click .discussion-submit-comment": "submitComment"
"focus .wmd-input": "showEditorChrome"
$: (selector) -> $: (selector) ->
@$el.find(selector) @$el.find(selector)
...@@ -13,7 +14,10 @@ if Backbone? ...@@ -13,7 +14,10 @@ if Backbone?
renderTemplate: -> renderTemplate: ->
@template = _.template($("#thread-response-template").html()) @template = _.template($("#thread-response-template").html())
@template(@model.toJSON())
templateData = @model.toJSON()
templateData.wmdId = @model.id ? (new Date()).getTime()
@template(templateData)
render: -> render: ->
@$el.html(@renderTemplate()) @$el.html(@renderTemplate())
...@@ -25,6 +29,18 @@ if Backbone? ...@@ -25,6 +29,18 @@ if Backbone?
@renderComments() @renderComments()
@ @
afterInsert: ->
@makeWmdEditor "comment-body"
@hideEditorChrome()
hideEditorChrome: ->
@$('.wmd-button-row').hide()
@$('.wmd-preview').hide()
showEditorChrome: ->
@$('.wmd-button-row').show()
@$('.wmd-preview').show()
renderComments: -> renderComments: ->
comments = new Comments() comments = new Comments()
comments.comparator = (comment) -> comments.comparator = (comment) ->
...@@ -42,19 +58,18 @@ if Backbone? ...@@ -42,19 +58,18 @@ if Backbone?
comment.set('thread', @model.get('thread')) comment.set('thread', @model.get('thread'))
view = new ResponseCommentView(model: comment) view = new ResponseCommentView(model: comment)
view.render() view.render()
@$el.find(".comments li:last").before(view.el) @$el.find(".comments .new-comment").before(view.el)
view view
submitComment: (event) -> submitComment: (event) ->
event.preventDefault() event.preventDefault()
url = @model.urlFor('reply') url = @model.urlFor('reply')
body = @$(".comment-form-input").val() body = @getWmdContent("comment-body")
if not body.trim().length return if not body.trim().length
return @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") 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) view = @renderComment(comment)
@trigger "comment:add", comment @trigger "comment:add", comment
@$(".comment-form-input").val("")
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: $(event.target) $elem: $(event.target)
......
...@@ -76,9 +76,13 @@ ...@@ -76,9 +76,13 @@
<script type="text/template" id="thread-response-template"> <script type="text/template" id="thread-response-template">
<div class="discussion-response"></div> <div class="discussion-response"></div>
<ol class="comments"> <ol class="comments">
<li class="response-local"> <li class="new-comment response-local">
<form class="comment-form"> <form class="comment-form" data-id="${'<%- wmdId %>'}">
<input type="text" placeholder="Comment&hellip;" class="comment-form-input"> <ul class="discussion-errors"></ul>
<div class="comment-body" data-id="${'<%- wmdId %>'}"></div>
<div class="comment-post-control">
<a class="discussion-submit-comment control-button" href="#">Submit</a>
</div>
</form> </form>
</li> </li>
</ol> </ol>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment