{% init _is_select2_loaded = False %}

{% if not _is_select2_loaded %} 
    {% set-global _is_select2_loaded = True %}
    <link rel="stylesheet" href="{{_server_home}}/_static/lib/select2/4.0.13/select2.min.css" type="text/css" />
    <script type="text/javascript" src="{{_server_home}}/_static/lib/select2/4.0.13/select2.min.js"></script>
    <script>
        xnote.initSelect2 = function () {
            // 只有大于等于10个选项时展示搜索
            $("select").each(function (index, elem) {
                var parent = $(elem).parents(".layui-layer-content");
                if (parent.length == 0) {
                    parent = undefined;
                }
                if ($(elem).attr("data-disable-select2")) {
                    return;
                }
                // select2默认支持 data-placeholder
                // https://select2.org/configuration/data-attributes
                $(elem).select2({
                    minimumResultsForSearch: 10,
                    dropdownParent:parent
                });
            })
        };
    
        $(function () {
            xnote.initSelect2();
        });
    </script>
{% end %}

