Giter Site home page Giter Site logo

sachinchoolur / lightgallery.js Goto Github PK

View Code? Open in Web Editor NEW
5.3K 107.0 598.0 55.78 MB

Full featured JavaScript image & video gallery. No dependencies

Home Page: https://sachinchoolur.github.io/lightgallery.js/

License: Other

JavaScript 65.85% CSS 34.15%
gallery video-gallery image-gallery lightbox lightbox-gallery-plugin thumbnails youtube vimeo html5-video css-animations

lightgallery.js's Introduction

lightgallery.js

travis bower npm

Full featured JavaScript lightbox gallery. No dependencies.

lightgallery

Important notice

  • lightgallery.js has been merged with lightGallery. That means, v2 of lightgallery.js is https://www.lightgalleryjs.com/. if you have a lightgallery.js license, this is valid for lightGallery as well. But, since version 2.0 you need to pass the license key as a plugin option. If you alredy have a license, please contact me at [email protected] for the license key
  • Completely re-wrote from scratch in typescript
  • Moved all modules to the main repo for better maintainability.
  • Dropped IE 8 and 9 support. Let me know if you still need support for IE 8 and 9. I’ll consider adding a plugin to add support if there is enough demand.
  • Website
  • Docs
  • Demos
Any questions, ideas, suggestions about v2? please start a discussion.

New features

  • Pinch to zoom
  • Virtual slides
  • Swipe to close
  • Zoom from the origin
  • Inline gallery
  • Next-generation image formats support(webp, JPEG XL). etc
  • Better customizability
  • Better performance on mobile devices.
  • Dynamically add, remove slides while the gallery is open
  • Comment interface
  • and much more.

How to upgrade

To make the upgrade seamless, v2 follows the API structure as much as possible. But, few settings are removed and a lot of additional settings are added, the way we use public methods is changed slightly and few events are renamed.

Initialization V2 doesn’t require jQuery as a dependancy.

lightGallery(document.getElementById('lightgallery'), {
  plugins: [lgZoom, lgThumbnail,]
  speed: 500
  ... other settings
});

Plugins To avoid polluting global scope, since v2 plugins has to be passed via settings.

lightGallery(document.getElementById(‘’lightgallery), {
    
plugins: [lgZoom, lgAutoplay, lgComment, lgFullscreen , lgHash, lgPager, lgRotate, lgShare, lgThumbnail, lgVideo]
});
  • Removed in-built support for Dailymotion VK. We Will be adding separate plugins for DailyMotion and VK support
  • Added Wistia support
  • HTML videos - Videos can be passed via data-video attribute instead of passing it via hidden div
data-video='{"source": [{"src":"/videos/video1.mp4", "type":"video/mp4"}], "attributes": {"preload": false, "controls": true}}'
  • Events are renamed - Please take a look at the documentation
  • Few settings are added, removed, or renamed. Rather than listing down all the changes here, I’d recommend going through the current settings that you are using and compare them with the new documentation.



Main features

  • Fully responsive.
  • Modular architecture with built in plugins.
  • Touch support for mobile devices.
  • Mouse drag supports for desktops.
  • Double-click/Double-tap to see actual size of the image.
  • Animated thumbnails.
  • Social media sharing.
  • YouTube, Vimeo, Dailymotion, VK and HTML5 video support.
  • 20+ Hardware-Accelerated CSS3 transitions.
  • Dynamic mode.
  • Full screen support.
  • Supports zoom.
  • Browser history API.
  • Responsive images.
  • HTML iframe support.
  • Multiple instances on one page.
  • Easily customizable via CSS (SCSS) and Settings.
  • Smart image preloading and code optimization.
  • Keyboard Navigation for desktop.
  • Font icon support.
  • Rotate, flip images.
  • Accessibility support.
  • And many more.

Browser support

lightgallery supports all major browsers including IE 9 and above.

Installation

Install with NPM

You can install lightgallery.js using the npm package manager.

npm install lightgallery.js

You can also find lightgallery.js on Yarn and Bower.

Yarn

yarn add lightgallery.js

Bower

bower install lightgallery.js --save

CDN

http://www.jsdelivr.com/projects/lightgallery.js

Download from GitHub

You can also directly download lightgallery from GitHub.

Include CSS and JavaScript files

First of all add lightgallery.css in the <head> of the document.

<head>
    <link rel="stylesheet" href="css/lightgallery.css">
</head>

Then include lightgallery.min.js into your document. If you want to include any lightgallery plugin you can include it after lightgallery.min.js.

<body>
    ...

    <script src="js/lightgallery.min.js"></script>

    <!-- lightgallery plugins -->
    <script src="js/lg-thumbnail.min.js"></script>
    <script src="js/lg-fullscreen.min.js"></script>
</body>

Lightgallery also supports AMD, CommonJS and ES6 modules. When you use AMD make sure that lightgallery.js is loaded before lightgallery modules.

require(['./lightgallery.js'], function() {
    require(["./lg-zoom.js", "./lg-thumbnail.js"], function(){
        lightGallery(document.getElementById('lightgallery'));
    });
});

The markup

lightgallery does not force you to use any kind of markup. You can use whatever markup you want. But i suggest you to use the following markup. Here you can find the detailed examples of different kinds of markup.

<div id="lightgallery">
    <a href="img/img1.jpg">
        <img src="img/thumb1.jpg">
    </a>
    <a href="img/img2.jpg">
        <img src="img/thumb2.jpg">
    </a>
    ...
</div>

Call the plugin

Finally you need to initiate the gallery by adding the following code.

<script>
    lightGallery(document.getElementById('lightgallery'));
</script>

Support lightgallery

If you like lightgallery please support the project by staring the repository or tweet about this project.

Resources

Demos

Built in modules

  1. Thumbnail - GItHub - Docs
  2. Autoplay - GItHub - Docs
  3. Video - GItHub - Docs
  4. Fullscreen - GItHub - Docs
  5. Pager - GItHub - Docs
  6. Zoom - GItHub - Docs
  7. Hash - GItHub - Docs
  8. Share - GItHub - Docs
  9. Rotate - GItHub - Docs

License

Commercial license

If you want to use lightgallery.js to develop commercial sites, themes, projects, and applications, the Commercial license is the appropriate license. With this option, your source code is kept proprietary. Read more about the commercial license

Open source license

If you are creating an open source application under a license compatible with the GNU GPL license v3, you may use this project under the terms of the GPLv3.

lightgallery.js's People

Contributors

a2wd avatar blimpage avatar boboldehampsink avatar dependabot[bot] avatar domoritz avatar gdimitrov-propy avatar kudlatyamroth avatar limonte avatar maistho avatar ryanzim avatar sachinchoolur avatar sachinds avatar xhmikosr 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  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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lightgallery.js's Issues

Adding lg-video resizes all gallery frames

I am trying to do a mix media gallery of images, videos, and some iframe content.

I notice that when I add the lg-video script that all the media will resize.

Is there a way to make the video resize only happen on a per slide basis to avoid this?

util.js window & document getAttribute/setAttribute not working with google maps streetview

Problem
If you are using lightgallery.js with google maps on the same page (both libraries included) and want to use Google Maps Street View you will not be able to, because the lightgallery hardcoded functions for "getAttribute" and "setAttribute" on window and document will conflict with Google Maps Street View

Request
Remove these functions from window and document and use a util function instead.

Pull Request already added to #68

Preload option starts playing YouTube videos

Right now if you click an adjacent gallery item to a video, the video will start playing. Disabling preload fixes the issue. Ideally, preload should only affect photos, not video.

Video play - adding multiple CSS classes breaks

Greetings,

the original code for addClass breaks when adding lg-video-playing lg-has-video classes.

Using version: lightgallery.js | 0.0.2 | August 4th 2016

Error:
lightgallery.min.js:7 Uncaught InvalidCharacterError: Failed to execute 'add' on 'DOMTokenList': The token provided ('lg-video-playing lg-has-video') contains HTML space characters, which are not valid in tokens.

I made a quick workaround for myself (not production code):

addClass: function addClass(el, className) {
if (!el) {
return;
}
if (el.classList) {
var classArray = className.split(' ');
for(var i = 0, len = classArray.length; i < len; i++){
el.classList.add(classArray[i]);
}

        } else {
            el.className += ' ' + className;
        }
    },

With regards,

Marko

Using video plugin and image display breaks images

When installed video plugin and having two different list, one for videos and other with images, the image visualization breaks, because the plugin is installed globally (under window variable) so it expect it for every lightgallery instance, which is not the case for a normal image gallery.

I would say that this happens for all plugins. If there is any gallery is forced to use all the installed plugin

containing gallery inside an element

Hi;
I want to use the fixed dims gallery as a kind of a carousel (https://sachinchoolur.github.io/lightgallery.js/demos/fixed-size.html)
however, I want the carousel to be contained inside a specific element of my choice. looking at this code it looks like no matter what there is a full size overlay in the back ground that is 'not containable'
is there a way to achieve what i need?
for example, my website has a header that I do not want to cover with the gallery overlay. but I would just like it to not overflow from the element I want it to be in.
thanks!

Importing to React

I am trying to import this into React. I keep getting an empty object. I am not sure if I am doing it incorrectly or if there is an issue.

import lightGallery from 'lightgallery.js';
console.log(lightGallery); // returns Object {}

thanks

Uncaught TypeError: Cannot read property 'match' of null

I'm setting up lightgallery.js for a website and am running into an issue with it using version 0.0.3.

The error message is:

Uncaught TypeError: Cannot read property 'match' of null

Running the non-minified script fails at line 638, which contains:

var youtube = src.match(/\/\/(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=|embed\/)?([a-z0-9\-\_\%]+)/i);

Here's the relevant markup (which uses the Pure CSS framework):

<section class="content">
  <h1 class="text-centered">Gallery</h1>
  <div id="lightgallery" class="pure-g">
    <div class="pure-u-1 pure-u-sm-1-2">
      <a href="/media/gallery/1.jpg">
        <img src="/media/gallery/1.jpg" class="pure-img">
      </a>
    </div>
    <div class="pure-u-1 pure-u-sm-1-2">
      <a href="/media/gallery/2.jpg">
        <img src="/media/gallery/2.jpg" class="pure-img" >
      </a>
    </div>
    <div class="pure-u-1 pure-u-sm-1-2">
      <a href="/media/gallery/3.jpg">
        <img src="/media/gallery/3.jpg" class="pure-img" >
      </a>
    </div>
    <div class="pure-u-1 pure-u-sm-1-2">
      <a href="/media/gallery/4.jpg">
        <img src="/media/gallery/4.jpg" class="pure-img" >
      </a>
    </div>
  </div>
</section>

And the JavaScript used to initialize it:

<script src="/assets/js/lightgallery.js"></script>
<script>
  lightGallery(document.getElementById('lightgallery'));
</script>

I'm not using any other JavaScript files on that site, not even jQuery. Note that it used to work for a small while, but I can't remember why.

I can reproduce this behavior with both Chromium 52 and Firefox 48.

lightgallery.js:628 Uncaught Error: Make sure that slide 0 has an image/video src

<!-- data-src should not be provided when you use html5 videos -->
<ul id="html5-videos">
  <li data-poster="video-poster1.jpg" data-sub-html="video caption1" data-html="#video1" >
      <img src="img/thumb1.jpg" />
  </li>
  <li data-poster="video-poster2.jpg" data-sub-html="video caption2" data-html="#video2" >
      <img src="img/thumb2.jpg" />
  </li>
</ul>

Launch Gallery from Button(link)

Hello,
Is it possible to launch a gallery by clicking on a button(link), instead of clicking a thumbnail?

I'm trying to do this with the list of images already on the page in HTML.

Thank you

"isVideo" function will never return "true" for html5?

In the isVideo() function there is a test for src which throws an error if a src is not provided. Cool. But later there is this:

    if (!src && html) {
        return {
            html5: true
     };

If src is "falsey" then we would never get that far. I'm running into this while trying to sort out why I can't get dynamic html5 video to work with lightgallery.js in an Electron desktop project.

I don't know if the above is a bug or not (not a JS hero...) but changing that to affirmative tests (if src && html) seems to give a correct result.

In context:

Plugin.prototype.isVideo = function(src, index) {

    if(!src) {
        throw new Error("Make sure that slide " + index + " has an image/video src");
    }

    var html;
    if (this.s.dynamic) {
        html = this.s.dynamicEl[index].html;
    } else {
        html = this.items[index].getAttribute('data-html');
    }

    if (!src && html) {
        return {
            html5: true
     };
}

//etc

Integrate viewerjs via plugin

Plan is to integrate http://viewerjs.org with this gallery via plugin. Idea is inspired by Google Inbox style preview for attachments. Previews of supported files will be achieved by viewerjs and displayed through lightgallery.

It would be helpful to know, from the makers of this plugin, how much of this integration is possible without changing core and only relying on Plugin API. Also guidelines would be of great help while developing such integration or untill I'm more familiar with plugin internals.

I am interested whether this would benefit project and would be of use to community. Help and ideas are welcomed and appreciated.

justifyedGallery alternatives

Hi,
sorry, this is not completely about lightgallery.js but i think i can have an answer here..

i am trying to implement lightgallery.js in a React.js project and i like the way justifiedGallery arrange the photos but i cannot use it with react because it is a jQuery plugin.
Did someone found an alternative that can be used for the lightgallery.js markup structure without jQuery needed?
Thank you!

Vimeo Javascript

This should be updated to use the new Vimeo javascript API and not Froogaloop as it's deprecated now. The new player API is far better.

Any idea if this is going to happen? Or is this project now dead? There haven't been any commits in a good long time.

Woff2 support for the font

It would be great if the custom font could be provided in woff2 format as well, as it is supported by most browsers and is more efficient than woff (and so should be the preferred format for supporting browsers)

Touch-Swipe not working

On iOS 9.3.3 (Safari and Chrome), the swipe gesture to next/prev does not work. Nothing happens if i swipe right/left.

ES6/ES2015 import

Would appreciate it if you can include in the README examples of how the library and its modules can be imported using the ES6 import statement.

sass files in npm version

Hello. This is just a suggestion, but I've installed the npm version of your plugin and I've been loving it, so far.

I'd just like to inquire about the possibility of adding the sass files to it, rather than just the lib and dist files.

Thank you very much for your attention, and please keep up the great work!

Pinch to Zoom

Not so much an issue then a question.
Does this support pinch to zoom vs just the button click?

Lazy loading

This is just a proposal but what about lazy loading?
thanks!

Prefer data-src attribute instead href (iframe links)

I have added a google maps lightbox on a page and it works fine, using either the "href" and "data-src" attributes.

However, when I add both of them the "href" seems to be stronger. This is an issue because I would like to

  • single click: open the map in a lightbox (using "data-src" with the embed link)
  • middle click: open the google maps page (using "href" with the normal link)

When both attributes are present, middle click works fine (uses the "href" value), but single click also uses "href" data instead "data-src".

Is there a way I can force this behaviour or is there a workaround? My best guess is to use "noscript" tag but that's ugly.

License.md

Can you add license.md? I see Apache-2.0 ref in package.json and bower.json.

Plugins with webpack

First off, thanks for the awesome plugin, and rewriting it without dependencies.

I am using the lightgallery portion successfully, but am unable to get the plugins working. I am trying to use lg-zoom.js and lg-fullscreen.js. I tried the nested requires like you had an example of to no success. I have tried several methods of using webpack loaders for exporting or importing variables into the module. If you or any other users have an idea on how to fix this it would be greatly appreciated.

My setup looks like

require('lightgallery.js');
require('lg-zoom.js');
require('lg-pager.js');
require('lg-fullscreen.js');

export default (function () {
  $('document').ready(() => {
    lightgallery($('#lightgallery')[0]);

    $('.dwnld').click(function(ev) {
      ev.preventDefault();
      $(this).text('Preparing Download…');
      var $form = $('#download-form');
      $form.submit();
    });
  });
})();

Several galleries on the same page

I would like to know if it is possible to have several image galleries on the same page at the same time, they would be gallery of few images, about 5 or 6. I have tried with the demo to duplicate the four images and works well with the first four, but with the Next group does not work.

Destroying lightgallery.js?

I can't destroy the lightgallery, I'm using

lightGallery().destroy()

is this the right way to destroy this lib? Also I can't get this to work with webpack

Webpack usage

Hello,

I cannot figure out how I can use lightgallery with webpack.

I tried

var lightGallery = require('lightgallery.js');
lightGallery( document.getElementById('lightgallery') );

and

require('lightgallery.js');

$(document).ready(function(){
    lightGallery( document.getElementById('lightgallery') );
});

but none works.

Could you help, please ?

Hover titles on the icons

Hi,

First of all great implementation! What I am missing is a hover title on the icons. A title which describes what the click on the icons will do.

Thanks. Keep up the great work,
Wolfgang

destroy only works once

Hi,
I'm currently building a website and using lightGallery in combination with Justified Gallery. I ran into a problem when filtering images and therefore destroying and reinitialize lightGallery with the remaining pictures.

As long as I haven't clicked on a picture or so to speak opened the gallery, the gallery gets correctly destroyed and repopulated with the remaining pictures after filtering (let's say with architecture-pictures). But clicking on any pictures before filtering leads to this.thumbOuter.parentNode is null in lg-thumbnail.min.js:7:8883.

I initialize the gallery as follows:

$(document).ready(function() {
    var gallery = document.getElementById('lightgallery');
    lightGallery(gallery, {
        selector: ".itemlg",
        mode: "lg-fade",
        hideBarsDelay: 1000
    });
});

Then filtering by clicking on a button.

$(document).ready(function() {
    $(this).on("click", "#architecture", function() {
        //causes the error
        window.lgData[gallery.getAttribute("lg-uid")].destroy(true);

        jQuery("#mygallery").justifiedGallery({
            filter: ".architecture",
        });

        gallery = document.getElementById('lightgallery');
        lightGallery(gallery, {
            selector: ".architecture",
            mode: "lg-fade",
            hideBarsDelay: 1000
        });
    });
});

I don't think that's intended. Or maybe I missed a point.

hideControlOnEnd hiding right arrow for 1st slide when there are more slides?

Should this code be

                if (index > 0) {
                    prev.removeAttribute('disabled');
                    _lgUtils2.default.removeClass(prev, 'disabled');
                } else {
                    next.setAttribute('disabled', 'disabled');
                    _lgUtils2.default.addClass(next, 'disabled');
                }

like this?

                if (index > 0) {
                    prev.removeAttribute('disabled');
                    _lgUtils2.default.removeClass(prev, 'disabled');
                } else {
                    prev.setAttribute('disabled', 'disabled');
                    _lgUtils2.default.addClass(prev, 'disabled');
                }

This fixed the issue for me.

Mixed content warnings for gh-pages

I tried to fix it myself but I can't checkout the gh-pages branch on Windows.

xmr@xmr-PC ~
$ cd /c/Users/xmr/Desktop/lightgallery.js/

xmr@xmr-PC /c/Users/xmr/Desktop/lightgallery.js
$ git checkout -b gh-pages remotes/origin/gh-pages
fatal: cannot create directory at 'lightgallery/sass/C:': Invalid argument

The fix should be pretty easy; just use https for all links and scripts.

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.