PageSourceSearch

https://alpinemag.fr/wp-content/plugins/recapture-for-restrict-content-pro//js/recapture-rcp.js?ver=1.0.21

js alpinemag.fr collected 2026-10-02 03:12:56 UTC 5,402 bytes, 203 lines download raw bytes

1(function () {
2  function debounce(timeout, callback) {
3    let bounceTimeout = null;
4
5    return function () {
6      if (bounceTimeout) {
7        clearTimeout(bounceTimeout);
8      }
9      bounceTimeout = setTimeout(callback, timeout);
10    };
11  }
12
13  function getCartUrl(level, cartId) {
14    // parse current params (if any)
15    const params = jQuery.deparam(window.location.search.substring(1));
16
17    // set the level
18    params.level = level;
19
20    // remove the discount (if any) so it can be added by recapture
21    if (params.discount) {
22      delete params.discount;
23    }
24
25    // set the cart id
26    params.racart = cartId;
27
28    // return the new url
29    return (
30      location.protocol +
31      '//' +
32      location.host +
33      location.pathname +
34      '?' +
35      jQuery.param(params)
36    );
37  }
38
39  function getProductName(level) {
40    return new Promise(resolve => {
41      jQuery.ajax({
42        type: 'post',
43        dataType: 'json',
44        url: rcp_script_options.ajaxurl,
45        data: {
46          action: 'recapture_get_level_details',
47          level,
48        },
49        success: function (response) {
50          if (!response.success) {
51            resolve('');
52            return;
53          }
54
55          resolve(response?.data?.name || '');
56        },
57        error: function () {
58          resolve('');
59        },
60      });
61    });
62  }
63
64  function getProductInfo(onSuccess, onError) {
65    const state = rcp_get_registration_form_state();
66
67    jQuery.ajax({
68      type: 'post',
69      dataType: 'json',
70      url: rcp_script_options.ajaxurl,
71      data: {
72        action: 'rcp_validate_registration_state',
73        rcp_level: state.membership_level,
74        lifetime: state.lifetime,
75        level_has_trial: state.level_has_trial,
76        is_free: state.is_free,
77        discount_code: state.discount_code,
78        rcp_gateway: state.gateway,
79        rcp_auto_renew: true === state.auto_renew ? true : '',
80        event_type: null,
81        registration_type: jQuery('#rcp-registration-type').val(),
82        membership_id: jQuery('#rcp-membership-id').val(),
83        rcp_registration_payment_id: jQuery('#rcp-payment-id').val(),
84      },
85      success: async function (response) {
86        if (!response.success) {
87          return;
88        }
89
90        const {data} = response;
91
92        const name =
93          // get form the api first
94          (await getProductName(data.level_id)) ||
95          // Get the subscription level name using the selector
96          jQuery(
97            `.rcp_subscription_level_${data.level_id} .rcp_subscription_level_name`,
98          ).text() ||
99          // Use the totals table
100          jQuery(
101            '.rcp_registration_total_details td[data-th=Membership]',
102          ).text();
103
104        onSuccess({
105          level: data.level_id,
106          price: data.initial_total,
107          lifetime: data.lifetime,
108          discountCode: data.discount_code,
109          gateway: data.gateway,
110          gatewayData: rcp_get_gateway(),
111          autoRenew: jQuery('#rcp_auto_renew').prop('checked'),
112          name,
113        });
114      },
115      error: function (xhr, options, err) {
116        onError(err);
117      },
118    });
119  }
120
121  const sendCartToRecapture = debounce(2500, function () {
122    // If we have a subscription and we should not create carts for renewals then exit
123    if (__recaptureRcp.hasSubscription && __recaptureRcp.excludeRenewalCarts) {
124      return;
125    }
126
127    getProductInfo(
128      function (product) {
129        const cartId = Cookies.get('racart');
130
131        const cart = {
132          externalId: cartId,
133          checkoutUrl: getCartUrl(product.level, cartId),
134          customerId: Cookies.get('ra_customer_id'),
135          firstName:
136            jQuery('#rcp_user_first').val() || __recaptureRcp.firstName,
137          lastName: jQuery('#rcp_user_last').val() || __recaptureRcp.lastName,
138          email: jQuery('#rcp_user_email').val() || __recaptureRcp.email,
139          products: [
140            {
141              externalId: product.level,
142              sku: product.level,
143              name: product.name,
144              price: product.price,
145              imageUrl: '',
146              quantity: 1,
147            },
148          ],
149          shipping: 0,
150          tax: 0,
151        };
152
153        ra('setCart', [cart]);
154      },
155      function (err) {
156        // Level not found in RCP, don't log the cart
157      },
158    );
159  });
160
161  function onDocumentKeyPress() {
162    // send the cart to Recapture
163    sendCartToRecapture();
164  }
165
166  function onLevelChange(level) {
167    sendCartToRecapture();
168  }
169
170  function onDiscountChanged() {
171    sendCartToRecapture();
172  }
173
174  function onDiscountApplies(discount, d2) {
175    sendCartToRecapture();
176  }
177
178  function onLoad() {
179    // make sure we have valid data from WP
180    if (!__recaptureRcp) {
181      return;
182    }
183
184    // handle change level events
185    jQuery('body').on('rcp_level_change', onLevelChange);
186    jQuery('body').on('rcp_discount_change', onDiscountChanged);
187    jQuery('body').on('rcp_discount_applied', onDiscountApplies);
188
189    if (__recaptureRcp.email && ra) {
190      ra('email');
191    }
192
193    if (__recaptureRcp.hasSubscription) {
194      // The user already has a subscription to create the cart
195      sendCartToRecapture();
196    } else {
197      // wait for a keypress, then send the cart
198      jQuery(document).on('keypress.recapture', onDocumentKeyPress);
199    }
200  }
201
202  jQuery(document).ready(onLoad);
203})();

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.