PageSourceSearch

https://www.guardchild.com/wp-content/plugins/popup-by-supsystic/modules/popup/js/frontend.popup.js?ver=1.13.0

js guardchild.com collected 2026-10-02 11:19:18 UTC 62,488 bytes, 1,611 lines download raw bytes

1var g_ppsWindowLoaded = false,
2  g_ppsIsPageCached = false,
3  g_ppsIsPageCachedChecked = false,
4  g_ppsShowCallbacks = {},
5  g_ppsClks = {};
6jQuery(document).ready(function () {
7  if (typeof ppsPopupsFromFooter !== 'undefined' && ppsPopupsFromFooter && ppsPopupsFromFooter.length) {
8    ppsPopups = typeof ppsPopups === 'undefined' ? [] : ppsPopups;
9    ppsPopups = ppsPopups.concat(ppsPopupsFromFooter);
10  }
11  jQuery(document).trigger('ppsBeforePopupsStartInit', ppsPopups);
12  if (typeof ppsPopups !== 'undefined' && ppsPopups && ppsPopups.length) {
13    ppsInitBgOverlay();
14    jQuery(document).trigger('ppsBeforePopupsInit', ppsPopups);
15    for (var i = 0; i < ppsPopups.length; i++) {
16      // If in popups lists exist groups, we need combine it to one wrapper for owl-carousel
17      if (ppsPopups[i].params.main.groups && ppsPopups[i].params.main.groups.length > 0) {
18        for (var y = 0; y < ppsPopups[i].params.main.groups.length; y++) {
19          var newGroupDiv = 'ppsGroupWrapper-' + ppsPopups[i].params.main.groups[y];
20          var className = newGroupDiv;
21          if (jQuery('.' + className).length > 0) {
22            jQuery('.' + className).append(ppsPopups[i].rendered_html);
23            jQuery('#ppsPopupShell_' + ppsPopups[i].view_id)
24              .find('.ppsPopupClose')
25              .remove();
26          } else {
27            newGroupDiv = '<div class="owl-carousel ppsGroupWrappers ' + className + '"/>';
28            jQuery('body').append(newGroupDiv);
29            jQuery('.' + className).append(ppsPopups[i].rendered_html);
30            jQuery('#ppsPopupShell_' + ppsPopups[i].view_id)
31              .find('.ppsPopupClose')
32              .remove();
33            jQuery('.' + className)
34              .wrapAll('<div class="ppsGroupOverlay"></div>')
35              .wrapAll('<div class="ppsGroupSubOverlay"></div>');
36            jQuery('.ppsGroupSubOverlay').append('<div class="ppsGroupOverlayClose"></div>');
37            jQuery('body').on('click', '.ppsGroupOverlayClose', function () {
38              jQuery(this).closest('.ppsGroupOverlay').fadeOut();
39            });
40          }
41        }
42        // Bind our events
43        ppsMovePopupStyles(ppsPopups[i]); /* Move back from replaced style tags - to normal style tag */
44        ppsBindPopupLoad(ppsPopups[i]);
45        // If one pop-up window is displayed, then others from this group should be displayed in owl-carousel.
46        ppsBindPopupShow(ppsPopups[i]);
47        ppsBindPopupActions(ppsPopups[i]);
48        // In this case close button - secondary option
49        ppsBindPopupClose(ppsPopups[i]);
50        ppsBindPopupSubscribers(ppsPopups[i]);
51        ppsBindPopupForceShow(ppsPopups[i]);
52      } else {
53        // If we don't use groups
54        jQuery('body').append(ppsPopups[i].rendered_html);
55        ppsMovePopupStyles(ppsPopups[i]); /* Move back from replaced style tags - to normal style tag */
56        ppsBindPopupLoad(ppsPopups[i]);
57        ppsBindPopupShow(ppsPopups[i]);
58        ppsBindPopupActions(ppsPopups[i]);
59        ppsBindPopupClose(ppsPopups[i]);
60        ppsBindPopupSubscribers(ppsPopups[i]);
61        ppsBindPopupForceShow(ppsPopups[i]);
62      }
63    }
64
65    jQuery('.ppsGroupWrappers')
66      .find('link, img.ppsPopupPreloadImg')
67      .each(function () {
68        var newCloneItem = jQuery(this).clone();
69        jQuery(this).remove();
70        jQuery('body').append(newCloneItem);
71      });
72    jQuery('.ppsGroupWrappers')
73      .find('.ppsPopupShell')
74      .each(function (index) {
75        jQuery(this).css({ display: 'block', position: 'relative', left: 'inherit', right: 'inherit', top: 'inherit', bottom: 'inherit' });
76      });
77    //Init owl-carousel for all created groups
78    jQuery('.ppsGroupWrappers').each(function (index) {
79      var owlCarousel = jQuery(this).owlCarousel({
80        responsiveClass: true,
81        loop: false,
82        rewind: true,
83        responsive: {
84          0: {
85            items: 1,
86            nav: true,
87            loop: false,
88          },
89        },
90      });
91      owlCarousel.each(function (index) {
92        jQuery(this).find('.owl-nav, .owl-dots').wrapAll("<div class='owl-control
92s'></div>");
93      });
94    });
95
96    _ppsBindOnElementClickPopups();
97    _ppsBindClickHrefSaving();
98    /* To make sure - that we checked all elements, even those who loaded later then current code run */
99    setTimeout(_ppsBindOnElementClickPopups, 300);
100    jQuery(document).trigger('ppsAfterPopupsInit', ppsPopups);
101    jQuery(window).resize(function () {
102      for (var i = 0; i < ppsPopups.length; i++) {
103        if (ppsPopups[i].is_visible) {
104          _ppsPositionPopup({ popup: ppsPopups[i] });
105          _ppsCloseBtnListenersSafari({ popup: ppsPopups[i] });
106        }
107      }
108    });
109    /* For case when for some reason jQuery(window).load() will not trigger -
110        make it work correctly with re-position and re-sizing in any case */
111    setTimeout(function () {
112      g_ppsWindowLoaded = true;
113    }, 5000);
114  }
115});
116jQuery(window).on('load', function () {
117  g_ppsWindowLoaded = true;
118  for (var i = 0; i < ppsPopups.length; i++) {
119    if (ppsPopups[i].is_visible) {
120      _ppsPositionPopup({ popup: ppsPopups[i] });
121    }
122  }
123});
124function _ppsAddPopUpClick(popupId, btn) {
125  g_ppsClks[popupId] = btn;
126}
127function _ppsGetPopUpClick(popupId) {
128  return g_ppsClks[popupId];
129}
130function _ppsCheckPopupOnFollowClk(lnk) {
131  var href = lnk.href,
132    hash = lnk.hash,
133    wndLocation = window.location.href,
134    wndHash = window.location.hash;
135  if (hash) {
136    if (hash && hash != '') {
137      href = str_replace(href, hash, '');
138    }
139    if (wndHash && wndHash != '') {
140      wndLocation = str_replace(wndLocation, wndHash, '');
141    }
142    if (strpos(href, '/', href.length - 1) !== false) {
143      href = href.substr(0, href.length - 1);
144    }
145    if (strpos(wndLocation, '/', wndLocation.length - 1) !== false) {
146      wndLocation = wndLocation.substr(0, wndLocation.length - 1);
147    }
148    if (wndLocation == href) {
149      setTimeout(function () {
150        toeReload();
151      }, 100);
152    }
153  }
154}
155function _ppsBindOnElementClickPopups() {
156  var $clickOnLinks = jQuery('[href*="#ppsShowPopUp_"]:not(.ppsClickBinded)');
157  if ($clickOnLinks && $clickOnLinks.length) {
158    $clickOnLinks
159      .each(function () {
160        jQuery(this).click(function () {
161          var popupId = jQuery(this).attr('href');
162          if (popupId && popupId != '') {
163            popupId = popupId.split('_');
164            popupId = popupId[1] ? parseInt(popupId[1]) : 0;
165            if (popupId) {
166              var popup = ppsGetPopupById(popupId);
167              if (popup && popup.params.main.show_on == 'link_follow') {
168                _ppsCheckPopupOnFollowClk(this);
169                return true;
170              }
171              _ppsAddPopUpClick(popupId, this);
172              if (!_ppsPopupBindDelay(popupId, 'show_on_click_on_el_delay', 'show_on_click_on_el_enb_delay')) {
173                ppsShowPopup(popupId);
174              }
175            } else {
176              _ppsCheckPopupOnFollowClk(this);
177              return true;
178            }
179          }
180          return false;
181        });
182      })
183      .addClass('ppsClickBinded');
184  }
185  var $clickOnMenuItems = jQuery('[title*="#ppsShowPopUp_"]:not(.ppsClickBinded)'); /* You can also set this in title - for menu items for example */
186  if ($clickOnMenuItems && $clickOnMenuItems.length) {
187    $clickOnMenuItems
188      .each(function () {
189        var title = jQuery(this).attr('title'),
190          matched = title.match(/#ppsShowPopUp_(\d+)/);
191        if (matched && matched.length == 2) {
192          var popupId = parseInt(matched[1]);
193          if (popupId) {
194            jQuery(this)
195              .data('popup-id', popupId)
196              .attr('title', str_replace(title, matched[0], ''))
197              .click(function () {
198                var popupId = jQuery(this).data('popup-id');
199                _ppsAddPopUpClick(popupId, this);
200                if (!_ppsPopupBindDelay(popupId, 'show_on_click_on_el_delay', 'show_on_click_on_el_enb_delay')) {
201                  ppsShowPopup(popupId);
202                }
203                return false;
204              });
205          }
206        }
207      })
208      .addClass('ppsClickBinded');
209  }
210}
211function ppsMovePopupStyles(popup) {
212  var $style = jQuery('<style type="text/css" />'),
213    $replacerTag = jQuery('#ppsPopupStylesHidden_' + popup.view_id);
214  $style.appendTo('body').html($replacerTag.html());
215  $replacerTag.remove();
216}
217function ppsBindPopupLoad(popup) {
218  var preloadImgs = jQuery('.ppsPopupPreloadImg_' + popup.view_id);
219  popup._imgsCount = preloadImgs.length;
220  if (popup._imgsCount) {
221    popup._imgsLoaded = false;
222    popup._imgsLoadedCount = 0;
223    preloadImgs.bind('load error', function () {
224      popup._imgsLoadedCount++;
225      if (popup._imgsLoadedCount >= popup._imgsCount) {
226        popup._imgsLoaded = true;
227        var $shell = ppsGetPopupShell(popup);
228        $shell.trigger('ppsShowPopupAfterAllImgs', popup);
229      }
230    });
231  } else {
232    if (toeInArrayPps(popup.type, ['iframe', 'pdf'])) {
233      popup._imgsLoaded = false;
234      var $shell = ppsGetPopupShell(popup);
235      $shell.find('.ppsMainFrame').bind('load error', function () {
236        var wasTriggeredBefore = popup._imgsLoaded;
237        popup._imgsLoaded = true;
238        if (!wasTriggeredBefore) {
239          setTimeout(function () {
240            $shell.trigger('ppsShowPopupAfterAllImgs', popup);
241          }, 1000); /* This timeout need to be here - to wait until loaded frame will be correctly rendered */
242        }
243      });
244    } else {
245      popup._imgsLoaded = true;
246    }
247  }
248  /* Additional re-calculation for case if there are too much images */
249  var $shell = ppsGetPopupShell(popup),
250    $imgs = $shell.find('img'),
251    imgsCnt = $imgs ? $imgs.length : 0;
252  if (imgsCnt) {
253    if (popup._imgsCount) {
254      var substracted = false;
255      preloadImgs.each(function () {
256        var $preload = jQuery(this),
257          preloadSrc = $preload.attr('src');
258        $imgs.each(function () {
259          var $img = jQuery(this),
260            imgSrc = $img.attr('src');
261          if (imgSrc == preloadSrc) {
262            /*Preload is same as image - don't count it*/
263            $imgs = $imgs.filter(this);
264            substracted = true;
265            return false;
266          }
267        });
268      });
269      if (substracted) {
270        imgsCnt = $imgs.length;
271      }
272    }
273    if (imgsCnt) {
274      $imgs.bind('load error', function () {
275        imgsCnt--;
276        if (imgsCnt <= 0 && popup.is_visible) {
277          _ppsPositionPopup({ shell: $shell, popup: popup, recalc: true });
278        }
279      });
280    }
281  }
282}
283function ppsBindPopupShow(popup) {
284  _ppsCheckBindVideo({ popup: popup });
285  switch (popup.params.main.show_on) {
286    case 'page_load':
287      if (!_ppsPopupBindDelay(popup, 'show_on_page_load_delay', 'show_on_page_load_enb_delay')) {
288        if (popup.type == 'fb_like') {
289          /* FB Like will be rendered right after all widget content - will be loaded */
290          popup.render_with_fb_load = true;
291        } else {
292          ppsCheckShowPopup(popup);
293        }
294      }
295      break;
296    case 'click_on_page':
297      jQuery(document).click(function () {
298        if (!popup.click_on_page_displayed) {
299          ppsCheckShowPopup(popup);
300          popup.click_on_page_displayed = true;
301        }
302      });
303      break;
304    case 'click_on_element':
305      /* @see _ppsBindOnElementClickPopups() */
306      break;
307    case 'scroll_window':
308      jQuery(window).scroll(function () {
309        if (parseInt(popup.params.main.show_on_scroll_window_enb_perc_scroll)) {
310          var percScroll = parseInt(popup.params.main.show_on_scroll_window_perc_scroll);
311          if (percScroll) {
312            var docHt = jQuery(document).height(),
313              wndHt = jQuery(window).height(),
314              wndScrollPos = jQuery(window).scrollTop(),
315              wndScrollHt = docHt - wndHt,
316              currScrollPerc = (wndScrollPos * 100) / wndScrollHt;
317            if (wndScrollHt > 0 && currScrollPerc < percScroll) {
318              return;
319            }
320          }
321        }
322        if (!popup.scroll_window_displayed) {
323          var delay = 0;
324          if (popup.params.main.show_on_scroll_window_enb_delay && parseInt(popup.params.main.show_on_scroll_window_enb_delay)) {
325            popup.params.main.show_on_scroll_window_delay = parseInt(popup.params.main.show_on_scroll_window_delay);
326            if (popup.params.main.show_on_scroll_window_delay) {
327              delay = popup.params.main.show_on_scroll_window_delay * 1000;
328            }
329          }
330          if (delay) {
331            setTimeout(function () {
332              ppsCheckShowPopup(popup);
333            }, delay);
334          } else {
335            ppsCheckShowPopup(popup);
336          }
337          popup.scroll_window_displayed = true;
338        }
339      });
340      break;
341  }
342}
343function ppsBindPopupClose(popup) {
344  /* For now - only one method - click on close btn */
345  var $shell = ppsGetPopupShell(popup);
346  $shell.find('.ppsPopupClose').click(function () {
347    ppsClosePopup(popup);
348    return false;
349  });
350}
351function ppsBindPopupSubscribers(popup) {
352  if (popup.params.tpl.enb_subscribe) {
353    var $shell = ppsGetPopupShell(popup),
354      $form = $shell.find('.ppsSubscribeForm'),
355      $inFormCloseBtn = $form.find('.ppsPopupClose');
356    switch (popup.params.tpl.sub_dest) {
357      case 'aweber':
358        /* No ajax action here */
359        break;
360      case 'wordpress':
361      case 'mailchimp':
362      case 'mailpoet':
363      default:
364        $form.submit(function () {
365          var submitBtn = jQuery(this).find('input[type=submit]'),
366            self = this,
367            msgEl = jQuery(this).find('.ppsSubMsg');
368          submitBtn.attr('disabled', 'disabled');
369          jQuery(this).sendFormPps({
370            msgElID: msgEl,
371            onSuccess: function (res) {
372              jQuery(self).find('input[type=submit]').removeAttr('disabled');
373              if (!res.error) {
374                var parentShell = jQuery(self).parents('.ppsSubscribeShell'),
375                  closeInsideBtn = jQuery(self).find('.ppsPopupClose'); /* Close button can be inside form - we can't remove it, because in this case user will not be able to close PopUp */
376                if (closeInsideBtn && closeInsideBtn.length) {
377                  closeInsideBtn.appendTo(parentShell);
378                }
379                msgEl.appendTo(parentShell);
380                jQuery(self).animateRemovePps(300, function () {
381                  _ppsPositionPopup({ shell: $shell, popup: popup, recalc: true });
382                });
383                var $hideAfterSubscribe = $shell.find('.ppsHideAfterSubscribe');
384                if ($hideAfterSubscribe && $hideAfterSubscribe.length) {
385                  $hideAfterSubscribe.animateRemovePps(300);
386                }
387                ppsPopupSubscribeSuccess(popup);
388                var redirectTo = popup.params.sub_redirect_to_btn_url_href ? popup.params.sub_redirect_to_btn_url_href : false;
389                if (!redirectTo && res.data && res.data.redirect) {
390                  redirectTo = res.data.redirect;
391                }
392                if (redirectTo) {
393                  toeRedirect(redirectTo, parseInt(popup.params.tpl.sub_redirect_new_wnd));
394                }
395              } else {
396                _ppsPopupAddStat(popup, 'subscribe_error'); /* Save close popup statistics */
397                if (res.data && res.data.emailExistsRedirect) {
398                  /* Simulate here client side subscribe success if email already exists */
399                  ppsPopupSubscribeSuccess(popup, { ignoreSendStat: true });
400                  if (res.data.emailExistsRedirect.indexOf('http') !== 0) {
401                    res.data.emailExistsRedirect = window.location.href + res.data.emailExistsRedirect;
402                  }
403                  toeRedirect(res.data.emailExistsRedirect);
404                }
405              }
406            },
407          });
408          return false;
409        });
410        break;
411    }
412    /* If user even press Enter on exit btn in form -let it still submit it.
413         Close only if user click it using mouse*/
414    if ($inFormCloseBtn && $inFormCloseBtn.length) {
415      $inFormCloseBtn.keydown(function (e) {
416        if (e.keyCode == 13) {
417          /* Enter */
418          $form.submit();
419          return false;
420        }
421      });
422    }
423    /* Required fields validation for Safary browser */
424    if (navigator.userAgent.indexOf('Safari') > -1 && !(navigator.userAgent.indexOf('Chrome') > -1)) {
425      var forms = $shell.get(0).getElementsByTagName('form');
426      if (forms && forms.length) {
427        for (var i = 0; i < forms.length; i++) {
428          forms[i].noValidate = true;
429          forms[i].addEventListener(
430            'submit',
431            function (event) {
432              if (!event.target.checkValidity()) {
433                event.preventDefault();
434                jQuery(this).find('.ppsSubMsg').addClass('ppsErrorMsg').html('Please fill-in all fields');
435              }
436            },
437            false
438          );
439        }
440      }
441    }
442  }
443}
444/**
445 * Will check - was popup shown before and it's setting, and deside - should it be shown now or not
446 * @param {mixed} popup Popup object or it's ID
447 */
448function ppsCheckShowPopup(popup, params) {
449  if (isNumericPps(popup)) popup = ppsGetPopupById(popup);
450  var showKey = 'pps_show_' + popup.id,
451    prevShow = getCookiePps(showKey),
452    countTimes = popup.params.main.show_to == 'count_times',
453    timesShowedKey = 'pps_times_showed_' + popup.id,
454    timesShowed = parseInt(getCookiePps(timesShowedKey));
455  if (popup.params.main.show_to == 'first_time_visit' && prevShow) return;
456  if (countTimes && prevShow && prevShow != '1') {
457    var prevShowStamp = new Date(prevShow).getTime(),
458      currStamp = new Date().getTime();
459    if (prevShowStamp) {
460      var diff = (currStamp - prevShowStamp) / 1000, // Miliseconds to seconds
461        hour = 3600,
462        needShowTimes = parseInt(popup.params.main.count_times_num);
463      if (timesShowed && needShowTimes && timesShowed >= needShowTimes) {
464        if ((popup.params.main.count_times_mes == 'hour' && diff < hour) || (popup.params.main.count_times_mes == 'day' && diff < 24 * hour) || (popup.params.main.count_times_mes == 'week' && diff < 7 * 24 * hour) || (popup.params.main.count_times_mes == 'month' && diff < 30 * 24 * hour)) {
465          return;
466        }
467        if (timesShowed >= needShowTimes) {
468          timesShowed = 0;
469        }
470      }
471    }
472  }
473  if (!prevShow || countTimes) {
474    var saveCookieTime = parseInt(popup.params.main.show_to_first_time_visit_days);
475    saveCookieTime = isNaN(saveCookieTime) || countTimes ? 30 : saveCookieTime;
476    if (!saveCookieTime) saveCookieTime = null; // Save for current session only
477    var saveMark = countTimes ? new Date().toString() : '1';
478    setCookiePps('pps_show_' + popup.id, saveMark, saveCookieTime); // Save just flag only in cookie for now
479    if (countTimes) {
480      setCookiePps(timesShowedKey, timesShowed ? timesShowed + 1 : 1, 30);
481    }
482  }
483  var actionDone = _ppsPopupGetActionDone(popup);
484  if (popup.params.main.show_to == 'until_make_action' && actionDone) return;
485  if (_ppsCheckDisplayTime(popup)) return;
486  if (popup.params.main.show_to == 'until_email_confirm' && typeof ppsCheckEmailConfirmed === 'function' && ppsCheckEmailConfirmed(popup)) {
487    return;
488  }
489  params = params || {};
490  params.isUnique = prevShow ? 0 : 1;
491  ppsShowPopup(popup, params);
492  return false;
493}
494/**
495 * Check popup show time - "Time display settings" in admin area
496 * @param {mixed} popup Popup object or it's ID
497 */
498function _ppsCheckDisplayTime(popup) {
499  if (isNumericPps(popup)) popup = ppsGetPopupById(popup);
500  if (popup.params.main.enb_show_time && popup.params.main.show_time_from && popup.params.main.show_time_to && popup.params.main.show_time_from != popup.params.main.show_time_to) {
501    var timeToNum = function (timeStr) {
502      var add = strpos(timeStr, 'pm') !== false ? 12 : 0;
503      var time = parseFloat(str_replace(str_replace(str_replace(timeStr, 'am', ''), 'pm', ''), ':', '.'));
504      if (toeInArray(time, [12, 12.3]) === -1) {
505        time += add;
506      } else if (!add) {
507        time -= 12;
508      }
509      return time;
510    };
511    var timeFrom = timeToNum(popup.params.main.show_time_from),
512      timeTo = timeToNum(popup.params.main.show_time_to),
513      currDate = new Date(),
514      currTime = currDate.getHours() + currDate.getMinutes() / 100;
515
516    if (currTime < timeFrom || currTime > timeTo) {
517      return true;
518    }
519  }
520  return false;
521}
522/**
523 * Check - was action done in this popup or not (any action will be checked)
524 * @param {mixed} popup Popup object or it's ID
525 */
526function _ppsPopupGetActionDone(popup) {
527  if (isNumericPps(popup)) popup = ppsGetPopupById(popup);
528  var actionsKey = 'pps_actions_' + popup.id,
529    actions = getCookiePps(actionsKey);
530  if (actions) {
531    if (popup.type == 'age_verify' && actions.age_verify && popup.params.opts_attrs.btns_number) {
532      // Count action done for Age Berify types only if primary was clicked
533      // if there are button, marked as primary in admin are.
534      // If there are no such - it will be counted as Done for any button
535      var primaryBtnExists = false;
536      for (var i = 0; i < popup.params.opts_attrs.btns_number; i++) {
537        if (popup.params.tpl['is_btn_primary_' + i]) {
538          if (i == actions.age_verify) {
539            return true;
540          }
541          primaryBtnExists = true;
542        }
543      }
544      // Do not break anything in current users workflow
545      if (primaryBtnExists) return false;
546    }
547    // TODO: make priority check here - if subscribe enabled and user just shared popup - return false
548    return true;
549  }
550  return false;
551}
552/**
553 * Set done action in popup
554 * @param {mixed} popup Popup object or it's ID
555 * @param {type} action Action that was done
556 */
557function _ppsPopupSetActionDone(popup, action, smType, params) {
558  params = params || {};
559  if (isNumericPps(popup)) popup = ppsGetPopupById(popup);
560  smType = smType !== null ? smType : '';
561  var actionsKey = 'pps_actions_' + popup.id,
562    actions = getCookiePps(actionsKey);
563  if (!actions) actions = {};
564  // Save btn ID for age verify popups
565  if (action == 'age_verify') {
566    actions[action] = smType;
567  } else actions[action] = 1; // Save only flags for now
568  var saveCookieTime = parseInt(popup.params.main.show_to_until_make_action_days);
569  saveCookieTime = isNaN(saveCookieTime) ? 30 : saveCookieTime;
570  if (!saveCookieTime) saveCookieTime = null; // Save for current session only
571  setCookiePps(actionsKey, actions, saveCookieTime);
572  if (!params.ignoreSendStat) {
573    _ppsPopupAddStat(popup, action, smType);
574  }
575  jQuery(document).trigger('ppsAfterPopupsActionDone', { popup: popup, action: action, smType: smType });
576}
577function _ppsPopupAddStat(popup, action, smType, isUnique) {
578  if (popup && popup.params && popup.params.tpl.dsbl_stats)
579    // Stats is disabled
580    return;
581  jQuery.sendFormPps({
582    msgElID: 'noMessages',
583    data: { mod: 'statistics', action: 'add', id: popup.id, type: action, sm_type: smType, is_unique: isUnique, connect_hash: popup.connect_hash },
584  });
585  jQuery(document).trigger('ppsAfterPopupsStatAdded', { popup: popup, action: action, smType: smType, is_unique: isUnique });
586}
587function ppsShowPopUpOnClick(popup, element) {
588  if (isNumericPps(popup)) popup = ppsGetPopupById(popup);
589  _ppsSaveClickHref(popup, jQuery(element));
590  ppsShowPopup(popup);
591}
592function __ppsDisplayShell(params) {
593  params.shell.show();
594  _ppsTriggerIframeScrollByHash(params);
595  setTimeout(function () {
596    if (navigator.userAgent.indexOf('Safari') > -1 && navigator.userAgent.indexOf('Chrome') == -1 && params.shell.find('.ppsMainFrame').length) {
597      params.shell.css({
598        'overflow-y': 'auto',
599        '-webkit-overflow-scrolling': 'touch',
600        border: params.shell.find('.ppsMainFrame').css('border'),
601        'border-radius': params.shell.find('.ppsMainFrame').css('border-radius'),
602      });
603      params.shell.find('.ppsMainFrame').css({
604        width: params.shell.width() + 'px',
605        'max-width': params.shell.width() + 'px',
606        height: params.shell.height(),
607        border: 'none',
608        'border-radius': '0',
609      });
610      _ppsCloseBtnPositionSafari(params);
611    }
612  }, 10);
613  // For FB PopUp only
614  if (params.shell.find('.fb-page iframe:first').length > 0) {
615    setTimeout(function () {
616      _ppsPositionPopup(params);
617    }, 500);
618  }
619}
620function __ppsHideShell(params) {
621  params.shell.hide();
622}
623function _ppsTriggerIframeScrollByHash(params) {
624  var iframe = params.shell.find('.ppsMainFrame');
625
626  if (iframe.length) {
627    iframe.each(function () {
628      var frame = jQuery(this),
629        frameSrc = frame.attr('src'),
630        hashArr = frameSrc.split('#');
631      if (hashArr.length && hashArr[1]) {
632        setTimeout(function () {
633          iframe.get(0).contentWindow.location.href = frameSrc;
634        }, 200);
635      }
636    });
637  }
638}
639function _ppsCloseBtnListenersSafari(params) {
640  params.shell = ppsGetPopupShell(params.popup);
641  if (navigator.userAgent.indexOf('Safari') > -1 && navigator.userAgent.indexOf('Chrome') == -1 && params.shell.find('.ppsMainFrame').length) {
642    jQuery(window).on('resize', function () {
643      _ppsCloseBtnPositionSafari(params);
644    });
645    jQuery(window).on('orientationchange', function () {
646      _ppsCloseBtnPositionSafari(params);
647    });
648    jQuery('#ppsPopupBgOverlay').click(function () {
649      if (ppsPopups && ppsPopups.length) {
650        for (var i = 0; i < ppsPopups.length; i++) {
651          if (ppsPopups[i] && ppsPopups[i].params && ppsPopups[i].params.main && ppsPopups[i].params.main.close_on && ppsPopups[i].params.main.close_on == 'user_close' && ppsPopups[i].view_id == popup.view_id) {
652            ppsClosePopup(ppsPopups[i]);
653          }
654        }
655      }
656    });
657  }
658}
659function _ppsCloseBtnPositionSafari(params) {
660  var $shell = jQuery('#ppsPopupShell_' + params.popup.view_id);
661  $shell.find('.ppsPopupClose').css({
662    position: 'fixed',
663    top: parseInt($shell.css('top') + 20) + 'px',
664    left: parseInt($shell.css('left')) + $shell.width() - $shell.find('.ppsPopupClose').width() - 10 + 'px',
665  });
666}
667/**
668 * Show popup
669 * @param {mixed} popup Popup object or it's ID
670 * @param {objext} params Additional parameters to display
671 */
672//var owlAllreadyInit = false;
673function ppsShowPopup(popup, params) {
674  if (isNumericPps(popup)) popup = ppsGetPopupById(popup);
675
676  if (popup && popup.params.main.hide_other) {
677    jQuery('.ppsPopupShell').hide();
678    jQuery('.ppsPopupBgOverlay').hide();
679  }
680
681  if (popup && popup.params.main.groups && popup.params.main.groups.length > 0) {
682    //Show group overlay
683    jQuery('#ppsPopupShell_' + popup.view_id)
684      .closest('.ppsGroupOverlay')
685      .show();
686    //Show all popup from one group
687    jQuery('.ppsGroupWrappers')
688      .find('.ppsPopupShell')
689      .each(function (index) {
690        jQuery(this).css({ display: 'none', position: 'relative', left: 'inherit', right: 'inherit', top: 'inherit', bottom: 'inherit' });
691      });
692    setTimeout(function () {
693      jQuery('.ppsGroupWrappers')
694        .find('.ppsPopupShell')
695        .each(function (index) {
696          jQuery(this).css({ display: 'block', position: 'relative', left: 'inherit', right: 'inherit', top: 'inherit', bottom: 'inherit' });
697        });
698    }, 100);
699    jQuery('.ppsGroupWrappers').trigger(
700      'to.owl.carousel',
701      jQuery('#ppsPopupShell_' + popup.view_id)
702        .parent()
703        .index()
704    );
705  }
706
707  if (!ppsCorrectJqueryUsed()) {
708    ppsReloadCoreJs(ppsShowPopup, [popup, params]);
709    return;
710  }
711  params = params || {};
712  if (isNumericPps(popup)) popup = ppsGetPopupById(popup);
713  var $shell = ppsGetPopupShell(popup);
714  if (!popup._imgsLoaded) {
715    $shell.bind('ppsShowPopupAfterAllImgs', function () {
716      ppsShowPopup(popup, params);
717    });
718    return;
719  }
720  $shell.data('view-id', popup.view_id);
721  if (_ppsCheckIsPageCached()) {
722    _ppsUpdatePopupNonces(popup);
723  }
724  _ppsPopupAddStat(popup, 'show', 0, params.isUnique); // Save show popup statistics
725  if (!params.ignoreBgOverlay) {
726    ppsShowBgOverlay(popup);
727  }
728  if (g_ppsWindowLoaded && !params.ignorePosition) {
729    _ppsPositionPopup({ shell: $shell, popup: popup });
730  }
731  if (popup.params.tpl.anim && !popup.resized_for_wnd) {
732    _ppsHandlePopupAnimationShow(popup, $shell);
733  } else {
734    __ppsDisplayShell({ shell: $shell, popup: popup });
735  }
736  // For iFrames - we need to reset it's width - to make sure that it fit correct
737  if (toeInArrayPps(popup.type, ['iframe'])) {
738    var $frame = $shell.find('.ppsMainFrame');
739    if ($frame && $frame.length) {
740      $frame.css('width', 'auto');
741      $frame.css('width', '100%');
742    }
743  }
744  _ppsCheckPlayVideo({ popup: popup, shell: $shell });
745  _ppsIframesForReload({ popup: popup, shell: $shell });
746  _ppsCheckInnerScripts({ popup: popup, shell: $shell });
747  // timeout is to make sure that fronted.gmap.js loaded for this time - because exactly there we have defined maps data
748  setTimeout(function () {
749    _ppsCheckMap({ popup: popup, shell: $shell });
750    _ppsSocialIcons({ popup: popup, shell: $shell });
751    _ppsCheckContactForm({ popup: popup, shell: $shell });
752    _ppsCheckVideos({ popup: popup, shell: $shell });
753  }, 100);
754  // we not use timeout because we need to hide publication reinit
755  _ppsCheckPublication({ popup: popup, shell: $shell });
756  // Check disable wnd scrolling
757  if (popup.params.tpl.dsbl_wnd_scroll) {
758    disableScrollPps('html');
759    disableScrollPps('body');
760  }
761  popup.is_visible = true;
762  popup.is_rendered = true; // Rendered at least one time
763  jQuery(document).trigger('ppsAfterPopupsActionShow', popup);
764  runShowClb(popup, $shell); // Run all additional added show callback functions if such was added
765
766  if (toeInArrayPps(popup.type, ['iframe'])) {
767    if (popup.params.tpl.iframe_display_only && popup.params.tpl.iframe_display_only != '' && typeof _ppsIFrameDisplayOnly == 'function' && !popup.params.tpl._iframeDisplayOnlyBinded) {
768      _ppsIFrameDisplayOnly(popup);
769    }
770  }
771  if (popup.type == 'video') {
772    var $iframe = $shell.find('iframe:first');
773    $iframe.attr('style', '');
774  }
775}
776function _ppsCheckVideos(params) {
777  if (params.popup.type == 'video' && params.popup.params.tpl.video_type == 'youtube' && params.popup.params.tpl.video_autoplay) {
778    // I know about youtube API, but it just didn't worked:
779    // player.playVideo() was undefined all time
780    var $iframe = params.shell.find('iframe:first');
781    $iframe.attr('src', $iframe.attr('src') + '&autoplay=1');
782  }
783}
784function _ppsHandlePopupAnimationShow(popup, $shell) {
785  var preAnimClass = popup.params.tpl.anim.old ? 'magictime' : 'animated';
786  $shell.animationDuration(popup.params.tpl.anim_duration, true);
787  var hideClass = popup.params.tpl.anim_close ? popup.params.tpl.anim_close.hide_class : popup.params.tpl.anim.hide_class;
788  $shell.removeClass(hideClass);
789  $shell.addClass(preAnimClass + ' ' + popup.params.tpl.anim.show_class);
790  __ppsDisplayShell({ shell: $shell, popup: popup });
791  // This need to make properly work responsivness
792  setTimeout(function () {
793    $shell.removeClass(preAnimClass + ' ' + popup.params.tpl.anim.show_class);
794  }, parseInt(popup.params.tpl.anim_duration));
795}
796function _ppsHandlePopupAnimationHide(popup, $shell) {
797  var preAnimClass = popup.params.tpl.anim.old ? 'magictime' : 'animated';
798  var hideClass = popup.params.tpl.anim_close ? popup.params.tpl.anim_close.hide_class : popup.params.tpl.anim.hide_class;
799  var cloaseAnimDuration = popup.params.tpl.anim_close_duration;
800  if (cloaseAnimDuration && cloaseAnimDuration > 0) {
801    $shell.animationDuration(cloaseAnimDuration, true);
802  } else {
803    cloaseAnimDuration = popup.params.tpl.anim_duration;
804  }
805  $shell.removeClass(popup.params.tpl.anim.show_class).addClass(hideClass);
806  setTimeout(function () {
807    $shell.removeClass(preAnimClass);
808    __ppsHideShell({ shell: $shell, popup: popup });
809    ppsHideBgOverlay(popup);
810  }, cloaseAnimDuration);
811}
812function _ppsIframesForReload(params) {
813  var popup = params.popup,
814    shell = params.shell ? params.shell : ppsGetPopupShell(popup);
815  if (shell.find('iframe')) {
816    shell.find('iframe').each(function () {
817      var src = jQuery(this).attr('src');
818      if (src) {
819        if (src.indexOf('www.google.com/maps/embed') !== -1) {
820          this.src = this.src; // Reoad iframe
821        }
822      }
823    });
824  }
825}
826/**
827 * Is this iframe with video for example
828 * @param {object} params object with PopUp and PopUp shell (not mandatory): {popup: popup, shell: shell}
829 * @returns {bool} true if PopIp contains any video, else - false
830 */
831function _ppsIsIframeForHide(params) {
832  params = params || {};
833  if (params.popup.type == 'video') return true; // First check is really simple, isn't it?:)
834  var $shell = params.shell ? params.shell : ppsGetPopupShell(params.popup),
835    $iFrames = $shell ? $shell.find('iframe') : false,
836    videoFound = false;
837  if ($iFrames && $iFrames.length) {
838    var videoSources = ['youtube', 'vimeo', 'dtbaker'];
839    $iFrames.each(function () {
840      var originalSrc = jQuery(this).data('original-src'),
841        src = jQuery(this).attr('src');
842      if (src || originalSrc) {
843        for (var i = 0; i < videoSources.length; i++) {
844          if ((src && src.indexOf(videoSources[i]) !== -1) || (originalSrc && originalSrc.indexOf(videoSources[i]) !== -1)) {
845            videoFound = true;
846            return false;
847          }
848        }
849      }
850    });
851  }
852  return videoFound;
853}
854function _ppsCheckBindVideo(params) {
855  params = params || {};
856  if (_ppsIsIframeForHide(params)) {
857    var $shell = params.shell ? params.shell : ppsGetPopupShell(params.popup),
858      $iFrames = $shell ? $shell.find('iframe,video') : false;
859    if ($iFrames && $iFrames.length) {
860      $iFrames.each(function () {
861        jQuery(this).data('original-src', jQuery(this).attr('src'));
862        jQuery(this).attr('src', '');
863      });
864    }
865  }
866}
867function _ppsCheckPlayVideo(params) {
868  params = params || {};
869  if (_ppsIsIframeForHide(params)) {
870    var $shell = params.shell ? params.shell : ppsGetPopupShell(params.popup),
871      $iFrames = $shell ? $shell.find('iframe,video') : false;
872    if ($iFrames && $iFrames.length) {
873      $iFrames.each(function () {
874        var originalSrc = jQuery(this).data('original-src'),
875          src = jQuery(this).attr('src');
876        if (originalSrc && originalSrc != '' && (!src || src == '')) {
877          jQuery(this).attr('src', originalSrc);
878        }
879      });
880    }
881  }
882}
883function _ppsCheckStopVideo(params) {
884  params = params || {};
885  if (_ppsIsIframeForHide(params)) {
886    var $shell = params.shell ? params.shell : ppsGetPopupShell(params.popup),
887      $iFrames = $shell ? $shell.find('iframe,video') : false;
888    if (params.popup.params.tpl.video_extra_full_screen) {
889      return;
890    }
891    if ($iFrames && $iFrames.length) {
892      $iFrames.each(function () {
893        jQuery(this).attr('src', '');
894      });
895    }
896  }
897}
898function _ppsCheckInnerScripts(params) {
899  params = params || {};
900  var $shell = params.shell ? params.shell : ppsGetPopupShell(params.popup);
901  // Check scripts in description, and execute them if they are there
902  var $scripts = $shell.find('script');
903  if ($scripts && $scripts.length) {
904    $scripts.each(function () {
905      var scriptSrc = jQuery(this).attr('src');
906      if (scriptSrc && scriptSrc != '') {
907        jQuery.getScript(scriptSrc);
908      }
909    });
910  }
911}
912function _ppsCheckMap(params) {
913  params = params || {};
914  var shell = params.shell ? params.shell : ppsGetPopupShell(params.popup),
915    maps = shell.find('.gmp_map_opts');
916  if (maps && maps.length) {
917    // For case we need to wait until gmap scripts will be loaded
918    if (typeof gmpGetMapByViewId === 'undefined') {
919      setTimeout(function () {
920        _ppsCheckMap(params);
921      }, 1000);
922      return;
923    }
924    maps.each(function () {
925      var viewId = jQuery(this).data('view-id'),
926        map = gmpGetMapByViewId(viewId);
927      if (map) {
928        // If map is already there - just refresh it after popup was shown
929        map.fullRefresh ? map.fullRefresh() : map.refresh(); // For compatibilty with old methids, where there are no fullRefresh() method
930      } else {
931        // If there are no map - but it should be there - just create it
932        var mapData = gmpGetMapInfoByViewId(viewId);
933        gmpInitMapOnPage(mapData);
934      }
935    });
936  }
937}
938function _ppsCheckContactForm(params) {
939  params = params || {};
940  var $shell = params.shell ? params.shell : ppsGetPopupShell(params.popup),
941    $forms = $shell.find('.cfsFormShell');
942  if ($forms && $forms.length) {
943    // For case we need to wait until gmap scripts will be loaded
944    if (typeof g_cfsForms === 'undefined') {
945      setTimeout(function () {
946        _ppsCheckContactForm(params);
947      }, 1000);
948      return;
949    }
950    if (typeof cfsCheckInitForms !== 'undefined') {
951      cfsCheckInitForms($shell);
952    }
953    $forms.each(function () {
954      var viewHtmlId = jQuery(this).attr('id'),
955        form = g_cfsForms.getByViewHtmlId(viewHtmlId);
956      if (form) {
957        form.refresh();
958      } else {
959        // If there are no form - but it should be there - just create it
960        g_cfsForms.add(g_cfsForms.getFormDataByViewHtmlId(viewHtmlId));
961      }
962    });
963  }
964}
965/**
966 * Check social icons from Social Share Buttons by Supsystic plugin
967 * @param {object} params contain popup and popup shell html objects
968 */
969function _ppsSocialIcons(params) {
970  params = params || {};
971  var shell = params.shell ? params.shell : ppsGetPopupShell(params.popup),
972    icons = shell.find('.supsystic-social-sharing:not(.supsystic-social-sharing-loaded)');
973  if (icons && icons.length && typeof window.initSupsysticSocialSharing !== 'undefined') {
974    icons.each(function () {
975      window.initSupsysticSocialSharing(this);
976    });
977  }
978}
979function _ppsCheckPublication(params) {
980  params = params || {};
981  var shell = params.shell ? params.shell : ppsGetPopupShell(params.popup),
982    publications = shell.find('.dpsBookStageShell');
983
984  if (publications && publications.length) {
985    publications.each(function () {
986      if (typeof dpsBookMng == 'undefined') {
987        dpsBookMng = new dpsBookManager();
988      }
989      var id = jQuery(this).find('.dpsBook').data('bookid'),
990        publication = dpsBookMng.getById(id);
991      if (publication) {
992        // If publication is already there - just reinit it after popup was shown
993        publication.getHtml().turn('destroy');
994        publication.getStage().parent().html(publication._baseHtml);
995        publication._init(true);
996      } else {
997        dpsInitBookOnPage(dpsBookInfoByTermId(id));
998        dpsBindBookActions(id);
999      }
1000    });
1001  }
1002}
1003function _ppsPositionPopup(params) {
1004  params = params || {};
1005  params.popup = params.popup && typeof params.popup !== 'object' ? ppsGetPopupById(params.popup) : params.popup;
1006  if (params.popup.params.main.groups) return;
1007  var $shell = params.shell ? params.shell : ppsGetPopupShell(params.popup);
1008  if ($shell) {
1009    var wndWidthOffset = 10, // at least 10px;
1010      wndHeightOffset = 10, // at least 10px;
1011      leftOffset,
1012      btnClose;
1013
1014    btnClose = $shell.find('.ppsPopupClose');
1015    if (btnClose.css('position') == 'absolute') {
1016      wndWidthOffset = +wndWidthOffset - parseFloat(btnClose.css('right'));
1017    }
1018    leftOffset = wndWidthOffset / 2;
1019    var wndWidth = params.wndWidth ? params.wndWidth : jQuery(window).width(),
1020      wndHeight = params.wndHeight ? params.wndHeight : jQuery(window).height(),
1021      shellWidth = $shell.outerWidth(true),
1022      shellHeight = $shell.outerHeight(),
1023      resized = false,
1024      resizedW = false,
1025      resizedH = false,
1026      compareWidth = wndWidth - wndWidthOffset,
1027      compareHeight = wndHeight - wndHeightOffset,
1028      resizeDivision = 1,
1029      responsiveInside = $shell.hasClass('ppsResponsiveInside'),
1030      isResponsedByWidthOnly = false;
1031
1032    if (shellHeight >= compareHeight && !responsiveInside && !(params.popup && params.popup._notResizeHeight)) {
1033      var initialHeight = params.recalc ? false : parseInt($shell.data('init-height'));
1034      if (!initialHeight) {
1035        initialHeight = shellHeight;
1036        $shell.data('init-height', initialHeight);
1037      }
1038      resizeDivision = compareHeight / initialHeight;
1039      resized = resizedH = true;
1040    }
1041    if (shellWidth >= compareWidth && !responsiveInside) {
1042      var initialWidth = params.recalc ? false : parseInt($shell.data('init-width'));
1043      if (!initialWidth) {
1044        initialWidth = shellWidth;
1045        $shell.data('init-width', initialWidth);
1046      }
1047      var widthDivision = compareWidth / initialWidth;
1048      if (widthDivision < resizeDivision) {
1049        resizeDivision = widthDivision;
1050      }
1051      resized = resizedW = true;
1052    }
1053    if (resized) {
1054      if (params.popup.params.tpl.responsive_mode == 'width_only') {
1055        if (resizedW) {
1056          var totalPadding = shellWidth - $shell.width(); // outer width - just width == paddings
1057          isResponsedByWidthOnly = shellWidth >= wndWidth;
1058          $shell.css({
1059            width: 'calc(100% - ' + (totalPadding + 20) + 'px)',
1060          });
1061        } else {
1062          var initialWidth = parseInt($shell.data('init-width'));
1063          if (initialWidth && initialWidth < compareWidth) {
1064            $shell.css({
1065              width: initialWidth,
1066            });
1067          }
1068        }
1069        if (resizedH) {
1070          $shell.css({
1071            position: 'absolute',
1072          });
1073        } else {
1074          $shell.css({
1075            position: 'fixed',
1076          });
1077        }
1078      } else {
1079        var zoomOrigin = { left: 'center', top: 'center' };
1080        $shell.ppsZoom(resizeDivision, zoomOrigin.left + ' ' + zoomOrigin.top);
1081      }
1082      $shell.data('resized', 1);
1083      shellWidth = $shell.outerWidth();
1084      shellHeight = $shell.outerHeight();
1085    } else if ($shell.data('resized')) {
1086      if (params.popup.params.tpl.responsive_mode == 'width_only') {
1087        var initialWidth = parseInt($shell.data('init-width'));
1088        if (initialWidth && initialWidth < compareWidth) {
1089          $shell.css({
1090            width: initialWidth,
1091          });
1092        }
1093        $shell.css({
1094          position: 'fixed',
1095        });
1096      }
1097    }
1098    if (params.popup.params.tpl.responsive_mode != 'width_only') {
1099      $shell.attr('data-responsive', 'true');
1100    } else {
1101      $shell.removeAttr('data-responsive');
1102    }
1103    params.popup.resized_for_wnd = resized;
1104    jQuery(document).trigger('ppsResize', { popup: params.popup, shell: $shell, wndWidth: wndWidth, wndHeight: wndHeight, isResponsedByWidthOnly: isResponsedByWidthOnly });
1105    if (!$shell.positioned_outside) {
1106      // Make available - re-position popup from outside modules
1107      var left = (wndWidth - shellWidth) / 2,
1108        top = (wndHeight - shellHeight) / 2;
1109      left = left < 0 ? 0 : left;
1110      top = top < 0 ? 0 : top;
1111      if (resizedW) {
1112        left -= (initialWidth - initialWidth * widthDivision) / 2 - leftOffset;
1113      }
1114      if (resizedH && params.popup.params.tpl.responsive_mode != 'width_only') {
1115        top -= (initialHeight - initialHeight * resizeDivision) / 2;
1116      }
1117      $shell[0].removeAttribute('left');
1118      $shell[0].removeAttribute('top');
1119      $shell[0].style.setProperty('left', left + 'px', 'important');
1120      $shell[0].style.setProperty('top', top + 'px', 'important');
1121      $shell[0].style.setProperty('bottom', 'inherit', 'important');
1122      $shell[0].style.setProperty('right', 'inherit', 'important');
1123      // $shell.css({
1124      //     'left': left,
1125      // 	'top': top
1126      // });
1127      if (isResponsedByWidthOnly) {
1128        $shell.css({
1129          transform: 'translate(-50%, 0)',
1130          left: '0',
1131        });
1132        setTimeout(function () {
1133          $shell.css({
1134            left: '50%',
1135          });
1136        }, params.popup.params.tpl.anim_duration - 20);
1137      }
1138    }
1139  } else {
1140    console.log('CAN NOT FIND POPUP SHELL TO RESIZE!');
1141  }
1142}
1143function ppsClosePopup(popup) {
1144  if (isNumericPps(popup)) popup = ppsGetPopupById(popup);
1145  var $shell = ppsGetPopupShell(popup);
1146  if (popup.params.tpl.anim) {
1147    _ppsHandlePopupAnimationHide(popup, $shell);
1148  } else {
1149    __ppsHideShell({ shell: $shell, popup: popup });
1150    ppsHideBgOverlay(popup);
1151  }
1152  _ppsCheckStopVideo({ shell: $shell, popup: popup });
1153  // Check disable wnd scrolling
1154  if (popup.params.tpl.dsbl_wnd_scroll) {
1155    enableScrollPps('html');
1156    enableScrollPps('body');
1157  }
1158  // Check redirect after close option
1159  if (parseInt(popup.params.tpl.close_redirect_to_btn_url) && popup.params.close_redirect_to_btn_url_href) {
1160    toeRedirect(popup.params.close_redirect_to_btn_url_href, parseInt(popup.params.tpl.reidrect_on_close_new_wnd));
1161  } else if (popup.params.tpl.reidrect_on_close && popup.params.tpl.reidrect_on_close != '') {
1162    toeRedirect(popup.params.tpl.reidrect_on_close, parseInt(popup.params.tpl.reidrect_on_close_new_wnd));
1163  }
1164  _ppsPopupAddStat(popup, 'close'); // Save close popup statistics
1165  popup.is_visible = false;
1166}
1167function ppsGetPopupShell(popup) {
1168  if (isNumericPps(popup)) popup = ppsGetPopupById(popup);
1169  return jQuery('#ppsPopupShell_' + popup.view_id);
1170}
1171function ppsGetPopupById(id) {
1172  for (var i = 0; i < ppsPopups.length; i++) {
1173    if (ppsPopups[i].id == id) return ppsPopups[i];
1174  }
1175  return false;
1176}
1177function ppsGetPopupByViewId(viewId) {
1178  for (var i = 0; i < ppsPopups.length; i++) {
1179    if (ppsPopups[i].view_id == viewId) return ppsPopups[i];
1180  }
1181  return false;
1182}
1183function ppsInitBgOverlay() {
1184  jQuery('body').append('<div id="ppsPopupBgOverlay" />');
1185  jQuery('#ppsPopupBgOverlay').click(function () {
1186    if (ppsPopups && ppsPopups.length) {
1187      for (var i = 0; i < ppsPopups.length; i++) {
1188        if (ppsPopups[i] && ppsPopups[i].params && ppsPopups[i].params.main && ppsPopups[i].params.main.close_on && ppsPopups[i].params.main.close_on == 'overlay_click') {
1189          ppsClosePopup(ppsPopups[i]);
1190        }
1191      }
1192    }
1193  });
1194}
1195function ppsShowBgOverlay(popup) {
1196  if (popup.params.main.groups) return;
1197  if (popup && isNumericPps(popup)) popup = ppsGetPopupById(popup);
1198  // if (popup.ignore_background) /* For some types - we will not be require background - so we can manipulate it using this key */ return;
1199  var $overlay = jQuery('#ppsPopupBgOverlay');
1200  /* Clear all prev. sets - because there can be several numbers of PopUps, but overlay - is one for all */
1201  $overlay
1202    .css({
1203      'background-position': '',
1204      'background-repeat': '',
1205      'background-attachment': '',
1206      '-webkit-background-size': '',
1207      '-moz-background-size': '',
1208      '-o-background-size': '',
1209      'background-size': '',
1210      'background-color': '',
1211      'background-url': '',
1212    })
1213    .removeClass('ppsSnow');
1214  if (popup && popup.params) {
1215    /* Opacity check */
1216    if (typeof popup.params.tpl.bg_overlay_opacity !== 'undefined') {
1217      if (!popup.params.tpl.bg_overlay_opacity || popup.params.tpl.bg_overlay_opacity == '') popup.params.tpl.bg_overlay_opacity = 0;
1218      var opacity = parseFloat(popup.params.tpl.bg_overlay_opacity);
1219      if (!isNaN(opacity)) {
1220        $overlay.css({
1221          opacity: opacity,
1222        });
1223      }
1224    }
1225    if (typeof popup.params.tpl.bg_overlay_type !== 'undefined') {
1226      switch (popup.params.tpl.bg_overlay_type) {
1227        case 'color':
1228          $overlay.css({
1229            'background-color': popup.params.tpl.bg_overlay_color,
1230          });
1231          break;
1232        case 'img':
1233          if (popup.params.tpl.bg_overlay_img) {
1234            switch (popup.params.tpl.bg_overlay_img_pos) {
1235              case 'stretch':
1236                $overlay.css({
1237                  'background-position': 'center center',
1238                  'background-repeat': 'no-repeat',
1239                  'background-attachment': 'fixed',
1240                  '-webkit-background-size': 'cover',
1241                  '-moz-background-size': 'cover',
1242                  '-o-background-size': 'cover',
1243                  'background-size': 'cover',
1244                });
1245                break;
1246              case 'center':
1247                $overlay.css({
1248                  'background-position': 'center center',
1249                  'background-repeat': 'no-repeat',
1250                  'background-attachment': 'scroll',
1251                  '-webkit-background-size': 'auto',
1252                  '-moz-background-size': 'auto',
1253                  '-o-background-size': 'auto',
1254                  'background-size': 'auto',
1255                });
1256                break;
1257              case 'tile':
1258                $overlay.css({
1259                  'background-position': 'left top',
1260                  'background-repeat': 'repeat',
1261                  'background-attachment': 'scroll',
1262                  '-webkit-background-size': 'auto',
1263                  '-moz-background-size': 'auto',
1264                  '-o-background-size': 'auto',
1265                  'background-size': 'auto',
1266                });
1267                break;
1268            }
1269            $overlay.css({
1270              'background-image': 'url("' + popup.params.tpl.bg_overlay_img + '")',
1271            });
1272          }
1273          break;
1274        case 'snow': // Just snow effect for overlay
1275          $overlay.addClass('ppsSnow');
1276          break;
1277      }
1278    }
1279  }
1280  $overlay.show();
1281}
1282function ppsHideBgOverlay(popup) {
1283  if (popup && isNumericPps(popup)) popup = ppsGetPopupById(popup);
1284  // if (popup.ignore_background)
1285  //   // For some types - we will not be require background - so we can manipulate it using this key
1286  //   return;
1287  jQuery('#ppsPopupBgOverlay').hide();
1288}
1289function ppsBindPopupActions(popup) {
1290  var $shell = ppsGetPopupShell(popup);
1291  // TODO: make usage of ppsPopupSubscribeSuccess() function only after success subscribe process, not after subscribe action
1292  if ($shell.find('.ppsSubscribeForm_aweber').length) {
1293    $shell.find('.ppsSubscribeForm_aweber').submit(function () {
1294      if (jQuery(this).find('input[name=email]').val()) {
1295        ppsPopupSubscribeSuccess(popup);
1296      }
1297    });
1298  }
1299  // Check build-in PopUp subscribe links
1300  if ($shell.find('.ppsSmLink').length) {
1301    $shell.find('.ppsSmLink').click(function () {
1302      _ppsPopupSetActionDone(popup, 'share', jQuery(this).data('type'));
1303    });
1304  }
1305  // Check Social Share by Supsystic plugin links in PopUp
1306  if ($shell.find('.supsystic-social-sharing').length) {
1307    $shell.find('.supsystic-social-sharing a').click(function () {
1308      var socHost = this.hostname,
1309        socType = ''; // Social network type key
1310      if (socHost && socHost != '') {
1311        switch (socHost) {
1312          case 'www.facebook.com':
1313            socType = 'facebook';
1314            break;
1315          case 'plus.google.com':
1316            socType = 'googleplus';
1317            break;
1318          case 'twitter.com':
1319            socType = 'twitter';
1320            break;
1321          default:
1322            socType = socHost;
1323            break;
1324        }
1325        _ppsPopupSetActionDone(popup, 'share', socType);
1326      }
1327    });
1328  }
1329  if ($shell.find('.fb_iframe_widget').length) {
1330    _ppsBindFbLikeBtnAction(popup);
1331  }
1332  /*For age verification templates*/
1333  if (popup.type == 'age_verify') {
1334    var $verifyBtns = $shell.find('.ppsBtn');
1335    if ($verifyBtns && $verifyBtns.length) {
1336      $verifyBtns.click(function () {
1337        var btnClasses = jQuery(this).attr('class').split(' '),
1338          btnId = 0;
1339        if (btnClasses && btnClasses.length) {
1340          for (var i = 0; i < btnClasses.length; i++) {
1341            if (btnClasses[i].indexOf('ppsBtn_') === 0) {
1342              btnId = parseInt(btnClasses[i].split('_')[1]);
1343              break;
1344            }
1345          }
1346        }
1347        _ppsPopupSetActionDone(popup, 'age_verify', btnId);
1348      });
1349    }
1350  }
1351}
1352function _ppsBindFbLikeBtnAction(popup) {
1353  if (typeof FB === 'undefined') {
1354    // recurse until FB core will not be loaded
1355    setTimeout(function () {
1356      _ppsBindFbLikeBtnAction(popup);
1357    }, 500);
1358    return;
1359  }
1360  FB.Event.subscribe('edge.create', function (response) {
1361    _ppsPopupSetActionDone(popup, 'fb_like');
1362  });
1363  FB.Event.subscribe('xfbml.render', function (response) {
1364    setTimeout(function () {
1365      // Just don't know what to say.....
1366      setTimeout(function () {
1367        _ppsPositionPopup({ popup: popup });
1368      }, 1000);
1369      if (popup.render_with_fb_load) {
1370        // If it need to be rendered
1371        ppsCheckShowPopup(popup);
1372        _ppsPositionPopup({ popup: popup });
1373      } else {
1374        // else - just re-position it
1375        _ppsPositionPopup({ popup: popup });
1376      }
1377    }, 1000);
1378  });
1379}
1380function ppsPopupSubscribeSuccess(popup, params) {
1381  if (popup && isNumericPps(popup)) popup = ppsGetPopupById(popup);
1382  _ppsPopupSetActionDone(popup, 'subscribe', false, params);
1383}
1384function _ppsPopupBindDelay(popup, delayKey, delayEnbKey) {
1385  if (popup && isNumericPps(popup)) popup = ppsGetPopupById(popup);
1386  var delay = popup.params.main[delayEnbKey] && parseInt(popup.params.main[delayEnbKey]) && parseInt(popup.params.main[delayKey]) ? parseInt(popup.params.main[delayKey]) * 1000 : 0;
1387  if (delay) {
1388    // Check if option to make delay independed on page reload is enabled
1389    if (delayKey == 'show_on_page_load_delay' && parseInt(popup.params.main.enb_page_load_global_delay)) {
1390      popup.start_time = new Date().getTime();
1391      _ppsPopupBindUnloadDelay(delayKey, popup);
1392      var spentTime = parseInt(getCookiePps('pps_un_' + delayKey + '_' + popup.id)); // Check prev. counted time, spent on site
1393      if (spentTime && spentTime > 0) {
1394        delay -= spentTime; // Include already spent time on site - in current delay
1395        if (delay < 0) delay = 0;
1396      }
1397    }
1398    setTimeout(function () {
1399      ppsCheckShowPopup(popup);
1400    }, delay);
1401    return true;
1402  }
1403  return false;
1404}
1405/**
1406 * helper function for _ppsPopupBindDelay() function
1407 * @param {string} delayKey from _ppsPopupBindDelay() func
1408 * @param {object} popup PopUp object
1409 * @returns {undefined}
1410 */
1411function _ppsPopupBindUnloadDelay(delayKey, popup) {
1412  jQuery(window).unload(function () {
1413    var spentTime = popup.is_rendered ? 0 : new Date().getTime() - popup.start_time;
1414    setCookiePps('pps_un_' + delayKey + '_' + popup.id, spentTime);
1415  });
1416}
1417/**
1418 * Check show PopUp right after page was loaded
1419 * @param {object} popup PopUp object
1420 */
1421function ppsBindPopupForceShow(popup) {
1422  if (popup.params.main.show_on != 'link_follow') {
1423    var hashParams = toeGetHashParams();
1424    if (hashParams && hashParams.length && toeInArray('ppsShowPopUp_' + popup.id, hashParams) !== -1) {
1425      ppsCheckShowPopup(popup);
1426    }
1427  }
1428}
1429/**
1430 * Check if page was cached by any cache plugin - by checking page comments.
1431 * Usually they add comments in body tag.
1432 */
1433function _ppsCheckIsPageCached() {
1434  if (g_ppsIsPageCachedChecked)
1435    // It was computed before - ignore one more compilation
1436    return g_ppsIsPageCached;
1437  jQuery('*:not(iframe,video,object)')
1438    .contents()
1439    .filter(function () {
1440      return this.nodeType == 8;
1441    })
1442    .each(function (i, e) {
1443      if (e.nodeValue && (e.nodeValue.indexOf('Performance optimized by W3 Total Cache') !== -1 || e.nodeValue.indexOf('Cached page generated by WP-Super-Cache') !== -1)) {
1444        g_ppsIsPageCached = true;
1445        return false;
1446      }
1447    });
1448  g_ppsIsPageCachedChecked = true;
1449  return g_ppsIsPageCached;
1450}
1451function _ppsUpdatePopupNonces(popup) {
1452  if (!popup._nonces_updated) {
1453    // Update them only one time per session for each PopUp
1454    var $shell = ppsGetPopupShell(popup),
1455      $forms = $shell.find('form'),
1456      getFor = [],
1457      tryGetFor = ['ppsSubscribeForm', 'ppsLoginForm', 'ppsRegForm'];
1458    if ($forms && $forms.length) {
1459      $forms.each(function () {
1460        for (var i = 0; i < tryGetFor.length; i++) {
1461          if (jQuery(this).hasClass(tryGetFor[i])) {
1462            getFor.push(tryGetFor[i]);
1463          }
1464        }
1465      });
1466    }
1467    if (getFor && getFor.length) {
1468      jQuery.sendFormPps({
1469        msgElID: 'noMessages',
1470        data: { mod: 'popup', action: 'updateNonce', id: popup.id, get_for: getFor },
1471        onSuccess: function (res) {
1472          if (!res.error && res.data.update_for) {
1473            var $shell = ppsGetPopupShell(popup);
1474            for (var className in res.data.update_for) {
1475              $shell
1476                .find('.' + className)
1477                .find('input[name="_wpnonce"]')
1478                .val(res.data.update_for[className]);
1479            }
1480          }
1481        },
1482      });
1483    }
1484    popup._nonces_updated = true;
1485  }
1486}
1487function _ppsBindClickHrefSaving() {
1488  for (var i = 0; i < ppsPopups.length; i++) {
1489    if (ppsPopups[i].params && ppsPopups[i].params.tpl && (parseInt(ppsPopups[i].params.tpl.sub_redirect_to_btn_url) || parseInt(ppsPopups[i].params.tpl.close_redirect_to_btn_url))) {
1490      var $btn = jQuery('[onclick*="ppsShowPopup(' + ppsPopups[i].id + ')"]');
1491      ppsPopups[i] = _ppsSaveClickHref(ppsPopups[i], $btn);
1492    }
1493  }
1494}
1495function _ppsSaveClickHref(popup, $element) {
1496  if (popup.params && popup.params.tpl && $element && $element.length) {
1497    var href = $element.attr('href');
1498    if (parseInt(popup.params.tpl.sub_redirect_to_btn_url)) {
1499      popup.params.sub_redirect_to_btn_url_href = href;
1500    }
1501    if (parseInt(popup.params.tpl.close_redirect_to_btn_url)) {
1502      popup.params.close_redirect_to_btn_url_href = href;
1503    }
1504  }
1505  return popup;
1506}
1507function ppsAddShowClb(id, clb) {
1508  if (!g_ppsShowCallbacks[id]) {
1509    g_ppsShowCallbacks[id] = [];
1510  }
1511  g_ppsShowCallbacks[id].push(clb);
1512}
1513function runShowClb(popup, shell) {
1514  if (popup && isNumericPps(popup)) popup = ppsGetPopupById(popup);
1515  if (g_ppsShowCallbacks[popup.id] && g_ppsShowCallbacks[popup.id].length) {
1516    for (var i = 0; i < g_ppsShowCallbacks[popup.id].length; i++) {
1517      if (typeof g_ppsShowCallbacks[popup.id][i] === 'function') {
1518        g_ppsShowCallbacks[popup.id][i](popup, shell);
1519      }
1520    }
1521  }
1522}
1523jQuery(document).bind('ppsAfterPopupsActionShow', function (e, popup) {
1524  var scaleSize = 1,
1525    responsiveMode = popup.params.tpl.responsive_mode;
1526  if (responsiveMode === 'def') {
1527    var defaultPopupWidth = 0;
1528    var defaultPopupHeight = 0;
1529
1530    window.addEventListener(
1531      'resize',
1532      function () {
1533        setTimeout(function () {
1534          var popupDiv = jQuery('body').find('div[id*="ppsPopupShell_' + popup['id'] + '"]');
1535          window.popupDiv = popupDiv;
1536          popupWidth = defaultPopupWidth;
1537          defaultPopupHeight = defaultPopupHeight;
1538          window.popupDiv[0].style.setProperty('transform', '', '');
1539          if (popup.params.tpl.anim_key == 'none') {
1540            changeScaleByWidth();
1541          }
1542        }, 1000);
1543      },
1544      false
1545    );
1546
1547    window.addEventListener(
1548      'orientationchange',
1549      function () {
1550        setTimeout(function () {
1551          var popupDiv = jQuery('body').find('div[id*="ppsPopupShell_' + popup['id'] + '"]');
1552          window.popupDiv = popupDiv;
1553          popupWidth = defaultPopupWidth;
1554          defaultPopupHeight = defaultPopupHeight;
1555          window.popupDiv[0].style.setProperty('transform', '', '');
1556          if (popup.params.tpl.anim_key == 'none') {
1557            changeScaleByWidth();
1558          }
1559        }, 1000);
1560      },
1561      false
1562    );
1563
1564    if (popup.params.tpl.anim_key == 'none') {
1565      changeScaleByWidth();
1566    }
1567
1568    jQuery(window).resize(function () {
1569      setTimeout(changeScaleByWidth(), 2000);
1570    });
1571
1572    var docHeight = jQuery(window).height();
1573
1574    var doOnceGetInitHeightWidth = true;
1575
1576    function changeScaleByWidth() {
1577      scaleSize = 1;
1578      var popupDiv = jQuery('body').find('div[id*="ppsPopupShell_' + popup['id'] + '"]'),
1579        docWidth = jQuery(document).width(),
1580        docHeight = jQuery(window).height(),
1581        popupWidth = popupDiv[0].getBoundingClientRect().width,
1582        popupHeight = popupDiv[0].getBoundingClientRect().height;
1583
1584      if (doOnceGetInitHeightWidth) {
1585        defaultPopupHeight = popupHeight;
1586        defaultPopupWidth = popupWidth;
1587        doOnceGetInitHeightWidth = false;
1588      }
1589
1590      while ((popupWidth > docWidth || popupHeight + 30 > docHeight) && scaleSize > 0) {
1591        scaleSize = scaleSize - 0.01;
1592        popupDiv[0].removeAttribute('transform');
1593        popupDiv[0].style.setProperty('transform', 'scale(' + scaleSize + ')', 'important');
1594        docWidth = jQuery(document).width();
1595        docHeight = jQuery(window).height();
1596        popupWidth = popupDiv[0].getBoundingClientRect().width;
1597        popupHeight = popupDiv[0].getBoundingClientRect().height;
1598      }
1599      setTimeout(function () {
1600        var resultHeight = jQuery('body')
1601          .find('div[id*="ppsPopupShell_' + popup['id'] + '"]')[0]
1602          .getBoundingClientRect().height;
1603        if (resultHeight > docHeight) {
1604          if (popup.params.tpl.anim_key == 'none') {
1605            changeScaleByWidth();
1606          }
1607        }
1608      }, 1000);
1609    }
1610  }
1611});

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.