You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 line
1.3 KiB

  1. import './gallery.scss';
  2. import $ from 'jquery';
  3. import {createElement} from "../../_global/scripts/helpers";
  4. import {galleryData} from "./GalleryData";
  5. import Gallery from "./gallery";
  6. export const createGallery =
  7. ({
  8. galleryType = 'grid',
  9. itemsPerPage = 9,
  10. data = galleryData,
  11. }) => {
  12. const thumbWidth = galleryType === 'single-image' || galleryType === 'first-image' ? 880 : 300;
  13. const section = createElement('section', ['gallery'], null, null);
  14. section.dataset.type = galleryType;
  15. section.dataset.perPage = itemsPerPage.toString();
  16. const wrapper = createElement('div', ['gallery-wrapper'], '', section);
  17. data.map((item) => {
  18. const imageDiv = createElement('div', ['image'], '', wrapper);
  19. const thumbHeight = Math.round(thumbWidth / parseInt(item.width) * parseInt(item.height));
  20. imageDiv.dataset.thumb = item.src.replace(item.width, thumbWidth.toString()).replace(item.height, thumbHeight.toString());;
  21. imageDiv.dataset.full = item.src;
  22. imageDiv.dataset.width = item.width;
  23. imageDiv.dataset.height = item.height;
  24. if (item.copyright) {
  25. imageDiv.dataset.copyright = item.copyright;
  26. }
  27. })
  28. $(document).ready(() => {
  29. new Gallery($(section));
  30. })
  31. return section;
  32. };