PageSourceSearch

https://agora.ctxt.es/wp-content/plugins/yith-woocommerce-subscrip…/assets/js/ywsbs-frontend.js?ver=4.19.1

js ctxt.es collected 2026-10-01 10:20:54 UTC 3,290 bytes, 139 lines download raw bytes

1/**
2 * ywsbs-frontend.js
3 *
4 * @author YITH <[email protected]>
5 * @package YITH WooCommerce Subscription
6 * @version 1.0.0
7 */
8
9/* global yith_ywsbs_frontend */
10jQuery(function ($) {
11	'use strict';
12
13	var $body = $('body');
14	var blockParams = {
15		message: null,
16		overlayCSS: {background: '#fff', opacity: 0.7},
17		ignoreIfBlocked: true
18	};
19
20	// Change Add to cart Label on variable product when a variation is selected.
21	$.fn.yith_ywsbs_variations = function () {
22		var $form = $('.variations_form'),
23			$button = $form.find('.single_add_to_cart_button');
24
25
26		$form.on('found_variation', function (event, variation) {
27			if ( variation.is_subscription == true ) {
28				$button.text(yith_ywsbs_frontend.add_to_cart_label);
29			} else {
30				$button.text(yith_ywsbs_frontend.default_cart_label);
31			}
32		});
33
34	};
35
36	if ( $body.hasClass('single-product') ) {
37		$.fn.yith_ywsbs_variations();
38	}
39
40	/**
41	 * MODAL
42	 */
43
44	$(document).on('click', '.ywsbs-open-modal', function (event) {
45		event.stopPropagation();
46
47		try {
48			// Check for modal.
49			var modal = $(document).find('.ywsbs-modal');
50			if ( !modal.length ) {
51				return;
52			}
53
54			var template 		= wp.template('ywsbs-' + $(this).data('target'));
55			var templateContent = $(this).data('content') || {}
56
57			// Add modal body.
58			modal.find('.ywsbs-modal-body').html(template( templateContent ));
59			modal.fadeIn('slow');
60
61			$(document).trigger('ywsbs-subscription-modal-shown', [modal]);
62
63		} catch (error) {
64			console.error(error);
65		}
66	});
67
68	$(document).on('click', '.ywsbs-modal .close', function (event) {
69		event.stopPropagation();
70
71		var modal = $(document).find('.ywsbs-modal');
72
73		modal.fadeOut('slow', function () {
74			modal.find('.ywsbs-modal-body').html('');
75
76			$(document).trigger('ywsbs-subscription-modal-closed', [modal]);
77		});
78	});
79
80	/**
81	 * Change subscription status
82	 */
83
84	function reloadSubscriptionView() {
85		$.post(document.location.href, function (data) {
86			if ( data != '' ) {
87				var c = $("<div></div>").html(data),
88					wrap = c.find('.ywsbs-subscription-view-wrap');
89				$('.ywsbs-subscription-view-wrap').html(wrap.html());
90			}
91		});
92	}
93
94	$(document).on('click', '.ywsbs-action-button', function (e) {
95		e.preventDefault();
96		var $t = $(this),
97			container = $t.closest('.ywsbs-action-button-wrap'),
98			modalWrapper = $t.closest('.ywsbs-modal-body'),
99			modalBody = modalWrapper.find('.ywsbs-content-text'),
100			closeButton = modalWrapper.find('.close-modal-wrap'),
101			status = $t.data('action'),
102			sbs_id = $t.data('id'),
103			security = $t.data('nonce');
104
105		container.block(blockParams);
106		var data = {
107			subscription_id: sbs_id,
108			action: 'ywsbs_' + status + '_subscription',
109			change_status: status,
110			security: security,
111			context: 'frontend'
112		};
113
114		$.ajax({
115			url: yith_ywsbs_frontend.ajaxurl,
116			data: data,
117			type: 'POST',
118			success: function (response) {
119				if ( response.success ) {
120					modalBody.html(response.success);
121				}
122
123				if ( response.error ) {
124					modalBody.html('<span class="error">' + response.error + '</span>');
125				}
126
127				$t.fadeOut();
128				closeButton.fadeOut();
129				setTimeout(function () {
130					$('.ywsbs-modal .close').trigger('click');
131					reloadSubscriptionView(sbs_id);
132				}, 2500);
133			},
134			complete: function () {
135				container.unblock();
136			}
137		});
138	});
139});

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.