• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1{%- include scripts/utils/imagesLoad.js -%}
2(function () {
3  var SOURCES = window.TEXT_VARIABLES.sources;
4  window.Lazyload.js(SOURCES.jquery, function() {
5    var $pageGalleryModal = $('.js-page-gallery-modal');
6    var $images = $('.page__content').find('img:not(.lightbox-ignore)');
7    window.imagesLoad($images).then(function() {
8      /* global Gallery */
9      var pageGalleryModal = $pageGalleryModal.modal({ onChange: handleModalChange });
10      var gallery = null;
11      var modalVisible = false;
12      var i, items = [], image, item;
13      if($images && $images.length > 0) {
14        for (i = 0; i < $images.length; i++) {
15          image = $images.eq(i);
16          if (image.get(0).naturalWidth > 800) {
17            items.push({ src: image.attr('src'), w: image.get(0).naturalWidth, h: image.get(0).naturalHeight, $el: image});
18          }
19        }
20      }
21
22      if(items.length > 0) {
23        gallery = new Gallery('.gallery', items);
24        gallery.setOptions({ disabled: !modalVisible });
25        gallery.init();
26        for (i = 0; i < items.length; i++) {
27          item = items[i];
28          item.$el && (item.$el.addClass('popup-image'), item.$el.on('click', (function() {
29            var index = i;
30            return function() {
31              pageGalleryModal.show();
32              gallery.setOptions({ initialSlide: index });
33              gallery.refresh(true, { animation: false });
34            };
35          })()));
36        }
37      }
38
39      function handleModalChange(visible) {
40        modalVisible = visible;
41        gallery && gallery.setOptions({ disabled: !modalVisible });
42      }
43
44      $pageGalleryModal.on('click', function() {
45        pageGalleryModal.hide();
46      });
47    });
48  });
49})();