(function ($) {
    $.field_events = function (element, options) {
        var defaults = {
        }
        var plugin = this;
        plugin.settings = {}
        var $element = $(element), 
            element = element;    
        
        plugin.init = function () {
            plugin.settings = $.extend({}, defaults, options);
            $element.find('.list-event').select2(
                {
                    templateSelection: function (data) {
                        let text = data.text;
                        text = text.substr(0, 15);
                        let $result = $(
                            `${text}`
                        );
                        return text;
                    },
                    escapeMarkup: function (m) {
                        return m;
                    },
                }
            );
        };
        plugin.example_function = function () {
        };
        plugin.init();
    }
    
    $.fn.field_events = function (options) {
        
        return this.each(function () {
            
            if (undefined == $(this).data('field_events')) {
                var plugin = new $.field_events(this, options);
                $(this).data('field_events', plugin);
            }
        });
    }
})(jQuery);