Sha256: 52b3c15c279e0c1e204a25c84b02fc459dd66385eecab5266b8dd636b8bed45b

Contents?: true

Size: 830 Bytes

Versions: 10

Compression:

Stored size: 830 Bytes

Contents

window.Alchemy = {} if typeof(window.Alchemy) is 'undefined'

Alchemy.Autocomplete =

  tags: (scope) ->
    field = $('[data-autocomplete]', scope)
    url = field.data('autocomplete')
    field.select2
      tags: true
      tokenSeparators: [","]
      minimumInputLength: 1
      openOnEnter: false
      createSearchChoice: @_createResultItem
      ajax:
        url: url
        dataType: 'json'
        data: (term, page) -> term: term
        results: (data, page) -> results: data
      initSelection: @_initializeSelection

  _createResultItem: (term, data) ->
    if $(data).filter(-> @text.localeCompare(term) is 0).length is 0
      id: term
      text: term

  _initializeSelection: (element, callback) ->
    data = []
    $(element.val().split(",")).each ->
      data.push id: this, text: this
    callback(data)

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
alchemy_cms-3.0.4 app/assets/javascripts/alchemy/alchemy.autocomplete.js.coffee
alchemy_cms-3.0.3 app/assets/javascripts/alchemy/alchemy.autocomplete.js.coffee
alchemy_cms-3.1.0.beta1 app/assets/javascripts/alchemy/alchemy.autocomplete.js.coffee
alchemy_cms-3.0.2 app/assets/javascripts/alchemy/alchemy.autocomplete.js.coffee
alchemy_cms-3.0.1 app/assets/javascripts/alchemy/alchemy.autocomplete.js.coffee
alchemy_cms-3.0.0 app/assets/javascripts/alchemy/alchemy.autocomplete.js.coffee
alchemy_cms-3.0.0.rc8 app/assets/javascripts/alchemy/alchemy.autocomplete.js.coffee
alchemy_cms-3.0.0.rc7 app/assets/javascripts/alchemy/alchemy.autocomplete.js.coffee
alchemy_cms-3.0.0.rc6 app/assets/javascripts/alchemy/alchemy.autocomplete.js.coffee
alchemy_cms-3.0.0.rc5 app/assets/javascripts/alchemy/alchemy.autocomplete.js.coffee