PageSourceSearch

https://morvarid.pub/assets/rodin_services/js/rodin_navbar_cart_sync.js?v=1.1.0

js morvarid.pub collected 2026-09-25 02:02:51 UTC 2,575 bytes, 95 lines download raw bytes

1(function () {
2	var refreshInFlight = false;
3	var refreshQueued = false;
4
5	function renderCartCount(count) {
6		var parsed = parseInt(String(count), 10);
7		var value = isNaN(parsed) || parsed < 1 ? 0 : parsed;
8		var badges = document.querySelectorAll("[data-rodin-cart-badge]");
9
10		for (var i = 0; i < badges.length; i++) {
11			badges[i].textContent = value ? String(value) : "";
12			badges[i].classList.toggle("rodin-nav-cart-badge--empty", !value);
13			badges[i].setAttribute("aria-hidden", value ? "false" : "true");
14		}
15
16		return value;
17	}
18
19	function getCookieCartCount() {
20		if (typeof frappe === "undefined" || typeof frappe.get_cookie !== "function") {
21			return 0;
22		}
23		return parseInt(frappe.get_cookie("cart_count") || "0", 10) || 0;
24	}
25
26	function syncCartCountFromCookie() {
27		try {
28			var sc = window.erpnext && erpnext.e_commerce && erpnext.e_commerce.shopping_cart;
29			if (sc && typeof sc.set_cart_count === "function") {
30				sc.set_cart_count(false);
31			}
32		} catch (e) {
33			console.warn("rodin_navbar_cart_sync:", e);
34		}
35
36		return renderCartCount(getCookieCartCount());
37	}
38
39	function refreshCartCount() {
40		if (typeof frappe === "undefined" || !frappe.session || frappe.session.user === "Guest") {
41			renderCartCount(0);
42			return;
43		}
44
45		if (typeof frappe.call !== "function") {
46			syncCartCountFromCookie();
47			return;
48		}
49
50		if (refreshInFlight) {
51			refreshQueued = true;
52			return;
53		}
54
55		refreshInFlight = true;
56		frappe.call({
57			method: "rodin_services.mvc.Components.rodin_navbar.controller.get_active_cart_count",
58			callback: function (response) {
59				if (response && response.message !== undefined && response.message !== null) {
60					renderCartCount(response.message);
61				} else {
62					syncCartCountFromCookie();
63				}
64			},
65			error: syncCartCountFromCookie,
66			always: function () {
67				refreshInFlight = false;
68				if (refreshQueued) {
69					refreshQueued = false;
70					refreshCartCount();
71				}
72			},
73		});
74	}
75
76	window.rodinGetCartCount = getCookieCartCount;
77	window.rodinSetCartCount = renderCartCount;
78	window.rodinRefreshCartCount = refreshCartCount;
79
80	if (typeof jQuery !== "undefined") {
81		jQuery(document).on("page-change rodin:cart-updated", refreshCartCount);
82	}
83
84	if (typeof frappe !== "undefined" && typeof frappe.ready === "function") {
85		frappe.ready(function () {
86			window.setTimeout(refreshCartCount, 0);
87		});
88	}
89
90	window.addEventListener("pageshow", function (event) {
91		if (event.persisted) {
92			refreshCartCount();
93		}
94	});
95})();

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.