blob: 8e3c3cbdde75644597b4523c9caa629d9f770a1a (
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
47
|
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 = {}) ->
_this = $(el)
cfg =
ajax:
data: (params) ->
if _this.data('term')
{ q: "#{_this.data('term')}": params.term }
else
{ q: params.term }
url: _this.data('url'),
dataType: 'json',
delay: 125,
processResults: (data, params) -> results: data
templateResult: (item) ->
item.text
templateSelection: (item) ->
item.text
escapeMarkup: (markup) ->
markup
initSelection : (item, callback) ->
if _this.data('saved')
callback(_this.data('saved'))
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()
|