PluginProbe ʕ •ᴥ•ʔ
Image Widget / 4.2
Image Widget v4.2
trunk 1.0 2.0 2.1 2.2 2.2.1 2.2.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.2 3.2.1 3.2.10 3.2.11 3.2.2 3.2.3 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1 4.1.1 4.1.2 4.2 4.2.1 4.2.2 4.3 4.3.1 4.4 4.4.1 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9
image-widget / freemius / templates / deactivation-feedback-modal.php
image-widget / freemius / templates Last commit date
plugin-info 10 years ago account.php 10 years ago add-ons.php 10 years ago admin-notice.php 10 years ago all-admin-notice.php 10 years ago checkout.php 10 years ago connect.php 10 years ago contact.php 10 years ago deactivation-feedback-modal.php 10 years ago debug.php 10 years ago email.php 10 years ago firewall-issues-js.php 10 years ago pending-activation.php 10 years ago plugin-icon.php 10 years ago powered-by.php 10 years ago pricing.php 10 years ago sticky-admin-notice-js.php 10 years ago
deactivation-feedback-modal.php
197 lines
1 <?php
2 /**
3 * @package Freemius
4 * @copyright Copyright (c) 2015, Freemius, Inc.
5 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
6 * @since 1.1.2
7 */
8 $slug = $VARS['slug'];
9 $fs = freemius( $slug );
10
11 $confirmation_message = $fs->apply_filters( 'uninstall_confirmation_message', '' );
12
13 $reasons = $VARS['reasons'];
14
15 $reasons_list_items_html = '';
16
17 foreach ( $reasons as $reason ) {
18 $list_item_classes = 'reason' . ( ! empty( $reason['input_type'] ) ? ' has-input' : '' );
19 $reasons_list_items_html .= '<li class="' . $list_item_classes . '" data-input-type="' . $reason['input_type'] . '" data-input-placeholder="' . $reason['input_placeholder'] . '"><label><span><input type="radio" name="selected-reason" value="' . $reason['id'] . '"/></span><span>' . $reason['text'] . '</span></label></li>';
20 }
21 ?>
22 <script>
23 (function( $ ) {
24 var reasonsHtml = <?php echo json_encode( $reasons_list_items_html ); ?>,
25 modalHtml =
26 '<div class="fs-modal<?php echo empty( $confirmation_message ) ? ' no-confirmation-message' : ''; ?>">'
27 + ' <div class="fs-modal-dialog">'
28 + ' <div class="fs-modal-body">'
29 + ' <div class="fs-modal-panel" data-panel-id="confirm"><p><?php echo $confirmation_message; ?></p></div>'
30 + ' <div class="fs-modal-panel active" data-panel-id="reasons"><h3><strong><?php printf( __fs( 'deactivation-share-reason' ) ); ?>:</strong></h3><ul id="reasons-list">' + reasonsHtml + '</ul></div>'
31 + ' </div>'
32 + ' <div class="fs-modal-footer">'
33 + ' <a href="#" class="button button-secondary button-deactivate"></a>'
34 + ' <a href="#" class="button button-primary button-close"><?php printf( __fs( 'deactivation-modal-button-cancel' ) ); ?></a>'
35 + ' </div>'
36 + ' </div>'
37 + '</div>',
38 $modal = $( modalHtml ),
39 $deactivateLink = $( '#the-list .deactivate > [data-slug=<?php echo $VARS['slug']; ?>].fs-slug' ).prev();
40
41 $modal.appendTo( $( 'body' ) );
42
43 registerEventHandlers();
44
45 function registerEventHandlers() {
46 $deactivateLink.click(function ( evt ) {
47 evt.preventDefault();
48
49 showModal();
50 });
51
52 $modal.on( 'click', '.button', function( evt ) {
53 evt.preventDefault();
54
55 if ( $( this ).hasClass( 'disabled' ) ) {
56 return;
57 }
58
59 var _parent = $( this ).parents( '.fs-modal:first' );
60 var _this = $( this );
61
62 if ( _this.hasClass( 'allow-deactivate' ) ) {
63 var $radio = $( 'input[type="radio"]:checked' );
64
65 if ( 0 === $radio.length ) {
66 // If no selected reason, just deactivate the plugin.
67 window.location.href = $deactivateLink.attr( 'href' );
68 return;
69 }
70
71 var $selected_reason = $radio.parents( 'li:first' ),
72 $input = $selected_reason.find( 'textarea, input[type="text"]' );
73
74 $.ajax({
75 url: ajaxurl,
76 method: 'POST',
77 data: {
78 'action' : 'submit-uninstall-reason',
79 'reason_id' : $radio.val(),
80 'reason_info' : ( 0 !== $input.length ) ? $input.val().trim() : ''
81 },
82 beforeSend: function() {
83 _parent.find( '.button' ).addClass( 'disabled' );
84 _parent.find( '.button-secondary' ).text( 'Processing...' );
85 },
86 complete: function() {
87 // Do not show the dialog box, deactivate the plugin.
88 window.location.href = $deactivateLink.attr( 'href' );
89 }
90 });
91 } else if ( _this.hasClass( 'button-deactivate' ) ) {
92 // Change the Deactivate button's text and show the reasons panel.
93 _parent.find( '.button-deactivate').addClass( 'allow-deactivate' );
94
95 showPanel( 'reasons' );
96 }
97 });
98
99 $modal.on( 'click', 'input[type="radio"]', function() {
100 var _parent = $( this ).parents( 'li:first' );
101
102 $modal.find( '.reason-input' ).remove();
103 $modal.find( '.button-deactivate').text( '<?php printf( __fs( 'deactivation-modal-button-submit' ) ); ?>' );
104
105 if ( _parent.hasClass( 'has-input' ) ) {
106 var inputType = _parent.data( 'input-type' ),
107 inputPlaceholder = _parent.data( 'input-placeholder' ),
108 reasonInputHtml = '<div class="reason-input">' + ( ( 'textfield' === inputType ) ? '<input type="text" />' : '<textarea rows="5"></textarea>' ) + '</div>';
109
110 _parent.append( $( reasonInputHtml ) );
111 _parent.find( 'input, textarea' ).attr( 'placeholder', inputPlaceholder ).focus();
112 }
113 });
114
115 // If the user has clicked outside the window, cancel it.
116 $modal.on( 'click', function( evt ) {
117 var $target = $( evt.target );
118
119 // If the user has clicked anywhere in the modal dialog, just return.
120 if ( $target.hasClass( 'fs-modal-body' ) || $target.hasClass( 'fs-modal-footer' ) ) {
121 return;
122 }
123
124 // If the user has not clicked the close button and the clicked element is inside the modal dialog, just return.
125 if ( ! $target.hasClass( 'button-close' ) && ( $target.parents( '.fs-modal-body').length > 0 || $target.parents( '.fs-modal-footer').length > 0 ) ) {
126 return;
127 }
128
129 closeModal();
130 });
131 }
132
133 function showModal() {
134 resetModal();
135
136 // Display the dialog box.
137 $modal.addClass( 'active' );
138
139 $( 'body' ).addClass( 'has-fs-modal' );
140 }
141
142 function closeModal() {
143 $modal.removeClass( 'active' );
144
145 $( 'body' ).removeClass( 'has-fs-modal' );
146 }
147
148 function resetModal() {
149 $modal.find( '.button' ).removeClass( 'disabled' );
150
151 // Uncheck all radio buttons.
152 $modal.find( 'input[type="radio"]' ).prop( 'checked', false );
153
154 // Remove all input fields ( textfield, textarea ).
155 $modal.find( '.reason-input' ).remove();
156
157 var $deactivateButton = $modal.find( '.button-deactivate' );
158
159 /*
160 * If the modal dialog has no confirmation message, that is, it has only one panel, then ensure
161 * that clicking the deactivate button will actually deactivate the plugin.
162 */
163 if ( $modal.hasClass( 'no-confirmation-message' ) ) {
164 $deactivateButton.addClass( 'allow-deactivate' );
165
166 showPanel( 'reasons' );
167 } else {
168 $deactivateButton.removeClass( 'allow-deactivate' );
169
170 showPanel( 'confirm' );
171 }
172 }
173
174 function showPanel( panelType ) {
175 $modal.find( '.fs-modal-panel' ).removeClass( 'active ');
176 $modal.find( '[data-panel-id="' + panelType + '"]' ).addClass( 'active' );
177
178 updateButtonLabels();
179 }
180
181 function updateButtonLabels() {
182 var $deactivateButton = $modal.find( '.button-deactivate' );
183
184 // Reset the deactivate button's text.
185 if ( 'confirm' === getCurrentPanel() ) {
186 $deactivateButton.text( '<?php printf( __fs( 'deactivation-modal-button-confirm' ) ); ?>' );
187 } else {
188 $deactivateButton.text( '<?php printf( __fs( 'deactivation-modal-button-deactivate' ) ); ?>' );
189 }
190 }
191
192 function getCurrentPanel() {
193 return $modal.find( '.fs-modal-panel.active' ).attr( 'data-panel-id' );
194 }
195 })( jQuery );
196 </script>
197