← All changes
|
inc/freemius/templates/forms/subscription-cancellation.php
+282
-276
4.2.13
→
4.3.17
View file →
| @@ -1,277 +1,283 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * @package Freemius | |
| 4 | - * @copyright Copyright (c) 2015, Freemius, Inc. | |
| 5 | - * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 | |
| 6 | - * @since 2.2.1 | |
| 7 | - */ | |
| 8 | - | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | - exit; | |
| 11 | -} | |
| 12 | - | |
| 13 | -/** | |
| 14 | - * @var array $VARS | |
| 15 | - */ | |
| 16 | -$fs = freemius( $VARS['id'] ); | |
| 17 | -$slug = $fs->get_slug(); | |
| 18 | - | |
| 19 | -/** | |
| 20 | - * @var FS_Plugin_License $license | |
| 21 | - */ | |
| 22 | -$license = $VARS['license']; | |
| 23 | - | |
| 24 | -$has_trial = $VARS['has_trial']; | |
| 25 | - | |
| 26 | -$subscription_cancellation_context = $has_trial ? | |
| 27 | - fs_text_inline( 'trial', 'trial', $slug ) : | |
| 28 | - fs_text_inline( 'subscription', 'subscription', $slug ); | |
| 29 | - | |
| 30 | -$plan = $fs->get_plan(); | |
| 31 | -$module_label = $fs->get_module_label( true ); | |
| 32 | - | |
| 33 | -if ( $VARS['is_license_deactivation'] ) { | |
| 34 | - $subscription_cancellation_text = ''; | |
| 35 | -} else { | |
| 36 | - $subscription_cancellation_text = sprintf( | |
| 37 | - fs_text_inline( | |
| 38 | - "Deactivating or uninstalling the %s will automatically disable the license, which you'll be able to use on another site.", | |
| 39 | - 'deactivation-or-uninstall-message', | |
| 40 | - $slug | |
| 41 | - ), | |
| 42 | - $module_label | |
| 43 | - ) . ' '; | |
| 44 | -} | |
| 45 | - | |
| 46 | - $subscription_cancellation_text .= sprintf( | |
| 47 | - fs_text_inline( | |
| 48 | - 'In case you are NOT planning on using this %s on this site (or any other site) - would you like to cancel the %s as well?', | |
| 49 | - 'cancel-subscription-message', | |
| 50 | - $slug | |
| 51 | - ), | |
| 52 | - ( $VARS['is_license_deactivation'] ? fs_text_inline( 'license', 'license', $slug ) : $module_label ), | |
| 53 | - $subscription_cancellation_context | |
| 54 | -); | |
| 55 | - | |
| 56 | -$cancel_subscription_action_label = sprintf( | |
| 57 | - fs_esc_html_inline( | |
| 58 | - "Cancel %s - I no longer need any security & feature updates, nor support for %s because I'm not planning to use the %s on this, or any other site.", | |
| 59 | - 'cancel-x', | |
| 60 | - $slug | |
| 61 | - ), | |
| 62 | - esc_html( $subscription_cancellation_context ), | |
| 63 | - sprintf( '<strong>%s</strong>', esc_html( $fs->get_plugin_title() ) ), | |
| 64 | - esc_html( $module_label ) | |
| 65 | -); | |
| 66 | - | |
| 67 | -$keep_subscription_active_action_label = esc_html( sprintf( | |
| 68 | - fs_text_inline( | |
| 69 | - "Don't cancel %s - I'm still interested in getting security & feature updates, as well as be able to contact support.", | |
| 70 | - 'dont-cancel-x', | |
| 71 | - $slug | |
| 72 | - ), | |
| 73 | - $subscription_cancellation_context | |
| 74 | -) ); | |
| 75 | - | |
| 76 | -$subscription_cancellation_text = esc_html( $subscription_cancellation_text ); | |
| 77 | - | |
| 78 | -$subscription_cancellation_html = <<< HTML | |
| 79 | - <div class="notice notice-error inline"><p></p></div><p>{$subscription_cancellation_text}</p> | |
| 80 | - <ul class="subscription-actions"> | |
| 81 | - <li> | |
| 82 | - <label> | |
| 83 | - <input type="radio" name="cancel-subscription" value="false"/> | |
| 84 | - <span>{$keep_subscription_active_action_label}</span> | |
| 85 | - </label> | |
| 86 | - </li> | |
| 87 | - <li> | |
| 88 | - <label> | |
| 89 | - <input type="radio" name="cancel-subscription" value="true"/> | |
| 90 | - <span>{$cancel_subscription_action_label}</span> | |
| 91 | - </label> | |
| 92 | - </li> | |
| 93 | - </ul> | |
| 94 | -HTML; | |
| 95 | - | |
| 96 | -$downgrading_plan_text = fs_text_inline( 'Downgrading your plan', 'downgrading-plan', $slug ); | |
| 97 | -$cancelling_subscription_text = fs_text_inline( 'Cancelling the subscription', 'cancelling-subscription', $slug ); | |
| 98 | -/* translators: %1$s: Either 'Downgrading your plan' or 'Cancelling the subscription' */ | |
| 99 | -$downgrade_x_confirm_text = fs_text_inline( '%1$s will immediately stop all future recurring payments and your %2$s plan license will expire in %3$s.', 'downgrade-x-confirm', $slug ); | |
| 100 | -$prices_increase_text = fs_text_inline( 'Please note that we will not be able to grandfather outdated pricing for renewals/new subscriptions after a cancellation. If you choose to renew the subscription manually in the future, after a price increase, which typically occurs once a year, you will be charged the updated price.', 'pricing-increase-warning', $slug ); | |
| 101 | -$after_downgrade_non_blocking_text = fs_text_inline( 'You can still enjoy all %s features but you will not have access to %s security & feature updates, nor support.', 'after-downgrade-non-blocking', $slug ); | |
| 102 | -$after_downgrade_blocking_text = fs_text_inline( 'Once your license expires you can still use the Free version but you will NOT have access to the %s features.', 'after-downgrade-blocking', $slug ); | |
| 103 | -$after_downgrade_blocking_text_premium_only = fs_text_inline( 'Once your license expires you will no longer be able to use the %s, unless you activate it again with a valid premium license.', 'after-downgrade-blocking-premium-only', $slug ); | |
| 104 | - | |
| 105 | -$subscription_cancellation_confirmation_message = $has_trial ? | |
| 106 | - fs_text_inline( 'Cancelling the trial will immediately block access to all premium features. Are you sure?', 'cancel-trial-confirm', $slug ) : | |
| 107 | - sprintf( | |
| 108 | - '%s %s %s %s', | |
| 109 | - sprintf( | |
| 110 | - $downgrade_x_confirm_text, | |
| 111 | - ($fs->is_only_premium() ? $cancelling_subscription_text : $downgrading_plan_text ), | |
| 112 | - $plan->title, | |
| 113 | - human_time_diff( time(), strtotime( $license->expiration ) ) | |
| 114 | - ), | |
| 115 | - ( | |
| 116 | - $license->is_block_features ? | |
| 117 | - ( | |
| 118 | - $fs->is_only_premium() ? | |
| 119 | - sprintf( $after_downgrade_blocking_text_premium_only, $module_label ) : | |
| 120 | - sprintf( $after_downgrade_blocking_text, $plan->title ) | |
| 121 | - ) : | |
| 122 | - sprintf( $after_downgrade_non_blocking_text, $plan->title, $fs->get_module_label( true ) ) | |
| 123 | - ), | |
| 124 | - $prices_increase_text, | |
| 125 | - fs_esc_attr_inline( 'Are you sure you want to proceed?', 'proceed-confirmation', $slug ) | |
| 126 | - ); | |
| 127 | - | |
| 128 | -fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' ); | |
| 129 | -?> | |
| 130 | -<script type="text/javascript"> | |
| 131 | - (function( $ ) { | |
| 132 | - var modalHtml = | |
| 133 | - '<div class="fs-modal fs-modal-subscription-cancellation fs-modal-subscription-cancellation-<?php echo $fs->get_id() ?>">' | |
| 134 | - + ' <div class="fs-modal-dialog">' | |
| 135 | - + ' <div class="fs-modal-header">' | |
| 136 | - + ' <h4><?php echo esc_html( sprintf( fs_text_inline( 'Cancel %s?', 'cancel-x', $slug ), ucfirst( $subscription_cancellation_context ) ) ) ?></h4>' | |
| 137 | - + ' </div>' | |
| 138 | - + ' <div class="fs-modal-body">' | |
| 139 | - + ' <div class="fs-modal-panel active">' + <?php echo json_encode( $subscription_cancellation_html ) ?> + '<p class="fs-price-increase-warning" style="display: none;">' + <?php echo json_encode( $prices_increase_text ) ?> + '</p></div>' | |
| 140 | - + ' </div>' | |
| 141 | - + ' <div class="fs-modal-footer">' | |
| 142 | - + ' <a href="#" class="button button-secondary button-close"><?php fs_esc_attr_echo_inline( 'Cancel', 'cancel', $slug ) ?></a>' | |
| 143 | - + ' <a href="#" class="button button-primary button-deactivate disabled"><?php fs_esc_attr_echo_inline( 'Proceed', 'proceed', $slug ) ?></a>' | |
| 144 | - + ' </div>' | |
| 145 | - + ' </div>' | |
| 146 | - + '</div>', | |
| 147 | - $modal = $(modalHtml); | |
| 148 | - | |
| 149 | - $modal.appendTo($('body')); | |
| 150 | - | |
| 151 | - registerEventHandlers(); | |
| 152 | - | |
| 153 | - function registerEventHandlers() { | |
| 154 | - $modal.on( 'showModal', function() { | |
| 155 | - showModal(); | |
| 156 | - }); | |
| 157 | - | |
| 158 | - $modal.on( 'closeModal', function() { | |
| 159 | - closeModal(); | |
| 160 | - }); | |
| 161 | - | |
| 162 | - $modal.on('click', '.fs-modal-footer .button', function (evt) { | |
| 163 | - evt.preventDefault(); | |
| 164 | - | |
| 165 | - if ($(this).hasClass('disabled')) { | |
| 166 | - return; | |
| 167 | - } | |
| 168 | - | |
| 169 | - var _this = $(this), | |
| 170 | - subscriptionCancellationActionEventName = <?php echo json_encode( $fs->get_action_tag( 'subscription_cancellation_action' ) ) ?>; | |
| 171 | - | |
| 172 | - if ( _this.hasClass( 'button-primary' ) ) { | |
| 173 | - if ( 'true' !== $modal.find( 'input[name="cancel-subscription"]:checked' ).val() ) { | |
| 174 | - $modal.trigger( subscriptionCancellationActionEventName, false ); | |
| 175 | - } else { | |
| 176 | - if ( confirm( <?php echo json_encode( $subscription_cancellation_confirmation_message ) ?> ) ) { | |
| 177 | - $modal.trigger( subscriptionCancellationActionEventName, true ); | |
| 178 | - } | |
| 179 | - } | |
| 180 | - } | |
| 181 | - }); | |
| 182 | - | |
| 183 | - $modal.on('click', 'input[type="radio"]', function () { | |
| 184 | - var | |
| 185 | - $selectedOption = $( this ), | |
| 186 | - $primaryButton = $modal.find( '.button-primary' ), | |
| 187 | - isSelected = ( 'true' === $selectedOption.val() ); | |
| 188 | - | |
| 189 | - if ( isSelected ) { | |
| 190 | - $primaryButton.html( <?php echo json_encode( sprintf( | |
| 191 | - fs_text_inline( 'Cancel %s & Proceed', 'cancel-x-and-proceed', $slug ), | |
| 192 | - ucfirst( $subscription_cancellation_context ) | |
| 193 | - ) ) ?> ); | |
| 194 | - | |
| 195 | - $modal.find('.fs-price-increase-warning').show(); | |
| 196 | - } else { | |
| 197 | - $primaryButton.html( <?php fs_json_encode_echo_inline( 'Proceed', 'proceed', $slug ) ?> ); | |
| 198 | - $modal.find('.fs-price-increase-warning').hide(); | |
| 199 | - } | |
| 200 | - | |
| 201 | - $primaryButton.toggleClass( 'warn', isSelected ); | |
| 202 | - $primaryButton.removeClass( 'disabled' ); | |
| 203 | - }); | |
| 204 | - | |
| 205 | - // If the user has clicked outside the window, cancel it. | |
| 206 | - $modal.on('click', function (evt) { | |
| 207 | - var $target = $(evt.target); | |
| 208 | - | |
| 209 | - // If the user has clicked anywhere in the modal dialog, just return. | |
| 210 | - if ($target.hasClass('fs-modal-body') || $target.hasClass('fs-modal-footer')) { | |
| 211 | - return; | |
| 212 | - } | |
| 213 | - | |
| 214 | - // If the user has not clicked the close button and the clicked element is inside the modal dialog, just return. | |
| 215 | - if ( | |
| 216 | - ( ! $target.hasClass( 'button-close' ) ) && | |
| 217 | - ( $target.parents( '.fs-modal-body' ).length > 0 || $target.parents( '.fs-modal-footer' ).length > 0 ) | |
| 218 | - ) { | |
| 219 | - return; | |
| 220 | - } | |
| 221 | - | |
| 222 | - closeModal(); | |
| 223 | - | |
| 224 | - return false; | |
| 225 | - }); | |
| 226 | - } | |
| 227 | - | |
| 228 | - function showModal() { | |
| 229 | - resetModal(); | |
| 230 | - | |
| 231 | - // Display the dialog box. | |
| 232 | - $modal.addClass('active'); | |
| 233 | - | |
| 234 | - $('body').addClass('has-fs-modal'); | |
| 235 | - } | |
| 236 | - | |
| 237 | - function closeModal() { | |
| 238 | - var activeModalsCount = $( '.fs-modal.active' ).length; | |
| 239 | - | |
| 240 | - $modal.removeClass('active'); | |
| 241 | - | |
| 242 | - // If child modal, do not remove the "has-fs-modal" class of the <body> element to keep its scrollbars hidden. | |
| 243 | - if ( activeModalsCount > 1 ) { | |
| 244 | - return; | |
| 245 | - } | |
| 246 | - | |
| 247 | - $('body').removeClass('has-fs-modal'); | |
| 248 | - } | |
| 249 | - | |
| 250 | - function resetModal() { | |
| 251 | - updateButtonLabels(); | |
| 252 | - | |
| 253 | - if ( 0 === $modal.find( '.subscription-actions' ).length ) { | |
| 254 | - $modal.find('.button-deactivate').removeClass('disabled'); | |
| 255 | - } else { | |
| 256 | - $modal.find('.button-deactivate').addClass('disabled'); | |
| 257 | - } | |
| 258 | - | |
| 259 | - $modal.find('.fs-price-increase-warning').hide(); | |
| 260 | - | |
| 261 | - // Uncheck all radio buttons. | |
| 262 | - $modal.find('input[type="radio"]').prop('checked', false); | |
| 263 | - | |
| 264 | - $modal.find('.message').hide(); | |
| 265 | - } | |
| 266 | - | |
| 267 | - function showMessage(message) { | |
| 268 | - $modal.find('.message').text(message).show(); | |
| 269 | - } | |
| 270 | - | |
| 271 | - function updateButtonLabels() { | |
| 272 | - $modal.find('.button-primary').text( <?php fs_json_encode_echo_inline( 'Proceed', 'proceed', $slug ) ?> ); | |
| 273 | - | |
| 274 | - $modal.find('.button-secondary').text( <?php fs_json_encode_echo_inline( 'Cancel', 'cancel', $slug ) ?> ); | |
| 275 | - } | |
| 276 | - })( jQuery ); | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * @package Freemius | |
| 4 | + * @copyright Copyright (c) 2015, Freemius, Inc. | |
| 5 | + * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 | |
| 6 | + * @since 2.2.1 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | + exit; | |
| 11 | +} | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * @var array $VARS | |
| 15 | + */ | |
| 16 | +$fs = freemius( $VARS['id'] ); | |
| 17 | +$slug = $fs->get_slug(); | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * @var FS_Plugin_License $license | |
| 21 | + */ | |
| 22 | +$license = $VARS['license']; | |
| 23 | + | |
| 24 | +$has_trial = $VARS['has_trial']; | |
| 25 | + | |
| 26 | +$subscription_cancellation_context = $has_trial ? | |
| 27 | + fs_text_inline( 'trial', 'trial', $slug ) : | |
| 28 | + fs_text_inline( 'subscription', 'subscription', $slug ); | |
| 29 | + | |
| 30 | +$plan = $fs->get_plan(); | |
| 31 | +$module_label = $fs->get_module_label( true ); | |
| 32 | + | |
| 33 | +if ( $VARS['is_license_deactivation'] ) { | |
| 34 | + $subscription_cancellation_text = ''; | |
| 35 | +} else { | |
| 36 | + $subscription_cancellation_text = sprintf( | |
| 37 | + ( $fs->is_theme() ? | |
| 38 | + fs_text_inline( | |
| 39 | + "Deactivating or uninstalling the %s will automatically disable the license, which you'll be able to use on another site.", | |
| 40 | + 'deactivation-or-uninstall-message', | |
| 41 | + $slug | |
| 42 | + ) : | |
| 43 | + fs_text_inline( | |
| 44 | + "Uninstalling the %s will automatically disable the license, which you'll be able to use on another site.", | |
| 45 | + 'uninstall-message', | |
| 46 | + $slug | |
| 47 | + ) ), | |
| 48 | + $module_label | |
| 49 | + ) . ' '; | |
| 50 | +} | |
| 51 | + | |
| 52 | + $subscription_cancellation_text .= sprintf( | |
| 53 | + fs_text_inline( | |
| 54 | + 'In case you are NOT planning on using this %s on this site (or any other site) - would you like to cancel the %s as well?', | |
| 55 | + 'cancel-subscription-message', | |
| 56 | + $slug | |
| 57 | + ), | |
| 58 | + ( $VARS['is_license_deactivation'] ? fs_text_inline( 'license', 'license', $slug ) : $module_label ), | |
| 59 | + $subscription_cancellation_context | |
| 60 | +); | |
| 61 | + | |
| 62 | +$cancel_subscription_action_label = sprintf( | |
| 63 | + fs_esc_html_inline( | |
| 64 | + "Cancel %s - I no longer need any security & feature updates, nor support for %s because I'm not planning to use the %s on this, or any other site.", | |
| 65 | + 'cancel-x', | |
| 66 | + $slug | |
| 67 | + ), | |
| 68 | + esc_html( $subscription_cancellation_context ), | |
| 69 | + sprintf( '<strong>%s</strong>', esc_html( $fs->get_plugin_title() ) ), | |
| 70 | + esc_html( $module_label ) | |
| 71 | +); | |
| 72 | + | |
| 73 | +$keep_subscription_active_action_label = esc_html( sprintf( | |
| 74 | + fs_text_inline( | |
| 75 | + "Don't cancel %s - I'm still interested in getting security & feature updates, as well as be able to contact support.", | |
| 76 | + 'dont-cancel-x', | |
| 77 | + $slug | |
| 78 | + ), | |
| 79 | + $subscription_cancellation_context | |
| 80 | +) ); | |
| 81 | + | |
| 82 | +$subscription_cancellation_text = esc_html( $subscription_cancellation_text ); | |
| 83 | + | |
| 84 | +$subscription_cancellation_html = <<< HTML | |
| 85 | + <div class="notice notice-error inline"><p></p></div><p>{$subscription_cancellation_text}</p> | |
| 86 | + <ul class="subscription-actions"> | |
| 87 | + <li> | |
| 88 | + <label> | |
| 89 | + <input type="radio" name="cancel-subscription" value="false"/> | |
| 90 | + <span>{$keep_subscription_active_action_label}</span> | |
| 91 | + </label> | |
| 92 | + </li> | |
| 93 | + <li> | |
| 94 | + <label> | |
| 95 | + <input type="radio" name="cancel-subscription" value="true"/> | |
| 96 | + <span>{$cancel_subscription_action_label}</span> | |
| 97 | + </label> | |
| 98 | + </li> | |
| 99 | + </ul> | |
| 100 | +HTML; | |
| 101 | + | |
| 102 | +$downgrading_plan_text = fs_text_inline( 'Downgrading your plan', 'downgrading-plan', $slug ); | |
| 103 | +$cancelling_subscription_text = fs_text_inline( 'Cancelling the subscription', 'cancelling-subscription', $slug ); | |
| 104 | +/* translators: %1$s: Either 'Downgrading your plan' or 'Cancelling the subscription' */ | |
| 105 | +$downgrade_x_confirm_text = fs_text_inline( '%1$s will immediately stop all future recurring payments and your %2$s plan license will expire in %3$s.', 'downgrade-x-confirm', $slug ); | |
| 106 | +$prices_increase_text = fs_text_inline( 'Please note that we will not be able to grandfather outdated pricing for renewals/new subscriptions after a cancellation. If you choose to renew the subscription manually in the future, after a price increase, which typically occurs once a year, you will be charged the updated price.', 'pricing-increase-warning', $slug ); | |
| 107 | +$after_downgrade_non_blocking_text = fs_text_inline( 'You can still enjoy all %s features but you will not have access to %s security & feature updates, nor support.', 'after-downgrade-non-blocking', $slug ); | |
| 108 | +$after_downgrade_blocking_text = fs_text_inline( 'Once your license expires you can still use the Free version but you will NOT have access to the %s features.', 'after-downgrade-blocking', $slug ); | |
| 109 | +$after_downgrade_blocking_text_premium_only = fs_text_inline( 'Once your license expires you will no longer be able to use the %s, unless you activate it again with a valid premium license.', 'after-downgrade-blocking-premium-only', $slug ); | |
| 110 | + | |
| 111 | +$subscription_cancellation_confirmation_message = $has_trial ? | |
| 112 | + fs_text_inline( 'Cancelling the trial will immediately block access to all premium features. Are you sure?', 'cancel-trial-confirm', $slug ) : | |
| 113 | + sprintf( | |
| 114 | + '%s %s %s %s', | |
| 115 | + sprintf( | |
| 116 | + $downgrade_x_confirm_text, | |
| 117 | + ($fs->is_only_premium() ? $cancelling_subscription_text : $downgrading_plan_text ), | |
| 118 | + $plan->title, | |
| 119 | + human_time_diff( time(), strtotime( $license->expiration ) ) | |
| 120 | + ), | |
| 121 | + ( | |
| 122 | + $license->is_block_features ? | |
| 123 | + ( | |
| 124 | + $fs->is_only_premium() ? | |
| 125 | + sprintf( $after_downgrade_blocking_text_premium_only, $module_label ) : | |
| 126 | + sprintf( $after_downgrade_blocking_text, $plan->title ) | |
| 127 | + ) : | |
| 128 | + sprintf( $after_downgrade_non_blocking_text, $plan->title, $fs->get_module_label( true ) ) | |
| 129 | + ), | |
| 130 | + $prices_increase_text, | |
| 131 | + fs_esc_attr_inline( 'Are you sure you want to proceed?', 'proceed-confirmation', $slug ) | |
| 132 | + ); | |
| 133 | + | |
| 134 | +fs_enqueue_local_style( 'fs_dialog_boxes', '/admin/dialog-boxes.css' ); | |
| 135 | +?> | |
| 136 | +<script type="text/javascript"> | |
| 137 | + (function( $ ) { | |
| 138 | + var modalHtml = | |
| 139 | + '<div class="fs-modal fs-modal-subscription-cancellation fs-modal-subscription-cancellation-<?php echo $fs->get_id() ?>">' | |
| 140 | + + ' <div class="fs-modal-dialog">' | |
| 141 | + + ' <div class="fs-modal-header">' | |
| 142 | + + ' <h4><?php echo esc_html( sprintf( fs_text_inline( 'Cancel %s?', 'cancel-x', $slug ), ucfirst( $subscription_cancellation_context ) ) ) ?></h4>' | |
| 143 | + + ' </div>' | |
| 144 | + + ' <div class="fs-modal-body">' | |
| 145 | + + ' <div class="fs-modal-panel active">' + <?php echo json_encode( $subscription_cancellation_html ) ?> + '<p class="fs-price-increase-warning" style="display: none;">' + <?php echo json_encode( $prices_increase_text ) ?> + '</p></div>' | |
| 146 | + + ' </div>' | |
| 147 | + + ' <div class="fs-modal-footer">' | |
| 148 | + + ' <a href="#" class="button button-secondary button-close"><?php fs_esc_attr_echo_inline( 'Cancel', 'cancel', $slug ) ?></a>' | |
| 149 | + + ' <a href="#" class="button button-primary button-deactivate disabled"><?php fs_esc_attr_echo_inline( 'Proceed', 'proceed', $slug ) ?></a>' | |
| 150 | + + ' </div>' | |
| 151 | + + ' </div>' | |
| 152 | + + '</div>', | |
| 153 | + $modal = $(modalHtml); | |
| 154 | + | |
| 155 | + $modal.appendTo($('body')); | |
| 156 | + | |
| 157 | + registerEventHandlers(); | |
| 158 | + | |
| 159 | + function registerEventHandlers() { | |
| 160 | + $modal.on( 'showModal', function() { | |
| 161 | + showModal(); | |
| 162 | + }); | |
| 163 | + | |
| 164 | + $modal.on( 'closeModal', function() { | |
| 165 | + closeModal(); | |
| 166 | + }); | |
| 167 | + | |
| 168 | + $modal.on('click', '.fs-modal-footer .button', function (evt) { | |
| 169 | + evt.preventDefault(); | |
| 170 | + | |
| 171 | + if ($(this).hasClass('disabled')) { | |
| 172 | + return; | |
| 173 | + } | |
| 174 | + | |
| 175 | + var _this = $(this), | |
| 176 | + subscriptionCancellationActionEventName = <?php echo json_encode( $fs->get_action_tag( 'subscription_cancellation_action' ) ) ?>; | |
| 177 | + | |
| 178 | + if ( _this.hasClass( 'button-primary' ) ) { | |
| 179 | + if ( 'true' !== $modal.find( 'input[name="cancel-subscription"]:checked' ).val() ) { | |
| 180 | + $modal.trigger( subscriptionCancellationActionEventName, false ); | |
| 181 | + } else { | |
| 182 | + if ( confirm( <?php echo json_encode( $subscription_cancellation_confirmation_message ) ?> ) ) { | |
| 183 | + $modal.trigger( subscriptionCancellationActionEventName, true ); | |
| 184 | + } | |
| 185 | + } | |
| 186 | + } | |
| 187 | + }); | |
| 188 | + | |
| 189 | + $modal.on('click', 'input[type="radio"]', function () { | |
| 190 | + var | |
| 191 | + $selectedOption = $( this ), | |
| 192 | + $primaryButton = $modal.find( '.button-primary' ), | |
| 193 | + isSelected = ( 'true' === $selectedOption.val() ); | |
| 194 | + | |
| 195 | + if ( isSelected ) { | |
| 196 | + $primaryButton.html( <?php echo json_encode( sprintf( | |
| 197 | + fs_text_inline( 'Cancel %s & Proceed', 'cancel-x-and-proceed', $slug ), | |
| 198 | + ucfirst( $subscription_cancellation_context ) | |
| 199 | + ) ) ?> ); | |
| 200 | + | |
| 201 | + $modal.find('.fs-price-increase-warning').show(); | |
| 202 | + } else { | |
| 203 | + $primaryButton.html( <?php fs_json_encode_echo_inline( 'Proceed', 'proceed', $slug ) ?> ); | |
| 204 | + $modal.find('.fs-price-increase-warning').hide(); | |
| 205 | + } | |
| 206 | + | |
| 207 | + $primaryButton.toggleClass( 'warn', isSelected ); | |
| 208 | + $primaryButton.removeClass( 'disabled' ); | |
| 209 | + }); | |
| 210 | + | |
| 211 | + // If the user has clicked outside the window, cancel it. | |
| 212 | + $modal.on('click', function (evt) { | |
| 213 | + var $target = $(evt.target); | |
| 214 | + | |
| 215 | + // If the user has clicked anywhere in the modal dialog, just return. | |
| 216 | + if ($target.hasClass('fs-modal-body') || $target.hasClass('fs-modal-footer')) { | |
| 217 | + return; | |
| 218 | + } | |
| 219 | + | |
| 220 | + // If the user has not clicked the close button and the clicked element is inside the modal dialog, just return. | |
| 221 | + if ( | |
| 222 | + ( ! $target.hasClass( 'button-close' ) ) && | |
| 223 | + ( $target.parents( '.fs-modal-body' ).length > 0 || $target.parents( '.fs-modal-footer' ).length > 0 ) | |
| 224 | + ) { | |
| 225 | + return; | |
| 226 | + } | |
| 227 | + | |
| 228 | + closeModal(); | |
| 229 | + | |
| 230 | + return false; | |
| 231 | + }); | |
| 232 | + } | |
| 233 | + | |
| 234 | + function showModal() { | |
| 235 | + resetModal(); | |
| 236 | + | |
| 237 | + // Display the dialog box. | |
| 238 | + $modal.addClass('active'); | |
| 239 | + | |
| 240 | + $('body').addClass('has-fs-modal'); | |
| 241 | + } | |
| 242 | + | |
| 243 | + function closeModal() { | |
| 244 | + var activeModalsCount = $( '.fs-modal.active' ).length; | |
| 245 | + | |
| 246 | + $modal.removeClass('active'); | |
| 247 | + | |
| 248 | + // If child modal, do not remove the "has-fs-modal" class of the <body> element to keep its scrollbars hidden. | |
| 249 | + if ( activeModalsCount > 1 ) { | |
| 250 | + return; | |
| 251 | + } | |
| 252 | + | |
| 253 | + $('body').removeClass('has-fs-modal'); | |
| 254 | + } | |
| 255 | + | |
| 256 | + function resetModal() { | |
| 257 | + updateButtonLabels(); | |
| 258 | + | |
| 259 | + if ( 0 === $modal.find( '.subscription-actions' ).length ) { | |
| 260 | + $modal.find('.button-deactivate').removeClass('disabled'); | |
| 261 | + } else { | |
| 262 | + $modal.find('.button-deactivate').addClass('disabled'); | |
| 263 | + } | |
| 264 | + | |
| 265 | + $modal.find('.fs-price-increase-warning').hide(); | |
| 266 | + | |
| 267 | + // Uncheck all radio buttons. | |
| 268 | + $modal.find('input[type="radio"]').prop('checked', false); | |
| 269 | + | |
| 270 | + $modal.find('.message').hide(); | |
| 271 | + } | |
| 272 | + | |
| 273 | + function showMessage(message) { | |
| 274 | + $modal.find('.message').text(message).show(); | |
| 275 | + } | |
| 276 | + | |
| 277 | + function updateButtonLabels() { | |
| 278 | + $modal.find('.button-primary').text( <?php fs_json_encode_echo_inline( 'Proceed', 'proceed', $slug ) ?> ); | |
| 279 | + | |
| 280 | + $modal.find('.button-secondary').text( <?php fs_json_encode_echo_inline( 'Cancel', 'cancel', $slug ) ?> ); | |
| 281 | + } | |
| 282 | + })( jQuery ); | |
| 277 | 283 | </script> |