PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.38
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.38
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.38, at includes/extensions/Popup_Builder/popup-module.js

390 lines 14.7 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 popup.find('.king-addons-pb-popup-container').addClass('animated ' + settings.popup_animation);
150
151 $(window).trigger('resize');
152
153 $('.king-addons-pb-popup-overlay').hide().fadeIn();
154
155 popup.find('.king-addons-pb-popup-close-btn').css('opacity', '0');
156
157 // noinspection JSUnresolvedReference
158 setTimeout(function () {
159 popup.find('.king-addons-pb-popup-close-btn').animate({
160 'opacity': '1'
161 }, 500);
162 }, settings.popup_close_button_display_delay * 1000);
163
164 // noinspection JSUnresolvedReference
165 if (false !== settings.popup_automatic_close_switch) {
166 // noinspection JSUnresolvedReference
167 setTimeout(function () {
168 KingAddonsPB_Popups.closePopup(popup);
169 }, settings.popup_automatic_close_delay * 1000);
170 }
171 },
172
173 closePopupInit: function () {
174 $('.king-addons-pb-popup-close-btn').on('click', function () {
175 KingAddonsPB_Popups.closePopup($(this).closest('.king-addons-pb-template-popup'));
176 });
177
178 $('.king-addons-pb-popup-overlay').on('click', function () {
179 let popup = $(this).closest('.king-addons-pb-template-popup'),
180 popupID = KingAddonsPB_Popups.getID(popup),
181 settings = KingAddonsPB_Popups.getLocalStorage(popupID);
182
183 // noinspection JSUnresolvedReference
184 if (false === settings.popup_overlay_disable_close) {
185 KingAddonsPB_Popups.closePopup(popup);
186 }
187 });
188
189 $(document).on('keyup', function (event) {
190 let popup = $('.king-addons-pb-popup-open');
191
192 if (popup.length) {
193 let popupID = KingAddonsPB_Popups.getID(popup),
194 settings = KingAddonsPB_Popups.getLocalStorage(popupID);
195
196 // noinspection JSUnresolvedReference
197 if (27 === event.keyCode && false === settings.popup_disable_esc_key) {
198 KingAddonsPB_Popups.closePopup(popup);
199 }
200 }
201 });
202 },
203
204 closePopup: function (popup,) {
205 let popupID = KingAddonsPB_Popups.getID(popup),
206 settings = KingAddonsPB_Popups.getLocalStorage(popupID);
207
208 let body = $('body');
209
210 if ('notification' === settings.popup_display_as) {
211 body.css('padding-top', 0);
212 }
213
214 KingAddonsPB_Popups.setLocalStorage(popup, 'hide');
215
216 if ('modal' === settings.popup_display_as) {
217 popup.fadeOut();
218 } else {
219 popup.hide();
220 }
221
222 body.css('overflow', 'visible');
223
224 $(window).trigger('resize');
225 },
226
227 popupTriggerInit: function (popup) {
228 let popupTrigger = popup.find('.king-addons-pb-popup-trigger-button');
229
230 if (!popupTrigger.length) {
231 return;
232 }
233
234 popupTrigger.on('click', function () {
235 let settings = JSON.parse(localStorage.getItem('KingAddonsPB_PopupSettings')) || {};
236 let popupTriggerType = $(this).attr('data-trigger'),
237 popupShowDelay = $(this).attr('data-show-delay'),
238 popupRedirect = $(this).attr('data-redirect'),
239 popupRedirectURL = $(this).attr('data-redirect-url'),
240 popupID = KingAddonsPB_Popups.getID(popup);
241
242 // noinspection DuplicatedCode
243 if ('close' === popupTriggerType) {
244 settings[popupID].popup_show_again_delay = parseInt(popupShowDelay, 10);
245 settings[popupID].popup_close_time = Date.now();
246 } else if ('close-permanently' === popupTriggerType) {
247 settings[popupID].popup_show_again_delay = parseInt(popupShowDelay, 10);
248 settings[popupID].popup_close_time = Date.now();
249 } else if ('back' === popupTriggerType) {
250 window.history.back();
251 }
252
253 KingAddonsPB_Popups.closePopup(popup);
254
255 localStorage.setItem('KingAddonsPB_PopupSettings', JSON.stringify(settings));
256
257 if ('back' !== popupTriggerType && 'yes' === popupRedirect) {
258 setTimeout(function () {
259 window.location.href = popupRedirectURL;
260 }, 100);
261 }
262 });
263
264 },
265
266 getLocalStorage: function (id) {
267 let getLocalStorage = JSON.parse(localStorage.getItem('KingAddonsPB_PopupSettings'));
268
269 if (null == getLocalStorage) {
270 return false;
271 }
272
273 let settings = getLocalStorage[id];
274
275 if (null == settings) {
276 return false;
277 }
278
279 return settings;
280 },
281
282 setLocalStorage: function (popup, display) {
283 let popupID = KingAddonsPB_Popups.getID(popup);
284 let settings = JSON.parse(localStorage.getItem('KingAddonsPB_PopupSettings')) || {};
285
286 settings[popupID] = JSON.parse(popup.attr('data-settings'));
287
288 if ('hide' === display) {
289 settings[popupID].popup_close_time = Date.now();
290 } else {
291 settings[popupID].popup_close_time = false;
292 }
293
294 localStorage.setItem('KingAddonsPB_PopupSettings', JSON.stringify(settings));
295 },
296
297 checkStopShowingAfterDate: function (popup) {
298 let settings = JSON.parse(popup.attr('data-settings'));
299 let currentDate = Date.now();
300
301 // noinspection JSUnresolvedReference
302 if ('yes' === settings.popup_stop_after_date) {
303 // noinspection JSUnresolvedReference
304 if (currentDate >= Date.parse(settings.popup_stop_after_date_select)) {
305 return false;
306 }
307 }
308
309 return true;
310 },
311
312 checkAvailability: function (id) {
313 let popup = $('#king-addons-pb-popup-id-' + id),
314 dataSettings = JSON.parse(popup.attr('data-settings')),
315 currentURL = window.location.href;
316
317 // noinspection JSUnresolvedReference
318 if ('yes' === dataSettings.popup_show_via_referral && -1 === currentURL.indexOf('king_addons_ext_pb=user-popup')) {
319 // noinspection JSUnresolvedReference
320 if (currentURL.indexOf(dataSettings.popup_referral_keyword) === -1) {
321 return;
322 }
323 }
324
325 if (false === KingAddonsPB_Popups.getLocalStorage(id)) {
326 return true;
327 }
328
329 let trigger = popup.find('.king-addons-pb-popup-trigger-button'),
330 triggerShowDelay = trigger.attr('data-show-delay');
331
332 let currentDate = Date.now();
333 let settings = KingAddonsPB_Popups.getLocalStorage(id);
334
335 if (triggerShowDelay) {
336
337 let permanent = true;
338
339 trigger.each(function () {
340 let delay = $(this).attr('data-show-delay');
341
342 if (settings.popup_show_again_delay === parseInt(delay, 10)) {
343 permanent = false;
344 }
345 });
346
347 if (true === permanent) {
348 return true;
349 }
350 } else {
351 if (settings.popup_show_again_delay !== dataSettings.popup_show_again_delay) {
352 return true;
353 }
354 }
355
356 let closeDate = settings.popup_close_time || 0,
357 showDelay = parseInt(settings.popup_show_again_delay, 10);
358
359 return closeDate + showDelay < currentDate;
360 },
361
362 checkAvailableDevice: function (popup, settings) {
363 let viewport = $('body').prop('clientWidth');
364
365 if (viewport > 1024) {
366 // noinspection JSUnresolvedReference
367 return Boolean(settings.popup_show_on_device);
368 } else if (viewport > 768) {
369 // noinspection JSUnresolvedReference
370 return Boolean(settings.popup_show_on_device_tablet);
371 } else {
372 // noinspection JSUnresolvedReference
373 return Boolean(settings.popup_show_on_device_mobile);
374 }
375 },
376
377 getID: function (popup) {
378 let id = popup.attr('id');
379
380 return id.replace('king-addons-pb-popup-id-', '');
381 },
382
383 editorCheck: function () {
384 return !!$('body').hasClass('elementor-editor-active');
385 }
386 }
387
388 KingAddonsPB_Popups.init();
389
390 }(jQuery, window.elementorFrontend));