dynamically loads item url in source link

closes #2
This commit is contained in:
buttle 2021-06-28 15:48:32 +02:00
parent 622523a791
commit bf1cf9ce70
2 changed files with 37 additions and 12 deletions

View File

@ -76,7 +76,8 @@ class Carousel extends AbstractBlockLayout
return ''; return '';
} }
$urls = []; static $id = 0;
$images = [];
foreach ($attachments as $attachment) foreach ($attachments as $attachment)
{ {
@ -85,26 +86,27 @@ class Carousel extends AbstractBlockLayout
$mediaType = $media->mediaType(); $mediaType = $media->mediaType();
$mediaRenderer = $media->renderer(); $mediaRenderer = $media->renderer();
if ((strpos($mediaType, 'image/') !== false) || (strpos($mediaRenderer, 'youtube') !== false)) { if ((strpos($mediaType, 'image/') !== false) || (strpos($mediaRenderer, 'youtube') !== false)) {
array_push($urls, $media->thumbnailUrl('large')); array_push($images, ["media_url" => $media->originalUrl(),
"item_url" => $attachment->item()->url()
]);
} }
} }
} }
return $view->partial('common/block-layout/simple-carousel', [ return $view->partial('common/block-layout/simple-carousel', [
'carousel_id' => 'ic_' . ++$id,
'height' => $block->dataValue('height'), 'height' => $block->dataValue('height'),
'duration' => $block->dataValue('duration'), 'duration' => $block->dataValue('duration'),
'perPage' => $block->dataValue('perPage'), 'perPage' => $block->dataValue('perPage'),
'loop' => $block->dataValue('loop'), 'loop' => $block->dataValue('loop'),
'draggable' => $block->dataValue('draggable'), 'draggable' => $block->dataValue('draggable'),
'subTitle' => $block->dataValue('subTitle'), 'subTitle' => $block->dataValue('subTitle'),
'urls' => $urls, 'images' => $images,
'autoSlide' => $block->dataValue('autoSlide'), 'autoSlide' => $block->dataValue('autoSlide'),
'autoSlideInt' => $block->dataValue('autoSlideInt'), 'autoSlideInt' => $block->dataValue('autoSlideInt'),
'wrapStyle' => $block->dataValue('wrapStyle'), 'wrapStyle' => $block->dataValue('wrapStyle'),
'imgStyle' => $block->dataValue('imgStyle'), 'imgStyle' => $block->dataValue('imgStyle'),
'ui_background' => $block->dataValue('ui_background'), 'ui_background' => $block->dataValue('ui_background'),
'item_url' => $attachments[0]->item()->url(),
//'item_title' => $attachments[0]->item()->title(),
'renderSourceLink' => $block->dataValue('renderSourceLink'), 'renderSourceLink' => $block->dataValue('renderSourceLink'),
]); ]);
} }

View File

@ -20,22 +20,21 @@
<div class="archive-carousel"> <div class="archive-carousel">
<?php if ($renderSourceLink) { ?> <?php if ($renderSourceLink) { ?>
<div class="source-link"> <div class="source-link">
<a href="<?= $item_url ?>">Source</a> <a href="">Source</a>
</div> </div>
<?php } ?> <?php } ?>
<div style="position:relative;"> <div style="position:relative;">
<div class="siema"> <div class="siema_<?= $carousel_id ?> siema">
<?php foreach ($urls as $url) { ?> <?php foreach ($images as $image) { ?>
<div class="siema-wrap" <div class="siema-wrap"
style="<?= $wrapStyle ?>" style="<?= $wrapStyle ?>"
> >
<img class="siema-img" <img class="siema-img"
style="<?= $imgStyle ?>" style="<?= $imgStyle ?>"
src="<?= $url ?>" src="<?= $image['media_url'] ?>"
/> />
</div> </div>
<?php } ?> <?php } ?>
@ -50,14 +49,22 @@
</div> </div>
<script> <script>
var sourceURLs = [];
<?php foreach ($images as $image) { ?>
sourceURLs.push("<?= $image['item_url'] ?>")
<?php } ?>
$(document).ready(function() { $(document).ready(function() {
let siema = new Siema({ let siema = new Siema({
selector: '.siema', selector: '.siema_<?= $carousel_id ?>',
easing: 'ease-out', easing: 'ease-out',
duration: <?php echo $duration ?>, duration: <?php echo $duration ?>,
perPage: <?php echo $perPage ?>, perPage: <?php echo $perPage ?>,
loop: <?php echo $loop ?>, loop: <?php echo $loop ?>,
draggable: <?php echo $draggable ?> draggable: <?php echo $draggable ?>,
onInit: changeSourceURL,
onChange: changeSourceURL,
}); });
let caret = '<?php echo $caret;?>'; let caret = '<?php echo $caret;?>';
@ -78,4 +85,20 @@ $(document).ready(function() {
}, <?php echo $autoSlideInt; ?>); }, <?php echo $autoSlideInt; ?>);
<?php endif ?> <?php endif ?>
}); });
function changeSourceURL(){
var slide_idx = this.currentSlide
if (slide_idx < 0) {
slide_idx = sourceURLs.length -1;
}
var source_link = $(".siema_<?= $carousel_id ?>")
.closest(".archive-carousel")
.find(".source-link")
.find('a');
if (source_link.length != 0) {
$(source_link).attr("href", sourceURLs[slide_idx])
}
}
</script> </script>