PageSourceSearch

https://www.antoninascolaro.it/wp-content/themes/melanie-hanson/plugins/woocommerce/woocommerce.js

js antoninascolaro.it collected 2026-09-26 03:45:55 UTC 16,685 bytes, 435 lines download raw bytes

1/* global jQuery, MELANIE_HANSON_STORAGE */
2
3jQuery( document ).on( 'action.ready_melanie_hanson', function() {
4
5	"use strict";
6
7	var $window   = jQuery( window ),
8		$document = jQuery( document ),
9		$body     = jQuery( 'body' );
10
11	var $list_products_infinite,
12		$list_products_infinite_link,
13		$list_products,
14		_list_products_height;
15
16	// Update links after the new post added
17	$document.on( 'action.new_post_added', update_jquery_links );
18	$document.on( 'action.got_ajax_response', update_jquery_links );
19	$document.on( 'action.init_hidden_elements', update_jquery_links );
20	var first_run = true;
21	function update_jquery_links(e) {
22		if ( first_run && e && e.namespace == 'init_hidden_elements' ) {
23			first_run = false;
24			return; 
25		}
26		$list_products_infinite = jQuery( '.woocommerce-links-infinite' );
27		$list_products_infinite_link = $list_products_infinite.find( '>a' );
28		$list_products = jQuery( '.list_products > .products' ).eq( 0 );
29		_list_products_height = $list_products.length > 0 ? $list_products.height() : 0;
30	}
31	update_jquery_links();
32
33	$document.on( 'action.resize_melanie_hanson', function() {
34		_list_products_height = $list_products.length > 0 ? $list_products.height() : 0;
35	} );
36
37
38	// Change display mode
39	//--------------------------------
40	jQuery( '.woocommerce,.woocommerce-page' ).on( 'click', '.melanie_hanson_shop_mode_buttons a', function(e) {
41		var $self = jQuery(this),
42			mode  = $self.hasClass( 'woocommerce_thumbs' ) ? 'thumbs' : 'list';
43		melanie_hanson_set_cookie( 'melanie_hanson_shop_mode', mode, 365 * 24 * 60 * 60 * 1000 );   // 1 year
44		$self.siblings( 'input' ).val( mode ).parents( 'form' ).get( 0 ).submit();
45		e.preventDefault();
46		return false;
47	} );
48
49
50	// Add buttons to quantity
51	//--------------------------------
52	var woocomerce_inc_dec = '<span class="q_inc"></span><span class="q_dec"></span>';
53
54	// On first run
55	melanie_hanson_woocommerce_add_inc_dec();
56
57	// After the cart is updated
58	jQuery( document.body ).on( 'updated_wc_div woosq_loaded', function() {
59		melanie_hanson_woocommerce_add_inc_dec();
60	} );
61
62	// After products loaded by AJAX - timeout need to wait for fadeOut on old posts
63	$document.on( 'action.new_post_added action.got_ajax_response qv_loader_stop trx_qv_loaded', function() {
64		setTimeout( function() {
65			melanie_hanson_woocommerce_add_inc_dec();
66		}, 500 );
67	} );
68
69	// After variations are changed
70	$document.on( 'action.init_hidden_elements', function( e, container ) {
71		melanie_hanson_woocommerce_add_inc_dec();
72		container.find( '.variations_form.cart:not(.quantity_inited)' )
73			.addClass( 'quantity_inited' )
74			.on( 'wc_variation_form check_variations', function() {
75				setTimeout( function() {
76					melanie_hanson_woocommerce_add_inc_dec();
77				}, 100 );
78			} );
79	} );
80
81
82	// Add buttons inc/dec
83	function melanie_hanson_woocommerce_add_inc_dec() {
84		jQuery( '.woocommerce div.quantity:not(.inited),.woocommerce-page div.quantity:not(.inited),.variations_form.cart div.quantity:not(.inited)' ).each( function() {
85			var $self = jQuery(this).addClass('inited');
86			// If quantity is not hidden - add Inc/Dec buttons. If quantity is hidden - a total number of product is 1 and buttons are not needed.
87			if ( $self.find('>input[name="quantity"][type="hidden"]').length === 0 ) {
88				if ( $self.find('>.q_inc').length === 0 ) {
89					$self.append( woocomerce_inc_dec );
90				}
91				$self
92					.on( 'click', '>span', function(e) {
93						melanie_hanson_woocomerce_inc_dec_click( jQuery( this ) );
94						e.preventDefault();
95						return false;
96					} );
97			} else {
98				$self.addClass( 'hidden last_item_in_stock' );
99			}
100		} );
101	}
102
103	// Inc/Dec quantity on buttons inc/dec
104	function melanie_hanson_woocomerce_inc_dec_click(button) {
105		var f = button.siblings( 'input' );
106		if (button.hasClass( 'q_inc' )) {
107			f.val( ( f.val() === '' ? 0 : parseInt( f.val(), 10 ) ) + 1 ).trigger( 'change' );
108		} else {
109			f.val( Math.max( 0, ( f.val() === '' ? 0 : parseInt( f.val(), 10 ) ) - 1 ) ).trigger( 'change' );
110		}
111	}
112
113
114	// Decorate YITH Compare & Add to wishlist
115	//----------------------------------------------
116
117	// On the single product page
118	//----------------------------
119	
120	// Move 'Compare' before 'Wishlist' and convert 'Wishlist' to the button (if 'Compare' is a button)
121	var wishlist = jQuery( '.woocommerce .product .summary .yith-wcwl-add-to-wis
121hlist' ).eq( 0 ),
122		compare  = jQuery( '.woocommerce .product .summary .compare' ).eq( 0 );
123	if ( wishlist.length > 0 && compare.length > 0 ) {
124		compare.insertBefore( wishlist );
125		if ( compare.hasClass( 'button' ) ) {
126			// Add class 'button' to the link (if the link 'Compare' have same class)
127			wishlist.find( '.add_to_wishlist' ).addClass( 'button' );
128			// Restore class 'button' after any AJAX request
129			$document.on( 'ajaxComplete', function(e) {
130				setTimeout( function() {
131					jQuery( '.woocommerce .product .summary .yith-wcwl-add-to-wishlist .add_to_wishlist' ).eq(0).toggleClass( 'button', true );
132				}, 10 );
133			} );
134		}
135	}
136
137	// Remove class 'button' from links 'Compare' and 'Add to Wishlist' in the 'Related products' on the single product page
138	jQuery( '.single-product ul.products li.product .post_data .yith_buttons_wrap a' ).removeClass( 'button' );
139
140	// Remove class 'button' from links 'Quick view' on the product archive page
141	jQuery( 'ul.products li.product .post_data .yith-wcqv-button' ).removeClass( 'button' );
142	$document.on( 'action.new_post_added action.got_ajax_response', function() {
143		jQuery( 'ul.products li.product .post_data .yith-wcqv-button' ).removeClass( 'button' );
144	} );
145
146	// On the products list (if 'Add to wishlist' placed before image)
147	//----------------------------------------------------------------
148	$document.on( 'action.init_hidden_elements', function( e, container ) {
149
150		jQuery( 'ul.products li.product:not(.wishlist_decorated)' ).each( function() {
151
152			var $product = jQuery(this).addClass( 'wishlist_decorated' ),
153				$yith_buttons_wrap = $product.find('.yith_buttons_wrap' ).eq( 0 );
154
155			if ( $yith_buttons_wrap.length > 0 ) {
156				// Move 'Wishlist' and 'Quick View' to the '.yith_buttons_wrap' after the 'Compare'
157				$product.find( '.yith-wcwl-add-to-wishlist,.yith-wcqv-button,.woosq-btn,.compare' ).each( function() {
158					var $self = jQuery( this ).removeClass( 'button' );
159					if ( ! $self.parent().hasClass( 'yith_buttons_wrap' ) ) {
160						$yith_buttons_wrap.append( $self );
161					}
162				} );
163
164				if ( $product.hasClass( 'add-to-wishlist-before_image' ) ) {
165
166					// Wrap inner text in the links 'Compare' and 'Add to Wishlist' to the span
167					$yith_buttons_wrap.find( 'a' ).wrapInner( '<span class="tooltip"></span>' );
168
169					// Wrap inner text in the link 'Compare' after click
170					$yith_buttons_wrap.find( '.compare' ).on( 'click', function(e) {
171						var bt = jQuery(this), atts = 10;
172						setTimeout( trx_addons_add_tooltip_to_compare, 500 );
173						function trx_addons_add_tooltip_to_compare() {
174							if ( bt.hasClass('added') && bt.find('.tooltip').length === 0 ) {
175								bt.wrapInner( '<span class="tooltip"></span>' );
176							} else if (atts-- > 0) {
177								setTimeout( trx_addons_add_tooltip_to_compare, 500 );
178							}
179						}
180					} );
181
182					// Wrap inner text in the link 'Add to Wishlist' after click
183					$yith_buttons_wrap.find( '.add_to_wishlist' ).on( 'click', function(e) {
184						var atts = 30;
185						setTimeout( trx_addons_add_tooltip_to_wishlist, 250 );
186						function trx_addons_add_tooltip_to_wishlist() {
187							var bt = $yith_buttons_wrap.find('.yith-wcwl-add-to-wishlist a');
188							if ( bt.find('.tooltip').length === 0 ) {
189								bt.wrapInner( '<span class="tooltip"></span>' );
190							} else if ( atts-- > 0 ) {
191								setTimeout( trx_addons_add_tooltip_to_wishlist, 250 );
192							}
193						}
194					} );
195
196					// Change spinner image in the 'Add to Wishlist'
197					var img = $yith_buttons_wrap.find( '.yith-wcwl-add-button > img' );
198					if ( img.length > 0 ) {
199						img.each( function() {
200							var $self = jQuery(this),
201								src   = $self.attr('src');
202							if ( src != undefined && src.indexOf('wpspin_light') > 0 ) {
203								$self.attr( 'src', src.replace('wpspin_light', 'ajax-loader') );
204							}
205						} );
206					}
207				}
208			}
209
210		} );
211
212		// 'Load more' and 'Infinite scroll' on the products page
213		jQuery( '.woocommerce-load-more:not(.woocommerce-load-more-inited)' )
214			.addClass( 'woocommerce-load-more-inited' )
215			.on( 'click', function(e) {
216
217				e.preventDefault();
218
219				var more = jQuery( this );
220				if ( more.data( 'load_more_link_busy' ) ) {
221					return false;
222				}
223
224				var page     = Number( more.data( 'page' ) ),
225					max_page = Number( more.data( 'max-page' ) );
226				if (page >= max_page) {
227					more.parent().addClass( 'all_items_loaded' ).hide();
228					return false;
229				}
230
231				more.data( 'load_more_link_busy', true )
232					.parent().addClass( 'loading' );
233
234				var link     = more.parent().next( '.woocommerce-pagination' ).find( '.next' ).attr( 'href' ).replace( /\/page\/[0-9]+/, '/page/' + ( page + 1 ) );
235				var products = more.parent().prev( '.products' );
236
237				jQuery.get(	link ).done(
238					function(response) {
239						// Get inline styles and add to the page styles
240						melanie_hanson_import_inline_styles( response );
241						// Get tags 'link' from response and add its to the 'head'
242						melanie_hanson_import_tags_link( response );
243						// Get new posts and append to the .products
244						var posts_container = jQuery( response ).find('.list_products > .products');
245						if ( posts_container.length === 0 ) {
246							posts_container = jQuery( response ).find('ul.products');
247						}
248						if ( posts_container.length > 0 ) {
249							products.append( posts_container.find( '> li' ) );
250							more.data( 'page', page + 1 ).parent().removeClass( 'loading' );
251							// Trigger actions to init new elements
252							MELANIE_HANSON_STORAGE['init_all_mediaelements'] = true;
253							$document
254								.trigger( 'action.new_post_added', [products] )
255								.trigger( 'action.init_hidden_elements', [products] );
256						}
257						if (page + 1 >= max_page) {
258							more.parent().addClass( 'all_items_loaded' ).hide();
259						}
260						// Update a products counter above the products list.
261						// Counter in the format 'Showing 1–12 of 20 results'. Attention! Symbol '–' is not a simple dash!
262						// Need to update the second number (12) after loading new products.
263						var counter = $body.find( '.woocommerce-result-count' );
264						if ( counter.length > 0 ) {
265							var total = products.find( '> li.product:not(.product-category)' ).length;
266							counter.html( counter.html().replace( /–([0-9]+)/, '–' + total ) );
267						}
268						more.data( 'load_more_link_busy', false );
269						// Fire 'window.scroll' after clearing busy state
270						$window.trigger( 'scroll' );
271
272						$document.trigger( 'action.got_ajax_response', {
273							action: 'woocommerce_ajax_get_posts',
274							result: response,
275							products: products
276						});
277					}
278				);
279
280				return false;
281
282			} );
283
284	} );
285
286	// Infinite scroll on the products page
287	$document.on( 'action.scroll_melanie_hanson', function(e) {
288		if ( $list_products_infinite.length === 0 || $list_products_infinite_link.length === 0 || $list_products_infinite_link.data( 'load_more_link_busy' ) ) {
289			return;
290		}
291		if ( $list_products.length > 0 && $list_products.offset().top + _list_products_height < melanie_hanson_window_scroll_top() + melanie_hanson_window_height() * 1.5 ) {
292			$list_products_infinite_link.trigger( 'click' );
293		}
294	} );
295
296
297	// Wrap new select (created dynamically) with .select_container
298	//-------------------------------------------------------------------------
299	if ( ! MELANIE_HANSON_STORAGE['select_container_disabled'] ) {
300		jQuery( 'select#calc_shipping_country:not(.inited)' )
301			.addClass( 'inited' )
302			.on( 'change', function() {
303				setTimeout(
304					function() {
305						var state = jQuery( 'select#calc_shipping_state' );
306						if (state.length == 1 && ! state.parent().hasClass( 'select_container' )) {
307							state.wrap( '<div class="select_container"></div>' );
308						}
309					}, 10
310				);
311			} );
312		jQuery( document.body ).on( 'wc_fragments_refreshed wc_fragments_loaded updated_shipping_method update_checkout', function() {
313			jQuery( 'div.cart_totals select' ).each( function() {
314				var $self = jQuery( this );
315				if ( ! $self.parent().hasClass( 'select_container' )) {
316					$self.wrap( '<div class="select_container"></div>' );
317				}
318			} );
319		} );
320	}
321
322
323	// Add hover classes to the buttons created dynamically
324	//-------------------------------------------------------------------------
325	jQuery( document.body ).on( 'wc_fragments_refreshed wc_fragments_loaded update_checkout update_cart added_to_cart removed_from_cart', function() {
326		$document.trigger( 'action.init_hidden_elements', [ $body ] );
327	} );
328
329
330	// Update cart
331	//-------------------------------------------------------------------------
332	var table_cart = jQuery( 'table.cart' );
333
334	jQuery( document.body ).on( 'updated_wc_div', function() {
335
336		melanie_hanson_create_observer( 'update_woocommerce_cart', table_cart.parents('form').eq(0), function( mutationsList ) {
337			for ( var mutation of mutationsList ) {
338				if ( mutation.type == 'childList' || mutation.type == 'subtree' ) {
339					melanie_hanson_remove_observer( 'update_woocommerce_cart' );
340					table_cart = jQuery( 'table.cart' );
341					melanie_hanson_woocommerce_update_cart( 'update' );
342					break;
343				}
344			}
345		} );
346
347
348		if ( table_cart.length > 0 ) {
349			melanie_hanson_woocommerce_update_cart( 'update' );
350		}
351	} );
352
353	// Generate 'scroll' event after the cart is filled
354	jQuery( document.body ).on( 'wc_fragment_refresh', function() {
355		$window.trigger( 'scroll' );
356	} );
357
358	// Check device and update cart if need
359	if ( table_cart.length > 0 ) {
360		melanie_hanson_woocommerce_update_cart( 'init' );
361	}
362
363	// Resize action
364	$window.on( 'resize', function() {
365		if ( table_cart.length > 0 ) {
366			melanie_hanson_woocommerce_update_cart( 'resize' );
367		}
368	} );
369
370	// Update cart display
371	function melanie_hanson_woocommerce_update_cart(status){
372		setTimeout(
373			function() {
374				var w = window.innerWidth;
375				if (w == undefined) {
376					w = melanie_hanson_window_width() + ( melanie_hanson_window_height() < $document.height() || melanie_hanson_window_scroll_top() > 0 ? 16 : 0 );
377				}
378
379				var tbl = jQuery( 'table.cart' );   // table_cart;
380
381				if ( w < MELANIE_HANSON_STORAGE['mobile_layout_width'] ) {
382					var $mobile_cell = tbl.find( '.mobile_cell' );
383					if (status == 'resize' && $mobile_cell.length > 0) {
384						return;
385					} else {
386						if ( tbl.length > 0 ) {
387							if ( $mobile_cell.length === 0 ) {
388								tbl.find( 'thead tr .product-quantity, thead tr .product-subtotal, thead tr .product-thumbnail' ).hide();
389								if ( tbl.hasClass( 'wishlist_table' ) ) {
390									tbl.find( 'thead tr .product-remove, thead tr .product-stock-status' ).hide();
391									tbl.find( 'tfoot tr td' ).each( function() {
392										var $self = jQuery( this );
393										$self.data( 'colspan', $self.attr( 'colspan' ) ).attr( 'colspan', 3 );
394									} );
395								}
396							}
397							tbl.find( '.cart_item,[id*="yith-wcwl-row-"]' ).each( function() {
398								var $self = jQuery( this );
399								if ( $self.find( '>.mobile_cell' ).length == 0 ) {
400									$self.prepend( '<td class="mobile_cell" colspan="3"><table width="100%"><tr class="first_row"></tr><tr class="second_row"></tr></table></td>' );
401									$self.find( '.first_row' ).append( $self.find( '.product-thumbnail, .product-name, .product-price' ) );
402									$self.find( '.second_row' ).append( $self.find( '.product-remove, .product-quantity, .product-subtotal, .product-stock-status, .product-add-to-cart' ) );
403								}
404							} );
405							if ( ! tbl.hasClass( 'inited' ) ) {
406								tbl.addClass( 'inited' );
407							}
408						}
409					}
410				}
411
412				if ( w >= MELANIE_HANSON_STORAGE['mobile_layout_width'] && status == 'resize' && jQuery( 'table.cart .mobile_cell' ).length > 0) {
413					if ( tbl.length > 0 ) {
414						tbl.find( 'thead tr .product-quantity, thead tr .product-subtotal, thead tr .product-thumbnail' ).show();
415						if ( tbl.hasClass( 'wishlist_table' ) ) {
416							tbl.find( 'thead tr .product-remove, thead tr .product-stock-status' ).show();
417							tbl.find( 'tfoot tr td' ).each( function() {
418								var $self = jQuery( this );
419								$self.attr( 'colspan', $self.data( 'colspan' ) );
420							} );
421						}
422						tbl.find( '.cart_item,[id*="yith-wcwl-row-"]' ).each( function(){
423							var $self = jQuery( this );
424							$self.find( '.first_row td, .second_row td' ).prependTo( $self );
425							$self.find( '.product-remove' ).prependTo( $self );
426							$self.find( 'td.mobile_cell' ).remove();
427						} );
428					}
429				}
430
431			}, 10
432		);
433	}
434
435} );

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.