Version 1.03

* imgages in body-attach with title / alt attribute get them removed while adding fancy attributes
* Added fancybox to image inlined in posts. Un-hooked the old lightbox from frio and vier and excahnged that with fancybox hooks.
* Excluded images in "type-link" divs from being "fancied" as they have no images but pages linked to.
This commit is contained in:
Grischa Brockhaus 2022-12-05 00:54:04 +01:00
parent 07a11f6920
commit 4e7da2799c
4 changed files with 51 additions and 24 deletions

View file

@ -1,3 +1,13 @@
### Version 1.03
* imgages in body-attach with title / alt attribute get them removed while adding fancy attributes
* Added fancybox to image inlined in posts. Un-hooked the old lightbox from frio and vier and excahnged that with fancybox hooks.
* Excluded images in "type-link" divs from being "fancied" as they have no images but pages linked to.
### Version 1.02
* [MrPetovan](https://github.com/MrPetovan) optimized my noob regular expression code.
### Version 1.01 ### Version 1.01
* One gallery for each post * One gallery for each post

View file

@ -1,3 +1,4 @@
$(document).ready(function() { $(document).ready(function() {
$.fancybox.defaults.loop = "true"; $.fancybox.defaults.loop = "true";
$("body").off("click", ".wall-item-body a img");
}); });

View file

@ -11,7 +11,7 @@ rm $MODULE/dist/*
# create release for actual version # create release for actual version
zip -r9 $MODULE/dist/release.zip $MODULE/* -x $MODULE/dist/\* -x $MODULE/test/\* $MODULE/createrelease zip -r9 $MODULE/dist/release.zip $MODULE/* -x $MODULE/dist/\* -x $MODULE/test/\* $MODULE/createrelease
echo release/release.zip created. echo dist/release.zip created.
cd $MODULE cd $MODULE

View file

@ -2,7 +2,7 @@
/** /**
* Name: Fancybox * Name: Fancybox
* Description: Open media attachments of posts into a fancybox overlay. * Description: Open media attachments of posts into a fancybox overlay.
* Version: 1.01 * Version: 1.03
* Author: Grischa Brockhaus <grischa@brockha.us> * Author: Grischa Brockhaus <grischa@brockha.us>
*/ */
@ -28,27 +28,43 @@ function fancybox_footer(App $a, string &$str)
DI::page()->registerFooterScript(__DIR__ . '/asset/fancybox/fancybox.config.js'); DI::page()->registerFooterScript(__DIR__ . '/asset/fancybox/fancybox.config.js');
} }
function fancybox_render(App $a, array &$b) function fancybox_render($a, array &$b){
$gallery = 'gallery-' . $b['item']['uri-id'] ?? random_int(1000000, 10000000);
// prevent urls in <div class="type-link"> to be replaced
$b['html'] = preg_replace_callback(
'#<div class="type-link">.*?</div>#s',
function ($matches) use ($gallery) {
return str_replace('<a href', '<a data-nofancybox="" href', $matches[0]);
},
$b['html']
);
// This processes images inlined in posts
// Frio / Vier hooks für lightbox are un-hooked in fancybox-config.js. So this works for them, too!
//if (!in_array($a->getCurrentTheme(),['vier','frio']))
{ {
$matches = []; // normal post inline linked images
$pattern = '#<div class="body-attach">.*?</div>#s'; $b['html'] = preg_replace_callback(
$gallery = 'gallery'; '#<a[^>]*href="([^"]*)"[^>]*>(<img[^>]*src="[^"]*"[^>]*>)</a>#',
if (array_key_exists('item', $b)) { function ($matches) use ($gallery) {
$item = $b['item']; // don't touch URLS marked as not "fancyable".. ;-)
if (array_key_exists('uri-id', $item)) { if (preg_match('#data-nofancybox#', $matches[0]))
$gallery = $gallery . '-' . $item['uri-id']; {
return $matches[0];
} }
return '<a data-fancybox="' . $gallery . '" href="'. $matches[1] .'">' . $matches[2] .'</a>';
},
$b['html']
);
} }
$html = $b['html'];
while (preg_match($pattern, $html, $matches, PREG_OFFSET_CAPTURE)) { // Local content images attached:
if (is_array($matches)) { $b['html'] = preg_replace_callback(
$matches = $matches[0]; '#<div class="body-attach">.*?</div>#s',
} function ($matches) use ($gallery) {
$part = $matches[0]; return str_replace('<a href', '<a data-fancybox="' . $gallery . '" href', $matches[0]);
$replaced = str_replace('<a href', '<a data-fancybox="' . $gallery . '" href', $part); },
$replaced = str_replace('<div class="body-attach"', '<div class="body-attach done"', $replaced); $b['html']
$html = str_replace($part, $replaced, $html); );
}
$html = str_replace('class="body-attach done"', 'class="body-attach"', $html);
$b['html'] = $html;
} }