PageSourceSearch

https://quovadis-hb.de/wp-content/plugins/oneboxshop-cart/includes…/customer-account-inject.js?ver=3.20.0

js quovadis-hb.de collected 2026-10-07 20:29:58 UTC 3,973 bytes, 98 lines download raw bytes

1/**
2 * Minimal script loaded everywhere to inject the account overview offcanvas and its full scripts into the page on-demand.
3 */
4(function ($) {
5
6    /**
7     * Inject an empty offcanvas into the page, show it and load in the account overview content through AJAX.
8     */
9    function inject_offcanvas() {
10        // Inject Bootstrap offcanvas wrapper.
11        let offcanvas = $('#oneboxshop_account_overview');
12
13        if (offcanvas.length === 0) {
14            $('body').append('<div class="obs-bootstrap5"><div id="oneboxshop_account_overview" class="offcanvas offcanvas-end" tabindex="-1"></div>');
15            offcanvas = $('#oneboxshop_account_overview');
16        }
17
18        // Place spinner while loading inner content through AJAX.
19        offcanvas.html('<div class="offcanvas-body"><span class="fa fa-refresh fa-spin"></span></div>');
20        offcanvas.find('.offcanvas-body')
21            .css({
22                'display': 'flex',
23                'flex-direction': 'column',
24                'justify-content': 'center',
25                'align-items': 'center',
26            })
27            .find('span.fa-spin')
28            .css('font-size', '2em');
29
30        // Open offcanvas programmatically.
31        new bootstrap.Offcanvas(document.getElementById('oneboxshop_account_overview')).show();
32
33        // Load the account overview content to place inside the offcanvas through AJAX and the full JavaScript.
34        $.ajax(oneboxshop_cart_customer_account_frontend_parameters.url, {
35            type: 'POST',
36            data: {
37                action: 'oneboxshop_cart_frontend_sync',
38                nonce: oneboxshop_cart_customer_account_frontend_parameters.nonce,
39                type: 'customer_account',
40                func: 'show_customer_account_offcanvas',
41            },
42            dataType: 'json',
43            success: function (response) {
44                handle_invalid_nonce(response);
45                if (response.success) {
46                    // Load HTML.
47                    offcanvas.html(response.data.html);
48
49                    // Load script.
50                    if (response.data['script_id'] !== '' && response.data['script'] !== '') {
51                        if ($('#' + response.data['script_id']).length === 0) {
52                            const script_node = document.createElement('script');
53                            script_node.id = response.data['script_id'];
54                            script_node.text = response.data['script'];
55                            document.body.appendChild(script_node);
56                        }
57                    }
58
59                    // Trigger event to re-initialize event listeners on the new offcanvas.
60                    $(document).trigger('oneboxshop_account_overview_offcanvas_loaded');
61                } else {
62                    offcanvas.html('<div class="alert alert-danger">' + response.data + '</div>');
63                }
64            },
65            error: function (xhr, status, error) {
66                offcanvas.html('<div class="alert alert-danger">' + error + '</div>');
67            }
68        });
69    }
70
71
72    /**
73     * If response contains error code for invalid nonce, reload the page to refresh the nonce.
74     */
75    function handle_invalid_nonce(response = {}) {
76        if (response.hasOwnProperty('data') && response.data.hasOwnProperty('code') && response.data.code === 'nonce_invalid') {
77            window.location.reload();
78        }
79    }
80
81
82    // If the hash is already present on page load, inject the offcanvas immediately.
83    $(document).ready(function () {
84        if (window.location.hash === '#account') {
85            inject_offcanvas();
86        }
87    });
88
89    // Only inject the offcanvas if the hash is present.
90    $(window).on('hashchange', function (event) {
91        if (window.location.hash === '#account') {
92            event.stopPropagation();
93            event.preventDefault();
94            inject_offcanvas();
95        }
96    });
97
98})(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.