( function( $ ) { "use strict"; $(document).on('click', '.amd-notice .button-primary', function( e ) { if ( 'install-activate' === $(this).data('action') && ! $( this ).hasClass('init') ) { var $self = $(this), $href = $self.attr('href'); if ( 'true' === $self.data('freemius') ) { $href.replace('amdemoimporter-wizard','amdemoimporter-wizard') } $self.addClass('init'); $self.html('Installing Am Demo Importer '); var elementorData = { 'action' : 'amd_install_activate_elementor', 'nonce' : amd_localize.elementor_nonce }; // Send Request. $.post( amd_localize.ajax_url, elementorData, function( response ) { if ( response.success ) { console.log('elementor installed'); // Both Plugins Installed if ( true === response.data.plugins_updated ) { setTimeout(function() { $self.html('Redirecting to Am Demo Importer '); setTimeout( function() { window.location = $href; }, 1000 ); }, 500); console.log('Am Demo Importer Installed'); return false; } var amDemoImporterData = { 'action' : 'amd_install_activate_am_demo_importer', 'nonce' : amd_localize.am_demo_importer_nonce }; $.post( amd_localize.ajax_url, amDemoImporterData, function( response ) { if ( response.success ) { var elementorRedirect = { 'action' : 'amd_cancel_elementor_redirect', }; $.post( amd_localize.ajax_url, elementorRedirect, function( response ) { console.log('Am Demo Importer Installed'); setTimeout(function() { $self.html('Redirecting to Am Demo Importer page '); setTimeout( function() { window.location = $href; }, 1000 ); }, 500); }); } }); } } ).fail( function( xhr, textStatus, e ) { $(this).parent().after( `