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

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