| @@ -1,10572 +1 @@ | ||
| 1 | -/* exported frm_add_logic_row, frm_remove_tag, frm_show_div, frmCheckAll, frmCheckAllLevel */ | |
| 2 | - | |
| 3 | -var frmAdminBuild; | |
| 4 | - | |
| 5 | -var FrmFormsConnect = window.FrmFormsConnect || ( function( document, window, $ ) { | |
| 6 | - | |
| 7 | - /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl */ | |
| 8 | - | |
| 9 | - var el = { | |
| 10 | - licenseBox: document.getElementById( 'frm_license_top' ), | |
| 11 | - messageBox: document.getElementsByClassName( 'frm_pro_license_msg' )[0], | |
| 12 | - btn: document.getElementById( 'frm-settings-connect-btn' ), | |
| 13 | - reset: document.getElementById( 'frm_reconnect_link' ) | |
| 14 | - }; | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * Public functions and properties. | |
| 18 | - * | |
| 19 | - * @since 4.03 | |
| 20 | - * | |
| 21 | - * @type {Object} | |
| 22 | - */ | |
| 23 | - var app = { | |
| 24 | - | |
| 25 | - /** | |
| 26 | - * Register connect button event. | |
| 27 | - * | |
| 28 | - * @since 4.03 | |
| 29 | - */ | |
| 30 | - init: function() { | |
| 31 | - $( document.getElementById( 'frm_deauthorize_link' ) ).on( 'click', app.deauthorize ); | |
| 32 | - $( '.frm_authorize_link' ).on( 'click', app.authorize ); | |
| 33 | - if ( el.reset !== null ) { | |
| 34 | - $( el.reset ).on( 'click', app.reauthorize ); | |
| 35 | - } | |
| 36 | - | |
| 37 | - $( el.btn ).on( 'click', function( e ) { | |
| 38 | - e.preventDefault(); | |
| 39 | - app.gotoUpgradeUrl(); | |
| 40 | - }); | |
| 41 | - | |
| 42 | - window.addEventListener( 'message', function( msg ) { | |
| 43 | - if ( msg.origin.replace( /\/$/, '' ) !== frmGlobal.app_url.replace( /\/$/, '' ) ) { | |
| 44 | - return; | |
| 45 | - } | |
| 46 | - | |
| 47 | - if ( ! msg.data || 'object' !== typeof msg.data ) { | |
| 48 | - console.error( 'Messages from "' + frmGlobal.app_url + '" must contain an api key string.' ); | |
| 49 | - return; | |
| 50 | - } | |
| 51 | - | |
| 52 | - app.updateForm( msg.data ); | |
| 53 | - }); | |
| 54 | - | |
| 55 | - jQuery( document ).on( 'mouseover', '#frm_new_form_modal .frm-selectable', function() { | |
| 56 | - var $item = jQuery( this ), | |
| 57 | - $icons = $item.find( '.frm-hover-icons' ), | |
| 58 | - $clone; | |
| 59 | - | |
| 60 | - if ( ! $icons.length ) { | |
| 61 | - $clone = jQuery( '#frm-hover-icons-template' ).clone(); | |
| 62 | - $clone.removeAttr( 'id' ); | |
| 63 | - $item.append( $clone ); | |
| 64 | - } | |
| 65 | - | |
| 66 | - $icons.show(); | |
| 67 | - }); | |
| 68 | - | |
| 69 | - jQuery( document ).on( 'mouseout', '#frm_new_form_modal .frm-selectable', function() { | |
| 70 | - var $item = jQuery( this ), | |
| 71 | - $icons = $item.find( '.frm-hover-icons' ); | |
| 72 | - | |
| 73 | - if ( $icons.length ) { | |
| 74 | - $icons.hide(); | |
| 75 | - } | |
| 76 | - }); | |
| 77 | - }, | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * Go to upgrade url. | |
| 81 | - * | |
| 82 | - * @since 4.03 | |
| 83 | - */ | |
| 84 | - gotoUpgradeUrl: function() { | |
| 85 | - var w = window.open( frmGlobal.app_url + '/api-connect/', '_blank', 'location=no,width=500,height=730,scrollbars=0' ); | |
| 86 | - w.focus(); | |
| 87 | - }, | |
| 88 | - | |
| 89 | - updateForm: function( response ) { | |
| 90 | - | |
| 91 | - // Start spinner. | |
| 92 | - var btn = el.btn; | |
| 93 | - btn.classList.add( 'frm_loading_button' ); | |
| 94 | - | |
| 95 | - if ( response.url !== '' ) { | |
| 96 | - app.showProgress({ | |
| 97 | - success: true, | |
| 98 | - message: 'Installing...' | |
| 99 | - }); | |
| 100 | - var fallback = setTimeout( function() { | |
| 101 | - app.showProgress({ | |
| 102 | - success: true, | |
| 103 | - message: 'Installing is taking longer than expected. <a class="frm-install-addon button button-primary frm-button-primary" rel="' + response.url + '" aria-label="Install">Install Now</a>' | |
| 104 | - }); | |
| 105 | - }, 10000 ); | |
| 106 | - $.ajax({ | |
| 107 | - type: 'POST', | |
| 108 | - url: ajaxurl, | |
| 109 | - dataType: 'json', | |
| 110 | - data: { | |
| 111 | - action: 'frm_connect', | |
| 112 | - plugin: response.url, | |
| 113 | - nonce: frmGlobal.nonce | |
| 114 | - }, | |
| 115 | - success: function() { | |
| 116 | - clearTimeout( fallback ); | |
| 117 | - app.activateKey( response ); | |
| 118 | - }, | |
| 119 | - error: function( xhr, textStatus, e ) { | |
| 120 | - clearTimeout( fallback ); | |
| 121 | - btn.classList.remove( 'frm_loading_button' ); | |
| 122 | - app.showMessage({ | |
| 123 | - success: false, | |
| 124 | - message: e | |
| 125 | - }); | |
| 126 | - } | |
| 127 | - }); | |
| 128 | - } else if ( response.key !== '' ) { | |
| 129 | - app.activateKey( response ); | |
| 130 | - } | |
| 131 | - }, | |
| 132 | - | |
| 133 | - activateKey: function( response ) { | |
| 134 | - var btn = el.btn; | |
| 135 | - if ( response.key === '' ) { | |
| 136 | - btn.classList.remove( 'frm_loading_button' ); | |
| 137 | - } else { | |
| 138 | - app.showProgress({ | |
| 139 | - success: true, | |
| 140 | - message: 'Activating...' | |
| 141 | - }); | |
| 142 | - $.ajax({ | |
| 143 | - type: 'POST', | |
| 144 | - url: ajaxurl, | |
| 145 | - dataType: 'json', | |
| 146 | - data: { | |
| 147 | - action: 'frm_addon_activate', | |
| 148 | - license: response.key, | |
| 149 | - plugin: 'formidable_pro', | |
| 150 | - wpmu: 0, | |
| 151 | - nonce: frmGlobal.nonce | |
| 152 | - }, | |
| 153 | - success: function( msg ) { | |
| 154 | - btn.classList.remove( 'frm_loading_button' ); | |
| 155 | - | |
| 156 | - if ( msg.success === true ) { | |
| 157 | - el.licenseBox.classList.replace( 'frm_unauthorized_box', 'frm_authorized_box' ); | |
| 158 | - } | |
| 159 | - | |
| 160 | - app.showMessage( msg ); | |
| 161 | - }, | |
| 162 | - error: function( xhr, textStatus, e ) { | |
| 163 | - btn.classList.remove( 'frm_loading_button' ); | |
| 164 | - app.showMessage({ | |
| 165 | - success: false, | |
| 166 | - message: e | |
| 167 | - }); | |
| 168 | - } | |
| 169 | - }); | |
| 170 | - } | |
| 171 | - }, | |
| 172 | - | |
| 173 | - /* Manual license authorization */ | |
| 174 | - authorize: function() { | |
| 175 | - /*jshint validthis:true */ | |
| 176 | - var button = this; | |
| 177 | - var pluginSlug = this.getAttribute( 'data-plugin' ); | |
| 178 | - var input = document.getElementById( 'edd_' + pluginSlug + '_license_key' ); | |
| 179 | - var license = input.value; | |
| 180 | - var wpmu = document.getElementById( 'proplug-wpmu' ); | |
| 181 | - this.classList.add( 'frm_loading_button' ); | |
| 182 | - if ( wpmu === null ) { | |
| 183 | - wpmu = 0; | |
| 184 | - } else if ( wpmu.checked ) { | |
| 185 | - wpmu = 1; | |
| 186 | - } else { | |
| 187 | - wpmu = 0; | |
| 188 | - } | |
| 189 | - | |
| 190 | - $.ajax({ | |
| 191 | - type: 'POST', url: ajaxurl, dataType: 'json', | |
| 192 | - data: { | |
| 193 | - action: 'frm_addon_activate', | |
| 194 | - license: license, | |
| 195 | - plugin: pluginSlug, | |
| 196 | - wpmu: wpmu, | |
| 197 | - nonce: frmGlobal.nonce | |
| 198 | - }, | |
| 199 | - success: function( msg ) { | |
| 200 | - app.afterAuthorize( msg, input ); | |
| 201 | - button.classList.remove( 'frm_loading_button' ); | |
| 202 | - } | |
| 203 | - }); | |
| 204 | - }, | |
| 205 | - | |
| 206 | - afterAuthorize: function( msg, input ) { | |
| 207 | - if ( msg.success === true ) { | |
| 208 | - input.value = '•••••••••••••••••••'; | |
| 209 | - } | |
| 210 | - | |
| 211 | - app.showMessage( msg ); | |
| 212 | - }, | |
| 213 | - | |
| 214 | - showProgress: function( msg ) { | |
| 215 | - var messageBox = el.messageBox; | |
| 216 | - if ( msg.success === true ) { | |
| 217 | - messageBox.classList.remove( 'frm_error_style' ); | |
| 218 | - messageBox.classList.add( 'frm_message', 'frm_updated_message' ); | |
| 219 | - } else { | |
| 220 | - messageBox.classList.add( 'frm_error_style' ); | |
| 221 | - messageBox.classList.remove( 'frm_message', 'frm_updated_message' ); | |
| 222 | - } | |
| 223 | - messageBox.classList.remove( 'frm_hidden' ); | |
| 224 | - messageBox.innerHTML = msg.message; | |
| 225 | - }, | |
| 226 | - | |
| 227 | - showMessage: function( msg ) { | |
| 228 | - var messageBox = el.messageBox; | |
| 229 | - | |
| 230 | - if ( msg.success === true ) { | |
| 231 | - var d = el.licenseBox; | |
| 232 | - d.className = d.className.replace( 'frm_unauthorized_box', 'frm_authorized_box' ); | |
| 233 | - messageBox.classList.remove( 'frm_error_style' ); | |
| 234 | - messageBox.classList.add( 'frm_message', 'frm_updated_message' ); | |
| 235 | - } else { | |
| 236 | - messageBox.classList.add( 'frm_error_style' ); | |
| 237 | - messageBox.classList.remove( 'frm_message', 'frm_updated_message' ); | |
| 238 | - } | |
| 239 | - | |
| 240 | - messageBox.classList.remove( 'frm_hidden' ); | |
| 241 | - messageBox.innerHTML = msg.message; | |
| 242 | - if ( msg.message !== '' ) { | |
| 243 | - setTimeout( function() { | |
| 244 | - messageBox.innerHTML = ''; | |
| 245 | - messageBox.classList.add( 'frm_hidden' ); | |
| 246 | - messageBox.classList.remove( 'frm_error_style', 'frm_message', 'frm_updated_message' ); | |
| 247 | - }, 10000 ); | |
| 248 | - var refreshPage = document.querySelectorAll( '#frm-welcome' ); | |
| 249 | - if ( refreshPage.length > 0 ) { | |
| 250 | - window.location.reload(); | |
| 251 | - } | |
| 252 | - } | |
| 253 | - }, | |
| 254 | - | |
| 255 | - /* Clear the site license cache */ | |
| 256 | - reauthorize: function() { | |
| 257 | - /*jshint validthis:true */ | |
| 258 | - this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;float:none"></span>'; | |
| 259 | - | |
| 260 | - $.ajax({ | |
| 261 | - type: 'POST', | |
| 262 | - url: ajaxurl, | |
| 263 | - dataType: 'json', | |
| 264 | - data: { | |
| 265 | - action: 'frm_reset_cache', | |
| 266 | - plugin: 'formidable_pro', | |
| 267 | - nonce: frmGlobal.nonce | |
| 268 | - }, | |
| 269 | - success: function( msg ) { | |
| 270 | - el.reset.textContent = msg.message; | |
| 271 | - if ( el.reset.getAttribute( 'data-refresh' ) === '1' ) { | |
| 272 | - window.location.reload(); | |
| 273 | - } | |
| 274 | - } | |
| 275 | - }); | |
| 276 | - return false; | |
| 277 | - }, | |
| 278 | - | |
| 279 | - deauthorize: function() { | |
| 280 | - /*jshint validthis:true */ | |
| 281 | - if ( ! confirm( frmGlobal.deauthorize ) ) { | |
| 282 | - return false; | |
| 283 | - } | |
| 284 | - var pluginSlug = this.getAttribute( 'data-plugin' ), | |
| 285 | - input = document.getElementById( 'edd_' + pluginSlug + '_license_key' ), | |
| 286 | - license = input.value, | |
| 287 | - link = this; | |
| 288 | - | |
| 289 | - this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;"></span>'; | |
| 290 | - | |
| 291 | - $.ajax({ | |
| 292 | - type: 'POST', | |
| 293 | - url: ajaxurl, | |
| 294 | - data: { | |
| 295 | - action: 'frm_addon_deactivate', | |
| 296 | - license: license, | |
| 297 | - plugin: pluginSlug, | |
| 298 | - nonce: frmGlobal.nonce | |
| 299 | - }, | |
| 300 | - success: function() { | |
| 301 | - el.licenseBox.className = el.licenseBox.className.replace( 'frm_authorized_box', 'frm_unauthorized_box' ); | |
| 302 | - input.value = ''; | |
| 303 | - link.innerHTML = ''; | |
| 304 | - } | |
| 305 | - }); | |
| 306 | - return false; | |
| 307 | - } | |
| 308 | - }; | |
| 309 | - | |
| 310 | - // Provide access to public functions/properties. | |
| 311 | - return app; | |
| 312 | - | |
| 313 | -}( document, window, jQuery ) ); | |
| 314 | - | |
| 315 | -function frmAdminBuildJS() { | |
| 316 | - //'use strict'; | |
| 317 | - | |
| 318 | - /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl, fromDom */ | |
| 319 | - | |
| 320 | - const { tag, div, span, a, svg, img } = frmDom; | |
| 321 | - const { onClickPreventDefault } = frmDom.util; | |
| 322 | - const { doJsonFetch, doJsonPost } = frmDom.ajax; | |
| 323 | - const icons = { | |
| 324 | - save: svg({ href: '#frm_save_icon' }), | |
| 325 | - drag: svg({ href: '#frm_drag_icon', classList: [ 'frm_drag_icon', 'frm-drag' ] }) | |
| 326 | - }; | |
| 327 | - | |
| 328 | - let $newFields = jQuery( document.getElementById( 'frm-show-fields' ) ), | |
| 329 | - builderForm = document.getElementById( 'new_fields' ), | |
| 330 | - thisForm = document.getElementById( 'form_id' ), | |
| 331 | - copyHelper = false, | |
| 332 | - fieldsUpdated = 0, | |
| 333 | - thisFormId = 0, | |
| 334 | - autoId = 0, | |
| 335 | - optionMap = {}, | |
| 336 | - lastNewActionIdReturned = 0; | |
| 337 | - | |
| 338 | - const { __ } = wp.i18n; | |
| 339 | - let debouncedSyncAfterDragAndDrop, postBodyContent, $postBodyContent; | |
| 340 | - | |
| 341 | - if ( thisForm !== null ) { | |
| 342 | - thisFormId = thisForm.value; | |
| 343 | - } | |
| 344 | - | |
| 345 | - // Global settings | |
| 346 | - var s; | |
| 347 | - | |
| 348 | - function showElement( element ) { | |
| 349 | - element[0].style.display = ''; | |
| 350 | - } | |
| 351 | - | |
| 352 | - function hideElement( element ) { | |
| 353 | - element[0].style.display = 'none'; | |
| 354 | - } | |
| 355 | - | |
| 356 | - function empty( $obj ) { | |
| 357 | - if ( $obj !== null ) { | |
| 358 | - while ( $obj.firstChild ) { | |
| 359 | - $obj.removeChild( $obj.firstChild ); | |
| 360 | - } | |
| 361 | - } | |
| 362 | - } | |
| 363 | - | |
| 364 | - function addClass( $obj, className ) { | |
| 365 | - if ( $obj.classList ) { | |
| 366 | - $obj.classList.add( className ); | |
| 367 | - } else { | |
| 368 | - $obj.className += ' ' + className; | |
| 369 | - } | |
| 370 | - } | |
| 371 | - | |
| 372 | - function confirmClick( e ) { | |
| 373 | - /*jshint validthis:true */ | |
| 374 | - e.stopPropagation(); | |
| 375 | - e.preventDefault(); | |
| 376 | - confirmLinkClick( this ); | |
| 377 | - } | |
| 378 | - | |
| 379 | - function confirmLinkClick( link ) { | |
| 380 | - var message = link.getAttribute( 'data-frmverify' ); | |
| 381 | - | |
| 382 | - if ( message === null || link.id === 'frm-confirmed-click' ) { | |
| 383 | - return true; | |
| 384 | - } else { | |
| 385 | - return confirmModal( link ); | |
| 386 | - } | |
| 387 | - } | |
| 388 | - | |
| 389 | - function confirmModal( link ) { | |
| 390 | - var verify, $confirmMessage, i, dataAtts, btnClass, | |
| 391 | - $info = initModal( '#frm_confirm_modal', '400px' ), | |
| 392 | - continueButton = document.getElementById( 'frm-confirmed-click' ); | |
| 393 | - | |
| 394 | - if ( $info === false ) { | |
| 395 | - return false; | |
| 396 | - } | |
| 397 | - | |
| 398 | - verify = link.getAttribute( 'data-frmverify' ); | |
| 399 | - btnClass = verify ? link.getAttribute( 'data-frmverify-btn' ) : ''; | |
| 400 | - $confirmMessage = jQuery( '.frm-confirm-msg' ); | |
| 401 | - $confirmMessage.empty(); | |
| 402 | - | |
| 403 | - if ( verify ) { | |
| 404 | - $confirmMessage.append( document.createTextNode( verify ) ); | |
| 405 | - if ( btnClass ) { | |
| 406 | - continueButton.classList.add( btnClass ); | |
| 407 | - } | |
| 408 | - } | |
| 409 | - | |
| 410 | - removeAtts = continueButton.dataset; | |
| 411 | - for ( i in dataAtts ) { | |
| 412 | - continueButton.removeAttribute( 'data-' + i ); | |
| 413 | - } | |
| 414 | - | |
| 415 | - dataAtts = link.dataset; | |
| 416 | - for ( i in dataAtts ) { | |
| 417 | - if ( i !== 'frmverify' ) { | |
| 418 | - continueButton.setAttribute( 'data-' + i, dataAtts[i]); | |
| 419 | - } | |
| 420 | - } | |
| 421 | - | |
| 422 | - $info.dialog( 'open' ); | |
| 423 | - continueButton.setAttribute( 'href', link.getAttribute( 'href' ) ); | |
| 424 | - return false; | |
| 425 | - } | |
| 426 | - | |
| 427 | - function infoModal( msg ) { | |
| 428 | - var $info = initModal( '#frm_info_modal', '400px' ); | |
| 429 | - | |
| 430 | - if ( $info === false ) { | |
| 431 | - return false; | |
| 432 | - } | |
| 433 | - | |
| 434 | - jQuery( '.frm-info-msg' ).html( msg ); | |
| 435 | - | |
| 436 | - $info.dialog( 'open' ); | |
| 437 | - return false; | |
| 438 | - } | |
| 439 | - | |
| 440 | - function toggleItem( e ) { | |
| 441 | - /*jshint validthis:true */ | |
| 442 | - var toggle = this.getAttribute( 'data-frmtoggle' ), | |
| 443 | - text = this.getAttribute( 'data-toggletext' ), | |
| 444 | - items = jQuery( toggle ); | |
| 445 | - | |
| 446 | - e.preventDefault(); | |
| 447 | - | |
| 448 | - if ( items.is( ':visible' ) ) { | |
| 449 | - items.show(); | |
| 450 | - } else { | |
| 451 | - items.hide(); | |
| 452 | - } | |
| 453 | - | |
| 454 | - if ( text !== null && text !== '' ) { | |
| 455 | - this.setAttribute( 'data-toggletext', this.innerHTML ); | |
| 456 | - this.textContent = text; | |
| 457 | - } | |
| 458 | - | |
| 459 | - return false; | |
| 460 | - } | |
| 461 | - | |
| 462 | - /** | |
| 463 | - * Toggle a class on target elements when an anchor is clicked, or when a radio or checkbox has been selected. | |
| 464 | - * | |
| 465 | - * @param {Event} e Event with either the change or click type. | |
| 466 | - * @returns {false} | |
| 467 | - */ | |
| 468 | - function hideShowItem( e ) { | |
| 469 | - /*jshint validthis:true */ | |
| 470 | - let hide = this.getAttribute( 'data-frmhide' ); | |
| 471 | - let show = this.getAttribute( 'data-frmshow' ); | |
| 472 | - | |
| 473 | - // Flip unchecked checkboxes so an off value undoes the on value. | |
| 474 | - if ( isUncheckedCheckbox( this ) ) { | |
| 475 | - if ( hide !== null ) { | |
| 476 | - show = hide; | |
| 477 | - hide = null; | |
| 478 | - } else if ( show !== null ) { | |
| 479 | - hide = show; | |
| 480 | - show = null; | |
| 481 | - } | |
| 482 | - } | |
| 483 | - | |
| 484 | - e.preventDefault(); | |
| 485 | - | |
| 486 | - const toggleClass = this.getAttribute( 'data-toggleclass' ) || 'frm_hidden'; | |
| 487 | - | |
| 488 | - if ( hide !== null ) { | |
| 489 | - jQuery( hide ).addClass( toggleClass ); | |
| 490 | - } | |
| 491 | - | |
| 492 | - if ( show !== null ) { | |
| 493 | - jQuery( show ).removeClass( toggleClass ); | |
| 494 | - } | |
| 495 | - | |
| 496 | - var current = this.parentNode.querySelectorAll( 'a.current' ); | |
| 497 | - if ( current !== null ) { | |
| 498 | - for ( var i = 0; i < current.length; i++ ) { | |
| 499 | - current[ i ].classList.remove( 'current' ); | |
| 500 | - } | |
| 501 | - this.classList.add( 'current' ); | |
| 502 | - } | |
| 503 | - | |
| 504 | - return false; | |
| 505 | - } | |
| 506 | - | |
| 507 | - function isUncheckedCheckbox( element ) { | |
| 508 | - return 'INPUT' === element.nodeName && 'checkbox' === element.type && ! element.checked; | |
| 509 | - } | |
| 510 | - | |
| 511 | - function setupMenuOffset() { | |
| 512 | - window.onscroll = document.documentElement.onscroll = setMenuOffset; | |
| 513 | - setMenuOffset(); | |
| 514 | - } | |
| 515 | - | |
| 516 | - function setMenuOffset() { | |
| 517 | - var fields = document.getElementById( 'frm_adv_info' ); | |
| 518 | - if ( fields === null ) { | |
| 519 | - return; | |
| 520 | - } | |
| 521 | - | |
| 522 | - var currentOffset = document.documentElement.scrollTop || document.body.scrollTop; // body for Safari | |
| 523 | - if ( currentOffset === 0 ) { | |
| 524 | - fields.classList.remove( 'frm_fixed' ); | |
| 525 | - return; | |
| 526 | - } | |
| 527 | - | |
| 528 | - var posEle = document.getElementById( 'frm_position_ele' ); | |
| 529 | - if ( posEle === null ) { | |
| 530 | - return; | |
| 531 | - } | |
| 532 | - | |
| 533 | - var eleOffset = jQuery( posEle ).offset(); | |
| 534 | - var offset = eleOffset.top; | |
| 535 | - var desiredOffset = offset - currentOffset; | |
| 536 | - var menuHeight = 0; | |
| 537 | - | |
| 538 | - var menu = document.getElementById( 'wpadminbar' ); | |
| 539 | - if ( menu !== null ) { | |
| 540 | - menuHeight = menu.offsetHeight; | |
| 541 | - } | |
| 542 | - | |
| 543 | - if ( desiredOffset < menuHeight ) { | |
| 544 | - desiredOffset = menuHeight; | |
| 545 | - } | |
| 546 | - | |
| 547 | - if ( desiredOffset > menuHeight ) { | |
| 548 | - fields.classList.remove( 'frm_fixed' ); | |
| 549 | - } else { | |
| 550 | - fields.classList.add( 'frm_fixed' ); | |
| 551 | - if ( desiredOffset !== 32 ) { | |
| 552 | - fields.style.top = desiredOffset + 'px'; | |
| 553 | - } | |
| 554 | - } | |
| 555 | - } | |
| 556 | - | |
| 557 | - function loadTooltips() { | |
| 558 | - var wrapClass = jQuery( '.wrap, .frm_wrap' ), | |
| 559 | - confirmModal = document.getElementById( 'frm_confirm_modal' ), | |
| 560 | - doAction = false, | |
| 561 | - confirmedBulkDelete = false; | |
| 562 | - | |
| 563 | - jQuery( confirmModal ).on( 'click', '[data-deletefield]', deleteFieldConfirmed ); | |
| 564 | - jQuery( confirmModal ).on( 'click', '[data-removeid]', removeThisTag ); | |
| 565 | - jQuery( confirmModal ).on( 'click', '[data-trashtemplate]', trashTemplate ); | |
| 566 | - | |
| 567 | - wrapClass.on( 'click', '.frm_remove_tag, .frm_remove_form_action', removeThisTag ); | |
| 568 | - wrapClass.on( 'click', 'a[data-frmverify]', confirmClick ); | |
| 569 | - wrapClass.on( 'click', 'a[data-frmtoggle]', toggleItem ); | |
| 570 | - wrapClass.on( 'click', 'a[data-frmhide], a[data-frmshow]', hideShowItem ); | |
| 571 | - wrapClass.on( 'change', 'input[data-frmhide], input[data-frmshow]', hideShowItem ); | |
| 572 | - wrapClass.on( 'click', '.widget-top,a.widget-action', clickWidget ); | |
| 573 | - | |
| 574 | - wrapClass.on( 'mouseenter.frm', '.frm_bstooltip, .frm_help', function() { | |
| 575 | - jQuery( this ).off( 'mouseenter.frm' ); | |
| 576 | - | |
| 577 | - jQuery( '.frm_bstooltip, .frm_help' ).tooltip( ); | |
| 578 | - jQuery( this ).tooltip( 'show' ); | |
| 579 | - }); | |
| 580 | - | |
| 581 | - jQuery( '.frm_bstooltip, .frm_help' ).tooltip( ); | |
| 582 | - | |
| 583 | - jQuery( document ).on( 'click', '#doaction, #doaction2', function( event ) { | |
| 584 | - var isTop = this.id === 'doaction', | |
| 585 | - suffix = isTop ? 'top' : 'bottom', | |
| 586 | - bulkActionSelector = document.getElementById( 'bulk-action-selector-' + suffix ), | |
| 587 | - confirmBulkDelete = document.getElementById( 'confirm-bulk-delete-' + suffix ); | |
| 588 | - | |
| 589 | - if ( bulkActionSelector !== null && confirmBulkDelete !== null ) { | |
| 590 | - doAction = this; | |
| 591 | - | |
| 592 | - if ( ! confirmedBulkDelete && bulkActionSelector.value === 'bulk_delete' ) { | |
| 593 | - event.preventDefault(); | |
| 594 | - confirmLinkClick( confirmBulkDelete ); | |
| 595 | - return false; | |
| 596 | - } | |
| 597 | - } else { | |
| 598 | - doAction = false; | |
| 599 | - } | |
| 600 | - }); | |
| 601 | - | |
| 602 | - jQuery( document ).on( 'click', '#frm-confirmed-click', function( event ) { | |
| 603 | - if ( doAction === false ) { | |
| 604 | - return; | |
| 605 | - } | |
| 606 | - | |
| 607 | - if ( this.getAttribute( 'href' ) === 'confirm-bulk-delete' ) { | |
| 608 | - event.preventDefault(); | |
| 609 | - confirmedBulkDelete = true; | |
| 610 | - doAction.click(); | |
| 611 | - return false; | |
| 612 | - } | |
| 613 | - }); | |
| 614 | - } | |
| 615 | - | |
| 616 | - function deleteTooltips() { | |
| 617 | - document.querySelectorAll( '.tooltip' ).forEach( | |
| 618 | - function( tooltip ) { | |
| 619 | - tooltip.remove(); | |
| 620 | - } | |
| 621 | - ); | |
| 622 | - } | |
| 623 | - | |
| 624 | - function removeThisTag() { | |
| 625 | - /*jshint validthis:true */ | |
| 626 | - let show, hide, removeMore; | |
| 627 | - | |
| 628 | - if ( parseInt( this.getAttribute( 'data-skip-frm-js' ) ) || confirmLinkClick( this ) === false ) { | |
| 629 | - return; | |
| 630 | - } | |
| 631 | - | |
| 632 | - const deleteButton = jQuery( this ); | |
| 633 | - const id = deleteButton.attr( 'data-removeid' ); | |
| 634 | - | |
| 635 | - show = deleteButton.attr( 'data-showlast' ); | |
| 636 | - if ( typeof show === 'undefined' ) { | |
| 637 | - show = ''; | |
| 638 | - } | |
| 639 | - | |
| 640 | - hide = deleteButton.attr( 'data-hidelast' ); | |
| 641 | - if ( typeof hide === 'undefined' ) { | |
| 642 | - hide = ''; | |
| 643 | - } | |
| 644 | - | |
| 645 | - removeMore = deleteButton.attr( 'data-removemore' ); | |
| 646 | - | |
| 647 | - if ( show !== '' ) { | |
| 648 | - if ( deleteButton.closest( '.frm_add_remove' ).find( '.frm_remove_tag:visible' ).length > 1 ) { | |
| 649 | - show = ''; | |
| 650 | - hide = ''; | |
| 651 | - } | |
| 652 | - } else if ( id.indexOf( 'frm_postmeta_' ) === 0 ) { | |
| 653 | - if ( jQuery( '#frm_postmeta_rows .frm_postmeta_row' ).length < 2 ) { | |
| 654 | - show = '.frm_add_postmeta_row.button'; | |
| 655 | - } | |
| 656 | - if ( jQuery( '.frm_toggle_cf_opts' ).length && jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().length ) { | |
| 657 | - if ( show !== '' ) { | |
| 658 | - show += ','; | |
| 659 | - } | |
| 660 | - show += '#' + jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().attr( 'id' ) + ' .frm_toggle_cf_opts'; | |
| 661 | - } | |
| 662 | - } | |
| 663 | - | |
| 664 | - const $fadeEle = jQuery( document.getElementById( id ) ); | |
| 665 | - $fadeEle.fadeOut( 400, function() { | |
| 666 | - $fadeEle.remove(); | |
| 667 | - fieldUpdated(); | |
| 668 | - | |
| 669 | - if ( hide !== '' ) { | |
| 670 | - jQuery( hide ).hide(); | |
| 671 | - } | |
| 672 | - | |
| 673 | - if ( show !== '' ) { | |
| 674 | - jQuery( show + ' a,' + show ).removeClass( 'frm_hidden' ).fadeIn( 'slow' ); | |
| 675 | - } | |
| 676 | - | |
| 677 | - if ( this.closest( '.frm_form_action_settings' ) ) { | |
| 678 | - const type = this.closest( '.frm_form_action_settings' ).querySelector( '.frm_action_name' ).value; | |
| 679 | - afterActionRemoved( type ); | |
| 680 | - } | |
| 681 | - }); | |
| 682 | - | |
| 683 | - if ( typeof removeMore !== 'undefined' ) { | |
| 684 | - removeMore = jQuery( removeMore ); | |
| 685 | - removeMore.fadeOut( 400, function() { | |
| 686 | - removeMore.remove(); | |
| 687 | - }); | |
| 688 | - } | |
| 689 | - | |
| 690 | - if ( show !== '' ) { | |
| 691 | - jQuery( this ).closest( '.frm_logic_rows' ).fadeOut( 'slow' ); | |
| 692 | - } | |
| 693 | - | |
| 694 | - return false; | |
| 695 | - } | |
| 696 | - | |
| 697 | - function afterActionRemoved( type ) { | |
| 698 | - checkActiveAction( type ); | |
| 699 | - | |
| 700 | - const hookName = 'frm_after_action_removed'; | |
| 701 | - const hookArgs = { type }; | |
| 702 | - wp.hooks.doAction( hookName, hookArgs ); | |
| 703 | - } | |
| 704 | - | |
| 705 | - function clickWidget( event, b ) { | |
| 706 | - /*jshint validthis:true */ | |
| 707 | - if ( typeof b === 'undefined' ) { | |
| 708 | - b = this; | |
| 709 | - } | |
| 710 | - | |
| 711 | - popCalcFields( b, false ); | |
| 712 | - | |
| 713 | - const cont = jQuery( b ).closest( '.frm_form_action_settings' ); | |
| 714 | - const target = event.target; | |
| 715 | - | |
| 716 | - if ( cont.length && typeof target !== 'undefined' ) { | |
| 717 | - const className = target.parentElement.className; | |
| 718 | - if ( 'string' === typeof className ) { | |
| 719 | - if ( className.indexOf( 'frm_email_icons' ) > -1 || className.indexOf( 'frm_toggle' ) > -1 ) { | |
| 720 | - // clicking on delete icon shouldn't open it | |
| 721 | - event.stopPropagation(); | |
| 722 | - return; | |
| 723 | - } | |
| 724 | - } | |
| 725 | - } | |
| 726 | - | |
| 727 | - let inside = cont.children( '.widget-inside' ); | |
| 728 | - | |
| 729 | - if ( cont.length && inside.find( 'p, div, table' ).length < 1 ) { | |
| 730 | - const actionId = cont.find( 'input[name$="[ID]"]' ).val(); | |
| 731 | - const actionType = cont.find( 'input[name$="[post_excerpt]"]' ).val(); | |
| 732 | - if ( actionType ) { | |
| 733 | - inside.html( '<span class="frm-wait frm_spinner"></span>' ); | |
| 734 | - cont.find( '.spinner' ).fadeIn( 'slow' ); | |
| 735 | - jQuery.ajax({ | |
| 736 | - type: 'POST', | |
| 737 | - url: ajaxurl, | |
| 738 | - data: { | |
| 739 | - action: 'frm_form_action_fill', | |
| 740 | - action_id: actionId, | |
| 741 | - action_type: actionType, | |
| 742 | - nonce: frmGlobal.nonce | |
| 743 | - }, | |
| 744 | - success: function( html ) { | |
| 745 | - inside.html( html ); | |
| 746 | - initiateMultiselect(); | |
| 747 | - showInputIcon( '#' + cont.attr( 'id' ) ); | |
| 748 | - frmDom.autocomplete.initAutocomplete( 'page', inside ); | |
| 749 | - jQuery( b ).trigger( 'frm-action-loaded' ); | |
| 750 | - | |
| 751 | - /** | |
| 752 | - * Fires after filling form action content when opening. | |
| 753 | - * | |
| 754 | - * @since 5.5.4 | |
| 755 | - * | |
| 756 | - * @param {Object} insideElement JQuery object of form action inside element. | |
| 757 | - */ | |
| 758 | - wp.hooks.doAction( 'frm_filled_form_action', inside ); | |
| 759 | - } | |
| 760 | - }); | |
| 761 | - } | |
| 762 | - } | |
| 763 | - | |
| 764 | - jQuery( b ).closest( '.frm_field_box' ).siblings().find( '.widget-inside' ).slideUp( 'fast' ); | |
| 765 | - if ( ( typeof b.className !== 'undefined' && b.className.indexOf( 'widget-action' ) !== -1 ) || jQuery( b ).closest( '.start_divider' ).length < 1 ) { | |
| 766 | - return; | |
| 767 | - } | |
| 768 | - | |
| 769 | - inside = jQuery( b ).closest( 'div.widget' ).children( '.widget-inside' ); | |
| 770 | - if ( inside.is( ':hidden' ) ) { | |
| 771 | - inside.slideDown( 'fast' ); | |
| 772 | - } else { | |
| 773 | - inside.slideUp( 'fast' ); | |
| 774 | - } | |
| 775 | - } | |
| 776 | - | |
| 777 | - function clickNewTab() { | |
| 778 | - /*jshint validthis:true */ | |
| 779 | - var t = this.getAttribute( 'href' ), | |
| 780 | - c = t.replace( '#', '.' ), | |
| 781 | - $link = jQuery( this ); | |
| 782 | - | |
| 783 | - if ( typeof t === 'undefined' ) { | |
| 784 | - return false; | |
| 785 | - } | |
| 786 | - | |
| 787 | - $link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' ); | |
| 788 | - $link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide(); | |
| 789 | - document.getElementById( t.replace( '#', '' ) ).style.display = 'block'; | |
| 790 | - | |
| 791 | - if ( this.id === 'frm_insert_fields_tab' ) { | |
| 792 | - clearSettingsBox(); | |
| 793 | - } | |
| 794 | - return false; | |
| 795 | - } | |
| 796 | - | |
| 797 | - function clickTab( link, auto ) { | |
| 798 | - link = jQuery( link ); | |
| 799 | - var t = link.attr( 'href' ); | |
| 800 | - if ( typeof t === 'undefined' ) { | |
| 801 | - return; | |
| 802 | - } | |
| 803 | - | |
| 804 | - var c = t.replace( '#', '.' ); | |
| 805 | - | |
| 806 | - link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' ); | |
| 807 | - if ( link.closest( 'div' ).find( '.tabs-panel' ).length ) { | |
| 808 | - link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide(); | |
| 809 | - } else { | |
| 810 | - if ( document.getElementById( 'form_global_settings' ) !== null ) { | |
| 811 | - /* global settings */ | |
| 812 | - var ajax = link.data( 'frmajax' ); | |
| 813 | - link.closest( '.frm_wrap' ).find( '.tabs-panel, .hide_with_tabs' ).hide(); | |
| 814 | - if ( typeof ajax !== 'undefined' && ajax == '1' ) { | |
| 815 | - loadSettingsTab( t ); | |
| 816 | - } | |
| 817 | - } else { | |
| 818 | - /* form settings page */ | |
| 819 | - jQuery( '#frm-categorydiv .tabs-panel, .hide_with_tabs' ).hide(); | |
| 820 | - } | |
| 821 | - } | |
| 822 | - jQuery( t ).show(); | |
| 823 | - jQuery( c ).show(); | |
| 824 | - | |
| 825 | - hideShortcodes(); | |
| 826 | - | |
| 827 | - if ( auto !== 'auto' ) { | |
| 828 | - // Hide success message on tab change. | |
| 829 | - jQuery( '.frm_updated_message' ).hide(); | |
| 830 | - jQuery( '.frm_warning_style' ).hide(); | |
| 831 | - } | |
| 832 | - | |
| 833 | - if ( jQuery( link ).closest( '#frm_adv_info' ).length ) { | |
| 834 | - return; | |
| 835 | - } | |
| 836 | - | |
| 837 | - if ( jQuery( '.frm_form_settings' ).length ) { | |
| 838 | - jQuery( '.frm_form_settings' ).attr( 'action', '?page=formidable&frm_action=settings&id=' + jQuery( '.frm_form_settings input[name="id"]' ).val() + '&t=' + t.replace( '#', '' ) ); | |
| 839 | - } else { | |
| 840 | - jQuery( '.frm_settings_form' ).attr( 'action', '?page=formidable-settings&t=' + t.replace( '#', '' ) ); | |
| 841 | - } | |
| 842 | - } | |
| 843 | - | |
| 844 | - function setupSortable( sortableSelector ) { | |
| 845 | - document.querySelectorAll( sortableSelector ).forEach( | |
| 846 | - list => { | |
| 847 | - makeDroppable( list ); | |
| 848 | - Array.from( list.children ).forEach( child => makeDraggable( child, '.frm-move' ) ); | |
| 849 | - | |
| 850 | - const $sectionTitle = jQuery( list ).children( '[data-type="divider"]' ).children( '.divider_section_only' ); | |
| 851 | - if ( $sectionTitle.length ) { | |
| 852 | - makeDroppable( $sectionTitle ); | |
| 853 | - } | |
| 854 | - } | |
| 855 | - ); | |
| 856 | - setupFieldOptionSorting( jQuery( '#frm_builder_page' ) ); | |
| 857 | - } | |
| 858 | - | |
| 859 | - function makeDroppable( list ) { | |
| 860 | - jQuery( list ).droppable({ | |
| 861 | - accept: '.frmbutton, li.frm_field_box', | |
| 862 | - deactivate: handleFieldDrop, | |
| 863 | - over: onDragOverDroppable, | |
| 864 | - out: onDraggableLeavesDroppable, | |
| 865 | - tolerance: 'pointer' | |
| 866 | - }); | |
| 867 | - } | |
| 868 | - | |
| 869 | - function onDragOverDroppable( event, ui ) { | |
| 870 | - const droppable = getDroppableForOnDragOver( event.target ); | |
| 871 | - const draggable = ui.draggable[0]; | |
| 872 | - | |
| 873 | - if ( ! allowDrop( draggable, droppable ) ) { | |
| 874 | - droppable.classList.remove( 'frm-over-droppable' ); | |
| 875 | - jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' ); | |
| 876 | - return; | |
| 877 | - } | |
| 878 | - | |
| 879 | - document.querySelectorAll( '.frm-over-droppable' ).forEach( droppable => droppable.classList.remove( 'frm-over-droppable' ) ); | |
| 880 | - droppable.classList.add( 'frm-over-droppable' ); | |
| 881 | - jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' ); | |
| 882 | - } | |
| 883 | - | |
| 884 | - /** | |
| 885 | - * Maybe change the droppable. | |
| 886 | - * Section titles are made droppable, but are not a list, so we need to change the droppable to the section's list instead. | |
| 887 | - * | |
| 888 | - * @param {Element} droppable | |
| 889 | - * @returns {Element} | |
| 890 | - */ | |
| 891 | - function getDroppableForOnDragOver( droppable ) { | |
| 892 | - if ( droppable.classList.contains( 'divider_section_only' ) ) { | |
| 893 | - droppable = jQuery( droppable ).nextAll( '.start_divider.frm_sorting' ).get( 0 ); | |
| 894 | - } | |
| 895 | - return droppable; | |
| 896 | - } | |
| 897 | - | |
| 898 | - function onDraggableLeavesDroppable( event ) { | |
| 899 | - const droppable = event.target; | |
| 900 | - droppable.classList.remove( 'frm-over-droppable' ); | |
| 901 | - } | |
| 902 | - | |
| 903 | - function makeDraggable( draggable, handle ) { | |
| 904 | - const settings = { | |
| 905 | - helper: getDraggableHelper, | |
| 906 | - revert: 'invalid', | |
| 907 | - delay: 10, | |
| 908 | - start: handleDragStart, | |
| 909 | - stop: handleDragStop, | |
| 910 | - drag: handleDrag, | |
| 911 | - cursor: 'grabbing', | |
| 912 | - refreshPositions: true, | |
| 913 | - cursorAt: { | |
| 914 | - top: 0, | |
| 915 | - left: 90 // The width of draggable button is 180. 90 should center the draggable on the cursor. | |
| 916 | - } | |
| 917 | - }; | |
| 918 | - if ( 'string' === typeof handle ) { | |
| 919 | - settings.handle = handle; | |
| 920 | - } | |
| 921 | - jQuery( draggable ).draggable( settings ); | |
| 922 | - } | |
| 923 | - | |
| 924 | - function getDraggableHelper( event ) { | |
| 925 | - const draggable = event.delegateTarget; | |
| 926 | - | |
| 927 | - if ( isFieldGroup( draggable ) ) { | |
| 928 | - const newTextFieldClone = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_ttext' ).cloneNode( true ); | |
| 929 | - newTextFieldClone.querySelector( 'use' ).setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_field_group_layout_icon' ); | |
| 930 | - newTextFieldClone.querySelector( 'span' ).textContent = __( 'Field Group' ); | |
| 931 | - newTextFieldClone.classList.add( 'frm_field_box' ); | |
| 932 | - newTextFieldClone.classList.add( 'ui-sortable-helper' ); | |
| 933 | - return newTextFieldClone; | |
| 934 | - } | |
| 935 | - | |
| 936 | - let copyTarget; | |
| 937 | - const isNewField = draggable.classList.contains( 'frmbutton' ); | |
| 938 | - if ( isNewField ) { | |
| 939 | - copyTarget = draggable.cloneNode( true ); | |
| 940 | - copyTarget.classList.add( 'ui-sortable-helper' ); | |
| 941 | - draggable.classList.add( 'frm-new-field' ); | |
| 942 | - return copyTarget; | |
| 943 | - } | |
| 944 | - | |
| 945 | - if ( draggable.hasAttribute( 'data-ftype' ) ) { | |
| 946 | - const fieldType = draggable.getAttribute( 'data-ftype' ); | |
| 947 | - copyTarget = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_t' + fieldType ); | |
| 948 | - copyTarget = copyTarget.cloneNode( true ); | |
| 949 | - copyTarget.classList.add( 'form-field' ); | |
| 950 | - | |
| 951 | - copyTarget.classList.add( 'ui-sortable-helper' ); | |
| 952 | - | |
| 953 | - if ( copyTarget ) { | |
| 954 | - return copyTarget.cloneNode( true ); | |
| 955 | - } | |
| 956 | - } | |
| 957 | - | |
| 958 | - return div({ className: 'frmbutton' }); | |
| 959 | - } | |
| 960 | - | |
| 961 | - function handleDragStart( event, ui ) { | |
| 962 | - const container = postBodyContent; | |
| 963 | - container.classList.add( 'frm-dragging-field' ); | |
| 964 | - | |
| 965 | - document.body.classList.add( 'frm-dragging' ); | |
| 966 | - ui.helper.addClass( 'frm-sortable-helper' ); | |
| 967 | - ui.helper.initialOffset = container.scrollTop; | |
| 968 | - | |
| 969 | - event.target.classList.add( 'frm-drag-fade' ); | |
| 970 | - | |
| 971 | - unselectFieldGroups(); | |
| 972 | - deleteEmptyDividerWrappers(); | |
| 973 | - maybeRemoveGroupHoverTarget(); | |
| 974 | - closeOpenFieldDropdowns(); | |
| 975 | - deleteTooltips(); | |
| 976 | - } | |
| 977 | - | |
| 978 | - function handleDragStop() { | |
| 979 | - const container = postBodyContent; | |
| 980 | - container.classList.remove( 'frm-dragging-field' ); | |
| 981 | - document.body.classList.remove( 'frm-dragging' ); | |
| 982 | - | |
| 983 | - const fade = document.querySelector( '.frm-drag-fade' ); | |
| 984 | - if ( fade ) { | |
| 985 | - fade.classList.remove( 'frm-drag-fade' ); | |
| 986 | - } | |
| 987 | - } | |
| 988 | - | |
| 989 | - function handleDrag( event, ui ) { | |
| 990 | - maybeScrollBuilder( event ); | |
| 991 | - const draggable = event.target; | |
| 992 | - const droppable = getDroppableTarget(); | |
| 993 | - | |
| 994 | - let placeholder = document.getElementById( 'frm_drag_placeholder' ); | |
| 995 | - | |
| 996 | - if ( ! allowDrop( draggable, droppable ) ) { | |
| 997 | - if ( placeholder ) { | |
| 998 | - placeholder.remove(); | |
| 999 | - } | |
| 1000 | - return; | |
| 1001 | - } | |
| 1002 | - | |
| 1003 | - if ( ! placeholder ) { | |
| 1004 | - placeholder = tag( 'li', { | |
| 1005 | - id: 'frm_drag_placeholder', | |
| 1006 | - className: 'sortable-placeholder' | |
| 1007 | - }); | |
| 1008 | - } | |
| 1009 | - const frmSortableHelper = ui.helper.get( 0 ); | |
| 1010 | - if ( frmSortableHelper.classList.contains( 'form-field' ) || frmSortableHelper.classList.contains( 'frm_field_box' ) ) { | |
| 1011 | - // Sync the y position of the draggable so it still follows the cursor after scrolling up and down the field list. | |
| 1012 | - frmSortableHelper.style.transform = 'translateY(' + getDragOffset( ui.helper ) + 'px)'; | |
| 1013 | - } | |
| 1014 | - | |
| 1015 | - if ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) ) { | |
| 1016 | - placeholder.style.left = 0; | |
| 1017 | - handleDragOverYAxis({ droppable, y: event.clientY, placeholder }); | |
| 1018 | - return; | |
| 1019 | - } | |
| 1020 | - | |
| 1021 | - placeholder.style.top = ''; | |
| 1022 | - handleDragOverFieldGroup({ droppable, x: event.clientX, placeholder }); | |
| 1023 | - } | |
| 1024 | - | |
| 1025 | - function maybeScrollBuilder( event ) { | |
| 1026 | - $postBodyContent.scrollTop( | |
| 1027 | - ( _, v ) => { | |
| 1028 | - const moved = event.clientY; | |
| 1029 | - const h = postBodyContent.offsetHeight; | |
| 1030 | - const relativePos = event.clientY - postBodyContent.offsetTop; | |
| 1031 | - const y = relativePos - h / 2; | |
| 1032 | - | |
| 1033 | - if ( relativePos > ( h - 50 ) && moved > 5 ) { | |
| 1034 | - // Scrolling down. | |
| 1035 | - return v + y * 0.1; | |
| 1036 | - } | |
| 1037 | - | |
| 1038 | - if ( relativePos < 70 && moved < 130 ) { | |
| 1039 | - // Scrolling up. | |
| 1040 | - return v - Math.abs( y * 0.1 ); | |
| 1041 | - } | |
| 1042 | - | |
| 1043 | - return v; | |
| 1044 | - } | |
| 1045 | - ); | |
| 1046 | - } | |
| 1047 | - | |
| 1048 | - function getDragOffset( $helper ) { | |
| 1049 | - return postBodyContent.scrollTop - $helper.initialOffset; | |
| 1050 | - } | |
| 1051 | - | |
| 1052 | - function getDroppableTarget() { | |
| 1053 | - let droppable = document.getElementById( 'frm-show-fields' ); | |
| 1054 | - while ( droppable.querySelector( '.frm-over-droppable' ) ) { | |
| 1055 | - droppable = droppable.querySelector( '.frm-over-droppable' ); | |
| 1056 | - } | |
| 1057 | - if ( 'frm-show-fields' === droppable.id && ! droppable.classList.contains( 'frm-over-droppable' ) ) { | |
| 1058 | - droppable = false; | |
| 1059 | - } | |
| 1060 | - return droppable; | |
| 1061 | - } | |
| 1062 | - | |
| 1063 | - function handleFieldDrop( _, ui ) { | |
| 1064 | - const draggable = ui.draggable[0]; | |
| 1065 | - const placeholder = document.getElementById( 'frm_drag_placeholder' ); | |
| 1066 | - | |
| 1067 | - if ( ! placeholder ) { | |
| 1068 | - ui.helper.remove(); | |
| 1069 | - debouncedSyncAfterDragAndDrop(); | |
| 1070 | - return; | |
| 1071 | - } | |
| 1072 | - | |
| 1073 | - maybeOpenCollapsedPage( placeholder ); | |
| 1074 | - | |
| 1075 | - const $previousFieldContainer = ui.helper.parent(); | |
| 1076 | - const previousSection = ui.helper.get( 0 ).closest( 'ul.start_divider' ); | |
| 1077 | - const newSection = placeholder.closest( 'ul.frm_sorting' ); | |
| 1078 | - | |
| 1079 | - if ( draggable.classList.contains( 'frm-new-field' ) ) { | |
| 1080 | - insertNewFieldByDragging( draggable.id ); | |
| 1081 | - } else { | |
| 1082 | - moveFieldThatAlreadyExists( draggable, placeholder ); | |
| 1083 | - } | |
| 1084 | - | |
| 1085 | - const previousSectionId = previousSection ? parseInt( previousSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0; | |
| 1086 | - const newSectionId = newSection.classList.contains( 'start_divider' ) ? parseInt( newSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0; | |
| 1087 | - | |
| 1088 | - placeholder.remove(); | |
| 1089 | - ui.helper.remove(); | |
| 1090 | - | |
| 1091 | - const $previousContainerFields = $previousFieldContainer.length ? getFieldsInRow( $previousFieldContainer ) : []; | |
| 1092 | - maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields ); | |
| 1093 | - maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields ); | |
| 1094 | - | |
| 1095 | - if ( previousSectionId !== newSectionId ) { | |
| 1096 | - updateFieldAfterMovingBetweenSections( jQuery( draggable ), previousSection ); | |
| 1097 | - } | |
| 1098 | - | |
| 1099 | - debouncedSyncAfterDragAndDrop(); | |
| 1100 | - } | |
| 1101 | - | |
| 1102 | - /** | |
| 1103 | - * If a page if collapsed, expand it before dragging since only the page break will move. | |
| 1104 | - * | |
| 1105 | - * @param {Element} placeholder | |
| 1106 | - * @returns {void} | |
| 1107 | - */ | |
| 1108 | - function maybeOpenCollapsedPage( placeholder ) { | |
| 1109 | - if ( ! placeholder.previousElementSibling || ! placeholder.previousElementSibling.classList.contains( 'frm-is-collapsed' ) ) { | |
| 1110 | - return; | |
| 1111 | - } | |
| 1112 | - | |
| 1113 | - const $pageBreakField = jQuery( placeholder ).prevUntil( '[data-type="break"]' ); | |
| 1114 | - if ( ! $pageBreakField.length ) { | |
| 1115 | - return; | |
| 1116 | - } | |
| 1117 | - | |
| 1118 | - const collapseButton = $pageBreakField.find( '.frm-collapse-page' ).get( 0 ); | |
| 1119 | - if ( collapseButton ) { | |
| 1120 | - collapseButton.click(); | |
| 1121 | - } | |
| 1122 | - } | |
| 1123 | - | |
| 1124 | - function maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields ) { | |
| 1125 | - if ( ! $previousFieldContainer.length ) { | |
| 1126 | - return; | |
| 1127 | - } | |
| 1128 | - | |
| 1129 | - if ( $previousContainerFields.length ) { | |
| 1130 | - syncLayoutClasses( $previousContainerFields.first() ); | |
| 1131 | - } else { | |
| 1132 | - maybeDeleteAnEmptyFieldGroup( $previousFieldContainer.get( 0 ) ); | |
| 1133 | - } | |
| 1134 | - } | |
| 1135 | - | |
| 1136 | - function maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields ) { | |
| 1137 | - if ( 0 !== $previousContainerFields.length || 1 !== getFieldsInRow( jQuery( draggable.parentNode ) ).length ) { | |
| 1138 | - syncLayoutClasses( jQuery( draggable ) ); | |
| 1139 | - } | |
| 1140 | - } | |
| 1141 | - | |
| 1142 | - /** | |
| 1143 | - * Remove an empty field group, but don't remove an empty section. | |
| 1144 | - * | |
| 1145 | - * @param {Element} previousFieldContainer | |
| 1146 | - * @returns {void} | |
| 1147 | - */ | |
| 1148 | - function maybeDeleteAnEmptyFieldGroup( previousFieldContainer ) { | |
| 1149 | - const closestFieldBox = previousFieldContainer.closest( 'li.frm_field_box' ); | |
| 1150 | - if ( closestFieldBox && ! closestFieldBox.classList.contains( 'edit_field_type_divider' ) ) { | |
| 1151 | - closestFieldBox.remove(); | |
| 1152 | - } | |
| 1153 | - } | |
| 1154 | - | |
| 1155 | - function handleDragOverYAxis({ droppable, y, placeholder }) { | |
| 1156 | - const $list = jQuery( droppable ); | |
| 1157 | - | |
| 1158 | - let top; | |
| 1159 | - | |
| 1160 | - $children = $list.children().not( '.edit_field_type_end_divider' ); | |
| 1161 | - if ( 0 === $children.length ) { | |
| 1162 | - $list.prepend( placeholder ); | |
| 1163 | - top = 0; | |
| 1164 | - } else { | |
| 1165 | - const insertAtIndex = determineIndexBasedOffOfMousePositionInList( $list, y ); | |
| 1166 | - | |
| 1167 | - if ( insertAtIndex === $children.length ) { | |
| 1168 | - const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) ); | |
| 1169 | - top = $lastChild.offset().top + $lastChild.outerHeight(); | |
| 1170 | - $list.append( placeholder ); | |
| 1171 | - | |
| 1172 | - // Make sure nothing gets inserted after the end divider. | |
| 1173 | - const $endDivider = $list.children( '.edit_field_type_end_divider' ); | |
| 1174 | - if ( $endDivider.length ) { | |
| 1175 | - $list.append( $endDivider ); | |
| 1176 | - } | |
| 1177 | - } else { | |
| 1178 | - top = jQuery( $children.get( insertAtIndex ) ).offset().top; | |
| 1179 | - jQuery( $children.get( insertAtIndex ) ).before( placeholder ); | |
| 1180 | - } | |
| 1181 | - } | |
| 1182 | - | |
| 1183 | - top -= $list.offset().top; | |
| 1184 | - placeholder.style.top = top + 'px'; | |
| 1185 | - } | |
| 1186 | - | |
| 1187 | - function determineIndexBasedOffOfMousePositionInList( $list, y ) { | |
| 1188 | - const $items = $list.children().not( '.edit_field_type_end_divider' ); | |
| 1189 | - const length = $items.length; | |
| 1190 | - | |
| 1191 | - let index, item, itemTop, returnIndex; | |
| 1192 | - | |
| 1193 | - returnIndex = 0; | |
| 1194 | - for ( index = length - 1; index >= 0; --index ) { | |
| 1195 | - item = $items.get( index ); | |
| 1196 | - itemTop = jQuery( item ).offset().top; | |
| 1197 | - if ( y > itemTop ) { | |
| 1198 | - returnIndex = index; | |
| 1199 | - if ( y > itemTop + ( jQuery( item ).outerHeight() / 2 ) ) { | |
| 1200 | - returnIndex = index + 1; | |
| 1201 | - } | |
| 1202 | - break; | |
| 1203 | - } | |
| 1204 | - } | |
| 1205 | - | |
| 1206 | - return returnIndex; | |
| 1207 | - } | |
| 1208 | - | |
| 1209 | - function handleDragOverFieldGroup({ droppable, x, placeholder }) { | |
| 1210 | - const $row = jQuery( droppable ); | |
| 1211 | - const $children = getFieldsInRow( $row ); | |
| 1212 | - | |
| 1213 | - if ( ! $children.length ) { | |
| 1214 | - return; | |
| 1215 | - } | |
| 1216 | - | |
| 1217 | - let left; | |
| 1218 | - const insertAtIndex = determineIndexBasedOffOfMousePositionInRow( $row, x ); | |
| 1219 | - | |
| 1220 | - if ( insertAtIndex === $children.length ) { | |
| 1221 | - const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) ); | |
| 1222 | - left = $lastChild.offset().left + $lastChild.outerWidth(); | |
| 1223 | - $row.append( placeholder ); | |
| 1224 | - } else { | |
| 1225 | - left = jQuery( $children.get( insertAtIndex ) ).offset().left; | |
| 1226 | - jQuery( $children.get( insertAtIndex ) ).before( placeholder ); | |
| 1227 | - | |
| 1228 | - const amountToOffsetLeftBy = 0 === insertAtIndex ? 4 : 8; // Offset by 8 in between rows, but only 4 for the first item in a group. | |
| 1229 | - left -= amountToOffsetLeftBy; // Offset the placeholder slightly so it appears between two fields. | |
| 1230 | - } | |
| 1231 | - | |
| 1232 | - left -= $row.offset().left; | |
| 1233 | - | |
| 1234 | - placeholder.style.left = left + 'px'; | |
| 1235 | - } | |
| 1236 | - | |
| 1237 | - function syncAfterDragAndDrop() { | |
| 1238 | - fixUnwrappedListItems(); | |
| 1239 | - toggleSectionHolder(); | |
| 1240 | - maybeFixEndDividers(); | |
| 1241 | - maybeDeleteEmptyFieldGroups(); | |
| 1242 | - updateFieldOrder(); | |
| 1243 | - | |
| 1244 | - const event = new Event( 'frm_sync_after_drag_and_drop', { bubbles: false }); | |
| 1245 | - document.dispatchEvent( event ); | |
| 1246 | - } | |
| 1247 | - | |
| 1248 | - function maybeFixEndDividers() { | |
| 1249 | - document.querySelectorAll( '.edit_field_type_end_divider' ).forEach( | |
| 1250 | - endDivider => endDivider.parentNode.appendChild( endDivider ) | |
| 1251 | - ); | |
| 1252 | - } | |
| 1253 | - | |
| 1254 | - function maybeDeleteEmptyFieldGroups() { | |
| 1255 | - document.querySelectorAll( 'li.form_field_box:not(.form-field)' ).forEach( | |
| 1256 | - fieldGroup => ! fieldGroup.children.length && fieldGroup.remove() | |
| 1257 | - ); | |
| 1258 | - } | |
| 1259 | - | |
| 1260 | - function fixUnwrappedListItems() { | |
| 1261 | - const lists = document.querySelectorAll( 'ul#frm-show-fields, ul.start_divider' ); | |
| 1262 | - lists.forEach( | |
| 1263 | - list => { | |
| 1264 | - list.childNodes.forEach( | |
| 1265 | - child => { | |
| 1266 | - if ( 'undefined' === typeof child.classList ) { | |
| 1267 | - return; | |
| 1268 | - } | |
| 1269 | - | |
| 1270 | - if ( child.classList.contains( 'edit_field_type_end_divider' ) ) { | |
| 1271 | - // Never wrap end divider in place. | |
| 1272 | - return; | |
| 1273 | - } | |
| 1274 | - | |
| 1275 | - if ( 'undefined' !== typeof child.classList && child.classList.contains( 'form-field' ) ) { | |
| 1276 | - wrapFieldLiInPlace( child ); | |
| 1277 | - } | |
| 1278 | - } | |
| 1279 | - ); | |
| 1280 | - } | |
| 1281 | - ); | |
| 1282 | - } | |
| 1283 | - | |
| 1284 | - function deleteEmptyDividerWrappers() { | |
| 1285 | - const dividers = document.querySelectorAll( 'ul.start_divider' ); | |
| 1286 | - if ( ! dividers.length ) { | |
| 1287 | - return; | |
| 1288 | - } | |
| 1289 | - dividers.forEach( | |
| 1290 | - function( divider ) { | |
| 1291 | - const children = [].slice.call( divider.children ); | |
| 1292 | - children.forEach( | |
| 1293 | - function( child ) { | |
| 1294 | - if ( 0 === child.children.length ) { | |
| 1295 | - child.remove(); | |
| 1296 | - } else if ( 1 === child.children.length && 'ul' === child.firstElementChild.nodeName.toLowerCase() && 0 === child.firstElementChild.children.length ) { | |
| 1297 | - child.remove(); | |
| 1298 | - } | |
| 1299 | - } | |
| 1300 | - ); | |
| 1301 | - } | |
| 1302 | - ); | |
| 1303 | - } | |
| 1304 | - | |
| 1305 | - function getFieldsInRow( $row ) { | |
| 1306 | - let $fields = jQuery(); | |
| 1307 | - | |
| 1308 | - const row = $row.get( 0 ); | |
| 1309 | - if ( ! row.children ) { | |
| 1310 | - return $fields; | |
| 1311 | - } | |
| 1312 | - | |
| 1313 | - Array.from( row.children ).forEach( | |
| 1314 | - child => { | |
| 1315 | - if ( 'none' === child.style.display ) { | |
| 1316 | - return; | |
| 1317 | - } | |
| 1318 | - | |
| 1319 | - const classes = child.classList; | |
| 1320 | - if ( ! classes.contains( 'form-field' ) || classes.contains( 'edit_field_type_end_divider' ) || classes.contains( 'frm-sortable-helper' ) ) { | |
| 1321 | - return; | |
| 1322 | - } | |
| 1323 | - | |
| 1324 | - $fields = $fields.add( child ); | |
| 1325 | - } | |
| 1326 | - ); | |
| 1327 | - return $fields; | |
| 1328 | - } | |
| 1329 | - | |
| 1330 | - function determineIndexBasedOffOfMousePositionInRow( $row, x ) { | |
| 1331 | - var $inputs = getFieldsInRow( $row ), | |
| 1332 | - length = $inputs.length, | |
| 1333 | - index, input, inputLeft, returnIndex; | |
| 1334 | - | |
| 1335 | - returnIndex = 0; | |
| 1336 | - for ( index = length - 1; index >= 0; --index ) { | |
| 1337 | - input = $inputs.get( index ); | |
| 1338 | - inputLeft = jQuery( input ).offset().left; | |
| 1339 | - if ( x > inputLeft ) { | |
| 1340 | - returnIndex = index; | |
| 1341 | - if ( x > inputLeft + ( jQuery( input ).outerWidth() / 2 ) ) { | |
| 1342 | - returnIndex = index + 1; | |
| 1343 | - } | |
| 1344 | - break; | |
| 1345 | - } | |
| 1346 | - } | |
| 1347 | - | |
| 1348 | - return returnIndex; | |
| 1349 | - } | |
| 1350 | - | |
| 1351 | - function syncLayoutClasses( $item, type ) { | |
| 1352 | - var $fields, size, layoutClasses, classToAddFunction; | |
| 1353 | - | |
| 1354 | - if ( 'undefined' === typeof type ) { | |
| 1355 | - type = 'even'; | |
| 1356 | - } | |
| 1357 | - | |
| 1358 | - $fields = $item.parent().children( 'li.form-field, li.frmbutton_loadingnow' ).not( '.edit_field_type_end_divider' ); | |
| 1359 | - size = $fields.length; | |
| 1360 | - layoutClasses = getLayoutClasses(); | |
| 1361 | - | |
| 1362 | - if ( 'even' === type && 5 !== size ) { | |
| 1363 | - $fields.each( getSyncLayoutClass( layoutClasses, getEvenClassForSize( size ) ) ); | |
| 1364 | - } else if ( 'clear' === type ) { | |
| 1365 | - $fields.each( getSyncLayoutClass( layoutClasses, '' ) ); | |
| 1366 | - } else { | |
| 1367 | - if ( -1 !== [ 'left', 'right', 'middle', 'even' ].indexOf( type ) ) { | |
| 1368 | - classToAddFunction = function( index ) { | |
| 1369 | - return getClassForBlock( size, type, index ); | |
| 1370 | - }; | |
| 1371 | - } else { | |
| 1372 | - classToAddFunction = function( index ) { | |
| 1373 | - var size = type[ index ]; | |
| 1374 | - return getLayoutClassForSize( size ); | |
| 1375 | - }; | |
| 1376 | - } | |
| 1377 | - | |
| 1378 | - $fields.each( getSyncLayoutClass( layoutClasses, classToAddFunction ) ); | |
| 1379 | - } | |
| 1380 | - | |
| 1381 | - updateFieldGroupControls( $item.parent(), $fields.length ); | |
| 1382 | - } | |
| 1383 | - | |
| 1384 | - function updateFieldGroupControls( $row, count ) { | |
| 1385 | - var rowOffset, shouldShowControls, controls; | |
| 1386 | - | |
| 1387 | - rowOffset = $row.offset(); | |
| 1388 | - | |
| 1389 | - if ( 'undefined' === typeof rowOffset ) { | |
| 1390 | - return; | |
| 1391 | - } | |
| 1392 | - | |
| 1393 | - shouldShowControls = count >= 2; | |
| 1394 | - | |
| 1395 | - controls = document.getElementById( 'frm_field_group_controls' ); | |
| 1396 | - if ( null === controls ) { | |
| 1397 | - if ( ! shouldShowControls ) { | |
| 1398 | - // exit early. if we do not need controls and they do not exist, do nothing. | |
| 1399 | - return; | |
| 1400 | - } | |
| 1401 | - | |
| 1402 | - controls = div(); | |
| 1403 | - controls.id = 'frm_field_group_controls'; | |
| 1404 | - controls.setAttribute( 'role', 'group' ); | |
| 1405 | - controls.setAttribute( 'tabindex', 0 ); | |
| 1406 | - setFieldControlsHtml( controls ); | |
| 1407 | - document.getElementById( 'frm_builder_page' ).appendChild( controls ); | |
| 1408 | - } | |
| 1409 | - | |
| 1410 | - $row.append( controls ); | |
| 1411 | - controls.style.display = shouldShowControls ? 'block' : 'none'; | |
| 1412 | - } | |
| 1413 | - | |
| 1414 | - function setFieldControlsHtml( controls ) { | |
| 1415 | - var layoutOption, moveOption; | |
| 1416 | - | |
| 1417 | - layoutOption = document.createElement( 'span' ); | |
| 1418 | - layoutOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_field_group_layout_icon"></use></svg>'; | |
| 1419 | - const layoutOptionLabel = __( 'Set Row Layout', 'formidable' ); | |
| 1420 | - addTooltip( layoutOption, layoutOptionLabel ); | |
| 1421 | - makeTabbable( layoutOption, layoutOptionLabel ); | |
| 1422 | - | |
| 1423 | - moveOption = document.createElement( 'span' ); | |
| 1424 | - moveOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_thick_move_icon"></use></svg>'; | |
| 1425 | - moveOption.classList.add( 'frm-move' ); | |
| 1426 | - const moveOptionLabel = __( 'Move Field Group', 'formidable' ); | |
| 1427 | - addTooltip( moveOption, moveOptionLabel ); | |
| 1428 | - makeTabbable( moveOption, moveOptionLabel ); | |
| 1429 | - | |
| 1430 | - controls.innerHTML = ''; | |
| 1431 | - controls.appendChild( layoutOption ); | |
| 1432 | - controls.appendChild( moveOption ); | |
| 1433 | - controls.appendChild( getFieldControlsDropdown() ); | |
| 1434 | - } | |
| 1435 | - | |
| 1436 | - function addTooltip( element, title ) { | |
| 1437 | - element.setAttribute( 'data-toggle', 'tooltip' ); | |
| 1438 | - element.setAttribute( 'data-container', 'body' ); | |
| 1439 | - element.setAttribute( 'title', title ); | |
| 1440 | - element.addEventListener( | |
| 1441 | - 'mouseover', | |
| 1442 | - function() { | |
| 1443 | - if ( null === element.getAttribute( 'data-original-title' ) ) { | |
| 1444 | - jQuery( element ).tooltip(); | |
| 1445 | - } | |
| 1446 | - } | |
| 1447 | - ); | |
| 1448 | - } | |
| 1449 | - | |
| 1450 | - function getFieldControlsDropdown() { | |
| 1451 | - var dropdown, trigger, ul; | |
| 1452 | - | |
| 1453 | - dropdown = document.createElement( 'span' ); | |
| 1454 | - dropdown.classList.add( 'dropdown' ); | |
| 1455 | - | |
| 1456 | - trigger = document.createElement( 'a' ); | |
| 1457 | - trigger.classList.add( 'frm_bstooltip', 'frm-hover-icon', 'frm-dropdown-toggle', 'dropdown-toggle' ); | |
| 1458 | - trigger.setAttribute( 'title', __( 'More Options', 'formidable' ) ); | |
| 1459 | - trigger.setAttribute( 'data-toggle', 'dropdown' ); | |
| 1460 | - trigger.setAttribute( 'data-container', 'body' ); | |
| 1461 | - makeTabbable( trigger, __( 'More Options', 'formidable' ) ); | |
| 1462 | - trigger.innerHTML = '<span><svg class="frmsvg"><use xlink:href="#frm_thick_more_vert_icon"></use></svg></span>'; | |
| 1463 | - dropdown.appendChild( trigger ); | |
| 1464 | - | |
| 1465 | - ul = document.createElement( 'div' ); | |
| 1466 | - ul.classList.add( 'frm-dropdown-menu', 'dropdown-menu', 'dropdown-menu-right' ); | |
| 1467 | - ul.setAttribute( 'role', 'menu' ); | |
| 1468 | - dropdown.appendChild( ul ); | |
| 1469 | - | |
| 1470 | - return dropdown; | |
| 1471 | - } | |
| 1472 | - | |
| 1473 | - function getSyncLayoutClass( layoutClasses, classToAdd ) { | |
| 1474 | - return function( itemIndex ) { | |
| 1475 | - var currentClassToAdd, length, layoutClassIndex, currentClass, activeLayoutClass, fieldId, layoutClassesInput; | |
| 1476 | - | |
| 1477 | - currentClassToAdd = 'function' === typeof classToAdd ? classToAdd( itemIndex ) : classToAdd; | |
| 1478 | - length = layoutClasses.length; | |
| 1479 | - activeLayoutClass = false; | |
| 1480 | - for ( layoutClassIndex = 0; layoutClassIndex < length; ++layoutClassIndex ) { | |
| 1481 | - currentClass = layoutClasses[ layoutClassIndex ]; | |
| 1482 | - if ( this.classList.contains( currentClass ) ) { | |
| 1483 | - activeLayoutClass = currentClass; | |
| 1484 | - break; | |
| 1485 | - } | |
| 1486 | - } | |
| 1487 | - | |
| 1488 | - fieldId = this.dataset.fid; | |
| 1489 | - | |
| 1490 | - if ( 'undefined' === typeof fieldId ) { | |
| 1491 | - // we are syncing the drag/drop placeholder before the actual field has loaded. | |
| 1492 | - // this will get called again afterward and the input will exist then. | |
| 1493 | - this.classList.add( currentClassToAdd ); | |
| 1494 | - return; | |
| 1495 | - } | |
| 1496 | - | |
| 1497 | - moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) ); | |
| 1498 | - layoutClassesInput = document.getElementById( 'frm_classes_' + fieldId ); | |
| 1499 | - | |
| 1500 | - if ( null === layoutClassesInput ) { | |
| 1501 | - // not every field type has a layout class input. | |
| 1502 | - return; | |
| 1503 | - } | |
| 1504 | - | |
| 1505 | - if ( false === activeLayoutClass ) { | |
| 1506 | - if ( '' !== currentClassToAdd ) { | |
| 1507 | - layoutClassesInput.value = layoutClassesInput.value.concat( ' ' + currentClassToAdd ); | |
| 1508 | - } | |
| 1509 | - } else { | |
| 1510 | - this.classList.remove( activeLayoutClass ); | |
| 1511 | - layoutClassesInput.value = layoutClassesInput.value.replace( activeLayoutClass, currentClassToAdd ); | |
| 1512 | - } | |
| 1513 | - | |
| 1514 | - if ( this.classList.contains( 'frm_first' ) ) { | |
| 1515 | - this.classList.remove( 'frm_first' ); | |
| 1516 | - layoutClassesInput.value = layoutClassesInput.value.replace( 'frm_first', '' ).trim(); | |
| 1517 | - } | |
| 1518 | - | |
| 1519 | - if ( 0 === itemIndex ) { | |
| 1520 | - this.classList.add( 'frm_first' ); | |
| 1521 | - layoutClassesInput.value = layoutClassesInput.value.concat( ' frm_first' ); | |
| 1522 | - } | |
| 1523 | - | |
| 1524 | - jQuery( layoutClassesInput ).trigger( 'change' ); | |
| 1525 | - }; | |
| 1526 | - } | |
| 1527 | - | |
| 1528 | - function getLayoutClasses() { | |
| 1529 | - return [ 'frm_full', 'frm_half', 'frm_third', 'frm_fourth', 'frm_sixth', 'frm_two_thirds', 'frm_three_fourths', 'frm1', 'frm2', 'frm3', 'frm4', 'frm5', 'frm6', 'frm7', 'frm8', 'frm9', 'frm10', 'frm11', 'frm12' ]; | |
| 1530 | - } | |
| 1531 | - | |
| 1532 | - function setupFieldOptionSorting( sort ) { | |
| 1533 | - var opts = { | |
| 1534 | - items: '.frm_sortable_field_opts li', | |
| 1535 | - axis: 'y', | |
| 1536 | - opacity: 0.65, | |
| 1537 | - forcePlaceholderSize: false, | |
| 1538 | - handle: '.frm-drag', | |
| 1539 | - helper: function( e, li ) { | |
| 1540 | - copyHelper = li.clone().insertAfter( li ); | |
| 1541 | - return li.clone(); | |
| 1542 | - }, | |
| 1543 | - stop: function( e, ui ) { | |
| 1544 | - copyHelper && copyHelper.remove(); | |
| 1545 | - var fieldId = ui.item.attr( 'id' ).replace( 'frm_delete_field_', '' ).replace( '-' + ui.item.data( 'optkey' ) + '_container', '' ); | |
| 1546 | - resetDisplayedOpts( fieldId ); | |
| 1547 | - } | |
| 1548 | - }; | |
| 1549 | - jQuery( sort ).sortable( opts ); | |
| 1550 | - } | |
| 1551 | - | |
| 1552 | - // Get the section where a field is dropped | |
| 1553 | - function getSectionForFieldPlacement( currentItem ) { | |
| 1554 | - var section = ''; | |
| 1555 | - if ( typeof currentItem !== 'undefined' && ! currentItem.hasClass( 'edit_field_type_divider' ) ) { | |
| 1556 | - section = currentItem.closest( '.edit_field_type_divider' ); | |
| 1557 | - } | |
| 1558 | - return section; | |
| 1559 | - } | |
| 1560 | - | |
| 1561 | - // Get the form ID where a field is dropped | |
| 1562 | - function getFormIdForFieldPlacement( section ) { | |
| 1563 | - var formId = ''; | |
| 1564 | - | |
| 1565 | - if ( typeof section[0] !== 'undefined' ) { | |
| 1566 | - var sDivide = section.children( '.start_divider' ); | |
| 1567 | - sDivide.children( '.edit_field_type_end_divider' ).appendTo( sDivide ); | |
| 1568 | - if ( typeof section.attr( 'data-formid' ) !== 'undefined' ) { | |
| 1569 | - var fieldId = section.attr( 'data-fid' ); | |
| 1570 | - formId = jQuery( 'input[name="field_options[form_select_' + fieldId + ']"]' ).val(); | |
| 1571 | - } | |
| 1572 | - } | |
| 1573 | - | |
| 1574 | - if ( typeof formId === 'undefined' || formId === '' ) { | |
| 1575 | - formId = thisFormId; | |
| 1576 | - } | |
| 1577 | - | |
| 1578 | - return formId; | |
| 1579 | - } | |
| 1580 | - | |
| 1581 | - // Get the section ID where a field is dropped | |
| 1582 | - function getSectionIdForFieldPlacement( section ) { | |
| 1583 | - var sectionId = 0; | |
| 1584 | - if ( typeof section[0] !== 'undefined' ) { | |
| 1585 | - sectionId = section.attr( 'id' ).replace( 'frm_field_id_', '' ); | |
| 1586 | - } | |
| 1587 | - | |
| 1588 | - return sectionId; | |
| 1589 | - } | |
| 1590 | - | |
| 1591 | - /** | |
| 1592 | - * Update a field after it is dragged and dropped into, out of, or between sections | |
| 1593 | - * | |
| 1594 | - * @param {Object} currentItem | |
| 1595 | - * @param {Object} previousSection | |
| 1596 | - * @returns {void} | |
| 1597 | - */ | |
| 1598 | - function updateFieldAfterMovingBetweenSections( currentItem, previousSection ) { | |
| 1599 | - if ( ! currentItem.hasClass( 'form-field' ) ) { | |
| 1600 | - // currentItem is a field group. Call for children recursively. | |
| 1601 | - getFieldsInRow( jQuery( currentItem.get( 0 ).firstChild ) ).each( | |
| 1602 | - function() { | |
| 1603 | - updateFieldAfterMovingBetweenSections( jQuery( this ), previousSection ); | |
| 1604 | - } | |
| 1605 | - ); | |
| 1606 | - return; | |
| 1607 | - } | |
| 1608 | - | |
| 1609 | - const fieldId = currentItem.attr( 'id' ).replace( 'frm_field_id_', '' ); | |
| 1610 | - const section = getSectionForFieldPlacement( currentItem ); | |
| 1611 | - const formId = getFormIdForFieldPlacement( section ); | |
| 1612 | - const sectionId = getSectionIdForFieldPlacement( section ); | |
| 1613 | - const previousFormId = previousSection ? getFormIdForFieldPlacement( jQuery( previousSection.parentNode ) ) : 0; | |
| 1614 | - | |
| 1615 | - jQuery.ajax({ | |
| 1616 | - type: 'POST', | |
| 1617 | - url: ajaxurl, | |
| 1618 | - data: { | |
| 1619 | - action: 'frm_update_field_after_move', | |
| 1620 | - form_id: formId, | |
| 1621 | - field: fieldId, | |
| 1622 | - section_id: sectionId, | |
| 1623 | - previous_form_id: previousFormId, | |
| 1624 | - nonce: frmGlobal.nonce | |
| 1625 | - }, | |
| 1626 | - success: function() { | |
| 1627 | - toggleSectionHolder(); | |
| 1628 | - updateInSectionValue( fieldId, sectionId ); | |
| 1629 | - } | |
| 1630 | - }); | |
| 1631 | - } | |
| 1632 | - | |
| 1633 | - // Update the in_section field value | |
| 1634 | - function updateInSectionValue( fieldId, sectionId ) { | |
| 1635 | - document.getElementById( 'frm_in_section_' + fieldId ).value = sectionId; | |
| 1636 | - } | |
| 1637 | - | |
| 1638 | - /** | |
| 1639 | - * Add a new field by dragging and dropping it from the Fields sidebar | |
| 1640 | - * | |
| 1641 | - * @param {string} fieldType | |
| 1642 | - */ | |
| 1643 | - function insertNewFieldByDragging( fieldType ) { | |
| 1644 | - const placeholder = document.getElementById( 'frm_drag_placeholder' ); | |
| 1645 | - const loadingID = fieldType.replace( '|', '-' ) + '_' + getAutoId(); | |
| 1646 | - const loading = tag( | |
| 1647 | - 'li', | |
| 1648 | - { | |
| 1649 | - id: loadingID, | |
| 1650 | - className: 'frm-wait frmbutton_loadingnow' | |
| 1651 | - } | |
| 1652 | - ); | |
| 1653 | - const $placeholder = jQuery( loading ); | |
| 1654 | - const currentItem = jQuery( placeholder ); | |
| 1655 | - const section = getSectionForFieldPlacement( currentItem ); | |
| 1656 | - const formId = getFormIdForFieldPlacement( section ); | |
| 1657 | - const sectionId = getSectionIdForFieldPlacement( section ); | |
| 1658 | - | |
| 1659 | - placeholder.parentNode.insertBefore( loading, placeholder ); | |
| 1660 | - placeholder.remove(); | |
| 1661 | - syncLayoutClasses( $placeholder ); | |
| 1662 | - | |
| 1663 | - let hasBreak = 0; | |
| 1664 | - if ( 'summary' === fieldType ) { | |
| 1665 | - // see if we need to insert a page break before this newly-added summary field. Check for at least 1 page break | |
| 1666 | - hasBreak = jQuery( '.frmbutton_loadingnow#' + loadingID ).prevAll( 'li[data-type="break"]' ).length ? 1 : 0; | |
| 1667 | - } | |
| 1668 | - | |
| 1669 | - jQuery.ajax({ | |
| 1670 | - type: 'POST', url: ajaxurl, | |
| 1671 | - data: { | |
| 1672 | - action: 'frm_insert_field', | |
| 1673 | - form_id: formId, | |
| 1674 | - field_type: fieldType, | |
| 1675 | - section_id: sectionId, | |
| 1676 | - nonce: frmGlobal.nonce, | |
| 1677 | - has_break: hasBreak | |
| 1678 | - }, | |
| 1679 | - success: function( msg ) { | |
| 1680 | - let replaceWith; | |
| 1681 | - document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' ); | |
| 1682 | - const $siblings = $placeholder.siblings( 'li.form-field' ).not( '.edit_field_type_end_divider' ); | |
| 1683 | - if ( ! $siblings.length ) { | |
| 1684 | - // if dragging into a new row, we need to wrap the li first. | |
| 1685 | - replaceWith = wrapFieldLi( msg ); | |
| 1686 | - } else { | |
| 1687 | - replaceWith = msgAsjQueryObject( msg ); | |
| 1688 | - if ( ! $placeholder.get( 0 ).parentNode.parentNode.classList.contains( 'ui-draggable' ) ) { | |
| 1689 | - // If a field group wasn't draggable because it only had a single field, make it draggable. | |
| 1690 | - makeDraggable( $placeholder.get( 0 ).parentNode.parentNode, '.frm-move' ); | |
| 1691 | - } | |
| 1692 | - } | |
| 1693 | - $placeholder.replaceWith( replaceWith ); | |
| 1694 | - updateFieldOrder(); | |
| 1695 | - afterAddField( msg, false ); | |
| 1696 | - if ( $siblings.length ) { | |
| 1697 | - syncLayoutClasses( $siblings.first() ); | |
| 1698 | - } | |
| 1699 | - toggleSectionHolder(); | |
| 1700 | - | |
| 1701 | - if ( ! $siblings.length ) { | |
| 1702 | - makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) ); | |
| 1703 | - makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' ); | |
| 1704 | - } else { | |
| 1705 | - makeDraggable( replaceWith.get( 0 ), '.frm-move' ); | |
| 1706 | - } | |
| 1707 | - | |
| 1708 | - }, | |
| 1709 | - error: handleInsertFieldError | |
| 1710 | - }); | |
| 1711 | - } | |
| 1712 | - | |
| 1713 | - function moveFieldThatAlreadyExists( draggable, placeholder ) { | |
| 1714 | - placeholder.parentNode.insertBefore( draggable, placeholder ); | |
| 1715 | - } | |
| 1716 | - | |
| 1717 | - function msgAsjQueryObject( msg ) { | |
| 1718 | - const element = div(); | |
| 1719 | - element.innerHTML = msg; | |
| 1720 | - return jQuery( element.firstChild ); | |
| 1721 | - } | |
| 1722 | - | |
| 1723 | - function handleInsertFieldError( jqXHR, _, errorThrown ) { | |
| 1724 | - maybeShowInsertFieldError( errorThrown, jqXHR ); | |
| 1725 | - } | |
| 1726 | - | |
| 1727 | - function maybeShowInsertFieldError( errorThrown, jqXHR ) { | |
| 1728 | - if ( ! jqXHRAborted( jqXHR ) ) { | |
| 1729 | - infoModal( errorThrown + '. Please try again.' ); | |
| 1730 | - } | |
| 1731 | - } | |
| 1732 | - | |
| 1733 | - function jqXHRAborted( jqXHR ) { | |
| 1734 | - return jqXHR.status === 0 || jqXHR.readyState === 0; | |
| 1735 | - } | |
| 1736 | - | |
| 1737 | - /** | |
| 1738 | - * Get a unique id that automatically increments with every function call. | |
| 1739 | - * Can be used for any UI that requires a unique id. | |
| 1740 | - * Not to be used in data. | |
| 1741 | - * | |
| 1742 | - * @returns {integer} | |
| 1743 | - */ | |
| 1744 | - function getAutoId() { | |
| 1745 | - return ++autoId; | |
| 1746 | - } | |
| 1747 | - | |
| 1748 | - // Don't allow page break, embed form, or section inside section field | |
| 1749 | - // Don't allow page breaks inside of field groups. | |
| 1750 | - // Don't allow field groups with sections inside of sections. | |
| 1751 | - // Don't allow field groups in field groups. | |
| 1752 | - // Don't allow hidden fields inside of field groups but allow them in sections. | |
| 1753 | - function allowDrop( draggable, droppable ) { | |
| 1754 | - if ( false === droppable ) { | |
| 1755 | - // Don't show drop placeholder if dragging somewhere off of the droppable area. | |
| 1756 | - return false; | |
| 1757 | - } | |
| 1758 | - | |
| 1759 | - if ( droppable.closest( '.frm-sortable-helper' ) ) { | |
| 1760 | - // Do not allow drop into draggable. | |
| 1761 | - return false; | |
| 1762 | - } | |
| 1763 | - | |
| 1764 | - if ( 'frm-show-fields' === droppable.id ) { | |
| 1765 | - // Everything can be dropped into the main list of fields. | |
| 1766 | - return true; | |
| 1767 | - } | |
| 1768 | - | |
| 1769 | - if ( ! droppable.classList.contains( 'start_divider' ) ) { | |
| 1770 | - const $fieldsInRow = getFieldsInRow( jQuery( droppable ) ); | |
| 1771 | - if ( ! groupCanFitAnotherField( $fieldsInRow, jQuery( draggable ) ) ) { | |
| 1772 | - // Field group is full and cannot accept another field. | |
| 1773 | - return false; | |
| 1774 | - } | |
| 1775 | - } | |
| 1776 | - | |
| 1777 | - const isNewField = draggable.classList.contains( 'frm-new-field' ); | |
| 1778 | - if ( isNewField ) { | |
| 1779 | - return allowNewFieldDrop( draggable, droppable ); | |
| 1780 | - } | |
| 1781 | - | |
| 1782 | - return allowMoveField( draggable, droppable ); | |
| 1783 | - } | |
| 1784 | - | |
| 1785 | - // Don't allow a new page break or hidden field in a field group. | |
| 1786 | - // Don't allow a new field into a field group that includes a page break or hidden field. | |
| 1787 | - // Don't allow a new section inside of a section. | |
| 1788 | - // Don't allow an embedded form in a section. | |
| 1789 | - function allowNewFieldDrop( draggable, droppable ) { | |
| 1790 | - const classes = draggable.classList; | |
| 1791 | - const newPageBreakField = classes.contains( 'frm_tbreak' ); | |
| 1792 | - const newHiddenField = classes.contains( 'frm_thidden' ); | |
| 1793 | - const newSectionField = classes.contains( 'frm_tdivider' ); | |
| 1794 | - const newEmbedField = classes.contains( 'frm_tform' ); | |
| 1795 | - | |
| 1796 | - const newFieldWillBeAddedToAGroup = ! ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) ); | |
| 1797 | - if ( newFieldWillBeAddedToAGroup ) { | |
| 1798 | - if ( groupIncludesBreakOrHidden( droppable ) ) { | |
| 1799 | - // Never allow any field beside a page break or a hidden field. | |
| 1800 | - return false; | |
| 1801 | - } | |
| 1802 | - | |
| 1803 | - return ! newHiddenField && ! newPageBreakField; | |
| 1804 | - } | |
| 1805 | - | |
| 1806 | - const fieldTypeIsAlwaysAllowed = ! newPageBreakField && ! newHiddenField && ! newSectionField && ! newEmbedField; | |
| 1807 | - if ( fieldTypeIsAlwaysAllowed ) { | |
| 1808 | - return true; | |
| 1809 | - } | |
| 1810 | - | |
| 1811 | - const newFieldWillBeAddedToASection = droppable.classList.contains( 'start_divider' ) || null !== droppable.closest( '.start_divider' ); | |
| 1812 | - if ( newFieldWillBeAddedToASection ) { | |
| 1813 | - // Don't allow a section or an embedded form in a section. | |
| 1814 | - return ! newEmbedField && ! newSectionField; | |
| 1815 | - } | |
| 1816 | - | |
| 1817 | - return true; | |
| 1818 | - } | |
| 1819 | - | |
| 1820 | - function allowMoveField( draggable, droppable ) { | |
| 1821 | - if ( isFieldGroup( draggable ) ) { | |
| 1822 | - return allowMoveFieldGroup( draggable, droppable ); | |
| 1823 | - } | |
| 1824 | - | |
| 1825 | - const isPageBreak = draggable.classList.contains( 'edit_field_type_break' ); | |
| 1826 | - if ( isPageBreak ) { | |
| 1827 | - // Page breaks are only allowed in the main list of fields, not in sections or in field groups. | |
| 1828 | - return false; | |
| 1829 | - } | |
| 1830 | - | |
| 1831 | - if ( droppable.classList.contains( 'start_divider' ) ) { | |
| 1832 | - return allowMoveFieldToSection( draggable ); | |
| 1833 | - } | |
| 1834 | - | |
| 1835 | - const isHiddenField = draggable.classList.contains( 'edit_field_type_hidden' ); | |
| 1836 | - if ( isHiddenField ) { | |
| 1837 | - // Hidden fields should not be added to field groups since they're not shown and don't make sense with the grid distribution. | |
| 1838 | - return false; | |
| 1839 | - } | |
| 1840 | - | |
| 1841 | - return allowMoveFieldToGroup( draggable, droppable ); | |
| 1842 | - } | |
| 1843 | - | |
| 1844 | - function isFieldGroup( draggable ) { | |
| 1845 | - return draggable.classList.contains( 'frm_field_box' ) && ! draggable.classList.contains( 'form-field' ); | |
| 1846 | - } | |
| 1847 | - | |
| 1848 | - function allowMoveFieldGroup( fieldGroup, droppable ) { | |
| 1849 | - if ( droppable.classList.contains( 'start_divider' ) && null === fieldGroup.querySelector( '.start_divider' ) ) { | |
| 1850 | - // Allow a field group with no section inside of a section. | |
| 1851 | - return true; | |
| 1852 | - } | |
| 1853 | - return false; | |
| 1854 | - } | |
| 1855 | - | |
| 1856 | - function allowMoveFieldToSection( draggable ) { | |
| 1857 | - const draggableIncludeEmbedForm = draggable.classList.contains( 'edit_field_type_form' ) || draggable.querySelector( '.edit_field_type_form' ); | |
| 1858 | - if ( draggableIncludeEmbedForm ) { | |
| 1859 | - // Do not allow an embedded form inside of a section. | |
| 1860 | - return false; | |
| 1861 | - } | |
| 1862 | - | |
| 1863 | - const draggableIncludesSection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' ); | |
| 1864 | - if ( draggableIncludesSection ) { | |
| 1865 | - // Do not allow a section inside of a section. | |
| 1866 | - return false; | |
| 1867 | - } | |
| 1868 | - | |
| 1869 | - return true; | |
| 1870 | - } | |
| 1871 | - | |
| 1872 | - function allowMoveFieldToGroup( draggable, group ) { | |
| 1873 | - if ( groupIncludesBreakOrHidden( group ) ) { | |
| 1874 | - // Never allow any field beside a page break or a hidden field. | |
| 1875 | - return false; | |
| 1876 | - } | |
| 1877 | - | |
| 1878 | - const isFieldGroup = jQuery( draggable ).children( 'ul.frm_sorting' ).not( '.start_divider' ).length > 0; | |
| 1879 | - if ( isFieldGroup ) { | |
| 1880 | - // Do not allow a field group directly inside of a field group unless it's in a section. | |
| 1881 | - return false; | |
| 1882 | - } | |
| 1883 | - | |
| 1884 | - const draggableIncludesASection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' ); | |
| 1885 | - const draggableIsEmbedField = draggable.classList.contains( 'edit_field_type_form' ); | |
| 1886 | - const groupIsInASection = null !== group.closest( '.start_divider' ); | |
| 1887 | - if ( groupIsInASection && ( draggableIncludesASection || draggableIsEmbedField ) ) { | |
| 1888 | - // Do not allow a section or an embed field inside of a section. | |
| 1889 | - return false; | |
| 1890 | - } | |
| 1891 | - | |
| 1892 | - return true; | |
| 1893 | - } | |
| 1894 | - | |
| 1895 | - function groupIncludesBreakOrHidden( group ) { | |
| 1896 | - return null !== group.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ); | |
| 1897 | - } | |
| 1898 | - | |
| 1899 | - function groupCanFitAnotherField( fieldsInRow, $field ) { | |
| 1900 | - var fieldId; | |
| 1901 | - if ( fieldsInRow.length < 6 ) { | |
| 1902 | - return true; | |
| 1903 | - } | |
| 1904 | - if ( fieldsInRow.length > 6 ) { | |
| 1905 | - return false; | |
| 1906 | - } | |
| 1907 | - fieldId = $field.attr( 'data-fid' ); | |
| 1908 | - // allow 6 if we're not changing field groups. | |
| 1909 | - return 1 === jQuery( fieldsInRow ).filter( '[data-fid="' + fieldId + '"]' ).length; | |
| 1910 | - } | |
| 1911 | - | |
| 1912 | - function loadFields( fieldId ) { | |
| 1913 | - const thisField = document.getElementById( fieldId ); | |
| 1914 | - const $thisField = jQuery( thisField ); | |
| 1915 | - const field = []; | |
| 1916 | - const addHtmlToField = element => { | |
| 1917 | - const frmHiddenFdata = element.querySelector( '.frm_hidden_fdata' ); | |
| 1918 | - element.classList.add( 'frm_load_now' ); | |
| 1919 | - if ( frmHiddenFdata !== null ) { | |
| 1920 | - field.push( frmHiddenFdata.innerHTML ); | |
| 1921 | - } | |
| 1922 | - }; | |
| 1923 | - | |
| 1924 | - let nextElement = thisField; | |
| 1925 | - addHtmlToField( nextElement ); | |
| 1926 | - while ( nextElement.nextElementSibling && field.length < 15 ) { | |
| 1927 | - addHtmlToField( nextElement.nextElementSibling ); | |
| 1928 | - nextElement = nextElement.nextElementSibling; | |
| 1929 | - } | |
| 1930 | - | |
| 1931 | - jQuery.ajax({ | |
| 1932 | - type: 'POST', | |
| 1933 | - url: ajaxurl, | |
| 1934 | - data: { | |
| 1935 | - action: 'frm_load_field', | |
| 1936 | - field: field, | |
| 1937 | - form_id: thisFormId, | |
| 1938 | - nonce: frmGlobal.nonce | |
| 1939 | - }, | |
| 1940 | - success: html => handleAjaxLoadFieldSuccess( html, $thisField, field ) | |
| 1941 | - }); | |
| 1942 | - } | |
| 1943 | - | |
| 1944 | - function handleAjaxLoadFieldSuccess( html, $thisField, field ) { | |
| 1945 | - let key, $nextSet; | |
| 1946 | - | |
| 1947 | - html = html.replace( /^\s+|\s+$/g, '' ); | |
| 1948 | - if ( html.indexOf( '{' ) !== 0 ) { | |
| 1949 | - jQuery( '.frm_load_now' ).removeClass( '.frm_load_now' ).html( 'Error' ); | |
| 1950 | - return; | |
| 1951 | - } | |
| 1952 | - | |
| 1953 | - html = JSON.parse( html ); | |
| 1954 | - for ( key in html ) { | |
| 1955 | - jQuery( '#frm_field_id_' + key ).replaceWith( html[key]); | |
| 1956 | - setupSortable( '#frm_field_id_' + key + '.edit_field_type_divider ul.frm_sorting' ); | |
| 1957 | - makeDraggable( document.getElementById( 'frm_field_id_' + key ) ); | |
| 1958 | - } | |
| 1959 | - | |
| 1960 | - $nextSet = $thisField.nextAll( '.frm_field_loading:not(.frm_load_now)' ); | |
| 1961 | - if ( $nextSet.length ) { | |
| 1962 | - loadFields( $nextSet.attr( 'id' ) ); | |
| 1963 | - } else { | |
| 1964 | - // go up a level | |
| 1965 | - $nextSet = jQuery( document.getElementById( 'frm-show-fields' ) ).find( '.frm_field_loading:not(.frm_load_now)' ); | |
| 1966 | - if ( $nextSet.length ) { | |
| 1967 | - loadFields( $nextSet.attr( 'id' ) ); | |
| 1968 | - } | |
| 1969 | - } | |
| 1970 | - | |
| 1971 | - initiateMultiselect(); | |
| 1972 | - renumberPageBreaks(); | |
| 1973 | - maybeHideQuantityProductFieldOption(); | |
| 1974 | - | |
| 1975 | - const loadedEvent = new Event( 'frm_ajax_loaded_field', { bubbles: false }); | |
| 1976 | - loadedEvent.frmFields = field.map( f => JSON.parse( f ) ); | |
| 1977 | - document.dispatchEvent( loadedEvent ); | |
| 1978 | - } | |
| 1979 | - | |
| 1980 | - function addFieldClick() { | |
| 1981 | - /*jshint validthis:true */ | |
| 1982 | - const $thisObj = jQuery( this ); | |
| 1983 | - // there is no real way to disable a <a> (with a valid href attribute) in HTML - https://css-tricks.com/how-to-disable-links/ | |
| 1984 | - if ( $thisObj.hasClass( 'disabled' ) ) { | |
| 1985 | - return false; | |
| 1986 | - } | |
| 1987 | - | |
| 1988 | - const $button = $thisObj.closest( '.frmbutton' ); | |
| 1989 | - const fieldType = $button.attr( 'id' ); | |
| 1990 | - | |
| 1991 | - let hasBreak = 0; | |
| 1992 | - if ( 'summary' === fieldType ) { | |
| 1993 | - hasBreak = $newFields.children( 'li[data-type="break"]' ).length > 0 ? 1 : 0; | |
| 1994 | - } | |
| 1995 | - | |
| 1996 | - const formId = thisFormId; | |
| 1997 | - jQuery.ajax({ | |
| 1998 | - type: 'POST', | |
| 1999 | - url: ajaxurl, | |
| 2000 | - data: { | |
| 2001 | - action: 'frm_insert_field', | |
| 2002 | - form_id: formId, | |
| 2003 | - field_type: fieldType, | |
| 2004 | - section_id: 0, | |
| 2005 | - nonce: frmGlobal.nonce, | |
| 2006 | - has_break: hasBreak | |
| 2007 | - }, | |
| 2008 | - success: function( msg ) { | |
| 2009 | - document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' ); | |
| 2010 | - const replaceWith = wrapFieldLi( msg ); | |
| 2011 | - $newFields.append( replaceWith ); | |
| 2012 | - afterAddField( msg, true ); | |
| 2013 | - | |
| 2014 | - replaceWith.each( | |
| 2015 | - function() { | |
| 2016 | - makeDroppable( this.querySelector( 'ul.frm_sorting' ) ); | |
| 2017 | - makeDraggable( this.querySelector( '.form-field' ), '.frm-move' ); | |
| 2018 | - } | |
| 2019 | - ); | |
| 2020 | - }, | |
| 2021 | - error: handleInsertFieldError | |
| 2022 | - }); | |
| 2023 | - return false; | |
| 2024 | - } | |
| 2025 | - | |
| 2026 | - function maybeHideQuantityProductFieldOption() { | |
| 2027 | - var hide = true, | |
| 2028 | - opts = document.querySelectorAll( '.frmjs_prod_field_opt_cont' ); | |
| 2029 | - | |
| 2030 | - if ( $newFields.find( 'li.edit_field_type_product' ).length > 1 ) { | |
| 2031 | - hide = false; | |
| 2032 | - } | |
| 2033 | - | |
| 2034 | - for ( var i = 0; i < opts.length; i++ ) { | |
| 2035 | - if ( hide ) { | |
| 2036 | - opts[ i ].classList.add( 'frm_hidden' ); | |
| 2037 | - } else { | |
| 2038 | - opts[ i ].classList.remove( 'frm_hidden' ); | |
| 2039 | - } | |
| 2040 | - } | |
| 2041 | - } | |
| 2042 | - | |
| 2043 | - function duplicateField() { | |
| 2044 | - var $field, fieldId, children, newRowId, fieldOrder; | |
| 2045 | - | |
| 2046 | - $field = jQuery( this ).closest( 'li.form-field' ); | |
| 2047 | - | |
| 2048 | - if ( $field.hasClass( 'frm-page-collapsed' ) ) { | |
| 2049 | - return false; | |
| 2050 | - } | |
| 2051 | - | |
| 2052 | - closeOpenFieldDropdowns(); | |
| 2053 | - fieldId = $field.data( 'fid' ); | |
| 2054 | - children = fieldsInSection( fieldId ); | |
| 2055 | - newRowId = this.getAttribute( 'frm-target-row-id' ); | |
| 2056 | - | |
| 2057 | - if ( null !== newRowId ) { | |
| 2058 | - fieldOrder = this.getAttribute( 'frm-field-order' ); | |
| 2059 | - } | |
| 2060 | - | |
| 2061 | - jQuery.ajax({ | |
| 2062 | - type: 'POST', | |
| 2063 | - url: ajaxurl, | |
| 2064 | - data: { | |
| 2065 | - action: 'frm_duplicate_field', | |
| 2066 | - field_id: fieldId, | |
| 2067 | - form_id: thisFormId, | |
| 2068 | - children: children, | |
| 2069 | - nonce: frmGlobal.nonce | |
| 2070 | - }, | |
| 2071 | - success: function( msg ) { | |
| 2072 | - var newRow; | |
| 2073 | - | |
| 2074 | - let replaceWith; | |
| 2075 | - | |
| 2076 | - if ( null !== newRowId ) { | |
| 2077 | - newRow = document.getElementById( newRowId ); | |
| 2078 | - if ( null !== newRow ) { | |
| 2079 | - replaceWith = msgAsjQueryObject( msg ); | |
| 2080 | - jQuery( newRow ).append( replaceWith ); | |
| 2081 | - makeDraggable( replaceWith.get( 0 ), '.frm-move' ); | |
| 2082 | - if ( null !== fieldOrder ) { | |
| 2083 | - newRow.lastElementChild.setAttribute( 'frm-field-order', fieldOrder ); | |
| 2084 | - } | |
| 2085 | - jQuery( newRow ).trigger( | |
| 2086 | - 'frm_added_duplicated_field_to_row', | |
| 2087 | - { | |
| 2088 | - duplicatedFieldHtml: msg, | |
| 2089 | - originalFieldId: fieldId | |
| 2090 | - } | |
| 2091 | - ); | |
| 2092 | - afterAddField( msg, false ); | |
| 2093 | - return; | |
| 2094 | - } | |
| 2095 | - } | |
| 2096 | - | |
| 2097 | - if ( $field.siblings( 'li.form-field' ).length ) { | |
| 2098 | - replaceWith = msgAsjQueryObject( msg ); | |
| 2099 | - $field.after( replaceWith ); | |
| 2100 | - syncLayoutClasses( $field ); | |
| 2101 | - makeDraggable( replaceWith.get( 0 ), '.frm-move' ); | |
| 2102 | - } else { | |
| 2103 | - replaceWith = wrapFieldLi( msg ); | |
| 2104 | - $field.parent().parent().after( replaceWith ); | |
| 2105 | - makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) ); | |
| 2106 | - makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' ); | |
| 2107 | - } | |
| 2108 | - | |
| 2109 | - updateFieldOrder(); | |
| 2110 | - afterAddField( msg, false ); | |
| 2111 | - maybeDuplicateUnsavedSettings( fieldId, msg ); | |
| 2112 | - toggleOneSectionHolder( replaceWith.find( '.start_divider' ) ); | |
| 2113 | - $field[0].querySelector( '.frm-dropdown-menu.dropdown-menu-right' )?.classList.remove( 'show' ); | |
| 2114 | - } | |
| 2115 | - }); | |
| 2116 | - return false; | |
| 2117 | - } | |
| 2118 | - | |
| 2119 | - function maybeDuplicateUnsavedSettings( originalFieldId, newFieldHtml ) { | |
| 2120 | - var originalSettings, newFieldId, copySettings, fieldOptionKeys, originalDefault, copyDefault; | |
| 2121 | - | |
| 2122 | - originalSettings = document.getElementById( 'frm-single-settings-' + originalFieldId ); | |
| 2123 | - if ( null === originalSettings ) { | |
| 2124 | - return; | |
| 2125 | - } | |
| 2126 | - | |
| 2127 | - newFieldId = jQuery( newFieldHtml ).attr( 'data-fid' ); | |
| 2128 | - if ( 'undefined' === typeof newFieldId ) { | |
| 2129 | - return; | |
| 2130 | - } | |
| 2131 | - | |
| 2132 | - copySettings = document.getElementById( 'frm-single-settings-' + newFieldId ); | |
| 2133 | - if ( null === copySettings ) { | |
| 2134 | - return; | |
| 2135 | - } | |
| 2136 | - | |
| 2137 | - fieldOptionKeys = [ | |
| 2138 | - 'name', 'required', 'unique', 'read_only', 'placeholder', 'description', 'size', 'max', 'format', 'prepend', 'append', 'separate_value' | |
| 2139 | - ]; | |
| 2140 | - | |
| 2141 | - originalSettings.querySelectorAll( 'input[name^="field_options["], textarea[name^="field_options["]' ).forEach( | |
| 2142 | - function( originalSetting ) { | |
| 2143 | - var key, tagType, copySetting; | |
| 2144 | - | |
| 2145 | - key = getKeyFromSettingInput( originalSetting ); | |
| 2146 | - | |
| 2147 | - if ( 'options' === key ) { | |
| 2148 | - copyOption( originalSetting, copySettings, originalFieldId, newFieldId ); | |
| 2149 | - return; | |
| 2150 | - } | |
| 2151 | - | |
| 2152 | - if ( -1 === fieldOptionKeys.indexOf( key ) ) { | |
| 2153 | - return; | |
| 2154 | - } | |
| 2155 | - | |
| 2156 | - tagType = originalSetting.matches( 'input' ) ? 'input' : 'textarea'; | |
| 2157 | - copySetting = copySettings.querySelector( tagType + '[name="field_options[' + key + '_' + newFieldId + ']"]' ); | |
| 2158 | - if ( null === copySetting ) { | |
| 2159 | - return; | |
| 2160 | - } | |
| 2161 | - | |
| 2162 | - if ( 'checkbox' === originalSetting.type ) { | |
| 2163 | - if ( originalSetting.checked !== copySetting.checked ) { | |
| 2164 | - jQuery( copySetting ).trigger( 'click' ); | |
| 2165 | - } | |
| 2166 | - } else if ( 'text' === originalSetting.type || 'textarea' === tagType ) { | |
| 2167 | - if ( originalSetting.value !== copySetting.value ) { | |
| 2168 | - copySetting.value = originalSetting.value; | |
| 2169 | - jQuery( copySetting ).trigger( 'change' ); | |
| 2170 | - } | |
| 2171 | - } | |
| 2172 | - } | |
| 2173 | - ); | |
| 2174 | - | |
| 2175 | - originalDefault = originalSettings.querySelector( 'input[name="default_value_' + originalFieldId + '"]' ); | |
| 2176 | - if ( null !== originalDefault ) { | |
| 2177 | - copyDefault = copySettings.querySelector( 'input[name="default_value_' + newFieldId + '"]' ); | |
| 2178 | - if ( null !== copyDefault && originalDefault.value !== copyDefault.value ) { | |
| 2179 | - copyDefault.value = originalDefault.value; | |
| 2180 | - jQuery( copyDefault ).trigger( 'change' ); | |
| 2181 | - } | |
| 2182 | - } | |
| 2183 | - } | |
| 2184 | - | |
| 2185 | - function copyOption( originalSetting, copySettings, originalFieldId, newFieldId ) { | |
| 2186 | - var remainingKeyDetails, copyKey, copySetting; | |
| 2187 | - remainingKeyDetails = originalSetting.name.substr( 23 + ( '' + originalFieldId ).length ); | |
| 2188 | - copyKey = 'field_options[options_' + newFieldId + ']' + remainingKeyDetails; | |
| 2189 | - copySetting = copySettings.querySelector( 'input[name="' + copyKey + '"]' ); | |
| 2190 | - if ( null !== copySetting && copySetting.value !== originalSetting.value ) { | |
| 2191 | - copySetting.value = originalSetting.value; | |
| 2192 | - jQuery( copySetting ).trigger( 'change' ); | |
| 2193 | - } | |
| 2194 | - } | |
| 2195 | - | |
| 2196 | - function getKeyFromSettingInput( input ) { | |
| 2197 | - var nameWithoutPrefix, nameSplit; | |
| 2198 | - nameWithoutPrefix = input.name.substr( 14 ); | |
| 2199 | - nameSplit = nameWithoutPrefix.split( '_' ); | |
| 2200 | - nameSplit.pop(); | |
| 2201 | - return nameSplit.join( '_' ); | |
| 2202 | - } | |
| 2203 | - | |
| 2204 | - function closeOpenFieldDropdowns() { | |
| 2205 | - var openSettings = document.querySelector( '.frm-field-settings-open' ); | |
| 2206 | - if ( null !== openSettings ) { | |
| 2207 | - openSettings.classList.remove( 'frm-field-settings-open' ); | |
| 2208 | - jQuery( document ).off( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings ); | |
| 2209 | - jQuery( '.frm-field-action-icons .dropdown.open' ).removeClass( 'open' ); | |
| 2210 | - } | |
| 2211 | - } | |
| 2212 | - | |
| 2213 | - function handleClickOutsideOfFieldSettings( event ) { | |
| 2214 | - if ( ! jQuery( event.originalEvent.target ).closest( '.frm-field-action-icons' ).length ) { | |
| 2215 | - closeOpenFieldDropdowns(); | |
| 2216 | - } | |
| 2217 | - } | |
| 2218 | - | |
| 2219 | - function checkForMultiselectKeysOnMouseMove( event ) { | |
| 2220 | - var keyIsDown = ! ! ( event.ctrlKey || event.metaKey || event.shiftKey ); | |
| 2221 | - jQuery( document.getElementById( 'frm_builder_page' ) ).toggleClass( 'frm-multiselect-key-is-down', keyIsDown ); | |
| 2222 | - checkForActiveHoverTarget( event ); | |
| 2223 | - } | |
| 2224 | - | |
| 2225 | - function checkForActiveHoverTarget( event ) { | |
| 2226 | - var container, elementFromPoint, list, previousHoverTarget; | |
| 2227 | - | |
| 2228 | - container = postBodyContent; | |
| 2229 | - if ( container.classList.contains( 'frm-dragging-field' ) ) { | |
| 2230 | - return; | |
| 2231 | - } | |
| 2232 | - | |
| 2233 | - if ( null !== document.querySelector( '.frm-field-group-hover-target .frm-field-settings-open' ) ) { | |
| 2234 | - // do not set a hover target if a dropdown is open for the current hover target. | |
| 2235 | - return; | |
| 2236 | - } | |
| 2237 | - | |
| 2238 | - elementFromPoint = document.elementFromPoint( event.clientX, event.clientY ); | |
| 2239 | - if ( null !== elementFromPoint && ! elementFromPoint.classList.contains( 'edit_field_type_divider' ) ) { | |
| 2240 | - | |
| 2241 | - list = elementFromPoint.closest( 'ul.frm_sorting' ); | |
| 2242 | - | |
| 2243 | - if ( null !== list && ! list.classList.contains( 'start_divider' ) && 'frm-show-fields' !== list.id ) { | |
| 2244 | - previousHoverTarget = maybeRemoveGroupHoverTarget(); | |
| 2245 | - if ( false !== previousHoverTarget && ! jQuery( previousHoverTarget ).is( list ) ) { | |
| 2246 | - destroyFieldGroupPopup(); | |
| 2247 | - } | |
| 2248 | - updateFieldGroupControls( jQuery( list ), getFieldsInRow( jQuery( list ) ).length ); | |
| 2249 | - list.classList.add( 'frm-field-group-hover-target' ); | |
| 2250 | - jQuery( '#wpbody-content' ).on( 'mousemove', maybeRemoveHoverTargetOnMouseMove ); | |
| 2251 | - } | |
| 2252 | - } | |
| 2253 | - } | |
| 2254 | - | |
| 2255 | - function maybeRemoveGroupHoverTarget() { | |
| 2256 | - var controls, previousHoverTarget; | |
| 2257 | - | |
| 2258 | - controls = document.getElementById( 'frm_field_group_controls' ); | |
| 2259 | - if ( null !== controls ) { | |
| 2260 | - controls.style.display = 'none'; | |
| 2261 | - } | |
| 2262 | - | |
| 2263 | - previousHoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 2264 | - if ( null === previousHoverTarget ) { | |
| 2265 | - return false; | |
| 2266 | - } | |
| 2267 | - | |
| 2268 | - jQuery( '#wpbody-content' ).off( 'mousemove', maybeRemoveHoverTargetOnMouseMove ); | |
| 2269 | - previousHoverTarget.classList.remove( 'frm-field-group-hover-target' ); | |
| 2270 | - return previousHoverTarget; | |
| 2271 | - } | |
| 2272 | - | |
| 2273 | - function maybeRemoveHoverTargetOnMouseMove( event ) { | |
| 2274 | - var elementFromPoint = document.elementFromPoint( event.clientX, event.clientY ); | |
| 2275 | - if ( null !== elementFromPoint && null !== elementFromPoint.closest( '#frm-show-fields' ) ) { | |
| 2276 | - return; | |
| 2277 | - } | |
| 2278 | - maybeRemoveGroupHoverTarget(); | |
| 2279 | - } | |
| 2280 | - | |
| 2281 | - function onFieldActionDropdownShow( isFieldGroup ) { | |
| 2282 | - unselectFieldGroups(); | |
| 2283 | - // maybe offset the dropdown if it goes off of the right of the screen. | |
| 2284 | - setTimeout( | |
| 2285 | - function() { | |
| 2286 | - var ul, $ul; | |
| 2287 | - ul = document.querySelector( '.dropdown.show .frm-dropdown-menu' ); | |
| 2288 | - if ( null === ul ) { | |
| 2289 | - return; | |
| 2290 | - } | |
| 2291 | - if ( null === ul.getAttribute( 'aria-label' ) ) { | |
| 2292 | - ul.setAttribute( 'aria-label', __( 'More Options', 'formidable' ) ); | |
| 2293 | - } | |
| 2294 | - if ( 0 === ul.children.length ) { | |
| 2295 | - fillFieldActionDropdown( ul, true === isFieldGroup ); | |
| 2296 | - } | |
| 2297 | - $ul = jQuery( ul ); | |
| 2298 | - if ( $ul.offset().left > jQuery( window ).width() - $ul.outerWidth() ) { | |
| 2299 | - ul.style.left = ( -$ul.outerWidth() ) + 'px'; | |
| 2300 | - } | |
| 2301 | - const firstAnchor = ul.firstElementChild.querySelector( 'a' ); | |
| 2302 | - if ( firstAnchor ) { | |
| 2303 | - firstAnchor.focus(); | |
| 2304 | - } | |
| 2305 | - }, | |
| 2306 | - 0 | |
| 2307 | - ); | |
| 2308 | - } | |
| 2309 | - | |
| 2310 | - function onFieldGroupActionDropdownShow() { | |
| 2311 | - onFieldActionDropdownShow( true ); | |
| 2312 | - } | |
| 2313 | - | |
| 2314 | - function changeSectionStyle( e ) { | |
| 2315 | - const collapsedSection = e.target.closest( '.frm-section-collapsed' ); | |
| 2316 | - if ( ! collapsedSection ) { | |
| 2317 | - return; | |
| 2318 | - } | |
| 2319 | - | |
| 2320 | - if ( e.type === 'show' ) { | |
| 2321 | - collapsedSection.style.zIndex = 3; | |
| 2322 | - } else { | |
| 2323 | - collapsedSection.style.zIndex = 1; | |
| 2324 | - } | |
| 2325 | - } | |
| 2326 | - | |
| 2327 | - function fillFieldActionDropdown( ul, isFieldGroup ) { | |
| 2328 | - var classSuffix, options; | |
| 2329 | - classSuffix = isFieldGroup ? '_field_group' : '_field'; | |
| 2330 | - options = [ getDeleteActionOption( isFieldGroup ), getDuplicateActionOption( isFieldGroup ) ]; | |
| 2331 | - if ( ! isFieldGroup ) { | |
| 2332 | - options.push( | |
| 2333 | - { class: 'frm_select', icon: 'frm_settings_icon', label: __( 'Field Settings', 'formidable' ) } | |
| 2334 | - ); | |
| 2335 | - } | |
| 2336 | - options.forEach( | |
| 2337 | - function( option ) { | |
| 2338 | - var li, anchor, span; | |
| 2339 | - li = document.createElement( 'div' ); | |
| 2340 | - li.classList.add( 'frm_more_options_li', 'dropdown-item' ); | |
| 2341 | - | |
| 2342 | - anchor = document.createElement( 'a' ); | |
| 2343 | - anchor.classList.add( option.class + classSuffix ); | |
| 2344 | - anchor.setAttribute( 'href', '#' ); | |
| 2345 | - makeTabbable( anchor ); | |
| 2346 | - | |
| 2347 | - span = document.createElement( 'span' ); | |
| 2348 | - span.textContent = option.label; | |
| 2349 | - anchor.innerHTML = '<svg class="frmsvg"><use xlink:href="#' + option.icon + '"></use></svg>'; | |
| 2350 | - anchor.appendChild( document.createTextNode( ' ' ) ); | |
| 2351 | - anchor.appendChild( span ); | |
| 2352 | - | |
| 2353 | - li.appendChild( anchor ); | |
| 2354 | - ul.appendChild( li ); | |
| 2355 | - } | |
| 2356 | - ); | |
| 2357 | - } | |
| 2358 | - | |
| 2359 | - function getDeleteActionOption( isFieldGroup ) { | |
| 2360 | - var option = { class: 'frm_delete', icon: 'frm_delete_icon' }; | |
| 2361 | - option.label = isFieldGroup ? __( 'Delete Group', 'formidable' ) : __( 'Delete', 'formidable' ); | |
| 2362 | - return option; | |
| 2363 | - } | |
| 2364 | - | |
| 2365 | - function getDuplicateActionOption( isFieldGroup ) { | |
| 2366 | - var option = { class: 'frm_clone', icon: 'frm_clone_icon' }; | |
| 2367 | - option.label = isFieldGroup ? __( 'Duplicate Group', 'formidable' ) : __( 'Duplicate', 'formidable' ); | |
| 2368 | - return option; | |
| 2369 | - } | |
| 2370 | - | |
| 2371 | - function wrapFieldLi( field ) { | |
| 2372 | - const wrapper = div(); | |
| 2373 | - | |
| 2374 | - if ( 'string' === typeof field ) { | |
| 2375 | - wrapper.innerHTML = field; | |
| 2376 | - } else { | |
| 2377 | - wrapper.appendChild( field ); | |
| 2378 | - } | |
| 2379 | - | |
| 2380 | - let result = jQuery(); | |
| 2381 | - Array.from( wrapper.children ).forEach( | |
| 2382 | - li => { | |
| 2383 | - result = result.add( | |
| 2384 | - jQuery( '<li>' ) | |
| 2385 | - .addClass( 'frm_field_box' ) | |
| 2386 | - .html( | |
| 2387 | - jQuery( '<ul>' ).addClass( 'frm_grid_container frm_sorting' ).append( li ) | |
| 2388 | - ) | |
| 2389 | - ); | |
| 2390 | - } | |
| 2391 | - ); | |
| 2392 | - | |
| 2393 | - return result; | |
| 2394 | - } | |
| 2395 | - | |
| 2396 | - function wrapFieldLiInPlace( li ) { | |
| 2397 | - const ul = tag( | |
| 2398 | - 'ul', | |
| 2399 | - { | |
| 2400 | - className: 'frm_grid_container frm_sorting' | |
| 2401 | - } | |
| 2402 | - ); | |
| 2403 | - const wrapper = tag( | |
| 2404 | - 'li', | |
| 2405 | - { | |
| 2406 | - className: 'frm_field_box', | |
| 2407 | - child: ul | |
| 2408 | - } | |
| 2409 | - ); | |
| 2410 | - | |
| 2411 | - li.replaceWith( wrapper ); | |
| 2412 | - ul.appendChild( li ); | |
| 2413 | - | |
| 2414 | - makeDroppable( ul ); | |
| 2415 | - makeDraggable( wrapper, '.frm-move' ); | |
| 2416 | - } | |
| 2417 | - | |
| 2418 | - function afterAddField( msg, addFocus ) { | |
| 2419 | - var regex = /id="(\S+)"/, | |
| 2420 | - match = regex.exec( msg ), | |
| 2421 | - field = document.getElementById( match[1]), | |
| 2422 | - section = '#' + match[1] + '.edit_field_type_divider ul.frm_sorting.start_divider', | |
| 2423 | - $thisSection = jQuery( section ), | |
| 2424 | - type = field.getAttribute( 'data-type' ), | |
| 2425 | - toggled = false, | |
| 2426 | - $parentSection; | |
| 2427 | - | |
| 2428 | - setupSortable( section ); | |
| 2429 | - | |
| 2430 | - if ( 'quantity' === type ) { | |
| 2431 | - // try to automatically attach a product field | |
| 2432 | - maybeSetProductField( field ); | |
| 2433 | - } | |
| 2434 | - | |
| 2435 | - if ( 'product' === type || 'quantity' === type ) { | |
| 2436 | - // quantity too needs to be a part of the if stmt especially cos of the very | |
| 2437 | - // 1st quantity field (or even if it's just one quantity field in the form). | |
| 2438 | - maybeHideQuantityProductFieldOption(); | |
| 2439 | - } | |
| 2440 | - | |
| 2441 | - if ( $thisSection.length ) { | |
| 2442 | - $thisSection.parent( '.frm_field_box' ).children( '.frm_no_section_fields' ).addClass( 'frm_block' ); | |
| 2443 | - } else { | |
| 2444 | - $parentSection = jQuery( field ).closest( 'ul.frm_sorting.start_divider' ); | |
| 2445 | - if ( $parentSection.length ) { | |
| 2446 | - toggleOneSectionHolder( $parentSection ); | |
| 2447 | - toggled = true; | |
| 2448 | - } | |
| 2449 | - } | |
| 2450 | - | |
| 2451 | - if ( msg.indexOf( 'frm-collapse-page' ) !== -1 ) { | |
| 2452 | - renumberPageBreaks(); | |
| 2453 | - } | |
| 2454 | - | |
| 2455 | - addClass( field, 'frm-newly-added' ); | |
| 2456 | - setTimeout( function() { | |
| 2457 | - field.classList.remove( 'frm-newly-added' ); | |
| 2458 | - }, 1000 ); | |
| 2459 | - | |
| 2460 | - if ( addFocus ) { | |
| 2461 | - var bounding = field.getBoundingClientRect(), | |
| 2462 | - container = document.getElementById( 'post-body-content' ), | |
| 2463 | - inView = ( bounding.top >= 0 && | |
| 2464 | - bounding.left >= 0 && | |
| 2465 | - bounding.right <= ( window.innerWidth || document.documentElement.clientWidth ) && | |
| 2466 | - bounding.bottom <= ( window.innerHeight || document.documentElement.clientHeight ) | |
| 2467 | - ); | |
| 2468 | - | |
| 2469 | - if ( ! inView ) { | |
| 2470 | - container.scroll({ | |
| 2471 | - top: container.scrollHeight, | |
| 2472 | - left: 0, | |
| 2473 | - behavior: 'smooth' | |
| 2474 | - }); | |
| 2475 | - } | |
| 2476 | - | |
| 2477 | - if ( toggled === false ) { | |
| 2478 | - toggleOneSectionHolder( $thisSection ); | |
| 2479 | - } | |
| 2480 | - } | |
| 2481 | - | |
| 2482 | - deselectFields(); | |
| 2483 | - initiateMultiselect(); | |
| 2484 | - | |
| 2485 | - const addedEvent = new Event( 'frm_added_field', { bubbles: false }); | |
| 2486 | - addedEvent.frmField = field; | |
| 2487 | - addedEvent.frmSection = section; | |
| 2488 | - addedEvent.frmType = type; | |
| 2489 | - addedEvent.frmToggles = toggled; | |
| 2490 | - document.dispatchEvent( addedEvent ); | |
| 2491 | - } | |
| 2492 | - | |
| 2493 | - function clearSettingsBox( preventFieldGroups ) { | |
| 2494 | - jQuery( '#new_fields .frm-single-settings' ).addClass( 'frm_hidden' ); | |
| 2495 | - jQuery( '#frm-options-panel > .frm-single-settings' ).removeClass( 'frm_hidden' ); | |
| 2496 | - deselectFields( preventFieldGroups ); | |
| 2497 | - } | |
| 2498 | - | |
| 2499 | - function deselectFields( preventFieldGroups ) { | |
| 2500 | - jQuery( 'li.ui-state-default.selected' ).removeClass( 'selected' ); | |
| 2501 | - if ( ! preventFieldGroups ) { | |
| 2502 | - unselectFieldGroups(); | |
| 2503 | - } | |
| 2504 | - } | |
| 2505 | - | |
| 2506 | - function scrollToField( field ) { | |
| 2507 | - var newPos = field.getBoundingClientRect().top, | |
| 2508 | - container = document.getElementById( 'post-body-content' ); | |
| 2509 | - | |
| 2510 | - if ( typeof animate === 'undefined' ) { | |
| 2511 | - jQuery( container ).scrollTop( newPos ); | |
| 2512 | - } else { | |
| 2513 | - // TODO: smooth scroll | |
| 2514 | - jQuery( container ).animate({ scrollTop: newPos }, 500 ); | |
| 2515 | - } | |
| 2516 | - } | |
| 2517 | - | |
| 2518 | - function checkCalculationCreatedByUser() { | |
| 2519 | - var calculation = this.value; | |
| 2520 | - var warningMessage = checkMatchingParens( calculation ); | |
| 2521 | - warningMessage += checkShortcodes( calculation, this ); | |
| 2522 | - | |
| 2523 | - if ( warningMessage !== '' ) { | |
| 2524 | - infoModal( calculation + '\n\n' + warningMessage ); | |
| 2525 | - } | |
| 2526 | - } | |
| 2527 | - | |
| 2528 | - /** | |
| 2529 | - * Checks the Detail Page slug to see if it's a reserved word and displays a message if it is. | |
| 2530 | - */ | |
| 2531 | - function checkDetailPageSlug() { | |
| 2532 | - var slug = jQuery( '#param' ).val(), | |
| 2533 | - msg; | |
| 2534 | - slug = slug.trim().toLowerCase(); | |
| 2535 | - if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( slug ) ) { // eslint-disable-line camelcase | |
| 2536 | - msg = frm_admin_js.slug_is_reserved; // eslint-disable-line camelcase | |
| 2537 | - msg = msg.replace( '****', addHtmlTags( slug, 'strong' ) ); | |
| 2538 | - msg += '<br /><br />'; | |
| 2539 | - 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 | |
| 2540 | - infoModal( msg ); | |
| 2541 | - } | |
| 2542 | - } | |
| 2543 | - | |
| 2544 | - /** | |
| 2545 | - * Checks View filter value for params named with reserved words and displays a message if any are found. | |
| 2546 | - */ | |
| 2547 | - function checkFilterParamNames() { | |
| 2548 | - var regEx = /\[\s*get\s*param\s*=\s*['"]?([a-zA-Z-_]+)['"]?/ig, | |
| 2549 | - filterValue = jQuery( this ).val(), | |
| 2550 | - match = regEx.exec( filterValue ), | |
| 2551 | - unsafeParams = ''; | |
| 2552 | - | |
| 2553 | - while ( match !== null ) { | |
| 2554 | - if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( match[1]) ) { // eslint-disable-line camelcase | |
| 2555 | - if ( unsafeParams !== '' ) { | |
| 2556 | - unsafeParams += '", "' + match[ 1 ]; | |
| 2557 | - } else { | |
| 2558 | - unsafeParams = match[ 1 ]; | |
| 2559 | - } | |
| 2560 | - } | |
| 2561 | - match = regEx.exec( filterValue ); | |
| 2562 | - } | |
| 2563 | - | |
| 2564 | - if ( unsafeParams !== '' ) { | |
| 2565 | - msg = frm_admin_js.param_is_reserved; // eslint-disable-line camelcase | |
| 2566 | - msg = msg.replace( '****', addHtmlTags( unsafeParams, 'strong' ) ); | |
| 2567 | - msg += '<br /><br />'; | |
| 2568 | - 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 | |
| 2569 | - | |
| 2570 | - infoModal( msg ); | |
| 2571 | - } | |
| 2572 | - } | |
| 2573 | - | |
| 2574 | - function addHtmlTags( text, tag ) { | |
| 2575 | - tag = tag ? tag : 'p'; | |
| 2576 | - return '<' + tag + '>' + text + '</' + tag + '>'; | |
| 2577 | - } | |
| 2578 | - | |
| 2579 | - /** | |
| 2580 | - * Checks a string for parens, brackets, and curly braces and returns a message if any unmatched are found. | |
| 2581 | - * @param formula | |
| 2582 | - * @returns {string} | |
| 2583 | - */ | |
| 2584 | - function checkMatchingParens( formula ) { | |
| 2585 | - | |
| 2586 | - var stack = [], | |
| 2587 | - formulaArray = formula.split( '' ), | |
| 2588 | - length = formulaArray.length, | |
| 2589 | - opening = [ '{', '[', '(' ], | |
| 2590 | - closing = { | |
| 2591 | - '}': '{', | |
| 2592 | - ')': '(', | |
| 2593 | - ']': '[' | |
| 2594 | - }, | |
| 2595 | - unmatchedClosing = [], | |
| 2596 | - msg = '', | |
| 2597 | - i, top; | |
| 2598 | - | |
| 2599 | - for ( i = 0; i < length; i++ ) { | |
| 2600 | - if ( opening.includes( formulaArray[i]) ) { | |
| 2601 | - stack.push( formulaArray[i]); | |
| 2602 | - continue; | |
| 2603 | - } | |
| 2604 | - if ( closing.hasOwnProperty( formulaArray[i]) ) { | |
| 2605 | - top = stack.pop(); | |
| 2606 | - if ( top !== closing[formulaArray[i]]) { | |
| 2607 | - unmatchedClosing.push( formulaArray[i]); | |
| 2608 | - } | |
| 2609 | - } | |
| 2610 | - } | |
| 2611 | - | |
| 2612 | - if ( stack.length > 0 || unmatchedClosing.length > 0 ) { | |
| 2613 | - msg = frm_admin_js.unmatched_parens + '\n\n'; // eslint-disable-line camelcase | |
| 2614 | - return msg; | |
| 2615 | - } | |
| 2616 | - | |
| 2617 | - return ''; | |
| 2618 | - } | |
| 2619 | - | |
| 2620 | - /** | |
| 2621 | - * Checks a calculation for shortcodes that shouldn't be in it and returns a message if found. | |
| 2622 | - * @param calculation | |
| 2623 | - * @param inputElement | |
| 2624 | - * @returns {string} | |
| 2625 | - */ | |
| 2626 | - function checkShortcodes( calculation, inputElement ) { | |
| 2627 | - var msg = checkNonNumericShortcodes( calculation, inputElement ); | |
| 2628 | - msg += checkNonFormShortcodes( calculation ); | |
| 2629 | - | |
| 2630 | - return msg; | |
| 2631 | - } | |
| 2632 | - | |
| 2633 | - /** | |
| 2634 | - * Checks if a numeric calculation has shortcodes that output non-numeric strings and returns a message if found. | |
| 2635 | - * @param calculation | |
| 2636 | - * | |
| 2637 | - * @param inputElement | |
| 2638 | - * @returns {string} | |
| 2639 | - */ | |
| 2640 | - function checkNonNumericShortcodes( calculation, inputElement ) { | |
| 2641 | - | |
| 2642 | - var msg = ''; | |
| 2643 | - | |
| 2644 | - if ( isTextCalculation( inputElement ) ) { | |
| 2645 | - return msg; | |
| 2646 | - } | |
| 2647 | - | |
| 2648 | - var nonNumericShortcodes = getNonNumericShortcodes(); | |
| 2649 | - | |
| 2650 | - if ( nonNumericShortcodes.test( calculation ) ) { | |
| 2651 | - msg = frm_admin_js.text_shortcodes + '\n\n'; // eslint-disable-line camelcase | |
| 2652 | - } | |
| 2653 | - | |
| 2654 | - return msg; | |
| 2655 | - } | |
| 2656 | - | |
| 2657 | - /** | |
| 2658 | - * Determines if the calculation input is from a text calculation. | |
| 2659 | - * | |
| 2660 | - * @param inputElement | |
| 2661 | - */ | |
| 2662 | - function isTextCalculation( inputElement ) { | |
| 2663 | - return jQuery( inputElement ).siblings( 'label[for^="calc_type"]' ).children( 'input' ).prop( 'checked' ); | |
| 2664 | - } | |
| 2665 | - | |
| 2666 | - /** | |
| 2667 | - * Returns a regular expression of shortcodes that can't be used in numeric calculations. | |
| 2668 | - * @returns {RegExp} | |
| 2669 | - */ | |
| 2670 | - function getNonNumericShortcodes() { | |
| 2671 | - return /\[(date|time|email|ip)\]/; | |
| 2672 | - } | |
| 2673 | - | |
| 2674 | - /** | |
| 2675 | - * Checks if a string has any shortcodes that do not belong in forms and returns a message if any are found. | |
| 2676 | - * @param formula | |
| 2677 | - * @returns {string} | |
| 2678 | - */ | |
| 2679 | - function checkNonFormShortcodes( formula ) { | |
| 2680 | - var nonFormShortcodes = getNonFormShortcodes(), | |
| 2681 | - msg = ''; | |
| 2682 | - | |
| 2683 | - if ( nonFormShortcodes.test( formula ) ) { | |
| 2684 | - msg += frm_admin_js.view_shortcodes + '\n\n'; // eslint-disable-line camelcase | |
| 2685 | - } | |
| 2686 | - | |
| 2687 | - return msg; | |
| 2688 | - } | |
| 2689 | - | |
| 2690 | - /** | |
| 2691 | - * Returns a regular expression of shortcodes that can't be used in forms but can be used in Views, Email | |
| 2692 | - * Notifications, and other Formidable areas. | |
| 2693 | - * | |
| 2694 | - * @returns {RegExp} | |
| 2695 | - */ | |
| 2696 | - function getNonFormShortcodes() { | |
| 2697 | - return /\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g; | |
| 2698 | - } | |
| 2699 | - | |
| 2700 | - function isCalcBoxType( box, listClass ) { | |
| 2701 | - var list = jQuery( box ).find( '.frm_code_list' ); | |
| 2702 | - return 1 === list.length && list.hasClass( listClass ); | |
| 2703 | - } | |
| 2704 | - | |
| 2705 | - function extractExcludedOptions( exclude ) { | |
| 2706 | - var opts = []; | |
| 2707 | - if ( ! Array.isArray( exclude ) ) { | |
| 2708 | - return opts; | |
| 2709 | - } | |
| 2710 | - | |
| 2711 | - for ( var i = 0; i < exclude.length; i++ ) { | |
| 2712 | - if ( exclude[ i ].startsWith( '[' ) ) { | |
| 2713 | - opts.push( exclude[ i ]); | |
| 2714 | - // remove it | |
| 2715 | - exclude.splice( i, 1 ); | |
| 2716 | - // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value | |
| 2717 | - i--; | |
| 2718 | - } | |
| 2719 | - } | |
| 2720 | - | |
| 2721 | - return opts; | |
| 2722 | - } | |
| 2723 | - | |
| 2724 | - function hasExcludedOption( field, excludedOpts ) { | |
| 2725 | - var hasOption = false; | |
| 2726 | - for ( var i = 0; i < excludedOpts.length; i++ ) { | |
| 2727 | - var inputs = document.getElementsByName( getFieldOptionInputName( excludedOpts[ i ], field.fieldId ) ); | |
| 2728 | - // 2nd condition checks that there's at least one non-empty value | |
| 2729 | - if ( inputs.length && jQuery( inputs[0]).val() ) { | |
| 2730 | - hasOption = true; | |
| 2731 | - break; | |
| 2732 | - } | |
| 2733 | - } | |
| 2734 | - return hasOption; | |
| 2735 | - } | |
| 2736 | - | |
| 2737 | - function getFieldOptionInputName( opt, fieldId ) { | |
| 2738 | - var at = opt.indexOf( ']' ); | |
| 2739 | - return 'field_options' + opt.substring( 0, at ) + '_' + fieldId + opt.substring( at ); | |
| 2740 | - } | |
| 2741 | - | |
| 2742 | - function popCalcFields( v, force ) { | |
| 2743 | - var box, exclude, fields, i, list, | |
| 2744 | - p = jQuery( v ).closest( '.frm-single-settings' ), | |
| 2745 | - calc = p.find( '.frm-calc-field' ); | |
| 2746 | - | |
| 2747 | - if ( ! force && ( ! calc.length || calc.val() === '' || calc.is( ':hidden' ) ) ) { | |
| 2748 | - return; | |
| 2749 | - } | |
| 2750 | - | |
| 2751 | - var isSummary = isCalcBoxType( v, 'frm_js_summary_list' ); | |
| 2752 | - | |
| 2753 | - var fieldId = p.find( 'input[name="frm_fields_submitted[]"]' ).val(); | |
| 2754 | - | |
| 2755 | - if ( force ) { | |
| 2756 | - box = v; | |
| 2757 | - } else { | |
| 2758 | - box = document.getElementById( 'frm-calc-box-' + fieldId ); | |
| 2759 | - } | |
| 2760 | - | |
| 2761 | - exclude = getExcludeArray( box, isSummary ); | |
| 2762 | - var excludedOpts = extractExcludedOptions( exclude ); | |
| 2763 | - | |
| 2764 | - fields = getFieldList(); | |
| 2765 | - list = document.getElementById( 'frm-calc-list-' + fieldId ); | |
| 2766 | - list.innerHTML = ''; | |
| 2767 | - | |
| 2768 | - for ( i = 0; i < fields.length; i++ ) { | |
| 2769 | - if ( ( exclude && exclude.includes( fields[ i ].fieldType ) ) || | |
| 2770 | - ( excludedOpts.length && hasExcludedOption( fields[ i ], excludedOpts ) ) ) { | |
| 2771 | - continue; | |
| 2772 | - } | |
| 2773 | - | |
| 2774 | - var span = document.createElement( 'span' ); | |
| 2775 | - span.appendChild( document.createTextNode( '[' + fields[i].fieldId + ']' ) ); | |
| 2776 | - | |
| 2777 | - var a = document.createElement( 'a' ); | |
| 2778 | - a.setAttribute( 'href', '#' ); | |
| 2779 | - a.setAttribute( 'data-code', fields[i].fieldId ); | |
| 2780 | - a.classList.add( 'frm_insert_code' ); | |
| 2781 | - a.appendChild( span ); | |
| 2782 | - a.appendChild( document.createTextNode( fields[i].fieldName ) ); | |
| 2783 | - | |
| 2784 | - var li = document.createElement( 'li' ); | |
| 2785 | - li.classList.add( 'frm-field-list-' + fieldId ); | |
| 2786 | - li.classList.add( 'frm-field-list-' + fields[i].fieldType ); | |
| 2787 | - li.appendChild( a ); | |
| 2788 | - list.appendChild( li ); | |
| 2789 | - } | |
| 2790 | - } | |
| 2791 | - | |
| 2792 | - function getExcludeArray( calcBox, isSummary ) { | |
| 2793 | - var exclude = JSON.parse( calcBox.getElementsByClassName( 'frm_code_list' )[0].getAttribute( 'data-exclude' ) ); | |
| 2794 | - | |
| 2795 | - if ( isSummary ) { | |
| 2796 | - // includedExtras are those that are normally excluded from the summary but the form owner can choose to include, | |
| 2797 | - // when they have been chosen to be included, then they can now be manually excluded in the calc box. | |
| 2798 | - var includedExtras = getIncludedExtras(); | |
| 2799 | - if ( includedExtras.length ) { | |
| 2800 | - for ( var i = 0; i < exclude.length; i++ ) { | |
| 2801 | - if ( includedExtras.includes( exclude[ i ]) ) { | |
| 2802 | - // remove it | |
| 2803 | - exclude.splice( i, 1 ); | |
| 2804 | - // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value | |
| 2805 | - i--; | |
| 2806 | - } | |
| 2807 | - } | |
| 2808 | - } | |
| 2809 | - } | |
| 2810 | - | |
| 2811 | - return exclude; | |
| 2812 | - } | |
| 2813 | - | |
| 2814 | - function getIncludedExtras() { | |
| 2815 | - var checked = []; | |
| 2816 | - var checkboxes = document.getElementsByClassName( 'frm_include_extras_field' ); | |
| 2817 | - | |
| 2818 | - for ( var i = 0; i < checkboxes.length; i++ ) { | |
| 2819 | - if ( checkboxes[i].checked ) { | |
| 2820 | - checked.push( checkboxes[i].value ); | |
| 2821 | - } | |
| 2822 | - } | |
| 2823 | - | |
| 2824 | - return checked; | |
| 2825 | - } | |
| 2826 | - | |
| 2827 | - function rePopCalcFieldsForSummary() { | |
| 2828 | - popCalcFields( jQuery( '.frm-inline-modal.postbox:has(.frm_js_summary_list)' )[0], true ); | |
| 2829 | - } | |
| 2830 | - | |
| 2831 | - function getFieldList( fieldType ) { | |
| 2832 | - var i, | |
| 2833 | - fields = [], | |
| 2834 | - allFields = document.querySelectorAll( 'li.frm_field_box' ), | |
| 2835 | - checkType = 'undefined' !== typeof fieldType; | |
| 2836 | - | |
| 2837 | - for ( i = 0; i < allFields.length; i++ ) { | |
| 2838 | - // data-ftype is better (than data-type) cos of fields loaded by AJAX - which might not be ready yet | |
| 2839 | - if ( checkType && allFields[ i ].getAttribute( 'data-ftype' ) !== fieldType ) { | |
| 2840 | - continue; | |
| 2841 | - } | |
| 2842 | - | |
| 2843 | - var fieldId = allFields[ i ].getAttribute( 'data-fid' ); | |
| 2844 | - if ( typeof fieldId !== 'undefined' && fieldId ) { | |
| 2845 | - fields.push({ | |
| 2846 | - 'fieldId': fieldId, | |
| 2847 | - 'fieldName': getPossibleValue( 'frm_name_' + fieldId ), | |
| 2848 | - 'fieldType': getPossibleValue( 'field_options_type_' + fieldId ), | |
| 2849 | - 'fieldKey': getPossibleValue( 'field_options_field_key_' + fieldId ) | |
| 2850 | - }); | |
| 2851 | - } | |
| 2852 | - } | |
| 2853 | - | |
| 2854 | - return fields; | |
| 2855 | - } | |
| 2856 | - | |
| 2857 | - function popProductFields( field ) { | |
| 2858 | - var i, checked, id, | |
| 2859 | - options = [], | |
| 2860 | - current = getCurrentProductFields( field ), | |
| 2861 | - fName = field.getAttribute( 'data-frmfname' ), | |
| 2862 | - products = getFieldList( 'product' ), | |
| 2863 | - quantities = getFieldList( 'quantity' ), | |
| 2864 | - isSelect = field.tagName === 'SELECT', // for reverse compatibility. | |
| 2865 | - // whether we have just 1 product and 1 quantity field & should therefore attach the latter to the former | |
| 2866 | - auto = 1 === quantities.length && 1 === products.length; | |
| 2867 | - | |
| 2868 | - if ( isSelect ) { | |
| 2869 | - // This fallback can be removed after 4.05. | |
| 2870 | - current = field.getAttribute( 'data-frmcurrent' ); | |
| 2871 | - } | |
| 2872 | - | |
| 2873 | - for ( i = 0 ; i < products.length ; i++ ) { | |
| 2874 | - // let's be double sure it's string, else indexOf will fail | |
| 2875 | - id = products[ i ].fieldId.toString(); | |
| 2876 | - checked = auto || -1 !== current.indexOf( id ); | |
| 2877 | - if ( isSelect ) { | |
| 2878 | - // This fallback can be removed after 4.05. | |
| 2879 | - checked = checked ? ' selected' : ''; | |
| 2880 | - options.push( '<option value="' + id + '"' + checked + '>' + products[ i ].fieldName + '</option>' ); | |
| 2881 | - } else { | |
| 2882 | - checked = checked ? ' checked' : ''; | |
| 2883 | - options.push( '<label class="frm6">' ); | |
| 2884 | - options.push( '<input type="checkbox" name="' + fName + '" value="' + id + '"' + checked + '> ' + products[ i ].fieldName ); | |
| 2885 | - options.push( '</label>' ); | |
| 2886 | - } | |
| 2887 | - } | |
| 2888 | - | |
| 2889 | - field.innerHTML = options.join( '' ); | |
| 2890 | - } | |
| 2891 | - | |
| 2892 | - function getCurrentProductFields( prodFieldOpt ) { | |
| 2893 | - var products = prodFieldOpt.querySelectorAll( '[type="checkbox"]:checked' ), | |
| 2894 | - idsArray = []; | |
| 2895 | - | |
| 2896 | - for ( var i = 0; i < products.length; i++ ) { | |
| 2897 | - idsArray.push( products[ i ].value ); | |
| 2898 | - } | |
| 2899 | - | |
| 2900 | - return idsArray; | |
| 2901 | - } | |
| 2902 | - | |
| 2903 | - function popAllProductFields() { | |
| 2904 | - var opts = document.querySelectorAll( '.frmjs_prod_field_opt' ); | |
| 2905 | - for ( var i = 0; i < opts.length; i++ ) { | |
| 2906 | - popProductFields( opts[ i ]); | |
| 2907 | - } | |
| 2908 | - } | |
| 2909 | - | |
| 2910 | - function maybeSetProductField( field ) { | |
| 2911 | - var fieldId = field.getAttribute( 'data-fid' ), | |
| 2912 | - productFieldOpt = document.getElementById( 'field_options[product_field_' + fieldId + ']' ); | |
| 2913 | - | |
| 2914 | - if ( null === productFieldOpt ) { | |
| 2915 | - return; | |
| 2916 | - } | |
| 2917 | - | |
| 2918 | - popProductFields( productFieldOpt ); | |
| 2919 | - // in order to move its settings to that LHS panel where | |
| 2920 | - // the update form resides, else it'll lose this setting | |
| 2921 | - moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) ); | |
| 2922 | - } | |
| 2923 | - | |
| 2924 | - /** | |
| 2925 | - * If the element doesn't exist, use a blank value. | |
| 2926 | - */ | |
| 2927 | - function getPossibleValue( id ) { | |
| 2928 | - field = document.getElementById( id ); | |
| 2929 | - if ( field !== null ) { | |
| 2930 | - return field.value; | |
| 2931 | - } else { | |
| 2932 | - return ''; | |
| 2933 | - } | |
| 2934 | - } | |
| 2935 | - | |
| 2936 | - function liveChanges() { | |
| 2937 | - /*jshint validthis:true */ | |
| 2938 | - var option, | |
| 2939 | - newValue = this.value, | |
| 2940 | - changes = document.getElementById( this.getAttribute( 'data-changeme' ) ), | |
| 2941 | - att = this.getAttribute( 'data-changeatt' ); | |
| 2942 | - | |
| 2943 | - if ( changes === null ) { | |
| 2944 | - return; | |
| 2945 | - } | |
| 2946 | - | |
| 2947 | - if ( att !== null ) { | |
| 2948 | - if ( changes.tagName === 'SELECT' && att === 'placeholder' ) { | |
| 2949 | - option = changes.options[0]; | |
| 2950 | - if ( option.value === '' ) { | |
| 2951 | - option.innerHTML = newValue; | |
| 2952 | - } else { | |
| 2953 | - // Create a placeholder option if there are no blank values. | |
| 2954 | - addBlankSelectOption( changes, newValue ); | |
| 2955 | - } | |
| 2956 | - } else if ( att === 'class' ) { | |
| 2957 | - changeFieldClass( changes, this ); | |
| 2958 | - } else if ( isSliderField( changes ) ) { | |
| 2959 | - updateSliderFieldPreview( changes, att, newValue ); | |
| 2960 | - } else { | |
| 2961 | - changes.setAttribute( att, newValue ); | |
| 2962 | - } | |
| 2963 | - } else if ( changes.id.indexOf( 'setup-message' ) === 0 ) { | |
| 2964 | - if ( newValue !== '' ) { | |
| 2965 | - changes.innerHTML = '<input type="text" value="" disabled />'; | |
| 2966 | - } | |
| 2967 | - } else { | |
| 2968 | - changes.innerHTML = newValue; | |
| 2969 | - | |
| 2970 | - if ( 'TEXTAREA' === changes.nodeName && changes.classList.contains( 'wp-editor-area' ) ) { | |
| 2971 | - // Trigger change events on wysiwyg textareas so we can also sync default values in the visual tab. | |
| 2972 | - jQuery( changes ).trigger( 'change' ); | |
| 2973 | - } | |
| 2974 | - | |
| 2975 | - if ( changes.classList.contains( 'frm_primary_label' ) && 'break' === changes.nextElementSibling.getAttribute( 'data-ftype' ) ) { | |
| 2976 | - changes.nextElementSibling.querySelector( '.frm_button_submit' ).textContent = newValue; | |
| 2977 | - } | |
| 2978 | - } | |
| 2979 | - } | |
| 2980 | - | |
| 2981 | - function updateSliderFieldPreview( field, att, newValue ) { | |
| 2982 | - if ( frmGlobal.proIncludesSliderJs ) { | |
| 2983 | - const hookName = 'frm_update_slider_field_preview'; | |
| 2984 | - const hookArgs = { field, att, newValue }; | |
| 2985 | - wp.hooks.doAction( hookName, hookArgs ); | |
| 2986 | - return; | |
| 2987 | - } | |
| 2988 | - | |
| 2989 | - // This functionality has been moved to pro since v5.4.3. This code should be removed eventually. | |
| 2990 | - if ( 'value' === att ) { | |
| 2991 | - if ( '' === newValue ) { | |
| 2992 | - newValue = getSliderMidpoint( field ); | |
| 2993 | - } | |
| 2994 | - field.value = newValue; | |
| 2995 | - } else { | |
| 2996 | - field.setAttribute( att, newValue ); | |
| 2997 | - } | |
| 2998 | - | |
| 2999 | - if ( -1 === [ 'value', 'min', 'max' ].indexOf( att ) ) { | |
| 3000 | - return; | |
| 3001 | - } | |
| 3002 | - | |
| 3003 | - if ( ( 'max' === att || 'min' === att ) && '' === getSliderDefaultValueInput( field.id ) ) { | |
| 3004 | - field.value = getSliderMidpoint( field ); | |
| 3005 | - } | |
| 3006 | - | |
| 3007 | - field.parentNode.querySelector( '.frm_range_value' ).textContent = field.value; | |
| 3008 | - } | |
| 3009 | - | |
| 3010 | - function getSliderDefaultValueInput( previewInputId ) { | |
| 3011 | - return document.querySelector( 'input[data-changeme="' + previewInputId + '"][data-changeatt="value"]' ).value; | |
| 3012 | - } | |
| 3013 | - | |
| 3014 | - function getSliderMidpoint( sliderInput ) { | |
| 3015 | - const max = parseFloat( sliderInput.getAttribute( 'max' ) ); | |
| 3016 | - const min = parseFloat( sliderInput.getAttribute( 'min' ) ); | |
| 3017 | - return ( max - min ) / 2 + min; | |
| 3018 | - } | |
| 3019 | - | |
| 3020 | - function isSliderField( previewInput ) { | |
| 3021 | - return 'range' === previewInput.type && previewInput.parentNode.classList.contains( 'frm_range_container' ); | |
| 3022 | - } | |
| 3023 | - | |
| 3024 | - function toggleInvalidMsg() { | |
| 3025 | - /*jshint validthis:true */ | |
| 3026 | - var typeDropdown, fieldType, | |
| 3027 | - fieldId = this.getAttribute( 'data-fid' ), | |
| 3028 | - value = ''; | |
| 3029 | - | |
| 3030 | - [ 'field_options_max_', 'frm_format_' ].forEach( function( id ) { | |
| 3031 | - var input = document.getElementById( id + fieldId ); | |
| 3032 | - if ( ! input ) { | |
| 3033 | - return; | |
| 3034 | - } | |
| 3035 | - | |
| 3036 | - value += input.value; | |
| 3037 | - }); | |
| 3038 | - | |
| 3039 | - typeDropdown = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0]; | |
| 3040 | - fieldType = typeDropdown.options[typeDropdown.selectedIndex].value; | |
| 3041 | - | |
| 3042 | - if ( fieldType === 'text' ) { | |
| 3043 | - toggleValidationBox( '' !== value, '.frm_invalid_msg' + fieldId ); | |
| 3044 | - } | |
| 3045 | - } | |
| 3046 | - | |
| 3047 | - function markRequired() { | |
| 3048 | - /*jshint validthis:true */ | |
| 3049 | - var thisid = this.id.replace( 'frm_', '' ), | |
| 3050 | - fieldId = thisid.replace( 'req_field_', '' ), | |
| 3051 | - checked = this.checked, | |
| 3052 | - label = jQuery( '#field_label_' + fieldId + ' .frm_required' ); | |
| 3053 | - | |
| 3054 | - toggleValidationBox( checked, '.frm_required_details' + fieldId ); | |
| 3055 | - | |
| 3056 | - if ( checked ) { | |
| 3057 | - var $reqBox = jQuery( 'input[name="field_options[required_indicator_' + fieldId + ']"]' ); | |
| 3058 | - if ( $reqBox.val() === '' ) { | |
| 3059 | - $reqBox.val( '*' ); | |
| 3060 | - } | |
| 3061 | - label.removeClass( 'frm_hidden' ); | |
| 3062 | - } else { | |
| 3063 | - label.addClass( 'frm_hidden' ); | |
| 3064 | - } | |
| 3065 | - } | |
| 3066 | - | |
| 3067 | - function toggleValidationBox( hasValue, messageClass ) { | |
| 3068 | - $msg = jQuery( messageClass ); | |
| 3069 | - if ( hasValue ) { | |
| 3070 | - $msg.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' ); | |
| 3071 | - } else { | |
| 3072 | - //Fade out validation options | |
| 3073 | - var v = $msg.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(' + messageClass + '):visible' ).length; | |
| 3074 | - if ( v === 0 ) { | |
| 3075 | - $msg.closest( '.frm_validation_msg' ).fadeOut( 'fast' ); | |
| 3076 | - } | |
| 3077 | - } | |
| 3078 | - } | |
| 3079 | - | |
| 3080 | - function markUnique() { | |
| 3081 | - /*jshint validthis:true */ | |
| 3082 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3083 | - var $thisField = jQuery( '.frm_unique_details' + fieldId ); | |
| 3084 | - if ( this.checked ) { | |
| 3085 | - $thisField.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' ); | |
| 3086 | - $unqDetail = jQuery( '.frm_unique_details' + fieldId + ' input' ); | |
| 3087 | - if ( $unqDetail.val() === '' ) { | |
| 3088 | - $unqDetail.val( frm_admin_js.default_unique ); // eslint-disable-line camelcase | |
| 3089 | - } | |
| 3090 | - } else { | |
| 3091 | - var v = $thisField.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(.frm_unique_details' + fieldId + '):visible' ).length; | |
| 3092 | - if ( v === 0 ) { | |
| 3093 | - $thisField.closest( '.frm_validation_msg' ).fadeOut( 'fast' ); | |
| 3094 | - } | |
| 3095 | - } | |
| 3096 | - } | |
| 3097 | - | |
| 3098 | - //Fade confirmation field and validation option in or out | |
| 3099 | - function addConf() { | |
| 3100 | - /*jshint validthis:true */ | |
| 3101 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3102 | - var val = jQuery( this ).val(); | |
| 3103 | - var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ); | |
| 3104 | - | |
| 3105 | - toggleValidationBox( val !== '', '.frm_conf_details' + fieldId ); | |
| 3106 | - | |
| 3107 | - if ( val !== '' ) { | |
| 3108 | - //Add default validation message if empty | |
| 3109 | - var valMsg = jQuery( '.frm_validation_box .frm_conf_details' + fieldId + ' input' ); | |
| 3110 | - if ( valMsg.val() === '' ) { | |
| 3111 | - valMsg.val( frm_admin_js.default_conf ); // eslint-disable-line camelcase | |
| 3112 | - } | |
| 3113 | - | |
| 3114 | - setConfirmationFieldDescriptions( fieldId ); | |
| 3115 | - | |
| 3116 | - //Add or remove class for confirmation field styling | |
| 3117 | - if ( val === 'inline' ) { | |
| 3118 | - $thisField.removeClass( 'frm_conf_below' ).addClass( 'frm_conf_inline' ); | |
| 3119 | - } else if ( val === 'below' ) { | |
| 3120 | - $thisField.removeClass( 'frm_conf_inline' ).addClass( 'frm_conf_below' ); | |
| 3121 | - } | |
| 3122 | - jQuery( '.frm-conf-box-' + fieldId ).removeClass( 'frm_hidden' ); | |
| 3123 | - } else { | |
| 3124 | - jQuery( '.frm-conf-box-' + fieldId ).addClass( 'frm_hidden' ); | |
| 3125 | - setTimeout( function() { | |
| 3126 | - $thisField.removeClass( 'frm_conf_inline frm_conf_below' ); | |
| 3127 | - }, 200 ); | |
| 3128 | - } | |
| 3129 | - } | |
| 3130 | - | |
| 3131 | - function setConfirmationFieldDescriptions( fieldId ) { | |
| 3132 | - var fieldType = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0].value; | |
| 3133 | - | |
| 3134 | - var fieldDescription = document.getElementById( 'field_description_' + fieldId ); | |
| 3135 | - var hiddenDescName = 'field_options[description_' + fieldId + ']'; | |
| 3136 | - var newValue = frm_admin_js['enter_' + fieldType]; // eslint-disable-line camelcase | |
| 3137 | - maybeSetNewDescription( fieldDescription, hiddenDescName, newValue ); | |
| 3138 | - | |
| 3139 | - var confFieldDescription = document.getElementById( 'conf_field_description_' + fieldId ); | |
| 3140 | - var hiddenConfName = 'field_options[conf_desc_' + fieldId + ']'; | |
| 3141 | - var newConfValue = frm_admin_js['confirm_' + fieldType]; // eslint-disable-line camelcase | |
| 3142 | - maybeSetNewDescription( confFieldDescription, hiddenConfName, newConfValue ); | |
| 3143 | - } | |
| 3144 | - | |
| 3145 | - function maybeSetNewDescription( descriptionDiv, hiddenName, newValue ) { | |
| 3146 | - if ( descriptionDiv.innerHTML === frm_admin_js.desc ) { // eslint-disable-line camelcase | |
| 3147 | - | |
| 3148 | - // Set the visible description value and the hidden description value | |
| 3149 | - descriptionDiv.innerHTML = newValue; | |
| 3150 | - document.getElementsByName( hiddenName )[0].value = newValue; | |
| 3151 | - } | |
| 3152 | - } | |
| 3153 | - | |
| 3154 | - function initBulkOptionsOverlay() { | |
| 3155 | - /*jshint validthis:true */ | |
| 3156 | - var $info = initModal( '#frm-bulk-modal', '700px' ); | |
| 3157 | - if ( $info === false ) { | |
| 3158 | - return; | |
| 3159 | - } | |
| 3160 | - | |
| 3161 | - jQuery( '.frm-insert-preset' ).on( 'click', insertBulkPreset ); | |
| 3162 | - | |
| 3163 | - jQuery( builderForm ).on( 'click', 'a.frm-bulk-edit-link', function( event ) { | |
| 3164 | - event.preventDefault(); | |
| 3165 | - var i, key, label, | |
| 3166 | - content = '', | |
| 3167 | - optList, | |
| 3168 | - opts, | |
| 3169 | - fieldId = jQuery( this ).closest( '[data-fid]' ).data( 'fid' ), | |
| 3170 | - separate = usingSeparateValues( fieldId ), | |
| 3171 | - product = isProductField( fieldId ); | |
| 3172 | - | |
| 3173 | - optList = document.getElementById( 'frm_field_' + fieldId + '_opts' ); | |
| 3174 | - if ( ! optList ) { | |
| 3175 | - return; | |
| 3176 | - } | |
| 3177 | - | |
| 3178 | - opts = optList.getElementsByTagName( 'li' ); | |
| 3179 | - | |
| 3180 | - document.getElementById( 'bulk-field-id' ).value = fieldId; | |
| 3181 | - | |
| 3182 | - for ( i = 0; i < opts.length; i++ ) { | |
| 3183 | - key = opts[i].getAttribute( 'data-optkey' ); | |
| 3184 | - if ( key !== '000' ) { | |
| 3185 | - label = document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][label]' )[0]; | |
| 3186 | - if ( typeof label !== 'undefined' ) { | |
| 3187 | - content += label.value; | |
| 3188 | - if ( separate ) { | |
| 3189 | - content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][value]' )[0].value; | |
| 3190 | - } | |
| 3191 | - if ( product ) { | |
| 3192 | - content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][price]' )[0].value; | |
| 3193 | - } | |
| 3194 | - content += '\r\n'; | |
| 3195 | - } | |
| 3196 | - } | |
| 3197 | - | |
| 3198 | - if ( i >= opts.length - 1 ) { | |
| 3199 | - document.getElementById( 'frm_bulk_options' ).value = content; | |
| 3200 | - } | |
| 3201 | - } | |
| 3202 | - | |
| 3203 | - $info.dialog( 'open' ); | |
| 3204 | - | |
| 3205 | - return false; | |
| 3206 | - }); | |
| 3207 | - | |
| 3208 | - jQuery( '#frm-update-bulk-opts' ).on( 'click', function() { | |
| 3209 | - var fieldId = document.getElementById( 'bulk-field-id' ).value; | |
| 3210 | - var optionType = document.getElementById( 'bulk-option-type' ).value; | |
| 3211 | - | |
| 3212 | - if ( optionType ) { | |
| 3213 | - // Use custom handler for custom option type. | |
| 3214 | - return; | |
| 3215 | - } | |
| 3216 | - | |
| 3217 | - this.classList.add( 'frm_loading_button' ); | |
| 3218 | - frmAdminBuild.updateOpts( fieldId, document.getElementById( 'frm_bulk_options' ).value, $info ); | |
| 3219 | - }); | |
| 3220 | - } | |
| 3221 | - | |
| 3222 | - function insertBulkPreset( event ) { | |
| 3223 | - /*jshint validthis:true */ | |
| 3224 | - var opts = JSON.parse( this.getAttribute( 'data-opts' ) ); | |
| 3225 | - event.preventDefault(); | |
| 3226 | - document.getElementById( 'frm_bulk_options' ).value = opts.join( '\n' ); | |
| 3227 | - return false; | |
| 3228 | - } | |
| 3229 | - | |
| 3230 | - //Add new option or "Other" option to radio/checkbox/dropdown | |
| 3231 | - function addFieldOption() { | |
| 3232 | - /*jshint validthis:true */ | |
| 3233 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 3234 | - newOption = jQuery( '#frm_field_' + fieldId + '_opts .frm_option_template' ).prop( 'outerHTML' ), | |
| 3235 | - optType = jQuery( this ).data( 'opttype' ), | |
| 3236 | - optKey = 0, | |
| 3237 | - oldKey = '000', | |
| 3238 | - lastKey = getHighestOptKey( fieldId ); | |
| 3239 | - | |
| 3240 | - if ( lastKey !== oldKey ) { | |
| 3241 | - optKey = lastKey + 1; | |
| 3242 | - } | |
| 3243 | - | |
| 3244 | - //Update hidden field | |
| 3245 | - if ( optType === 'other' ) { | |
| 3246 | - document.getElementById( 'other_input_' + fieldId ).value = 1; | |
| 3247 | - | |
| 3248 | - //Hide "Add Other" option now if this is radio field | |
| 3249 | - var ftype = jQuery( this ).data( 'ftype' ); | |
| 3250 | - if ( ftype === 'radio' || ftype === 'select' ) { | |
| 3251 | - jQuery( this ).fadeOut( 'slow' ); | |
| 3252 | - } | |
| 3253 | - | |
| 3254 | - var data = { | |
| 3255 | - action: 'frm_add_field_option', | |
| 3256 | - field_id: fieldId, | |
| 3257 | - opt_key: optKey, | |
| 3258 | - opt_type: optType, | |
| 3259 | - nonce: frmGlobal.nonce | |
| 3260 | - }; | |
| 3261 | - jQuery.post( ajaxurl, data, function( msg ) { | |
| 3262 | - jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( msg ); | |
| 3263 | - resetDisplayedOpts( fieldId ); | |
| 3264 | - }); | |
| 3265 | - } else { | |
| 3266 | - newOption = newOption.replace( new RegExp( 'optkey="' + oldKey + '"', 'g' ), 'optkey="' + optKey + '"' ); | |
| 3267 | - newOption = newOption.replace( new RegExp( '-' + oldKey + '_', 'g' ), '-' + optKey + '_' ); | |
| 3268 | - newOption = newOption.replace( new RegExp( '-' + oldKey + '"', 'g' ), '-' + optKey + '"' ); | |
| 3269 | - newOption = newOption.replace( new RegExp( '\\[' + oldKey + '\\]', 'g' ), '[' + optKey + ']' ); | |
| 3270 | - newOption = newOption.replace( 'frm_hidden frm_option_template', '' ); | |
| 3271 | - newOption = { newOption }; | |
| 3272 | - addSaveAndDragIconsToOption( fieldId, newOption ); | |
| 3273 | - jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( newOption.newOption ); | |
| 3274 | - resetDisplayedOpts( fieldId ); | |
| 3275 | - } | |
| 3276 | - } | |
| 3277 | - | |
| 3278 | - function getHighestOptKey( fieldId ) { | |
| 3279 | - var i = 0, | |
| 3280 | - optKey = 0, | |
| 3281 | - opts = jQuery( '#frm_field_' + fieldId + '_opts li' ), | |
| 3282 | - lastKey = 0; | |
| 3283 | - | |
| 3284 | - for ( i; i < opts.length; i++ ) { | |
| 3285 | - optKey = opts[i].getAttribute( 'data-optkey' ); | |
| 3286 | - if ( opts.length === 1 ) { | |
| 3287 | - return optKey; | |
| 3288 | - } | |
| 3289 | - if ( optKey !== '000' ) { | |
| 3290 | - optKey = optKey.replace( 'other_', '' ); | |
| 3291 | - optKey = parseInt( optKey, 10 ); | |
| 3292 | - } | |
| 3293 | - | |
| 3294 | - if ( ! isNaN( lastKey ) && ( optKey > lastKey || lastKey === '000' ) ) { | |
| 3295 | - lastKey = optKey; | |
| 3296 | - } | |
| 3297 | - } | |
| 3298 | - | |
| 3299 | - return lastKey; | |
| 3300 | - } | |
| 3301 | - | |
| 3302 | - function toggleMultSel() { | |
| 3303 | - /*jshint validthis:true */ | |
| 3304 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3305 | - toggleMultiSelect( fieldId, this.value ); | |
| 3306 | - } | |
| 3307 | - | |
| 3308 | - function toggleMultiSelect( fieldId, value ) { | |
| 3309 | - var setting = jQuery( '.frm_multiple_cont_' + fieldId ); | |
| 3310 | - if ( value === 'select' ) { | |
| 3311 | - setting.fadeIn( 'fast' ); | |
| 3312 | - } else { | |
| 3313 | - setting.fadeOut( 'fast' ); | |
| 3314 | - } | |
| 3315 | - } | |
| 3316 | - | |
| 3317 | - function toggleSepValues() { | |
| 3318 | - /*jshint validthis:true */ | |
| 3319 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3320 | - toggle( jQuery( '.field_' + fieldId + '_option_key' ) ); | |
| 3321 | - jQuery( '.field_' + fieldId + '_option' ).toggleClass( 'frm_with_key' ); | |
| 3322 | - } | |
| 3323 | - | |
| 3324 | - function toggleImageOptions() { | |
| 3325 | - /*jshint validthis:true */ | |
| 3326 | - var hasImageOptions, imageSize, | |
| 3327 | - $field = jQuery( this ).closest( '.frm-single-settings' ), | |
| 3328 | - fieldId = $field.data( 'fid' ), | |
| 3329 | - displayField = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 3330 | - | |
| 3331 | - refreshOptionDisplayNow( jQuery( this ) ); | |
| 3332 | - | |
| 3333 | - toggle( jQuery( '.field_' + fieldId + '_image_id' ) ); | |
| 3334 | - toggle( jQuery( '.frm_toggle_image_options_' + fieldId ) ); | |
| 3335 | - toggle( jQuery( '.frm_image_size_' + fieldId ) ); | |
| 3336 | - toggle( jQuery( '.frm_alignment_' + fieldId ) ); | |
| 3337 | - toggle( jQuery( '.frm-add-other#frm_add_field_' + fieldId ) ); | |
| 3338 | - | |
| 3339 | - hasImageOptions = imagesAsOptions( fieldId ); | |
| 3340 | - | |
| 3341 | - if ( hasImageOptions ) { | |
| 3342 | - setAlignment( fieldId, 'inline' ); | |
| 3343 | - removeImageSizeClasses( displayField ); | |
| 3344 | - imageSize = getImageOptionSize( fieldId ); | |
| 3345 | - displayField.classList.add( 'frm_image_options' ); | |
| 3346 | - displayField.classList.add( 'frm_image_size_' + imageSize ); | |
| 3347 | - $field.find( '.frm-bulk-edit-link' ).hide(); | |
| 3348 | - } else { | |
| 3349 | - displayField.classList.remove( 'frm_image_options' ); | |
| 3350 | - removeImageSizeClasses( displayField ); | |
| 3351 | - setAlignment( fieldId, 'block' ); | |
| 3352 | - $field.find( '.frm-bulk-edit-link' ).show(); | |
| 3353 | - } | |
| 3354 | - } | |
| 3355 | - | |
| 3356 | - function removeImageSizeClasses( field ) { | |
| 3357 | - field.classList.remove( 'frm_image_size_', 'frm_image_size_small', 'frm_image_size_medium', 'frm_image_size_large', 'frm_image_size_xlarge' ); | |
| 3358 | - } | |
| 3359 | - | |
| 3360 | - function setAlignment( fieldId, alignment ) { | |
| 3361 | - jQuery( '#field_options_align_' + fieldId ).val( alignment ).trigger( 'change' ); | |
| 3362 | - } | |
| 3363 | - | |
| 3364 | - function setImageSize() { | |
| 3365 | - var $field = jQuery( this ).closest( '.frm-single-settings' ), | |
| 3366 | - fieldId = $field.data( 'fid' ), | |
| 3367 | - displayField = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 3368 | - | |
| 3369 | - refreshOptionDisplay(); | |
| 3370 | - | |
| 3371 | - if ( imagesAsOptions( fieldId ) ) { | |
| 3372 | - removeImageSizeClasses( displayField ); | |
| 3373 | - displayField.classList.add( 'frm_image_options' ); | |
| 3374 | - displayField.classList.add( 'frm_image_size_' + getImageOptionSize( fieldId ) ); | |
| 3375 | - } | |
| 3376 | - } | |
| 3377 | - | |
| 3378 | - function refreshOptionDisplayNow( object ) { | |
| 3379 | - var $field = object.closest( '.frm-single-settings' ), | |
| 3380 | - fieldID = $field.data( 'fid' ); | |
| 3381 | - jQuery( '.field_' + fieldID + '_option' ).trigger( 'change' ); | |
| 3382 | - } | |
| 3383 | - | |
| 3384 | - function refreshOptionDisplay() { | |
| 3385 | - /*jshint validthis:true */ | |
| 3386 | - refreshOptionDisplayNow( jQuery( this ) ); | |
| 3387 | - } | |
| 3388 | - | |
| 3389 | - function addImageToOption( event ) { | |
| 3390 | - const imagePreview = event.target.closest( '.frm_image_preview_wrapper' ); | |
| 3391 | - | |
| 3392 | - event.preventDefault(); | |
| 3393 | - | |
| 3394 | - wp.media.model.settings.post.id = 0; | |
| 3395 | - | |
| 3396 | - const fileFrame = wp.media.frames.file_frame = wp.media({ | |
| 3397 | - multiple: false, | |
| 3398 | - library: { | |
| 3399 | - type: [ 'image' ] | |
| 3400 | - } | |
| 3401 | - }); | |
| 3402 | - | |
| 3403 | - fileFrame.on( 'select', function() { | |
| 3404 | - const attachment = fileFrame.state().get( 'selection' ).first().toJSON(); | |
| 3405 | - const img = imagePreview.querySelector( 'img' ); | |
| 3406 | - | |
| 3407 | - img.setAttribute( 'src', attachment.url ); | |
| 3408 | - img.classList.remove( 'frm_hidden' ); | |
| 3409 | - img.removeAttribute( 'srcset' ); // Prevent the old image from sticking around. | |
| 3410 | - | |
| 3411 | - imagePreview.querySelector( '.frm_image_preview_frame' ).style.display = 'block'; | |
| 3412 | - imagePreview.querySelector( '.frm_image_preview_title' ).textContent = attachment.filename; | |
| 3413 | - imagePreview.querySelector( '.frm_choose_image_box' ).style.display = 'none'; | |
| 3414 | - | |
| 3415 | - const $imagePreview = jQuery( imagePreview ); | |
| 3416 | - $imagePreview.siblings( 'input[name*="[label]"]' ).data( 'frmimgurl', attachment.url ); | |
| 3417 | - $imagePreview.find( 'input.frm_image_id' ).val( attachment.id ).trigger( 'change' ); | |
| 3418 | - wp.media.model.settings.post.id = 0; | |
| 3419 | - }); | |
| 3420 | - | |
| 3421 | - fileFrame.open(); | |
| 3422 | - } | |
| 3423 | - | |
| 3424 | - function removeImageFromOption( event ) { | |
| 3425 | - var $this = jQuery( this ), | |
| 3426 | - previewWrapper = $this.closest( '.frm_image_preview_wrapper' ); | |
| 3427 | - | |
| 3428 | - event.preventDefault(); | |
| 3429 | - event.stopPropagation(); | |
| 3430 | - | |
| 3431 | - previewWrapper.find( 'img' ).attr( 'src', '' ); | |
| 3432 | - previewWrapper.find( '.frm_image_preview_frame' ).hide(); | |
| 3433 | - previewWrapper.find( '.frm_choose_image_box' ).show(); | |
| 3434 | - previewWrapper.find( 'input.frm_image_id' ).val( 0 ).trigger( 'change' ); | |
| 3435 | - } | |
| 3436 | - | |
| 3437 | - function toggleMultiselect() { | |
| 3438 | - /*jshint validthis:true */ | |
| 3439 | - var dropdown = jQuery( this ).closest( 'li' ).find( '.frm_form_fields select' ); | |
| 3440 | - if ( this.checked ) { | |
| 3441 | - dropdown.attr( 'multiple', 'multiple' ); | |
| 3442 | - } else { | |
| 3443 | - dropdown.removeAttr( 'multiple' ); | |
| 3444 | - } | |
| 3445 | - } | |
| 3446 | - | |
| 3447 | - /** | |
| 3448 | - * Allow typing on form switcher click without an extra click to search. | |
| 3449 | - */ | |
| 3450 | - function focusSearchBox() { | |
| 3451 | - var searchBox = document.getElementById( 'dropform-search-input' ); | |
| 3452 | - if ( searchBox !== null ) { | |
| 3453 | - setTimeout( function() { | |
| 3454 | - searchBox.focus(); | |
| 3455 | - }, 100 ); | |
| 3456 | - } | |
| 3457 | - } | |
| 3458 | - | |
| 3459 | - /** | |
| 3460 | - * Dismiss a warning message and send an AJAX request to update the dismissal state. | |
| 3461 | - * | |
| 3462 | - * @since 6.3 | |
| 3463 | - * | |
| 3464 | - * @param {Event} event The event object associated with the click on the dismiss icon. | |
| 3465 | - */ | |
| 3466 | - function dismissWarningMessage( event ) { | |
| 3467 | - const target = event.target; | |
| 3468 | - | |
| 3469 | - const warningEl = target.closest( '.frm_warning_style' ); | |
| 3470 | - jQuery( warningEl ).fadeOut( 400, () => warningEl.remove() ); | |
| 3471 | - | |
| 3472 | - const action = target.dataset.action; | |
| 3473 | - const formData = new FormData(); | |
| 3474 | - doJsonPost( action, formData ); | |
| 3475 | - } | |
| 3476 | - | |
| 3477 | - /** | |
| 3478 | - * If a field is clicked in the builder, prevent inputs from changing. | |
| 3479 | - */ | |
| 3480 | - function stopFieldFocus( e ) { | |
| 3481 | - e.preventDefault(); | |
| 3482 | - } | |
| 3483 | - | |
| 3484 | - function deleteFieldOption() { | |
| 3485 | - /*jshint validthis:true */ | |
| 3486 | - var otherInput, | |
| 3487 | - parentLi = this.parentNode, | |
| 3488 | - parentUl = parentLi.parentNode, | |
| 3489 | - fieldId = this.getAttribute( 'data-fid' ); | |
| 3490 | - | |
| 3491 | - jQuery( parentLi ).fadeOut( 'slow', function() { | |
| 3492 | - jQuery( parentLi ).remove(); | |
| 3493 | - | |
| 3494 | - var hasOther = jQuery( parentUl ).find( '.frm_other_option' ); | |
| 3495 | - if ( hasOther.length < 1 ) { | |
| 3496 | - otherInput = document.getElementById( 'other_input_' + fieldId ); | |
| 3497 | - if ( otherInput !== null ) { | |
| 3498 | - otherInput.value = 0; | |
| 3499 | - } | |
| 3500 | - jQuery( '#other_button_' + fieldId ).fadeIn( 'slow' ); | |
| 3501 | - } | |
| 3502 | - }); | |
| 3503 | - } | |
| 3504 | - | |
| 3505 | - /** | |
| 3506 | - * If a radio button is set as default, allow a click to | |
| 3507 | - * deselect it. | |
| 3508 | - */ | |
| 3509 | - function maybeUncheckRadio() { | |
| 3510 | - var $self, uncheck, unbind, up; | |
| 3511 | - | |
| 3512 | - /*jshint validthis:true */ | |
| 3513 | - $self = jQuery( this ); | |
| 3514 | - if ( $self.is( ':checked' ) ) { | |
| 3515 | - uncheck = function() { | |
| 3516 | - setTimeout( function() { | |
| 3517 | - $self.prop( 'checked', false ); | |
| 3518 | - }, 0 ); | |
| 3519 | - }; | |
| 3520 | - unbind = function() { | |
| 3521 | - $self.off( 'mouseup', up ); | |
| 3522 | - }; | |
| 3523 | - up = function() { | |
| 3524 | - uncheck(); | |
| 3525 | - unbind(); | |
| 3526 | - }; | |
| 3527 | - $self.on( 'mouseup', up ); | |
| 3528 | - $self.one( 'mouseout', unbind ); | |
| 3529 | - } | |
| 3530 | - } | |
| 3531 | - | |
| 3532 | - /** | |
| 3533 | - * If the field option has the default text, clear it out on click. | |
| 3534 | - */ | |
| 3535 | - function maybeClearOptText() { | |
| 3536 | - /*jshint validthis:true */ | |
| 3537 | - if ( this.value === frm_admin_js.new_option ) { // eslint-disable-line camelcase | |
| 3538 | - this.setAttribute( 'data-value-on-focus', this.value ); | |
| 3539 | - this.value = ''; | |
| 3540 | - } | |
| 3541 | - } | |
| 3542 | - | |
| 3543 | - function confirmFieldsDeleteMessage( numberOfFields ) { | |
| 3544 | - /* translators: %1$s: Number of fields that are selected to be deleted. */ | |
| 3545 | - return __( 'Are you sure you want to delete these %1$s selected field(s)?', 'formidable' ).replace( '%1$s', numberOfFields ); | |
| 3546 | - } | |
| 3547 | - | |
| 3548 | - function clickDeleteField() { | |
| 3549 | - /*jshint validthis:true */ | |
| 3550 | - var confirmMsg = frm_admin_js.conf_delete, // eslint-disable-line camelcase | |
| 3551 | - maybeDivider = this.parentNode.parentNode.parentNode.parentNode.parentNode, | |
| 3552 | - li = maybeDivider.parentNode, | |
| 3553 | - field = jQuery( this ).closest( 'li.form-field' ), | |
| 3554 | - fieldId = field.data( 'fid' ); | |
| 3555 | - | |
| 3556 | - if ( field.data( 'ftype' ) === 'divider' ) { | |
| 3557 | - const fieldBoxes = document.querySelectorAll( '.frm-field-group-hover-target .start_divider .frm_field_box' ); | |
| 3558 | - let fieldIdsToDelete = 0; | |
| 3559 | - fieldBoxes.forEach( fieldBox => { | |
| 3560 | - const fieldsInsideFieldBox = fieldBox.querySelectorAll( 'li.form-field' ); | |
| 3561 | - if ( fieldsInsideFieldBox ) { | |
| 3562 | - fieldIdsToDelete += fieldsInsideFieldBox.length; | |
| 3563 | - } | |
| 3564 | - }); | |
| 3565 | - if ( fieldIdsToDelete ) { | |
| 3566 | - confirmMsg = confirmFieldsDeleteMessage( ++fieldIdsToDelete ); | |
| 3567 | - } | |
| 3568 | - } | |
| 3569 | - | |
| 3570 | - if ( li.classList.contains( 'frm-section-collapsed' ) || li.classList.contains( 'frm-page-collapsed' ) ) { | |
| 3571 | - return false; | |
| 3572 | - } | |
| 3573 | - | |
| 3574 | - // If deleting a section, use a special message. | |
| 3575 | - if ( maybeDivider.className === 'divider_section_only' ) { | |
| 3576 | - confirmMsg = frm_admin_js.conf_delete_sec; // eslint-disable-line camelcase | |
| 3577 | - } | |
| 3578 | - | |
| 3579 | - this.setAttribute( 'data-frmverify', confirmMsg ); | |
| 3580 | - this.setAttribute( 'data-frmverify-btn', 'frm-button-red' ); | |
| 3581 | - this.setAttribute( 'data-deletefield', fieldId ); | |
| 3582 | - | |
| 3583 | - closeOpenFieldDropdowns(); | |
| 3584 | - | |
| 3585 | - confirmLinkClick( this ); | |
| 3586 | - return false; | |
| 3587 | - } | |
| 3588 | - | |
| 3589 | - function clickSelectField() { | |
| 3590 | - this.closest( 'li.form-field' ).click(); | |
| 3591 | - } | |
| 3592 | - | |
| 3593 | - function clickDeleteFieldGroup() { | |
| 3594 | - var hoverTarget, decoy; | |
| 3595 | - | |
| 3596 | - hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3597 | - if ( null === hoverTarget ) { | |
| 3598 | - return; | |
| 3599 | - } | |
| 3600 | - | |
| 3601 | - hoverTarget.classList.add( 'frm-selected-field-group' ); | |
| 3602 | - | |
| 3603 | - decoy = document.createElement( 'div' ); | |
| 3604 | - decoy.classList.add( 'frm-delete-field-groups', 'frm_hidden' ); | |
| 3605 | - document.body.appendChild( decoy ); | |
| 3606 | - decoy.click(); | |
| 3607 | - } | |
| 3608 | - | |
| 3609 | - function duplicateFieldGroup() { | |
| 3610 | - const hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3611 | - if ( null === hoverTarget ) { | |
| 3612 | - return; | |
| 3613 | - } | |
| 3614 | - | |
| 3615 | - const newRowId = 'frm_field_group_' + getAutoId(); | |
| 3616 | - const placeholderUlChild = document.createTextNode( '' ); | |
| 3617 | - wrapFieldLiInPlace( placeholderUlChild ); | |
| 3618 | - | |
| 3619 | - const newRow = jQuery( placeholderUlChild ).closest( 'li' ).get( 0 ); | |
| 3620 | - newRow.classList.add( 'frm_hidden' ); | |
| 3621 | - | |
| 3622 | - const newRowUl = newRow.querySelector( 'ul' ); | |
| 3623 | - newRowUl.id = newRowId; | |
| 3624 | - | |
| 3625 | - jQuery( hoverTarget.closest( 'li.frm_field_box' ) ).after( newRow ); | |
| 3626 | - | |
| 3627 | - const $fields = getFieldsInRow( jQuery( hoverTarget ) ); | |
| 3628 | - const syncDetails = []; | |
| 3629 | - const injectedCloneOptions = []; | |
| 3630 | - | |
| 3631 | - const expectedLength = $fields.length; | |
| 3632 | - const originalFieldIdByDuplicatedFieldId = {}; | |
| 3633 | - | |
| 3634 | - let duplicatedCount = 0; | |
| 3635 | - | |
| 3636 | - jQuery( newRow ).on( | |
| 3637 | - 'frm_added_duplicated_field_to_row', | |
| 3638 | - function( _, args ) { | |
| 3639 | - originalFieldIdByDuplicatedFieldId[ jQuery( args.duplicatedFieldHtml ).attr( 'data-fid' ) ] = args.originalFieldId; | |
| 3640 | - | |
| 3641 | - if ( expectedLength > ++duplicatedCount ) { | |
| 3642 | - return; | |
| 3643 | - } | |
| 3644 | - | |
| 3645 | - const $newRowUl = jQuery( newRowUl ); | |
| 3646 | - const $duplicatedFields = getFieldsInRow( $newRowUl ); | |
| 3647 | - | |
| 3648 | - injectedCloneOptions.forEach( | |
| 3649 | - function( cloneOption ) { | |
| 3650 | - cloneOption.remove(); | |
| 3651 | - } | |
| 3652 | - ); | |
| 3653 | - | |
| 3654 | - for ( let index = 0; index < expectedLength; ++index ) { | |
| 3655 | - $newRowUl.append( $newRowUl.children( 'li.form-field[frm-field-order="' + index + '"]' ) ); | |
| 3656 | - } | |
| 3657 | - | |
| 3658 | - syncLayoutClasses( $duplicatedFields.first(), syncDetails ); | |
| 3659 | - newRow.classList.remove( 'frm_hidden' ); | |
| 3660 | - updateFieldOrder(); | |
| 3661 | - | |
| 3662 | - getFieldsInRow( $newRowUl ).each( | |
| 3663 | - function() { | |
| 3664 | - maybeDuplicateUnsavedSettings( originalFieldIdByDuplicatedFieldId[ this.getAttribute( 'data-fid' ) ], jQuery( this ).prop( 'outerHTML' ) ); | |
| 3665 | - } | |
| 3666 | - ); | |
| 3667 | - } | |
| 3668 | - ); | |
| 3669 | - | |
| 3670 | - $fields.each( | |
| 3671 | - function( index ) { | |
| 3672 | - var cloneOption; | |
| 3673 | - cloneOption = document.createElement( 'li' ); | |
| 3674 | - cloneOption.classList.add( 'frm_clone_field' ); | |
| 3675 | - cloneOption.setAttribute( 'frm-target-row-id', newRowId ); | |
| 3676 | - cloneOption.setAttribute( 'frm-field-order', index ); | |
| 3677 | - this.appendChild( cloneOption ); | |
| 3678 | - cloneOption.click(); | |
| 3679 | - injectedCloneOptions.push( cloneOption ); | |
| 3680 | - syncDetails.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) ); | |
| 3681 | - } | |
| 3682 | - ); | |
| 3683 | - } | |
| 3684 | - | |
| 3685 | - function clickFieldGroupLayout() { | |
| 3686 | - var hoverTarget, sizeOfFieldGroup, popupWrapper; | |
| 3687 | - | |
| 3688 | - hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3689 | - | |
| 3690 | - if ( null === hoverTarget ) { | |
| 3691 | - return; | |
| 3692 | - } | |
| 3693 | - | |
| 3694 | - deselectFields(); | |
| 3695 | - | |
| 3696 | - sizeOfFieldGroup = getSizeOfFieldGroupFromChildElement( hoverTarget.querySelector( 'li.form-field' ) ); | |
| 3697 | - | |
| 3698 | - hoverTarget.classList.add( 'frm-has-open-field-group-popup' ); | |
| 3699 | - jQuery( document ).on( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick ); | |
| 3700 | - | |
| 3701 | - popupWrapper = div(); | |
| 3702 | - popupWrapper.style.position = 'relative'; | |
| 3703 | - popupWrapper.appendChild( getFieldGroupPopup( sizeOfFieldGroup, this ) ); | |
| 3704 | - this.parentNode.appendChild( popupWrapper ); | |
| 3705 | - | |
| 3706 | - const firstLayoutOption = popupWrapper.querySelector( '.frm-row-layout-option' ); | |
| 3707 | - if ( firstLayoutOption ) { | |
| 3708 | - firstLayoutOption.focus(); | |
| 3709 | - } | |
| 3710 | - } | |
| 3711 | - | |
| 3712 | - function destroyFieldGroupPopupOnOutsideClick( event ) { | |
| 3713 | - if ( event.target.classList.contains( 'frm-custom-field-group-layout' ) || event.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) { | |
| 3714 | - return; | |
| 3715 | - } | |
| 3716 | - if ( ! jQuery( event.target ).closest( '#frm_field_group_controls' ).length && ! jQuery( event.target ).closest( '#frm_field_group_popup' ).length ) { | |
| 3717 | - destroyFieldGroupPopup(); | |
| 3718 | - } | |
| 3719 | - } | |
| 3720 | - | |
| 3721 | - function getSizeOfFieldGroupFromChildElement( element ) { | |
| 3722 | - var $ul = jQuery( element ).closest( 'ul' ); | |
| 3723 | - if ( $ul.length ) { | |
| 3724 | - return getFieldsInRow( $ul ).length; | |
| 3725 | - } | |
| 3726 | - return getSelectedFieldCount(); | |
| 3727 | - } | |
| 3728 | - | |
| 3729 | - function getFieldGroupPopup( sizeOfFieldGroup, childElement ) { | |
| 3730 | - var popup, wrapper, rowLayoutOptions, ul; | |
| 3731 | - | |
| 3732 | - popup = document.getElementById( 'frm_field_group_popup' ); | |
| 3733 | - if ( null === popup ) { | |
| 3734 | - popup = div(); | |
| 3735 | - } else { | |
| 3736 | - popup.innerHTML = ''; | |
| 3737 | - } | |
| 3738 | - | |
| 3739 | - popup.id = 'frm_field_group_popup'; | |
| 3740 | - | |
| 3741 | - wrapper = div(); | |
| 3742 | - wrapper.style.padding = '0 24px 12px'; | |
| 3743 | - wrapper.appendChild( getRowLayoutTitle() ); | |
| 3744 | - | |
| 3745 | - rowLayoutOptions = getRowLayoutOptions( sizeOfFieldGroup ); | |
| 3746 | - | |
| 3747 | - ul = childElement.closest( 'ul.frm_sorting' ); | |
| 3748 | - if ( null !== ul ) { | |
| 3749 | - maybeMarkRowLayoutAsActive( ul, rowLayoutOptions ); | |
| 3750 | - } | |
| 3751 | - | |
| 3752 | - wrapper.appendChild( rowLayoutOptions ); | |
| 3753 | - | |
| 3754 | - popup.appendChild( wrapper ); | |
| 3755 | - popup.appendChild( separator() ); | |
| 3756 | - | |
| 3757 | - popup.appendChild( getCustomLayoutOption() ); | |
| 3758 | - popup.appendChild( getBreakIntoDifferentRowsOption() ); | |
| 3759 | - | |
| 3760 | - return popup; | |
| 3761 | - } | |
| 3762 | - | |
| 3763 | - function maybeMarkRowLayoutAsActive( activeRow, options ) { | |
| 3764 | - var length, index, currentRow; | |
| 3765 | - | |
| 3766 | - length = options.children.length; | |
| 3767 | - for ( index = 0; index < length; ++index ) { | |
| 3768 | - currentRow = options.children[ index ]; | |
| 3769 | - if ( rowLayoutsMatch( currentRow, activeRow ) ) { | |
| 3770 | - currentRow.classList.add( 'frm-active-row-layout' ); | |
| 3771 | - return; | |
| 3772 | - } | |
| 3773 | - } | |
| 3774 | - } | |
| 3775 | - | |
| 3776 | - function separator() { | |
| 3777 | - var hr = document.createElement( 'hr' ); | |
| 3778 | - return hr; | |
| 3779 | - } | |
| 3780 | - | |
| 3781 | - function getCustomLayoutOption() { | |
| 3782 | - var option = div(); | |
| 3783 | - option.textContent = __( 'Custom layout', 'formidable' ); | |
| 3784 | - jQuery( option ).prepend( getIconClone( 'frm_gear_svg' ) ); | |
| 3785 | - option.classList.add( 'frm-custom-field-group-layout' ); | |
| 3786 | - makeTabbable( option ); | |
| 3787 | - return option; | |
| 3788 | - } | |
| 3789 | - | |
| 3790 | - function makeTabbable( element, ariaLabel ) { | |
| 3791 | - element.setAttribute( 'tabindex', 0 ); | |
| 3792 | - element.setAttribute( 'role', 'button' ); | |
| 3793 | - if ( 'undefined' !== typeof ariaLabel ) { | |
| 3794 | - element.setAttribute( 'aria-label', ariaLabel ); | |
| 3795 | - } | |
| 3796 | - } | |
| 3797 | - | |
| 3798 | - function getIconClone( iconId ) { | |
| 3799 | - var clone = document.getElementById( iconId ).cloneNode( true ); | |
| 3800 | - clone.id = ''; | |
| 3801 | - return clone; | |
| 3802 | - } | |
| 3803 | - | |
| 3804 | - function getBreakIntoDifferentRowsOption() { | |
| 3805 | - var option = div(); | |
| 3806 | - option.textContent = __( 'Break into rows', 'formidable' ); | |
| 3807 | - jQuery( option ).prepend( getIconClone( 'frm_break_field_group_svg' ) ); | |
| 3808 | - option.classList.add( 'frm-break-field-group' ); | |
| 3809 | - makeTabbable( option ); | |
| 3810 | - return option; | |
| 3811 | - } | |
| 3812 | - | |
| 3813 | - function getRowLayoutTitle() { | |
| 3814 | - var rowLayoutTitle = div(); | |
| 3815 | - rowLayoutTitle.classList.add( 'frm-row-layout-title' ); | |
| 3816 | - rowLayoutTitle.textContent = __( 'Row Layout', 'formidable' ); | |
| 3817 | - return rowLayoutTitle; | |
| 3818 | - } | |
| 3819 | - | |
| 3820 | - function getRowLayoutOptions( size ) { | |
| 3821 | - var wrapper, padding; | |
| 3822 | - | |
| 3823 | - wrapper = getEmptyGridContainer(); | |
| 3824 | - if ( 5 !== size ) { | |
| 3825 | - wrapper.appendChild( getRowLayoutOption( size, 'even' ) ); | |
| 3826 | - } | |
| 3827 | - if ( size % 2 === 1 ) { | |
| 3828 | - // only include the middle option for odd numbers because even doesn't make a lot of sense. | |
| 3829 | - wrapper.appendChild( getRowLayoutOption( size, 'middle' ) ); | |
| 3830 | - } | |
| 3831 | - if ( size < 6 ) { | |
| 3832 | - wrapper.appendChild( getRowLayoutOption( size, 'left' ) ); | |
| 3833 | - wrapper.appendChild( getRowLayoutOption( size, 'right' ) ); | |
| 3834 | - } else { | |
| 3835 | - padding = div(); | |
| 3836 | - padding.classList.add( 'frm_fourth' ); | |
| 3837 | - wrapper.prepend( padding ); | |
| 3838 | - } | |
| 3839 | - | |
| 3840 | - return wrapper; | |
| 3841 | - } | |
| 3842 | - | |
| 3843 | - function getRowLayoutOption( size, type ) { | |
| 3844 | - var option, useClass; | |
| 3845 | - | |
| 3846 | - option = div(); | |
| 3847 | - option.classList.add( 'frm-row-layout-option' ); | |
| 3848 | - makeTabbable( option, type ); | |
| 3849 | - | |
| 3850 | - switch ( size ) { | |
| 3851 | - case 6: | |
| 3852 | - useClass = 'frm_half'; | |
| 3853 | - break; | |
| 3854 | - case 5: | |
| 3855 | - useClass = 'frm_third'; | |
| 3856 | - break; | |
| 3857 | - default: | |
| 3858 | - useClass = size % 2 === 1 ? 'frm_fourth' : 'frm_third'; | |
| 3859 | - break; | |
| 3860 | - } | |
| 3861 | - | |
| 3862 | - option.classList.add( useClass ); | |
| 3863 | - option.setAttribute( 'layout-type', type ); | |
| 3864 | - | |
| 3865 | - option.appendChild( getRowForSizeAndType( size, type ) ); | |
| 3866 | - return option; | |
| 3867 | - } | |
| 3868 | - | |
| 3869 | - function rowLayoutsMatch( row1, row2 ) { | |
| 3870 | - return getRowLayoutAsKey( row1 ) === getRowLayoutAsKey( row2 ); | |
| 3871 | - } | |
| 3872 | - | |
| 3873 | - function getRowLayoutAsKey( row ) { | |
| 3874 | - var $fields, sizes; | |
| 3875 | - if ( row.classList.contains( 'frm-row-layout-option' ) ) { | |
| 3876 | - $fields = jQuery( row ).find( '.frm_grid_container' ).children(); | |
| 3877 | - } else { | |
| 3878 | - $fields = getFieldsInRow( jQuery( row ) ); | |
| 3879 | - } | |
| 3880 | - sizes = []; | |
| 3881 | - $fields.each( | |
| 3882 | - function() { | |
| 3883 | - sizes.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) ); | |
| 3884 | - } | |
| 3885 | - ); | |
| 3886 | - return sizes.join( '-' ); | |
| 3887 | - } | |
| 3888 | - | |
| 3889 | - function getRowForSizeAndType( size, type ) { | |
| 3890 | - var row, index, block; | |
| 3891 | - | |
| 3892 | - row = getEmptyGridContainer(); | |
| 3893 | - for ( index = 0; index < size; ++index ) { | |
| 3894 | - block = div(); | |
| 3895 | - block.classList.add( getClassForBlock( size, type, index ) ); | |
| 3896 | - block.style.height = '16px'; | |
| 3897 | - block.style.background = '#9EA9B8'; | |
| 3898 | - block.style.borderRadius = '1px'; | |
| 3899 | - row.appendChild( block ); | |
| 3900 | - } | |
| 3901 | - | |
| 3902 | - return row; | |
| 3903 | - } | |
| 3904 | - | |
| 3905 | - /** | |
| 3906 | - * @param {int} size 2-6. | |
| 3907 | - * @param {string} type even, middle, left, or right. | |
| 3908 | - * @param {int} index 0-5. | |
| 3909 | - * @returns string | |
| 3910 | - */ | |
| 3911 | - function getClassForBlock( size, type, index ) { | |
| 3912 | - if ( 'even' === type ) { | |
| 3913 | - return getEvenClassForSize( size, index ); | |
| 3914 | - } else if ( 'middle' === type ) { | |
| 3915 | - if ( 3 === size ) { | |
| 3916 | - return 1 === index ? 'frm6' : 'frm3'; | |
| 3917 | - } | |
| 3918 | - if ( 5 === size ) { | |
| 3919 | - return 2 === index ? 'frm4' : 'frm2'; | |
| 3920 | - } | |
| 3921 | - } else if ( 'left' === type ) { | |
| 3922 | - return 0 === index ? getLargeClassForSize( size ) : getSmallClassForSize( size ); | |
| 3923 | - } else if ( 'right' === type ) { | |
| 3924 | - return index === size - 1 ? getLargeClassForSize( size ) : getSmallClassForSize( size ); | |
| 3925 | - } | |
| 3926 | - return 'frm12'; | |
| 3927 | - } | |
| 3928 | - | |
| 3929 | - function getEvenClassForSize( size, index ) { | |
| 3930 | - if ( -1 !== [ 2, 3, 4, 6 ].indexOf( size ) ) { | |
| 3931 | - return getLayoutClassForSize( 12 / size ); | |
| 3932 | - } | |
| 3933 | - if ( 5 === size && 'undefined' !== typeof index ) { | |
| 3934 | - return 0 === index ? 'frm4' : 'frm2'; | |
| 3935 | - } | |
| 3936 | - return 'frm12'; | |
| 3937 | - } | |
| 3938 | - | |
| 3939 | - function getSmallClassForSize( size ) { | |
| 3940 | - switch ( size ) { | |
| 3941 | - case 2: case 3: | |
| 3942 | - return 'frm3'; | |
| 3943 | - case 4: | |
| 3944 | - return 'frm2'; | |
| 3945 | - case 5: | |
| 3946 | - return 'frm2'; | |
| 3947 | - case 6: | |
| 3948 | - return 'frm1'; | |
| 3949 | - } | |
| 3950 | - return 'frm12'; | |
| 3951 | - } | |
| 3952 | - | |
| 3953 | - function getLargeClassForSize( size ) { | |
| 3954 | - switch ( size ) { | |
| 3955 | - case 2: | |
| 3956 | - return 'frm9'; | |
| 3957 | - case 3: case 4: | |
| 3958 | - return 'frm6'; | |
| 3959 | - case 5: | |
| 3960 | - return 'frm4'; | |
| 3961 | - case 6: | |
| 3962 | - return 'frm7'; | |
| 3963 | - } | |
| 3964 | - return 'frm12'; | |
| 3965 | - } | |
| 3966 | - | |
| 3967 | - function getEmptyGridContainer() { | |
| 3968 | - var wrapper = div(); | |
| 3969 | - wrapper.classList.add( 'frm_grid_container' ); | |
| 3970 | - return wrapper; | |
| 3971 | - } | |
| 3972 | - | |
| 3973 | - /** | |
| 3974 | - * Handle when a field group layout option (that sets grid classes/column sizing) is selected in the "Row Layout" popup. | |
| 3975 | - * | |
| 3976 | - * @returns {void} | |
| 3977 | - */ | |
| 3978 | - function handleFieldGroupLayoutOptionClick() { | |
| 3979 | - const row = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3980 | - if ( ! row ) { | |
| 3981 | - // The field group layout options also get clicked when merging multiple rows. | |
| 3982 | - // The following code isn't required for multiple rows though so just exit early. | |
| 3983 | - return; | |
| 3984 | - } | |
| 3985 | - | |
| 3986 | - const type = this.getAttribute( 'layout-type' ); | |
| 3987 | - syncLayoutClasses( getFieldsInRow( jQuery( row ) ).first(), type ); | |
| 3988 | - destroyFieldGroupPopup(); | |
| 3989 | - } | |
| 3990 | - | |
| 3991 | - function handleFieldGroupLayoutOptionInsideMergeClick() { | |
| 3992 | - var $ul, type; | |
| 3993 | - $ul = mergeSelectedFieldGroups(); | |
| 3994 | - type = this.getAttribute( 'layout-type' ); | |
| 3995 | - syncLayoutClasses( getFieldsInRow( $ul ).first(), type ); | |
| 3996 | - unselectFieldGroups(); | |
| 3997 | - } | |
| 3998 | - | |
| 3999 | - function mergeSelectedFieldGroups() { | |
| 4000 | - var $selectedFieldGroups = jQuery( '.frm-selected-field-group' ), | |
| 4001 | - $firstGroupUl = $selectedFieldGroups.first(); | |
| 4002 | - $selectedFieldGroups.not( $firstGroupUl ).each( | |
| 4003 | - function() { | |
| 4004 | - getFieldsInRow( jQuery( this ) ).each( | |
| 4005 | - function() { | |
| 4006 | - var previousParent = this.parentNode; | |
| 4007 | - getFieldsInRow( $firstGroupUl ).last().after( this ); | |
| 4008 | - if ( ! jQuery( previousParent ).children( 'li.form-field' ).length ) { | |
| 4009 | - // clean up the previous field group if we've removed all of its fields. | |
| 4010 | - previousParent.closest( 'li.frm_field_box' ).remove(); | |
| 4011 | - } | |
| 4012 | - } | |
| 4013 | - ); | |
| 4014 | - } | |
| 4015 | - ); | |
| 4016 | - updateFieldOrder(); | |
| 4017 | - syncLayoutClasses( getFieldsInRow( $firstGroupUl ).first() ); | |
| 4018 | - return $firstGroupUl; | |
| 4019 | - } | |
| 4020 | - | |
| 4021 | - function customFieldGroupLayoutClick() { | |
| 4022 | - var $fields; | |
| 4023 | - if ( null !== this.closest( '.frm-merge-fields-into-row' ) ) { | |
| 4024 | - return; | |
| 4025 | - } | |
| 4026 | - $fields = getFieldsInRow( jQuery( '.frm-field-group-hover-target' ) ); | |
| 4027 | - setupCustomLayoutOptions( $fields ); | |
| 4028 | - } | |
| 4029 | - | |
| 4030 | - function setupCustomLayoutOptions( $fields ) { | |
| 4031 | - var size, popup, wrapper, layoutClass, inputRow, paddingElement, inputValueOverride, index, inputField, heading, label, buttonsWrapper, cancelButton, saveButton; | |
| 4032 | - | |
| 4033 | - size = $fields.length; | |
| 4034 | - | |
| 4035 | - popup = document.getElementById( 'frm_field_group_popup' ); | |
| 4036 | - popup.innerHTML = ''; | |
| 4037 | - | |
| 4038 | - wrapper = div(); | |
| 4039 | - wrapper.style.padding = '24px'; | |
| 4040 | - | |
| 4041 | - layoutClass = getEvenClassForSize( 5 === size ? 6 : size ); | |
| 4042 | - | |
| 4043 | - inputRow = div(); | |
| 4044 | - inputRow.style.padding = '20px 0'; | |
| 4045 | - inputRow.classList.add( 'frm_grid_container' ); | |
| 4046 | - | |
| 4047 | - if ( 5 === size ) { | |
| 4048 | - // add a span to pad the inputs by 1 column, to account for the missing 2 columns. | |
| 4049 | - paddingElement = document.createElement( 'span' ); | |
| 4050 | - paddingElement.classList.add( 'frm1' ); | |
| 4051 | - inputRow.appendChild( paddingElement ); | |
| 4052 | - } | |
| 4053 | - | |
| 4054 | - inputValueOverride = getSelectedFieldCount() > 0 ? getSizeOfLayoutClass( getEvenClassForSize( size ) ) : false; | |
| 4055 | - if ( false !== inputValueOverride && inputValueOverride >= 12 ) { | |
| 4056 | - inputValueOverride = Math.floor( 12 / size ); | |
| 4057 | - } | |
| 4058 | - | |
| 4059 | - for ( index = 0; index < size; ++index ) { | |
| 4060 | - inputField = document.createElement( 'input' ); | |
| 4061 | - inputField.type = 'text'; | |
| 4062 | - inputField.classList.add( layoutClass ); | |
| 4063 | - inputField.classList.add( 'frm-custom-grid-size-input' ); | |
| 4064 | - inputField.value = false !== inputValueOverride ? inputValueOverride : getSizeOfLayoutClass( getLayoutClassName( $fields.get( index ).classList ) ); | |
| 4065 | - inputRow.appendChild( inputField ); | |
| 4066 | - } | |
| 4067 | - | |
| 4068 | - heading = div(); | |
| 4069 | - heading.classList.add( 'frm-builder-popup-heading' ); | |
| 4070 | - heading.textContent = __( 'Enter number of columns for each field', 'formidable' ); | |
| 4071 | - | |
| 4072 | - label = div(); | |
| 4073 | - label.classList.add( 'frm-builder-popup-subheading' ); | |
| 4074 | - label.textContent = __( 'Layouts are based on a 12-column grid system', 'formidable' ); | |
| 4075 | - | |
| 4076 | - wrapper.appendChild( heading ); | |
| 4077 | - wrapper.appendChild( label ); | |
| 4078 | - | |
| 4079 | - wrapper.appendChild( inputRow ); | |
| 4080 | - | |
| 4081 | - buttonsWrapper = div(); | |
| 4082 | - buttonsWrapper.style.textAlign = 'right'; | |
| 4083 | - | |
| 4084 | - cancelButton = getSecondaryButton(); | |
| 4085 | - cancelButton.textContent = __( 'Cancel', 'formidable' ); | |
| 4086 | - cancelButton.classList.add( 'frm-cancel-custom-field-group-layout' ); | |
| 4087 | - cancelButton.style.marginRight = '10px'; | |
| 4088 | - | |
| 4089 | - saveButton = getPrimaryButton(); | |
| 4090 | - saveButton.textContent = __( 'Save', 'formidable' ); | |
| 4091 | - saveButton.classList.add( 'frm-save-custom-field-group-layout' ); | |
| 4092 | - | |
| 4093 | - buttonsWrapper.appendChild( cancelButton ); | |
| 4094 | - buttonsWrapper.appendChild( saveButton ); | |
| 4095 | - | |
| 4096 | - wrapper.appendChild( buttonsWrapper ); | |
| 4097 | - | |
| 4098 | - popup.appendChild( wrapper ); | |
| 4099 | - | |
| 4100 | - setTimeout( | |
| 4101 | - function() { | |
| 4102 | - const firstInput = popup.querySelector( 'input.frm-custom-grid-size-input' ).focus(); | |
| 4103 | - if ( firstInput ) { | |
| 4104 | - firstInput.focus(); | |
| 4105 | - } | |
| 4106 | - }, | |
| 4107 | - 0 | |
| 4108 | - ); | |
| 4109 | - } | |
| 4110 | - | |
| 4111 | - function customFieldGroupLayoutInsideMergeClick() { | |
| 4112 | - $fields = jQuery( '.frm-selected-field-group li.form-field' ); | |
| 4113 | - setupCustomLayoutOptions( $fields ); | |
| 4114 | - } | |
| 4115 | - | |
| 4116 | - function getPrimaryButton() { | |
| 4117 | - var button = getButton(); | |
| 4118 | - button.classList.add( 'button-primary', 'frm-button-primary' ); | |
| 4119 | - return button; | |
| 4120 | - } | |
| 4121 | - | |
| 4122 | - function getSecondaryButton() { | |
| 4123 | - var button = getButton(); | |
| 4124 | - button.classList.add( 'button-secondary', 'frm-button-secondary' ); | |
| 4125 | - return button; | |
| 4126 | - } | |
| 4127 | - | |
| 4128 | - function getButton() { | |
| 4129 | - var button = document.createElement( 'a' ); | |
| 4130 | - button.setAttribute( 'href', '#' ); | |
| 4131 | - button.classList.add( 'button' ); | |
| 4132 | - button.style.textDecoration = 'none'; | |
| 4133 | - return button; | |
| 4134 | - } | |
| 4135 | - | |
| 4136 | - function getSizeOfLayoutClass( className ) { | |
| 4137 | - switch ( className ) { | |
| 4138 | - case 'frm_half': | |
| 4139 | - return 6; | |
| 4140 | - case 'frm_third': | |
| 4141 | - return 4; | |
| 4142 | - case 'frm_two_thirds': | |
| 4143 | - return 8; | |
| 4144 | - case 'frm_fourth': | |
| 4145 | - return 3; | |
| 4146 | - case 'frm_three_fourths': | |
| 4147 | - return 9; | |
| 4148 | - case 'frm_sixth': | |
| 4149 | - return 2; | |
| 4150 | - } | |
| 4151 | - | |
| 4152 | - if ( 0 === className.indexOf( 'frm' ) ) { | |
| 4153 | - return parseInt( className.substr( 3 ) ); | |
| 4154 | - } | |
| 4155 | - | |
| 4156 | - // Anything missing a layout class should be a full width row. | |
| 4157 | - return 12; | |
| 4158 | - } | |
| 4159 | - | |
| 4160 | - function getLayoutClassName( classList ) { | |
| 4161 | - var classes, index, currentClass; | |
| 4162 | - classes = getLayoutClasses(); | |
| 4163 | - for ( index = 0; index < classes.length; ++index ) { | |
| 4164 | - currentClass = classes[ index ]; | |
| 4165 | - if ( classList.contains( currentClass ) ) { | |
| 4166 | - return currentClass; | |
| 4167 | - } | |
| 4168 | - } | |
| 4169 | - return ''; | |
| 4170 | - } | |
| 4171 | - | |
| 4172 | - function getLayoutClassForSize( size ) { | |
| 4173 | - return 'frm' + size; | |
| 4174 | - } | |
| 4175 | - | |
| 4176 | - function breakFieldGroupClick() { | |
| 4177 | - var row = document.querySelector( '.frm-field-group-hover-target' ); | |
| 4178 | - breakRow( row ); | |
| 4179 | - destroyFieldGroupPopup(); | |
| 4180 | - } | |
| 4181 | - | |
| 4182 | - function breakRow( row ) { | |
| 4183 | - const $row = jQuery( row ); | |
| 4184 | - getFieldsInRow( $row ).each( | |
| 4185 | - function( index ) { | |
| 4186 | - const field = this; | |
| 4187 | - if ( 0 !== index ) { | |
| 4188 | - $row.parent().after( wrapFieldLi( field ) ); | |
| 4189 | - } | |
| 4190 | - stripLayoutFromFields( jQuery( field ) ); | |
| 4191 | - } | |
| 4192 | - ); | |
| 4193 | - } | |
| 4194 | - | |
| 4195 | - function stripLayoutFromFields( field ) { | |
| 4196 | - syncLayoutClasses( field, 'clear' ); | |
| 4197 | - } | |
| 4198 | - | |
| 4199 | - function focusFieldGroupInputOnClick() { | |
| 4200 | - this.select(); | |
| 4201 | - } | |
| 4202 | - | |
| 4203 | - function cancelCustomFieldGroupClick() { | |
| 4204 | - revertToFieldGroupPopupFirstPage( this ); | |
| 4205 | - } | |
| 4206 | - | |
| 4207 | - function revertToFieldGroupPopupFirstPage( triggerElement ) { | |
| 4208 | - jQuery( document.getElementById( 'frm_field_group_popup' ) ).replaceWith( | |
| 4209 | - getFieldGroupPopup( getSizeOfFieldGroupFromChildElement( triggerElement ), triggerElement ) | |
| 4210 | - ); | |
| 4211 | - } | |
| 4212 | - | |
| 4213 | - function destroyFieldGroupPopup() { | |
| 4214 | - var popup, wrapper; | |
| 4215 | - popup = document.getElementById( 'frm_field_group_popup' ); | |
| 4216 | - if ( popup === null ) { | |
| 4217 | - return; | |
| 4218 | - } | |
| 4219 | - wrapper = document.querySelector( '.frm-has-open-field-group-popup' ); | |
| 4220 | - if ( null !== wrapper ) { | |
| 4221 | - wrapper.classList.remove( 'frm-has-open-field-group-popup' ); | |
| 4222 | - popup.parentNode.remove(); | |
| 4223 | - } | |
| 4224 | - jQuery( document ).off( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick ); | |
| 4225 | - } | |
| 4226 | - | |
| 4227 | - function saveCustomFieldGroupClick() { | |
| 4228 | - var syncDetails, $controls, $ul; | |
| 4229 | - | |
| 4230 | - syncDetails = []; | |
| 4231 | - | |
| 4232 | - jQuery( document.getElementById( 'frm_field_group_popup' ).querySelectorAll( '.frm_grid_container input' ) ) | |
| 4233 | - .each( | |
| 4234 | - function() { | |
| 4235 | - syncDetails.push( parseInt( this.value ) ); | |
| 4236 | - } | |
| 4237 | - ); | |
| 4238 | - | |
| 4239 | - $controls = jQuery( document.getElementById( 'frm_field_group_controls' ) ); | |
| 4240 | - | |
| 4241 | - if ( $controls.length && 'none' !== $controls.get( 0 ).style.display ) { | |
| 4242 | - syncLayoutClasses( getFieldsInRow( jQuery( document.querySelector( '.frm-field-group-hover-target' ) ) ).first(), syncDetails ); | |
| 4243 | - } else { | |
| 4244 | - $ul = mergeSelectedFieldGroups(); | |
| 4245 | - syncLayoutClasses( getFieldsInRow( $ul ).first(), syncDetails ); | |
| 4246 | - unselectFieldGroups(); | |
| 4247 | - } | |
| 4248 | - | |
| 4249 | - destroyFieldGroupPopup(); | |
| 4250 | - } | |
| 4251 | - | |
| 4252 | - function fieldGroupClick( e ) { | |
| 4253 | - if ( 'ul' !== e.originalEvent.target.nodeName.toLowerCase() ) { | |
| 4254 | - // only continue if the group itself was clicked / ignore when a field is clicked. | |
| 4255 | - return; | |
| 4256 | - } | |
| 4257 | - | |
| 4258 | - const hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 4259 | - if ( ! hoverTarget ) { | |
| 4260 | - return; | |
| 4261 | - } | |
| 4262 | - | |
| 4263 | - const ctrlOrCmdKeyIsDown = e.ctrlKey || e.metaKey; | |
| 4264 | - const shiftKeyIsDown = e.shiftKey; | |
| 4265 | - const groupIsActive = hoverTarget.classList.contains( 'frm-selected-field-group' ); | |
| 4266 | - const $selectedFieldGroups = getSelectedFieldGroups(); | |
| 4267 | - | |
| 4268 | - let numberOfSelectedGroups = $selectedFieldGroups.length; | |
| 4269 | - | |
| 4270 | - if ( ctrlOrCmdKeyIsDown || shiftKeyIsDown ) { | |
| 4271 | - // multi-selecting | |
| 4272 | - | |
| 4273 | - const selectedField = getSelectedField(); | |
| 4274 | - if ( null !== selectedField && ! jQuery( selectedField ).siblings( 'li.form-field' ).length ) { | |
| 4275 | - // count a selected field on its own as a selected field group when multiselecting. | |
| 4276 | - selectedField.parentNode.classList.add( 'frm-selected-field-group' ); | |
| 4277 | - ++numberOfSelectedGroups; | |
| 4278 | - } | |
| 4279 | - | |
| 4280 | - if ( ctrlOrCmdKeyIsDown ) { | |
| 4281 | - if ( groupIsActive ) { | |
| 4282 | - // unselect if holding ctrl or cmd and the group was already active. | |
| 4283 | - --numberOfSelectedGroups; | |
| 4284 | - hoverTarget.classList.remove( 'frm-selected-field-group' ); | |
| 4285 | - syncAfterMultiSelect( numberOfSelectedGroups ); | |
| 4286 | - return; // exit early to avoid adding back frm-selected-field-group | |
| 4287 | - } else { | |
| 4288 | - ++numberOfSelectedGroups; | |
| 4289 | - } | |
| 4290 | - } else if ( shiftKeyIsDown && ! groupIsActive ) { | |
| 4291 | - ++numberOfSelectedGroups; // include the one we're selecting right now. | |
| 4292 | - const $firstGroup = $selectedFieldGroups.first(); | |
| 4293 | - | |
| 4294 | - let $range; | |
| 4295 | - if ( $firstGroup.parent().index() < jQuery( hoverTarget.parentNode ).index() ) { | |
| 4296 | - $range = $firstGroup.parent().nextUntil( hoverTarget.parentNode ); | |
| 4297 | - } else { | |
| 4298 | - $range = $firstGroup.parent().prevUntil( hoverTarget.parentNode ); | |
| 4299 | - } | |
| 4300 | - | |
| 4301 | - $range.each( | |
| 4302 | - function() { | |
| 4303 | - var $fieldGroup = jQuery( this ).closest( 'li' ).find( 'ul.frm_sorting' ); | |
| 4304 | - if ( ! $fieldGroup.hasClass( 'frm-selected-field-group' ) ) { | |
| 4305 | - ++numberOfSelectedGroups; | |
| 4306 | - $fieldGroup.addClass( 'frm-selected-field-group' ); | |
| 4307 | - } | |
| 4308 | - } | |
| 4309 | - ); | |
| 4310 | - | |
| 4311 | - // when holding shift and clicking, text gets selected. unselect it. | |
| 4312 | - document.getSelection().removeAllRanges(); | |
| 4313 | - } | |
| 4314 | - } else { | |
| 4315 | - // not multi-selecting | |
| 4316 | - unselectFieldGroups(); | |
| 4317 | - numberOfSelectedGroups = 1; | |
| 4318 | - } | |
| 4319 | - | |
| 4320 | - hoverTarget.classList.add( 'frm-selected-field-group' ); | |
| 4321 | - syncAfterMultiSelect( numberOfSelectedGroups ); | |
| 4322 | - | |
| 4323 | - jQuery( document ).off( 'click', unselectFieldGroups ); | |
| 4324 | - jQuery( document ).on( 'click', unselectFieldGroups ); | |
| 4325 | - } | |
| 4326 | - | |
| 4327 | - function getSelectedField() { | |
| 4328 | - return document.getElementById( 'frm-show-fields' ).querySelector( 'li.form-field.selected' ); | |
| 4329 | - } | |
| 4330 | - | |
| 4331 | - function getSelectedFieldGroups() { | |
| 4332 | - const $fieldGroups = jQuery( '.frm-selected-field-group' ); | |
| 4333 | - if ( $fieldGroups.length ) { | |
| 4334 | - return $fieldGroups; | |
| 4335 | - } | |
| 4336 | - | |
| 4337 | - const selectedField = getSelectedField(); | |
| 4338 | - if ( selectedField ) { | |
| 4339 | - // If there is only one field in a group and the field is selected, consider the field's group as selected for multi-select. | |
| 4340 | - const selectedFieldGroup = selectedField.closest( 'ul' ); | |
| 4341 | - if ( selectedFieldGroup && 1 === getFieldsInRow( jQuery( selectedFieldGroup ) ).length ) { | |
| 4342 | - selectedFieldGroup.classList.add( 'frm-selected-field-group' ); | |
| 4343 | - return jQuery( selectedFieldGroup ); | |
| 4344 | - } | |
| 4345 | - } | |
| 4346 | - | |
| 4347 | - return jQuery(); | |
| 4348 | - } | |
| 4349 | - | |
| 4350 | - function syncAfterMultiSelect( numberOfSelectedGroups ) { | |
| 4351 | - clearSettingsBox( true ); // unselect any fields if one is selected. | |
| 4352 | - if ( numberOfSelectedGroups >= 2 || ( 1 === numberOfSelectedGroups && selectedGroupHasMultipleFields() ) ) { | |
| 4353 | - addFieldMultiselectPopup(); | |
| 4354 | - } else { | |
| 4355 | - maybeRemoveMultiselectPopup(); | |
| 4356 | - } | |
| 4357 | - maybeRemoveGroupHoverTarget(); | |
| 4358 | - } | |
| 4359 | - | |
| 4360 | - function selectedGroupHasMultipleFields() { | |
| 4361 | - return getFieldsInRow( jQuery( document.querySelector( '.frm-selected-field-group' ) ) ).length > 1; | |
| 4362 | - } | |
| 4363 | - | |
| 4364 | - function unselectFieldGroups( event ) { | |
| 4365 | - if ( 'undefined' !== typeof event ) { | |
| 4366 | - if ( null !== event.originalEvent.target.closest( '#frm-show-fields' ) ) { | |
| 4367 | - return; | |
| 4368 | - } | |
| 4369 | - if ( event.originalEvent.target.classList.contains( 'frm-merge-fields-into-row' ) ) { | |
| 4370 | - return; | |
| 4371 | - } | |
| 4372 | - if ( null !== event.originalEvent.target.closest( '.frm-merge-fields-into-row' ) ) { | |
| 4373 | - return; | |
| 4374 | - } | |
| 4375 | - if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) { | |
| 4376 | - return; | |
| 4377 | - } | |
| 4378 | - if ( event.originalEvent.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) { | |
| 4379 | - return; | |
| 4380 | - } | |
| 4381 | - } | |
| 4382 | - jQuery( '.frm-selected-field-group' ).removeClass( 'frm-selected-field-group' ); | |
| 4383 | - jQuery( document ).off( 'click', unselectFieldGroups ); | |
| 4384 | - maybeRemoveMultiselectPopup(); | |
| 4385 | - } | |
| 4386 | - | |
| 4387 | - function maybeRemoveMultiselectPopup() { | |
| 4388 | - var popup = document.getElementById( 'frm_field_multiselect_popup' ); | |
| 4389 | - if ( null !== popup ) { | |
| 4390 | - popup.remove(); | |
| 4391 | - } | |
| 4392 | - } | |
| 4393 | - | |
| 4394 | - function addFieldMultiselectPopup() { | |
| 4395 | - getFieldMultiselectPopup(); | |
| 4396 | - } | |
| 4397 | - | |
| 4398 | - function getFieldMultiselectPopup() { | |
| 4399 | - var popup, mergeOption, caret, verticalSeparator, deleteOption; | |
| 4400 | - | |
| 4401 | - popup = document.getElementById( 'frm_field_multiselect_popup' ); | |
| 4402 | - | |
| 4403 | - if ( null !== popup ) { | |
| 4404 | - popup.classList.toggle( 'frm-unmergable', ! selectedFieldsAreMergable() ); | |
| 4405 | - return popup; | |
| 4406 | - } | |
| 4407 | - | |
| 4408 | - popup = div(); | |
| 4409 | - popup.id = 'frm_field_multiselect_popup'; | |
| 4410 | - if ( ! selectedFieldsAreMergable() ) { | |
| 4411 | - popup.classList.add( 'frm-unmergable' ); | |
| 4412 | - } | |
| 4413 | - | |
| 4414 | - mergeOption = div(); | |
| 4415 | - mergeOption.classList.add( 'frm-merge-fields-into-row' ); | |
| 4416 | - mergeOption.textContent = __( 'Merge into row', 'formidable' ); | |
| 4417 | - | |
| 4418 | - caret = document.createElement( 'a' ); | |
| 4419 | - caret.style.marginLeft = '5px'; | |
| 4420 | - caret.classList.add( 'frm_icon_font', 'frm_arrowdown6_icon' ); | |
| 4421 | - caret.setAttribute( 'href', '#' ); | |
| 4422 | - mergeOption.appendChild( caret ); | |
| 4423 | - | |
| 4424 | - popup.appendChild( mergeOption ); | |
| 4425 | - | |
| 4426 | - verticalSeparator = div(); | |
| 4427 | - verticalSeparator.classList.add( 'frm-multiselect-popup-separator' ); | |
| 4428 | - popup.appendChild( verticalSeparator ); | |
| 4429 | - | |
| 4430 | - deleteOption = div(); | |
| 4431 | - deleteOption.classList.add( 'frm-delete-field-groups' ); | |
| 4432 | - deleteOption.appendChild( getIconClone( 'frm_trash_svg' ) ); | |
| 4433 | - popup.appendChild( deleteOption ); | |
| 4434 | - | |
| 4435 | - document.getElementById( 'post-body-content' ).appendChild( popup ); | |
| 4436 | - | |
| 4437 | - jQuery( popup ).hide().fadeIn(); | |
| 4438 | - | |
| 4439 | - return popup; | |
| 4440 | - } | |
| 4441 | - | |
| 4442 | - function selectedFieldsAreMergable() { | |
| 4443 | - var selectedFieldGroups, totalFieldCount, length, index, fieldGroup; | |
| 4444 | - selectedFieldGroups = document.querySelectorAll( '.frm-selected-field-group' ); | |
| 4445 | - length = selectedFieldGroups.length; | |
| 4446 | - if ( 1 === length ) { | |
| 4447 | - return false; | |
| 4448 | - } | |
| 4449 | - totalFieldCount = 0; | |
| 4450 | - for ( index = 0; index < length; ++index ) { | |
| 4451 | - fieldGroup = selectedFieldGroups[ index ]; | |
| 4452 | - if ( null !== fieldGroup.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ) ) { | |
| 4453 | - return false; | |
| 4454 | - } | |
| 4455 | - totalFieldCount += getFieldsInRow( jQuery( fieldGroup ) ).length; | |
| 4456 | - if ( totalFieldCount > 6 ) { | |
| 4457 | - return false; | |
| 4458 | - } | |
| 4459 | - } | |
| 4460 | - return true; | |
| 4461 | - } | |
| 4462 | - | |
| 4463 | - function mergeFieldsIntoRowClick( event ) { | |
| 4464 | - var size, popup; | |
| 4465 | - | |
| 4466 | - if ( null !== event.originalEvent.target.closest( '#frm_field_group_popup' ) ) { | |
| 4467 | - // prevent clicks within the popup from triggering the button again. | |
| 4468 | - return; | |
| 4469 | - } | |
| 4470 | - | |
| 4471 | - if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) { | |
| 4472 | - // avoid switching back to the first page when clicking the custom option nested inside of the merge option. | |
| 4473 | - return; | |
| 4474 | - } | |
| 4475 | - | |
| 4476 | - size = getSelectedFieldCount(); | |
| 4477 | - popup = getFieldGroupPopup( size, document.querySelector( '.frm-selected-field-group' ).firstChild ); | |
| 4478 | - this.appendChild( popup ); | |
| 4479 | - } | |
| 4480 | - | |
| 4481 | - function getSelectedFieldCount() { | |
| 4482 | - var count = 0; | |
| 4483 | - jQuery( document.querySelectorAll( '.frm-selected-field-group' ) ).each( | |
| 4484 | - function() { | |
| 4485 | - count += getFieldsInRow( jQuery( this ) ).length; | |
| 4486 | - } | |
| 4487 | - ); | |
| 4488 | - return count; | |
| 4489 | - } | |
| 4490 | - | |
| 4491 | - function deleteFieldGroupsClick() { | |
| 4492 | - var fieldIdsToDelete, deleteOnConfirm, multiselectPopup; | |
| 4493 | - | |
| 4494 | - fieldIdsToDelete = getSelectedFieldIds(); | |
| 4495 | - deleteOnConfirm = getDeleteSelectedFieldGroupsOnConfirmFunction( fieldIdsToDelete ); | |
| 4496 | - | |
| 4497 | - multiselectPopup = document.getElementById( 'frm_field_multiselect_popup' ); | |
| 4498 | - if ( null !== multiselectPopup ) { | |
| 4499 | - multiselectPopup.remove(); | |
| 4500 | - } | |
| 4501 | - | |
| 4502 | - this.setAttribute( 'data-frmverify', confirmFieldsDeleteMessage( fieldIdsToDelete.length ) ); | |
| 4503 | - confirmLinkClick( this ); | |
| 4504 | - | |
| 4505 | - jQuery( '#frm-confirmed-click' ).on( 'click', deleteOnConfirm ); | |
| 4506 | - jQuery( '#frm_confirm_modal' ).one( 'dialogclose', function() { | |
| 4507 | - jQuery( '#frm-confirmed-click' ).off( 'click', deleteOnConfirm ); | |
| 4508 | - }); | |
| 4509 | - } | |
| 4510 | - | |
| 4511 | - function getSelectedFieldIds() { | |
| 4512 | - var deleteFieldIds = []; | |
| 4513 | - jQuery( '.frm-selected-field-group > li.form-field' ) | |
| 4514 | - .each( | |
| 4515 | - function() { | |
| 4516 | - deleteFieldIds.push( this.dataset.fid ); | |
| 4517 | - } | |
| 4518 | - ); | |
| 4519 | - return deleteFieldIds; | |
| 4520 | - } | |
| 4521 | - | |
| 4522 | - function getDeleteSelectedFieldGroupsOnConfirmFunction( deleteFieldIds ) { | |
| 4523 | - return function( event ) { | |
| 4524 | - event.preventDefault(); | |
| 4525 | - deleteAllSelectedFieldGroups( deleteFieldIds ); | |
| 4526 | - }; | |
| 4527 | - } | |
| 4528 | - | |
| 4529 | - function deleteAllSelectedFieldGroups( deleteFieldIds ) { | |
| 4530 | - deleteFieldIds.forEach( | |
| 4531 | - function( fieldId ) { | |
| 4532 | - deleteFields( fieldId ); | |
| 4533 | - } | |
| 4534 | - ); | |
| 4535 | - } | |
| 4536 | - | |
| 4537 | - function deleteFieldConfirmed() { | |
| 4538 | - /*jshint validthis:true */ | |
| 4539 | - deleteFields( this.getAttribute( 'data-deletefield' ) ); | |
| 4540 | - } | |
| 4541 | - | |
| 4542 | - function deleteFields( fieldId ) { | |
| 4543 | - var field = jQuery( '#frm_field_id_' + fieldId ); | |
| 4544 | - | |
| 4545 | - deleteField( fieldId ); | |
| 4546 | - | |
| 4547 | - if ( field.hasClass( 'edit_field_type_divider' ) ) { | |
| 4548 | - field.find( 'li.frm_field_box' ).each( function() { | |
| 4549 | - //TODO: maybe delete only end section | |
| 4550 | - //if(n.hasClass('edit_field_type_end_divider')){ | |
| 4551 | - deleteField( this.getAttribute( 'data-fid' ) ); | |
| 4552 | - //} | |
| 4553 | - }); | |
| 4554 | - } | |
| 4555 | - toggleSectionHolder(); | |
| 4556 | - } | |
| 4557 | - | |
| 4558 | - function deleteField( fieldId ) { | |
| 4559 | - jQuery.ajax({ | |
| 4560 | - type: 'POST', | |
| 4561 | - url: ajaxurl, | |
| 4562 | - data: { | |
| 4563 | - action: 'frm_delete_field', | |
| 4564 | - field_id: fieldId, | |
| 4565 | - nonce: frmGlobal.nonce | |
| 4566 | - }, | |
| 4567 | - success: function() { | |
| 4568 | - var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ), | |
| 4569 | - settings = jQuery( '#frm-single-settings-' + fieldId ); | |
| 4570 | - | |
| 4571 | - // Remove settings from sidebar. | |
| 4572 | - if ( settings.is( ':visible' ) ) { | |
| 4573 | - document.getElementById( 'frm_insert_fields_tab' ).click(); | |
| 4574 | - } | |
| 4575 | - settings.remove(); | |
| 4576 | - | |
| 4577 | - $thisField.fadeOut( 'slow', function() { | |
| 4578 | - var $section = $thisField.closest( '.start_divider' ), | |
| 4579 | - type = $thisField.data( 'type' ), | |
| 4580 | - $adjacentFields = $thisField.siblings( 'li.form-field' ), | |
| 4581 | - $liWrapper; | |
| 4582 | - | |
| 4583 | - if ( ! $adjacentFields.length ) { | |
| 4584 | - if ( $thisField.is( '.edit_field_type_end_divider' ) ) { | |
| 4585 | - $adjacentFields.length = $thisField.closest( 'li.form-field' ).siblings(); | |
| 4586 | - } else { | |
| 4587 | - $liWrapper = $thisField.closest( 'ul.frm_sorting' ).parent(); | |
| 4588 | - } | |
| 4589 | - } | |
| 4590 | - | |
| 4591 | - $thisField.remove(); | |
| 4592 | - if ( type === 'break' ) { | |
| 4593 | - renumberPageBreaks(); | |
| 4594 | - } | |
| 4595 | - if ( type === 'product' ) { | |
| 4596 | - maybeHideQuantityProductFieldOption(); | |
| 4597 | - // a product field attached to a quantity field earlier might be the one deleted, so re-populate | |
| 4598 | - popAllProductFields(); | |
| 4599 | - } | |
| 4600 | - if ( jQuery( '#frm-show-fields li' ).length === 0 ) { | |
| 4601 | - document.getElementById( 'frm_form_editor_container' ).classList.remove( 'frm-has-fields' ); | |
| 4602 | - } else if ( $section.length ) { | |
| 4603 | - toggleOneSectionHolder( $section ); | |
| 4604 | - } | |
| 4605 | - if ( $adjacentFields.length ) { | |
| 4606 | - syncLayoutClasses( $adjacentFields.first() ); | |
| 4607 | - } else { | |
| 4608 | - $liWrapper.remove(); | |
| 4609 | - } | |
| 4610 | - | |
| 4611 | - // prevent "More Options" tooltips from staying around after their target field is deleted. | |
| 4612 | - deleteTooltips(); | |
| 4613 | - }); | |
| 4614 | - } | |
| 4615 | - }); | |
| 4616 | - } | |
| 4617 | - | |
| 4618 | - function addFieldLogicRow() { | |
| 4619 | - /*jshint validthis:true */ | |
| 4620 | - var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 4621 | - formId = thisFormId, | |
| 4622 | - logicRows = document.getElementById( 'frm_logic_row_' + id ).querySelectorAll( '.frm_logic_row' ); | |
| 4623 | - jQuery.ajax({ | |
| 4624 | - type: 'POST', | |
| 4625 | - url: ajaxurl, | |
| 4626 | - data: { | |
| 4627 | - action: 'frm_add_logic_row', | |
| 4628 | - form_id: formId, | |
| 4629 | - field_id: id, | |
| 4630 | - nonce: frmGlobal.nonce, | |
| 4631 | - meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ), | |
| 4632 | - fields: getFieldList() | |
| 4633 | - }, | |
| 4634 | - success: function( html ) { | |
| 4635 | - jQuery( document.getElementById( 'logic_' + id ) ).fadeOut( 'slow', function() { | |
| 4636 | - var logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) ); | |
| 4637 | - logicRow.append( html ); | |
| 4638 | - logicRow.closest( '.frm_logic_rows' ).fadeIn( 'slow' ); | |
| 4639 | - }); | |
| 4640 | - } | |
| 4641 | - }); | |
| 4642 | - return false; | |
| 4643 | - } | |
| 4644 | - | |
| 4645 | - function getNewRowId( rows, replace, defaultValue ) { | |
| 4646 | - if ( ! rows.length ) { | |
| 4647 | - return 'undefined' !== typeof defaultValue ? defaultValue : 0; | |
| 4648 | - } | |
| 4649 | - return parseInt( rows[ rows.length - 1 ].id.replace( replace, '' ), 10 ) + 1; | |
| 4650 | - } | |
| 4651 | - | |
| 4652 | - function addWatchLookupRow() { | |
| 4653 | - /*jshint validthis:true */ | |
| 4654 | - var lastRowId, | |
| 4655 | - id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 4656 | - formId = thisFormId, | |
| 4657 | - lookupBlockRows = document.getElementById( 'frm_watch_lookup_block_' + id ).children; | |
| 4658 | - jQuery.ajax({ | |
| 4659 | - type: 'POST', | |
| 4660 | - url: ajaxurl, | |
| 4661 | - data: { | |
| 4662 | - action: 'frm_add_watch_lookup_row', | |
| 4663 | - form_id: formId, | |
| 4664 | - field_id: id, | |
| 4665 | - row_key: getNewRowId( lookupBlockRows, 'frm_watch_lookup_' + id + '_' ), | |
| 4666 | - nonce: frmGlobal.nonce | |
| 4667 | - }, | |
| 4668 | - success: function( newRow ) { | |
| 4669 | - var watchRowBlock = jQuery( document.getElementById( 'frm_watch_lookup_block_' + id ) ); | |
| 4670 | - watchRowBlock.append( newRow ); | |
| 4671 | - watchRowBlock.fadeIn( 'slow' ); | |
| 4672 | - } | |
| 4673 | - }); | |
| 4674 | - return false; | |
| 4675 | - } | |
| 4676 | - | |
| 4677 | - function resetOptionTextDetails() { | |
| 4678 | - jQuery( '.frm-single-settings ul input[type="text"][name^="field_options[options_"]' ).filter( '[data-value-on-load]' ).removeAttr( 'data-value-on-load' ); | |
| 4679 | - jQuery( 'input[type="hidden"][name^=optionmap]' ).remove(); | |
| 4680 | - } | |
| 4681 | - | |
| 4682 | - function optionTextAlreadyExists( input ) { | |
| 4683 | - var fieldId = jQuery( input ).closest( '.frm-single-settings' ).attr( 'data-fid' ), | |
| 4684 | - optionInputs = jQuery( input ).closest( 'ul' ).get( 0 ).querySelectorAll( '.field_' + fieldId + '_option' ), | |
| 4685 | - index, | |
| 4686 | - optionInput; | |
| 4687 | - | |
| 4688 | - for ( index in optionInputs ) { | |
| 4689 | - optionInput = optionInputs[ index ]; | |
| 4690 | - if ( optionInput.id !== input.id && optionInput.value === input.value && optionInput.getAttribute( 'data-duplicate' ) !== 'true' ) { | |
| 4691 | - return true; | |
| 4692 | - } | |
| 4693 | - } | |
| 4694 | - | |
| 4695 | - return false; | |
| 4696 | - } | |
| 4697 | - | |
| 4698 | - function onOptionTextFocus() { | |
| 4699 | - var input, | |
| 4700 | - fieldId; | |
| 4701 | - | |
| 4702 | - if ( this.getAttribute( 'data-value-on-load' ) === null ) { | |
| 4703 | - this.setAttribute( 'data-value-on-load', this.value ); | |
| 4704 | - | |
| 4705 | - fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' ); | |
| 4706 | - input = document.createElement( 'input' ); | |
| 4707 | - input.value = this.value; | |
| 4708 | - input.setAttribute( 'type', 'hidden' ); | |
| 4709 | - input.setAttribute( 'name', 'optionmap[' + fieldId + '][' + this.value + ']' ); | |
| 4710 | - this.parentNode.appendChild( input ); | |
| 4711 | - | |
| 4712 | - if ( typeof optionMap[ fieldId ] === 'undefined' ) { | |
| 4713 | - optionMap[ fieldId ] = {}; | |
| 4714 | - } | |
| 4715 | - | |
| 4716 | - optionMap[ fieldId ][ this.value ] = input; | |
| 4717 | - } | |
| 4718 | - | |
| 4719 | - if ( this.getAttribute( 'data-duplicate' ) === 'true' ) { | |
| 4720 | - this.removeAttribute( 'data-duplicate' ); | |
| 4721 | - | |
| 4722 | - // we want to use original value if actually still a duplicate | |
| 4723 | - if ( optionTextAlreadyExists( this ) ) { | |
| 4724 | - this.setAttribute( 'data-value-on-focus', this.getAttribute( 'data-value-on-load' ) ); | |
| 4725 | - return; | |
| 4726 | - } | |
| 4727 | - } | |
| 4728 | - | |
| 4729 | - if ( '' !== this.value || frm_admin_js.new_option !== this.getAttribute( 'data-value-on-focus' ) ) { // eslint-disable-line camelcase | |
| 4730 | - this.setAttribute( 'data-value-on-focus', this.value ); | |
| 4731 | - } | |
| 4732 | - } | |
| 4733 | - | |
| 4734 | - function onOptionTextBlur() { | |
| 4735 | - var originalValue, | |
| 4736 | - oldValue = this.getAttribute( 'data-value-on-focus' ), | |
| 4737 | - newValue = this.value, | |
| 4738 | - fieldId, | |
| 4739 | - fieldIndex, | |
| 4740 | - logicId, | |
| 4741 | - row, | |
| 4742 | - rowLength, | |
| 4743 | - rowIndex, | |
| 4744 | - valueSelect, | |
| 4745 | - opts, | |
| 4746 | - fieldIds, | |
| 4747 | - settingId, | |
| 4748 | - setting, | |
| 4749 | - optionMatches, | |
| 4750 | - option; | |
| 4751 | - | |
| 4752 | - if ( oldValue === newValue ) { | |
| 4753 | - return; | |
| 4754 | - } | |
| 4755 | - | |
| 4756 | - fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' ); | |
| 4757 | - originalValue = this.getAttribute( 'data-value-on-load' ); | |
| 4758 | - | |
| 4759 | - // check if the newValue is already mapped to another option | |
| 4760 | - // if it is, mark as duplicate and return | |
| 4761 | - if ( optionTextAlreadyExists( this ) ) { | |
| 4762 | - this.setAttribute( 'data-duplicate', 'true' ); | |
| 4763 | - | |
| 4764 | - if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) { | |
| 4765 | - // unmap any other change that may have happened before instead of changing it to something unused | |
| 4766 | - optionMap[ fieldId ][ originalValue ].value = originalValue; | |
| 4767 | - } | |
| 4768 | - | |
| 4769 | - return; | |
| 4770 | - } | |
| 4771 | - | |
| 4772 | - if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) { | |
| 4773 | - optionMap[ fieldId ][ originalValue ].value = newValue; | |
| 4774 | - } | |
| 4775 | - | |
| 4776 | - fieldIds = []; | |
| 4777 | - rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ); | |
| 4778 | - rowLength = rows.length; | |
| 4779 | - for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) { | |
| 4780 | - row = rows[ rowIndex ]; | |
| 4781 | - opts = row.querySelector( '.frm_logic_field_opts' ); | |
| 4782 | - | |
| 4783 | - if ( opts.value !== fieldId ) { | |
| 4784 | - continue; | |
| 4785 | - } | |
| 4786 | - | |
| 4787 | - logicId = row.id.split( '_' )[ 2 ]; | |
| 4788 | - valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' ); | |
| 4789 | - | |
| 4790 | - if ( '' === oldValue ) { | |
| 4791 | - optionMatches = []; | |
| 4792 | - } else { | |
| 4793 | - optionMatches = valueSelect.querySelectorAll( 'option[value="' + oldValue + '"]' ); | |
| 4794 | - } | |
| 4795 | - | |
| 4796 | - if ( ! optionMatches.length ) { | |
| 4797 | - optionMatches = valueSelect.querySelectorAll( 'option[value="' + newValue + '"]' ); | |
| 4798 | - | |
| 4799 | - if ( ! optionMatches.length ) { | |
| 4800 | - option = document.createElement( 'option' ); | |
| 4801 | - valueSelect.appendChild( option ); | |
| 4802 | - } | |
| 4803 | - } | |
| 4804 | - | |
| 4805 | - if ( optionMatches.length ) { | |
| 4806 | - option = optionMatches[ optionMatches.length - 1 ]; | |
| 4807 | - } | |
| 4808 | - | |
| 4809 | - option.setAttribute( 'value', newValue ); | |
| 4810 | - option.textContent = newValue; | |
| 4811 | - | |
| 4812 | - if ( fieldIds.indexOf( logicId ) === -1 ) { | |
| 4813 | - fieldIds.push( logicId ); | |
| 4814 | - } | |
| 4815 | - } | |
| 4816 | - | |
| 4817 | - for ( fieldIndex in fieldIds ) { | |
| 4818 | - settingId = fieldIds[ fieldIndex ]; | |
| 4819 | - setting = document.getElementById( 'frm-single-settings-' + settingId ); | |
| 4820 | - moveFieldSettings( setting ); | |
| 4821 | - } | |
| 4822 | - } | |
| 4823 | - | |
| 4824 | - function updateGetValueFieldSelection() { | |
| 4825 | - /*jshint validthis:true */ | |
| 4826 | - var fieldID = this.id.replace( 'get_values_form_', '' ); | |
| 4827 | - var fieldSelect = document.getElementById( 'get_values_field_' + fieldID ); | |
| 4828 | - var fieldType = this.getAttribute( 'data-fieldtype' ); | |
| 4829 | - | |
| 4830 | - if ( this.value === '' ) { | |
| 4831 | - fieldSelect.options.length = 1; | |
| 4832 | - } else { | |
| 4833 | - var formID = this.value; | |
| 4834 | - jQuery.ajax({ | |
| 4835 | - type: 'POST', url: ajaxurl, | |
| 4836 | - data: { | |
| 4837 | - action: 'frm_get_options_for_get_values_field', | |
| 4838 | - form_id: formID, | |
| 4839 | - field_type: fieldType, | |
| 4840 | - nonce: frmGlobal.nonce | |
| 4841 | - }, | |
| 4842 | - success: function( fields ) { | |
| 4843 | - fieldSelect.innerHTML = fields; | |
| 4844 | - } | |
| 4845 | - }); | |
| 4846 | - } | |
| 4847 | - } | |
| 4848 | - | |
| 4849 | - // Clear the Watch Fields option when Lookup field switches to "Text" option | |
| 4850 | - function maybeClearWatchFields() { | |
| 4851 | - /*jshint validthis:true */ | |
| 4852 | - var link, lookupBlock, | |
| 4853 | - fieldID = this.name.replace( 'field_options[data_type_', '' ).replace( ']', '' ); | |
| 4854 | - | |
| 4855 | - link = document.getElementById( 'frm_add_watch_lookup_link_' + fieldID ).parentNode; | |
| 4856 | - | |
| 4857 | - if ( this.value === 'text' ) { | |
| 4858 | - lookupBlock = document.getElementById( 'frm_watch_lookup_block_' + fieldID ); | |
| 4859 | - if ( lookupBlock !== null ) { | |
| 4860 | - // Clear and hide the Watch Fields option | |
| 4861 | - lookupBlock.innerHTML = ''; | |
| 4862 | - link.classList.add( 'frm_hidden' ); | |
| 4863 | - | |
| 4864 | - // Hide the Watch Fields row | |
| 4865 | - link.previousElementSibling.style.display = 'none'; | |
| 4866 | - link.previousElementSibling.previousElementSibling.style.display = 'none'; | |
| 4867 | - link.previousElementSibling.previousElementSibling.previousElementSibling.style.display = 'none'; | |
| 4868 | - } | |
| 4869 | - } else { | |
| 4870 | - // Show the Watch Fields option | |
| 4871 | - link.classList.remove( 'frm_hidden' ); | |
| 4872 | - } | |
| 4873 | - | |
| 4874 | - toggleMultiSelect( fieldID, this.value ); | |
| 4875 | - } | |
| 4876 | - | |
| 4877 | - // Number the pages and hide/show the first page as needed. | |
| 4878 | - function renumberPageBreaks() { | |
| 4879 | - var i, containerClass, | |
| 4880 | - pages = document.getElementsByClassName( 'frm-page-num' ); | |
| 4881 | - | |
| 4882 | - if ( pages.length > 1 ) { | |
| 4883 | - document.getElementById( 'frm-fake-page' ).style.display = 'block'; | |
| 4884 | - for ( i = 0; i < pages.length; i++ ) { | |
| 4885 | - containerClass = pages[i].parentNode.parentNode.parentNode.classList; | |
| 4886 | - if ( i === 1 ) { | |
| 4887 | - // Hide previous button on page 1 | |
| 4888 | - containerClass.add( 'frm-first-page' ); | |
| 4889 | - } else { | |
| 4890 | - containerClass.remove( 'frm-first-page' ); | |
| 4891 | - } | |
| 4892 | - pages[i].textContent = ( i + 1 ); | |
| 4893 | - } | |
| 4894 | - } else { | |
| 4895 | - document.getElementById( 'frm-fake-page' ).style.display = 'none'; | |
| 4896 | - } | |
| 4897 | - } | |
| 4898 | - | |
| 4899 | - // The fake field works differently than real fields. | |
| 4900 | - function maybeCollapsePage() { | |
| 4901 | - /*jshint validthis:true */ | |
| 4902 | - var field = jQuery( this ).closest( '.frm_field_box[data-ftype=break]' ); | |
| 4903 | - if ( field.length ) { | |
| 4904 | - toggleCollapsePage( field ); | |
| 4905 | - } else { | |
| 4906 | - toggleCollapseFakePage(); | |
| 4907 | - } | |
| 4908 | - } | |
| 4909 | - | |
| 4910 | - // Find all fields in a page and hide/show them | |
| 4911 | - function toggleCollapsePage( field ) { | |
| 4912 | - var toCollapse = getAllFieldsForPage( field.get( 0 ).parentNode.closest( 'li.frm_field_box' ).nextElementSibling ); | |
| 4913 | - togglePage( field, toCollapse ); | |
| 4914 | - } | |
| 4915 | - | |
| 4916 | - function toggleCollapseFakePage() { | |
| 4917 | - var topLevel = document.getElementById( 'frm-fake-page' ), | |
| 4918 | - firstField = document.getElementById( 'frm-show-fields' ).firstElementChild, | |
| 4919 | - toCollapse = getAllFieldsForPage( firstField ); | |
| 4920 | - | |
| 4921 | - if ( firstField.getAttribute( 'data-ftype' ) === 'break' ) { | |
| 4922 | - // Don't collapse if the first field is a page break. | |
| 4923 | - return; | |
| 4924 | - } | |
| 4925 | - | |
| 4926 | - togglePage( jQuery( topLevel ), toCollapse ); | |
| 4927 | - } | |
| 4928 | - | |
| 4929 | - function getAllFieldsForPage( firstWrapper ) { | |
| 4930 | - var $fieldsForPage, currentWrapper; | |
| 4931 | - | |
| 4932 | - $fieldsForPage = jQuery(); | |
| 4933 | - | |
| 4934 | - if ( null === firstWrapper ) { | |
| 4935 | - return $fieldsForPage; | |
| 4936 | - } | |
| 4937 | - | |
| 4938 | - currentWrapper = firstWrapper; | |
| 4939 | - | |
| 4940 | - do { | |
| 4941 | - if ( null !== currentWrapper.querySelector( '.edit_field_type_break' ) ) { | |
| 4942 | - break; | |
| 4943 | - } | |
| 4944 | - $fieldsForPage = $fieldsForPage.add( jQuery( currentWrapper ) ); | |
| 4945 | - currentWrapper = currentWrapper.nextElementSibling; | |
| 4946 | - } while ( null !== currentWrapper ); | |
| 4947 | - | |
| 4948 | - return $fieldsForPage; | |
| 4949 | - } | |
| 4950 | - | |
| 4951 | - function togglePage( field, toCollapse ) { | |
| 4952 | - var i, | |
| 4953 | - fieldCount = toCollapse.length, | |
| 4954 | - slide = Math.min( fieldCount, 3 ); | |
| 4955 | - | |
| 4956 | - if ( field.hasClass( 'frm-page-collapsed' ) ) { | |
| 4957 | - field.removeClass( 'frm-page-collapsed' ); | |
| 4958 | - toCollapse.removeClass( 'frm-is-collapsed' ); | |
| 4959 | - for ( i = 0; i < slide; i++ ) { | |
| 4960 | - if ( i === slide - 1 ) { | |
| 4961 | - jQuery( toCollapse[ i ]).slideDown( 150, function() { | |
| 4962 | - toCollapse.show(); | |
| 4963 | - }); | |
| 4964 | - } else { | |
| 4965 | - jQuery( toCollapse[ i ]).slideDown( 150 ); | |
| 4966 | - } | |
| 4967 | - } | |
| 4968 | - } else { | |
| 4969 | - field.addClass( 'frm-page-collapsed' ); | |
| 4970 | - toCollapse.addClass( 'frm-is-collapsed' ); | |
| 4971 | - for ( i = 0; i < slide; i++ ) { | |
| 4972 | - if ( i === slide - 1 ) { | |
| 4973 | - jQuery( toCollapse[ i ]).slideUp( 150, function() { | |
| 4974 | - toCollapse.css( 'cssText', 'display:none !important;' ); | |
| 4975 | - }); | |
| 4976 | - } else { | |
| 4977 | - jQuery( toCollapse[ i ]).slideUp( 150 ); | |
| 4978 | - } | |
| 4979 | - } | |
| 4980 | - } | |
| 4981 | - } | |
| 4982 | - | |
| 4983 | - function maybeCollapseSection() { | |
| 4984 | - /*jshint validthis:true */ | |
| 4985 | - var parentCont = this.parentNode.parentNode.parentNode.parentNode; | |
| 4986 | - | |
| 4987 | - parentCont.classList.toggle( 'frm-section-collapsed' ); | |
| 4988 | - } | |
| 4989 | - | |
| 4990 | - function maybeCollapseSettings() { | |
| 4991 | - /*jshint validthis:true */ | |
| 4992 | - this.classList.toggle( 'frm-collapsed' ); | |
| 4993 | - } | |
| 4994 | - | |
| 4995 | - function clickLabel() { | |
| 4996 | - if ( ! this.id ) { | |
| 4997 | - return; | |
| 4998 | - } | |
| 4999 | - | |
| 5000 | - /*jshint validthis:true */ | |
| 5001 | - var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0], | |
| 5002 | - fieldId = this.id.replace( 'field_label_', '' ), | |
| 5003 | - fieldType = document.getElementById( 'field_options_type_' + fieldId ), | |
| 5004 | - fieldTypeName = fieldType.value; | |
| 5005 | - | |
| 5006 | - if ( typeof setting !== 'undefined' ) { | |
| 5007 | - if ( fieldType.tagName === 'SELECT' ) { | |
| 5008 | - fieldTypeName = fieldType.options[ fieldType.selectedIndex ].text.toLowerCase(); | |
| 5009 | - } else { | |
| 5010 | - fieldTypeName = fieldTypeName.replace( '_', ' ' ); | |
| 5011 | - } | |
| 5012 | - | |
| 5013 | - fieldTypeName = normalizeFieldName( fieldTypeName ); | |
| 5014 | - | |
| 5015 | - setTimeout( function() { | |
| 5016 | - if ( setting.value.toLowerCase() === fieldTypeName ) { | |
| 5017 | - setting.select(); | |
| 5018 | - } else { | |
| 5019 | - setting.focus(); | |
| 5020 | - } | |
| 5021 | - }, 50 ); | |
| 5022 | - } | |
| 5023 | - } | |
| 5024 | - | |
| 5025 | - function clickDescription() { | |
| 5026 | - /*jshint validthis:true */ | |
| 5027 | - var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0]; | |
| 5028 | - if ( typeof setting !== 'undefined' ) { | |
| 5029 | - setTimeout( function() { | |
| 5030 | - setting.focus(); | |
| 5031 | - autoExpandSettings( setting ); | |
| 5032 | - }, 50 ); | |
| 5033 | - } | |
| 5034 | - } | |
| 5035 | - | |
| 5036 | - function autoExpandSettings( setting ) { | |
| 5037 | - var inSection = setting.closest( '.frm-collapse-me' ); | |
| 5038 | - if ( inSection !== null ) { | |
| 5039 | - inSection.previousElementSibling.classList.remove( 'frm-collapsed' ); | |
| 5040 | - } | |
| 5041 | - } | |
| 5042 | - | |
| 5043 | - function normalizeFieldName( fieldTypeName ) { | |
| 5044 | - if ( fieldTypeName === 'divider' ) { | |
| 5045 | - fieldTypeName = 'section'; | |
| 5046 | - } else if ( fieldTypeName === 'range' ) { | |
| 5047 | - fieldTypeName = 'slider'; | |
| 5048 | - } else if ( fieldTypeName === 'data' ) { | |
| 5049 | - fieldTypeName = 'dynamic'; | |
| 5050 | - } else if ( fieldTypeName === 'form' ) { | |
| 5051 | - fieldTypeName = 'embed form'; | |
| 5052 | - } | |
| 5053 | - return fieldTypeName; | |
| 5054 | - } | |
| 5055 | - | |
| 5056 | - function clickVis( e ) { | |
| 5057 | - /*jshint validthis:true */ | |
| 5058 | - var currentClass, originalList; | |
| 5059 | - | |
| 5060 | - currentClass = e.target.classList; | |
| 5061 | - | |
| 5062 | - if ( currentClass.contains( 'frm-collapse-page' ) || currentClass.contains( 'frm-sub-label' ) || e.target.closest( '.dropdown' ) !== null ) { | |
| 5063 | - return; | |
| 5064 | - } | |
| 5065 | - | |
| 5066 | - if ( this.closest( '.start_divider' ) !== null ) { | |
| 5067 | - e.stopPropagation(); | |
| 5068 | - } | |
| 5069 | - | |
| 5070 | - if ( this.classList.contains( 'edit_field_type_divider' ) ) { | |
| 5071 | - originalList = e.originalEvent.target.closest( 'ul.frm_sorting' ); | |
| 5072 | - if ( null !== originalList ) { | |
| 5073 | - // prevent section click if clicking a field group within a section. | |
| 5074 | - if ( originalList.classList.contains( 'edit_field_type_divider' ) || originalList.parentNode.parentNode.classList.contains( 'start_divider' ) ) { | |
| 5075 | - return; | |
| 5076 | - } | |
| 5077 | - } | |
| 5078 | - } | |
| 5079 | - | |
| 5080 | - clickAction( this ); | |
| 5081 | - } | |
| 5082 | - | |
| 5083 | - /** | |
| 5084 | - * Open Advanced settings on double click. | |
| 5085 | - */ | |
| 5086 | - function openAdvanced() { | |
| 5087 | - var fieldId = this.getAttribute( 'data-fid' ); | |
| 5088 | - autoExpandSettings( document.getElementById( 'field_options_field_key_' + fieldId ) ); | |
| 5089 | - } | |
| 5090 | - | |
| 5091 | - function toggleRepeatButtons() { | |
| 5092 | - /*jshint validthis:true */ | |
| 5093 | - var $thisField = jQuery( this ).closest( '.frm_field_box' ); | |
| 5094 | - $thisField.find( '.repeat_icon_links' ).removeClass( 'repeat_format repeat_formatboth repeat_formattext' ).addClass( 'repeat_format' + this.value ); | |
| 5095 | - if ( this.value === 'text' || this.value === 'both' ) { | |
| 5096 | - $thisField.find( '.frm_repeat_text' ).show(); | |
| 5097 | - $thisField.find( '.repeat_icon_links a' ).addClass( 'frm_button' ); | |
| 5098 | - } else { | |
| 5099 | - $thisField.find( '.frm_repeat_text' ).hide(); | |
| 5100 | - $thisField.find( '.repeat_icon_links a' ).removeClass( 'frm_button' ); | |
| 5101 | - } | |
| 5102 | - } | |
| 5103 | - | |
| 5104 | - function checkRepeatLimit() { | |
| 5105 | - /*jshint validthis:true */ | |
| 5106 | - var val = this.value; | |
| 5107 | - if ( val !== '' && ( val < 2 || val > 200 ) ) { | |
| 5108 | - infoModal( frm_admin_js.repeat_limit_min ); // eslint-disable-line camelcase | |
| 5109 | - this.value = ''; | |
| 5110 | - } | |
| 5111 | - } | |
| 5112 | - | |
| 5113 | - function checkCheckboxSelectionsLimit() { | |
| 5114 | - /*jshint validthis:true */ | |
| 5115 | - var val = this.value; | |
| 5116 | - if ( val !== '' && ( val < 1 || val > 200 ) ) { | |
| 5117 | - infoModal( frm_admin_js.checkbox_limit ); // eslint-disable-line camelcase | |
| 5118 | - this.value = ''; | |
| 5119 | - } | |
| 5120 | - } | |
| 5121 | - | |
| 5122 | - function updateRepeatText( obj, addRemove ) { | |
| 5123 | - var $thisField = jQuery( obj ).closest( '.frm_field_box' ); | |
| 5124 | - $thisField.find( '.frm_' + addRemove + '_form_row .frm_repeat_label' ).text( obj.value ); | |
| 5125 | - } | |
| 5126 | - | |
| 5127 | - function fieldsInSection( id ) { | |
| 5128 | - var children = []; | |
| 5129 | - jQuery( document.getElementById( 'frm_field_id_' + id ) ).find( 'li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)' ).each( function() { | |
| 5130 | - children.push( jQuery( this ).data( 'fid' ) ); | |
| 5131 | - }); | |
| 5132 | - return children; | |
| 5133 | - } | |
| 5134 | - | |
| 5135 | - function toggleFormTax() { | |
| 5136 | - /*jshint validthis:true */ | |
| 5137 | - var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 5138 | - var val = this.value; | |
| 5139 | - var $showFields = document.getElementById( 'frm_show_selected_fields_' + id ); | |
| 5140 | - var $showForms = document.getElementById( 'frm_show_selected_forms_' + id ); | |
| 5141 | - | |
| 5142 | - jQuery( $showForms ).find( 'select' ).val( '' ); | |
| 5143 | - if ( val === 'form' ) { | |
| 5144 | - $showForms.style.display = 'inline'; | |
| 5145 | - empty( $showFields ); | |
| 5146 | - } else { | |
| 5147 | - $showFields.style.display = 'none'; | |
| 5148 | - $showForms.style.display = 'none'; | |
| 5149 | - getTaxOrFieldSelection( val, id ); | |
| 5150 | - } | |
| 5151 | - | |
| 5152 | - } | |
| 5153 | - | |
| 5154 | - function resetOptOnChange() { | |
| 5155 | - /*jshint validthis:true */ | |
| 5156 | - var field, thisOpt; | |
| 5157 | - | |
| 5158 | - field = getFieldKeyFromOpt( this ); | |
| 5159 | - if ( ! field ) { | |
| 5160 | - return; | |
| 5161 | - } | |
| 5162 | - | |
| 5163 | - thisOpt = jQuery( this ).closest( '.frm_single_option' ); | |
| 5164 | - | |
| 5165 | - resetSingleOpt( field.fieldId, field.fieldKey, thisOpt ); | |
| 5166 | - } | |
| 5167 | - | |
| 5168 | - function getFieldKeyFromOpt( object ) { | |
| 5169 | - var allOpts, fieldId, fieldKey; | |
| 5170 | - | |
| 5171 | - allOpts = jQuery( object ).closest( '.frm_sortable_field_opts' ); | |
| 5172 | - if ( ! allOpts.length ) { | |
| 5173 | - return false; | |
| 5174 | - } | |
| 5175 | - | |
| 5176 | - fieldId = allOpts.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_opts', '' ); | |
| 5177 | - fieldKey = allOpts.data( 'key' ); | |
| 5178 | - | |
| 5179 | - return { | |
| 5180 | - fieldId: fieldId, | |
| 5181 | - fieldKey: fieldKey | |
| 5182 | - }; | |
| 5183 | - } | |
| 5184 | - | |
| 5185 | - function resetSingleOpt( fieldId, fieldKey, thisOpt ) { | |
| 5186 | - var saved, text, defaultVal, previewInput, labelForDisplay, optContainer, | |
| 5187 | - optKey = thisOpt.data( 'optkey' ), | |
| 5188 | - separateValues = usingSeparateValues( fieldId ), | |
| 5189 | - single = jQuery( 'label[for="field_' + fieldKey + '-' + optKey + '"]' ), | |
| 5190 | - baseName = 'field_options[options_' + fieldId + '][' + optKey + ']', | |
| 5191 | - label = jQuery( 'input[name="' + baseName + '[label]"]' ); | |
| 5192 | - | |
| 5193 | - if ( single.length < 1 ) { | |
| 5194 | - resetDisplayedOpts( fieldId ); | |
| 5195 | - | |
| 5196 | - // Set the default value. | |
| 5197 | - defaultVal = thisOpt.find( 'input[name^="default_value_"]' ); | |
| 5198 | - if ( defaultVal.is( ':checked' ) && label.length > 0 ) { | |
| 5199 | - jQuery( 'select[name^="item_meta[' + fieldId + ']"]' ).val( label.val() ); | |
| 5200 | - } | |
| 5201 | - return; | |
| 5202 | - } | |
| 5203 | - | |
| 5204 | - previewInput = single.children( 'input' ); | |
| 5205 | - | |
| 5206 | - if ( label.length < 1 ) { | |
| 5207 | - // Check for other label. | |
| 5208 | - label = jQuery( 'input[name="' + baseName + '"]' ); | |
| 5209 | - saved = label.val(); | |
| 5210 | - } else if ( separateValues ) { | |
| 5211 | - saved = jQuery( 'input[name="' + baseName + '[value]"]' ).val(); | |
| 5212 | - } else { | |
| 5213 | - saved = label.val(); | |
| 5214 | - } | |
| 5215 | - | |
| 5216 | - if ( label.length < 1 ) { | |
| 5217 | - return; | |
| 5218 | - } | |
| 5219 | - | |
| 5220 | - // Set the displayed value. | |
| 5221 | - text = single[0].childNodes; | |
| 5222 | - | |
| 5223 | - if ( imagesAsOptions( fieldId ) ) { | |
| 5224 | - labelForDisplay = getImageDisplayValue( thisOpt, fieldId, label ); | |
| 5225 | - optContainer = single.find( '.frm_image_option_container' ); | |
| 5226 | - | |
| 5227 | - if ( optContainer.length > 0 ) { | |
| 5228 | - optContainer.replaceWith( labelForDisplay ); | |
| 5229 | - } else { | |
| 5230 | - text[ text.length - 1 ].nodeValue = ''; | |
| 5231 | - single.append( labelForDisplay ); | |
| 5232 | - } | |
| 5233 | - } else { | |
| 5234 | - let firstInputIndex = false; | |
| 5235 | - text.forEach( ( node, index ) => { | |
| 5236 | - if ( firstInputIndex === false ) { | |
| 5237 | - if ( node.tagName === 'INPUT' ) { | |
| 5238 | - firstInputIndex = index; | |
| 5239 | - } | |
| 5240 | - } else { | |
| 5241 | - if ( index === firstInputIndex + 1 ) { | |
| 5242 | - let nodeValue = ''; | |
| 5243 | - | |
| 5244 | - if ( buttonsAsOptions( fieldId ) ) { | |
| 5245 | - nodeValue = div({ className: 'frm_label_button_container', text: ' ' + label.val() }); | |
| 5246 | - single[0].replaceChild( nodeValue, node ); | |
| 5247 | - } else { | |
| 5248 | - node.nodeValue = ' ' + label.val(); | |
| 5249 | - } | |
| 5250 | - } else { | |
| 5251 | - single[0].removeChild( node ); | |
| 5252 | - } | |
| 5253 | - } | |
| 5254 | - }); | |
| 5255 | - } | |
| 5256 | - | |
| 5257 | - // Set saved value. | |
| 5258 | - previewInput.val( saved ); | |
| 5259 | - | |
| 5260 | - // Set the default value. | |
| 5261 | - defaultVal = thisOpt.find( 'input[name^="default_value_"]' ); | |
| 5262 | - previewInput.prop( 'checked', defaultVal.is( ':checked' ) ? true : false ); | |
| 5263 | - } | |
| 5264 | - | |
| 5265 | - function buttonsAsOptions( fieldId ) { | |
| 5266 | - const fields = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' ); | |
| 5267 | - const result = Array.from( fields ).find( field => field.checked && ( 'buttons' === field.value ) ); | |
| 5268 | - | |
| 5269 | - return typeof result !== 'undefined'; | |
| 5270 | - } | |
| 5271 | - | |
| 5272 | - /** | |
| 5273 | - * Set the displayed value for an image option. | |
| 5274 | - */ | |
| 5275 | - function getImageDisplayValue( thisOpt, fieldId, label ) { | |
| 5276 | - var image, imageUrl, showLabelWithImage, fieldType; | |
| 5277 | - | |
| 5278 | - image = thisOpt.find( 'img' ); | |
| 5279 | - if ( image ) { | |
| 5280 | - imageUrl = image.attr( 'src' ); | |
| 5281 | - } | |
| 5282 | - | |
| 5283 | - showLabelWithImage = showingLabelWithImage( fieldId ); | |
| 5284 | - fieldType = radioOrCheckbox( fieldId ); | |
| 5285 | - return getImageLabel( label.val(), showLabelWithImage, imageUrl, fieldType ); | |
| 5286 | - } | |
| 5287 | - | |
| 5288 | - function getImageOptionSize( fieldId ) { | |
| 5289 | - var val, | |
| 5290 | - field = document.getElementById( 'field_options_image_size_' + fieldId ), | |
| 5291 | - size = ''; | |
| 5292 | - | |
| 5293 | - if ( field !== null ) { | |
| 5294 | - val = field.value; | |
| 5295 | - if ( val !== '' ) { | |
| 5296 | - size = val; | |
| 5297 | - } | |
| 5298 | - } | |
| 5299 | - | |
| 5300 | - return size; | |
| 5301 | - } | |
| 5302 | - | |
| 5303 | - function resetDisplayedOpts( fieldId ) { | |
| 5304 | - var i, opts, type, placeholder, fieldInfo, | |
| 5305 | - input = jQuery( '[name^="item_meta[' + fieldId + ']"]' ); | |
| 5306 | - | |
| 5307 | - if ( input.length < 1 ) { | |
| 5308 | - return; | |
| 5309 | - } | |
| 5310 | - | |
| 5311 | - if ( input.is( 'select' ) ) { | |
| 5312 | - placeholder = document.getElementById( 'frm_placeholder_' + fieldId ); | |
| 5313 | - if ( placeholder !== null && placeholder.value === '' ) { | |
| 5314 | - fillDropdownOpts( input[0], { sourceID: fieldId }); | |
| 5315 | - } else { | |
| 5316 | - fillDropdownOpts( input[0], { | |
| 5317 | - sourceID: fieldId, | |
| 5318 | - placeholder: placeholder.value | |
| 5319 | - }); | |
| 5320 | - } | |
| 5321 | - } else { | |
| 5322 | - opts = getMultipleOpts( fieldId ); | |
| 5323 | - type = input.attr( 'type' ); | |
| 5324 | - jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ).html( '' ); | |
| 5325 | - fieldInfo = getFieldKeyFromOpt( jQuery( '#frm_delete_field_' + fieldId + '-000_container' ) ); | |
| 5326 | - | |
| 5327 | - var container = jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ), | |
| 5328 | - hasImageOptions = imagesAsOptions( fieldId ), | |
| 5329 | - imageSize = hasImageOptions ? getImageOptionSize( fieldId ) : '', | |
| 5330 | - imageOptionClass = hasImageOptions ? ( 'frm_image_option frm_image_' + imageSize + ' ' ) : '', | |
| 5331 | - isProduct = isProductField( fieldId ); | |
| 5332 | - | |
| 5333 | - for ( i = 0; i < opts.length; i++ ) { | |
| 5334 | - container.append( addRadioCheckboxOpt( type, opts[ i ], fieldId, fieldInfo.fieldKey, isProduct, imageOptionClass ) ); | |
| 5335 | - } | |
| 5336 | - } | |
| 5337 | - | |
| 5338 | - adjustConditionalLogicOptionOrders( fieldId ); | |
| 5339 | - } | |
| 5340 | - | |
| 5341 | - function adjustConditionalLogicOptionOrders( fieldId ) { | |
| 5342 | - var row, opts, logicId, valueSelect, rowOptions, expectedOrder, optionLength, optionIndex, expectedOption, optionMatch, | |
| 5343 | - rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ), | |
| 5344 | - rowLength = rows.length, | |
| 5345 | - fieldOptions = getFieldOptions( fieldId ), | |
| 5346 | - optionLength = fieldOptions.length; | |
| 5347 | - | |
| 5348 | - for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) { | |
| 5349 | - row = rows[ rowIndex ]; | |
| 5350 | - opts = row.querySelector( '.frm_logic_field_opts' ); | |
| 5351 | - | |
| 5352 | - if ( opts.value != fieldId ) { | |
| 5353 | - continue; | |
| 5354 | - } | |
| 5355 | - | |
| 5356 | - logicId = row.id.split( '_' )[ 2 ]; | |
| 5357 | - valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' ); | |
| 5358 | - | |
| 5359 | - for ( optionIndex = optionLength - 1; optionIndex >= 0; optionIndex-- ) { | |
| 5360 | - expectedOption = fieldOptions[ optionIndex ]; | |
| 5361 | - optionMatch = valueSelect.querySelector( 'option[value="' + expectedOption + '"]' ); | |
| 5362 | - | |
| 5363 | - if ( optionMatch === null ) { | |
| 5364 | - optionMatch = document.createElement( 'option' ); | |
| 5365 | - optionMatch.setAttribute( 'value', expectedOption ); | |
| 5366 | - optionMatch.textContent = expectedOption; | |
| 5367 | - } | |
| 5368 | - | |
| 5369 | - valueSelect.prepend( optionMatch ); | |
| 5370 | - } | |
| 5371 | - | |
| 5372 | - optionMatch = valueSelect.querySelector( 'option[value=""]' ); | |
| 5373 | - if ( optionMatch !== null ) { | |
| 5374 | - valueSelect.prepend( optionMatch ); | |
| 5375 | - } | |
| 5376 | - } | |
| 5377 | - } | |
| 5378 | - | |
| 5379 | - function getFieldOptions( fieldId ) { | |
| 5380 | - var index, input, li, | |
| 5381 | - listItems = document.getElementById( 'frm_field_' + fieldId + '_opts' ).querySelectorAll( '.frm_single_option' ), | |
| 5382 | - options = [], | |
| 5383 | - length = listItems.length; | |
| 5384 | - for ( index = 0; index < length; index++ ) { | |
| 5385 | - li = listItems[ index ]; | |
| 5386 | - | |
| 5387 | - if ( li.classList.contains( 'frm_hidden' ) ) { | |
| 5388 | - continue; | |
| 5389 | - } | |
| 5390 | - | |
| 5391 | - input = li.querySelector( '.field_' + fieldId + '_option' ); | |
| 5392 | - options.push( input.value ); | |
| 5393 | - } | |
| 5394 | - return options; | |
| 5395 | - } | |
| 5396 | - | |
| 5397 | - function addRadioCheckboxOpt( type, opt, fieldId, fieldKey, isProduct, classes ) { | |
| 5398 | - var other, single, | |
| 5399 | - isOther = opt.key.indexOf( 'other' ) !== -1, | |
| 5400 | - | |
| 5401 | - id = 'field_' + fieldKey + '-' + opt.key; | |
| 5402 | - | |
| 5403 | - 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="" />'; | |
| 5404 | - | |
| 5405 | - single = '<div class="frm_' + type + ' ' + type + ' ' + classes + '" id="frm_' + type + '_' + fieldId + '-' + opt.key + '"><label for="' + id + | |
| 5406 | - '"><input type="' + type + | |
| 5407 | - '" name="item_meta[' + fieldId + ']' + ( type === 'checkbox' ? '[]' : '' ) + | |
| 5408 | - '" value="' + purifyHtml( opt.saved ) + '" id="' + id + '"' + ( isProduct ? ' data-price="' + opt.price + '"' : '' ) + ( opt.checked ? ' checked="checked"' : '' ) + '> ' + purifyHtml( opt.label ) + '</label>' + | |
| 5409 | - ( isOther ? other : '' ) + | |
| 5410 | - '</div>'; | |
| 5411 | - | |
| 5412 | - return single; | |
| 5413 | - } | |
| 5414 | - | |
| 5415 | - function fillDropdownOpts( field, atts ) { | |
| 5416 | - if ( field === null ) { | |
| 5417 | - return; | |
| 5418 | - } | |
| 5419 | - var sourceID = atts.sourceID, | |
| 5420 | - placeholder = atts.placeholder, | |
| 5421 | - isProduct = isProductField( sourceID ), | |
| 5422 | - showOther = atts.other; | |
| 5423 | - | |
| 5424 | - removeDropdownOpts( field ); | |
| 5425 | - var opts = getMultipleOpts( sourceID ), | |
| 5426 | - hasPlaceholder = ( typeof placeholder !== 'undefined' ); | |
| 5427 | - | |
| 5428 | - for ( var i = 0; i < opts.length; i++ ) { | |
| 5429 | - var label = opts[ i ].label, | |
| 5430 | - isOther = opts[ i ].key.indexOf( 'other' ) !== -1; | |
| 5431 | - | |
| 5432 | - if ( hasPlaceholder && label !== '' ) { | |
| 5433 | - addBlankSelectOption( field, placeholder ); | |
| 5434 | - } else if ( hasPlaceholder ) { | |
| 5435 | - label = placeholder; | |
| 5436 | - } | |
| 5437 | - hasPlaceholder = false; | |
| 5438 | - | |
| 5439 | - if ( ! isOther || showOther ) { | |
| 5440 | - var opt = document.createElement( 'option' ); | |
| 5441 | - opt.value = opts[ i ].saved; | |
| 5442 | - opt.innerHTML = purifyHtml( label ); | |
| 5443 | - | |
| 5444 | - if ( isProduct ) { | |
| 5445 | - opt.setAttribute( 'data-price', opts[ i ].price ); | |
| 5446 | - } | |
| 5447 | - | |
| 5448 | - field.appendChild( opt ); | |
| 5449 | - } | |
| 5450 | - } | |
| 5451 | - } | |
| 5452 | - | |
| 5453 | - function addBlankSelectOption( field, placeholder ) { | |
| 5454 | - var opt = document.createElement( 'option' ), | |
| 5455 | - firstChild = field.firstChild; | |
| 5456 | - | |
| 5457 | - opt.value = ''; | |
| 5458 | - opt.innerHTML = placeholder; | |
| 5459 | - if ( firstChild !== null ) { | |
| 5460 | - field.insertBefore( opt, firstChild ); | |
| 5461 | - field.selectedIndex = 0; | |
| 5462 | - } else { | |
| 5463 | - field.appendChild( opt ); | |
| 5464 | - } | |
| 5465 | - } | |
| 5466 | - | |
| 5467 | - function getMultipleOpts( fieldId ) { | |
| 5468 | - let i, saved, labelName, label, key, optObj, | |
| 5469 | - fieldType, | |
| 5470 | - checked = false, | |
| 5471 | - opts = [], | |
| 5472 | - imageUrl = ''; | |
| 5473 | - | |
| 5474 | - const optVals = jQuery( 'input[name^="field_options[options_' + fieldId + ']"]' ); | |
| 5475 | - const isProduct = isProductField( fieldId ); | |
| 5476 | - const showLabelWithImage = showingLabelWithImage( fieldId ); | |
| 5477 | - const hasImageOptions = imagesAsOptions( fieldId ); | |
| 5478 | - const separateValues = usingSeparateValues( fieldId ); | |
| 5479 | - | |
| 5480 | - for ( i = 0; i < optVals.length; i++ ) { | |
| 5481 | - 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 ) { | |
| 5482 | - continue; | |
| 5483 | - } | |
| 5484 | - | |
| 5485 | - saved = optVals[ i ].value; | |
| 5486 | - label = saved; | |
| 5487 | - key = optVals[ i ].name.replace( 'field_options[options_' + fieldId + '][', '' ).replace( '[label]', '' ).replace( ']', '' ); | |
| 5488 | - | |
| 5489 | - if ( separateValues ) { | |
| 5490 | - labelName = optVals[ i ].name.replace( '[label]', '[value]' ); | |
| 5491 | - saved = jQuery( 'input[name="' + labelName + '"]' ).val(); | |
| 5492 | - } | |
| 5493 | - | |
| 5494 | - if ( hasImageOptions ) { | |
| 5495 | - imageUrl = getImageUrlFromInput( optVals[i]); | |
| 5496 | - fieldType = radioOrCheckbox( fieldId ); | |
| 5497 | - label = getImageLabel( label, showLabelWithImage, imageUrl, fieldType ); | |
| 5498 | - } | |
| 5499 | - | |
| 5500 | - /** | |
| 5501 | - * @since 5.0.04 | |
| 5502 | - */ | |
| 5503 | - label = frmAdminBuild.hooks.applyFilters( 'frm_choice_field_label', label, fieldId, optVals[ i ], hasImageOptions ); | |
| 5504 | - | |
| 5505 | - checked = getChecked( optVals[ i ].id ); | |
| 5506 | - | |
| 5507 | - optObj = { | |
| 5508 | - saved: saved, | |
| 5509 | - label: label, | |
| 5510 | - checked: checked, | |
| 5511 | - key: key | |
| 5512 | - }; | |
| 5513 | - | |
| 5514 | - if ( isProduct ) { | |
| 5515 | - labelName = optVals[ i ].name.replace( '[label]', '[price]' ); | |
| 5516 | - optObj.price = jQuery( 'input[name="' + labelName + '"]' ).val(); | |
| 5517 | - } | |
| 5518 | - | |
| 5519 | - opts.push( optObj ); | |
| 5520 | - } | |
| 5521 | - | |
| 5522 | - return opts; | |
| 5523 | - } | |
| 5524 | - | |
| 5525 | - function radioOrCheckbox( fieldId ) { | |
| 5526 | - var settings = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 5527 | - if ( settings === null ) { | |
| 5528 | - return 'radio'; | |
| 5529 | - } | |
| 5530 | - | |
| 5531 | - return settings.classList.contains( 'frm-type-checkbox' ) ? 'checkbox' : 'radio'; | |
| 5532 | - } | |
| 5533 | - | |
| 5534 | - function getImageUrlFromInput( optVal ) { | |
| 5535 | - var img, | |
| 5536 | - wrapper = jQuery( optVal ).siblings( '.frm_image_preview_wrapper' ); | |
| 5537 | - | |
| 5538 | - if ( ! wrapper.length ) { | |
| 5539 | - return ''; | |
| 5540 | - } | |
| 5541 | - | |
| 5542 | - img = wrapper.find( 'img' ); | |
| 5543 | - if ( ! img.length ) { | |
| 5544 | - return ''; | |
| 5545 | - } | |
| 5546 | - | |
| 5547 | - return img.attr( 'src' ); | |
| 5548 | - } | |
| 5549 | - | |
| 5550 | - function purifyHtml( html ) { | |
| 5551 | - if ( html instanceof Element || html instanceof Document ) { | |
| 5552 | - html = html.outerHTML; | |
| 5553 | - } | |
| 5554 | - | |
| 5555 | - const clean = jQuery.parseHTML( html ).reduce( | |
| 5556 | - ( total, currentNode ) => { | |
| 5557 | - const cleanNode = frmDom.cleanNode( currentNode ); | |
| 5558 | - | |
| 5559 | - if ( '#text' === cleanNode.nodeName ) { | |
| 5560 | - return total += cleanNode.textContent; | |
| 5561 | - } | |
| 5562 | - | |
| 5563 | - return total + cleanNode.outerHTML; | |
| 5564 | - }, | |
| 5565 | - '' | |
| 5566 | - ); | |
| 5567 | - | |
| 5568 | - return clean; | |
| 5569 | - } | |
| 5570 | - | |
| 5571 | - function getImageLabel( label, showLabelWithImage, imageUrl, fieldType ) { | |
| 5572 | - var imageLabelClass, | |
| 5573 | - originalLabel = label, | |
| 5574 | - shape = fieldType === 'checkbox' ? 'square' : 'circle', | |
| 5575 | - labelImage, | |
| 5576 | - labelNode, | |
| 5577 | - imageLabel; | |
| 5578 | - | |
| 5579 | - originalLabel = purifyHtml( originalLabel ); | |
| 5580 | - | |
| 5581 | - if ( imageUrl ) { | |
| 5582 | - labelImage = img({ src: imageUrl, alt: originalLabel }); | |
| 5583 | - } else { | |
| 5584 | - labelImage = div({ className: 'frm_empty_url' }); | |
| 5585 | - labelImage.innerHTML = frm_admin_js.image_placeholder_icon; // eslint-disable-line camelcase | |
| 5586 | - } | |
| 5587 | - | |
| 5588 | - imageLabelClass = showLabelWithImage ? ' frm_label_with_image' : ''; | |
| 5589 | - | |
| 5590 | - imageLabel = tag( 'span', { className: 'frm_text_label_for_image_inner' }); | |
| 5591 | - | |
| 5592 | - imageLabel.innerHTML = originalLabel; | |
| 5593 | - labelNode = tag( | |
| 5594 | - 'span', | |
| 5595 | - { | |
| 5596 | - className: 'frm_image_option_container' + imageLabelClass, | |
| 5597 | - children: [ | |
| 5598 | - tag( 'div', { className: 'frm_selected_checkmark', child: svg({ href: '#frm_checkmark_' + shape + '_icon' }) }), | |
| 5599 | - labelImage, | |
| 5600 | - tag( 'span', { className: 'frm_text_label_for_image', child: imageLabel }) | |
| 5601 | - ] | |
| 5602 | - } | |
| 5603 | - ); | |
| 5604 | - | |
| 5605 | - return labelNode; | |
| 5606 | - } | |
| 5607 | - | |
| 5608 | - function getChecked( id ) { | |
| 5609 | - field = jQuery( '#' + id ); | |
| 5610 | - | |
| 5611 | - if ( field.length === 0 ) { | |
| 5612 | - return false; | |
| 5613 | - } | |
| 5614 | - | |
| 5615 | - checkbox = field.siblings( 'input[type=checkbox]' ); | |
| 5616 | - | |
| 5617 | - return checkbox.length && checkbox.prop( 'checked' ); | |
| 5618 | - } | |
| 5619 | - | |
| 5620 | - function removeDropdownOpts( field ) { | |
| 5621 | - var i; | |
| 5622 | - if ( typeof field.options === 'undefined' ) { | |
| 5623 | - return; | |
| 5624 | - } | |
| 5625 | - | |
| 5626 | - for ( i = field.options.length - 1; i >= 0; i-- ) { | |
| 5627 | - field.remove( i ); | |
| 5628 | - } | |
| 5629 | - } | |
| 5630 | - | |
| 5631 | - /** | |
| 5632 | - * Is the box checked to use separate values? | |
| 5633 | - */ | |
| 5634 | - function usingSeparateValues( fieldId ) { | |
| 5635 | - return isChecked( 'separate_value_' + fieldId ); | |
| 5636 | - } | |
| 5637 | - | |
| 5638 | - /** | |
| 5639 | - * Is the box checked to use images as options? | |
| 5640 | - */ | |
| 5641 | - function imagesAsOptions( fieldId ) { | |
| 5642 | - var checked = false, | |
| 5643 | - field = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' ); | |
| 5644 | - | |
| 5645 | - for ( var i = 0; i < field.length; i++ ) { | |
| 5646 | - if ( field[ i ].checked ) { | |
| 5647 | - checked = '0' !== field[ i ].value; | |
| 5648 | - } | |
| 5649 | - } | |
| 5650 | - | |
| 5651 | - /** | |
| 5652 | - * @since 5.0.04 | |
| 5653 | - */ | |
| 5654 | - return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_images_as_options', checked, fieldId ); | |
| 5655 | - } | |
| 5656 | - | |
| 5657 | - function showingLabelWithImage( fieldId ) { | |
| 5658 | - const isShowing = ! isChecked( 'hide_image_text_' + fieldId ); | |
| 5659 | - | |
| 5660 | - /** | |
| 5661 | - * @since 5.0.04 | |
| 5662 | - */ | |
| 5663 | - return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_showing_label_with_image', isShowing, fieldId ); | |
| 5664 | - } | |
| 5665 | - | |
| 5666 | - function isChecked( id ) { | |
| 5667 | - var field = document.getElementById( id ); | |
| 5668 | - if ( field === null ) { | |
| 5669 | - return false; | |
| 5670 | - } else { | |
| 5671 | - return field.checked; | |
| 5672 | - } | |
| 5673 | - } | |
| 5674 | - | |
| 5675 | - function checkUniqueOpt( targetInput ) { | |
| 5676 | - const settingsContainer = targetInput.closest( '.frm-single-settings' ); | |
| 5677 | - const fieldId = settingsContainer.getAttribute( 'data-fid' ); | |
| 5678 | - const areValuesSeparate = settingsContainer.querySelector( '[name="field_options[separate_value_' + fieldId + ']"]' ).checked; | |
| 5679 | - | |
| 5680 | - if ( areValuesSeparate && ! targetInput.name.endsWith( '[value]' ) ) { | |
| 5681 | - return; | |
| 5682 | - } | |
| 5683 | - | |
| 5684 | - const container = document.getElementById( 'frm_field_' + fieldId + '_opts' ); | |
| 5685 | - const conflicts = Array.from( container.querySelectorAll( 'input[type="text"]' ) ).filter( | |
| 5686 | - input => input.id !== targetInput.id && | |
| 5687 | - areValuesSeparate === input.name.endsWith( '[value]' ) && | |
| 5688 | - input.value === targetInput.value | |
| 5689 | - ); | |
| 5690 | - | |
| 5691 | - if ( conflicts.length ) { | |
| 5692 | - infoModal( __( 'Duplicate option value "%s" detected', 'formidable' ).replace( '%s', purifyHtml( targetInput.value ) ) ); | |
| 5693 | - } | |
| 5694 | - } | |
| 5695 | - | |
| 5696 | - function setStarValues() { | |
| 5697 | - /*jshint validthis:true */ | |
| 5698 | - var fieldID = this.id.replace( 'radio_maxnum_', '' ); | |
| 5699 | - var container = jQuery( '#field_' + fieldID + '_inner_container .frm-star-group' ); | |
| 5700 | - var fieldKey = document.getElementsByName( 'field_options[field_key_' + fieldID + ']' )[0].value; | |
| 5701 | - container.html( '' ); | |
| 5702 | - | |
| 5703 | - var min = 1; | |
| 5704 | - var max = this.value; | |
| 5705 | - if ( min > max ) { | |
| 5706 | - max = min; | |
| 5707 | - } | |
| 5708 | - | |
| 5709 | - for ( var i = min; i <= max; i++ ) { | |
| 5710 | - 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>' ); | |
| 5711 | - } | |
| 5712 | - } | |
| 5713 | - | |
| 5714 | - function getFieldValues() { | |
| 5715 | - /*jshint validthis:true */ | |
| 5716 | - var isTaxonomy, | |
| 5717 | - val = this.value; | |
| 5718 | - | |
| 5719 | - if ( val ) { | |
| 5720 | - var parentIDs = this.parentNode.id.replace( 'frm_logic_', '' ).split( '_' ); | |
| 5721 | - var fieldID = parentIDs[0]; | |
| 5722 | - var metaKey = parentIDs[1]; | |
| 5723 | - var valueField = document.getElementById( 'frm_field_id_' + val ); | |
| 5724 | - var valueFieldType = valueField.getAttribute( 'data-ftype' ); | |
| 5725 | - var fill = document.getElementById( 'frm_show_selected_values_' + fieldID + '_' + metaKey ); | |
| 5726 | - var optionName = 'field_options[hide_opt_' + fieldID + '][]'; | |
| 5727 | - var optionID = 'frm_field_logic_opt_' + fieldID; | |
| 5728 | - var input = false; | |
| 5729 | - var showSelect = ( valueFieldType === 'select' || valueFieldType === 'checkbox' || valueFieldType === 'radio' ); | |
| 5730 | - var showText = ( valueFieldType === 'text' || valueFieldType === 'email' || valueFieldType === 'phone' || valueFieldType === 'url' || valueFieldType === 'number' ); | |
| 5731 | - | |
| 5732 | - if ( showSelect ) { | |
| 5733 | - isTaxonomy = document.getElementById( 'frm_has_hidden_options_' + val ); | |
| 5734 | - if ( isTaxonomy !== null ) { | |
| 5735 | - // get the category options with ajax | |
| 5736 | - showSelect = false; | |
| 5737 | - } | |
| 5738 | - } | |
| 5739 | - | |
| 5740 | - if ( showSelect || showText ) { | |
| 5741 | - fill.innerHTML = ''; | |
| 5742 | - if ( showSelect ) { | |
| 5743 | - input = document.createElement( 'select' ); | |
| 5744 | - } else { | |
| 5745 | - input = document.createElement( 'input' ); | |
| 5746 | - input.type = 'text'; | |
| 5747 | - } | |
| 5748 | - input.name = optionName; | |
| 5749 | - input.id = optionID + '_' + metaKey; | |
| 5750 | - fill.appendChild( input ); | |
| 5751 | - | |
| 5752 | - if ( showSelect ) { | |
| 5753 | - var fillField = document.getElementById( input.id ); | |
| 5754 | - fillDropdownOpts( fillField, { | |
| 5755 | - sourceID: val, | |
| 5756 | - placeholder: '', | |
| 5757 | - other: true | |
| 5758 | - }); | |
| 5759 | - } | |
| 5760 | - } else { | |
| 5761 | - var thisType = this.getAttribute( 'data-type' ); | |
| 5762 | - frmGetFieldValues( val, fieldID, metaKey, thisType ); | |
| 5763 | - } | |
| 5764 | - } | |
| 5765 | - } | |
| 5766 | - | |
| 5767 | - function getFieldSelection() { | |
| 5768 | - /*jshint validthis:true */ | |
| 5769 | - var formId = this.value; | |
| 5770 | - if ( formId ) { | |
| 5771 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 5772 | - getTaxOrFieldSelection( formId, fieldId ); | |
| 5773 | - } | |
| 5774 | - } | |
| 5775 | - | |
| 5776 | - function getTaxOrFieldSelection( formId, fieldId ) { | |
| 5777 | - if ( formId ) { | |
| 5778 | - jQuery.ajax({ | |
| 5779 | - type: 'POST', | |
| 5780 | - url: ajaxurl, | |
| 5781 | - data: { | |
| 5782 | - action: 'frm_get_field_selection', | |
| 5783 | - field_id: fieldId, | |
| 5784 | - form_id: formId, | |
| 5785 | - nonce: frmGlobal.nonce | |
| 5786 | - }, | |
| 5787 | - success: function( msg ) { | |
| 5788 | - jQuery( '#frm_show_selected_fields_' + fieldId ).html( msg ).show(); | |
| 5789 | - } | |
| 5790 | - }); | |
| 5791 | - } | |
| 5792 | - } | |
| 5793 | - | |
| 5794 | - function updateFieldOrder() { | |
| 5795 | - var fields, fieldId, field, currentOrder, newOrder; | |
| 5796 | - renumberPageBreaks(); | |
| 5797 | - jQuery( '#frm-show-fields' ).each( function( i ) { | |
| 5798 | - fields = jQuery( 'li.frm_field_box', this ); | |
| 5799 | - for ( i = 0; i < fields.length; i++ ) { | |
| 5800 | - fieldId = fields[ i ].getAttribute( 'data-fid' ); | |
| 5801 | - field = jQuery( 'input[name="field_options[field_order_' + fieldId + ']"]' ); | |
| 5802 | - currentOrder = field.val(); | |
| 5803 | - newOrder = i + 1; | |
| 5804 | - | |
| 5805 | - if ( currentOrder != newOrder ) { | |
| 5806 | - field.val( newOrder ); | |
| 5807 | - singleField = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 5808 | - | |
| 5809 | - moveFieldSettings( singleField ); | |
| 5810 | - fieldUpdated(); | |
| 5811 | - } | |
| 5812 | - } | |
| 5813 | - }); | |
| 5814 | - } | |
| 5815 | - | |
| 5816 | - function toggleSectionHolder() { | |
| 5817 | - document.querySelectorAll( '.start_divider' ).forEach( | |
| 5818 | - function( divider ) { | |
| 5819 | - toggleOneSectionHolder( jQuery( divider ) ); | |
| 5820 | - } | |
| 5821 | - ); | |
| 5822 | - } | |
| 5823 | - | |
| 5824 | - function toggleOneSectionHolder( $section ) { | |
| 5825 | - var noSectionFields, $rows, length, index, sectionHasFields; | |
| 5826 | - | |
| 5827 | - if ( ! $section.length ) { | |
| 5828 | - return; | |
| 5829 | - } | |
| 5830 | - | |
| 5831 | - $rows = $section.find( 'ul.frm_sorting' ); | |
| 5832 | - sectionHasFields = false; | |
| 5833 | - length = $rows.length; | |
| 5834 | - for ( index = 0; index < length; ++index ) { | |
| 5835 | - if ( 0 !== getFieldsInRow( jQuery( $rows.get( index ) ) ).length ) { | |
| 5836 | - sectionHasFields = true; | |
| 5837 | - break; | |
| 5838 | - } | |
| 5839 | - } | |
| 5840 | - | |
| 5841 | - noSectionFields = $section.parent().children( '.frm_no_section_fields' ).get( 0 ); | |
| 5842 | - noSectionFields.classList.toggle( 'frm_block', ! sectionHasFields ); | |
| 5843 | - } | |
| 5844 | - | |
| 5845 | - function slideDown() { | |
| 5846 | - /*jshint validthis:true */ | |
| 5847 | - var id = jQuery( this ).data( 'slidedown' ); | |
| 5848 | - var $thisId = jQuery( document.getElementById( id ) ); | |
| 5849 | - if ( $thisId.is( ':hidden' ) ) { | |
| 5850 | - $thisId.slideDown( 'fast' ); | |
| 5851 | - this.style.display = 'none'; | |
| 5852 | - } | |
| 5853 | - return false; | |
| 5854 | - } | |
| 5855 | - | |
| 5856 | - function slideUp() { | |
| 5857 | - /*jshint validthis:true */ | |
| 5858 | - var id = jQuery( this ).data( 'slideup' ); | |
| 5859 | - var $thisId = jQuery( document.getElementById( id ) ); | |
| 5860 | - $thisId.slideUp( 'fast' ); | |
| 5861 | - $thisId.siblings( 'a' ).show(); | |
| 5862 | - return false; | |
| 5863 | - } | |
| 5864 | - | |
| 5865 | - function adjustVisibilityValuesForEveryoneValues( element, option ) { | |
| 5866 | - if ( '' === option.getAttribute( 'value' ) ) { | |
| 5867 | - onEveryoneOptionSelected( jQuery( this ) ); | |
| 5868 | - } else { | |
| 5869 | - unselectEveryoneOptionIfSelected( jQuery( this ) ); | |
| 5870 | - } | |
| 5871 | - } | |
| 5872 | - | |
| 5873 | - function onEveryoneOptionSelected( $select ) { | |
| 5874 | - $select.val( '' ); | |
| 5875 | - $select.next( '.btn-group' ).find( '.multiselect-container input[value!=""]' ).prop( 'checked', false ); | |
| 5876 | - } | |
| 5877 | - | |
| 5878 | - function unselectEveryoneOptionIfSelected( $select ) { | |
| 5879 | - var selectedValues = $select.val(), | |
| 5880 | - index; | |
| 5881 | - | |
| 5882 | - if ( selectedValues === null ) { | |
| 5883 | - $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', true ); | |
| 5884 | - onEveryoneOptionSelected( $select ); | |
| 5885 | - return; | |
| 5886 | - } | |
| 5887 | - | |
| 5888 | - index = selectedValues.indexOf( '' ); | |
| 5889 | - if ( index >= 0 ) { | |
| 5890 | - selectedValues.splice( index, 1 ); | |
| 5891 | - $select.val( selectedValues ); | |
| 5892 | - $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', false ); | |
| 5893 | - } | |
| 5894 | - } | |
| 5895 | - | |
| 5896 | - /** | |
| 5897 | - * Get rid of empty container that inserts extra space. | |
| 5898 | - */ | |
| 5899 | - function hideEmptyEle() { | |
| 5900 | - jQuery( '.frm-hide-empty' ).each( function() { | |
| 5901 | - if ( jQuery( this ).text().trim().length === 0 ) { | |
| 5902 | - jQuery( this ).remove(); | |
| 5903 | - } | |
| 5904 | - }); | |
| 5905 | - } | |
| 5906 | - | |
| 5907 | - /* Change the classes in the builder */ | |
| 5908 | - function changeFieldClass( field, setting ) { | |
| 5909 | - var classes, replace, alignField, | |
| 5910 | - replaceWith = ' ' + setting.value, | |
| 5911 | - fieldId = field.getAttribute( 'data-fid' ); | |
| 5912 | - | |
| 5913 | - // Include classes from multiple settings. | |
| 5914 | - if ( typeof fieldId !== 'undefined' ) { | |
| 5915 | - if ( setting.classList.contains( 'field_options_align' ) ) { | |
| 5916 | - replaceWith += ' ' + document.getElementById( 'frm_classes_' + fieldId ).value; | |
| 5917 | - } else if ( setting.classList.contains( 'frm_classes' ) ) { | |
| 5918 | - alignField = document.getElementById( 'field_options_align_' + fieldId ); | |
| 5919 | - if ( alignField !== null ) { | |
| 5920 | - replaceWith += ' ' + alignField.value; | |
| 5921 | - } | |
| 5922 | - } | |
| 5923 | - } | |
| 5924 | - replaceWith += ' '; | |
| 5925 | - | |
| 5926 | - // Allow for the column number dropdown. | |
| 5927 | - replaceWith = replaceWith.replace( ' block ', ' ' ).replace( ' inline ', ' horizontal_radio ' ); | |
| 5928 | - | |
| 5929 | - classes = field.className.split( ' frmstart ' )[1]; | |
| 5930 | - classes = 0 === classes.indexOf( 'frmend ' ) ? '' : classes.split( ' frmend ' )[0]; | |
| 5931 | - | |
| 5932 | - if ( classes.trim() === '' ) { | |
| 5933 | - replace = ' frmstart frmend '; | |
| 5934 | - if ( -1 === field.className.indexOf( replace ) ) { | |
| 5935 | - replace = ' frmstart frmend '; | |
| 5936 | - } | |
| 5937 | - replaceWith = ' frmstart ' + replaceWith.trim() + ' frmend '; | |
| 5938 | - } else { | |
| 5939 | - replace = classes.trim(); | |
| 5940 | - replaceWith = replaceWith.trim(); | |
| 5941 | - } | |
| 5942 | - | |
| 5943 | - field.className = field.className.replace( replace, replaceWith ); | |
| 5944 | - } | |
| 5945 | - | |
| 5946 | - function maybeShowInlineModal( e ) { | |
| 5947 | - /*jshint validthis:true */ | |
| 5948 | - e.preventDefault(); | |
| 5949 | - showInlineModal( this ); | |
| 5950 | - } | |
| 5951 | - | |
| 5952 | - function showInlineModal( icon, input ) { | |
| 5953 | - var box = document.getElementById( icon.getAttribute( 'data-open' ) ), | |
| 5954 | - container = jQuery( icon ).closest( 'p' ), | |
| 5955 | - inputTrigger = ( typeof input !== 'undefined' ); | |
| 5956 | - | |
| 5957 | - if ( container.hasClass( 'frm-open' ) ) { | |
| 5958 | - container.removeClass( 'frm-open' ); | |
| 5959 | - box.classList.add( 'frm_hidden' ); | |
| 5960 | - } else { | |
| 5961 | - if ( ! inputTrigger ) { | |
| 5962 | - input = getInputForIcon( icon ); | |
| 5963 | - } | |
| 5964 | - if ( input !== null ) { | |
| 5965 | - if ( ! inputTrigger ) { | |
| 5966 | - input.focus(); | |
| 5967 | - } | |
| 5968 | - container.after( box ); | |
| 5969 | - box.setAttribute( 'data-fills', input.id ); | |
| 5970 | - | |
| 5971 | - if ( box.id.indexOf( 'frm-calc-box' ) === 0 ) { | |
| 5972 | - popCalcFields( box, true ); | |
| 5973 | - } | |
| 5974 | - } | |
| 5975 | - | |
| 5976 | - container.addClass( 'frm-open' ); | |
| 5977 | - box.classList.remove( 'frm_hidden' ); | |
| 5978 | - } | |
| 5979 | - } | |
| 5980 | - | |
| 5981 | - function dismissInlineModal( e ) { | |
| 5982 | - /*jshint validthis:true */ | |
| 5983 | - e.preventDefault(); | |
| 5984 | - this.parentNode.classList.add( 'frm_hidden' ); | |
| 5985 | - jQuery( '.frm-open [data-open="' + this.parentNode.id + '"]' ).closest( '.frm-open' ).removeClass( 'frm-open' ); | |
| 5986 | - } | |
| 5987 | - | |
| 5988 | - function changeInputtedValue() { | |
| 5989 | - /*jshint validthis:true */ | |
| 5990 | - var i, | |
| 5991 | - action = this.getAttribute( 'data-frmchange' ).split( ',' ); | |
| 5992 | - | |
| 5993 | - for ( i = 0; i < action.length; i++ ) { | |
| 5994 | - if ( action[i] === 'updateOption' ) { | |
| 5995 | - changeHiddenSeparateValue( this ); | |
| 5996 | - } else if ( action[i] === 'updateDefault' ) { | |
| 5997 | - changeDefaultRadioValue( this ); | |
| 5998 | - } else if ( action[i] === 'checkUniqueOpt' ) { | |
| 5999 | - checkUniqueOpt( this ); | |
| 6000 | - } else { | |
| 6001 | - this.value = this.value[ action[i] ](); | |
| 6002 | - } | |
| 6003 | - } | |
| 6004 | - } | |
| 6005 | - | |
| 6006 | - /** | |
| 6007 | - * When the saved value is changed, update the default value radio. | |
| 6008 | - */ | |
| 6009 | - function changeDefaultRadioValue( input ) { | |
| 6010 | - var parentLi = getOptionParent( input ), | |
| 6011 | - key = parentLi.getAttribute( 'data-optkey' ), | |
| 6012 | - fieldId = getOptionFieldId( parentLi, key ), | |
| 6013 | - defaultRadio = parentLi.querySelector( 'input[name="default_value_' + fieldId + '"]' ); | |
| 6014 | - | |
| 6015 | - if ( defaultRadio !== null ) { | |
| 6016 | - defaultRadio.value = input.value; | |
| 6017 | - } | |
| 6018 | - } | |
| 6019 | - | |
| 6020 | - /** | |
| 6021 | - * If separate values are not enabled, change the saved value when | |
| 6022 | - * the displayed value is changed. | |
| 6023 | - */ | |
| 6024 | - function changeHiddenSeparateValue( input ) { | |
| 6025 | - var savedVal, | |
| 6026 | - parentLi = getOptionParent( input ), | |
| 6027 | - key = parentLi.getAttribute( 'data-optkey' ), | |
| 6028 | - fieldId = getOptionFieldId( parentLi, key ), | |
| 6029 | - sep = document.getElementById( 'separate_value_' + fieldId ); | |
| 6030 | - | |
| 6031 | - if ( sep !== null && sep.checked === false ) { | |
| 6032 | - // If separate values are not turned on. | |
| 6033 | - savedVal = document.getElementById( 'field_key_' + fieldId + '-' + key ); | |
| 6034 | - savedVal.value = input.value; | |
| 6035 | - changeDefaultRadioValue( savedVal ); | |
| 6036 | - } | |
| 6037 | - } | |
| 6038 | - | |
| 6039 | - function getOptionParent( input ) { | |
| 6040 | - var parentLi = input.parentNode; | |
| 6041 | - if ( parentLi.tagName !== 'LI' ) { | |
| 6042 | - parentLi = parentLi.parentNode; | |
| 6043 | - } | |
| 6044 | - return parentLi; | |
| 6045 | - } | |
| 6046 | - | |
| 6047 | - function getOptionFieldId( li, key ) { | |
| 6048 | - var liId = li.id; | |
| 6049 | - | |
| 6050 | - return liId.replace( 'frm_delete_field_', '' ).replace( '-' + key + '_container', '' ); | |
| 6051 | - } | |
| 6052 | - | |
| 6053 | - function submitBuild() { | |
| 6054 | - /*jshint validthis:true */ | |
| 6055 | - var $thisEle = this; | |
| 6056 | - | |
| 6057 | - preFormSave( this ); | |
| 6058 | - | |
| 6059 | - var $form = jQuery( builderForm ); | |
| 6060 | - var v = JSON.stringify( $form.serializeArray() ); | |
| 6061 | - | |
| 6062 | - jQuery( document.getElementById( 'frm_compact_fields' ) ).val( v ); | |
| 6063 | - jQuery.ajax({ | |
| 6064 | - type: 'POST', | |
| 6065 | - url: ajaxurl, | |
| 6066 | - data: {action: 'frm_save_form', 'frm_compact_fields': v, nonce: frmGlobal.nonce}, | |
| 6067 | - success: function( msg ) { | |
| 6068 | - afterFormSave( $thisEle ); | |
| 6069 | - | |
| 6070 | - var $postStuff = document.getElementById( 'post-body-content' ); | |
| 6071 | - var $html = document.createElement( 'div' ); | |
| 6072 | - $html.setAttribute( 'class', 'frm_updated_message' ); | |
| 6073 | - $html.innerHTML = msg; | |
| 6074 | - $postStuff.insertBefore( $html, $postStuff.firstChild ); | |
| 6075 | - }, | |
| 6076 | - error: function() { | |
| 6077 | - triggerSubmit( document.getElementById( 'frm_js_build_form' ) ); | |
| 6078 | - } | |
| 6079 | - }); | |
| 6080 | - } | |
| 6081 | - | |
| 6082 | - function triggerSubmit( form ) { | |
| 6083 | - var button = form.ownerDocument.createElement( 'input' ); | |
| 6084 | - button.style.display = 'none'; | |
| 6085 | - button.type = 'submit'; | |
| 6086 | - form.appendChild( button ).click(); | |
| 6087 | - form.removeChild( button ); | |
| 6088 | - } | |
| 6089 | - | |
| 6090 | - function triggerChange( element ) { | |
| 6091 | - jQuery( element ).trigger( 'change' ); | |
| 6092 | - } | |
| 6093 | - | |
| 6094 | - function submitNoAjax() { | |
| 6095 | - /*jshint validthis:true */ | |
| 6096 | - var form; | |
| 6097 | - | |
| 6098 | - preFormSave( this ); | |
| 6099 | - form = jQuery( builderForm ); | |
| 6100 | - jQuery( document.getElementById( 'frm_compact_fields' ) ).val( JSON.stringify( form.serializeArray() ) ); | |
| 6101 | - triggerSubmit( document.getElementById( 'frm_js_build_form' ) ); | |
| 6102 | - } | |
| 6103 | - | |
| 6104 | - function preFormSave( b ) { | |
| 6105 | - removeWPUnload(); | |
| 6106 | - if ( jQuery( 'form.inplace_form' ).length ) { | |
| 6107 | - jQuery( '.inplace_save, .postbox' ).trigger( 'click' ); | |
| 6108 | - } | |
| 6109 | - | |
| 6110 | - if ( b.classList.contains( 'frm_button_submit' ) ) { | |
| 6111 | - b.classList.add( 'frm_loading_form' ); | |
| 6112 | - } else { | |
| 6113 | - b.classList.add( 'frm_loading_button' ); | |
| 6114 | - } | |
| 6115 | - b.setAttribute( 'aria-busy', 'true' ); | |
| 6116 | - } | |
| 6117 | - | |
| 6118 | - function afterFormSave( button ) { | |
| 6119 | - button.classList.remove( 'frm_loading_form' ); | |
| 6120 | - button.classList.remove( 'frm_loading_button' ); | |
| 6121 | - resetOptionTextDetails(); | |
| 6122 | - fieldsUpdated = 0; | |
| 6123 | - button.setAttribute( 'aria-busy', 'false' ); | |
| 6124 | - | |
| 6125 | - setTimeout( function() { | |
| 6126 | - jQuery( '.frm_updated_message' ).fadeOut( 'slow', function() { | |
| 6127 | - this.parentNode.removeChild( this ); | |
| 6128 | - }); | |
| 6129 | - }, 5000 ); | |
| 6130 | - } | |
| 6131 | - | |
| 6132 | - function initUpgradeModal() { | |
| 6133 | - const $info = initModal( '#frm_upgrade_modal' ); | |
| 6134 | - if ( $info === false ) { | |
| 6135 | - return; | |
| 6136 | - } | |
| 6137 | - | |
| 6138 | - document.addEventListener( 'click', handleUpgradeClick ); | |
| 6139 | - | |
| 6140 | - function handleUpgradeClick( event ) { | |
| 6141 | - let element, link, content; | |
| 6142 | - | |
| 6143 | - element = event.target; | |
| 6144 | - | |
| 6145 | - if ( ! element.classList ) { | |
| 6146 | - return; | |
| 6147 | - } | |
| 6148 | - | |
| 6149 | - const showExpiredModal = element.classList.contains( 'frm_show_expired_modal' ) || null !== element.querySelector( '.frm_show_expired_modal' ) || element.closest( '.frm_show_expired_modal' ); | |
| 6150 | - | |
| 6151 | - if ( ! element.dataset.upgrade ) { | |
| 6152 | - const parent = element.closest( '[data-upgrade]' ); | |
| 6153 | - if ( ! parent ) { | |
| 6154 | - return; | |
| 6155 | - } | |
| 6156 | - element = parent; | |
| 6157 | - } | |
| 6158 | - | |
| 6159 | - if ( showExpiredModal ) { | |
| 6160 | - const hookName = 'frm_show_expired_modal'; | |
| 6161 | - wp.hooks.doAction( hookName, element ); | |
| 6162 | - return; | |
| 6163 | - } | |
| 6164 | - | |
| 6165 | - const upgradeLabel = element.dataset.upgrade; | |
| 6166 | - if ( ! upgradeLabel || element.classList.contains( 'frm_show_upgrade_tab' ) ) { | |
| 6167 | - return; | |
| 6168 | - } | |
| 6169 | - | |
| 6170 | - event.preventDefault(); | |
| 6171 | - | |
| 6172 | - const modal = $info.get( 0 ); | |
| 6173 | - const lockIcon = modal.querySelector( '.frm_lock_icon' ); | |
| 6174 | - | |
| 6175 | - if ( lockIcon ) { | |
| 6176 | - lockIcon.style.display = 'block'; | |
| 6177 | - lockIcon.classList.remove( 'frm_lock_open_icon' ); | |
| 6178 | - lockIcon.querySelector( 'use' ).setAttribute( 'href', '#frm_lock_icon' ); | |
| 6179 | - } | |
| 6180 | - | |
| 6181 | - const upgradeImageId = 'frm_upgrade_modal_image'; | |
| 6182 | - const oldImage = document.getElementById( upgradeImageId ); | |
| 6183 | - if ( oldImage ) { | |
| 6184 | - oldImage.remove(); | |
| 6185 | - } | |
| 6186 | - | |
| 6187 | - if ( element.dataset.image ) { | |
| 6188 | - if ( lockIcon ) { | |
| 6189 | - lockIcon.style.display = 'none'; | |
| 6190 | - } | |
| 6191 | - lockIcon.parentNode.insertBefore( img({ id: upgradeImageId, src: frmGlobal.url + '/images/' + element.dataset.image }), lockIcon ); | |
| 6192 | - } | |
| 6193 | - | |
| 6194 | - const level = modal.querySelector( '.license-level' ); | |
| 6195 | - if ( level ) { | |
| 6196 | - level.textContent = getRequiredLicenseFromTrigger( element ); | |
| 6197 | - } | |
| 6198 | - | |
| 6199 | - // If one click upgrade, hide other content | |
| 6200 | - addOneClick( element, 'modal', upgradeLabel ); | |
| 6201 | - | |
| 6202 | - modal.querySelector( '.frm_are_not_installed' ).style.display = element.dataset.image ? 'none' : 'inline-block'; | |
| 6203 | - modal.querySelector( '.frm_feature_label' ).textContent = upgradeLabel; | |
| 6204 | - modal.querySelector( 'h2' ).style.display = 'block'; | |
| 6205 | - | |
| 6206 | - $info.dialog( 'open' ); | |
| 6207 | - | |
| 6208 | - // set the utm medium | |
| 6209 | - const button = modal.querySelector( '.button-primary:not(.frm-oneclick-button)' ); | |
| 6210 | - link = button.getAttribute( 'href' ).replace( /(medium=)[a-z_-]+/ig, '$1' + element.getAttribute( 'data-medium' ) ); | |
| 6211 | - content = element.getAttribute( 'data-content' ); | |
| 6212 | - if ( content === null ) { | |
| 6213 | - content = ''; | |
| 6214 | - } | |
| 6215 | - link = link.replace( /(content=)[a-z_-]+/ig, '$1' + content ); | |
| 6216 | - button.setAttribute( 'href', link ); | |
| 6217 | - } | |
| 6218 | - } | |
| 6219 | - | |
| 6220 | - function getRequiredLicenseFromTrigger( element ) { | |
| 6221 | - if ( element.dataset.requires ) { | |
| 6222 | - return element.dataset.requires; | |
| 6223 | - } | |
| 6224 | - return 'Pro'; | |
| 6225 | - } | |
| 6226 | - | |
| 6227 | - function populateUpgradeTab( element ) { | |
| 6228 | - const title = element.dataset.upgrade; | |
| 6229 | - | |
| 6230 | - const tab = element.getAttribute( 'href' ).replace( '#', '' ); | |
| 6231 | - const container = document.querySelector( '.frm_' + tab ) || document.querySelector( '.' + tab ); | |
| 6232 | - | |
| 6233 | - if ( ! container ) { | |
| 6234 | - return; | |
| 6235 | - } | |
| 6236 | - | |
| 6237 | - if ( container.querySelector( '.frm-upgrade-message' ) ) { | |
| 6238 | - // Tab has already been populated. | |
| 6239 | - return; | |
| 6240 | - } | |
| 6241 | - | |
| 6242 | - const h2 = container.querySelector( 'h2' ); | |
| 6243 | - h2.style.borderBottom = 'none'; | |
| 6244 | - | |
| 6245 | - /* translators: %s: Form Setting section name (ie Form Permissions, Form Scheduling). */ | |
| 6246 | - h2.textContent = __( '%s are not installed' ).replace( '%s', title ); | |
| 6247 | - | |
| 6248 | - container.classList.add( 'frmcenter' ); | |
| 6249 | - | |
| 6250 | - const upgradeModal = document.getElementById( 'frm_upgrade_modal' ); | |
| 6251 | - appendClonedModalElementToContainer( 'frm-oneclick' ); | |
| 6252 | - appendClonedModalElementToContainer( 'frm-addon-status' ); | |
| 6253 | - | |
| 6254 | - // 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). | |
| 6255 | - const upgradeModalLink = upgradeModal.querySelector( '.frm-upgrade-link' ); | |
| 6256 | - if ( upgradeModalLink ) { | |
| 6257 | - const upgradeButton = upgradeModalLink.cloneNode( true ); | |
| 6258 | - const level = upgradeButton.querySelector( '.license-level' ); | |
| 6259 | - | |
| 6260 | - if ( level ) { | |
| 6261 | - level.textContent = getRequiredLicenseFromTrigger( element ); | |
| 6262 | - } | |
| 6263 | - | |
| 6264 | - container.appendChild( upgradeButton ); | |
| 6265 | - | |
| 6266 | - // Maybe append the secondary "Already purchased?" link from the upgradeModal as well. | |
| 6267 | - if ( upgradeModalLink.nextElementSibling && upgradeModalLink.nextElementSibling.querySelector( '.frm-link-secondary' ) ) { | |
| 6268 | - container.appendChild( upgradeModalLink.nextElementSibling.cloneNode( true ) ); | |
| 6269 | - } | |
| 6270 | - | |
| 6271 | - appendClonedModalElementToContainer( 'frm-oneclick-button' ); | |
| 6272 | - } | |
| 6273 | - | |
| 6274 | - appendClonedModalElementToContainer( 'frm-upgrade-message' ); | |
| 6275 | - addOneClick( element, 'tab', element.dataset.message ); | |
| 6276 | - | |
| 6277 | - if ( element.dataset.screenshot ) { | |
| 6278 | - container.appendChild( getScreenshotWrapper( element.dataset.screenshot ) ); | |
| 6279 | - } | |
| 6280 | - | |
| 6281 | - function appendClonedModalElementToContainer( className ) { | |
| 6282 | - container.appendChild( upgradeModal.querySelector( '.' + className ).cloneNode( true ) ); | |
| 6283 | - } | |
| 6284 | - } | |
| 6285 | - | |
| 6286 | - function getScreenshotWrapper( screenshot ) { | |
| 6287 | - const folderUrl = frmGlobal.url + '/images/screenshots/'; | |
| 6288 | - const wrapper = div({ | |
| 6289 | - className: 'frm-settings-screenshot-wrapper', | |
| 6290 | - children: [ | |
| 6291 | - getToolbar(), | |
| 6292 | - div({ child: img({ src: folderUrl + screenshot }) }) | |
| 6293 | - ] | |
| 6294 | - }); | |
| 6295 | - | |
| 6296 | - function getToolbar() { | |
| 6297 | - const children = getColorIcons(); | |
| 6298 | - children.push( img({ src: frmGlobal.url + '/images/tab.svg' }) ); | |
| 6299 | - return div({ | |
| 6300 | - className: 'frm-settings-screenshot-toolbar', | |
| 6301 | - children | |
| 6302 | - }); | |
| 6303 | - } | |
| 6304 | - | |
| 6305 | - function getColorIcons() { | |
| 6306 | - return [ '#ED8181', '#EDE06A', '#80BE30' ].map( | |
| 6307 | - color => { | |
| 6308 | - const circle = div({ className: 'frm-minmax-icon' }); | |
| 6309 | - circle.style.backgroundColor = color; | |
| 6310 | - return circle; | |
| 6311 | - } | |
| 6312 | - ); | |
| 6313 | - } | |
| 6314 | - | |
| 6315 | - return wrapper; | |
| 6316 | - } | |
| 6317 | - | |
| 6318 | - /** | |
| 6319 | - * Allow addons to be installed from the upgrade modal. | |
| 6320 | - * | |
| 6321 | - * @param {Element} link | |
| 6322 | - * @param {String} context Either 'modal' or 'tab'. | |
| 6323 | - * @param {String|undefined} upgradeLabel | |
| 6324 | - */ | |
| 6325 | - function addOneClick( link, context, upgradeLabel ) { | |
| 6326 | - let container; | |
| 6327 | - | |
| 6328 | - if ( 'modal' === context ) { | |
| 6329 | - container = document.getElementById( 'frm_upgrade_modal' ); | |
| 6330 | - } else if ( 'tab' === context ) { | |
| 6331 | - container = document.getElementById( link.getAttribute( 'href' ).substr( 1 ) ); | |
| 6332 | - } else { | |
| 6333 | - return; | |
| 6334 | - } | |
| 6335 | - | |
| 6336 | - const oneclickMessage = container.querySelector( '.frm-oneclick' ); | |
| 6337 | - const upgradeMessage = container.querySelector( '.frm-upgrade-message' ); | |
| 6338 | - const showLink = container.querySelector( '.frm-upgrade-link' ); | |
| 6339 | - const button = container.querySelector( '.frm-oneclick-button' ); | |
| 6340 | - const addonStatus = container.querySelector( '.frm-addon-status' ); | |
| 6341 | - | |
| 6342 | - let oneclick = link.getAttribute( 'data-oneclick' ); | |
| 6343 | - let newMessage = link.getAttribute( 'data-message' ); | |
| 6344 | - let showIt = 'block'; | |
| 6345 | - let showMsg = 'block'; | |
| 6346 | - let hideIt = 'none'; | |
| 6347 | - | |
| 6348 | - // If one click upgrade, hide other content. | |
| 6349 | - if ( oneclickMessage !== null && typeof oneclick !== 'undefined' && oneclick ) { | |
| 6350 | - if ( newMessage === null ) { | |
| 6351 | - showMsg = 'none'; | |
| 6352 | - } | |
| 6353 | - showIt = 'none'; | |
| 6354 | - hideIt = 'block'; | |
| 6355 | - oneclick = JSON.parse( oneclick ); | |
| 6356 | - | |
| 6357 | - button.className = button.className.replace( ' frm-install-addon', '' ).replace( ' frm-activate-addon', '' ); | |
| 6358 | - button.className = button.className + ' ' + oneclick.class; | |
| 6359 | - button.textContent = __( 'Activate', 'formidable' ); | |
| 6360 | - button.rel = oneclick.url; | |
| 6361 | - } | |
| 6362 | - | |
| 6363 | - if ( ! newMessage ) { | |
| 6364 | - newMessage = upgradeMessage.getAttribute( 'data-default' ); | |
| 6365 | - } | |
| 6366 | - if ( undefined !== upgradeLabel ) { | |
| 6367 | - newMessage = newMessage.replace( '<span class="frm_feature_label"></span>', upgradeLabel ); | |
| 6368 | - } | |
| 6369 | - | |
| 6370 | - upgradeMessage.innerHTML = newMessage; | |
| 6371 | - | |
| 6372 | - // Either set the link or use the default. | |
| 6373 | - showLink.href = getShowLinkHrefValue( link, showLink ); | |
| 6374 | - | |
| 6375 | - addonStatus.style.display = 'none'; | |
| 6376 | - | |
| 6377 | - oneclickMessage.style.display = hideIt; | |
| 6378 | - button.style.display = hideIt === 'block' ? 'inline-block' : hideIt; | |
| 6379 | - upgradeMessage.style.display = showMsg; | |
| 6380 | - showLink.style.display = showIt === 'block' ? 'inline-block' : showIt; | |
| 6381 | - } | |
| 6382 | - | |
| 6383 | - function getShowLinkHrefValue( link, showLink ) { | |
| 6384 | - let customLink = link.getAttribute( 'data-link' ); | |
| 6385 | - if ( customLink === null || typeof customLink === 'undefined' || customLink === '' ) { | |
| 6386 | - customLink = showLink.getAttribute( 'data-default' ); | |
| 6387 | - } | |
| 6388 | - return customLink; | |
| 6389 | - } | |
| 6390 | - | |
| 6391 | - /* Form settings */ | |
| 6392 | - | |
| 6393 | - function showInputIcon( parentClass ) { | |
| 6394 | - if ( typeof parentClass === 'undefined' ) { | |
| 6395 | - parentClass = ''; | |
| 6396 | - } | |
| 6397 | - maybeAddFieldSelection( parentClass ); | |
| 6398 | - 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>' ); | |
| 6399 | - } | |
| 6400 | - | |
| 6401 | - /** | |
| 6402 | - * For reverse compatibility. Check for fields that were | |
| 6403 | - * using the old sidebar. | |
| 6404 | - */ | |
| 6405 | - function maybeAddFieldSelection( parentClass ) { | |
| 6406 | - var i, | |
| 6407 | - 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' ); | |
| 6408 | - for ( i = 0; i < missingClass.length; i++ ) { | |
| 6409 | - missingClass[i].parentNode.classList.add( 'frm_has_shortcodes' ); | |
| 6410 | - } | |
| 6411 | - } | |
| 6412 | - | |
| 6413 | - function showSuccessOpt() { | |
| 6414 | - /*jshint validthis:true */ | |
| 6415 | - var c = 'success'; | |
| 6416 | - if ( this.name === 'options[edit_action]' ) { | |
| 6417 | - c = 'edit'; | |
| 6418 | - } | |
| 6419 | - var v = jQuery( this ).val(); | |
| 6420 | - jQuery( '.' + c + '_action_box' ).hide(); | |
| 6421 | - if ( v === 'redirect' ) { | |
| 6422 | - jQuery( '.' + c + '_action_redirect_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 6423 | - } else if ( v === 'page' ) { | |
| 6424 | - jQuery( '.' + c + '_action_page_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 6425 | - } else { | |
| 6426 | - jQuery( '.' + c + '_action_message_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 6427 | - } | |
| 6428 | - } | |
| 6429 | - | |
| 6430 | - function copyFormAction( event ) { | |
| 6431 | - if ( waitForActionToLoadBeforeCopy( event.target ) ) { | |
| 6432 | - return; | |
| 6433 | - } | |
| 6434 | - | |
| 6435 | - const targetSettings = event.target.closest( '.frm_form_action_settings' ); | |
| 6436 | - const wysiwyg = targetSettings.querySelector( '.wp-editor-area' ); | |
| 6437 | - if ( wysiwyg ) { | |
| 6438 | - // Temporary remove TinyMCE before cloning to avoid TinyMCE conflicts. | |
| 6439 | - tinymce.EditorManager.execCommand( 'mceRemoveEditor', true, wysiwyg.id ); | |
| 6440 | - } | |
| 6441 | - | |
| 6442 | - const $action = jQuery( targetSettings ).clone(); | |
| 6443 | - const currentID = $action.attr( 'id' ).replace( 'frm_form_action_', '' ); | |
| 6444 | - const newID = newActionId( currentID ); | |
| 6445 | - | |
| 6446 | - $action.find( '.frm_action_id, .frm-btn-group' ).remove(); | |
| 6447 | - $action.find( 'input[name$="[' + currentID + '][ID]"]' ).val( '' ); | |
| 6448 | - $action.find( '.widget-inside' ).hide(); | |
| 6449 | - | |
| 6450 | - // the .html() gets original values, so they need to be set | |
| 6451 | - $action.find( 'input[type=text], textarea, input[type=number]' ).prop( 'defaultValue', function() { | |
| 6452 | - return this.value; | |
| 6453 | - }); | |
| 6454 | - | |
| 6455 | - $action.find( 'input[type=checkbox], input[type=radio]' ).prop( 'defaultChecked', function() { | |
| 6456 | - return this.checked; | |
| 6457 | - }); | |
| 6458 | - | |
| 6459 | - const rename = new RegExp( '\\[' + currentID + '\\]', 'g' ); | |
| 6460 | - const reid = new RegExp( '_' + currentID + '"', 'g' ); | |
| 6461 | - const reclass = new RegExp( '-' + currentID + '"', 'g' ); | |
| 6462 | - const revalue = new RegExp( '"' + currentID + '"', 'g' ); // if a field id matches, this could cause trouble | |
| 6463 | - | |
| 6464 | - let html = $action.html().replace( rename, '[' + newID + ']' ).replace( reid, '_' + newID + '"' ); | |
| 6465 | - html = html.replace( reclass, '-' + newID + '"' ).replace( revalue, '"' + newID + '"' ); | |
| 6466 | - | |
| 6467 | - const newAction = div({ | |
| 6468 | - id: 'frm_form_action_' + newID, | |
| 6469 | - className: $action.get( 0 ).className | |
| 6470 | - }); | |
| 6471 | - newAction.setAttribute( 'data-actionkey', newID ); | |
| 6472 | - newAction.innerHTML = html; | |
| 6473 | - newAction.querySelectorAll( '.wp-editor-wrap, .wp-editor-wrap *' ).forEach( | |
| 6474 | - element => { | |
| 6475 | - if ( 'string' === typeof element.className ) { | |
| 6476 | - element.className = element.className.replace( currentID, newID ); | |
| 6477 | - } | |
| 6478 | - element.id = element.id.replace( currentID, newID ); | |
| 6479 | - } | |
| 6480 | - ); | |
| 6481 | - newAction.classList.remove( 'open' ); | |
| 6482 | - document.getElementById( 'frm_notification_settings' ).appendChild( newAction ); | |
| 6483 | - | |
| 6484 | - if ( wysiwyg ) { | |
| 6485 | - // Re-initialize the original wysiwyg which was removed before cloning. | |
| 6486 | - frmDom.wysiwyg.init( wysiwyg ); | |
| 6487 | - frmDom.wysiwyg.init( newAction.querySelector( '.wp-editor-area' ) ); | |
| 6488 | - } | |
| 6489 | - | |
| 6490 | - if ( newAction.classList.contains( 'frm_single_on_submit_settings' ) ) { | |
| 6491 | - const autocompleteInput = newAction.querySelector( 'input.frm-page-search' ); | |
| 6492 | - if ( autocompleteInput ) { | |
| 6493 | - frmDom.autocomplete.initAutocomplete( 'page', newAction ); | |
| 6494 | - } | |
| 6495 | - } | |
| 6496 | - | |
| 6497 | - initiateMultiselect(); | |
| 6498 | - | |
| 6499 | - const hookName = 'frm_after_duplicate_action'; | |
| 6500 | - wp.hooks.doAction( hookName, newAction ); | |
| 6501 | - } | |
| 6502 | - | |
| 6503 | - function waitForActionToLoadBeforeCopy( element ) { | |
| 6504 | - var $trigger = jQuery( element ), | |
| 6505 | - $original = $trigger.closest( '.frm_form_action_settings' ), | |
| 6506 | - $inside = $original.find( '.widget-inside' ), | |
| 6507 | - $top; | |
| 6508 | - | |
| 6509 | - if ( $inside.find( 'p, div, table' ).length ) { | |
| 6510 | - return false; | |
| 6511 | - } | |
| 6512 | - | |
| 6513 | - $top = $original.find( '.widget-top' ); | |
| 6514 | - $top.on( 'frm-action-loaded', function() { | |
| 6515 | - $trigger.trigger( 'click' ); | |
| 6516 | - $original.removeClass( 'open' ); | |
| 6517 | - $inside.hide(); | |
| 6518 | - }); | |
| 6519 | - $top.trigger( 'click' ); | |
| 6520 | - return true; | |
| 6521 | - } | |
| 6522 | - | |
| 6523 | - function newActionId( currentID ) { | |
| 6524 | - var newID = parseInt( currentID, 10 ) + 11; | |
| 6525 | - var exists = document.getElementById( 'frm_form_action_' + newID ); | |
| 6526 | - if ( exists !== null ) { | |
| 6527 | - newID++; | |
| 6528 | - newID = newActionId( newID ); | |
| 6529 | - } | |
| 6530 | - return newID; | |
| 6531 | - } | |
| 6532 | - | |
| 6533 | - function addFormAction() { | |
| 6534 | - /*jshint validthis:true */ | |
| 6535 | - const type = jQuery( this ).data( 'actiontype' ); | |
| 6536 | - | |
| 6537 | - if ( isAtLimitForActionType( type ) ) { | |
| 6538 | - return; | |
| 6539 | - } | |
| 6540 | - | |
| 6541 | - const actionId = getNewActionId(); | |
| 6542 | - const formId = thisFormId; | |
| 6543 | - | |
| 6544 | - const placeholderSetting = document.createElement( 'div' ); | |
| 6545 | - placeholderSetting.classList.add( 'frm_single_' + type + '_settings' ); | |
| 6546 | - | |
| 6547 | - const actionsList = document.getElementById( 'frm_notification_settings' ); | |
| 6548 | - actionsList.appendChild( placeholderSetting ); | |
| 6549 | - | |
| 6550 | - jQuery.ajax({ | |
| 6551 | - type: 'POST', | |
| 6552 | - url: ajaxurl, | |
| 6553 | - data: { | |
| 6554 | - action: 'frm_add_form_action', | |
| 6555 | - type: type, | |
| 6556 | - list_id: actionId, | |
| 6557 | - form_id: formId, | |
| 6558 | - nonce: frmGlobal.nonce | |
| 6559 | - }, | |
| 6560 | - success: handleAddFormActionSuccess | |
| 6561 | - }); | |
| 6562 | - | |
| 6563 | - function handleAddFormActionSuccess( html ) { | |
| 6564 | - fieldUpdated(); | |
| 6565 | - placeholderSetting.remove(); | |
| 6566 | - | |
| 6567 | - closeOpenActions(); | |
| 6568 | - | |
| 6569 | - const newActionContainer = div(); | |
| 6570 | - newActionContainer.innerHTML = html; | |
| 6571 | - | |
| 6572 | - const widgetTop = newActionContainer.querySelector( '.widget-top' ); | |
| 6573 | - Array.from( newActionContainer.children ).forEach( child => actionsList.appendChild( child ) ); | |
| 6574 | - | |
| 6575 | - jQuery( '.frm_form_action_settings' ).fadeIn( 'slow' ); | |
| 6576 | - | |
| 6577 | - const newAction = document.getElementById( 'frm_form_action_' + actionId ); | |
| 6578 | - | |
| 6579 | - newAction.classList.add( 'open' ); | |
| 6580 | - document.getElementById( 'post-body-content' ).scroll({ | |
| 6581 | - top: newAction.offsetTop + 10, | |
| 6582 | - left: 0, | |
| 6583 | - behavior: 'smooth' | |
| 6584 | - }); | |
| 6585 | - | |
| 6586 | - // Check if icon should be active | |
| 6587 | - checkActiveAction( type ); | |
| 6588 | - showInputIcon( '#frm_form_action_' + actionId ); | |
| 6589 | - | |
| 6590 | - initiateMultiselect(); | |
| 6591 | - frmDom.autocomplete.initAutocomplete( 'page', newAction ); | |
| 6592 | - | |
| 6593 | - if ( widgetTop ) { | |
| 6594 | - jQuery( widgetTop ).trigger( 'frm-action-loaded' ); | |
| 6595 | - } | |
| 6596 | - | |
| 6597 | - /** | |
| 6598 | - * Fires after added a new form action. | |
| 6599 | - * | |
| 6600 | - * @since 5.5.4 | |
| 6601 | - * | |
| 6602 | - * @param {HTMLElement} formAction Form action element. | |
| 6603 | - */ | |
| 6604 | - frmAdminBuild.hooks.doAction( 'frm_added_form_action', newAction ); | |
| 6605 | - } | |
| 6606 | - } | |
| 6607 | - | |
| 6608 | - function closeOpenActions() { | |
| 6609 | - document.querySelectorAll( '.frm_form_action_settings.open' ).forEach( | |
| 6610 | - setting => setting.classList.remove( 'open' ) | |
| 6611 | - ); | |
| 6612 | - } | |
| 6613 | - | |
| 6614 | - function toggleActionGroups() { | |
| 6615 | - /*jshint validthis:true */ | |
| 6616 | - var actions = document.getElementById( 'frm_email_addon_menu' ).classList, | |
| 6617 | - search = document.getElementById( 'actions-search-input' ); | |
| 6618 | - | |
| 6619 | - if ( actions.contains( 'frm-all-actions' ) ) { | |
| 6620 | - actions.remove( 'frm-all-actions' ); | |
| 6621 | - actions.add( 'frm-limited-actions' ); | |
| 6622 | - } else { | |
| 6623 | - actions.add( 'frm-all-actions' ); | |
| 6624 | - actions.remove( 'frm-limited-actions' ); | |
| 6625 | - } | |
| 6626 | - | |
| 6627 | - // Reset search. | |
| 6628 | - search.value = ''; | |
| 6629 | - triggerEvent( search, 'input' ); | |
| 6630 | - } | |
| 6631 | - | |
| 6632 | - function getNewActionId() { | |
| 6633 | - var actionSettings = document.querySelectorAll( '.frm_form_action_settings' ), | |
| 6634 | - len = getNewRowId( actionSettings, 'frm_form_action_' ); | |
| 6635 | - if ( typeof document.getElementById( 'frm_form_action_' + len ) !== 'undefined' ) { | |
| 6636 | - len = len + 100; | |
| 6637 | - } | |
| 6638 | - if ( lastNewActionIdReturned >= len ) { | |
| 6639 | - len = lastNewActionIdReturned + 1; | |
| 6640 | - } | |
| 6641 | - lastNewActionIdReturned = len; | |
| 6642 | - return len; | |
| 6643 | - } | |
| 6644 | - | |
| 6645 | - function clickAction( obj ) { | |
| 6646 | - var $thisobj = jQuery( obj ); | |
| 6647 | - | |
| 6648 | - if ( obj.className.indexOf( 'selected' ) !== -1 ) { | |
| 6649 | - return; | |
| 6650 | - } | |
| 6651 | - if ( obj.className.indexOf( 'edit_field_type_end_divider' ) !== -1 && $thisobj.closest( '.edit_field_type_divider' ).hasClass( 'no_repeat_section' ) ) { | |
| 6652 | - return; | |
| 6653 | - } | |
| 6654 | - | |
| 6655 | - deselectFields(); | |
| 6656 | - $thisobj.addClass( 'selected' ); | |
| 6657 | - showFieldOptions( obj ); | |
| 6658 | - } | |
| 6659 | - | |
| 6660 | - /** | |
| 6661 | - * When a field is selected, show the field settings in the sidebar. | |
| 6662 | - */ | |
| 6663 | - function showFieldOptions( obj ) { | |
| 6664 | - var i, singleField, | |
| 6665 | - fieldId = obj.getAttribute( 'data-fid' ), | |
| 6666 | - fieldType = obj.getAttribute( 'data-type' ), | |
| 6667 | - allFieldSettings = document.querySelectorAll( '.frm-single-settings:not(.frm_hidden)' ); | |
| 6668 | - | |
| 6669 | - for ( i = 0; i < allFieldSettings.length; i++ ) { | |
| 6670 | - allFieldSettings[i].classList.add( 'frm_hidden' ); | |
| 6671 | - } | |
| 6672 | - | |
| 6673 | - singleField = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 6674 | - moveFieldSettings( singleField ); | |
| 6675 | - | |
| 6676 | - if ( fieldType && 'quantity' === fieldType ) { | |
| 6677 | - popProductFields( jQuery( singleField ).find( '.frmjs_prod_field_opt' )[0]); | |
| 6678 | - } | |
| 6679 | - | |
| 6680 | - singleField.classList.remove( 'frm_hidden' ); | |
| 6681 | - document.getElementById( 'frm-options-panel-tab' ).click(); | |
| 6682 | - | |
| 6683 | - const editor = singleField.querySelector( '.wp-editor-area' ); | |
| 6684 | - if ( editor ) { | |
| 6685 | - frmDom.wysiwyg.init( | |
| 6686 | - editor, | |
| 6687 | - { setupCallback: setupTinyMceEventHandlers } | |
| 6688 | - ); | |
| 6689 | - } | |
| 6690 | - } | |
| 6691 | - | |
| 6692 | - function setupTinyMceEventHandlers( editor ) { | |
| 6693 | - editor.on( 'Change', function() { | |
| 6694 | - handleTinyMceChange( editor ); | |
| 6695 | - }); | |
| 6696 | - } | |
| 6697 | - | |
| 6698 | - function handleTinyMceChange( editor ) { | |
| 6699 | - if ( ! isTinyMceActive() || tinyMCE.activeEditor.isHidden() ) { | |
| 6700 | - return; | |
| 6701 | - } | |
| 6702 | - | |
| 6703 | - editor.targetElm.value = editor.getContent(); | |
| 6704 | - jQuery( editor.targetElm ).trigger( 'change' ); | |
| 6705 | - } | |
| 6706 | - | |
| 6707 | - function isTinyMceActive() { | |
| 6708 | - var activeSettings, wrapper; | |
| 6709 | - | |
| 6710 | - activeSettings = document.querySelector( '.frm-single-settings:not(.frm_hidden)' ); | |
| 6711 | - if ( ! activeSettings ) { | |
| 6712 | - return false; | |
| 6713 | - } | |
| 6714 | - | |
| 6715 | - wrapper = activeSettings.querySelector( '.wp-editor-wrap' ); | |
| 6716 | - return null !== wrapper && wrapper.classList.contains( 'tmce-active' ); | |
| 6717 | - } | |
| 6718 | - | |
| 6719 | - /** | |
| 6720 | - * Move the settings to the sidebar the first time they are changed or selected. | |
| 6721 | - * Keep the end marker at the end of the form. | |
| 6722 | - */ | |
| 6723 | - function moveFieldSettings( singleField ) { | |
| 6724 | - if ( singleField === null ) { | |
| 6725 | - // The field may have not been loaded yet via ajax. | |
| 6726 | - return; | |
| 6727 | - } | |
| 6728 | - | |
| 6729 | - var classes = singleField.parentElement.classList; | |
| 6730 | - if ( classes.contains( 'frm_field_box' ) || classes.contains( 'divider_section_only' ) ) { | |
| 6731 | - var endMarker = document.getElementById( 'frm-end-form-marker' ); | |
| 6732 | - builderForm.insertBefore( singleField, endMarker ); | |
| 6733 | - } | |
| 6734 | - } | |
| 6735 | - | |
| 6736 | - function showEmailRow() { | |
| 6737 | - /*jshint validthis:true */ | |
| 6738 | - var actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ); | |
| 6739 | - var rowType = this.getAttribute( 'data-emailrow' ); | |
| 6740 | - | |
| 6741 | - jQuery( '#frm_form_action_' + actionKey + ' .frm_' + rowType + '_row' ).fadeIn( 'slow' ); | |
| 6742 | - jQuery( this ).fadeOut( 'slow' ); | |
| 6743 | - } | |
| 6744 | - | |
| 6745 | - function hideEmailRow() { | |
| 6746 | - /*jshint validthis:true */ | |
| 6747 | - var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ), | |
| 6748 | - rowType = this.getAttribute( 'data-emailrow' ), | |
| 6749 | - emailRowSelector = '.frm_' + rowType + '_row', | |
| 6750 | - emailButtonSelector = '.frm_' + rowType + '_button'; | |
| 6751 | - | |
| 6752 | - jQuery( actionBox ).find( emailButtonSelector ).fadeIn( 'slow' ); | |
| 6753 | - jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow', function() { | |
| 6754 | - jQuery( actionBox ).find( emailRowSelector + ' input' ).val( '' ); | |
| 6755 | - }); | |
| 6756 | - } | |
| 6757 | - | |
| 6758 | - function showEmailWarning() { | |
| 6759 | - /*jshint validthis:true */ | |
| 6760 | - var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ), | |
| 6761 | - emailRowSelector = '.frm_from_to_match_row', | |
| 6762 | - fromVal = actionBox.find( 'input[name$="[post_content][from]"]' ).val(), | |
| 6763 | - toVal = actionBox.find( 'input[name$="[post_content][email_to]"]' ).val(); | |
| 6764 | - | |
| 6765 | - if ( fromVal === toVal ) { | |
| 6766 | - jQuery( actionBox ).find( emailRowSelector ).fadeIn( 'slow' ); | |
| 6767 | - } else { | |
| 6768 | - jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow' ); | |
| 6769 | - } | |
| 6770 | - } | |
| 6771 | - | |
| 6772 | - function checkActiveAction( type ) { | |
| 6773 | - const actionTriggers = document.querySelectorAll( '.frm_' + type + '_action' ); | |
| 6774 | - | |
| 6775 | - if ( isAtLimitForActionType( type ) ) { | |
| 6776 | - const addAlreadyUsedClass = getLimitForActionType( type ) > 0; | |
| 6777 | - markActionTriggersInactive( actionTriggers, addAlreadyUsedClass ); | |
| 6778 | - return; | |
| 6779 | - } | |
| 6780 | - | |
| 6781 | - markActionTriggersActive( actionTriggers ); | |
| 6782 | - } | |
| 6783 | - | |
| 6784 | - function markActionTriggersActive( triggers ) { | |
| 6785 | - triggers.forEach( | |
| 6786 | - trigger => { | |
| 6787 | - if ( trigger.querySelector( '.frm_show_upgrade' ) ) { | |
| 6788 | - // Prevent disabled action becoming active. | |
| 6789 | - return; | |
| 6790 | - } | |
| 6791 | - | |
| 6792 | - trigger.classList.remove( 'frm_inactive_action', 'frm_already_used' ); | |
| 6793 | - trigger.classList.add( 'frm_active_action' ); | |
| 6794 | - } | |
| 6795 | - ); | |
| 6796 | - } | |
| 6797 | - | |
| 6798 | - function markActionTriggersInactive( triggers, addAlreadyUsedClass ) { | |
| 6799 | - triggers.forEach( | |
| 6800 | - trigger => { | |
| 6801 | - trigger.classList.remove( 'frm_active_action' ); | |
| 6802 | - trigger.classList.add( 'frm_inactive_action' ); | |
| 6803 | - if ( addAlreadyUsedClass ) { | |
| 6804 | - trigger.classList.add( 'frm_already_used' ); | |
| 6805 | - } | |
| 6806 | - } | |
| 6807 | - ); | |
| 6808 | - } | |
| 6809 | - | |
| 6810 | - function isAtLimitForActionType( type ) { | |
| 6811 | - let atLimit = getNumberOfActionsForType( type ) >= getLimitForActionType( type ); | |
| 6812 | - | |
| 6813 | - const hookName = 'frm_action_at_limit'; | |
| 6814 | - const hookArgs = { type }; | |
| 6815 | - atLimit = wp.hooks.applyFilters( hookName, atLimit, hookArgs ); | |
| 6816 | - | |
| 6817 | - return atLimit; | |
| 6818 | - } | |
| 6819 | - | |
| 6820 | - function getLimitForActionType( type ) { | |
| 6821 | - return parseInt( jQuery( '.frm_' + type + '_action' ).data( 'limit' ), 10 ); | |
| 6822 | - } | |
| 6823 | - | |
| 6824 | - function getNumberOfActionsForType( type ) { | |
| 6825 | - return jQuery( '.frm_single_' + type + '_settings' ).length; | |
| 6826 | - } | |
| 6827 | - | |
| 6828 | - function onlyOneActionMessage() { | |
| 6829 | - infoModal( frm_admin_js.only_one_action ); // eslint-disable-line camelcase | |
| 6830 | - } | |
| 6831 | - | |
| 6832 | - function addFormLogicRow() { | |
| 6833 | - /*jshint validthis:true */ | |
| 6834 | - var id = jQuery( this ).data( 'emailkey' ), | |
| 6835 | - type = jQuery( this ).closest( '.frm_form_action_settings' ).find( '.frm_action_name' ).val(), | |
| 6836 | - formId = document.getElementById( 'form_id' ).value, | |
| 6837 | - logicRows = document.getElementById( 'frm_form_action_' + id ).querySelectorAll( '.frm_logic_row' ); | |
| 6838 | - jQuery.ajax({ | |
| 6839 | - type: 'POST', url: ajaxurl, | |
| 6840 | - data: { | |
| 6841 | - action: 'frm_add_form_logic_row', | |
| 6842 | - email_id: id, | |
| 6843 | - form_id: formId, | |
| 6844 | - meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ), | |
| 6845 | - type: type, | |
| 6846 | - nonce: frmGlobal.nonce | |
| 6847 | - }, | |
| 6848 | - success: function( html ) { | |
| 6849 | - jQuery( document.getElementById( 'logic_link_' + id ) ).fadeOut( 'slow', function() { | |
| 6850 | - var $logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) ); | |
| 6851 | - $logicRow.append( html ); | |
| 6852 | - $logicRow.parent( '.frm_logic_rows' ).fadeIn( 'slow' ); | |
| 6853 | - }); | |
| 6854 | - } | |
| 6855 | - }); | |
| 6856 | - return false; | |
| 6857 | - } | |
| 6858 | - | |
| 6859 | - function toggleSubmitLogic() { | |
| 6860 | - /*jshint validthis:true */ | |
| 6861 | - if ( this.checked ) { | |
| 6862 | - addSubmitLogic(); | |
| 6863 | - } else { | |
| 6864 | - jQuery( '.frm_logic_row_submit' ).remove(); | |
| 6865 | - document.getElementById( 'frm_submit_logic_rows' ).style.display = 'none'; | |
| 6866 | - } | |
| 6867 | - } | |
| 6868 | - | |
| 6869 | - /** | |
| 6870 | - * Adds submit button Conditional Logic row and reveals submit button Conditional Logic | |
| 6871 | - * | |
| 6872 | - * @returns {boolean} | |
| 6873 | - */ | |
| 6874 | - function addSubmitLogic() { | |
| 6875 | - /*jshint validthis:true */ | |
| 6876 | - var formId = thisFormId, | |
| 6877 | - logicRows = document.getElementById( 'frm_submit_logic_row' ).querySelectorAll( '.frm_logic_row' ); | |
| 6878 | - jQuery.ajax({ | |
| 6879 | - type: 'POST', | |
| 6880 | - url: ajaxurl, | |
| 6881 | - data: { | |
| 6882 | - action: 'frm_add_submit_logic_row', | |
| 6883 | - form_id: formId, | |
| 6884 | - meta_name: getNewRowId( logicRows, 'frm_logic_submit_' ), | |
| 6885 | - nonce: frmGlobal.nonce | |
| 6886 | - }, | |
| 6887 | - success: function( html ) { | |
| 6888 | - var $logicRow = jQuery( document.getElementById( 'frm_submit_logic_row' ) ); | |
| 6889 | - $logicRow.append( html ); | |
| 6890 | - $logicRow.parent( '.frm_submit_logic_rows' ).fadeIn( 'slow' ); | |
| 6891 | - } | |
| 6892 | - }); | |
| 6893 | - return false; | |
| 6894 | - } | |
| 6895 | - | |
| 6896 | - /** | |
| 6897 | - * When the user selects a field for a submit condition, update corresponding options field accordingly. | |
| 6898 | - */ | |
| 6899 | - function addSubmitLogicOpts() { | |
| 6900 | - var fieldOpt = jQuery( this ); | |
| 6901 | - var fieldId = fieldOpt.find( ':selected' ).val(); | |
| 6902 | - | |
| 6903 | - if ( fieldId ) { | |
| 6904 | - var row = fieldOpt.data( 'row' ); | |
| 6905 | - frmGetFieldValues( fieldId, 'submit', row, '', 'options[submit_conditions][hide_opt][]' ); | |
| 6906 | - } | |
| 6907 | - } | |
| 6908 | - | |
| 6909 | - function formatEmailSetting() { | |
| 6910 | - /*jshint validthis:true */ | |
| 6911 | - /*var val = jQuery( this ).val(); | |
| 6912 | - var email = val.match( /(\s[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi ); | |
| 6913 | - if(email !== null && email.length) { | |
| 6914 | - //has email | |
| 6915 | - //TODO: add < > if they aren't there | |
| 6916 | - }*/ | |
| 6917 | - } | |
| 6918 | - | |
| 6919 | - function checkDupPost() { | |
| 6920 | - /*jshint validthis:true */ | |
| 6921 | - var postField = jQuery( 'select.frm_single_post_field' ); | |
| 6922 | - postField.css( 'border-color', '' ); | |
| 6923 | - var $t = this; | |
| 6924 | - var v = jQuery( $t ).val(); | |
| 6925 | - if ( v === '' || v === 'checkbox' ) { | |
| 6926 | - return false; | |
| 6927 | - } | |
| 6928 | - postField.each( function() { | |
| 6929 | - if ( jQuery( this ).val() === v && this.name !== $t.name ) { | |
| 6930 | - this.style.borderColor = 'red'; | |
| 6931 | - jQuery( $t ).val( '' ); | |
| 6932 | - infoModal( frm_admin_js.field_already_used ); // eslint-disable-line camelcase | |
| 6933 | - return false; | |
| 6934 | - } | |
| 6935 | - }); | |
| 6936 | - } | |
| 6937 | - | |
| 6938 | - function togglePostContent() { | |
| 6939 | - /*jshint validthis:true */ | |
| 6940 | - var v = jQuery( this ).val(); | |
| 6941 | - if ( '' === v ) { | |
| 6942 | - jQuery( '.frm_post_content_opt, select.frm_dyncontent_opt' ).hide().val( '' ); | |
| 6943 | - jQuery( '.frm_dyncontent_opt' ).hide(); | |
| 6944 | - } else if ( 'post_content' === v ) { | |
| 6945 | - jQuery( '.frm_post_content_opt' ).show(); | |
| 6946 | - jQuery( '.frm_dyncontent_opt' ).hide(); | |
| 6947 | - jQuery( 'select.frm_dyncontent_opt' ).val( '' ); | |
| 6948 | - } else { | |
| 6949 | - jQuery( '.frm_post_content_opt' ).hide().val( '' ); | |
| 6950 | - jQuery( 'select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt' ).show(); | |
| 6951 | - } | |
| 6952 | - } | |
| 6953 | - | |
| 6954 | - function fillDyncontent() { | |
| 6955 | - /*jshint validthis:true */ | |
| 6956 | - var v = jQuery( this ).val(); | |
| 6957 | - var $dyn = jQuery( document.getElementById( 'frm_dyncontent' ) ); | |
| 6958 | - if ( '' === v || 'new' === v ) { | |
| 6959 | - $dyn.val( '' ); | |
| 6960 | - jQuery( '.frm_dyncontent_opt' ).show(); | |
| 6961 | - } else { | |
| 6962 | - jQuery.ajax({ | |
| 6963 | - type: 'POST', url: ajaxurl, | |
| 6964 | - data: {action: 'frm_display_get_content', id: v, nonce: frmGlobal.nonce}, | |
| 6965 | - success: function( val ) { | |
| 6966 | - $dyn.val( val ); | |
| 6967 | - jQuery( '.frm_dyncontent_opt' ).show(); | |
| 6968 | - } | |
| 6969 | - }); | |
| 6970 | - } | |
| 6971 | - } | |
| 6972 | - | |
| 6973 | - function switchPostType() { | |
| 6974 | - /*jshint validthis:true */ | |
| 6975 | - // update all rows of categories/taxonomies | |
| 6976 | - var curSelect, newSelect, | |
| 6977 | - catRows = document.getElementById( 'frm_posttax_rows' ).childNodes, | |
| 6978 | - postParentField = document.querySelector( '.frm_post_parent_field' ), | |
| 6979 | - postMenuOrderField = document.querySelector( '.frm_post_menu_order_field' ), | |
| 6980 | - postType = this.value; | |
| 6981 | - | |
| 6982 | - // Get new category/taxonomy options | |
| 6983 | - jQuery.ajax({ | |
| 6984 | - type: 'POST', | |
| 6985 | - url: ajaxurl, | |
| 6986 | - data: { | |
| 6987 | - action: 'frm_replace_posttax_options', | |
| 6988 | - post_type: postType, | |
| 6989 | - nonce: frmGlobal.nonce | |
| 6990 | - }, | |
| 6991 | - success: function( html ) { | |
| 6992 | - | |
| 6993 | - // Loop through each category row, and replace the first dropdown | |
| 6994 | - for ( i = 0; i < catRows.length; i++ ) { | |
| 6995 | - // Check if current element is a div | |
| 6996 | - if ( catRows[i].tagName !== 'DIV' ) { | |
| 6997 | - continue; | |
| 6998 | - } | |
| 6999 | - | |
| 7000 | - // Get current category select | |
| 7001 | - curSelect = catRows[i].getElementsByTagName( 'select' )[0]; | |
| 7002 | - | |
| 7003 | - // Set up new select | |
| 7004 | - newSelect = document.createElement( 'select' ); | |
| 7005 | - newSelect.innerHTML = html; | |
| 7006 | - newSelect.className = curSelect.className; | |
| 7007 | - newSelect.name = curSelect.name; | |
| 7008 | - | |
| 7009 | - // Replace the old select with the new select | |
| 7010 | - catRows[i].replaceChild( newSelect, curSelect ); | |
| 7011 | - } | |
| 7012 | - } | |
| 7013 | - }); | |
| 7014 | - | |
| 7015 | - // Get new post parent option. | |
| 7016 | - if ( postParentField ) { | |
| 7017 | - getActionOption( | |
| 7018 | - postParentField, | |
| 7019 | - postType, | |
| 7020 | - 'frm_get_post_parent_option', | |
| 7021 | - function( response, optName ) { | |
| 7022 | - // The replaced string is declared in FrmProFormActionController::ajax_get_post_menu_order_option() in the pro version. | |
| 7023 | - postParentField.querySelector( '.frm_post_parent_opt_wrapper' ).innerHTML = response.replaceAll( 'REPLACETHISNAME', optName ); | |
| 7024 | - frmDom.autocomplete.initAutocomplete( 'page', postParentField ); | |
| 7025 | - } | |
| 7026 | - ); | |
| 7027 | - } | |
| 7028 | - | |
| 7029 | - if ( postMenuOrderField ) { | |
| 7030 | - getActionOption( postMenuOrderField, postType, 'frm_should_use_post_menu_order_option' ); | |
| 7031 | - } | |
| 7032 | - } | |
| 7033 | - | |
| 7034 | - function getActionOption( field, postType, action, successHandler ) { | |
| 7035 | - const opt = field.querySelector( '.frm_autocomplete_value_input' ) || field.querySelector( 'select' ), | |
| 7036 | - optName = opt.getAttribute( 'name' ); | |
| 7037 | - | |
| 7038 | - jQuery.ajax({ | |
| 7039 | - url: ajaxurl, | |
| 7040 | - method: 'POST', | |
| 7041 | - data: { | |
| 7042 | - action: action, | |
| 7043 | - post_type: postType, | |
| 7044 | - _wpnonce: frmGlobal.nonce | |
| 7045 | - }, | |
| 7046 | - success: response => { | |
| 7047 | - if ( 'string' !== typeof response ) { | |
| 7048 | - console.error( response ); | |
| 7049 | - return; | |
| 7050 | - } | |
| 7051 | - | |
| 7052 | - if ( '0' === response ) { | |
| 7053 | - // This post type does not support this field. | |
| 7054 | - field.classList.add( 'frm_hidden' ); | |
| 7055 | - field.value = ''; | |
| 7056 | - return; | |
| 7057 | - } | |
| 7058 | - | |
| 7059 | - field.classList.remove( 'frm_hidden' ); | |
| 7060 | - | |
| 7061 | - if ( 'function' === typeof successHandler ) { | |
| 7062 | - successHandler( response, optName ); | |
| 7063 | - } | |
| 7064 | - }, | |
| 7065 | - error: response => console.error( response ) | |
| 7066 | - }); | |
| 7067 | - } | |
| 7068 | - | |
| 7069 | - function addPosttaxRow() { | |
| 7070 | - /*jshint validthis:true */ | |
| 7071 | - addPostRow( 'tax', this ); | |
| 7072 | - } | |
| 7073 | - | |
| 7074 | - function addPostmetaRow() { | |
| 7075 | - /*jshint validthis:true */ | |
| 7076 | - addPostRow( 'meta', this ); | |
| 7077 | - } | |
| 7078 | - | |
| 7079 | - function addPostRow( type, button ) { | |
| 7080 | - var name, | |
| 7081 | - id = jQuery( 'input[name="id"]' ).val(), | |
| 7082 | - settings = jQuery( button ).closest( '.frm_form_action_settings' ), | |
| 7083 | - key = settings.data( 'actionkey' ), | |
| 7084 | - postType = settings.find( '.frm_post_type' ).val(), | |
| 7085 | - metaName = 0, | |
| 7086 | - postTypeRows = document.querySelectorAll( '.frm_post' + type + '_row' ); | |
| 7087 | - | |
| 7088 | - if ( postTypeRows.length ) { | |
| 7089 | - name = postTypeRows[ postTypeRows.length - 1 ].id.replace( 'frm_post' + type + '_', '' ); | |
| 7090 | - if ( isNumeric( name ) ) { | |
| 7091 | - metaName = 1 + parseInt( name, 10 ); | |
| 7092 | - } else { | |
| 7093 | - metaName = 1; | |
| 7094 | - } | |
| 7095 | - } | |
| 7096 | - | |
| 7097 | - jQuery.ajax({ | |
| 7098 | - type: 'POST', url: ajaxurl, | |
| 7099 | - data: { | |
| 7100 | - action: 'frm_add_post' + type + '_row', | |
| 7101 | - form_id: id, | |
| 7102 | - meta_name: metaName, | |
| 7103 | - tax_key: metaName, | |
| 7104 | - post_type: postType, | |
| 7105 | - action_key: key, | |
| 7106 | - nonce: frmGlobal.nonce | |
| 7107 | - }, | |
| 7108 | - success: function( html ) { | |
| 7109 | - var cfOpts, optIndex; | |
| 7110 | - jQuery( document.getElementById( 'frm_post' + type + '_rows' ) ).append( html ); | |
| 7111 | - jQuery( '.frm_add_post' + type + '_row.button' ).hide(); | |
| 7112 | - | |
| 7113 | - if ( type === 'meta' ) { | |
| 7114 | - jQuery( '.frm_name_value' ).show(); | |
| 7115 | - cfOpts = document.querySelectorAll( '.frm_toggle_cf_opts' ); | |
| 7116 | - for ( optIndex = 0; optIndex < cfOpts.length - 1; ++optIndex ) { | |
| 7117 | - cfOpts[ optIndex ].style.display = 'none'; | |
| 7118 | - } | |
| 7119 | - } else if ( type === 'tax' ) { | |
| 7120 | - jQuery( '.frm_posttax_labels' ).show(); | |
| 7121 | - } | |
| 7122 | - } | |
| 7123 | - }); | |
| 7124 | - } | |
| 7125 | - | |
| 7126 | - function isNumeric( value ) { | |
| 7127 | - return ! isNaN( parseFloat( value ) ) && isFinite( value ); | |
| 7128 | - } | |
| 7129 | - | |
| 7130 | - function getMetaValue( id, metaName ) { | |
| 7131 | - var newMeta = metaName; | |
| 7132 | - if ( jQuery( document.getElementById( id + metaName ) ).length > 0 ) { | |
| 7133 | - newMeta = getMetaValue( id, metaName + 1 ); | |
| 7134 | - } | |
| 7135 | - return newMeta; | |
| 7136 | - } | |
| 7137 | - | |
| 7138 | - function changePosttaxRow() { | |
| 7139 | - /*jshint validthis:true */ | |
| 7140 | - if ( ! jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).length ) { | |
| 7141 | - return; | |
| 7142 | - } | |
| 7143 | - | |
| 7144 | - jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).html( '<div class="spinner frm_spinner" style="display:block"></div>' ); | |
| 7145 | - | |
| 7146 | - var postType = jQuery( this ).closest( '.frm_form_action_settings' ).find( 'select[name$="[post_content][post_type]"]' ).val(), | |
| 7147 | - actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ), | |
| 7148 | - taxKey = jQuery( this ).closest( '.frm_posttax_row' ).attr( 'id' ).replace( 'frm_posttax_', '' ), | |
| 7149 | - metaName = jQuery( this ).val(), | |
| 7150 | - showExclude = jQuery( document.getElementById( taxKey + '_show_exclude' ) ).is( ':checked' ) ? 1 : 0, | |
| 7151 | - fieldId = jQuery( 'select[name$="[post_category][' + taxKey + '][field_id]"]' ).val(), | |
| 7152 | - id = jQuery( 'input[name="id"]' ).val(); | |
| 7153 | - | |
| 7154 | - jQuery.ajax({ | |
| 7155 | - type: 'POST', | |
| 7156 | - url: ajaxurl, | |
| 7157 | - data: { | |
| 7158 | - action: 'frm_add_posttax_row', | |
| 7159 | - form_id: id, | |
| 7160 | - post_type: postType, | |
| 7161 | - tax_key: taxKey, | |
| 7162 | - action_key: actionKey, | |
| 7163 | - meta_name: metaName, | |
| 7164 | - field_id: fieldId, | |
| 7165 | - show_exclude: showExclude, | |
| 7166 | - nonce: frmGlobal.nonce | |
| 7167 | - }, | |
| 7168 | - success: function( html ) { | |
| 7169 | - var $tax = jQuery( document.getElementById( 'frm_posttax_' + taxKey ) ); | |
| 7170 | - $tax.replaceWith( html ); | |
| 7171 | - } | |
| 7172 | - }); | |
| 7173 | - } | |
| 7174 | - | |
| 7175 | - function toggleCfOpts() { | |
| 7176 | - /*jshint validthis:true */ | |
| 7177 | - var row = jQuery( this ).closest( '.frm_postmeta_row' ); | |
| 7178 | - var cancel = row.find( '.frm_cancelnew' ); | |
| 7179 | - var select = row.find( '.frm_enternew' ); | |
| 7180 | - if ( row.find( 'select.frm_cancelnew' ).is( ':visible' ) ) { | |
| 7181 | - cancel.hide(); | |
| 7182 | - select.show(); | |
| 7183 | - } else { | |
| 7184 | - cancel.show(); | |
| 7185 | - select.hide(); | |
| 7186 | - } | |
| 7187 | - | |
| 7188 | - row.find( 'input.frm_enternew, select.frm_cancelnew' ).val( '' ); | |
| 7189 | - return false; | |
| 7190 | - } | |
| 7191 | - | |
| 7192 | - function toggleFormOpts() { | |
| 7193 | - /*jshint validthis:true */ | |
| 7194 | - var changedOpt = jQuery( this ); | |
| 7195 | - var val = changedOpt.val(); | |
| 7196 | - if ( changedOpt.attr( 'type' ) === 'checkbox' ) { | |
| 7197 | - if ( this.checked === false ) { | |
| 7198 | - val = ''; | |
| 7199 | - } | |
| 7200 | - } | |
| 7201 | - | |
| 7202 | - var toggleClass = changedOpt.data( 'toggleclass' ); | |
| 7203 | - if ( val === '' ) { | |
| 7204 | - jQuery( '.' + toggleClass ).hide(); | |
| 7205 | - } else { | |
| 7206 | - jQuery( '.' + toggleClass ).show(); | |
| 7207 | - jQuery( '.hide_' + toggleClass + '_' + val ).hide(); | |
| 7208 | - } | |
| 7209 | - } | |
| 7210 | - | |
| 7211 | - function submitSettings() { | |
| 7212 | - /*jshint validthis:true */ | |
| 7213 | - preFormSave( this ); | |
| 7214 | - triggerSubmit( document.querySelector( '.frm_form_settings' ) ); | |
| 7215 | - } | |
| 7216 | - | |
| 7217 | - /* View Functions */ | |
| 7218 | - function showCount() { | |
| 7219 | - /*jshint validthis:true */ | |
| 7220 | - var value = jQuery( this ).val(); | |
| 7221 | - | |
| 7222 | - var $cont = document.getElementById( 'date_select_container' ); | |
| 7223 | - var tab = document.getElementById( 'frm_listing_tab' ); | |
| 7224 | - var label = tab.getAttribute( 'data-label' ); | |
| 7225 | - if ( value === 'calendar' ) { | |
| 7226 | - jQuery( '.hide_dyncontent, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 7227 | - jQuery( '.limit_container' ).addClass( 'frm_hidden' ); | |
| 7228 | - $cont.style.display = 'block'; | |
| 7229 | - } else if ( value === 'dynamic' ) { | |
| 7230 | - jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 7231 | - } else if ( value === 'one' ) { | |
| 7232 | - label = tab.getAttribute( 'data-one' ); | |
| 7233 | - jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).addClass( 'frm_hidden' ); | |
| 7234 | - } else { | |
| 7235 | - jQuery( '.hide_dyncontent' ).addClass( 'frm_hidden' ); | |
| 7236 | - jQuery( '.limit_container, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 7237 | - } | |
| 7238 | - | |
| 7239 | - if ( value !== 'calendar' ) { | |
| 7240 | - $cont.style.display = 'none'; | |
| 7241 | - } | |
| 7242 | - tab.innerHTML = label; | |
| 7243 | - } | |
| 7244 | - | |
| 7245 | - function displayFormSelected() { | |
| 7246 | - /*jshint validthis:true */ | |
| 7247 | - var formId = jQuery( this ).val(); | |
| 7248 | - thisFormId = formId; // set the global form id | |
| 7249 | - if ( formId === '' ) { | |
| 7250 | - return; | |
| 7251 | - } | |
| 7252 | - | |
| 7253 | - jQuery.ajax({ | |
| 7254 | - type: 'POST', | |
| 7255 | - url: ajaxurl, | |
| 7256 | - data: { | |
| 7257 | - action: 'frm_get_cd_tags_box', | |
| 7258 | - form_id: formId, | |
| 7259 | - nonce: frmGlobal.nonce | |
| 7260 | - }, | |
| 7261 | - success: function( html ) { | |
| 7262 | - jQuery( '#frm_adv_info .categorydiv' ).html( html ); | |
| 7263 | - } | |
| 7264 | - }); | |
| 7265 | - | |
| 7266 | - jQuery.ajax({ | |
| 7267 | - type: 'POST', | |
| 7268 | - url: ajaxurl, | |
| 7269 | - data: { | |
| 7270 | - action: 'frm_get_date_field_select', | |
| 7271 | - form_id: formId, | |
| 7272 | - nonce: frmGlobal.nonce | |
| 7273 | - }, | |
| 7274 | - success: function( html ) { | |
| 7275 | - jQuery( document.getElementById( 'date_select_container' ) ).html( html ); | |
| 7276 | - } | |
| 7277 | - }); | |
| 7278 | - } | |
| 7279 | - | |
| 7280 | - function clickTabsAfterAjax() { | |
| 7281 | - /*jshint validthis:true */ | |
| 7282 | - var t = jQuery( this ).attr( 'href' ); | |
| 7283 | - jQuery( this ).parent().addClass( 'tabs' ).siblings( 'li' ).removeClass( 'tabs' ); | |
| 7284 | - jQuery( t ).show().siblings( '.tabs-panel' ).hide(); | |
| 7285 | - return false; | |
| 7286 | - } | |
| 7287 | - | |
| 7288 | - function clickContentTab() { | |
| 7289 | - /*jshint validthis:true */ | |
| 7290 | - link = jQuery( this ); | |
| 7291 | - var t = link.attr( 'href' ); | |
| 7292 | - if ( typeof t === 'undefined' ) { | |
| 7293 | - return false; | |
| 7294 | - } | |
| 7295 | - | |
| 7296 | - var c = t.replace( '#', '.' ); | |
| 7297 | - link.closest( '.nav-tab-wrapper' ).find( 'a' ).removeClass( 'nav-tab-active' ); | |
| 7298 | - link.addClass( 'nav-tab-active' ); | |
| 7299 | - jQuery( '.nav-menu-content' ).not( t ).not( c ).hide(); | |
| 7300 | - jQuery( t + ',' + c ).show(); | |
| 7301 | - | |
| 7302 | - return false; | |
| 7303 | - } | |
| 7304 | - | |
| 7305 | - function addOrderRow() { | |
| 7306 | - var logicRows = document.getElementById( 'frm_order_options' ).querySelectorAll( '.frm_logic_rows div' ); | |
| 7307 | - jQuery.ajax({ | |
| 7308 | - type: 'POST', | |
| 7309 | - url: ajaxurl, | |
| 7310 | - data: { | |
| 7311 | - action: 'frm_add_order_row', | |
| 7312 | - form_id: thisFormId, | |
| 7313 | - order_key: getNewRowId( logicRows, 'frm_order_field_', 1 ), | |
| 7314 | - nonce: frmGlobal.nonce | |
| 7315 | - }, | |
| 7316 | - success: function( html ) { | |
| 7317 | - jQuery( '#frm_order_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_order_row' ).hide(); | |
| 7318 | - } | |
| 7319 | - }); | |
| 7320 | - } | |
| 7321 | - | |
| 7322 | - function addWhereRow() { | |
| 7323 | - var rowDivs = document.getElementById( 'frm_where_options' ).querySelectorAll( '.frm_logic_rows div' ); | |
| 7324 | - jQuery.ajax({ | |
| 7325 | - type: 'POST', | |
| 7326 | - url: ajaxurl, | |
| 7327 | - data: { | |
| 7328 | - action: 'frm_add_where_row', | |
| 7329 | - form_id: thisFormId, | |
| 7330 | - where_key: getNewRowId( rowDivs, 'frm_where_field_', 1 ), | |
| 7331 | - nonce: frmGlobal.nonce | |
| 7332 | - }, | |
| 7333 | - success: function( html ) { | |
| 7334 | - jQuery( '#frm_where_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_where_row' ).hide(); | |
| 7335 | - } | |
| 7336 | - }); | |
| 7337 | - } | |
| 7338 | - | |
| 7339 | - function insertWhereOptions() { | |
| 7340 | - /*jshint validthis:true */ | |
| 7341 | - var value = this.value, | |
| 7342 | - whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' ); | |
| 7343 | - | |
| 7344 | - jQuery.ajax({ | |
| 7345 | - type: 'POST', | |
| 7346 | - url: ajaxurl, | |
| 7347 | - data: { | |
| 7348 | - action: 'frm_add_where_options', | |
| 7349 | - where_key: whereKey, | |
| 7350 | - field_id: value, | |
| 7351 | - nonce: frmGlobal.nonce | |
| 7352 | - }, | |
| 7353 | - success: function( html ) { | |
| 7354 | - jQuery( document.getElementById( 'where_field_options_' + whereKey ) ).html( html ); | |
| 7355 | - } | |
| 7356 | - }); | |
| 7357 | - } | |
| 7358 | - | |
| 7359 | - function hideWhereOptions() { | |
| 7360 | - /*jshint validthis:true */ | |
| 7361 | - var value = this.value, | |
| 7362 | - whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' ); | |
| 7363 | - | |
| 7364 | - if ( value === 'group_by' || value === 'group_by_newest' ) { | |
| 7365 | - document.getElementById( 'where_field_options_' + whereKey ).style.display = 'none'; | |
| 7366 | - } else { | |
| 7367 | - document.getElementById( 'where_field_options_' + whereKey ).style.display = 'inline-block'; | |
| 7368 | - } | |
| 7369 | - } | |
| 7370 | - | |
| 7371 | - function setDefaultPostStatus() { | |
| 7372 | - var urlQuery = window.location.search.substring( 1 ); | |
| 7373 | - if ( urlQuery.indexOf( 'action=edit' ) === -1 ) { | |
| 7374 | - document.getElementById( 'post-visibility-display' ).textContent = frm_admin_js.private_label; // eslint-disable-line camelcase | |
| 7375 | - document.getElementById( 'hidden-post-visibility' ).value = 'private'; | |
| 7376 | - document.getElementById( 'visibility-radio-private' ).checked = true; | |
| 7377 | - } | |
| 7378 | - } | |
| 7379 | - | |
| 7380 | - /* Customization Panel */ | |
| 7381 | - function insertCode( e ) { | |
| 7382 | - /*jshint validthis:true */ | |
| 7383 | - e.preventDefault(); | |
| 7384 | - insertFieldCode( jQuery( this ), this.getAttribute( 'data-code' ) ); | |
| 7385 | - return false; | |
| 7386 | - } | |
| 7387 | - | |
| 7388 | - function insertFieldCode( element, variable ) { | |
| 7389 | - var rich = false, | |
| 7390 | - elementId = element; | |
| 7391 | - if ( typeof element === 'object' ) { | |
| 7392 | - if ( element.hasClass( 'frm_noallow' ) ) { | |
| 7393 | - return; | |
| 7394 | - } | |
| 7395 | - | |
| 7396 | - elementId = jQuery( element ).closest( '[data-fills]' ).attr( 'data-fills' ); | |
| 7397 | - if ( typeof elementId === 'undefined' ) { | |
| 7398 | - elementId = element.closest( 'div' ).attr( 'class' ); | |
| 7399 | - if ( typeof elementId !== 'undefined' ) { | |
| 7400 | - elementId = elementId.split( ' ' )[1]; | |
| 7401 | - } | |
| 7402 | - } | |
| 7403 | - } | |
| 7404 | - | |
| 7405 | - if ( typeof elementId === 'undefined' ) { | |
| 7406 | - var active = document.activeElement; | |
| 7407 | - if ( active.type === 'search' ) { | |
| 7408 | - // If the search field has focus, find the correct field. | |
| 7409 | - elementId = active.id.replace( '-search-input', '' ); | |
| 7410 | - if ( elementId.match( /\d/gi ) === null ) { | |
| 7411 | - active = jQuery( '.frm-single-settings:visible .' + elementId ); | |
| 7412 | - elementId = active.attr( 'id' ); | |
| 7413 | - } | |
| 7414 | - } else { | |
| 7415 | - elementId = active.id; | |
| 7416 | - } | |
| 7417 | - } | |
| 7418 | - | |
| 7419 | - if ( elementId ) { | |
| 7420 | - rich = jQuery( '#wp-' + elementId + '-wrap.wp-editor-wrap' ).length > 0; | |
| 7421 | - } | |
| 7422 | - | |
| 7423 | - var contentBox = jQuery( document.getElementById( elementId ) ); | |
| 7424 | - if ( typeof element.attr( 'data-shortcode' ) === 'undefined' && ( ! contentBox.length || typeof contentBox.attr( 'data-shortcode' ) === 'undefined' ) ) { | |
| 7425 | - // this helps to exclude those that don't want shortcode-like inserted content e.g. frm-pro's summary field | |
| 7426 | - var doShortcode = element.parents( 'ul.frm_code_list' ).attr( 'data-shortcode' ); | |
| 7427 | - if ( doShortcode === 'undefined' || doShortcode !== 'no' ) { | |
| 7428 | - variable = '[' + variable + ']'; | |
| 7429 | - } | |
| 7430 | - } | |
| 7431 | - | |
| 7432 | - if ( rich ) { | |
| 7433 | - wpActiveEditor = elementId; | |
| 7434 | - } | |
| 7435 | - | |
| 7436 | - if ( ! contentBox.length ) { | |
| 7437 | - return false; | |
| 7438 | - } | |
| 7439 | - | |
| 7440 | - if ( variable === '[default-html]' || variable === '[default-plain]' ) { | |
| 7441 | - var p = 0; | |
| 7442 | - if ( variable === '[default-plain]' ) { | |
| 7443 | - p = 1; | |
| 7444 | - } | |
| 7445 | - jQuery.ajax({ | |
| 7446 | - type: 'POST', url: ajaxurl, | |
| 7447 | - data: { | |
| 7448 | - action: 'frm_get_default_html', | |
| 7449 | - form_id: jQuery( 'input[name="id"]' ).val(), | |
| 7450 | - plain_text: p, | |
| 7451 | - nonce: frmGlobal.nonce | |
| 7452 | - }, | |
| 7453 | - elementId: elementId, | |
| 7454 | - success: function( msg ) { | |
| 7455 | - if ( rich ) { | |
| 7456 | - let p = document.createElement( 'p' ); | |
| 7457 | - p.innerText = msg; | |
| 7458 | - send_to_editor( p.innerHTML ); | |
| 7459 | - } else { | |
| 7460 | - insertContent( contentBox, msg ); | |
| 7461 | - } | |
| 7462 | - } | |
| 7463 | - }); | |
| 7464 | - } else { | |
| 7465 | - variable = maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox ); | |
| 7466 | - if ( rich ) { | |
| 7467 | - send_to_editor( variable ); | |
| 7468 | - } else { | |
| 7469 | - insertContent( contentBox, variable ); | |
| 7470 | - } | |
| 7471 | - } | |
| 7472 | - return false; | |
| 7473 | - } | |
| 7474 | - | |
| 7475 | - function maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox ) { | |
| 7476 | - if ( 'object' !== typeof element || ! ( element instanceof jQuery ) || 0 !== contentBox[0].id.indexOf( 'success_url_' ) ) { | |
| 7477 | - return variable; | |
| 7478 | - } | |
| 7479 | - | |
| 7480 | - element = element[0]; | |
| 7481 | - if ( ! element.closest( '#frm-insert-fields-box' ) ) { | |
| 7482 | - // Only add sanitize_url=1 to field shortcodes. | |
| 7483 | - return variable; | |
| 7484 | - } | |
| 7485 | - | |
| 7486 | - if ( ! element.parentNode.classList.contains( 'frm_insert_url' ) ) { | |
| 7487 | - variable = variable.replace( ']', ' sanitize_url=1]' ); | |
| 7488 | - } | |
| 7489 | - | |
| 7490 | - return variable; | |
| 7491 | - } | |
| 7492 | - | |
| 7493 | - function insertContent( contentBox, variable ) { | |
| 7494 | - if ( document.selection ) { | |
| 7495 | - contentBox[0].focus(); | |
| 7496 | - document.selection.createRange().text = variable; | |
| 7497 | - } else { | |
| 7498 | - obj = contentBox[0]; | |
| 7499 | - var e = obj.selectionEnd; | |
| 7500 | - | |
| 7501 | - variable = maybeFormatInsertedContent( contentBox, variable, obj.selectionStart, e ); | |
| 7502 | - | |
| 7503 | - obj.value = obj.value.substr( 0, obj.selectionStart ) + variable + obj.value.substr( obj.selectionEnd, obj.value.length ); | |
| 7504 | - var s = e + variable.length; | |
| 7505 | - obj.focus(); | |
| 7506 | - obj.setSelectionRange( s, s ); | |
| 7507 | - } | |
| 7508 | - triggerChange( contentBox ); | |
| 7509 | - } | |
| 7510 | - | |
| 7511 | - function maybeFormatInsertedContent( input, textToInsert, selectionStart, selectionEnd ) { | |
| 7512 | - var separator = input.data( 'sep' ); | |
| 7513 | - if ( undefined === separator ) { | |
| 7514 | - return textToInsert; | |
| 7515 | - } | |
| 7516 | - | |
| 7517 | - var value = input.val(); | |
| 7518 | - | |
| 7519 | - if ( ! value.trim().length ) { | |
| 7520 | - return textToInsert; | |
| 7521 | - } | |
| 7522 | - | |
| 7523 | - var startPattern = new RegExp( separator + '\\s*$' ); | |
| 7524 | - var endPattern = new RegExp( '^\\s*' + separator ); | |
| 7525 | - | |
| 7526 | - if ( value.substr( 0, selectionStart ).trim().length && false === startPattern.test( value.substr( 0, selectionStart ) ) ) { | |
| 7527 | - textToInsert = separator + textToInsert; | |
| 7528 | - } | |
| 7529 | - | |
| 7530 | - if ( value.substr( selectionEnd, value.length ).trim().length && false === endPattern.test( value.substr( selectionEnd, value.length ) ) ) { | |
| 7531 | - textToInsert += separator; | |
| 7532 | - } | |
| 7533 | - | |
| 7534 | - return textToInsert; | |
| 7535 | - } | |
| 7536 | - | |
| 7537 | - function resetLogicBuilder() { | |
| 7538 | - /*jshint validthis:true */ | |
| 7539 | - var id = document.getElementById( 'frm-id-condition' ), | |
| 7540 | - key = document.getElementById( 'frm-key-condition' ); | |
| 7541 | - | |
| 7542 | - if ( this.checked ) { | |
| 7543 | - id.classList.remove( 'frm_hidden' ); | |
| 7544 | - key.classList.add( 'frm_hidden' ); | |
| 7545 | - triggerEvent( key, 'change' ); | |
| 7546 | - } else { | |
| 7547 | - id.classList.add( 'frm_hidden' ); | |
| 7548 | - key.classList.remove( 'frm_hidden' ); | |
| 7549 | - triggerEvent( id, 'change' ); | |
| 7550 | - } | |
| 7551 | - } | |
| 7552 | - | |
| 7553 | - function setLogicExample() { | |
| 7554 | - var field, code, | |
| 7555 | - idKey = document.getElementById( 'frm-id-key-condition' ).checked ? 'frm-id-condition' : 'frm-key-condition', | |
| 7556 | - is = document.getElementById( 'frm-is-condition' ).value, | |
| 7557 | - text = document.getElementById( 'frm-text-condition' ).value, | |
| 7558 | - result = document.getElementById( 'frm-insert-condition' ); | |
| 7559 | - | |
| 7560 | - idKey = document.getElementById( idKey ); | |
| 7561 | - field = idKey.options[idKey.selectedIndex].value; | |
| 7562 | - code = 'if ' + field + ' ' + is + '="' + text + '"]'; | |
| 7563 | - result.setAttribute( 'data-code', code + frm_admin_js.conditional_text + '[/if ' + field ); // eslint-disable-line camelcase | |
| 7564 | - result.innerHTML = '[' + code + '[/if ' + field + ']'; | |
| 7565 | - } | |
| 7566 | - | |
| 7567 | - function showBuilderModal() { | |
| 7568 | - /*jshint validthis:true */ | |
| 7569 | - var moreIcon = getIconForInput( this ); | |
| 7570 | - showInlineModal( moreIcon, this ); | |
| 7571 | - } | |
| 7572 | - | |
| 7573 | - function maybeShowModal( input ) { | |
| 7574 | - var moreIcon; | |
| 7575 | - if ( input.parentNode.parentNode.classList.contains( 'frm_has_shortcodes' ) ) { | |
| 7576 | - hideShortcodes(); | |
| 7577 | - moreIcon = getIconForInput( input ); | |
| 7578 | - if ( moreIcon.tagName === 'use' ) { | |
| 7579 | - moreIcon = moreIcon.firstElementChild; | |
| 7580 | - if ( moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ).indexOf( 'frm_close_icon' ) === -1 ) { | |
| 7581 | - showShortcodeBox( moreIcon, 'nofocus' ); | |
| 7582 | - } | |
| 7583 | - } else if ( ! moreIcon.classList.contains( 'frm_close_icon' ) ) { | |
| 7584 | - showShortcodeBox( moreIcon, 'nofocus' ); | |
| 7585 | - } | |
| 7586 | - } | |
| 7587 | - } | |
| 7588 | - | |
| 7589 | - function showShortcodes( e ) { | |
| 7590 | - /*jshint validthis:true */ | |
| 7591 | - e.preventDefault(); | |
| 7592 | - e.stopPropagation(); | |
| 7593 | - | |
| 7594 | - showShortcodeBox( this ); | |
| 7595 | - } | |
| 7596 | - | |
| 7597 | - function showShortcodeBox( moreIcon, shouldFocus ) { | |
| 7598 | - var pos = moreIcon.getBoundingClientRect(), | |
| 7599 | - input = getInputForIcon( moreIcon ), | |
| 7600 | - box = document.getElementById( 'frm_adv_info' ), | |
| 7601 | - classes = moreIcon.className, | |
| 7602 | - parentPos = box.parentElement.getBoundingClientRect(); | |
| 7603 | - | |
| 7604 | - if ( moreIcon.tagName === 'svg' ) { | |
| 7605 | - moreIcon = moreIcon.firstElementChild; | |
| 7606 | - } | |
| 7607 | - if ( moreIcon.tagName === 'use' ) { | |
| 7608 | - classes = moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ); | |
| 7609 | - } | |
| 7610 | - | |
| 7611 | - if ( classes.indexOf( 'frm_close_icon' ) !== -1 ) { | |
| 7612 | - hideShortcodes( box ); | |
| 7613 | - } else { | |
| 7614 | - box.style.top = ( pos.top - parentPos.top + 32 ) + 'px'; | |
| 7615 | - box.style.left = ( pos.left - parentPos.left - 280 ) + 'px'; | |
| 7616 | - | |
| 7617 | - jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ); | |
| 7618 | - if ( input.classList.contains( 'frm_not_email_to' ) ) { | |
| 7619 | - jQuery( '#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a' ).addClass( 'frm_noallow' ); | |
| 7620 | - } else if ( input.classList.contains( 'frm_not_email_subject' ) ) { | |
| 7621 | - jQuery( '.frm_code_list li.hide_frm_not_email_subject a' ).addClass( 'frm_noallow' ); | |
| 7622 | - } | |
| 7623 | - | |
| 7624 | - box.setAttribute( 'data-fills', input.id ); | |
| 7625 | - box.style.display = 'block'; | |
| 7626 | - | |
| 7627 | - if ( moreIcon.tagName === 'use' ) { | |
| 7628 | - moreIcon.setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_close_icon' ); | |
| 7629 | - } else { | |
| 7630 | - moreIcon.className = classes.replace( 'frm_more_horiz_solid_icon', 'frm_close_icon' ); | |
| 7631 | - } | |
| 7632 | - | |
| 7633 | - if ( shouldFocus !== 'nofocus' ) { | |
| 7634 | - if ( 'none' !== input.style.display ) { | |
| 7635 | - input.focus(); | |
| 7636 | - } else { | |
| 7637 | - jQuery( tinymce.get( input.id ) ).trigger( 'focus' ); | |
| 7638 | - } | |
| 7639 | - } | |
| 7640 | - } | |
| 7641 | - } | |
| 7642 | - | |
| 7643 | - function fieldUpdated() { | |
| 7644 | - if ( ! fieldsUpdated ) { | |
| 7645 | - fieldsUpdated = 1; | |
| 7646 | - window.addEventListener( 'beforeunload', confirmExit ); | |
| 7647 | - } | |
| 7648 | - } | |
| 7649 | - | |
| 7650 | - function buildSubmittedNoAjax() { | |
| 7651 | - // set fieldsUpdated to 0 to avoid the unsaved changes pop up | |
| 7652 | - fieldsUpdated = 0; | |
| 7653 | - } | |
| 7654 | - | |
| 7655 | - function settingsSubmitted() { | |
| 7656 | - // set fieldsUpdated to 0 to avoid the unsaved changes pop up | |
| 7657 | - fieldsUpdated = 0; | |
| 7658 | - } | |
| 7659 | - | |
| 7660 | - function saveAndReloadSettings() { | |
| 7661 | - var page, form; | |
| 7662 | - page = document.getElementById( 'form_settings_page' ); | |
| 7663 | - if ( null !== page ) { | |
| 7664 | - form = page.querySelector( 'form.frm_form_settings' ); | |
| 7665 | - if ( null !== form ) { | |
| 7666 | - fieldsUpdated = 0; | |
| 7667 | - form.submit(); | |
| 7668 | - } | |
| 7669 | - } | |
| 7670 | - } | |
| 7671 | - | |
| 7672 | - function saveAndReloadFormBuilder() { | |
| 7673 | - document.getElementById( 'frm_submit_side_top' ).click(); | |
| 7674 | - } | |
| 7675 | - | |
| 7676 | - function confirmExit( event ) { | |
| 7677 | - if ( fieldsUpdated ) { | |
| 7678 | - event.preventDefault(); | |
| 7679 | - event.returnValue = ''; | |
| 7680 | - } | |
| 7681 | - } | |
| 7682 | - | |
| 7683 | - function bindClickForDialogClose( $modal ) { | |
| 7684 | - const closeModal = function() { | |
| 7685 | - $modal.dialog( 'close' ); | |
| 7686 | - }; | |
| 7687 | - jQuery( '.ui-widget-overlay' ).on( 'click', closeModal ); | |
| 7688 | - $modal.on( 'click', 'a.dismiss', closeModal ); | |
| 7689 | - } | |
| 7690 | - | |
| 7691 | - function triggerNewFormModal( event ) { | |
| 7692 | - var $modal, | |
| 7693 | - dismiss = document.getElementById( 'frm_new_form_modal' ).querySelector( 'a.dismiss' ); | |
| 7694 | - | |
| 7695 | - if ( typeof event !== 'undefined' ) { | |
| 7696 | - event.preventDefault(); | |
| 7697 | - } | |
| 7698 | - | |
| 7699 | - dismiss.setAttribute( 'tabindex', -1 ); | |
| 7700 | - | |
| 7701 | - $modal = initModal( '#frm_new_form_modal', '600px' ); | |
| 7702 | - offsetModalY( $modal, '50px' ); | |
| 7703 | - $modal.attr( 'frm-page', 'create' ); | |
| 7704 | - $modal.find( '#template-search-input' ).val( '' ).trigger( 'change' ); | |
| 7705 | - $modal.dialog( 'open' ); | |
| 7706 | - | |
| 7707 | - dismiss.removeAttribute( 'tabindex' ); | |
| 7708 | - bindClickForDialogClose( $modal ); | |
| 7709 | - | |
| 7710 | - addApplicationsToNewFormModal( $modal.get( 0 ) ); | |
| 7711 | - } | |
| 7712 | - | |
| 7713 | - function addApplicationsToNewFormModal( modal ) { | |
| 7714 | - if ( modal.querySelector( '.frm-ready-made-solution' ) ) { | |
| 7715 | - // Avoid adding duplicates if the modal is opened multiple times. | |
| 7716 | - return; | |
| 7717 | - } | |
| 7718 | - | |
| 7719 | - if ( ! frmGlobal.canAccessApplicationDashboard ) { | |
| 7720 | - // User does not have privileges to see Ready Made Solutions. | |
| 7721 | - return; | |
| 7722 | - } | |
| 7723 | - | |
| 7724 | - doJsonFetch( 'get_applications_data&view=templates' ).then( addTemplatesOnFetchSuccess ); | |
| 7725 | - | |
| 7726 | - const categoryList = modal.querySelector( 'ul.frm-categories-list' ); | |
| 7727 | - | |
| 7728 | - function addTemplatesOnFetchSuccess( data ) { | |
| 7729 | - data.templates.forEach( addTemplateToCategoryList ); | |
| 7730 | - initSearch( 'template-search-input', 'frm-searchable-template frm-ready-made-solution' ); | |
| 7731 | - } | |
| 7732 | - | |
| 7733 | - function addTemplateToCategoryList( template ) { | |
| 7734 | - categoryList.appendChild( getReadyMadeSolution( template ) ); | |
| 7735 | - } | |
| 7736 | - | |
| 7737 | - function getReadyMadeSolution( template ) { | |
| 7738 | - const image = tag( 'img' ); | |
| 7739 | - const thumbnailFolderUrl = frmGlobal.url + '/images/applications/thumbnails/'; | |
| 7740 | - const filenameToUse = template.hasLiteThumbnail ? template.key + '.png' : 'placeholder.svg'; | |
| 7741 | - image.setAttribute( 'src', thumbnailFolderUrl + filenameToUse ); | |
| 7742 | - | |
| 7743 | - const imageWrapper = div({ child: image }); | |
| 7744 | - const href = frmGlobal.applicationsUrl + '&triggerViewApplicationModal=1&template=' + template.key; | |
| 7745 | - | |
| 7746 | - return tag( | |
| 7747 | - 'li', | |
| 7748 | - { | |
| 7749 | - className: 'frm-searchable-template frm-ready-made-solution frm-selectable', | |
| 7750 | - data: { | |
| 7751 | - href: href | |
| 7752 | - }, | |
| 7753 | - children: [ | |
| 7754 | - imageWrapper, | |
| 7755 | - div({ | |
| 7756 | - className: 'frm-solution-details', | |
| 7757 | - children: [ | |
| 7758 | - span({ | |
| 7759 | - className: 'frm-meta-tag', | |
| 7760 | - text: __( 'Ready Made Solution', 'formidable' ) | |
| 7761 | - }), | |
| 7762 | - tag( 'h3', template.name ), | |
| 7763 | - a({ | |
| 7764 | - text: __( 'See all applications', 'formidable' ), | |
| 7765 | - href: frmGlobal.applicationsUrl | |
| 7766 | - }) | |
| 7767 | - ] | |
| 7768 | - }), | |
| 7769 | - div({ | |
| 7770 | - className: 'frm-hover-icons', | |
| 7771 | - child: a({ | |
| 7772 | - child: svg({ href: '#frm_plus_icon' }), | |
| 7773 | - href: href | |
| 7774 | - }) | |
| 7775 | - }) | |
| 7776 | - ] | |
| 7777 | - } | |
| 7778 | - ); | |
| 7779 | - } | |
| 7780 | - } | |
| 7781 | - | |
| 7782 | - function offsetModalY( $modal, amount ) { | |
| 7783 | - const position = { | |
| 7784 | - my: 'top', | |
| 7785 | - at: 'top+' + amount, | |
| 7786 | - of: window | |
| 7787 | - }; | |
| 7788 | - $modal.dialog( 'option', 'position', position ); | |
| 7789 | - } | |
| 7790 | - | |
| 7791 | - /** | |
| 7792 | - * Get the input box for the selected ... icon. | |
| 7793 | - */ | |
| 7794 | - function getInputForIcon( moreIcon ) { | |
| 7795 | - var input = moreIcon.nextElementSibling; | |
| 7796 | - | |
| 7797 | - while ( input !== null && input.tagName !== 'INPUT' && input.tagName !== 'TEXTAREA' ) { | |
| 7798 | - input = getInputForIcon( input ); | |
| 7799 | - } | |
| 7800 | - | |
| 7801 | - return input; | |
| 7802 | - } | |
| 7803 | - | |
| 7804 | - /** | |
| 7805 | - * Get the ... icon for the selected input box. | |
| 7806 | - */ | |
| 7807 | - function getIconForInput( input ) { | |
| 7808 | - var moreIcon = input.previousElementSibling; | |
| 7809 | - | |
| 7810 | - while ( moreIcon !== null && moreIcon.tagName !== 'I' && moreIcon.tagName !== 'svg' ) { | |
| 7811 | - moreIcon = getIconForInput( moreIcon ); | |
| 7812 | - } | |
| 7813 | - | |
| 7814 | - return moreIcon; | |
| 7815 | - } | |
| 7816 | - | |
| 7817 | - function hideShortcodes( box ) { | |
| 7818 | - var i, u, closeIcons, closeSvg; | |
| 7819 | - if ( typeof box === 'undefined' ) { | |
| 7820 | - box = document.getElementById( 'frm_adv_info' ); | |
| 7821 | - if ( box === null ) { | |
| 7822 | - return; | |
| 7823 | - } | |
| 7824 | - } | |
| 7825 | - | |
| 7826 | - if ( document.getElementById( 'frm_dyncontent' ) !== null ) { | |
| 7827 | - // Don't run when in the sidebar. | |
| 7828 | - return; | |
| 7829 | - } | |
| 7830 | - | |
| 7831 | - box.style.display = 'none'; | |
| 7832 | - | |
| 7833 | - closeIcons = document.querySelectorAll( '.frm-show-box.frm_close_icon' ); | |
| 7834 | - for ( i = 0; i < closeIcons.length; i++ ) { | |
| 7835 | - closeIcons[i].classList.remove( 'frm_close_icon' ); | |
| 7836 | - closeIcons[i].classList.add( 'frm_more_horiz_solid_icon' ); | |
| 7837 | - } | |
| 7838 | - | |
| 7839 | - closeSvg = document.querySelectorAll( '.frm_has_shortcodes use' ); | |
| 7840 | - for ( u = 0; u < closeSvg.length; u++ ) { | |
| 7841 | - if ( closeSvg[u].getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) === '#frm_close_icon' ) { | |
| 7842 | - closeSvg[u].setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_more_horiz_solid_icon' ); | |
| 7843 | - } | |
| 7844 | - } | |
| 7845 | - } | |
| 7846 | - | |
| 7847 | - function initToggleShortcodes() { | |
| 7848 | - if ( typeof tinymce !== 'object' ) { | |
| 7849 | - return; | |
| 7850 | - } | |
| 7851 | - | |
| 7852 | - DOM = tinymce.DOM; | |
| 7853 | - if ( typeof DOM.events !== 'undefined' && typeof DOM.events.add !== 'undefined' ) { | |
| 7854 | - DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseover', function() { | |
| 7855 | - if ( jQuery( '*:focus' ).length > 0 ) { | |
| 7856 | - return; | |
| 7857 | - } | |
| 7858 | - if ( this.id ) { | |
| 7859 | - toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 7860 | - } | |
| 7861 | - }); | |
| 7862 | - DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseout', function() { | |
| 7863 | - if ( jQuery( '*:focus' ).length > 0 ) { | |
| 7864 | - return; | |
| 7865 | - } | |
| 7866 | - if ( this.id ) { | |
| 7867 | - toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 7868 | - } | |
| 7869 | - }); | |
| 7870 | - } else { | |
| 7871 | - jQuery( '#frm_dyncontent' ).on( 'mouseover mouseout', '.wp-editor-wrap', function() { | |
| 7872 | - if ( jQuery( '*:focus' ).length > 0 ) { | |
| 7873 | - return; | |
| 7874 | - } | |
| 7875 | - if ( this.id ) { | |
| 7876 | - toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 7877 | - } | |
| 7878 | - }); | |
| 7879 | - } | |
| 7880 | - } | |
| 7881 | - | |
| 7882 | - function toggleAllowedShortcodes( id ) { | |
| 7883 | - var c, clickedID; | |
| 7884 | - if ( typeof id === 'undefined' ) { | |
| 7885 | - id = ''; | |
| 7886 | - } | |
| 7887 | - c = id; | |
| 7888 | - | |
| 7889 | - if ( id.indexOf( '-search-input' ) !== -1 ) { | |
| 7890 | - return; | |
| 7891 | - } | |
| 7892 | - | |
| 7893 | - if ( id !== '' ) { | |
| 7894 | - var $ele = jQuery( document.getElementById( id ) ); | |
| 7895 | - if ( $ele.attr( 'class' ) && id !== 'wpbody-content' && id !== 'content' && id !== 'dyncontent' && id !== 'success_msg' ) { | |
| 7896 | - var d = $ele.attr( 'class' ).split( ' ' )[0]; | |
| 7897 | - if ( d === 'frm_long_input' || d === 'frm_98_width' || typeof d === 'undefined' ) { | |
| 7898 | - d = ''; | |
| 7899 | - } else { | |
| 7900 | - id = d.trim(); | |
| 7901 | - } | |
| 7902 | - c = c + ' ' + d; | |
| 7903 | - c = c.replace( 'widefat', '' ).replace( 'frm_with_left_label', '' ); | |
| 7904 | - } | |
| 7905 | - } | |
| 7906 | - | |
| 7907 | - jQuery( '#frm-insert-fields-box,#frm-conditionals,#frm-adv-info-tab,#frm-dynamic-values' ).attr( 'data-fills', c.trim() ); | |
| 7908 | - var a = [ | |
| 7909 | - 'content', 'wpbody-content', 'dyncontent', 'success_url', | |
| 7910 | - 'success_msg', 'edit_msg', 'frm_dyncontent', 'frm_not_email_message', | |
| 7911 | - 'frm_not_email_subject' | |
| 7912 | - ]; | |
| 7913 | - var b = [ | |
| 7914 | - 'before_content', 'after_content', 'frm_not_email_to', | |
| 7915 | - 'dyn_default_value' | |
| 7916 | - ]; | |
| 7917 | - | |
| 7918 | - if ( jQuery.inArray( id, a ) >= 0 ) { | |
| 7919 | - jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' ); | |
| 7920 | - jQuery( '.frm_code_list a.hide_' + id ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 7921 | - } else if ( jQuery.inArray( id, b ) >= 0 ) { | |
| 7922 | - jQuery( '.frm_code_list:not(.frm-dropdown-menu) a:not(.show_' + id + ')' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 7923 | - jQuery( '.frm_code_list a.show_' + id ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' ); | |
| 7924 | - } else { | |
| 7925 | - jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 7926 | - } | |
| 7927 | - | |
| 7928 | - // Automatically select a tab. | |
| 7929 | - if ( id === 'dyn_default_value' ) { | |
| 7930 | - clickedID = 'frm_dynamic_values'; | |
| 7931 | - document.getElementById( clickedID + '_tab' ).click(); | |
| 7932 | - jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_inactive' ).addClass( 'frm_hidden' ); | |
| 7933 | - jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_active' ).removeClass( 'frm_hidden' ); | |
| 7934 | - } | |
| 7935 | - } | |
| 7936 | - | |
| 7937 | - function toggleAllowedHTML( input ) { | |
| 7938 | - var b, | |
| 7939 | - id = input.id; | |
| 7940 | - if ( typeof id === 'undefined' || id.indexOf( '-search-input' ) !== -1 ) { | |
| 7941 | - return; | |
| 7942 | - } | |
| 7943 | - | |
| 7944 | - jQuery( '#frm-adv-info-tab' ).attr( 'data-fills', id.trim() ); | |
| 7945 | - if ( input.classList.contains( 'field_custom_html' ) ) { | |
| 7946 | - id = 'field_custom_html'; | |
| 7947 | - } | |
| 7948 | - | |
| 7949 | - b = [ 'after_html', 'before_html', 'submit_html', 'field_custom_html' ]; | |
| 7950 | - if ( jQuery.inArray( id, b ) >= 0 ) { | |
| 7951 | - jQuery( '.frm_code_list li:not(.show_' + id + ')' ).addClass( 'frm_hidden' ); | |
| 7952 | - jQuery( '.frm_code_list li.show_' + id ).removeClass( 'frm_hidden' ); | |
| 7953 | - } | |
| 7954 | - } | |
| 7955 | - | |
| 7956 | - function toggleKeyID( switchTo, e ) { | |
| 7957 | - e.stopPropagation(); | |
| 7958 | - jQuery( '.frm_code_list .frmids, .frm_code_list .frmkeys' ).addClass( 'frm_hidden' ); | |
| 7959 | - jQuery( '.frm_code_list .' + switchTo ).removeClass( 'frm_hidden' ); | |
| 7960 | - jQuery( '.frmids, .frmkeys' ).removeClass( 'current' ); | |
| 7961 | - jQuery( '.' + switchTo ).addClass( 'current' ); | |
| 7962 | - } | |
| 7963 | - | |
| 7964 | - function onActionLoaded( event ) { | |
| 7965 | - const settings = event.target.closest( '.frm_form_action_settings' ); | |
| 7966 | - if ( settings && ( settings.classList.contains( 'frm_single_email_settings' ) || settings.classList.contains( 'frm_single_on_submit_settings' ) ) ) { | |
| 7967 | - initWysiwygOnActionLoaded( settings ); | |
| 7968 | - } | |
| 7969 | - } | |
| 7970 | - | |
| 7971 | - function initWysiwygOnActionLoaded( settings ) { | |
| 7972 | - const wysiwyg = settings.querySelector( '.wp-editor-area' ); | |
| 7973 | - if ( wysiwyg ) { | |
| 7974 | - frmDom.wysiwyg.init( | |
| 7975 | - wysiwyg, | |
| 7976 | - { height: 160, addFocusEvents: true } | |
| 7977 | - ); | |
| 7978 | - } | |
| 7979 | - } | |
| 7980 | - | |
| 7981 | - /* Global settings page */ | |
| 7982 | - function loadSettingsTab( anchor ) { | |
| 7983 | - var holder = anchor.replace( '#', '' ); | |
| 7984 | - var holderContainer = jQuery( '.frm_' + holder + '_ajax' ); | |
| 7985 | - if ( holderContainer.length ) { | |
| 7986 | - jQuery.ajax({ | |
| 7987 | - type: 'POST', url: ajaxurl, | |
| 7988 | - data: { | |
| 7989 | - 'action': 'frm_settings_tab', | |
| 7990 | - 'tab': holder.replace( '_settings', '' ), | |
| 7991 | - 'nonce': frmGlobal.nonce | |
| 7992 | - }, | |
| 7993 | - success: function( html ) { | |
| 7994 | - holderContainer.replaceWith( html ); | |
| 7995 | - } | |
| 7996 | - }); | |
| 7997 | - } | |
| 7998 | - } | |
| 7999 | - | |
| 8000 | - function uninstallNow() { | |
| 8001 | - /*jshint validthis:true */ | |
| 8002 | - if ( confirmLinkClick( this ) === true ) { | |
| 8003 | - jQuery( '.frm_uninstall .frm-wait' ).css( 'visibility', 'visible' ); | |
| 8004 | - jQuery.ajax({ | |
| 8005 | - type: 'POST', | |
| 8006 | - url: ajaxurl, | |
| 8007 | - data: 'action=frm_uninstall&nonce=' + frmGlobal.nonce, | |
| 8008 | - success: function( msg ) { | |
| 8009 | - jQuery( '.frm_uninstall' ).fadeOut( 'slow' ); | |
| 8010 | - window.location = msg; | |
| 8011 | - } | |
| 8012 | - }); | |
| 8013 | - } | |
| 8014 | - return false; | |
| 8015 | - } | |
| 8016 | - | |
| 8017 | - function saveAddonLicense() { | |
| 8018 | - /*jshint validthis:true */ | |
| 8019 | - var button = jQuery( this ); | |
| 8020 | - var buttonName = this.name; | |
| 8021 | - var pluginSlug = this.getAttribute( 'data-plugin' ); | |
| 8022 | - var action = buttonName.replace( 'edd_' + pluginSlug + '_license_', '' ); | |
| 8023 | - var license = document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value; | |
| 8024 | - jQuery.ajax({ | |
| 8025 | - type: 'POST', url: ajaxurl, dataType: 'json', | |
| 8026 | - data: {action: 'frm_addon_' + action, license: license, plugin: pluginSlug, nonce: frmGlobal.nonce}, | |
| 8027 | - success: function( msg ) { | |
| 8028 | - var thisRow = button.closest( '.edd_frm_license_row' ); | |
| 8029 | - if ( action === 'deactivate' ) { | |
| 8030 | - license = ''; | |
| 8031 | - document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value = ''; | |
| 8032 | - } | |
| 8033 | - thisRow.find( '.edd_frm_license' ).html( license ); | |
| 8034 | - if ( msg.success === true ) { | |
| 8035 | - thisRow.find( '.frm_icon_font' ).removeClass( 'frm_hidden' ); | |
| 8036 | - thisRow.find( 'div.alignleft' ).toggleClass( 'frm_hidden', 1000 ); | |
| 8037 | - } | |
| 8038 | - | |
| 8039 | - var messageBox = thisRow.find( '.frm_license_msg' ); | |
| 8040 | - messageBox.html( msg.message ); | |
| 8041 | - if ( msg.message !== '' ) { | |
| 8042 | - setTimeout( function() { | |
| 8043 | - messageBox.html( '' ); | |
| 8044 | - }, 15000 ); | |
| 8045 | - } | |
| 8046 | - } | |
| 8047 | - }); | |
| 8048 | - } | |
| 8049 | - | |
| 8050 | - /* Import/Export page */ | |
| 8051 | - | |
| 8052 | - function startFormMigration( event ) { | |
| 8053 | - event.preventDefault(); | |
| 8054 | - | |
| 8055 | - var checkedBoxes = jQuery( event.target ).find( 'input:checked' ); | |
| 8056 | - if ( ! checkedBoxes.length ) { | |
| 8057 | - return; | |
| 8058 | - } | |
| 8059 | - | |
| 8060 | - var ids = []; | |
| 8061 | - checkedBoxes.each( function( i ) { | |
| 8062 | - ids[i] = this.value; | |
| 8063 | - }); | |
| 8064 | - | |
| 8065 | - // Begin the import process. | |
| 8066 | - importForms( ids, event.target ); | |
| 8067 | - } | |
| 8068 | - | |
| 8069 | - /** | |
| 8070 | - * Begins the process of importing the forms. | |
| 8071 | - */ | |
| 8072 | - function importForms( forms, targetForm ) { | |
| 8073 | - | |
| 8074 | - // Hide the form select section. | |
| 8075 | - var $form = jQuery( targetForm ), | |
| 8076 | - $processSettings = $form.next( '.frm-importer-process' ); | |
| 8077 | - | |
| 8078 | - // Display total number of forms we have to import. | |
| 8079 | - $processSettings.find( '.form-total' ).text( forms.length ); | |
| 8080 | - $processSettings.find( '.form-current' ).text( '1' ); | |
| 8081 | - | |
| 8082 | - $form.hide(); | |
| 8083 | - | |
| 8084 | - // Show processing status. | |
| 8085 | - // '.process-completed' might have been shown earlier during a previous import, so hide now. | |
| 8086 | - $processSettings.find( '.process-completed' ).hide(); | |
| 8087 | - $processSettings.show(); | |
| 8088 | - | |
| 8089 | - // Create global import queue. | |
| 8090 | - s.importQueue = forms; | |
| 8091 | - s.imported = 0; | |
| 8092 | - | |
| 8093 | - // Import the first form in the queue. | |
| 8094 | - importForm( $processSettings ); | |
| 8095 | - } | |
| 8096 | - | |
| 8097 | - /** | |
| 8098 | - * Imports a single form from the import queue. | |
| 8099 | - */ | |
| 8100 | - function importForm( $processSettings ) { | |
| 8101 | - var formID = s.importQueue[0], | |
| 8102 | - provider = jQuery( '#welcome-panel' ).find( 'input[name="slug"]' ).val(), | |
| 8103 | - data = { | |
| 8104 | - action: 'frm_import_' + provider, | |
| 8105 | - form_id: formID, | |
| 8106 | - nonce: frmGlobal.nonce | |
| 8107 | - }; | |
| 8108 | - | |
| 8109 | - // Trigger AJAX import for this form. | |
| 8110 | - jQuery.post( ajaxurl, data, function( res ) { | |
| 8111 | - | |
| 8112 | - if ( res.success ) { | |
| 8113 | - var statusUpdate; | |
| 8114 | - | |
| 8115 | - if ( res.data.error ) { | |
| 8116 | - statusUpdate = '<p>' + res.data.name + ': ' + res.data.msg + '</p>'; | |
| 8117 | - } else { | |
| 8118 | - statusUpdate = '<p>Imported <a href="' + res.data.link + '" target="_blank">' + res.data.name + '</a></p>'; | |
| 8119 | - } | |
| 8120 | - | |
| 8121 | - $processSettings.find( '.status' ).prepend( statusUpdate ); | |
| 8122 | - $processSettings.find( '.status' ).show(); | |
| 8123 | - | |
| 8124 | - // Remove this form ID from the queue. | |
| 8125 | - s.importQueue = jQuery.grep( s.importQueue, function( value ) { | |
| 8126 | - return value != formID; | |
| 8127 | - }); | |
| 8128 | - s.imported++; | |
| 8129 | - | |
| 8130 | - if ( s.importQueue.length === 0 ) { | |
| 8131 | - $processSettings.find( '.process-count' ).hide(); | |
| 8132 | - $processSettings.find( '.forms-completed' ).text( s.imported ); | |
| 8133 | - $processSettings.find( '.process-completed' ).show(); | |
| 8134 | - } else { | |
| 8135 | - // Import next form in the queue. | |
| 8136 | - $processSettings.find( '.form-current' ).text( s.imported + 1 ); | |
| 8137 | - importForm( $processSettings ); | |
| 8138 | - } | |
| 8139 | - } | |
| 8140 | - }); | |
| 8141 | - } | |
| 8142 | - | |
| 8143 | - function validateExport( e ) { | |
| 8144 | - /*jshint validthis:true */ | |
| 8145 | - e.preventDefault(); | |
| 8146 | - | |
| 8147 | - var s = false; | |
| 8148 | - var $exportForms = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 8149 | - | |
| 8150 | - if ( ! jQuery( 'input[name="frm_export_forms[]"]:checked' ).val() ) { | |
| 8151 | - $exportForms.closest( '.frm-table-box' ).addClass( 'frm_blank_field' ); | |
| 8152 | - s = 'stop'; | |
| 8153 | - } | |
| 8154 | - | |
| 8155 | - var $exportType = jQuery( 'input[name="type[]"]' ); | |
| 8156 | - if ( ! jQuery( 'input[name="type[]"]:checked' ).val() && $exportType.attr( 'type' ) === 'checkbox' ) { | |
| 8157 | - $exportType.closest( 'p' ).addClass( 'frm_blank_field' ); | |
| 8158 | - s = 'stop'; | |
| 8159 | - } | |
| 8160 | - | |
| 8161 | - if ( s === 'stop' ) { | |
| 8162 | - return false; | |
| 8163 | - } | |
| 8164 | - | |
| 8165 | - e.stopPropagation(); | |
| 8166 | - this.submit(); | |
| 8167 | - } | |
| 8168 | - | |
| 8169 | - function removeExportError() { | |
| 8170 | - /*jshint validthis:true */ | |
| 8171 | - var t = jQuery( this ).closest( '.frm_blank_field' ); | |
| 8172 | - if ( typeof t === 'undefined' ) { | |
| 8173 | - return; | |
| 8174 | - } | |
| 8175 | - | |
| 8176 | - var $thisName = this.name; | |
| 8177 | - if ( $thisName === 'type[]' && jQuery( 'input[name="type[]"]:checked' ).val() ) { | |
| 8178 | - t.removeClass( 'frm_blank_field' ); | |
| 8179 | - } else if ( $thisName === 'frm_export_forms[]' && jQuery( this ).val() ) { | |
| 8180 | - t.removeClass( 'frm_blank_field' ); | |
| 8181 | - } | |
| 8182 | - | |
| 8183 | - } | |
| 8184 | - | |
| 8185 | - function checkCSVExtension() { | |
| 8186 | - /*jshint validthis:true */ | |
| 8187 | - var f = jQuery( this ).val(); | |
| 8188 | - var re = /\.csv$/i; | |
| 8189 | - if ( f.match( re ) !== null ) { | |
| 8190 | - jQuery( '.show_csv' ).fadeIn(); | |
| 8191 | - } else { | |
| 8192 | - jQuery( '.show_csv' ).fadeOut(); | |
| 8193 | - } | |
| 8194 | - } | |
| 8195 | - | |
| 8196 | - function getExportOption() { | |
| 8197 | - const exportFormatSelect = document.querySelector( 'select[name="format"]' ); | |
| 8198 | - if ( exportFormatSelect ) { | |
| 8199 | - return exportFormatSelect.value; | |
| 8200 | - } else { | |
| 8201 | - return ''; | |
| 8202 | - } | |
| 8203 | - } | |
| 8204 | - | |
| 8205 | - function exportTypeChanged( event ) { | |
| 8206 | - const value = event.target.value; | |
| 8207 | - showOrHideRepeaters( value ); | |
| 8208 | - checkExportTypes.call( event.target ); | |
| 8209 | - checkSelectedAllFormsCheckbox( value ); | |
| 8210 | - } | |
| 8211 | - | |
| 8212 | - function checkSelectedAllFormsCheckbox( exportType ) { | |
| 8213 | - const selectAllCheckbox = document.getElementById( 'frm-export-select-all' ); | |
| 8214 | - if ( exportType === 'csv' ) { | |
| 8215 | - selectAllCheckbox.checked = false; | |
| 8216 | - selectAllCheckbox.disabled = true; | |
| 8217 | - } else { | |
| 8218 | - selectAllCheckbox.disabled = false; | |
| 8219 | - } | |
| 8220 | - } | |
| 8221 | - | |
| 8222 | - function checkExportTypes() { | |
| 8223 | - /*jshint validthis:true */ | |
| 8224 | - var $dropdown = jQuery( this ); | |
| 8225 | - var $selected = $dropdown.find( ':selected' ); | |
| 8226 | - var s = $selected.data( 'support' ); | |
| 8227 | - | |
| 8228 | - var multiple = s.indexOf( '|' ); | |
| 8229 | - jQuery( 'input[name="type[]"]' ).each( function() { | |
| 8230 | - this.checked = false; | |
| 8231 | - if ( s.indexOf( this.value ) >= 0 ) { | |
| 8232 | - this.disabled = false; | |
| 8233 | - if ( multiple === -1 ) { | |
| 8234 | - this.checked = true; | |
| 8235 | - } | |
| 8236 | - } else { | |
| 8237 | - this.disabled = true; | |
| 8238 | - } | |
| 8239 | - }); | |
| 8240 | - | |
| 8241 | - if ( $dropdown.val() === 'csv' ) { | |
| 8242 | - jQuery( '.csv_opts' ).show(); | |
| 8243 | - jQuery( '.xml_opts' ).hide(); | |
| 8244 | - } else { | |
| 8245 | - jQuery( '.csv_opts' ).hide(); | |
| 8246 | - jQuery( '.xml_opts' ).show(); | |
| 8247 | - } | |
| 8248 | - | |
| 8249 | - var c = $selected.data( 'count' ); | |
| 8250 | - var exportField = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 8251 | - if ( c === 'single' ) { | |
| 8252 | - exportField.prop( 'multiple', false ); | |
| 8253 | - exportField.prop( 'checked', false ); | |
| 8254 | - } else { | |
| 8255 | - exportField.prop( 'multiple', true ); | |
| 8256 | - exportField.prop( 'disabled', false ); | |
| 8257 | - } | |
| 8258 | - $dropdown.trigger( 'change' ); | |
| 8259 | - } | |
| 8260 | - | |
| 8261 | - function showOrHideRepeaters( exportOption ) { | |
| 8262 | - if ( exportOption === '' ) { | |
| 8263 | - return; | |
| 8264 | - } | |
| 8265 | - | |
| 8266 | - const repeaters = document.querySelectorAll( '.frm-is-repeater' ); | |
| 8267 | - if ( ! repeaters.length ) { | |
| 8268 | - return; | |
| 8269 | - } | |
| 8270 | - | |
| 8271 | - if ( exportOption === 'csv' ) { | |
| 8272 | - repeaters.forEach( form => { | |
| 8273 | - form.classList.remove( 'frm_hidden' ); | |
| 8274 | - }); | |
| 8275 | - } else { | |
| 8276 | - repeaters.forEach( form => { | |
| 8277 | - form.classList.add( 'frm_hidden' ); | |
| 8278 | - }); | |
| 8279 | - } | |
| 8280 | - | |
| 8281 | - searchContent.call( document.querySelector( '.frm-auto-search' ) ); | |
| 8282 | - } | |
| 8283 | - | |
| 8284 | - function preventMultipleExport() { | |
| 8285 | - var type = jQuery( 'select[name=format]' ), | |
| 8286 | - selected = type.find( ':selected' ), | |
| 8287 | - count = selected.data( 'count' ), | |
| 8288 | - exportField = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 8289 | - | |
| 8290 | - if ( count === 'single' ) { | |
| 8291 | - // Disable all other fields to prevent multiple selections. | |
| 8292 | - if ( this.checked ) { | |
| 8293 | - exportField.prop( 'disabled', true ); | |
| 8294 | - this.removeAttribute( 'disabled' ); | |
| 8295 | - } else { | |
| 8296 | - exportField.prop( 'disabled', false ); | |
| 8297 | - } | |
| 8298 | - } else { | |
| 8299 | - exportField.prop( 'disabled', false ); | |
| 8300 | - } | |
| 8301 | - } | |
| 8302 | - | |
| 8303 | - function initiateMultiselect() { | |
| 8304 | - jQuery( '.frm_multiselect' ).hide().each( frmDom.bootstrap.multiselect.init ); | |
| 8305 | - } | |
| 8306 | - | |
| 8307 | - /* Addons page */ | |
| 8308 | - function installMultipleAddons( e ) { | |
| 8309 | - e.preventDefault(); | |
| 8310 | - installOrActivate( this, 'frm_multiple_addons' ); | |
| 8311 | - } | |
| 8312 | - | |
| 8313 | - function activateAddon( e ) { | |
| 8314 | - e.preventDefault(); | |
| 8315 | - installOrActivate( this, 'frm_activate_addon' ); | |
| 8316 | - } | |
| 8317 | - | |
| 8318 | - function installAddon( e ) { | |
| 8319 | - e.preventDefault(); | |
| 8320 | - installOrActivate( this, 'frm_install_addon' ); | |
| 8321 | - } | |
| 8322 | - | |
| 8323 | - function installOrActivate( clicked, action ) { | |
| 8324 | - let button, plugin, el, message; | |
| 8325 | - | |
| 8326 | - // Remove any leftover error messages, output an icon and get the plugin basename that needs to be activated. | |
| 8327 | - jQuery( '.frm-addon-error' ).remove(); | |
| 8328 | - button = jQuery( clicked ); | |
| 8329 | - plugin = button.attr( 'rel' ); | |
| 8330 | - el = button.parent(); | |
| 8331 | - message = el.parent().find( '.addon-status-label' ); | |
| 8332 | - | |
| 8333 | - button.addClass( 'frm_loading_button' ); | |
| 8334 | - | |
| 8335 | - // Process the Ajax to perform the activation. | |
| 8336 | - jQuery.ajax({ | |
| 8337 | - url: ajaxurl, | |
| 8338 | - type: 'POST', | |
| 8339 | - async: true, | |
| 8340 | - cache: false, | |
| 8341 | - dataType: 'json', | |
| 8342 | - data: { | |
| 8343 | - action: action, | |
| 8344 | - nonce: frmGlobal.nonce, | |
| 8345 | - plugin: plugin | |
| 8346 | - }, | |
| 8347 | - success: function( response ) { | |
| 8348 | - let saveAndReload; | |
| 8349 | - | |
| 8350 | - if ( 'string' !== typeof response && 'string' === typeof response.message ) { | |
| 8351 | - if ( 'undefined' !== typeof response.saveAndReload ) { | |
| 8352 | - saveAndReload = response.saveAndReload; | |
| 8353 | - } | |
| 8354 | - response = response.message; | |
| 8355 | - } | |
| 8356 | - | |
| 8357 | - const error = extractErrorFromAddOnResponse( response ); | |
| 8358 | - if ( error ) { | |
| 8359 | - addonError( error, el, button ); | |
| 8360 | - return; | |
| 8361 | - } | |
| 8362 | - | |
| 8363 | - afterAddonInstall( response, button, message, el, saveAndReload ); | |
| 8364 | - }, | |
| 8365 | - error: function() { | |
| 8366 | - button.removeClass( 'frm_loading_button' ); | |
| 8367 | - } | |
| 8368 | - }); | |
| 8369 | - } | |
| 8370 | - | |
| 8371 | - function installAddonWithCreds( e ) { | |
| 8372 | - // Prevent the default action, let the user know we are attempting to install again and go with it. | |
| 8373 | - e.preventDefault(); | |
| 8374 | - | |
| 8375 | - // Now let's make another Ajax request once the user has submitted their credentials. | |
| 8376 | - const proceed = jQuery( this ); | |
| 8377 | - const el = proceed.parent().parent(); | |
| 8378 | - const plugin = proceed.attr( 'rel' ); | |
| 8379 | - | |
| 8380 | - proceed.addClass( 'frm_loading_button' ); | |
| 8381 | - | |
| 8382 | - jQuery.ajax({ | |
| 8383 | - url: ajaxurl, | |
| 8384 | - type: 'POST', | |
| 8385 | - async: true, | |
| 8386 | - cache: false, | |
| 8387 | - dataType: 'json', | |
| 8388 | - data: { | |
| 8389 | - action: 'frm_install_addon', | |
| 8390 | - nonce: frm_admin_js.nonce, // eslint-disable-line camelcase | |
| 8391 | - plugin: plugin, | |
| 8392 | - hostname: el.find( '#hostname' ).val(), | |
| 8393 | - username: el.find( '#username' ).val(), | |
| 8394 | - password: el.find( '#password' ).val() | |
| 8395 | - }, | |
| 8396 | - success: function( response ) { | |
| 8397 | - const error = extractErrorFromAddOnResponse( response ); | |
| 8398 | - if ( error ) { | |
| 8399 | - addonError( error, el, proceed ); | |
| 8400 | - return; | |
| 8401 | - } | |
| 8402 | - | |
| 8403 | - afterAddonInstall( response, proceed, message, el ); | |
| 8404 | - }, | |
| 8405 | - error: function() { | |
| 8406 | - proceed.removeClass( 'frm_loading_button' ); | |
| 8407 | - } | |
| 8408 | - }); | |
| 8409 | - } | |
| 8410 | - | |
| 8411 | - function afterAddonInstall( response, button, message, el, saveAndReload ) { | |
| 8412 | - const addonStatuses = document.querySelectorAll( '.frm-addon-status' ); | |
| 8413 | - addonStatuses.forEach( | |
| 8414 | - addonStatus => { | |
| 8415 | - addonStatus.textContent = response; | |
| 8416 | - addonStatus.style.display = 'block'; | |
| 8417 | - } | |
| 8418 | - ); | |
| 8419 | - | |
| 8420 | - // The Ajax request was successful, so let's update the output. | |
| 8421 | - button.css({ opacity: '0' }); | |
| 8422 | - message.text( frm_admin_js.active ); // eslint-disable-line camelcase | |
| 8423 | - | |
| 8424 | - document.querySelectorAll( '.frm-oneclick' ).forEach( | |
| 8425 | - oneClick => { | |
| 8426 | - oneClick.style.display = 'none'; | |
| 8427 | - } | |
| 8428 | - ); | |
| 8429 | - | |
| 8430 | - jQuery( '#frm_upgrade_modal h2' ).hide(); | |
| 8431 | - jQuery( '#frm_upgrade_modal .frm_lock_icon' ).addClass( 'frm_lock_open_icon' ); | |
| 8432 | - jQuery( '#frm_upgrade_modal .frm_lock_icon use' ).attr( 'xlink:href', '#frm_lock_open_icon' ); | |
| 8433 | - | |
| 8434 | - // Proceed with CSS changes | |
| 8435 | - el.parent().removeClass( 'frm-addon-not-installed frm-addon-installed' ).addClass( 'frm-addon-active' ); | |
| 8436 | - button.removeClass( 'frm_loading_button' ); | |
| 8437 | - | |
| 8438 | - // Maybe refresh import and SMTP pages | |
| 8439 | - const refreshPage = document.querySelectorAll( '.frm-admin-page-import, #frm-admin-smtp, #frm-welcome' ); | |
| 8440 | - if ( refreshPage.length > 0 ) { | |
| 8441 | - window.location.reload(); | |
| 8442 | - return; | |
| 8443 | - } | |
| 8444 | - | |
| 8445 | - if ([ 'settings', 'form_builder' ].includes( saveAndReload ) ) { | |
| 8446 | - addonStatuses.forEach( | |
| 8447 | - addonStatus => { | |
| 8448 | - const inModal = null !== addonStatus.closest( '#frm_upgrade_modal' ); | |
| 8449 | - addonStatus.appendChild( getSaveAndReloadSettingsOptions( saveAndReload, inModal ) ); | |
| 8450 | - } | |
| 8451 | - ); | |
| 8452 | - } | |
| 8453 | - } | |
| 8454 | - | |
| 8455 | - function getSaveAndReloadSettingsOptions( saveAndReload, inModal ) { | |
| 8456 | - const className = 'frm-save-and-reload-options'; | |
| 8457 | - const children = [ saveAndReloadSettingsButton( saveAndReload ) ]; | |
| 8458 | - if ( inModal ) { | |
| 8459 | - children.push( closePopupButton() ); | |
| 8460 | - } | |
| 8461 | - return div({ className, children }); | |
| 8462 | - } | |
| 8463 | - | |
| 8464 | - function saveAndReloadSettingsButton( saveAndReload ) { | |
| 8465 | - var button = document.createElement( 'button' ); | |
| 8466 | - button.classList.add( 'frm-save-and-reload', 'button', 'button-primary', 'frm-button-primary' ); | |
| 8467 | - button.textContent = __( 'Save and Reload', 'formidable' ); | |
| 8468 | - button.addEventListener( 'click', () => { | |
| 8469 | - if ( saveAndReload === 'form_builder' ) { | |
| 8470 | - saveAndReloadFormBuilder(); | |
| 8471 | - } else if ( saveAndReload === 'settings' ) { | |
| 8472 | - saveAndReloadSettings(); | |
| 8473 | - } | |
| 8474 | - }); | |
| 8475 | - return button; | |
| 8476 | - } | |
| 8477 | - | |
| 8478 | - function closePopupButton() { | |
| 8479 | - var a = document.createElement( 'a' ); | |
| 8480 | - a.setAttribute( 'href', '#' ); | |
| 8481 | - a.classList.add( 'button', 'button-secondary', 'frm-button-secondary', 'dismiss' ); | |
| 8482 | - a.textContent = __( 'Close', 'formidable' ); | |
| 8483 | - return a; | |
| 8484 | - } | |
| 8485 | - | |
| 8486 | - function extractErrorFromAddOnResponse( response ) { | |
| 8487 | - if ( typeof response !== 'string' ) { | |
| 8488 | - if ( typeof response.success !== 'undefined' && response.success ) { | |
| 8489 | - return false; | |
| 8490 | - } | |
| 8491 | - | |
| 8492 | - if ( response.form ) { | |
| 8493 | - if ( jQuery( response.form ).is( '#message' ) ) { | |
| 8494 | - return { | |
| 8495 | - message: jQuery( response.form ).find( 'p' ).html() | |
| 8496 | - }; | |
| 8497 | - } | |
| 8498 | - } | |
| 8499 | - | |
| 8500 | - return response; | |
| 8501 | - } | |
| 8502 | - | |
| 8503 | - return false; | |
| 8504 | - } | |
| 8505 | - | |
| 8506 | - function addonError( response, el, button ) { | |
| 8507 | - if ( response.form ) { | |
| 8508 | - jQuery( '.frm-inline-error' ).remove(); | |
| 8509 | - button.closest( '.frm-card' ) | |
| 8510 | - .html( response.form ) | |
| 8511 | - .css({ padding: 5 }) | |
| 8512 | - .find( '#upgrade' ) | |
| 8513 | - .attr( 'rel', button.attr( 'rel' ) ) | |
| 8514 | - .on( 'click', installAddonWithCreds ); | |
| 8515 | - } else { | |
| 8516 | - el.append( '<div class="frm-addon-error frm_error_style"><p><strong>' + response.message + '</strong></p></div>' ); | |
| 8517 | - button.removeClass( 'frm_loading_button' ); | |
| 8518 | - jQuery( '.frm-addon-error' ).delay( 4000 ).fadeOut(); | |
| 8519 | - } | |
| 8520 | - } | |
| 8521 | - | |
| 8522 | - /* Templates */ | |
| 8523 | - | |
| 8524 | - function initNewFormModal() { | |
| 8525 | - var installFormTrigger, | |
| 8526 | - activeHoverIcons, | |
| 8527 | - $modal, | |
| 8528 | - handleError, | |
| 8529 | - handleEmailAddressError, | |
| 8530 | - handleConfirmEmailAddressError, | |
| 8531 | - showFreeTemplatesForm, | |
| 8532 | - firstLockedTemplate, | |
| 8533 | - isShowFreeTemplatesFormFirst, | |
| 8534 | - url, | |
| 8535 | - urlParams; | |
| 8536 | - | |
| 8537 | - url = new URL( window.location.href ); | |
| 8538 | - urlParams = url.searchParams; | |
| 8539 | - | |
| 8540 | - isShowFreeTemplatesFormFirst = urlParams.get( 'free-templates' ); | |
| 8541 | - | |
| 8542 | - jQuery( document ).on( 'click', '.frm-trigger-new-form-modal', triggerNewFormModal ); | |
| 8543 | - $modal = initModal( '#frm_new_form_modal', '600px' ); | |
| 8544 | - | |
| 8545 | - if ( false === $modal ) { | |
| 8546 | - return; | |
| 8547 | - } | |
| 8548 | - | |
| 8549 | - setTimeout( | |
| 8550 | - function() { | |
| 8551 | - $modal.get( 0 ).querySelector( '.postbox' ).style.display = 'block'; // Fixes pro issue #3508, prevent a conflict that hides the postbox in modal. | |
| 8552 | - }, | |
| 8553 | - 0 | |
| 8554 | - ); | |
| 8555 | - | |
| 8556 | - installFormTrigger = document.createElement( 'a' ); | |
| 8557 | - installFormTrigger.classList.add( 'frm-install-template', 'frm_hidden' ); | |
| 8558 | - document.body.appendChild( installFormTrigger ); | |
| 8559 | - | |
| 8560 | - jQuery( '.frm-install-template' ).on( 'click', function( event ) { | |
| 8561 | - var $h3Clone = jQuery( this ).closest( 'li, td' ).find( 'h3' ).clone(), | |
| 8562 | - nameLabel = document.getElementById( 'frm_new_name' ), | |
| 8563 | - descLabel = document.getElementById( 'frm_new_desc' ), | |
| 8564 | - oldName; | |
| 8565 | - | |
| 8566 | - $h3Clone.find( 'svg, .frm-plan-required-tag' ).remove(); | |
| 8567 | - oldName = $h3Clone.html().trim(); | |
| 8568 | - | |
| 8569 | - event.preventDefault(); | |
| 8570 | - | |
| 8571 | - document.getElementById( 'frm_template_name' ).value = oldName; | |
| 8572 | - document.getElementById( 'frm_link' ).value = this.attributes.rel.value; | |
| 8573 | - document.getElementById( 'frm_action_type' ).value = 'frm_install_template'; | |
| 8574 | - nameLabel.textContent = nameLabel.getAttribute( 'data-form' ); | |
| 8575 | - descLabel.textContent = descLabel.getAttribute( 'data-form' ); | |
| 8576 | - $modal.dialog( 'open' ); | |
| 8577 | - }); | |
| 8578 | - | |
| 8579 | - jQuery( document ).on( 'submit', '#frm-new-template', installTemplate ); | |
| 8580 | - | |
| 8581 | - jQuery( document ).on( 'click', '.frm-hover-icons .frm-preview-form', function( event ) { | |
| 8582 | - var $li, link, iframe, | |
| 8583 | - container = document.getElementById( 'frm-preview-block' ); | |
| 8584 | - | |
| 8585 | - event.preventDefault(); | |
| 8586 | - | |
| 8587 | - $li = jQuery( this ).closest( 'li' ); | |
| 8588 | - link = $li.attr( 'data-preview' ); | |
| 8589 | - | |
| 8590 | - if ( link.indexOf( ajaxurl ) > -1 ) { | |
| 8591 | - iframe = document.createElement( 'iframe' ); | |
| 8592 | - iframe.src = link; | |
| 8593 | - iframe.height = '400'; | |
| 8594 | - iframe.width = '100%'; | |
| 8595 | - container.innerHTML = ''; | |
| 8596 | - container.appendChild( iframe ); | |
| 8597 | - } else { | |
| 8598 | - frmApiPreview( container, link ); | |
| 8599 | - } | |
| 8600 | - | |
| 8601 | - jQuery( '#frm-preview-title' ).text( getStrippedTemplateName( $li ) ); | |
| 8602 | - $modal.attr( 'frm-page', 'preview' ); | |
| 8603 | - activeHoverIcons = jQuery( this ).closest( '.frm-hover-icons' ); | |
| 8604 | - }); | |
| 8605 | - | |
| 8606 | - jQuery( document ).on( 'click', 'li.frm-ready-made-solution[data-href]', function() { | |
| 8607 | - window.location = this.getAttribute( 'data-href' ); | |
| 8608 | - }); | |
| 8609 | - | |
| 8610 | - jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-create-form', function( event ) { | |
| 8611 | - var $li, name, link, action; | |
| 8612 | - | |
| 8613 | - event.preventDefault(); | |
| 8614 | - | |
| 8615 | - $li = jQuery( this ).closest( 'li' ); | |
| 8616 | - | |
| 8617 | - if ( $li.is( '[data-href]' ) ) { | |
| 8618 | - window.location = $li.attr( 'data-href' ); | |
| 8619 | - return; | |
| 8620 | - } | |
| 8621 | - | |
| 8622 | - if ( $li.hasClass( 'frm-add-blank-form' ) ) { | |
| 8623 | - name = link = ''; | |
| 8624 | - action = 'frm_install_form'; | |
| 8625 | - } else if ( $li.is( '[data-rel]' ) ) { | |
| 8626 | - name = getStrippedTemplateName( $li ); | |
| 8627 | - link = $li.attr( 'data-rel' ); | |
| 8628 | - action = 'frm_install_template'; | |
| 8629 | - } else { | |
| 8630 | - return; | |
| 8631 | - } | |
| 8632 | - | |
| 8633 | - transitionToAddDetails( $modal, name, link, action ); | |
| 8634 | - }); | |
| 8635 | - | |
| 8636 | - // Welcome page modals. | |
| 8637 | - jQuery( document ).on( 'click', '.frm-create-blank-form', function( event ) { | |
| 8638 | - event.preventDefault(); | |
| 8639 | - jQuery( '.frm-trigger-new-form-modal' ).trigger( 'click' ); | |
| 8640 | - transitionToAddDetails( $modal, '', '', 'frm_install_form' ); | |
| 8641 | - | |
| 8642 | - // Close the modal with the cancel button. | |
| 8643 | - jQuery( '.frm-modal-cancel.frm-back-to-all-templates' ).on( 'click', function() { | |
| 8644 | - jQuery( '.ui-widget-overlay' ).trigger( 'click' ); | |
| 8645 | - }); | |
| 8646 | - }); | |
| 8647 | - | |
| 8648 | - 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 ) { | |
| 8649 | - var $hoverIcons, $trigger, | |
| 8650 | - $li = jQuery( this ).closest( 'li' ), | |
| 8651 | - triggerClass = $li.hasClass( 'frm-locked-template' ) ? 'frm-unlock-form' : 'frm-create-form'; | |
| 8652 | - | |
| 8653 | - $hoverIcons = $li.find( '.frm-hover-icons' ); | |
| 8654 | - if ( ! $hoverIcons.length ) { | |
| 8655 | - $li.trigger( 'mouseover' ); | |
| 8656 | - $hoverIcons = $li.find( '.frm-hover-icons' ); | |
| 8657 | - $hoverIcons.hide(); | |
| 8658 | - } | |
| 8659 | - | |
| 8660 | - $trigger = $hoverIcons.find( '.' + triggerClass ); | |
| 8661 | - $trigger.trigger( 'click' ); | |
| 8662 | - }); | |
| 8663 | - | |
| 8664 | - jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-delete-form', function( event ) { | |
| 8665 | - var $li, | |
| 8666 | - trigger; | |
| 8667 | - | |
| 8668 | - event.preventDefault(); | |
| 8669 | - | |
| 8670 | - $li = jQuery( this ).closest( 'li' ); | |
| 8671 | - $li.addClass( 'frm-deleting' ); | |
| 8672 | - trigger = document.createElement( 'a' ); | |
| 8673 | - trigger.setAttribute( 'href', '#' ); | |
| 8674 | - trigger.setAttribute( 'data-id', $li.attr( 'data-formid' ) ); | |
| 8675 | - $li.attr( 'id', 'frm-template-custom-' + $li.attr( 'data-formid' ) ); | |
| 8676 | - jQuery( trigger ).on( 'click', trashTemplate ); | |
| 8677 | - trigger.click(); | |
| 8678 | - setTemplateCount( $li.closest( '.accordion-section' ).get( 0 ) ); | |
| 8679 | - }); | |
| 8680 | - | |
| 8681 | - showFreeTemplatesForm = function( $el ) { | |
| 8682 | - var formContainer = document.getElementById( 'frmapi-email-form' ); | |
| 8683 | - jQuery.ajax({ | |
| 8684 | - dataType: 'json', | |
| 8685 | - url: formContainer.getAttribute( 'data-url' ), | |
| 8686 | - success: function( json ) { | |
| 8687 | - var form = json.renderedHtml; | |
| 8688 | - form = form.replace( /<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi, '' ); | |
| 8689 | - formContainer.innerHTML = form; | |
| 8690 | - } | |
| 8691 | - }); | |
| 8692 | - | |
| 8693 | - $modal.attr( 'frm-page', 'email' ); | |
| 8694 | - $modal.attr( 'frm-this-form', $el.attr( 'data-key' ) ); | |
| 8695 | - $el.append( installFormTrigger ); | |
| 8696 | - }; | |
| 8697 | - | |
| 8698 | - jQuery( document ).on( 'click', 'li.frm-locked-template .frm-hover-icons .frm-unlock-form', function( event ) { | |
| 8699 | - var $li, | |
| 8700 | - activePage; | |
| 8701 | - | |
| 8702 | - event.preventDefault(); | |
| 8703 | - | |
| 8704 | - $li = jQuery( this ).closest( '.frm-locked-template' ); | |
| 8705 | - | |
| 8706 | - if ( $li.hasClass( 'frm-free-template' ) ) { | |
| 8707 | - showFreeTemplatesForm( $li ); | |
| 8708 | - return; | |
| 8709 | - } | |
| 8710 | - | |
| 8711 | - if ( $modal.hasClass( 'frm-expired' ) ) { | |
| 8712 | - activePage = 'renew'; | |
| 8713 | - } else { | |
| 8714 | - activePage = 'upgrade'; | |
| 8715 | - } | |
| 8716 | - | |
| 8717 | - $modal.attr( 'frm-page', activePage ); | |
| 8718 | - }); | |
| 8719 | - | |
| 8720 | - jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop', function() { | |
| 8721 | - jQuery( this ) | |
| 8722 | - .closest( '.accordion-section-content' ).css( 'overflow', 'visible' ) | |
| 8723 | - .closest( '.accordion-section' ).css( 'z-index', 1 ); | |
| 8724 | - }); | |
| 8725 | - | |
| 8726 | - jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop + .frm-dropdown-menu .frm-build-template', function() { | |
| 8727 | - var name = this.getAttribute( 'data-fullname' ), | |
| 8728 | - link = this.getAttribute( 'data-formid' ), | |
| 8729 | - action = 'frm_build_template'; | |
| 8730 | - transitionToAddDetails( $modal, name, link, action ); | |
| 8731 | - }); | |
| 8732 | - | |
| 8733 | - handleError = function( inputId, errorId, type, message ) { | |
| 8734 | - var $error = jQuery( errorId ); | |
| 8735 | - $error.removeClass( 'frm_hidden' ).attr( 'frm-error', type ); | |
| 8736 | - | |
| 8737 | - if ( typeof message !== 'undefined' ) { | |
| 8738 | - $error.find( 'span[frm-error="' + type + '"]' ).text( message ); | |
| 8739 | - } | |
| 8740 | - | |
| 8741 | - jQuery( inputId ).one( 'keyup', function() { | |
| 8742 | - $error.addClass( 'frm_hidden' ); | |
| 8743 | - }); | |
| 8744 | - }; | |
| 8745 | - | |
| 8746 | - handleEmailAddressError = function( type ) { | |
| 8747 | - handleError( '#frm_leave_email', '#frm_leave_email_error', type ); | |
| 8748 | - }; | |
| 8749 | - | |
| 8750 | - jQuery( document ).on( 'click', '#frm-add-my-email-address', function( event ) { | |
| 8751 | - var email = document.getElementById( 'frm_leave_email' ).value.trim(), | |
| 8752 | - regex, | |
| 8753 | - $hiddenForm, | |
| 8754 | - $hiddenEmailField; | |
| 8755 | - | |
| 8756 | - event.preventDefault(); | |
| 8757 | - | |
| 8758 | - if ( '' === email ) { | |
| 8759 | - handleEmailAddressError( 'empty' ); | |
| 8760 | - return; | |
| 8761 | - } | |
| 8762 | - | |
| 8763 | - 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; | |
| 8764 | - | |
| 8765 | - if ( regex.test( email ) === false ) { | |
| 8766 | - handleEmailAddressError( 'invalid' ); | |
| 8767 | - return; | |
| 8768 | - } | |
| 8769 | - | |
| 8770 | - $hiddenForm = jQuery( '#frmapi-email-form' ).find( 'form' ); | |
| 8771 | - $hiddenEmailField = $hiddenForm.find( '[type="email"]' ).not( '.frm_verify' ); | |
| 8772 | - if ( ! $hiddenEmailField.length ) { | |
| 8773 | - return; | |
| 8774 | - } | |
| 8775 | - | |
| 8776 | - $hiddenEmailField.val( email ); | |
| 8777 | - jQuery.ajax({ | |
| 8778 | - type: 'POST', | |
| 8779 | - url: $hiddenForm.attr( 'action' ), | |
| 8780 | - data: $hiddenForm.serialize() + '&action=frm_forms_preview' | |
| 8781 | - }).done( function( data ) { | |
| 8782 | - var message = jQuery( data ).find( '.frm_message' ).text().trim(); | |
| 8783 | - if ( message.indexOf( 'Thanks!' ) >= 0 ) { | |
| 8784 | - $modal.attr( 'frm-page', 'code' ); | |
| 8785 | - } else { | |
| 8786 | - handleEmailAddressError( 'invalid' ); | |
| 8787 | - } | |
| 8788 | - }); | |
| 8789 | - }); | |
| 8790 | - | |
| 8791 | - handleConfirmEmailAddressError = function( type, message ) { | |
| 8792 | - handleError( '#frm_code_from_email', '#frm_code_from_email_error', type, message ); | |
| 8793 | - }; | |
| 8794 | - | |
| 8795 | - jQuery( document ).on( 'click', '.frm-confirm-email-address', function( event ) { | |
| 8796 | - var code = document.getElementById( 'frm_code_from_email' ).value.trim(); | |
| 8797 | - | |
| 8798 | - event.preventDefault(); | |
| 8799 | - | |
| 8800 | - if ( '' === code ) { | |
| 8801 | - handleConfirmEmailAddressError( 'empty' ); | |
| 8802 | - return; | |
| 8803 | - } | |
| 8804 | - | |
| 8805 | - jQuery.ajax({ | |
| 8806 | - type: 'POST', | |
| 8807 | - url: ajaxurl, | |
| 8808 | - dataType: 'json', | |
| 8809 | - data: { | |
| 8810 | - action: 'template_api_signup', | |
| 8811 | - nonce: frmGlobal.nonce, | |
| 8812 | - code: code, | |
| 8813 | - key: $modal.attr( 'frm-this-form' ) | |
| 8814 | - }, | |
| 8815 | - success: function( response ) { | |
| 8816 | - if ( response.success ) { | |
| 8817 | - if ( isShowFreeTemplatesFormFirst ) { | |
| 8818 | - // Remove free-templates param from URL then reload page. | |
| 8819 | - urlParams.delete( 'free-templates' ); | |
| 8820 | - url.search = urlParams.toString(); | |
| 8821 | - window.location.href = url.toString(); | |
| 8822 | - | |
| 8823 | - return; | |
| 8824 | - } | |
| 8825 | - | |
| 8826 | - if ( typeof response.data !== 'undefined' && typeof response.data.url !== 'undefined' ) { | |
| 8827 | - installFormTrigger.setAttribute( 'rel', response.data.url ); | |
| 8828 | - installFormTrigger.click(); | |
| 8829 | - $modal.attr( 'frm-page', 'details' ); | |
| 8830 | - | |
| 8831 | - const hookName = 'frm_new_form_modal_form'; | |
| 8832 | - wp.hooks.doAction( hookName, $modal ); | |
| 8833 | - | |
| 8834 | - document.getElementById( 'frm_action_type' ).value = 'frm_install_template'; | |
| 8835 | - | |
| 8836 | - if ( typeof response.data.urlByKey !== 'undefined' ) { | |
| 8837 | - updateTemplateModalFreeUrls( response.data.urlByKey ); | |
| 8838 | - } | |
| 8839 | - } | |
| 8840 | - } else { | |
| 8841 | - if ( Array.isArray( response.data ) && response.data.length ) { | |
| 8842 | - handleConfirmEmailAddressError( 'custom', response.data[0].message ); | |
| 8843 | - } else { | |
| 8844 | - handleConfirmEmailAddressError( 'wrong-code' ); | |
| 8845 | - } | |
| 8846 | - | |
| 8847 | - jQuery( '#frm_code_from_email_options' ).removeClass( 'frm_hidden' ); | |
| 8848 | - } | |
| 8849 | - } | |
| 8850 | - }); | |
| 8851 | - }); | |
| 8852 | - | |
| 8853 | - jQuery( document ).on( 'click', '#frm-change-email-address', function() { | |
| 8854 | - $modal.attr( 'frm-page', 'email' ); | |
| 8855 | - }); | |
| 8856 | - | |
| 8857 | - jQuery( document ).on( 'click', '#frm-resend-code', function() { | |
| 8858 | - document.getElementById( 'frm_code_from_email' ).value = ''; | |
| 8859 | - jQuery( '#frm_code_from_email_options, #frm_code_from_email_error' ).addClass( 'frm_hidden' ); | |
| 8860 | - document.getElementById( 'frm-add-my-email-address' ).click(); | |
| 8861 | - }); | |
| 8862 | - | |
| 8863 | - 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 ) { | |
| 8864 | - document.getElementById( 'frm-create-title' ).removeAttribute( 'frm-type' ); | |
| 8865 | - $modal.attr( 'frm-page', 'create' ); | |
| 8866 | - }); | |
| 8867 | - | |
| 8868 | - jQuery( document ).on( 'click', '.frm-use-this-template', function( event ) { | |
| 8869 | - var $trigger; | |
| 8870 | - | |
| 8871 | - event.preventDefault(); | |
| 8872 | - | |
| 8873 | - $trigger = activeHoverIcons.find( '.frm-create-form' ); | |
| 8874 | - if ( $trigger.closest( '.frm-selectable' ).hasClass( 'frm-locked-template' ) ) { | |
| 8875 | - $trigger = activeHoverIcons.find( '.frm-unlock-form' ); | |
| 8876 | - } | |
| 8877 | - | |
| 8878 | - $trigger.trigger( 'click' ); | |
| 8879 | - }); | |
| 8880 | - | |
| 8881 | - jQuery( document ).on( 'click', '.frm-submit-new-template', function( event ) { | |
| 8882 | - var button; | |
| 8883 | - event.preventDefault(); | |
| 8884 | - button = document.getElementById( 'frm-new-template' ).querySelector( 'button' ); | |
| 8885 | - if ( null !== button ) { | |
| 8886 | - button.click(); | |
| 8887 | - } | |
| 8888 | - }); | |
| 8889 | - | |
| 8890 | - if ( urlParams.get( 'triggerNewFormModal' ) ) { | |
| 8891 | - triggerNewFormModal(); | |
| 8892 | - | |
| 8893 | - if ( isShowFreeTemplatesFormFirst ) { | |
| 8894 | - firstLockedTemplate = jQuery( 'li.frm-locked-template.frm-free-template' ).eq( 0 ); | |
| 8895 | - | |
| 8896 | - if ( firstLockedTemplate.length ) { | |
| 8897 | - showFreeTemplatesForm( firstLockedTemplate ); | |
| 8898 | - } | |
| 8899 | - } | |
| 8900 | - } | |
| 8901 | - | |
| 8902 | - initSearch( 'template-search-input', 'control-section accordion-section' ); | |
| 8903 | - } | |
| 8904 | - | |
| 8905 | - function initSearch( inputID, itemClass ) { | |
| 8906 | - const searchInput = document.getElementById( inputID ); | |
| 8907 | - | |
| 8908 | - if ( itemClass === 'control-section accordion-section' ) { | |
| 8909 | - itemClass = 'frm-selectable frm-searchable-template'; | |
| 8910 | - | |
| 8911 | - const handleTemplateSearch = () => { | |
| 8912 | - document.querySelectorAll( '.control-section.accordion-section' ).forEach( category => { | |
| 8913 | - const found = category.querySelector( '.frm-selectable.frm-searchable-template:not(.frm_hidden)' ) || ( searchInput.value === '' && category.querySelector( '#frm-template-drop' ) ); | |
| 8914 | - if ( found ) { | |
| 8915 | - setTemplateCount( category ); | |
| 8916 | - } | |
| 8917 | - category.classList.toggle( 'frm_hidden', ! found ); | |
| 8918 | - }); | |
| 8919 | - }; | |
| 8920 | - | |
| 8921 | - frmDom.search.init( searchInput, itemClass, { handleSearchResult: handleTemplateSearch }); | |
| 8922 | - | |
| 8923 | - } else { | |
| 8924 | - if ( itemClass === 'frm-searchable-template frm-ready-made-solution' ) { | |
| 8925 | - Array.from( document.getElementsByClassName( itemClass ) ).forEach( item => { | |
| 8926 | - let innerText = ''; | |
| 8927 | - innerText = item.querySelector( 'h3' ).innerText; | |
| 8928 | - item.setAttribute( 'frm-search-text', innerText.toLowerCase() ); | |
| 8929 | - }); | |
| 8930 | - } | |
| 8931 | - frmDom.search.init( searchInput, itemClass ); | |
| 8932 | - } | |
| 8933 | - | |
| 8934 | - } | |
| 8935 | - | |
| 8936 | - function updateTemplateModalFreeUrls( urlByKey ) { | |
| 8937 | - jQuery( '#frm_new_form_modal' ).find( '.frm-selectable[data-key]' ).each( function() { | |
| 8938 | - var $template = jQuery( this ), | |
| 8939 | - key = $template.attr( 'data-key' ); | |
| 8940 | - if ( 'undefined' !== typeof urlByKey[ key ]) { | |
| 8941 | - $template.removeClass( 'frm-locked-template' ); | |
| 8942 | - $template.find( 'h3 svg' ).remove(); // remove the lock from the title | |
| 8943 | - $template.attr( 'data-rel', urlByKey[ key ]); | |
| 8944 | - } | |
| 8945 | - }); | |
| 8946 | - } | |
| 8947 | - | |
| 8948 | - function transitionToAddDetails( $modal, name, link, action ) { | |
| 8949 | - var nameLabel = document.getElementById( 'frm_new_name' ), | |
| 8950 | - descLabel = document.getElementById( 'frm_new_desc' ), | |
| 8951 | - type = [ 'frm_install_template', 'frm_install_form' ].indexOf( action ) >= 0 ? 'form' : 'template', | |
| 8952 | - templateNameInput = document.getElementById( 'frm_template_name' ); | |
| 8953 | - | |
| 8954 | - templateNameInput.value = name; | |
| 8955 | - document.getElementById( 'frm_link' ).value = link; | |
| 8956 | - document.getElementById( 'frm_action_type' ).value = action; | |
| 8957 | - nameLabel.textContent = nameLabel.getAttribute( 'data-' + type ); | |
| 8958 | - if ( descLabel !== null ) { | |
| 8959 | - descLabel.textContent = descLabel.getAttribute( 'data-' + type ); | |
| 8960 | - } | |
| 8961 | - | |
| 8962 | - document.getElementById( 'frm-create-title' ).setAttribute( 'frm-type', type ); | |
| 8963 | - | |
| 8964 | - $modal.attr( 'frm-page', 'details' ); | |
| 8965 | - | |
| 8966 | - const hookName = 'frm_new_form_modal_form'; | |
| 8967 | - wp.hooks.doAction( hookName, $modal ); | |
| 8968 | - | |
| 8969 | - if ( '' === name ) { | |
| 8970 | - templateNameInput.focus(); | |
| 8971 | - } | |
| 8972 | - } | |
| 8973 | - | |
| 8974 | - function getStrippedTemplateName( $li ) { | |
| 8975 | - var $clone = $li.find( 'h3' ).clone(); | |
| 8976 | - $clone.find( 'svg, .frm-plan-required-tag, .frm-new-pill' ).remove(); | |
| 8977 | - return $clone.html().trim(); | |
| 8978 | - } | |
| 8979 | - | |
| 8980 | - function setTemplateCount( category, searchableTemplates ) { | |
| 8981 | - var count, | |
| 8982 | - templateIndex, | |
| 8983 | - availableCounter, | |
| 8984 | - availableCount; | |
| 8985 | - | |
| 8986 | - if ( typeof searchableTemplates === 'undefined' ) { | |
| 8987 | - searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden):not(.frm-deleting)' ); | |
| 8988 | - } | |
| 8989 | - | |
| 8990 | - count = searchableTemplates.length; | |
| 8991 | - category.querySelector( '.frm-template-count' ).textContent = count; | |
| 8992 | - | |
| 8993 | - jQuery( category ).find( '.frm-templates-plural' ).toggleClass( 'frm_hidden', count === 1 ); | |
| 8994 | - jQuery( category ).find( '.frm-templates-singular' ).toggleClass( 'frm_hidden', count !== 1 ); | |
| 8995 | - | |
| 8996 | - availableCounter = category.querySelector( '.frm-available-templates-count' ); | |
| 8997 | - if ( availableCounter !== null ) { | |
| 8998 | - availableCount = 0; | |
| 8999 | - for ( templateIndex in searchableTemplates ) { | |
| 9000 | - if ( ! isNaN( templateIndex ) && ! searchableTemplates[ templateIndex ].classList.contains( 'frm-locked-template' ) ) { | |
| 9001 | - availableCount++; | |
| 9002 | - } | |
| 9003 | - } | |
| 9004 | - | |
| 9005 | - availableCounter.textContent = availableCount; | |
| 9006 | - } | |
| 9007 | - } | |
| 9008 | - | |
| 9009 | - function initSelectionAutocomplete() { | |
| 9010 | - frmDom.autocomplete.initSelectionAutocomplete(); | |
| 9011 | - } | |
| 9012 | - | |
| 9013 | - function nextInstallStep( thisStep ) { | |
| 9014 | - thisStep.classList.add( 'frm_grey' ); | |
| 9015 | - thisStep.nextElementSibling.classList.remove( 'frm_grey' ); | |
| 9016 | - } | |
| 9017 | - | |
| 9018 | - function frmApiPreview( cont, link ) { | |
| 9019 | - cont.innerHTML = '<div class="frm-wait"></div>'; | |
| 9020 | - jQuery.ajax({ | |
| 9021 | - dataType: 'json', | |
| 9022 | - url: link, | |
| 9023 | - success: function( json ) { | |
| 9024 | - var form = json.renderedHtml; | |
| 9025 | - form = form.replace( /<script\b[^<]*(js\/jquery\/jquery)[^<]*><\/script>/gi, '' ); | |
| 9026 | - form = form.replace( /<link\b[^>]*(jquery-ui.min.css)[^>]*>/gi, '' ); | |
| 9027 | - form = form.replace( ' frm_logic_form ', ' ' ); | |
| 9028 | - form = form.replace( '<form ', '<form onsubmit="event.preventDefault();" ' ); | |
| 9029 | - cont.innerHTML = '<div class="frm-wait" id="frm-remove-me"></div><div class="frm-fade" id="frm-show-me">' + | |
| 9030 | - form + '</div>'; | |
| 9031 | - setTimeout( function() { | |
| 9032 | - document.getElementById( 'frm-remove-me' ).style.display = 'none'; | |
| 9033 | - document.getElementById( 'frm-show-me' ).style.opacity = '1'; | |
| 9034 | - }, 300 ); | |
| 9035 | - } | |
| 9036 | - }); | |
| 9037 | - } | |
| 9038 | - | |
| 9039 | - function installTemplateFieldset( e ) { | |
| 9040 | - /*jshint validthis:true */ | |
| 9041 | - var fieldset = this.parentNode.parentNode, | |
| 9042 | - action = fieldset.elements.type.value, | |
| 9043 | - button = this; | |
| 9044 | - e.preventDefault(); | |
| 9045 | - button.classList.add( 'frm_loading_button' ); | |
| 9046 | - installNewForm( fieldset, action, button ); | |
| 9047 | - } | |
| 9048 | - | |
| 9049 | - function installTemplate( e ) { | |
| 9050 | - /*jshint validthis:true */ | |
| 9051 | - var action = this.elements.type.value, | |
| 9052 | - button = this.querySelector( 'button' ); | |
| 9053 | - e.preventDefault(); | |
| 9054 | - button.classList.add( 'frm_loading_button' ); | |
| 9055 | - installNewForm( this, action, button ); | |
| 9056 | - } | |
| 9057 | - | |
| 9058 | - function installNewForm( form, action, button ) { | |
| 9059 | - const formData = formToData( form ); | |
| 9060 | - const formName = formData.template_name; | |
| 9061 | - const formDesc = formData.template_desc; | |
| 9062 | - const link = form.elements.link.value; | |
| 9063 | - | |
| 9064 | - let data = { | |
| 9065 | - action: action, | |
| 9066 | - xml: link, | |
| 9067 | - name: formName, | |
| 9068 | - desc: formDesc, | |
| 9069 | - form: JSON.stringify( formData ), | |
| 9070 | - nonce: frmGlobal.nonce | |
| 9071 | - }; | |
| 9072 | - | |
| 9073 | - const hookName = 'frm_before_install_new_form'; | |
| 9074 | - const filterArgs = { formData }; | |
| 9075 | - data = wp.hooks.applyFilters( hookName, data, filterArgs ); | |
| 9076 | - | |
| 9077 | - postAjax( data, function( response ) { | |
| 9078 | - if ( typeof response.redirect !== 'undefined' ) { | |
| 9079 | - const redirect = response.redirect; | |
| 9080 | - if ( typeof form.elements.redirect === 'undefined' ) { | |
| 9081 | - window.location = redirect; | |
| 9082 | - } else { | |
| 9083 | - const href = document.getElementById( 'frm-redirect-link' ); | |
| 9084 | - if ( typeof link !== 'undefined' && href !== null ) { | |
| 9085 | - // Show the next installation step. | |
| 9086 | - href.setAttribute( 'href', redirect ); | |
| 9087 | - href.classList.remove( 'frm_grey', 'disabled' ); | |
| 9088 | - nextInstallStep( form.parentNode.parentNode ); | |
| 9089 | - button.classList.add( 'frm_grey', 'disabled' ); | |
| 9090 | - } | |
| 9091 | - } | |
| 9092 | - } else { | |
| 9093 | - jQuery( '.spinner' ).css( 'visibility', 'hidden' ); | |
| 9094 | - | |
| 9095 | - // Show response.message | |
| 9096 | - if ( 'string' === typeof response.message ) { | |
| 9097 | - showInstallFormErrorModal( response.message ); | |
| 9098 | - } | |
| 9099 | - } | |
| 9100 | - button.classList.remove( 'frm_loading_button' ); | |
| 9101 | - }); | |
| 9102 | - } | |
| 9103 | - | |
| 9104 | - function showInstallFormErrorModal( message ) { | |
| 9105 | - const modalContent = div( message ); | |
| 9106 | - modalContent.style.padding = '20px 40px'; | |
| 9107 | - const modal = frmDom.modal.maybeCreateModal( | |
| 9108 | - 'frmInstallFormErrorModal', | |
| 9109 | - { | |
| 9110 | - title: __( 'Unable to install template', 'formidable' ), | |
| 9111 | - content: modalContent | |
| 9112 | - } | |
| 9113 | - ); | |
| 9114 | - modal.classList.add( 'frm_common_modal' ); | |
| 9115 | - } | |
| 9116 | - | |
| 9117 | - function handleCaptchaTypeChange( e ) { | |
| 9118 | - const thresholdContainer = document.getElementById( 'frm_captcha_threshold_container' ); | |
| 9119 | - if ( thresholdContainer ) { | |
| 9120 | - thresholdContainer.classList.toggle( 'frm_hidden', 'v3' !== e.target.value ); | |
| 9121 | - } | |
| 9122 | - } | |
| 9123 | - | |
| 9124 | - function trashTemplate( e ) { | |
| 9125 | - /*jshint validthis:true */ | |
| 9126 | - var id = this.getAttribute( 'data-id' ); | |
| 9127 | - e.preventDefault(); | |
| 9128 | - | |
| 9129 | - data = { | |
| 9130 | - action: 'frm_forms_trash', | |
| 9131 | - id: id, | |
| 9132 | - nonce: frmGlobal.nonce | |
| 9133 | - }; | |
| 9134 | - postAjax( data, function() { | |
| 9135 | - var card = document.getElementById( 'frm-template-custom-' + id ); | |
| 9136 | - fadeOut( card, function() { | |
| 9137 | - card.parentNode.removeChild( card ); | |
| 9138 | - }); | |
| 9139 | - }); | |
| 9140 | - } | |
| 9141 | - | |
| 9142 | - function searchContent() { | |
| 9143 | - /*jshint validthis:true */ | |
| 9144 | - var i, | |
| 9145 | - regEx = false, | |
| 9146 | - searchText = this.value.toLowerCase(), | |
| 9147 | - toSearch = this.getAttribute( 'data-tosearch' ), | |
| 9148 | - items = document.getElementsByClassName( toSearch ); | |
| 9149 | - | |
| 9150 | - if ( this.tagName === 'SELECT' ) { | |
| 9151 | - searchText = selectedOptions( this ); | |
| 9152 | - searchText = searchText.join( '|' ).toLowerCase(); | |
| 9153 | - regEx = true; | |
| 9154 | - } | |
| 9155 | - | |
| 9156 | - if ( toSearch === 'frm-action' && searchText !== '' ) { | |
| 9157 | - var addons = document.getElementById( 'frm_email_addon_menu' ).classList; | |
| 9158 | - addons.remove( 'frm-all-actions' ); | |
| 9159 | - addons.add( 'frm-limited-actions' ); | |
| 9160 | - } | |
| 9161 | - | |
| 9162 | - for ( i = 0; i < items.length; i++ ) { | |
| 9163 | - var innerText = items[i].innerText.toLowerCase(); | |
| 9164 | - | |
| 9165 | - const itemCanBeShown = ! ( getExportOption() === 'xml' && items[i].classList.contains( 'frm-is-repeater' ) ); | |
| 9166 | - if ( searchText === '' ) { | |
| 9167 | - if ( itemCanBeShown ) { | |
| 9168 | - items[i].classList.remove( 'frm_hidden' ); | |
| 9169 | - } | |
| 9170 | - items[i].classList.remove( 'frm-search-result' ); | |
| 9171 | - } else if ( ( regEx && new RegExp( searchText ).test( innerText ) ) || innerText.indexOf( searchText ) >= 0 ) { | |
| 9172 | - if ( itemCanBeShown ) { | |
| 9173 | - items[i].classList.remove( 'frm_hidden' ); | |
| 9174 | - } | |
| 9175 | - items[i].classList.add( 'frm-search-result' ); | |
| 9176 | - } else { | |
| 9177 | - items[i].classList.add( 'frm_hidden' ); | |
| 9178 | - items[i].classList.remove( 'frm-search-result' ); | |
| 9179 | - } | |
| 9180 | - } | |
| 9181 | - | |
| 9182 | - jQuery( this ).trigger( 'frmAfterSearch' ); | |
| 9183 | - } | |
| 9184 | - | |
| 9185 | - function stopPropagation( e ) { | |
| 9186 | - e.stopPropagation(); | |
| 9187 | - } | |
| 9188 | - | |
| 9189 | - /* Helpers */ | |
| 9190 | - | |
| 9191 | - function selectedOptions( select ) { | |
| 9192 | - var opt, | |
| 9193 | - result = [], | |
| 9194 | - options = select && select.options; | |
| 9195 | - | |
| 9196 | - for ( var i = 0, iLen = options.length; i < iLen; i++ ) { | |
| 9197 | - opt = options[i]; | |
| 9198 | - | |
| 9199 | - if ( opt.selected ) { | |
| 9200 | - result.push( opt.value ); | |
| 9201 | - } | |
| 9202 | - } | |
| 9203 | - return result; | |
| 9204 | - } | |
| 9205 | - | |
| 9206 | - function triggerEvent( element, event ) { | |
| 9207 | - var evt = document.createEvent( 'HTMLEvents' ); | |
| 9208 | - evt.initEvent( event, false, true ); | |
| 9209 | - element.dispatchEvent( evt ); | |
| 9210 | - } | |
| 9211 | - | |
| 9212 | - function postAjax( data, success ) { | |
| 9213 | - let response; | |
| 9214 | - | |
| 9215 | - const xmlHttp = new XMLHttpRequest(); | |
| 9216 | - const params = typeof data === 'string' ? data : Object.keys( data ).map( | |
| 9217 | - function( k ) { | |
| 9218 | - return encodeURIComponent( k ) + '=' + encodeURIComponent( data[k]); | |
| 9219 | - } | |
| 9220 | - ).join( '&' ); | |
| 9221 | - | |
| 9222 | - xmlHttp.open( 'post', ajaxurl, true ); | |
| 9223 | - xmlHttp.onreadystatechange = function() { | |
| 9224 | - if ( xmlHttp.readyState > 3 && xmlHttp.status == 200 ) { | |
| 9225 | - response = xmlHttp.responseText; | |
| 9226 | - try { | |
| 9227 | - response = JSON.parse( response ); | |
| 9228 | - } catch ( e ) { | |
| 9229 | - // The response may not be JSON, so just return it. | |
| 9230 | - } | |
| 9231 | - success( response ); | |
| 9232 | - } | |
| 9233 | - }; | |
| 9234 | - xmlHttp.setRequestHeader( 'X-Requested-With', 'XMLHttpRequest' ); | |
| 9235 | - xmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' ); | |
| 9236 | - xmlHttp.send( params ); | |
| 9237 | - return xmlHttp; | |
| 9238 | - } | |
| 9239 | - | |
| 9240 | - function fadeOut( element, success ) { | |
| 9241 | - element.classList.add( 'frm-fade' ); | |
| 9242 | - setTimeout( success, 1000 ); | |
| 9243 | - } | |
| 9244 | - | |
| 9245 | - function invisible( classes ) { | |
| 9246 | - jQuery( classes ).css( 'visibility', 'hidden' ); | |
| 9247 | - } | |
| 9248 | - | |
| 9249 | - function visible( classes ) { | |
| 9250 | - jQuery( classes ).css( 'visibility', 'visible' ); | |
| 9251 | - } | |
| 9252 | - | |
| 9253 | - function initModal( id, width ) { | |
| 9254 | - const $info = jQuery( id ); | |
| 9255 | - if ( ! $info.length ) { | |
| 9256 | - return false; | |
| 9257 | - } | |
| 9258 | - | |
| 9259 | - if ( typeof width === 'undefined' ) { | |
| 9260 | - width = '550px'; | |
| 9261 | - } | |
| 9262 | - | |
| 9263 | - const dialogArgs = { | |
| 9264 | - dialogClass: 'frm-dialog', | |
| 9265 | - modal: true, | |
| 9266 | - autoOpen: false, | |
| 9267 | - closeOnEscape: true, | |
| 9268 | - width: width, | |
| 9269 | - resizable: false, | |
| 9270 | - draggable: false, | |
| 9271 | - open: function() { | |
| 9272 | - jQuery( '.ui-dialog-titlebar' ).addClass( 'frm_hidden' ).removeClass( 'ui-helper-clearfix' ); | |
| 9273 | - jQuery( '#wpwrap' ).addClass( 'frm_overlay' ); | |
| 9274 | - jQuery( '.frm-dialog' ).removeClass( 'ui-widget ui-widget-content ui-corner-all' ); | |
| 9275 | - $info.removeClass( 'ui-dialog-content ui-widget-content' ); | |
| 9276 | - bindClickForDialogClose( $info ); | |
| 9277 | - }, | |
| 9278 | - close: function() { | |
| 9279 | - jQuery( '#wpwrap' ).removeClass( 'frm_overlay' ); | |
| 9280 | - jQuery( '.spinner' ).css( 'visibility', 'hidden' ); | |
| 9281 | - | |
| 9282 | - this.removeAttribute( 'data-option-type' ); | |
| 9283 | - const optionType = document.getElementById( 'bulk-option-type' ); | |
| 9284 | - if ( optionType ) { | |
| 9285 | - optionType.value = ''; | |
| 9286 | - } | |
| 9287 | - } | |
| 9288 | - }; | |
| 9289 | - | |
| 9290 | - $info.dialog( dialogArgs ); | |
| 9291 | - | |
| 9292 | - return $info; | |
| 9293 | - } | |
| 9294 | - | |
| 9295 | - function toggle( cname, id ) { | |
| 9296 | - if ( id === '#' ) { | |
| 9297 | - var cont = document.getElementById( cname ); | |
| 9298 | - var hidden = cont.style.display; | |
| 9299 | - if ( hidden === 'none' ) { | |
| 9300 | - cont.style.display = 'block'; | |
| 9301 | - } else { | |
| 9302 | - cont.style.display = 'none'; | |
| 9303 | - } | |
| 9304 | - } else { | |
| 9305 | - var vis = cname.is( ':visible' ); | |
| 9306 | - if ( vis ) { | |
| 9307 | - cname.hide(); | |
| 9308 | - } else { | |
| 9309 | - cname.show(); | |
| 9310 | - } | |
| 9311 | - } | |
| 9312 | - } | |
| 9313 | - | |
| 9314 | - function removeWPUnload() { | |
| 9315 | - window.onbeforeunload = null; | |
| 9316 | - var w = jQuery( window ); | |
| 9317 | - w.off( 'beforeunload.widgets' ); | |
| 9318 | - w.off( 'beforeunload.edit-post' ); | |
| 9319 | - } | |
| 9320 | - | |
| 9321 | - function addMultiselectLabelListener() { | |
| 9322 | - const clickListener = ( e ) => { | |
| 9323 | - if ( 'LABEL' !== e.target.nodeName ) { | |
| 9324 | - return; | |
| 9325 | - } | |
| 9326 | - | |
| 9327 | - const labelFor = e.target.getAttribute( 'for' ); | |
| 9328 | - if ( ! labelFor ) { | |
| 9329 | - return; | |
| 9330 | - } | |
| 9331 | - | |
| 9332 | - const input = document.getElementById( labelFor ); | |
| 9333 | - if ( ! input || ! input.nextElementSibling ) { | |
| 9334 | - return; | |
| 9335 | - } | |
| 9336 | - | |
| 9337 | - const buttonToggle = input.nextElementSibling.querySelector( 'button.dropdown-toggle.multiselect' ); | |
| 9338 | - if ( ! buttonToggle ) { | |
| 9339 | - return; | |
| 9340 | - } | |
| 9341 | - | |
| 9342 | - const triggerMultiselectClick = () => buttonToggle.click(); | |
| 9343 | - setTimeout( triggerMultiselectClick, 0 ); | |
| 9344 | - }; | |
| 9345 | - document.addEventListener( 'click', clickListener ); | |
| 9346 | - } | |
| 9347 | - | |
| 9348 | - function maybeChangeEmbedFormMsg() { | |
| 9349 | - var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 9350 | - var fieldItem = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 9351 | - if ( null === fieldItem || 'form' !== fieldItem.dataset.type ) { | |
| 9352 | - return; | |
| 9353 | - } | |
| 9354 | - | |
| 9355 | - fieldItem = jQuery( fieldItem ); | |
| 9356 | - | |
| 9357 | - if ( this.options[ this.selectedIndex ].value ) { | |
| 9358 | - fieldItem.find( '.frm-not-set' )[0].classList.add( 'frm_hidden' ); | |
| 9359 | - var embedMsg = fieldItem.find( '.frm-embed-message' ); | |
| 9360 | - embedMsg.html( embedMsg.data( 'embedmsg' ) + this.options[ this.selectedIndex ].text ); | |
| 9361 | - fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.remove( 'frm_hidden' ); | |
| 9362 | - } else { | |
| 9363 | - fieldItem.find( '.frm-not-set' )[0].classList.remove( 'frm_hidden' ); | |
| 9364 | - fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.add( 'frm_hidden' ); | |
| 9365 | - } | |
| 9366 | - } | |
| 9367 | - | |
| 9368 | - function toggleProductType() { | |
| 9369 | - var settings = jQuery( this ).closest( '.frm-single-settings' ), | |
| 9370 | - container = settings.find( '.frmjs_product_choices' ), | |
| 9371 | - heading = settings.find( '.frm_prod_options_heading' ), | |
| 9372 | - currentVal = this.options[ this.selectedIndex ].value; | |
| 9373 | - | |
| 9374 | - container.removeClass( 'frm_prod_type_single frm_prod_type_user_def' ); | |
| 9375 | - heading.removeClass( 'frm_prod_user_def' ); | |
| 9376 | - | |
| 9377 | - if ( 'single' === currentVal ) { | |
| 9378 | - container.addClass( 'frm_prod_type_single' ); | |
| 9379 | - } else if ( 'user_def' === currentVal ) { | |
| 9380 | - container.addClass( 'frm_prod_type_user_def' ); | |
| 9381 | - heading.addClass( 'frm_prod_user_def' ); | |
| 9382 | - } | |
| 9383 | - } | |
| 9384 | - | |
| 9385 | - function isProductField( fieldId ) { | |
| 9386 | - var field = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 9387 | - if ( field === null ) { | |
| 9388 | - return false; | |
| 9389 | - } else { | |
| 9390 | - return 'product' === field.getAttribute( 'data-type' ); | |
| 9391 | - } | |
| 9392 | - } | |
| 9393 | - | |
| 9394 | - /** | |
| 9395 | - * Serialize form data with vanilla JS. | |
| 9396 | - */ | |
| 9397 | - function formToData( form ) { | |
| 9398 | - var subKey, i, | |
| 9399 | - object = {}, | |
| 9400 | - formData = form.elements; | |
| 9401 | - | |
| 9402 | - for ( i = 0; i < formData.length; i++ ) { | |
| 9403 | - var input = formData[i], | |
| 9404 | - key = input.name, | |
| 9405 | - value = input.value, | |
| 9406 | - names = key.match( /(.*)\[(.*)\]/ ); | |
| 9407 | - | |
| 9408 | - if ( ( input.type === 'radio' || input.type === 'checkbox' ) && ! input.checked ) { | |
| 9409 | - continue; | |
| 9410 | - } | |
| 9411 | - | |
| 9412 | - if ( names !== null ) { | |
| 9413 | - key = names[1]; | |
| 9414 | - subKey = names[2]; | |
| 9415 | - if ( ! Reflect.has( object, key ) ) { | |
| 9416 | - object[key] = {}; | |
| 9417 | - } | |
| 9418 | - object[key][subKey] = value; | |
| 9419 | - continue; | |
| 9420 | - } | |
| 9421 | - | |
| 9422 | - // Reflect.has in favor of: object.hasOwnProperty(key) | |
| 9423 | - if ( ! Reflect.has( object, key ) ) { | |
| 9424 | - object[key] = value; | |
| 9425 | - continue; | |
| 9426 | - } | |
| 9427 | - if ( ! Array.isArray( object[key]) ) { | |
| 9428 | - object[key] = [ object[key] ]; | |
| 9429 | - } | |
| 9430 | - object[key].push( value ); | |
| 9431 | - } | |
| 9432 | - | |
| 9433 | - return object; | |
| 9434 | - } | |
| 9435 | - | |
| 9436 | - /** | |
| 9437 | - * Show, hide, and sort subfields of Name field on form builder. | |
| 9438 | - * | |
| 9439 | - * @since 4.11 | |
| 9440 | - */ | |
| 9441 | - function handleNameFieldOnFormBuilder() { | |
| 9442 | - /** | |
| 9443 | - * Gets subfield element from cache. | |
| 9444 | - * | |
| 9445 | - * @param {String} fieldId Field ID. | |
| 9446 | - * @param {String} key Cache key. | |
| 9447 | - * @returns {HTMLElement|undefined} Return the element from cache or undefined if not found. | |
| 9448 | - */ | |
| 9449 | - const getSubFieldElFromCache = ( fieldId, key ) => { | |
| 9450 | - window.frmCachedSubFields = window.frmCachedSubFields || {}; | |
| 9451 | - window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {}; | |
| 9452 | - return window.frmCachedSubFields[fieldId][key]; | |
| 9453 | - }; | |
| 9454 | - | |
| 9455 | - /** | |
| 9456 | - * Sets subfield element to cache. | |
| 9457 | - * | |
| 9458 | - * @param {String} fieldId Field ID. | |
| 9459 | - * @param {String} key Cache key. | |
| 9460 | - * @param {HTMLElement} el Element. | |
| 9461 | - */ | |
| 9462 | - const setSubFieldElToCache = ( fieldId, key, el ) => { | |
| 9463 | - window.frmCachedSubFields = window.frmCachedSubFields || {}; | |
| 9464 | - window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {}; | |
| 9465 | - window.frmCachedSubFields[fieldId][key] = el; | |
| 9466 | - }; | |
| 9467 | - | |
| 9468 | - /** | |
| 9469 | - * Gets column class from the number of columns. | |
| 9470 | - * | |
| 9471 | - * @param {Number} colCount Number of columns. | |
| 9472 | - * @returns {string} | |
| 9473 | - */ | |
| 9474 | - const getColClass = colCount => 'frm' + parseInt( 12 / colCount ); | |
| 9475 | - | |
| 9476 | - const colClasses = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ].map( num => 'frm' + num ); | |
| 9477 | - | |
| 9478 | - const allSubFieldNames = [ 'first', 'middle', 'last' ]; | |
| 9479 | - | |
| 9480 | - /** | |
| 9481 | - * Handles name layout change. | |
| 9482 | - * | |
| 9483 | - * @param {Event} event Event object. | |
| 9484 | - */ | |
| 9485 | - const onChangeLayout = event => { | |
| 9486 | - const value = event.target.value; | |
| 9487 | - const subFieldNames = value.split( '_' ); | |
| 9488 | - const fieldId = event.target.dataset.fieldId; | |
| 9489 | - | |
| 9490 | - /* | |
| 9491 | - * Live update form on the form builder. | |
| 9492 | - */ | |
| 9493 | - const container = document.querySelector( '#field_' + fieldId + '_inner_container .frm_combo_inputs_container' ); | |
| 9494 | - const newColClass = getColClass( subFieldNames.length ); | |
| 9495 | - | |
| 9496 | - // Set all sub field elements to cache and hide all of them first. | |
| 9497 | - allSubFieldNames.forEach( name => { | |
| 9498 | - const subFieldEl = container.querySelector( '[data-sub-field-name="' + name + '"]' ); | |
| 9499 | - if ( subFieldEl ) { | |
| 9500 | - subFieldEl.classList.add( 'frm_hidden' ); | |
| 9501 | - subFieldEl.classList.remove( ...colClasses ); | |
| 9502 | - setSubFieldElToCache( fieldId, name, subFieldEl ); | |
| 9503 | - } | |
| 9504 | - }); | |
| 9505 | - | |
| 9506 | - subFieldNames.forEach( subFieldName => { | |
| 9507 | - const subFieldEl = getSubFieldElFromCache( fieldId, subFieldName ); | |
| 9508 | - if ( ! subFieldEl ) { | |
| 9509 | - return; | |
| 9510 | - } | |
| 9511 | - | |
| 9512 | - subFieldEl.classList.remove( 'frm_hidden' ); | |
| 9513 | - subFieldEl.classList.add( newColClass ); | |
| 9514 | - | |
| 9515 | - container.append( subFieldEl ); | |
| 9516 | - }); | |
| 9517 | - | |
| 9518 | - /* | |
| 9519 | - * Live update subfield options. | |
| 9520 | - */ | |
| 9521 | - // Hide all subfield options. | |
| 9522 | - allSubFieldNames.forEach( name => { | |
| 9523 | - const optionsEl = document.querySelector( '.frm_sub_field_options-' + name + '[data-field-id="' + fieldId + '"]' ); | |
| 9524 | - if ( optionsEl ) { | |
| 9525 | - optionsEl.classList.add( 'frm_hidden' ); | |
| 9526 | - setSubFieldElToCache( fieldId, name + '_options', optionsEl ); | |
| 9527 | - } | |
| 9528 | - }); | |
| 9529 | - | |
| 9530 | - subFieldNames.forEach( subFieldName => { | |
| 9531 | - const optionsEl = getSubFieldElFromCache( fieldId, subFieldName + '_options' ); | |
| 9532 | - if ( ! optionsEl ) { | |
| 9533 | - return; | |
| 9534 | - } | |
| 9535 | - optionsEl.classList.remove( 'frm_hidden' ); | |
| 9536 | - }); | |
| 9537 | - }; | |
| 9538 | - | |
| 9539 | - const dropdownSelector = '.frm_name_layout_dropdown'; | |
| 9540 | - document.addEventListener( 'change', event => { | |
| 9541 | - if ( event.target.matches( dropdownSelector ) ) { | |
| 9542 | - onChangeLayout( event ); | |
| 9543 | - } | |
| 9544 | - }, false ); | |
| 9545 | - } | |
| 9546 | - | |
| 9547 | - function debounce( func, wait = 100 ) { | |
| 9548 | - return frmDom.util.debounce( func, wait ); | |
| 9549 | - } | |
| 9550 | - | |
| 9551 | - function addSaveAndDragIconsToOption( fieldId, liObject ) { | |
| 9552 | - let li, useTag, useTagHref; | |
| 9553 | - let hasDragIcon = false; | |
| 9554 | - let hasSaveIcon = false; | |
| 9555 | - | |
| 9556 | - if ( liObject.newOption ) { | |
| 9557 | - const parser = new DOMParser(); | |
| 9558 | - li = parser.parseFromString( liObject.newOption, 'text/html' ).body.childNodes[0]; | |
| 9559 | - } else { | |
| 9560 | - li = liObject; | |
| 9561 | - } | |
| 9562 | - | |
| 9563 | - const liIcons = li.querySelectorAll( 'svg' ); | |
| 9564 | - | |
| 9565 | - liIcons.forEach( ( svg, key ) => { | |
| 9566 | - useTag = svg.getElementsByTagNameNS( 'http://www.w3.org/2000/svg', 'use' )[0]; | |
| 9567 | - if ( ! useTag ) { | |
| 9568 | - return; | |
| 9569 | - } | |
| 9570 | - useTagHref = useTag.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) || useTag.getAttribute( 'href' ); | |
| 9571 | - | |
| 9572 | - if ( useTagHref === '#frm_drag_icon' ) { | |
| 9573 | - hasDragIcon = true; | |
| 9574 | - } | |
| 9575 | - | |
| 9576 | - if ( useTagHref === '#frm_save_icon' ) { | |
| 9577 | - hasSaveIcon = true; | |
| 9578 | - } | |
| 9579 | - }); | |
| 9580 | - | |
| 9581 | - if ( ! hasDragIcon ) { | |
| 9582 | - li.prepend( icons.drag.cloneNode( true ) ); | |
| 9583 | - } | |
| 9584 | - | |
| 9585 | - if ( li.querySelector( `[id^=field_key_${fieldId}-]` ) && ! hasSaveIcon ) { | |
| 9586 | - li.querySelector( `[id^=field_key_${fieldId}-]` ).after( icons.save.cloneNode( true ) ); | |
| 9587 | - } | |
| 9588 | - | |
| 9589 | - if ( liObject.newOption ) { | |
| 9590 | - liObject.newOption = li; | |
| 9591 | - } | |
| 9592 | - } | |
| 9593 | - | |
| 9594 | - function maybeAddSaveAndDragIcons( fieldId ) { | |
| 9595 | - fieldOptions = document.querySelectorAll( `[id^=frm_delete_field_${fieldId}-]` ); | |
| 9596 | - // return if there are no options. | |
| 9597 | - if ( fieldOptions.length < 2 ) { | |
| 9598 | - return; | |
| 9599 | - } | |
| 9600 | - | |
| 9601 | - let options = [ ...fieldOptions ].slice( 1 ); | |
| 9602 | - options.forEach( ( li, _key ) => { | |
| 9603 | - if ( li.classList.contains( 'frm_other_option' ) ) { | |
| 9604 | - return; | |
| 9605 | - } | |
| 9606 | - addSaveAndDragIconsToOption( fieldId, li ); | |
| 9607 | - }); | |
| 9608 | - } | |
| 9609 | - | |
| 9610 | - function initOnSubmitAction() { | |
| 9611 | - const onChangeType = event => { | |
| 9612 | - if ( ! event.target.checked ) { | |
| 9613 | - return; | |
| 9614 | - } | |
| 9615 | - | |
| 9616 | - const actionEl = event.target.closest( '.frm_form_action_settings' ); | |
| 9617 | - actionEl.querySelectorAll( '.frm_on_submit_dependent_setting:not(.frm_hidden)' ).forEach( el => { | |
| 9618 | - el.classList.add( 'frm_hidden' ); | |
| 9619 | - }); | |
| 9620 | - | |
| 9621 | - const activeEls = actionEl.querySelectorAll( '.frm_on_submit_dependent_setting[data-show-if-' + event.target.value + ']' ); | |
| 9622 | - activeEls.forEach( activeEl => { | |
| 9623 | - activeEl.classList.remove( 'frm_hidden' ); | |
| 9624 | - }); | |
| 9625 | - | |
| 9626 | - actionEl.setAttribute( 'data-on-submit-type', event.target.value ); | |
| 9627 | - }; | |
| 9628 | - | |
| 9629 | - frmDom.util.documentOn( 'change', '.frm_on_submit_type input[type="radio"]', onChangeType ); | |
| 9630 | - } | |
| 9631 | - | |
| 9632 | - return { | |
| 9633 | - init: function() { | |
| 9634 | - s = {}; | |
| 9635 | - | |
| 9636 | - // Bootstrap dropdown button | |
| 9637 | - jQuery( '.wp-admin' ).on( 'click', function( e ) { | |
| 9638 | - var t = jQuery( e.target ); | |
| 9639 | - var $openDrop = jQuery( '.dropdown.open' ); | |
| 9640 | - if ( $openDrop.length && ! t.hasClass( 'dropdown' ) && ! t.closest( '.dropdown' ).length ) { | |
| 9641 | - $openDrop.removeClass( 'open' ); | |
| 9642 | - } | |
| 9643 | - }); | |
| 9644 | - jQuery( '#frm_bs_dropdown:not(.open) a' ).on( 'click', focusSearchBox ); | |
| 9645 | - | |
| 9646 | - if ( typeof thisFormId === 'undefined' ) { | |
| 9647 | - thisFormId = jQuery( document.getElementById( 'form_id' ) ).val(); | |
| 9648 | - } | |
| 9649 | - | |
| 9650 | - // Add event listener for dismissible warning messages. | |
| 9651 | - document.querySelectorAll( '.frm-warning-dismiss' ).forEach( ( dismissIcon ) => { | |
| 9652 | - onClickPreventDefault( dismissIcon, dismissWarningMessage ); | |
| 9653 | - }); | |
| 9654 | - | |
| 9655 | - frmAdminBuild.inboxBannerInit(); | |
| 9656 | - | |
| 9657 | - if ( $newFields.length > 0 ) { | |
| 9658 | - // only load this on the form builder page | |
| 9659 | - frmAdminBuild.buildInit(); | |
| 9660 | - } else if ( document.getElementById( 'frm_notification_settings' ) !== null ) { | |
| 9661 | - // only load on form settings page | |
| 9662 | - frmAdminBuild.settingsInit(); | |
| 9663 | - } else if ( document.getElementById( 'frm_styling_form' ) !== null ) { | |
| 9664 | - // load styling settings js | |
| 9665 | - frmAdminBuild.styleInit(); | |
| 9666 | - } else if ( document.getElementById( 'form_global_settings' ) !== null ) { | |
| 9667 | - // global settings page | |
| 9668 | - frmAdminBuild.globalSettingsInit(); | |
| 9669 | - } else if ( document.getElementById( 'frm_export_xml' ) !== null ) { | |
| 9670 | - // import/export page | |
| 9671 | - frmAdminBuild.exportInit(); | |
| 9672 | - } else if ( document.getElementById( 'frm_dyncontent' ) !== null ) { | |
| 9673 | - // only load on views settings page | |
| 9674 | - frmAdminBuild.viewInit(); | |
| 9675 | - } else if ( document.getElementById( 'frm_inbox_page' ) !== null ) { | |
| 9676 | - // Inbox page | |
| 9677 | - frmAdminBuild.inboxInit(); | |
| 9678 | - } else if ( document.getElementById( 'frm-welcome' ) !== null ) { | |
| 9679 | - // Solution install page | |
| 9680 | - frmAdminBuild.solutionInit(); | |
| 9681 | - } else { | |
| 9682 | - // New form selection page | |
| 9683 | - initNewFormModal(); | |
| 9684 | - initSelectionAutocomplete(); | |
| 9685 | - | |
| 9686 | - jQuery( '[data-frmprint]' ).on( 'click', function() { | |
| 9687 | - window.print(); | |
| 9688 | - return false; | |
| 9689 | - }); | |
| 9690 | - } | |
| 9691 | - | |
| 9692 | - var $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) ); | |
| 9693 | - if ( $advInfo.length > 0 || jQuery( '.frm_field_list' ).length > 0 ) { | |
| 9694 | - // only load on the form, form settings, and view settings pages | |
| 9695 | - frmAdminBuild.panelInit(); | |
| 9696 | - } | |
| 9697 | - | |
| 9698 | - loadTooltips(); | |
| 9699 | - initUpgradeModal(); | |
| 9700 | - | |
| 9701 | - // used on build, form settings, and view settings | |
| 9702 | - var $shortCodeDiv = jQuery( document.getElementById( 'frm_shortcodediv' ) ); | |
| 9703 | - if ( $shortCodeDiv.length > 0 ) { | |
| 9704 | - jQuery( 'a.edit-frm_shortcode' ).on( 'click', function() { | |
| 9705 | - if ( $shortCodeDiv.is( ':hidden' ) ) { | |
| 9706 | - $shortCodeDiv.slideDown( 'fast' ); | |
| 9707 | - this.style.display = 'none'; | |
| 9708 | - } | |
| 9709 | - return false; | |
| 9710 | - }); | |
| 9711 | - | |
| 9712 | - jQuery( '.cancel-frm_shortcode', '#frm_shortcodediv' ).on( 'click', function() { | |
| 9713 | - $shortCodeDiv.slideUp( 'fast' ); | |
| 9714 | - $shortCodeDiv.siblings( 'a.edit-frm_shortcode' ).show(); | |
| 9715 | - return false; | |
| 9716 | - }); | |
| 9717 | - } | |
| 9718 | - | |
| 9719 | - // tabs | |
| 9720 | - jQuery( document ).on( 'click', '#frm-nav-tabs a', clickNewTab ); | |
| 9721 | - jQuery( '.post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a' ).on( 'click', function() { | |
| 9722 | - const showUpgradeTab = this.classList.contains( 'frm_show_upgrade_tab' ); | |
| 9723 | - if ( this.classList.contains( 'frm_noallow' ) && ! showUpgradeTab ) { | |
| 9724 | - return; | |
| 9725 | - } | |
| 9726 | - | |
| 9727 | - if ( showUpgradeTab ) { | |
| 9728 | - populateUpgradeTab( this ); | |
| 9729 | - } | |
| 9730 | - | |
| 9731 | - clickTab( this ); | |
| 9732 | - return false; | |
| 9733 | - }); | |
| 9734 | - clickTab( jQuery( '.starttab a' ), 'auto' ); | |
| 9735 | - | |
| 9736 | - // submit the search form with dropdown | |
| 9737 | - jQuery( document ).on( 'click', '#frm-fid-search-menu a', function() { | |
| 9738 | - var val = this.id.replace( 'fid-', '' ); | |
| 9739 | - jQuery( 'select[name="fid"]' ).val( val ); | |
| 9740 | - triggerSubmit( document.getElementById( 'posts-filter' ) ); | |
| 9741 | - return false; | |
| 9742 | - }); | |
| 9743 | - | |
| 9744 | - jQuery( '.frm_select_box' ).on( 'click focus', function() { | |
| 9745 | - this.select(); | |
| 9746 | - }); | |
| 9747 | - | |
| 9748 | - jQuery( document ).on( 'input search change', '.frm-auto-search:not(#frm_new_form_modal #template-search-input)', searchContent ); | |
| 9749 | - jQuery( document ).on( 'focusin click', '.frm-auto-search', stopPropagation ); | |
| 9750 | - var autoSearch = jQuery( '.frm-auto-search' ); | |
| 9751 | - if ( autoSearch.val() !== '' ) { | |
| 9752 | - autoSearch.trigger( 'keyup' ); | |
| 9753 | - } | |
| 9754 | - | |
| 9755 | - // Initialize Formidable Connection. | |
| 9756 | - FrmFormsConnect.init(); | |
| 9757 | - | |
| 9758 | - jQuery( document ).on( 'click', '.frm-install-addon', installAddon ); | |
| 9759 | - jQuery( document ).on( 'click', '.frm-activate-addon', activateAddon ); | |
| 9760 | - jQuery( document ).on( 'click', '.frm-solution-multiple', installMultipleAddons ); | |
| 9761 | - | |
| 9762 | - // prevent annoying confirmation message from WordPress | |
| 9763 | - jQuery( 'button, input[type=submit]' ).on( 'click', removeWPUnload ); | |
| 9764 | - | |
| 9765 | - addMultiselectLabelListener(); | |
| 9766 | - | |
| 9767 | - frmAdminBuild.hooks.addFilter( | |
| 9768 | - 'frm_before_embed_modal', | |
| 9769 | - ( ids, { element, type }) => { | |
| 9770 | - if ( 'form' !== type ) { | |
| 9771 | - return ids; | |
| 9772 | - } | |
| 9773 | - | |
| 9774 | - let formId, formKey; | |
| 9775 | - const row = element.closest( 'tr' ); | |
| 9776 | - | |
| 9777 | - if ( row ) { | |
| 9778 | - // Embed icon on form index. | |
| 9779 | - formId = parseInt( row.querySelector( '.column-id' ).textContent ); | |
| 9780 | - formKey = row.querySelector( '.column-form_key' ).textContent; | |
| 9781 | - } else { | |
| 9782 | - // Embed button in form builder / form settings. | |
| 9783 | - formId = document.getElementById( 'form_id' ).value; | |
| 9784 | - | |
| 9785 | - const formKeyInput = document.getElementById( 'frm_form_key' ); | |
| 9786 | - if ( formKeyInput ) { | |
| 9787 | - formKey = formKeyInput.value; | |
| 9788 | - } else { | |
| 9789 | - const previewDrop = document.getElementById( 'frm-previewDrop' ); | |
| 9790 | - if ( previewDrop ) { | |
| 9791 | - formKey = previewDrop.nextElementSibling.querySelector( '.dropdown-item a' ).getAttribute( 'href' ).split( 'form=' )[1]; | |
| 9792 | - } | |
| 9793 | - } | |
| 9794 | - } | |
| 9795 | - | |
| 9796 | - return [ formId, formKey ]; | |
| 9797 | - } | |
| 9798 | - ); | |
| 9799 | - | |
| 9800 | - document.querySelectorAll( '#frm-show-fields > li, .frm_grid_container li' ).forEach( ( el, _key ) => { | |
| 9801 | - el.addEventListener( 'click', function() { | |
| 9802 | - let fieldId = this.querySelector( 'li' )?.dataset.fid || this.dataset.fid; | |
| 9803 | - maybeAddSaveAndDragIcons( fieldId ); | |
| 9804 | - }); | |
| 9805 | - }); | |
| 9806 | - }, | |
| 9807 | - | |
| 9808 | - buildInit: function() { | |
| 9809 | - let loadFieldId, $builderForm, builderArea; | |
| 9810 | - | |
| 9811 | - debouncedSyncAfterDragAndDrop = debounce( syncAfterDragAndDrop, 10 ); | |
| 9812 | - postBodyContent = document.getElementById( 'post-body-content' ); | |
| 9813 | - $postBodyContent = jQuery( postBodyContent ); | |
| 9814 | - | |
| 9815 | - if ( jQuery( '.frm_field_loading' ).length ) { | |
| 9816 | - loadFieldId = jQuery( '.frm_field_loading' ).first().attr( 'id' ); | |
| 9817 | - loadFields( loadFieldId ); | |
| 9818 | - } | |
| 9819 | - | |
| 9820 | - setupSortable( 'ul.frm_sorting' ); | |
| 9821 | - | |
| 9822 | - document.querySelectorAll( '.field_type_list > li:not(.frm_show_upgrade)' ).forEach( makeDraggable ); | |
| 9823 | - | |
| 9824 | - 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(); | |
| 9825 | - | |
| 9826 | - jQuery( '.frm_submit_ajax' ).on( 'click', submitBuild ); | |
| 9827 | - jQuery( '.frm_submit_no_ajax' ).on( 'click', submitNoAjax ); | |
| 9828 | - | |
| 9829 | - jQuery( 'a.edit-form-status' ).on( 'click', slideDown ); | |
| 9830 | - jQuery( '.cancel-form-status' ).on( 'click', slideUp ); | |
| 9831 | - jQuery( '.save-form-status' ).on( 'click', function() { | |
| 9832 | - const newStatus = jQuery( document.getElementById( 'form_change_status' ) ).val(); | |
| 9833 | - jQuery( 'input[name="new_status"]' ).val( newStatus ); | |
| 9834 | - jQuery( document.getElementById( 'form-status-display' ) ).html( newStatus ); | |
| 9835 | - jQuery( '.cancel-form-status' ).trigger( 'click' ); | |
| 9836 | - return false; | |
| 9837 | - }); | |
| 9838 | - | |
| 9839 | - jQuery( '.frm_form_builder form' ).first().on( 'submit', function() { | |
| 9840 | - jQuery( '.inplace_field' ).trigger( 'blur' ); | |
| 9841 | - }); | |
| 9842 | - | |
| 9843 | - initiateMultiselect(); | |
| 9844 | - renumberPageBreaks(); | |
| 9845 | - | |
| 9846 | - $builderForm = jQuery( builderForm ); | |
| 9847 | - builderArea = document.getElementById( 'frm_form_editor_container' ); | |
| 9848 | - $builderForm.on( 'click', '.frm_add_logic_row', addFieldLogicRow ); | |
| 9849 | - $builderForm.on( 'click', '.frm_add_watch_lookup_row', addWatchLookupRow ); | |
| 9850 | - $builderForm.on( 'change', '.frm_get_values_form', updateGetValueFieldSelection ); | |
| 9851 | - $builderForm.on( 'change', '.frm_logic_field_opts', getFieldValues ); | |
| 9852 | - $builderForm.on( 'change', '.radio_maxnum', setStarValues ); | |
| 9853 | - $builderForm.on( 'frm-multiselect-changed', 'select[name^="field_options[admin_only_"]', adjustVisibilityValuesForEveryoneValues ); | |
| 9854 | - | |
| 9855 | - jQuery( document.getElementById( 'frm-insert-fields' ) ).on( 'click', '.frm_add_field', addFieldClick ); | |
| 9856 | - $newFields.on( 'click', '.frm_clone_field', duplicateField ); | |
| 9857 | - $builderForm.on( 'blur', 'input[id^="frm_calc"]', checkCalculationCreatedByUser ); | |
| 9858 | - $builderForm.on( 'change', 'input.frm_format_opt, input.frm_max_length_opt', toggleInvalidMsg ); | |
| 9859 | - $builderForm.on( 'change click', '[data-changeme]', liveChanges ); | |
| 9860 | - $builderForm.on( 'click', 'input.frm_req_field', markRequired ); | |
| 9861 | - $builderForm.on( 'click', '.frm_mark_unique', markUnique ); | |
| 9862 | - | |
| 9863 | - $builderForm.on( 'change', '.frm_repeat_format', toggleRepeatButtons ); | |
| 9864 | - $builderForm.on( 'change', '.frm_repeat_limit', checkRepeatLimit ); | |
| 9865 | - $builderForm.on( 'change', '.frm_js_checkbox_limit', checkCheckboxSelectionsLimit ); | |
| 9866 | - $builderForm.on( 'input', 'input[name^="field_options[add_label_"]', function() { | |
| 9867 | - updateRepeatText( this, 'add' ); | |
| 9868 | - }); | |
| 9869 | - $builderForm.on( 'input', 'input[name^="field_options[remove_label_"]', function() { | |
| 9870 | - updateRepeatText( this, 'remove' ); | |
| 9871 | - }); | |
| 9872 | - $builderForm.on( 'change', 'select[name^="field_options[data_type_"]', maybeClearWatchFields ); | |
| 9873 | - jQuery( builderArea ).on( 'click', '.frm-collapse-page', maybeCollapsePage ); | |
| 9874 | - jQuery( builderArea ).on( 'click', '.frm-collapse-section', maybeCollapseSection ); | |
| 9875 | - $builderForm.on( 'click', '.frm-single-settings h3', maybeCollapseSettings ); | |
| 9876 | - | |
| 9877 | - jQuery( builderArea ).on( 'show.bs.dropdown hide.bs.dropdown', changeSectionStyle ); | |
| 9878 | - | |
| 9879 | - $builderForm.on( 'click', '.frm_toggle_sep_values', toggleSepValues ); | |
| 9880 | - $builderForm.on( 'click', '.frm_toggle_image_options', toggleImageOptions ); | |
| 9881 | - $builderForm.on( 'click', '.frm_remove_image_option', removeImageFromOption ); | |
| 9882 | - $builderForm.on( 'click', '.frm_choose_image_box', addImageToOption ); | |
| 9883 | - $builderForm.on( 'change', '.frm_hide_image_text', refreshOptionDisplay ); | |
| 9884 | - $builderForm.on( 'change', '.frm_field_options_image_size', setImageSize ); | |
| 9885 | - $builderForm.on( 'click', '.frm_multiselect_opt', toggleMultiselect ); | |
| 9886 | - $newFields.on( 'mousedown', 'input, textarea, select', stopFieldFocus ); | |
| 9887 | - $newFields.on( 'click', 'input[type=radio], input[type=checkbox]', stopFieldFocus ); | |
| 9888 | - $newFields.on( 'click', '.frm_delete_field', clickDeleteField ); | |
| 9889 | - $newFields.on( 'click', '.frm_select_field', clickSelectField ); | |
| 9890 | - jQuery( document ).on( 'click', '.frm_delete_field_group', clickDeleteFieldGroup ); | |
| 9891 | - jQuery( document ).on( 'click', '.frm_clone_field_group', duplicateFieldGroup ); | |
| 9892 | - jQuery( document ).on( 'click', '#frm_field_group_controls > span:first-child', clickFieldGroupLayout ); | |
| 9893 | - jQuery( document ).on( 'click', '.frm-row-layout-option', handleFieldGroupLayoutOptionClick ); | |
| 9894 | - jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-row-layout-option', handleFieldGroupLayoutOptionInsideMergeClick ); | |
| 9895 | - jQuery( document ).on( 'click', '.frm-custom-field-group-layout', customFieldGroupLayoutClick ); | |
| 9896 | - jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-custom-field-group-layout', customFieldGroupLayoutInsideMergeClick ); | |
| 9897 | - jQuery( document ).on( 'click', '.frm-break-field-group', breakFieldGroupClick ); | |
| 9898 | - $newFields.on( 'click', '#frm_field_group_popup .frm_grid_container input', focusFieldGroupInputOnClick ); | |
| 9899 | - jQuery( document ).on( 'click', '.frm-cancel-custom-field-group-layout', cancelCustomFieldGroupClick ); | |
| 9900 | - jQuery( document ).on( 'click', '.frm-save-custom-field-group-layout', saveCustomFieldGroupClick ); | |
| 9901 | - $newFields.on( 'click', 'ul.frm_sorting', fieldGroupClick ); | |
| 9902 | - jQuery( document ).on( 'click', '.frm-merge-fields-into-row', mergeFieldsIntoRowClick ); | |
| 9903 | - jQuery( document ).on( 'click', '.frm-delete-field-groups', deleteFieldGroupsClick ); | |
| 9904 | - $newFields.on( 'click', '.frm-field-action-icons [data-toggle="dropdown"]', function() { | |
| 9905 | - this.closest( 'li.form-field' ).classList.add( 'frm-field-settings-open' ); | |
| 9906 | - jQuery( document ).on( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings ); | |
| 9907 | - }); | |
| 9908 | - $newFields.on( 'mousemove', 'ul.frm_sorting', checkForMultiselectKeysOnMouseMove ); | |
| 9909 | - $newFields.on( 'show.bs.dropdown', '.frm-field-action-icons', onFieldActionDropdownShow ); | |
| 9910 | - jQuery( document ).on( 'show.bs.dropdown', '#frm_field_group_controls', onFieldGroupActionDropdownShow ); | |
| 9911 | - $builderForm.on( 'click', '.frm_single_option a[data-removeid]', deleteFieldOption ); | |
| 9912 | - $builderForm.on( 'mousedown', '.frm_single_option input[type=radio]', maybeUncheckRadio ); | |
| 9913 | - $builderForm.on( 'focusin', '.frm_single_option input[type=text]', maybeClearOptText ); | |
| 9914 | - $builderForm.on( 'click', '.frm_add_opt', addFieldOption ); | |
| 9915 | - $builderForm.on( 'change', '.frm_single_option input', resetOptOnChange ); | |
| 9916 | - $builderForm.on( 'change', '.frm_image_id', resetOptOnChange ); | |
| 9917 | - $builderForm.on( 'change', '.frm_toggle_mult_sel', toggleMultSel ); | |
| 9918 | - $builderForm.on( 'focusin', '.frm_classes', showBuilderModal ); | |
| 9919 | - | |
| 9920 | - $newFields.on( 'click', '.frm_primary_label', clickLabel ); | |
| 9921 | - $newFields.on( 'click', '.frm_description', clickDescription ); | |
| 9922 | - $newFields.on( 'click', 'li.ui-state-default', clickVis ); | |
| 9923 | - $newFields.on( 'dblclick', 'li.ui-state-default', openAdvanced ); | |
| 9924 | - $builderForm.on( 'change', '.frm_tax_form_select', toggleFormTax ); | |
| 9925 | - $builderForm.on( 'change', 'select.conf_field', addConf ); | |
| 9926 | - | |
| 9927 | - $builderForm.on( 'change', '.frm_get_field_selection', getFieldSelection ); | |
| 9928 | - | |
| 9929 | - $builderForm.on( 'click', '.frm-show-inline-modal', maybeShowInlineModal ); | |
| 9930 | - | |
| 9931 | - $builderForm.on( 'click', '.frm-inline-modal .dismiss', dismissInlineModal ); | |
| 9932 | - jQuery( document ).on( 'change', '[data-frmchange]', changeInputtedValue ); | |
| 9933 | - | |
| 9934 | - $builderForm.on( 'change', '.frm_include_extras_field', rePopCalcFieldsForSummary ); | |
| 9935 | - $builderForm.on( 'change', 'select[name^="field_options[form_select_"]', maybeChangeEmbedFormMsg ); | |
| 9936 | - | |
| 9937 | - jQuery( document ).on( 'submit', '#frm_js_build_form', buildSubmittedNoAjax ); | |
| 9938 | - 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 ); | |
| 9939 | - | |
| 9940 | - popAllProductFields(); | |
| 9941 | - | |
| 9942 | - jQuery( document ).on( 'change', '.frmjs_prod_data_type_opt', toggleProductType ); | |
| 9943 | - | |
| 9944 | - jQuery( document ).on( 'focus', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextFocus ); | |
| 9945 | - jQuery( document ).on( 'blur', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextBlur ); | |
| 9946 | - | |
| 9947 | - initBulkOptionsOverlay(); | |
| 9948 | - hideEmptyEle(); | |
| 9949 | - maybeHideQuantityProductFieldOption(); | |
| 9950 | - handleNameFieldOnFormBuilder(); | |
| 9951 | - toggleSectionHolder(); | |
| 9952 | - }, | |
| 9953 | - | |
| 9954 | - settingsInit: function() { | |
| 9955 | - const $formActions = jQuery( document.getElementById( 'frm_notification_settings' ) ); | |
| 9956 | - | |
| 9957 | - let formSettings, $loggedIn, $cookieExp, $editable; | |
| 9958 | - | |
| 9959 | - // BCC, CC, and Reply To button functionality | |
| 9960 | - $formActions.on( 'click', '.frm_email_buttons', showEmailRow ); | |
| 9961 | - $formActions.on( 'click', '.frm_remove_field', hideEmailRow ); | |
| 9962 | - $formActions.on( 'change', '.frm_to_row, .frm_from_row', showEmailWarning ); | |
| 9963 | - $formActions.on( 'change', '.frm_tax_selector', changePosttaxRow ); | |
| 9964 | - $formActions.on( 'change', 'select.frm_single_post_field', checkDupPost ); | |
| 9965 | - $formActions.on( 'change', 'select.frm_toggle_post_content', togglePostContent ); | |
| 9966 | - $formActions.on( 'change', 'select.frm_dyncontent_opt', fillDyncontent ); | |
| 9967 | - $formActions.on( 'change', '.frm_post_type', switchPostType ); | |
| 9968 | - $formActions.on( 'click', '.frm_add_postmeta_row', addPostmetaRow ); | |
| 9969 | - $formActions.on( 'click', '.frm_add_posttax_row', addPosttaxRow ); | |
| 9970 | - $formActions.on( 'click', '.frm_toggle_cf_opts', toggleCfOpts ); | |
| 9971 | - $formActions.on( 'click', '.frm_duplicate_form_action', copyFormAction ); | |
| 9972 | - jQuery( document ).on( 'change', 'select[data-toggleclass], input[data-toggleclass]', toggleFormOpts ); | |
| 9973 | - jQuery( '.frm_actions_list' ).on( 'click', '.frm_active_action', addFormAction ); | |
| 9974 | - jQuery( '#frm-show-groups, #frm-hide-groups' ).on( 'click', toggleActionGroups ); | |
| 9975 | - initiateMultiselect(); | |
| 9976 | - | |
| 9977 | - //set actions icons to inactive | |
| 9978 | - jQuery( 'ul.frm_actions_list li' ).each( function() { | |
| 9979 | - checkActiveAction( jQuery( this ).children( 'a' ).data( 'actiontype' ) ); | |
| 9980 | - | |
| 9981 | - // If the icon is a background image, don't add BG color. | |
| 9982 | - const icon = jQuery( this ).find( 'i' ); | |
| 9983 | - if ( icon.css( 'background-image' ) !== 'none' ) { | |
| 9984 | - icon.addClass( 'frm-inverse' ); | |
| 9985 | - } | |
| 9986 | - }); | |
| 9987 | - | |
| 9988 | - jQuery( '.frm_submit_settings_btn' ).on( 'click', submitSettings ); | |
| 9989 | - | |
| 9990 | - formSettings = jQuery( '.frm_form_settings' ); | |
| 9991 | - formSettings.on( 'click', '.frm_add_form_logic', addFormLogicRow ); | |
| 9992 | - formSettings.on( 'blur', '.frm_email_blur', formatEmailSetting ); | |
| 9993 | - formSettings.on( 'click', '.frm_already_used', onlyOneActionMessage ); | |
| 9994 | - | |
| 9995 | - formSettings.on( 'change', '#logic_link_submit', toggleSubmitLogic ); | |
| 9996 | - formSettings.on( 'click', '.frm_add_submit_logic', addSubmitLogic ); | |
| 9997 | - formSettings.on( 'change', '.frm_submit_logic_field_opts', addSubmitLogicOpts ); | |
| 9998 | - | |
| 9999 | - document.addEventListener( | |
| 10000 | - 'click', | |
| 10001 | - function handleImageUploadClickEvents( event ) { | |
| 10002 | - const { target } = event; | |
| 10003 | - | |
| 10004 | - if ( ! target.closest( '.frm_image_preview_wrapper' ) ) { | |
| 10005 | - return; | |
| 10006 | - } | |
| 10007 | - | |
| 10008 | - if ( target.closest( '.frm_choose_image_box' ) ) { | |
| 10009 | - addImageToOption.bind( target )( event ); | |
| 10010 | - return; | |
| 10011 | - } | |
| 10012 | - | |
| 10013 | - if ( target.closest( '.frm_remove_image_option' ) ) { | |
| 10014 | - removeImageFromOption.bind( target )( event ); | |
| 10015 | - } | |
| 10016 | - } | |
| 10017 | - ); | |
| 10018 | - | |
| 10019 | - // Close shortcode modal on click. | |
| 10020 | - formSettings.on( 'mouseup', '*:not(.frm-show-box)', function( e ) { | |
| 10021 | - e.stopPropagation(); | |
| 10022 | - | |
| 10023 | - if ( e.target.classList.contains( 'frm-show-box' ) || e.target.parentElement.classList.contains( 'frm-show-box' ) ) { | |
| 10024 | - return; | |
| 10025 | - } | |
| 10026 | - | |
| 10027 | - const sidebar = document.getElementById( 'frm_adv_info' ); | |
| 10028 | - if ( ! sidebar ) { | |
| 10029 | - return; | |
| 10030 | - } | |
| 10031 | - | |
| 10032 | - if ( sidebar.getAttribute( 'data-fills' ) === e.target.id && typeof e.target.id !== 'undefined' ) { | |
| 10033 | - return; | |
| 10034 | - } | |
| 10035 | - | |
| 10036 | - const isChild = jQuery( e.target ).closest( '#frm_adv_info' ).length > 0; | |
| 10037 | - | |
| 10038 | - if ( ! isChild && sidebar.display !== 'none' ) { | |
| 10039 | - hideShortcodes( sidebar ); | |
| 10040 | - } | |
| 10041 | - }); | |
| 10042 | - | |
| 10043 | - //Warning when user selects "Do not store entries ..." | |
| 10044 | - jQuery( document.getElementById( 'no_save' ) ).on( 'change', function() { | |
| 10045 | - if ( this.checked ) { | |
| 10046 | - if ( confirm( frm_admin_js.no_save_warning ) !== true ) { // eslint-disable-line camelcase | |
| 10047 | - // Uncheck box if user hits "Cancel" | |
| 10048 | - jQuery( this ).attr( 'checked', false ); | |
| 10049 | - } | |
| 10050 | - } | |
| 10051 | - }); | |
| 10052 | - | |
| 10053 | - jQuery( 'select[name="options[edit_action]"]' ).on( 'change', showSuccessOpt ); | |
| 10054 | - | |
| 10055 | - $loggedIn = document.getElementById( 'logged_in' ); | |
| 10056 | - jQuery( $loggedIn ).on( 'change', function() { | |
| 10057 | - if ( this.checked ) { | |
| 10058 | - visible( '.hide_logged_in' ); | |
| 10059 | - } else { | |
| 10060 | - invisible( '.hide_logged_in' ); | |
| 10061 | - } | |
| 10062 | - }); | |
| 10063 | - | |
| 10064 | - $cookieExp = jQuery( document.getElementById( 'frm_cookie_expiration' ) ); | |
| 10065 | - jQuery( document.getElementById( 'frm_single_entry_type' ) ).on( 'change', function() { | |
| 10066 | - if ( this.value === 'cookie' ) { | |
| 10067 | - $cookieExp.fadeIn( 'slow' ); | |
| 10068 | - } else { | |
| 10069 | - $cookieExp.fadeOut( 'slow' ); | |
| 10070 | - } | |
| 10071 | - }); | |
| 10072 | - | |
| 10073 | - var $singleEntry = document.getElementById( 'single_entry' ); | |
| 10074 | - jQuery( $singleEntry ).on( 'change', function() { | |
| 10075 | - if ( this.checked ) { | |
| 10076 | - visible( '.hide_single_entry' ); | |
| 10077 | - } else { | |
| 10078 | - invisible( '.hide_single_entry' ); | |
| 10079 | - } | |
| 10080 | - | |
| 10081 | - if ( this.checked && jQuery( document.getElementById( 'frm_single_entry_type' ) ).val() === 'cookie' ) { | |
| 10082 | - $cookieExp.fadeIn( 'slow' ); | |
| 10083 | - } else { | |
| 10084 | - $cookieExp.fadeOut( 'slow' ); | |
| 10085 | - } | |
| 10086 | - }); | |
| 10087 | - | |
| 10088 | - jQuery( '.hide_save_draft' ).hide(); | |
| 10089 | - | |
| 10090 | - var $saveDraft = jQuery( document.getElementById( 'save_draft' ) ); | |
| 10091 | - $saveDraft.on( 'change', function() { | |
| 10092 | - if ( this.checked ) { | |
| 10093 | - jQuery( '.hide_save_draft' ).fadeIn( 'slow' ); | |
| 10094 | - } else { | |
| 10095 | - jQuery( '.hide_save_draft' ).fadeOut( 'slow' ); | |
| 10096 | - } | |
| 10097 | - }); | |
| 10098 | - triggerChange( $saveDraft ); | |
| 10099 | - | |
| 10100 | - //If Allow editing is checked/unchecked | |
| 10101 | - $editable = document.getElementById( 'editable' ); | |
| 10102 | - jQuery( $editable ).on( 'change', function() { | |
| 10103 | - if ( this.checked ) { | |
| 10104 | - jQuery( '.hide_editable' ).fadeIn( 'slow' ); | |
| 10105 | - triggerChange( document.getElementById( 'edit_action' ) ); | |
| 10106 | - } else { | |
| 10107 | - jQuery( '.hide_editable' ).fadeOut( 'slow' ); | |
| 10108 | - jQuery( '.edit_action_message_box' ).fadeOut( 'slow' );//Hide On Update message box | |
| 10109 | - } | |
| 10110 | - }); | |
| 10111 | - | |
| 10112 | - //If File Protection is checked/unchecked | |
| 10113 | - jQuery( document ).on( 'change', '#protect_files', function() { | |
| 10114 | - if ( this.checked ) { | |
| 10115 | - jQuery( '.hide_protect_files' ).fadeIn( 'slow' ); | |
| 10116 | - } else { | |
| 10117 | - jQuery( '.hide_protect_files' ).fadeOut( 'slow' ); | |
| 10118 | - } | |
| 10119 | - }); | |
| 10120 | - | |
| 10121 | - jQuery( document ).on( 'frm-multiselect-changed', '#protect_files_role', adjustVisibilityValuesForEveryoneValues ); | |
| 10122 | - | |
| 10123 | - jQuery( document ).on( 'submit', '.frm_form_settings', settingsSubmitted ); | |
| 10124 | - jQuery( document ).on( 'change', '#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea', fieldUpdated ); | |
| 10125 | - | |
| 10126 | - // Page Selection Autocomplete | |
| 10127 | - initSelectionAutocomplete(); | |
| 10128 | - | |
| 10129 | - jQuery( document ).on( 'frm-action-loaded', onActionLoaded ); | |
| 10130 | - | |
| 10131 | - initOnSubmitAction(); | |
| 10132 | - }, | |
| 10133 | - | |
| 10134 | - panelInit: function() { | |
| 10135 | - var customPanel, settingsPage, viewPage, insertFieldsTab; | |
| 10136 | - | |
| 10137 | - jQuery( '.frm_wrap, #postbox-container-1' ).on( 'click', '.frm_insert_code', insertCode ); | |
| 10138 | - jQuery( document ).on( 'change', '.frm_insert_val', function() { | |
| 10139 | - insertFieldCode( jQuery( this ).data( 'target' ), jQuery( this ).val() ); | |
| 10140 | - jQuery( this ).val( '' ); | |
| 10141 | - }); | |
| 10142 | - | |
| 10143 | - jQuery( document ).on( 'click change', '#frm-id-key-condition', resetLogicBuilder ); | |
| 10144 | - jQuery( document ).on( 'keyup change', '.frm-build-logic', setLogicExample ); | |
| 10145 | - | |
| 10146 | - showInputIcon(); | |
| 10147 | - jQuery( document ).on( 'frmElementAdded', function( event, parentEle ) { | |
| 10148 | - /* This is here for add-ons to trigger */ | |
| 10149 | - showInputIcon( parentEle ); | |
| 10150 | - }); | |
| 10151 | - jQuery( document ).on( 'mousedown', '.frm-show-box', showShortcodes ); | |
| 10152 | - | |
| 10153 | - settingsPage = document.getElementById( 'form_settings_page' ); | |
| 10154 | - viewPage = document.body.classList.contains( 'post-type-frm_display' ); | |
| 10155 | - insertFieldsTab = document.getElementById( 'frm_insert_fields_tab' ); | |
| 10156 | - | |
| 10157 | - if ( settingsPage !== null || viewPage ) { | |
| 10158 | - jQuery( document ).on( 'focusin', 'form input, form textarea', function( e ) { | |
| 10159 | - var htmlTab; | |
| 10160 | - e.stopPropagation(); | |
| 10161 | - maybeShowModal( this ); | |
| 10162 | - | |
| 10163 | - if ( jQuery( this ).is( ':not(:submit, input[type=button], .frm-search-input, input[type=checkbox])' ) ) { | |
| 10164 | - if ( jQuery( e.target ).closest( '#frm_adv_info' ).length ) { | |
| 10165 | - // Don't trigger for fields inside of the modal. | |
| 10166 | - return; | |
| 10167 | - } | |
| 10168 | - | |
| 10169 | - if ( settingsPage !== null ) { | |
| 10170 | - /* form settings page */ | |
| 10171 | - htmlTab = jQuery( '#frm_html_tab' ); | |
| 10172 | - if ( jQuery( this ).closest( '#html_settings' ).length > 0 ) { | |
| 10173 | - htmlTab.show(); | |
| 10174 | - htmlTab.siblings().hide(); | |
| 10175 | - jQuery( '#frm_html_tab a' ).trigger( 'click' ); | |
| 10176 | - toggleAllowedHTML( this, e.type ); | |
| 10177 | - } else { | |
| 10178 | - showElement( jQuery( '.frm-category-tabs li' ) ); | |
| 10179 | - insertFieldsTab.click(); | |
| 10180 | - htmlTab.hide(); | |
| 10181 | - htmlTab.siblings().show(); | |
| 10182 | - } | |
| 10183 | - } else if ( viewPage ) { | |
| 10184 | - // Run on view page. | |
| 10185 | - toggleAllowedShortcodes( this.id, e.type ); | |
| 10186 | - } | |
| 10187 | - } | |
| 10188 | - }); | |
| 10189 | - } | |
| 10190 | - | |
| 10191 | - jQuery( '.frm_wrap, #postbox-container-1' ).on( 'mousedown', '#frm_adv_info a, .frm_field_list a', function( e ) { | |
| 10192 | - e.preventDefault(); | |
| 10193 | - }); | |
| 10194 | - | |
| 10195 | - customPanel = jQuery( '#frm_adv_info' ); | |
| 10196 | - customPanel.on( 'click', '.subsubsub a.frmids', function( e ) { | |
| 10197 | - toggleKeyID( 'frmids', e ); | |
| 10198 | - }); | |
| 10199 | - customPanel.on( 'click', '.subsubsub a.frmkeys', function( e ) { | |
| 10200 | - toggleKeyID( 'frmkeys', e ); | |
| 10201 | - }); | |
| 10202 | - }, | |
| 10203 | - | |
| 10204 | - viewInit: function() { | |
| 10205 | - var $addRemove, | |
| 10206 | - $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) ); | |
| 10207 | - $advInfo.before( '<div id="frm_position_ele"></div>' ); | |
| 10208 | - setupMenuOffset(); | |
| 10209 | - | |
| 10210 | - jQuery( document ).on( 'blur', '#param', checkDetailPageSlug ); | |
| 10211 | - jQuery( document ).on( 'blur', 'input[name^="options[where_val]"]', checkFilterParamNames ); | |
| 10212 | - | |
| 10213 | - // Show loading indicator. | |
| 10214 | - jQuery( '#publish' ).on( 'mousedown', function() { | |
| 10215 | - fieldsUpdated = 0; | |
| 10216 | - this.classList.add( 'frm_loading_button' ); | |
| 10217 | - }); | |
| 10218 | - | |
| 10219 | - // move content tabs | |
| 10220 | - jQuery( '#frm_dyncontent .handlediv' ).before( jQuery( '#frm_dyncontent .nav-menus-php' ) ); | |
| 10221 | - | |
| 10222 | - // click content tabs | |
| 10223 | - jQuery( '.nav-tab-wrapper a' ).on( 'click', clickContentTab ); | |
| 10224 | - | |
| 10225 | - // click tabs after panel is replaced with ajax | |
| 10226 | - jQuery( '#side-sortables' ).on( 'click', '.frm_doing_ajax.categorydiv .category-tabs a', clickTabsAfterAjax ); | |
| 10227 | - | |
| 10228 | - initToggleShortcodes(); | |
| 10229 | - jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ); | |
| 10230 | - | |
| 10231 | - jQuery( 'input[name="show_count"]' ).on( 'change', showCount ); | |
| 10232 | - | |
| 10233 | - jQuery( document.getElementById( 'form_id' ) ).on( 'change', displayFormSelected ); | |
| 10234 | - | |
| 10235 | - $addRemove = jQuery( '.frm_repeat_rows' ); | |
| 10236 | - $addRemove.on( 'click', '.frm_add_order_row', addOrderRow ); | |
| 10237 | - $addRemove.on( 'click', '.frm_add_where_row', addWhereRow ); | |
| 10238 | - $addRemove.on( 'change', '.frm_insert_where_options', insertWhereOptions ); | |
| 10239 | - $addRemove.on( 'change', '.frm_where_is_options', hideWhereOptions ); | |
| 10240 | - | |
| 10241 | - setDefaultPostStatus(); | |
| 10242 | - }, | |
| 10243 | - | |
| 10244 | - inboxInit: function() { | |
| 10245 | - jQuery( '.frm_inbox_dismiss, footer .frm-button-secondary, footer .frm-button-primary' ).on( 'click', function( e ) { | |
| 10246 | - var message = this.parentNode.parentNode, | |
| 10247 | - key = message.getAttribute( 'data-message' ), | |
| 10248 | - href = this.getAttribute( 'href' ); | |
| 10249 | - | |
| 10250 | - if ( 'free_templates' === key && ! this.classList.contains( 'frm_inbox_dismiss' ) ) { | |
| 10251 | - return; | |
| 10252 | - } | |
| 10253 | - | |
| 10254 | - e.preventDefault(); | |
| 10255 | - | |
| 10256 | - data = { | |
| 10257 | - action: 'frm_inbox_dismiss', | |
| 10258 | - key: key, | |
| 10259 | - nonce: frmGlobal.nonce | |
| 10260 | - }; | |
| 10261 | - postAjax( data, function() { | |
| 10262 | - if ( href !== '#' ) { | |
| 10263 | - window.location = href; | |
| 10264 | - return true; | |
| 10265 | - } | |
| 10266 | - fadeOut( message, function() { | |
| 10267 | - message.parentNode.removeChild( message ); | |
| 10268 | - }); | |
| 10269 | - }); | |
| 10270 | - }); | |
| 10271 | - jQuery( '#frm-dismiss-inbox' ).on( 'click', function( e ) { | |
| 10272 | - data = { | |
| 10273 | - action: 'frm_inbox_dismiss', | |
| 10274 | - key: 'all', | |
| 10275 | - nonce: frmGlobal.nonce | |
| 10276 | - }; | |
| 10277 | - postAjax( data, function() { | |
| 10278 | - fadeOut( document.getElementById( 'frm_message_list' ), function() { | |
| 10279 | - document.getElementById( 'frm_empty_inbox' ).classList.remove( 'frm_hidden' ); | |
| 10280 | - }); | |
| 10281 | - }); | |
| 10282 | - }); | |
| 10283 | - }, | |
| 10284 | - | |
| 10285 | - solutionInit: function() { | |
| 10286 | - jQuery( document ).on( 'submit', '#frm-new-template', installTemplate ); | |
| 10287 | - }, | |
| 10288 | - | |
| 10289 | - styleInit: function() { | |
| 10290 | - const $previewWrapper = jQuery( '.frm_image_preview_wrapper' ); | |
| 10291 | - $previewWrapper.on( 'click', '.frm_choose_image_box', addImageToOption ); | |
| 10292 | - $previewWrapper.on( 'click', '.frm_remove_image_option', removeImageFromOption ); | |
| 10293 | - | |
| 10294 | - wp.hooks.doAction( 'frm_style_editor_init' ); | |
| 10295 | - }, | |
| 10296 | - | |
| 10297 | - customCSSInit: function() { | |
| 10298 | - console.warn( 'Calling frmAdminBuild.customCSSInit is deprecated.' ); | |
| 10299 | - }, | |
| 10300 | - | |
| 10301 | - globalSettingsInit: function() { | |
| 10302 | - var licenseTab; | |
| 10303 | - | |
| 10304 | - jQuery( document ).on( 'click', '[data-frmuninstall]', uninstallNow ); | |
| 10305 | - | |
| 10306 | - initiateMultiselect(); | |
| 10307 | - | |
| 10308 | - // activate addon licenses | |
| 10309 | - licenseTab = document.getElementById( 'licenses_settings' ); | |
| 10310 | - if ( licenseTab !== null ) { | |
| 10311 | - jQuery( licenseTab ).on( 'click', '.edd_frm_save_license', saveAddonLicense ); | |
| 10312 | - } | |
| 10313 | - | |
| 10314 | - // Solution install page | |
| 10315 | - jQuery( document ).on( 'click', '#frm-new-template button', installTemplateFieldset ); | |
| 10316 | - | |
| 10317 | - jQuery( '#frm-dismissable-cta .dismiss' ).on( 'click', function( event ) { | |
| 10318 | - event.preventDefault(); | |
| 10319 | - jQuery.post( ajaxurl, { | |
| 10320 | - action: 'frm_lite_settings_upgrade' | |
| 10321 | - }); | |
| 10322 | - jQuery( '.settings-lite-cta' ).remove(); | |
| 10323 | - }); | |
| 10324 | - | |
| 10325 | - const captchaType = document.getElementById( 'frm_re_type' ); | |
| 10326 | - if ( captchaType ) { | |
| 10327 | - captchaType.addEventListener( 'change', handleCaptchaTypeChange ); | |
| 10328 | - } | |
| 10329 | - | |
| 10330 | - document.querySelector( '.frm_captchas' ).addEventListener( 'change', function() { | |
| 10331 | - document.querySelector( '.captcha_settings .frm_note_style' ).classList.toggle( 'frm_hidden' ); | |
| 10332 | - }); | |
| 10333 | - }, | |
| 10334 | - | |
| 10335 | - exportInit: function() { | |
| 10336 | - jQuery( '.frm_form_importer' ).on( 'submit', startFormMigration ); | |
| 10337 | - jQuery( document.getElementById( 'frm_export_xml' ) ).on( 'submit', validateExport ); | |
| 10338 | - jQuery( '#frm_export_xml input, #frm_export_xml select' ).on( 'change', removeExportError ); | |
| 10339 | - jQuery( 'input[name="frm_import_file"]' ).on( 'change', checkCSVExtension ); | |
| 10340 | - document.querySelector( 'select[name="format"]' ).addEventListener( 'change', exportTypeChanged ); | |
| 10341 | - | |
| 10342 | - jQuery( 'input[name="frm_export_forms[]"]' ).on( 'click', preventMultipleExport ); | |
| 10343 | - initiateMultiselect(); | |
| 10344 | - | |
| 10345 | - jQuery( '.frm-feature-banner .dismiss' ).on( 'click', function( event ) { | |
| 10346 | - event.preventDefault(); | |
| 10347 | - jQuery.post( ajaxurl, { | |
| 10348 | - action: 'frm_dismiss_migrator', | |
| 10349 | - plugin: this.id, | |
| 10350 | - nonce: frmGlobal.nonce | |
| 10351 | - }); | |
| 10352 | - this.parentElement.remove(); | |
| 10353 | - }); | |
| 10354 | - | |
| 10355 | - showOrHideRepeaters( getExportOption() ); | |
| 10356 | - | |
| 10357 | - document.querySelector( '#frm-export-select-all' ).addEventListener( 'change', event => { | |
| 10358 | - document.querySelectorAll( '[name="frm_export_forms[]"]' ).forEach( cb => cb.checked = event.target.checked ); | |
| 10359 | - }); | |
| 10360 | - }, | |
| 10361 | - | |
| 10362 | - inboxBannerInit: function() { | |
| 10363 | - const banner = document.getElementById( 'frm_banner' ); | |
| 10364 | - if ( ! banner ) { | |
| 10365 | - return; | |
| 10366 | - } | |
| 10367 | - | |
| 10368 | - const dismissButton = banner.querySelector( '.frm-banner-dismiss' ); | |
| 10369 | - document.addEventListener( | |
| 10370 | - 'click', | |
| 10371 | - function( event ) { | |
| 10372 | - if ( event.target !== dismissButton ) { | |
| 10373 | - return; | |
| 10374 | - } | |
| 10375 | - | |
| 10376 | - const data = { | |
| 10377 | - action: 'frm_inbox_dismiss', | |
| 10378 | - key: banner.dataset.key, | |
| 10379 | - nonce: frmGlobal.nonce | |
| 10380 | - }; | |
| 10381 | - postAjax( | |
| 10382 | - data, | |
| 10383 | - function() { | |
| 10384 | - jQuery( banner ).fadeOut( | |
| 10385 | - 400, | |
| 10386 | - function() { | |
| 10387 | - banner.remove(); | |
| 10388 | - } | |
| 10389 | - ); | |
| 10390 | - } | |
| 10391 | - ); | |
| 10392 | - } | |
| 10393 | - ); | |
| 10394 | - }, | |
| 10395 | - | |
| 10396 | - updateOpts: function( fieldId, opts, modal ) { | |
| 10397 | - var separate = usingSeparateValues( fieldId ), | |
| 10398 | - action = isProductField( fieldId ) ? 'frm_bulk_products' : 'frm_import_options'; | |
| 10399 | - jQuery.ajax({ | |
| 10400 | - type: 'POST', | |
| 10401 | - url: ajaxurl, | |
| 10402 | - data: { | |
| 10403 | - action: action, | |
| 10404 | - field_id: fieldId, | |
| 10405 | - opts: opts, | |
| 10406 | - separate: separate, | |
| 10407 | - nonce: frmGlobal.nonce | |
| 10408 | - }, | |
| 10409 | - success: function( html ) { | |
| 10410 | - document.getElementById( 'frm_field_' + fieldId + '_opts' ).innerHTML = html; | |
| 10411 | - resetDisplayedOpts( fieldId ); | |
| 10412 | - | |
| 10413 | - if ( typeof modal !== 'undefined' ) { | |
| 10414 | - modal.dialog( 'close' ); | |
| 10415 | - document.getElementById( 'frm-update-bulk-opts' ).classList.remove( 'frm_loading_button' ); | |
| 10416 | - } | |
| 10417 | - } | |
| 10418 | - }); | |
| 10419 | - }, | |
| 10420 | - | |
| 10421 | - /* remove conditional logic if the field doesn't exist */ | |
| 10422 | - triggerRemoveLogic: function( fieldID, metaName ) { | |
| 10423 | - jQuery( '#frm_logic_' + fieldID + '_' + metaName + ' .frm_remove_tag' ).trigger( 'click' ); | |
| 10424 | - }, | |
| 10425 | - | |
| 10426 | - downloadXML: function( controller, ids, isTemplate ) { | |
| 10427 | - var url = ajaxurl + '?action=frm_' + controller + '_xml&ids=' + ids; | |
| 10428 | - if ( isTemplate !== null ) { | |
| 10429 | - url = url + '&is_template=' + isTemplate; | |
| 10430 | - } | |
| 10431 | - location.href = url; | |
| 10432 | - }, | |
| 10433 | - | |
| 10434 | - /** | |
| 10435 | - * @since 5.0.04 | |
| 10436 | - */ | |
| 10437 | - hooks: { | |
| 10438 | - applyFilters: function( hookName, ...args ) { | |
| 10439 | - return wp.hooks.applyFilters( hookName, ...args ); | |
| 10440 | - }, | |
| 10441 | - addFilter: function( hookName, callback, priority ) { | |
| 10442 | - return wp.hooks.addFilter( hookName, 'formidable', callback, priority ); | |
| 10443 | - }, | |
| 10444 | - doAction: function( hookName, ...args ) { | |
| 10445 | - return wp.hooks.doAction( hookName, ...args ); | |
| 10446 | - }, | |
| 10447 | - addAction: function( hookName, callback, priority ) { | |
| 10448 | - return wp.hooks.addAction( hookName, 'formidable', callback, priority ); | |
| 10449 | - } | |
| 10450 | - }, | |
| 10451 | - | |
| 10452 | - infoModal: infoModal | |
| 10453 | - }; | |
| 10454 | -} | |
| 10455 | - | |
| 10456 | -frmAdminBuild = frmAdminBuildJS(); | |
| 10457 | - | |
| 10458 | -jQuery( document ).ready( | |
| 10459 | - () => { | |
| 10460 | - frmAdminBuild.init(); | |
| 10461 | - | |
| 10462 | - frmDom.bootstrap.setupBootstrapDropdowns( convertOldBootstrapDropdownsToBootstrap4 ); | |
| 10463 | - function convertOldBootstrapDropdownsToBootstrap4( frmDropdownMenu ) { | |
| 10464 | - const toggle = frmDropdownMenu.querySelector( '.frm-dropdown-toggle' ); | |
| 10465 | - if ( toggle ) { | |
| 10466 | - if ( ! toggle.hasAttribute( 'role' ) ) { | |
| 10467 | - toggle.setAttribute( 'role', 'button' ); | |
| 10468 | - } | |
| 10469 | - if ( ! toggle.hasAttribute( 'tabindex' ) ) { | |
| 10470 | - toggle.setAttribute( 'tabindex', 0 ); | |
| 10471 | - } | |
| 10472 | - } | |
| 10473 | - | |
| 10474 | - // Convert <li> and <ul> tags. | |
| 10475 | - if ( 'UL' === frmDropdownMenu.tagName ) { | |
| 10476 | - convertBootstrapUl( frmDropdownMenu ); | |
| 10477 | - } | |
| 10478 | - } | |
| 10479 | - | |
| 10480 | - function convertBootstrapUl( ul ) { | |
| 10481 | - let html = ul.outerHTML; | |
| 10482 | - html = html.replace( '<ul ', '<div ' ); | |
| 10483 | - html = html.replace( '</ul>', '</div>' ); | |
| 10484 | - html = html.replaceAll( '<li>', '<div class="dropdown-item">' ); | |
| 10485 | - html = html.replaceAll( '<li class="', '<div class="dropdown-item ' ); | |
| 10486 | - html = html.replaceAll( '</li>', '</div>' ); | |
| 10487 | - ul.outerHTML = html; | |
| 10488 | - } | |
| 10489 | - } | |
| 10490 | -); | |
| 10491 | - | |
| 10492 | -function frm_remove_tag( htmlTag ) { // eslint-disable-line camelcase | |
| 10493 | - console.warn( 'DEPRECATED: function frm_remove_tag in v2.0' ); | |
| 10494 | - jQuery( htmlTag ).remove(); | |
| 10495 | -} | |
| 10496 | - | |
| 10497 | -function frm_show_div( div, value, showIf, classId ) { // eslint-disable-line camelcase | |
| 10498 | - if ( value == showIf ) { | |
| 10499 | - jQuery( classId + div ).fadeIn( 'slow' ).css( 'visibility', 'visible' ); | |
| 10500 | - } else { | |
| 10501 | - jQuery( classId + div ).fadeOut( 'slow' ); | |
| 10502 | - } | |
| 10503 | -} | |
| 10504 | - | |
| 10505 | -function frmCheckAll( checked, n ) { | |
| 10506 | - jQuery( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked ); | |
| 10507 | -} | |
| 10508 | - | |
| 10509 | -function frmCheckAllLevel( checked, n, level ) { | |
| 10510 | - var $kids = jQuery( '.frm_catlevel_' + level ).children( '.frm_checkbox' ).children( 'label' ); | |
| 10511 | - $kids.children( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked ); | |
| 10512 | -} | |
| 10513 | - | |
| 10514 | -function frm_add_logic_row( id, formId ) { // eslint-disable-line camelcase | |
| 10515 | - console.warn( 'DEPRECATED: function frm_add_logic_row in v2.0' ); | |
| 10516 | - jQuery.ajax({ | |
| 10517 | - type: 'POST', | |
| 10518 | - url: ajaxurl, | |
| 10519 | - data: { | |
| 10520 | - action: 'frm_add_logic_row', | |
| 10521 | - form_id: formId, | |
| 10522 | - field_id: id, | |
| 10523 | - meta_name: jQuery( '#frm_logic_row_' + id + ' > div' ).length, | |
| 10524 | - nonce: frmGlobal.nonce | |
| 10525 | - }, | |
| 10526 | - success: function( html ) { | |
| 10527 | - jQuery( '#frm_logic_row_' + id ).append( html ); | |
| 10528 | - } | |
| 10529 | - }); | |
| 10530 | - return false; | |
| 10531 | -} | |
| 10532 | - | |
| 10533 | -function frmGetFieldValues( fieldId, cur, rowNumber, fieldType, htmlName ) { | |
| 10534 | - | |
| 10535 | - if ( fieldId ) { | |
| 10536 | - jQuery.ajax({ | |
| 10537 | - type: 'POST', url: ajaxurl, | |
| 10538 | - 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, | |
| 10539 | - success: function( msg ) { | |
| 10540 | - document.getElementById( 'frm_show_selected_values_' + cur + '_' + rowNumber ).innerHTML = msg; | |
| 10541 | - } | |
| 10542 | - }); | |
| 10543 | - } | |
| 10544 | -} | |
| 10545 | - | |
| 10546 | -function frmImportCsv( formID ) { | |
| 10547 | - var urlVars = ''; | |
| 10548 | - if ( typeof __FRMURLVARS !== 'undefined' ) { | |
| 10549 | - urlVars = __FRMURLVARS; | |
| 10550 | - } | |
| 10551 | - | |
| 10552 | - jQuery.ajax({ | |
| 10553 | - type: 'POST', url: ajaxurl, | |
| 10554 | - data: 'action=frm_import_csv&nonce=' + frmGlobal.nonce + '&frm_skip_cookie=1' + urlVars, | |
| 10555 | - success: function( count ) { | |
| 10556 | - var max = jQuery( '.frm_admin_progress_bar' ).attr( 'aria-valuemax' ); | |
| 10557 | - var imported = max - count; | |
| 10558 | - var percent = ( imported / max ) * 100; | |
| 10559 | - jQuery( '.frm_admin_progress_bar' ).css( 'width', percent + '%' ).attr( 'aria-valuenow', imported ); | |
| 10560 | - | |
| 10561 | - if ( parseInt( count, 10 ) > 0 ) { | |
| 10562 | - jQuery( '.frm_csv_remaining' ).html( count ); | |
| 10563 | - frmImportCsv( formID ); | |
| 10564 | - } else { | |
| 10565 | - jQuery( document.getElementById( 'frm_import_message' ) ).html( frm_admin_js.import_complete ); // eslint-disable-line camelcase | |
| 10566 | - setTimeout( function() { | |
| 10567 | - location.href = '?page=formidable-entries&frm_action=list&form=' + formID + '&import-message=1'; | |
| 10568 | - }, 2000 ); | |
| 10569 | - } | |
| 10570 | - } | |
| 10571 | - }); | |
| 10572 | -} | |
| 1 | +(()=>{function e(e){return function(e){if(Array.isArray(e))return r(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||t(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 t(e,t){if(e){if("string"==typeof e)return r(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}function r(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}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)}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")}},i={init:function(){n.setElements(),r(e.getElementById("frm_deauthorize_link")).on("click",i.deauthorize),r(".frm_authorize_link").on("click",i.authorize),r(".frm-dashboard-license-options").on("click","#frm_deauthorize_link",i.deauthorize),r(".frm-dashboard-license-options").on("click","#frm_reconnect_link",i.reauthorize),null!==n.reset&&r(n.reset).on("click",i.reauthorize)},authorize:function(){var t=this,n=this.getAttribute("data-plugin"),o=e.getElementById("edd_"+n+"_license_key"),a=o.value,l=e.getElementById("proplug-wpmu");this.classList.add("frm_loading_button"),l=null===l?0: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){i.afterAuthorize(e,o),t.classList.remove("frm_loading_button")}})},afterAuthorize:function(e,t){!0===e.success&&(t.value="•••••••••••••••••••"),wp.hooks.doAction("frm_after_authorize",e),i.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 o=n.messageBox;!0===r.success&&(i.showAuthorized(!0),i.showInlineSuccess(),wp.hooks.doAction("frmAdmin.afterLicenseAuthorizeSuccess",{msg:r})),i.showProgress(r),""!==r.message&&(setTimeout((function(){o.innerHTML="",o.classList.add("frm_hidden"),o.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",i=e.querySelectorAll(".frm_"+r+"_box");i.length&&i.forEach((function(e){e.className=e.className.replace("frm_"+r+"_box","frm_"+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_"+t+"_license_key"),o=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:o,plugin:t,nonce:frmGlobal.nonce},success:function(){i.showAuthorized(!1),n.value="",a.replaceWith("Disconnected"),wp.hooks.doAction("frmAdmin.afterLicenseDeauthorizeSuccess",{})}}),!1}};return i}(document,window,jQuery),window.frmAdminBuild=function(){var r,o,a=frm_admin_js,l=frmDom,s=l.tag,d=l.div,c=l.span,f=l.a,u=l.svg,m=l.img,_=frmDom.util.onClickPreventDefault,p=frmDom.ajax,g=(p.doJsonFetch,p.doJsonPost);a.contextualShortcodes=(o=null===(r=document.getElementById("frm_adv_info"))||void 0===r?void 0:r.dataset.contextualShortcodes)?((o=JSON.parse(o)).addressSelector="[id^=email_to], [id^=from_], [id^=cc], [id^=bcc]",o.bodySelector="[id^=email_message_]",o):[];var y,h,v,b={save:u({href:"#frm_save_icon"}),drag:u({href:"#frm_drag_icon",classList:["frm_drag_icon","frm-drag"]})},j=jQuery(document.getElementById("frm-show-fields")),w=document.getElementById("new_fields"),Q=document.getElementById("form_id"),x=!1,E=0,k=0,L=0,S={},A=0,I=wp.i18n,B=I.__,C=I.sprintf,q={dragging:!1};null!==Q&&(k=Q.value);var N,T=new URL(window.location.href),O=T.searchParams,D=document.getElementById("frm_builder_page");function M(e){e.stopPropagation(),e.preventDefault(),F(this)}function F(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:To}):function(e){var t,r,n,i,o,a=To("#frm_confirm_modal","400px"),l=document.getElementById("frm-confirmed-click");if(!1===a)return!1;for(n in o=(t=e.getAttribute("data-frmverify"))?e.getAttribute("data-frmverify-btn"):"",(r=jQuery(".frm-confirm-msg")).empty(),t&&(r.append(document.createTextNode(t)),o&&l.classList.add(o)),removeAtts=l.dataset,i)l.removeAttribute("data-"+n);for(n in i=e.dataset)"frmverify"!==n&&l.setAttribute("data-"+n,i[n]);return wp.hooks.doAction("frmAdmin.beforeOpenConfirmModal",{$info:a,link:e}),a.dialog("open"),l.setAttribute("href",e.getAttribute("href")||e.getAttribute("data-href")),!1}(e))}function H(e){var t=To("#frm_info_modal","400px");return!1===t||(jQuery(".frm-info-msg").html(e),t.dialog("open")),!1}function P(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 z(e){var t=this.getAttribute("data-frmhide"),r=this.getAttribute("data-frmshow"),n=this.getAttribute("data-frmuncheck"),i=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 o=this.getAttribute("data-toggleclass")||"frm_hidden";null!==t&&jQuery(t).addClass(o),null!==r&&jQuery(r).removeClass(o);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 i.length&&i.forEach((function(e){var t=document.querySelector(e);t&&(t.checked=!1)})),!1}function R(){document.querySelectorAll(".tooltip").forEach((function(e){e.remove()}))}function G(){var e,t,r;if(!parseInt(this.getAttribute("data-skip-frm-js"))&&!1!==F(this)){var n=jQuery(this),i=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===i.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(#"+i+")").last().length&&(""!==e&&(e+=","),e+="#"+jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#"+i+")").last().attr("id")+" .frm_toggle_cf_opts"));var o=document.getElementById(i),a=jQuery(o);return a.fadeOut(300,(function(){var r;a.remove(),Mi(),""!==t&&jQuery(t).hide(),""!==e&&jQuery(e+" a,"+e).removeClass("frm_hidden").fadeIn("slow"),this.closest(".frm_form_action_settings")&&function(e){si(e);var t={type:e};wp.hooks.doAction("frm_after_action_removed",t)}(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",i,o),!1}}function $(e,t){void 0===t&&(t=this),Ze(t,!1);var r=jQuery(t).closest(".frm_form_action_settings"),n=e.target;if(r.length&&void 0!==n){var i=n.parentElement.className;if("string"==typeof i&&(i.indexOf("frm_email_icons")>-1||i.indexOf("frm_toggle")>-1))return void e.stopPropagation()}var o=r.children(".widget-inside");if(r.length&&o.find("p, div, table").length<1){var a=r.find('input[name$="[ID]"]').val(),l=r.find('input[name$="[post_excerpt]"]').val();l&&(o.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){o.html(e),lo(),Yn("#"+r.attr("id")),jo(o),jQuery(t).trigger("frm-action-loaded"),wp.hooks.doAction("frm_filled_form_action",o)}}))}jQuery(t).closest(".frm_field_box").siblings().find(".widget-inside").slideUp("fast"),void 0!==t.className&&-1!==t.className.indexOf("widget-action")||jQuery(t).closest(".start_divider").length<1||((o=jQuery(t).closest("div.widget").children(".widget-inside")).is(":hidden")?o.slideDown("fast"):o.slideUp("fast"))}function W(){var e=this.getAttribute("href");if(void 0===e)return!1;var t=e.replace("#","."),r=jQuery(this);r.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab"),r.closest("div").children(".tabs-panel").not(e).not(t).hide();var n=document.getElementById(e.replace("#",""));return n&&(n.style.display="block"),"frm_insert_fields_tab"!==this.id||this.closest("#frm_adv_info")||Ke(),!1}function U(e,t){var r=(e=jQuery(e)).attr("href");if(void 0!==r){var n,i,o=r.replace("#",".");if(e.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab"),e.closest("div").find(".tabs-panel").length)e.closest("div").children(".tabs-panel").not(r).not(o).hide();else if(null!==document.getElementById("form_global_settings")){var a=e.data("frmajax");e.closest(".frm_wrap").find(".tabs-panel, .hide_with_tabs").hide(),void 0!==a&&"1"==a&&(n=r.replace("#",""),(i=jQuery(".frm_"+n+"_ajax")).length&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_settings_tab",tab:n.replace("_settings",""),nonce:frmGlobal.nonce},success:function(e){i.replaceWith(e)}}))}else jQuery("#frm-categorydiv .tabs-panel, .hide_with_tabs").hide();jQuery(r).show(),jQuery(o).show(),Wi(),"auto"!==t&&(jQuery(".frm_updated_message").hide(),jQuery(".frm_warning_style").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="+jQuery('.frm_form_settings input[name="id"]').val()+"&t="+r.replace("#","")):jQuery(".frm_settings_form").attr("action","?page=formidable-settings&t="+r.replace("#","")))}}function V(e){var t,r;document.querySelectorAll(e).forEach((function(e){K(e),Array.from(e.children).forEach((function(e){return X(e,".frm-move")}));var t=jQuery(e).children('[data-type="divider"]').children(".divider_section_only");t.length&&K(t)})),t=jQuery("#frm_builder_page"),r={items:".frm_sortable_field_opts li",axis:"y",opacity:.65,forcePlaceholderSize:!1,handle:".frm-drag",helper:function(e,t){return x=t.clone().insertAfter(t),t.clone()},stop:function(e,t){x&&x.remove(),rn(t.item.attr("id").replace("frm_delete_field_","").replace("-"+t.item.data("optkey")+"_container","")),Mi()}},jQuery(t).sortable(r)}function K(e){jQuery(e).droppable({accept:".frmbutton, li.frm_field_box",deactivate:ne,over:J,out:Y,tolerance:"pointer"})}function J(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(!Qe(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 Y(e){e.target.classList.remove("frm-over-droppable")}function X(e,t){var r={helper:Z,revert:"invalid",delay:10,start:ee,stop:te,drag:re,cursor:"grabbing",refreshPositions:!0,cursorAt:{top:0,left:90}};"string"==typeof t&&(r.handle=t),jQuery(e).draggable(r)}function Z(e){var t,r=e.delegateTarget;if(Ee(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=B("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 i=r.getAttribute("data-ftype");if((t=(t=document.getElementById("frm-insert-fields").querySelector(".frm_t"+i)).cloneNode(!0)).classList.add("form-field"),t.classList.add("ui-sortable-helper"),t)return t.cloneNode(!0)}return d({className:"frmbutton"})}function ee(e,t){q.dragging=!0;var r,n=h;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"),gr(),(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()}))})),Me(),Te(),R()}function te(){h.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 re(e,t){!function(e){v.scrollTop((function(t,r){var n=e.clientY,i=h.offsetHeight,o=e.clientY-h.offsetTop,a=o-i/2;return o>i-50&&n>5?r+.1*a:o<70&&n<130?r-Math.abs(.1*a):r}))}(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}(),i=document.getElementById("frm_drag_placeholder");if(Qe(r,n,e)){i||(i=s("li",{id:"frm_drag_placeholder",className:"sortable-placeholder"}));var o,a=t.helper.get(0);if((a.classList.contains("form-field")||a.classList.contains("frm_field_box"))&&(a.style.transform="translateY("+(o=t.helper,h.scrollTop-o.initialOffset+"px)")),"frm-show-fields"===n.id||n.classList.contains("start_divider"))return i.style.left=0,void function(e){var t,r=e.y,n=e.placeholder,i=jQuery(e.droppable);if($children=i.children().not(".edit_field_type_end_divider"),0===$children.length)i.prepend(n),t=0;else{var o=ie(i,r);if(o===$children.length){var a=jQuery($children.get(o-1));t=a.offset().top+a.outerHeight(),i.append(n);var l=i.children(".edit_field_type_end_divider");l.length&&i.append(l)}else t=jQuery($children.get(o)).offset().top,jQuery($children.get(o)).before(n)}t-=i.offset().top,n.style.top=t+"px"}({droppable:n,y:e.clientY,placeholder:i});i.style.top="",function(e){var t,r=e.x,n=e.placeholder,i=jQuery(e.droppable),o=ae(i);if(o.length){var a=function(e,t){var r,n,i,o,a=ae(e);for(o=0,r=a.length-1;r>=0;--r)if(n=a.get(r),t>(i=jQuery(n).offset().left)){o=r,t>i+jQuery(n).outerWidth()/2&&(o=r+1);break}return o}(i,r);if(a===o.length){var l=jQuery(o.get(a-1));t=l.offset().left+l.outerWidth(),i.append(n)}else t=jQuery(o.get(a)).offset().left,jQuery(o.get(a)).before(n),t-=0===a?4:8;t-=i.offset().left,n.style.left=t+"px"}}({droppable:n,x:e.clientX,placeholder:i})}else i&&i.remove()}function ne(e,t){if(q.dragging){q.dragging=!1;var r=t.draggable[0],n=document.getElementById("frm_drag_placeholder");if(!n)return t.helper.remove(),void y();!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 i=t.helper.parent(),o=t.helper.get(0).closest("ul.start_divider"),a=n.closest("ul.start_divider");r.classList.contains("frm-new-field")?function(e){if(ge(e))wp.hooks.doAction("frm_stopped_inserting_by_dragging",e);else{var t=document.getElementById("frm_drag_placeholder"),r=e.replace("|","-")+"_"+we(),n=s("li",{id:r,className:"frm-wait frmbutton_loadingnow"}),i=jQuery(n),o=fe(jQuery(t)),a=ue(o),l=me(o);t.parentNode.insertBefore(n,t),t.remove(),le(i);var d=0;"summary"===e&&(d=jQuery(".frmbutton_loadingnow#"+r).prevAll('li[data-type="break"]').length?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:pe(e,l,a,d),success:function(t){ye(t,i);var r=he(t);r&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:r,fieldType:e,form_id:a})},error:je})}}(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")&&X(t,".frm-move")}}(n.parentElement));var l=o?parseInt(o.closest(".edit_field_type_divider").getAttribute("data-fid")):0,d=a?parseInt(a.closest(".edit_field_type_divider").getAttribute("data-fid")):0;n.remove(),t.helper.remove();var c=i.length?ae(i):[];!function(e,t){var r;e.length&&(t.length?le(t.first()):(r=e.get(0).closest("li.frm_field_box"))&&!r.classList.contains("edit_field_type_divider")&&r.remove())}(i,c),function(e,t){0===t.length&&1===ae(jQuery(e.parentNode)).length||le(jQuery(e))}(r,c),l!==d&&_e(jQuery(r),o),y()}}function ie(e,t){var r,n,i,o,a=e.children().not(".edit_field_type_end_divider"),l=a.length;if(!document.querySelector(".frm-has-fields .frm_no_fields"))return 0;for(o=0,r=l-1;r>=0;--r)if(n=a.get(r),t>(i=jQuery(n).offset().top)){o=r,t>i+jQuery(n).outerHeight()/2&&(o=r+1);break}return o}function oe(){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")&&We(e))}))})),xn(),document.querySelectorAll(".edit_field_type_end_divider").forEach((function(e){return e.parentNode.appendChild(e)})),document.querySelectorAll("li.form_field_box:not(.form-field)").forEach((function(e){return!e.children.length&&e.remove()})),Qn();var e=new Event("frm_sync_after_drag_and_drop",{bubbles:!1});document.dispatchEvent(e)}function ae(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 le(e,t){var r,n,i,o;void 0===t&&(t="even"),r=e.parent().children("li.form-field, li.frmbutton_loadingnow").not(".edit_field_type_end_divider"),n=r.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!==n?r.each(ce(i,Ut(n))):"clear"===t?r.each(ce(i,"")):(o=-1!==["left","right","middle","even"].indexOf(t)?function(e){return Wt(n,t,e)}:function(e){return ar(t[e])},r.each(ce(i,o))),se(e.parent(),r.length)}function se(e,t){var r,n;if(void 0!==e.offset()){if(r=t>=2,null===(n=document.getElementById("frm_field_group_controls"))){if(!r)return;(n=d()).id="frm_field_group_controls",n.setAttribute("role","group"),n.setAttribute("tabindex",0),function(e){var t,r;(t=document.createElement("span")).innerHTML='<svg class="frmsvg"><use xlink:href="#frm_field_group_layout_icon"></use></svg>';var n=B("Set Row Layout","formidable");de(t,n),zt(t,n),(r=document.createElement("span")).innerHTML='<svg class="frmsvg"><use xlink:href="#frm_thick_move_icon"></use></svg>',r.classList.add("frm-move");var i=B("Move Field Group","formidable");de(r,i),zt(r,i),e.innerHTML="",e.appendChild(t),e.appendChild(r),e.appendChild(function(){var e=c({className:"dropdown"}),t=f({className:"frm_bstooltip frm-hover-icon frm-dropdown-toggle dropdown-toggle",children:[c({child:u({href:"#frm_thick_more_vert_icon"})}),c({className:"screen-reader-text",text:B("Toggle More Options Dropdown","formidable")})]});frmDom.setAttributes(t,{title:B("More Options","formidable"),"data-toggle":"dropdown","data-container":"body"}),zt(t,B("More Options","formidable")),e.appendChild(t);var r=d({className:"frm-dropdown-menu dropdown-menu dropdown-menu-right"});return r.setAttribute("role","menu"),e.appendChild(r),e}())}(n),D.appendChild(n)}e.append(n),n.style.display=r?"block":"none"}}function de(e,t){e.setAttribute("data-toggle","tooltip"),e.setAttribute("data-container","body"),e.setAttribute("title",t),e.addEventListener("mouseover",(function(){null===e.getAttribute("data-original-title")&&jQuery(e).tooltip()}))}function ce(e,t){return function(r){var n,i,o,a,l,s,d;for(n="function"==typeof t?t(r):t,i=e.length,l=!1,o=0;o<i;++o)if(a=e[o],this.classList.contains(a)){l=a;break}void 0!==(s=this.dataset.fid)?(ii(document.getElementById("frm-single-settings-"+s)),null!==(d=document.getElementById("frm_classes_"+s))&&(!1===l?""!==n&&(d.value=d.value.concat(" "+n)):(this.classList.remove(l),d.value=d.value.replace(l,n)),this.classList.contains("frm_first")&&(this.classList.remove("frm_first"),d.value=d.value.replace("frm_first","").trim()),0===r&&(this.classList.add("frm_first"),d.value=d.value.concat(" frm_first")),jQuery(d).trigger("change"))):this.classList.add(n)}}function fe(e){var t="";return void 0===e||e.hasClass("edit_field_type_divider")||(t=e.closest(".edit_field_type_divider")),t}function ue(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_'+n+']"]').val()}}return void 0!==t&&""!==t||(t=k),t}function me(e){var t=0;return void 0!==e[0]&&(t=e.attr("id").replace("frm_field_id_","")),t}function _e(e,t){if(e.hasClass("form-field")){var r=e.attr("id").replace("frm_field_id_",""),n=fe(e),i=ue(n),o=me(n),a=t?ue(jQuery(t.parentNode)):0;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_update_field_after_move",form_id:i,field:r,section_id:o,previous_form_id:a,nonce:frmGlobal.nonce},success:function(){xn(),function(e,t){document.getElementById("frm_in_section_"+e).value=t}(r,o)}})}else ae(jQuery(e.get(0).firstChild)).each((function(){_e(jQuery(this),t)}))}function pe(e,t,r,n){return{action:"frm_insert_field",form_id:r,field_type:e,section_id:t,nonce:frmGlobal.nonce,has_break:n,last_row_field_ids:ve()}}function ge(e){return wp.hooks.applyFilters("frm_should_stop_inserting_field",!1,e)}function ye(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=be(e),t.get(0).parentNode.parentNode.classList.contains("ui-draggable")||X(t.get(0).parentNode.parentNode,".frm-move")):r=$e(e),t.replaceWith(r),Qn(),Ue(e,!1),n.length&&le(n.first()),xn(),n.length?X(r.get(0),".frm-move"):(K(r.get(0).querySelector("ul.frm_sorting")),X(r.get(0).querySelector("li.form-field"),".frm-move"))}function he(e){var t=e.match(/data-fid="(\d+)"/);return t?parseInt(t[1]):0}function ve(){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}function be(e){var t=d();return t.innerHTML=e,jQuery(t.firstChild)}function je(e,t,r){!function(e,t){(function(e){return 0===e.status||0===e.readyState})(t)||H(e+". Please try again.")}(r,e)}function we(){return++L}function Qe(e,t,r){if(!1===t)return!1;if(t.closest(".frm-sortable-helper"))return!1;var n,i,o,a=e.classList.contains("edit_field_type_submit"),l=!e.classList.contains("form_field")&&!!e.querySelector(".edit_field_type_submit");if("frm-show-fields"===t.id){var s=ie(jQuery(t),r.clientY);return a||l?s>t.childElementCount-1:s<=jQuery(t.querySelector(".edit_field_type_submit").closest("#frm-show-fields > li")).index()}if(a)return!(t.classList.contains("start_divider")||!xe(t.parentElement)&&(!xe(t.parentElement.nextElementSibling)||e.parentElement.querySelector("li.frm_field_box:not(.edit_field_type_submit)")));if(t.classList.contains("start_divider")&&(e.classList.contains("edit_field_type_gdpr")||"gdpr"===e.id)&&t.closest(".repeat_section"))return!1;if(!t.classList.contains("start_divider")){if(n=ae(jQuery(t)),i=jQuery(e),!(n.length<6)&&(n.length>6||(o=i.attr("data-fid"),1!==jQuery(n).filter('[data-fid="'+o+'"]').length)))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"),i=r.contains("frm_thidden"),o=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||i||o||a)||(!(t.classList.contains("start_divider")||null!==t.closest(".start_divider"))||!a&&!o):!(ke(t)||i||n||l)}(e,t):function(e,t){if(Ee(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(ke(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 xe(e){return e&&e.matches("#frm-show-fields > li:last-child")}function Ee(e){return e.classList.contains("frm_field_box")&&!e.classList.contains("form-field")}function ke(e){return null!==e.querySelector(".edit_field_type_break, .edit_field_type_hidden, .edit_field_type_user_id")}function Le(e){var t=document.getElementById(e),r=jQuery(t),n=[],i=function(e){var t=e.querySelector(".frm_hidden_fdata");e.classList.add("frm_load_now"),null!==t&&n.push(t.innerHTML)},o=t;i(o);for(var a=Se(o);a&&n.length<15;)i(a),o=a,a=Se(a);jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_load_field",field:n,form_id:k,nonce:frmGlobal.nonce},success:function(e){return function(e,t,r){var n,i;if(0===(e=e.replace(/^\s+|\s+$/g,"")).indexOf("{")){for(n in e=JSON.parse(e))jQuery("#frm_field_id_"+n).replaceWith(e[n]),V("#frm_field_id_"+n+".edit_field_type_divider ul.frm_sorting"),X(document.getElementById("frm_field_id_"+n));((i=t.nextAll(".frm_field_loading:not(.frm_load_now)")).length||(i=jQuery(document.getElementById("frm-show-fields")).find(".frm_field_loading:not(.frm_load_now)")).length)&&Le(i.attr("id")),lo(),Tr(),Be();var o=new Event("frm_ajax_loaded_field",{bubbles:!1});o.frmFields=r.map((function(e){return JSON.parse(e)})),document.dispatchEvent(o)}else jQuery(".frm_load_now").removeClass(".frm_load_now").html("Error")}(e,r,n)}})}function Se(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 Ae(){var e=jQuery(this);if(e.hasClass("disabled"))return!1;var t=e.closest(".frmbutton").attr("id");if(!ge(t)){var r=0;"summary"===t&&(r=j.children('li[data-type="break"]').length>0?1:0);var n=k;return jQuery.ajax({type:"POST",url:ajaxurl,data:pe(t,0,n,r),success:function(e){Ie(e);var r=he(e);r&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:e,fieldId:r,fieldType:t,form_id:n})},error:je}),!1}}function Ie(e){document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var t=$e(e),r=j[0].querySelector(".edit_field_type_submit");r?jQuery(r.closest(".frm_field_box:not(.form-field)")).before(t):j.append(t),Ue(e,!0),t.each((function(){K(this.querySelector("ul.frm_sorting")),X(this.querySelector(".form-field"),".frm-move")}))}function Be(){var e=!0,t=document.querySelectorAll(".frmjs_prod_field_opt_cont");j.find("li.edit_field_type_product").length>1&&(e=!1);for(var r=0;r<t.length;r++)e?t[r].classList.add("frm_hidden"):t[r].classList.remove("frm_hidden")}function Ce(){var e,t,r,n,i;if(e=jQuery(this).closest("li.form-field"),(n=this.getAttribute("frm-target-row-id"))&&n.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||ae(jQuery(t.querySelector("ul"))).length<6}(e.get(0)))return Te(),r=function(e){var t=[];return jQuery(document.getElementById("frm_field_id_"+e)).find("li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)").each((function(){t.push(jQuery(this).data("fid"))})),t}(t=e.data("fid")),null!==n&&(i=this.getAttribute("frm-field-order")),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_duplicate_field",field_id:t,form_id:k,children:r,nonce:frmGlobal.nonce},success:function(r){var o,a,l;if(null!==n&&null!==(a=document.getElementById(n)))return l=be(r),jQuery(a).append(l),X(l.get(0),".frm-move"),null!==i&&a.lastElementChild.setAttribute("frm-field-order",i),jQuery(a).trigger("frm_added_duplicated_field_to_row",{duplicatedFieldHtml:r,originalFieldId:t}),Ue(r,!1),void qe(e.get(0),l.get(0));e.siblings("li.form-field").length?(l=be(r),e.after(l),le(e),X(l.get(0),".frm-move")):(l=$e(r),e.parent().parent().after(l),K(l.get(0).querySelector("ul.frm_sorting")),X(l.get(0).querySelector("li.form-field"),".frm-move")),Qn(),Ue(r,!1),Ne(t,r),En(l.find(".start_divider")),null===(o=e[0].querySelector(".frm-dropdown-menu.dropdown-menu-right"))||void 0===o||o.classList.remove("show"),qe(e.get(0),l.get(0))}}),!1;H(C(B("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"),6))}function qe(e,t){var r,n=e.closest(".frm-field-group-hover-target");if(n&&Ee(n.parentElement)){var i=e.dataset.fid,o=null===(r=document.getElementById("frm_classes_"+i))||void 0===r?void 0:r.value;if(o&&(o=o.replace("frm_first",""),!t.className.includes(o))){t.className+=" "+o;var a=document.getElementById("frm_classes_"+t.dataset.fid);a&&(a.value=o)}}}function Ne(e,t){var r,n,i,o,a,l;null!==(r=document.getElementById("frm-single-settings-"+e))&&void 0!==(n=jQuery(t).attr("data-fid"))&&null!==(i=document.getElementById("frm-single-settings-"+n))&&(o=["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,l,s;(s=t.name.substr(14).split("_")).pop(),"options"!==(r=s.join("_"))?-1!==o.indexOf(r)&&(a=t.matches("input")?"input":"textarea",null!==(l=i.querySelector(a+'[name="field_options['+r+"_"+n+']"]'))&&("checkbox"===t.type?t.checked!==l.checked&&jQuery(l).trigger("click"):"text"!==t.type&&"textarea"!==a||t.value!==l.value&&(l.value=t.value,jQuery(l).trigger("change")))):function(e,t,r,n){var i,o;i="field_options[options_"+n+"]"+e.name.substr(23+(""+r).length),null!==(o=t.querySelector('input[name="'+i+'"]'))&&o.value!==e.value&&(o.value=e.value,jQuery(o).trigger("change"))}(t,i,e,n)})),null!==(a=r.querySelector('input[name="default_value_'+e+'"]'))&&null!==(l=i.querySelector('input[name="default_value_'+n+'"]'))&&a.value!==l.value&&(l.value=a.value,jQuery(l).trigger("change")))}function Te(){var e=document.querySelector(".frm-field-settings-open");null!==e&&(e.classList.remove("frm-field-settings-open"),jQuery(document).off("click","#frm_builder_page",Oe),jQuery(".frm-field-action-icons .dropdown.open").removeClass("open"))}function Oe(e){jQuery(e.originalEvent.target).closest(".frm-field-action-icons").length||Te()}function De(e){var t=!!(e.ctrlKey||e.metaKey||e.shiftKey);jQuery(D).toggleClass("frm-multiselect-key-is-down",t),function(e){var t,r,n;h.classList.contains("frm-dragging-field")||null===document.querySelector(".frm-field-group-hover-target .frm-field-settings-open")&&(null===(t=document.elementFromPoint(e.clientX,e.clientY))||t.classList.contains("edit_field_type_divider")||null===(r=t.closest("ul.frm_sorting"))||r.classList.contains("start_divider")||"frm-show-fields"===r.id||(!1===(n=Me())||jQuery(n).is(r)||cr(),se(jQuery(r),ae(jQuery(r)).length),r.classList.add("frm-field-group-hover-target"),jQuery("#wpbody-content").on("mousemove",Fe)))}(e)}function Me(){var e,t;return null!==(e=document.getElementById("frm_field_group_controls"))&&(e.style.display="none"),null!==(t=document.querySelector(".frm-field-group-hover-target"))&&(jQuery("#wpbody-content").off("mousemove",Fe),t.classList.remove("frm-field-group-hover-target"),t)}function Fe(e){var t=document.elementFromPoint(e.clientX,e.clientY);null!==t&&null!==t.closest("#frm-show-fields")||Me()}function He(e){gr(),setTimeout((function(){var t,r;if(null!==(t=document.querySelector(".dropdown.show .frm-dropdown-menu"))){null===t.getAttribute("aria-label")&&t.setAttribute("aria-label",B("More Options","formidable")),0===t.children.length&&function(e,t){var r,n;r=t?"_field_group":"_field",n=[Re(t),Ge(t)],t||n.push({class:"frm_select",icon:"frm_settings_icon",label:B("Field Settings","formidable")}),n.forEach((function(t){var n,i,o;(n=document.createElement("div")).classList.add("frm_more_options_li","dropdown-item"),(i=document.createElement("a")).classList.add(t.class+r),i.setAttribute("href","#"),zt(i),(o=document.createElement("span")).textContent=t.label,i.innerHTML='<svg class="frmsvg"><use xlink:href="#'+t.icon+'"></use></svg>',i.appendChild(document.createTextNode(" ")),i.appendChild(o),n.appendChild(i),e.appendChild(n)}))}(t,!0===e),(r=jQuery(t)).offset().left>jQuery(window).width()-r.outerWidth()&&(t.style.left=-r.outerWidth()+"px");var n=t.firstElementChild.querySelector("a");n&&n.focus()}}),0)}function Pe(){He(!0)}function ze(e){var t=e.target.closest(".frm-section-collapsed");t&&("show"===e.type?t.style.zIndex=3:t.style.zIndex=1)}function Re(e){var t={class:"frm_delete",icon:"frm_delete_icon"};return t.label=B(e?"Delete Group":"Delete","formidable"),t}function Ge(e){var t={class:"frm_clone",icon:"frm_clone_icon"};return t.label=B(e?"Duplicate Group":"Duplicate","formidable"),t}function $e(e){var t=d();"string"==typeof e?t.innerHTML=e:t.appendChild(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 We(e){var t=s("ul",{className:"frm_grid_container frm_sorting"}),r=s("li",{className:"frm_field_box",child:t});e.replaceWith(r),t.appendChild(e),K(t),X(r,".frm-move")}function Ue(e,t){var r,n,i=/id="(\S+)"/.exec(e),o=document.getElementById(i[1]),a="#"+i[1]+".edit_field_type_divider ul.frm_sorting.start_divider",l=jQuery(a),s=o.getAttribute("data-type");r=e,(n=d()).innerHTML=r,n.querySelectorAll(".form-field").forEach(Ve);var c,f,u=!1;if(Mi(),V(a),"quantity"===s&&function(e){var t=e.getAttribute("data-fid"),r=document.getElementById("field_options[product_field_"+t+"]");null!==r&&(rt(r),ii(document.getElementById("frm-single-settings-"+t)))}(o),"product"!==s&&"quantity"!==s||Be(),l.length)l.parent(".frm_field_box").children(".frm_no_section_fields").addClass("frm_block");else{var m=jQuery(o).closest("ul.frm_sorting.start_divider");m.length&&(En(m),u=!0)}if(-1!==e.indexOf("frm-collapse-page")&&Tr(),f="frm-newly-added",(c=o).classList?c.classList.add(f):c.className+=" "+f,setTimeout((function(){o.classList.remove("frm-newly-added")}),1e3),t){var _=o.getBoundingClientRect(),p=document.getElementById("post-body-content");_.top>=0&&_.left>=0&&_.right<=(window.innerWidth||document.documentElement.clientWidth)&&_.bottom<=(window.innerHeight||document.documentElement.clientHeight)||p.scroll({top:p.scrollHeight,left:0,behavior:"smooth"}),!1===u&&En(l)}Je(),lo(),document.getElementById("frm-show-fields").classList.remove("frm-over-droppable");var g=new Event("frm_added_field",{bubbles:!1});g.frmField=o,g.frmSection=a,g.frmType=s,g.frmToggles=u,document.dispatchEvent(g)}function Ve(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+=","+e.dataset.fid))}}function Ke(e){jQuery("#new_fields .frm-single-settings").addClass("frm_hidden"),jQuery("#frm-options-panel > .frm-single-settings").removeClass("frm_hidden"),Je(e)}function Je(e){jQuery("li.ui-state-default.selected").removeClass("selected"),jQuery(".frm-show-field-settings.selected").removeClass("selected"),e||gr()}function Ye(){var e=this.value,t=function(e){var t,r=[],n=e.split(""),i=n.length,o=["{","[","("],l={"}":"{",")":"(","]":"["},s=[];for(t=0;t<i;t++)o.includes(n[t])?r.push(n[t]):l.hasOwnProperty(n[t])&&r.pop()!==l[n[t]]&&s.push(n[t]);return r.length>0||s.length>0?a.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=a.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+=a.view_shortcodes+"\n\n"),t}(e)}(e,this),""!==t&&H(e+"\n\n"+t)}function Xe(e,t){for(var r,n,i,o=!1,a=0;a<t.length;a++){var l=document.getElementsByName((r=t[a],n=e.fieldId,void 0,i=r.indexOf("]"),"field_options"+r.substring(0,i)+"_"+n+r.substring(i)));if(l.length&&jQuery(l[0]).val()){o=!0;break}}return o}function Ze(e,t){var r,n,i,o,a=jQuery(e).closest(".frm-single-settings"),l=a.find(".frm-calc-field");if(t||l.length&&""!==l.val()&&!l.is(":hidden")){var s=function(e){var t=jQuery(e).find(".frm_code_list");return 1===t.length&&t.hasClass("frm_js_summary_list")}(e),d=a.find('input[name="frm_fields_submitted[]"]').val();r=function(e,t){var r=e.querySelector(".frm_code_list"),n=JSON.parse(r.getAttribute("data-exclude"));if(t){var i=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(i.length)for(var o=0;o<n.length;o++)i.includes(n[o])&&(n.splice(o,1),o--)}return n}(t?e:document.getElementById("frm-calc-box-"+d),s);var f=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}(r);for(n=tt(),(o=document.getElementById("frm-calc-list-"+d)).innerHTML="",i=0;i<n.length;i++)if(!(r&&r.includes(n[i].fieldType)||f.length&&Xe(n[i],f))){var u=document.createElement("a");u.setAttribute("href","#"),u.setAttribute("data-code",n[i].fieldId),u.classList.add("frm_insert_code"),u.appendChild(c(n[i].fieldName)),u.appendChild(c({className:"frm-text-sm frm-text-grey-500",text:"["+n[i].fieldId+"]"}));var m=document.createElement("li");m.classList.add("frm-field-list-"+d),m.classList.add("frm-field-list-"+n[i].fieldType),m.appendChild(u),o.appendChild(m)}}}function et(){Ze(jQuery(".frm-inline-modal.postbox:has(.frm_js_summary_list)")[0],!0)}function tt(e){var t,r=[],n=document.querySelectorAll("li.frm_field_box"),i=void 0!==e;for(t=0;t<n.length;t++)if(!i||n[t].getAttribute("data-ftype")===e){var o=n[t].getAttribute("data-fid");void 0!==o&&o&&r.push({fieldId:o,fieldName:it("frm_name_"+o),fieldType:it("field_options_type_"+o),fieldKey:it("field_options_field_key_"+o)})}return wp.hooks.applyFilters("frm_admin_get_field_list",r,e,n)}function rt(e){var t,r,n,i=[],o=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=tt("product"),s=tt("quantity"),d="SELECT"===e.tagName,c=1===s.length&&1===l.length;for(d&&(o=e.getAttribute("data-frmcurrent")),t=0;t<l.length;t++)n=l[t].fieldId.toString(),r=c||-1!==o.indexOf(n),d?(r=r?" selected":"",i.push('<option value="'+n+'"'+r+">"+l[t].fieldName+"</option>")):(r=r?" checked":"",i.push('<label class="frm6">'),i.push('<input type="checkbox" name="'+a+'" value="'+n+'"'+r+"> "+l[t].fieldName),i.push("</label>"));e.innerHTML=i.join("")}function nt(){for(var e=document.querySelectorAll(".frmjs_prod_field_opt"),t=0;t<e.length;t++)rt(e[t])}function it(e){var t=document.getElementById(e);return null!==t?t.value:""}function ot(){var e,t,r=this.value,n=document.getElementById(this.getAttribute("data-changeme")),i=this.getAttribute("data-changeatt");null!==n&&(null!==i?"SELECT"===n.tagName&&"placeholder"===i?""===(e=n.options[0]).value?e.innerHTML=r:dn(n,r):"class"===i?function(e,t){var r,n,i,o=" "+t.value,a=e.getAttribute("data-fid");void 0!==a&&(t.classList.contains("field_options_align")?o+=" "+document.getElementById("frm_classes_"+a).value:t.classList.contains("frm_classes")&&null!==(i=document.getElementById("field_options_align_"+a))&&(o+=" "+i.value)),o=(o+=" ").replace(" block "," ").replace(" inline "," horizontal_radio "),""===(r=0===(r=e.className.split(" frmstart ")[1]).indexOf("frmend ")?"":r.split(" frmend ")[0]).trim()?(n=" frmstart frmend ",-1===e.className.indexOf(n)&&(n=" frmstart frmend "),o=" frmstart "+o.trim()+" frmend "):(n=r.trim(),o=o.trim()),e.className=e.className.replace(n,o)}(n,this):"range"===(t=n).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 i;if("value"===t?(""===r&&(r=at(e)),e.value=r):e.setAttribute(t,r),-1!==["value","min","max"].indexOf(t))"max"!==t&&"min"!==t||""!==(i=e.id,document.querySelector('input[data-changeme="'+i+'"][data-changeatt="value"]').value)||(e.value=at(e)),e.parentNode.querySelector(".frm_range_value").textContent=e.value}}(n,i,r):n.setAttribute(i,r):0===n.id.indexOf("setup-message")?""!==r&&(n.innerHTML='<input type="text" value="" disabled />'):(n.innerHTML=mn(r),"TEXTAREA"===n.nodeName&&n.classList.contains("wp-editor-area")&&jQuery(n).trigger("change"),n.classList.contains("frm_primary_label")&&"break"===n.nextElementSibling.getAttribute("data-ftype")&&(n.nextElementSibling.querySelector(".frm_button_submit").textContent=r)))}function at(e){var t=parseFloat(e.getAttribute("max")),r=parseFloat(e.getAttribute("min"));return(t-r)/2+r}function lt(){var e,t=this.getAttribute("data-fid"),r="";["field_options_max_","frm_format_"].forEach((function(e){var n=document.getElementById(e+t);n&&(r+=n.value)})),"text"===(e=document.getElementsByName("field_options[type_"+t+"]")[0]).options[e.selectedIndex].value&&dt(""!==r,".frm_invalid_msg"+t)}function st(){var e=this.id.replace("frm_","").replace("req_field_",""),t=this.checked,r=jQuery("#field_label_"+e+" .frm_required");if(dt(t,".frm_required_details"+e),t){var n=jQuery('input[name="field_options[required_indicator_'+e+']"]');""===n.val()&&n.val("*"),r.removeClass("frm_hidden")}else r.addClass("frm_hidden")}function dt(e,t){if($msg=jQuery(t),e)$msg.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");else{var r=$msg.fadeOut("fast").closest(".frm_validation_box"),n=r.css("display","block").children(":not("+t+"):visible").length;r.css("display",""),0===n&&$msg.closest(".frm_validation_msg").fadeOut("fast")}}function ct(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(".frm_unique_details"+e);if(this.checked)t.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast"),$unqDetail=jQuery(".frm_unique_details"+e+" input"),""===$unqDetail.val()&&$unqDetail.val(a.default_unique);else{var r=t.fadeOut("fast").closest(".frm_validation_box"),n=r.css("display","block").children(":not(.frm_unique_details"+e+"):visible").length;r.css("display",""),0===n&&t.closest(".frm_validation_msg").fadeOut("fast")}}function ft(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(this).val(),r=jQuery(document.getElementById("frm_field_id_"+e));if(dt(""!==t,".frm_conf_details"+e),""!==t){var n=jQuery(".frm_validation_box .frm_conf_details"+e+" input");""===n.val()&&n.val(a.default_conf),function(e){var t=document.getElementsByName("field_options[type_"+e+"]")[0].value;ut(document.getElementById("field_description_"+e),"field_options[description_"+e+"]",a["enter_"+t]),ut(document.getElementById("conf_field_description_"+e),"field_options[conf_desc_"+e+"]",a["confirm_"+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-"+e).removeClass("frm_hidden")}else jQuery(".frm-conf-box-"+e).addClass("frm_hidden"),setTimeout((function(){r.removeClass("frm_conf_inline frm_conf_below")}),200)}function ut(e,t,r){e.innerHTML===a.desc&&(e.innerHTML=r,document.getElementsByName(t)[0].value=r)}function mt(e){var t=JSON.parse(this.getAttribute("data-opts"));return e.preventDefault(),document.getElementById("frm_bulk_options").value=t.join("\n"),!1}function _t(){var e,t=jQuery(this).closest(".frm-single-settings").data("fid"),r=jQuery("#frm_field_"+t+"_opts .frm_option_template").prop("outerHTML"),n=jQuery(this).data("opttype"),i=0,o=function(e){for(var t=0,r=0,n=jQuery("#frm_field_"+e+"_opts li"),i=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(i)&&(r>i||"000"===i)&&(i=r)}return i}(t);if("000"!==o&&(i=o+1),"other"===n){document.getElementById("other_input_"+t).value=1;var a=jQuery(this).data("ftype");"radio"!==a&&"select"!==a||jQuery(this).fadeOut("slow");var l={action:"frm_add_field_option",field_id:t,opt_key:i,opt_type:n,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,l,(function(e){jQuery(document.getElementById("frm_field_"+t+"_opts")).append(e),rn(t)}))}else r=(r=(r=(r=(r=r.replace(new RegExp('optkey="000"',"g"),'optkey="'+i+'"')).replace(new RegExp("-000_","g"),"-"+i+"_")).replace(new RegExp('-000"',"g"),"-"+i+'"')).replace(new RegExp("\\[000\\]","g"),"["+i+"]")).replace("frm_hidden frm_option_template",""),zo(t,r={newOption:r}),this.closest(".frm_single_option").after(r.newOption),rn(t);null===(e=this.closest(".frm_sortable_field_opts"))||void 0===e||null===(e=e.querySelectorAll(".frm_remove_tag.frm_disabled"))||void 0===e||e.forEach((function(e){return e.classList.remove("frm_disabled")})),Mi()}function pt(){gt(jQuery(this).closest(".frm-single-settings").data("fid"),this.value)}function gt(e,t){var r=jQuery(".frm_multiple_cont_"+e);"select"===t?r.fadeIn("fast"):r.fadeOut("fast")}function yt(){var e=jQuery(this).closest(".frm-single-settings").data("fid");Oo(jQuery(".field_"+e+"_option_key")),jQuery(".field_"+e+"_option").toggleClass("frm_with_key")}function ht(){var e,t,r=jQuery(this).closest(".frm-single-settings"),n=r.data("fid"),i=document.getElementById("frm_field_id_"+n);wt(jQuery(this)),Oo(jQuery(".field_"+n+"_image_id")),Oo(jQuery(".frm_toggle_image_options_"+n)),Oo(jQuery(".frm_image_size_"+n)),Oo(jQuery(".frm_alignment_"+n)),Oo(jQuery(".frm-add-other#frm_add_field_"+n)),(e=gn(n))?(bt(n,"inline"),vt(i),t=tn(n),i.classList.add("frm_image_options"),i.classList.add("frm_image_size_"+t),r.find(".frm-bulk-edit-link").hide()):(i.classList.remove("frm_image_options"),vt(i),bt(n,"block"),r.find(".frm-bulk-edit-link").show()),wp.hooks.doAction("frm_image_options_toggled",r[0],e)}function vt(e){e.classList.remove("frm_image_size_","frm_image_size_small","frm_image_size_medium","frm_image_size_large","frm_image_size_xlarge")}function bt(e,t){jQuery("#field_options_align_"+e).val(t).trigger("change")}function jt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_"+e);Qt(),gn(e)&&(vt(t),t.classList.add("frm_image_options"),t.classList.add("frm_image_size_"+tn(e)))}function wt(e){var t=e.closest(".frm-single-settings").data("fid");jQuery(".field_"+t+"_option").trigger("change")}function Qt(){wt(jQuery(this))}function xt(e){var t=e.target.closest(".frm_image_preview_wrapper");e.preventDefault(),wp.media.model.settings.post.id=0;var r=wp.media.frames.file_frame=wp.media({multiple:!1,library:{type:["image"]}});r.on("select",(function(){var e=r.state().get("selection").first().toJSON(),n=t.querySelector("img");n.setAttribute("src",e.url),n.classList.remove("frm_hidden"),n.removeAttribute("srcset"),t.querySelector(".frm_image_preview_frame").style.display="block",t.querySelector(".frm_image_preview_title").textContent=e.filename,t.querySelector(".frm_choose_image_box").style.display="none";var i=jQuery(t);i.siblings('input[name*="[label]"]').data("frmimgurl",e.url),i.find("input.frm_image_id").val(e.id).trigger("change"),wp.media.model.settings.post.id=0})),r.open()}function Et(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 kt(){var e=jQuery(this).closest("li").find(".frm_form_fields select");this.checked?e.attr("multiple","multiple"):e.removeAttr("multiple")}function Lt(){var e=document.getElementById("dropform-search-input");null!==e&&setTimeout((function(){e.focus()}),100)}function St(e){var t=e.target,r=t.closest(".frm_warning_style");jQuery(r).fadeOut(400,(function(){return r.remove()}));var n=t.dataset.action,i=new FormData;g(n,i)}function At(e){e.preventDefault()}function It(){var e,t=this.parentNode,r=t.parentNode,n=r.querySelectorAll("li:not(.frm_hidden)");2===n.length&&(null===(e=Array.from(n).find((function(e){return e!==t})).querySelector(".frm_remove_tag"))||void 0===e||e.classList.add("frm_disabled"));var i,o=this.getAttribute("data-fid");jQuery(t).fadeOut("fast",(function(){wp.hooks.doAction("frm_before_delete_field_option",this),jQuery(t).remove(),jQuery(r).find(".frm_other_option").length<1&&(null!==(i=document.getElementById("other_input_"+o))&&(i.value=0),jQuery("#other_button_"+o).fadeIn("fast"))})),Mi()}function Bt(){var e,t,r,n;(e=jQuery(this)).is(":checked")&&(t=function(){setTimeout((function(){e.prop("checked",!1)}),0)},r=function(){e.off("mouseup",n)},n=function(){t(),r()},e.on("mouseup",n),e.one("mouseout",r))}function Ct(){this.value===a.new_option&&(this.setAttribute("data-value-on-focus",this.value),this.value="")}function qt(e){return C(B("Are you sure you want to delete these %1$s selected field(s)?","formidable"),e)}function Nt(){var e=a.conf_delete,t=this.parentNode.parentNode.parentNode.parentNode.parentNode,r=t.parentNode,n=jQuery(this).closest("li.form-field"),i=n.data("fid");if("divider"===n.data("ftype")){var o=document.querySelectorAll(".frm-field-group-hover-target .start_divider .frm_field_box"),l=0;o.forEach((function(e){var t=e.querySelectorAll("li.form-field");t&&(l+=t.length)})),l&&(e=qt(++l))}return r.classList.contains("frm-section-collapsed")||r.classList.contains("frm-page-collapsed")||("divider_section_only"===t.className&&(e=a.conf_delete_sec),this.setAttribute("data-frmverify",e),this.setAttribute("data-frmverify-btn","frm-button-red"),this.setAttribute("data-deletefield",i),Te(),F(this)),!1}function Tt(){this.closest("li.form-field").click()}function Ot(){var e,t;null!==(e=document.querySelector(".frm-field-group-hover-target"))&&(e.classList.add("frm-selected-field-group"),(t=document.createElement("div")).classList.add("frm-delete-field-groups","frm_hidden"),document.body.appendChild(t),t.click())}function Dt(){var e=document.querySelector(".frm-field-group-hover-target");if(null!==e){var t="frm_field_group_"+we(),r=document.createTextNode("");We(r);var n=jQuery(r).closest("li").get(0);n.classList.add("frm_hidden");var i=n.querySelector("ul");i.id=t,jQuery(e.closest("li.frm_field_box")).after(n);var o=ae(jQuery(e)),a=[],l=[],s=o.length,d={},c=0;jQuery(n).on("frm_added_duplicated_field_to_row",(function(e,t){if(d[jQuery(t.duplicatedFieldHtml).attr("data-fid")]=t.originalFieldId,!(s>++c)){var r=jQuery(i),o=ae(r);l.forEach((function(e){e.remove()}));for(var f=0;f<s;++f)r.append(r.children('li.form-field[frm-field-order="'+f+'"]'));le(o.first(),a),n.classList.remove("frm_hidden"),Qn(),ae(r).each((function(){Ne(d[this.getAttribute("data-fid")],jQuery(this).prop("outerHTML"))}))}})),o.each((function(e){var r;(r=document.createElement("li")).classList.add("frm_clone_field"),r.setAttribute("frm-target-row-id",t),r.setAttribute("frm-field-order",e),this.appendChild(r),r.click(),l.push(r),a.push(ir(or(this.classList)))}))}}function Mt(){var e,t,r;if(null!==(e=document.querySelector(".frm-field-group-hover-target"))){Je(),t=Ht(e.querySelector("li.form-field")),e.classList.add("frm-has-open-field-group-popup"),jQuery(document).on("click","#frm_builder_page",Ft),(r=d()).style.position="relative",r.appendChild(Pt(t,this)),this.parentNode.appendChild(r);var n=r.querySelector(".frm-row-layout-option");n&&n.focus()}}function Ft(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||cr()}function Ht(e){var t=jQuery(e).closest("ul");return t.length?ae(t).length:br()}function Pt(e,t){var r,n,i,o,a,l;return null===(r=document.getElementById("frm_field_group_popup"))?r=d():r.innerHTML="",r.id="frm_field_group_popup",(n=d()).style.padding="0 24px 12px",n.appendChild(((a=d()).classList.add("frm-row-layout-title"),a.textContent=B("Row Layout","formidable"),a)),i=function(e){var t,r;return t=Jt(),5!==e&&t.appendChild(Gt(e,"even")),e%2==1&&t.appendChild(Gt(e,"middle")),e<6?(t.appendChild(Gt(e,"left")),t.appendChild(Gt(e,"right"))):((r=d()).classList.add("frm_fourth"),t.prepend(r)),t}(e),null!==(o=t.closest("ul.frm_sorting"))&&function(e,t){var r,n,i,o,a;for(r=t.children.length,n=0;n<r;++n)if(o=i=t.children[n],a=e,$t(o)===$t(a))return void i.classList.add("frm-active-row-layout")}(o,i),n.appendChild(i),r.appendChild(n),r.appendChild(document.createElement("hr")),r.appendChild(((l=d()).textContent=B("Custom layout","formidable"),jQuery(l).prepend(Rt("frm_gear_svg")),l.classList.add("frm-custom-field-group-layout"),zt(l),l)),r.appendChild(function(){var e=d();return e.textContent=B("Break into rows","formidable"),jQuery(e).prepend(Rt("frm_break_field_group_svg")),e.classList.add("frm-break-field-group"),zt(e),e}()),r}function zt(e,t){e.setAttribute("tabindex",0),e.setAttribute("role","button"),void 0!==t&&e.setAttribute("aria-label",t)}function Rt(e){var t=document.getElementById(e).cloneNode(!0);return t.id="",t}function Gt(e,t){var r,n;switch((r=d()).classList.add("frm-row-layout-option"),zt(r,t),e){case 6:n="frm_half";break;case 5:n="frm_third";break;default:n=e%2==1?"frm_fourth":"frm_third"}return r.classList.add(n),r.setAttribute("layout-type",t),r.appendChild(function(e,t){var r,n,i;for(r=Jt(),n=0;n<e;++n)(i=d()).classList.add(Wt(e,t,n)),i.style.height="16px",i.style.background="#9EA9B8",i.style.borderRadius="1px",r.appendChild(i);return r}(e,t)),r}function $t(e){var t,r;return t=e.classList.contains("frm-row-layout-option")?jQuery(e).find(".frm_grid_container").children():ae(jQuery(e)),r=[],t.each((function(){r.push(ir(or(this.classList)))})),r.join("-")}function Wt(e,t,r){if("even"===t)return Ut(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?Kt(e):Vt(e);if("right"===t)return r===e-1?Kt(e):Vt(e)}return"frm12"}function Ut(e,t){return-1!==[2,3,4,6].indexOf(e)?ar(12/e):5===e&&void 0!==t?0===t?"frm4":"frm2":"frm12"}function Vt(e){switch(e){case 2:case 3:return"frm3";case 4:case 5:return"frm2";case 6:return"frm1"}return"frm12"}function Kt(e){switch(e){case 2:return"frm9";case 3:case 4:return"frm6";case 5:return"frm4";case 6:return"frm7"}return"frm12"}function Jt(){var e=d();return e.classList.add("frm_grid_container"),e}function Yt(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t=this.getAttribute("layout-type");le(ae(jQuery(e)).first(),t),cr()}}function Xt(){var e,t;e=Zt(),t=this.getAttribute("layout-type"),le(ae(e).first(),t),gr()}function Zt(){var e=jQuery(".frm-selected-field-group"),t=e.first();return e.not(t).each((function(){ae(jQuery(this)).each((function(){var e=this.parentNode;ae(t).last().after(this),jQuery(e).children("li.form-field").length||e.closest("li.frm_field_box").remove()}))})),Qn(),le(ae(t).first()),t}function er(){null===this.closest(".frm-merge-fields-into-row")&&tr(ae(jQuery(".frm-field-group-hover-target")))}function tr(e){var t,r,n,i,o,a,l,s,c,f,u,m,_,p,g;for(t=e.length,(r=document.getElementById("frm_field_group_popup")).innerHTML="",(n=d()).style.padding="0 24px",i=Ut(5===t?6:t),(o=d()).style.padding="20px 0",o.classList.add("frm_grid_container"),5===t&&((a=document.createElement("span")).classList.add("frm1"),o.appendChild(a)),!1!==(l=br()>0&&ir(Ut(t)))&&l>=12&&(l=Math.floor(12/t)),s=0;s<t;++s)(c=document.createElement("input")).type="text",c.classList.add(i),c.classList.add("frm-custom-grid-size-input"),c.value=!1!==l?l:ir(or(e.get(s).classList)),o.appendChild(c);(f=d()).classList.add("frm-builder-popup-heading"),f.textContent=B("Enter number of columns for each field","formidable"),(u=d()).classList.add("frm-builder-popup-subheading"),u.textContent=B("Layouts are based on a 12-column grid system","formidable"),n.appendChild(f),n.appendChild(u),n.appendChild(o),(m=d()).style.textAlign="right",(g=nr()).classList.add("button-secondary","frm-button-secondary"),(_=g).textContent=B("Cancel","formidable"),_.classList.add("frm-cancel-custom-field-group-layout"),_.style.marginRight="10px",p=function(){var e=nr();return e.classList.add("button-primary","frm-button-primary"),e}(),p.textContent=B("Save","formidable"),p.classList.add("frm-save-custom-field-group-layout"),m.appendChild(_),m.appendChild(p),n.appendChild(m),r.appendChild(n),setTimeout((function(){var e=r.querySelector("input.frm-custom-grid-size-input").focus();e&&e.focus()}),0)}function rr(){$fields=jQuery(".frm-selected-field-group li.form-field"),tr($fields)}function nr(){var e=document.createElement("a");return e.setAttribute("href","#"),e.classList.add("button"),e.style.textDecoration="none",e}function ir(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}return 0===e.indexOf("frm")?parseInt(e.substr(3)):12}function or(e){var t,r,n;for(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)if(n=t[r],e.contains(n))return n;return""}function ar(e){return"frm"+e}function lr(){var e,t;e=document.querySelector(".frm-field-group-hover-target"),ae(t=jQuery(e)).each((function(e){0!==e&&t.parent().after($e(this)),function(e){le(e,"clear")}(jQuery(this))})),cr()}function sr(){this.select()}function dr(){jQuery(document.getElementById("frm_field_group_popup")).replaceWith(Pt(Ht(this),this))}function cr(){var e,t;null!==(e=document.getElementById("frm_field_group_popup"))&&(null!==(t=document.querySelector(".frm-has-open-field-group-popup"))&&(t.classList.remove("frm-has-open-field-group-popup"),e.parentNode.remove()),jQuery(document).off("click","#frm_builder_page",Ft))}function fr(){var e,t;e=[],jQuery(document.getElementById("frm_field_group_popup").querySelectorAll(".frm_grid_container input")).each((function(){e.push(parseInt(this.value))})),(t=jQuery(document.getElementById("frm_field_group_controls"))).length&&"none"!==t.get(0).style.display?le(ae(jQuery(document.querySelector(".frm-field-group-hover-target"))).first(),e):(le(ae(Zt()).first(),e),gr()),cr()}function ur(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)mr(e);else if(e)!function(e){e&&(e.classList.remove("frm_hidden"),e.classList.add("frm-fadein-up-back"))}(e);else{e=d({id:"frm-field-group-message",className:"frm-flex-center frm-fadein-up-back",children:[c({id:"frm-field-group-message-dismiss",className:"frm-flex-center",child:u({href:"#frm_close_icon"})})]}),document.getElementById("post-body-content").appendChild(e);var t,r=((t=document.createElement("span")).classList.add("frm-field-group-message-text","frm-flex-center"),t.innerHTML=C(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(){mr(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,i=t.classList.contains("frm-selected-field-group"),o=function(){var e=jQuery(".frm-selected-field-group");if(e.length)return e;var t=_r();if(t){var r=t.closest("ul");if(r&&1===ae(jQuery(r)).length)return r.classList.add("frm-selected-field-group"),jQuery(r)}return jQuery()}(),a=o.length;if(r||n){var l=_r();if(null===l||jQuery(l).siblings("li.form-field").length||(l.parentNode.classList.add("frm-selected-field-group"),++a),r){if(i)return--a,t.classList.remove("frm-selected-field-group"),void pr(a);++a}else if(n&&!i){++a;var s=o.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 gr(),a=1;t.classList.add("frm-selected-field-group"),pr(a),document.querySelectorAll(".frm-selected-field-group").length<2||mr(document.getElementById("frm-field-group-message")),jQuery(document).off("click",gr),jQuery(document).on("click",gr)}}}function mr(e){e&&(e.classList.add("frm_hidden"),e.classList.remove("frm-fadein-up-back"))}function _r(){return document.getElementById("frm-show-fields").querySelector("li.form-field.selected")}function pr(e){Ke(!0),e>=2||1===e&&ae(jQuery(document.querySelector(".frm-selected-field-group"))).length>1?function(){var e,t,r,n,i;if(null!==(e=document.getElementById("frm_field_multiselect_popup")))return e.classList.toggle("frm-unmergable",!hr()),e;(e=d()).id="frm_field_multiselect_popup",hr()||e.classList.add("frm-unmergable"),(t=d()).classList.add("frm-merge-fields-into-row"),t.textContent=B("Merge into row","formidable"),(r=document.createElement("a")).style.marginLeft="5px",r.classList.add("frm_icon_font","frm_arrowdown6_icon"),r.setAttribute("href","#"),t.appendChild(r),e.appendChild(t),(n=d()).classList.add("frm-multiselect-popup-separator"),e.appendChild(n),(i=d()).classList.add("frm-delete-field-groups"),i.appendChild(Rt("frm_trash_svg")),e.appendChild(i),document.getElementById("post-body-content").appendChild(e),jQuery(e).hide().fadeIn()}():yr(),Me()}function gr(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",gr),yr()}function yr(){var e=document.getElementById("frm_field_multiselect_popup");null!==e&&e.remove()}function hr(){var e,t,r,n,i;if(1===(r=(e=document.querySelectorAll(".frm-selected-field-group")).length))return!1;for(t=0,n=0;n<r;++n){if(null!==(i=e[n]).querySelector(".edit_field_type_break, .edit_field_type_hidden"))return!1;if((t+=ae(jQuery(i)).length)>6)return!1}return!0}function vr(e){var t;null===e.originalEvent.target.closest("#frm_field_group_popup")&&(e.originalEvent.target.classList.contains("frm-custom-field-group-layout")||(t=Pt(br(),document.querySelector(".frm-selected-field-group").firstChild),this.appendChild(t)))}function br(){var e=0;return jQuery(document.querySelectorAll(".frm-selected-field-group")).each((function(){e+=ae(jQuery(this)).length})),e}function jr(){var e,t,r,n;n=[],jQuery(".frm-selected-field-group > li.form-field").each((function(){n.push(this.dataset.fid)})),t=function(e){return function(t){t.preventDefault(),function(e){e.forEach((function(e){Qr(e)}))}(e)}}(e=n),null!==(r=document.getElementById("frm_field_multiselect_popup"))&&r.remove(),this.setAttribute("data-frmverify",qt(e.length)),F(this);var i=document.getElementById("frm-confirmed-click");null==i||i.removeAttribute("data-deletefield"),jQuery(i).on("click",t),jQuery("#frm_confirm_modal").one("dialogclose",(function(){jQuery(i).off("click",t)}))}function wr(){Qr(this.getAttribute("data-deletefield"))}function Qr(e){var t=jQuery("#frm_field_id_"+e);xr(e),t.hasClass("edit_field_type_divider")&&t.find("li.frm_field_box[data-fid]").each((function(){xr(this.getAttribute("data-fid"))})),xn()}function xr(e){jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_delete_field",field_id:e,nonce:frmGlobal.nonce},success:function(){var t,r=jQuery(document.getElementById("frm_field_id_"+e)),n=jQuery("#frm-single-settings-"+e);n.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").appendChild(e)}))}(n),n.remove(),r.fadeOut("slow",(function(){var e,t=r.closest(".start_divider"),n=r.data("type"),i=r.siblings("li.form-field");if(i.length||(r.is(".edit_field_type_end_divider")?i.length=r.closest("li.form-field").siblings():e=r.closest("ul.frm_sorting").parent()),r.remove(),"break"===n?Tr():"product"===n&&(Be(),nt()),i.length?le(i.first()):e.remove(),0===jQuery("#frm-show-fields li").length||function(){if(j.get(0).childElementCount>1)return!1;var e=j.get(0).firstElementChild.firstElementChild.querySelectorAll("li.frm_field_box");return!(e.length>1)&&e[0].classList.contains("edit_field_type_submit")}()){var o=document.getElementById("frm_form_editor_container");o.classList.remove("frm-has-fields"),o.classList.add("frm-empty-fields")}else t.length&&En(t);R()})),r.length&&wp.hooks.doAction("frm_after_delete_field",r[0])}})}function Er(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=k,r=document.getElementById("frm_logic_row_"+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_"+e+"_"),fields:tt()},success:function(t){jQuery(document.getElementById("logic_"+e)).fadeOut("fast",(function(){var r=document.getElementById("frm_logic_row_"+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 i=r.closest(".frm_logic_rows");i.style.height="auto",jQuery(i).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 Lr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=k,r=document.getElementById("frm_watch_lookup_block_"+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_"+e+"_"),nonce:frmGlobal.nonce},success:function(t){var r,n=jQuery(document.getElementById("frm_watch_lookup_block_"+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 Sr(e){var t,r,n=jQuery(e).closest(".frm-single-settings").attr("data-fid"),i=jQuery(e).closest("ul").get(0).querySelectorAll(".field_"+n+"_option");for(t in i)if((r=i[t]).id!==e.id&&r.value===e.value&&"true"!==r.getAttribute("data-duplicate"))return!0;return!1}function Ar(){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["+t+"]["+this.value+"]"),this.parentNode.appendChild(e),void 0===S[t]&&(S[t]={}),S[t][this.value]=e),"true"===this.getAttribute("data-duplicate")&&(this.removeAttribute("data-duplicate"),Sr(this))?this.setAttribute("data-value-on-focus",this.getAttribute("data-value-on-load")):""===this.value&&a.new_option===this.getAttribute("data-value-on-focus")||this.setAttribute("data-value-on-focus",this.value)}function Ir(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 Br(){var e,t,r,n,i,o,a,l,s,d,c,f,u=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,i=e.closest(".frm_single_option");return n&&e.parentElement.classList.contains("frm_single_option")?{oldValue:i.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:i.querySelector('input[type="text"]').getAttribute("data-value-on-focus")}}(e),r=t.oldValue,n=t.oldLabel,i=Ir(e);return{oldValue:r,oldLabel:n,newValue:i.newValue,newLabel:i.newLabel}}(this),m=u.oldValue,_=u.oldLabel,p=u.newValue,g=u.newLabel;if(m!==p||_!==g){var y=this.closest(".frm-single-settings");if(t=y.getAttribute("data-fid"),e=this.getAttribute("data-value-on-load"),Sr(this))return this.setAttribute("data-duplicate","true"),void(void 0!==S[t]&&void 0!==S[t][e]&&(S[t][e].value=e));for(void 0!==S[t]&&void 0!==S[t][e]&&(S[t][e].value=p),s=[],rows=D.querySelectorAll(".frm_logic_row"),o=rows.length,a=0;a<o;a++)if((i=rows[a]).querySelector(".frm_logic_field_opts").value===t){var h;n=i.id.split("_")[2],l=i.querySelector('select[name="field_options[hide_opt_'+n+'][]"]'),(c=""===m?[]:l.querySelectorAll('option[value="'+m+'"]')).length||(c=l.querySelectorAll('option[value="'+p+'"]')).length||(null!==(h=y.querySelector(".frm_toggle_sep_values"))&&void 0!==h&&h.checked||(f=Cr(l,m)),f||(f=document.createElement("option"),l.appendChild(f))),c.length&&(f=c[c.length-1]),f.setAttribute("value",p),f.textContent=g,-1===s.indexOf(n)&&s.push(n)}for(r in s)d=s[r],ii(document.getElementById("frm-single-settings-"+d))}}function Cr(e,t){for(var r=e.options,n=0;n<r.length;n++){var i=r[n];if(t===i.textContent)return i}return null}function qr(){var e=this.id.replace("get_values_form_",""),t=document.getElementById("get_values_field_"+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 Nr(){var e,t,r=this.name.replace("field_options[data_type_","").replace("]","");(e=document.getElementById("frm_add_watch_lookup_link_"+r))&&(e=e.parentNode,"text"===this.value?null!==(t=document.getElementById("frm_watch_lookup_block_"+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"),gt(r,this.value))}function Tr(){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 Or(){var e,t,r,n=jQuery(this).closest(".frm_field_box[data-ftype=break]");n.length?function(e){var t=Dr(e.get(0).parentNode.closest("li.frm_field_box").nextElementSibling);Mr(e,t)}(n):(e=document.getElementById("frm-fake-page"),t=document.getElementById("frm-show-fields").firstElementChild,r=Dr(t),"break"!==t.getAttribute("data-ftype")&&Mr(jQuery(e),r))}function Dr(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 Mr(e,t){var r,n=t.length,i=Math.min(n,3);if(e.hasClass("frm-page-collapsed"))for(e.removeClass("frm-page-collapsed"),t.removeClass("frm-is-collapsed"),r=0;r<i;r++)r===i-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<i;r++)r===i-1?jQuery(t[r]).slideUp(150,(function(){t.css("cssText","display:none !important;")})):jQuery(t[r]).slideUp(150)}function Fr(){this.parentNode.parentNode.parentNode.parentNode.classList.toggle("frm-section-collapsed")}function Hr(){this.classList.toggle("frm-collapsed");var e="true"===this.getAttribute("aria-expanded")||!1;this.setAttribute("aria-expanded",!e),Pr(this.nextElementSibling)}function Pr(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 zr(){if(this.id){var e=document.querySelectorAll('[data-changeme="'+this.id+'"]')[0],t=this.id.replace("field_label_",""),r=document.getElementById("field_options_type_"+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 Rr(){var e=document.querySelectorAll('[data-changeme="'+this.id+'"]')[0];void 0!==e&&setTimeout((function(){e.focus(),Gr(e)}),50)}function Gr(e){var t=e.closest(".frm-collapse-me");null!==t&&t.previousElementSibling.classList.remove("frm-collapsed")}function $r(e){var t,r;(t=e.target.classList).contains("frm-collapse-page")||t.contains("frm-sub-label")||null!==e.target.closest(".dropdown")||(null!==this.closest(".start_divider")&&e.stopPropagation(),this.classList.contains("edit_field_type_divider")&&null!==(r=e.originalEvent.target.closest("ul.frm_sorting"))&&(r.classList.contains("edit_field_type_divider")||r.parentNode.parentNode.classList.contains("start_divider"))||function(e){var t=jQuery(e);-1===e.className.indexOf("selected")&&(-1!==e.className.indexOf("edit_field_type_end_divider")&&t.closest(".edit_field_type_divider").hasClass("no_repeat_section")||(Je(),t.addClass("selected"),function(e){var t,r,n,i=e.getAttribute("data-fid"),o=e.getAttribute("data-type"),a=document.querySelectorAll(".frm-single-settings:not(.frm_hidden)");for(r=0;r<a.length;r++)a[r].classList.add("frm_hidden");ii(n=document.getElementById("frm-single-settings-"+i)),o&&"quantity"===o&&rt(jQuery(n).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"}),n.classList.remove("frm_hidden"),document.getElementById("frm-options-panel-tab").click();var l=n.querySelector(".wp-editor-area");l&&frmDom.wysiwyg.init(l,{setupCallback:ni}),wp.hooks.doAction("frmShowedFieldSettings",e,n),function(e,t,r){var n;if(function(e){return wp.hooks.applyFilters("frm_fields_with_shortcode_popup",["html"]).includes(e)}(e)){var i="#frm-single-settings-"+t;if(!document.querySelector(i+" .frm-show-box")){null===(n=r.querySelector(".wp-editor-container"))||void 0===n||n.classList.add("frm_has_shortcodes");var o=function(){return frmDom.svg({href:"#frm_more_horiz_solid_icon",classList:["frm-show-box"]})};document.querySelectorAll(i+" .frm_has_shortcodes textarea").forEach((function(e){var t=c({className:"frm-with-right-icon"});e.parentNode.insertBefore(t,e),t.appendChild(o()),t.appendChild(e)}))}}}(o,i,n)}(e)))}(this))}function Wr(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 Ur(){var e=this.getAttribute("data-fid");Gr(document.getElementById("field_options_field_key_"+e))}function Vr(){var e=jQuery(this).closest(".frm_field_box");e.find(".repeat_icon_links").removeClass("repeat_format repeat_formatboth repeat_formattext").addClass("repeat_format"+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 Kr(){var e=this.value;""!==e&&(e<2||e>200)&&(H(a.repeat_limit_min),this.value="")}function Jr(){var e=this.value;""!==e&&(e<1||e>200)&&(H(a.checkbox_limit),this.value="")}function Yr(e,t){jQuery(e).closest(".frm_field_box").find(".frm_"+t+"_form_row .frm_repeat_label").text(e.value)}function Xr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=this.value,r=document.getElementById("frm_show_selected_fields_"+e),n=document.getElementById("frm_show_selected_forms_"+e);jQuery(n).find("select").val(""),"form"===t?(n.style.display="inline",function(e){if(null!==e)for(;e.firstChild;)e.removeChild(e.firstChild)}(r)):(r.style.display="none",n.style.display="none",wn(t,e))}function Zr(){var e,t;(e=en(this))&&(t=jQuery(this).closest(".frm_single_option"),function(e,t,r){var n,i,o,a,l,s,c=r.data("optkey"),f=pn(e),u=jQuery('label[for="field_'+t+"-"+c+'"]'),m="field_options[options_"+e+"]["+c+"]",_=jQuery('input[name="'+m+'[label]"]');if(u.length<1)return rn(e),void((o=r.find('input[name^="default_value_"]')).is(":checked")&&_.length>0&&jQuery('select[name^="item_meta['+e+']"]').val(_.val()));if(a=u.children("input"),n=_.length<1?(_=jQuery('input[name="'+m+'"]')).val():f?jQuery('input[name="'+m+'[value]"]').val():_.val(),!(_.length<1)){if(i=u[0].childNodes,gn(e))l=function(e,t,r){var n,i,o;return(n=e.find("img"))&&(i=n.attr("src")),o=yn(t),fn(t),_n(r.val(),o,i)}(r,e,_),(s=u.find(".frm_image_option_container")).length>0?s.replaceWith(l):(i[i.length-1].nodeValue="",u.append(l));else{var p=!1;i.forEach((function(t,r){if(!1===p)"INPUT"===t.tagName&&(p=r);else if(r===p+1){var n="";!function(e){var t=document.getElementsByName("field_options[image_options_"+e+"]"),r=Array.from(t).find((function(e){return e.checked&&"buttons"===e.value}));return void 0!==r}(e)?t.nodeValue=" "+_.val():(n=d({className:"frm_label_button_container",text:" "+_.val()}),u[0].replaceChild(n,t))}else u[0].removeChild(t)}))}a.val(n),o=r.find('input[name^="default_value_"]'),a.prop("checked",!!o.is(":checked"))}}(e.fieldId,e.fieldKey,t))}function en(e){var t;return!!(t=jQuery(e).closest(".frm_sortable_field_opts")).length&&{fieldId:t.attr("id").replace("frm_field_","").replace("_opts",""),fieldKey:t.data("key")}}function tn(e){var t,r=document.getElementById("field_options_image_size_"+e),n="";return null!==r&&""!==(t=r.value)&&(n=t),n}function rn(e){var t,r,n,i,o,a=jQuery('[name^="item_meta['+e+']"]');if(!(a.length<1)){if(a.is("select"))null!==(i=document.getElementById("frm_placeholder_"+e))&&""===i.value?sn(a[0],{sourceID:e}):sn(a[0],{sourceID:e,placeholder:i.value});else{r=cn(e),jQuery("#field_"+e+"_inner_container > .frm_form_fields").html(""),o=en(jQuery("#frm_delete_field_"+e+"-000_container"));var l=jQuery("#field_"+e+"_inner_container > .frm_form_fields"),s=gn(e),d=s?tn(e):"",c=s?"frm_image_option frm_image_"+d+" ":"",f=Ho(e);for(n="hidden"===a.attr("type")?a.data("field-type"):a.attr("type"),t=0;t<r.length;t++)l.append(ln(n,r[t],e,o.fieldKey,f,c))}on(e)}}function nn(e,t){var r=document.getElementById("frm_field_"+e+"_opts").querySelector('input[value="'+t+'"]');return r?Ir(r):{newValue:t,newLabel:t}}function on(e,t){var r,n,i,o,a,l,s,d,c=D.querySelectorAll(".frm_logic_row"),f=c.length;for(o=(d=wp.hooks.applyFilters("frm_conditional_logic_field_options",function(e){var t,r,n,i,o,a,l=[];if(!(o=document.getElementById("frm_field_"+e+"_opts")))return l;for(a=(i=o.querySelectorAll(".frm_single_option")).length,t=0;t<a;t++)(n=i[t]).classList.contains("frm_hidden")||(r=n.querySelector(".field_"+e+"_option"),l.push(r.value));return l}(e),{type:t,fieldId:e})).length,rowIndex=0;rowIndex<f;rowIndex++)if((r=c[rowIndex]).querySelector(".frm_logic_field_opts").value==e){for(n=r.id.split("_")[2],i=r.querySelector('select[name="field_options[hide_opt_'+n+'][]"]'),a=o-1;a>=0;a--){var u;l=d[a];var m=null===(u=document.getElementById("frm_field_"+e+"_opts").querySelector('.frm_option_key input[type="text"]'))||void 0===u?void 0:u.value;m||(m=l),s=i.querySelector('option[value="'+m+'"]');var _=nn(e,l),p=_.newValue,g=_.newLabel,y=document.querySelectorAll("#frm_field_"+e+"_opts input[data-value-on-focus]"),h=Array.from(y).find((function(e){return e.value===l}));if(h){var v=h.dataset.valueOnFocus;if(v&&i.querySelector('option[value="'+v+'"]'))continue}an(i,s,p,g)}null!==(s=i.querySelector('option[value=""]'))&&i.prepend(s)}}function an(e,t,r,n){null!==t||e.querySelector('option[value="'+r+'"]')||((t=frmDom.tag("option",{text:n})).value=r),e.prepend(t)}function ln(e,t,r,n,i,o){var a,l="",s=-1!==t.key.indexOf("other"),d="field_"+n+"-"+t.key,c="scale"===e?"radio":e;return a='<input type="text" id="field_'+n+"-"+t.key+'-otext" class="frm_other_input frm_pos_none" name="item_meta[other]['+r+"]["+t.key+']" value="" />',this.getSingle=function(){return""!==(l=wp.hooks.applyFilters("frm_admin.build_single_option_template",l,{opt:t,type:e,fieldId:r,classes:o,id:d}))?l:'<div class="frm_'+e+" "+e+" "+o+'" id="frm_'+e+"_"+r+"-"+t.key+'"><label for="'+d+'"><input type="'+c+'" name="item_meta['+r+"]"+("checkbox"===e?"[]":"")+'" value="'+mn(t.saved)+'" id="'+d+'"'+(i?' data-price="'+t.price+'"':"")+(t.checked?' checked="checked"':"")+"> "+mn(t.label)+"</label>"+(s?a:"")+"</div>"},this.getSingle()}function sn(e,t){if(null!==e){var r=t.sourceID,n=t.placeholder,i=Ho(r),o=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),l=void 0!==n,s=0;s<a.length;s++){var d=a[s].label,c=-1!==a[s].key.indexOf("other");if(l&&""!==d?dn(e,n):l&&(d=n),l=!1,!c||o){var f=document.createElement("option");f.value=a[s].saved,f.innerHTML=mn(d),i&&f.setAttribute("data-price",a[s].price),e.appendChild(f)}}}}function dn(e,t){var r=document.createElement("option"),n=e.firstChild;r.value="",r.innerHTML=t,null!==n?(e.insertBefore(r,n),e.selectedIndex=0):e.appendChild(r)}function cn(e){var t,r,n,i,o,a,l,s=[],d=jQuery('input[name^="field_options[options_'+e+']"]'),c=Ho(e),f=yn(e),u=gn(e),m=pn(e);for(t=0;t<d.length;t++)d[t].name.indexOf("[000]")>0||d[t].name.indexOf("[value]")>0||d[t].name.indexOf("[image]")>0||d[t].name.indexOf("[price]")>0||(i=r=d[t].value,o=d[t].name.replace("field_options[options_"+e+"][","").replace("[label]","").replace("]",""),m&&(n=d[t].name.replace("[label]","[value]"),r=jQuery('input[name="'+n+'"]').val()),u&&(i=_n(i,f,un(d[t]),fn(e))),a={saved:r,label:i=frmAdminBuild.hooks.applyFilters("frm_choice_field_label",i,e,d[t],u),checked:(l=d[t].id,field=jQuery("#"+l),0!==field.length&&(checkbox=field.siblings("input[type=checkbox]"),checkbox.length&&checkbox.prop("checked"))),key:o},c&&(n=d[t].name.replace("[label]","[price]"),a.price=jQuery('input[name="'+n+'"]').val()),s.push(a));return s}function fn(e){var t=document.getElementById("frm-single-settings-"+e);return null===t?"radio":t.classList.contains("frm-type-checkbox")?"checkbox":"radio"}function un(e){var t,r=jQuery(e).siblings(".frm_image_preview_wrapper");return r.length&&(t=r.find("img")).length?t.attr("src"):""}function mn(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?mn(t):t}function _n(e,t,r,n){var i,o,l,c=e;return c=mn(c),r?o=m({src:r,alt:c}):(o=d({className:"frm_empty_url"})).innerHTML=a.image_placeholder_icon,i=t?" frm_label_with_image":"",(l=s("span",{className:"frm_text_label_for_image_inner"})).innerHTML=c,s("span",{className:"frm_image_option_container"+i,children:[o,s("span",{className:"frm_text_label_for_image",child:l})]})}function pn(e){return hn("separate_value_"+e)}function gn(e){for(var t=!1,r=document.getElementsByName("field_options[image_options_"+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 yn(e){var t=!hn("hide_image_text_"+e);return frmAdminBuild.hooks.applyFilters("frm_choice_field_showing_label_with_image",t,e)}function hn(e){var t=document.getElementById(e);return null!==t&&t.checked}function vn(e){var t=e.closest(".frm-single-settings"),r=t.getAttribute("data-fid"),n=t.querySelector('[name="field_options[separate_value_'+r+']"]').checked;if(!n||e.name.endsWith("[value]")){var i=document.getElementById("frm_field_"+r+"_opts");Array.from(i.querySelectorAll('input[type="text"]')).filter((function(t){return t.id!==e.id&&n===t.name.endsWith("[value]")&&t.value===e.value})).length&&H(C(B('Duplicate option value "%s" detected',"formidable"),mn(e.value)))}}function bn(){var e,t,r,n,i,o=this.value;if(o){var a=this.parentNode.id.replace("frm_logic_","").split("_"),l=a[0],s=a[1],d=document.getElementById("frm_field_id_"+o).getAttribute("data-ftype"),c=document.getElementById("frm_show_selected_values_"+l+"_"+s),f="field_options[hide_opt_"+l+"][]",u="frm_field_logic_opt_"+l,m=!1,_="select"===d||"checkbox"===d||"radio"===d,p="text"===d||"email"===d||"phone"===d||"url"===d||"number"===d;if(_&&null!==document.getElementById("frm_has_hidden_options_"+o)&&(_=!1),_||p){var g=document.querySelector("#frm_logic_".concat(l,"_").concat(s,' [name="field_options[hide_field_cond_').concat(l,'][]"]')).value;c.innerHTML="";var y=_&&!["LIKE","not LIKE","LIKE%","%LIKE"].includes(g);y?m=document.createElement("select"):(m=document.createElement("input")).type="text",m.name=f,m.id=u+"_"+s,c.appendChild(m),y&&sn(document.getElementById(m.id),{sourceID:o,placeholder:"",other:!0})}else{var h=this.getAttribute("data-type");t=l,r=s,n=h,i=function(){var e=new CustomEvent("frm_logic_options_loaded");e.frmData={valueFieldType:d,fieldID:l,metaKey:s},document.dispatchEvent(e)},(e=o)&&jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_get_field_values¤t_field="+t+"&field_id="+e+"&name="+void 0+"&t="+n+"&form_action="+jQuery('input[name="frm_action"]').val()+"&nonce="+frmGlobal.nonce,success:function(e){document.getElementById("frm_show_selected_values_"+t+"_"+r).innerHTML=e,i()}})}}}function jn(){var e=this.value;e&&wn(e,jQuery(this).closest(".frm-single-settings").data("fid"))}function wn(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_"+t);r.toggleClass("frm6",!e.includes("frm-inline-message")),r.html(e).show()}})}function Qn(){var e=this;return this.initOnceInAllInstances=function(){void 0===Qn.prototype.orderFieldsObject&&(Qn.prototype.orderFieldsObject={},Qn.prototype.fieldSettingsForm=document.getElementById("frm-end-form-marker").closest("form"))},this.getFieldOrderInputById=function(e,t){var r,n=Qn.prototype.orderFieldsObject,i=Qn.prototype.fieldSettingsForm;return void 0===n[e]?(null===(r=i.querySelector('input[name="field_options[field_order_'+e+']"]'))&&(r=t.querySelector('input[name="field_options[field_order_'+e+']"]')),n[e]=r,r):n[e]},this.initOnceInAllInstances(),Tr(),function(){var t,r,n,o,a=new ii,l=jQuery("li.frm_field_box",jQuery("#frm-show-fields"));for(i=0;i<l.length;i++)t=l[i].getAttribute("data-fid"),(n=null!==(r=e.getFieldOrderInputById(t,l[i]))?Object.assign({},r.value)[0]:null)!=(o=i+1)&&null!==n&&(r.value=o,singleField=l[i].querySelector("#frm-single-settings-"+t),a.append(singleField),Mi());a.moveFields()}()}function xn(){document.querySelectorAll(".start_divider").forEach((function(e){En(jQuery(e))}))}function En(e){var t,r,n,i;if(e.length){for(i=!1,r=(t=e.find("ul.frm_sorting")).length,n=0;n<r;++n)if(0!==ae(jQuery(t.get(n))).length){i=!0;break}e.parent().children(".frm_no_section_fields").get(0).classList.toggle("frm_block",!i)}}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 Ln(){var e=jQuery(this).data("slideup"),t=jQuery(document.getElementById(e));return t.slideUp("fast"),t.siblings("a").show(),!1}function Sn(e,t){""===t.getAttribute("value")?An(jQuery(this)):function(e){var t,r=e.val();if(null===r)return e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!0),void An(e);(t=r.indexOf(""))>=0&&(r.splice(t,1),e.val(r),e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!1))}(jQuery(this))}function An(e){e.val(""),e.next(".btn-group").find('.multiselect-container input[value!=""]').prop("checked",!1)}function In(){jQuery(".frm-hide-empty").each((function(){0===jQuery(this).text().trim().length&&jQuery(this).remove()}))}function Bn(e){e.preventDefault(),Cn(this)}function Cn(e,t){var r=document.getElementById(e.getAttribute("data-open")),n=jQuery(e).closest("p,ul"),i=void 0!==t;n.hasClass("frm-open")?(n.removeClass("frm-open"),r.classList.add("frm_hidden")):(i||(t=Gi(e)),null!==t&&(i||t.focus(),n.after(r),r.setAttribute("data-fills",t.id.replace("-proxy-input","")),0===r.id.indexOf("frm-calc-box")&&Ze(r,!0)),n.addClass("frm-open"),r.classList.remove("frm_hidden"),wp.hooks.doAction("frm_show_inline_modal",r,e))}function qn(e){e.preventDefault(),this.parentNode.classList.add("frm_hidden"),jQuery('.frm-open [data-open="'+this.parentNode.id+'"]').closest(".frm-open").removeClass("frm-open")}function Nn(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 Tn(){var e,t,r,n,i,o,a,l=this.getAttribute("data-frmchange").split(",");for(e=0;e<l.length;e++)"updateOption"===l[e]?(r=void 0,n=void 0,i=void 0,o=void 0,a=void 0,n=Dn(t=this),i=n.getAttribute("data-optkey"),o=Mn(n,i),null!==(a=document.getElementById("separate_value_"+o))&&!1===a.checked&&((r=document.getElementById("field_key_"+o+"-"+i)).value=t.value,On(r))):"updateDefault"===l[e]?On(this):"checkUniqueOpt"===l[e]?vn(this):this.value=this.value[l[e]]()}function On(e){var t=Dn(e),r=t.getAttribute("data-optkey"),n=Mn(t,r),i=t.querySelector('input[name="default_value_'+n+'"]');null!==i&&(i.value=e.value)}function Dn(e){var t=e.parentNode;return"LI"!==t.tagName&&(t=t.parentNode),t}function Mn(e,t){return e.id.replace("frm_delete_field_","").replace("-"+t+"_container","")}function Fn(){var e=this;if(!Rn()){Wn(this);var t=jQuery(w),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(),E=0,r.setAttribute("aria-busy","false"),setTimeout((function(){jQuery(".frm_updated_message").fadeOut("slow",(function(){this.parentNode.removeChild(this)}))}),5e3);var n,i=document.getElementById("post-body-content"),o=document.createElement("div");o.setAttribute("class","frm_updated_message"),o.innerHTML=t,i.insertBefore(o,i.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(){Hn(document.getElementById("frm_js_build_form"))}})}}function Hn(e){var t=e.ownerDocument.createElement("input");t.style.display="none",t.type="submit",e.appendChild(t).click(),e.removeChild(t)}function Pn(e){jQuery(e).trigger("change")}function zn(){var e;Rn()||(Wn(this),e=jQuery(w),jQuery(document.getElementById("frm_compact_fields")).val(JSON.stringify(e.serializeArray())),Hn(document.getElementById("frm_js_build_form")))}function Rn(){if((t=document.getElementById("frm_form_name"))&&""!==t.value.trim()||"true"!==O.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=To("#frm-form-templates-modal","440px");return!!r&&(Ri(r,"72px"),r.dialog("open"),!0)}function Gn(){var e=document.getElementById("frm-save-form-name-button"),t=document.getElementById("frm_new_form_name_input");_(e,$n),t.addEventListener("keydown",(function(e){"Enter"===e.key&&$n.call(this,e)}))}var $n=function(e){var t=document.getElementById("frm_new_form_name_input").value.trim(),r=new FormData;r.append("form_id",O.get("id")),r.append("form_name",t),g("rename_form",r).then((function(e){O.delete("new_template"),T.search=O.toString(),history.replaceState({},"",T.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 Wn(e){var t,r;Do(),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 Un(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,i=n.modalTitle,o=n.modalContent;i&&o&&(e.preventDefault(),frmDom.modal.maybeCreateModal("frmBasicModal",{title:i,content:d({className:"inside",child:c(o)})}))}}function Vn(e){return e.dataset.requires?e.dataset.requires:"Pro"}function Kn(e){var t,r,n,i=e.dataset.upgrade,o=e.getAttribute("href").replace("#",""),a=document.querySelector(".frm_"+o)||document.querySelector("."+o);if(a&&!a.querySelector(".frm-upgrade-message")){var l=a.querySelector("h2");l.style.borderBottom="none",l.textContent=C(B("%s are not installed","formidable"),i),a.classList.add("frmcenter");var s=document.getElementById("frm_upgrade_modal");p("frm-oneclick"),p("frm-addon-status");var c=s.querySelector(".frm-upgrade-link");if(c){var f=c.cloneNode(!0),u=f.querySelector(".license-level");u&&(u.textContent=Vn(e)),a.appendChild(f),c.nextElementSibling&&c.nextElementSibling.querySelector(".frm-link-secondary")&&a.appendChild(c.nextElementSibling.cloneNode(!0)),p("frm-oneclick-button")}p("frm-upgrade-message");var _=e.dataset.message;void 0===_&&(_=e.dataset.upgrade),Jn(e,"tab",_),e.dataset.screenshot&&a.appendChild((t=e.dataset.screenshot,n=frmGlobal.url+"/images/screenshots/",d({className:"frm-settings-screenshot-wrapper",children:[(r=["#ED8181","#EDE06A","#80BE30"].map((function(e){var t=d({className:"frm-minmax-icon"});return t.style.backgroundColor=e,t})),r.push(m({src:frmGlobal.url+"/images/tab.svg"})),d({className:"frm-settings-screenshot-toolbar",children:r})),d({child:m({src:n+t})})]})))}function p(e){a.appendChild(s.querySelector("."+e).cloneNode(!0))}}function Jn(e,t,r){var n;if("modal"===t)n=document.getElementById("frm_upgrade_modal");else{if("tab"!==t)return;n=document.getElementById(e.getAttribute("href").substr(1))}var i=n.querySelector(".frm-oneclick"),o=n.querySelector(".frm-upgrade-message"),a=n.querySelector(".frm-upgrade-link"),l=n.querySelector(".frm-oneclick-button"),s=n.querySelector(".frm-addon-status"),d=e.getAttribute("data-oneclick"),c=e.getAttribute("data-message"),f="block",u="block",_="none";null!==i&&void 0!==d&&d&&(null===c&&(u="none"),f="none",_="block",d=JSON.parse(d),l.className=l.className.replace(" frm-install-addon","").replace(" frm-activate-addon",""),l.className=l.className+" "+d.class,l.rel=d.url,"frm-activate-addon"===d.class?(i.textContent=B("This plugin is not activated. Would you like to activate it now?","formidable"),l.textContent=B("Activate","formidable")):(i.textContent=B("That add-on is not installed. Would you like to install it now?","formidable"),l.textContent=B("Install","formidable"))),c||(c=o.getAttribute("data-default")),void 0!==r&&(c=c.replace('<span class="frm_feature_label"></span>',r)),o.innerHTML=c,e.dataset.upsellImage&&o.appendChild(m({src:e.dataset.upsellImage,alt:e.dataset.upgrade})),a.href=function(e,t){var r=e.getAttribute("data-link");return null!=r&&""!==r||(r=t.getAttribute("data-default")),r}(e,a),s.style.display="none",i.style.display=_,l.style.display="block"===_?"inline-block":_,o.style.display=u,a.style.display="block"===f?"inline-block":f}function Yn(e){void 0===e&&(e=""),function(e){var t,r=jQuery(e+" :not(.frm_has_shortcodes) .frm_not_email_message, "+e+" :not(.frm_has_shortcodes) .frm_not_email_to, "+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(e+" .frm_has_shortcodes:not(.frm-with-right-icon) input,"+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 xlink:href="#frm_more_horiz_solid_icon"/></svg>')}function Xn(){var e="success";"options[edit_action]"===this.name&&(e="edit");var t=jQuery(this).val();jQuery("."+e+"_action_box").hide(),"redirect"===t?jQuery("."+e+"_action_redirect_box."+e+"_action_box").fadeIn("slow"):"page"===t?jQuery("."+e+"_action_page_box."+e+"_action_box").fadeIn("slow"):jQuery("."+e+"_action_message_box."+e+"_action_box").fadeIn("slow")}function Zn(e){if(m=e.target,p=jQuery(m),g=p.closest(".frm_form_action_settings"),(y=g.find(".widget-inside")).find("p, div, table").length||((_=g.find(".widget-top")).on("frm-action-loaded",(function(){p.trigger("click"),g.removeClass("open"),y.hide()})),_.trigger("click"),0)){var t=e.target.closest(".frm_form_action_settings"),r=t.querySelectorAll(".wp-editor-area");r.length&&r.forEach((function(e){tinymce.EditorManager.execCommand("mceRemoveEditor",!0,e.id)}));var n=jQuery(t).clone(),i=n.attr("id").replace("frm_form_action_",""),o=ei(i);n.find(".frm_action_id, .frm-btn-group").remove(),n.find('input[name$="['+i+'][ID]"]').val(""),n.find(".widget-inside").hide(),n.find("input[type=text], textarea, input[type=number]").prop("defaultValue",(function(){return this.value})),n.find("input[type=checkbox], input[type=radio]").prop("defaultChecked",(function(){return this.checked}));var a=new RegExp("\\["+i+"\\]","g"),l=new RegExp("_"+i+'"',"g"),s=new RegExp("-"+i+'"',"g"),c=new RegExp('"'+i+'"',"g"),f=n.html().replace(a,"["+o+"]").replace(l,"_"+o+'"');f=f.replace(s,"-"+o+'"').replace(c,'"'+o+'"');var u=d({id:"frm_form_action_"+o,className:n.get(0).className});u.setAttribute("data-actionkey",o),u.innerHTML=f,u.querySelectorAll(".wp-editor-wrap, .wp-editor-wrap *").forEach((function(e){"string"==typeof e.className&&(e.className=e.className.replace(i,o)),e.id=e.id.replace(i,o)})),u.classList.remove("open"),document.getElementById("frm_notification_settings").appendChild(u),r.length&&(r.forEach((function(e){frmDom.wysiwyg.init(e)})),u.querySelectorAll(".wp-editor-area").forEach((function(e){frmDom.wysiwyg.init(e)}))),u.classList.contains("frm_single_on_submit_settings")&&u.querySelector("input.frm-page-search")&&jo(u),lo(),wp.hooks.doAction("frm_after_duplicate_action",u)}var m,_,p,g,y}function ei(e){var t=parseInt(e,10)+11;return null!==document.getElementById("frm_form_action_"+t)&&(t=ei(++t)),t}function ti(){var e,t=jQuery(this).data("actiontype");if(!di(t)){var r=(e=kr(document.querySelectorAll(".frm_form_action_settings"),"frm_form_action_"),void 0!==document.getElementById("frm_form_action_"+e)&&(e+=100),A>=e&&(e=A+1),A=e,e),n=k,i=document.createElement("div");i.classList.add("frm_single_"+t+"_settings");var o=document.getElementById("frm_notification_settings");o.appendChild(i),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_action",type:t,list_id:r,form_id:n,nonce:frmGlobal.nonce},success:function(e){Mi(),i.remove(),document.querySelectorAll(".frm_form_action_settings.open").forEach((function(e){return e.classList.remove("open")}));var n=d();n.innerHTML=e;var a=n.querySelector(".widget-top");Array.from(n.children).forEach((function(e){return o.appendChild(e)})),jQuery(".frm_form_action_settings").fadeIn("slow");var l=document.getElementById("frm_form_action_"+r);l.classList.add("open"),document.getElementById("post-body-content").scroll({top:l.offsetTop+10,left:0,behavior:"smooth"}),si(t),Yn("#frm_form_action_"+r),lo(),jo(l),a&&jQuery(a).trigger("frm-action-loaded"),frmAdminBuild.hooks.doAction("frm_added_form_action",l)}})}}function ri(){var e=document.getElementById("frm_email_addon_menu").classList,t=document.getElementById("actions-search-input");e.contains("frm-all-actions")?(e.remove("frm-all-actions"),e.add("frm-limited-actions")):(e.add("frm-all-actions"),e.remove("frm-limited-actions")),t.value="",Io(t,"input")}function ni(e){e.on("Change",(function(){!function(e){var t,r;(t=document.querySelector(".frm-single-settings:not(.frm_hidden)"))&&null!==(r=t.querySelector(".wp-editor-wrap"))&&r.classList.contains("tmce-active")&&!tinyMCE.activeEditor.isHidden()&&(e.targetElm.value=e.getContent(),jQuery(e.targetElm).trigger("change"))}(e)}))}function ii(e){var t=this;if(null!==e)return this.fragment=document.createDocumentFragment(),this.initOnceInAllInstances=function(){void 0===ii.prototype.endMarker&&(ii.prototype.endMarker=document.getElementById("frm-end-form-marker"))},this.append=function(e){var r=null!==e?e.parentElement.classList:"";null!==e&&(r.contains("frm_field_box")||r.contains("divider_section_only"))&&t.fragment.appendChild(e)},this.moveFields=function(){w.insertBefore(t.fragment,ii.prototype.endMarker)},this.initOnceInAllInstances(),void 0!==e?(this.append(e),void this.moveFields()):{append:this.append,moveFields:this.moveFields}}function oi(){var e=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),t=this.getAttribute("data-emailrow");jQuery("#frm_form_action_"+e+" .frm_"+t+"_row").fadeIn("slow"),jQuery(this).fadeOut("slow")}function ai(){var e=jQuery(this).closest(".frm_form_action_settings"),t=this.getAttribute("data-emailrow"),r=".frm_"+t+"_row",n=".frm_"+t+"_button";jQuery(e).find(n).fadeIn("slow"),jQuery(e).find(r).fadeOut("slow",(function(){jQuery(e).find(r+" input").val("")}))}function li(){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 si(e){var t,r,n=document.querySelectorAll(".frm_"+e+"_action");di(e)?(t=n,r=ci(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 di(e){var t=function(e){return jQuery(".frm_single_"+e+"_settings").length}(e)>=ci(e),r={type:e};return wp.hooks.applyFilters("frm_action_at_limit",t,r)}function ci(e){return parseInt(jQuery(".frm_"+e+"_action").data("limit"),10)}function fi(){var e=a.only_one_action,t=this.dataset.limit;void 0!==t&&((t=parseInt(t))>1?e=e.replace(1,t).trim():e+=" "+a.edit_action_text),H(e)}function ui(){var e=jQuery(this).data("emailkey"),t=jQuery(this).closest(".frm_form_action_settings").find(".frm_action_name").val(),r=document.getElementById("form_id").value,n=document.getElementById("frm_logic_row_"+e),i=kr(n.querySelectorAll(".frm_logic_row"),"frm_logic_"+e+"_"),o=d({id:"frm_logic_"+e+"_"+i,className:"frm_logic_row frm_hidden"});return n.appendChild(o),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_logic_row",email_id:e,form_id:r,meta_name:i,type:t,nonce:frmGlobal.nonce},success:function(t){jQuery(document.getElementById("logic_link_"+e)).fadeOut("slow",(function(){o.insertAdjacentHTML("beforebegin",t),o.remove(),jQuery(n).parent(".frm_logic_rows").fadeIn("slow")}))}}),!1}function mi(){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(""),H(a.field_already_used),!1}))}function _i(){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 pi(){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 gi(){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"),a=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_replace_posttax_options",post_type:a,nonce:frmGlobal.nonce},success:function(n){for(i=0;i<r.length;i++)"DIV"===r[i].tagName&&(e=r[i].getElementsByTagName("select")[0],(t=document.createElement("select")).innerHTML=n,t.className=e.className,t.name=e.name,r[i].replaceChild(t,e))}}),n&&yi(n,a,"frm_get_post_parent_option",(function(e,t){n.querySelector(".frm_post_parent_opt_wrapper").innerHTML=e.replaceAll("REPLACETHISNAME",t),jo(n)})),o&&yi(o,a,"frm_should_use_post_menu_order_option")}function yi(e,t,r,n){var i=(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,i)}else console.error(t)},error:function(e){return console.error(e)}})}function hi(){bi("tax",this)}function vi(){bi("meta",this)}function bi(e,t){var r,n,i=jQuery('input[name="id"]').val(),o=jQuery(t).closest(".frm_form_action_settings"),a=o.data("actionkey"),l=o.find(".frm_post_type").val(),s=0,d=document.querySelectorAll(".frm_post"+e+"_row");d.length&&(n=r=d[d.length-1].id.replace("frm_post"+e+"_",""),s=!isNaN(parseFloat(n))&&isFinite(n)?1+parseInt(r,10):1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_post"+e+"_row",form_id:i,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"+e+"_rows")).append(t),jQuery(".frm_add_post"+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 ji(){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(),i=jQuery(document.getElementById(r+"_show_exclude")).is(":checked")?1:0,o=jQuery('select[name$="[post_category]['+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:o,show_exclude:i,nonce:frmGlobal.nonce},success:function(e){jQuery(document.getElementById("frm_posttax_"+r)).replaceWith(e)}})}}function wi(){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 Qi(){var e=jQuery(this),t=e.val();"checkbox"===e.attr("type")&&!1===this.checked&&(t="");var r=e.data("toggleclass");""===t?jQuery("."+r).hide():(jQuery("."+r).show(),jQuery(".hide_"+r+"_"+t).hide())}function xi(){Rn()||(Wn(this),Hn(document.querySelector(".frm_form_settings")))}function Ei(e){return e.preventDefault(),ki(jQuery(this),this.getAttribute("data-code")),!1}function ki(e,t){var r=!1,i=e;if("object"===n(e)){if(e.hasClass("frm_noallow"))return;void 0===(i=jQuery(e).closest("[data-fills]").attr("data-fills"))&&void 0!==(i=e.closest("div").attr("class"))&&(i=i.split(" ")[1])}if(void 0===i){var o=document.activeElement;"search"===o.type?null===(i=o.id.replace("-search-input","")).match(/\d/gi)&&(i=(o=jQuery(".frm-single-settings:visible ."+i)).attr("id")):i=o.id}i&&(r=jQuery("#wp-"+i+"-wrap.wp-editor-wrap").length>0);var a=jQuery(document.getElementById(i));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="["+t+"]")}if(r&&(wpActiveEditor=i),!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:i,success:function(e){if(r){var t=document.createElement("p");t.innerText=e,send_to_editor(t.innerHTML)}else Li(a,e)}})}else t=function(e,t,r){return"object"===n(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):Li(a,t);return!1}function Li(e,t){if(document.selection)e[0].focus(),document.selection.createRange().text=t;else{obj=e[0];var r=obj.selectionEnd;t=function(e,t,r,n){var i=e.data("sep");if(void 0===i)return t;var o=e.val();if(!o.trim().length)return t;var a=new RegExp(i+"\\s*$"),l=new RegExp("^\\s*"+i);return o.substr(0,r).trim().length&&!1===a.test(o.substr(0,r))&&(t=i+t),o.substr(n,o.length).trim().length&&!1===l.test(o.substr(n,o.length))&&(t+=i),t}(e,t,obj.selectionStart,r),obj.value=obj.value.substr(0,obj.selectionStart)+t+obj.value.substr(obj.selectionEnd,obj.value.length);var n=r+t.length;!function(e,t){if(e.classList.contains("frm_classes")&&Si(t)){var r=e.value.split(" ").filter(Si);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()))}}(obj,t),obj.focus(),obj.setSelectionRange(n,n)}Pn(e)}function Si(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 Ai(){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"),Io(t,"change")):(e.classList.add("frm_hidden"),t.classList.remove("frm_hidden"),Io(e,"change"))}function Ii(){var e,t,r=document.getElementById("frm-id-key-condition-id").checked?"frm-id-condition":"frm-key-condition",n=document.getElementById("frm-is-condition").value,i=document.getElementById("frm-text-condition").value,o=document.getElementById("frm-insert-condition");t="if "+(e=(r=document.getElementById(r)).options[r.selectedIndex].value)+" "+n+'="'+i+'"]',o.setAttribute("data-code",t+a.conditional_text+"[/if "+e),o.innerHTML="["+t+"[/if "+e+"]"}function Bi(){Cn($i(this),this)}function Ci(e){e.preventDefault(),e.stopPropagation(),Oi(this)}function qi(e){!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))||Ni()}}(e.target)}function Ni(e){var t;void 0===e&&(e=B("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:B("Save and Reload?","formidable"),content:(t=d(e),t.style.padding="var(--gap-md)",t),footer:function(){var e=frmDom.modal.footerButton({text:B("Save and Reload","formidable"),buttonType:"primary"});_(e,(function(){Pi()}));var t=frmDom.modal.footerButton({text:B("Cancel","formidable"),buttonType:"cancel"});return t.classList.add("dismiss"),frmDom.div({children:[t,e]})}()})}function Ti(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 i=t.getBoundingClientRect(),o=document.getElementById("frm_adv_info"),a=o.parentElement.getBoundingClientRect();o.style.top=i.top-a.top+32+"px",o.style.left=i.left-a.left-280+"px"}function Oi(e,r){var n=Gi(e),i=document.getElementById("frm_adv_info"),o=e.className;if("svg"===e.tagName&&(e=e.firstElementChild),"use"===e.tagName&&null===(o=e.getAttributeNS("http://www.w3.org/1999/xlink","href"))&&(o=e.getAttribute("href")),-1!==o.indexOf("frm_close_icon"))Wi(i);else{if(Ti(e),jQuery(".frm_code_list a").removeClass("frm_noallow"),n.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"):n.classList.contains("frm_not_email_subject")&&jQuery(".frm_code_list li.hide_frm_not_email_subject a").addClass("frm_noallow"),i.setAttribute("data-fills",n.id),i.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 l=document.createElementNS("http://www.w3.org/2000/svg","use");l.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon"),e.parentNode.replaceChild(l,e)}else e.className=o.replace("frm_more_horiz_solid_icon","frm_close_icon");"nofocus"!==r&&("none"!==n.style.display?n.focus():jQuery(tinymce.get(n.id)).trigger("focus")),function(e){["address","body"].forEach((function(r){!function(e,r){var n,i;n=a.contextualShortcodes[r+"Selector"],i=a.contextualShortcodes[r];var o,l=e.matches(n),s=function(e){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=t(e))){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}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 o,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,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(l)throw o}}}}(i);try{for(s.s();!(o=s.n()).done;){var d,c=o.value,f=null===(d=document.querySelector('#frm-adv-info-tab .frm_code_list [data-code="'+c+'"]'))||void 0===d?void 0:d.closest("li");null==f||f.classList.toggle("frm_hidden",!l)}}catch(e){s.e(e)}finally{s.f()}}(e,r)}))}(n)}}function Di(e){return 0===a.contextualShortcodes.length||!function(e){var t=e.querySelector("a");if(!t)return!1;var r=t.dataset.code;return a.contextualShortcodes.address.includes(r)||a.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),i=a.contextualShortcodes;return i.address.includes(t)?n.matches(i.addressSelector):n.matches(i.bodySelector)}(e)}function Mi(){E||(E=1,window.addEventListener("beforeunload",zi))}function Fi(){E=0}function Hi(){E=0}function Pi(){var e=document.getElementById("frm_submit_side_top");e.classList.contains("frm_submit_ajax")&&e.setAttribute("data-new-addon-installed",!0),e.click()}function zi(e){E&&(e.preventDefault(),e.returnValue="")}function Ri(e,t){var r={my:"top",at:"top+"+t,of:window};e.dialog("option","position",r)}function Gi(e){for(var t,r=e.nextElementSibling;null!==r&&("INPUT"!==r.tagName&&"TEXTAREA"!==r.tagName||r.classList.contains("frm-token-input-field"));)r=Gi(r);return r||(r=null===(t=e.closest(".frm-field-formula"))||void 0===t?void 0:t.querySelector(".frm-calc-field")),r}function $i(e){for(var t=e.previousElementSibling;null!==t&&"I"!==t.tagName&&"svg"!==t.tagName;)t=$i(t);return t}function Wi(e){var t,r,n,i;if((void 0!==e||null!==(e=document.getElementById("frm_adv_info")))&&null===document.getElementById("frm_dyncontent")){for(e.style.display="none",n=document.querySelectorAll(".frm-show-box.frm_close_icon"),t=0;t<n.length;t++)n[t].classList.remove("frm_close_icon"),n[t].classList.add("frm_more_horiz_solid_icon");for(i=document.querySelectorAll(".frm_has_shortcodes use"),r=0;r<i.length;r++)if("#frm_close_icon"===i[r].getAttributeNS("http://www.w3.org/1999/xlink","href")){if(i[r].closest(".frm_remove_field"))continue;i[r].setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_more_horiz_solid_icon")}}}function Ui(e,t){t.stopPropagation(),jQuery(".frm_code_list .frmids, .frm_code_list .frmkeys").addClass("frm_hidden"),jQuery(".frm_code_list ."+e).removeClass("frm_hidden"),jQuery(".frmids, .frmkeys").removeClass("current"),jQuery("."+e).addClass("current")}function Vi(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 Ki(){return!0===F(this)&&(jQuery(".frm_uninstall .frm-wait").css("visibility","visible"),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_uninstall&nonce="+frmGlobal.nonce,success:function(e){jQuery(".frm_uninstall").fadeOut("slow"),window.location=e}})),!1}function Ji(){var e=jQuery(this),t=this.name,r=this.getAttribute("data-plugin"),n=t.replace("edd_"+r+"_license_",""),i=document.getElementById("edd_"+r+"_license_key").value;e.get(0).disabled=!0,jQuery.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_"+n,license:i,plugin:r,nonce:frmGlobal.nonce},success:function(t){e.get(0).disabled=!1;var o=e.closest(".edd_frm_license_row");"deactivate"===n&&(i="",document.getElementById("edd_"+r+"_license_key").value=""),o.find(".edd_frm_license").html(i);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=o.find(".frm_license_msg");s.html(t.message),""!==t.message&&setTimeout((function(){if(s.html(""),o.find(".frm_icon_font").addClass("frm_hidden"),l){var e="activate"===n;o.get(0).querySelector(".edd_frm_unauthorized").classList.toggle("frm_hidden",e),o.get(0).querySelector(".edd_frm_authorized").classList.toggle("frm_hidden",!e)}}),2e3)}})}function Yi(e){e.preventDefault();var t=jQuery(e.target).find("input:checked");if(t.length){var r,n,i,o,a=[];t.each((function(e){a[e]=this.value})),r=a,n=e.target,(o=(i=jQuery(n)).next(".frm-importer-process")).find(".form-total").text(r.length),o.find(".form-current").text("1"),i.hide(),o.find(".process-completed").hide(),o.show(),N.importQueue=r,N.imported=0,Xi(o)}}function Xi(e){var t=N.importQueue[0],r={action:"frm_import_"+jQuery("#welcome-panel").find('input[name="slug"]').val(),form_id:t,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,r,(function(r){var n;r.success&&(n=r.data.error?"<p>"+r.data.name+": "+r.data.msg+"</p>":'<p>Imported <a href="'+r.data.link+'" target="_blank">'+r.data.name+"</a></p>",e.find(".status").prepend(n),e.find(".status").show(),N.importQueue=jQuery.grep(N.importQueue,(function(e){return e!=t})),N.imported++,0===N.importQueue.length?(e.find(".process-count").hide(),e.find(".forms-completed").text(N.imported),e.find(".process-completed").show()):(e.find(".form-current").text(N.imported+1),Xi(e)))}))}function Zi(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 eo(){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 to(){null!==jQuery(this).val().match(/\.csv$/i)?jQuery(".show_csv").fadeIn():jQuery(".show_csv").fadeOut()}function ro(){var e=document.querySelector('select[name="format"]');return e?e.value:""}function no(e){var t,r,n=e.target.value;oo(n),io.call(e.target),t=n,r=document.getElementById("frm-export-select-all"),"csv"===t?(r.checked=!1,r.disabled=!0):r.disabled=!1}function io(){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.indexOf(this.value)>=0?(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 i=t.data("count"),o=jQuery('input[name="frm_export_forms[]"]');"single"===i?(o.prop("multiple",!1),o.prop("checked",!1)):(o.prop("multiple",!0),o.prop("disabled",!1)),e.trigger("change")}function oo(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")})),Lo.call(document.querySelector(".frm-auto-search")))}}function ao(){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 lo(){jQuery(".frm_multiselect").hide().each(frmDom.bootstrap.multiselect.init)}function so(e){e.preventDefault(),uo(this,"frm_multiple_addons")}function co(e){e.preventDefault(),uo(this,"frm_activate_addon")}function fo(e){e.preventDefault(),uo(this,"frm_install_addon")}function uo(e,t){var r,n,i,o;jQuery(".frm-addon-error").remove(),n=(r=jQuery(e)).attr("rel"),i=r.parent(),o=i.parent().find(".addon-status-label"),r.addClass("frm_loading_button"),jQuery.ajax({url:ajaxurl,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:t,nonce:frmGlobal.nonce,plugin:n},success:function(e){var n,a,l;"string"!=typeof(e=null!==(n=null===(a=e)||void 0===a?void 0:a.data)&&void 0!==n?n:e)&&"string"==typeof e.message&&(void 0!==e.saveAndReload&&(l=e.saveAndReload),e=e.message);var s=go(e);s?yo(s,i,r):(_o(e,r,o,i,l,t),wp.hooks.doAction("frm_update_addon_state",e))},error:function(){r.removeClass("frm_loading_button")}})}function mo(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:a.nonce,plugin:n,hostname:r.find("#hostname").val(),username:r.find("#username").val(),password:r.find("#password").val()},success:function(e){var n,i,o=go(e=null!==(n=null===(i=e)||void 0===i?void 0:i.data)&&void 0!==n?n:e);o?yo(o,r,t):_o(e,t,message,r)},error:function(){t.removeClass("frm_loading_button")}})}function _o(e,t,r,n,i){var o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"frm_activate_addon",l=document.querySelectorAll(".frm-addon-status");l.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"})),jQuery("#frm_upgrade_modal h2").hide(),jQuery("#frm_upgrade_modal .frm_lock_icon").addClass("frm_lock_open_icon"),jQuery("#frm_upgrade_modal .frm_lock_icon use").attr("xlink:href","#frm_lock_open_icon");var s={frm_activate_addon:{class:"frm-addon-active",message:a.active},frm_deactivate_addon:{class:"frm-addon-installed",message:a.installed},frm_uninstall_addon:{class:"frm-addon-not-installed",message:a.not_installed}};s.frm_install_addon=s.frm_activate_addon;var c=r[0];c&&(c.textContent=s[o].message);var f=n[0].parentElement;f.classList.remove("frm-addon-not-installed","frm-addon-installed","frm-addon-active"),f.classList.add(s[o].class),t[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(i)&&l.forEach((function(e){var t=null!==e.closest("#frm_upgrade_modal");e.appendChild(function(e,t){var r=[po(e)];return t&&r.push(function(){var e=document.createElement("a");return e.setAttribute("href","#"),e.classList.add("button","button-secondary","frm-button-secondary","dismiss"),e.textContent=B("Close","formidable"),e}()),d({className:"frm-save-and-reload-options",children:r})}(i,t))}))}function po(e){var t=document.createElement("button");return t.classList.add("frm-save-and-reload","button","button-primary","frm-button-primary"),t.textContent=B("Save and Reload","formidable"),t.addEventListener("click",(function(){var t,r;"form_builder"===e?Pi():"settings"===e&&null!==(t=document.getElementById("form_settings_page"))&&null!==(r=t.querySelector("form.frm_form_settings"))&&(E=0,r.submit())})),t}function go(e){return"string"!=typeof e&&(void 0===e.success||!e.success)&&(e.form&&jQuery(e.form).is("#message")?{message:jQuery(e.form).find("p").html()}:e)}function yo(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",mo)):(t.append('<div class="frm-addon-error frm_error_style"><p><strong>'+e.message+"</strong></p></div>"),r.removeClass("frm_loading_button"),jQuery(".frm-addon-error").delay(4e3).fadeOut())}function ho(){bo()}function vo(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 bo(){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 jo(e){frmDom.autocomplete.initSelectionAutocomplete(e)}function wo(e){var t=this.parentNode.parentNode,r=t.elements.type.value;e.preventDefault(),this.classList.add("frm_loading_button"),xo(t,r,this)}function Qo(e){var t=this.elements.type.value,r=this.querySelector("button");e.preventDefault(),r.classList.add("frm_loading_button"),xo(this,t,r)}function xo(e,t,r){var n=function(e){var t,r,n={},i=e.elements;for(r=0;r<i.length;r++){var o=i[r],a=o.name,l=o.value,s=a.match(/(.*)\[(.*)\]/);("radio"!==o.type&&"checkbox"!==o.type||o.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),i=n.template_name,o=n.template_desc,a=e.elements.link.value,l={action:t,xml:a,name:i,desc:o,form:JSON.stringify(n),nonce:frmGlobal.nonce},s={formData:n};Bo(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 i=document.getElementById("frm-redirect-link");void 0!==a&&null!==i&&(i.setAttribute("href",n),i.classList.remove("frm_grey","disabled"),(o=e.parentNode.parentNode).classList.add("frm_grey"),o.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=d(e);t.style.padding="20px 40px",frmDom.modal.maybeCreateModal("frmInstallFormErrorModal",{title:B("Unable to install template","formidable"),content:t}).classList.add("frm_common_modal")}(t.message);var o;r.classList.remove("frm_loading_button")}))}function Eo(e){var t=document.getElementById("frm_captcha_threshold_container");t&&t.classList.toggle("frm_hidden","v3"!==e.target.value)}function ko(e){var t=this.getAttribute("data-id");e.preventDefault(),data={action:"frm_forms_trash",id:t,nonce:frmGlobal.nonce},Bo(data,(function(){var e=document.getElementById("frm-template-custom-"+t);Co(e,(function(){e.parentNode.removeChild(e)}))}))}function Lo(){var e,t,r=!1,n=this.value.toLowerCase(),i=this.getAttribute("data-tosearch"),o=document.getElementsByClassName(i);if("SELECT"===this.tagName&&(n=(n=function(e){for(var t,r=[],n=e&&e.options,i=0,o=n.length;i<o;i++)(t=n[i]).selected&&r.push(t.value);return r}(this)).join("|").toLowerCase(),r=!0),"frm-action"===i&&""!==n){var a=document.getElementById("frm_email_addon_menu").classList;a.remove("frm-all-actions"),a.add("frm-limited-actions")}for(e=0;e<o.length;e++){var l=o[e].innerText.toLowerCase(),s=!("xml"===ro()&&o[e].classList.contains("frm-is-repeater"));""===n?(s&&Di(o[e])&&o[e].classList.remove("frm_hidden"),o[e].classList.remove("frm-search-result")):r&&new RegExp(n).test(l)||l.indexOf(n)>=0||So(l,n)?(s&&Di(o[e])&&o[e].classList.remove("frm_hidden"),o[e].classList.add("frm-search-result")):(o[e].classList.add("frm_hidden"),o[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 So(e,t){return"s"!==t&&"s"!==e[e.length-1]&&(e+"s").indexOf(t)>=0}function Ao(e){e.stopPropagation()}function Io(e,t){var r=document.createEvent("HTMLEvents");r.initEvent(t,!1,!0),e.dispatchEvent(r)}function Bo(e,t){var r,n=new XMLHttpRequest,i="string"==typeof e?e:Object.keys(e).map((function(t){return encodeURIComponent(t)+"="+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(i),n}function Co(e,t){e.classList.add("frm-fade"),setTimeout(t,1e3)}function qo(e){jQuery(e).css("visibility","hidden")}function No(e){jQuery(e).css("visibility","visible")}function To(e,t){var r=jQuery(e);if(!r.length)return!1;void 0===t&&(t="550px");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 Oo(e,t){if("#"===t){var r=document.getElementById(e),n=r.style.display;r.style.display="none"===n?"block":"none"}else e.is(":visible")?e.hide():e.show()}function Do(){window.onbeforeunload=null;var e=jQuery(window);e.off("beforeunload.widgets"),e.off("beforeunload.edit-post")}function Mo(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_"+e);if(null!==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 Fo(){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;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"))}function Ho(e){var t=document.getElementById("frm_field_id_"+e);return null!==t&&"product"===t.getAttribute("data-type")}function Po(){var t=function(e,t){return window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]},r=function(e,t,r){window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]=r},n=[1,2,3,4,5,6,7,8,9,10,11,12].map((function(e){return"frm"+e})),i=["first","middle","last"];document.addEventListener("change",(function(o){o.target.matches(".frm_name_layout_dropdown")&&function(o){var a,l=o.target.value.split("_"),s=o.target.dataset.fieldId,d=document.querySelector("#field_"+s+"_inner_container .frm_combo_inputs_container"),c=(a=l.length,"frm"+parseInt(12/a));i.forEach((function(t){var i,o=d.querySelector('[data-sub-field-name="'+t+'"]');o&&(o.classList.add("frm_hidden"),(i=o.classList).remove.apply(i,e(n)),r(s,t,o))})),l.forEach((function(e){var r=t(s,e);r&&(r.classList.remove("frm_hidden"),r.classList.add(c),d.append(r))})),i.forEach((function(e){var t=document.querySelector(".frm_sub_field_options-"+e+'[data-field-id="'+s+'"]');t&&(t.classList.add("frm_hidden"),r(s,e+"_options",t))})),l.forEach((function(e){var r=t(s,e+"_options");r&&r.classList.remove("frm_hidden")}))}(o)}),!1)}function zo(e,t){var r,n,i,o=!1,a=!1;(r=t.newOption?(new DOMParser).parseFromString(t.newOption,"text/html").body.childNodes[0]:t).querySelectorAll("svg").forEach((function(e,t){(n=e.getElementsByTagNameNS("http://www.w3.org/2000/svg","use")[0])&&("#frm_drag_icon"===(i=n.getAttributeNS("http://www.w3.org/1999/xlink","href")||n.getAttribute("href"))&&(o=!0),"#frm_save_icon"===i&&(a=!0))})),o||r.prepend(b.drag.cloneNode(!0)),r.querySelector("[id^=field_key_".concat(e,"-]"))&&!a&&r.querySelector("[id^=field_key_".concat(e,"-]")).after(b.save.cloneNode(!0)),t.newOption&&(t.newOption=r)}function Ro(){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 i=c({className:"frm-wait frm_spinner"});i.style.visibility="visible",i.style.float="none",i.style.width="unset",n.parentElement.insertBefore(i,n.nextElementSibling)}}r.val(e),jQuery.ajax({type:"POST",url:t.attr("action"),data:t.serialize()+"&action=frm_forms_preview"}).done((function(e){if(-1!==jQuery(e).find(".frm_message").text().trim().indexOf("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(c(B("Thank you for signing up!","formidable")))}else vo("invalid")}))}}else vo("invalid");else vo("empty")}function Go(e){if(D||e.stopPropagation(),!(e.target.classList.contains("frm-show-box")||e.target.parentElement&&e.target.parentElement.classList.contains("frm-show-box"))){var t=document.getElementById("frm_adv_info");t&&(t.dataset.fills===e.target.id&&void 0!==e.target.id||e.target.closest("#frm_adv_info")||"none"===t.style.display||Wi(t))}}return{init:function(){var t,r,n,i,o,a,l;!function(){jQuery(document).on("click","#frm-add-my-email-address",(function(e){e.preventDefault(),Ro()}));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()}}))}}(),r=document.querySelector(".frm-admin-footer-links"),n=null!==(t=document.querySelector(".frm_page_container"))&&void 0!==t?t:document.getElementById("wpbody-content"),r&&n&&(n.appendChild(r),r.classList.remove("frm_hidden")),N={},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",Lt),void 0===k&&(k=jQuery(document.getElementById("form_id")).val()),document.querySelectorAll(".frm-warning-dismiss").forEach((function(e){_(e,St)})),frmAdminBuild.inboxBannerInit(),j.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=d({className:"frm_warning_style",text:B("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"]')),i=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")};i(),n.forEach((function(e){e.addEventListener("change",(function(e){e.target.checked?i():(t.classList.add("frm_hidden"),n.forEach((function(e){e.parentNode.classList.remove("frm_noallow"),e.disabled=!1})))}))}))}}}(),jo(),jQuery("[data-frmprint]").on("click",(function(){return window.print(),!1}))),jQuery(document).on("change","select[data-toggleclass], input[data-toggleclass]",Qi),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"),o=document.getElementById("frm_confirm_modal"),a=!1,l=!1,jQuery(o).on("click","[data-deletefield]",wr),jQuery(o).on("click","[data-removeid]",G),jQuery(o).on("click","[data-trashtemplate]",ko),i.on("click",".frm_remove_tag, .frm_remove_form_action",G),i.on("click","a[data-frmverify]",M),i.on("click","a[data-frmtoggle]",P),i.on("click","a[data-frmhide], a[data-frmshow]",z),i.on("change","input[data-frmhide], input[data-frmshow]",z),i.on("click",".widget-top,a.widget-action",$),i.on("mouseenter.frm",".frm_bstooltip, .frm_help",(function(){jQuery(this).off("mouseenter.frm"),jQuery(".frm_bstooltip, .frm_help").tooltip(),jQuery(this).tooltip("show")})),jQuery(".frm_bstooltip, .frm_help").tooltip(),jQuery(document).on("click","#doaction, #doaction2",(function(e){var t="doaction"===this.id?"top":"bottom",r=document.getElementById("bulk-action-selector-"+t),n=document.getElementById("confirm-bulk-delete-"+t);if(null!==r&&null!==n){if(a=this,!l&&"bulk_delete"===r.value)return e.preventDefault(),F(n),!1}else a=!1})),jQuery(document).on("click","#frm-confirmed-click",(function(e){if(!1!==a&&!e.target.classList.contains("frm-btn-inactive"))return"confirm-bulk-delete"===this.getAttribute("href")?(e.preventDefault(),l=!0,a.click(),!1):void 0})),function(){var e=To("#frm_upgrade_modal");function t(t){var r,n,i;if((r=t.target).classList){var o=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 a=r.options[r.selectedIndex];a&&a.dataset.upgrade&&(r=a)}if(!r.dataset.upgrade){var l=r.closest("[data-upgrade]");if(!l){if(!(l=r.closest(".frm_field_box")))return;r.dataset.upgrade=""}r=l}if(o)wp.hooks.doAction("frm_show_expired_modal",r);else{var s=r.dataset.upgrade;if(s&&!r.classList.contains("frm_show_upgrade_tab")){t.preventDefault();var d=e.get(0),c=d.querySelector(".frm_lock_icon");c&&(c.style.display="block",c.classList.remove("frm_lock_open_icon"),c.querySelector("use").setAttribute("href","#frm_lock_icon"));var f="frm_upgrade_modal_image",u=document.getElementById(f);u&&u.remove(),r.dataset.image&&(c&&(c.style.display="none"),c.parentNode.insertBefore(m({id:f,src:frmGlobal.url+"/images/"+r.dataset.image}),c));var _=d.querySelector(".license-level");_&&(_.textContent=Vn(r)),Jn(r,"modal",s),d.querySelector(".frm_are_not_installed").style.display=r.dataset.image?"none":"inline-block",d.querySelector(".frm_feature_label").textContent=s,d.querySelector("h2").style.display="block",e.dialog("open");var p=d.querySelector(".button-primary:not(.frm-oneclick-button)");n=p.getAttribute("href").replace(/(medium=)[a-z_-]+/gi,"$1"+r.getAttribute("data-medium")),null===(i=r.getAttribute("data-content"))&&(i=""),n=n.replace(/(content=)[a-z_-]+/gi,"$1"+i),p.setAttribute("href",n)}}}}!1!==e&&(document.addEventListener("click",t),frmDom.util.documentOn("change","select.frm_select_with_upgrade",t))}(),frmDom.util.documentOn("click","[data-modal-title]",Un);var s=jQuery(document.getElementById("frm_shortcodediv"));s.length>0&&(jQuery("a.edit-frm_shortcode").on("click",(function(){return s.is(":hidden")&&(s.slideDown("fast"),this.style.display="none"),!1})),jQuery(".cancel-frm_shortcode","#frm_shortcodediv").on("click",(function(){return s.slideUp("fast"),s.siblings("a.edit-frm_shortcode").show(),!1}))),jQuery(document).on("click","#frm-nav-tabs a",W),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&&Kn(this),U(this),!1})),U(jQuery(".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),Hn(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)",Lo),jQuery(document).on("focusin click",".frm-auto-search",Ao);var c=jQuery(".frm-auto-search");""!==c.val()&&c.trigger("keyup"),FrmFormsConnect.init(),jQuery(document).on("click",".frm-install-addon",fo),jQuery(document).on("click",".frm-activate-addon",co),jQuery(document).on("click",".frm-solution-multiple",so),jQuery("button, input[type=submit]").on("click",Do),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,i=t.element;if("form"!==t.type)return e;var o=i.closest("tr");if(o)r=parseInt(o.querySelector(".column-id").textContent),n=o.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]})),document.querySelectorAll("#frm-show-fields > li, .frm_grid_container li").forEach((function(t,r){t.addEventListener("click",(function(){var t,r,n;r=(null===(t=this.querySelector("li"))||void 0===t?void 0:t.dataset.fid)||this.dataset.fid,(n=document.querySelectorAll("[id^=frm_delete_field_".concat(r,"-]"))).length<2||e(n).slice(1).forEach((function(e,t){e.classList.contains("frm_other_option")||zo(r,e)}))}))}));var f=document.getElementById("frm_small_screen_proceed_button");f&&_(f,(function(){var e;null===(e=document.getElementById("frm_small_device_message_container"))||void 0===e||e.remove(),g("small_screen_proceed",new FormData)}));var u=document.getElementById("frm_sale_banner"),p=null==u?void 0:u.querySelector(".dismiss");u&&(_(u,(function(e){e.target.closest(".dismiss")||(window.location.href=u.getAttribute("data-url"))})),p&&_(p,(function(){u.remove();var e=new FormData;g("sale_banner_dismiss",e)})))},buildInit:function(){var e,t,r;jQuery("#frm_builder_page").on("mouseup","*:not(.frm-show-box)",Go),y=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return frmDom.util.debounce(e,t)}(oe,10),h=document.getElementById("post-body-content"),v=jQuery(h),jQuery(".frm_field_loading").length&&Le(jQuery(".frm_field_loading").first().attr("id")),V("ul.frm_sorting"),document.querySelectorAll(".field_type_list > li:not(.frm_show_upgrade)").forEach(X),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",Fn),jQuery(".frm_submit_no_ajax").on("click",zn),Gn(),jQuery("a.edit-form-status").on("click",kn),jQuery(".cancel-form-status").on("click",Ln),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")})),lo(),Tr(),e=jQuery(w),t=document.getElementById("frm_form_editor_container"),e.on("click",".frm_add_logic_row",Er),e.on("click",".frm_add_watch_lookup_row",Lr),e.on("change",".frm_get_values_form",qr),e.on("change",".frm_logic_field_opts",bn),e.on("frm-multiselect-changed",'select[name^="field_options[admin_only_"]',Sn),jQuery(document.getElementById("frm-insert-fields")).on("click",".frm_add_field",Ae),j.on("click",".frm_clone_field",Ce),e.on("blur",'input[id^="frm_calc"]',Ye),e.on("change","input.frm_format_opt, input.frm_max_length_opt",lt),e.on("change click","[data-changeme]",ot),e.on("click","input.frm_req_field",st),e.on("click",".frm_mark_unique",ct),e.on("change",".frm_repeat_format",Vr),e.on("change",".frm_repeat_limit",Kr),e.on("change",".frm_js_checkbox_limit",Jr),e.on("input",'input[name^="field_options[add_label_"]',(function(){Yr(this,"add")})),e.on("input",'input[name^="field_options[remove_label_"]',(function(){Yr(this,"remove")})),e.on("change",'select[name^="field_options[data_type_"]',Nr),jQuery(t).on("click",".frm-collapse-page",Or),jQuery(t).on("click",".frm-collapse-section",Fr),e.on("click",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",Hr),e.on("keydown",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",(function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),Hr.call(this,e))})),jQuery(t).on("show.bs.dropdown hide.bs.dropdown",ze),e.on("click",".frm_toggle_sep_values",yt),e.on("click",".frm_toggle_image_options",ht),e.on("click",".frm_remove_image_option",Et),e.on("click",".frm_choose_image_box",xt),e.on("change",".frm_hide_image_text",Qt),e.on("change",".frm_field_options_image_size",jt),e.on("click",".frm_multiselect_opt",kt),j.on("mousedown","input, textarea, select",At),j.on("click","input[type=radio], input[type=checkbox]",At),j.on("click",".frm_delete_field",Nt),j.on("click",".frm_select_field",Tt),jQuery(document).on("click",".frm_delete_field_group",Ot),jQuery(document).on("click",".frm_clone_field_group",Dt),jQuery(document).on("click","#frm_field_group_controls > span:first-child",Mt),jQuery(document).on("click",".frm-row-layout-option",Yt),jQuery(document).on("click",".frm-merge-fields-into-row .frm-row-layout-option",Xt),jQuery(document).on("click",".frm-custom-field-group-layout",er),jQuery(document).on("click",".frm-merge-fields-into-row .frm-custom-field-group-layout",rr),jQuery(document).on("click",".frm-break-field-group",lr),j.on("click","#frm_field_group_popup .frm_grid_container input",sr),jQuery(document).on("click",".frm-cancel-custom-field-group-layout",dr),jQuery(document).on("click",".frm-save-custom-field-group-layout",fr),j.on("click","ul.frm_sorting",ur),jQuery(document).on("click",".frm-merge-fields-into-row",vr),jQuery(document).on("click",".frm-delete-field-groups",jr),j.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",Oe)})),j.on("mousemove","ul.frm_sorting",De),j.on("show.bs.dropdown",".frm-field-action-icons",He),jQuery(document).on("show.bs.dropdown","#frm_field_group_controls",Pe),e.on("click",".frm_single_option a[data-removeid]",It),e.on("mousedown",".frm_single_option input[type=radio]",Bt),e.on("focusin",".frm_single_option input[type=text]",Ct),e.on("click",".frm_add_opt",_t),e.on("change",".frm_single_option input",Zr),e.on("change",".frm_image_id",Zr),e.on("change",".frm_toggle_mult_sel",pt),e.on("focusin",".frm_classes + .frm-token-proxy-input",Bi),j.on("click",".frm_primary_label",zr),j.on("click",".frm_description",Rr),j.on("click","li.ui-state-default:not(.frm_noallow)",$r),j.on("dblclick","li.ui-state-default",Ur),e.on("change",".frm_tax_form_select",Xr),e.on("change","select.conf_field",ft),e.on("change",".frm_get_field_selection",jn),e.on("click",".frm-show-inline-modal",Bn),e.on("click",".frm-inline-modal .dismiss",qn),jQuery(document).on("change","[data-frmchange]",Tn),document.addEventListener("click",Nn),e.on("change",".frm_include_extras_field",et),e.on("change",'select[name^="field_options[form_select_"]',Mo),jQuery(document).on("submit","#frm_js_build_form",Fi),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",Mi),nt(),jQuery(document).on("change",".frmjs_prod_data_type_opt",Fo),jQuery(document).on("focus",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',Ar),jQuery(document).on("blur",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',Br),frmDom.util.documentOn("click",".frm-show-field-settings",$r),frmDom.util.documentOn("change","select.frm_format_dropdown, select.frm_phone_type_dropdown",Wr),e.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 i=r.slice(n+1).find((function(e){return null!==e.offsetParent}));if(i){i.focus();var o=i.value.length;i.setSelectionRange(o,o)}}}(e.currentTarget)})),!1!==(r=To("#frm-bulk-modal","700px"))&&(jQuery(".frm-insert-preset").on("click",mt),jQuery(w).on("click","a.frm-bulk-edit-link",(function(e){e.preventDefault();var t,n,i,o,a,l="",s=jQuery(this).closest("[data-fid]").data("fid"),d=pn(s),c=Ho(s);if(o=document.getElementById("frm_field_"+s+"_opts")){for(a=o.getElementsByTagName("li"),document.getElementById("bulk-field-id").value=s,t=0;t<a.length;t++)"000"!==(n=a[t].getAttribute("data-optkey"))&&void 0!==(i=document.getElementsByName("field_options[options_"+s+"]["+n+"][label]")[0])&&(l+=i.value,d&&(l+="|"+document.getElementsByName("field_options[options_"+s+"]["+n+"][value]")[0].value),c&&(l+="|"+document.getElementsByName("field_options[options_"+s+"]["+n+"][price]")[0].value),l+="\r\n"),t>=a.length-1&&(document.getElementById("frm_bulk_options").value=l);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),Mi())}))),In(),document.addEventListener("frm_added_field",In),Be(),Po(),xn(),frmDom.util.documentOn("change",".frm_show_password_setting_input",(function(e){var t=e.target.getAttribute("data-fid"),r=document.getElementById("frm_field_id_"+t);r&&r.classList.toggle("frm_disabled_show_password",!e.target.checked)})),document.addEventListener("scroll",Ti,!0),document.addEventListener("change",qi),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(Pr)}),9999)},settingsInit:function(){var e,t,r,n,i=jQuery(document.getElementById("frm_notification_settings"));i.on("click",".frm_email_buttons",oi),i.on("click",".frm_remove_field",ai),i.on("change",".frm_to_row, .frm_from_row",li),i.on("change",".frm_tax_selector",ji),i.on("change","select.frm_single_post_field",mi),i.on("change","select.frm_toggle_post_content",_i),i.on("change","select.frm_dyncontent_opt",pi),i.on("change",".frm_post_type",gi),i.on("click",".frm_add_postmeta_row",vi),i.on("click",".frm_add_posttax_row",hi),i.on("click",".frm_toggle_cf_opts",wi),i.on("click",".frm_duplicate_form_action",Zn),jQuery(".frm_actions_list").on("click",".frm_active_action",ti),jQuery("#frm-show-groups, #frm-hide-groups").on("click",ri),lo(),jQuery("ul.frm_actions_list li").each((function(){si(jQuery(this).children("a").data("actiontype"));var e=jQuery(this).find("i");"none"!==e.css("background-image")&&e.addClass("frm-inverse")})),jQuery(".frm_submit_settings_btn").on("click",xi),Gn(),(e=jQuery(".frm_form_settings")).on("click",".frm_add_form_logic",ui),e.on("click",".frm_already_used",fi),document.addEventListener("click",(function(e){var t=e.target;t.closest(".frm_image_preview_wrapper")&&(t.closest(".frm_choose_image_box")?xt.bind(t)(e):t.closest(".frm_remove_image_option")&&Et.bind(t)(e))})),e.on("mouseup","*:not(.frm-show-box)",Go),jQuery(document.getElementById("no_save")).on("change",(function(){this.checked&&!0!==confirm(a.no_save_warning)&&jQuery(this).attr("checked",!1)})),jQuery('select[name="options[edit_action]"]').on("change",Xn),t=document.getElementById("logged_in"),jQuery(t).on("change",(function(){this.checked?No(".hide_logged_in"):qo(".hide_logged_in")})),r=jQuery(document.getElementById("frm_cookie_expiration")),jQuery(document.getElementById("frm_single_entry_type")).on("change",(function(){"cookie"===this.value?r.fadeIn("slow"):r.fadeOut("slow")}));var o=document.getElementById("single_entry");jQuery(o).on("change",(function(){this.checked?No(".hide_single_entry"):qo(".hide_single_entry"),this.checked&&"cookie"===jQuery(document.getElementById("frm_single_entry_type")).val()?r.fadeIn("slow"):r.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")})),Pn(l),n=document.getElementById("editable"),jQuery(n).on("change",(function(){this.checked?(jQuery(".hide_editable").fadeIn("slow"),Pn(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",Sn),jQuery(document).on("submit",".frm_form_settings",Hi),jQuery(document).on("change","#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea",Mi),jo(),jQuery(document).on("frm-action-loaded",Vi),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-"+e.target.value+"]").forEach((function(e){e.classList.remove("frm_hidden")})),t.setAttribute("data-on-submit-type",e.target.value)}}))},panelInit:function(){var e,t,r,n;jQuery(".frm_wrap, #postbox-container-1").on("click",".frm_insert_code",Ei),jQuery(document).on("change",".frm_insert_val",(function(){ki(jQuery(this).data("target"),jQuery(this).val()),jQuery(this).val("")})),jQuery(document).on("click change",'[name="frm-id-key-condition"]',Ai),jQuery(document).on("keyup change",".frm-build-logic",Ii),Yn(),jQuery(document).on("frmElementAdded",(function(e,t){Yn(t)})),jQuery(document).on("mousedown",".frm-show-box",Ci),t=document.getElementById("form_settings_page"),r=document.body.classList.contains("post-type-frm_display"),n=document.getElementById("frm_insert_fields_tab"),(null!==t||r||D)&&jQuery(document).on("focusin","form input, form textarea",(function(e){var i,o,a,l;if(e.stopPropagation(),(o=this).parentNode.parentNode.classList.contains("frm_has_shortcodes")&&(Wi(),"use"===(a=$i(o)).tagName?-1===(a=a.firstElementChild).getAttributeNS("http://www.w3.org/1999/xlink","href").indexOf("frm_close_icon")&&Oi(a,"nofocus"):a.classList.contains("frm_close_icon")||Oi(a,"nofocus")),jQuery(this).is(":not(:submit, input[type=button], .frm-search-input, input[type=checkbox])")){if(jQuery(e.target).closest("#frm_adv_info").length)return;if(null!==t||D)i=jQuery("#frm_html_tab"),jQuery(this).closest("#html_settings").length>0?(i.show(),i.siblings().hide(),jQuery("#frm_html_tab a").trigger("click"),function(e){var t,r=e.id;void 0!==r&&-1===r.indexOf("-search-input")&&(jQuery("#frm-adv-info-tab").attr("data-fills",r.trim()),e.classList.contains("field_custom_html")&&(r="field_custom_html"),t=["after_html","before_html","submit_html","field_custom_html"],jQuery.inArray(r,t)>=0&&(jQuery(".frm_code_list li:not(.show_"+r+")").addClass("frm_hidden"),jQuery(".frm_code_list li.show_"+r).removeClass("frm_hidden")))}(this)):((l=jQuery(".frm-category-tabs li"))[0]&&(l[0].style.display=""),n.click(),i.hide(),i.siblings().show());else if(r){var s=new CustomEvent("frm_legacy_views_handle_field_focus");s.frmData={idAttrValue:this.id},document.dispatchEvent(s)}}})),jQuery(".frm_wrap, #postbox-container-1").on("mousedown","#frm_adv_info a, .frm_field_list a",(function(e){e.preventDefault()})),(e=jQuery("#frm_adv_info")).on("click",".subsubsub a.frmids",(function(e){Ui("frmids",e)})),e.on("click",".subsubsub a.frmkeys",(function(e){Ui("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"),i=t.cloneNode(!0),o=document.querySelector(".frm-dismissed-inbox-messages");if("free_templates"!==r||this.classList.contains("frm_inbox_dismiss")){e.preventDefault(),data={action:"frm_inbox_dismiss",key:r,nonce:frmGlobal.nonce};var a="frm_inbox_slide_in"===t.id;a&&(t.classList.remove("s11-fadein"),t.classList.add("s11-fadeout"),t.addEventListener("animationend",(function(){return t.remove()}),{once:!0})),Bo(data,(function(){if(!a)return"#"!==n?(window.location=n,!0):void Co(t,(function(){var e;null!==o&&(i.classList.remove("frm-fade"),null===(e=i.querySelector(".frm-inbox-message-heading"))||void 0===e||e.removeChild(i.querySelector(".frm-inbox-message-heading .frm_inbox_dismiss")),o.append(i)),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"),ho()),t.parentNode.removeChild(t)}))}))}})),!1===(null===(e=document.getElementById("frm_empty_inbox"))||void 0===e?void 0:e.classList.contains("frm_hidden"))&&ho()},solutionInit:function(){jQuery(document).on("submit","#frm-new-template",Qo)},styleInit:function(){var e=jQuery(".frm_image_preview_wrapper");e.on("click",".frm_choose_image_box",xt),e.on("click",".frm_remove_image_option",Et),wp.hooks.doAction("frm_style_editor_init")},customCSSInit:function(){console.warn("Calling frmAdminBuild.customCSSInit is deprecated.")},globalSettingsInit:function(){var e;jQuery(document).on("click","[data-frmuninstall]",Ki),lo(),null!==(e=document.getElementById("licenses_settings"))&&jQuery(e).on("click",".edd_frm_save_license",Ji),jQuery(document).on("click","#frm-new-template button",wo),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",Eo),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(){return E=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"),i=null==n?void 0:n.querySelectorAll('[name="frm_payment_section"]');i&&i.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"),i.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",Yi),jQuery(document.getElementById("frm_export_xml")).on("submit",Zi),jQuery("#frm_export_xml input, #frm_export_xml select").on("change",eo),jQuery('input[name="frm_import_file"]').on("change",to),document.querySelector('select[name="format"]').addEventListener("change",no),jQuery('input[name="frm_export_forms[]"]').on("click",ao),lo(),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()})),oo(ro()),document.querySelector("#frm-export-select-all").addEventListener("change",(function(e){document.querySelectorAll('[name="frm_export_forms[]"]').forEach((function(t){return 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&&Bo({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=pn(e),i=Ho(e)?"frm_bulk_products":"frm_import_options";jQuery.ajax({type:"POST",url:ajaxurl,data:{action:i,field_id:e,opts:t,separate:n,nonce:frmGlobal.nonce},success:function(t){document.getElementById("frm_field_"+e+"_opts").innerHTML=t,wp.hooks.doAction("frm_after_bulk_edit_opts",e),rn(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_"+e+"_"+t+" .frm_remove_tag").trigger("click")},downloadXML:function(e,t,r){var n=ajaxurl+"?action=frm_"+e+"_xml&ids="+t;null!==r&&(n=n+"&is_template="+r),location.href=n},hooks:{applyFilters:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];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),i=1;i<r;i++)n[i-1]=arguments[i];return(t=wp.hooks).doAction.apply(t,[e].concat(n))},addAction:function(e,t,r){return wp.hooks.addAction(e,"formidable",t,r)}},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:To,infoModal:H,offsetModalY:Ri,adjustConditionalLogicOptionOrders:on,addRadioCheckboxOpt:ln,installNewForm:xo,toggleAddonState:uo,purifyHtml:mn,loadApiEmailForm:bo,addMyEmailAddress:Ro,fillDropdownOpts:sn,showSaveAndReloadModal:Ni,clearSettingsBox:Ke,deleteField:xr,insertFormField:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(r){var n=k,i=0;"summary"===e&&(i=j.children('li[data-type="break"]').length>0?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:Object.assign(pe(e,0,n,i),{field_options:t}),success:function(t){r(t),setTimeout((function(){Qn(),Ue(t,!0);var r=he(t);r&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:r,fieldType:e,form_id:n})}),10)},error:je})}))},confirmLinkClick:F,handleInsertFieldByDraggingResponse:ye,handleAddFieldClickResponse:Ie,syncLayoutClasses:le}}(),jQuery(document).ready((function(){var e;frmAdminBuild.init(),frmDom.bootstrap.setupBootstrapDropdowns((function(e){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-toggle","dropdown")}))})(); | |