PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.4
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.4
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/admin/embed.js +69 -76 6.355.4 View file →
@@ -4,9 +4,9 @@
4 4 if ( 'undefined' === typeof ajaxurl || 'undefined' === typeof wp || 'undefined' === typeof frmDom ) {
5 5 return;
6 6 }
7 7
8 - const { __, sprintf } = wp.i18n;
8 + const __ = wp.i18n.__;
9 9 const { div, tag, svg } = frmDom;
10 10 const { maybeCreateModal, footerButton } = frmDom.modal;
11 11
12 12 let autoId = 0;
@@ -44,10 +44,9 @@
44 44 }
45 45 break;
46 46
47 47 case 'svg':
48 - case 'use':
49 - clicked = null !== element.closest( '.frm-embed-form' );
48 + clicked = element.parentNode.classList.contains( 'frm-embed-form' );
50 49 if ( clicked ) {
51 50 state.type = 'form';
52 51 }
53 52 break;
@@ -73,9 +72,9 @@
73 72 }
74 73
75 74 function openEmbedModal() {
76 75 /* translators: %s type: ie form, view. */
77 - const title = sprintf( __( 'Embed %s', 'formidable' ), getTypeDescription() );
76 + const title = __( 'Embed %s', 'formidable' ).replace( '%s', getTypeDescription() );
78 77
79 78 modal = maybeCreateModal(
80 79 'frm_embed_modal',
81 80 {
@@ -92,17 +91,17 @@
92 91 $modal.parent().addClass( 'frm-embed-modal-wrapper' );
93 92 }
94 93
95 94 function getModalFooter() {
96 - const doneButton = footerButton( {
95 + const doneButton = footerButton({
97 96 text: __( 'Done', 'formidable' ),
98 97 buttonType: 'primary'
99 - } );
98 + });
100 99
101 - const cancelButton = footerButton( {
100 + const cancelButton = footerButton({
102 101 text: __( 'Back', 'formidable' ),
103 102 buttonType: 'cancel'
104 - } );
103 + });
105 104 cancelButton.addEventListener(
106 105 'click',
107 106 function( event ) {
108 107 event.preventDefault();
@@ -109,17 +108,17 @@
109 108 openEmbedModal();
110 109 }
111 110 );
112 111
113 - return div( {
112 + return div({
114 113 children: [ doneButton, cancelButton ]
115 - } );
114 + });
116 115 }
117 116
118 117 function offsetModalY( $modal, amount ) {
119 118 const position = {
120 119 my: 'top',
121 - at: `top+${ amount }`,
120 + at: 'top+' + amount,
122 121 of: window
123 122 };
124 123 $modal.dialog( 'option', 'position', position );
125 124 }
@@ -124,19 +123,19 @@
124 123 $modal.dialog( 'option', 'position', position );
125 124 }
126 125
127 126 function getModalOptions() {
128 - const content = div( { className: 'frm-embed-modal-content frm_wrap' } );
127 + const content = div({ className: 'frm-embed-modal-content frm_wrap' });
129 128 const typeDescription = getTypeDescription();
130 129
131 130 /* translators: %s type: ie form, view. */
132 - const existingPageDescription = sprintf( __( 'Embed your %s into an existing page.', 'formidable' ), typeDescription );
131 + const existingPageDescription = __( 'Embed your %s into an existing page.', 'formidable' ).replace( '%s', typeDescription );
133 132
134 133 /* translators: %s type: ie form, view. */
135 - const newPageDescription = sprintf( __( 'Put your %s on a newly created page.', 'formidable' ), typeDescription );
134 + const newPageDescription = __( 'Put your %s on a newly created page.', 'formidable' ).replace( '%s', typeDescription );
136 135
137 136 /* translators: %s type: ie form, view. */
138 - const insertManuallyDescription = sprintf( __( 'Use shortcodes or PHP code to put the %s anywhere.', 'formidable' ), typeDescription );
137 + const insertManuallyDescription = __( 'Use WP shortcodes or PHP code to put the %s in any place.', 'formidable' ).replace( '%s', typeDescription );
139 138
140 139 const options = [
141 140 {
142 141 icon: '#frm_file_icon',
@@ -147,17 +146,17 @@
147 146
148 147 const spinner = tag( 'span' );
149 148 spinner.className = 'frm-wait frm_spinner';
150 149 spinner.style.visibility = 'visible';
151 - content.append( spinner );
150 + content.appendChild( spinner );
152 151
153 152 const gap = div();
154 153 gap.style.height = '20px';
155 - content.append( gap );
154 + content.appendChild( gap );
156 155
157 156 content.classList.add( 'frm-loading-page-options' );
158 157
159 - jQuery.ajax( {
158 + jQuery.ajax({
160 159 type: 'POST',
161 160 url: ajaxurl,
162 161 data: {
163 162 action: 'get_page_dropdown',
@@ -164,9 +163,9 @@
164 163 nonce: frmGlobal.nonce
165 164 },
166 165 dataType: 'json',
167 166 success: addExistingPageDropdown
168 - } );
167 + });
169 168
170 169 function addExistingPageDropdown( response ) {
171 170 if ( 'object' !== typeof response || 'string' !== typeof response.html ) {
172 171 return;
@@ -177,28 +176,28 @@
177 176
178 177 const typeDescription = getTypeDescription();
179 178
180 179 /* translators: %s: type (ie. view, form). */
181 - const titleText = sprintf( __( 'Select the page you want to embed your %s into.', 'formidable' ), typeDescription );
180 + const titleText = __( 'Select the page you want to embed your %s into.', 'formidable' ).replace( '%s', typeDescription );
182 181
183 182 const title = getLabel( titleText );
184 183 title.setAttribute( 'for', 'frm_page_dropdown' );
185 - content.append( title );
184 + content.appendChild( title );
186 185
187 186 let editPageUrl;
188 187
189 - const doneButton = modal.querySelector( '.frm_modal_footer .button-primary' );
188 + doneButton = modal.querySelector( '.frm_modal_footer .button-primary' );
190 189 doneButton.classList.remove( 'dismiss' );
191 190 /* translators: %s: type (ie. view, form). */
192 - doneButton.textContent = sprintf( __( 'Insert %s', 'formidable' ), typeDescription );
191 + doneButton.textContent = __( 'Insert %s', 'formidable' ).replace( '%s', typeDescription );
193 192 doneButton.addEventListener( 'click', redirectToExistingPageWithInjectedShortcode );
194 193
195 194 const dropdownWrapper = div();
196 195 dropdownWrapper.innerHTML = response.html;
197 - content.append( dropdownWrapper );
196 + content.appendChild( dropdownWrapper );
198 197
199 198 if ( 'form' === state.type ) {
200 - editPageUrl = `${ response.edit_page_url }&frmForm=${ state.objectId }`;
199 + editPageUrl = response.edit_page_url + '&frmForm=' + state.objectId;
201 200 } else {
202 201 const hookName = 'frm_embed_edit_page_url';
203 202 const hookArgs = {
204 203 objectId: state.objectId,
@@ -208,12 +207,8 @@
208 207 }
209 208
210 209 frmDom.autocomplete.initAutocomplete( 'page', dropdownWrapper );
211 210
212 - // Prevent cutoff issue with the autocomplete dropdown.
213 - // This also adds visible overflow even if autocomplete is not activated, but that's fine for this page.
214 - modal.querySelector( '.postbox' ).style.overflow = 'visible';
215 -
216 211 function redirectToExistingPageWithInjectedShortcode( event ) {
217 212 event.preventDefault();
218 213
219 214 const pageDropdown = modal.querySelector( '[name="frm_page_dropdown"]' );
@@ -221,9 +216,9 @@
221 216
222 217 const pageId = pageDropdown.value;
223 218
224 219 if ( '0' === pageId || '' === pageId ) {
225 - const error = div( { className: 'frm_error_style' } );
220 + const error = div({ className: 'frm_error_style' });
226 221 error.setAttribute( 'role', 'alert' );
227 222 error.textContent = __( 'Please select a page', 'formidable' );
228 223 content.insertBefore( error, title.nextElementSibling );
229 224 return;
@@ -228,9 +223,9 @@
228 223 content.insertBefore( error, title.nextElementSibling );
229 224 return;
230 225 }
231 226
232 - window.location.href = editPageUrl.replace( 'post=0', `post=${ pageId }` );
227 + window.location.href = editPageUrl.replace( 'post=0', 'post=' + pageId );
233 228 }
234 229 }
235 230 }
236 231 },
@@ -240,9 +235,9 @@
240 235 description: newPageDescription,
241 236 callback: () => {
242 237 content.innerHTML = '';
243 238
244 - const wrapper = div( { className: 'field-group' } );
239 + const wrapper = div({ className: 'field-group' });
245 240 const form = tag( 'form' );
246 241
247 242 const createPageWithShortcode = () => {
248 243 const hookName = 'frm_create_page_with_shortcode_data';
@@ -255,19 +250,19 @@
255 250 name: input.value,
256 251 nonce: frmGlobal.nonce
257 252 }
258 253 );
259 - jQuery.ajax( {
254 + jQuery.ajax({
260 255 type: 'POST',
261 256 url: ajaxurl,
262 257 data,
263 258 dataType: 'json',
264 - success( response ) {
259 + success: function( response ) {
265 260 if ( 'object' === typeof response && 'string' === typeof response.redirect ) {
266 261 window.location.href = response.redirect;
267 262 }
268 263 }
269 - } );
264 + });
270 265 };
271 266
272 267 form.addEventListener(
273 268 'submit',
@@ -280,22 +275,22 @@
280 275 );
281 276
282 277 const title = getLabel( __( 'What will you call the new page?', 'formidable' ) );
283 278 title.setAttribute( 'for', 'frm_name_your_page' );
284 - form.append( title );
279 + form.appendChild( title );
285 280
286 281 const input = tag( 'input' );
287 282 input.id = 'frm_name_your_page';
288 283 input.placeholder = __( 'Name your page', 'formidable' );
289 - form.append( input );
284 + form.appendChild( input );
290 285
291 - wrapper.append( form );
292 - content.append( wrapper );
286 + wrapper.appendChild( form );
287 + content.appendChild( wrapper );
293 288
294 289 input.type = 'text';
295 290 input.focus();
296 291
297 - const doneButton = modal.querySelector( '.frm_modal_footer .button-primary' );
292 + doneButton = modal.querySelector( '.frm_modal_footer .button-primary' );
298 293 doneButton.textContent = __( 'Create page', 'formidable' );
299 294 doneButton.addEventListener(
300 295 'click',
301 296 function( event ) {
@@ -312,9 +307,9 @@
312 307 callback: () => {
313 308 content.innerHTML = '';
314 309
315 310 if ( 'form' === state.type ) {
316 - getEmbedFormManualExamples().forEach( example => content.append( getEmbedExample( example ) ) );
311 + getEmbedFormManualExamples().forEach( example => content.appendChild( getEmbedExample( example ) ) );
317 312 } else {
318 313 const hookName = 'frm_embed_examples';
319 314 const hookArgs = {
320 315 type: state.type,
@@ -321,9 +316,9 @@
321 316 objectId: state.objectId,
322 317 objectKey: state.objectKey
323 318 };
324 319 wp.hooks.applyFilters( hookName, [], hookArgs ).forEach(
325 - example => content.append( getEmbedExample( example ) )
320 + example => content.appendChild( getEmbedExample( example ) )
326 321 );
327 322 }
328 323 }
329 324 }
@@ -329,9 +324,9 @@
329 324 }
330 325 ];
331 326
332 327 options.forEach(
333 - option => content.append( getModalOption( option ) )
328 + option => content.appendChild( getModalOption( option ) )
334 329 );
335 330
336 331 return content;
337 332 }
@@ -345,22 +340,20 @@
345 340 return __( 'form', 'formidable' );
346 341 }
347 342 }
348 343
349 - function getModalOption( { icon, label, description, callback } ) {
344 + function getModalOption({ icon, label, description, callback }) {
350 345 const output = div();
351 - output.append( wrapModalOptionIcon( icon ) );
346 + output.appendChild( wrapModalOptionIcon( icon ) );
352 347 output.className = 'frm-embed-modal-option';
353 348 output.setAttribute( 'tabindex', 0 );
354 349 output.setAttribute( 'role', 'button' );
355 350
356 351 const textWrapper = div();
357 - textWrapper.append( getLabel( label ) );
358 - textWrapper.append( div( description ) );
359 - output.append( textWrapper );
352 + textWrapper.appendChild( getLabel( label ) );
353 + textWrapper.appendChild( div( description ) );
354 + output.appendChild( textWrapper );
360 355
361 - output.append( div( { className: 'caret' } ) );
362 -
363 356 output.addEventListener(
364 357 'click',
365 358 function() {
366 359 modal.classList.add( 'frm-on-page-2' );
@@ -370,12 +363,12 @@
370 363 return output;
371 364 }
372 365
373 366 function wrapModalOptionIcon( iconHref ) {
374 - return div( {
375 - className: 'frm-icon-wrapper',
376 - child: svg( { href: iconHref } )
377 - } );
367 + return div({
368 + className: 'frm-embed-modal-icon-wrapper',
369 + child: svg({ href: iconHref })
370 + });
378 371 }
379 372
380 373 function getEmbedFormManualExamples() {
381 374 const formId = state.objectId;
@@ -383,15 +376,15 @@
383 376
384 377 let examples = [
385 378 {
386 379 label: __( 'WordPress shortcode', 'formidable' ),
387 - example: `[formidable id=${ formId }]`,
380 + example: '[formidable id=' + formId + ' title=true description=true]',
388 381 link: 'https://formidableforms.com/knowledgebase/publish-a-form/#kb-insert-the-shortcode-manually',
389 382 linkLabel: __( 'How to use shortcodes in WordPress', 'formidable' )
390 383 },
391 384 {
392 385 label: __( 'Use PHP code', 'formidable' ),
393 - example: `<?php echo FrmFormsController::get_form_shortcode( array( 'id' => ${ formId } ) ); ?>`
386 + example: '<?php echo FrmFormsController::get_form_shortcode( array( \'id\' => ' + formId + ', \'title\' => true, \'description\' => true ) ); ?>'
394 387 }
395 388 ];
396 389
397 390 const filterArgs = { formId, formKey };
@@ -399,18 +392,18 @@
399 392
400 393 return examples;
401 394 }
402 395
403 - function getEmbedExample( { label, example, link, linkLabel } ) {
404 - const unique = getAutoId();
396 + function getEmbedExample({ label, example, link, linkLabel }) {
397 + let unique, element, labelElement, exampleElement, linkElement;
405 398
406 - const labelElement = getLabel( label );
407 - labelElement.id = `frm_embed_example_label_${ unique }`;
399 + unique = getAutoId();
400 + element = div();
408 401
409 - const element = div();
410 - element.append( labelElement );
402 + labelElement = getLabel( label );
403 + labelElement.id = 'frm_embed_example_label_' + unique;
404 + element.appendChild( labelElement );
411 405
412 - let exampleElement;
413 406 if ( example.length > 80 ) {
414 407 exampleElement = tag( 'textarea' );
415 408 } else {
416 409 exampleElement = tag( 'input' );
@@ -416,24 +409,24 @@
416 409 exampleElement = tag( 'input' );
417 410 exampleElement.type = 'text';
418 411 }
419 412
420 - exampleElement.id = `frm_embed_example_${ unique }`;
413 + exampleElement.id = 'frm_embed_example_' + unique;
421 414 exampleElement.className = 'frm_embed_example';
422 415 exampleElement.value = example;
423 416 exampleElement.readOnly = true;
424 417 exampleElement.setAttribute( 'tabindex', -1 );
425 418
426 - if ( link !== undefined && linkLabel !== undefined ) {
427 - const linkElement = tag( 'a' );
419 + if ( 'undefined' !== typeof link && 'undefined' !== typeof linkLabel ) {
420 + linkElement = tag( 'a' );
428 421 linkElement.href = link;
429 422 linkElement.textContent = linkLabel;
430 423 linkElement.setAttribute( 'target', '_blank' );
431 - element.append( linkElement );
424 + element.appendChild( linkElement );
432 425 }
433 426
434 - element.append( exampleElement );
435 - element.append( getCopyIcon( label ) );
427 + element.appendChild( exampleElement );
428 + element.appendChild( getCopyIcon( label ) );
436 429
437 430 return element;
438 431 }
439 432
@@ -442,14 +435,14 @@
442 435 return tag( 'label', args );
443 436 }
444 437
445 438 function getCopyIcon( label ) {
446 - const icon = svg( { href: '#frm_clone_icon' } );
447 - icon.id = `frm_copy_embed_${ getAutoId() }`;
439 + const icon = svg({ href: '#frm_clone_icon' });
440 + icon.id = 'frm_copy_embed_' + getAutoId();
448 441 icon.setAttribute( 'tabindex', 0 );
449 442 icon.setAttribute( 'role', 'button' );
450 443 /* translators: %s: Example type (ie. WordPress shortcode, API Form script) */
451 - icon.setAttribute( 'aria-label', sprintf( __( 'Copy %s', 'formidable' ), label ) );
444 + icon.setAttribute( 'aria-label', __( 'Copy %s', 'formidable' ).replace( '%s', label ) );
452 445 icon.addEventListener(
453 446 'click',
454 447 () => copyExampleToClipboard( icon.parentNode.querySelector( '.frm_embed_example' ) )
455 448 );
@@ -486,17 +479,17 @@
486 479 }
487 480
488 481 function speak( message ) {
489 482 const element = document.createElement( 'div' );
490 - const id = `speak-${ getAutoId() }`;
483 + const id = 'speak-' + getAutoId();
491 484
492 485 element.setAttribute( 'aria-live', 'assertive' );
493 486 element.setAttribute( 'id', id );
494 487 element.className = 'frm_screen_reader frm_hidden';
495 488 element.textContent = message;
496 - document.body.append( element );
489 + document.body.appendChild( element );
497 490
498 - setTimeout( () => element.remove(), 1000 );
491 + setTimeout( () => document.body.removeChild( element ), 1000 );
499 492 }
500 493
501 494 /**
502 495 * Get a unique id that automatically increments with every function call.
@@ -502,9 +495,9 @@
502 495 * Get a unique id that automatically increments with every function call.
503 496 * Can be used for any UI that requires a unique id.
504 497 * Not to be used in data.
505 498 *
506 - * @return {number} The unique id.
499 + * @returns {integer}
507 500 */
508 501 function getAutoId() {
509 502 return ++autoId;
510 503 }