'use strict';
/**
* Used to handle :
* Click of Non-Installed Plugins
* Show Upsell Popup
* Unbind Drag & Drop
*/
let SbElementorHandler = window.SbElementorHandler || ( function( _document, window, $ ) {
const smashBalloonPlugins = sbHandler.smashPlugins;
let app = {
init: function() {
app.events();
},
events: function() {
$( window ).on('elementor/frontend/init', function () {
app.disableInactiveSmashWidgets();
setTimeout(function(){
elementor.panel.$el.on('click', function () {
app.disableInactiveSmashWidgets();
});
}, 300)
});
},
disableInactiveSmashWidgets : function(){
setTimeout(function(){
for (const pluginName in smashBalloonPlugins) {
let plugin = smashBalloonPlugins[pluginName],
pluginWidget = elementor.panel.$el.find("#elementor-panel-category-smash-balloon").find('.sb-elem-inactive.sb-elem-'+pluginName).parents('.elementor-element-wrapper').find('.elementor-element');
pluginWidget.attr('draggable', false);
pluginWidget.on('click', function(){
app.createUpsellPopup( pluginName );
});
}
}, 500)
},
createUpsellPopup : function( pluginName ){
let plugin = smashBalloonPlugins[pluginName],
spinnerIcon = '',
upsellPopupOutput =
'
\
\
';
if($(window.parent.document.body).find('.sb-center-boss').length === 0){
$(window.parent.document.body).append(upsellPopupOutput);
}
$(window.parent.document.body).find('.sb-install-plugin-btn').on('click', function(){
let downloadPlugin = $(this).attr('data-plugin');
$(this).find('.sb-install-plugin-spinner').show();
app.installPlugin(downloadPlugin);
});
$(window.parent.document.body).find('.sb-install-refresh-btn').on('click', function(){
window.parent.location.reload();
});
$(window.parent.document.body).find('.sb-popup-cls').on('click', function(){
app.closeUpsellPopup();
});
},
closeUpsellPopup : function(){
$(window.parent.document.body).find('.sb-center-boss').remove();
},
installPlugin : function(downloadPlugin){
let data = new FormData();
data.append( 'action', 'sby_install_other_plugins' );
data.append( 'nonce', sbHandler.nonce );
data.append( 'plugin', downloadPlugin );
data.append( 'type', 'plugin' );
fetch(sbHandler.ajax_handler, {
method: "POST",
credentials: 'same-origin',
body: data
})
.then(response => response.json())
.then(data => {
$(window.parent.document.body).find('.sb-install-plugin-btn').hide();
if( data.success == true ) {
$(window.parent.document.body).find('.sb-install-refresh-btn').show();
}
});
}
};
return app;
}( document, window, jQuery ) );
SbElementorHandler.init();