Sha256: 3de99a9c894a3fd6b0d7d286df8ef558110f53ff33c16c72773fef2e74b72e5d

Contents?: true

Size: 1.68 KB

Versions: 15

Compression:

Stored size: 1.68 KB

Contents

$.fn.select2.defaults.set("theme", "bootstrap")

decko.slotReady (slot) ->
  slot.find('select:not(._no-select2)').each (_i) ->
    decko.initSelect2($(this))

decko.slotDestroy (slot) ->
  slot.find('select:not(._no-select2)').each (_i) ->
    $(this).deInitSelect2()

$.extend decko,
  initSelect2: (elem) ->
    if elem.length > 1
      decko.initSelect2($(single_el)) for single_el in elem
    else
      opts = { dropdownAutoWidth: "true", containerCssClass: ":all:", width: "auto" }

      elem.attr "id", decko.uniqSelect2Id(elem.attr("id"))
      if elem.hasClass("tags")
        opts.tags = "true"
      if elem.data("minimum-results-for-search")?
        opts.minimumResultsForSearch = elem.data("minimum-results-for-search")
      elem.select2(opts)

  uniqSelect2Id: (id) ->
    return id unless $("[data-select2-id=" + id + "]").length > 0
    decko.uniqSelect2Id id + "1"


$(window).ready ->
  $('body').on 'select2:select', '._go-to-selected', ->
    val = $(this).val()
    if val != ''
      window.location = decko.path(escape(val))

  $('body').on "select2:select", "._submit-on-select", (event) ->
      $(event.target).closest('form').submit()

$.fn.extend
  cloneSelect2: (withDataAndEvents, deepWithDataAndEvents) ->
    $old = if this.is('select') then this else this.find('select')
    $old.deInitSelect2()
    $cloned = this.clone(withDataAndEvents, deepWithDataAndEvents)
    decko.initSelect2 $old
    if $cloned.is('select')
      decko.initSelect2 $cloned
    else
      decko.initSelect2 $cloned.find('select')
    $cloned

  deInitSelect2: ->
    return unless @attr "data-select2-id"
    @select2 "destroy"
    @removeAttr "data-select2-id"
    @find("option").removeAttr "data-select2-id"

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
card-mod-bootstrap-0.14.2 assets/script/script_load_select2.js.coffee
card-mod-bootstrap-0.14.1 assets/script/script_load_select2.js.coffee
card-mod-bootstrap-0.14.0 assets/script/script_load_select2.js.coffee
card-mod-bootstrap-0.13.4 assets/script/script_load_select2.js.coffee
card-mod-bootstrap-0.13.3 assets/script/script_load_select2.js.coffee
card-mod-bootstrap-0.13.2 assets/script/script_load_select2.js.coffee
card-mod-bootstrap-0.11.7 lib/javascript/script_load_select2.js.coffee
card-mod-bootstrap-0.12.0 lib/javascript/script_load_select2.js.coffee
card-mod-bootstrap-0.11.6 lib/javascript/script_load_select2.js.coffee
card-mod-bootstrap-0.11.5 lib/javascript/script_load_select2.js.coffee
card-mod-bootstrap-0.11.4 lib/javascript/script_load_select2.js.coffee
card-mod-bootstrap-0.11.3 lib/javascript/script_load_select2.js.coffee
card-mod-bootstrap-0.11.2 lib/javascript/script_load_select2.js.coffee
card-mod-bootstrap-0.11.1 lib/javascript/script_load_select2.js.coffee
card-mod-bootstrap-0.11.0 lib/javascript/script_load_select2.js.coffee