blob: 508d0760a239c2f3ac16148ab7c07d46d36e9600 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import { addPostListener, addPostResponder, JQueryAjaxResponse } from "@/shared/intercept-jquery-ajax";
/** Caches the login area HTML to avoid re-fetching it on subsequent requests. */
let loginAreaHTML: string | null = null;
/**
* Intercepts `viewLoginAreaAction` AJAX requests and serves the cached HTML
* if available, avoiding an unnecessary network round-trip.
*/
addPostResponder(
"viewLoginAreaAction",
function(_args): JQueryAjaxResponse | undefined | null {
return loginAreaHTML
? {
data: loginAreaHTML
}
: null;
}
);
/**
* Listens for successful `viewLoginAreaAction` responses and stores the
* returned HTML so the responder above can serve it from cache later.
*/
addPostListener(
"viewLoginAreaAction",
function(_args, result): void {
loginAreaHTML = result.data?.toString() ?? null;
},
false
);
|