PageSourceSearch

https://jagdishsweets.com/src/js/modules/profile_sidebar.js?v=1790839790

js jagdishsweets.com collected 2026-10-02 01:32:58 UTC 5,210 bytes, 109 lines download raw bytes

1'use strict';
2
3(function () {
4    var sidebar = document.getElementById('profileSidebar');
5    var overlay = document.getElementById('profileOverlay');
6    if (!sidebar || !overlay) return;
7
8    var nameEl  = document.getElementById('psName');
9    var emailEl = document.getElementById('psEmail');
10
11    function getUser() {
12        try { return JSON.parse(localStorage.getItem('userdata') || '{}'); }
13        catch (e) { return {}; }
14    }
15
16    function prefill() {
17        var u = getUser();
18        if (nameEl)  nameEl.textContent  = u.name || (u.mobile ? '+91 ' + u.mobile : 'Guest');
19        if (emailEl) emailEl.textContent = u.email || '';
20    }
21
22    // The menu card clears the sticky header on mobile. Header height varies per
23    // brand (logo + tagline) and a notification/announcement bar may sit above it,
24    // so measure the header's live BOTTOM edge rather than hardcode a height —
25    // otherwise a taller header overlaps the card. Desktop uses the in-card layout.
26    function syncHeaderOffset() {
27        var header = document.querySelector('.site-header');
28        if (header && window.matchMedia('(max-width: 767px)').matches) {
29            // +8px breathing gap so the card never visually touches the header's
30            // bottom border/shadow (which reads as an overlap).
31            var offset = Math.max(0, Math.round(header.getBoundingClientRect().bottom)) + 8;
32            sidebar.style.setProperty('--profile-header-offset', offset + 'px');
33        } else {
34            sidebar.style.removeProperty('--profile-header-offset');
35        }
36    }
37
38    function open() {
39        prefill();
40        syncHeaderOffset();
41        overlay.hidden = false;
42        // next frame so transition fires
43        requestAnimationFrame(function () {
44            overlay.classList.add('is-open');
45            sidebar.classList.add('is-open');
46            sidebar.setAttribute('aria-hidden', 'false');
47            // `clip` (not `hidden`) locks scroll without making <body> a scroll
48            // container — `hidden` would break `position: sticky` on the menu's
49            // left category rail (see CLAUDE.md sticky/overflow gotcha).
50            document.body.style.overflow = 'clip';
51            // Mobile keeps the sidebar under the sticky header (z 1020 < 1030) so
52            // the header icon stays tappable to close it; the checkout pay bar is
53            // also z 1030, so flag the body to hide it while the menu is open.
54            document.body.classList.add('profile-sidebar-is-open');
55            // Re-measure after the layout settles (overflow:clip applied, sticky
56            // header repositioned) so the offset reflects the final on-screen header.
57            syncHeaderOffset();
58        });
59    }
60
61    // Keep the offset correct if the viewport rotates/resizes while the menu is open.
62    window.addEventListener('resize', function () {
63        if (sidebar.classList.contains('is-open')) syncHeaderOffset();
64    });
65
66    function close() {
67        overlay.classList.remove('is-open');
68        sidebar.classList.remove('is-open');
69        sidebar.setAttribute('aria-hidden', 'true');
70        document.body.style.overflow = '';
71        document.body.classList.remove('profile-sidebar-is-open');
72        // hide overlay after transition so it doesn't block clicks
73        setTimeout(function () {
74            if (!overlay.classList.contains('is-open')) overlay.hidden = true;
75        }, 280);
76    }
77
78    window.toggleProfileSidebar = function () {
79        if (sidebar.classList.contains('is-open')) close(); else open();
80    };
81    window.openProfileSidebar  = open;
82    window.closeProfileSidebar = close;
83
84    overlay.addEventListener('click', close);
85    document.getElementById('profileSidebarClose')?.addEventListener('click', close);
86    document.addEventListener('keydown', function (e) {
87        if (e.key === 'Escape' && sidebar.classList.contains('is-open')) close();
88    });
89
90    document.getElementById('psLogout')?.addEventListener('click', function () {
91        // Clear the entry_channel cookie (set by WhatsappOrderAuthFilter on a
92        // WhatsApp nonce redeem) — without this, a WhatsApp customer logging out
93        // would leave it set, silently mis-attributing whatever they (or the next
94        // person on a shared device) do next as a WhatsApp-originated session.
95        // Plain cookie, not session data (see wa_entry_channel() in wla_helper.php),
96        // so this file — a classic <script>, not a module, can't import the
97        // auth-storage.js helper other logout paths use — just clears it directly.
98        document.cookie = 'entry_channel=; Max-Age=0; path=/';
99        localStorage.removeItem('userdata');
100        localStorage.removeItem('token');
101        localStorage.removeItem('v4_cart');
102        // Fast-checkout last-payment cache — never carry a UPI method across accounts.
103        localStorage.removeItem('last_payment_date');
104        localStorage.removeItem('last_payment_response');
105        // Reset the location journey so a new session re-prompts for outlet selection.
106        if (typeof window.resetLocationJourney === 'function') window.resetLocationJourney();
107        window.location.href = '/';
108    });
109})();

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.