PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
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
← All changes | js/formidable_admin_global.js +167 -173 6.3 → trunk View file →
@@ -1,39 +1,35 @@
1 -/*global jQuery:false, frmGlobal, tb_remove, ajaxurl, adminpage */
2 -
3 1 /* exported frm_install_now, frmSelectSubnav, frmCreatePostEntry */
4 2
5 -var frmWidgets, frmAdminPopup;
3 +jQuery( document ).ready( function() {
4 + const installLink = document.getElementById( 'frm_install_link' );
6 5
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 - }
6 + if ( installLink ) {
7 + jQuery( installLink ).on( 'click', frmInstallPro );
8 + }
13 9
14 - deauthLink = jQuery( '.frm_deauthorize_link' );
10 + const deauthLink = jQuery( '.frm_deauthorize_link' );
15 11 if ( deauthLink.length ) {
16 12 deauthLink.on( 'click', frmDeauthorizeNow );
17 13 }
18 14
19 - if ( typeof tb_remove === 'function' ) { // eslint-disable-line camelcase
20 - frmAdminPopup.init();
21 - }
15 + if ( typeof tb_remove === 'function' ) { // eslint-disable-line camelcase
16 + frmAdminPopup.init();
17 + }
22 18
23 - submenuItem = document.querySelector( '.frm-upgrade-submenu' );
24 - if ( null !== submenuItem ) {
25 - li = submenuItem.parentNode.parentNode;
19 + const submenuItem = document.querySelector( '.frm-upgrade-submenu' );
20 + if ( submenuItem ) {
21 + const li = submenuItem.parentNode.parentNode;
26 22 if ( li ) {
27 23 li.classList.add( 'frm-submenu-highlight' );
28 24 }
29 25 }
30 -});
26 +} );
31 27
32 28 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({
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( {
36 32 type: 'POST',
37 33 url: ajaxurl,
38 34 data: {
39 35 action: 'frm_install',
@@ -38,18 +34,17 @@
38 34 data: {
39 35 action: 'frm_install',
40 36 nonce: frmGlobal.nonce
41 37 },
42 - success: function() {
38 + success() {
43 39 $msg.fadeOut( 'slow' );
44 40 }
45 - });
41 + } );
46 42 return false;
47 43 }
48 44
49 45 function frmInstallPro( e ) {
50 - var $msg,
51 - plugin = this.getAttribute( 'data-prourl' );
46 + const plugin = this.getAttribute( 'data-prourl' );
52 47 if ( plugin === '' ) {
53 48 return true;
54 49 }
55 50
@@ -54,13 +49,13 @@
54 49 }
55 50
56 51 e.preventDefault();
57 52
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>' );
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>` );
60 55 $msg.fadeIn( 'slow' );
61 56
62 - jQuery.ajax({
57 + jQuery.ajax( {
63 58 url: ajaxurl,
64 59 type: 'POST',
65 60 async: true,
66 61 cache: false,
@@ -67,92 +62,91 @@
67 62 dataType: 'json',
68 63 data: {
69 64 action: 'frm_install_addon',
70 65 nonce: frmGlobal.nonce,
71 - plugin: plugin
66 + plugin
72 67 },
73 - success: function() {
68 + success() {
74 69 $msg.fadeOut( 'slow' );
75 70 $msg.parent().fadeOut( 'slow' );
76 71 },
77 - error: function() {
72 + error() {
78 73 $msg.fadeOut( 'slow' );
79 74 }
80 - });
75 + } );
81 76 return false;
82 77 }
83 78
84 79 function frmDeauthorizeNow() {
85 - if ( ! confirm( frmGlobal.deauthorize ) ) {
80 + if ( ! confirm( frmGlobal.deauthorize ) ) {
86 81 return false;
87 - }
88 - jQuery( this ).html( '<span class="spinner"></span>' );
89 - jQuery.ajax({
90 - type: 'POST',
82 + }
83 + jQuery( this ).html( '<span class="spinner"></span>' );
84 + jQuery.ajax( {
85 + type: 'POST',
91 86 url: ajaxurl,
92 - data: {
87 + data: {
93 88 action: 'frm_deauthorize',
94 89 nonce: frmGlobal.nonce
95 90 },
96 - success: function() {
91 + success() {
97 92 jQuery( '.error' ).fadeOut( 'slow' );
98 93 }
99 - });
100 - return false;
94 + } );
95 + return false;
101 96 }
102 97
103 98 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' );
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' );
107 102 }
108 103
109 104 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({
105 + jQuery( '#frm_create_entry p' ).replaceWith( `<img src="${ frmGlobal.url }/images/wpspin_light.gif" alt="${ frmGlobal.loading }" />` );
106 + jQuery.ajax( {
112 107 type: 'POST',
113 108 url: ajaxurl,
114 109 data: {
115 110 action: 'frm_create_post_entry',
116 - id: id,
111 + id,
117 112 post_id: postId,
118 113 nonce: frmGlobal.nonce
119 114 },
120 - success: function() {
115 + success() {
121 116 jQuery( document.getElementById( 'frm_create_entry' ) ).fadeOut( 'slow' );
122 117 }
123 - });
118 + } );
124 119 }
125 120
126 121 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 - }
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 + }
137 131
138 - function populateOpts( val ) {
139 - var $settings, $scOpts, $spinner,
140 - sc = document.getElementById( 'frm_complete_shortcode' );
141 - if ( sc !== null ) {
142 - sc.value = '[' + val + ']';
132 + function populateOpts( val ) {
133 + const sc = document.getElementById( 'frm_complete_shortcode' );
134 +
135 + if ( sc ) {
136 + sc.value = `[${ val }]`;
143 137 }
144 - jQuery( '.frm_shortcode_option' ).hide();
138 + jQuery( '.frm_shortcode_option' ).hide();
145 139
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({
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( {
155 149 type: 'POST',
156 150 url: ajaxurl,
157 151 data: {
158 152 action: 'frm_get_shortcode_opts',
@@ -158,144 +152,144 @@
158 152 action: 'frm_get_shortcode_opts',
159 153 shortcode: val,
160 154 nonce: frmGlobal.nonce
161 155 },
162 - success: function( html ) {
156 + success( html ) {
163 157 $spinner.hide();
164 158 $scOpts.append( html );
165 - jQuery( document.getElementById( 'sc-' + val ) ).trigger( 'click' );
159 + jQuery( document.getElementById( `sc-${ val }` ) ).trigger( 'click' );
166 160 }
167 - });
161 + } );
168 162 }
169 163 }
170 164
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 + '_', '' );
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 }_`, '' );
181 178 attrVal = $thisInput.val();
182 179
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 - }
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 + }
192 188
193 - function insertShortcode() {
194 - var win = window.dialogArguments || opener || parent || top;
195 - win.send_to_editor( document.getElementById( 'frm_complete_shortcode' ).value );
196 - }
189 + function insertShortcode() {
190 + const win = window.dialogArguments || opener || parent || top;
191 + win.send_to_editor( document.getElementById( 'frm_complete_shortcode' ).value );
192 + }
197 193
198 - function getFieldSelection() {
199 - var thisId,
200 - formId = this.value;
201 - if ( formId ) {
202 - thisId = this.id;
203 - jQuery.ajax({
194 + function getFieldSelection() {
195 + let thisId;
196 + const formId = this.value;
197 + if ( formId ) {
198 + thisId = this.id;
199 + jQuery.ajax( {
204 200 type: 'POST',
205 201 url: ajaxurl,
206 - data: {
202 + data: {
207 203 action: 'frm_get_field_selection',
208 204 field_id: 0,
209 205 form_id: formId,
210 206 nonce: frmGlobal.nonce
211 207 },
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 - }
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 + }
220 216
221 217 function toggleMenu() {
222 218 jQuery( document.getElementById( 'frm_popup_content' ) ).find( '.media-menu' ).toggleClass( 'visible' );
223 219 }
224 220
225 - return {
226 - init: function() {
227 - var $scOptsDiv;
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 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 );
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 );
234 232
235 - $scOptsDiv = jQuery( document.getElementById( 'frm_shortcode_options' ) );
236 - $scOptsDiv.on( 'change', 'select, input', addToShortcode );
237 - $scOptsDiv.on( 'change', '.frm_get_field_selection', getFieldSelection );
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 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();
239 +window.frmAdminPopup = frmAdminPopupJS();
245 240
246 241 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 - }
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 + }
255 250
256 - function getFields() {
257 - var widget,
258 - displayId = this.value;
259 - if ( displayId !== '' ) {
251 + function getFields() {
252 + let widget;
253 + const displayId = this.value;
254 + if ( displayId !== '' ) {
260 255 widget = jQuery( this ).closest( '.widget-content' );
261 256
262 - jQuery.ajax({
263 - type: 'POST',
257 + jQuery.ajax( {
258 + type: 'POST',
264 259 url: ajaxurl,
265 - dataType: 'json',
266 - data: {
260 + dataType: 'json',
261 + data: {
267 262 action: 'frm_get_dynamic_widget_opts',
268 263 display_id: displayId,
269 264 nonce: frmGlobal.nonce
270 265 },
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 - });
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 + } );
279 273
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 - }
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 + }
290 284
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 - };
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 + };
297 291 }
298 292 if ( typeof adminpage !== 'undefined' && adminpage === 'widgets-php' ) {
299 - frmWidgets = frmWidgetsJS();
300 - frmWidgets.init();
293 + window.frmWidgets = frmWidgetsJS();
294 + window.frmWidgets.init();
301 295 }