Sha256: b5b05223ae5800955dcd834d4276064cf9c2b704f184dd358e84a44d945249c8

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

# -----------------------------------------------------------------------------
# Author: Alexander Kravets <alex@slatestudio.com>,
#         Slate Studio (http://www.slatestudio.com)
# -----------------------------------------------------------------------------
# INPUT COLOR
# -----------------------------------------------------------------------------
class @InputColor extends InputString

  # PRIVATE ===================================================================

  _add_color_preview: ->
    @$colorPreview =$ "<div class='preview'>"
    @$el.append @$colorPreview

  _update_color_preview: ->
    @$colorPreview.css { 'background-color': "##{ @$input.val() }" }

  _validate_input_value: ->
    if (/^(?:[0-9a-f]{3}){1,2}$/i).test(@$input.val())
      @hideErrorMessage()
    else
      @showErrorMessage('Invalid hex value')

  # PUBLIC ====================================================================

  initialize: ->
    @config.beforeInitialize?(this)

    @$input.attr('placeholder', @config.placeholder || 'e.g. #eee')

    @_add_color_preview()
    @_update_color_preview()

    @$input.on 'change keyup',  (e) =>
      @hideErrorMessage()
      @_validate_input_value()
      @_update_color_preview()

    @config.onInitialize?(this)

chr.formInputs['color'] = InputColor

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
formagic-0.3.10 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.3.9 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.3.8 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.3.7 app/assets/javascripts/formagic/inputs/color.coffee