Skip to content

Commit

Permalink
try finish
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdarkle committed Sep 10, 2024
1 parent 878c1bc commit fe18665
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"build": "npm run build:css && webpack --mode production",
"format": "prettier --write src",
"format-check": "prettier --check src",
"build:css": "cp ./node_modules/@fancyapps/ui/dist/fancybox/fancybox.css ../less/fancybox.css && cp ./node_modules/@fancyapps/ui/dist/carousel/carousel.css ../less/carousel.css && cp ./node_modules/@fancyapps/ui/dist/panzoom/panzoom.css ../less/panzoom.css"
"build:css": "cp ./node_modules/@fancyapps/ui/dist/fancybox/fancybox.css ../less/fancybox.css && cp ./node_modules/@fancyapps/ui/dist/carousel/carousel.css ../less/carousel.css"
}
}
2 changes: 0 additions & 2 deletions less/forum.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
@import (inline) "fancybox.css";
@import (inline) "carousel.css";
@import (inline) "panzoom.css";
@import (inline) "panzoom.controls.css";

.f-carousel__slide {
display: flex;
Expand Down
1 change: 0 additions & 1 deletion less/panzoom.controls.css

This file was deleted.

1 change: 0 additions & 1 deletion less/panzoom.css

This file was deleted.

26 changes: 20 additions & 6 deletions src/DefineGalleryTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,30 @@ public function __invoke(Configurator $config)
<xsl:choose>
<xsl:when test="parent::FANCYBOX-GALLERY-ITEM">
<a data-fancybox="gallery" href="{@src}">
<img src="{@src}" alt="{@alt}" loading="lazy">
<xsl:copy-of select="@*"/>
</img>
<img src="{@src}" alt="{@alt}" loading="lazy"/>
</a>
</xsl:when>
<xsl:otherwise>
<a data-fancybox="single" href="{@src}">
<img src="{@src}" alt="{@alt}" loading="lazy">
<xsl:copy-of select="@*"/>
</img>
<img src="{@src}" alt="{@alt}" loading="lazy"/>
</a>
</xsl:otherwise>
</xsl:choose>
XML;
}

if ($config->tags->exists('UPL-IMAGE-PREVIEW')) {
$tag = $config->tags->get('UPL-IMAGE-PREVIEW');
$tag->template = <<<XML
<xsl:choose>
<xsl:when test="parent::FANCYBOX-GALLERY-ITEM">
<a data-fancybox="gallery" href="{@url}">
<img src="{@url}" alt="" loading="lazy"/>
</a>
</xsl:when>
<xsl:otherwise>
<a data-fancybox="single" href="{@url}">
<img src="{@url}" alt="" loading="lazy"/>
</a>
</xsl:otherwise>
</xsl:choose>
Expand Down
8 changes: 4 additions & 4 deletions src/WrapImagesInGallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

class WrapImagesInGallery
{
const MATCH_IMG_TAGS = '(\[upl-image-preview[^\]]*\]|\<IMG[^>]*\>(?:.*?)\<\/IMG\>|\<UPL-IMAGE-PREVIEW[^>]*\>(?:.*?)\<\/UPL-IMAGE-PREVIEW\>)';
const MATCH_GALLERY_REGEX = '/(' . self::MATCH_IMG_TAGS . '(?:\s*\n\s*' . self::MATCH_IMG_TAGS . ')+)/s';
const MATCH_IMG_TAGS = '((?:<UPL-IMAGE-PREVIEW[^>]*>(?:(?!<\/UPL-IMAGE-PREVIEW>).)*<\/UPL-IMAGE-PREVIEW>)|(?:<IMG[^>]*>(?:(?!<\/IMG>).)*<\/IMG>))';
const MATCH_GALLERY_REGEX = '((?:'.self::MATCH_IMG_TAGS.'(?:\s*(?:<br\/>|<br>|\n)\s*)?){2,})';

public function __invoke(Renderer $renderer, $context, string $xml): string
{
return preg_replace_callback(self::MATCH_GALLERY_REGEX, function ($matches) {
$images = preg_split('/\s*\n\s*/', $matches[1]);
return preg_replace_callback('/'.self::MATCH_GALLERY_REGEX.'/m', function ($matches) {
$images = preg_split('/\s*(?:<br\/>|<br>|\n)\s*/', $matches[0]);
$galleryItems = array_map(function($img) {
return '<FANCYBOX-GALLERY-ITEM>' . trim($img) . '</FANCYBOX-GALLERY-ITEM>';
}, $images);
Expand Down

0 comments on commit fe18665

Please sign in to comment.