replicate template changes, fix bugs

- fixes QR code height introducing space even when hidden in page layout
- fix modals in bootstrap 5 (modal syntax changed heavily, no longer jQuery integrated)
- hide and show tab-toggle depending on application state
- don't encode HTML entities in translated messages containing kbd tags (in addition to links)
This commit is contained in:
El RIDO 2024-11-24 15:42:38 +01:00
parent 9028ddbb97
commit c7195aaf9a
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
9 changed files with 84 additions and 26 deletions

View File

@ -18,6 +18,10 @@
--bs-dropdown-min-width: 23rem; --bs-dropdown-min-width: 23rem;
} }
pre {
margin-bottom: 0;
}
[data-bs-theme=light] pre, [data-bs-theme=light] .card { [data-bs-theme=light] pre, [data-bs-theme=light] .card {
background-color: RGBA(var(--bs-light-rgb), var(--bs-bg-opacity, 1)); background-color: RGBA(var(--bs-light-rgb), var(--bs-bg-opacity, 1));
} }

View File

@ -53,7 +53,6 @@
#qrcode-display { #qrcode-display {
width: 200px; width: 200px;
height: 200px;
margin: auto; margin: auto;
} }

View File

@ -125,7 +125,7 @@ h3.title {
#pasteresult button { margin-left: 11px; } #pasteresult button { margin-left: 11px; }
#toolbar, #status { margin-bottom: 5px; } #message, #plaintext, #prettymessage, #toolbar, #status { margin-bottom: 5px; }
#copyhint { color: #666; font-size: 0.85em } #copyhint { color: #666; font-size: 0.85em }

View File

@ -2257,7 +2257,11 @@ jQuery.PrivateBin = (function($, RawDeflate) {
password = $passwordDecrypt.val(); password = $passwordDecrypt.val();
// hide modal // hide modal
if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) {
(new bootstrap.Modal($passwordModal[0])).hide();
} else {
$passwordModal.modal('hide'); $passwordModal.modal('hide');
}
PasteDecrypter.run(); PasteDecrypter.run();
} }
@ -2278,7 +2282,11 @@ jQuery.PrivateBin = (function($, RawDeflate) {
const $loadconfirmClose = $loadconfirmmodal.find('.close'); const $loadconfirmClose = $loadconfirmmodal.find('.close');
$loadconfirmClose.off('click.close'); $loadconfirmClose.off('click.close');
$loadconfirmClose.on('click.close', Controller.newPaste); $loadconfirmClose.on('click.close', Controller.newPaste);
if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) {
(new bootstrap.Modal($loadconfirmmodal[0])).show();
} else {
$loadconfirmmodal.modal('show'); $loadconfirmmodal.modal('show');
}
} else { } else {
if (window.confirm( if (window.confirm(
I18n._('This secret message can only be displayed once. Would you like to see it now?') I18n._('This secret message can only be displayed once. Would you like to see it now?')
@ -2300,11 +2308,18 @@ jQuery.PrivateBin = (function($, RawDeflate) {
{ {
// show new bootstrap method (if available) // show new bootstrap method (if available)
if ($passwordModal.length !== 0) { if ($passwordModal.length !== 0) {
if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) {
(new bootstrap.Modal($passwordModal[0]), {
backdrop: 'static',
keyboard: false
}).show();
} else {
$passwordModal.modal({ $passwordModal.modal({
backdrop: 'static', backdrop: 'static',
keyboard: false keyboard: false
}); });
$passwordModal.modal('show'); $passwordModal.modal('show');
}
// focus password input // focus password input
$passwordDecrypt.focus(); $passwordDecrypt.focus();
// then re-focus it, when modal causes it to loose focus again // then re-focus it, when modal causes it to loose focus again
@ -2393,6 +2408,8 @@ jQuery.PrivateBin = (function($, RawDeflate) {
$messageEditParent, $messageEditParent,
$messagePreview, $messagePreview,
$messagePreviewParent, $messagePreviewParent,
$messageTab,
$messageTabParent,
$message, $message,
isPreview = false, isPreview = false,
isTabSupported = true; isTabSupported = true;
@ -2410,7 +2427,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
// support disabling tab support using [Esc] and [Ctrl]+[m] // support disabling tab support using [Esc] and [Ctrl]+[m]
if (event.key === 'Escape' || (event.ctrlKey && event.key === 'm')) { if (event.key === 'Escape' || (event.ctrlKey && event.key === 'm')) {
toggleTabSupport(); toggleTabSupport();
document.getElementById('message-tab').checked = isTabSupported; $messageTab[0].checked = isTabSupported;
event.preventDefault(); event.preventDefault();
} }
// tab was pressed // tab was pressed
@ -2462,6 +2479,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
// reshow input // reshow input
$message.removeClass('hidden'); $message.removeClass('hidden');
$messageTabParent.removeClass('hidden');
me.focusInput(); me.focusInput();
@ -2494,6 +2512,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
// hide input as now preview is shown // hide input as now preview is shown
$message.addClass('hidden'); $message.addClass('hidden');
$messageTabParent.addClass('hidden');
// show preview // show preview
PasteViewer.setText($message.val()); PasteViewer.setText($message.val());
@ -2552,6 +2571,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
me.show = function() me.show = function()
{ {
$message.removeClass('hidden'); $message.removeClass('hidden');
$messageTabParent.removeClass('hidden');
$editorTabs.removeClass('hidden'); $editorTabs.removeClass('hidden');
}; };
@ -2564,6 +2584,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
me.hide = function() me.hide = function()
{ {
$message.addClass('hidden'); $message.addClass('hidden');
$messageTabParent.addClass('hidden');
$editorTabs.addClass('hidden'); $editorTabs.addClass('hidden');
}; };
@ -2603,7 +2624,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
}; };
/** /**
* init status manager * init editor
* *
* preloads jQuery elements * preloads jQuery elements
* *
@ -2614,10 +2635,12 @@ jQuery.PrivateBin = (function($, RawDeflate) {
{ {
$editorTabs = $('#editorTabs'); $editorTabs = $('#editorTabs');
$message = $('#message'); $message = $('#message');
$messageTab = $('#messagetab');
$messageTabParent = $messageTab.parent();
// bind events // bind events
$message.keydown(supportTabs); $message.keydown(supportTabs);
$('#message-tab').change(toggleTabSupport); $messageTab.change(toggleTabSupport);
// bind click events to tab switchers (a), and save parents (li) // bind click events to tab switchers (a), and save parents (li)
$messageEdit = $('#messageedit').click(viewEditor); $messageEdit = $('#messageedit').click(viewEditor);
@ -2638,7 +2661,8 @@ jQuery.PrivateBin = (function($, RawDeflate) {
const PasteViewer = (function () { const PasteViewer = (function () {
const me = {}; const me = {};
let $placeholder, let $messageTabParent,
$placeholder,
$prettyMessage, $prettyMessage,
$prettyPrint, $prettyPrint,
$plainText, $plainText,
@ -2718,6 +2742,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
} }
// otherwise hide the placeholder // otherwise hide the placeholder
$placeholder.addClass('hidden'); $placeholder.addClass('hidden');
$messageTabParent.addClass('hidden');
if (format === 'markdown') { if (format === 'markdown') {
$plainText.removeClass('hidden'); $plainText.removeClass('hidden');
@ -2856,6 +2881,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
*/ */
me.init = function() me.init = function()
{ {
$messageTabParent = $('#messagetab').parent();
$placeholder = $('#placeholder'); $placeholder = $('#placeholder');
$plainText = $('#plaintext'); $plainText = $('#plaintext');
$prettyMessage = $('#prettymessage'); $prettyMessage = $('#prettymessage');
@ -3960,8 +3986,8 @@ jQuery.PrivateBin = (function($, RawDeflate) {
}); });
$('#qrcode-display').html(qrCanvas); $('#qrcode-display').html(qrCanvas);
// only necessary for bootstrap 5, other templates won't have this // only necessary for bootstrap 5, other templates won't have this
if (bootstrap.Tooltip.VERSION) { if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) {
$('#qrcodemodal').modal('show'); (new bootstrap.Modal('#qrcodemodal')).show();
} }
} }
@ -4054,7 +4080,11 @@ jQuery.PrivateBin = (function($, RawDeflate) {
$emailconfirmTimezoneCurrent.off('click.sendEmailCurrentTimezone'); $emailconfirmTimezoneCurrent.off('click.sendEmailCurrentTimezone');
$emailconfirmTimezoneCurrent.on('click.sendEmailCurrentTimezone', () => { $emailconfirmTimezoneCurrent.on('click.sendEmailCurrentTimezone', () => {
const emailBody = templateEmailBody(expirationDateRoundedToSecond.toLocaleString(), isBurnafterreading); const emailBody = templateEmailBody(expirationDateRoundedToSecond.toLocaleString(), isBurnafterreading);
if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) {
(new bootstrap.Modal($emailconfirmmodal[0])).hide();
} else {
$emailconfirmmodal.modal('hide'); $emailconfirmmodal.modal('hide');
}
triggerEmailSend(emailBody); triggerEmailSend(emailBody);
}); });
$emailconfirmTimezoneUtc.off('click.sendEmailUtcTimezone'); $emailconfirmTimezoneUtc.off('click.sendEmailUtcTimezone');
@ -4064,10 +4094,18 @@ jQuery.PrivateBin = (function($, RawDeflate) {
// we don't use Date.prototype.toUTCString() because we would like to avoid GMT // we don't use Date.prototype.toUTCString() because we would like to avoid GMT
{ timeZone: 'UTC', dateStyle: 'long', timeStyle: 'long' } { timeZone: 'UTC', dateStyle: 'long', timeStyle: 'long' }
), isBurnafterreading); ), isBurnafterreading);
if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) {
(new bootstrap.Modal($emailconfirmmodal[0])).hide();
} else {
$emailconfirmmodal.modal('hide'); $emailconfirmmodal.modal('hide');
}
triggerEmailSend(emailBody); triggerEmailSend(emailBody);
}); });
if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip.VERSION) {
(new bootstrap.Modal($emailconfirmmodal[0])).show();
} else {
$emailconfirmmodal.modal('show'); $emailconfirmmodal.modal('show');
}
} else { } else {
triggerEmailSend(templateEmailBody(null, isBurnafterreading)); triggerEmailSend(templateEmailBody(null, isBurnafterreading));
} }

View File

@ -108,7 +108,7 @@ class Configuration
'js/kjua-0.9.0.js' => 'sha512-CVn7af+vTMBd9RjoS4QM5fpLFEOtBCoB0zPtaqIDC7sF4F8qgUSRFQQpIyEDGsr6yrjbuOLzdf20tkHHmpaqwQ==', 'js/kjua-0.9.0.js' => 'sha512-CVn7af+vTMBd9RjoS4QM5fpLFEOtBCoB0zPtaqIDC7sF4F8qgUSRFQQpIyEDGsr6yrjbuOLzdf20tkHHmpaqwQ==',
'js/legacy.js' => 'sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==', 'js/legacy.js' => 'sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==',
'js/prettify.js' => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==', 'js/prettify.js' => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==',
'js/privatebin.js' => 'sha512-Tit/JkrOoSGSvbDmnWmvK7utnjzHaErYPRrQYlGf0PEQZPYWFVYCKkV+HkNJzFXAXKWqqpA8b16TU38R/wgpRg==', 'js/privatebin.js' => 'sha512-rbfSVRLvLB7zcmnDGOopePCL0BUEDH10Yd1sZig/l44MaxQGcMaAG/T5Zeln3it/0LxMOIujZV/By+0ShhwysQ==',
'js/purify-3.1.7.js' => 'sha512-LegvqULiMtOfboJZw9MpETN/b+xnLRXZI90gG7oIFHW+yAeHmKvRtEUbiMFx2WvUqQoL9XB3gwU+hWXUT0X+8A==', 'js/purify-3.1.7.js' => 'sha512-LegvqULiMtOfboJZw9MpETN/b+xnLRXZI90gG7oIFHW+yAeHmKvRtEUbiMFx2WvUqQoL9XB3gwU+hWXUT0X+8A==',
'js/rawinflate-0.3.js' => 'sha512-g8uelGgJW9A/Z1tB6Izxab++oj5kdD7B4qC7DHwZkB6DGMXKyzx7v5mvap2HXueI2IIn08YlRYM56jwWdm2ucQ==', 'js/rawinflate-0.3.js' => 'sha512-g8uelGgJW9A/Z1tB6Izxab++oj5kdD7B4qC7DHwZkB6DGMXKyzx7v5mvap2HXueI2IIn08YlRYM56jwWdm2ucQ==',
'js/showdown-2.1.0.js' => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==', 'js/showdown-2.1.0.js' => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==',

View File

@ -127,12 +127,19 @@ class I18n
} else { } else {
$args[0] = self::$_translations[$messageId]; $args[0] = self::$_translations[$messageId];
} }
// encode any non-integer arguments and the message ID, if it doesn't contain a link // encode any non-integer arguments and the message ID, if it doesn't contain a link or keyboard input
$argsCount = count($args); $argsCount = count($args);
for ($i = 0; $i < $argsCount; ++$i) { for ($i = 0; $i < $argsCount; ++$i) {
if ($i > 0 ? !is_int($args[$i]) : strpos($args[0], '<a') === false) { if ($i === 0) {
$args[$i] = self::encode($args[$i]); if (strpos($args[0], '<a') !== false || strpos($args[0], '<kbd>') !== false) {
continue;
} }
} else {
if (is_int($args[$i])) {
continue;
}
}
$args[$i] = self::encode($args[$i]);
} }
return call_user_func_array('sprintf', $args); return call_user_func_array('sprintf', $args);
} }

View File

@ -584,6 +584,12 @@ endif;
</div> </div>
<div id="plaintext" class="col-md-12 hidden"></div> <div id="plaintext" class="col-md-12 hidden"></div>
<p class="col-md-12"><textarea id="message" name="message" cols="80" rows="25" class="form-control hidden"></textarea></p> <p class="col-md-12"><textarea id="message" name="message" cols="80" rows="25" class="form-control hidden"></textarea></p>
<p class="col-md-12 checkbox">
<label>
<input id="messagetab" type="checkbox" checked="checked" />
<?php echo I18n::_('Tabulator key serves as character (Hit <kbd>Ctrl</kbd>+<kbd>m</kbd> or <kbd>Esc</kbd> to toggle)'), PHP_EOL; ?>
</label>
</p>
</article> </article>
</section> </section>
<section class="container"> <section class="container">

View File

@ -440,10 +440,10 @@ endif;
</div> </div>
<div id="plaintext" class="col-md-12 hidden"></div> <div id="plaintext" class="col-md-12 hidden"></div>
<p class="col-md-12"><textarea id="message" name="message" cols="80" rows="25" aria-label="<?php echo I18n::_('Paste text'); ?>" class="form-control hidden"></textarea></p> <p class="col-md-12"><textarea id="message" name="message" cols="80" rows="25" aria-label="<?php echo I18n::_('Paste text'); ?>" class="form-control hidden"></textarea></p>
<p class="col-md-12" id="message-controls"> <p class="col-md-12 form-check form-switch">
<input id="message-tab" type="checkbox" class="form-check-input" checked="checked" /> <input id="messagetab" type="checkbox" class="form-check-input" checked="checked" />
<label for="message-tab" class="form-check-label"> <label for="messagetab" class="form-check-label">
<?php echo I18n::_('Tabulator key serves as character (Hit <kbd>Ctrl</kbd>+<kbd>m</kbd> or <kbd>Esc</kbd> to toggle)'); ?> <?php echo I18n::_('Tabulator key serves as character (Hit <kbd>Ctrl</kbd>+<kbd>m</kbd> or <kbd>Esc</kbd> to toggle)'), PHP_EOL; ?>
</label> </label>
</p> </p>
</article> </article>

View File

@ -264,6 +264,10 @@ endif;
</div> </div>
<div id="plaintext" class="hidden"></div> <div id="plaintext" class="hidden"></div>
<textarea id="message" name="message" cols="80" rows="25" class="hidden"></textarea> <textarea id="message" name="message" cols="80" rows="25" class="hidden"></textarea>
<div class="button">
<input id="messagetab" type="checkbox" checked="checked" />
<label for="messagetab"><?php echo I18n::_('Tabulator key serves as character (Hit <kbd>Ctrl</kbd>+<kbd>m</kbd> or <kbd>Esc</kbd> to toggle)'); ?></label>
</div>
</article> </article>
</section> </section>
<section> <section>