From 333f0568b64c10ebe511237bd55d9313f5a440a1 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Fri, 27 Dec 2024 09:17:35 +0100 Subject: [PATCH] fix bootstrap 5 modal usage kudos @kanna5 --- js/privatebin.js | 88 +++++++++++++++++++++---------------------- lib/Configuration.php | 2 +- tpl/bootstrap5.php | 2 +- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index e34979ec..f88753b5 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -2237,8 +2237,8 @@ jQuery.PrivateBin = (function($, RawDeflate) { const me = {}; let $passwordDecrypt, - $passwordForm, $passwordModal, + bootstrap5PasswordModal = null, password = ''; /** @@ -2257,8 +2257,8 @@ jQuery.PrivateBin = (function($, RawDeflate) { password = $passwordDecrypt.val(); // hide modal - if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) { - (new bootstrap.Modal($passwordModal[0])).hide(); + if (bootstrap5PasswordModal) { + bootstrap5PasswordModal.hide(); } else { $passwordModal.modal('hide'); } @@ -2308,24 +2308,11 @@ jQuery.PrivateBin = (function($, RawDeflate) { { // show new bootstrap method (if available) if ($passwordModal.length !== 0) { - if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) { - (new bootstrap.Modal($passwordModal[0], { - backdrop: 'static', - keyboard: false - })).show(); + if (bootstrap5PasswordModal) { + bootstrap5PasswordModal.show(); } else { - $passwordModal.modal({ - backdrop: 'static', - keyboard: false - }); $passwordModal.modal('show'); } - // focus password input - $passwordDecrypt.focus(); - // then re-focus it, when modal causes it to loose focus again - setTimeout(function () { - $passwordDecrypt.focus(); - }, 500); return; } @@ -2369,7 +2356,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { // and also reset UI $passwordDecrypt.val(''); - } + }; /** * init status manager @@ -2382,11 +2369,26 @@ jQuery.PrivateBin = (function($, RawDeflate) { me.init = function() { $passwordDecrypt = $('#passworddecrypt'); - $passwordForm = $('#passwordform'); $passwordModal = $('#passwordmodal'); // bind events - handle Model password submission - $passwordForm.submit(submitPasswordModal); + if ($passwordModal.length !== 0) { + $('#passwordform').submit(submitPasswordModal); + + const disableClosingConfig = { + backdrop: 'static', + keyboard: false, + show: false + }; + if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) { + bootstrap5PasswordModal = new bootstrap.Modal($passwordModal[0], disableClosingConfig); + } else { + $passwordModal.modal(disableClosingConfig); + } + $passwordModal.on('shown.bs.modal', () => { + $passwordDecrypt.focus(); + }); + } }; return me; @@ -3985,10 +3987,6 @@ jQuery.PrivateBin = (function($, RawDeflate) { text: window.location.href }); $('#qrcode-display').html(qrCanvas); - // only necessary for bootstrap 5, other templates won't have this - if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) { - (new bootstrap.Modal('#qrcodemodal')).show(); - } } /** @@ -4077,32 +4075,34 @@ jQuery.PrivateBin = (function($, RawDeflate) { if (expirationDate !== null) { const $emailconfirmTimezoneCurrent = $emailconfirmmodal.find('#emailconfirm-timezone-current'); const $emailconfirmTimezoneUtc = $emailconfirmmodal.find('#emailconfirm-timezone-utc'); - $emailconfirmTimezoneCurrent.off('click.sendEmailCurrentTimezone'); - $emailconfirmTimezoneCurrent.on('click.sendEmailCurrentTimezone', () => { - const emailBody = templateEmailBody(expirationDateRoundedToSecond.toLocaleString(), isBurnafterreading); - if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) { - (new bootstrap.Modal($emailconfirmmodal[0])).hide(); + let localeConfiguration = { dateStyle: 'long', timeStyle: 'long' }; + const bootstrap5EmailConfirmModal = typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION ? + new bootstrap.Modal($emailconfirmmodal[0]) : null; + + function sendEmailAndHideModal() { + const emailBody = templateEmailBody( + // we don't use Date.prototype.toUTCString() because we would like to avoid GMT + expirationDateRoundedToSecond.toLocaleString( + [], localeConfiguration + ), isBurnafterreading + ); + if (bootstrap5EmailConfirmModal) { + bootstrap5EmailConfirmModal.hide(); } else { $emailconfirmmodal.modal('hide'); } triggerEmailSend(emailBody); - }); + }; + + $emailconfirmTimezoneCurrent.off('click.sendEmailCurrentTimezone'); + $emailconfirmTimezoneCurrent.on('click.sendEmailCurrentTimezone', sendEmailAndHideModal); $emailconfirmTimezoneUtc.off('click.sendEmailUtcTimezone'); $emailconfirmTimezoneUtc.on('click.sendEmailUtcTimezone', () => { - const emailBody = templateEmailBody(expirationDateRoundedToSecond.toLocaleString( - undefined, - // we don't use Date.prototype.toUTCString() because we would like to avoid GMT - { timeZone: 'UTC', dateStyle: 'long', timeStyle: 'long' } - ), isBurnafterreading); - if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) { - (new bootstrap.Modal($emailconfirmmodal[0])).hide(); - } else { - $emailconfirmmodal.modal('hide'); - } - triggerEmailSend(emailBody); + localeConfiguration.timeZone = 'UTC'; + sendEmailAndHideModal(); }); - if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) { - (new bootstrap.Modal($emailconfirmmodal[0])).show(); + if (bootstrap5EmailConfirmModal) { + bootstrap5EmailConfirmModal.show(); } else { $emailconfirmmodal.modal('show'); } diff --git a/lib/Configuration.php b/lib/Configuration.php index dc1fcb94..6bc95238 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -108,7 +108,7 @@ class Configuration 'js/kjua-0.9.0.js' => 'sha512-CVn7af+vTMBd9RjoS4QM5fpLFEOtBCoB0zPtaqIDC7sF4F8qgUSRFQQpIyEDGsr6yrjbuOLzdf20tkHHmpaqwQ==', 'js/legacy.js' => 'sha512-UxW/TOZKon83n6dk/09GsYKIyeO5LeBHokxyIq+r7KFS5KMBeIB/EM7NrkVYIezwZBaovnyNtY2d9tKFicRlXg==', 'js/prettify.js' => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==', - 'js/privatebin.js' => 'sha512-5JuYesxfZ0hS5Auqm5QkDsUy7ZzVabjcfS3zbVLfwkhJVt8ekzU5tYLbhaDTM+wmq3xwV+8N8krpp9fuF5kS3A==', + 'js/privatebin.js' => 'sha512-1RKY0XUEbDtZ6M4/YUwmLsav/qSzteqc/93jvEaH5mFLhCl8f+dItPy6Q8hUcydz10oyCYrB4DFSAtYfcaKZMg==', 'js/purify-3.1.7.js' => 'sha512-LegvqULiMtOfboJZw9MpETN/b+xnLRXZI90gG7oIFHW+yAeHmKvRtEUbiMFx2WvUqQoL9XB3gwU+hWXUT0X+8A==', 'js/rawinflate-0.3.js' => 'sha512-g8uelGgJW9A/Z1tB6Izxab++oj5kdD7B4qC7DHwZkB6DGMXKyzx7v5mvap2HXueI2IIn08YlRYM56jwWdm2ucQ==', 'js/showdown-2.1.0.js' => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==', diff --git a/tpl/bootstrap5.php b/tpl/bootstrap5.php index 4db055ca..d96aafb6 100644 --- a/tpl/bootstrap5.php +++ b/tpl/bootstrap5.php @@ -193,7 +193,7 @@ if ($EMAIL) : endif; if ($QRCODE) : ?> -