mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Add helper function to export ts functions to html
This commit is contained in:
parent
3b1d06a71d
commit
b6e1c3bc88
@ -4,3 +4,17 @@ declare global {
|
|||||||
const Alpine: AlpineType;
|
const Alpine: AlpineType;
|
||||||
const gettext: (text: string) => string;
|
const gettext: (text: string) => string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function to export typescript functions to regular html and jinja files
|
||||||
|
* Without it, you either have to use the any keyword and suppress warnings or do a
|
||||||
|
* very painful type conversion workaround which is only here to please the linter
|
||||||
|
*
|
||||||
|
* This is only useful if you're using typescript, this is equivalent to doing
|
||||||
|
* window.yourFunction = yourFunction
|
||||||
|
**/
|
||||||
|
// biome-ignore lint/suspicious/noExplicitAny: Avoid strange tricks to export functions
|
||||||
|
export function exportToHtml(name: string, func: any) {
|
||||||
|
// biome-ignore lint/suspicious/noExplicitAny: Avoid strange tricks to export functions
|
||||||
|
(window as any)[name] = func;
|
||||||
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { makeUrl, paginated } from "#core:utils/api";
|
import { makeUrl, paginated } from "#core:utils/api";
|
||||||
|
import { exportToHtml } from "#core:utils/globals";
|
||||||
import { History } from "#core:utils/history";
|
import { History } from "#core:utils/history";
|
||||||
import {
|
import {
|
||||||
type AjaxResponse,
|
type AjaxResponse,
|
||||||
@ -97,8 +98,7 @@ interface ViewerConfig {
|
|||||||
/**
|
/**
|
||||||
* Load user picture page with a nice download bar
|
* Load user picture page with a nice download bar
|
||||||
**/
|
**/
|
||||||
(window as unknown as { loadViewer: (config: ViewerConfig) => undefined }).loadViewer =
|
exportToHtml("loadViewer", (config: ViewerConfig) => {
|
||||||
(config: ViewerConfig) => {
|
|
||||||
document.addEventListener("alpine:init", () => {
|
document.addEventListener("alpine:init", () => {
|
||||||
Alpine.data("picture_viewer", () => ({
|
Alpine.data("picture_viewer", () => ({
|
||||||
/**
|
/**
|
||||||
@ -227,11 +227,7 @@ interface ViewerConfig {
|
|||||||
);
|
);
|
||||||
this.pushstate = History.Push;
|
this.pushstate = History.Push;
|
||||||
} else {
|
} else {
|
||||||
window.history.pushState(
|
window.history.pushState(updateArgs.data, updateArgs.unused, updateArgs.url);
|
||||||
updateArgs.data,
|
|
||||||
updateArgs.unused,
|
|
||||||
updateArgs.url,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.moderationError = "";
|
this.moderationError = "";
|
||||||
@ -321,4 +317,4 @@ interface ViewerConfig {
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user