[TASK] Uses single-asset insertion when only one asset has been selected to be inserted

See #651.

Backported from master branch.

Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
Garvin Hicking 2019-10-17 13:14:00 +02:00 committed by Thomas Hochstein
parent d319ad16f1
commit a45c545ee3
2 changed files with 38 additions and 1 deletions

View File

@ -10,6 +10,12 @@ Version 2.3.3-beta1 ()
published blog entries and ability to prepend a mail body. published blog entries and ability to prepend a mail body.
Also fixes missing "keep strip tags" configuration option Also fixes missing "keep strip tags" configuration option
* #651: When using checkboxes to insert multiple media files, if only
one asset has been selected, do not use the gallery mode,
but instead single-asset view. Also improves to click the title
of an asset to select its checkbox, and hides the 'Insert all'
button when no assets are selected. (garvinhicking)
* Fix: [bbcode] Get roman numerals working in bbcode plugin. * Fix: [bbcode] Get roman numerals working in bbcode plugin.
Thanks to Fabien Chabreuil! Thanks to Fabien Chabreuil!

View File

@ -1387,8 +1387,39 @@ $(function() {
$('.multidelete, .multiinsert').click(function() { $('.multidelete, .multiinsert').click(function() {
var $el = $(this); var $el = $(this);
serendipity.highlightComment($el.attr('data-multidelid'), $el.attr('checked')); serendipity.highlightComment($el.attr('data-multidelid'), $el.attr('checked'));
var selectionAmount = $('.multidelete:checked, .multiinsert:checked').length;
if (selectionAmount > 0) {
$('#media_galleryinsert').fadeIn(); $('#media_galleryinsert').fadeIn();
} else {
$('#media_galleryinsert').fadeOut();
}
}); });
// Also marks checkbox when header is clicked
$('.media_file h3').on('click', function() {
$(this).parent().find('.multiinsert').click();
});
// When clicking the 'Insert all' button, check whether only one or multiple
// images are selected
$('#media_galleryinsert .image_insert').on('click', function(e) {
var selectionAmount = $('.multidelete:checked, .multiinsert:checked').length;
if (selectionAmount == 0) {
e.preventDefault();
return false;
}
// Actually do a single insert
if (selectionAmount == 1) {
e.preventDefault();
var actualTargetElement = $('.multidelete:checked, .multiinsert:checked').closest('.media_file').find('.media_file_preview a').first();
// This below is a hack. Triggering actualTargetElement.click() does not work. Probably because MFP overrides click events within a modal popup.
// So we need to do something dirty and directly access the location href. Don't tell my mom.
location.href = actualTargetElement.attr('href');
return false;
}
});
// hide gallery insert button until an image is selected // hide gallery insert button until an image is selected
$('#media_galleryinsert').hide(); $('#media_galleryinsert').hide();