PageSourceSearch

https://sandsrx.com/wp-content/plugins/repeater-for-contact-form-7/libs/cf7_repeater.js?ver=1791247280

js sandsrx.com collected 2026-10-06 07:27:52 UTC 11,492 bytes, 307 lines download raw bytes

1(function ($) {
2	"use strict";
3	jQuery(document).ready(function ($) {
4		document.addEventListener('change', function (event) {
5			const el = event.target;
6			var $form = $(el).closest('form.wpcf7-form');
7			if (!$form.length) {
8				return;
9			}
10			$(".repeater-field-content .wpcf7-not-valid-tip",$form).remove();
11		}, false);
12		document.addEventListener('wpcf7invalid', function (event) {
13			$.each(event.detail.apiResponse.invalid_fields, function (index, value) {
14				if (value.idref == "yeeaddons") {
15					$('[name="' + value.field + '"]').closest(".wpcf7-form-control-wrap").append('<span class="wpcf7-not-valid-tip" aria-hidden="true">' + value.message + '</span>');
16				}
17			});
18		}, false);
19		get_repeater_data_name();
20		document.addEventListener('wpcf7mailsent', function (event) {
21			setTimeout(function () {
22				$(".field-repeater-data").each(function () {
23					var field = $(this);
24					var data = JSON.stringify(field.data("old"));
25					field.val(data).change();
26				})
27			}, 100);
28		}, false);
29		var list_names = [];
30		function change_name_and_ids(item, field_end = null, id_rand = '') {
31			var datas = JSON.parse(field_end.find(".field-repeater-data").val());
32			var datas_ids = datas.id;
33			datas_ids.push(id_rand);
34			datas.id = datas_ids;
35			field_end.find(".field-repeater-data").val(JSON.stringify(datas));
36			field_end.find(".field-repeater-data").attr("data-old", JSON.stringify(datas));
37			item = $("<div>" + item + "</div>");
38			$(item.find(".cf7-group")).each(function () {
39				var id = $(this).attr("id");
40				$(this).attr("id", id + "__" + id_rand);
41			})
42			$("input", item).each(function () {
43				var name = $(this).attr("name");
44				list_names.push(name);
45				var type = $(this).attr("type");
46				var id = $(this).attr("id");
47				var index = $(this).closest(".container-repeater-field").data("step");
48				if (type == "radio") {
49					$(this).attr("name", name + "__" + id_rand);
50				} else if (type == 'checkbox') {
51					name = name.replace("[]", "__" + id_rand + "[]");
52					$(this).attr("name", name);
53				} else if (type == 'file') {
54					if ($(this).attr("multiple") == "multiple") {
55						name = name.replace("[]", "__" + id_rand + "[]");
56						$(this).attr("name", name + "[]");
57					} else {
58						$(this).attr("name", name + "__" + id_rand);
59					}
60				} else {
61					$(this).attr("name", name + "__" + id_rand);
62				}
63				$(this).attr("id", id + "-" + id_rand + "");
64			})
65			$("textarea", item).each(function () {
66				var name = $(this).attr("name");
67				list_names.push(name);
68				var id = $(this).attr("id");
69				$(this).attr("name", name + "__" + id_rand);
70				$(this).attr("id", id + "-" + id_rand + "");
71			})
72			$("select", item).each(function () {
73				var name = $(this).attr("name");
74				list_names.push(name);
75				var id = $(this).attr("id");
76				if ($(this).attr("multiple") == "multiple") {
77					name = name.replace("[]", "__" + id_rand + "[]");
78				} else {
79					$(this).attr("name", name + "__" + id_rand);
80				}
81				$(this).attr("id", id + "-" + id_rand + "");
82			})
83			if (list_names.length > 0) {
84				list_names = [...new Set(list_names)];
85				$('input[name="_yeeaddons_cf7_repeater_fields"]').val(list_names.join("|"));
86			}
87			return item;
88		}
89		function add_repeater_data(button) {
90			var id_rand = Math.floor(Math.random() * 10000);
91			var item = $('<div class="repeater-field-item"><div class="repeater-field-header"></div><div class="repeater-field-content"></div></div>');
92			item.attr("data-id", id_rand);
93			var html_field = get_repeater_data(button, id_rand);
94			var header = get_repeater_data_header(button);
95			item.find(".repeater-field-header").append(header);
96			item.find(".repeater-field-content").append(html_field);
97			button.find(".cf7-field-repeater-reponese").append(item);
98			update_repeater_count_header();
99			$("input").trigger("done_load_repeater");
100		}
101		function get_repeater_data(step_field, id_rand) {
102			var html_step = change_name_and_ids(step_field.find(".cf7-field-repeater-data-
102html").html(), step_field, id_rand);
103			return html_step;
104		}
105		function get_repeater_data_name() {
106			var i = 1;
107			$(".cf7-repeater").each(function () {
108				var datas = $(this).find(".field-repeater-data").data("datas") + " yeeaddons_test";
109				var title = explode_datas(datas, "title");
110				var button_text = explode_datas(datas, "button_text");
111				var data_header = $(this).find(".repeater-field-header-data").html();
112				data_header = $(data_header);
113				data_header.find(".repeater-field-header-title-text").html(title);
114				$(".repeater-field-button-add", $(this)).html(button_text);
115				$(this).find(".repeater-field-header-data").html(data_header);
116				var html_step = $("<div class='container-repeater-field'></div>");
117				var names = [];
118				var step_field_data = $(this).find(".field-repeater-data");
119				var field_end = $(this).find(".cf7-field-repeater-data-html").html();
120				var button = $(this);
121				$("input,select,textarea", $(field_end)).each(function (index) {
122					names.push($(this).attr("name"));
123				})
124				step_field_data.val(JSON.stringify({ "count": 1, "fields": names, "id": [] }));
125				step_field_data.attr("data-old", JSON.stringify({ "count": 1, "fields": names, "id": [] }));
126				var initial_rows = 0;
127				initial_rows = explode_datas(datas, "initial_rows");
128				if (cf7_repeater.pro != "ok") {
129					if (initial_rows > 1) {
130						alert("Free version: initial_rows < 2");
131						initial_rows = 1;
132					}
133				}
134				if (cf7_repeater.pro == "ok") {
135					var initial_rows_map_field = explode_datas(datas, "initial_rows_map");
136					var initial_rows_map_number = $('[name="' + initial_rows_map_field + '"]').val();
137					if (initial_rows_map_number !== undefined) {
138						$('[name="' + initial_rows_map_field + '"]').attr("data-repeater", $(this).find(".field-repeater-data").attr("name"));
139						$('[name="' + initial_rows_map_field + '"]').attr("repeater_initial_rows", "ok");
140						initial_rows = initial_rows_map_number;
141						$(this).find(".repeater-field-button-add").addClass("hidden");
142						$(this).addClass("repeater-remove-toolbar");
143					}
144				}
145				setTimeout(function () {
146					for (var j = 0; j < initial_rows; j++) {
147						add_repeater_data(button);
148					}
149				}, 100);
150				i++;
151			})
152		}
153		$("body").on("change", "[repeater_initial_rows='ok']", function (e) {
154			if (cf7_repeater.pro == "ok") {
155				var repeater_id = $(this).data("repeater");
156				$("#" + repeater_id).find(".repeater-field-item").remove();
157				var number = $(this).val();
158				for (let i = 0; i < number; i++) {
159					$("#" + repeater_id).find(".repeater-field-button-add").click();
160				}
161			}
162		})
163		function get_repeater_data_header(start_field) {
164			var html_step = start_field.find(".repeater-field-header-data").html()
165			return html_step;
166		}
167		function update_repeater_count_header() {
168			$(".cf7-repeater").each(function () {
169				var i = 1;
170				$(".repeater-field-item", $(this)).each(function () {
171					$(this).find(".repeater-field-header-count").html(i);
172					$(this).addClass("repeater-field-item-" + i);
173					i++;
174				})
175				var datas = JSON.parse($(this).find(".field-repeater-data").val());
176				datas.count = i - 1;
177				$(this).find(".field-repeater-data").val(JSON.stringify(datas));
178				$(this).find(".field-repeater-data").attr("data-old", JSON.stringify(datas));
179			});
180		}
181		function check_max_row(step_field) {
182			var max = explode_datas(step_field.find(".field-repeater-data").data("datas"));
183			console.log(step_field.find(".field-repeater-data").data("datas"));
184			console.log(max);
185			var number_item = $('.repeater-field-item', step_field).length;
186			if (number_item >= max) {
187				return false;
188			} else {
189				return true;
190			}
191		}
192		function check_min_row(step_field) {
193			var min = explode_datas(step_field.find(".field-repeater-data").data("datas"), "initial_rows");
194			var number_item = $('.repeater-field-item', step_field).length;
195			if (number_item <= min) {
196				return false;
197			} else {
198				return true;
199			}
200		}
201		function explode_datas(str = "", type = "max") {
202			if (type == "max") {
203				const regex = /max\s*:\s*(\d+)/;
204				const match = str.match(regex);
205				return match ? parseInt(match[1], 10) : 100;
206			} else if (type == "initial_rows") {
207				const regex = /initial_rows\:(.\d?) /gm;
208				let m;
209				let max = 1;
210				while ((m = regex.exec(str)) !== null) {
211					if (m.index === regex.lastIndex) {
212						regex.lastIndex++;
213					}
214					m.forEach((match, groupIndex) => {
215						max = match;
216					});
217				}
218				return max;
219			}
220			else if (type == "title") {
221				const regex = /title\:'(.*?)' /gm;
222				let m;
223				let max = "";
224				while ((m = regex.exec(str)) !== null) {
225					if (m.index === regex.lastIndex) {
226						regex.lastIndex++;
227					}
228					m.forEach((match, groupIndex) => {
229						max = match;
230					});
231				}
232				return max;
233			} else if (type == "button_text") {
234				const regex = /button\:'(.*?)' /gm;
235				let m;
236				let max = "Add more";
237				while ((m = regex.exec(str)) !== null) {
238					if (m.index === regex.lastIndex) {
239						regex.lastIndex++;
240					}
241					m.forEach((match, groupIndex) => {
242						max = match;
243					});
244				}
245				return max;
246			} else if (type == "initial_rows_map") {
247				const regex = /initial_rows_map\:(.*?) /gm;
248				let m;
249				let max = "";
250				while ((m = regex.exec(str)) !== null) {
251					if (m.index === regex.lastIndex) {
252						regex.lastIndex++;
253					}
254					m.forEach((match, groupIndex) => {
255						max = match;
256					});
257				}
258				return max;
259			}
260		}
261		function removeAR(arr) {
262			var what, a = arguments, L = a.length, ax;
263			while (L > 1 && arr.length) {
264				what = a[--L];
265				while ((ax = arr.indexOf(what)) !== -1) {
266					arr.splice(ax, 1);
267				}
268			}
269			return arr;
270		}
271		$("body").on("click", ".repeater-field-button-add", function (e) {
272			e.preventDefault();
273			if (check_max_row($(this).closest(".cf7-repeater"))) {
274				add_repeater_data($(this).closest(".cf7-repeater"));
275			} else {
276				$(this).addClass('hidden');
277			}
278		})
279		$("body").on("click", ".repeater-field-header-acctions-toogle", function (e) {
280			e.preventDefault();
281			if ($(this).hasClass("icon-down-open")) {
282				$(this).removeClass("icon-down-open");
283				$(this).addClass("icon-up-open");
284			} else {
285				$(this).addClass("icon-down-open");
286				$(this).removeClass("icon-up-open");
287			}
288			$(this).closest(".repeater-field-item").find(".repeater-field-content").slideToggle("slow");
289			$(this).closest(".repeater-field-item").find(".repeater-field-header").toggleClass('repeater-content-show');
290		})
291		$("body").on("click", ".repeater-field-header-acctions-remove", function (e) {
292			e.preventDefault();
293			if (check_min_row($(this).closest(".cf7-repeater"))) {
294				var id = $(this).closest(".repeater-field-item").data("id");
295				var datas = JSON.parse($(this).closest(".cf7-repeater").find(".field-repeater-data").val());
296				var datas_ids = datas.id;
297				datas_ids = removeAR(datas_ids, id);
298				datas.id = datas_ids;
299				$(this).closest(".cf7-repeater").find(".field-repeater-data").val(JSON.stringify(datas));
300				$(this).closest(".cf7-repeater").find(".field-repeater-data").attr("data-old", JSON.stringify(datas));
301				$(this).closest(".repeater-field-item").remove();
302			} else {
303			}
304			update_repeater_count_header();
305		})
306	})
307})(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.