PageSourceSearch

https://auburnrehab.com/wp-content/plugins/gallery-by-supsystic/sr…/Galleries/assets/js/frontend.js?ver=1.17.1

js auburnrehab.com collected 2026-10-08 04:28:17 UTC 101,304 bytes, 2,902 lines download raw bytes

1(function ($, undefined) {
2  window.supSocialSharePrintImage = function (img) {
3    var printFrame = document.createElement('iframe');
4    printFrame.style.display = 'none';
5    document.body.appendChild(printFrame);
6    var printDocument = printFrame.contentWindow.document;
7    printDocument.write('<img style="max-width:100%;" src="' + img + '">');
8    printDocument.close();
9    printFrame.contentWindow.print();
10  };
11
12  jQuery('[data-video-source]').attr('rel', 'video');
13
14  var init = false;
15
16  function Gallery(selector, autoInit) {
17    autoInit = autoInit || false;
18    var $deferred = jQuery.Deferred(),
19      self = this;
20    this.loadedFonts = [];
21
22    this.$container = $(selector);
23    if (window.sggIsMobile) {
24      this.$container.attr('data-is-mobile', window.sggIsMobile[0]);
25    }
26    this.$container.addClass('fitvidsignore');
27    this.$elements = this.$container.find('figure.grid-gallery-caption').fadeIn();
28    this.initialMargin = this.$elements.first().css('margin-bottom');
29    this.$navigation = this.$container.find('nav.grid-gallery-nav');
30
31    this.selectedCategory = '';
32
33    this.galleryContainerId = this.$container.attr('id').replace(/[^a-z0-9]/g, '');
34
35    this.$qsData = null;
36    this.$qsDuration = '750';
37    this.$qsEnable = false;
38    this.areaPosition = this.$container.data('area-position'); // I think we wil need this in future
39
40    this.pagination = {
41      currentPage: 1,
42      limit: 0,
43      total: this.$elements.length,
44      pages: 1,
45      $wrapper: this.$container.find('.grid-gallery-pagination-wrap'),
46    };
47
48    this.loadingText = this.$container.data('show-more-loading-text');
49
50    this.popupTranslates = this.$container.data('popup-i18n-words');
51    if (this.$container.data('exif-as-popup') == 1) {
52      this.popupTitleAttribute = 'data-exif-text';
53    } else {
54      this.popupTitleAttribute = this.$container.data('popup-image-text');
55    }
56    this.popupMaxHeight = '90%';
57    this.popupMaxWidth = '90%';
58    this.popup_opened_image = false;
59    this.popupImageDimension = function () {};
60    this.resizeColorbox = function () {};
61
62    this.socialSharing = this.$container.data('social-sharing');
63    this.socialSharingWrapperClass = 'supsystic-grid-gallery-image-sharing';
64    this.socialSharingImageOperators = {
65      pinterest: 'media',
66    };
67    this.socialButtonsUrl = window.location.href.replace(window.location.hash, '');
68    this.socialButtonsUrl = this.removePopUpHashFromUrl(this.socialButtonsUrl);
69    if (this.socialButtonsUrl.indexOf('#') + 1 == this.socialButtonsUrl.length) {
70      this.socialButtonsUrl = this.socialButtonsUrl.substr(0, this.socialButtonsUrl.length - 1);
71    }
72
73    this.disablePopupHistory = !!this.$container.data('popup-disable-history');
74
75    if (this.isFluidHeight()) {
76      this.$elements.addClass('wookmarked');
77    }
78
79    $(document).trigger('GalleryExtend', this);
80
81    if (autoInit) {
82      // Interval check for init gallery when container becomes visible.
83      // This need to properly load gallery from tabs, accordions or any other hidden containers.
84      self.$container.data(
85        'isVisible',
86        setInterval(function () {
87          if (self.$container.is(':visible') || self.$container.hasClass('hidden-item')) {
88            clearInterval(self.$container.data('isVisible'));
89            self.init();
90          }
91        }, 500)
92      );
93    }
94
95    //Add init flag
96    this.$container.addClass('initialized');
97    return $deferred.resolve();
98  }
99
100  Gallery.prototype.isFluidHeight = function () {
101    return this.$container.is('.grid-gallery-fluid-height');
102  };
103
104  Gallery.prototype.isImageOverlay = function () {
105    return this.$container.find('.crop').is('.image-overlay');
106  };
107
108  Gallery.prototype.isMouseShadowShow = function () {
109    return this.$container.find('.grid-gallery-caption').is('.shadow-show');
110  };
111
112  Gallery.prototype.initQuicksand = function () {
113    if (this.$container.data('quicksand') == 'enabled' && this.$container.data('caption-builder-icons') !== 1) {
114      this.$qsEnable = true;
115      this.$qsDuration = this.$container.data('quicksand-duration');
116      this.$qsHolder = this.$container.find('.grid-gallery-photos:first');
117      this.$qsData = this.$container.find('.grid-gallery-photos > a');
118    }
119  };
120
121  Gallery.prototype.showCaption = function () {
122    var isExifCaption = this.$container.data('exif-as-caption');
123    this.$container.find('.grid-gallery-figcaption-wrap').each(function () {
124      if ($.trim($(this).html()) === '' && !$(this).find('img').length && $(this).has('.hi-icon').length === 0) {
125        $(this).closest('figcaption').remove();
126      }
127    });
128
129    this.$container.find('.gg-image-caption').each(function () {
130      var $this = $(this),
131        captionHtmlEntry = '';
132      if (isExifCaption == 1) {
133        var $objExist = $this.find('object');
134        if ($objExist.length) {
135          captionHtmlEntry = $this
136            .find('object')
137            .html()
138            .replace(/<a(.*?)>(.*?)<\/a>/gi, "<object type='none'>$&</object>");
139        } else {
140          captionHtmlEntry = $this.html();
141        }
142      } else {
143        captionHtmlEntry = $this.text().replace(/<a(.*?)>(.*?)<\/a>/gi, "<object type='none'>$&</object>");
144      }
145      $this.html(captionHtmlEntry);
146      $this.find('a').on('click', function (event) {
147        event.stopPropagation();
148      });
149    });
150
151    $(document).on('click', '.sliphover-container object a', function (event) {
152      event.stopPropagation();
153    });
154  };
155
156  Gallery.prototype.initWookmark = function () {
157    var self = this,
158      horizontalScroll = this.$container.data('horizontal-scroll'),
159      isMobile = parseInt($anyGallery.attr('data-is-mobile')),
160      width = this.$container.data('width'),
161      offset = 0,
162      outerOffset = 0,
163      spacing,
164      windowWidth = $(window).width(),
165      isFixedColumn = this.$container.data('gridType') == 3;
166    // if responsive mode = 'one by one' and mobile -> run this method
167    if (horizontalScroll && horizontalScroll.enabled) {
168      if (horizontalScroll.responsiveMode == 1 && isMobile) {
169      } else {
170        return;
171      }
172    }
173    // not for Mosaic Gallery
174    if (this.$container.data('gridType') == 4) {
175      return;
176    }
177
178    if (this.$container.data('offset')) {
179      offset = this.$container.data('offset');
180    }
181
182    if (this.$container.data('padding')) {
183      outerOffset = parseInt(this.$container.data('padding'));
184    }
185
186    if (String(width).indexOf('%') > -1) {
187      var imagesPerRow = Math.floor(100 / parseInt(width));
188
189      spacing = offset * (imagesPerRow - 1) + outerOffset * 2;
190      width = ((this.$container.width() - spacing) / 100) * parseInt(width);
191
192      $.each(this.$container.find('img'), function () {
193        aspectRatio = $(this).width() / $(this).height();
194        $(this).width(width);
195        $(this).height(width / aspectRatio);
196      });
197    }
198
199    if (isFixedColumn) {
200      var defaultWidth = parseInt(width),
201        defaultHeight = parseInt(this.$container.data('height')),
202        koefWidthHeigth = defaultWidth > 0 && defaultHeight > 0 ? defaultHeight / defaultWidth : 1;
203    }
204
205    function resizeColumns() {
206      var columnsNumber = self.getResponsiveColumnsNumber();
207
208      spacing = offset * (columnsNumber - 1) + outerOffset * 2;
209      width = Math.floor(((self.$container.width() - spacing) / 100) * (100 / columnsNumber));
210
211      $.each(self.$elements, function (index, el) {
212        var $el = $(el),
213          $img = $el.find('img');
214        if ($img.length && !$el.hasClass('initialized')) {
215          var imageOriginalSize = self.getOriginalImageSizes($img.get(0)),
216            elWidth = imageOriginalSize.width,
217            elHeight = imageOriginalSize.height,
218            aspectRatio = elWidth / elHeight,
219            height = width / aspectRatio;
220
221          if (isFixedColumn && $img.attr('data-gg-remote-image') == 1) {
222            height = width * koefWidthHeigth;
223          }
224
225          $el.css({
226            width: width,
227            height: height,
228          });
229          if (!$img.hasClass('ggLazyImg')) {
230            $img.removeClass('ggNotInitImg');
231            self.polaroidCaptionCalculate($el);
232            if ($el.hasClass('initialized')) {
233              setTimeout(function () {
234                $el.trigger('refreshWookmark');
235              }, 350);
236            }
237          }
238        }
239      });
240      self.$container.find('.grid-gallery-photos').removeAttr('data-min-height');
241      return width;
242    }
243
244    if (this.$container.data('columns-number')) {
245      self.$container.find('figure:not(.initialized) img').css({
246        maxWidth: '100%',
247        width: '100%',
248        height: 'auto',
249      });
250
251      resizeColumns();
252    }
253
254    if (this.$container.data('width') !== 'auto' && !this.$qsEnable) {
255      this.wookmark = this.$elements
256        .filter(':visible')
257        .wookmark({
258          autoResize: true,
259          container: this.$container.find('.grid-gallery-photos'),
260          direction: this.areaPosition == 'right' ? 'right' : 'left',
261          fillEmptySpace: false,
262          flexibleWidth: !this.$container.data('columns-number'),
263          itemWidth: width,
264          offset: offset,
265          align: this.areaPosition,
266          outerOffset: outerOffset,
267          onLayoutChanged: function () {
268            setTimeout(function () {
269              self.$container.trigger('wookmark.changed');
270            }, 50);
271          },
272          onResize: function () {
273            if ($(window).width() != windowWidth) {
274              // Fix touchscreen resize event issue see #544
275              windowWidth = $(window).width();
276
277              clearTimeout(self.$container.data('resize.timer'));
278              self.$container.data(
279                'resize.timer',
280                setTimeout(function () {
281                  var overflow = self.$container.css('overflow');
282
283                  self.$container.removeData('resize.timer');
284                  self.$container.css('overflow', 'hidden');
285
286                  if (self.$container.data('columns-number')) {
287                    self.$elements.wookmark({
288                      container: self.$container.find('.grid-gallery-photos'),
289                      itemWidth: resizeColumns(),
290                      offset: offset,
291                    });
292                  }
293
294                  self.$elements.last().one('transitionend webkitTransitionEnd oTransitionEnd', function () {
295                    self.$elements.filter(':visible').trigger('refreshWookmark');
296                  });
297                  self.$elements.filter(':visible').trigger('refreshWookmark');
298                  self.$container.css('overflow', overflow);
299                }, 250)
300              );
301            }
302          },
303        })
304        .css({
305          margin: '0',
306          transition: 'all 0.4s linear',
307        });
308    }
309
310    this.$container.find('.grid-gallery-photos').css('text-align', this.$container.data('area-position'));
311    var minheight = this.$container.find('.grid-gallery-photos').data('min-height');
312    this.$container.find('.grid-gallery-photos').css({
313      'min-height': minheight,
314    });
315    this.$container.filter(':visible').find('.grid-gallery-photos > *').filter(':visible').css({
316      float: 'none',
317      display: 'inline-block',
318      'vertical-align': 'top',
319    });
320  };
321
322  Gallery.prototype.initControll = function () {
323    $(document).on('click', '#cboxRight', function () {
324      $.colorbox.prev();
325    });
326    $(document).on('click', '#cboxLeft', function () {
327      $.colorbox.next();
328    });
329  };
330
331  Gallery.prototype.getPopupDimensions = function (width, height) {
332    var width = $(window).width() < width ? '90%' : width;
333    var height = $(window).height() < height ? '90%' : height;
334
335    if (width == '90%') {
336      width = parseFloat(($(window).width() * parseFloat(width)) / 100);
337    }
338    if (height == '90%') {
339      height = parseFloat(($(window).height() * parseFloat(height)) / 100);
340    }
341
342    return {
343      width: width,
344      height: height,
345    };
346  };
347
348  /**
349   * Get popup title depending on gallery settings
350   * @return string title for popup image
351   */
352  Gallery.prototype.getPopupTitle = function ($element) {
353    var title, $img;
354
355    if ($element.hasClass('hi-icon')) {
356      $img = $element.closest('.grid-gallery-caption').find('img');
357    } else {
358      $img = $element.find('img');
359    }
360
361    title = $img.attr(this.popupTitleAttribute);
362
363    if (!title) {
364      title = $img.attr('title');
365    }
366
367    return title;
368  };
369
370  Gallery.prototype.initPopup = function () {
371    var popupType = (this.popupType = this.$container.data('popup-type')),
372      popupMaxWidth = this.popupMaxWidth,
373      popupMaxHeight = this.popupMaxHeight,
374      sW = this.$container.data('popup-widthsize'),
375      sH = this.$container.data('popup-heightsize'),
376      popupOverlayTransper = this.$container.data('popup-transparency'),
377      popupBackground = this.$container.data('popup-background'),
378      slidePlay = this.$container.data('popup-slideshow') === true,
379      slidePlayAuto = slidePlay && this.$container.data('popup-slideshow-auto') === true,
380      popupHoverStop = slidePlay && this.$container.data('popup-hoverstop') === true,
381      slideshowSpeed = this.$container.data('popup-slideshow-speed'),
382      popupPlacementType = this.$container.data('popup-placement-type'),
383      isLazyLoad = this.$container.data('lazyload-enable') == '1',
384      self = this;
385
386    function generateOverlayColor(selector, background, opacity, optype) {
387      var style = selector + '{',
388        rgb = self.hex2rgb(background);
389      opacity = (100 - opacity) / 100;
390
391      if (background) {
392        color = 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ', ' + opacity + ')';
393        style += 'background-image:none!important; background-color:' + color + '!important;';
394      } else {
395        if (optype) {
396          style += 'opacity:' + opacity + '!important;';
397        } else {
398          rgb = self.hex2rgb(self.rgb2hex($(selector).css('backgroundColor')));
399          color = 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ', ' + opacity + ')';
400          style += 'background-image:none!important; background-color:' + color + '!important;';
401        }
402      }
403      style += '}';
404      $('<style type="text/css"> ' + style + '</style>').appendTo('head');
405    }
406
407    if (!!sW && sW !== 'auto') {
408      popupMaxWidth = sW;
409    } else {
410      sW = '90%';
411    }
412    if (!!sH && sH !== 'auto') {
413      popupMaxHeight = sH;
414    } else {
415      sH = '90%';
416    }
417
418    var getImageDimension = function () {
419      return self.getPopupDimensions(sW, sH);
420    };
421
422    var getColorboxImageDimension = function () {
423      var response = self.getPopupDimensions(sW, sH);
424      if ($(self.popup_opened_image).children('figure').attr('data-linked-images') || $(self.popup_opened_image).hasClass('linked-element')) {
425        response.width -= 120;
426      }
427      return response;
428    };
429
430    var delayResize = (function () {
431      var timer = 0;
432      return function (callback, ms) {
433        clearTimeout(timer);
434        timer = setTimeout(callback, ms);
435      };
436    })();
437
438    this.resizeColorbox = function () {
439      if (self.popup_opened_image === false) return;
440      var dimensions = getColorboxImageDimension();
441      if (self.popup_opened_image.attr && self.popup_opened_image.attr('rel') == 'video' && dimensions.width >= 0.9 * window.innerWidth) {
442        return;
443      }
444
445      $(self.popup_opened_image).data('colorbox').maxWidth = dimensions.width;
446      $(self.popup_opened_image).data('colorbox').maxHeight = dimensions.height;
447
448      $(document).trigger('beforeResizeColorBoxResponsive', this);
449      delayResize(function () {
450        $.colorbox.resizeResponsive(self.popup_opened_image);
451      }, 500);
452    };
453
454    //Responsive popup if width or height > window.width
455    popupMaxWidth = $(window).width() < popupMaxWidth ? '90%' : popupMaxWidth;
456    popupMaxHeight = $(window).height() < popupMaxHeight ? '90%' : popupMaxHeight;
457
458    this.popupMaxWidth = popupMaxWidth;
459    this.popupMaxHeight = popupMaxHeight;
460    this.popupImageDimension = getImageDimension;
461
462    if (popupType && popupType !== 'disable') {
463      this.$container.parentsUntil('body').each(function () {
464        var events = $._data(this, 'events'),
465          el = this;
466
467        if (events && events.click) {
468          $.each(events.click, function (index, ev) {
469            if (ev.selector && self.$container.has($(ev.selector)).length) {
470              $(el).off('click', ev.selector);
471            }
472          });
473        }
474      });
475    }
476
477    var hideLongTooltipTitles = this.$container.data('hide-long-tltp-title');
478
479    //===========|Popup gallery scripts|===========//
480    if (popupType == 'colorbox') {
481      var $this = this.$container;
482      // simple selector
483      var colorBoxItemSelector =
484        '.grid-gallery-photos > .gg-colorbox:visible,' +
485        // mosaic selector
486        ' .grid-gallery-photos .gg-mosaic-wrapper .gg-colorbox,' +
487        // icon selector
488        ' .hi-icon.gg-colorbox:visible';
489      // for popup "Display only first image"
490      if ($this.hasClass('one-photo') || $this.hasClass('hidden-item')) {
491        colorBoxItemSelector = '.grid-gallery-photos > .gg-colorbox, .hi-icon.gg-colorbox';
492      }
493
494      if (this.initColorbox) {
495        this.$container.find(colorBoxItemSelector).colorbox.remove('#' + this.$container.attr('id'));
496      } else {
497        if (hideLongTooltipTitles == 0) {
498          var $colorboxtooltip = $('<div id="sggCboxTooltip">');
499          $(document).on(
500            {
501              mouseenter: function () {
502                $colorboxtooltip.addClass('active');
503              },
504              mouseleave: function () {
505                setTimeout(function () {
506                  $colorboxtooltip.removeClass('active');
507                }, 400);
508              },
509            },
510            '#colorbox.' + $this.data('popup-theme') + ' #cboxTitle'
511          );
512
513          $(document).one('cbox_complete', function (event) {
514            if (!$('#sggCboxTooltip').length) {
515              $('#cboxWrapper').append($colorboxtooltip);
516            }
517          });
518
519          $(document).on('cbox_complete', function (event) {
520            $colorboxtooltip.html($('#cboxTitle').html());
521            if ($('#colorbox').width() < 300) {
522              $('#colorbox').filter('.theme_1').find('#cboxSlideshow').css('bottom', '30px');
523            }
524          });
525        }
526      }
527
528      this.initColorbox = true;
529      var colorBoxConfig = {
530        fadeOut: this.$container.data('popup-fadeOut'),
531        fixed: true,
532        maxHeight: getImageDimension().height,
533        maxWidth: getImageDimension().width,
534        scalePhotos: true,
535        scrolling: false,
536        returnFocus: false,
537        slideshow: slidePlay && this.$container.data('popup-slideshow-speed'),
538        slideshowAuto: slidePlayAuto,
539        slideshowSpeed: slideshowSpeed,
540        rel: this.$container.attr('id'),
541        slideshowStart: self.popupTranslates.start_slideshow,
542        slideshowStop: self.popupTranslates.stop_slideshow,
543        current: self.popupTranslates.image + ' {current} ' + self.popupTranslates.of + ' {total}',
544        previous: self.popupTranslates.previous,
545        next: self.popupTranslates.next,
546        close: self.popupTranslates.close,
547        isDisableRightClick: this.$container.attr('data-disable-right-click') == 'true',
548        title: function () {
549          return self.getPopupTitle($(this));
550        },
551        speed: 350,
552        transition: 'elastic',
553        onComplete: function (e) {
554          self.changePopUpHash($(e.el).attr('id') || $(e.el).attr('data-id'));
555          self.addSocialShareToPopUp($(e.el), $('#cboxContent'), 'popup');
556          self.$container.find('.grid-gallery-photos > .gg-colorbox, .hi-icon.gg-colorbox').colorbox.resize();
557          $('#cboxLoadedContent').append("<div id='cboxRight'></div><div id='cboxLeft'></div>");
558        },
559        onLoad: function (e) {
560          if (self.popup_opened_image == e.el) return;
561          self.popup_opened_image = e.el;
562          var dimensions = getColorboxImageDimension();
563          $(self.popup_opened_image).data('colorbox').maxWidth = dimensions.width;
564          $(self.popup_opened_image).data('colorbox').maxHeight = dimensions.height;
565        },
566        onOpen: function (e) {
567          //Enable/Disable stop slideshow on mouse hover
568          if (popupHoverStop) {
569            var timeoutId = 0;
570            $('#cboxContent').hover(
571              function () {
572                clearTimeout(timeoutId);
573                $('.cboxSlideshow_on #cboxSlideshow').click();
574              },
575              function () {
576                if (slidePlayAuto) {
577                  clearTimeout(timeoutId);
578                  timeoutId = setTimeout(function () {
579                    $('.cboxSlideshow_off #cboxSlideshow').click();
580                  }, slideshowSpeed);
581                }
582              }
583            );
584          }
585        },
586        onClosed: function () {
587          self.popup_opened_image = false;
588          self.clearPopUpHash();
589        },
590      };
591
592      if (popupPlacementType == 1 || popupPlacementType == 2) {
593        colorBoxConfig['maxWidth'] = '100%';
594        colorBoxConfig['imgPlaceType'] = popupPlacementType;
595      }
596      this.$container.find(colorBoxItemSelector).off('click').colorbox(colorBoxConfig);
597
598      $(window).resize(function () {
599        self.resizeColorbox();
600      });
601
602      $('#cboxOverlay')
603        .removeClass()
604        .addClass($this.data('popup-theme') + '-overlay');
605      $('#colorbox').removeClass().addClass($this.data('popup-theme'));
606
607      generateOverlayColor('#cboxOverlay', popupBackground, popupOverlayTransper, true);
608    }
609
610    if (popupType == 'pretty-photo') {
611      // simple selector
612      var prettyPhotoItemSelector =
613        '.grid-gallery-photos > a[data-rel^="prettyPhoto"]:visible,' +
614        ' .grid-gallery-photos .gg-mosaic-wrapper a[data-rel^="prettyPhoto"],' + // mosaic selector
615        ' .grid-gallery-photos .hi-icon-wrap > a[data-rel^="prettyPhoto"]:visible'; // icon selector
616      // for popup "Display only first image"
617      if (this.$container.hasClass('one-photo') || this.$container.hasClass('hidden-item')) {
618        prettyPhotoItemSelector =
619          '.grid-gallery-photos > a[data-rel^="prettyPhoto"],' +
620          ' .grid-gallery-photos .gg-mosaic-wrapper a[data-rel^="prettyPhoto"],' + // mosaic selector
621          ' .grid-gallery-photos .hi-icon-wrap > a[data-rel^="prettyPhoto"]'; // icon selector
622      }
623
624      if (!this.$prettyPhoto) {
625        if (hideLongTooltipTitles == 0) {
626          var $prettyPhotoTooltip = $('<div id="sggPrettyPhototooltip">');
627          $(document).on(
628            {
629              mouseenter: function () {
630                $prettyPhotoTooltip.addClass('active');
631              },
632              mouseleave: function () {
633                setTimeout(function () {
634                  $prettyPhotoTooltip.removeClass('active');
635                }, 400);
636              },
637            },
638            '.pp_content_container .pp_description'
639          );
640        }
641
642        if (this.$container.attr('data-show-buttonlink-in-popup') == 1 && window.prettyPhotoDetailLink) {
643          this.loadButtonsFontFamily(this.$container.attr('data-buttonlink-font'), null);
644        }
645
646        this.$prettyPhoto = this.$container
647          .find(prettyPhotoItemSelector)
648          .off('click')
649          .ggPrettyPhoto({
650            hook: 'data-rel',
651            theme: 'light_square',
652            allow_resize: true,
653            allow_expand: true,
654            deeplinking: false,
655            slideshow: slidePlay && this.$container.data('popup-slideshow-speed'),
656            autoplay_slideshow: slidePlayAuto,
657            social_tools: '',
658            default_width: popupMaxWidth,
659            default_height: popupMaxHeight,
660            getImageDimensions: getImageDimension,
661            is_lazy_load: isLazyLoad,
662            ppTranslates: self.popupTranslates,
663            isDisableRightClick: this.$container.attr('data-disable-right-click') == 'true',
664            isShowRotateBtn: this.$container.attr('data-show-rotate-btn-in-popup') == 1,
665            isShowAttributes: this.$container.attr('data-show-attributes-in-popup') == 1,
666            attributesPosition: this.$container.attr('data-attributes-position'),
667            attributesWidth: this.$container.attr('data-attributes-width'),
668            isShowButtonLink: this.$container.attr('data-show-buttonlink-in-popup') == 1,
669            buttonLinkStyle: this.$container.attr('data-buttonlink-style'),
670            isShowLinkBtn: this.$container.attr('data-show-link-btn-in-popup') == 1,
671            isShowHovThumbnail: this.$container.attr('data-show-thumb-hov-in-popup') == 1,
672            galleryId: this.$container.attr('data-gg-id'),
673            getTitle: function () {},
674            setImageTitleForPrepare: function ($element) {
675              var imgTile = self.getPopupTitle($element);
676              return imgTile;
677            },
678            popup_border_type: this.$container.attr('data-popup-border-type'),
679            popup_border_color: this.$container.attr('data-popup-border-color'),
680            popup_border_width: this.$container.attr('data-popup-border-width'),
681            popup_border_enable: this.$container.attr('data-popup-border-enable') == 'on',
682            changepicturecallback: function (element) {
683              self.changePopUpHash(element.attr('id') || element.attr('data-id'));
684              self.popup_opened_image = element;
685              $('.pp_description').html(self.getPopupTitle(element)).show();
686              //add social share buttons if enabled
687              self.addSocialShareToPopUp(element, $('.pp_hoverContainer'), 'popup');
688              if (!slidePlay) {
689                $('.pp_play').hide();
690              }
691              // change detail link url
692              if (self.$container.attr('data-show-link-btn-in-popup') == 1 && window.prettyPhotoDetailLink) {
693                window.prettyPhotoDetailLink(element);
694              }
695              if (self.$container.attr('data-show-attributes-in-popup') == 1 && window.prettyPhotoAttributes) {
696                window.prettyPhotoAttributes(element, self.$container);
697              }
698
699              //Enable/Disable stop slideshow on mouse hover
700              if (popupHoverStop) {
701                $('.pp_hoverContainer').hover(
702                  function () {
703                    $('.pp_nav .pp_pause').click();
704                  },
705                  function () {
706                    if (slidePlayAuto) {
707                      $('.pp_nav .pp_play').click();
708                    }
709                  }
710                );
711              }
712              var $_desc = $('.pp_description'),
713                desc_height = parseInt($_desc.height()),
714                desc_line_height = parseInt($_desc.css('font-size'));
715              if (desc_line_height < desc_height) {
716                $('.pp_content').height($('.pp_fade').outerHeight(true) + $('.pp_details').outerHeight(true));
717              }
718
719              if (hideLongTooltipTitles == 0) {
720                if (!$('#sggPrettyPhototooltip').length) {
721                  $('.pp_content_container .pp_content').append($prettyPhotoTooltip);
722                }
723                $prettyPhotoTooltip.html($('.pp_content_container .pp_description').html());
724              }
725            },
726            callback: function () {
727              self.popup_opened_image = false;
728              self.clearPopUpHash();
729            },
730          });
731        $(window).resize(function () {
732          if (!self.popup_opened_image || !self.$prettyPhoto) return;
733          //if(self.$prettyPhoto[0].closest('div') != self.popup_opened_image[0].closest('div')) return;
734          self.$prettyPhoto.open(self.popup_opened_image);
735        });
736      } else {
737        this.$prettyPhoto.refresh(this.$container.find(prettyPhotoItemSelector));
738      }
739
740      generateOverlayColor('.pp_overlay', popupBackground, popupOverlayTransper, true);
741    }
742
743    if (popupType == 'photobox') {
744      var photoBoxItemSelector = 'a.pbox:visible',
745        photoBoxConfig = null;
746      // for popup "Display only first image"
747      if (this.$container.hasClass('one-photo') || this.$container.hasClass('hidden-item') || this.$container.data('gridType') == '4') {
748        photoBoxItemSelector = 'a.pbox';
749      }
750
751      if (this.initPhotobox) {
752        this.$container.find('.grid-gallery-photos').photobox('destroy');
753      }
754      this.initPhotobox = true;
755      photoBoxConfig = {
756        autoplay: slidePlayAuto,
757        isDisableRightClick: this.$container.attr('data-disable-right-click') == 'true',
758        thumb: function (link) {
759          if (self.$container.data('caption-buider') == '1' && self.$container.data('caption-builder-icons') == 1) {
760            return link.closest('.grid-gallery-caption').find('img')[0];
761          } else if (self.$container.data('icons')) {
762            return link.closest('.grid-gallery-caption').find('img')[0];
763          }
764          return null;
765        },
766        getTitle: function (el) {
767          var nameTitle = self.getPopupTitle($(el));
768          return nameTitle;
769        },
770        beforeShow: function (element) {
771          self.changePopUpHash($(element).attr('id') || $(element).attr('data-id'));
772          self.addSocialShareToPopUp($(element), $('#pbCaption'), 'photobox', true);
773        },
774        afterClose: function () {
775          self.clearPopUpHash();
776        },
777      };
778      if (isLazyLoad) {
779        photoBoxConfig['thumbAttr'] = 'data-gg-real-image-href';
780      }
781
782      this.$container.find('.grid-gallery-photos').off('click').photobox(photoBoxItemSelector, photoBoxConfig);
783
784      //Hide autoplay button when slideshow = false
785      if (!this.$container.data('popup-slideshow')) {
786        $('#pbAutoplayBtn').hide();
787      }
788
789      //Enable/Disable stop slideshow on mouse hover
790      if (popupHoverStop) {
791        $('.pbWrapper img').hover(
792          function () {
793            $('#pbOverlay .playing').click();
794          },
795          function () {
796            if (slidePlayAuto) {
797              $('#pbOverlay .play').click();
798            }
799          }
800        );
801      }
802
803      generateOverlayColor('#pbOverlay', popupBackground, popupOverlayTransper);
804    }
805    //===========|Popup gallery scripts|===========//
806  };
807
808  Gallery.prototype.preventImages = function () {
809    var popupType = this.$container.data('popup-type');
810
811    if (popupType == 'disable') {
812      this.$container.find('a.gg-link').off('click');
813      this.$container.find('a.gg-link:not([data-type=link])').addClass('disabled');
814      this.$container.on('click', 'a.gg-link', function (event) {
815        if ($(this).data('type') !== 'link') {
816          event.preventDefault();
817          event.stopPropagation();
818        }
819      });
820    }
821  };
822
823  Gallery.prototype.getResponsiveColumnsNumber = function () {
824    var columnsData = this.$container.data('responsive-colums'),
825      settings = [],
826      columnsNumber = parseInt(this.$container.data('columns-number'));
827
828    for (var key in columnsData) {
829      settings.push(columnsData[key]);
830    }
831
832    settings.sort(function (a, b) {
833      a.width = Number(a.width);
834      b.width = Number(b.width);
835      if (a.width > b.width) {
836        return 1;
837      } else if (a.width < b.width) {
838        return -1;
839      } else {
840        return 0;
841      }
842    });
843
844    for (var i = 0, len = settings.length, windowWidth = $(window).width(), minBreakpoint = 0; i < len; i++) {
845      if (windowWidth > minBreakpoint && windowWidth <= settings[i].width) {
846        columnsNumber = Number(settings[i].columns);
847        break;
848      }
849      minBreakpoint = settings[i].width;
850    }
851
852    return columnsNumber;
853  };
854
855  Gallery.prototype.initRowsMode = function () {
856    var columnsNumber = parseInt(this.$container.data('columns-number'));
857
858    if (this.$container.data('horizontal-scroll')) {
859      return;
860    }
861
862    if (typeof this.$container.data('responsive-colums') == 'object') {
863      columnsNumber = this.getResponsiveColumnsNumber();
864    }
865
866    if (columnsNumber) {
867      var containerWidth = parseInt(this.$container.width()),
868        spacing = parseInt(this.$container.data('offset')),
869        scaleHeight = parseInt(this.$container.data('width')) / parseInt(this.$container.data('height')),
870        elementWidth = null,
871        elementHeight = null;
872
873      elementWidth = Math.floor((this.$container.width() - (columnsNumber - 1) * spacing) / columnsNumber);
874      elementHeight = Math.floor(elementWidth / scaleHeight);
875
876      this.$elements.each(function () {
877        var $this = $(this);
878        if (!$this.find('.post-feed-crop').length) {
879          $this.css('width', elementWidth);
880          if (!isNaN(elementHeight)) {
881            $this.css('height', elementHeight);
882          } else {
883            $this.css('height', 'auto');
884          }
885        } else {
886          $this.find('figcaption').css('width', elementWidth);
887        }
888      });
889
890      this.$elements.find('.crop').css({
891        width: 'auto',
892        height: 'auto',
893      });
894    }
895  };
896
897  Gallery.prototype.setImagesHeight = function () {
898    var $images = this.$container.find('img');
899
900    if ($images != undefined && $images.length > 0) {
901      $images.each(function () {
902        var $image = $(this),
903          $wrapper = $image.parent();
904
905        if ($image.height() < $wrapper.height()) {
906          $wrapper.css('height', $image.height());
907        }
908      });
909    }
910  };
911
912  Gallery.prototype.setOverlayTransparency = function () {
913    this.$elements.find('figcaption, [class*="caption-with-icons"]').each(function () {
914      var $caption = $(this),
915        alpha = (10 - parseInt($caption.data('alpha'), 10)) / 10,
916        rgb = $caption.css('background-color'),
917        rgba = rgb.replace(')', ', ' + alpha + ')').replace('rgb', 'rgba');
918
919      $caption.css('background', rgba);
920    });
921  };
922
923  Gallery.prototype.setIconsPosition = function () {
924    var self = this;
925    this.$elements.each(function () {
926      var $element = $(this),
927        isCaptionBuilderUsed = self.$container.data('caption-buider'),
928        $wrapper = $element.find('div.hi-icon-wrap'),
929        $icons = $element.find('a.hi-icon');
930
931      $icons.each(function () {
932        var $icon = $(this),
933          marginData = {},
934          marginY = $element.height() / 2 - $icon.height() / 2 - 10,
935          marginX = $wrapper.data('margin');
936
937        if (marginX && !isCaptionBuilderUsed) {
938          marginData['margin-left'] = marginX;
939          marginData['margin-right'] = marginX;
940        }
941        if (marginY && !isCaptionBuilderUsed) {
942          marginData['margin-top'] = Math.abs(marginY);
943        }
944        $icon.css(marginData);
945      });
946    });
947  };
948
949  Gallery.prototype.initCategories = function () {
950    var $defaultElement = this.$navigation.find('a[data-tag="__all__"]'),
951      $elements = this.$navigation.find('a'),
952      $defaultBackground = $elements.first().css('background-color');
953
954    function shadeColor(color, percent) {
955      var f = parseInt(color.slice(1), 16),
956        t = percent < 0 ? 0 : 255,
957        p = percent < 0 ? percent * -1 : percent,
958        R = f >> 16,
959        G = (f >> 8) & 0x00ff,
960        B = f & 0x0000ff;
961      return '#' + (0x1000000 + (Math.round((t - R) * p) + R) * 0x10000 + (Math.round((t - G) * p) + G) * 0x100 + (Math.round((t - B) * p) + B)).toString(16).slice(1);
962    }
963
964    bg = shadeColor('#' + this.rgb2hex($elements.first().css('borderTopColor')), 0.3);
965
966    this.$navigation.find('a').on(
967      'click',
968      $.proxy(function (event) {
969        event.preventDefault();
970
971        var $category = $(event.currentTarget),
972          requested = String($category.data('tag')),
973          _defaultTag = '__all__',
974          currentGallery = this.$navigation.parent().attr('id');
975
976        $elements.css('background-color', $defaultBackground);
977        $category.css('background-color', bg);
978
979        if (requested == _defaultTag) {
980          this.$elements
981            .each(function () {
982              if ($(this).parent().attr('rel')) {
983                $(this)
984                  .parent()
985                  .attr('rel', 'prettyPhoto[' + currentGallery + ']');
986              }
987            })
988            .fadeIn();
989
990          this.correctMargin();
991          this.initWookmark();
992
993          if (!this.isFluidHeight() && this.$qsEnable) {
994            this.callQuicksand(this.$qsHolder, this.$qsData, this.$qsDuration);
995          }
996          return false;
997        }
998
999        if (!this.isFluidHeight() && this.$qsEnable) {
1000          var $filteredData = this.$qsData.filter(function () {
1001            var tags = $(this).children().data('tags');
1002            if (typeof tags !== 'undefined') {
1003              tags = tags.split('|');
1004            }
1005            return $.inArray(requested, tags) > -1;
1006          });
1007          this.callQuicksand(this.$qsHolder, $filteredData, this.$qsDuration);
1008        } else {
1009          $hidden = $();
1010          $visible = $();
1011          this.$elements.each(function () {
1012            var $element = $(this),
1013              tags = $element.data('tags');
1014
1015            if (typeof tags != 'string') {
1016              tags = String(tags);
1017            }
1018
1019            if (tags != undefined) {
1020              tags = tags.split('|');
1021            }
1022            if ($.inArray(requested, tags) > -1) {
1023              if ($element.parent().attr('rel')) {
1024                $element.parent().attr('rel', 'prettyPhoto[' + currentGallery + '-' + requested + ']');
1025              }
1026              $visible.push(this);
1027            } else {
1028              $hidden.push(this);
1029            }
1030          });
1031
1032          $.when($hidden.fadeOut()).done(
1033            $.proxy(function () {
1034              $visible.fadeIn().css({ height: '' });
1035              this.correctMargin();
1036              this.initWookmark();
1037            }, this)
1038          );
1039        }
1040      }, this)
1041    );
1042
1043    var firstTag = $elements.first().data('tag');
1044    this.$container.find('a[data-tag="' + firstTag + '"]').trigger('click');
1045  };
1046
1047  Gallery.prototype.callQuicksand = function ($holder, $filteredData, duration) {
1048    self = this;
1049
1050    $filteredData.find('figure.grid-gallery-caption').css('margin', this.initialMargin).parent().css('clear', 'none');
1051
1052    $holder.quicksand(
1053      $filteredData,
1054      {
1055        duration: Number(duration),
1056        easing: 'swing',
1057        attribute: 'href',
1058      },
1059      function () {
1060        $holder
1061          .css({
1062            width: 'auto',
1063            height: 'auto',
1064          })
1065          .append('<div class="grid-gallery-clearfix"></div>');
1066        self.initPopup();
1067        self.correctMargin();
1068        if (self.$container.data('lazyload-enable') == '1') {
1069          // images area removed and filled new images
1070          self.initLazyLoad();
1071        }
1072      }
1073    );
1074  };
1075
1076  Gallery.prototype.hidePopupCaptions = function () {
1077    //never show alternative text for popup theme 6 on top of popup
1078    $('<style type="text/css">.ppt{ display:none!important; }</style>').appendTo('head');
1079    if (this.$container.data('popup-captions') == 'hide') {
1080      $('<style type="text/css">#cboxTitle, #cboxCurrent, .pbCaptionText, .ppt, .pp_description { display:none!important; }</style>').appendTo('head');
1081    }
1082  };
1083
1084  Gallery.prototype.hidePaginationControls = function () {
1085    return false;
1086  };
1087
1088  Gallery.prototype.setImageOverlay = function () {
1089    if (this.isImageOverlay()) {
1090      this.$container.find('.grid-gallery-caption').each(function () {
1091        var image = $(this).find('img');
1092        var crop = $(this).find('.image-overlay');
1093        image.css('opacity', '0.2');
1094        crop.css('background-color', '#424242');
1095        $(this).on('mouseenter', function () {
1096          image.css('opacity', '1.0');
1097          crop.css('background-color', 'inherit');
1098        });
1099        $(this).on('mouseleave', function () {
1100          image.css('opacity', '0.2');
1101          crop.css('background-color', '#424242');
1102        });
1103      });
1104    }
1105  };
1106
1107  Gallery.prototype.setMouseShadow = function () {
1108    var shadow = null,
1109      $selector = null,
1110      $captions = this.$container.find('.grid-gallery-caption'),
1111      self = this,
1112      showOver = function (event) {
1113        if (event.type === 'mouseenter') {
1114          $(this).css('box-shadow', self.mouseOverBoxShadow);
1115        } else {
1116          $(this).css('box-shadow', 'none');
1117        }
1118      },
1119      hideOver = function (event) {
1120        if (event.type === 'mouseenter') {
1121          $(this).css('box-shadow', 'none');
1122        } else {
1123          $(this).css('box-shadow', self.mouseOverBoxShadow);
1124        }
1125      };
1126    // only first Init elem has correct value
1127    if (!self.mouseOverBoxShadow) {
1128      self.mouseOverBoxShadow = $captions.filter(':first').css('box-shadow');
1129    }
1130
1131    if ($captions.is('.shadow-show')) {
1132      $captions.css('box-shadow', 'none');
1133      $captions.off('hover').on('hover', showOver);
1134    } else if ($captions.is('.shadow-hide')) {
1135      $captions.off('hover').on('hover', hideOver);
1136    }
1137  };
1138
1139  Gallery.prototype.initPagination = function () {
1140    var perPage = parseInt(this.$container.find('.grid-gallery-photos').data('per-page'), 10),
1141      buffer = [],
1142      page = 1,
1143      offset = 0;
1144    self = this;
1145
1146    if (isNaN(perPage)) {
1147      this.$elements.fadeIn();
1148      return false;
1149    }
1150
1151    if (this.$container.data('gridType') == 4 && this.$container.data('show-mosaic-all-img') != 1) {
1152      this.$elements.fadeIn();
1153      this.pagination.wrapper.hide();
1154      return false;
1155    }
1156
1157    var showCurrentPage = function (gallery) {
1158      gallery.$elements.removeClass('current-page').hide(350);
1159
1160      $.each(buffer[gallery.pagination.currentPage], function () {
1161        $(this)
1162          .addClass('current-page')
1163          .css({ height: gallery.$container.data('height'), width: gallery.$container.data('width') })
1164          .show(function () {
1165            gallery.setIconsPosition();
1166            self.correctMargin();
1167          });
1168      });
1169      /*
1170             if (!gallery.isFluidHeight()) {
1171             $('.current-page .crop').css('height', function () {
1172             var height = null;
1173             $('.crop img').each(function () {
1174             if($(this).height() && !height) {
1175             height = $(this).height();
1176             }
1177             });
1178             return height;
1179             });
1180             }
1181             */
1182    };
1183
1184    this.pagination.limit = perPage;
1185
1186    this.$elements
1187      .each(
1188        $.proxy(function (index, el) {
1189          var currentIndex = index + 1;
1190
1191          if (currentIndex - offset <= this.pagination.limit) {
1192            if (!$.isArray(buffer[page])) {
1193              buffer[page] = [];
1194            }
1195
1196            buffer[page].push(el);
1197          } else {
1198            offset += this.pagination.limit;
1199            page += 1;
1200
1201            buffer[page] = [el];
1202          }
1203        }, this)
1204      )
1205      .hide();
1206
1207    this.pagination.pages = Math.ceil(this.pagination.total / this.pagination.limit);
1208
1209    var element = this.pagination.$wrapper.find('a.grid-gallery-page[data-page="1"]');
1210    element.css('font-size', '19pt');
1211
1212    this.pagination.$wrapper.find('a.grid-gallery-page').on(
1213      'click',
1214      $.proxy(function (e) {
1215        e.preventDefault();
1216
1217        var element = $(e.currentTarget);
1218        var galery = Gallery.prototype;
1219        this.pagination.$wrapper.find('a.grid-gallery-page').each(function () {
1220          $(this).css('font-size', 'inherit');
1221        });
1222        galery.selectedCategory = element.data('page');
1223        element.css('font-size', '19pt');
1224
1225        var $anchor = $(e.currentTarget),
1226          requestedPage = $anchor.data('page');
1227
1228        this.pagination.currentPage = requestedPage;
1229
1230        showCurrentPage(this);
1231
1232        return false;
1233      }, this)
1234    );
1235
1236    showCurrentPage(this);
1237  };
1238
1239  Gallery.prototype.hex = function (x) {
1240    return isNaN(x) ? '00' : hexDigits[(x - (x % 16)) / 16] + hexDigits[x % 16];
1241  };
1242
1243  Gallery.prototype.rgb2hex = function (rgb) {
1244    if (rgb) {
1245      rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(0\.\d+))?\)$/);
1246      function hex(x) {
1247        return ('0' + parseInt(x).toString(16)).slice(-2);
1248      }
1249      return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
1250    }
1251  };
1252
1253  Gallery.prototype.hex2rgb = function (hex) {
1254    var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
1255    hex = hex.replace(shorthandRegex, function (m, r, g, b) {
1256      return r + r + g + g + b + b;
1257    });
1258
1259    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
1260    return result
1261      ? {
1262          r: parseInt(result[1], 16),
1263          g: parseInt(result[2], 16),
1264          b: parseInt(result[3], 16),
1265        }
1266      : null;
1267  };
1268
1269  Gallery.prototype.importFontFamily = function (familyName) {
1270    var styleId = 'sggFontFamilyStyle',
1271      $style = $('#' + styleId);
1272    if (!$style.length) {
1273      $style = $('<style/>', { id: styleId });
1274      $('head').append($style);
1275    }
1276    familyName = familyName.replace(/\s+/g, '+').replace(/"/g, '');
1277
1278    var obj = document.getElementById(styleId),
1279      sheet = obj.sheet || obj.styleSheet;
1280    if (this.loadedFonts.indexOf(familyName) === -1) {
1281      if (sheet.insertRule) {
1282        sheet.insertRule('@import url("//fonts.googleapis.com/css?family=' + familyName + '"); ', 0);
1283      } else if (sheet.addImport) {
1284        sheet.addImport('//fonts.googleapis.com/css?family=' + familyName);
1285      }
1286      this.loadedFonts.push(familyName);
1287    }
1288  };
1289
1290  Gallery.prototype.loadFontFamily = function () {
1291    font = this.$container.data('caption-font-family');
1292    if (typeof font !== 'undefined') {
1293      if (window && window.sggStandartFontsList && $.inArray(font.replace(/\"/g, ''), window.sggStandartFontsList) != -1) {
1294        return false;
1295      }
1296      if (font && font !== 'Default') {
1297        this.importFontFamily(font);
1298      }
1299    } else {
1300      return false;
1301    }
1302  };
1303
1304  Gallery.prototype.initCaptionCalculations = function () {
1305    var self = this;
1306
1307    this.$container.find('.grid-gallery-caption').each(function () {
1308      wrap = $(this).find('div.grid-gallery-figcaption-wrap');
1309      figcaption = $(this).find('figcaption');
1310
1311      wrap.css({
1312        display: 'table-cell',
1313        'text-align': figcaption.css('text-align'),
1314      });
1315
1316      wrap.wrap(
1317        $('<div>', {
1318          css: {
1319            display: 'table',
1320            height: '100%',
1321            width: '100%',
1322          },
1323        })
1324      );
1325    });
1326  };
1327
1328  Gallery.prototype.checkDirection = function ($element, e) {
1329    var w = $element.width(),
1330      h = $element.height(),
1331      x = (e.pageX - $element.offset().left - w / 2) * (w > h ? h / w : 1),
1332      y = (e.pageY - $element.offset().top - h / 2) * (h > w ? w / h : 1);
1333
1334    return Math.round((Math.atan2(y, x) * (180 / Math.PI) + 180) / 90 + 3) % 4;
1335  };
1336
1337  Gallery.prototype.generateOverlayCaptionColor = function (overlayColor, alpha) {
1338    if (typeof overlayColor == 'string') {
1339      overlayColor = overlayColor.split(')');
1340
1341      if (overlayColor.length > 0) {
1342        overlayColor = overlayColor[0].split('(');
1343
1344        if (overlayColor.length > 1) {
1345          var chanels = overlayColor[1].split(',');
1346
1347          if (chanels.length == 4) {
1348            // it is already rgba (fix for IE)
1349            overlayColor[0] = overlayColor[0].replace('a', '');
1350            chanels.splice(-1, 1);
1351            overlayColor[1] = chanels.join(',');
1352          }
1353          return overlayColor[0] + 'a(' + overlayColor[1] + ', ' + (1 - alpha / 10) + ')';
1354        }
1355      }
1356    }
1357    return overlayColor;
1358  };
1359
1360  Gallery.prototype.initCaptionEffects = function () {
1361    var self = this,
1362      allwaysShowCaptionOnMobile = this.$container.data('caption-mobile'),
1363      disableCaptionOnMobile = this.$container.data('caption-disabled-on-mobile'),
1364      isMobile = !!parseInt(this.$container.data('is-mobile'));
1365
1366    if (isMobile && navigator && navigator.userAgent && navigator.userAgent.indexOf('Safari') > -1) {
1367      var $3dCubeCaptions = this.$container.find('.grid-gallery-caption[data-grid-gallery-type="3d-cube"]');
1368      $3dCubeCaptions.attr('data-grid-gallery-type', 'revolving-door-bottom');
1369      $3dCubeCaptions.data('grid-gallery-type', 'revolving-door-bottom');
1370    }
1371
1372    $.each(this.$elements, function (index, el) {
1373      var $el = $(el),
1374        overlayColor = $el.find('figcaption').css('backgroundColor'),
1375        alpha = parseInt($el.find('figcaption').data('alpha'));
1376
1377      if (isMobile && allwaysShowCaptionOnMobile) {
1378        $el.attr('data-grid-gallery-type', 'none');
1379      }
1380
1381      if ($el.data('grid-gallery-type') == 'cube') {
1382        $el.on('mouseenter mouseleave', function (e) {
1383          var $figcaption = $(this).find('figcaption'),
1384            direction = self.checkDirection($(this), e),
1385            classHelper = null;
1386
1387          switch (direction) {
1388            case 0:
1389              classHelper = 'cube-' + (e.type == 'mouseenter' ? 'in' : 'out') + '-top';
1390              break;
1391            case 1:
1392              classHelper = 'cube-' + (e.type == 'mouseenter' ? 'in' : 'out') + '-right';
1393              break;
1394            case 2:
1395              classHelper = 'cube-' + (e.type == 'mouseenter' ? 'in' : 'out') + '-bottom';
1396              break;
1397            case 3:
1398              classHelper = 'cube-' + (e.type == 'mouseenter' ? 'in' : 'out') + '-left';
1399              break;
1400          }
1401
1402          $figcaption.removeClass().addClass(classHelper);
1403        });
1404      }
1405
1406      if ($el.data('grid-gallery-type') == 'direction-aware') {
1407        var color = $el.find('figcaption').css('color'),
1408          isCaptionBuilderUsed = self.$container.data('caption-buider'),
1409          classStr = '',
1410          addAttr = '',
1411          align = $el.find('figcaption').css('text-align');
1412
1413        if (isCaptionBuilderUsed == 1) {
1414          $el.attr('data-caption', '<div style="padding:0px; height: ' + $el.height() + 'px;
1414 font-family:' + self.$container.data('caption-font-family') + '; font-size:' + self.$container.data('caption-text-size') + '">' + ($el.find('figcaption').html() || '') + '</div>');
1415        } else {
1416          var $ggImgCaption = $el.find('.gg-image-caption');
1417          if ($ggImgCaption.hasClass('ggRtlClass')) {
1418            classStr = 'ggRtlClass';
1419            addAttr = 'dir="rtl"';
1420          }
1421          $el.attr('data-caption', '<div class="' + classStr + '" ' + addAttr + ' style="padding:20px;font-family:' + self.$container.data('caption-font-family') + '; font-size:' + self.$container.data('caption-text-size') + ';">' + ($ggImgCaption.html() || '') + '</div>');
1422        }
1423
1424        $el.sliphover({
1425          target: $el,
1426          backgroundColor: self.generateOverlayCaptionColor(overlayColor, alpha),
1427          fontColor: color,
1428          textAlign: align,
1429          caption: 'data-caption',
1430        });
1431      }
1432
1433      if ($el.data('grid-gallery-type') == '3d-cube') {
1434        if (!$el.find('.box-3d-cube-scene').length) {
1435          var cubeWidth = $el.width(),
1436            cubeHeight = $el.height();
1437          // $el.addClass('box-3d-cube-scene');
1438          $el.children('div').addClass('front').addClass('face');
1439          $el.children('figcaption').addClass('back').addClass('face');
1440          $el.html('<div class="box-3d-cube-scene"><div class="box-3d-cube">' + $el.html() + '</div></div>');
1441          // $el.html("<div class='box-3d-cube-scene'><div class='box-3d-cube'><div class='front face'><img src='http://placehold.it/"+cubeWidth+"x"+cubeHeight+"/' alt=''></div><div class='back face'><div>This is back</div></div></div></div>");
1442          self.changeImageHeightFor3dCubeEffect($el, cubeWidth, cubeHeight);
1443        }
1444      }
1445
1446      if ($el.data('grid-gallery-type') == 'polaroid') {
1447        self.polaroidCaptionCalculate($el);
1448      } else {
1449        var topRow = $el.find('.gg-caption-row.top'),
1450          centerRow = $el.find('.gg-caption-row.center');
1451        if (centerRow.length == 1 && topRow.length == 1) {
1452          centerRow.css({ top: topRow.height(), transform: 'initial' });
1453        }
1454      }
1455    });
1456
1457    $(document).on('click', '.sliphover-container', function (event) {
1458      event.preventDefault();
1459      $(this).data('relatedElement').get(0).click();
1460    });
1461
1462    if (isMobile && !disableCaptionOnMobile) {
1463      this.$container.find('.grid-gallery-caption').each(function () {
1464        var caption = this,
1465          $caption = $(caption),
1466          hammer = new Hammer_gg(this),
1467          captionIsMobile = self.$container.attr('data-caption-mobile'),
1468          preventClick = false;
1469
1470        $caption.on('click', function (event) {
1471          if (preventClick) {
1472            event.preventDefault();
1473            event.stopPropagation();
1474          }
1475        });
1476
1477        hammer.on('tap panstart', function (event) {
1478          if (event.type === 'panstart') {
1479            self.$container.find('.grid-gallery-caption').removeClass('hovered');
1480          }
1481
1482          if (event.type === 'tap') {
1483            preventClick = false;
1484            if (!$caption.hasClass('hovered')) {
1485              self.$container.find('.grid-gallery-caption').not(caption).removeClass('hovered');
1486              $(caption).addClass('hovered');
1487              if (captionIsMobile == 'false') {
1488                preventClick = true;
1489              }
1490            }
1491          }
1492        });
1493      });
1494    }
1495
1496    if (isMobile && disableCaptionOnMobile) {
1497      this.$container.find('.grid-gallery-caption figcaption').hide();
1498    }
1499  };
1500
1501  Gallery.prototype.polaroidCaptionCalculate = function ($el) {
1502    if ($el.data('grid-gallery-type') != 'polaroid' || $(this).find('.post-feed-crop').length || $el.hasClass('initialized')) return;
1503    var $img = $el.find('img');
1504
1505    if ($img.hasClass('ggLazyImg') || $img.hasClass('ggNotInitImg')) return;
1506    if ($el.closest('.gg-mw-row').hasClass('sggDisplNone')) return;
1507
1508    $el.addClass('initialized');
1509    $img.finish();
1510    var width = $el.width(),
1511      gridType = this.$container.data('gridType'),
1512      frameWidth = parseInt(this.$container.data('polaroid-frame-width'), 10) || 20,
1513      captionHeight = this.$container.data('polaroid-caption-height'),
1514      clearHeight = captionHeight ? parseInt(captionHeight.toString().match(/\d.?\d*.?\d*/)[0]) : 0,
1515      overlayColor = $el.find('figcaption').css('backgroundColor'),
1516      alpha = parseInt($el.find('figcaption').data('alpha')),
1517      $figcaption = $el.find('figcaption'),
1518      scaleRatio = $img.width() / $img.height();
1519    if (gridType == 2) {
1520      var imageHeight = $img.height() - frameWidth * 2,
1521        imageWidth = imageHeight * scaleRatio;
1522    } else {
1523      var imageWidth = $img.width() - frameWidth * 2,
1524        imageHeight = imageWidth / scaleRatio;
1525    }
1526    var figcaptionHeight = !isNaN(clearHeight) && clearHeight != 0 ? (captionHeight.toString().indexOf('%') > 0 ? (imageHeight * clearHeight) / 100 : clearHeight) : 0,
1527      figureFullHeight = imageHeight + frameWidth * 2 + figcaptionHeight;
1528
1529    $img.css({
1530      width: imageWidth + 'px',
1531      height: imageHeight + 'px',
1532      margin: frameWidth + 'px auto 0',
1533    });
1534    $el.find('.gg-caption-table').css('height', '1px');
1535
1536    $el.find('.crop').css({
1537      height: imageHeight + frameWidth + 'px',
1538    });
1539    if (gridType == 0) {
1540      $el.find('.crop').css('overflow', 'visible');
1541    } else if (gridType == 2) {
1542      $el.css({
1543        height: figureFullHeight + 'px',
1544        width: imageWidth + frameWidth * 2 + 'px',
1545      });
1546    } else if (gridType == 3) {
1547      $el.css({
1548        height: figureFullHeight + 'px',
1549      });
1550    }
1551
1552    $el.css({
1553      background: overlayColor,
1554    });
1555    $el.css({
1556      width: $el.width(),
1557      background: this.generateOverlayCaptionColor(overlayColor, alpha),
1558    });
1559
1560    $figcaption.css({
1561      background: 'none',
1562      transition: 'none',
1563    });
1564    if (figcaptionHeight) {
1565      figcaptionHeight += 'px';
1566      $figcaption.css('height', figcaptionHeight);
1567      $el.find('.gg-caption-row').css({ 'max-height': figcaptionHeight ? figcaptionHeight : '100%', height: 'auto' });
1568      $el.find('.gg-caption-cell').css('height', '100%');
1569      if (gridType == 3) {
1570        $figcaption.css('margin-top', frameWidth + 'px');
1571      }
1572    } else {
1573      $figcaption.css('padding', frameWidth + 'px');
1574    }
1575
1576    if ($figcaption.find('.grid-gallery-figcaption-wrap').text().length === 0) {
1577      $figcaption.find('.grid-gallery-figcaption-wrap').append('<span></span>');
1578    }
1579
1580    if (this.$container.data('polaroid-animation')) {
1581      $el.addClass('polaroid-animation');
1582    }
1583
1584    if (this.$container.data('polaroid-scattering')) {
1585      $el.css({
1586        transform: 'rotate(' + (-3 + Math.random() * (10 - 3)) + 'deg)',
1587      });
1588      $el.addClass('polaroid-scattering');
1589    }
1590    var slimScroll = $el.closest('div.slimScrollDiv');
1591    if (slimScroll.length) {
1592      var scrollHeight = figureFullHeight + 20 + 'px';
1593      slimScroll.css('height', scrollHeight);
1594      slimScroll.find('.grid-gallery-photos').css('height', scrollHeight);
1595    }
1596  };
1597
1598  Gallery.prototype.changeImageHeightFor3dCubeEffect = function ($figure, cubeWidth, cubeHeight) {
1599    // check params
1600    if (!$figure) {
1601      return;
1602    }
1603    // call this function from PRO script
1604    if (!$figure.length) {
1605      if ('figure' in $figure && 'width' in $figure && 'height' in $figure) {
1606        cubeWidth = $figure.width;
1607        cubeHeight = $figure.height;
1608        $figure = $figure.figure;
1609      } else {
1610        return;
1611      }
1612    }
1613
1614    if (!cubeWidth) {
1615      cubeWidth = $figure.width();
1616    }
1617    if (!cubeHeight) {
1618      cubeHeight = $figure.height();
1619    }
1620
1621    var perspective = Math.max(cubeHeight, cubeWidth) * 2 + 'px',
1622      transformOrigin = '50% 50% -' + Math.round(cubeHeight / 2) + 'px';
1623
1624    $figure.find('.box-3d-cube-scene').css({
1625      perspective: perspective,
1626      '-webkit-perspective': perspective,
1627    });
1628    $figure.find('.box-3d-cube').css({
1629      'transform-origin': transformOrigin,
1630      '-ms-transform-origin': transformOrigin,
1631      '-webkit-transform-origin': transformOrigin,
1632    });
1633    $figure.find('.box-3d-cube, .box-3d-cube .face').css({
1634      width: cubeWidth + 'px',
1635      height: cubeHeight + 'px',
1636    });
1637  };
1638
1639  Gallery.prototype.correctMargin = function () {
1640    if (this.$container.data('area-position') == 'right') {
1641      return;
1642    }
1643    if (this.$container.data('gridType') == 4) {
1644      return;
1645    }
1646    // if responsive mode = 'one by one' and mobile -> run this method
1647    var horizontalScroll = this.$container.data('horizontal-scroll'),
1648      isMobile = parseInt($anyGallery.attr('data-is-mobile'));
1649    if (horizontalScroll && horizontalScroll.responsiveMode == 1 && isMobile) {
1650    } else {
1651      return;
1652    }
1653    if (!this.isFluidHeight()) {
1654      if (this.$qsEnable) {
1655        this.$elements = this.$container.find('figure.grid-gallery-caption');
1656      }
1657
1658      var prevElement = null,
1659        totalElements = this.$elements.filter(':visible').length,
1660        rowWidth = 0,
1661        maxRowWidth = this.$container.width(),
1662        initialMargin = this.initialMargin;
1663
1664      this.$elements.css('margin', this.initialMargin);
1665      this.$elements.parent().css('clear', 'none');
1666
1667      this.$elements.filter(':visible').each(function (index) {
1668        if (rowWidth + $(this).outerWidth() > maxRowWidth) {
1669          $(prevElement).css('margin-right', 0);
1670          $(this).css('margin-right', this.initialMargin);
1671          $(this).parent().css('clear', 'left');
1672          rowWidth = $(this).outerWidth() + parseInt(initialMargin);
1673        } else if (rowWidth + $(this).outerWidth() == maxRowWidth) {
1674          $(this).css('margin-right', 0);
1675          rowWidth = 0;
1676        } else {
1677          rowWidth += $(this).outerWidth() + parseInt(initialMargin);
1678        }
1679
1680        if (index == totalElements - 1) {
1681          $(this).css('margin-right', 0);
1682        }
1683
1684        prevElement = this;
1685      });
1686    }
1687  };
1688
1689  Gallery.prototype.hideTitleTooltip = function () {
1690    if (this.$container.data('hide-tooltip') == true) {
1691      title = '';
1692      this.$container
1693        .find('a, img, div:not(.grid-gallery-photos)')
1694        .on('mouseenter', function () {
1695          title = $(this).attr('title');
1696          $(this).attr({ title: ' ' });
1697        })
1698        .mouseout(function () {
1699          $(this).attr({ title: title });
1700        });
1701    }
1702  };
1703
1704  Gallery.prototype.correctFullscreen = function () {
1705    var windowWidth = $(window).width();
1706    this.$elements.each(function () {
1707      var coef = parseInt(windowWidth / $(this).width()),
1708        resultWidth = Math.round(windowWidth / coef);
1709      $(this).width(resultWidth);
1710    });
1711  };
1712
1713  Gallery.prototype.correctFullScreenWidthGallery = function () {
1714    var windowWidth = $(window).width(),
1715      $parentContainer = this.$container.parent(),
1716      containerOffset = $parentContainer.offset(),
1717      containerOffsetLeft = containerOffset.left + parseFloat($parentContainer.css('padding-left'));
1718
1719    this.$container.find('.grid-gallery-photos').css({
1720      width: windowWidth,
1721    });
1722
1723    var cssDirection = this.$container.css('direction');
1724
1725    if ('ltr' == cssDirection) {
1726      this.$container.css({
1727        width: windowWidth,
1728        left: '-' + containerOffsetLeft + 'px',
1729        //'max-width': '100%'
1730      });
1731      this.$container.find('.grid-gallery-nav').css('width', windowWidth + 'px');
1732    } else {
1733      this.$container
1734        .css({
1735          width: windowWidth, //, 'max-width': '100%'
1736        })
1737        .offset(function (i, coords) {
1738          return { top: coords.top, left: 0 };
1739        });
1740    }
1741  };
1742
1743  Gallery.prototype.getOriginalImageSizes = function (img) {
1744    var tempImage = new Image(),
1745      width,
1746      height;
1747
1748    if ('naturalWidth' in tempImage && 'naturalHeight' in tempImage) {
1749      width = img.naturalWidth;
1750      height = img.naturalHeight;
1751    } else {
1752      tempImage.src = img.src;
1753      width = tempImage.width;
1754      height = tempImage.height;
1755    }
1756
1757    return {
1758      width: width,
1759      height: height,
1760    };
1761  };
1762
1763  Gallery.prototype.initHorizontalMode = function () {
1764    var horizontalScroll = this.$container.data('horizontal-scroll'),
1765      height = this.$container.data('height'),
1766      width = this.$container.data('width'),
1767      offset = this.$container.data('offset'),
1768      isMobile = parseInt($anyGallery.attr('data-is-mobile')),
1769      mouseWheelStep = 100,
1770      touchStep = 100,
1771      responsiveMode = 0,
1772      tmpValue = 0,
1773      self = this;
1774
1775    if (this.$container.data('gridType') == 4) {
1776      return;
1777    }
1778    if (!horizontalScroll) {
1779      return;
1780    }
1781    if (horizontalScroll) {
1782      // if responsive mode = 'one by one' and mobile -> need to disable "responsive mode"
1783      if (horizontalScroll.responsiveMode == 1 && isMobile) {
1784        return;
1785      }
1786      if (horizontalScroll.mouseWheelStep) {
1787        tmpValue = parseInt(horizontalScroll.mouseWheelStep);
1788        if (!isNaN(tmpValue)) {
1789          mouseWheelStep = tmpValue;
1790        }
1791      }
1792      if (horizontalScroll.touchStep) {
1793        tmpValue = parseInt(horizontalScroll.touchStep);
1794        if (!isNaN(tmpValue)) {
1795          touchStep = tmpValue;
1796        }
1797      }
1798    }
1799
1800    //Calculate max-height and margin
1801    if (!height) {
1802      var elementsHeight = this.$container
1803          .find('.grid-gallery-caption>a')
1804          .map(function () {
1805            return $(this).height();
1806          })
1807          .get(),
1808        height = Math.max.apply(null, elementsHeight);
1809    } else {
1810      if (offset && offset > 0) {
1811        height = height + offset * 2;
1812      }
1813    }
1814
1815    if (width === 'auto') {
1816      this.$elements.each(function (index, el) {
1817        var $figure = $(el),
1818          $image = $figure.find('img');
1819        sizes = self.getOriginalImageSizes($image.get(0));
1820        $image.css('max-width', 'none');
1821        if (!$image.hasClass('ggLazyImg')) $figure.width(Math.floor((height / sizes.height) * sizes.width));
1822      });
1823    }
1824
1825    //Fixed IE9 scroll bug
1826    var isIE9OrBelow = function () {
1827      return /MSIE\s/.test(navigator.userAgent) && parseFloat(navigator.appVersion.split('MSIE')[1]) < 10;
1828    };
1829
1830    if (isIE9OrBelow()) {
1831      this.$container.find('.grid-gallery-photos > *').css('display', 'table-cell');
1832    } else {
1833      this.$container.find('.grid-gallery-photos > *').css('display', 'inline-block');
1834    }
1835
1836    this.$container.find('.grid-gallery-photos > *').css({
1837      margin: 0,
1838      padding: 0,
1839      float: 'none',
1840      animate: true,
1841      'vertical-align': 'middle',
1842      clear: 'right',
1843      //'margin-right': '-5px',
1844      border: 'none',
1845      'max-width': 'none',
1846    });
1847
1848    this.$container.find('.grid-gallery-photos').css({
1849      'font-size': 0,
1850    });
1851
1852    this.$container.find('.grid-gallery-photos .grid-gallery-caption').css({
1853      float: 'none',
1854      'margin-left': 0,
1855    });
1856
1857    // https://github.com/lanre-ade/jQuery-slimScroll
1858    height = height + 7; //This is scrollbar height;
1859    var slimScroll = this.$container.find('.grid-gallery-photos').slimScroll({
1860      height: height,
1861      width: 'auto',
1862      railVisible: true,
1863      alwaysVisible: true,
1864      allowPageScroll: true,
1865      axis: 'x',
1866      animate: true,
1867      color: horizontalScroll.color || '#000',
1868      opacity: (100 - horizontalScroll.transparency) * 0.01,
1869      wheelStep: mouseWheelStep,
1870      touchScrollStep: touchStep,
1871      isMobile: isMobile,
1872      ggSlimscrollHandler: function () {
1873        self.lazyLoadTriggerHandler();
1874      },
1875    });
1876
1877    // Load more height fix
1878    if (slimScroll.height() < height) {
1879      slimScroll.height(height);
1880      slimScroll.parent().height(height);
1881    }
1882  };
1883
1884  Gallery.prototype.initHorizontalGalleryType = function () {
1885    if (this.$container.data('height') && String(this.$container.data('height')).indexOf('%') > -1) {
1886      var height = this.$elements.first().height();
1887      this.$elements.find('img').css({
1888        'max-height': height,
1889        'min-height': height,
1890      });
1891    }
1892    var self = this;
1893    setTimeout(function () {
1894      self.resizeHorizontalElements();
1895    }, 50);
1896  };
1897
1898  Gallery.prototype.hidePreloader = function () {
1899    var preloadEnab = this.$container.attr('data-preloader'),
1900      preloader = this.$container.find('.gallery-loading'),
1901      galleryPhotos = this.$container.find('.grid-gallery-photos');
1902
1903    preloader.hide();
1904    if (preloadEnab !== '' && preloadEnab === 'true') {
1905      setTimeout(function () {
1906        galleryPhotos.show().fadeTo('slow', 1, function () {
1907          galleryPhotos.css('opacity', '1');
1908        });
1909      }, 0);
1910    } else {
1911      galleryPhotos.show().fadeTo('fast', 1, function () {
1912        galleryPhotos.css('opacity', '1');
1913      });
1914    }
1915  };
1916
1917  Gallery.prototype.showGalleryParts = function () {
1918    this.$container.children('.hidden-item').removeClass('hidden-item');
1919  };
1920
1921  Gallery.prototype.$getImagesFigureContainer = function () {
1922    return this.$container.find('figure.grid-gallery-caption');
1923  };
1924
1925  Gallery.prototype.initSocialSharing = function () {
1926    if (!this.socialSharing || !this.socialSharing.enabled) {
1927      return;
1928    }
1929    var newUrl = encodeURIComponent(window.location.href);
1930    var newTitle = encodeURIComponent(document.title);
1931    jQuery('.supSocialIcon').each(function () {
1932      var $this = $(this);
1933      var origUrl = $this.attr('originalurl');
1934      var newUrl2 = origUrl.replace('{url}', newUrl);
1935      newUrl2 = newUrl2.replace('{title}', newTitle);
1936      newUrl2 = newUrl2.replace('{description}', newTitle);
1937      $this.attr('href', newUrl2);
1938    });
1939    this.initGallerySocialSharing();
1940    this.initImageSocialSharing();
1941  };
1942  Gallery.prototype.initGallerySocialSharing = function () {
1943    var gallerySharing = this.socialSharing.gallerySharing;
1944    if (!parseInt(gallerySharing.enabled)) {
1945      return;
1946    }
1947    if (gallerySharing.position == 'top' || gallerySharing.position == 'all') {
1948      this.$container.find('.gallery-sharing-top').fadeIn();
1949    }
1950    if (gallerySharing.position == 'bottom' || gallerySharing.position == 'all') {
1951      this.$container.find('.gallery-sharing-bottom').fadeIn();
1952    }
1953  };
1954  Gallery.prototype.initImageSocialSharing = function () {
1955    var imageSharing = this.socialSharing.imageSharing;
1956    if (!parseInt(imageSharing.enabled)) {
1957      return;
1958    }
1959    var btns = this.$container.find('.gallery-sharing-image').clone();
1960
1961    var $images = this.$getImagesFigureContainer(),
1962      iconsEnabled = this.$container.data('icons');
1963    $images.each(function () {
1964      var $this = $(this),
1965        $el;
1966      var imgLink = jQuery($this).parent().attr('href');
1967      btns.find('.supSocialIcon').each(function () {
1968        var $thisBtn = $(this);
1969        if ($thisBtn.hasClass('supSocialIconprint')) {
1970          $thisBtn.attr('onClick', 'supSocialSharePrintImage("' + imgLink + '")');
1971        }
1972      });
1973
1974      if (!iconsEnabled) {
1975        $el = $this.parent();
1976      } else {
1977        $el = $this.find('a.hi-icon');
1978      }
1979      $this.append(btns.html());
1980    });
1981  };
1982  Gallery.prototype.addSocialShareToPopUp = function ($element, $wrapper, addClass, fixed) {
1983    if (!this.socialSharing.enabled || !parseInt(this.socialSharing.popupSharing.enabled)) {
1984      return;
1985    }
1986    var btns = this.$container.find('.gallery-sharing-popup').clone();
1987    var newUrl = encodeURIComponent($element.get(0).baseURI);
1988    var imgLink = $element.get(0).href;
1989    var newTitle = jQuery($element.get(0)).attr('title');
1990    btns.find('.supSocialIcon').each(function () {
1991      var $this = $(this);
1992      if ($this.hasClass('supSocialIconprint')) {
1993        $this.attr('onClick', 'supSocialSharePrintImage("' + imgLink + '")');
1994      }
1995      $this.attr('title', newTitle);
1996      var origUrl = $this.attr('originalurl');
1997      var newUrl2 = origUrl.replace('{url}', newUrl);
1998      newUrl2 = newUrl2.replace('{title}', newTitle);
1999      newUrl2 = newUrl2.replace('{description}', newTitle);
2000      $this.attr('href', newUrl2);
2001    });
2002    $wrapper.find('.supSocialIconsWrapper').remove();
2003    $wrapper.append(btns.html());
2004  };
2005
2006  // Gallery.prototype.initEvent = function($elements){
2007  //     $elements.find('.supsystic-social-sharing a.social-sharing-button').on('click',function (e) {
2008  // if( !e ) e = window.event;
2009  // e.preventDefault();
2010  // e.stopPropagation();
2011  // e.stopImmediatePropagation();
2012  // $(document).trigger('ssSocialClick', this);
2013  // if (e.currentTarget.href.slice(-1) !== '#') {
2014  //     window.open(e.currentTarget.href, 'mw' + e.timeStamp, 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');
2015  // }
2016
2017  // var button = $(this)
2018  // ,   figureWrapper = button.closest('.grid-gallery')
2019  // ,   socialHtmlWrapper = figureWrapper.find('#social-share-html')
2020  // // ,   socialHtmlWrapper = figureWrapper.find('.supsystic-social-sharing')
2021  // ,   popupWrapper = socialHtmlWrapper.find('.supsystic-social-sharing-popup');
2022
2023  // if(button.hasClass('trigger-popup')){
2024  // 	if(socialHtmlWrapper.css('display') === 'none'){
2025  //         socialHtmlWrapper.find('a').css('display', 'none');
2026  //         socialHtmlWrapper.css('display','block');
2027  //         popupWrapper.css('display','block');
2028  //     }else{
2029  //         socialHtmlWrapper.css('display','none');
2030  //         popupWrapper.css('display','none');
2031  //     }
2032  // }
2033  // if(button.closest('#pp_full_res').length){
2034  //     var buttonOverlayWrapper = button.closest('#pp_full_res')
2035  //     ,   buttonPopupWrapper = buttonOverlayWrapper.find('.supsystic-social-sharing-popup');
2036  //     if(buttonPopupWrapper.css('display') === 'none'){
2037  //         buttonPopupWrapper.css('display','block');
2038  //     }else{
2039  //         buttonPopupWrapper.css('display','none');
2040  //     }
2041  // }
2042  // $(document).on('click', function (e) {
2043  //     if( !e ) e = window.event;
2044  //     if (!$(e.target).is(".supsystic-social-sharing-popup")) {
2045  //         socialHtmlWrapper.css('display','none');
2046  //         popupWrapper.css('display','none');
2047  //         socialHtmlWrapper.find('a').css('display', 'block');
2048  //     }
2049  // });
2050  //     });
2051  // };
2052
2053  // Gallery.prototype.getSocialButtons = function(wrapper_class, url, img_id, img_src, title, noCounter) {
2054  //     title = title || '';
2055
2056  // 	var html = this.$container.find('#social-share-html').html();
2057
2058  //     if (html !== undefined && html.length){
2059  //         html = html.replace(/{url}/g, url).replace(/{title}/g, title);
2060  //         if(noCounter) {
2061  //             // cut counter div
2062  //             html = html.replace(/<div class="counter-wrap.*?>.*?<\/div>/g, '');
2063  //         }
2064  //     }
2065
2066  //     return $('<div>', {
2067  //         class: wrapper_class,
2068  //         'data-img-thumbnail': img_src,
2069  //         'data-img-id': img_id,
2070  //         'data-img-title': title,
2071  //     }).html(html);
2072  // };
2073
2074  // Gallery.prototype.getSocialButtonsByImage = function(wrapper_class, $element, popup) {
2075
2076  //     var $img = $element.find('img'),
2077  //         imgSrc = $element.attr('href'),
2078  //         title = $element.attr('title'),
2079  //         $captionContainer = $element.find('.gg-image-caption'),
2080  //         url = location.href,
2081  // 		imageId = null;
2082
2083  // 	if($element.attr('data-type') == 'link' || $element.attr('data-video-source') == 'youtube') {
2084  // 		if($img.length) {
2085  // 			if($img.attr('data-gg-real-image-href')) {
2086  // 				imgSrc = $img.attr('data-gg-real-image-href');
2087  // 			} else {
2088  // 				imgSrc = $img.attr('src');
2089  // 			}
2090  // 		}
2091  // 	}
2092
2093  // 	if($element && $element.attr('id') && $element.attr('id').split('-').pop()) {
2094  // 		imageId = $element.attr('id').split('-').pop();
2095  // 	}
2096
2097  //     if ($captionContainer.length) {
2098  //         var caption = $.trim(
2099  //             $captionContainer.clone().html($captionContainer.html()
2100  //                 .replace(/<br\s*[\/]?>/gi, ' '))
2101  //                 .text()
2102  //                 .replace(/\s+/, ' ')
2103  //         );
2104
2105  //         if (caption.length) {
2106  //             title = caption;
2107  //         }
2108  //     }
2109
2110  //     if (imgSrc && imgSrc.indexOf('http') !== 0) {
2111  //         imgSrc = 'http:' + imgSrc;
2112  //     }
2113
2114  //     function updateQueryStringParameter(uri, key, value) {
2115  //         var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
2116  //         var separator = uri.indexOf('?') !== -1 ? "&" : "?";
2117  //         if (uri.match(re)) {
2118  //             return uri.replace(re, '$1' + key + "=" + value + '$2');
2119  //         } else {
2120  //             return uri + separator + key + "=" + value;
2121  //         }
2122  //     }
2123
2124  //     if (popup) {
2125  //         url = url.replace('#!', '?');
2126  //     }
2127  // 	if(imageId) {
2128  // 		url = updateQueryStringParameter(url, '_gallery', $element.attr('id'));
2129  // 		url = encodeURIComponent(updateQueryStringParameter(url, 'shared-image', imageId));
2130  // 	}
2131
2132  //     return this.getSocialButtons(wrapper_class, url, $element.attr('id'), imgSrc, title, true);
2133  // };
2134
2135  // Gallery.prototype.correctImageSocialButtons = function($imageSharing){
2136
2137  // if(!$imageSharing.length){
2138  //     return;
2139  // }
2140  // var $example = $imageSharing.eq(0),
2141  //     correctCss = {};
2142
2143  // if($example.hasClass('vertical')){
2144  //     var buttonWidth = $example.find('.social-sharing-button').eq(0).outerWidth();
2145  //     correctCss.width = buttonWidth;
2146  //     $example.width(buttonWidth);
2147  // }
2148
2149  // var width = $example.width();
2150  // var height = $example.height();
2151
2152  // if($example.hasClass('center')){
2153  //     $.extend(correctCss,{'margin-left': '-' + (width/2) + 'px'})
2154  // }
2155  // if($example.hasClass('middle')){
2156  //     $.extend(correctCss,{'margin-top': '-' + (height/2) + 'px'})
2157  // }
2158
2159  // $imageSharing.find('.social-sharing-button.print').on('click',function(){
2160  //     var image_url = $(this).closest('.supsystic-grid-gallery-image-sharing').data('img-url');
2161  //     window.open(image_url).print();
2162  // });
2163
2164  // $imageSharing.find('.social-sharing-button.mail').on('click',function(){
2165  //     var $infoElement = $(this).closest('.supsystic-grid-gallery-image-sharing'),
2166  //         image_id = $infoElement.data('img-id'),
2167  //         image_title = $infoElement.data('img-title');
2168  //     var url = window.location.href.replace(window.location.hash,'') + '#' + image_id + '/';
2169
2170  //     var src = 'mailto:[email protected]?subject=' + encodeURIComponent(document.title) + ',' + image_title + '&body=' + url;
2171  //     var iframe = $('<iframe id="mailtoFrame" src="' + src + '" width="1" height="1" border="0" frameborder="0"></iframe>');
2172
2173  //     $('body').append(iframe);
2174  //     window.setTimeout(function(){
2175  //         iframe.remove();
2176  //     }, 500);
2177  // });
2178
2179  // var self = this;
2180  // $imageSharing.each(function(){
2181
2182  //     $(this).css(correctCss);
2183
2184  //     var thumbnail = $(this).data('img-thumbnail');
2185
2186  //     if (thumbnail) {
2187
2188  //         for(var sharingClass in self.socialSharingImageOperators){
2189  //             var $button = $(this).find('.social-sharing-button.'+sharingClass);
2190  //             if($button.length){
2191  //                 var img_url = $(this).data('img-url'),
2192  //                     img_id = $(this).data('img-id'),
2193  // 					shareUrlObj = self.urlToObject($button.attr('href')),
2194  // 					newHref = '';
2195
2196  // 				// set gallery image for share link
2197  // 				shareUrlObj.params[self.socialSharingImageOperators[sharingClass]] = thumbnail;
2198  // 				newHref = self.objectToUrl(shareUrlObj);
2199
2200  // 				if(img_url) {
2201  // 					newHref = newHref.replace(
2202  // 						img_url,
2203  // 						self.addPopUpHashToUrl(self.socialButtonsUrl, img_id)
2204  // 					);
2205  // 				}
2206
2207  // 				$button.attr('href', newHref);
2208  //             }
2209  //         }
2210  //     }
2211  // });
2212
2213  // };
2214
2215  Gallery.prototype.urlToObject = function (strUrl) {
2216    if (!strUrl) {
2217      return null;
2218    }
2219    var posQ = strUrl.indexOf('?');
2220    if (posQ == -1) {
2221      return null;
2222    }
2223    var strQueryParams = strUrl.substr(posQ + 1),
2224      result = {
2225        url: strUrl.substr(0, posQ),
2226        params: {},
2227      };
2228    strQueryParams.split('&').forEach(function (part) {
2229      var item = part.split('=');
2230      if (item.length >= 2) {
2231        result.params[item[0]] = decodeURIComponent(item[1]);
2232      }
2233    });
2234    return result;
2235  };
2236
2237  Gallery.prototype.objectToUrl = function (specObj) {
2238    if (!specObj) {
2239      return null;
2240    }
2241
2242    var resUrl = '';
2243    if (specObj.url) {
2244      resUrl = specObj.url;
2245    }
2246    if (specObj.params) {
2247      var paramParts = [],
2248        paramKeys = Object.keys(specObj.params),
2249        indX = 0;
2250      for (indX = 0; indX < paramKeys.length; indX++) {
2251        paramParts.push(encodeURIComponent(paramKeys[indX]) + '=' + encodeURIComponent(specObj.params[paramKeys[indX]]));
2252      }
2253      resUrl = resUrl + '?' + paramParts.join('&');
2254    }
2255    return resUrl;
2256  };
2257
2258  Gallery.prototype.removePopUpHashFromUrl = function (url) {
2259    var match = url.match(/gg-\d+-\d+/);
2260    return url.replace(url[url.indexOf(match) - 1] + match, '');
2261  };
2262
2263  Gallery.prototype.addPopUpHashToUrl = function (url, hash) {
2264    if (!hash || !hash.length) {
2265      return url;
2266    }
2267    var prefix = '?';
2268    if (url.indexOf(prefix) != -1) prefix = '&';
2269    return url + prefix + hash;
2270  };
2271
2272  Gallery.prototype.openHashPopUp = function () {
2273    var getElementId = function () {
2274      var search = window.location.search;
2275      if (search.match(/gg-\d+-\d+/)) {
2276        return search.match(/gg-\d+-\d+/);
2277      }
2278
2279      var hash = window.location.hash;
2280      if (hash.match(/gg-\d+-\d+/)) {
2281        return hash.match(/gg-\d+-\d+/);
2282      }
2283    };
2284
2285    var elementId = getElementId(),
2286      $element = this.$container.find('#' + elementId + ', [data-id="' + elementId + '"]').first();
2287
2288    if ($element.length) {
2289      $element.click();
2290      var $figure;
2291
2292      if ($element.hasClass('hi-icon')) {
2293        $figure = $element.closest('figure.grid-gallery-caption');
2294      } else {
2295        $figure = $element.children('figure');
2296      }
2297
2298      if ($figure.length) {
2299        $('html, body').animate(
2300          {
2301            scrollTop: $figure.offset().top,
2302          },
2303          100
2304        );
2305      }
2306    }
2307  };
2308
2309  Gallery.prototype.updateQueryParams = function (url, params) {
2310    for (var param in params) {
2311      var re = new RegExp('[\\?&]' + param + '=([^&#]*)'),
2312        match = re.exec(url),
2313        delimiter,
2314        value = params[param];
2315
2316      if (match === null) {
2317        var hasQuestionMark = /\?/.test(url);
2318        delimiter = hasQuestionMark ? '&' : '?';
2319
2320        if (value) {
2321          url = url + delimiter + param + '=' + value;
2322        }
2323      } else {
2324        delimiter = match[0].charAt(0);
2325
2326        if (value) {
2327          url = url.replace(re, delimiter + param + '=' + value);
2328        } else {
2329          url = url.replace(re, '');
2330          if (delimiter === '?' && url.length) {
2331            url = '?' + url.substr(1);
2332          }
2333        }
2334      }
2335    }
2336
2337    return url;
2338  };
2339
2340  Gallery.prototype.changePopUpHash = function (hash) {
2341    var galleryId = this.$container.attr('data-gg-id'),
2342      galleryOpenPopupHashRegex = new RegExp('gg-' + galleryId + '(?:-(\\d+))*'),
2343      regexFoundGalleryImageId = galleryOpenPopupHashRegex.exec(hash),
2344      changedUrlDisabled = this.$container.attr('data-popup-disable-changed-url');
2345
2346    if (changedUrlDisabled !== 'true') {
2347      // if image id not exits
2348      if (!regexFoundGalleryImageId || regexFoundGalleryImageId.length < 2 || !regexFoundGalleryImageId[1]) {
2349        return;
2350      }
2351      this.popupIsOpened = true;
2352
2353      if (this.ignoreStateChange) {
2354        this.ignoreStateChange = false;
2355        return;
2356      }
2357      var queryParams = this.updateQueryParams(window.location.search, { _gallery: hash }),
2358        stateUrl = window.location.pathname + queryParams;
2359
2360      this.historyStateChange = true;
2361
2362      if (!this.popupIsInit) {
2363        if (queryParams === document.location.search) {
2364          History.replaceState(
2365            {
2366              type: 'sc-gallery',
2367              hash: hash,
2368              state: 'close',
2369            },
2370            document.title,
2371            window.location.pathname + this.updateQueryParams(window.location.search, { _gallery: null })
2372          );
2373
2374          History.pushState(
2375            {
2376              type: 'sc-gallery',
2377              hash: hash,
2378              state: 'init',
2379            },
2380            document.title,
2381            stateUrl
2382          );
2383        } else {
2384          History.replaceState(
2385            {
2386              type: 'sc-gallery',
2387              hash: hash,
2388              state: 'init',
2389            },
2390            document.title,
2391            stateUrl
2392          );
2393        }
2394
2395        this.popupIsInit = true;
2396      } else {
2397        if (this.disablePopupHistory) {
2398          History.replaceState(
2399            {
2400              type: 'sc-gallery',
2401              hash: hash,
2402              state: 'change',
2403            },
2404            document.title,
2405            stateUrl
2406          );
2407        } else {
2408          History.pushState(
2409            {
2410              type: 'sc-gallery',
2411              hash: hash,
2412              state: 'change',
2413            },
2414            document.title,
2415            stateUrl
2416          );
2417        }
2418      }
2419
2420      this.historyStateChange = false;
2421    }
2422  };
2423
2424  Gallery.prototype.clearPopUpHash = function () {
2425    this.historyStateChange = true;
2426
2427    if (this.disablePopupHistory) {
2428      History.replaceState(
2429        {
2430          type: 'sc-gallery',
2431          hash: '',
2432          state: 'close',
2433        },
2434        document.title,
2435        window.location.pathname + this.updateQueryParams(window.location.search, { _gallery: null })
2436      );
2437    } else {
2438      History.pushState(
2439        {
2440          type: 'sc-gallery',
2441          hash: '',
2442          state: 'close',
2443        },
2444        document.title,
2445        window.location.pathname + this.updateQueryParams(window.location.search, { _gallery: null })
2446      );
2447    }
2448
2449    this.historyStateChange = false;
2450    this.popupIsOpened = false;
2451  };
2452
2453  Gallery.prototype.getRealImgSizeInBrowser = function (arguments) {
2454    if (!arguments && !arguments.length) {
2455      return null;
2456    }
2457    if (arguments.length > 1) {
2458      returnType = arguments[1];
2459    }
2460    if (arguments.length) {
2461      $image = arguments[0];
2462    }
2463
2464    var returnData = null,
2465      boundRect = null;
2466    if ($image && $image.length && $image[0].getBoundingClientRect) {
2467      boundRect = $image[0].getBoundingClientRect();
2468    }
2469
2470    if (returnType == 'h') {
2471      if (boundRect && boundRect.height) {
2472        returnData = boundRect.height;
2473      } else {
2474        returnData = parseFloat($image.css('height'));
2475      }
2476    } else if (returnType == 'w') {
2477      if (boundRect && boundRect.width) {
2478        returnData = boundRect.width;
2479      } else {
2480        returnData = parseFloat($image.css('width'));
2481      }
2482    }
2483
2484    return returnData;
2485  };
2486
2487  Gallery.prototype.lazyLoadTriggerHandler = function () {
2488    $(document).trigger('scroll');
2489  };
2490  Gallery.prototype.lazyLoadDistanceRefresh = function (waitTime) {
2491    var self = this,
2492      galleryType = this.$container.data('gridType');
2493
2494    if (typeof waitTime == 'undefined') {
2495      waitTime = 400;
2496    }
2497
2498    // need run function once at every load
2499    if (self.ggLazyTimeOut) {
2500      clearTimeout(self.ggLazyTimeOut);
2501    }
2502    self.ggLazyTimeOut = setTimeout(function () {
2503      setTimeout(function () {
2504        $.each(self.$elements, function (index, el) {
2505          var $el = $(el);
2506          if ($el.data('grid-gallery-type') == 'polaroid') {
2507            self.polaroidCaptionCalculate($el);
2508          }
2509        });
2510      }, waitTime + 50);
2511
2512      switch (galleryType) {
2513        case 4:
2514          $(document).trigger('ggMosaicResizedEvent');
2515          break;
2516        case 0:
2517          if (typeof self.setCaptionOnHoverImage == 'function') {
2518            self.setCaptionOnHoverImage();
2519          }
2520          // if hidden images  not showing
2521          setTimeout(function () {
2522            self.lazyLoadTriggerHandler();
2523            setTimeout(function () {
2524              if (self.wookmark) {
2525                self.wookmark.trigger('refreshWookmark');
2526              }
2527            }, 50);
2528          }, waitTime + 60); //450); // animation transition time
2529          break;
2530        case 1:
2531          if (typeof self.setCaptionOnHoverImage == 'function') {
2532            self.setCaptionOnHoverImage();
2533          }
2534          $.each(self.$elements, function (index, el) {
2535            var $el = $(el);
2536            if ($el.data('grid-gallery-type') == '3d-cube') {
2537              self.changeImageHeightFor3dCubeEffect($el, $el.width(), $el.find('img').length ? $el.find('img').height() : $el.height());
2538            }
2539          });
2540        case 2:
2541        case 3:
2542        default:
2543          //self.initWookmark();
2544          // if hidden images  not showing
2545          setTimeout(function () {
2546            self.lazyLoadTriggerHandler();
2547            self.initWookmark();
2548          }, waitTime + 50); //450); // animation transition time
2549          break;
2550      }
2551    }, 100);
2552  };
2553
2554  Gallery.prototype.initLazyLoad = function () {
2555    var self = this,
2556      hoverImgSrc = this.$container.data('image-on-hover');
2557    /*if(hoverImgSrc && hoverImgSrc.length) {
2558			// lazy load not work for image on hover
2559			return;
2560		}*/
2561    var showMoreCategory = this.$container.find('.showMoreCategory'),
2562      effect = this.$container.data('lazyload-effect'),
2563      duration = this.$container.data('lazyload-effect-duration');
2564
2565    if (typeof effect == 'undefined') {
2566      effect = 'show';
2567      duration = 400;
2568    }
2569    var waitTime = effect == 'fadeIn' ? 200 : duration;
2570
2571    self.ggLazyTimeOut = null;
2572    this.$container.find('.ggLazyImg').ggLazyLoad({
2573      data_attribute: 'gg-real-image-href',
2574      threshold: 50,
2575      effect: effect,
2576      effectspeed: duration,
2577      skip_invisible: showMoreCategory.length > 0,
2578      load: function (event) {
2579        var image = $(this);
2580        self.lazyLoadDistanceRefresh(waitTime);
2581        if (self.$container.data('gridType') != 0) {
2582          image.closest('div .crop').css('height', '');
2583        }
2584        image.closest('figure').css('height', 'auto');
2585        if (self.$container.data('gridType') == 2 && self.$elements) {
2586          setTimeout(function () {
2587            self.resizeElementHeight(image, image.closest('figure'));
2588          }, waitTime + 20); //460); // animation transition time + 20ms
2589        }
2590      },
2591    });
2592  };
2593
2594  Gallery.prototype.init = function () {
2595    //this.$container.imagesLoaded().done($.proxy(function () {
2596    var self = this;
2597    this.setImagesHeight();
2598    var galleryBeforeInitId = 'GalleryBeforeInit' + this.galleryContainerId;
2599
2600    setTimeout(() => {
2601      $(document).trigger(galleryBeforeInitId, [this]);
2602    }, 10);
2603
2604    this.hidePreloader();
2605    this.showCaption();
2606    this.initRowsMode();
2607    this.initHorizontalGalleryType();
2608    this.initQuicksand();
2609
2610    if (this.$container.attr('data-fullscreen') == 'true') {
2611      this.correctFullScreenWidthGallery();
2612      $(window).resize(function () {
2613        self.correctFullScreenWidthGallery();
2614      });
2615    }
2616
2617    this.initHorizontalMode();
2618    this.setOverlayTransparency();
2619    this.initCaptionCalculations();
2620    this.initCaptionEffects();
2621    this.hideTitleTooltip();
2622    this.initPagination();
2623
2624    this.initPopup();
2625
2626    this.setMouseShadow();
2627    this.setImageOverlay();
2628
2629    this.loadFontFamily();
2630    this.hidePopupCaptions();
2631    this.preventImages();
2632    this.initWookmark();
2633    this.initCategories();
2634    this.setIconsPosition();
2635
2636    this.correctMargin();
2637    this.initControll();
2638    this.showGalleryParts();
2639    this.initLazyLoad();
2640
2641    this.initSocialSharing();
2642
2643    // iOS Safari fix
2644    setTimeout(function () {
2645      if (self.wookmark) {
2646        self.wookmark.trigger('refreshWookmark');
2647      }
2648    }, 500);
2649
2650    setTimeout(function () {
2651      self.openHashPopUp();
2652    }, 500);
2653
2654    $(document).ready(function () {
2655      $(document).trigger('GalleryAfterInit', self);
2656    });
2657
2658    var galleryId = this.$container.attr('data-gg-id'),
2659      openByLinkRegexp = new RegExp('#gg-open-' + galleryId + '(\\-([\\d]+))*$');
2660
2661    History.Adapter.bind(window, 'statechange', function (event) {
2662      var state = History.getState();
2663
2664      // self.historyStateChange if true means manual update state and we need skip this event
2665      if (!self.historyStateChange) {
2666        if ((state.data.type !== 'sc-gallery' && self.popupIsOpened) || (state.data.type === 'sc-gallery' && (state.data.state === 'close' || state.data.state === 'hashchange') && self.popupIsOpened)) {
2667          if (self.popupType == 'pretty-photo') {
2668            this.$prettyPhoto && this.$prettyPhoto.close();
2669          }
2670
2671          if (self.popupType == 'colorbox') {
2672            $.colorbox && $.colorbox.close();
2673          }
2674
2675          if (self.popupType == 'photobox') {
2676            window._photobox && window._photobox.close();
2677          }
2678        }
2679
2680        // On history open image
2681        if (state.data.type === 'sc-gallery' && state.data.hash && state.data.state !== 'close') {
2682          self.ignoreStateChange = true;
2683
2684          var $el = self.$container.find('#' + state.data.hash + ', [data-id="' + state.data.hash + '"]').first();
2685
2686          if (self.popupIsOpened) {
2687            if (self.popupType == 'pretty-photo' && this.$prettyPhoto) {
2688              var href = $el.attr('href'),
2689                index = this.$prettyPhoto.getImagesList().indexOf(href);
2690              this.$prettyPhoto.changePage(index);
2691            }
2692
2693            if (self.popupType == 'colorbox') {
2694              $.colorbox.resizeResponsive($el);
2695            }
2696
2697            if (self.popupType == 'photobox') {
2698              var images = window._photobox.getImages(),
2699                href = $el.attr('href');
2700
2701              for (var i = 0; i < images.length; i++) {
2702                if (images[i][0] == href || images[i][0] == 'http:' + href || images[i][0] == 'https:' + href) {
2703                  window._photobox.changeImage(i);
2704                }
2705              }
2706            }
2707          } else {
2708            $el.trigger('click');
2709          }
2710        }
2711      }
2712    });
2713
2714    //check url and show popups
2715    //options "Open by link in popup"
2716    function checkUrl() {
2717      var hash = window.location.hash,
2718        matches = openByLinkRegexp.exec(hash);
2719
2720      if (matches) {
2721        History.replaceState(
2722          {
2723            type: 'sc-gallery',
2724            hash: '',
2725            state: 'hashchange',
2726          },
2727          document.title,
2728          window.location.pathname
2729        );
2730
2731        var position = matches[2] ? 'eq(' + (matches[2] - 1) + ')' : 'first';
2732        self.$container.find('.gg-link:' + position + ', .hi-icon:' + position).trigger('click');
2733      }
2734    }
2735
2736    $(window).on('hashchange', function (event) {
2737      checkUrl();
2738    });
2739
2740    $(document).ready(function () {
2741      checkUrl();
2742    });
2743
2744    //}, this));
2745
2746    $(window).on(
2747      'resize',
2748      $.proxy(function () {
2749        this.correctMargin();
2750        this.resizeHorizontalElements();
2751        this.initHorizontalMode();
2752      }, this)
2753    );
2754  };
2755
2756  Gallery.prototype.resizeHorizontalElements = function () {
2757    var self = this;
2758    if (this.$container.data('gridType') == 2 && this.$elements) {
2759      this.$elements.each(function () {
2760        var element = $(this),
2761          image = element.find('img');
2762        if (image) {
2763          self.resizeElementHeight(image, element);
2764        }
2765      });
2766    }
2767  };
2768
2769  Gallery.prototype.resizeElementHeight = function (image, element) {
2770    var imageHeight = parseInt(image.css('height'));
2771    if (!isNaN(imageHeight) && !element.hasClass('initialized')) {
2772      element.css('height', Math.floor(imageHeight - 1) + 'px');
2773    }
2774    if (!image.hasClass('ggLazyImg')) {
2775      image.removeClass('ggNotInitImg');
2776      this.polaroidCaptionCalculate(element);
2777    }
2778  };
2779
2780  window.initGridGallery = function (el, autoInit) {
2781    var makeSelector = function (el) {
2782      return '#' + el.id;
2783    };
2784    return new Gallery(makeSelector(el), autoInit);
2785  };
2786
2787  window.contentLoaded = function () {
2788    var $galleries = $(".grid-gallery:not('.initialized')"),
2789      $promise = new $.Deferred().resolve();
2790
2791    if ($galleries.length > 0) {
2792      $.each($galleries, function (i, el) {
2793        $promise = $promise.then(function () {
2794          return new Gallery(el, true);
2795        });
2796      });
2797    }
2798
2799    $('.crop').css('display', 'block');
2800  };
2801
2802  if (!init) {
2803    var hammer = new Hammer_gg(document),
2804      $anyGallery = $('.grid-gallery:first'),
2805      isMobile = parseInt($anyGallery.attr('data-is-mobile'));
2806    // only if mobile, because "mouse dragg" include for this event
2807    if (!isNaN(isMobile) && isMobile) {
2808      // On swipe click next prev button in active popup
2809      hammer.on('swipeleft swiperight', function (event) {
2810        if (event.type == 'swipeleft') {
2811          $('#colorbox:visible #cboxNext, .pp_pic_holder a.pp_arrow_next, #cboxOverlay:visible #pbNextBtn').click();
2812        } else {
2813          $('#colorbox:visible #cboxPrevious, .pp_pic_holder a.pp_arrow_previous, #cboxOverlay:visible #pbPrevBtn').click();
2814        }
2815      });
2816    }
2817    init = true;
2818  }
2819
2820  $(document)
2821    .ready(function () {
2822      contentLoaded();
2823    })
2824    .ajaxComplete(function () {
2825      contentLoaded();
2826    });
2827
2828  if (jQuery('body').hasClass('oceanwp-theme')) {
2829    function oceanwpFixedFooter() {
2830      $('#main').css('min-height', '0px');
2831    }
2832    jQuery(window).resize(function () {
2833      oceanwpFixedFooter();
2834    });
2835    jQuery(document).ready(function () {
2836      setTimeout(function () {
2837        oceanwpFixedFooter();
2838      }, 3000);
2839    });
2840  }
2841
2842  // added Gallery initialization by trigger
2843  $(document).on('ggFirInitialize', function () {
2844    contentLoaded();
2845  });
2846
2847  //if a customer enter an e-mail for image link in gallery he'll get a mailto: link
2848  $('a.gg-link').each(function () {
2849    var gLink = $(this).attr('href');
2850    var reg = /[0-9a-z_]+@[0-9a-z_]+\.[a-z]{2,5}/i;
2851    if (gLink) {
2852      var isEmail = gLink.match(reg);
2853      if (isEmail) {
2854        $(this).attr('href', 'mailto:' + isEmail[0]);
2855      }
2856    }
2857  });
2858
2859  jQuery(document).ready(function () {
2860    jQuery('.supSocialIconBookmarkBtn').click(function () {
2861      alert('Please press Ctrl+D (Cmd+D on Mac) to add this page to your bookmarks.');
2862    });
2863    setTimeout(function () {
2864      jQuery('body')
2865        .find('.supsystic-social-sharing')
2866        .each(function (key, value) {
2867          var summary = 0;
2868          jQuery(this)
2869            .find('.social-sharing-button')
2870            .each(function (key2, value2) {
2871              if (jQuery(this).parent().hasClass('supsystic-social-sharing-popup')) return;
2872              var networks = jQuery(this).attr('data-networks');
2873              networks = jQuery.parseJSON(networks);
2874              var attachId = jQuery('.supsystic-social-sharing').eq(key).closest('[data-attachment-id]').attr('data-attachment-id');
2875              if (typeof attachId != 'undefined') {
2876                var nid = jQuery(this).attr('data-nid');
2877                var counter = networks[attachId][nid];
2878                if (parseInt(counter) && !isNaN(counter)) {
2879                  summary = summary + parseInt(counter);
2880                }
2881                var counterWrapper = '';
2882                if (jQuery(this).hasClass('counter-standard')) {
2883                  jQuery(this).find('.counter-wrap.standard').remove('');
2884                  counterWrapper = '<div class="counter-wrap standard"><span class="counter">' + counter + '</span></div>';
2885                }
2886                if (jQuery(this).hasClass('counter-arrowed')) {
2887                  jQuery(this).find('.counter-wrap.arrowed').remove('');
2888                  counterWrapper = '<div class="counter-wrap arrowed"><span class="counter">' + counter + '</span></div>';
2889                }
2890                if (jQuery(this).hasClass('counter-white-arrowed')) {
2891                  jQuery(this).find('.counter-wrap.white-arrowed').remove('');
2892                  counterWrapper = '<div class="counter-wrap white-arrowed"><span class="counter">' + counter + '</span></div>';
2893                }
2894                var attachId = jQuery(this).append(counterWrapper);
2895              }
2896            });
2897          summary = '<span>Shares</span> <span>' + summary + '</span>';
2898          jQuery(this).closest('a').find('.supsystic-social-sharing-total-counter.counter-wrap').html(summary);
2899        });
2900    }, 1000);
2901  });
2902})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.