PageSourceSearch

https://hanumanchicago.org/wp-content/plugins/repeater-for-contact-form-7/libs/cf7_repeater.js?ver=1791000678

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