PageSourceSearch

https://blackcalderbrewing.com/wp-content/themes/uncode/library/js/woocommerce-swatches.js?ver=181331529

js blackcalderbrewing.com collected 2026-10-08 20:07:23 UTC 4,330 bytes, 164 lines download raw bytes

1(function($) {
2	"use strict";
3
4	function find_select(variation_form, id) {
5		var selects = variation_form.find('select');
6		var select = false;
7
8		selects.each(function() {
9			var _this = $(this);
10
11			if (_this.attr('id').toLowerCase() == encodeURIComponent(id).toLowerCase()) {
12				select = _this;
13				return true;
14			}
15		});
16
17		return select;
18	}
19
20	function find_swatch(swatch_selector, value) {
21		var swatches = swatch_selector.find('.swatch');
22		var swatch = false;
23
24		swatches.each(function() {
25			var _this = $(this);
26
27			if (_this.attr('data-swatch-value') == value) {
28				swatch = _this;
29				return true;
30			}
31		});
32
33		return swatch;
34	}
35
36	function init_general_swatches() {
37		var variation_forms = $('.variations_form');
38
39		variation_forms.each(function() {
40			var variation_form = $(this);
41
42			if (variation_form.data('swatches')) {
43				return;
44			}
45
46			variation_form.data('swatches', true);
47
48			variation_form.on('click', '.swatches-select > .swatch', function() {
49				var _this = $(this);
50				var value = _this.data('swatch-value');
51				var id = _this.parent().data('swatch-id');
52				var title = _this.data('swatch-title');
53
54				if (variation_form.hasClass('is-updating-gallery')) {
55					return;
56				}
57
58				reset_general_swatches(variation_form);
59
60				if (_this.hasClass('swatch--active')) {
61					return;
62				}
63
64				if (_this.hasClass('swatch--disabled')) {
65					return;
66				}
67
68				if (window.UncodeWCParameters != undefined && window.UncodeWCParameters.swatches_use_custom_find === '1') {
69					var select = find_select(variation_form, id);
70					select.val(value).trigger('change');
71				} else {
72					variation_form.find('select#' + id).val(value).trigger('change');
73				}
74
75				_this.parent().find('.swatch--active').removeClass('swatch--active');
76				_this.addClass('swatch--active');
77				reset_general_swatches(variation_form);
78			})
79			.on('woocommerce_update_variation_values', function() {
80				reset_general_swatches(variation_form);
81			})
82			.on('click', '.reset_variations', function() {
83				variation_form.find('.swatch--active').removeClass('swatch--active');
84			})
85		});
86	}
87
88	function reset_general_swatches(variation_form) {
89		if (variation_form.data('product_variations') === false) {
90			return;
91		}
92
93		var has_hidden_swatch = false;
94
95		variation_form.find('.variations select').each(function() {
96			var select = $(this);
97			var swatch_selector = select.parent().find('.swatches-select');
98			var options = select.html();
99
100			options = $(options);
101
102			swatch_selector.find('> .swatch').removeClass('swatch--enabled').addClass('swatch--disabled');
103
104			options.each(function() {
105				var value = $(this).val();
106
107				if ($(this).hasClass('enabled')) {
108					if (window.UncodeWCParameters != undefined && window.UncodeWCParameters.swatches_use_custom_find === '1') {
109						var swatch = find_swatch(swatch_selector, value);
110						if (swatch) {
111							swatch.removeClass('swatch--disabled').addClass('swatch--enabled');
112						}
113					} else {
114						swatch_selector.find('.swatch[data-swatch-value="' + value + '"]').removeClass('swatch--disabled').addClass('swatch--enabled');
115					}
116				} else {
117					if (window.UncodeWCParameters != undefined && window.UncodeWCParameters.swatches_use_custom_find === '1') {
118						var swatch = find_swatch(swatch_selector, value);
119						if (swatch) {
120							swatch.removeClass('swatch--disabled').addClass('swatch--enabled');
121						}
122					} else {
123						swatch_selector.find('.swatch[data-swatch-value="' + value + '"]').addClass('swatch--disabled').removeClass('swatch--enabled');
124					}
125				}
126			});
127
128			var hidden_swatches = swatch_selector.find('> .swatch--active.hidden');
129
130			if (hidden_swatches.length > 0) {
131				hidden_swatches.remove();
132				has_hidden_swatch = true;
133			}
134		});
135
136		if (has_hidden_swatch) {
137			$('.swatch--active').removeClass('swatch--active');
138		}
139	}
140
141	function init_more_swacthes_link() {
142		var more_link = $('.swatches-more-link');
143
144		more_link.on('click', function() {
145			var link = $(this).data('link');
146
147			if (link) {
148				window.location = link;
149			}
150		});
151	}
152
153	init_more_swacthes_link();
154	init_general_swatches();
155
156	$(document).on('uncode-quick-view-loaded more-items-loaded', function() {
157		init_more_swacthes_link();
158		init_general_swatches();
159	});
160
161	$(document).on('uncode-ajax-filtered', function() {
162		init_general_swatches();
163	});
164})(jQuery);

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.