Blame view

js/start-swipe.js 1.64 KB
ee3cea15   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  (function($) {
  
      var $pswp = $('.pswp')[0];
      var image = [];
  
      $('.reviews_gallery-wr').each( function() {
          var $pic     = $(this),
              getItems = function() {
                  var items = [];
                  $pic.find('figure a').each(function() {
                      var $href   = $(this).attr('href'),
                          $size   = $(this).data('size').split('x'),
                          $width  = $size[0],
                          $height = $size[1];
  
                      if(!($(this).data('type') == 'video')){
                          var item = {
                              src : $href,
                              w   : $width,
                              h   : $height
                          }
                      } else {
                          item = {
                              html: '<div class="wrapper">' + $(this).data('video') + '</div>'
                          };
  
                      }
  
  
  
                      items.push(item);
                  });
                  return items;
              }
  
          var items = getItems();
  
          $.each(items, function(index, value) {
              image[index]     = new Image();
              image[index].src = value['src'];
          });
  
          $pic.on('click', 'figure', function(event) {
              event.preventDefault();
              var $index = $(this).index();
              var options = {
                  index: $index,
                  bgOpacity: 0.7,
                  showHideOpacity: true,
                  shareEl: false
              }
  
              var lightBox = new PhotoSwipe($pswp, PhotoSwipeUI_Default, items, options);
              lightBox.init();
          });
      });
  
  })(jQuery);