PageSourceSearch

https://pablomartin.com/wp-content/plugins/sm-checkout/assets/js/frontend.js?ver=1.3.0

js pablomartin.com collected 2026-10-04 06:04:04 UTC 3,834 bytes, 112 lines download raw bytes

1(function () {
2    'use strict';
3
4    var overlay = document.getElementById('smc-overlay');
5    var modal = document.getElementById('smc-modal');
6    var iframe = document.getElementById('smc-iframe');
7    var iframeContainer = document.getElementById('smc-iframe-container');
8    var loading = document.getElementById('smc-loading');
9    var success = document.getElementById('smc-success');
10    var error = document.getElementById('smc-error');
11    var closeBtn = document.getElementById('smc-close');
12
13    if (!overlay || !iframe) return;
14
15    // --- Open modal ---
16    var iframeReady = false;
17
18    function openCheckout(productId) {
19        // Reset states
20        iframeReady = false;
21        loading.style.display = '';
22        iframeContainer.style.display = 'none';
23        success.style.display = 'none';
24        error.style.display = 'none';
25
26        // Show modal
27        overlay.style.display = 'flex';
28        document.body.style.overflow = 'hidden';
29
30        // Reset iframe first, then load checkout after a tick
31        iframe.src = 'about:blank';
32        var checkoutUrl = smc_vars.checkout_base + productId;
33        setTimeout(function () {
34            iframe.src = checkoutUrl;
35        }, 50);
36    }
37
38    function showIframe() {
39        if (iframeReady) return;
40        iframeReady = true;
41        loading.style.display = 'none';
42        iframeContainer.style.display = 'block';
43    }
44
45    // --- Iframe loaded ---
46    iframe.addEventListener('load', function () {
47        if (!iframe.src || iframe.src === 'about:blank') return;
48        showIframe();
49    });
50
51    // --- Listen for messages from iframe ---
52    window.addEventListener('message', function (e) {
53        if (e.origin !== window.location.origin) return;
54
55        if (e.data === 'smc_loaded') {
56            showIframe();
57        }
58
59        if (e.data === 'smc_complete') {
60            iframeContainer.style.display = 'none';
61            loading.style.display = 'none';
62            success.style.display = '';
63        }
64
65        if (e.data && e.data.type === 'smc_redirect') {
66            // Payment gateway redirect (e.g. PayPal) — break out of iframe
67            closeModal();
68            window.location.href = e.data.url;
69        }
70    });
71
72    // --- Close modal ---
73    function closeModal() {
74        overlay.style.display = 'none';
75        document.body.style.overflow = '';
76        iframe.src = 'about:blank';
77    }
78
79    // Close ONLY via the X button (no overlay/outside click — avoids accidental close mid-payment).
80    closeBtn.addEventListener('click', closeModal);
81
82    document.addEventListener('keydown', function (e) {
83        if (e.key === 'Escape' && overlay.style.display === 'flex') {
84            closeModal();
85        }
86    });
87
88    // --- Click handler: any link with href="#pm-checkout-{id}" or "#pm-checkout" ---
89    document.addEventListener('click', function (e) {
90        var link = e.target.closest('a[href^="#pm-checkout"]');
91        if (!link) return;
92
93        e.preventDefault();
94
95        var href = link.getAttribute('href');
96        var match = href.match(/#pm-checkout-(\d+)/);
97        var productId = match ? match[1] : '553';
98
99        openCheckout(productId);
100    });
101
102    // --- Open directly from URL hash (shareable buy link), e.g. #pm-checkout-553 ---
103    function openCheckoutFromHash() {
104        var h = window.location.hash || '';
105        if (h.indexOf('#pm-checkout') !== 0) return;
106        var match = h.match(/#pm-checkout-(\d+)/);
107        var productId = match ? match[1] : '553';
108        openCheckout(productId);
109    }
110    openCheckoutFromHash();                                  // on page load
111    window.addEventListener('hashchange', openCheckoutFromHash); // if hash changes
112})();

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.