forked from Automattic/developer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeveloper.js
155 lines (133 loc) · 4 KB
/
developer.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
function a8c_developer_lightbox() {
(function($){
function make_colorbox( href, transition ) {
$.colorbox({
inline: true,
href: href,
title: a8c_developer_i18n.lightbox_title,
innerWidth: 500,
maxHeight: '100%',
transition: transition
});
}
make_colorbox( '#a8c-developer-setup-dialog-step-1', 'none' );
$('#a8c-developer-setup-dialog-step-1-form').submit( function(e) {
var form = this;
$('#a8c-developer-setup-dialog-step-1-submit').val( a8c_developer_i18n.saving );
if ( 'yes' != a8c_developer_i18n.go_to_step_2 )
return;
e.preventDefault();
$.post( ajaxurl, $(form).serialize() )
.success( function( result ) {
// If there was an error with the AJAX save, then do a normal POST
if ( '-1' == result ) {
location.href = 'options-general.php?page=' + a8c_developer_i18n.settings_slug + '&a8cdev_errorsaving=1';
return;
}
// AJAX says no step 2 needed, so head to the settings page
if ( 'redirect' == result ) {
location.href = 'options-general.php?page=' + a8c_developer_i18n.settings_slug + '&updated=1';
return;
}
// Display the AJAX reponse
$('#a8c-developer-setup-dialog-step-2').html( result );
make_colorbox( '#a8c-developer-setup-dialog-step-2' );
})
;
});
})(jQuery);
}
function a8c_developer_bind_events() {
(function($){
$('.a8c-developer-button-install').click( function() {
var button = this;
$(button).html( a8c_developer_i18n.installing );
$.post( ajaxurl, {
'action': 'a8c_developer_install_plugin',
'_ajax_nonce': $(button).attr('data-nonce'),
'plugin_slug': $(button).attr('data-pluginslug')
} )
.success( function( result ) {
if ( '1' === result ) {
$(button).html( a8c_developer_i18n.installed );
$(button).unbind('click').prop('disabled', true);
} else {
alert( result );
$(button).html( a8c_developer_i18n.error );
}
})
.error( function() {
$(button).html( a8c_developer_i18n.error );
})
;
});
$('.a8c-developer-button-activate').click( function() {
var button = this;
$(button).html( a8c_developer_i18n.activating );
$.post( ajaxurl, {
'action': 'a8c_developer_activate_plugin',
'_ajax_nonce': $(button).attr('data-nonce'),
'path': $(button).attr('data-path')
} )
.success( function( result ) {
if ( '1' === result ) {
$(button).html( a8c_developer_i18n.activated );
$(button).unbind('click').prop('disabled', true);
} else {
alert( result );
$(button).html( a8c_developer_i18n.error );
}
})
.error( function() {
$(button).html( a8c_developer_i18n.error );
})
;
});
})(jQuery);
}
function a8c_developer_bind_settings_events() {
(function($){
$('.a8c-developer-button-install').click( function() {
var button = this;
$(button).html( a8c_developer_i18n.installing );
$.post( ajaxurl, {
'action': 'a8c_developer_install_plugin',
'_ajax_nonce': $(button).attr('data-nonce'),
'plugin_slug': $(button).attr('data-pluginslug')
} )
.success( function( result ) {
if ( '1' == result ) {
$(button).html( a8c_developer_i18n.INSTALLED );
} else {
$(button).html( a8c_developer_i18n.ERROR );
}
})
.error( function() {
$(button).html( a8c_developer_i18n.ERROR );
})
;
return false;
});
$('.a8c-developer-button-activate').click( function() {
var button = this;
$(button).html( a8c_developer_i18n.activating );
$.post( ajaxurl, {
'action': 'a8c_developer_activate_plugin',
'_ajax_nonce': $(button).attr('data-nonce'),
'path': $(button).attr('data-path')
} )
.success( function( result ) {
if ( '1' == result ) {
$(button).replaceWith("<span class='a8c-developer-active'>" + a8c_developer_i18n.ACTIVE + "</span>");
} else {
$(button).html( a8c_developer_i18n.ERROR );
}
})
.error( function() {
$(button).html( a8c_developer_i18n.ERROR );
})
;
return false;
});
})(jQuery);
}