mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-20 04:04:35 +00:00
Make public photo selection independent of gdThumb
This commit is contained in:
@@ -4,20 +4,69 @@
|
|||||||
var active = false;
|
var active = false;
|
||||||
var selected = {};
|
var selected = {};
|
||||||
|
|
||||||
function getThumbs() {
|
function candidateLinks() {
|
||||||
return $('#thumbnails .gdthumb');
|
return $('#thumbnails a[href], .thumbnails a[href]');
|
||||||
}
|
}
|
||||||
|
|
||||||
function imageIdFromThumb($thumb) {
|
function imageIdFromHref(href) {
|
||||||
var $link = $thumb.find('a[href]').first();
|
if (!href) {
|
||||||
var href = $link.attr('href') || '';
|
return 0;
|
||||||
var matches = href.match(/(?:image|picture)\/(\d+)|[?&](?:image_id|id)=(\d+)/i);
|
|
||||||
if (matches) {
|
|
||||||
return parseInt(matches[1] || matches[2], 10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var id = $thumb.data('image-id') || $thumb.attr('data-image-id');
|
var patterns = [
|
||||||
return id ? parseInt(id, 10) : 0;
|
/(?:^|\/)picture(?:\.php)?\?\/(\d+)(?:[-/]|$)/i,
|
||||||
|
/(?:^|\/)picture\/(\d+)(?:[-/]|$)/i,
|
||||||
|
/(?:^|\/)image\/(\d+)(?:[-/]|$)/i,
|
||||||
|
/[?&](?:image_id|image|picture_id|id)=(\d+)(?:&|$)/i
|
||||||
|
];
|
||||||
|
|
||||||
|
for (var i = 0; i < patterns.length; i++) {
|
||||||
|
var match = href.match(patterns[i]);
|
||||||
|
if (match) {
|
||||||
|
return parseInt(match[1], 10) || 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function imageIdFromLink($link) {
|
||||||
|
var direct = $link.attr('data-image-id') || $link.data('image-id');
|
||||||
|
if (direct) {
|
||||||
|
return parseInt(direct, 10) || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var $withId = $link.closest('[data-image-id]');
|
||||||
|
if ($withId.length) {
|
||||||
|
return parseInt($withId.attr('data-image-id'), 10) || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return imageIdFromHref($link.attr('href') || '');
|
||||||
|
}
|
||||||
|
|
||||||
|
function itemFromLink($link) {
|
||||||
|
// Prefer semantic list/card wrappers used by Piwigo themes and thumbnail
|
||||||
|
// plugins. gdThumb is only one supported markup, not a dependency.
|
||||||
|
var $item = $link.closest('li, .thumbnail, .thumbnailCategory, .gdthumb, .card');
|
||||||
|
return $item.length ? $item.first() : $link;
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectableLinks() {
|
||||||
|
return candidateLinks().filter(function () {
|
||||||
|
return imageIdFromLink($(this)) > 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshSelectableItems() {
|
||||||
|
selectableLinks().each(function () {
|
||||||
|
var $link = $(this);
|
||||||
|
var imageId = imageIdFromLink($link);
|
||||||
|
var $item = itemFromLink($link);
|
||||||
|
$item.addClass('bratonien-selectable').attr('data-bratonien-image-id', imageId);
|
||||||
|
if (selected[imageId]) {
|
||||||
|
$item.addClass('bratonien-selected');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateBar() {
|
function updateBar() {
|
||||||
@@ -31,6 +80,7 @@
|
|||||||
$('body').toggleClass('bratonien-selection-active', active);
|
$('body').toggleClass('bratonien-selection-active', active);
|
||||||
$('#bratonien-selection-bar').prop('hidden', !active);
|
$('#bratonien-selection-bar').prop('hidden', !active);
|
||||||
$('#bratonien-selection-toggle').toggleClass('active', active);
|
$('#bratonien-selection-toggle').toggleClass('active', active);
|
||||||
|
refreshSelectableItems();
|
||||||
if (!active) {
|
if (!active) {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
}
|
}
|
||||||
@@ -38,7 +88,7 @@
|
|||||||
|
|
||||||
function clearSelection() {
|
function clearSelection() {
|
||||||
selected = {};
|
selected = {};
|
||||||
getThumbs().removeClass('bratonien-selected');
|
$('.bratonien-selectable').removeClass('bratonien-selected');
|
||||||
updateBar();
|
updateBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,26 +97,27 @@
|
|||||||
setActive(!active);
|
setActive(!active);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', '#thumbnails .gdthumb a', function (e) {
|
$(document).on('click', '#thumbnails a[href], .thumbnails a[href]', function (e) {
|
||||||
if (!active) {
|
if (!active) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var $link = $(this);
|
||||||
|
var imageId = imageIdFromLink($link);
|
||||||
|
if (!imageId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
var $thumb = $(this).closest('.gdthumb');
|
var $item = itemFromLink($link);
|
||||||
var imageId = imageIdFromThumb($thumb);
|
|
||||||
if (!imageId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selected[imageId]) {
|
if (selected[imageId]) {
|
||||||
delete selected[imageId];
|
delete selected[imageId];
|
||||||
$thumb.removeClass('bratonien-selected');
|
$item.removeClass('bratonien-selected');
|
||||||
} else {
|
} else {
|
||||||
selected[imageId] = true;
|
selected[imageId] = true;
|
||||||
$thumb.addClass('bratonien-selected');
|
$item.addClass('bratonien-selected');
|
||||||
}
|
}
|
||||||
updateBar();
|
updateBar();
|
||||||
});
|
});
|
||||||
@@ -84,4 +135,12 @@
|
|||||||
var separator = window.BratonienSelectionConfig.downloadUrl.indexOf('?') === -1 ? '?' : '&';
|
var separator = window.BratonienSelectionConfig.downloadUrl.indexOf('?') === -1 ? '?' : '&';
|
||||||
window.location.href = window.BratonienSelectionConfig.downloadUrl + separator + 'bratonien_selection=' + encodeURIComponent(ids.join(','));
|
window.location.href = window.BratonienSelectionConfig.downloadUrl + separator + 'bratonien_selection=' + encodeURIComponent(ids.join(','));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Some plugins append thumbnails after the initial page render. Refresh the
|
||||||
|
// markers without depending on any particular thumbnail implementation.
|
||||||
|
$(document).ajaxComplete(function () {
|
||||||
|
if (active) {
|
||||||
|
refreshSelectableItems();
|
||||||
|
}
|
||||||
|
});
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
|||||||
Reference in New Issue
Block a user