blob: 2e3884d7f2b138e8349e4de4ce5394beee7deea3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
bind_select2 = (el, cfg = {}) ->
target = $(el)
default_cfg =
theme: 'bootstrap'
language: 'fr'
placeholder: target.data('select2ed-placeholder')
allowClear: false
target.select2 $.extend({}, default_cfg, cfg)
bind_select2_ajax = (el, cfg = {}) ->
target = $(el)
cfg =
ajax:
data: (params) ->
q:
"#{target.data('term')}": params.term
url: target.data('url'),
dataType: 'json',
delay: 125,
processResults: (data, params) -> results: data
minimumInputLength: 1
placeholder: target.data('select2ed-placeholder')
templateResult: (item) ->
item.text
templateSelection: (item) ->
item.text
escapeMarkup: (markup) ->
markup
bind_select2(el, cfg)
@select_2 = ->
$("[data-select2ed='true']").each ->
bind_select2(this)
$("[data-select2-ajax='true']").each ->
bind_select2_ajax(this)
$('select.form-control.tags').each ->
bind_select2(this, {tags: true})
$ ->
select_2()
|