PageSourceSearch

https://www.hilfe-schenken.ch/_assets/609e8a4e0e0484232ba9209ef957…/Aimeos/Themes/default/catalog-lists.js?v=1

js hilfe-schenken.ch collected 2026-10-07 04:10:30 UTC 4,295 bytes, 185 lines download raw bytes

1/**
2 * Catalog list actions
3 */
4AimeosCatalogLists = {
5
6	/**
7	 * Shows the basket after submitting the form
8	 *
9	 * @param DomNode form Form DOM element
10	 */
11	async showBasket(form) {
12
13		await fetch(form.getAttribute("action"), {
14			body: new FormData(form),
15			method: 'POST'
16		}).then(response => {
17			return response.text();
18		}).then(data => {
19			Aimeos.createContainer(AimeosBasket.updateBasket(data));
20		});
21	},
22
23
24	/**
25	 * Marks products as pinned
26	 */
27	setPinned() {
28
29		$('.catalog-list-items').each((idx, el) => {
30			$('.product .btn-pin', el).removeClass('active');
31
32			for(id in $(el).data('pinned')) {
33				$('.product[data-prodid="' + id + '"] .btn-pin', el).addClass('active');
34			}
35		});
36	},
37
38
39	/**
40	 * Add to basket
41	 */
42	onAddBasket() {
43
44		//$(document).on("click", ".catalog-list-items .product .btn-action", ev => {
45		//
46		//	console.log("onAddBasket: CLICK");
47		//
48		//	const target = $(ev.currentTarget).closest(".product");
49		//	ev.preventDefault();
50		//
51		//	//Aimeos.createOverlay();
52		//
53		//	if($(".catalog-list-items:not(.list) .basket .items-selection .selection li, .catalog-list-items:not(.list) .basket .items-attribute .selection li", target).length) {
54		//		const node = target.clone();
55		//
56		//		console.log("FOUND ELEMENT");
57		//
58		//		$("[id]", node).each((idx, el) => {
59		//			el.setAttribute("id", el.getAttribute("id") + '-2');
60		//		});
61		//
62		//		$("[for]", node).each((idx, el) => {
63		//			el.setAttribute("for", el.getAttribute("for") + '-2');
64		//		});
65		//
66		//		node.on("click", ".btn-action", (ev) => {
67		//			if(AimeosCatalog.checkVariants(ev.currentTarget)) {
68		//				this.showBasket($(ev.currentTarget).closest("form.basket")[0]);
69		//			}
70		//			ev.stopPropagation();
71		//			ev.preventDefault();
72		//		});
73		//
74		//		Aimeos.createContainer($('<div class="catalog-list catalog-list-items list">').append(node));
75		//		return;
76		//	}
77		//
78		//	console.log($("form.basket", target)[0]);
79		//
80		//	this.showBasket($("form.basket", target)[0]);
81		//});
82
83	},
84
85
86	/**
87	 * Enables infinite scroll if available
88	 */
89	async onScroll() {
90
91		if($('.catalog-list-items').data('infiniteurl')) {
92			const scroll = async function() {
93
94				const list = $('.catalog-list-items');
95				const infiniteUrl = list.data('infiniteurl');
96
97				if(infiniteUrl && list.length && list[0].getBoundingClientRect().bottom < window.innerHeight * 3) {
98					list.data('infiniteurl', '');
99
100					await fetch(infiniteUrl).then(response => {
101						return response.text();
102					}).then(data => {
103						const nonce = $('script.items-stock', document)?.attr('nonce');
104						const nextPage = $('<html/>').html(data);
105						const newList = $('.catalog-list-items', nextPage);
106						const ids = newList.data('pinned') || {};
107
108						$('.product', newList).each((idx, node) => {
109							ids[node.dataset.prodid] ? $('.btn-pin', node).addClass('active') : null;
110							list.append(node);
111						});
112
113						$('script.items-stock', nextPage).each((idx, node) => {
114							node.setAttribute('nonce', nonce);
115							$(document.head).append(node);
116						});
117
118						list.data('infiniteurl', newList.data('infiniteurl'));
119						$(window).trigger('scroll');
120						Aimeos.loadImages();
121					});
122				}
123			};
124
125			$(window).on('scroll', scroll);
126			scroll();
127		}
128	},
129
130
131	/**
132	 * Add products to pinned list
133	 */
134	onPin() {
135
136		$("body").on("click", ".catalog-list-items .product .btn-pin", async ev => {
137
138			const el = $(ev.currentTarget);
139			const url = el.hasClass('active') ? el.data('rmurl') : el.attr('href');
140
141			if(url) {
142				const form = new FormData();
143				const csrf = el.closest('form').find('.csrf-token');
144
145				form.append(csrf.attr('name'), csrf.attr('value'));
146				el.toggleClass('active');
147
148				await fetch(url, {
149					method: 'POST',
150					body: form
151				}).then(response => {
152					return response.text();
153				}).then(data => {
154					const doc = $('<html/>').html(data);
155					const pinned = $(".catalog-session-pinned", doc);
156
157					if(pinned.length) {
158						$('.catalog-session-pinned').replaceWith(pinned);
159					}
160				});
161
162				return false;
163			}
164		});
165	},
166
167
168	/**
169	 * Initializes the catalog list actions
170	 */
171	init() {
172		if(this.once) return;
173		this.once = true;
174
175		this.setPinned();
176		this.onAddBasket();
177		this.onScroll();
178		this.onPin();
179	}
180};
181
182
183$(function() {
184	AimeosCatalogLists.init();
185});

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.