mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
b902edc1be
t-out automatically escaped content when it is a string not marked with the `markup` function t-out renders the raw content if it is a Block, or if it has been marked with the `markup` funtion. t-esc has been kept since it is safe and is optimized to render text nodes. all t-raw calls are in fact the same as t-out.
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
export class EventBus extends EventTarget {
|
|
trigger(name: string, payload?: any) {
|
|
this.dispatchEvent(new CustomEvent(name, { detail: payload }));
|
|
}
|
|
}
|
|
|
|
export function whenReady(fn?: any): Promise<void> {
|
|
return new Promise(function (resolve) {
|
|
if (document.readyState !== "loading") {
|
|
resolve(true);
|
|
} else {
|
|
document.addEventListener("DOMContentLoaded", resolve, false);
|
|
}
|
|
}).then(fn || function () {});
|
|
}
|
|
|
|
export async function loadFile(url: string): Promise<string> {
|
|
const result = await fetch(url);
|
|
if (!result.ok) {
|
|
throw new Error("Error while fetching xml templates");
|
|
}
|
|
return await result.text();
|
|
}
|
|
|
|
/*
|
|
* This class just transports the fact that a string is safe
|
|
* to be injected as HTML. Overriding a JS primitive is quite painful though
|
|
* so we need to redfine toString and valueOf.
|
|
*/
|
|
export class Markup extends String {}
|
|
|
|
/*
|
|
* Marks a value as safe, that is, a value that can be injected as HTML directly.
|
|
* It should be used to wrap the value passed to a t-out directive to allow a raw rendering.
|
|
*/
|
|
export function markup(value: any) {
|
|
return new Markup(value);
|
|
}
|