Compare commits

..

2 Commits

Author SHA1 Message Date
buttle 16c745ce4c adds source link to each image 2021-10-14 14:20:51 +02:00
buttle 7bb9c659ff improves function to fetch large media 2021-10-14 13:34:25 +02:00
2 changed files with 28 additions and 27 deletions

View File

@ -91,11 +91,13 @@ class SmartGallery extends AbstractBlockLayout
$mediaType = $media->mediaType(); $mediaType = $media->mediaType();
$mediaRenderer = $media->renderer(); $mediaRenderer = $media->renderer();
if (strpos($mediaType, 'image/') !== false) { if (strpos($mediaType, 'image/') !== false) {
$new_url = $media->originalUrl(); $thumbs = $media->thumbnailUrls();
// original files size may be very large. /large/<name>.jpg is smaller if (isset($thumbs['large'])) {
$new_url = substr_replace($new_url, 'jpg', strrpos($new_url, '.') +1); $media_url = $thumbs['large'];
$new_url = str_replace("original", "large", $new_url); } else {
array_push($images, ["media_url" => $new_url, $media_url = $media->originalUrl();
}
array_push($images, ["media_url" => $media_url,
"item_url" => $attachment->item()->url(), "item_url" => $attachment->item()->url(),
"image_title" => $media->title(), "image_title" => $media->title(),
"img_id" => 'gi_' . $gallery_id . '_' . $img_id, "img_id" => 'gi_' . $gallery_id . '_' . $img_id,

View File

@ -6,21 +6,16 @@ $this->headLink()->appendStylesheet($this->assetUrl('css/style.css',
?> ?>
<!-- <style>
<script> .sg_src_link {
console.log(<?= json_encode($images, JSON_UNESCAPED_SLASHES) ?>) font-size: 0.70em;
</script> }
--> </style>
<?php $image_id = 0; ?> <?php $image_id = 0; ?>
<div class="archive-item-block smart-gallery"> <div id="<?= $gallery_id ?>_wrap"
class="archive-item-block smart-gallery">
<?php if ($renderSourceLink) { ?>
<div class="source-link">
<a href="<?= $item_url ?>">Source</a>
</div>
<?php } ?>
<div class="wrapper"> <div class="wrapper">
<div class="masonry"> <div class="masonry">
@ -59,16 +54,20 @@ echo $this->inlineScript()
<script> <script>
jQuery(document).ready(function() { jQuery(document).ready(function() {
$(function(){
$(".<?= $gallery_id ?>").SmartPhoto({ $(".<?= $gallery_id ?>").SmartPhoto({
resizeStyle: 'fit', resizeStyle: 'fit',
}); });
}); <?php if ($renderSourceLink) { ?>
var images_<?= $gallery_id ?> = <?= json_encode($images, JSON_UNESCAPED_SLASHES) ?>;
for (let i in images_<?= $gallery_id ?>) {
var image = images_<?= $gallery_id ?>[i]
var src_link = '<div class="sg_src_link"><a href="'+image['item_url']+'">Source</a></div>';
var gallery_image = $('#<?= $gallery_id ?>_wrap').find('img[src="'+image['media_url']+'"]')
if ( !($(gallery_image).next().attr('src') == image['media_url']) ){
$(gallery_image).closest('.brick').append(src_link)
console.log(image['media_url'])
}
}
<?php } ?>
}); });
function updateSourceURL(thumbnail){
$(thumbnail).closest(".archive-gallery")
.find('.source-link')
.find('a').prop('href', $(thumbnail).attr('item_url'));
}
</script> </script>