PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.19
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.19
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.19, at js/formidable_admin_global.js

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