Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wwwebman/b9c10ec3569b96452ca20d66deae0124 to your computer and use it in GitHub Desktop.
Save wwwebman/b9c10ec3569b96452ca20d66deae0124 to your computer and use it in GitHub Desktop.
How to init the PhotoSwipe Plugin by dimsemenov for JavaScript gallery (Webpack + Babel + ES6 + pureJS)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML that will be parsed by dimsemenov PhotoSwipe-JavaScript-gallery</title>
</head>
<body>
<div class="m-gallery g6" itemscope itemtype="http://schema.org/ImageGallery">
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="http://placehold.it/1024x612" itemprop="contentUrl" data-size="1024x612">
<img src="http://placehold.it/450x270" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption</figcaption>
</figure>
<figure itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="http://placehold.it/1024x612" itemprop="contentUrl" data-size="1024x612">
<img src="http://placehold.it/450x270" itemprop="thumbnail" alt="Image description" />
</a>
<figcaption itemprop="caption description">Image caption</figcaption>
</figure>
</div>
<script src="assets/js/bundle.js" defer></script>
</body>
</html>
@Birowsky
Copy link

Sorry, could you help clarify how are the styles included?

@wwwebman
Copy link
Author

wwwebman commented Jul 24, 2019

Sorry, could you help clarify how are the styles included?

Hi! I have added this gist long time ago, cannot even remember how it works :). Also not sure if i got you right.

  1. If question was "how to add styles?" then you can check next options:
    Option 1: SASS + webpack -> dimsemenov/PhotoSwipe#1374 (comment)
    Option 2: https://photoswipe.com/documentation/getting-started.html -> 'Step 1: include JS and CSS files'

  2. If styles added and you wounder how then pls prepare demo in codesandbox.io. Maybe I can help you then.

@Birowsky
Copy link

Thanx a lot for offering your help!

I ended up figuring it out for myself. I am building a lit-element wrapper for photo-swipe, and this is how I set up the styles:

  static get styles() {
    return [
      css(require('photoswipe/dist/photoswipe.css').toString()),
      css(require('photoswipe/dist/default-skin/default-skin.css').toString()),
      `,
    ];
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment