| 1 |
(function ($) { |
| 2 |
"use strict"; |
| 3 |
|
| 4 |
let KingAddonsPB_ModalPopups = { |
| 5 |
|
| 6 |
init: function () { |
| 7 |
if (!$('body').hasClass('elementor-editor-king-addons-pb-popups')) { |
| 8 |
return; |
| 9 |
} |
| 10 |
window.elementor.on('preview:loaded', KingAddonsPB_ModalPopups.onPreviewLoad); |
| 11 |
elementor.settings.page.model.on('change', KingAddonsPB_ModalPopups.onControlChange); |
| 12 |
}, |
| 13 |
|
| 14 |
onPreviewLoad: function () { |
| 15 |
|
| 16 |
setTimeout(function () { |
| 17 |
$('#elementor-panel-footer-settings').trigger('click'); |
| 18 |
}, 2000); |
| 19 |
|
| 20 |
KingAddonsPB_ModalPopups.settingsNotification(); |
| 21 |
|
| 22 |
window.elementorFrontend.hooks.addAction('frontend/element_ready/global', function ($scope) { |
| 23 |
let popup = $scope.closest('.king-addons-pb-template-popup'); |
| 24 |
KingAddonsPB_ModalPopups.fixPopupLayout(popup); |
| 25 |
}); |
| 26 |
}, |
| 27 |
|
| 28 |
onControlChange: function (model) { |
| 29 |
let iframe = document.getElementById('elementor-preview-iframe'), |
| 30 |
iframeContent = iframe.contentDocument || iframe.contentWindow.document; |
| 31 |
|
| 32 |
let popup = $('.king-addons-pb-template-popup', iframeContent); |
| 33 |
|
| 34 |
if (model.changed.hasOwnProperty('popup_display_as')) { |
| 35 |
if ('notification' === model.changed['popup_display_as']) { |
| 36 |
popup.addClass('king-addons-pb-popup-notification'); |
| 37 |
} else { |
| 38 |
popup.removeClass('king-addons-pb-popup-notification'); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
if (model.changed.hasOwnProperty('popup_animation')) { |
| 43 |
let popupContainer = popup.find('.king-addons-pb-popup-container'); |
| 44 |
|
| 45 |
// Avoid conflict with Bootstrap's `.fade` class. |
| 46 |
const animationClass = (model.changed['popup_animation'] === 'fade') ? 'fadeIn' : model.changed['popup_animation']; |
| 47 |
|
| 48 |
popupContainer.removeAttr('class'); |
| 49 |
popupContainer.addClass('king-addons-pb-popup-container animated ' + animationClass); |
| 50 |
} |
| 51 |
}, |
| 52 |
|
| 53 |
fixPopupLayout: function (popup) { |
| 54 |
let settings = KingAddonsPB_ModalPopups.getDocumentSettings(); |
| 55 |
|
| 56 |
if (!popup.find('.king-addons-pb-popup-container-inner').hasClass('ps')) { |
| 57 |
new PerfectScrollbar(popup.find('.king-addons-pb-popup-container-inner')[0], { |
| 58 |
suppressScrollX: true |
| 59 |
}); |
| 60 |
} |
| 61 |
|
| 62 |
if ('notification' === settings.popup_display_as) { |
| 63 |
popup.addClass('king-addons-pb-popup-notification'); |
| 64 |
} |
| 65 |
}, |
| 66 |
|
| 67 |
getDocumentSettings: function () { |
| 68 |
let documentSettings = {}, |
| 69 |
settings = elementor.settings.page.model; |
| 70 |
|
| 71 |
jQuery.each(settings.getActiveControls(), function (controlKey) { |
| 72 |
documentSettings[controlKey] = settings.attributes[controlKey]; |
| 73 |
}); |
| 74 |
|
| 75 |
return documentSettings; |
| 76 |
}, |
| 77 |
|
| 78 |
settingsNotification: function () { |
| 79 |
let closeTime = JSON.parse(localStorage.getItem('KingAddonsPopupEditorNotificationDate')) || 0; |
| 80 |
|
| 81 |
// 7 days |
| 82 |
if (closeTime + 604800000 >= Date.now()) { |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
const body = $('body'); |
| 87 |
|
| 88 |
const isNewEditor = body.find('#elementor-editor-wrapper-v2').length > 0; |
| 89 |
|
| 90 |
const nHTML = `<div id="king-addons-editor-settings-notification" class="${isNewEditor ? 'king-addons-new-editor-bar' : ''}"> |
| 91 |
<p>Click here to access <strong>Popup Settings</strong>.</p> |
| 92 |
<i class="eicon-close"></i> |
| 93 |
</div>`; |
| 94 |
|
| 95 |
const target = isNewEditor |
| 96 |
? $('body .MuiBox-root button[value="document-settings"]') |
| 97 |
: body; |
| 98 |
|
| 99 |
target.append(nHTML).hide().fadeIn(); |
| 100 |
|
| 101 |
$('#king-addons-editor-settings-notification .eicon-close').on('click', function () { |
| 102 |
$('#king-addons-editor-settings-notification').fadeOut(); |
| 103 |
|
| 104 |
localStorage.setItem('KingAddonsPopupEditorNotificationDate', JSON.stringify(Date.now())); |
| 105 |
}); |
| 106 |
}, |
| 107 |
}; |
| 108 |
|
| 109 |
$(window).on('elementor:init', KingAddonsPB_ModalPopups.init); |
| 110 |
}(jQuery)); |