PageSourceSearch

https://www.mentedigitale.org/wp-content/plugins/wp-user-frontend/assets/js/subscriptions-old.js?ver=4.3.12

js mentedigitale.org collected 2026-09-24 18:27:16 UTC 13,642 bytes, 401 lines download raw bytes

1(function($) {
2
3	var subscription = {
4
5		init: function() {
6
7			$('input#wpuf-recuring-pay').on('click', this.showSubscriptionRecurring );
8
9			$('input#wpuf-trial-status').on('click', this.showSubscriptionPack );
10
11            $('.wpuf-order-summary').on( 'click', 'a.wpuf-apply-coupon', this.couponApply );
12
13            $('.wpuf-order-summary').on( 'click', 'a.wpuf-coupon-show', this.couponShow );
14
15            $('.wpuf-order-summary').on( 'click', 'a.wpuf-coupon-cancel', this.couponCancel );
16
17            $('.wpuf-order-summary').on( 'click', '.wpuf-coupon-remove', this.couponRemove );
18
19            $( '#wpuf-payment-gateway' ).on( 'submit', this.checkoutSubmit );
20
21            $('.wpuf-assing-pack-btn').on( 'click', this.showPackDropdown );
22
23            $('.wpuf-delete-pack-btn').on( 'click', this.deletePack );
24
25            $('.wpuf-disabled-link').click( this.packAlert );
26
27            //on change enable expiration check status
28            this.changeExpirationFieldVisibility(':checkbox#wpuf-enable_post_expiration');
29
30            $('.wpuf-metabox-post_expiration').on('change',':checkbox#wpuf-enable_post_expiration',this.changeExpirationFieldVisibility);
31            //on change expiration type drop down
32            //this.setTimeExpiration('select#wpuf-expiration_time_type');
33            $('.wpuf-metabox-post_expiration').on('change','select#wpuf-expiration_time_type',this.setTimeExpiration);
34
35            // warn the user before updating the package
36            $( 'body.post-type-wpuf_subscription #post' ).submit( function( event ) {
37                if ( document.activeElement.value === 'Update' ) {
38                    event.preventDefault();
39                    Swal.fire({
40                        title: 'Are you sure to update the subscription?',
41                        text: 'The changes you made will be applied only to the new subscriptions and pending recurring payments.',
42                        icon: 'warning',
43                        showCancelButton: true,
44                        confirmButtonColor: '#3085d6',
45                        cancelButtonColor: '#d33',
46                        confirmButtonText: 'Update'
47                    }).then((result) => {
48                        if (result.isConfirmed) {
49                            $( this ).unbind('submit').submit()
50                        }
51                    });
52                }
53            } );
54
55		},
56
57        packAlert : function () {
58            alert( wpuf_subscription.pack_notice );
59        },
60
61        showPackDropdown: function(e) {
62            e.preventDefault();
63            var self = $(this),
64                wrap = self.parents('.wpuf-user-subscription'),
65                sub_dropdown = wrap.find('.wpuf-pack-dropdown'),
66                sub_details = wrap.find('.wpuf-user-sub-info'),
67                cancel_btn = wrap.find('.wpuf-cancel-pack'),
68                add_btn = wrap.find('.wpuf-add-pack');
69
70            if ( sub_dropdown.attr( 'disabled' ) === 'disabled' ) {
71                sub_dropdown.show().removeAttr('disabled');
72                sub_details.hide().attr('disabled', true );
73                cancel_btn.show();
74                add_btn.hide();
75            } else {
76                sub_details.show().removeAttr('disabled');
77                sub_dropdown.hide().attr('disabled', true );
78                cancel_btn.hide();
79                add_btn.show();
80            }
81
82        },
83
84        deletePack: function(e){
85            var self = $(this),
86                wrap = self.parents('.wpuf-user-subscription'),
87                sub_dropdown = wrap.find('.wpuf-pack-dropdown'),
88                selected_sub = wrap.find( '#wpuf_sub_pack' ),
89                userid = $(e.target).attr('data-userid'),
90                packid = $(e.target).attr('data-packid');
91
92            wrap.find('.wpuf-delete-pack-btn').attr('disabled', true);
93            wrap.css('opacity', 0.5);
94            $.post(
95                ajaxurl,
96                {
97                    'action' : 'wpuf_delete_user_package',
98                    'userid' : userid,
99                    'packid' : packid,
100                    'wpuf_subscription_delete_nonce': wpuf_subs_vars.wpuf_subscription_delete_nonce
101                },
102                function(data){
103                    if(data){
104                        wrap.css( 'opacity', 1 );
105                        $('.wpuf-user-sub-info').remove();
106                        $(e.target).remove();
107                        selected_sub.val(-1);
108                        sub_dropdown.show();
109                    }
110                }
111            );
112
113        },
114
115        couponCancel: function(e) {
116
117            e.preventDefault();
118
119            var self = $(this),
120
121                data = {
122
123                    action: 'wpuf_coupon_cancel',
124
125                    _wpnonce: wpuf_frontend.nonce,
126
127                    pack_id: self.data('pack_id'),
128
129                    type: $( '#wpuf_type' ).text() || 'pack'
130
131                },
132
133                coupon_field = self.closest('.wpuf-order-summary').find('input.wpuf-coupon-field');
134
135
136
137            coupon_field.addClass('wpuf-coupon-field-spinner');
138
139            $.post( wpuf_frontend.ajaxurl, data, function( res ) {
140
141                coupon_field.removeClass('wpuf-coupon-field-spinner');
142
143                if ( res.success ) {
144                    var orderSummary = self.closest('.wpuf-order-summary');
145                    orderSummary.find('.wpuf-pack-inner').html( res.data.append_data );
146                    orderSummary.find('.wpuf-coupon-id-field').val('');
147                    orderSummary.find('.wpuf-coupon-applied').remove();
148                    orderSummary.find('.wpuf-coupon-show').show();
149                }
150
151            });
152        },
153
154        couponRemove: function(e) {
155
156            e.preventDefault();
157
158            var self = $(this),
159                orderSummary = self.closest('.wpuf-order-summary'),
160                data = {
161                    action: 'wpuf_coupon_cancel',
162                    _wpnonce: wpuf_frontend.nonce,
163                    pack_id: self.data('pack_id'),
164                    type: $( '#wpuf_type' ).text() || 'pack'
165                };
166
167            $.post( wpuf_frontend.ajaxurl, data, function( res ) {
168                if ( res.success ) {
169                    orderSummary.find('.wpuf-pack-inner').html( res.data.append_data );
170                    orderSummary.find('.wpuf-coupon-id-field').val('');
171                    orderSummary.find('.wpuf-coupon-applied').remove();
172                    orderSummary.find('.wpuf-coupon-show').show();
173                }
174            });
175
176        },
177
178        couponShow: function(e) {
179
180            e.preventDefault();
181
182            var self = $(this);
183
184            self.hide();
185
186            self.siblings('.wpuf-coupon-wrap').show();
187
188        },
189
190        couponApply: function(e) {
191
192            e.preventDefault();
193
194            var self = $(this),
195
196                orderSummary = self.closest('.wpuf-order-summary'),
197
198                coupon_field = orderSummary.find('input.wpuf-coupon-field'),
199
200                coupon = coupon_field.val();
201
202
203            if ( coupon === '' ) {
204
205                orderSummary.find('.wpuf-coupon-error').html( wpuf_frontend.coupon_error );
206                return;
207
208            }
209
210            var data = {
211
212                    action: 'wpuf_coupon_apply',
213
214                    _wpnonce: wpuf_frontend.nonce,
215
216                    coupon: coupon,
217
218                    pack_id: self.data('pack_id'),
219
220                    type: $( '#wpuf_type' ).text() || 'pack'
221
222                };
223
224
225            if ( self.attr('disabled') === 'disabled' ) {
226
227                //return;
228
229            }
230
231            self.attr( 'disabled', true );
232
233            coupon_field.addClass('wpuf-coupon-field-spinner');
234
235            $.post( wpuf_frontend.ajaxurl, data, function( res ) {
236                coupon_field.removeClass('wpuf-coupon-field-spinner');
237
238                if ( res.success ) {
239                    orderSummary.find('.wpuf-pack-inner').html( res.data.append_data );
240                    orderSummary.find('.wpuf-coupon-id-field').val( res.data.coupon_id );
241                    orderSummary.find('.wpuf-coupon-error').html('');
242
243                    if ( res.data.amount <= 0 ) {
244                        $('.wpuf-nullamount-hide').hide();
245                    }
246
247                    // Hide the coupon input wrap and show the applied bar
248                    var coponWrap = orderSummary.find('.wpuf-coupon-wrap');
249                    coponWrap.hide();
250                    orderSummary.find('.wpuf-coupon-applied').remove();
251                    orderSummary.append(
252                        '<div class="wpuf-coupon-applied">' +
253                            '<span class="wpuf-coupon-applied-label">Coupon code applied</span>' +
254                            '<button type="button" class="wpuf-coupon-remove" data-pack_id="' + self.data('pack_id') + '">&times;</button>' +
255                        '</div>'
256                    );
257                } else {
258                    self.attr( 'disabled', false );
259                    orderSummary.find('.wpuf-coupon-error').html( res.data.message );
260                }
261
262            });
263
264        },
265
266		showSubscriptionRecurring: function() {
267
268            var self = $(this),
269
270                wrap = self.parents('table.form-table'),
271                pack_child = wrap.find('.wpuf-recurring-child'),
272                trial_checkbox = wrap.find('input#wpuf-trial-status'),
273                trial_child = wrap.find('.wpuf-trial-child'),
274                expire_field = wrap.find('.wpuf-subcription-expire');
275
276            if ( self.is(':checked') ) {
277
278            	if ( trial_checkbox.is(':checked') ) {
279
280            		trial_child.show();
281
282            	}
283
284                pack_child.show();
285
286                expire_field.hide();
287
288            } else {
289
290            	trial_child.hide();
291
292                pack_child.hide();
293
294                expire_field.show();
295
296            }
297
298        },
299
300        showSubscriptionPack: function() {
301
302            var self = $(this),
303
304                pack_status = self.closest('table.form-table').find('.wpuf-trial-child');
305
306            if ( self.is(':checked') ) {
307
308                pack_status.show();
309
310            } else {
311
312                pack_status.hide();
313
314            }
315
316        },
317
318        setTimeExpiration: function(e){
319            var timeArray = {
320                'day' : 30,
321                'month' : 12,
322                'year': 100
323            };
324            $('#wpuf-expiration_time_value').html('');
325            var timeVal = e.target?$(e.target).val():$(e).val();
326            for(var time = 1; time <= timeArray[timeVal]; time++){
327                $('#wpuf-expiration_time_value').append('<option>'+ time +'</option>');
328            }
329        },
330
331        changeExpirationFieldVisibility : function(e){
332
333            var checkbox_obj = e.target? $(e.target) : $(e);
334
335            if ( checkbox_obj.is(':checked') ) {
336                $('.wpuf_subscription_expiration_field').show();
337            } else {
338                $('.wpuf_subscription_expiration_field').hide();
339            }
340        },
341
342        checkoutSubmit: function( e ) {
343            var form            = $( '#wpuf-payment-gateway' );
344            var selectedGateway = form.find( "input[name='wpuf_payment_method']:checked" ).val();
345            var btn             = form.find( '.wpuf-checkout-btn' );
346            var wrap            = form.find( '.wpuf-checkout-wrap' );
347            var originalLabel   = btn.data( 'original-label' ) || btn.text().trim();
348
349            // Show loading immediately so the user gets instant feedback.
350            btn.data( 'original-label', originalLabel )
351               .prop( 'disabled', true )
352               .addClass( 'wpuf-checkout-btn--loading' )
353               .html(
354                   '<span class="wpuf-btn-spinner"></span>' +
355                   '<span class="wpuf-btn-text">Processing&hellip;</span>'
356               );
357
358            // Blur the rest of the checkout so focus stays on the spinner.
359            wrap.addClass( 'wpuf-checkout-wrap--loading' ).attr( 'aria-busy', 'true' );
360
361            // Helper to roll back the button if validation fails.
362            function resetBtn() {
363                btn.prop( 'disabled', false )
364                   .removeClass( 'wpuf-checkout-btn--loading' )
365                   .text( originalLabel );
366                wrap.removeClass( 'wpuf-checkout-wrap--loading' ).removeAttr( 'aria-busy' );
367            }
368
369            // Stripe intercepts and processes everything itself (no real form POST).
370            // Keep the button disabled so the user can't double-submit while Stripe's
371            // modal/redirect runs; Pro Stripe handler is responsible for its own error UI.
372            if ( selectedGateway === 'stripe' ) {
373                return;
374            }
375
376            // validateForm() returns false on error, serialized string on success.
377            if ( typeof WP_User_Frontend !== 'undefined' ) {
378                if ( WP_User_Frontend.validateForm( form ) === false ) {
379                    resetBtn();
380                    return;
381                }
382            }
383
384            // Billing address validation when the address form is present.
385            if ( $( '#wpuf-ajax-address-form' ).length && typeof wpuf_validate_address === 'function' ) {
386                if ( ! wpuf_validate_address() ) {
387                    resetBtn();
388                    return;
389                }
390            }
391        },
392
393	};
394
395    if ( typeof datepicker === 'function') {
396        $('.wpuf-date-picker').datepicker({ dateFormat: "yy-mm-dd" });
397    }
398
399	subscription.init();
400
401})(jQuery);

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.