$.fn.selectize = function(settings_user) { var defaults = $.fn.selectize.defaults; var settings = $.extend({}, defaults, settings_user); var attr_data = settings.dataAttr; var field_label = settings.labelField; var field_value = settings.valueField; var field_optgroup = settings.optgroupField; var field_optgroup_label = settings.optgroupLabelField; var field_optgroup_value = settings.optgroupValueField; var optionsMap = {}; /** * Initializes selectize from a element. * * @param {object} $input * @param {object} settings_element */ var init_textbox = function($input, settings_element) { var i, n, values, option; var data_raw = $input.attr(attr_data); if (!data_raw) { var value = $.trim($input.val() || ''); if (!settings.allowEmptyOption && !value.length) return; values = value.split(settings.delimiter); for (i = 0, n = values.length; i < n; i++) { option = {}; option[field_label] = values[i]; option[field_value] = values[i]; settings_element.options.push(option); } settings_element.items = values; } else { settings_element.options = JSON.parse(data_raw); for (i = 0, n = settings_element.options.length; i < n; i++) { settings_element.items.push(settings_element.options[i][field_value]); } } }; /** * Initializes selectize from a