| @@ -1,10761 +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 | - loadedFrom = link.getAttribute( 'data-loaded-from' ) ; | |
| 382 | - | |
| 383 | - if ( message === null || link.id === 'frm-confirmed-click' ) { | |
| 384 | - return true; | |
| 385 | - } | |
| 386 | - | |
| 387 | - if ( 'entries-list' === loadedFrom ) { | |
| 388 | - return wp.hooks.applyFilters( 'frm_on_multiple_entries_delete', { link, initModal }); | |
| 389 | - } | |
| 390 | - | |
| 391 | - return confirmModal( link ); | |
| 392 | - } | |
| 393 | - | |
| 394 | - function confirmModal( link ) { | |
| 395 | - var verify, $confirmMessage, i, dataAtts, btnClass, | |
| 396 | - $info = initModal( '#frm_confirm_modal', '400px' ), | |
| 397 | - continueButton = document.getElementById( 'frm-confirmed-click' ); | |
| 398 | - | |
| 399 | - if ( $info === false ) { | |
| 400 | - return false; | |
| 401 | - } | |
| 402 | - | |
| 403 | - verify = link.getAttribute( 'data-frmverify' ); | |
| 404 | - btnClass = verify ? link.getAttribute( 'data-frmverify-btn' ) : ''; | |
| 405 | - $confirmMessage = jQuery( '.frm-confirm-msg' ); | |
| 406 | - $confirmMessage.empty(); | |
| 407 | - | |
| 408 | - if ( verify ) { | |
| 409 | - $confirmMessage.append( document.createTextNode( verify ) ); | |
| 410 | - if ( btnClass ) { | |
| 411 | - continueButton.classList.add( btnClass ); | |
| 412 | - } | |
| 413 | - } | |
| 414 | - | |
| 415 | - removeAtts = continueButton.dataset; | |
| 416 | - for ( i in dataAtts ) { | |
| 417 | - continueButton.removeAttribute( 'data-' + i ); | |
| 418 | - } | |
| 419 | - | |
| 420 | - dataAtts = link.dataset; | |
| 421 | - for ( i in dataAtts ) { | |
| 422 | - if ( i !== 'frmverify' ) { | |
| 423 | - continueButton.setAttribute( 'data-' + i, dataAtts[i]); | |
| 424 | - } | |
| 425 | - } | |
| 426 | - | |
| 427 | - $info.dialog( 'open' ); | |
| 428 | - continueButton.setAttribute( 'href', link.getAttribute( 'href' ) ); | |
| 429 | - return false; | |
| 430 | - } | |
| 431 | - | |
| 432 | - function infoModal( msg ) { | |
| 433 | - var $info = initModal( '#frm_info_modal', '400px' ); | |
| 434 | - | |
| 435 | - if ( $info === false ) { | |
| 436 | - return false; | |
| 437 | - } | |
| 438 | - | |
| 439 | - jQuery( '.frm-info-msg' ).html( msg ); | |
| 440 | - | |
| 441 | - $info.dialog( 'open' ); | |
| 442 | - return false; | |
| 443 | - } | |
| 444 | - | |
| 445 | - function toggleItem( e ) { | |
| 446 | - /*jshint validthis:true */ | |
| 447 | - var toggle = this.getAttribute( 'data-frmtoggle' ), | |
| 448 | - text = this.getAttribute( 'data-toggletext' ), | |
| 449 | - items = jQuery( toggle ); | |
| 450 | - | |
| 451 | - e.preventDefault(); | |
| 452 | - | |
| 453 | - if ( items.is( ':visible' ) ) { | |
| 454 | - items.show(); | |
| 455 | - } else { | |
| 456 | - items.hide(); | |
| 457 | - } | |
| 458 | - | |
| 459 | - if ( text !== null && text !== '' ) { | |
| 460 | - this.setAttribute( 'data-toggletext', this.innerHTML ); | |
| 461 | - this.textContent = text; | |
| 462 | - } | |
| 463 | - | |
| 464 | - return false; | |
| 465 | - } | |
| 466 | - | |
| 467 | - /** | |
| 468 | - * Toggle a class on target elements when an anchor is clicked, or when a radio or checkbox has been selected. | |
| 469 | - * | |
| 470 | - * @param {Event} e Event with either the change or click type. | |
| 471 | - * @returns {false} | |
| 472 | - */ | |
| 473 | - function hideShowItem( e ) { | |
| 474 | - /*jshint validthis:true */ | |
| 475 | - let hide = this.getAttribute( 'data-frmhide' ); | |
| 476 | - let show = this.getAttribute( 'data-frmshow' ); | |
| 477 | - | |
| 478 | - // Flip unchecked checkboxes so an off value undoes the on value. | |
| 479 | - if ( isUncheckedCheckbox( this ) ) { | |
| 480 | - if ( hide !== null ) { | |
| 481 | - show = hide; | |
| 482 | - hide = null; | |
| 483 | - } else if ( show !== null ) { | |
| 484 | - hide = show; | |
| 485 | - show = null; | |
| 486 | - } | |
| 487 | - } | |
| 488 | - | |
| 489 | - e.preventDefault(); | |
| 490 | - | |
| 491 | - const toggleClass = this.getAttribute( 'data-toggleclass' ) || 'frm_hidden'; | |
| 492 | - | |
| 493 | - if ( hide !== null ) { | |
| 494 | - jQuery( hide ).addClass( toggleClass ); | |
| 495 | - } | |
| 496 | - | |
| 497 | - if ( show !== null ) { | |
| 498 | - jQuery( show ).removeClass( toggleClass ); | |
| 499 | - } | |
| 500 | - | |
| 501 | - var current = this.parentNode.querySelectorAll( 'a.current' ); | |
| 502 | - if ( current !== null ) { | |
| 503 | - for ( var i = 0; i < current.length; i++ ) { | |
| 504 | - current[ i ].classList.remove( 'current' ); | |
| 505 | - } | |
| 506 | - this.classList.add( 'current' ); | |
| 507 | - } | |
| 508 | - | |
| 509 | - return false; | |
| 510 | - } | |
| 511 | - | |
| 512 | - function isUncheckedCheckbox( element ) { | |
| 513 | - return 'INPUT' === element.nodeName && 'checkbox' === element.type && ! element.checked; | |
| 514 | - } | |
| 515 | - | |
| 516 | - function setupMenuOffset() { | |
| 517 | - window.onscroll = document.documentElement.onscroll = setMenuOffset; | |
| 518 | - setMenuOffset(); | |
| 519 | - } | |
| 520 | - | |
| 521 | - function setMenuOffset() { | |
| 522 | - var fields = document.getElementById( 'frm_adv_info' ); | |
| 523 | - if ( fields === null ) { | |
| 524 | - return; | |
| 525 | - } | |
| 526 | - | |
| 527 | - var currentOffset = document.documentElement.scrollTop || document.body.scrollTop; // body for Safari | |
| 528 | - if ( currentOffset === 0 ) { | |
| 529 | - fields.classList.remove( 'frm_fixed' ); | |
| 530 | - return; | |
| 531 | - } | |
| 532 | - | |
| 533 | - var posEle = document.getElementById( 'frm_position_ele' ); | |
| 534 | - if ( posEle === null ) { | |
| 535 | - return; | |
| 536 | - } | |
| 537 | - | |
| 538 | - var eleOffset = jQuery( posEle ).offset(); | |
| 539 | - var offset = eleOffset.top; | |
| 540 | - var desiredOffset = offset - currentOffset; | |
| 541 | - var menuHeight = 0; | |
| 542 | - | |
| 543 | - var menu = document.getElementById( 'wpadminbar' ); | |
| 544 | - if ( menu !== null ) { | |
| 545 | - menuHeight = menu.offsetHeight; | |
| 546 | - } | |
| 547 | - | |
| 548 | - if ( desiredOffset < menuHeight ) { | |
| 549 | - desiredOffset = menuHeight; | |
| 550 | - } | |
| 551 | - | |
| 552 | - if ( desiredOffset > menuHeight ) { | |
| 553 | - fields.classList.remove( 'frm_fixed' ); | |
| 554 | - } else { | |
| 555 | - fields.classList.add( 'frm_fixed' ); | |
| 556 | - if ( desiredOffset !== 32 ) { | |
| 557 | - fields.style.top = desiredOffset + 'px'; | |
| 558 | - } | |
| 559 | - } | |
| 560 | - } | |
| 561 | - | |
| 562 | - function loadTooltips() { | |
| 563 | - var wrapClass = jQuery( '.wrap, .frm_wrap' ), | |
| 564 | - confirmModal = document.getElementById( 'frm_confirm_modal' ), | |
| 565 | - doAction = false, | |
| 566 | - confirmedBulkDelete = false; | |
| 567 | - | |
| 568 | - jQuery( confirmModal ).on( 'click', '[data-deletefield]', deleteFieldConfirmed ); | |
| 569 | - jQuery( confirmModal ).on( 'click', '[data-removeid]', removeThisTag ); | |
| 570 | - jQuery( confirmModal ).on( 'click', '[data-trashtemplate]', trashTemplate ); | |
| 571 | - | |
| 572 | - wrapClass.on( 'click', '.frm_remove_tag, .frm_remove_form_action', removeThisTag ); | |
| 573 | - wrapClass.on( 'click', 'a[data-frmverify]', confirmClick ); | |
| 574 | - wrapClass.on( 'click', 'a[data-frmtoggle]', toggleItem ); | |
| 575 | - wrapClass.on( 'click', 'a[data-frmhide], a[data-frmshow]', hideShowItem ); | |
| 576 | - wrapClass.on( 'change', 'input[data-frmhide], input[data-frmshow]', hideShowItem ); | |
| 577 | - wrapClass.on( 'click', '.widget-top,a.widget-action', clickWidget ); | |
| 578 | - | |
| 579 | - wrapClass.on( 'mouseenter.frm', '.frm_bstooltip, .frm_help', function() { | |
| 580 | - jQuery( this ).off( 'mouseenter.frm' ); | |
| 581 | - | |
| 582 | - jQuery( '.frm_bstooltip, .frm_help' ).tooltip( ); | |
| 583 | - jQuery( this ).tooltip( 'show' ); | |
| 584 | - }); | |
| 585 | - | |
| 586 | - jQuery( '.frm_bstooltip, .frm_help' ).tooltip( ); | |
| 587 | - | |
| 588 | - jQuery( document ).on( 'click', '#doaction, #doaction2', function( event ) { | |
| 589 | - var isTop = this.id === 'doaction', | |
| 590 | - suffix = isTop ? 'top' : 'bottom', | |
| 591 | - bulkActionSelector = document.getElementById( 'bulk-action-selector-' + suffix ), | |
| 592 | - confirmBulkDelete = document.getElementById( 'confirm-bulk-delete-' + suffix ); | |
| 593 | - | |
| 594 | - if ( bulkActionSelector !== null && confirmBulkDelete !== null ) { | |
| 595 | - doAction = this; | |
| 596 | - | |
| 597 | - if ( ! confirmedBulkDelete && bulkActionSelector.value === 'bulk_delete' ) { | |
| 598 | - event.preventDefault(); | |
| 599 | - confirmLinkClick( confirmBulkDelete ); | |
| 600 | - return false; | |
| 601 | - } | |
| 602 | - } else { | |
| 603 | - doAction = false; | |
| 604 | - } | |
| 605 | - }); | |
| 606 | - | |
| 607 | - jQuery( document ).on( 'click', '#frm-confirmed-click', function( event ) { | |
| 608 | - if ( doAction === false || event.target.classList.contains( 'frm-btn-inactive' ) ) { | |
| 609 | - return; | |
| 610 | - } | |
| 611 | - | |
| 612 | - if ( this.getAttribute( 'href' ) === 'confirm-bulk-delete' ) { | |
| 613 | - event.preventDefault(); | |
| 614 | - confirmedBulkDelete = true; | |
| 615 | - doAction.click(); | |
| 616 | - return false; | |
| 617 | - } | |
| 618 | - }); | |
| 619 | - } | |
| 620 | - | |
| 621 | - function deleteTooltips() { | |
| 622 | - document.querySelectorAll( '.tooltip' ).forEach( | |
| 623 | - function( tooltip ) { | |
| 624 | - tooltip.remove(); | |
| 625 | - } | |
| 626 | - ); | |
| 627 | - } | |
| 628 | - | |
| 629 | - function removeThisTag() { | |
| 630 | - /*jshint validthis:true */ | |
| 631 | - let show, hide, removeMore; | |
| 632 | - | |
| 633 | - if ( parseInt( this.getAttribute( 'data-skip-frm-js' ) ) || confirmLinkClick( this ) === false ) { | |
| 634 | - return; | |
| 635 | - } | |
| 636 | - | |
| 637 | - const deleteButton = jQuery( this ); | |
| 638 | - const id = deleteButton.attr( 'data-removeid' ); | |
| 639 | - | |
| 640 | - show = deleteButton.attr( 'data-showlast' ); | |
| 641 | - if ( typeof show === 'undefined' ) { | |
| 642 | - show = ''; | |
| 643 | - } | |
| 644 | - | |
| 645 | - hide = deleteButton.attr( 'data-hidelast' ); | |
| 646 | - if ( typeof hide === 'undefined' ) { | |
| 647 | - hide = ''; | |
| 648 | - } | |
| 649 | - | |
| 650 | - removeMore = deleteButton.attr( 'data-removemore' ); | |
| 651 | - | |
| 652 | - if ( show !== '' ) { | |
| 653 | - if ( deleteButton.closest( '.frm_add_remove' ).find( '.frm_remove_tag:visible' ).length > 1 ) { | |
| 654 | - show = ''; | |
| 655 | - hide = ''; | |
| 656 | - } | |
| 657 | - } else if ( id.indexOf( 'frm_postmeta_' ) === 0 ) { | |
| 658 | - if ( jQuery( '#frm_postmeta_rows .frm_postmeta_row' ).length < 2 ) { | |
| 659 | - show = '.frm_add_postmeta_row.button'; | |
| 660 | - } | |
| 661 | - if ( jQuery( '.frm_toggle_cf_opts' ).length && jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().length ) { | |
| 662 | - if ( show !== '' ) { | |
| 663 | - show += ','; | |
| 664 | - } | |
| 665 | - show += '#' + jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().attr( 'id' ) + ' .frm_toggle_cf_opts'; | |
| 666 | - } | |
| 667 | - } | |
| 668 | - | |
| 669 | - const $fadeEle = jQuery( document.getElementById( id ) ); | |
| 670 | - $fadeEle.fadeOut( 400, function() { | |
| 671 | - $fadeEle.remove(); | |
| 672 | - fieldUpdated(); | |
| 673 | - | |
| 674 | - if ( hide !== '' ) { | |
| 675 | - jQuery( hide ).hide(); | |
| 676 | - } | |
| 677 | - | |
| 678 | - if ( show !== '' ) { | |
| 679 | - jQuery( show + ' a,' + show ).removeClass( 'frm_hidden' ).fadeIn( 'slow' ); | |
| 680 | - } | |
| 681 | - | |
| 682 | - if ( this.closest( '.frm_form_action_settings' ) ) { | |
| 683 | - const type = this.closest( '.frm_form_action_settings' ).querySelector( '.frm_action_name' ).value; | |
| 684 | - afterActionRemoved( type ); | |
| 685 | - } | |
| 686 | - }); | |
| 687 | - | |
| 688 | - if ( typeof removeMore !== 'undefined' ) { | |
| 689 | - removeMore = jQuery( removeMore ); | |
| 690 | - removeMore.fadeOut( 400, function() { | |
| 691 | - removeMore.remove(); | |
| 692 | - }); | |
| 693 | - } | |
| 694 | - | |
| 695 | - if ( show !== '' ) { | |
| 696 | - jQuery( this ).closest( '.frm_logic_rows' ).fadeOut( 'slow' ); | |
| 697 | - } | |
| 698 | - | |
| 699 | - return false; | |
| 700 | - } | |
| 701 | - | |
| 702 | - function afterActionRemoved( type ) { | |
| 703 | - checkActiveAction( type ); | |
| 704 | - | |
| 705 | - const hookName = 'frm_after_action_removed'; | |
| 706 | - const hookArgs = { type }; | |
| 707 | - wp.hooks.doAction( hookName, hookArgs ); | |
| 708 | - } | |
| 709 | - | |
| 710 | - function clickWidget( event, b ) { | |
| 711 | - /*jshint validthis:true */ | |
| 712 | - if ( typeof b === 'undefined' ) { | |
| 713 | - b = this; | |
| 714 | - } | |
| 715 | - | |
| 716 | - popCalcFields( b, false ); | |
| 717 | - | |
| 718 | - const cont = jQuery( b ).closest( '.frm_form_action_settings' ); | |
| 719 | - const target = event.target; | |
| 720 | - | |
| 721 | - if ( cont.length && typeof target !== 'undefined' ) { | |
| 722 | - const className = target.parentElement.className; | |
| 723 | - if ( 'string' === typeof className ) { | |
| 724 | - if ( className.indexOf( 'frm_email_icons' ) > -1 || className.indexOf( 'frm_toggle' ) > -1 ) { | |
| 725 | - // clicking on delete icon shouldn't open it | |
| 726 | - event.stopPropagation(); | |
| 727 | - return; | |
| 728 | - } | |
| 729 | - } | |
| 730 | - } | |
| 731 | - | |
| 732 | - let inside = cont.children( '.widget-inside' ); | |
| 733 | - | |
| 734 | - if ( cont.length && inside.find( 'p, div, table' ).length < 1 ) { | |
| 735 | - const actionId = cont.find( 'input[name$="[ID]"]' ).val(); | |
| 736 | - const actionType = cont.find( 'input[name$="[post_excerpt]"]' ).val(); | |
| 737 | - if ( actionType ) { | |
| 738 | - inside.html( '<span class="frm-wait frm_spinner"></span>' ); | |
| 739 | - cont.find( '.spinner' ).fadeIn( 'slow' ); | |
| 740 | - jQuery.ajax({ | |
| 741 | - type: 'POST', | |
| 742 | - url: ajaxurl, | |
| 743 | - data: { | |
| 744 | - action: 'frm_form_action_fill', | |
| 745 | - action_id: actionId, | |
| 746 | - action_type: actionType, | |
| 747 | - nonce: frmGlobal.nonce | |
| 748 | - }, | |
| 749 | - success: function( html ) { | |
| 750 | - inside.html( html ); | |
| 751 | - initiateMultiselect(); | |
| 752 | - showInputIcon( '#' + cont.attr( 'id' ) ); | |
| 753 | - frmDom.autocomplete.initAutocomplete( 'page', inside ); | |
| 754 | - jQuery( b ).trigger( 'frm-action-loaded' ); | |
| 755 | - | |
| 756 | - /** | |
| 757 | - * Fires after filling form action content when opening. | |
| 758 | - * | |
| 759 | - * @since 5.5.4 | |
| 760 | - * | |
| 761 | - * @param {Object} insideElement JQuery object of form action inside element. | |
| 762 | - */ | |
| 763 | - wp.hooks.doAction( 'frm_filled_form_action', inside ); | |
| 764 | - } | |
| 765 | - }); | |
| 766 | - } | |
| 767 | - } | |
| 768 | - | |
| 769 | - jQuery( b ).closest( '.frm_field_box' ).siblings().find( '.widget-inside' ).slideUp( 'fast' ); | |
| 770 | - if ( ( typeof b.className !== 'undefined' && b.className.indexOf( 'widget-action' ) !== -1 ) || jQuery( b ).closest( '.start_divider' ).length < 1 ) { | |
| 771 | - return; | |
| 772 | - } | |
| 773 | - | |
| 774 | - inside = jQuery( b ).closest( 'div.widget' ).children( '.widget-inside' ); | |
| 775 | - if ( inside.is( ':hidden' ) ) { | |
| 776 | - inside.slideDown( 'fast' ); | |
| 777 | - } else { | |
| 778 | - inside.slideUp( 'fast' ); | |
| 779 | - } | |
| 780 | - } | |
| 781 | - | |
| 782 | - function clickNewTab() { | |
| 783 | - /*jshint validthis:true */ | |
| 784 | - var t = this.getAttribute( 'href' ), | |
| 785 | - c = t.replace( '#', '.' ), | |
| 786 | - $link = jQuery( this ); | |
| 787 | - | |
| 788 | - if ( typeof t === 'undefined' ) { | |
| 789 | - return false; | |
| 790 | - } | |
| 791 | - | |
| 792 | - $link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' ); | |
| 793 | - $link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide(); | |
| 794 | - document.getElementById( t.replace( '#', '' ) ).style.display = 'block'; | |
| 795 | - | |
| 796 | - if ( this.id === 'frm_insert_fields_tab' ) { | |
| 797 | - clearSettingsBox(); | |
| 798 | - } | |
| 799 | - return false; | |
| 800 | - } | |
| 801 | - | |
| 802 | - function clickTab( link, auto ) { | |
| 803 | - link = jQuery( link ); | |
| 804 | - var t = link.attr( 'href' ); | |
| 805 | - if ( typeof t === 'undefined' ) { | |
| 806 | - return; | |
| 807 | - } | |
| 808 | - | |
| 809 | - var c = t.replace( '#', '.' ); | |
| 810 | - | |
| 811 | - link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' ); | |
| 812 | - if ( link.closest( 'div' ).find( '.tabs-panel' ).length ) { | |
| 813 | - link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide(); | |
| 814 | - } else { | |
| 815 | - if ( document.getElementById( 'form_global_settings' ) !== null ) { | |
| 816 | - /* global settings */ | |
| 817 | - var ajax = link.data( 'frmajax' ); | |
| 818 | - link.closest( '.frm_wrap' ).find( '.tabs-panel, .hide_with_tabs' ).hide(); | |
| 819 | - if ( typeof ajax !== 'undefined' && ajax == '1' ) { | |
| 820 | - loadSettingsTab( t ); | |
| 821 | - } | |
| 822 | - } else { | |
| 823 | - /* form settings page */ | |
| 824 | - jQuery( '#frm-categorydiv .tabs-panel, .hide_with_tabs' ).hide(); | |
| 825 | - } | |
| 826 | - } | |
| 827 | - jQuery( t ).show(); | |
| 828 | - jQuery( c ).show(); | |
| 829 | - | |
| 830 | - hideShortcodes(); | |
| 831 | - | |
| 832 | - if ( auto !== 'auto' ) { | |
| 833 | - // Hide success message on tab change. | |
| 834 | - jQuery( '.frm_updated_message' ).hide(); | |
| 835 | - jQuery( '.frm_warning_style' ).hide(); | |
| 836 | - } | |
| 837 | - | |
| 838 | - if ( jQuery( link ).closest( '#frm_adv_info' ).length ) { | |
| 839 | - return; | |
| 840 | - } | |
| 841 | - | |
| 842 | - if ( jQuery( '.frm_form_settings' ).length ) { | |
| 843 | - jQuery( '.frm_form_settings' ).attr( 'action', '?page=formidable&frm_action=settings&id=' + jQuery( '.frm_form_settings input[name="id"]' ).val() + '&t=' + t.replace( '#', '' ) ); | |
| 844 | - } else { | |
| 845 | - jQuery( '.frm_settings_form' ).attr( 'action', '?page=formidable-settings&t=' + t.replace( '#', '' ) ); | |
| 846 | - } | |
| 847 | - } | |
| 848 | - | |
| 849 | - function setupSortable( sortableSelector ) { | |
| 850 | - document.querySelectorAll( sortableSelector ).forEach( | |
| 851 | - list => { | |
| 852 | - makeDroppable( list ); | |
| 853 | - Array.from( list.children ).forEach( child => makeDraggable( child, '.frm-move' ) ); | |
| 854 | - | |
| 855 | - const $sectionTitle = jQuery( list ).children( '[data-type="divider"]' ).children( '.divider_section_only' ); | |
| 856 | - if ( $sectionTitle.length ) { | |
| 857 | - makeDroppable( $sectionTitle ); | |
| 858 | - } | |
| 859 | - } | |
| 860 | - ); | |
| 861 | - setupFieldOptionSorting( jQuery( '#frm_builder_page' ) ); | |
| 862 | - } | |
| 863 | - | |
| 864 | - function makeDroppable( list ) { | |
| 865 | - jQuery( list ).droppable({ | |
| 866 | - accept: '.frmbutton, li.frm_field_box', | |
| 867 | - deactivate: handleFieldDrop, | |
| 868 | - over: onDragOverDroppable, | |
| 869 | - out: onDraggableLeavesDroppable, | |
| 870 | - tolerance: 'pointer' | |
| 871 | - }); | |
| 872 | - } | |
| 873 | - | |
| 874 | - function onDragOverDroppable( event, ui ) { | |
| 875 | - const droppable = getDroppableForOnDragOver( event.target ); | |
| 876 | - const draggable = ui.draggable[0]; | |
| 877 | - | |
| 878 | - if ( ! allowDrop( draggable, droppable ) ) { | |
| 879 | - droppable.classList.remove( 'frm-over-droppable' ); | |
| 880 | - jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' ); | |
| 881 | - return; | |
| 882 | - } | |
| 883 | - | |
| 884 | - document.querySelectorAll( '.frm-over-droppable' ).forEach( droppable => droppable.classList.remove( 'frm-over-droppable' ) ); | |
| 885 | - droppable.classList.add( 'frm-over-droppable' ); | |
| 886 | - jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' ); | |
| 887 | - } | |
| 888 | - | |
| 889 | - /** | |
| 890 | - * Maybe change the droppable. | |
| 891 | - * Section titles are made droppable, but are not a list, so we need to change the droppable to the section's list instead. | |
| 892 | - * | |
| 893 | - * @param {Element} droppable | |
| 894 | - * @returns {Element} | |
| 895 | - */ | |
| 896 | - function getDroppableForOnDragOver( droppable ) { | |
| 897 | - if ( droppable.classList.contains( 'divider_section_only' ) ) { | |
| 898 | - droppable = jQuery( droppable ).nextAll( '.start_divider.frm_sorting' ).get( 0 ); | |
| 899 | - } | |
| 900 | - return droppable; | |
| 901 | - } | |
| 902 | - | |
| 903 | - function onDraggableLeavesDroppable( event ) { | |
| 904 | - const droppable = event.target; | |
| 905 | - droppable.classList.remove( 'frm-over-droppable' ); | |
| 906 | - } | |
| 907 | - | |
| 908 | - function makeDraggable( draggable, handle ) { | |
| 909 | - const settings = { | |
| 910 | - helper: getDraggableHelper, | |
| 911 | - revert: 'invalid', | |
| 912 | - delay: 10, | |
| 913 | - start: handleDragStart, | |
| 914 | - stop: handleDragStop, | |
| 915 | - drag: handleDrag, | |
| 916 | - cursor: 'grabbing', | |
| 917 | - refreshPositions: true, | |
| 918 | - cursorAt: { | |
| 919 | - top: 0, | |
| 920 | - left: 90 // The width of draggable button is 180. 90 should center the draggable on the cursor. | |
| 921 | - } | |
| 922 | - }; | |
| 923 | - if ( 'string' === typeof handle ) { | |
| 924 | - settings.handle = handle; | |
| 925 | - } | |
| 926 | - jQuery( draggable ).draggable( settings ); | |
| 927 | - } | |
| 928 | - | |
| 929 | - function getDraggableHelper( event ) { | |
| 930 | - const draggable = event.delegateTarget; | |
| 931 | - | |
| 932 | - if ( isFieldGroup( draggable ) ) { | |
| 933 | - const newTextFieldClone = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_ttext' ).cloneNode( true ); | |
| 934 | - newTextFieldClone.querySelector( 'use' ).setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_field_group_layout_icon' ); | |
| 935 | - newTextFieldClone.querySelector( 'span' ).textContent = __( 'Field Group' ); | |
| 936 | - newTextFieldClone.classList.add( 'frm_field_box' ); | |
| 937 | - newTextFieldClone.classList.add( 'ui-sortable-helper' ); | |
| 938 | - return newTextFieldClone; | |
| 939 | - } | |
| 940 | - | |
| 941 | - let copyTarget; | |
| 942 | - const isNewField = draggable.classList.contains( 'frmbutton' ); | |
| 943 | - if ( isNewField ) { | |
| 944 | - copyTarget = draggable.cloneNode( true ); | |
| 945 | - copyTarget.classList.add( 'ui-sortable-helper' ); | |
| 946 | - draggable.classList.add( 'frm-new-field' ); | |
| 947 | - return copyTarget; | |
| 948 | - } | |
| 949 | - | |
| 950 | - if ( draggable.hasAttribute( 'data-ftype' ) ) { | |
| 951 | - const fieldType = draggable.getAttribute( 'data-ftype' ); | |
| 952 | - copyTarget = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_t' + fieldType ); | |
| 953 | - copyTarget = copyTarget.cloneNode( true ); | |
| 954 | - copyTarget.classList.add( 'form-field' ); | |
| 955 | - | |
| 956 | - copyTarget.classList.add( 'ui-sortable-helper' ); | |
| 957 | - | |
| 958 | - if ( copyTarget ) { | |
| 959 | - return copyTarget.cloneNode( true ); | |
| 960 | - } | |
| 961 | - } | |
| 962 | - | |
| 963 | - return div({ className: 'frmbutton' }); | |
| 964 | - } | |
| 965 | - | |
| 966 | - function handleDragStart( event, ui ) { | |
| 967 | - const container = postBodyContent; | |
| 968 | - container.classList.add( 'frm-dragging-field' ); | |
| 969 | - | |
| 970 | - document.body.classList.add( 'frm-dragging' ); | |
| 971 | - ui.helper.addClass( 'frm-sortable-helper' ); | |
| 972 | - ui.helper.initialOffset = container.scrollTop; | |
| 973 | - | |
| 974 | - event.target.classList.add( 'frm-drag-fade' ); | |
| 975 | - | |
| 976 | - unselectFieldGroups(); | |
| 977 | - deleteEmptyDividerWrappers(); | |
| 978 | - maybeRemoveGroupHoverTarget(); | |
| 979 | - closeOpenFieldDropdowns(); | |
| 980 | - deleteTooltips(); | |
| 981 | - } | |
| 982 | - | |
| 983 | - function handleDragStop() { | |
| 984 | - const container = postBodyContent; | |
| 985 | - container.classList.remove( 'frm-dragging-field' ); | |
| 986 | - document.body.classList.remove( 'frm-dragging' ); | |
| 987 | - | |
| 988 | - const fade = document.querySelector( '.frm-drag-fade' ); | |
| 989 | - if ( fade ) { | |
| 990 | - fade.classList.remove( 'frm-drag-fade' ); | |
| 991 | - } | |
| 992 | - } | |
| 993 | - | |
| 994 | - function handleDrag( event, ui ) { | |
| 995 | - maybeScrollBuilder( event ); | |
| 996 | - const draggable = event.target; | |
| 997 | - const droppable = getDroppableTarget(); | |
| 998 | - | |
| 999 | - let placeholder = document.getElementById( 'frm_drag_placeholder' ); | |
| 1000 | - | |
| 1001 | - if ( ! allowDrop( draggable, droppable ) ) { | |
| 1002 | - if ( placeholder ) { | |
| 1003 | - placeholder.remove(); | |
| 1004 | - } | |
| 1005 | - return; | |
| 1006 | - } | |
| 1007 | - | |
| 1008 | - if ( ! placeholder ) { | |
| 1009 | - placeholder = tag( 'li', { | |
| 1010 | - id: 'frm_drag_placeholder', | |
| 1011 | - className: 'sortable-placeholder' | |
| 1012 | - }); | |
| 1013 | - } | |
| 1014 | - const frmSortableHelper = ui.helper.get( 0 ); | |
| 1015 | - if ( frmSortableHelper.classList.contains( 'form-field' ) || frmSortableHelper.classList.contains( 'frm_field_box' ) ) { | |
| 1016 | - // Sync the y position of the draggable so it still follows the cursor after scrolling up and down the field list. | |
| 1017 | - frmSortableHelper.style.transform = 'translateY(' + getDragOffset( ui.helper ) + 'px)'; | |
| 1018 | - } | |
| 1019 | - | |
| 1020 | - if ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) ) { | |
| 1021 | - placeholder.style.left = 0; | |
| 1022 | - handleDragOverYAxis({ droppable, y: event.clientY, placeholder }); | |
| 1023 | - return; | |
| 1024 | - } | |
| 1025 | - | |
| 1026 | - placeholder.style.top = ''; | |
| 1027 | - handleDragOverFieldGroup({ droppable, x: event.clientX, placeholder }); | |
| 1028 | - } | |
| 1029 | - | |
| 1030 | - function maybeScrollBuilder( event ) { | |
| 1031 | - $postBodyContent.scrollTop( | |
| 1032 | - ( _, v ) => { | |
| 1033 | - const moved = event.clientY; | |
| 1034 | - const h = postBodyContent.offsetHeight; | |
| 1035 | - const relativePos = event.clientY - postBodyContent.offsetTop; | |
| 1036 | - const y = relativePos - h / 2; | |
| 1037 | - | |
| 1038 | - if ( relativePos > ( h - 50 ) && moved > 5 ) { | |
| 1039 | - // Scrolling down. | |
| 1040 | - return v + y * 0.1; | |
| 1041 | - } | |
| 1042 | - | |
| 1043 | - if ( relativePos < 70 && moved < 130 ) { | |
| 1044 | - // Scrolling up. | |
| 1045 | - return v - Math.abs( y * 0.1 ); | |
| 1046 | - } | |
| 1047 | - | |
| 1048 | - return v; | |
| 1049 | - } | |
| 1050 | - ); | |
| 1051 | - } | |
| 1052 | - | |
| 1053 | - function getDragOffset( $helper ) { | |
| 1054 | - return postBodyContent.scrollTop - $helper.initialOffset; | |
| 1055 | - } | |
| 1056 | - | |
| 1057 | - function getDroppableTarget() { | |
| 1058 | - let droppable = document.getElementById( 'frm-show-fields' ); | |
| 1059 | - while ( droppable.querySelector( '.frm-over-droppable' ) ) { | |
| 1060 | - droppable = droppable.querySelector( '.frm-over-droppable' ); | |
| 1061 | - } | |
| 1062 | - if ( 'frm-show-fields' === droppable.id && ! droppable.classList.contains( 'frm-over-droppable' ) ) { | |
| 1063 | - droppable = false; | |
| 1064 | - } | |
| 1065 | - return droppable; | |
| 1066 | - } | |
| 1067 | - | |
| 1068 | - function handleFieldDrop( _, ui ) { | |
| 1069 | - const draggable = ui.draggable[0]; | |
| 1070 | - const placeholder = document.getElementById( 'frm_drag_placeholder' ); | |
| 1071 | - | |
| 1072 | - if ( ! placeholder ) { | |
| 1073 | - ui.helper.remove(); | |
| 1074 | - debouncedSyncAfterDragAndDrop(); | |
| 1075 | - return; | |
| 1076 | - } | |
| 1077 | - | |
| 1078 | - maybeOpenCollapsedPage( placeholder ); | |
| 1079 | - | |
| 1080 | - const $previousFieldContainer = ui.helper.parent(); | |
| 1081 | - const previousSection = ui.helper.get( 0 ).closest( 'ul.start_divider' ); | |
| 1082 | - const newSection = placeholder.closest( 'ul.frm_sorting' ); | |
| 1083 | - | |
| 1084 | - if ( draggable.classList.contains( 'frm-new-field' ) ) { | |
| 1085 | - insertNewFieldByDragging( draggable.id ); | |
| 1086 | - } else { | |
| 1087 | - moveFieldThatAlreadyExists( draggable, placeholder ); | |
| 1088 | - } | |
| 1089 | - | |
| 1090 | - const previousSectionId = previousSection ? parseInt( previousSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0; | |
| 1091 | - const newSectionId = newSection.classList.contains( 'start_divider' ) ? parseInt( newSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0; | |
| 1092 | - | |
| 1093 | - placeholder.remove(); | |
| 1094 | - ui.helper.remove(); | |
| 1095 | - | |
| 1096 | - const $previousContainerFields = $previousFieldContainer.length ? getFieldsInRow( $previousFieldContainer ) : []; | |
| 1097 | - maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields ); | |
| 1098 | - maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields ); | |
| 1099 | - | |
| 1100 | - if ( previousSectionId !== newSectionId ) { | |
| 1101 | - updateFieldAfterMovingBetweenSections( jQuery( draggable ), previousSection ); | |
| 1102 | - } | |
| 1103 | - | |
| 1104 | - debouncedSyncAfterDragAndDrop(); | |
| 1105 | - } | |
| 1106 | - | |
| 1107 | - /** | |
| 1108 | - * If a page if collapsed, expand it before dragging since only the page break will move. | |
| 1109 | - * | |
| 1110 | - * @param {Element} placeholder | |
| 1111 | - * @returns {void} | |
| 1112 | - */ | |
| 1113 | - function maybeOpenCollapsedPage( placeholder ) { | |
| 1114 | - if ( ! placeholder.previousElementSibling || ! placeholder.previousElementSibling.classList.contains( 'frm-is-collapsed' ) ) { | |
| 1115 | - return; | |
| 1116 | - } | |
| 1117 | - | |
| 1118 | - const $pageBreakField = jQuery( placeholder ).prevUntil( '[data-type="break"]' ); | |
| 1119 | - if ( ! $pageBreakField.length ) { | |
| 1120 | - return; | |
| 1121 | - } | |
| 1122 | - | |
| 1123 | - const collapseButton = $pageBreakField.find( '.frm-collapse-page' ).get( 0 ); | |
| 1124 | - if ( collapseButton ) { | |
| 1125 | - collapseButton.click(); | |
| 1126 | - } | |
| 1127 | - } | |
| 1128 | - | |
| 1129 | - function maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields ) { | |
| 1130 | - if ( ! $previousFieldContainer.length ) { | |
| 1131 | - return; | |
| 1132 | - } | |
| 1133 | - | |
| 1134 | - if ( $previousContainerFields.length ) { | |
| 1135 | - syncLayoutClasses( $previousContainerFields.first() ); | |
| 1136 | - } else { | |
| 1137 | - maybeDeleteAnEmptyFieldGroup( $previousFieldContainer.get( 0 ) ); | |
| 1138 | - } | |
| 1139 | - } | |
| 1140 | - | |
| 1141 | - function maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields ) { | |
| 1142 | - if ( 0 !== $previousContainerFields.length || 1 !== getFieldsInRow( jQuery( draggable.parentNode ) ).length ) { | |
| 1143 | - syncLayoutClasses( jQuery( draggable ) ); | |
| 1144 | - } | |
| 1145 | - } | |
| 1146 | - | |
| 1147 | - /** | |
| 1148 | - * Remove an empty field group, but don't remove an empty section. | |
| 1149 | - * | |
| 1150 | - * @param {Element} previousFieldContainer | |
| 1151 | - * @returns {void} | |
| 1152 | - */ | |
| 1153 | - function maybeDeleteAnEmptyFieldGroup( previousFieldContainer ) { | |
| 1154 | - const closestFieldBox = previousFieldContainer.closest( 'li.frm_field_box' ); | |
| 1155 | - if ( closestFieldBox && ! closestFieldBox.classList.contains( 'edit_field_type_divider' ) ) { | |
| 1156 | - closestFieldBox.remove(); | |
| 1157 | - } | |
| 1158 | - } | |
| 1159 | - | |
| 1160 | - function handleDragOverYAxis({ droppable, y, placeholder }) { | |
| 1161 | - const $list = jQuery( droppable ); | |
| 1162 | - | |
| 1163 | - let top; | |
| 1164 | - | |
| 1165 | - $children = $list.children().not( '.edit_field_type_end_divider' ); | |
| 1166 | - if ( 0 === $children.length ) { | |
| 1167 | - $list.prepend( placeholder ); | |
| 1168 | - top = 0; | |
| 1169 | - } else { | |
| 1170 | - const insertAtIndex = determineIndexBasedOffOfMousePositionInList( $list, y ); | |
| 1171 | - | |
| 1172 | - if ( insertAtIndex === $children.length ) { | |
| 1173 | - const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) ); | |
| 1174 | - top = $lastChild.offset().top + $lastChild.outerHeight(); | |
| 1175 | - $list.append( placeholder ); | |
| 1176 | - | |
| 1177 | - // Make sure nothing gets inserted after the end divider. | |
| 1178 | - const $endDivider = $list.children( '.edit_field_type_end_divider' ); | |
| 1179 | - if ( $endDivider.length ) { | |
| 1180 | - $list.append( $endDivider ); | |
| 1181 | - } | |
| 1182 | - } else { | |
| 1183 | - top = jQuery( $children.get( insertAtIndex ) ).offset().top; | |
| 1184 | - jQuery( $children.get( insertAtIndex ) ).before( placeholder ); | |
| 1185 | - } | |
| 1186 | - } | |
| 1187 | - | |
| 1188 | - top -= $list.offset().top; | |
| 1189 | - placeholder.style.top = top + 'px'; | |
| 1190 | - } | |
| 1191 | - | |
| 1192 | - function determineIndexBasedOffOfMousePositionInList( $list, y ) { | |
| 1193 | - const $items = $list.children().not( '.edit_field_type_end_divider' ); | |
| 1194 | - const length = $items.length; | |
| 1195 | - | |
| 1196 | - let index, item, itemTop, returnIndex; | |
| 1197 | - | |
| 1198 | - returnIndex = 0; | |
| 1199 | - for ( index = length - 1; index >= 0; --index ) { | |
| 1200 | - item = $items.get( index ); | |
| 1201 | - itemTop = jQuery( item ).offset().top; | |
| 1202 | - if ( y > itemTop ) { | |
| 1203 | - returnIndex = index; | |
| 1204 | - if ( y > itemTop + ( jQuery( item ).outerHeight() / 2 ) ) { | |
| 1205 | - returnIndex = index + 1; | |
| 1206 | - } | |
| 1207 | - break; | |
| 1208 | - } | |
| 1209 | - } | |
| 1210 | - | |
| 1211 | - return returnIndex; | |
| 1212 | - } | |
| 1213 | - | |
| 1214 | - function handleDragOverFieldGroup({ droppable, x, placeholder }) { | |
| 1215 | - const $row = jQuery( droppable ); | |
| 1216 | - const $children = getFieldsInRow( $row ); | |
| 1217 | - | |
| 1218 | - if ( ! $children.length ) { | |
| 1219 | - return; | |
| 1220 | - } | |
| 1221 | - | |
| 1222 | - let left; | |
| 1223 | - const insertAtIndex = determineIndexBasedOffOfMousePositionInRow( $row, x ); | |
| 1224 | - | |
| 1225 | - if ( insertAtIndex === $children.length ) { | |
| 1226 | - const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) ); | |
| 1227 | - left = $lastChild.offset().left + $lastChild.outerWidth(); | |
| 1228 | - $row.append( placeholder ); | |
| 1229 | - } else { | |
| 1230 | - left = jQuery( $children.get( insertAtIndex ) ).offset().left; | |
| 1231 | - jQuery( $children.get( insertAtIndex ) ).before( placeholder ); | |
| 1232 | - | |
| 1233 | - const amountToOffsetLeftBy = 0 === insertAtIndex ? 4 : 8; // Offset by 8 in between rows, but only 4 for the first item in a group. | |
| 1234 | - left -= amountToOffsetLeftBy; // Offset the placeholder slightly so it appears between two fields. | |
| 1235 | - } | |
| 1236 | - | |
| 1237 | - left -= $row.offset().left; | |
| 1238 | - | |
| 1239 | - placeholder.style.left = left + 'px'; | |
| 1240 | - } | |
| 1241 | - | |
| 1242 | - function syncAfterDragAndDrop() { | |
| 1243 | - fixUnwrappedListItems(); | |
| 1244 | - toggleSectionHolder(); | |
| 1245 | - maybeFixEndDividers(); | |
| 1246 | - maybeDeleteEmptyFieldGroups(); | |
| 1247 | - updateFieldOrder(); | |
| 1248 | - | |
| 1249 | - const event = new Event( 'frm_sync_after_drag_and_drop', { bubbles: false }); | |
| 1250 | - document.dispatchEvent( event ); | |
| 1251 | - } | |
| 1252 | - | |
| 1253 | - function maybeFixEndDividers() { | |
| 1254 | - document.querySelectorAll( '.edit_field_type_end_divider' ).forEach( | |
| 1255 | - endDivider => endDivider.parentNode.appendChild( endDivider ) | |
| 1256 | - ); | |
| 1257 | - } | |
| 1258 | - | |
| 1259 | - function maybeDeleteEmptyFieldGroups() { | |
| 1260 | - document.querySelectorAll( 'li.form_field_box:not(.form-field)' ).forEach( | |
| 1261 | - fieldGroup => ! fieldGroup.children.length && fieldGroup.remove() | |
| 1262 | - ); | |
| 1263 | - } | |
| 1264 | - | |
| 1265 | - function fixUnwrappedListItems() { | |
| 1266 | - const lists = document.querySelectorAll( 'ul#frm-show-fields, ul.start_divider' ); | |
| 1267 | - lists.forEach( | |
| 1268 | - list => { | |
| 1269 | - list.childNodes.forEach( | |
| 1270 | - child => { | |
| 1271 | - if ( 'undefined' === typeof child.classList ) { | |
| 1272 | - return; | |
| 1273 | - } | |
| 1274 | - | |
| 1275 | - if ( child.classList.contains( 'edit_field_type_end_divider' ) ) { | |
| 1276 | - // Never wrap end divider in place. | |
| 1277 | - return; | |
| 1278 | - } | |
| 1279 | - | |
| 1280 | - if ( 'undefined' !== typeof child.classList && child.classList.contains( 'form-field' ) ) { | |
| 1281 | - wrapFieldLiInPlace( child ); | |
| 1282 | - } | |
| 1283 | - } | |
| 1284 | - ); | |
| 1285 | - } | |
| 1286 | - ); | |
| 1287 | - } | |
| 1288 | - | |
| 1289 | - function deleteEmptyDividerWrappers() { | |
| 1290 | - const dividers = document.querySelectorAll( 'ul.start_divider' ); | |
| 1291 | - if ( ! dividers.length ) { | |
| 1292 | - return; | |
| 1293 | - } | |
| 1294 | - dividers.forEach( | |
| 1295 | - function( divider ) { | |
| 1296 | - const children = [].slice.call( divider.children ); | |
| 1297 | - children.forEach( | |
| 1298 | - function( child ) { | |
| 1299 | - if ( 0 === child.children.length ) { | |
| 1300 | - child.remove(); | |
| 1301 | - } else if ( 1 === child.children.length && 'ul' === child.firstElementChild.nodeName.toLowerCase() && 0 === child.firstElementChild.children.length ) { | |
| 1302 | - child.remove(); | |
| 1303 | - } | |
| 1304 | - } | |
| 1305 | - ); | |
| 1306 | - } | |
| 1307 | - ); | |
| 1308 | - } | |
| 1309 | - | |
| 1310 | - function getFieldsInRow( $row ) { | |
| 1311 | - let $fields = jQuery(); | |
| 1312 | - | |
| 1313 | - const row = $row.get( 0 ); | |
| 1314 | - if ( ! row.children ) { | |
| 1315 | - return $fields; | |
| 1316 | - } | |
| 1317 | - | |
| 1318 | - Array.from( row.children ).forEach( | |
| 1319 | - child => { | |
| 1320 | - if ( 'none' === child.style.display ) { | |
| 1321 | - return; | |
| 1322 | - } | |
| 1323 | - | |
| 1324 | - const classes = child.classList; | |
| 1325 | - if ( ! classes.contains( 'form-field' ) || classes.contains( 'edit_field_type_end_divider' ) || classes.contains( 'frm-sortable-helper' ) ) { | |
| 1326 | - return; | |
| 1327 | - } | |
| 1328 | - | |
| 1329 | - $fields = $fields.add( child ); | |
| 1330 | - } | |
| 1331 | - ); | |
| 1332 | - return $fields; | |
| 1333 | - } | |
| 1334 | - | |
| 1335 | - function determineIndexBasedOffOfMousePositionInRow( $row, x ) { | |
| 1336 | - var $inputs = getFieldsInRow( $row ), | |
| 1337 | - length = $inputs.length, | |
| 1338 | - index, input, inputLeft, returnIndex; | |
| 1339 | - | |
| 1340 | - returnIndex = 0; | |
| 1341 | - for ( index = length - 1; index >= 0; --index ) { | |
| 1342 | - input = $inputs.get( index ); | |
| 1343 | - inputLeft = jQuery( input ).offset().left; | |
| 1344 | - if ( x > inputLeft ) { | |
| 1345 | - returnIndex = index; | |
| 1346 | - if ( x > inputLeft + ( jQuery( input ).outerWidth() / 2 ) ) { | |
| 1347 | - returnIndex = index + 1; | |
| 1348 | - } | |
| 1349 | - break; | |
| 1350 | - } | |
| 1351 | - } | |
| 1352 | - | |
| 1353 | - return returnIndex; | |
| 1354 | - } | |
| 1355 | - | |
| 1356 | - function syncLayoutClasses( $item, type ) { | |
| 1357 | - var $fields, size, layoutClasses, classToAddFunction; | |
| 1358 | - | |
| 1359 | - if ( 'undefined' === typeof type ) { | |
| 1360 | - type = 'even'; | |
| 1361 | - } | |
| 1362 | - | |
| 1363 | - $fields = $item.parent().children( 'li.form-field, li.frmbutton_loadingnow' ).not( '.edit_field_type_end_divider' ); | |
| 1364 | - size = $fields.length; | |
| 1365 | - layoutClasses = getLayoutClasses(); | |
| 1366 | - | |
| 1367 | - if ( 'even' === type && 5 !== size ) { | |
| 1368 | - $fields.each( getSyncLayoutClass( layoutClasses, getEvenClassForSize( size ) ) ); | |
| 1369 | - } else if ( 'clear' === type ) { | |
| 1370 | - $fields.each( getSyncLayoutClass( layoutClasses, '' ) ); | |
| 1371 | - } else { | |
| 1372 | - if ( -1 !== [ 'left', 'right', 'middle', 'even' ].indexOf( type ) ) { | |
| 1373 | - classToAddFunction = function( index ) { | |
| 1374 | - return getClassForBlock( size, type, index ); | |
| 1375 | - }; | |
| 1376 | - } else { | |
| 1377 | - classToAddFunction = function( index ) { | |
| 1378 | - var size = type[ index ]; | |
| 1379 | - return getLayoutClassForSize( size ); | |
| 1380 | - }; | |
| 1381 | - } | |
| 1382 | - | |
| 1383 | - $fields.each( getSyncLayoutClass( layoutClasses, classToAddFunction ) ); | |
| 1384 | - } | |
| 1385 | - | |
| 1386 | - updateFieldGroupControls( $item.parent(), $fields.length ); | |
| 1387 | - } | |
| 1388 | - | |
| 1389 | - function updateFieldGroupControls( $row, count ) { | |
| 1390 | - var rowOffset, shouldShowControls, controls; | |
| 1391 | - | |
| 1392 | - rowOffset = $row.offset(); | |
| 1393 | - | |
| 1394 | - if ( 'undefined' === typeof rowOffset ) { | |
| 1395 | - return; | |
| 1396 | - } | |
| 1397 | - | |
| 1398 | - shouldShowControls = count >= 2; | |
| 1399 | - | |
| 1400 | - controls = document.getElementById( 'frm_field_group_controls' ); | |
| 1401 | - if ( null === controls ) { | |
| 1402 | - if ( ! shouldShowControls ) { | |
| 1403 | - // exit early. if we do not need controls and they do not exist, do nothing. | |
| 1404 | - return; | |
| 1405 | - } | |
| 1406 | - | |
| 1407 | - controls = div(); | |
| 1408 | - controls.id = 'frm_field_group_controls'; | |
| 1409 | - controls.setAttribute( 'role', 'group' ); | |
| 1410 | - controls.setAttribute( 'tabindex', 0 ); | |
| 1411 | - setFieldControlsHtml( controls ); | |
| 1412 | - document.getElementById( 'frm_builder_page' ).appendChild( controls ); | |
| 1413 | - } | |
| 1414 | - | |
| 1415 | - $row.append( controls ); | |
| 1416 | - controls.style.display = shouldShowControls ? 'block' : 'none'; | |
| 1417 | - } | |
| 1418 | - | |
| 1419 | - function setFieldControlsHtml( controls ) { | |
| 1420 | - var layoutOption, moveOption; | |
| 1421 | - | |
| 1422 | - layoutOption = document.createElement( 'span' ); | |
| 1423 | - layoutOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_field_group_layout_icon"></use></svg>'; | |
| 1424 | - const layoutOptionLabel = __( 'Set Row Layout', 'formidable' ); | |
| 1425 | - addTooltip( layoutOption, layoutOptionLabel ); | |
| 1426 | - makeTabbable( layoutOption, layoutOptionLabel ); | |
| 1427 | - | |
| 1428 | - moveOption = document.createElement( 'span' ); | |
| 1429 | - moveOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_thick_move_icon"></use></svg>'; | |
| 1430 | - moveOption.classList.add( 'frm-move' ); | |
| 1431 | - const moveOptionLabel = __( 'Move Field Group', 'formidable' ); | |
| 1432 | - addTooltip( moveOption, moveOptionLabel ); | |
| 1433 | - makeTabbable( moveOption, moveOptionLabel ); | |
| 1434 | - | |
| 1435 | - controls.innerHTML = ''; | |
| 1436 | - controls.appendChild( layoutOption ); | |
| 1437 | - controls.appendChild( moveOption ); | |
| 1438 | - controls.appendChild( getFieldControlsDropdown() ); | |
| 1439 | - } | |
| 1440 | - | |
| 1441 | - function addTooltip( element, title ) { | |
| 1442 | - element.setAttribute( 'data-toggle', 'tooltip' ); | |
| 1443 | - element.setAttribute( 'data-container', 'body' ); | |
| 1444 | - element.setAttribute( 'title', title ); | |
| 1445 | - element.addEventListener( | |
| 1446 | - 'mouseover', | |
| 1447 | - function() { | |
| 1448 | - if ( null === element.getAttribute( 'data-original-title' ) ) { | |
| 1449 | - jQuery( element ).tooltip(); | |
| 1450 | - } | |
| 1451 | - } | |
| 1452 | - ); | |
| 1453 | - } | |
| 1454 | - | |
| 1455 | - function getFieldControlsDropdown() { | |
| 1456 | - var dropdown, trigger, ul; | |
| 1457 | - | |
| 1458 | - dropdown = document.createElement( 'span' ); | |
| 1459 | - dropdown.classList.add( 'dropdown' ); | |
| 1460 | - | |
| 1461 | - trigger = document.createElement( 'a' ); | |
| 1462 | - trigger.classList.add( 'frm_bstooltip', 'frm-hover-icon', 'frm-dropdown-toggle', 'dropdown-toggle' ); | |
| 1463 | - trigger.setAttribute( 'title', __( 'More Options', 'formidable' ) ); | |
| 1464 | - trigger.setAttribute( 'data-toggle', 'dropdown' ); | |
| 1465 | - trigger.setAttribute( 'data-container', 'body' ); | |
| 1466 | - makeTabbable( trigger, __( 'More Options', 'formidable' ) ); | |
| 1467 | - trigger.innerHTML = '<span><svg class="frmsvg"><use xlink:href="#frm_thick_more_vert_icon"></use></svg></span>'; | |
| 1468 | - dropdown.appendChild( trigger ); | |
| 1469 | - | |
| 1470 | - ul = document.createElement( 'div' ); | |
| 1471 | - ul.classList.add( 'frm-dropdown-menu', 'dropdown-menu', 'dropdown-menu-right' ); | |
| 1472 | - ul.setAttribute( 'role', 'menu' ); | |
| 1473 | - dropdown.appendChild( ul ); | |
| 1474 | - | |
| 1475 | - return dropdown; | |
| 1476 | - } | |
| 1477 | - | |
| 1478 | - function getSyncLayoutClass( layoutClasses, classToAdd ) { | |
| 1479 | - return function( itemIndex ) { | |
| 1480 | - var currentClassToAdd, length, layoutClassIndex, currentClass, activeLayoutClass, fieldId, layoutClassesInput; | |
| 1481 | - | |
| 1482 | - currentClassToAdd = 'function' === typeof classToAdd ? classToAdd( itemIndex ) : classToAdd; | |
| 1483 | - length = layoutClasses.length; | |
| 1484 | - activeLayoutClass = false; | |
| 1485 | - for ( layoutClassIndex = 0; layoutClassIndex < length; ++layoutClassIndex ) { | |
| 1486 | - currentClass = layoutClasses[ layoutClassIndex ]; | |
| 1487 | - if ( this.classList.contains( currentClass ) ) { | |
| 1488 | - activeLayoutClass = currentClass; | |
| 1489 | - break; | |
| 1490 | - } | |
| 1491 | - } | |
| 1492 | - | |
| 1493 | - fieldId = this.dataset.fid; | |
| 1494 | - | |
| 1495 | - if ( 'undefined' === typeof fieldId ) { | |
| 1496 | - // we are syncing the drag/drop placeholder before the actual field has loaded. | |
| 1497 | - // this will get called again afterward and the input will exist then. | |
| 1498 | - this.classList.add( currentClassToAdd ); | |
| 1499 | - return; | |
| 1500 | - } | |
| 1501 | - | |
| 1502 | - moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) ); | |
| 1503 | - layoutClassesInput = document.getElementById( 'frm_classes_' + fieldId ); | |
| 1504 | - | |
| 1505 | - if ( null === layoutClassesInput ) { | |
| 1506 | - // not every field type has a layout class input. | |
| 1507 | - return; | |
| 1508 | - } | |
| 1509 | - | |
| 1510 | - if ( false === activeLayoutClass ) { | |
| 1511 | - if ( '' !== currentClassToAdd ) { | |
| 1512 | - layoutClassesInput.value = layoutClassesInput.value.concat( ' ' + currentClassToAdd ); | |
| 1513 | - } | |
| 1514 | - } else { | |
| 1515 | - this.classList.remove( activeLayoutClass ); | |
| 1516 | - layoutClassesInput.value = layoutClassesInput.value.replace( activeLayoutClass, currentClassToAdd ); | |
| 1517 | - } | |
| 1518 | - | |
| 1519 | - if ( this.classList.contains( 'frm_first' ) ) { | |
| 1520 | - this.classList.remove( 'frm_first' ); | |
| 1521 | - layoutClassesInput.value = layoutClassesInput.value.replace( 'frm_first', '' ).trim(); | |
| 1522 | - } | |
| 1523 | - | |
| 1524 | - if ( 0 === itemIndex ) { | |
| 1525 | - this.classList.add( 'frm_first' ); | |
| 1526 | - layoutClassesInput.value = layoutClassesInput.value.concat( ' frm_first' ); | |
| 1527 | - } | |
| 1528 | - | |
| 1529 | - jQuery( layoutClassesInput ).trigger( 'change' ); | |
| 1530 | - }; | |
| 1531 | - } | |
| 1532 | - | |
| 1533 | - function getLayoutClasses() { | |
| 1534 | - 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' ]; | |
| 1535 | - } | |
| 1536 | - | |
| 1537 | - function setupFieldOptionSorting( sort ) { | |
| 1538 | - var opts = { | |
| 1539 | - items: '.frm_sortable_field_opts li', | |
| 1540 | - axis: 'y', | |
| 1541 | - opacity: 0.65, | |
| 1542 | - forcePlaceholderSize: false, | |
| 1543 | - handle: '.frm-drag', | |
| 1544 | - helper: function( e, li ) { | |
| 1545 | - copyHelper = li.clone().insertAfter( li ); | |
| 1546 | - return li.clone(); | |
| 1547 | - }, | |
| 1548 | - stop: function( e, ui ) { | |
| 1549 | - copyHelper && copyHelper.remove(); | |
| 1550 | - var fieldId = ui.item.attr( 'id' ).replace( 'frm_delete_field_', '' ).replace( '-' + ui.item.data( 'optkey' ) + '_container', '' ); | |
| 1551 | - resetDisplayedOpts( fieldId ); | |
| 1552 | - fieldUpdated(); | |
| 1553 | - } | |
| 1554 | - }; | |
| 1555 | - jQuery( sort ).sortable( opts ); | |
| 1556 | - } | |
| 1557 | - | |
| 1558 | - // Get the section where a field is dropped | |
| 1559 | - function getSectionForFieldPlacement( currentItem ) { | |
| 1560 | - var section = ''; | |
| 1561 | - if ( typeof currentItem !== 'undefined' && ! currentItem.hasClass( 'edit_field_type_divider' ) ) { | |
| 1562 | - section = currentItem.closest( '.edit_field_type_divider' ); | |
| 1563 | - } | |
| 1564 | - return section; | |
| 1565 | - } | |
| 1566 | - | |
| 1567 | - // Get the form ID where a field is dropped | |
| 1568 | - function getFormIdForFieldPlacement( section ) { | |
| 1569 | - var formId = ''; | |
| 1570 | - | |
| 1571 | - if ( typeof section[0] !== 'undefined' ) { | |
| 1572 | - var sDivide = section.children( '.start_divider' ); | |
| 1573 | - sDivide.children( '.edit_field_type_end_divider' ).appendTo( sDivide ); | |
| 1574 | - if ( typeof section.attr( 'data-formid' ) !== 'undefined' ) { | |
| 1575 | - var fieldId = section.attr( 'data-fid' ); | |
| 1576 | - formId = jQuery( 'input[name="field_options[form_select_' + fieldId + ']"]' ).val(); | |
| 1577 | - } | |
| 1578 | - } | |
| 1579 | - | |
| 1580 | - if ( typeof formId === 'undefined' || formId === '' ) { | |
| 1581 | - formId = thisFormId; | |
| 1582 | - } | |
| 1583 | - | |
| 1584 | - return formId; | |
| 1585 | - } | |
| 1586 | - | |
| 1587 | - // Get the section ID where a field is dropped | |
| 1588 | - function getSectionIdForFieldPlacement( section ) { | |
| 1589 | - var sectionId = 0; | |
| 1590 | - if ( typeof section[0] !== 'undefined' ) { | |
| 1591 | - sectionId = section.attr( 'id' ).replace( 'frm_field_id_', '' ); | |
| 1592 | - } | |
| 1593 | - | |
| 1594 | - return sectionId; | |
| 1595 | - } | |
| 1596 | - | |
| 1597 | - /** | |
| 1598 | - * Update a field after it is dragged and dropped into, out of, or between sections | |
| 1599 | - * | |
| 1600 | - * @param {Object} currentItem | |
| 1601 | - * @param {Object} previousSection | |
| 1602 | - * @returns {void} | |
| 1603 | - */ | |
| 1604 | - function updateFieldAfterMovingBetweenSections( currentItem, previousSection ) { | |
| 1605 | - if ( ! currentItem.hasClass( 'form-field' ) ) { | |
| 1606 | - // currentItem is a field group. Call for children recursively. | |
| 1607 | - getFieldsInRow( jQuery( currentItem.get( 0 ).firstChild ) ).each( | |
| 1608 | - function() { | |
| 1609 | - updateFieldAfterMovingBetweenSections( jQuery( this ), previousSection ); | |
| 1610 | - } | |
| 1611 | - ); | |
| 1612 | - return; | |
| 1613 | - } | |
| 1614 | - | |
| 1615 | - const fieldId = currentItem.attr( 'id' ).replace( 'frm_field_id_', '' ); | |
| 1616 | - const section = getSectionForFieldPlacement( currentItem ); | |
| 1617 | - const formId = getFormIdForFieldPlacement( section ); | |
| 1618 | - const sectionId = getSectionIdForFieldPlacement( section ); | |
| 1619 | - const previousFormId = previousSection ? getFormIdForFieldPlacement( jQuery( previousSection.parentNode ) ) : 0; | |
| 1620 | - | |
| 1621 | - jQuery.ajax({ | |
| 1622 | - type: 'POST', | |
| 1623 | - url: ajaxurl, | |
| 1624 | - data: { | |
| 1625 | - action: 'frm_update_field_after_move', | |
| 1626 | - form_id: formId, | |
| 1627 | - field: fieldId, | |
| 1628 | - section_id: sectionId, | |
| 1629 | - previous_form_id: previousFormId, | |
| 1630 | - nonce: frmGlobal.nonce | |
| 1631 | - }, | |
| 1632 | - success: function() { | |
| 1633 | - toggleSectionHolder(); | |
| 1634 | - updateInSectionValue( fieldId, sectionId ); | |
| 1635 | - } | |
| 1636 | - }); | |
| 1637 | - } | |
| 1638 | - | |
| 1639 | - // Update the in_section field value | |
| 1640 | - function updateInSectionValue( fieldId, sectionId ) { | |
| 1641 | - document.getElementById( 'frm_in_section_' + fieldId ).value = sectionId; | |
| 1642 | - } | |
| 1643 | - | |
| 1644 | - /** | |
| 1645 | - * Add a new field by dragging and dropping it from the Fields sidebar | |
| 1646 | - * | |
| 1647 | - * @param {string} fieldType | |
| 1648 | - */ | |
| 1649 | - function insertNewFieldByDragging( fieldType ) { | |
| 1650 | - const placeholder = document.getElementById( 'frm_drag_placeholder' ); | |
| 1651 | - const loadingID = fieldType.replace( '|', '-' ) + '_' + getAutoId(); | |
| 1652 | - const loading = tag( | |
| 1653 | - 'li', | |
| 1654 | - { | |
| 1655 | - id: loadingID, | |
| 1656 | - className: 'frm-wait frmbutton_loadingnow' | |
| 1657 | - } | |
| 1658 | - ); | |
| 1659 | - const $placeholder = jQuery( loading ); | |
| 1660 | - const currentItem = jQuery( placeholder ); | |
| 1661 | - const section = getSectionForFieldPlacement( currentItem ); | |
| 1662 | - const formId = getFormIdForFieldPlacement( section ); | |
| 1663 | - const sectionId = getSectionIdForFieldPlacement( section ); | |
| 1664 | - | |
| 1665 | - placeholder.parentNode.insertBefore( loading, placeholder ); | |
| 1666 | - placeholder.remove(); | |
| 1667 | - syncLayoutClasses( $placeholder ); | |
| 1668 | - | |
| 1669 | - let hasBreak = 0; | |
| 1670 | - if ( 'summary' === fieldType ) { | |
| 1671 | - // see if we need to insert a page break before this newly-added summary field. Check for at least 1 page break | |
| 1672 | - hasBreak = jQuery( '.frmbutton_loadingnow#' + loadingID ).prevAll( 'li[data-type="break"]' ).length ? 1 : 0; | |
| 1673 | - } | |
| 1674 | - | |
| 1675 | - jQuery.ajax({ | |
| 1676 | - type: 'POST', url: ajaxurl, | |
| 1677 | - data: { | |
| 1678 | - action: 'frm_insert_field', | |
| 1679 | - form_id: formId, | |
| 1680 | - field_type: fieldType, | |
| 1681 | - section_id: sectionId, | |
| 1682 | - nonce: frmGlobal.nonce, | |
| 1683 | - has_break: hasBreak | |
| 1684 | - }, | |
| 1685 | - success: function( msg ) { | |
| 1686 | - let replaceWith; | |
| 1687 | - document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' ); | |
| 1688 | - const $siblings = $placeholder.siblings( 'li.form-field' ).not( '.edit_field_type_end_divider' ); | |
| 1689 | - if ( ! $siblings.length ) { | |
| 1690 | - // if dragging into a new row, we need to wrap the li first. | |
| 1691 | - replaceWith = wrapFieldLi( msg ); | |
| 1692 | - } else { | |
| 1693 | - replaceWith = msgAsjQueryObject( msg ); | |
| 1694 | - if ( ! $placeholder.get( 0 ).parentNode.parentNode.classList.contains( 'ui-draggable' ) ) { | |
| 1695 | - // If a field group wasn't draggable because it only had a single field, make it draggable. | |
| 1696 | - makeDraggable( $placeholder.get( 0 ).parentNode.parentNode, '.frm-move' ); | |
| 1697 | - } | |
| 1698 | - } | |
| 1699 | - $placeholder.replaceWith( replaceWith ); | |
| 1700 | - updateFieldOrder(); | |
| 1701 | - afterAddField( msg, false ); | |
| 1702 | - if ( $siblings.length ) { | |
| 1703 | - syncLayoutClasses( $siblings.first() ); | |
| 1704 | - } | |
| 1705 | - toggleSectionHolder(); | |
| 1706 | - | |
| 1707 | - if ( ! $siblings.length ) { | |
| 1708 | - makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) ); | |
| 1709 | - makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' ); | |
| 1710 | - } else { | |
| 1711 | - makeDraggable( replaceWith.get( 0 ), '.frm-move' ); | |
| 1712 | - } | |
| 1713 | - | |
| 1714 | - }, | |
| 1715 | - error: handleInsertFieldError | |
| 1716 | - }); | |
| 1717 | - } | |
| 1718 | - | |
| 1719 | - function moveFieldThatAlreadyExists( draggable, placeholder ) { | |
| 1720 | - placeholder.parentNode.insertBefore( draggable, placeholder ); | |
| 1721 | - } | |
| 1722 | - | |
| 1723 | - function msgAsjQueryObject( msg ) { | |
| 1724 | - const element = div(); | |
| 1725 | - element.innerHTML = msg; | |
| 1726 | - return jQuery( element.firstChild ); | |
| 1727 | - } | |
| 1728 | - | |
| 1729 | - function handleInsertFieldError( jqXHR, _, errorThrown ) { | |
| 1730 | - maybeShowInsertFieldError( errorThrown, jqXHR ); | |
| 1731 | - } | |
| 1732 | - | |
| 1733 | - function maybeShowInsertFieldError( errorThrown, jqXHR ) { | |
| 1734 | - if ( ! jqXHRAborted( jqXHR ) ) { | |
| 1735 | - infoModal( errorThrown + '. Please try again.' ); | |
| 1736 | - } | |
| 1737 | - } | |
| 1738 | - | |
| 1739 | - function jqXHRAborted( jqXHR ) { | |
| 1740 | - return jqXHR.status === 0 || jqXHR.readyState === 0; | |
| 1741 | - } | |
| 1742 | - | |
| 1743 | - /** | |
| 1744 | - * Get a unique id that automatically increments with every function call. | |
| 1745 | - * Can be used for any UI that requires a unique id. | |
| 1746 | - * Not to be used in data. | |
| 1747 | - * | |
| 1748 | - * @returns {integer} | |
| 1749 | - */ | |
| 1750 | - function getAutoId() { | |
| 1751 | - return ++autoId; | |
| 1752 | - } | |
| 1753 | - | |
| 1754 | - // Don't allow page break, embed form, or section inside section field | |
| 1755 | - // Don't allow page breaks inside of field groups. | |
| 1756 | - // Don't allow field groups with sections inside of sections. | |
| 1757 | - // Don't allow field groups in field groups. | |
| 1758 | - // Don't allow hidden fields inside of field groups but allow them in sections. | |
| 1759 | - function allowDrop( draggable, droppable ) { | |
| 1760 | - if ( false === droppable ) { | |
| 1761 | - // Don't show drop placeholder if dragging somewhere off of the droppable area. | |
| 1762 | - return false; | |
| 1763 | - } | |
| 1764 | - | |
| 1765 | - if ( droppable.closest( '.frm-sortable-helper' ) ) { | |
| 1766 | - // Do not allow drop into draggable. | |
| 1767 | - return false; | |
| 1768 | - } | |
| 1769 | - | |
| 1770 | - if ( 'frm-show-fields' === droppable.id ) { | |
| 1771 | - // Everything can be dropped into the main list of fields. | |
| 1772 | - return true; | |
| 1773 | - } | |
| 1774 | - | |
| 1775 | - if ( ! droppable.classList.contains( 'start_divider' ) ) { | |
| 1776 | - const $fieldsInRow = getFieldsInRow( jQuery( droppable ) ); | |
| 1777 | - if ( ! groupCanFitAnotherField( $fieldsInRow, jQuery( draggable ) ) ) { | |
| 1778 | - // Field group is full and cannot accept another field. | |
| 1779 | - return false; | |
| 1780 | - } | |
| 1781 | - } | |
| 1782 | - | |
| 1783 | - const isNewField = draggable.classList.contains( 'frm-new-field' ); | |
| 1784 | - if ( isNewField ) { | |
| 1785 | - return allowNewFieldDrop( draggable, droppable ); | |
| 1786 | - } | |
| 1787 | - | |
| 1788 | - return allowMoveField( draggable, droppable ); | |
| 1789 | - } | |
| 1790 | - | |
| 1791 | - // Don't allow a new page break or hidden field in a field group. | |
| 1792 | - // Don't allow a new field into a field group that includes a page break or hidden field. | |
| 1793 | - // Don't allow a new section inside of a section. | |
| 1794 | - // Don't allow an embedded form in a section. | |
| 1795 | - function allowNewFieldDrop( draggable, droppable ) { | |
| 1796 | - const classes = draggable.classList; | |
| 1797 | - const newPageBreakField = classes.contains( 'frm_tbreak' ); | |
| 1798 | - const newHiddenField = classes.contains( 'frm_thidden' ); | |
| 1799 | - const newSectionField = classes.contains( 'frm_tdivider' ); | |
| 1800 | - const newEmbedField = classes.contains( 'frm_tform' ); | |
| 1801 | - | |
| 1802 | - const newFieldWillBeAddedToAGroup = ! ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) ); | |
| 1803 | - if ( newFieldWillBeAddedToAGroup ) { | |
| 1804 | - if ( groupIncludesBreakOrHidden( droppable ) ) { | |
| 1805 | - // Never allow any field beside a page break or a hidden field. | |
| 1806 | - return false; | |
| 1807 | - } | |
| 1808 | - | |
| 1809 | - return ! newHiddenField && ! newPageBreakField; | |
| 1810 | - } | |
| 1811 | - | |
| 1812 | - const fieldTypeIsAlwaysAllowed = ! newPageBreakField && ! newHiddenField && ! newSectionField && ! newEmbedField; | |
| 1813 | - if ( fieldTypeIsAlwaysAllowed ) { | |
| 1814 | - return true; | |
| 1815 | - } | |
| 1816 | - | |
| 1817 | - const newFieldWillBeAddedToASection = droppable.classList.contains( 'start_divider' ) || null !== droppable.closest( '.start_divider' ); | |
| 1818 | - if ( newFieldWillBeAddedToASection ) { | |
| 1819 | - // Don't allow a section or an embedded form in a section. | |
| 1820 | - return ! newEmbedField && ! newSectionField; | |
| 1821 | - } | |
| 1822 | - | |
| 1823 | - return true; | |
| 1824 | - } | |
| 1825 | - | |
| 1826 | - function allowMoveField( draggable, droppable ) { | |
| 1827 | - if ( isFieldGroup( draggable ) ) { | |
| 1828 | - return allowMoveFieldGroup( draggable, droppable ); | |
| 1829 | - } | |
| 1830 | - | |
| 1831 | - const isPageBreak = draggable.classList.contains( 'edit_field_type_break' ); | |
| 1832 | - if ( isPageBreak ) { | |
| 1833 | - // Page breaks are only allowed in the main list of fields, not in sections or in field groups. | |
| 1834 | - return false; | |
| 1835 | - } | |
| 1836 | - | |
| 1837 | - if ( droppable.classList.contains( 'start_divider' ) ) { | |
| 1838 | - return allowMoveFieldToSection( draggable ); | |
| 1839 | - } | |
| 1840 | - | |
| 1841 | - const isHiddenField = draggable.classList.contains( 'edit_field_type_hidden' ); | |
| 1842 | - if ( isHiddenField ) { | |
| 1843 | - // Hidden fields should not be added to field groups since they're not shown and don't make sense with the grid distribution. | |
| 1844 | - return false; | |
| 1845 | - } | |
| 1846 | - | |
| 1847 | - return allowMoveFieldToGroup( draggable, droppable ); | |
| 1848 | - } | |
| 1849 | - | |
| 1850 | - function isFieldGroup( draggable ) { | |
| 1851 | - return draggable.classList.contains( 'frm_field_box' ) && ! draggable.classList.contains( 'form-field' ); | |
| 1852 | - } | |
| 1853 | - | |
| 1854 | - function allowMoveFieldGroup( fieldGroup, droppable ) { | |
| 1855 | - if ( droppable.classList.contains( 'start_divider' ) && null === fieldGroup.querySelector( '.start_divider' ) ) { | |
| 1856 | - // Allow a field group with no section inside of a section. | |
| 1857 | - return true; | |
| 1858 | - } | |
| 1859 | - return false; | |
| 1860 | - } | |
| 1861 | - | |
| 1862 | - function allowMoveFieldToSection( draggable ) { | |
| 1863 | - const draggableIncludeEmbedForm = draggable.classList.contains( 'edit_field_type_form' ) || draggable.querySelector( '.edit_field_type_form' ); | |
| 1864 | - if ( draggableIncludeEmbedForm ) { | |
| 1865 | - // Do not allow an embedded form inside of a section. | |
| 1866 | - return false; | |
| 1867 | - } | |
| 1868 | - | |
| 1869 | - const draggableIncludesSection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' ); | |
| 1870 | - if ( draggableIncludesSection ) { | |
| 1871 | - // Do not allow a section inside of a section. | |
| 1872 | - return false; | |
| 1873 | - } | |
| 1874 | - | |
| 1875 | - return true; | |
| 1876 | - } | |
| 1877 | - | |
| 1878 | - function allowMoveFieldToGroup( draggable, group ) { | |
| 1879 | - if ( groupIncludesBreakOrHidden( group ) ) { | |
| 1880 | - // Never allow any field beside a page break or a hidden field. | |
| 1881 | - return false; | |
| 1882 | - } | |
| 1883 | - | |
| 1884 | - const isFieldGroup = jQuery( draggable ).children( 'ul.frm_sorting' ).not( '.start_divider' ).length > 0; | |
| 1885 | - if ( isFieldGroup ) { | |
| 1886 | - // Do not allow a field group directly inside of a field group unless it's in a section. | |
| 1887 | - return false; | |
| 1888 | - } | |
| 1889 | - | |
| 1890 | - const draggableIncludesASection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' ); | |
| 1891 | - const draggableIsEmbedField = draggable.classList.contains( 'edit_field_type_form' ); | |
| 1892 | - const groupIsInASection = null !== group.closest( '.start_divider' ); | |
| 1893 | - if ( groupIsInASection && ( draggableIncludesASection || draggableIsEmbedField ) ) { | |
| 1894 | - // Do not allow a section or an embed field inside of a section. | |
| 1895 | - return false; | |
| 1896 | - } | |
| 1897 | - | |
| 1898 | - return true; | |
| 1899 | - } | |
| 1900 | - | |
| 1901 | - function groupIncludesBreakOrHidden( group ) { | |
| 1902 | - return null !== group.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ); | |
| 1903 | - } | |
| 1904 | - | |
| 1905 | - function groupCanFitAnotherField( fieldsInRow, $field ) { | |
| 1906 | - var fieldId; | |
| 1907 | - if ( fieldsInRow.length < 6 ) { | |
| 1908 | - return true; | |
| 1909 | - } | |
| 1910 | - if ( fieldsInRow.length > 6 ) { | |
| 1911 | - return false; | |
| 1912 | - } | |
| 1913 | - fieldId = $field.attr( 'data-fid' ); | |
| 1914 | - // allow 6 if we're not changing field groups. | |
| 1915 | - return 1 === jQuery( fieldsInRow ).filter( '[data-fid="' + fieldId + '"]' ).length; | |
| 1916 | - } | |
| 1917 | - | |
| 1918 | - function loadFields( fieldId ) { | |
| 1919 | - const thisField = document.getElementById( fieldId ); | |
| 1920 | - const $thisField = jQuery( thisField ); | |
| 1921 | - const field = []; | |
| 1922 | - const addHtmlToField = element => { | |
| 1923 | - const frmHiddenFdata = element.querySelector( '.frm_hidden_fdata' ); | |
| 1924 | - element.classList.add( 'frm_load_now' ); | |
| 1925 | - if ( frmHiddenFdata !== null ) { | |
| 1926 | - field.push( frmHiddenFdata.innerHTML ); | |
| 1927 | - } | |
| 1928 | - }; | |
| 1929 | - | |
| 1930 | - let nextElement = thisField; | |
| 1931 | - addHtmlToField( nextElement ); | |
| 1932 | - while ( nextElement.nextElementSibling && field.length < 15 ) { | |
| 1933 | - addHtmlToField( nextElement.nextElementSibling ); | |
| 1934 | - nextElement = nextElement.nextElementSibling; | |
| 1935 | - } | |
| 1936 | - | |
| 1937 | - jQuery.ajax({ | |
| 1938 | - type: 'POST', | |
| 1939 | - url: ajaxurl, | |
| 1940 | - data: { | |
| 1941 | - action: 'frm_load_field', | |
| 1942 | - field: field, | |
| 1943 | - form_id: thisFormId, | |
| 1944 | - nonce: frmGlobal.nonce | |
| 1945 | - }, | |
| 1946 | - success: html => handleAjaxLoadFieldSuccess( html, $thisField, field ) | |
| 1947 | - }); | |
| 1948 | - } | |
| 1949 | - | |
| 1950 | - function handleAjaxLoadFieldSuccess( html, $thisField, field ) { | |
| 1951 | - let key, $nextSet; | |
| 1952 | - | |
| 1953 | - html = html.replace( /^\s+|\s+$/g, '' ); | |
| 1954 | - if ( html.indexOf( '{' ) !== 0 ) { | |
| 1955 | - jQuery( '.frm_load_now' ).removeClass( '.frm_load_now' ).html( 'Error' ); | |
| 1956 | - return; | |
| 1957 | - } | |
| 1958 | - | |
| 1959 | - html = JSON.parse( html ); | |
| 1960 | - for ( key in html ) { | |
| 1961 | - jQuery( '#frm_field_id_' + key ).replaceWith( html[key]); | |
| 1962 | - setupSortable( '#frm_field_id_' + key + '.edit_field_type_divider ul.frm_sorting' ); | |
| 1963 | - makeDraggable( document.getElementById( 'frm_field_id_' + key ) ); | |
| 1964 | - } | |
| 1965 | - | |
| 1966 | - $nextSet = $thisField.nextAll( '.frm_field_loading:not(.frm_load_now)' ); | |
| 1967 | - if ( $nextSet.length ) { | |
| 1968 | - loadFields( $nextSet.attr( 'id' ) ); | |
| 1969 | - } else { | |
| 1970 | - // go up a level | |
| 1971 | - $nextSet = jQuery( document.getElementById( 'frm-show-fields' ) ).find( '.frm_field_loading:not(.frm_load_now)' ); | |
| 1972 | - if ( $nextSet.length ) { | |
| 1973 | - loadFields( $nextSet.attr( 'id' ) ); | |
| 1974 | - } | |
| 1975 | - } | |
| 1976 | - | |
| 1977 | - initiateMultiselect(); | |
| 1978 | - renumberPageBreaks(); | |
| 1979 | - maybeHideQuantityProductFieldOption(); | |
| 1980 | - | |
| 1981 | - const loadedEvent = new Event( 'frm_ajax_loaded_field', { bubbles: false }); | |
| 1982 | - loadedEvent.frmFields = field.map( f => JSON.parse( f ) ); | |
| 1983 | - document.dispatchEvent( loadedEvent ); | |
| 1984 | - } | |
| 1985 | - | |
| 1986 | - function addFieldClick() { | |
| 1987 | - /*jshint validthis:true */ | |
| 1988 | - const $thisObj = jQuery( this ); | |
| 1989 | - // there is no real way to disable a <a> (with a valid href attribute) in HTML - https://css-tricks.com/how-to-disable-links/ | |
| 1990 | - if ( $thisObj.hasClass( 'disabled' ) ) { | |
| 1991 | - return false; | |
| 1992 | - } | |
| 1993 | - | |
| 1994 | - const $button = $thisObj.closest( '.frmbutton' ); | |
| 1995 | - const fieldType = $button.attr( 'id' ); | |
| 1996 | - | |
| 1997 | - let hasBreak = 0; | |
| 1998 | - if ( 'summary' === fieldType ) { | |
| 1999 | - hasBreak = $newFields.children( 'li[data-type="break"]' ).length > 0 ? 1 : 0; | |
| 2000 | - } | |
| 2001 | - | |
| 2002 | - const formId = thisFormId; | |
| 2003 | - jQuery.ajax({ | |
| 2004 | - type: 'POST', | |
| 2005 | - url: ajaxurl, | |
| 2006 | - data: { | |
| 2007 | - action: 'frm_insert_field', | |
| 2008 | - form_id: formId, | |
| 2009 | - field_type: fieldType, | |
| 2010 | - section_id: 0, | |
| 2011 | - nonce: frmGlobal.nonce, | |
| 2012 | - has_break: hasBreak | |
| 2013 | - }, | |
| 2014 | - success: function( msg ) { | |
| 2015 | - document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' ); | |
| 2016 | - const replaceWith = wrapFieldLi( msg ); | |
| 2017 | - $newFields.append( replaceWith ); | |
| 2018 | - afterAddField( msg, true ); | |
| 2019 | - | |
| 2020 | - replaceWith.each( | |
| 2021 | - function() { | |
| 2022 | - makeDroppable( this.querySelector( 'ul.frm_sorting' ) ); | |
| 2023 | - makeDraggable( this.querySelector( '.form-field' ), '.frm-move' ); | |
| 2024 | - } | |
| 2025 | - ); | |
| 2026 | - }, | |
| 2027 | - error: handleInsertFieldError | |
| 2028 | - }); | |
| 2029 | - return false; | |
| 2030 | - } | |
| 2031 | - | |
| 2032 | - function maybeHideQuantityProductFieldOption() { | |
| 2033 | - var hide = true, | |
| 2034 | - opts = document.querySelectorAll( '.frmjs_prod_field_opt_cont' ); | |
| 2035 | - | |
| 2036 | - if ( $newFields.find( 'li.edit_field_type_product' ).length > 1 ) { | |
| 2037 | - hide = false; | |
| 2038 | - } | |
| 2039 | - | |
| 2040 | - for ( var i = 0; i < opts.length; i++ ) { | |
| 2041 | - if ( hide ) { | |
| 2042 | - opts[ i ].classList.add( 'frm_hidden' ); | |
| 2043 | - } else { | |
| 2044 | - opts[ i ].classList.remove( 'frm_hidden' ); | |
| 2045 | - } | |
| 2046 | - } | |
| 2047 | - } | |
| 2048 | - | |
| 2049 | - function duplicateField() { | |
| 2050 | - var $field, fieldId, children, newRowId, fieldOrder; | |
| 2051 | - | |
| 2052 | - $field = jQuery( this ).closest( 'li.form-field' ); | |
| 2053 | - | |
| 2054 | - if ( $field.hasClass( 'frm-page-collapsed' ) ) { | |
| 2055 | - return false; | |
| 2056 | - } | |
| 2057 | - | |
| 2058 | - closeOpenFieldDropdowns(); | |
| 2059 | - fieldId = $field.data( 'fid' ); | |
| 2060 | - children = fieldsInSection( fieldId ); | |
| 2061 | - newRowId = this.getAttribute( 'frm-target-row-id' ); | |
| 2062 | - | |
| 2063 | - if ( null !== newRowId ) { | |
| 2064 | - fieldOrder = this.getAttribute( 'frm-field-order' ); | |
| 2065 | - } | |
| 2066 | - | |
| 2067 | - jQuery.ajax({ | |
| 2068 | - type: 'POST', | |
| 2069 | - url: ajaxurl, | |
| 2070 | - data: { | |
| 2071 | - action: 'frm_duplicate_field', | |
| 2072 | - field_id: fieldId, | |
| 2073 | - form_id: thisFormId, | |
| 2074 | - children: children, | |
| 2075 | - nonce: frmGlobal.nonce | |
| 2076 | - }, | |
| 2077 | - success: function( msg ) { | |
| 2078 | - var newRow; | |
| 2079 | - | |
| 2080 | - let replaceWith; | |
| 2081 | - | |
| 2082 | - if ( null !== newRowId ) { | |
| 2083 | - newRow = document.getElementById( newRowId ); | |
| 2084 | - if ( null !== newRow ) { | |
| 2085 | - replaceWith = msgAsjQueryObject( msg ); | |
| 2086 | - jQuery( newRow ).append( replaceWith ); | |
| 2087 | - makeDraggable( replaceWith.get( 0 ), '.frm-move' ); | |
| 2088 | - if ( null !== fieldOrder ) { | |
| 2089 | - newRow.lastElementChild.setAttribute( 'frm-field-order', fieldOrder ); | |
| 2090 | - } | |
| 2091 | - jQuery( newRow ).trigger( | |
| 2092 | - 'frm_added_duplicated_field_to_row', | |
| 2093 | - { | |
| 2094 | - duplicatedFieldHtml: msg, | |
| 2095 | - originalFieldId: fieldId | |
| 2096 | - } | |
| 2097 | - ); | |
| 2098 | - afterAddField( msg, false ); | |
| 2099 | - return; | |
| 2100 | - } | |
| 2101 | - } | |
| 2102 | - | |
| 2103 | - if ( $field.siblings( 'li.form-field' ).length ) { | |
| 2104 | - replaceWith = msgAsjQueryObject( msg ); | |
| 2105 | - $field.after( replaceWith ); | |
| 2106 | - syncLayoutClasses( $field ); | |
| 2107 | - makeDraggable( replaceWith.get( 0 ), '.frm-move' ); | |
| 2108 | - } else { | |
| 2109 | - replaceWith = wrapFieldLi( msg ); | |
| 2110 | - $field.parent().parent().after( replaceWith ); | |
| 2111 | - makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) ); | |
| 2112 | - makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' ); | |
| 2113 | - } | |
| 2114 | - | |
| 2115 | - updateFieldOrder(); | |
| 2116 | - afterAddField( msg, false ); | |
| 2117 | - maybeDuplicateUnsavedSettings( fieldId, msg ); | |
| 2118 | - toggleOneSectionHolder( replaceWith.find( '.start_divider' ) ); | |
| 2119 | - $field[0].querySelector( '.frm-dropdown-menu.dropdown-menu-right' )?.classList.remove( 'show' ); | |
| 2120 | - } | |
| 2121 | - }); | |
| 2122 | - return false; | |
| 2123 | - } | |
| 2124 | - | |
| 2125 | - function maybeDuplicateUnsavedSettings( originalFieldId, newFieldHtml ) { | |
| 2126 | - var originalSettings, newFieldId, copySettings, fieldOptionKeys, originalDefault, copyDefault; | |
| 2127 | - | |
| 2128 | - originalSettings = document.getElementById( 'frm-single-settings-' + originalFieldId ); | |
| 2129 | - if ( null === originalSettings ) { | |
| 2130 | - return; | |
| 2131 | - } | |
| 2132 | - | |
| 2133 | - newFieldId = jQuery( newFieldHtml ).attr( 'data-fid' ); | |
| 2134 | - if ( 'undefined' === typeof newFieldId ) { | |
| 2135 | - return; | |
| 2136 | - } | |
| 2137 | - | |
| 2138 | - copySettings = document.getElementById( 'frm-single-settings-' + newFieldId ); | |
| 2139 | - if ( null === copySettings ) { | |
| 2140 | - return; | |
| 2141 | - } | |
| 2142 | - | |
| 2143 | - fieldOptionKeys = [ | |
| 2144 | - 'name', 'required', 'unique', 'read_only', 'placeholder', 'description', 'size', 'max', 'format', 'prepend', 'append', 'separate_value' | |
| 2145 | - ]; | |
| 2146 | - | |
| 2147 | - originalSettings.querySelectorAll( 'input[name^="field_options["], textarea[name^="field_options["]' ).forEach( | |
| 2148 | - function( originalSetting ) { | |
| 2149 | - var key, tagType, copySetting; | |
| 2150 | - | |
| 2151 | - key = getKeyFromSettingInput( originalSetting ); | |
| 2152 | - | |
| 2153 | - if ( 'options' === key ) { | |
| 2154 | - copyOption( originalSetting, copySettings, originalFieldId, newFieldId ); | |
| 2155 | - return; | |
| 2156 | - } | |
| 2157 | - | |
| 2158 | - if ( -1 === fieldOptionKeys.indexOf( key ) ) { | |
| 2159 | - return; | |
| 2160 | - } | |
| 2161 | - | |
| 2162 | - tagType = originalSetting.matches( 'input' ) ? 'input' : 'textarea'; | |
| 2163 | - copySetting = copySettings.querySelector( tagType + '[name="field_options[' + key + '_' + newFieldId + ']"]' ); | |
| 2164 | - if ( null === copySetting ) { | |
| 2165 | - return; | |
| 2166 | - } | |
| 2167 | - | |
| 2168 | - if ( 'checkbox' === originalSetting.type ) { | |
| 2169 | - if ( originalSetting.checked !== copySetting.checked ) { | |
| 2170 | - jQuery( copySetting ).trigger( 'click' ); | |
| 2171 | - } | |
| 2172 | - } else if ( 'text' === originalSetting.type || 'textarea' === tagType ) { | |
| 2173 | - if ( originalSetting.value !== copySetting.value ) { | |
| 2174 | - copySetting.value = originalSetting.value; | |
| 2175 | - jQuery( copySetting ).trigger( 'change' ); | |
| 2176 | - } | |
| 2177 | - } | |
| 2178 | - } | |
| 2179 | - ); | |
| 2180 | - | |
| 2181 | - originalDefault = originalSettings.querySelector( 'input[name="default_value_' + originalFieldId + '"]' ); | |
| 2182 | - if ( null !== originalDefault ) { | |
| 2183 | - copyDefault = copySettings.querySelector( 'input[name="default_value_' + newFieldId + '"]' ); | |
| 2184 | - if ( null !== copyDefault && originalDefault.value !== copyDefault.value ) { | |
| 2185 | - copyDefault.value = originalDefault.value; | |
| 2186 | - jQuery( copyDefault ).trigger( 'change' ); | |
| 2187 | - } | |
| 2188 | - } | |
| 2189 | - } | |
| 2190 | - | |
| 2191 | - function copyOption( originalSetting, copySettings, originalFieldId, newFieldId ) { | |
| 2192 | - var remainingKeyDetails, copyKey, copySetting; | |
| 2193 | - remainingKeyDetails = originalSetting.name.substr( 23 + ( '' + originalFieldId ).length ); | |
| 2194 | - copyKey = 'field_options[options_' + newFieldId + ']' + remainingKeyDetails; | |
| 2195 | - copySetting = copySettings.querySelector( 'input[name="' + copyKey + '"]' ); | |
| 2196 | - if ( null !== copySetting && copySetting.value !== originalSetting.value ) { | |
| 2197 | - copySetting.value = originalSetting.value; | |
| 2198 | - jQuery( copySetting ).trigger( 'change' ); | |
| 2199 | - } | |
| 2200 | - } | |
| 2201 | - | |
| 2202 | - function getKeyFromSettingInput( input ) { | |
| 2203 | - var nameWithoutPrefix, nameSplit; | |
| 2204 | - nameWithoutPrefix = input.name.substr( 14 ); | |
| 2205 | - nameSplit = nameWithoutPrefix.split( '_' ); | |
| 2206 | - nameSplit.pop(); | |
| 2207 | - return nameSplit.join( '_' ); | |
| 2208 | - } | |
| 2209 | - | |
| 2210 | - function closeOpenFieldDropdowns() { | |
| 2211 | - var openSettings = document.querySelector( '.frm-field-settings-open' ); | |
| 2212 | - if ( null !== openSettings ) { | |
| 2213 | - openSettings.classList.remove( 'frm-field-settings-open' ); | |
| 2214 | - jQuery( document ).off( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings ); | |
| 2215 | - jQuery( '.frm-field-action-icons .dropdown.open' ).removeClass( 'open' ); | |
| 2216 | - } | |
| 2217 | - } | |
| 2218 | - | |
| 2219 | - function handleClickOutsideOfFieldSettings( event ) { | |
| 2220 | - if ( ! jQuery( event.originalEvent.target ).closest( '.frm-field-action-icons' ).length ) { | |
| 2221 | - closeOpenFieldDropdowns(); | |
| 2222 | - } | |
| 2223 | - } | |
| 2224 | - | |
| 2225 | - function checkForMultiselectKeysOnMouseMove( event ) { | |
| 2226 | - var keyIsDown = ! ! ( event.ctrlKey || event.metaKey || event.shiftKey ); | |
| 2227 | - jQuery( document.getElementById( 'frm_builder_page' ) ).toggleClass( 'frm-multiselect-key-is-down', keyIsDown ); | |
| 2228 | - checkForActiveHoverTarget( event ); | |
| 2229 | - } | |
| 2230 | - | |
| 2231 | - function checkForActiveHoverTarget( event ) { | |
| 2232 | - var container, elementFromPoint, list, previousHoverTarget; | |
| 2233 | - | |
| 2234 | - container = postBodyContent; | |
| 2235 | - if ( container.classList.contains( 'frm-dragging-field' ) ) { | |
| 2236 | - return; | |
| 2237 | - } | |
| 2238 | - | |
| 2239 | - if ( null !== document.querySelector( '.frm-field-group-hover-target .frm-field-settings-open' ) ) { | |
| 2240 | - // do not set a hover target if a dropdown is open for the current hover target. | |
| 2241 | - return; | |
| 2242 | - } | |
| 2243 | - | |
| 2244 | - elementFromPoint = document.elementFromPoint( event.clientX, event.clientY ); | |
| 2245 | - if ( null !== elementFromPoint && ! elementFromPoint.classList.contains( 'edit_field_type_divider' ) ) { | |
| 2246 | - | |
| 2247 | - list = elementFromPoint.closest( 'ul.frm_sorting' ); | |
| 2248 | - | |
| 2249 | - if ( null !== list && ! list.classList.contains( 'start_divider' ) && 'frm-show-fields' !== list.id ) { | |
| 2250 | - previousHoverTarget = maybeRemoveGroupHoverTarget(); | |
| 2251 | - if ( false !== previousHoverTarget && ! jQuery( previousHoverTarget ).is( list ) ) { | |
| 2252 | - destroyFieldGroupPopup(); | |
| 2253 | - } | |
| 2254 | - updateFieldGroupControls( jQuery( list ), getFieldsInRow( jQuery( list ) ).length ); | |
| 2255 | - list.classList.add( 'frm-field-group-hover-target' ); | |
| 2256 | - jQuery( '#wpbody-content' ).on( 'mousemove', maybeRemoveHoverTargetOnMouseMove ); | |
| 2257 | - } | |
| 2258 | - } | |
| 2259 | - } | |
| 2260 | - | |
| 2261 | - function maybeRemoveGroupHoverTarget() { | |
| 2262 | - var controls, previousHoverTarget; | |
| 2263 | - | |
| 2264 | - controls = document.getElementById( 'frm_field_group_controls' ); | |
| 2265 | - if ( null !== controls ) { | |
| 2266 | - controls.style.display = 'none'; | |
| 2267 | - } | |
| 2268 | - | |
| 2269 | - previousHoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 2270 | - if ( null === previousHoverTarget ) { | |
| 2271 | - return false; | |
| 2272 | - } | |
| 2273 | - | |
| 2274 | - jQuery( '#wpbody-content' ).off( 'mousemove', maybeRemoveHoverTargetOnMouseMove ); | |
| 2275 | - previousHoverTarget.classList.remove( 'frm-field-group-hover-target' ); | |
| 2276 | - return previousHoverTarget; | |
| 2277 | - } | |
| 2278 | - | |
| 2279 | - function maybeRemoveHoverTargetOnMouseMove( event ) { | |
| 2280 | - var elementFromPoint = document.elementFromPoint( event.clientX, event.clientY ); | |
| 2281 | - if ( null !== elementFromPoint && null !== elementFromPoint.closest( '#frm-show-fields' ) ) { | |
| 2282 | - return; | |
| 2283 | - } | |
| 2284 | - maybeRemoveGroupHoverTarget(); | |
| 2285 | - } | |
| 2286 | - | |
| 2287 | - function onFieldActionDropdownShow( isFieldGroup ) { | |
| 2288 | - unselectFieldGroups(); | |
| 2289 | - // maybe offset the dropdown if it goes off of the right of the screen. | |
| 2290 | - setTimeout( | |
| 2291 | - function() { | |
| 2292 | - var ul, $ul; | |
| 2293 | - ul = document.querySelector( '.dropdown.show .frm-dropdown-menu' ); | |
| 2294 | - if ( null === ul ) { | |
| 2295 | - return; | |
| 2296 | - } | |
| 2297 | - if ( null === ul.getAttribute( 'aria-label' ) ) { | |
| 2298 | - ul.setAttribute( 'aria-label', __( 'More Options', 'formidable' ) ); | |
| 2299 | - } | |
| 2300 | - if ( 0 === ul.children.length ) { | |
| 2301 | - fillFieldActionDropdown( ul, true === isFieldGroup ); | |
| 2302 | - } | |
| 2303 | - $ul = jQuery( ul ); | |
| 2304 | - if ( $ul.offset().left > jQuery( window ).width() - $ul.outerWidth() ) { | |
| 2305 | - ul.style.left = ( -$ul.outerWidth() ) + 'px'; | |
| 2306 | - } | |
| 2307 | - const firstAnchor = ul.firstElementChild.querySelector( 'a' ); | |
| 2308 | - if ( firstAnchor ) { | |
| 2309 | - firstAnchor.focus(); | |
| 2310 | - } | |
| 2311 | - }, | |
| 2312 | - 0 | |
| 2313 | - ); | |
| 2314 | - } | |
| 2315 | - | |
| 2316 | - function onFieldGroupActionDropdownShow() { | |
| 2317 | - onFieldActionDropdownShow( true ); | |
| 2318 | - } | |
| 2319 | - | |
| 2320 | - function changeSectionStyle( e ) { | |
| 2321 | - const collapsedSection = e.target.closest( '.frm-section-collapsed' ); | |
| 2322 | - if ( ! collapsedSection ) { | |
| 2323 | - return; | |
| 2324 | - } | |
| 2325 | - | |
| 2326 | - if ( e.type === 'show' ) { | |
| 2327 | - collapsedSection.style.zIndex = 3; | |
| 2328 | - } else { | |
| 2329 | - collapsedSection.style.zIndex = 1; | |
| 2330 | - } | |
| 2331 | - } | |
| 2332 | - | |
| 2333 | - function fillFieldActionDropdown( ul, isFieldGroup ) { | |
| 2334 | - var classSuffix, options; | |
| 2335 | - classSuffix = isFieldGroup ? '_field_group' : '_field'; | |
| 2336 | - options = [ getDeleteActionOption( isFieldGroup ), getDuplicateActionOption( isFieldGroup ) ]; | |
| 2337 | - if ( ! isFieldGroup ) { | |
| 2338 | - options.push( | |
| 2339 | - { class: 'frm_select', icon: 'frm_settings_icon', label: __( 'Field Settings', 'formidable' ) } | |
| 2340 | - ); | |
| 2341 | - } | |
| 2342 | - options.forEach( | |
| 2343 | - function( option ) { | |
| 2344 | - var li, anchor, span; | |
| 2345 | - li = document.createElement( 'div' ); | |
| 2346 | - li.classList.add( 'frm_more_options_li', 'dropdown-item' ); | |
| 2347 | - | |
| 2348 | - anchor = document.createElement( 'a' ); | |
| 2349 | - anchor.classList.add( option.class + classSuffix ); | |
| 2350 | - anchor.setAttribute( 'href', '#' ); | |
| 2351 | - makeTabbable( anchor ); | |
| 2352 | - | |
| 2353 | - span = document.createElement( 'span' ); | |
| 2354 | - span.textContent = option.label; | |
| 2355 | - anchor.innerHTML = '<svg class="frmsvg"><use xlink:href="#' + option.icon + '"></use></svg>'; | |
| 2356 | - anchor.appendChild( document.createTextNode( ' ' ) ); | |
| 2357 | - anchor.appendChild( span ); | |
| 2358 | - | |
| 2359 | - li.appendChild( anchor ); | |
| 2360 | - ul.appendChild( li ); | |
| 2361 | - } | |
| 2362 | - ); | |
| 2363 | - } | |
| 2364 | - | |
| 2365 | - function getDeleteActionOption( isFieldGroup ) { | |
| 2366 | - var option = { class: 'frm_delete', icon: 'frm_delete_icon' }; | |
| 2367 | - option.label = isFieldGroup ? __( 'Delete Group', 'formidable' ) : __( 'Delete', 'formidable' ); | |
| 2368 | - return option; | |
| 2369 | - } | |
| 2370 | - | |
| 2371 | - function getDuplicateActionOption( isFieldGroup ) { | |
| 2372 | - var option = { class: 'frm_clone', icon: 'frm_clone_icon' }; | |
| 2373 | - option.label = isFieldGroup ? __( 'Duplicate Group', 'formidable' ) : __( 'Duplicate', 'formidable' ); | |
| 2374 | - return option; | |
| 2375 | - } | |
| 2376 | - | |
| 2377 | - function wrapFieldLi( field ) { | |
| 2378 | - const wrapper = div(); | |
| 2379 | - | |
| 2380 | - if ( 'string' === typeof field ) { | |
| 2381 | - wrapper.innerHTML = field; | |
| 2382 | - } else { | |
| 2383 | - wrapper.appendChild( field ); | |
| 2384 | - } | |
| 2385 | - | |
| 2386 | - let result = jQuery(); | |
| 2387 | - Array.from( wrapper.children ).forEach( | |
| 2388 | - li => { | |
| 2389 | - result = result.add( | |
| 2390 | - jQuery( '<li>' ) | |
| 2391 | - .addClass( 'frm_field_box' ) | |
| 2392 | - .html( | |
| 2393 | - jQuery( '<ul>' ).addClass( 'frm_grid_container frm_sorting' ).append( li ) | |
| 2394 | - ) | |
| 2395 | - ); | |
| 2396 | - } | |
| 2397 | - ); | |
| 2398 | - | |
| 2399 | - return result; | |
| 2400 | - } | |
| 2401 | - | |
| 2402 | - function wrapFieldLiInPlace( li ) { | |
| 2403 | - const ul = tag( | |
| 2404 | - 'ul', | |
| 2405 | - { | |
| 2406 | - className: 'frm_grid_container frm_sorting' | |
| 2407 | - } | |
| 2408 | - ); | |
| 2409 | - const wrapper = tag( | |
| 2410 | - 'li', | |
| 2411 | - { | |
| 2412 | - className: 'frm_field_box', | |
| 2413 | - child: ul | |
| 2414 | - } | |
| 2415 | - ); | |
| 2416 | - | |
| 2417 | - li.replaceWith( wrapper ); | |
| 2418 | - ul.appendChild( li ); | |
| 2419 | - | |
| 2420 | - makeDroppable( ul ); | |
| 2421 | - makeDraggable( wrapper, '.frm-move' ); | |
| 2422 | - } | |
| 2423 | - | |
| 2424 | - function afterAddField( msg, addFocus ) { | |
| 2425 | - var regex = /id="(\S+)"/, | |
| 2426 | - match = regex.exec( msg ), | |
| 2427 | - field = document.getElementById( match[1]), | |
| 2428 | - section = '#' + match[1] + '.edit_field_type_divider ul.frm_sorting.start_divider', | |
| 2429 | - $thisSection = jQuery( section ), | |
| 2430 | - type = field.getAttribute( 'data-type' ), | |
| 2431 | - toggled = false, | |
| 2432 | - $parentSection; | |
| 2433 | - | |
| 2434 | - setupSortable( section ); | |
| 2435 | - | |
| 2436 | - if ( 'quantity' === type ) { | |
| 2437 | - // try to automatically attach a product field | |
| 2438 | - maybeSetProductField( field ); | |
| 2439 | - } | |
| 2440 | - | |
| 2441 | - if ( 'product' === type || 'quantity' === type ) { | |
| 2442 | - // quantity too needs to be a part of the if stmt especially cos of the very | |
| 2443 | - // 1st quantity field (or even if it's just one quantity field in the form). | |
| 2444 | - maybeHideQuantityProductFieldOption(); | |
| 2445 | - } | |
| 2446 | - | |
| 2447 | - if ( $thisSection.length ) { | |
| 2448 | - $thisSection.parent( '.frm_field_box' ).children( '.frm_no_section_fields' ).addClass( 'frm_block' ); | |
| 2449 | - } else { | |
| 2450 | - $parentSection = jQuery( field ).closest( 'ul.frm_sorting.start_divider' ); | |
| 2451 | - if ( $parentSection.length ) { | |
| 2452 | - toggleOneSectionHolder( $parentSection ); | |
| 2453 | - toggled = true; | |
| 2454 | - } | |
| 2455 | - } | |
| 2456 | - | |
| 2457 | - if ( msg.indexOf( 'frm-collapse-page' ) !== -1 ) { | |
| 2458 | - renumberPageBreaks(); | |
| 2459 | - } | |
| 2460 | - | |
| 2461 | - addClass( field, 'frm-newly-added' ); | |
| 2462 | - setTimeout( function() { | |
| 2463 | - field.classList.remove( 'frm-newly-added' ); | |
| 2464 | - }, 1000 ); | |
| 2465 | - | |
| 2466 | - if ( addFocus ) { | |
| 2467 | - var bounding = field.getBoundingClientRect(), | |
| 2468 | - container = document.getElementById( 'post-body-content' ), | |
| 2469 | - inView = ( bounding.top >= 0 && | |
| 2470 | - bounding.left >= 0 && | |
| 2471 | - bounding.right <= ( window.innerWidth || document.documentElement.clientWidth ) && | |
| 2472 | - bounding.bottom <= ( window.innerHeight || document.documentElement.clientHeight ) | |
| 2473 | - ); | |
| 2474 | - | |
| 2475 | - if ( ! inView ) { | |
| 2476 | - container.scroll({ | |
| 2477 | - top: container.scrollHeight, | |
| 2478 | - left: 0, | |
| 2479 | - behavior: 'smooth' | |
| 2480 | - }); | |
| 2481 | - } | |
| 2482 | - | |
| 2483 | - if ( toggled === false ) { | |
| 2484 | - toggleOneSectionHolder( $thisSection ); | |
| 2485 | - } | |
| 2486 | - } | |
| 2487 | - | |
| 2488 | - deselectFields(); | |
| 2489 | - initiateMultiselect(); | |
| 2490 | - | |
| 2491 | - const addedEvent = new Event( 'frm_added_field', { bubbles: false }); | |
| 2492 | - addedEvent.frmField = field; | |
| 2493 | - addedEvent.frmSection = section; | |
| 2494 | - addedEvent.frmType = type; | |
| 2495 | - addedEvent.frmToggles = toggled; | |
| 2496 | - document.dispatchEvent( addedEvent ); | |
| 2497 | - } | |
| 2498 | - | |
| 2499 | - function clearSettingsBox( preventFieldGroups ) { | |
| 2500 | - jQuery( '#new_fields .frm-single-settings' ).addClass( 'frm_hidden' ); | |
| 2501 | - jQuery( '#frm-options-panel > .frm-single-settings' ).removeClass( 'frm_hidden' ); | |
| 2502 | - deselectFields( preventFieldGroups ); | |
| 2503 | - } | |
| 2504 | - | |
| 2505 | - function deselectFields( preventFieldGroups ) { | |
| 2506 | - jQuery( 'li.ui-state-default.selected' ).removeClass( 'selected' ); | |
| 2507 | - if ( ! preventFieldGroups ) { | |
| 2508 | - unselectFieldGroups(); | |
| 2509 | - } | |
| 2510 | - } | |
| 2511 | - | |
| 2512 | - function scrollToField( field ) { | |
| 2513 | - var newPos = field.getBoundingClientRect().top, | |
| 2514 | - container = document.getElementById( 'post-body-content' ); | |
| 2515 | - | |
| 2516 | - if ( typeof animate === 'undefined' ) { | |
| 2517 | - jQuery( container ).scrollTop( newPos ); | |
| 2518 | - } else { | |
| 2519 | - // TODO: smooth scroll | |
| 2520 | - jQuery( container ).animate({ scrollTop: newPos }, 500 ); | |
| 2521 | - } | |
| 2522 | - } | |
| 2523 | - | |
| 2524 | - function checkCalculationCreatedByUser() { | |
| 2525 | - var calculation = this.value; | |
| 2526 | - var warningMessage = checkMatchingParens( calculation ); | |
| 2527 | - warningMessage += checkShortcodes( calculation, this ); | |
| 2528 | - | |
| 2529 | - if ( warningMessage !== '' ) { | |
| 2530 | - infoModal( calculation + '\n\n' + warningMessage ); | |
| 2531 | - } | |
| 2532 | - } | |
| 2533 | - | |
| 2534 | - /** | |
| 2535 | - * Checks the Detail Page slug to see if it's a reserved word and displays a message if it is. | |
| 2536 | - */ | |
| 2537 | - function checkDetailPageSlug() { | |
| 2538 | - var slug = jQuery( '#param' ).val(), | |
| 2539 | - msg; | |
| 2540 | - slug = slug.trim().toLowerCase(); | |
| 2541 | - if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( slug ) ) { // eslint-disable-line camelcase | |
| 2542 | - msg = frm_admin_js.slug_is_reserved; // eslint-disable-line camelcase | |
| 2543 | - msg = msg.replace( '****', addHtmlTags( slug, 'strong' ) ); | |
| 2544 | - msg += '<br /><br />'; | |
| 2545 | - 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 | |
| 2546 | - infoModal( msg ); | |
| 2547 | - } | |
| 2548 | - } | |
| 2549 | - | |
| 2550 | - /** | |
| 2551 | - * Checks View filter value for params named with reserved words and displays a message if any are found. | |
| 2552 | - */ | |
| 2553 | - function checkFilterParamNames() { | |
| 2554 | - var regEx = /\[\s*get\s*param\s*=\s*['"]?([a-zA-Z-_]+)['"]?/ig, | |
| 2555 | - filterValue = jQuery( this ).val(), | |
| 2556 | - match = regEx.exec( filterValue ), | |
| 2557 | - unsafeParams = ''; | |
| 2558 | - | |
| 2559 | - while ( match !== null ) { | |
| 2560 | - if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( match[1]) ) { // eslint-disable-line camelcase | |
| 2561 | - if ( unsafeParams !== '' ) { | |
| 2562 | - unsafeParams += '", "' + match[ 1 ]; | |
| 2563 | - } else { | |
| 2564 | - unsafeParams = match[ 1 ]; | |
| 2565 | - } | |
| 2566 | - } | |
| 2567 | - match = regEx.exec( filterValue ); | |
| 2568 | - } | |
| 2569 | - | |
| 2570 | - if ( unsafeParams !== '' ) { | |
| 2571 | - msg = frm_admin_js.param_is_reserved; // eslint-disable-line camelcase | |
| 2572 | - msg = msg.replace( '****', addHtmlTags( unsafeParams, 'strong' ) ); | |
| 2573 | - msg += '<br /><br />'; | |
| 2574 | - 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 | |
| 2575 | - | |
| 2576 | - infoModal( msg ); | |
| 2577 | - } | |
| 2578 | - } | |
| 2579 | - | |
| 2580 | - function addHtmlTags( text, tag ) { | |
| 2581 | - tag = tag ? tag : 'p'; | |
| 2582 | - return '<' + tag + '>' + text + '</' + tag + '>'; | |
| 2583 | - } | |
| 2584 | - | |
| 2585 | - /** | |
| 2586 | - * Checks a string for parens, brackets, and curly braces and returns a message if any unmatched are found. | |
| 2587 | - * @param formula | |
| 2588 | - * @returns {string} | |
| 2589 | - */ | |
| 2590 | - function checkMatchingParens( formula ) { | |
| 2591 | - | |
| 2592 | - var stack = [], | |
| 2593 | - formulaArray = formula.split( '' ), | |
| 2594 | - length = formulaArray.length, | |
| 2595 | - opening = [ '{', '[', '(' ], | |
| 2596 | - closing = { | |
| 2597 | - '}': '{', | |
| 2598 | - ')': '(', | |
| 2599 | - ']': '[' | |
| 2600 | - }, | |
| 2601 | - unmatchedClosing = [], | |
| 2602 | - msg = '', | |
| 2603 | - i, top; | |
| 2604 | - | |
| 2605 | - for ( i = 0; i < length; i++ ) { | |
| 2606 | - if ( opening.includes( formulaArray[i]) ) { | |
| 2607 | - stack.push( formulaArray[i]); | |
| 2608 | - continue; | |
| 2609 | - } | |
| 2610 | - if ( closing.hasOwnProperty( formulaArray[i]) ) { | |
| 2611 | - top = stack.pop(); | |
| 2612 | - if ( top !== closing[formulaArray[i]]) { | |
| 2613 | - unmatchedClosing.push( formulaArray[i]); | |
| 2614 | - } | |
| 2615 | - } | |
| 2616 | - } | |
| 2617 | - | |
| 2618 | - if ( stack.length > 0 || unmatchedClosing.length > 0 ) { | |
| 2619 | - msg = frm_admin_js.unmatched_parens + '\n\n'; // eslint-disable-line camelcase | |
| 2620 | - return msg; | |
| 2621 | - } | |
| 2622 | - | |
| 2623 | - return ''; | |
| 2624 | - } | |
| 2625 | - | |
| 2626 | - /** | |
| 2627 | - * Checks a calculation for shortcodes that shouldn't be in it and returns a message if found. | |
| 2628 | - * @param calculation | |
| 2629 | - * @param inputElement | |
| 2630 | - * @returns {string} | |
| 2631 | - */ | |
| 2632 | - function checkShortcodes( calculation, inputElement ) { | |
| 2633 | - var msg = checkNonNumericShortcodes( calculation, inputElement ); | |
| 2634 | - msg += checkNonFormShortcodes( calculation ); | |
| 2635 | - | |
| 2636 | - return msg; | |
| 2637 | - } | |
| 2638 | - | |
| 2639 | - /** | |
| 2640 | - * Checks if a numeric calculation has shortcodes that output non-numeric strings and returns a message if found. | |
| 2641 | - * @param calculation | |
| 2642 | - * | |
| 2643 | - * @param inputElement | |
| 2644 | - * @returns {string} | |
| 2645 | - */ | |
| 2646 | - function checkNonNumericShortcodes( calculation, inputElement ) { | |
| 2647 | - | |
| 2648 | - var msg = ''; | |
| 2649 | - | |
| 2650 | - if ( isTextCalculation( inputElement ) ) { | |
| 2651 | - return msg; | |
| 2652 | - } | |
| 2653 | - | |
| 2654 | - var nonNumericShortcodes = getNonNumericShortcodes(); | |
| 2655 | - | |
| 2656 | - if ( nonNumericShortcodes.test( calculation ) ) { | |
| 2657 | - msg = frm_admin_js.text_shortcodes + '\n\n'; // eslint-disable-line camelcase | |
| 2658 | - } | |
| 2659 | - | |
| 2660 | - return msg; | |
| 2661 | - } | |
| 2662 | - | |
| 2663 | - /** | |
| 2664 | - * Determines if the calculation input is from a text calculation. | |
| 2665 | - * | |
| 2666 | - * @param inputElement | |
| 2667 | - */ | |
| 2668 | - function isTextCalculation( inputElement ) { | |
| 2669 | - return jQuery( inputElement ).siblings( 'label[for^="calc_type"]' ).children( 'input' ).prop( 'checked' ); | |
| 2670 | - } | |
| 2671 | - | |
| 2672 | - /** | |
| 2673 | - * Returns a regular expression of shortcodes that can't be used in numeric calculations. | |
| 2674 | - * @returns {RegExp} | |
| 2675 | - */ | |
| 2676 | - function getNonNumericShortcodes() { | |
| 2677 | - return /\[(date|time|email|ip)\]/; | |
| 2678 | - } | |
| 2679 | - | |
| 2680 | - /** | |
| 2681 | - * Checks if a string has any shortcodes that do not belong in forms and returns a message if any are found. | |
| 2682 | - * @param formula | |
| 2683 | - * @returns {string} | |
| 2684 | - */ | |
| 2685 | - function checkNonFormShortcodes( formula ) { | |
| 2686 | - var nonFormShortcodes = getNonFormShortcodes(), | |
| 2687 | - msg = ''; | |
| 2688 | - | |
| 2689 | - if ( nonFormShortcodes.test( formula ) ) { | |
| 2690 | - msg += frm_admin_js.view_shortcodes + '\n\n'; // eslint-disable-line camelcase | |
| 2691 | - } | |
| 2692 | - | |
| 2693 | - return msg; | |
| 2694 | - } | |
| 2695 | - | |
| 2696 | - /** | |
| 2697 | - * Returns a regular expression of shortcodes that can't be used in forms but can be used in Views, Email | |
| 2698 | - * Notifications, and other Formidable areas. | |
| 2699 | - * | |
| 2700 | - * @returns {RegExp} | |
| 2701 | - */ | |
| 2702 | - function getNonFormShortcodes() { | |
| 2703 | - return /\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g; | |
| 2704 | - } | |
| 2705 | - | |
| 2706 | - function isCalcBoxType( box, listClass ) { | |
| 2707 | - var list = jQuery( box ).find( '.frm_code_list' ); | |
| 2708 | - return 1 === list.length && list.hasClass( listClass ); | |
| 2709 | - } | |
| 2710 | - | |
| 2711 | - function extractExcludedOptions( exclude ) { | |
| 2712 | - var opts = []; | |
| 2713 | - if ( ! Array.isArray( exclude ) ) { | |
| 2714 | - return opts; | |
| 2715 | - } | |
| 2716 | - | |
| 2717 | - for ( var i = 0; i < exclude.length; i++ ) { | |
| 2718 | - if ( exclude[ i ].startsWith( '[' ) ) { | |
| 2719 | - opts.push( exclude[ i ]); | |
| 2720 | - // remove it | |
| 2721 | - exclude.splice( i, 1 ); | |
| 2722 | - // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value | |
| 2723 | - i--; | |
| 2724 | - } | |
| 2725 | - } | |
| 2726 | - | |
| 2727 | - return opts; | |
| 2728 | - } | |
| 2729 | - | |
| 2730 | - function hasExcludedOption( field, excludedOpts ) { | |
| 2731 | - var hasOption = false; | |
| 2732 | - for ( var i = 0; i < excludedOpts.length; i++ ) { | |
| 2733 | - var inputs = document.getElementsByName( getFieldOptionInputName( excludedOpts[ i ], field.fieldId ) ); | |
| 2734 | - // 2nd condition checks that there's at least one non-empty value | |
| 2735 | - if ( inputs.length && jQuery( inputs[0]).val() ) { | |
| 2736 | - hasOption = true; | |
| 2737 | - break; | |
| 2738 | - } | |
| 2739 | - } | |
| 2740 | - return hasOption; | |
| 2741 | - } | |
| 2742 | - | |
| 2743 | - function getFieldOptionInputName( opt, fieldId ) { | |
| 2744 | - var at = opt.indexOf( ']' ); | |
| 2745 | - return 'field_options' + opt.substring( 0, at ) + '_' + fieldId + opt.substring( at ); | |
| 2746 | - } | |
| 2747 | - | |
| 2748 | - function popCalcFields( v, force ) { | |
| 2749 | - var box, exclude, fields, i, list, | |
| 2750 | - p = jQuery( v ).closest( '.frm-single-settings' ), | |
| 2751 | - calc = p.find( '.frm-calc-field' ); | |
| 2752 | - | |
| 2753 | - if ( ! force && ( ! calc.length || calc.val() === '' || calc.is( ':hidden' ) ) ) { | |
| 2754 | - return; | |
| 2755 | - } | |
| 2756 | - | |
| 2757 | - var isSummary = isCalcBoxType( v, 'frm_js_summary_list' ); | |
| 2758 | - | |
| 2759 | - var fieldId = p.find( 'input[name="frm_fields_submitted[]"]' ).val(); | |
| 2760 | - | |
| 2761 | - if ( force ) { | |
| 2762 | - box = v; | |
| 2763 | - } else { | |
| 2764 | - box = document.getElementById( 'frm-calc-box-' + fieldId ); | |
| 2765 | - } | |
| 2766 | - | |
| 2767 | - exclude = getExcludeArray( box, isSummary ); | |
| 2768 | - var excludedOpts = extractExcludedOptions( exclude ); | |
| 2769 | - | |
| 2770 | - fields = getFieldList(); | |
| 2771 | - list = document.getElementById( 'frm-calc-list-' + fieldId ); | |
| 2772 | - list.innerHTML = ''; | |
| 2773 | - | |
| 2774 | - for ( i = 0; i < fields.length; i++ ) { | |
| 2775 | - if ( ( exclude && exclude.includes( fields[ i ].fieldType ) ) || | |
| 2776 | - ( excludedOpts.length && hasExcludedOption( fields[ i ], excludedOpts ) ) ) { | |
| 2777 | - continue; | |
| 2778 | - } | |
| 2779 | - | |
| 2780 | - var span = document.createElement( 'span' ); | |
| 2781 | - span.appendChild( document.createTextNode( '[' + fields[i].fieldId + ']' ) ); | |
| 2782 | - | |
| 2783 | - var a = document.createElement( 'a' ); | |
| 2784 | - a.setAttribute( 'href', '#' ); | |
| 2785 | - a.setAttribute( 'data-code', fields[i].fieldId ); | |
| 2786 | - a.classList.add( 'frm_insert_code' ); | |
| 2787 | - a.appendChild( span ); | |
| 2788 | - a.appendChild( document.createTextNode( fields[i].fieldName ) ); | |
| 2789 | - | |
| 2790 | - var li = document.createElement( 'li' ); | |
| 2791 | - li.classList.add( 'frm-field-list-' + fieldId ); | |
| 2792 | - li.classList.add( 'frm-field-list-' + fields[i].fieldType ); | |
| 2793 | - li.appendChild( a ); | |
| 2794 | - list.appendChild( li ); | |
| 2795 | - } | |
| 2796 | - } | |
| 2797 | - | |
| 2798 | - function getExcludeArray( calcBox, isSummary ) { | |
| 2799 | - var exclude = JSON.parse( calcBox.getElementsByClassName( 'frm_code_list' )[0].getAttribute( 'data-exclude' ) ); | |
| 2800 | - | |
| 2801 | - if ( isSummary ) { | |
| 2802 | - // includedExtras are those that are normally excluded from the summary but the form owner can choose to include, | |
| 2803 | - // when they have been chosen to be included, then they can now be manually excluded in the calc box. | |
| 2804 | - var includedExtras = getIncludedExtras(); | |
| 2805 | - if ( includedExtras.length ) { | |
| 2806 | - for ( var i = 0; i < exclude.length; i++ ) { | |
| 2807 | - if ( includedExtras.includes( exclude[ i ]) ) { | |
| 2808 | - // remove it | |
| 2809 | - exclude.splice( i, 1 ); | |
| 2810 | - // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value | |
| 2811 | - i--; | |
| 2812 | - } | |
| 2813 | - } | |
| 2814 | - } | |
| 2815 | - } | |
| 2816 | - | |
| 2817 | - return exclude; | |
| 2818 | - } | |
| 2819 | - | |
| 2820 | - function getIncludedExtras() { | |
| 2821 | - var checked = []; | |
| 2822 | - var checkboxes = document.getElementsByClassName( 'frm_include_extras_field' ); | |
| 2823 | - | |
| 2824 | - for ( var i = 0; i < checkboxes.length; i++ ) { | |
| 2825 | - if ( checkboxes[i].checked ) { | |
| 2826 | - checked.push( checkboxes[i].value ); | |
| 2827 | - } | |
| 2828 | - } | |
| 2829 | - | |
| 2830 | - return checked; | |
| 2831 | - } | |
| 2832 | - | |
| 2833 | - function rePopCalcFieldsForSummary() { | |
| 2834 | - popCalcFields( jQuery( '.frm-inline-modal.postbox:has(.frm_js_summary_list)' )[0], true ); | |
| 2835 | - } | |
| 2836 | - | |
| 2837 | - function getFieldList( fieldType ) { | |
| 2838 | - var i, | |
| 2839 | - fields = [], | |
| 2840 | - allFields = document.querySelectorAll( 'li.frm_field_box' ), | |
| 2841 | - checkType = 'undefined' !== typeof fieldType; | |
| 2842 | - | |
| 2843 | - for ( i = 0; i < allFields.length; i++ ) { | |
| 2844 | - // data-ftype is better (than data-type) cos of fields loaded by AJAX - which might not be ready yet | |
| 2845 | - if ( checkType && allFields[ i ].getAttribute( 'data-ftype' ) !== fieldType ) { | |
| 2846 | - continue; | |
| 2847 | - } | |
| 2848 | - | |
| 2849 | - var fieldId = allFields[ i ].getAttribute( 'data-fid' ); | |
| 2850 | - if ( typeof fieldId !== 'undefined' && fieldId ) { | |
| 2851 | - fields.push({ | |
| 2852 | - 'fieldId': fieldId, | |
| 2853 | - 'fieldName': getPossibleValue( 'frm_name_' + fieldId ), | |
| 2854 | - 'fieldType': getPossibleValue( 'field_options_type_' + fieldId ), | |
| 2855 | - 'fieldKey': getPossibleValue( 'field_options_field_key_' + fieldId ) | |
| 2856 | - }); | |
| 2857 | - } | |
| 2858 | - } | |
| 2859 | - | |
| 2860 | - return fields; | |
| 2861 | - } | |
| 2862 | - | |
| 2863 | - function popProductFields( field ) { | |
| 2864 | - var i, checked, id, | |
| 2865 | - options = [], | |
| 2866 | - current = getCurrentProductFields( field ), | |
| 2867 | - fName = field.getAttribute( 'data-frmfname' ), | |
| 2868 | - products = getFieldList( 'product' ), | |
| 2869 | - quantities = getFieldList( 'quantity' ), | |
| 2870 | - isSelect = field.tagName === 'SELECT', // for reverse compatibility. | |
| 2871 | - // whether we have just 1 product and 1 quantity field & should therefore attach the latter to the former | |
| 2872 | - auto = 1 === quantities.length && 1 === products.length; | |
| 2873 | - | |
| 2874 | - if ( isSelect ) { | |
| 2875 | - // This fallback can be removed after 4.05. | |
| 2876 | - current = field.getAttribute( 'data-frmcurrent' ); | |
| 2877 | - } | |
| 2878 | - | |
| 2879 | - for ( i = 0 ; i < products.length ; i++ ) { | |
| 2880 | - // let's be double sure it's string, else indexOf will fail | |
| 2881 | - id = products[ i ].fieldId.toString(); | |
| 2882 | - checked = auto || -1 !== current.indexOf( id ); | |
| 2883 | - if ( isSelect ) { | |
| 2884 | - // This fallback can be removed after 4.05. | |
| 2885 | - checked = checked ? ' selected' : ''; | |
| 2886 | - options.push( '<option value="' + id + '"' + checked + '>' + products[ i ].fieldName + '</option>' ); | |
| 2887 | - } else { | |
| 2888 | - checked = checked ? ' checked' : ''; | |
| 2889 | - options.push( '<label class="frm6">' ); | |
| 2890 | - options.push( '<input type="checkbox" name="' + fName + '" value="' + id + '"' + checked + '> ' + products[ i ].fieldName ); | |
| 2891 | - options.push( '</label>' ); | |
| 2892 | - } | |
| 2893 | - } | |
| 2894 | - | |
| 2895 | - field.innerHTML = options.join( '' ); | |
| 2896 | - } | |
| 2897 | - | |
| 2898 | - function getCurrentProductFields( prodFieldOpt ) { | |
| 2899 | - var products = prodFieldOpt.querySelectorAll( '[type="checkbox"]:checked' ), | |
| 2900 | - idsArray = []; | |
| 2901 | - | |
| 2902 | - for ( var i = 0; i < products.length; i++ ) { | |
| 2903 | - idsArray.push( products[ i ].value ); | |
| 2904 | - } | |
| 2905 | - | |
| 2906 | - return idsArray; | |
| 2907 | - } | |
| 2908 | - | |
| 2909 | - function popAllProductFields() { | |
| 2910 | - var opts = document.querySelectorAll( '.frmjs_prod_field_opt' ); | |
| 2911 | - for ( var i = 0; i < opts.length; i++ ) { | |
| 2912 | - popProductFields( opts[ i ]); | |
| 2913 | - } | |
| 2914 | - } | |
| 2915 | - | |
| 2916 | - function maybeSetProductField( field ) { | |
| 2917 | - var fieldId = field.getAttribute( 'data-fid' ), | |
| 2918 | - productFieldOpt = document.getElementById( 'field_options[product_field_' + fieldId + ']' ); | |
| 2919 | - | |
| 2920 | - if ( null === productFieldOpt ) { | |
| 2921 | - return; | |
| 2922 | - } | |
| 2923 | - | |
| 2924 | - popProductFields( productFieldOpt ); | |
| 2925 | - // in order to move its settings to that LHS panel where | |
| 2926 | - // the update form resides, else it'll lose this setting | |
| 2927 | - moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) ); | |
| 2928 | - } | |
| 2929 | - | |
| 2930 | - /** | |
| 2931 | - * If the element doesn't exist, use a blank value. | |
| 2932 | - */ | |
| 2933 | - function getPossibleValue( id ) { | |
| 2934 | - field = document.getElementById( id ); | |
| 2935 | - if ( field !== null ) { | |
| 2936 | - return field.value; | |
| 2937 | - } else { | |
| 2938 | - return ''; | |
| 2939 | - } | |
| 2940 | - } | |
| 2941 | - | |
| 2942 | - function liveChanges() { | |
| 2943 | - /*jshint validthis:true */ | |
| 2944 | - var option, | |
| 2945 | - newValue = this.value, | |
| 2946 | - changes = document.getElementById( this.getAttribute( 'data-changeme' ) ), | |
| 2947 | - att = this.getAttribute( 'data-changeatt' ); | |
| 2948 | - | |
| 2949 | - if ( changes === null ) { | |
| 2950 | - return; | |
| 2951 | - } | |
| 2952 | - | |
| 2953 | - if ( att !== null ) { | |
| 2954 | - if ( changes.tagName === 'SELECT' && att === 'placeholder' ) { | |
| 2955 | - option = changes.options[0]; | |
| 2956 | - if ( option.value === '' ) { | |
| 2957 | - option.innerHTML = newValue; | |
| 2958 | - } else { | |
| 2959 | - // Create a placeholder option if there are no blank values. | |
| 2960 | - addBlankSelectOption( changes, newValue ); | |
| 2961 | - } | |
| 2962 | - } else if ( att === 'class' ) { | |
| 2963 | - changeFieldClass( changes, this ); | |
| 2964 | - } else if ( isSliderField( changes ) ) { | |
| 2965 | - updateSliderFieldPreview( changes, att, newValue ); | |
| 2966 | - } else { | |
| 2967 | - changes.setAttribute( att, newValue ); | |
| 2968 | - } | |
| 2969 | - } else if ( changes.id.indexOf( 'setup-message' ) === 0 ) { | |
| 2970 | - if ( newValue !== '' ) { | |
| 2971 | - changes.innerHTML = '<input type="text" value="" disabled />'; | |
| 2972 | - } | |
| 2973 | - } else { | |
| 2974 | - changes.innerHTML = newValue; | |
| 2975 | - | |
| 2976 | - if ( 'TEXTAREA' === changes.nodeName && changes.classList.contains( 'wp-editor-area' ) ) { | |
| 2977 | - // Trigger change events on wysiwyg textareas so we can also sync default values in the visual tab. | |
| 2978 | - jQuery( changes ).trigger( 'change' ); | |
| 2979 | - } | |
| 2980 | - | |
| 2981 | - if ( changes.classList.contains( 'frm_primary_label' ) && 'break' === changes.nextElementSibling.getAttribute( 'data-ftype' ) ) { | |
| 2982 | - changes.nextElementSibling.querySelector( '.frm_button_submit' ).textContent = newValue; | |
| 2983 | - } | |
| 2984 | - } | |
| 2985 | - } | |
| 2986 | - | |
| 2987 | - function updateSliderFieldPreview( field, att, newValue ) { | |
| 2988 | - if ( frmGlobal.proIncludesSliderJs ) { | |
| 2989 | - const hookName = 'frm_update_slider_field_preview'; | |
| 2990 | - const hookArgs = { field, att, newValue }; | |
| 2991 | - wp.hooks.doAction( hookName, hookArgs ); | |
| 2992 | - return; | |
| 2993 | - } | |
| 2994 | - | |
| 2995 | - // This functionality has been moved to pro since v5.4.3. This code should be removed eventually. | |
| 2996 | - if ( 'value' === att ) { | |
| 2997 | - if ( '' === newValue ) { | |
| 2998 | - newValue = getSliderMidpoint( field ); | |
| 2999 | - } | |
| 3000 | - field.value = newValue; | |
| 3001 | - } else { | |
| 3002 | - field.setAttribute( att, newValue ); | |
| 3003 | - } | |
| 3004 | - | |
| 3005 | - if ( -1 === [ 'value', 'min', 'max' ].indexOf( att ) ) { | |
| 3006 | - return; | |
| 3007 | - } | |
| 3008 | - | |
| 3009 | - if ( ( 'max' === att || 'min' === att ) && '' === getSliderDefaultValueInput( field.id ) ) { | |
| 3010 | - field.value = getSliderMidpoint( field ); | |
| 3011 | - } | |
| 3012 | - | |
| 3013 | - field.parentNode.querySelector( '.frm_range_value' ).textContent = field.value; | |
| 3014 | - } | |
| 3015 | - | |
| 3016 | - function getSliderDefaultValueInput( previewInputId ) { | |
| 3017 | - return document.querySelector( 'input[data-changeme="' + previewInputId + '"][data-changeatt="value"]' ).value; | |
| 3018 | - } | |
| 3019 | - | |
| 3020 | - function getSliderMidpoint( sliderInput ) { | |
| 3021 | - const max = parseFloat( sliderInput.getAttribute( 'max' ) ); | |
| 3022 | - const min = parseFloat( sliderInput.getAttribute( 'min' ) ); | |
| 3023 | - return ( max - min ) / 2 + min; | |
| 3024 | - } | |
| 3025 | - | |
| 3026 | - function isSliderField( previewInput ) { | |
| 3027 | - return 'range' === previewInput.type && previewInput.parentNode.classList.contains( 'frm_range_container' ); | |
| 3028 | - } | |
| 3029 | - | |
| 3030 | - function toggleInvalidMsg() { | |
| 3031 | - /*jshint validthis:true */ | |
| 3032 | - var typeDropdown, fieldType, | |
| 3033 | - fieldId = this.getAttribute( 'data-fid' ), | |
| 3034 | - value = ''; | |
| 3035 | - | |
| 3036 | - [ 'field_options_max_', 'frm_format_' ].forEach( function( id ) { | |
| 3037 | - var input = document.getElementById( id + fieldId ); | |
| 3038 | - if ( ! input ) { | |
| 3039 | - return; | |
| 3040 | - } | |
| 3041 | - | |
| 3042 | - value += input.value; | |
| 3043 | - }); | |
| 3044 | - | |
| 3045 | - typeDropdown = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0]; | |
| 3046 | - fieldType = typeDropdown.options[typeDropdown.selectedIndex].value; | |
| 3047 | - | |
| 3048 | - if ( fieldType === 'text' ) { | |
| 3049 | - toggleValidationBox( '' !== value, '.frm_invalid_msg' + fieldId ); | |
| 3050 | - } | |
| 3051 | - } | |
| 3052 | - | |
| 3053 | - function markRequired() { | |
| 3054 | - /*jshint validthis:true */ | |
| 3055 | - var thisid = this.id.replace( 'frm_', '' ), | |
| 3056 | - fieldId = thisid.replace( 'req_field_', '' ), | |
| 3057 | - checked = this.checked, | |
| 3058 | - label = jQuery( '#field_label_' + fieldId + ' .frm_required' ); | |
| 3059 | - | |
| 3060 | - toggleValidationBox( checked, '.frm_required_details' + fieldId ); | |
| 3061 | - | |
| 3062 | - if ( checked ) { | |
| 3063 | - var $reqBox = jQuery( 'input[name="field_options[required_indicator_' + fieldId + ']"]' ); | |
| 3064 | - if ( $reqBox.val() === '' ) { | |
| 3065 | - $reqBox.val( '*' ); | |
| 3066 | - } | |
| 3067 | - label.removeClass( 'frm_hidden' ); | |
| 3068 | - } else { | |
| 3069 | - label.addClass( 'frm_hidden' ); | |
| 3070 | - } | |
| 3071 | - } | |
| 3072 | - | |
| 3073 | - function toggleValidationBox( hasValue, messageClass ) { | |
| 3074 | - $msg = jQuery( messageClass ); | |
| 3075 | - if ( hasValue ) { | |
| 3076 | - $msg.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' ); | |
| 3077 | - } else { | |
| 3078 | - //Fade out validation options | |
| 3079 | - var v = $msg.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(' + messageClass + '):visible' ).length; | |
| 3080 | - if ( v === 0 ) { | |
| 3081 | - $msg.closest( '.frm_validation_msg' ).fadeOut( 'fast' ); | |
| 3082 | - } | |
| 3083 | - } | |
| 3084 | - } | |
| 3085 | - | |
| 3086 | - function markUnique() { | |
| 3087 | - /*jshint validthis:true */ | |
| 3088 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3089 | - var $thisField = jQuery( '.frm_unique_details' + fieldId ); | |
| 3090 | - if ( this.checked ) { | |
| 3091 | - $thisField.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' ); | |
| 3092 | - $unqDetail = jQuery( '.frm_unique_details' + fieldId + ' input' ); | |
| 3093 | - if ( $unqDetail.val() === '' ) { | |
| 3094 | - $unqDetail.val( frm_admin_js.default_unique ); // eslint-disable-line camelcase | |
| 3095 | - } | |
| 3096 | - } else { | |
| 3097 | - var v = $thisField.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(.frm_unique_details' + fieldId + '):visible' ).length; | |
| 3098 | - if ( v === 0 ) { | |
| 3099 | - $thisField.closest( '.frm_validation_msg' ).fadeOut( 'fast' ); | |
| 3100 | - } | |
| 3101 | - } | |
| 3102 | - } | |
| 3103 | - | |
| 3104 | - //Fade confirmation field and validation option in or out | |
| 3105 | - function addConf() { | |
| 3106 | - /*jshint validthis:true */ | |
| 3107 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3108 | - var val = jQuery( this ).val(); | |
| 3109 | - var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ); | |
| 3110 | - | |
| 3111 | - toggleValidationBox( val !== '', '.frm_conf_details' + fieldId ); | |
| 3112 | - | |
| 3113 | - if ( val !== '' ) { | |
| 3114 | - //Add default validation message if empty | |
| 3115 | - var valMsg = jQuery( '.frm_validation_box .frm_conf_details' + fieldId + ' input' ); | |
| 3116 | - if ( valMsg.val() === '' ) { | |
| 3117 | - valMsg.val( frm_admin_js.default_conf ); // eslint-disable-line camelcase | |
| 3118 | - } | |
| 3119 | - | |
| 3120 | - setConfirmationFieldDescriptions( fieldId ); | |
| 3121 | - | |
| 3122 | - //Add or remove class for confirmation field styling | |
| 3123 | - if ( val === 'inline' ) { | |
| 3124 | - $thisField.removeClass( 'frm_conf_below' ).addClass( 'frm_conf_inline' ); | |
| 3125 | - } else if ( val === 'below' ) { | |
| 3126 | - $thisField.removeClass( 'frm_conf_inline' ).addClass( 'frm_conf_below' ); | |
| 3127 | - } | |
| 3128 | - jQuery( '.frm-conf-box-' + fieldId ).removeClass( 'frm_hidden' ); | |
| 3129 | - } else { | |
| 3130 | - jQuery( '.frm-conf-box-' + fieldId ).addClass( 'frm_hidden' ); | |
| 3131 | - setTimeout( function() { | |
| 3132 | - $thisField.removeClass( 'frm_conf_inline frm_conf_below' ); | |
| 3133 | - }, 200 ); | |
| 3134 | - } | |
| 3135 | - } | |
| 3136 | - | |
| 3137 | - function setConfirmationFieldDescriptions( fieldId ) { | |
| 3138 | - var fieldType = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0].value; | |
| 3139 | - | |
| 3140 | - var fieldDescription = document.getElementById( 'field_description_' + fieldId ); | |
| 3141 | - var hiddenDescName = 'field_options[description_' + fieldId + ']'; | |
| 3142 | - var newValue = frm_admin_js['enter_' + fieldType]; // eslint-disable-line camelcase | |
| 3143 | - maybeSetNewDescription( fieldDescription, hiddenDescName, newValue ); | |
| 3144 | - | |
| 3145 | - var confFieldDescription = document.getElementById( 'conf_field_description_' + fieldId ); | |
| 3146 | - var hiddenConfName = 'field_options[conf_desc_' + fieldId + ']'; | |
| 3147 | - var newConfValue = frm_admin_js['confirm_' + fieldType]; // eslint-disable-line camelcase | |
| 3148 | - maybeSetNewDescription( confFieldDescription, hiddenConfName, newConfValue ); | |
| 3149 | - } | |
| 3150 | - | |
| 3151 | - function maybeSetNewDescription( descriptionDiv, hiddenName, newValue ) { | |
| 3152 | - if ( descriptionDiv.innerHTML === frm_admin_js.desc ) { // eslint-disable-line camelcase | |
| 3153 | - | |
| 3154 | - // Set the visible description value and the hidden description value | |
| 3155 | - descriptionDiv.innerHTML = newValue; | |
| 3156 | - document.getElementsByName( hiddenName )[0].value = newValue; | |
| 3157 | - } | |
| 3158 | - } | |
| 3159 | - | |
| 3160 | - function initBulkOptionsOverlay() { | |
| 3161 | - /*jshint validthis:true */ | |
| 3162 | - var $info = initModal( '#frm-bulk-modal', '700px' ); | |
| 3163 | - if ( $info === false ) { | |
| 3164 | - return; | |
| 3165 | - } | |
| 3166 | - | |
| 3167 | - jQuery( '.frm-insert-preset' ).on( 'click', insertBulkPreset ); | |
| 3168 | - | |
| 3169 | - jQuery( builderForm ).on( 'click', 'a.frm-bulk-edit-link', function( event ) { | |
| 3170 | - event.preventDefault(); | |
| 3171 | - var i, key, label, | |
| 3172 | - content = '', | |
| 3173 | - optList, | |
| 3174 | - opts, | |
| 3175 | - fieldId = jQuery( this ).closest( '[data-fid]' ).data( 'fid' ), | |
| 3176 | - separate = usingSeparateValues( fieldId ), | |
| 3177 | - product = isProductField( fieldId ); | |
| 3178 | - | |
| 3179 | - optList = document.getElementById( 'frm_field_' + fieldId + '_opts' ); | |
| 3180 | - if ( ! optList ) { | |
| 3181 | - return; | |
| 3182 | - } | |
| 3183 | - | |
| 3184 | - opts = optList.getElementsByTagName( 'li' ); | |
| 3185 | - | |
| 3186 | - document.getElementById( 'bulk-field-id' ).value = fieldId; | |
| 3187 | - | |
| 3188 | - for ( i = 0; i < opts.length; i++ ) { | |
| 3189 | - key = opts[i].getAttribute( 'data-optkey' ); | |
| 3190 | - if ( key !== '000' ) { | |
| 3191 | - label = document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][label]' )[0]; | |
| 3192 | - if ( typeof label !== 'undefined' ) { | |
| 3193 | - content += label.value; | |
| 3194 | - if ( separate ) { | |
| 3195 | - content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][value]' )[0].value; | |
| 3196 | - } | |
| 3197 | - if ( product ) { | |
| 3198 | - content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][price]' )[0].value; | |
| 3199 | - } | |
| 3200 | - content += '\r\n'; | |
| 3201 | - } | |
| 3202 | - } | |
| 3203 | - | |
| 3204 | - if ( i >= opts.length - 1 ) { | |
| 3205 | - document.getElementById( 'frm_bulk_options' ).value = content; | |
| 3206 | - } | |
| 3207 | - } | |
| 3208 | - | |
| 3209 | - $info.dialog( 'open' ); | |
| 3210 | - | |
| 3211 | - return false; | |
| 3212 | - }); | |
| 3213 | - | |
| 3214 | - jQuery( '#frm-update-bulk-opts' ).on( 'click', function() { | |
| 3215 | - var fieldId = document.getElementById( 'bulk-field-id' ).value; | |
| 3216 | - var optionType = document.getElementById( 'bulk-option-type' ).value; | |
| 3217 | - | |
| 3218 | - if ( optionType ) { | |
| 3219 | - // Use custom handler for custom option type. | |
| 3220 | - return; | |
| 3221 | - } | |
| 3222 | - | |
| 3223 | - this.classList.add( 'frm_loading_button' ); | |
| 3224 | - frmAdminBuild.updateOpts( fieldId, document.getElementById( 'frm_bulk_options' ).value, $info ); | |
| 3225 | - fieldUpdated(); | |
| 3226 | - }); | |
| 3227 | - } | |
| 3228 | - | |
| 3229 | - function insertBulkPreset( event ) { | |
| 3230 | - /*jshint validthis:true */ | |
| 3231 | - var opts = JSON.parse( this.getAttribute( 'data-opts' ) ); | |
| 3232 | - event.preventDefault(); | |
| 3233 | - document.getElementById( 'frm_bulk_options' ).value = opts.join( '\n' ); | |
| 3234 | - return false; | |
| 3235 | - } | |
| 3236 | - | |
| 3237 | - //Add new option or "Other" option to radio/checkbox/dropdown | |
| 3238 | - function addFieldOption() { | |
| 3239 | - /*jshint validthis:true */ | |
| 3240 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 3241 | - newOption = jQuery( '#frm_field_' + fieldId + '_opts .frm_option_template' ).prop( 'outerHTML' ), | |
| 3242 | - optType = jQuery( this ).data( 'opttype' ), | |
| 3243 | - optKey = 0, | |
| 3244 | - oldKey = '000', | |
| 3245 | - lastKey = getHighestOptKey( fieldId ); | |
| 3246 | - | |
| 3247 | - if ( lastKey !== oldKey ) { | |
| 3248 | - optKey = lastKey + 1; | |
| 3249 | - } | |
| 3250 | - | |
| 3251 | - //Update hidden field | |
| 3252 | - if ( optType === 'other' ) { | |
| 3253 | - document.getElementById( 'other_input_' + fieldId ).value = 1; | |
| 3254 | - | |
| 3255 | - //Hide "Add Other" option now if this is radio field | |
| 3256 | - var ftype = jQuery( this ).data( 'ftype' ); | |
| 3257 | - if ( ftype === 'radio' || ftype === 'select' ) { | |
| 3258 | - jQuery( this ).fadeOut( 'slow' ); | |
| 3259 | - } | |
| 3260 | - | |
| 3261 | - var data = { | |
| 3262 | - action: 'frm_add_field_option', | |
| 3263 | - field_id: fieldId, | |
| 3264 | - opt_key: optKey, | |
| 3265 | - opt_type: optType, | |
| 3266 | - nonce: frmGlobal.nonce | |
| 3267 | - }; | |
| 3268 | - jQuery.post( ajaxurl, data, function( msg ) { | |
| 3269 | - jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( msg ); | |
| 3270 | - resetDisplayedOpts( fieldId ); | |
| 3271 | - }); | |
| 3272 | - } else { | |
| 3273 | - newOption = newOption.replace( new RegExp( 'optkey="' + oldKey + '"', 'g' ), 'optkey="' + optKey + '"' ); | |
| 3274 | - newOption = newOption.replace( new RegExp( '-' + oldKey + '_', 'g' ), '-' + optKey + '_' ); | |
| 3275 | - newOption = newOption.replace( new RegExp( '-' + oldKey + '"', 'g' ), '-' + optKey + '"' ); | |
| 3276 | - newOption = newOption.replace( new RegExp( '\\[' + oldKey + '\\]', 'g' ), '[' + optKey + ']' ); | |
| 3277 | - newOption = newOption.replace( 'frm_hidden frm_option_template', '' ); | |
| 3278 | - newOption = { newOption }; | |
| 3279 | - addSaveAndDragIconsToOption( fieldId, newOption ); | |
| 3280 | - jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( newOption.newOption ); | |
| 3281 | - resetDisplayedOpts( fieldId ); | |
| 3282 | - } | |
| 3283 | - fieldUpdated(); | |
| 3284 | - } | |
| 3285 | - | |
| 3286 | - function getHighestOptKey( fieldId ) { | |
| 3287 | - var i = 0, | |
| 3288 | - optKey = 0, | |
| 3289 | - opts = jQuery( '#frm_field_' + fieldId + '_opts li' ), | |
| 3290 | - lastKey = 0; | |
| 3291 | - | |
| 3292 | - for ( i; i < opts.length; i++ ) { | |
| 3293 | - optKey = opts[i].getAttribute( 'data-optkey' ); | |
| 3294 | - if ( opts.length === 1 ) { | |
| 3295 | - return optKey; | |
| 3296 | - } | |
| 3297 | - if ( optKey !== '000' ) { | |
| 3298 | - optKey = optKey.replace( 'other_', '' ); | |
| 3299 | - optKey = parseInt( optKey, 10 ); | |
| 3300 | - } | |
| 3301 | - | |
| 3302 | - if ( ! isNaN( lastKey ) && ( optKey > lastKey || lastKey === '000' ) ) { | |
| 3303 | - lastKey = optKey; | |
| 3304 | - } | |
| 3305 | - } | |
| 3306 | - | |
| 3307 | - return lastKey; | |
| 3308 | - } | |
| 3309 | - | |
| 3310 | - function toggleMultSel() { | |
| 3311 | - /*jshint validthis:true */ | |
| 3312 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3313 | - toggleMultiSelect( fieldId, this.value ); | |
| 3314 | - } | |
| 3315 | - | |
| 3316 | - function toggleMultiSelect( fieldId, value ) { | |
| 3317 | - var setting = jQuery( '.frm_multiple_cont_' + fieldId ); | |
| 3318 | - if ( value === 'select' ) { | |
| 3319 | - setting.fadeIn( 'fast' ); | |
| 3320 | - } else { | |
| 3321 | - setting.fadeOut( 'fast' ); | |
| 3322 | - } | |
| 3323 | - } | |
| 3324 | - | |
| 3325 | - function toggleSepValues() { | |
| 3326 | - /*jshint validthis:true */ | |
| 3327 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3328 | - toggle( jQuery( '.field_' + fieldId + '_option_key' ) ); | |
| 3329 | - jQuery( '.field_' + fieldId + '_option' ).toggleClass( 'frm_with_key' ); | |
| 3330 | - } | |
| 3331 | - | |
| 3332 | - function toggleImageOptions() { | |
| 3333 | - /*jshint validthis:true */ | |
| 3334 | - var hasImageOptions, imageSize, | |
| 3335 | - $field = jQuery( this ).closest( '.frm-single-settings' ), | |
| 3336 | - fieldId = $field.data( 'fid' ), | |
| 3337 | - displayField = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 3338 | - | |
| 3339 | - refreshOptionDisplayNow( jQuery( this ) ); | |
| 3340 | - | |
| 3341 | - toggle( jQuery( '.field_' + fieldId + '_image_id' ) ); | |
| 3342 | - toggle( jQuery( '.frm_toggle_image_options_' + fieldId ) ); | |
| 3343 | - toggle( jQuery( '.frm_image_size_' + fieldId ) ); | |
| 3344 | - toggle( jQuery( '.frm_alignment_' + fieldId ) ); | |
| 3345 | - toggle( jQuery( '.frm-add-other#frm_add_field_' + fieldId ) ); | |
| 3346 | - | |
| 3347 | - hasImageOptions = imagesAsOptions( fieldId ); | |
| 3348 | - | |
| 3349 | - if ( hasImageOptions ) { | |
| 3350 | - setAlignment( fieldId, 'inline' ); | |
| 3351 | - removeImageSizeClasses( displayField ); | |
| 3352 | - imageSize = getImageOptionSize( fieldId ); | |
| 3353 | - displayField.classList.add( 'frm_image_options' ); | |
| 3354 | - displayField.classList.add( 'frm_image_size_' + imageSize ); | |
| 3355 | - $field.find( '.frm-bulk-edit-link' ).hide(); | |
| 3356 | - } else { | |
| 3357 | - displayField.classList.remove( 'frm_image_options' ); | |
| 3358 | - removeImageSizeClasses( displayField ); | |
| 3359 | - setAlignment( fieldId, 'block' ); | |
| 3360 | - $field.find( '.frm-bulk-edit-link' ).show(); | |
| 3361 | - } | |
| 3362 | - } | |
| 3363 | - | |
| 3364 | - function removeImageSizeClasses( field ) { | |
| 3365 | - field.classList.remove( 'frm_image_size_', 'frm_image_size_small', 'frm_image_size_medium', 'frm_image_size_large', 'frm_image_size_xlarge' ); | |
| 3366 | - } | |
| 3367 | - | |
| 3368 | - function setAlignment( fieldId, alignment ) { | |
| 3369 | - jQuery( '#field_options_align_' + fieldId ).val( alignment ).trigger( 'change' ); | |
| 3370 | - } | |
| 3371 | - | |
| 3372 | - function setImageSize() { | |
| 3373 | - var $field = jQuery( this ).closest( '.frm-single-settings' ), | |
| 3374 | - fieldId = $field.data( 'fid' ), | |
| 3375 | - displayField = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 3376 | - | |
| 3377 | - refreshOptionDisplay(); | |
| 3378 | - | |
| 3379 | - if ( imagesAsOptions( fieldId ) ) { | |
| 3380 | - removeImageSizeClasses( displayField ); | |
| 3381 | - displayField.classList.add( 'frm_image_options' ); | |
| 3382 | - displayField.classList.add( 'frm_image_size_' + getImageOptionSize( fieldId ) ); | |
| 3383 | - } | |
| 3384 | - } | |
| 3385 | - | |
| 3386 | - function refreshOptionDisplayNow( object ) { | |
| 3387 | - var $field = object.closest( '.frm-single-settings' ), | |
| 3388 | - fieldID = $field.data( 'fid' ); | |
| 3389 | - jQuery( '.field_' + fieldID + '_option' ).trigger( 'change' ); | |
| 3390 | - } | |
| 3391 | - | |
| 3392 | - function refreshOptionDisplay() { | |
| 3393 | - /*jshint validthis:true */ | |
| 3394 | - refreshOptionDisplayNow( jQuery( this ) ); | |
| 3395 | - } | |
| 3396 | - | |
| 3397 | - function addImageToOption( event ) { | |
| 3398 | - const imagePreview = event.target.closest( '.frm_image_preview_wrapper' ); | |
| 3399 | - | |
| 3400 | - event.preventDefault(); | |
| 3401 | - | |
| 3402 | - wp.media.model.settings.post.id = 0; | |
| 3403 | - | |
| 3404 | - const fileFrame = wp.media.frames.file_frame = wp.media({ | |
| 3405 | - multiple: false, | |
| 3406 | - library: { | |
| 3407 | - type: [ 'image' ] | |
| 3408 | - } | |
| 3409 | - }); | |
| 3410 | - | |
| 3411 | - fileFrame.on( 'select', function() { | |
| 3412 | - const attachment = fileFrame.state().get( 'selection' ).first().toJSON(); | |
| 3413 | - const img = imagePreview.querySelector( 'img' ); | |
| 3414 | - | |
| 3415 | - img.setAttribute( 'src', attachment.url ); | |
| 3416 | - img.classList.remove( 'frm_hidden' ); | |
| 3417 | - img.removeAttribute( 'srcset' ); // Prevent the old image from sticking around. | |
| 3418 | - | |
| 3419 | - imagePreview.querySelector( '.frm_image_preview_frame' ).style.display = 'block'; | |
| 3420 | - imagePreview.querySelector( '.frm_image_preview_title' ).textContent = attachment.filename; | |
| 3421 | - imagePreview.querySelector( '.frm_choose_image_box' ).style.display = 'none'; | |
| 3422 | - | |
| 3423 | - const $imagePreview = jQuery( imagePreview ); | |
| 3424 | - $imagePreview.siblings( 'input[name*="[label]"]' ).data( 'frmimgurl', attachment.url ); | |
| 3425 | - $imagePreview.find( 'input.frm_image_id' ).val( attachment.id ).trigger( 'change' ); | |
| 3426 | - wp.media.model.settings.post.id = 0; | |
| 3427 | - }); | |
| 3428 | - | |
| 3429 | - fileFrame.open(); | |
| 3430 | - } | |
| 3431 | - | |
| 3432 | - function removeImageFromOption( event ) { | |
| 3433 | - var $this = jQuery( this ), | |
| 3434 | - previewWrapper = $this.closest( '.frm_image_preview_wrapper' ); | |
| 3435 | - | |
| 3436 | - event.preventDefault(); | |
| 3437 | - event.stopPropagation(); | |
| 3438 | - | |
| 3439 | - previewWrapper.find( 'img' ).attr( 'src', '' ); | |
| 3440 | - previewWrapper.find( '.frm_image_preview_frame' ).hide(); | |
| 3441 | - previewWrapper.find( '.frm_choose_image_box' ).show(); | |
| 3442 | - previewWrapper.find( 'input.frm_image_id' ).val( 0 ).trigger( 'change' ); | |
| 3443 | - } | |
| 3444 | - | |
| 3445 | - function toggleMultiselect() { | |
| 3446 | - /*jshint validthis:true */ | |
| 3447 | - var dropdown = jQuery( this ).closest( 'li' ).find( '.frm_form_fields select' ); | |
| 3448 | - if ( this.checked ) { | |
| 3449 | - dropdown.attr( 'multiple', 'multiple' ); | |
| 3450 | - } else { | |
| 3451 | - dropdown.removeAttr( 'multiple' ); | |
| 3452 | - } | |
| 3453 | - } | |
| 3454 | - | |
| 3455 | - /** | |
| 3456 | - * Allow typing on form switcher click without an extra click to search. | |
| 3457 | - */ | |
| 3458 | - function focusSearchBox() { | |
| 3459 | - var searchBox = document.getElementById( 'dropform-search-input' ); | |
| 3460 | - if ( searchBox !== null ) { | |
| 3461 | - setTimeout( function() { | |
| 3462 | - searchBox.focus(); | |
| 3463 | - }, 100 ); | |
| 3464 | - } | |
| 3465 | - } | |
| 3466 | - | |
| 3467 | - /** | |
| 3468 | - * Dismiss a warning message and send an AJAX request to update the dismissal state. | |
| 3469 | - * | |
| 3470 | - * @since 6.3 | |
| 3471 | - * | |
| 3472 | - * @param {Event} event The event object associated with the click on the dismiss icon. | |
| 3473 | - */ | |
| 3474 | - function dismissWarningMessage( event ) { | |
| 3475 | - const target = event.target; | |
| 3476 | - | |
| 3477 | - const warningEl = target.closest( '.frm_warning_style' ); | |
| 3478 | - jQuery( warningEl ).fadeOut( 400, () => warningEl.remove() ); | |
| 3479 | - | |
| 3480 | - const action = target.dataset.action; | |
| 3481 | - const formData = new FormData(); | |
| 3482 | - doJsonPost( action, formData ); | |
| 3483 | - } | |
| 3484 | - | |
| 3485 | - /** | |
| 3486 | - * If a field is clicked in the builder, prevent inputs from changing. | |
| 3487 | - */ | |
| 3488 | - function stopFieldFocus( e ) { | |
| 3489 | - e.preventDefault(); | |
| 3490 | - } | |
| 3491 | - | |
| 3492 | - function deleteFieldOption() { | |
| 3493 | - /*jshint validthis:true */ | |
| 3494 | - var otherInput, | |
| 3495 | - parentLi = this.parentNode, | |
| 3496 | - parentUl = parentLi.parentNode, | |
| 3497 | - fieldId = this.getAttribute( 'data-fid' ); | |
| 3498 | - | |
| 3499 | - jQuery( parentLi ).fadeOut( 'slow', function() { | |
| 3500 | - jQuery( parentLi ).remove(); | |
| 3501 | - | |
| 3502 | - var hasOther = jQuery( parentUl ).find( '.frm_other_option' ); | |
| 3503 | - if ( hasOther.length < 1 ) { | |
| 3504 | - otherInput = document.getElementById( 'other_input_' + fieldId ); | |
| 3505 | - if ( otherInput !== null ) { | |
| 3506 | - otherInput.value = 0; | |
| 3507 | - } | |
| 3508 | - jQuery( '#other_button_' + fieldId ).fadeIn( 'slow' ); | |
| 3509 | - } | |
| 3510 | - }); | |
| 3511 | - fieldUpdated(); | |
| 3512 | - } | |
| 3513 | - | |
| 3514 | - /** | |
| 3515 | - * If a radio button is set as default, allow a click to | |
| 3516 | - * deselect it. | |
| 3517 | - */ | |
| 3518 | - function maybeUncheckRadio() { | |
| 3519 | - var $self, uncheck, unbind, up; | |
| 3520 | - | |
| 3521 | - /*jshint validthis:true */ | |
| 3522 | - $self = jQuery( this ); | |
| 3523 | - if ( $self.is( ':checked' ) ) { | |
| 3524 | - uncheck = function() { | |
| 3525 | - setTimeout( function() { | |
| 3526 | - $self.prop( 'checked', false ); | |
| 3527 | - }, 0 ); | |
| 3528 | - }; | |
| 3529 | - unbind = function() { | |
| 3530 | - $self.off( 'mouseup', up ); | |
| 3531 | - }; | |
| 3532 | - up = function() { | |
| 3533 | - uncheck(); | |
| 3534 | - unbind(); | |
| 3535 | - }; | |
| 3536 | - $self.on( 'mouseup', up ); | |
| 3537 | - $self.one( 'mouseout', unbind ); | |
| 3538 | - } | |
| 3539 | - } | |
| 3540 | - | |
| 3541 | - /** | |
| 3542 | - * If the field option has the default text, clear it out on click. | |
| 3543 | - */ | |
| 3544 | - function maybeClearOptText() { | |
| 3545 | - /*jshint validthis:true */ | |
| 3546 | - if ( this.value === frm_admin_js.new_option ) { // eslint-disable-line camelcase | |
| 3547 | - this.setAttribute( 'data-value-on-focus', this.value ); | |
| 3548 | - this.value = ''; | |
| 3549 | - } | |
| 3550 | - } | |
| 3551 | - | |
| 3552 | - function confirmFieldsDeleteMessage( numberOfFields ) { | |
| 3553 | - /* translators: %1$s: Number of fields that are selected to be deleted. */ | |
| 3554 | - return __( 'Are you sure you want to delete these %1$s selected field(s)?', 'formidable' ).replace( '%1$s', numberOfFields ); | |
| 3555 | - } | |
| 3556 | - | |
| 3557 | - function clickDeleteField() { | |
| 3558 | - /*jshint validthis:true */ | |
| 3559 | - var confirmMsg = frm_admin_js.conf_delete, // eslint-disable-line camelcase | |
| 3560 | - maybeDivider = this.parentNode.parentNode.parentNode.parentNode.parentNode, | |
| 3561 | - li = maybeDivider.parentNode, | |
| 3562 | - field = jQuery( this ).closest( 'li.form-field' ), | |
| 3563 | - fieldId = field.data( 'fid' ); | |
| 3564 | - | |
| 3565 | - if ( field.data( 'ftype' ) === 'divider' ) { | |
| 3566 | - const fieldBoxes = document.querySelectorAll( '.frm-field-group-hover-target .start_divider .frm_field_box' ); | |
| 3567 | - let fieldIdsToDelete = 0; | |
| 3568 | - fieldBoxes.forEach( fieldBox => { | |
| 3569 | - const fieldsInsideFieldBox = fieldBox.querySelectorAll( 'li.form-field' ); | |
| 3570 | - if ( fieldsInsideFieldBox ) { | |
| 3571 | - fieldIdsToDelete += fieldsInsideFieldBox.length; | |
| 3572 | - } | |
| 3573 | - }); | |
| 3574 | - if ( fieldIdsToDelete ) { | |
| 3575 | - confirmMsg = confirmFieldsDeleteMessage( ++fieldIdsToDelete ); | |
| 3576 | - } | |
| 3577 | - } | |
| 3578 | - | |
| 3579 | - if ( li.classList.contains( 'frm-section-collapsed' ) || li.classList.contains( 'frm-page-collapsed' ) ) { | |
| 3580 | - return false; | |
| 3581 | - } | |
| 3582 | - | |
| 3583 | - // If deleting a section, use a special message. | |
| 3584 | - if ( maybeDivider.className === 'divider_section_only' ) { | |
| 3585 | - confirmMsg = frm_admin_js.conf_delete_sec; // eslint-disable-line camelcase | |
| 3586 | - } | |
| 3587 | - | |
| 3588 | - this.setAttribute( 'data-frmverify', confirmMsg ); | |
| 3589 | - this.setAttribute( 'data-frmverify-btn', 'frm-button-red' ); | |
| 3590 | - this.setAttribute( 'data-deletefield', fieldId ); | |
| 3591 | - | |
| 3592 | - closeOpenFieldDropdowns(); | |
| 3593 | - | |
| 3594 | - confirmLinkClick( this ); | |
| 3595 | - return false; | |
| 3596 | - } | |
| 3597 | - | |
| 3598 | - function clickSelectField() { | |
| 3599 | - this.closest( 'li.form-field' ).click(); | |
| 3600 | - } | |
| 3601 | - | |
| 3602 | - function clickDeleteFieldGroup() { | |
| 3603 | - var hoverTarget, decoy; | |
| 3604 | - | |
| 3605 | - hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3606 | - if ( null === hoverTarget ) { | |
| 3607 | - return; | |
| 3608 | - } | |
| 3609 | - | |
| 3610 | - hoverTarget.classList.add( 'frm-selected-field-group' ); | |
| 3611 | - | |
| 3612 | - decoy = document.createElement( 'div' ); | |
| 3613 | - decoy.classList.add( 'frm-delete-field-groups', 'frm_hidden' ); | |
| 3614 | - document.body.appendChild( decoy ); | |
| 3615 | - decoy.click(); | |
| 3616 | - } | |
| 3617 | - | |
| 3618 | - function duplicateFieldGroup() { | |
| 3619 | - const hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3620 | - if ( null === hoverTarget ) { | |
| 3621 | - return; | |
| 3622 | - } | |
| 3623 | - | |
| 3624 | - const newRowId = 'frm_field_group_' + getAutoId(); | |
| 3625 | - const placeholderUlChild = document.createTextNode( '' ); | |
| 3626 | - wrapFieldLiInPlace( placeholderUlChild ); | |
| 3627 | - | |
| 3628 | - const newRow = jQuery( placeholderUlChild ).closest( 'li' ).get( 0 ); | |
| 3629 | - newRow.classList.add( 'frm_hidden' ); | |
| 3630 | - | |
| 3631 | - const newRowUl = newRow.querySelector( 'ul' ); | |
| 3632 | - newRowUl.id = newRowId; | |
| 3633 | - | |
| 3634 | - jQuery( hoverTarget.closest( 'li.frm_field_box' ) ).after( newRow ); | |
| 3635 | - | |
| 3636 | - const $fields = getFieldsInRow( jQuery( hoverTarget ) ); | |
| 3637 | - const syncDetails = []; | |
| 3638 | - const injectedCloneOptions = []; | |
| 3639 | - | |
| 3640 | - const expectedLength = $fields.length; | |
| 3641 | - const originalFieldIdByDuplicatedFieldId = {}; | |
| 3642 | - | |
| 3643 | - let duplicatedCount = 0; | |
| 3644 | - | |
| 3645 | - jQuery( newRow ).on( | |
| 3646 | - 'frm_added_duplicated_field_to_row', | |
| 3647 | - function( _, args ) { | |
| 3648 | - originalFieldIdByDuplicatedFieldId[ jQuery( args.duplicatedFieldHtml ).attr( 'data-fid' ) ] = args.originalFieldId; | |
| 3649 | - | |
| 3650 | - if ( expectedLength > ++duplicatedCount ) { | |
| 3651 | - return; | |
| 3652 | - } | |
| 3653 | - | |
| 3654 | - const $newRowUl = jQuery( newRowUl ); | |
| 3655 | - const $duplicatedFields = getFieldsInRow( $newRowUl ); | |
| 3656 | - | |
| 3657 | - injectedCloneOptions.forEach( | |
| 3658 | - function( cloneOption ) { | |
| 3659 | - cloneOption.remove(); | |
| 3660 | - } | |
| 3661 | - ); | |
| 3662 | - | |
| 3663 | - for ( let index = 0; index < expectedLength; ++index ) { | |
| 3664 | - $newRowUl.append( $newRowUl.children( 'li.form-field[frm-field-order="' + index + '"]' ) ); | |
| 3665 | - } | |
| 3666 | - | |
| 3667 | - syncLayoutClasses( $duplicatedFields.first(), syncDetails ); | |
| 3668 | - newRow.classList.remove( 'frm_hidden' ); | |
| 3669 | - updateFieldOrder(); | |
| 3670 | - | |
| 3671 | - getFieldsInRow( $newRowUl ).each( | |
| 3672 | - function() { | |
| 3673 | - maybeDuplicateUnsavedSettings( originalFieldIdByDuplicatedFieldId[ this.getAttribute( 'data-fid' ) ], jQuery( this ).prop( 'outerHTML' ) ); | |
| 3674 | - } | |
| 3675 | - ); | |
| 3676 | - } | |
| 3677 | - ); | |
| 3678 | - | |
| 3679 | - $fields.each( | |
| 3680 | - function( index ) { | |
| 3681 | - var cloneOption; | |
| 3682 | - cloneOption = document.createElement( 'li' ); | |
| 3683 | - cloneOption.classList.add( 'frm_clone_field' ); | |
| 3684 | - cloneOption.setAttribute( 'frm-target-row-id', newRowId ); | |
| 3685 | - cloneOption.setAttribute( 'frm-field-order', index ); | |
| 3686 | - this.appendChild( cloneOption ); | |
| 3687 | - cloneOption.click(); | |
| 3688 | - injectedCloneOptions.push( cloneOption ); | |
| 3689 | - syncDetails.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) ); | |
| 3690 | - } | |
| 3691 | - ); | |
| 3692 | - } | |
| 3693 | - | |
| 3694 | - function clickFieldGroupLayout() { | |
| 3695 | - var hoverTarget, sizeOfFieldGroup, popupWrapper; | |
| 3696 | - | |
| 3697 | - hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3698 | - | |
| 3699 | - if ( null === hoverTarget ) { | |
| 3700 | - return; | |
| 3701 | - } | |
| 3702 | - | |
| 3703 | - deselectFields(); | |
| 3704 | - | |
| 3705 | - sizeOfFieldGroup = getSizeOfFieldGroupFromChildElement( hoverTarget.querySelector( 'li.form-field' ) ); | |
| 3706 | - | |
| 3707 | - hoverTarget.classList.add( 'frm-has-open-field-group-popup' ); | |
| 3708 | - jQuery( document ).on( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick ); | |
| 3709 | - | |
| 3710 | - popupWrapper = div(); | |
| 3711 | - popupWrapper.style.position = 'relative'; | |
| 3712 | - popupWrapper.appendChild( getFieldGroupPopup( sizeOfFieldGroup, this ) ); | |
| 3713 | - this.parentNode.appendChild( popupWrapper ); | |
| 3714 | - | |
| 3715 | - const firstLayoutOption = popupWrapper.querySelector( '.frm-row-layout-option' ); | |
| 3716 | - if ( firstLayoutOption ) { | |
| 3717 | - firstLayoutOption.focus(); | |
| 3718 | - } | |
| 3719 | - } | |
| 3720 | - | |
| 3721 | - function destroyFieldGroupPopupOnOutsideClick( event ) { | |
| 3722 | - if ( event.target.classList.contains( 'frm-custom-field-group-layout' ) || event.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) { | |
| 3723 | - return; | |
| 3724 | - } | |
| 3725 | - if ( ! jQuery( event.target ).closest( '#frm_field_group_controls' ).length && ! jQuery( event.target ).closest( '#frm_field_group_popup' ).length ) { | |
| 3726 | - destroyFieldGroupPopup(); | |
| 3727 | - } | |
| 3728 | - } | |
| 3729 | - | |
| 3730 | - function getSizeOfFieldGroupFromChildElement( element ) { | |
| 3731 | - var $ul = jQuery( element ).closest( 'ul' ); | |
| 3732 | - if ( $ul.length ) { | |
| 3733 | - return getFieldsInRow( $ul ).length; | |
| 3734 | - } | |
| 3735 | - return getSelectedFieldCount(); | |
| 3736 | - } | |
| 3737 | - | |
| 3738 | - function getFieldGroupPopup( sizeOfFieldGroup, childElement ) { | |
| 3739 | - var popup, wrapper, rowLayoutOptions, ul; | |
| 3740 | - | |
| 3741 | - popup = document.getElementById( 'frm_field_group_popup' ); | |
| 3742 | - if ( null === popup ) { | |
| 3743 | - popup = div(); | |
| 3744 | - } else { | |
| 3745 | - popup.innerHTML = ''; | |
| 3746 | - } | |
| 3747 | - | |
| 3748 | - popup.id = 'frm_field_group_popup'; | |
| 3749 | - | |
| 3750 | - wrapper = div(); | |
| 3751 | - wrapper.style.padding = '0 24px 12px'; | |
| 3752 | - wrapper.appendChild( getRowLayoutTitle() ); | |
| 3753 | - | |
| 3754 | - rowLayoutOptions = getRowLayoutOptions( sizeOfFieldGroup ); | |
| 3755 | - | |
| 3756 | - ul = childElement.closest( 'ul.frm_sorting' ); | |
| 3757 | - if ( null !== ul ) { | |
| 3758 | - maybeMarkRowLayoutAsActive( ul, rowLayoutOptions ); | |
| 3759 | - } | |
| 3760 | - | |
| 3761 | - wrapper.appendChild( rowLayoutOptions ); | |
| 3762 | - | |
| 3763 | - popup.appendChild( wrapper ); | |
| 3764 | - popup.appendChild( separator() ); | |
| 3765 | - | |
| 3766 | - popup.appendChild( getCustomLayoutOption() ); | |
| 3767 | - popup.appendChild( getBreakIntoDifferentRowsOption() ); | |
| 3768 | - | |
| 3769 | - return popup; | |
| 3770 | - } | |
| 3771 | - | |
| 3772 | - function maybeMarkRowLayoutAsActive( activeRow, options ) { | |
| 3773 | - var length, index, currentRow; | |
| 3774 | - | |
| 3775 | - length = options.children.length; | |
| 3776 | - for ( index = 0; index < length; ++index ) { | |
| 3777 | - currentRow = options.children[ index ]; | |
| 3778 | - if ( rowLayoutsMatch( currentRow, activeRow ) ) { | |
| 3779 | - currentRow.classList.add( 'frm-active-row-layout' ); | |
| 3780 | - return; | |
| 3781 | - } | |
| 3782 | - } | |
| 3783 | - } | |
| 3784 | - | |
| 3785 | - function separator() { | |
| 3786 | - var hr = document.createElement( 'hr' ); | |
| 3787 | - return hr; | |
| 3788 | - } | |
| 3789 | - | |
| 3790 | - function getCustomLayoutOption() { | |
| 3791 | - var option = div(); | |
| 3792 | - option.textContent = __( 'Custom layout', 'formidable' ); | |
| 3793 | - jQuery( option ).prepend( getIconClone( 'frm_gear_svg' ) ); | |
| 3794 | - option.classList.add( 'frm-custom-field-group-layout' ); | |
| 3795 | - makeTabbable( option ); | |
| 3796 | - return option; | |
| 3797 | - } | |
| 3798 | - | |
| 3799 | - function makeTabbable( element, ariaLabel ) { | |
| 3800 | - element.setAttribute( 'tabindex', 0 ); | |
| 3801 | - element.setAttribute( 'role', 'button' ); | |
| 3802 | - if ( 'undefined' !== typeof ariaLabel ) { | |
| 3803 | - element.setAttribute( 'aria-label', ariaLabel ); | |
| 3804 | - } | |
| 3805 | - } | |
| 3806 | - | |
| 3807 | - function getIconClone( iconId ) { | |
| 3808 | - var clone = document.getElementById( iconId ).cloneNode( true ); | |
| 3809 | - clone.id = ''; | |
| 3810 | - return clone; | |
| 3811 | - } | |
| 3812 | - | |
| 3813 | - function getBreakIntoDifferentRowsOption() { | |
| 3814 | - var option = div(); | |
| 3815 | - option.textContent = __( 'Break into rows', 'formidable' ); | |
| 3816 | - jQuery( option ).prepend( getIconClone( 'frm_break_field_group_svg' ) ); | |
| 3817 | - option.classList.add( 'frm-break-field-group' ); | |
| 3818 | - makeTabbable( option ); | |
| 3819 | - return option; | |
| 3820 | - } | |
| 3821 | - | |
| 3822 | - function getRowLayoutTitle() { | |
| 3823 | - var rowLayoutTitle = div(); | |
| 3824 | - rowLayoutTitle.classList.add( 'frm-row-layout-title' ); | |
| 3825 | - rowLayoutTitle.textContent = __( 'Row Layout', 'formidable' ); | |
| 3826 | - return rowLayoutTitle; | |
| 3827 | - } | |
| 3828 | - | |
| 3829 | - function getRowLayoutOptions( size ) { | |
| 3830 | - var wrapper, padding; | |
| 3831 | - | |
| 3832 | - wrapper = getEmptyGridContainer(); | |
| 3833 | - if ( 5 !== size ) { | |
| 3834 | - wrapper.appendChild( getRowLayoutOption( size, 'even' ) ); | |
| 3835 | - } | |
| 3836 | - if ( size % 2 === 1 ) { | |
| 3837 | - // only include the middle option for odd numbers because even doesn't make a lot of sense. | |
| 3838 | - wrapper.appendChild( getRowLayoutOption( size, 'middle' ) ); | |
| 3839 | - } | |
| 3840 | - if ( size < 6 ) { | |
| 3841 | - wrapper.appendChild( getRowLayoutOption( size, 'left' ) ); | |
| 3842 | - wrapper.appendChild( getRowLayoutOption( size, 'right' ) ); | |
| 3843 | - } else { | |
| 3844 | - padding = div(); | |
| 3845 | - padding.classList.add( 'frm_fourth' ); | |
| 3846 | - wrapper.prepend( padding ); | |
| 3847 | - } | |
| 3848 | - | |
| 3849 | - return wrapper; | |
| 3850 | - } | |
| 3851 | - | |
| 3852 | - function getRowLayoutOption( size, type ) { | |
| 3853 | - var option, useClass; | |
| 3854 | - | |
| 3855 | - option = div(); | |
| 3856 | - option.classList.add( 'frm-row-layout-option' ); | |
| 3857 | - makeTabbable( option, type ); | |
| 3858 | - | |
| 3859 | - switch ( size ) { | |
| 3860 | - case 6: | |
| 3861 | - useClass = 'frm_half'; | |
| 3862 | - break; | |
| 3863 | - case 5: | |
| 3864 | - useClass = 'frm_third'; | |
| 3865 | - break; | |
| 3866 | - default: | |
| 3867 | - useClass = size % 2 === 1 ? 'frm_fourth' : 'frm_third'; | |
| 3868 | - break; | |
| 3869 | - } | |
| 3870 | - | |
| 3871 | - option.classList.add( useClass ); | |
| 3872 | - option.setAttribute( 'layout-type', type ); | |
| 3873 | - | |
| 3874 | - option.appendChild( getRowForSizeAndType( size, type ) ); | |
| 3875 | - return option; | |
| 3876 | - } | |
| 3877 | - | |
| 3878 | - function rowLayoutsMatch( row1, row2 ) { | |
| 3879 | - return getRowLayoutAsKey( row1 ) === getRowLayoutAsKey( row2 ); | |
| 3880 | - } | |
| 3881 | - | |
| 3882 | - function getRowLayoutAsKey( row ) { | |
| 3883 | - var $fields, sizes; | |
| 3884 | - if ( row.classList.contains( 'frm-row-layout-option' ) ) { | |
| 3885 | - $fields = jQuery( row ).find( '.frm_grid_container' ).children(); | |
| 3886 | - } else { | |
| 3887 | - $fields = getFieldsInRow( jQuery( row ) ); | |
| 3888 | - } | |
| 3889 | - sizes = []; | |
| 3890 | - $fields.each( | |
| 3891 | - function() { | |
| 3892 | - sizes.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) ); | |
| 3893 | - } | |
| 3894 | - ); | |
| 3895 | - return sizes.join( '-' ); | |
| 3896 | - } | |
| 3897 | - | |
| 3898 | - function getRowForSizeAndType( size, type ) { | |
| 3899 | - var row, index, block; | |
| 3900 | - | |
| 3901 | - row = getEmptyGridContainer(); | |
| 3902 | - for ( index = 0; index < size; ++index ) { | |
| 3903 | - block = div(); | |
| 3904 | - block.classList.add( getClassForBlock( size, type, index ) ); | |
| 3905 | - block.style.height = '16px'; | |
| 3906 | - block.style.background = '#9EA9B8'; | |
| 3907 | - block.style.borderRadius = '1px'; | |
| 3908 | - row.appendChild( block ); | |
| 3909 | - } | |
| 3910 | - | |
| 3911 | - return row; | |
| 3912 | - } | |
| 3913 | - | |
| 3914 | - /** | |
| 3915 | - * @param {int} size 2-6. | |
| 3916 | - * @param {string} type even, middle, left, or right. | |
| 3917 | - * @param {int} index 0-5. | |
| 3918 | - * @returns string | |
| 3919 | - */ | |
| 3920 | - function getClassForBlock( size, type, index ) { | |
| 3921 | - if ( 'even' === type ) { | |
| 3922 | - return getEvenClassForSize( size, index ); | |
| 3923 | - } else if ( 'middle' === type ) { | |
| 3924 | - if ( 3 === size ) { | |
| 3925 | - return 1 === index ? 'frm6' : 'frm3'; | |
| 3926 | - } | |
| 3927 | - if ( 5 === size ) { | |
| 3928 | - return 2 === index ? 'frm4' : 'frm2'; | |
| 3929 | - } | |
| 3930 | - } else if ( 'left' === type ) { | |
| 3931 | - return 0 === index ? getLargeClassForSize( size ) : getSmallClassForSize( size ); | |
| 3932 | - } else if ( 'right' === type ) { | |
| 3933 | - return index === size - 1 ? getLargeClassForSize( size ) : getSmallClassForSize( size ); | |
| 3934 | - } | |
| 3935 | - return 'frm12'; | |
| 3936 | - } | |
| 3937 | - | |
| 3938 | - function getEvenClassForSize( size, index ) { | |
| 3939 | - if ( -1 !== [ 2, 3, 4, 6 ].indexOf( size ) ) { | |
| 3940 | - return getLayoutClassForSize( 12 / size ); | |
| 3941 | - } | |
| 3942 | - if ( 5 === size && 'undefined' !== typeof index ) { | |
| 3943 | - return 0 === index ? 'frm4' : 'frm2'; | |
| 3944 | - } | |
| 3945 | - return 'frm12'; | |
| 3946 | - } | |
| 3947 | - | |
| 3948 | - function getSmallClassForSize( size ) { | |
| 3949 | - switch ( size ) { | |
| 3950 | - case 2: case 3: | |
| 3951 | - return 'frm3'; | |
| 3952 | - case 4: | |
| 3953 | - return 'frm2'; | |
| 3954 | - case 5: | |
| 3955 | - return 'frm2'; | |
| 3956 | - case 6: | |
| 3957 | - return 'frm1'; | |
| 3958 | - } | |
| 3959 | - return 'frm12'; | |
| 3960 | - } | |
| 3961 | - | |
| 3962 | - function getLargeClassForSize( size ) { | |
| 3963 | - switch ( size ) { | |
| 3964 | - case 2: | |
| 3965 | - return 'frm9'; | |
| 3966 | - case 3: case 4: | |
| 3967 | - return 'frm6'; | |
| 3968 | - case 5: | |
| 3969 | - return 'frm4'; | |
| 3970 | - case 6: | |
| 3971 | - return 'frm7'; | |
| 3972 | - } | |
| 3973 | - return 'frm12'; | |
| 3974 | - } | |
| 3975 | - | |
| 3976 | - function getEmptyGridContainer() { | |
| 3977 | - var wrapper = div(); | |
| 3978 | - wrapper.classList.add( 'frm_grid_container' ); | |
| 3979 | - return wrapper; | |
| 3980 | - } | |
| 3981 | - | |
| 3982 | - /** | |
| 3983 | - * Handle when a field group layout option (that sets grid classes/column sizing) is selected in the "Row Layout" popup. | |
| 3984 | - * | |
| 3985 | - * @returns {void} | |
| 3986 | - */ | |
| 3987 | - function handleFieldGroupLayoutOptionClick() { | |
| 3988 | - const row = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3989 | - if ( ! row ) { | |
| 3990 | - // The field group layout options also get clicked when merging multiple rows. | |
| 3991 | - // The following code isn't required for multiple rows though so just exit early. | |
| 3992 | - return; | |
| 3993 | - } | |
| 3994 | - | |
| 3995 | - const type = this.getAttribute( 'layout-type' ); | |
| 3996 | - syncLayoutClasses( getFieldsInRow( jQuery( row ) ).first(), type ); | |
| 3997 | - destroyFieldGroupPopup(); | |
| 3998 | - } | |
| 3999 | - | |
| 4000 | - function handleFieldGroupLayoutOptionInsideMergeClick() { | |
| 4001 | - var $ul, type; | |
| 4002 | - $ul = mergeSelectedFieldGroups(); | |
| 4003 | - type = this.getAttribute( 'layout-type' ); | |
| 4004 | - syncLayoutClasses( getFieldsInRow( $ul ).first(), type ); | |
| 4005 | - unselectFieldGroups(); | |
| 4006 | - } | |
| 4007 | - | |
| 4008 | - function mergeSelectedFieldGroups() { | |
| 4009 | - var $selectedFieldGroups = jQuery( '.frm-selected-field-group' ), | |
| 4010 | - $firstGroupUl = $selectedFieldGroups.first(); | |
| 4011 | - $selectedFieldGroups.not( $firstGroupUl ).each( | |
| 4012 | - function() { | |
| 4013 | - getFieldsInRow( jQuery( this ) ).each( | |
| 4014 | - function() { | |
| 4015 | - var previousParent = this.parentNode; | |
| 4016 | - getFieldsInRow( $firstGroupUl ).last().after( this ); | |
| 4017 | - if ( ! jQuery( previousParent ).children( 'li.form-field' ).length ) { | |
| 4018 | - // clean up the previous field group if we've removed all of its fields. | |
| 4019 | - previousParent.closest( 'li.frm_field_box' ).remove(); | |
| 4020 | - } | |
| 4021 | - } | |
| 4022 | - ); | |
| 4023 | - } | |
| 4024 | - ); | |
| 4025 | - updateFieldOrder(); | |
| 4026 | - syncLayoutClasses( getFieldsInRow( $firstGroupUl ).first() ); | |
| 4027 | - return $firstGroupUl; | |
| 4028 | - } | |
| 4029 | - | |
| 4030 | - function customFieldGroupLayoutClick() { | |
| 4031 | - var $fields; | |
| 4032 | - if ( null !== this.closest( '.frm-merge-fields-into-row' ) ) { | |
| 4033 | - return; | |
| 4034 | - } | |
| 4035 | - $fields = getFieldsInRow( jQuery( '.frm-field-group-hover-target' ) ); | |
| 4036 | - setupCustomLayoutOptions( $fields ); | |
| 4037 | - } | |
| 4038 | - | |
| 4039 | - function setupCustomLayoutOptions( $fields ) { | |
| 4040 | - var size, popup, wrapper, layoutClass, inputRow, paddingElement, inputValueOverride, index, inputField, heading, label, buttonsWrapper, cancelButton, saveButton; | |
| 4041 | - | |
| 4042 | - size = $fields.length; | |
| 4043 | - | |
| 4044 | - popup = document.getElementById( 'frm_field_group_popup' ); | |
| 4045 | - popup.innerHTML = ''; | |
| 4046 | - | |
| 4047 | - wrapper = div(); | |
| 4048 | - wrapper.style.padding = '0 24px'; | |
| 4049 | - | |
| 4050 | - layoutClass = getEvenClassForSize( 5 === size ? 6 : size ); | |
| 4051 | - | |
| 4052 | - inputRow = div(); | |
| 4053 | - inputRow.style.padding = '20px 0'; | |
| 4054 | - inputRow.classList.add( 'frm_grid_container' ); | |
| 4055 | - | |
| 4056 | - if ( 5 === size ) { | |
| 4057 | - // add a span to pad the inputs by 1 column, to account for the missing 2 columns. | |
| 4058 | - paddingElement = document.createElement( 'span' ); | |
| 4059 | - paddingElement.classList.add( 'frm1' ); | |
| 4060 | - inputRow.appendChild( paddingElement ); | |
| 4061 | - } | |
| 4062 | - | |
| 4063 | - inputValueOverride = getSelectedFieldCount() > 0 ? getSizeOfLayoutClass( getEvenClassForSize( size ) ) : false; | |
| 4064 | - if ( false !== inputValueOverride && inputValueOverride >= 12 ) { | |
| 4065 | - inputValueOverride = Math.floor( 12 / size ); | |
| 4066 | - } | |
| 4067 | - | |
| 4068 | - for ( index = 0; index < size; ++index ) { | |
| 4069 | - inputField = document.createElement( 'input' ); | |
| 4070 | - inputField.type = 'text'; | |
| 4071 | - inputField.classList.add( layoutClass ); | |
| 4072 | - inputField.classList.add( 'frm-custom-grid-size-input' ); | |
| 4073 | - inputField.value = false !== inputValueOverride ? inputValueOverride : getSizeOfLayoutClass( getLayoutClassName( $fields.get( index ).classList ) ); | |
| 4074 | - inputRow.appendChild( inputField ); | |
| 4075 | - } | |
| 4076 | - | |
| 4077 | - heading = div(); | |
| 4078 | - heading.classList.add( 'frm-builder-popup-heading' ); | |
| 4079 | - heading.textContent = __( 'Enter number of columns for each field', 'formidable' ); | |
| 4080 | - | |
| 4081 | - label = div(); | |
| 4082 | - label.classList.add( 'frm-builder-popup-subheading' ); | |
| 4083 | - label.textContent = __( 'Layouts are based on a 12-column grid system', 'formidable' ); | |
| 4084 | - | |
| 4085 | - wrapper.appendChild( heading ); | |
| 4086 | - wrapper.appendChild( label ); | |
| 4087 | - | |
| 4088 | - wrapper.appendChild( inputRow ); | |
| 4089 | - | |
| 4090 | - buttonsWrapper = div(); | |
| 4091 | - buttonsWrapper.style.textAlign = 'right'; | |
| 4092 | - | |
| 4093 | - cancelButton = getSecondaryButton(); | |
| 4094 | - cancelButton.textContent = __( 'Cancel', 'formidable' ); | |
| 4095 | - cancelButton.classList.add( 'frm-cancel-custom-field-group-layout' ); | |
| 4096 | - cancelButton.style.marginRight = '10px'; | |
| 4097 | - | |
| 4098 | - saveButton = getPrimaryButton(); | |
| 4099 | - saveButton.textContent = __( 'Save', 'formidable' ); | |
| 4100 | - saveButton.classList.add( 'frm-save-custom-field-group-layout' ); | |
| 4101 | - | |
| 4102 | - buttonsWrapper.appendChild( cancelButton ); | |
| 4103 | - buttonsWrapper.appendChild( saveButton ); | |
| 4104 | - | |
| 4105 | - wrapper.appendChild( buttonsWrapper ); | |
| 4106 | - | |
| 4107 | - popup.appendChild( wrapper ); | |
| 4108 | - | |
| 4109 | - setTimeout( | |
| 4110 | - function() { | |
| 4111 | - const firstInput = popup.querySelector( 'input.frm-custom-grid-size-input' ).focus(); | |
| 4112 | - if ( firstInput ) { | |
| 4113 | - firstInput.focus(); | |
| 4114 | - } | |
| 4115 | - }, | |
| 4116 | - 0 | |
| 4117 | - ); | |
| 4118 | - } | |
| 4119 | - | |
| 4120 | - function customFieldGroupLayoutInsideMergeClick() { | |
| 4121 | - $fields = jQuery( '.frm-selected-field-group li.form-field' ); | |
| 4122 | - setupCustomLayoutOptions( $fields ); | |
| 4123 | - } | |
| 4124 | - | |
| 4125 | - function getPrimaryButton() { | |
| 4126 | - var button = getButton(); | |
| 4127 | - button.classList.add( 'button-primary', 'frm-button-primary' ); | |
| 4128 | - return button; | |
| 4129 | - } | |
| 4130 | - | |
| 4131 | - function getSecondaryButton() { | |
| 4132 | - var button = getButton(); | |
| 4133 | - button.classList.add( 'button-secondary', 'frm-button-secondary' ); | |
| 4134 | - return button; | |
| 4135 | - } | |
| 4136 | - | |
| 4137 | - function getButton() { | |
| 4138 | - var button = document.createElement( 'a' ); | |
| 4139 | - button.setAttribute( 'href', '#' ); | |
| 4140 | - button.classList.add( 'button' ); | |
| 4141 | - button.style.textDecoration = 'none'; | |
| 4142 | - return button; | |
| 4143 | - } | |
| 4144 | - | |
| 4145 | - function getSizeOfLayoutClass( className ) { | |
| 4146 | - switch ( className ) { | |
| 4147 | - case 'frm_half': | |
| 4148 | - return 6; | |
| 4149 | - case 'frm_third': | |
| 4150 | - return 4; | |
| 4151 | - case 'frm_two_thirds': | |
| 4152 | - return 8; | |
| 4153 | - case 'frm_fourth': | |
| 4154 | - return 3; | |
| 4155 | - case 'frm_three_fourths': | |
| 4156 | - return 9; | |
| 4157 | - case 'frm_sixth': | |
| 4158 | - return 2; | |
| 4159 | - } | |
| 4160 | - | |
| 4161 | - if ( 0 === className.indexOf( 'frm' ) ) { | |
| 4162 | - return parseInt( className.substr( 3 ) ); | |
| 4163 | - } | |
| 4164 | - | |
| 4165 | - // Anything missing a layout class should be a full width row. | |
| 4166 | - return 12; | |
| 4167 | - } | |
| 4168 | - | |
| 4169 | - function getLayoutClassName( classList ) { | |
| 4170 | - var classes, index, currentClass; | |
| 4171 | - classes = getLayoutClasses(); | |
| 4172 | - for ( index = 0; index < classes.length; ++index ) { | |
| 4173 | - currentClass = classes[ index ]; | |
| 4174 | - if ( classList.contains( currentClass ) ) { | |
| 4175 | - return currentClass; | |
| 4176 | - } | |
| 4177 | - } | |
| 4178 | - return ''; | |
| 4179 | - } | |
| 4180 | - | |
| 4181 | - function getLayoutClassForSize( size ) { | |
| 4182 | - return 'frm' + size; | |
| 4183 | - } | |
| 4184 | - | |
| 4185 | - function breakFieldGroupClick() { | |
| 4186 | - var row = document.querySelector( '.frm-field-group-hover-target' ); | |
| 4187 | - breakRow( row ); | |
| 4188 | - destroyFieldGroupPopup(); | |
| 4189 | - } | |
| 4190 | - | |
| 4191 | - function breakRow( row ) { | |
| 4192 | - const $row = jQuery( row ); | |
| 4193 | - getFieldsInRow( $row ).each( | |
| 4194 | - function( index ) { | |
| 4195 | - const field = this; | |
| 4196 | - if ( 0 !== index ) { | |
| 4197 | - $row.parent().after( wrapFieldLi( field ) ); | |
| 4198 | - } | |
| 4199 | - stripLayoutFromFields( jQuery( field ) ); | |
| 4200 | - } | |
| 4201 | - ); | |
| 4202 | - } | |
| 4203 | - | |
| 4204 | - function stripLayoutFromFields( field ) { | |
| 4205 | - syncLayoutClasses( field, 'clear' ); | |
| 4206 | - } | |
| 4207 | - | |
| 4208 | - function focusFieldGroupInputOnClick() { | |
| 4209 | - this.select(); | |
| 4210 | - } | |
| 4211 | - | |
| 4212 | - function cancelCustomFieldGroupClick() { | |
| 4213 | - revertToFieldGroupPopupFirstPage( this ); | |
| 4214 | - } | |
| 4215 | - | |
| 4216 | - function revertToFieldGroupPopupFirstPage( triggerElement ) { | |
| 4217 | - jQuery( document.getElementById( 'frm_field_group_popup' ) ).replaceWith( | |
| 4218 | - getFieldGroupPopup( getSizeOfFieldGroupFromChildElement( triggerElement ), triggerElement ) | |
| 4219 | - ); | |
| 4220 | - } | |
| 4221 | - | |
| 4222 | - function destroyFieldGroupPopup() { | |
| 4223 | - var popup, wrapper; | |
| 4224 | - popup = document.getElementById( 'frm_field_group_popup' ); | |
| 4225 | - if ( popup === null ) { | |
| 4226 | - return; | |
| 4227 | - } | |
| 4228 | - wrapper = document.querySelector( '.frm-has-open-field-group-popup' ); | |
| 4229 | - if ( null !== wrapper ) { | |
| 4230 | - wrapper.classList.remove( 'frm-has-open-field-group-popup' ); | |
| 4231 | - popup.parentNode.remove(); | |
| 4232 | - } | |
| 4233 | - jQuery( document ).off( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick ); | |
| 4234 | - } | |
| 4235 | - | |
| 4236 | - function saveCustomFieldGroupClick() { | |
| 4237 | - var syncDetails, $controls, $ul; | |
| 4238 | - | |
| 4239 | - syncDetails = []; | |
| 4240 | - | |
| 4241 | - jQuery( document.getElementById( 'frm_field_group_popup' ).querySelectorAll( '.frm_grid_container input' ) ) | |
| 4242 | - .each( | |
| 4243 | - function() { | |
| 4244 | - syncDetails.push( parseInt( this.value ) ); | |
| 4245 | - } | |
| 4246 | - ); | |
| 4247 | - | |
| 4248 | - $controls = jQuery( document.getElementById( 'frm_field_group_controls' ) ); | |
| 4249 | - | |
| 4250 | - if ( $controls.length && 'none' !== $controls.get( 0 ).style.display ) { | |
| 4251 | - syncLayoutClasses( getFieldsInRow( jQuery( document.querySelector( '.frm-field-group-hover-target' ) ) ).first(), syncDetails ); | |
| 4252 | - } else { | |
| 4253 | - $ul = mergeSelectedFieldGroups(); | |
| 4254 | - syncLayoutClasses( getFieldsInRow( $ul ).first(), syncDetails ); | |
| 4255 | - unselectFieldGroups(); | |
| 4256 | - } | |
| 4257 | - | |
| 4258 | - destroyFieldGroupPopup(); | |
| 4259 | - } | |
| 4260 | - | |
| 4261 | - function fieldGroupClick( e ) { | |
| 4262 | - if ( 'ul' !== e.originalEvent.target.nodeName.toLowerCase() ) { | |
| 4263 | - // only continue if the group itself was clicked / ignore when a field is clicked. | |
| 4264 | - return; | |
| 4265 | - } | |
| 4266 | - | |
| 4267 | - const hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 4268 | - if ( ! hoverTarget ) { | |
| 4269 | - return; | |
| 4270 | - } | |
| 4271 | - | |
| 4272 | - const ctrlOrCmdKeyIsDown = e.ctrlKey || e.metaKey; | |
| 4273 | - const shiftKeyIsDown = e.shiftKey; | |
| 4274 | - const groupIsActive = hoverTarget.classList.contains( 'frm-selected-field-group' ); | |
| 4275 | - const $selectedFieldGroups = getSelectedFieldGroups(); | |
| 4276 | - | |
| 4277 | - let numberOfSelectedGroups = $selectedFieldGroups.length; | |
| 4278 | - | |
| 4279 | - if ( ctrlOrCmdKeyIsDown || shiftKeyIsDown ) { | |
| 4280 | - // multi-selecting | |
| 4281 | - | |
| 4282 | - const selectedField = getSelectedField(); | |
| 4283 | - if ( null !== selectedField && ! jQuery( selectedField ).siblings( 'li.form-field' ).length ) { | |
| 4284 | - // count a selected field on its own as a selected field group when multiselecting. | |
| 4285 | - selectedField.parentNode.classList.add( 'frm-selected-field-group' ); | |
| 4286 | - ++numberOfSelectedGroups; | |
| 4287 | - } | |
| 4288 | - | |
| 4289 | - if ( ctrlOrCmdKeyIsDown ) { | |
| 4290 | - if ( groupIsActive ) { | |
| 4291 | - // unselect if holding ctrl or cmd and the group was already active. | |
| 4292 | - --numberOfSelectedGroups; | |
| 4293 | - hoverTarget.classList.remove( 'frm-selected-field-group' ); | |
| 4294 | - syncAfterMultiSelect( numberOfSelectedGroups ); | |
| 4295 | - return; // exit early to avoid adding back frm-selected-field-group | |
| 4296 | - } else { | |
| 4297 | - ++numberOfSelectedGroups; | |
| 4298 | - } | |
| 4299 | - } else if ( shiftKeyIsDown && ! groupIsActive ) { | |
| 4300 | - ++numberOfSelectedGroups; // include the one we're selecting right now. | |
| 4301 | - const $firstGroup = $selectedFieldGroups.first(); | |
| 4302 | - | |
| 4303 | - let $range; | |
| 4304 | - if ( $firstGroup.parent().index() < jQuery( hoverTarget.parentNode ).index() ) { | |
| 4305 | - $range = $firstGroup.parent().nextUntil( hoverTarget.parentNode ); | |
| 4306 | - } else { | |
| 4307 | - $range = $firstGroup.parent().prevUntil( hoverTarget.parentNode ); | |
| 4308 | - } | |
| 4309 | - | |
| 4310 | - $range.each( | |
| 4311 | - function() { | |
| 4312 | - var $fieldGroup = jQuery( this ).closest( 'li' ).find( 'ul.frm_sorting' ); | |
| 4313 | - if ( ! $fieldGroup.hasClass( 'frm-selected-field-group' ) ) { | |
| 4314 | - ++numberOfSelectedGroups; | |
| 4315 | - $fieldGroup.addClass( 'frm-selected-field-group' ); | |
| 4316 | - } | |
| 4317 | - } | |
| 4318 | - ); | |
| 4319 | - | |
| 4320 | - // when holding shift and clicking, text gets selected. unselect it. | |
| 4321 | - document.getSelection().removeAllRanges(); | |
| 4322 | - } | |
| 4323 | - } else { | |
| 4324 | - // not multi-selecting | |
| 4325 | - unselectFieldGroups(); | |
| 4326 | - numberOfSelectedGroups = 1; | |
| 4327 | - } | |
| 4328 | - | |
| 4329 | - hoverTarget.classList.add( 'frm-selected-field-group' ); | |
| 4330 | - syncAfterMultiSelect( numberOfSelectedGroups ); | |
| 4331 | - | |
| 4332 | - jQuery( document ).off( 'click', unselectFieldGroups ); | |
| 4333 | - jQuery( document ).on( 'click', unselectFieldGroups ); | |
| 4334 | - } | |
| 4335 | - | |
| 4336 | - function getSelectedField() { | |
| 4337 | - return document.getElementById( 'frm-show-fields' ).querySelector( 'li.form-field.selected' ); | |
| 4338 | - } | |
| 4339 | - | |
| 4340 | - function getSelectedFieldGroups() { | |
| 4341 | - const $fieldGroups = jQuery( '.frm-selected-field-group' ); | |
| 4342 | - if ( $fieldGroups.length ) { | |
| 4343 | - return $fieldGroups; | |
| 4344 | - } | |
| 4345 | - | |
| 4346 | - const selectedField = getSelectedField(); | |
| 4347 | - if ( selectedField ) { | |
| 4348 | - // If there is only one field in a group and the field is selected, consider the field's group as selected for multi-select. | |
| 4349 | - const selectedFieldGroup = selectedField.closest( 'ul' ); | |
| 4350 | - if ( selectedFieldGroup && 1 === getFieldsInRow( jQuery( selectedFieldGroup ) ).length ) { | |
| 4351 | - selectedFieldGroup.classList.add( 'frm-selected-field-group' ); | |
| 4352 | - return jQuery( selectedFieldGroup ); | |
| 4353 | - } | |
| 4354 | - } | |
| 4355 | - | |
| 4356 | - return jQuery(); | |
| 4357 | - } | |
| 4358 | - | |
| 4359 | - function syncAfterMultiSelect( numberOfSelectedGroups ) { | |
| 4360 | - clearSettingsBox( true ); // unselect any fields if one is selected. | |
| 4361 | - if ( numberOfSelectedGroups >= 2 || ( 1 === numberOfSelectedGroups && selectedGroupHasMultipleFields() ) ) { | |
| 4362 | - addFieldMultiselectPopup(); | |
| 4363 | - } else { | |
| 4364 | - maybeRemoveMultiselectPopup(); | |
| 4365 | - } | |
| 4366 | - maybeRemoveGroupHoverTarget(); | |
| 4367 | - } | |
| 4368 | - | |
| 4369 | - function selectedGroupHasMultipleFields() { | |
| 4370 | - return getFieldsInRow( jQuery( document.querySelector( '.frm-selected-field-group' ) ) ).length > 1; | |
| 4371 | - } | |
| 4372 | - | |
| 4373 | - function unselectFieldGroups( event ) { | |
| 4374 | - if ( 'undefined' !== typeof event ) { | |
| 4375 | - if ( null !== event.originalEvent.target.closest( '#frm-show-fields' ) ) { | |
| 4376 | - return; | |
| 4377 | - } | |
| 4378 | - if ( event.originalEvent.target.classList.contains( 'frm-merge-fields-into-row' ) ) { | |
| 4379 | - return; | |
| 4380 | - } | |
| 4381 | - if ( null !== event.originalEvent.target.closest( '.frm-merge-fields-into-row' ) ) { | |
| 4382 | - return; | |
| 4383 | - } | |
| 4384 | - if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) { | |
| 4385 | - return; | |
| 4386 | - } | |
| 4387 | - if ( event.originalEvent.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) { | |
| 4388 | - return; | |
| 4389 | - } | |
| 4390 | - } | |
| 4391 | - jQuery( '.frm-selected-field-group' ).removeClass( 'frm-selected-field-group' ); | |
| 4392 | - jQuery( document ).off( 'click', unselectFieldGroups ); | |
| 4393 | - maybeRemoveMultiselectPopup(); | |
| 4394 | - } | |
| 4395 | - | |
| 4396 | - function maybeRemoveMultiselectPopup() { | |
| 4397 | - var popup = document.getElementById( 'frm_field_multiselect_popup' ); | |
| 4398 | - if ( null !== popup ) { | |
| 4399 | - popup.remove(); | |
| 4400 | - } | |
| 4401 | - } | |
| 4402 | - | |
| 4403 | - function addFieldMultiselectPopup() { | |
| 4404 | - getFieldMultiselectPopup(); | |
| 4405 | - } | |
| 4406 | - | |
| 4407 | - function getFieldMultiselectPopup() { | |
| 4408 | - var popup, mergeOption, caret, verticalSeparator, deleteOption; | |
| 4409 | - | |
| 4410 | - popup = document.getElementById( 'frm_field_multiselect_popup' ); | |
| 4411 | - | |
| 4412 | - if ( null !== popup ) { | |
| 4413 | - popup.classList.toggle( 'frm-unmergable', ! selectedFieldsAreMergable() ); | |
| 4414 | - return popup; | |
| 4415 | - } | |
| 4416 | - | |
| 4417 | - popup = div(); | |
| 4418 | - popup.id = 'frm_field_multiselect_popup'; | |
| 4419 | - if ( ! selectedFieldsAreMergable() ) { | |
| 4420 | - popup.classList.add( 'frm-unmergable' ); | |
| 4421 | - } | |
| 4422 | - | |
| 4423 | - mergeOption = div(); | |
| 4424 | - mergeOption.classList.add( 'frm-merge-fields-into-row' ); | |
| 4425 | - mergeOption.textContent = __( 'Merge into row', 'formidable' ); | |
| 4426 | - | |
| 4427 | - caret = document.createElement( 'a' ); | |
| 4428 | - caret.style.marginLeft = '5px'; | |
| 4429 | - caret.classList.add( 'frm_icon_font', 'frm_arrowdown6_icon' ); | |
| 4430 | - caret.setAttribute( 'href', '#' ); | |
| 4431 | - mergeOption.appendChild( caret ); | |
| 4432 | - | |
| 4433 | - popup.appendChild( mergeOption ); | |
| 4434 | - | |
| 4435 | - verticalSeparator = div(); | |
| 4436 | - verticalSeparator.classList.add( 'frm-multiselect-popup-separator' ); | |
| 4437 | - popup.appendChild( verticalSeparator ); | |
| 4438 | - | |
| 4439 | - deleteOption = div(); | |
| 4440 | - deleteOption.classList.add( 'frm-delete-field-groups' ); | |
| 4441 | - deleteOption.appendChild( getIconClone( 'frm_trash_svg' ) ); | |
| 4442 | - popup.appendChild( deleteOption ); | |
| 4443 | - | |
| 4444 | - document.getElementById( 'post-body-content' ).appendChild( popup ); | |
| 4445 | - | |
| 4446 | - jQuery( popup ).hide().fadeIn(); | |
| 4447 | - | |
| 4448 | - return popup; | |
| 4449 | - } | |
| 4450 | - | |
| 4451 | - function selectedFieldsAreMergable() { | |
| 4452 | - var selectedFieldGroups, totalFieldCount, length, index, fieldGroup; | |
| 4453 | - selectedFieldGroups = document.querySelectorAll( '.frm-selected-field-group' ); | |
| 4454 | - length = selectedFieldGroups.length; | |
| 4455 | - if ( 1 === length ) { | |
| 4456 | - return false; | |
| 4457 | - } | |
| 4458 | - totalFieldCount = 0; | |
| 4459 | - for ( index = 0; index < length; ++index ) { | |
| 4460 | - fieldGroup = selectedFieldGroups[ index ]; | |
| 4461 | - if ( null !== fieldGroup.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ) ) { | |
| 4462 | - return false; | |
| 4463 | - } | |
| 4464 | - totalFieldCount += getFieldsInRow( jQuery( fieldGroup ) ).length; | |
| 4465 | - if ( totalFieldCount > 6 ) { | |
| 4466 | - return false; | |
| 4467 | - } | |
| 4468 | - } | |
| 4469 | - return true; | |
| 4470 | - } | |
| 4471 | - | |
| 4472 | - function mergeFieldsIntoRowClick( event ) { | |
| 4473 | - var size, popup; | |
| 4474 | - | |
| 4475 | - if ( null !== event.originalEvent.target.closest( '#frm_field_group_popup' ) ) { | |
| 4476 | - // prevent clicks within the popup from triggering the button again. | |
| 4477 | - return; | |
| 4478 | - } | |
| 4479 | - | |
| 4480 | - if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) { | |
| 4481 | - // avoid switching back to the first page when clicking the custom option nested inside of the merge option. | |
| 4482 | - return; | |
| 4483 | - } | |
| 4484 | - | |
| 4485 | - size = getSelectedFieldCount(); | |
| 4486 | - popup = getFieldGroupPopup( size, document.querySelector( '.frm-selected-field-group' ).firstChild ); | |
| 4487 | - this.appendChild( popup ); | |
| 4488 | - } | |
| 4489 | - | |
| 4490 | - function getSelectedFieldCount() { | |
| 4491 | - var count = 0; | |
| 4492 | - jQuery( document.querySelectorAll( '.frm-selected-field-group' ) ).each( | |
| 4493 | - function() { | |
| 4494 | - count += getFieldsInRow( jQuery( this ) ).length; | |
| 4495 | - } | |
| 4496 | - ); | |
| 4497 | - return count; | |
| 4498 | - } | |
| 4499 | - | |
| 4500 | - function deleteFieldGroupsClick() { | |
| 4501 | - var fieldIdsToDelete, deleteOnConfirm, multiselectPopup; | |
| 4502 | - | |
| 4503 | - fieldIdsToDelete = getSelectedFieldIds(); | |
| 4504 | - deleteOnConfirm = getDeleteSelectedFieldGroupsOnConfirmFunction( fieldIdsToDelete ); | |
| 4505 | - | |
| 4506 | - multiselectPopup = document.getElementById( 'frm_field_multiselect_popup' ); | |
| 4507 | - if ( null !== multiselectPopup ) { | |
| 4508 | - multiselectPopup.remove(); | |
| 4509 | - } | |
| 4510 | - | |
| 4511 | - this.setAttribute( 'data-frmverify', confirmFieldsDeleteMessage( fieldIdsToDelete.length ) ); | |
| 4512 | - confirmLinkClick( this ); | |
| 4513 | - | |
| 4514 | - jQuery( '#frm-confirmed-click' ).on( 'click', deleteOnConfirm ); | |
| 4515 | - jQuery( '#frm_confirm_modal' ).one( 'dialogclose', function() { | |
| 4516 | - jQuery( '#frm-confirmed-click' ).off( 'click', deleteOnConfirm ); | |
| 4517 | - }); | |
| 4518 | - } | |
| 4519 | - | |
| 4520 | - function getSelectedFieldIds() { | |
| 4521 | - var deleteFieldIds = []; | |
| 4522 | - jQuery( '.frm-selected-field-group > li.form-field' ) | |
| 4523 | - .each( | |
| 4524 | - function() { | |
| 4525 | - deleteFieldIds.push( this.dataset.fid ); | |
| 4526 | - } | |
| 4527 | - ); | |
| 4528 | - return deleteFieldIds; | |
| 4529 | - } | |
| 4530 | - | |
| 4531 | - function getDeleteSelectedFieldGroupsOnConfirmFunction( deleteFieldIds ) { | |
| 4532 | - return function( event ) { | |
| 4533 | - event.preventDefault(); | |
| 4534 | - deleteAllSelectedFieldGroups( deleteFieldIds ); | |
| 4535 | - }; | |
| 4536 | - } | |
| 4537 | - | |
| 4538 | - function deleteAllSelectedFieldGroups( deleteFieldIds ) { | |
| 4539 | - deleteFieldIds.forEach( | |
| 4540 | - function( fieldId ) { | |
| 4541 | - deleteFields( fieldId ); | |
| 4542 | - } | |
| 4543 | - ); | |
| 4544 | - } | |
| 4545 | - | |
| 4546 | - function deleteFieldConfirmed() { | |
| 4547 | - /*jshint validthis:true */ | |
| 4548 | - deleteFields( this.getAttribute( 'data-deletefield' ) ); | |
| 4549 | - } | |
| 4550 | - | |
| 4551 | - function deleteFields( fieldId ) { | |
| 4552 | - var field = jQuery( '#frm_field_id_' + fieldId ); | |
| 4553 | - | |
| 4554 | - deleteField( fieldId ); | |
| 4555 | - | |
| 4556 | - if ( field.hasClass( 'edit_field_type_divider' ) ) { | |
| 4557 | - field.find( 'li.frm_field_box' ).each( function() { | |
| 4558 | - //TODO: maybe delete only end section | |
| 4559 | - //if(n.hasClass('edit_field_type_end_divider')){ | |
| 4560 | - deleteField( this.getAttribute( 'data-fid' ) ); | |
| 4561 | - //} | |
| 4562 | - }); | |
| 4563 | - } | |
| 4564 | - toggleSectionHolder(); | |
| 4565 | - } | |
| 4566 | - | |
| 4567 | - function deleteField( fieldId ) { | |
| 4568 | - jQuery.ajax({ | |
| 4569 | - type: 'POST', | |
| 4570 | - url: ajaxurl, | |
| 4571 | - data: { | |
| 4572 | - action: 'frm_delete_field', | |
| 4573 | - field_id: fieldId, | |
| 4574 | - nonce: frmGlobal.nonce | |
| 4575 | - }, | |
| 4576 | - success: function() { | |
| 4577 | - var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ), | |
| 4578 | - settings = jQuery( '#frm-single-settings-' + fieldId ); | |
| 4579 | - | |
| 4580 | - // Remove settings from sidebar. | |
| 4581 | - if ( settings.is( ':visible' ) ) { | |
| 4582 | - document.getElementById( 'frm_insert_fields_tab' ).click(); | |
| 4583 | - } | |
| 4584 | - settings.remove(); | |
| 4585 | - | |
| 4586 | - $thisField.fadeOut( 'slow', function() { | |
| 4587 | - var $section = $thisField.closest( '.start_divider' ), | |
| 4588 | - type = $thisField.data( 'type' ), | |
| 4589 | - $adjacentFields = $thisField.siblings( 'li.form-field' ), | |
| 4590 | - $liWrapper; | |
| 4591 | - | |
| 4592 | - if ( ! $adjacentFields.length ) { | |
| 4593 | - if ( $thisField.is( '.edit_field_type_end_divider' ) ) { | |
| 4594 | - $adjacentFields.length = $thisField.closest( 'li.form-field' ).siblings(); | |
| 4595 | - } else { | |
| 4596 | - $liWrapper = $thisField.closest( 'ul.frm_sorting' ).parent(); | |
| 4597 | - } | |
| 4598 | - } | |
| 4599 | - | |
| 4600 | - $thisField.remove(); | |
| 4601 | - if ( type === 'break' ) { | |
| 4602 | - renumberPageBreaks(); | |
| 4603 | - } | |
| 4604 | - if ( type === 'product' ) { | |
| 4605 | - maybeHideQuantityProductFieldOption(); | |
| 4606 | - // a product field attached to a quantity field earlier might be the one deleted, so re-populate | |
| 4607 | - popAllProductFields(); | |
| 4608 | - } | |
| 4609 | - if ( jQuery( '#frm-show-fields li' ).length === 0 ) { | |
| 4610 | - document.getElementById( 'frm_form_editor_container' ).classList.remove( 'frm-has-fields' ); | |
| 4611 | - } else if ( $section.length ) { | |
| 4612 | - toggleOneSectionHolder( $section ); | |
| 4613 | - } | |
| 4614 | - if ( $adjacentFields.length ) { | |
| 4615 | - syncLayoutClasses( $adjacentFields.first() ); | |
| 4616 | - } else { | |
| 4617 | - $liWrapper.remove(); | |
| 4618 | - } | |
| 4619 | - | |
| 4620 | - // prevent "More Options" tooltips from staying around after their target field is deleted. | |
| 4621 | - deleteTooltips(); | |
| 4622 | - }); | |
| 4623 | - } | |
| 4624 | - }); | |
| 4625 | - } | |
| 4626 | - | |
| 4627 | - function addFieldLogicRow() { | |
| 4628 | - /*jshint validthis:true */ | |
| 4629 | - var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 4630 | - formId = thisFormId, | |
| 4631 | - logicRows = document.getElementById( 'frm_logic_row_' + id ).querySelectorAll( '.frm_logic_row' ); | |
| 4632 | - jQuery.ajax({ | |
| 4633 | - type: 'POST', | |
| 4634 | - url: ajaxurl, | |
| 4635 | - data: { | |
| 4636 | - action: 'frm_add_logic_row', | |
| 4637 | - form_id: formId, | |
| 4638 | - field_id: id, | |
| 4639 | - nonce: frmGlobal.nonce, | |
| 4640 | - meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ), | |
| 4641 | - fields: getFieldList() | |
| 4642 | - }, | |
| 4643 | - success: function( html ) { | |
| 4644 | - jQuery( document.getElementById( 'logic_' + id ) ).fadeOut( 'slow', function() { | |
| 4645 | - var logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) ); | |
| 4646 | - logicRow.append( html ); | |
| 4647 | - logicRow.closest( '.frm_logic_rows' ).fadeIn( 'slow' ); | |
| 4648 | - }); | |
| 4649 | - } | |
| 4650 | - }); | |
| 4651 | - return false; | |
| 4652 | - } | |
| 4653 | - | |
| 4654 | - function getNewRowId( rows, replace, defaultValue ) { | |
| 4655 | - if ( ! rows.length ) { | |
| 4656 | - return 'undefined' !== typeof defaultValue ? defaultValue : 0; | |
| 4657 | - } | |
| 4658 | - return parseInt( rows[ rows.length - 1 ].id.replace( replace, '' ), 10 ) + 1; | |
| 4659 | - } | |
| 4660 | - | |
| 4661 | - function addWatchLookupRow() { | |
| 4662 | - /*jshint validthis:true */ | |
| 4663 | - var lastRowId, | |
| 4664 | - id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 4665 | - formId = thisFormId, | |
| 4666 | - lookupBlockRows = document.getElementById( 'frm_watch_lookup_block_' + id ).children; | |
| 4667 | - jQuery.ajax({ | |
| 4668 | - type: 'POST', | |
| 4669 | - url: ajaxurl, | |
| 4670 | - data: { | |
| 4671 | - action: 'frm_add_watch_lookup_row', | |
| 4672 | - form_id: formId, | |
| 4673 | - field_id: id, | |
| 4674 | - row_key: getNewRowId( lookupBlockRows, 'frm_watch_lookup_' + id + '_' ), | |
| 4675 | - nonce: frmGlobal.nonce | |
| 4676 | - }, | |
| 4677 | - success: function( newRow ) { | |
| 4678 | - var watchRowBlock = jQuery( document.getElementById( 'frm_watch_lookup_block_' + id ) ); | |
| 4679 | - watchRowBlock.append( newRow ); | |
| 4680 | - watchRowBlock.fadeIn( 'slow' ); | |
| 4681 | - } | |
| 4682 | - }); | |
| 4683 | - return false; | |
| 4684 | - } | |
| 4685 | - | |
| 4686 | - function resetOptionTextDetails() { | |
| 4687 | - jQuery( '.frm-single-settings ul input[type="text"][name^="field_options[options_"]' ).filter( '[data-value-on-load]' ).removeAttr( 'data-value-on-load' ); | |
| 4688 | - jQuery( 'input[type="hidden"][name^=optionmap]' ).remove(); | |
| 4689 | - } | |
| 4690 | - | |
| 4691 | - function optionTextAlreadyExists( input ) { | |
| 4692 | - var fieldId = jQuery( input ).closest( '.frm-single-settings' ).attr( 'data-fid' ), | |
| 4693 | - optionInputs = jQuery( input ).closest( 'ul' ).get( 0 ).querySelectorAll( '.field_' + fieldId + '_option' ), | |
| 4694 | - index, | |
| 4695 | - optionInput; | |
| 4696 | - | |
| 4697 | - for ( index in optionInputs ) { | |
| 4698 | - optionInput = optionInputs[ index ]; | |
| 4699 | - if ( optionInput.id !== input.id && optionInput.value === input.value && optionInput.getAttribute( 'data-duplicate' ) !== 'true' ) { | |
| 4700 | - return true; | |
| 4701 | - } | |
| 4702 | - } | |
| 4703 | - | |
| 4704 | - return false; | |
| 4705 | - } | |
| 4706 | - | |
| 4707 | - function onOptionTextFocus() { | |
| 4708 | - var input, | |
| 4709 | - fieldId; | |
| 4710 | - | |
| 4711 | - if ( this.getAttribute( 'data-value-on-load' ) === null ) { | |
| 4712 | - this.setAttribute( 'data-value-on-load', this.value ); | |
| 4713 | - | |
| 4714 | - fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' ); | |
| 4715 | - input = document.createElement( 'input' ); | |
| 4716 | - input.value = this.value; | |
| 4717 | - input.setAttribute( 'type', 'hidden' ); | |
| 4718 | - input.setAttribute( 'name', 'optionmap[' + fieldId + '][' + this.value + ']' ); | |
| 4719 | - this.parentNode.appendChild( input ); | |
| 4720 | - | |
| 4721 | - if ( typeof optionMap[ fieldId ] === 'undefined' ) { | |
| 4722 | - optionMap[ fieldId ] = {}; | |
| 4723 | - } | |
| 4724 | - | |
| 4725 | - optionMap[ fieldId ][ this.value ] = input; | |
| 4726 | - } | |
| 4727 | - | |
| 4728 | - if ( this.getAttribute( 'data-duplicate' ) === 'true' ) { | |
| 4729 | - this.removeAttribute( 'data-duplicate' ); | |
| 4730 | - | |
| 4731 | - // we want to use original value if actually still a duplicate | |
| 4732 | - if ( optionTextAlreadyExists( this ) ) { | |
| 4733 | - this.setAttribute( 'data-value-on-focus', this.getAttribute( 'data-value-on-load' ) ); | |
| 4734 | - return; | |
| 4735 | - } | |
| 4736 | - } | |
| 4737 | - | |
| 4738 | - if ( '' !== this.value || frm_admin_js.new_option !== this.getAttribute( 'data-value-on-focus' ) ) { // eslint-disable-line camelcase | |
| 4739 | - this.setAttribute( 'data-value-on-focus', this.value ); | |
| 4740 | - } | |
| 4741 | - } | |
| 4742 | - | |
| 4743 | - function onOptionTextBlur() { | |
| 4744 | - var originalValue, | |
| 4745 | - oldValue = this.getAttribute( 'data-value-on-focus' ), | |
| 4746 | - newValue = this.value, | |
| 4747 | - fieldId, | |
| 4748 | - fieldIndex, | |
| 4749 | - logicId, | |
| 4750 | - row, | |
| 4751 | - rowLength, | |
| 4752 | - rowIndex, | |
| 4753 | - valueSelect, | |
| 4754 | - opts, | |
| 4755 | - fieldIds, | |
| 4756 | - settingId, | |
| 4757 | - setting, | |
| 4758 | - optionMatches, | |
| 4759 | - option; | |
| 4760 | - | |
| 4761 | - if ( oldValue === newValue ) { | |
| 4762 | - return; | |
| 4763 | - } | |
| 4764 | - | |
| 4765 | - fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' ); | |
| 4766 | - originalValue = this.getAttribute( 'data-value-on-load' ); | |
| 4767 | - | |
| 4768 | - // check if the newValue is already mapped to another option | |
| 4769 | - // if it is, mark as duplicate and return | |
| 4770 | - if ( optionTextAlreadyExists( this ) ) { | |
| 4771 | - this.setAttribute( 'data-duplicate', 'true' ); | |
| 4772 | - | |
| 4773 | - if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) { | |
| 4774 | - // unmap any other change that may have happened before instead of changing it to something unused | |
| 4775 | - optionMap[ fieldId ][ originalValue ].value = originalValue; | |
| 4776 | - } | |
| 4777 | - | |
| 4778 | - return; | |
| 4779 | - } | |
| 4780 | - | |
| 4781 | - if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) { | |
| 4782 | - optionMap[ fieldId ][ originalValue ].value = newValue; | |
| 4783 | - } | |
| 4784 | - | |
| 4785 | - fieldIds = []; | |
| 4786 | - rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ); | |
| 4787 | - rowLength = rows.length; | |
| 4788 | - for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) { | |
| 4789 | - row = rows[ rowIndex ]; | |
| 4790 | - opts = row.querySelector( '.frm_logic_field_opts' ); | |
| 4791 | - | |
| 4792 | - if ( opts.value !== fieldId ) { | |
| 4793 | - continue; | |
| 4794 | - } | |
| 4795 | - | |
| 4796 | - logicId = row.id.split( '_' )[ 2 ]; | |
| 4797 | - valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' ); | |
| 4798 | - | |
| 4799 | - if ( '' === oldValue ) { | |
| 4800 | - optionMatches = []; | |
| 4801 | - } else { | |
| 4802 | - optionMatches = valueSelect.querySelectorAll( 'option[value="' + oldValue + '"]' ); | |
| 4803 | - } | |
| 4804 | - | |
| 4805 | - if ( ! optionMatches.length ) { | |
| 4806 | - optionMatches = valueSelect.querySelectorAll( 'option[value="' + newValue + '"]' ); | |
| 4807 | - | |
| 4808 | - if ( ! optionMatches.length ) { | |
| 4809 | - option = document.createElement( 'option' ); | |
| 4810 | - valueSelect.appendChild( option ); | |
| 4811 | - } | |
| 4812 | - } | |
| 4813 | - | |
| 4814 | - if ( optionMatches.length ) { | |
| 4815 | - option = optionMatches[ optionMatches.length - 1 ]; | |
| 4816 | - } | |
| 4817 | - | |
| 4818 | - option.setAttribute( 'value', newValue ); | |
| 4819 | - option.textContent = newValue; | |
| 4820 | - | |
| 4821 | - if ( fieldIds.indexOf( logicId ) === -1 ) { | |
| 4822 | - fieldIds.push( logicId ); | |
| 4823 | - } | |
| 4824 | - } | |
| 4825 | - | |
| 4826 | - for ( fieldIndex in fieldIds ) { | |
| 4827 | - settingId = fieldIds[ fieldIndex ]; | |
| 4828 | - setting = document.getElementById( 'frm-single-settings-' + settingId ); | |
| 4829 | - moveFieldSettings( setting ); | |
| 4830 | - } | |
| 4831 | - } | |
| 4832 | - | |
| 4833 | - function updateGetValueFieldSelection() { | |
| 4834 | - /*jshint validthis:true */ | |
| 4835 | - var fieldID = this.id.replace( 'get_values_form_', '' ); | |
| 4836 | - var fieldSelect = document.getElementById( 'get_values_field_' + fieldID ); | |
| 4837 | - var fieldType = this.getAttribute( 'data-fieldtype' ); | |
| 4838 | - | |
| 4839 | - if ( this.value === '' ) { | |
| 4840 | - fieldSelect.options.length = 1; | |
| 4841 | - } else { | |
| 4842 | - var formID = this.value; | |
| 4843 | - jQuery.ajax({ | |
| 4844 | - type: 'POST', url: ajaxurl, | |
| 4845 | - data: { | |
| 4846 | - action: 'frm_get_options_for_get_values_field', | |
| 4847 | - form_id: formID, | |
| 4848 | - field_type: fieldType, | |
| 4849 | - nonce: frmGlobal.nonce | |
| 4850 | - }, | |
| 4851 | - success: function( fields ) { | |
| 4852 | - fieldSelect.innerHTML = fields; | |
| 4853 | - } | |
| 4854 | - }); | |
| 4855 | - } | |
| 4856 | - } | |
| 4857 | - | |
| 4858 | - // Clear the Watch Fields option when Lookup field switches to "Text" option | |
| 4859 | - function maybeClearWatchFields() { | |
| 4860 | - /*jshint validthis:true */ | |
| 4861 | - var link, lookupBlock, | |
| 4862 | - fieldID = this.name.replace( 'field_options[data_type_', '' ).replace( ']', '' ); | |
| 4863 | - | |
| 4864 | - link = document.getElementById( 'frm_add_watch_lookup_link_' + fieldID ).parentNode; | |
| 4865 | - | |
| 4866 | - if ( this.value === 'text' ) { | |
| 4867 | - lookupBlock = document.getElementById( 'frm_watch_lookup_block_' + fieldID ); | |
| 4868 | - if ( lookupBlock !== null ) { | |
| 4869 | - // Clear and hide the Watch Fields option | |
| 4870 | - lookupBlock.innerHTML = ''; | |
| 4871 | - link.classList.add( 'frm_hidden' ); | |
| 4872 | - | |
| 4873 | - // Hide the Watch Fields row | |
| 4874 | - link.previousElementSibling.style.display = 'none'; | |
| 4875 | - link.previousElementSibling.previousElementSibling.style.display = 'none'; | |
| 4876 | - link.previousElementSibling.previousElementSibling.previousElementSibling.style.display = 'none'; | |
| 4877 | - } | |
| 4878 | - } else { | |
| 4879 | - // Show the Watch Fields option | |
| 4880 | - link.classList.remove( 'frm_hidden' ); | |
| 4881 | - } | |
| 4882 | - | |
| 4883 | - toggleMultiSelect( fieldID, this.value ); | |
| 4884 | - } | |
| 4885 | - | |
| 4886 | - // Number the pages and hide/show the first page as needed. | |
| 4887 | - function renumberPageBreaks() { | |
| 4888 | - var i, containerClass, | |
| 4889 | - pages = document.getElementsByClassName( 'frm-page-num' ); | |
| 4890 | - | |
| 4891 | - if ( pages.length > 1 ) { | |
| 4892 | - document.getElementById( 'frm-fake-page' ).style.display = 'block'; | |
| 4893 | - for ( i = 0; i < pages.length; i++ ) { | |
| 4894 | - containerClass = pages[i].parentNode.parentNode.parentNode.classList; | |
| 4895 | - if ( i === 1 ) { | |
| 4896 | - // Hide previous button on page 1 | |
| 4897 | - containerClass.add( 'frm-first-page' ); | |
| 4898 | - } else { | |
| 4899 | - containerClass.remove( 'frm-first-page' ); | |
| 4900 | - } | |
| 4901 | - pages[i].textContent = ( i + 1 ); | |
| 4902 | - } | |
| 4903 | - } else { | |
| 4904 | - document.getElementById( 'frm-fake-page' ).style.display = 'none'; | |
| 4905 | - } | |
| 4906 | - } | |
| 4907 | - | |
| 4908 | - // The fake field works differently than real fields. | |
| 4909 | - function maybeCollapsePage() { | |
| 4910 | - /*jshint validthis:true */ | |
| 4911 | - var field = jQuery( this ).closest( '.frm_field_box[data-ftype=break]' ); | |
| 4912 | - if ( field.length ) { | |
| 4913 | - toggleCollapsePage( field ); | |
| 4914 | - } else { | |
| 4915 | - toggleCollapseFakePage(); | |
| 4916 | - } | |
| 4917 | - } | |
| 4918 | - | |
| 4919 | - // Find all fields in a page and hide/show them | |
| 4920 | - function toggleCollapsePage( field ) { | |
| 4921 | - var toCollapse = getAllFieldsForPage( field.get( 0 ).parentNode.closest( 'li.frm_field_box' ).nextElementSibling ); | |
| 4922 | - togglePage( field, toCollapse ); | |
| 4923 | - } | |
| 4924 | - | |
| 4925 | - function toggleCollapseFakePage() { | |
| 4926 | - var topLevel = document.getElementById( 'frm-fake-page' ), | |
| 4927 | - firstField = document.getElementById( 'frm-show-fields' ).firstElementChild, | |
| 4928 | - toCollapse = getAllFieldsForPage( firstField ); | |
| 4929 | - | |
| 4930 | - if ( firstField.getAttribute( 'data-ftype' ) === 'break' ) { | |
| 4931 | - // Don't collapse if the first field is a page break. | |
| 4932 | - return; | |
| 4933 | - } | |
| 4934 | - | |
| 4935 | - togglePage( jQuery( topLevel ), toCollapse ); | |
| 4936 | - } | |
| 4937 | - | |
| 4938 | - function getAllFieldsForPage( firstWrapper ) { | |
| 4939 | - var $fieldsForPage, currentWrapper; | |
| 4940 | - | |
| 4941 | - $fieldsForPage = jQuery(); | |
| 4942 | - | |
| 4943 | - if ( null === firstWrapper ) { | |
| 4944 | - return $fieldsForPage; | |
| 4945 | - } | |
| 4946 | - | |
| 4947 | - currentWrapper = firstWrapper; | |
| 4948 | - | |
| 4949 | - do { | |
| 4950 | - if ( null !== currentWrapper.querySelector( '.edit_field_type_break' ) ) { | |
| 4951 | - break; | |
| 4952 | - } | |
| 4953 | - $fieldsForPage = $fieldsForPage.add( jQuery( currentWrapper ) ); | |
| 4954 | - currentWrapper = currentWrapper.nextElementSibling; | |
| 4955 | - } while ( null !== currentWrapper ); | |
| 4956 | - | |
| 4957 | - return $fieldsForPage; | |
| 4958 | - } | |
| 4959 | - | |
| 4960 | - function togglePage( field, toCollapse ) { | |
| 4961 | - var i, | |
| 4962 | - fieldCount = toCollapse.length, | |
| 4963 | - slide = Math.min( fieldCount, 3 ); | |
| 4964 | - | |
| 4965 | - if ( field.hasClass( 'frm-page-collapsed' ) ) { | |
| 4966 | - field.removeClass( 'frm-page-collapsed' ); | |
| 4967 | - toCollapse.removeClass( 'frm-is-collapsed' ); | |
| 4968 | - for ( i = 0; i < slide; i++ ) { | |
| 4969 | - if ( i === slide - 1 ) { | |
| 4970 | - jQuery( toCollapse[ i ]).slideDown( 150, function() { | |
| 4971 | - toCollapse.show(); | |
| 4972 | - }); | |
| 4973 | - } else { | |
| 4974 | - jQuery( toCollapse[ i ]).slideDown( 150 ); | |
| 4975 | - } | |
| 4976 | - } | |
| 4977 | - } else { | |
| 4978 | - field.addClass( 'frm-page-collapsed' ); | |
| 4979 | - toCollapse.addClass( 'frm-is-collapsed' ); | |
| 4980 | - for ( i = 0; i < slide; i++ ) { | |
| 4981 | - if ( i === slide - 1 ) { | |
| 4982 | - jQuery( toCollapse[ i ]).slideUp( 150, function() { | |
| 4983 | - toCollapse.css( 'cssText', 'display:none !important;' ); | |
| 4984 | - }); | |
| 4985 | - } else { | |
| 4986 | - jQuery( toCollapse[ i ]).slideUp( 150 ); | |
| 4987 | - } | |
| 4988 | - } | |
| 4989 | - } | |
| 4990 | - } | |
| 4991 | - | |
| 4992 | - function maybeCollapseSection() { | |
| 4993 | - /*jshint validthis:true */ | |
| 4994 | - var parentCont = this.parentNode.parentNode.parentNode.parentNode; | |
| 4995 | - | |
| 4996 | - parentCont.classList.toggle( 'frm-section-collapsed' ); | |
| 4997 | - } | |
| 4998 | - | |
| 4999 | - function maybeCollapseSettings() { | |
| 5000 | - /*jshint validthis:true */ | |
| 5001 | - this.classList.toggle( 'frm-collapsed' ); | |
| 5002 | - | |
| 5003 | - // Toggles the "aria-expanded" attribute | |
| 5004 | - let expanded = this.getAttribute( 'aria-expanded' ) === 'true' || false; | |
| 5005 | - this.setAttribute( 'aria-expanded', ! expanded ); | |
| 5006 | - } | |
| 5007 | - | |
| 5008 | - function clickLabel() { | |
| 5009 | - if ( ! this.id ) { | |
| 5010 | - return; | |
| 5011 | - } | |
| 5012 | - | |
| 5013 | - /*jshint validthis:true */ | |
| 5014 | - var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0], | |
| 5015 | - fieldId = this.id.replace( 'field_label_', '' ), | |
| 5016 | - fieldType = document.getElementById( 'field_options_type_' + fieldId ), | |
| 5017 | - fieldTypeName = fieldType.value; | |
| 5018 | - | |
| 5019 | - if ( typeof setting !== 'undefined' ) { | |
| 5020 | - if ( fieldType.tagName === 'SELECT' ) { | |
| 5021 | - fieldTypeName = fieldType.options[ fieldType.selectedIndex ].text.toLowerCase(); | |
| 5022 | - } else { | |
| 5023 | - fieldTypeName = fieldTypeName.replace( '_', ' ' ); | |
| 5024 | - } | |
| 5025 | - | |
| 5026 | - fieldTypeName = normalizeFieldName( fieldTypeName ); | |
| 5027 | - | |
| 5028 | - setTimeout( function() { | |
| 5029 | - if ( setting.value.toLowerCase() === fieldTypeName ) { | |
| 5030 | - setting.select(); | |
| 5031 | - } else { | |
| 5032 | - setting.focus(); | |
| 5033 | - } | |
| 5034 | - }, 50 ); | |
| 5035 | - } | |
| 5036 | - } | |
| 5037 | - | |
| 5038 | - function clickDescription() { | |
| 5039 | - /*jshint validthis:true */ | |
| 5040 | - var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0]; | |
| 5041 | - if ( typeof setting !== 'undefined' ) { | |
| 5042 | - setTimeout( function() { | |
| 5043 | - setting.focus(); | |
| 5044 | - autoExpandSettings( setting ); | |
| 5045 | - }, 50 ); | |
| 5046 | - } | |
| 5047 | - } | |
| 5048 | - | |
| 5049 | - function autoExpandSettings( setting ) { | |
| 5050 | - var inSection = setting.closest( '.frm-collapse-me' ); | |
| 5051 | - if ( inSection !== null ) { | |
| 5052 | - inSection.previousElementSibling.classList.remove( 'frm-collapsed' ); | |
| 5053 | - } | |
| 5054 | - } | |
| 5055 | - | |
| 5056 | - function normalizeFieldName( fieldTypeName ) { | |
| 5057 | - if ( fieldTypeName === 'divider' ) { | |
| 5058 | - fieldTypeName = 'section'; | |
| 5059 | - } else if ( fieldTypeName === 'range' ) { | |
| 5060 | - fieldTypeName = 'slider'; | |
| 5061 | - } else if ( fieldTypeName === 'data' ) { | |
| 5062 | - fieldTypeName = 'dynamic'; | |
| 5063 | - } else if ( fieldTypeName === 'form' ) { | |
| 5064 | - fieldTypeName = 'embed form'; | |
| 5065 | - } | |
| 5066 | - return fieldTypeName; | |
| 5067 | - } | |
| 5068 | - | |
| 5069 | - function clickVis( e ) { | |
| 5070 | - /*jshint validthis:true */ | |
| 5071 | - var currentClass, originalList; | |
| 5072 | - | |
| 5073 | - currentClass = e.target.classList; | |
| 5074 | - | |
| 5075 | - if ( currentClass.contains( 'frm-collapse-page' ) || currentClass.contains( 'frm-sub-label' ) || e.target.closest( '.dropdown' ) !== null ) { | |
| 5076 | - return; | |
| 5077 | - } | |
| 5078 | - | |
| 5079 | - if ( this.closest( '.start_divider' ) !== null ) { | |
| 5080 | - e.stopPropagation(); | |
| 5081 | - } | |
| 5082 | - | |
| 5083 | - if ( this.classList.contains( 'edit_field_type_divider' ) ) { | |
| 5084 | - originalList = e.originalEvent.target.closest( 'ul.frm_sorting' ); | |
| 5085 | - if ( null !== originalList ) { | |
| 5086 | - // prevent section click if clicking a field group within a section. | |
| 5087 | - if ( originalList.classList.contains( 'edit_field_type_divider' ) || originalList.parentNode.parentNode.classList.contains( 'start_divider' ) ) { | |
| 5088 | - return; | |
| 5089 | - } | |
| 5090 | - } | |
| 5091 | - } | |
| 5092 | - | |
| 5093 | - clickAction( this ); | |
| 5094 | - } | |
| 5095 | - | |
| 5096 | - /** | |
| 5097 | - * Open Advanced settings on double click. | |
| 5098 | - */ | |
| 5099 | - function openAdvanced() { | |
| 5100 | - var fieldId = this.getAttribute( 'data-fid' ); | |
| 5101 | - autoExpandSettings( document.getElementById( 'field_options_field_key_' + fieldId ) ); | |
| 5102 | - } | |
| 5103 | - | |
| 5104 | - function toggleRepeatButtons() { | |
| 5105 | - /*jshint validthis:true */ | |
| 5106 | - var $thisField = jQuery( this ).closest( '.frm_field_box' ); | |
| 5107 | - $thisField.find( '.repeat_icon_links' ).removeClass( 'repeat_format repeat_formatboth repeat_formattext' ).addClass( 'repeat_format' + this.value ); | |
| 5108 | - if ( this.value === 'text' || this.value === 'both' ) { | |
| 5109 | - $thisField.find( '.frm_repeat_text' ).show(); | |
| 5110 | - $thisField.find( '.repeat_icon_links a' ).addClass( 'frm_button' ); | |
| 5111 | - } else { | |
| 5112 | - $thisField.find( '.frm_repeat_text' ).hide(); | |
| 5113 | - $thisField.find( '.repeat_icon_links a' ).removeClass( 'frm_button' ); | |
| 5114 | - } | |
| 5115 | - } | |
| 5116 | - | |
| 5117 | - function checkRepeatLimit() { | |
| 5118 | - /*jshint validthis:true */ | |
| 5119 | - var val = this.value; | |
| 5120 | - if ( val !== '' && ( val < 2 || val > 200 ) ) { | |
| 5121 | - infoModal( frm_admin_js.repeat_limit_min ); // eslint-disable-line camelcase | |
| 5122 | - this.value = ''; | |
| 5123 | - } | |
| 5124 | - } | |
| 5125 | - | |
| 5126 | - function checkCheckboxSelectionsLimit() { | |
| 5127 | - /*jshint validthis:true */ | |
| 5128 | - var val = this.value; | |
| 5129 | - if ( val !== '' && ( val < 1 || val > 200 ) ) { | |
| 5130 | - infoModal( frm_admin_js.checkbox_limit ); // eslint-disable-line camelcase | |
| 5131 | - this.value = ''; | |
| 5132 | - } | |
| 5133 | - } | |
| 5134 | - | |
| 5135 | - function updateRepeatText( obj, addRemove ) { | |
| 5136 | - var $thisField = jQuery( obj ).closest( '.frm_field_box' ); | |
| 5137 | - $thisField.find( '.frm_' + addRemove + '_form_row .frm_repeat_label' ).text( obj.value ); | |
| 5138 | - } | |
| 5139 | - | |
| 5140 | - function fieldsInSection( id ) { | |
| 5141 | - var children = []; | |
| 5142 | - jQuery( document.getElementById( 'frm_field_id_' + id ) ).find( 'li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)' ).each( function() { | |
| 5143 | - children.push( jQuery( this ).data( 'fid' ) ); | |
| 5144 | - }); | |
| 5145 | - return children; | |
| 5146 | - } | |
| 5147 | - | |
| 5148 | - function toggleFormTax() { | |
| 5149 | - /*jshint validthis:true */ | |
| 5150 | - var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 5151 | - var val = this.value; | |
| 5152 | - var $showFields = document.getElementById( 'frm_show_selected_fields_' + id ); | |
| 5153 | - var $showForms = document.getElementById( 'frm_show_selected_forms_' + id ); | |
| 5154 | - | |
| 5155 | - jQuery( $showForms ).find( 'select' ).val( '' ); | |
| 5156 | - if ( val === 'form' ) { | |
| 5157 | - $showForms.style.display = 'inline'; | |
| 5158 | - empty( $showFields ); | |
| 5159 | - } else { | |
| 5160 | - $showFields.style.display = 'none'; | |
| 5161 | - $showForms.style.display = 'none'; | |
| 5162 | - getTaxOrFieldSelection( val, id ); | |
| 5163 | - } | |
| 5164 | - | |
| 5165 | - } | |
| 5166 | - | |
| 5167 | - function resetOptOnChange() { | |
| 5168 | - /*jshint validthis:true */ | |
| 5169 | - var field, thisOpt; | |
| 5170 | - | |
| 5171 | - field = getFieldKeyFromOpt( this ); | |
| 5172 | - if ( ! field ) { | |
| 5173 | - return; | |
| 5174 | - } | |
| 5175 | - | |
| 5176 | - thisOpt = jQuery( this ).closest( '.frm_single_option' ); | |
| 5177 | - | |
| 5178 | - resetSingleOpt( field.fieldId, field.fieldKey, thisOpt ); | |
| 5179 | - } | |
| 5180 | - | |
| 5181 | - function getFieldKeyFromOpt( object ) { | |
| 5182 | - var allOpts, fieldId, fieldKey; | |
| 5183 | - | |
| 5184 | - allOpts = jQuery( object ).closest( '.frm_sortable_field_opts' ); | |
| 5185 | - if ( ! allOpts.length ) { | |
| 5186 | - return false; | |
| 5187 | - } | |
| 5188 | - | |
| 5189 | - fieldId = allOpts.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_opts', '' ); | |
| 5190 | - fieldKey = allOpts.data( 'key' ); | |
| 5191 | - | |
| 5192 | - return { | |
| 5193 | - fieldId: fieldId, | |
| 5194 | - fieldKey: fieldKey | |
| 5195 | - }; | |
| 5196 | - } | |
| 5197 | - | |
| 5198 | - function resetSingleOpt( fieldId, fieldKey, thisOpt ) { | |
| 5199 | - var saved, text, defaultVal, previewInput, labelForDisplay, optContainer, | |
| 5200 | - optKey = thisOpt.data( 'optkey' ), | |
| 5201 | - separateValues = usingSeparateValues( fieldId ), | |
| 5202 | - single = jQuery( 'label[for="field_' + fieldKey + '-' + optKey + '"]' ), | |
| 5203 | - baseName = 'field_options[options_' + fieldId + '][' + optKey + ']', | |
| 5204 | - label = jQuery( 'input[name="' + baseName + '[label]"]' ); | |
| 5205 | - | |
| 5206 | - if ( single.length < 1 ) { | |
| 5207 | - resetDisplayedOpts( fieldId ); | |
| 5208 | - | |
| 5209 | - // Set the default value. | |
| 5210 | - defaultVal = thisOpt.find( 'input[name^="default_value_"]' ); | |
| 5211 | - if ( defaultVal.is( ':checked' ) && label.length > 0 ) { | |
| 5212 | - jQuery( 'select[name^="item_meta[' + fieldId + ']"]' ).val( label.val() ); | |
| 5213 | - } | |
| 5214 | - return; | |
| 5215 | - } | |
| 5216 | - | |
| 5217 | - previewInput = single.children( 'input' ); | |
| 5218 | - | |
| 5219 | - if ( label.length < 1 ) { | |
| 5220 | - // Check for other label. | |
| 5221 | - label = jQuery( 'input[name="' + baseName + '"]' ); | |
| 5222 | - saved = label.val(); | |
| 5223 | - } else if ( separateValues ) { | |
| 5224 | - saved = jQuery( 'input[name="' + baseName + '[value]"]' ).val(); | |
| 5225 | - } else { | |
| 5226 | - saved = label.val(); | |
| 5227 | - } | |
| 5228 | - | |
| 5229 | - if ( label.length < 1 ) { | |
| 5230 | - return; | |
| 5231 | - } | |
| 5232 | - | |
| 5233 | - // Set the displayed value. | |
| 5234 | - text = single[0].childNodes; | |
| 5235 | - | |
| 5236 | - if ( imagesAsOptions( fieldId ) ) { | |
| 5237 | - labelForDisplay = getImageDisplayValue( thisOpt, fieldId, label ); | |
| 5238 | - optContainer = single.find( '.frm_image_option_container' ); | |
| 5239 | - | |
| 5240 | - if ( optContainer.length > 0 ) { | |
| 5241 | - optContainer.replaceWith( labelForDisplay ); | |
| 5242 | - } else { | |
| 5243 | - text[ text.length - 1 ].nodeValue = ''; | |
| 5244 | - single.append( labelForDisplay ); | |
| 5245 | - } | |
| 5246 | - } else { | |
| 5247 | - let firstInputIndex = false; | |
| 5248 | - text.forEach( ( node, index ) => { | |
| 5249 | - if ( firstInputIndex === false ) { | |
| 5250 | - if ( node.tagName === 'INPUT' ) { | |
| 5251 | - firstInputIndex = index; | |
| 5252 | - } | |
| 5253 | - } else { | |
| 5254 | - if ( index === firstInputIndex + 1 ) { | |
| 5255 | - let nodeValue = ''; | |
| 5256 | - | |
| 5257 | - if ( buttonsAsOptions( fieldId ) ) { | |
| 5258 | - nodeValue = div({ className: 'frm_label_button_container', text: ' ' + label.val() }); | |
| 5259 | - single[0].replaceChild( nodeValue, node ); | |
| 5260 | - } else { | |
| 5261 | - node.nodeValue = ' ' + label.val(); | |
| 5262 | - } | |
| 5263 | - } else { | |
| 5264 | - single[0].removeChild( node ); | |
| 5265 | - } | |
| 5266 | - } | |
| 5267 | - }); | |
| 5268 | - } | |
| 5269 | - | |
| 5270 | - // Set saved value. | |
| 5271 | - previewInput.val( saved ); | |
| 5272 | - | |
| 5273 | - // Set the default value. | |
| 5274 | - defaultVal = thisOpt.find( 'input[name^="default_value_"]' ); | |
| 5275 | - previewInput.prop( 'checked', defaultVal.is( ':checked' ) ? true : false ); | |
| 5276 | - } | |
| 5277 | - | |
| 5278 | - function buttonsAsOptions( fieldId ) { | |
| 5279 | - const fields = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' ); | |
| 5280 | - const result = Array.from( fields ).find( field => field.checked && ( 'buttons' === field.value ) ); | |
| 5281 | - | |
| 5282 | - return typeof result !== 'undefined'; | |
| 5283 | - } | |
| 5284 | - | |
| 5285 | - /** | |
| 5286 | - * Set the displayed value for an image option. | |
| 5287 | - */ | |
| 5288 | - function getImageDisplayValue( thisOpt, fieldId, label ) { | |
| 5289 | - var image, imageUrl, showLabelWithImage, fieldType; | |
| 5290 | - | |
| 5291 | - image = thisOpt.find( 'img' ); | |
| 5292 | - if ( image ) { | |
| 5293 | - imageUrl = image.attr( 'src' ); | |
| 5294 | - } | |
| 5295 | - | |
| 5296 | - showLabelWithImage = showingLabelWithImage( fieldId ); | |
| 5297 | - fieldType = radioOrCheckbox( fieldId ); | |
| 5298 | - return getImageLabel( label.val(), showLabelWithImage, imageUrl, fieldType ); | |
| 5299 | - } | |
| 5300 | - | |
| 5301 | - function getImageOptionSize( fieldId ) { | |
| 5302 | - var val, | |
| 5303 | - field = document.getElementById( 'field_options_image_size_' + fieldId ), | |
| 5304 | - size = ''; | |
| 5305 | - | |
| 5306 | - if ( field !== null ) { | |
| 5307 | - val = field.value; | |
| 5308 | - if ( val !== '' ) { | |
| 5309 | - size = val; | |
| 5310 | - } | |
| 5311 | - } | |
| 5312 | - | |
| 5313 | - return size; | |
| 5314 | - } | |
| 5315 | - | |
| 5316 | - function resetDisplayedOpts( fieldId ) { | |
| 5317 | - var i, opts, type, placeholder, fieldInfo, | |
| 5318 | - input = jQuery( '[name^="item_meta[' + fieldId + ']"]' ); | |
| 5319 | - | |
| 5320 | - if ( input.length < 1 ) { | |
| 5321 | - return; | |
| 5322 | - } | |
| 5323 | - | |
| 5324 | - if ( input.is( 'select' ) ) { | |
| 5325 | - placeholder = document.getElementById( 'frm_placeholder_' + fieldId ); | |
| 5326 | - if ( placeholder !== null && placeholder.value === '' ) { | |
| 5327 | - fillDropdownOpts( input[0], { sourceID: fieldId }); | |
| 5328 | - } else { | |
| 5329 | - fillDropdownOpts( input[0], { | |
| 5330 | - sourceID: fieldId, | |
| 5331 | - placeholder: placeholder.value | |
| 5332 | - }); | |
| 5333 | - } | |
| 5334 | - } else { | |
| 5335 | - opts = getMultipleOpts( fieldId ); | |
| 5336 | - type = input.attr( 'type' ); | |
| 5337 | - jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ).html( '' ); | |
| 5338 | - fieldInfo = getFieldKeyFromOpt( jQuery( '#frm_delete_field_' + fieldId + '-000_container' ) ); | |
| 5339 | - | |
| 5340 | - var container = jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ), | |
| 5341 | - hasImageOptions = imagesAsOptions( fieldId ), | |
| 5342 | - imageSize = hasImageOptions ? getImageOptionSize( fieldId ) : '', | |
| 5343 | - imageOptionClass = hasImageOptions ? ( 'frm_image_option frm_image_' + imageSize + ' ' ) : '', | |
| 5344 | - isProduct = isProductField( fieldId ); | |
| 5345 | - | |
| 5346 | - for ( i = 0; i < opts.length; i++ ) { | |
| 5347 | - container.append( addRadioCheckboxOpt( type, opts[ i ], fieldId, fieldInfo.fieldKey, isProduct, imageOptionClass ) ); | |
| 5348 | - } | |
| 5349 | - } | |
| 5350 | - | |
| 5351 | - adjustConditionalLogicOptionOrders( fieldId ); | |
| 5352 | - } | |
| 5353 | - | |
| 5354 | - function adjustConditionalLogicOptionOrders( fieldId, type ) { | |
| 5355 | - var row, opts, logicId, valueSelect, optionLength, optionIndex, expectedOption, optionMatch, fieldOptions, | |
| 5356 | - rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ), | |
| 5357 | - rowLength = rows.length; | |
| 5358 | - | |
| 5359 | - fieldOptions = wp.hooks.applyFilters( 'frm_conditional_logic_field_options', getFieldOptions( fieldId ), { type, fieldId }); | |
| 5360 | - optionLength = fieldOptions.length; | |
| 5361 | - | |
| 5362 | - for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) { | |
| 5363 | - row = rows[ rowIndex ]; | |
| 5364 | - opts = row.querySelector( '.frm_logic_field_opts' ); | |
| 5365 | - | |
| 5366 | - if ( opts.value != fieldId ) { | |
| 5367 | - continue; | |
| 5368 | - } | |
| 5369 | - | |
| 5370 | - logicId = row.id.split( '_' )[ 2 ]; | |
| 5371 | - valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' ); | |
| 5372 | - | |
| 5373 | - for ( optionIndex = optionLength - 1; optionIndex >= 0; optionIndex-- ) { | |
| 5374 | - expectedOption = fieldOptions[ optionIndex ]; | |
| 5375 | - optionMatch = valueSelect.querySelector( 'option[value="' + expectedOption + '"]' ); | |
| 5376 | - | |
| 5377 | - if ( optionMatch === null ) { | |
| 5378 | - optionMatch = document.createElement( 'option' ); | |
| 5379 | - optionMatch.setAttribute( 'value', expectedOption ); | |
| 5380 | - optionMatch.textContent = expectedOption; | |
| 5381 | - } | |
| 5382 | - | |
| 5383 | - valueSelect.prepend( optionMatch ); | |
| 5384 | - } | |
| 5385 | - | |
| 5386 | - optionMatch = valueSelect.querySelector( 'option[value=""]' ); | |
| 5387 | - if ( optionMatch !== null ) { | |
| 5388 | - valueSelect.prepend( optionMatch ); | |
| 5389 | - } | |
| 5390 | - } | |
| 5391 | - } | |
| 5392 | - | |
| 5393 | - function getFieldOptions( fieldId ) { | |
| 5394 | - var index, input, li, listItems, optsContainer, length, | |
| 5395 | - options = []; | |
| 5396 | - optsContainer = document.getElementById( 'frm_field_' + fieldId + '_opts' ); | |
| 5397 | - | |
| 5398 | - if ( ! optsContainer ) { | |
| 5399 | - return options; | |
| 5400 | - } | |
| 5401 | - listItems = optsContainer.querySelectorAll( '.frm_single_option' ); | |
| 5402 | - length = listItems.length; | |
| 5403 | - | |
| 5404 | - for ( index = 0; index < length; index++ ) { | |
| 5405 | - li = listItems[ index ]; | |
| 5406 | - | |
| 5407 | - if ( li.classList.contains( 'frm_hidden' ) ) { | |
| 5408 | - continue; | |
| 5409 | - } | |
| 5410 | - | |
| 5411 | - input = li.querySelector( '.field_' + fieldId + '_option' ); | |
| 5412 | - options.push( input.value ); | |
| 5413 | - } | |
| 5414 | - return options; | |
| 5415 | - } | |
| 5416 | - | |
| 5417 | - function addRadioCheckboxOpt( type, opt, fieldId, fieldKey, isProduct, classes ) { | |
| 5418 | - var other, single, | |
| 5419 | - isOther = opt.key.indexOf( 'other' ) !== -1, | |
| 5420 | - id = 'field_' + fieldKey + '-' + opt.key, | |
| 5421 | - inputType = type === 'scale' ? 'radio' : type; | |
| 5422 | - | |
| 5423 | - 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="" />'; | |
| 5424 | - | |
| 5425 | - single = '<div class="frm_' + type + ' ' + type + ' ' + classes + '" id="frm_' + type + '_' + fieldId + '-' + opt.key + '"><label for="' + id + | |
| 5426 | - '"><input type="' + inputType + | |
| 5427 | - '" name="item_meta[' + fieldId + ']' + ( type === 'checkbox' ? '[]' : '' ) + | |
| 5428 | - '" value="' + purifyHtml( opt.saved ) + '" id="' + id + '"' + ( isProduct ? ' data-price="' + opt.price + '"' : '' ) + ( opt.checked ? ' checked="checked"' : '' ) + '> ' + purifyHtml( opt.label ) + '</label>' + | |
| 5429 | - ( isOther ? other : '' ) + | |
| 5430 | - '</div>'; | |
| 5431 | - | |
| 5432 | - return single; | |
| 5433 | - } | |
| 5434 | - | |
| 5435 | - function fillDropdownOpts( field, atts ) { | |
| 5436 | - if ( field === null ) { | |
| 5437 | - return; | |
| 5438 | - } | |
| 5439 | - var sourceID = atts.sourceID, | |
| 5440 | - placeholder = atts.placeholder, | |
| 5441 | - isProduct = isProductField( sourceID ), | |
| 5442 | - showOther = atts.other; | |
| 5443 | - | |
| 5444 | - removeDropdownOpts( field ); | |
| 5445 | - var opts = getMultipleOpts( sourceID ), | |
| 5446 | - hasPlaceholder = ( typeof placeholder !== 'undefined' ); | |
| 5447 | - | |
| 5448 | - for ( var i = 0; i < opts.length; i++ ) { | |
| 5449 | - var label = opts[ i ].label, | |
| 5450 | - isOther = opts[ i ].key.indexOf( 'other' ) !== -1; | |
| 5451 | - | |
| 5452 | - if ( hasPlaceholder && label !== '' ) { | |
| 5453 | - addBlankSelectOption( field, placeholder ); | |
| 5454 | - } else if ( hasPlaceholder ) { | |
| 5455 | - label = placeholder; | |
| 5456 | - } | |
| 5457 | - hasPlaceholder = false; | |
| 5458 | - | |
| 5459 | - if ( ! isOther || showOther ) { | |
| 5460 | - var opt = document.createElement( 'option' ); | |
| 5461 | - opt.value = opts[ i ].saved; | |
| 5462 | - opt.innerHTML = purifyHtml( label ); | |
| 5463 | - | |
| 5464 | - if ( isProduct ) { | |
| 5465 | - opt.setAttribute( 'data-price', opts[ i ].price ); | |
| 5466 | - } | |
| 5467 | - | |
| 5468 | - field.appendChild( opt ); | |
| 5469 | - } | |
| 5470 | - } | |
| 5471 | - } | |
| 5472 | - | |
| 5473 | - function addBlankSelectOption( field, placeholder ) { | |
| 5474 | - var opt = document.createElement( 'option' ), | |
| 5475 | - firstChild = field.firstChild; | |
| 5476 | - | |
| 5477 | - opt.value = ''; | |
| 5478 | - opt.innerHTML = placeholder; | |
| 5479 | - if ( firstChild !== null ) { | |
| 5480 | - field.insertBefore( opt, firstChild ); | |
| 5481 | - field.selectedIndex = 0; | |
| 5482 | - } else { | |
| 5483 | - field.appendChild( opt ); | |
| 5484 | - } | |
| 5485 | - } | |
| 5486 | - | |
| 5487 | - function getMultipleOpts( fieldId ) { | |
| 5488 | - let i, saved, labelName, label, key, optObj, | |
| 5489 | - fieldType, | |
| 5490 | - checked = false, | |
| 5491 | - opts = [], | |
| 5492 | - imageUrl = ''; | |
| 5493 | - | |
| 5494 | - const optVals = jQuery( 'input[name^="field_options[options_' + fieldId + ']"]' ); | |
| 5495 | - const isProduct = isProductField( fieldId ); | |
| 5496 | - const showLabelWithImage = showingLabelWithImage( fieldId ); | |
| 5497 | - const hasImageOptions = imagesAsOptions( fieldId ); | |
| 5498 | - const separateValues = usingSeparateValues( fieldId ); | |
| 5499 | - | |
| 5500 | - for ( i = 0; i < optVals.length; i++ ) { | |
| 5501 | - 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 ) { | |
| 5502 | - continue; | |
| 5503 | - } | |
| 5504 | - | |
| 5505 | - saved = optVals[ i ].value; | |
| 5506 | - label = saved; | |
| 5507 | - key = optVals[ i ].name.replace( 'field_options[options_' + fieldId + '][', '' ).replace( '[label]', '' ).replace( ']', '' ); | |
| 5508 | - | |
| 5509 | - if ( separateValues ) { | |
| 5510 | - labelName = optVals[ i ].name.replace( '[label]', '[value]' ); | |
| 5511 | - saved = jQuery( 'input[name="' + labelName + '"]' ).val(); | |
| 5512 | - } | |
| 5513 | - | |
| 5514 | - if ( hasImageOptions ) { | |
| 5515 | - imageUrl = getImageUrlFromInput( optVals[i]); | |
| 5516 | - fieldType = radioOrCheckbox( fieldId ); | |
| 5517 | - label = getImageLabel( label, showLabelWithImage, imageUrl, fieldType ); | |
| 5518 | - } | |
| 5519 | - | |
| 5520 | - /** | |
| 5521 | - * @since 5.0.04 | |
| 5522 | - */ | |
| 5523 | - label = frmAdminBuild.hooks.applyFilters( 'frm_choice_field_label', label, fieldId, optVals[ i ], hasImageOptions ); | |
| 5524 | - | |
| 5525 | - checked = getChecked( optVals[ i ].id ); | |
| 5526 | - | |
| 5527 | - optObj = { | |
| 5528 | - saved: saved, | |
| 5529 | - label: label, | |
| 5530 | - checked: checked, | |
| 5531 | - key: key | |
| 5532 | - }; | |
| 5533 | - | |
| 5534 | - if ( isProduct ) { | |
| 5535 | - labelName = optVals[ i ].name.replace( '[label]', '[price]' ); | |
| 5536 | - optObj.price = jQuery( 'input[name="' + labelName + '"]' ).val(); | |
| 5537 | - } | |
| 5538 | - | |
| 5539 | - opts.push( optObj ); | |
| 5540 | - } | |
| 5541 | - | |
| 5542 | - return opts; | |
| 5543 | - } | |
| 5544 | - | |
| 5545 | - function radioOrCheckbox( fieldId ) { | |
| 5546 | - var settings = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 5547 | - if ( settings === null ) { | |
| 5548 | - return 'radio'; | |
| 5549 | - } | |
| 5550 | - | |
| 5551 | - return settings.classList.contains( 'frm-type-checkbox' ) ? 'checkbox' : 'radio'; | |
| 5552 | - } | |
| 5553 | - | |
| 5554 | - function getImageUrlFromInput( optVal ) { | |
| 5555 | - var img, | |
| 5556 | - wrapper = jQuery( optVal ).siblings( '.frm_image_preview_wrapper' ); | |
| 5557 | - | |
| 5558 | - if ( ! wrapper.length ) { | |
| 5559 | - return ''; | |
| 5560 | - } | |
| 5561 | - | |
| 5562 | - img = wrapper.find( 'img' ); | |
| 5563 | - if ( ! img.length ) { | |
| 5564 | - return ''; | |
| 5565 | - } | |
| 5566 | - | |
| 5567 | - return img.attr( 'src' ); | |
| 5568 | - } | |
| 5569 | - | |
| 5570 | - function purifyHtml( html ) { | |
| 5571 | - if ( html instanceof Element || html instanceof Document ) { | |
| 5572 | - html = html.outerHTML; | |
| 5573 | - } | |
| 5574 | - | |
| 5575 | - const clean = jQuery.parseHTML( html ).reduce( | |
| 5576 | - ( total, currentNode ) => { | |
| 5577 | - const cleanNode = frmDom.cleanNode( currentNode ); | |
| 5578 | - | |
| 5579 | - if ( '#text' === cleanNode.nodeName ) { | |
| 5580 | - return total += cleanNode.textContent; | |
| 5581 | - } | |
| 5582 | - | |
| 5583 | - return total + cleanNode.outerHTML; | |
| 5584 | - }, | |
| 5585 | - '' | |
| 5586 | - ); | |
| 5587 | - | |
| 5588 | - return clean; | |
| 5589 | - } | |
| 5590 | - | |
| 5591 | - function getImageLabel( label, showLabelWithImage, imageUrl, fieldType ) { | |
| 5592 | - var imageLabelClass, | |
| 5593 | - originalLabel = label, | |
| 5594 | - shape = fieldType === 'checkbox' ? 'square' : 'circle', | |
| 5595 | - labelImage, | |
| 5596 | - labelNode, | |
| 5597 | - imageLabel; | |
| 5598 | - | |
| 5599 | - originalLabel = purifyHtml( originalLabel ); | |
| 5600 | - | |
| 5601 | - if ( imageUrl ) { | |
| 5602 | - labelImage = img({ src: imageUrl, alt: originalLabel }); | |
| 5603 | - } else { | |
| 5604 | - labelImage = div({ className: 'frm_empty_url' }); | |
| 5605 | - labelImage.innerHTML = frm_admin_js.image_placeholder_icon; // eslint-disable-line camelcase | |
| 5606 | - } | |
| 5607 | - | |
| 5608 | - imageLabelClass = showLabelWithImage ? ' frm_label_with_image' : ''; | |
| 5609 | - | |
| 5610 | - imageLabel = tag( 'span', { className: 'frm_text_label_for_image_inner' }); | |
| 5611 | - | |
| 5612 | - imageLabel.innerHTML = originalLabel; | |
| 5613 | - labelNode = tag( | |
| 5614 | - 'span', | |
| 5615 | - { | |
| 5616 | - className: 'frm_image_option_container' + imageLabelClass, | |
| 5617 | - children: [ | |
| 5618 | - tag( 'div', { className: 'frm_selected_checkmark', child: svg({ href: '#frm_checkmark_' + shape + '_icon' }) }), | |
| 5619 | - labelImage, | |
| 5620 | - tag( 'span', { className: 'frm_text_label_for_image', child: imageLabel }) | |
| 5621 | - ] | |
| 5622 | - } | |
| 5623 | - ); | |
| 5624 | - | |
| 5625 | - return labelNode; | |
| 5626 | - } | |
| 5627 | - | |
| 5628 | - function getChecked( id ) { | |
| 5629 | - field = jQuery( '#' + id ); | |
| 5630 | - | |
| 5631 | - if ( field.length === 0 ) { | |
| 5632 | - return false; | |
| 5633 | - } | |
| 5634 | - | |
| 5635 | - checkbox = field.siblings( 'input[type=checkbox]' ); | |
| 5636 | - | |
| 5637 | - return checkbox.length && checkbox.prop( 'checked' ); | |
| 5638 | - } | |
| 5639 | - | |
| 5640 | - function removeDropdownOpts( field ) { | |
| 5641 | - var i; | |
| 5642 | - if ( typeof field.options === 'undefined' ) { | |
| 5643 | - return; | |
| 5644 | - } | |
| 5645 | - | |
| 5646 | - for ( i = field.options.length - 1; i >= 0; i-- ) { | |
| 5647 | - field.remove( i ); | |
| 5648 | - } | |
| 5649 | - } | |
| 5650 | - | |
| 5651 | - /** | |
| 5652 | - * Is the box checked to use separate values? | |
| 5653 | - */ | |
| 5654 | - function usingSeparateValues( fieldId ) { | |
| 5655 | - return isChecked( 'separate_value_' + fieldId ); | |
| 5656 | - } | |
| 5657 | - | |
| 5658 | - /** | |
| 5659 | - * Is the box checked to use images as options? | |
| 5660 | - */ | |
| 5661 | - function imagesAsOptions( fieldId ) { | |
| 5662 | - var checked = false, | |
| 5663 | - field = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' ); | |
| 5664 | - | |
| 5665 | - for ( var i = 0; i < field.length; i++ ) { | |
| 5666 | - if ( field[ i ].checked ) { | |
| 5667 | - checked = '0' !== field[ i ].value; | |
| 5668 | - } | |
| 5669 | - } | |
| 5670 | - | |
| 5671 | - /** | |
| 5672 | - * @since 5.0.04 | |
| 5673 | - */ | |
| 5674 | - return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_images_as_options', checked, fieldId ); | |
| 5675 | - } | |
| 5676 | - | |
| 5677 | - function showingLabelWithImage( fieldId ) { | |
| 5678 | - const isShowing = ! isChecked( 'hide_image_text_' + fieldId ); | |
| 5679 | - | |
| 5680 | - /** | |
| 5681 | - * @since 5.0.04 | |
| 5682 | - */ | |
| 5683 | - return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_showing_label_with_image', isShowing, fieldId ); | |
| 5684 | - } | |
| 5685 | - | |
| 5686 | - function isChecked( id ) { | |
| 5687 | - var field = document.getElementById( id ); | |
| 5688 | - if ( field === null ) { | |
| 5689 | - return false; | |
| 5690 | - } else { | |
| 5691 | - return field.checked; | |
| 5692 | - } | |
| 5693 | - } | |
| 5694 | - | |
| 5695 | - function checkUniqueOpt( targetInput ) { | |
| 5696 | - const settingsContainer = targetInput.closest( '.frm-single-settings' ); | |
| 5697 | - const fieldId = settingsContainer.getAttribute( 'data-fid' ); | |
| 5698 | - const areValuesSeparate = settingsContainer.querySelector( '[name="field_options[separate_value_' + fieldId + ']"]' ).checked; | |
| 5699 | - | |
| 5700 | - if ( areValuesSeparate && ! targetInput.name.endsWith( '[value]' ) ) { | |
| 5701 | - return; | |
| 5702 | - } | |
| 5703 | - | |
| 5704 | - const container = document.getElementById( 'frm_field_' + fieldId + '_opts' ); | |
| 5705 | - const conflicts = Array.from( container.querySelectorAll( 'input[type="text"]' ) ).filter( | |
| 5706 | - input => input.id !== targetInput.id && | |
| 5707 | - areValuesSeparate === input.name.endsWith( '[value]' ) && | |
| 5708 | - input.value === targetInput.value | |
| 5709 | - ); | |
| 5710 | - | |
| 5711 | - if ( conflicts.length ) { | |
| 5712 | - infoModal( __( 'Duplicate option value "%s" detected', 'formidable' ).replace( '%s', purifyHtml( targetInput.value ) ) ); | |
| 5713 | - } | |
| 5714 | - } | |
| 5715 | - | |
| 5716 | - function setStarValues() { | |
| 5717 | - /*jshint validthis:true */ | |
| 5718 | - var fieldID = this.id.replace( 'radio_maxnum_', '' ); | |
| 5719 | - var container = jQuery( '#field_' + fieldID + '_inner_container .frm-star-group' ); | |
| 5720 | - var fieldKey = document.getElementsByName( 'field_options[field_key_' + fieldID + ']' )[0].value; | |
| 5721 | - container.html( '' ); | |
| 5722 | - | |
| 5723 | - var min = 1; | |
| 5724 | - var max = this.value; | |
| 5725 | - if ( min > max ) { | |
| 5726 | - max = min; | |
| 5727 | - } | |
| 5728 | - | |
| 5729 | - for ( var i = min; i <= max; i++ ) { | |
| 5730 | - 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>' ); | |
| 5731 | - } | |
| 5732 | - } | |
| 5733 | - | |
| 5734 | - function getFieldValues() { | |
| 5735 | - /*jshint validthis:true */ | |
| 5736 | - var isTaxonomy, | |
| 5737 | - val = this.value; | |
| 5738 | - | |
| 5739 | - if ( val ) { | |
| 5740 | - var parentIDs = this.parentNode.id.replace( 'frm_logic_', '' ).split( '_' ); | |
| 5741 | - var fieldID = parentIDs[0]; | |
| 5742 | - var metaKey = parentIDs[1]; | |
| 5743 | - var valueField = document.getElementById( 'frm_field_id_' + val ); | |
| 5744 | - var valueFieldType = valueField.getAttribute( 'data-ftype' ); | |
| 5745 | - var fill = document.getElementById( 'frm_show_selected_values_' + fieldID + '_' + metaKey ); | |
| 5746 | - var optionName = 'field_options[hide_opt_' + fieldID + '][]'; | |
| 5747 | - var optionID = 'frm_field_logic_opt_' + fieldID; | |
| 5748 | - var input = false; | |
| 5749 | - var showSelect = ( valueFieldType === 'select' || valueFieldType === 'checkbox' || valueFieldType === 'radio' ); | |
| 5750 | - var showText = ( valueFieldType === 'text' || valueFieldType === 'email' || valueFieldType === 'phone' || valueFieldType === 'url' || valueFieldType === 'number' ); | |
| 5751 | - | |
| 5752 | - if ( showSelect ) { | |
| 5753 | - isTaxonomy = document.getElementById( 'frm_has_hidden_options_' + val ); | |
| 5754 | - if ( isTaxonomy !== null ) { | |
| 5755 | - // get the category options with ajax | |
| 5756 | - showSelect = false; | |
| 5757 | - } | |
| 5758 | - } | |
| 5759 | - | |
| 5760 | - if ( showSelect || showText ) { | |
| 5761 | - fill.innerHTML = ''; | |
| 5762 | - if ( showSelect ) { | |
| 5763 | - input = document.createElement( 'select' ); | |
| 5764 | - } else { | |
| 5765 | - input = document.createElement( 'input' ); | |
| 5766 | - input.type = 'text'; | |
| 5767 | - } | |
| 5768 | - input.name = optionName; | |
| 5769 | - input.id = optionID + '_' + metaKey; | |
| 5770 | - fill.appendChild( input ); | |
| 5771 | - | |
| 5772 | - if ( showSelect ) { | |
| 5773 | - var fillField = document.getElementById( input.id ); | |
| 5774 | - fillDropdownOpts( fillField, { | |
| 5775 | - sourceID: val, | |
| 5776 | - placeholder: '', | |
| 5777 | - other: true | |
| 5778 | - }); | |
| 5779 | - } | |
| 5780 | - } else { | |
| 5781 | - var thisType = this.getAttribute( 'data-type' ); | |
| 5782 | - frmGetFieldValues( val, fieldID, metaKey, thisType ); | |
| 5783 | - } | |
| 5784 | - } | |
| 5785 | - } | |
| 5786 | - | |
| 5787 | - function getFieldSelection() { | |
| 5788 | - /*jshint validthis:true */ | |
| 5789 | - var formId = this.value; | |
| 5790 | - if ( formId ) { | |
| 5791 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 5792 | - getTaxOrFieldSelection( formId, fieldId ); | |
| 5793 | - } | |
| 5794 | - } | |
| 5795 | - | |
| 5796 | - function getTaxOrFieldSelection( formId, fieldId ) { | |
| 5797 | - if ( formId ) { | |
| 5798 | - jQuery.ajax({ | |
| 5799 | - type: 'POST', | |
| 5800 | - url: ajaxurl, | |
| 5801 | - data: { | |
| 5802 | - action: 'frm_get_field_selection', | |
| 5803 | - field_id: fieldId, | |
| 5804 | - form_id: formId, | |
| 5805 | - nonce: frmGlobal.nonce | |
| 5806 | - }, | |
| 5807 | - success: function( msg ) { | |
| 5808 | - jQuery( '#frm_show_selected_fields_' + fieldId ).html( msg ).show(); | |
| 5809 | - } | |
| 5810 | - }); | |
| 5811 | - } | |
| 5812 | - } | |
| 5813 | - | |
| 5814 | - function updateFieldOrder() { | |
| 5815 | - var fields, fieldId, field, currentOrder, newOrder; | |
| 5816 | - renumberPageBreaks(); | |
| 5817 | - jQuery( '#frm-show-fields' ).each( function( i ) { | |
| 5818 | - fields = jQuery( 'li.frm_field_box', this ); | |
| 5819 | - for ( i = 0; i < fields.length; i++ ) { | |
| 5820 | - fieldId = fields[ i ].getAttribute( 'data-fid' ); | |
| 5821 | - field = jQuery( 'input[name="field_options[field_order_' + fieldId + ']"]' ); | |
| 5822 | - currentOrder = field.val(); | |
| 5823 | - newOrder = i + 1; | |
| 5824 | - | |
| 5825 | - if ( currentOrder != newOrder ) { | |
| 5826 | - field.val( newOrder ); | |
| 5827 | - singleField = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 5828 | - | |
| 5829 | - moveFieldSettings( singleField ); | |
| 5830 | - fieldUpdated(); | |
| 5831 | - } | |
| 5832 | - } | |
| 5833 | - }); | |
| 5834 | - } | |
| 5835 | - | |
| 5836 | - function toggleSectionHolder() { | |
| 5837 | - document.querySelectorAll( '.start_divider' ).forEach( | |
| 5838 | - function( divider ) { | |
| 5839 | - toggleOneSectionHolder( jQuery( divider ) ); | |
| 5840 | - } | |
| 5841 | - ); | |
| 5842 | - } | |
| 5843 | - | |
| 5844 | - function toggleOneSectionHolder( $section ) { | |
| 5845 | - var noSectionFields, $rows, length, index, sectionHasFields; | |
| 5846 | - | |
| 5847 | - if ( ! $section.length ) { | |
| 5848 | - return; | |
| 5849 | - } | |
| 5850 | - | |
| 5851 | - $rows = $section.find( 'ul.frm_sorting' ); | |
| 5852 | - sectionHasFields = false; | |
| 5853 | - length = $rows.length; | |
| 5854 | - for ( index = 0; index < length; ++index ) { | |
| 5855 | - if ( 0 !== getFieldsInRow( jQuery( $rows.get( index ) ) ).length ) { | |
| 5856 | - sectionHasFields = true; | |
| 5857 | - break; | |
| 5858 | - } | |
| 5859 | - } | |
| 5860 | - | |
| 5861 | - noSectionFields = $section.parent().children( '.frm_no_section_fields' ).get( 0 ); | |
| 5862 | - noSectionFields.classList.toggle( 'frm_block', ! sectionHasFields ); | |
| 5863 | - } | |
| 5864 | - | |
| 5865 | - function handleShowPasswordLiveUpdate() { | |
| 5866 | - frmDom.util.documentOn( 'change', '.frm_show_password_setting_input', event => { | |
| 5867 | - const fieldId = event.target.getAttribute( 'data-fid' ); | |
| 5868 | - const fieldEl = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 5869 | - if ( ! fieldEl ) { | |
| 5870 | - return; | |
| 5871 | - } | |
| 5872 | - | |
| 5873 | - fieldEl.classList.toggle( 'frm_disabled_show_password', ! event.target.checked ); | |
| 5874 | - }); | |
| 5875 | - } | |
| 5876 | - | |
| 5877 | - function slideDown() { | |
| 5878 | - /*jshint validthis:true */ | |
| 5879 | - var id = jQuery( this ).data( 'slidedown' ); | |
| 5880 | - var $thisId = jQuery( document.getElementById( id ) ); | |
| 5881 | - if ( $thisId.is( ':hidden' ) ) { | |
| 5882 | - $thisId.slideDown( 'fast' ); | |
| 5883 | - this.style.display = 'none'; | |
| 5884 | - } | |
| 5885 | - return false; | |
| 5886 | - } | |
| 5887 | - | |
| 5888 | - function slideUp() { | |
| 5889 | - /*jshint validthis:true */ | |
| 5890 | - var id = jQuery( this ).data( 'slideup' ); | |
| 5891 | - var $thisId = jQuery( document.getElementById( id ) ); | |
| 5892 | - $thisId.slideUp( 'fast' ); | |
| 5893 | - $thisId.siblings( 'a' ).show(); | |
| 5894 | - return false; | |
| 5895 | - } | |
| 5896 | - | |
| 5897 | - function adjustVisibilityValuesForEveryoneValues( element, option ) { | |
| 5898 | - if ( '' === option.getAttribute( 'value' ) ) { | |
| 5899 | - onEveryoneOptionSelected( jQuery( this ) ); | |
| 5900 | - } else { | |
| 5901 | - unselectEveryoneOptionIfSelected( jQuery( this ) ); | |
| 5902 | - } | |
| 5903 | - } | |
| 5904 | - | |
| 5905 | - function onEveryoneOptionSelected( $select ) { | |
| 5906 | - $select.val( '' ); | |
| 5907 | - $select.next( '.btn-group' ).find( '.multiselect-container input[value!=""]' ).prop( 'checked', false ); | |
| 5908 | - } | |
| 5909 | - | |
| 5910 | - function unselectEveryoneOptionIfSelected( $select ) { | |
| 5911 | - var selectedValues = $select.val(), | |
| 5912 | - index; | |
| 5913 | - | |
| 5914 | - if ( selectedValues === null ) { | |
| 5915 | - $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', true ); | |
| 5916 | - onEveryoneOptionSelected( $select ); | |
| 5917 | - return; | |
| 5918 | - } | |
| 5919 | - | |
| 5920 | - index = selectedValues.indexOf( '' ); | |
| 5921 | - if ( index >= 0 ) { | |
| 5922 | - selectedValues.splice( index, 1 ); | |
| 5923 | - $select.val( selectedValues ); | |
| 5924 | - $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', false ); | |
| 5925 | - } | |
| 5926 | - } | |
| 5927 | - | |
| 5928 | - /** | |
| 5929 | - * Get rid of empty container that inserts extra space. | |
| 5930 | - */ | |
| 5931 | - function hideEmptyEle() { | |
| 5932 | - jQuery( '.frm-hide-empty' ).each( function() { | |
| 5933 | - if ( jQuery( this ).text().trim().length === 0 ) { | |
| 5934 | - jQuery( this ).remove(); | |
| 5935 | - } | |
| 5936 | - }); | |
| 5937 | - } | |
| 5938 | - | |
| 5939 | - /* Change the classes in the builder */ | |
| 5940 | - function changeFieldClass( field, setting ) { | |
| 5941 | - var classes, replace, alignField, | |
| 5942 | - replaceWith = ' ' + setting.value, | |
| 5943 | - fieldId = field.getAttribute( 'data-fid' ); | |
| 5944 | - | |
| 5945 | - // Include classes from multiple settings. | |
| 5946 | - if ( typeof fieldId !== 'undefined' ) { | |
| 5947 | - if ( setting.classList.contains( 'field_options_align' ) ) { | |
| 5948 | - replaceWith += ' ' + document.getElementById( 'frm_classes_' + fieldId ).value; | |
| 5949 | - } else if ( setting.classList.contains( 'frm_classes' ) ) { | |
| 5950 | - alignField = document.getElementById( 'field_options_align_' + fieldId ); | |
| 5951 | - if ( alignField !== null ) { | |
| 5952 | - replaceWith += ' ' + alignField.value; | |
| 5953 | - } | |
| 5954 | - } | |
| 5955 | - } | |
| 5956 | - replaceWith += ' '; | |
| 5957 | - | |
| 5958 | - // Allow for the column number dropdown. | |
| 5959 | - replaceWith = replaceWith.replace( ' block ', ' ' ).replace( ' inline ', ' horizontal_radio ' ); | |
| 5960 | - | |
| 5961 | - classes = field.className.split( ' frmstart ' )[1]; | |
| 5962 | - classes = 0 === classes.indexOf( 'frmend ' ) ? '' : classes.split( ' frmend ' )[0]; | |
| 5963 | - | |
| 5964 | - if ( classes.trim() === '' ) { | |
| 5965 | - replace = ' frmstart frmend '; | |
| 5966 | - if ( -1 === field.className.indexOf( replace ) ) { | |
| 5967 | - replace = ' frmstart frmend '; | |
| 5968 | - } | |
| 5969 | - replaceWith = ' frmstart ' + replaceWith.trim() + ' frmend '; | |
| 5970 | - } else { | |
| 5971 | - replace = classes.trim(); | |
| 5972 | - replaceWith = replaceWith.trim(); | |
| 5973 | - } | |
| 5974 | - | |
| 5975 | - field.className = field.className.replace( replace, replaceWith ); | |
| 5976 | - } | |
| 5977 | - | |
| 5978 | - function maybeShowInlineModal( e ) { | |
| 5979 | - /*jshint validthis:true */ | |
| 5980 | - e.preventDefault(); | |
| 5981 | - showInlineModal( this ); | |
| 5982 | - } | |
| 5983 | - | |
| 5984 | - function showInlineModal( icon, input ) { | |
| 5985 | - var box = document.getElementById( icon.getAttribute( 'data-open' ) ), | |
| 5986 | - container = jQuery( icon ).closest( 'p' ), | |
| 5987 | - inputTrigger = ( typeof input !== 'undefined' ); | |
| 5988 | - | |
| 5989 | - if ( container.hasClass( 'frm-open' ) ) { | |
| 5990 | - container.removeClass( 'frm-open' ); | |
| 5991 | - box.classList.add( 'frm_hidden' ); | |
| 5992 | - } else { | |
| 5993 | - if ( ! inputTrigger ) { | |
| 5994 | - input = getInputForIcon( icon ); | |
| 5995 | - } | |
| 5996 | - if ( input !== null ) { | |
| 5997 | - if ( ! inputTrigger ) { | |
| 5998 | - input.focus(); | |
| 5999 | - } | |
| 6000 | - container.after( box ); | |
| 6001 | - box.setAttribute( 'data-fills', input.id ); | |
| 6002 | - | |
| 6003 | - if ( box.id.indexOf( 'frm-calc-box' ) === 0 ) { | |
| 6004 | - popCalcFields( box, true ); | |
| 6005 | - } | |
| 6006 | - } | |
| 6007 | - | |
| 6008 | - container.addClass( 'frm-open' ); | |
| 6009 | - box.classList.remove( 'frm_hidden' ); | |
| 6010 | - | |
| 6011 | - /** | |
| 6012 | - * @since 6.4.1 | |
| 6013 | - */ | |
| 6014 | - wp.hooks.doAction( 'frm_show_inline_modal', box, icon ); | |
| 6015 | - } | |
| 6016 | - } | |
| 6017 | - | |
| 6018 | - function dismissInlineModal( e ) { | |
| 6019 | - /*jshint validthis:true */ | |
| 6020 | - e.preventDefault(); | |
| 6021 | - this.parentNode.classList.add( 'frm_hidden' ); | |
| 6022 | - jQuery( '.frm-open [data-open="' + this.parentNode.id + '"]' ).closest( '.frm-open' ).removeClass( 'frm-open' ); | |
| 6023 | - } | |
| 6024 | - | |
| 6025 | - function changeInputtedValue() { | |
| 6026 | - /*jshint validthis:true */ | |
| 6027 | - var i, | |
| 6028 | - action = this.getAttribute( 'data-frmchange' ).split( ',' ); | |
| 6029 | - | |
| 6030 | - for ( i = 0; i < action.length; i++ ) { | |
| 6031 | - if ( action[i] === 'updateOption' ) { | |
| 6032 | - changeHiddenSeparateValue( this ); | |
| 6033 | - } else if ( action[i] === 'updateDefault' ) { | |
| 6034 | - changeDefaultRadioValue( this ); | |
| 6035 | - } else if ( action[i] === 'checkUniqueOpt' ) { | |
| 6036 | - checkUniqueOpt( this ); | |
| 6037 | - } else { | |
| 6038 | - this.value = this.value[ action[i] ](); | |
| 6039 | - } | |
| 6040 | - } | |
| 6041 | - } | |
| 6042 | - | |
| 6043 | - /** | |
| 6044 | - * When the saved value is changed, update the default value radio. | |
| 6045 | - */ | |
| 6046 | - function changeDefaultRadioValue( input ) { | |
| 6047 | - var parentLi = getOptionParent( input ), | |
| 6048 | - key = parentLi.getAttribute( 'data-optkey' ), | |
| 6049 | - fieldId = getOptionFieldId( parentLi, key ), | |
| 6050 | - defaultRadio = parentLi.querySelector( 'input[name="default_value_' + fieldId + '"]' ); | |
| 6051 | - | |
| 6052 | - if ( defaultRadio !== null ) { | |
| 6053 | - defaultRadio.value = input.value; | |
| 6054 | - } | |
| 6055 | - } | |
| 6056 | - | |
| 6057 | - /** | |
| 6058 | - * If separate values are not enabled, change the saved value when | |
| 6059 | - * the displayed value is changed. | |
| 6060 | - */ | |
| 6061 | - function changeHiddenSeparateValue( input ) { | |
| 6062 | - var savedVal, | |
| 6063 | - parentLi = getOptionParent( input ), | |
| 6064 | - key = parentLi.getAttribute( 'data-optkey' ), | |
| 6065 | - fieldId = getOptionFieldId( parentLi, key ), | |
| 6066 | - sep = document.getElementById( 'separate_value_' + fieldId ); | |
| 6067 | - | |
| 6068 | - if ( sep !== null && sep.checked === false ) { | |
| 6069 | - // If separate values are not turned on. | |
| 6070 | - savedVal = document.getElementById( 'field_key_' + fieldId + '-' + key ); | |
| 6071 | - savedVal.value = input.value; | |
| 6072 | - changeDefaultRadioValue( savedVal ); | |
| 6073 | - } | |
| 6074 | - } | |
| 6075 | - | |
| 6076 | - function getOptionParent( input ) { | |
| 6077 | - var parentLi = input.parentNode; | |
| 6078 | - if ( parentLi.tagName !== 'LI' ) { | |
| 6079 | - parentLi = parentLi.parentNode; | |
| 6080 | - } | |
| 6081 | - return parentLi; | |
| 6082 | - } | |
| 6083 | - | |
| 6084 | - function getOptionFieldId( li, key ) { | |
| 6085 | - var liId = li.id; | |
| 6086 | - | |
| 6087 | - return liId.replace( 'frm_delete_field_', '' ).replace( '-' + key + '_container', '' ); | |
| 6088 | - } | |
| 6089 | - | |
| 6090 | - function submitBuild() { | |
| 6091 | - /*jshint validthis:true */ | |
| 6092 | - var $thisEle = this; | |
| 6093 | - | |
| 6094 | - preFormSave( this ); | |
| 6095 | - | |
| 6096 | - var $form = jQuery( builderForm ); | |
| 6097 | - var v = JSON.stringify( $form.serializeArray() ); | |
| 6098 | - | |
| 6099 | - jQuery( document.getElementById( 'frm_compact_fields' ) ).val( v ); | |
| 6100 | - jQuery.ajax({ | |
| 6101 | - type: 'POST', | |
| 6102 | - url: ajaxurl, | |
| 6103 | - data: {action: 'frm_save_form', 'frm_compact_fields': v, nonce: frmGlobal.nonce}, | |
| 6104 | - success: function( msg ) { | |
| 6105 | - afterFormSave( $thisEle ); | |
| 6106 | - | |
| 6107 | - var $postStuff = document.getElementById( 'post-body-content' ); | |
| 6108 | - var $html = document.createElement( 'div' ); | |
| 6109 | - $html.setAttribute( 'class', 'frm_updated_message' ); | |
| 6110 | - $html.innerHTML = msg; | |
| 6111 | - $postStuff.insertBefore( $html, $postStuff.firstChild ); | |
| 6112 | - reloadIfAddonActivatedAjaxSubmitOnly(); | |
| 6113 | - }, | |
| 6114 | - error: function() { | |
| 6115 | - triggerSubmit( document.getElementById( 'frm_js_build_form' ) ); | |
| 6116 | - } | |
| 6117 | - }); | |
| 6118 | - } | |
| 6119 | - | |
| 6120 | - function triggerSubmit( form ) { | |
| 6121 | - var button = form.ownerDocument.createElement( 'input' ); | |
| 6122 | - button.style.display = 'none'; | |
| 6123 | - button.type = 'submit'; | |
| 6124 | - form.appendChild( button ).click(); | |
| 6125 | - form.removeChild( button ); | |
| 6126 | - } | |
| 6127 | - | |
| 6128 | - function triggerChange( element ) { | |
| 6129 | - jQuery( element ).trigger( 'change' ); | |
| 6130 | - } | |
| 6131 | - | |
| 6132 | - function submitNoAjax() { | |
| 6133 | - /*jshint validthis:true */ | |
| 6134 | - var form; | |
| 6135 | - | |
| 6136 | - preFormSave( this ); | |
| 6137 | - form = jQuery( builderForm ); | |
| 6138 | - jQuery( document.getElementById( 'frm_compact_fields' ) ).val( JSON.stringify( form.serializeArray() ) ); | |
| 6139 | - triggerSubmit( document.getElementById( 'frm_js_build_form' ) ); | |
| 6140 | - } | |
| 6141 | - | |
| 6142 | - function preFormSave( b ) { | |
| 6143 | - removeWPUnload(); | |
| 6144 | - if ( jQuery( 'form.inplace_form' ).length ) { | |
| 6145 | - jQuery( '.inplace_save, .postbox' ).trigger( 'click' ); | |
| 6146 | - } | |
| 6147 | - | |
| 6148 | - if ( b.classList.contains( 'frm_button_submit' ) ) { | |
| 6149 | - b.classList.add( 'frm_loading_form' ); | |
| 6150 | - } else { | |
| 6151 | - b.classList.add( 'frm_loading_button' ); | |
| 6152 | - } | |
| 6153 | - b.setAttribute( 'aria-busy', 'true' ); | |
| 6154 | - } | |
| 6155 | - | |
| 6156 | - function afterFormSave( button ) { | |
| 6157 | - button.classList.remove( 'frm_loading_form' ); | |
| 6158 | - button.classList.remove( 'frm_loading_button' ); | |
| 6159 | - resetOptionTextDetails(); | |
| 6160 | - fieldsUpdated = 0; | |
| 6161 | - button.setAttribute( 'aria-busy', 'false' ); | |
| 6162 | - | |
| 6163 | - setTimeout( function() { | |
| 6164 | - jQuery( '.frm_updated_message' ).fadeOut( 'slow', function() { | |
| 6165 | - this.parentNode.removeChild( this ); | |
| 6166 | - }); | |
| 6167 | - }, 5000 ); | |
| 6168 | - } | |
| 6169 | - | |
| 6170 | - function initUpgradeModal() { | |
| 6171 | - const $info = initModal( '#frm_upgrade_modal' ); | |
| 6172 | - if ( $info === false ) { | |
| 6173 | - return; | |
| 6174 | - } | |
| 6175 | - | |
| 6176 | - document.addEventListener( 'click', handleUpgradeClick ); | |
| 6177 | - | |
| 6178 | - function handleUpgradeClick( event ) { | |
| 6179 | - let element, link, content; | |
| 6180 | - | |
| 6181 | - element = event.target; | |
| 6182 | - | |
| 6183 | - if ( ! element.classList ) { | |
| 6184 | - return; | |
| 6185 | - } | |
| 6186 | - | |
| 6187 | - const showExpiredModal = element.classList.contains( 'frm_show_expired_modal' ) || null !== element.querySelector( '.frm_show_expired_modal' ) || element.closest( '.frm_show_expired_modal' ); | |
| 6188 | - | |
| 6189 | - if ( ! element.dataset.upgrade ) { | |
| 6190 | - let parent = element.closest( '[data-upgrade]' ); | |
| 6191 | - if ( ! parent ) { | |
| 6192 | - parent = element.closest( '.frm_field_box' ); | |
| 6193 | - if ( ! parent ) { | |
| 6194 | - return; | |
| 6195 | - } | |
| 6196 | - // Fake it if it's missing to avoid error. | |
| 6197 | - element.dataset.upgrade = ''; | |
| 6198 | - } | |
| 6199 | - element = parent; | |
| 6200 | - } | |
| 6201 | - | |
| 6202 | - if ( showExpiredModal ) { | |
| 6203 | - const hookName = 'frm_show_expired_modal'; | |
| 6204 | - wp.hooks.doAction( hookName, element ); | |
| 6205 | - return; | |
| 6206 | - } | |
| 6207 | - | |
| 6208 | - const upgradeLabel = element.dataset.upgrade; | |
| 6209 | - if ( ! upgradeLabel || element.classList.contains( 'frm_show_upgrade_tab' ) ) { | |
| 6210 | - return; | |
| 6211 | - } | |
| 6212 | - | |
| 6213 | - event.preventDefault(); | |
| 6214 | - | |
| 6215 | - const modal = $info.get( 0 ); | |
| 6216 | - const lockIcon = modal.querySelector( '.frm_lock_icon' ); | |
| 6217 | - | |
| 6218 | - if ( lockIcon ) { | |
| 6219 | - lockIcon.style.display = 'block'; | |
| 6220 | - lockIcon.classList.remove( 'frm_lock_open_icon' ); | |
| 6221 | - lockIcon.querySelector( 'use' ).setAttribute( 'href', '#frm_lock_icon' ); | |
| 6222 | - } | |
| 6223 | - | |
| 6224 | - const upgradeImageId = 'frm_upgrade_modal_image'; | |
| 6225 | - const oldImage = document.getElementById( upgradeImageId ); | |
| 6226 | - if ( oldImage ) { | |
| 6227 | - oldImage.remove(); | |
| 6228 | - } | |
| 6229 | - | |
| 6230 | - if ( element.dataset.image ) { | |
| 6231 | - if ( lockIcon ) { | |
| 6232 | - lockIcon.style.display = 'none'; | |
| 6233 | - } | |
| 6234 | - lockIcon.parentNode.insertBefore( img({ id: upgradeImageId, src: frmGlobal.url + '/images/' + element.dataset.image }), lockIcon ); | |
| 6235 | - } | |
| 6236 | - | |
| 6237 | - const level = modal.querySelector( '.license-level' ); | |
| 6238 | - if ( level ) { | |
| 6239 | - level.textContent = getRequiredLicenseFromTrigger( element ); | |
| 6240 | - } | |
| 6241 | - | |
| 6242 | - // If one click upgrade, hide other content | |
| 6243 | - addOneClick( element, 'modal', upgradeLabel ); | |
| 6244 | - | |
| 6245 | - modal.querySelector( '.frm_are_not_installed' ).style.display = element.dataset.image ? 'none' : 'inline-block'; | |
| 6246 | - modal.querySelector( '.frm_feature_label' ).textContent = upgradeLabel; | |
| 6247 | - modal.querySelector( 'h2' ).style.display = 'block'; | |
| 6248 | - | |
| 6249 | - $info.dialog( 'open' ); | |
| 6250 | - | |
| 6251 | - // set the utm medium | |
| 6252 | - const button = modal.querySelector( '.button-primary:not(.frm-oneclick-button)' ); | |
| 6253 | - link = button.getAttribute( 'href' ).replace( /(medium=)[a-z_-]+/ig, '$1' + element.getAttribute( 'data-medium' ) ); | |
| 6254 | - content = element.getAttribute( 'data-content' ); | |
| 6255 | - if ( content === null ) { | |
| 6256 | - content = ''; | |
| 6257 | - } | |
| 6258 | - link = link.replace( /(content=)[a-z_-]+/ig, '$1' + content ); | |
| 6259 | - button.setAttribute( 'href', link ); | |
| 6260 | - } | |
| 6261 | - } | |
| 6262 | - | |
| 6263 | - function getRequiredLicenseFromTrigger( element ) { | |
| 6264 | - if ( element.dataset.requires ) { | |
| 6265 | - return element.dataset.requires; | |
| 6266 | - } | |
| 6267 | - return 'Pro'; | |
| 6268 | - } | |
| 6269 | - | |
| 6270 | - function populateUpgradeTab( element ) { | |
| 6271 | - const title = element.dataset.upgrade; | |
| 6272 | - | |
| 6273 | - const tab = element.getAttribute( 'href' ).replace( '#', '' ); | |
| 6274 | - const container = document.querySelector( '.frm_' + tab ) || document.querySelector( '.' + tab ); | |
| 6275 | - | |
| 6276 | - if ( ! container ) { | |
| 6277 | - return; | |
| 6278 | - } | |
| 6279 | - | |
| 6280 | - if ( container.querySelector( '.frm-upgrade-message' ) ) { | |
| 6281 | - // Tab has already been populated. | |
| 6282 | - return; | |
| 6283 | - } | |
| 6284 | - | |
| 6285 | - const h2 = container.querySelector( 'h2' ); | |
| 6286 | - h2.style.borderBottom = 'none'; | |
| 6287 | - | |
| 6288 | - /* translators: %s: Form Setting section name (ie Form Permissions, Form Scheduling). */ | |
| 6289 | - h2.textContent = __( '%s are not installed' ).replace( '%s', title ); | |
| 6290 | - | |
| 6291 | - container.classList.add( 'frmcenter' ); | |
| 6292 | - | |
| 6293 | - const upgradeModal = document.getElementById( 'frm_upgrade_modal' ); | |
| 6294 | - appendClonedModalElementToContainer( 'frm-oneclick' ); | |
| 6295 | - appendClonedModalElementToContainer( 'frm-addon-status' ); | |
| 6296 | - | |
| 6297 | - // 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). | |
| 6298 | - const upgradeModalLink = upgradeModal.querySelector( '.frm-upgrade-link' ); | |
| 6299 | - if ( upgradeModalLink ) { | |
| 6300 | - const upgradeButton = upgradeModalLink.cloneNode( true ); | |
| 6301 | - const level = upgradeButton.querySelector( '.license-level' ); | |
| 6302 | - | |
| 6303 | - if ( level ) { | |
| 6304 | - level.textContent = getRequiredLicenseFromTrigger( element ); | |
| 6305 | - } | |
| 6306 | - | |
| 6307 | - container.appendChild( upgradeButton ); | |
| 6308 | - | |
| 6309 | - // Maybe append the secondary "Already purchased?" link from the upgradeModal as well. | |
| 6310 | - if ( upgradeModalLink.nextElementSibling && upgradeModalLink.nextElementSibling.querySelector( '.frm-link-secondary' ) ) { | |
| 6311 | - container.appendChild( upgradeModalLink.nextElementSibling.cloneNode( true ) ); | |
| 6312 | - } | |
| 6313 | - | |
| 6314 | - appendClonedModalElementToContainer( 'frm-oneclick-button' ); | |
| 6315 | - } | |
| 6316 | - | |
| 6317 | - appendClonedModalElementToContainer( 'frm-upgrade-message' ); | |
| 6318 | - | |
| 6319 | - let upgradeLabel = element.dataset.message; | |
| 6320 | - | |
| 6321 | - if ( upgradeLabel === undefined ) { | |
| 6322 | - upgradeLabel = element.dataset.upgrade; | |
| 6323 | - } | |
| 6324 | - addOneClick( element, 'tab', upgradeLabel ); | |
| 6325 | - | |
| 6326 | - if ( element.dataset.screenshot ) { | |
| 6327 | - container.appendChild( getScreenshotWrapper( element.dataset.screenshot ) ); | |
| 6328 | - } | |
| 6329 | - | |
| 6330 | - function appendClonedModalElementToContainer( className ) { | |
| 6331 | - container.appendChild( upgradeModal.querySelector( '.' + className ).cloneNode( true ) ); | |
| 6332 | - } | |
| 6333 | - } | |
| 6334 | - | |
| 6335 | - function getScreenshotWrapper( screenshot ) { | |
| 6336 | - const folderUrl = frmGlobal.url + '/images/screenshots/'; | |
| 6337 | - const wrapper = div({ | |
| 6338 | - className: 'frm-settings-screenshot-wrapper', | |
| 6339 | - children: [ | |
| 6340 | - getToolbar(), | |
| 6341 | - div({ child: img({ src: folderUrl + screenshot }) }) | |
| 6342 | - ] | |
| 6343 | - }); | |
| 6344 | - | |
| 6345 | - function getToolbar() { | |
| 6346 | - const children = getColorIcons(); | |
| 6347 | - children.push( img({ src: frmGlobal.url + '/images/tab.svg' }) ); | |
| 6348 | - return div({ | |
| 6349 | - className: 'frm-settings-screenshot-toolbar', | |
| 6350 | - children | |
| 6351 | - }); | |
| 6352 | - } | |
| 6353 | - | |
| 6354 | - function getColorIcons() { | |
| 6355 | - return [ '#ED8181', '#EDE06A', '#80BE30' ].map( | |
| 6356 | - color => { | |
| 6357 | - const circle = div({ className: 'frm-minmax-icon' }); | |
| 6358 | - circle.style.backgroundColor = color; | |
| 6359 | - return circle; | |
| 6360 | - } | |
| 6361 | - ); | |
| 6362 | - } | |
| 6363 | - | |
| 6364 | - return wrapper; | |
| 6365 | - } | |
| 6366 | - | |
| 6367 | - /** | |
| 6368 | - * Allow addons to be installed from the upgrade modal. | |
| 6369 | - * | |
| 6370 | - * @param {Element} link | |
| 6371 | - * @param {String} context Either 'modal' or 'tab'. | |
| 6372 | - * @param {String|undefined} upgradeLabel | |
| 6373 | - */ | |
| 6374 | - function addOneClick( link, context, upgradeLabel ) { | |
| 6375 | - let container; | |
| 6376 | - | |
| 6377 | - if ( 'modal' === context ) { | |
| 6378 | - container = document.getElementById( 'frm_upgrade_modal' ); | |
| 6379 | - } else if ( 'tab' === context ) { | |
| 6380 | - container = document.getElementById( link.getAttribute( 'href' ).substr( 1 ) ); | |
| 6381 | - } else { | |
| 6382 | - return; | |
| 6383 | - } | |
| 6384 | - | |
| 6385 | - const oneclickMessage = container.querySelector( '.frm-oneclick' ); | |
| 6386 | - const upgradeMessage = container.querySelector( '.frm-upgrade-message' ); | |
| 6387 | - const showLink = container.querySelector( '.frm-upgrade-link' ); | |
| 6388 | - const button = container.querySelector( '.frm-oneclick-button' ); | |
| 6389 | - const addonStatus = container.querySelector( '.frm-addon-status' ); | |
| 6390 | - | |
| 6391 | - let oneclick = link.getAttribute( 'data-oneclick' ); | |
| 6392 | - let newMessage = link.getAttribute( 'data-message' ); | |
| 6393 | - let showIt = 'block'; | |
| 6394 | - let showMsg = 'block'; | |
| 6395 | - let hideIt = 'none'; | |
| 6396 | - | |
| 6397 | - // If one click upgrade, hide other content. | |
| 6398 | - if ( oneclickMessage !== null && typeof oneclick !== 'undefined' && oneclick ) { | |
| 6399 | - if ( newMessage === null ) { | |
| 6400 | - showMsg = 'none'; | |
| 6401 | - } | |
| 6402 | - showIt = 'none'; | |
| 6403 | - hideIt = 'block'; | |
| 6404 | - oneclick = JSON.parse( oneclick ); | |
| 6405 | - | |
| 6406 | - button.className = button.className.replace( ' frm-install-addon', '' ).replace( ' frm-activate-addon', '' ); | |
| 6407 | - button.className = button.className + ' ' + oneclick.class; | |
| 6408 | - button.textContent = __( 'Activate', 'formidable' ); | |
| 6409 | - button.rel = oneclick.url; | |
| 6410 | - } | |
| 6411 | - | |
| 6412 | - if ( ! newMessage ) { | |
| 6413 | - newMessage = upgradeMessage.getAttribute( 'data-default' ); | |
| 6414 | - } | |
| 6415 | - if ( undefined !== upgradeLabel ) { | |
| 6416 | - newMessage = newMessage.replace( '<span class="frm_feature_label"></span>', upgradeLabel ); | |
| 6417 | - } | |
| 6418 | - | |
| 6419 | - upgradeMessage.innerHTML = newMessage; | |
| 6420 | - | |
| 6421 | - // Either set the link or use the default. | |
| 6422 | - showLink.href = getShowLinkHrefValue( link, showLink ); | |
| 6423 | - | |
| 6424 | - addonStatus.style.display = 'none'; | |
| 6425 | - | |
| 6426 | - oneclickMessage.style.display = hideIt; | |
| 6427 | - button.style.display = hideIt === 'block' ? 'inline-block' : hideIt; | |
| 6428 | - upgradeMessage.style.display = showMsg; | |
| 6429 | - showLink.style.display = showIt === 'block' ? 'inline-block' : showIt; | |
| 6430 | - } | |
| 6431 | - | |
| 6432 | - function getShowLinkHrefValue( link, showLink ) { | |
| 6433 | - let customLink = link.getAttribute( 'data-link' ); | |
| 6434 | - if ( customLink === null || typeof customLink === 'undefined' || customLink === '' ) { | |
| 6435 | - customLink = showLink.getAttribute( 'data-default' ); | |
| 6436 | - } | |
| 6437 | - return customLink; | |
| 6438 | - } | |
| 6439 | - | |
| 6440 | - /* Form settings */ | |
| 6441 | - | |
| 6442 | - function showInputIcon( parentClass ) { | |
| 6443 | - if ( typeof parentClass === 'undefined' ) { | |
| 6444 | - parentClass = ''; | |
| 6445 | - } | |
| 6446 | - maybeAddFieldSelection( parentClass ); | |
| 6447 | - 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>' ); | |
| 6448 | - } | |
| 6449 | - | |
| 6450 | - /** | |
| 6451 | - * For reverse compatibility. Check for fields that were | |
| 6452 | - * using the old sidebar. | |
| 6453 | - */ | |
| 6454 | - function maybeAddFieldSelection( parentClass ) { | |
| 6455 | - var i, | |
| 6456 | - 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' ); | |
| 6457 | - for ( i = 0; i < missingClass.length; i++ ) { | |
| 6458 | - missingClass[i].parentNode.classList.add( 'frm_has_shortcodes' ); | |
| 6459 | - } | |
| 6460 | - } | |
| 6461 | - | |
| 6462 | - function showSuccessOpt() { | |
| 6463 | - /*jshint validthis:true */ | |
| 6464 | - var c = 'success'; | |
| 6465 | - if ( this.name === 'options[edit_action]' ) { | |
| 6466 | - c = 'edit'; | |
| 6467 | - } | |
| 6468 | - var v = jQuery( this ).val(); | |
| 6469 | - jQuery( '.' + c + '_action_box' ).hide(); | |
| 6470 | - if ( v === 'redirect' ) { | |
| 6471 | - jQuery( '.' + c + '_action_redirect_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 6472 | - } else if ( v === 'page' ) { | |
| 6473 | - jQuery( '.' + c + '_action_page_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 6474 | - } else { | |
| 6475 | - jQuery( '.' + c + '_action_message_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 6476 | - } | |
| 6477 | - } | |
| 6478 | - | |
| 6479 | - function copyFormAction( event ) { | |
| 6480 | - if ( waitForActionToLoadBeforeCopy( event.target ) ) { | |
| 6481 | - return; | |
| 6482 | - } | |
| 6483 | - | |
| 6484 | - const targetSettings = event.target.closest( '.frm_form_action_settings' ); | |
| 6485 | - const wysiwyg = targetSettings.querySelector( '.wp-editor-area' ); | |
| 6486 | - if ( wysiwyg ) { | |
| 6487 | - // Temporary remove TinyMCE before cloning to avoid TinyMCE conflicts. | |
| 6488 | - tinymce.EditorManager.execCommand( 'mceRemoveEditor', true, wysiwyg.id ); | |
| 6489 | - } | |
| 6490 | - | |
| 6491 | - const $action = jQuery( targetSettings ).clone(); | |
| 6492 | - const currentID = $action.attr( 'id' ).replace( 'frm_form_action_', '' ); | |
| 6493 | - const newID = newActionId( currentID ); | |
| 6494 | - | |
| 6495 | - $action.find( '.frm_action_id, .frm-btn-group' ).remove(); | |
| 6496 | - $action.find( 'input[name$="[' + currentID + '][ID]"]' ).val( '' ); | |
| 6497 | - $action.find( '.widget-inside' ).hide(); | |
| 6498 | - | |
| 6499 | - // the .html() gets original values, so they need to be set | |
| 6500 | - $action.find( 'input[type=text], textarea, input[type=number]' ).prop( 'defaultValue', function() { | |
| 6501 | - return this.value; | |
| 6502 | - }); | |
| 6503 | - | |
| 6504 | - $action.find( 'input[type=checkbox], input[type=radio]' ).prop( 'defaultChecked', function() { | |
| 6505 | - return this.checked; | |
| 6506 | - }); | |
| 6507 | - | |
| 6508 | - const rename = new RegExp( '\\[' + currentID + '\\]', 'g' ); | |
| 6509 | - const reid = new RegExp( '_' + currentID + '"', 'g' ); | |
| 6510 | - const reclass = new RegExp( '-' + currentID + '"', 'g' ); | |
| 6511 | - const revalue = new RegExp( '"' + currentID + '"', 'g' ); // if a field id matches, this could cause trouble | |
| 6512 | - | |
| 6513 | - let html = $action.html().replace( rename, '[' + newID + ']' ).replace( reid, '_' + newID + '"' ); | |
| 6514 | - html = html.replace( reclass, '-' + newID + '"' ).replace( revalue, '"' + newID + '"' ); | |
| 6515 | - | |
| 6516 | - const newAction = div({ | |
| 6517 | - id: 'frm_form_action_' + newID, | |
| 6518 | - className: $action.get( 0 ).className | |
| 6519 | - }); | |
| 6520 | - newAction.setAttribute( 'data-actionkey', newID ); | |
| 6521 | - newAction.innerHTML = html; | |
| 6522 | - newAction.querySelectorAll( '.wp-editor-wrap, .wp-editor-wrap *' ).forEach( | |
| 6523 | - element => { | |
| 6524 | - if ( 'string' === typeof element.className ) { | |
| 6525 | - element.className = element.className.replace( currentID, newID ); | |
| 6526 | - } | |
| 6527 | - element.id = element.id.replace( currentID, newID ); | |
| 6528 | - } | |
| 6529 | - ); | |
| 6530 | - newAction.classList.remove( 'open' ); | |
| 6531 | - document.getElementById( 'frm_notification_settings' ).appendChild( newAction ); | |
| 6532 | - | |
| 6533 | - if ( wysiwyg ) { | |
| 6534 | - // Re-initialize the original wysiwyg which was removed before cloning. | |
| 6535 | - frmDom.wysiwyg.init( wysiwyg ); | |
| 6536 | - frmDom.wysiwyg.init( newAction.querySelector( '.wp-editor-area' ) ); | |
| 6537 | - } | |
| 6538 | - | |
| 6539 | - if ( newAction.classList.contains( 'frm_single_on_submit_settings' ) ) { | |
| 6540 | - const autocompleteInput = newAction.querySelector( 'input.frm-page-search' ); | |
| 6541 | - if ( autocompleteInput ) { | |
| 6542 | - frmDom.autocomplete.initAutocomplete( 'page', newAction ); | |
| 6543 | - } | |
| 6544 | - } | |
| 6545 | - | |
| 6546 | - initiateMultiselect(); | |
| 6547 | - | |
| 6548 | - const hookName = 'frm_after_duplicate_action'; | |
| 6549 | - wp.hooks.doAction( hookName, newAction ); | |
| 6550 | - } | |
| 6551 | - | |
| 6552 | - function waitForActionToLoadBeforeCopy( element ) { | |
| 6553 | - var $trigger = jQuery( element ), | |
| 6554 | - $original = $trigger.closest( '.frm_form_action_settings' ), | |
| 6555 | - $inside = $original.find( '.widget-inside' ), | |
| 6556 | - $top; | |
| 6557 | - | |
| 6558 | - if ( $inside.find( 'p, div, table' ).length ) { | |
| 6559 | - return false; | |
| 6560 | - } | |
| 6561 | - | |
| 6562 | - $top = $original.find( '.widget-top' ); | |
| 6563 | - $top.on( 'frm-action-loaded', function() { | |
| 6564 | - $trigger.trigger( 'click' ); | |
| 6565 | - $original.removeClass( 'open' ); | |
| 6566 | - $inside.hide(); | |
| 6567 | - }); | |
| 6568 | - $top.trigger( 'click' ); | |
| 6569 | - return true; | |
| 6570 | - } | |
| 6571 | - | |
| 6572 | - function newActionId( currentID ) { | |
| 6573 | - var newID = parseInt( currentID, 10 ) + 11; | |
| 6574 | - var exists = document.getElementById( 'frm_form_action_' + newID ); | |
| 6575 | - if ( exists !== null ) { | |
| 6576 | - newID++; | |
| 6577 | - newID = newActionId( newID ); | |
| 6578 | - } | |
| 6579 | - return newID; | |
| 6580 | - } | |
| 6581 | - | |
| 6582 | - function addFormAction() { | |
| 6583 | - /*jshint validthis:true */ | |
| 6584 | - const type = jQuery( this ).data( 'actiontype' ); | |
| 6585 | - | |
| 6586 | - if ( isAtLimitForActionType( type ) ) { | |
| 6587 | - return; | |
| 6588 | - } | |
| 6589 | - | |
| 6590 | - const actionId = getNewActionId(); | |
| 6591 | - const formId = thisFormId; | |
| 6592 | - | |
| 6593 | - const placeholderSetting = document.createElement( 'div' ); | |
| 6594 | - placeholderSetting.classList.add( 'frm_single_' + type + '_settings' ); | |
| 6595 | - | |
| 6596 | - const actionsList = document.getElementById( 'frm_notification_settings' ); | |
| 6597 | - actionsList.appendChild( placeholderSetting ); | |
| 6598 | - | |
| 6599 | - jQuery.ajax({ | |
| 6600 | - type: 'POST', | |
| 6601 | - url: ajaxurl, | |
| 6602 | - data: { | |
| 6603 | - action: 'frm_add_form_action', | |
| 6604 | - type: type, | |
| 6605 | - list_id: actionId, | |
| 6606 | - form_id: formId, | |
| 6607 | - nonce: frmGlobal.nonce | |
| 6608 | - }, | |
| 6609 | - success: handleAddFormActionSuccess | |
| 6610 | - }); | |
| 6611 | - | |
| 6612 | - function handleAddFormActionSuccess( html ) { | |
| 6613 | - fieldUpdated(); | |
| 6614 | - placeholderSetting.remove(); | |
| 6615 | - | |
| 6616 | - closeOpenActions(); | |
| 6617 | - | |
| 6618 | - const newActionContainer = div(); | |
| 6619 | - newActionContainer.innerHTML = html; | |
| 6620 | - | |
| 6621 | - const widgetTop = newActionContainer.querySelector( '.widget-top' ); | |
| 6622 | - Array.from( newActionContainer.children ).forEach( child => actionsList.appendChild( child ) ); | |
| 6623 | - | |
| 6624 | - jQuery( '.frm_form_action_settings' ).fadeIn( 'slow' ); | |
| 6625 | - | |
| 6626 | - const newAction = document.getElementById( 'frm_form_action_' + actionId ); | |
| 6627 | - | |
| 6628 | - newAction.classList.add( 'open' ); | |
| 6629 | - document.getElementById( 'post-body-content' ).scroll({ | |
| 6630 | - top: newAction.offsetTop + 10, | |
| 6631 | - left: 0, | |
| 6632 | - behavior: 'smooth' | |
| 6633 | - }); | |
| 6634 | - | |
| 6635 | - // Check if icon should be active | |
| 6636 | - checkActiveAction( type ); | |
| 6637 | - showInputIcon( '#frm_form_action_' + actionId ); | |
| 6638 | - | |
| 6639 | - initiateMultiselect(); | |
| 6640 | - frmDom.autocomplete.initAutocomplete( 'page', newAction ); | |
| 6641 | - | |
| 6642 | - if ( widgetTop ) { | |
| 6643 | - jQuery( widgetTop ).trigger( 'frm-action-loaded' ); | |
| 6644 | - } | |
| 6645 | - | |
| 6646 | - /** | |
| 6647 | - * Fires after added a new form action. | |
| 6648 | - * | |
| 6649 | - * @since 5.5.4 | |
| 6650 | - * | |
| 6651 | - * @param {HTMLElement} formAction Form action element. | |
| 6652 | - */ | |
| 6653 | - frmAdminBuild.hooks.doAction( 'frm_added_form_action', newAction ); | |
| 6654 | - } | |
| 6655 | - } | |
| 6656 | - | |
| 6657 | - function closeOpenActions() { | |
| 6658 | - document.querySelectorAll( '.frm_form_action_settings.open' ).forEach( | |
| 6659 | - setting => setting.classList.remove( 'open' ) | |
| 6660 | - ); | |
| 6661 | - } | |
| 6662 | - | |
| 6663 | - function toggleActionGroups() { | |
| 6664 | - /*jshint validthis:true */ | |
| 6665 | - var actions = document.getElementById( 'frm_email_addon_menu' ).classList, | |
| 6666 | - search = document.getElementById( 'actions-search-input' ); | |
| 6667 | - | |
| 6668 | - if ( actions.contains( 'frm-all-actions' ) ) { | |
| 6669 | - actions.remove( 'frm-all-actions' ); | |
| 6670 | - actions.add( 'frm-limited-actions' ); | |
| 6671 | - } else { | |
| 6672 | - actions.add( 'frm-all-actions' ); | |
| 6673 | - actions.remove( 'frm-limited-actions' ); | |
| 6674 | - } | |
| 6675 | - | |
| 6676 | - // Reset search. | |
| 6677 | - search.value = ''; | |
| 6678 | - triggerEvent( search, 'input' ); | |
| 6679 | - } | |
| 6680 | - | |
| 6681 | - function getNewActionId() { | |
| 6682 | - var actionSettings = document.querySelectorAll( '.frm_form_action_settings' ), | |
| 6683 | - len = getNewRowId( actionSettings, 'frm_form_action_' ); | |
| 6684 | - if ( typeof document.getElementById( 'frm_form_action_' + len ) !== 'undefined' ) { | |
| 6685 | - len = len + 100; | |
| 6686 | - } | |
| 6687 | - if ( lastNewActionIdReturned >= len ) { | |
| 6688 | - len = lastNewActionIdReturned + 1; | |
| 6689 | - } | |
| 6690 | - lastNewActionIdReturned = len; | |
| 6691 | - return len; | |
| 6692 | - } | |
| 6693 | - | |
| 6694 | - function clickAction( obj ) { | |
| 6695 | - var $thisobj = jQuery( obj ); | |
| 6696 | - | |
| 6697 | - if ( obj.className.indexOf( 'selected' ) !== -1 ) { | |
| 6698 | - return; | |
| 6699 | - } | |
| 6700 | - if ( obj.className.indexOf( 'edit_field_type_end_divider' ) !== -1 && $thisobj.closest( '.edit_field_type_divider' ).hasClass( 'no_repeat_section' ) ) { | |
| 6701 | - return; | |
| 6702 | - } | |
| 6703 | - | |
| 6704 | - deselectFields(); | |
| 6705 | - $thisobj.addClass( 'selected' ); | |
| 6706 | - showFieldOptions( obj ); | |
| 6707 | - } | |
| 6708 | - | |
| 6709 | - /** | |
| 6710 | - * When a field is selected, show the field settings in the sidebar. | |
| 6711 | - */ | |
| 6712 | - function showFieldOptions( obj ) { | |
| 6713 | - var i, singleField, | |
| 6714 | - fieldId = obj.getAttribute( 'data-fid' ), | |
| 6715 | - fieldType = obj.getAttribute( 'data-type' ), | |
| 6716 | - allFieldSettings = document.querySelectorAll( '.frm-single-settings:not(.frm_hidden)' ); | |
| 6717 | - | |
| 6718 | - for ( i = 0; i < allFieldSettings.length; i++ ) { | |
| 6719 | - allFieldSettings[i].classList.add( 'frm_hidden' ); | |
| 6720 | - } | |
| 6721 | - | |
| 6722 | - singleField = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 6723 | - moveFieldSettings( singleField ); | |
| 6724 | - | |
| 6725 | - if ( fieldType && 'quantity' === fieldType ) { | |
| 6726 | - popProductFields( jQuery( singleField ).find( '.frmjs_prod_field_opt' )[0]); | |
| 6727 | - } | |
| 6728 | - | |
| 6729 | - singleField.classList.remove( 'frm_hidden' ); | |
| 6730 | - document.getElementById( 'frm-options-panel-tab' ).click(); | |
| 6731 | - | |
| 6732 | - const editor = singleField.querySelector( '.wp-editor-area' ); | |
| 6733 | - if ( editor ) { | |
| 6734 | - frmDom.wysiwyg.init( | |
| 6735 | - editor, | |
| 6736 | - { setupCallback: setupTinyMceEventHandlers } | |
| 6737 | - ); | |
| 6738 | - } | |
| 6739 | - } | |
| 6740 | - | |
| 6741 | - function setupTinyMceEventHandlers( editor ) { | |
| 6742 | - editor.on( 'Change', function() { | |
| 6743 | - handleTinyMceChange( editor ); | |
| 6744 | - }); | |
| 6745 | - } | |
| 6746 | - | |
| 6747 | - function handleTinyMceChange( editor ) { | |
| 6748 | - if ( ! isTinyMceActive() || tinyMCE.activeEditor.isHidden() ) { | |
| 6749 | - return; | |
| 6750 | - } | |
| 6751 | - | |
| 6752 | - editor.targetElm.value = editor.getContent(); | |
| 6753 | - jQuery( editor.targetElm ).trigger( 'change' ); | |
| 6754 | - } | |
| 6755 | - | |
| 6756 | - function isTinyMceActive() { | |
| 6757 | - var activeSettings, wrapper; | |
| 6758 | - | |
| 6759 | - activeSettings = document.querySelector( '.frm-single-settings:not(.frm_hidden)' ); | |
| 6760 | - if ( ! activeSettings ) { | |
| 6761 | - return false; | |
| 6762 | - } | |
| 6763 | - | |
| 6764 | - wrapper = activeSettings.querySelector( '.wp-editor-wrap' ); | |
| 6765 | - return null !== wrapper && wrapper.classList.contains( 'tmce-active' ); | |
| 6766 | - } | |
| 6767 | - | |
| 6768 | - /** | |
| 6769 | - * Move the settings to the sidebar the first time they are changed or selected. | |
| 6770 | - * Keep the end marker at the end of the form. | |
| 6771 | - */ | |
| 6772 | - function moveFieldSettings( singleField ) { | |
| 6773 | - if ( singleField === null ) { | |
| 6774 | - // The field may have not been loaded yet via ajax. | |
| 6775 | - return; | |
| 6776 | - } | |
| 6777 | - | |
| 6778 | - var classes = singleField.parentElement.classList; | |
| 6779 | - if ( classes.contains( 'frm_field_box' ) || classes.contains( 'divider_section_only' ) ) { | |
| 6780 | - var endMarker = document.getElementById( 'frm-end-form-marker' ); | |
| 6781 | - builderForm.insertBefore( singleField, endMarker ); | |
| 6782 | - } | |
| 6783 | - } | |
| 6784 | - | |
| 6785 | - function showEmailRow() { | |
| 6786 | - /*jshint validthis:true */ | |
| 6787 | - var actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ); | |
| 6788 | - var rowType = this.getAttribute( 'data-emailrow' ); | |
| 6789 | - | |
| 6790 | - jQuery( '#frm_form_action_' + actionKey + ' .frm_' + rowType + '_row' ).fadeIn( 'slow' ); | |
| 6791 | - jQuery( this ).fadeOut( 'slow' ); | |
| 6792 | - } | |
| 6793 | - | |
| 6794 | - function hideEmailRow() { | |
| 6795 | - /*jshint validthis:true */ | |
| 6796 | - var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ), | |
| 6797 | - rowType = this.getAttribute( 'data-emailrow' ), | |
| 6798 | - emailRowSelector = '.frm_' + rowType + '_row', | |
| 6799 | - emailButtonSelector = '.frm_' + rowType + '_button'; | |
| 6800 | - | |
| 6801 | - jQuery( actionBox ).find( emailButtonSelector ).fadeIn( 'slow' ); | |
| 6802 | - jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow', function() { | |
| 6803 | - jQuery( actionBox ).find( emailRowSelector + ' input' ).val( '' ); | |
| 6804 | - }); | |
| 6805 | - } | |
| 6806 | - | |
| 6807 | - function showEmailWarning() { | |
| 6808 | - /*jshint validthis:true */ | |
| 6809 | - var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ), | |
| 6810 | - emailRowSelector = '.frm_from_to_match_row', | |
| 6811 | - fromVal = actionBox.find( 'input[name$="[post_content][from]"]' ).val(), | |
| 6812 | - toVal = actionBox.find( 'input[name$="[post_content][email_to]"]' ).val(); | |
| 6813 | - | |
| 6814 | - if ( fromVal === toVal ) { | |
| 6815 | - jQuery( actionBox ).find( emailRowSelector ).fadeIn( 'slow' ); | |
| 6816 | - } else { | |
| 6817 | - jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow' ); | |
| 6818 | - } | |
| 6819 | - } | |
| 6820 | - | |
| 6821 | - function checkActiveAction( type ) { | |
| 6822 | - const actionTriggers = document.querySelectorAll( '.frm_' + type + '_action' ); | |
| 6823 | - | |
| 6824 | - if ( isAtLimitForActionType( type ) ) { | |
| 6825 | - const addAlreadyUsedClass = getLimitForActionType( type ) > 0; | |
| 6826 | - markActionTriggersInactive( actionTriggers, addAlreadyUsedClass ); | |
| 6827 | - return; | |
| 6828 | - } | |
| 6829 | - | |
| 6830 | - markActionTriggersActive( actionTriggers ); | |
| 6831 | - } | |
| 6832 | - | |
| 6833 | - function markActionTriggersActive( triggers ) { | |
| 6834 | - triggers.forEach( | |
| 6835 | - trigger => { | |
| 6836 | - if ( trigger.querySelector( '.frm_show_upgrade' ) ) { | |
| 6837 | - // Prevent disabled action becoming active. | |
| 6838 | - return; | |
| 6839 | - } | |
| 6840 | - | |
| 6841 | - trigger.classList.remove( 'frm_inactive_action', 'frm_already_used' ); | |
| 6842 | - trigger.classList.add( 'frm_active_action' ); | |
| 6843 | - } | |
| 6844 | - ); | |
| 6845 | - } | |
| 6846 | - | |
| 6847 | - function markActionTriggersInactive( triggers, addAlreadyUsedClass ) { | |
| 6848 | - triggers.forEach( | |
| 6849 | - trigger => { | |
| 6850 | - trigger.classList.remove( 'frm_active_action' ); | |
| 6851 | - trigger.classList.add( 'frm_inactive_action' ); | |
| 6852 | - if ( addAlreadyUsedClass ) { | |
| 6853 | - trigger.classList.add( 'frm_already_used' ); | |
| 6854 | - } | |
| 6855 | - } | |
| 6856 | - ); | |
| 6857 | - } | |
| 6858 | - | |
| 6859 | - function isAtLimitForActionType( type ) { | |
| 6860 | - let atLimit = getNumberOfActionsForType( type ) >= getLimitForActionType( type ); | |
| 6861 | - | |
| 6862 | - const hookName = 'frm_action_at_limit'; | |
| 6863 | - const hookArgs = { type }; | |
| 6864 | - atLimit = wp.hooks.applyFilters( hookName, atLimit, hookArgs ); | |
| 6865 | - | |
| 6866 | - return atLimit; | |
| 6867 | - } | |
| 6868 | - | |
| 6869 | - function getLimitForActionType( type ) { | |
| 6870 | - return parseInt( jQuery( '.frm_' + type + '_action' ).data( 'limit' ), 10 ); | |
| 6871 | - } | |
| 6872 | - | |
| 6873 | - function getNumberOfActionsForType( type ) { | |
| 6874 | - return jQuery( '.frm_single_' + type + '_settings' ).length; | |
| 6875 | - } | |
| 6876 | - | |
| 6877 | - function onlyOneActionMessage() { | |
| 6878 | - infoModal( frm_admin_js.only_one_action ); // eslint-disable-line camelcase | |
| 6879 | - } | |
| 6880 | - | |
| 6881 | - function addFormLogicRow() { | |
| 6882 | - /*jshint validthis:true */ | |
| 6883 | - var id = jQuery( this ).data( 'emailkey' ), | |
| 6884 | - type = jQuery( this ).closest( '.frm_form_action_settings' ).find( '.frm_action_name' ).val(), | |
| 6885 | - formId = document.getElementById( 'form_id' ).value, | |
| 6886 | - logicRows = document.getElementById( 'frm_form_action_' + id ).querySelectorAll( '.frm_logic_row' ); | |
| 6887 | - jQuery.ajax({ | |
| 6888 | - type: 'POST', url: ajaxurl, | |
| 6889 | - data: { | |
| 6890 | - action: 'frm_add_form_logic_row', | |
| 6891 | - email_id: id, | |
| 6892 | - form_id: formId, | |
| 6893 | - meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ), | |
| 6894 | - type: type, | |
| 6895 | - nonce: frmGlobal.nonce | |
| 6896 | - }, | |
| 6897 | - success: function( html ) { | |
| 6898 | - jQuery( document.getElementById( 'logic_link_' + id ) ).fadeOut( 'slow', function() { | |
| 6899 | - var $logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) ); | |
| 6900 | - $logicRow.append( html ); | |
| 6901 | - $logicRow.parent( '.frm_logic_rows' ).fadeIn( 'slow' ); | |
| 6902 | - }); | |
| 6903 | - } | |
| 6904 | - }); | |
| 6905 | - return false; | |
| 6906 | - } | |
| 6907 | - | |
| 6908 | - function toggleSubmitLogic() { | |
| 6909 | - /*jshint validthis:true */ | |
| 6910 | - if ( this.checked ) { | |
| 6911 | - addSubmitLogic(); | |
| 6912 | - } else { | |
| 6913 | - jQuery( '.frm_logic_row_submit' ).remove(); | |
| 6914 | - document.getElementById( 'frm_submit_logic_rows' ).style.display = 'none'; | |
| 6915 | - } | |
| 6916 | - } | |
| 6917 | - | |
| 6918 | - /** | |
| 6919 | - * Adds submit button Conditional Logic row and reveals submit button Conditional Logic | |
| 6920 | - * | |
| 6921 | - * @returns {boolean} | |
| 6922 | - */ | |
| 6923 | - function addSubmitLogic() { | |
| 6924 | - /*jshint validthis:true */ | |
| 6925 | - var formId = thisFormId, | |
| 6926 | - logicRows = document.getElementById( 'frm_submit_logic_row' ).querySelectorAll( '.frm_logic_row' ); | |
| 6927 | - jQuery.ajax({ | |
| 6928 | - type: 'POST', | |
| 6929 | - url: ajaxurl, | |
| 6930 | - data: { | |
| 6931 | - action: 'frm_add_submit_logic_row', | |
| 6932 | - form_id: formId, | |
| 6933 | - meta_name: getNewRowId( logicRows, 'frm_logic_submit_' ), | |
| 6934 | - nonce: frmGlobal.nonce | |
| 6935 | - }, | |
| 6936 | - success: function( html ) { | |
| 6937 | - var $logicRow = jQuery( document.getElementById( 'frm_submit_logic_row' ) ); | |
| 6938 | - $logicRow.append( html ); | |
| 6939 | - $logicRow.parent( '.frm_submit_logic_rows' ).fadeIn( 'slow' ); | |
| 6940 | - } | |
| 6941 | - }); | |
| 6942 | - return false; | |
| 6943 | - } | |
| 6944 | - | |
| 6945 | - /** | |
| 6946 | - * When the user selects a field for a submit condition, update corresponding options field accordingly. | |
| 6947 | - */ | |
| 6948 | - function addSubmitLogicOpts() { | |
| 6949 | - var fieldOpt = jQuery( this ); | |
| 6950 | - var fieldId = fieldOpt.find( ':selected' ).val(); | |
| 6951 | - | |
| 6952 | - if ( fieldId ) { | |
| 6953 | - var row = fieldOpt.data( 'row' ); | |
| 6954 | - frmGetFieldValues( fieldId, 'submit', row, '', 'options[submit_conditions][hide_opt][]' ); | |
| 6955 | - } | |
| 6956 | - } | |
| 6957 | - | |
| 6958 | - function formatEmailSetting() { | |
| 6959 | - /*jshint validthis:true */ | |
| 6960 | - /*var val = jQuery( this ).val(); | |
| 6961 | - var email = val.match( /(\s[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi ); | |
| 6962 | - if(email !== null && email.length) { | |
| 6963 | - //has email | |
| 6964 | - //TODO: add < > if they aren't there | |
| 6965 | - }*/ | |
| 6966 | - } | |
| 6967 | - | |
| 6968 | - function checkDupPost() { | |
| 6969 | - /*jshint validthis:true */ | |
| 6970 | - var postField = jQuery( 'select.frm_single_post_field' ); | |
| 6971 | - postField.css( 'border-color', '' ); | |
| 6972 | - var $t = this; | |
| 6973 | - var v = jQuery( $t ).val(); | |
| 6974 | - if ( v === '' || v === 'checkbox' ) { | |
| 6975 | - return false; | |
| 6976 | - } | |
| 6977 | - postField.each( function() { | |
| 6978 | - if ( jQuery( this ).val() === v && this.name !== $t.name ) { | |
| 6979 | - this.style.borderColor = 'red'; | |
| 6980 | - jQuery( $t ).val( '' ); | |
| 6981 | - infoModal( frm_admin_js.field_already_used ); // eslint-disable-line camelcase | |
| 6982 | - return false; | |
| 6983 | - } | |
| 6984 | - }); | |
| 6985 | - } | |
| 6986 | - | |
| 6987 | - function togglePostContent() { | |
| 6988 | - /*jshint validthis:true */ | |
| 6989 | - var v = jQuery( this ).val(); | |
| 6990 | - if ( '' === v ) { | |
| 6991 | - jQuery( '.frm_post_content_opt, select.frm_dyncontent_opt' ).hide().val( '' ); | |
| 6992 | - jQuery( '.frm_dyncontent_opt' ).hide(); | |
| 6993 | - } else if ( 'post_content' === v ) { | |
| 6994 | - jQuery( '.frm_post_content_opt' ).show(); | |
| 6995 | - jQuery( '.frm_dyncontent_opt' ).hide(); | |
| 6996 | - jQuery( 'select.frm_dyncontent_opt' ).val( '' ); | |
| 6997 | - } else { | |
| 6998 | - jQuery( '.frm_post_content_opt' ).hide().val( '' ); | |
| 6999 | - jQuery( 'select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt' ).show(); | |
| 7000 | - } | |
| 7001 | - } | |
| 7002 | - | |
| 7003 | - function fillDyncontent() { | |
| 7004 | - /*jshint validthis:true */ | |
| 7005 | - var v = jQuery( this ).val(); | |
| 7006 | - var $dyn = jQuery( document.getElementById( 'frm_dyncontent' ) ); | |
| 7007 | - if ( '' === v || 'new' === v ) { | |
| 7008 | - $dyn.val( '' ); | |
| 7009 | - jQuery( '.frm_dyncontent_opt' ).show(); | |
| 7010 | - } else { | |
| 7011 | - jQuery.ajax({ | |
| 7012 | - type: 'POST', url: ajaxurl, | |
| 7013 | - data: {action: 'frm_display_get_content', id: v, nonce: frmGlobal.nonce}, | |
| 7014 | - success: function( val ) { | |
| 7015 | - $dyn.val( val ); | |
| 7016 | - jQuery( '.frm_dyncontent_opt' ).show(); | |
| 7017 | - } | |
| 7018 | - }); | |
| 7019 | - } | |
| 7020 | - } | |
| 7021 | - | |
| 7022 | - function switchPostType() { | |
| 7023 | - /*jshint validthis:true */ | |
| 7024 | - // update all rows of categories/taxonomies | |
| 7025 | - var curSelect, newSelect, | |
| 7026 | - catRows = document.getElementById( 'frm_posttax_rows' ).childNodes, | |
| 7027 | - postParentField = document.querySelector( '.frm_post_parent_field' ), | |
| 7028 | - postMenuOrderField = document.querySelector( '.frm_post_menu_order_field' ), | |
| 7029 | - postType = this.value; | |
| 7030 | - | |
| 7031 | - // Get new category/taxonomy options | |
| 7032 | - jQuery.ajax({ | |
| 7033 | - type: 'POST', | |
| 7034 | - url: ajaxurl, | |
| 7035 | - data: { | |
| 7036 | - action: 'frm_replace_posttax_options', | |
| 7037 | - post_type: postType, | |
| 7038 | - nonce: frmGlobal.nonce | |
| 7039 | - }, | |
| 7040 | - success: function( html ) { | |
| 7041 | - | |
| 7042 | - // Loop through each category row, and replace the first dropdown | |
| 7043 | - for ( i = 0; i < catRows.length; i++ ) { | |
| 7044 | - // Check if current element is a div | |
| 7045 | - if ( catRows[i].tagName !== 'DIV' ) { | |
| 7046 | - continue; | |
| 7047 | - } | |
| 7048 | - | |
| 7049 | - // Get current category select | |
| 7050 | - curSelect = catRows[i].getElementsByTagName( 'select' )[0]; | |
| 7051 | - | |
| 7052 | - // Set up new select | |
| 7053 | - newSelect = document.createElement( 'select' ); | |
| 7054 | - newSelect.innerHTML = html; | |
| 7055 | - newSelect.className = curSelect.className; | |
| 7056 | - newSelect.name = curSelect.name; | |
| 7057 | - | |
| 7058 | - // Replace the old select with the new select | |
| 7059 | - catRows[i].replaceChild( newSelect, curSelect ); | |
| 7060 | - } | |
| 7061 | - } | |
| 7062 | - }); | |
| 7063 | - | |
| 7064 | - // Get new post parent option. | |
| 7065 | - if ( postParentField ) { | |
| 7066 | - getActionOption( | |
| 7067 | - postParentField, | |
| 7068 | - postType, | |
| 7069 | - 'frm_get_post_parent_option', | |
| 7070 | - function( response, optName ) { | |
| 7071 | - // The replaced string is declared in FrmProFormActionController::ajax_get_post_menu_order_option() in the pro version. | |
| 7072 | - postParentField.querySelector( '.frm_post_parent_opt_wrapper' ).innerHTML = response.replaceAll( 'REPLACETHISNAME', optName ); | |
| 7073 | - frmDom.autocomplete.initAutocomplete( 'page', postParentField ); | |
| 7074 | - } | |
| 7075 | - ); | |
| 7076 | - } | |
| 7077 | - | |
| 7078 | - if ( postMenuOrderField ) { | |
| 7079 | - getActionOption( postMenuOrderField, postType, 'frm_should_use_post_menu_order_option' ); | |
| 7080 | - } | |
| 7081 | - } | |
| 7082 | - | |
| 7083 | - function getActionOption( field, postType, action, successHandler ) { | |
| 7084 | - const opt = field.querySelector( '.frm_autocomplete_value_input' ) || field.querySelector( 'select' ), | |
| 7085 | - optName = opt.getAttribute( 'name' ); | |
| 7086 | - | |
| 7087 | - jQuery.ajax({ | |
| 7088 | - url: ajaxurl, | |
| 7089 | - method: 'POST', | |
| 7090 | - data: { | |
| 7091 | - action: action, | |
| 7092 | - post_type: postType, | |
| 7093 | - _wpnonce: frmGlobal.nonce | |
| 7094 | - }, | |
| 7095 | - success: response => { | |
| 7096 | - if ( 'string' !== typeof response ) { | |
| 7097 | - console.error( response ); | |
| 7098 | - return; | |
| 7099 | - } | |
| 7100 | - | |
| 7101 | - if ( '0' === response ) { | |
| 7102 | - // This post type does not support this field. | |
| 7103 | - field.classList.add( 'frm_hidden' ); | |
| 7104 | - field.value = ''; | |
| 7105 | - return; | |
| 7106 | - } | |
| 7107 | - | |
| 7108 | - field.classList.remove( 'frm_hidden' ); | |
| 7109 | - | |
| 7110 | - if ( 'function' === typeof successHandler ) { | |
| 7111 | - successHandler( response, optName ); | |
| 7112 | - } | |
| 7113 | - }, | |
| 7114 | - error: response => console.error( response ) | |
| 7115 | - }); | |
| 7116 | - } | |
| 7117 | - | |
| 7118 | - function addPosttaxRow() { | |
| 7119 | - /*jshint validthis:true */ | |
| 7120 | - addPostRow( 'tax', this ); | |
| 7121 | - } | |
| 7122 | - | |
| 7123 | - function addPostmetaRow() { | |
| 7124 | - /*jshint validthis:true */ | |
| 7125 | - addPostRow( 'meta', this ); | |
| 7126 | - } | |
| 7127 | - | |
| 7128 | - function addPostRow( type, button ) { | |
| 7129 | - var name, | |
| 7130 | - id = jQuery( 'input[name="id"]' ).val(), | |
| 7131 | - settings = jQuery( button ).closest( '.frm_form_action_settings' ), | |
| 7132 | - key = settings.data( 'actionkey' ), | |
| 7133 | - postType = settings.find( '.frm_post_type' ).val(), | |
| 7134 | - metaName = 0, | |
| 7135 | - postTypeRows = document.querySelectorAll( '.frm_post' + type + '_row' ); | |
| 7136 | - | |
| 7137 | - if ( postTypeRows.length ) { | |
| 7138 | - name = postTypeRows[ postTypeRows.length - 1 ].id.replace( 'frm_post' + type + '_', '' ); | |
| 7139 | - if ( isNumeric( name ) ) { | |
| 7140 | - metaName = 1 + parseInt( name, 10 ); | |
| 7141 | - } else { | |
| 7142 | - metaName = 1; | |
| 7143 | - } | |
| 7144 | - } | |
| 7145 | - | |
| 7146 | - jQuery.ajax({ | |
| 7147 | - type: 'POST', url: ajaxurl, | |
| 7148 | - data: { | |
| 7149 | - action: 'frm_add_post' + type + '_row', | |
| 7150 | - form_id: id, | |
| 7151 | - meta_name: metaName, | |
| 7152 | - tax_key: metaName, | |
| 7153 | - post_type: postType, | |
| 7154 | - action_key: key, | |
| 7155 | - nonce: frmGlobal.nonce | |
| 7156 | - }, | |
| 7157 | - success: function( html ) { | |
| 7158 | - var cfOpts, optIndex; | |
| 7159 | - jQuery( document.getElementById( 'frm_post' + type + '_rows' ) ).append( html ); | |
| 7160 | - jQuery( '.frm_add_post' + type + '_row.button' ).hide(); | |
| 7161 | - | |
| 7162 | - if ( type === 'meta' ) { | |
| 7163 | - jQuery( '.frm_name_value' ).show(); | |
| 7164 | - cfOpts = document.querySelectorAll( '.frm_toggle_cf_opts' ); | |
| 7165 | - for ( optIndex = 0; optIndex < cfOpts.length - 1; ++optIndex ) { | |
| 7166 | - cfOpts[ optIndex ].style.display = 'none'; | |
| 7167 | - } | |
| 7168 | - } else if ( type === 'tax' ) { | |
| 7169 | - jQuery( '.frm_posttax_labels' ).show(); | |
| 7170 | - } | |
| 7171 | - } | |
| 7172 | - }); | |
| 7173 | - } | |
| 7174 | - | |
| 7175 | - function isNumeric( value ) { | |
| 7176 | - return ! isNaN( parseFloat( value ) ) && isFinite( value ); | |
| 7177 | - } | |
| 7178 | - | |
| 7179 | - function getMetaValue( id, metaName ) { | |
| 7180 | - var newMeta = metaName; | |
| 7181 | - if ( jQuery( document.getElementById( id + metaName ) ).length > 0 ) { | |
| 7182 | - newMeta = getMetaValue( id, metaName + 1 ); | |
| 7183 | - } | |
| 7184 | - return newMeta; | |
| 7185 | - } | |
| 7186 | - | |
| 7187 | - function changePosttaxRow() { | |
| 7188 | - /*jshint validthis:true */ | |
| 7189 | - if ( ! jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).length ) { | |
| 7190 | - return; | |
| 7191 | - } | |
| 7192 | - | |
| 7193 | - jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).html( '<div class="spinner frm_spinner" style="display:block"></div>' ); | |
| 7194 | - | |
| 7195 | - var postType = jQuery( this ).closest( '.frm_form_action_settings' ).find( 'select[name$="[post_content][post_type]"]' ).val(), | |
| 7196 | - actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ), | |
| 7197 | - taxKey = jQuery( this ).closest( '.frm_posttax_row' ).attr( 'id' ).replace( 'frm_posttax_', '' ), | |
| 7198 | - metaName = jQuery( this ).val(), | |
| 7199 | - showExclude = jQuery( document.getElementById( taxKey + '_show_exclude' ) ).is( ':checked' ) ? 1 : 0, | |
| 7200 | - fieldId = jQuery( 'select[name$="[post_category][' + taxKey + '][field_id]"]' ).val(), | |
| 7201 | - id = jQuery( 'input[name="id"]' ).val(); | |
| 7202 | - | |
| 7203 | - jQuery.ajax({ | |
| 7204 | - type: 'POST', | |
| 7205 | - url: ajaxurl, | |
| 7206 | - data: { | |
| 7207 | - action: 'frm_add_posttax_row', | |
| 7208 | - form_id: id, | |
| 7209 | - post_type: postType, | |
| 7210 | - tax_key: taxKey, | |
| 7211 | - action_key: actionKey, | |
| 7212 | - meta_name: metaName, | |
| 7213 | - field_id: fieldId, | |
| 7214 | - show_exclude: showExclude, | |
| 7215 | - nonce: frmGlobal.nonce | |
| 7216 | - }, | |
| 7217 | - success: function( html ) { | |
| 7218 | - var $tax = jQuery( document.getElementById( 'frm_posttax_' + taxKey ) ); | |
| 7219 | - $tax.replaceWith( html ); | |
| 7220 | - } | |
| 7221 | - }); | |
| 7222 | - } | |
| 7223 | - | |
| 7224 | - function toggleCfOpts() { | |
| 7225 | - /*jshint validthis:true */ | |
| 7226 | - var row = jQuery( this ).closest( '.frm_postmeta_row' ); | |
| 7227 | - var cancel = row.find( '.frm_cancelnew' ); | |
| 7228 | - var select = row.find( '.frm_enternew' ); | |
| 7229 | - if ( row.find( 'select.frm_cancelnew' ).is( ':visible' ) ) { | |
| 7230 | - cancel.hide(); | |
| 7231 | - select.show(); | |
| 7232 | - } else { | |
| 7233 | - cancel.show(); | |
| 7234 | - select.hide(); | |
| 7235 | - } | |
| 7236 | - | |
| 7237 | - row.find( 'input.frm_enternew, select.frm_cancelnew' ).val( '' ); | |
| 7238 | - return false; | |
| 7239 | - } | |
| 7240 | - | |
| 7241 | - function toggleFormOpts() { | |
| 7242 | - /*jshint validthis:true */ | |
| 7243 | - var changedOpt = jQuery( this ); | |
| 7244 | - var val = changedOpt.val(); | |
| 7245 | - if ( changedOpt.attr( 'type' ) === 'checkbox' ) { | |
| 7246 | - if ( this.checked === false ) { | |
| 7247 | - val = ''; | |
| 7248 | - } | |
| 7249 | - } | |
| 7250 | - | |
| 7251 | - var toggleClass = changedOpt.data( 'toggleclass' ); | |
| 7252 | - if ( val === '' ) { | |
| 7253 | - jQuery( '.' + toggleClass ).hide(); | |
| 7254 | - } else { | |
| 7255 | - jQuery( '.' + toggleClass ).show(); | |
| 7256 | - jQuery( '.hide_' + toggleClass + '_' + val ).hide(); | |
| 7257 | - } | |
| 7258 | - } | |
| 7259 | - | |
| 7260 | - function submitSettings() { | |
| 7261 | - /*jshint validthis:true */ | |
| 7262 | - preFormSave( this ); | |
| 7263 | - triggerSubmit( document.querySelector( '.frm_form_settings' ) ); | |
| 7264 | - } | |
| 7265 | - | |
| 7266 | - /* View Functions */ | |
| 7267 | - function showCount() { | |
| 7268 | - /*jshint validthis:true */ | |
| 7269 | - var value = jQuery( this ).val(); | |
| 7270 | - | |
| 7271 | - var $cont = document.getElementById( 'date_select_container' ); | |
| 7272 | - var tab = document.getElementById( 'frm_listing_tab' ); | |
| 7273 | - var label = tab.getAttribute( 'data-label' ); | |
| 7274 | - if ( value === 'calendar' ) { | |
| 7275 | - jQuery( '.hide_dyncontent, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 7276 | - jQuery( '.limit_container' ).addClass( 'frm_hidden' ); | |
| 7277 | - $cont.style.display = 'block'; | |
| 7278 | - } else if ( value === 'dynamic' ) { | |
| 7279 | - jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 7280 | - } else if ( value === 'one' ) { | |
| 7281 | - label = tab.getAttribute( 'data-one' ); | |
| 7282 | - jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).addClass( 'frm_hidden' ); | |
| 7283 | - } else { | |
| 7284 | - jQuery( '.hide_dyncontent' ).addClass( 'frm_hidden' ); | |
| 7285 | - jQuery( '.limit_container, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 7286 | - } | |
| 7287 | - | |
| 7288 | - if ( value !== 'calendar' ) { | |
| 7289 | - $cont.style.display = 'none'; | |
| 7290 | - } | |
| 7291 | - tab.innerHTML = label; | |
| 7292 | - } | |
| 7293 | - | |
| 7294 | - function displayFormSelected() { | |
| 7295 | - /*jshint validthis:true */ | |
| 7296 | - var formId = jQuery( this ).val(); | |
| 7297 | - thisFormId = formId; // set the global form id | |
| 7298 | - if ( formId === '' ) { | |
| 7299 | - return; | |
| 7300 | - } | |
| 7301 | - | |
| 7302 | - jQuery.ajax({ | |
| 7303 | - type: 'POST', | |
| 7304 | - url: ajaxurl, | |
| 7305 | - data: { | |
| 7306 | - action: 'frm_get_cd_tags_box', | |
| 7307 | - form_id: formId, | |
| 7308 | - nonce: frmGlobal.nonce | |
| 7309 | - }, | |
| 7310 | - success: function( html ) { | |
| 7311 | - jQuery( '#frm_adv_info .categorydiv' ).html( html ); | |
| 7312 | - } | |
| 7313 | - }); | |
| 7314 | - | |
| 7315 | - jQuery.ajax({ | |
| 7316 | - type: 'POST', | |
| 7317 | - url: ajaxurl, | |
| 7318 | - data: { | |
| 7319 | - action: 'frm_get_date_field_select', | |
| 7320 | - form_id: formId, | |
| 7321 | - nonce: frmGlobal.nonce | |
| 7322 | - }, | |
| 7323 | - success: function( html ) { | |
| 7324 | - jQuery( document.getElementById( 'date_select_container' ) ).html( html ); | |
| 7325 | - } | |
| 7326 | - }); | |
| 7327 | - } | |
| 7328 | - | |
| 7329 | - function clickTabsAfterAjax() { | |
| 7330 | - /*jshint validthis:true */ | |
| 7331 | - var t = jQuery( this ).attr( 'href' ); | |
| 7332 | - jQuery( this ).parent().addClass( 'tabs' ).siblings( 'li' ).removeClass( 'tabs' ); | |
| 7333 | - jQuery( t ).show().siblings( '.tabs-panel' ).hide(); | |
| 7334 | - return false; | |
| 7335 | - } | |
| 7336 | - | |
| 7337 | - function clickContentTab() { | |
| 7338 | - /*jshint validthis:true */ | |
| 7339 | - link = jQuery( this ); | |
| 7340 | - var t = link.attr( 'href' ); | |
| 7341 | - if ( typeof t === 'undefined' ) { | |
| 7342 | - return false; | |
| 7343 | - } | |
| 7344 | - | |
| 7345 | - var c = t.replace( '#', '.' ); | |
| 7346 | - link.closest( '.nav-tab-wrapper' ).find( 'a' ).removeClass( 'nav-tab-active' ); | |
| 7347 | - link.addClass( 'nav-tab-active' ); | |
| 7348 | - jQuery( '.nav-menu-content' ).not( t ).not( c ).hide(); | |
| 7349 | - jQuery( t + ',' + c ).show(); | |
| 7350 | - | |
| 7351 | - return false; | |
| 7352 | - } | |
| 7353 | - | |
| 7354 | - function addOrderRow() { | |
| 7355 | - var logicRows = document.getElementById( 'frm_order_options' ).querySelectorAll( '.frm_logic_rows div' ); | |
| 7356 | - jQuery.ajax({ | |
| 7357 | - type: 'POST', | |
| 7358 | - url: ajaxurl, | |
| 7359 | - data: { | |
| 7360 | - action: 'frm_add_order_row', | |
| 7361 | - form_id: thisFormId, | |
| 7362 | - order_key: getNewRowId( logicRows, 'frm_order_field_', 1 ), | |
| 7363 | - nonce: frmGlobal.nonce | |
| 7364 | - }, | |
| 7365 | - success: function( html ) { | |
| 7366 | - jQuery( '#frm_order_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_order_row' ).hide(); | |
| 7367 | - } | |
| 7368 | - }); | |
| 7369 | - } | |
| 7370 | - | |
| 7371 | - function addWhereRow() { | |
| 7372 | - var rowDivs = document.getElementById( 'frm_where_options' ).querySelectorAll( '.frm_logic_rows div' ); | |
| 7373 | - jQuery.ajax({ | |
| 7374 | - type: 'POST', | |
| 7375 | - url: ajaxurl, | |
| 7376 | - data: { | |
| 7377 | - action: 'frm_add_where_row', | |
| 7378 | - form_id: thisFormId, | |
| 7379 | - where_key: getNewRowId( rowDivs, 'frm_where_field_', 1 ), | |
| 7380 | - nonce: frmGlobal.nonce | |
| 7381 | - }, | |
| 7382 | - success: function( html ) { | |
| 7383 | - jQuery( '#frm_where_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_where_row' ).hide(); | |
| 7384 | - } | |
| 7385 | - }); | |
| 7386 | - } | |
| 7387 | - | |
| 7388 | - function insertWhereOptions() { | |
| 7389 | - /*jshint validthis:true */ | |
| 7390 | - var value = this.value, | |
| 7391 | - whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' ); | |
| 7392 | - | |
| 7393 | - jQuery.ajax({ | |
| 7394 | - type: 'POST', | |
| 7395 | - url: ajaxurl, | |
| 7396 | - data: { | |
| 7397 | - action: 'frm_add_where_options', | |
| 7398 | - where_key: whereKey, | |
| 7399 | - field_id: value, | |
| 7400 | - nonce: frmGlobal.nonce | |
| 7401 | - }, | |
| 7402 | - success: function( html ) { | |
| 7403 | - jQuery( document.getElementById( 'where_field_options_' + whereKey ) ).html( html ); | |
| 7404 | - } | |
| 7405 | - }); | |
| 7406 | - } | |
| 7407 | - | |
| 7408 | - function hideWhereOptions() { | |
| 7409 | - /*jshint validthis:true */ | |
| 7410 | - var value = this.value, | |
| 7411 | - whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' ); | |
| 7412 | - | |
| 7413 | - if ( value === 'group_by' || value === 'group_by_newest' ) { | |
| 7414 | - document.getElementById( 'where_field_options_' + whereKey ).style.display = 'none'; | |
| 7415 | - } else { | |
| 7416 | - document.getElementById( 'where_field_options_' + whereKey ).style.display = 'inline-block'; | |
| 7417 | - } | |
| 7418 | - } | |
| 7419 | - | |
| 7420 | - function setDefaultPostStatus() { | |
| 7421 | - var urlQuery = window.location.search.substring( 1 ); | |
| 7422 | - if ( urlQuery.indexOf( 'action=edit' ) === -1 ) { | |
| 7423 | - document.getElementById( 'post-visibility-display' ).textContent = frm_admin_js.private_label; // eslint-disable-line camelcase | |
| 7424 | - document.getElementById( 'hidden-post-visibility' ).value = 'private'; | |
| 7425 | - document.getElementById( 'visibility-radio-private' ).checked = true; | |
| 7426 | - } | |
| 7427 | - } | |
| 7428 | - | |
| 7429 | - /* Customization Panel */ | |
| 7430 | - function insertCode( e ) { | |
| 7431 | - /*jshint validthis:true */ | |
| 7432 | - e.preventDefault(); | |
| 7433 | - insertFieldCode( jQuery( this ), this.getAttribute( 'data-code' ) ); | |
| 7434 | - return false; | |
| 7435 | - } | |
| 7436 | - | |
| 7437 | - function insertFieldCode( element, variable ) { | |
| 7438 | - var rich = false, | |
| 7439 | - elementId = element; | |
| 7440 | - if ( typeof element === 'object' ) { | |
| 7441 | - if ( element.hasClass( 'frm_noallow' ) ) { | |
| 7442 | - return; | |
| 7443 | - } | |
| 7444 | - | |
| 7445 | - elementId = jQuery( element ).closest( '[data-fills]' ).attr( 'data-fills' ); | |
| 7446 | - if ( typeof elementId === 'undefined' ) { | |
| 7447 | - elementId = element.closest( 'div' ).attr( 'class' ); | |
| 7448 | - if ( typeof elementId !== 'undefined' ) { | |
| 7449 | - elementId = elementId.split( ' ' )[1]; | |
| 7450 | - } | |
| 7451 | - } | |
| 7452 | - } | |
| 7453 | - | |
| 7454 | - if ( typeof elementId === 'undefined' ) { | |
| 7455 | - var active = document.activeElement; | |
| 7456 | - if ( active.type === 'search' ) { | |
| 7457 | - // If the search field has focus, find the correct field. | |
| 7458 | - elementId = active.id.replace( '-search-input', '' ); | |
| 7459 | - if ( elementId.match( /\d/gi ) === null ) { | |
| 7460 | - active = jQuery( '.frm-single-settings:visible .' + elementId ); | |
| 7461 | - elementId = active.attr( 'id' ); | |
| 7462 | - } | |
| 7463 | - } else { | |
| 7464 | - elementId = active.id; | |
| 7465 | - } | |
| 7466 | - } | |
| 7467 | - | |
| 7468 | - if ( elementId ) { | |
| 7469 | - rich = jQuery( '#wp-' + elementId + '-wrap.wp-editor-wrap' ).length > 0; | |
| 7470 | - } | |
| 7471 | - | |
| 7472 | - var contentBox = jQuery( document.getElementById( elementId ) ); | |
| 7473 | - if ( typeof element.attr( 'data-shortcode' ) === 'undefined' && ( ! contentBox.length || typeof contentBox.attr( 'data-shortcode' ) === 'undefined' ) ) { | |
| 7474 | - // this helps to exclude those that don't want shortcode-like inserted content e.g. frm-pro's summary field | |
| 7475 | - var doShortcode = element.parents( 'ul.frm_code_list' ).attr( 'data-shortcode' ); | |
| 7476 | - if ( doShortcode === 'undefined' || doShortcode !== 'no' ) { | |
| 7477 | - variable = '[' + variable + ']'; | |
| 7478 | - } | |
| 7479 | - } | |
| 7480 | - | |
| 7481 | - if ( rich ) { | |
| 7482 | - wpActiveEditor = elementId; | |
| 7483 | - } | |
| 7484 | - | |
| 7485 | - if ( ! contentBox.length ) { | |
| 7486 | - return false; | |
| 7487 | - } | |
| 7488 | - | |
| 7489 | - if ( variable === '[default-html]' || variable === '[default-plain]' ) { | |
| 7490 | - var p = 0; | |
| 7491 | - if ( variable === '[default-plain]' ) { | |
| 7492 | - p = 1; | |
| 7493 | - } | |
| 7494 | - jQuery.ajax({ | |
| 7495 | - type: 'POST', url: ajaxurl, | |
| 7496 | - data: { | |
| 7497 | - action: 'frm_get_default_html', | |
| 7498 | - form_id: jQuery( 'input[name="id"]' ).val(), | |
| 7499 | - plain_text: p, | |
| 7500 | - nonce: frmGlobal.nonce | |
| 7501 | - }, | |
| 7502 | - elementId: elementId, | |
| 7503 | - success: function( msg ) { | |
| 7504 | - if ( rich ) { | |
| 7505 | - let p = document.createElement( 'p' ); | |
| 7506 | - p.innerText = msg; | |
| 7507 | - send_to_editor( p.innerHTML ); | |
| 7508 | - } else { | |
| 7509 | - insertContent( contentBox, msg ); | |
| 7510 | - } | |
| 7511 | - } | |
| 7512 | - }); | |
| 7513 | - } else { | |
| 7514 | - variable = maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox ); | |
| 7515 | - if ( rich ) { | |
| 7516 | - send_to_editor( variable ); | |
| 7517 | - } else { | |
| 7518 | - insertContent( contentBox, variable ); | |
| 7519 | - } | |
| 7520 | - } | |
| 7521 | - return false; | |
| 7522 | - } | |
| 7523 | - | |
| 7524 | - function maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox ) { | |
| 7525 | - if ( 'object' !== typeof element || ! ( element instanceof jQuery ) || 0 !== contentBox[0].id.indexOf( 'success_url_' ) ) { | |
| 7526 | - return variable; | |
| 7527 | - } | |
| 7528 | - | |
| 7529 | - element = element[0]; | |
| 7530 | - if ( ! element.closest( '#frm-insert-fields-box' ) ) { | |
| 7531 | - // Only add sanitize_url=1 to field shortcodes. | |
| 7532 | - return variable; | |
| 7533 | - } | |
| 7534 | - | |
| 7535 | - if ( ! element.parentNode.classList.contains( 'frm_insert_url' ) ) { | |
| 7536 | - variable = variable.replace( ']', ' sanitize_url=1]' ); | |
| 7537 | - } | |
| 7538 | - | |
| 7539 | - return variable; | |
| 7540 | - } | |
| 7541 | - | |
| 7542 | - function insertContent( contentBox, variable ) { | |
| 7543 | - if ( document.selection ) { | |
| 7544 | - contentBox[0].focus(); | |
| 7545 | - document.selection.createRange().text = variable; | |
| 7546 | - } else { | |
| 7547 | - obj = contentBox[0]; | |
| 7548 | - var e = obj.selectionEnd; | |
| 7549 | - | |
| 7550 | - variable = maybeFormatInsertedContent( contentBox, variable, obj.selectionStart, e ); | |
| 7551 | - | |
| 7552 | - obj.value = obj.value.substr( 0, obj.selectionStart ) + variable + obj.value.substr( obj.selectionEnd, obj.value.length ); | |
| 7553 | - var s = e + variable.length; | |
| 7554 | - obj.focus(); | |
| 7555 | - obj.setSelectionRange( s, s ); | |
| 7556 | - } | |
| 7557 | - triggerChange( contentBox ); | |
| 7558 | - } | |
| 7559 | - | |
| 7560 | - function maybeFormatInsertedContent( input, textToInsert, selectionStart, selectionEnd ) { | |
| 7561 | - var separator = input.data( 'sep' ); | |
| 7562 | - if ( undefined === separator ) { | |
| 7563 | - return textToInsert; | |
| 7564 | - } | |
| 7565 | - | |
| 7566 | - var value = input.val(); | |
| 7567 | - | |
| 7568 | - if ( ! value.trim().length ) { | |
| 7569 | - return textToInsert; | |
| 7570 | - } | |
| 7571 | - | |
| 7572 | - var startPattern = new RegExp( separator + '\\s*$' ); | |
| 7573 | - var endPattern = new RegExp( '^\\s*' + separator ); | |
| 7574 | - | |
| 7575 | - if ( value.substr( 0, selectionStart ).trim().length && false === startPattern.test( value.substr( 0, selectionStart ) ) ) { | |
| 7576 | - textToInsert = separator + textToInsert; | |
| 7577 | - } | |
| 7578 | - | |
| 7579 | - if ( value.substr( selectionEnd, value.length ).trim().length && false === endPattern.test( value.substr( selectionEnd, value.length ) ) ) { | |
| 7580 | - textToInsert += separator; | |
| 7581 | - } | |
| 7582 | - | |
| 7583 | - return textToInsert; | |
| 7584 | - } | |
| 7585 | - | |
| 7586 | - function resetLogicBuilder() { | |
| 7587 | - /*jshint validthis:true */ | |
| 7588 | - var id = document.getElementById( 'frm-id-condition' ), | |
| 7589 | - key = document.getElementById( 'frm-key-condition' ); | |
| 7590 | - | |
| 7591 | - if ( this.checked ) { | |
| 7592 | - id.classList.remove( 'frm_hidden' ); | |
| 7593 | - key.classList.add( 'frm_hidden' ); | |
| 7594 | - triggerEvent( key, 'change' ); | |
| 7595 | - } else { | |
| 7596 | - id.classList.add( 'frm_hidden' ); | |
| 7597 | - key.classList.remove( 'frm_hidden' ); | |
| 7598 | - triggerEvent( id, 'change' ); | |
| 7599 | - } | |
| 7600 | - } | |
| 7601 | - | |
| 7602 | - function setLogicExample() { | |
| 7603 | - var field, code, | |
| 7604 | - idKey = document.getElementById( 'frm-id-key-condition' ).checked ? 'frm-id-condition' : 'frm-key-condition', | |
| 7605 | - is = document.getElementById( 'frm-is-condition' ).value, | |
| 7606 | - text = document.getElementById( 'frm-text-condition' ).value, | |
| 7607 | - result = document.getElementById( 'frm-insert-condition' ); | |
| 7608 | - | |
| 7609 | - idKey = document.getElementById( idKey ); | |
| 7610 | - field = idKey.options[idKey.selectedIndex].value; | |
| 7611 | - code = 'if ' + field + ' ' + is + '="' + text + '"]'; | |
| 7612 | - result.setAttribute( 'data-code', code + frm_admin_js.conditional_text + '[/if ' + field ); // eslint-disable-line camelcase | |
| 7613 | - result.innerHTML = '[' + code + '[/if ' + field + ']'; | |
| 7614 | - } | |
| 7615 | - | |
| 7616 | - function showBuilderModal() { | |
| 7617 | - /*jshint validthis:true */ | |
| 7618 | - var moreIcon = getIconForInput( this ); | |
| 7619 | - showInlineModal( moreIcon, this ); | |
| 7620 | - } | |
| 7621 | - | |
| 7622 | - function maybeShowModal( input ) { | |
| 7623 | - var moreIcon; | |
| 7624 | - if ( input.parentNode.parentNode.classList.contains( 'frm_has_shortcodes' ) ) { | |
| 7625 | - hideShortcodes(); | |
| 7626 | - moreIcon = getIconForInput( input ); | |
| 7627 | - if ( moreIcon.tagName === 'use' ) { | |
| 7628 | - moreIcon = moreIcon.firstElementChild; | |
| 7629 | - if ( moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ).indexOf( 'frm_close_icon' ) === -1 ) { | |
| 7630 | - showShortcodeBox( moreIcon, 'nofocus' ); | |
| 7631 | - } | |
| 7632 | - } else if ( ! moreIcon.classList.contains( 'frm_close_icon' ) ) { | |
| 7633 | - showShortcodeBox( moreIcon, 'nofocus' ); | |
| 7634 | - } | |
| 7635 | - } | |
| 7636 | - } | |
| 7637 | - | |
| 7638 | - function showShortcodes( e ) { | |
| 7639 | - /*jshint validthis:true */ | |
| 7640 | - e.preventDefault(); | |
| 7641 | - e.stopPropagation(); | |
| 7642 | - | |
| 7643 | - showShortcodeBox( this ); | |
| 7644 | - } | |
| 7645 | - | |
| 7646 | - function showShortcodeBox( moreIcon, shouldFocus ) { | |
| 7647 | - var pos = moreIcon.getBoundingClientRect(), | |
| 7648 | - input = getInputForIcon( moreIcon ), | |
| 7649 | - box = document.getElementById( 'frm_adv_info' ), | |
| 7650 | - classes = moreIcon.className, | |
| 7651 | - parentPos = box.parentElement.getBoundingClientRect(); | |
| 7652 | - | |
| 7653 | - if ( moreIcon.tagName === 'svg' ) { | |
| 7654 | - moreIcon = moreIcon.firstElementChild; | |
| 7655 | - } | |
| 7656 | - if ( moreIcon.tagName === 'use' ) { | |
| 7657 | - classes = moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ); | |
| 7658 | - } | |
| 7659 | - | |
| 7660 | - if ( classes.indexOf( 'frm_close_icon' ) !== -1 ) { | |
| 7661 | - hideShortcodes( box ); | |
| 7662 | - } else { | |
| 7663 | - box.style.top = ( pos.top - parentPos.top + 32 ) + 'px'; | |
| 7664 | - box.style.left = ( pos.left - parentPos.left - 280 ) + 'px'; | |
| 7665 | - | |
| 7666 | - jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ); | |
| 7667 | - if ( input.classList.contains( 'frm_not_email_to' ) ) { | |
| 7668 | - jQuery( '#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a' ).addClass( 'frm_noallow' ); | |
| 7669 | - } else if ( input.classList.contains( 'frm_not_email_subject' ) ) { | |
| 7670 | - jQuery( '.frm_code_list li.hide_frm_not_email_subject a' ).addClass( 'frm_noallow' ); | |
| 7671 | - } | |
| 7672 | - | |
| 7673 | - box.setAttribute( 'data-fills', input.id ); | |
| 7674 | - box.style.display = 'block'; | |
| 7675 | - | |
| 7676 | - if ( moreIcon.tagName === 'use' ) { | |
| 7677 | - moreIcon.setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_close_icon' ); | |
| 7678 | - } else { | |
| 7679 | - moreIcon.className = classes.replace( 'frm_more_horiz_solid_icon', 'frm_close_icon' ); | |
| 7680 | - } | |
| 7681 | - | |
| 7682 | - if ( shouldFocus !== 'nofocus' ) { | |
| 7683 | - if ( 'none' !== input.style.display ) { | |
| 7684 | - input.focus(); | |
| 7685 | - } else { | |
| 7686 | - jQuery( tinymce.get( input.id ) ).trigger( 'focus' ); | |
| 7687 | - } | |
| 7688 | - } | |
| 7689 | - } | |
| 7690 | - } | |
| 7691 | - | |
| 7692 | - function fieldUpdated() { | |
| 7693 | - if ( ! fieldsUpdated ) { | |
| 7694 | - fieldsUpdated = 1; | |
| 7695 | - window.addEventListener( 'beforeunload', confirmExit ); | |
| 7696 | - } | |
| 7697 | - } | |
| 7698 | - | |
| 7699 | - function buildSubmittedNoAjax() { | |
| 7700 | - // set fieldsUpdated to 0 to avoid the unsaved changes pop up | |
| 7701 | - fieldsUpdated = 0; | |
| 7702 | - } | |
| 7703 | - | |
| 7704 | - function settingsSubmitted() { | |
| 7705 | - // set fieldsUpdated to 0 to avoid the unsaved changes pop up | |
| 7706 | - fieldsUpdated = 0; | |
| 7707 | - } | |
| 7708 | - | |
| 7709 | - function saveAndReloadSettings() { | |
| 7710 | - var page, form; | |
| 7711 | - page = document.getElementById( 'form_settings_page' ); | |
| 7712 | - if ( null !== page ) { | |
| 7713 | - form = page.querySelector( 'form.frm_form_settings' ); | |
| 7714 | - if ( null !== form ) { | |
| 7715 | - fieldsUpdated = 0; | |
| 7716 | - form.submit(); | |
| 7717 | - } | |
| 7718 | - } | |
| 7719 | - } | |
| 7720 | - | |
| 7721 | - function reloadIfAddonActivatedAjaxSubmitOnly() { | |
| 7722 | - const submitButton = document.getElementById( 'frm_submit_side_top' ); | |
| 7723 | - if ( submitButton.hasAttribute( 'data-new-addon-installed' ) && 'true' === submitButton.getAttribute( 'data-new-addon-installed' ) ) { | |
| 7724 | - submitButton.removeAttribute( 'data-new-addon-installed' ); | |
| 7725 | - window.location.reload(); | |
| 7726 | - } | |
| 7727 | - | |
| 7728 | - } | |
| 7729 | - | |
| 7730 | - function saveAndReloadFormBuilder() { | |
| 7731 | - const submitButton = document.getElementById( 'frm_submit_side_top' ); | |
| 7732 | - if ( submitButton.classList.contains( 'frm_submit_ajax' ) ) { | |
| 7733 | - submitButton.setAttribute( 'data-new-addon-installed', true ); | |
| 7734 | - } | |
| 7735 | - submitButton.click(); | |
| 7736 | - } | |
| 7737 | - | |
| 7738 | - function confirmExit( event ) { | |
| 7739 | - if ( fieldsUpdated ) { | |
| 7740 | - event.preventDefault(); | |
| 7741 | - event.returnValue = ''; | |
| 7742 | - } | |
| 7743 | - } | |
| 7744 | - | |
| 7745 | - function bindClickForDialogClose( $modal ) { | |
| 7746 | - const closeModal = function() { | |
| 7747 | - $modal.dialog( 'close' ); | |
| 7748 | - }; | |
| 7749 | - jQuery( '.ui-widget-overlay' ).on( 'click', closeModal ); | |
| 7750 | - $modal.on( 'click', 'a.dismiss', closeModal ); | |
| 7751 | - } | |
| 7752 | - | |
| 7753 | - function triggerNewFormModal( event ) { | |
| 7754 | - var $modal, | |
| 7755 | - dismiss = document.getElementById( 'frm_new_form_modal' ).querySelector( 'a.dismiss' ); | |
| 7756 | - | |
| 7757 | - if ( typeof event !== 'undefined' ) { | |
| 7758 | - event.preventDefault(); | |
| 7759 | - } | |
| 7760 | - | |
| 7761 | - dismiss.setAttribute( 'tabindex', -1 ); | |
| 7762 | - | |
| 7763 | - $modal = initModal( '#frm_new_form_modal', '600px' ); | |
| 7764 | - offsetModalY( $modal, '50px' ); | |
| 7765 | - $modal.attr( 'frm-page', 'create' ); | |
| 7766 | - $modal.find( '#template-search-input' ).val( '' ).trigger( 'change' ); | |
| 7767 | - $modal.dialog( 'open' ); | |
| 7768 | - | |
| 7769 | - dismiss.removeAttribute( 'tabindex' ); | |
| 7770 | - bindClickForDialogClose( $modal ); | |
| 7771 | - | |
| 7772 | - addApplicationsToNewFormModal( $modal.get( 0 ) ); | |
| 7773 | - } | |
| 7774 | - | |
| 7775 | - function addApplicationsToNewFormModal( modal ) { | |
| 7776 | - if ( modal.querySelector( '.frm-ready-made-solution' ) ) { | |
| 7777 | - // Avoid adding duplicates if the modal is opened multiple times. | |
| 7778 | - return; | |
| 7779 | - } | |
| 7780 | - | |
| 7781 | - if ( ! frmGlobal.canAccessApplicationDashboard ) { | |
| 7782 | - // User does not have privileges to see Ready Made Solutions. | |
| 7783 | - return; | |
| 7784 | - } | |
| 7785 | - | |
| 7786 | - doJsonFetch( 'get_applications_data&view=templates' ).then( addTemplatesOnFetchSuccess ); | |
| 7787 | - | |
| 7788 | - const categoryList = modal.querySelector( 'ul.frm-categories-list' ); | |
| 7789 | - | |
| 7790 | - function addTemplatesOnFetchSuccess( data ) { | |
| 7791 | - data.templates.forEach( addTemplateToCategoryList ); | |
| 7792 | - initSearch( 'template-search-input', 'frm-searchable-template frm-ready-made-solution' ); | |
| 7793 | - } | |
| 7794 | - | |
| 7795 | - function addTemplateToCategoryList( template ) { | |
| 7796 | - categoryList.appendChild( getReadyMadeSolution( template ) ); | |
| 7797 | - } | |
| 7798 | - | |
| 7799 | - function getReadyMadeSolution( template ) { | |
| 7800 | - const image = tag( 'img' ); | |
| 7801 | - const thumbnailFolderUrl = frmGlobal.url + '/images/applications/thumbnails/'; | |
| 7802 | - const filenameToUse = template.hasLiteThumbnail ? template.key + '.png' : 'placeholder.svg'; | |
| 7803 | - image.setAttribute( 'src', thumbnailFolderUrl + filenameToUse ); | |
| 7804 | - | |
| 7805 | - const imageWrapper = div({ child: image }); | |
| 7806 | - const href = frmGlobal.applicationsUrl + '&triggerViewApplicationModal=1&template=' + template.key; | |
| 7807 | - | |
| 7808 | - return tag( | |
| 7809 | - 'li', | |
| 7810 | - { | |
| 7811 | - className: 'frm-searchable-template frm-ready-made-solution frm-selectable', | |
| 7812 | - data: { | |
| 7813 | - href: href | |
| 7814 | - }, | |
| 7815 | - children: [ | |
| 7816 | - imageWrapper, | |
| 7817 | - div({ | |
| 7818 | - className: 'frm-solution-details', | |
| 7819 | - children: [ | |
| 7820 | - span({ | |
| 7821 | - className: 'frm-meta-tag', | |
| 7822 | - text: __( 'Ready Made Solution', 'formidable' ) | |
| 7823 | - }), | |
| 7824 | - tag( 'h3', template.name ), | |
| 7825 | - a({ | |
| 7826 | - text: __( 'See all applications', 'formidable' ), | |
| 7827 | - href: frmGlobal.applicationsUrl | |
| 7828 | - }) | |
| 7829 | - ] | |
| 7830 | - }), | |
| 7831 | - div({ | |
| 7832 | - className: 'frm-hover-icons', | |
| 7833 | - child: a({ | |
| 7834 | - child: svg({ href: '#frm_plus_icon' }), | |
| 7835 | - href: href | |
| 7836 | - }) | |
| 7837 | - }) | |
| 7838 | - ] | |
| 7839 | - } | |
| 7840 | - ); | |
| 7841 | - } | |
| 7842 | - } | |
| 7843 | - | |
| 7844 | - function offsetModalY( $modal, amount ) { | |
| 7845 | - const position = { | |
| 7846 | - my: 'top', | |
| 7847 | - at: 'top+' + amount, | |
| 7848 | - of: window | |
| 7849 | - }; | |
| 7850 | - $modal.dialog( 'option', 'position', position ); | |
| 7851 | - } | |
| 7852 | - | |
| 7853 | - /** | |
| 7854 | - * Get the input box for the selected ... icon. | |
| 7855 | - */ | |
| 7856 | - function getInputForIcon( moreIcon ) { | |
| 7857 | - var input = moreIcon.nextElementSibling; | |
| 7858 | - | |
| 7859 | - while ( input !== null && input.tagName !== 'INPUT' && input.tagName !== 'TEXTAREA' ) { | |
| 7860 | - input = getInputForIcon( input ); | |
| 7861 | - } | |
| 7862 | - | |
| 7863 | - return input; | |
| 7864 | - } | |
| 7865 | - | |
| 7866 | - /** | |
| 7867 | - * Get the ... icon for the selected input box. | |
| 7868 | - */ | |
| 7869 | - function getIconForInput( input ) { | |
| 7870 | - var moreIcon = input.previousElementSibling; | |
| 7871 | - | |
| 7872 | - while ( moreIcon !== null && moreIcon.tagName !== 'I' && moreIcon.tagName !== 'svg' ) { | |
| 7873 | - moreIcon = getIconForInput( moreIcon ); | |
| 7874 | - } | |
| 7875 | - | |
| 7876 | - return moreIcon; | |
| 7877 | - } | |
| 7878 | - | |
| 7879 | - function hideShortcodes( box ) { | |
| 7880 | - var i, u, closeIcons, closeSvg; | |
| 7881 | - if ( typeof box === 'undefined' ) { | |
| 7882 | - box = document.getElementById( 'frm_adv_info' ); | |
| 7883 | - if ( box === null ) { | |
| 7884 | - return; | |
| 7885 | - } | |
| 7886 | - } | |
| 7887 | - | |
| 7888 | - if ( document.getElementById( 'frm_dyncontent' ) !== null ) { | |
| 7889 | - // Don't run when in the sidebar. | |
| 7890 | - return; | |
| 7891 | - } | |
| 7892 | - | |
| 7893 | - box.style.display = 'none'; | |
| 7894 | - | |
| 7895 | - closeIcons = document.querySelectorAll( '.frm-show-box.frm_close_icon' ); | |
| 7896 | - for ( i = 0; i < closeIcons.length; i++ ) { | |
| 7897 | - closeIcons[i].classList.remove( 'frm_close_icon' ); | |
| 7898 | - closeIcons[i].classList.add( 'frm_more_horiz_solid_icon' ); | |
| 7899 | - } | |
| 7900 | - | |
| 7901 | - closeSvg = document.querySelectorAll( '.frm_has_shortcodes use' ); | |
| 7902 | - for ( u = 0; u < closeSvg.length; u++ ) { | |
| 7903 | - if ( closeSvg[u].getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) === '#frm_close_icon' ) { | |
| 7904 | - closeSvg[u].setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_more_horiz_solid_icon' ); | |
| 7905 | - } | |
| 7906 | - } | |
| 7907 | - } | |
| 7908 | - | |
| 7909 | - function initToggleShortcodes() { | |
| 7910 | - if ( typeof tinymce !== 'object' ) { | |
| 7911 | - return; | |
| 7912 | - } | |
| 7913 | - | |
| 7914 | - DOM = tinymce.DOM; | |
| 7915 | - if ( typeof DOM.events !== 'undefined' && typeof DOM.events.add !== 'undefined' ) { | |
| 7916 | - DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseover', function() { | |
| 7917 | - if ( jQuery( '*:focus' ).length > 0 ) { | |
| 7918 | - return; | |
| 7919 | - } | |
| 7920 | - if ( this.id ) { | |
| 7921 | - toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 7922 | - } | |
| 7923 | - }); | |
| 7924 | - DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseout', function() { | |
| 7925 | - if ( jQuery( '*:focus' ).length > 0 ) { | |
| 7926 | - return; | |
| 7927 | - } | |
| 7928 | - if ( this.id ) { | |
| 7929 | - toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 7930 | - } | |
| 7931 | - }); | |
| 7932 | - } else { | |
| 7933 | - jQuery( '#frm_dyncontent' ).on( 'mouseover mouseout', '.wp-editor-wrap', function() { | |
| 7934 | - if ( jQuery( '*:focus' ).length > 0 ) { | |
| 7935 | - return; | |
| 7936 | - } | |
| 7937 | - if ( this.id ) { | |
| 7938 | - toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 7939 | - } | |
| 7940 | - }); | |
| 7941 | - } | |
| 7942 | - } | |
| 7943 | - | |
| 7944 | - function toggleAllowedShortcodes( id ) { | |
| 7945 | - var c, clickedID; | |
| 7946 | - if ( typeof id === 'undefined' ) { | |
| 7947 | - id = ''; | |
| 7948 | - } | |
| 7949 | - c = id; | |
| 7950 | - | |
| 7951 | - if ( id.indexOf( '-search-input' ) !== -1 ) { | |
| 7952 | - return; | |
| 7953 | - } | |
| 7954 | - | |
| 7955 | - if ( id !== '' ) { | |
| 7956 | - var $ele = jQuery( document.getElementById( id ) ); | |
| 7957 | - if ( $ele.attr( 'class' ) && id !== 'wpbody-content' && id !== 'content' && id !== 'dyncontent' && id !== 'success_msg' ) { | |
| 7958 | - var d = $ele.attr( 'class' ).split( ' ' )[0]; | |
| 7959 | - if ( d === 'frm_long_input' || d === 'frm_98_width' || typeof d === 'undefined' ) { | |
| 7960 | - d = ''; | |
| 7961 | - } else { | |
| 7962 | - id = d.trim(); | |
| 7963 | - } | |
| 7964 | - c = c + ' ' + d; | |
| 7965 | - c = c.replace( 'widefat', '' ).replace( 'frm_with_left_label', '' ); | |
| 7966 | - } | |
| 7967 | - } | |
| 7968 | - | |
| 7969 | - jQuery( '#frm-insert-fields-box,#frm-conditionals,#frm-adv-info-tab,#frm-dynamic-values' ).attr( 'data-fills', c.trim() ); | |
| 7970 | - var a = [ | |
| 7971 | - 'content', 'wpbody-content', 'dyncontent', 'success_url', | |
| 7972 | - 'success_msg', 'edit_msg', 'frm_dyncontent', 'frm_not_email_message', | |
| 7973 | - 'frm_not_email_subject' | |
| 7974 | - ]; | |
| 7975 | - var b = [ | |
| 7976 | - 'before_content', 'after_content', 'frm_not_email_to', | |
| 7977 | - 'dyn_default_value' | |
| 7978 | - ]; | |
| 7979 | - | |
| 7980 | - if ( jQuery.inArray( id, a ) >= 0 ) { | |
| 7981 | - jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' ); | |
| 7982 | - jQuery( '.frm_code_list a.hide_' + id ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 7983 | - } else if ( jQuery.inArray( id, b ) >= 0 ) { | |
| 7984 | - jQuery( '.frm_code_list:not(.frm-dropdown-menu) a:not(.show_' + id + ')' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 7985 | - jQuery( '.frm_code_list a.show_' + id ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' ); | |
| 7986 | - } else { | |
| 7987 | - jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 7988 | - } | |
| 7989 | - | |
| 7990 | - // Automatically select a tab. | |
| 7991 | - if ( id === 'dyn_default_value' ) { | |
| 7992 | - clickedID = 'frm_dynamic_values'; | |
| 7993 | - document.getElementById( clickedID + '_tab' ).click(); | |
| 7994 | - jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_inactive' ).addClass( 'frm_hidden' ); | |
| 7995 | - jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_active' ).removeClass( 'frm_hidden' ); | |
| 7996 | - } | |
| 7997 | - } | |
| 7998 | - | |
| 7999 | - function toggleAllowedHTML( input ) { | |
| 8000 | - var b, | |
| 8001 | - id = input.id; | |
| 8002 | - if ( typeof id === 'undefined' || id.indexOf( '-search-input' ) !== -1 ) { | |
| 8003 | - return; | |
| 8004 | - } | |
| 8005 | - | |
| 8006 | - jQuery( '#frm-adv-info-tab' ).attr( 'data-fills', id.trim() ); | |
| 8007 | - if ( input.classList.contains( 'field_custom_html' ) ) { | |
| 8008 | - id = 'field_custom_html'; | |
| 8009 | - } | |
| 8010 | - | |
| 8011 | - b = [ 'after_html', 'before_html', 'submit_html', 'field_custom_html' ]; | |
| 8012 | - if ( jQuery.inArray( id, b ) >= 0 ) { | |
| 8013 | - jQuery( '.frm_code_list li:not(.show_' + id + ')' ).addClass( 'frm_hidden' ); | |
| 8014 | - jQuery( '.frm_code_list li.show_' + id ).removeClass( 'frm_hidden' ); | |
| 8015 | - } | |
| 8016 | - } | |
| 8017 | - | |
| 8018 | - function toggleKeyID( switchTo, e ) { | |
| 8019 | - e.stopPropagation(); | |
| 8020 | - jQuery( '.frm_code_list .frmids, .frm_code_list .frmkeys' ).addClass( 'frm_hidden' ); | |
| 8021 | - jQuery( '.frm_code_list .' + switchTo ).removeClass( 'frm_hidden' ); | |
| 8022 | - jQuery( '.frmids, .frmkeys' ).removeClass( 'current' ); | |
| 8023 | - jQuery( '.' + switchTo ).addClass( 'current' ); | |
| 8024 | - } | |
| 8025 | - | |
| 8026 | - function onActionLoaded( event ) { | |
| 8027 | - const settings = event.target.closest( '.frm_form_action_settings' ); | |
| 8028 | - if ( settings && ( settings.classList.contains( 'frm_single_email_settings' ) || settings.classList.contains( 'frm_single_on_submit_settings' ) ) ) { | |
| 8029 | - initWysiwygOnActionLoaded( settings ); | |
| 8030 | - } | |
| 8031 | - } | |
| 8032 | - | |
| 8033 | - function initWysiwygOnActionLoaded( settings ) { | |
| 8034 | - const wysiwyg = settings.querySelector( '.wp-editor-area' ); | |
| 8035 | - if ( wysiwyg ) { | |
| 8036 | - frmDom.wysiwyg.init( | |
| 8037 | - wysiwyg, | |
| 8038 | - { height: 160, addFocusEvents: true } | |
| 8039 | - ); | |
| 8040 | - } | |
| 8041 | - } | |
| 8042 | - | |
| 8043 | - /* Global settings page */ | |
| 8044 | - function loadSettingsTab( anchor ) { | |
| 8045 | - var holder = anchor.replace( '#', '' ); | |
| 8046 | - var holderContainer = jQuery( '.frm_' + holder + '_ajax' ); | |
| 8047 | - if ( holderContainer.length ) { | |
| 8048 | - jQuery.ajax({ | |
| 8049 | - type: 'POST', url: ajaxurl, | |
| 8050 | - data: { | |
| 8051 | - 'action': 'frm_settings_tab', | |
| 8052 | - 'tab': holder.replace( '_settings', '' ), | |
| 8053 | - 'nonce': frmGlobal.nonce | |
| 8054 | - }, | |
| 8055 | - success: function( html ) { | |
| 8056 | - holderContainer.replaceWith( html ); | |
| 8057 | - } | |
| 8058 | - }); | |
| 8059 | - } | |
| 8060 | - } | |
| 8061 | - | |
| 8062 | - function uninstallNow() { | |
| 8063 | - /*jshint validthis:true */ | |
| 8064 | - if ( confirmLinkClick( this ) === true ) { | |
| 8065 | - jQuery( '.frm_uninstall .frm-wait' ).css( 'visibility', 'visible' ); | |
| 8066 | - jQuery.ajax({ | |
| 8067 | - type: 'POST', | |
| 8068 | - url: ajaxurl, | |
| 8069 | - data: 'action=frm_uninstall&nonce=' + frmGlobal.nonce, | |
| 8070 | - success: function( msg ) { | |
| 8071 | - jQuery( '.frm_uninstall' ).fadeOut( 'slow' ); | |
| 8072 | - window.location = msg; | |
| 8073 | - } | |
| 8074 | - }); | |
| 8075 | - } | |
| 8076 | - return false; | |
| 8077 | - } | |
| 8078 | - | |
| 8079 | - function saveAddonLicense() { | |
| 8080 | - /*jshint validthis:true */ | |
| 8081 | - var button = jQuery( this ); | |
| 8082 | - var buttonName = this.name; | |
| 8083 | - var pluginSlug = this.getAttribute( 'data-plugin' ); | |
| 8084 | - var action = buttonName.replace( 'edd_' + pluginSlug + '_license_', '' ); | |
| 8085 | - var license = document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value; | |
| 8086 | - jQuery.ajax({ | |
| 8087 | - type: 'POST', url: ajaxurl, dataType: 'json', | |
| 8088 | - data: {action: 'frm_addon_' + action, license: license, plugin: pluginSlug, nonce: frmGlobal.nonce}, | |
| 8089 | - success: function( msg ) { | |
| 8090 | - var thisRow = button.closest( '.edd_frm_license_row' ); | |
| 8091 | - if ( action === 'deactivate' ) { | |
| 8092 | - license = ''; | |
| 8093 | - document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value = ''; | |
| 8094 | - } | |
| 8095 | - thisRow.find( '.edd_frm_license' ).html( license ); | |
| 8096 | - if ( msg.success === true ) { | |
| 8097 | - thisRow.find( '.frm_icon_font' ).removeClass( 'frm_hidden' ); | |
| 8098 | - thisRow.find( 'div.alignleft' ).toggleClass( 'frm_hidden', 1000 ); | |
| 8099 | - } | |
| 8100 | - | |
| 8101 | - var messageBox = thisRow.find( '.frm_license_msg' ); | |
| 8102 | - messageBox.html( msg.message ); | |
| 8103 | - if ( msg.message !== '' ) { | |
| 8104 | - setTimeout( function() { | |
| 8105 | - messageBox.html( '' ); | |
| 8106 | - }, 15000 ); | |
| 8107 | - } | |
| 8108 | - } | |
| 8109 | - }); | |
| 8110 | - } | |
| 8111 | - | |
| 8112 | - /* Import/Export page */ | |
| 8113 | - | |
| 8114 | - function startFormMigration( event ) { | |
| 8115 | - event.preventDefault(); | |
| 8116 | - | |
| 8117 | - var checkedBoxes = jQuery( event.target ).find( 'input:checked' ); | |
| 8118 | - if ( ! checkedBoxes.length ) { | |
| 8119 | - return; | |
| 8120 | - } | |
| 8121 | - | |
| 8122 | - var ids = []; | |
| 8123 | - checkedBoxes.each( function( i ) { | |
| 8124 | - ids[i] = this.value; | |
| 8125 | - }); | |
| 8126 | - | |
| 8127 | - // Begin the import process. | |
| 8128 | - importForms( ids, event.target ); | |
| 8129 | - } | |
| 8130 | - | |
| 8131 | - /** | |
| 8132 | - * Begins the process of importing the forms. | |
| 8133 | - */ | |
| 8134 | - function importForms( forms, targetForm ) { | |
| 8135 | - | |
| 8136 | - // Hide the form select section. | |
| 8137 | - var $form = jQuery( targetForm ), | |
| 8138 | - $processSettings = $form.next( '.frm-importer-process' ); | |
| 8139 | - | |
| 8140 | - // Display total number of forms we have to import. | |
| 8141 | - $processSettings.find( '.form-total' ).text( forms.length ); | |
| 8142 | - $processSettings.find( '.form-current' ).text( '1' ); | |
| 8143 | - | |
| 8144 | - $form.hide(); | |
| 8145 | - | |
| 8146 | - // Show processing status. | |
| 8147 | - // '.process-completed' might have been shown earlier during a previous import, so hide now. | |
| 8148 | - $processSettings.find( '.process-completed' ).hide(); | |
| 8149 | - $processSettings.show(); | |
| 8150 | - | |
| 8151 | - // Create global import queue. | |
| 8152 | - s.importQueue = forms; | |
| 8153 | - s.imported = 0; | |
| 8154 | - | |
| 8155 | - // Import the first form in the queue. | |
| 8156 | - importForm( $processSettings ); | |
| 8157 | - } | |
| 8158 | - | |
| 8159 | - /** | |
| 8160 | - * Imports a single form from the import queue. | |
| 8161 | - */ | |
| 8162 | - function importForm( $processSettings ) { | |
| 8163 | - var formID = s.importQueue[0], | |
| 8164 | - provider = jQuery( '#welcome-panel' ).find( 'input[name="slug"]' ).val(), | |
| 8165 | - data = { | |
| 8166 | - action: 'frm_import_' + provider, | |
| 8167 | - form_id: formID, | |
| 8168 | - nonce: frmGlobal.nonce | |
| 8169 | - }; | |
| 8170 | - | |
| 8171 | - // Trigger AJAX import for this form. | |
| 8172 | - jQuery.post( ajaxurl, data, function( res ) { | |
| 8173 | - | |
| 8174 | - if ( res.success ) { | |
| 8175 | - var statusUpdate; | |
| 8176 | - | |
| 8177 | - if ( res.data.error ) { | |
| 8178 | - statusUpdate = '<p>' + res.data.name + ': ' + res.data.msg + '</p>'; | |
| 8179 | - } else { | |
| 8180 | - statusUpdate = '<p>Imported <a href="' + res.data.link + '" target="_blank">' + res.data.name + '</a></p>'; | |
| 8181 | - } | |
| 8182 | - | |
| 8183 | - $processSettings.find( '.status' ).prepend( statusUpdate ); | |
| 8184 | - $processSettings.find( '.status' ).show(); | |
| 8185 | - | |
| 8186 | - // Remove this form ID from the queue. | |
| 8187 | - s.importQueue = jQuery.grep( s.importQueue, function( value ) { | |
| 8188 | - return value != formID; | |
| 8189 | - }); | |
| 8190 | - s.imported++; | |
| 8191 | - | |
| 8192 | - if ( s.importQueue.length === 0 ) { | |
| 8193 | - $processSettings.find( '.process-count' ).hide(); | |
| 8194 | - $processSettings.find( '.forms-completed' ).text( s.imported ); | |
| 8195 | - $processSettings.find( '.process-completed' ).show(); | |
| 8196 | - } else { | |
| 8197 | - // Import next form in the queue. | |
| 8198 | - $processSettings.find( '.form-current' ).text( s.imported + 1 ); | |
| 8199 | - importForm( $processSettings ); | |
| 8200 | - } | |
| 8201 | - } | |
| 8202 | - }); | |
| 8203 | - } | |
| 8204 | - | |
| 8205 | - function validateExport( e ) { | |
| 8206 | - /*jshint validthis:true */ | |
| 8207 | - e.preventDefault(); | |
| 8208 | - | |
| 8209 | - var s = false; | |
| 8210 | - var $exportForms = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 8211 | - | |
| 8212 | - if ( ! jQuery( 'input[name="frm_export_forms[]"]:checked' ).val() ) { | |
| 8213 | - $exportForms.closest( '.frm-table-box' ).addClass( 'frm_blank_field' ); | |
| 8214 | - s = 'stop'; | |
| 8215 | - } | |
| 8216 | - | |
| 8217 | - var $exportType = jQuery( 'input[name="type[]"]' ); | |
| 8218 | - if ( ! jQuery( 'input[name="type[]"]:checked' ).val() && $exportType.attr( 'type' ) === 'checkbox' ) { | |
| 8219 | - $exportType.closest( 'p' ).addClass( 'frm_blank_field' ); | |
| 8220 | - s = 'stop'; | |
| 8221 | - } | |
| 8222 | - | |
| 8223 | - if ( s === 'stop' ) { | |
| 8224 | - return false; | |
| 8225 | - } | |
| 8226 | - | |
| 8227 | - e.stopPropagation(); | |
| 8228 | - this.submit(); | |
| 8229 | - } | |
| 8230 | - | |
| 8231 | - function removeExportError() { | |
| 8232 | - /*jshint validthis:true */ | |
| 8233 | - var t = jQuery( this ).closest( '.frm_blank_field' ); | |
| 8234 | - if ( typeof t === 'undefined' ) { | |
| 8235 | - return; | |
| 8236 | - } | |
| 8237 | - | |
| 8238 | - var $thisName = this.name; | |
| 8239 | - if ( $thisName === 'type[]' && jQuery( 'input[name="type[]"]:checked' ).val() ) { | |
| 8240 | - t.removeClass( 'frm_blank_field' ); | |
| 8241 | - } else if ( $thisName === 'frm_export_forms[]' && jQuery( this ).val() ) { | |
| 8242 | - t.removeClass( 'frm_blank_field' ); | |
| 8243 | - } | |
| 8244 | - | |
| 8245 | - } | |
| 8246 | - | |
| 8247 | - function checkCSVExtension() { | |
| 8248 | - /*jshint validthis:true */ | |
| 8249 | - var f = jQuery( this ).val(); | |
| 8250 | - var re = /\.csv$/i; | |
| 8251 | - if ( f.match( re ) !== null ) { | |
| 8252 | - jQuery( '.show_csv' ).fadeIn(); | |
| 8253 | - } else { | |
| 8254 | - jQuery( '.show_csv' ).fadeOut(); | |
| 8255 | - } | |
| 8256 | - } | |
| 8257 | - | |
| 8258 | - function getExportOption() { | |
| 8259 | - const exportFormatSelect = document.querySelector( 'select[name="format"]' ); | |
| 8260 | - if ( exportFormatSelect ) { | |
| 8261 | - return exportFormatSelect.value; | |
| 8262 | - } else { | |
| 8263 | - return ''; | |
| 8264 | - } | |
| 8265 | - } | |
| 8266 | - | |
| 8267 | - function exportTypeChanged( event ) { | |
| 8268 | - const value = event.target.value; | |
| 8269 | - showOrHideRepeaters( value ); | |
| 8270 | - checkExportTypes.call( event.target ); | |
| 8271 | - checkSelectedAllFormsCheckbox( value ); | |
| 8272 | - } | |
| 8273 | - | |
| 8274 | - function checkSelectedAllFormsCheckbox( exportType ) { | |
| 8275 | - const selectAllCheckbox = document.getElementById( 'frm-export-select-all' ); | |
| 8276 | - if ( exportType === 'csv' ) { | |
| 8277 | - selectAllCheckbox.checked = false; | |
| 8278 | - selectAllCheckbox.disabled = true; | |
| 8279 | - } else { | |
| 8280 | - selectAllCheckbox.disabled = false; | |
| 8281 | - } | |
| 8282 | - } | |
| 8283 | - | |
| 8284 | - function checkExportTypes() { | |
| 8285 | - /*jshint validthis:true */ | |
| 8286 | - var $dropdown = jQuery( this ); | |
| 8287 | - var $selected = $dropdown.find( ':selected' ); | |
| 8288 | - var s = $selected.data( 'support' ); | |
| 8289 | - | |
| 8290 | - var multiple = s.indexOf( '|' ); | |
| 8291 | - jQuery( 'input[name="type[]"]' ).each( function() { | |
| 8292 | - this.checked = false; | |
| 8293 | - if ( s.indexOf( this.value ) >= 0 ) { | |
| 8294 | - this.disabled = false; | |
| 8295 | - if ( multiple === -1 ) { | |
| 8296 | - this.checked = true; | |
| 8297 | - } | |
| 8298 | - } else { | |
| 8299 | - this.disabled = true; | |
| 8300 | - } | |
| 8301 | - }); | |
| 8302 | - | |
| 8303 | - if ( $dropdown.val() === 'csv' ) { | |
| 8304 | - jQuery( '.csv_opts' ).show(); | |
| 8305 | - jQuery( '.xml_opts' ).hide(); | |
| 8306 | - } else { | |
| 8307 | - jQuery( '.csv_opts' ).hide(); | |
| 8308 | - jQuery( '.xml_opts' ).show(); | |
| 8309 | - } | |
| 8310 | - | |
| 8311 | - var c = $selected.data( 'count' ); | |
| 8312 | - var exportField = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 8313 | - if ( c === 'single' ) { | |
| 8314 | - exportField.prop( 'multiple', false ); | |
| 8315 | - exportField.prop( 'checked', false ); | |
| 8316 | - } else { | |
| 8317 | - exportField.prop( 'multiple', true ); | |
| 8318 | - exportField.prop( 'disabled', false ); | |
| 8319 | - } | |
| 8320 | - $dropdown.trigger( 'change' ); | |
| 8321 | - } | |
| 8322 | - | |
| 8323 | - function showOrHideRepeaters( exportOption ) { | |
| 8324 | - if ( exportOption === '' ) { | |
| 8325 | - return; | |
| 8326 | - } | |
| 8327 | - | |
| 8328 | - const repeaters = document.querySelectorAll( '.frm-is-repeater' ); | |
| 8329 | - if ( ! repeaters.length ) { | |
| 8330 | - return; | |
| 8331 | - } | |
| 8332 | - | |
| 8333 | - if ( exportOption === 'csv' ) { | |
| 8334 | - repeaters.forEach( form => { | |
| 8335 | - form.classList.remove( 'frm_hidden' ); | |
| 8336 | - }); | |
| 8337 | - } else { | |
| 8338 | - repeaters.forEach( form => { | |
| 8339 | - form.classList.add( 'frm_hidden' ); | |
| 8340 | - }); | |
| 8341 | - } | |
| 8342 | - | |
| 8343 | - searchContent.call( document.querySelector( '.frm-auto-search' ) ); | |
| 8344 | - } | |
| 8345 | - | |
| 8346 | - function preventMultipleExport() { | |
| 8347 | - var type = jQuery( 'select[name=format]' ), | |
| 8348 | - selected = type.find( ':selected' ), | |
| 8349 | - count = selected.data( 'count' ), | |
| 8350 | - exportField = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 8351 | - | |
| 8352 | - if ( count === 'single' ) { | |
| 8353 | - // Disable all other fields to prevent multiple selections. | |
| 8354 | - if ( this.checked ) { | |
| 8355 | - exportField.prop( 'disabled', true ); | |
| 8356 | - this.removeAttribute( 'disabled' ); | |
| 8357 | - } else { | |
| 8358 | - exportField.prop( 'disabled', false ); | |
| 8359 | - } | |
| 8360 | - } else { | |
| 8361 | - exportField.prop( 'disabled', false ); | |
| 8362 | - } | |
| 8363 | - } | |
| 8364 | - | |
| 8365 | - function initiateMultiselect() { | |
| 8366 | - jQuery( '.frm_multiselect' ).hide().each( frmDom.bootstrap.multiselect.init ); | |
| 8367 | - } | |
| 8368 | - | |
| 8369 | - /* Addons page */ | |
| 8370 | - function installMultipleAddons( e ) { | |
| 8371 | - e.preventDefault(); | |
| 8372 | - installOrActivate( this, 'frm_multiple_addons' ); | |
| 8373 | - } | |
| 8374 | - | |
| 8375 | - function activateAddon( e ) { | |
| 8376 | - e.preventDefault(); | |
| 8377 | - installOrActivate( this, 'frm_activate_addon' ); | |
| 8378 | - } | |
| 8379 | - | |
| 8380 | - function installAddon( e ) { | |
| 8381 | - e.preventDefault(); | |
| 8382 | - installOrActivate( this, 'frm_install_addon' ); | |
| 8383 | - } | |
| 8384 | - | |
| 8385 | - function installOrActivate( clicked, action ) { | |
| 8386 | - let button, plugin, el, message; | |
| 8387 | - | |
| 8388 | - // Remove any leftover error messages, output an icon and get the plugin basename that needs to be activated. | |
| 8389 | - jQuery( '.frm-addon-error' ).remove(); | |
| 8390 | - button = jQuery( clicked ); | |
| 8391 | - plugin = button.attr( 'rel' ); | |
| 8392 | - el = button.parent(); | |
| 8393 | - message = el.parent().find( '.addon-status-label' ); | |
| 8394 | - | |
| 8395 | - button.addClass( 'frm_loading_button' ); | |
| 8396 | - | |
| 8397 | - // Process the Ajax to perform the activation. | |
| 8398 | - jQuery.ajax({ | |
| 8399 | - url: ajaxurl, | |
| 8400 | - type: 'POST', | |
| 8401 | - async: true, | |
| 8402 | - cache: false, | |
| 8403 | - dataType: 'json', | |
| 8404 | - data: { | |
| 8405 | - action: action, | |
| 8406 | - nonce: frmGlobal.nonce, | |
| 8407 | - plugin: plugin | |
| 8408 | - }, | |
| 8409 | - success: function( response ) { | |
| 8410 | - let saveAndReload; | |
| 8411 | - | |
| 8412 | - if ( 'string' !== typeof response && 'string' === typeof response.message ) { | |
| 8413 | - if ( 'undefined' !== typeof response.saveAndReload ) { | |
| 8414 | - saveAndReload = response.saveAndReload; | |
| 8415 | - } | |
| 8416 | - response = response.message; | |
| 8417 | - } | |
| 8418 | - | |
| 8419 | - const error = extractErrorFromAddOnResponse( response ); | |
| 8420 | - if ( error ) { | |
| 8421 | - addonError( error, el, button ); | |
| 8422 | - return; | |
| 8423 | - } | |
| 8424 | - | |
| 8425 | - afterAddonInstall( response, button, message, el, saveAndReload ); | |
| 8426 | - }, | |
| 8427 | - error: function() { | |
| 8428 | - button.removeClass( 'frm_loading_button' ); | |
| 8429 | - } | |
| 8430 | - }); | |
| 8431 | - } | |
| 8432 | - | |
| 8433 | - function installAddonWithCreds( e ) { | |
| 8434 | - // Prevent the default action, let the user know we are attempting to install again and go with it. | |
| 8435 | - e.preventDefault(); | |
| 8436 | - | |
| 8437 | - // Now let's make another Ajax request once the user has submitted their credentials. | |
| 8438 | - const proceed = jQuery( this ); | |
| 8439 | - const el = proceed.parent().parent(); | |
| 8440 | - const plugin = proceed.attr( 'rel' ); | |
| 8441 | - | |
| 8442 | - proceed.addClass( 'frm_loading_button' ); | |
| 8443 | - | |
| 8444 | - jQuery.ajax({ | |
| 8445 | - url: ajaxurl, | |
| 8446 | - type: 'POST', | |
| 8447 | - async: true, | |
| 8448 | - cache: false, | |
| 8449 | - dataType: 'json', | |
| 8450 | - data: { | |
| 8451 | - action: 'frm_install_addon', | |
| 8452 | - nonce: frm_admin_js.nonce, // eslint-disable-line camelcase | |
| 8453 | - plugin: plugin, | |
| 8454 | - hostname: el.find( '#hostname' ).val(), | |
| 8455 | - username: el.find( '#username' ).val(), | |
| 8456 | - password: el.find( '#password' ).val() | |
| 8457 | - }, | |
| 8458 | - success: function( response ) { | |
| 8459 | - const error = extractErrorFromAddOnResponse( response ); | |
| 8460 | - if ( error ) { | |
| 8461 | - addonError( error, el, proceed ); | |
| 8462 | - return; | |
| 8463 | - } | |
| 8464 | - | |
| 8465 | - afterAddonInstall( response, proceed, message, el ); | |
| 8466 | - }, | |
| 8467 | - error: function() { | |
| 8468 | - proceed.removeClass( 'frm_loading_button' ); | |
| 8469 | - } | |
| 8470 | - }); | |
| 8471 | - } | |
| 8472 | - | |
| 8473 | - function afterAddonInstall( response, button, message, el, saveAndReload ) { | |
| 8474 | - const addonStatuses = document.querySelectorAll( '.frm-addon-status' ); | |
| 8475 | - addonStatuses.forEach( | |
| 8476 | - addonStatus => { | |
| 8477 | - addonStatus.textContent = response; | |
| 8478 | - addonStatus.style.display = 'block'; | |
| 8479 | - } | |
| 8480 | - ); | |
| 8481 | - | |
| 8482 | - // The Ajax request was successful, so let's update the output. | |
| 8483 | - button.css({ opacity: '0' }); | |
| 8484 | - message.text( frm_admin_js.active ); // eslint-disable-line camelcase | |
| 8485 | - | |
| 8486 | - document.querySelectorAll( '.frm-oneclick' ).forEach( | |
| 8487 | - oneClick => { | |
| 8488 | - oneClick.style.display = 'none'; | |
| 8489 | - } | |
| 8490 | - ); | |
| 8491 | - | |
| 8492 | - jQuery( '#frm_upgrade_modal h2' ).hide(); | |
| 8493 | - jQuery( '#frm_upgrade_modal .frm_lock_icon' ).addClass( 'frm_lock_open_icon' ); | |
| 8494 | - jQuery( '#frm_upgrade_modal .frm_lock_icon use' ).attr( 'xlink:href', '#frm_lock_open_icon' ); | |
| 8495 | - | |
| 8496 | - // Proceed with CSS changes | |
| 8497 | - el.parent().removeClass( 'frm-addon-not-installed frm-addon-installed' ).addClass( 'frm-addon-active' ); | |
| 8498 | - button.removeClass( 'frm_loading_button' ); | |
| 8499 | - | |
| 8500 | - // Maybe refresh import and SMTP pages | |
| 8501 | - const refreshPage = document.querySelectorAll( '.frm-admin-page-import, #frm-admin-smtp, #frm-welcome' ); | |
| 8502 | - if ( refreshPage.length > 0 ) { | |
| 8503 | - window.location.reload(); | |
| 8504 | - return; | |
| 8505 | - } | |
| 8506 | - | |
| 8507 | - if ([ 'settings', 'form_builder' ].includes( saveAndReload ) ) { | |
| 8508 | - addonStatuses.forEach( | |
| 8509 | - addonStatus => { | |
| 8510 | - const inModal = null !== addonStatus.closest( '#frm_upgrade_modal' ); | |
| 8511 | - addonStatus.appendChild( getSaveAndReloadSettingsOptions( saveAndReload, inModal ) ); | |
| 8512 | - } | |
| 8513 | - ); | |
| 8514 | - } | |
| 8515 | - } | |
| 8516 | - | |
| 8517 | - function getSaveAndReloadSettingsOptions( saveAndReload, inModal ) { | |
| 8518 | - const className = 'frm-save-and-reload-options'; | |
| 8519 | - const children = [ saveAndReloadSettingsButton( saveAndReload ) ]; | |
| 8520 | - if ( inModal ) { | |
| 8521 | - children.push( closePopupButton() ); | |
| 8522 | - } | |
| 8523 | - return div({ className, children }); | |
| 8524 | - } | |
| 8525 | - | |
| 8526 | - function saveAndReloadSettingsButton( saveAndReload ) { | |
| 8527 | - var button = document.createElement( 'button' ); | |
| 8528 | - button.classList.add( 'frm-save-and-reload', 'button', 'button-primary', 'frm-button-primary' ); | |
| 8529 | - button.textContent = __( 'Save and Reload', 'formidable' ); | |
| 8530 | - button.addEventListener( 'click', () => { | |
| 8531 | - if ( saveAndReload === 'form_builder' ) { | |
| 8532 | - saveAndReloadFormBuilder(); | |
| 8533 | - } else if ( saveAndReload === 'settings' ) { | |
| 8534 | - saveAndReloadSettings(); | |
| 8535 | - } | |
| 8536 | - }); | |
| 8537 | - return button; | |
| 8538 | - } | |
| 8539 | - | |
| 8540 | - function closePopupButton() { | |
| 8541 | - var a = document.createElement( 'a' ); | |
| 8542 | - a.setAttribute( 'href', '#' ); | |
| 8543 | - a.classList.add( 'button', 'button-secondary', 'frm-button-secondary', 'dismiss' ); | |
| 8544 | - a.textContent = __( 'Close', 'formidable' ); | |
| 8545 | - return a; | |
| 8546 | - } | |
| 8547 | - | |
| 8548 | - function extractErrorFromAddOnResponse( response ) { | |
| 8549 | - if ( typeof response !== 'string' ) { | |
| 8550 | - if ( typeof response.success !== 'undefined' && response.success ) { | |
| 8551 | - return false; | |
| 8552 | - } | |
| 8553 | - | |
| 8554 | - if ( response.form ) { | |
| 8555 | - if ( jQuery( response.form ).is( '#message' ) ) { | |
| 8556 | - return { | |
| 8557 | - message: jQuery( response.form ).find( 'p' ).html() | |
| 8558 | - }; | |
| 8559 | - } | |
| 8560 | - } | |
| 8561 | - | |
| 8562 | - return response; | |
| 8563 | - } | |
| 8564 | - | |
| 8565 | - return false; | |
| 8566 | - } | |
| 8567 | - | |
| 8568 | - function addonError( response, el, button ) { | |
| 8569 | - if ( response.form ) { | |
| 8570 | - jQuery( '.frm-inline-error' ).remove(); | |
| 8571 | - button.closest( '.frm-card' ) | |
| 8572 | - .html( response.form ) | |
| 8573 | - .css({ padding: 5 }) | |
| 8574 | - .find( '#upgrade' ) | |
| 8575 | - .attr( 'rel', button.attr( 'rel' ) ) | |
| 8576 | - .on( 'click', installAddonWithCreds ); | |
| 8577 | - } else { | |
| 8578 | - el.append( '<div class="frm-addon-error frm_error_style"><p><strong>' + response.message + '</strong></p></div>' ); | |
| 8579 | - button.removeClass( 'frm_loading_button' ); | |
| 8580 | - jQuery( '.frm-addon-error' ).delay( 4000 ).fadeOut(); | |
| 8581 | - } | |
| 8582 | - } | |
| 8583 | - | |
| 8584 | - /* Templates */ | |
| 8585 | - | |
| 8586 | - function showFreeTemplatesForm() { | |
| 8587 | - loadApiEmailForm(); | |
| 8588 | - } | |
| 8589 | - | |
| 8590 | - function showActiveCampaignForm() { | |
| 8591 | - loadApiEmailForm(); | |
| 8592 | - } | |
| 8593 | - | |
| 8594 | - function loadApiEmailForm() { | |
| 8595 | - const formContainer = document.getElementById( 'frmapi-email-form' ); | |
| 8596 | - jQuery.ajax({ | |
| 8597 | - dataType: 'json', | |
| 8598 | - url: formContainer.getAttribute( 'data-url' ), | |
| 8599 | - success: function( json ) { | |
| 8600 | - var form = json.renderedHtml; | |
| 8601 | - form = form.replace( /<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi, '' ); | |
| 8602 | - formContainer.innerHTML = form; | |
| 8603 | - } | |
| 8604 | - }); | |
| 8605 | - } | |
| 8606 | - | |
| 8607 | - function handleApiFormError( inputId, errorId, type, message ) { | |
| 8608 | - const $error = jQuery( errorId ); | |
| 8609 | - $error.removeClass( 'frm_hidden' ).attr( 'frm-error', type ); | |
| 8610 | - | |
| 8611 | - if ( typeof message !== 'undefined' ) { | |
| 8612 | - $error.find( 'span[frm-error="' + type + '"]' ).text( message ); | |
| 8613 | - } | |
| 8614 | - | |
| 8615 | - jQuery( inputId ).one( 'keyup', function() { | |
| 8616 | - $error.addClass( 'frm_hidden' ); | |
| 8617 | - }); | |
| 8618 | - } | |
| 8619 | - | |
| 8620 | - function handleEmailAddressError( type ) { | |
| 8621 | - handleApiFormError( '#frm_leave_email', '#frm_leave_email_error', type ); | |
| 8622 | - } | |
| 8623 | - | |
| 8624 | - function initNewFormModal() { | |
| 8625 | - var installFormTrigger, | |
| 8626 | - activeHoverIcons, | |
| 8627 | - $modal, | |
| 8628 | - handleConfirmEmailAddressError, | |
| 8629 | - firstLockedTemplate, | |
| 8630 | - isShowFreeTemplatesFormFirst, | |
| 8631 | - url, | |
| 8632 | - urlParams; | |
| 8633 | - | |
| 8634 | - url = new URL( window.location.href ); | |
| 8635 | - urlParams = url.searchParams; | |
| 8636 | - | |
| 8637 | - isShowFreeTemplatesFormFirst = urlParams.get( 'free-templates' ); | |
| 8638 | - | |
| 8639 | - jQuery( document ).on( 'click', '.frm-trigger-new-form-modal', triggerNewFormModal ); | |
| 8640 | - $modal = initModal( '#frm_new_form_modal', '600px' ); | |
| 8641 | - | |
| 8642 | - if ( false === $modal ) { | |
| 8643 | - return; | |
| 8644 | - } | |
| 8645 | - | |
| 8646 | - setTimeout( | |
| 8647 | - function() { | |
| 8648 | - $modal.get( 0 ).querySelector( '.postbox' ).style.display = 'block'; // Fixes pro issue #3508, prevent a conflict that hides the postbox in modal. | |
| 8649 | - }, | |
| 8650 | - 0 | |
| 8651 | - ); | |
| 8652 | - | |
| 8653 | - installFormTrigger = document.createElement( 'a' ); | |
| 8654 | - installFormTrigger.classList.add( 'frm-install-template', 'frm_hidden' ); | |
| 8655 | - document.body.appendChild( installFormTrigger ); | |
| 8656 | - | |
| 8657 | - jQuery( '.frm-install-template' ).on( 'click', function( event ) { | |
| 8658 | - var $h3Clone = jQuery( this ).closest( 'li, td' ).find( 'h3' ).clone(), | |
| 8659 | - nameLabel = document.getElementById( 'frm_new_name' ), | |
| 8660 | - descLabel = document.getElementById( 'frm_new_desc' ), | |
| 8661 | - oldName; | |
| 8662 | - | |
| 8663 | - $h3Clone.find( 'svg, .frm-plan-required-tag' ).remove(); | |
| 8664 | - oldName = $h3Clone.html().trim(); | |
| 8665 | - | |
| 8666 | - event.preventDefault(); | |
| 8667 | - | |
| 8668 | - document.getElementById( 'frm_template_name' ).value = oldName; | |
| 8669 | - document.getElementById( 'frm_link' ).value = this.attributes.rel.value; | |
| 8670 | - document.getElementById( 'frm_action_type' ).value = 'frm_install_template'; | |
| 8671 | - nameLabel.textContent = nameLabel.getAttribute( 'data-form' ); | |
| 8672 | - descLabel.textContent = descLabel.getAttribute( 'data-form' ); | |
| 8673 | - $modal.dialog( 'open' ); | |
| 8674 | - }); | |
| 8675 | - | |
| 8676 | - jQuery( document ).on( 'submit', '#frm-new-template', installTemplate ); | |
| 8677 | - | |
| 8678 | - jQuery( document ).on( 'click', '.frm-hover-icons .frm-preview-form', function( event ) { | |
| 8679 | - var $li, link, iframe, | |
| 8680 | - container = document.getElementById( 'frm-preview-block' ); | |
| 8681 | - | |
| 8682 | - event.preventDefault(); | |
| 8683 | - | |
| 8684 | - $li = jQuery( this ).closest( 'li' ); | |
| 8685 | - link = $li.attr( 'data-preview' ); | |
| 8686 | - | |
| 8687 | - if ( link.indexOf( ajaxurl ) > -1 ) { | |
| 8688 | - iframe = document.createElement( 'iframe' ); | |
| 8689 | - iframe.src = link; | |
| 8690 | - iframe.height = '400'; | |
| 8691 | - iframe.width = '100%'; | |
| 8692 | - container.innerHTML = ''; | |
| 8693 | - container.appendChild( iframe ); | |
| 8694 | - } else { | |
| 8695 | - frmApiPreview( container, link ); | |
| 8696 | - } | |
| 8697 | - | |
| 8698 | - jQuery( '#frm-preview-title' ).text( getStrippedTemplateName( $li ) ); | |
| 8699 | - $modal.attr( 'frm-page', 'preview' ); | |
| 8700 | - activeHoverIcons = jQuery( this ).closest( '.frm-hover-icons' ); | |
| 8701 | - }); | |
| 8702 | - | |
| 8703 | - jQuery( document ).on( 'click', 'li.frm-ready-made-solution[data-href]', function() { | |
| 8704 | - window.location = this.getAttribute( 'data-href' ); | |
| 8705 | - }); | |
| 8706 | - | |
| 8707 | - jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-create-form', function( event ) { | |
| 8708 | - var $li, name, link, action; | |
| 8709 | - | |
| 8710 | - event.preventDefault(); | |
| 8711 | - | |
| 8712 | - $li = jQuery( this ).closest( 'li' ); | |
| 8713 | - | |
| 8714 | - if ( $li.is( '[data-href]' ) ) { | |
| 8715 | - window.location = $li.attr( 'data-href' ); | |
| 8716 | - return; | |
| 8717 | - } | |
| 8718 | - | |
| 8719 | - if ( $li.hasClass( 'frm-add-blank-form' ) ) { | |
| 8720 | - name = link = ''; | |
| 8721 | - action = 'frm_install_form'; | |
| 8722 | - } else if ( $li.is( '[data-rel]' ) ) { | |
| 8723 | - name = getStrippedTemplateName( $li ); | |
| 8724 | - link = $li.attr( 'data-rel' ); | |
| 8725 | - action = 'frm_install_template'; | |
| 8726 | - } else { | |
| 8727 | - return; | |
| 8728 | - } | |
| 8729 | - | |
| 8730 | - transitionToAddDetails( $modal, name, link, action ); | |
| 8731 | - }); | |
| 8732 | - | |
| 8733 | - // Welcome page modals. | |
| 8734 | - jQuery( document ).on( 'click', '.frm-create-blank-form', function( event ) { | |
| 8735 | - event.preventDefault(); | |
| 8736 | - jQuery( '.frm-trigger-new-form-modal' ).trigger( 'click' ); | |
| 8737 | - transitionToAddDetails( $modal, '', '', 'frm_install_form' ); | |
| 8738 | - | |
| 8739 | - // Close the modal with the cancel button. | |
| 8740 | - jQuery( '.frm-modal-cancel.frm-back-to-all-templates' ).on( 'click', function() { | |
| 8741 | - jQuery( '.ui-widget-overlay' ).trigger( 'click' ); | |
| 8742 | - }); | |
| 8743 | - }); | |
| 8744 | - | |
| 8745 | - 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 ) { | |
| 8746 | - var $hoverIcons, $trigger, | |
| 8747 | - $li = jQuery( this ).closest( 'li' ), | |
| 8748 | - triggerClass = $li.hasClass( 'frm-locked-template' ) ? 'frm-unlock-form' : 'frm-create-form'; | |
| 8749 | - | |
| 8750 | - $hoverIcons = $li.find( '.frm-hover-icons' ); | |
| 8751 | - if ( ! $hoverIcons.length ) { | |
| 8752 | - $li.trigger( 'mouseover' ); | |
| 8753 | - $hoverIcons = $li.find( '.frm-hover-icons' ); | |
| 8754 | - $hoverIcons.hide(); | |
| 8755 | - } | |
| 8756 | - | |
| 8757 | - $trigger = $hoverIcons.find( '.' + triggerClass ); | |
| 8758 | - $trigger.trigger( 'click' ); | |
| 8759 | - }); | |
| 8760 | - | |
| 8761 | - jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-delete-form', function( event ) { | |
| 8762 | - var $li, | |
| 8763 | - trigger; | |
| 8764 | - | |
| 8765 | - event.preventDefault(); | |
| 8766 | - | |
| 8767 | - $li = jQuery( this ).closest( 'li' ); | |
| 8768 | - $li.addClass( 'frm-deleting' ); | |
| 8769 | - trigger = document.createElement( 'a' ); | |
| 8770 | - trigger.setAttribute( 'href', '#' ); | |
| 8771 | - trigger.setAttribute( 'data-id', $li.attr( 'data-formid' ) ); | |
| 8772 | - $li.attr( 'id', 'frm-template-custom-' + $li.attr( 'data-formid' ) ); | |
| 8773 | - jQuery( trigger ).on( 'click', trashTemplate ); | |
| 8774 | - trigger.click(); | |
| 8775 | - setTemplateCount( $li.closest( '.accordion-section' ).get( 0 ) ); | |
| 8776 | - }); | |
| 8777 | - | |
| 8778 | - jQuery( document ).on( 'click', 'li.frm-locked-template .frm-hover-icons .frm-unlock-form', function( event ) { | |
| 8779 | - var $li, | |
| 8780 | - activePage; | |
| 8781 | - | |
| 8782 | - event.preventDefault(); | |
| 8783 | - | |
| 8784 | - $li = jQuery( this ).closest( '.frm-locked-template' ); | |
| 8785 | - | |
| 8786 | - if ( $li.hasClass( 'frm-free-template' ) ) { | |
| 8787 | - showFreeTemplatesForm(); | |
| 8788 | - | |
| 8789 | - $modal.attr( 'frm-page', 'email' ); | |
| 8790 | - | |
| 8791 | - $modal.attr( 'frm-this-form', $li.attr( 'data-key' ) ); | |
| 8792 | - $li.append( installFormTrigger ); | |
| 8793 | - return; | |
| 8794 | - } | |
| 8795 | - | |
| 8796 | - if ( $modal.hasClass( 'frm-expired' ) ) { | |
| 8797 | - activePage = 'renew'; | |
| 8798 | - } else { | |
| 8799 | - activePage = 'upgrade'; | |
| 8800 | - } | |
| 8801 | - | |
| 8802 | - $modal.attr( 'frm-page', activePage ); | |
| 8803 | - }); | |
| 8804 | - | |
| 8805 | - jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop', function() { | |
| 8806 | - jQuery( this ) | |
| 8807 | - .closest( '.accordion-section-content' ).css( 'overflow', 'visible' ) | |
| 8808 | - .closest( '.accordion-section' ).css( 'z-index', 1 ); | |
| 8809 | - }); | |
| 8810 | - | |
| 8811 | - jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop + .frm-dropdown-menu .frm-build-template', function() { | |
| 8812 | - var name = this.getAttribute( 'data-fullname' ), | |
| 8813 | - link = this.getAttribute( 'data-formid' ), | |
| 8814 | - action = 'frm_build_template'; | |
| 8815 | - transitionToAddDetails( $modal, name, link, action ); | |
| 8816 | - }); | |
| 8817 | - | |
| 8818 | - handleConfirmEmailAddressError = function( type, message ) { | |
| 8819 | - handleApiFormError( '#frm_code_from_email', '#frm_code_from_email_error', type, message ); | |
| 8820 | - }; | |
| 8821 | - | |
| 8822 | - jQuery( document ).on( 'click', '.frm-confirm-email-address', function( event ) { | |
| 8823 | - var code = document.getElementById( 'frm_code_from_email' ).value.trim(); | |
| 8824 | - | |
| 8825 | - event.preventDefault(); | |
| 8826 | - | |
| 8827 | - if ( '' === code ) { | |
| 8828 | - handleConfirmEmailAddressError( 'empty' ); | |
| 8829 | - return; | |
| 8830 | - } | |
| 8831 | - | |
| 8832 | - jQuery.ajax({ | |
| 8833 | - type: 'POST', | |
| 8834 | - url: ajaxurl, | |
| 8835 | - dataType: 'json', | |
| 8836 | - data: { | |
| 8837 | - action: 'template_api_signup', | |
| 8838 | - nonce: frmGlobal.nonce, | |
| 8839 | - code: code, | |
| 8840 | - key: $modal.attr( 'frm-this-form' ) | |
| 8841 | - }, | |
| 8842 | - success: function( response ) { | |
| 8843 | - if ( response.success ) { | |
| 8844 | - if ( isShowFreeTemplatesFormFirst ) { | |
| 8845 | - // Remove free-templates param from URL then reload page. | |
| 8846 | - urlParams.delete( 'free-templates' ); | |
| 8847 | - url.search = urlParams.toString(); | |
| 8848 | - window.location.href = url.toString(); | |
| 8849 | - | |
| 8850 | - return; | |
| 8851 | - } | |
| 8852 | - | |
| 8853 | - if ( typeof response.data !== 'undefined' && typeof response.data.url !== 'undefined' ) { | |
| 8854 | - installFormTrigger.setAttribute( 'rel', response.data.url ); | |
| 8855 | - installFormTrigger.click(); | |
| 8856 | - $modal.attr( 'frm-page', 'details' ); | |
| 8857 | - | |
| 8858 | - const hookName = 'frm_new_form_modal_form'; | |
| 8859 | - wp.hooks.doAction( hookName, $modal ); | |
| 8860 | - | |
| 8861 | - document.getElementById( 'frm_action_type' ).value = 'frm_install_template'; | |
| 8862 | - | |
| 8863 | - if ( typeof response.data.urlByKey !== 'undefined' ) { | |
| 8864 | - updateTemplateModalFreeUrls( response.data.urlByKey ); | |
| 8865 | - } | |
| 8866 | - } | |
| 8867 | - } else { | |
| 8868 | - if ( Array.isArray( response.data ) && response.data.length ) { | |
| 8869 | - handleConfirmEmailAddressError( 'custom', response.data[0].message ); | |
| 8870 | - } else { | |
| 8871 | - handleConfirmEmailAddressError( 'wrong-code' ); | |
| 8872 | - } | |
| 8873 | - | |
| 8874 | - jQuery( '#frm_code_from_email_options' ).removeClass( 'frm_hidden' ); | |
| 8875 | - } | |
| 8876 | - } | |
| 8877 | - }); | |
| 8878 | - }); | |
| 8879 | - | |
| 8880 | - jQuery( document ).on( 'click', '#frm-change-email-address', function() { | |
| 8881 | - $modal.attr( 'frm-page', 'email' ); | |
| 8882 | - }); | |
| 8883 | - | |
| 8884 | - jQuery( document ).on( 'click', '#frm-resend-code', function() { | |
| 8885 | - document.getElementById( 'frm_code_from_email' ).value = ''; | |
| 8886 | - jQuery( '#frm_code_from_email_options, #frm_code_from_email_error' ).addClass( 'frm_hidden' ); | |
| 8887 | - document.getElementById( 'frm-add-my-email-address' ).click(); | |
| 8888 | - }); | |
| 8889 | - | |
| 8890 | - 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 ) { | |
| 8891 | - document.getElementById( 'frm-create-title' ).removeAttribute( 'frm-type' ); | |
| 8892 | - $modal.attr( 'frm-page', 'create' ); | |
| 8893 | - }); | |
| 8894 | - | |
| 8895 | - jQuery( document ).on( 'click', '.frm-use-this-template', function( event ) { | |
| 8896 | - var $trigger; | |
| 8897 | - | |
| 8898 | - event.preventDefault(); | |
| 8899 | - | |
| 8900 | - $trigger = activeHoverIcons.find( '.frm-create-form' ); | |
| 8901 | - if ( $trigger.closest( '.frm-selectable' ).hasClass( 'frm-locked-template' ) ) { | |
| 8902 | - $trigger = activeHoverIcons.find( '.frm-unlock-form' ); | |
| 8903 | - } | |
| 8904 | - | |
| 8905 | - $trigger.trigger( 'click' ); | |
| 8906 | - }); | |
| 8907 | - | |
| 8908 | - jQuery( document ).on( 'click', '.frm-submit-new-template', function( event ) { | |
| 8909 | - var button; | |
| 8910 | - event.preventDefault(); | |
| 8911 | - button = document.getElementById( 'frm-new-template' ).querySelector( 'button' ); | |
| 8912 | - if ( null !== button ) { | |
| 8913 | - button.click(); | |
| 8914 | - } | |
| 8915 | - }); | |
| 8916 | - | |
| 8917 | - if ( urlParams.get( 'triggerNewFormModal' ) ) { | |
| 8918 | - triggerNewFormModal(); | |
| 8919 | - | |
| 8920 | - if ( isShowFreeTemplatesFormFirst ) { | |
| 8921 | - firstLockedTemplate = jQuery( 'li.frm-locked-template.frm-free-template' ).eq( 0 ); | |
| 8922 | - | |
| 8923 | - if ( firstLockedTemplate.length ) { | |
| 8924 | - showFreeTemplatesForm(); | |
| 8925 | - | |
| 8926 | - $modal.attr( 'frm-page', 'email' ); | |
| 8927 | - $modal.attr( 'frm-this-form', firstLockedTemplate.attr( 'data-key' ) ); | |
| 8928 | - | |
| 8929 | - firstLockedTemplate.append( installFormTrigger ); | |
| 8930 | - } | |
| 8931 | - | |
| 8932 | - // Hides the back button in the Free Template Modal and shows it when the cancel button is clicked | |
| 8933 | - $modalBackButton = $modal.find( '.frm-modal-back' ); | |
| 8934 | - $modalBackButton.hide(); | |
| 8935 | - $modal.find( '.frm-modal-cancel' ).on( 'click', ( event ) => { | |
| 8936 | - $modalBackButton.show(); | |
| 8937 | - $modal.dialog( 'close' ); | |
| 8938 | - }); | |
| 8939 | - } | |
| 8940 | - } | |
| 8941 | - | |
| 8942 | - initSearch( 'template-search-input', 'control-section accordion-section' ); | |
| 8943 | - } | |
| 8944 | - | |
| 8945 | - function initSearch( inputID, itemClass ) { | |
| 8946 | - const searchInput = document.getElementById( inputID ); | |
| 8947 | - | |
| 8948 | - if ( itemClass === 'control-section accordion-section' ) { | |
| 8949 | - itemClass = 'frm-selectable frm-searchable-template'; | |
| 8950 | - | |
| 8951 | - const handleTemplateSearch = () => { | |
| 8952 | - document.querySelectorAll( '.control-section.accordion-section' ).forEach( category => { | |
| 8953 | - const found = category.querySelector( '.frm-selectable.frm-searchable-template:not(.frm_hidden)' ) || ( searchInput.value === '' && category.querySelector( '#frm-template-drop' ) ); | |
| 8954 | - if ( found ) { | |
| 8955 | - setTemplateCount( category ); | |
| 8956 | - } | |
| 8957 | - category.classList.toggle( 'frm_hidden', ! found ); | |
| 8958 | - }); | |
| 8959 | - }; | |
| 8960 | - | |
| 8961 | - frmDom.search.init( searchInput, itemClass, { handleSearchResult: handleTemplateSearch }); | |
| 8962 | - | |
| 8963 | - } else { | |
| 8964 | - if ( itemClass === 'frm-searchable-template frm-ready-made-solution' ) { | |
| 8965 | - Array.from( document.getElementsByClassName( itemClass ) ).forEach( item => { | |
| 8966 | - let innerText = ''; | |
| 8967 | - innerText = item.querySelector( 'h3' ).innerText; | |
| 8968 | - item.setAttribute( 'frm-search-text', innerText.toLowerCase() ); | |
| 8969 | - }); | |
| 8970 | - } | |
| 8971 | - frmDom.search.init( searchInput, itemClass ); | |
| 8972 | - } | |
| 8973 | - | |
| 8974 | - } | |
| 8975 | - | |
| 8976 | - function updateTemplateModalFreeUrls( urlByKey ) { | |
| 8977 | - jQuery( '#frm_new_form_modal' ).find( '.frm-selectable[data-key]' ).each( function() { | |
| 8978 | - var $template = jQuery( this ), | |
| 8979 | - key = $template.attr( 'data-key' ); | |
| 8980 | - if ( 'undefined' !== typeof urlByKey[ key ]) { | |
| 8981 | - $template.removeClass( 'frm-locked-template' ); | |
| 8982 | - $template.find( 'h3 svg' ).remove(); // remove the lock from the title | |
| 8983 | - $template.attr( 'data-rel', urlByKey[ key ]); | |
| 8984 | - } | |
| 8985 | - }); | |
| 8986 | - } | |
| 8987 | - | |
| 8988 | - function transitionToAddDetails( $modal, name, link, action ) { | |
| 8989 | - var nameLabel = document.getElementById( 'frm_new_name' ), | |
| 8990 | - descLabel = document.getElementById( 'frm_new_desc' ), | |
| 8991 | - type = [ 'frm_install_template', 'frm_install_form' ].indexOf( action ) >= 0 ? 'form' : 'template', | |
| 8992 | - templateNameInput = document.getElementById( 'frm_template_name' ); | |
| 8993 | - | |
| 8994 | - templateNameInput.value = name; | |
| 8995 | - document.getElementById( 'frm_link' ).value = link; | |
| 8996 | - document.getElementById( 'frm_action_type' ).value = action; | |
| 8997 | - nameLabel.textContent = nameLabel.getAttribute( 'data-' + type ); | |
| 8998 | - if ( descLabel !== null ) { | |
| 8999 | - descLabel.textContent = descLabel.getAttribute( 'data-' + type ); | |
| 9000 | - } | |
| 9001 | - | |
| 9002 | - document.getElementById( 'frm-create-title' ).setAttribute( 'frm-type', type ); | |
| 9003 | - | |
| 9004 | - $modal.attr( 'frm-page', 'details' ); | |
| 9005 | - | |
| 9006 | - const hookName = 'frm_new_form_modal_form'; | |
| 9007 | - wp.hooks.doAction( hookName, $modal ); | |
| 9008 | - | |
| 9009 | - if ( '' === name ) { | |
| 9010 | - templateNameInput.focus(); | |
| 9011 | - } | |
| 9012 | - } | |
| 9013 | - | |
| 9014 | - function getStrippedTemplateName( $li ) { | |
| 9015 | - var $clone = $li.find( 'h3' ).clone(); | |
| 9016 | - $clone.find( 'svg, .frm-plan-required-tag, .frm-new-pill' ).remove(); | |
| 9017 | - return $clone.html().trim(); | |
| 9018 | - } | |
| 9019 | - | |
| 9020 | - function setTemplateCount( category, searchableTemplates ) { | |
| 9021 | - var count, | |
| 9022 | - templateIndex, | |
| 9023 | - availableCounter, | |
| 9024 | - availableCount; | |
| 9025 | - | |
| 9026 | - if ( typeof searchableTemplates === 'undefined' ) { | |
| 9027 | - searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden):not(.frm-deleting)' ); | |
| 9028 | - } | |
| 9029 | - | |
| 9030 | - count = searchableTemplates.length; | |
| 9031 | - category.querySelector( '.frm-template-count' ).textContent = count; | |
| 9032 | - | |
| 9033 | - jQuery( category ).find( '.frm-templates-plural' ).toggleClass( 'frm_hidden', count === 1 ); | |
| 9034 | - jQuery( category ).find( '.frm-templates-singular' ).toggleClass( 'frm_hidden', count !== 1 ); | |
| 9035 | - | |
| 9036 | - availableCounter = category.querySelector( '.frm-available-templates-count' ); | |
| 9037 | - if ( availableCounter !== null ) { | |
| 9038 | - availableCount = 0; | |
| 9039 | - for ( templateIndex in searchableTemplates ) { | |
| 9040 | - if ( ! isNaN( templateIndex ) && ! searchableTemplates[ templateIndex ].classList.contains( 'frm-locked-template' ) ) { | |
| 9041 | - availableCount++; | |
| 9042 | - } | |
| 9043 | - } | |
| 9044 | - | |
| 9045 | - availableCounter.textContent = availableCount; | |
| 9046 | - } | |
| 9047 | - } | |
| 9048 | - | |
| 9049 | - function initSelectionAutocomplete() { | |
| 9050 | - frmDom.autocomplete.initSelectionAutocomplete(); | |
| 9051 | - } | |
| 9052 | - | |
| 9053 | - function nextInstallStep( thisStep ) { | |
| 9054 | - thisStep.classList.add( 'frm_grey' ); | |
| 9055 | - thisStep.nextElementSibling.classList.remove( 'frm_grey' ); | |
| 9056 | - } | |
| 9057 | - | |
| 9058 | - function frmApiPreview( cont, link ) { | |
| 9059 | - cont.innerHTML = '<div class="frm-wait"></div>'; | |
| 9060 | - jQuery.ajax({ | |
| 9061 | - dataType: 'json', | |
| 9062 | - url: link, | |
| 9063 | - success: function( json ) { | |
| 9064 | - var form = json.renderedHtml; | |
| 9065 | - form = form.replace( /<script\b[^<]*(js\/jquery\/jquery)[^<]*><\/script>/gi, '' ); | |
| 9066 | - form = form.replace( /<link\b[^>]*(jquery-ui.min.css)[^>]*>/gi, '' ); | |
| 9067 | - form = form.replace( ' frm_logic_form ', ' ' ); | |
| 9068 | - form = form.replace( '<form ', '<form onsubmit="event.preventDefault();" ' ); | |
| 9069 | - cont.innerHTML = '<div class="frm-wait" id="frm-remove-me"></div><div class="frm-fade" id="frm-show-me">' + | |
| 9070 | - form + '</div>'; | |
| 9071 | - setTimeout( function() { | |
| 9072 | - document.getElementById( 'frm-remove-me' ).style.display = 'none'; | |
| 9073 | - document.getElementById( 'frm-show-me' ).style.opacity = '1'; | |
| 9074 | - }, 300 ); | |
| 9075 | - } | |
| 9076 | - }); | |
| 9077 | - } | |
| 9078 | - | |
| 9079 | - function installTemplateFieldset( e ) { | |
| 9080 | - /*jshint validthis:true */ | |
| 9081 | - var fieldset = this.parentNode.parentNode, | |
| 9082 | - action = fieldset.elements.type.value, | |
| 9083 | - button = this; | |
| 9084 | - e.preventDefault(); | |
| 9085 | - button.classList.add( 'frm_loading_button' ); | |
| 9086 | - installNewForm( fieldset, action, button ); | |
| 9087 | - } | |
| 9088 | - | |
| 9089 | - function installTemplate( e ) { | |
| 9090 | - /*jshint validthis:true */ | |
| 9091 | - var action = this.elements.type.value, | |
| 9092 | - button = this.querySelector( 'button' ); | |
| 9093 | - e.preventDefault(); | |
| 9094 | - button.classList.add( 'frm_loading_button' ); | |
| 9095 | - installNewForm( this, action, button ); | |
| 9096 | - } | |
| 9097 | - | |
| 9098 | - function installNewForm( form, action, button ) { | |
| 9099 | - const formData = formToData( form ); | |
| 9100 | - const formName = formData.template_name; | |
| 9101 | - const formDesc = formData.template_desc; | |
| 9102 | - const link = form.elements.link.value; | |
| 9103 | - | |
| 9104 | - let data = { | |
| 9105 | - action: action, | |
| 9106 | - xml: link, | |
| 9107 | - name: formName, | |
| 9108 | - desc: formDesc, | |
| 9109 | - form: JSON.stringify( formData ), | |
| 9110 | - nonce: frmGlobal.nonce | |
| 9111 | - }; | |
| 9112 | - | |
| 9113 | - const hookName = 'frm_before_install_new_form'; | |
| 9114 | - const filterArgs = { formData }; | |
| 9115 | - data = wp.hooks.applyFilters( hookName, data, filterArgs ); | |
| 9116 | - | |
| 9117 | - postAjax( data, function( response ) { | |
| 9118 | - if ( typeof response.redirect !== 'undefined' ) { | |
| 9119 | - const redirect = response.redirect; | |
| 9120 | - if ( typeof form.elements.redirect === 'undefined' ) { | |
| 9121 | - window.location = redirect; | |
| 9122 | - } else { | |
| 9123 | - const href = document.getElementById( 'frm-redirect-link' ); | |
| 9124 | - if ( typeof link !== 'undefined' && href !== null ) { | |
| 9125 | - // Show the next installation step. | |
| 9126 | - href.setAttribute( 'href', redirect ); | |
| 9127 | - href.classList.remove( 'frm_grey', 'disabled' ); | |
| 9128 | - nextInstallStep( form.parentNode.parentNode ); | |
| 9129 | - button.classList.add( 'frm_grey', 'disabled' ); | |
| 9130 | - } | |
| 9131 | - } | |
| 9132 | - } else { | |
| 9133 | - jQuery( '.spinner' ).css( 'visibility', 'hidden' ); | |
| 9134 | - | |
| 9135 | - // Show response.message | |
| 9136 | - if ( 'string' === typeof response.message ) { | |
| 9137 | - showInstallFormErrorModal( response.message ); | |
| 9138 | - } | |
| 9139 | - } | |
| 9140 | - button.classList.remove( 'frm_loading_button' ); | |
| 9141 | - }); | |
| 9142 | - } | |
| 9143 | - | |
| 9144 | - function showInstallFormErrorModal( message ) { | |
| 9145 | - const modalContent = div( message ); | |
| 9146 | - modalContent.style.padding = '20px 40px'; | |
| 9147 | - const modal = frmDom.modal.maybeCreateModal( | |
| 9148 | - 'frmInstallFormErrorModal', | |
| 9149 | - { | |
| 9150 | - title: __( 'Unable to install template', 'formidable' ), | |
| 9151 | - content: modalContent | |
| 9152 | - } | |
| 9153 | - ); | |
| 9154 | - modal.classList.add( 'frm_common_modal' ); | |
| 9155 | - } | |
| 9156 | - | |
| 9157 | - function handleCaptchaTypeChange( e ) { | |
| 9158 | - const thresholdContainer = document.getElementById( 'frm_captcha_threshold_container' ); | |
| 9159 | - if ( thresholdContainer ) { | |
| 9160 | - thresholdContainer.classList.toggle( 'frm_hidden', 'v3' !== e.target.value ); | |
| 9161 | - } | |
| 9162 | - } | |
| 9163 | - | |
| 9164 | - function trashTemplate( e ) { | |
| 9165 | - /*jshint validthis:true */ | |
| 9166 | - var id = this.getAttribute( 'data-id' ); | |
| 9167 | - e.preventDefault(); | |
| 9168 | - | |
| 9169 | - data = { | |
| 9170 | - action: 'frm_forms_trash', | |
| 9171 | - id: id, | |
| 9172 | - nonce: frmGlobal.nonce | |
| 9173 | - }; | |
| 9174 | - postAjax( data, function() { | |
| 9175 | - var card = document.getElementById( 'frm-template-custom-' + id ); | |
| 9176 | - fadeOut( card, function() { | |
| 9177 | - card.parentNode.removeChild( card ); | |
| 9178 | - }); | |
| 9179 | - }); | |
| 9180 | - } | |
| 9181 | - | |
| 9182 | - function searchContent() { | |
| 9183 | - /*jshint validthis:true */ | |
| 9184 | - var i, | |
| 9185 | - regEx = false, | |
| 9186 | - searchText = this.value.toLowerCase(), | |
| 9187 | - toSearch = this.getAttribute( 'data-tosearch' ), | |
| 9188 | - items = document.getElementsByClassName( toSearch ); | |
| 9189 | - | |
| 9190 | - if ( this.tagName === 'SELECT' ) { | |
| 9191 | - searchText = selectedOptions( this ); | |
| 9192 | - searchText = searchText.join( '|' ).toLowerCase(); | |
| 9193 | - regEx = true; | |
| 9194 | - } | |
| 9195 | - | |
| 9196 | - if ( toSearch === 'frm-action' && searchText !== '' ) { | |
| 9197 | - var addons = document.getElementById( 'frm_email_addon_menu' ).classList; | |
| 9198 | - addons.remove( 'frm-all-actions' ); | |
| 9199 | - addons.add( 'frm-limited-actions' ); | |
| 9200 | - } | |
| 9201 | - | |
| 9202 | - for ( i = 0; i < items.length; i++ ) { | |
| 9203 | - var innerText = items[i].innerText.toLowerCase(); | |
| 9204 | - | |
| 9205 | - const itemCanBeShown = ! ( getExportOption() === 'xml' && items[i].classList.contains( 'frm-is-repeater' ) ); | |
| 9206 | - if ( searchText === '' ) { | |
| 9207 | - if ( itemCanBeShown ) { | |
| 9208 | - items[i].classList.remove( 'frm_hidden' ); | |
| 9209 | - } | |
| 9210 | - items[i].classList.remove( 'frm-search-result' ); | |
| 9211 | - } else if ( ( regEx && new RegExp( searchText ).test( innerText ) ) || innerText.indexOf( searchText ) >= 0 ) { | |
| 9212 | - if ( itemCanBeShown ) { | |
| 9213 | - items[i].classList.remove( 'frm_hidden' ); | |
| 9214 | - } | |
| 9215 | - items[i].classList.add( 'frm-search-result' ); | |
| 9216 | - } else { | |
| 9217 | - items[i].classList.add( 'frm_hidden' ); | |
| 9218 | - items[i].classList.remove( 'frm-search-result' ); | |
| 9219 | - } | |
| 9220 | - } | |
| 9221 | - | |
| 9222 | - // Updates the visibility of category headings based on search results. | |
| 9223 | - updateCatHeadingVisibility(); | |
| 9224 | - | |
| 9225 | - jQuery( this ).trigger( 'frmAfterSearch' ); | |
| 9226 | - } | |
| 9227 | - | |
| 9228 | - /** | |
| 9229 | - * Updates the visibility of category headings based on search results. | |
| 9230 | - * If all associated fields are hidden (indicating no search matches), | |
| 9231 | - * the heading is hidden. | |
| 9232 | - * | |
| 9233 | - * @since 6.4.1 | |
| 9234 | - */ | |
| 9235 | - function updateCatHeadingVisibility() { | |
| 9236 | - const insertFieldsElement = document.querySelector( '#frm-insert-fields' ); | |
| 9237 | - if ( ! insertFieldsElement ) { | |
| 9238 | - return; | |
| 9239 | - } | |
| 9240 | - | |
| 9241 | - const headingElements = insertFieldsElement.querySelectorAll( ':scope > .frm-with-line' ); | |
| 9242 | - headingElements.forEach( heading => { | |
| 9243 | - const fieldsListElement = heading.nextElementSibling; | |
| 9244 | - if ( ! fieldsListElement ) { | |
| 9245 | - return; | |
| 9246 | - } | |
| 9247 | - const listItemElements = fieldsListElement.querySelectorAll( ':scope > li.frmbutton' ); | |
| 9248 | - const allHidden = Array.from( listItemElements ).every( li => li.classList.contains( 'frm_hidden' ) ); | |
| 9249 | - | |
| 9250 | - // Add or remove class based on `allHidden` condition | |
| 9251 | - heading.classList.toggle( 'frm_hidden', allHidden ); | |
| 9252 | - }); | |
| 9253 | - } | |
| 9254 | - | |
| 9255 | - function stopPropagation( e ) { | |
| 9256 | - e.stopPropagation(); | |
| 9257 | - } | |
| 9258 | - | |
| 9259 | - /* Helpers */ | |
| 9260 | - | |
| 9261 | - function selectedOptions( select ) { | |
| 9262 | - var opt, | |
| 9263 | - result = [], | |
| 9264 | - options = select && select.options; | |
| 9265 | - | |
| 9266 | - for ( var i = 0, iLen = options.length; i < iLen; i++ ) { | |
| 9267 | - opt = options[i]; | |
| 9268 | - | |
| 9269 | - if ( opt.selected ) { | |
| 9270 | - result.push( opt.value ); | |
| 9271 | - } | |
| 9272 | - } | |
| 9273 | - return result; | |
| 9274 | - } | |
| 9275 | - | |
| 9276 | - function triggerEvent( element, event ) { | |
| 9277 | - var evt = document.createEvent( 'HTMLEvents' ); | |
| 9278 | - evt.initEvent( event, false, true ); | |
| 9279 | - element.dispatchEvent( evt ); | |
| 9280 | - } | |
| 9281 | - | |
| 9282 | - function postAjax( data, success ) { | |
| 9283 | - let response; | |
| 9284 | - | |
| 9285 | - const xmlHttp = new XMLHttpRequest(); | |
| 9286 | - const params = typeof data === 'string' ? data : Object.keys( data ).map( | |
| 9287 | - function( k ) { | |
| 9288 | - return encodeURIComponent( k ) + '=' + encodeURIComponent( data[k]); | |
| 9289 | - } | |
| 9290 | - ).join( '&' ); | |
| 9291 | - | |
| 9292 | - xmlHttp.open( 'post', ajaxurl, true ); | |
| 9293 | - xmlHttp.onreadystatechange = function() { | |
| 9294 | - if ( xmlHttp.readyState > 3 && xmlHttp.status == 200 ) { | |
| 9295 | - response = xmlHttp.responseText; | |
| 9296 | - try { | |
| 9297 | - response = JSON.parse( response ); | |
| 9298 | - } catch ( e ) { | |
| 9299 | - // The response may not be JSON, so just return it. | |
| 9300 | - } | |
| 9301 | - success( response ); | |
| 9302 | - } | |
| 9303 | - }; | |
| 9304 | - xmlHttp.setRequestHeader( 'X-Requested-With', 'XMLHttpRequest' ); | |
| 9305 | - xmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' ); | |
| 9306 | - xmlHttp.send( params ); | |
| 9307 | - return xmlHttp; | |
| 9308 | - } | |
| 9309 | - | |
| 9310 | - function fadeOut( element, success ) { | |
| 9311 | - element.classList.add( 'frm-fade' ); | |
| 9312 | - setTimeout( success, 1000 ); | |
| 9313 | - } | |
| 9314 | - | |
| 9315 | - function invisible( classes ) { | |
| 9316 | - jQuery( classes ).css( 'visibility', 'hidden' ); | |
| 9317 | - } | |
| 9318 | - | |
| 9319 | - function visible( classes ) { | |
| 9320 | - jQuery( classes ).css( 'visibility', 'visible' ); | |
| 9321 | - } | |
| 9322 | - | |
| 9323 | - function initModal( id, width ) { | |
| 9324 | - const $info = jQuery( id ); | |
| 9325 | - if ( ! $info.length ) { | |
| 9326 | - return false; | |
| 9327 | - } | |
| 9328 | - | |
| 9329 | - if ( typeof width === 'undefined' ) { | |
| 9330 | - width = '550px'; | |
| 9331 | - } | |
| 9332 | - | |
| 9333 | - const dialogArgs = { | |
| 9334 | - dialogClass: 'frm-dialog', | |
| 9335 | - modal: true, | |
| 9336 | - autoOpen: false, | |
| 9337 | - closeOnEscape: true, | |
| 9338 | - width: width, | |
| 9339 | - resizable: false, | |
| 9340 | - draggable: false, | |
| 9341 | - open: function() { | |
| 9342 | - jQuery( '.ui-dialog-titlebar' ).addClass( 'frm_hidden' ).removeClass( 'ui-helper-clearfix' ); | |
| 9343 | - jQuery( '#wpwrap' ).addClass( 'frm_overlay' ); | |
| 9344 | - jQuery( '.frm-dialog' ).removeClass( 'ui-widget ui-widget-content ui-corner-all' ); | |
| 9345 | - $info.removeClass( 'ui-dialog-content ui-widget-content' ); | |
| 9346 | - bindClickForDialogClose( $info ); | |
| 9347 | - }, | |
| 9348 | - close: function() { | |
| 9349 | - jQuery( '#wpwrap' ).removeClass( 'frm_overlay' ); | |
| 9350 | - jQuery( '.spinner' ).css( 'visibility', 'hidden' ); | |
| 9351 | - | |
| 9352 | - this.removeAttribute( 'data-option-type' ); | |
| 9353 | - const optionType = document.getElementById( 'bulk-option-type' ); | |
| 9354 | - if ( optionType ) { | |
| 9355 | - optionType.value = ''; | |
| 9356 | - } | |
| 9357 | - } | |
| 9358 | - }; | |
| 9359 | - | |
| 9360 | - $info.dialog( dialogArgs ); | |
| 9361 | - | |
| 9362 | - return $info; | |
| 9363 | - } | |
| 9364 | - | |
| 9365 | - function toggle( cname, id ) { | |
| 9366 | - if ( id === '#' ) { | |
| 9367 | - var cont = document.getElementById( cname ); | |
| 9368 | - var hidden = cont.style.display; | |
| 9369 | - if ( hidden === 'none' ) { | |
| 9370 | - cont.style.display = 'block'; | |
| 9371 | - } else { | |
| 9372 | - cont.style.display = 'none'; | |
| 9373 | - } | |
| 9374 | - } else { | |
| 9375 | - var vis = cname.is( ':visible' ); | |
| 9376 | - if ( vis ) { | |
| 9377 | - cname.hide(); | |
| 9378 | - } else { | |
| 9379 | - cname.show(); | |
| 9380 | - } | |
| 9381 | - } | |
| 9382 | - } | |
| 9383 | - | |
| 9384 | - function removeWPUnload() { | |
| 9385 | - window.onbeforeunload = null; | |
| 9386 | - var w = jQuery( window ); | |
| 9387 | - w.off( 'beforeunload.widgets' ); | |
| 9388 | - w.off( 'beforeunload.edit-post' ); | |
| 9389 | - } | |
| 9390 | - | |
| 9391 | - function addMultiselectLabelListener() { | |
| 9392 | - const clickListener = ( e ) => { | |
| 9393 | - if ( 'LABEL' !== e.target.nodeName ) { | |
| 9394 | - return; | |
| 9395 | - } | |
| 9396 | - | |
| 9397 | - const labelFor = e.target.getAttribute( 'for' ); | |
| 9398 | - if ( ! labelFor ) { | |
| 9399 | - return; | |
| 9400 | - } | |
| 9401 | - | |
| 9402 | - const input = document.getElementById( labelFor ); | |
| 9403 | - if ( ! input || ! input.nextElementSibling ) { | |
| 9404 | - return; | |
| 9405 | - } | |
| 9406 | - | |
| 9407 | - const buttonToggle = input.nextElementSibling.querySelector( 'button.dropdown-toggle.multiselect' ); | |
| 9408 | - if ( ! buttonToggle ) { | |
| 9409 | - return; | |
| 9410 | - } | |
| 9411 | - | |
| 9412 | - const triggerMultiselectClick = () => buttonToggle.click(); | |
| 9413 | - setTimeout( triggerMultiselectClick, 0 ); | |
| 9414 | - }; | |
| 9415 | - document.addEventListener( 'click', clickListener ); | |
| 9416 | - } | |
| 9417 | - | |
| 9418 | - function maybeChangeEmbedFormMsg() { | |
| 9419 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 9420 | - var fieldItem = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 9421 | - if ( null === fieldItem || 'form' !== fieldItem.dataset.type ) { | |
| 9422 | - return; | |
| 9423 | - } | |
| 9424 | - | |
| 9425 | - fieldItem = jQuery( fieldItem ); | |
| 9426 | - | |
| 9427 | - if ( this.options[ this.selectedIndex ].value ) { | |
| 9428 | - fieldItem.find( '.frm-not-set' )[0].classList.add( 'frm_hidden' ); | |
| 9429 | - var embedMsg = fieldItem.find( '.frm-embed-message' ); | |
| 9430 | - embedMsg.html( embedMsg.data( 'embedmsg' ) + this.options[ this.selectedIndex ].text ); | |
| 9431 | - fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.remove( 'frm_hidden' ); | |
| 9432 | - } else { | |
| 9433 | - fieldItem.find( '.frm-not-set' )[0].classList.remove( 'frm_hidden' ); | |
| 9434 | - fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.add( 'frm_hidden' ); | |
| 9435 | - } | |
| 9436 | - } | |
| 9437 | - | |
| 9438 | - function toggleProductType() { | |
| 9439 | - var settings = jQuery( this ).closest( '.frm-single-settings' ), | |
| 9440 | - container = settings.find( '.frmjs_product_choices' ), | |
| 9441 | - heading = settings.find( '.frm_prod_options_heading' ), | |
| 9442 | - currentVal = this.options[ this.selectedIndex ].value; | |
| 9443 | - | |
| 9444 | - container.removeClass( 'frm_prod_type_single frm_prod_type_user_def' ); | |
| 9445 | - heading.removeClass( 'frm_prod_user_def' ); | |
| 9446 | - | |
| 9447 | - if ( 'single' === currentVal ) { | |
| 9448 | - container.addClass( 'frm_prod_type_single' ); | |
| 9449 | - } else if ( 'user_def' === currentVal ) { | |
| 9450 | - container.addClass( 'frm_prod_type_user_def' ); | |
| 9451 | - heading.addClass( 'frm_prod_user_def' ); | |
| 9452 | - } | |
| 9453 | - } | |
| 9454 | - | |
| 9455 | - function isProductField( fieldId ) { | |
| 9456 | - var field = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 9457 | - if ( field === null ) { | |
| 9458 | - return false; | |
| 9459 | - } else { | |
| 9460 | - return 'product' === field.getAttribute( 'data-type' ); | |
| 9461 | - } | |
| 9462 | - } | |
| 9463 | - | |
| 9464 | - /** | |
| 9465 | - * Serialize form data with vanilla JS. | |
| 9466 | - */ | |
| 9467 | - function formToData( form ) { | |
| 9468 | - var subKey, i, | |
| 9469 | - object = {}, | |
| 9470 | - formData = form.elements; | |
| 9471 | - | |
| 9472 | - for ( i = 0; i < formData.length; i++ ) { | |
| 9473 | - var input = formData[i], | |
| 9474 | - key = input.name, | |
| 9475 | - value = input.value, | |
| 9476 | - names = key.match( /(.*)\[(.*)\]/ ); | |
| 9477 | - | |
| 9478 | - if ( ( input.type === 'radio' || input.type === 'checkbox' ) && ! input.checked ) { | |
| 9479 | - continue; | |
| 9480 | - } | |
| 9481 | - | |
| 9482 | - if ( names !== null ) { | |
| 9483 | - key = names[1]; | |
| 9484 | - subKey = names[2]; | |
| 9485 | - if ( ! Reflect.has( object, key ) ) { | |
| 9486 | - object[key] = {}; | |
| 9487 | - } | |
| 9488 | - object[key][subKey] = value; | |
| 9489 | - continue; | |
| 9490 | - } | |
| 9491 | - | |
| 9492 | - // Reflect.has in favor of: object.hasOwnProperty(key) | |
| 9493 | - if ( ! Reflect.has( object, key ) ) { | |
| 9494 | - object[key] = value; | |
| 9495 | - continue; | |
| 9496 | - } | |
| 9497 | - if ( ! Array.isArray( object[key]) ) { | |
| 9498 | - object[key] = [ object[key] ]; | |
| 9499 | - } | |
| 9500 | - object[key].push( value ); | |
| 9501 | - } | |
| 9502 | - | |
| 9503 | - return object; | |
| 9504 | - } | |
| 9505 | - | |
| 9506 | - /** | |
| 9507 | - * Show, hide, and sort subfields of Name field on form builder. | |
| 9508 | - * | |
| 9509 | - * @since 4.11 | |
| 9510 | - */ | |
| 9511 | - function handleNameFieldOnFormBuilder() { | |
| 9512 | - /** | |
| 9513 | - * Gets subfield element from cache. | |
| 9514 | - * | |
| 9515 | - * @param {String} fieldId Field ID. | |
| 9516 | - * @param {String} key Cache key. | |
| 9517 | - * @returns {HTMLElement|undefined} Return the element from cache or undefined if not found. | |
| 9518 | - */ | |
| 9519 | - const getSubFieldElFromCache = ( fieldId, key ) => { | |
| 9520 | - window.frmCachedSubFields = window.frmCachedSubFields || {}; | |
| 9521 | - window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {}; | |
| 9522 | - return window.frmCachedSubFields[fieldId][key]; | |
| 9523 | - }; | |
| 9524 | - | |
| 9525 | - /** | |
| 9526 | - * Sets subfield element to cache. | |
| 9527 | - * | |
| 9528 | - * @param {String} fieldId Field ID. | |
| 9529 | - * @param {String} key Cache key. | |
| 9530 | - * @param {HTMLElement} el Element. | |
| 9531 | - */ | |
| 9532 | - const setSubFieldElToCache = ( fieldId, key, el ) => { | |
| 9533 | - window.frmCachedSubFields = window.frmCachedSubFields || {}; | |
| 9534 | - window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {}; | |
| 9535 | - window.frmCachedSubFields[fieldId][key] = el; | |
| 9536 | - }; | |
| 9537 | - | |
| 9538 | - /** | |
| 9539 | - * Gets column class from the number of columns. | |
| 9540 | - * | |
| 9541 | - * @param {Number} colCount Number of columns. | |
| 9542 | - * @returns {string} | |
| 9543 | - */ | |
| 9544 | - const getColClass = colCount => 'frm' + parseInt( 12 / colCount ); | |
| 9545 | - | |
| 9546 | - const colClasses = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ].map( num => 'frm' + num ); | |
| 9547 | - | |
| 9548 | - const allSubFieldNames = [ 'first', 'middle', 'last' ]; | |
| 9549 | - | |
| 9550 | - /** | |
| 9551 | - * Handles name layout change. | |
| 9552 | - * | |
| 9553 | - * @param {Event} event Event object. | |
| 9554 | - */ | |
| 9555 | - const onChangeLayout = event => { | |
| 9556 | - const value = event.target.value; | |
| 9557 | - const subFieldNames = value.split( '_' ); | |
| 9558 | - const fieldId = event.target.dataset.fieldId; | |
| 9559 | - | |
| 9560 | - /* | |
| 9561 | - * Live update form on the form builder. | |
| 9562 | - */ | |
| 9563 | - const container = document.querySelector( '#field_' + fieldId + '_inner_container .frm_combo_inputs_container' ); | |
| 9564 | - const newColClass = getColClass( subFieldNames.length ); | |
| 9565 | - | |
| 9566 | - // Set all sub field elements to cache and hide all of them first. | |
| 9567 | - allSubFieldNames.forEach( name => { | |
| 9568 | - const subFieldEl = container.querySelector( '[data-sub-field-name="' + name + '"]' ); | |
| 9569 | - if ( subFieldEl ) { | |
| 9570 | - subFieldEl.classList.add( 'frm_hidden' ); | |
| 9571 | - subFieldEl.classList.remove( ...colClasses ); | |
| 9572 | - setSubFieldElToCache( fieldId, name, subFieldEl ); | |
| 9573 | - } | |
| 9574 | - }); | |
| 9575 | - | |
| 9576 | - subFieldNames.forEach( subFieldName => { | |
| 9577 | - const subFieldEl = getSubFieldElFromCache( fieldId, subFieldName ); | |
| 9578 | - if ( ! subFieldEl ) { | |
| 9579 | - return; | |
| 9580 | - } | |
| 9581 | - | |
| 9582 | - subFieldEl.classList.remove( 'frm_hidden' ); | |
| 9583 | - subFieldEl.classList.add( newColClass ); | |
| 9584 | - | |
| 9585 | - container.append( subFieldEl ); | |
| 9586 | - }); | |
| 9587 | - | |
| 9588 | - /* | |
| 9589 | - * Live update subfield options. | |
| 9590 | - */ | |
| 9591 | - // Hide all subfield options. | |
| 9592 | - allSubFieldNames.forEach( name => { | |
| 9593 | - const optionsEl = document.querySelector( '.frm_sub_field_options-' + name + '[data-field-id="' + fieldId + '"]' ); | |
| 9594 | - if ( optionsEl ) { | |
| 9595 | - optionsEl.classList.add( 'frm_hidden' ); | |
| 9596 | - setSubFieldElToCache( fieldId, name + '_options', optionsEl ); | |
| 9597 | - } | |
| 9598 | - }); | |
| 9599 | - | |
| 9600 | - subFieldNames.forEach( subFieldName => { | |
| 9601 | - const optionsEl = getSubFieldElFromCache( fieldId, subFieldName + '_options' ); | |
| 9602 | - if ( ! optionsEl ) { | |
| 9603 | - return; | |
| 9604 | - } | |
| 9605 | - optionsEl.classList.remove( 'frm_hidden' ); | |
| 9606 | - }); | |
| 9607 | - }; | |
| 9608 | - | |
| 9609 | - const dropdownSelector = '.frm_name_layout_dropdown'; | |
| 9610 | - document.addEventListener( 'change', event => { | |
| 9611 | - if ( event.target.matches( dropdownSelector ) ) { | |
| 9612 | - onChangeLayout( event ); | |
| 9613 | - } | |
| 9614 | - }, false ); | |
| 9615 | - } | |
| 9616 | - | |
| 9617 | - function debounce( func, wait = 100 ) { | |
| 9618 | - return frmDom.util.debounce( func, wait ); | |
| 9619 | - } | |
| 9620 | - | |
| 9621 | - function addSaveAndDragIconsToOption( fieldId, liObject ) { | |
| 9622 | - let li, useTag, useTagHref; | |
| 9623 | - let hasDragIcon = false; | |
| 9624 | - let hasSaveIcon = false; | |
| 9625 | - | |
| 9626 | - if ( liObject.newOption ) { | |
| 9627 | - const parser = new DOMParser(); | |
| 9628 | - li = parser.parseFromString( liObject.newOption, 'text/html' ).body.childNodes[0]; | |
| 9629 | - } else { | |
| 9630 | - li = liObject; | |
| 9631 | - } | |
| 9632 | - | |
| 9633 | - const liIcons = li.querySelectorAll( 'svg' ); | |
| 9634 | - | |
| 9635 | - liIcons.forEach( ( svg, key ) => { | |
| 9636 | - useTag = svg.getElementsByTagNameNS( 'http://www.w3.org/2000/svg', 'use' )[0]; | |
| 9637 | - if ( ! useTag ) { | |
| 9638 | - return; | |
| 9639 | - } | |
| 9640 | - useTagHref = useTag.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) || useTag.getAttribute( 'href' ); | |
| 9641 | - | |
| 9642 | - if ( useTagHref === '#frm_drag_icon' ) { | |
| 9643 | - hasDragIcon = true; | |
| 9644 | - } | |
| 9645 | - | |
| 9646 | - if ( useTagHref === '#frm_save_icon' ) { | |
| 9647 | - hasSaveIcon = true; | |
| 9648 | - } | |
| 9649 | - }); | |
| 9650 | - | |
| 9651 | - if ( ! hasDragIcon ) { | |
| 9652 | - li.prepend( icons.drag.cloneNode( true ) ); | |
| 9653 | - } | |
| 9654 | - | |
| 9655 | - if ( li.querySelector( `[id^=field_key_${fieldId}-]` ) && ! hasSaveIcon ) { | |
| 9656 | - li.querySelector( `[id^=field_key_${fieldId}-]` ).after( icons.save.cloneNode( true ) ); | |
| 9657 | - } | |
| 9658 | - | |
| 9659 | - if ( liObject.newOption ) { | |
| 9660 | - liObject.newOption = li; | |
| 9661 | - } | |
| 9662 | - } | |
| 9663 | - | |
| 9664 | - function maybeAddSaveAndDragIcons( fieldId ) { | |
| 9665 | - fieldOptions = document.querySelectorAll( `[id^=frm_delete_field_${fieldId}-]` ); | |
| 9666 | - // return if there are no options. | |
| 9667 | - if ( fieldOptions.length < 2 ) { | |
| 9668 | - return; | |
| 9669 | - } | |
| 9670 | - | |
| 9671 | - let options = [ ...fieldOptions ].slice( 1 ); | |
| 9672 | - options.forEach( ( li, _key ) => { | |
| 9673 | - if ( li.classList.contains( 'frm_other_option' ) ) { | |
| 9674 | - return; | |
| 9675 | - } | |
| 9676 | - addSaveAndDragIconsToOption( fieldId, li ); | |
| 9677 | - }); | |
| 9678 | - } | |
| 9679 | - | |
| 9680 | - function initOnSubmitAction() { | |
| 9681 | - const onChangeType = event => { | |
| 9682 | - if ( ! event.target.checked ) { | |
| 9683 | - return; | |
| 9684 | - } | |
| 9685 | - | |
| 9686 | - const actionEl = event.target.closest( '.frm_form_action_settings' ); | |
| 9687 | - actionEl.querySelectorAll( '.frm_on_submit_dependent_setting:not(.frm_hidden)' ).forEach( el => { | |
| 9688 | - el.classList.add( 'frm_hidden' ); | |
| 9689 | - }); | |
| 9690 | - | |
| 9691 | - const activeEls = actionEl.querySelectorAll( '.frm_on_submit_dependent_setting[data-show-if-' + event.target.value + ']' ); | |
| 9692 | - activeEls.forEach( activeEl => { | |
| 9693 | - activeEl.classList.remove( 'frm_hidden' ); | |
| 9694 | - }); | |
| 9695 | - | |
| 9696 | - actionEl.setAttribute( 'data-on-submit-type', event.target.value ); | |
| 9697 | - }; | |
| 9698 | - | |
| 9699 | - frmDom.util.documentOn( 'change', '.frm_on_submit_type input[type="radio"]', onChangeType ); | |
| 9700 | - } | |
| 9701 | - | |
| 9702 | - /** | |
| 9703 | - * Listen for click events for an API-loaded email collection form. | |
| 9704 | - * This is used for the free templates flow of the new form modal. | |
| 9705 | - * It is also used for the Active Campaign sign-up form in the inbox page (when there are no messages). | |
| 9706 | - */ | |
| 9707 | - function initAddMyEmailAddress() { | |
| 9708 | - jQuery( document ).on( | |
| 9709 | - 'click', | |
| 9710 | - '#frm-add-my-email-address', | |
| 9711 | - event => { | |
| 9712 | - event.preventDefault(); | |
| 9713 | - addMyEmailAddress(); | |
| 9714 | - } | |
| 9715 | - ); | |
| 9716 | - | |
| 9717 | - const emptyInbox = document.getElementById( 'frm_empty_inbox' ); | |
| 9718 | - if ( emptyInbox ) { | |
| 9719 | - const leaveEmailIput = document.getElementById( 'frm_leave_email' ); | |
| 9720 | - leaveEmailIput.addEventListener( | |
| 9721 | - 'keyup', | |
| 9722 | - event => { | |
| 9723 | - if ( 'Enter' === event.key ) { | |
| 9724 | - const button = document.getElementById( 'frm-add-my-email-address' ); | |
| 9725 | - if ( button ) { | |
| 9726 | - button.click(); | |
| 9727 | - } | |
| 9728 | - } | |
| 9729 | - } | |
| 9730 | - ); | |
| 9731 | - } | |
| 9732 | - } | |
| 9733 | - | |
| 9734 | - function addMyEmailAddress() { | |
| 9735 | - const email = document.getElementById( 'frm_leave_email' ).value.trim(); | |
| 9736 | - if ( '' === email ) { | |
| 9737 | - handleEmailAddressError( 'empty' ); | |
| 9738 | - return; | |
| 9739 | - } | |
| 9740 | - | |
| 9741 | - const 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; | |
| 9742 | - if ( regex.test( email ) === false ) { | |
| 9743 | - handleEmailAddressError( 'invalid' ); | |
| 9744 | - return; | |
| 9745 | - } | |
| 9746 | - | |
| 9747 | - const $hiddenForm = jQuery( '#frmapi-email-form' ).find( 'form' ); | |
| 9748 | - const $hiddenEmailField = $hiddenForm.find( '[type="email"]' ).not( '.frm_verify' ); | |
| 9749 | - if ( ! $hiddenEmailField.length ) { | |
| 9750 | - return; | |
| 9751 | - } | |
| 9752 | - | |
| 9753 | - const emptyInbox = document.getElementById( 'frm_empty_inbox' ); | |
| 9754 | - if ( emptyInbox ) { | |
| 9755 | - document.getElementById( 'frm-add-my-email-address' ).remove(); | |
| 9756 | - | |
| 9757 | - const emailWrapper = document.getElementById( 'frm_leave_email_wrapper' ); | |
| 9758 | - if ( emailWrapper ) { | |
| 9759 | - emailWrapper.classList.add( 'frm_hidden' ); | |
| 9760 | - const spinner = span({ className: 'frm-wait frm_spinner' }); | |
| 9761 | - spinner.style.visibility = 'visible'; | |
| 9762 | - spinner.style.float = 'none'; | |
| 9763 | - emailWrapper.parentElement.insertBefore( | |
| 9764 | - spinner, | |
| 9765 | - emailWrapper.nextElementSibling | |
| 9766 | - ); | |
| 9767 | - } | |
| 9768 | - } | |
| 9769 | - | |
| 9770 | - $hiddenEmailField.val( email ); | |
| 9771 | - jQuery.ajax({ | |
| 9772 | - type: 'POST', | |
| 9773 | - url: $hiddenForm.attr( 'action' ), | |
| 9774 | - data: $hiddenForm.serialize() + '&action=frm_forms_preview' | |
| 9775 | - }).done( function( data ) { | |
| 9776 | - const message = jQuery( data ).find( '.frm_message' ).text().trim(); | |
| 9777 | - if ( message.indexOf( 'Thanks!' ) === -1 ) { | |
| 9778 | - handleEmailAddressError( 'invalid' ); | |
| 9779 | - return; | |
| 9780 | - } | |
| 9781 | - | |
| 9782 | - const apiForm = document.getElementById( 'frmapi-email-form' ); | |
| 9783 | - const spinner = apiForm.parentElement.querySelector( '.frm_spinner' ); | |
| 9784 | - if ( spinner ) { | |
| 9785 | - spinner.remove(); | |
| 9786 | - } | |
| 9787 | - | |
| 9788 | - // Handle successful form submission. | |
| 9789 | - // If the new form modal exists, handle the free templates form. | |
| 9790 | - const modal = document.getElementById( 'frm_new_form_modal' ); | |
| 9791 | - if ( modal ) { | |
| 9792 | - modal.setAttribute( 'frm-page', 'code' ); | |
| 9793 | - } else { | |
| 9794 | - // If no modal exists handle the Active Campaign form on the inbox page. | |
| 9795 | - document.getElementById( 'frm_leave_email_wrapper' ).replaceWith( | |
| 9796 | - document.createTextNode( 'Thank you for signing up!' ) | |
| 9797 | - ); | |
| 9798 | - } | |
| 9799 | - }); | |
| 9800 | - } | |
| 9801 | - | |
| 9802 | - return { | |
| 9803 | - init: function() { | |
| 9804 | - initAddMyEmailAddress(); | |
| 9805 | - | |
| 9806 | - s = {}; | |
| 9807 | - | |
| 9808 | - // Bootstrap dropdown button | |
| 9809 | - jQuery( '.wp-admin' ).on( 'click', function( e ) { | |
| 9810 | - var t = jQuery( e.target ); | |
| 9811 | - var $openDrop = jQuery( '.dropdown.open' ); | |
| 9812 | - if ( $openDrop.length && ! t.hasClass( 'dropdown' ) && ! t.closest( '.dropdown' ).length ) { | |
| 9813 | - $openDrop.removeClass( 'open' ); | |
| 9814 | - } | |
| 9815 | - }); | |
| 9816 | - jQuery( '#frm_bs_dropdown:not(.open) a' ).on( 'click', focusSearchBox ); | |
| 9817 | - | |
| 9818 | - if ( typeof thisFormId === 'undefined' ) { | |
| 9819 | - thisFormId = jQuery( document.getElementById( 'form_id' ) ).val(); | |
| 9820 | - } | |
| 9821 | - | |
| 9822 | - // Add event listener for dismissible warning messages. | |
| 9823 | - document.querySelectorAll( '.frm-warning-dismiss' ).forEach( ( dismissIcon ) => { | |
| 9824 | - onClickPreventDefault( dismissIcon, dismissWarningMessage ); | |
| 9825 | - }); | |
| 9826 | - | |
| 9827 | - frmAdminBuild.inboxBannerInit(); | |
| 9828 | - | |
| 9829 | - if ( $newFields.length > 0 ) { | |
| 9830 | - // only load this on the form builder page | |
| 9831 | - frmAdminBuild.buildInit(); | |
| 9832 | - } else if ( document.getElementById( 'frm_notification_settings' ) !== null ) { | |
| 9833 | - // only load on form settings page | |
| 9834 | - frmAdminBuild.settingsInit(); | |
| 9835 | - } else if ( document.getElementById( 'frm_styling_form' ) !== null ) { | |
| 9836 | - // load styling settings js | |
| 9837 | - frmAdminBuild.styleInit(); | |
| 9838 | - } else if ( document.getElementById( 'form_global_settings' ) !== null ) { | |
| 9839 | - // global settings page | |
| 9840 | - frmAdminBuild.globalSettingsInit(); | |
| 9841 | - } else if ( document.getElementById( 'frm_export_xml' ) !== null ) { | |
| 9842 | - // import/export page | |
| 9843 | - frmAdminBuild.exportInit(); | |
| 9844 | - } else if ( document.getElementById( 'frm_dyncontent' ) !== null ) { | |
| 9845 | - // only load on views settings page | |
| 9846 | - frmAdminBuild.viewInit(); | |
| 9847 | - } else if ( document.getElementById( 'frm_inbox_page' ) !== null ) { | |
| 9848 | - // Inbox page | |
| 9849 | - frmAdminBuild.inboxInit(); | |
| 9850 | - } else if ( document.getElementById( 'frm-welcome' ) !== null ) { | |
| 9851 | - // Solution install page | |
| 9852 | - frmAdminBuild.solutionInit(); | |
| 9853 | - } else { | |
| 9854 | - // New form selection page | |
| 9855 | - initNewFormModal(); | |
| 9856 | - initSelectionAutocomplete(); | |
| 9857 | - | |
| 9858 | - jQuery( '[data-frmprint]' ).on( 'click', function() { | |
| 9859 | - window.print(); | |
| 9860 | - return false; | |
| 9861 | - }); | |
| 9862 | - } | |
| 9863 | - | |
| 9864 | - var $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) ); | |
| 9865 | - if ( $advInfo.length > 0 || jQuery( '.frm_field_list' ).length > 0 ) { | |
| 9866 | - // only load on the form, form settings, and view settings pages | |
| 9867 | - frmAdminBuild.panelInit(); | |
| 9868 | - } | |
| 9869 | - | |
| 9870 | - loadTooltips(); | |
| 9871 | - initUpgradeModal(); | |
| 9872 | - | |
| 9873 | - // used on build, form settings, and view settings | |
| 9874 | - var $shortCodeDiv = jQuery( document.getElementById( 'frm_shortcodediv' ) ); | |
| 9875 | - if ( $shortCodeDiv.length > 0 ) { | |
| 9876 | - jQuery( 'a.edit-frm_shortcode' ).on( 'click', function() { | |
| 9877 | - if ( $shortCodeDiv.is( ':hidden' ) ) { | |
| 9878 | - $shortCodeDiv.slideDown( 'fast' ); | |
| 9879 | - this.style.display = 'none'; | |
| 9880 | - } | |
| 9881 | - return false; | |
| 9882 | - }); | |
| 9883 | - | |
| 9884 | - jQuery( '.cancel-frm_shortcode', '#frm_shortcodediv' ).on( 'click', function() { | |
| 9885 | - $shortCodeDiv.slideUp( 'fast' ); | |
| 9886 | - $shortCodeDiv.siblings( 'a.edit-frm_shortcode' ).show(); | |
| 9887 | - return false; | |
| 9888 | - }); | |
| 9889 | - } | |
| 9890 | - | |
| 9891 | - // tabs | |
| 9892 | - jQuery( document ).on( 'click', '#frm-nav-tabs a', clickNewTab ); | |
| 9893 | - jQuery( '.post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a' ).on( 'click', function() { | |
| 9894 | - const showUpgradeTab = this.classList.contains( 'frm_show_upgrade_tab' ); | |
| 9895 | - if ( this.classList.contains( 'frm_noallow' ) && ! showUpgradeTab ) { | |
| 9896 | - return; | |
| 9897 | - } | |
| 9898 | - | |
| 9899 | - if ( showUpgradeTab ) { | |
| 9900 | - populateUpgradeTab( this ); | |
| 9901 | - } | |
| 9902 | - | |
| 9903 | - clickTab( this ); | |
| 9904 | - return false; | |
| 9905 | - }); | |
| 9906 | - clickTab( jQuery( '.starttab a' ), 'auto' ); | |
| 9907 | - | |
| 9908 | - // submit the search form with dropdown | |
| 9909 | - jQuery( document ).on( 'click', '#frm-fid-search-menu a', function() { | |
| 9910 | - var val = this.id.replace( 'fid-', '' ); | |
| 9911 | - jQuery( 'select[name="fid"]' ).val( val ); | |
| 9912 | - triggerSubmit( document.getElementById( 'posts-filter' ) ); | |
| 9913 | - return false; | |
| 9914 | - }); | |
| 9915 | - | |
| 9916 | - jQuery( '.frm_select_box' ).on( 'click focus', function() { | |
| 9917 | - this.select(); | |
| 9918 | - }); | |
| 9919 | - | |
| 9920 | - jQuery( document ).on( 'input search change', '.frm-auto-search:not(#frm_new_form_modal #template-search-input)', searchContent ); | |
| 9921 | - jQuery( document ).on( 'focusin click', '.frm-auto-search', stopPropagation ); | |
| 9922 | - var autoSearch = jQuery( '.frm-auto-search' ); | |
| 9923 | - if ( autoSearch.val() !== '' ) { | |
| 9924 | - autoSearch.trigger( 'keyup' ); | |
| 9925 | - } | |
| 9926 | - | |
| 9927 | - // Initialize Formidable Connection. | |
| 9928 | - FrmFormsConnect.init(); | |
| 9929 | - | |
| 9930 | - jQuery( document ).on( 'click', '.frm-install-addon', installAddon ); | |
| 9931 | - jQuery( document ).on( 'click', '.frm-activate-addon', activateAddon ); | |
| 9932 | - jQuery( document ).on( 'click', '.frm-solution-multiple', installMultipleAddons ); | |
| 9933 | - | |
| 9934 | - // prevent annoying confirmation message from WordPress | |
| 9935 | - jQuery( 'button, input[type=submit]' ).on( 'click', removeWPUnload ); | |
| 9936 | - | |
| 9937 | - addMultiselectLabelListener(); | |
| 9938 | - | |
| 9939 | - frmAdminBuild.hooks.addFilter( | |
| 9940 | - 'frm_before_embed_modal', | |
| 9941 | - ( ids, { element, type }) => { | |
| 9942 | - if ( 'form' !== type ) { | |
| 9943 | - return ids; | |
| 9944 | - } | |
| 9945 | - | |
| 9946 | - let formId, formKey; | |
| 9947 | - const row = element.closest( 'tr' ); | |
| 9948 | - | |
| 9949 | - if ( row ) { | |
| 9950 | - // Embed icon on form index. | |
| 9951 | - formId = parseInt( row.querySelector( '.column-id' ).textContent ); | |
| 9952 | - formKey = row.querySelector( '.column-form_key' ).textContent; | |
| 9953 | - } else { | |
| 9954 | - // Embed button in form builder / form settings. | |
| 9955 | - formId = document.getElementById( 'form_id' ).value; | |
| 9956 | - | |
| 9957 | - const formKeyInput = document.getElementById( 'frm_form_key' ); | |
| 9958 | - if ( formKeyInput ) { | |
| 9959 | - formKey = formKeyInput.value; | |
| 9960 | - } else { | |
| 9961 | - const previewDrop = document.getElementById( 'frm-previewDrop' ); | |
| 9962 | - if ( previewDrop ) { | |
| 9963 | - formKey = previewDrop.nextElementSibling.querySelector( '.dropdown-item a' ).getAttribute( 'href' ).split( 'form=' )[1]; | |
| 9964 | - } | |
| 9965 | - } | |
| 9966 | - } | |
| 9967 | - | |
| 9968 | - return [ formId, formKey ]; | |
| 9969 | - } | |
| 9970 | - ); | |
| 9971 | - | |
| 9972 | - document.querySelectorAll( '#frm-show-fields > li, .frm_grid_container li' ).forEach( ( el, _key ) => { | |
| 9973 | - el.addEventListener( 'click', function() { | |
| 9974 | - let fieldId = this.querySelector( 'li' )?.dataset.fid || this.dataset.fid; | |
| 9975 | - maybeAddSaveAndDragIcons( fieldId ); | |
| 9976 | - }); | |
| 9977 | - }); | |
| 9978 | - }, | |
| 9979 | - | |
| 9980 | - buildInit: function() { | |
| 9981 | - let loadFieldId, $builderForm, builderArea; | |
| 9982 | - | |
| 9983 | - debouncedSyncAfterDragAndDrop = debounce( syncAfterDragAndDrop, 10 ); | |
| 9984 | - postBodyContent = document.getElementById( 'post-body-content' ); | |
| 9985 | - $postBodyContent = jQuery( postBodyContent ); | |
| 9986 | - | |
| 9987 | - if ( jQuery( '.frm_field_loading' ).length ) { | |
| 9988 | - loadFieldId = jQuery( '.frm_field_loading' ).first().attr( 'id' ); | |
| 9989 | - loadFields( loadFieldId ); | |
| 9990 | - } | |
| 9991 | - | |
| 9992 | - setupSortable( 'ul.frm_sorting' ); | |
| 9993 | - | |
| 9994 | - document.querySelectorAll( '.field_type_list > li:not(.frm_show_upgrade)' ).forEach( makeDraggable ); | |
| 9995 | - | |
| 9996 | - 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(); | |
| 9997 | - | |
| 9998 | - jQuery( '.frm_submit_ajax' ).on( 'click', submitBuild ); | |
| 9999 | - jQuery( '.frm_submit_no_ajax' ).on( 'click', submitNoAjax ); | |
| 10000 | - | |
| 10001 | - jQuery( 'a.edit-form-status' ).on( 'click', slideDown ); | |
| 10002 | - jQuery( '.cancel-form-status' ).on( 'click', slideUp ); | |
| 10003 | - jQuery( '.save-form-status' ).on( 'click', function() { | |
| 10004 | - const newStatus = jQuery( document.getElementById( 'form_change_status' ) ).val(); | |
| 10005 | - jQuery( 'input[name="new_status"]' ).val( newStatus ); | |
| 10006 | - jQuery( document.getElementById( 'form-status-display' ) ).html( newStatus ); | |
| 10007 | - jQuery( '.cancel-form-status' ).trigger( 'click' ); | |
| 10008 | - return false; | |
| 10009 | - }); | |
| 10010 | - | |
| 10011 | - jQuery( '.frm_form_builder form' ).first().on( 'submit', function() { | |
| 10012 | - jQuery( '.inplace_field' ).trigger( 'blur' ); | |
| 10013 | - }); | |
| 10014 | - | |
| 10015 | - initiateMultiselect(); | |
| 10016 | - renumberPageBreaks(); | |
| 10017 | - | |
| 10018 | - $builderForm = jQuery( builderForm ); | |
| 10019 | - builderArea = document.getElementById( 'frm_form_editor_container' ); | |
| 10020 | - $builderForm.on( 'click', '.frm_add_logic_row', addFieldLogicRow ); | |
| 10021 | - $builderForm.on( 'click', '.frm_add_watch_lookup_row', addWatchLookupRow ); | |
| 10022 | - $builderForm.on( 'change', '.frm_get_values_form', updateGetValueFieldSelection ); | |
| 10023 | - $builderForm.on( 'change', '.frm_logic_field_opts', getFieldValues ); | |
| 10024 | - $builderForm.on( 'change', '.radio_maxnum', setStarValues ); | |
| 10025 | - $builderForm.on( 'frm-multiselect-changed', 'select[name^="field_options[admin_only_"]', adjustVisibilityValuesForEveryoneValues ); | |
| 10026 | - | |
| 10027 | - jQuery( document.getElementById( 'frm-insert-fields' ) ).on( 'click', '.frm_add_field', addFieldClick ); | |
| 10028 | - $newFields.on( 'click', '.frm_clone_field', duplicateField ); | |
| 10029 | - $builderForm.on( 'blur', 'input[id^="frm_calc"]', checkCalculationCreatedByUser ); | |
| 10030 | - $builderForm.on( 'change', 'input.frm_format_opt, input.frm_max_length_opt', toggleInvalidMsg ); | |
| 10031 | - $builderForm.on( 'change click', '[data-changeme]', liveChanges ); | |
| 10032 | - $builderForm.on( 'click', 'input.frm_req_field', markRequired ); | |
| 10033 | - $builderForm.on( 'click', '.frm_mark_unique', markUnique ); | |
| 10034 | - | |
| 10035 | - $builderForm.on( 'change', '.frm_repeat_format', toggleRepeatButtons ); | |
| 10036 | - $builderForm.on( 'change', '.frm_repeat_limit', checkRepeatLimit ); | |
| 10037 | - $builderForm.on( 'change', '.frm_js_checkbox_limit', checkCheckboxSelectionsLimit ); | |
| 10038 | - $builderForm.on( 'input', 'input[name^="field_options[add_label_"]', function() { | |
| 10039 | - updateRepeatText( this, 'add' ); | |
| 10040 | - }); | |
| 10041 | - $builderForm.on( 'input', 'input[name^="field_options[remove_label_"]', function() { | |
| 10042 | - updateRepeatText( this, 'remove' ); | |
| 10043 | - }); | |
| 10044 | - $builderForm.on( 'change', 'select[name^="field_options[data_type_"]', maybeClearWatchFields ); | |
| 10045 | - jQuery( builderArea ).on( 'click', '.frm-collapse-page', maybeCollapsePage ); | |
| 10046 | - jQuery( builderArea ).on( 'click', '.frm-collapse-section', maybeCollapseSection ); | |
| 10047 | - $builderForm.on( 'click', '.frm-single-settings h3', maybeCollapseSettings ); | |
| 10048 | - $builderForm.on( 'keydown', '.frm-single-settings h3', function( event ) { | |
| 10049 | - // If so, only proceed if the key pressed was 'Enter' or 'Space' | |
| 10050 | - if ( event.key === 'Enter' || event.key === ' ' ) { | |
| 10051 | - event.preventDefault(); | |
| 10052 | - maybeCollapseSettings.call( this, event ); | |
| 10053 | - } | |
| 10054 | - }); | |
| 10055 | - | |
| 10056 | - jQuery( builderArea ).on( 'show.bs.dropdown hide.bs.dropdown', changeSectionStyle ); | |
| 10057 | - | |
| 10058 | - $builderForm.on( 'click', '.frm_toggle_sep_values', toggleSepValues ); | |
| 10059 | - $builderForm.on( 'click', '.frm_toggle_image_options', toggleImageOptions ); | |
| 10060 | - $builderForm.on( 'click', '.frm_remove_image_option', removeImageFromOption ); | |
| 10061 | - $builderForm.on( 'click', '.frm_choose_image_box', addImageToOption ); | |
| 10062 | - $builderForm.on( 'change', '.frm_hide_image_text', refreshOptionDisplay ); | |
| 10063 | - $builderForm.on( 'change', '.frm_field_options_image_size', setImageSize ); | |
| 10064 | - $builderForm.on( 'click', '.frm_multiselect_opt', toggleMultiselect ); | |
| 10065 | - $newFields.on( 'mousedown', 'input, textarea, select', stopFieldFocus ); | |
| 10066 | - $newFields.on( 'click', 'input[type=radio], input[type=checkbox]', stopFieldFocus ); | |
| 10067 | - $newFields.on( 'click', '.frm_delete_field', clickDeleteField ); | |
| 10068 | - $newFields.on( 'click', '.frm_select_field', clickSelectField ); | |
| 10069 | - jQuery( document ).on( 'click', '.frm_delete_field_group', clickDeleteFieldGroup ); | |
| 10070 | - jQuery( document ).on( 'click', '.frm_clone_field_group', duplicateFieldGroup ); | |
| 10071 | - jQuery( document ).on( 'click', '#frm_field_group_controls > span:first-child', clickFieldGroupLayout ); | |
| 10072 | - jQuery( document ).on( 'click', '.frm-row-layout-option', handleFieldGroupLayoutOptionClick ); | |
| 10073 | - jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-row-layout-option', handleFieldGroupLayoutOptionInsideMergeClick ); | |
| 10074 | - jQuery( document ).on( 'click', '.frm-custom-field-group-layout', customFieldGroupLayoutClick ); | |
| 10075 | - jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-custom-field-group-layout', customFieldGroupLayoutInsideMergeClick ); | |
| 10076 | - jQuery( document ).on( 'click', '.frm-break-field-group', breakFieldGroupClick ); | |
| 10077 | - $newFields.on( 'click', '#frm_field_group_popup .frm_grid_container input', focusFieldGroupInputOnClick ); | |
| 10078 | - jQuery( document ).on( 'click', '.frm-cancel-custom-field-group-layout', cancelCustomFieldGroupClick ); | |
| 10079 | - jQuery( document ).on( 'click', '.frm-save-custom-field-group-layout', saveCustomFieldGroupClick ); | |
| 10080 | - $newFields.on( 'click', 'ul.frm_sorting', fieldGroupClick ); | |
| 10081 | - jQuery( document ).on( 'click', '.frm-merge-fields-into-row', mergeFieldsIntoRowClick ); | |
| 10082 | - jQuery( document ).on( 'click', '.frm-delete-field-groups', deleteFieldGroupsClick ); | |
| 10083 | - $newFields.on( 'click', '.frm-field-action-icons [data-toggle="dropdown"]', function() { | |
| 10084 | - this.closest( 'li.form-field' ).classList.add( 'frm-field-settings-open' ); | |
| 10085 | - jQuery( document ).on( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings ); | |
| 10086 | - }); | |
| 10087 | - $newFields.on( 'mousemove', 'ul.frm_sorting', checkForMultiselectKeysOnMouseMove ); | |
| 10088 | - $newFields.on( 'show.bs.dropdown', '.frm-field-action-icons', onFieldActionDropdownShow ); | |
| 10089 | - jQuery( document ).on( 'show.bs.dropdown', '#frm_field_group_controls', onFieldGroupActionDropdownShow ); | |
| 10090 | - $builderForm.on( 'click', '.frm_single_option a[data-removeid]', deleteFieldOption ); | |
| 10091 | - $builderForm.on( 'mousedown', '.frm_single_option input[type=radio]', maybeUncheckRadio ); | |
| 10092 | - $builderForm.on( 'focusin', '.frm_single_option input[type=text]', maybeClearOptText ); | |
| 10093 | - $builderForm.on( 'click', '.frm_add_opt', addFieldOption ); | |
| 10094 | - $builderForm.on( 'change', '.frm_single_option input', resetOptOnChange ); | |
| 10095 | - $builderForm.on( 'change', '.frm_image_id', resetOptOnChange ); | |
| 10096 | - $builderForm.on( 'change', '.frm_toggle_mult_sel', toggleMultSel ); | |
| 10097 | - $builderForm.on( 'focusin', '.frm_classes', showBuilderModal ); | |
| 10098 | - | |
| 10099 | - $newFields.on( 'click', '.frm_primary_label', clickLabel ); | |
| 10100 | - $newFields.on( 'click', '.frm_description', clickDescription ); | |
| 10101 | - $newFields.on( 'click', 'li.ui-state-default:not(.frm_noallow)', clickVis ); | |
| 10102 | - $newFields.on( 'dblclick', 'li.ui-state-default', openAdvanced ); | |
| 10103 | - $builderForm.on( 'change', '.frm_tax_form_select', toggleFormTax ); | |
| 10104 | - $builderForm.on( 'change', 'select.conf_field', addConf ); | |
| 10105 | - | |
| 10106 | - $builderForm.on( 'change', '.frm_get_field_selection', getFieldSelection ); | |
| 10107 | - | |
| 10108 | - $builderForm.on( 'click', '.frm-show-inline-modal', maybeShowInlineModal ); | |
| 10109 | - | |
| 10110 | - $builderForm.on( 'click', '.frm-inline-modal .dismiss', dismissInlineModal ); | |
| 10111 | - jQuery( document ).on( 'change', '[data-frmchange]', changeInputtedValue ); | |
| 10112 | - | |
| 10113 | - $builderForm.on( 'change', '.frm_include_extras_field', rePopCalcFieldsForSummary ); | |
| 10114 | - $builderForm.on( 'change', 'select[name^="field_options[form_select_"]', maybeChangeEmbedFormMsg ); | |
| 10115 | - | |
| 10116 | - jQuery( document ).on( 'submit', '#frm_js_build_form', buildSubmittedNoAjax ); | |
| 10117 | - 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 ); | |
| 10118 | - | |
| 10119 | - popAllProductFields(); | |
| 10120 | - | |
| 10121 | - jQuery( document ).on( 'change', '.frmjs_prod_data_type_opt', toggleProductType ); | |
| 10122 | - | |
| 10123 | - jQuery( document ).on( 'focus', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextFocus ); | |
| 10124 | - jQuery( document ).on( 'blur', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextBlur ); | |
| 10125 | - | |
| 10126 | - initBulkOptionsOverlay(); | |
| 10127 | - hideEmptyEle(); | |
| 10128 | - maybeHideQuantityProductFieldOption(); | |
| 10129 | - handleNameFieldOnFormBuilder(); | |
| 10130 | - toggleSectionHolder(); | |
| 10131 | - handleShowPasswordLiveUpdate(); | |
| 10132 | - }, | |
| 10133 | - | |
| 10134 | - settingsInit: function() { | |
| 10135 | - const $formActions = jQuery( document.getElementById( 'frm_notification_settings' ) ); | |
| 10136 | - | |
| 10137 | - let formSettings, $loggedIn, $cookieExp, $editable; | |
| 10138 | - | |
| 10139 | - // BCC, CC, and Reply To button functionality | |
| 10140 | - $formActions.on( 'click', '.frm_email_buttons', showEmailRow ); | |
| 10141 | - $formActions.on( 'click', '.frm_remove_field', hideEmailRow ); | |
| 10142 | - $formActions.on( 'change', '.frm_to_row, .frm_from_row', showEmailWarning ); | |
| 10143 | - $formActions.on( 'change', '.frm_tax_selector', changePosttaxRow ); | |
| 10144 | - $formActions.on( 'change', 'select.frm_single_post_field', checkDupPost ); | |
| 10145 | - $formActions.on( 'change', 'select.frm_toggle_post_content', togglePostContent ); | |
| 10146 | - $formActions.on( 'change', 'select.frm_dyncontent_opt', fillDyncontent ); | |
| 10147 | - $formActions.on( 'change', '.frm_post_type', switchPostType ); | |
| 10148 | - $formActions.on( 'click', '.frm_add_postmeta_row', addPostmetaRow ); | |
| 10149 | - $formActions.on( 'click', '.frm_add_posttax_row', addPosttaxRow ); | |
| 10150 | - $formActions.on( 'click', '.frm_toggle_cf_opts', toggleCfOpts ); | |
| 10151 | - $formActions.on( 'click', '.frm_duplicate_form_action', copyFormAction ); | |
| 10152 | - jQuery( document ).on( 'change', 'select[data-toggleclass], input[data-toggleclass]', toggleFormOpts ); | |
| 10153 | - jQuery( '.frm_actions_list' ).on( 'click', '.frm_active_action', addFormAction ); | |
| 10154 | - jQuery( '#frm-show-groups, #frm-hide-groups' ).on( 'click', toggleActionGroups ); | |
| 10155 | - initiateMultiselect(); | |
| 10156 | - | |
| 10157 | - //set actions icons to inactive | |
| 10158 | - jQuery( 'ul.frm_actions_list li' ).each( function() { | |
| 10159 | - checkActiveAction( jQuery( this ).children( 'a' ).data( 'actiontype' ) ); | |
| 10160 | - | |
| 10161 | - // If the icon is a background image, don't add BG color. | |
| 10162 | - const icon = jQuery( this ).find( 'i' ); | |
| 10163 | - if ( icon.css( 'background-image' ) !== 'none' ) { | |
| 10164 | - icon.addClass( 'frm-inverse' ); | |
| 10165 | - } | |
| 10166 | - }); | |
| 10167 | - | |
| 10168 | - jQuery( '.frm_submit_settings_btn' ).on( 'click', submitSettings ); | |
| 10169 | - | |
| 10170 | - formSettings = jQuery( '.frm_form_settings' ); | |
| 10171 | - formSettings.on( 'click', '.frm_add_form_logic', addFormLogicRow ); | |
| 10172 | - formSettings.on( 'blur', '.frm_email_blur', formatEmailSetting ); | |
| 10173 | - formSettings.on( 'click', '.frm_already_used', onlyOneActionMessage ); | |
| 10174 | - | |
| 10175 | - formSettings.on( 'change', '#logic_link_submit', toggleSubmitLogic ); | |
| 10176 | - formSettings.on( 'click', '.frm_add_submit_logic', addSubmitLogic ); | |
| 10177 | - formSettings.on( 'change', '.frm_submit_logic_field_opts', addSubmitLogicOpts ); | |
| 10178 | - | |
| 10179 | - document.addEventListener( | |
| 10180 | - 'click', | |
| 10181 | - function handleImageUploadClickEvents( event ) { | |
| 10182 | - const { target } = event; | |
| 10183 | - | |
| 10184 | - if ( ! target.closest( '.frm_image_preview_wrapper' ) ) { | |
| 10185 | - return; | |
| 10186 | - } | |
| 10187 | - | |
| 10188 | - if ( target.closest( '.frm_choose_image_box' ) ) { | |
| 10189 | - addImageToOption.bind( target )( event ); | |
| 10190 | - return; | |
| 10191 | - } | |
| 10192 | - | |
| 10193 | - if ( target.closest( '.frm_remove_image_option' ) ) { | |
| 10194 | - removeImageFromOption.bind( target )( event ); | |
| 10195 | - } | |
| 10196 | - } | |
| 10197 | - ); | |
| 10198 | - | |
| 10199 | - // Close shortcode modal on click. | |
| 10200 | - formSettings.on( 'mouseup', '*:not(.frm-show-box)', function( e ) { | |
| 10201 | - e.stopPropagation(); | |
| 10202 | - | |
| 10203 | - if ( e.target.classList.contains( 'frm-show-box' ) || e.target.parentElement.classList.contains( 'frm-show-box' ) ) { | |
| 10204 | - return; | |
| 10205 | - } | |
| 10206 | - | |
| 10207 | - const sidebar = document.getElementById( 'frm_adv_info' ); | |
| 10208 | - if ( ! sidebar ) { | |
| 10209 | - return; | |
| 10210 | - } | |
| 10211 | - | |
| 10212 | - if ( sidebar.getAttribute( 'data-fills' ) === e.target.id && typeof e.target.id !== 'undefined' ) { | |
| 10213 | - return; | |
| 10214 | - } | |
| 10215 | - | |
| 10216 | - const isChild = jQuery( e.target ).closest( '#frm_adv_info' ).length > 0; | |
| 10217 | - | |
| 10218 | - if ( ! isChild && sidebar.display !== 'none' ) { | |
| 10219 | - hideShortcodes( sidebar ); | |
| 10220 | - } | |
| 10221 | - }); | |
| 10222 | - | |
| 10223 | - //Warning when user selects "Do not store entries ..." | |
| 10224 | - jQuery( document.getElementById( 'no_save' ) ).on( 'change', function() { | |
| 10225 | - if ( this.checked ) { | |
| 10226 | - if ( confirm( frm_admin_js.no_save_warning ) !== true ) { // eslint-disable-line camelcase | |
| 10227 | - // Uncheck box if user hits "Cancel" | |
| 10228 | - jQuery( this ).attr( 'checked', false ); | |
| 10229 | - } | |
| 10230 | - } | |
| 10231 | - }); | |
| 10232 | - | |
| 10233 | - jQuery( 'select[name="options[edit_action]"]' ).on( 'change', showSuccessOpt ); | |
| 10234 | - | |
| 10235 | - $loggedIn = document.getElementById( 'logged_in' ); | |
| 10236 | - jQuery( $loggedIn ).on( 'change', function() { | |
| 10237 | - if ( this.checked ) { | |
| 10238 | - visible( '.hide_logged_in' ); | |
| 10239 | - } else { | |
| 10240 | - invisible( '.hide_logged_in' ); | |
| 10241 | - } | |
| 10242 | - }); | |
| 10243 | - | |
| 10244 | - $cookieExp = jQuery( document.getElementById( 'frm_cookie_expiration' ) ); | |
| 10245 | - jQuery( document.getElementById( 'frm_single_entry_type' ) ).on( 'change', function() { | |
| 10246 | - if ( this.value === 'cookie' ) { | |
| 10247 | - $cookieExp.fadeIn( 'slow' ); | |
| 10248 | - } else { | |
| 10249 | - $cookieExp.fadeOut( 'slow' ); | |
| 10250 | - } | |
| 10251 | - }); | |
| 10252 | - | |
| 10253 | - var $singleEntry = document.getElementById( 'single_entry' ); | |
| 10254 | - jQuery( $singleEntry ).on( 'change', function() { | |
| 10255 | - if ( this.checked ) { | |
| 10256 | - visible( '.hide_single_entry' ); | |
| 10257 | - } else { | |
| 10258 | - invisible( '.hide_single_entry' ); | |
| 10259 | - } | |
| 10260 | - | |
| 10261 | - if ( this.checked && jQuery( document.getElementById( 'frm_single_entry_type' ) ).val() === 'cookie' ) { | |
| 10262 | - $cookieExp.fadeIn( 'slow' ); | |
| 10263 | - } else { | |
| 10264 | - $cookieExp.fadeOut( 'slow' ); | |
| 10265 | - } | |
| 10266 | - }); | |
| 10267 | - | |
| 10268 | - jQuery( '.hide_save_draft' ).hide(); | |
| 10269 | - | |
| 10270 | - var $saveDraft = jQuery( document.getElementById( 'save_draft' ) ); | |
| 10271 | - $saveDraft.on( 'change', function() { | |
| 10272 | - if ( this.checked ) { | |
| 10273 | - jQuery( '.hide_save_draft' ).fadeIn( 'slow' ); | |
| 10274 | - } else { | |
| 10275 | - jQuery( '.hide_save_draft' ).fadeOut( 'slow' ); | |
| 10276 | - } | |
| 10277 | - }); | |
| 10278 | - triggerChange( $saveDraft ); | |
| 10279 | - | |
| 10280 | - //If Allow editing is checked/unchecked | |
| 10281 | - $editable = document.getElementById( 'editable' ); | |
| 10282 | - jQuery( $editable ).on( 'change', function() { | |
| 10283 | - if ( this.checked ) { | |
| 10284 | - jQuery( '.hide_editable' ).fadeIn( 'slow' ); | |
| 10285 | - triggerChange( document.getElementById( 'edit_action' ) ); | |
| 10286 | - } else { | |
| 10287 | - jQuery( '.hide_editable' ).fadeOut( 'slow' ); | |
| 10288 | - jQuery( '.edit_action_message_box' ).fadeOut( 'slow' );//Hide On Update message box | |
| 10289 | - } | |
| 10290 | - }); | |
| 10291 | - | |
| 10292 | - //If File Protection is checked/unchecked | |
| 10293 | - jQuery( document ).on( 'change', '#protect_files', function() { | |
| 10294 | - if ( this.checked ) { | |
| 10295 | - jQuery( '.hide_protect_files' ).fadeIn( 'slow' ); | |
| 10296 | - } else { | |
| 10297 | - jQuery( '.hide_protect_files' ).fadeOut( 'slow' ); | |
| 10298 | - } | |
| 10299 | - }); | |
| 10300 | - | |
| 10301 | - jQuery( document ).on( 'frm-multiselect-changed', '#protect_files_role', adjustVisibilityValuesForEveryoneValues ); | |
| 10302 | - | |
| 10303 | - jQuery( document ).on( 'submit', '.frm_form_settings', settingsSubmitted ); | |
| 10304 | - jQuery( document ).on( 'change', '#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea', fieldUpdated ); | |
| 10305 | - | |
| 10306 | - // Page Selection Autocomplete | |
| 10307 | - initSelectionAutocomplete(); | |
| 10308 | - | |
| 10309 | - jQuery( document ).on( 'frm-action-loaded', onActionLoaded ); | |
| 10310 | - | |
| 10311 | - initOnSubmitAction(); | |
| 10312 | - }, | |
| 10313 | - | |
| 10314 | - panelInit: function() { | |
| 10315 | - var customPanel, settingsPage, viewPage, insertFieldsTab; | |
| 10316 | - | |
| 10317 | - jQuery( '.frm_wrap, #postbox-container-1' ).on( 'click', '.frm_insert_code', insertCode ); | |
| 10318 | - jQuery( document ).on( 'change', '.frm_insert_val', function() { | |
| 10319 | - insertFieldCode( jQuery( this ).data( 'target' ), jQuery( this ).val() ); | |
| 10320 | - jQuery( this ).val( '' ); | |
| 10321 | - }); | |
| 10322 | - | |
| 10323 | - jQuery( document ).on( 'click change', '#frm-id-key-condition', resetLogicBuilder ); | |
| 10324 | - jQuery( document ).on( 'keyup change', '.frm-build-logic', setLogicExample ); | |
| 10325 | - | |
| 10326 | - showInputIcon(); | |
| 10327 | - jQuery( document ).on( 'frmElementAdded', function( event, parentEle ) { | |
| 10328 | - /* This is here for add-ons to trigger */ | |
| 10329 | - showInputIcon( parentEle ); | |
| 10330 | - }); | |
| 10331 | - jQuery( document ).on( 'mousedown', '.frm-show-box', showShortcodes ); | |
| 10332 | - | |
| 10333 | - settingsPage = document.getElementById( 'form_settings_page' ); | |
| 10334 | - viewPage = document.body.classList.contains( 'post-type-frm_display' ); | |
| 10335 | - insertFieldsTab = document.getElementById( 'frm_insert_fields_tab' ); | |
| 10336 | - | |
| 10337 | - if ( settingsPage !== null || viewPage ) { | |
| 10338 | - jQuery( document ).on( 'focusin', 'form input, form textarea', function( e ) { | |
| 10339 | - var htmlTab; | |
| 10340 | - e.stopPropagation(); | |
| 10341 | - maybeShowModal( this ); | |
| 10342 | - | |
| 10343 | - if ( jQuery( this ).is( ':not(:submit, input[type=button], .frm-search-input, input[type=checkbox])' ) ) { | |
| 10344 | - if ( jQuery( e.target ).closest( '#frm_adv_info' ).length ) { | |
| 10345 | - // Don't trigger for fields inside of the modal. | |
| 10346 | - return; | |
| 10347 | - } | |
| 10348 | - | |
| 10349 | - if ( settingsPage !== null ) { | |
| 10350 | - /* form settings page */ | |
| 10351 | - htmlTab = jQuery( '#frm_html_tab' ); | |
| 10352 | - if ( jQuery( this ).closest( '#html_settings' ).length > 0 ) { | |
| 10353 | - htmlTab.show(); | |
| 10354 | - htmlTab.siblings().hide(); | |
| 10355 | - jQuery( '#frm_html_tab a' ).trigger( 'click' ); | |
| 10356 | - toggleAllowedHTML( this, e.type ); | |
| 10357 | - } else { | |
| 10358 | - showElement( jQuery( '.frm-category-tabs li' ) ); | |
| 10359 | - insertFieldsTab.click(); | |
| 10360 | - htmlTab.hide(); | |
| 10361 | - htmlTab.siblings().show(); | |
| 10362 | - } | |
| 10363 | - } else if ( viewPage ) { | |
| 10364 | - // Run on view page. | |
| 10365 | - toggleAllowedShortcodes( this.id, e.type ); | |
| 10366 | - } | |
| 10367 | - } | |
| 10368 | - }); | |
| 10369 | - } | |
| 10370 | - | |
| 10371 | - jQuery( '.frm_wrap, #postbox-container-1' ).on( 'mousedown', '#frm_adv_info a, .frm_field_list a', function( e ) { | |
| 10372 | - e.preventDefault(); | |
| 10373 | - }); | |
| 10374 | - | |
| 10375 | - customPanel = jQuery( '#frm_adv_info' ); | |
| 10376 | - customPanel.on( 'click', '.subsubsub a.frmids', function( e ) { | |
| 10377 | - toggleKeyID( 'frmids', e ); | |
| 10378 | - }); | |
| 10379 | - customPanel.on( 'click', '.subsubsub a.frmkeys', function( e ) { | |
| 10380 | - toggleKeyID( 'frmkeys', e ); | |
| 10381 | - }); | |
| 10382 | - }, | |
| 10383 | - | |
| 10384 | - viewInit: function() { | |
| 10385 | - var $addRemove, | |
| 10386 | - $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) ); | |
| 10387 | - $advInfo.before( '<div id="frm_position_ele"></div>' ); | |
| 10388 | - setupMenuOffset(); | |
| 10389 | - | |
| 10390 | - jQuery( document ).on( 'blur', '#param', checkDetailPageSlug ); | |
| 10391 | - jQuery( document ).on( 'blur', 'input[name^="options[where_val]"]', checkFilterParamNames ); | |
| 10392 | - | |
| 10393 | - // Show loading indicator. | |
| 10394 | - jQuery( '#publish' ).on( 'mousedown', function() { | |
| 10395 | - fieldsUpdated = 0; | |
| 10396 | - this.classList.add( 'frm_loading_button' ); | |
| 10397 | - }); | |
| 10398 | - | |
| 10399 | - // move content tabs | |
| 10400 | - jQuery( '#frm_dyncontent .handlediv' ).before( jQuery( '#frm_dyncontent .nav-menus-php' ) ); | |
| 10401 | - | |
| 10402 | - // click content tabs | |
| 10403 | - jQuery( '.nav-tab-wrapper a' ).on( 'click', clickContentTab ); | |
| 10404 | - | |
| 10405 | - // click tabs after panel is replaced with ajax | |
| 10406 | - jQuery( '#side-sortables' ).on( 'click', '.frm_doing_ajax.categorydiv .category-tabs a', clickTabsAfterAjax ); | |
| 10407 | - | |
| 10408 | - initToggleShortcodes(); | |
| 10409 | - jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ); | |
| 10410 | - | |
| 10411 | - jQuery( 'input[name="show_count"]' ).on( 'change', showCount ); | |
| 10412 | - | |
| 10413 | - jQuery( document.getElementById( 'form_id' ) ).on( 'change', displayFormSelected ); | |
| 10414 | - | |
| 10415 | - $addRemove = jQuery( '.frm_repeat_rows' ); | |
| 10416 | - $addRemove.on( 'click', '.frm_add_order_row', addOrderRow ); | |
| 10417 | - $addRemove.on( 'click', '.frm_add_where_row', addWhereRow ); | |
| 10418 | - $addRemove.on( 'change', '.frm_insert_where_options', insertWhereOptions ); | |
| 10419 | - $addRemove.on( 'change', '.frm_where_is_options', hideWhereOptions ); | |
| 10420 | - | |
| 10421 | - setDefaultPostStatus(); | |
| 10422 | - }, | |
| 10423 | - | |
| 10424 | - inboxInit: function() { | |
| 10425 | - jQuery( '.frm_inbox_dismiss, footer .frm-button-secondary, footer .frm-button-primary' ).on( 'click', function( e ) { | |
| 10426 | - var message = this.parentNode.parentNode, | |
| 10427 | - key = message.getAttribute( 'data-message' ), | |
| 10428 | - href = this.getAttribute( 'href' ); | |
| 10429 | - | |
| 10430 | - if ( 'free_templates' === key && ! this.classList.contains( 'frm_inbox_dismiss' ) ) { | |
| 10431 | - return; | |
| 10432 | - } | |
| 10433 | - | |
| 10434 | - e.preventDefault(); | |
| 10435 | - | |
| 10436 | - data = { | |
| 10437 | - action: 'frm_inbox_dismiss', | |
| 10438 | - key: key, | |
| 10439 | - nonce: frmGlobal.nonce | |
| 10440 | - }; | |
| 10441 | - postAjax( data, function() { | |
| 10442 | - if ( href !== '#' ) { | |
| 10443 | - window.location = href; | |
| 10444 | - return true; | |
| 10445 | - } | |
| 10446 | - fadeOut( message, function() { | |
| 10447 | - message.parentNode.removeChild( message ); | |
| 10448 | - }); | |
| 10449 | - }); | |
| 10450 | - }); | |
| 10451 | - jQuery( '#frm-dismiss-inbox' ).on( 'click', function( e ) { | |
| 10452 | - data = { | |
| 10453 | - action: 'frm_inbox_dismiss', | |
| 10454 | - key: 'all', | |
| 10455 | - nonce: frmGlobal.nonce | |
| 10456 | - }; | |
| 10457 | - postAjax( data, function() { | |
| 10458 | - fadeOut( document.getElementById( 'frm_message_list' ), function() { | |
| 10459 | - document.getElementById( 'frm_empty_inbox' ).classList.remove( 'frm_hidden' ); | |
| 10460 | - showActiveCampaignForm(); | |
| 10461 | - }); | |
| 10462 | - }); | |
| 10463 | - }); | |
| 10464 | - | |
| 10465 | - if ( ! document.getElementById( 'frm_empty_inbox' ).classList.contains( 'frm_hidden' ) ) { | |
| 10466 | - showActiveCampaignForm(); | |
| 10467 | - } | |
| 10468 | - }, | |
| 10469 | - | |
| 10470 | - solutionInit: function() { | |
| 10471 | - jQuery( document ).on( 'submit', '#frm-new-template', installTemplate ); | |
| 10472 | - }, | |
| 10473 | - | |
| 10474 | - styleInit: function() { | |
| 10475 | - const $previewWrapper = jQuery( '.frm_image_preview_wrapper' ); | |
| 10476 | - $previewWrapper.on( 'click', '.frm_choose_image_box', addImageToOption ); | |
| 10477 | - $previewWrapper.on( 'click', '.frm_remove_image_option', removeImageFromOption ); | |
| 10478 | - | |
| 10479 | - wp.hooks.doAction( 'frm_style_editor_init' ); | |
| 10480 | - }, | |
| 10481 | - | |
| 10482 | - customCSSInit: function() { | |
| 10483 | - console.warn( 'Calling frmAdminBuild.customCSSInit is deprecated.' ); | |
| 10484 | - }, | |
| 10485 | - | |
| 10486 | - globalSettingsInit: function() { | |
| 10487 | - var licenseTab; | |
| 10488 | - | |
| 10489 | - jQuery( document ).on( 'click', '[data-frmuninstall]', uninstallNow ); | |
| 10490 | - | |
| 10491 | - initiateMultiselect(); | |
| 10492 | - | |
| 10493 | - // activate addon licenses | |
| 10494 | - licenseTab = document.getElementById( 'licenses_settings' ); | |
| 10495 | - if ( licenseTab !== null ) { | |
| 10496 | - jQuery( licenseTab ).on( 'click', '.edd_frm_save_license', saveAddonLicense ); | |
| 10497 | - } | |
| 10498 | - | |
| 10499 | - // Solution install page | |
| 10500 | - jQuery( document ).on( 'click', '#frm-new-template button', installTemplateFieldset ); | |
| 10501 | - | |
| 10502 | - jQuery( '#frm-dismissable-cta .dismiss' ).on( 'click', function( event ) { | |
| 10503 | - event.preventDefault(); | |
| 10504 | - jQuery.post( ajaxurl, { | |
| 10505 | - action: 'frm_lite_settings_upgrade' | |
| 10506 | - }); | |
| 10507 | - jQuery( '.settings-lite-cta' ).remove(); | |
| 10508 | - }); | |
| 10509 | - | |
| 10510 | - const captchaType = document.getElementById( 'frm_re_type' ); | |
| 10511 | - if ( captchaType ) { | |
| 10512 | - captchaType.addEventListener( 'change', handleCaptchaTypeChange ); | |
| 10513 | - } | |
| 10514 | - | |
| 10515 | - document.querySelector( '.frm_captchas' ).addEventListener( 'change', function() { | |
| 10516 | - document.querySelector( '.captcha_settings .frm_note_style' ).classList.toggle( 'frm_hidden' ); | |
| 10517 | - }); | |
| 10518 | - }, | |
| 10519 | - | |
| 10520 | - exportInit: function() { | |
| 10521 | - jQuery( '.frm_form_importer' ).on( 'submit', startFormMigration ); | |
| 10522 | - jQuery( document.getElementById( 'frm_export_xml' ) ).on( 'submit', validateExport ); | |
| 10523 | - jQuery( '#frm_export_xml input, #frm_export_xml select' ).on( 'change', removeExportError ); | |
| 10524 | - jQuery( 'input[name="frm_import_file"]' ).on( 'change', checkCSVExtension ); | |
| 10525 | - document.querySelector( 'select[name="format"]' ).addEventListener( 'change', exportTypeChanged ); | |
| 10526 | - | |
| 10527 | - jQuery( 'input[name="frm_export_forms[]"]' ).on( 'click', preventMultipleExport ); | |
| 10528 | - initiateMultiselect(); | |
| 10529 | - | |
| 10530 | - jQuery( '.frm-feature-banner .dismiss' ).on( 'click', function( event ) { | |
| 10531 | - event.preventDefault(); | |
| 10532 | - jQuery.post( ajaxurl, { | |
| 10533 | - action: 'frm_dismiss_migrator', | |
| 10534 | - plugin: this.id, | |
| 10535 | - nonce: frmGlobal.nonce | |
| 10536 | - }); | |
| 10537 | - this.parentElement.remove(); | |
| 10538 | - }); | |
| 10539 | - | |
| 10540 | - showOrHideRepeaters( getExportOption() ); | |
| 10541 | - | |
| 10542 | - document.querySelector( '#frm-export-select-all' ).addEventListener( 'change', event => { | |
| 10543 | - document.querySelectorAll( '[name="frm_export_forms[]"]' ).forEach( cb => cb.checked = event.target.checked ); | |
| 10544 | - }); | |
| 10545 | - }, | |
| 10546 | - | |
| 10547 | - inboxBannerInit: function() { | |
| 10548 | - const banner = document.getElementById( 'frm_banner' ); | |
| 10549 | - if ( ! banner ) { | |
| 10550 | - return; | |
| 10551 | - } | |
| 10552 | - | |
| 10553 | - const dismissButton = banner.querySelector( '.frm-banner-dismiss' ); | |
| 10554 | - document.addEventListener( | |
| 10555 | - 'click', | |
| 10556 | - function( event ) { | |
| 10557 | - if ( event.target !== dismissButton ) { | |
| 10558 | - return; | |
| 10559 | - } | |
| 10560 | - | |
| 10561 | - const data = { | |
| 10562 | - action: 'frm_inbox_dismiss', | |
| 10563 | - key: banner.dataset.key, | |
| 10564 | - nonce: frmGlobal.nonce | |
| 10565 | - }; | |
| 10566 | - postAjax( | |
| 10567 | - data, | |
| 10568 | - function() { | |
| 10569 | - jQuery( banner ).fadeOut( | |
| 10570 | - 400, | |
| 10571 | - function() { | |
| 10572 | - banner.remove(); | |
| 10573 | - } | |
| 10574 | - ); | |
| 10575 | - } | |
| 10576 | - ); | |
| 10577 | - } | |
| 10578 | - ); | |
| 10579 | - }, | |
| 10580 | - | |
| 10581 | - updateOpts: function( fieldId, opts, modal ) { | |
| 10582 | - var separate = usingSeparateValues( fieldId ), | |
| 10583 | - action = isProductField( fieldId ) ? 'frm_bulk_products' : 'frm_import_options'; | |
| 10584 | - jQuery.ajax({ | |
| 10585 | - type: 'POST', | |
| 10586 | - url: ajaxurl, | |
| 10587 | - data: { | |
| 10588 | - action: action, | |
| 10589 | - field_id: fieldId, | |
| 10590 | - opts: opts, | |
| 10591 | - separate: separate, | |
| 10592 | - nonce: frmGlobal.nonce | |
| 10593 | - }, | |
| 10594 | - success: function( html ) { | |
| 10595 | - document.getElementById( 'frm_field_' + fieldId + '_opts' ).innerHTML = html; | |
| 10596 | - resetDisplayedOpts( fieldId ); | |
| 10597 | - | |
| 10598 | - if ( typeof modal !== 'undefined' ) { | |
| 10599 | - modal.dialog( 'close' ); | |
| 10600 | - document.getElementById( 'frm-update-bulk-opts' ).classList.remove( 'frm_loading_button' ); | |
| 10601 | - } | |
| 10602 | - } | |
| 10603 | - }); | |
| 10604 | - }, | |
| 10605 | - | |
| 10606 | - /* remove conditional logic if the field doesn't exist */ | |
| 10607 | - triggerRemoveLogic: function( fieldID, metaName ) { | |
| 10608 | - jQuery( '#frm_logic_' + fieldID + '_' + metaName + ' .frm_remove_tag' ).trigger( 'click' ); | |
| 10609 | - }, | |
| 10610 | - | |
| 10611 | - downloadXML: function( controller, ids, isTemplate ) { | |
| 10612 | - var url = ajaxurl + '?action=frm_' + controller + '_xml&ids=' + ids; | |
| 10613 | - if ( isTemplate !== null ) { | |
| 10614 | - url = url + '&is_template=' + isTemplate; | |
| 10615 | - } | |
| 10616 | - location.href = url; | |
| 10617 | - }, | |
| 10618 | - | |
| 10619 | - /** | |
| 10620 | - * @since 5.0.04 | |
| 10621 | - */ | |
| 10622 | - hooks: { | |
| 10623 | - applyFilters: function( hookName, ...args ) { | |
| 10624 | - return wp.hooks.applyFilters( hookName, ...args ); | |
| 10625 | - }, | |
| 10626 | - addFilter: function( hookName, callback, priority ) { | |
| 10627 | - return wp.hooks.addFilter( hookName, 'formidable', callback, priority ); | |
| 10628 | - }, | |
| 10629 | - doAction: function( hookName, ...args ) { | |
| 10630 | - return wp.hooks.doAction( hookName, ...args ); | |
| 10631 | - }, | |
| 10632 | - addAction: function( hookName, callback, priority ) { | |
| 10633 | - return wp.hooks.addAction( hookName, 'formidable', callback, priority ); | |
| 10634 | - } | |
| 10635 | - }, | |
| 10636 | - | |
| 10637 | - infoModal: infoModal, | |
| 10638 | - adjustConditionalLogicOptionOrders: adjustConditionalLogicOptionOrders, | |
| 10639 | - addRadioCheckboxOpt: addRadioCheckboxOpt | |
| 10640 | - }; | |
| 10641 | -} | |
| 10642 | - | |
| 10643 | -frmAdminBuild = frmAdminBuildJS(); | |
| 10644 | - | |
| 10645 | -jQuery( document ).ready( | |
| 10646 | - () => { | |
| 10647 | - frmAdminBuild.init(); | |
| 10648 | - | |
| 10649 | - frmDom.bootstrap.setupBootstrapDropdowns( convertOldBootstrapDropdownsToBootstrap4 ); | |
| 10650 | - document.querySelector( '.preview.dropdown .frm-dropdown-toggle' )?.setAttribute( 'data-toggle', 'dropdown' ); | |
| 10651 | - | |
| 10652 | - function convertOldBootstrapDropdownsToBootstrap4( frmDropdownMenu ) { | |
| 10653 | - const toggle = frmDropdownMenu.querySelector( '.frm-dropdown-toggle' ); | |
| 10654 | - if ( toggle ) { | |
| 10655 | - if ( ! toggle.hasAttribute( 'role' ) ) { | |
| 10656 | - toggle.setAttribute( 'role', 'button' ); | |
| 10657 | - } | |
| 10658 | - if ( ! toggle.hasAttribute( 'tabindex' ) ) { | |
| 10659 | - toggle.setAttribute( 'tabindex', 0 ); | |
| 10660 | - } | |
| 10661 | - } | |
| 10662 | - | |
| 10663 | - // Convert <li> and <ul> tags. | |
| 10664 | - if ( 'UL' === frmDropdownMenu.tagName ) { | |
| 10665 | - convertBootstrapUl( frmDropdownMenu ); | |
| 10666 | - } | |
| 10667 | - } | |
| 10668 | - | |
| 10669 | - function convertBootstrapUl( ul ) { | |
| 10670 | - let html = ul.outerHTML; | |
| 10671 | - html = html.replace( '<ul ', '<div ' ); | |
| 10672 | - html = html.replace( '</ul>', '</div>' ); | |
| 10673 | - html = html.replaceAll( '<li>', '<div class="dropdown-item">' ); | |
| 10674 | - html = html.replaceAll( '<li class="', '<div class="dropdown-item ' ); | |
| 10675 | - html = html.replaceAll( '</li>', '</div>' ); | |
| 10676 | - ul.outerHTML = html; | |
| 10677 | - } | |
| 10678 | - } | |
| 10679 | -); | |
| 10680 | - | |
| 10681 | -function frm_remove_tag( htmlTag ) { // eslint-disable-line camelcase | |
| 10682 | - console.warn( 'DEPRECATED: function frm_remove_tag in v2.0' ); | |
| 10683 | - jQuery( htmlTag ).remove(); | |
| 10684 | -} | |
| 10685 | - | |
| 10686 | -function frm_show_div( div, value, showIf, classId ) { // eslint-disable-line camelcase | |
| 10687 | - if ( value == showIf ) { | |
| 10688 | - jQuery( classId + div ).fadeIn( 'slow' ).css( 'visibility', 'visible' ); | |
| 10689 | - } else { | |
| 10690 | - jQuery( classId + div ).fadeOut( 'slow' ); | |
| 10691 | - } | |
| 10692 | -} | |
| 10693 | - | |
| 10694 | -function frmCheckAll( checked, n ) { | |
| 10695 | - jQuery( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked ); | |
| 10696 | -} | |
| 10697 | - | |
| 10698 | -function frmCheckAllLevel( checked, n, level ) { | |
| 10699 | - var $kids = jQuery( '.frm_catlevel_' + level ).children( '.frm_checkbox' ).children( 'label' ); | |
| 10700 | - $kids.children( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked ); | |
| 10701 | -} | |
| 10702 | - | |
| 10703 | -function frm_add_logic_row( id, formId ) { // eslint-disable-line camelcase | |
| 10704 | - console.warn( 'DEPRECATED: function frm_add_logic_row in v2.0' ); | |
| 10705 | - jQuery.ajax({ | |
| 10706 | - type: 'POST', | |
| 10707 | - url: ajaxurl, | |
| 10708 | - data: { | |
| 10709 | - action: 'frm_add_logic_row', | |
| 10710 | - form_id: formId, | |
| 10711 | - field_id: id, | |
| 10712 | - meta_name: jQuery( '#frm_logic_row_' + id + ' > div' ).length, | |
| 10713 | - nonce: frmGlobal.nonce | |
| 10714 | - }, | |
| 10715 | - success: function( html ) { | |
| 10716 | - jQuery( '#frm_logic_row_' + id ).append( html ); | |
| 10717 | - } | |
| 10718 | - }); | |
| 10719 | - return false; | |
| 10720 | -} | |
| 10721 | - | |
| 10722 | -function frmGetFieldValues( fieldId, cur, rowNumber, fieldType, htmlName ) { | |
| 10723 | - | |
| 10724 | - if ( fieldId ) { | |
| 10725 | - jQuery.ajax({ | |
| 10726 | - type: 'POST', url: ajaxurl, | |
| 10727 | - data: 'action=frm_get_field_values¤t_field=' + cur + '&field_id=' + fieldId + '&name=' + htmlName + '&t=' + fieldType + '&form_action=' + jQuery( 'input[name="frm_action"]' ).val() + '&nonce=' + frmGlobal.nonce, | |
| 10728 | - success: function( msg ) { | |
| 10729 | - document.getElementById( 'frm_show_selected_values_' + cur + '_' + rowNumber ).innerHTML = msg; | |
| 10730 | - } | |
| 10731 | - }); | |
| 10732 | - } | |
| 10733 | -} | |
| 10734 | - | |
| 10735 | -function frmImportCsv( formID ) { | |
| 10736 | - var urlVars = ''; | |
| 10737 | - if ( typeof __FRMURLVARS !== 'undefined' ) { | |
| 10738 | - urlVars = __FRMURLVARS; | |
| 10739 | - } | |
| 10740 | - | |
| 10741 | - jQuery.ajax({ | |
| 10742 | - type: 'POST', url: ajaxurl, | |
| 10743 | - data: 'action=frm_import_csv&nonce=' + frmGlobal.nonce + '&frm_skip_cookie=1' + urlVars, | |
| 10744 | - success: function( count ) { | |
| 10745 | - var max = jQuery( '.frm_admin_progress_bar' ).attr( 'aria-valuemax' ); | |
| 10746 | - var imported = max - count; | |
| 10747 | - var percent = ( imported / max ) * 100; | |
| 10748 | - jQuery( '.frm_admin_progress_bar' ).css( 'width', percent + '%' ).attr( 'aria-valuenow', imported ); | |
| 10749 | - | |
| 10750 | - if ( parseInt( count, 10 ) > 0 ) { | |
| 10751 | - jQuery( '.frm_csv_remaining' ).html( count ); | |
| 10752 | - frmImportCsv( formID ); | |
| 10753 | - } else { | |
| 10754 | - jQuery( document.getElementById( 'frm_import_message' ) ).html( frm_admin_js.import_complete ); // eslint-disable-line camelcase | |
| 10755 | - setTimeout( function() { | |
| 10756 | - location.href = '?page=formidable-entries&frm_action=list&form=' + formID + '&import-message=1'; | |
| 10757 | - }, 2000 ); | |
| 10758 | - } | |
| 10759 | - } | |
| 10760 | - }); | |
| 10761 | -} | |
| 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&>(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¤t_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))}})}})(); | |