GithubHelp home page GithubHelp logo

wottpal / kirby-lightbox-gallery Goto Github PK

View Code? Open in Web Editor NEW
36.0 5.0 7.0 8.28 MB

A plugin for Kirby CMS which allows the editor to easily inline beautifully aligned galleries with lightbox-support.

License: MIT License

JavaScript 47.99% PHP 42.39% CSS 9.62%

kirby-lightbox-gallery's Introduction

๐Ÿ–ผ Kirby Lightbox-Gallery by @wottpal

Release MIT Tweet

(Disclaimer: This is a pre-release.)

A plugin for the awesome Kirby CMS which allows the editor to easily inline beautiful galleries with lightbox-support.

  • Dynamic & responsive Grid-Alignment
  • Works with Kirby's built-in thumbnail class, ImageSet by @fabianmichael and Focus by @flokosiol
  • Powered by PhotoSwipe by @dimsemenov
  • Parses title & caption image-fields directly into PhotoSwipe
  • Configurable & Customizable to it's core ๐Ÿค˜

Demo of Kirby Lightbox-Gallery

๐Ÿคนโ€ Demos

๐Ÿคธ Installation

Because of the PhotoSwipe dependency multiple steps are necessary for a proper installation of the plugin. Also PHP 5.6+ is required. If you have any questions feel free to reach out or file an issue.

1. Install the plugin itself

Recommended: Use Kirby's CLI and install the plugin via: kirby plugin:install wottpal/kirby-lightbox-gallery

Oldschool: Download this repo and move the folder to site/plugins/.

2. Download Photoswipe

Download PhotoSwipe (tested version 4.1.2) rename the dist directory to photoswipe and place it under assets/vendor/.

Note: Additionally you should minify the two .css files of PhotoSwipe which is weirdly not done by them. I love to use Squeezer for macOS for that. In the next section I'll assume that minified versions of these files exist.

3. Link Resources

Embed necessary styles within your <head>:

<?= css([
  'assets/plugins/lightbox-gallery/gallery.min.css',
  'assets/vendor/photoswipe/photoswipe.min.css',
  'assets/vendor/photoswipe/default-skin/default-skin.min.css'
  ]) ?>

Embed necessary scripts before the end of your </body>:

<?= js([
  'assets/vendor/photoswipe/photoswipe.min.js',
  'assets/vendor/photoswipe/photoswipe-ui-default.min.js',
  'assets/plugins/lightbox-gallery/init-photoswipe.min.js'
]) ?>

If you use the default initialization (init-photoswipe.min.js) and want to support older browsers you may need to add polyfills for the forEach and Array.from functions.

Customization

Except the PhotoSwipe Base CSS & JS you can literally replace every dependency with your own code. A good start for this is to copy & paste the original dependency (e.g. 'site/plugins/lightbox-gallery/src_assets/init-photoswipe.js') into your own assets folder, do your modifications and change the asset-paths accordingly. But be aware that the plugin changes over time and you may have to keep your changes compatible.

๐ŸŠ Usage Examples

(gallery: all)  # Includes all images of the page
(gallery: 1.png 2.png 3.png)  # Includes only selected images
(gallery: all page: projects/a)  # Includes all images of the page with the given uri

(gallery: all limit: 2)  # Only shows thumbs of the first two images

(gallery: all order: random)  # Shuffles all images
(gallery: all order: reverse)  # Displays all images in reverse order

(gallery: all cols: 2 4)  # Sets cols to ['min' => 2, 'max' => 4]
(gallery: all cols: 3)  # Sets cols to ['min' => 3, 'max' => 3]
(gallery: all mobilecols: 1 2)  # Sets mobilecols to ['min' => 1, 'max' => 2]

(gallery: all stretch: last)  # Stretch trailing items instead of first
(gallery: all stretch: none)  # Disable stretching

(gallery: all class: my-class id: my-id)  # Applied a class & id to the gallery-wrapper

Please see the following section for further description how the particular parameters work. Options set in a Kirbytag always overwrite global options.

๐Ÿคบ Options

The following options can be set globally in your config.php with c::set($key, $value = null). You can also set multiple keys with c::set([$key => $value, ..]). ๐Ÿค“


  • lightboxgallery.kirbytext.tagname (default: 'gallery')

The name of the tag to use this gallery within kirbytext. Like (gallery: ...).


  • lightboxgallery.id (default: '')
  • lightboxgallery.class (default: '')

Specify an ID or class which is added to the gallery-wrapper element. Use it for custom styling.


  • lightboxgallery.combine (default: false)

If set to true all galleries on one page will be virtually the same. So you can navigate between all images in the same lightbox.


  • lightboxgallery.limit (default: false)

Maximum amount of previewed thumbnails to be shown.

Note: The hidden items are only visually hidden with CSS. By appending a data-not-previewed attribute to the <figure> elements.


  • lightboxgallery.cols (default: ['min' => 3, 'max' => 4])
  • lightboxgallery.mobilecols (default: ['min' => 2, 'max' => 2])

Defines the range of possible columns the gallery can choose of. Within this range an algorithm ๐Ÿ”ฎ tries to find the best match in terms of minimizing row-count and overhang with the given amount of thumbs.

Note 1: The actual implementation is located under helpers.php.

Note 2: The mobile-breakpoint and gutter-width are currently defined in src_assets/gallery.scss. You can overwrite it by setting a lightboxgallery.class and adding your own styles or completely substituting the plugins CSS with your own stylesheets.


  • lightboxgallery.stretch (default: 'first')

*If there are not enough images to fill all rows with as many items as columns by default the images in the first row are stretched to fill up the whole width. You can set this option to 'last' to stretch all trailing items instead or set it to 'none' to disable stretching at all.


  • lightboxgallery.thumb.provider (default: 'thumb')

Choose from one of the following providers for thumb-creation:

Note: Because thumbnail-creation for a whole gallery may take some time and you don't want the first visitor of your site to suffer I recommend you to have a look into ImageKit.


  • lightboxgallery.thumb.options (default: ["width" => 800, "height" => 800, "crop" => true])

Define the options for the selected thumb.provider. Works exactly the same way as you would use the options with their respective functions. If you set the thumb.provider to something else than 'thumb' or false you must set this option.

Note 1: The default-value is crops 800x800 thumbnails with Kirby's built-in thumbnail class.

Note 2: If you use focus put all values in an array. So for example if you set it to [300,300] the plugin will call focusCrop(300,300).

Note 3: If you use imageset you set this option to something like ['400x400-1000x1000, 4'] to generate responsive square images. (You should specify sizes as well).


๐Ÿ„ Changelog

Have a look at the releases page.

๐Ÿ‹๏ธ Roadmap

Contributions welcome ๐Ÿ˜˜

  • Possibility to define thumb-sizes for the Non-ImageSet version
  • Option to move stretched row to the end (only if count % col != 0)
  • Option to not stretch row and keep the same column-count (only if count % col != 0).
  • Allow cols/mobilecols to be set in the kirbytag
  • Think more about non-square images
  • Dynamic thumb-options based on column-count
  • Define responsive image-sources for PhotoSwipe
  • Option to disable lightbox usage
  • Enable use of History-API of PhotoSwipe in init-photoswipe.js
  • Maybe a new breakpoint-based API for defining min/max cols like
  • Support for videos (esp. webM with mp4 and gif fallbacks)

๐Ÿ‘จโ€๐Ÿ’ป Development

For minification and transpilation I use Gulp. Please note that all files under assets/ are only the generated ones from src_assets/.

# Install Dependencies
npm i

# Or: Install Dependencies for Hipsters
yarn

# Build & Watch (Install 'gulp-cli' globally to omit the 'npx')
npx gulp

๐Ÿ’ฐโ€ Pricing

Just kidding. This plugin is totally free. Please consider following me on Twitter if it saved your day.

Twitter Follow

You can also check out one of my other Kirby-plugins:

  • HTML5-Video Kirbytag - Adds a kirbytag for embedding HTML5-videos with a variety of features.
  • Anchor-Headings - A kirby field-method which enumerates heading-elements, generates IDs for anchor-links and inserts custom markup based on your needs.

kirby-lightbox-gallery's People

Contributors

wottpal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

kirby-lightbox-gallery's Issues

Feature Ideas/Requests

Hi, i saw this Gallery: http://topdevs.net/smart-grid-gallery/

i like those hover effects and caption styles, the image alignment of different image sizes and the animation -> fullscreen, when clicking on an image.

Maybe you are interested to implement such features?

thx a lot
demlak

Feature Idea: Before and After

Just an Idea:

Something like a mouse-hover which shows picture 1 and when mouse is moved outside the frame of the picture, picture 2 is shown.. or similar.

That would be a nice feature for galleries of edited pictures or historical pictures, and so on..
With this feature you can show "before and after".

since i'm not a coder, i can't help on that topic.

Kirby3 support

Hey there,
Just wondering why this great plugin was never upgraded to Kirby 3

I got it to work with Kirby3 quite fast, so is there a reason ? (You can check my changes on my fork)

Basic Installation Question

Hello,

Extremely basic question, not an issue with the plugin: just looking for how to add a gallery to my site..!

I have been looking for what I need to add to my blueprints so that I can use this gallery plugin for each project I am looking to show in a portfolio, and cannot figure it out.

The example video where you drag photos into your panel and customize how they appear with different keywords: how do you add this to a blueprint??

I installed the JS and CSS files and they are all going through correctly, and I am very confused.
Thank you!

Is there a way to add captions?

Hi, pretty new to Kirby and just installed your plugin.

Works awesome, but I'm wondering whether it is possible at all to add captions of the images?

Happy Holidays!
Pieter

Feature Idea: "crossover" gallery

Would be nice to have a gallery to cross over Pages.
At the moment it seems that a gallery is restricted to one page.

something like this would be nice:
(gallery: home\page1\image1.jpg home\page2\image2.jpg home\page3\image3.jpg)

since i'm not a coder, i can't help on that topic.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.