PageSourceSearch

https://tastematch.app/wp-content/plugins/recipe-card-blocks-by-wpzoom/dist/assets/js/script.js?ver=3.4.15

js tastematch.app collected 2026-10-02 01:15:16 UTC 7,200 bytes, 271 lines download raw bytes

1(function ($, wpzoomRecipeCard) {
2	"use scrict";
3
4	function wpzoom_set_correct_ids_to_recipe_shortcode() {
5		$('.wpzoom-rcb-post-shortcode').each(function( index ) {
6			var parent_id = $(this).data('parent-id');
7
8			$(this).find('.btn-print-link').attr( 'data-recipe-id', parent_id );
9			$(this).find('.wpzoom-rating-stars-container').attr( 'data-recipe-id', parent_id );
10
11		});
12
13		$('.wpzoom-custom-recipe-card-post').each(function( index ) {
14			var recipe_id = $(this).data('recipe-post');
15			$('.wpzoom-recipe-snippet-button.wp-block-wpzoom-recipe-card-block-print-recipe').attr( 'data-recipe-id', recipe_id );
16			$(this).find('.btn-print-link').attr( 'data-recipe-id', recipe_id );
17		});
18
19	}
20
21	function wpzoom_set_servings_size_to_print_button() {
22		const servings_size = $(document)
23			.find(".wpzoom-recipe-card-print-link .btn-print-link")
24			.data("servings-size");
25
26		if (servings_size) {
27			$(document)
28				.find(".wp-block-wpzoom-recipe-card-block-print-recipe")
29				.data("servings-size", servings_size);
30		}
31	}
32
33	function wpzoom_print_recipe(atts) {
34		const defaults = {
35			servings: 0,
36			"reusable-block-id": 0,
37			"recipe-id": 0,
38			"block-type": "recipe-card",
39			"block-id": "wpzoom-recipe-card",
40		};
41
42		atts = {
43			...defaults,
44			...atts,
45		};
46
47		const urlParts = wpzoomRecipeCard.homeURL.split(/\?(.+)/);
48		let printUrl = wpzoom_print_add_url_args(atts, urlParts[0], urlParts);
49
50		const print_window = window.open(printUrl, "_blank");
51		print_window.wpzoomRecipeCard = wpzoomRecipeCard;
52		print_window.onload = function () {
53			print_window.focus();
54			print_window.document.title = document.title;
55			print_window.history.pushState(
56				"",
57				"Print Recipe",
58				location.href.replace(location.hash, "")
59			);
60
61			setTimeout(function () {
62				print_window.print();
63			}, 500);
64
65			print_window.onfocus = function () {
66				setTimeout(function () {
67					print_window.close();
68				}, 500);
69			};
70		};
71	}
72
73	function wpzoom_print_add_url_args(atts, url, urlParts) {
74		if (!atts["recipe-id"]) {
75			return url;
76		}
77		if (wpzoomRecipeCard.permalinks) {
78			url += `wpzoom_rcb_print/${atts["recipe-id"]}/`;
79
80			if (urlParts[1]) {
81				url += `?${urlParts[1]}`;
82				for (const property in atts) {
83					url += `&${property}=${atts[property]}`;
84				}
85			} else {
86				for (const property in atts) {
87					if (!url.match(/\?./)) {
88						url += `?${property}=${atts[property]}`;
89					} else {
90						url += `&${property}=${atts[property]}`;
91					}
92				}
93			}
94		} else {
95			url += `?wpzoom_rcb_print=${atts["recipe-id"]}`;
96			for (const property in atts) {
97				if (!url.match(/\?./)) {
98					url += `?${property}=${atts[property]}`;
99				} else {
100					url += `&${property}=${atts[property]}`;
101				}
102			}
103			if (urlParts[1]) {
104				url += `&${urlParts[1]}`;
105			}
106		}
107
108		return url;
109	}
110
111	$(document).ready(function () {
112		wpzoom_set_servings_size_to_print_button();
113
114		$(
115			".wp-block-wpzoom-recipe-card-block-ingredients .ingredients-list li, .
115wp-block-wpzoom-recipe-card-block-recipe-card .ingredients-list li"
116		).click(function (e) {
117			// Don't do any actions if clicked on link
118			if (e.target.nodeName === "A") {
119				return;
120			}
121			$(this).toggleClass("ticked");
122		});
123
124		let instances = 0;
125
126		$(
127			".wp-block-wpzoom-recipe-card-block-ingredients .ingredients-list li, .wp-block-wpzoom-recipe-card-block-recipe-card .ingredients-list li"
128		).on("mouseover", function (e) {
129			const $ingredientName = $(this).find(".ingredient-item-name");
130			const hasStrikeThrough = $ingredientName.hasClass(
131				"is-strikethrough-active"
132			);
133
134			// Check if strikethrough is disabled
135			if (instances === 0 && !hasStrikeThrough) {
136				instances = 0;
137				return;
138			}
139
140			// Remove strike through if hover on link
141			if (e.target.nodeName === "A") {
142				$ingredientName.removeClass("is-strikethrough-active");
143			} else {
144				if (!hasStrikeThrough) {
145					$ingredientName.addClass("is-strikethrough-active");
146				}
147			}
148
149			instances++;
150		});
151
152		$(
153			".wpzoom-recipe-card-print-link .btn-print-link, .wp-block-wpzoom-recipe-card-block-print-recipe"
154		).each(function () {
155			const $printBtn = $(this);
156
157			$printBtn.on("click", function (e) {
158				const $this = $(this);
159				const recipeID = $this.data("recipe-id");
160				const servings = $this.data("servings-size");
161				const reusableBlockID = $this.data("reusable-block-id");
162
163				const isRecipeCardBlock = $this.parents(
164					".wp-block-wpzoom-recipe-card-block-recipe-card"
165				).length;
166				const isIngredientsBlock = $this.parents(
167					".wp-block-wpzoom-recipe-card-block-ingredients"
168				).length;
169				const isDirectionsBlock = $this.parents(
170					".wp-block-wpzoom-recipe-card-block-directions"
171				).length;
172				const isSnippetButton = $this.hasClass(
173					"wp-block-wpzoom-recipe-card-block-print-recipe"
174				);
175
176				let blockType;
177				let blockId;
178
179				if (isRecipeCardBlock) {
180					blockType = "recipe-card";
181					blockId = $this
182						.parents(
183							".wp-block-wpzoom-recipe-card-block-recipe-card"
184						)
185						.attr("id");
186				} else if (isIngredientsBlock) {
187					blockType = "ingredients-block";
188					blockId = $this
189						.parents(
190							".wp-block-wpzoom-recipe-card-block-ingredients"
191						)
192						.attr("id");
193				} else if (isDirectionsBlock) {
194					blockType = "directions-block";
195					blockId = $this
196						.parents(
197							".wp-block-wpzoom-recipe-card-block-directions"
198						)
199						.attr("id");
200				} else if (isSnippetButton) {
201					blockType = "recipe-card";
202					blockId = $this
203						.attr("href")
204						.substr(1, $this.attr("href").length);
205				}
206
207				// Print attributes.
208				const atts = {};
209				if (recipeID) {
210					atts["recipe-id"] = recipeID;
211				}
212				if (reusableBlockID) {
213					atts["reusable-block-id"] = reusableBlockID;
214				}
215				if (servings) {
216					atts["servings"] = servings;
217				}
218				if (blockType) {
219					atts["block-type"] = blockType;
220				}
221				if (blockId) {
222					atts["block-id"] = blockId;
223				}
224
225				if (recipeID) {
226					e.preventDefault();
227					wpzoom_print_recipe(atts);
228				}
229			});
230		});
231		wpzoom_set_correct_ids_to_recipe_shortcode();
232	});
233})(jQuery, wpzoomRecipeCard);
234
235/**
236 * Make embeds responsive so they don't overflow their container.
237 * Add max-width & max-height to <iframe> elements, depending on their width & height props.
238 *
239 * @see Twenty Twenty-One file responsive-embeds.js.
240 * @since 2.7.8
241 *
242 * @return {void}
243 */
244function recipeCardResponsiveEmbeds() {
245	let proportion, parentWidth;
246
247	// Loop iframe elements.
248	document.querySelectorAll("iframe").forEach(function (iframe) {
249		// Only continue if the iframe has a width & height defined.
250		if (iframe.width && iframe.height) {
251			// Calculate the proportion/ratio based on the width & height.
252			proportion = parseFloat(iframe.width) / parseFloat(iframe.height);
253			// Get the parent element's width.
254			parentWidth = parseFloat(
255				window
256					.getComputedStyle(iframe.parentElement, null)
257					.width.replace("px", "")
258			);
259			// Set the max-width & height.
260			iframe.style.maxWidth = "100%";
261			iframe.style.maxHeight =
262				Math.round(parentWidth / proportion).toString() + "px";
263		}
264	});
265}
266
267// Run on initial load.
268recipeCardResponsiveEmbeds();
269
270// Run on resize.
271window.onresize = recipeCardResponsiveEmbeds;

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.