PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.32.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.32.1
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / js / formidable_admin_global.js

formidable_admin_global.js in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.32.1, at js/formidable_admin_global.js

296 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* exported frm_install_now, frmSelectSubnav, frmCreatePostEntry */
2
3 jQuery( document ).ready( function() {
4 const installLink = document.getElementById( 'frm_install_link' );
5
6 if ( installLink ) {
7 jQuery( installLink ).on( 'click', frmInstallPro );
8 }
9
10 const deauthLink = jQuery( '.frm_deauthorize_link' );
11 if ( deauthLink.length ) {
12 deauthLink.on( 'click', frmDeauthorizeNow );
13 }
14
15 if ( typeof tb_remove === 'function' ) { // eslint-disable-line camelcase
16 frmAdminPopup.init();
17 }
18
19 const submenuItem = document.querySelector( '.frm-upgrade-submenu' );
20 if ( submenuItem ) {
21 const li = submenuItem.parentNode.parentNode;
22 if ( li ) {
23 li.classList.add( 'frm-submenu-highlight' );
24 }
25 }
26 } );
27
28 function frm_install_now() { // eslint-disable-line camelcase
29 const $msg = jQuery( document.getElementById( 'frm_install_message' ) );
30 $msg.html( `<div class="frm_plugin_updating">${ frmGlobal.updating_msg }<div class="spinner frm_spinner"></div></div>` );
31 jQuery.ajax( {
32 type: 'POST',
33 url: ajaxurl,
34 data: {
35 action: 'frm_install',
36 nonce: frmGlobal.nonce
37 },
38 success() {
39 $msg.fadeOut( 'slow' );
40 }
41 } );
42 return false;
43 }
44
45 function frmInstallPro( e ) {
46 const plugin = this.getAttribute( 'data-prourl' );
47 if ( plugin === '' ) {
48 return true;
49 }
50
51 e.preventDefault();
52
53 const $msg = jQuery( document.getElementById( 'frm_install_message' ) );
54 $msg.html( `<div class="frm_plugin_updating">${ frmGlobal.updating_msg }<div class="spinner frm_spinner"></div></div>` );
55 $msg.fadeIn( 'slow' );
56
57 jQuery.ajax( {
58 url: ajaxurl,
59 type: 'POST',
60 async: true,
61 cache: false,
62 dataType: 'json',
63 data: {
64 action: 'frm_install_addon',
65 nonce: frmGlobal.nonce,
66 plugin
67 },
68 success() {
69 $msg.fadeOut( 'slow' );
70 $msg.parent().fadeOut( 'slow' );
71 },
72 error() {
73 $msg.fadeOut( 'slow' );
74 }
75 } );
76 return false;
77 }
78
79 function frmDeauthorizeNow() {
80 if ( ! confirm( frmGlobal.deauthorize ) ) {
81 return false;
82 }
83 jQuery( this ).html( '<span class="spinner"></span>' );
84 jQuery.ajax( {
85 type: 'POST',
86 url: ajaxurl,
87 data: {
88 action: 'frm_deauthorize',
89 nonce: frmGlobal.nonce
90 },
91 success() {
92 jQuery( '.error' ).fadeOut( 'slow' );
93 }
94 } );
95 return false;
96 }
97
98 function frmSelectSubnav() {
99 const frmMenu = document.getElementById( 'toplevel_page_formidable' );
100 jQuery( frmMenu ).removeClass( 'wp-not-current-submenu' ).addClass( 'wp-has-current-submenu wp-menu-open' );
101 jQuery( '#toplevel_page_formidable a.wp-has-submenu' ).removeClass( 'wp-not-current-submenu' ).addClass( 'wp-has-current-submenu wp-menu-open' );
102 }
103
104 function frmCreatePostEntry( id, postId ) {
105 jQuery( '#frm_create_entry p' ).replaceWith( `<img src="${ frmGlobal.url }/images/wpspin_light.gif" alt="${ frmGlobal.loading }" />` );
106 jQuery.ajax( {
107 type: 'POST',
108 url: ajaxurl,
109 data: {
110 action: 'frm_create_post_entry',
111 id,
112 post_id: postId,
113 nonce: frmGlobal.nonce
114 },
115 success() {
116 jQuery( document.getElementById( 'frm_create_entry' ) ).fadeOut( 'slow' );
117 }
118 } );
119 }
120
121 function frmAdminPopupJS() {
122 function switchSc() {
123 jQuery( '.frm_switch_sc' ).removeClass( 'active' );
124 jQuery( this ).addClass( 'active' );
125 toggleMenu();
126 jQuery( '#frm_popup_content .media-frame-title h1' ).html( `${ jQuery( this ).children( '.howto' ).text() } <span class="spinner" style="float:left;"></span>` );
127 const val = this.id.replace( 'sc-link-', '' );
128 populateOpts( val );
129 return false;
130 }
131
132 function populateOpts( val ) {
133 const sc = document.getElementById( 'frm_complete_shortcode' );
134
135 if ( sc ) {
136 sc.value = `[${ val }]`;
137 }
138 jQuery( '.frm_shortcode_option' ).hide();
139
140 const $settings = document.getElementById( `sc-opts-${ val }` );
141 if ( $settings ) {
142 $settings.style.display = '';
143 jQuery( document.getElementById( `sc-${ val }` ) ).trigger( 'click' );
144 } else {
145 const $scOpts = jQuery( document.getElementById( 'frm_shortcode_options' ) );
146 const $spinner = jQuery( '.media-frame-title .spinner' );
147 $spinner.show();
148 jQuery.ajax( {
149 type: 'POST',
150 url: ajaxurl,
151 data: {
152 action: 'frm_get_shortcode_opts',
153 shortcode: val,
154 nonce: frmGlobal.nonce
155 },
156 success( html ) {
157 $spinner.hide();
158 $scOpts.append( html );
159 jQuery( document.getElementById( `sc-${ val }` ) ).trigger( 'click' );
160 }
161 } );
162 }
163 }
164
165 function addToShortcode() {
166 const sc = jQuery( 'input[name=frmsc]:checked' ).val();
167 const inputs = jQuery( document.getElementById( `sc-opts-${ sc }` ) ).find( 'input, select' );
168 let output = `[${ sc }`;
169
170 inputs.each( function() {
171 let attrName;
172 let attrVal;
173 const $thisInput = jQuery( this );
174 const attrId = this.id;
175
176 if ( attrId.indexOf( 'frmsc_' ) === 0 ) {
177 attrName = attrId.replace( `frmsc_${ sc }_`, '' );
178 attrVal = $thisInput.val();
179
180 if ( ( $thisInput.attr( 'type' ) !== 'checkbox' || this.checked ) && ( ( $thisInput.attr( 'type' ) !== 'text' && ! $thisInput.is( 'select' ) ) || attrVal !== '' ) ) {
181 output += ` ${ attrName }="${ attrVal }"`;
182 }
183 }
184 } );
185 output += ']';
186 document.getElementById( 'frm_complete_shortcode' ).value = output;
187 }
188
189 function insertShortcode() {
190 const win = window.dialogArguments || opener || parent || top;
191 win.send_to_editor( document.getElementById( 'frm_complete_shortcode' ).value );
192 }
193
194 function getFieldSelection() {
195 let thisId;
196 const formId = this.value;
197 if ( formId ) {
198 thisId = this.id;
199 jQuery.ajax( {
200 type: 'POST',
201 url: ajaxurl,
202 data: {
203 action: 'frm_get_field_selection',
204 field_id: 0,
205 form_id: formId,
206 nonce: frmGlobal.nonce
207 },
208 success( msg ) {
209 const baseId = thisId.replace( '_form', '' );
210 msg = msg.replace( 'name="field_options[form_select_0]"', `id="frmsc_${ baseId }_fields"` );
211 jQuery( document.getElementById( `${ baseId }_fields_container` ) ).html( msg );
212 }
213 } );
214 }
215 }
216
217 function toggleMenu() {
218 jQuery( document.getElementById( 'frm_popup_content' ) ).find( '.media-menu' ).toggleClass( 'visible' );
219 }
220
221 return {
222 init() {
223 jQuery( '.frm_switch_sc' ).on( 'click', switchSc );
224 jQuery( '.button.frm_insert_form' ).on( 'click', function() {
225 populateOpts( 'formidable' );
226 } );
227 jQuery( document.getElementById( 'frm_insert_shortcode' ) ).on( 'click', insertShortcode );
228
229 const $scOptsDiv = jQuery( document.getElementById( 'frm_shortcode_options' ) );
230 $scOptsDiv.on( 'change', 'select, input', addToShortcode );
231 $scOptsDiv.on( 'change', '.frm_get_field_selection', getFieldSelection );
232
233 jQuery( '#frm_popup_content .media-modal-close' ).on( 'click', tb_remove );
234 jQuery( '#frm_popup_content .media-frame-title h1' ).on( 'click', toggleMenu );
235 }
236 };
237 }
238
239 window.frmAdminPopup = frmAdminPopupJS();
240
241 function frmWidgetsJS() {
242 function toggleCatOpt() {
243 const catOpts = jQuery( this ).closest( '.widget-content' ).children( '.frm_list_items_hide_cat_opts' );
244 if ( this.checked ) {
245 catOpts.fadeIn();
246 } else {
247 catOpts.fadeOut();
248 }
249 }
250
251 function getFields() {
252 let widget;
253 const displayId = this.value;
254 if ( displayId !== '' ) {
255 widget = jQuery( this ).closest( '.widget-content' );
256
257 jQuery.ajax( {
258 type: 'POST',
259 url: ajaxurl,
260 dataType: 'json',
261 data: {
262 action: 'frm_get_dynamic_widget_opts',
263 display_id: displayId,
264 nonce: frmGlobal.nonce
265 },
266 success( opts ) {
267 const catField = widget.find( '.frm_list_items_cat_id' );
268 catField.find( 'option' ).remove().end();
269 catField.append( jQuery( '<option></option>' ) );
270 jQuery.each( opts.catValues, function( key, value ) {
271 catField.append( jQuery( '<option></option>' ).attr( 'value', key ).text( value ) );
272 } );
273
274 const titleField = widget.find( '.frm_list_items_title_id' );
275 titleField.find( 'option' ).remove().end();
276 titleField.append( jQuery( '<option></option>' ) );
277 jQuery.each( opts.titleValues, function( key, value ) {
278 titleField.append( jQuery( '<option></option>' ).attr( 'value', key ).text( value ) );
279 } );
280 }
281 } );
282 }
283 }
284
285 return {
286 init() {
287 jQuery( document ).on( 'click', '.frm_list_items_cat_list', toggleCatOpt );
288 jQuery( document ).on( 'change', '.frm_list_items_display_id', getFields );
289 }
290 };
291 }
292 if ( typeof adminpage !== 'undefined' && adminpage === 'widgets-php' ) {
293 window.frmWidgets = frmWidgetsJS();
294 window.frmWidgets.init();
295 }
296