| 1 |
/* global jQuery, WPFunnelCommonJS */ |
| 2 |
( function( $ ) { |
| 3 |
'use strict'; |
| 4 |
var WPFunnelCommonJS = { |
| 5 |
installPlugin: function(e) { |
| 6 |
e.preventDefault(); |
| 7 |
$('.wpfnl-notice .wpfnl-notice-button .notice-loader').css('display', 'inline-block'); |
| 8 |
|
| 9 |
let slug = $(this).attr('data-slug'); |
| 10 |
wp.updates.queue.push( { |
| 11 |
action: 'install-plugin', // Required action. |
| 12 |
data: { |
| 13 |
slug: slug, |
| 14 |
}, |
| 15 |
} ); |
| 16 |
wp.updates.queueChecker(); |
| 17 |
}, |
| 18 |
|
| 19 |
installSuccess: function(e, response) { |
| 20 |
e.preventDefault(); |
| 21 |
var pluginFile = 'woocommerce/woocommerce.php'; |
| 22 |
$.ajax( { |
| 23 |
url: window.wpfnl_common_vars.ajaxurl, |
| 24 |
type: 'POST', |
| 25 |
data: { |
| 26 |
action : 'plugin_install_success', |
| 27 |
plugin_init : pluginFile, |
| 28 |
security : window.wpfnl_common_vars.wpfnl_activate_plugin_nonce, |
| 29 |
}, |
| 30 |
success: function(response) { |
| 31 |
if(response.success) { |
| 32 |
window.location.reload(); |
| 33 |
} |
| 34 |
} |
| 35 |
}).done( function ( request, status, XHR ) { |
| 36 |
if(status.success) { |
| 37 |
window.location.reload(); |
| 38 |
} |
| 39 |
}); |
| 40 |
}, |
| 41 |
|
| 42 |
installError: function(e, response) { |
| 43 |
e.preventDefault(); |
| 44 |
$('.wpfnl-notice-message').html(response.errorMessage); |
| 45 |
$('.wpfnl-notice .wpfnl-notice-button .notice-loader').css('display', 'none'); |
| 46 |
}, |
| 47 |
|
| 48 |
activatePlugin: function(e) { |
| 49 |
e.preventDefault(); |
| 50 |
var pluginFile = 'woocommerce/woocommerce.php'; |
| 51 |
$.ajax( { |
| 52 |
url: window.wpfnl_common_vars.ajaxurl, |
| 53 |
type: 'POST', |
| 54 |
data: { |
| 55 |
action : 'plugin_install_success', |
| 56 |
plugin_init : pluginFile, |
| 57 |
security : window.wpfnl_common_vars.wpfnl_activate_plugin_nonce, |
| 58 |
}, |
| 59 |
success: function(response) { |
| 60 |
if(response.success) { |
| 61 |
window.location.reload(); |
| 62 |
} |
| 63 |
} |
| 64 |
}).done( function ( request, status, XHR ) { |
| 65 |
if(status.data.success) { |
| 66 |
window.location.reload(); |
| 67 |
} |
| 68 |
}); |
| 69 |
}, |
| 70 |
|
| 71 |
init: function() { |
| 72 |
$(document) |
| 73 |
.on('click', '#wpfnl-install-plugin', this.installPlugin) |
| 74 |
.on('click', '#wpfnl-activate-plugin', this.activatePlugin) |
| 75 |
.on('wp-plugin-install-success', this.installSuccess) |
| 76 |
.on('wp-plugin-install-error', this.installError) |
| 77 |
}, |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
$( function() { |
| 82 |
WPFunnelCommonJS.init(); |
| 83 |
} ); |
| 84 |
|
| 85 |
}( jQuery ) ); |
| 86 |
|