npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery.photoswipe

v1.1.1

Published

The jQuery plugin for PhotoSwipe

Downloads

580

Readme

This is a jQuery plugin for the PhotoSwipe that allow you to setup PhotoSwipe with just a few code.

Usage

Step 1. Include JS and CSS files

The CSS files are provided by PhotoSwipe, you can find them in the dist folder of PhotoSwipe's GitHub repository.

Note that this plugin already included the PhotoSwipe, so you don't have to include it yourself.
Also, you can access the PhotoSwipe class by referring $.fn.photoSwipe.PhotoSwipe.

I recommend that you install this plugin by NPM npm install jquery.photoswipe.

<!-- CSS file -->
<link rel="stylesheet" href="path/to/photoswipe.css">
<link rel="stylesheet" href="path/to/default-skin/default-skin.css">

<!-- JS file -->
<script src="path/to/jquery.js"></script>
<script src="path/to/jquery.photoswipe-global.js"></script>

The markup is something like this.

<div id="gallery">
    <!-- 
    You can specify the following attribute for a img tag
    
      `data-original-src` : The url of original image 
      `data-original-src-width` : The width of original image 
      `data-original-src-height` : The height of original image
      
      ** About the caption text **
      The plugin will try to find the caption text from:
      1. `data-caption-class` attribute
         The value is a class name that indicates the element which contains the caption text.
         
      2. `figcaption` element
         The `figcaption` element that resides inside a `figure` which contains the slide `img` element.
         
      3. `alt` attribute
         The `alt` attribute of the slide `img` element.
    -->
    <img src="images/IMG_2969--thumbnail.jpg" data-original-src="images/IMG_2969.jpg" data-original-src-width="2000" data-original-src-height="2000" alt="caption text">

    <!-- 
    If the `data-original-src` not exists, `src` will be used. 
    If the `data-original-src-width` or `data-original-src-width` not exists, the natural width and height of the `src` will be used.
    If the file name of `src` matches the pattern `/(\d+)[*×x](\d+)/` (e.g. images/IMG_3012-1200x800.jpg), the plugin will takes width and height from the file name.
    (That way you don't need to specify the `data-original-src-width` and `data-original-src-width`).
    -->
    <img src="images/IMG_3012.jpg">
</div>

Step 2. Setup PhotoSwipe

Suppose you have the above markup, then just simply call the photoSwipe() method, you're done.

$('#gallery').photoSwipe();

Options

There are three parameters of the method photoSwipe.

Syntax

$gallery.photoSwipe(slideSelector, options, events);

Here is a sample code use all the three parameters.

var slideSelector = 'img',
    options     = {bgOpacity: 0.8},
    events      = {
        close: function () {
            console.log('closed');
        }
    };

$('#gallery').photoSwipe(slideSelector, options, events);

Update gallery

After adding or removing slides of a gallery dynamically, all you need to do is $('#gallery').photoSwipe('update') to update the gallery.

ECMAScript 6

The source code is written in ECMAScript 6 (Browserify + Babelify), so you can easily import it by

import PhotoSwipeMounter from 'jquery.photoswipe';

PhotoSwipeMounter(jQuery); // mount this plugin into jQuery

Also you should install it by npm install jquery.photoswipe.

Have fun!!