PageSourceSearch

https://expertmusic.net.ua/wp-content/plugins/enhancer-for-woocomm…/assets/js/frontend.js?ver=4.5.0

js expertmusic.net.ua collected 2026-10-07 00:51:40 UTC 7,776 bytes, 183 lines download raw bytes

1/* global enr_frontend_params */
2
3jQuery( function ( $ ) {
4    'use strict';
5
6    var is_blocked = function ( $node ) {
7        return $node.is( '.processing' ) || $node.parents( '.processing' ).length;
8    };
9
10    /**
11     * Block a node visually for processing.
12     *
13     * @param {JQuery Object} $node
14     */
15    var block = function ( $node ) {
16        $.blockUI.defaults.overlayCSS.cursor = 'wait';
17
18        if ( !is_blocked( $node ) ) {
19            $node.addClass( 'processing' ).block( {
20                message: null,
21                overlayCSS: {
22                    background: '#fff',
23                    opacity: 0.6
24                }
25            } );
26        }
27    };
28
29    /**
30     * Unblock a node after processing is complete.
31     *
32     * @param {JQuery Object} $node
33     */
34    var unblock = function ( $node ) {
35        $node.removeClass( 'processing' ).unblock();
36    };
37
38    // Hide variable level limit notice when it is limited to variation level
39    if ( 'yes' === enr_frontend_params.hide_variable_limited_notice && $( 'form.variations_form' ).length && $( 'form.variations_form' ).find( '.limited-subscription-notice' ).length ) {
40        $( 'form.variations_form' ).find( '.limited-subscription-notice' ).hide();
41    }
42
43    function maybeProcessSwitchRequest() {
44        if ( window.location.href.indexOf( 'switch-subscription' ) != -1 && window.location.href.indexOf( 'item' ) != -1 ) {
45            $( '.product form.cart' ).prop( 'action', '' );
46        }
47    }
48
49    /**
50     * Handle product page subscribe events.
51     */
52    var wcs_variations_form = {
53        variationForm: $( '.variations_form' ),
54        cartForm: $( 'form.cart' ),
55        init: function () {
56            $( document ).on( 'found_variation.wc-variation-form', this.onFoundVariation );
57            $( document ).on( 'reset_data', this.onResetVariation );
58        },
59        onFoundVariation: function ( evt, variation ) {
60            wcs_variations_form.onResetVariation();
61
62            if ( variation.enr_limited_subscription_notice ) {
63                wcs_variations_form.variationForm.find( '.woocommerce-variation-add-to-cart' ).after( variation.enr_limited_subscription_notice );
64            }
65
66            if ( variation.enr_resubscribe_link ) {
67                wcs_variations_form.variationForm.find( '.woocommerce-variation-add-to-cart' ).after( variation.enr_resubscribe_link );
68            }
69
70            if ( variation.enr_subscribe_now_form ) {
71                wcs_variations_form.variationForm.find( '.woocommerce-variation-add-to-cart' ).before( variation.enr_subscribe_now_form );
72                wcs_variations_form.variationForm.find( '.single_add_to_cart_button' ).text( variation.enr_single_add_to_cart_text );
73                wcs_variations_form.variationForm.find( '.enr-subscribe-now-wrapper #enr_subscribe_now' ).change();
74            }
75            
76            maybeProcessSwitchRequest();
77        },
78        onResetVariation: function () {
79            if ( wcs_variations_form.variationForm.find( '.enr-variation-wrapper' ).length ) {
80                wcs_variations_form.variationForm.find( '.enr-variation-wrapper' ).remove();
81            }
82
83            if ( wcs_variations_form.variationForm.find( '.enr-subscribe-now-wrapper' ).length ) {
84                wcs_variations_form.variationForm.find( '.enr-subscribe-now-wrapper' ).parent().remove();
85            }
86
87            wcs_variations_form.variationForm.find( '.single_add_to_cart_button' ).removeClass( 'enr_single_subscribe_button' ).text( enr_frontend_params.single_add_to_cart_text );
88        },
89    };
90
91    /**
92     * Handle subscribe now events.
93     */
94    var wcs_subscribe_now = {
95        wrapper: $( '.enr-subscribe-now-wrapper' ),
96        init: function () {
97            $( document ).on( 'change', '#enr_subscribe_now,#enr_subscribe_plans,#enr_subscribe_period,#enr_subscribe_period_interval,#enr_subscribe_length', this.updateAction );
98            $( document ).on( 'updated_wc_div, updated_cart_totals', this.mayBeShowForm );
99
100            if ( this.wrapper.length > 0 ) {
101                this.wrapper.find( '#enr_subscribe_now' ).change();
102                maybeProcessSwitchRequest();
103            }
104        },
105        showForm: function ( node ) {
106            var wrapper = node;
107            wrapper = node.closest( '.enr-subscribe-now-wrapper' );
108
109            if ( wrapper.length > 0 ) {
110                if ( wrapper.find( '#enr_subscribe_now' ).is( ':checked' ) ) {
111                    wrapper.find( 'tr:gt(0)' ).slideDown();
112                } else {
113                    wrapper.find( 'tr:gt(0)' ).slideUp();
114                }
115            }
116        },
117        mayBeShowForm: function () {
118            wcs_subscribe_now.showForm( wcs_subscribe_now.wrapper );
119        },
120        updateAction: function ( evt, refreshed ) {
121            evt.preventDefault();
122
123            var $this = $( evt.currentTarget );
124            refreshed = refreshed || false;
125
126            wcs_subscribe_now.showForm( $this );
127            block( wcs_subscribe_now.getNode() );
128
129            $.ajax( {
130                type: 'POST',
131                url: enr_frontend_params.ajax_url,
132                data: {
133                    action: '_enr_subscribe_now',
134                    security: enr_frontend_params.subscribe_now_nonce,
135                    is_switch_request: enr_frontend_params.is_switch_request,
136                    data: $this.closest( '.enr-subscribe-now-wrapper' ).find( ':input[name]' ).serialize()
137                },
138                success: function ( response ) {
139                    if ( response.success ) {
140                        $this.closest( response.data.subscribe_wrapper_class ).empty().append( response.data.html );
141                        wcs_subscribe_now.showForm( $this );
142
143                        if ( $( '.single_add_to_cart_button' ).length ) {
144                            if ( '1' !== enr_frontend_params.is_switch_request && $this.closest( '.enr-subscribe-now-wrapper' ).find( '#enr_subscribe_now' ).is( ':checked' ) ) {
145                                $( '.single_add_to_cart_button' ).addClass( 'enr_single_subscribe_button' ).text( enr_frontend_params.subscribe_now_button_text );
146                            } else {
147                                $( '.single_add_to_cart_button' ).removeClass( 'enr_single_subscribe_button' ).text( enr_frontend_params.single_add_to_cart_text );
148                            }
149                        }
150
151                        if ( false === response.data.refresh || true === refreshed ) {
152                            $( document.body ).trigger( 'update_checkout' );
153
154                            if ( $( '.woocommerce-cart-form' ).length ) {
155                                $( document.body ).trigger( 'wc_update_cart' );
156                            }
157                        } else {
158                            $( '#enr_subscribe_now' ).trigger( 'change', [ true ] );
159                        }
160                        
161                        $( document.body ).trigger( 'enr_subscribe_form_submitted_success' );
162                    }
163                },
164                complete: function () {
165                    unblock( wcs_subscribe_now.getNode() );
166                }
167            } );
168            return false;
169        },
170        getNode: function () {
171            if ( $( '.woocommerce-cart-form' ).length ) {
172                return $( 'div.cart_totals' );
173            } else if ( $( '.woocommerce-checkout' ).length ) {
174                return $( '.woocommerce-checkout-payment, .woocommerce-checkout-review-order-table' ).closest( 'form' );
175            } else {
176                return $( '.enr-subscribe-now-wrapper' );
177            }
178        },
179    };
180
181    wcs_variations_form.init();
182    wcs_subscribe_now.init();
183} );

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.