Sha256: 4f71cc079a07a5f61b3b573911af1997c5542c3d007e856e0e9069409b4f57bd

Contents?: true

Size: 1013 Bytes

Versions: 18

Compression:

Stored size: 1013 Bytes

Contents

#= require jquery
#= require chosen/chosen.jquery
#= require ajax-chosen/lib/ajax-chosen
#= require underscore

# Selects all options of a multi-select box belonging to a optgroup, when
# clicking on the optgroup label.
init_group_selectable = (select) ->
  chosen = select.next()
  chosen.on 'click', '.group-result', (e) ->
    target = $(e.target)
    group_name = target.text()
    options = select.find('optgroup[label="' + group_name + '"]').children()
    options.attr('selected', 'selected')
    select.trigger('chosen:updated')

$ ->
  $('.ui-components-select').each ->
    $this = $(this)

    data = transform_keys $this.data(), underscore
    data.search_contains = true
    $this.chosen data

    init_group_selectable($this)

    if data.remote_options
      $this.ajaxChosen
        type: 'GET'
        url: data.remote_options
        dataType: 'json'

underscore = (str) -> str.replace /[A-Z]/g, (m) -> '_' + m.toLowerCase()

transform_keys = (obj, f) -> _.object _.map obj, (v, k) -> [f(k), v]

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ad2games-ui_components-2.4.2 app/cells/select/select.coffee
ad2games-ui_components-2.4.1 app/cells/select/select.coffee
ad2games-ui_components-2.4.0 app/cells/select/select.coffee
ad2games-ui_components-2.3.0 app/cells/select/select.coffee
ad2games-ui_components-2.1.0 app/cells/select/select.coffee
ad2games-ui_components-2.0.14 app/cells/select/select.coffee
ad2games-ui_components-2.0.12 app/cells/select/select.coffee
ad2games-ui_components-2.0.11 app/cells/select/select.coffee
ad2games-ui_components-2.0.10 app/cells/select/select.coffee
ad2games-ui_components-2.0.9 app/cells/select/select.coffee
ad2games-ui_components-2.0.8 app/cells/select/select.coffee
ad2games-ui_components-2.0.7 app/cells/select/select.coffee
ad2games-ui_components-2.0.5 app/cells/select/select.coffee
ad2games-ui_components-2.0.4 app/cells/select/select.coffee
ad2games-ui_components-2.0.3 app/cells/select/select.coffee
ad2games-ui_components-2.0.2 app/cells/select/select.coffee
ad2games-ui_components-2.0.1 app/cells/select/select.coffee
ad2games-ui_components-2.0.0 app/cells/select/select.coffee