PageSourceSearch

https://abigailwhitney.co/assets/js/product-config.js

js abigailwhitney.co collected 2026-10-09 01:06:34 UTC 2,581 bytes, 88 lines download raw bytes

1document.addEventListener('DOMContentLoaded', function () {
2  if (!window.AWCart) return;
3
4  var configScript = document.getElementById('product-config');
5  if (!configScript) return;
6
7  var PRODUCT_CONFIG;
8  try {
9    PRODUCT_CONFIG = JSON.parse(configScript.textContent);
10  } catch (e) {
11    console.error('Invalid product-config JSON', e);
12    return;
13  }
14
15  var buyButton = document.getElementById('buyButton');
16  var loading   = document.getElementById('loading');
17  var errorDiv  = document.getElementById('error');
18
19  if (!buyButton) return;
20
21  function getSelectedVariant() {
22    if (!PRODUCT_CONFIG.variants || !PRODUCT_CONFIG.variants.length) return null;
23
24    var selected = document.querySelector('input[name="variant_language"]:checked');
25    if (!selected) return PRODUCT_CONFIG.variants[0];
26
27    var lang = selected.value;
28    return PRODUCT_CONFIG.variants.find(function (v) {
29      return v.language === lang;
30    }) || PRODUCT_CONFIG.variants[0];
31  }
32
33  buyButton.addEventListener('click', function (event) {
34    event.preventDefault();
35
36    if (loading) {
37      loading.textContent = 'Adding to cart…';
38      loading.style.display = 'block';
39    }
40    if (errorDiv) {
41      errorDiv.style.display = 'none';
42      errorDiv.textContent = '';
43    }
44
45    var variant = getSelectedVariant();
46
47    // Determine price to use (sale price if available and lower)
48    var regularPrice = PRODUCT_CONFIG.price;
49    var salePrice = PRODUCT_CONFIG.sale_price;
50    var usePrice = (salePrice && salePrice < regularPrice) ? salePrice : regularPrice;
51
52    var price = variant && typeof variant.price === 'number'
53      ? variant.price
54      : usePrice;
55
56    // Determine original price for strikethrough (only if on sale)
57    var originalPrice = null;
58    if (salePrice && salePrice < regularPrice) {
59      originalPrice = regularPrice;
60    }
61
62    var id = variant && variant.id
63      ? variant.id
64      : PRODUCT_CONFIG.id;
65
66    // Base name only
67    var name = PRODUCT_CONFIG.name;
68    // Note shown on second line in cart
69    var variantLabel = variant ? (variant.label || variant.language || '') : '';
70
71    AWCart.addItem({
72      id: id,
73      name: name,
74      price: price,
75      original_price: originalPrice,
76      image: PRODUCT_CONFIG.image || '',
77      url: PRODUCT_CONFIG.url || window.location.pathname,
78      variant: variantLabel,
79      format: PRODUCT_CONFIG.format || 'digital'
80    });
81
82    var trigger = document.querySelector('.cart-trigger');
83    if (trigger) trigger.click();
84
85    if (loading) loading.style.display = 'none';
86    buyButton.blur();
87  });
88});

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.