PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.65
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.65
51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 All 40 releases
king-addons / includes / extensions / Popup_Builder / popup-module.js

popup-module.js in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.65, at includes/extensions/Popup_Builder/popup-module.js

395 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2 "use strict";
3
4 let KingAddonsPB_Popups = {
5
6 init: function () {
7 $(document).ready(function () {
8 if (!$('.king-addons-pb-template-popup').length || KingAddonsPB_Popups.editorCheck()) {
9 return;
10 }
11 KingAddonsPB_Popups.openPopupInit();
12 KingAddonsPB_Popups.closePopupInit();
13 });
14 },
15
16 openPopupInit: function () {
17 $('.king-addons-pb-template-popup').each(function () {
18 let popup = $(this),
19 popupID = KingAddonsPB_Popups.getID(popup);
20
21 if (!KingAddonsPB_Popups.checkAvailability(popupID)) {
22 return;
23 }
24
25 if (!KingAddonsPB_Popups.checkStopShowingAfterDate(popup)) {
26 return;
27 }
28
29 KingAddonsPB_Popups.setLocalStorage(popup, 'show');
30
31 let getLocalStorage = JSON.parse(localStorage.getItem('KingAddonsPB_PopupSettings')),
32 settings = getLocalStorage[popupID];
33
34 if (!KingAddonsPB_Popups.checkAvailableDevice(popup, settings)) {
35 return false;
36 }
37
38 KingAddonsPB_Popups.popupTriggerInit(popup);
39
40 if ('load' === settings.popup_trigger) {
41 let loadDelay = settings.popup_load_delay * 1000;
42
43 $(window).on('load', function () {
44 setTimeout(function () {
45 KingAddonsPB_Popups.openPopup(popup, settings);
46 }, loadDelay);
47 });
48
49 } else if ('scroll' === settings.popup_trigger) {
50 $(window).on('scroll', function () {
51
52 let scrollPercent = Math.round(($(window).scrollTop() / ($(document).height() - $(window).height())) * 100);
53
54 // noinspection JSUnresolvedReference
55 if (scrollPercent >= settings.popup_scroll_progress && !popup.hasClass('king-addons-pb-popup-open')) {
56 KingAddonsPB_Popups.openPopup(popup, settings);
57 }
58 });
59
60 } else if ('element-scroll' === settings.popup_trigger) {
61 $(window).on('scroll', function () {
62 // noinspection JSUnresolvedReference
63 let element = $(settings.popup_element_scroll),
64 ScrollBottom = $(window).scrollTop() + $(window).height();
65
66 if (!element.length) {
67 return;
68 }
69
70 if (element.offset().top < ScrollBottom && !popup.hasClass('king-addons-pb-popup-open')) {
71 KingAddonsPB_Popups.openPopup(popup, settings);
72 }
73 });
74
75 } else if ('date' === settings.popup_trigger) {
76 // noinspection JSUnresolvedReference
77 let nowDate = Date.now(),
78 startDate = Date.parse(settings.popup_specific_date);
79
80 if (startDate < nowDate) {
81
82 setTimeout(function () {
83 KingAddonsPB_Popups.openPopup(popup, settings);
84 }, 1000);
85 }
86
87 } else if ('inactivity' === settings.popup_trigger) {
88 // noinspection JSUnresolvedReference
89 let idleTimer = null,
90 inactivityTime = settings.popup_inactivity_time * 1000;
91
92 // noinspection DuplicatedCode
93 $('*').bind('mousemove click keyup scroll resize', function () {
94 if (popup.hasClass('king-addons-pb-popup-open')) {
95 return;
96 }
97
98 clearTimeout(idleTimer);
99
100 idleTimer = setTimeout(function () {
101 KingAddonsPB_Popups.openPopup(popup, settings);
102 }, inactivityTime);
103 });
104
105 $('body').trigger('mousemove');
106
107 } else if ('exit' === settings.popup_trigger) {
108 $(document).on('mouseleave', 'body', function () {
109 if (!popup.hasClass('king-addons-pb-popup-open')) {
110 KingAddonsPB_Popups.openPopup(popup, settings);
111 }
112 });
113
114 } else if ('custom' === settings.popup_trigger) {
115 // noinspection JSUnresolvedReference
116 $(settings.popup_custom_trigger).on('click', function () {
117 KingAddonsPB_Popups.openPopup(popup, settings);
118 });
119
120 // noinspection JSUnresolvedReference
121 $(settings.popup_custom_trigger).css('cursor', 'pointer');
122 }
123
124 if ('0px' !== popup.find('.king-addons-pb-popup-container-inner').css('height')) {
125 new PerfectScrollbar(popup.find('.king-addons-pb-popup-container-inner')[0], {
126 suppressScrollX: true
127 });
128 }
129 });
130 },
131
132 openPopup: function (popup, settings) {
133 if ('notification' === settings.popup_display_as) {
134 popup.addClass('king-addons-pb-popup-notification');
135
136 setTimeout(function () {
137 $('body').animate({
138 'padding-top': popup.find('.king-addons-pb-popup-container').outerHeight() + 'px'
139 }, settings.popup_animation_duration * 1000, 'linear');
140 }, 10);
141 }
142
143 // noinspection JSUnresolvedReference
144 if (settings.popup_disable_page_scroll && 'modal' === settings.popup_display_as) {
145 $('body').css('overflow', 'hidden');
146 }
147
148 popup.addClass('king-addons-pb-popup-open').show();
149 const popupContainer = popup.find('.king-addons-pb-popup-container');
150
151 // Avoid conflict with Bootstrap's `.fade` class.
152 // Keep stored setting as `fade`, but use animate.css `fadeIn` at runtime.
153 const animationClass = (settings.popup_animation === 'fade') ? 'fadeIn' : settings.popup_animation;
154 popupContainer.addClass('animated ' + animationClass);
155
156 $(window).trigger('resize');
157
158 $('.king-addons-pb-popup-overlay').hide().fadeIn();
159
160 popup.find('.king-addons-pb-popup-close-btn').css('opacity', '0');
161
162 // noinspection JSUnresolvedReference
163 setTimeout(function () {
164 popup.find('.king-addons-pb-popup-close-btn').animate({
165 'opacity': '1'
166 }, 500);
167 }, settings.popup_close_button_display_delay * 1000);
168
169 // noinspection JSUnresolvedReference
170 if (false !== settings.popup_automatic_close_switch) {
171 // noinspection JSUnresolvedReference
172 setTimeout(function () {
173 KingAddonsPB_Popups.closePopup(popup);
174 }, settings.popup_automatic_close_delay * 1000);
175 }
176 },
177
178 closePopupInit: function () {
179 $('.king-addons-pb-popup-close-btn').on('click', function () {
180 KingAddonsPB_Popups.closePopup($(this).closest('.king-addons-pb-template-popup'));
181 });
182
183 $('.king-addons-pb-popup-overlay').on('click', function () {
184 let popup = $(this).closest('.king-addons-pb-template-popup'),
185 popupID = KingAddonsPB_Popups.getID(popup),
186 settings = KingAddonsPB_Popups.getLocalStorage(popupID);
187
188 // noinspection JSUnresolvedReference
189 if (false === settings.popup_overlay_disable_close) {
190 KingAddonsPB_Popups.closePopup(popup);
191 }
192 });
193
194 $(document).on('keyup', function (event) {
195 let popup = $('.king-addons-pb-popup-open');
196
197 if (popup.length) {
198 let popupID = KingAddonsPB_Popups.getID(popup),
199 settings = KingAddonsPB_Popups.getLocalStorage(popupID);
200
201 // noinspection JSUnresolvedReference
202 if (27 === event.keyCode && false === settings.popup_disable_esc_key) {
203 KingAddonsPB_Popups.closePopup(popup);
204 }
205 }
206 });
207 },
208
209 closePopup: function (popup,) {
210 let popupID = KingAddonsPB_Popups.getID(popup),
211 settings = KingAddonsPB_Popups.getLocalStorage(popupID);
212
213 let body = $('body');
214
215 if ('notification' === settings.popup_display_as) {
216 body.css('padding-top', 0);
217 }
218
219 KingAddonsPB_Popups.setLocalStorage(popup, 'hide');
220
221 if ('modal' === settings.popup_display_as) {
222 popup.fadeOut();
223 } else {
224 popup.hide();
225 }
226
227 body.css('overflow', 'visible');
228
229 $(window).trigger('resize');
230 },
231
232 popupTriggerInit: function (popup) {
233 let popupTrigger = popup.find('.king-addons-pb-popup-trigger-button');
234
235 if (!popupTrigger.length) {
236 return;
237 }
238
239 popupTrigger.on('click', function () {
240 let settings = JSON.parse(localStorage.getItem('KingAddonsPB_PopupSettings')) || {};
241 let popupTriggerType = $(this).attr('data-trigger'),
242 popupShowDelay = $(this).attr('data-show-delay'),
243 popupRedirect = $(this).attr('data-redirect'),
244 popupRedirectURL = $(this).attr('data-redirect-url'),
245 popupID = KingAddonsPB_Popups.getID(popup);
246
247 // noinspection DuplicatedCode
248 if ('close' === popupTriggerType) {
249 settings[popupID].popup_show_again_delay = parseInt(popupShowDelay, 10);
250 settings[popupID].popup_close_time = Date.now();
251 } else if ('close-permanently' === popupTriggerType) {
252 settings[popupID].popup_show_again_delay = parseInt(popupShowDelay, 10);
253 settings[popupID].popup_close_time = Date.now();
254 } else if ('back' === popupTriggerType) {
255 window.history.back();
256 }
257
258 KingAddonsPB_Popups.closePopup(popup);
259
260 localStorage.setItem('KingAddonsPB_PopupSettings', JSON.stringify(settings));
261
262 if ('back' !== popupTriggerType && 'yes' === popupRedirect) {
263 setTimeout(function () {
264 window.location.href = popupRedirectURL;
265 }, 100);
266 }
267 });
268
269 },
270
271 getLocalStorage: function (id) {
272 let getLocalStorage = JSON.parse(localStorage.getItem('KingAddonsPB_PopupSettings'));
273
274 if (null == getLocalStorage) {
275 return false;
276 }
277
278 let settings = getLocalStorage[id];
279
280 if (null == settings) {
281 return false;
282 }
283
284 return settings;
285 },
286
287 setLocalStorage: function (popup, display) {
288 let popupID = KingAddonsPB_Popups.getID(popup);
289 let settings = JSON.parse(localStorage.getItem('KingAddonsPB_PopupSettings')) || {};
290
291 settings[popupID] = JSON.parse(popup.attr('data-settings'));
292
293 if ('hide' === display) {
294 settings[popupID].popup_close_time = Date.now();
295 } else {
296 settings[popupID].popup_close_time = false;
297 }
298
299 localStorage.setItem('KingAddonsPB_PopupSettings', JSON.stringify(settings));
300 },
301
302 checkStopShowingAfterDate: function (popup) {
303 let settings = JSON.parse(popup.attr('data-settings'));
304 let currentDate = Date.now();
305
306 // noinspection JSUnresolvedReference
307 if ('yes' === settings.popup_stop_after_date) {
308 // noinspection JSUnresolvedReference
309 if (currentDate >= Date.parse(settings.popup_stop_after_date_select)) {
310 return false;
311 }
312 }
313
314 return true;
315 },
316
317 checkAvailability: function (id) {
318 let popup = $('#king-addons-pb-popup-id-' + id),
319 dataSettings = JSON.parse(popup.attr('data-settings')),
320 currentURL = window.location.href;
321
322 // noinspection JSUnresolvedReference
323 if ('yes' === dataSettings.popup_show_via_referral && -1 === currentURL.indexOf('king_addons_ext_pb=user-popup')) {
324 // noinspection JSUnresolvedReference
325 if (currentURL.indexOf(dataSettings.popup_referral_keyword) === -1) {
326 return;
327 }
328 }
329
330 if (false === KingAddonsPB_Popups.getLocalStorage(id)) {
331 return true;
332 }
333
334 let trigger = popup.find('.king-addons-pb-popup-trigger-button'),
335 triggerShowDelay = trigger.attr('data-show-delay');
336
337 let currentDate = Date.now();
338 let settings = KingAddonsPB_Popups.getLocalStorage(id);
339
340 if (triggerShowDelay) {
341
342 let permanent = true;
343
344 trigger.each(function () {
345 let delay = $(this).attr('data-show-delay');
346
347 if (settings.popup_show_again_delay === parseInt(delay, 10)) {
348 permanent = false;
349 }
350 });
351
352 if (true === permanent) {
353 return true;
354 }
355 } else {
356 if (settings.popup_show_again_delay !== dataSettings.popup_show_again_delay) {
357 return true;
358 }
359 }
360
361 let closeDate = settings.popup_close_time || 0,
362 showDelay = parseInt(settings.popup_show_again_delay, 10);
363
364 return closeDate + showDelay < currentDate;
365 },
366
367 checkAvailableDevice: function (popup, settings) {
368 let viewport = $('body').prop('clientWidth');
369
370 if (viewport > 1024) {
371 // noinspection JSUnresolvedReference
372 return Boolean(settings.popup_show_on_device);
373 } else if (viewport > 768) {
374 // noinspection JSUnresolvedReference
375 return Boolean(settings.popup_show_on_device_tablet);
376 } else {
377 // noinspection JSUnresolvedReference
378 return Boolean(settings.popup_show_on_device_mobile);
379 }
380 },
381
382 getID: function (popup) {
383 let id = popup.attr('id');
384
385 return id.replace('king-addons-pb-popup-id-', '');
386 },
387
388 editorCheck: function () {
389 return !!$('body').hasClass('elementor-editor-active');
390 }
391 }
392
393 KingAddonsPB_Popups.init();
394
395 }(jQuery, window.elementorFrontend));