Sha256: 7262846acb57c5a78c54875012e42605379716da0b6335494ce2df720e8e223a

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

class Meyasubako
  constructor: ->
    @setToggleEvent()
    @setSubmitEvent()

  setToggleEvent: ->
    $('.meyasubako__heading').on 'click', ->
      container = $('.meyasubako__container')

      # Switch form visibility
      if container.is(':visible') then container.hide() else container.show()

  setSubmitEvent: ->
    $('.meyasubako__submit').on 'click', ->
      # Return if textarea is empty
      return false unless $('.meyasubako__content').val()

      # Disable form
      $('.meyasubako__content').attr('disabled', 'disabled')
      $('.meyasubako__submit').attr('disabled', 'disabled')

      # Show sending message
      $('.meyasubako__message__container').fadeIn()

      # Blink message
      interval =
        setInterval ->
          $('.meyasubako__message--sending').fadeOut 500, ->
            $(this).fadeIn 500
        , 1000

      $.ajax
        type: 'post'
        url: '/meyasubako'
        data:
          authenticity_token: $('#authenticity_token').val()
          content:            $('.meyasubako__content').val()

        success: ->
          # Clear animation
          $('.meyasubako__message--sending').stop()

          # Stop blinking
          clearInterval(interval)

          # Show success message
          $('.meyasubako__message--sending').hide()
          $('.meyasubako__message--success').fadeIn()

window.Meyasubako = Meyasubako

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
meyasubako-0.1.0 app/assets/javascripts/meyasubako.coffee
meyasubako-0.0.1 app/assets/javascripts/meyasubako.coffee