Skip to content

Commit

Permalink
netteForms: showModal uses <dialog> by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 13, 2022
1 parent fb31845 commit 9c70c15
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,33 +307,30 @@
* Display modal window.
*/
Nette.showModal = function(message, onclose) {
var dialog = document.createElement('dialog'),
ua = navigator.userAgentData;

if (ua && dialog.showModal
&& ua.brands.some(function(item) { return item.brand === 'Opera' || (item.brand === 'Chromium' && ua.mobile); })
) {
var style = document.createElement('style');
style.innerText = '.netteFormsModal { text-align: center; margin: auto; border: 2px solid black; padding: 1rem } .netteFormsModal button { padding: .1em 2em }';

var button = document.createElement('button');
button.innerText = 'OK';
button.onclick = function () {
dialog.remove();
onclose();
};
var dialog = document.createElement('dialog');

dialog.setAttribute('class', 'netteFormsModal');
dialog.innerText = message + '\n\n';
dialog.appendChild(style);
dialog.appendChild(button);
document.body.appendChild(dialog);
dialog.showModal();
if (!dialog.showModal) {
alert(message);
onclose();
return;
}

alert(message);
onclose();
var style = document.createElement('style');
style.innerText = '.netteFormsModal { text-align: center; margin: auto; border: 2px solid black; padding: 1rem } .netteFormsModal button { padding: .1em 2em }';

var button = document.createElement('button');
button.innerText = 'OK';
button.onclick = function () {
dialog.remove();
onclose();
};

dialog.setAttribute('class', 'netteFormsModal');
dialog.innerText = message + '\n\n';
dialog.appendChild(style);
dialog.appendChild(button);
document.body.appendChild(dialog);
dialog.showModal();
};


Expand Down

0 comments on commit 9c70c15

Please sign in to comment.