PluginProbe
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder / 3.6.0
Buttonizer – Floating Menus, Sticky Buttons, & Popup Builder v3.6.0
3.6.0 3.5.0 trunk 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.6.1 1.0.7 1.0.8 1.0.9 1.1 1.1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5 1.5.1 All 110 releases
← All changes | freemius/templates/forms/deactivation/form.php +387 -130 1.4.53.6.0 View file →
@@ -9,72 +9,126 @@
9 9 if ( ! defined( 'ABSPATH' ) ) {
10 10 exit;
11 11 }
12 12
13 + /**
14 + * @var array $VARS
15 + */
13 16 $fs = freemius( $VARS['id'] );
14 17 $slug = $fs->get_slug();
15 18
16 - $confirmation_message = $fs->apply_filters( 'uninstall_confirmation_message', '' );
19 + $subscription_cancellation_dialog_box_template_params = $VARS['subscription_cancellation_dialog_box_template_params'];
20 + $show_deactivation_feedback_form = $VARS['show_deactivation_feedback_form'];
21 + $confirmation_message = $VARS['uninstall_confirmation_message'];
17 22
18 - $reasons = $VARS['reasons'];
23 + $is_anonymous = ( ! $fs->is_registered() );
24 + $anonymous_feedback_checkbox_html = '';
19 25
20 - $reasons_list_items_html = '';
26 + $reasons_list_items_html = '';
27 + $snooze_select_html = '';
21 28
22 - foreach ( $reasons as $reason ) {
23 - $list_item_classes = 'reason' . ( ! empty( $reason['input_type'] ) ? ' has-input' : '' );
29 + if ( $show_deactivation_feedback_form ) {
30 + $reasons = $VARS['reasons'];
24 31
25 - if ( isset( $reason['internal_message'] ) && ! empty( $reason['internal_message'] ) ) {
26 - $list_item_classes .= ' has-internal-message';
27 - $reason_internal_message = $reason['internal_message'];
28 - } else {
29 - $reason_internal_message = '';
30 - }
31 -
32 - $reason_input_type = ( ! empty( $reason['input_type'] ) ? $reason['input_type'] : '' );
33 - $reason_input_placeholder = ( ! empty( $reason['input_placeholder'] ) ? $reason['input_placeholder'] : '' );
34 -
35 - $reason_list_item_html = <<< HTML
36 - <li class="{$list_item_classes}"
37 - data-input-type="{$reason_input_type}"
38 - data-input-placeholder="{$reason_input_placeholder}">
39 - <label>
40 - <span>
41 - <input type="radio" name="selected-reason" value="{$reason['id']}"/>
42 - </span>
43 - <span>{$reason['text']}</span>
44 - </label>
45 - <div class="internal-message">{$reason_internal_message}</div>
46 - </li>
32 + foreach ( $reasons as $reason ) {
33 + $list_item_classes = 'reason' . ( ! empty( $reason['input_type'] ) ? ' has-input' : '' );
34 +
35 + if ( isset( $reason['internal_message'] ) && ! empty( $reason['internal_message'] ) ) {
36 + $list_item_classes .= ' has-internal-message';
37 + $reason_internal_message = $reason['internal_message'];
38 + } else {
39 + $reason_internal_message = '';
40 + }
41 +
42 + $reason_input_type = ( ! empty( $reason['input_type'] ) ? $reason['input_type'] : '' );
43 + $reason_input_placeholder = ( ! empty( $reason['input_placeholder'] ) ? $reason['input_placeholder'] : '' );
44 +
45 + $reason_list_item_html = <<< HTML
46 + <li class="{$list_item_classes}"
47 + data-input-type="{$reason_input_type}"
48 + data-input-placeholder="{$reason_input_placeholder}">
49 + <label>
50 + <span>
51 + <input type="radio" name="selected-reason" value="{$reason['id']}"/>
52 + </span>
53 + <span>{$reason['text']}</span>
54 + </label>
55 + <div class="internal-message">{$reason_internal_message}</div>
56 + </li>
47 57 HTML;
48 58
49 - $reasons_list_items_html .= $reason_list_item_html;
50 - }
59 + $reasons_list_items_html .= $reason_list_item_html;
60 + }
51 61
52 - $is_anonymous = ( ! $fs->is_registered() );
53 - if ( $is_anonymous ) {
54 - $anonymous_feedback_checkbox_html = sprintf(
55 - '<label class="anonymous-feedback-label"><input type="checkbox" class="anonymous-feedback-checkbox"> %s</label>',
56 - fs_esc_html_inline( 'Anonymous feedback', 'anonymous-feedback', $slug )
57 - );
58 - } else {
59 - $anonymous_feedback_checkbox_html = '';
60 - }
62 + if ( $is_anonymous ) {
63 + $anonymous_feedback_checkbox_html = sprintf(
64 + '<label class="anonymous-feedback-label"><input type="checkbox" class="anonymous-feedback-checkbox"> %s</label>',
65 + fs_esc_html_inline( 'Anonymous feedback', 'anonymous-feedback', $slug )
66 + );
67 + }
61 68
69 + $snooze_periods = array(
70 + array(
71 + 'increment' => fs_text_inline( 'hour', $slug ),
72 + 'quantity' => number_format_i18n(1),
73 + 'value' => 6 * WP_FS__TIME_10_MIN_IN_SEC,
74 + ),
75 + array(
76 + 'increment' => fs_text_inline( 'hours', $slug ),
77 + 'quantity' => number_format_i18n(24),
78 + 'value' => WP_FS__TIME_24_HOURS_IN_SEC,
79 + ),
80 + array(
81 + 'increment' => fs_text_inline( 'days', $slug ),
82 + 'quantity' => number_format_i18n(7),
83 + 'value' => WP_FS__TIME_WEEK_IN_SEC,
84 + ),
85 + array(
86 + 'increment' => fs_text_inline( 'days', $slug ),
87 + 'quantity' => number_format_i18n(30),
88 + 'value' => 30 * WP_FS__TIME_24_HOURS_IN_SEC,
89 + ),
90 + );
91 +
92 + $snooze_select_html = '<select>';
93 + foreach ($snooze_periods as $period) {
94 + $snooze_select_html .= sprintf(
95 + '<option value="%s">%s %s</option>',
96 + $period['value'],
97 + $period['quantity'],
98 + $period['increment']
99 + );
100 + }
101 +
102 + $snooze_select_html .= '</select>';
103 + }
104 +
62 105 // Aliases.
63 106 $deactivate_text = fs_text_inline( 'Deactivate', 'deactivate', $slug );
64 107 $theme_text = fs_text_inline( 'Theme', 'theme', $slug );
65 108 $activate_x_text = fs_text_inline( 'Activate %s', 'activate-x', $slug );
66 109
110 + $submit_deactivate_text = sprintf(
111 + fs_text_inline( 'Submit & %s', 'deactivation-modal-button-submit', $slug ),
112 + $fs->is_plugin() ?
113 + $deactivate_text :
114 + sprintf( $activate_x_text, $theme_text )
115 + );
116 +
67 117 fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' );
118 +
119 + if ( ! empty( $subscription_cancellation_dialog_box_template_params ) ) {
120 + fs_require_template( 'forms/subscription-cancellation.php', $subscription_cancellation_dialog_box_template_params );
121 + }
68 122 ?>
69 123 <script type="text/javascript">
70 124 (function ($) {
71 - var reasonsHtml = <?php echo json_encode( $reasons_list_items_html ); ?>,
72 - modalHtml =
125 + var reasonsHtml = <?php echo json_encode( $reasons_list_items_html ) ?>,
126 + modalHtml =
73 127 '<div class="fs-modal fs-modal-deactivation-feedback<?php echo empty( $confirmation_message ) ? ' no-confirmation-message' : ''; ?>">'
74 128 + ' <div class="fs-modal-dialog">'
75 129 + ' <div class="fs-modal-header">'
76 - + ' <h4><?php fs_esc_attr_echo_inline( 'Quick feedback', 'quick-feedback' , $slug ) ?></h4>'
130 + + ' <h4><?php fs_esc_attr_echo_inline( 'Quick Feedback', 'quick-feedback' , $slug ) ?></h4>'
77 131 + ' </div>'
78 132 + ' <div class="fs-modal-body">'
79 133 + ' <div class="fs-modal-panel" data-panel-id="confirm"><p><?php echo $confirmation_message; ?></p></div>'
80 134 + ' <div class="fs-modal-panel active" data-panel-id="reasons"><h3><strong><?php echo esc_js( sprintf( fs_text_inline( 'If you have a moment, please let us know why you are %s', 'deactivation-share-reason' , $slug ), ( $fs->is_plugin() ? fs_text_inline( 'deactivating', 'deactivating', $slug ) : fs_text_inline( 'switching', 'switching', $slug ) ) ) ) ?>:</strong></h3><ul id="reasons-list">' + reasonsHtml + '</ul></div>'
@@ -80,37 +134,117 @@
80 134 + ' <div class="fs-modal-panel active" data-panel-id="reasons"><h3><strong><?php echo esc_js( sprintf( fs_text_inline( 'If you have a moment, please let us know why you are %s', 'deactivation-share-reason' , $slug ), ( $fs->is_plugin() ? fs_text_inline( 'deactivating', 'deactivating', $slug ) : fs_text_inline( 'switching', 'switching', $slug ) ) ) ) ?>:</strong></h3><ul id="reasons-list">' + reasonsHtml + '</ul></div>'
81 135 + ' </div>'
82 136 + ' <div class="fs-modal-footer">'
83 137 + ' <?php echo $anonymous_feedback_checkbox_html ?>'
138 + + ' <label style="display: none" class="feedback-from-snooze-label"><input type="checkbox" class="feedback-from-snooze-checkbox"> <span><?php fs_esc_js_echo_inline( 'Snooze this panel during troubleshooting', 'snooze-panel-during-troubleshooting', $slug ) ?></span><span style="display: none"><?php fs_esc_js_echo_inline( 'Snooze this panel for', 'snooze-panel-for', $slug ) ?> <?php echo $snooze_select_html ?></span></label>'
84 139 + ' <a href="#" class="button button-secondary button-deactivate"></a>'
85 - + ' <a href="#" class="button button-primary button-close"><?php fs_esc_js_echo_inline( 'Cancel', 'cancel' , $slug ) ?></a>'
140 + + ' <a href="#" class="button button-secondary button-close"><?php fs_esc_js_echo_inline( 'Cancel', 'cancel', $slug ) ?></a>'
86 141 + ' </div>'
87 142 + ' </div>'
88 143 + '</div>',
89 - $modal = $(modalHtml),
90 - $deactivateLink = $('#the-list .deactivate > [data-module-id=<?php echo $fs->get_id() ?>].fs-module-id').prev(),
91 - selectedReasonID = false,
92 - redirectLink = '',
93 - $anonymousFeedback = $modal.find( '.anonymous-feedback-label' ),
94 - isAnonymous = <?php echo ( $is_anonymous ? 'true' : 'false' ); ?>,
95 - otherReasonID = <?php echo Freemius::REASON_OTHER; ?>,
96 - dontShareDataReasonID = <?php echo Freemius::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION; ?>;
144 + $modal = $(modalHtml),
145 + selectedReasonID = false,
146 + redirectLink = '',
147 + $anonymousFeedback = $modal.find( '.anonymous-feedback-label' ),
148 + $feedbackSnooze = $modal.find( '.feedback-from-snooze-label' ),
149 + isAnonymous = <?php echo ( $is_anonymous ? 'true' : 'false' ); ?>,
150 + otherReasonID = <?php echo Freemius::REASON_OTHER; ?>,
151 + dontShareDataReasonID = <?php echo Freemius::REASON_DONT_LIKE_TO_SHARE_MY_INFORMATION; ?>,
152 + deleteThemeUpdateData = <?php echo $fs->is_theme() && $fs->is_premium() && ! $fs->has_any_active_valid_license() ? 'true' : 'false' ?>,
153 + $subscriptionCancellationModal = $( '.fs-modal-subscription-cancellation-<?php echo $fs->get_id() ?>' ),
154 + showDeactivationFeedbackForm = <?php echo ( $show_deactivation_feedback_form ? 'true' : 'false' ) ?>,
155 + $body = $( 'body' );
97 156
98 - $modal.appendTo($('body'));
157 + $modal.appendTo( $body );
99 158
159 + if ( 0 !== $subscriptionCancellationModal.length ) {
160 + $subscriptionCancellationModal.on( '<?php echo $fs->get_action_tag( 'subscription_cancellation_action' ) ?>', function( evt, cancelSubscription ) {
161 + var shouldDeactivateModule = ( $modal.hasClass( 'no-confirmation-message' ) && ! showDeactivationFeedbackForm );
162 +
163 + if ( false === cancelSubscription ) {
164 + if ( ! shouldDeactivateModule ) {
165 + showModal();
166 + }
167 +
168 + $subscriptionCancellationModal.trigger( 'closeModal' );
169 +
170 + if ( shouldDeactivateModule ) {
171 + deactivateModule();
172 + }
173 + } else {
174 + var $errorMessage = $subscriptionCancellationModal.find( '.notice-error' );
175 +
176 + <?php
177 + $subscription_cancellation_context = $fs->is_paid_trial() ?
178 + fs_text_inline( 'trial', 'trial', $slug ) :
179 + fs_text_inline( 'subscription', 'subscription', $slug );
180 + ?>
181 +
182 + $.ajax({
183 + url : <?php echo Freemius::ajax_url() ?>,
184 + method : 'POST',
185 + data : {
186 + action : '<?php echo $fs->get_ajax_action( 'cancel_subscription_or_trial' ) ?>',
187 + security : '<?php echo $fs->get_ajax_security( 'cancel_subscription_or_trial' ) ?>',
188 + module_id: '<?php echo $fs->get_id() ?>'
189 + },
190 + beforeSend: function() {
191 + $errorMessage.hide();
192 +
193 + $subscriptionCancellationModal.find( '.fs-modal-footer .button' ).addClass( 'disabled' );
194 + $subscriptionCancellationModal.find( '.fs-modal-footer .button-primary' ).text( '<?php echo esc_js(
195 + sprintf( fs_text_inline( 'Cancelling %s...', 'cancelling-x' , $slug ), $subscription_cancellation_context )
196 + ) ?>' );
197 + },
198 + success: function( result ) {
199 + if ( result.success ) {
200 + $subscriptionCancellationModal.removeClass( 'has-subscription-actions' );
201 + $subscriptionCancellationModal.find( '.fs-modal-footer .button-primary' ).removeClass( 'warn' );
202 +
203 + $subscriptionCancellationModal.remove();
204 +
205 + if ( ! shouldDeactivateModule ) {
206 + showModal();
207 + } else {
208 + deactivateModule();
209 + }
210 + } else {
211 + $errorMessage.find( '> p' ).html( result.error );
212 + $errorMessage.show();
213 +
214 + $subscriptionCancellationModal.find( '.fs-modal-footer .button' ).removeClass( 'disabled' );
215 + $subscriptionCancellationModal.find( '.fs-modal-footer .button-primary' ).html( <?php echo json_encode( sprintf(
216 + fs_text_inline( 'Cancel %s & Proceed', 'cancel-x-and-proceed', $slug ),
217 + ucfirst( $subscription_cancellation_context )
218 + ) ) ?> );
219 + }
220 + }
221 + });
222 + }
223 + });
224 + }
225 +
100 226 registerEventHandlers();
101 227
102 228 function registerEventHandlers() {
103 - <?php
104 - if ( $fs->is_plugin() ) { ?>
105 - $deactivateLink.click(function (evt) {
229 + $body.on( 'click', '#the-list .deactivate > a', function ( evt ) {
230 + if ( 0 === $( this ).next( '[data-module-id=<?php echo $fs->get_id() ?>].fs-module-id' ).length ) {
231 + return true;
232 + }
233 +
106 234 evt.preventDefault();
107 235
108 - redirectLink = $(this).attr('href');
236 + redirectLink = $(this).attr('href');
109 237
110 - showModal();
238 + if ( 0 == $subscriptionCancellationModal.length ) {
239 + showModal();
240 + } else {
241 + $subscriptionCancellationModal.trigger( 'showModal' );
242 + }
111 243 });
244 +
112 245 <?php
246 + if ( ! $fs->is_plugin() ) {
113 247 /**
114 248 * For "theme" module type, the modal is shown when the current user clicks on
115 249 * the "Activate" button of any other theme. The "Activate" button is actually
116 250 * a link to the "Themes" page (/wp-admin/themes.php) containing query params
@@ -120,24 +254,28 @@
120 254 * @since 1.2.2
121 255 *
122 256 * @since 1.2.2.7 Don't trigger the deactivation feedback form if activating the premium version of the theme.
123 257 */
124 - } else { ?>
125 - $('body').on('click', '.theme-browser .theme:not([data-slug=<?php echo $slug ?>-premium]) .theme-actions .button.activate', function (evt) {
258 + ?>
259 + $('body').on('click', '.theme-browser .theme:not([data-slug=<?php echo $fs->get_premium_slug() ?>]) .theme-actions .button.activate', function (evt) {
126 260 evt.preventDefault();
127 261
128 262 redirectLink = $(this).attr('href');
129 263
130 - showModal();
264 + if ( 0 != $subscriptionCancellationModal.length ) {
265 + $subscriptionCancellationModal.trigger( 'showModal' );
266 + } else {
267 + if ( $modal.hasClass( 'no-confirmation-message' ) && ! showDeactivationFeedbackForm ) {
268 + deactivateModule();
269 + } else {
270 + showModal();
271 + }
272 + }
131 273 });
132 274 <?php
133 275 } ?>
134 276
135 277 $modal.on('input propertychange', '.reason-input input', function () {
136 - if (!isOtherReasonSelected()) {
137 - return;
138 - }
139 -
140 278 var reason = $(this).val().trim();
141 279
142 280 /**
143 281 * If reason is not empty, remove the error-message class of the message container
@@ -143,11 +281,14 @@
143 281 * If reason is not empty, remove the error-message class of the message container
144 282 * to change the message color back to default.
145 283 */
146 284 if (reason.length > 0) {
147 - $('.message').removeClass('error-message');
148 - enableDeactivateButton();
149 - }
285 + $('.message').removeClass('error-message');
286 + }
287 +
288 + toggleDeactivationButtonPrimary( reason.length > 0 );
289 +
290 + changeDeactivateButtonText();
150 291 });
151 292
152 293 $modal.on('blur', '.reason-input input', function () {
153 294 var $userReason = $(this);
@@ -162,10 +303,10 @@
162 303 * to change the message color to red.
163 304 */
164 305 if (0 === $userReason.val().trim().length) {
165 306 $('.message').addClass('error-message');
166 - disableDeactivateButton();
167 - }
307 + changeDeactivateButtonText();
308 + }
168 309 }, 150);
169 310 });
170 311
171 312 $modal.on('click', '.fs-modal-footer .button', function (evt) {
@@ -178,38 +319,75 @@
178 319 var _parent = $(this).parents('.fs-modal:first');
179 320 var _this = $(this);
180 321
181 322 if (_this.hasClass('allow-deactivate')) {
182 - var $radio = $('input[type="radio"]:checked');
323 + var
324 + $radio = $modal.find('input[type="radio"]:checked'),
325 + isReasonSelected = (0 < $radio.length),
326 + userReason = '';
183 327
184 - if (0 === $radio.length) {
185 - // If no selected reason, just deactivate the plugin.
186 - window.location.href = redirectLink;
328 + if ( isReasonSelected ) {
329 + var $selectedReason = $radio.parents('li:first'),
330 + $reasonInput = $selectedReason.find('textarea, input[type="text"]');
331 +
332 + if ( 0 < $reasonInput.length ) {
333 + userReason = $reasonInput.val().trim();
334 + }
335 + }
336 +
337 + if ( otherReasonID == selectedReasonID && '' === userReason ) {
338 + // If the 'Other' is selected and a reason is not provided (aka it's empty), treat it as if a reason wasn't selected at all.
339 + isReasonSelected = false;
340 + }
341 +
342 + _parent.find( '.fs-modal-footer .button' ).addClass( 'disabled' );
343 +
344 + if ( ! isReasonSelected ) {
345 + if ( ! deleteThemeUpdateData ) {
346 + // If no selected reason, just deactivate the plugin.
347 + window.location.href = redirectLink;
348 + } else {
349 + $.ajax({
350 + url : <?php echo Freemius::ajax_url() ?>,
351 + method : 'POST',
352 + data : {
353 + action : '<?php echo $fs->get_ajax_action( 'delete_theme_update_data' ) ?>',
354 + security : '<?php echo $fs->get_ajax_security( 'delete_theme_update_data' ) ?>',
355 + module_id: '<?php echo $fs->get_id() ?>'
356 + },
357 + beforeSend: function() {
358 + _parent.find( '.fs-modal-footer .button-deactivate' ).text( '<?php echo esc_js( fs_text_inline( 'Processing', 'processing', $slug ) ) ?>...' );
359 + },
360 + complete : function() {
361 + window.location.href = redirectLink;
362 + }
363 + });
364 + }
365 +
187 366 return;
188 367 }
189 368
190 - var $selected_reason = $radio.parents('li:first'),
191 - $input = $selected_reason.find('textarea, input[type="text"]'),
192 - userReason = ( 0 !== $input.length ) ? $input.val().trim() : '';
369 + var snoozePeriod = 0,
370 + shouldSnooze = $feedbackSnooze.find( '.feedback-from-snooze-checkbox' ).is( ':checked' );
193 371
194 - if (isOtherReasonSelected() && ( '' === userReason )) {
195 - return;
196 - }
372 + if ( shouldSnooze && <?php echo Freemius::REASON_TEMPORARY_DEACTIVATION ?> == selectedReasonID ) {
373 + snoozePeriod = parseInt($feedbackSnooze.find('select').val(), 10);
374 + }
197 375
198 376 $.ajax({
199 - url : ajaxurl,
377 + url : <?php echo Freemius::ajax_url() ?>,
200 378 method : 'POST',
201 379 data : {
202 - action : '<?php echo $fs->get_ajax_action( 'submit_uninstall_reason' ) ?>',
203 - security : '<?php echo $fs->get_ajax_security( 'submit_uninstall_reason' ) ?>',
204 - module_id : '<?php echo $fs->get_id() ?>',
205 - reason_id : $radio.val(),
206 - reason_info : userReason,
207 - is_anonymous: isAnonymousFeedback()
380 + action : '<?php echo $fs->get_ajax_action( 'submit_uninstall_reason' ) ?>',
381 + security : '<?php echo $fs->get_ajax_security( 'submit_uninstall_reason' ) ?>',
382 + module_id : '<?php echo $fs->get_id() ?>',
383 + reason_id : $radio.val(),
384 + reason_info : userReason,
385 + is_anonymous : isAnonymousFeedback(),
386 + snooze_period: snoozePeriod
208 387 },
209 388 beforeSend: function () {
210 - _parent.find('.fs-modal-footer .button').addClass('disabled');
211 - _parent.find('.fs-modal-footer .button-secondary').text('Processing...');
389 + _parent.find('.fs-modal-footer .button-deactivate').text('<?php echo esc_js( fs_text_inline( 'Processing', 'processing', $slug ) ) ?>...');
212 390 },
213 391 complete : function () {
214 392 // Do not show the dialog box, deactivate the plugin.
215 393 window.location.href = redirectLink;
@@ -218,14 +396,18 @@
218 396 } else if (_this.hasClass('button-deactivate')) {
219 397 // Change the Deactivate button's text and show the reasons panel.
220 398 _parent.find('.button-deactivate').addClass('allow-deactivate');
221 399
222 - showPanel('reasons');
400 + if ( showDeactivationFeedbackForm ) {
401 + showPanel('reasons');
402 + } else {
403 + deactivateModule();
404 + }
223 405 }
224 406 });
225 407
226 408 $modal.on('click', 'input[type="radio"]', function () {
227 - var $selectedReasonOption = $(this);
409 + var $selectedReasonOption = $( this );
228 410
229 411 // If the selection has not changed, do not proceed.
230 412 if (selectedReasonID === $selectedReasonOption.val())
231 413 return;
@@ -243,25 +425,22 @@
243 425 var _parent = $(this).parents('li:first');
244 426
245 427 $modal.find('.reason-input').remove();
246 428 $modal.find( '.internal-message' ).hide();
247 - $modal.find('.button-deactivate').html('<?php echo esc_js( sprintf(
248 - fs_text_inline( 'Submit & %s', 'deactivation-modal-button-submit' , $slug ),
249 - $fs->is_plugin() ?
250 - $deactivate_text :
251 - sprintf( $activate_x_text, $theme_text )
252 - ) ) ?>');
429 + $modal.find('.button-deactivate').html('<?php echo esc_js( $submit_deactivate_text ) ?>');
253 430
254 - enableDeactivateButton();
255 -
256 431 if ( _parent.hasClass( 'has-internal-message' ) ) {
257 432 _parent.find( '.internal-message' ).show();
258 433 }
259 434
260 - if (_parent.hasClass('has-input')) {
435 + if ( ! _parent.hasClass('has-input') ) {
436 + toggleDeactivationButtonPrimary( true );
437 + } else {
438 + toggleDeactivationButtonPrimary( false );
439 +
261 440 var inputType = _parent.data('input-type'),
262 441 inputPlaceholder = _parent.data('input-placeholder'),
263 - reasonInputHtml = '<div class="reason-input"><span class="message"></span>' + ( ( 'textfield' === inputType ) ? '<input type="text" />' : '<textarea rows="5"></textarea>' ) + '</div>';
442 + reasonInputHtml = '<div class="reason-input"><span class="message"></span>' + ( ( 'textfield' === inputType ) ? '<input type="text" maxlength="128" />' : '<textarea rows="5" maxlength="128"></textarea>' ) + '</div>';
264 443
265 444 _parent.append($(reasonInputHtml));
266 445 _parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus();
267 446
@@ -266,13 +445,62 @@
266 445 _parent.find('input, textarea').attr('placeholder', inputPlaceholder).focus();
267 446
268 447 if (isOtherReasonSelected()) {
269 448 showMessage('<?php echo esc_js( fs_text_inline( 'Kindly tell us the reason so we can improve.', 'ask-for-reason-message' , $slug ) ); ?>');
270 - disableDeactivateButton();
271 - }
449 + changeDeactivateButtonText();
450 + }
272 451 }
452 +
453 + $anonymousFeedback.toggle( <?php echo Freemius::REASON_TEMPORARY_DEACTIVATION ?> != selectedReasonID );
454 + $feedbackSnooze.toggle( <?php echo Freemius::REASON_TEMPORARY_DEACTIVATION ?> == selectedReasonID );
455 +
456 + if ( <?php echo Freemius::REASON_TEMPORARY_DEACTIVATION ?> == selectedReasonID ) {
457 + updateDeactivationButtonOnTrouble();
458 + }
273 459 });
274 460
461 + var toggleDeactivationButtonPrimary = function ( isPrimary ) {
462 + if ( isPrimary ) {
463 + $modal.find('.button-deactivate')
464 + .removeClass( 'button-secondary' )
465 + .addClass( 'button-primary' );
466 + } else {
467 + $modal.find('.button-deactivate')
468 + .addClass( 'button-secondary' )
469 + .removeClass( 'button-primary' );
470 + }
471 + };
472 +
473 + var snooze = false;
474 +
475 + var updateDeactivationButtonOnTrouble = function () {
476 + if ( snooze ) {
477 + $modal.find('.button-deactivate').html('<?php echo esc_js( sprintf(
478 + fs_text_inline( 'Snooze & %s', 'snooze-modal-button-submit' , $slug ),
479 + $fs->is_plugin() ?
480 + $deactivate_text :
481 + sprintf( $activate_x_text, $theme_text )
482 + ) ) ?>');
483 + } else {
484 + $modal.find('.button-deactivate').html('<?php echo esc_js(
485 + $fs->is_plugin() ?
486 + $deactivate_text :
487 + sprintf( $activate_x_text, $theme_text )
488 + ) ?>');
489 + }
490 + };
491 +
492 + $feedbackSnooze.on( 'click', 'input', function () {
493 + var $spans = $feedbackSnooze.find( 'span' );
494 +
495 + snooze = ( ! snooze );
496 +
497 + $( $spans[0] ).toggle();
498 + $( $spans[1] ).toggle();
499 +
500 + updateDeactivationButtonOnTrouble();
501 + });
502 +
275 503 // If the user has clicked outside the window, cancel it.
276 504 $modal.on('click', function (evt) {
277 505 var $target = $(evt.target);
278 506
@@ -281,13 +509,17 @@
281 509 return;
282 510 }
283 511
284 512 // If the user has not clicked the close button and the clicked element is inside the modal dialog, just return.
285 - if (!$target.hasClass('button-close') && ( $target.parents('.fs-modal-body').length > 0 || $target.parents('.fs-modal-footer').length > 0 )) {
513 + if (
514 + ! $target.hasClass( 'button-close' ) &&
515 + ( $target.parents( '.fs-modal-body' ).length > 0 || $target.parents( '.fs-modal-footer' ).length > 0 )
516 + ) {
286 517 return;
287 518 }
288 519
289 520 closeModal();
521 +
290 522 return false;
291 523 });
292 524 }
293 525
@@ -327,10 +559,8 @@
327 559
328 560 function resetModal() {
329 561 selectedReasonID = false;
330 562
331 - enableDeactivateButton();
332 -
333 563 // Uncheck all radio buttons.
334 564 $modal.find('input[type="radio"]').prop('checked', false);
335 565
336 566 // Remove all input fields ( textfield, textarea ).
@@ -337,10 +567,10 @@
337 567 $modal.find('.reason-input').remove();
338 568
339 569 $modal.find('.message').hide();
340 570
341 - if ( isAnonymous ) {
342 - $anonymousFeedback.find( 'input' ).prop( 'checked', false );
571 + if ( isAnonymous ) {
572 + $anonymousFeedback.find( 'input' ).prop( 'checked', <?php echo $fs->apply_filters( 'default_to_anonymous_feedback', false ) ? 'true' : 'false' ?> );
343 573
344 574 // Hide, since by default there is no selected reason.
345 575 $anonymousFeedback.hide();
346 576 }
@@ -350,16 +580,16 @@
350 580 /*
351 581 * If the modal dialog has no confirmation message, that is, it has only one panel, then ensure
352 582 * that clicking the deactivate button will actually deactivate the plugin.
353 583 */
354 - if ($modal.hasClass('no-confirmation-message')) {
355 - $deactivateButton.addClass('allow-deactivate');
584 + if ( $modal.hasClass( 'no-confirmation-message' ) ) {
585 + $deactivateButton.addClass( 'allow-deactivate' );
356 586
357 - showPanel('reasons');
587 + showPanel( 'reasons' );
358 588 } else {
359 - $deactivateButton.removeClass('allow-deactivate');
589 + $deactivateButton.removeClass( 'allow-deactivate' );
360 590
361 - showPanel('confirm');
591 + showPanel( 'confirm' );
362 592 }
363 593 }
364 594
365 595 function showMessage(message) {
@@ -365,41 +595,59 @@
365 595 function showMessage(message) {
366 596 $modal.find('.message').text(message).show();
367 597 }
368 598
369 - function enableDeactivateButton() {
370 - $modal.find('.button-deactivate').removeClass('disabled');
371 - }
599 + /**
600 + * @author Xiaheng Chen (@xhchen)
601 + *
602 + * @since 2.4.2
603 + */
604 + function changeDeactivateButtonText() {
605 + if ( ! isOtherReasonSelected()) {
606 + return;
607 + }
372 608
373 - function disableDeactivateButton() {
374 - $modal.find('.button-deactivate').addClass('disabled');
375 - }
609 + var
610 + $userReason = $modal.find('.reason-input input'),
611 + $deactivateButton = $modal.find('.button-deactivate');
376 612
613 + if (0 === $userReason.val().trim().length) {
614 + // If the reason is empty, just change the text to 'Deactivate' (plugin) or 'Activate themeX' (theme).
615 + $deactivateButton.html('<?php echo
616 + $fs->is_plugin() ?
617 + $deactivate_text :
618 + sprintf( $activate_x_text, $theme_text )
619 + ?>');
620 + } else {
621 + $deactivateButton.html('<?php echo esc_js( $submit_deactivate_text ) ?>');
622 + }
623 + }
624 +
377 625 function showPanel(panelType) {
378 - $modal.find('.fs-modal-panel').removeClass('active ');
379 - $modal.find('[data-panel-id="' + panelType + '"]').addClass('active');
626 + $modal.find( '.fs-modal-panel' ).removeClass( 'active' );
627 + $modal.find( '[data-panel-id="' + panelType + '"]' ).addClass( 'active' );
380 628
381 629 updateButtonLabels();
382 630 }
383 631
384 632 function updateButtonLabels() {
385 - var $deactivateButton = $modal.find('.button-deactivate');
633 + var $deactivateButton = $modal.find( '.button-deactivate' );
386 634
387 - // Reset the deactivate button's text.
388 - if ('confirm' === getCurrentPanel()) {
389 - $deactivateButton.text('<?php echo esc_js( sprintf(
390 - fs_text_inline( 'Yes - %s', 'deactivation-modal-button-confirm' , $slug ),
391 - $fs->is_plugin() ?
392 - $deactivate_text :
393 - sprintf( $activate_x_text, $theme_text )
394 - ) ) ?>');
635 + // Reset the deactivate button's text.
636 + if ( 'confirm' === getCurrentPanel() ) {
637 + $deactivateButton.text( <?php echo json_encode( sprintf(
638 + fs_text_inline( 'Yes - %s', 'deactivation-modal-button-confirm', $slug ),
639 + $fs->is_plugin() ?
640 + $deactivate_text :
641 + sprintf( $activate_x_text, $theme_text )
642 + ) ) ?> );
395 643 } else {
396 - $deactivateButton.html('<?php echo esc_js( sprintf(
644 + $deactivateButton.html( <?php echo json_encode( sprintf(
397 645 fs_text_inline('Skip & %s', 'skip-and-x', $slug ),
398 646 $fs->is_plugin() ?
399 647 $deactivate_text :
400 648 sprintf( $activate_x_text, $theme_text )
401 - ) ) ?>');
649 + ) ) ?> );
402 650 }
403 651 }
404 652
405 653 function getCurrentPanel() {
@@ -404,6 +652,15 @@
404 652
405 653 function getCurrentPanel() {
406 654 return $modal.find('.fs-modal-panel.active').attr('data-panel-id');
407 655 }
656 +
657 + /**
658 + * @author Leo Fajardo (@leorw)
659 + *
660 + * @since 2.3.0
661 + */
662 + function deactivateModule() {
663 + window.location.href = redirectLink;
664 + }
408 665 })(jQuery);
409 666 </script>