Update SpaccDotWeb.Alt: ShowModal, RequireScript
This commit is contained in:
parent
79925ffe53
commit
5487921ecb
|
@ -6,29 +6,36 @@
|
||||||
return SpaccDotWeb;
|
return SpaccDotWeb;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpaccDotWeb.Sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
SpaccDotWeb.Sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
SpaccDotWeb.RequireScript = (src, type) => {
|
SpaccDotWeb.RequireScript = (src, type) => {
|
||||||
const scriptElem = document.createElement('script');
|
return new Promise((resolve) => {
|
||||||
scriptElem.src = src;
|
const scriptElem = document.createElement('script');
|
||||||
document.body.appendChild(scriptElem);
|
//if (type) {
|
||||||
|
// scriptElem.type = type;
|
||||||
|
//}
|
||||||
|
scriptElem.onload = (event) => {
|
||||||
|
resolve(event);
|
||||||
|
};
|
||||||
|
scriptElem.src = src;
|
||||||
|
document.body.appendChild(scriptElem);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SpaccDotWeb.ShowModal = async (params) => {
|
SpaccDotWeb.ShowModal = async (params) => {
|
||||||
// TODO: delete dialogs from DOM after use (garbage collect)?
|
// TODO: delete dialogs from DOM after use (garbage collect)?
|
||||||
if (!window.HTMLDialogElement && !window.dialogPolyfill) {
|
if (!window.HTMLDialogElement && !window.dialogPolyfill) {
|
||||||
SpaccDotWeb.RequireScript('https://googlechrome.github.io/dialog-polyfill/dist/dialog-polyfill.js');
|
await SpaccDotWeb.RequireScript('https://googlechrome.github.io/dialog-polyfill/dist/dialog-polyfill.js');
|
||||||
}
|
|
||||||
while (!window.HTMLDialogElement && !window.dialogPolyfill) {
|
|
||||||
await SpaccDotWeb.Sleep(50);
|
|
||||||
}
|
}
|
||||||
let output;
|
let output;
|
||||||
if (typeof(params) === 'string') {
|
if (typeof(params) === 'string') {
|
||||||
params = { label: params }
|
params = { label: params }
|
||||||
}
|
}
|
||||||
|
//params.deleteOnClose ||= true;
|
||||||
const modal = document.createElement('dialog');
|
const modal = document.createElement('dialog');
|
||||||
|
const label = (params.label || params.text);
|
||||||
modal.innerHTML = `
|
modal.innerHTML = `
|
||||||
<p>${params.label || params.text || ''}</p>
|
${label ? `<p>${label}</p>` : ''}
|
||||||
${params.extraHTML || ''}
|
${params.extraHTML || ''}
|
||||||
<button name="cancel">🔙️ Cancel</button>
|
<button name="cancel">🔙️ Cancel</button>
|
||||||
`;
|
`;
|
||||||
|
|
Loading…
Reference in New Issue