gitlab-org--gitlab-foss/app/assets/javascripts/gl_form.js.coffee

52 lines
1.2 KiB
CoffeeScript
Raw Normal View History

class @GLForm
constructor: (@form) ->
2016-04-05 05:34:02 -04:00
@textarea = @form.find('textarea.js-gfm-input')
2016-04-05 05:34:02 -04:00
# Before we start, we should clean up any previous data for this form
@destroy()
# Setup the form
@setupForm()
2016-04-05 05:28:10 -04:00
@form.data 'gl-form', @
destroy: ->
# Clean form listeners
@clearEventListeners()
@form.data 'gl-form', null
setupForm: ->
isNewForm = @form.is(':not(.gfm-form)')
2016-04-05 05:28:10 -04:00
@form.removeClass 'js-new-note-form'
if isNewForm
@form.find('.div-dropzone').remove()
@form.addClass('gfm-form')
2016-04-05 05:28:10 -04:00
disableButtonIfEmptyField @form.find('.js-note-text'), @form.find('.js-comment-button')
# remove notify commit author checkbox for non-commit notes
GitLab.GfmAutoComplete.setup()
new DropzoneInput(@form)
autosize(@textarea)
# form and textarea event listeners
@addEventListeners()
# hide discard button
@form.find('.js-note-discard').hide()
@form.show()
2016-04-05 05:28:10 -04:00
clearEventListeners: ->
@textarea.off 'focus'
@textarea.off 'blur'
addEventListeners: ->
@textarea.on 'focus', ->
$(@).closest('.md-area').addClass 'is-focused'
@textarea.on 'blur', ->
$(@).closest('.md-area').removeClass 'is-focused'