Sha256: f001a7d963f2bc0d4bf1c32cbac077647b3ec3d79fcbc6b4fe986ea1895b077d

Contents?: true

Size: 1001 Bytes

Versions: 4

Compression:

Stored size: 1001 Bytes

Contents

(($, window) ->

  class DropdownSelectInput
    defaults: {}

    constructor: ($el, options) ->
      @options = $.extend({}, @defaults, options)
      @$el = $el
      @$input = $el.find('input')
      @$toggle = $el.find('.dropdown_toggle_button')

      @$el.on 'click', 'a[data-value]', (e) =>
        $a = $(e.currentTarget)

        @$input.val($a.data('value'))
               .trigger('input')
               .trigger('change')

        $a.closest('li')
          .addClass('active')
          .siblings()
          .removeClass('active')

        @$toggle.text($a.find('.dropdown_select_input_title').text())

  $.fn.extend dropdownSelectInput: (option, args...) ->
    @each ->
      data = $(@).data('dropdown-select-input')

      if !data
        $(@).data 'dropdown-select-input', (data = new DropdownSelectInput($(@), option))
      if typeof option == 'string'
        data[option].apply(data, args)

) window.jQuery, window

$ ->
  $(".dropdown_select_input").dropdownSelectInput()

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
simple_form-dropdown_select-0.0.4 app/assets/javascripts/simple_form/dropdown_select.js.coffee
simple_form-dropdown_select-0.0.3 app/assets/javascripts/simple_form/dropdown_select.js.coffee
simple_form-dropdown_select-0.0.2 app/assets/javascripts/simple_form/dropdown_select.js.coffee
simple_form-dropdown_select-0.0.1 app/assets/javascripts/simple_form/dropdown_select.js.coffee