Giter Site home page Giter Site logo

grav-plugin-featherlight's Introduction

Grav Featherlight Plugin

Featherlight

featherlight is a simple Grav plugin that adds lightbox functionality via the jQuery plugin Featherlight.js.

Installation

Installing the Featherlight plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.

GPM Installation (Preferred)

The simplest way to install this plugin is via the Grav Package Manager (GPM) through your system's Terminal (also called the command line). From the root of your Grav install type:

bin/gpm install featherlight

This will install the Featherlight plugin into your /user/plugins directory within Grav. Its files can be found under /your/site/grav/user/plugins/featherlight.

Manual Installation

To install this plugin, just download the zip version of this repository and unzip it under /your/site/grav/user/plugins. Then, rename the folder to featherlight. You can find these files either on GitHub or via GetGrav.org.

You should now have all the plugin files under

/your/site/grav/user/plugins/featherlight

NOTE: This plugin is a modular component for Grav which requires Grav to function

Usage

To best understand how Featherlight works, you should read through the original project documentation.

Configuration

Featherlight is enabled but not active by default. You can change this behavior by setting active: true in the plugin's configuration. Simply copy the user/plugins/featherlight/featherlight.yaml into user/config/plugins/featherlight.yaml and make your modifications.

enabled: true                 # global enable/disable the entire plugin
active: false                 # if the plugin is active and JS/CSS should be loaded
openSpeed: 250                # open speed in ms
closeSpeed: 250               # close speed in ms
closeOnClick: background      # background|anywhere|false
closeOnEsc: true              # true|false on hitting Esc key
root: body                    # where to append featherlights
initTemplate: plugin://featherlight/js/featherlight.init.js

You can also override any default setings from the page headers:

eg:

    ---
    title: Sample Code With Custom Settings
    featherlight:
        active: true
        openSpeed: 100
        closeSpeed: 100
    ---

You can also enable globally in the yaml, but disable featherlighting for a particular page:

    ---
    title: Sample Code with Featherlight disabled
    featherlight:
        active: false
    ---

Implementing a lightbox with Featherlight

To implement a lightbox using Featherlight in Grav, you must output the proper HTML output. Luckily Grav already takes care of this for you if you are using Grav media files.

In markdown this could look something like:

![Sample Image](sample-image.jpg?lightbox=1024&cropResize=200,200)

In Twig this could look like:

{{ page.media['sample-image.jpg'].lightbox(1024,768).cropResize(200,200).html('Sample Image') }}

More details can be found in the Grav documentation for Media functionality.

NOTE: Featherlight does not support srcset.

Adding captions to the lightbox

Image captions within the lightbox do not come out of the box with featherlight. But as the author described in his wiki it's quite easy to add.

Per default we use a this script when initializing the plugin: js/featherlight.init.js. You can copy it to the "user" folder, change the initTemplate setting to user://js/featherlight.init.js and add a afterContent callback like this:

    $(document).ready(function(){
        $('a[rel="lightbox"]').{pluginName}({
            openSpeed: {openSpeed},
            closeSpeed: {closeSpeed},
            closeOnClick: '{closeOnClick}',
            closeOnEsc: '{closeOnEsc}',
            root: '{root}',
            afterContent: function() {
                var caption = this.$currentTarget.find('img').attr('alt');
                this.$instance.find('.caption').remove();
                $('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content'));
            }
        });
    });

The placeholders {pluginName}, {openSpeed}, {closeSpeed} and {root} will be replaced when processing this file.

Using AMD modules with RequireJS

Must update to v1.4.1. When you select RequireJS from the config, this plugin will inlineJS an AMD module called featherlight that you can use with RequireJS. If you call this module directly, it will work, however if you decide to disable this plugin RequireJS will fail. As such, if you include the module below it will see if featherlight exists and include it if it does.

define(['jquery'], function($){
  var Lightbox = {
    Init : function() {
    if (require.specified('featherlight')) {
      require( [ 'featherlight' ], function (Featherlight) {
        Featherlight.Init();
      });
      }
    }
  };
  return Lightbox;
});

Also set your main.js file to include this line:

paths: {
    ...
    plugin: '/user/plugins',
    ...
},

Updating

As development for the Featherlight plugin continues, new versions may become available that add additional features and functionality, improve compatibility with newer Grav releases, and generally provide a better user experience. Updating Featherlight is easy, and can be done through Grav's GPM system, as well as manually.

GPM Update (Preferred)

The simplest way to update this plugin is via the Grav Package Manager (GPM). You can do this with this by navigating to the root directory of your Grav install using your system's Terminal (also called command line) and typing the following:

bin/gpm update featherlight

This command will check your Grav install to see if your Featherlight plugin is due for an update. If a newer release is found, you will be asked whether or not you wish to update. To continue, type y and hit enter. The plugin will automatically update and clear Grav's cache.

Manual Update

Manually updating Featherlight is pretty simple. Here is what you will need to do to get this done:

  • Delete the your/site/user/plugins/featherlight directory.
  • Download the new version of the Featherlight plugin from either GitHub or GetGrav.org.
  • Unzip the zip file in your/site/user/plugins and rename the resulting folder to featherlight.
  • Clear the Grav cache. The simplest way to do this is by going to the root Grav directory in terminal and typing bin/grav clear-cache.

Note: Any changes you have made to any of the files listed under this directory will also be removed and replaced by the new set. Any files located elsewhere (for example a YAML settings file placed in user/config/plugins) will remain intact.

grav-plugin-featherlight's People

Contributors

flaviocopes avatar khanduras avatar kitzberger avatar mikegcox avatar rhukster avatar rotzbua avatar ryanmpierson avatar seebz avatar waseigo 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grav-plugin-featherlight's Issues

Minor

There is a minor issue with documentation in the Readme file.

![Sample Image](sample-image.jpg?lightbox=1024,cropResize=200,200)

Should be:

![Sample Image](sample-image.jpg?lightbox=1024&cropResize=200,200)

There is a comma in the querystring part of the file path that should be an ampersand.

Next button causes scroll bars on narrow images

In testing of featherlight I found a small problem with displaying narrow images. When hovering on the right of the image, the "next" icon causes the dimensions to push out and create scroll bars. So the image keeps jumping around. This can be fixed by reducing the font-size from 80px to 40px. I also found the contrast between the white background and white button to be very unclear, so preferred a darker background. These are small tweaks to css - can do a PR if you want.

Before:
before

After:
after

Images are not opening in lightbox

Hi guys,

I've got problem with Featherlight plugin and I don't have idea how to fix it, so maybe you will be able to help me.
I'm using Grav v1.2.4 with Grav Admin v1.4.2 and Clean Blog template. I've installed and activated Featherlight plugin as the manual says. However it's not working as it should - images are showing in the tab, not in the lightbox as it should. You can check it here: http://sugoi.com.pl/beta/new-nintendo-2ds-xl-odswiezona-przenosna-konsola (images are at the end of the article).

Code in the article is:
![](2ds-dq2.jpg?lightbox=1024&cropResize=200,200) ![](2ds-dq1.jpg?lightbox=1024&cropResize=200,200) ![](2ds-dq3.jpg?lightbox=1024&cropResize=200,200)

And here is configuration of Featherlight from featherlight.yaml file:

enabled: true                 # global enable/disable the entire plugin
active: true                  # if the plugin is active and JS/CSS should be loaded
gallery: false                # enable/disable the gallery extension
requirejs: false              # output to an AMD module
openSpeed: 250                # open speed in ms
closeSpeed: 250               # close speed in ms
closeOnClick: background      # background|anywhere|false
closeOnEsc: true              # true|false on hitting Esc key
root: body                    # where to append featherlights
initTemplate: plugin://featherlight/js/featherlight.init.js

Any ideas what I have done wrong?

How to combine

Hi, I whrite this

             
       
 {% for element in page.header.vidsites  %}
           < img class="lazyload " data-src=" {{ page.media[element.image].lightbox(1024,768).url() }}"  >    
 {% endfor %}

this not work? how to write this ?
without .lightbox(1024,768) work ok
(sorry for my english...)

Clarification on captions

Hi There,
I'm not a deep CSS/Twig person, I just want to implement captions. I've followed the instructions and see the init.js you give below embedded within the page, however no captions are being added.

(document).ready(function(){
    $('a[rel="lightbox"]').{pluginName}({
        openSpeed: {openSpeed},
        closeSpeed: {closeSpeed},
        closeOnClick: '{closeOnClick}',
        closeOnEsc: '{closeOnEsc}',
        root: '{root}',
                afterContent: function() {
            var caption = this.$currentTarget.find('img').attr('alt');
            this.$instance.find('.caption').remove();
            $('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content'));
        }
    });
});

It just doesn't seem to "fire", no captions are added, even if I override the caption in the code with "HELLO WORLD". I've tried adding meta-yaml files and changing the attr to "data-description" but that made no difference.

Does this still work, or has this functionality been broken by updates to Featherlite? I just can't seem to get this code to fire when the lightbox opens :( Any help most appreciated.

Change default for 'active' to true?

How about the default 'active' setting is changed to true for this plugin? I know this is stated in the ReadMe but if one installs this plugin wouldn't the expected behavior be to 'work out of the box' rather than needing additional config for such a simple thing like lightbox functionality?

Thanks for considering this request!

Update?

Any chance of an update? Featherlight is at 1.7.

'Feeling stupid' problems

According to the original featherlicht documentation the folloing gallery.html.twig template should work, although it doesn't here. And no matter what i do I can't nail the problem...

<div class="modular-row {{ page.header.class}}">

    <div style="text-align:center;">
        <h2>{{page.header.title}}</h2>
    </div>

    <div style="text-align:center; width: 100%; margin-left: auto; margin-right: auto; padding-bottom: 30px;">
        {% for image in page.media.images|sort %}
            <a href="{{ image.url }}" data-featherlight="image" style="display:inline-block;
                padding-left: 12px;
                padding-right: 12px;
                padding-top: 12px;
                margin-top: 16px;
                margin-left:5px;
                margin-right:5px;
                background-color: #efefef">{{ image.cropZoom(250,180).html }}</a>
        {% endfor %}
    </div>

    <div style="text-align:center;">
        {{content}}
    </div>

</div>

gallery.md looks like this:


---
title: This is my gallery
menu: Gallery
featherlight:
        active: true
        openSpeed: 4000
        closeSpeed: 100
        closeOnEsc: true

---
This is my gallery

Unable to close image in 1 click on Opera browser

Hi,

Closing an image requires 2 actions on Opera browser (current version 47) and Featherlight v1.5.0.

First mouse click (or pressing escape key) only triggers the fade effect. A second action (e.g. mouse click or escape key) is then required to start to close image after fade effect is completed.

I would expect image can be closed in one action (clic or key).

best regards,

Featherlight plugin activation code

Hi,

I have a problem with the Featherlight plugin (v1.5.0), which previously worked correctly. The error is probably in the activation code, which should be the following (a copy of https://learn.getgrav.org/):

<script>
$(document).ready(function(){
    $('a[rel="lightbox"]').featherlight({
        openSpeed: 250,
        closeSpeed: 250,
        closeOnClick: 'background',
        closeOnEsc: '1',
        root: 'body'
    });
});
</script>

But the following code is generated on my site:

<script>
define("featherlight",['jquery', 'plugin/featherlight/js/featherlight.min' ], function($){
                var Lightbox = {
                  Init : function() {
                    $('a[rel="lightbox"]').featherlight({
                      openSpeed: 250,
                      closeSpeed: 250,
                      closeOnClick: 'background',
                      closeOnEsc:   '1',
                      root: 'body'
                    });
                  }
                };
                return Lightbox;
            });
</script>

What is wrong?

Swipe functionality missing?

Featherlight version: 1.5.0
Grav version: v1.6.31
PHP version: 7.4

When using the Featherlight plugin, I see the following error in my Chrome console. Swipe functionality is indeed missing. Is this intentionally?

FeatherlightGallery: No compatible swipe library detected; one must be included before featherlightGallery for swipe motions to navigate the galleries.
c @ featherlight.gallery.min.js:7
(anonymous) @ featherlight.gallery.min.js:7
(anonymous) @ featherlight.gallery.min.js:7

Big puctures support (zoom in/zoom out)

Mi image is 1763x2163

I want to view it fullscreen. I use this line to show:

![](1_1.jpg?lightbox&resize=600)

How it looks in featherlight mode:
image

This same result with line ![](1_1.jpg?lightbox=1763,2163&resize=600)

It would be very nice to be able to enlarge the image like in lightGallery plugin. Default:
image

Zoom in:
image

(it also supports zoom steps etc)

P.S. I also saw the Premium Lightbox Gallery. Does it support zoom correctly?

Classes ignored for lightbox images

Grav allows adding image HTML attributes like classes or an id:
https://learn.getgrav.org/content/image-linking#image-attributes

When I enable lightbox on an image, this functionality breaks. For example this markup renders the image with my classes:
![Alt text](image.png?classes=deskw-50,border,rounded,border-success,p-3)

While this markup enables the lightbox, but my classes are not present:
![Alt text](image.png?lightbox=500&classes=deskw-50,border,rounded,border-success,p-3)

I'm using the latest grav-plugin-featherlight (v1.5.0).

featherlight gallery shows images of all page folders?

Hi,
I have a modular page.
My images in different page folders using lightbox effect. I activated gallery mode in featherlight plugin. So this works. Now all images of all page folders with lightbox effect are shown in gallery. I want only to show those images in gallery that are in one page folder. So the gallery should work for a single page folder and not for all page folders. Is this possible?
Another point:
On a modular page it is not possible to override featherlight settings in page headers. Not working, no effect.

Images have '@1x' burned in

Hi,
On all images when using Featherlite, I see '@1x' burned in to the top left corner. Is this working as designed? Can I turn this off?

Example: ![](piHAT1-1200.jpg?lightbox=1200&resize=600)
image

(Apologies if this is a feature and I'm just misusing the plugin as I don't use many images.)

Opens Image in new page only

Greetings,

so, in markdown I put ...

![logo](../logo.png?lightbox)

But all it does is open the logo in a new window, no lightbox. Suggestions?

Control options halfway hidden

The control options are halfway hidden with the default CSS. I fixed it for me by simply deleting the content of youtube.css. See the bottom of the screen. That is actually how it looks.
screen shot 2017-08-13 at 19 41 37

New release?

@rhukster Can you create a release since the last is 5 years old and important patches #30 are merged over a year ago? Thanks

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.