<commit_before>class CommentForm
  constructor: (@thread) ->
    @createElement()
    @bindEvents()

  createElement: ->
    @element = document.createElement('li')
    @element.id = 'comment-form'
    @element.className = 'carnival-comment-form'
    @element.innerHTML = "<a class='carnival-create'><span>+</span> Leave a comment</a><form><a class='carnival-cancel'>✖</a><div class='carnival-author'><img src=''><span></span></div><textarea placeholder='Type here&hellip;' class='carnival-body'></textarea><input type='submit' value='Comment'></form>"

  body: ->
    @element.querySelector('.carnival-body').value

  resizeTextarea: ->
    if @scrollHeight > @clientHeight
      @style.height = @scrollHeight + "px"

  bindEvents: ->
    @element.querySelector('textarea').addEventListener 'keyup', @resizeTextarea
    @element.addEventListener 'submit', (event) =>
      event.preventDefault()
      event.stopPropagation()
      @saveComment()
    @element.querySelector('a.carnival-create').addEventListener 'click', (event) =>
      event.preventDefault()
      event.stopPropagation()
      if Carnival.isLoggedIn()
        @showCommentForm()
      else
        Carnival.login()
    @element.querySelector('a.carnival-cancel').addEventListener 'click', (event) =>
      event.preventDefault()
      event.stopPropagation()
      @hideCommentForm()
    @element.querySelector('textarea').addEventListener 'keydown', (event) =>
      if event.keyCode == 13 and event.metaKey
        @saveComment()
    document.addEventListener 'hasLoggedIn', =>
      @showCommentForm()

  hasBody: ->
    @body().replace(/\s/g, '').length > 4

  showCommentForm: ->
    @element.querySelector('a').style.display = 'none'
    @element.querySelector('form').style.display = 'block'
    @element.querySelector('.carnival-author span').innerHTML = Carnival.userName()
    @element.querySelector('.carnival-author img').src = Carnival.userGravatarUrl()
    @element.querySelector('.carnival-body').focus()

  hideCommentForm: ->
    @element.querySelector('form').style.display = 'none'
    @element.querySelector('a').style.display = 'block'

  saveComment: ->
    if @hasBody()
      @thread.add(@body())
      @element.querySelector('.carnival-body').value = ''
<commit_msg>Support quick submit on Linux too<commit_after>class CommentForm
  constructor: (@thread) ->
    @createElement()
    @bindEvents()

  createElement: ->
    @element = document.createElement('li')
    @element.id = 'comment-form'
    @element.className = 'carnival-comment-form'
    @element.innerHTML = "<a class='carnival-create'><span>+</span> Leave a comment</a><form><a class='carnival-cancel'>✖</a><div class='carnival-author'><img src=''><span></span></div><textarea placeholder='Type here&hellip;' class='carnival-body'></textarea><input type='submit' value='Comment'></form>"

  body: ->
    @element.querySelector('.carnival-body').value

  resizeTextarea: ->
    if @scrollHeight > @clientHeight
      @style.height = @scrollHeight + "px"

  bindEvents: ->
    @element.querySelector('textarea').addEventListener 'keyup', @resizeTextarea
    @element.addEventListener 'submit', (event) =>
      event.preventDefault()
      event.stopPropagation()
      @saveComment()
    @element.querySelector('a.carnival-create').addEventListener 'click', (event) =>
      event.preventDefault()
      event.stopPropagation()
      if Carnival.isLoggedIn()
        @showCommentForm()
      else
        Carnival.login()
    @element.querySelector('a.carnival-cancel').addEventListener 'click', (event) =>
      event.preventDefault()
      event.stopPropagation()
      @hideCommentForm()
    @element.querySelector('textarea').addEventListener 'keydown', (event) =>
      if event.keyCode == 13 and (event.metaKey or event.ctrlKey)
        @saveComment()
    document.addEventListener 'hasLoggedIn', =>
      @showCommentForm()

  hasBody: ->
    @body().replace(/\s/g, '').length > 4

  showCommentForm: ->
    @element.querySelector('a').style.display = 'none'
    @element.querySelector('form').style.display = 'block'
    @element.querySelector('.carnival-author span').innerHTML = Carnival.userName()
    @element.querySelector('.carnival-author img').src = Carnival.userGravatarUrl()
    @element.querySelector('.carnival-body').focus()

  hideCommentForm: ->
    @element.querySelector('form').style.display = 'none'
    @element.querySelector('a').style.display = 'block'

  saveComment: ->
    if @hasBody()
      @thread.add(@body())
      @element.querySelector('.carnival-body').value = ''

{'fraction_non_alphanumeric': 0.16984440061363137, 'fraction_numerical': 0.0013149243918474688, 'mean_word_length': 3.9662676822633296, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3204330', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1350, 'n_words': 207}