PageSourceSearch

https://www.kagyumonlam.or.id/wp-content/plugins/popup-by-supsysti…/popup/js/frontend.popup.js?ver=1.10.28

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

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.