Skip to content

Commit

Permalink
Item14977: add support for native lazy-loading
Browse files Browse the repository at this point in the history
also:

* added showhidden parameter to exclude hidden images from the gallery
* added warn toggle to disable warinings
  • Loading branch information
MichaelDaum committed Oct 26, 2020
1 parent 7c414bf commit 881b3ac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
10 changes: 7 additions & 3 deletions data/System/ImageGalleryPlugin.txt
Expand Up @@ -32,12 +32,14 @@ below).
| frontend | select gallery interface, possible values are =default=, =slimbox=, =prettyphoto=, =photoswipe= | photoswipe, prettyphoto or slimbox (in the given prioirty) |
| header | header part of the gallery | =<div class="$class clearfix" data-item-selector=".imageSimple">= |
| include | regular expression an image must match to be part of the gallery | |
| showhidden | boolean flag to include images that are hidden; set to off to hide hidden images | on |
| layout | thumbnail layout algorithm, can be either =packery= (using Foswiki:Extensions/JQPackeryContrib) or =masonry= or undefined | |
| limit | maximum number of images to display | 0, meaning no limit |
| reverse | invert the initial order of the images, can be on or off | off |
| size | the thumbnail size, the actual geometries of a size can be configured below; possible values: tiny, small, medium, large, huge (default: medium) |
| sort | set the initial order of the images, can be name, date, size or comment | date |
| titles | toggles image and thumnail titles on and off | off |
| warn | toogles display of error messages, i.e. when no image was found | on |

---+++ Frontends

Expand Down Expand Up @@ -111,6 +113,8 @@ Note, that the $comment variable will only display =<comment>= , that is w

---++ Change History
%TABLE{columnwidths="7em" tablewidth="100%"}%
| 26 Oct 2020 | added support for native lazy loading of images; \
added =showhidden= parameter to exclude hidden images from the gallery |
| 27 Jul 2017 | massive rewrite using Foswiki:Extensions/ImagePlugin as a backend now; \
removed <nop>NRIMAGES macro; \
oo-ified implementation; \
Expand Down Expand Up @@ -158,8 +162,8 @@ Note, that the $comment variable will only display =&lt;comment&gt;= , that is w
added refresh query parameter to recompute images |
| 09 May 2005 | fixed errors reported by Marcel Trap; \
added support for multiple topics (proposed by Martin Cleaver; \
added %<nop>NRIMAGES% tag |
| &nbsp; | fix error when called from within rename view |
added %<nop>NRIMAGES% tag; \
fix error when called from within rename view |
| 03 May 2005 | fixed thumbnail resizing; reintroduced =titles= parameter; \
support for multiple galleries per topic |
| 27 Apr 2005 | complete rewrite |
Expand All @@ -173,7 +177,7 @@ Note, that the $comment variable will only display =&lt;comment&gt;= , that is w
%META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%25TOPIC%25"}%
%META:FIELD{name="Copyright" title="Copyright" value="2002-2009, Will Norris; 2005-2017, Michael Daum http://michaeldaumconsulting.com"}%
%META:FIELD{name="Copyright" title="Copyright" value="&copy; 2002-2009, Will Norris, 2005-2020, Michael Daum"}%
%META:FIELD{name="License" title="License" value="GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]])"}%
%META:FIELD{name="Home" title="Home" value="Foswiki:Extensions/%25TOPIC%25"}%
%META:FIELD{name="Support" title="Support" value="Foswiki:Support/%25TOPIC%25"}%
Expand Down
9 changes: 3 additions & 6 deletions lib/Foswiki/Plugins/ImageGalleryPlugin.pm
@@ -1,5 +1,5 @@
# Copyright (C) 2002-2009 Will Norris. All Rights Reserved. (wbniv@saneasylumstudios.com)
# Copyright (C) 2005-2017 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2005-2020 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -17,13 +17,12 @@ package Foswiki::Plugins::ImageGalleryPlugin;
use strict;
use warnings;

our $VERSION = '8.01';
our $RELEASE = '27 Jul 2017';
our $VERSION = '8.20';
our $RELEASE = '26 Oct 2020';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Displays image gallery with auto-generated thumbnails from attachments';
our $core;

###############################################################################
sub initPlugin {
#my ($topic, $web, $user, $installWeb) = @_;

Expand All @@ -36,14 +35,12 @@ sub initPlugin {
return 1;
}

###############################################################################
sub finishPlugin {

$core->finish() if defined $core;
#undef $core; # EXPERIMENTAL: keep it in memory
}

###############################################################################
sub getCore {

unless (defined $core) {
Expand Down
14 changes: 5 additions & 9 deletions lib/Foswiki/Plugins/ImageGalleryPlugin/Core.pm
@@ -1,7 +1,7 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2002-2009 Will Norris. All Rights Reserved. (wbniv@saneasylumstudios.com)
# Copyright (C) 2005-2017 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2005-2020 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -67,14 +67,14 @@ sub handleIMAGEGALLERY {
$params->{crop} //= "on";
$params->{tooltip} = Foswiki::Func::isTrue($params->{tooltip} // "off", 0)?"on":"off";
$params->{titles} = Foswiki::Func::isTrue($params->{titles} // "off", 0);
$params->{lazyload} = Foswiki::Func::isTrue($params->{lazyload} // "on", 1);
$params->{format} //= '%IMAGE{"$name" topic="$web.$topic" align="left" size="$size" crop="$crop" caption="$title" tooltip="$tooltip" filter="$filter"}%';
$params->{format} //= '%IMAGE{"$name" topic="$web.$topic" align="left" size="$size" crop="$crop" caption="$title" tooltip="$tooltip" filter="$filter" lazyload="on"}%';
$params->{header} //= '<noautolink><div class="$class clearfix" data-item-selector=".imageSimple">';
$params->{footer} //= '</div></noautolink>';
$params->{separator} //= '';
$params->{limit} //= 0;
$params->{skip} //= 0;
$params->{filter} //= '';
$params->{showhidden} //= 'on';

$params->{filter} = '' if $params->{filter} eq 'none';

Expand Down Expand Up @@ -150,11 +150,6 @@ sub handleIMAGEGALLERY {

$this->addToZone();

if ($params->{lazyload} && $context->{'LazyLoadPluginEnabled'}) {
Foswiki::Plugins::JQueryPlugin::createPlugin("lazyload");
$result = '%STARTLAZYLOAD%'.$result.'%ENDLAZYLOAD%';
}

return Foswiki::Func::decodeFormatTokens($result);
}

Expand Down Expand Up @@ -193,9 +188,10 @@ sub getImages {
}

foreach my $attachment ($meta->find('FILEATTACHMENT')) {
next unless $this->isImage($attachment->{name});
next if $params->{showhidden} ne 'on' && $attachment->{attr} =~ /h/;
next if $params->{exclude} && $attachment->{$params->{field}} =~ /$params->{exclude}/;
next if $params->{include} && $attachment->{$params->{field}} !~ /$params->{include}/;
next unless $this->isImage($attachment->{name});
push @images, {
web => $theWeb,
topic => $theTopic,
Expand Down

0 comments on commit 881b3ac

Please sign in to comment.