Skip to content

Commit

Permalink
netteForms: uses <dialog> in Opera & mobile Chromium because it loses…
Browse files Browse the repository at this point in the history
… focus after alert() [Closes #275]
  • Loading branch information
dg committed Aug 25, 2021
1 parent 5ba98cc commit 7ceac59
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,31 @@
* 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 } .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();
return;
}

alert(message);
onclose();
};
Expand Down

0 comments on commit 7ceac59

Please sign in to comment.