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()