PageSourceSearch

https://farmersmarketsontario.com/_scripts/_hi5/selectize/selectize.jquery.js

js farmersmarketsontario.com collected 2026-10-01 14:40:45 UTC 4,576 bytes, 160 lines download raw bytes

vendor: 4,576 bytes, lines 1-160
1$.fn.selectize = function(settings_user) {
2	var defaults             = $.fn.selectize.defaults;
3	var settings             = $.extend({}, defaults, settings_user);
4	var attr_data            = settings.dataAttr;
5	var field_label          = settings.labelField;
6	var field_value          = settings.valueField;
7	var field_optgroup       = settings.optgroupField;
8	var field_optgroup_label = settings.optgroupLabelField;
9	var field_optgroup_value = settings.optgroupValueField;
10
11	/**
12	 * Initializes selectize from a <input type="text"> element.
13	 *
14	 * @param {object} $input
15	 * @param {object} settings_element
16	 */
17	var init_textbox = function($input, settings_element) {
18		var i, n, values, option;
19
20		var data_raw = $input.attr(attr_data);
21
22		if (!data_raw) {
23			var value = $.trim($input.val() || '');
24			if (!settings.allowEmptyOption && !value.length) return;
25			values = value.split(settings.delimiter);
26			for (i = 0, n = values.length; i < n; i++) {
27				option = {};
28				option[field_label] = values[i];
29				option[field_value] = values[i];
30				settings_element.options.push(option);
31			}
32			settings_element.items = values;
33		} else {
34			settings_element.options = JSON.parse(data_raw);
35			for (i = 0, n = settings_element.options.length; i < n; i++) {
36				settings_element.items.push(settings_element.options[i][field_value]);
37			}
38		}
39	};
40
41	/**
42	 * Initializes selectize from a <select> element.
43	 *
44	 * @param {object} $input
45	 * @param {object} settings_element
46	 */
47	var init_select = function($input, settings_element) {
48		var i, n, tagName, $children, order = 0;
49		var options = settings_element.options;
50		var optionsMap = {};
51
52		var readData = function($el) {
53			var data = attr_data && $el.attr(attr_data);
54			if (typeof data === 'string' && data.length) {
55				return JSON.parse(data);
56			}
57			return null;
58		};
59
60		var addOption = function($option, group) {
61			$option = $($option);
62
63			var value = hash_key($option.val());
64			if (!value && !settings.allowEmptyOption) return;
65
66			// if the option already exists, it's probably been
67			// duplicated in another optgroup. in this case, push
68			// the current group to the "optgroup" property on the
69			// existing option so that it's rendered in both places.
70			if (optionsMap.hasOwnProperty(value)) {
71				if (group) {
72					var arr = optionsMap[value][field_optgroup];
73					if (!arr) {
74						optionsMap[value][field_optgroup] = group;
75					} else if (!$.isArray(arr)) {
76						optionsMap[value][field_optgroup] = [arr, group];
77					} else {
78						arr.push(group);
79					}
80				}
81				return;
82			}
83
84			var option             = readData($option) || {};
85			option[field_label]    = option[field_label] || $option.text();
86			option[field_value]    = option[field_value] || value;
87			option[field_optgroup] = option[field_optgroup] || group;
88
89			optionsMap[value] = option;
90			options.push(option);
91
92			if ($option.is(':selected')) {
93				settings_element.items.push(value);
94			}
95		};
96
97		var addGroup = function($optgroup) {
98			var i, n, id, optgroup, $options;
99
100			$optgroup = $($optgroup);
101			id = $optgroup.attr('label');
102
103			if (id) {
104				optgroup = readData($optgroup) || {};
105				optgroup[field_optgroup_label] = id;
106				optgroup[field_optgroup_value] = id;
107				settings_element.optgroups.push(optgroup);
108			}
109
110			$options = $('option', $optgroup);
111			for (i = 0, n = $options.length; i < n; i++) {
112				addOption($options[i], id);
113			}
114		};
115
116		settings_element.maxItems = $input.attr('multiple') ? null : 1;
117
118		$children = $input.children();
119		for (i = 0, n = $children.length; i < n; i++) {
120			tagName = $children[i].tagName.toLowerCase();
121			if (tagName === 'optgroup') {
122				addGroup($children[i]);
123			} else if (tagName === 'option') {
124				addOption($children[i]);
125			}
126		}
127	};
128
129	return this.each(function() {
130		if (this.selectize) return;
131
132		var instance;
133		var $input = $(this);
134		var tag_name = this.tagName.toLowerCase();
135		var placeholder = $input.attr('placeholder') || $input.attr('data-placeholder');
136		if (!placeholder && !settings.allowEmptyOption) {
137			placeholder = $input.children('option[value=""]').text();
138		}
139
140		var settings_element = {
141			'placeholder' : placeholder,
142			'options'     : [],
143			'optgroups'   : [],
144			'items'       : []
145		};
146
147		if (tag_name === 'select') {
148			init_select($input, settings_element);
149		} else {
150			init_textbox($input, settings_element);
151		}
152
153		instance = new Selectize($input, $.extend(true, {}, defaults, settings_element, settings_user));
154	});
155};
156
157$.fn.selectize.defaults = Selectize.defaults;
158$.fn.selectize.support = {
159	validity: SUPPORTS_VALIDITY_API
160};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.