PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.16.5
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.16.5
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / assets / js / jquery-pb-add-ons.js

jquery-pb-add-ons.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.16.5, at assets/js/jquery-pb-add-ons.js

237 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 /*
3 * Function to download/activate add-ons on button click
4 */
5 jQuery('.wppb-add-on .button').on( 'click', function(e) {
6 if( jQuery(this).attr('disabled') ) {
7 return false;
8 }
9
10 // Activate add-on
11 if( jQuery(this).hasClass('wppb-add-on-activate') ) {
12 e.preventDefault();
13 wppb_add_on_activate( jQuery(this) );
14 }
15
16 // Deactivate add-on
17 if( jQuery(this).hasClass('wppb-add-on-deactivate') ) {
18 e.preventDefault();
19 wppb_add_on_deactivate( jQuery(this) );
20 }
21 });
22
23
24 /*
25 * Make deactivate button from Add-On is Active message button
26 */
27 jQuery('.wppb-add-on').on( 'mouseenter mouseleave', function() {
28
29 $button = jQuery(this).find('.wppb-add-on-deactivate');
30
31 if( $button.length > 0 ) {
32 $button
33 .animate({
34 opacity: 1
35 }, 100);
36 }
37 });
38
39 /*
40 * Make Add-On is Active message button from deactivate button
41 */
42 jQuery('.wppb-add-on').on( 'mouseleave', function() {
43
44 $button = jQuery(this).find('.wppb-add-on-deactivate');
45
46 if( $button.length > 0 ) {
47 $button
48 .animate({
49 opacity: 0
50 }, 100);
51 }
52 });
53
54
55 /*
56 * Function that activates the add-on
57 */
58 function wppb_add_on_activate( $button ) {
59 $activate_button = $button;
60
61 var fade_in_out_speed = 300;
62 var plugin = $activate_button.attr('href');
63 var add_on_index = $activate_button.parents('.wppb-add-on').index('.wppb-add-on');
64 var nonce = $activate_button.data('nonce');
65
66 $activate_button
67 .attr('disabled', true);
68
69 $spinner = $activate_button.siblings('.spinner');
70
71 $spinner.animate({
72 opacity: 0.7
73 }, 100);
74
75 // Remove the current displayed message
76 wppb_add_on_remove_status_message( $activate_button, fade_in_out_speed);
77
78 jQuery.post( ajaxurl, { action: 'wppb_add_on_activate', wppb_add_on_to_activate: plugin, wppb_add_on_index: add_on_index, nonce: nonce }, function( response ) {
79
80 add_on_index = response;
81
82 $activate_button = jQuery('.wppb-add-on').eq( add_on_index ).find('.button');
83
84 $activate_button
85 .blur()
86 .removeClass('wppb-add-on-activate button-primary')
87 .addClass('wppb-add-on-deactivate button-secondary')
88 .removeAttr('disabled')
89 .text( jQuery('#wppb-add-on-deactivate-button-text').text() );
90
91 $spinner = $activate_button.siblings('.spinner');
92
93 $spinner.animate({
94 opacity: 0
95 }, 0);
96
97 // Set status confirmation message
98 wppb_add_on_set_status_message( $activate_button, 'dashicons-yes', jQuery('#wppb-add-on-activated-message-text').text(), fade_in_out_speed, 0, true );
99 wppb_add_on_remove_status_message( $activate_button, fade_in_out_speed, 2000 );
100
101 // Set is active message
102 wppb_add_on_set_status_message( $activate_button, 'dashicons-yes', jQuery('#wppb-add-on-is-active-message-text').html(), fade_in_out_speed, 2000 + fade_in_out_speed );
103 });
104 }
105
106
107
108 /*
109 * Function that deactivates the add-on
110 */
111 function wppb_add_on_deactivate( $button ) {
112
113 var fade_in_out_speed = 300;
114 var plugin = $button.attr('href');
115 var add_on_index = $button.parents('.wppb-add-on').index('.wppb-add-on');
116 var nonce = $button.data('nonce');
117
118 $button
119 .removeClass('wppb-add-on-deactivate')
120 .attr('disabled', true);
121
122 $spinner = $button.siblings('.spinner');
123
124 $spinner.animate({
125 opacity: 0.7
126 }, 100);
127
128 // Remove the current displayed message
129 wppb_add_on_remove_status_message( $button, fade_in_out_speed );
130
131 jQuery.post( ajaxurl, { action: 'wppb_add_on_deactivate', wppb_add_on_to_deactivate: plugin, wppb_add_on_index: add_on_index, nonce: nonce }, function( response ) {
132
133 add_on_index = response;
134
135 $button = jQuery('.wppb-add-on').eq( add_on_index ).find('.button');
136
137 $button
138 .blur()
139 .removeClass('wppb-add-on-is-active button-secondary')
140 .addClass('wppb-add-on-activate button-primary')
141 .attr( 'disabled', false )
142 .text( jQuery('#wppb-add-on-activate-button-text').text() );
143
144 $spinner = $button.siblings('.spinner');
145
146 $spinner.animate({
147 opacity: 0
148 }, 0);
149
150 // Set status confirmation message
151 wppb_add_on_set_status_message( $button, 'dashicons-yes', jQuery('#wppb-add-on-deactivated-message-text').text(), fade_in_out_speed, 0, true );
152 wppb_add_on_remove_status_message( $button, fade_in_out_speed, 2000 );
153
154 // Set is active message
155 wppb_add_on_set_status_message( $button, 'dashicons-no-alt', jQuery('#wppb-add-on-is-not-active-message-text').html(), fade_in_out_speed, 2000 + fade_in_out_speed );
156
157 });
158 }
159
160
161 /*
162 * Function used to remove the status message of an add-on
163 *
164 * @param object $button - The jQuery object of the add-on box button that was pressed
165 * @param int fade_in_out_speed - The speed of the fade in and out animations
166 * @param int delay - Delay removing of the message
167 *
168 */
169 function wppb_add_on_remove_status_message( $button, fade_in_out_speed, delay ) {
170
171 if( typeof( delay ) == 'undefined' ) {
172 delay = 0;
173 }
174
175 setTimeout( function() {
176
177 $button.siblings('.dashicons')
178 .animate({
179 opacity: 0
180 }, fade_in_out_speed );
181
182 $button.siblings('.wppb-add-on-message')
183 .animate({
184 opacity: 0
185 }, fade_in_out_speed );
186
187 }, delay);
188
189 }
190
191 /*
192 * Function used to remove the status message of an add-on
193 *
194 * @param object $button - The jQuery object of the add-on box button that was pressed
195 * @param string message_icon_class - The string name of the class we want the icon to have
196 * @param string message_text - The text we want the user to see
197 * @param int fade_in_out_speed - The speed of the fade in and out animations
198 * @param bool success - If true adds a class to style the message as a success one, if false adds a class to style the message as a failure
199 *
200 */
201 function wppb_add_on_set_status_message( $button, message_icon_class, message_text, fade_in_out_speed, delay, success ) {
202
203 if( typeof( delay ) == 'undefined' ) {
204 delay = 0;
205 }
206
207 setTimeout(function() {
208
209 $button.siblings('.dashicons')
210 .css('opacity', 0)
211 .attr('class', 'dashicons')
212 .addClass( message_icon_class )
213 .animate({ opacity: 1}, fade_in_out_speed);
214
215 $button.siblings('.wppb-add-on-message')
216 .css('opacity', 0)
217 .attr( 'class', 'wppb-add-on-message' )
218 .html( message_text )
219 .animate({ opacity: 1}, fade_in_out_speed);
220
221 if( typeof( success ) != 'undefined' ) {
222 if( success == true ) {
223 $button.siblings('.dashicons')
224 .addClass('wppb-confirmation-success');
225 $button.siblings('.wppb-add-on-message')
226 .addClass('wppb-confirmation-success');
227 } else if( success == false ) {
228 $button.siblings('.dashicons')
229 .addClass('wppb-confirmation-error');
230 $button.siblings('.wppb-add-on-message')
231 .addClass('wppb-confirmation-error');
232 }
233 }
234
235 }, delay );
236
237 }