PageSourceSearch

https://villago.it/wp-content/plugins/trx_addons/components/cpt/la…/shortcodes/cart/cart.js?reload=1767750201

js villago.it collected 2026-09-25 08:04:49 UTC 11,304 bytes, 292 lines download raw bytes

1/* global jQuery, TRX_ADDONS_STORAGE */
2
3jQuery(document).on('action.ready_trx_addons', function() {
4
5	"use strict";
6
7	trx_addons_sc_layouts_cart_init_js();
8} );
9
10jQuery(window).on( "elementor/frontend/init", function () {
11	elementorFrontend.hooks.addAction( "frontend/element_ready/trx_sc_layouts_cart.default", trx_addons_sc_layouts_cart_init_js );
12} );
13
14function trx_addons_sc_layouts_cart_init_js ( $scope = false ) {
15	var $document = jQuery( document ),
16		$body = jQuery( 'body' ),
17		is_trx_addons_customizable = $body.find( '.sc_layouts_cart.trx_addons_customizable' ).length > 0,
18		is_edit_mode = is_trx_addons_customizable && $scope && elementorFrontend.isEditMode();
19
20	if ( ! $body.hasClass( 'added_to_cart_inited' ) || is_edit_mode ) {
21
22		$body.addClass( 'added_to_cart_inited' );
23
24		var $sc_cart = jQuery( '.sc_layouts_cart' ),
25			$cart_button = jQuery( '.sc_layouts_cart_button_wrap' );
26
27		if ( $sc_cart.length > 0 ) {
28
29			// Show/Hide cart
30			$sc_cart.filter(':not(.inited)').each( function(idx) {
31				var cart = jQuery(this);
32				// Show/Hide cart widget as dropdown
33				cart.addClass('inited')
34					.on('click', '.sc_layouts_cart_icon,.sc_layouts_cart_details', function(e) {
35						var link = jQuery( this );
36						if ( ! link.data( 'panel-id' ) ) {
37							var widget = link.siblings('.sc_layouts_cart_widget').eq(0),
38								row    = link.parents('.sc_layouts_row').eq(0),
39								cart   = link.parents('.sc_layouts_cart').eq(0);
40							if ( widget.length > 0 && widget.text().replace(/\s*/g, '') !== '' ) {
41								cart.toggleClass( 'sc_layouts_cart_opened' );
42								row.toggleClass( 'sc_layouts_row_on_top' );
43								widget.fadeToggle();
44								$document.trigger( 'action.opened_dropdown_elements', [$sc_cart] );
45							}
46							//e.preventDefault();
47							//return false;
48						}
49					})
50					.on('click', '.sc_layouts_cart_widget_close', function(e) {
51						var link = jQuery( this ),
52							row  = link.parents('.sc_layouts_row').eq(0),
53							cart = link.parents('.sc_layouts_cart').eq(0);
54						row.removeClass( 'sc_layouts_row_on_top' );
55						cart.removeClass( 'sc_layouts_cart_opened' );
56						link.parent().fadeOut();
57						//e.preventDefault();
58						//return false;
59					} );
60			} );
61
62			// Show cart widget as a panel
63			$document.on( 'action.prepare_popup_elements', function( e, panel ) {
64				if ( panel.hasClass( 'sc_layouts_cart_panel') ) {
65					$sc_cart.find( '[data-panel-id="' + panel.attr('id') + '"]' ).each( function() {
66						var $cart = jQuery( this ).parents( '.sc_layouts_cart' );
67						if ( $cart.is( ':visible' ) ) {
68							$cart.toggleClass( 'sc_layouts_cart_opened', true );
69						}
70					} );
71
72					trx_addons_sc_layouts_cart_panel_close_icon_replace( panel );
73				}
74			} );
75
76			// Hide cart widget as a panel
77			$document.on( 'action.close_popup_elements', function( e, panel ) {
78				if ( panel.hasClass( 'sc_layouts_cart_panel' ) ) {
79					$sc_cart.find( '[data-panel-id="' + panel.attr('id') + '"]' ).each( function() {
80						var $cart = jQuery( this ).parents( '.sc_layouts_cart' );
81						if ( $cart.is( ':visible' ) ) {
82							$cart.removeClass( 'sc_layouts_cart_opened' );
83						}
84					} );
85				}
86			} );
87
88			// Hide cart widget as button
89			if ( trx_addons_apply_filters( 'trx_addons_filter_sc_layouts_cart_button_hide_on_scroll', true ) ) {
90				$document.on( 'action.scroll_trx_addons', function() {
91					$cart_button.each( function() {
92						var $self = jQuery( this );
93						if ( $self.hasClass( 'sc_layouts_cart_button_showed' ) && ! is_edit_mode ) {
94							$self.removeClass( 'sc_layouts_cart_button_showed' );
95						}
96					} );
97				} );
98			}
99
100			// WooCommerce Cart: Update amount on the cart button
101			jQuery( document.body ).on( 'wc_fragments_refreshed wc_fragments_loaded update_cart added_to_cart removed_from_cart', function(e) {
102
103				jQuery( '.widget_shopping_cart' ).each( function() {
104					var $widget = jQuery( this );
105
106					// Update amount value on the cart button
107					var total = 0;
108					var $total = $widget.find( '.total .amount' );
109					if ( ! $total.length ) {
110						$total = $widget.find( '.elementor-menu-cart__subtotal .amount' );
111					}
112					if ( $total.length ) {
113						total = $total.text();
114					}
115					$sc_cart.find( '.sc_layouts_cart_summa' ).text( total );
116
117					// Update count items on the cart button
118					var cnt = 0, cart_list = false;
119					$widget.find( '.cart_list li' ).each( function() {
120						var q = jQuery( this ).find( '.quantity' ).html().split( ' ', 2 );
121						if ( ! isNaN( q[0] ) ) {
122							cnt += Number( q[0] );
123						}
124						cart_list = true;
125					} );
126					if ( ! cart_list ) {
127						$widget.find( '.elementor-menu-cart__product' ).each( function() {
128							var q = jQuery( this ).find( '.product-quantity' ).text().split( ' ' );
129							if ( ! isNaN( q[0] ) ) {
130								cnt += Number( q[0] );
131							}
132						} );
133					}
134					var $items = $sc_cart.find( '.sc_layouts_cart_items' ).eq(0),
135						items = $items.text().split( ' ', 2 );
136					items[0] = cnt;
137					$items.text( items[0] + ( items.length > 1 ? ' ' + ( cnt == 1 ? $items.data( 'item' ) : $items.data( 'items' ) ) : '' ) );
138					jQuery( '.sc_layouts_cart_items_short' ).text( items[0] );
139					// Update data-attr on button
140					$sc_cart.data( {
141						'items': cnt ? cnt : 0,
142						'summa': total ? total : 0
143					} );
144					// Open cart panel
145					if ( e.type == 'added_to_cart' ) {
146						sc_layouts_cart_panel_open( $sc_cart );
147					}
148
149					trx_addons_sc_layouts_cart_item_close_icon_replace( $widget );
150				} );
151
152			} );
153
154			// EDD Cart: Update amount on the cart button
155			jQuery( document.body ).on( 'edd_cart_item_added edd_cart_item_removed edd_quantity_updated', function ( e, data ) {
156				var items = $sc_cart.find( '.sc_layouts_cart_items' ).eq(0).text().split( ' ', 2 );
157				items[0] = data.cart_quantity ? data.cart_quantity : data.quantity;
158				jQuery( '.sc_layouts_cart_items' ).text( items[0] + ( items.length > 1 ? ' ' + items[1] : '' ) );
159				jQuery( '.sc_layouts_cart_items_short' ).text( items[0] );
160				jQuery( '.sc_layouts_cart_summa' ).text( data.total );
161				// Update data-attr on button
162				$sc_cart.data( {
163					'items': data.cart_quantity ? data.cart_quantity : 0,
164					'summa': data.total ? data.total : 0
165				} );
166				// Open cart panel
167				sc_layouts_cart_panel_open( $sc_cart );
168			} );
169
170		}
171	}
172
173	// Open a panel with cart widget or display an icon with counter after elements are added to the cart
174	function sc_layouts_cart_panel_open( $sc_cart ) {
175		if ( ! $sc_cart.hasClass( 'sc_layouts_cart_opened' ) ) {
176			var link = $sc_cart.filter( ':visible' ).find( '.sc_layouts_cart_icon,.sc_layouts_cart_details' ).eq(0);
177			if ( link.length ) {
178				// Show panel
179				if ( link.data( 'panel-id' ) ) {
180					link.trigger( 'click' );
181
182				// Show button after hidden elements are inited (to skip scroll event inside init_hidden_elements)
183				} else if ( link.data( 'button-id' ) ) {
184					setTimeout( function() {
185						jQuery( '#' + link.data( 'button-id' ) ).toggleClass( 'sc_layouts_cart_button_showed' );
186					}, 10 );
187				}
188			}
189		}
190	}
191
192	function trx_addons_sc_layouts_cart_panel_close_icon_replace ( panel = false ) {
193		if ( ! is_trx_addons_customizable || ! panel ) {
194			return false;
195		}
196
197		if ( panel.prev( '.sc_layouts_panel_hide_content.trx_addons_customizable' ).length <= 0 && panel.hasClass( 'trx_addons_customizable' ) ) {
198			panel.prev( '.sc_layouts_panel_hide_content' ).addClass( 'trx_addons_customizable' );
199		}
200
201		if ( panel.prev( '.sc_layouts_panel_hide_content[class*="sc_layouts_cart_panel_style_"]' ).length <= 0 ) {
202			var panel_class_list = panel.attr('class').split(/\s+/);
203			for ( var i = 0; i < panel_class_list.length; i++ ) {
204				if ( panel_class_list[i].indexOf( "sc_layouts_cart_panel_style_" ) !== -1 ) {
205					panel.prev( '.sc_layouts_panel_hide_content' ).addClass( panel_class_list[i] + '-panel_overlay' );
206					break;
207				}
208			}
209		}
210
211		if ( panel.length > 0 && panel.attr( 'id' ) && panel.find( '.sc_layouts_panel_close.replaced-icon' ).length <= 0 ) {
212
213			var $cart_widget_wrapper = jQuery( '.sc_layouts_item_icon[data-panel-id="' + panel.attr( 'id' ) + '"]' );
214			if ( $cart_widget_wrapper.length > 0 && $cart_widget_wrapper.closest( '.sc_layouts_cart' ).length > 0 ) {
215
216				var $cart_item_close_icon = $cart_widget_wrapper.closest( '.sc_layouts_cart' );
217				if ( $cart_item_close_icon.length > 0 && $cart_item_close_icon.data( 'panel-close-icon' ) ) {
218					panel.find( '.sc_layouts_panel_close' ).html( $cart_item_close_icon.data( 'panel-close-icon' ) );
219				}
220			}
221			panel.find( '.sc_layouts_panel_close' ).addClass( 'replaced-icon' );
222		}
223	}
224
225	function trx_addons_sc_layouts_cart_item_close_icon_replace ( $widget = false ) {
226		if ( ! is_trx_addons_customizable || ! $widget ) {
227			return false;
228		}
229
230		//Change close button icon 'default'
231		var $try_cart_item_close_icon = $widget.closest( '[data-cart-item-close-icon]' );
232
233		if ( $try_cart_item_close_icon.length <= 0 ) {
234			$try_cart_item_close_icon = $widget.find( '[data-cart-item-close-icon]' );
235		}
236
237		if ( $try_cart_item_close_icon.length > 0 && $try_cart_item_close_icon.data( 'cart-item-close-icon' ) ) {
238			var $try_cart_item_close_icon_html = jQuery( $try_cart_item_close_icon.data( 'cart-item-close-icon' ) );
239			$widget.find( 'a.remove' ).html( $try_cart_item_close_icon_html.removeAttr( 'id' ) );
240		} else {
241
242			//Change close button icon 'panel'
243			var $layouts_panel = $widget.closest( '.sc_layouts_panel' );
244			if ( $layouts_panel.length > 0 && $layouts_panel.attr( 'id' ) ) {
245
246				var $cart_widget_wrapper = jQuery( '.sc_layouts_item_icon[data-panel-id="' + $layouts_panel.attr( 'id' ) + '"]' );
247				if ( $cart_widget_wrapper.length > 0 && $cart_widget_wrapper.closest( '.sc_layouts_cart' ).length > 0 ) {
248
249					var $cart_item_close_icon = $cart_widget_wrapper.closest( '.sc_layouts_cart' );
250					if ( $cart_item_close_icon.length > 0 && $cart_item_close_icon.data( 'cart-item-close-icon' ) ) {
251						var $cart_item_close_icon_html = jQuery( $cart_item_close_icon.data( 'cart-item-close-icon' ) );
252						$widget.find( 'a.remove' ).html( $cart_item_close_icon_html.removeAttr( 'id' ) );
253					}
254				}
255			}
256		}
257	}
258
259	function trx_addons_sc_layouts_cart_preview_panel_z_index ( $scope = false ) {
260		if ( ! $scope ) {
261			return false;
262		}
263
264		var $closest_parent = $scope.closest( '.elementor-section-wrap > .elementor-element' );
265
266		if ( $closest_parent.find( '.sc_layouts_cart_preview_init' ).length > 0 ) {
267			$closest_parent.addClass( 'trx_addons_customizable trx_addons_sc_layouts_cart_general_parent' );
268		} else {
269			$closest_parent.removeClass( 'trx_addons_customizable trx_addons_sc_layouts_cart_general_parent' );
270		}
271	}
272
273	if ( is_edit_mode ) {
274
275		trx_addons_sc_layouts_cart_preview_panel_z_index( $scope );
276
277		trx_addons_sc_layouts_cart_item_close_icon_replace( $scope );
278
279		var editPanelID = $scope.find( '[data-panel-id]' ).eq(0);
280		if ( editPanelID.length > 0 && editPanelID.data( 'panel-id' ) ) {
281
282			var editPanel = jQuery( '#' + editPanelID.data( 'panel-id' ) );
283			if ( editPanel.length > 0 ) {
284				trx_addons_sc_layouts_cart_panel_close_icon_replace( editPanel );
285
286				if ( editPanel.prev( '.sc_layouts_panel_hide_content.sc_layouts_cart_preview_init' ).length <= 0 ) {
287					editPanel.prev( '.sc_layouts_panel_hide_content' ).addClass( 'sc_layouts_cart_preview_init' )
288				}
289			}
290		}
291	}
292};

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.