Refactor alert module
This commit is contained in:
parent
24fad10f36
commit
0a878bfbcd
1 changed files with 15 additions and 24 deletions
|
@ -3,43 +3,34 @@ import browser from "../scripts/browser";
|
||||||
import dialog from "./dialog/dialog";
|
import dialog from "./dialog/dialog";
|
||||||
import globalize from "../scripts/globalize";
|
import globalize from "../scripts/globalize";
|
||||||
|
|
||||||
function useNativeAlert() {
|
export default async function (text, title) {
|
||||||
// webOS seems to block modals
|
// Modals seem to be blocked on Web OS and Tizen 2.x
|
||||||
// Tizen 2.x seems to block modals
|
const canUseNativeAlert = !!(
|
||||||
return (
|
|
||||||
!browser.web0s &&
|
!browser.web0s &&
|
||||||
!(browser.tizenVersion && browser.tizenVersion < 3) &&
|
!(browser.tizenVersion && browser.tizenVersion < 3) &&
|
||||||
browser.tv &&
|
browser.tv &&
|
||||||
window.alert
|
window.alert
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
export default async function (text, title) {
|
let options = typeof text === "string" ? { title, text } : text;
|
||||||
let options;
|
|
||||||
if (typeof text === "string") {
|
|
||||||
options = {
|
|
||||||
title: title,
|
|
||||||
text: text,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
options = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
await appRouter.ready();
|
await appRouter.ready();
|
||||||
|
|
||||||
if (useNativeAlert()) {
|
if (canUseNativeAlert) {
|
||||||
alert((options.text || "").replaceAll("<br/>", "\n"));
|
alert((options.text || "").replaceAll("<br/>", "\n"));
|
||||||
return Promise.resolve();
|
|
||||||
} else {
|
|
||||||
const items = [];
|
|
||||||
|
|
||||||
items.push({
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
const items = [
|
||||||
|
{
|
||||||
name: globalize.translate("ButtonGotIt"),
|
name: globalize.translate("ButtonGotIt"),
|
||||||
id: "ok",
|
id: "ok",
|
||||||
type: "submit",
|
type: "submit",
|
||||||
});
|
},
|
||||||
|
];
|
||||||
|
|
||||||
options.buttons = items;
|
options.buttons = items;
|
||||||
return dialog.show(options);
|
|
||||||
}
|
return dialog.show(options);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue