Sha256: 8f789c3abf361ba726122524cf59aae29cf0bbbd0d713bc8fe4e1d0490f3dd0d

Contents?: true

Size: 1.41 KB

Versions: 11

Compression:

Stored size: 1.41 KB

Contents

# -----------------------------------------------------------------------------
# Author: Alexander Kravets <alex@slatestudio.com>,
#         Slate Studio (http://www.slatestudio.com)
#
# Coding Guide:
#   https://github.com/thoughtbot/guides/tree/master/style/coffeescript
# -----------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# 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

11 entries across 11 versions & 2 rubygems

Version Path
formagic-0.3.4 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.3.3 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.3.2 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.3.1 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.3.0 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.2.9 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.2.8 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.2.6 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.2.5 app/assets/javascripts/formagic/inputs/color.coffee
formagic-0.1.0 app/assets/javascripts/formagic/inputs/color.coffee
chr-0.3.5 app/assets/javascripts/form/input-color.coffee