PageSourceSearch

https://cdn.contrastly.com/wp-content/plugins/wpfomify/assets/js/frontend.js?ver=2.1.1.2

js contrastly.com collected 2026-10-02 16:45:00 UTC 21,627 bytes, 613 lines download raw bytes

1;(function($) {
2
3    /**
4     * The main fomo interface.
5     *
6     * @since 1.0.0
7     * @class IBXFomo
8     */
9    IBXFomo = {
10		_isActive: false,
11        /**
12         * A flag to check whether the fomo is showing or not.
13         *
14         * @since 1.0.0
15         * @access private
16         */
17        _fomoBarActive: 0,
18
19        /**
20         * Initialize fomo interface.
21         *
22         * @since 1.0.0
23         * @access private
24         * @method _init
25         */
26        _init: function()
27        {
28			if ( ! this._isActive ) {
29				this._initFomoBar();
30				this._initNotifications();
31				this._bindEvents();
32				this._isActive = true;
33			}
34        },
35
36        /**
37         * Bind events.
38         *
39         * @since 1.0.0
40         * @access private
41         * @method _bindEvents
42         */
43        _bindEvents: function()
44        {
45            $('body').delegate( '.ibx-fomo .ibx-fomo-bar-close', 'click', function() {
46                IBXFomo._fomoBarActive = 0;
47                IBXFomo._hideFomoBar();
48            } );
49
50            $('body').delegate( '.ibx-notification-popup .ibx-notification-popup-close', 'click', function() {
51				var element = $(this).parents('.ibx-notification-popup');
52				$.cookie( 'ibx_wpfomo_notification_hidden', true, { path: '/' } );
53				IBXFomo._hideNotification(element);
54            } );
55        },
56
57        /**
58         * Initialize the fomo bar and countdown.
59         *
60         * @since 1.0.0
61         * @access private
62         * @method _initFomoBar
63         */
64        _initFomoBar: function()
65        {
66            var elements = $('.ibx-fomo:last');
67
68            if ( elements.length === 0 ) {
69                return;
70			}
71
72            elements.each(function() {
73                var fomo_bar        = $(this),
74                    id              = fomo_bar.data('fomo-id'),
75                    duration        = fomo_bar.data('display-duration'),
76                    countdown_time  = fomo_bar.find('.ibx-fomo-countdown').data('fomo-time'),
77					timer_style  	= fomo_bar.find('.ibx-fomo-countdown').data('style'),
78					date 			= new Date(),
79					countdown       = [],
80					countdown_cookie = '';
81
82				if ( fomo_bar.hasClass( 'ibx-fomo-hide-mobile' ) && window.innerWidth <= 768 ) {
83					return;
84				}
85
86                if ( 'undefined' !== typeof countdown_time ) {
87
88					if ( 'evergreen' === timer_style ) {
89						countdown['days']       = countdown_time.split(',')[0];
90						countdown['hours']      = countdown_time.split(',')[1];
91						countdown['minutes']    = countdown_time.split(',')[2];
92						countdown['seconds']    = countdown_time.split(',')[3];
93
94						var year    = date.getYear() + 1900,
95							month   = date.getMonth() + 1,
96							days    = ( parseInt( date.getDate() ) + parseInt( countdown['days'] ) ),
97							hours   = ( parseInt( date.getHours() ) + parseInt( countdown['hours'] ) ),
98							minutes = ( parseInt( date.getMinutes() ) + parseInt( countdown['minutes'] ) ),
99							seconds = ( parseInt( date.getSeconds() ) + parseInt( countdown['seconds'] ) );
100					} else {
101						countdown['days']       = countdown_time.split(',')[0];
102						countdown['month']      = countdown_time.split(',')[1];
103						countdown['year']    	= countdown_time.split(',')[2];
104						countdown['hours']    	= countdown_time.split(',')[3];
105						countdown['minutes']    = countdown_time.split(',')[4];
106						countdown['seconds']    = countdown_time.split(',')[5];
107
108						var year    = parseInt( countdown['year'] ),
109							month   = parseInt( countdown['month'] ),
110							days    = parseInt( countdown['days'] ),
111							hours   = parseInt( countdown['hours'] ),
112							minutes = parseInt( countdown['minutes'] ),
113							seconds = parseInt( countdown['seconds'] );
114					}
115
116					var new_date = new Date( year, parseInt( month, 10 ) - 1, days, hours, minutes, seconds );
117
118                    // Convert countdown time to miliseconds and add it to current date.
119                    date.setTime(date.getTime() +  ( parseInt( countdown['days'] ) * 24 * 60 * 60 * 1000)
120                                                +  ( parseInt( countdown['hours'] )  * 60 * 60 * 1000)
121                                                +  ( parseInt( countdown['minutes'] ) * 60 * 1000)
122                                                +  ( parseInt( countdown['seconds'] ) * 1000) );
123
124                    // Remove countdown value from cookie if countdown value has changed in wp-admin.
125                    if( $.cookie('ibx_fomo_countdown_old') !== countdown_time ){
126                        $.cookie( 'ibx_fomo_countdown_old', countdown_time, { expires: date } );
127                        $.removeCookie('ibx_fomo_countdown');
128                    }
129                    // Get countdown value from cookie if exist.
130                    if ( $.cookie('ibx_fomo_countdown') ){
131                        countdown_cookie = $.cookie( 'ibx_fomo_countdown' );
132                    }
133                    else {
134                        // Set countdown value in cookie if doesn't exist.
135                        $.cookie( 'ibx_fomo_countdown', new_date.getTime(), { expires: date } );
136                        $.cookie( 'ibx_fomo_countdown_old', countdown_time, { expires: date } );
137                        countdown_cookie = $.cookie( 'ibx_fomo_countdown' );
138                    }
139
140                    // Start countdown.
141                    var countdown_interval = setInterval(function() {
142                        var now         = new Date().getTime(),
143							difference  = 'evergreen' === timer_style ? ( countdown_cookie - now ) : ( new_date.getTime() - now );
144							
145						// If the count down is over, write some text
146						if ( difference <= 0 ) {
147							clearInterval( countdown_interval );
148							fomo_bar.find('.ibx-fomo-days').html('0');
149							fomo_bar.find('.ibx-fomo-hours').html('0');
150							fomo_bar.find('.ibx-fomo-minutes').html('0');
151							fomo_bar.find('.ibx-fomo-seconds').html('0');
152							fomo_bar.find('.ibx-fomo-bar-wrapper').addClass('ibx-fomo-expired');
153							return;
154						}
155
156                        // Calculate time from difference.
157                        var days        = Math.floor( difference / ( 1000 * 60 * 60 * 24 ) ),
158                            hours       = Math.floor( ( difference % ( 1000 * 60 * 60 * 24 ) ) / ( 1000 * 60 * 60 ) ),
159                            minutes     = Math.floor( ( difference % ( 1000 * 60 * 60 ) ) / ( 1000 * 60 ) ),
160                            seconds     = Math.floor( ( difference % ( 1000 * 60 )) / 1000 );
161
162                        // Output the result in an element with id="ibx-fomo-countdown-time"
163                        fomo_bar.find('.ibx-fomo-days').html(days);
164                        fomo_bar.find('.ibx-fomo-hours').html(hours);
165                        fomo_bar.find('.ibx-fomo-minutes').html(minutes);
166                        fomo_bar.find('.ibx-fomo-seconds').html(seconds);
167                    }, 1000);
168                }
169
170                IBXFomo._showFomoBar(fomo_bar);
171
172                if ( 'undefined' !== typeof duration && '' !== duration ) {
173                    setTimeout(function() {
174                        IBXFomo._hideFomoBar();
175                    }, parseInt(duration) * 1000);
176                }
177            });
178        },
179
180		/**
181         * Displays the notification fomo bar.
182         *
183         * @since 1.0.0
184         * @access private
185         * @method _showFomoBar
186         */
187        _showFomoBar: function(fomo_bar)
188        {
189            if ( '' === fomo_bar ) {
190                fomo_bar = $('.ibx-fomo:last');
191            }
192            var initial_delay       = parseInt( fomo_bar.data('initial-delay') ),
193                fomo_bar_height     = fomo_bar.find('.ibx-fomo-bar-wrapper').outerHeight(),
194                admin_bar_height    = ( $('#wpadminbar').length > 0 ) ? $('#wpadminbar').outerHeight() : 0;
195
196            if ( '' === initial_delay || isNaN( initial_delay ) ) {
197                initial_delay = 0;
198            }
199
200            setTimeout(function() {
201                $('html').addClass('ibx-fomo-bar-active');
202                if ( fomo_bar.hasClass('ibx-fomo-position-top') ) {
203					$('html').animate({ 'padding-top': fomo_bar_height + 'px' }, 300);
204					fomo_bar.find('.ibx-fomo-bar-wrapper').css( 'margin-top', '0px' );
205                } else {
206					$('body').animate({'margin-bottom': fomo_bar_height + 'px'}, 300);
207				}
208
209                IBXFomo._fomoBarActive = 1;
210            }, initial_delay * 1000);
211        },
212
213		/**
214         * Hides the notification fomo bar.
215         *
216         * @since 1.0.0
217         * @access private
218         * @method _hideFomoBar
219         */
220        _hideFomoBar: function()
221        {
222            var fomo_bar            = $('.ibx-fomo:last'),
223                fomo_bar_height     = fomo_bar.find('.ibx-fomo-bar-wrapper').outerHeight(),
224                admin_bar_height    = ( $('#wpadminbar').length > 0 ) ? $('#wpadminbar').outerHeight() : 0;
225
226			$('html').removeClass('ibx-fomo-bar-active');
227			if ( ! fomo_bar.hasClass( 'ibx-fomo-position-bottom' ) ) {
228				$('html, body').css( 'padding-top', '0px' );
229			} else {
230				$('body').css('margin-bottom', '0px');
231			}		
232			fomo_bar.find('.ibx-fomo-bar-wrapper').removeAttr( 'style' );
233
234            IBXFomo._fomoBarActive = 0;
235		},
236		
237		/**
238         * Initialize the notifications.
239         *
240         * @since 1.0.0
241         * @access private
242         * @method _initNotifications
243         */
244		_initNotifications: function()
245		{
246			if ( 'undefined' === typeof ibx_fomo ) {
247                return;
248			}
249
250			$.cookie('ibx_wpfomo_notification_hidden', '', { expires: -1, path: '/' });
251			
252			if ( ibx_fomo.conversions.length > 0 ) {
253                IBXFomo._processNotifications( ibx_fomo.conversions, 'conversions' );
254			}
255			
256			if ( ibx_fomo.reviews.length > 0 ) {
257                IBXFomo._processNotifications( ibx_fomo.reviews, 'reviews' );
258            }
259		},
260
261		/**
262         * Fetch the notifications data and process them to render.
263         *
264         * @since 2.0
265         * @access private
266         * @method _processNotifications
267         */
268		_processNotifications: function( ids, type )
269		{
270			var node = $('<div class="ibx-conversions"></div>');
271			var html = '';
272			
273			if ( 'undefined' !== typeof ibx_fomo.data[type] ) {
274				var data = ibx_fomo.data[type];
275				var rawHtml = data.content;
276						
277				if ( rawHtml ) {
278					rawHtml = rawHtml.replace( /&#8217;/g, String.fromCharCode(8217) );
279					rawHtml = rawHtml.replace( /&amp;#8217;/g, String.fromCharCode(8217) );
280					rawHtml = rawHtml.replace( /&#8211;/g, String.fromCharCode(8211) );
281					rawHtml = rawHtml.replace( /&amp;#8211;/g, String.fromCharCode(8211) );
282				}
283
284				html = node.html(rawHtml);
285
286				IBXFomo._removeNotificationLocalData();
287				IBXFomo._renderNotification(data.config, html);
288
289				return;
290			}
291
292            $.ajax({
293                type: 'post',
294                url: ibx_fomo.ajaxurl,
295				cache: false,
296				headers: {
297					'X-Requested-With': 'WPfomify'
298				},
299                data: {
300                    action: 'ibx_wpfomo_get_conversions',
301                    nonce: ibx_fomo.nonce,
302                    ids: ids
303                },
304                success: function(data) {
305                    if ( data ) {
306
307						data = JSON.parse( data );
308						var rawHtml = data.content;
309						
310						if ( rawHtml ) {
311							rawHtml = rawHtml.replace( /&#8217;/g, String.fromCharCode(8217) );
312							rawHtml = rawHtml.replace( /&amp;#8217;/g, String.fromCharCode(8217) );
313							rawHtml = rawHtml.replace( /&#8211;/g, String.fromCharCode(8211) );
314							rawHtml = rawHtml.replace( /&amp;#8211;/g, String.fromCharCode(8211) );
315						}
316
317                        html = node.html(rawHtml);
318                        if ( 'undefined' !== typeof data.config.randomize && data.config.randomize === 1 ) {
319							var localData = IBXFomo._getNotificationLocalData(data.config.source);
320                            if ( localData ) {
321                                html = $(localData);
322                            } else {
323								if ( html[0].children.length > 0 ) {
324									for (var i = html[0].children.length; i >= 0; i--) {
325										html[0].appendChild(html[0].children[(Math.random() * i) | 0]);
326									}
327								}
328                                IBXFomo._saveNotificationLocalData(html[0].outerHTML, data.config.source);
329							}
330                        } else {
331							IBXFomo._removeNotificationLocalData();
332						}
333                        IBXFomo._renderNotification(data.config, html);
334                    }
335                }
336            });
337		},
338
339        /**
340         * Render the markup of notification.
341         *
342         * @since 1.0.0
343         * @access private
344         * @method _renderNotification
345         */
346        _renderNotification: function(config, html)
347        {
348            var count       = 0,
349                elements    = html.find('.ibx-notification-popup-' + config.id),
350                delayCalc   = (config.initial_delay + config.display_duration + config.delay_each) / 1000,
351                delayEach   = config.delay_each,
352                last        = IBXFomo._getLastNotification(config.id, false);
353
354            if ( last >= 0 ) {
355                count = last + 1;
356			}
357
358			if ( count >= $(elements).length ) {
359				count = 0;
360			}
361
362			if ( config.loop === 0 && elements.length === 1 ) {
363				count = 0;
364			}
365
366            setTimeout(function() {
367
368                // Show the first notification.
369				IBXFomo._showNotification( $(elements[count]), config, count );
370
371                setTimeout(function() {
372
373                    // Hide the first notification when display duration is expired.
374					IBXFomo._hideNotification( $(elements[count]) );
375					
376                    // Increase the sequence.
377                    count++;
378
379                    // Now lets render next notifications.
380                    var next = setInterval(function() {
381                        // Show next notification
382						IBXFomo._showNotification( $(elements[count]), config, count );
383
384                        setTimeout(function() {
385                            // Again hide this notification once display duration is expired.
386                            IBXFomo._hideNotification( $(elements[count]) );
387
388                            // reset the count, so that it can either start from begining or stop.
389                            if ( count >= elements.length - 1 ) {
390                                count = 0;
391                                // If notifications are not in loop, clear the interval.
392                                if ( config.loop === 0 ) {
393                                    clearInterval(next);
394                                }
395                            } else {
396                                count++;
397                            }
398
399                        }, config.display_duration);
400
401						// TODO: delayEach can be used as random number.
402                    }, delayEach + config.display_duration);
403
404                }, config.display_duration);
405
406            }, config.initial_delay);
407        },
408
409        /**
410         * Show notification.
411         *
412         * @since 1.0.0
413         * @access private
414         * @method _showNotification
415         */
416        _showNotification: function(element, config, count)
417        {
418			if ( 'undefined' === typeof element || 0 === element.length ) {
419				return;
420			}
421
422			if ( 'undefined' !== typeof $.cookie( 'ibx_wpfomo_notification_hidden' ) ) {
423				return;
424            }
425            // if page visitor analytics then randomize.
426            var tmp_analytics_elem = element.find("#ibx-notification-popup-analytics-page");
427            if ('undefined' !== typeof tmp_analytics_elem && tmp_analytics_elem.length > 0) {
428                var prev_cnt = parseInt(tmp_analytics_elem.html().trim(), 10);
429                tmp_analytics_elem.html(prev_cnt + Math.abs( parseInt(IBXFomo._getRandomInt(-3, 3), 10)));
430            }
431			$('body').append(element);
432			
433			$('body').trigger('wpfomo.notification.beforeShow', [element]);
434
435			//element.animate({ 'bottom': '20px', 'opacity': '1' }, 500);
436
437            element.animate({ 'bottom': '15px', 'opacity': '1' }, 500, function () {
438				//this.classList.add("fade");
439				$('body').trigger('wpfomo.notification.afterShow', [element]);
440            });
441
442			// Save the sequence of the last notification.
443			IBXFomo._saveLastConversion( config.id, count );
444        },
445
446        /**
447         * Hide notification.
448         *
449         * @since 1.0.0
450         * @access private
451         * @method _hideNotification
452         */
453        _hideNotification: function(element)
454        {
455			$('body').trigger('wpfomo.notification.beforeHide', [element]);
456
457            element.animate({ 'bottom': '-250px', 'opacity': '0' }, 1000, function() {
458				IBXFomo._removeNotification(element);
459				$('body').trigger('wpfomo.notification.afterHide', [element]);
460            });
461        },
462
463        /**
464         * Remove notification.
465         *
466         * @since 1.0.0
467         * @access private
468         * @method _removeNotification
469         */
470        _removeNotification: function(element)
471        {
472            if ( element.length > 0 ) {
473                element.remove();
474            }
475        },
476
477        /**
478         * Get the sequence of the last notification.
479         *
480         * @since 1.0.0
481         * @access private
482         * @method _getLastNotification
483         */
484        _getLastNotification: function(id, obj)
485        {
486            var last = -1;
487            if ( window.localStorage ) {
488                var notificationSequenece = window.localStorage.getItem('ibx_wpfomo_notifications');
489                if ( null !== notificationSequenece ) {
490                    notificationSequenece = JSON.parse(notificationSequenece);
491                    if ( undefined !== notificationSequenece[id] ) {
492                        if ( obj ) {
493                            return notificationSequenece;
494                        }
495                        last = notificationSequenece[id];
496                    }
497                }
498            } else {
499                console.log('Browser does not support localStorage!');
500            }
501            return last;
502        },
503
504        /**
505         * Save the sequence of the last notification.
506         *
507         * @since 1.0.0
508         * @access private
509         * @method _saveLastConversion
510         */
511        _saveLastConversion: function(id, sequence)
512        {
513            if ( window.localStorage ) {
514                var lastConversion = IBXFomo._getLastNotification(id, true);
515                if ( 'object' === typeof lastConversion ) {
516                    lastConversion[id] = sequence;
517                } else {
518                    lastConversion = new Object;
519                    lastConversion[id] = sequence;
520                }
521                window.localStorage.setItem('ibx_wpfomo_notifications', JSON.stringify(lastConversion));
522            } else {
523                console.log('Browser does not support localStorage!');
524            }
525        },
526
527        /**
528         * Get notification data from localStorage.
529         *
530         * @since 1.0.0
531         * @access private
532         * @method _getNotificationLocalData
533         */
534        _getNotificationLocalData: function(source)
535        {
536            if (window.localStorage) {
537				
538				if ( window.localStorage.getItem('ibx_wpfomo_notifications_source') !== source ) {
539					IBXFomo._removeNotificationLocalData();
540					return false;
541				}
542
543                var html = window.localStorage.getItem('ibx_wpfomo_notifications_html');
544                var expireTime = window.localStorage.getItem("ibx_wpfomo_notifications_expire");
545                var difference = Date.now() - expireTime;
546                var hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
547
548                if ( hours >= 3 ) {
549					html = '';
550					IBXFomo._removeNotificationLocalData();
551                }
552
553                if ( typeof html === 'undefined' || html === '' ) {
554                    return false;
555                }
556
557                return html;
558            }
559
560            return false;
561        },
562
563        /**
564         * Save notification data in localStorage.
565         *
566         * @since 1.0.0
567         * @access private
568         * @method _saveNotificationLocalData
569         */
570        _saveNotificationLocalData: function(html, source)
571        {
572            if (window.localStorage) {
573                window.localStorage.setItem('ibx_wpfomo_notifications_html', html);
574                window.localStorage.setItem('ibx_wpfomo_notifications_source', source);
575                window.localStorage.setItem('ibx_wpfomo_notifications_expire', Date.now());
576            }
577		},
578		
579		/**
580         * Remove notification data from localStorage.
581         *
582         * @since 1.0.0
583         * @access private
584         * @method _removeNotificationLocalData
585         */
586		_removeNotificationLocalData: function()
587		{
588			window.localStorage.removeItem('ibx_wpfomo_notifications_html');
589			window.localStorage.removeItem('ibx_wpfomo_notifications_source');
590			window.localStorage.removeItem('ibx_wpfomo_notifications_expire');
591        },
592
593        /**
594		 * Get random integer value between range
595		 *
596		 * @since 1.0.0
597		 * @access private
598		 * @method _getRandomInt
599		 */
600        _getRandomInt: function (min, max) 
601        {
602            min = Math.ceil(min);
603            max = Math.floor(max);
604            return Math.floor(Math.random() * (max - min)) + min; // The maximum is exclusive and the minimum is inclusive
605        },
606    };
607
608	// Load the object.
609    $(window).load(function(e) {
610		IBXFomo._init();
611	});
612
613})(jQuery);

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