Merge pull request #4730 from sttatusx/refactor-alert-js
Refactor alert js
This commit is contained in:
commit
74920c9f96
1 changed files with 18 additions and 27 deletions
|
@ -3,41 +3,32 @@ 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() {
|
|
||||||
// webOS seems to block modals
|
|
||||||
// Tizen 2.x seems to block modals
|
|
||||||
return !browser.web0s
|
|
||||||
&& !(browser.tizenVersion && browser.tizenVersion < 3)
|
|
||||||
&& browser.tv
|
|
||||||
&& window.alert;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async function (text, title) {
|
export default async function (text, title) {
|
||||||
let options;
|
// Modals seem to be blocked on Web OS and Tizen 2.x
|
||||||
if (typeof text === 'string') {
|
const canUseNativeAlert = !!(
|
||||||
options = {
|
!browser.web0s
|
||||||
title: title,
|
&& !(browser.tizenVersion && browser.tizenVersion < 3)
|
||||||
text: text
|
&& browser.tv
|
||||||
};
|
&& window.alert
|
||||||
} else {
|
);
|
||||||
options = text;
|
|
||||||
}
|
const options = typeof text === 'string' ? { title, text } : 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
options.buttons = [
|
||||||
|
{
|
||||||
name: globalize.translate('ButtonGotIt'),
|
name: globalize.translate('ButtonGotIt'),
|
||||||
id: 'ok',
|
id: 'ok',
|
||||||
type: 'submit'
|
type: 'submit'
|
||||||
});
|
}
|
||||||
|
];
|
||||||
|
|
||||||
options.buttons = items;
|
return dialog.show(options);
|
||||||
return dialog.show(options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue