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.js +1 -10643 6.4.1 → trunk View file →
@@ -1,10643 +1 @@
1 -/* exported frm_add_logic_row, frm_remove_tag, frm_show_div, frmCheckAll, frmCheckAllLevel */
2 -
3 -var frmAdminBuild;
4 -
5 -var FrmFormsConnect = window.FrmFormsConnect || ( function( document, window, $ ) {
6 -
7 - /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl */
8 -
9 - var el = {
10 - licenseBox: document.getElementById( 'frm_license_top' ),
11 - messageBox: document.getElementsByClassName( 'frm_pro_license_msg' )[0],
12 - btn: document.getElementById( 'frm-settings-connect-btn' ),
13 - reset: document.getElementById( 'frm_reconnect_link' )
14 - };
15 -
16 - /**
17 - * Public functions and properties.
18 - *
19 - * @since 4.03
20 - *
21 - * @type {Object}
22 - */
23 - var app = {
24 -
25 - /**
26 - * Register connect button event.
27 - *
28 - * @since 4.03
29 - */
30 - init: function() {
31 - $( document.getElementById( 'frm_deauthorize_link' ) ).on( 'click', app.deauthorize );
32 - $( '.frm_authorize_link' ).on( 'click', app.authorize );
33 - if ( el.reset !== null ) {
34 - $( el.reset ).on( 'click', app.reauthorize );
35 - }
36 -
37 - $( el.btn ).on( 'click', function( e ) {
38 - e.preventDefault();
39 - app.gotoUpgradeUrl();
40 - });
41 -
42 - window.addEventListener( 'message', function( msg ) {
43 - if ( msg.origin.replace( /\/$/, '' ) !== frmGlobal.app_url.replace( /\/$/, '' ) ) {
44 - return;
45 - }
46 -
47 - if ( ! msg.data || 'object' !== typeof msg.data ) {
48 - console.error( 'Messages from "' + frmGlobal.app_url + '" must contain an api key string.' );
49 - return;
50 - }
51 -
52 - app.updateForm( msg.data );
53 - });
54 -
55 - jQuery( document ).on( 'mouseover', '#frm_new_form_modal .frm-selectable', function() {
56 - var $item = jQuery( this ),
57 - $icons = $item.find( '.frm-hover-icons' ),
58 - $clone;
59 -
60 - if ( ! $icons.length ) {
61 - $clone = jQuery( '#frm-hover-icons-template' ).clone();
62 - $clone.removeAttr( 'id' );
63 - $item.append( $clone );
64 - }
65 -
66 - $icons.show();
67 - });
68 -
69 - jQuery( document ).on( 'mouseout', '#frm_new_form_modal .frm-selectable', function() {
70 - var $item = jQuery( this ),
71 - $icons = $item.find( '.frm-hover-icons' );
72 -
73 - if ( $icons.length ) {
74 - $icons.hide();
75 - }
76 - });
77 - },
78 -
79 - /**
80 - * Go to upgrade url.
81 - *
82 - * @since 4.03
83 - */
84 - gotoUpgradeUrl: function() {
85 - var w = window.open( frmGlobal.app_url + '/api-connect/', '_blank', 'location=no,width=500,height=730,scrollbars=0' );
86 - w.focus();
87 - },
88 -
89 - updateForm: function( response ) {
90 -
91 - // Start spinner.
92 - var btn = el.btn;
93 - btn.classList.add( 'frm_loading_button' );
94 -
95 - if ( response.url !== '' ) {
96 - app.showProgress({
97 - success: true,
98 - message: 'Installing...'
99 - });
100 - var fallback = setTimeout( function() {
101 - app.showProgress({
102 - success: true,
103 - message: 'Installing is taking longer than expected. <a class="frm-install-addon button button-primary frm-button-primary" rel="' + response.url + '" aria-label="Install">Install Now</a>'
104 - });
105 - }, 10000 );
106 - $.ajax({
107 - type: 'POST',
108 - url: ajaxurl,
109 - dataType: 'json',
110 - data: {
111 - action: 'frm_connect',
112 - plugin: response.url,
113 - nonce: frmGlobal.nonce
114 - },
115 - success: function() {
116 - clearTimeout( fallback );
117 - app.activateKey( response );
118 - },
119 - error: function( xhr, textStatus, e ) {
120 - clearTimeout( fallback );
121 - btn.classList.remove( 'frm_loading_button' );
122 - app.showMessage({
123 - success: false,
124 - message: e
125 - });
126 - }
127 - });
128 - } else if ( response.key !== '' ) {
129 - app.activateKey( response );
130 - }
131 - },
132 -
133 - activateKey: function( response ) {
134 - var btn = el.btn;
135 - if ( response.key === '' ) {
136 - btn.classList.remove( 'frm_loading_button' );
137 - } else {
138 - app.showProgress({
139 - success: true,
140 - message: 'Activating...'
141 - });
142 - $.ajax({
143 - type: 'POST',
144 - url: ajaxurl,
145 - dataType: 'json',
146 - data: {
147 - action: 'frm_addon_activate',
148 - license: response.key,
149 - plugin: 'formidable_pro',
150 - wpmu: 0,
151 - nonce: frmGlobal.nonce
152 - },
153 - success: function( msg ) {
154 - btn.classList.remove( 'frm_loading_button' );
155 -
156 - if ( msg.success === true ) {
157 - el.licenseBox.classList.replace( 'frm_unauthorized_box', 'frm_authorized_box' );
158 - }
159 -
160 - app.showMessage( msg );
161 - },
162 - error: function( xhr, textStatus, e ) {
163 - btn.classList.remove( 'frm_loading_button' );
164 - app.showMessage({
165 - success: false,
166 - message: e
167 - });
168 - }
169 - });
170 - }
171 - },
172 -
173 - /* Manual license authorization */
174 - authorize: function() {
175 - /*jshint validthis:true */
176 - var button = this;
177 - var pluginSlug = this.getAttribute( 'data-plugin' );
178 - var input = document.getElementById( 'edd_' + pluginSlug + '_license_key' );
179 - var license = input.value;
180 - var wpmu = document.getElementById( 'proplug-wpmu' );
181 - this.classList.add( 'frm_loading_button' );
182 - if ( wpmu === null ) {
183 - wpmu = 0;
184 - } else if ( wpmu.checked ) {
185 - wpmu = 1;
186 - } else {
187 - wpmu = 0;
188 - }
189 -
190 - $.ajax({
191 - type: 'POST', url: ajaxurl, dataType: 'json',
192 - data: {
193 - action: 'frm_addon_activate',
194 - license: license,
195 - plugin: pluginSlug,
196 - wpmu: wpmu,
197 - nonce: frmGlobal.nonce
198 - },
199 - success: function( msg ) {
200 - app.afterAuthorize( msg, input );
201 - button.classList.remove( 'frm_loading_button' );
202 - }
203 - });
204 - },
205 -
206 - afterAuthorize: function( msg, input ) {
207 - if ( msg.success === true ) {
208 - input.value = '•••••••••••••••••••';
209 - }
210 -
211 - app.showMessage( msg );
212 - },
213 -
214 - showProgress: function( msg ) {
215 - var messageBox = el.messageBox;
216 - if ( msg.success === true ) {
217 - messageBox.classList.remove( 'frm_error_style' );
218 - messageBox.classList.add( 'frm_message', 'frm_updated_message' );
219 - } else {
220 - messageBox.classList.add( 'frm_error_style' );
221 - messageBox.classList.remove( 'frm_message', 'frm_updated_message' );
222 - }
223 - messageBox.classList.remove( 'frm_hidden' );
224 - messageBox.innerHTML = msg.message;
225 - },
226 -
227 - showMessage: function( msg ) {
228 - var messageBox = el.messageBox;
229 -
230 - if ( msg.success === true ) {
231 - var d = el.licenseBox;
232 - d.className = d.className.replace( 'frm_unauthorized_box', 'frm_authorized_box' );
233 - messageBox.classList.remove( 'frm_error_style' );
234 - messageBox.classList.add( 'frm_message', 'frm_updated_message' );
235 - } else {
236 - messageBox.classList.add( 'frm_error_style' );
237 - messageBox.classList.remove( 'frm_message', 'frm_updated_message' );
238 - }
239 -
240 - messageBox.classList.remove( 'frm_hidden' );
241 - messageBox.innerHTML = msg.message;
242 - if ( msg.message !== '' ) {
243 - setTimeout( function() {
244 - messageBox.innerHTML = '';
245 - messageBox.classList.add( 'frm_hidden' );
246 - messageBox.classList.remove( 'frm_error_style', 'frm_message', 'frm_updated_message' );
247 - }, 10000 );
248 - var refreshPage = document.querySelectorAll( '#frm-welcome' );
249 - if ( refreshPage.length > 0 ) {
250 - window.location.reload();
251 - }
252 - }
253 - },
254 -
255 - /* Clear the site license cache */
256 - reauthorize: function() {
257 - /*jshint validthis:true */
258 - this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;float:none"></span>';
259 -
260 - $.ajax({
261 - type: 'POST',
262 - url: ajaxurl,
263 - dataType: 'json',
264 - data: {
265 - action: 'frm_reset_cache',
266 - plugin: 'formidable_pro',
267 - nonce: frmGlobal.nonce
268 - },
269 - success: function( msg ) {
270 - el.reset.textContent = msg.message;
271 - if ( el.reset.getAttribute( 'data-refresh' ) === '1' ) {
272 - window.location.reload();
273 - }
274 - }
275 - });
276 - return false;
277 - },
278 -
279 - deauthorize: function() {
280 - /*jshint validthis:true */
281 - if ( ! confirm( frmGlobal.deauthorize ) ) {
282 - return false;
283 - }
284 - var pluginSlug = this.getAttribute( 'data-plugin' ),
285 - input = document.getElementById( 'edd_' + pluginSlug + '_license_key' ),
286 - license = input.value,
287 - link = this;
288 -
289 - this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;"></span>';
290 -
291 - $.ajax({
292 - type: 'POST',
293 - url: ajaxurl,
294 - data: {
295 - action: 'frm_addon_deactivate',
296 - license: license,
297 - plugin: pluginSlug,
298 - nonce: frmGlobal.nonce
299 - },
300 - success: function() {
301 - el.licenseBox.className = el.licenseBox.className.replace( 'frm_authorized_box', 'frm_unauthorized_box' );
302 - input.value = '';
303 - link.innerHTML = '';
304 - }
305 - });
306 - return false;
307 - }
308 - };
309 -
310 - // Provide access to public functions/properties.
311 - return app;
312 -
313 -}( document, window, jQuery ) );
314 -
315 -function frmAdminBuildJS() {
316 - //'use strict';
317 -
318 - /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl, fromDom */
319 -
320 - const { tag, div, span, a, svg, img } = frmDom;
321 - const { onClickPreventDefault } = frmDom.util;
322 - const { doJsonFetch, doJsonPost } = frmDom.ajax;
323 - const icons = {
324 - save: svg({ href: '#frm_save_icon' }),
325 - drag: svg({ href: '#frm_drag_icon', classList: [ 'frm_drag_icon', 'frm-drag' ] })
326 - };
327 -
328 - let $newFields = jQuery( document.getElementById( 'frm-show-fields' ) ),
329 - builderForm = document.getElementById( 'new_fields' ),
330 - thisForm = document.getElementById( 'form_id' ),
331 - copyHelper = false,
332 - fieldsUpdated = 0,
333 - thisFormId = 0,
334 - autoId = 0,
335 - optionMap = {},
336 - lastNewActionIdReturned = 0;
337 -
338 - const { __ } = wp.i18n;
339 - let debouncedSyncAfterDragAndDrop, postBodyContent, $postBodyContent;
340 -
341 - if ( thisForm !== null ) {
342 - thisFormId = thisForm.value;
343 - }
344 -
345 - // Global settings
346 - var s;
347 -
348 - function showElement( element ) {
349 - element[0].style.display = '';
350 - }
351 -
352 - function hideElement( element ) {
353 - element[0].style.display = 'none';
354 - }
355 -
356 - function empty( $obj ) {
357 - if ( $obj !== null ) {
358 - while ( $obj.firstChild ) {
359 - $obj.removeChild( $obj.firstChild );
360 - }
361 - }
362 - }
363 -
364 - function addClass( $obj, className ) {
365 - if ( $obj.classList ) {
366 - $obj.classList.add( className );
367 - } else {
368 - $obj.className += ' ' + className;
369 - }
370 - }
371 -
372 - function confirmClick( e ) {
373 - /*jshint validthis:true */
374 - e.stopPropagation();
375 - e.preventDefault();
376 - confirmLinkClick( this );
377 - }
378 -
379 - function confirmLinkClick( link ) {
380 - var message = link.getAttribute( 'data-frmverify' );
381 -
382 - if ( message === null || link.id === 'frm-confirmed-click' ) {
383 - return true;
384 - } else {
385 - return confirmModal( link );
386 - }
387 - }
388 -
389 - function confirmModal( link ) {
390 - var verify, $confirmMessage, i, dataAtts, btnClass,
391 - $info = initModal( '#frm_confirm_modal', '400px' ),
392 - continueButton = document.getElementById( 'frm-confirmed-click' );
393 -
394 - if ( $info === false ) {
395 - return false;
396 - }
397 -
398 - verify = link.getAttribute( 'data-frmverify' );
399 - btnClass = verify ? link.getAttribute( 'data-frmverify-btn' ) : '';
400 - $confirmMessage = jQuery( '.frm-confirm-msg' );
401 - $confirmMessage.empty();
402 -
403 - if ( verify ) {
404 - $confirmMessage.append( document.createTextNode( verify ) );
405 - if ( btnClass ) {
406 - continueButton.classList.add( btnClass );
407 - }
408 - }
409 -
410 - removeAtts = continueButton.dataset;
411 - for ( i in dataAtts ) {
412 - continueButton.removeAttribute( 'data-' + i );
413 - }
414 -
415 - dataAtts = link.dataset;
416 - for ( i in dataAtts ) {
417 - if ( i !== 'frmverify' ) {
418 - continueButton.setAttribute( 'data-' + i, dataAtts[i]);
419 - }
420 - }
421 -
422 - $info.dialog( 'open' );
423 - continueButton.setAttribute( 'href', link.getAttribute( 'href' ) );
424 - return false;
425 - }
426 -
427 - function infoModal( msg ) {
428 - var $info = initModal( '#frm_info_modal', '400px' );
429 -
430 - if ( $info === false ) {
431 - return false;
432 - }
433 -
434 - jQuery( '.frm-info-msg' ).html( msg );
435 -
436 - $info.dialog( 'open' );
437 - return false;
438 - }
439 -
440 - function toggleItem( e ) {
441 - /*jshint validthis:true */
442 - var toggle = this.getAttribute( 'data-frmtoggle' ),
443 - text = this.getAttribute( 'data-toggletext' ),
444 - items = jQuery( toggle );
445 -
446 - e.preventDefault();
447 -
448 - if ( items.is( ':visible' ) ) {
449 - items.show();
450 - } else {
451 - items.hide();
452 - }
453 -
454 - if ( text !== null && text !== '' ) {
455 - this.setAttribute( 'data-toggletext', this.innerHTML );
456 - this.textContent = text;
457 - }
458 -
459 - return false;
460 - }
461 -
462 - /**
463 - * Toggle a class on target elements when an anchor is clicked, or when a radio or checkbox has been selected.
464 - *
465 - * @param {Event} e Event with either the change or click type.
466 - * @returns {false}
467 - */
468 - function hideShowItem( e ) {
469 - /*jshint validthis:true */
470 - let hide = this.getAttribute( 'data-frmhide' );
471 - let show = this.getAttribute( 'data-frmshow' );
472 -
473 - // Flip unchecked checkboxes so an off value undoes the on value.
474 - if ( isUncheckedCheckbox( this ) ) {
475 - if ( hide !== null ) {
476 - show = hide;
477 - hide = null;
478 - } else if ( show !== null ) {
479 - hide = show;
480 - show = null;
481 - }
482 - }
483 -
484 - e.preventDefault();
485 -
486 - const toggleClass = this.getAttribute( 'data-toggleclass' ) || 'frm_hidden';
487 -
488 - if ( hide !== null ) {
489 - jQuery( hide ).addClass( toggleClass );
490 - }
491 -
492 - if ( show !== null ) {
493 - jQuery( show ).removeClass( toggleClass );
494 - }
495 -
496 - var current = this.parentNode.querySelectorAll( 'a.current' );
497 - if ( current !== null ) {
498 - for ( var i = 0; i < current.length; i++ ) {
499 - current[ i ].classList.remove( 'current' );
500 - }
501 - this.classList.add( 'current' );
502 - }
503 -
504 - return false;
505 - }
506 -
507 - function isUncheckedCheckbox( element ) {
508 - return 'INPUT' === element.nodeName && 'checkbox' === element.type && ! element.checked;
509 - }
510 -
511 - function setupMenuOffset() {
512 - window.onscroll = document.documentElement.onscroll = setMenuOffset;
513 - setMenuOffset();
514 - }
515 -
516 - function setMenuOffset() {
517 - var fields = document.getElementById( 'frm_adv_info' );
518 - if ( fields === null ) {
519 - return;
520 - }
521 -
522 - var currentOffset = document.documentElement.scrollTop || document.body.scrollTop; // body for Safari
523 - if ( currentOffset === 0 ) {
524 - fields.classList.remove( 'frm_fixed' );
525 - return;
526 - }
527 -
528 - var posEle = document.getElementById( 'frm_position_ele' );
529 - if ( posEle === null ) {
530 - return;
531 - }
532 -
533 - var eleOffset = jQuery( posEle ).offset();
534 - var offset = eleOffset.top;
535 - var desiredOffset = offset - currentOffset;
536 - var menuHeight = 0;
537 -
538 - var menu = document.getElementById( 'wpadminbar' );
539 - if ( menu !== null ) {
540 - menuHeight = menu.offsetHeight;
541 - }
542 -
543 - if ( desiredOffset < menuHeight ) {
544 - desiredOffset = menuHeight;
545 - }
546 -
547 - if ( desiredOffset > menuHeight ) {
548 - fields.classList.remove( 'frm_fixed' );
549 - } else {
550 - fields.classList.add( 'frm_fixed' );
551 - if ( desiredOffset !== 32 ) {
552 - fields.style.top = desiredOffset + 'px';
553 - }
554 - }
555 - }
556 -
557 - function loadTooltips() {
558 - var wrapClass = jQuery( '.wrap, .frm_wrap' ),
559 - confirmModal = document.getElementById( 'frm_confirm_modal' ),
560 - doAction = false,
561 - confirmedBulkDelete = false;
562 -
563 - jQuery( confirmModal ).on( 'click', '[data-deletefield]', deleteFieldConfirmed );
564 - jQuery( confirmModal ).on( 'click', '[data-removeid]', removeThisTag );
565 - jQuery( confirmModal ).on( 'click', '[data-trashtemplate]', trashTemplate );
566 -
567 - wrapClass.on( 'click', '.frm_remove_tag, .frm_remove_form_action', removeThisTag );
568 - wrapClass.on( 'click', 'a[data-frmverify]', confirmClick );
569 - wrapClass.on( 'click', 'a[data-frmtoggle]', toggleItem );
570 - wrapClass.on( 'click', 'a[data-frmhide], a[data-frmshow]', hideShowItem );
571 - wrapClass.on( 'change', 'input[data-frmhide], input[data-frmshow]', hideShowItem );
572 - wrapClass.on( 'click', '.widget-top,a.widget-action', clickWidget );
573 -
574 - wrapClass.on( 'mouseenter.frm', '.frm_bstooltip, .frm_help', function() {
575 - jQuery( this ).off( 'mouseenter.frm' );
576 -
577 - jQuery( '.frm_bstooltip, .frm_help' ).tooltip( );
578 - jQuery( this ).tooltip( 'show' );
579 - });
580 -
581 - jQuery( '.frm_bstooltip, .frm_help' ).tooltip( );
582 -
583 - jQuery( document ).on( 'click', '#doaction, #doaction2', function( event ) {
584 - var isTop = this.id === 'doaction',
585 - suffix = isTop ? 'top' : 'bottom',
586 - bulkActionSelector = document.getElementById( 'bulk-action-selector-' + suffix ),
587 - confirmBulkDelete = document.getElementById( 'confirm-bulk-delete-' + suffix );
588 -
589 - if ( bulkActionSelector !== null && confirmBulkDelete !== null ) {
590 - doAction = this;
591 -
592 - if ( ! confirmedBulkDelete && bulkActionSelector.value === 'bulk_delete' ) {
593 - event.preventDefault();
594 - confirmLinkClick( confirmBulkDelete );
595 - return false;
596 - }
597 - } else {
598 - doAction = false;
599 - }
600 - });
601 -
602 - jQuery( document ).on( 'click', '#frm-confirmed-click', function( event ) {
603 - if ( doAction === false ) {
604 - return;
605 - }
606 -
607 - if ( this.getAttribute( 'href' ) === 'confirm-bulk-delete' ) {
608 - event.preventDefault();
609 - confirmedBulkDelete = true;
610 - doAction.click();
611 - return false;
612 - }
613 - });
614 - }
615 -
616 - function deleteTooltips() {
617 - document.querySelectorAll( '.tooltip' ).forEach(
618 - function( tooltip ) {
619 - tooltip.remove();
620 - }
621 - );
622 - }
623 -
624 - function removeThisTag() {
625 - /*jshint validthis:true */
626 - let show, hide, removeMore;
627 -
628 - if ( parseInt( this.getAttribute( 'data-skip-frm-js' ) ) || confirmLinkClick( this ) === false ) {
629 - return;
630 - }
631 -
632 - const deleteButton = jQuery( this );
633 - const id = deleteButton.attr( 'data-removeid' );
634 -
635 - show = deleteButton.attr( 'data-showlast' );
636 - if ( typeof show === 'undefined' ) {
637 - show = '';
638 - }
639 -
640 - hide = deleteButton.attr( 'data-hidelast' );
641 - if ( typeof hide === 'undefined' ) {
642 - hide = '';
643 - }
644 -
645 - removeMore = deleteButton.attr( 'data-removemore' );
646 -
647 - if ( show !== '' ) {
648 - if ( deleteButton.closest( '.frm_add_remove' ).find( '.frm_remove_tag:visible' ).length > 1 ) {
649 - show = '';
650 - hide = '';
651 - }
652 - } else if ( id.indexOf( 'frm_postmeta_' ) === 0 ) {
653 - if ( jQuery( '#frm_postmeta_rows .frm_postmeta_row' ).length < 2 ) {
654 - show = '.frm_add_postmeta_row.button';
655 - }
656 - if ( jQuery( '.frm_toggle_cf_opts' ).length && jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().length ) {
657 - if ( show !== '' ) {
658 - show += ',';
659 - }
660 - show += '#' + jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().attr( 'id' ) + ' .frm_toggle_cf_opts';
661 - }
662 - }
663 -
664 - const $fadeEle = jQuery( document.getElementById( id ) );
665 - $fadeEle.fadeOut( 400, function() {
666 - $fadeEle.remove();
667 - fieldUpdated();
668 -
669 - if ( hide !== '' ) {
670 - jQuery( hide ).hide();
671 - }
672 -
673 - if ( show !== '' ) {
674 - jQuery( show + ' a,' + show ).removeClass( 'frm_hidden' ).fadeIn( 'slow' );
675 - }
676 -
677 - if ( this.closest( '.frm_form_action_settings' ) ) {
678 - const type = this.closest( '.frm_form_action_settings' ).querySelector( '.frm_action_name' ).value;
679 - afterActionRemoved( type );
680 - }
681 - });
682 -
683 - if ( typeof removeMore !== 'undefined' ) {
684 - removeMore = jQuery( removeMore );
685 - removeMore.fadeOut( 400, function() {
686 - removeMore.remove();
687 - });
688 - }
689 -
690 - if ( show !== '' ) {
691 - jQuery( this ).closest( '.frm_logic_rows' ).fadeOut( 'slow' );
692 - }
693 -
694 - return false;
695 - }
696 -
697 - function afterActionRemoved( type ) {
698 - checkActiveAction( type );
699 -
700 - const hookName = 'frm_after_action_removed';
701 - const hookArgs = { type };
702 - wp.hooks.doAction( hookName, hookArgs );
703 - }
704 -
705 - function clickWidget( event, b ) {
706 - /*jshint validthis:true */
707 - if ( typeof b === 'undefined' ) {
708 - b = this;
709 - }
710 -
711 - popCalcFields( b, false );
712 -
713 - const cont = jQuery( b ).closest( '.frm_form_action_settings' );
714 - const target = event.target;
715 -
716 - if ( cont.length && typeof target !== 'undefined' ) {
717 - const className = target.parentElement.className;
718 - if ( 'string' === typeof className ) {
719 - if ( className.indexOf( 'frm_email_icons' ) > -1 || className.indexOf( 'frm_toggle' ) > -1 ) {
720 - // clicking on delete icon shouldn't open it
721 - event.stopPropagation();
722 - return;
723 - }
724 - }
725 - }
726 -
727 - let inside = cont.children( '.widget-inside' );
728 -
729 - if ( cont.length && inside.find( 'p, div, table' ).length < 1 ) {
730 - const actionId = cont.find( 'input[name$="[ID]"]' ).val();
731 - const actionType = cont.find( 'input[name$="[post_excerpt]"]' ).val();
732 - if ( actionType ) {
733 - inside.html( '<span class="frm-wait frm_spinner"></span>' );
734 - cont.find( '.spinner' ).fadeIn( 'slow' );
735 - jQuery.ajax({
736 - type: 'POST',
737 - url: ajaxurl,
738 - data: {
739 - action: 'frm_form_action_fill',
740 - action_id: actionId,
741 - action_type: actionType,
742 - nonce: frmGlobal.nonce
743 - },
744 - success: function( html ) {
745 - inside.html( html );
746 - initiateMultiselect();
747 - showInputIcon( '#' + cont.attr( 'id' ) );
748 - frmDom.autocomplete.initAutocomplete( 'page', inside );
749 - jQuery( b ).trigger( 'frm-action-loaded' );
750 -
751 - /**
752 - * Fires after filling form action content when opening.
753 - *
754 - * @since 5.5.4
755 - *
756 - * @param {Object} insideElement JQuery object of form action inside element.
757 - */
758 - wp.hooks.doAction( 'frm_filled_form_action', inside );
759 - }
760 - });
761 - }
762 - }
763 -
764 - jQuery( b ).closest( '.frm_field_box' ).siblings().find( '.widget-inside' ).slideUp( 'fast' );
765 - if ( ( typeof b.className !== 'undefined' && b.className.indexOf( 'widget-action' ) !== -1 ) || jQuery( b ).closest( '.start_divider' ).length < 1 ) {
766 - return;
767 - }
768 -
769 - inside = jQuery( b ).closest( 'div.widget' ).children( '.widget-inside' );
770 - if ( inside.is( ':hidden' ) ) {
771 - inside.slideDown( 'fast' );
772 - } else {
773 - inside.slideUp( 'fast' );
774 - }
775 - }
776 -
777 - function clickNewTab() {
778 - /*jshint validthis:true */
779 - var t = this.getAttribute( 'href' ),
780 - c = t.replace( '#', '.' ),
781 - $link = jQuery( this );
782 -
783 - if ( typeof t === 'undefined' ) {
784 - return false;
785 - }
786 -
787 - $link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' );
788 - $link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide();
789 - document.getElementById( t.replace( '#', '' ) ).style.display = 'block';
790 -
791 - if ( this.id === 'frm_insert_fields_tab' ) {
792 - clearSettingsBox();
793 - }
794 - return false;
795 - }
796 -
797 - function clickTab( link, auto ) {
798 - link = jQuery( link );
799 - var t = link.attr( 'href' );
800 - if ( typeof t === 'undefined' ) {
801 - return;
802 - }
803 -
804 - var c = t.replace( '#', '.' );
805 -
806 - link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' );
807 - if ( link.closest( 'div' ).find( '.tabs-panel' ).length ) {
808 - link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide();
809 - } else {
810 - if ( document.getElementById( 'form_global_settings' ) !== null ) {
811 - /* global settings */
812 - var ajax = link.data( 'frmajax' );
813 - link.closest( '.frm_wrap' ).find( '.tabs-panel, .hide_with_tabs' ).hide();
814 - if ( typeof ajax !== 'undefined' && ajax == '1' ) {
815 - loadSettingsTab( t );
816 - }
817 - } else {
818 - /* form settings page */
819 - jQuery( '#frm-categorydiv .tabs-panel, .hide_with_tabs' ).hide();
820 - }
821 - }
822 - jQuery( t ).show();
823 - jQuery( c ).show();
824 -
825 - hideShortcodes();
826 -
827 - if ( auto !== 'auto' ) {
828 - // Hide success message on tab change.
829 - jQuery( '.frm_updated_message' ).hide();
830 - jQuery( '.frm_warning_style' ).hide();
831 - }
832 -
833 - if ( jQuery( link ).closest( '#frm_adv_info' ).length ) {
834 - return;
835 - }
836 -
837 - if ( jQuery( '.frm_form_settings' ).length ) {
838 - jQuery( '.frm_form_settings' ).attr( 'action', '?page=formidable&frm_action=settings&id=' + jQuery( '.frm_form_settings input[name="id"]' ).val() + '&t=' + t.replace( '#', '' ) );
839 - } else {
840 - jQuery( '.frm_settings_form' ).attr( 'action', '?page=formidable-settings&t=' + t.replace( '#', '' ) );
841 - }
842 - }
843 -
844 - function setupSortable( sortableSelector ) {
845 - document.querySelectorAll( sortableSelector ).forEach(
846 - list => {
847 - makeDroppable( list );
848 - Array.from( list.children ).forEach( child => makeDraggable( child, '.frm-move' ) );
849 -
850 - const $sectionTitle = jQuery( list ).children( '[data-type="divider"]' ).children( '.divider_section_only' );
851 - if ( $sectionTitle.length ) {
852 - makeDroppable( $sectionTitle );
853 - }
854 - }
855 - );
856 - setupFieldOptionSorting( jQuery( '#frm_builder_page' ) );
857 - }
858 -
859 - function makeDroppable( list ) {
860 - jQuery( list ).droppable({
861 - accept: '.frmbutton, li.frm_field_box',
862 - deactivate: handleFieldDrop,
863 - over: onDragOverDroppable,
864 - out: onDraggableLeavesDroppable,
865 - tolerance: 'pointer'
866 - });
867 - }
868 -
869 - function onDragOverDroppable( event, ui ) {
870 - const droppable = getDroppableForOnDragOver( event.target );
871 - const draggable = ui.draggable[0];
872 -
873 - if ( ! allowDrop( draggable, droppable ) ) {
874 - droppable.classList.remove( 'frm-over-droppable' );
875 - jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' );
876 - return;
877 - }
878 -
879 - document.querySelectorAll( '.frm-over-droppable' ).forEach( droppable => droppable.classList.remove( 'frm-over-droppable' ) );
880 - droppable.classList.add( 'frm-over-droppable' );
881 - jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' );
882 - }
883 -
884 - /**
885 - * Maybe change the droppable.
886 - * Section titles are made droppable, but are not a list, so we need to change the droppable to the section's list instead.
887 - *
888 - * @param {Element} droppable
889 - * @returns {Element}
890 - */
891 - function getDroppableForOnDragOver( droppable ) {
892 - if ( droppable.classList.contains( 'divider_section_only' ) ) {
893 - droppable = jQuery( droppable ).nextAll( '.start_divider.frm_sorting' ).get( 0 );
894 - }
895 - return droppable;
896 - }
897 -
898 - function onDraggableLeavesDroppable( event ) {
899 - const droppable = event.target;
900 - droppable.classList.remove( 'frm-over-droppable' );
901 - }
902 -
903 - function makeDraggable( draggable, handle ) {
904 - const settings = {
905 - helper: getDraggableHelper,
906 - revert: 'invalid',
907 - delay: 10,
908 - start: handleDragStart,
909 - stop: handleDragStop,
910 - drag: handleDrag,
911 - cursor: 'grabbing',
912 - refreshPositions: true,
913 - cursorAt: {
914 - top: 0,
915 - left: 90 // The width of draggable button is 180. 90 should center the draggable on the cursor.
916 - }
917 - };
918 - if ( 'string' === typeof handle ) {
919 - settings.handle = handle;
920 - }
921 - jQuery( draggable ).draggable( settings );
922 - }
923 -
924 - function getDraggableHelper( event ) {
925 - const draggable = event.delegateTarget;
926 -
927 - if ( isFieldGroup( draggable ) ) {
928 - const newTextFieldClone = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_ttext' ).cloneNode( true );
929 - newTextFieldClone.querySelector( 'use' ).setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_field_group_layout_icon' );
930 - newTextFieldClone.querySelector( 'span' ).textContent = __( 'Field Group' );
931 - newTextFieldClone.classList.add( 'frm_field_box' );
932 - newTextFieldClone.classList.add( 'ui-sortable-helper' );
933 - return newTextFieldClone;
934 - }
935 -
936 - let copyTarget;
937 - const isNewField = draggable.classList.contains( 'frmbutton' );
938 - if ( isNewField ) {
939 - copyTarget = draggable.cloneNode( true );
940 - copyTarget.classList.add( 'ui-sortable-helper' );
941 - draggable.classList.add( 'frm-new-field' );
942 - return copyTarget;
943 - }
944 -
945 - if ( draggable.hasAttribute( 'data-ftype' ) ) {
946 - const fieldType = draggable.getAttribute( 'data-ftype' );
947 - copyTarget = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_t' + fieldType );
948 - copyTarget = copyTarget.cloneNode( true );
949 - copyTarget.classList.add( 'form-field' );
950 -
951 - copyTarget.classList.add( 'ui-sortable-helper' );
952 -
953 - if ( copyTarget ) {
954 - return copyTarget.cloneNode( true );
955 - }
956 - }
957 -
958 - return div({ className: 'frmbutton' });
959 - }
960 -
961 - function handleDragStart( event, ui ) {
962 - const container = postBodyContent;
963 - container.classList.add( 'frm-dragging-field' );
964 -
965 - document.body.classList.add( 'frm-dragging' );
966 - ui.helper.addClass( 'frm-sortable-helper' );
967 - ui.helper.initialOffset = container.scrollTop;
968 -
969 - event.target.classList.add( 'frm-drag-fade' );
970 -
971 - unselectFieldGroups();
972 - deleteEmptyDividerWrappers();
973 - maybeRemoveGroupHoverTarget();
974 - closeOpenFieldDropdowns();
975 - deleteTooltips();
976 - }
977 -
978 - function handleDragStop() {
979 - const container = postBodyContent;
980 - container.classList.remove( 'frm-dragging-field' );
981 - document.body.classList.remove( 'frm-dragging' );
982 -
983 - const fade = document.querySelector( '.frm-drag-fade' );
984 - if ( fade ) {
985 - fade.classList.remove( 'frm-drag-fade' );
986 - }
987 - }
988 -
989 - function handleDrag( event, ui ) {
990 - maybeScrollBuilder( event );
991 - const draggable = event.target;
992 - const droppable = getDroppableTarget();
993 -
994 - let placeholder = document.getElementById( 'frm_drag_placeholder' );
995 -
996 - if ( ! allowDrop( draggable, droppable ) ) {
997 - if ( placeholder ) {
998 - placeholder.remove();
999 - }
1000 - return;
1001 - }
1002 -
1003 - if ( ! placeholder ) {
1004 - placeholder = tag( 'li', {
1005 - id: 'frm_drag_placeholder',
1006 - className: 'sortable-placeholder'
1007 - });
1008 - }
1009 - const frmSortableHelper = ui.helper.get( 0 );
1010 - if ( frmSortableHelper.classList.contains( 'form-field' ) || frmSortableHelper.classList.contains( 'frm_field_box' ) ) {
1011 - // Sync the y position of the draggable so it still follows the cursor after scrolling up and down the field list.
1012 - frmSortableHelper.style.transform = 'translateY(' + getDragOffset( ui.helper ) + 'px)';
1013 - }
1014 -
1015 - if ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) ) {
1016 - placeholder.style.left = 0;
1017 - handleDragOverYAxis({ droppable, y: event.clientY, placeholder });
1018 - return;
1019 - }
1020 -
1021 - placeholder.style.top = '';
1022 - handleDragOverFieldGroup({ droppable, x: event.clientX, placeholder });
1023 - }
1024 -
1025 - function maybeScrollBuilder( event ) {
1026 - $postBodyContent.scrollTop(
1027 - ( _, v ) => {
1028 - const moved = event.clientY;
1029 - const h = postBodyContent.offsetHeight;
1030 - const relativePos = event.clientY - postBodyContent.offsetTop;
1031 - const y = relativePos - h / 2;
1032 -
1033 - if ( relativePos > ( h - 50 ) && moved > 5 ) {
1034 - // Scrolling down.
1035 - return v + y * 0.1;
1036 - }
1037 -
1038 - if ( relativePos < 70 && moved < 130 ) {
1039 - // Scrolling up.
1040 - return v - Math.abs( y * 0.1 );
1041 - }
1042 -
1043 - return v;
1044 - }
1045 - );
1046 - }
1047 -
1048 - function getDragOffset( $helper ) {
1049 - return postBodyContent.scrollTop - $helper.initialOffset;
1050 - }
1051 -
1052 - function getDroppableTarget() {
1053 - let droppable = document.getElementById( 'frm-show-fields' );
1054 - while ( droppable.querySelector( '.frm-over-droppable' ) ) {
1055 - droppable = droppable.querySelector( '.frm-over-droppable' );
1056 - }
1057 - if ( 'frm-show-fields' === droppable.id && ! droppable.classList.contains( 'frm-over-droppable' ) ) {
1058 - droppable = false;
1059 - }
1060 - return droppable;
1061 - }
1062 -
1063 - function handleFieldDrop( _, ui ) {
1064 - const draggable = ui.draggable[0];
1065 - const placeholder = document.getElementById( 'frm_drag_placeholder' );
1066 -
1067 - if ( ! placeholder ) {
1068 - ui.helper.remove();
1069 - debouncedSyncAfterDragAndDrop();
1070 - return;
1071 - }
1072 -
1073 - maybeOpenCollapsedPage( placeholder );
1074 -
1075 - const $previousFieldContainer = ui.helper.parent();
1076 - const previousSection = ui.helper.get( 0 ).closest( 'ul.start_divider' );
1077 - const newSection = placeholder.closest( 'ul.frm_sorting' );
1078 -
1079 - if ( draggable.classList.contains( 'frm-new-field' ) ) {
1080 - insertNewFieldByDragging( draggable.id );
1081 - } else {
1082 - moveFieldThatAlreadyExists( draggable, placeholder );
1083 - }
1084 -
1085 - const previousSectionId = previousSection ? parseInt( previousSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0;
1086 - const newSectionId = newSection.classList.contains( 'start_divider' ) ? parseInt( newSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0;
1087 -
1088 - placeholder.remove();
1089 - ui.helper.remove();
1090 -
1091 - const $previousContainerFields = $previousFieldContainer.length ? getFieldsInRow( $previousFieldContainer ) : [];
1092 - maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields );
1093 - maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields );
1094 -
1095 - if ( previousSectionId !== newSectionId ) {
1096 - updateFieldAfterMovingBetweenSections( jQuery( draggable ), previousSection );
1097 - }
1098 -
1099 - debouncedSyncAfterDragAndDrop();
1100 - }
1101 -
1102 - /**
1103 - * If a page if collapsed, expand it before dragging since only the page break will move.
1104 - *
1105 - * @param {Element} placeholder
1106 - * @returns {void}
1107 - */
1108 - function maybeOpenCollapsedPage( placeholder ) {
1109 - if ( ! placeholder.previousElementSibling || ! placeholder.previousElementSibling.classList.contains( 'frm-is-collapsed' ) ) {
1110 - return;
1111 - }
1112 -
1113 - const $pageBreakField = jQuery( placeholder ).prevUntil( '[data-type="break"]' );
1114 - if ( ! $pageBreakField.length ) {
1115 - return;
1116 - }
1117 -
1118 - const collapseButton = $pageBreakField.find( '.frm-collapse-page' ).get( 0 );
1119 - if ( collapseButton ) {
1120 - collapseButton.click();
1121 - }
1122 - }
1123 -
1124 - function maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields ) {
1125 - if ( ! $previousFieldContainer.length ) {
1126 - return;
1127 - }
1128 -
1129 - if ( $previousContainerFields.length ) {
1130 - syncLayoutClasses( $previousContainerFields.first() );
1131 - } else {
1132 - maybeDeleteAnEmptyFieldGroup( $previousFieldContainer.get( 0 ) );
1133 - }
1134 - }
1135 -
1136 - function maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields ) {
1137 - if ( 0 !== $previousContainerFields.length || 1 !== getFieldsInRow( jQuery( draggable.parentNode ) ).length ) {
1138 - syncLayoutClasses( jQuery( draggable ) );
1139 - }
1140 - }
1141 -
1142 - /**
1143 - * Remove an empty field group, but don't remove an empty section.
1144 - *
1145 - * @param {Element} previousFieldContainer
1146 - * @returns {void}
1147 - */
1148 - function maybeDeleteAnEmptyFieldGroup( previousFieldContainer ) {
1149 - const closestFieldBox = previousFieldContainer.closest( 'li.frm_field_box' );
1150 - if ( closestFieldBox && ! closestFieldBox.classList.contains( 'edit_field_type_divider' ) ) {
1151 - closestFieldBox.remove();
1152 - }
1153 - }
1154 -
1155 - function handleDragOverYAxis({ droppable, y, placeholder }) {
1156 - const $list = jQuery( droppable );
1157 -
1158 - let top;
1159 -
1160 - $children = $list.children().not( '.edit_field_type_end_divider' );
1161 - if ( 0 === $children.length ) {
1162 - $list.prepend( placeholder );
1163 - top = 0;
1164 - } else {
1165 - const insertAtIndex = determineIndexBasedOffOfMousePositionInList( $list, y );
1166 -
1167 - if ( insertAtIndex === $children.length ) {
1168 - const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) );
1169 - top = $lastChild.offset().top + $lastChild.outerHeight();
1170 - $list.append( placeholder );
1171 -
1172 - // Make sure nothing gets inserted after the end divider.
1173 - const $endDivider = $list.children( '.edit_field_type_end_divider' );
1174 - if ( $endDivider.length ) {
1175 - $list.append( $endDivider );
1176 - }
1177 - } else {
1178 - top = jQuery( $children.get( insertAtIndex ) ).offset().top;
1179 - jQuery( $children.get( insertAtIndex ) ).before( placeholder );
1180 - }
1181 - }
1182 -
1183 - top -= $list.offset().top;
1184 - placeholder.style.top = top + 'px';
1185 - }
1186 -
1187 - function determineIndexBasedOffOfMousePositionInList( $list, y ) {
1188 - const $items = $list.children().not( '.edit_field_type_end_divider' );
1189 - const length = $items.length;
1190 -
1191 - let index, item, itemTop, returnIndex;
1192 -
1193 - returnIndex = 0;
1194 - for ( index = length - 1; index >= 0; --index ) {
1195 - item = $items.get( index );
1196 - itemTop = jQuery( item ).offset().top;
1197 - if ( y > itemTop ) {
1198 - returnIndex = index;
1199 - if ( y > itemTop + ( jQuery( item ).outerHeight() / 2 ) ) {
1200 - returnIndex = index + 1;
1201 - }
1202 - break;
1203 - }
1204 - }
1205 -
1206 - return returnIndex;
1207 - }
1208 -
1209 - function handleDragOverFieldGroup({ droppable, x, placeholder }) {
1210 - const $row = jQuery( droppable );
1211 - const $children = getFieldsInRow( $row );
1212 -
1213 - if ( ! $children.length ) {
1214 - return;
1215 - }
1216 -
1217 - let left;
1218 - const insertAtIndex = determineIndexBasedOffOfMousePositionInRow( $row, x );
1219 -
1220 - if ( insertAtIndex === $children.length ) {
1221 - const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) );
1222 - left = $lastChild.offset().left + $lastChild.outerWidth();
1223 - $row.append( placeholder );
1224 - } else {
1225 - left = jQuery( $children.get( insertAtIndex ) ).offset().left;
1226 - jQuery( $children.get( insertAtIndex ) ).before( placeholder );
1227 -
1228 - const amountToOffsetLeftBy = 0 === insertAtIndex ? 4 : 8; // Offset by 8 in between rows, but only 4 for the first item in a group.
1229 - left -= amountToOffsetLeftBy; // Offset the placeholder slightly so it appears between two fields.
1230 - }
1231 -
1232 - left -= $row.offset().left;
1233 -
1234 - placeholder.style.left = left + 'px';
1235 - }
1236 -
1237 - function syncAfterDragAndDrop() {
1238 - fixUnwrappedListItems();
1239 - toggleSectionHolder();
1240 - maybeFixEndDividers();
1241 - maybeDeleteEmptyFieldGroups();
1242 - updateFieldOrder();
1243 -
1244 - const event = new Event( 'frm_sync_after_drag_and_drop', { bubbles: false });
1245 - document.dispatchEvent( event );
1246 - }
1247 -
1248 - function maybeFixEndDividers() {
1249 - document.querySelectorAll( '.edit_field_type_end_divider' ).forEach(
1250 - endDivider => endDivider.parentNode.appendChild( endDivider )
1251 - );
1252 - }
1253 -
1254 - function maybeDeleteEmptyFieldGroups() {
1255 - document.querySelectorAll( 'li.form_field_box:not(.form-field)' ).forEach(
1256 - fieldGroup => ! fieldGroup.children.length && fieldGroup.remove()
1257 - );
1258 - }
1259 -
1260 - function fixUnwrappedListItems() {
1261 - const lists = document.querySelectorAll( 'ul#frm-show-fields, ul.start_divider' );
1262 - lists.forEach(
1263 - list => {
1264 - list.childNodes.forEach(
1265 - child => {
1266 - if ( 'undefined' === typeof child.classList ) {
1267 - return;
1268 - }
1269 -
1270 - if ( child.classList.contains( 'edit_field_type_end_divider' ) ) {
1271 - // Never wrap end divider in place.
1272 - return;
1273 - }
1274 -
1275 - if ( 'undefined' !== typeof child.classList && child.classList.contains( 'form-field' ) ) {
1276 - wrapFieldLiInPlace( child );
1277 - }
1278 - }
1279 - );
1280 - }
1281 - );
1282 - }
1283 -
1284 - function deleteEmptyDividerWrappers() {
1285 - const dividers = document.querySelectorAll( 'ul.start_divider' );
1286 - if ( ! dividers.length ) {
1287 - return;
1288 - }
1289 - dividers.forEach(
1290 - function( divider ) {
1291 - const children = [].slice.call( divider.children );
1292 - children.forEach(
1293 - function( child ) {
1294 - if ( 0 === child.children.length ) {
1295 - child.remove();
1296 - } else if ( 1 === child.children.length && 'ul' === child.firstElementChild.nodeName.toLowerCase() && 0 === child.firstElementChild.children.length ) {
1297 - child.remove();
1298 - }
1299 - }
1300 - );
1301 - }
1302 - );
1303 - }
1304 -
1305 - function getFieldsInRow( $row ) {
1306 - let $fields = jQuery();
1307 -
1308 - const row = $row.get( 0 );
1309 - if ( ! row.children ) {
1310 - return $fields;
1311 - }
1312 -
1313 - Array.from( row.children ).forEach(
1314 - child => {
1315 - if ( 'none' === child.style.display ) {
1316 - return;
1317 - }
1318 -
1319 - const classes = child.classList;
1320 - if ( ! classes.contains( 'form-field' ) || classes.contains( 'edit_field_type_end_divider' ) || classes.contains( 'frm-sortable-helper' ) ) {
1321 - return;
1322 - }
1323 -
1324 - $fields = $fields.add( child );
1325 - }
1326 - );
1327 - return $fields;
1328 - }
1329 -
1330 - function determineIndexBasedOffOfMousePositionInRow( $row, x ) {
1331 - var $inputs = getFieldsInRow( $row ),
1332 - length = $inputs.length,
1333 - index, input, inputLeft, returnIndex;
1334 -
1335 - returnIndex = 0;
1336 - for ( index = length - 1; index >= 0; --index ) {
1337 - input = $inputs.get( index );
1338 - inputLeft = jQuery( input ).offset().left;
1339 - if ( x > inputLeft ) {
1340 - returnIndex = index;
1341 - if ( x > inputLeft + ( jQuery( input ).outerWidth() / 2 ) ) {
1342 - returnIndex = index + 1;
1343 - }
1344 - break;
1345 - }
1346 - }
1347 -
1348 - return returnIndex;
1349 - }
1350 -
1351 - function syncLayoutClasses( $item, type ) {
1352 - var $fields, size, layoutClasses, classToAddFunction;
1353 -
1354 - if ( 'undefined' === typeof type ) {
1355 - type = 'even';
1356 - }
1357 -
1358 - $fields = $item.parent().children( 'li.form-field, li.frmbutton_loadingnow' ).not( '.edit_field_type_end_divider' );
1359 - size = $fields.length;
1360 - layoutClasses = getLayoutClasses();
1361 -
1362 - if ( 'even' === type && 5 !== size ) {
1363 - $fields.each( getSyncLayoutClass( layoutClasses, getEvenClassForSize( size ) ) );
1364 - } else if ( 'clear' === type ) {
1365 - $fields.each( getSyncLayoutClass( layoutClasses, '' ) );
1366 - } else {
1367 - if ( -1 !== [ 'left', 'right', 'middle', 'even' ].indexOf( type ) ) {
1368 - classToAddFunction = function( index ) {
1369 - return getClassForBlock( size, type, index );
1370 - };
1371 - } else {
1372 - classToAddFunction = function( index ) {
1373 - var size = type[ index ];
1374 - return getLayoutClassForSize( size );
1375 - };
1376 - }
1377 -
1378 - $fields.each( getSyncLayoutClass( layoutClasses, classToAddFunction ) );
1379 - }
1380 -
1381 - updateFieldGroupControls( $item.parent(), $fields.length );
1382 - }
1383 -
1384 - function updateFieldGroupControls( $row, count ) {
1385 - var rowOffset, shouldShowControls, controls;
1386 -
1387 - rowOffset = $row.offset();
1388 -
1389 - if ( 'undefined' === typeof rowOffset ) {
1390 - return;
1391 - }
1392 -
1393 - shouldShowControls = count >= 2;
1394 -
1395 - controls = document.getElementById( 'frm_field_group_controls' );
1396 - if ( null === controls ) {
1397 - if ( ! shouldShowControls ) {
1398 - // exit early. if we do not need controls and they do not exist, do nothing.
1399 - return;
1400 - }
1401 -
1402 - controls = div();
1403 - controls.id = 'frm_field_group_controls';
1404 - controls.setAttribute( 'role', 'group' );
1405 - controls.setAttribute( 'tabindex', 0 );
1406 - setFieldControlsHtml( controls );
1407 - document.getElementById( 'frm_builder_page' ).appendChild( controls );
1408 - }
1409 -
1410 - $row.append( controls );
1411 - controls.style.display = shouldShowControls ? 'block' : 'none';
1412 - }
1413 -
1414 - function setFieldControlsHtml( controls ) {
1415 - var layoutOption, moveOption;
1416 -
1417 - layoutOption = document.createElement( 'span' );
1418 - layoutOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_field_group_layout_icon"></use></svg>';
1419 - const layoutOptionLabel = __( 'Set Row Layout', 'formidable' );
1420 - addTooltip( layoutOption, layoutOptionLabel );
1421 - makeTabbable( layoutOption, layoutOptionLabel );
1422 -
1423 - moveOption = document.createElement( 'span' );
1424 - moveOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_thick_move_icon"></use></svg>';
1425 - moveOption.classList.add( 'frm-move' );
1426 - const moveOptionLabel = __( 'Move Field Group', 'formidable' );
1427 - addTooltip( moveOption, moveOptionLabel );
1428 - makeTabbable( moveOption, moveOptionLabel );
1429 -
1430 - controls.innerHTML = '';
1431 - controls.appendChild( layoutOption );
1432 - controls.appendChild( moveOption );
1433 - controls.appendChild( getFieldControlsDropdown() );
1434 - }
1435 -
1436 - function addTooltip( element, title ) {
1437 - element.setAttribute( 'data-toggle', 'tooltip' );
1438 - element.setAttribute( 'data-container', 'body' );
1439 - element.setAttribute( 'title', title );
1440 - element.addEventListener(
1441 - 'mouseover',
1442 - function() {
1443 - if ( null === element.getAttribute( 'data-original-title' ) ) {
1444 - jQuery( element ).tooltip();
1445 - }
1446 - }
1447 - );
1448 - }
1449 -
1450 - function getFieldControlsDropdown() {
1451 - var dropdown, trigger, ul;
1452 -
1453 - dropdown = document.createElement( 'span' );
1454 - dropdown.classList.add( 'dropdown' );
1455 -
1456 - trigger = document.createElement( 'a' );
1457 - trigger.classList.add( 'frm_bstooltip', 'frm-hover-icon', 'frm-dropdown-toggle', 'dropdown-toggle' );
1458 - trigger.setAttribute( 'title', __( 'More Options', 'formidable' ) );
1459 - trigger.setAttribute( 'data-toggle', 'dropdown' );
1460 - trigger.setAttribute( 'data-container', 'body' );
1461 - makeTabbable( trigger, __( 'More Options', 'formidable' ) );
1462 - trigger.innerHTML = '<span><svg class="frmsvg"><use xlink:href="#frm_thick_more_vert_icon"></use></svg></span>';
1463 - dropdown.appendChild( trigger );
1464 -
1465 - ul = document.createElement( 'div' );
1466 - ul.classList.add( 'frm-dropdown-menu', 'dropdown-menu', 'dropdown-menu-right' );
1467 - ul.setAttribute( 'role', 'menu' );
1468 - dropdown.appendChild( ul );
1469 -
1470 - return dropdown;
1471 - }
1472 -
1473 - function getSyncLayoutClass( layoutClasses, classToAdd ) {
1474 - return function( itemIndex ) {
1475 - var currentClassToAdd, length, layoutClassIndex, currentClass, activeLayoutClass, fieldId, layoutClassesInput;
1476 -
1477 - currentClassToAdd = 'function' === typeof classToAdd ? classToAdd( itemIndex ) : classToAdd;
1478 - length = layoutClasses.length;
1479 - activeLayoutClass = false;
1480 - for ( layoutClassIndex = 0; layoutClassIndex < length; ++layoutClassIndex ) {
1481 - currentClass = layoutClasses[ layoutClassIndex ];
1482 - if ( this.classList.contains( currentClass ) ) {
1483 - activeLayoutClass = currentClass;
1484 - break;
1485 - }
1486 - }
1487 -
1488 - fieldId = this.dataset.fid;
1489 -
1490 - if ( 'undefined' === typeof fieldId ) {
1491 - // we are syncing the drag/drop placeholder before the actual field has loaded.
1492 - // this will get called again afterward and the input will exist then.
1493 - this.classList.add( currentClassToAdd );
1494 - return;
1495 - }
1496 -
1497 - moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) );
1498 - layoutClassesInput = document.getElementById( 'frm_classes_' + fieldId );
1499 -
1500 - if ( null === layoutClassesInput ) {
1501 - // not every field type has a layout class input.
1502 - return;
1503 - }
1504 -
1505 - if ( false === activeLayoutClass ) {
1506 - if ( '' !== currentClassToAdd ) {
1507 - layoutClassesInput.value = layoutClassesInput.value.concat( ' ' + currentClassToAdd );
1508 - }
1509 - } else {
1510 - this.classList.remove( activeLayoutClass );
1511 - layoutClassesInput.value = layoutClassesInput.value.replace( activeLayoutClass, currentClassToAdd );
1512 - }
1513 -
1514 - if ( this.classList.contains( 'frm_first' ) ) {
1515 - this.classList.remove( 'frm_first' );
1516 - layoutClassesInput.value = layoutClassesInput.value.replace( 'frm_first', '' ).trim();
1517 - }
1518 -
1519 - if ( 0 === itemIndex ) {
1520 - this.classList.add( 'frm_first' );
1521 - layoutClassesInput.value = layoutClassesInput.value.concat( ' frm_first' );
1522 - }
1523 -
1524 - jQuery( layoutClassesInput ).trigger( 'change' );
1525 - };
1526 - }
1527 -
1528 - function getLayoutClasses() {
1529 - return [ 'frm_full', 'frm_half', 'frm_third', 'frm_fourth', 'frm_sixth', 'frm_two_thirds', 'frm_three_fourths', 'frm1', 'frm2', 'frm3', 'frm4', 'frm5', 'frm6', 'frm7', 'frm8', 'frm9', 'frm10', 'frm11', 'frm12' ];
1530 - }
1531 -
1532 - function setupFieldOptionSorting( sort ) {
1533 - var opts = {
1534 - items: '.frm_sortable_field_opts li',
1535 - axis: 'y',
1536 - opacity: 0.65,
1537 - forcePlaceholderSize: false,
1538 - handle: '.frm-drag',
1539 - helper: function( e, li ) {
1540 - copyHelper = li.clone().insertAfter( li );
1541 - return li.clone();
1542 - },
1543 - stop: function( e, ui ) {
1544 - copyHelper && copyHelper.remove();
1545 - var fieldId = ui.item.attr( 'id' ).replace( 'frm_delete_field_', '' ).replace( '-' + ui.item.data( 'optkey' ) + '_container', '' );
1546 - resetDisplayedOpts( fieldId );
1547 - fieldUpdated();
1548 - }
1549 - };
1550 - jQuery( sort ).sortable( opts );
1551 - }
1552 -
1553 - // Get the section where a field is dropped
1554 - function getSectionForFieldPlacement( currentItem ) {
1555 - var section = '';
1556 - if ( typeof currentItem !== 'undefined' && ! currentItem.hasClass( 'edit_field_type_divider' ) ) {
1557 - section = currentItem.closest( '.edit_field_type_divider' );
1558 - }
1559 - return section;
1560 - }
1561 -
1562 - // Get the form ID where a field is dropped
1563 - function getFormIdForFieldPlacement( section ) {
1564 - var formId = '';
1565 -
1566 - if ( typeof section[0] !== 'undefined' ) {
1567 - var sDivide = section.children( '.start_divider' );
1568 - sDivide.children( '.edit_field_type_end_divider' ).appendTo( sDivide );
1569 - if ( typeof section.attr( 'data-formid' ) !== 'undefined' ) {
1570 - var fieldId = section.attr( 'data-fid' );
1571 - formId = jQuery( 'input[name="field_options[form_select_' + fieldId + ']"]' ).val();
1572 - }
1573 - }
1574 -
1575 - if ( typeof formId === 'undefined' || formId === '' ) {
1576 - formId = thisFormId;
1577 - }
1578 -
1579 - return formId;
1580 - }
1581 -
1582 - // Get the section ID where a field is dropped
1583 - function getSectionIdForFieldPlacement( section ) {
1584 - var sectionId = 0;
1585 - if ( typeof section[0] !== 'undefined' ) {
1586 - sectionId = section.attr( 'id' ).replace( 'frm_field_id_', '' );
1587 - }
1588 -
1589 - return sectionId;
1590 - }
1591 -
1592 - /**
1593 - * Update a field after it is dragged and dropped into, out of, or between sections
1594 - *
1595 - * @param {Object} currentItem
1596 - * @param {Object} previousSection
1597 - * @returns {void}
1598 - */
1599 - function updateFieldAfterMovingBetweenSections( currentItem, previousSection ) {
1600 - if ( ! currentItem.hasClass( 'form-field' ) ) {
1601 - // currentItem is a field group. Call for children recursively.
1602 - getFieldsInRow( jQuery( currentItem.get( 0 ).firstChild ) ).each(
1603 - function() {
1604 - updateFieldAfterMovingBetweenSections( jQuery( this ), previousSection );
1605 - }
1606 - );
1607 - return;
1608 - }
1609 -
1610 - const fieldId = currentItem.attr( 'id' ).replace( 'frm_field_id_', '' );
1611 - const section = getSectionForFieldPlacement( currentItem );
1612 - const formId = getFormIdForFieldPlacement( section );
1613 - const sectionId = getSectionIdForFieldPlacement( section );
1614 - const previousFormId = previousSection ? getFormIdForFieldPlacement( jQuery( previousSection.parentNode ) ) : 0;
1615 -
1616 - jQuery.ajax({
1617 - type: 'POST',
1618 - url: ajaxurl,
1619 - data: {
1620 - action: 'frm_update_field_after_move',
1621 - form_id: formId,
1622 - field: fieldId,
1623 - section_id: sectionId,
1624 - previous_form_id: previousFormId,
1625 - nonce: frmGlobal.nonce
1626 - },
1627 - success: function() {
1628 - toggleSectionHolder();
1629 - updateInSectionValue( fieldId, sectionId );
1630 - }
1631 - });
1632 - }
1633 -
1634 - // Update the in_section field value
1635 - function updateInSectionValue( fieldId, sectionId ) {
1636 - document.getElementById( 'frm_in_section_' + fieldId ).value = sectionId;
1637 - }
1638 -
1639 - /**
1640 - * Add a new field by dragging and dropping it from the Fields sidebar
1641 - *
1642 - * @param {string} fieldType
1643 - */
1644 - function insertNewFieldByDragging( fieldType ) {
1645 - const placeholder = document.getElementById( 'frm_drag_placeholder' );
1646 - const loadingID = fieldType.replace( '|', '-' ) + '_' + getAutoId();
1647 - const loading = tag(
1648 - 'li',
1649 - {
1650 - id: loadingID,
1651 - className: 'frm-wait frmbutton_loadingnow'
1652 - }
1653 - );
1654 - const $placeholder = jQuery( loading );
1655 - const currentItem = jQuery( placeholder );
1656 - const section = getSectionForFieldPlacement( currentItem );
1657 - const formId = getFormIdForFieldPlacement( section );
1658 - const sectionId = getSectionIdForFieldPlacement( section );
1659 -
1660 - placeholder.parentNode.insertBefore( loading, placeholder );
1661 - placeholder.remove();
1662 - syncLayoutClasses( $placeholder );
1663 -
1664 - let hasBreak = 0;
1665 - if ( 'summary' === fieldType ) {
1666 - // see if we need to insert a page break before this newly-added summary field. Check for at least 1 page break
1667 - hasBreak = jQuery( '.frmbutton_loadingnow#' + loadingID ).prevAll( 'li[data-type="break"]' ).length ? 1 : 0;
1668 - }
1669 -
1670 - jQuery.ajax({
1671 - type: 'POST', url: ajaxurl,
1672 - data: {
1673 - action: 'frm_insert_field',
1674 - form_id: formId,
1675 - field_type: fieldType,
1676 - section_id: sectionId,
1677 - nonce: frmGlobal.nonce,
1678 - has_break: hasBreak
1679 - },
1680 - success: function( msg ) {
1681 - let replaceWith;
1682 - document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' );
1683 - const $siblings = $placeholder.siblings( 'li.form-field' ).not( '.edit_field_type_end_divider' );
1684 - if ( ! $siblings.length ) {
1685 - // if dragging into a new row, we need to wrap the li first.
1686 - replaceWith = wrapFieldLi( msg );
1687 - } else {
1688 - replaceWith = msgAsjQueryObject( msg );
1689 - if ( ! $placeholder.get( 0 ).parentNode.parentNode.classList.contains( 'ui-draggable' ) ) {
1690 - // If a field group wasn't draggable because it only had a single field, make it draggable.
1691 - makeDraggable( $placeholder.get( 0 ).parentNode.parentNode, '.frm-move' );
1692 - }
1693 - }
1694 - $placeholder.replaceWith( replaceWith );
1695 - updateFieldOrder();
1696 - afterAddField( msg, false );
1697 - if ( $siblings.length ) {
1698 - syncLayoutClasses( $siblings.first() );
1699 - }
1700 - toggleSectionHolder();
1701 -
1702 - if ( ! $siblings.length ) {
1703 - makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) );
1704 - makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' );
1705 - } else {
1706 - makeDraggable( replaceWith.get( 0 ), '.frm-move' );
1707 - }
1708 -
1709 - },
1710 - error: handleInsertFieldError
1711 - });
1712 - }
1713 -
1714 - function moveFieldThatAlreadyExists( draggable, placeholder ) {
1715 - placeholder.parentNode.insertBefore( draggable, placeholder );
1716 - }
1717 -
1718 - function msgAsjQueryObject( msg ) {
1719 - const element = div();
1720 - element.innerHTML = msg;
1721 - return jQuery( element.firstChild );
1722 - }
1723 -
1724 - function handleInsertFieldError( jqXHR, _, errorThrown ) {
1725 - maybeShowInsertFieldError( errorThrown, jqXHR );
1726 - }
1727 -
1728 - function maybeShowInsertFieldError( errorThrown, jqXHR ) {
1729 - if ( ! jqXHRAborted( jqXHR ) ) {
1730 - infoModal( errorThrown + '. Please try again.' );
1731 - }
1732 - }
1733 -
1734 - function jqXHRAborted( jqXHR ) {
1735 - return jqXHR.status === 0 || jqXHR.readyState === 0;
1736 - }
1737 -
1738 - /**
1739 - * Get a unique id that automatically increments with every function call.
1740 - * Can be used for any UI that requires a unique id.
1741 - * Not to be used in data.
1742 - *
1743 - * @returns {integer}
1744 - */
1745 - function getAutoId() {
1746 - return ++autoId;
1747 - }
1748 -
1749 - // Don't allow page break, embed form, or section inside section field
1750 - // Don't allow page breaks inside of field groups.
1751 - // Don't allow field groups with sections inside of sections.
1752 - // Don't allow field groups in field groups.
1753 - // Don't allow hidden fields inside of field groups but allow them in sections.
1754 - function allowDrop( draggable, droppable ) {
1755 - if ( false === droppable ) {
1756 - // Don't show drop placeholder if dragging somewhere off of the droppable area.
1757 - return false;
1758 - }
1759 -
1760 - if ( droppable.closest( '.frm-sortable-helper' ) ) {
1761 - // Do not allow drop into draggable.
1762 - return false;
1763 - }
1764 -
1765 - if ( 'frm-show-fields' === droppable.id ) {
1766 - // Everything can be dropped into the main list of fields.
1767 - return true;
1768 - }
1769 -
1770 - if ( ! droppable.classList.contains( 'start_divider' ) ) {
1771 - const $fieldsInRow = getFieldsInRow( jQuery( droppable ) );
1772 - if ( ! groupCanFitAnotherField( $fieldsInRow, jQuery( draggable ) ) ) {
1773 - // Field group is full and cannot accept another field.
1774 - return false;
1775 - }
1776 - }
1777 -
1778 - const isNewField = draggable.classList.contains( 'frm-new-field' );
1779 - if ( isNewField ) {
1780 - return allowNewFieldDrop( draggable, droppable );
1781 - }
1782 -
1783 - return allowMoveField( draggable, droppable );
1784 - }
1785 -
1786 - // Don't allow a new page break or hidden field in a field group.
1787 - // Don't allow a new field into a field group that includes a page break or hidden field.
1788 - // Don't allow a new section inside of a section.
1789 - // Don't allow an embedded form in a section.
1790 - function allowNewFieldDrop( draggable, droppable ) {
1791 - const classes = draggable.classList;
1792 - const newPageBreakField = classes.contains( 'frm_tbreak' );
1793 - const newHiddenField = classes.contains( 'frm_thidden' );
1794 - const newSectionField = classes.contains( 'frm_tdivider' );
1795 - const newEmbedField = classes.contains( 'frm_tform' );
1796 -
1797 - const newFieldWillBeAddedToAGroup = ! ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) );
1798 - if ( newFieldWillBeAddedToAGroup ) {
1799 - if ( groupIncludesBreakOrHidden( droppable ) ) {
1800 - // Never allow any field beside a page break or a hidden field.
1801 - return false;
1802 - }
1803 -
1804 - return ! newHiddenField && ! newPageBreakField;
1805 - }
1806 -
1807 - const fieldTypeIsAlwaysAllowed = ! newPageBreakField && ! newHiddenField && ! newSectionField && ! newEmbedField;
1808 - if ( fieldTypeIsAlwaysAllowed ) {
1809 - return true;
1810 - }
1811 -
1812 - const newFieldWillBeAddedToASection = droppable.classList.contains( 'start_divider' ) || null !== droppable.closest( '.start_divider' );
1813 - if ( newFieldWillBeAddedToASection ) {
1814 - // Don't allow a section or an embedded form in a section.
1815 - return ! newEmbedField && ! newSectionField;
1816 - }
1817 -
1818 - return true;
1819 - }
1820 -
1821 - function allowMoveField( draggable, droppable ) {
1822 - if ( isFieldGroup( draggable ) ) {
1823 - return allowMoveFieldGroup( draggable, droppable );
1824 - }
1825 -
1826 - const isPageBreak = draggable.classList.contains( 'edit_field_type_break' );
1827 - if ( isPageBreak ) {
1828 - // Page breaks are only allowed in the main list of fields, not in sections or in field groups.
1829 - return false;
1830 - }
1831 -
1832 - if ( droppable.classList.contains( 'start_divider' ) ) {
1833 - return allowMoveFieldToSection( draggable );
1834 - }
1835 -
1836 - const isHiddenField = draggable.classList.contains( 'edit_field_type_hidden' );
1837 - if ( isHiddenField ) {
1838 - // Hidden fields should not be added to field groups since they're not shown and don't make sense with the grid distribution.
1839 - return false;
1840 - }
1841 -
1842 - return allowMoveFieldToGroup( draggable, droppable );
1843 - }
1844 -
1845 - function isFieldGroup( draggable ) {
1846 - return draggable.classList.contains( 'frm_field_box' ) && ! draggable.classList.contains( 'form-field' );
1847 - }
1848 -
1849 - function allowMoveFieldGroup( fieldGroup, droppable ) {
1850 - if ( droppable.classList.contains( 'start_divider' ) && null === fieldGroup.querySelector( '.start_divider' ) ) {
1851 - // Allow a field group with no section inside of a section.
1852 - return true;
1853 - }
1854 - return false;
1855 - }
1856 -
1857 - function allowMoveFieldToSection( draggable ) {
1858 - const draggableIncludeEmbedForm = draggable.classList.contains( 'edit_field_type_form' ) || draggable.querySelector( '.edit_field_type_form' );
1859 - if ( draggableIncludeEmbedForm ) {
1860 - // Do not allow an embedded form inside of a section.
1861 - return false;
1862 - }
1863 -
1864 - const draggableIncludesSection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' );
1865 - if ( draggableIncludesSection ) {
1866 - // Do not allow a section inside of a section.
1867 - return false;
1868 - }
1869 -
1870 - return true;
1871 - }
1872 -
1873 - function allowMoveFieldToGroup( draggable, group ) {
1874 - if ( groupIncludesBreakOrHidden( group ) ) {
1875 - // Never allow any field beside a page break or a hidden field.
1876 - return false;
1877 - }
1878 -
1879 - const isFieldGroup = jQuery( draggable ).children( 'ul.frm_sorting' ).not( '.start_divider' ).length > 0;
1880 - if ( isFieldGroup ) {
1881 - // Do not allow a field group directly inside of a field group unless it's in a section.
1882 - return false;
1883 - }
1884 -
1885 - const draggableIncludesASection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' );
1886 - const draggableIsEmbedField = draggable.classList.contains( 'edit_field_type_form' );
1887 - const groupIsInASection = null !== group.closest( '.start_divider' );
1888 - if ( groupIsInASection && ( draggableIncludesASection || draggableIsEmbedField ) ) {
1889 - // Do not allow a section or an embed field inside of a section.
1890 - return false;
1891 - }
1892 -
1893 - return true;
1894 - }
1895 -
1896 - function groupIncludesBreakOrHidden( group ) {
1897 - return null !== group.querySelector( '.edit_field_type_break, .edit_field_type_hidden' );
1898 - }
1899 -
1900 - function groupCanFitAnotherField( fieldsInRow, $field ) {
1901 - var fieldId;
1902 - if ( fieldsInRow.length < 6 ) {
1903 - return true;
1904 - }
1905 - if ( fieldsInRow.length > 6 ) {
1906 - return false;
1907 - }
1908 - fieldId = $field.attr( 'data-fid' );
1909 - // allow 6 if we're not changing field groups.
1910 - return 1 === jQuery( fieldsInRow ).filter( '[data-fid="' + fieldId + '"]' ).length;
1911 - }
1912 -
1913 - function loadFields( fieldId ) {
1914 - const thisField = document.getElementById( fieldId );
1915 - const $thisField = jQuery( thisField );
1916 - const field = [];
1917 - const addHtmlToField = element => {
1918 - const frmHiddenFdata = element.querySelector( '.frm_hidden_fdata' );
1919 - element.classList.add( 'frm_load_now' );
1920 - if ( frmHiddenFdata !== null ) {
1921 - field.push( frmHiddenFdata.innerHTML );
1922 - }
1923 - };
1924 -
1925 - let nextElement = thisField;
1926 - addHtmlToField( nextElement );
1927 - while ( nextElement.nextElementSibling && field.length < 15 ) {
1928 - addHtmlToField( nextElement.nextElementSibling );
1929 - nextElement = nextElement.nextElementSibling;
1930 - }
1931 -
1932 - jQuery.ajax({
1933 - type: 'POST',
1934 - url: ajaxurl,
1935 - data: {
1936 - action: 'frm_load_field',
1937 - field: field,
1938 - form_id: thisFormId,
1939 - nonce: frmGlobal.nonce
1940 - },
1941 - success: html => handleAjaxLoadFieldSuccess( html, $thisField, field )
1942 - });
1943 - }
1944 -
1945 - function handleAjaxLoadFieldSuccess( html, $thisField, field ) {
1946 - let key, $nextSet;
1947 -
1948 - html = html.replace( /^\s+|\s+$/g, '' );
1949 - if ( html.indexOf( '{' ) !== 0 ) {
1950 - jQuery( '.frm_load_now' ).removeClass( '.frm_load_now' ).html( 'Error' );
1951 - return;
1952 - }
1953 -
1954 - html = JSON.parse( html );
1955 - for ( key in html ) {
1956 - jQuery( '#frm_field_id_' + key ).replaceWith( html[key]);
1957 - setupSortable( '#frm_field_id_' + key + '.edit_field_type_divider ul.frm_sorting' );
1958 - makeDraggable( document.getElementById( 'frm_field_id_' + key ) );
1959 - }
1960 -
1961 - $nextSet = $thisField.nextAll( '.frm_field_loading:not(.frm_load_now)' );
1962 - if ( $nextSet.length ) {
1963 - loadFields( $nextSet.attr( 'id' ) );
1964 - } else {
1965 - // go up a level
1966 - $nextSet = jQuery( document.getElementById( 'frm-show-fields' ) ).find( '.frm_field_loading:not(.frm_load_now)' );
1967 - if ( $nextSet.length ) {
1968 - loadFields( $nextSet.attr( 'id' ) );
1969 - }
1970 - }
1971 -
1972 - initiateMultiselect();
1973 - renumberPageBreaks();
1974 - maybeHideQuantityProductFieldOption();
1975 -
1976 - const loadedEvent = new Event( 'frm_ajax_loaded_field', { bubbles: false });
1977 - loadedEvent.frmFields = field.map( f => JSON.parse( f ) );
1978 - document.dispatchEvent( loadedEvent );
1979 - }
1980 -
1981 - function addFieldClick() {
1982 - /*jshint validthis:true */
1983 - const $thisObj = jQuery( this );
1984 - // there is no real way to disable a <a> (with a valid href attribute) in HTML - https://css-tricks.com/how-to-disable-links/
1985 - if ( $thisObj.hasClass( 'disabled' ) ) {
1986 - return false;
1987 - }
1988 -
1989 - const $button = $thisObj.closest( '.frmbutton' );
1990 - const fieldType = $button.attr( 'id' );
1991 -
1992 - let hasBreak = 0;
1993 - if ( 'summary' === fieldType ) {
1994 - hasBreak = $newFields.children( 'li[data-type="break"]' ).length > 0 ? 1 : 0;
1995 - }
1996 -
1997 - const formId = thisFormId;
1998 - jQuery.ajax({
1999 - type: 'POST',
2000 - url: ajaxurl,
2001 - data: {
2002 - action: 'frm_insert_field',
2003 - form_id: formId,
2004 - field_type: fieldType,
2005 - section_id: 0,
2006 - nonce: frmGlobal.nonce,
2007 - has_break: hasBreak
2008 - },
2009 - success: function( msg ) {
2010 - document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' );
2011 - const replaceWith = wrapFieldLi( msg );
2012 - $newFields.append( replaceWith );
2013 - afterAddField( msg, true );
2014 -
2015 - replaceWith.each(
2016 - function() {
2017 - makeDroppable( this.querySelector( 'ul.frm_sorting' ) );
2018 - makeDraggable( this.querySelector( '.form-field' ), '.frm-move' );
2019 - }
2020 - );
2021 - },
2022 - error: handleInsertFieldError
2023 - });
2024 - return false;
2025 - }
2026 -
2027 - function maybeHideQuantityProductFieldOption() {
2028 - var hide = true,
2029 - opts = document.querySelectorAll( '.frmjs_prod_field_opt_cont' );
2030 -
2031 - if ( $newFields.find( 'li.edit_field_type_product' ).length > 1 ) {
2032 - hide = false;
2033 - }
2034 -
2035 - for ( var i = 0; i < opts.length; i++ ) {
2036 - if ( hide ) {
2037 - opts[ i ].classList.add( 'frm_hidden' );
2038 - } else {
2039 - opts[ i ].classList.remove( 'frm_hidden' );
2040 - }
2041 - }
2042 - }
2043 -
2044 - function duplicateField() {
2045 - var $field, fieldId, children, newRowId, fieldOrder;
2046 -
2047 - $field = jQuery( this ).closest( 'li.form-field' );
2048 -
2049 - if ( $field.hasClass( 'frm-page-collapsed' ) ) {
2050 - return false;
2051 - }
2052 -
2053 - closeOpenFieldDropdowns();
2054 - fieldId = $field.data( 'fid' );
2055 - children = fieldsInSection( fieldId );
2056 - newRowId = this.getAttribute( 'frm-target-row-id' );
2057 -
2058 - if ( null !== newRowId ) {
2059 - fieldOrder = this.getAttribute( 'frm-field-order' );
2060 - }
2061 -
2062 - jQuery.ajax({
2063 - type: 'POST',
2064 - url: ajaxurl,
2065 - data: {
2066 - action: 'frm_duplicate_field',
2067 - field_id: fieldId,
2068 - form_id: thisFormId,
2069 - children: children,
2070 - nonce: frmGlobal.nonce
2071 - },
2072 - success: function( msg ) {
2073 - var newRow;
2074 -
2075 - let replaceWith;
2076 -
2077 - if ( null !== newRowId ) {
2078 - newRow = document.getElementById( newRowId );
2079 - if ( null !== newRow ) {
2080 - replaceWith = msgAsjQueryObject( msg );
2081 - jQuery( newRow ).append( replaceWith );
2082 - makeDraggable( replaceWith.get( 0 ), '.frm-move' );
2083 - if ( null !== fieldOrder ) {
2084 - newRow.lastElementChild.setAttribute( 'frm-field-order', fieldOrder );
2085 - }
2086 - jQuery( newRow ).trigger(
2087 - 'frm_added_duplicated_field_to_row',
2088 - {
2089 - duplicatedFieldHtml: msg,
2090 - originalFieldId: fieldId
2091 - }
2092 - );
2093 - afterAddField( msg, false );
2094 - return;
2095 - }
2096 - }
2097 -
2098 - if ( $field.siblings( 'li.form-field' ).length ) {
2099 - replaceWith = msgAsjQueryObject( msg );
2100 - $field.after( replaceWith );
2101 - syncLayoutClasses( $field );
2102 - makeDraggable( replaceWith.get( 0 ), '.frm-move' );
2103 - } else {
2104 - replaceWith = wrapFieldLi( msg );
2105 - $field.parent().parent().after( replaceWith );
2106 - makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) );
2107 - makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' );
2108 - }
2109 -
2110 - updateFieldOrder();
2111 - afterAddField( msg, false );
2112 - maybeDuplicateUnsavedSettings( fieldId, msg );
2113 - toggleOneSectionHolder( replaceWith.find( '.start_divider' ) );
2114 - $field[0].querySelector( '.frm-dropdown-menu.dropdown-menu-right' )?.classList.remove( 'show' );
2115 - }
2116 - });
2117 - return false;
2118 - }
2119 -
2120 - function maybeDuplicateUnsavedSettings( originalFieldId, newFieldHtml ) {
2121 - var originalSettings, newFieldId, copySettings, fieldOptionKeys, originalDefault, copyDefault;
2122 -
2123 - originalSettings = document.getElementById( 'frm-single-settings-' + originalFieldId );
2124 - if ( null === originalSettings ) {
2125 - return;
2126 - }
2127 -
2128 - newFieldId = jQuery( newFieldHtml ).attr( 'data-fid' );
2129 - if ( 'undefined' === typeof newFieldId ) {
2130 - return;
2131 - }
2132 -
2133 - copySettings = document.getElementById( 'frm-single-settings-' + newFieldId );
2134 - if ( null === copySettings ) {
2135 - return;
2136 - }
2137 -
2138 - fieldOptionKeys = [
2139 - 'name', 'required', 'unique', 'read_only', 'placeholder', 'description', 'size', 'max', 'format', 'prepend', 'append', 'separate_value'
2140 - ];
2141 -
2142 - originalSettings.querySelectorAll( 'input[name^="field_options["], textarea[name^="field_options["]' ).forEach(
2143 - function( originalSetting ) {
2144 - var key, tagType, copySetting;
2145 -
2146 - key = getKeyFromSettingInput( originalSetting );
2147 -
2148 - if ( 'options' === key ) {
2149 - copyOption( originalSetting, copySettings, originalFieldId, newFieldId );
2150 - return;
2151 - }
2152 -
2153 - if ( -1 === fieldOptionKeys.indexOf( key ) ) {
2154 - return;
2155 - }
2156 -
2157 - tagType = originalSetting.matches( 'input' ) ? 'input' : 'textarea';
2158 - copySetting = copySettings.querySelector( tagType + '[name="field_options[' + key + '_' + newFieldId + ']"]' );
2159 - if ( null === copySetting ) {
2160 - return;
2161 - }
2162 -
2163 - if ( 'checkbox' === originalSetting.type ) {
2164 - if ( originalSetting.checked !== copySetting.checked ) {
2165 - jQuery( copySetting ).trigger( 'click' );
2166 - }
2167 - } else if ( 'text' === originalSetting.type || 'textarea' === tagType ) {
2168 - if ( originalSetting.value !== copySetting.value ) {
2169 - copySetting.value = originalSetting.value;
2170 - jQuery( copySetting ).trigger( 'change' );
2171 - }
2172 - }
2173 - }
2174 - );
2175 -
2176 - originalDefault = originalSettings.querySelector( 'input[name="default_value_' + originalFieldId + '"]' );
2177 - if ( null !== originalDefault ) {
2178 - copyDefault = copySettings.querySelector( 'input[name="default_value_' + newFieldId + '"]' );
2179 - if ( null !== copyDefault && originalDefault.value !== copyDefault.value ) {
2180 - copyDefault.value = originalDefault.value;
2181 - jQuery( copyDefault ).trigger( 'change' );
2182 - }
2183 - }
2184 - }
2185 -
2186 - function copyOption( originalSetting, copySettings, originalFieldId, newFieldId ) {
2187 - var remainingKeyDetails, copyKey, copySetting;
2188 - remainingKeyDetails = originalSetting.name.substr( 23 + ( '' + originalFieldId ).length );
2189 - copyKey = 'field_options[options_' + newFieldId + ']' + remainingKeyDetails;
2190 - copySetting = copySettings.querySelector( 'input[name="' + copyKey + '"]' );
2191 - if ( null !== copySetting && copySetting.value !== originalSetting.value ) {
2192 - copySetting.value = originalSetting.value;
2193 - jQuery( copySetting ).trigger( 'change' );
2194 - }
2195 - }
2196 -
2197 - function getKeyFromSettingInput( input ) {
2198 - var nameWithoutPrefix, nameSplit;
2199 - nameWithoutPrefix = input.name.substr( 14 );
2200 - nameSplit = nameWithoutPrefix.split( '_' );
2201 - nameSplit.pop();
2202 - return nameSplit.join( '_' );
2203 - }
2204 -
2205 - function closeOpenFieldDropdowns() {
2206 - var openSettings = document.querySelector( '.frm-field-settings-open' );
2207 - if ( null !== openSettings ) {
2208 - openSettings.classList.remove( 'frm-field-settings-open' );
2209 - jQuery( document ).off( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings );
2210 - jQuery( '.frm-field-action-icons .dropdown.open' ).removeClass( 'open' );
2211 - }
2212 - }
2213 -
2214 - function handleClickOutsideOfFieldSettings( event ) {
2215 - if ( ! jQuery( event.originalEvent.target ).closest( '.frm-field-action-icons' ).length ) {
2216 - closeOpenFieldDropdowns();
2217 - }
2218 - }
2219 -
2220 - function checkForMultiselectKeysOnMouseMove( event ) {
2221 - var keyIsDown = ! ! ( event.ctrlKey || event.metaKey || event.shiftKey );
2222 - jQuery( document.getElementById( 'frm_builder_page' ) ).toggleClass( 'frm-multiselect-key-is-down', keyIsDown );
2223 - checkForActiveHoverTarget( event );
2224 - }
2225 -
2226 - function checkForActiveHoverTarget( event ) {
2227 - var container, elementFromPoint, list, previousHoverTarget;
2228 -
2229 - container = postBodyContent;
2230 - if ( container.classList.contains( 'frm-dragging-field' ) ) {
2231 - return;
2232 - }
2233 -
2234 - if ( null !== document.querySelector( '.frm-field-group-hover-target .frm-field-settings-open' ) ) {
2235 - // do not set a hover target if a dropdown is open for the current hover target.
2236 - return;
2237 - }
2238 -
2239 - elementFromPoint = document.elementFromPoint( event.clientX, event.clientY );
2240 - if ( null !== elementFromPoint && ! elementFromPoint.classList.contains( 'edit_field_type_divider' ) ) {
2241 -
2242 - list = elementFromPoint.closest( 'ul.frm_sorting' );
2243 -
2244 - if ( null !== list && ! list.classList.contains( 'start_divider' ) && 'frm-show-fields' !== list.id ) {
2245 - previousHoverTarget = maybeRemoveGroupHoverTarget();
2246 - if ( false !== previousHoverTarget && ! jQuery( previousHoverTarget ).is( list ) ) {
2247 - destroyFieldGroupPopup();
2248 - }
2249 - updateFieldGroupControls( jQuery( list ), getFieldsInRow( jQuery( list ) ).length );
2250 - list.classList.add( 'frm-field-group-hover-target' );
2251 - jQuery( '#wpbody-content' ).on( 'mousemove', maybeRemoveHoverTargetOnMouseMove );
2252 - }
2253 - }
2254 - }
2255 -
2256 - function maybeRemoveGroupHoverTarget() {
2257 - var controls, previousHoverTarget;
2258 -
2259 - controls = document.getElementById( 'frm_field_group_controls' );
2260 - if ( null !== controls ) {
2261 - controls.style.display = 'none';
2262 - }
2263 -
2264 - previousHoverTarget = document.querySelector( '.frm-field-group-hover-target' );
2265 - if ( null === previousHoverTarget ) {
2266 - return false;
2267 - }
2268 -
2269 - jQuery( '#wpbody-content' ).off( 'mousemove', maybeRemoveHoverTargetOnMouseMove );
2270 - previousHoverTarget.classList.remove( 'frm-field-group-hover-target' );
2271 - return previousHoverTarget;
2272 - }
2273 -
2274 - function maybeRemoveHoverTargetOnMouseMove( event ) {
2275 - var elementFromPoint = document.elementFromPoint( event.clientX, event.clientY );
2276 - if ( null !== elementFromPoint && null !== elementFromPoint.closest( '#frm-show-fields' ) ) {
2277 - return;
2278 - }
2279 - maybeRemoveGroupHoverTarget();
2280 - }
2281 -
2282 - function onFieldActionDropdownShow( isFieldGroup ) {
2283 - unselectFieldGroups();
2284 - // maybe offset the dropdown if it goes off of the right of the screen.
2285 - setTimeout(
2286 - function() {
2287 - var ul, $ul;
2288 - ul = document.querySelector( '.dropdown.show .frm-dropdown-menu' );
2289 - if ( null === ul ) {
2290 - return;
2291 - }
2292 - if ( null === ul.getAttribute( 'aria-label' ) ) {
2293 - ul.setAttribute( 'aria-label', __( 'More Options', 'formidable' ) );
2294 - }
2295 - if ( 0 === ul.children.length ) {
2296 - fillFieldActionDropdown( ul, true === isFieldGroup );
2297 - }
2298 - $ul = jQuery( ul );
2299 - if ( $ul.offset().left > jQuery( window ).width() - $ul.outerWidth() ) {
2300 - ul.style.left = ( -$ul.outerWidth() ) + 'px';
2301 - }
2302 - const firstAnchor = ul.firstElementChild.querySelector( 'a' );
2303 - if ( firstAnchor ) {
2304 - firstAnchor.focus();
2305 - }
2306 - },
2307 - 0
2308 - );
2309 - }
2310 -
2311 - function onFieldGroupActionDropdownShow() {
2312 - onFieldActionDropdownShow( true );
2313 - }
2314 -
2315 - function changeSectionStyle( e ) {
2316 - const collapsedSection = e.target.closest( '.frm-section-collapsed' );
2317 - if ( ! collapsedSection ) {
2318 - return;
2319 - }
2320 -
2321 - if ( e.type === 'show' ) {
2322 - collapsedSection.style.zIndex = 3;
2323 - } else {
2324 - collapsedSection.style.zIndex = 1;
2325 - }
2326 - }
2327 -
2328 - function fillFieldActionDropdown( ul, isFieldGroup ) {
2329 - var classSuffix, options;
2330 - classSuffix = isFieldGroup ? '_field_group' : '_field';
2331 - options = [ getDeleteActionOption( isFieldGroup ), getDuplicateActionOption( isFieldGroup ) ];
2332 - if ( ! isFieldGroup ) {
2333 - options.push(
2334 - { class: 'frm_select', icon: 'frm_settings_icon', label: __( 'Field Settings', 'formidable' ) }
2335 - );
2336 - }
2337 - options.forEach(
2338 - function( option ) {
2339 - var li, anchor, span;
2340 - li = document.createElement( 'div' );
2341 - li.classList.add( 'frm_more_options_li', 'dropdown-item' );
2342 -
2343 - anchor = document.createElement( 'a' );
2344 - anchor.classList.add( option.class + classSuffix );
2345 - anchor.setAttribute( 'href', '#' );
2346 - makeTabbable( anchor );
2347 -
2348 - span = document.createElement( 'span' );
2349 - span.textContent = option.label;
2350 - anchor.innerHTML = '<svg class="frmsvg"><use xlink:href="#' + option.icon + '"></use></svg>';
2351 - anchor.appendChild( document.createTextNode( ' ' ) );
2352 - anchor.appendChild( span );
2353 -
2354 - li.appendChild( anchor );
2355 - ul.appendChild( li );
2356 - }
2357 - );
2358 - }
2359 -
2360 - function getDeleteActionOption( isFieldGroup ) {
2361 - var option = { class: 'frm_delete', icon: 'frm_delete_icon' };
2362 - option.label = isFieldGroup ? __( 'Delete Group', 'formidable' ) : __( 'Delete', 'formidable' );
2363 - return option;
2364 - }
2365 -
2366 - function getDuplicateActionOption( isFieldGroup ) {
2367 - var option = { class: 'frm_clone', icon: 'frm_clone_icon' };
2368 - option.label = isFieldGroup ? __( 'Duplicate Group', 'formidable' ) : __( 'Duplicate', 'formidable' );
2369 - return option;
2370 - }
2371 -
2372 - function wrapFieldLi( field ) {
2373 - const wrapper = div();
2374 -
2375 - if ( 'string' === typeof field ) {
2376 - wrapper.innerHTML = field;
2377 - } else {
2378 - wrapper.appendChild( field );
2379 - }
2380 -
2381 - let result = jQuery();
2382 - Array.from( wrapper.children ).forEach(
2383 - li => {
2384 - result = result.add(
2385 - jQuery( '<li>' )
2386 - .addClass( 'frm_field_box' )
2387 - .html(
2388 - jQuery( '<ul>' ).addClass( 'frm_grid_container frm_sorting' ).append( li )
2389 - )
2390 - );
2391 - }
2392 - );
2393 -
2394 - return result;
2395 - }
2396 -
2397 - function wrapFieldLiInPlace( li ) {
2398 - const ul = tag(
2399 - 'ul',
2400 - {
2401 - className: 'frm_grid_container frm_sorting'
2402 - }
2403 - );
2404 - const wrapper = tag(
2405 - 'li',
2406 - {
2407 - className: 'frm_field_box',
2408 - child: ul
2409 - }
2410 - );
2411 -
2412 - li.replaceWith( wrapper );
2413 - ul.appendChild( li );
2414 -
2415 - makeDroppable( ul );
2416 - makeDraggable( wrapper, '.frm-move' );
2417 - }
2418 -
2419 - function afterAddField( msg, addFocus ) {
2420 - var regex = /id="(\S+)"/,
2421 - match = regex.exec( msg ),
2422 - field = document.getElementById( match[1]),
2423 - section = '#' + match[1] + '.edit_field_type_divider ul.frm_sorting.start_divider',
2424 - $thisSection = jQuery( section ),
2425 - type = field.getAttribute( 'data-type' ),
2426 - toggled = false,
2427 - $parentSection;
2428 -
2429 - setupSortable( section );
2430 -
2431 - if ( 'quantity' === type ) {
2432 - // try to automatically attach a product field
2433 - maybeSetProductField( field );
2434 - }
2435 -
2436 - if ( 'product' === type || 'quantity' === type ) {
2437 - // quantity too needs to be a part of the if stmt especially cos of the very
2438 - // 1st quantity field (or even if it's just one quantity field in the form).
2439 - maybeHideQuantityProductFieldOption();
2440 - }
2441 -
2442 - if ( $thisSection.length ) {
2443 - $thisSection.parent( '.frm_field_box' ).children( '.frm_no_section_fields' ).addClass( 'frm_block' );
2444 - } else {
2445 - $parentSection = jQuery( field ).closest( 'ul.frm_sorting.start_divider' );
2446 - if ( $parentSection.length ) {
2447 - toggleOneSectionHolder( $parentSection );
2448 - toggled = true;
2449 - }
2450 - }
2451 -
2452 - if ( msg.indexOf( 'frm-collapse-page' ) !== -1 ) {
2453 - renumberPageBreaks();
2454 - }
2455 -
2456 - addClass( field, 'frm-newly-added' );
2457 - setTimeout( function() {
2458 - field.classList.remove( 'frm-newly-added' );
2459 - }, 1000 );
2460 -
2461 - if ( addFocus ) {
2462 - var bounding = field.getBoundingClientRect(),
2463 - container = document.getElementById( 'post-body-content' ),
2464 - inView = ( bounding.top >= 0 &&
2465 - bounding.left >= 0 &&
2466 - bounding.right <= ( window.innerWidth || document.documentElement.clientWidth ) &&
2467 - bounding.bottom <= ( window.innerHeight || document.documentElement.clientHeight )
2468 - );
2469 -
2470 - if ( ! inView ) {
2471 - container.scroll({
2472 - top: container.scrollHeight,
2473 - left: 0,
2474 - behavior: 'smooth'
2475 - });
2476 - }
2477 -
2478 - if ( toggled === false ) {
2479 - toggleOneSectionHolder( $thisSection );
2480 - }
2481 - }
2482 -
2483 - deselectFields();
2484 - initiateMultiselect();
2485 -
2486 - const addedEvent = new Event( 'frm_added_field', { bubbles: false });
2487 - addedEvent.frmField = field;
2488 - addedEvent.frmSection = section;
2489 - addedEvent.frmType = type;
2490 - addedEvent.frmToggles = toggled;
2491 - document.dispatchEvent( addedEvent );
2492 - }
2493 -
2494 - function clearSettingsBox( preventFieldGroups ) {
2495 - jQuery( '#new_fields .frm-single-settings' ).addClass( 'frm_hidden' );
2496 - jQuery( '#frm-options-panel > .frm-single-settings' ).removeClass( 'frm_hidden' );
2497 - deselectFields( preventFieldGroups );
2498 - }
2499 -
2500 - function deselectFields( preventFieldGroups ) {
2501 - jQuery( 'li.ui-state-default.selected' ).removeClass( 'selected' );
2502 - if ( ! preventFieldGroups ) {
2503 - unselectFieldGroups();
2504 - }
2505 - }
2506 -
2507 - function scrollToField( field ) {
2508 - var newPos = field.getBoundingClientRect().top,
2509 - container = document.getElementById( 'post-body-content' );
2510 -
2511 - if ( typeof animate === 'undefined' ) {
2512 - jQuery( container ).scrollTop( newPos );
2513 - } else {
2514 - // TODO: smooth scroll
2515 - jQuery( container ).animate({ scrollTop: newPos }, 500 );
2516 - }
2517 - }
2518 -
2519 - function checkCalculationCreatedByUser() {
2520 - var calculation = this.value;
2521 - var warningMessage = checkMatchingParens( calculation );
2522 - warningMessage += checkShortcodes( calculation, this );
2523 -
2524 - if ( warningMessage !== '' ) {
2525 - infoModal( calculation + '\n\n' + warningMessage );
2526 - }
2527 - }
2528 -
2529 - /**
2530 - * Checks the Detail Page slug to see if it's a reserved word and displays a message if it is.
2531 - */
2532 - function checkDetailPageSlug() {
2533 - var slug = jQuery( '#param' ).val(),
2534 - msg;
2535 - slug = slug.trim().toLowerCase();
2536 - if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( slug ) ) { // eslint-disable-line camelcase
2537 - msg = frm_admin_js.slug_is_reserved; // eslint-disable-line camelcase
2538 - msg = msg.replace( '****', addHtmlTags( slug, 'strong' ) );
2539 - msg += '<br /><br />';
2540 - msg += addHtmlTags( '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>', 'div' ); // eslint-disable-line camelcase
2541 - infoModal( msg );
2542 - }
2543 - }
2544 -
2545 - /**
2546 - * Checks View filter value for params named with reserved words and displays a message if any are found.
2547 - */
2548 - function checkFilterParamNames() {
2549 - var regEx = /\[\s*get\s*param\s*=\s*['"]?([a-zA-Z-_]+)['"]?/ig,
2550 - filterValue = jQuery( this ).val(),
2551 - match = regEx.exec( filterValue ),
2552 - unsafeParams = '';
2553 -
2554 - while ( match !== null ) {
2555 - if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( match[1]) ) { // eslint-disable-line camelcase
2556 - if ( unsafeParams !== '' ) {
2557 - unsafeParams += '", "' + match[ 1 ];
2558 - } else {
2559 - unsafeParams = match[ 1 ];
2560 - }
2561 - }
2562 - match = regEx.exec( filterValue );
2563 - }
2564 -
2565 - if ( unsafeParams !== '' ) {
2566 - msg = frm_admin_js.param_is_reserved; // eslint-disable-line camelcase
2567 - msg = msg.replace( '****', addHtmlTags( unsafeParams, 'strong' ) );
2568 - msg += '<br /><br />';
2569 - msg += ' <a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>'; // eslint-disable-line camelcase
2570 -
2571 - infoModal( msg );
2572 - }
2573 - }
2574 -
2575 - function addHtmlTags( text, tag ) {
2576 - tag = tag ? tag : 'p';
2577 - return '<' + tag + '>' + text + '</' + tag + '>';
2578 - }
2579 -
2580 - /**
2581 - * Checks a string for parens, brackets, and curly braces and returns a message if any unmatched are found.
2582 - * @param formula
2583 - * @returns {string}
2584 - */
2585 - function checkMatchingParens( formula ) {
2586 -
2587 - var stack = [],
2588 - formulaArray = formula.split( '' ),
2589 - length = formulaArray.length,
2590 - opening = [ '{', '[', '(' ],
2591 - closing = {
2592 - '}': '{',
2593 - ')': '(',
2594 - ']': '['
2595 - },
2596 - unmatchedClosing = [],
2597 - msg = '',
2598 - i, top;
2599 -
2600 - for ( i = 0; i < length; i++ ) {
2601 - if ( opening.includes( formulaArray[i]) ) {
2602 - stack.push( formulaArray[i]);
2603 - continue;
2604 - }
2605 - if ( closing.hasOwnProperty( formulaArray[i]) ) {
2606 - top = stack.pop();
2607 - if ( top !== closing[formulaArray[i]]) {
2608 - unmatchedClosing.push( formulaArray[i]);
2609 - }
2610 - }
2611 - }
2612 -
2613 - if ( stack.length > 0 || unmatchedClosing.length > 0 ) {
2614 - msg = frm_admin_js.unmatched_parens + '\n\n'; // eslint-disable-line camelcase
2615 - return msg;
2616 - }
2617 -
2618 - return '';
2619 - }
2620 -
2621 - /**
2622 - * Checks a calculation for shortcodes that shouldn't be in it and returns a message if found.
2623 - * @param calculation
2624 - * @param inputElement
2625 - * @returns {string}
2626 - */
2627 - function checkShortcodes( calculation, inputElement ) {
2628 - var msg = checkNonNumericShortcodes( calculation, inputElement );
2629 - msg += checkNonFormShortcodes( calculation );
2630 -
2631 - return msg;
2632 - }
2633 -
2634 - /**
2635 - * Checks if a numeric calculation has shortcodes that output non-numeric strings and returns a message if found.
2636 - * @param calculation
2637 - *
2638 - * @param inputElement
2639 - * @returns {string}
2640 - */
2641 - function checkNonNumericShortcodes( calculation, inputElement ) {
2642 -
2643 - var msg = '';
2644 -
2645 - if ( isTextCalculation( inputElement ) ) {
2646 - return msg;
2647 - }
2648 -
2649 - var nonNumericShortcodes = getNonNumericShortcodes();
2650 -
2651 - if ( nonNumericShortcodes.test( calculation ) ) {
2652 - msg = frm_admin_js.text_shortcodes + '\n\n'; // eslint-disable-line camelcase
2653 - }
2654 -
2655 - return msg;
2656 - }
2657 -
2658 - /**
2659 - * Determines if the calculation input is from a text calculation.
2660 - *
2661 - * @param inputElement
2662 - */
2663 - function isTextCalculation( inputElement ) {
2664 - return jQuery( inputElement ).siblings( 'label[for^="calc_type"]' ).children( 'input' ).prop( 'checked' );
2665 - }
2666 -
2667 - /**
2668 - * Returns a regular expression of shortcodes that can't be used in numeric calculations.
2669 - * @returns {RegExp}
2670 - */
2671 - function getNonNumericShortcodes() {
2672 - return /\[(date|time|email|ip)\]/;
2673 - }
2674 -
2675 - /**
2676 - * Checks if a string has any shortcodes that do not belong in forms and returns a message if any are found.
2677 - * @param formula
2678 - * @returns {string}
2679 - */
2680 - function checkNonFormShortcodes( formula ) {
2681 - var nonFormShortcodes = getNonFormShortcodes(),
2682 - msg = '';
2683 -
2684 - if ( nonFormShortcodes.test( formula ) ) {
2685 - msg += frm_admin_js.view_shortcodes + '\n\n'; // eslint-disable-line camelcase
2686 - }
2687 -
2688 - return msg;
2689 - }
2690 -
2691 - /**
2692 - * Returns a regular expression of shortcodes that can't be used in forms but can be used in Views, Email
2693 - * Notifications, and other Formidable areas.
2694 - *
2695 - * @returns {RegExp}
2696 - */
2697 - function getNonFormShortcodes() {
2698 - return /\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g;
2699 - }
2700 -
2701 - function isCalcBoxType( box, listClass ) {
2702 - var list = jQuery( box ).find( '.frm_code_list' );
2703 - return 1 === list.length && list.hasClass( listClass );
2704 - }
2705 -
2706 - function extractExcludedOptions( exclude ) {
2707 - var opts = [];
2708 - if ( ! Array.isArray( exclude ) ) {
2709 - return opts;
2710 - }
2711 -
2712 - for ( var i = 0; i < exclude.length; i++ ) {
2713 - if ( exclude[ i ].startsWith( '[' ) ) {
2714 - opts.push( exclude[ i ]);
2715 - // remove it
2716 - exclude.splice( i, 1 );
2717 - // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value
2718 - i--;
2719 - }
2720 - }
2721 -
2722 - return opts;
2723 - }
2724 -
2725 - function hasExcludedOption( field, excludedOpts ) {
2726 - var hasOption = false;
2727 - for ( var i = 0; i < excludedOpts.length; i++ ) {
2728 - var inputs = document.getElementsByName( getFieldOptionInputName( excludedOpts[ i ], field.fieldId ) );
2729 - // 2nd condition checks that there's at least one non-empty value
2730 - if ( inputs.length && jQuery( inputs[0]).val() ) {
2731 - hasOption = true;
2732 - break;
2733 - }
2734 - }
2735 - return hasOption;
2736 - }
2737 -
2738 - function getFieldOptionInputName( opt, fieldId ) {
2739 - var at = opt.indexOf( ']' );
2740 - return 'field_options' + opt.substring( 0, at ) + '_' + fieldId + opt.substring( at );
2741 - }
2742 -
2743 - function popCalcFields( v, force ) {
2744 - var box, exclude, fields, i, list,
2745 - p = jQuery( v ).closest( '.frm-single-settings' ),
2746 - calc = p.find( '.frm-calc-field' );
2747 -
2748 - if ( ! force && ( ! calc.length || calc.val() === '' || calc.is( ':hidden' ) ) ) {
2749 - return;
2750 - }
2751 -
2752 - var isSummary = isCalcBoxType( v, 'frm_js_summary_list' );
2753 -
2754 - var fieldId = p.find( 'input[name="frm_fields_submitted[]"]' ).val();
2755 -
2756 - if ( force ) {
2757 - box = v;
2758 - } else {
2759 - box = document.getElementById( 'frm-calc-box-' + fieldId );
2760 - }
2761 -
2762 - exclude = getExcludeArray( box, isSummary );
2763 - var excludedOpts = extractExcludedOptions( exclude );
2764 -
2765 - fields = getFieldList();
2766 - list = document.getElementById( 'frm-calc-list-' + fieldId );
2767 - list.innerHTML = '';
2768 -
2769 - for ( i = 0; i < fields.length; i++ ) {
2770 - if ( ( exclude && exclude.includes( fields[ i ].fieldType ) ) ||
2771 - ( excludedOpts.length && hasExcludedOption( fields[ i ], excludedOpts ) ) ) {
2772 - continue;
2773 - }
2774 -
2775 - var span = document.createElement( 'span' );
2776 - span.appendChild( document.createTextNode( '[' + fields[i].fieldId + ']' ) );
2777 -
2778 - var a = document.createElement( 'a' );
2779 - a.setAttribute( 'href', '#' );
2780 - a.setAttribute( 'data-code', fields[i].fieldId );
2781 - a.classList.add( 'frm_insert_code' );
2782 - a.appendChild( span );
2783 - a.appendChild( document.createTextNode( fields[i].fieldName ) );
2784 -
2785 - var li = document.createElement( 'li' );
2786 - li.classList.add( 'frm-field-list-' + fieldId );
2787 - li.classList.add( 'frm-field-list-' + fields[i].fieldType );
2788 - li.appendChild( a );
2789 - list.appendChild( li );
2790 - }
2791 - }
2792 -
2793 - function getExcludeArray( calcBox, isSummary ) {
2794 - var exclude = JSON.parse( calcBox.getElementsByClassName( 'frm_code_list' )[0].getAttribute( 'data-exclude' ) );
2795 -
2796 - if ( isSummary ) {
2797 - // includedExtras are those that are normally excluded from the summary but the form owner can choose to include,
2798 - // when they have been chosen to be included, then they can now be manually excluded in the calc box.
2799 - var includedExtras = getIncludedExtras();
2800 - if ( includedExtras.length ) {
2801 - for ( var i = 0; i < exclude.length; i++ ) {
2802 - if ( includedExtras.includes( exclude[ i ]) ) {
2803 - // remove it
2804 - exclude.splice( i, 1 );
2805 - // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value
2806 - i--;
2807 - }
2808 - }
2809 - }
2810 - }
2811 -
2812 - return exclude;
2813 - }
2814 -
2815 - function getIncludedExtras() {
2816 - var checked = [];
2817 - var checkboxes = document.getElementsByClassName( 'frm_include_extras_field' );
2818 -
2819 - for ( var i = 0; i < checkboxes.length; i++ ) {
2820 - if ( checkboxes[i].checked ) {
2821 - checked.push( checkboxes[i].value );
2822 - }
2823 - }
2824 -
2825 - return checked;
2826 - }
2827 -
2828 - function rePopCalcFieldsForSummary() {
2829 - popCalcFields( jQuery( '.frm-inline-modal.postbox:has(.frm_js_summary_list)' )[0], true );
2830 - }
2831 -
2832 - function getFieldList( fieldType ) {
2833 - var i,
2834 - fields = [],
2835 - allFields = document.querySelectorAll( 'li.frm_field_box' ),
2836 - checkType = 'undefined' !== typeof fieldType;
2837 -
2838 - for ( i = 0; i < allFields.length; i++ ) {
2839 - // data-ftype is better (than data-type) cos of fields loaded by AJAX - which might not be ready yet
2840 - if ( checkType && allFields[ i ].getAttribute( 'data-ftype' ) !== fieldType ) {
2841 - continue;
2842 - }
2843 -
2844 - var fieldId = allFields[ i ].getAttribute( 'data-fid' );
2845 - if ( typeof fieldId !== 'undefined' && fieldId ) {
2846 - fields.push({
2847 - 'fieldId': fieldId,
2848 - 'fieldName': getPossibleValue( 'frm_name_' + fieldId ),
2849 - 'fieldType': getPossibleValue( 'field_options_type_' + fieldId ),
2850 - 'fieldKey': getPossibleValue( 'field_options_field_key_' + fieldId )
2851 - });
2852 - }
2853 - }
2854 -
2855 - return fields;
2856 - }
2857 -
2858 - function popProductFields( field ) {
2859 - var i, checked, id,
2860 - options = [],
2861 - current = getCurrentProductFields( field ),
2862 - fName = field.getAttribute( 'data-frmfname' ),
2863 - products = getFieldList( 'product' ),
2864 - quantities = getFieldList( 'quantity' ),
2865 - isSelect = field.tagName === 'SELECT', // for reverse compatibility.
2866 - // whether we have just 1 product and 1 quantity field & should therefore attach the latter to the former
2867 - auto = 1 === quantities.length && 1 === products.length;
2868 -
2869 - if ( isSelect ) {
2870 - // This fallback can be removed after 4.05.
2871 - current = field.getAttribute( 'data-frmcurrent' );
2872 - }
2873 -
2874 - for ( i = 0 ; i < products.length ; i++ ) {
2875 - // let's be double sure it's string, else indexOf will fail
2876 - id = products[ i ].fieldId.toString();
2877 - checked = auto || -1 !== current.indexOf( id );
2878 - if ( isSelect ) {
2879 - // This fallback can be removed after 4.05.
2880 - checked = checked ? ' selected' : '';
2881 - options.push( '<option value="' + id + '"' + checked + '>' + products[ i ].fieldName + '</option>' );
2882 - } else {
2883 - checked = checked ? ' checked' : '';
2884 - options.push( '<label class="frm6">' );
2885 - options.push( '<input type="checkbox" name="' + fName + '" value="' + id + '"' + checked + '> ' + products[ i ].fieldName );
2886 - options.push( '</label>' );
2887 - }
2888 - }
2889 -
2890 - field.innerHTML = options.join( '' );
2891 - }
2892 -
2893 - function getCurrentProductFields( prodFieldOpt ) {
2894 - var products = prodFieldOpt.querySelectorAll( '[type="checkbox"]:checked' ),
2895 - idsArray = [];
2896 -
2897 - for ( var i = 0; i < products.length; i++ ) {
2898 - idsArray.push( products[ i ].value );
2899 - }
2900 -
2901 - return idsArray;
2902 - }
2903 -
2904 - function popAllProductFields() {
2905 - var opts = document.querySelectorAll( '.frmjs_prod_field_opt' );
2906 - for ( var i = 0; i < opts.length; i++ ) {
2907 - popProductFields( opts[ i ]);
2908 - }
2909 - }
2910 -
2911 - function maybeSetProductField( field ) {
2912 - var fieldId = field.getAttribute( 'data-fid' ),
2913 - productFieldOpt = document.getElementById( 'field_options[product_field_' + fieldId + ']' );
2914 -
2915 - if ( null === productFieldOpt ) {
2916 - return;
2917 - }
2918 -
2919 - popProductFields( productFieldOpt );
2920 - // in order to move its settings to that LHS panel where
2921 - // the update form resides, else it'll lose this setting
2922 - moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) );
2923 - }
2924 -
2925 - /**
2926 - * If the element doesn't exist, use a blank value.
2927 - */
2928 - function getPossibleValue( id ) {
2929 - field = document.getElementById( id );
2930 - if ( field !== null ) {
2931 - return field.value;
2932 - } else {
2933 - return '';
2934 - }
2935 - }
2936 -
2937 - function liveChanges() {
2938 - /*jshint validthis:true */
2939 - var option,
2940 - newValue = this.value,
2941 - changes = document.getElementById( this.getAttribute( 'data-changeme' ) ),
2942 - att = this.getAttribute( 'data-changeatt' );
2943 -
2944 - if ( changes === null ) {
2945 - return;
2946 - }
2947 -
2948 - if ( att !== null ) {
2949 - if ( changes.tagName === 'SELECT' && att === 'placeholder' ) {
2950 - option = changes.options[0];
2951 - if ( option.value === '' ) {
2952 - option.innerHTML = newValue;
2953 - } else {
2954 - // Create a placeholder option if there are no blank values.
2955 - addBlankSelectOption( changes, newValue );
2956 - }
2957 - } else if ( att === 'class' ) {
2958 - changeFieldClass( changes, this );
2959 - } else if ( isSliderField( changes ) ) {
2960 - updateSliderFieldPreview( changes, att, newValue );
2961 - } else {
2962 - changes.setAttribute( att, newValue );
2963 - }
2964 - } else if ( changes.id.indexOf( 'setup-message' ) === 0 ) {
2965 - if ( newValue !== '' ) {
2966 - changes.innerHTML = '<input type="text" value="" disabled />';
2967 - }
2968 - } else {
2969 - changes.innerHTML = newValue;
2970 -
2971 - if ( 'TEXTAREA' === changes.nodeName && changes.classList.contains( 'wp-editor-area' ) ) {
2972 - // Trigger change events on wysiwyg textareas so we can also sync default values in the visual tab.
2973 - jQuery( changes ).trigger( 'change' );
2974 - }
2975 -
2976 - if ( changes.classList.contains( 'frm_primary_label' ) && 'break' === changes.nextElementSibling.getAttribute( 'data-ftype' ) ) {
2977 - changes.nextElementSibling.querySelector( '.frm_button_submit' ).textContent = newValue;
2978 - }
2979 - }
2980 - }
2981 -
2982 - function updateSliderFieldPreview( field, att, newValue ) {
2983 - if ( frmGlobal.proIncludesSliderJs ) {
2984 - const hookName = 'frm_update_slider_field_preview';
2985 - const hookArgs = { field, att, newValue };
2986 - wp.hooks.doAction( hookName, hookArgs );
2987 - return;
2988 - }
2989 -
2990 - // This functionality has been moved to pro since v5.4.3. This code should be removed eventually.
2991 - if ( 'value' === att ) {
2992 - if ( '' === newValue ) {
2993 - newValue = getSliderMidpoint( field );
2994 - }
2995 - field.value = newValue;
2996 - } else {
2997 - field.setAttribute( att, newValue );
2998 - }
2999 -
3000 - if ( -1 === [ 'value', 'min', 'max' ].indexOf( att ) ) {
3001 - return;
3002 - }
3003 -
3004 - if ( ( 'max' === att || 'min' === att ) && '' === getSliderDefaultValueInput( field.id ) ) {
3005 - field.value = getSliderMidpoint( field );
3006 - }
3007 -
3008 - field.parentNode.querySelector( '.frm_range_value' ).textContent = field.value;
3009 - }
3010 -
3011 - function getSliderDefaultValueInput( previewInputId ) {
3012 - return document.querySelector( 'input[data-changeme="' + previewInputId + '"][data-changeatt="value"]' ).value;
3013 - }
3014 -
3015 - function getSliderMidpoint( sliderInput ) {
3016 - const max = parseFloat( sliderInput.getAttribute( 'max' ) );
3017 - const min = parseFloat( sliderInput.getAttribute( 'min' ) );
3018 - return ( max - min ) / 2 + min;
3019 - }
3020 -
3021 - function isSliderField( previewInput ) {
3022 - return 'range' === previewInput.type && previewInput.parentNode.classList.contains( 'frm_range_container' );
3023 - }
3024 -
3025 - function toggleInvalidMsg() {
3026 - /*jshint validthis:true */
3027 - var typeDropdown, fieldType,
3028 - fieldId = this.getAttribute( 'data-fid' ),
3029 - value = '';
3030 -
3031 - [ 'field_options_max_', 'frm_format_' ].forEach( function( id ) {
3032 - var input = document.getElementById( id + fieldId );
3033 - if ( ! input ) {
3034 - return;
3035 - }
3036 -
3037 - value += input.value;
3038 - });
3039 -
3040 - typeDropdown = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0];
3041 - fieldType = typeDropdown.options[typeDropdown.selectedIndex].value;
3042 -
3043 - if ( fieldType === 'text' ) {
3044 - toggleValidationBox( '' !== value, '.frm_invalid_msg' + fieldId );
3045 - }
3046 - }
3047 -
3048 - function markRequired() {
3049 - /*jshint validthis:true */
3050 - var thisid = this.id.replace( 'frm_', '' ),
3051 - fieldId = thisid.replace( 'req_field_', '' ),
3052 - checked = this.checked,
3053 - label = jQuery( '#field_label_' + fieldId + ' .frm_required' );
3054 -
3055 - toggleValidationBox( checked, '.frm_required_details' + fieldId );
3056 -
3057 - if ( checked ) {
3058 - var $reqBox = jQuery( 'input[name="field_options[required_indicator_' + fieldId + ']"]' );
3059 - if ( $reqBox.val() === '' ) {
3060 - $reqBox.val( '*' );
3061 - }
3062 - label.removeClass( 'frm_hidden' );
3063 - } else {
3064 - label.addClass( 'frm_hidden' );
3065 - }
3066 - }
3067 -
3068 - function toggleValidationBox( hasValue, messageClass ) {
3069 - $msg = jQuery( messageClass );
3070 - if ( hasValue ) {
3071 - $msg.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' );
3072 - } else {
3073 - //Fade out validation options
3074 - var v = $msg.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(' + messageClass + '):visible' ).length;
3075 - if ( v === 0 ) {
3076 - $msg.closest( '.frm_validation_msg' ).fadeOut( 'fast' );
3077 - }
3078 - }
3079 - }
3080 -
3081 - function markUnique() {
3082 - /*jshint validthis:true */
3083 - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3084 - var $thisField = jQuery( '.frm_unique_details' + fieldId );
3085 - if ( this.checked ) {
3086 - $thisField.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' );
3087 - $unqDetail = jQuery( '.frm_unique_details' + fieldId + ' input' );
3088 - if ( $unqDetail.val() === '' ) {
3089 - $unqDetail.val( frm_admin_js.default_unique ); // eslint-disable-line camelcase
3090 - }
3091 - } else {
3092 - var v = $thisField.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(.frm_unique_details' + fieldId + '):visible' ).length;
3093 - if ( v === 0 ) {
3094 - $thisField.closest( '.frm_validation_msg' ).fadeOut( 'fast' );
3095 - }
3096 - }
3097 - }
3098 -
3099 - //Fade confirmation field and validation option in or out
3100 - function addConf() {
3101 - /*jshint validthis:true */
3102 - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3103 - var val = jQuery( this ).val();
3104 - var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) );
3105 -
3106 - toggleValidationBox( val !== '', '.frm_conf_details' + fieldId );
3107 -
3108 - if ( val !== '' ) {
3109 - //Add default validation message if empty
3110 - var valMsg = jQuery( '.frm_validation_box .frm_conf_details' + fieldId + ' input' );
3111 - if ( valMsg.val() === '' ) {
3112 - valMsg.val( frm_admin_js.default_conf ); // eslint-disable-line camelcase
3113 - }
3114 -
3115 - setConfirmationFieldDescriptions( fieldId );
3116 -
3117 - //Add or remove class for confirmation field styling
3118 - if ( val === 'inline' ) {
3119 - $thisField.removeClass( 'frm_conf_below' ).addClass( 'frm_conf_inline' );
3120 - } else if ( val === 'below' ) {
3121 - $thisField.removeClass( 'frm_conf_inline' ).addClass( 'frm_conf_below' );
3122 - }
3123 - jQuery( '.frm-conf-box-' + fieldId ).removeClass( 'frm_hidden' );
3124 - } else {
3125 - jQuery( '.frm-conf-box-' + fieldId ).addClass( 'frm_hidden' );
3126 - setTimeout( function() {
3127 - $thisField.removeClass( 'frm_conf_inline frm_conf_below' );
3128 - }, 200 );
3129 - }
3130 - }
3131 -
3132 - function setConfirmationFieldDescriptions( fieldId ) {
3133 - var fieldType = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0].value;
3134 -
3135 - var fieldDescription = document.getElementById( 'field_description_' + fieldId );
3136 - var hiddenDescName = 'field_options[description_' + fieldId + ']';
3137 - var newValue = frm_admin_js['enter_' + fieldType]; // eslint-disable-line camelcase
3138 - maybeSetNewDescription( fieldDescription, hiddenDescName, newValue );
3139 -
3140 - var confFieldDescription = document.getElementById( 'conf_field_description_' + fieldId );
3141 - var hiddenConfName = 'field_options[conf_desc_' + fieldId + ']';
3142 - var newConfValue = frm_admin_js['confirm_' + fieldType]; // eslint-disable-line camelcase
3143 - maybeSetNewDescription( confFieldDescription, hiddenConfName, newConfValue );
3144 - }
3145 -
3146 - function maybeSetNewDescription( descriptionDiv, hiddenName, newValue ) {
3147 - if ( descriptionDiv.innerHTML === frm_admin_js.desc ) { // eslint-disable-line camelcase
3148 -
3149 - // Set the visible description value and the hidden description value
3150 - descriptionDiv.innerHTML = newValue;
3151 - document.getElementsByName( hiddenName )[0].value = newValue;
3152 - }
3153 - }
3154 -
3155 - function initBulkOptionsOverlay() {
3156 - /*jshint validthis:true */
3157 - var $info = initModal( '#frm-bulk-modal', '700px' );
3158 - if ( $info === false ) {
3159 - return;
3160 - }
3161 -
3162 - jQuery( '.frm-insert-preset' ).on( 'click', insertBulkPreset );
3163 -
3164 - jQuery( builderForm ).on( 'click', 'a.frm-bulk-edit-link', function( event ) {
3165 - event.preventDefault();
3166 - var i, key, label,
3167 - content = '',
3168 - optList,
3169 - opts,
3170 - fieldId = jQuery( this ).closest( '[data-fid]' ).data( 'fid' ),
3171 - separate = usingSeparateValues( fieldId ),
3172 - product = isProductField( fieldId );
3173 -
3174 - optList = document.getElementById( 'frm_field_' + fieldId + '_opts' );
3175 - if ( ! optList ) {
3176 - return;
3177 - }
3178 -
3179 - opts = optList.getElementsByTagName( 'li' );
3180 -
3181 - document.getElementById( 'bulk-field-id' ).value = fieldId;
3182 -
3183 - for ( i = 0; i < opts.length; i++ ) {
3184 - key = opts[i].getAttribute( 'data-optkey' );
3185 - if ( key !== '000' ) {
3186 - label = document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][label]' )[0];
3187 - if ( typeof label !== 'undefined' ) {
3188 - content += label.value;
3189 - if ( separate ) {
3190 - content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][value]' )[0].value;
3191 - }
3192 - if ( product ) {
3193 - content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][price]' )[0].value;
3194 - }
3195 - content += '\r\n';
3196 - }
3197 - }
3198 -
3199 - if ( i >= opts.length - 1 ) {
3200 - document.getElementById( 'frm_bulk_options' ).value = content;
3201 - }
3202 - }
3203 -
3204 - $info.dialog( 'open' );
3205 -
3206 - return false;
3207 - });
3208 -
3209 - jQuery( '#frm-update-bulk-opts' ).on( 'click', function() {
3210 - var fieldId = document.getElementById( 'bulk-field-id' ).value;
3211 - var optionType = document.getElementById( 'bulk-option-type' ).value;
3212 -
3213 - if ( optionType ) {
3214 - // Use custom handler for custom option type.
3215 - return;
3216 - }
3217 -
3218 - this.classList.add( 'frm_loading_button' );
3219 - frmAdminBuild.updateOpts( fieldId, document.getElementById( 'frm_bulk_options' ).value, $info );
3220 - fieldUpdated();
3221 - });
3222 - }
3223 -
3224 - function insertBulkPreset( event ) {
3225 - /*jshint validthis:true */
3226 - var opts = JSON.parse( this.getAttribute( 'data-opts' ) );
3227 - event.preventDefault();
3228 - document.getElementById( 'frm_bulk_options' ).value = opts.join( '\n' );
3229 - return false;
3230 - }
3231 -
3232 - //Add new option or "Other" option to radio/checkbox/dropdown
3233 - function addFieldOption() {
3234 - /*jshint validthis:true */
3235 - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
3236 - newOption = jQuery( '#frm_field_' + fieldId + '_opts .frm_option_template' ).prop( 'outerHTML' ),
3237 - optType = jQuery( this ).data( 'opttype' ),
3238 - optKey = 0,
3239 - oldKey = '000',
3240 - lastKey = getHighestOptKey( fieldId );
3241 -
3242 - if ( lastKey !== oldKey ) {
3243 - optKey = lastKey + 1;
3244 - }
3245 -
3246 - //Update hidden field
3247 - if ( optType === 'other' ) {
3248 - document.getElementById( 'other_input_' + fieldId ).value = 1;
3249 -
3250 - //Hide "Add Other" option now if this is radio field
3251 - var ftype = jQuery( this ).data( 'ftype' );
3252 - if ( ftype === 'radio' || ftype === 'select' ) {
3253 - jQuery( this ).fadeOut( 'slow' );
3254 - }
3255 -
3256 - var data = {
3257 - action: 'frm_add_field_option',
3258 - field_id: fieldId,
3259 - opt_key: optKey,
3260 - opt_type: optType,
3261 - nonce: frmGlobal.nonce
3262 - };
3263 - jQuery.post( ajaxurl, data, function( msg ) {
3264 - jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( msg );
3265 - resetDisplayedOpts( fieldId );
3266 - });
3267 - } else {
3268 - newOption = newOption.replace( new RegExp( 'optkey="' + oldKey + '"', 'g' ), 'optkey="' + optKey + '"' );
3269 - newOption = newOption.replace( new RegExp( '-' + oldKey + '_', 'g' ), '-' + optKey + '_' );
3270 - newOption = newOption.replace( new RegExp( '-' + oldKey + '"', 'g' ), '-' + optKey + '"' );
3271 - newOption = newOption.replace( new RegExp( '\\[' + oldKey + '\\]', 'g' ), '[' + optKey + ']' );
3272 - newOption = newOption.replace( 'frm_hidden frm_option_template', '' );
3273 - newOption = { newOption };
3274 - addSaveAndDragIconsToOption( fieldId, newOption );
3275 - jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( newOption.newOption );
3276 - resetDisplayedOpts( fieldId );
3277 - }
3278 - fieldUpdated();
3279 - }
3280 -
3281 - function getHighestOptKey( fieldId ) {
3282 - var i = 0,
3283 - optKey = 0,
3284 - opts = jQuery( '#frm_field_' + fieldId + '_opts li' ),
3285 - lastKey = 0;
3286 -
3287 - for ( i; i < opts.length; i++ ) {
3288 - optKey = opts[i].getAttribute( 'data-optkey' );
3289 - if ( opts.length === 1 ) {
3290 - return optKey;
3291 - }
3292 - if ( optKey !== '000' ) {
3293 - optKey = optKey.replace( 'other_', '' );
3294 - optKey = parseInt( optKey, 10 );
3295 - }
3296 -
3297 - if ( ! isNaN( lastKey ) && ( optKey > lastKey || lastKey === '000' ) ) {
3298 - lastKey = optKey;
3299 - }
3300 - }
3301 -
3302 - return lastKey;
3303 - }
3304 -
3305 - function toggleMultSel() {
3306 - /*jshint validthis:true */
3307 - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3308 - toggleMultiSelect( fieldId, this.value );
3309 - }
3310 -
3311 - function toggleMultiSelect( fieldId, value ) {
3312 - var setting = jQuery( '.frm_multiple_cont_' + fieldId );
3313 - if ( value === 'select' ) {
3314 - setting.fadeIn( 'fast' );
3315 - } else {
3316 - setting.fadeOut( 'fast' );
3317 - }
3318 - }
3319 -
3320 - function toggleSepValues() {
3321 - /*jshint validthis:true */
3322 - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3323 - toggle( jQuery( '.field_' + fieldId + '_option_key' ) );
3324 - jQuery( '.field_' + fieldId + '_option' ).toggleClass( 'frm_with_key' );
3325 - }
3326 -
3327 - function toggleImageOptions() {
3328 - /*jshint validthis:true */
3329 - var hasImageOptions, imageSize,
3330 - $field = jQuery( this ).closest( '.frm-single-settings' ),
3331 - fieldId = $field.data( 'fid' ),
3332 - displayField = document.getElementById( 'frm_field_id_' + fieldId );
3333 -
3334 - refreshOptionDisplayNow( jQuery( this ) );
3335 -
3336 - toggle( jQuery( '.field_' + fieldId + '_image_id' ) );
3337 - toggle( jQuery( '.frm_toggle_image_options_' + fieldId ) );
3338 - toggle( jQuery( '.frm_image_size_' + fieldId ) );
3339 - toggle( jQuery( '.frm_alignment_' + fieldId ) );
3340 - toggle( jQuery( '.frm-add-other#frm_add_field_' + fieldId ) );
3341 -
3342 - hasImageOptions = imagesAsOptions( fieldId );
3343 -
3344 - if ( hasImageOptions ) {
3345 - setAlignment( fieldId, 'inline' );
3346 - removeImageSizeClasses( displayField );
3347 - imageSize = getImageOptionSize( fieldId );
3348 - displayField.classList.add( 'frm_image_options' );
3349 - displayField.classList.add( 'frm_image_size_' + imageSize );
3350 - $field.find( '.frm-bulk-edit-link' ).hide();
3351 - } else {
3352 - displayField.classList.remove( 'frm_image_options' );
3353 - removeImageSizeClasses( displayField );
3354 - setAlignment( fieldId, 'block' );
3355 - $field.find( '.frm-bulk-edit-link' ).show();
3356 - }
3357 - }
3358 -
3359 - function removeImageSizeClasses( field ) {
3360 - field.classList.remove( 'frm_image_size_', 'frm_image_size_small', 'frm_image_size_medium', 'frm_image_size_large', 'frm_image_size_xlarge' );
3361 - }
3362 -
3363 - function setAlignment( fieldId, alignment ) {
3364 - jQuery( '#field_options_align_' + fieldId ).val( alignment ).trigger( 'change' );
3365 - }
3366 -
3367 - function setImageSize() {
3368 - var $field = jQuery( this ).closest( '.frm-single-settings' ),
3369 - fieldId = $field.data( 'fid' ),
3370 - displayField = document.getElementById( 'frm_field_id_' + fieldId );
3371 -
3372 - refreshOptionDisplay();
3373 -
3374 - if ( imagesAsOptions( fieldId ) ) {
3375 - removeImageSizeClasses( displayField );
3376 - displayField.classList.add( 'frm_image_options' );
3377 - displayField.classList.add( 'frm_image_size_' + getImageOptionSize( fieldId ) );
3378 - }
3379 - }
3380 -
3381 - function refreshOptionDisplayNow( object ) {
3382 - var $field = object.closest( '.frm-single-settings' ),
3383 - fieldID = $field.data( 'fid' );
3384 - jQuery( '.field_' + fieldID + '_option' ).trigger( 'change' );
3385 - }
3386 -
3387 - function refreshOptionDisplay() {
3388 - /*jshint validthis:true */
3389 - refreshOptionDisplayNow( jQuery( this ) );
3390 - }
3391 -
3392 - function addImageToOption( event ) {
3393 - const imagePreview = event.target.closest( '.frm_image_preview_wrapper' );
3394 -
3395 - event.preventDefault();
3396 -
3397 - wp.media.model.settings.post.id = 0;
3398 -
3399 - const fileFrame = wp.media.frames.file_frame = wp.media({
3400 - multiple: false,
3401 - library: {
3402 - type: [ 'image' ]
3403 - }
3404 - });
3405 -
3406 - fileFrame.on( 'select', function() {
3407 - const attachment = fileFrame.state().get( 'selection' ).first().toJSON();
3408 - const img = imagePreview.querySelector( 'img' );
3409 -
3410 - img.setAttribute( 'src', attachment.url );
3411 - img.classList.remove( 'frm_hidden' );
3412 - img.removeAttribute( 'srcset' ); // Prevent the old image from sticking around.
3413 -
3414 - imagePreview.querySelector( '.frm_image_preview_frame' ).style.display = 'block';
3415 - imagePreview.querySelector( '.frm_image_preview_title' ).textContent = attachment.filename;
3416 - imagePreview.querySelector( '.frm_choose_image_box' ).style.display = 'none';
3417 -
3418 - const $imagePreview = jQuery( imagePreview );
3419 - $imagePreview.siblings( 'input[name*="[label]"]' ).data( 'frmimgurl', attachment.url );
3420 - $imagePreview.find( 'input.frm_image_id' ).val( attachment.id ).trigger( 'change' );
3421 - wp.media.model.settings.post.id = 0;
3422 - });
3423 -
3424 - fileFrame.open();
3425 - }
3426 -
3427 - function removeImageFromOption( event ) {
3428 - var $this = jQuery( this ),
3429 - previewWrapper = $this.closest( '.frm_image_preview_wrapper' );
3430 -
3431 - event.preventDefault();
3432 - event.stopPropagation();
3433 -
3434 - previewWrapper.find( 'img' ).attr( 'src', '' );
3435 - previewWrapper.find( '.frm_image_preview_frame' ).hide();
3436 - previewWrapper.find( '.frm_choose_image_box' ).show();
3437 - previewWrapper.find( 'input.frm_image_id' ).val( 0 ).trigger( 'change' );
3438 - }
3439 -
3440 - function toggleMultiselect() {
3441 - /*jshint validthis:true */
3442 - var dropdown = jQuery( this ).closest( 'li' ).find( '.frm_form_fields select' );
3443 - if ( this.checked ) {
3444 - dropdown.attr( 'multiple', 'multiple' );
3445 - } else {
3446 - dropdown.removeAttr( 'multiple' );
3447 - }
3448 - }
3449 -
3450 - /**
3451 - * Allow typing on form switcher click without an extra click to search.
3452 - */
3453 - function focusSearchBox() {
3454 - var searchBox = document.getElementById( 'dropform-search-input' );
3455 - if ( searchBox !== null ) {
3456 - setTimeout( function() {
3457 - searchBox.focus();
3458 - }, 100 );
3459 - }
3460 - }
3461 -
3462 - /**
3463 - * Dismiss a warning message and send an AJAX request to update the dismissal state.
3464 - *
3465 - * @since 6.3
3466 - *
3467 - * @param {Event} event The event object associated with the click on the dismiss icon.
3468 - */
3469 - function dismissWarningMessage( event ) {
3470 - const target = event.target;
3471 -
3472 - const warningEl = target.closest( '.frm_warning_style' );
3473 - jQuery( warningEl ).fadeOut( 400, () => warningEl.remove() );
3474 -
3475 - const action = target.dataset.action;
3476 - const formData = new FormData();
3477 - doJsonPost( action, formData );
3478 - }
3479 -
3480 - /**
3481 - * If a field is clicked in the builder, prevent inputs from changing.
3482 - */
3483 - function stopFieldFocus( e ) {
3484 - e.preventDefault();
3485 - }
3486 -
3487 - function deleteFieldOption() {
3488 - /*jshint validthis:true */
3489 - var otherInput,
3490 - parentLi = this.parentNode,
3491 - parentUl = parentLi.parentNode,
3492 - fieldId = this.getAttribute( 'data-fid' );
3493 -
3494 - jQuery( parentLi ).fadeOut( 'slow', function() {
3495 - jQuery( parentLi ).remove();
3496 -
3497 - var hasOther = jQuery( parentUl ).find( '.frm_other_option' );
3498 - if ( hasOther.length < 1 ) {
3499 - otherInput = document.getElementById( 'other_input_' + fieldId );
3500 - if ( otherInput !== null ) {
3501 - otherInput.value = 0;
3502 - }
3503 - jQuery( '#other_button_' + fieldId ).fadeIn( 'slow' );
3504 - }
3505 - });
3506 - fieldUpdated();
3507 - }
3508 -
3509 - /**
3510 - * If a radio button is set as default, allow a click to
3511 - * deselect it.
3512 - */
3513 - function maybeUncheckRadio() {
3514 - var $self, uncheck, unbind, up;
3515 -
3516 - /*jshint validthis:true */
3517 - $self = jQuery( this );
3518 - if ( $self.is( ':checked' ) ) {
3519 - uncheck = function() {
3520 - setTimeout( function() {
3521 - $self.prop( 'checked', false );
3522 - }, 0 );
3523 - };
3524 - unbind = function() {
3525 - $self.off( 'mouseup', up );
3526 - };
3527 - up = function() {
3528 - uncheck();
3529 - unbind();
3530 - };
3531 - $self.on( 'mouseup', up );
3532 - $self.one( 'mouseout', unbind );
3533 - }
3534 - }
3535 -
3536 - /**
3537 - * If the field option has the default text, clear it out on click.
3538 - */
3539 - function maybeClearOptText() {
3540 - /*jshint validthis:true */
3541 - if ( this.value === frm_admin_js.new_option ) { // eslint-disable-line camelcase
3542 - this.setAttribute( 'data-value-on-focus', this.value );
3543 - this.value = '';
3544 - }
3545 - }
3546 -
3547 - function confirmFieldsDeleteMessage( numberOfFields ) {
3548 - /* translators: %1$s: Number of fields that are selected to be deleted. */
3549 - return __( 'Are you sure you want to delete these %1$s selected field(s)?', 'formidable' ).replace( '%1$s', numberOfFields );
3550 - }
3551 -
3552 - function clickDeleteField() {
3553 - /*jshint validthis:true */
3554 - var confirmMsg = frm_admin_js.conf_delete, // eslint-disable-line camelcase
3555 - maybeDivider = this.parentNode.parentNode.parentNode.parentNode.parentNode,
3556 - li = maybeDivider.parentNode,
3557 - field = jQuery( this ).closest( 'li.form-field' ),
3558 - fieldId = field.data( 'fid' );
3559 -
3560 - if ( field.data( 'ftype' ) === 'divider' ) {
3561 - const fieldBoxes = document.querySelectorAll( '.frm-field-group-hover-target .start_divider .frm_field_box' );
3562 - let fieldIdsToDelete = 0;
3563 - fieldBoxes.forEach( fieldBox => {
3564 - const fieldsInsideFieldBox = fieldBox.querySelectorAll( 'li.form-field' );
3565 - if ( fieldsInsideFieldBox ) {
3566 - fieldIdsToDelete += fieldsInsideFieldBox.length;
3567 - }
3568 - });
3569 - if ( fieldIdsToDelete ) {
3570 - confirmMsg = confirmFieldsDeleteMessage( ++fieldIdsToDelete );
3571 - }
3572 - }
3573 -
3574 - if ( li.classList.contains( 'frm-section-collapsed' ) || li.classList.contains( 'frm-page-collapsed' ) ) {
3575 - return false;
3576 - }
3577 -
3578 - // If deleting a section, use a special message.
3579 - if ( maybeDivider.className === 'divider_section_only' ) {
3580 - confirmMsg = frm_admin_js.conf_delete_sec; // eslint-disable-line camelcase
3581 - }
3582 -
3583 - this.setAttribute( 'data-frmverify', confirmMsg );
3584 - this.setAttribute( 'data-frmverify-btn', 'frm-button-red' );
3585 - this.setAttribute( 'data-deletefield', fieldId );
3586 -
3587 - closeOpenFieldDropdowns();
3588 -
3589 - confirmLinkClick( this );
3590 - return false;
3591 - }
3592 -
3593 - function clickSelectField() {
3594 - this.closest( 'li.form-field' ).click();
3595 - }
3596 -
3597 - function clickDeleteFieldGroup() {
3598 - var hoverTarget, decoy;
3599 -
3600 - hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3601 - if ( null === hoverTarget ) {
3602 - return;
3603 - }
3604 -
3605 - hoverTarget.classList.add( 'frm-selected-field-group' );
3606 -
3607 - decoy = document.createElement( 'div' );
3608 - decoy.classList.add( 'frm-delete-field-groups', 'frm_hidden' );
3609 - document.body.appendChild( decoy );
3610 - decoy.click();
3611 - }
3612 -
3613 - function duplicateFieldGroup() {
3614 - const hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3615 - if ( null === hoverTarget ) {
3616 - return;
3617 - }
3618 -
3619 - const newRowId = 'frm_field_group_' + getAutoId();
3620 - const placeholderUlChild = document.createTextNode( '' );
3621 - wrapFieldLiInPlace( placeholderUlChild );
3622 -
3623 - const newRow = jQuery( placeholderUlChild ).closest( 'li' ).get( 0 );
3624 - newRow.classList.add( 'frm_hidden' );
3625 -
3626 - const newRowUl = newRow.querySelector( 'ul' );
3627 - newRowUl.id = newRowId;
3628 -
3629 - jQuery( hoverTarget.closest( 'li.frm_field_box' ) ).after( newRow );
3630 -
3631 - const $fields = getFieldsInRow( jQuery( hoverTarget ) );
3632 - const syncDetails = [];
3633 - const injectedCloneOptions = [];
3634 -
3635 - const expectedLength = $fields.length;
3636 - const originalFieldIdByDuplicatedFieldId = {};
3637 -
3638 - let duplicatedCount = 0;
3639 -
3640 - jQuery( newRow ).on(
3641 - 'frm_added_duplicated_field_to_row',
3642 - function( _, args ) {
3643 - originalFieldIdByDuplicatedFieldId[ jQuery( args.duplicatedFieldHtml ).attr( 'data-fid' ) ] = args.originalFieldId;
3644 -
3645 - if ( expectedLength > ++duplicatedCount ) {
3646 - return;
3647 - }
3648 -
3649 - const $newRowUl = jQuery( newRowUl );
3650 - const $duplicatedFields = getFieldsInRow( $newRowUl );
3651 -
3652 - injectedCloneOptions.forEach(
3653 - function( cloneOption ) {
3654 - cloneOption.remove();
3655 - }
3656 - );
3657 -
3658 - for ( let index = 0; index < expectedLength; ++index ) {
3659 - $newRowUl.append( $newRowUl.children( 'li.form-field[frm-field-order="' + index + '"]' ) );
3660 - }
3661 -
3662 - syncLayoutClasses( $duplicatedFields.first(), syncDetails );
3663 - newRow.classList.remove( 'frm_hidden' );
3664 - updateFieldOrder();
3665 -
3666 - getFieldsInRow( $newRowUl ).each(
3667 - function() {
3668 - maybeDuplicateUnsavedSettings( originalFieldIdByDuplicatedFieldId[ this.getAttribute( 'data-fid' ) ], jQuery( this ).prop( 'outerHTML' ) );
3669 - }
3670 - );
3671 - }
3672 - );
3673 -
3674 - $fields.each(
3675 - function( index ) {
3676 - var cloneOption;
3677 - cloneOption = document.createElement( 'li' );
3678 - cloneOption.classList.add( 'frm_clone_field' );
3679 - cloneOption.setAttribute( 'frm-target-row-id', newRowId );
3680 - cloneOption.setAttribute( 'frm-field-order', index );
3681 - this.appendChild( cloneOption );
3682 - cloneOption.click();
3683 - injectedCloneOptions.push( cloneOption );
3684 - syncDetails.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) );
3685 - }
3686 - );
3687 - }
3688 -
3689 - function clickFieldGroupLayout() {
3690 - var hoverTarget, sizeOfFieldGroup, popupWrapper;
3691 -
3692 - hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3693 -
3694 - if ( null === hoverTarget ) {
3695 - return;
3696 - }
3697 -
3698 - deselectFields();
3699 -
3700 - sizeOfFieldGroup = getSizeOfFieldGroupFromChildElement( hoverTarget.querySelector( 'li.form-field' ) );
3701 -
3702 - hoverTarget.classList.add( 'frm-has-open-field-group-popup' );
3703 - jQuery( document ).on( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick );
3704 -
3705 - popupWrapper = div();
3706 - popupWrapper.style.position = 'relative';
3707 - popupWrapper.appendChild( getFieldGroupPopup( sizeOfFieldGroup, this ) );
3708 - this.parentNode.appendChild( popupWrapper );
3709 -
3710 - const firstLayoutOption = popupWrapper.querySelector( '.frm-row-layout-option' );
3711 - if ( firstLayoutOption ) {
3712 - firstLayoutOption.focus();
3713 - }
3714 - }
3715 -
3716 - function destroyFieldGroupPopupOnOutsideClick( event ) {
3717 - if ( event.target.classList.contains( 'frm-custom-field-group-layout' ) || event.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) {
3718 - return;
3719 - }
3720 - if ( ! jQuery( event.target ).closest( '#frm_field_group_controls' ).length && ! jQuery( event.target ).closest( '#frm_field_group_popup' ).length ) {
3721 - destroyFieldGroupPopup();
3722 - }
3723 - }
3724 -
3725 - function getSizeOfFieldGroupFromChildElement( element ) {
3726 - var $ul = jQuery( element ).closest( 'ul' );
3727 - if ( $ul.length ) {
3728 - return getFieldsInRow( $ul ).length;
3729 - }
3730 - return getSelectedFieldCount();
3731 - }
3732 -
3733 - function getFieldGroupPopup( sizeOfFieldGroup, childElement ) {
3734 - var popup, wrapper, rowLayoutOptions, ul;
3735 -
3736 - popup = document.getElementById( 'frm_field_group_popup' );
3737 - if ( null === popup ) {
3738 - popup = div();
3739 - } else {
3740 - popup.innerHTML = '';
3741 - }
3742 -
3743 - popup.id = 'frm_field_group_popup';
3744 -
3745 - wrapper = div();
3746 - wrapper.style.padding = '0 24px 12px';
3747 - wrapper.appendChild( getRowLayoutTitle() );
3748 -
3749 - rowLayoutOptions = getRowLayoutOptions( sizeOfFieldGroup );
3750 -
3751 - ul = childElement.closest( 'ul.frm_sorting' );
3752 - if ( null !== ul ) {
3753 - maybeMarkRowLayoutAsActive( ul, rowLayoutOptions );
3754 - }
3755 -
3756 - wrapper.appendChild( rowLayoutOptions );
3757 -
3758 - popup.appendChild( wrapper );
3759 - popup.appendChild( separator() );
3760 -
3761 - popup.appendChild( getCustomLayoutOption() );
3762 - popup.appendChild( getBreakIntoDifferentRowsOption() );
3763 -
3764 - return popup;
3765 - }
3766 -
3767 - function maybeMarkRowLayoutAsActive( activeRow, options ) {
3768 - var length, index, currentRow;
3769 -
3770 - length = options.children.length;
3771 - for ( index = 0; index < length; ++index ) {
3772 - currentRow = options.children[ index ];
3773 - if ( rowLayoutsMatch( currentRow, activeRow ) ) {
3774 - currentRow.classList.add( 'frm-active-row-layout' );
3775 - return;
3776 - }
3777 - }
3778 - }
3779 -
3780 - function separator() {
3781 - var hr = document.createElement( 'hr' );
3782 - return hr;
3783 - }
3784 -
3785 - function getCustomLayoutOption() {
3786 - var option = div();
3787 - option.textContent = __( 'Custom layout', 'formidable' );
3788 - jQuery( option ).prepend( getIconClone( 'frm_gear_svg' ) );
3789 - option.classList.add( 'frm-custom-field-group-layout' );
3790 - makeTabbable( option );
3791 - return option;
3792 - }
3793 -
3794 - function makeTabbable( element, ariaLabel ) {
3795 - element.setAttribute( 'tabindex', 0 );
3796 - element.setAttribute( 'role', 'button' );
3797 - if ( 'undefined' !== typeof ariaLabel ) {
3798 - element.setAttribute( 'aria-label', ariaLabel );
3799 - }
3800 - }
3801 -
3802 - function getIconClone( iconId ) {
3803 - var clone = document.getElementById( iconId ).cloneNode( true );
3804 - clone.id = '';
3805 - return clone;
3806 - }
3807 -
3808 - function getBreakIntoDifferentRowsOption() {
3809 - var option = div();
3810 - option.textContent = __( 'Break into rows', 'formidable' );
3811 - jQuery( option ).prepend( getIconClone( 'frm_break_field_group_svg' ) );
3812 - option.classList.add( 'frm-break-field-group' );
3813 - makeTabbable( option );
3814 - return option;
3815 - }
3816 -
3817 - function getRowLayoutTitle() {
3818 - var rowLayoutTitle = div();
3819 - rowLayoutTitle.classList.add( 'frm-row-layout-title' );
3820 - rowLayoutTitle.textContent = __( 'Row Layout', 'formidable' );
3821 - return rowLayoutTitle;
3822 - }
3823 -
3824 - function getRowLayoutOptions( size ) {
3825 - var wrapper, padding;
3826 -
3827 - wrapper = getEmptyGridContainer();
3828 - if ( 5 !== size ) {
3829 - wrapper.appendChild( getRowLayoutOption( size, 'even' ) );
3830 - }
3831 - if ( size % 2 === 1 ) {
3832 - // only include the middle option for odd numbers because even doesn't make a lot of sense.
3833 - wrapper.appendChild( getRowLayoutOption( size, 'middle' ) );
3834 - }
3835 - if ( size < 6 ) {
3836 - wrapper.appendChild( getRowLayoutOption( size, 'left' ) );
3837 - wrapper.appendChild( getRowLayoutOption( size, 'right' ) );
3838 - } else {
3839 - padding = div();
3840 - padding.classList.add( 'frm_fourth' );
3841 - wrapper.prepend( padding );
3842 - }
3843 -
3844 - return wrapper;
3845 - }
3846 -
3847 - function getRowLayoutOption( size, type ) {
3848 - var option, useClass;
3849 -
3850 - option = div();
3851 - option.classList.add( 'frm-row-layout-option' );
3852 - makeTabbable( option, type );
3853 -
3854 - switch ( size ) {
3855 - case 6:
3856 - useClass = 'frm_half';
3857 - break;
3858 - case 5:
3859 - useClass = 'frm_third';
3860 - break;
3861 - default:
3862 - useClass = size % 2 === 1 ? 'frm_fourth' : 'frm_third';
3863 - break;
3864 - }
3865 -
3866 - option.classList.add( useClass );
3867 - option.setAttribute( 'layout-type', type );
3868 -
3869 - option.appendChild( getRowForSizeAndType( size, type ) );
3870 - return option;
3871 - }
3872 -
3873 - function rowLayoutsMatch( row1, row2 ) {
3874 - return getRowLayoutAsKey( row1 ) === getRowLayoutAsKey( row2 );
3875 - }
3876 -
3877 - function getRowLayoutAsKey( row ) {
3878 - var $fields, sizes;
3879 - if ( row.classList.contains( 'frm-row-layout-option' ) ) {
3880 - $fields = jQuery( row ).find( '.frm_grid_container' ).children();
3881 - } else {
3882 - $fields = getFieldsInRow( jQuery( row ) );
3883 - }
3884 - sizes = [];
3885 - $fields.each(
3886 - function() {
3887 - sizes.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) );
3888 - }
3889 - );
3890 - return sizes.join( '-' );
3891 - }
3892 -
3893 - function getRowForSizeAndType( size, type ) {
3894 - var row, index, block;
3895 -
3896 - row = getEmptyGridContainer();
3897 - for ( index = 0; index < size; ++index ) {
3898 - block = div();
3899 - block.classList.add( getClassForBlock( size, type, index ) );
3900 - block.style.height = '16px';
3901 - block.style.background = '#9EA9B8';
3902 - block.style.borderRadius = '1px';
3903 - row.appendChild( block );
3904 - }
3905 -
3906 - return row;
3907 - }
3908 -
3909 - /**
3910 - * @param {int} size 2-6.
3911 - * @param {string} type even, middle, left, or right.
3912 - * @param {int} index 0-5.
3913 - * @returns string
3914 - */
3915 - function getClassForBlock( size, type, index ) {
3916 - if ( 'even' === type ) {
3917 - return getEvenClassForSize( size, index );
3918 - } else if ( 'middle' === type ) {
3919 - if ( 3 === size ) {
3920 - return 1 === index ? 'frm6' : 'frm3';
3921 - }
3922 - if ( 5 === size ) {
3923 - return 2 === index ? 'frm4' : 'frm2';
3924 - }
3925 - } else if ( 'left' === type ) {
3926 - return 0 === index ? getLargeClassForSize( size ) : getSmallClassForSize( size );
3927 - } else if ( 'right' === type ) {
3928 - return index === size - 1 ? getLargeClassForSize( size ) : getSmallClassForSize( size );
3929 - }
3930 - return 'frm12';
3931 - }
3932 -
3933 - function getEvenClassForSize( size, index ) {
3934 - if ( -1 !== [ 2, 3, 4, 6 ].indexOf( size ) ) {
3935 - return getLayoutClassForSize( 12 / size );
3936 - }
3937 - if ( 5 === size && 'undefined' !== typeof index ) {
3938 - return 0 === index ? 'frm4' : 'frm2';
3939 - }
3940 - return 'frm12';
3941 - }
3942 -
3943 - function getSmallClassForSize( size ) {
3944 - switch ( size ) {
3945 - case 2: case 3:
3946 - return 'frm3';
3947 - case 4:
3948 - return 'frm2';
3949 - case 5:
3950 - return 'frm2';
3951 - case 6:
3952 - return 'frm1';
3953 - }
3954 - return 'frm12';
3955 - }
3956 -
3957 - function getLargeClassForSize( size ) {
3958 - switch ( size ) {
3959 - case 2:
3960 - return 'frm9';
3961 - case 3: case 4:
3962 - return 'frm6';
3963 - case 5:
3964 - return 'frm4';
3965 - case 6:
3966 - return 'frm7';
3967 - }
3968 - return 'frm12';
3969 - }
3970 -
3971 - function getEmptyGridContainer() {
3972 - var wrapper = div();
3973 - wrapper.classList.add( 'frm_grid_container' );
3974 - return wrapper;
3975 - }
3976 -
3977 - /**
3978 - * Handle when a field group layout option (that sets grid classes/column sizing) is selected in the "Row Layout" popup.
3979 - *
3980 - * @returns {void}
3981 - */
3982 - function handleFieldGroupLayoutOptionClick() {
3983 - const row = document.querySelector( '.frm-field-group-hover-target' );
3984 - if ( ! row ) {
3985 - // The field group layout options also get clicked when merging multiple rows.
3986 - // The following code isn't required for multiple rows though so just exit early.
3987 - return;
3988 - }
3989 -
3990 - const type = this.getAttribute( 'layout-type' );
3991 - syncLayoutClasses( getFieldsInRow( jQuery( row ) ).first(), type );
3992 - destroyFieldGroupPopup();
3993 - }
3994 -
3995 - function handleFieldGroupLayoutOptionInsideMergeClick() {
3996 - var $ul, type;
3997 - $ul = mergeSelectedFieldGroups();
3998 - type = this.getAttribute( 'layout-type' );
3999 - syncLayoutClasses( getFieldsInRow( $ul ).first(), type );
4000 - unselectFieldGroups();
4001 - }
4002 -
4003 - function mergeSelectedFieldGroups() {
4004 - var $selectedFieldGroups = jQuery( '.frm-selected-field-group' ),
4005 - $firstGroupUl = $selectedFieldGroups.first();
4006 - $selectedFieldGroups.not( $firstGroupUl ).each(
4007 - function() {
4008 - getFieldsInRow( jQuery( this ) ).each(
4009 - function() {
4010 - var previousParent = this.parentNode;
4011 - getFieldsInRow( $firstGroupUl ).last().after( this );
4012 - if ( ! jQuery( previousParent ).children( 'li.form-field' ).length ) {
4013 - // clean up the previous field group if we've removed all of its fields.
4014 - previousParent.closest( 'li.frm_field_box' ).remove();
4015 - }
4016 - }
4017 - );
4018 - }
4019 - );
4020 - updateFieldOrder();
4021 - syncLayoutClasses( getFieldsInRow( $firstGroupUl ).first() );
4022 - return $firstGroupUl;
4023 - }
4024 -
4025 - function customFieldGroupLayoutClick() {
4026 - var $fields;
4027 - if ( null !== this.closest( '.frm-merge-fields-into-row' ) ) {
4028 - return;
4029 - }
4030 - $fields = getFieldsInRow( jQuery( '.frm-field-group-hover-target' ) );
4031 - setupCustomLayoutOptions( $fields );
4032 - }
4033 -
4034 - function setupCustomLayoutOptions( $fields ) {
4035 - var size, popup, wrapper, layoutClass, inputRow, paddingElement, inputValueOverride, index, inputField, heading, label, buttonsWrapper, cancelButton, saveButton;
4036 -
4037 - size = $fields.length;
4038 -
4039 - popup = document.getElementById( 'frm_field_group_popup' );
4040 - popup.innerHTML = '';
4041 -
4042 - wrapper = div();
4043 - wrapper.style.padding = '0 24px';
4044 -
4045 - layoutClass = getEvenClassForSize( 5 === size ? 6 : size );
4046 -
4047 - inputRow = div();
4048 - inputRow.style.padding = '20px 0';
4049 - inputRow.classList.add( 'frm_grid_container' );
4050 -
4051 - if ( 5 === size ) {
4052 - // add a span to pad the inputs by 1 column, to account for the missing 2 columns.
4053 - paddingElement = document.createElement( 'span' );
4054 - paddingElement.classList.add( 'frm1' );
4055 - inputRow.appendChild( paddingElement );
4056 - }
4057 -
4058 - inputValueOverride = getSelectedFieldCount() > 0 ? getSizeOfLayoutClass( getEvenClassForSize( size ) ) : false;
4059 - if ( false !== inputValueOverride && inputValueOverride >= 12 ) {
4060 - inputValueOverride = Math.floor( 12 / size );
4061 - }
4062 -
4063 - for ( index = 0; index < size; ++index ) {
4064 - inputField = document.createElement( 'input' );
4065 - inputField.type = 'text';
4066 - inputField.classList.add( layoutClass );
4067 - inputField.classList.add( 'frm-custom-grid-size-input' );
4068 - inputField.value = false !== inputValueOverride ? inputValueOverride : getSizeOfLayoutClass( getLayoutClassName( $fields.get( index ).classList ) );
4069 - inputRow.appendChild( inputField );
4070 - }
4071 -
4072 - heading = div();
4073 - heading.classList.add( 'frm-builder-popup-heading' );
4074 - heading.textContent = __( 'Enter number of columns for each field', 'formidable' );
4075 -
4076 - label = div();
4077 - label.classList.add( 'frm-builder-popup-subheading' );
4078 - label.textContent = __( 'Layouts are based on a 12-column grid system', 'formidable' );
4079 -
4080 - wrapper.appendChild( heading );
4081 - wrapper.appendChild( label );
4082 -
4083 - wrapper.appendChild( inputRow );
4084 -
4085 - buttonsWrapper = div();
4086 - buttonsWrapper.style.textAlign = 'right';
4087 -
4088 - cancelButton = getSecondaryButton();
4089 - cancelButton.textContent = __( 'Cancel', 'formidable' );
4090 - cancelButton.classList.add( 'frm-cancel-custom-field-group-layout' );
4091 - cancelButton.style.marginRight = '10px';
4092 -
4093 - saveButton = getPrimaryButton();
4094 - saveButton.textContent = __( 'Save', 'formidable' );
4095 - saveButton.classList.add( 'frm-save-custom-field-group-layout' );
4096 -
4097 - buttonsWrapper.appendChild( cancelButton );
4098 - buttonsWrapper.appendChild( saveButton );
4099 -
4100 - wrapper.appendChild( buttonsWrapper );
4101 -
4102 - popup.appendChild( wrapper );
4103 -
4104 - setTimeout(
4105 - function() {
4106 - const firstInput = popup.querySelector( 'input.frm-custom-grid-size-input' ).focus();
4107 - if ( firstInput ) {
4108 - firstInput.focus();
4109 - }
4110 - },
4111 - 0
4112 - );
4113 - }
4114 -
4115 - function customFieldGroupLayoutInsideMergeClick() {
4116 - $fields = jQuery( '.frm-selected-field-group li.form-field' );
4117 - setupCustomLayoutOptions( $fields );
4118 - }
4119 -
4120 - function getPrimaryButton() {
4121 - var button = getButton();
4122 - button.classList.add( 'button-primary', 'frm-button-primary' );
4123 - return button;
4124 - }
4125 -
4126 - function getSecondaryButton() {
4127 - var button = getButton();
4128 - button.classList.add( 'button-secondary', 'frm-button-secondary' );
4129 - return button;
4130 - }
4131 -
4132 - function getButton() {
4133 - var button = document.createElement( 'a' );
4134 - button.setAttribute( 'href', '#' );
4135 - button.classList.add( 'button' );
4136 - button.style.textDecoration = 'none';
4137 - return button;
4138 - }
4139 -
4140 - function getSizeOfLayoutClass( className ) {
4141 - switch ( className ) {
4142 - case 'frm_half':
4143 - return 6;
4144 - case 'frm_third':
4145 - return 4;
4146 - case 'frm_two_thirds':
4147 - return 8;
4148 - case 'frm_fourth':
4149 - return 3;
4150 - case 'frm_three_fourths':
4151 - return 9;
4152 - case 'frm_sixth':
4153 - return 2;
4154 - }
4155 -
4156 - if ( 0 === className.indexOf( 'frm' ) ) {
4157 - return parseInt( className.substr( 3 ) );
4158 - }
4159 -
4160 - // Anything missing a layout class should be a full width row.
4161 - return 12;
4162 - }
4163 -
4164 - function getLayoutClassName( classList ) {
4165 - var classes, index, currentClass;
4166 - classes = getLayoutClasses();
4167 - for ( index = 0; index < classes.length; ++index ) {
4168 - currentClass = classes[ index ];
4169 - if ( classList.contains( currentClass ) ) {
4170 - return currentClass;
4171 - }
4172 - }
4173 - return '';
4174 - }
4175 -
4176 - function getLayoutClassForSize( size ) {
4177 - return 'frm' + size;
4178 - }
4179 -
4180 - function breakFieldGroupClick() {
4181 - var row = document.querySelector( '.frm-field-group-hover-target' );
4182 - breakRow( row );
4183 - destroyFieldGroupPopup();
4184 - }
4185 -
4186 - function breakRow( row ) {
4187 - const $row = jQuery( row );
4188 - getFieldsInRow( $row ).each(
4189 - function( index ) {
4190 - const field = this;
4191 - if ( 0 !== index ) {
4192 - $row.parent().after( wrapFieldLi( field ) );
4193 - }
4194 - stripLayoutFromFields( jQuery( field ) );
4195 - }
4196 - );
4197 - }
4198 -
4199 - function stripLayoutFromFields( field ) {
4200 - syncLayoutClasses( field, 'clear' );
4201 - }
4202 -
4203 - function focusFieldGroupInputOnClick() {
4204 - this.select();
4205 - }
4206 -
4207 - function cancelCustomFieldGroupClick() {
4208 - revertToFieldGroupPopupFirstPage( this );
4209 - }
4210 -
4211 - function revertToFieldGroupPopupFirstPage( triggerElement ) {
4212 - jQuery( document.getElementById( 'frm_field_group_popup' ) ).replaceWith(
4213 - getFieldGroupPopup( getSizeOfFieldGroupFromChildElement( triggerElement ), triggerElement )
4214 - );
4215 - }
4216 -
4217 - function destroyFieldGroupPopup() {
4218 - var popup, wrapper;
4219 - popup = document.getElementById( 'frm_field_group_popup' );
4220 - if ( popup === null ) {
4221 - return;
4222 - }
4223 - wrapper = document.querySelector( '.frm-has-open-field-group-popup' );
4224 - if ( null !== wrapper ) {
4225 - wrapper.classList.remove( 'frm-has-open-field-group-popup' );
4226 - popup.parentNode.remove();
4227 - }
4228 - jQuery( document ).off( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick );
4229 - }
4230 -
4231 - function saveCustomFieldGroupClick() {
4232 - var syncDetails, $controls, $ul;
4233 -
4234 - syncDetails = [];
4235 -
4236 - jQuery( document.getElementById( 'frm_field_group_popup' ).querySelectorAll( '.frm_grid_container input' ) )
4237 - .each(
4238 - function() {
4239 - syncDetails.push( parseInt( this.value ) );
4240 - }
4241 - );
4242 -
4243 - $controls = jQuery( document.getElementById( 'frm_field_group_controls' ) );
4244 -
4245 - if ( $controls.length && 'none' !== $controls.get( 0 ).style.display ) {
4246 - syncLayoutClasses( getFieldsInRow( jQuery( document.querySelector( '.frm-field-group-hover-target' ) ) ).first(), syncDetails );
4247 - } else {
4248 - $ul = mergeSelectedFieldGroups();
4249 - syncLayoutClasses( getFieldsInRow( $ul ).first(), syncDetails );
4250 - unselectFieldGroups();
4251 - }
4252 -
4253 - destroyFieldGroupPopup();
4254 - }
4255 -
4256 - function fieldGroupClick( e ) {
4257 - if ( 'ul' !== e.originalEvent.target.nodeName.toLowerCase() ) {
4258 - // only continue if the group itself was clicked / ignore when a field is clicked.
4259 - return;
4260 - }
4261 -
4262 - const hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
4263 - if ( ! hoverTarget ) {
4264 - return;
4265 - }
4266 -
4267 - const ctrlOrCmdKeyIsDown = e.ctrlKey || e.metaKey;
4268 - const shiftKeyIsDown = e.shiftKey;
4269 - const groupIsActive = hoverTarget.classList.contains( 'frm-selected-field-group' );
4270 - const $selectedFieldGroups = getSelectedFieldGroups();
4271 -
4272 - let numberOfSelectedGroups = $selectedFieldGroups.length;
4273 -
4274 - if ( ctrlOrCmdKeyIsDown || shiftKeyIsDown ) {
4275 - // multi-selecting
4276 -
4277 - const selectedField = getSelectedField();
4278 - if ( null !== selectedField && ! jQuery( selectedField ).siblings( 'li.form-field' ).length ) {
4279 - // count a selected field on its own as a selected field group when multiselecting.
4280 - selectedField.parentNode.classList.add( 'frm-selected-field-group' );
4281 - ++numberOfSelectedGroups;
4282 - }
4283 -
4284 - if ( ctrlOrCmdKeyIsDown ) {
4285 - if ( groupIsActive ) {
4286 - // unselect if holding ctrl or cmd and the group was already active.
4287 - --numberOfSelectedGroups;
4288 - hoverTarget.classList.remove( 'frm-selected-field-group' );
4289 - syncAfterMultiSelect( numberOfSelectedGroups );
4290 - return; // exit early to avoid adding back frm-selected-field-group
4291 - } else {
4292 - ++numberOfSelectedGroups;
4293 - }
4294 - } else if ( shiftKeyIsDown && ! groupIsActive ) {
4295 - ++numberOfSelectedGroups; // include the one we're selecting right now.
4296 - const $firstGroup = $selectedFieldGroups.first();
4297 -
4298 - let $range;
4299 - if ( $firstGroup.parent().index() < jQuery( hoverTarget.parentNode ).index() ) {
4300 - $range = $firstGroup.parent().nextUntil( hoverTarget.parentNode );
4301 - } else {
4302 - $range = $firstGroup.parent().prevUntil( hoverTarget.parentNode );
4303 - }
4304 -
4305 - $range.each(
4306 - function() {
4307 - var $fieldGroup = jQuery( this ).closest( 'li' ).find( 'ul.frm_sorting' );
4308 - if ( ! $fieldGroup.hasClass( 'frm-selected-field-group' ) ) {
4309 - ++numberOfSelectedGroups;
4310 - $fieldGroup.addClass( 'frm-selected-field-group' );
4311 - }
4312 - }
4313 - );
4314 -
4315 - // when holding shift and clicking, text gets selected. unselect it.
4316 - document.getSelection().removeAllRanges();
4317 - }
4318 - } else {
4319 - // not multi-selecting
4320 - unselectFieldGroups();
4321 - numberOfSelectedGroups = 1;
4322 - }
4323 -
4324 - hoverTarget.classList.add( 'frm-selected-field-group' );
4325 - syncAfterMultiSelect( numberOfSelectedGroups );
4326 -
4327 - jQuery( document ).off( 'click', unselectFieldGroups );
4328 - jQuery( document ).on( 'click', unselectFieldGroups );
4329 - }
4330 -
4331 - function getSelectedField() {
4332 - return document.getElementById( 'frm-show-fields' ).querySelector( 'li.form-field.selected' );
4333 - }
4334 -
4335 - function getSelectedFieldGroups() {
4336 - const $fieldGroups = jQuery( '.frm-selected-field-group' );
4337 - if ( $fieldGroups.length ) {
4338 - return $fieldGroups;
4339 - }
4340 -
4341 - const selectedField = getSelectedField();
4342 - if ( selectedField ) {
4343 - // If there is only one field in a group and the field is selected, consider the field's group as selected for multi-select.
4344 - const selectedFieldGroup = selectedField.closest( 'ul' );
4345 - if ( selectedFieldGroup && 1 === getFieldsInRow( jQuery( selectedFieldGroup ) ).length ) {
4346 - selectedFieldGroup.classList.add( 'frm-selected-field-group' );
4347 - return jQuery( selectedFieldGroup );
4348 - }
4349 - }
4350 -
4351 - return jQuery();
4352 - }
4353 -
4354 - function syncAfterMultiSelect( numberOfSelectedGroups ) {
4355 - clearSettingsBox( true ); // unselect any fields if one is selected.
4356 - if ( numberOfSelectedGroups >= 2 || ( 1 === numberOfSelectedGroups && selectedGroupHasMultipleFields() ) ) {
4357 - addFieldMultiselectPopup();
4358 - } else {
4359 - maybeRemoveMultiselectPopup();
4360 - }
4361 - maybeRemoveGroupHoverTarget();
4362 - }
4363 -
4364 - function selectedGroupHasMultipleFields() {
4365 - return getFieldsInRow( jQuery( document.querySelector( '.frm-selected-field-group' ) ) ).length > 1;
4366 - }
4367 -
4368 - function unselectFieldGroups( event ) {
4369 - if ( 'undefined' !== typeof event ) {
4370 - if ( null !== event.originalEvent.target.closest( '#frm-show-fields' ) ) {
4371 - return;
4372 - }
4373 - if ( event.originalEvent.target.classList.contains( 'frm-merge-fields-into-row' ) ) {
4374 - return;
4375 - }
4376 - if ( null !== event.originalEvent.target.closest( '.frm-merge-fields-into-row' ) ) {
4377 - return;
4378 - }
4379 - if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) {
4380 - return;
4381 - }
4382 - if ( event.originalEvent.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) {
4383 - return;
4384 - }
4385 - }
4386 - jQuery( '.frm-selected-field-group' ).removeClass( 'frm-selected-field-group' );
4387 - jQuery( document ).off( 'click', unselectFieldGroups );
4388 - maybeRemoveMultiselectPopup();
4389 - }
4390 -
4391 - function maybeRemoveMultiselectPopup() {
4392 - var popup = document.getElementById( 'frm_field_multiselect_popup' );
4393 - if ( null !== popup ) {
4394 - popup.remove();
4395 - }
4396 - }
4397 -
4398 - function addFieldMultiselectPopup() {
4399 - getFieldMultiselectPopup();
4400 - }
4401 -
4402 - function getFieldMultiselectPopup() {
4403 - var popup, mergeOption, caret, verticalSeparator, deleteOption;
4404 -
4405 - popup = document.getElementById( 'frm_field_multiselect_popup' );
4406 -
4407 - if ( null !== popup ) {
4408 - popup.classList.toggle( 'frm-unmergable', ! selectedFieldsAreMergable() );
4409 - return popup;
4410 - }
4411 -
4412 - popup = div();
4413 - popup.id = 'frm_field_multiselect_popup';
4414 - if ( ! selectedFieldsAreMergable() ) {
4415 - popup.classList.add( 'frm-unmergable' );
4416 - }
4417 -
4418 - mergeOption = div();
4419 - mergeOption.classList.add( 'frm-merge-fields-into-row' );
4420 - mergeOption.textContent = __( 'Merge into row', 'formidable' );
4421 -
4422 - caret = document.createElement( 'a' );
4423 - caret.style.marginLeft = '5px';
4424 - caret.classList.add( 'frm_icon_font', 'frm_arrowdown6_icon' );
4425 - caret.setAttribute( 'href', '#' );
4426 - mergeOption.appendChild( caret );
4427 -
4428 - popup.appendChild( mergeOption );
4429 -
4430 - verticalSeparator = div();
4431 - verticalSeparator.classList.add( 'frm-multiselect-popup-separator' );
4432 - popup.appendChild( verticalSeparator );
4433 -
4434 - deleteOption = div();
4435 - deleteOption.classList.add( 'frm-delete-field-groups' );
4436 - deleteOption.appendChild( getIconClone( 'frm_trash_svg' ) );
4437 - popup.appendChild( deleteOption );
4438 -
4439 - document.getElementById( 'post-body-content' ).appendChild( popup );
4440 -
4441 - jQuery( popup ).hide().fadeIn();
4442 -
4443 - return popup;
4444 - }
4445 -
4446 - function selectedFieldsAreMergable() {
4447 - var selectedFieldGroups, totalFieldCount, length, index, fieldGroup;
4448 - selectedFieldGroups = document.querySelectorAll( '.frm-selected-field-group' );
4449 - length = selectedFieldGroups.length;
4450 - if ( 1 === length ) {
4451 - return false;
4452 - }
4453 - totalFieldCount = 0;
4454 - for ( index = 0; index < length; ++index ) {
4455 - fieldGroup = selectedFieldGroups[ index ];
4456 - if ( null !== fieldGroup.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ) ) {
4457 - return false;
4458 - }
4459 - totalFieldCount += getFieldsInRow( jQuery( fieldGroup ) ).length;
4460 - if ( totalFieldCount > 6 ) {
4461 - return false;
4462 - }
4463 - }
4464 - return true;
4465 - }
4466 -
4467 - function mergeFieldsIntoRowClick( event ) {
4468 - var size, popup;
4469 -
4470 - if ( null !== event.originalEvent.target.closest( '#frm_field_group_popup' ) ) {
4471 - // prevent clicks within the popup from triggering the button again.
4472 - return;
4473 - }
4474 -
4475 - if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) {
4476 - // avoid switching back to the first page when clicking the custom option nested inside of the merge option.
4477 - return;
4478 - }
4479 -
4480 - size = getSelectedFieldCount();
4481 - popup = getFieldGroupPopup( size, document.querySelector( '.frm-selected-field-group' ).firstChild );
4482 - this.appendChild( popup );
4483 - }
4484 -
4485 - function getSelectedFieldCount() {
4486 - var count = 0;
4487 - jQuery( document.querySelectorAll( '.frm-selected-field-group' ) ).each(
4488 - function() {
4489 - count += getFieldsInRow( jQuery( this ) ).length;
4490 - }
4491 - );
4492 - return count;
4493 - }
4494 -
4495 - function deleteFieldGroupsClick() {
4496 - var fieldIdsToDelete, deleteOnConfirm, multiselectPopup;
4497 -
4498 - fieldIdsToDelete = getSelectedFieldIds();
4499 - deleteOnConfirm = getDeleteSelectedFieldGroupsOnConfirmFunction( fieldIdsToDelete );
4500 -
4501 - multiselectPopup = document.getElementById( 'frm_field_multiselect_popup' );
4502 - if ( null !== multiselectPopup ) {
4503 - multiselectPopup.remove();
4504 - }
4505 -
4506 - this.setAttribute( 'data-frmverify', confirmFieldsDeleteMessage( fieldIdsToDelete.length ) );
4507 - confirmLinkClick( this );
4508 -
4509 - jQuery( '#frm-confirmed-click' ).on( 'click', deleteOnConfirm );
4510 - jQuery( '#frm_confirm_modal' ).one( 'dialogclose', function() {
4511 - jQuery( '#frm-confirmed-click' ).off( 'click', deleteOnConfirm );
4512 - });
4513 - }
4514 -
4515 - function getSelectedFieldIds() {
4516 - var deleteFieldIds = [];
4517 - jQuery( '.frm-selected-field-group > li.form-field' )
4518 - .each(
4519 - function() {
4520 - deleteFieldIds.push( this.dataset.fid );
4521 - }
4522 - );
4523 - return deleteFieldIds;
4524 - }
4525 -
4526 - function getDeleteSelectedFieldGroupsOnConfirmFunction( deleteFieldIds ) {
4527 - return function( event ) {
4528 - event.preventDefault();
4529 - deleteAllSelectedFieldGroups( deleteFieldIds );
4530 - };
4531 - }
4532 -
4533 - function deleteAllSelectedFieldGroups( deleteFieldIds ) {
4534 - deleteFieldIds.forEach(
4535 - function( fieldId ) {
4536 - deleteFields( fieldId );
4537 - }
4538 - );
4539 - }
4540 -
4541 - function deleteFieldConfirmed() {
4542 - /*jshint validthis:true */
4543 - deleteFields( this.getAttribute( 'data-deletefield' ) );
4544 - }
4545 -
4546 - function deleteFields( fieldId ) {
4547 - var field = jQuery( '#frm_field_id_' + fieldId );
4548 -
4549 - deleteField( fieldId );
4550 -
4551 - if ( field.hasClass( 'edit_field_type_divider' ) ) {
4552 - field.find( 'li.frm_field_box' ).each( function() {
4553 - //TODO: maybe delete only end section
4554 - //if(n.hasClass('edit_field_type_end_divider')){
4555 - deleteField( this.getAttribute( 'data-fid' ) );
4556 - //}
4557 - });
4558 - }
4559 - toggleSectionHolder();
4560 - }
4561 -
4562 - function deleteField( fieldId ) {
4563 - jQuery.ajax({
4564 - type: 'POST',
4565 - url: ajaxurl,
4566 - data: {
4567 - action: 'frm_delete_field',
4568 - field_id: fieldId,
4569 - nonce: frmGlobal.nonce
4570 - },
4571 - success: function() {
4572 - var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ),
4573 - settings = jQuery( '#frm-single-settings-' + fieldId );
4574 -
4575 - // Remove settings from sidebar.
4576 - if ( settings.is( ':visible' ) ) {
4577 - document.getElementById( 'frm_insert_fields_tab' ).click();
4578 - }
4579 - settings.remove();
4580 -
4581 - $thisField.fadeOut( 'slow', function() {
4582 - var $section = $thisField.closest( '.start_divider' ),
4583 - type = $thisField.data( 'type' ),
4584 - $adjacentFields = $thisField.siblings( 'li.form-field' ),
4585 - $liWrapper;
4586 -
4587 - if ( ! $adjacentFields.length ) {
4588 - if ( $thisField.is( '.edit_field_type_end_divider' ) ) {
4589 - $adjacentFields.length = $thisField.closest( 'li.form-field' ).siblings();
4590 - } else {
4591 - $liWrapper = $thisField.closest( 'ul.frm_sorting' ).parent();
4592 - }
4593 - }
4594 -
4595 - $thisField.remove();
4596 - if ( type === 'break' ) {
4597 - renumberPageBreaks();
4598 - }
4599 - if ( type === 'product' ) {
4600 - maybeHideQuantityProductFieldOption();
4601 - // a product field attached to a quantity field earlier might be the one deleted, so re-populate
4602 - popAllProductFields();
4603 - }
4604 - if ( jQuery( '#frm-show-fields li' ).length === 0 ) {
4605 - document.getElementById( 'frm_form_editor_container' ).classList.remove( 'frm-has-fields' );
4606 - } else if ( $section.length ) {
4607 - toggleOneSectionHolder( $section );
4608 - }
4609 - if ( $adjacentFields.length ) {
4610 - syncLayoutClasses( $adjacentFields.first() );
4611 - } else {
4612 - $liWrapper.remove();
4613 - }
4614 -
4615 - // prevent "More Options" tooltips from staying around after their target field is deleted.
4616 - deleteTooltips();
4617 - });
4618 - }
4619 - });
4620 - }
4621 -
4622 - function addFieldLogicRow() {
4623 - /*jshint validthis:true */
4624 - var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
4625 - formId = thisFormId,
4626 - logicRows = document.getElementById( 'frm_logic_row_' + id ).querySelectorAll( '.frm_logic_row' );
4627 - jQuery.ajax({
4628 - type: 'POST',
4629 - url: ajaxurl,
4630 - data: {
4631 - action: 'frm_add_logic_row',
4632 - form_id: formId,
4633 - field_id: id,
4634 - nonce: frmGlobal.nonce,
4635 - meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ),
4636 - fields: getFieldList()
4637 - },
4638 - success: function( html ) {
4639 - jQuery( document.getElementById( 'logic_' + id ) ).fadeOut( 'slow', function() {
4640 - var logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) );
4641 - logicRow.append( html );
4642 - logicRow.closest( '.frm_logic_rows' ).fadeIn( 'slow' );
4643 - });
4644 - }
4645 - });
4646 - return false;
4647 - }
4648 -
4649 - function getNewRowId( rows, replace, defaultValue ) {
4650 - if ( ! rows.length ) {
4651 - return 'undefined' !== typeof defaultValue ? defaultValue : 0;
4652 - }
4653 - return parseInt( rows[ rows.length - 1 ].id.replace( replace, '' ), 10 ) + 1;
4654 - }
4655 -
4656 - function addWatchLookupRow() {
4657 - /*jshint validthis:true */
4658 - var lastRowId,
4659 - id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
4660 - formId = thisFormId,
4661 - lookupBlockRows = document.getElementById( 'frm_watch_lookup_block_' + id ).children;
4662 - jQuery.ajax({
4663 - type: 'POST',
4664 - url: ajaxurl,
4665 - data: {
4666 - action: 'frm_add_watch_lookup_row',
4667 - form_id: formId,
4668 - field_id: id,
4669 - row_key: getNewRowId( lookupBlockRows, 'frm_watch_lookup_' + id + '_' ),
4670 - nonce: frmGlobal.nonce
4671 - },
4672 - success: function( newRow ) {
4673 - var watchRowBlock = jQuery( document.getElementById( 'frm_watch_lookup_block_' + id ) );
4674 - watchRowBlock.append( newRow );
4675 - watchRowBlock.fadeIn( 'slow' );
4676 - }
4677 - });
4678 - return false;
4679 - }
4680 -
4681 - function resetOptionTextDetails() {
4682 - jQuery( '.frm-single-settings ul input[type="text"][name^="field_options[options_"]' ).filter( '[data-value-on-load]' ).removeAttr( 'data-value-on-load' );
4683 - jQuery( 'input[type="hidden"][name^=optionmap]' ).remove();
4684 - }
4685 -
4686 - function optionTextAlreadyExists( input ) {
4687 - var fieldId = jQuery( input ).closest( '.frm-single-settings' ).attr( 'data-fid' ),
4688 - optionInputs = jQuery( input ).closest( 'ul' ).get( 0 ).querySelectorAll( '.field_' + fieldId + '_option' ),
4689 - index,
4690 - optionInput;
4691 -
4692 - for ( index in optionInputs ) {
4693 - optionInput = optionInputs[ index ];
4694 - if ( optionInput.id !== input.id && optionInput.value === input.value && optionInput.getAttribute( 'data-duplicate' ) !== 'true' ) {
4695 - return true;
4696 - }
4697 - }
4698 -
4699 - return false;
4700 - }
4701 -
4702 - function onOptionTextFocus() {
4703 - var input,
4704 - fieldId;
4705 -
4706 - if ( this.getAttribute( 'data-value-on-load' ) === null ) {
4707 - this.setAttribute( 'data-value-on-load', this.value );
4708 -
4709 - fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' );
4710 - input = document.createElement( 'input' );
4711 - input.value = this.value;
4712 - input.setAttribute( 'type', 'hidden' );
4713 - input.setAttribute( 'name', 'optionmap[' + fieldId + '][' + this.value + ']' );
4714 - this.parentNode.appendChild( input );
4715 -
4716 - if ( typeof optionMap[ fieldId ] === 'undefined' ) {
4717 - optionMap[ fieldId ] = {};
4718 - }
4719 -
4720 - optionMap[ fieldId ][ this.value ] = input;
4721 - }
4722 -
4723 - if ( this.getAttribute( 'data-duplicate' ) === 'true' ) {
4724 - this.removeAttribute( 'data-duplicate' );
4725 -
4726 - // we want to use original value if actually still a duplicate
4727 - if ( optionTextAlreadyExists( this ) ) {
4728 - this.setAttribute( 'data-value-on-focus', this.getAttribute( 'data-value-on-load' ) );
4729 - return;
4730 - }
4731 - }
4732 -
4733 - if ( '' !== this.value || frm_admin_js.new_option !== this.getAttribute( 'data-value-on-focus' ) ) { // eslint-disable-line camelcase
4734 - this.setAttribute( 'data-value-on-focus', this.value );
4735 - }
4736 - }
4737 -
4738 - function onOptionTextBlur() {
4739 - var originalValue,
4740 - oldValue = this.getAttribute( 'data-value-on-focus' ),
4741 - newValue = this.value,
4742 - fieldId,
4743 - fieldIndex,
4744 - logicId,
4745 - row,
4746 - rowLength,
4747 - rowIndex,
4748 - valueSelect,
4749 - opts,
4750 - fieldIds,
4751 - settingId,
4752 - setting,
4753 - optionMatches,
4754 - option;
4755 -
4756 - if ( oldValue === newValue ) {
4757 - return;
4758 - }
4759 -
4760 - fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' );
4761 - originalValue = this.getAttribute( 'data-value-on-load' );
4762 -
4763 - // check if the newValue is already mapped to another option
4764 - // if it is, mark as duplicate and return
4765 - if ( optionTextAlreadyExists( this ) ) {
4766 - this.setAttribute( 'data-duplicate', 'true' );
4767 -
4768 - if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) {
4769 - // unmap any other change that may have happened before instead of changing it to something unused
4770 - optionMap[ fieldId ][ originalValue ].value = originalValue;
4771 - }
4772 -
4773 - return;
4774 - }
4775 -
4776 - if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) {
4777 - optionMap[ fieldId ][ originalValue ].value = newValue;
4778 - }
4779 -
4780 - fieldIds = [];
4781 - rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' );
4782 - rowLength = rows.length;
4783 - for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) {
4784 - row = rows[ rowIndex ];
4785 - opts = row.querySelector( '.frm_logic_field_opts' );
4786 -
4787 - if ( opts.value !== fieldId ) {
4788 - continue;
4789 - }
4790 -
4791 - logicId = row.id.split( '_' )[ 2 ];
4792 - valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' );
4793 -
4794 - if ( '' === oldValue ) {
4795 - optionMatches = [];
4796 - } else {
4797 - optionMatches = valueSelect.querySelectorAll( 'option[value="' + oldValue + '"]' );
4798 - }
4799 -
4800 - if ( ! optionMatches.length ) {
4801 - optionMatches = valueSelect.querySelectorAll( 'option[value="' + newValue + '"]' );
4802 -
4803 - if ( ! optionMatches.length ) {
4804 - option = document.createElement( 'option' );
4805 - valueSelect.appendChild( option );
4806 - }
4807 - }
4808 -
4809 - if ( optionMatches.length ) {
4810 - option = optionMatches[ optionMatches.length - 1 ];
4811 - }
4812 -
4813 - option.setAttribute( 'value', newValue );
4814 - option.textContent = newValue;
4815 -
4816 - if ( fieldIds.indexOf( logicId ) === -1 ) {
4817 - fieldIds.push( logicId );
4818 - }
4819 - }
4820 -
4821 - for ( fieldIndex in fieldIds ) {
4822 - settingId = fieldIds[ fieldIndex ];
4823 - setting = document.getElementById( 'frm-single-settings-' + settingId );
4824 - moveFieldSettings( setting );
4825 - }
4826 - }
4827 -
4828 - function updateGetValueFieldSelection() {
4829 - /*jshint validthis:true */
4830 - var fieldID = this.id.replace( 'get_values_form_', '' );
4831 - var fieldSelect = document.getElementById( 'get_values_field_' + fieldID );
4832 - var fieldType = this.getAttribute( 'data-fieldtype' );
4833 -
4834 - if ( this.value === '' ) {
4835 - fieldSelect.options.length = 1;
4836 - } else {
4837 - var formID = this.value;
4838 - jQuery.ajax({
4839 - type: 'POST', url: ajaxurl,
4840 - data: {
4841 - action: 'frm_get_options_for_get_values_field',
4842 - form_id: formID,
4843 - field_type: fieldType,
4844 - nonce: frmGlobal.nonce
4845 - },
4846 - success: function( fields ) {
4847 - fieldSelect.innerHTML = fields;
4848 - }
4849 - });
4850 - }
4851 - }
4852 -
4853 - // Clear the Watch Fields option when Lookup field switches to "Text" option
4854 - function maybeClearWatchFields() {
4855 - /*jshint validthis:true */
4856 - var link, lookupBlock,
4857 - fieldID = this.name.replace( 'field_options[data_type_', '' ).replace( ']', '' );
4858 -
4859 - link = document.getElementById( 'frm_add_watch_lookup_link_' + fieldID ).parentNode;
4860 -
4861 - if ( this.value === 'text' ) {
4862 - lookupBlock = document.getElementById( 'frm_watch_lookup_block_' + fieldID );
4863 - if ( lookupBlock !== null ) {
4864 - // Clear and hide the Watch Fields option
4865 - lookupBlock.innerHTML = '';
4866 - link.classList.add( 'frm_hidden' );
4867 -
4868 - // Hide the Watch Fields row
4869 - link.previousElementSibling.style.display = 'none';
4870 - link.previousElementSibling.previousElementSibling.style.display = 'none';
4871 - link.previousElementSibling.previousElementSibling.previousElementSibling.style.display = 'none';
4872 - }
4873 - } else {
4874 - // Show the Watch Fields option
4875 - link.classList.remove( 'frm_hidden' );
4876 - }
4877 -
4878 - toggleMultiSelect( fieldID, this.value );
4879 - }
4880 -
4881 - // Number the pages and hide/show the first page as needed.
4882 - function renumberPageBreaks() {
4883 - var i, containerClass,
4884 - pages = document.getElementsByClassName( 'frm-page-num' );
4885 -
4886 - if ( pages.length > 1 ) {
4887 - document.getElementById( 'frm-fake-page' ).style.display = 'block';
4888 - for ( i = 0; i < pages.length; i++ ) {
4889 - containerClass = pages[i].parentNode.parentNode.parentNode.classList;
4890 - if ( i === 1 ) {
4891 - // Hide previous button on page 1
4892 - containerClass.add( 'frm-first-page' );
4893 - } else {
4894 - containerClass.remove( 'frm-first-page' );
4895 - }
4896 - pages[i].textContent = ( i + 1 );
4897 - }
4898 - } else {
4899 - document.getElementById( 'frm-fake-page' ).style.display = 'none';
4900 - }
4901 - }
4902 -
4903 - // The fake field works differently than real fields.
4904 - function maybeCollapsePage() {
4905 - /*jshint validthis:true */
4906 - var field = jQuery( this ).closest( '.frm_field_box[data-ftype=break]' );
4907 - if ( field.length ) {
4908 - toggleCollapsePage( field );
4909 - } else {
4910 - toggleCollapseFakePage();
4911 - }
4912 - }
4913 -
4914 - // Find all fields in a page and hide/show them
4915 - function toggleCollapsePage( field ) {
4916 - var toCollapse = getAllFieldsForPage( field.get( 0 ).parentNode.closest( 'li.frm_field_box' ).nextElementSibling );
4917 - togglePage( field, toCollapse );
4918 - }
4919 -
4920 - function toggleCollapseFakePage() {
4921 - var topLevel = document.getElementById( 'frm-fake-page' ),
4922 - firstField = document.getElementById( 'frm-show-fields' ).firstElementChild,
4923 - toCollapse = getAllFieldsForPage( firstField );
4924 -
4925 - if ( firstField.getAttribute( 'data-ftype' ) === 'break' ) {
4926 - // Don't collapse if the first field is a page break.
4927 - return;
4928 - }
4929 -
4930 - togglePage( jQuery( topLevel ), toCollapse );
4931 - }
4932 -
4933 - function getAllFieldsForPage( firstWrapper ) {
4934 - var $fieldsForPage, currentWrapper;
4935 -
4936 - $fieldsForPage = jQuery();
4937 -
4938 - if ( null === firstWrapper ) {
4939 - return $fieldsForPage;
4940 - }
4941 -
4942 - currentWrapper = firstWrapper;
4943 -
4944 - do {
4945 - if ( null !== currentWrapper.querySelector( '.edit_field_type_break' ) ) {
4946 - break;
4947 - }
4948 - $fieldsForPage = $fieldsForPage.add( jQuery( currentWrapper ) );
4949 - currentWrapper = currentWrapper.nextElementSibling;
4950 - } while ( null !== currentWrapper );
4951 -
4952 - return $fieldsForPage;
4953 - }
4954 -
4955 - function togglePage( field, toCollapse ) {
4956 - var i,
4957 - fieldCount = toCollapse.length,
4958 - slide = Math.min( fieldCount, 3 );
4959 -
4960 - if ( field.hasClass( 'frm-page-collapsed' ) ) {
4961 - field.removeClass( 'frm-page-collapsed' );
4962 - toCollapse.removeClass( 'frm-is-collapsed' );
4963 - for ( i = 0; i < slide; i++ ) {
4964 - if ( i === slide - 1 ) {
4965 - jQuery( toCollapse[ i ]).slideDown( 150, function() {
4966 - toCollapse.show();
4967 - });
4968 - } else {
4969 - jQuery( toCollapse[ i ]).slideDown( 150 );
4970 - }
4971 - }
4972 - } else {
4973 - field.addClass( 'frm-page-collapsed' );
4974 - toCollapse.addClass( 'frm-is-collapsed' );
4975 - for ( i = 0; i < slide; i++ ) {
4976 - if ( i === slide - 1 ) {
4977 - jQuery( toCollapse[ i ]).slideUp( 150, function() {
4978 - toCollapse.css( 'cssText', 'display:none !important;' );
4979 - });
4980 - } else {
4981 - jQuery( toCollapse[ i ]).slideUp( 150 );
4982 - }
4983 - }
4984 - }
4985 - }
4986 -
4987 - function maybeCollapseSection() {
4988 - /*jshint validthis:true */
4989 - var parentCont = this.parentNode.parentNode.parentNode.parentNode;
4990 -
4991 - parentCont.classList.toggle( 'frm-section-collapsed' );
4992 - }
4993 -
4994 - function maybeCollapseSettings() {
4995 - /*jshint validthis:true */
4996 - this.classList.toggle( 'frm-collapsed' );
4997 - }
4998 -
4999 - function clickLabel() {
5000 - if ( ! this.id ) {
5001 - return;
5002 - }
5003 -
5004 - /*jshint validthis:true */
5005 - var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0],
5006 - fieldId = this.id.replace( 'field_label_', '' ),
5007 - fieldType = document.getElementById( 'field_options_type_' + fieldId ),
5008 - fieldTypeName = fieldType.value;
5009 -
5010 - if ( typeof setting !== 'undefined' ) {
5011 - if ( fieldType.tagName === 'SELECT' ) {
5012 - fieldTypeName = fieldType.options[ fieldType.selectedIndex ].text.toLowerCase();
5013 - } else {
5014 - fieldTypeName = fieldTypeName.replace( '_', ' ' );
5015 - }
5016 -
5017 - fieldTypeName = normalizeFieldName( fieldTypeName );
5018 -
5019 - setTimeout( function() {
5020 - if ( setting.value.toLowerCase() === fieldTypeName ) {
5021 - setting.select();
5022 - } else {
5023 - setting.focus();
5024 - }
5025 - }, 50 );
5026 - }
5027 - }
5028 -
5029 - function clickDescription() {
5030 - /*jshint validthis:true */
5031 - var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0];
5032 - if ( typeof setting !== 'undefined' ) {
5033 - setTimeout( function() {
5034 - setting.focus();
5035 - autoExpandSettings( setting );
5036 - }, 50 );
5037 - }
5038 - }
5039 -
5040 - function autoExpandSettings( setting ) {
5041 - var inSection = setting.closest( '.frm-collapse-me' );
5042 - if ( inSection !== null ) {
5043 - inSection.previousElementSibling.classList.remove( 'frm-collapsed' );
5044 - }
5045 - }
5046 -
5047 - function normalizeFieldName( fieldTypeName ) {
5048 - if ( fieldTypeName === 'divider' ) {
5049 - fieldTypeName = 'section';
5050 - } else if ( fieldTypeName === 'range' ) {
5051 - fieldTypeName = 'slider';
5052 - } else if ( fieldTypeName === 'data' ) {
5053 - fieldTypeName = 'dynamic';
5054 - } else if ( fieldTypeName === 'form' ) {
5055 - fieldTypeName = 'embed form';
5056 - }
5057 - return fieldTypeName;
5058 - }
5059 -
5060 - function clickVis( e ) {
5061 - /*jshint validthis:true */
5062 - var currentClass, originalList;
5063 -
5064 - currentClass = e.target.classList;
5065 -
5066 - if ( currentClass.contains( 'frm-collapse-page' ) || currentClass.contains( 'frm-sub-label' ) || e.target.closest( '.dropdown' ) !== null ) {
5067 - return;
5068 - }
5069 -
5070 - if ( this.closest( '.start_divider' ) !== null ) {
5071 - e.stopPropagation();
5072 - }
5073 -
5074 - if ( this.classList.contains( 'edit_field_type_divider' ) ) {
5075 - originalList = e.originalEvent.target.closest( 'ul.frm_sorting' );
5076 - if ( null !== originalList ) {
5077 - // prevent section click if clicking a field group within a section.
5078 - if ( originalList.classList.contains( 'edit_field_type_divider' ) || originalList.parentNode.parentNode.classList.contains( 'start_divider' ) ) {
5079 - return;
5080 - }
5081 - }
5082 - }
5083 -
5084 - clickAction( this );
5085 - }
5086 -
5087 - /**
5088 - * Open Advanced settings on double click.
5089 - */
5090 - function openAdvanced() {
5091 - var fieldId = this.getAttribute( 'data-fid' );
5092 - autoExpandSettings( document.getElementById( 'field_options_field_key_' + fieldId ) );
5093 - }
5094 -
5095 - function toggleRepeatButtons() {
5096 - /*jshint validthis:true */
5097 - var $thisField = jQuery( this ).closest( '.frm_field_box' );
5098 - $thisField.find( '.repeat_icon_links' ).removeClass( 'repeat_format repeat_formatboth repeat_formattext' ).addClass( 'repeat_format' + this.value );
5099 - if ( this.value === 'text' || this.value === 'both' ) {
5100 - $thisField.find( '.frm_repeat_text' ).show();
5101 - $thisField.find( '.repeat_icon_links a' ).addClass( 'frm_button' );
5102 - } else {
5103 - $thisField.find( '.frm_repeat_text' ).hide();
5104 - $thisField.find( '.repeat_icon_links a' ).removeClass( 'frm_button' );
5105 - }
5106 - }
5107 -
5108 - function checkRepeatLimit() {
5109 - /*jshint validthis:true */
5110 - var val = this.value;
5111 - if ( val !== '' && ( val < 2 || val > 200 ) ) {
5112 - infoModal( frm_admin_js.repeat_limit_min ); // eslint-disable-line camelcase
5113 - this.value = '';
5114 - }
5115 - }
5116 -
5117 - function checkCheckboxSelectionsLimit() {
5118 - /*jshint validthis:true */
5119 - var val = this.value;
5120 - if ( val !== '' && ( val < 1 || val > 200 ) ) {
5121 - infoModal( frm_admin_js.checkbox_limit ); // eslint-disable-line camelcase
5122 - this.value = '';
5123 - }
5124 - }
5125 -
5126 - function updateRepeatText( obj, addRemove ) {
5127 - var $thisField = jQuery( obj ).closest( '.frm_field_box' );
5128 - $thisField.find( '.frm_' + addRemove + '_form_row .frm_repeat_label' ).text( obj.value );
5129 - }
5130 -
5131 - function fieldsInSection( id ) {
5132 - var children = [];
5133 - jQuery( document.getElementById( 'frm_field_id_' + id ) ).find( 'li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)' ).each( function() {
5134 - children.push( jQuery( this ).data( 'fid' ) );
5135 - });
5136 - return children;
5137 - }
5138 -
5139 - function toggleFormTax() {
5140 - /*jshint validthis:true */
5141 - var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
5142 - var val = this.value;
5143 - var $showFields = document.getElementById( 'frm_show_selected_fields_' + id );
5144 - var $showForms = document.getElementById( 'frm_show_selected_forms_' + id );
5145 -
5146 - jQuery( $showForms ).find( 'select' ).val( '' );
5147 - if ( val === 'form' ) {
5148 - $showForms.style.display = 'inline';
5149 - empty( $showFields );
5150 - } else {
5151 - $showFields.style.display = 'none';
5152 - $showForms.style.display = 'none';
5153 - getTaxOrFieldSelection( val, id );
5154 - }
5155 -
5156 - }
5157 -
5158 - function resetOptOnChange() {
5159 - /*jshint validthis:true */
5160 - var field, thisOpt;
5161 -
5162 - field = getFieldKeyFromOpt( this );
5163 - if ( ! field ) {
5164 - return;
5165 - }
5166 -
5167 - thisOpt = jQuery( this ).closest( '.frm_single_option' );
5168 -
5169 - resetSingleOpt( field.fieldId, field.fieldKey, thisOpt );
5170 - }
5171 -
5172 - function getFieldKeyFromOpt( object ) {
5173 - var allOpts, fieldId, fieldKey;
5174 -
5175 - allOpts = jQuery( object ).closest( '.frm_sortable_field_opts' );
5176 - if ( ! allOpts.length ) {
5177 - return false;
5178 - }
5179 -
5180 - fieldId = allOpts.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_opts', '' );
5181 - fieldKey = allOpts.data( 'key' );
5182 -
5183 - return {
5184 - fieldId: fieldId,
5185 - fieldKey: fieldKey
5186 - };
5187 - }
5188 -
5189 - function resetSingleOpt( fieldId, fieldKey, thisOpt ) {
5190 - var saved, text, defaultVal, previewInput, labelForDisplay, optContainer,
5191 - optKey = thisOpt.data( 'optkey' ),
5192 - separateValues = usingSeparateValues( fieldId ),
5193 - single = jQuery( 'label[for="field_' + fieldKey + '-' + optKey + '"]' ),
5194 - baseName = 'field_options[options_' + fieldId + '][' + optKey + ']',
5195 - label = jQuery( 'input[name="' + baseName + '[label]"]' );
5196 -
5197 - if ( single.length < 1 ) {
5198 - resetDisplayedOpts( fieldId );
5199 -
5200 - // Set the default value.
5201 - defaultVal = thisOpt.find( 'input[name^="default_value_"]' );
5202 - if ( defaultVal.is( ':checked' ) && label.length > 0 ) {
5203 - jQuery( 'select[name^="item_meta[' + fieldId + ']"]' ).val( label.val() );
5204 - }
5205 - return;
5206 - }
5207 -
5208 - previewInput = single.children( 'input' );
5209 -
5210 - if ( label.length < 1 ) {
5211 - // Check for other label.
5212 - label = jQuery( 'input[name="' + baseName + '"]' );
5213 - saved = label.val();
5214 - } else if ( separateValues ) {
5215 - saved = jQuery( 'input[name="' + baseName + '[value]"]' ).val();
5216 - } else {
5217 - saved = label.val();
5218 - }
5219 -
5220 - if ( label.length < 1 ) {
5221 - return;
5222 - }
5223 -
5224 - // Set the displayed value.
5225 - text = single[0].childNodes;
5226 -
5227 - if ( imagesAsOptions( fieldId ) ) {
5228 - labelForDisplay = getImageDisplayValue( thisOpt, fieldId, label );
5229 - optContainer = single.find( '.frm_image_option_container' );
5230 -
5231 - if ( optContainer.length > 0 ) {
5232 - optContainer.replaceWith( labelForDisplay );
5233 - } else {
5234 - text[ text.length - 1 ].nodeValue = '';
5235 - single.append( labelForDisplay );
5236 - }
5237 - } else {
5238 - let firstInputIndex = false;
5239 - text.forEach( ( node, index ) => {
5240 - if ( firstInputIndex === false ) {
5241 - if ( node.tagName === 'INPUT' ) {
5242 - firstInputIndex = index;
5243 - }
5244 - } else {
5245 - if ( index === firstInputIndex + 1 ) {
5246 - let nodeValue = '';
5247 -
5248 - if ( buttonsAsOptions( fieldId ) ) {
5249 - nodeValue = div({ className: 'frm_label_button_container', text: ' ' + label.val() });
5250 - single[0].replaceChild( nodeValue, node );
5251 - } else {
5252 - node.nodeValue = ' ' + label.val();
5253 - }
5254 - } else {
5255 - single[0].removeChild( node );
5256 - }
5257 - }
5258 - });
5259 - }
5260 -
5261 - // Set saved value.
5262 - previewInput.val( saved );
5263 -
5264 - // Set the default value.
5265 - defaultVal = thisOpt.find( 'input[name^="default_value_"]' );
5266 - previewInput.prop( 'checked', defaultVal.is( ':checked' ) ? true : false );
5267 - }
5268 -
5269 - function buttonsAsOptions( fieldId ) {
5270 - const fields = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' );
5271 - const result = Array.from( fields ).find( field => field.checked && ( 'buttons' === field.value ) );
5272 -
5273 - return typeof result !== 'undefined';
5274 - }
5275 -
5276 - /**
5277 - * Set the displayed value for an image option.
5278 - */
5279 - function getImageDisplayValue( thisOpt, fieldId, label ) {
5280 - var image, imageUrl, showLabelWithImage, fieldType;
5281 -
5282 - image = thisOpt.find( 'img' );
5283 - if ( image ) {
5284 - imageUrl = image.attr( 'src' );
5285 - }
5286 -
5287 - showLabelWithImage = showingLabelWithImage( fieldId );
5288 - fieldType = radioOrCheckbox( fieldId );
5289 - return getImageLabel( label.val(), showLabelWithImage, imageUrl, fieldType );
5290 - }
5291 -
5292 - function getImageOptionSize( fieldId ) {
5293 - var val,
5294 - field = document.getElementById( 'field_options_image_size_' + fieldId ),
5295 - size = '';
5296 -
5297 - if ( field !== null ) {
5298 - val = field.value;
5299 - if ( val !== '' ) {
5300 - size = val;
5301 - }
5302 - }
5303 -
5304 - return size;
5305 - }
5306 -
5307 - function resetDisplayedOpts( fieldId ) {
5308 - var i, opts, type, placeholder, fieldInfo,
5309 - input = jQuery( '[name^="item_meta[' + fieldId + ']"]' );
5310 -
5311 - if ( input.length < 1 ) {
5312 - return;
5313 - }
5314 -
5315 - if ( input.is( 'select' ) ) {
5316 - placeholder = document.getElementById( 'frm_placeholder_' + fieldId );
5317 - if ( placeholder !== null && placeholder.value === '' ) {
5318 - fillDropdownOpts( input[0], { sourceID: fieldId });
5319 - } else {
5320 - fillDropdownOpts( input[0], {
5321 - sourceID: fieldId,
5322 - placeholder: placeholder.value
5323 - });
5324 - }
5325 - } else {
5326 - opts = getMultipleOpts( fieldId );
5327 - type = input.attr( 'type' );
5328 - jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ).html( '' );
5329 - fieldInfo = getFieldKeyFromOpt( jQuery( '#frm_delete_field_' + fieldId + '-000_container' ) );
5330 -
5331 - var container = jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ),
5332 - hasImageOptions = imagesAsOptions( fieldId ),
5333 - imageSize = hasImageOptions ? getImageOptionSize( fieldId ) : '',
5334 - imageOptionClass = hasImageOptions ? ( 'frm_image_option frm_image_' + imageSize + ' ' ) : '',
5335 - isProduct = isProductField( fieldId );
5336 -
5337 - for ( i = 0; i < opts.length; i++ ) {
5338 - container.append( addRadioCheckboxOpt( type, opts[ i ], fieldId, fieldInfo.fieldKey, isProduct, imageOptionClass ) );
5339 - }
5340 - }
5341 -
5342 - adjustConditionalLogicOptionOrders( fieldId );
5343 - }
5344 -
5345 - function adjustConditionalLogicOptionOrders( fieldId, type ) {
5346 - var row, opts, logicId, valueSelect, optionLength, optionIndex, expectedOption, optionMatch, fieldOptions,
5347 - rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ),
5348 - rowLength = rows.length;
5349 -
5350 - fieldOptions = wp.hooks.applyFilters( 'frm_conditional_logic_field_options', getFieldOptions( fieldId ), { type, fieldId });
5351 - optionLength = fieldOptions.length;
5352 -
5353 - for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) {
5354 - row = rows[ rowIndex ];
5355 - opts = row.querySelector( '.frm_logic_field_opts' );
5356 -
5357 - if ( opts.value != fieldId ) {
5358 - continue;
5359 - }
5360 -
5361 - logicId = row.id.split( '_' )[ 2 ];
5362 - valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' );
5363 -
5364 - for ( optionIndex = optionLength - 1; optionIndex >= 0; optionIndex-- ) {
5365 - expectedOption = fieldOptions[ optionIndex ];
5366 - optionMatch = valueSelect.querySelector( 'option[value="' + expectedOption + '"]' );
5367 -
5368 - if ( optionMatch === null ) {
5369 - optionMatch = document.createElement( 'option' );
5370 - optionMatch.setAttribute( 'value', expectedOption );
5371 - optionMatch.textContent = expectedOption;
5372 - }
5373 -
5374 - valueSelect.prepend( optionMatch );
5375 - }
5376 -
5377 - optionMatch = valueSelect.querySelector( 'option[value=""]' );
5378 - if ( optionMatch !== null ) {
5379 - valueSelect.prepend( optionMatch );
5380 - }
5381 - }
5382 - }
5383 -
5384 - function getFieldOptions( fieldId ) {
5385 - var index, input, li, listItems, optsContainer, length,
5386 - options = [];
5387 - optsContainer = document.getElementById( 'frm_field_' + fieldId + '_opts' );
5388 -
5389 - if ( ! optsContainer ) {
5390 - return options;
5391 - }
5392 - listItems = optsContainer.querySelectorAll( '.frm_single_option' );
5393 - length = listItems.length;
5394 -
5395 - for ( index = 0; index < length; index++ ) {
5396 - li = listItems[ index ];
5397 -
5398 - if ( li.classList.contains( 'frm_hidden' ) ) {
5399 - continue;
5400 - }
5401 -
5402 - input = li.querySelector( '.field_' + fieldId + '_option' );
5403 - options.push( input.value );
5404 - }
5405 - return options;
5406 - }
5407 -
5408 - function addRadioCheckboxOpt( type, opt, fieldId, fieldKey, isProduct, classes ) {
5409 - var other, single,
5410 - isOther = opt.key.indexOf( 'other' ) !== -1,
5411 - id = 'field_' + fieldKey + '-' + opt.key,
5412 - inputType = type === 'scale' ? 'radio' : type;
5413 -
5414 - other = '<input type="text" id="field_' + fieldKey + '-' + opt.key + '-otext" class="frm_other_input frm_pos_none" name="item_meta[other][' + fieldId + '][' + opt.key + ']" value="" />';
5415 -
5416 - single = '<div class="frm_' + type + ' ' + type + ' ' + classes + '" id="frm_' + type + '_' + fieldId + '-' + opt.key + '"><label for="' + id +
5417 - '"><input type="' + inputType +
5418 - '" name="item_meta[' + fieldId + ']' + ( type === 'checkbox' ? '[]' : '' ) +
5419 - '" value="' + purifyHtml( opt.saved ) + '" id="' + id + '"' + ( isProduct ? ' data-price="' + opt.price + '"' : '' ) + ( opt.checked ? ' checked="checked"' : '' ) + '> ' + purifyHtml( opt.label ) + '</label>' +
5420 - ( isOther ? other : '' ) +
5421 - '</div>';
5422 -
5423 - return single;
5424 - }
5425 -
5426 - function fillDropdownOpts( field, atts ) {
5427 - if ( field === null ) {
5428 - return;
5429 - }
5430 - var sourceID = atts.sourceID,
5431 - placeholder = atts.placeholder,
5432 - isProduct = isProductField( sourceID ),
5433 - showOther = atts.other;
5434 -
5435 - removeDropdownOpts( field );
5436 - var opts = getMultipleOpts( sourceID ),
5437 - hasPlaceholder = ( typeof placeholder !== 'undefined' );
5438 -
5439 - for ( var i = 0; i < opts.length; i++ ) {
5440 - var label = opts[ i ].label,
5441 - isOther = opts[ i ].key.indexOf( 'other' ) !== -1;
5442 -
5443 - if ( hasPlaceholder && label !== '' ) {
5444 - addBlankSelectOption( field, placeholder );
5445 - } else if ( hasPlaceholder ) {
5446 - label = placeholder;
5447 - }
5448 - hasPlaceholder = false;
5449 -
5450 - if ( ! isOther || showOther ) {
5451 - var opt = document.createElement( 'option' );
5452 - opt.value = opts[ i ].saved;
5453 - opt.innerHTML = purifyHtml( label );
5454 -
5455 - if ( isProduct ) {
5456 - opt.setAttribute( 'data-price', opts[ i ].price );
5457 - }
5458 -
5459 - field.appendChild( opt );
5460 - }
5461 - }
5462 - }
5463 -
5464 - function addBlankSelectOption( field, placeholder ) {
5465 - var opt = document.createElement( 'option' ),
5466 - firstChild = field.firstChild;
5467 -
5468 - opt.value = '';
5469 - opt.innerHTML = placeholder;
5470 - if ( firstChild !== null ) {
5471 - field.insertBefore( opt, firstChild );
5472 - field.selectedIndex = 0;
5473 - } else {
5474 - field.appendChild( opt );
5475 - }
5476 - }
5477 -
5478 - function getMultipleOpts( fieldId ) {
5479 - let i, saved, labelName, label, key, optObj,
5480 - fieldType,
5481 - checked = false,
5482 - opts = [],
5483 - imageUrl = '';
5484 -
5485 - const optVals = jQuery( 'input[name^="field_options[options_' + fieldId + ']"]' );
5486 - const isProduct = isProductField( fieldId );
5487 - const showLabelWithImage = showingLabelWithImage( fieldId );
5488 - const hasImageOptions = imagesAsOptions( fieldId );
5489 - const separateValues = usingSeparateValues( fieldId );
5490 -
5491 - for ( i = 0; i < optVals.length; i++ ) {
5492 - if ( optVals[ i ].name.indexOf( '[000]' ) > 0 || optVals[ i ].name.indexOf( '[value]' ) > 0 || optVals[ i ].name.indexOf( '[image]' ) > 0 || optVals[ i ].name.indexOf( '[price]' ) > 0 ) {
5493 - continue;
5494 - }
5495 -
5496 - saved = optVals[ i ].value;
5497 - label = saved;
5498 - key = optVals[ i ].name.replace( 'field_options[options_' + fieldId + '][', '' ).replace( '[label]', '' ).replace( ']', '' );
5499 -
5500 - if ( separateValues ) {
5501 - labelName = optVals[ i ].name.replace( '[label]', '[value]' );
5502 - saved = jQuery( 'input[name="' + labelName + '"]' ).val();
5503 - }
5504 -
5505 - if ( hasImageOptions ) {
5506 - imageUrl = getImageUrlFromInput( optVals[i]);
5507 - fieldType = radioOrCheckbox( fieldId );
5508 - label = getImageLabel( label, showLabelWithImage, imageUrl, fieldType );
5509 - }
5510 -
5511 - /**
5512 - * @since 5.0.04
5513 - */
5514 - label = frmAdminBuild.hooks.applyFilters( 'frm_choice_field_label', label, fieldId, optVals[ i ], hasImageOptions );
5515 -
5516 - checked = getChecked( optVals[ i ].id );
5517 -
5518 - optObj = {
5519 - saved: saved,
5520 - label: label,
5521 - checked: checked,
5522 - key: key
5523 - };
5524 -
5525 - if ( isProduct ) {
5526 - labelName = optVals[ i ].name.replace( '[label]', '[price]' );
5527 - optObj.price = jQuery( 'input[name="' + labelName + '"]' ).val();
5528 - }
5529 -
5530 - opts.push( optObj );
5531 - }
5532 -
5533 - return opts;
5534 - }
5535 -
5536 - function radioOrCheckbox( fieldId ) {
5537 - var settings = document.getElementById( 'frm-single-settings-' + fieldId );
5538 - if ( settings === null ) {
5539 - return 'radio';
5540 - }
5541 -
5542 - return settings.classList.contains( 'frm-type-checkbox' ) ? 'checkbox' : 'radio';
5543 - }
5544 -
5545 - function getImageUrlFromInput( optVal ) {
5546 - var img,
5547 - wrapper = jQuery( optVal ).siblings( '.frm_image_preview_wrapper' );
5548 -
5549 - if ( ! wrapper.length ) {
5550 - return '';
5551 - }
5552 -
5553 - img = wrapper.find( 'img' );
5554 - if ( ! img.length ) {
5555 - return '';
5556 - }
5557 -
5558 - return img.attr( 'src' );
5559 - }
5560 -
5561 - function purifyHtml( html ) {
5562 - if ( html instanceof Element || html instanceof Document ) {
5563 - html = html.outerHTML;
5564 - }
5565 -
5566 - const clean = jQuery.parseHTML( html ).reduce(
5567 - ( total, currentNode ) => {
5568 - const cleanNode = frmDom.cleanNode( currentNode );
5569 -
5570 - if ( '#text' === cleanNode.nodeName ) {
5571 - return total += cleanNode.textContent;
5572 - }
5573 -
5574 - return total + cleanNode.outerHTML;
5575 - },
5576 - ''
5577 - );
5578 -
5579 - return clean;
5580 - }
5581 -
5582 - function getImageLabel( label, showLabelWithImage, imageUrl, fieldType ) {
5583 - var imageLabelClass,
5584 - originalLabel = label,
5585 - shape = fieldType === 'checkbox' ? 'square' : 'circle',
5586 - labelImage,
5587 - labelNode,
5588 - imageLabel;
5589 -
5590 - originalLabel = purifyHtml( originalLabel );
5591 -
5592 - if ( imageUrl ) {
5593 - labelImage = img({ src: imageUrl, alt: originalLabel });
5594 - } else {
5595 - labelImage = div({ className: 'frm_empty_url' });
5596 - labelImage.innerHTML = frm_admin_js.image_placeholder_icon; // eslint-disable-line camelcase
5597 - }
5598 -
5599 - imageLabelClass = showLabelWithImage ? ' frm_label_with_image' : '';
5600 -
5601 - imageLabel = tag( 'span', { className: 'frm_text_label_for_image_inner' });
5602 -
5603 - imageLabel.innerHTML = originalLabel;
5604 - labelNode = tag(
5605 - 'span',
5606 - {
5607 - className: 'frm_image_option_container' + imageLabelClass,
5608 - children: [
5609 - tag( 'div', { className: 'frm_selected_checkmark', child: svg({ href: '#frm_checkmark_' + shape + '_icon' }) }),
5610 - labelImage,
5611 - tag( 'span', { className: 'frm_text_label_for_image', child: imageLabel })
5612 - ]
5613 - }
5614 - );
5615 -
5616 - return labelNode;
5617 - }
5618 -
5619 - function getChecked( id ) {
5620 - field = jQuery( '#' + id );
5621 -
5622 - if ( field.length === 0 ) {
5623 - return false;
5624 - }
5625 -
5626 - checkbox = field.siblings( 'input[type=checkbox]' );
5627 -
5628 - return checkbox.length && checkbox.prop( 'checked' );
5629 - }
5630 -
5631 - function removeDropdownOpts( field ) {
5632 - var i;
5633 - if ( typeof field.options === 'undefined' ) {
5634 - return;
5635 - }
5636 -
5637 - for ( i = field.options.length - 1; i >= 0; i-- ) {
5638 - field.remove( i );
5639 - }
5640 - }
5641 -
5642 - /**
5643 - * Is the box checked to use separate values?
5644 - */
5645 - function usingSeparateValues( fieldId ) {
5646 - return isChecked( 'separate_value_' + fieldId );
5647 - }
5648 -
5649 - /**
5650 - * Is the box checked to use images as options?
5651 - */
5652 - function imagesAsOptions( fieldId ) {
5653 - var checked = false,
5654 - field = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' );
5655 -
5656 - for ( var i = 0; i < field.length; i++ ) {
5657 - if ( field[ i ].checked ) {
5658 - checked = '0' !== field[ i ].value;
5659 - }
5660 - }
5661 -
5662 - /**
5663 - * @since 5.0.04
5664 - */
5665 - return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_images_as_options', checked, fieldId );
5666 - }
5667 -
5668 - function showingLabelWithImage( fieldId ) {
5669 - const isShowing = ! isChecked( 'hide_image_text_' + fieldId );
5670 -
5671 - /**
5672 - * @since 5.0.04
5673 - */
5674 - return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_showing_label_with_image', isShowing, fieldId );
5675 - }
5676 -
5677 - function isChecked( id ) {
5678 - var field = document.getElementById( id );
5679 - if ( field === null ) {
5680 - return false;
5681 - } else {
5682 - return field.checked;
5683 - }
5684 - }
5685 -
5686 - function checkUniqueOpt( targetInput ) {
5687 - const settingsContainer = targetInput.closest( '.frm-single-settings' );
5688 - const fieldId = settingsContainer.getAttribute( 'data-fid' );
5689 - const areValuesSeparate = settingsContainer.querySelector( '[name="field_options[separate_value_' + fieldId + ']"]' ).checked;
5690 -
5691 - if ( areValuesSeparate && ! targetInput.name.endsWith( '[value]' ) ) {
5692 - return;
5693 - }
5694 -
5695 - const container = document.getElementById( 'frm_field_' + fieldId + '_opts' );
5696 - const conflicts = Array.from( container.querySelectorAll( 'input[type="text"]' ) ).filter(
5697 - input => input.id !== targetInput.id &&
5698 - areValuesSeparate === input.name.endsWith( '[value]' ) &&
5699 - input.value === targetInput.value
5700 - );
5701 -
5702 - if ( conflicts.length ) {
5703 - infoModal( __( 'Duplicate option value "%s" detected', 'formidable' ).replace( '%s', purifyHtml( targetInput.value ) ) );
5704 - }
5705 - }
5706 -
5707 - function setStarValues() {
5708 - /*jshint validthis:true */
5709 - var fieldID = this.id.replace( 'radio_maxnum_', '' );
5710 - var container = jQuery( '#field_' + fieldID + '_inner_container .frm-star-group' );
5711 - var fieldKey = document.getElementsByName( 'field_options[field_key_' + fieldID + ']' )[0].value;
5712 - container.html( '' );
5713 -
5714 - var min = 1;
5715 - var max = this.value;
5716 - if ( min > max ) {
5717 - max = min;
5718 - }
5719 -
5720 - for ( var i = min; i <= max; i++ ) {
5721 - container.append( '<input type="hidden" name="field_options[options_' + fieldID + '][' + i + ']" value="' + i + '"><input type="radio" name="item_meta[' + fieldID + ']" id="field_' + fieldKey + '-' + i + '" value="' + i + '" /><label for="field_' + fieldKey + '-' + i + '" class="star-rating"></label>' );
5722 - }
5723 - }
5724 -
5725 - function getFieldValues() {
5726 - /*jshint validthis:true */
5727 - var isTaxonomy,
5728 - val = this.value;
5729 -
5730 - if ( val ) {
5731 - var parentIDs = this.parentNode.id.replace( 'frm_logic_', '' ).split( '_' );
5732 - var fieldID = parentIDs[0];
5733 - var metaKey = parentIDs[1];
5734 - var valueField = document.getElementById( 'frm_field_id_' + val );
5735 - var valueFieldType = valueField.getAttribute( 'data-ftype' );
5736 - var fill = document.getElementById( 'frm_show_selected_values_' + fieldID + '_' + metaKey );
5737 - var optionName = 'field_options[hide_opt_' + fieldID + '][]';
5738 - var optionID = 'frm_field_logic_opt_' + fieldID;
5739 - var input = false;
5740 - var showSelect = ( valueFieldType === 'select' || valueFieldType === 'checkbox' || valueFieldType === 'radio' );
5741 - var showText = ( valueFieldType === 'text' || valueFieldType === 'email' || valueFieldType === 'phone' || valueFieldType === 'url' || valueFieldType === 'number' );
5742 -
5743 - if ( showSelect ) {
5744 - isTaxonomy = document.getElementById( 'frm_has_hidden_options_' + val );
5745 - if ( isTaxonomy !== null ) {
5746 - // get the category options with ajax
5747 - showSelect = false;
5748 - }
5749 - }
5750 -
5751 - if ( showSelect || showText ) {
5752 - fill.innerHTML = '';
5753 - if ( showSelect ) {
5754 - input = document.createElement( 'select' );
5755 - } else {
5756 - input = document.createElement( 'input' );
5757 - input.type = 'text';
5758 - }
5759 - input.name = optionName;
5760 - input.id = optionID + '_' + metaKey;
5761 - fill.appendChild( input );
5762 -
5763 - if ( showSelect ) {
5764 - var fillField = document.getElementById( input.id );
5765 - fillDropdownOpts( fillField, {
5766 - sourceID: val,
5767 - placeholder: '',
5768 - other: true
5769 - });
5770 - }
5771 - } else {
5772 - var thisType = this.getAttribute( 'data-type' );
5773 - frmGetFieldValues( val, fieldID, metaKey, thisType );
5774 - }
5775 - }
5776 - }
5777 -
5778 - function getFieldSelection() {
5779 - /*jshint validthis:true */
5780 - var formId = this.value;
5781 - if ( formId ) {
5782 - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
5783 - getTaxOrFieldSelection( formId, fieldId );
5784 - }
5785 - }
5786 -
5787 - function getTaxOrFieldSelection( formId, fieldId ) {
5788 - if ( formId ) {
5789 - jQuery.ajax({
5790 - type: 'POST',
5791 - url: ajaxurl,
5792 - data: {
5793 - action: 'frm_get_field_selection',
5794 - field_id: fieldId,
5795 - form_id: formId,
5796 - nonce: frmGlobal.nonce
5797 - },
5798 - success: function( msg ) {
5799 - jQuery( '#frm_show_selected_fields_' + fieldId ).html( msg ).show();
5800 - }
5801 - });
5802 - }
5803 - }
5804 -
5805 - function updateFieldOrder() {
5806 - var fields, fieldId, field, currentOrder, newOrder;
5807 - renumberPageBreaks();
5808 - jQuery( '#frm-show-fields' ).each( function( i ) {
5809 - fields = jQuery( 'li.frm_field_box', this );
5810 - for ( i = 0; i < fields.length; i++ ) {
5811 - fieldId = fields[ i ].getAttribute( 'data-fid' );
5812 - field = jQuery( 'input[name="field_options[field_order_' + fieldId + ']"]' );
5813 - currentOrder = field.val();
5814 - newOrder = i + 1;
5815 -
5816 - if ( currentOrder != newOrder ) {
5817 - field.val( newOrder );
5818 - singleField = document.getElementById( 'frm-single-settings-' + fieldId );
5819 -
5820 - moveFieldSettings( singleField );
5821 - fieldUpdated();
5822 - }
5823 - }
5824 - });
5825 - }
5826 -
5827 - function toggleSectionHolder() {
5828 - document.querySelectorAll( '.start_divider' ).forEach(
5829 - function( divider ) {
5830 - toggleOneSectionHolder( jQuery( divider ) );
5831 - }
5832 - );
5833 - }
5834 -
5835 - function toggleOneSectionHolder( $section ) {
5836 - var noSectionFields, $rows, length, index, sectionHasFields;
5837 -
5838 - if ( ! $section.length ) {
5839 - return;
5840 - }
5841 -
5842 - $rows = $section.find( 'ul.frm_sorting' );
5843 - sectionHasFields = false;
5844 - length = $rows.length;
5845 - for ( index = 0; index < length; ++index ) {
5846 - if ( 0 !== getFieldsInRow( jQuery( $rows.get( index ) ) ).length ) {
5847 - sectionHasFields = true;
5848 - break;
5849 - }
5850 - }
5851 -
5852 - noSectionFields = $section.parent().children( '.frm_no_section_fields' ).get( 0 );
5853 - noSectionFields.classList.toggle( 'frm_block', ! sectionHasFields );
5854 - }
5855 -
5856 - function handleShowPasswordLiveUpdate() {
5857 - frmDom.util.documentOn( 'change', '.frm_show_password_setting_input', event => {
5858 - const fieldId = event.target.getAttribute( 'data-fid' );
5859 - const fieldEl = document.getElementById( 'frm_field_id_' + fieldId );
5860 - if ( ! fieldEl ) {
5861 - return;
5862 - }
5863 -
5864 - fieldEl.classList.toggle( 'frm_disabled_show_password', ! event.target.checked );
5865 - });
5866 - }
5867 -
5868 - function slideDown() {
5869 - /*jshint validthis:true */
5870 - var id = jQuery( this ).data( 'slidedown' );
5871 - var $thisId = jQuery( document.getElementById( id ) );
5872 - if ( $thisId.is( ':hidden' ) ) {
5873 - $thisId.slideDown( 'fast' );
5874 - this.style.display = 'none';
5875 - }
5876 - return false;
5877 - }
5878 -
5879 - function slideUp() {
5880 - /*jshint validthis:true */
5881 - var id = jQuery( this ).data( 'slideup' );
5882 - var $thisId = jQuery( document.getElementById( id ) );
5883 - $thisId.slideUp( 'fast' );
5884 - $thisId.siblings( 'a' ).show();
5885 - return false;
5886 - }
5887 -
5888 - function adjustVisibilityValuesForEveryoneValues( element, option ) {
5889 - if ( '' === option.getAttribute( 'value' ) ) {
5890 - onEveryoneOptionSelected( jQuery( this ) );
5891 - } else {
5892 - unselectEveryoneOptionIfSelected( jQuery( this ) );
5893 - }
5894 - }
5895 -
5896 - function onEveryoneOptionSelected( $select ) {
5897 - $select.val( '' );
5898 - $select.next( '.btn-group' ).find( '.multiselect-container input[value!=""]' ).prop( 'checked', false );
5899 - }
5900 -
5901 - function unselectEveryoneOptionIfSelected( $select ) {
5902 - var selectedValues = $select.val(),
5903 - index;
5904 -
5905 - if ( selectedValues === null ) {
5906 - $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', true );
5907 - onEveryoneOptionSelected( $select );
5908 - return;
5909 - }
5910 -
5911 - index = selectedValues.indexOf( '' );
5912 - if ( index >= 0 ) {
5913 - selectedValues.splice( index, 1 );
5914 - $select.val( selectedValues );
5915 - $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', false );
5916 - }
5917 - }
5918 -
5919 - /**
5920 - * Get rid of empty container that inserts extra space.
5921 - */
5922 - function hideEmptyEle() {
5923 - jQuery( '.frm-hide-empty' ).each( function() {
5924 - if ( jQuery( this ).text().trim().length === 0 ) {
5925 - jQuery( this ).remove();
5926 - }
5927 - });
5928 - }
5929 -
5930 - /* Change the classes in the builder */
5931 - function changeFieldClass( field, setting ) {
5932 - var classes, replace, alignField,
5933 - replaceWith = ' ' + setting.value,
5934 - fieldId = field.getAttribute( 'data-fid' );
5935 -
5936 - // Include classes from multiple settings.
5937 - if ( typeof fieldId !== 'undefined' ) {
5938 - if ( setting.classList.contains( 'field_options_align' ) ) {
5939 - replaceWith += ' ' + document.getElementById( 'frm_classes_' + fieldId ).value;
5940 - } else if ( setting.classList.contains( 'frm_classes' ) ) {
5941 - alignField = document.getElementById( 'field_options_align_' + fieldId );
5942 - if ( alignField !== null ) {
5943 - replaceWith += ' ' + alignField.value;
5944 - }
5945 - }
5946 - }
5947 - replaceWith += ' ';
5948 -
5949 - // Allow for the column number dropdown.
5950 - replaceWith = replaceWith.replace( ' block ', ' ' ).replace( ' inline ', ' horizontal_radio ' );
5951 -
5952 - classes = field.className.split( ' frmstart ' )[1];
5953 - classes = 0 === classes.indexOf( 'frmend ' ) ? '' : classes.split( ' frmend ' )[0];
5954 -
5955 - if ( classes.trim() === '' ) {
5956 - replace = ' frmstart frmend ';
5957 - if ( -1 === field.className.indexOf( replace ) ) {
5958 - replace = ' frmstart frmend ';
5959 - }
5960 - replaceWith = ' frmstart ' + replaceWith.trim() + ' frmend ';
5961 - } else {
5962 - replace = classes.trim();
5963 - replaceWith = replaceWith.trim();
5964 - }
5965 -
5966 - field.className = field.className.replace( replace, replaceWith );
5967 - }
5968 -
5969 - function maybeShowInlineModal( e ) {
5970 - /*jshint validthis:true */
5971 - e.preventDefault();
5972 - showInlineModal( this );
5973 - }
5974 -
5975 - function showInlineModal( icon, input ) {
5976 - var box = document.getElementById( icon.getAttribute( 'data-open' ) ),
5977 - container = jQuery( icon ).closest( 'p' ),
5978 - inputTrigger = ( typeof input !== 'undefined' );
5979 -
5980 - if ( container.hasClass( 'frm-open' ) ) {
5981 - container.removeClass( 'frm-open' );
5982 - box.classList.add( 'frm_hidden' );
5983 - } else {
5984 - if ( ! inputTrigger ) {
5985 - input = getInputForIcon( icon );
5986 - }
5987 - if ( input !== null ) {
5988 - if ( ! inputTrigger ) {
5989 - input.focus();
5990 - }
5991 - container.after( box );
5992 - box.setAttribute( 'data-fills', input.id );
5993 -
5994 - if ( box.id.indexOf( 'frm-calc-box' ) === 0 ) {
5995 - popCalcFields( box, true );
5996 - }
5997 - }
5998 -
5999 - container.addClass( 'frm-open' );
6000 - box.classList.remove( 'frm_hidden' );
6001 -
6002 - /**
6003 - * @since 6.4.1
6004 - */
6005 - wp.hooks.doAction( 'frm_show_inline_modal', box, icon );
6006 - }
6007 - }
6008 -
6009 - function dismissInlineModal( e ) {
6010 - /*jshint validthis:true */
6011 - e.preventDefault();
6012 - this.parentNode.classList.add( 'frm_hidden' );
6013 - jQuery( '.frm-open [data-open="' + this.parentNode.id + '"]' ).closest( '.frm-open' ).removeClass( 'frm-open' );
6014 - }
6015 -
6016 - function changeInputtedValue() {
6017 - /*jshint validthis:true */
6018 - var i,
6019 - action = this.getAttribute( 'data-frmchange' ).split( ',' );
6020 -
6021 - for ( i = 0; i < action.length; i++ ) {
6022 - if ( action[i] === 'updateOption' ) {
6023 - changeHiddenSeparateValue( this );
6024 - } else if ( action[i] === 'updateDefault' ) {
6025 - changeDefaultRadioValue( this );
6026 - } else if ( action[i] === 'checkUniqueOpt' ) {
6027 - checkUniqueOpt( this );
6028 - } else {
6029 - this.value = this.value[ action[i] ]();
6030 - }
6031 - }
6032 - }
6033 -
6034 - /**
6035 - * When the saved value is changed, update the default value radio.
6036 - */
6037 - function changeDefaultRadioValue( input ) {
6038 - var parentLi = getOptionParent( input ),
6039 - key = parentLi.getAttribute( 'data-optkey' ),
6040 - fieldId = getOptionFieldId( parentLi, key ),
6041 - defaultRadio = parentLi.querySelector( 'input[name="default_value_' + fieldId + '"]' );
6042 -
6043 - if ( defaultRadio !== null ) {
6044 - defaultRadio.value = input.value;
6045 - }
6046 - }
6047 -
6048 - /**
6049 - * If separate values are not enabled, change the saved value when
6050 - * the displayed value is changed.
6051 - */
6052 - function changeHiddenSeparateValue( input ) {
6053 - var savedVal,
6054 - parentLi = getOptionParent( input ),
6055 - key = parentLi.getAttribute( 'data-optkey' ),
6056 - fieldId = getOptionFieldId( parentLi, key ),
6057 - sep = document.getElementById( 'separate_value_' + fieldId );
6058 -
6059 - if ( sep !== null && sep.checked === false ) {
6060 - // If separate values are not turned on.
6061 - savedVal = document.getElementById( 'field_key_' + fieldId + '-' + key );
6062 - savedVal.value = input.value;
6063 - changeDefaultRadioValue( savedVal );
6064 - }
6065 - }
6066 -
6067 - function getOptionParent( input ) {
6068 - var parentLi = input.parentNode;
6069 - if ( parentLi.tagName !== 'LI' ) {
6070 - parentLi = parentLi.parentNode;
6071 - }
6072 - return parentLi;
6073 - }
6074 -
6075 - function getOptionFieldId( li, key ) {
6076 - var liId = li.id;
6077 -
6078 - return liId.replace( 'frm_delete_field_', '' ).replace( '-' + key + '_container', '' );
6079 - }
6080 -
6081 - function submitBuild() {
6082 - /*jshint validthis:true */
6083 - var $thisEle = this;
6084 -
6085 - preFormSave( this );
6086 -
6087 - var $form = jQuery( builderForm );
6088 - var v = JSON.stringify( $form.serializeArray() );
6089 -
6090 - jQuery( document.getElementById( 'frm_compact_fields' ) ).val( v );
6091 - jQuery.ajax({
6092 - type: 'POST',
6093 - url: ajaxurl,
6094 - data: {action: 'frm_save_form', 'frm_compact_fields': v, nonce: frmGlobal.nonce},
6095 - success: function( msg ) {
6096 - afterFormSave( $thisEle );
6097 -
6098 - var $postStuff = document.getElementById( 'post-body-content' );
6099 - var $html = document.createElement( 'div' );
6100 - $html.setAttribute( 'class', 'frm_updated_message' );
6101 - $html.innerHTML = msg;
6102 - $postStuff.insertBefore( $html, $postStuff.firstChild );
6103 - },
6104 - error: function() {
6105 - triggerSubmit( document.getElementById( 'frm_js_build_form' ) );
6106 - }
6107 - });
6108 - }
6109 -
6110 - function triggerSubmit( form ) {
6111 - var button = form.ownerDocument.createElement( 'input' );
6112 - button.style.display = 'none';
6113 - button.type = 'submit';
6114 - form.appendChild( button ).click();
6115 - form.removeChild( button );
6116 - }
6117 -
6118 - function triggerChange( element ) {
6119 - jQuery( element ).trigger( 'change' );
6120 - }
6121 -
6122 - function submitNoAjax() {
6123 - /*jshint validthis:true */
6124 - var form;
6125 -
6126 - preFormSave( this );
6127 - form = jQuery( builderForm );
6128 - jQuery( document.getElementById( 'frm_compact_fields' ) ).val( JSON.stringify( form.serializeArray() ) );
6129 - triggerSubmit( document.getElementById( 'frm_js_build_form' ) );
6130 - }
6131 -
6132 - function preFormSave( b ) {
6133 - removeWPUnload();
6134 - if ( jQuery( 'form.inplace_form' ).length ) {
6135 - jQuery( '.inplace_save, .postbox' ).trigger( 'click' );
6136 - }
6137 -
6138 - if ( b.classList.contains( 'frm_button_submit' ) ) {
6139 - b.classList.add( 'frm_loading_form' );
6140 - } else {
6141 - b.classList.add( 'frm_loading_button' );
6142 - }
6143 - b.setAttribute( 'aria-busy', 'true' );
6144 - }
6145 -
6146 - function afterFormSave( button ) {
6147 - button.classList.remove( 'frm_loading_form' );
6148 - button.classList.remove( 'frm_loading_button' );
6149 - resetOptionTextDetails();
6150 - fieldsUpdated = 0;
6151 - button.setAttribute( 'aria-busy', 'false' );
6152 -
6153 - setTimeout( function() {
6154 - jQuery( '.frm_updated_message' ).fadeOut( 'slow', function() {
6155 - this.parentNode.removeChild( this );
6156 - });
6157 - }, 5000 );
6158 - }
6159 -
6160 - function initUpgradeModal() {
6161 - const $info = initModal( '#frm_upgrade_modal' );
6162 - if ( $info === false ) {
6163 - return;
6164 - }
6165 -
6166 - document.addEventListener( 'click', handleUpgradeClick );
6167 -
6168 - function handleUpgradeClick( event ) {
6169 - let element, link, content;
6170 -
6171 - element = event.target;
6172 -
6173 - if ( ! element.classList ) {
6174 - return;
6175 - }
6176 -
6177 - const showExpiredModal = element.classList.contains( 'frm_show_expired_modal' ) || null !== element.querySelector( '.frm_show_expired_modal' ) || element.closest( '.frm_show_expired_modal' );
6178 -
6179 - if ( ! element.dataset.upgrade ) {
6180 - const parent = element.closest( '[data-upgrade]' );
6181 - if ( ! parent ) {
6182 - return;
6183 - }
6184 - element = parent;
6185 - }
6186 -
6187 - if ( showExpiredModal ) {
6188 - const hookName = 'frm_show_expired_modal';
6189 - wp.hooks.doAction( hookName, element );
6190 - return;
6191 - }
6192 -
6193 - const upgradeLabel = element.dataset.upgrade;
6194 - if ( ! upgradeLabel || element.classList.contains( 'frm_show_upgrade_tab' ) ) {
6195 - return;
6196 - }
6197 -
6198 - event.preventDefault();
6199 -
6200 - const modal = $info.get( 0 );
6201 - const lockIcon = modal.querySelector( '.frm_lock_icon' );
6202 -
6203 - if ( lockIcon ) {
6204 - lockIcon.style.display = 'block';
6205 - lockIcon.classList.remove( 'frm_lock_open_icon' );
6206 - lockIcon.querySelector( 'use' ).setAttribute( 'href', '#frm_lock_icon' );
6207 - }
6208 -
6209 - const upgradeImageId = 'frm_upgrade_modal_image';
6210 - const oldImage = document.getElementById( upgradeImageId );
6211 - if ( oldImage ) {
6212 - oldImage.remove();
6213 - }
6214 -
6215 - if ( element.dataset.image ) {
6216 - if ( lockIcon ) {
6217 - lockIcon.style.display = 'none';
6218 - }
6219 - lockIcon.parentNode.insertBefore( img({ id: upgradeImageId, src: frmGlobal.url + '/images/' + element.dataset.image }), lockIcon );
6220 - }
6221 -
6222 - const level = modal.querySelector( '.license-level' );
6223 - if ( level ) {
6224 - level.textContent = getRequiredLicenseFromTrigger( element );
6225 - }
6226 -
6227 - // If one click upgrade, hide other content
6228 - addOneClick( element, 'modal', upgradeLabel );
6229 -
6230 - modal.querySelector( '.frm_are_not_installed' ).style.display = element.dataset.image ? 'none' : 'inline-block';
6231 - modal.querySelector( '.frm_feature_label' ).textContent = upgradeLabel;
6232 - modal.querySelector( 'h2' ).style.display = 'block';
6233 -
6234 - $info.dialog( 'open' );
6235 -
6236 - // set the utm medium
6237 - const button = modal.querySelector( '.button-primary:not(.frm-oneclick-button)' );
6238 - link = button.getAttribute( 'href' ).replace( /(medium=)[a-z_-]+/ig, '$1' + element.getAttribute( 'data-medium' ) );
6239 - content = element.getAttribute( 'data-content' );
6240 - if ( content === null ) {
6241 - content = '';
6242 - }
6243 - link = link.replace( /(content=)[a-z_-]+/ig, '$1' + content );
6244 - button.setAttribute( 'href', link );
6245 - }
6246 - }
6247 -
6248 - function getRequiredLicenseFromTrigger( element ) {
6249 - if ( element.dataset.requires ) {
6250 - return element.dataset.requires;
6251 - }
6252 - return 'Pro';
6253 - }
6254 -
6255 - function populateUpgradeTab( element ) {
6256 - const title = element.dataset.upgrade;
6257 -
6258 - const tab = element.getAttribute( 'href' ).replace( '#', '' );
6259 - const container = document.querySelector( '.frm_' + tab ) || document.querySelector( '.' + tab );
6260 -
6261 - if ( ! container ) {
6262 - return;
6263 - }
6264 -
6265 - if ( container.querySelector( '.frm-upgrade-message' ) ) {
6266 - // Tab has already been populated.
6267 - return;
6268 - }
6269 -
6270 - const h2 = container.querySelector( 'h2' );
6271 - h2.style.borderBottom = 'none';
6272 -
6273 - /* translators: %s: Form Setting section name (ie Form Permissions, Form Scheduling). */
6274 - h2.textContent = __( '%s are not installed' ).replace( '%s', title );
6275 -
6276 - container.classList.add( 'frmcenter' );
6277 -
6278 - const upgradeModal = document.getElementById( 'frm_upgrade_modal' );
6279 - appendClonedModalElementToContainer( 'frm-oneclick' );
6280 - appendClonedModalElementToContainer( 'frm-addon-status' );
6281 -
6282 - // Borrow the call to action from the Upgrade upgradeModal which should exist on the settings page (it is still used for other upgrades including Actions).
6283 - const upgradeModalLink = upgradeModal.querySelector( '.frm-upgrade-link' );
6284 - if ( upgradeModalLink ) {
6285 - const upgradeButton = upgradeModalLink.cloneNode( true );
6286 - const level = upgradeButton.querySelector( '.license-level' );
6287 -
6288 - if ( level ) {
6289 - level.textContent = getRequiredLicenseFromTrigger( element );
6290 - }
6291 -
6292 - container.appendChild( upgradeButton );
6293 -
6294 - // Maybe append the secondary "Already purchased?" link from the upgradeModal as well.
6295 - if ( upgradeModalLink.nextElementSibling && upgradeModalLink.nextElementSibling.querySelector( '.frm-link-secondary' ) ) {
6296 - container.appendChild( upgradeModalLink.nextElementSibling.cloneNode( true ) );
6297 - }
6298 -
6299 - appendClonedModalElementToContainer( 'frm-oneclick-button' );
6300 - }
6301 -
6302 - appendClonedModalElementToContainer( 'frm-upgrade-message' );
6303 - addOneClick( element, 'tab', element.dataset.message );
6304 -
6305 - if ( element.dataset.screenshot ) {
6306 - container.appendChild( getScreenshotWrapper( element.dataset.screenshot ) );
6307 - }
6308 -
6309 - function appendClonedModalElementToContainer( className ) {
6310 - container.appendChild( upgradeModal.querySelector( '.' + className ).cloneNode( true ) );
6311 - }
6312 - }
6313 -
6314 - function getScreenshotWrapper( screenshot ) {
6315 - const folderUrl = frmGlobal.url + '/images/screenshots/';
6316 - const wrapper = div({
6317 - className: 'frm-settings-screenshot-wrapper',
6318 - children: [
6319 - getToolbar(),
6320 - div({ child: img({ src: folderUrl + screenshot }) })
6321 - ]
6322 - });
6323 -
6324 - function getToolbar() {
6325 - const children = getColorIcons();
6326 - children.push( img({ src: frmGlobal.url + '/images/tab.svg' }) );
6327 - return div({
6328 - className: 'frm-settings-screenshot-toolbar',
6329 - children
6330 - });
6331 - }
6332 -
6333 - function getColorIcons() {
6334 - return [ '#ED8181', '#EDE06A', '#80BE30' ].map(
6335 - color => {
6336 - const circle = div({ className: 'frm-minmax-icon' });
6337 - circle.style.backgroundColor = color;
6338 - return circle;
6339 - }
6340 - );
6341 - }
6342 -
6343 - return wrapper;
6344 - }
6345 -
6346 - /**
6347 - * Allow addons to be installed from the upgrade modal.
6348 - *
6349 - * @param {Element} link
6350 - * @param {String} context Either 'modal' or 'tab'.
6351 - * @param {String|undefined} upgradeLabel
6352 - */
6353 - function addOneClick( link, context, upgradeLabel ) {
6354 - let container;
6355 -
6356 - if ( 'modal' === context ) {
6357 - container = document.getElementById( 'frm_upgrade_modal' );
6358 - } else if ( 'tab' === context ) {
6359 - container = document.getElementById( link.getAttribute( 'href' ).substr( 1 ) );
6360 - } else {
6361 - return;
6362 - }
6363 -
6364 - const oneclickMessage = container.querySelector( '.frm-oneclick' );
6365 - const upgradeMessage = container.querySelector( '.frm-upgrade-message' );
6366 - const showLink = container.querySelector( '.frm-upgrade-link' );
6367 - const button = container.querySelector( '.frm-oneclick-button' );
6368 - const addonStatus = container.querySelector( '.frm-addon-status' );
6369 -
6370 - let oneclick = link.getAttribute( 'data-oneclick' );
6371 - let newMessage = link.getAttribute( 'data-message' );
6372 - let showIt = 'block';
6373 - let showMsg = 'block';
6374 - let hideIt = 'none';
6375 -
6376 - // If one click upgrade, hide other content.
6377 - if ( oneclickMessage !== null && typeof oneclick !== 'undefined' && oneclick ) {
6378 - if ( newMessage === null ) {
6379 - showMsg = 'none';
6380 - }
6381 - showIt = 'none';
6382 - hideIt = 'block';
6383 - oneclick = JSON.parse( oneclick );
6384 -
6385 - button.className = button.className.replace( ' frm-install-addon', '' ).replace( ' frm-activate-addon', '' );
6386 - button.className = button.className + ' ' + oneclick.class;
6387 - button.textContent = __( 'Activate', 'formidable' );
6388 - button.rel = oneclick.url;
6389 - }
6390 -
6391 - if ( ! newMessage ) {
6392 - newMessage = upgradeMessage.getAttribute( 'data-default' );
6393 - }
6394 - if ( undefined !== upgradeLabel ) {
6395 - newMessage = newMessage.replace( '<span class="frm_feature_label"></span>', upgradeLabel );
6396 - }
6397 -
6398 - upgradeMessage.innerHTML = newMessage;
6399 -
6400 - // Either set the link or use the default.
6401 - showLink.href = getShowLinkHrefValue( link, showLink );
6402 -
6403 - addonStatus.style.display = 'none';
6404 -
6405 - oneclickMessage.style.display = hideIt;
6406 - button.style.display = hideIt === 'block' ? 'inline-block' : hideIt;
6407 - upgradeMessage.style.display = showMsg;
6408 - showLink.style.display = showIt === 'block' ? 'inline-block' : showIt;
6409 - }
6410 -
6411 - function getShowLinkHrefValue( link, showLink ) {
6412 - let customLink = link.getAttribute( 'data-link' );
6413 - if ( customLink === null || typeof customLink === 'undefined' || customLink === '' ) {
6414 - customLink = showLink.getAttribute( 'data-default' );
6415 - }
6416 - return customLink;
6417 - }
6418 -
6419 - /* Form settings */
6420 -
6421 - function showInputIcon( parentClass ) {
6422 - if ( typeof parentClass === 'undefined' ) {
6423 - parentClass = '';
6424 - }
6425 - maybeAddFieldSelection( parentClass );
6426 - jQuery( parentClass + ' .frm_has_shortcodes:not(.frm-with-right-icon) input,' + parentClass + ' .frm_has_shortcodes:not(.frm-with-right-icon) textarea' ).wrap( '<span class="frm-with-right-icon"></span>' ).before( '<svg class="frmsvg frm-show-box"><use xlink:href="#frm_more_horiz_solid_icon"/></svg>' );
6427 - }
6428 -
6429 - /**
6430 - * For reverse compatibility. Check for fields that were
6431 - * using the old sidebar.
6432 - */
6433 - function maybeAddFieldSelection( parentClass ) {
6434 - var i,
6435 - missingClass = jQuery( parentClass + ' :not(.frm_has_shortcodes) .frm_not_email_message, ' + parentClass + ' :not(.frm_has_shortcodes) .frm_not_email_to, ' + parentClass + ' :not(.frm_has_shortcodes) .frm_not_email_subject' );
6436 - for ( i = 0; i < missingClass.length; i++ ) {
6437 - missingClass[i].parentNode.classList.add( 'frm_has_shortcodes' );
6438 - }
6439 - }
6440 -
6441 - function showSuccessOpt() {
6442 - /*jshint validthis:true */
6443 - var c = 'success';
6444 - if ( this.name === 'options[edit_action]' ) {
6445 - c = 'edit';
6446 - }
6447 - var v = jQuery( this ).val();
6448 - jQuery( '.' + c + '_action_box' ).hide();
6449 - if ( v === 'redirect' ) {
6450 - jQuery( '.' + c + '_action_redirect_box.' + c + '_action_box' ).fadeIn( 'slow' );
6451 - } else if ( v === 'page' ) {
6452 - jQuery( '.' + c + '_action_page_box.' + c + '_action_box' ).fadeIn( 'slow' );
6453 - } else {
6454 - jQuery( '.' + c + '_action_message_box.' + c + '_action_box' ).fadeIn( 'slow' );
6455 - }
6456 - }
6457 -
6458 - function copyFormAction( event ) {
6459 - if ( waitForActionToLoadBeforeCopy( event.target ) ) {
6460 - return;
6461 - }
6462 -
6463 - const targetSettings = event.target.closest( '.frm_form_action_settings' );
6464 - const wysiwyg = targetSettings.querySelector( '.wp-editor-area' );
6465 - if ( wysiwyg ) {
6466 - // Temporary remove TinyMCE before cloning to avoid TinyMCE conflicts.
6467 - tinymce.EditorManager.execCommand( 'mceRemoveEditor', true, wysiwyg.id );
6468 - }
6469 -
6470 - const $action = jQuery( targetSettings ).clone();
6471 - const currentID = $action.attr( 'id' ).replace( 'frm_form_action_', '' );
6472 - const newID = newActionId( currentID );
6473 -
6474 - $action.find( '.frm_action_id, .frm-btn-group' ).remove();
6475 - $action.find( 'input[name$="[' + currentID + '][ID]"]' ).val( '' );
6476 - $action.find( '.widget-inside' ).hide();
6477 -
6478 - // the .html() gets original values, so they need to be set
6479 - $action.find( 'input[type=text], textarea, input[type=number]' ).prop( 'defaultValue', function() {
6480 - return this.value;
6481 - });
6482 -
6483 - $action.find( 'input[type=checkbox], input[type=radio]' ).prop( 'defaultChecked', function() {
6484 - return this.checked;
6485 - });
6486 -
6487 - const rename = new RegExp( '\\[' + currentID + '\\]', 'g' );
6488 - const reid = new RegExp( '_' + currentID + '"', 'g' );
6489 - const reclass = new RegExp( '-' + currentID + '"', 'g' );
6490 - const revalue = new RegExp( '"' + currentID + '"', 'g' ); // if a field id matches, this could cause trouble
6491 -
6492 - let html = $action.html().replace( rename, '[' + newID + ']' ).replace( reid, '_' + newID + '"' );
6493 - html = html.replace( reclass, '-' + newID + '"' ).replace( revalue, '"' + newID + '"' );
6494 -
6495 - const newAction = div({
6496 - id: 'frm_form_action_' + newID,
6497 - className: $action.get( 0 ).className
6498 - });
6499 - newAction.setAttribute( 'data-actionkey', newID );
6500 - newAction.innerHTML = html;
6501 - newAction.querySelectorAll( '.wp-editor-wrap, .wp-editor-wrap *' ).forEach(
6502 - element => {
6503 - if ( 'string' === typeof element.className ) {
6504 - element.className = element.className.replace( currentID, newID );
6505 - }
6506 - element.id = element.id.replace( currentID, newID );
6507 - }
6508 - );
6509 - newAction.classList.remove( 'open' );
6510 - document.getElementById( 'frm_notification_settings' ).appendChild( newAction );
6511 -
6512 - if ( wysiwyg ) {
6513 - // Re-initialize the original wysiwyg which was removed before cloning.
6514 - frmDom.wysiwyg.init( wysiwyg );
6515 - frmDom.wysiwyg.init( newAction.querySelector( '.wp-editor-area' ) );
6516 - }
6517 -
6518 - if ( newAction.classList.contains( 'frm_single_on_submit_settings' ) ) {
6519 - const autocompleteInput = newAction.querySelector( 'input.frm-page-search' );
6520 - if ( autocompleteInput ) {
6521 - frmDom.autocomplete.initAutocomplete( 'page', newAction );
6522 - }
6523 - }
6524 -
6525 - initiateMultiselect();
6526 -
6527 - const hookName = 'frm_after_duplicate_action';
6528 - wp.hooks.doAction( hookName, newAction );
6529 - }
6530 -
6531 - function waitForActionToLoadBeforeCopy( element ) {
6532 - var $trigger = jQuery( element ),
6533 - $original = $trigger.closest( '.frm_form_action_settings' ),
6534 - $inside = $original.find( '.widget-inside' ),
6535 - $top;
6536 -
6537 - if ( $inside.find( 'p, div, table' ).length ) {
6538 - return false;
6539 - }
6540 -
6541 - $top = $original.find( '.widget-top' );
6542 - $top.on( 'frm-action-loaded', function() {
6543 - $trigger.trigger( 'click' );
6544 - $original.removeClass( 'open' );
6545 - $inside.hide();
6546 - });
6547 - $top.trigger( 'click' );
6548 - return true;
6549 - }
6550 -
6551 - function newActionId( currentID ) {
6552 - var newID = parseInt( currentID, 10 ) + 11;
6553 - var exists = document.getElementById( 'frm_form_action_' + newID );
6554 - if ( exists !== null ) {
6555 - newID++;
6556 - newID = newActionId( newID );
6557 - }
6558 - return newID;
6559 - }
6560 -
6561 - function addFormAction() {
6562 - /*jshint validthis:true */
6563 - const type = jQuery( this ).data( 'actiontype' );
6564 -
6565 - if ( isAtLimitForActionType( type ) ) {
6566 - return;
6567 - }
6568 -
6569 - const actionId = getNewActionId();
6570 - const formId = thisFormId;
6571 -
6572 - const placeholderSetting = document.createElement( 'div' );
6573 - placeholderSetting.classList.add( 'frm_single_' + type + '_settings' );
6574 -
6575 - const actionsList = document.getElementById( 'frm_notification_settings' );
6576 - actionsList.appendChild( placeholderSetting );
6577 -
6578 - jQuery.ajax({
6579 - type: 'POST',
6580 - url: ajaxurl,
6581 - data: {
6582 - action: 'frm_add_form_action',
6583 - type: type,
6584 - list_id: actionId,
6585 - form_id: formId,
6586 - nonce: frmGlobal.nonce
6587 - },
6588 - success: handleAddFormActionSuccess
6589 - });
6590 -
6591 - function handleAddFormActionSuccess( html ) {
6592 - fieldUpdated();
6593 - placeholderSetting.remove();
6594 -
6595 - closeOpenActions();
6596 -
6597 - const newActionContainer = div();
6598 - newActionContainer.innerHTML = html;
6599 -
6600 - const widgetTop = newActionContainer.querySelector( '.widget-top' );
6601 - Array.from( newActionContainer.children ).forEach( child => actionsList.appendChild( child ) );
6602 -
6603 - jQuery( '.frm_form_action_settings' ).fadeIn( 'slow' );
6604 -
6605 - const newAction = document.getElementById( 'frm_form_action_' + actionId );
6606 -
6607 - newAction.classList.add( 'open' );
6608 - document.getElementById( 'post-body-content' ).scroll({
6609 - top: newAction.offsetTop + 10,
6610 - left: 0,
6611 - behavior: 'smooth'
6612 - });
6613 -
6614 - // Check if icon should be active
6615 - checkActiveAction( type );
6616 - showInputIcon( '#frm_form_action_' + actionId );
6617 -
6618 - initiateMultiselect();
6619 - frmDom.autocomplete.initAutocomplete( 'page', newAction );
6620 -
6621 - if ( widgetTop ) {
6622 - jQuery( widgetTop ).trigger( 'frm-action-loaded' );
6623 - }
6624 -
6625 - /**
6626 - * Fires after added a new form action.
6627 - *
6628 - * @since 5.5.4
6629 - *
6630 - * @param {HTMLElement} formAction Form action element.
6631 - */
6632 - frmAdminBuild.hooks.doAction( 'frm_added_form_action', newAction );
6633 - }
6634 - }
6635 -
6636 - function closeOpenActions() {
6637 - document.querySelectorAll( '.frm_form_action_settings.open' ).forEach(
6638 - setting => setting.classList.remove( 'open' )
6639 - );
6640 - }
6641 -
6642 - function toggleActionGroups() {
6643 - /*jshint validthis:true */
6644 - var actions = document.getElementById( 'frm_email_addon_menu' ).classList,
6645 - search = document.getElementById( 'actions-search-input' );
6646 -
6647 - if ( actions.contains( 'frm-all-actions' ) ) {
6648 - actions.remove( 'frm-all-actions' );
6649 - actions.add( 'frm-limited-actions' );
6650 - } else {
6651 - actions.add( 'frm-all-actions' );
6652 - actions.remove( 'frm-limited-actions' );
6653 - }
6654 -
6655 - // Reset search.
6656 - search.value = '';
6657 - triggerEvent( search, 'input' );
6658 - }
6659 -
6660 - function getNewActionId() {
6661 - var actionSettings = document.querySelectorAll( '.frm_form_action_settings' ),
6662 - len = getNewRowId( actionSettings, 'frm_form_action_' );
6663 - if ( typeof document.getElementById( 'frm_form_action_' + len ) !== 'undefined' ) {
6664 - len = len + 100;
6665 - }
6666 - if ( lastNewActionIdReturned >= len ) {
6667 - len = lastNewActionIdReturned + 1;
6668 - }
6669 - lastNewActionIdReturned = len;
6670 - return len;
6671 - }
6672 -
6673 - function clickAction( obj ) {
6674 - var $thisobj = jQuery( obj );
6675 -
6676 - if ( obj.className.indexOf( 'selected' ) !== -1 ) {
6677 - return;
6678 - }
6679 - if ( obj.className.indexOf( 'edit_field_type_end_divider' ) !== -1 && $thisobj.closest( '.edit_field_type_divider' ).hasClass( 'no_repeat_section' ) ) {
6680 - return;
6681 - }
6682 -
6683 - deselectFields();
6684 - $thisobj.addClass( 'selected' );
6685 - showFieldOptions( obj );
6686 - }
6687 -
6688 - /**
6689 - * When a field is selected, show the field settings in the sidebar.
6690 - */
6691 - function showFieldOptions( obj ) {
6692 - var i, singleField,
6693 - fieldId = obj.getAttribute( 'data-fid' ),
6694 - fieldType = obj.getAttribute( 'data-type' ),
6695 - allFieldSettings = document.querySelectorAll( '.frm-single-settings:not(.frm_hidden)' );
6696 -
6697 - for ( i = 0; i < allFieldSettings.length; i++ ) {
6698 - allFieldSettings[i].classList.add( 'frm_hidden' );
6699 - }
6700 -
6701 - singleField = document.getElementById( 'frm-single-settings-' + fieldId );
6702 - moveFieldSettings( singleField );
6703 -
6704 - if ( fieldType && 'quantity' === fieldType ) {
6705 - popProductFields( jQuery( singleField ).find( '.frmjs_prod_field_opt' )[0]);
6706 - }
6707 -
6708 - singleField.classList.remove( 'frm_hidden' );
6709 - document.getElementById( 'frm-options-panel-tab' ).click();
6710 -
6711 - const editor = singleField.querySelector( '.wp-editor-area' );
6712 - if ( editor ) {
6713 - frmDom.wysiwyg.init(
6714 - editor,
6715 - { setupCallback: setupTinyMceEventHandlers }
6716 - );
6717 - }
6718 - }
6719 -
6720 - function setupTinyMceEventHandlers( editor ) {
6721 - editor.on( 'Change', function() {
6722 - handleTinyMceChange( editor );
6723 - });
6724 - }
6725 -
6726 - function handleTinyMceChange( editor ) {
6727 - if ( ! isTinyMceActive() || tinyMCE.activeEditor.isHidden() ) {
6728 - return;
6729 - }
6730 -
6731 - editor.targetElm.value = editor.getContent();
6732 - jQuery( editor.targetElm ).trigger( 'change' );
6733 - }
6734 -
6735 - function isTinyMceActive() {
6736 - var activeSettings, wrapper;
6737 -
6738 - activeSettings = document.querySelector( '.frm-single-settings:not(.frm_hidden)' );
6739 - if ( ! activeSettings ) {
6740 - return false;
6741 - }
6742 -
6743 - wrapper = activeSettings.querySelector( '.wp-editor-wrap' );
6744 - return null !== wrapper && wrapper.classList.contains( 'tmce-active' );
6745 - }
6746 -
6747 - /**
6748 - * Move the settings to the sidebar the first time they are changed or selected.
6749 - * Keep the end marker at the end of the form.
6750 - */
6751 - function moveFieldSettings( singleField ) {
6752 - if ( singleField === null ) {
6753 - // The field may have not been loaded yet via ajax.
6754 - return;
6755 - }
6756 -
6757 - var classes = singleField.parentElement.classList;
6758 - if ( classes.contains( 'frm_field_box' ) || classes.contains( 'divider_section_only' ) ) {
6759 - var endMarker = document.getElementById( 'frm-end-form-marker' );
6760 - builderForm.insertBefore( singleField, endMarker );
6761 - }
6762 - }
6763 -
6764 - function showEmailRow() {
6765 - /*jshint validthis:true */
6766 - var actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' );
6767 - var rowType = this.getAttribute( 'data-emailrow' );
6768 -
6769 - jQuery( '#frm_form_action_' + actionKey + ' .frm_' + rowType + '_row' ).fadeIn( 'slow' );
6770 - jQuery( this ).fadeOut( 'slow' );
6771 - }
6772 -
6773 - function hideEmailRow() {
6774 - /*jshint validthis:true */
6775 - var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ),
6776 - rowType = this.getAttribute( 'data-emailrow' ),
6777 - emailRowSelector = '.frm_' + rowType + '_row',
6778 - emailButtonSelector = '.frm_' + rowType + '_button';
6779 -
6780 - jQuery( actionBox ).find( emailButtonSelector ).fadeIn( 'slow' );
6781 - jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow', function() {
6782 - jQuery( actionBox ).find( emailRowSelector + ' input' ).val( '' );
6783 - });
6784 - }
6785 -
6786 - function showEmailWarning() {
6787 - /*jshint validthis:true */
6788 - var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ),
6789 - emailRowSelector = '.frm_from_to_match_row',
6790 - fromVal = actionBox.find( 'input[name$="[post_content][from]"]' ).val(),
6791 - toVal = actionBox.find( 'input[name$="[post_content][email_to]"]' ).val();
6792 -
6793 - if ( fromVal === toVal ) {
6794 - jQuery( actionBox ).find( emailRowSelector ).fadeIn( 'slow' );
6795 - } else {
6796 - jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow' );
6797 - }
6798 - }
6799 -
6800 - function checkActiveAction( type ) {
6801 - const actionTriggers = document.querySelectorAll( '.frm_' + type + '_action' );
6802 -
6803 - if ( isAtLimitForActionType( type ) ) {
6804 - const addAlreadyUsedClass = getLimitForActionType( type ) > 0;
6805 - markActionTriggersInactive( actionTriggers, addAlreadyUsedClass );
6806 - return;
6807 - }
6808 -
6809 - markActionTriggersActive( actionTriggers );
6810 - }
6811 -
6812 - function markActionTriggersActive( triggers ) {
6813 - triggers.forEach(
6814 - trigger => {
6815 - if ( trigger.querySelector( '.frm_show_upgrade' ) ) {
6816 - // Prevent disabled action becoming active.
6817 - return;
6818 - }
6819 -
6820 - trigger.classList.remove( 'frm_inactive_action', 'frm_already_used' );
6821 - trigger.classList.add( 'frm_active_action' );
6822 - }
6823 - );
6824 - }
6825 -
6826 - function markActionTriggersInactive( triggers, addAlreadyUsedClass ) {
6827 - triggers.forEach(
6828 - trigger => {
6829 - trigger.classList.remove( 'frm_active_action' );
6830 - trigger.classList.add( 'frm_inactive_action' );
6831 - if ( addAlreadyUsedClass ) {
6832 - trigger.classList.add( 'frm_already_used' );
6833 - }
6834 - }
6835 - );
6836 - }
6837 -
6838 - function isAtLimitForActionType( type ) {
6839 - let atLimit = getNumberOfActionsForType( type ) >= getLimitForActionType( type );
6840 -
6841 - const hookName = 'frm_action_at_limit';
6842 - const hookArgs = { type };
6843 - atLimit = wp.hooks.applyFilters( hookName, atLimit, hookArgs );
6844 -
6845 - return atLimit;
6846 - }
6847 -
6848 - function getLimitForActionType( type ) {
6849 - return parseInt( jQuery( '.frm_' + type + '_action' ).data( 'limit' ), 10 );
6850 - }
6851 -
6852 - function getNumberOfActionsForType( type ) {
6853 - return jQuery( '.frm_single_' + type + '_settings' ).length;
6854 - }
6855 -
6856 - function onlyOneActionMessage() {
6857 - infoModal( frm_admin_js.only_one_action ); // eslint-disable-line camelcase
6858 - }
6859 -
6860 - function addFormLogicRow() {
6861 - /*jshint validthis:true */
6862 - var id = jQuery( this ).data( 'emailkey' ),
6863 - type = jQuery( this ).closest( '.frm_form_action_settings' ).find( '.frm_action_name' ).val(),
6864 - formId = document.getElementById( 'form_id' ).value,
6865 - logicRows = document.getElementById( 'frm_form_action_' + id ).querySelectorAll( '.frm_logic_row' );
6866 - jQuery.ajax({
6867 - type: 'POST', url: ajaxurl,
6868 - data: {
6869 - action: 'frm_add_form_logic_row',
6870 - email_id: id,
6871 - form_id: formId,
6872 - meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ),
6873 - type: type,
6874 - nonce: frmGlobal.nonce
6875 - },
6876 - success: function( html ) {
6877 - jQuery( document.getElementById( 'logic_link_' + id ) ).fadeOut( 'slow', function() {
6878 - var $logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) );
6879 - $logicRow.append( html );
6880 - $logicRow.parent( '.frm_logic_rows' ).fadeIn( 'slow' );
6881 - });
6882 - }
6883 - });
6884 - return false;
6885 - }
6886 -
6887 - function toggleSubmitLogic() {
6888 - /*jshint validthis:true */
6889 - if ( this.checked ) {
6890 - addSubmitLogic();
6891 - } else {
6892 - jQuery( '.frm_logic_row_submit' ).remove();
6893 - document.getElementById( 'frm_submit_logic_rows' ).style.display = 'none';
6894 - }
6895 - }
6896 -
6897 - /**
6898 - * Adds submit button Conditional Logic row and reveals submit button Conditional Logic
6899 - *
6900 - * @returns {boolean}
6901 - */
6902 - function addSubmitLogic() {
6903 - /*jshint validthis:true */
6904 - var formId = thisFormId,
6905 - logicRows = document.getElementById( 'frm_submit_logic_row' ).querySelectorAll( '.frm_logic_row' );
6906 - jQuery.ajax({
6907 - type: 'POST',
6908 - url: ajaxurl,
6909 - data: {
6910 - action: 'frm_add_submit_logic_row',
6911 - form_id: formId,
6912 - meta_name: getNewRowId( logicRows, 'frm_logic_submit_' ),
6913 - nonce: frmGlobal.nonce
6914 - },
6915 - success: function( html ) {
6916 - var $logicRow = jQuery( document.getElementById( 'frm_submit_logic_row' ) );
6917 - $logicRow.append( html );
6918 - $logicRow.parent( '.frm_submit_logic_rows' ).fadeIn( 'slow' );
6919 - }
6920 - });
6921 - return false;
6922 - }
6923 -
6924 - /**
6925 - * When the user selects a field for a submit condition, update corresponding options field accordingly.
6926 - */
6927 - function addSubmitLogicOpts() {
6928 - var fieldOpt = jQuery( this );
6929 - var fieldId = fieldOpt.find( ':selected' ).val();
6930 -
6931 - if ( fieldId ) {
6932 - var row = fieldOpt.data( 'row' );
6933 - frmGetFieldValues( fieldId, 'submit', row, '', 'options[submit_conditions][hide_opt][]' );
6934 - }
6935 - }
6936 -
6937 - function formatEmailSetting() {
6938 - /*jshint validthis:true */
6939 - /*var val = jQuery( this ).val();
6940 - var email = val.match( /(\s[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi );
6941 - if(email !== null && email.length) {
6942 - //has email
6943 - //TODO: add < > if they aren't there
6944 - }*/
6945 - }
6946 -
6947 - function checkDupPost() {
6948 - /*jshint validthis:true */
6949 - var postField = jQuery( 'select.frm_single_post_field' );
6950 - postField.css( 'border-color', '' );
6951 - var $t = this;
6952 - var v = jQuery( $t ).val();
6953 - if ( v === '' || v === 'checkbox' ) {
6954 - return false;
6955 - }
6956 - postField.each( function() {
6957 - if ( jQuery( this ).val() === v && this.name !== $t.name ) {
6958 - this.style.borderColor = 'red';
6959 - jQuery( $t ).val( '' );
6960 - infoModal( frm_admin_js.field_already_used ); // eslint-disable-line camelcase
6961 - return false;
6962 - }
6963 - });
6964 - }
6965 -
6966 - function togglePostContent() {
6967 - /*jshint validthis:true */
6968 - var v = jQuery( this ).val();
6969 - if ( '' === v ) {
6970 - jQuery( '.frm_post_content_opt, select.frm_dyncontent_opt' ).hide().val( '' );
6971 - jQuery( '.frm_dyncontent_opt' ).hide();
6972 - } else if ( 'post_content' === v ) {
6973 - jQuery( '.frm_post_content_opt' ).show();
6974 - jQuery( '.frm_dyncontent_opt' ).hide();
6975 - jQuery( 'select.frm_dyncontent_opt' ).val( '' );
6976 - } else {
6977 - jQuery( '.frm_post_content_opt' ).hide().val( '' );
6978 - jQuery( 'select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt' ).show();
6979 - }
6980 - }
6981 -
6982 - function fillDyncontent() {
6983 - /*jshint validthis:true */
6984 - var v = jQuery( this ).val();
6985 - var $dyn = jQuery( document.getElementById( 'frm_dyncontent' ) );
6986 - if ( '' === v || 'new' === v ) {
6987 - $dyn.val( '' );
6988 - jQuery( '.frm_dyncontent_opt' ).show();
6989 - } else {
6990 - jQuery.ajax({
6991 - type: 'POST', url: ajaxurl,
6992 - data: {action: 'frm_display_get_content', id: v, nonce: frmGlobal.nonce},
6993 - success: function( val ) {
6994 - $dyn.val( val );
6995 - jQuery( '.frm_dyncontent_opt' ).show();
6996 - }
6997 - });
6998 - }
6999 - }
7000 -
7001 - function switchPostType() {
7002 - /*jshint validthis:true */
7003 - // update all rows of categories/taxonomies
7004 - var curSelect, newSelect,
7005 - catRows = document.getElementById( 'frm_posttax_rows' ).childNodes,
7006 - postParentField = document.querySelector( '.frm_post_parent_field' ),
7007 - postMenuOrderField = document.querySelector( '.frm_post_menu_order_field' ),
7008 - postType = this.value;
7009 -
7010 - // Get new category/taxonomy options
7011 - jQuery.ajax({
7012 - type: 'POST',
7013 - url: ajaxurl,
7014 - data: {
7015 - action: 'frm_replace_posttax_options',
7016 - post_type: postType,
7017 - nonce: frmGlobal.nonce
7018 - },
7019 - success: function( html ) {
7020 -
7021 - // Loop through each category row, and replace the first dropdown
7022 - for ( i = 0; i < catRows.length; i++ ) {
7023 - // Check if current element is a div
7024 - if ( catRows[i].tagName !== 'DIV' ) {
7025 - continue;
7026 - }
7027 -
7028 - // Get current category select
7029 - curSelect = catRows[i].getElementsByTagName( 'select' )[0];
7030 -
7031 - // Set up new select
7032 - newSelect = document.createElement( 'select' );
7033 - newSelect.innerHTML = html;
7034 - newSelect.className = curSelect.className;
7035 - newSelect.name = curSelect.name;
7036 -
7037 - // Replace the old select with the new select
7038 - catRows[i].replaceChild( newSelect, curSelect );
7039 - }
7040 - }
7041 - });
7042 -
7043 - // Get new post parent option.
7044 - if ( postParentField ) {
7045 - getActionOption(
7046 - postParentField,
7047 - postType,
7048 - 'frm_get_post_parent_option',
7049 - function( response, optName ) {
7050 - // The replaced string is declared in FrmProFormActionController::ajax_get_post_menu_order_option() in the pro version.
7051 - postParentField.querySelector( '.frm_post_parent_opt_wrapper' ).innerHTML = response.replaceAll( 'REPLACETHISNAME', optName );
7052 - frmDom.autocomplete.initAutocomplete( 'page', postParentField );
7053 - }
7054 - );
7055 - }
7056 -
7057 - if ( postMenuOrderField ) {
7058 - getActionOption( postMenuOrderField, postType, 'frm_should_use_post_menu_order_option' );
7059 - }
7060 - }
7061 -
7062 - function getActionOption( field, postType, action, successHandler ) {
7063 - const opt = field.querySelector( '.frm_autocomplete_value_input' ) || field.querySelector( 'select' ),
7064 - optName = opt.getAttribute( 'name' );
7065 -
7066 - jQuery.ajax({
7067 - url: ajaxurl,
7068 - method: 'POST',
7069 - data: {
7070 - action: action,
7071 - post_type: postType,
7072 - _wpnonce: frmGlobal.nonce
7073 - },
7074 - success: response => {
7075 - if ( 'string' !== typeof response ) {
7076 - console.error( response );
7077 - return;
7078 - }
7079 -
7080 - if ( '0' === response ) {
7081 - // This post type does not support this field.
7082 - field.classList.add( 'frm_hidden' );
7083 - field.value = '';
7084 - return;
7085 - }
7086 -
7087 - field.classList.remove( 'frm_hidden' );
7088 -
7089 - if ( 'function' === typeof successHandler ) {
7090 - successHandler( response, optName );
7091 - }
7092 - },
7093 - error: response => console.error( response )
7094 - });
7095 - }
7096 -
7097 - function addPosttaxRow() {
7098 - /*jshint validthis:true */
7099 - addPostRow( 'tax', this );
7100 - }
7101 -
7102 - function addPostmetaRow() {
7103 - /*jshint validthis:true */
7104 - addPostRow( 'meta', this );
7105 - }
7106 -
7107 - function addPostRow( type, button ) {
7108 - var name,
7109 - id = jQuery( 'input[name="id"]' ).val(),
7110 - settings = jQuery( button ).closest( '.frm_form_action_settings' ),
7111 - key = settings.data( 'actionkey' ),
7112 - postType = settings.find( '.frm_post_type' ).val(),
7113 - metaName = 0,
7114 - postTypeRows = document.querySelectorAll( '.frm_post' + type + '_row' );
7115 -
7116 - if ( postTypeRows.length ) {
7117 - name = postTypeRows[ postTypeRows.length - 1 ].id.replace( 'frm_post' + type + '_', '' );
7118 - if ( isNumeric( name ) ) {
7119 - metaName = 1 + parseInt( name, 10 );
7120 - } else {
7121 - metaName = 1;
7122 - }
7123 - }
7124 -
7125 - jQuery.ajax({
7126 - type: 'POST', url: ajaxurl,
7127 - data: {
7128 - action: 'frm_add_post' + type + '_row',
7129 - form_id: id,
7130 - meta_name: metaName,
7131 - tax_key: metaName,
7132 - post_type: postType,
7133 - action_key: key,
7134 - nonce: frmGlobal.nonce
7135 - },
7136 - success: function( html ) {
7137 - var cfOpts, optIndex;
7138 - jQuery( document.getElementById( 'frm_post' + type + '_rows' ) ).append( html );
7139 - jQuery( '.frm_add_post' + type + '_row.button' ).hide();
7140 -
7141 - if ( type === 'meta' ) {
7142 - jQuery( '.frm_name_value' ).show();
7143 - cfOpts = document.querySelectorAll( '.frm_toggle_cf_opts' );
7144 - for ( optIndex = 0; optIndex < cfOpts.length - 1; ++optIndex ) {
7145 - cfOpts[ optIndex ].style.display = 'none';
7146 - }
7147 - } else if ( type === 'tax' ) {
7148 - jQuery( '.frm_posttax_labels' ).show();
7149 - }
7150 - }
7151 - });
7152 - }
7153 -
7154 - function isNumeric( value ) {
7155 - return ! isNaN( parseFloat( value ) ) && isFinite( value );
7156 - }
7157 -
7158 - function getMetaValue( id, metaName ) {
7159 - var newMeta = metaName;
7160 - if ( jQuery( document.getElementById( id + metaName ) ).length > 0 ) {
7161 - newMeta = getMetaValue( id, metaName + 1 );
7162 - }
7163 - return newMeta;
7164 - }
7165 -
7166 - function changePosttaxRow() {
7167 - /*jshint validthis:true */
7168 - if ( ! jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).length ) {
7169 - return;
7170 - }
7171 -
7172 - jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).html( '<div class="spinner frm_spinner" style="display:block"></div>' );
7173 -
7174 - var postType = jQuery( this ).closest( '.frm_form_action_settings' ).find( 'select[name$="[post_content][post_type]"]' ).val(),
7175 - actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ),
7176 - taxKey = jQuery( this ).closest( '.frm_posttax_row' ).attr( 'id' ).replace( 'frm_posttax_', '' ),
7177 - metaName = jQuery( this ).val(),
7178 - showExclude = jQuery( document.getElementById( taxKey + '_show_exclude' ) ).is( ':checked' ) ? 1 : 0,
7179 - fieldId = jQuery( 'select[name$="[post_category][' + taxKey + '][field_id]"]' ).val(),
7180 - id = jQuery( 'input[name="id"]' ).val();
7181 -
7182 - jQuery.ajax({
7183 - type: 'POST',
7184 - url: ajaxurl,
7185 - data: {
7186 - action: 'frm_add_posttax_row',
7187 - form_id: id,
7188 - post_type: postType,
7189 - tax_key: taxKey,
7190 - action_key: actionKey,
7191 - meta_name: metaName,
7192 - field_id: fieldId,
7193 - show_exclude: showExclude,
7194 - nonce: frmGlobal.nonce
7195 - },
7196 - success: function( html ) {
7197 - var $tax = jQuery( document.getElementById( 'frm_posttax_' + taxKey ) );
7198 - $tax.replaceWith( html );
7199 - }
7200 - });
7201 - }
7202 -
7203 - function toggleCfOpts() {
7204 - /*jshint validthis:true */
7205 - var row = jQuery( this ).closest( '.frm_postmeta_row' );
7206 - var cancel = row.find( '.frm_cancelnew' );
7207 - var select = row.find( '.frm_enternew' );
7208 - if ( row.find( 'select.frm_cancelnew' ).is( ':visible' ) ) {
7209 - cancel.hide();
7210 - select.show();
7211 - } else {
7212 - cancel.show();
7213 - select.hide();
7214 - }
7215 -
7216 - row.find( 'input.frm_enternew, select.frm_cancelnew' ).val( '' );
7217 - return false;
7218 - }
7219 -
7220 - function toggleFormOpts() {
7221 - /*jshint validthis:true */
7222 - var changedOpt = jQuery( this );
7223 - var val = changedOpt.val();
7224 - if ( changedOpt.attr( 'type' ) === 'checkbox' ) {
7225 - if ( this.checked === false ) {
7226 - val = '';
7227 - }
7228 - }
7229 -
7230 - var toggleClass = changedOpt.data( 'toggleclass' );
7231 - if ( val === '' ) {
7232 - jQuery( '.' + toggleClass ).hide();
7233 - } else {
7234 - jQuery( '.' + toggleClass ).show();
7235 - jQuery( '.hide_' + toggleClass + '_' + val ).hide();
7236 - }
7237 - }
7238 -
7239 - function submitSettings() {
7240 - /*jshint validthis:true */
7241 - preFormSave( this );
7242 - triggerSubmit( document.querySelector( '.frm_form_settings' ) );
7243 - }
7244 -
7245 - /* View Functions */
7246 - function showCount() {
7247 - /*jshint validthis:true */
7248 - var value = jQuery( this ).val();
7249 -
7250 - var $cont = document.getElementById( 'date_select_container' );
7251 - var tab = document.getElementById( 'frm_listing_tab' );
7252 - var label = tab.getAttribute( 'data-label' );
7253 - if ( value === 'calendar' ) {
7254 - jQuery( '.hide_dyncontent, .hide_single_content' ).removeClass( 'frm_hidden' );
7255 - jQuery( '.limit_container' ).addClass( 'frm_hidden' );
7256 - $cont.style.display = 'block';
7257 - } else if ( value === 'dynamic' ) {
7258 - jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).removeClass( 'frm_hidden' );
7259 - } else if ( value === 'one' ) {
7260 - label = tab.getAttribute( 'data-one' );
7261 - jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).addClass( 'frm_hidden' );
7262 - } else {
7263 - jQuery( '.hide_dyncontent' ).addClass( 'frm_hidden' );
7264 - jQuery( '.limit_container, .hide_single_content' ).removeClass( 'frm_hidden' );
7265 - }
7266 -
7267 - if ( value !== 'calendar' ) {
7268 - $cont.style.display = 'none';
7269 - }
7270 - tab.innerHTML = label;
7271 - }
7272 -
7273 - function displayFormSelected() {
7274 - /*jshint validthis:true */
7275 - var formId = jQuery( this ).val();
7276 - thisFormId = formId; // set the global form id
7277 - if ( formId === '' ) {
7278 - return;
7279 - }
7280 -
7281 - jQuery.ajax({
7282 - type: 'POST',
7283 - url: ajaxurl,
7284 - data: {
7285 - action: 'frm_get_cd_tags_box',
7286 - form_id: formId,
7287 - nonce: frmGlobal.nonce
7288 - },
7289 - success: function( html ) {
7290 - jQuery( '#frm_adv_info .categorydiv' ).html( html );
7291 - }
7292 - });
7293 -
7294 - jQuery.ajax({
7295 - type: 'POST',
7296 - url: ajaxurl,
7297 - data: {
7298 - action: 'frm_get_date_field_select',
7299 - form_id: formId,
7300 - nonce: frmGlobal.nonce
7301 - },
7302 - success: function( html ) {
7303 - jQuery( document.getElementById( 'date_select_container' ) ).html( html );
7304 - }
7305 - });
7306 - }
7307 -
7308 - function clickTabsAfterAjax() {
7309 - /*jshint validthis:true */
7310 - var t = jQuery( this ).attr( 'href' );
7311 - jQuery( this ).parent().addClass( 'tabs' ).siblings( 'li' ).removeClass( 'tabs' );
7312 - jQuery( t ).show().siblings( '.tabs-panel' ).hide();
7313 - return false;
7314 - }
7315 -
7316 - function clickContentTab() {
7317 - /*jshint validthis:true */
7318 - link = jQuery( this );
7319 - var t = link.attr( 'href' );
7320 - if ( typeof t === 'undefined' ) {
7321 - return false;
7322 - }
7323 -
7324 - var c = t.replace( '#', '.' );
7325 - link.closest( '.nav-tab-wrapper' ).find( 'a' ).removeClass( 'nav-tab-active' );
7326 - link.addClass( 'nav-tab-active' );
7327 - jQuery( '.nav-menu-content' ).not( t ).not( c ).hide();
7328 - jQuery( t + ',' + c ).show();
7329 -
7330 - return false;
7331 - }
7332 -
7333 - function addOrderRow() {
7334 - var logicRows = document.getElementById( 'frm_order_options' ).querySelectorAll( '.frm_logic_rows div' );
7335 - jQuery.ajax({
7336 - type: 'POST',
7337 - url: ajaxurl,
7338 - data: {
7339 - action: 'frm_add_order_row',
7340 - form_id: thisFormId,
7341 - order_key: getNewRowId( logicRows, 'frm_order_field_', 1 ),
7342 - nonce: frmGlobal.nonce
7343 - },
7344 - success: function( html ) {
7345 - jQuery( '#frm_order_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_order_row' ).hide();
7346 - }
7347 - });
7348 - }
7349 -
7350 - function addWhereRow() {
7351 - var rowDivs = document.getElementById( 'frm_where_options' ).querySelectorAll( '.frm_logic_rows div' );
7352 - jQuery.ajax({
7353 - type: 'POST',
7354 - url: ajaxurl,
7355 - data: {
7356 - action: 'frm_add_where_row',
7357 - form_id: thisFormId,
7358 - where_key: getNewRowId( rowDivs, 'frm_where_field_', 1 ),
7359 - nonce: frmGlobal.nonce
7360 - },
7361 - success: function( html ) {
7362 - jQuery( '#frm_where_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_where_row' ).hide();
7363 - }
7364 - });
7365 - }
7366 -
7367 - function insertWhereOptions() {
7368 - /*jshint validthis:true */
7369 - var value = this.value,
7370 - whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' );
7371 -
7372 - jQuery.ajax({
7373 - type: 'POST',
7374 - url: ajaxurl,
7375 - data: {
7376 - action: 'frm_add_where_options',
7377 - where_key: whereKey,
7378 - field_id: value,
7379 - nonce: frmGlobal.nonce
7380 - },
7381 - success: function( html ) {
7382 - jQuery( document.getElementById( 'where_field_options_' + whereKey ) ).html( html );
7383 - }
7384 - });
7385 - }
7386 -
7387 - function hideWhereOptions() {
7388 - /*jshint validthis:true */
7389 - var value = this.value,
7390 - whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' );
7391 -
7392 - if ( value === 'group_by' || value === 'group_by_newest' ) {
7393 - document.getElementById( 'where_field_options_' + whereKey ).style.display = 'none';
7394 - } else {
7395 - document.getElementById( 'where_field_options_' + whereKey ).style.display = 'inline-block';
7396 - }
7397 - }
7398 -
7399 - function setDefaultPostStatus() {
7400 - var urlQuery = window.location.search.substring( 1 );
7401 - if ( urlQuery.indexOf( 'action=edit' ) === -1 ) {
7402 - document.getElementById( 'post-visibility-display' ).textContent = frm_admin_js.private_label; // eslint-disable-line camelcase
7403 - document.getElementById( 'hidden-post-visibility' ).value = 'private';
7404 - document.getElementById( 'visibility-radio-private' ).checked = true;
7405 - }
7406 - }
7407 -
7408 - /* Customization Panel */
7409 - function insertCode( e ) {
7410 - /*jshint validthis:true */
7411 - e.preventDefault();
7412 - insertFieldCode( jQuery( this ), this.getAttribute( 'data-code' ) );
7413 - return false;
7414 - }
7415 -
7416 - function insertFieldCode( element, variable ) {
7417 - var rich = false,
7418 - elementId = element;
7419 - if ( typeof element === 'object' ) {
7420 - if ( element.hasClass( 'frm_noallow' ) ) {
7421 - return;
7422 - }
7423 -
7424 - elementId = jQuery( element ).closest( '[data-fills]' ).attr( 'data-fills' );
7425 - if ( typeof elementId === 'undefined' ) {
7426 - elementId = element.closest( 'div' ).attr( 'class' );
7427 - if ( typeof elementId !== 'undefined' ) {
7428 - elementId = elementId.split( ' ' )[1];
7429 - }
7430 - }
7431 - }
7432 -
7433 - if ( typeof elementId === 'undefined' ) {
7434 - var active = document.activeElement;
7435 - if ( active.type === 'search' ) {
7436 - // If the search field has focus, find the correct field.
7437 - elementId = active.id.replace( '-search-input', '' );
7438 - if ( elementId.match( /\d/gi ) === null ) {
7439 - active = jQuery( '.frm-single-settings:visible .' + elementId );
7440 - elementId = active.attr( 'id' );
7441 - }
7442 - } else {
7443 - elementId = active.id;
7444 - }
7445 - }
7446 -
7447 - if ( elementId ) {
7448 - rich = jQuery( '#wp-' + elementId + '-wrap.wp-editor-wrap' ).length > 0;
7449 - }
7450 -
7451 - var contentBox = jQuery( document.getElementById( elementId ) );
7452 - if ( typeof element.attr( 'data-shortcode' ) === 'undefined' && ( ! contentBox.length || typeof contentBox.attr( 'data-shortcode' ) === 'undefined' ) ) {
7453 - // this helps to exclude those that don't want shortcode-like inserted content e.g. frm-pro's summary field
7454 - var doShortcode = element.parents( 'ul.frm_code_list' ).attr( 'data-shortcode' );
7455 - if ( doShortcode === 'undefined' || doShortcode !== 'no' ) {
7456 - variable = '[' + variable + ']';
7457 - }
7458 - }
7459 -
7460 - if ( rich ) {
7461 - wpActiveEditor = elementId;
7462 - }
7463 -
7464 - if ( ! contentBox.length ) {
7465 - return false;
7466 - }
7467 -
7468 - if ( variable === '[default-html]' || variable === '[default-plain]' ) {
7469 - var p = 0;
7470 - if ( variable === '[default-plain]' ) {
7471 - p = 1;
7472 - }
7473 - jQuery.ajax({
7474 - type: 'POST', url: ajaxurl,
7475 - data: {
7476 - action: 'frm_get_default_html',
7477 - form_id: jQuery( 'input[name="id"]' ).val(),
7478 - plain_text: p,
7479 - nonce: frmGlobal.nonce
7480 - },
7481 - elementId: elementId,
7482 - success: function( msg ) {
7483 - if ( rich ) {
7484 - let p = document.createElement( 'p' );
7485 - p.innerText = msg;
7486 - send_to_editor( p.innerHTML );
7487 - } else {
7488 - insertContent( contentBox, msg );
7489 - }
7490 - }
7491 - });
7492 - } else {
7493 - variable = maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox );
7494 - if ( rich ) {
7495 - send_to_editor( variable );
7496 - } else {
7497 - insertContent( contentBox, variable );
7498 - }
7499 - }
7500 - return false;
7501 - }
7502 -
7503 - function maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox ) {
7504 - if ( 'object' !== typeof element || ! ( element instanceof jQuery ) || 0 !== contentBox[0].id.indexOf( 'success_url_' ) ) {
7505 - return variable;
7506 - }
7507 -
7508 - element = element[0];
7509 - if ( ! element.closest( '#frm-insert-fields-box' ) ) {
7510 - // Only add sanitize_url=1 to field shortcodes.
7511 - return variable;
7512 - }
7513 -
7514 - if ( ! element.parentNode.classList.contains( 'frm_insert_url' ) ) {
7515 - variable = variable.replace( ']', ' sanitize_url=1]' );
7516 - }
7517 -
7518 - return variable;
7519 - }
7520 -
7521 - function insertContent( contentBox, variable ) {
7522 - if ( document.selection ) {
7523 - contentBox[0].focus();
7524 - document.selection.createRange().text = variable;
7525 - } else {
7526 - obj = contentBox[0];
7527 - var e = obj.selectionEnd;
7528 -
7529 - variable = maybeFormatInsertedContent( contentBox, variable, obj.selectionStart, e );
7530 -
7531 - obj.value = obj.value.substr( 0, obj.selectionStart ) + variable + obj.value.substr( obj.selectionEnd, obj.value.length );
7532 - var s = e + variable.length;
7533 - obj.focus();
7534 - obj.setSelectionRange( s, s );
7535 - }
7536 - triggerChange( contentBox );
7537 - }
7538 -
7539 - function maybeFormatInsertedContent( input, textToInsert, selectionStart, selectionEnd ) {
7540 - var separator = input.data( 'sep' );
7541 - if ( undefined === separator ) {
7542 - return textToInsert;
7543 - }
7544 -
7545 - var value = input.val();
7546 -
7547 - if ( ! value.trim().length ) {
7548 - return textToInsert;
7549 - }
7550 -
7551 - var startPattern = new RegExp( separator + '\\s*$' );
7552 - var endPattern = new RegExp( '^\\s*' + separator );
7553 -
7554 - if ( value.substr( 0, selectionStart ).trim().length && false === startPattern.test( value.substr( 0, selectionStart ) ) ) {
7555 - textToInsert = separator + textToInsert;
7556 - }
7557 -
7558 - if ( value.substr( selectionEnd, value.length ).trim().length && false === endPattern.test( value.substr( selectionEnd, value.length ) ) ) {
7559 - textToInsert += separator;
7560 - }
7561 -
7562 - return textToInsert;
7563 - }
7564 -
7565 - function resetLogicBuilder() {
7566 - /*jshint validthis:true */
7567 - var id = document.getElementById( 'frm-id-condition' ),
7568 - key = document.getElementById( 'frm-key-condition' );
7569 -
7570 - if ( this.checked ) {
7571 - id.classList.remove( 'frm_hidden' );
7572 - key.classList.add( 'frm_hidden' );
7573 - triggerEvent( key, 'change' );
7574 - } else {
7575 - id.classList.add( 'frm_hidden' );
7576 - key.classList.remove( 'frm_hidden' );
7577 - triggerEvent( id, 'change' );
7578 - }
7579 - }
7580 -
7581 - function setLogicExample() {
7582 - var field, code,
7583 - idKey = document.getElementById( 'frm-id-key-condition' ).checked ? 'frm-id-condition' : 'frm-key-condition',
7584 - is = document.getElementById( 'frm-is-condition' ).value,
7585 - text = document.getElementById( 'frm-text-condition' ).value,
7586 - result = document.getElementById( 'frm-insert-condition' );
7587 -
7588 - idKey = document.getElementById( idKey );
7589 - field = idKey.options[idKey.selectedIndex].value;
7590 - code = 'if ' + field + ' ' + is + '="' + text + '"]';
7591 - result.setAttribute( 'data-code', code + frm_admin_js.conditional_text + '[/if ' + field ); // eslint-disable-line camelcase
7592 - result.innerHTML = '[' + code + '[/if ' + field + ']';
7593 - }
7594 -
7595 - function showBuilderModal() {
7596 - /*jshint validthis:true */
7597 - var moreIcon = getIconForInput( this );
7598 - showInlineModal( moreIcon, this );
7599 - }
7600 -
7601 - function maybeShowModal( input ) {
7602 - var moreIcon;
7603 - if ( input.parentNode.parentNode.classList.contains( 'frm_has_shortcodes' ) ) {
7604 - hideShortcodes();
7605 - moreIcon = getIconForInput( input );
7606 - if ( moreIcon.tagName === 'use' ) {
7607 - moreIcon = moreIcon.firstElementChild;
7608 - if ( moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ).indexOf( 'frm_close_icon' ) === -1 ) {
7609 - showShortcodeBox( moreIcon, 'nofocus' );
7610 - }
7611 - } else if ( ! moreIcon.classList.contains( 'frm_close_icon' ) ) {
7612 - showShortcodeBox( moreIcon, 'nofocus' );
7613 - }
7614 - }
7615 - }
7616 -
7617 - function showShortcodes( e ) {
7618 - /*jshint validthis:true */
7619 - e.preventDefault();
7620 - e.stopPropagation();
7621 -
7622 - showShortcodeBox( this );
7623 - }
7624 -
7625 - function showShortcodeBox( moreIcon, shouldFocus ) {
7626 - var pos = moreIcon.getBoundingClientRect(),
7627 - input = getInputForIcon( moreIcon ),
7628 - box = document.getElementById( 'frm_adv_info' ),
7629 - classes = moreIcon.className,
7630 - parentPos = box.parentElement.getBoundingClientRect();
7631 -
7632 - if ( moreIcon.tagName === 'svg' ) {
7633 - moreIcon = moreIcon.firstElementChild;
7634 - }
7635 - if ( moreIcon.tagName === 'use' ) {
7636 - classes = moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' );
7637 - }
7638 -
7639 - if ( classes.indexOf( 'frm_close_icon' ) !== -1 ) {
7640 - hideShortcodes( box );
7641 - } else {
7642 - box.style.top = ( pos.top - parentPos.top + 32 ) + 'px';
7643 - box.style.left = ( pos.left - parentPos.left - 280 ) + 'px';
7644 -
7645 - jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' );
7646 - if ( input.classList.contains( 'frm_not_email_to' ) ) {
7647 - jQuery( '#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a' ).addClass( 'frm_noallow' );
7648 - } else if ( input.classList.contains( 'frm_not_email_subject' ) ) {
7649 - jQuery( '.frm_code_list li.hide_frm_not_email_subject a' ).addClass( 'frm_noallow' );
7650 - }
7651 -
7652 - box.setAttribute( 'data-fills', input.id );
7653 - box.style.display = 'block';
7654 -
7655 - if ( moreIcon.tagName === 'use' ) {
7656 - moreIcon.setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_close_icon' );
7657 - } else {
7658 - moreIcon.className = classes.replace( 'frm_more_horiz_solid_icon', 'frm_close_icon' );
7659 - }
7660 -
7661 - if ( shouldFocus !== 'nofocus' ) {
7662 - if ( 'none' !== input.style.display ) {
7663 - input.focus();
7664 - } else {
7665 - jQuery( tinymce.get( input.id ) ).trigger( 'focus' );
7666 - }
7667 - }
7668 - }
7669 - }
7670 -
7671 - function fieldUpdated() {
7672 - if ( ! fieldsUpdated ) {
7673 - fieldsUpdated = 1;
7674 - window.addEventListener( 'beforeunload', confirmExit );
7675 - }
7676 - }
7677 -
7678 - function buildSubmittedNoAjax() {
7679 - // set fieldsUpdated to 0 to avoid the unsaved changes pop up
7680 - fieldsUpdated = 0;
7681 - }
7682 -
7683 - function settingsSubmitted() {
7684 - // set fieldsUpdated to 0 to avoid the unsaved changes pop up
7685 - fieldsUpdated = 0;
7686 - }
7687 -
7688 - function saveAndReloadSettings() {
7689 - var page, form;
7690 - page = document.getElementById( 'form_settings_page' );
7691 - if ( null !== page ) {
7692 - form = page.querySelector( 'form.frm_form_settings' );
7693 - if ( null !== form ) {
7694 - fieldsUpdated = 0;
7695 - form.submit();
7696 - }
7697 - }
7698 - }
7699 -
7700 - function saveAndReloadFormBuilder() {
7701 - document.getElementById( 'frm_submit_side_top' ).click();
7702 - }
7703 -
7704 - function confirmExit( event ) {
7705 - if ( fieldsUpdated ) {
7706 - event.preventDefault();
7707 - event.returnValue = '';
7708 - }
7709 - }
7710 -
7711 - function bindClickForDialogClose( $modal ) {
7712 - const closeModal = function() {
7713 - $modal.dialog( 'close' );
7714 - };
7715 - jQuery( '.ui-widget-overlay' ).on( 'click', closeModal );
7716 - $modal.on( 'click', 'a.dismiss', closeModal );
7717 - }
7718 -
7719 - function triggerNewFormModal( event ) {
7720 - var $modal,
7721 - dismiss = document.getElementById( 'frm_new_form_modal' ).querySelector( 'a.dismiss' );
7722 -
7723 - if ( typeof event !== 'undefined' ) {
7724 - event.preventDefault();
7725 - }
7726 -
7727 - dismiss.setAttribute( 'tabindex', -1 );
7728 -
7729 - $modal = initModal( '#frm_new_form_modal', '600px' );
7730 - offsetModalY( $modal, '50px' );
7731 - $modal.attr( 'frm-page', 'create' );
7732 - $modal.find( '#template-search-input' ).val( '' ).trigger( 'change' );
7733 - $modal.dialog( 'open' );
7734 -
7735 - dismiss.removeAttribute( 'tabindex' );
7736 - bindClickForDialogClose( $modal );
7737 -
7738 - addApplicationsToNewFormModal( $modal.get( 0 ) );
7739 - }
7740 -
7741 - function addApplicationsToNewFormModal( modal ) {
7742 - if ( modal.querySelector( '.frm-ready-made-solution' ) ) {
7743 - // Avoid adding duplicates if the modal is opened multiple times.
7744 - return;
7745 - }
7746 -
7747 - if ( ! frmGlobal.canAccessApplicationDashboard ) {
7748 - // User does not have privileges to see Ready Made Solutions.
7749 - return;
7750 - }
7751 -
7752 - doJsonFetch( 'get_applications_data&view=templates' ).then( addTemplatesOnFetchSuccess );
7753 -
7754 - const categoryList = modal.querySelector( 'ul.frm-categories-list' );
7755 -
7756 - function addTemplatesOnFetchSuccess( data ) {
7757 - data.templates.forEach( addTemplateToCategoryList );
7758 - initSearch( 'template-search-input', 'frm-searchable-template frm-ready-made-solution' );
7759 - }
7760 -
7761 - function addTemplateToCategoryList( template ) {
7762 - categoryList.appendChild( getReadyMadeSolution( template ) );
7763 - }
7764 -
7765 - function getReadyMadeSolution( template ) {
7766 - const image = tag( 'img' );
7767 - const thumbnailFolderUrl = frmGlobal.url + '/images/applications/thumbnails/';
7768 - const filenameToUse = template.hasLiteThumbnail ? template.key + '.png' : 'placeholder.svg';
7769 - image.setAttribute( 'src', thumbnailFolderUrl + filenameToUse );
7770 -
7771 - const imageWrapper = div({ child: image });
7772 - const href = frmGlobal.applicationsUrl + '&triggerViewApplicationModal=1&template=' + template.key;
7773 -
7774 - return tag(
7775 - 'li',
7776 - {
7777 - className: 'frm-searchable-template frm-ready-made-solution frm-selectable',
7778 - data: {
7779 - href: href
7780 - },
7781 - children: [
7782 - imageWrapper,
7783 - div({
7784 - className: 'frm-solution-details',
7785 - children: [
7786 - span({
7787 - className: 'frm-meta-tag',
7788 - text: __( 'Ready Made Solution', 'formidable' )
7789 - }),
7790 - tag( 'h3', template.name ),
7791 - a({
7792 - text: __( 'See all applications', 'formidable' ),
7793 - href: frmGlobal.applicationsUrl
7794 - })
7795 - ]
7796 - }),
7797 - div({
7798 - className: 'frm-hover-icons',
7799 - child: a({
7800 - child: svg({ href: '#frm_plus_icon' }),
7801 - href: href
7802 - })
7803 - })
7804 - ]
7805 - }
7806 - );
7807 - }
7808 - }
7809 -
7810 - function offsetModalY( $modal, amount ) {
7811 - const position = {
7812 - my: 'top',
7813 - at: 'top+' + amount,
7814 - of: window
7815 - };
7816 - $modal.dialog( 'option', 'position', position );
7817 - }
7818 -
7819 - /**
7820 - * Get the input box for the selected ... icon.
7821 - */
7822 - function getInputForIcon( moreIcon ) {
7823 - var input = moreIcon.nextElementSibling;
7824 -
7825 - while ( input !== null && input.tagName !== 'INPUT' && input.tagName !== 'TEXTAREA' ) {
7826 - input = getInputForIcon( input );
7827 - }
7828 -
7829 - return input;
7830 - }
7831 -
7832 - /**
7833 - * Get the ... icon for the selected input box.
7834 - */
7835 - function getIconForInput( input ) {
7836 - var moreIcon = input.previousElementSibling;
7837 -
7838 - while ( moreIcon !== null && moreIcon.tagName !== 'I' && moreIcon.tagName !== 'svg' ) {
7839 - moreIcon = getIconForInput( moreIcon );
7840 - }
7841 -
7842 - return moreIcon;
7843 - }
7844 -
7845 - function hideShortcodes( box ) {
7846 - var i, u, closeIcons, closeSvg;
7847 - if ( typeof box === 'undefined' ) {
7848 - box = document.getElementById( 'frm_adv_info' );
7849 - if ( box === null ) {
7850 - return;
7851 - }
7852 - }
7853 -
7854 - if ( document.getElementById( 'frm_dyncontent' ) !== null ) {
7855 - // Don't run when in the sidebar.
7856 - return;
7857 - }
7858 -
7859 - box.style.display = 'none';
7860 -
7861 - closeIcons = document.querySelectorAll( '.frm-show-box.frm_close_icon' );
7862 - for ( i = 0; i < closeIcons.length; i++ ) {
7863 - closeIcons[i].classList.remove( 'frm_close_icon' );
7864 - closeIcons[i].classList.add( 'frm_more_horiz_solid_icon' );
7865 - }
7866 -
7867 - closeSvg = document.querySelectorAll( '.frm_has_shortcodes use' );
7868 - for ( u = 0; u < closeSvg.length; u++ ) {
7869 - if ( closeSvg[u].getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) === '#frm_close_icon' ) {
7870 - closeSvg[u].setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_more_horiz_solid_icon' );
7871 - }
7872 - }
7873 - }
7874 -
7875 - function initToggleShortcodes() {
7876 - if ( typeof tinymce !== 'object' ) {
7877 - return;
7878 - }
7879 -
7880 - DOM = tinymce.DOM;
7881 - if ( typeof DOM.events !== 'undefined' && typeof DOM.events.add !== 'undefined' ) {
7882 - DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseover', function() {
7883 - if ( jQuery( '*:focus' ).length > 0 ) {
7884 - return;
7885 - }
7886 - if ( this.id ) {
7887 - toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7888 - }
7889 - });
7890 - DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseout', function() {
7891 - if ( jQuery( '*:focus' ).length > 0 ) {
7892 - return;
7893 - }
7894 - if ( this.id ) {
7895 - toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7896 - }
7897 - });
7898 - } else {
7899 - jQuery( '#frm_dyncontent' ).on( 'mouseover mouseout', '.wp-editor-wrap', function() {
7900 - if ( jQuery( '*:focus' ).length > 0 ) {
7901 - return;
7902 - }
7903 - if ( this.id ) {
7904 - toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7905 - }
7906 - });
7907 - }
7908 - }
7909 -
7910 - function toggleAllowedShortcodes( id ) {
7911 - var c, clickedID;
7912 - if ( typeof id === 'undefined' ) {
7913 - id = '';
7914 - }
7915 - c = id;
7916 -
7917 - if ( id.indexOf( '-search-input' ) !== -1 ) {
7918 - return;
7919 - }
7920 -
7921 - if ( id !== '' ) {
7922 - var $ele = jQuery( document.getElementById( id ) );
7923 - if ( $ele.attr( 'class' ) && id !== 'wpbody-content' && id !== 'content' && id !== 'dyncontent' && id !== 'success_msg' ) {
7924 - var d = $ele.attr( 'class' ).split( ' ' )[0];
7925 - if ( d === 'frm_long_input' || d === 'frm_98_width' || typeof d === 'undefined' ) {
7926 - d = '';
7927 - } else {
7928 - id = d.trim();
7929 - }
7930 - c = c + ' ' + d;
7931 - c = c.replace( 'widefat', '' ).replace( 'frm_with_left_label', '' );
7932 - }
7933 - }
7934 -
7935 - jQuery( '#frm-insert-fields-box,#frm-conditionals,#frm-adv-info-tab,#frm-dynamic-values' ).attr( 'data-fills', c.trim() );
7936 - var a = [
7937 - 'content', 'wpbody-content', 'dyncontent', 'success_url',
7938 - 'success_msg', 'edit_msg', 'frm_dyncontent', 'frm_not_email_message',
7939 - 'frm_not_email_subject'
7940 - ];
7941 - var b = [
7942 - 'before_content', 'after_content', 'frm_not_email_to',
7943 - 'dyn_default_value'
7944 - ];
7945 -
7946 - if ( jQuery.inArray( id, a ) >= 0 ) {
7947 - jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' );
7948 - jQuery( '.frm_code_list a.hide_' + id ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7949 - } else if ( jQuery.inArray( id, b ) >= 0 ) {
7950 - jQuery( '.frm_code_list:not(.frm-dropdown-menu) a:not(.show_' + id + ')' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7951 - jQuery( '.frm_code_list a.show_' + id ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' );
7952 - } else {
7953 - jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7954 - }
7955 -
7956 - // Automatically select a tab.
7957 - if ( id === 'dyn_default_value' ) {
7958 - clickedID = 'frm_dynamic_values';
7959 - document.getElementById( clickedID + '_tab' ).click();
7960 - jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_inactive' ).addClass( 'frm_hidden' );
7961 - jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_active' ).removeClass( 'frm_hidden' );
7962 - }
7963 - }
7964 -
7965 - function toggleAllowedHTML( input ) {
7966 - var b,
7967 - id = input.id;
7968 - if ( typeof id === 'undefined' || id.indexOf( '-search-input' ) !== -1 ) {
7969 - return;
7970 - }
7971 -
7972 - jQuery( '#frm-adv-info-tab' ).attr( 'data-fills', id.trim() );
7973 - if ( input.classList.contains( 'field_custom_html' ) ) {
7974 - id = 'field_custom_html';
7975 - }
7976 -
7977 - b = [ 'after_html', 'before_html', 'submit_html', 'field_custom_html' ];
7978 - if ( jQuery.inArray( id, b ) >= 0 ) {
7979 - jQuery( '.frm_code_list li:not(.show_' + id + ')' ).addClass( 'frm_hidden' );
7980 - jQuery( '.frm_code_list li.show_' + id ).removeClass( 'frm_hidden' );
7981 - }
7982 - }
7983 -
7984 - function toggleKeyID( switchTo, e ) {
7985 - e.stopPropagation();
7986 - jQuery( '.frm_code_list .frmids, .frm_code_list .frmkeys' ).addClass( 'frm_hidden' );
7987 - jQuery( '.frm_code_list .' + switchTo ).removeClass( 'frm_hidden' );
7988 - jQuery( '.frmids, .frmkeys' ).removeClass( 'current' );
7989 - jQuery( '.' + switchTo ).addClass( 'current' );
7990 - }
7991 -
7992 - function onActionLoaded( event ) {
7993 - const settings = event.target.closest( '.frm_form_action_settings' );
7994 - if ( settings && ( settings.classList.contains( 'frm_single_email_settings' ) || settings.classList.contains( 'frm_single_on_submit_settings' ) ) ) {
7995 - initWysiwygOnActionLoaded( settings );
7996 - }
7997 - }
7998 -
7999 - function initWysiwygOnActionLoaded( settings ) {
8000 - const wysiwyg = settings.querySelector( '.wp-editor-area' );
8001 - if ( wysiwyg ) {
8002 - frmDom.wysiwyg.init(
8003 - wysiwyg,
8004 - { height: 160, addFocusEvents: true }
8005 - );
8006 - }
8007 - }
8008 -
8009 - /* Global settings page */
8010 - function loadSettingsTab( anchor ) {
8011 - var holder = anchor.replace( '#', '' );
8012 - var holderContainer = jQuery( '.frm_' + holder + '_ajax' );
8013 - if ( holderContainer.length ) {
8014 - jQuery.ajax({
8015 - type: 'POST', url: ajaxurl,
8016 - data: {
8017 - 'action': 'frm_settings_tab',
8018 - 'tab': holder.replace( '_settings', '' ),
8019 - 'nonce': frmGlobal.nonce
8020 - },
8021 - success: function( html ) {
8022 - holderContainer.replaceWith( html );
8023 - }
8024 - });
8025 - }
8026 - }
8027 -
8028 - function uninstallNow() {
8029 - /*jshint validthis:true */
8030 - if ( confirmLinkClick( this ) === true ) {
8031 - jQuery( '.frm_uninstall .frm-wait' ).css( 'visibility', 'visible' );
8032 - jQuery.ajax({
8033 - type: 'POST',
8034 - url: ajaxurl,
8035 - data: 'action=frm_uninstall&nonce=' + frmGlobal.nonce,
8036 - success: function( msg ) {
8037 - jQuery( '.frm_uninstall' ).fadeOut( 'slow' );
8038 - window.location = msg;
8039 - }
8040 - });
8041 - }
8042 - return false;
8043 - }
8044 -
8045 - function saveAddonLicense() {
8046 - /*jshint validthis:true */
8047 - var button = jQuery( this );
8048 - var buttonName = this.name;
8049 - var pluginSlug = this.getAttribute( 'data-plugin' );
8050 - var action = buttonName.replace( 'edd_' + pluginSlug + '_license_', '' );
8051 - var license = document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value;
8052 - jQuery.ajax({
8053 - type: 'POST', url: ajaxurl, dataType: 'json',
8054 - data: {action: 'frm_addon_' + action, license: license, plugin: pluginSlug, nonce: frmGlobal.nonce},
8055 - success: function( msg ) {
8056 - var thisRow = button.closest( '.edd_frm_license_row' );
8057 - if ( action === 'deactivate' ) {
8058 - license = '';
8059 - document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value = '';
8060 - }
8061 - thisRow.find( '.edd_frm_license' ).html( license );
8062 - if ( msg.success === true ) {
8063 - thisRow.find( '.frm_icon_font' ).removeClass( 'frm_hidden' );
8064 - thisRow.find( 'div.alignleft' ).toggleClass( 'frm_hidden', 1000 );
8065 - }
8066 -
8067 - var messageBox = thisRow.find( '.frm_license_msg' );
8068 - messageBox.html( msg.message );
8069 - if ( msg.message !== '' ) {
8070 - setTimeout( function() {
8071 - messageBox.html( '' );
8072 - }, 15000 );
8073 - }
8074 - }
8075 - });
8076 - }
8077 -
8078 - /* Import/Export page */
8079 -
8080 - function startFormMigration( event ) {
8081 - event.preventDefault();
8082 -
8083 - var checkedBoxes = jQuery( event.target ).find( 'input:checked' );
8084 - if ( ! checkedBoxes.length ) {
8085 - return;
8086 - }
8087 -
8088 - var ids = [];
8089 - checkedBoxes.each( function( i ) {
8090 - ids[i] = this.value;
8091 - });
8092 -
8093 - // Begin the import process.
8094 - importForms( ids, event.target );
8095 - }
8096 -
8097 - /**
8098 - * Begins the process of importing the forms.
8099 - */
8100 - function importForms( forms, targetForm ) {
8101 -
8102 - // Hide the form select section.
8103 - var $form = jQuery( targetForm ),
8104 - $processSettings = $form.next( '.frm-importer-process' );
8105 -
8106 - // Display total number of forms we have to import.
8107 - $processSettings.find( '.form-total' ).text( forms.length );
8108 - $processSettings.find( '.form-current' ).text( '1' );
8109 -
8110 - $form.hide();
8111 -
8112 - // Show processing status.
8113 - // '.process-completed' might have been shown earlier during a previous import, so hide now.
8114 - $processSettings.find( '.process-completed' ).hide();
8115 - $processSettings.show();
8116 -
8117 - // Create global import queue.
8118 - s.importQueue = forms;
8119 - s.imported = 0;
8120 -
8121 - // Import the first form in the queue.
8122 - importForm( $processSettings );
8123 - }
8124 -
8125 - /**
8126 - * Imports a single form from the import queue.
8127 - */
8128 - function importForm( $processSettings ) {
8129 - var formID = s.importQueue[0],
8130 - provider = jQuery( '#welcome-panel' ).find( 'input[name="slug"]' ).val(),
8131 - data = {
8132 - action: 'frm_import_' + provider,
8133 - form_id: formID,
8134 - nonce: frmGlobal.nonce
8135 - };
8136 -
8137 - // Trigger AJAX import for this form.
8138 - jQuery.post( ajaxurl, data, function( res ) {
8139 -
8140 - if ( res.success ) {
8141 - var statusUpdate;
8142 -
8143 - if ( res.data.error ) {
8144 - statusUpdate = '<p>' + res.data.name + ': ' + res.data.msg + '</p>';
8145 - } else {
8146 - statusUpdate = '<p>Imported <a href="' + res.data.link + '" target="_blank">' + res.data.name + '</a></p>';
8147 - }
8148 -
8149 - $processSettings.find( '.status' ).prepend( statusUpdate );
8150 - $processSettings.find( '.status' ).show();
8151 -
8152 - // Remove this form ID from the queue.
8153 - s.importQueue = jQuery.grep( s.importQueue, function( value ) {
8154 - return value != formID;
8155 - });
8156 - s.imported++;
8157 -
8158 - if ( s.importQueue.length === 0 ) {
8159 - $processSettings.find( '.process-count' ).hide();
8160 - $processSettings.find( '.forms-completed' ).text( s.imported );
8161 - $processSettings.find( '.process-completed' ).show();
8162 - } else {
8163 - // Import next form in the queue.
8164 - $processSettings.find( '.form-current' ).text( s.imported + 1 );
8165 - importForm( $processSettings );
8166 - }
8167 - }
8168 - });
8169 - }
8170 -
8171 - function validateExport( e ) {
8172 - /*jshint validthis:true */
8173 - e.preventDefault();
8174 -
8175 - var s = false;
8176 - var $exportForms = jQuery( 'input[name="frm_export_forms[]"]' );
8177 -
8178 - if ( ! jQuery( 'input[name="frm_export_forms[]"]:checked' ).val() ) {
8179 - $exportForms.closest( '.frm-table-box' ).addClass( 'frm_blank_field' );
8180 - s = 'stop';
8181 - }
8182 -
8183 - var $exportType = jQuery( 'input[name="type[]"]' );
8184 - if ( ! jQuery( 'input[name="type[]"]:checked' ).val() && $exportType.attr( 'type' ) === 'checkbox' ) {
8185 - $exportType.closest( 'p' ).addClass( 'frm_blank_field' );
8186 - s = 'stop';
8187 - }
8188 -
8189 - if ( s === 'stop' ) {
8190 - return false;
8191 - }
8192 -
8193 - e.stopPropagation();
8194 - this.submit();
8195 - }
8196 -
8197 - function removeExportError() {
8198 - /*jshint validthis:true */
8199 - var t = jQuery( this ).closest( '.frm_blank_field' );
8200 - if ( typeof t === 'undefined' ) {
8201 - return;
8202 - }
8203 -
8204 - var $thisName = this.name;
8205 - if ( $thisName === 'type[]' && jQuery( 'input[name="type[]"]:checked' ).val() ) {
8206 - t.removeClass( 'frm_blank_field' );
8207 - } else if ( $thisName === 'frm_export_forms[]' && jQuery( this ).val() ) {
8208 - t.removeClass( 'frm_blank_field' );
8209 - }
8210 -
8211 - }
8212 -
8213 - function checkCSVExtension() {
8214 - /*jshint validthis:true */
8215 - var f = jQuery( this ).val();
8216 - var re = /\.csv$/i;
8217 - if ( f.match( re ) !== null ) {
8218 - jQuery( '.show_csv' ).fadeIn();
8219 - } else {
8220 - jQuery( '.show_csv' ).fadeOut();
8221 - }
8222 - }
8223 -
8224 - function getExportOption() {
8225 - const exportFormatSelect = document.querySelector( 'select[name="format"]' );
8226 - if ( exportFormatSelect ) {
8227 - return exportFormatSelect.value;
8228 - } else {
8229 - return '';
8230 - }
8231 - }
8232 -
8233 - function exportTypeChanged( event ) {
8234 - const value = event.target.value;
8235 - showOrHideRepeaters( value );
8236 - checkExportTypes.call( event.target );
8237 - checkSelectedAllFormsCheckbox( value );
8238 - }
8239 -
8240 - function checkSelectedAllFormsCheckbox( exportType ) {
8241 - const selectAllCheckbox = document.getElementById( 'frm-export-select-all' );
8242 - if ( exportType === 'csv' ) {
8243 - selectAllCheckbox.checked = false;
8244 - selectAllCheckbox.disabled = true;
8245 - } else {
8246 - selectAllCheckbox.disabled = false;
8247 - }
8248 - }
8249 -
8250 - function checkExportTypes() {
8251 - /*jshint validthis:true */
8252 - var $dropdown = jQuery( this );
8253 - var $selected = $dropdown.find( ':selected' );
8254 - var s = $selected.data( 'support' );
8255 -
8256 - var multiple = s.indexOf( '|' );
8257 - jQuery( 'input[name="type[]"]' ).each( function() {
8258 - this.checked = false;
8259 - if ( s.indexOf( this.value ) >= 0 ) {
8260 - this.disabled = false;
8261 - if ( multiple === -1 ) {
8262 - this.checked = true;
8263 - }
8264 - } else {
8265 - this.disabled = true;
8266 - }
8267 - });
8268 -
8269 - if ( $dropdown.val() === 'csv' ) {
8270 - jQuery( '.csv_opts' ).show();
8271 - jQuery( '.xml_opts' ).hide();
8272 - } else {
8273 - jQuery( '.csv_opts' ).hide();
8274 - jQuery( '.xml_opts' ).show();
8275 - }
8276 -
8277 - var c = $selected.data( 'count' );
8278 - var exportField = jQuery( 'input[name="frm_export_forms[]"]' );
8279 - if ( c === 'single' ) {
8280 - exportField.prop( 'multiple', false );
8281 - exportField.prop( 'checked', false );
8282 - } else {
8283 - exportField.prop( 'multiple', true );
8284 - exportField.prop( 'disabled', false );
8285 - }
8286 - $dropdown.trigger( 'change' );
8287 - }
8288 -
8289 - function showOrHideRepeaters( exportOption ) {
8290 - if ( exportOption === '' ) {
8291 - return;
8292 - }
8293 -
8294 - const repeaters = document.querySelectorAll( '.frm-is-repeater' );
8295 - if ( ! repeaters.length ) {
8296 - return;
8297 - }
8298 -
8299 - if ( exportOption === 'csv' ) {
8300 - repeaters.forEach( form => {
8301 - form.classList.remove( 'frm_hidden' );
8302 - });
8303 - } else {
8304 - repeaters.forEach( form => {
8305 - form.classList.add( 'frm_hidden' );
8306 - });
8307 - }
8308 -
8309 - searchContent.call( document.querySelector( '.frm-auto-search' ) );
8310 - }
8311 -
8312 - function preventMultipleExport() {
8313 - var type = jQuery( 'select[name=format]' ),
8314 - selected = type.find( ':selected' ),
8315 - count = selected.data( 'count' ),
8316 - exportField = jQuery( 'input[name="frm_export_forms[]"]' );
8317 -
8318 - if ( count === 'single' ) {
8319 - // Disable all other fields to prevent multiple selections.
8320 - if ( this.checked ) {
8321 - exportField.prop( 'disabled', true );
8322 - this.removeAttribute( 'disabled' );
8323 - } else {
8324 - exportField.prop( 'disabled', false );
8325 - }
8326 - } else {
8327 - exportField.prop( 'disabled', false );
8328 - }
8329 - }
8330 -
8331 - function initiateMultiselect() {
8332 - jQuery( '.frm_multiselect' ).hide().each( frmDom.bootstrap.multiselect.init );
8333 - }
8334 -
8335 - /* Addons page */
8336 - function installMultipleAddons( e ) {
8337 - e.preventDefault();
8338 - installOrActivate( this, 'frm_multiple_addons' );
8339 - }
8340 -
8341 - function activateAddon( e ) {
8342 - e.preventDefault();
8343 - installOrActivate( this, 'frm_activate_addon' );
8344 - }
8345 -
8346 - function installAddon( e ) {
8347 - e.preventDefault();
8348 - installOrActivate( this, 'frm_install_addon' );
8349 - }
8350 -
8351 - function installOrActivate( clicked, action ) {
8352 - let button, plugin, el, message;
8353 -
8354 - // Remove any leftover error messages, output an icon and get the plugin basename that needs to be activated.
8355 - jQuery( '.frm-addon-error' ).remove();
8356 - button = jQuery( clicked );
8357 - plugin = button.attr( 'rel' );
8358 - el = button.parent();
8359 - message = el.parent().find( '.addon-status-label' );
8360 -
8361 - button.addClass( 'frm_loading_button' );
8362 -
8363 - // Process the Ajax to perform the activation.
8364 - jQuery.ajax({
8365 - url: ajaxurl,
8366 - type: 'POST',
8367 - async: true,
8368 - cache: false,
8369 - dataType: 'json',
8370 - data: {
8371 - action: action,
8372 - nonce: frmGlobal.nonce,
8373 - plugin: plugin
8374 - },
8375 - success: function( response ) {
8376 - let saveAndReload;
8377 -
8378 - if ( 'string' !== typeof response && 'string' === typeof response.message ) {
8379 - if ( 'undefined' !== typeof response.saveAndReload ) {
8380 - saveAndReload = response.saveAndReload;
8381 - }
8382 - response = response.message;
8383 - }
8384 -
8385 - const error = extractErrorFromAddOnResponse( response );
8386 - if ( error ) {
8387 - addonError( error, el, button );
8388 - return;
8389 - }
8390 -
8391 - afterAddonInstall( response, button, message, el, saveAndReload );
8392 - },
8393 - error: function() {
8394 - button.removeClass( 'frm_loading_button' );
8395 - }
8396 - });
8397 - }
8398 -
8399 - function installAddonWithCreds( e ) {
8400 - // Prevent the default action, let the user know we are attempting to install again and go with it.
8401 - e.preventDefault();
8402 -
8403 - // Now let's make another Ajax request once the user has submitted their credentials.
8404 - const proceed = jQuery( this );
8405 - const el = proceed.parent().parent();
8406 - const plugin = proceed.attr( 'rel' );
8407 -
8408 - proceed.addClass( 'frm_loading_button' );
8409 -
8410 - jQuery.ajax({
8411 - url: ajaxurl,
8412 - type: 'POST',
8413 - async: true,
8414 - cache: false,
8415 - dataType: 'json',
8416 - data: {
8417 - action: 'frm_install_addon',
8418 - nonce: frm_admin_js.nonce, // eslint-disable-line camelcase
8419 - plugin: plugin,
8420 - hostname: el.find( '#hostname' ).val(),
8421 - username: el.find( '#username' ).val(),
8422 - password: el.find( '#password' ).val()
8423 - },
8424 - success: function( response ) {
8425 - const error = extractErrorFromAddOnResponse( response );
8426 - if ( error ) {
8427 - addonError( error, el, proceed );
8428 - return;
8429 - }
8430 -
8431 - afterAddonInstall( response, proceed, message, el );
8432 - },
8433 - error: function() {
8434 - proceed.removeClass( 'frm_loading_button' );
8435 - }
8436 - });
8437 - }
8438 -
8439 - function afterAddonInstall( response, button, message, el, saveAndReload ) {
8440 - const addonStatuses = document.querySelectorAll( '.frm-addon-status' );
8441 - addonStatuses.forEach(
8442 - addonStatus => {
8443 - addonStatus.textContent = response;
8444 - addonStatus.style.display = 'block';
8445 - }
8446 - );
8447 -
8448 - // The Ajax request was successful, so let's update the output.
8449 - button.css({ opacity: '0' });
8450 - message.text( frm_admin_js.active ); // eslint-disable-line camelcase
8451 -
8452 - document.querySelectorAll( '.frm-oneclick' ).forEach(
8453 - oneClick => {
8454 - oneClick.style.display = 'none';
8455 - }
8456 - );
8457 -
8458 - jQuery( '#frm_upgrade_modal h2' ).hide();
8459 - jQuery( '#frm_upgrade_modal .frm_lock_icon' ).addClass( 'frm_lock_open_icon' );
8460 - jQuery( '#frm_upgrade_modal .frm_lock_icon use' ).attr( 'xlink:href', '#frm_lock_open_icon' );
8461 -
8462 - // Proceed with CSS changes
8463 - el.parent().removeClass( 'frm-addon-not-installed frm-addon-installed' ).addClass( 'frm-addon-active' );
8464 - button.removeClass( 'frm_loading_button' );
8465 -
8466 - // Maybe refresh import and SMTP pages
8467 - const refreshPage = document.querySelectorAll( '.frm-admin-page-import, #frm-admin-smtp, #frm-welcome' );
8468 - if ( refreshPage.length > 0 ) {
8469 - window.location.reload();
8470 - return;
8471 - }
8472 -
8473 - if ([ 'settings', 'form_builder' ].includes( saveAndReload ) ) {
8474 - addonStatuses.forEach(
8475 - addonStatus => {
8476 - const inModal = null !== addonStatus.closest( '#frm_upgrade_modal' );
8477 - addonStatus.appendChild( getSaveAndReloadSettingsOptions( saveAndReload, inModal ) );
8478 - }
8479 - );
8480 - }
8481 - }
8482 -
8483 - function getSaveAndReloadSettingsOptions( saveAndReload, inModal ) {
8484 - const className = 'frm-save-and-reload-options';
8485 - const children = [ saveAndReloadSettingsButton( saveAndReload ) ];
8486 - if ( inModal ) {
8487 - children.push( closePopupButton() );
8488 - }
8489 - return div({ className, children });
8490 - }
8491 -
8492 - function saveAndReloadSettingsButton( saveAndReload ) {
8493 - var button = document.createElement( 'button' );
8494 - button.classList.add( 'frm-save-and-reload', 'button', 'button-primary', 'frm-button-primary' );
8495 - button.textContent = __( 'Save and Reload', 'formidable' );
8496 - button.addEventListener( 'click', () => {
8497 - if ( saveAndReload === 'form_builder' ) {
8498 - saveAndReloadFormBuilder();
8499 - } else if ( saveAndReload === 'settings' ) {
8500 - saveAndReloadSettings();
8501 - }
8502 - });
8503 - return button;
8504 - }
8505 -
8506 - function closePopupButton() {
8507 - var a = document.createElement( 'a' );
8508 - a.setAttribute( 'href', '#' );
8509 - a.classList.add( 'button', 'button-secondary', 'frm-button-secondary', 'dismiss' );
8510 - a.textContent = __( 'Close', 'formidable' );
8511 - return a;
8512 - }
8513 -
8514 - function extractErrorFromAddOnResponse( response ) {
8515 - if ( typeof response !== 'string' ) {
8516 - if ( typeof response.success !== 'undefined' && response.success ) {
8517 - return false;
8518 - }
8519 -
8520 - if ( response.form ) {
8521 - if ( jQuery( response.form ).is( '#message' ) ) {
8522 - return {
8523 - message: jQuery( response.form ).find( 'p' ).html()
8524 - };
8525 - }
8526 - }
8527 -
8528 - return response;
8529 - }
8530 -
8531 - return false;
8532 - }
8533 -
8534 - function addonError( response, el, button ) {
8535 - if ( response.form ) {
8536 - jQuery( '.frm-inline-error' ).remove();
8537 - button.closest( '.frm-card' )
8538 - .html( response.form )
8539 - .css({ padding: 5 })
8540 - .find( '#upgrade' )
8541 - .attr( 'rel', button.attr( 'rel' ) )
8542 - .on( 'click', installAddonWithCreds );
8543 - } else {
8544 - el.append( '<div class="frm-addon-error frm_error_style"><p><strong>' + response.message + '</strong></p></div>' );
8545 - button.removeClass( 'frm_loading_button' );
8546 - jQuery( '.frm-addon-error' ).delay( 4000 ).fadeOut();
8547 - }
8548 - }
8549 -
8550 - /* Templates */
8551 -
8552 - function initNewFormModal() {
8553 - var installFormTrigger,
8554 - activeHoverIcons,
8555 - $modal,
8556 - handleError,
8557 - handleEmailAddressError,
8558 - handleConfirmEmailAddressError,
8559 - showFreeTemplatesForm,
8560 - firstLockedTemplate,
8561 - isShowFreeTemplatesFormFirst,
8562 - url,
8563 - urlParams;
8564 -
8565 - url = new URL( window.location.href );
8566 - urlParams = url.searchParams;
8567 -
8568 - isShowFreeTemplatesFormFirst = urlParams.get( 'free-templates' );
8569 -
8570 - jQuery( document ).on( 'click', '.frm-trigger-new-form-modal', triggerNewFormModal );
8571 - $modal = initModal( '#frm_new_form_modal', '600px' );
8572 -
8573 - if ( false === $modal ) {
8574 - return;
8575 - }
8576 -
8577 - setTimeout(
8578 - function() {
8579 - $modal.get( 0 ).querySelector( '.postbox' ).style.display = 'block'; // Fixes pro issue #3508, prevent a conflict that hides the postbox in modal.
8580 - },
8581 - 0
8582 - );
8583 -
8584 - installFormTrigger = document.createElement( 'a' );
8585 - installFormTrigger.classList.add( 'frm-install-template', 'frm_hidden' );
8586 - document.body.appendChild( installFormTrigger );
8587 -
8588 - jQuery( '.frm-install-template' ).on( 'click', function( event ) {
8589 - var $h3Clone = jQuery( this ).closest( 'li, td' ).find( 'h3' ).clone(),
8590 - nameLabel = document.getElementById( 'frm_new_name' ),
8591 - descLabel = document.getElementById( 'frm_new_desc' ),
8592 - oldName;
8593 -
8594 - $h3Clone.find( 'svg, .frm-plan-required-tag' ).remove();
8595 - oldName = $h3Clone.html().trim();
8596 -
8597 - event.preventDefault();
8598 -
8599 - document.getElementById( 'frm_template_name' ).value = oldName;
8600 - document.getElementById( 'frm_link' ).value = this.attributes.rel.value;
8601 - document.getElementById( 'frm_action_type' ).value = 'frm_install_template';
8602 - nameLabel.textContent = nameLabel.getAttribute( 'data-form' );
8603 - descLabel.textContent = descLabel.getAttribute( 'data-form' );
8604 - $modal.dialog( 'open' );
8605 - });
8606 -
8607 - jQuery( document ).on( 'submit', '#frm-new-template', installTemplate );
8608 -
8609 - jQuery( document ).on( 'click', '.frm-hover-icons .frm-preview-form', function( event ) {
8610 - var $li, link, iframe,
8611 - container = document.getElementById( 'frm-preview-block' );
8612 -
8613 - event.preventDefault();
8614 -
8615 - $li = jQuery( this ).closest( 'li' );
8616 - link = $li.attr( 'data-preview' );
8617 -
8618 - if ( link.indexOf( ajaxurl ) > -1 ) {
8619 - iframe = document.createElement( 'iframe' );
8620 - iframe.src = link;
8621 - iframe.height = '400';
8622 - iframe.width = '100%';
8623 - container.innerHTML = '';
8624 - container.appendChild( iframe );
8625 - } else {
8626 - frmApiPreview( container, link );
8627 - }
8628 -
8629 - jQuery( '#frm-preview-title' ).text( getStrippedTemplateName( $li ) );
8630 - $modal.attr( 'frm-page', 'preview' );
8631 - activeHoverIcons = jQuery( this ).closest( '.frm-hover-icons' );
8632 - });
8633 -
8634 - jQuery( document ).on( 'click', 'li.frm-ready-made-solution[data-href]', function() {
8635 - window.location = this.getAttribute( 'data-href' );
8636 - });
8637 -
8638 - jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-create-form', function( event ) {
8639 - var $li, name, link, action;
8640 -
8641 - event.preventDefault();
8642 -
8643 - $li = jQuery( this ).closest( 'li' );
8644 -
8645 - if ( $li.is( '[data-href]' ) ) {
8646 - window.location = $li.attr( 'data-href' );
8647 - return;
8648 - }
8649 -
8650 - if ( $li.hasClass( 'frm-add-blank-form' ) ) {
8651 - name = link = '';
8652 - action = 'frm_install_form';
8653 - } else if ( $li.is( '[data-rel]' ) ) {
8654 - name = getStrippedTemplateName( $li );
8655 - link = $li.attr( 'data-rel' );
8656 - action = 'frm_install_template';
8657 - } else {
8658 - return;
8659 - }
8660 -
8661 - transitionToAddDetails( $modal, name, link, action );
8662 - });
8663 -
8664 - // Welcome page modals.
8665 - jQuery( document ).on( 'click', '.frm-create-blank-form', function( event ) {
8666 - event.preventDefault();
8667 - jQuery( '.frm-trigger-new-form-modal' ).trigger( 'click' );
8668 - transitionToAddDetails( $modal, '', '', 'frm_install_form' );
8669 -
8670 - // Close the modal with the cancel button.
8671 - jQuery( '.frm-modal-cancel.frm-back-to-all-templates' ).on( 'click', function() {
8672 - jQuery( '.ui-widget-overlay' ).trigger( 'click' );
8673 - });
8674 - });
8675 -
8676 - jQuery( document ).on( 'click', '.frm-featured-forms.frm-templates-list li [role="button"]:not(a), .frm-templates-list .accordion-section.open li [role="button"]:not(a)', function( event ) {
8677 - var $hoverIcons, $trigger,
8678 - $li = jQuery( this ).closest( 'li' ),
8679 - triggerClass = $li.hasClass( 'frm-locked-template' ) ? 'frm-unlock-form' : 'frm-create-form';
8680 -
8681 - $hoverIcons = $li.find( '.frm-hover-icons' );
8682 - if ( ! $hoverIcons.length ) {
8683 - $li.trigger( 'mouseover' );
8684 - $hoverIcons = $li.find( '.frm-hover-icons' );
8685 - $hoverIcons.hide();
8686 - }
8687 -
8688 - $trigger = $hoverIcons.find( '.' + triggerClass );
8689 - $trigger.trigger( 'click' );
8690 - });
8691 -
8692 - jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-delete-form', function( event ) {
8693 - var $li,
8694 - trigger;
8695 -
8696 - event.preventDefault();
8697 -
8698 - $li = jQuery( this ).closest( 'li' );
8699 - $li.addClass( 'frm-deleting' );
8700 - trigger = document.createElement( 'a' );
8701 - trigger.setAttribute( 'href', '#' );
8702 - trigger.setAttribute( 'data-id', $li.attr( 'data-formid' ) );
8703 - $li.attr( 'id', 'frm-template-custom-' + $li.attr( 'data-formid' ) );
8704 - jQuery( trigger ).on( 'click', trashTemplate );
8705 - trigger.click();
8706 - setTemplateCount( $li.closest( '.accordion-section' ).get( 0 ) );
8707 - });
8708 -
8709 - showFreeTemplatesForm = function( $el ) {
8710 - var formContainer = document.getElementById( 'frmapi-email-form' );
8711 - jQuery.ajax({
8712 - dataType: 'json',
8713 - url: formContainer.getAttribute( 'data-url' ),
8714 - success: function( json ) {
8715 - var form = json.renderedHtml;
8716 - form = form.replace( /<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi, '' );
8717 - formContainer.innerHTML = form;
8718 - }
8719 - });
8720 -
8721 - $modal.attr( 'frm-page', 'email' );
8722 - $modal.attr( 'frm-this-form', $el.attr( 'data-key' ) );
8723 - $el.append( installFormTrigger );
8724 - };
8725 -
8726 - jQuery( document ).on( 'click', 'li.frm-locked-template .frm-hover-icons .frm-unlock-form', function( event ) {
8727 - var $li,
8728 - activePage;
8729 -
8730 - event.preventDefault();
8731 -
8732 - $li = jQuery( this ).closest( '.frm-locked-template' );
8733 -
8734 - if ( $li.hasClass( 'frm-free-template' ) ) {
8735 - showFreeTemplatesForm( $li );
8736 - return;
8737 - }
8738 -
8739 - if ( $modal.hasClass( 'frm-expired' ) ) {
8740 - activePage = 'renew';
8741 - } else {
8742 - activePage = 'upgrade';
8743 - }
8744 -
8745 - $modal.attr( 'frm-page', activePage );
8746 - });
8747 -
8748 - jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop', function() {
8749 - jQuery( this )
8750 - .closest( '.accordion-section-content' ).css( 'overflow', 'visible' )
8751 - .closest( '.accordion-section' ).css( 'z-index', 1 );
8752 - });
8753 -
8754 - jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop + .frm-dropdown-menu .frm-build-template', function() {
8755 - var name = this.getAttribute( 'data-fullname' ),
8756 - link = this.getAttribute( 'data-formid' ),
8757 - action = 'frm_build_template';
8758 - transitionToAddDetails( $modal, name, link, action );
8759 - });
8760 -
8761 - handleError = function( inputId, errorId, type, message ) {
8762 - var $error = jQuery( errorId );
8763 - $error.removeClass( 'frm_hidden' ).attr( 'frm-error', type );
8764 -
8765 - if ( typeof message !== 'undefined' ) {
8766 - $error.find( 'span[frm-error="' + type + '"]' ).text( message );
8767 - }
8768 -
8769 - jQuery( inputId ).one( 'keyup', function() {
8770 - $error.addClass( 'frm_hidden' );
8771 - });
8772 - };
8773 -
8774 - handleEmailAddressError = function( type ) {
8775 - handleError( '#frm_leave_email', '#frm_leave_email_error', type );
8776 - };
8777 -
8778 - jQuery( document ).on( 'click', '#frm-add-my-email-address', function( event ) {
8779 - var email = document.getElementById( 'frm_leave_email' ).value.trim(),
8780 - regex,
8781 - $hiddenForm,
8782 - $hiddenEmailField;
8783 -
8784 - event.preventDefault();
8785 -
8786 - if ( '' === email ) {
8787 - handleEmailAddressError( 'empty' );
8788 - return;
8789 - }
8790 -
8791 - regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i;
8792 -
8793 - if ( regex.test( email ) === false ) {
8794 - handleEmailAddressError( 'invalid' );
8795 - return;
8796 - }
8797 -
8798 - $hiddenForm = jQuery( '#frmapi-email-form' ).find( 'form' );
8799 - $hiddenEmailField = $hiddenForm.find( '[type="email"]' ).not( '.frm_verify' );
8800 - if ( ! $hiddenEmailField.length ) {
8801 - return;
8802 - }
8803 -
8804 - $hiddenEmailField.val( email );
8805 - jQuery.ajax({
8806 - type: 'POST',
8807 - url: $hiddenForm.attr( 'action' ),
8808 - data: $hiddenForm.serialize() + '&action=frm_forms_preview'
8809 - }).done( function( data ) {
8810 - var message = jQuery( data ).find( '.frm_message' ).text().trim();
8811 - if ( message.indexOf( 'Thanks!' ) >= 0 ) {
8812 - $modal.attr( 'frm-page', 'code' );
8813 - } else {
8814 - handleEmailAddressError( 'invalid' );
8815 - }
8816 - });
8817 - });
8818 -
8819 - handleConfirmEmailAddressError = function( type, message ) {
8820 - handleError( '#frm_code_from_email', '#frm_code_from_email_error', type, message );
8821 - };
8822 -
8823 - jQuery( document ).on( 'click', '.frm-confirm-email-address', function( event ) {
8824 - var code = document.getElementById( 'frm_code_from_email' ).value.trim();
8825 -
8826 - event.preventDefault();
8827 -
8828 - if ( '' === code ) {
8829 - handleConfirmEmailAddressError( 'empty' );
8830 - return;
8831 - }
8832 -
8833 - jQuery.ajax({
8834 - type: 'POST',
8835 - url: ajaxurl,
8836 - dataType: 'json',
8837 - data: {
8838 - action: 'template_api_signup',
8839 - nonce: frmGlobal.nonce,
8840 - code: code,
8841 - key: $modal.attr( 'frm-this-form' )
8842 - },
8843 - success: function( response ) {
8844 - if ( response.success ) {
8845 - if ( isShowFreeTemplatesFormFirst ) {
8846 - // Remove free-templates param from URL then reload page.
8847 - urlParams.delete( 'free-templates' );
8848 - url.search = urlParams.toString();
8849 - window.location.href = url.toString();
8850 -
8851 - return;
8852 - }
8853 -
8854 - if ( typeof response.data !== 'undefined' && typeof response.data.url !== 'undefined' ) {
8855 - installFormTrigger.setAttribute( 'rel', response.data.url );
8856 - installFormTrigger.click();
8857 - $modal.attr( 'frm-page', 'details' );
8858 -
8859 - const hookName = 'frm_new_form_modal_form';
8860 - wp.hooks.doAction( hookName, $modal );
8861 -
8862 - document.getElementById( 'frm_action_type' ).value = 'frm_install_template';
8863 -
8864 - if ( typeof response.data.urlByKey !== 'undefined' ) {
8865 - updateTemplateModalFreeUrls( response.data.urlByKey );
8866 - }
8867 - }
8868 - } else {
8869 - if ( Array.isArray( response.data ) && response.data.length ) {
8870 - handleConfirmEmailAddressError( 'custom', response.data[0].message );
8871 - } else {
8872 - handleConfirmEmailAddressError( 'wrong-code' );
8873 - }
8874 -
8875 - jQuery( '#frm_code_from_email_options' ).removeClass( 'frm_hidden' );
8876 - }
8877 - }
8878 - });
8879 - });
8880 -
8881 - jQuery( document ).on( 'click', '#frm-change-email-address', function() {
8882 - $modal.attr( 'frm-page', 'email' );
8883 - });
8884 -
8885 - jQuery( document ).on( 'click', '#frm-resend-code', function() {
8886 - document.getElementById( 'frm_code_from_email' ).value = '';
8887 - jQuery( '#frm_code_from_email_options, #frm_code_from_email_error' ).addClass( 'frm_hidden' );
8888 - document.getElementById( 'frm-add-my-email-address' ).click();
8889 - });
8890 -
8891 - jQuery( document ).on( 'click', '#frm_new_form_modal .frm-modal-back, #frm_new_form_modal .frm_modal_footer .frm-modal-cancel, #frm_new_form_modal .frm-back-to-all-templates', function( event ) {
8892 - document.getElementById( 'frm-create-title' ).removeAttribute( 'frm-type' );
8893 - $modal.attr( 'frm-page', 'create' );
8894 - });
8895 -
8896 - jQuery( document ).on( 'click', '.frm-use-this-template', function( event ) {
8897 - var $trigger;
8898 -
8899 - event.preventDefault();
8900 -
8901 - $trigger = activeHoverIcons.find( '.frm-create-form' );
8902 - if ( $trigger.closest( '.frm-selectable' ).hasClass( 'frm-locked-template' ) ) {
8903 - $trigger = activeHoverIcons.find( '.frm-unlock-form' );
8904 - }
8905 -
8906 - $trigger.trigger( 'click' );
8907 - });
8908 -
8909 - jQuery( document ).on( 'click', '.frm-submit-new-template', function( event ) {
8910 - var button;
8911 - event.preventDefault();
8912 - button = document.getElementById( 'frm-new-template' ).querySelector( 'button' );
8913 - if ( null !== button ) {
8914 - button.click();
8915 - }
8916 - });
8917 -
8918 - if ( urlParams.get( 'triggerNewFormModal' ) ) {
8919 - triggerNewFormModal();
8920 -
8921 - if ( isShowFreeTemplatesFormFirst ) {
8922 - firstLockedTemplate = jQuery( 'li.frm-locked-template.frm-free-template' ).eq( 0 );
8923 -
8924 - if ( firstLockedTemplate.length ) {
8925 - showFreeTemplatesForm( firstLockedTemplate );
8926 - }
8927 -
8928 - // Hides the back button in the Free Template Modal and shows it when the cancel button is clicked
8929 - $modalBackButton = $modal.find( '.frm-modal-back' );
8930 - $modalBackButton.hide();
8931 - $modal.find( '.frm-modal-cancel' ).on( 'click', ( event ) => {
8932 - $modalBackButton.show();
8933 - $modal.dialog( 'close' );
8934 - });
8935 - }
8936 - }
8937 -
8938 - initSearch( 'template-search-input', 'control-section accordion-section' );
8939 - }
8940 -
8941 - function initSearch( inputID, itemClass ) {
8942 - const searchInput = document.getElementById( inputID );
8943 -
8944 - if ( itemClass === 'control-section accordion-section' ) {
8945 - itemClass = 'frm-selectable frm-searchable-template';
8946 -
8947 - const handleTemplateSearch = () => {
8948 - document.querySelectorAll( '.control-section.accordion-section' ).forEach( category => {
8949 - const found = category.querySelector( '.frm-selectable.frm-searchable-template:not(.frm_hidden)' ) || ( searchInput.value === '' && category.querySelector( '#frm-template-drop' ) );
8950 - if ( found ) {
8951 - setTemplateCount( category );
8952 - }
8953 - category.classList.toggle( 'frm_hidden', ! found );
8954 - });
8955 - };
8956 -
8957 - frmDom.search.init( searchInput, itemClass, { handleSearchResult: handleTemplateSearch });
8958 -
8959 - } else {
8960 - if ( itemClass === 'frm-searchable-template frm-ready-made-solution' ) {
8961 - Array.from( document.getElementsByClassName( itemClass ) ).forEach( item => {
8962 - let innerText = '';
8963 - innerText = item.querySelector( 'h3' ).innerText;
8964 - item.setAttribute( 'frm-search-text', innerText.toLowerCase() );
8965 - });
8966 - }
8967 - frmDom.search.init( searchInput, itemClass );
8968 - }
8969 -
8970 - }
8971 -
8972 - function updateTemplateModalFreeUrls( urlByKey ) {
8973 - jQuery( '#frm_new_form_modal' ).find( '.frm-selectable[data-key]' ).each( function() {
8974 - var $template = jQuery( this ),
8975 - key = $template.attr( 'data-key' );
8976 - if ( 'undefined' !== typeof urlByKey[ key ]) {
8977 - $template.removeClass( 'frm-locked-template' );
8978 - $template.find( 'h3 svg' ).remove(); // remove the lock from the title
8979 - $template.attr( 'data-rel', urlByKey[ key ]);
8980 - }
8981 - });
8982 - }
8983 -
8984 - function transitionToAddDetails( $modal, name, link, action ) {
8985 - var nameLabel = document.getElementById( 'frm_new_name' ),
8986 - descLabel = document.getElementById( 'frm_new_desc' ),
8987 - type = [ 'frm_install_template', 'frm_install_form' ].indexOf( action ) >= 0 ? 'form' : 'template',
8988 - templateNameInput = document.getElementById( 'frm_template_name' );
8989 -
8990 - templateNameInput.value = name;
8991 - document.getElementById( 'frm_link' ).value = link;
8992 - document.getElementById( 'frm_action_type' ).value = action;
8993 - nameLabel.textContent = nameLabel.getAttribute( 'data-' + type );
8994 - if ( descLabel !== null ) {
8995 - descLabel.textContent = descLabel.getAttribute( 'data-' + type );
8996 - }
8997 -
8998 - document.getElementById( 'frm-create-title' ).setAttribute( 'frm-type', type );
8999 -
9000 - $modal.attr( 'frm-page', 'details' );
9001 -
9002 - const hookName = 'frm_new_form_modal_form';
9003 - wp.hooks.doAction( hookName, $modal );
9004 -
9005 - if ( '' === name ) {
9006 - templateNameInput.focus();
9007 - }
9008 - }
9009 -
9010 - function getStrippedTemplateName( $li ) {
9011 - var $clone = $li.find( 'h3' ).clone();
9012 - $clone.find( 'svg, .frm-plan-required-tag, .frm-new-pill' ).remove();
9013 - return $clone.html().trim();
9014 - }
9015 -
9016 - function setTemplateCount( category, searchableTemplates ) {
9017 - var count,
9018 - templateIndex,
9019 - availableCounter,
9020 - availableCount;
9021 -
9022 - if ( typeof searchableTemplates === 'undefined' ) {
9023 - searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden):not(.frm-deleting)' );
9024 - }
9025 -
9026 - count = searchableTemplates.length;
9027 - category.querySelector( '.frm-template-count' ).textContent = count;
9028 -
9029 - jQuery( category ).find( '.frm-templates-plural' ).toggleClass( 'frm_hidden', count === 1 );
9030 - jQuery( category ).find( '.frm-templates-singular' ).toggleClass( 'frm_hidden', count !== 1 );
9031 -
9032 - availableCounter = category.querySelector( '.frm-available-templates-count' );
9033 - if ( availableCounter !== null ) {
9034 - availableCount = 0;
9035 - for ( templateIndex in searchableTemplates ) {
9036 - if ( ! isNaN( templateIndex ) && ! searchableTemplates[ templateIndex ].classList.contains( 'frm-locked-template' ) ) {
9037 - availableCount++;
9038 - }
9039 - }
9040 -
9041 - availableCounter.textContent = availableCount;
9042 - }
9043 - }
9044 -
9045 - function initSelectionAutocomplete() {
9046 - frmDom.autocomplete.initSelectionAutocomplete();
9047 - }
9048 -
9049 - function nextInstallStep( thisStep ) {
9050 - thisStep.classList.add( 'frm_grey' );
9051 - thisStep.nextElementSibling.classList.remove( 'frm_grey' );
9052 - }
9053 -
9054 - function frmApiPreview( cont, link ) {
9055 - cont.innerHTML = '<div class="frm-wait"></div>';
9056 - jQuery.ajax({
9057 - dataType: 'json',
9058 - url: link,
9059 - success: function( json ) {
9060 - var form = json.renderedHtml;
9061 - form = form.replace( /<script\b[^<]*(js\/jquery\/jquery)[^<]*><\/script>/gi, '' );
9062 - form = form.replace( /<link\b[^>]*(jquery-ui.min.css)[^>]*>/gi, '' );
9063 - form = form.replace( ' frm_logic_form ', ' ' );
9064 - form = form.replace( '<form ', '<form onsubmit="event.preventDefault();" ' );
9065 - cont.innerHTML = '<div class="frm-wait" id="frm-remove-me"></div><div class="frm-fade" id="frm-show-me">' +
9066 - form + '</div>';
9067 - setTimeout( function() {
9068 - document.getElementById( 'frm-remove-me' ).style.display = 'none';
9069 - document.getElementById( 'frm-show-me' ).style.opacity = '1';
9070 - }, 300 );
9071 - }
9072 - });
9073 - }
9074 -
9075 - function installTemplateFieldset( e ) {
9076 - /*jshint validthis:true */
9077 - var fieldset = this.parentNode.parentNode,
9078 - action = fieldset.elements.type.value,
9079 - button = this;
9080 - e.preventDefault();
9081 - button.classList.add( 'frm_loading_button' );
9082 - installNewForm( fieldset, action, button );
9083 - }
9084 -
9085 - function installTemplate( e ) {
9086 - /*jshint validthis:true */
9087 - var action = this.elements.type.value,
9088 - button = this.querySelector( 'button' );
9089 - e.preventDefault();
9090 - button.classList.add( 'frm_loading_button' );
9091 - installNewForm( this, action, button );
9092 - }
9093 -
9094 - function installNewForm( form, action, button ) {
9095 - const formData = formToData( form );
9096 - const formName = formData.template_name;
9097 - const formDesc = formData.template_desc;
9098 - const link = form.elements.link.value;
9099 -
9100 - let data = {
9101 - action: action,
9102 - xml: link,
9103 - name: formName,
9104 - desc: formDesc,
9105 - form: JSON.stringify( formData ),
9106 - nonce: frmGlobal.nonce
9107 - };
9108 -
9109 - const hookName = 'frm_before_install_new_form';
9110 - const filterArgs = { formData };
9111 - data = wp.hooks.applyFilters( hookName, data, filterArgs );
9112 -
9113 - postAjax( data, function( response ) {
9114 - if ( typeof response.redirect !== 'undefined' ) {
9115 - const redirect = response.redirect;
9116 - if ( typeof form.elements.redirect === 'undefined' ) {
9117 - window.location = redirect;
9118 - } else {
9119 - const href = document.getElementById( 'frm-redirect-link' );
9120 - if ( typeof link !== 'undefined' && href !== null ) {
9121 - // Show the next installation step.
9122 - href.setAttribute( 'href', redirect );
9123 - href.classList.remove( 'frm_grey', 'disabled' );
9124 - nextInstallStep( form.parentNode.parentNode );
9125 - button.classList.add( 'frm_grey', 'disabled' );
9126 - }
9127 - }
9128 - } else {
9129 - jQuery( '.spinner' ).css( 'visibility', 'hidden' );
9130 -
9131 - // Show response.message
9132 - if ( 'string' === typeof response.message ) {
9133 - showInstallFormErrorModal( response.message );
9134 - }
9135 - }
9136 - button.classList.remove( 'frm_loading_button' );
9137 - });
9138 - }
9139 -
9140 - function showInstallFormErrorModal( message ) {
9141 - const modalContent = div( message );
9142 - modalContent.style.padding = '20px 40px';
9143 - const modal = frmDom.modal.maybeCreateModal(
9144 - 'frmInstallFormErrorModal',
9145 - {
9146 - title: __( 'Unable to install template', 'formidable' ),
9147 - content: modalContent
9148 - }
9149 - );
9150 - modal.classList.add( 'frm_common_modal' );
9151 - }
9152 -
9153 - function handleCaptchaTypeChange( e ) {
9154 - const thresholdContainer = document.getElementById( 'frm_captcha_threshold_container' );
9155 - if ( thresholdContainer ) {
9156 - thresholdContainer.classList.toggle( 'frm_hidden', 'v3' !== e.target.value );
9157 - }
9158 - }
9159 -
9160 - function trashTemplate( e ) {
9161 - /*jshint validthis:true */
9162 - var id = this.getAttribute( 'data-id' );
9163 - e.preventDefault();
9164 -
9165 - data = {
9166 - action: 'frm_forms_trash',
9167 - id: id,
9168 - nonce: frmGlobal.nonce
9169 - };
9170 - postAjax( data, function() {
9171 - var card = document.getElementById( 'frm-template-custom-' + id );
9172 - fadeOut( card, function() {
9173 - card.parentNode.removeChild( card );
9174 - });
9175 - });
9176 - }
9177 -
9178 - function searchContent() {
9179 - /*jshint validthis:true */
9180 - var i,
9181 - regEx = false,
9182 - searchText = this.value.toLowerCase(),
9183 - toSearch = this.getAttribute( 'data-tosearch' ),
9184 - items = document.getElementsByClassName( toSearch );
9185 -
9186 - if ( this.tagName === 'SELECT' ) {
9187 - searchText = selectedOptions( this );
9188 - searchText = searchText.join( '|' ).toLowerCase();
9189 - regEx = true;
9190 - }
9191 -
9192 - if ( toSearch === 'frm-action' && searchText !== '' ) {
9193 - var addons = document.getElementById( 'frm_email_addon_menu' ).classList;
9194 - addons.remove( 'frm-all-actions' );
9195 - addons.add( 'frm-limited-actions' );
9196 - }
9197 -
9198 - for ( i = 0; i < items.length; i++ ) {
9199 - var innerText = items[i].innerText.toLowerCase();
9200 -
9201 - const itemCanBeShown = ! ( getExportOption() === 'xml' && items[i].classList.contains( 'frm-is-repeater' ) );
9202 - if ( searchText === '' ) {
9203 - if ( itemCanBeShown ) {
9204 - items[i].classList.remove( 'frm_hidden' );
9205 - }
9206 - items[i].classList.remove( 'frm-search-result' );
9207 - } else if ( ( regEx && new RegExp( searchText ).test( innerText ) ) || innerText.indexOf( searchText ) >= 0 ) {
9208 - if ( itemCanBeShown ) {
9209 - items[i].classList.remove( 'frm_hidden' );
9210 - }
9211 - items[i].classList.add( 'frm-search-result' );
9212 - } else {
9213 - items[i].classList.add( 'frm_hidden' );
9214 - items[i].classList.remove( 'frm-search-result' );
9215 - }
9216 - }
9217 -
9218 - // Updates the visibility of category headings based on search results.
9219 - updateCatHeadingVisibility();
9220 -
9221 - jQuery( this ).trigger( 'frmAfterSearch' );
9222 - }
9223 -
9224 - /**
9225 - * Updates the visibility of category headings based on search results.
9226 - * If all associated fields are hidden (indicating no search matches),
9227 - * the heading is hidden.
9228 - *
9229 - * @since 6.4.1
9230 - */
9231 - function updateCatHeadingVisibility() {
9232 - const insertFieldsElement = document.querySelector( '#frm-insert-fields' );
9233 - if ( ! insertFieldsElement ) {
9234 - return;
9235 - }
9236 -
9237 - const headingElements = insertFieldsElement.querySelectorAll( ':scope > .frm-with-line' );
9238 - headingElements.forEach( heading => {
9239 - const fieldsListElement = heading.nextElementSibling;
9240 - if ( ! fieldsListElement ) {
9241 - return;
9242 - }
9243 - const listItemElements = fieldsListElement.querySelectorAll( ':scope > li.frmbutton' );
9244 - const allHidden = Array.from( listItemElements ).every( li => li.classList.contains( 'frm_hidden' ) );
9245 -
9246 - // Add or remove class based on `allHidden` condition
9247 - heading.classList.toggle( 'frm_hidden', allHidden );
9248 - });
9249 - }
9250 -
9251 - function stopPropagation( e ) {
9252 - e.stopPropagation();
9253 - }
9254 -
9255 - /* Helpers */
9256 -
9257 - function selectedOptions( select ) {
9258 - var opt,
9259 - result = [],
9260 - options = select && select.options;
9261 -
9262 - for ( var i = 0, iLen = options.length; i < iLen; i++ ) {
9263 - opt = options[i];
9264 -
9265 - if ( opt.selected ) {
9266 - result.push( opt.value );
9267 - }
9268 - }
9269 - return result;
9270 - }
9271 -
9272 - function triggerEvent( element, event ) {
9273 - var evt = document.createEvent( 'HTMLEvents' );
9274 - evt.initEvent( event, false, true );
9275 - element.dispatchEvent( evt );
9276 - }
9277 -
9278 - function postAjax( data, success ) {
9279 - let response;
9280 -
9281 - const xmlHttp = new XMLHttpRequest();
9282 - const params = typeof data === 'string' ? data : Object.keys( data ).map(
9283 - function( k ) {
9284 - return encodeURIComponent( k ) + '=' + encodeURIComponent( data[k]);
9285 - }
9286 - ).join( '&' );
9287 -
9288 - xmlHttp.open( 'post', ajaxurl, true );
9289 - xmlHttp.onreadystatechange = function() {
9290 - if ( xmlHttp.readyState > 3 && xmlHttp.status == 200 ) {
9291 - response = xmlHttp.responseText;
9292 - try {
9293 - response = JSON.parse( response );
9294 - } catch ( e ) {
9295 - // The response may not be JSON, so just return it.
9296 - }
9297 - success( response );
9298 - }
9299 - };
9300 - xmlHttp.setRequestHeader( 'X-Requested-With', 'XMLHttpRequest' );
9301 - xmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
9302 - xmlHttp.send( params );
9303 - return xmlHttp;
9304 - }
9305 -
9306 - function fadeOut( element, success ) {
9307 - element.classList.add( 'frm-fade' );
9308 - setTimeout( success, 1000 );
9309 - }
9310 -
9311 - function invisible( classes ) {
9312 - jQuery( classes ).css( 'visibility', 'hidden' );
9313 - }
9314 -
9315 - function visible( classes ) {
9316 - jQuery( classes ).css( 'visibility', 'visible' );
9317 - }
9318 -
9319 - function initModal( id, width ) {
9320 - const $info = jQuery( id );
9321 - if ( ! $info.length ) {
9322 - return false;
9323 - }
9324 -
9325 - if ( typeof width === 'undefined' ) {
9326 - width = '550px';
9327 - }
9328 -
9329 - const dialogArgs = {
9330 - dialogClass: 'frm-dialog',
9331 - modal: true,
9332 - autoOpen: false,
9333 - closeOnEscape: true,
9334 - width: width,
9335 - resizable: false,
9336 - draggable: false,
9337 - open: function() {
9338 - jQuery( '.ui-dialog-titlebar' ).addClass( 'frm_hidden' ).removeClass( 'ui-helper-clearfix' );
9339 - jQuery( '#wpwrap' ).addClass( 'frm_overlay' );
9340 - jQuery( '.frm-dialog' ).removeClass( 'ui-widget ui-widget-content ui-corner-all' );
9341 - $info.removeClass( 'ui-dialog-content ui-widget-content' );
9342 - bindClickForDialogClose( $info );
9343 - },
9344 - close: function() {
9345 - jQuery( '#wpwrap' ).removeClass( 'frm_overlay' );
9346 - jQuery( '.spinner' ).css( 'visibility', 'hidden' );
9347 -
9348 - this.removeAttribute( 'data-option-type' );
9349 - const optionType = document.getElementById( 'bulk-option-type' );
9350 - if ( optionType ) {
9351 - optionType.value = '';
9352 - }
9353 - }
9354 - };
9355 -
9356 - $info.dialog( dialogArgs );
9357 -
9358 - return $info;
9359 - }
9360 -
9361 - function toggle( cname, id ) {
9362 - if ( id === '#' ) {
9363 - var cont = document.getElementById( cname );
9364 - var hidden = cont.style.display;
9365 - if ( hidden === 'none' ) {
9366 - cont.style.display = 'block';
9367 - } else {
9368 - cont.style.display = 'none';
9369 - }
9370 - } else {
9371 - var vis = cname.is( ':visible' );
9372 - if ( vis ) {
9373 - cname.hide();
9374 - } else {
9375 - cname.show();
9376 - }
9377 - }
9378 - }
9379 -
9380 - function removeWPUnload() {
9381 - window.onbeforeunload = null;
9382 - var w = jQuery( window );
9383 - w.off( 'beforeunload.widgets' );
9384 - w.off( 'beforeunload.edit-post' );
9385 - }
9386 -
9387 - function addMultiselectLabelListener() {
9388 - const clickListener = ( e ) => {
9389 - if ( 'LABEL' !== e.target.nodeName ) {
9390 - return;
9391 - }
9392 -
9393 - const labelFor = e.target.getAttribute( 'for' );
9394 - if ( ! labelFor ) {
9395 - return;
9396 - }
9397 -
9398 - const input = document.getElementById( labelFor );
9399 - if ( ! input || ! input.nextElementSibling ) {
9400 - return;
9401 - }
9402 -
9403 - const buttonToggle = input.nextElementSibling.querySelector( 'button.dropdown-toggle.multiselect' );
9404 - if ( ! buttonToggle ) {
9405 - return;
9406 - }
9407 -
9408 - const triggerMultiselectClick = () => buttonToggle.click();
9409 - setTimeout( triggerMultiselectClick, 0 );
9410 - };
9411 - document.addEventListener( 'click', clickListener );
9412 - }
9413 -
9414 - function maybeChangeEmbedFormMsg() {
9415 - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
9416 - var fieldItem = document.getElementById( 'frm_field_id_' + fieldId );
9417 - if ( null === fieldItem || 'form' !== fieldItem.dataset.type ) {
9418 - return;
9419 - }
9420 -
9421 - fieldItem = jQuery( fieldItem );
9422 -
9423 - if ( this.options[ this.selectedIndex ].value ) {
9424 - fieldItem.find( '.frm-not-set' )[0].classList.add( 'frm_hidden' );
9425 - var embedMsg = fieldItem.find( '.frm-embed-message' );
9426 - embedMsg.html( embedMsg.data( 'embedmsg' ) + this.options[ this.selectedIndex ].text );
9427 - fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.remove( 'frm_hidden' );
9428 - } else {
9429 - fieldItem.find( '.frm-not-set' )[0].classList.remove( 'frm_hidden' );
9430 - fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.add( 'frm_hidden' );
9431 - }
9432 - }
9433 -
9434 - function toggleProductType() {
9435 - var settings = jQuery( this ).closest( '.frm-single-settings' ),
9436 - container = settings.find( '.frmjs_product_choices' ),
9437 - heading = settings.find( '.frm_prod_options_heading' ),
9438 - currentVal = this.options[ this.selectedIndex ].value;
9439 -
9440 - container.removeClass( 'frm_prod_type_single frm_prod_type_user_def' );
9441 - heading.removeClass( 'frm_prod_user_def' );
9442 -
9443 - if ( 'single' === currentVal ) {
9444 - container.addClass( 'frm_prod_type_single' );
9445 - } else if ( 'user_def' === currentVal ) {
9446 - container.addClass( 'frm_prod_type_user_def' );
9447 - heading.addClass( 'frm_prod_user_def' );
9448 - }
9449 - }
9450 -
9451 - function isProductField( fieldId ) {
9452 - var field = document.getElementById( 'frm_field_id_' + fieldId );
9453 - if ( field === null ) {
9454 - return false;
9455 - } else {
9456 - return 'product' === field.getAttribute( 'data-type' );
9457 - }
9458 - }
9459 -
9460 - /**
9461 - * Serialize form data with vanilla JS.
9462 - */
9463 - function formToData( form ) {
9464 - var subKey, i,
9465 - object = {},
9466 - formData = form.elements;
9467 -
9468 - for ( i = 0; i < formData.length; i++ ) {
9469 - var input = formData[i],
9470 - key = input.name,
9471 - value = input.value,
9472 - names = key.match( /(.*)\[(.*)\]/ );
9473 -
9474 - if ( ( input.type === 'radio' || input.type === 'checkbox' ) && ! input.checked ) {
9475 - continue;
9476 - }
9477 -
9478 - if ( names !== null ) {
9479 - key = names[1];
9480 - subKey = names[2];
9481 - if ( ! Reflect.has( object, key ) ) {
9482 - object[key] = {};
9483 - }
9484 - object[key][subKey] = value;
9485 - continue;
9486 - }
9487 -
9488 - // Reflect.has in favor of: object.hasOwnProperty(key)
9489 - if ( ! Reflect.has( object, key ) ) {
9490 - object[key] = value;
9491 - continue;
9492 - }
9493 - if ( ! Array.isArray( object[key]) ) {
9494 - object[key] = [ object[key] ];
9495 - }
9496 - object[key].push( value );
9497 - }
9498 -
9499 - return object;
9500 - }
9501 -
9502 - /**
9503 - * Show, hide, and sort subfields of Name field on form builder.
9504 - *
9505 - * @since 4.11
9506 - */
9507 - function handleNameFieldOnFormBuilder() {
9508 - /**
9509 - * Gets subfield element from cache.
9510 - *
9511 - * @param {String} fieldId Field ID.
9512 - * @param {String} key Cache key.
9513 - * @returns {HTMLElement|undefined} Return the element from cache or undefined if not found.
9514 - */
9515 - const getSubFieldElFromCache = ( fieldId, key ) => {
9516 - window.frmCachedSubFields = window.frmCachedSubFields || {};
9517 - window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {};
9518 - return window.frmCachedSubFields[fieldId][key];
9519 - };
9520 -
9521 - /**
9522 - * Sets subfield element to cache.
9523 - *
9524 - * @param {String} fieldId Field ID.
9525 - * @param {String} key Cache key.
9526 - * @param {HTMLElement} el Element.
9527 - */
9528 - const setSubFieldElToCache = ( fieldId, key, el ) => {
9529 - window.frmCachedSubFields = window.frmCachedSubFields || {};
9530 - window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {};
9531 - window.frmCachedSubFields[fieldId][key] = el;
9532 - };
9533 -
9534 - /**
9535 - * Gets column class from the number of columns.
9536 - *
9537 - * @param {Number} colCount Number of columns.
9538 - * @returns {string}
9539 - */
9540 - const getColClass = colCount => 'frm' + parseInt( 12 / colCount );
9541 -
9542 - const colClasses = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ].map( num => 'frm' + num );
9543 -
9544 - const allSubFieldNames = [ 'first', 'middle', 'last' ];
9545 -
9546 - /**
9547 - * Handles name layout change.
9548 - *
9549 - * @param {Event} event Event object.
9550 - */
9551 - const onChangeLayout = event => {
9552 - const value = event.target.value;
9553 - const subFieldNames = value.split( '_' );
9554 - const fieldId = event.target.dataset.fieldId;
9555 -
9556 - /*
9557 - * Live update form on the form builder.
9558 - */
9559 - const container = document.querySelector( '#field_' + fieldId + '_inner_container .frm_combo_inputs_container' );
9560 - const newColClass = getColClass( subFieldNames.length );
9561 -
9562 - // Set all sub field elements to cache and hide all of them first.
9563 - allSubFieldNames.forEach( name => {
9564 - const subFieldEl = container.querySelector( '[data-sub-field-name="' + name + '"]' );
9565 - if ( subFieldEl ) {
9566 - subFieldEl.classList.add( 'frm_hidden' );
9567 - subFieldEl.classList.remove( ...colClasses );
9568 - setSubFieldElToCache( fieldId, name, subFieldEl );
9569 - }
9570 - });
9571 -
9572 - subFieldNames.forEach( subFieldName => {
9573 - const subFieldEl = getSubFieldElFromCache( fieldId, subFieldName );
9574 - if ( ! subFieldEl ) {
9575 - return;
9576 - }
9577 -
9578 - subFieldEl.classList.remove( 'frm_hidden' );
9579 - subFieldEl.classList.add( newColClass );
9580 -
9581 - container.append( subFieldEl );
9582 - });
9583 -
9584 - /*
9585 - * Live update subfield options.
9586 - */
9587 - // Hide all subfield options.
9588 - allSubFieldNames.forEach( name => {
9589 - const optionsEl = document.querySelector( '.frm_sub_field_options-' + name + '[data-field-id="' + fieldId + '"]' );
9590 - if ( optionsEl ) {
9591 - optionsEl.classList.add( 'frm_hidden' );
9592 - setSubFieldElToCache( fieldId, name + '_options', optionsEl );
9593 - }
9594 - });
9595 -
9596 - subFieldNames.forEach( subFieldName => {
9597 - const optionsEl = getSubFieldElFromCache( fieldId, subFieldName + '_options' );
9598 - if ( ! optionsEl ) {
9599 - return;
9600 - }
9601 - optionsEl.classList.remove( 'frm_hidden' );
9602 - });
9603 - };
9604 -
9605 - const dropdownSelector = '.frm_name_layout_dropdown';
9606 - document.addEventListener( 'change', event => {
9607 - if ( event.target.matches( dropdownSelector ) ) {
9608 - onChangeLayout( event );
9609 - }
9610 - }, false );
9611 - }
9612 -
9613 - function debounce( func, wait = 100 ) {
9614 - return frmDom.util.debounce( func, wait );
9615 - }
9616 -
9617 - function addSaveAndDragIconsToOption( fieldId, liObject ) {
9618 - let li, useTag, useTagHref;
9619 - let hasDragIcon = false;
9620 - let hasSaveIcon = false;
9621 -
9622 - if ( liObject.newOption ) {
9623 - const parser = new DOMParser();
9624 - li = parser.parseFromString( liObject.newOption, 'text/html' ).body.childNodes[0];
9625 - } else {
9626 - li = liObject;
9627 - }
9628 -
9629 - const liIcons = li.querySelectorAll( 'svg' );
9630 -
9631 - liIcons.forEach( ( svg, key ) => {
9632 - useTag = svg.getElementsByTagNameNS( 'http://www.w3.org/2000/svg', 'use' )[0];
9633 - if ( ! useTag ) {
9634 - return;
9635 - }
9636 - useTagHref = useTag.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) || useTag.getAttribute( 'href' );
9637 -
9638 - if ( useTagHref === '#frm_drag_icon' ) {
9639 - hasDragIcon = true;
9640 - }
9641 -
9642 - if ( useTagHref === '#frm_save_icon' ) {
9643 - hasSaveIcon = true;
9644 - }
9645 - });
9646 -
9647 - if ( ! hasDragIcon ) {
9648 - li.prepend( icons.drag.cloneNode( true ) );
9649 - }
9650 -
9651 - if ( li.querySelector( `[id^=field_key_${fieldId}-]` ) && ! hasSaveIcon ) {
9652 - li.querySelector( `[id^=field_key_${fieldId}-]` ).after( icons.save.cloneNode( true ) );
9653 - }
9654 -
9655 - if ( liObject.newOption ) {
9656 - liObject.newOption = li;
9657 - }
9658 - }
9659 -
9660 - function maybeAddSaveAndDragIcons( fieldId ) {
9661 - fieldOptions = document.querySelectorAll( `[id^=frm_delete_field_${fieldId}-]` );
9662 - // return if there are no options.
9663 - if ( fieldOptions.length < 2 ) {
9664 - return;
9665 - }
9666 -
9667 - let options = [ ...fieldOptions ].slice( 1 );
9668 - options.forEach( ( li, _key ) => {
9669 - if ( li.classList.contains( 'frm_other_option' ) ) {
9670 - return;
9671 - }
9672 - addSaveAndDragIconsToOption( fieldId, li );
9673 - });
9674 - }
9675 -
9676 - function initOnSubmitAction() {
9677 - const onChangeType = event => {
9678 - if ( ! event.target.checked ) {
9679 - return;
9680 - }
9681 -
9682 - const actionEl = event.target.closest( '.frm_form_action_settings' );
9683 - actionEl.querySelectorAll( '.frm_on_submit_dependent_setting:not(.frm_hidden)' ).forEach( el => {
9684 - el.classList.add( 'frm_hidden' );
9685 - });
9686 -
9687 - const activeEls = actionEl.querySelectorAll( '.frm_on_submit_dependent_setting[data-show-if-' + event.target.value + ']' );
9688 - activeEls.forEach( activeEl => {
9689 - activeEl.classList.remove( 'frm_hidden' );
9690 - });
9691 -
9692 - actionEl.setAttribute( 'data-on-submit-type', event.target.value );
9693 - };
9694 -
9695 - frmDom.util.documentOn( 'change', '.frm_on_submit_type input[type="radio"]', onChangeType );
9696 - }
9697 -
9698 - return {
9699 - init: function() {
9700 - s = {};
9701 -
9702 - // Bootstrap dropdown button
9703 - jQuery( '.wp-admin' ).on( 'click', function( e ) {
9704 - var t = jQuery( e.target );
9705 - var $openDrop = jQuery( '.dropdown.open' );
9706 - if ( $openDrop.length && ! t.hasClass( 'dropdown' ) && ! t.closest( '.dropdown' ).length ) {
9707 - $openDrop.removeClass( 'open' );
9708 - }
9709 - });
9710 - jQuery( '#frm_bs_dropdown:not(.open) a' ).on( 'click', focusSearchBox );
9711 -
9712 - if ( typeof thisFormId === 'undefined' ) {
9713 - thisFormId = jQuery( document.getElementById( 'form_id' ) ).val();
9714 - }
9715 -
9716 - // Add event listener for dismissible warning messages.
9717 - document.querySelectorAll( '.frm-warning-dismiss' ).forEach( ( dismissIcon ) => {
9718 - onClickPreventDefault( dismissIcon, dismissWarningMessage );
9719 - });
9720 -
9721 - frmAdminBuild.inboxBannerInit();
9722 -
9723 - if ( $newFields.length > 0 ) {
9724 - // only load this on the form builder page
9725 - frmAdminBuild.buildInit();
9726 - } else if ( document.getElementById( 'frm_notification_settings' ) !== null ) {
9727 - // only load on form settings page
9728 - frmAdminBuild.settingsInit();
9729 - } else if ( document.getElementById( 'frm_styling_form' ) !== null ) {
9730 - // load styling settings js
9731 - frmAdminBuild.styleInit();
9732 - } else if ( document.getElementById( 'form_global_settings' ) !== null ) {
9733 - // global settings page
9734 - frmAdminBuild.globalSettingsInit();
9735 - } else if ( document.getElementById( 'frm_export_xml' ) !== null ) {
9736 - // import/export page
9737 - frmAdminBuild.exportInit();
9738 - } else if ( document.getElementById( 'frm_dyncontent' ) !== null ) {
9739 - // only load on views settings page
9740 - frmAdminBuild.viewInit();
9741 - } else if ( document.getElementById( 'frm_inbox_page' ) !== null ) {
9742 - // Inbox page
9743 - frmAdminBuild.inboxInit();
9744 - } else if ( document.getElementById( 'frm-welcome' ) !== null ) {
9745 - // Solution install page
9746 - frmAdminBuild.solutionInit();
9747 - } else {
9748 - // New form selection page
9749 - initNewFormModal();
9750 - initSelectionAutocomplete();
9751 -
9752 - jQuery( '[data-frmprint]' ).on( 'click', function() {
9753 - window.print();
9754 - return false;
9755 - });
9756 - }
9757 -
9758 - var $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) );
9759 - if ( $advInfo.length > 0 || jQuery( '.frm_field_list' ).length > 0 ) {
9760 - // only load on the form, form settings, and view settings pages
9761 - frmAdminBuild.panelInit();
9762 - }
9763 -
9764 - loadTooltips();
9765 - initUpgradeModal();
9766 -
9767 - // used on build, form settings, and view settings
9768 - var $shortCodeDiv = jQuery( document.getElementById( 'frm_shortcodediv' ) );
9769 - if ( $shortCodeDiv.length > 0 ) {
9770 - jQuery( 'a.edit-frm_shortcode' ).on( 'click', function() {
9771 - if ( $shortCodeDiv.is( ':hidden' ) ) {
9772 - $shortCodeDiv.slideDown( 'fast' );
9773 - this.style.display = 'none';
9774 - }
9775 - return false;
9776 - });
9777 -
9778 - jQuery( '.cancel-frm_shortcode', '#frm_shortcodediv' ).on( 'click', function() {
9779 - $shortCodeDiv.slideUp( 'fast' );
9780 - $shortCodeDiv.siblings( 'a.edit-frm_shortcode' ).show();
9781 - return false;
9782 - });
9783 - }
9784 -
9785 - // tabs
9786 - jQuery( document ).on( 'click', '#frm-nav-tabs a', clickNewTab );
9787 - jQuery( '.post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a' ).on( 'click', function() {
9788 - const showUpgradeTab = this.classList.contains( 'frm_show_upgrade_tab' );
9789 - if ( this.classList.contains( 'frm_noallow' ) && ! showUpgradeTab ) {
9790 - return;
9791 - }
9792 -
9793 - if ( showUpgradeTab ) {
9794 - populateUpgradeTab( this );
9795 - }
9796 -
9797 - clickTab( this );
9798 - return false;
9799 - });
9800 - clickTab( jQuery( '.starttab a' ), 'auto' );
9801 -
9802 - // submit the search form with dropdown
9803 - jQuery( document ).on( 'click', '#frm-fid-search-menu a', function() {
9804 - var val = this.id.replace( 'fid-', '' );
9805 - jQuery( 'select[name="fid"]' ).val( val );
9806 - triggerSubmit( document.getElementById( 'posts-filter' ) );
9807 - return false;
9808 - });
9809 -
9810 - jQuery( '.frm_select_box' ).on( 'click focus', function() {
9811 - this.select();
9812 - });
9813 -
9814 - jQuery( document ).on( 'input search change', '.frm-auto-search:not(#frm_new_form_modal #template-search-input)', searchContent );
9815 - jQuery( document ).on( 'focusin click', '.frm-auto-search', stopPropagation );
9816 - var autoSearch = jQuery( '.frm-auto-search' );
9817 - if ( autoSearch.val() !== '' ) {
9818 - autoSearch.trigger( 'keyup' );
9819 - }
9820 -
9821 - // Initialize Formidable Connection.
9822 - FrmFormsConnect.init();
9823 -
9824 - jQuery( document ).on( 'click', '.frm-install-addon', installAddon );
9825 - jQuery( document ).on( 'click', '.frm-activate-addon', activateAddon );
9826 - jQuery( document ).on( 'click', '.frm-solution-multiple', installMultipleAddons );
9827 -
9828 - // prevent annoying confirmation message from WordPress
9829 - jQuery( 'button, input[type=submit]' ).on( 'click', removeWPUnload );
9830 -
9831 - addMultiselectLabelListener();
9832 -
9833 - frmAdminBuild.hooks.addFilter(
9834 - 'frm_before_embed_modal',
9835 - ( ids, { element, type }) => {
9836 - if ( 'form' !== type ) {
9837 - return ids;
9838 - }
9839 -
9840 - let formId, formKey;
9841 - const row = element.closest( 'tr' );
9842 -
9843 - if ( row ) {
9844 - // Embed icon on form index.
9845 - formId = parseInt( row.querySelector( '.column-id' ).textContent );
9846 - formKey = row.querySelector( '.column-form_key' ).textContent;
9847 - } else {
9848 - // Embed button in form builder / form settings.
9849 - formId = document.getElementById( 'form_id' ).value;
9850 -
9851 - const formKeyInput = document.getElementById( 'frm_form_key' );
9852 - if ( formKeyInput ) {
9853 - formKey = formKeyInput.value;
9854 - } else {
9855 - const previewDrop = document.getElementById( 'frm-previewDrop' );
9856 - if ( previewDrop ) {
9857 - formKey = previewDrop.nextElementSibling.querySelector( '.dropdown-item a' ).getAttribute( 'href' ).split( 'form=' )[1];
9858 - }
9859 - }
9860 - }
9861 -
9862 - return [ formId, formKey ];
9863 - }
9864 - );
9865 -
9866 - document.querySelectorAll( '#frm-show-fields > li, .frm_grid_container li' ).forEach( ( el, _key ) => {
9867 - el.addEventListener( 'click', function() {
9868 - let fieldId = this.querySelector( 'li' )?.dataset.fid || this.dataset.fid;
9869 - maybeAddSaveAndDragIcons( fieldId );
9870 - });
9871 - });
9872 - },
9873 -
9874 - buildInit: function() {
9875 - let loadFieldId, $builderForm, builderArea;
9876 -
9877 - debouncedSyncAfterDragAndDrop = debounce( syncAfterDragAndDrop, 10 );
9878 - postBodyContent = document.getElementById( 'post-body-content' );
9879 - $postBodyContent = jQuery( postBodyContent );
9880 -
9881 - if ( jQuery( '.frm_field_loading' ).length ) {
9882 - loadFieldId = jQuery( '.frm_field_loading' ).first().attr( 'id' );
9883 - loadFields( loadFieldId );
9884 - }
9885 -
9886 - setupSortable( 'ul.frm_sorting' );
9887 -
9888 - document.querySelectorAll( '.field_type_list > li:not(.frm_show_upgrade)' ).forEach( makeDraggable );
9889 -
9890 - jQuery( 'ul.field_type_list, .field_type_list li, ul.frm_code_list, .frm_code_list li, .frm_code_list li a, #frm_adv_info #category-tabs li, #frm_adv_info #category-tabs li a' ).disableSelection();
9891 -
9892 - jQuery( '.frm_submit_ajax' ).on( 'click', submitBuild );
9893 - jQuery( '.frm_submit_no_ajax' ).on( 'click', submitNoAjax );
9894 -
9895 - jQuery( 'a.edit-form-status' ).on( 'click', slideDown );
9896 - jQuery( '.cancel-form-status' ).on( 'click', slideUp );
9897 - jQuery( '.save-form-status' ).on( 'click', function() {
9898 - const newStatus = jQuery( document.getElementById( 'form_change_status' ) ).val();
9899 - jQuery( 'input[name="new_status"]' ).val( newStatus );
9900 - jQuery( document.getElementById( 'form-status-display' ) ).html( newStatus );
9901 - jQuery( '.cancel-form-status' ).trigger( 'click' );
9902 - return false;
9903 - });
9904 -
9905 - jQuery( '.frm_form_builder form' ).first().on( 'submit', function() {
9906 - jQuery( '.inplace_field' ).trigger( 'blur' );
9907 - });
9908 -
9909 - initiateMultiselect();
9910 - renumberPageBreaks();
9911 -
9912 - $builderForm = jQuery( builderForm );
9913 - builderArea = document.getElementById( 'frm_form_editor_container' );
9914 - $builderForm.on( 'click', '.frm_add_logic_row', addFieldLogicRow );
9915 - $builderForm.on( 'click', '.frm_add_watch_lookup_row', addWatchLookupRow );
9916 - $builderForm.on( 'change', '.frm_get_values_form', updateGetValueFieldSelection );
9917 - $builderForm.on( 'change', '.frm_logic_field_opts', getFieldValues );
9918 - $builderForm.on( 'change', '.radio_maxnum', setStarValues );
9919 - $builderForm.on( 'frm-multiselect-changed', 'select[name^="field_options[admin_only_"]', adjustVisibilityValuesForEveryoneValues );
9920 -
9921 - jQuery( document.getElementById( 'frm-insert-fields' ) ).on( 'click', '.frm_add_field', addFieldClick );
9922 - $newFields.on( 'click', '.frm_clone_field', duplicateField );
9923 - $builderForm.on( 'blur', 'input[id^="frm_calc"]', checkCalculationCreatedByUser );
9924 - $builderForm.on( 'change', 'input.frm_format_opt, input.frm_max_length_opt', toggleInvalidMsg );
9925 - $builderForm.on( 'change click', '[data-changeme]', liveChanges );
9926 - $builderForm.on( 'click', 'input.frm_req_field', markRequired );
9927 - $builderForm.on( 'click', '.frm_mark_unique', markUnique );
9928 -
9929 - $builderForm.on( 'change', '.frm_repeat_format', toggleRepeatButtons );
9930 - $builderForm.on( 'change', '.frm_repeat_limit', checkRepeatLimit );
9931 - $builderForm.on( 'change', '.frm_js_checkbox_limit', checkCheckboxSelectionsLimit );
9932 - $builderForm.on( 'input', 'input[name^="field_options[add_label_"]', function() {
9933 - updateRepeatText( this, 'add' );
9934 - });
9935 - $builderForm.on( 'input', 'input[name^="field_options[remove_label_"]', function() {
9936 - updateRepeatText( this, 'remove' );
9937 - });
9938 - $builderForm.on( 'change', 'select[name^="field_options[data_type_"]', maybeClearWatchFields );
9939 - jQuery( builderArea ).on( 'click', '.frm-collapse-page', maybeCollapsePage );
9940 - jQuery( builderArea ).on( 'click', '.frm-collapse-section', maybeCollapseSection );
9941 - $builderForm.on( 'click', '.frm-single-settings h3', maybeCollapseSettings );
9942 -
9943 - jQuery( builderArea ).on( 'show.bs.dropdown hide.bs.dropdown', changeSectionStyle );
9944 -
9945 - $builderForm.on( 'click', '.frm_toggle_sep_values', toggleSepValues );
9946 - $builderForm.on( 'click', '.frm_toggle_image_options', toggleImageOptions );
9947 - $builderForm.on( 'click', '.frm_remove_image_option', removeImageFromOption );
9948 - $builderForm.on( 'click', '.frm_choose_image_box', addImageToOption );
9949 - $builderForm.on( 'change', '.frm_hide_image_text', refreshOptionDisplay );
9950 - $builderForm.on( 'change', '.frm_field_options_image_size', setImageSize );
9951 - $builderForm.on( 'click', '.frm_multiselect_opt', toggleMultiselect );
9952 - $newFields.on( 'mousedown', 'input, textarea, select', stopFieldFocus );
9953 - $newFields.on( 'click', 'input[type=radio], input[type=checkbox]', stopFieldFocus );
9954 - $newFields.on( 'click', '.frm_delete_field', clickDeleteField );
9955 - $newFields.on( 'click', '.frm_select_field', clickSelectField );
9956 - jQuery( document ).on( 'click', '.frm_delete_field_group', clickDeleteFieldGroup );
9957 - jQuery( document ).on( 'click', '.frm_clone_field_group', duplicateFieldGroup );
9958 - jQuery( document ).on( 'click', '#frm_field_group_controls > span:first-child', clickFieldGroupLayout );
9959 - jQuery( document ).on( 'click', '.frm-row-layout-option', handleFieldGroupLayoutOptionClick );
9960 - jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-row-layout-option', handleFieldGroupLayoutOptionInsideMergeClick );
9961 - jQuery( document ).on( 'click', '.frm-custom-field-group-layout', customFieldGroupLayoutClick );
9962 - jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-custom-field-group-layout', customFieldGroupLayoutInsideMergeClick );
9963 - jQuery( document ).on( 'click', '.frm-break-field-group', breakFieldGroupClick );
9964 - $newFields.on( 'click', '#frm_field_group_popup .frm_grid_container input', focusFieldGroupInputOnClick );
9965 - jQuery( document ).on( 'click', '.frm-cancel-custom-field-group-layout', cancelCustomFieldGroupClick );
9966 - jQuery( document ).on( 'click', '.frm-save-custom-field-group-layout', saveCustomFieldGroupClick );
9967 - $newFields.on( 'click', 'ul.frm_sorting', fieldGroupClick );
9968 - jQuery( document ).on( 'click', '.frm-merge-fields-into-row', mergeFieldsIntoRowClick );
9969 - jQuery( document ).on( 'click', '.frm-delete-field-groups', deleteFieldGroupsClick );
9970 - $newFields.on( 'click', '.frm-field-action-icons [data-toggle="dropdown"]', function() {
9971 - this.closest( 'li.form-field' ).classList.add( 'frm-field-settings-open' );
9972 - jQuery( document ).on( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings );
9973 - });
9974 - $newFields.on( 'mousemove', 'ul.frm_sorting', checkForMultiselectKeysOnMouseMove );
9975 - $newFields.on( 'show.bs.dropdown', '.frm-field-action-icons', onFieldActionDropdownShow );
9976 - jQuery( document ).on( 'show.bs.dropdown', '#frm_field_group_controls', onFieldGroupActionDropdownShow );
9977 - $builderForm.on( 'click', '.frm_single_option a[data-removeid]', deleteFieldOption );
9978 - $builderForm.on( 'mousedown', '.frm_single_option input[type=radio]', maybeUncheckRadio );
9979 - $builderForm.on( 'focusin', '.frm_single_option input[type=text]', maybeClearOptText );
9980 - $builderForm.on( 'click', '.frm_add_opt', addFieldOption );
9981 - $builderForm.on( 'change', '.frm_single_option input', resetOptOnChange );
9982 - $builderForm.on( 'change', '.frm_image_id', resetOptOnChange );
9983 - $builderForm.on( 'change', '.frm_toggle_mult_sel', toggleMultSel );
9984 - $builderForm.on( 'focusin', '.frm_classes', showBuilderModal );
9985 -
9986 - $newFields.on( 'click', '.frm_primary_label', clickLabel );
9987 - $newFields.on( 'click', '.frm_description', clickDescription );
9988 - $newFields.on( 'click', 'li.ui-state-default', clickVis );
9989 - $newFields.on( 'dblclick', 'li.ui-state-default', openAdvanced );
9990 - $builderForm.on( 'change', '.frm_tax_form_select', toggleFormTax );
9991 - $builderForm.on( 'change', 'select.conf_field', addConf );
9992 -
9993 - $builderForm.on( 'change', '.frm_get_field_selection', getFieldSelection );
9994 -
9995 - $builderForm.on( 'click', '.frm-show-inline-modal', maybeShowInlineModal );
9996 -
9997 - $builderForm.on( 'click', '.frm-inline-modal .dismiss', dismissInlineModal );
9998 - jQuery( document ).on( 'change', '[data-frmchange]', changeInputtedValue );
9999 -
10000 - $builderForm.on( 'change', '.frm_include_extras_field', rePopCalcFieldsForSummary );
10001 - $builderForm.on( 'change', 'select[name^="field_options[form_select_"]', maybeChangeEmbedFormMsg );
10002 -
10003 - jQuery( document ).on( 'submit', '#frm_js_build_form', buildSubmittedNoAjax );
10004 - jQuery( document ).on( 'change', '#frm_builder_page input:not(.frm-search-input):not(.frm-custom-grid-size-input), #frm_builder_page select, #frm_builder_page textarea', fieldUpdated );
10005 -
10006 - popAllProductFields();
10007 -
10008 - jQuery( document ).on( 'change', '.frmjs_prod_data_type_opt', toggleProductType );
10009 -
10010 - jQuery( document ).on( 'focus', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextFocus );
10011 - jQuery( document ).on( 'blur', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextBlur );
10012 -
10013 - initBulkOptionsOverlay();
10014 - hideEmptyEle();
10015 - maybeHideQuantityProductFieldOption();
10016 - handleNameFieldOnFormBuilder();
10017 - toggleSectionHolder();
10018 - handleShowPasswordLiveUpdate();
10019 - },
10020 -
10021 - settingsInit: function() {
10022 - const $formActions = jQuery( document.getElementById( 'frm_notification_settings' ) );
10023 -
10024 - let formSettings, $loggedIn, $cookieExp, $editable;
10025 -
10026 - // BCC, CC, and Reply To button functionality
10027 - $formActions.on( 'click', '.frm_email_buttons', showEmailRow );
10028 - $formActions.on( 'click', '.frm_remove_field', hideEmailRow );
10029 - $formActions.on( 'change', '.frm_to_row, .frm_from_row', showEmailWarning );
10030 - $formActions.on( 'change', '.frm_tax_selector', changePosttaxRow );
10031 - $formActions.on( 'change', 'select.frm_single_post_field', checkDupPost );
10032 - $formActions.on( 'change', 'select.frm_toggle_post_content', togglePostContent );
10033 - $formActions.on( 'change', 'select.frm_dyncontent_opt', fillDyncontent );
10034 - $formActions.on( 'change', '.frm_post_type', switchPostType );
10035 - $formActions.on( 'click', '.frm_add_postmeta_row', addPostmetaRow );
10036 - $formActions.on( 'click', '.frm_add_posttax_row', addPosttaxRow );
10037 - $formActions.on( 'click', '.frm_toggle_cf_opts', toggleCfOpts );
10038 - $formActions.on( 'click', '.frm_duplicate_form_action', copyFormAction );
10039 - jQuery( document ).on( 'change', 'select[data-toggleclass], input[data-toggleclass]', toggleFormOpts );
10040 - jQuery( '.frm_actions_list' ).on( 'click', '.frm_active_action', addFormAction );
10041 - jQuery( '#frm-show-groups, #frm-hide-groups' ).on( 'click', toggleActionGroups );
10042 - initiateMultiselect();
10043 -
10044 - //set actions icons to inactive
10045 - jQuery( 'ul.frm_actions_list li' ).each( function() {
10046 - checkActiveAction( jQuery( this ).children( 'a' ).data( 'actiontype' ) );
10047 -
10048 - // If the icon is a background image, don't add BG color.
10049 - const icon = jQuery( this ).find( 'i' );
10050 - if ( icon.css( 'background-image' ) !== 'none' ) {
10051 - icon.addClass( 'frm-inverse' );
10052 - }
10053 - });
10054 -
10055 - jQuery( '.frm_submit_settings_btn' ).on( 'click', submitSettings );
10056 -
10057 - formSettings = jQuery( '.frm_form_settings' );
10058 - formSettings.on( 'click', '.frm_add_form_logic', addFormLogicRow );
10059 - formSettings.on( 'blur', '.frm_email_blur', formatEmailSetting );
10060 - formSettings.on( 'click', '.frm_already_used', onlyOneActionMessage );
10061 -
10062 - formSettings.on( 'change', '#logic_link_submit', toggleSubmitLogic );
10063 - formSettings.on( 'click', '.frm_add_submit_logic', addSubmitLogic );
10064 - formSettings.on( 'change', '.frm_submit_logic_field_opts', addSubmitLogicOpts );
10065 -
10066 - document.addEventListener(
10067 - 'click',
10068 - function handleImageUploadClickEvents( event ) {
10069 - const { target } = event;
10070 -
10071 - if ( ! target.closest( '.frm_image_preview_wrapper' ) ) {
10072 - return;
10073 - }
10074 -
10075 - if ( target.closest( '.frm_choose_image_box' ) ) {
10076 - addImageToOption.bind( target )( event );
10077 - return;
10078 - }
10079 -
10080 - if ( target.closest( '.frm_remove_image_option' ) ) {
10081 - removeImageFromOption.bind( target )( event );
10082 - }
10083 - }
10084 - );
10085 -
10086 - // Close shortcode modal on click.
10087 - formSettings.on( 'mouseup', '*:not(.frm-show-box)', function( e ) {
10088 - e.stopPropagation();
10089 -
10090 - if ( e.target.classList.contains( 'frm-show-box' ) || e.target.parentElement.classList.contains( 'frm-show-box' ) ) {
10091 - return;
10092 - }
10093 -
10094 - const sidebar = document.getElementById( 'frm_adv_info' );
10095 - if ( ! sidebar ) {
10096 - return;
10097 - }
10098 -
10099 - if ( sidebar.getAttribute( 'data-fills' ) === e.target.id && typeof e.target.id !== 'undefined' ) {
10100 - return;
10101 - }
10102 -
10103 - const isChild = jQuery( e.target ).closest( '#frm_adv_info' ).length > 0;
10104 -
10105 - if ( ! isChild && sidebar.display !== 'none' ) {
10106 - hideShortcodes( sidebar );
10107 - }
10108 - });
10109 -
10110 - //Warning when user selects "Do not store entries ..."
10111 - jQuery( document.getElementById( 'no_save' ) ).on( 'change', function() {
10112 - if ( this.checked ) {
10113 - if ( confirm( frm_admin_js.no_save_warning ) !== true ) { // eslint-disable-line camelcase
10114 - // Uncheck box if user hits "Cancel"
10115 - jQuery( this ).attr( 'checked', false );
10116 - }
10117 - }
10118 - });
10119 -
10120 - jQuery( 'select[name="options[edit_action]"]' ).on( 'change', showSuccessOpt );
10121 -
10122 - $loggedIn = document.getElementById( 'logged_in' );
10123 - jQuery( $loggedIn ).on( 'change', function() {
10124 - if ( this.checked ) {
10125 - visible( '.hide_logged_in' );
10126 - } else {
10127 - invisible( '.hide_logged_in' );
10128 - }
10129 - });
10130 -
10131 - $cookieExp = jQuery( document.getElementById( 'frm_cookie_expiration' ) );
10132 - jQuery( document.getElementById( 'frm_single_entry_type' ) ).on( 'change', function() {
10133 - if ( this.value === 'cookie' ) {
10134 - $cookieExp.fadeIn( 'slow' );
10135 - } else {
10136 - $cookieExp.fadeOut( 'slow' );
10137 - }
10138 - });
10139 -
10140 - var $singleEntry = document.getElementById( 'single_entry' );
10141 - jQuery( $singleEntry ).on( 'change', function() {
10142 - if ( this.checked ) {
10143 - visible( '.hide_single_entry' );
10144 - } else {
10145 - invisible( '.hide_single_entry' );
10146 - }
10147 -
10148 - if ( this.checked && jQuery( document.getElementById( 'frm_single_entry_type' ) ).val() === 'cookie' ) {
10149 - $cookieExp.fadeIn( 'slow' );
10150 - } else {
10151 - $cookieExp.fadeOut( 'slow' );
10152 - }
10153 - });
10154 -
10155 - jQuery( '.hide_save_draft' ).hide();
10156 -
10157 - var $saveDraft = jQuery( document.getElementById( 'save_draft' ) );
10158 - $saveDraft.on( 'change', function() {
10159 - if ( this.checked ) {
10160 - jQuery( '.hide_save_draft' ).fadeIn( 'slow' );
10161 - } else {
10162 - jQuery( '.hide_save_draft' ).fadeOut( 'slow' );
10163 - }
10164 - });
10165 - triggerChange( $saveDraft );
10166 -
10167 - //If Allow editing is checked/unchecked
10168 - $editable = document.getElementById( 'editable' );
10169 - jQuery( $editable ).on( 'change', function() {
10170 - if ( this.checked ) {
10171 - jQuery( '.hide_editable' ).fadeIn( 'slow' );
10172 - triggerChange( document.getElementById( 'edit_action' ) );
10173 - } else {
10174 - jQuery( '.hide_editable' ).fadeOut( 'slow' );
10175 - jQuery( '.edit_action_message_box' ).fadeOut( 'slow' );//Hide On Update message box
10176 - }
10177 - });
10178 -
10179 - //If File Protection is checked/unchecked
10180 - jQuery( document ).on( 'change', '#protect_files', function() {
10181 - if ( this.checked ) {
10182 - jQuery( '.hide_protect_files' ).fadeIn( 'slow' );
10183 - } else {
10184 - jQuery( '.hide_protect_files' ).fadeOut( 'slow' );
10185 - }
10186 - });
10187 -
10188 - jQuery( document ).on( 'frm-multiselect-changed', '#protect_files_role', adjustVisibilityValuesForEveryoneValues );
10189 -
10190 - jQuery( document ).on( 'submit', '.frm_form_settings', settingsSubmitted );
10191 - jQuery( document ).on( 'change', '#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea', fieldUpdated );
10192 -
10193 - // Page Selection Autocomplete
10194 - initSelectionAutocomplete();
10195 -
10196 - jQuery( document ).on( 'frm-action-loaded', onActionLoaded );
10197 -
10198 - initOnSubmitAction();
10199 - },
10200 -
10201 - panelInit: function() {
10202 - var customPanel, settingsPage, viewPage, insertFieldsTab;
10203 -
10204 - jQuery( '.frm_wrap, #postbox-container-1' ).on( 'click', '.frm_insert_code', insertCode );
10205 - jQuery( document ).on( 'change', '.frm_insert_val', function() {
10206 - insertFieldCode( jQuery( this ).data( 'target' ), jQuery( this ).val() );
10207 - jQuery( this ).val( '' );
10208 - });
10209 -
10210 - jQuery( document ).on( 'click change', '#frm-id-key-condition', resetLogicBuilder );
10211 - jQuery( document ).on( 'keyup change', '.frm-build-logic', setLogicExample );
10212 -
10213 - showInputIcon();
10214 - jQuery( document ).on( 'frmElementAdded', function( event, parentEle ) {
10215 - /* This is here for add-ons to trigger */
10216 - showInputIcon( parentEle );
10217 - });
10218 - jQuery( document ).on( 'mousedown', '.frm-show-box', showShortcodes );
10219 -
10220 - settingsPage = document.getElementById( 'form_settings_page' );
10221 - viewPage = document.body.classList.contains( 'post-type-frm_display' );
10222 - insertFieldsTab = document.getElementById( 'frm_insert_fields_tab' );
10223 -
10224 - if ( settingsPage !== null || viewPage ) {
10225 - jQuery( document ).on( 'focusin', 'form input, form textarea', function( e ) {
10226 - var htmlTab;
10227 - e.stopPropagation();
10228 - maybeShowModal( this );
10229 -
10230 - if ( jQuery( this ).is( ':not(:submit, input[type=button], .frm-search-input, input[type=checkbox])' ) ) {
10231 - if ( jQuery( e.target ).closest( '#frm_adv_info' ).length ) {
10232 - // Don't trigger for fields inside of the modal.
10233 - return;
10234 - }
10235 -
10236 - if ( settingsPage !== null ) {
10237 - /* form settings page */
10238 - htmlTab = jQuery( '#frm_html_tab' );
10239 - if ( jQuery( this ).closest( '#html_settings' ).length > 0 ) {
10240 - htmlTab.show();
10241 - htmlTab.siblings().hide();
10242 - jQuery( '#frm_html_tab a' ).trigger( 'click' );
10243 - toggleAllowedHTML( this, e.type );
10244 - } else {
10245 - showElement( jQuery( '.frm-category-tabs li' ) );
10246 - insertFieldsTab.click();
10247 - htmlTab.hide();
10248 - htmlTab.siblings().show();
10249 - }
10250 - } else if ( viewPage ) {
10251 - // Run on view page.
10252 - toggleAllowedShortcodes( this.id, e.type );
10253 - }
10254 - }
10255 - });
10256 - }
10257 -
10258 - jQuery( '.frm_wrap, #postbox-container-1' ).on( 'mousedown', '#frm_adv_info a, .frm_field_list a', function( e ) {
10259 - e.preventDefault();
10260 - });
10261 -
10262 - customPanel = jQuery( '#frm_adv_info' );
10263 - customPanel.on( 'click', '.subsubsub a.frmids', function( e ) {
10264 - toggleKeyID( 'frmids', e );
10265 - });
10266 - customPanel.on( 'click', '.subsubsub a.frmkeys', function( e ) {
10267 - toggleKeyID( 'frmkeys', e );
10268 - });
10269 - },
10270 -
10271 - viewInit: function() {
10272 - var $addRemove,
10273 - $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) );
10274 - $advInfo.before( '<div id="frm_position_ele"></div>' );
10275 - setupMenuOffset();
10276 -
10277 - jQuery( document ).on( 'blur', '#param', checkDetailPageSlug );
10278 - jQuery( document ).on( 'blur', 'input[name^="options[where_val]"]', checkFilterParamNames );
10279 -
10280 - // Show loading indicator.
10281 - jQuery( '#publish' ).on( 'mousedown', function() {
10282 - fieldsUpdated = 0;
10283 - this.classList.add( 'frm_loading_button' );
10284 - });
10285 -
10286 - // move content tabs
10287 - jQuery( '#frm_dyncontent .handlediv' ).before( jQuery( '#frm_dyncontent .nav-menus-php' ) );
10288 -
10289 - // click content tabs
10290 - jQuery( '.nav-tab-wrapper a' ).on( 'click', clickContentTab );
10291 -
10292 - // click tabs after panel is replaced with ajax
10293 - jQuery( '#side-sortables' ).on( 'click', '.frm_doing_ajax.categorydiv .category-tabs a', clickTabsAfterAjax );
10294 -
10295 - initToggleShortcodes();
10296 - jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' );
10297 -
10298 - jQuery( 'input[name="show_count"]' ).on( 'change', showCount );
10299 -
10300 - jQuery( document.getElementById( 'form_id' ) ).on( 'change', displayFormSelected );
10301 -
10302 - $addRemove = jQuery( '.frm_repeat_rows' );
10303 - $addRemove.on( 'click', '.frm_add_order_row', addOrderRow );
10304 - $addRemove.on( 'click', '.frm_add_where_row', addWhereRow );
10305 - $addRemove.on( 'change', '.frm_insert_where_options', insertWhereOptions );
10306 - $addRemove.on( 'change', '.frm_where_is_options', hideWhereOptions );
10307 -
10308 - setDefaultPostStatus();
10309 - },
10310 -
10311 - inboxInit: function() {
10312 - jQuery( '.frm_inbox_dismiss, footer .frm-button-secondary, footer .frm-button-primary' ).on( 'click', function( e ) {
10313 - var message = this.parentNode.parentNode,
10314 - key = message.getAttribute( 'data-message' ),
10315 - href = this.getAttribute( 'href' );
10316 -
10317 - if ( 'free_templates' === key && ! this.classList.contains( 'frm_inbox_dismiss' ) ) {
10318 - return;
10319 - }
10320 -
10321 - e.preventDefault();
10322 -
10323 - data = {
10324 - action: 'frm_inbox_dismiss',
10325 - key: key,
10326 - nonce: frmGlobal.nonce
10327 - };
10328 - postAjax( data, function() {
10329 - if ( href !== '#' ) {
10330 - window.location = href;
10331 - return true;
10332 - }
10333 - fadeOut( message, function() {
10334 - message.parentNode.removeChild( message );
10335 - });
10336 - });
10337 - });
10338 - jQuery( '#frm-dismiss-inbox' ).on( 'click', function( e ) {
10339 - data = {
10340 - action: 'frm_inbox_dismiss',
10341 - key: 'all',
10342 - nonce: frmGlobal.nonce
10343 - };
10344 - postAjax( data, function() {
10345 - fadeOut( document.getElementById( 'frm_message_list' ), function() {
10346 - document.getElementById( 'frm_empty_inbox' ).classList.remove( 'frm_hidden' );
10347 - });
10348 - });
10349 - });
10350 - },
10351 -
10352 - solutionInit: function() {
10353 - jQuery( document ).on( 'submit', '#frm-new-template', installTemplate );
10354 - },
10355 -
10356 - styleInit: function() {
10357 - const $previewWrapper = jQuery( '.frm_image_preview_wrapper' );
10358 - $previewWrapper.on( 'click', '.frm_choose_image_box', addImageToOption );
10359 - $previewWrapper.on( 'click', '.frm_remove_image_option', removeImageFromOption );
10360 -
10361 - wp.hooks.doAction( 'frm_style_editor_init' );
10362 - },
10363 -
10364 - customCSSInit: function() {
10365 - console.warn( 'Calling frmAdminBuild.customCSSInit is deprecated.' );
10366 - },
10367 -
10368 - globalSettingsInit: function() {
10369 - var licenseTab;
10370 -
10371 - jQuery( document ).on( 'click', '[data-frmuninstall]', uninstallNow );
10372 -
10373 - initiateMultiselect();
10374 -
10375 - // activate addon licenses
10376 - licenseTab = document.getElementById( 'licenses_settings' );
10377 - if ( licenseTab !== null ) {
10378 - jQuery( licenseTab ).on( 'click', '.edd_frm_save_license', saveAddonLicense );
10379 - }
10380 -
10381 - // Solution install page
10382 - jQuery( document ).on( 'click', '#frm-new-template button', installTemplateFieldset );
10383 -
10384 - jQuery( '#frm-dismissable-cta .dismiss' ).on( 'click', function( event ) {
10385 - event.preventDefault();
10386 - jQuery.post( ajaxurl, {
10387 - action: 'frm_lite_settings_upgrade'
10388 - });
10389 - jQuery( '.settings-lite-cta' ).remove();
10390 - });
10391 -
10392 - const captchaType = document.getElementById( 'frm_re_type' );
10393 - if ( captchaType ) {
10394 - captchaType.addEventListener( 'change', handleCaptchaTypeChange );
10395 - }
10396 -
10397 - document.querySelector( '.frm_captchas' ).addEventListener( 'change', function() {
10398 - document.querySelector( '.captcha_settings .frm_note_style' ).classList.toggle( 'frm_hidden' );
10399 - });
10400 - },
10401 -
10402 - exportInit: function() {
10403 - jQuery( '.frm_form_importer' ).on( 'submit', startFormMigration );
10404 - jQuery( document.getElementById( 'frm_export_xml' ) ).on( 'submit', validateExport );
10405 - jQuery( '#frm_export_xml input, #frm_export_xml select' ).on( 'change', removeExportError );
10406 - jQuery( 'input[name="frm_import_file"]' ).on( 'change', checkCSVExtension );
10407 - document.querySelector( 'select[name="format"]' ).addEventListener( 'change', exportTypeChanged );
10408 -
10409 - jQuery( 'input[name="frm_export_forms[]"]' ).on( 'click', preventMultipleExport );
10410 - initiateMultiselect();
10411 -
10412 - jQuery( '.frm-feature-banner .dismiss' ).on( 'click', function( event ) {
10413 - event.preventDefault();
10414 - jQuery.post( ajaxurl, {
10415 - action: 'frm_dismiss_migrator',
10416 - plugin: this.id,
10417 - nonce: frmGlobal.nonce
10418 - });
10419 - this.parentElement.remove();
10420 - });
10421 -
10422 - showOrHideRepeaters( getExportOption() );
10423 -
10424 - document.querySelector( '#frm-export-select-all' ).addEventListener( 'change', event => {
10425 - document.querySelectorAll( '[name="frm_export_forms[]"]' ).forEach( cb => cb.checked = event.target.checked );
10426 - });
10427 - },
10428 -
10429 - inboxBannerInit: function() {
10430 - const banner = document.getElementById( 'frm_banner' );
10431 - if ( ! banner ) {
10432 - return;
10433 - }
10434 -
10435 - const dismissButton = banner.querySelector( '.frm-banner-dismiss' );
10436 - document.addEventListener(
10437 - 'click',
10438 - function( event ) {
10439 - if ( event.target !== dismissButton ) {
10440 - return;
10441 - }
10442 -
10443 - const data = {
10444 - action: 'frm_inbox_dismiss',
10445 - key: banner.dataset.key,
10446 - nonce: frmGlobal.nonce
10447 - };
10448 - postAjax(
10449 - data,
10450 - function() {
10451 - jQuery( banner ).fadeOut(
10452 - 400,
10453 - function() {
10454 - banner.remove();
10455 - }
10456 - );
10457 - }
10458 - );
10459 - }
10460 - );
10461 - },
10462 -
10463 - updateOpts: function( fieldId, opts, modal ) {
10464 - var separate = usingSeparateValues( fieldId ),
10465 - action = isProductField( fieldId ) ? 'frm_bulk_products' : 'frm_import_options';
10466 - jQuery.ajax({
10467 - type: 'POST',
10468 - url: ajaxurl,
10469 - data: {
10470 - action: action,
10471 - field_id: fieldId,
10472 - opts: opts,
10473 - separate: separate,
10474 - nonce: frmGlobal.nonce
10475 - },
10476 - success: function( html ) {
10477 - document.getElementById( 'frm_field_' + fieldId + '_opts' ).innerHTML = html;
10478 - resetDisplayedOpts( fieldId );
10479 -
10480 - if ( typeof modal !== 'undefined' ) {
10481 - modal.dialog( 'close' );
10482 - document.getElementById( 'frm-update-bulk-opts' ).classList.remove( 'frm_loading_button' );
10483 - }
10484 - }
10485 - });
10486 - },
10487 -
10488 - /* remove conditional logic if the field doesn't exist */
10489 - triggerRemoveLogic: function( fieldID, metaName ) {
10490 - jQuery( '#frm_logic_' + fieldID + '_' + metaName + ' .frm_remove_tag' ).trigger( 'click' );
10491 - },
10492 -
10493 - downloadXML: function( controller, ids, isTemplate ) {
10494 - var url = ajaxurl + '?action=frm_' + controller + '_xml&ids=' + ids;
10495 - if ( isTemplate !== null ) {
10496 - url = url + '&is_template=' + isTemplate;
10497 - }
10498 - location.href = url;
10499 - },
10500 -
10501 - /**
10502 - * @since 5.0.04
10503 - */
10504 - hooks: {
10505 - applyFilters: function( hookName, ...args ) {
10506 - return wp.hooks.applyFilters( hookName, ...args );
10507 - },
10508 - addFilter: function( hookName, callback, priority ) {
10509 - return wp.hooks.addFilter( hookName, 'formidable', callback, priority );
10510 - },
10511 - doAction: function( hookName, ...args ) {
10512 - return wp.hooks.doAction( hookName, ...args );
10513 - },
10514 - addAction: function( hookName, callback, priority ) {
10515 - return wp.hooks.addAction( hookName, 'formidable', callback, priority );
10516 - }
10517 - },
10518 -
10519 - infoModal: infoModal,
10520 - adjustConditionalLogicOptionOrders: adjustConditionalLogicOptionOrders,
10521 - addRadioCheckboxOpt: addRadioCheckboxOpt
10522 - };
10523 -}
10524 -
10525 -frmAdminBuild = frmAdminBuildJS();
10526 -
10527 -jQuery( document ).ready(
10528 - () => {
10529 - frmAdminBuild.init();
10530 -
10531 - frmDom.bootstrap.setupBootstrapDropdowns( convertOldBootstrapDropdownsToBootstrap4 );
10532 - document.querySelector( '.preview.dropdown .frm-dropdown-toggle' )?.setAttribute( 'data-toggle', 'dropdown' );
10533 -
10534 - function convertOldBootstrapDropdownsToBootstrap4( frmDropdownMenu ) {
10535 - const toggle = frmDropdownMenu.querySelector( '.frm-dropdown-toggle' );
10536 - if ( toggle ) {
10537 - if ( ! toggle.hasAttribute( 'role' ) ) {
10538 - toggle.setAttribute( 'role', 'button' );
10539 - }
10540 - if ( ! toggle.hasAttribute( 'tabindex' ) ) {
10541 - toggle.setAttribute( 'tabindex', 0 );
10542 - }
10543 - }
10544 -
10545 - // Convert <li> and <ul> tags.
10546 - if ( 'UL' === frmDropdownMenu.tagName ) {
10547 - convertBootstrapUl( frmDropdownMenu );
10548 - }
10549 - }
10550 -
10551 - function convertBootstrapUl( ul ) {
10552 - let html = ul.outerHTML;
10553 - html = html.replace( '<ul ', '<div ' );
10554 - html = html.replace( '</ul>', '</div>' );
10555 - html = html.replaceAll( '<li>', '<div class="dropdown-item">' );
10556 - html = html.replaceAll( '<li class="', '<div class="dropdown-item ' );
10557 - html = html.replaceAll( '</li>', '</div>' );
10558 - ul.outerHTML = html;
10559 - }
10560 - }
10561 -);
10562 -
10563 -function frm_remove_tag( htmlTag ) { // eslint-disable-line camelcase
10564 - console.warn( 'DEPRECATED: function frm_remove_tag in v2.0' );
10565 - jQuery( htmlTag ).remove();
10566 -}
10567 -
10568 -function frm_show_div( div, value, showIf, classId ) { // eslint-disable-line camelcase
10569 - if ( value == showIf ) {
10570 - jQuery( classId + div ).fadeIn( 'slow' ).css( 'visibility', 'visible' );
10571 - } else {
10572 - jQuery( classId + div ).fadeOut( 'slow' );
10573 - }
10574 -}
10575 -
10576 -function frmCheckAll( checked, n ) {
10577 - jQuery( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked );
10578 -}
10579 -
10580 -function frmCheckAllLevel( checked, n, level ) {
10581 - var $kids = jQuery( '.frm_catlevel_' + level ).children( '.frm_checkbox' ).children( 'label' );
10582 - $kids.children( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked );
10583 -}
10584 -
10585 -function frm_add_logic_row( id, formId ) { // eslint-disable-line camelcase
10586 - console.warn( 'DEPRECATED: function frm_add_logic_row in v2.0' );
10587 - jQuery.ajax({
10588 - type: 'POST',
10589 - url: ajaxurl,
10590 - data: {
10591 - action: 'frm_add_logic_row',
10592 - form_id: formId,
10593 - field_id: id,
10594 - meta_name: jQuery( '#frm_logic_row_' + id + ' > div' ).length,
10595 - nonce: frmGlobal.nonce
10596 - },
10597 - success: function( html ) {
10598 - jQuery( '#frm_logic_row_' + id ).append( html );
10599 - }
10600 - });
10601 - return false;
10602 -}
10603 -
10604 -function frmGetFieldValues( fieldId, cur, rowNumber, fieldType, htmlName ) {
10605 -
10606 - if ( fieldId ) {
10607 - jQuery.ajax({
10608 - type: 'POST', url: ajaxurl,
10609 - data: 'action=frm_get_field_values&current_field=' + cur + '&field_id=' + fieldId + '&name=' + htmlName + '&t=' + fieldType + '&form_action=' + jQuery( 'input[name="frm_action"]' ).val() + '&nonce=' + frmGlobal.nonce,
10610 - success: function( msg ) {
10611 - document.getElementById( 'frm_show_selected_values_' + cur + '_' + rowNumber ).innerHTML = msg;
10612 - }
10613 - });
10614 - }
10615 -}
10616 -
10617 -function frmImportCsv( formID ) {
10618 - var urlVars = '';
10619 - if ( typeof __FRMURLVARS !== 'undefined' ) {
10620 - urlVars = __FRMURLVARS;
10621 - }
10622 -
10623 - jQuery.ajax({
10624 - type: 'POST', url: ajaxurl,
10625 - data: 'action=frm_import_csv&nonce=' + frmGlobal.nonce + '&frm_skip_cookie=1' + urlVars,
10626 - success: function( count ) {
10627 - var max = jQuery( '.frm_admin_progress_bar' ).attr( 'aria-valuemax' );
10628 - var imported = max - count;
10629 - var percent = ( imported / max ) * 100;
10630 - jQuery( '.frm_admin_progress_bar' ).css( 'width', percent + '%' ).attr( 'aria-valuenow', imported );
10631 -
10632 - if ( parseInt( count, 10 ) > 0 ) {
10633 - jQuery( '.frm_csv_remaining' ).html( count );
10634 - frmImportCsv( formID );
10635 - } else {
10636 - jQuery( document.getElementById( 'frm_import_message' ) ).html( frm_admin_js.import_complete ); // eslint-disable-line camelcase
10637 - setTimeout( function() {
10638 - location.href = '?page=formidable-entries&frm_action=list&form=' + formID + '&import-message=1';
10639 - }, 2000 );
10640 - }
10641 - }
10642 - });
10643 -}
1 +(()=>{var e={65:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(8793),o=r(1323);function i(e){var t=(0,n.A)(e);return function(e){return(0,o.A)(t,e)}}},1323:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n={"!":function(e){return!e},"*":function(e,t){return e*t},"/":function(e,t){return e/t},"%":function(e,t){return e%t},"+":function(e,t){return e+t},"-":function(e,t){return e-t},"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"==":function(e,t){return e===t},"!=":function(e,t){return e!==t},"&&":function(e,t){return e&&t},"||":function(e,t){return e||t},"?:":function(e,t,r){if(e)throw t;return r}};function o(e,t){var r,o,i,a,l,s,c=[];for(r=0;r<e.length;r++){if(l=e[r],a=n[l]){for(o=a.length,i=Array(o);o--;)i[o]=c.pop();try{s=a.apply(null,i)}catch(e){return e}}else s=t.hasOwnProperty(l)?t[l]:+l;c.push(s)}return c[0]}},1364:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(65);function o(e){var t=(0,n.A)(e);return function(e){return+t({n:e})}}},8793:(e,t,r)=>{"use strict";var n,o,i,a;function l(e){for(var t,r,l,s,c=[],d=[];t=e.match(a);){for(r=t[0],(l=e.substr(0,t.index).trim())&&c.push(l);s=d.pop();){if(i[r]){if(i[r][0]===s){r=i[r][1]||r;break}}else if(o.indexOf(s)>=0||n[s]<n[r]){d.push(s);break}c.push(s)}i[r]||d.push(r),e=e.substr(t.index+r.length)}return(e=e.trim())&&c.push(e),c.concat(d.reverse())}r.d(t,{A:()=>l}),n={"(":9,"!":8,"*":7,"/":7,"%":7,"+":6,"-":6,"<":5,"<=":5,">":5,">=":5,"==":4,"!=":4,"&&":3,"||":2,"?":1,"?:":1},o=["(","?"],i={")":["("],":":["?","?:"]},a=/<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/},7521:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(6956),o=r(7395);const i=function(e,t){return function(r,i,a){var l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10,s=e[t];if((0,o.A)(r)&&(0,n.A)(i))if("function"==typeof a)if("number"==typeof l){var c={callback:a,priority:l,namespace:i};if(s[r]){var d,u=s[r].handlers;for(d=u.length;d>0&&!(l>=u[d-1].priority);d--);d===u.length?u[d]=c:u.splice(d,0,c),s.__current.forEach(function(e){e.name===r&&e.currentIndex>=d&&e.currentIndex++})}else s[r]={handlers:[c],runs:0};"hookAdded"!==r&&e.doAction("hookAdded",r,i,a,l)}else console.error("If specified, the hook priority must be a number.");else console.error("The hook callback must be a function.")}}},11:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){return function(){var r,n,o=e[t];return null!==(r=null===(n=o.__current[o.__current.length-1])||void 0===n?void 0:n.name)&&void 0!==r?r:null}}},5375:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(7395);const o=function(e,t){return function(r){var o=e[t];if((0,n.A)(r))return o[r]&&o[r].runs?o[r].runs:0}}},3561:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){return function(r){var n=e[t];return void 0===r?void 0!==n.__current[0]:!!n.__current[0]&&r===n.__current[0].name}}},8830:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){return function(r,n){var o=e[t];return void 0!==n?r in o&&o[r].handlers.some(function(e){return e.namespace===n}):r in o}}},7765:(e,t,r)=>{"use strict";r.d(t,{A:()=>f});var n=r(3029),o=r(7521),i=r(4194),a=r(8830),l=r(6763),s=r(11),c=r(3561),d=r(5375),u=function e(){(0,n.A)(this,e),this.actions=Object.create(null),this.actions.__current=[],this.filters=Object.create(null),this.filters.__current=[],this.addAction=(0,o.A)(this,"actions"),this.addFilter=(0,o.A)(this,"filters"),this.removeAction=(0,i.A)(this,"actions"),this.removeFilter=(0,i.A)(this,"filters"),this.hasAction=(0,a.A)(this,"actions"),this.hasFilter=(0,a.A)(this,"filters"),this.removeAllActions=(0,i.A)(this,"actions",!0),this.removeAllFilters=(0,i.A)(this,"filters",!0),this.doAction=(0,l.A)(this,"actions"),this.applyFilters=(0,l.A)(this,"filters",!0),this.currentAction=(0,s.A)(this,"actions"),this.currentFilter=(0,s.A)(this,"filters"),this.doingAction=(0,c.A)(this,"actions"),this.doingFilter=(0,c.A)(this,"filters"),this.didAction=(0,d.A)(this,"actions"),this.didFilter=(0,d.A)(this,"filters")};const f=function(){return new u}},4194:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(6956),o=r(7395);const i=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(i,a){var l=e[t];if((0,o.A)(i)&&(r||(0,n.A)(a))){if(!l[i])return 0;var s=0;if(r)s=l[i].handlers.length,l[i]={runs:l[i].runs,handlers:[]};else for(var c=l[i].handlers,d=function(e){c[e].namespace===a&&(c.splice(e,1),s++,l.__current.forEach(function(t){t.name===i&&t.currentIndex>=e&&t.currentIndex--}))},u=c.length-1;u>=0;u--)d(u);return"hookRemoved"!==i&&e.doAction("hookRemoved",i,a),s}}}},6763:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(n){var o=e[t];o[n]||(o[n]={handlers:[],runs:0}),o[n].runs++;for(var i=o[n].handlers,a=arguments.length,l=new Array(a>1?a-1:0),s=1;s<a;s++)l[s-1]=arguments[s];if(!i||!i.length)return r?l[0]:void 0;var c={name:n,currentIndex:0};for(o.__current.push(c);c.currentIndex<i.length;){var d=i[c.currentIndex].callback.apply(null,l);r&&(l[0]=d),c.currentIndex++}return o.__current.pop(),r?l[0]:void 0}}},2133:(e,t,r)=>{"use strict";r.d(t,{se:()=>n});var n=(0,r(7765).A)();n.addAction,n.addFilter,n.removeAction,n.removeFilter,n.hasAction,n.hasFilter,n.removeAllActions,n.removeAllFilters,n.doAction,n.applyFilters,n.currentAction,n.currentFilter,n.doingAction,n.doingFilter,n.didAction,n.didFilter,n.actions,n.filters},7395:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e){return"string"!=typeof e||""===e?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(e)?(console.error("The hook name cannot begin with `__`."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(e)||(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)}},6956:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e){return"string"!=typeof e||""===e?(console.error("The namespace must be a non-empty string."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(e)||(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)}},772:(e,t,r)=>{"use strict";r.d(t,{h:()=>c});var n=r(4467),o=r(5397);function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach(function(t){(0,n.A)(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var l={"":{plural_forms:function(e){return 1===e?0:1}}},s=/^i18n\.(n?gettext|has_translation)(_|$)/,c=function(e,t,r){var n=new o.A({}),i=new Set,c=function(){i.forEach(function(e){return e()})},d=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default";n.data[t]=a(a(a({},l),n.data[t]),e),n.data[t][""]=a(a({},l[""]),n.data[t][""])},u=function(e,t){d(e,t),c()},f=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default",t=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;return n.data[e]||d(void 0,e),n.dcnpgettext(e,t,r,o,i)},m=function(){return arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default"},_=function(e,t,n){var o=f(n,t,e);return r?(o=r.applyFilters("i18n.gettext_with_context",o,e,t,n),r.applyFilters("i18n.gettext_with_context_"+m(n),o,e,t,n)):o};if(e&&u(e,t),r){var p=function(e){s.test(e)&&c()};r.addAction("hookAdded","core/i18n",p),r.addAction("hookRemoved","core/i18n",p)}return{getLocaleData:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default";return n.data[e]},setLocaleData:u,resetLocaleData:function(e,t){n.data={},n.pluralForms={},u(e,t)},subscribe:function(e){return i.add(e),function(){return i.delete(e)}},__:function(e,t){var n=f(t,void 0,e);return r?(n=r.applyFilters("i18n.gettext",n,e,t),r.applyFilters("i18n.gettext_"+m(t),n,e,t)):n},_x:_,_n:function(e,t,n,o){var i=f(o,void 0,e,t,n);return r?(i=r.applyFilters("i18n.ngettext",i,e,t,n,o),r.applyFilters("i18n.ngettext_"+m(o),i,e,t,n,o)):i},_nx:function(e,t,n,o,i){var a=f(i,o,e,t,n);return r?(a=r.applyFilters("i18n.ngettext_with_context",a,e,t,n,o,i),r.applyFilters("i18n.ngettext_with_context_"+m(i),a,e,t,n,o,i)):a},isRTL:function(){return"rtl"===_("ltr","text direction")},hasTranslation:function(e,t,o){var i,a,l=t?t+""+e:e,s=!(null===(i=n.data)||void 0===i||null===(a=i[null!=o?o:"default"])||void 0===a||!a[l]);return r&&(s=r.applyFilters("i18n.has_translation",s,e,t,o),s=r.applyFilters("i18n.has_translation_"+m(o),s,e,t,o)),s}}}},5839:(e,t,r)=>{"use strict";r.d(t,{__:()=>a});var n=r(772),o=r(2133),i=(0,n.h)(void 0,void 0,o.se),a=(i.getLocaleData.bind(i),i.setLocaleData.bind(i),i.resetLocaleData.bind(i),i.subscribe.bind(i),i.__.bind(i));i._x.bind(i),i._n.bind(i),i._nx.bind(i),i.isRTL.bind(i),i.hasTranslation.bind(i)},9575:(e,t,r)=>{"use strict";r.d(t,{__:()=>n.__}),r(181),r(772);var n=r(5839)},181:(e,t,r)=>{"use strict";var n=r(8616),o=r.n(n);r(7604),o()(console.error)},1105:(e,t,r)=>{"use strict";r.r(t),r.d(t,{addonError:()=>f,afterAddonInstall:()=>u,extractErrorFromAddOnResponse:()=>d,toggleAddonState:()=>c});var n=r(9575);function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,l=[],s=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(l.push(n.value),l.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var a=frmDom,l=a.div,s=a.svg;function c(e,t){var r,n=null!==(r=window.ajaxurl)&&void 0!==r?r:frm_js.ajax_url;jQuery(".frm-addon-error").remove();var o=jQuery(e),i=o.attr("rel"),a=o.parent(),l=a.parent().find(".addon-status-label");o.addClass("frm_loading_button"),jQuery.ajax({url:n,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:t,nonce:frmGlobal.nonce,plugin:i},success:function(e){var r,n,i;"string"!=typeof(e=null!==(r=null===(n=e)||void 0===n?void 0:n.data)&&void 0!==r?r:e)&&"string"==typeof e.message&&(void 0!==e.saveAndReload&&(i=e.saveAndReload),e=e.message);var s=d(e);s?f(s,a,o):(u(e,o,l,a,i,t),wp.hooks.doAction("frm_update_addon_state",e))},error:function(){o.removeClass("frm_loading_button")}})}function d(e){return"string"!=typeof e&&!e.success&&(e.form&&jQuery(e.form).is("#message")?{message:jQuery(e.form).find("p").html()}:e)}function u(e,t,r,i,a){var c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"frm_activate_addon",d=frm_admin_js,u=document.querySelectorAll(".frm-addon-status");u.forEach(function(t){t.textContent=e,t.style.display="block"}),t.css({opacity:"0"}),document.querySelectorAll(".frm-oneclick").forEach(function(e){e.style.display="none"}),function(){var e=document.getElementById("frm_upgrade_modal");if(e){e.classList.add("frm-success");var t=e.querySelector(".frm-upgrade-message");if(t){var r=t.querySelector("img");t.replaceChildren((0,n.__)("Great! Everything's ready to go!","formidable"),document.createElement("br"),(0,n.__)("You just need to refresh the builder so the new field becomes available.","formidable")),r&&t.append(r)}var o=document.querySelector(".frm-addon-status");o&&(o.textContent="");var i,a=e.querySelector(".frm-circled-icon");if(a)a.classList.add("frm-circled-icon-green"),null===(i=a.querySelector("svg"))||void 0===i||i.replaceWith(s({href:"#frm_checkmark_icon"}))}}();var f={frm_activate_addon:{class:"frm-addon-active",message:d.active},frm_deactivate_addon:{class:"frm-addon-installed",message:d.installed},frm_uninstall_addon:{class:"frm-addon-not-installed",message:d.not_installed}};f.frm_install_addon=f.frm_activate_addon;var _=o(r,1)[0];_&&(_.textContent=f[c].message);var p=o(i,1)[0].parentElement;p.classList.remove("frm-addon-not-installed","frm-addon-installed","frm-addon-active"),p.classList.add(f[c].class),o(t,1)[0].classList.remove("frm_loading_button"),document.querySelectorAll(".frm-admin-page-import, #frm-admin-smtp, #frm-welcome").length>0?window.location.reload():["settings","form_builder"].includes(a)&&u.forEach(function(e){var t=null!==e.closest("#frm_upgrade_modal");e.append(function(e,t){var r,o=[m(e)];return t&&o.push(((r=document.createElement("a")).setAttribute("href","#"),r.classList.add("button","button-secondary","frm-button-secondary","dismiss"),r.textContent=(0,n.__)("Not Now","formidable"),r)),l({className:"frm-save-and-reload-options",children:o})}(a,t))})}function f(e,t,r){e.form?(jQuery(".frm-inline-error").remove(),r.closest(".frm-card").html(e.form).css({padding:5}).find("#upgrade").attr("rel",r.attr("rel")).on("click",_)):(t.append('<div class="frm-addon-error frm_error_style"><p><strong>'.concat(e.message,"</strong></p></div>")),r.removeClass("frm_loading_button"),jQuery(".frm-addon-error").delay(4e3).fadeOut())}function m(e){var t=document.createElement("button");return t.classList.add("frm-save-and-reload","button","button-primary","frm-button-primary"),t.textContent=(0,n.__)("Save and Reload","formidable"),t.addEventListener("click",function(){var t;"form_builder"===e?((t=document.getElementById("frm_submit_side_top")).classList.contains("frm_submit_ajax")&&t.setAttribute("data-new-addon-installed",!0),t.click()):"settings"===e&&function(){var e=document.getElementById("form_settings_page");if(e){var t=e.querySelector("form.frm_form_settings");null!==t&&(wp.hooks.doAction("frm_reset_fields_updated"),t.submit())}}()}),t}function _(e){e.preventDefault();var t=jQuery(this),r=t.parent().parent(),n=t.attr("rel");t.addClass("frm_loading_button"),jQuery.ajax({url:ajaxurl,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:"frm_install_addon",nonce:frmAdminJs.nonce,plugin:n,hostname:r.find("#hostname").val(),username:r.find("#username").val(),password:r.find("#password").val()},success:function(e){var n,o,i=d(e=null!==(n=null===(o=e)||void 0===o?void 0:o.data)&&void 0!==n?n:e);i?f(i,r,t):u(e,t,message,r)},error:function(){t.removeClass("frm_loading_button")}})}},4365:()=>{!function(){function e(e){var t=e.querySelector(".frm-gc-item-type"),r=t.value,n=t.name.replace(/\[type\]$/,"");e.querySelectorAll(".frm-gc-type-settings").forEach(function(e){var t=e.dataset.type===r;e.toggleAttribute("hidden",!t),e.querySelectorAll("[data-frm-gc-field]").forEach(function(e){var r=e.dataset.frmGcField;t?e.name="".concat(n,"[").concat(r,"]"):e.removeAttribute("name")})})}function t(t){var r,n=t.querySelector(".frm_gc_add_item"),o=null!==(r=null==n?void 0:n.dataset.fieldNameBase)&&void 0!==r?r:"",i=t.querySelectorAll(".frm_gc_item_row");i.forEach(function(r,n){var i=r.querySelector(".frm-gc-item-type");i&&o&&(i.name="".concat(o,"[").concat(n,"][type]")),function(e,t,r){var n=e.querySelector('[data-frm-gc-field="type"]');if(n){n.id="".concat(t,"_type_").concat(r);var o=e.querySelector('[data-frm-gc-for="type"]');o&&(o.htmlFor=n.id)}e.querySelectorAll(".frm-gc-type-settings").forEach(function(e){var n=e.dataset.type;e.querySelectorAll("[data-frm-gc-field]").forEach(function(o){var i=o.dataset.frmGcField;o.id="".concat(t,"_").concat(i,"_").concat(n,"_").concat(r);var a=e.querySelector('[data-frm-gc-for="'.concat(i,'"]'));a&&(a.htmlFor=o.id)})})}(r,t.id,n),e(r)}),t.dataset.itemCount=i.length}function r(e){var t=e.getAttribute("aria-label");e.classList.add("is-copied"),e.setAttribute("aria-label",e.dataset.copiedLabel||"Copied!"),setTimeout(function(){e.classList.remove("is-copied"),e.setAttribute("aria-label",t)},1600)}document.addEventListener("click",function(e){var n=e.target.closest(".frm_gc_add_item");if(n){var o=n.closest(".frm_gated_content_settings"),i=o.querySelector(".frm_gc_items_list"),a=o.querySelector(".frm_gc_item_template");return i.append(a.content.cloneNode(!0)),t(o),void frmDom.autocomplete.initSelectionAutocomplete(i.lastElementChild)}var l=e.target.closest(".frm_gc_remove_item");if(l){var s=l.closest(".frm_gated_content_settings");return l.closest(".frm_gc_item_row").remove(),void t(s)}var c=e.target.closest(".frm_gc_copy_shortcode");if(c){var d,u=c.dataset.frmCopy;if(null!==(d=navigator.clipboard)&&void 0!==d&&d.writeText)navigator.clipboard.writeText(u).then(function(){return r(c)});else{var f=document.createElement("textarea");f.value=u,f.style.cssText="position:fixed;opacity:0;",document.body.append(f),f.select(),document.execCommand("copy"),f.remove(),r(c)}}}),document.addEventListener("change",function(t){var r=t.target.closest(".frm-gc-item-type");if(r)e(r.closest(".frm_gc_item_row"));else{var n=t.target.closest(".frm-gc-file-form-select");n&&function(e){var t=e.closest(".frm-gc-type-settings"),r=null==t?void 0:t.querySelector('[data-frm-gc-field="id"]');if(r){var n=e.value;Array.from(r.options).forEach(function(e){var t=e.dataset.formId;e.style.display=t?n&&t===n?"":"none":""});var o=r.options[r.selectedIndex];"none"===(null==o?void 0:o.style.display)&&(r.value="")}}(n)}}),jQuery(document).on("frm-multiselect-changed",'select[id^="event_"]',function(){var e=document.querySelector('.frm_gc_update_section[data-frm-gc-event-id="'.concat(this.id,'"]'));if(e){var t=Array.from(this.options).some(function(e){return e.selected&&"update"===e.value});e.hidden=!t}})}()},8095:(e,t,r)=>{"use strict";function n(e,t){var r=t();return r?(frmAdminBuild.infoModal(r),e.classList.add("frm_invalid_field"),function(e){var t=document.querySelectorAll("#frm_info_modal .dismiss, #frm_info_modal #frm-info-click, .ui-widget-overlay.ui-front");function r(){setTimeout(function(){return e.focus()},0),t.forEach(function(e){return e.removeEventListener("click",r)})}t.forEach(function(e){return e.addEventListener("click",r)})}(e)):e.classList.remove("frm_invalid_field"),r}r.r(t),r.d(t,{validateField:()=>n})},4746:(e,t,r)=>{"use strict";r.r(t),r.d(t,{getRangeSettingsDefaults:()=>l,validateNumberRangeSetting:()=>s,validateRangeSettings:()=>d,validateStepSetting:()=>c});var n=r(9575),o=r(8095),i=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return t?t.dataset.fid:null==r||null===(e=r.closest(".frm-single-settings"))||void 0===e?void 0:e.dataset.fid},a=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return t||(t=null==r?void 0:r.closest(".frm-single-settings")),null===(e=t)||void 0===e||null===(e=e.className.match(/frm-type-(\w+)/))||void 0===e?void 0:e[1]};function l(e){var t=a(e)||"number";return wp.hooks.applyFilters("frm_range_settings_defaults",{maxNum:9999999,minNum:0,step:1},{singleSettings:e,fieldType:t})}function s(e){if(e.closest(".frm-number-range")){var t=e.closest(".frm-single-settings"),r=i(t);if(r){var a=document.querySelector('[name="field_options[minnum_'.concat(r,']"]'));if(a){var s=document.querySelector('[name="field_options[maxnum_'.concat(r,']"]'));if(s)return(0,o.validateField)(e,function(){var e=l(t),r=e.minNum,o=e.maxNum;return parseFloat(a.value||r)>=parseFloat(s.value||o)?(0,n.__)("Minimum value cannot be greater than or equal to maximum value.","formidable"):""})}}}}function c(e){if(e.closest(".frm-step")){var t=e.closest(".frm-single-settings"),r=i(t);if(r){var a=document.querySelector('[name="field_options[step_'.concat(r,']"]'));if(a)return(0,o.validateField)(e,function(){var e=l(t),o=e.step,i=e.minNum,s=e.maxNum,c=parseFloat(a.value||o);if(c<=0)return(0,n.__)("Step value must be greater than 0.","formidable");var d=document.querySelector('[name="field_options[maxnum_'.concat(r,']"]'));if(!d)return"";var u=document.querySelector('[name="field_options[minnum_'.concat(r,']"]')),f=parseFloat((null==u?void 0:u.value)||i);return c>parseFloat(d.value||s)-f?(0,n.__)("Step value cannot be greater than the difference between the minimum and maximum values.","formidable"):""})}}}function d(e){var t=s(e);return t||(t=c(e)),wp.hooks.applyFilters("frm_validate_range_settings",t||"",{field:e})}},4260:(e,t,r)=>{"use strict";r.r(t),r.d(t,{addOneClick:()=>i,initModal:()=>a,initUpgradeModal:()=>l});var n=r(9575),o=frmDom.svg;function i(e,t,r){var i;if("modal"===t)i=document.getElementById("frm_upgrade_modal");else{if("tab"!==t)return;i=document.getElementById(e.getAttribute("href").substr(1))}var a,l=i.querySelector(".frm-oneclick"),s=i.querySelector(".frm-upgrade-message"),c=i.querySelector(".frm-upgrade-link"),d=i.querySelector(".frm-oneclick-button"),u=i.querySelector(".frm-addon-status"),f=e.getAttribute("data-oneclick"),m=e.getAttribute("data-message"),_="block",p="block",g="none",v=i.querySelector(".frm-circled-icon");v&&(v.classList.remove("frm-circled-icon-green"),null===(a=v.querySelector("svg"))||void 0===a||a.replaceWith(o({href:"#frm_filled_lock_icon"})));var y=i.querySelector(".frm-learn-more");if(y&&(e.dataset.learnMore?(y.href=e.dataset.learnMore,y.style.display=""):y.style.display="none"),null!==l&&null!==d&&void 0!==f&&f){null===m&&(p="none"),_="none",g="block",f=JSON.parse(f),d.className=d.className.replace(" frm-install-addon","").replace(" frm-activate-addon",""),d.className="".concat(d.className," ").concat(f.class),d.rel=f.url,l.textContent=(0,n.__)("This plugin is not activated. Would you like to activate it now?","formidable"),d.textContent=(0,n.__)("Activate","formidable");var h=e.querySelector("use");h&&(null==v||v.querySelector("svg").replaceWith(o({href:h.getAttribute("href")||h.getAttribute("xlink:href"),classList:["frm_svg32"]})))}m||(m=s.getAttribute("data-default")),void 0!==r&&(m=m.replace('<span class="frm_feature_label"></span>',r)),s.innerHTML=m,e.dataset.upsellImage&&s.append(frmDom.img({src:e.dataset.upsellImage,alt:e.dataset.upgrade})),c.href=function(e,t){var r=e.getAttribute("data-link");return null!=r&&""!==r||(r=t.getAttribute("data-default")),r}(e,c),u.style.display="none",l&&(l.style.display=g),d&&(d.style.display="block"===g?"inline-block":g),s.style.display=p,c.style.display="block"===_?"inline-block":_;var b=c.closest(".frm-upgrade-modal-actions");b&&(b.style.display="block"===_?"flex":_)}function a(e,t){var r=jQuery(e);if(!r.length)return!1;void 0===t&&(t="552px");var n={dialogClass:"frm-dialog",modal:!0,autoOpen:!1,closeOnEscape:!0,width:t,resizable:!1,draggable:!1,open:function(){var e,t;jQuery(".ui-dialog-titlebar").addClass("frm_hidden").removeClass("ui-helper-clearfix"),jQuery("#wpwrap").addClass("frm_overlay"),jQuery(".frm-dialog").removeClass("ui-widget ui-widget-content ui-corner-all"),r.removeClass("ui-dialog-content ui-widget-content"),e=r,t=function(){e.dialog("close")},jQuery(".ui-widget-overlay").on("click",t),e.on("click","a.dismiss",t)},close:function(){jQuery("#wpwrap").removeClass("frm_overlay"),jQuery(".spinner").css("visibility","hidden"),this.removeAttribute("data-option-type");var e=document.getElementById("bulk-option-type");e&&(e.value="")}};return r.dialog(n),r}function l(){var e=a("#frm_upgrade_modal");function t(t){var r,o,a;if((r=t.target).classList){var l=r.classList.contains("frm_show_expired_modal")||null!==r.querySelector(".frm_show_expired_modal")||r.closest(".frm_show_expired_modal");if("change"===t.type&&r.classList.contains("frm_select_with_upgrade")){var s,c=r.options[r.selectedIndex];null!=c&&null!==(s=c.dataset)&&void 0!==s&&s.upgrade&&(r=c)}if(!r.dataset.upgrade){var d=r.closest("[data-upgrade]");if(!d){if(!(d=r.closest(".frm_field_box")))return;r.dataset.upgrade=""}r=d}if(l)wp.hooks.doAction("frm_show_expired_modal",r);else{var u=r.dataset.upgrade;if(u&&!r.classList.contains("frm_show_upgrade_tab")){t.preventDefault();var f=e.get(0);f.classList.remove("frm-success");var m=f.querySelector(".frm_lock_icon");m&&(m.style.display="block",m.classList.remove("frm_lock_open_icon"),m.querySelector("use").setAttribute("href","#frm_lock_icon"));var _="frm_upgrade_modal_image",p=document.getElementById(_);p&&p.remove(),r.dataset.image&&m&&(m.style.display="none",m.parentNode.insertBefore(frmDom.img({id:_,src:"".concat(frmGlobal.url,"/images/").concat(r.dataset.image)}),m));var g=f.querySelector(".license-level");g&&(g.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(r)),i(r,"modal",u);var v=f.querySelector(".frm_are_not_installed");v.style.display=r.dataset.image||r.dataset.oneclick?"none":"inline-block",v.textContent=v.dataset.default,f.querySelector(".frm-upgrade-modal-title-prefix").style.display=r.dataset.oneclick?"inline":"none",f.querySelector(".frm_feature_label").textContent=u,f.querySelector(".frm-upgrade-modal-title-suffix").style.display="none",f.querySelector("h2").style.display="block",e.dialog("open");var y=f.querySelector(".button-primary:not(.frm-oneclick-button)");o=y.getAttribute("href").replace(/(medium=)[a-z_-]+/gi,"$1".concat(r.getAttribute("data-medium"))),null===(a=r.getAttribute("data-content"))&&(a=""),o=o.replace(/(content=)[a-z_-]+/gi,"$1".concat(a)),y.setAttribute("href",o),r.classList.contains("frm_show_update")&&function(e){var t=e.querySelector(".frm-upgrade-modal-title-prefix");t&&(t.style.display="none");var r=e.querySelector(".frm_are_not_installed");r&&(r.textContent=(0,n.__)("require an update","formidable"),r.style.display="");var o=e.querySelector(".frm-oneclick");o&&(o.style.display="none");var i=e.querySelector(".frm-oneclick-button");i&&(i.textContent=(0,n.__)("Update Now","formidable"))}(f)}}}}!1!==e&&(document.addEventListener("click",t),frmDom.util.documentOn("change","select.frm_select_with_upgrade",t))}},8616:e=>{e.exports=function(e,t){var r,n,o=0;function i(){var i,a,l=r,s=arguments.length;e:for(;l;){if(l.args.length===arguments.length){for(a=0;a<s;a++)if(l.args[a]!==arguments[a]){l=l.next;continue e}return l!==r&&(l===n&&(n=l.prev),l.prev.next=l.next,l.next&&(l.next.prev=l.prev),l.next=r,l.prev=null,r.prev=l,r=l),l.val}l=l.next}for(i=new Array(s),a=0;a<s;a++)i[a]=arguments[a];return l={args:i,val:e.apply(null,i)},r?(r.prev=l,l.next=r):n=l,o===t.maxSize?(n=n.prev).next=null:o++,r=l,l.val}return t=t||{},i.clear=function(){r=null,n=null,o=0},i}},7604:(e,t,r)=>{var n;!function(){"use strict";var o={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function i(e){return function(e,t){var r,n,a,l,s,c,d,u,f,m=1,_=e.length,p="";for(n=0;n<_;n++)if("string"==typeof e[n])p+=e[n];else if("object"==typeof e[n]){if((l=e[n]).keys)for(r=t[m],a=0;a<l.keys.length;a++){if(null==r)throw new Error(i('[sprintf] Cannot access property "%s" of undefined value "%s"',l.keys[a],l.keys[a-1]));r=r[l.keys[a]]}else r=l.param_no?t[l.param_no]:t[m++];if(o.not_type.test(l.type)&&o.not_primitive.test(l.type)&&r instanceof Function&&(r=r()),o.numeric_arg.test(l.type)&&"number"!=typeof r&&isNaN(r))throw new TypeError(i("[sprintf] expecting number but found %T",r));switch(o.number.test(l.type)&&(u=r>=0),l.type){case"b":r=parseInt(r,10).toString(2);break;case"c":r=String.fromCharCode(parseInt(r,10));break;case"d":case"i":r=parseInt(r,10);break;case"j":r=JSON.stringify(r,null,l.width?parseInt(l.width):0);break;case"e":r=l.precision?parseFloat(r).toExponential(l.precision):parseFloat(r).toExponential();break;case"f":r=l.precision?parseFloat(r).toFixed(l.precision):parseFloat(r);break;case"g":r=l.precision?String(Number(r.toPrecision(l.precision))):parseFloat(r);break;case"o":r=(parseInt(r,10)>>>0).toString(8);break;case"s":r=String(r),r=l.precision?r.substring(0,l.precision):r;break;case"t":r=String(!!r),r=l.precision?r.substring(0,l.precision):r;break;case"T":r=Object.prototype.toString.call(r).slice(8,-1).toLowerCase(),r=l.precision?r.substring(0,l.precision):r;break;case"u":r=parseInt(r,10)>>>0;break;case"v":r=r.valueOf(),r=l.precision?r.substring(0,l.precision):r;break;case"x":r=(parseInt(r,10)>>>0).toString(16);break;case"X":r=(parseInt(r,10)>>>0).toString(16).toUpperCase()}o.json.test(l.type)?p+=r:(!o.number.test(l.type)||u&&!l.sign?f="":(f=u?"+":"-",r=r.toString().replace(o.sign,"")),c=l.pad_char?"0"===l.pad_char?"0":l.pad_char.charAt(1):" ",d=l.width-(f+r).length,s=l.width&&d>0?c.repeat(d):"",p+=l.align?f+r+s:"0"===c?f+s+r:s+f+r)}return p}(function(e){if(l[e])return l[e];for(var t,r=e,n=[],i=0;r;){if(null!==(t=o.text.exec(r)))n.push(t[0]);else if(null!==(t=o.modulo.exec(r)))n.push("%");else{if(null===(t=o.placeholder.exec(r)))throw new SyntaxError("[sprintf] unexpected placeholder");if(t[2]){i|=1;var a=[],s=t[2],c=[];if(null===(c=o.key.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(a.push(c[1]);""!==(s=s.substring(c[0].length));)if(null!==(c=o.key_access.exec(s)))a.push(c[1]);else{if(null===(c=o.index_access.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");a.push(c[1])}t[2]=a}else i|=2;if(3===i)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");n.push({placeholder:t[0],param_no:t[1],keys:t[2],sign:t[3],pad_char:t[4],align:t[5],width:t[6],precision:t[7],type:t[8]})}r=r.substring(t[0].length)}return l[e]=n}(e),arguments)}function a(e,t){return i.apply(null,[e].concat(t||[]))}var l=Object.create(null);"undefined"!=typeof window&&(window.sprintf=i,window.vsprintf=a,void 0===(n=function(){return{sprintf:i,vsprintf:a}}.call(t,r,t,e))||(e.exports=n))}()},5397:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(1364),o={contextDelimiter:"",onMissingKey:null};function i(e,t){var r;for(r in this.data=e,this.pluralForms={},this.options={},o)this.options[r]=void 0!==t&&r in t?t[r]:o[r]}i.prototype.getPluralForm=function(e,t){var r,o,i,a=this.pluralForms[e];return a||("function"!=typeof(i=(r=this.data[e][""])["Plural-Forms"]||r["plural-forms"]||r.plural_forms)&&(o=function(e){var t,r,n;for(t=e.split(";"),r=0;r<t.length;r++)if(0===(n=t[r].trim()).indexOf("plural="))return n.substr(7)}(r["Plural-Forms"]||r["plural-forms"]||r.plural_forms),i=(0,n.A)(o)),a=this.pluralForms[e]=i),a(t)},i.prototype.dcnpgettext=function(e,t,r,n,o){var i,a,l;return i=void 0===o?0:this.getPluralForm(e,o),a=r,t&&(a=t+this.options.contextDelimiter+r),(l=this.data[e][a])&&l[i]?l[i]:(this.options.onMissingKey&&this.options.onMissingKey(r,e),0===i?r:n)}},3029:(e,t,r)=>{"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}r.d(t,{A:()=>n})},4467:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(9922);function o(e,t,r){return(t=(0,n.A)(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}},2327:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(2284);function o(e,t){if("object"!=(0,n.A)(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!=(0,n.A)(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}},9922:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(2284),o=r(2327);function i(e){var t=(0,o.A)(e,"string");return"symbol"==(0,n.A)(t)?t:t+""}},2284:(e,t,r)=>{"use strict";function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}r.d(t,{A:()=>n})}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}function n(e){return function(e){if(Array.isArray(e))return d(e)}(e)||o(e)||c(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function i(e){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i(e)}function a(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e){if(Array.isArray(e))return e}function s(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=c(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,l=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){l=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(l)throw i}}}}function c(e,t){if(e){if("string"==typeof e)return d(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var u=r(8095).validateField,f=r(4746),m=f.getRangeSettingsDefaults,_=f.validateNumberRangeSetting,p=f.validateStepSetting,g=f.validateRangeSettings;window.FrmFormsConnect=window.FrmFormsConnect||function(e,t,r){var n={messageBox:null,reset:null,setElements:function(){n.messageBox=e.querySelector(".frm_pro_license_msg"),n.reset=e.getElementById("frm_reconnect_link")}},o={init:function(){n.setElements(),r(e.getElementById("frm_deauthorize_link")).on("click",o.deauthorize),r(".frm_authorize_link").on("click",o.authorize),r(".frm-dashboard-license-options").on("click","#frm_deauthorize_link",o.deauthorize),r(".frm-dashboard-license-options").on("click","#frm_reconnect_link",o.reauthorize),null!==n.reset&&r(n.reset).on("click",o.reauthorize)},authorize:function(){var t=this,n=this.getAttribute("data-plugin"),i=e.getElementById("edd_".concat(n,"_license_key")),a=i.value,l=e.getElementById("proplug-wpmu");this.classList.add("frm_loading_button"),l=l&&l.checked?1:0,r.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_activate",license:a,plugin:n,wpmu:l,nonce:frmGlobal.nonce},success:function(e){o.afterAuthorize(e,i),t.classList.remove("frm_loading_button")}})},afterAuthorize:function(e,t){!0===e.success&&(t.value="•••••••••••••••••••"),wp.hooks.doAction("frm_after_authorize",e),o.showMessage(e)},showProgress:function(e){null===n.messageBox&&n.setElements();var t=n.messageBox;null!==t&&(!0===e.success?(t.classList.remove("frm_error_style"),t.classList.add("frm_message","frm_updated_message")):(t.classList.add("frm_error_style"),t.classList.remove("frm_message","frm_updated_message")),t.classList.remove("frm_hidden"),t.innerHTML=e.message)},showMessage:function(r){null===n.messageBox&&n.setElements();var i=n.messageBox;!0===r.success&&(o.showAuthorized(!0),o.showInlineSuccess(),wp.hooks.doAction("frmAdmin.afterLicenseAuthorizeSuccess",{msg:r})),o.showProgress(r),""!==r.message&&(setTimeout(function(){i.innerHTML="",i.classList.add("frm_hidden"),i.classList.remove("frm_error_style","frm_message","frm_updated_message")},1e4),e.querySelector(".frm-admin-page-dashboard")&&setTimeout(function(){t.location.reload()},1e3))},showAuthorized:function(t){var r=t?"unauthorized":"authorized",n=t?"authorized":"unauthorized",o=e.querySelectorAll(".frm_".concat(r,"_box"));o.length&&o.forEach(function(e){e.className=e.className.replace("frm_".concat(r,"_box"),"frm_".concat(n,"_box"))})},showInlineSuccess:function(){var t=e.querySelectorAll(".frm-confirm-msg [data-success]");t.length&&t.forEach(function(e){e.innerHTML=frmAdminBuild.purifyHtml(e.getAttribute("data-success"))})},reauthorize:function(){return this.innerHTML='<span class="frm-wait frm_spinner" style="visibility:visible;float:none"></span>',r.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_reset_cache",plugin:"formidable_pro",nonce:frmGlobal.nonce},success:function(e){n.reset.textContent=e.message,"1"===n.reset.getAttribute("data-refresh")&&t.location.reload()}}),!1},deauthorize:function(){if(!confirm(frmGlobal.deauthorize))return!1;var t=this.getAttribute("data-plugin"),n=e.getElementById("edd_".concat(t,"_license_key")),i=n.value,a=this;return this.innerHTML='<span class="frm-wait frm_spinner" style="visibility:visible;"></span>',r.ajax({type:"POST",url:ajaxurl,data:{action:"frm_addon_deactivate",license:i,plugin:t,nonce:frmGlobal.nonce},success:function(){o.showAuthorized(!1),n.value="",a.replaceWith("Disconnected"),wp.hooks.doAction("frmAdmin.afterLicenseDeauthorizeSuccess",{})}}),!1}};return o}(document,window,jQuery),window.frmAdminBuildJS=function(){var e,t,f=frm_admin_js,v=frmDom,y=v.tag,h=v.div,b=v.span,w=v.a,j=v.svg,x=v.img,E=frmDom.util.onClickPreventDefault,k=frmDom.ajax.doJsonPost;f.contextualShortcodes=(t=null===(e=document.getElementById("frm_adv_info"))||void 0===e?void 0:e.dataset.contextualShortcodes)?((t=JSON.parse(t)).addressSelector="[id^=email_to], [id^=from_], [id^=cc], [id^=bcc]",t.bodySelector="[id^=email_message_]",t):[];var Q,S,A,L={save:j({href:"#frm_save_icon"}),drag:j({href:"#frm_drag_icon",classList:["frm_drag_icon","frm-drag"]})},I=jQuery(document.getElementById("frm-show-fields")),q=document.getElementById("new_fields"),B=document.getElementById("form_id"),C=!1,N=0,T=0,O=0,F={},D=0,M=wp.i18n,P=M.__,R=M.sprintf,z={dragging:!1,draggable:null,offsetsRefreshed:!1,submitButtonRow:null};B&&(T=B.value);var H,G=new URL(window.location.href),U=G.searchParams,W=document.getElementById("frm_builder_page");function $(e){e.stopPropagation(),e.preventDefault(),V(this)}function V(e){var t=e.getAttribute("data-frmverify"),r=e.getAttribute("data-loaded-from");return null===t||"frm-confirmed-click"===e.id||("entries-list"===r?wp.hooks.applyFilters("frm_on_multiple_entries_delete",{link:e,initModal:ea}):function(e){var t=ea("#frm_confirm_modal","400px"),r=document.getElementById("frm-confirmed-click");if(!1===t)return!1;r&&(r.style.display="block");var n=e.getAttribute("data-frmverify"),o=n?e.getAttribute("data-frmverify-btn"):"",i=jQuery(".frm-confirm-msg");i.empty(),n&&(i.append(document.createTextNode(n)),o&&(null==r||r.classList.add(o)));var a=e.dataset;if(r){for(var l in r.dataset)r.removeAttribute("data-".concat(l));for(var s in a)"frmverify"!==s&&r.setAttribute("data-".concat(s),a[s])}return wp.hooks.doAction("frmAdmin.beforeOpenConfirmModal",{$info:t,link:e}),t.dialog("open"),null==r||r.setAttribute("href",e.getAttribute("href")||e.getAttribute("data-href")),!1}(e))}function K(e,t){var r=ea("#frm_info_modal",t||"400px");if(!1===r)return!1;"string"==typeof e&&(e={msg:e}),e=Object.assign({title:"",msg:P("Are you sure?","formidable"),img:"",closeText:P("Got it!","formidable"),actionUrl:"",actionText:"",noCenter:!1},e);var n=r[0].querySelector(".info-modal-title");n.textContent=e.title||"",n.classList.toggle("frm_hidden",!e.title),e.msg&&(r[0].querySelector(".frm-info-msg").innerHTML=Tn(e.msg)),r[0].querySelector(".info-modal-img").src=e.img,r[0].querySelector(".info-modal-img-wrapper").classList.toggle("frm_hidden",!e.img);var o=document.getElementById("frm-info-click");e.closeText&&(o.textContent=e.closeText),o.classList.toggle("button-primary",!e.actionUrl),o.classList.toggle("frm-button-primary",!e.actionUrl),o.classList.toggle("button-secondary",Boolean(e.actionUrl)),o.classList.toggle("frm-button-secondary",Boolean(e.actionUrl));var i=r[0].querySelector(".info-modal-action-link");return e.actionUrl&&(i.href=e.actionUrl,e.actionText&&(i.textContent=e.actionText)),i.classList.toggle("frm_hidden",!e.actionUrl),r[0].querySelector(".info-modal-inside").classList.toggle("frmcenter",!e.noCenter),r[0].querySelector(".info-modal-buttons").classList.toggle("frmright",e.noCenter),r.dialog("open"),!1}function J(e){var t=this.getAttribute("data-frmtoggle"),r=this.getAttribute("data-toggletext"),n=jQuery(t);return e.preventDefault(),n.toggle(),null!==r&&""!==r&&(this.setAttribute("data-toggletext",this.innerHTML),this.textContent=r),!1}function X(e){var t=this.getAttribute("data-frmhide"),r=this.getAttribute("data-frmshow"),n=this.getAttribute("data-frmuncheck"),o=n?n.split(","):[];"INPUT"!==this.nodeName||"checkbox"!==this.type||this.checked||(null!==t?(r=t,t=null):null!==r&&(t=r,r=null)),e.preventDefault();var i=this.getAttribute("data-toggleclass")||"frm_hidden";null!==t&&jQuery(t).addClass(i),null!==r&&jQuery(r).removeClass(i);var a=this.parentNode.querySelectorAll("a.current");if(null!==a){for(var l=0;l<a.length;l++)a[l].classList.remove("current");this.classList.add("current")}return o.length&&o.forEach(function(e){var t=document.querySelector(e);t&&(t.checked=!1)}),!1}function Y(){document.querySelectorAll(".tooltip").forEach(function(e){e.remove()})}function Z(){var e,t,r;if(!parseInt(this.getAttribute("data-skip-frm-js"))&&!1!==V(this)){var n=jQuery(this),o=n.attr("data-removeid");void 0===(e=n.attr("data-showlast"))&&(e=""),void 0===(t=n.attr("data-hidelast"))&&(t=""),r=n.attr("data-removemore"),""!==e?n.closest(".frm_add_remove").find(".frm_remove_tag:visible").length>1&&(e="",t=""):0===o.indexOf("frm_postmeta_")&&(jQuery("#frm_postmeta_rows .frm_postmeta_row").length<2&&(e=".frm_add_postmeta_row.button"),jQuery(".frm_toggle_cf_opts").length&&jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().length&&(""!==e&&(e+=","),e+="#".concat(jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().attr("id")," .frm_toggle_cf_opts")));var i=document.getElementById(o),a=jQuery(i);return a.fadeOut(300,function(){var r;a.remove(),ci(),""!==t&&(jQuery(t).hide(),function(e){var t=document.querySelector(e);if(t){var r,n=s(t.classList);try{for(n.s();!(r=n.n()).done;){var o=r.value,i=document.querySelector('input[data-toggleclass="'.concat(o,'"]'));if(null!=i&&i.checked)return void(i.checked=!1)}}catch(e){n.e(e)}finally{n.f()}}}(t)),""!==e&&jQuery("".concat(e," a,").concat(e)).removeClass("frm_hidden").fadeIn("slow"),this.closest(".frm_form_action_settings")&&function(e){var t;Io(e),"payment"===e&&["stripe","square","paypal"].forEach(function(e){return Io(e)}),document.querySelector(".frm_form_action_settings")||null===(t=document.querySelector(".frm-no-actions-message"))||void 0===t||t.classList.remove("frm_hidden");var r={type:e};wp.hooks.doAction("frm_after_action_removed",r)}(this.closest(".frm_form_action_settings").querySelector(".frm_action_name").value),null===(r=document.querySelector(".tooltip"))||void 0===r||r.remove()}),void 0!==r&&(r=jQuery(r)).fadeOut(400,function(){r.remove()}),""!==e&&jQuery(this).closest(".frm_logic_rows").fadeOut("slow"),wp.hooks.doAction("frm_admin_tag_removed",o,i),!1}}function ee(){var e,t=document.querySelector("#frm-actions-filter-content .frm-action:not(.frm_hidden)");null===(e=document.getElementById("frm-actions-no-results"))||void 0===e||e.classList.toggle("frm_hidden",t)}function te(e,t){void 0===t&&(t=this),yt(t,!1);var r=jQuery(t).closest(".frm_form_action_settings"),n=e.target;if(r.length&&void 0!==n){var o=n.parentElement.className;if("string"==typeof o&&(o.includes("frm_email_icons")||o.includes("frm_toggle")))return void e.stopPropagation()}var i=r.children(".widget-inside");if(r.length&&i.find("p, div, table").length<1){var a=r.find('input[name$="[ID]"]').val(),l=r.find('input[name$="[post_excerpt]"]').val();l&&(i.html('<span class="frm-wait frm_spinner"></span>'),r.find(".spinner").fadeIn("slow"),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_form_action_fill",action_id:a,action_type:l,nonce:frmGlobal.nonce},success:function(e){i.html(e),Bi(),ho("#".concat(r.attr("id"))),Pi(i),jQuery(t).trigger("frm-action-loaded"),wp.hooks.doAction("frm_filled_form_action",i)}}))}jQuery(t).closest(".frm_field_box").siblings().find(".widget-inside").slideUp("fast"),void 0!==t.className&&t.className.includes("widget-action")||jQuery(t).closest(".start_divider").length<1||((i=jQuery(t).closest("div.widget").children(".widget-inside")).is(":hidden")?i.slideDown("fast"):i.slideUp("fast"))}function re(e,t){Array.from(e.children).forEach(function(e){e.classList.contains("tabs-panel")&&e.id!==t&&!e.classList.contains(t)&&(e.style.display="none")})}function ne(e){e.style.display="block"}function oe(){var e=this.getAttribute("href");if(null===e||"#"!==e.charAt(0))return!1;var t=e.slice(1),r=this.closest("li");r&&(r.classList.add("frm-tabs","active"),Array.from(r.parentNode.children).forEach(function(e){e!==r&&"LI"===e.tagName&&e.classList.remove("frm-tabs","active","starttab")}));var n=this.closest("div");n&&re(n,t);var o=document.getElementById(t);return o&&ne(o),"frm_insert_fields_tab"!==this.id||this.closest("#frm_adv_info")||mt(),!1}function ie(e,t){var r,n,o=(e=jQuery(e)).attr("href");if(void 0!==o&&"#"===o.charAt(0)){var i=o.slice(1);e.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab");var s,d,u=(r=e.closest("div"),n=1,l(r)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,l=[],s=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(l.push(n.value),l.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return l}}(r,n)||c(r,n)||a())[0];if(null!=u&&u.querySelector(".tabs-panel"))re(u,i);else if(null!==document.getElementById("form_global_settings")){var f=e.data("frmajax");e.closest(".frm_wrap").find(".tabs-panel, .hide_with_tabs").hide(),void 0!==f&&"1"==f&&(s=o.replace("#",""),(d=jQuery(".frm_".concat(s,"_ajax"))).length&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_settings_tab",tab:s.replace("_settings",""),nonce:frmGlobal.nonce},success:function(e){d.replaceWith(e)}}))}else jQuery("#frm-categorydiv .tabs-panel, .hide_with_tabs").hide();var m=document.getElementById(i);m&&ne(m),Array.from(document.getElementsByClassName(i)).forEach(function(e){return ne(e)}),vi(),"auto"!==t&&(jQuery(".frm_updated_message").hide(),jQuery(".frm_warning_style:not(.frm_force_visible_warning)").hide()),jQuery(e).closest("#frm_adv_info").length||(jQuery(".frm_form_settings").length?jQuery(".frm_form_settings").attr("action","?page=formidable&frm_action=settings&id=".concat(jQuery('.frm_form_settings input[name="id"]').val(),"&t=").concat(i)):jQuery(".frm_settings_form").attr("action","?page=formidable-settings&t=".concat(i)))}}function ae(e){document.querySelectorAll(e).forEach(function(e){le(e),Array.from(e.children).forEach(function(e){return de(e,".frm-move")});var t=jQuery(e).children('[data-type="divider"]').children(".divider_section_only");t.length&&le(t)})}function le(e){jQuery(e).droppable({accept:".frmbutton, li.frm_field_box",deactivate:ge,over:se,out:ce,tolerance:"pointer"})}function se(e,t){var r=function(e){return e.classList.contains("divider_section_only")&&(e=jQuery(e).nextAll(".start_divider.frm_sorting").get(0)),e}(e.target);if(!Oe(t.draggable[0],r,e))return r.classList.remove("frm-over-droppable"),void jQuery(r).parents("ul.frm_sorting").addClass("frm-over-droppable");document.querySelectorAll(".frm-over-droppable").forEach(function(e){return e.classList.remove("frm-over-droppable")}),r.classList.add("frm-over-droppable"),jQuery(r).parents("ul.frm_sorting").addClass("frm-over-droppable")}function ce(e){e.target.classList.remove("frm-over-droppable")}function de(e,t){var r={helper:ue,revert:"invalid",delay:10,start:fe,stop:me,drag:_e,cursor:"grabbing",cursorAt:{top:0,left:90}};"string"==typeof t&&(r.handle=t),jQuery(e).draggable(r)}function ue(e){var t,r=e.delegateTarget;if(De(r)){var n=document.getElementById("frm-insert-fields").querySelector(".frm_ttext").cloneNode(!0);return n.querySelector("use").setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_field_group_layout_icon"),n.querySelector("span").textContent=P("Field Group","formidable"),n.classList.add("frm_field_box"),n.classList.add("ui-sortable-helper"),n}if(r.classList.contains("frmbutton"))return(t=r.cloneNode(!0)).classList.add("ui-sortable-helper"),r.classList.add("frm-new-field"),t;if(r.hasAttribute("data-ftype")){var o=r.getAttribute("data-ftype");if(t=document.getElementById("frm-insert-fields").querySelector(".frm_t".concat(o)))return(t=t.cloneNode(!0)).classList.add("form-field"),t.classList.add("ui-sortable-helper"),t.cloneNode(!0)}return h({className:"frmbutton"})}function fe(e,t){if(e.target.classList.contains("frm_at_limit"))return $e(),!1;z.dragging=!0,z.draggable=null,z.offsetsRefreshed=!1;var r,n=S;n.classList.add("frm-dragging-field"),document.body.classList.add("frm-dragging"),t.helper.addClass("frm-sortable-helper"),t.helper.initialOffset=n.scrollTop,e.target.classList.add("frm-drag-fade"),Dr(),(r=document.querySelectorAll("ul.start_divider")).length&&r.forEach(function(e){[].slice.call(e.children).forEach(function(e){(0===e.children.length||1===e.children.length&&"ul"===e.firstElementChild.nodeName.toLowerCase()&&0===e.firstElementChild.children.length)&&e.remove()})}),rt(),Ze(),Y()}function me(){z.draggable=null,S.classList.remove("frm-dragging-field"),document.body.classList.remove("frm-dragging");var e=document.querySelector(".frm-drag-fade");e&&e.classList.remove("frm-drag-fade")}function _e(e,t){z.offsetsRefreshed||(z.offsetsRefreshed=!0,z.draggable=jQuery(e.target).draggable("instance")||null,pe(e)),function(e){var t=S.scrollTop;A.scrollTop(function(t,r){var n=e.clientY,o=S.offsetHeight,i=e.clientY-S.offsetTop,a=i-o/2;return i>o-50&&n>5?r+.1*a:i<70&&n<130?r-Math.abs(.1*a):r}),t!==S.scrollTop&&pe(e)}(e);var r=e.target,n=function(){for(var e=document.getElementById("frm-show-fields");e.querySelector(".frm-over-droppable");)e=e.querySelector(".frm-over-droppable");return"frm-show-fields"!==e.id||e.classList.contains("frm-over-droppable")||(e=!1),e}(),o=document.getElementById("frm_drag_placeholder");if(Oe(r,n,e)){o||(o=y("li",{id:"frm_drag_placeholder",className:"sortable-placeholder"}));var i,a=t.helper.get(0);if((a.classList.contains("form-field")||a.classList.contains("frm_field_box"))&&(a.style.transform="translateY(".concat((i=t.helper,S.scrollTop-i.initialOffset),"px)")),"frm-show-fields"===n.id||n.classList.contains("start_divider"))return o.style.left=0,void function(e){var t,r=e.y,n=e.placeholder,o=jQuery(e.droppable),i=ve(o);if(0===i.length)o.prepend(n),t=0;else{var a=ye(o,r,i);if(a===i.length){var l=jQuery(i[a-1]);t=l.offset().top+l.outerHeight(),o.append(n);var s=o.children(".edit_field_type_end_divider");s.length&&o.append(s)}else t=jQuery(i[a]).offset().top,jQuery(i[a]).before(n)}t-=o.offset().top,n.style.top="".concat(t,"px")}({droppable:n,y:e.clientY,placeholder:o});o.style.top="",function(e){var t,r=e.x,n=e.placeholder,o=jQuery(e.droppable),i=be(o);if(i.length){var a=function(e,t){var r,n,o,i,a=be(e);for(i=0,r=a.length-1;r>=0;--r)if(n=a.get(r),t>(o=jQuery(n).offset().left)){i=r,t>o+jQuery(n).outerWidth()/2&&(i=r+1);break}return i}(o,r);if(a===i.length){var l=jQuery(i.get(a-1));t=l.offset().left+l.outerWidth(),o.append(n)}else t=jQuery(i.get(a)).offset().left,jQuery(i.get(a)).before(n),t-=0===a?4:8;t-=o.offset().left,n.style.left="".concat(t,"px")}}({droppable:n,x:e.clientX,placeholder:o})}else o&&o.remove()}function pe(e){z.draggable&&jQuery.ui.ddmanager.prepareOffsets(z.draggable,e)}function ge(e,t){if(z.dragging){z.dragging=!1;var r=t.draggable[0],n=document.getElementById("frm_drag_placeholder");if(!n)return t.helper.remove(),void Q();!function(e){if(e.previousElementSibling&&e.previousElementSibling.classList.contains("frm-is-collapsed")){var t=jQuery(e).prevUntil('[data-type="break"]');if(t.length){var r=t.find(".frm-collapse-page").get(0);r&&r.click()}}}(n);var o=t.helper.parent(),i=t.helper.get(0).closest("ul.start_divider"),a=n.closest("ul.start_divider");r.classList.contains("frm-new-field")?function(e){if(Ie(e))wp.hooks.doAction("frm_stopped_inserting_by_dragging",e);else{var t=document.getElementById("frm_drag_placeholder"),r="".concat(e.replace("|","-"),"_").concat(Te()),n=y("li",{id:r,className:"frm-wait frmbutton_loadingnow"}),o=jQuery(n),i=ke(jQuery(t)),a=Qe(i),l=Se(i);t.parentNode.insertBefore(n,t),t.remove(),we(o);var s=0;"summary"===e&&(s=jQuery(".frmbutton_loadingnow#".concat(r)).prevAll('li[data-type="break"]').length?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:Le(e,l,a,s),success:function(t){qe(t,o);var r=Be(t);r&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:r,fieldType:e,form_id:a})},error:Ne})}}(r.id):(function(e,t){t.parentNode.insertBefore(e,t)}(r,n),function(e){if("UL"===e.nodeName&&!e.classList.contains("start_divider")&&"frm-show-fields"!==e.id){var t=e.closest("li");t&&!t.classList.contains("ui-draggable")&&de(t,".frm-move")}}(n.parentElement));var l=i?parseInt(i.closest(".edit_field_type_divider").getAttribute("data-fid")):0,s=a?parseInt(a.closest(".edit_field_type_divider").getAttribute("data-fid")):0;n.remove(),t.helper.remove();var c=o.length?be(o):[];!function(e,t){var r;e.length&&(t.length?we(t.first()):(r=e.get(0).closest("li.frm_field_box"))&&!r.classList.contains("edit_field_type_divider")&&r.remove())}(o,c),function(e,t){0===t.length&&1===be(jQuery(e.parentNode)).length||we(jQuery(e))}(r,c),l!==s&&Ae(jQuery(r),i),Q()}}function ve(e){var t=e.get(0);return t?Array.from(t.children).filter(function(e){return!e.classList.contains("edit_field_type_end_divider")}):[]}function ye(e,t,r){if(!document.querySelector(".frm-has-fields .frm_no_fields"))return 0;for(var n=r||ve(e),o=0,i=n.length-1,a=-1;o<=i;){var l=Math.floor((o+i)/2);t>n[l].getBoundingClientRect().top?(a=l,o=l+1):i=l-1}if(-1===a)return 0;var s=n[a].getBoundingClientRect();return t>s.top+s.height/2?a+1:a}function he(){document.querySelectorAll("ul#frm-show-fields, ul.start_divider").forEach(function(e){e.childNodes.forEach(function(e){void 0!==e.classList&&(e.classList.contains("edit_field_type_end_divider")||void 0!==e.classList&&e.classList.contains("form-field")&&dt(e))})}),$n(),document.querySelectorAll(".edit_field_type_end_divider").forEach(function(e){return e.parentNode.append(e)}),document.querySelectorAll("li.form_field_box:not(.form-field)").forEach(function(e){return!e.children.length&&e.remove()}),Wn();var e=new Event("frm_sync_after_drag_and_drop",{bubbles:!1});document.dispatchEvent(e)}function be(e){var t=jQuery(),r=e.get(0);return r.children?(Array.from(r.children).forEach(function(e){if("none"!==e.style.display){var r=e.classList;!r.contains("form-field")||r.contains("edit_field_type_end_divider")||r.contains("frm-sortable-helper")||(t=t.add(e))}}),t):t}function we(e,t){var r;void 0===t&&(t="even");var n=e.parent().children("li.form-field, li.frmbutton_loadingnow").not(".edit_field_type_end_divider"),o=n.length,i=["frm_full","frm_half","frm_third","frm_fourth","frm_sixth","frm_two_thirds","frm_three_fourths","frm1","frm2","frm3","frm4","frm5","frm6","frm7","frm8","frm9","frm10","frm11","frm12"];"even"===t&&5!==o?n.each(Ee(i,pr(o))):"clear"===t?n.each(Ee(i,"")):(r=["left","right","middle","even"].includes(t)?function(e){return _r(o,t,e)}:function(e){return Ar(t[e])},n.each(Ee(i,r))),je(e.parent(),n.length)}function je(e,t){if(void 0!==e.offset()){var r=t>=2,n=document.getElementById("frm_field_group_controls");if(!n){if(!r)return;(n=h()).id="frm_field_group_controls",n.setAttribute("role","group"),n.setAttribute("tabindex",0),function(e){var t=document.createElement("span");t.innerHTML='<svg class="frmsvg"><use href="#frm_field_group_layout_icon"></use></svg>';var r=P("Set Row Layout","formidable");xe(t,r),cr(t,r);var n=document.createElement("span");n.innerHTML='<svg class="frmsvg"><use href="#frm_thick_move_icon"></use></svg>',n.classList.add("frm-move");var o=P("Move Field Group","formidable");xe(n,o),cr(n,o),e.innerHTML="",e.append(t),e.append(n),e.append(function(){var e=b({className:"dropdown"}),t=w({className:"frm_bstooltip frm-hover-icon frm-dropdown-toggle dropdown-toggle",children:[b({child:j({href:"#frm_thick_more_vert_icon"})}),b({className:"screen-reader-text",text:P("Toggle More Options Dropdown","formidable")})]});frmDom.setAttributes(t,{title:P("More Options","formidable"),"data-bs-toggle":"dropdown","data-bs-container":"body","data-bs-display":"static"}),cr(t,P("More Options","formidable")),e.append(t);var r=h({className:"frm-dropdown-menu dropdown-menu dropdown-menu-right"});return r.setAttribute("role","menu"),e.append(r),e}())}(n),W.append(n)}e.append(n),n.style.display=r?"block":"none"}}function xe(e,t){e.setAttribute("data-bs-toggle","tooltip"),e.setAttribute("data-bs-container","body"),e.setAttribute("title",t),e.addEventListener("mouseover",function(){e.__bootstrapTooltip||(e.__bootstrapTooltip=new bootstrap.Tooltip(e))})}function Ee(e,t){return function(r){for(var n="function"==typeof t?t(r):t,o=e.length,i=!1,a=0;a<o;++a){var l=e[a];if(this.classList.contains(l)){i=l;break}}var s=this.dataset.fid;if(void 0!==s){Qo(document.getElementById("frm-single-settings-".concat(s)));var c=document.getElementById("frm_classes_".concat(s));c&&(!1===i?""!==n&&(c.value=c.value.concat(" ".concat(n))):(this.classList.remove(i),c.value=c.value.replace(i,n)),this.classList.contains("frm_first")&&(this.classList.remove("frm_first"),c.value=c.value.replace("frm_first","").trim()),0===r&&(this.classList.add("frm_first"),c.value=c.value.concat(" frm_first")),jQuery(c).trigger("change"))}else this.classList.add(n)}}function ke(e){var t="";return void 0===e||e.hasClass("edit_field_type_divider")||(t=e.closest(".edit_field_type_divider")),t}function Qe(e){var t="";if(void 0!==e[0]){var r=e.children(".start_divider");if(r.children(".edit_field_type_end_divider").appendTo(r),void 0!==e.attr("data-formid")){var n=e.attr("data-fid");t=jQuery('input[name="field_options[form_select_'.concat(n,']"]')).val()}}return void 0!==t&&""!==t||(t=T),t}function Se(e){var t=0;return void 0!==e[0]&&(t=e.attr("id").replace("frm_field_id_","")),t}function Ae(e,t){if(e.hasClass("form-field")){var r=e.attr("id").replace("frm_field_id_",""),n=ke(e),o=Qe(n),i=Se(n),a=t?Qe(jQuery(t.parentNode)):0;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_update_field_after_move",form_id:o,field:r,section_id:i,previous_form_id:a,nonce:frmGlobal.nonce},success:function(){$n(),function(e,t){document.getElementById("frm_in_section_".concat(e)).value=t}(r,i)}})}else be(jQuery(e.get(0).firstChild)).each(function(){Ae(jQuery(this),t)})}function Le(e,t,r,n){var o={action:"frm_insert_field",form_id:r,field_type:e,section_id:t,nonce:frmGlobal.nonce,has_break:n};return t>0&&document.getElementById("form_id").value!==r||(o.last_row_field_ids=function(){var e=document.querySelector(".edit_field_type_submit");if(!e)return[];for(var t=e.parentNode.children,r=[],n=0;n<t.length;n++)r.push(t[n].dataset.fid);return r}()),o}function Ie(e){return wp.hooks.applyFilters("frm_should_stop_inserting_field",!1,e)}function qe(e,t){var r;document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var n=t.siblings("li.form-field").not(".edit_field_type_end_divider");n.length?(r=Ce(e),t.get(0).parentNode.parentNode.classList.contains("ui-draggable")||de(t.get(0).parentNode.parentNode,".frm-move")):r=ct(e),t.replaceWith(r),Wn(),ut(e,!1),n.length&&we(n.first()),$n(),n.length?de(r.get(0),".frm-move"):(le(r.get(0).querySelector("ul.frm_sorting")),de(r.get(0).querySelector("li.form-field"),".frm-move"))}function Be(e){var t=e.match(/data-fid="(\d+)"/);return t?parseInt(t[1]):0}function Ce(e){var t=h();return t.innerHTML=e,jQuery(t.firstChild)}function Ne(e,t,r){!function(e,t){(function(e){return 0===e.status||0===e.readyState})(t)||K("".concat(e,". Please try again."))}(r,e)}function Te(){return++O}function Oe(e,t,r){if(!1===t)return!1;if(t.closest(".frm-sortable-helper"))return!1;var n=e.classList.contains("edit_field_type_submit"),o=!e.classList.contains("form_field")&&Boolean(e.querySelector(".edit_field_type_submit"));if("frm-show-fields"===t.id){var i=ye(jQuery(t),r.clientY);if(n||o)return i>t.childElementCount-1;var a=function(e){if(z.submitButtonRow&&z.submitButtonRow.parentNode===e)return z.submitButtonRow;var t=e.querySelector(".edit_field_type_submit");return z.submitButtonRow=t?t.closest("#frm-show-fields > li"):null,z.submitButtonRow}(t);return!a||i<=Array.prototype.indexOf.call(t.children,a)}if(n)return!(t.classList.contains("start_divider")||!Fe(t.parentElement)&&(!Fe(t.parentElement.nextElementSibling)||e.parentElement.querySelector("li.frm_field_box:not(.edit_field_type_submit)")));var l=t.classList.contains("start_divider")&&null!==t.closest(".repeat_section"),s=null!==t.closest(".repeat_section");if(l||s){if(e.classList.contains("edit_field_type_gdpr")||"gdpr"===e.id)return!1;if(wp.hooks.applyFilters("frm_deny_drop_in_repeater",!1,e))return!1}if(!l){if(!function(e,t){if(e.length<12)return!0;if(e.length>12)return!1;var r=t.attr("data-fid");return 1===jQuery(e).filter('[data-fid="'.concat(r,'"]')).length}(be(jQuery(t)),jQuery(e)))return!1;if("divider"===e.id&&t.closest(".start_divider"))return!1}return e.classList.contains("frm-new-field")?function(e,t){var r=e.classList,n=r.contains("frm_tbreak"),o=r.contains("frm_thidden"),i=r.contains("frm_tdivider"),a=r.contains("frm_tform"),l=r.contains("frm_tuser_id");return"frm-show-fields"===t.id||t.classList.contains("start_divider")?!(n||o||i||a)||(!(t.classList.contains("start_divider")||null!==t.closest(".start_divider"))||!a&&!i):!(Me(t)||o||n||l)}(e,t):function(e,t){if(De(e))return function(e,t){return!(!t.classList.contains("start_divider")||null!==e.querySelector(".start_divider"))}(e,t);if(e.classList.contains("edit_field_type_break"))return!1;if(t.classList.contains("start_divider"))return function(e){return!e.classList.contains("edit_field_type_form")&&!e.querySelector(".edit_field_type_form")&&!(e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"))}(e);var r=e.classList.contains("edit_field_type_hidden"),n=e.classList.contains("edit_field_type_user_id");return!r&&!n&&function(e,t){if(Me(t))return!1;if(jQuery(e).children("ul.frm_sorting").not(".start_divider").length>0)return!1;var r=e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"),n=e.classList.contains("edit_field_type_form");return!(null!==t.closest(".start_divider")&&(r||n))}(e,t)}(e,t)}function Fe(e){return null==e?void 0:e.matches("#frm-show-fields > li:last-child")}function De(e){return e.classList.contains("frm_field_box")&&!e.classList.contains("form-field")}function Me(e){return null!==e.querySelector(".edit_field_type_break, .edit_field_type_hidden, .edit_field_type_user_id")}var Pe=0,Re=!1;function ze(){for(;Pe<3;){var e=document.querySelector("#frm-show-fields .frm_field_loading:not(.frm_load_now)");if(!e)break;He(e)}Re&&0===Pe&&(on(),Ke())}function He(e){var t=[],r=function(e){e.classList.add("frm_load_now"),e.classList.contains("frm_field_loading")&&t.push(e.dataset.fid)};r(e);for(var n=Ge(e);n&&t.length<40;)r(n),n=Ge(n);t.length&&(++Pe,Re=!0,jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_load_field",field_ids:t,form_id:T,nonce:frmGlobal.nonce},success:Ue,complete:function(){--Pe,ze()}}))}function Ge(e){var t;return e.nextElementSibling?e.nextElementSibling:null===(t=e.parentNode)||void 0===t||null===(t=t.closest(".frm_field_box"))||void 0===t||null===(t=t.nextElementSibling)||void 0===t?void 0:t.querySelector(".form-field")}function Ue(e){var t;if(0===(e=e.replace(/^\s+|\s+$/g,"")).indexOf("{")){var r=JSON.parse(e),n=[],o=[];for(t in r)if(Object.hasOwn(r,t)){jQuery("#frm_field_id_".concat(t)).replaceWith(r[t].html),o.push({id:t,type:r[t].type});var i=document.getElementById("frm_field_id_".concat(t));i&&(n.push(i),i.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),i.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")})),ae("#frm_field_id_".concat(t,".edit_field_type_divider ul.frm_sorting")),de(document.getElementById("frm_field_id_".concat(t)))}Bi(n),z.dragging&&pe();var a=new Event("frm_ajax_loaded_field",{bubbles:!1});a.frmFields=o,document.dispatchEvent(a)}else jQuery(".frm_load_now").removeClass(".frm_load_now").html("Error")}function We(){var e=jQuery(this);if(e.hasClass("disabled"))return!1;var t=e.closest(".frmbutton"),r=t.attr("id");if(t.hasClass("frm_at_limit"))return $e(),!1;if(frm_admin_js.paymentsSettingsModal&&"object"===i(frm_admin_js.paymentsSettingsModal)&&["product","quantity","total"].includes(r))return K(frm_admin_js.paymentsSettingsModal),!1;if(!Ie(r)){var n=0;"summary"===r&&(n=I.children('li[data-type="break"]').length>0?1:0);var o=T;return jQuery.ajax({type:"POST",url:ajaxurl,data:Le(r,0,o,n),success:function(e){Ve(e);var t=Be(e);t&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:e,fieldId:t,fieldType:r,form_id:o})},error:Ne}),!1}}function $e(){var e=document.querySelector(".frm_wrap");if(e){var t=document.createElement("a");t.setAttribute("data-frmverify",P("This field type has reached its limit.","formidable")),e.append(t),t.click(),t.remove();var r=document.getElementById("frm-confirmed-click");r&&(r.style.display="none")}}function Ve(e){document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var t=ct(e),r=I[0].querySelector(".edit_field_type_submit");r?jQuery(r.closest(".frm_field_box:not(.form-field)")).before(t):I.append(t),ut(e,!0),t.each(function(){le(this.querySelector("ul.frm_sorting")),de(this.querySelector(".form-field"),".frm-move")})}function Ke(){var e=!0,t=document.querySelectorAll(".frmjs_prod_field_opt_cont");I.find("li.edit_field_type_product").length>1&&(e=!1);for(var r=0;r<t.length;r++)t[r].classList.toggle("frm_hidden",e)}function Je(){var e=jQuery(this).closest("li.form-field"),t=this.getAttribute("frm-target-row-id");if(null!=t&&t.startsWith("frm_field_group_")||function(e){if(e.classList.contains("frm-page-collapsed"))return!1;var t=e.closest("li.frm_field_box:not(.form-field)");return!t||be(jQuery(t.querySelector("ul"))).length<12}(e.get(0))){Ze();var r,n=e.data("fid"),o=function(e){var t=[];return jQuery(document.getElementById("frm_field_id_".concat(e))).find("li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)").each(function(){t.push(jQuery(this).data("fid"))}),t}(n);return null!==t&&(r=this.getAttribute("frm-field-order")),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_duplicate_field",field_id:n,form_id:T,children:o,nonce:frmGlobal.nonce},success:function(o){var i,a,l;if(null!==t&&(a=document.getElementById(t)))return l=Ce(o),jQuery(a).append(l),de(l.get(0),".frm-move"),null!==r&&a.lastElementChild.setAttribute("frm-field-order",r),jQuery(a).trigger("frm_added_duplicated_field_to_row",{duplicatedFieldHtml:o,originalFieldId:n}),ut(o,!1),void Xe(e.get(0),l.get(0));e.siblings("li.form-field").length?(l=Ce(o),e.after(l),we(e),de(l.get(0),".frm-move")):(l=ct(o),e.parent().parent().after(l),le(l.get(0).querySelector("ul.frm_sorting")),de(l.get(0).querySelector("li.form-field"),".frm-move")),Wn(),ut(o,!1),Ye(n,o),Vn(l.find(".start_divider")),null===(i=e[0].querySelector(".frm-dropdown-menu.dropdown-menu-right"))||void 0===i||i.classList.remove("show"),Xe(e.get(0),l.get(0))}}),!1}K(R(P("You can only have a maximum of %1$d fields in a field group. Delete or move out a field from the group and try again.","formidable"),12))}function Xe(e,t){var r,n=e.closest(".frm-field-group-hover-target");if(n&&De(n.parentElement)){var o=e.dataset.fid,i=null===(r=document.getElementById("frm_classes_".concat(o)))||void 0===r?void 0:r.value;if(i&&(i=i.replace("frm_first",""),!t.className.includes(i))){t.className+=" ".concat(i);var a=document.getElementById("frm_classes_".concat(t.dataset.fid));a&&(a.value=i)}}}function Ye(e,t){var r=document.getElementById("frm-single-settings-".concat(e));if(r){var n=jQuery(t).attr("data-fid");if(void 0!==n){var o=document.getElementById("frm-single-settings-".concat(n));if(o){var i=["name","required","unique","read_only","placeholder","description","size","max","format","prepend","append","separate_value"];r.querySelectorAll('input[name^="field_options["], textarea[name^="field_options["]').forEach(function(t){var r,a=((r=t.name.substr(14).split("_")).pop(),r.join("_"));if("options"!==a){if(i.includes(a)){var l=t.matches("input")?"input":"textarea",s=o.querySelector("".concat(l,'[name="field_options[').concat(a,"_").concat(n,']"]'));null!==s&&("checkbox"===t.type?t.checked!==s.checked&&jQuery(s).trigger("click"):"text"!==t.type&&"textarea"!==l||t.value!==s.value&&(s.value=t.value,jQuery(s).trigger("change")))}}else!function(e,t,r,n){var o=e.name.substr(23+"".concat(r).length),i="field_options[options_".concat(n,"]").concat(o),a=t.querySelector('input[name="'.concat(i,'"]'));null!==a&&a.value!==e.value&&(a.value=e.value,jQuery(a).trigger("change"))}(t,o,e,n)});var a=r.querySelector('input[name="default_value_'.concat(e,'"]'));if(null!==a){var l=o.querySelector('input[name="default_value_'.concat(n,'"]'));null!==l&&a.value!==l.value&&(l.value=a.value,jQuery(l).trigger("change"))}}}}}function Ze(){var e=document.querySelector(".frm-field-settings-open");e&&(e.classList.remove("frm-field-settings-open"),jQuery(document).off("click","#frm_builder_page",et),jQuery(".frm-field-action-icons .dropdown.open").removeClass("open"))}function et(e){jQuery(e.originalEvent.target).closest(".frm-field-action-icons").length||Ze()}function tt(e){var t=Boolean(e.ctrlKey||e.metaKey||e.shiftKey);jQuery(W).toggleClass("frm-multiselect-key-is-down",t),function(e){if(!S.classList.contains("frm-dragging-field")&&null===document.querySelector(".frm-field-group-hover-target .frm-field-settings-open")){var t=document.elementFromPoint(e.clientX,e.clientY);if(null!==t&&!t.classList.contains("edit_field_type_divider")){var r=t.closest("ul.frm_sorting");if(null!==r&&!r.classList.contains("start_divider")&&"frm-show-fields"!==r.id){var n=rt();!1===n||jQuery(n).is(r)||Br(),je(jQuery(r),be(jQuery(r)).length),r.classList.add("frm-field-group-hover-target"),jQuery("#wpbody-content").on("mousemove",nt)}}}}(e)}function rt(){var e=document.getElementById("frm_field_group_controls");e&&(e.style.display="none");var t=document.querySelector(".frm-field-group-hover-target");return!!t&&(jQuery("#wpbody-content").off("mousemove",nt),t.classList.remove("frm-field-group-hover-target"),t)}function nt(e){var t=document.elementFromPoint(e.clientX,e.clientY);null!==t&&null!==t.closest("#frm-show-fields")||(rt(),Y())}function ot(e){Dr(),setTimeout(function(){var t=document.querySelector(".dropdown .frm-dropdown-menu.show");if(t){null===t.getAttribute("aria-label")&&t.setAttribute("aria-label",P("More Options","formidable")),0===t.children.length&&function(e,t){var r=t?"_field_group":"_field",n=[lt(t),st(t)];t||n.push({class:"frm_select",icon:"frm_settings_icon",label:P("Field Settings","formidable")}),n.forEach(function(t){var n=document.createElement("div");n.classList.add("frm_more_options_li","dropdown-item");var o=document.createElement("a");o.classList.add(t.class+r),o.setAttribute("href","#"),cr(o);var i=document.createElement("span");i.textContent=t.label,o.innerHTML='<svg class="frmsvg"><use href="#'.concat(t.icon,'"></use></svg>'),o.append(document.createTextNode(" ")),o.append(i),n.append(o),e.append(n)})}(t,!0===e);var r=jQuery(t);r.offset().left>jQuery(window).width()-r.outerWidth()?t.style.left="".concat(-r.outerWidth(),"px"):S&&r.offset().left<S.getBoundingClientRect().left&&(t.style.right="auto",t.style.left="0");var n=t.firstElementChild.querySelector("a");n&&n.focus()}},0)}function it(){ot(!0)}function at(e){var t=e.target.closest(".frm-section-collapsed");t&&("show"===e.type?t.style.zIndex=3:t.style.zIndex=1)}function lt(e){var t={class:"frm_delete",icon:"frm_delete_icon"};return t.label=P(e?"Delete Group":"Delete","formidable"),t}function st(e){var t={class:"frm_clone",icon:"frm_clone_icon"};return t.label=P(e?"Duplicate Group":"Duplicate","formidable"),t}function ct(e){var t=h();"string"==typeof e?t.innerHTML=e:t.append(e);var r=jQuery();return Array.from(t.children).forEach(function(e){r=r.add(jQuery("<li>").addClass("frm_field_box").html(jQuery("<ul>").addClass("frm_grid_container frm_sorting").append(e)))}),r}function dt(e){var t=y("ul",{className:"frm_grid_container frm_sorting"}),r=y("li",{className:"frm_field_box",child:t});e.replaceWith(r),t.append(e),le(t),de(r,".frm-move")}function ut(e,t){var r,n,o=/id="(\S+)"/.exec(e),a=document.getElementById(o[1]),l="#".concat(o[1],".edit_field_type_divider ul.frm_sorting.start_divider"),s=jQuery(l),c=a.getAttribute("data-type");r=e,(n=h()).innerHTML=r,n.querySelectorAll(".form-field").forEach(ft);var d,u,f=!1;if(ci(),ae(l),"quantity"===c&&function(e){var t=e.getAttribute("data-fid"),r=document.getElementById("field_options[product_field_".concat(t,"]"));r&&(xt(r),Qo(document.getElementById("frm-single-settings-".concat(t))))}(a),"product"!==c&&"quantity"!==c||Ke(),s.length)s.parent(".frm_field_box").children(".frm_no_section_fields").addClass("frm_block");else{var m=jQuery(a).closest("ul.frm_sorting.start_divider");m.length&&(Vn(m),f=!0)}e.includes("frm-collapse-page")&&on(),u="frm-newly-added",(d=a).classList?d.classList.add(u):d.className+=" ".concat(u),setTimeout(function(){a.classList.remove("frm-newly-added")},1e3);var _,p=a.querySelector("#frm-last-row-fields-order");if(p&&((_=JSON.parse(p.value))&&"object"===i(_)&&Object.keys(_).forEach(function(e){var t=document.querySelector('input[name="field_options[field_order_'.concat(e,']"]'));t&&(t.value=_[e])})),t){var g=a.getBoundingClientRect(),v=document.getElementById("post-body-content");g.top>=0&&g.left>=0&&g.right<=(window.innerWidth||document.documentElement.clientWidth)&&g.bottom<=(window.innerHeight||document.documentElement.clientHeight)||v.scroll({top:v.scrollHeight,left:0,behavior:"smooth"}),!1===f&&Vn(s)}_t(),Bi(),document.getElementById("frm-show-fields").classList.remove("frm-over-droppable"),function(e){var t=document.getElementById(e);null!=t&&t.dataset.limit&&$r(e)>=t.dataset.limit&&t.classList.add("frm_at_limit")}(c),a.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),a.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")});var y=new Event("frm_added_field",{bubbles:!1});y.frmField=a,y.frmSection=l,y.frmType=c,y.frmToggles=f,document.dispatchEvent(y)}function ft(e){if(e.dataset.fid){var t=document.getElementById("draft_fields");t&&(""===t.value?t.value=e.dataset.fid:t.value.split(",").includes(e.dataset.fid)||(t.value+=",".concat(e.dataset.fid)))}}function mt(e){jQuery("#new_fields .frm-single-settings").addClass("frm_hidden"),jQuery("#frm-options-panel > .frm-single-settings").removeClass("frm_hidden"),_t(e)}function _t(e){jQuery("li.ui-state-default.selected").removeClass("selected"),jQuery(".frm-show-field-settings.selected").removeClass("selected"),e||Dr()}function pt(){var e=this.value,t=function(e){var t,r=[],n=e.split(""),o=n.length,i=["{","[","("],a={"}":"{",")":"(","]":"["},l=!1;for(t=0;t<o;t++)i.includes(n[t])?r.push(n[t]):Object.hasOwn(a,n[t])&&r.pop()!==a[n[t]]&&(l=!0);return r.length>0||l?"".concat(f.unmatched_parens,"\n\n"):""}(e);t+=function(e,t){var r=function(e,t){var r="";return function(e){return jQuery(e).siblings('label[for^="calc_type"]').children("input").prop("checked")}(t)||/\[(date|time|email|ip)\]/.test(e)&&(r="".concat(f.text_shortcodes,"\n\n")),r}(e,t);return r+=function(e){var t="";return/\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g.test(e)&&(t+="".concat(f.view_shortcodes,"\n\n")),t}(e)}(e,this),""!==t&&K("".concat(e,"\n\n").concat(t))}function gt(e,t){for(var r=!1,n=0;n<t.length;n++){var o=document.getElementsByName(vt(t[n],e.fieldId));if(o.length&&jQuery(o[0]).val()){r=!0;break}}return r}function vt(e,t){var r=e.indexOf("]");return"field_options".concat(e.substring(0,r),"_").concat(t).concat(e.substring(r))}function yt(e,t){var r=jQuery(e).closest(".frm-single-settings"),n=r.find(".frm-calc-field");if(t||n.length&&""!==n.val()&&!n.is(":hidden")){var o,i=function(e){var t=jQuery(e).find(".frm_code_list");return 1===t.length&&t.hasClass("frm_js_summary_list")}(e),a=r.find('input[name="frm_fields_submitted[]"]').val(),l=(o=t?e:document.getElementById("frm-calc-box-".concat(a))).querySelector(".frm_code_list"),s=function(e,t){var r=JSON.parse(e.getAttribute("data-exclude"));if(t){var n=function(){for(var e=[],t=document.getElementsByClassName("frm_include_extras_field"),r=0;r<t.length;r++)t[r].checked&&e.push(t[r].value);return e}();if(n.length)for(var o=0;o<r.length;o++)n.includes(r[o])&&(r.splice(o,1),o--)}return r}(l,i),c=function(e){var t=[];if(!Array.isArray(e))return t;for(var r=0;r<e.length;r++)e[r].startsWith("[")&&(t.push(e[r]),e.splice(r,1),r--);return t}(s),d=wp.hooks.applyFilters("frm_calc_field_list",jt(),{box:o,codeList:l,isSummary:i}),u=document.getElementById("frm-calc-list-".concat(a));u.innerHTML="";for(var f=0;f<d.length;f++)null!=s&&s.includes(d[f].fieldType)||c.length&&gt(d[f],c)||(bt(u,a,d[f].fieldId,d[f].fieldName,d[f].fieldType),i||ht(d[f],a,u))}}function ht(e,t,r){wp.hooks.doAction("frm_add_calc_field_shortcodes",{field:e,fieldId:t,list:r,addCalcFieldLiToList:bt})}function bt(e,t,r,n,o){var i=w({className:"frm_insert_code",children:[b(n),b({className:"frm-text-sm frm-text-grey-500",text:"[".concat(r,"]")})],data:{code:r}});e.append(y("li",{className:"frm-field-list-".concat(t," frm-field-list-").concat(o),child:i}))}function wt(){yt(jQuery(".frm-inline-modal.postbox:has(.frm_js_summary_list)")[0],!0)}function jt(e){var t,r=[],n=document.querySelectorAll("li.frm_field_box"),o=void 0!==e;for(t=0;t<n.length;t++)if(!o||n[t].getAttribute("data-ftype")===e){var i=n[t].getAttribute("data-fid");i&&r.push({fieldId:i,fieldName:kt("frm_name_".concat(i)),fieldType:kt("field_options_type_".concat(i)),fieldKey:kt("field_options_field_key_".concat(i))})}return wp.hooks.applyFilters("frm_admin_get_field_list",r,e,n)}function xt(e){var t,r,n,o=[],i=function(e){for(var t=e.querySelectorAll('[type="checkbox"]:checked'),r=[],n=0;n<t.length;n++)r.push(t[n].value);return r}(e),a=e.getAttribute("data-frmfname"),l=jt("product"),s=jt("quantity"),c="SELECT"===e.tagName,d=1===s.length&&1===l.length;for(c&&(i=e.getAttribute("data-frmcurrent")),t=0;t<l.length;t++)n=l[t].fieldId.toString(),r=d||i.includes(n),c?(r=r?" selected":"",o.push('<option value="'.concat(n,'"').concat(r,">").concat(l[t].fieldName,"</option>"))):(r=r?" checked":"",o.push('<label class="frm6">'),o.push('<input type="checkbox" name="'.concat(a,'" value="').concat(n,'"').concat(r,"> ").concat(l[t].fieldName)),o.push("</label>"));e.innerHTML=o.join("")}function Et(){for(var e=document.querySelectorAll(".frmjs_prod_field_opt"),t=0;t<e.length;t++)xt(e[t])}function kt(e){var t=document.getElementById(e);return t?t.value:""}function Qt(){var e,t,r=this.value,o=document.getElementById(this.getAttribute("data-changeme")),i=this.getAttribute("data-changeatt");o&&(null!==i?"SELECT"===o.tagName&&"placeholder"===i?""===(e=o.options[0]).value?e.innerHTML=r:Bn(o,r):"class"===i?function(e,t){var r,o,i,a=" ".concat(t.value),l=e.getAttribute("data-fid");if(""===a.trim()){var s=t.querySelector("option[data-align]");a=s?" ".concat(s.getAttribute("data-align")):""}void 0!==l&&(t.classList.contains("field_options_align")?a+=" ".concat(document.getElementById("frm_classes_".concat(l)).value):t.classList.contains("frm_classes")&&(i=document.getElementById("field_options_align_".concat(l)))&&(a+=" ".concat(i.value))),a=(a+=" ").replace(" block "," vertical_radio ").replace(" inline "," horizontal_radio "),""===(r=0===(r=e.className.split(" frmstart ")[1]).indexOf("frmend ")?"":r.split(" frmend ")[0]).trim()?(o=" frmstart frmend ",e.className.includes(o)||(o=" frmstart frmend "),a=" frmstart ".concat(a.trim()," frmend ")):(o=r.trim(),a=a.trim());var c=e.classList.contains("frm_first");e.className=e.className.replace(o,a),!c&&e.classList.contains("frm_first")&&function(e){var t=e.parentElement;if(t&&"UL"===t.nodeName&&!t.classList.contains("start_divider")){var r=t.parentElement;if(r&&De(r)&&!(be(jQuery(t)).get().indexOf(e)<1)){var o=y("ul",{className:"frm_grid_container frm_sorting"}),i=y("li",{className:"frm_field_box",child:o});r.after(i),o.append.apply(o,n(function(e){for(var t=[],r=e;r;)"LI"===r.nodeName&&t.push(r),r=r.nextElementSibling;return t}(e))),le(o),de(i,".frm-move"),je(jQuery(t),be(jQuery(t)).length)}}}(e)}(o,this):"range"===(t=o).type&&t.parentNode.classList.contains("frm_range_container")?function(e,t,r){if(frmGlobal.proIncludesSliderJs){var n={field:e,att:t,newValue:r};wp.hooks.doAction("frm_update_slider_field_preview",n)}else{var o;if("value"===t?(""===r&&(r=St(e)),e.value=r):e.setAttribute(t,r),["value","min","max"].includes(t))"max"!==t&&"min"!==t||""!==(o=e.id,document.querySelector('input[data-changeme="'.concat(o,'"][data-changeatt="value"]')).value)||(e.value=St(e)),e.parentNode.querySelector(".frm_range_value").textContent=e.value}}(o,i,r):o.setAttribute(i,r):0===o.id.indexOf("setup-message")?""!==r&&(o.innerHTML='<input type="text" value="" disabled />'):(o.innerHTML=Tn(r),"TEXTAREA"===o.nodeName&&o.classList.contains("wp-editor-area")&&jQuery(o).trigger("change"),o.classList.contains("frm_primary_label")&&"break"===o.nextElementSibling.getAttribute("data-ftype")&&(o.nextElementSibling.querySelector(".frm_button_submit").textContent=r)))}function St(e){var t=parseFloat(e.getAttribute("max")),r=parseFloat(e.getAttribute("min"));return(t-r)/2+r}function At(){var e=this.getAttribute("data-fid"),t="";["field_options_max_","frm_format_"].forEach(function(r){var n=document.getElementById(r+e);n&&(t+=n.value)});var r=document.getElementsByName("field_options[type_".concat(e,"]"))[0];"text"===r.options[r.selectedIndex].value&&It(""!==t,".frm_invalid_msg".concat(e))}function Lt(){var e=this.id.replace("frm_","").replace("req_field_",""),t=this.checked,r=jQuery("#field_label_".concat(e," .frm_required"));if(It(t,".frm_required_details".concat(e)),t){var n=jQuery('input[name="field_options[required_indicator_'.concat(e,']"]'));""===n.val()&&n.val("*"),r.removeClass("frm_hidden")}else r.addClass("frm_hidden")}function It(e,t){var r=jQuery(t);if(e)r.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");else{var n=r.fadeOut("fast").closest(".frm_validation_box"),o=n.css("display","block").children(":not(".concat(t,"):visible")).length;n.css("display",""),0===o&&r.closest(".frm_validation_msg").fadeOut("fast")}}function qt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(".frm_unique_details".concat(e));if(this.checked){t.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");var r=jQuery(".frm_unique_details".concat(e," input"));""===r.val()&&r.val(f.default_unique)}else{var n=t.fadeOut("fast").closest(".frm_validation_box"),o=n.css("display","block").children(":not(.frm_unique_details".concat(e,"):visible")).length;n.css("display",""),0===o&&t.closest(".frm_validation_msg").fadeOut("fast")}}function Bt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(this).val(),r=jQuery(document.getElementById("frm_field_id_".concat(e)));if(It(""!==t,".frm_conf_details".concat(e)),""!==t){var n=jQuery(".frm_validation_box .frm_conf_details".concat(e," input"));""===n.val()&&n.val(f.default_conf),function(e){var t=document.getElementsByName("field_options[type_".concat(e,"]"))[0].value;Ct(document.getElementById("field_description_".concat(e)),"field_options[description_".concat(e,"]"),f["enter_".concat(t)]),Ct(document.getElementById("conf_field_description_".concat(e)),"field_options[conf_desc_".concat(e,"]"),f["confirm_".concat(t)])}(e),"inline"===t?r.removeClass("frm_conf_below").addClass("frm_conf_inline"):"below"===t&&r.removeClass("frm_conf_inline").addClass("frm_conf_below"),jQuery(".frm-conf-box-".concat(e)).removeClass("frm_hidden")}else jQuery(".frm-conf-box-".concat(e)).addClass("frm_hidden"),setTimeout(function(){r.removeClass("frm_conf_inline frm_conf_below")},200)}function Ct(e,t,r){e.innerHTML===f.desc&&(e.innerHTML=r,document.getElementsByName(t)[0].value=r)}function Nt(e){var t=JSON.parse(this.getAttribute("data-opts"));return e.preventDefault(),document.getElementById("frm_bulk_options").value=t.join("\n"),!1}function Tt(){var e,t,r,n=jQuery(this).closest(".frm-single-settings").data("fid"),o=jQuery("#frm_field_".concat(n,"_opts .frm_option_template")).prop("outerHTML"),i=jQuery(this).data("opttype"),a=0,l="000",s=function(e){for(var t=0,r=0,n=jQuery("#frm_field_".concat(e,"_opts li")),o=0;t<n.length;t++){if(r=n[t].getAttribute("data-optkey"),1===n.length)return r;"000"!==r&&(r=r.replace("other_",""),r=parseInt(r,10)),!isNaN(o)&&(r>o||"000"===o)&&(o=r)}return o}(n);if(s!==l&&(a=s+1),"other"===i){document.getElementById("other_input_".concat(n)).value=1;var c=jQuery(this).data("ftype");"radio"!==c&&"select"!==c||jQuery(this).fadeOut("slow");var d={action:"frm_add_field_option",field_id:n,opt_key:a,opt_type:i,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,d,function(e){jQuery(document.getElementById("frm_field_".concat(n,"_opts"))).append(e),Qn(n)})}else{o=(o=(o=(o=(o=o.replace(new RegExp('optkey="'.concat(l,'"'),"g"),'optkey="'.concat(a,'"'))).replace(new RegExp("-".concat(l,"_"),"g"),"-".concat(a,"_"))).replace(new RegExp("-".concat(l,'"'),"g"),"-".concat(a,'"'))).replace(new RegExp("\\[".concat(l,"\\]"),"g"),"[".concat(a,"]"))).replace("frm_hidden frm_option_template",""),sa(n,o={newOption:o});var u=this.closest(".frm_single_option");u?u.after(o.newOption):jQuery("#frm_field_".concat(n,"_opts")).append(o.newOption),Qn(n)}null==(r=(e=this).classList.contains("frm-add-option-legacy")?null===(t=e.closest(".frm-collapse-me"))||void 0===t?void 0:t.querySelector(".frm_sortable_field_opts"):e.closest(".frm_sortable_field_opts"))||r.querySelectorAll(".frm_remove_tag.frm_disabled").forEach(function(e){return e.classList.remove("frm_disabled")}),ci()}function Ot(){Ft(jQuery(this).closest(".frm-single-settings").data("fid"),this.value)}function Ft(e,t){var r=jQuery(".frm_multiple_cont_".concat(e));"select"===t?r.fadeIn("fast"):r.fadeOut("fast")}function Dt(){var e=jQuery(this).closest(".frm-single-settings").data("fid");ta(jQuery(".field_".concat(e,"_option_key")),"",this.checked),jQuery(".field_".concat(e,"_option")).toggleClass("frm_with_key")}function Mt(){var e=jQuery(this).closest(".frm-single-settings"),t=e.data("fid"),r=document.getElementById("frm_field_id_".concat(t));Ht(jQuery(this));var n=Mn(t);if(ta(jQuery(".field_".concat(t,"_image_id")),"",n),ta(jQuery(".frm_toggle_image_options_".concat(t)),"",n),ta(jQuery(".frm_image_size_".concat(t)),"",n),ta(jQuery(".frm_alignment_".concat(t)),"",n),ta(jQuery(".frm-add-other#frm_add_field_".concat(t)),"",n),Pt(r),n){Rt(t,"inline");var o=kn(t);r.classList.add("frm_image_options"),r.classList.add("frm_image_size_".concat(o)),e.find(".frm-bulk-edit-link").hide()}else r.classList.remove("frm_image_options"),Rt(t,"block"),e.find(".frm-bulk-edit-link").show();wp.hooks.doAction("frm_image_options_toggled",e[0],n)}function Pt(e){e.classList.remove("frm_image_size_","frm_image_size_small","frm_image_size_medium","frm_image_size_large","frm_image_size_xlarge")}function Rt(e,t){jQuery("#field_options_align_".concat(e)).val(t).trigger("change")}function zt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));Gt(),Mn(e)&&(Pt(t),t.classList.add("frm_image_options"),t.classList.add("frm_image_size_".concat(kn(e))))}function Ht(e){var t=e.closest(".frm-single-settings").data("fid");jQuery(".field_".concat(t,"_option")).trigger("change")}function Gt(){Ht(jQuery(this))}function Ut(e){var t,r=e.target.closest(".frm_image_preview_wrapper");if(null!==(t=wp)&&void 0!==t&&t.media&&(null==r||!r.dataset.upgrade)){e.preventDefault(),wp.media.model.settings.post.id=0;var n=wp.media.frames.file_frame=wp.media({multiple:!1,library:{type:["image"]}});n.on("select",function(){var e=n.state().get("selection").first().toJSON(),t=r.querySelector("img");t.setAttribute("src",e.url),t.classList.remove("frm_hidden"),t.removeAttribute("srcset"),r.querySelector(".frm_image_preview_frame").style.display="block",r.querySelector(".frm_image_preview_title").textContent=e.filename,r.querySelector(".frm_choose_image_box").style.display="none";var o=jQuery(r);o.siblings('input[name*="[label]"]').data("frmimgurl",e.url),o.find("input.frm_image_id").val(e.id).trigger("change"),wp.media.model.settings.post.id=0}),n.open()}}function Wt(e){var t=jQuery(this).closest(".frm_image_preview_wrapper");e.preventDefault(),e.stopPropagation(),t.find("img").attr("src",""),t.find(".frm_image_preview_frame").hide(),t.find(".frm_choose_image_box").show(),t.find("input.frm_image_id").val(0).trigger("change")}function $t(){var e=jQuery(this).closest("li").find(".frm_form_fields select");this.checked?e.attr("multiple","multiple"):e.removeAttr("multiple")}function Vt(){var e=document.getElementById("dropform-search-input");e&&setTimeout(function(){e.focus()},100)}function Kt(e){var t=e.target,r=t.closest(".frm_warning_style");jQuery(r).fadeOut(400,function(){return r.remove()});var n=t.dataset.action,o=new FormData;k(n,o)}function Jt(e){e.preventDefault()}function Xt(){var e,t,r=this.parentNode,n=r.parentNode,o=n.querySelectorAll("li:not(.frm_hidden)");2===o.length&&(null===(e=Array.from(o).find(function(e){return e!==r}).querySelector(".frm_remove_tag"))||void 0===e||e.classList.add("frm_disabled"));var i=this.getAttribute("data-fid");jQuery(r).fadeOut("fast",function(){wp.hooks.doAction("frm_before_delete_field_option",this),jQuery(r).remove(),jQuery(n).find(".frm_other_option").length<1&&((t=document.getElementById("other_input_".concat(i)))&&(t.value=0),jQuery("#other_button_".concat(i)).fadeIn("fast"))}),ci()}function Yt(){var e=jQuery(this);if(e.is(":checked")){var t,r=function(){e.off("mouseup",t)};t=function(){setTimeout(function(){e.prop("checked",!1)},0),r()},e.on("mouseup",t),e.one("mouseout",r)}}function Zt(){this.value===f.new_option&&(this.setAttribute("data-value-on-focus",this.value),this.value="")}function er(e){return R(P("Are you sure you want to delete these %1$s selected field(s)?","formidable"),e)}function tr(){var e=f.conf_delete,t=this.parentNode.parentNode.parentNode.parentNode.parentNode,r=t.parentNode,n=jQuery(this).closest("li.form-field"),o=n.data("fid");if("divider"===n.data("ftype")){var i=document.querySelectorAll(".frm-field-group-hover-target .start_divider .frm_field_box"),a=0;i.forEach(function(e){var t=e.querySelectorAll("li.form-field");t&&(a+=t.length)}),a&&(e=er(++a))}return r.classList.contains("frm-section-collapsed")||r.classList.contains("frm-page-collapsed")||("divider_section_only"===t.className&&(e=f.conf_delete_sec),this.setAttribute("data-frmverify",e),this.setAttribute("data-frmverify-btn","frm-button-red"),this.setAttribute("data-deletefield",o),Ze(),V(this)),!1}function rr(){this.closest("li.form-field").click()}function nr(){var e=document.querySelector(".frm-field-group-hover-target");if(e){e.classList.add("frm-selected-field-group");var t=document.createElement("div");t.classList.add("frm-delete-field-groups","frm_hidden"),document.body.append(t),t.click()}}function or(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t="frm_field_group_".concat(Te()),r=document.createTextNode("");dt(r);var n=jQuery(r).closest("li").get(0);n.classList.add("frm_hidden");var o=n.querySelector("ul");o.id=t,jQuery(e.closest("li.frm_field_box")).after(n);var i=be(jQuery(e)),a=[],l=[],s=i.length,c={},d=0;jQuery(n).on("frm_added_duplicated_field_to_row",function(e,t){if(c[jQuery(t.duplicatedFieldHtml).attr("data-fid")]=t.originalFieldId,!(s>++d)){var r=jQuery(o),i=be(r);l.forEach(function(e){e.remove()});for(var u=0;u<s;++u)r.append(r.children('li.form-field[frm-field-order="'.concat(u,'"]')));we(i.first(),a),n.classList.remove("frm_hidden"),Wn(),be(r).each(function(){Ye(c[this.getAttribute("data-fid")],jQuery(this).prop("outerHTML"))})}}),i.each(function(e){var r=document.createElement("li");r.classList.add("frm_clone_field"),r.setAttribute("frm-target-row-id",t),r.setAttribute("frm-field-order",e),this.append(r),r.click(),l.push(r),a.push(Qr(Sr(this.classList)))})}}function ir(){var e=document.querySelector(".frm-field-group-hover-target");if(e){_t();var t=lr(e.querySelector("li.form-field"));e.classList.add("frm-has-open-field-group-popup"),jQuery(document).on("click","#frm_builder_page",ar);var r=h();r.style.position="relative",r.append(sr(t,this)),this.parentNode.append(r);var n=r.querySelector(".frm-row-layout-option");n&&n.focus()}}function ar(e){e.target.classList.contains("frm-custom-field-group-layout")||e.target.classList.contains("frm-cancel-custom-field-group-layout")||jQuery(e.target).closest("#frm_field_group_controls").length||jQuery(e.target).closest("#frm_field_group_popup").length||Br()}function lr(e){var t=jQuery(e).closest("ul");return t.length?be(t).length:zr()}function sr(e,t){var r=document.getElementById("frm_field_group_popup");r?r.innerHTML="":r=h(),r.id="frm_field_group_popup";var n,o=h();o.style.padding="0 24px 12px",o.append(((n=h()).classList.add("frm-row-layout-title"),n.textContent=P("Row Layout","formidable"),n));var i,a=function(e){var t=yr();if(e>6)return t.append(ur(e,"even")),t;if(5!==e&&t.append(ur(e,"even")),e%2==1&&t.append(ur(e,"middle")),e<6)t.append(ur(e,"left")),t.append(ur(e,"right"));else{var r=h();r.classList.add("frm_fourth"),t.prepend(r)}return t}(e),l=t.closest("ul.frm_sorting");return l&&function(e,t){for(var r=t.children.length,n=0;n<r;++n){var o=t.children[n];if(fr(o,e))return void o.classList.add("frm-active-row-layout")}}(l,a),o.append(a),r.append(o),r.append(document.createElement("hr")),e<=6&&r.append(((i=h()).textContent=P("Custom layout","formidable"),jQuery(i).prepend(dr("frm_gear_svg")),i.classList.add("frm-custom-field-group-layout"),cr(i),i)),r.append(function(){var e=h();return e.textContent=P("Break into rows","formidable"),jQuery(e).prepend(dr("frm_break_field_group_svg")),e.classList.add("frm-break-field-group"),cr(e),e}()),r}function cr(e,t){e.setAttribute("tabindex",0),e.setAttribute("role","button"),void 0!==t&&e.setAttribute("aria-label",t)}function dr(e){var t=document.getElementById(e).cloneNode(!0);return t.id="",t}function ur(e,t){var r,n=h();switch(n.classList.add("frm-row-layout-option"),cr(n,t),e){case 6:r="frm_half";break;case 5:r="frm_third";break;default:r=e>6?"frm_full":e%2==1?"frm_fourth":"frm_third"}return n.classList.add(r),n.setAttribute("layout-type",t),n.append(function(e,t){for(var r=yr(),n=0;n<e;++n){var o=h();o.classList.add(_r(e,t,n)),o.style.height="16px",o.style.background="#9EA9B8",o.style.borderRadius="1px",r.append(o)}return r}(e,t)),n}function fr(e,t){return mr(e)===mr(t)}function mr(e){var t;t=e.classList.contains("frm-row-layout-option")?jQuery(e).find(".frm_grid_container").children():be(jQuery(e));var r=[];return t.each(function(){r.push(Qr(Sr(this.classList)))}),r.join("-")}function _r(e,t,r){if("even"===t)return pr(e,r);if("middle"===t){if(3===e)return 1===r?"frm6":"frm3";if(5===e)return 2===r?"frm4":"frm2"}else{if("left"===t)return 0===r?vr(e):gr(e);if("right"===t)return r===e-1?vr(e):gr(e)}return"frm12"}function pr(e,t){return e>6?"frm1":[2,3,4,6].includes(e)?Ar(12/e):5===e&&void 0!==t?0===t?"frm4":"frm2":"frm12"}function gr(e){switch(e){case 2:case 3:return"frm3";case 4:case 5:return"frm2";case 6:return"frm1";default:return"frm12"}}function vr(e){switch(e){case 2:return"frm9";case 3:case 4:return"frm6";case 5:return"frm4";case 6:return"frm7";default:return"frm12"}}function yr(){var e=h();return e.classList.add("frm_grid_container"),e}function hr(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t=this.getAttribute("layout-type");we(be(jQuery(e)).first(),t),Br()}}function br(){var e=wr(),t=this.getAttribute("layout-type");we(be(e).first(),t),Dr()}function wr(){var e=jQuery(".frm-selected-field-group"),t=e.first();return e.not(t).each(function(){be(jQuery(this)).each(function(){var e=this.parentNode;be(t).last().after(this),jQuery(e).children("li.form-field").length||e.closest("li.frm_field_box").remove()})}),Wn(),we(be(t).first()),t}function jr(){null===this.closest(".frm-merge-fields-into-row")&&xr(be(jQuery(".frm-field-group-hover-target")))}function xr(e){var t=e.length,r=document.getElementById("frm_field_group_popup");r.innerHTML="";var n=h();n.style.padding="0 24px";var o=pr(5===t?6:t),i=h();if(i.style.padding="20px 0",i.classList.add("frm_grid_container"),5===t){var a=document.createElement("span");a.classList.add("frm1"),i.append(a)}var l=zr()>0&&Qr(pr(t));!1!==l&&l>=12&&(l=Math.floor(12/t));for(var s=0;s<t;++s){var c=document.createElement("input");c.type="text",c.classList.add(o),c.classList.add("frm-custom-grid-size-input"),c.value=!1!==l?l:Qr(Sr(e.get(s).classList)),i.append(c)}var d=h();d.classList.add("frm-builder-popup-heading"),d.textContent=P("Enter number of columns for each field","formidable");var u=h();u.classList.add("frm-builder-popup-subheading"),u.textContent=P("Layouts are based on a 12-column grid system","formidable"),n.append(d),n.append(u),n.append(i);var f=h();f.style.textAlign="right";var m,_=((m=kr()).classList.add("button-secondary","frm-button-secondary"),m);_.textContent=P("Cancel","formidable"),_.classList.add("frm-cancel-custom-field-group-layout"),_.style.marginRight="10px";var p=function(){var e=kr();return e.classList.add("button-primary","frm-button-primary"),e}();p.textContent=P("Save","formidable"),p.classList.add("frm-save-custom-field-group-layout"),f.append(_),f.append(p),n.append(f),r.append(n),setTimeout(function(){var e=r.querySelector("input.frm-custom-grid-size-input").focus();e&&e.focus()},0)}function Er(){xr(jQuery(".frm-selected-field-group li.form-field"))}function kr(){var e=document.createElement("a");return e.setAttribute("href","#"),e.classList.add("button"),e.style.textDecoration="none",e}function Qr(e){switch(e){case"frm_half":return 6;case"frm_third":return 4;case"frm_two_thirds":return 8;case"frm_fourth":return 3;case"frm_three_fourths":return 9;case"frm_sixth":return 2;default:return 0===e.indexOf("frm")?parseInt(e.substr(3)):12}}function Sr(e){for(var t=["frm_full","frm_half","frm_third","frm_fourth","frm_sixth","frm_two_thirds","frm_three_fourths","frm1","frm2","frm3","frm4","frm5","frm6","frm7","frm8","frm9","frm10","frm11","frm12"],r=0;r<t.length;++r){var n=t[r];if(e.contains(n))return n}return""}function Ar(e){return"frm".concat(e)}function Lr(){var e,t;e=document.querySelector(".frm-field-group-hover-target"),be(t=jQuery(e)).each(function(e){0!==e&&t.parent().after(ct(this)),function(e){we(e,"clear")}(jQuery(this))}),Br()}function Ir(){this.select()}function qr(){jQuery(document.getElementById("frm_field_group_popup")).replaceWith(sr(lr(this),this))}function Br(){var e=document.getElementById("frm_field_group_popup");if(e){var t=document.querySelector(".frm-has-open-field-group-popup");t&&(t.classList.remove("frm-has-open-field-group-popup"),e.parentNode.remove()),jQuery(document).off("click","#frm_builder_page",ar)}}function Cr(){var e=[];jQuery(document.getElementById("frm_field_group_popup").querySelectorAll(".frm_grid_container input")).each(function(){e.push(parseInt(this.value))});var t=jQuery(document.getElementById("frm_field_group_controls"));t.length&&"none"!==t.get(0).style.display?we(be(jQuery(document.querySelector(".frm-field-group-hover-target"))).first(),e):(we(be(wr()).first(),e),Dr()),Br()}function Nr(e){if(function(){var e=document.getElementById("frm-field-group-message");if(document.querySelectorAll(".edit_form_item:not(.edit_field_type_end_divider)").length<2)Tr(e);else if(e)!function(e){e&&(e.classList.remove("frm_hidden"),e.classList.add("frm-fadein-up-back"))}(e);else{e=h({id:"frm-field-group-message",className:"frm-flex-center frm-fadein-up-back",children:[b({id:"frm-field-group-message-dismiss",className:"frm-flex-center",child:j({href:"#frm_close_icon"})})]}),document.getElementById("post-body-content").append(e);var t,r=((t=document.createElement("span")).classList.add("frm-field-group-message-text","frm-flex-center"),t.innerHTML=R(frm_admin_js.holdShiftMsg,'<span class="frm-meta-tag frm-flex-center"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-shift" viewBox="0 0 16 16"><path d="M7.3 2a1 1 0 0 1 1.4 0l6.4 6.8a1 1 0 0 1-.8 1.7h-2.8v3a1 1 0 0 1-1 1h-5a1 1 0 0 1-1-1v-3H1.7a1 1 0 0 1-.8-1.7L7.3 2zm7 7.5L8 2.7 1.7 9.5h2.8a1 1 0 0 1 1 1v3h5v-3a1 1 0 0 1 1-1h2.8z"/></svg>',"</span>"),t);e.prepend(r),document.getElementById("frm-field-group-message-dismiss").addEventListener("click",function(){Tr(document.getElementById("frm-field-group-message"))})}}(),"ul"===e.originalEvent.target.nodeName.toLowerCase()){var t=document.querySelector(".frm-field-group-hover-target");if(t){var r=e.ctrlKey||e.metaKey,n=e.shiftKey,o=t.classList.contains("frm-selected-field-group"),i=function(){var e=jQuery(".frm-selected-field-group");if(e.length)return e;var t=Or();if(t){var r=t.closest("ul");if(r&&1===be(jQuery(r)).length)return r.classList.add("frm-selected-field-group"),jQuery(r)}return jQuery()}(),a=i.length;if(r||n){var l=Or();if(null===l||jQuery(l).siblings("li.form-field").length||(l.parentNode.classList.add("frm-selected-field-group"),++a),r){if(o)return--a,t.classList.remove("frm-selected-field-group"),void Fr(a);++a}else if(n&&!o){++a;var s=i.first();(s.parent().index()<jQuery(t.parentNode).index()?s.parent().nextUntil(t.parentNode):s.parent().prevUntil(t.parentNode)).each(function(){var e=jQuery(this).closest("li").find("ul.frm_sorting");e.hasClass("frm-selected-field-group")||(++a,e.addClass("frm-selected-field-group"))})}}else Dr(),a=1;t.classList.add("frm-selected-field-group"),Fr(a),document.querySelectorAll(".frm-selected-field-group").length<2||Tr(document.getElementById("frm-field-group-message")),jQuery(document).off("click",Dr),jQuery(document).on("click",Dr)}}}function Tr(e){e&&(e.classList.add("frm_hidden"),e.classList.remove("frm-fadein-up-back"))}function Or(){return document.getElementById("frm-show-fields").querySelector("li.form-field.selected")}function Fr(e){mt(!0),e>=2||1===e&&be(jQuery(document.querySelector(".frm-selected-field-group"))).length>1?function(){var e=document.getElementById("frm_field_multiselect_popup");if(e)return e.classList.toggle("frm-unmergable",!Pr()),e;(e=h()).id="frm_field_multiselect_popup",Pr()||e.classList.add("frm-unmergable");var t=h();t.classList.add("frm-merge-fields-into-row"),t.textContent=P("Merge into row","formidable");var r=document.createElement("a");r.style.marginLeft="5px",r.classList.add("frm_icon_font","frm_arrowdown6_icon"),r.setAttribute("href","#"),t.append(r),e.append(t);var n=h();n.classList.add("frm-multiselect-popup-separator"),e.append(n);var o=h();o.classList.add("frm-delete-field-groups"),o.append(dr("frm_trash_svg")),e.append(o),document.getElementById("post-body-content").append(e),jQuery(e).hide().fadeIn()}():Mr(),rt()}function Dr(e){if(void 0!==e){if(null!==e.originalEvent.target.closest("#frm-show-fields"))return;if(e.originalEvent.target.classList.contains("frm-merge-fields-into-row"))return;if(null!==e.originalEvent.target.closest(".frm-merge-fields-into-row"))return;if(e.originalEvent.target.classList.contains("frm-custom-field-group-layout"))return;if(e.originalEvent.target.classList.contains("frm-cancel-custom-field-group-layout"))return}jQuery(".frm-selected-field-group").removeClass("frm-selected-field-group"),jQuery(document).off("click",Dr),Mr()}function Mr(){var e=document.getElementById("frm_field_multiselect_popup");e&&e.remove()}function Pr(){var e=document.querySelectorAll(".frm-selected-field-group"),t=e.length;if(1===t)return!1;for(var r=0,n=0;n<t;++n){var o=e[n];if(null!==o.querySelector(".edit_field_type_break, .edit_field_type_hidden"))return!1;if((r+=be(jQuery(o)).length)>12)return!1}return!0}function Rr(e){if(null===e.originalEvent.target.closest("#frm_field_group_popup")&&!e.originalEvent.target.classList.contains("frm-custom-field-group-layout")){var t=sr(zr(),document.querySelector(".frm-selected-field-group").firstChild);this.append(t)}}function zr(){var e=0;return jQuery(document.querySelectorAll(".frm-selected-field-group")).each(function(){e+=be(jQuery(this)).length}),e}function Hr(){var e,t=(e=[],jQuery(".frm-selected-field-group > li.form-field").each(function(){e.push(this.dataset.fid)}),e),r=function(e){return function(t){t.preventDefault(),function(e){e.forEach(function(e){Ur(e)})}(e)}}(t),n=document.getElementById("frm_field_multiselect_popup");n&&n.remove(),this.setAttribute("data-frmverify",er(t.length)),V(this);var o=document.getElementById("frm-confirmed-click");null==o||o.removeAttribute("data-deletefield"),jQuery(o).on("click",r),jQuery("#frm_confirm_modal").one("dialogclose",function(){jQuery(o).off("click",r)})}function Gr(){Ur(this.getAttribute("data-deletefield"))}function Ur(e){var t=jQuery("#frm_field_id_".concat(e));Wr(e),t.hasClass("edit_field_type_divider")&&t.find("li.frm_field_box[data-fid]").each(function(){Wr(this.getAttribute("data-fid"))}),$n()}function Wr(e){jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_delete_field",field_id:e,nonce:frmGlobal.nonce},success:function(){var t,r,n,o=jQuery(document.getElementById("frm_field_id_".concat(e))),i=jQuery("#frm-single-settings-".concat(e));i.is(":visible")&&(null===(t=document.querySelector(".frm-settings-panel .frm-tabs-navs ul > li:first-child"))||void 0===t||t.click(),document.querySelector("#frm-options-panel .frm-single-settings").classList.remove("frm_hidden")),function(e){var t=e[0].querySelectorAll(".frm-inline-modal[data-fills]");t.length&&t.forEach(function(e){e.classList.add("frm_hidden"),e.removeAttribute("data-fills"),e.closest("form").append(e)})}(i),i.remove(),o.fadeOut("slow",function(){var e,t=o.closest(".start_divider"),r=o.data("type"),n=o.siblings("li.form-field");if(n.length||(o.is(".edit_field_type_end_divider")?n.length=o.closest("li.form-field").siblings():e=o.closest("ul.frm_sorting").parent()),o.remove(),"break"===r?on():"product"===r&&(Ke(),Et()),n.length?we(n.first()):e.remove(),0===jQuery("#frm-show-fields li").length||function(){if(I.get(0).childElementCount>1)return!1;var e=I.get(0).firstElementChild.firstElementChild.querySelectorAll("li.frm_field_box");return!(e.length>1)&&e[0].classList.contains("edit_field_type_submit")}()){var i=document.getElementById("frm_form_editor_container");i.classList.remove("frm-has-fields"),i.classList.add("frm-empty-fields")}else t.length&&Vn(t);Y()}),o.length&&(r=o.data("type"),(n=document.getElementById(r))&&n.dataset.limit&&$r(r)-1<n.dataset.limit&&n.classList.remove("frm_at_limit"),wp.hooks.doAction("frm_after_delete_field",o[0]))}})}function $r(e){return document.getElementById("frm-show-fields").querySelectorAll('li.form-field[data-ftype="'.concat(e,'"]')).length}function Vr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=T,r=document.getElementById("frm_logic_row_".concat(e)).querySelectorAll(".frm_logic_row");return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_logic_row",form_id:t,field_id:e,nonce:frmGlobal.nonce,meta_name:Kr(r,"frm_logic_".concat(e,"_")),fields:jt()},success:function(t){jQuery(document.getElementById("logic_".concat(e))).fadeOut("fast",function(){var r=document.getElementById("frm_logic_row_".concat(e));r.insertAdjacentHTML("beforeend",t);var n=r.querySelector(".frm_logic_row:last-child .frm-logic-rule-text");n&&(n.textContent=r.dataset.ruleText);var o=r.closest(".frm_logic_rows");o.style.height="auto",jQuery(o).fadeIn("fast")})}}),!1}function Kr(e,t,r){return e.length?parseInt(e[e.length-1].id.replace(t,""),10)+1:void 0!==r?r:0}function Jr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=T,r=document.getElementById("frm_watch_lookup_block_".concat(e)).children;return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_watch_lookup_row",form_id:t,field_id:e,row_key:Kr(r,"frm_watch_lookup_".concat(e,"_")),nonce:frmGlobal.nonce},success:function(t){var r,n=jQuery(document.getElementById("frm_watch_lookup_block_".concat(e)));n.append(t),n.fadeIn("slow"),null===(r=document.getElementById("frm_watch_lookup_label_".concat(e)))||void 0===r||r.classList.remove("frm-force-hidden")}}),!1}function Xr(e){var t,r,n=jQuery(e).closest(".frm-single-settings").attr("data-fid"),o=jQuery(e).closest("ul").get(0).querySelectorAll(".field_".concat(n,"_option"));for(t in o)if(Object.hasOwn(o,t)&&(r=o[t]).id!==e.id&&r.value===e.value&&"true"!==r.getAttribute("data-duplicate"))return!0;return!1}function Yr(){var e,t;null===this.getAttribute("data-value-on-load")&&(this.setAttribute("data-value-on-load",this.value),t=jQuery(this).closest(".frm-single-settings").attr("data-fid"),(e=document.createElement("input")).value=this.value,e.setAttribute("type","hidden"),e.setAttribute("name","optionmap[".concat(t,"][").concat(this.value,"]")),this.parentNode.append(e),void 0===F[t]&&(F[t]={}),F[t][this.value]=e),"true"===this.getAttribute("data-duplicate")&&(this.removeAttribute("data-duplicate"),Xr(this))?this.setAttribute("data-value-on-focus",this.getAttribute("data-value-on-load")):""===this.value&&f.new_option===this.getAttribute("data-value-on-focus")||this.setAttribute("data-value-on-focus",this.value)}function Zr(e){var t,r=e.closest(".frm_single_option");return e.parentElement.classList.contains("frm_single_option")?{newValue:r.querySelector('.frm_option_key input[type="text"]').value,newLabel:t=e.value}:(t=r.querySelector('input[type="text"]').value,{newValue:e.value,newLabel:t})}function en(){var e,t,r=function(e){var t=function(e){var t,r,n=null!==(t=null===(r=e.closest(".frm-single-settings").querySelector(".frm_toggle_sep_values"))||void 0===r?void 0:r.checked)&&void 0!==t&&t,o=e.closest(".frm_single_option");return n&&e.parentElement.classList.contains("frm_single_option")?{oldValue:o.querySelector('.frm_option_key input[type="text"]').getAttribute("data-value-on-focus"),oldLabel:e.getAttribute("data-value-on-focus")}:{oldValue:e.getAttribute("data-value-on-focus"),oldLabel:o.querySelector('input[type="text"]').getAttribute("data-value-on-focus")}}(e),r=t.oldValue,n=t.oldLabel,o=Zr(e);return{oldValue:r,oldLabel:n,newValue:o.newValue,newLabel:o.newLabel}}(this),n=r.oldValue,o=r.oldLabel,i=r.newValue,a=r.newLabel;if(n!==i||o!==a){var l=this.closest(".frm-single-settings"),s=l.getAttribute("data-fid"),c=this.getAttribute("data-value-on-load");if(Xr(this))return this.setAttribute("data-duplicate","true"),void(void 0!==F[s]&&void 0!==F[s][c]&&(F[s][c].value=c));void 0!==F[s]&&void 0!==F[s][c]&&(F[s][c].value=i);for(var d=[],u=W.querySelectorAll(".frm_logic_row"),f=u.length,m=0;m<f;m++){var _=u[m];if(_.querySelector(".frm_logic_field_opts").value===s){var p,g=_.id.split("_")[2],v=_.querySelector('select[name="field_options[hide_opt_'.concat(g,'][]"]')),y=void 0,h=void 0;(y=""===n?[]:v.querySelectorAll('option[value="'.concat(n,'"]'))).length||(y=v.querySelectorAll('option[value="'.concat(i,'"]'))).length||(null!==(p=l.querySelector(".frm_toggle_sep_values"))&&void 0!==p&&p.checked||(h=tn(v,n)),h||(h=document.createElement("option"),v.append(h))),y.length&&(h=y[y.length-1]),h.setAttribute("value",i),h.textContent=a,d.includes(g)||d.push(g)}}for(e in d)Object.hasOwn(d,e)&&(t=d[e],Qo(document.getElementById("frm-single-settings-".concat(t))))}}function tn(e,t){for(var r=e.options,n=0;n<r.length;n++){var o=r[n];if(t===o.textContent)return o}return null}function rn(){var e=this.id.replace("get_values_form_",""),t=document.getElementById("get_values_field_".concat(e)),r=this.getAttribute("data-fieldtype");if(""===this.value)t.options.length=1;else{var n=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_options_for_get_values_field",form_id:n,field_type:r,nonce:frmGlobal.nonce},success:function(e){t.innerHTML=e}})}}function nn(){var e,t,r=this.name.replace("field_options[data_type_","").replace("]","");(e=document.getElementById("frm_add_watch_lookup_link_".concat(r)))&&(e=e.parentNode,"text"===this.value?(t=document.getElementById("frm_watch_lookup_block_".concat(r)))&&(t.innerHTML="",e.classList.add("frm_hidden"),e.previousElementSibling.style.display="none",e.previousElementSibling.previousElementSibling.style.display="none",e.previousElementSibling.previousElementSibling.previousElementSibling.style.display="none"):e.classList.remove("frm_hidden"),Ft(r,this.value))}function on(){var e,t,r=document.getElementsByClassName("frm-page-num");if(r.length>1)for(document.getElementById("frm-fake-page").style.display="block",e=0;e<r.length;e++)t=r[e].parentNode.parentNode.parentNode.classList,1===e?t.add("frm-first-page"):t.remove("frm-first-page"),r[e].textContent=e+1;else document.getElementById("frm-fake-page").style.display="none";wp.hooks.doAction("frm_renumber_page_breaks",r)}function an(){var e,t,r,n=jQuery(this).closest(".frm_field_box[data-ftype=break]");n.length?function(e){var t=ln(e.get(0).parentNode.closest("li.frm_field_box").nextElementSibling);sn(e,t)}(n):(e=document.getElementById("frm-fake-page"),t=document.getElementById("frm-show-fields").firstElementChild,r=ln(t),"break"!==t.getAttribute("data-ftype")&&sn(jQuery(e),r))}function ln(e){var t,r;if(t=jQuery(),null===e)return t;r=e;do{if(null!==r.querySelector(".edit_field_type_break"))break;t=t.add(jQuery(r)),r=r.nextElementSibling}while(null!==r);return t}function sn(e,t){var r,n=t.length,o=Math.min(n,3);if(e.hasClass("frm-page-collapsed"))for(e.removeClass("frm-page-collapsed"),t.removeClass("frm-is-collapsed"),r=0;r<o;r++)r===o-1?jQuery(t[r]).slideDown(150,function(){t.show()}):jQuery(t[r]).slideDown(150);else for(e.addClass("frm-page-collapsed"),t.addClass("frm-is-collapsed"),r=0;r<o;r++)r===o-1?jQuery(t[r]).slideUp(150,function(){t.css("cssText","display:none !important;")}):jQuery(t[r]).slideUp(150)}function cn(){this.parentNode.parentNode.parentNode.parentNode.classList.toggle("frm-section-collapsed")}function dn(){this.nextElementSibling&&(this.nextElementSibling.style.animation=""),this.classList.toggle("frm-collapsed");var e="true"===this.getAttribute("aria-expanded")||!1;this.setAttribute("aria-expanded",!e),un(this.nextElementSibling)}function un(e){if(e){var t=e.scrollHeight;t<=0||(t+=250,e.style.setProperty("--slide-height","".concat(t,"px")),e.style.setProperty("--slide-time","".concat(Math.ceil(.8*t),"ms")))}}function fn(){if(this.id){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0],t=this.id.replace("field_label_",""),r=document.getElementById("field_options_type_".concat(t)),n=r.value;void 0!==e&&(n=function(e){return"divider"===e?e="section":"range"===e?e="slider":"data"===e?e="dynamic":"form"===e&&(e="embed form"),e}(n="SELECT"===r.tagName?r.options[r.selectedIndex].text.toLowerCase():n.replace("_"," ")),setTimeout(function(){e.value.toLowerCase()===n?e.select():e.focus()},50))}}function mn(){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0];void 0!==e&&setTimeout(function(){e.focus(),_n(e)},50)}function _n(e){var t=e.closest(".frm-collapse-me");null!==t&&t.previousElementSibling.classList.remove("frm-collapsed")}function pn(e){var t,r,n=e.target.classList;if(!n.contains("frm-collapse-page")&&!n.contains("frm-sub-label")&&null===e.target.closest(".dropdown")){if(null!==this.closest(".start_divider")&&e.stopPropagation(),this.classList.contains("edit_field_type_divider")){var o=e.originalEvent.target.closest("ul.frm_sorting");if(null!==o&&(o.classList.contains("edit_field_type_divider")||o.parentNode.parentNode.classList.contains("start_divider")))return}t=this,r=jQuery(t),t.className.includes("selected")||t.className.includes("edit_field_type_end_divider")&&r.closest(".edit_field_type_divider").hasClass("no_repeat_section")||(_t(),r.addClass("selected"),function(e){var t,r,n=e.getAttribute("data-fid"),o=e.getAttribute("data-type"),i=document.querySelectorAll(".frm-single-settings:not(.frm_hidden)");for(r=0;r<i.length;r++)i[r].classList.add("frm_hidden");var a=document.getElementById("frm-single-settings-".concat(n));Qo(a),o&&"quantity"===o&&xt(jQuery(a).find(".frmjs_prod_field_opt")[0]),null===(t=document.querySelector(".frm-settings-panel.frm-scrollbar-wrapper"))||void 0===t||t.scrollTo({top:0,behavior:"instant"}),a.classList.remove("frm_hidden"),a.querySelectorAll("h3:not(.frm-collapsed) + .frm-collapse-me").forEach(function(e){return e.style.animation="none"}),document.getElementById("frm-options-panel-tab").click();var l=a.querySelector(".wp-editor-area");l&&frmDom.wysiwyg.init(l,{setupCallback:ko}),wp.hooks.doAction("frmShowedFieldSettings",e,a),function(e,t,r){var n;if(function(e){return wp.hooks.applyFilters("frm_fields_with_shortcode_popup",["html"]).includes(e)}(e)){var o="#frm-single-settings-".concat(t);if(!document.querySelector("".concat(o," .frm-show-box"))){null===(n=r.querySelector(".wp-editor-container"))||void 0===n||n.classList.add("frm_has_shortcodes");var i=function(){return frmDom.svg({href:"#frm_more_horiz_solid_icon",classList:["frm-show-box"]})};document.querySelectorAll("".concat(o," .frm_has_shortcodes textarea")).forEach(function(e){var t=b({className:"frm-with-right-icon"});e.parentNode.insertBefore(t,e),t.append(i()),t.append(e)})}}}(o,n,a)}(t))}}function gn(e){var t=e.target;if("custom"===t.value){var r=t.dataset.fieldId,n=document.getElementById("frm-field-format-custom-".concat(r)).querySelector(".frm_format_opt");"international"!==n.value&&"currency"!==n.value&&"number"!==n.value||n.setAttribute("value","")}setTimeout(function(){t.querySelectorAll("option").forEach(function(e){e.selected&&e.classList.contains("frm_show_upgrade")&&(t.value="none")})},0)}function vn(){var e=this.getAttribute("data-fid");_n(document.getElementById("field_options_field_key_".concat(e)))}function yn(){var e=jQuery(this).closest(".frm_field_box");e.find(".repeat_icon_links").removeClass("repeat_format repeat_formatboth repeat_formattext").addClass("repeat_format".concat(this.value)),"text"===this.value||"both"===this.value?(e.find(".frm_repeat_text").show(),e.find(".repeat_icon_links a").addClass("frm_button")):(e.find(".frm_repeat_text").hide(),e.find(".repeat_icon_links a").removeClass("frm_button"))}function hn(){var e=this.value;""!==e&&(e<2||e>200)&&(K(f.repeat_limit_min),this.value="")}function bn(){var e=this.value;""!==e&&(e<1||e>200)&&(K(f.checkbox_limit),this.value="")}function wn(e,t){jQuery(e).closest(".frm_field_box").find(".frm_".concat(t,"_form_row .frm_repeat_label")).text(e.value)}function jn(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=this.value,r=document.getElementById("frm_show_selected_fields_".concat(e)),n=document.getElementById("frm_show_selected_forms_".concat(e));jQuery(n).find("select").val(""),"form"===t?(n.style.display="inline",function(e){if(null!==e)for(;e.firstChild;)e.firstChild.remove()}(r)):(r.style.display="none",n.style.display="none",Un(t,e))}function xn(){var e=En(this);if(e){var t=jQuery(this).closest(".frm_single_option");!function(e,t,r){var n=r.data("optkey"),o=Dn(e),i=jQuery('label[for="field_'.concat(t,"-").concat(n,'"]')),a="field_options[options_".concat(e,"][").concat(n,"]"),l=jQuery('input[name="'.concat(a,'[label]"]'));if(i.length<1)return Qn(e),void(r.find('input[name^="default_value_"]').is(":checked")&&l.length>0&&jQuery('select[name^="item_meta['.concat(e,']"]')).val(l.val()));var s,c=i.children("input");if(s=l.length<1?(l=jQuery('input[name="'.concat(a,'"]'))).val():o?jQuery('input[name="'.concat(a,'[value]"]')).val():l.val(),!(l.length<1)){var d=i[0].childNodes;if(Mn(e)){var u=function(e,t,r){var n,o=e.find("img");o&&(n=o.attr("src"));var i=Pn(t);return On(r.val(),i,n)}(r,e,l),f=i.find(".frm_image_option_container");f.length>0?f.replaceWith(u):(d[d.length-1].nodeValue="",i.append(u))}else{var m=!1;d.forEach(function(t,r){if(!1===m)"INPUT"===t.tagName&&(m=r);else if(r===m+1){var n="";!function(e){var t=document.getElementsByName("field_options[image_options_".concat(e,"]")),r=Array.from(t).find(function(e){return e.checked&&"buttons"===e.value});return void 0!==r}(e)?t.nodeValue=" ".concat(l.val()):(n=h({className:"frm_label_button_container",text:" ".concat(l.val())}),i[0].replaceChild(n,t))}else t.remove()})}c.val(s),defaultVal=r.find('input[name^="default_value_"]'),c.prop("checked",!!defaultVal.is(":checked"))}}(e.fieldId,e.fieldKey,t)}}function En(e){var t=jQuery(e).closest(".frm_sortable_field_opts");return!!t.length&&{fieldId:t.attr("id").replace("frm_field_","").replace("_opts",""),fieldKey:t.data("key")}}function kn(e){var t,r=document.getElementById("field_options_image_size_".concat(e)),n="";return r&&""!==(t=r.value)&&(n=t),n}function Qn(e){var t=jQuery('[name^="item_meta['.concat(e,']"]'));if(!(t.length<1)){var r={fieldId:e,metaInput:t[0]};if(!1===wp.hooks.applyFilters("frm_custom_reset_displayed_opts",!1,r)){if(t.is("select")){var n=document.getElementById("frm_placeholder_".concat(e));n&&""!==n.value?qn(t[0],{sourceID:e,placeholder:n.value}):qn(t[0],{sourceID:e})}else{var o=Cn(e),i=jQuery("#field_".concat(e,"_inner_container > .frm_form_fields")),a=Mn(e),l=a?kn(e):"",s=a?"frm_image_option frm_image_".concat(l," "):"";i.html("");for(var c=En(jQuery("#frm_delete_field_".concat(e,"-000_container"))),d=aa(e),u="hidden"===t.attr("type")?t.data("field-type"):t.attr("type"),f=0;f<o.length;f++)i.append(In(u,o[f],e,c.fieldKey,d,s))}An(e)}else An(e)}}function Sn(e,t){var r=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('input[value="'.concat(t,'"]'));return r?Zr(r):{newValue:t,newLabel:t}}function An(e,t){for(var r=W.querySelectorAll(".frm_logic_row"),n=r.length,o=wp.hooks.applyFilters("frm_conditional_logic_field_options",function(e){var t=[],r=document.getElementById("frm_field_".concat(e,"_opts"));if(!r)return t;for(var n=r.querySelectorAll(".frm_single_option"),o=n.length,i=0;i<o;i++){var a=n[i];if(!a.classList.contains("frm_hidden")){var l=a.querySelector(".field_".concat(e,"_option"));t.push(l.value)}}return t}(e),{type:t,fieldId:e}),i=o.length,a=0;a<n;a++){var l=r[a];if(l.querySelector(".frm_logic_field_opts").value==e){for(var s=l.id.split("_")[2],c=l.querySelector('select[name="field_options[hide_opt_'.concat(s,'][]"]')),d=function(){var t,r=o[u],n=null===(t=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('.frm_option_key input[type="text"]'))||void 0===t?void 0:t.value;n||(n=r);var i=c.querySelector('option[value="'.concat(n,'"]')),a=Sn(e,r),l=a.newValue,s=a.newLabel,d=document.querySelectorAll("#frm_field_".concat(e,"_opts input[data-value-on-focus]")),f=Array.from(d).find(function(e){return e.value===r});if(f){var m=f.dataset.valueOnFocus;if(m&&c.querySelector('option[value="'.concat(m,'"]')))return 1}Ln(c,i,l,s)},u=i-1;u>=0;u--)d();var f=c.querySelector('option[value=""]');null!==f&&c.prepend(f)}}}function Ln(e,t,r,n){null!==t||e.querySelector('option[value="'.concat(r,'"]'))||((t=frmDom.tag("option",{text:n})).value=r),e.prepend(t)}function In(e,t,r,n,o,i){var a="",l=t.key.includes("other"),s="field_".concat(n,"-").concat(t.key),c="scale"===e?"radio":e,d='<input type="text" id="field_'.concat(n,"-").concat(t.key,'-otext" class="frm_other_input frm_pos_none" name="item_meta[other][').concat(r,"][").concat(t.key,']" value="" />');return this.getSingle=function(){return""!==(a=wp.hooks.applyFilters("frm_admin.build_single_option_template",a,{opt:t,type:e,fieldId:r,classes:i,id:s}))?a:'<div class="frm_'.concat(e," ").concat(e," ").concat(i,'" id="frm_').concat(e,"_").concat(r,"-").concat(t.key,'">\n\t\t\t\t\t<label for="').concat(s,'">\n\t\t\t\t\t\t<input type="').concat(c,'" name="item_meta[').concat(r,"]").concat("checkbox"===e?"[]":"",'" value="').concat(Tn(t.saved),'" id="').concat(s,'"').concat(o?' data-price="'.concat(t.price,'"'):"").concat(t.checked?' checked="checked"':"",">\n\t\t\t\t\t\t").concat(Tn(t.label),"\n\t\t\t\t\t</label>\n\t\t\t\t\t").concat(l?d:"","\n\t\t\t\t</div>")},this.getSingle()}function qn(e,t){if(e){var r=t.sourceID,n=t.placeholder,o=aa(r),i=t.other;!function(e){var t;if(void 0!==e.options)for(t=e.options.length-1;t>=0;t--)e.remove(t)}(e);for(var a=Cn(r,e.id.includes("frm_field_logic_opt")),l=void 0!==n,s=0;s<a.length;s++){var c=a[s].label,d=a[s].key.includes("other");if(l&&""!==c?Bn(e,n):l&&(c=n),l=!1,!d||i){var u=document.createElement("option");u.value=a[s].saved,u.innerHTML=Tn(c),o&&u.setAttribute("data-price",a[s].price),e.append(u)}}}}function Bn(e,t){var r=document.createElement("option"),n=e.firstChild;r.value="",r.innerHTML=t,null!==n?(n.before(r),e.selectedIndex=0):e.append(r)}function Cn(e){var t,r,n,o,i,a,l=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=[],c=jQuery('input[name^="field_options[options_'.concat(e,']"]')).filter('[name$="[label]"], [name*="[other_"]'),d=aa(e),u=Pn(e),f=Mn(e),m=Dn(e);for(t=0;t<c.length;t++)c[t].name.indexOf("[000]")>0||(o=r=c[t].value,i=c[t].name.replace("field_options[options_".concat(e,"]["),"").replace("[label]","").replace("]",""),m&&(n=c[t].name.replace("[label]","[value]"),r=jQuery('input[name="'.concat(n,'"]')).val(),l&&""===o&&(o=""!==r?r:frm_admin_js.no_label)),f&&(o=On(o,u,Nn(c[t]))),a={saved:r,label:o=frmAdminBuild.hooks.applyFilters("frm_choice_field_label",o,e,c[t],f),checked:Fn(c[t].id),key:i},d&&(n=c[t].name.replace("[label]","[price]"),a.price=jQuery('input[name="'.concat(n,'"]')).val()),s.push(a));return s}function Nn(e){var t=jQuery(e).siblings(".frm_image_preview_wrapper");if(!t.length)return"";var r=t.find("img");return r.length?r.attr("src"):""}function Tn(e){(e instanceof Element||e instanceof Document)&&(e=e.outerHTML);var t=jQuery.parseHTML(e).reduce(function(e,t){var r=frmDom.cleanNode(t);return"#text"===r.nodeName?e+r.textContent:e+r.outerHTML},"");return t!==e?Tn(t):t}function On(e,t,r){var n,o=e;o=Tn(o),r?n=x({src:r,alt:o}):(n=h({className:"frm_empty_url"})).innerHTML=f.image_placeholder_icon;var i=t?" frm_label_with_image":"",a=[n];if(t){var l=y("span",{className:"frm_text_label_for_image_inner"});l.innerHTML=o,a.push(y("span",{className:"frm_text_label_for_image",child:l}))}return y("span",{className:"frm_image_option_container".concat(i),children:a})}function Fn(e){var t=jQuery("#".concat(e));if(0===t.length)return!1;var r=t.siblings("input[type=checkbox]");return r.length&&r.prop("checked")}function Dn(e){return Rn("separate_value_".concat(e))}function Mn(e){for(var t=!1,r=document.getElementsByName("field_options[image_options_".concat(e,"]")),n=0;n<r.length;n++)r[n].checked&&(t="0"!==r[n].value);return frmAdminBuild.hooks.applyFilters("frm_choice_field_images_as_options",t,e)}function Pn(e){var t=!Rn("hide_image_text_".concat(e));return frmAdminBuild.hooks.applyFilters("frm_choice_field_showing_label_with_image",t,e)}function Rn(e){var t=document.getElementById(e);return!!t&&t.checked}function zn(e){var t=e.closest(".frm-single-settings"),r=t.getAttribute("data-fid"),n=t.querySelector('[name="field_options[separate_value_'.concat(r,']"]')).checked;if(!n||e.name.endsWith("[value]")){var o=document.getElementById("frm_field_".concat(r,"_opts"));Array.from(o.querySelectorAll('input[type="text"]')).filter(function(t){return t.id!==e.id&&n===t.name.endsWith("[value]")&&t.value===e.value}).length&&K(R(P('Duplicate option value "%s" detected',"formidable"),Tn(e.value)))}}function Hn(){var e=this.value;if(e){var t=this.parentNode.id.replace("frm_logic_","").split("_"),r=t[0],n=t[1],o=document.getElementById("frm_field_id_".concat(e)).getAttribute("data-ftype"),i=document.getElementById("frm_show_selected_values_".concat(r,"_").concat(n)),a="field_options[hide_opt_".concat(r,"][]"),l="frm_field_logic_opt_".concat(r),s=!1,c="select"===o||"checkbox"===o||"radio"===o,d="text"===o||"email"===o||"phone"===o||"url"===o||"number"===o;if(c&&document.getElementById("frm_has_hidden_options_".concat(e))&&(c=!1),c||d){var u=document.querySelector("#frm_logic_".concat(r,"_").concat(n,' [name="field_options[hide_field_cond_').concat(r,'][]"]')).value;i.innerHTML="";var f=c&&!["LIKE","not LIKE","LIKE%","%LIKE"].includes(u);f?s=document.createElement("select"):(s=document.createElement("input")).type="text",s.name=a,s.id="".concat(l,"_").concat(n),i.append(s),f&&qn(document.getElementById(s.id),{sourceID:e,placeholder:"",other:!0})}else{var m=this.getAttribute("data-type");frmGetFieldValues(e,r,n,m,void 0,function(){var e=new CustomEvent("frm_logic_options_loaded");e.frmData={valueFieldType:o,fieldID:r,metaKey:n},document.dispatchEvent(e)})}}}function Gn(){var e=this.value;e&&Un(e,jQuery(this).closest(".frm-single-settings").data("fid"))}function Un(e,t){e&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_field_selection",field_id:t,form_id:e,nonce:frmGlobal.nonce},success:function(e){var r=jQuery("#frm_show_selected_fields_".concat(t));r.toggleClass("frm6",!e.includes("frm-inline-message")),r.html(e).show()}})}function Wn(){var e=this;return this.initOnceInAllInstances=function(){void 0===Wn.prototype.orderFieldsObject&&(Wn.prototype.orderFieldsObject={},Wn.prototype.fieldSettingsForm=document.getElementById("frm-end-form-marker").closest("form"))},this.getFieldOrderInputById=function(e,t){var r,n=Wn.prototype.orderFieldsObject,o=Wn.prototype.fieldSettingsForm;return void 0===n[e]?((r=o.querySelector('input[name="field_options[field_order_'.concat(e,']"]')))||(r=t.querySelector('input[name="field_options[field_order_'.concat(e,']"]'))),n[e]=r,r):n[e]},this.initOnceInAllInstances(),on(),function(){var t,r,n,o,i,a,l=new Qo,s=jQuery("li.frm_field_box",jQuery("#frm-show-fields"));for(i=0;i<s.length;i++)t=s[i].getAttribute("data-fid"),(n=(r=e.getFieldOrderInputById(t,s[i]))?Object.assign({},r.value)[0]:null)!=(o=i+1)&&null!==n&&(r.value=o,a=s[i].querySelector("#frm-single-settings-".concat(t)),l.append(a),ci());l.moveFields()}()}function $n(){document.querySelectorAll(".start_divider").forEach(function(e){Vn(jQuery(e))})}function Vn(e){if(e.length){for(var t=e.find("ul.frm_sorting"),r=!1,n=t.length,o=0;o<n;++o)if(0!==be(jQuery(t.get(o))).length){r=!0;break}e.parent().children(".frm_no_section_fields").get(0).classList.toggle("frm_block",!r)}}function Kn(){var e=jQuery(this).data("slidedown"),t=jQuery(document.getElementById(e));return t.is(":hidden")&&(t.slideDown("fast"),this.style.display="none"),!1}function Jn(){var e=jQuery(this).data("slideup"),t=jQuery(document.getElementById(e));return t.slideUp("fast"),t.siblings("a").show(),!1}function Xn(e,t){""===t.getAttribute("value")?Yn(jQuery(this)):function(e){var t=e.val();if(null===t)return e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!0),void Yn(e);var r=t.indexOf("");r>=0&&(t.splice(r,1),e.val(t),e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!1))}(jQuery(this))}function Yn(e){e.val(""),e.next(".btn-group").find('.multiselect-container input[value!=""]').prop("checked",!1)}function Zn(){jQuery(".frm-hide-empty").each(function(){0===jQuery(this).text().trim().length&&jQuery(this).remove()})}function eo(e){e.preventDefault(),function(e,t,r){var n=document.getElementById(e.getAttribute("data-open")),o=jQuery(e).closest("p,ul"),i=void 0!==t;if(o.hasClass("frm-open"))o.removeClass("frm-open"),n.classList.add("frm_hidden");else{if(i||(t=pi(e)),t){if(!i){var a=r.key;"Enter"!==a&&" "!==a&&t.focus()}o.after(n),n.setAttribute("data-fills",t.id.replace("-proxy-input","")),0===n.id.indexOf("frm-calc-box")&&yt(n,!0)}o.addClass("frm-open"),n.classList.remove("frm_hidden"),wp.hooks.doAction("frm_show_inline_modal",n,e)}}(this,void 0,e)}function to(e){e.preventDefault(),this.parentNode.classList.add("frm_hidden"),jQuery('.frm-open [data-open="'.concat(this.parentNode.id,'"]')).closest(".frm-open").removeClass("frm-open")}function ro(e){var t=e.target;t.closest(".frm-inline-modal.frm-modal-no-dismiss")||t.closest(".frm-show-inline-modal")||t.closest("#frm_adv_info")||t.closest(".frm-token-proxy-input")||document.querySelectorAll(".frm-inline-modal.frm-modal-no-dismiss:not(.frm_hidden)").forEach(function(e){e.classList.add("frm_hidden"),e.previousElementSibling.classList.remove("frm-open")})}function no(){var e,t=this.getAttribute("data-frmchange").split(",");for(e=0;e<t.length;e++)"updateOption"===t[e]?io(this):"updateDefault"===t[e]?oo(this):"checkUniqueOpt"===t[e]?zn(this):this.value=this.value[t[e]]()}function oo(e){var t=ao(e),r=t.getAttribute("data-optkey"),n=lo(t,r),o=t.querySelector('input[name="default_value_'.concat(n,'"]'));null!==o&&(o.value=e.value)}function io(e){var t,r=ao(e),n=r.getAttribute("data-optkey"),o=lo(r,n),i=document.getElementById("separate_value_".concat(o));i&&!1===i.checked&&((t=document.getElementById("field_key_".concat(o,"-").concat(n))).value=e.value,oo(t))}function ao(e){var t=e.parentNode;return"LI"!==t.tagName&&(t=t.parentNode),t}function lo(e,t){return e.id.replace("frm_delete_field_","").replace("-".concat(t,"_container"),"")}function so(){var e=this;if(!mo()){go(this);var t=jQuery(q),r=JSON.stringify(t.serializeArray());jQuery(document.getElementById("frm_compact_fields")).val(r),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_save_form",frm_compact_fields:r,nonce:frmGlobal.nonce},success:function(t){var r;(r=e).classList.remove("frm_loading_form"),r.classList.remove("frm_loading_button"),jQuery('.frm-single-settings ul input[type="text"][name^="field_options[options_"]').filter("[data-value-on-load]").removeAttr("data-value-on-load"),jQuery('input[type="hidden"][name^=optionmap]').remove(),N=0,r.setAttribute("aria-busy","false"),setTimeout(function(){jQuery(".frm_updated_message").fadeOut("slow",function(){this.remove()})},5e3);var n,o=document.getElementById("post-body-content"),i=document.createElement("div");i.setAttribute("class","frm_updated_message"),i.innerHTML=t,o.insertBefore(i,o.firstChild),(n=document.getElementById("frm_submit_side_top")).hasAttribute("data-new-addon-installed")&&"true"===n.getAttribute("data-new-addon-installed")&&(n.removeAttribute("data-new-addon-installed"),window.location.reload())},error:function(){co(document.getElementById("frm_js_build_form"))}})}}function co(e){var t=e.ownerDocument.createElement("input");t.style.display="none",t.type="submit",e.append(t),t.click(),t.remove()}function uo(e){jQuery(e).trigger("change")}function fo(){if(!mo()){go(this);var e=jQuery(q);jQuery(document.getElementById("frm_compact_fields")).val(JSON.stringify(e.serializeArray())),co(document.getElementById("frm_js_build_form"))}}function mo(){if((t=document.getElementById("frm_form_name"))&&""!==t.value.trim()||"true"!==U.get("new_template")||(null===(e=document.querySelector("#frm_top_bar #frm_bs_dropdown .frm_bstooltip"))||void 0===e?void 0:e.textContent.trim())!==frm_admin_js.noTitleText)return!1;var e,t,r=ea("#frm-form-templates-modal","440px");return!!r&&(_i(r,"72px"),r.dialog("open"),!0)}function _o(){var e=document.getElementById("frm-save-form-name-button"),t=document.getElementById("frm_new_form_name_input");E(e,po),t.addEventListener("keydown",function(e){"Enter"===e.key&&po(e)})}var po=function(e){var t=document.getElementById("frm_new_form_name_input").value.trim(),r=new FormData;r.append("form_id",U.get("id")),r.append("form_name",t),k("rename_form",r).then(function(e){U.delete("new_template"),G.search=U.toString(),history.replaceState({},"",G.toString()),null!==document.getElementById("frm_notification_settings")&&(document.getElementById("frm_form_name").value=t,document.getElementById("frm_form_key").value=e.form_key),jQuery("#frm-publishing").find(".frm_button_submit").trigger("click")})};function go(e){var t,r;ra(),jQuery("form.inplace_form").length&&jQuery(".inplace_save, .postbox").trigger("click"),e.classList.contains("frm_button_submit")?e.classList.add("frm_loading_form"):e.classList.add("frm_loading_button"),e.setAttribute("aria-busy","true"),t=document.querySelectorAll(".frm_format_dropdown, .frm_phone_type_dropdown"),r={none:"",international:"international",currency:"currency",number:"number"},t.forEach(function(e){var t=e.value;t in r&&(document.getElementById("frm_format_".concat(e.dataset.fieldId)).value=r[t])})}function vo(e){var t,r=null!==(t=e.target.dataset)&&void 0!==t&&t.modalTitle?e.target:e.target.closest("[data-modal-title]");if(r){var n=r.dataset,o=n.modalTitle,i=n.modalContent;o&&i&&(e.preventDefault(),frmDom.modal.maybeCreateModal("frmBasicModal",{title:o,content:h({className:"inside",child:b(i)})}))}}function yo(e){var t,n,i,s,u,f,m,_,p=e.dataset.upgrade,g=e.getAttribute("href").replace("#",""),v=document.querySelector(".frm_".concat(g))||document.querySelector(".".concat(g));if(v&&!v.querySelector(".frm-upgrade-message")){var y=v.querySelector("h2");y.style.borderBottom="none",y.textContent=R(P("%s are not installed","formidable"),p),v.classList.add("frmcenter");var b=document.getElementById("frm_upgrade_modal");A("frm-upgrade-message"),A("frm-oneclick"),A("frm-addon-status");var w=b.querySelector(".frm-upgrade-link");if(w){var j,E,k=w.closest(".frm-upgrade-modal-actions"),Q=(E=k?(k=k.cloneNode(!0)).querySelector(".frm-upgrade-link"):w.cloneNode(!0)).querySelector(".license-level");Q&&(Q.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(e)),e.dataset.gradientUpgrade&&E.classList.add("frm-gradient"),v.append(k||E),null!==(j=w.nextElementSibling)&&void 0!==j&&j.querySelector(".frm-link-secondary")&&v.append(w.nextElementSibling.cloneNode(!0)),A("frm-oneclick-button")}var S=e.dataset.message;void 0===S&&(S=e.dataset.upgrade),function(e,t,n){r(4260).addOneClick(e,"tab",n)}(e,0,S),e.dataset.upsellImages?v.append((t=e.dataset.upsellImages,n=p,s="".concat(frmGlobal.url,"/images/upsell/"),u=l(i=t.split(",").map(function(e){return x({src:s+e.trim(),alt:n})}))||o(i)||c(i)||a(),f=u[0],m=d(u).slice(1),_=[f],m.length&&_.push(h({className:"frm-upsell-images-row",children:m})),h({className:"frm-upsell-images",children:_}))):e.dataset.screenshot&&v.append(function(e){var t="".concat(frmGlobal.url,"/images/screenshots/");return h({className:"frm-settings-screenshot-wrapper",children:[function(){var e=["#ED8181","#EDE06A","#80BE30"].map(function(e){var t=h({className:"frm-minmax-icon"});return t.style.backgroundColor=e,t});return e.push(x({src:"".concat(frmGlobal.url,"/images/tab.svg")})),h({className:"frm-settings-screenshot-toolbar",children:e})}(),h({child:x({src:t+e})})]})}(e.dataset.screenshot))}function A(e){v.append(b.querySelector(".".concat(e)).cloneNode(!0))}}function ho(e){void 0===e&&(e=""),function(e){var t,r=jQuery("".concat(e," :not(.frm_has_shortcodes) .frm_not_email_message, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_to, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_subject"));for(t=0;t<r.length;t++)r[t].parentNode.classList.add("frm_has_shortcodes")}(e),jQuery("".concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) input,").concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) textarea")).wrap('<span class="frm-with-right-icon"></span>').before('<svg class="frmsvg frm-show-box"><use href="#frm_more_horiz_solid_icon"/></svg>')}function bo(){var e="success";"options[edit_action]"===this.name&&(e="edit");var t=jQuery(this).val();jQuery(".".concat(e,"_action_box")).hide(),"redirect"===t?jQuery(".".concat(e,"_action_redirect_box.").concat(e,"_action_box")).fadeIn("slow"):"page"===t?jQuery(".".concat(e,"_action_page_box.").concat(e,"_action_box")).fadeIn("slow"):jQuery(".".concat(e,"_action_message_box.").concat(e,"_action_box")).fadeIn("slow")}function wo(e){var t,r,n;if(e.stopPropagation(),!function(e){var t=jQuery(e),r=t.closest(".frm_form_action_settings"),n=r.find(".widget-inside");if(n.find("p, div, table").length)return!1;var o=r.find(".widget-top");return o.one("frm-action-loaded",function(){t.trigger("click"),r.removeClass("open"),n.hide()}),o.trigger("click"),!0}(e.target)){var o=e.target.closest(".frm_form_action_settings"),i=o.querySelectorAll(".wp-editor-area");i.length&&i.forEach(function(e){tinymce.EditorManager.execCommand("mceRemoveEditor",!0,e.id)});var a=jQuery(o).clone(),l=a.attr("id").replace("frm_form_action_",""),s=jo(l),c=null===(t=o.querySelector(".frm_action_name"))||void 0===t?void 0:t.value,d=function(e,t){for(var r=new Set(t),n=e,o=2;r.has(n);)n="".concat(e," (").concat(o,")"),o++;return n}((null!==(r=null===(n=o.querySelector(".widget-title h4 span:not(.frm-border-icon)"))||void 0===n?void 0:n.textContent.trim())&&void 0!==r?r:"").replace(/ \(\d+\)$/,""),xo(c));a[0].querySelector(".widget-title h4 span:not(.frm-border-icon)").textContent=d,a[0].querySelector('input[name$="['.concat(l,'][post_title]"]')).value=d,a.find(".frm_action_id, .frm-btn-group").remove(),a.find('input[name$="['.concat(l,'][ID]"]')).val(""),a.find(".widget-inside").hide(),a.find("input[type=text], textarea, input[type=number]").prop("defaultValue",function(){return this.value}),a.find("input[type=checkbox], input[type=radio]").prop("defaultChecked",function(){return this.checked});var u=new RegExp("\\[".concat(l,"\\]"),"g"),f=new RegExp("_".concat(l,'"'),"g"),m=new RegExp("_".concat(l," "),"g"),_=new RegExp("-".concat(l,'"'),"g"),p=new RegExp('"'.concat(l,'"'),"g"),g=a.html().replace(u,"[".concat(s,"]")).replace(f,"_".concat(s,'"'));g=(g=g.replace(m,"_".concat(s," "))).replace(_,"-".concat(s,'"')).replace(p,'"'.concat(s,'"'));var v=h({id:"frm_form_action_".concat(s),className:a.get(0).className});v.setAttribute("data-actionkey",s),v.innerHTML=g,v.querySelectorAll(".wp-editor-wrap, .wp-editor-wrap *").forEach(function(e){"string"==typeof e.className&&(e.className=e.className.replace(l,s)),e.id=e.id.replace(l,s)}),v.classList.remove("open"),document.getElementById("frm_notification_settings").append(v),i.length&&(i.forEach(function(e){frmDom.wysiwyg.init(e)}),v.querySelectorAll(".wp-editor-area").forEach(function(e){frmDom.wysiwyg.init(e)})),v.classList.contains("frm_single_on_submit_settings")&&v.querySelector("input.frm-page-search")&&Pi(v),Bi(),wp.hooks.doAction("frm_after_duplicate_action",v)}}function jo(e){var t=parseInt(e,10)+11;return document.getElementById("frm_form_action_".concat(t))&&(t=jo(++t)),t}function xo(e){return Array.from(document.querySelectorAll(".frm_single_".concat(e,"_settings .widget-title h4 span:not(.frm-border-icon)")),function(e){return e.textContent.trim()})}function Eo(){var e,t=jQuery(this).data("actiontype");if(!qo(t)){var r=(e=Kr(document.querySelectorAll(".frm_form_action_settings"),"frm_form_action_"),void 0!==document.getElementById("frm_form_action_".concat(e))&&(e+=100),D>=e&&(e=D+1),D=e,e),n=T,o=xo(t),i=document.createElement("div");i.classList.add("frm_single_".concat(t,"_settings"));var a=document.getElementById("frm_notification_settings");a.append(i),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_action",type:t,list_id:r,form_id:n,nonce:frmGlobal.nonce,existing_titles:o},success:function(e){var n;ci(),i.remove(),null===(n=document.querySelector(".frm-no-actions-message"))||void 0===n||n.classList.add("frm_hidden"),document.querySelectorAll(".frm_form_action_settings.open").forEach(function(e){return e.classList.remove("open")});var o=h();o.innerHTML=e;var l=o.querySelector(".widget-top");Array.from(o.children).forEach(function(e){return a.append(e)}),jQuery(".frm_form_action_settings").fadeIn("slow");var s,c,d=document.getElementById("frm_form_action_".concat(r));d.classList.add("open"),document.getElementById("post-body-content").scroll({top:d.offsetTop+10,left:0,behavior:"smooth"}),Io(t),(c=["stripe","square","paypal"]).includes(s=t)&&c.forEach(function(e){e!==s&&Io(e)}),ho("#frm_form_action_".concat(r)),Bi(),Pi(d),l&&jQuery(l).trigger("frm-action-loaded"),frmAdminBuild.hooks.doAction("frm_added_form_action",d)}})}}function ko(e){e.on("Change",function(){!function(e){(function(){var e=document.querySelector(".frm-single-settings:not(.frm_hidden)");if(!e)return!1;var t=e.querySelector(".wp-editor-wrap");return t&&t.classList.contains("tmce-active")})()&&!tinyMCE.activeEditor.isHidden()&&(e.targetElm.value=e.getContent(),jQuery(e.targetElm).trigger("change"))}(e)})}function Qo(e){var t=this;if(null!==e)return this.fragment=document.createDocumentFragment(),this.initOnceInAllInstances=function(){void 0===Qo.prototype.endMarker&&(Qo.prototype.endMarker=document.getElementById("frm-end-form-marker"))},this.append=function(e){var r=e?e.parentElement.classList:"";e&&(r.contains("frm_field_box")||r.contains("divider_section_only"))&&t.fragment.append(e)},this.moveFields=function(){q.insertBefore(t.fragment,Qo.prototype.endMarker)},this.initOnceInAllInstances(),void 0!==e?(this.append(e),void this.moveFields()):{append:this.append,moveFields:this.moveFields}}function So(){var e=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),t=this.getAttribute("data-emailrow");jQuery("#frm_form_action_".concat(e," .frm_").concat(t,"_row")).fadeIn("slow"),jQuery(this).fadeOut("slow")}function Ao(){var e=jQuery(this).closest(".frm_form_action_settings"),t=this.getAttribute("data-emailrow"),r=".frm_".concat(t,"_row"),n=".frm_".concat(t,"_button");jQuery(e).find(n).fadeIn("slow"),jQuery(e).find(r).fadeOut("slow",function(){jQuery(e).find("".concat(r," input")).val("")})}function Lo(){var e=jQuery(this).closest(".frm_form_action_settings"),t=".frm_from_to_match_row";e.find('input[name$="[post_content][from]"]').val()===e.find('input[name$="[post_content][email_to]"]').val()?jQuery(e).find(t).fadeIn("slow"):jQuery(e).find(t).fadeOut("slow")}function Io(e){var t,r,n=document.querySelectorAll(".frm_".concat(e,"_action"));qo(e)?(t=n,r=Bo(e)>0,t.forEach(function(e){e.classList.remove("frm_active_action"),e.classList.add("frm_inactive_action"),r&&e.classList.add("frm_already_used")})):n.forEach(function(e){e.querySelector(".frm_show_upgrade")||(e.classList.remove("frm_inactive_action","frm_already_used"),e.classList.add("frm_active_action"))})}function qo(e){var t=function(e){return["paypal","stripe","square"].includes(e)&&(e="payment"),jQuery(".frm_single_".concat(e,"_settings")).length}(e)>=Bo(e),r={type:e};return wp.hooks.applyFilters("frm_action_at_limit",t,r)}function Bo(e){return parseInt(jQuery(".frm_".concat(e,"_action")).data("limit"),10)}function Co(){var e=f.only_one_action,t=this.dataset.limit,r=this.dataset.actiontype;r&&["paypal","stripe","square","payment"].includes(r)&&(e="stripe"===r?f.only_one_stripe_action:f.only_one_payment_action),void 0!==t&&((t=parseInt(t))>1?e=e.replace(1,t).trim():e+=" ".concat(f.edit_action_text)),K(e)}function No(e,t){var r=jQuery(t).closest(".frm_form_action_settings").find(".frm_action_name").val(),n=document.getElementById("form_id").value,o=document.getElementById("frm_logic_row_".concat(e)),i=Kr(o.querySelectorAll(".frm_logic_row"),"frm_logic_".concat(e,"_")),a=h({id:"frm_logic_".concat(e,"_").concat(i),className:"frm_logic_row frm_hidden"}),l=document.getElementById("logic_link_".concat(e)),s=l?o.closest(".frm_logic_rows"):null;o.append(a),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_logic_row",email_id:e,form_id:n,meta_name:i,type:r,nonce:frmGlobal.nonce},success:function(e){a.insertAdjacentHTML("beforebegin",e),a.remove();var t=o.querySelector(".frm_logic_row:last-child"),r=t?t.querySelector(".frm-logic-rule-text"):null;r&&(r.textContent=o.dataset.ruleText||""),l&&l.classList.add("frm_hidden"),s&&(s.classList.remove("frm_hidden"),s.style.display="")}})}function To(){return No(jQuery(this).data("emailkey"),this),!1}function Oo(){var e;if(this.checked){var t=this.getAttribute("data-emailkey");if(t&&null!==(e=this.dataset.toggleclass)&&void 0!==e&&e.startsWith("frm_logic_rows_")){var r=document.getElementById("frm_logic_row_".concat(t));r&&!r.querySelector(".frm_logic_row")&&No(t,this)}}}function Fo(){var e=jQuery("select.frm_single_post_field");e.css("border-color","");var t=this,r=jQuery(t).val();if(""===r||"checkbox"===r)return!1;e.each(function(){if(jQuery(this).val()===r&&this.name!==t.name)return this.style.borderColor="red",jQuery(t).val(""),K(f.field_already_used),!1})}function Do(){var e=jQuery(this).val();""===e?(jQuery(".frm_post_content_opt, select.frm_dyncontent_opt").hide().val(""),jQuery(".frm_dyncontent_opt").hide()):"post_content"===e?(jQuery(".frm_post_content_opt").show(),jQuery(".frm_dyncontent_opt").hide(),jQuery("select.frm_dyncontent_opt").val("")):(jQuery(".frm_post_content_opt").hide().val(""),jQuery("select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt").show())}function Mo(){var e=jQuery(this).val(),t=jQuery(document.getElementById("frm_dyncontent"));""===e||"new"===e?(t.val(""),jQuery(".frm_dyncontent_opt").show()):jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_display_get_content",id:e,nonce:frmGlobal.nonce},success:function(e){t.val(e),jQuery(".frm_dyncontent_opt").show()}})}function Po(){var e,t,r=document.getElementById("frm_posttax_rows").childNodes,n=document.querySelector(".frm_post_parent_field"),o=document.querySelector(".frm_post_menu_order_field"),i=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_replace_posttax_options",post_type:i,nonce:frmGlobal.nonce},success:function(n){for(var o=0;o<r.length;o++)"DIV"===r[o].tagName&&(e=r[o].getElementsByTagName("select")[0],(t=document.createElement("select")).innerHTML=n,t.className=e.className,t.name=e.name,r[o].replaceChild(t,e))}}),n&&Ro(n,i,"frm_get_post_parent_option",function(e,t){n.querySelector(".frm_post_parent_opt_wrapper").innerHTML=e.replaceAll("REPLACETHISNAME",t),Pi(n)}),o&&Ro(o,i,"frm_should_use_post_menu_order_option")}function Ro(e,t,r,n){var o=(e.querySelector(".frm_autocomplete_value_input")||e.querySelector("select")).getAttribute("name");jQuery.ajax({url:ajaxurl,method:"POST",data:{action:r,post_type:t,_wpnonce:frmGlobal.nonce},success:function(t){if("string"==typeof t){if("0"===t)return e.classList.add("frm_hidden"),void(e.value="");e.classList.remove("frm_hidden"),"function"==typeof n&&n(t,o)}else console.error(t)},error:function(e){return console.error(e)}})}function zo(){Go("tax",this)}function Ho(){Go("meta",this)}function Go(e,t){var r,n,o=jQuery('input[name="id"]').val(),i=jQuery(t).closest(".frm_form_action_settings"),a=i.data("actionkey"),l=i.find(".frm_post_type").val(),s=0,c=document.querySelectorAll(".frm_post".concat(e,"_row"));c.length&&(n=r=c[c.length-1].id.replace("frm_post".concat(e,"_"),""),s=!isNaN(parseFloat(n))&&isFinite(n)?1+parseInt(r,10):1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_post".concat(e,"_row"),form_id:o,meta_name:s,tax_key:s,post_type:l,action_key:a,nonce:frmGlobal.nonce},success:function(t){var r,n;if(jQuery(document.getElementById("frm_post".concat(e,"_rows"))).append(t),jQuery(".frm_add_post".concat(e,"_row.button")).hide(),"meta"===e)for(jQuery(".frm_name_value").show(),r=document.querySelectorAll(".frm_toggle_cf_opts"),n=0;n<r.length-1;++n)r[n].style.display="none";else"tax"===e&&jQuery(".frm_posttax_labels").show()}})}function Uo(){if(jQuery(this).closest(".frm_posttax_row").find(".frm_posttax_opt_list").length){jQuery(this).closest(".frm_posttax_row").find(".frm_posttax_opt_list").html('<div class="spinner frm_spinner" style="display:block"></div>');var e=jQuery(this).closest(".frm_form_action_settings").find('select[name$="[post_content][post_type]"]').val(),t=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),r=jQuery(this).closest(".frm_posttax_row").attr("id").replace("frm_posttax_",""),n=jQuery(this).val(),o=jQuery(document.getElementById("".concat(r,"_show_exclude"))).is(":checked")?1:0,i=jQuery('select[name$="[post_category]['.concat(r,'][field_id]"]')).val(),a=jQuery('input[name="id"]').val();jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_posttax_row",form_id:a,post_type:e,tax_key:r,action_key:t,meta_name:n,field_id:i,show_exclude:o,nonce:frmGlobal.nonce},success:function(e){jQuery(document.getElementById("frm_posttax_".concat(r))).replaceWith(e)}})}}function Wo(){var e=jQuery(this).closest(".frm_postmeta_row"),t=e.find(".frm_cancelnew"),r=e.find(".frm_enternew");return e.find("select.frm_cancelnew").is(":visible")?(t.hide(),r.show()):(t.show(),r.hide()),e.find("input.frm_enternew, select.frm_cancelnew").val(""),!1}function $o(){var e=jQuery(this),t=e.val();"checkbox"===e.attr("type")&&!1===this.checked&&(t="");var r=e.data("toggleclass");""===t?jQuery(".".concat(r)).hide():(jQuery(".".concat(r)).show(),jQuery(".hide_".concat(r,"_").concat(t)).hide())}function Vo(){mo()||(go(this),co(document.querySelector(".frm_form_settings")))}function Ko(e){return e.preventDefault(),Jo(jQuery(this),this.getAttribute("data-code")),!1}function Jo(e,t){var r=!1,n=e;if("object"===i(e)){if(e.hasClass("frm_noallow"))return;void 0===(n=jQuery(e).closest("[data-fills]").attr("data-fills"))&&void 0!==(n=e.closest("div").attr("class"))&&(n=n.split(" ")[1])}if(void 0===n){var o=document.activeElement;"search"===o.type?null===(n=o.id.replace("-search-input","")).match(/\d/gi)&&(n=(o=jQuery(".frm-single-settings:visible .".concat(n))).attr("id")):n=o.id}n&&(r=jQuery("#wp-".concat(n,"-wrap.wp-editor-wrap")).length>0);var a=jQuery(document.getElementById(n));if(void 0===e.attr("data-shortcode")&&(!a.length||void 0===a.attr("data-shortcode"))){var l=e.parents("ul.frm_code_list").attr("data-shortcode");"undefined"!==l&&"no"===l||(t="[".concat(t,"]"))}if(r&&(wpActiveEditor=n),!a.length)return!1;if("[default-html]"===t||"[default-plain]"===t){var s=0;"[default-plain]"===t&&(s=1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_default_html",form_id:jQuery('input[name="id"]').val(),plain_text:s,nonce:frmGlobal.nonce},elementId:n,success:function(e){if(r){var t=document.createElement("p");t.innerText=e,send_to_editor(t.innerHTML)}else Xo(a,e)}})}else t=function(e,t,r){return"object"===i(t)&&t instanceof jQuery&&0===r[0].id.indexOf("success_url_")&&(t=t[0]).closest("#frm-insert-fields-box")?(t.parentNode.classList.contains("frm_insert_url")||(e=e.replace("]"," sanitize_url=1]")),e):e}(t,e,a),r?send_to_editor(t):Xo(a,t);return!1}function Xo(e,t){if(document.selection)e[0].focus(),document.selection.createRange().text=t;else{var r=e[0],n=r.selectionEnd;t=function(e,t,r,n){var o=e.data("sep");if(void 0===o)return t;var i=e.val();if(!i.trim().length)return t;var a=new RegExp("".concat(o,"\\s*$")),l=new RegExp("^\\s*".concat(o));return i.substr(0,r).trim().length&&!1===a.test(i.substr(0,r))&&(t=o+t),i.substr(n,i.length).trim().length&&!1===l.test(i.substr(n,i.length))&&(t+=o),t}(e,t,r.selectionStart,n),r.value=r.value.substr(0,r.selectionStart)+t+r.value.substr(r.selectionEnd,r.value.length);var o=n+t.length;!function(e,t){if(e.classList.contains("frm_classes")&&Yo(t)){var r=e.value.split(" ").filter(Yo);r.length&&(e.value=function(e,t,r){var n=e.split(" ").filter(function(e){return(e=e.trim()).length&&!t.includes(e)});return n.includes(r)||n.push(r),n.join(" ")}(e.value,r,t.trim()))}}(r,t),r.focus(),r.setSelectionRange(o,o)}uo(e)}function Yo(e){return["frm_half","frm_third","frm_two_thirds","frm_fourth","frm_three_fourths","frm_fifth","frm_sixth","frm2","frm3","frm4","frm6","frm8","frm9","frm10","frm12"].includes(e.trim())}function Zo(){var e=document.getElementById("frm-id-condition"),t=document.getElementById("frm-key-condition");"id"===this.value?(e.classList.remove("frm_hidden"),t.classList.add("frm_hidden"),Ki(t,"change")):(e.classList.add("frm_hidden"),t.classList.remove("frm_hidden"),Ki(e,"change"))}function ei(){var e=document.getElementById("frm-id-key-condition-id").checked?"frm-id-condition":"frm-key-condition",t=document.getElementById("frm-is-condition").value,r=document.getElementById("frm-text-condition").value,n=document.getElementById("frm-insert-condition"),o=(e=document.getElementById(e)).options[e.selectedIndex].value,i="if ".concat(o," ").concat(t,'="').concat(r,'"]');n.setAttribute("data-code","".concat(i+f.conditional_text,"[/if ").concat(o)),n.innerHTML="[".concat(i,"[/if ").concat(o,"]")}function ti(e){return e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href")}function ri(e){var t;e.parentNode.parentNode.classList.contains("frm_has_shortcodes")&&(vi(),"use"===(t=gi(e)).tagName?ti(t=t.firstElementChild).includes("frm_close_icon")||li(t,"nofocus"):t.classList.contains("frm_close_icon")||li(t,"nofocus"))}function ni(e){e.preventDefault(),e.stopPropagation(),li(this)}function oi(e){var t=e.target;!function(e){var t;if(e.id.startsWith("field_options_type_")){var r=e.id.split("_"),n=r.length&&r[r.length-1];null!==(t=document.querySelector("#frm-single-settings-".concat(n)))&&void 0!==t&&t.classList.contains("frm-type-".concat(e.value))||ii()}}(t),g(t)}function ii(e){var t;void 0===e&&(e=P("You are changing the field type. Not all field settings will appear as expected until you reload the page. Would you like to reload the page now?","formidable")),frmDom.modal.maybeCreateModal("frmSaveAndReloadModal",{title:P("Save and Reload?","formidable"),content:(t=h(e),t.style.padding="var(--gap-md)",t),footer:function(){var e=frmDom.modal.footerButton({text:P("Save and Reload","formidable"),buttonType:"primary"});E(e,function(){var e;(e=document.getElementById("frm_submit_side_top")).classList.contains("frm_submit_ajax")&&e.setAttribute("data-new-addon-installed",!0),e.click()});var t=frmDom.modal.footerButton({text:P("Cancel","formidable"),buttonType:"cancel"});return t.classList.add("dismiss"),frmDom.div({children:[t,e]})}()})}function ai(e){var t;if(e instanceof Event){var r=document.querySelectorAll(".frm-single-settings .frm-show-box.frmsvg use"),n=Array.from(r).find(function(e){return"#frm_close_icon"===e.getAttribute("href")});if(void 0===n)return;t=n.parentElement}else t=e;var o=t.getBoundingClientRect(),i=document.getElementById("frm_adv_info"),a=i.parentElement.getBoundingClientRect();i.style.top="".concat(o.top-a.top+32,"px"),i.style.left="".concat(o.left-a.left-280,"px")}function li(e,t){var r=pi(e),n=document.getElementById("frm_adv_info"),o=e.className;if("svg"===e.tagName&&(e=e.firstElementChild),"use"===e.tagName&&(o=ti(e)),o.includes("frm_close_icon"))vi(n);else{if(ai(e),jQuery(".frm_code_list a").removeClass("frm_noallow"),r.classList.contains("frm_not_email_to")?jQuery("#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a").addClass("frm_noallow"):r.classList.contains("frm_not_email_subject")&&jQuery(".frm_code_list li.hide_frm_not_email_subject a").addClass("frm_noallow"),n.setAttribute("data-fills",r.id),n.style.display="block","use"===e.tagName)if(e.hasAttributeNS("http://www.w3.org/1999/xlink","href"))e.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon");else{var i=document.createElementNS("http://www.w3.org/2000/svg","use");i.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon"),e.parentNode.replaceChild(i,e)}else e.className=o.replace("frm_more_horiz_solid_icon","frm_close_icon");"nofocus"!==t&&("none"!==r.style.display?r.focus():jQuery(tinymce.get(r.id)).trigger("focus")),function(e){["address","body"].forEach(function(t){!function(e,t){var r,n=f.contextualShortcodes["".concat(t,"Selector")],o=f.contextualShortcodes[t],i=e.matches(n),a=s(o);try{for(a.s();!(r=a.n()).done;){var l,c=r.value,d=null===(l=document.querySelector('#frm-adv-info-tab .frm_code_list [data-code="'.concat(c,'"]')))||void 0===l?void 0:l.closest("li");null==d||d.classList.toggle("frm_hidden",!i)}}catch(e){a.e(e)}finally{a.f()}}(e,t)})}(r)}}function si(e){return 0===f.contextualShortcodes.length||!function(e){var t=e.querySelector("a");if(!t)return!1;var r=t.dataset.code;return f.contextualShortcodes.address.includes(r)||f.contextualShortcodes.body.includes(r)}(e)||function(e){var t=e.querySelector("a").dataset.code,r=document.getElementById("frm_adv_info").dataset.fills,n=document.getElementById(r),o=f.contextualShortcodes;return o.address.includes(t)?n.matches(o.addressSelector):n.matches(o.bodySelector)}(e)}function ci(){N||(N=1,window.addEventListener("beforeunload",mi))}function di(){N=0}function ui(){N=0}function fi(){N=0}function mi(e){N&&(e.preventDefault(),e.returnValue="")}function _i(e,t){var r={my:"top",at:"top+".concat(t),of:window};e.dialog("option","position",r)}function pi(e){if(e.classList.contains("frm-input-icon"))return e.previousElementSibling;for(var t,r=e.nextElementSibling;r&&("INPUT"!==r.tagName&&"TEXTAREA"!==r.tagName||r.classList.contains("frm-token-input-field"));)r=pi(r);return r||(r=null===(t=e.closest(".frm-field-formula"))||void 0===t?void 0:t.querySelector(".frm-calc-field")),r}function gi(e){var t;if(null!==(t=e.nextElementSibling)&&void 0!==t&&t.classList.contains("frm-input-icon"))return e.nextElementSibling;for(var r=e.previousElementSibling;null!==r&&"I"!==r.tagName&&"svg"!==r.tagName;)r=gi(r);return r}function vi(e){if((void 0!==e||(e=document.getElementById("frm_adv_info")))&&null===document.getElementById("frm_dyncontent")){e.style.display="none";for(var t=document.querySelectorAll(".frm-show-box.frm_close_icon"),r=0;r<t.length;r++)t[r].classList.remove("frm_close_icon"),t[r].classList.add("frm_more_horiz_solid_icon");for(var n=document.querySelectorAll(".frm_has_shortcodes use"),o=0;o<n.length;o++)if("#frm_close_icon"===ti(n[o])){if(n[o].closest(".frm_remove_field"))continue;n[o].setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_more_horiz_solid_icon")}}}function yi(e,t){t.stopPropagation(),jQuery(".frm_code_list .frmids, .frm_code_list .frmkeys").addClass("frm_hidden"),jQuery(".frm_code_list .".concat(e)).removeClass("frm_hidden"),jQuery(".frmids, .frmkeys").removeClass("current"),jQuery(".".concat(e)).addClass("current")}function hi(e){var t=e.target.closest(".frm_form_action_settings");t&&(t.classList.contains("frm_single_email_settings")||t.classList.contains("frm_single_on_submit_settings"))&&function(e){e.querySelectorAll(".wp-editor-area").forEach(function(e){frmDom.wysiwyg.init(e,{height:160,addFocusEvents:!0})})}(t)}function bi(){return!0===V(this)&&(jQuery(".frm_uninstall .frm-wait").css("visibility","visible"),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_uninstall&nonce=".concat(frmGlobal.nonce),success:function(e){jQuery(".frm_uninstall").fadeOut("slow"),window.location=e}})),!1}function wi(){var e=jQuery(this),t=this.name,r=this.getAttribute("data-plugin"),n=t.replace("edd_".concat(r,"_license_"),""),o=document.getElementById("edd_".concat(r,"_license_key")).value;e.get(0).disabled=!0,jQuery.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_".concat(n),license:o,plugin:r,nonce:frmGlobal.nonce},success:function(t){e.get(0).disabled=!1;var i=e.closest(".edd_frm_license_row");"deactivate"===n&&(o="",document.getElementById("edd_".concat(r,"_license_key")).value=""),i.find(".edd_frm_license").html(o);var a=e.get(0).closest(".frm_form_field"),l=!0===t.success;a.querySelector(".frm_icon_font.frm_action_success").classList.toggle("frm_hidden",!l||"deactivate"===n),a.querySelector(".frm_icon_font.frm_action_error").classList.toggle("frm_hidden",l);var s=i.find(".frm_license_msg");s.html(t.message),""!==t.message&&setTimeout(function(){if(s.html(""),i.find(".frm_icon_font").addClass("frm_hidden"),l){var e="activate"===n;i.get(0).querySelector(".edd_frm_unauthorized").classList.toggle("frm_hidden",e),i.get(0).querySelector(".edd_frm_authorized").classList.toggle("frm_hidden",!e)}},2e3)}})}function ji(e){e.preventDefault();var t=jQuery(e.target).find("input:checked");if(t.length){var r,n,o,i,a=[];t.each(function(e){a[e]=this.value}),r=a,n=e.target,(i=(o=jQuery(n)).next(".frm-importer-process")).find(".form-total").text(r.length),i.find(".form-current").text("1"),o.hide(),i.find(".process-completed").hide(),i.show(),H.importQueue=r,H.imported=0,xi(i)}}function xi(e){var t=H.importQueue[0],r=jQuery("#welcome-panel").find('input[name="slug"]').val(),n={action:"frm_import_".concat(r),form_id:t,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,n,function(r){var n;r.success&&(n=r.data.error?"<p>".concat(r.data.name,": ").concat(r.data.msg,"</p>"):'<p>Imported <a href="'.concat(r.data.link,'" target="_blank">').concat(r.data.name,"</a></p>"),e.find(".status").prepend(n),e.find(".status").show(),H.importQueue=jQuery.grep(H.importQueue,function(e){return e!=t}),H.imported++,0===H.importQueue.length?(e.find(".process-count").hide(),e.find(".forms-completed").text(H.imported),e.find(".process-completed").show()):(e.find(".form-current").text(H.imported+1),xi(e)))})}function Ei(e){e.preventDefault();var t=!1,r=jQuery('input[name="frm_export_forms[]"]');jQuery('input[name="frm_export_forms[]"]:checked').val()||(r.closest(".frm-table-box").addClass("frm_blank_field"),t="stop");var n=jQuery('input[name="type[]"]');if(jQuery('input[name="type[]"]:checked').val()||"checkbox"!==n.attr("type")||(n.closest("p").addClass("frm_blank_field"),t="stop"),"stop"===t)return!1;e.stopPropagation(),this.submit()}function ki(){var e=jQuery(this).closest(".frm_blank_field");if(void 0!==e){var t=this.name;("type[]"===t&&jQuery('input[name="type[]"]:checked').val()||"frm_export_forms[]"===t&&jQuery(this).val())&&e.removeClass("frm_blank_field")}}function Qi(){null!==jQuery(this).val().match(/\.csv$/i)?jQuery(".show_csv").fadeIn():jQuery(".show_csv").fadeOut()}function Si(){var e=document.querySelector('select[name="format"]');return e?e.value:""}function Ai(e){var t,r,n=e.target.value;Ii(n),Li.call(e.target),t=n,r=document.getElementById("frm-export-select-all"),"csv"===t?(r.checked=!1,r.disabled=!0):r.disabled=!1}function Li(){var e=jQuery(this),t=e.find(":selected"),r=t.data("support"),n=r.indexOf("|");jQuery('input[name="type[]"]').each(function(){this.checked=!1,r.includes(this.value)?(this.disabled=!1,-1===n&&(this.checked=!0)):this.disabled=!0}),"csv"===e.val()?(jQuery(".csv_opts").show(),jQuery(".xml_opts").hide()):(jQuery(".csv_opts").hide(),jQuery(".xml_opts").show());var o=t.data("count"),i=jQuery('input[name="frm_export_forms[]"]');"single"===o?(i.prop("multiple",!1),i.prop("checked",!1)):(i.prop("multiple",!0),i.prop("disabled",!1)),e.trigger("change")}function Ii(e){if(""!==e){var t=document.querySelectorAll(".frm-is-repeater");t.length&&("csv"===e?t.forEach(function(e){e.classList.remove("frm_hidden")}):t.forEach(function(e){e.classList.add("frm_hidden")}),Wi.call(document.querySelector(".frm-auto-search")))}}function qi(){var e=jQuery("select[name=format]").find(":selected").data("count"),t=jQuery('input[name="frm_export_forms[]"]');"single"===e&&this.checked?(t.prop("disabled",!0),this.removeAttribute("disabled")):t.prop("disabled",!1)}function Bi(e){(e?jQuery(e).find(".frm_multiselect"):jQuery(".frm_multiselect")).hide().each(frmDom.bootstrap.multiselect.init)}function Ci(e){e.preventDefault(),Oi(this,"frm_multiple_addons")}function Ni(e){e.preventDefault(),Oi(this,"frm_activate_addon")}function Ti(e){e.preventDefault(),Oi(this,"frm_install_addon")}function Oi(e,t){r(1105).toggleAddonState(e,t)}function Fi(){Mi()}function Di(e){!function(e,t,r){var n=jQuery("#frm_leave_email_error");n.removeClass("frm_hidden").attr("frm-error",r),jQuery("#frm_leave_email").one("keyup",function(){n.addClass("frm_hidden")})}(0,0,e)}function Mi(){var e=document.getElementById("frmapi-email-form");jQuery.ajax({dataType:"json",url:e.getAttribute("data-url"),success:function(t){var r=t.renderedHtml;r=r.replace(/<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi,""),e.innerHTML=r}})}function Pi(e){frmDom.autocomplete.initSelectionAutocomplete(e)}function Ri(e){var t=this.parentNode.parentNode,r=t.elements.type.value;e.preventDefault(),this.classList.add("frm_loading_button"),Hi(t,r,this)}function zi(e){var t=this.elements.type.value,r=this.querySelector("button");e.preventDefault(),r.classList.add("frm_loading_button"),Hi(this,t,r)}function Hi(e,t,r){var n=function(e){var t,r,n={},o=e.elements;for(r=0;r<o.length;r++){var i=o[r],a=i.name,l=i.value,s=a.match(/(.*)\[(.*)\]/);("radio"!==i.type&&"checkbox"!==i.type||i.checked)&&(null===s?Reflect.has(n,a)?(Array.isArray(n[a])||(n[a]=[n[a]]),n[a].push(l)):n[a]=l:(a=s[1],t=s[2],Reflect.has(n,a)||(n[a]={}),n[a][t]=l))}return n}(e),o=n.template_name,i=n.template_desc,a=e.elements.link.value,l={action:t,xml:a,name:o,desc:i,form:JSON.stringify(n),nonce:frmGlobal.nonce},s={formData:n};Ji(l=wp.hooks.applyFilters("frm_before_install_new_form",l,s),function(t){if(void 0!==t.redirect){var n=t.redirect;if(void 0===e.elements.redirect)window.location=n;else{var o=document.getElementById("frm-redirect-link");void 0!==a&&o&&(o.setAttribute("href",n),o.classList.remove("frm_grey","disabled"),(i=e.parentNode.parentNode).classList.add("frm_grey"),i.nextElementSibling.classList.remove("frm_grey"),r.classList.add("frm_grey","disabled"))}}else jQuery(".spinner").css("visibility","hidden"),"string"==typeof t.message&&function(e){var t=h(e);t.style.padding="20px 40px",frmDom.modal.maybeCreateModal("frmInstallFormErrorModal",{title:P("Unable to install template","formidable"),content:t}).classList.add("frm_common_modal")}(t.message);var i;r.classList.remove("frm_loading_button")})}function Gi(e){var t=document.getElementById("frm_captcha_threshold_container");t&&t.classList.toggle("frm_hidden","v3"!==e.target.value)}function Ui(e){var t=this.getAttribute("data-id");e.preventDefault(),Ji({action:"frm_forms_trash",id:t,nonce:frmGlobal.nonce},function(){var e=document.getElementById("frm-template-custom-".concat(t));Xi(e,function(){e.remove()})})}function Wi(){var e,t,r=!1,n=this.value.toLowerCase(),o=this.getAttribute("data-tosearch"),i=document.getElementsByClassName(o);for("SELECT"===this.tagName&&(n=function(e){for(var t,r=[],n=null==e?void 0:e.options,o=0,i=null==n?void 0:n.length;o<i;o++)(t=n[o]).selected&&r.push(t.value);return r}(this),n=n.join("|").toLowerCase(),r=!0),e=0;e<i.length;e++){var a=i[e].textContent.toLowerCase(),l=!("xml"===Si()&&i[e].classList.contains("frm-is-repeater"));""===n?(l&&si(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.remove("frm-search-result")):r&&new RegExp(n).test(a)||a.includes(n)||$i(a,n)?(l&&si(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.add("frm-search-result")):(i[e].classList.add("frm_hidden"),i[e].classList.remove("frm-search-result"))}(t=document.querySelector("#frm-insert-fields"))&&t.querySelectorAll(":scope > .frm-with-line").forEach(function(e){var t=e.nextElementSibling;if(t){var r=t.querySelectorAll(":scope > li.frmbutton"),n=Array.from(r).every(function(e){return e.classList.contains("frm_hidden")});e.classList.toggle("frm_hidden",n)}}),jQuery(this).trigger("frmAfterSearch")}function $i(e,t){return"s"!==t&&"s"!==e[e.length-1]&&"".concat(e,"s").includes(t)}function Vi(e){e.stopPropagation()}function Ki(e,t){var r=document.createEvent("HTMLEvents");r.initEvent(t,!1,!0),e.dispatchEvent(r)}function Ji(e,t){var r,n=new XMLHttpRequest,o="string"==typeof e?e:Object.keys(e).map(function(t){return"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(e[t]))}).join("&");return n.open("post",ajaxurl,!0),n.onreadystatechange=function(){if(n.readyState>3&&200==n.status){r=n.responseText;try{r=JSON.parse(r)}catch(e){}t(r)}},n.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n.send(o),n}function Xi(e,t){e.classList.add("frm-fade"),setTimeout(t,1e3)}function Yi(e){jQuery(e).css("visibility","hidden")}function Zi(e){jQuery(e).css("visibility","visible")}function ea(e,t){return r(4260).initModal(e,t)}function ta(e,t,r){if("#"===t){var n=document.getElementById(e);if(void 0!==r)n.style.display=r?"block":"none";else{var o=n.style.display;n.style.display="none"===o?"block":"none"}}else void 0!==r?r?e.show():e.hide():e.is(":visible")?e.hide():e.show()}function ra(){window.onbeforeunload=null;var e=jQuery(window);e.off("beforeunload.widgets"),e.off("beforeunload.edit-post")}function na(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));if(t&&"form"===t.dataset.type)if(t=jQuery(t),this.options[this.selectedIndex].value){t.find(".frm-not-set")[0].classList.add("frm_hidden");var r=t.find(".frm-embed-message");r.html(r.data("embedmsg")+this.options[this.selectedIndex].text),t.find(".frm-embed-field-placeholder")[0].classList.remove("frm_hidden")}else t.find(".frm-not-set")[0].classList.remove("frm_hidden"),t.find(".frm-embed-field-placeholder")[0].classList.add("frm_hidden")}function oa(e){var t=e.target,r=t.value.trim();if(!r.includes("[")||!r.includes("]")){if(isNaN(r.replace(/,/,""))){var n=P("Please enter a valid number.","formidable");return frmAdminBuild.infoModal(n),void function(e){var t=document.querySelectorAll("#frm_info_modal .dismiss, #frm_info_modal #frm-info-click, .ui-widget-overlay.ui-front");function r(){e.classList.add("frm_invalid_field"),setTimeout(function(){return e.focus()},0),t.forEach(function(e){e.removeEventListener("click",r)})}t.forEach(function(e){e.addEventListener("click",r)})}(t)}t.classList.remove("frm_invalid_field")}}function ia(){var e=jQuery(this).closest(".frm-single-settings"),t=e.find(".frmjs_product_choices"),r=e.find(".frm_prod_options_heading"),n=this.options[this.selectedIndex].value,o=e[0].querySelector(".frm_display_format_options");o&&o.setAttribute("data-product-type",n),t.removeClass("frm_prod_type_single frm_prod_type_user_def"),r.removeClass("frm_prod_user_def"),"single"===n?t.addClass("frm_prod_type_single"):"user_def"===n&&(t.addClass("frm_prod_type_user_def"),r.addClass("frm_prod_user_def")),wp.hooks.doAction("frm_product_type_toggled",n,e[0])}function aa(e){var t=document.getElementById("frm_field_id_".concat(e));return!!t&&"product"===t.getAttribute("data-type")}function la(){var e=function(e,t){return window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]},t=function(e,t,r){window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]=r},r=[1,2,3,4,5,6,7,8,9,10,11,12].map(function(e){return"frm".concat(e)}),o=["first","middle","last"];document.addEventListener("change",function(i){i.target.matches(".frm_name_layout_dropdown")&&function(i){var a,l=i.target.value.split("_"),s=i.target.dataset.fieldId,c=document.querySelector("#field_".concat(s,"_inner_container .frm_combo_inputs_container")),d=(a=l.length,"frm".concat(parseInt(12/a)));o.forEach(function(e){var o,i=c.querySelector('[data-sub-field-name="'.concat(e,'"]'));i&&(i.classList.add("frm_hidden"),(o=i.classList).remove.apply(o,n(r)),t(s,e,i))}),l.forEach(function(t){var r=e(s,t);r&&(r.classList.remove("frm_hidden"),r.classList.add(d),c.append(r))}),o.forEach(function(e){var r=document.querySelector(".frm_sub_field_options-".concat(e,'[data-field-id="').concat(s,'"]'));r&&(r.classList.add("frm_hidden"),t(s,"".concat(e,"_options"),r))}),l.forEach(function(t){var r=e(s,"".concat(t,"_options"));r&&r.classList.remove("frm_hidden")})}(i)},!1)}function sa(e,t){var r,n,o,i=!1,a=!1;(r=t.newOption?(new DOMParser).parseFromString(t.newOption,"text/html").body.childNodes[0]:t).querySelectorAll("svg").forEach(function(e){(n=e.getElementsByTagNameNS("http://www.w3.org/2000/svg","use")[0])&&("#frm_drag_icon"===(o=ti(n))&&(i=!0),"#frm_save_icon"===o&&(a=!0))}),i||r.prepend(L.drag.cloneNode(!0)),r.querySelector("[id^=field_key_".concat(e,"-]"))&&!a&&r.querySelector("[id^=field_key_".concat(e,"-]")).after(L.save.cloneNode(!0)),t.newOption&&(t.newOption=r)}function ca(){var e=document.getElementById("frm_leave_email").value.trim();if(""!==e)if(!1!==/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i.test(e)){var t=jQuery("#frmapi-email-form").find("form"),r=t.find('[type="email"]').not(".frm_verify");if(r.length){if(document.getElementById("frm_empty_inbox")){document.getElementById("frm-add-my-email-address").remove();var n=document.getElementById("frm_leave_email_wrapper");if(n){n.classList.add("frm_hidden");var o=b({className:"frm-wait frm_spinner"});o.style.visibility="visible",o.style.float="none",o.style.width="unset",n.parentElement.insertBefore(o,n.nextElementSibling)}}r.val(e),jQuery.ajax({type:"POST",url:t.attr("action"),data:"".concat(t.serialize(),"&action=frm_forms_preview")}).done(function(e){if(jQuery(e).find(".frm_message").text().trim().includes("Thanks!")){var t=document.getElementById("frmapi-email-form").parentElement.querySelector(".frm_spinner");t&&t.remove(),wp.hooks.applyFilters("frm_thank_you_on_signup",!0)&&document.getElementById("frm_leave_email_wrapper").replaceWith(b(P("Thank you for signing up!","formidable")))}else Di("invalid")})}}else Di("invalid");else Di("empty")}function da(e){var t;if(W||e.stopPropagation(),!(e.target.classList.contains("frm-show-box")||null!==(t=e.target.parentElement)&&void 0!==t&&t.classList.contains("frm-show-box"))){var r=document.getElementById("frm_adv_info");r&&(r.dataset.fills===e.target.id&&void 0!==e.target.id||e.target.closest("#frm_adv_info")||"none"===r.style.display||vi(r))}}return{init:function(){var e,t,o,i,a,l,s;!function(){jQuery(document).on("click","#frm-add-my-email-address",function(e){e.preventDefault(),ca()});var e=document.getElementById("frm_empty_inbox"),t=document.getElementById("frm_leave_email");if(e&&t){var r=document.getElementById("frm-leave-email-modal");r.classList.remove("frm_hidden"),r.querySelector(".frm_modal_footer").classList.add("frm_hidden"),t.addEventListener("keyup",function(e){if("Enter"===e.key){var t=document.getElementById("frm-add-my-email-address");t&&t.click()}})}}(),t=document.querySelector(".frm-admin-footer-links"),o=null!==(e=document.querySelector(".frm_page_container"))&&void 0!==e?e:document.getElementById("wpbody-content"),t&&o&&(o.append(t),t.classList.remove("frm_hidden")),document.addEventListener("show.bs.dropdown",function(){Y()}),H={},jQuery(".wp-admin").on("click",function(e){var t=jQuery(e.target),r=jQuery(".dropdown.open");!r.length||t.hasClass("dropdown")||t.closest(".dropdown").length||r.removeClass("open")}),jQuery("#frm_bs_dropdown:not(.open) a").on("click",Vt),void 0===T&&(T=jQuery(document.getElementById("form_id")).val()),document.querySelectorAll(".frm-warning-dismiss").forEach(function(e){E(e,Kt)}),frmAdminBuild.inboxBannerInit(),I.length>0?frmAdminBuild.buildInit():null!==document.getElementById("frm_notification_settings")?frmAdminBuild.settingsInit():null!==document.getElementById("frm_styling_form")?frmAdminBuild.styleInit():null!==document.getElementById("form_global_settings")?frmAdminBuild.globalSettingsInit():null!==document.getElementById("frm_export_xml")?frmAdminBuild.exportInit():null!==document.querySelector(".frm-inbox-wrapper")?frmAdminBuild.inboxInit():null!==document.getElementById("frm-welcome")?frmAdminBuild.solutionInit():(function(){if(document.body.classList.contains("frm-admin-page-entries")){var e=document.getElementById("screen-options-wrap");if(e){var t=h({className:"frm_warning_style",text:P("Only 10 columns can be selected at a time.","formidable")});t.style.margin=0;var r=e.querySelector("legend");r.parentNode.insertBefore(t,r.nextElementSibling);var n=Array.from(e.querySelectorAll('input[type="checkbox"]')),o=function(){n.reduce(function(e,t){return t.checked?e+1:e},0)>=10?(t.classList.remove("frm_hidden"),n.forEach(function(e){e.checked||(e.parentNode.classList.add("frm_noallow"),e.disabled=!0)})):t.classList.add("frm_hidden")};o(),n.forEach(function(e){e.addEventListener("change",function(e){e.target.checked?o():(t.classList.add("frm_hidden"),n.forEach(function(e){e.parentNode.classList.remove("frm_noallow"),e.disabled=!1}))})})}}}(),Pi(),jQuery("[data-frmprint]").on("click",function(){return window.print(),!1})),jQuery(document).on("change","select[data-toggleclass], input[data-toggleclass]",$o),function(){function e(e){var t=e.options[e.selectedIndex];e.querySelectorAll("option[data-dependency]:not([data-dependency-skip])").forEach(function(e){var r=document.querySelector(e.dataset.dependency);null==r||r.classList.toggle("frm_hidden",t!==e)})}document.querySelectorAll("select.frm_select_with_dependency").forEach(e),frmDom.util.documentOn("change","select.frm_select_with_dependency",function(t){return e(t.target)})}(),(jQuery(document.getElementById("frm_adv_info")).length>0||jQuery(".frm_field_list").length>0)&&frmAdminBuild.panelInit(),i=jQuery(".wrap, .frm_wrap"),a=document.getElementById("frm_confirm_modal"),l=!1,s=!1,jQuery(a).on("click","[data-deletefield]",Gr),jQuery(a).on("click","[data-removeid]",Z),jQuery(a).on("click","[data-trashtemplate]",Ui),i.on("click",".frm_remove_tag, .frm_remove_form_action",Z),i.on("click","a[data-frmverify]",$),i.on("click","a[data-frmtoggle]",J),i.on("click","a[data-frmhide], a[data-frmshow]",X),i.on("change","input[data-frmhide], input[data-frmshow]",X),i.on("click",".widget-top,a.widget-action",te),function(e){e.on("keydown",".widget-top",function(e){e.currentTarget===e.target&&("Enter"!==e.key&&" "!==e.key||(e.preventDefault(),te(e,e.currentTarget)))});var t=function(e){return function(t){t.key===e&&(t.preventDefault(),t.currentTarget.click())}};e.on("keydown",".frm_form_action_settings .frm_duplicate_form_action, .frm_form_action_settings .frm_remove_form_action",t(" ")),e.on("keydown",".frm_form_action_settings .frm_toggle",t("Enter"))}(i),i.on("mouseenter.frm",".frm_bstooltip, .frm_help",function(){jQuery(this).off("mouseenter.frm"),function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=e;(r.hasAttribute("data-toggle")||r.hasAttribute("data-bs-toggle"))&&(r.parentElement.setAttribute("title",r.getAttribute("title")),r.removeAttribute("title"),r.classList.remove("frm_bstooltip"),r.parentElement.classList.add("frm_bstooltip"),r=r.parentElement);var n=new bootstrap.Tooltip(r);t&&(Y(),n.show())}(this,!0)}),jQuery(document).on("click","#doaction, #doaction2",function(e){var t="doaction"===this.id?"top":"bottom",r=document.getElementById("bulk-action-selector-".concat(t)),n=document.getElementById("confirm-bulk-delete-".concat(t));if(r&&n){if(l=this,!s&&"bulk_delete"===r.value)return e.preventDefault(),V(n),!1}else l=!1}),jQuery(document).on("click","#frm-confirmed-click",function(e){if(!1!==l&&!e.target.classList.contains("frm-btn-inactive"))return"confirm-bulk-delete"===this.getAttribute("href")?(e.preventDefault(),s=!0,l.click(),!1):void 0}),r(4260).initUpgradeModal(),frmDom.util.documentOn("click","[data-modal-title]",vo);var c=jQuery(document.getElementById("frm_shortcodediv"));c.length>0&&(jQuery("a.edit-frm_shortcode").on("click",function(){return c.is(":hidden")&&(c.slideDown("fast"),this.style.display="none"),!1}),jQuery(".cancel-frm_shortcode","#frm_shortcodediv").on("click",function(){return c.slideUp("fast"),c.siblings("a.edit-frm_shortcode").show(),!1})),jQuery(document).on("click","#frm-nav-tabs a",oe),jQuery(".post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a").on("click",function(){var e=this.classList.contains("frm_show_upgrade_tab");if(!this.classList.contains("frm_noallow")||e)return e&&this.classList.contains("frm_show_expired_modal")?(wp.hooks.doAction("frm_show_expired_modal",this),!1):(e&&yo(this),ie(this),!1)}),ie(jQuery(".frm-category-tabs .starttab a"),"auto"),jQuery(document).on("click","#frm-fid-search-menu a",function(){var e=this.id.replace("fid-","");return jQuery('select[name="fid"]').val(e),co(document.getElementById("posts-filter")),!1}),jQuery(".frm_select_box").on("click focus",function(){this.select()}),jQuery(document).on("input search change",".frm-auto-search:not(#frm-form-templates-page #template-search-input)",Wi),jQuery(document).on("focusin click",".frm-auto-search",Vi);var d=jQuery(".frm-auto-search");""!==d.val()&&d.trigger("keyup"),FrmFormsConnect.init(),jQuery(document).on("click",".frm-install-addon",Ti),jQuery(document).on("click",".frm-activate-addon",Ni),jQuery(document).on("click",".frm-solution-multiple",Ci),jQuery("button, input[type=submit]").on("click",ra),document.addEventListener("click",function(e){if("LABEL"===e.target.nodeName){var t=e.target.getAttribute("for");if(t){var r=document.getElementById(t);if(r&&r.nextElementSibling){var n=r.nextElementSibling.querySelector("button.dropdown-toggle.multiselect");n&&setTimeout(function(){return n.click()},0)}}}}),frmAdminBuild.hooks.addFilter("frm_before_embed_modal",function(e,t){var r,n,o=t.element;if("form"!==t.type)return e;var i=o.closest("tr");if(i)r=parseInt(i.querySelector(".column-id").textContent),n=i.querySelector(".column-form_key").textContent;else{r=document.getElementById("form_id").value;var a=document.getElementById("frm_form_key");if(a)n=a.value;else{var l=document.getElementById("frm-previewDrop");l&&(n=l.nextElementSibling.querySelector(".dropdown-item a").getAttribute("href").split("form=")[1])}}return[r,n]}),I.on("click","> li, .frm_grid_container li",function(){var e,t=(null===(e=this.querySelector("li"))||void 0===e?void 0:e.dataset.fid)||this.dataset.fid;!function(e){var t=document.querySelectorAll("[id^=frm_delete_field_".concat(e,"-]"));t.length<2||n(t).slice(1).forEach(function(t,r){t.classList.contains("frm_other_option")||sa(e,t)})}(t),function(e){var t=document.getElementById("frm_field_".concat(e,"_opts"));if(t){var r=t.querySelector(".frm_option_template"),n=null==r?void 0:r.querySelector(".frm_remove_tag"),o=null==r?void 0:r.querySelector(".frm_add_opt");if(n&&o){var i=t.querySelectorAll(".frm_single_option:not(.frm_option_template)"),a=i.length>1;i.forEach(function(e){if(!e.querySelector(".frm_remove_tag")){var t=e.dataset.optkey;if(void 0!==t){var r=n.cloneNode(!0);["removeid","removemore"].forEach(function(e){var n=r.dataset[e];n&&(r.dataset[e]=n.replace("-000","-".concat(t)))}),r.classList.toggle("frm_disabled",!a);var i=e.querySelector(".frm_option_key");i?i.before(r,o.cloneNode(!0)):e.append(r,o.cloneNode(!0))}}})}}}(t)});var u=document.getElementById("frm_small_screen_proceed_button");u&&E(u,function(){var e;null===(e=document.getElementById("frm_small_device_message_container"))||void 0===e||e.remove(),k("small_screen_proceed",new FormData)});var f=document.getElementById("frm_sale_banner"),m=null==f?void 0:f.querySelector(".dismiss");f&&(E(f,function(e){e.target.closest(".dismiss")||(window.location.href=f.getAttribute("data-url"))}),m&&E(m,function(){f.remove();var e=new FormData;k("sale_banner_dismiss",e)}))},buildInit:function(){var e,t;jQuery("#frm_builder_page").on("mouseup","*:not(.frm-show-box)",da),Q=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return frmDom.util.debounce(e,t)}(he,10),S=document.getElementById("post-body-content"),A=jQuery(S),ze(),ae("ul.frm_sorting"),e=jQuery("#frm_builder_page"),t={items:".frm_sortable_field_opts li",axis:"y",opacity:.65,forcePlaceholderSize:!1,handle:".frm-drag",helper:function(e,t){return C=t.clone().insertAfter(t),t.clone()},stop:function(e,t){C&&C.remove(),Qn(t.item.attr("id").replace("frm_delete_field_","").replace("-".concat(t.item.data("optkey"),"_container"),"")),ci()}},jQuery(e).sortable(t),document.querySelectorAll(".field_type_list > li:not(.frm_show_upgrade):not(.frm_show_update)").forEach(de),jQuery("ul.field_type_list, .field_type_list li, ul.frm_code_list, .frm_code_list li, .frm_code_list li a, #frm_adv_info #category-tabs li, #frm_adv_info #category-tabs li a").disableSelection(),jQuery(".frm_submit_ajax").on("click",so),jQuery(".frm_submit_no_ajax").on("click",fo),_o(),jQuery("a.edit-form-status").on("click",Kn),jQuery(".cancel-form-status").on("click",Jn),jQuery(".save-form-status").on("click",function(){var e=jQuery(document.getElementById("form_change_status")).val();return jQuery('input[name="new_status"]').val(e),jQuery(document.getElementById("form-status-display")).html(e),jQuery(".cancel-form-status").trigger("click"),!1}),jQuery(".frm_form_builder form").first().on("submit",function(){jQuery(".inplace_field").trigger("blur")}),Bi(),on();var r,n=jQuery(q),o=document.getElementById("frm_form_editor_container");n.on("click",".frm_add_logic_row",Vr),n.on("click",".frm_add_watch_lookup_row",Jr),n.on("change",".frm_get_values_form",rn),n.on("change",".frm_logic_field_opts",Hn),n.on("frm-multiselect-changed",'select[name^="field_options[admin_only_"]',Xn),jQuery(document.getElementById("frm-insert-fields")).on("click",".frm_add_field",We),I.on("click",".frm_clone_field",Je),n.on("blur",'input[id^="frm_calc"]',pt),n.on("change","input.frm_format_opt, input.frm_max_length_opt",At),n.on("change click","[data-changeme]",Qt),n.on("click","input.frm_req_field",Lt),n.on("click",".frm_mark_unique",qt),n.on("change",".frm_repeat_format",yn),n.on("change",".frm_repeat_limit",hn),n.on("change",".frm_js_checkbox_limit",bn),n.on("input",'input[name^="field_options[add_label_"]',function(){wn(this,"add")}),n.on("input",'input[name^="field_options[remove_label_"]',function(){wn(this,"remove")}),n.on("change",'select[name^="field_options[data_type_"]',nn),jQuery(o).on("click",".frm-collapse-page",an),jQuery(o).on("click",".frm-collapse-section",cn),n.on("click",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",dn),n.on("keydown",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),dn.call(this,e))}),jQuery(o).on("show.bs.dropdown hide.bs.dropdown",at),n.on("change",".frm_toggle_sep_values",Dt),n.on("change",".frm_toggle_image_options",Mt),n.on("click",".frm_remove_image_option",Wt),n.on("click",".frm_choose_image_box",Ut),n.on("change",".frm_hide_image_text",Gt),n.on("change",".frm_field_options_image_size",zt),n.on("click",".frm_multiselect_opt",$t),I.on("mousedown","input, textarea, select",Jt),I.on("click","input[type=radio], input[type=checkbox]",Jt),I.on("click",".frm_delete_field",tr),I.on("click",".frm_select_field",rr),jQuery(document).on("click",".frm_delete_field_group",nr),jQuery(document).on("click",".frm_clone_field_group",or),jQuery(document).on("click","#frm_field_group_controls > span:first-child",ir),jQuery(document).on("click",".frm-row-layout-option",hr),jQuery(document).on("click",".frm-merge-fields-into-row .frm-row-layout-option",br),jQuery(document).on("click",".frm-custom-field-group-layout",jr),jQuery(document).on("click",".frm-merge-fields-into-row .frm-custom-field-group-layout",Er),jQuery(document).on("click",".frm-break-field-group",Lr),I.on("click","#frm_field_group_popup .frm_grid_container input",Ir),jQuery(document).on("click",".frm-cancel-custom-field-group-layout",qr),jQuery(document).on("click",".frm-save-custom-field-group-layout",Cr),I.on("click","ul.frm_sorting",Nr),jQuery(document).on("click",".frm-merge-fields-into-row",Rr),jQuery(document).on("click",".frm-delete-field-groups",Hr),I.on("click",'.frm-field-action-icons [data-toggle="dropdown"]',function(){this.closest("li.form-field").classList.add("frm-field-settings-open"),jQuery(document).on("click","#frm_builder_page",et)}),I.on("mousemove","ul.frm_sorting",tt),I.on("show.bs.dropdown",".frm-field-action-icons",ot),jQuery(document).on("show.bs.dropdown","#frm_field_group_controls",it),n.on("click",".frm_single_option a[data-removeid]",Xt),n.on("mousedown",".frm_single_option input[type=radio]",Yt),n.on("focusin",".frm_single_option input[type=text]",Zt),n.on("click",".frm_add_opt",Tt),n.on("change",".frm_single_option input",xn),n.on("change",".frm_image_id",xn),n.on("change",".frm_toggle_mult_sel",Ot),I.on("click",".frm_primary_label",fn),I.on("click",".frm_description",mn),I.on("click","li.ui-state-default:not(.frm_noallow)",pn),I.on("dblclick","li.ui-state-default",vn),n.on("change",".frm_tax_form_select",jn),n.on("change","select.conf_field",Bt),n.on("change",".frm_get_field_selection",Gn),n.on("click",".frm-show-inline-modal",eo),n.on("keydown",".frm-show-inline-modal",function(e){var t=e.key;"Enter"!==t&&" "!==t||(e.preventDefault(),eo.call(this,e))}),n.on("click",".frm-inline-modal .dismiss",to),jQuery(document).on("change","[data-frmchange]",no),document.addEventListener("click",ro),n.on("change",".frm_include_extras_field",wt),n.on("change",'select[name^="field_options[form_select_"]',na),jQuery(document).on("submit","#frm_js_build_form",di),jQuery(document).on("change","#frm_builder_page input:not(.frm-search-input):not(.frm-custom-grid-size-input), #frm_builder_page select, #frm_builder_page textarea",ci),Et(),frmDom.util.documentOn("change",".frm_product_price",oa),jQuery(document).on("change",".frmjs_prod_data_type_opt",ia),jQuery(document).on("focus",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',Yr),jQuery(document).on("blur",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',en),frmDom.util.documentOn("click",".frm-show-field-settings",pn),frmDom.util.documentOn("change","select.frm_format_dropdown, select.frm_phone_type_dropdown",gn),n.on("keydown",'.frm_single_option input[name^="field_options["], .frm_single_option input[name^="rows_"]',function(e){"Enter"===e.key&&function(e){var t=e.closest(".frm_single_option").parentElement.querySelectorAll('.frm_single_option input[name^="field_options[" ], .frm_single_option input[name^="rows_"]'),r=Array.from(t),n=r.indexOf(e);if(!(n<0)){var o=r.slice(n+1).find(function(e){return null!==e.offsetParent});if(o){o.focus();var i=o.value.length;o.setSelectionRange(i,i)}}}(e.currentTarget)}),!1!==(r=ea("#frm-bulk-modal","700px"))&&(jQuery(".frm-insert-preset").on("click",Nt),jQuery(q).on("click","a.frm-bulk-edit-link",function(e){e.preventDefault();var t="",n=jQuery(this).closest("[data-fid]").data("fid"),o=Dn(n),i=aa(n),a=document.getElementById("frm_field_".concat(n,"_opts"));if(a){var l=a.getElementsByTagName("li");document.getElementById("bulk-field-id").value=n;for(var s=0;s<l.length;s++){var c=l[s].getAttribute("data-optkey");if("000"!==c){var d=document.getElementsByName("field_options[options_".concat(n,"][").concat(c,"][label]"))[0];void 0!==d&&(t+=d.value,o&&(t+="|".concat(document.getElementsByName("field_options[options_".concat(n,"][").concat(c,"][value]"))[0].value)),i&&(t+="|".concat(document.getElementsByName("field_options[options_".concat(n,"][").concat(c,"][price]"))[0].value)),t+="\r\n")}s>=l.length-1&&(document.getElementById("frm_bulk_options").value=t)}return r.dialog("open"),!1}}),jQuery("#frm-update-bulk-opts").on("click",function(){var e=document.getElementById("bulk-field-id").value;document.getElementById("bulk-option-type").value||(this.classList.add("frm_loading_button"),frmAdminBuild.updateOpts(e,document.getElementById("frm_bulk_options").value,r),ci())})),Zn(),document.addEventListener("frm_added_field",Zn),Ke(),la(),$n(),frmDom.util.documentOn("change",".frm_show_password_setting_input",function(e){var t=e.target.getAttribute("data-fid"),r=document.getElementById("frm_field_id_".concat(t));r&&r.classList.toggle("frm_disabled_show_password",!e.target.checked)}),document.addEventListener("scroll",ai,!0),document.addEventListener("change",oi),document.querySelector(".frm_form_builder").addEventListener("mousedown",function(e){e.shiftKey&&e.preventDefault()}),wp.hooks.addAction("frmShowedFieldSettings","formidableAdmin",function(e,t){t.querySelectorAll(".frm-collapse-me").forEach(un)},9999),frm_admin_js.pricingFieldsModal&&"object"===i(frm_admin_js.pricingFieldsModal)&&K(frm_admin_js.pricingFieldsModal,"550px")},settingsInit:function(){var e=jQuery(document.getElementById("frm_notification_settings"));e.on("click",".frm_email_buttons",So),e.on("click",".frm_remove_field",Ao),e.on("change",".frm_to_row, .frm_from_row",Lo),e.on("change",".frm_tax_selector",Uo),e.on("change","select.frm_single_post_field",Fo),e.on("change","select.frm_toggle_post_content",Do),e.on("change","select.frm_dyncontent_opt",Mo),e.on("change",".frm_post_type",Po),e.on("click",".frm_add_postmeta_row",Ho),e.on("click",".frm_add_posttax_row",zo),e.on("click",".frm_toggle_cf_opts",Wo),e.on("click",".frm_duplicate_form_action",wo),jQuery(".frm_actions_list").on("click",".frm_active_action",Eo),jQuery(document).on("frmAfterSearch","#actions-search-input",ee),Bi(),document.querySelectorAll(".frm_actions_list a[data-actiontype]").forEach(function(e){return Io(e.dataset.actiontype)}),jQuery(".frm_submit_settings_btn").on("click",Vo),_o();var t=jQuery(".frm_form_settings");t.on("click",".frm_add_form_logic",To),t.on("change","input[data-emailkey][data-toggleclass]",Oo),t.on("click",".frm_already_used",Co),document.addEventListener("click",function(e){var t=e.target;t.closest(".frm_image_preview_wrapper")&&(t.closest(".frm_choose_image_box")?Ut.bind(t)(e):t.closest(".frm_remove_image_option")&&Wt.bind(t)(e))}),t.on("mouseup","*:not(.frm-show-box)",da),jQuery(document.getElementById("no_save")).on("change",function(){this.checked&&!0!==confirm(f.no_save_warning)&&jQuery(this).attr("checked",!1)}),document.querySelectorAll('a[href="#spam_settings"]').forEach(function(e){e.addEventListener("click",function(e){e.preventDefault();var t=document.querySelector('.frm-category-tabs a[href="#spam_settings"]');t&&(ie(t),setTimeout(function(){var e=document.getElementById("frm-categorydiv");e&&e.scrollIntoView({block:"start"})},50))})});var r=document.getElementById("frm_include_captcha");if(r){var n=r.checked;r.addEventListener("change",function(){var e=document.getElementById("frm_captcha_add_warning"),t=document.getElementById("frm_captcha_remove_warning");e&&t&&(this.checked!==n?this.checked?(e.style.display="block",t.style.display="none"):(e.style.display="none",t.style.display="block"):(e.style.display="none",t.style.display="none"))})}jQuery('select[name="options[edit_action]"]').on("change",bo);var o=document.getElementById("logged_in");jQuery(o).on("change",function(){this.checked?Zi(".hide_logged_in"):Yi(".hide_logged_in")});var i=jQuery(document.getElementById("frm_cookie_expiration"));jQuery(document.getElementById("frm_single_entry_type")).on("change",function(){"cookie"===this.value?i.fadeIn("slow"):i.fadeOut("slow")});var a=document.getElementById("single_entry");jQuery(a).on("change",function(){this.checked?Zi(".hide_single_entry"):Yi(".hide_single_entry"),this.checked&&"cookie"===jQuery(document.getElementById("frm_single_entry_type")).val()?i.fadeIn("slow"):i.fadeOut("slow")}),jQuery(".hide_save_draft").hide();var l=jQuery(document.getElementById("save_draft"));l.on("change",function(){this.checked?jQuery(".hide_save_draft").fadeIn("slow"):jQuery(".hide_save_draft").fadeOut("slow")}),uo(l);var s=document.getElementById("editable");jQuery(s).on("change",function(){this.checked?(jQuery(".hide_editable").fadeIn("slow"),uo(document.getElementById("edit_action"))):(jQuery(".hide_editable").fadeOut("slow"),jQuery(".edit_action_message_box").fadeOut("slow"))}),jQuery(document).on("change","#protect_files",function(){this.checked?jQuery(".hide_protect_files").fadeIn("slow"):jQuery(".hide_protect_files").fadeOut("slow")}),jQuery(document).on("frm-multiselect-changed","#protect_files_role",Xn),jQuery(document).on("submit",".frm_form_settings",ui),jQuery(document).on("change","#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea",ci),Pi(),jQuery(document).on("frm-action-loaded",hi),frmDom.util.documentOn("change",'.frm_on_submit_type input[type="radio"]',function(e){if(e.target.checked){var t=e.target.closest(".frm_form_action_settings");t.querySelectorAll(".frm_on_submit_dependent_setting:not(.frm_hidden)").forEach(function(e){e.classList.add("frm_hidden")}),t.querySelectorAll(".frm_on_submit_dependent_setting[data-show-if-".concat(e.target.value,"]")).forEach(function(e){e.classList.remove("frm_hidden")}),t.setAttribute("data-on-submit-type",e.target.value)}}),wp.hooks.addAction("frm_reset_fields_updated","formidableAdmin",fi)},panelInit:function(){jQuery(".frm_wrap, #postbox-container-1").on("click",".frm_insert_code",Ko),jQuery(document).on("change",".frm_insert_val",function(){Jo(jQuery(this).data("target"),jQuery(this).val()),jQuery(this).val("")}),jQuery(document).on("click change",'[name="frm-id-key-condition"]',Zo),jQuery(document).on("keyup change",".frm-build-logic",ei),ho(),jQuery(document).on("frmElementAdded",function(e,t){ho(t)}),jQuery(document).on("mousedown",".frm-show-box",ni);var e=document.getElementById("form_settings_page"),t=document.body.classList.contains("post-type-frm_display"),r=document.getElementById("frm_insert_fields_tab");(e||t||W)&&jQuery(document).on("focusin","form input, form textarea",function(n){var o,i,a;if(n.stopPropagation(),ri(this),jQuery(this).is(":not(:submit, input[type=button], .frm-search-input, input[type=checkbox])")){if(jQuery(n.target).closest("#frm_adv_info").length)return;if(e||W)o=jQuery("#frm_html_tab"),jQuery(this).closest("#html_settings").length>0?(o.show(),o.siblings().hide(),jQuery("#frm_html_tab a").trigger("click"),void 0===(a=this.id)||a.includes("-search-input")||(jQuery("#frm-adv-info-tab").attr("data-fills",a.trim()),this.classList.contains("field_custom_html")&&(a="field_custom_html"),jQuery.inArray(a,["after_html","before_html","submit_html","field_custom_html"])>=0&&(jQuery(".frm_code_list li:not(.show_".concat(a,")")).addClass("frm_hidden"),jQuery(".frm_code_list li.show_".concat(a)).removeClass("frm_hidden")))):((i=jQuery(".frm-category-tabs li"))[0]&&(i[0].style.display=""),r.click(),o.hide(),o.siblings().show());else if(t){var l=new CustomEvent("frm_legacy_views_handle_field_focus");l.frmData={idAttrValue:this.id},document.dispatchEvent(l)}}}),jQuery(".frm_wrap, #postbox-container-1").on("mousedown","#frm_adv_info a, .frm_field_list a",function(e){e.preventDefault()});var n=jQuery("#frm_adv_info");n.on("click",".subsubsub a.frmids",function(e){yi("frmids",e)}),n.on("click",".subsubsub a.frmkeys",function(e){yi("frmkeys",e)})},inboxInit:function(){var e;jQuery(".frm_inbox_dismiss").on("click",function(e){var t=this.parentNode.parentNode,r=t.getAttribute("data-message"),n=this.getAttribute("href"),o=t.cloneNode(!0),i=document.querySelector(".frm-dismissed-inbox-messages");if("free_templates"!==r||this.classList.contains("frm_inbox_dismiss")){e.preventDefault();var a={action:"frm_inbox_dismiss",key:r,nonce:frmGlobal.nonce},l="frm_inbox_slide_in"===t.id;l&&(t.classList.remove("s11-fadein"),t.classList.add("s11-fadeout"),t.addEventListener("animationend",function(){return t.remove()},{once:!0})),Ji(a,function(){if(!l)return"#"!==n?(window.location=n,!0):void Xi(t,function(){var e;i&&(o.classList.remove("frm-fade"),null===(e=o.querySelector(".frm-inbox-message-heading .frm_inbox_dismiss"))||void 0===e||e.remove(),i.append(o)),1===t.parentNode.querySelectorAll(".frm-inbox-message-container").length&&(document.getElementById("frm_empty_inbox").classList.remove("frm_hidden"),t.parentNode.closest(".frm-active").classList.add("frm-empty-inbox"),Fi()),t.remove()})})}}),!1===(null===(e=document.getElementById("frm_empty_inbox"))||void 0===e?void 0:e.classList.contains("frm_hidden"))&&Fi()},solutionInit:function(){jQuery(document).on("submit","#frm-new-template",zi)},styleInit:function(){var e=jQuery(".frm_image_preview_wrapper");e.on("click",".frm_choose_image_box",Ut),e.on("click",".frm_remove_image_option",Wt),wp.hooks.doAction("frm_style_editor_init")},customCSSInit:function(){console.warn("Calling frmAdminBuild.customCSSInit is deprecated.")},globalSettingsInit:function(){jQuery(document).on("click","[data-frmuninstall]",bi),Bi();var e=document.getElementById("licenses_settings");e&&jQuery(e).on("click",".edd_frm_save_license",wi),jQuery(document).on("click","#frm-new-template button",Ri),jQuery("#frm-dismissable-cta .dismiss").on("click",function(e){e.preventDefault(),jQuery.post(ajaxurl,{action:"frm_lite_settings_upgrade",nonce:frmGlobal.nonce}),jQuery(".settings-lite-cta").remove()});var t=document.getElementById("frm_re_type");t&&t.addEventListener("change",Gi),document.querySelector(".frm_captchas").addEventListener("change",function(e){var t,r=null===(t=document.querySelector('.frm_captchas input[checked="checked"]'))||void 0===t?void 0:t.value,n=e.target.value!==r;document.querySelector(".captcha_settings .frm_note_style").classList.toggle("frm_hidden",!n)}),frmDom.util.documentOn("submit",".frm_settings_form",function(){N=0});var r=document.getElementById("manage_styles_settings");r&&r.addEventListener("change",function(e){var t=e.target;"SELECT"===t.nodeName&&t.dataset.name&&!t.getAttribute("name")&&t.setAttribute("name",t.dataset.name)});var n=document.getElementById("payments_settings"),o=null==n?void 0:n.querySelectorAll('[name="frm_payment_section"]');o&&o.forEach(function(e){e.addEventListener("change",function(){if(e.checked){var t=n.querySelector('label[for="'.concat(e.id,'"]'));t&&t.setAttribute("aria-selected","true"),o.forEach(function(t){if(t!==e){var r=n.querySelector('label[for="'.concat(t.id,'"]'));r&&r.setAttribute("aria-selected","false")}})}})})},exportInit:function(){jQuery(".frm_form_importer").on("submit",ji),jQuery(document.getElementById("frm_export_xml")).on("submit",Ei),jQuery("#frm_export_xml input, #frm_export_xml select").on("change",ki),jQuery('input[name="frm_import_file"]').on("change",Qi),document.querySelector('select[name="format"]').addEventListener("change",Ai),jQuery('input[name="frm_export_forms[]"]').on("click",qi),Bi(),jQuery(".frm-feature-banner .dismiss").on("click",function(e){e.preventDefault(),jQuery.post(ajaxurl,{action:"frm_dismiss_migrator",plugin:this.id,nonce:frmGlobal.nonce}),this.parentElement.remove()}),Ii(Si()),document.querySelector("#frm-export-select-all").addEventListener("change",function(e){document.querySelectorAll('[name="frm_export_forms[]"]').forEach(function(t){t.checked=e.target.checked})})},inboxBannerInit:function(){var e=document.getElementById("frm_banner");if(e){var t=e.querySelector(".frm-banner-dismiss");document.addEventListener("click",function(r){r.target===t&&Ji({action:"frm_inbox_dismiss",key:e.dataset.key,nonce:frmGlobal.nonce},function(){jQuery(e).fadeOut(400,function(){e.remove()})})})}},updateOpts:function(e,t,r){var n=Dn(e),o=aa(e)?"frm_bulk_products":"frm_import_options";jQuery.ajax({type:"POST",url:ajaxurl,data:{action:o,field_id:e,opts:t,separate:n,nonce:frmGlobal.nonce},success:function(t){document.getElementById("frm_field_".concat(e,"_opts")).innerHTML=t,wp.hooks.doAction("frm_after_bulk_edit_opts",e),Qn(e),void 0!==r&&(r.dialog("close"),document.getElementById("frm-update-bulk-opts").classList.remove("frm_loading_button"))}})},triggerRemoveLogic:function(e,t){jQuery("#frm_logic_".concat(e,"_").concat(t," .frm_remove_tag")).trigger("click")},downloadXML:function(e,t,r){var n="".concat(ajaxurl,"?action=frm_").concat(e,"_xml&ids=").concat(t);null!==r&&(n="".concat(n,"&is_template=").concat(r)),location.href=n},hooks:{applyFilters:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return(t=wp.hooks).applyFilters.apply(t,[e].concat(n))},addFilter:function(e,t,r){return wp.hooks.addFilter(e,"formidable",t,r)},doAction:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return(t=wp.hooks).doAction.apply(t,[e].concat(n))},addAction:function(e,t,r){return wp.hooks.addAction(e,"formidable",t,r)}},settings:{validate:{validateField:u,getRangeSettingsDefaults:m,validateNumberRangeSetting:_,validateStepSetting:p,validateRangeSettings:g}},applyZebraStriping:function(e,t){var r=document.querySelectorAll("".concat(e," tr").concat(t?":not(.".concat(t,")"):""));if(!(r.length<1)){var n=!0;r.forEach(function(e){e.classList.remove("frm-odd","frm-even"),e.classList.add(n?"frm-odd":"frm-even"),n=!n}),document.querySelectorAll(e).forEach(function(e){return e.classList.add("frm-zebra-striping")})}},initModal:ea,infoModal:K,offsetModalY:_i,adjustConditionalLogicOptionOrders:An,addRadioCheckboxOpt:In,installNewForm:Hi,toggleAddonState:Oi,purifyHtml:Tn,loadApiEmailForm:Mi,addMyEmailAddress:ca,fillDropdownOpts:qn,showSaveAndReloadModal:ii,clearSettingsBox:mt,deleteField:Wr,insertFormField:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(r){var n=T,o=0;"summary"===e&&(o=I.children('li[data-type="break"]').length>0?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:Object.assign(Le(e,0,n,o),{field_options:t}),success:function(t){r(t),setTimeout(function(){Wn(),ut(t,!0);var r=Be(t);r&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:r,fieldType:e,form_id:n})},10)},error:Ne})})},confirmLinkClick:V,handleInsertFieldByDraggingResponse:qe,handleAddFieldClickResponse:Ve,syncLayoutClasses:we,moveFieldSettings:Qo,maybeCollapseSettings:dn}},window.frmAdminBuild=frmAdminBuildJS(),jQuery(document).ready(function(){var e;frmAdminBuild.init(),document.querySelectorAll(".frm-dropdown-menu").forEach(function(e){e.classList.add("dropdown-menu");var t,r,n=e.querySelector(".frm-dropdown-toggle");n&&(n.hasAttribute("role")||n.setAttribute("role","button"),n.hasAttribute("tabindex")||n.setAttribute("tabindex",0)),"UL"===e.tagName&&(r=(r=(r=(r=(r=(r=(t=e).outerHTML).replace("<ul ","<div ")).replace("</ul>","</div>")).replaceAll("<li>",'<div class="dropdown-item">')).replaceAll('<li class="','<div class="dropdown-item ')).replaceAll("</li>","</div>"),t.outerHTML=r)}),null===(e=document.querySelector(".preview.dropdown .frm-dropdown-toggle"))||void 0===e||e.setAttribute("data-bs-toggle","dropdown"),document.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))})}),window.frm_show_div=function(e,t,r,n){t==r?jQuery(n+e).fadeIn("slow").css("visibility","visible"):jQuery(n+e).fadeOut("slow")},window.frmCheckAll=function(e,t){jQuery('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmCheckAllLevel=function(e,t,r){jQuery(".frm_catlevel_".concat(r)).children(".frm_checkbox").children("label").children('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmGetFieldValues=function(e,t,r,n,o,i){e&&jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_get_field_values&current_field=".concat(t,"&field_id=").concat(e,"&name=").concat(o,"&t=").concat(n,"&form_action=").concat(jQuery('input[name="frm_action"]').val(),"&nonce=").concat(frmGlobal.nonce),success:function(e){document.getElementById("frm_show_selected_values_".concat(t,"_").concat(r)).innerHTML=e,"function"==typeof i&&i()}})},r(4365),window.frmImportCsv=function(e){var t="";"undefined"!=typeof __FRMURLVARS&&(t=__FRMURLVARS),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_import_csv&nonce=".concat(frmGlobal.nonce,"&frm_skip_cookie=1").concat(t),success:function(t){var r=jQuery(".frm_admin_progress_bar").attr("aria-valuemax"),n=r-t,o=n/r*100;jQuery(".frm_admin_progress_bar").css("width","".concat(o,"%")).attr("aria-valuenow",n),parseInt(t,10)>0?(jQuery(".frm_csv_remaining").html(t),frmImportCsv(e)):(jQuery(document.getElementById("frm_import_message")).html(frm_admin_js.import_complete),setTimeout(function(){location.href="?page=formidable-entries&frm_action=list&form=".concat(e,"&import-message=1")},2e3))}})}})();