deactivation.js
2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Shows the deactivation modal window when the Plugin is deactivated
* through the Plugins screen, giving the user an option to specify
* why they are deactivating.
*
* @package WPZincDashboardWidget
* @author WP Zinc
*/
var wpzinc_deactivation_url;
jQuery( document ).ready(
function( $ ) {
/**
* Show deactivation modal if the user is deactivating our plugin.
*/
$( 'span.deactivate a' ).on(
'click',
function( e ) {
// If the link slug doesn't exist, let the request through.
var plugin_name = $( this ).closest( 'tr' ).data( 'slug' );
if ( typeof plugin_name === 'undefined' ) {
return true;
}
// If the Plugin being deactivated isn't our one, let the request through.
if ( plugin_name != wpzinc_dashboard.plugin.name ) {
return true;
}
// If here, we're deactivating our plugin.
e.preventDefault();
// Store the target URL.
wpzinc_deactivation_url = $( this ).attr( 'href' );
// Show the modal.
$( '#wpzinc-deactivation-modal, #wpzinc-deactivation-modal-overlay' ).show();
// Resize and position the modal.
$( '#wpzinc-deactivation-modal' ).css( 'margin-top', '-210px' );
$( '#wpzinc-deactivation-modal' ).outerHeight( 420 );
}
);
/**
* Send the result of the deactivation modal when the submit button is clicked,
* and load the deactivation URL so that the plugin gets deactivated.
*/
$( 'form#wpzinc-deactivation-modal-form' ).on(
'submit',
function( e ) {
e.preventDefault();
var wpzinc_dashboard_deactivation_reason = $( 'input[name=reason]:checked', $( this ) ).val(),
wpzinc_dashboard_deactivation_reason_text = $( 'input[name=reason_text]', $( this ) ).val(),
wpzinc_dashboard_deactivation_reason_email = $( 'input[name=reason_email]', $( this ) ).val();
// Submit the form via AJAX if a reason was given.
if ( typeof wpzinc_dashboard_deactivation_reason !== 'undefined' ) {
$.ajax(
{
url: ajaxurl,
type: 'POST',
async: true,
data: {
action: 'wpzinc_dashboard_deactivation_modal_submit',
product: wpzinc_dashboard.plugin.name,
version: wpzinc_dashboard.plugin.version,
reason: wpzinc_dashboard_deactivation_reason,
reason_text: wpzinc_dashboard_deactivation_reason_text,
reason_email: wpzinc_dashboard_deactivation_reason_email
},
error: function( a, b, c ) {
},
success: function( result ) {
}
}
);
}
// Hide the modal.
$( '#wpzinc-deactivation-modal, #wpzinc-deactivation-modal-overlay' ).hide();
// Load the deactivation URL.
window.location.href = wpzinc_deactivation_url;
}
);
}
);