Skip to content

Commit

Permalink
Fix #73 missing lightbox image size
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Mar 22, 2021
1 parent 07a1576 commit 7129426
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
6 changes: 4 additions & 2 deletions src/Module/Slider.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ protected function compile()
'title' => $arrMeta['title'],
'imageUrl' => $arrMeta['link'],
'caption' => $arrMeta['caption'],
'fullsize' => $this->fullsize,
);

}
Expand Down Expand Up @@ -221,7 +222,7 @@ protected function compile()
foreach ($images as $key => $image) {
$newImage = new \stdClass();
$image['size'] = isset($this->imgSize) ? $this->imgSize : $this->size;
$this->addImageToTemplate($newImage, $image, null, null, \FilesModel::findByPk($image['id']));
$this->addImageToTemplate($newImage, $image, null, substr(md5('mod_rocksolid_slider_' . $this->id), 0, 6), \FilesModel::findByPk($image['id']));
if ($this->rsts_navType === 'thumbs') {
$newImage->thumb = new \stdClass;
$image['size'] = $this->rsts_thumbs_imgSize;
Expand Down Expand Up @@ -451,7 +452,8 @@ protected function parseSlides($objSlides)
'imageUrl' => $meta['link'],
'caption' => $meta['caption'],
'size' => isset($this->imgSize) ? $this->imgSize : $this->size,
), null, null, $file);
'fullsize' => $this->fullsize,
), null, substr(md5('mod_rocksolid_slider_' . $this->id), 0, 6), $file);
}

if ($slide['type'] === 'video' && $slide['videoURL'] && empty($slide['image'])) {
Expand Down
35 changes: 12 additions & 23 deletions src/Resources/contao/templates/rsts_default.html5
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,24 @@
<?php ob_start() ?>
<?php endif ?>

<?php if ($this->fullsize && !$image->href) {
$lightboxUrls[] = array(TL_FILES_URL . \Contao\System::urlEncode($image->singleSRC), $image->linkTitle ?: $image->picture['alt']);
<?php if (strpos($image->attributes, 'data-lightbox') !== false) {
$lightboxUrls[] = array($image->href, $image->linkTitle ?: $image->picture['alt']);
} ?>

<?php
$tagName = 'div';
$attributes = array(
'data-rsts-type="image"',
);
if ($image->href || $this->fullsize) {
if ($image->href) {
$tagName = 'a';
}
if ($image->href || $this->fullsize || $image->linkTitle) {
if ($image->href || $image->linkTitle) {
$attributes[] = 'title="' . ($image->linkTitle ?: $image->picture['alt']) . '"';
}
if ($image->href) {
$attributes[] = 'href="' . $image->href . '"';
if ($this->fullsize) {
$attributes[] = 'target="_blank"';
}
}
elseif ($this->fullsize) {
$attributes[] = 'href="' . TL_FILES_URL . \Contao\System::urlEncode($image->singleSRC) . '"';
$attributes[] = 'data-lightbox="' . substr(md5('mod_rocksolid_slider_' . $this->id), 0, 6) . '"';
$attributes[] = $image->attributes;
}
if (!empty($this->rsts_invertControls)) {
$attributes[] = 'data-rsts-class="' . (empty($this->options['cssPrefix']) ? 'rsts-' : $this->options['cssPrefix']) . 'invert-controls"';
Expand Down Expand Up @@ -166,20 +160,15 @@

<?php elseif (! empty($slide['image'])): ?>

<?php if (($this->fullsize || $slide['image']->href) && $tagName !== 'a') {
<?php if ($slide['image']->href && $tagName !== 'a') {
$tagName = 'a';
if ($slide['image']->href) {
$attributes .= ' href="' . $slide['image']->href . '"';
if ($slide['image']->linkTitle) {
$attributes .= ' title="' . $slide['image']->linkTitle . '"';
}
if ($this->fullsize) {
$attributes .= ' target="_blank"';
}
$attributes .= ' href="' . $slide['image']->href . '"';
if ($slide['image']->linkTitle) {
$attributes .= ' title="' . $slide['image']->linkTitle . '"';
}
else {
$lightboxUrls[] = array(TL_FILES_URL . \Contao\System::urlEncode($slide['image']->singleSRC), $slide['title']);
$attributes .= ' href="' . TL_FILES_URL . \Contao\System::urlEncode($slide['image']->singleSRC) . '" data-lightbox="' . substr(md5('mod_rocksolid_slider_' . $this->id), 0, 6) . '" title="' . \Contao\StringUtil::specialchars($slide['title']) . '"';
$attributes .= ' '.$slide['image']->attributes;
if (strpos($slide['image']->attributes, 'data-lightbox') !== false) {
$lightboxUrls[] = array($slide['image']->href, $slide['title']);
}
} ?>

Expand Down

0 comments on commit 7129426

Please sign in to comment.