diff options
| author | Arpit Chakladar <arpitchakladar+git@gmail.com> | 2026-07-13 11:35:08 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar+git@gmail.com> | 2026-07-13 11:35:08 +0530 |
| commit | 600c337b1cdc884aebf59083eb57b178b43441ce (patch) | |
| tree | d1f3cb7eb1020bcdcd66d9dbf0279f79d5856332 /src/shared/intercept-jquery-ajax.ts | |
| parent | 98e7019c61ea0ffe344ef7ce809d38d62254a9fc (diff) | |
| download | banglar-bhumi-utils-600c337b1cdc884aebf59083eb57b178b43441ce.tar.gz banglar-bhumi-utils-600c337b1cdc884aebf59083eb57b178b43441ce.zip | |
docs: added some documentation comments to all functions
Diffstat (limited to 'src/shared/intercept-jquery-ajax.ts')
| -rw-r--r-- | src/shared/intercept-jquery-ajax.ts | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/shared/intercept-jquery-ajax.ts b/src/shared/intercept-jquery-ajax.ts index a77dd44..7e1f54e 100644 --- a/src/shared/intercept-jquery-ajax.ts +++ b/src/shared/intercept-jquery-ajax.ts @@ -8,10 +8,15 @@ interface InterceptJqueryEntry { const postIntercepts: InterceptJqueryEntry[] = []; const getIntercepts: InterceptJqueryEntry[] = []; +/** + * On DOMContentLoaded, proxies jQuery's `$.post` and `$.get` so that + * registered interceptors are called before the real request. + */ document.addEventListener("DOMContentLoaded", () => { const proxiedPost = $.post; const proxiedGet = $.get; + /** Proxied `$.post` that invokes registered interceptors before the real call. */ $.post = function() { for (const { url, callback } of postIntercepts) { if (arguments[0].endsWith(url)) { @@ -21,6 +26,7 @@ document.addEventListener("DOMContentLoaded", () => { return proxiedPost.apply(this, Array.from(arguments) as any); }; + /** Proxied `$.get` that invokes registered interceptors before the real call. */ $.get = function() { for (const { url, callback } of getIntercepts) { if (arguments[0].endsWith(url)) { @@ -32,10 +38,24 @@ document.addEventListener("DOMContentLoaded", () => { }; }); +/** + * Registers a callback that fires whenever a jQuery POST request matches + * the given URL suffix. + * + * @param url - The URL suffix to match (checked via `endsWith`). + * @param callback - Receives the original `arguments` from `$.post`. + */ export function interceptPost(url: string, callback: InterceptJqueryAjaxCallback) { postIntercepts.push({ url, callback }); }; +/** + * Registers a callback that fires whenever a jQuery GET request matches + * the given URL suffix. + * + * @param url - The URL suffix to match (checked via `endsWith`). + * @param callback - Receives the original `arguments` from `$.get`. + */ export function interceptGet(url: string, callback: InterceptJqueryAjaxCallback) { getIntercepts.push({ url, callback }); }; |
