PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16.1
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | js/formidable_admin.js +11155 -1 6.336.16.1 View file →
@@ -1 +1,11155 @@
1 -(()=>{var e={65:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(8793),o=n(1323);function i(e){var t=(0,r.A)(e);return function(e){return(0,o.A)(t,e)}}},1323:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r={"!":function(e){return!e},"*":function(e,t){return e*t},"/":function(e,t){return e/t},"%":function(e,t){return e%t},"+":function(e,t){return e+t},"-":function(e,t){return e-t},"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"==":function(e,t){return e===t},"!=":function(e,t){return e!==t},"&&":function(e,t){return e&&t},"||":function(e,t){return e||t},"?:":function(e,t,n){if(e)throw t;return n}};function o(e,t){var n,o,i,a,l,s,c=[];for(n=0;n<e.length;n++){if(l=e[n],a=r[l]){for(o=a.length,i=Array(o);o--;)i[o]=c.pop();try{s=a.apply(null,i)}catch(e){return e}}else s=t.hasOwnProperty(l)?t[l]:+l;c.push(s)}return c[0]}},1364:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(65);function o(e){var t=(0,r.A)(e);return function(e){return+t({n:e})}}},8793:(e,t,n)=>{"use strict";var r,o,i,a;function l(e){for(var t,n,l,s,c=[],d=[];t=e.match(a);){for(n=t[0],(l=e.substr(0,t.index).trim())&&c.push(l);s=d.pop();){if(i[n]){if(i[n][0]===s){n=i[n][1]||n;break}}else if(o.indexOf(s)>=0||r[s]<r[n]){d.push(s);break}c.push(s)}i[n]||d.push(n),e=e.substr(t.index+n.length)}return(e=e.trim())&&c.push(e),c.concat(d.reverse())}n.d(t,{A:()=>l}),r={"(":9,"!":8,"*":7,"/":7,"%":7,"+":6,"-":6,"<":5,"<=":5,">":5,">=":5,"==":4,"!=":4,"&&":3,"||":2,"?":1,"?:":1},o=["(","?"],i={")":["("],":":["?","?:"]},a=/<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/},7521:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(6956),o=n(7395);const i=function(e,t){return function(n,i,a){var l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10,s=e[t];if((0,o.A)(n)&&(0,r.A)(i))if("function"==typeof a)if("number"==typeof l){var c={callback:a,priority:l,namespace:i};if(s[n]){var d,u=s[n].handlers;for(d=u.length;d>0&&!(l>=u[d-1].priority);d--);d===u.length?u[d]=c:u.splice(d,0,c),s.__current.forEach(function(e){e.name===n&&e.currentIndex>=d&&e.currentIndex++})}else s[n]={handlers:[c],runs:0};"hookAdded"!==n&&e.doAction("hookAdded",n,i,a,l)}else console.error("If specified, the hook priority must be a number.");else console.error("The hook callback must be a function.")}}},11:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){return function(){var n,r,o=e[t];return null!==(n=null===(r=o.__current[o.__current.length-1])||void 0===r?void 0:r.name)&&void 0!==n?n:null}}},5375:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(7395);const o=function(e,t){return function(n){var o=e[t];if((0,r.A)(n))return o[n]&&o[n].runs?o[n].runs:0}}},3561:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){return function(n){var r=e[t];return void 0===n?void 0!==r.__current[0]:!!r.__current[0]&&n===r.__current[0].name}}},8830:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){return function(n,r){var o=e[t];return void 0!==r?n in o&&o[n].handlers.some(function(e){return e.namespace===r}):n in o}}},7765:(e,t,n)=>{"use strict";n.d(t,{A:()=>f});var r=n(3029),o=n(7521),i=n(4194),a=n(8830),l=n(6763),s=n(11),c=n(3561),d=n(5375),u=function e(){(0,r.A)(this,e),this.actions=Object.create(null),this.actions.__current=[],this.filters=Object.create(null),this.filters.__current=[],this.addAction=(0,o.A)(this,"actions"),this.addFilter=(0,o.A)(this,"filters"),this.removeAction=(0,i.A)(this,"actions"),this.removeFilter=(0,i.A)(this,"filters"),this.hasAction=(0,a.A)(this,"actions"),this.hasFilter=(0,a.A)(this,"filters"),this.removeAllActions=(0,i.A)(this,"actions",!0),this.removeAllFilters=(0,i.A)(this,"filters",!0),this.doAction=(0,l.A)(this,"actions"),this.applyFilters=(0,l.A)(this,"filters",!0),this.currentAction=(0,s.A)(this,"actions"),this.currentFilter=(0,s.A)(this,"filters"),this.doingAction=(0,c.A)(this,"actions"),this.doingFilter=(0,c.A)(this,"filters"),this.didAction=(0,d.A)(this,"actions"),this.didFilter=(0,d.A)(this,"filters")};const f=function(){return new u}},4194:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(6956),o=n(7395);const i=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(i,a){var l=e[t];if((0,o.A)(i)&&(n||(0,r.A)(a))){if(!l[i])return 0;var s=0;if(n)s=l[i].handlers.length,l[i]={runs:l[i].runs,handlers:[]};else for(var c=l[i].handlers,d=function(e){c[e].namespace===a&&(c.splice(e,1),s++,l.__current.forEach(function(t){t.name===i&&t.currentIndex>=e&&t.currentIndex--}))},u=c.length-1;u>=0;u--)d(u);return"hookRemoved"!==i&&e.doAction("hookRemoved",i,a),s}}}},6763:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(r){var o=e[t];o[r]||(o[r]={handlers:[],runs:0}),o[r].runs++;for(var i=o[r].handlers,a=arguments.length,l=new Array(a>1?a-1:0),s=1;s<a;s++)l[s-1]=arguments[s];if(!i||!i.length)return n?l[0]:void 0;var c={name:r,currentIndex:0};for(o.__current.push(c);c.currentIndex<i.length;){var d=i[c.currentIndex].callback.apply(null,l);n&&(l[0]=d),c.currentIndex++}return o.__current.pop(),n?l[0]:void 0}}},2133:(e,t,n)=>{"use strict";n.d(t,{se:()=>r});var r=(0,n(7765).A)();r.addAction,r.addFilter,r.removeAction,r.removeFilter,r.hasAction,r.hasFilter,r.removeAllActions,r.removeAllFilters,r.doAction,r.applyFilters,r.currentAction,r.currentFilter,r.doingAction,r.doingFilter,r.didAction,r.didFilter,r.actions,r.filters},7395:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e){return"string"!=typeof e||""===e?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(e)?(console.error("The hook name cannot begin with `__`."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(e)||(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)}},6956:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e){return"string"!=typeof e||""===e?(console.error("The namespace must be a non-empty string."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(e)||(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)}},772:(e,t,n)=>{"use strict";n.d(t,{h:()=>c});var r=n(4467),o=n(5397);function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach(function(t){(0,r.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var l={"":{plural_forms:function(e){return 1===e?0:1}}},s=/^i18n\.(n?gettext|has_translation)(_|$)/,c=function(e,t,n){var r=new o.A({}),i=new Set,c=function(){i.forEach(function(e){return e()})},d=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default";r.data[t]=a(a(a({},l),r.data[t]),e),r.data[t][""]=a(a({},l[""]),r.data[t][""])},u=function(e,t){d(e,t),c()},f=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default",t=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;return r.data[e]||d(void 0,e),r.dcnpgettext(e,t,n,o,i)},m=function(){return arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default"},_=function(e,t,r){var o=f(r,t,e);return n?(o=n.applyFilters("i18n.gettext_with_context",o,e,t,r),n.applyFilters("i18n.gettext_with_context_"+m(r),o,e,t,r)):o};if(e&&u(e,t),n){var p=function(e){s.test(e)&&c()};n.addAction("hookAdded","core/i18n",p),n.addAction("hookRemoved","core/i18n",p)}return{getLocaleData:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default";return r.data[e]},setLocaleData:u,resetLocaleData:function(e,t){r.data={},r.pluralForms={},u(e,t)},subscribe:function(e){return i.add(e),function(){return i.delete(e)}},__:function(e,t){var r=f(t,void 0,e);return n?(r=n.applyFilters("i18n.gettext",r,e,t),n.applyFilters("i18n.gettext_"+m(t),r,e,t)):r},_x:_,_n:function(e,t,r,o){var i=f(o,void 0,e,t,r);return n?(i=n.applyFilters("i18n.ngettext",i,e,t,r,o),n.applyFilters("i18n.ngettext_"+m(o),i,e,t,r,o)):i},_nx:function(e,t,r,o,i){var a=f(i,o,e,t,r);return n?(a=n.applyFilters("i18n.ngettext_with_context",a,e,t,r,o,i),n.applyFilters("i18n.ngettext_with_context_"+m(i),a,e,t,r,o,i)):a},isRTL:function(){return"rtl"===_("ltr","text direction")},hasTranslation:function(e,t,o){var i,a,l=t?t+""+e:e,s=!(null===(i=r.data)||void 0===i||null===(a=i[null!=o?o:"default"])||void 0===a||!a[l]);return n&&(s=n.applyFilters("i18n.has_translation",s,e,t,o),s=n.applyFilters("i18n.has_translation_"+m(o),s,e,t,o)),s}}}},5839:(e,t,n)=>{"use strict";n.d(t,{__:()=>a});var r=n(772),o=n(2133),i=(0,r.h)(void 0,void 0,o.se),a=(i.getLocaleData.bind(i),i.setLocaleData.bind(i),i.resetLocaleData.bind(i),i.subscribe.bind(i),i.__.bind(i));i._x.bind(i),i._n.bind(i),i._nx.bind(i),i.isRTL.bind(i),i.hasTranslation.bind(i)},9575:(e,t,n)=>{"use strict";n.d(t,{__:()=>r.__}),n(181),n(772);var r=n(5839)},181:(e,t,n)=>{"use strict";var r=n(8616),o=n.n(r);n(7604),o()(console.error)},1105:(e,t,n)=>{"use strict";n.r(t),n.d(t,{addonError:()=>f,afterAddonInstall:()=>u,extractErrorFromAddOnResponse:()=>d,toggleAddonState:()=>c});var r=n(9575);function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,a,l=[],s=!0,c=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(r=i.call(n)).done)&&(l.push(r.value),l.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw o}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var 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)?i(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var a=frmDom,l=a.div,s=a.svg;function c(e,t){var n,r=null!==(n=window.ajaxurl)&&void 0!==n?n:frm_js.ajax_url;jQuery(".frm-addon-error").remove();var o=jQuery(e),i=o.attr("rel"),a=o.parent(),l=a.parent().find(".addon-status-label");o.addClass("frm_loading_button"),jQuery.ajax({url:r,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:t,nonce:frmGlobal.nonce,plugin:i},success:function(e){var n,r,i;"string"!=typeof(e=null!==(n=null===(r=e)||void 0===r?void 0:r.data)&&void 0!==n?n:e)&&"string"==typeof e.message&&(void 0!==e.saveAndReload&&(i=e.saveAndReload),e=e.message);var s=d(e);s?f(s,a,o):(u(e,o,l,a,i,t),wp.hooks.doAction("frm_update_addon_state",e))},error:function(){o.removeClass("frm_loading_button")}})}function d(e){return"string"!=typeof e&&!e.success&&(e.form&&jQuery(e.form).is("#message")?{message:jQuery(e.form).find("p").html()}:e)}function u(e,t,n,i,a){var c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"frm_activate_addon",d=frm_admin_js,u=document.querySelectorAll(".frm-addon-status");u.forEach(function(t){t.textContent=e,t.style.display="block"}),t.css({opacity:"0"}),document.querySelectorAll(".frm-oneclick").forEach(function(e){e.style.display="none"}),function(){var e=document.getElementById("frm_upgrade_modal");if(e){e.classList.add("frm-success");var t=e.querySelector(".frm-upgrade-message");if(t){var n=t.querySelector("img");t.replaceChildren((0,r.__)("Great! Everything's ready to go!","formidable"),document.createElement("br"),(0,r.__)("You just need to refresh the builder so the new field becomes available.","formidable")),n&&t.append(n)}var o=document.querySelector(".frm-addon-status");o&&(o.textContent="");var i,a=e.querySelector(".frm-circled-icon");if(a)a.classList.add("frm-circled-icon-green"),null===(i=a.querySelector("svg"))||void 0===i||i.replaceWith(s({href:"#frm_checkmark_icon"}))}}();var f={frm_activate_addon:{class:"frm-addon-active",message:d.active},frm_deactivate_addon:{class:"frm-addon-installed",message:d.installed},frm_uninstall_addon:{class:"frm-addon-not-installed",message:d.not_installed}};f.frm_install_addon=f.frm_activate_addon;var _=o(n,1)[0];_&&(_.textContent=f[c].message);var p=o(i,1)[0].parentElement;p.classList.remove("frm-addon-not-installed","frm-addon-installed","frm-addon-active"),p.classList.add(f[c].class),o(t,1)[0].classList.remove("frm_loading_button"),document.querySelectorAll(".frm-admin-page-import, #frm-admin-smtp, #frm-welcome").length>0?window.location.reload():["settings","form_builder"].includes(a)&&u.forEach(function(e){var t=null!==e.closest("#frm_upgrade_modal");e.append(function(e,t){var n,o=[m(e)];return t&&o.push(((n=document.createElement("a")).setAttribute("href","#"),n.classList.add("button","button-secondary","frm-button-secondary","dismiss"),n.textContent=(0,r.__)("Not Now","formidable"),n)),l({className:"frm-save-and-reload-options",children:o})}(a,t))})}function f(e,t,n){e.form?(jQuery(".frm-inline-error").remove(),n.closest(".frm-card").html(e.form).css({padding:5}).find("#upgrade").attr("rel",n.attr("rel")).on("click",_)):(t.append('<div class="frm-addon-error frm_error_style"><p><strong>'.concat(e.message,"</strong></p></div>")),n.removeClass("frm_loading_button"),jQuery(".frm-addon-error").delay(4e3).fadeOut())}function m(e){var t=document.createElement("button");return t.classList.add("frm-save-and-reload","button","button-primary","frm-button-primary"),t.textContent=(0,r.__)("Save and Reload","formidable"),t.addEventListener("click",function(){var t;"form_builder"===e?((t=document.getElementById("frm_submit_side_top")).classList.contains("frm_submit_ajax")&&t.setAttribute("data-new-addon-installed",!0),t.click()):"settings"===e&&function(){var e=document.getElementById("form_settings_page");if(e){var t=e.querySelector("form.frm_form_settings");null!==t&&(wp.hooks.doAction("frm_reset_fields_updated"),t.submit())}}()}),t}function _(e){e.preventDefault();var t=jQuery(this),n=t.parent().parent(),r=t.attr("rel");t.addClass("frm_loading_button"),jQuery.ajax({url:ajaxurl,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:"frm_install_addon",nonce:frmAdminJs.nonce,plugin:r,hostname:n.find("#hostname").val(),username:n.find("#username").val(),password:n.find("#password").val()},success:function(e){var r,o,i=d(e=null!==(r=null===(o=e)||void 0===o?void 0:o.data)&&void 0!==r?r:e);i?f(i,n,t):u(e,t,message,n)},error:function(){t.removeClass("frm_loading_button")}})}},4365:()=>{!function(){function e(e){var t=e.querySelector(".frm-gc-item-type"),n=t.value,r=t.name.replace(/\[type\]$/,"");e.querySelectorAll(".frm-gc-type-settings").forEach(function(e){var t=e.dataset.type===n;e.toggleAttribute("hidden",!t),e.querySelectorAll("[data-frm-gc-field]").forEach(function(e){var n=e.dataset.frmGcField;t?e.name="".concat(r,"[").concat(n,"]"):e.removeAttribute("name")})})}function t(t){var n,r=t.querySelector(".frm_gc_add_item"),o=null!==(n=null==r?void 0:r.dataset.fieldNameBase)&&void 0!==n?n:"",i=t.querySelectorAll(".frm_gc_item_row");i.forEach(function(n,r){var i=n.querySelector(".frm-gc-item-type");i&&o&&(i.name="".concat(o,"[").concat(r,"][type]")),function(e,t,n){var r=e.querySelector('[data-frm-gc-field="type"]');if(r){r.id="".concat(t,"_type_").concat(n);var o=e.querySelector('[data-frm-gc-for="type"]');o&&(o.htmlFor=r.id)}e.querySelectorAll(".frm-gc-type-settings").forEach(function(e){var r=e.dataset.type;e.querySelectorAll("[data-frm-gc-field]").forEach(function(o){var i=o.dataset.frmGcField;o.id="".concat(t,"_").concat(i,"_").concat(r,"_").concat(n);var a=e.querySelector('[data-frm-gc-for="'.concat(i,'"]'));a&&(a.htmlFor=o.id)})})}(n,t.id,r),e(n)}),t.dataset.itemCount=i.length}function n(e){var t=e.getAttribute("aria-label");e.classList.add("is-copied"),e.setAttribute("aria-label",e.dataset.copiedLabel||"Copied!"),setTimeout(function(){e.classList.remove("is-copied"),e.setAttribute("aria-label",t)},1600)}document.addEventListener("click",function(e){var r=e.target.closest(".frm_gc_add_item");if(r){var o=r.closest(".frm_gated_content_settings"),i=o.querySelector(".frm_gc_items_list"),a=o.querySelector(".frm_gc_item_template");return i.append(a.content.cloneNode(!0)),t(o),void frmDom.autocomplete.initSelectionAutocomplete(i.lastElementChild)}var l=e.target.closest(".frm_gc_remove_item");if(l){var s=l.closest(".frm_gated_content_settings");return l.closest(".frm_gc_item_row").remove(),void t(s)}var c=e.target.closest(".frm_gc_copy_shortcode");if(c){var d,u=c.dataset.frmCopy;if(null!==(d=navigator.clipboard)&&void 0!==d&&d.writeText)navigator.clipboard.writeText(u).then(function(){return n(c)});else{var f=document.createElement("textarea");f.value=u,f.style.cssText="position:fixed;opacity:0;",document.body.append(f),f.select(),document.execCommand("copy"),f.remove(),n(c)}}}),document.addEventListener("change",function(t){var n=t.target.closest(".frm-gc-item-type");if(n)e(n.closest(".frm_gc_item_row"));else{var r=t.target.closest(".frm-gc-file-form-select");r&&function(e){var t=e.closest(".frm-gc-type-settings"),n=null==t?void 0:t.querySelector('[data-frm-gc-field="id"]');if(n){var r=e.value;Array.from(n.options).forEach(function(e){var t=e.dataset.formId;e.style.display=t?r&&t===r?"":"none":""});var o=n.options[n.selectedIndex];"none"===(null==o?void 0:o.style.display)&&(n.value="")}}(r)}}),jQuery(document).on("frm-multiselect-changed",'select[id^="event_"]',function(){var e=document.querySelector('.frm_gc_update_section[data-frm-gc-event-id="'.concat(this.id,'"]'));if(e){var t=Array.from(this.options).some(function(e){return e.selected&&"update"===e.value});e.hidden=!t}})}()},8095:(e,t,n)=>{"use strict";function r(e,t){var n=t();return n?(frmAdminBuild.infoModal(n),e.classList.add("frm_invalid_field"),function(e){var t=document.querySelectorAll("#frm_info_modal .dismiss, #frm_info_modal #frm-info-click, .ui-widget-overlay.ui-front");function n(){setTimeout(function(){return e.focus()},0),t.forEach(function(e){return e.removeEventListener("click",n)})}t.forEach(function(e){return e.addEventListener("click",n)})}(e)):e.classList.remove("frm_invalid_field"),n}n.r(t),n.d(t,{validateField:()=>r})},4746:(e,t,n)=>{"use strict";n.r(t),n.d(t,{getRangeSettingsDefaults:()=>l,validateNumberRangeSetting:()=>s,validateRangeSettings:()=>d,validateStepSetting:()=>c});var r=n(9575),o=n(8095),i=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return t?t.dataset.fid:null==n||null===(e=n.closest(".frm-single-settings"))||void 0===e?void 0:e.dataset.fid},a=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return t||(t=null==n?void 0:n.closest(".frm-single-settings")),null===(e=t)||void 0===e||null===(e=e.className.match(/frm-type-(\w+)/))||void 0===e?void 0:e[1]};function l(e){var t=a(e)||"number";return wp.hooks.applyFilters("frm_range_settings_defaults",{maxNum:9999999,minNum:0,step:1},{singleSettings:e,fieldType:t})}function s(e){if(e.closest(".frm-number-range")){var t=e.closest(".frm-single-settings"),n=i(t);if(n){var a=document.querySelector('[name="field_options[minnum_'.concat(n,']"]'));if(a){var s=document.querySelector('[name="field_options[maxnum_'.concat(n,']"]'));if(s)return(0,o.validateField)(e,function(){var e=l(t),n=e.minNum,o=e.maxNum;return parseFloat(a.value||n)>=parseFloat(s.value||o)?(0,r.__)("Minimum value cannot be greater than or equal to maximum value.","formidable"):""})}}}}function c(e){if(e.closest(".frm-step")){var t=e.closest(".frm-single-settings"),n=i(t);if(n){var a=document.querySelector('[name="field_options[step_'.concat(n,']"]'));if(a)return(0,o.validateField)(e,function(){var e=l(t),o=e.step,i=e.minNum,s=e.maxNum,c=parseFloat(a.value||o);if(c<=0)return(0,r.__)("Step value must be greater than 0.","formidable");var d=document.querySelector('[name="field_options[maxnum_'.concat(n,']"]'));if(!d)return"";var u=document.querySelector('[name="field_options[minnum_'.concat(n,']"]')),f=parseFloat((null==u?void 0:u.value)||i);return c>parseFloat(d.value||s)-f?(0,r.__)("Step value cannot be greater than the difference between the minimum and maximum values.","formidable"):""})}}}function d(e){var t=s(e);return t||(t=c(e)),wp.hooks.applyFilters("frm_validate_range_settings",t||"",{field:e})}},4260:(e,t,n)=>{"use strict";n.r(t),n.d(t,{addOneClick:()=>i,initModal:()=>a,initUpgradeModal:()=>l});var r=n(9575),o=frmDom.svg;function i(e,t,n){var i;if("modal"===t)i=document.getElementById("frm_upgrade_modal");else{if("tab"!==t)return;i=document.getElementById(e.getAttribute("href").substr(1))}var a,l=i.querySelector(".frm-oneclick"),s=i.querySelector(".frm-upgrade-message"),c=i.querySelector(".frm-upgrade-link"),d=i.querySelector(".frm-oneclick-button"),u=i.querySelector(".frm-addon-status"),f=e.getAttribute("data-oneclick"),m=e.getAttribute("data-message"),_="block",p="block",g="none",v=i.querySelector(".frm-circled-icon");v&&(v.classList.remove("frm-circled-icon-green"),null===(a=v.querySelector("svg"))||void 0===a||a.replaceWith(o({href:"#frm_filled_lock_icon"})));var y=i.querySelector(".frm-learn-more");if(y&&(e.dataset.learnMore?(y.href=e.dataset.learnMore,y.style.display=""):y.style.display="none"),null!==l&&null!==d&&void 0!==f&&f){null===m&&(p="none"),_="none",g="block",f=JSON.parse(f),d.className=d.className.replace(" frm-install-addon","").replace(" frm-activate-addon",""),d.className="".concat(d.className," ").concat(f.class),d.rel=f.url,l.textContent=(0,r.__)("This plugin is not activated. Would you like to activate it now?","formidable"),d.textContent=(0,r.__)("Activate","formidable");var h=e.querySelector("use");h&&(null==v||v.querySelector("svg").replaceWith(o({href:h.getAttribute("href")||h.getAttribute("xlink:href"),classList:["frm_svg32"]})))}m||(m=s.getAttribute("data-default")),void 0!==n&&(m=m.replace('<span class="frm_feature_label"></span>',n)),s.innerHTML=m,e.dataset.upsellImage&&s.append(frmDom.img({src:e.dataset.upsellImage,alt:e.dataset.upgrade})),c.href=function(e,t){var n=e.getAttribute("data-link");return null!=n&&""!==n||(n=t.getAttribute("data-default")),n}(e,c),u.style.display="none",l&&(l.style.display=g),d&&(d.style.display="block"===g?"inline-block":g),s.style.display=p,c.style.display="block"===_?"inline-block":_;var b=c.closest(".frm-upgrade-modal-actions");b&&(b.style.display="block"===_?"flex":_)}function a(e,t){var n=jQuery(e);if(!n.length)return!1;void 0===t&&(t="552px");var r={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"),n.removeClass("ui-dialog-content ui-widget-content"),e=n,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 n.dialog(r),n}function l(){var e=a("#frm_upgrade_modal");function t(t){var n,o,a;if((n=t.target).classList){var l=n.classList.contains("frm_show_expired_modal")||null!==n.querySelector(".frm_show_expired_modal")||n.closest(".frm_show_expired_modal");if("change"===t.type&&n.classList.contains("frm_select_with_upgrade")){var s,c=n.options[n.selectedIndex];null!=c&&null!==(s=c.dataset)&&void 0!==s&&s.upgrade&&(n=c)}if(!n.dataset.upgrade){var d=n.closest("[data-upgrade]");if(!d){if(!(d=n.closest(".frm_field_box")))return;n.dataset.upgrade=""}n=d}if(l)wp.hooks.doAction("frm_show_expired_modal",n);else{var u=n.dataset.upgrade;if(u&&!n.classList.contains("frm_show_upgrade_tab")){t.preventDefault();var f=e.get(0);f.classList.remove("frm-success");var m=f.querySelector(".frm_lock_icon");m&&(m.style.display="block",m.classList.remove("frm_lock_open_icon"),m.querySelector("use").setAttribute("href","#frm_lock_icon"));var _="frm_upgrade_modal_image",p=document.getElementById(_);p&&p.remove(),n.dataset.image&&m&&(m.style.display="none",m.parentNode.insertBefore(frmDom.img({id:_,src:"".concat(frmGlobal.url,"/images/").concat(n.dataset.image)}),m));var g=f.querySelector(".license-level");g&&(g.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(n)),i(n,"modal",u);var v=f.querySelector(".frm_are_not_installed");v.style.display=n.dataset.image||n.dataset.oneclick?"none":"inline-block",v.textContent=v.dataset.default,f.querySelector(".frm-upgrade-modal-title-prefix").style.display=n.dataset.oneclick?"inline":"none",f.querySelector(".frm_feature_label").textContent=u,f.querySelector(".frm-upgrade-modal-title-suffix").style.display="none",f.querySelector("h2").style.display="block",e.dialog("open");var y=f.querySelector(".button-primary:not(.frm-oneclick-button)");o=y.getAttribute("href").replace(/(medium=)[a-z_-]+/gi,"$1".concat(n.getAttribute("data-medium"))),null===(a=n.getAttribute("data-content"))&&(a=""),o=o.replace(/(content=)[a-z_-]+/gi,"$1".concat(a)),y.setAttribute("href",o),n.classList.contains("frm_show_update")&&function(e){var t=e.querySelector(".frm-upgrade-modal-title-prefix");t&&(t.style.display="none");var n=e.querySelector(".frm_are_not_installed");n&&(n.textContent=(0,r.__)("require an update","formidable"),n.style.display="");var o=e.querySelector(".frm-oneclick");o&&(o.style.display="none");var i=e.querySelector(".frm-oneclick-button");i&&(i.textContent=(0,r.__)("Update Now","formidable"))}(f)}}}}!1!==e&&(document.addEventListener("click",t),frmDom.util.documentOn("change","select.frm_select_with_upgrade",t))}},8616:e=>{e.exports=function(e,t){var n,r,o=0;function i(){var i,a,l=n,s=arguments.length;e:for(;l;){if(l.args.length===arguments.length){for(a=0;a<s;a++)if(l.args[a]!==arguments[a]){l=l.next;continue e}return l!==n&&(l===r&&(r=l.prev),l.prev.next=l.next,l.next&&(l.next.prev=l.prev),l.next=n,l.prev=null,n.prev=l,n=l),l.val}l=l.next}for(i=new Array(s),a=0;a<s;a++)i[a]=arguments[a];return l={args:i,val:e.apply(null,i)},n?(n.prev=l,l.next=n):r=l,o===t.maxSize?(r=r.prev).next=null:o++,n=l,l.val}return t=t||{},i.clear=function(){n=null,r=null,o=0},i}},7604:(e,t,n)=>{var r;!function(){"use strict";var o={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function i(e){return function(e,t){var n,r,a,l,s,c,d,u,f,m=1,_=e.length,p="";for(r=0;r<_;r++)if("string"==typeof e[r])p+=e[r];else if("object"==typeof e[r]){if((l=e[r]).keys)for(n=t[m],a=0;a<l.keys.length;a++){if(null==n)throw new Error(i('[sprintf] Cannot access property "%s" of undefined value "%s"',l.keys[a],l.keys[a-1]));n=n[l.keys[a]]}else n=l.param_no?t[l.param_no]:t[m++];if(o.not_type.test(l.type)&&o.not_primitive.test(l.type)&&n instanceof Function&&(n=n()),o.numeric_arg.test(l.type)&&"number"!=typeof n&&isNaN(n))throw new TypeError(i("[sprintf] expecting number but found %T",n));switch(o.number.test(l.type)&&(u=n>=0),l.type){case"b":n=parseInt(n,10).toString(2);break;case"c":n=String.fromCharCode(parseInt(n,10));break;case"d":case"i":n=parseInt(n,10);break;case"j":n=JSON.stringify(n,null,l.width?parseInt(l.width):0);break;case"e":n=l.precision?parseFloat(n).toExponential(l.precision):parseFloat(n).toExponential();break;case"f":n=l.precision?parseFloat(n).toFixed(l.precision):parseFloat(n);break;case"g":n=l.precision?String(Number(n.toPrecision(l.precision))):parseFloat(n);break;case"o":n=(parseInt(n,10)>>>0).toString(8);break;case"s":n=String(n),n=l.precision?n.substring(0,l.precision):n;break;case"t":n=String(!!n),n=l.precision?n.substring(0,l.precision):n;break;case"T":n=Object.prototype.toString.call(n).slice(8,-1).toLowerCase(),n=l.precision?n.substring(0,l.precision):n;break;case"u":n=parseInt(n,10)>>>0;break;case"v":n=n.valueOf(),n=l.precision?n.substring(0,l.precision):n;break;case"x":n=(parseInt(n,10)>>>0).toString(16);break;case"X":n=(parseInt(n,10)>>>0).toString(16).toUpperCase()}o.json.test(l.type)?p+=n:(!o.number.test(l.type)||u&&!l.sign?f="":(f=u?"+":"-",n=n.toString().replace(o.sign,"")),c=l.pad_char?"0"===l.pad_char?"0":l.pad_char.charAt(1):" ",d=l.width-(f+n).length,s=l.width&&d>0?c.repeat(d):"",p+=l.align?f+n+s:"0"===c?f+s+n:s+f+n)}return p}(function(e){if(l[e])return l[e];for(var t,n=e,r=[],i=0;n;){if(null!==(t=o.text.exec(n)))r.push(t[0]);else if(null!==(t=o.modulo.exec(n)))r.push("%");else{if(null===(t=o.placeholder.exec(n)))throw new SyntaxError("[sprintf] unexpected placeholder");if(t[2]){i|=1;var a=[],s=t[2],c=[];if(null===(c=o.key.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(a.push(c[1]);""!==(s=s.substring(c[0].length));)if(null!==(c=o.key_access.exec(s)))a.push(c[1]);else{if(null===(c=o.index_access.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");a.push(c[1])}t[2]=a}else i|=2;if(3===i)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");r.push({placeholder:t[0],param_no:t[1],keys:t[2],sign:t[3],pad_char:t[4],align:t[5],width:t[6],precision:t[7],type:t[8]})}n=n.substring(t[0].length)}return l[e]=r}(e),arguments)}function a(e,t){return i.apply(null,[e].concat(t||[]))}var l=Object.create(null);"undefined"!=typeof window&&(window.sprintf=i,window.vsprintf=a,void 0===(r=function(){return{sprintf:i,vsprintf:a}}.call(t,n,t,e))||(e.exports=r))}()},5397:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(1364),o={contextDelimiter:"",onMissingKey:null};function i(e,t){var n;for(n in this.data=e,this.pluralForms={},this.options={},o)this.options[n]=void 0!==t&&n in t?t[n]:o[n]}i.prototype.getPluralForm=function(e,t){var n,o,i,a=this.pluralForms[e];return a||("function"!=typeof(i=(n=this.data[e][""])["Plural-Forms"]||n["plural-forms"]||n.plural_forms)&&(o=function(e){var t,n,r;for(t=e.split(";"),n=0;n<t.length;n++)if(0===(r=t[n].trim()).indexOf("plural="))return r.substr(7)}(n["Plural-Forms"]||n["plural-forms"]||n.plural_forms),i=(0,r.A)(o)),a=this.pluralForms[e]=i),a(t)},i.prototype.dcnpgettext=function(e,t,n,r,o){var i,a,l;return i=void 0===o?0:this.getPluralForm(e,o),a=n,t&&(a=t+this.options.contextDelimiter+n),(l=this.data[e][a])&&l[i]?l[i]:(this.options.onMissingKey&&this.options.onMissingKey(n,e),0===i?n:r)}},3029:(e,t,n)=>{"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}n.d(t,{A:()=>r})},4467:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(9922);function o(e,t,n){return(t=(0,r.A)(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},2327:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(2284);function o(e,t){if("object"!=(0,r.A)(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=(0,r.A)(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}},9922:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(2284),o=n(2327);function i(e){var t=(0,o.A)(e,"string");return"symbol"==(0,r.A)(t)?t:t+""}},2284:(e,t,n)=>{"use strict";function r(e){return r="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},r(e)}n.d(t,{A:()=>r})}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}function r(e){return function(e){if(Array.isArray(e))return l(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||a(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e){return o="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},o(e)}function i(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=a(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,l=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){s=!0,i=e},f:function(){try{l||null==n.return||n.return()}finally{if(s)throw i}}}}function a(e,t){if(e){if("string"==typeof e)return l(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)?l(e,t):void 0}}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s=n(8095).validateField,c=n(4746),d=c.getRangeSettingsDefaults,u=c.validateNumberRangeSetting,f=c.validateStepSetting,m=c.validateRangeSettings;window.FrmFormsConnect=window.FrmFormsConnect||function(e,t,n){var r={messageBox:null,reset:null,setElements:function(){r.messageBox=e.querySelector(".frm_pro_license_msg"),r.reset=e.getElementById("frm_reconnect_link")}},o={init:function(){r.setElements(),n(e.getElementById("frm_deauthorize_link")).on("click",o.deauthorize),n(".frm_authorize_link").on("click",o.authorize),n(".frm-dashboard-license-options").on("click","#frm_deauthorize_link",o.deauthorize),n(".frm-dashboard-license-options").on("click","#frm_reconnect_link",o.reauthorize),null!==r.reset&&n(r.reset).on("click",o.reauthorize)},authorize:function(){var t=this,r=this.getAttribute("data-plugin"),i=e.getElementById("edd_".concat(r,"_license_key")),a=i.value,l=e.getElementById("proplug-wpmu");this.classList.add("frm_loading_button"),l=l&&l.checked?1:0,n.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_activate",license:a,plugin:r,wpmu:l,nonce:frmGlobal.nonce},success:function(e){o.afterAuthorize(e,i),t.classList.remove("frm_loading_button")}})},afterAuthorize:function(e,t){!0===e.success&&(t.value="•••••••••••••••••••"),wp.hooks.doAction("frm_after_authorize",e),o.showMessage(e)},showProgress:function(e){null===r.messageBox&&r.setElements();var t=r.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(n){null===r.messageBox&&r.setElements();var i=r.messageBox;!0===n.success&&(o.showAuthorized(!0),o.showInlineSuccess(),wp.hooks.doAction("frmAdmin.afterLicenseAuthorizeSuccess",{msg:n})),o.showProgress(n),""!==n.message&&(setTimeout(function(){i.innerHTML="",i.classList.add("frm_hidden"),i.classList.remove("frm_error_style","frm_message","frm_updated_message")},1e4),e.querySelector(".frm-admin-page-dashboard")&&setTimeout(function(){t.location.reload()},1e3))},showAuthorized:function(t){var n=t?"unauthorized":"authorized",r=t?"authorized":"unauthorized",o=e.querySelectorAll(".frm_".concat(n,"_box"));o.length&&o.forEach(function(e){e.className=e.className.replace("frm_".concat(n,"_box"),"frm_".concat(r,"_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>',n.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_reset_cache",plugin:"formidable_pro",nonce:frmGlobal.nonce},success:function(e){r.reset.textContent=e.message,"1"===r.reset.getAttribute("data-refresh")&&t.location.reload()}}),!1},deauthorize:function(){if(!confirm(frmGlobal.deauthorize))return!1;var t=this.getAttribute("data-plugin"),r=e.getElementById("edd_".concat(t,"_license_key")),i=r.value,a=this;return this.innerHTML='<span class="frm-wait frm_spinner" style="visibility:visible;"></span>',n.ajax({type:"POST",url:ajaxurl,data:{action:"frm_addon_deactivate",license:i,plugin:t,nonce:frmGlobal.nonce},success:function(){o.showAuthorized(!1),r.value="",a.replaceWith("Disconnected"),wp.hooks.doAction("frmAdmin.afterLicenseDeauthorizeSuccess",{})}}),!1}};return o}(document,window,jQuery),window.frmAdminBuildJS=function(){var e,t,a=frm_admin_js,l=frmDom,c=l.tag,_=l.div,p=l.span,g=l.a,v=l.svg,y=l.img,h=frmDom.util.onClickPreventDefault,b=frmDom.ajax.doJsonPost;a.contextualShortcodes=(t=null===(e=document.getElementById("frm_adv_info"))||void 0===e?void 0:e.dataset.contextualShortcodes)?((t=JSON.parse(t)).addressSelector="[id^=email_to], [id^=from_], [id^=cc], [id^=bcc]",t.bodySelector="[id^=email_message_]",t):[];var w,j,x,E={save:v({href:"#frm_save_icon"}),drag:v({href:"#frm_drag_icon",classList:["frm_drag_icon","frm-drag"]})},k=jQuery(document.getElementById("frm-show-fields")),Q=document.getElementById("new_fields"),S=document.getElementById("form_id"),A=!1,L=0,I=0,q=0,B={},C=0,N=wp.i18n,T=N.__,O=N.sprintf,F={dragging:!1};S&&(I=S.value);var D,M=new URL(window.location.href),P=M.searchParams,H=document.getElementById("frm_builder_page");function z(e){e.stopPropagation(),e.preventDefault(),R(this)}function R(e){var t=e.getAttribute("data-frmverify"),n=e.getAttribute("data-loaded-from");return null===t||"frm-confirmed-click"===e.id||("entries-list"===n?wp.hooks.applyFilters("frm_on_multiple_entries_delete",{link:e,initModal:Mi}):function(e){var t=Mi("#frm_confirm_modal","400px"),n=document.getElementById("frm-confirmed-click");if(!1===t)return!1;n&&(n.style.display="block");var r=e.getAttribute("data-frmverify"),o=r?e.getAttribute("data-frmverify-btn"):"",i=jQuery(".frm-confirm-msg");i.empty(),r&&(i.append(document.createTextNode(r)),o&&(null==n||n.classList.add(o)));var a=e.dataset;if(n){for(var l in n.dataset)n.removeAttribute("data-".concat(l));for(var s in a)"frmverify"!==s&&n.setAttribute("data-".concat(s),a[s])}return wp.hooks.doAction("frmAdmin.beforeOpenConfirmModal",{$info:t,link:e}),t.dialog("open"),null==n||n.setAttribute("href",e.getAttribute("href")||e.getAttribute("data-href")),!1}(e))}function G(e,t){var n=Mi("#frm_info_modal",t||"400px");if(!1===n)return!1;"string"==typeof e&&(e={msg:e}),e=Object.assign({title:"",msg:T("Are you sure?","formidable"),img:"",closeText:T("Got it!","formidable"),actionUrl:"",actionText:"",noCenter:!1},e);var r=n[0].querySelector(".info-modal-title");r.textContent=e.title||"",r.classList.toggle("frm_hidden",!e.title),e.msg&&(n[0].querySelector(".frm-info-msg").innerHTML=br(e.msg)),n[0].querySelector(".info-modal-img").src=e.img,n[0].querySelector(".info-modal-img-wrapper").classList.toggle("frm_hidden",!e.img);var o=document.getElementById("frm-info-click");e.closeText&&(o.textContent=e.closeText),o.classList.toggle("button-primary",!e.actionUrl),o.classList.toggle("frm-button-primary",!e.actionUrl),o.classList.toggle("button-secondary",Boolean(e.actionUrl)),o.classList.toggle("frm-button-secondary",Boolean(e.actionUrl));var i=n[0].querySelector(".info-modal-action-link");return e.actionUrl&&(i.href=e.actionUrl,e.actionText&&(i.textContent=e.actionText)),i.classList.toggle("frm_hidden",!e.actionUrl),n[0].querySelector(".info-modal-inside").classList.toggle("frmcenter",!e.noCenter),n[0].querySelector(".info-modal-buttons").classList.toggle("frmright",e.noCenter),n.dialog("open"),!1}function U(e){var t=this.getAttribute("data-frmtoggle"),n=this.getAttribute("data-toggletext"),r=jQuery(t);return e.preventDefault(),r.toggle(),null!==n&&""!==n&&(this.setAttribute("data-toggletext",this.innerHTML),this.textContent=n),!1}function W(e){var t=this.getAttribute("data-frmhide"),n=this.getAttribute("data-frmshow"),r=this.getAttribute("data-frmuncheck"),o=r?r.split(","):[];"INPUT"!==this.nodeName||"checkbox"!==this.type||this.checked||(null!==t?(n=t,t=null):null!==n&&(t=n,n=null)),e.preventDefault();var i=this.getAttribute("data-toggleclass")||"frm_hidden";null!==t&&jQuery(t).addClass(i),null!==n&&jQuery(n).removeClass(i);var a=this.parentNode.querySelectorAll("a.current");if(null!==a){for(var l=0;l<a.length;l++)a[l].classList.remove("current");this.classList.add("current")}return o.length&&o.forEach(function(e){var t=document.querySelector(e);t&&(t.checked=!1)}),!1}function $(){document.querySelectorAll(".tooltip").forEach(function(e){e.remove()})}function V(){var e,t,n;if(!parseInt(this.getAttribute("data-skip-frm-js"))&&!1!==R(this)){var r=jQuery(this),o=r.attr("data-removeid");void 0===(e=r.attr("data-showlast"))&&(e=""),void 0===(t=r.attr("data-hidelast"))&&(t=""),n=r.attr("data-removemore"),""!==e?r.closest(".frm_add_remove").find(".frm_remove_tag:visible").length>1&&(e="",t=""):0===o.indexOf("frm_postmeta_")&&(jQuery("#frm_postmeta_rows .frm_postmeta_row").length<2&&(e=".frm_add_postmeta_row.button"),jQuery(".frm_toggle_cf_opts").length&&jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().length&&(""!==e&&(e+=","),e+="#".concat(jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().attr("id")," .frm_toggle_cf_opts")));var a=document.getElementById(o),l=jQuery(a);return l.fadeOut(300,function(){var n;l.remove(),Vo(),""!==t&&(jQuery(t).hide(),function(e){var t=document.querySelector(e);if(t){var n,r=i(t.classList);try{for(r.s();!(n=r.n()).done;){var o=n.value,a=document.querySelector('input[data-toggleclass="'.concat(o,'"]'));if(null!=a&&a.checked)return void(a.checked=!1)}}catch(e){r.e(e)}finally{r.f()}}}(t)),""!==e&&jQuery("".concat(e," a,").concat(e)).removeClass("frm_hidden").fadeIn("slow"),this.closest(".frm_form_action_settings")&&function(e){var t;po(e),"payment"===e&&["stripe","square","paypal"].forEach(function(e){return po(e)}),document.querySelector(".frm_form_action_settings")||null===(t=document.querySelector(".frm-no-actions-message"))||void 0===t||t.classList.remove("frm_hidden");var n={type:e};wp.hooks.doAction("frm_after_action_removed",n)}(this.closest(".frm_form_action_settings").querySelector(".frm_action_name").value),null===(n=document.querySelector(".tooltip"))||void 0===n||n.remove()}),void 0!==n&&(n=jQuery(n)).fadeOut(400,function(){n.remove()}),""!==e&&jQuery(this).closest(".frm_logic_rows").fadeOut("slow"),wp.hooks.doAction("frm_admin_tag_removed",o,a),!1}}function K(){var e,t=document.querySelector("#frm-actions-filter-content .frm-action:not(.frm_hidden)");null===(e=document.getElementById("frm-actions-no-results"))||void 0===e||e.classList.toggle("frm_hidden",t)}function J(e,t){void 0===t&&(t=this),it(t,!1);var n=jQuery(t).closest(".frm_form_action_settings"),r=e.target;if(n.length&&void 0!==r){var o=r.parentElement.className;if("string"==typeof o&&(o.includes("frm_email_icons")||o.includes("frm_toggle")))return void e.stopPropagation()}var i=n.children(".widget-inside");if(n.length&&i.find("p, div, table").length<1){var a=n.find('input[name$="[ID]"]').val(),l=n.find('input[name$="[post_excerpt]"]').val();l&&(i.html('<span class="frm-wait frm_spinner"></span>'),n.find(".spinner").fadeIn("slow"),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_form_action_fill",action_id:a,action_type:l,nonce:frmGlobal.nonce},success:function(e){i.html(e),vi(),ro("#".concat(n.attr("id"))),ki(i),jQuery(t).trigger("frm-action-loaded"),wp.hooks.doAction("frm_filled_form_action",i)}}))}jQuery(t).closest(".frm_field_box").siblings().find(".widget-inside").slideUp("fast"),void 0!==t.className&&t.className.includes("widget-action")||jQuery(t).closest(".start_divider").length<1||((i=jQuery(t).closest("div.widget").children(".widget-inside")).is(":hidden")?i.slideDown("fast"):i.slideUp("fast"))}function X(){var e=this.getAttribute("href");if(null===e)return!1;var t=e.replace("#","."),n=jQuery(this);n.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab"),n.closest("div").children(".tabs-panel").not(e).not(t).hide();var r=document.getElementById(e.replace("#",""));return r&&(r.style.display="block"),"frm_insert_fields_tab"!==this.id||this.closest("#frm_adv_info")||et(),!1}function Y(e,t){var n=(e=jQuery(e)).attr("href");if(void 0!==n){var r,o,i=n.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(n).not(i).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&&(r=n.replace("#",""),(o=jQuery(".frm_".concat(r,"_ajax"))).length&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_settings_tab",tab:r.replace("_settings",""),nonce:frmGlobal.nonce},success:function(e){o.replaceWith(e)}}))}else jQuery("#frm-categorydiv .tabs-panel, .hide_with_tabs").hide();jQuery(n).show(),jQuery(i).show(),ni(),"auto"!==t&&(jQuery(".frm_updated_message").hide(),jQuery(".frm_warning_style:not(.frm_force_visible_warning)").hide()),jQuery(e).closest("#frm_adv_info").length||(jQuery(".frm_form_settings").length?jQuery(".frm_form_settings").attr("action","?page=formidable&frm_action=settings&id=".concat(jQuery('.frm_form_settings input[name="id"]').val(),"&t=").concat(n.replace("#",""))):jQuery(".frm_settings_form").attr("action","?page=formidable-settings&t=".concat(n.replace("#",""))))}}function Z(e){var t,n;document.querySelectorAll(e).forEach(function(e){ee(e),Array.from(e.children).forEach(function(e){return re(e,".frm-move")});var t=jQuery(e).children('[data-type="divider"]').children(".divider_section_only");t.length&&ee(t)}),t=jQuery("#frm_builder_page"),n={items:".frm_sortable_field_opts li",axis:"y",opacity:.65,forcePlaceholderSize:!1,handle:".frm-drag",helper:function(e,t){return A=t.clone().insertAfter(t),t.clone()},stop:function(e,t){A&&A.remove(),ur(t.item.attr("id").replace("frm_delete_field_","").replace("-".concat(t.item.data("optkey"),"_container"),"")),Vo()}},jQuery(t).sortable(n)}function ee(e){jQuery(e).droppable({accept:".frmbutton, li.frm_field_box",deactivate:se,over:te,out:ne,tolerance:"pointer"})}function te(e,t){var n=function(e){return e.classList.contains("divider_section_only")&&(e=jQuery(e).nextAll(".start_divider.frm_sorting").get(0)),e}(e.target);if(!Se(t.draggable[0],n,e))return n.classList.remove("frm-over-droppable"),void jQuery(n).parents("ul.frm_sorting").addClass("frm-over-droppable");document.querySelectorAll(".frm-over-droppable").forEach(function(e){return e.classList.remove("frm-over-droppable")}),n.classList.add("frm-over-droppable"),jQuery(n).parents("ul.frm_sorting").addClass("frm-over-droppable")}function ne(e){e.target.classList.remove("frm-over-droppable")}function re(e,t){var n={helper:oe,revert:"invalid",delay:10,start:ie,stop:ae,drag:le,cursor:"grabbing",refreshPositions:!0,cursorAt:{top:0,left:90}};"string"==typeof t&&(n.handle=t),jQuery(e).draggable(n)}function oe(e){var t,n=e.delegateTarget;if(Le(n)){var r=document.getElementById("frm-insert-fields").querySelector(".frm_ttext").cloneNode(!0);return r.querySelector("use").setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_field_group_layout_icon"),r.querySelector("span").textContent=T("Field Group","formidable"),r.classList.add("frm_field_box"),r.classList.add("ui-sortable-helper"),r}if(n.classList.contains("frmbutton"))return(t=n.cloneNode(!0)).classList.add("ui-sortable-helper"),n.classList.add("frm-new-field"),t;if(n.hasAttribute("data-ftype")){var o=n.getAttribute("data-ftype");if(t=document.getElementById("frm-insert-fields").querySelector(".frm_t".concat(o)))return(t=t.cloneNode(!0)).classList.add("form-field"),t.classList.add("ui-sortable-helper"),t.cloneNode(!0)}return _({className:"frmbutton"})}function ie(e,t){if(e.target.classList.contains("frm_at_limit"))return Ne(),!1;F.dragging=!0;var n,r=j;r.classList.add("frm-dragging-field"),document.body.classList.add("frm-dragging"),t.helper.addClass("frm-sortable-helper"),t.helper.initialOffset=r.scrollTop,e.target.classList.add("frm-drag-fade"),En(),(n=document.querySelectorAll("ul.start_divider")).length&&n.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()})}),Re(),Pe(),$()}function ae(){j.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 le(e,t){!function(e){x.scrollTop(function(t,n){var r=e.clientY,o=j.offsetHeight,i=e.clientY-j.offsetTop,a=i-o/2;return i>o-50&&r>5?n+.1*a:i<70&&r<130?n-Math.abs(.1*a):n})}(e);var n=e.target,r=function(){for(var e=document.getElementById("frm-show-fields");e.querySelector(".frm-over-droppable");)e=e.querySelector(".frm-over-droppable");return"frm-show-fields"!==e.id||e.classList.contains("frm-over-droppable")||(e=!1),e}(),o=document.getElementById("frm_drag_placeholder");if(Se(n,r,e)){o||(o=c("li",{id:"frm_drag_placeholder",className:"sortable-placeholder"}));var i,a=t.helper.get(0);if((a.classList.contains("form-field")||a.classList.contains("frm_field_box"))&&(a.style.transform="translateY(".concat((i=t.helper,j.scrollTop-i.initialOffset),"px)")),"frm-show-fields"===r.id||r.classList.contains("start_divider"))return o.style.left=0,void function(e){var t,n=e.y,r=e.placeholder,o=jQuery(e.droppable),i=o.children().not(".edit_field_type_end_divider");if(0===i.length)o.prepend(r),t=0;else{var a=ce(o,n);if(a===i.length){var l=jQuery(i.get(a-1));t=l.offset().top+l.outerHeight(),o.append(r);var s=o.children(".edit_field_type_end_divider");s.length&&o.append(s)}else t=jQuery(i.get(a)).offset().top,jQuery(i.get(a)).before(r)}t-=o.offset().top,r.style.top="".concat(t,"px")}({droppable:r,y:e.clientY,placeholder:o});o.style.top="",function(e){var t,n=e.x,r=e.placeholder,o=jQuery(e.droppable),i=ue(o);if(i.length){var a=function(e,t){var n,r,o,i,a=ue(e);for(i=0,n=a.length-1;n>=0;--n)if(r=a.get(n),t>(o=jQuery(r).offset().left)){i=n,t>o+jQuery(r).outerWidth()/2&&(i=n+1);break}return i}(o,n);if(a===i.length){var l=jQuery(i.get(a-1));t=l.offset().left+l.outerWidth(),o.append(r)}else t=jQuery(i.get(a)).offset().left,jQuery(i.get(a)).before(r),t-=0===a?4:8;t-=o.offset().left,r.style.left="".concat(t,"px")}}({droppable:r,x:e.clientX,placeholder:o})}else o&&o.remove()}function se(e,t){if(F.dragging){F.dragging=!1;var n=t.draggable[0],r=document.getElementById("frm_drag_placeholder");if(!r)return t.helper.remove(),void w();!function(e){if(e.previousElementSibling&&e.previousElementSibling.classList.contains("frm-is-collapsed")){var t=jQuery(e).prevUntil('[data-type="break"]');if(t.length){var n=t.find(".frm-collapse-page").get(0);n&&n.click()}}}(r);var o=t.helper.parent(),i=t.helper.get(0).closest("ul.start_divider"),a=r.closest("ul.start_divider");n.classList.contains("frm-new-field")?function(e){if(we(e))wp.hooks.doAction("frm_stopped_inserting_by_dragging",e);else{var t=document.getElementById("frm_drag_placeholder"),n="".concat(e.replace("|","-"),"_").concat(Qe()),r=c("li",{id:n,className:"frm-wait frmbutton_loadingnow"}),o=jQuery(r),i=ge(jQuery(t)),a=ve(i),l=ye(i);t.parentNode.insertBefore(r,t),t.remove(),fe(o);var s=0;"summary"===e&&(s=jQuery(".frmbutton_loadingnow#".concat(n)).prevAll('li[data-type="break"]').length?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:be(e,l,a,s),success:function(t){je(t,o);var n=xe(t);n&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:n,fieldType:e,form_id:a})},error:ke})}}(n.id):(function(e,t){t.parentNode.insertBefore(e,t)}(n,r),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")&&re(t,".frm-move")}}(r.parentElement));var l=i?parseInt(i.closest(".edit_field_type_divider").getAttribute("data-fid")):0,s=a?parseInt(a.closest(".edit_field_type_divider").getAttribute("data-fid")):0;r.remove(),t.helper.remove();var d=o.length?ue(o):[];!function(e,t){var n;e.length&&(t.length?fe(t.first()):(n=e.get(0).closest("li.frm_field_box"))&&!n.classList.contains("edit_field_type_divider")&&n.remove())}(o,d),function(e,t){0===t.length&&1===ue(jQuery(e.parentNode)).length||fe(jQuery(e))}(n,d),l!==s&&he(jQuery(n),i),w()}}function ce(e,t){var n,r,o,i,a=e.children().not(".edit_field_type_end_divider"),l=a.length;if(!document.querySelector(".frm-has-fields .frm_no_fields"))return 0;for(i=0,n=l-1;n>=0;--n)if(r=a.get(n),t>(o=jQuery(r).offset().top)){i=n,t>o+jQuery(r).outerHeight()/2&&(i=n+1);break}return i}function de(){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")&&Xe(e))})}),Br(),document.querySelectorAll(".edit_field_type_end_divider").forEach(function(e){return e.parentNode.append(e)}),document.querySelectorAll("li.form_field_box:not(.form-field)").forEach(function(e){return!e.children.length&&e.remove()}),qr();var e=new Event("frm_sync_after_drag_and_drop",{bubbles:!1});document.dispatchEvent(e)}function ue(e){var t=jQuery(),n=e.get(0);return n.children?(Array.from(n.children).forEach(function(e){if("none"!==e.style.display){var n=e.classList;!n.contains("form-field")||n.contains("edit_field_type_end_divider")||n.contains("frm-sortable-helper")||(t=t.add(e))}}),t):t}function fe(e,t){var n;void 0===t&&(t="even");var r=e.parent().children("li.form-field, li.frmbutton_loadingnow").not(".edit_field_type_end_divider"),o=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!==o?r.each(pe(i,en(o))):"clear"===t?r.each(pe(i,"")):(n=["left","right","middle","even"].includes(t)?function(e){return Zt(o,t,e)}:function(e){return _n(t[e])},r.each(pe(i,n))),me(e.parent(),r.length)}function me(e,t){if(void 0!==e.offset()){var n=t>=2,r=document.getElementById("frm_field_group_controls");if(!r){if(!n)return;(r=_()).id="frm_field_group_controls",r.setAttribute("role","group"),r.setAttribute("tabindex",0),function(e){var t=document.createElement("span");t.innerHTML='<svg class="frmsvg"><use href="#frm_field_group_layout_icon"></use></svg>';var n=T("Set Row Layout","formidable");_e(t,n),Vt(t,n);var r=document.createElement("span");r.innerHTML='<svg class="frmsvg"><use href="#frm_thick_move_icon"></use></svg>',r.classList.add("frm-move");var o=T("Move Field Group","formidable");_e(r,o),Vt(r,o),e.innerHTML="",e.append(t),e.append(r),e.append(function(){var e=p({className:"dropdown"}),t=g({className:"frm_bstooltip frm-hover-icon frm-dropdown-toggle dropdown-toggle",children:[p({child:v({href:"#frm_thick_more_vert_icon"})}),p({className:"screen-reader-text",text:T("Toggle More Options Dropdown","formidable")})]});frmDom.setAttributes(t,{title:T("More Options","formidable"),"data-bs-toggle":"dropdown","data-bs-container":"body","data-bs-display":"static"}),Vt(t,T("More Options","formidable")),e.append(t);var n=_({className:"frm-dropdown-menu dropdown-menu dropdown-menu-right"});return n.setAttribute("role","menu"),e.append(n),e}())}(r),H.append(r)}e.append(r),r.style.display=n?"block":"none"}}function _e(e,t){e.setAttribute("data-bs-toggle","tooltip"),e.setAttribute("data-bs-container","body"),e.setAttribute("title",t),e.addEventListener("mouseover",function(){e.__bootstrapTooltip||(e.__bootstrapTooltip=new bootstrap.Tooltip(e))})}function pe(e,t){return function(n){for(var r="function"==typeof t?t(n):t,o=e.length,i=!1,a=0;a<o;++a){var l=e[a];if(this.classList.contains(l)){i=l;break}}var s=this.dataset.fid;if(void 0!==s){uo(document.getElementById("frm-single-settings-".concat(s)));var c=document.getElementById("frm_classes_".concat(s));c&&(!1===i?""!==r&&(c.value=c.value.concat(" ".concat(r))):(this.classList.remove(i),c.value=c.value.replace(i,r)),this.classList.contains("frm_first")&&(this.classList.remove("frm_first"),c.value=c.value.replace("frm_first","").trim()),0===n&&(this.classList.add("frm_first"),c.value=c.value.concat(" frm_first")),jQuery(c).trigger("change"))}else this.classList.add(r)}}function ge(e){var t="";return void 0===e||e.hasClass("edit_field_type_divider")||(t=e.closest(".edit_field_type_divider")),t}function ve(e){var t="";if(void 0!==e[0]){var n=e.children(".start_divider");if(n.children(".edit_field_type_end_divider").appendTo(n),void 0!==e.attr("data-formid")){var r=e.attr("data-fid");t=jQuery('input[name="field_options[form_select_'.concat(r,']"]')).val()}}return void 0!==t&&""!==t||(t=I),t}function ye(e){var t=0;return void 0!==e[0]&&(t=e.attr("id").replace("frm_field_id_","")),t}function he(e,t){if(e.hasClass("form-field")){var n=e.attr("id").replace("frm_field_id_",""),r=ge(e),o=ve(r),i=ye(r),a=t?ve(jQuery(t.parentNode)):0;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_update_field_after_move",form_id:o,field:n,section_id:i,previous_form_id:a,nonce:frmGlobal.nonce},success:function(){Br(),function(e,t){document.getElementById("frm_in_section_".concat(e)).value=t}(n,i)}})}else ue(jQuery(e.get(0).firstChild)).each(function(){he(jQuery(this),t)})}function be(e,t,n,r){var o={action:"frm_insert_field",form_id:n,field_type:e,section_id:t,nonce:frmGlobal.nonce,has_break:r};return t>0&&document.getElementById("form_id").value!==n||(o.last_row_field_ids=function(){var e=document.querySelector(".edit_field_type_submit");if(!e)return[];for(var t=e.parentNode.children,n=[],r=0;r<t.length;r++)n.push(t[r].dataset.fid);return n}()),o}function we(e){return wp.hooks.applyFilters("frm_should_stop_inserting_field",!1,e)}function je(e,t){var n;document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var r=t.siblings("li.form-field").not(".edit_field_type_end_divider");r.length?(n=Ee(e),t.get(0).parentNode.parentNode.classList.contains("ui-draggable")||re(t.get(0).parentNode.parentNode,".frm-move")):n=Je(e),t.replaceWith(n),qr(),Ye(e,!1),r.length&&fe(r.first()),Br(),r.length?re(n.get(0),".frm-move"):(ee(n.get(0).querySelector("ul.frm_sorting")),re(n.get(0).querySelector("li.form-field"),".frm-move"))}function xe(e){var t=e.match(/data-fid="(\d+)"/);return t?parseInt(t[1]):0}function Ee(e){var t=_();return t.innerHTML=e,jQuery(t.firstChild)}function ke(e,t,n){!function(e,t){(function(e){return 0===e.status||0===e.readyState})(t)||G("".concat(e,". Please try again."))}(n,e)}function Qe(){return++q}function Se(e,t,n){if(!1===t)return!1;if(t.closest(".frm-sortable-helper"))return!1;var r=e.classList.contains("edit_field_type_submit"),o=!e.classList.contains("form_field")&&Boolean(e.querySelector(".edit_field_type_submit"));if("frm-show-fields"===t.id){var i=ce(jQuery(t),n.clientY);return r||o?i>t.childElementCount-1:i<=jQuery(t.querySelector(".edit_field_type_submit").closest("#frm-show-fields > li")).index()}if(r)return!(t.classList.contains("start_divider")||!Ae(t.parentElement)&&(!Ae(t.parentElement.nextElementSibling)||e.parentElement.querySelector("li.frm_field_box:not(.edit_field_type_submit)")));var a=t.classList.contains("start_divider")&&null!==t.closest(".repeat_section"),l=null!==t.closest(".repeat_section");if(a||l){if(e.classList.contains("edit_field_type_gdpr")||"gdpr"===e.id)return!1;if(wp.hooks.applyFilters("frm_deny_drop_in_repeater",!1,e))return!1}if(!a){if(!function(e,t){if(e.length<12)return!0;if(e.length>12)return!1;var n=t.attr("data-fid");return 1===jQuery(e).filter('[data-fid="'.concat(n,'"]')).length}(ue(jQuery(t)),jQuery(e)))return!1;if("divider"===e.id&&t.closest(".start_divider"))return!1}return e.classList.contains("frm-new-field")?function(e,t){var n=e.classList,r=n.contains("frm_tbreak"),o=n.contains("frm_thidden"),i=n.contains("frm_tdivider"),a=n.contains("frm_tform"),l=n.contains("frm_tuser_id");return"frm-show-fields"===t.id||t.classList.contains("start_divider")?!(r||o||i||a)||(!(t.classList.contains("start_divider")||null!==t.closest(".start_divider"))||!a&&!i):!(Ie(t)||o||r||l)}(e,t):function(e,t){if(Le(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 n=e.classList.contains("edit_field_type_hidden"),r=e.classList.contains("edit_field_type_user_id");return!n&&!r&&function(e,t){if(Ie(t))return!1;if(jQuery(e).children("ul.frm_sorting").not(".start_divider").length>0)return!1;var n=e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"),r=e.classList.contains("edit_field_type_form");return!(null!==t.closest(".start_divider")&&(n||r))}(e,t)}(e,t)}function Ae(e){return null==e?void 0:e.matches("#frm-show-fields > li:last-child")}function Le(e){return e.classList.contains("frm_field_box")&&!e.classList.contains("form-field")}function Ie(e){return null!==e.querySelector(".edit_field_type_break, .edit_field_type_hidden, .edit_field_type_user_id")}function qe(e){var t=document.getElementById(e),n=jQuery(t),r=[],o=function(e){var t=e.querySelector(".frm_hidden_fdata");e.classList.add("frm_load_now"),null!==t&&r.push(t.innerHTML)};o(t);for(var i=Be(t);i&&r.length<15;)o(i),i=Be(i);jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_load_field",field:r,form_id:I,nonce:frmGlobal.nonce},success:function(e){return function(e,t,n){var r,o;if(0===(e=e.replace(/^\s+|\s+$/g,"")).indexOf("{")){for(r in e=JSON.parse(e))if(Object.hasOwn(e,r)){jQuery("#frm_field_id_".concat(r)).replaceWith(e[r]);var i=document.getElementById("frm_field_id_".concat(r));i&&(i.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),i.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")})),Z("#frm_field_id_".concat(r,".edit_field_type_divider ul.frm_sorting")),re(document.getElementById("frm_field_id_".concat(r)))}((o=t.nextAll(".frm_field_loading:not(.frm_load_now)")).length||(o=jQuery(document.getElementById("frm-show-fields")).find(".frm_field_loading:not(.frm_load_now)")).length)&&qe(o.attr("id")),vi(),Gn(),Oe();var a=new Event("frm_ajax_loaded_field",{bubbles:!1});a.frmFields=n.map(function(e){return JSON.parse(e)}),document.dispatchEvent(a)}else jQuery(".frm_load_now").removeClass(".frm_load_now").html("Error")}(e,n,r)}})}function Be(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 Ce(){var e=jQuery(this);if(e.hasClass("disabled"))return!1;var t=e.closest(".frmbutton"),n=t.attr("id");if(t.hasClass("frm_at_limit"))return Ne(),!1;if(frm_admin_js.paymentsSettingsModal&&"object"===o(frm_admin_js.paymentsSettingsModal)&&["product","quantity","total"].includes(n))return G(frm_admin_js.paymentsSettingsModal),!1;if(!we(n)){var r=0;"summary"===n&&(r=k.children('li[data-type="break"]').length>0?1:0);var i=I;return jQuery.ajax({type:"POST",url:ajaxurl,data:be(n,0,i,r),success:function(e){Te(e);var t=xe(e);t&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:e,fieldId:t,fieldType:n,form_id:i})},error:ke}),!1}}function Ne(){var e=document.querySelector(".frm_wrap");if(e){var t=document.createElement("a");t.setAttribute("data-frmverify",T("This field type has reached its limit.","formidable")),e.append(t),t.click(),t.remove();var n=document.getElementById("frm-confirmed-click");n&&(n.style.display="none")}}function Te(e){document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var t=Je(e),n=k[0].querySelector(".edit_field_type_submit");n?jQuery(n.closest(".frm_field_box:not(.form-field)")).before(t):k.append(t),Ye(e,!0),t.each(function(){ee(this.querySelector("ul.frm_sorting")),re(this.querySelector(".form-field"),".frm-move")})}function Oe(){var e=!0,t=document.querySelectorAll(".frmjs_prod_field_opt_cont");k.find("li.edit_field_type_product").length>1&&(e=!1);for(var n=0;n<t.length;n++)t[n].classList.toggle("frm_hidden",e)}function Fe(){var e=jQuery(this).closest("li.form-field"),t=this.getAttribute("frm-target-row-id");if(null!=t&&t.startsWith("frm_field_group_")||function(e){if(e.classList.contains("frm-page-collapsed"))return!1;var t=e.closest("li.frm_field_box:not(.form-field)");return!t||ue(jQuery(t.querySelector("ul"))).length<12}(e.get(0))){Pe();var n,r=e.data("fid"),o=function(e){var t=[];return jQuery(document.getElementById("frm_field_id_".concat(e))).find("li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)").each(function(){t.push(jQuery(this).data("fid"))}),t}(r);return null!==t&&(n=this.getAttribute("frm-field-order")),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_duplicate_field",field_id:r,form_id:I,children:o,nonce:frmGlobal.nonce},success:function(o){var i,a,l;if(null!==t&&(a=document.getElementById(t)))return l=Ee(o),jQuery(a).append(l),re(l.get(0),".frm-move"),null!==n&&a.lastElementChild.setAttribute("frm-field-order",n),jQuery(a).trigger("frm_added_duplicated_field_to_row",{duplicatedFieldHtml:o,originalFieldId:r}),Ye(o,!1),void De(e.get(0),l.get(0));e.siblings("li.form-field").length?(l=Ee(o),e.after(l),fe(e),re(l.get(0),".frm-move")):(l=Je(o),e.parent().parent().after(l),ee(l.get(0).querySelector("ul.frm_sorting")),re(l.get(0).querySelector("li.form-field"),".frm-move")),qr(),Ye(o,!1),Me(r,o),Cr(l.find(".start_divider")),null===(i=e[0].querySelector(".frm-dropdown-menu.dropdown-menu-right"))||void 0===i||i.classList.remove("show"),De(e.get(0),l.get(0))}}),!1}G(O(T("You can only have a maximum of %1$d fields in a field group. Delete or move out a field from the group and try again.","formidable"),12))}function De(e,t){var n,r=e.closest(".frm-field-group-hover-target");if(r&&Le(r.parentElement)){var o=e.dataset.fid,i=null===(n=document.getElementById("frm_classes_".concat(o)))||void 0===n?void 0:n.value;if(i&&(i=i.replace("frm_first",""),!t.className.includes(i))){t.className+=" ".concat(i);var a=document.getElementById("frm_classes_".concat(t.dataset.fid));a&&(a.value=i)}}}function Me(e,t){var n=document.getElementById("frm-single-settings-".concat(e));if(n){var r=jQuery(t).attr("data-fid");if(void 0!==r){var o=document.getElementById("frm-single-settings-".concat(r));if(o){var i=["name","required","unique","read_only","placeholder","description","size","max","format","prepend","append","separate_value"];n.querySelectorAll('input[name^="field_options["], textarea[name^="field_options["]').forEach(function(t){var n,a=((n=t.name.substr(14).split("_")).pop(),n.join("_"));if("options"!==a){if(i.includes(a)){var l=t.matches("input")?"input":"textarea",s=o.querySelector("".concat(l,'[name="field_options[').concat(a,"_").concat(r,']"]'));null!==s&&("checkbox"===t.type?t.checked!==s.checked&&jQuery(s).trigger("click"):"text"!==t.type&&"textarea"!==l||t.value!==s.value&&(s.value=t.value,jQuery(s).trigger("change")))}}else!function(e,t,n,r){var o=e.name.substr(23+"".concat(n).length),i="field_options[options_".concat(r,"]").concat(o),a=t.querySelector('input[name="'.concat(i,'"]'));null!==a&&a.value!==e.value&&(a.value=e.value,jQuery(a).trigger("change"))}(t,o,e,r)});var a=n.querySelector('input[name="default_value_'.concat(e,'"]'));if(null!==a){var l=o.querySelector('input[name="default_value_'.concat(r,'"]'));null!==l&&a.value!==l.value&&(l.value=a.value,jQuery(l).trigger("change"))}}}}}function Pe(){var e=document.querySelector(".frm-field-settings-open");e&&(e.classList.remove("frm-field-settings-open"),jQuery(document).off("click","#frm_builder_page",He),jQuery(".frm-field-action-icons .dropdown.open").removeClass("open"))}function He(e){jQuery(e.originalEvent.target).closest(".frm-field-action-icons").length||Pe()}function ze(e){var t=Boolean(e.ctrlKey||e.metaKey||e.shiftKey);jQuery(H).toggleClass("frm-multiselect-key-is-down",t),function(e){if(!j.classList.contains("frm-dragging-field")&&null===document.querySelector(".frm-field-group-hover-target .frm-field-settings-open")){var t=document.elementFromPoint(e.clientX,e.clientY);if(null!==t&&!t.classList.contains("edit_field_type_divider")){var n=t.closest("ul.frm_sorting");if(null!==n&&!n.classList.contains("start_divider")&&"frm-show-fields"!==n.id){var r=Re();!1===r||jQuery(r).is(n)||yn(),me(jQuery(n),ue(jQuery(n)).length),n.classList.add("frm-field-group-hover-target"),jQuery("#wpbody-content").on("mousemove",Ge)}}}}(e)}function Re(){var e=document.getElementById("frm_field_group_controls");e&&(e.style.display="none");var t=document.querySelector(".frm-field-group-hover-target");return!!t&&(jQuery("#wpbody-content").off("mousemove",Ge),t.classList.remove("frm-field-group-hover-target"),t)}function Ge(e){var t=document.elementFromPoint(e.clientX,e.clientY);null!==t&&null!==t.closest("#frm-show-fields")||(Re(),$())}function Ue(e){En(),setTimeout(function(){var t=document.querySelector(".dropdown .frm-dropdown-menu.show");if(t){null===t.getAttribute("aria-label")&&t.setAttribute("aria-label",T("More Options","formidable")),0===t.children.length&&function(e,t){var n=t?"_field_group":"_field",r=[Ve(t),Ke(t)];t||r.push({class:"frm_select",icon:"frm_settings_icon",label:T("Field Settings","formidable")}),r.forEach(function(t){var r=document.createElement("div");r.classList.add("frm_more_options_li","dropdown-item");var o=document.createElement("a");o.classList.add(t.class+n),o.setAttribute("href","#"),Vt(o);var i=document.createElement("span");i.textContent=t.label,o.innerHTML='<svg class="frmsvg"><use href="#'.concat(t.icon,'"></use></svg>'),o.append(document.createTextNode(" ")),o.append(i),r.append(o),e.append(r)})}(t,!0===e);var n=jQuery(t);n.offset().left>jQuery(window).width()-n.outerWidth()?t.style.left="".concat(-n.outerWidth(),"px"):j&&n.offset().left<j.getBoundingClientRect().left&&(t.style.right="auto",t.style.left="0");var r=t.firstElementChild.querySelector("a");r&&r.focus()}},0)}function We(){Ue(!0)}function $e(e){var t=e.target.closest(".frm-section-collapsed");t&&("show"===e.type?t.style.zIndex=3:t.style.zIndex=1)}function Ve(e){var t={class:"frm_delete",icon:"frm_delete_icon"};return t.label=T(e?"Delete Group":"Delete","formidable"),t}function Ke(e){var t={class:"frm_clone",icon:"frm_clone_icon"};return t.label=T(e?"Duplicate Group":"Duplicate","formidable"),t}function Je(e){var t=_();"string"==typeof e?t.innerHTML=e:t.append(e);var n=jQuery();return Array.from(t.children).forEach(function(e){n=n.add(jQuery("<li>").addClass("frm_field_box").html(jQuery("<ul>").addClass("frm_grid_container frm_sorting").append(e)))}),n}function Xe(e){var t=c("ul",{className:"frm_grid_container frm_sorting"}),n=c("li",{className:"frm_field_box",child:t});e.replaceWith(n),t.append(e),ee(t),re(n,".frm-move")}function Ye(e,t){var n,r,i=/id="(\S+)"/.exec(e),a=document.getElementById(i[1]),l="#".concat(i[1],".edit_field_type_divider ul.frm_sorting.start_divider"),s=jQuery(l),c=a.getAttribute("data-type");n=e,(r=_()).innerHTML=n,r.querySelectorAll(".form-field").forEach(Ze);var d,u,f=!1;if(Vo(),Z(l),"quantity"===c&&function(e){var t=e.getAttribute("data-fid"),n=document.getElementById("field_options[product_field_".concat(t,"]"));n&&(st(n),uo(document.getElementById("frm-single-settings-".concat(t))))}(a),"product"!==c&&"quantity"!==c||Oe(),s.length)s.parent(".frm_field_box").children(".frm_no_section_fields").addClass("frm_block");else{var m=jQuery(a).closest("ul.frm_sorting.start_divider");m.length&&(Cr(m),f=!0)}e.includes("frm-collapse-page")&&Gn(),u="frm-newly-added",(d=a).classList?d.classList.add(u):d.className+=" ".concat(u),setTimeout(function(){a.classList.remove("frm-newly-added")},1e3);var p,g=a.querySelector("#frm-last-row-fields-order");if(g&&((p=JSON.parse(g.value))&&"object"===o(p)&&Object.keys(p).forEach(function(e){var t=document.querySelector('input[name="field_options[field_order_'.concat(e,']"]'));t&&(t.value=p[e])})),t){var v=a.getBoundingClientRect(),y=document.getElementById("post-body-content");v.top>=0&&v.left>=0&&v.right<=(window.innerWidth||document.documentElement.clientWidth)&&v.bottom<=(window.innerHeight||document.documentElement.clientHeight)||y.scroll({top:y.scrollHeight,left:0,behavior:"smooth"}),!1===f&&Cr(s)}tt(),vi(),document.getElementById("frm-show-fields").classList.remove("frm-over-droppable"),function(e){var t=document.getElementById(e);null!=t&&t.dataset.limit&&Cn(e)>=t.dataset.limit&&t.classList.add("frm_at_limit")}(c),a.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),a.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")});var h=new Event("frm_added_field",{bubbles:!1});h.frmField=a,h.frmSection=l,h.frmType=c,h.frmToggles=f,document.dispatchEvent(h)}function Ze(e){if(e.dataset.fid){var t=document.getElementById("draft_fields");t&&(""===t.value?t.value=e.dataset.fid:t.value.split(",").includes(e.dataset.fid)||(t.value+=",".concat(e.dataset.fid)))}}function et(e){jQuery("#new_fields .frm-single-settings").addClass("frm_hidden"),jQuery("#frm-options-panel > .frm-single-settings").removeClass("frm_hidden"),tt(e)}function tt(e){jQuery("li.ui-state-default.selected").removeClass("selected"),jQuery(".frm-show-field-settings.selected").removeClass("selected"),e||En()}function nt(){var e=this.value,t=function(e){var t,n=[],r=e.split(""),o=r.length,i=["{","[","("],l={"}":"{",")":"(","]":"["},s=!1;for(t=0;t<o;t++)i.includes(r[t])?n.push(r[t]):Object.hasOwn(l,r[t])&&n.pop()!==l[r[t]]&&(s=!0);return n.length>0||s?"".concat(a.unmatched_parens,"\n\n"):""}(e);t+=function(e,t){var n=function(e,t){var n="";return function(e){return jQuery(e).siblings('label[for^="calc_type"]').children("input").prop("checked")}(t)||/\[(date|time|email|ip)\]/.test(e)&&(n="".concat(a.text_shortcodes,"\n\n")),n}(e,t);return n+=function(e){var t="";return/\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g.test(e)&&(t+="".concat(a.view_shortcodes,"\n\n")),t}(e)}(e,this),""!==t&&G("".concat(e,"\n\n").concat(t))}function rt(e,t){for(var n=!1,r=0;r<t.length;r++){var o=document.getElementsByName(ot(t[r],e.fieldId));if(o.length&&jQuery(o[0]).val()){n=!0;break}}return n}function ot(e,t){var n=e.indexOf("]");return"field_options".concat(e.substring(0,n),"_").concat(t).concat(e.substring(n))}function it(e,t){var n=jQuery(e).closest(".frm-single-settings"),r=n.find(".frm-calc-field");if(t||r.length&&""!==r.val()&&!r.is(":hidden")){var o=function(e){var t=jQuery(e).find(".frm_code_list");return 1===t.length&&t.hasClass("frm_js_summary_list")}(e),i=n.find('input[name="frm_fields_submitted[]"]').val(),a=function(e,t){var n=e.querySelector(".frm_code_list"),r=JSON.parse(n.getAttribute("data-exclude"));if(t){var o=function(){for(var e=[],t=document.getElementsByClassName("frm_include_extras_field"),n=0;n<t.length;n++)t[n].checked&&e.push(t[n].value);return e}();if(o.length)for(var i=0;i<r.length;i++)o.includes(r[i])&&(r.splice(i,1),i--)}return r}(t?e:document.getElementById("frm-calc-box-".concat(i)),o),l=function(e){var t=[];if(!Array.isArray(e))return t;for(var n=0;n<e.length;n++)e[n].startsWith("[")&&(t.push(e[n]),e.splice(n,1),n--);return t}(a),s=lt(),c=document.getElementById("frm-calc-list-".concat(i));c.innerHTML="";for(var d=0;d<s.length;d++)if(!(null!=a&&a.includes(s[d].fieldType)||l.length&&rt(s[d],l))){var u=document.createElement("a");u.setAttribute("href","#"),u.setAttribute("data-code",s[d].fieldId),u.classList.add("frm_insert_code"),u.append(p(s[d].fieldName)),u.append(p({className:"frm-text-sm frm-text-grey-500",text:"[".concat(s[d].fieldId,"]")}));var f=document.createElement("li");f.classList.add("frm-field-list-".concat(i)),f.classList.add("frm-field-list-".concat(s[d].fieldType)),f.append(u),c.append(f)}}}function at(){it(jQuery(".frm-inline-modal.postbox:has(.frm_js_summary_list)")[0],!0)}function lt(e){var t,n=[],r=document.querySelectorAll("li.frm_field_box"),o=void 0!==e;for(t=0;t<r.length;t++)if(!o||r[t].getAttribute("data-ftype")===e){var i=r[t].getAttribute("data-fid");i&&n.push({fieldId:i,fieldName:dt("frm_name_".concat(i)),fieldType:dt("field_options_type_".concat(i)),fieldKey:dt("field_options_field_key_".concat(i))})}return wp.hooks.applyFilters("frm_admin_get_field_list",n,e,r)}function st(e){var t,n,r,o=[],i=function(e){for(var t=e.querySelectorAll('[type="checkbox"]:checked'),n=[],r=0;r<t.length;r++)n.push(t[r].value);return n}(e),a=e.getAttribute("data-frmfname"),l=lt("product"),s=lt("quantity"),c="SELECT"===e.tagName,d=1===s.length&&1===l.length;for(c&&(i=e.getAttribute("data-frmcurrent")),t=0;t<l.length;t++)r=l[t].fieldId.toString(),n=d||i.includes(r),c?(n=n?" selected":"",o.push('<option value="'.concat(r,'"').concat(n,">").concat(l[t].fieldName,"</option>"))):(n=n?" checked":"",o.push('<label class="frm6">'),o.push('<input type="checkbox" name="'.concat(a,'" value="').concat(r,'"').concat(n,"> ").concat(l[t].fieldName)),o.push("</label>"));e.innerHTML=o.join("")}function ct(){for(var e=document.querySelectorAll(".frmjs_prod_field_opt"),t=0;t<e.length;t++)st(e[t])}function dt(e){var t=document.getElementById(e);return t?t.value:""}function ut(){var e,t,n,r,o,i,a,l,s,c=this.value,d=document.getElementById(this.getAttribute("data-changeme")),u=this.getAttribute("data-changeatt");d&&(null!==u?"SELECT"===d.tagName&&"placeholder"===u?""===(e=d.options[0]).value?e.innerHTML=c:vr(d,c):"class"===u?(n=d,l=" ".concat((r=this).value),s=n.getAttribute("data-fid"),""===l.trim()&&(l=" ".concat(r.querySelector("option[data-align]").getAttribute("data-align"))),void 0!==s&&(r.classList.contains("field_options_align")?l+=" ".concat(document.getElementById("frm_classes_".concat(s)).value):r.classList.contains("frm_classes")&&(a=document.getElementById("field_options_align_".concat(s)))&&(l+=" ".concat(a.value))),l=(l+=" ").replace(" block "," vertical_radio ").replace(" inline "," horizontal_radio "),""===(o=0===(o=n.className.split(" frmstart ")[1]).indexOf("frmend ")?"":o.split(" frmend ")[0]).trim()?(i=" frmstart frmend ",n.className.includes(i)||(i=" frmstart frmend "),l=" frmstart ".concat(l.trim()," frmend ")):(i=o.trim(),l=l.trim()),n.className=n.className.replace(i,l)):"range"===(t=d).type&&t.parentNode.classList.contains("frm_range_container")?function(e,t,n){if(frmGlobal.proIncludesSliderJs){var r={field:e,att:t,newValue:n};wp.hooks.doAction("frm_update_slider_field_preview",r)}else{var o;if("value"===t?(""===n&&(n=ft(e)),e.value=n):e.setAttribute(t,n),["value","min","max"].includes(t))"max"!==t&&"min"!==t||""!==(o=e.id,document.querySelector('input[data-changeme="'.concat(o,'"][data-changeatt="value"]')).value)||(e.value=ft(e)),e.parentNode.querySelector(".frm_range_value").textContent=e.value}}(d,u,c):d.setAttribute(u,c):0===d.id.indexOf("setup-message")?""!==c&&(d.innerHTML='<input type="text" value="" disabled />'):(d.innerHTML=br(c),"TEXTAREA"===d.nodeName&&d.classList.contains("wp-editor-area")&&jQuery(d).trigger("change"),d.classList.contains("frm_primary_label")&&"break"===d.nextElementSibling.getAttribute("data-ftype")&&(d.nextElementSibling.querySelector(".frm_button_submit").textContent=c)))}function ft(e){var t=parseFloat(e.getAttribute("max")),n=parseFloat(e.getAttribute("min"));return(t-n)/2+n}function mt(){var e=this.getAttribute("data-fid"),t="";["field_options_max_","frm_format_"].forEach(function(n){var r=document.getElementById(n+e);r&&(t+=r.value)});var n=document.getElementsByName("field_options[type_".concat(e,"]"))[0];"text"===n.options[n.selectedIndex].value&&pt(""!==t,".frm_invalid_msg".concat(e))}function _t(){var e=this.id.replace("frm_","").replace("req_field_",""),t=this.checked,n=jQuery("#field_label_".concat(e," .frm_required"));if(pt(t,".frm_required_details".concat(e)),t){var r=jQuery('input[name="field_options[required_indicator_'.concat(e,']"]'));""===r.val()&&r.val("*"),n.removeClass("frm_hidden")}else n.addClass("frm_hidden")}function pt(e,t){var n=jQuery(t);if(e)n.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");else{var r=n.fadeOut("fast").closest(".frm_validation_box"),o=r.css("display","block").children(":not(".concat(t,"):visible")).length;r.css("display",""),0===o&&n.closest(".frm_validation_msg").fadeOut("fast")}}function gt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(".frm_unique_details".concat(e));if(this.checked){t.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");var n=jQuery(".frm_unique_details".concat(e," input"));""===n.val()&&n.val(a.default_unique)}else{var r=t.fadeOut("fast").closest(".frm_validation_box"),o=r.css("display","block").children(":not(.frm_unique_details".concat(e,"):visible")).length;r.css("display",""),0===o&&t.closest(".frm_validation_msg").fadeOut("fast")}}function vt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(this).val(),n=jQuery(document.getElementById("frm_field_id_".concat(e)));if(pt(""!==t,".frm_conf_details".concat(e)),""!==t){var r=jQuery(".frm_validation_box .frm_conf_details".concat(e," input"));""===r.val()&&r.val(a.default_conf),function(e){var t=document.getElementsByName("field_options[type_".concat(e,"]"))[0].value;yt(document.getElementById("field_description_".concat(e)),"field_options[description_".concat(e,"]"),a["enter_".concat(t)]),yt(document.getElementById("conf_field_description_".concat(e)),"field_options[conf_desc_".concat(e,"]"),a["confirm_".concat(t)])}(e),"inline"===t?n.removeClass("frm_conf_below").addClass("frm_conf_inline"):"below"===t&&n.removeClass("frm_conf_inline").addClass("frm_conf_below"),jQuery(".frm-conf-box-".concat(e)).removeClass("frm_hidden")}else jQuery(".frm-conf-box-".concat(e)).addClass("frm_hidden"),setTimeout(function(){n.removeClass("frm_conf_inline frm_conf_below")},200)}function yt(e,t,n){e.innerHTML===a.desc&&(e.innerHTML=n,document.getElementsByName(t)[0].value=n)}function ht(e){var t=JSON.parse(this.getAttribute("data-opts"));return e.preventDefault(),document.getElementById("frm_bulk_options").value=t.join("\n"),!1}function bt(){var e,t,n,r=jQuery(this).closest(".frm-single-settings").data("fid"),o=jQuery("#frm_field_".concat(r,"_opts .frm_option_template")).prop("outerHTML"),i=jQuery(this).data("opttype"),a=0,l="000",s=function(e){for(var t=0,n=0,r=jQuery("#frm_field_".concat(e,"_opts li")),o=0;t<r.length;t++){if(n=r[t].getAttribute("data-optkey"),1===r.length)return n;"000"!==n&&(n=n.replace("other_",""),n=parseInt(n,10)),!isNaN(o)&&(n>o||"000"===o)&&(o=n)}return o}(r);if(s!==l&&(a=s+1),"other"===i){document.getElementById("other_input_".concat(r)).value=1;var c=jQuery(this).data("ftype");"radio"!==c&&"select"!==c||jQuery(this).fadeOut("slow");var d={action:"frm_add_field_option",field_id:r,opt_key:a,opt_type:i,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,d,function(e){jQuery(document.getElementById("frm_field_".concat(r,"_opts"))).append(e),ur(r)})}else{o=(o=(o=(o=(o=o.replace(new RegExp('optkey="'.concat(l,'"'),"g"),'optkey="'.concat(a,'"'))).replace(new RegExp("-".concat(l,"_"),"g"),"-".concat(a,"_"))).replace(new RegExp("-".concat(l,'"'),"g"),"-".concat(a,'"'))).replace(new RegExp("\\[".concat(l,"\\]"),"g"),"[".concat(a,"]"))).replace("frm_hidden frm_option_template",""),$i(r,o={newOption:o});var u=this.closest(".frm_single_option");u?u.after(o.newOption):jQuery("#frm_field_".concat(r,"_opts")).append(o.newOption),ur(r)}null==(n=(e=this).classList.contains("frm-add-option-legacy")?null===(t=e.closest(".frm-collapse-me"))||void 0===t?void 0:t.querySelector(".frm_sortable_field_opts"):e.closest(".frm_sortable_field_opts"))||n.querySelectorAll(".frm_remove_tag.frm_disabled").forEach(function(e){return e.classList.remove("frm_disabled")}),Vo()}function wt(){jt(jQuery(this).closest(".frm-single-settings").data("fid"),this.value)}function jt(e,t){var n=jQuery(".frm_multiple_cont_".concat(e));"select"===t?n.fadeIn("fast"):n.fadeOut("fast")}function xt(){var e=jQuery(this).closest(".frm-single-settings").data("fid");Pi(jQuery(".field_".concat(e,"_option_key")),"",this.checked),jQuery(".field_".concat(e,"_option")).toggleClass("frm_with_key")}function Et(){var e=jQuery(this).closest(".frm-single-settings"),t=e.data("fid"),n=document.getElementById("frm_field_id_".concat(t));At(jQuery(this));var r=Er(t);if(Pi(jQuery(".field_".concat(t,"_image_id")),"",r),Pi(jQuery(".frm_toggle_image_options_".concat(t)),"",r),Pi(jQuery(".frm_image_size_".concat(t)),"",r),Pi(jQuery(".frm_alignment_".concat(t)),"",r),Pi(jQuery(".frm-add-other#frm_add_field_".concat(t)),"",r),kt(n),r){Qt(t,"inline");var o=dr(t);n.classList.add("frm_image_options"),n.classList.add("frm_image_size_".concat(o)),e.find(".frm-bulk-edit-link").hide()}else n.classList.remove("frm_image_options"),Qt(t,"block"),e.find(".frm-bulk-edit-link").show();wp.hooks.doAction("frm_image_options_toggled",e[0],r)}function kt(e){e.classList.remove("frm_image_size_","frm_image_size_small","frm_image_size_medium","frm_image_size_large","frm_image_size_xlarge")}function Qt(e,t){jQuery("#field_options_align_".concat(e)).val(t).trigger("change")}function St(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));Lt(),Er(e)&&(kt(t),t.classList.add("frm_image_options"),t.classList.add("frm_image_size_".concat(dr(e))))}function At(e){var t=e.closest(".frm-single-settings").data("fid");jQuery(".field_".concat(t,"_option")).trigger("change")}function Lt(){At(jQuery(this))}function It(e){var t,n=e.target.closest(".frm_image_preview_wrapper");if(null!==(t=wp)&&void 0!==t&&t.media&&(null==n||!n.dataset.upgrade)){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(),t=n.querySelector("img");t.setAttribute("src",e.url),t.classList.remove("frm_hidden"),t.removeAttribute("srcset"),n.querySelector(".frm_image_preview_frame").style.display="block",n.querySelector(".frm_image_preview_title").textContent=e.filename,n.querySelector(".frm_choose_image_box").style.display="none";var o=jQuery(n);o.siblings('input[name*="[label]"]').data("frmimgurl",e.url),o.find("input.frm_image_id").val(e.id).trigger("change"),wp.media.model.settings.post.id=0}),r.open()}}function qt(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 Bt(){var e=jQuery(this).closest("li").find(".frm_form_fields select");this.checked?e.attr("multiple","multiple"):e.removeAttr("multiple")}function Ct(){var e=document.getElementById("dropform-search-input");e&&setTimeout(function(){e.focus()},100)}function Nt(e){var t=e.target,n=t.closest(".frm_warning_style");jQuery(n).fadeOut(400,function(){return n.remove()});var r=t.dataset.action,o=new FormData;b(r,o)}function Tt(e){e.preventDefault()}function Ot(){var e,t,n=this.parentNode,r=n.parentNode,o=r.querySelectorAll("li:not(.frm_hidden)");2===o.length&&(null===(e=Array.from(o).find(function(e){return e!==n}).querySelector(".frm_remove_tag"))||void 0===e||e.classList.add("frm_disabled"));var i=this.getAttribute("data-fid");jQuery(n).fadeOut("fast",function(){wp.hooks.doAction("frm_before_delete_field_option",this),jQuery(n).remove(),jQuery(r).find(".frm_other_option").length<1&&((t=document.getElementById("other_input_".concat(i)))&&(t.value=0),jQuery("#other_button_".concat(i)).fadeIn("fast"))}),Vo()}function Ft(){var e=jQuery(this);if(e.is(":checked")){var t,n=function(){e.off("mouseup",t)};t=function(){setTimeout(function(){e.prop("checked",!1)},0),n()},e.on("mouseup",t),e.one("mouseout",n)}}function Dt(){this.value===a.new_option&&(this.setAttribute("data-value-on-focus",this.value),this.value="")}function Mt(e){return O(T("Are you sure you want to delete these %1$s selected field(s)?","formidable"),e)}function Pt(){var e=a.conf_delete,t=this.parentNode.parentNode.parentNode.parentNode.parentNode,n=t.parentNode,r=jQuery(this).closest("li.form-field"),o=r.data("fid");if("divider"===r.data("ftype")){var i=document.querySelectorAll(".frm-field-group-hover-target .start_divider .frm_field_box"),l=0;i.forEach(function(e){var t=e.querySelectorAll("li.form-field");t&&(l+=t.length)}),l&&(e=Mt(++l))}return n.classList.contains("frm-section-collapsed")||n.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",o),Pe(),R(this)),!1}function Ht(){this.closest("li.form-field").click()}function zt(){var e=document.querySelector(".frm-field-group-hover-target");if(e){e.classList.add("frm-selected-field-group");var t=document.createElement("div");t.classList.add("frm-delete-field-groups","frm_hidden"),document.body.append(t),t.click()}}function Rt(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t="frm_field_group_".concat(Qe()),n=document.createTextNode("");Xe(n);var r=jQuery(n).closest("li").get(0);r.classList.add("frm_hidden");var o=r.querySelector("ul");o.id=t,jQuery(e.closest("li.frm_field_box")).after(r);var i=ue(jQuery(e)),a=[],l=[],s=i.length,c={},d=0;jQuery(r).on("frm_added_duplicated_field_to_row",function(e,t){if(c[jQuery(t.duplicatedFieldHtml).attr("data-fid")]=t.originalFieldId,!(s>++d)){var n=jQuery(o),i=ue(n);l.forEach(function(e){e.remove()});for(var u=0;u<s;++u)n.append(n.children('li.form-field[frm-field-order="'.concat(u,'"]')));fe(i.first(),a),r.classList.remove("frm_hidden"),qr(),ue(n).each(function(){Me(c[this.getAttribute("data-fid")],jQuery(this).prop("outerHTML"))})}}),i.each(function(e){var n=document.createElement("li");n.classList.add("frm_clone_field"),n.setAttribute("frm-target-row-id",t),n.setAttribute("frm-field-order",e),this.append(n),n.click(),l.push(n),a.push(fn(mn(this.classList)))})}}function Gt(){var e=document.querySelector(".frm-field-group-hover-target");if(e){tt();var t=Wt(e.querySelector("li.form-field"));e.classList.add("frm-has-open-field-group-popup"),jQuery(document).on("click","#frm_builder_page",Ut);var n=_();n.style.position="relative",n.append($t(t,this)),this.parentNode.append(n);var r=n.querySelector(".frm-row-layout-option");r&&r.focus()}}function Ut(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||yn()}function Wt(e){var t=jQuery(e).closest("ul");return t.length?ue(t).length:An()}function $t(e,t){var n=document.getElementById("frm_field_group_popup");n?n.innerHTML="":n=_(),n.id="frm_field_group_popup";var r,o=_();o.style.padding="0 24px 12px",o.append(((r=_()).classList.add("frm-row-layout-title"),r.textContent=T("Row Layout","formidable"),r));var i,a=function(e){var t=rn();if(e>6)return t.append(Jt(e,"even")),t;if(5!==e&&t.append(Jt(e,"even")),e%2==1&&t.append(Jt(e,"middle")),e<6)t.append(Jt(e,"left")),t.append(Jt(e,"right"));else{var n=_();n.classList.add("frm_fourth"),t.prepend(n)}return t}(e),l=t.closest("ul.frm_sorting");return l&&function(e,t){for(var n=t.children.length,r=0;r<n;++r){var o=t.children[r];if(Xt(o,e))return void o.classList.add("frm-active-row-layout")}}(l,a),o.append(a),n.append(o),n.append(document.createElement("hr")),e<=6&&n.append(((i=_()).textContent=T("Custom layout","formidable"),jQuery(i).prepend(Kt("frm_gear_svg")),i.classList.add("frm-custom-field-group-layout"),Vt(i),i)),n.append(function(){var e=_();return e.textContent=T("Break into rows","formidable"),jQuery(e).prepend(Kt("frm_break_field_group_svg")),e.classList.add("frm-break-field-group"),Vt(e),e}()),n}function Vt(e,t){e.setAttribute("tabindex",0),e.setAttribute("role","button"),void 0!==t&&e.setAttribute("aria-label",t)}function Kt(e){var t=document.getElementById(e).cloneNode(!0);return t.id="",t}function Jt(e,t){var n,r=_();switch(r.classList.add("frm-row-layout-option"),Vt(r,t),e){case 6:n="frm_half";break;case 5:n="frm_third";break;default:n=e>6?"frm_full":e%2==1?"frm_fourth":"frm_third"}return r.classList.add(n),r.setAttribute("layout-type",t),r.append(function(e,t){for(var n=rn(),r=0;r<e;++r){var o=_();o.classList.add(Zt(e,t,r)),o.style.height="16px",o.style.background="#9EA9B8",o.style.borderRadius="1px",n.append(o)}return n}(e,t)),r}function Xt(e,t){return Yt(e)===Yt(t)}function Yt(e){var t;t=e.classList.contains("frm-row-layout-option")?jQuery(e).find(".frm_grid_container").children():ue(jQuery(e));var n=[];return t.each(function(){n.push(fn(mn(this.classList)))}),n.join("-")}function Zt(e,t,n){if("even"===t)return en(e,n);if("middle"===t){if(3===e)return 1===n?"frm6":"frm3";if(5===e)return 2===n?"frm4":"frm2"}else{if("left"===t)return 0===n?nn(e):tn(e);if("right"===t)return n===e-1?nn(e):tn(e)}return"frm12"}function en(e,t){return e>6?"frm1":[2,3,4,6].includes(e)?_n(12/e):5===e&&void 0!==t?0===t?"frm4":"frm2":"frm12"}function tn(e){switch(e){case 2:case 3:return"frm3";case 4:case 5:return"frm2";case 6:return"frm1";default:return"frm12"}}function nn(e){switch(e){case 2:return"frm9";case 3:case 4:return"frm6";case 5:return"frm4";case 6:return"frm7";default:return"frm12"}}function rn(){var e=_();return e.classList.add("frm_grid_container"),e}function on(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t=this.getAttribute("layout-type");fe(ue(jQuery(e)).first(),t),yn()}}function an(){var e=ln(),t=this.getAttribute("layout-type");fe(ue(e).first(),t),En()}function ln(){var e=jQuery(".frm-selected-field-group"),t=e.first();return e.not(t).each(function(){ue(jQuery(this)).each(function(){var e=this.parentNode;ue(t).last().after(this),jQuery(e).children("li.form-field").length||e.closest("li.frm_field_box").remove()})}),qr(),fe(ue(t).first()),t}function sn(){null===this.closest(".frm-merge-fields-into-row")&&cn(ue(jQuery(".frm-field-group-hover-target")))}function cn(e){var t=e.length,n=document.getElementById("frm_field_group_popup");n.innerHTML="";var r=_();r.style.padding="0 24px";var o=en(5===t?6:t),i=_();if(i.style.padding="20px 0",i.classList.add("frm_grid_container"),5===t){var a=document.createElement("span");a.classList.add("frm1"),i.append(a)}var l=An()>0&&fn(en(t));!1!==l&&l>=12&&(l=Math.floor(12/t));for(var s=0;s<t;++s){var c=document.createElement("input");c.type="text",c.classList.add(o),c.classList.add("frm-custom-grid-size-input"),c.value=!1!==l?l:fn(mn(e.get(s).classList)),i.append(c)}var d=_();d.classList.add("frm-builder-popup-heading"),d.textContent=T("Enter number of columns for each field","formidable");var u=_();u.classList.add("frm-builder-popup-subheading"),u.textContent=T("Layouts are based on a 12-column grid system","formidable"),r.append(d),r.append(u),r.append(i);var f=_();f.style.textAlign="right";var m,p=((m=un()).classList.add("button-secondary","frm-button-secondary"),m);p.textContent=T("Cancel","formidable"),p.classList.add("frm-cancel-custom-field-group-layout"),p.style.marginRight="10px";var g=function(){var e=un();return e.classList.add("button-primary","frm-button-primary"),e}();g.textContent=T("Save","formidable"),g.classList.add("frm-save-custom-field-group-layout"),f.append(p),f.append(g),r.append(f),n.append(r),setTimeout(function(){var e=n.querySelector("input.frm-custom-grid-size-input").focus();e&&e.focus()},0)}function dn(){cn(jQuery(".frm-selected-field-group li.form-field"))}function un(){var e=document.createElement("a");return e.setAttribute("href","#"),e.classList.add("button"),e.style.textDecoration="none",e}function fn(e){switch(e){case"frm_half":return 6;case"frm_third":return 4;case"frm_two_thirds":return 8;case"frm_fourth":return 3;case"frm_three_fourths":return 9;case"frm_sixth":return 2;default:return 0===e.indexOf("frm")?parseInt(e.substr(3)):12}}function mn(e){for(var t=["frm_full","frm_half","frm_third","frm_fourth","frm_sixth","frm_two_thirds","frm_three_fourths","frm1","frm2","frm3","frm4","frm5","frm6","frm7","frm8","frm9","frm10","frm11","frm12"],n=0;n<t.length;++n){var r=t[n];if(e.contains(r))return r}return""}function _n(e){return"frm".concat(e)}function pn(){var e,t;e=document.querySelector(".frm-field-group-hover-target"),ue(t=jQuery(e)).each(function(e){0!==e&&t.parent().after(Je(this)),function(e){fe(e,"clear")}(jQuery(this))}),yn()}function gn(){this.select()}function vn(){jQuery(document.getElementById("frm_field_group_popup")).replaceWith($t(Wt(this),this))}function yn(){var e=document.getElementById("frm_field_group_popup");if(e){var t=document.querySelector(".frm-has-open-field-group-popup");t&&(t.classList.remove("frm-has-open-field-group-popup"),e.parentNode.remove()),jQuery(document).off("click","#frm_builder_page",Ut)}}function hn(){var e=[];jQuery(document.getElementById("frm_field_group_popup").querySelectorAll(".frm_grid_container input")).each(function(){e.push(parseInt(this.value))});var t=jQuery(document.getElementById("frm_field_group_controls"));t.length&&"none"!==t.get(0).style.display?fe(ue(jQuery(document.querySelector(".frm-field-group-hover-target"))).first(),e):(fe(ue(ln()).first(),e),En()),yn()}function bn(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)wn(e);else if(e)!function(e){e&&(e.classList.remove("frm_hidden"),e.classList.add("frm-fadein-up-back"))}(e);else{e=_({id:"frm-field-group-message",className:"frm-flex-center frm-fadein-up-back",children:[p({id:"frm-field-group-message-dismiss",className:"frm-flex-center",child:v({href:"#frm_close_icon"})})]}),document.getElementById("post-body-content").append(e);var t,n=((t=document.createElement("span")).classList.add("frm-field-group-message-text","frm-flex-center"),t.innerHTML=O(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(n),document.getElementById("frm-field-group-message-dismiss").addEventListener("click",function(){wn(document.getElementById("frm-field-group-message"))})}}(),"ul"===e.originalEvent.target.nodeName.toLowerCase()){var t=document.querySelector(".frm-field-group-hover-target");if(t){var n=e.ctrlKey||e.metaKey,r=e.shiftKey,o=t.classList.contains("frm-selected-field-group"),i=function(){var e=jQuery(".frm-selected-field-group");if(e.length)return e;var t=jn();if(t){var n=t.closest("ul");if(n&&1===ue(jQuery(n)).length)return n.classList.add("frm-selected-field-group"),jQuery(n)}return jQuery()}(),a=i.length;if(n||r){var l=jn();if(null===l||jQuery(l).siblings("li.form-field").length||(l.parentNode.classList.add("frm-selected-field-group"),++a),n){if(o)return--a,t.classList.remove("frm-selected-field-group"),void xn(a);++a}else if(r&&!o){++a;var s=i.first();(s.parent().index()<jQuery(t.parentNode).index()?s.parent().nextUntil(t.parentNode):s.parent().prevUntil(t.parentNode)).each(function(){var e=jQuery(this).closest("li").find("ul.frm_sorting");e.hasClass("frm-selected-field-group")||(++a,e.addClass("frm-selected-field-group"))})}}else En(),a=1;t.classList.add("frm-selected-field-group"),xn(a),document.querySelectorAll(".frm-selected-field-group").length<2||wn(document.getElementById("frm-field-group-message")),jQuery(document).off("click",En),jQuery(document).on("click",En)}}}function wn(e){e&&(e.classList.add("frm_hidden"),e.classList.remove("frm-fadein-up-back"))}function jn(){return document.getElementById("frm-show-fields").querySelector("li.form-field.selected")}function xn(e){et(!0),e>=2||1===e&&ue(jQuery(document.querySelector(".frm-selected-field-group"))).length>1?function(){var e=document.getElementById("frm_field_multiselect_popup");if(e)return e.classList.toggle("frm-unmergable",!Qn()),e;(e=_()).id="frm_field_multiselect_popup",Qn()||e.classList.add("frm-unmergable");var t=_();t.classList.add("frm-merge-fields-into-row"),t.textContent=T("Merge into row","formidable");var n=document.createElement("a");n.style.marginLeft="5px",n.classList.add("frm_icon_font","frm_arrowdown6_icon"),n.setAttribute("href","#"),t.append(n),e.append(t);var r=_();r.classList.add("frm-multiselect-popup-separator"),e.append(r);var o=_();o.classList.add("frm-delete-field-groups"),o.append(Kt("frm_trash_svg")),e.append(o),document.getElementById("post-body-content").append(e),jQuery(e).hide().fadeIn()}():kn(),Re()}function En(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",En),kn()}function kn(){var e=document.getElementById("frm_field_multiselect_popup");e&&e.remove()}function Qn(){var e=document.querySelectorAll(".frm-selected-field-group"),t=e.length;if(1===t)return!1;for(var n=0,r=0;r<t;++r){var o=e[r];if(null!==o.querySelector(".edit_field_type_break, .edit_field_type_hidden"))return!1;if((n+=ue(jQuery(o)).length)>12)return!1}return!0}function Sn(e){if(null===e.originalEvent.target.closest("#frm_field_group_popup")&&!e.originalEvent.target.classList.contains("frm-custom-field-group-layout")){var t=$t(An(),document.querySelector(".frm-selected-field-group").firstChild);this.append(t)}}function An(){var e=0;return jQuery(document.querySelectorAll(".frm-selected-field-group")).each(function(){e+=ue(jQuery(this)).length}),e}function Ln(){var e,t=(e=[],jQuery(".frm-selected-field-group > li.form-field").each(function(){e.push(this.dataset.fid)}),e),n=function(e){return function(t){t.preventDefault(),function(e){e.forEach(function(e){qn(e)})}(e)}}(t),r=document.getElementById("frm_field_multiselect_popup");r&&r.remove(),this.setAttribute("data-frmverify",Mt(t.length)),R(this);var o=document.getElementById("frm-confirmed-click");null==o||o.removeAttribute("data-deletefield"),jQuery(o).on("click",n),jQuery("#frm_confirm_modal").one("dialogclose",function(){jQuery(o).off("click",n)})}function In(){qn(this.getAttribute("data-deletefield"))}function qn(e){var t=jQuery("#frm_field_id_".concat(e));Bn(e),t.hasClass("edit_field_type_divider")&&t.find("li.frm_field_box[data-fid]").each(function(){Bn(this.getAttribute("data-fid"))}),Br()}function Bn(e){jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_delete_field",field_id:e,nonce:frmGlobal.nonce},success:function(){var t,n,r,o=jQuery(document.getElementById("frm_field_id_".concat(e))),i=jQuery("#frm-single-settings-".concat(e));i.is(":visible")&&(null===(t=document.querySelector(".frm-settings-panel .frm-tabs-navs ul > li:first-child"))||void 0===t||t.click(),document.querySelector("#frm-options-panel .frm-single-settings").classList.remove("frm_hidden")),function(e){var t=e[0].querySelectorAll(".frm-inline-modal[data-fills]");t.length&&t.forEach(function(e){e.classList.add("frm_hidden"),e.removeAttribute("data-fills"),e.closest("form").append(e)})}(i),i.remove(),o.fadeOut("slow",function(){var e,t=o.closest(".start_divider"),n=o.data("type"),r=o.siblings("li.form-field");if(r.length||(o.is(".edit_field_type_end_divider")?r.length=o.closest("li.form-field").siblings():e=o.closest("ul.frm_sorting").parent()),o.remove(),"break"===n?Gn():"product"===n&&(Oe(),ct()),r.length?fe(r.first()):e.remove(),0===jQuery("#frm-show-fields li").length||function(){if(k.get(0).childElementCount>1)return!1;var e=k.get(0).firstElementChild.firstElementChild.querySelectorAll("li.frm_field_box");return!(e.length>1)&&e[0].classList.contains("edit_field_type_submit")}()){var i=document.getElementById("frm_form_editor_container");i.classList.remove("frm-has-fields"),i.classList.add("frm-empty-fields")}else t.length&&Cr(t);$()}),o.length&&(n=o.data("type"),(r=document.getElementById(n))&&r.dataset.limit&&Cn(n)-1<r.dataset.limit&&r.classList.remove("frm_at_limit"),wp.hooks.doAction("frm_after_delete_field",o[0]))}})}function Cn(e){return document.getElementById("frm-show-fields").querySelectorAll('li.form-field[data-ftype="'.concat(e,'"]')).length}function Nn(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=I,n=document.getElementById("frm_logic_row_".concat(e)).querySelectorAll(".frm_logic_row");return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_logic_row",form_id:t,field_id:e,nonce:frmGlobal.nonce,meta_name:Tn(n,"frm_logic_".concat(e,"_")),fields:lt()},success:function(t){jQuery(document.getElementById("logic_".concat(e))).fadeOut("fast",function(){var n=document.getElementById("frm_logic_row_".concat(e));n.insertAdjacentHTML("beforeend",t);var r=n.querySelector(".frm_logic_row:last-child .frm-logic-rule-text");r&&(r.textContent=n.dataset.ruleText);var o=n.closest(".frm_logic_rows");o.style.height="auto",jQuery(o).fadeIn("fast")})}}),!1}function Tn(e,t,n){return e.length?parseInt(e[e.length-1].id.replace(t,""),10)+1:void 0!==n?n:0}function On(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=I,n=document.getElementById("frm_watch_lookup_block_".concat(e)).children;return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_watch_lookup_row",form_id:t,field_id:e,row_key:Tn(n,"frm_watch_lookup_".concat(e,"_")),nonce:frmGlobal.nonce},success:function(t){var n,r=jQuery(document.getElementById("frm_watch_lookup_block_".concat(e)));r.append(t),r.fadeIn("slow"),null===(n=document.getElementById("frm_watch_lookup_label_".concat(e)))||void 0===n||n.classList.remove("frm-force-hidden")}}),!1}function Fn(e){var t,n,r=jQuery(e).closest(".frm-single-settings").attr("data-fid"),o=jQuery(e).closest("ul").get(0).querySelectorAll(".field_".concat(r,"_option"));for(t in o)if(Object.hasOwn(o,t)&&(n=o[t]).id!==e.id&&n.value===e.value&&"true"!==n.getAttribute("data-duplicate"))return!0;return!1}function Dn(){var e,t;null===this.getAttribute("data-value-on-load")&&(this.setAttribute("data-value-on-load",this.value),t=jQuery(this).closest(".frm-single-settings").attr("data-fid"),(e=document.createElement("input")).value=this.value,e.setAttribute("type","hidden"),e.setAttribute("name","optionmap[".concat(t,"][").concat(this.value,"]")),this.parentNode.append(e),void 0===B[t]&&(B[t]={}),B[t][this.value]=e),"true"===this.getAttribute("data-duplicate")&&(this.removeAttribute("data-duplicate"),Fn(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 Mn(e){var t,n=e.closest(".frm_single_option");return e.parentElement.classList.contains("frm_single_option")?{newValue:n.querySelector('.frm_option_key input[type="text"]').value,newLabel:t=e.value}:(t=n.querySelector('input[type="text"]').value,{newValue:e.value,newLabel:t})}function Pn(){var e,t,n=function(e){var t=function(e){var t,n,r=null!==(t=null===(n=e.closest(".frm-single-settings").querySelector(".frm_toggle_sep_values"))||void 0===n?void 0:n.checked)&&void 0!==t&&t,o=e.closest(".frm_single_option");return r&&e.parentElement.classList.contains("frm_single_option")?{oldValue:o.querySelector('.frm_option_key input[type="text"]').getAttribute("data-value-on-focus"),oldLabel:e.getAttribute("data-value-on-focus")}:{oldValue:e.getAttribute("data-value-on-focus"),oldLabel:o.querySelector('input[type="text"]').getAttribute("data-value-on-focus")}}(e),n=t.oldValue,r=t.oldLabel,o=Mn(e);return{oldValue:n,oldLabel:r,newValue:o.newValue,newLabel:o.newLabel}}(this),r=n.oldValue,o=n.oldLabel,i=n.newValue,a=n.newLabel;if(r!==i||o!==a){var l=this.closest(".frm-single-settings"),s=l.getAttribute("data-fid"),c=this.getAttribute("data-value-on-load");if(Fn(this))return this.setAttribute("data-duplicate","true"),void(void 0!==B[s]&&void 0!==B[s][c]&&(B[s][c].value=c));void 0!==B[s]&&void 0!==B[s][c]&&(B[s][c].value=i);for(var d=[],u=H.querySelectorAll(".frm_logic_row"),f=u.length,m=0;m<f;m++){var _=u[m];if(_.querySelector(".frm_logic_field_opts").value===s){var p,g=_.id.split("_")[2],v=_.querySelector('select[name="field_options[hide_opt_'.concat(g,'][]"]')),y=void 0,h=void 0;(y=""===r?[]:v.querySelectorAll('option[value="'.concat(r,'"]'))).length||(y=v.querySelectorAll('option[value="'.concat(i,'"]'))).length||(null!==(p=l.querySelector(".frm_toggle_sep_values"))&&void 0!==p&&p.checked||(h=Hn(v,r)),h||(h=document.createElement("option"),v.append(h))),y.length&&(h=y[y.length-1]),h.setAttribute("value",i),h.textContent=a,d.includes(g)||d.push(g)}}for(e in d)Object.hasOwn(d,e)&&(t=d[e],uo(document.getElementById("frm-single-settings-".concat(t))))}}function Hn(e,t){for(var n=e.options,r=0;r<n.length;r++){var o=n[r];if(t===o.textContent)return o}return null}function zn(){var e=this.id.replace("get_values_form_",""),t=document.getElementById("get_values_field_".concat(e)),n=this.getAttribute("data-fieldtype");if(""===this.value)t.options.length=1;else{var r=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_options_for_get_values_field",form_id:r,field_type:n,nonce:frmGlobal.nonce},success:function(e){t.innerHTML=e}})}}function Rn(){var e,t,n=this.name.replace("field_options[data_type_","").replace("]","");(e=document.getElementById("frm_add_watch_lookup_link_".concat(n)))&&(e=e.parentNode,"text"===this.value?(t=document.getElementById("frm_watch_lookup_block_".concat(n)))&&(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"),jt(n,this.value))}function Gn(){var e,t,n=document.getElementsByClassName("frm-page-num");if(n.length>1)for(document.getElementById("frm-fake-page").style.display="block",e=0;e<n.length;e++)t=n[e].parentNode.parentNode.parentNode.classList,1===e?t.add("frm-first-page"):t.remove("frm-first-page"),n[e].textContent=e+1;else document.getElementById("frm-fake-page").style.display="none";wp.hooks.doAction("frm_renumber_page_breaks",n)}function Un(){var e,t,n,r=jQuery(this).closest(".frm_field_box[data-ftype=break]");r.length?function(e){var t=Wn(e.get(0).parentNode.closest("li.frm_field_box").nextElementSibling);$n(e,t)}(r):(e=document.getElementById("frm-fake-page"),t=document.getElementById("frm-show-fields").firstElementChild,n=Wn(t),"break"!==t.getAttribute("data-ftype")&&$n(jQuery(e),n))}function Wn(e){var t,n;if(t=jQuery(),null===e)return t;n=e;do{if(null!==n.querySelector(".edit_field_type_break"))break;t=t.add(jQuery(n)),n=n.nextElementSibling}while(null!==n);return t}function $n(e,t){var n,r=t.length,o=Math.min(r,3);if(e.hasClass("frm-page-collapsed"))for(e.removeClass("frm-page-collapsed"),t.removeClass("frm-is-collapsed"),n=0;n<o;n++)n===o-1?jQuery(t[n]).slideDown(150,function(){t.show()}):jQuery(t[n]).slideDown(150);else for(e.addClass("frm-page-collapsed"),t.addClass("frm-is-collapsed"),n=0;n<o;n++)n===o-1?jQuery(t[n]).slideUp(150,function(){t.css("cssText","display:none !important;")}):jQuery(t[n]).slideUp(150)}function Vn(){this.parentNode.parentNode.parentNode.parentNode.classList.toggle("frm-section-collapsed")}function Kn(){this.nextElementSibling&&(this.nextElementSibling.style.animation=""),this.classList.toggle("frm-collapsed");var e="true"===this.getAttribute("aria-expanded")||!1;this.setAttribute("aria-expanded",!e),Jn(this.nextElementSibling)}function Jn(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 Xn(){if(this.id){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0],t=this.id.replace("field_label_",""),n=document.getElementById("field_options_type_".concat(t)),r=n.value;void 0!==e&&(r=function(e){return"divider"===e?e="section":"range"===e?e="slider":"data"===e?e="dynamic":"form"===e&&(e="embed form"),e}(r="SELECT"===n.tagName?n.options[n.selectedIndex].text.toLowerCase():r.replace("_"," ")),setTimeout(function(){e.value.toLowerCase()===r?e.select():e.focus()},50))}}function Yn(){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0];void 0!==e&&setTimeout(function(){e.focus(),Zn(e)},50)}function Zn(e){var t=e.closest(".frm-collapse-me");null!==t&&t.previousElementSibling.classList.remove("frm-collapsed")}function er(e){var t,n,r=e.target.classList;if(!r.contains("frm-collapse-page")&&!r.contains("frm-sub-label")&&null===e.target.closest(".dropdown")){if(null!==this.closest(".start_divider")&&e.stopPropagation(),this.classList.contains("edit_field_type_divider")){var o=e.originalEvent.target.closest("ul.frm_sorting");if(null!==o&&(o.classList.contains("edit_field_type_divider")||o.parentNode.parentNode.classList.contains("start_divider")))return}t=this,n=jQuery(t),t.className.includes("selected")||t.className.includes("edit_field_type_end_divider")&&n.closest(".edit_field_type_divider").hasClass("no_repeat_section")||(tt(),n.addClass("selected"),function(e){var t,n,r=e.getAttribute("data-fid"),o=e.getAttribute("data-type"),i=document.querySelectorAll(".frm-single-settings:not(.frm_hidden)");for(n=0;n<i.length;n++)i[n].classList.add("frm_hidden");var a=document.getElementById("frm-single-settings-".concat(r));uo(a),o&&"quantity"===o&&st(jQuery(a).find(".frmjs_prod_field_opt")[0]),null===(t=document.querySelector(".frm-settings-panel.frm-scrollbar-wrapper"))||void 0===t||t.scrollTo({top:0,behavior:"instant"}),a.classList.remove("frm_hidden"),a.querySelectorAll("h3:not(.frm-collapsed) + .frm-collapse-me").forEach(function(e){return e.style.animation="none"}),document.getElementById("frm-options-panel-tab").click();var l=a.querySelector(".wp-editor-area");l&&frmDom.wysiwyg.init(l,{setupCallback:co}),wp.hooks.doAction("frmShowedFieldSettings",e,a),function(e,t,n){var r;if(function(e){return wp.hooks.applyFilters("frm_fields_with_shortcode_popup",["html"]).includes(e)}(e)){var o="#frm-single-settings-".concat(t);if(!document.querySelector("".concat(o," .frm-show-box"))){null===(r=n.querySelector(".wp-editor-container"))||void 0===r||r.classList.add("frm_has_shortcodes");var i=function(){return frmDom.svg({href:"#frm_more_horiz_solid_icon",classList:["frm-show-box"]})};document.querySelectorAll("".concat(o," .frm_has_shortcodes textarea")).forEach(function(e){var t=p({className:"frm-with-right-icon"});e.parentNode.insertBefore(t,e),t.append(i()),t.append(e)})}}}(o,r,a)}(t))}}function tr(e){var t=e.target;if("custom"===t.value){var n=t.dataset.fieldId,r=document.getElementById("frm-field-format-custom-".concat(n)).querySelector(".frm_format_opt");"international"!==r.value&&"currency"!==r.value&&"number"!==r.value||r.setAttribute("value","")}setTimeout(function(){t.querySelectorAll("option").forEach(function(e){e.selected&&e.classList.contains("frm_show_upgrade")&&(t.value="none")})},0)}function nr(){var e=this.getAttribute("data-fid");Zn(document.getElementById("field_options_field_key_".concat(e)))}function rr(){var e=jQuery(this).closest(".frm_field_box");e.find(".repeat_icon_links").removeClass("repeat_format repeat_formatboth repeat_formattext").addClass("repeat_format".concat(this.value)),"text"===this.value||"both"===this.value?(e.find(".frm_repeat_text").show(),e.find(".repeat_icon_links a").addClass("frm_button")):(e.find(".frm_repeat_text").hide(),e.find(".repeat_icon_links a").removeClass("frm_button"))}function or(){var e=this.value;""!==e&&(e<2||e>200)&&(G(a.repeat_limit_min),this.value="")}function ir(){var e=this.value;""!==e&&(e<1||e>200)&&(G(a.checkbox_limit),this.value="")}function ar(e,t){jQuery(e).closest(".frm_field_box").find(".frm_".concat(t,"_form_row .frm_repeat_label")).text(e.value)}function lr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=this.value,n=document.getElementById("frm_show_selected_fields_".concat(e)),r=document.getElementById("frm_show_selected_forms_".concat(e));jQuery(r).find("select").val(""),"form"===t?(r.style.display="inline",function(e){if(null!==e)for(;e.firstChild;)e.firstChild.remove()}(n)):(n.style.display="none",r.style.display="none",Ir(t,e))}function sr(){var e=cr(this);if(e){var t=jQuery(this).closest(".frm_single_option");!function(e,t,n){var r=n.data("optkey"),o=xr(e),i=jQuery('label[for="field_'.concat(t,"-").concat(r,'"]')),a="field_options[options_".concat(e,"][").concat(r,"]"),l=jQuery('input[name="'.concat(a,'[label]"]'));if(i.length<1)return ur(e),void(n.find('input[name^="default_value_"]').is(":checked")&&l.length>0&&jQuery('select[name^="item_meta['.concat(e,']"]')).val(l.val()));var s,c=i.children("input");if(s=l.length<1?(l=jQuery('input[name="'.concat(a,'"]'))).val():o?jQuery('input[name="'.concat(a,'[value]"]')).val():l.val(),!(l.length<1)){var d=i[0].childNodes;if(Er(e)){var u=function(e,t,n){var r,o=e.find("img");o&&(r=o.attr("src"));var i=kr(t);return wr(n.val(),i,r)}(n,e,l),f=i.find(".frm_image_option_container");f.length>0?f.replaceWith(u):(d[d.length-1].nodeValue="",i.append(u))}else{var m=!1;d.forEach(function(t,n){if(!1===m)"INPUT"===t.tagName&&(m=n);else if(n===m+1){var r="";!function(e){var t=document.getElementsByName("field_options[image_options_".concat(e,"]")),n=Array.from(t).find(function(e){return e.checked&&"buttons"===e.value});return void 0!==n}(e)?t.nodeValue=" ".concat(l.val()):(r=_({className:"frm_label_button_container",text:" ".concat(l.val())}),i[0].replaceChild(r,t))}else t.remove()})}c.val(s),defaultVal=n.find('input[name^="default_value_"]'),c.prop("checked",!!defaultVal.is(":checked"))}}(e.fieldId,e.fieldKey,t)}}function cr(e){var t=jQuery(e).closest(".frm_sortable_field_opts");return!!t.length&&{fieldId:t.attr("id").replace("frm_field_","").replace("_opts",""),fieldKey:t.data("key")}}function dr(e){var t,n=document.getElementById("field_options_image_size_".concat(e)),r="";return n&&""!==(t=n.value)&&(r=t),r}function ur(e){var t=jQuery('[name^="item_meta['.concat(e,']"]'));if(!(t.length<1)){var n={fieldId:e,metaInput:t[0]};if(!1===wp.hooks.applyFilters("frm_custom_reset_displayed_opts",!1,n)){if(t.is("select")){var r=document.getElementById("frm_placeholder_".concat(e));r&&""!==r.value?gr(t[0],{sourceID:e,placeholder:r.value}):gr(t[0],{sourceID:e})}else{var o=yr(e),i=jQuery("#field_".concat(e,"_inner_container > .frm_form_fields")),a=Er(e),l=a?dr(e):"",s=a?"frm_image_option frm_image_".concat(l," "):"";i.html("");for(var c=cr(jQuery("#frm_delete_field_".concat(e,"-000_container"))),d=Ui(e),u="hidden"===t.attr("type")?t.data("field-type"):t.attr("type"),f=0;f<o.length;f++)i.append(pr(u,o[f],e,c.fieldKey,d,s))}mr(e)}else mr(e)}}function fr(e,t){var n=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('input[value="'.concat(t,'"]'));return n?Mn(n):{newValue:t,newLabel:t}}function mr(e,t){for(var n=H.querySelectorAll(".frm_logic_row"),r=n.length,o=wp.hooks.applyFilters("frm_conditional_logic_field_options",function(e){var t=[],n=document.getElementById("frm_field_".concat(e,"_opts"));if(!n)return t;for(var r=n.querySelectorAll(".frm_single_option"),o=r.length,i=0;i<o;i++){var a=r[i];if(!a.classList.contains("frm_hidden")){var l=a.querySelector(".field_".concat(e,"_option"));t.push(l.value)}}return t}(e),{type:t,fieldId:e}),i=o.length,a=0;a<r;a++){var l=n[a];if(l.querySelector(".frm_logic_field_opts").value==e){for(var s=l.id.split("_")[2],c=l.querySelector('select[name="field_options[hide_opt_'.concat(s,'][]"]')),d=function(){var t,n=o[u],r=null===(t=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('.frm_option_key input[type="text"]'))||void 0===t?void 0:t.value;r||(r=n);var i=c.querySelector('option[value="'.concat(r,'"]')),a=fr(e,n),l=a.newValue,s=a.newLabel,d=document.querySelectorAll("#frm_field_".concat(e,"_opts input[data-value-on-focus]")),f=Array.from(d).find(function(e){return e.value===n});if(f){var m=f.dataset.valueOnFocus;if(m&&c.querySelector('option[value="'.concat(m,'"]')))return 1}_r(c,i,l,s)},u=i-1;u>=0;u--)d();var f=c.querySelector('option[value=""]');null!==f&&c.prepend(f)}}}function _r(e,t,n,r){null!==t||e.querySelector('option[value="'.concat(n,'"]'))||((t=frmDom.tag("option",{text:r})).value=n),e.prepend(t)}function pr(e,t,n,r,o,i){var a="",l=t.key.includes("other"),s="field_".concat(r,"-").concat(t.key),c="scale"===e?"radio":e,d='<input type="text" id="field_'.concat(r,"-").concat(t.key,'-otext" class="frm_other_input frm_pos_none" name="item_meta[other][').concat(n,"][").concat(t.key,']" value="" />');return this.getSingle=function(){return""!==(a=wp.hooks.applyFilters("frm_admin.build_single_option_template",a,{opt:t,type:e,fieldId:n,classes:i,id:s}))?a:'<div class="frm_'.concat(e," ").concat(e," ").concat(i,'" id="frm_').concat(e,"_").concat(n,"-").concat(t.key,'">\n\t\t\t\t\t<label for="').concat(s,'">\n\t\t\t\t\t\t<input type="').concat(c,'" name="item_meta[').concat(n,"]").concat("checkbox"===e?"[]":"",'" value="').concat(br(t.saved),'" id="').concat(s,'"').concat(o?' data-price="'.concat(t.price,'"'):"").concat(t.checked?' checked="checked"':"",">\n\t\t\t\t\t\t").concat(br(t.label),"\n\t\t\t\t\t</label>\n\t\t\t\t\t").concat(l?d:"","\n\t\t\t\t</div>")},this.getSingle()}function gr(e,t){if(e){var n=t.sourceID,r=t.placeholder,o=Ui(n),i=t.other;!function(e){var t;if(void 0!==e.options)for(t=e.options.length-1;t>=0;t--)e.remove(t)}(e);for(var a=yr(n,e.id.includes("frm_field_logic_opt")),l=void 0!==r,s=0;s<a.length;s++){var c=a[s].label,d=a[s].key.includes("other");if(l&&""!==c?vr(e,r):l&&(c=r),l=!1,!d||i){var u=document.createElement("option");u.value=a[s].saved,u.innerHTML=br(c),o&&u.setAttribute("data-price",a[s].price),e.append(u)}}}}function vr(e,t){var n=document.createElement("option"),r=e.firstChild;n.value="",n.innerHTML=t,null!==r?(r.before(n),e.selectedIndex=0):e.append(n)}function yr(e){var t,n,r,o,i,a,l=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=[],c=jQuery('input[name^="field_options[options_'.concat(e,']"]')).filter('[name$="[label]"], [name*="[other_"]'),d=Ui(e),u=kr(e),f=Er(e),m=xr(e);for(t=0;t<c.length;t++)c[t].name.indexOf("[000]")>0||(o=n=c[t].value,i=c[t].name.replace("field_options[options_".concat(e,"]["),"").replace("[label]","").replace("]",""),m&&(r=c[t].name.replace("[label]","[value]"),n=jQuery('input[name="'.concat(r,'"]')).val(),l&&""===o&&(o=""!==n?n:frm_admin_js.no_label)),f&&(o=wr(o,u,hr(c[t]))),a={saved:n,label:o=frmAdminBuild.hooks.applyFilters("frm_choice_field_label",o,e,c[t],f),checked:jr(c[t].id),key:i},d&&(r=c[t].name.replace("[label]","[price]"),a.price=jQuery('input[name="'.concat(r,'"]')).val()),s.push(a));return s}function hr(e){var t=jQuery(e).siblings(".frm_image_preview_wrapper");if(!t.length)return"";var n=t.find("img");return n.length?n.attr("src"):""}function br(e){(e instanceof Element||e instanceof Document)&&(e=e.outerHTML);var t=jQuery.parseHTML(e).reduce(function(e,t){var n=frmDom.cleanNode(t);return"#text"===n.nodeName?e+n.textContent:e+n.outerHTML},"");return t!==e?br(t):t}function wr(e,t,n){var r,o=e;o=br(o),n?r=y({src:n,alt:o}):(r=_({className:"frm_empty_url"})).innerHTML=a.image_placeholder_icon;var i=t?" frm_label_with_image":"",l=[r];if(t){var s=c("span",{className:"frm_text_label_for_image_inner"});s.innerHTML=o,l.push(c("span",{className:"frm_text_label_for_image",child:s}))}return c("span",{className:"frm_image_option_container".concat(i),children:l})}function jr(e){var t=jQuery("#".concat(e));if(0===t.length)return!1;var n=t.siblings("input[type=checkbox]");return n.length&&n.prop("checked")}function xr(e){return Qr("separate_value_".concat(e))}function Er(e){for(var t=!1,n=document.getElementsByName("field_options[image_options_".concat(e,"]")),r=0;r<n.length;r++)n[r].checked&&(t="0"!==n[r].value);return frmAdminBuild.hooks.applyFilters("frm_choice_field_images_as_options",t,e)}function kr(e){var t=!Qr("hide_image_text_".concat(e));return frmAdminBuild.hooks.applyFilters("frm_choice_field_showing_label_with_image",t,e)}function Qr(e){var t=document.getElementById(e);return!!t&&t.checked}function Sr(e){var t=e.closest(".frm-single-settings"),n=t.getAttribute("data-fid"),r=t.querySelector('[name="field_options[separate_value_'.concat(n,']"]')).checked;if(!r||e.name.endsWith("[value]")){var o=document.getElementById("frm_field_".concat(n,"_opts"));Array.from(o.querySelectorAll('input[type="text"]')).filter(function(t){return t.id!==e.id&&r===t.name.endsWith("[value]")&&t.value===e.value}).length&&G(O(T('Duplicate option value "%s" detected',"formidable"),br(e.value)))}}function Ar(){var e=this.value;if(e){var t=this.parentNode.id.replace("frm_logic_","").split("_"),n=t[0],r=t[1],o=document.getElementById("frm_field_id_".concat(e)).getAttribute("data-ftype"),i=document.getElementById("frm_show_selected_values_".concat(n,"_").concat(r)),a="field_options[hide_opt_".concat(n,"][]"),l="frm_field_logic_opt_".concat(n),s=!1,c="select"===o||"checkbox"===o||"radio"===o,d="text"===o||"email"===o||"phone"===o||"url"===o||"number"===o;if(c&&document.getElementById("frm_has_hidden_options_".concat(e))&&(c=!1),c||d){var u=document.querySelector("#frm_logic_".concat(n,"_").concat(r,' [name="field_options[hide_field_cond_').concat(n,'][]"]')).value;i.innerHTML="";var f=c&&!["LIKE","not LIKE","LIKE%","%LIKE"].includes(u);f?s=document.createElement("select"):(s=document.createElement("input")).type="text",s.name=a,s.id="".concat(l,"_").concat(r),i.append(s),f&&gr(document.getElementById(s.id),{sourceID:e,placeholder:"",other:!0})}else{var m=this.getAttribute("data-type");frmGetFieldValues(e,n,r,m,void 0,function(){var e=new CustomEvent("frm_logic_options_loaded");e.frmData={valueFieldType:o,fieldID:n,metaKey:r},document.dispatchEvent(e)})}}}function Lr(){var e=this.value;e&&Ir(e,jQuery(this).closest(".frm-single-settings").data("fid"))}function Ir(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 n=jQuery("#frm_show_selected_fields_".concat(t));n.toggleClass("frm6",!e.includes("frm-inline-message")),n.html(e).show()}})}function qr(){var e=this;return this.initOnceInAllInstances=function(){void 0===qr.prototype.orderFieldsObject&&(qr.prototype.orderFieldsObject={},qr.prototype.fieldSettingsForm=document.getElementById("frm-end-form-marker").closest("form"))},this.getFieldOrderInputById=function(e,t){var n,r=qr.prototype.orderFieldsObject,o=qr.prototype.fieldSettingsForm;return void 0===r[e]?((n=o.querySelector('input[name="field_options[field_order_'.concat(e,']"]')))||(n=t.querySelector('input[name="field_options[field_order_'.concat(e,']"]'))),r[e]=n,n):r[e]},this.initOnceInAllInstances(),Gn(),function(){var t,n,r,o,i,a,l=new uo,s=jQuery("li.frm_field_box",jQuery("#frm-show-fields"));for(i=0;i<s.length;i++)t=s[i].getAttribute("data-fid"),(r=(n=e.getFieldOrderInputById(t,s[i]))?Object.assign({},n.value)[0]:null)!=(o=i+1)&&null!==r&&(n.value=o,a=s[i].querySelector("#frm-single-settings-".concat(t)),l.append(a),Vo());l.moveFields()}()}function Br(){document.querySelectorAll(".start_divider").forEach(function(e){Cr(jQuery(e))})}function Cr(e){if(e.length){for(var t=e.find("ul.frm_sorting"),n=!1,r=t.length,o=0;o<r;++o)if(0!==ue(jQuery(t.get(o))).length){n=!0;break}e.parent().children(".frm_no_section_fields").get(0).classList.toggle("frm_block",!n)}}function Nr(){var e=jQuery(this).data("slidedown"),t=jQuery(document.getElementById(e));return t.is(":hidden")&&(t.slideDown("fast"),this.style.display="none"),!1}function Tr(){var e=jQuery(this).data("slideup"),t=jQuery(document.getElementById(e));return t.slideUp("fast"),t.siblings("a").show(),!1}function Or(e,t){""===t.getAttribute("value")?Fr(jQuery(this)):function(e){var t=e.val();if(null===t)return e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!0),void Fr(e);var n=t.indexOf("");n>=0&&(t.splice(n,1),e.val(t),e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!1))}(jQuery(this))}function Fr(e){e.val(""),e.next(".btn-group").find('.multiselect-container input[value!=""]').prop("checked",!1)}function Dr(){jQuery(".frm-hide-empty").each(function(){0===jQuery(this).text().trim().length&&jQuery(this).remove()})}function Mr(e){e.preventDefault(),function(e,t,n){var r=document.getElementById(e.getAttribute("data-open")),o=jQuery(e).closest("p,ul"),i=void 0!==t;if(o.hasClass("frm-open"))o.removeClass("frm-open"),r.classList.add("frm_hidden");else{if(i||(t=ei(e)),t){if(!i){var a=n.key;"Enter"!==a&&" "!==a&&t.focus()}o.after(r),r.setAttribute("data-fills",t.id.replace("-proxy-input","")),0===r.id.indexOf("frm-calc-box")&&it(r,!0)}o.addClass("frm-open"),r.classList.remove("frm_hidden"),wp.hooks.doAction("frm_show_inline_modal",r,e)}}(this,void 0,e)}function Pr(e){e.preventDefault(),this.parentNode.classList.add("frm_hidden"),jQuery('.frm-open [data-open="'.concat(this.parentNode.id,'"]')).closest(".frm-open").removeClass("frm-open")}function Hr(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 zr(){var e,t=this.getAttribute("data-frmchange").split(",");for(e=0;e<t.length;e++)"updateOption"===t[e]?Gr(this):"updateDefault"===t[e]?Rr(this):"checkUniqueOpt"===t[e]?Sr(this):this.value=this.value[t[e]]()}function Rr(e){var t=Ur(e),n=t.getAttribute("data-optkey"),r=Wr(t,n),o=t.querySelector('input[name="default_value_'.concat(r,'"]'));null!==o&&(o.value=e.value)}function Gr(e){var t,n=Ur(e),r=n.getAttribute("data-optkey"),o=Wr(n,r),i=document.getElementById("separate_value_".concat(o));i&&!1===i.checked&&((t=document.getElementById("field_key_".concat(o,"-").concat(r))).value=e.value,Rr(t))}function Ur(e){var t=e.parentNode;return"LI"!==t.tagName&&(t=t.parentNode),t}function Wr(e,t){return e.id.replace("frm_delete_field_","").replace("-".concat(t,"_container"),"")}function $r(){var e=this;if(!Xr()){eo(this);var t=jQuery(Q),n=JSON.stringify(t.serializeArray());jQuery(document.getElementById("frm_compact_fields")).val(n),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_save_form",frm_compact_fields:n,nonce:frmGlobal.nonce},success:function(t){var n;(n=e).classList.remove("frm_loading_form"),n.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(),L=0,n.setAttribute("aria-busy","false"),setTimeout(function(){jQuery(".frm_updated_message").fadeOut("slow",function(){this.remove()})},5e3);var r,o=document.getElementById("post-body-content"),i=document.createElement("div");i.setAttribute("class","frm_updated_message"),i.innerHTML=t,o.insertBefore(i,o.firstChild),(r=document.getElementById("frm_submit_side_top")).hasAttribute("data-new-addon-installed")&&"true"===r.getAttribute("data-new-addon-installed")&&(r.removeAttribute("data-new-addon-installed"),window.location.reload())},error:function(){Vr(document.getElementById("frm_js_build_form"))}})}}function Vr(e){var t=e.ownerDocument.createElement("input");t.style.display="none",t.type="submit",e.append(t),t.click(),t.remove()}function Kr(e){jQuery(e).trigger("change")}function Jr(){if(!Xr()){eo(this);var e=jQuery(Q);jQuery(document.getElementById("frm_compact_fields")).val(JSON.stringify(e.serializeArray())),Vr(document.getElementById("frm_js_build_form"))}}function Xr(){if((t=document.getElementById("frm_form_name"))&&""!==t.value.trim()||"true"!==P.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,n=Mi("#frm-form-templates-modal","440px");return!!n&&(Zo(n,"72px"),n.dialog("open"),!0)}function Yr(){var e=document.getElementById("frm-save-form-name-button"),t=document.getElementById("frm_new_form_name_input");h(e,Zr),t.addEventListener("keydown",function(e){"Enter"===e.key&&Zr(e)})}var Zr=function(e){var t=document.getElementById("frm_new_form_name_input").value.trim(),n=new FormData;n.append("form_id",P.get("id")),n.append("form_name",t),b("rename_form",n).then(function(e){P.delete("new_template"),M.search=P.toString(),history.replaceState({},"",M.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 eo(e){var t,n;Hi(),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"),n={none:"",international:"international",currency:"currency",number:"number"},t.forEach(function(e){var t=e.value;t in n&&(document.getElementById("frm_format_".concat(e.dataset.fieldId)).value=n[t])})}function to(e){var t,n=null!==(t=e.target.dataset)&&void 0!==t&&t.modalTitle?e.target:e.target.closest("[data-modal-title]");if(n){var r=n.dataset,o=r.modalTitle,i=r.modalContent;o&&i&&(e.preventDefault(),frmDom.modal.maybeCreateModal("frmBasicModal",{title:o,content:_({className:"inside",child:p(i)})}))}}function no(e){var t,r,o,i=e.dataset.upgrade,a=e.getAttribute("href").replace("#",""),l=document.querySelector(".frm_".concat(a))||document.querySelector(".".concat(a));if(l&&!l.querySelector(".frm-upgrade-message")){var s=l.querySelector("h2");s.style.borderBottom="none",s.textContent=O(T("%s are not installed","formidable"),i),l.classList.add("frmcenter");var c=document.getElementById("frm_upgrade_modal");v("frm-oneclick"),v("frm-addon-status");var d=c.querySelector(".frm-upgrade-link");if(d){var u,f,m=d.closest(".frm-upgrade-modal-actions"),p=(f=m?(m=m.cloneNode(!0)).querySelector(".frm-upgrade-link"):d.cloneNode(!0)).querySelector(".license-level");p&&(p.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(e)),l.append(m||f),null!==(u=d.nextElementSibling)&&void 0!==u&&u.querySelector(".frm-link-secondary")&&l.append(d.nextElementSibling.cloneNode(!0)),v("frm-oneclick-button")}v("frm-upgrade-message");var g=e.dataset.message;void 0===g&&(g=e.dataset.upgrade),function(e,t,r){n(4260).addOneClick(e,"tab",r)}(e,0,g),e.dataset.screenshot&&l.append((t=e.dataset.screenshot,o="".concat(frmGlobal.url,"/images/screenshots/"),_({className:"frm-settings-screenshot-wrapper",children:[(r=["#ED8181","#EDE06A","#80BE30"].map(function(e){var t=_({className:"frm-minmax-icon"});return t.style.backgroundColor=e,t}),r.push(y({src:"".concat(frmGlobal.url,"/images/tab.svg")})),_({className:"frm-settings-screenshot-toolbar",children:r})),_({child:y({src:o+t})})]})))}function v(e){l.append(c.querySelector(".".concat(e)).cloneNode(!0))}}function ro(e){void 0===e&&(e=""),function(e){var t,n=jQuery("".concat(e," :not(.frm_has_shortcodes) .frm_not_email_message, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_to, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_subject"));for(t=0;t<n.length;t++)n[t].parentNode.classList.add("frm_has_shortcodes")}(e),jQuery("".concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) input,").concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) textarea")).wrap('<span class="frm-with-right-icon"></span>').before('<svg class="frmsvg frm-show-box"><use href="#frm_more_horiz_solid_icon"/></svg>')}function oo(){var e="success";"options[edit_action]"===this.name&&(e="edit");var t=jQuery(this).val();jQuery(".".concat(e,"_action_box")).hide(),"redirect"===t?jQuery(".".concat(e,"_action_redirect_box.").concat(e,"_action_box")).fadeIn("slow"):"page"===t?jQuery(".".concat(e,"_action_page_box.").concat(e,"_action_box")).fadeIn("slow"):jQuery(".".concat(e,"_action_message_box.").concat(e,"_action_box")).fadeIn("slow")}function io(e){var t,n,r;if(e.stopPropagation(),!function(e){var t=jQuery(e),n=t.closest(".frm_form_action_settings"),r=n.find(".widget-inside");if(r.find("p, div, table").length)return!1;var o=n.find(".widget-top");return o.one("frm-action-loaded",function(){t.trigger("click"),n.removeClass("open"),r.hide()}),o.trigger("click"),!0}(e.target)){var o=e.target.closest(".frm_form_action_settings"),i=o.querySelectorAll(".wp-editor-area");i.length&&i.forEach(function(e){tinymce.EditorManager.execCommand("mceRemoveEditor",!0,e.id)});var a=jQuery(o).clone(),l=a.attr("id").replace("frm_form_action_",""),s=ao(l),c=null===(t=o.querySelector(".frm_action_name"))||void 0===t?void 0:t.value,d=function(e,t){for(var n=new Set(t),r=e,o=2;n.has(r);)r="".concat(e," (").concat(o,")"),o++;return r}((null!==(n=null===(r=o.querySelector(".widget-title h4 span:not(.frm-border-icon)"))||void 0===r?void 0:r.textContent.trim())&&void 0!==n?n:"").replace(/ \(\d+\)$/,""),lo(c));a[0].querySelector(".widget-title h4 span:not(.frm-border-icon)").textContent=d,a[0].querySelector('input[name$="['.concat(l,'][post_title]"]')).value=d,a.find(".frm_action_id, .frm-btn-group").remove(),a.find('input[name$="['.concat(l,'][ID]"]')).val(""),a.find(".widget-inside").hide(),a.find("input[type=text], textarea, input[type=number]").prop("defaultValue",function(){return this.value}),a.find("input[type=checkbox], input[type=radio]").prop("defaultChecked",function(){return this.checked});var u=new RegExp("\\[".concat(l,"\\]"),"g"),f=new RegExp("_".concat(l,'"'),"g"),m=new RegExp("_".concat(l," "),"g"),p=new RegExp("-".concat(l,'"'),"g"),g=new RegExp('"'.concat(l,'"'),"g"),v=a.html().replace(u,"[".concat(s,"]")).replace(f,"_".concat(s,'"'));v=(v=v.replace(m,"_".concat(s," "))).replace(p,"-".concat(s,'"')).replace(g,'"'.concat(s,'"'));var y=_({id:"frm_form_action_".concat(s),className:a.get(0).className});y.setAttribute("data-actionkey",s),y.innerHTML=v,y.querySelectorAll(".wp-editor-wrap, .wp-editor-wrap *").forEach(function(e){"string"==typeof e.className&&(e.className=e.className.replace(l,s)),e.id=e.id.replace(l,s)}),y.classList.remove("open"),document.getElementById("frm_notification_settings").append(y),i.length&&(i.forEach(function(e){frmDom.wysiwyg.init(e)}),y.querySelectorAll(".wp-editor-area").forEach(function(e){frmDom.wysiwyg.init(e)})),y.classList.contains("frm_single_on_submit_settings")&&y.querySelector("input.frm-page-search")&&ki(y),vi(),wp.hooks.doAction("frm_after_duplicate_action",y)}}function ao(e){var t=parseInt(e,10)+11;return document.getElementById("frm_form_action_".concat(t))&&(t=ao(++t)),t}function lo(e){return Array.from(document.querySelectorAll(".frm_single_".concat(e,"_settings .widget-title h4 span:not(.frm-border-icon)")),function(e){return e.textContent.trim()})}function so(){var e,t=jQuery(this).data("actiontype");if(!go(t)){var n=(e=Tn(document.querySelectorAll(".frm_form_action_settings"),"frm_form_action_"),void 0!==document.getElementById("frm_form_action_".concat(e))&&(e+=100),C>=e&&(e=C+1),C=e,e),r=I,o=lo(t),i=document.createElement("div");i.classList.add("frm_single_".concat(t,"_settings"));var a=document.getElementById("frm_notification_settings");a.append(i),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_action",type:t,list_id:n,form_id:r,nonce:frmGlobal.nonce,existing_titles:o},success:function(e){var r;Vo(),i.remove(),null===(r=document.querySelector(".frm-no-actions-message"))||void 0===r||r.classList.add("frm_hidden"),document.querySelectorAll(".frm_form_action_settings.open").forEach(function(e){return e.classList.remove("open")});var o=_();o.innerHTML=e;var l=o.querySelector(".widget-top");Array.from(o.children).forEach(function(e){return a.append(e)}),jQuery(".frm_form_action_settings").fadeIn("slow");var s,c,d=document.getElementById("frm_form_action_".concat(n));d.classList.add("open"),document.getElementById("post-body-content").scroll({top:d.offsetTop+10,left:0,behavior:"smooth"}),po(t),(c=["stripe","square","paypal"]).includes(s=t)&&c.forEach(function(e){e!==s&&po(e)}),ro("#frm_form_action_".concat(n)),vi(),ki(d),l&&jQuery(l).trigger("frm-action-loaded"),frmAdminBuild.hooks.doAction("frm_added_form_action",d)}})}}function co(e){e.on("Change",function(){!function(e){(function(){var e=document.querySelector(".frm-single-settings:not(.frm_hidden)");if(!e)return!1;var t=e.querySelector(".wp-editor-wrap");return t&&t.classList.contains("tmce-active")})()&&!tinyMCE.activeEditor.isHidden()&&(e.targetElm.value=e.getContent(),jQuery(e.targetElm).trigger("change"))}(e)})}function uo(e){var t=this;if(null!==e)return this.fragment=document.createDocumentFragment(),this.initOnceInAllInstances=function(){void 0===uo.prototype.endMarker&&(uo.prototype.endMarker=document.getElementById("frm-end-form-marker"))},this.append=function(e){var n=e?e.parentElement.classList:"";e&&(n.contains("frm_field_box")||n.contains("divider_section_only"))&&t.fragment.append(e)},this.moveFields=function(){Q.insertBefore(t.fragment,uo.prototype.endMarker)},this.initOnceInAllInstances(),void 0!==e?(this.append(e),void this.moveFields()):{append:this.append,moveFields:this.moveFields}}function fo(){var e=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),t=this.getAttribute("data-emailrow");jQuery("#frm_form_action_".concat(e," .frm_").concat(t,"_row")).fadeIn("slow"),jQuery(this).fadeOut("slow")}function mo(){var e=jQuery(this).closest(".frm_form_action_settings"),t=this.getAttribute("data-emailrow"),n=".frm_".concat(t,"_row"),r=".frm_".concat(t,"_button");jQuery(e).find(r).fadeIn("slow"),jQuery(e).find(n).fadeOut("slow",function(){jQuery(e).find("".concat(n," input")).val("")})}function _o(){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 po(e){var t,n,r=document.querySelectorAll(".frm_".concat(e,"_action"));go(e)?(t=r,n=vo(e)>0,t.forEach(function(e){e.classList.remove("frm_active_action"),e.classList.add("frm_inactive_action"),n&&e.classList.add("frm_already_used")})):r.forEach(function(e){e.querySelector(".frm_show_upgrade")||(e.classList.remove("frm_inactive_action","frm_already_used"),e.classList.add("frm_active_action"))})}function go(e){var t=function(e){return["paypal","stripe","square"].includes(e)&&(e="payment"),jQuery(".frm_single_".concat(e,"_settings")).length}(e)>=vo(e),n={type:e};return wp.hooks.applyFilters("frm_action_at_limit",t,n)}function vo(e){return parseInt(jQuery(".frm_".concat(e,"_action")).data("limit"),10)}function yo(){var e=a.only_one_action,t=this.dataset.limit,n=this.dataset.actiontype;n&&["paypal","stripe","square","payment"].includes(n)&&(e="stripe"===n?a.only_one_stripe_action:a.only_one_payment_action),void 0!==t&&((t=parseInt(t))>1?e=e.replace(1,t).trim():e+=" ".concat(a.edit_action_text)),G(e)}function ho(e,t){var n=jQuery(t).closest(".frm_form_action_settings").find(".frm_action_name").val(),r=document.getElementById("form_id").value,o=document.getElementById("frm_logic_row_".concat(e)),i=Tn(o.querySelectorAll(".frm_logic_row"),"frm_logic_".concat(e,"_")),a=_({id:"frm_logic_".concat(e,"_").concat(i),className:"frm_logic_row frm_hidden"}),l=document.getElementById("logic_link_".concat(e)),s=l?o.closest(".frm_logic_rows"):null;o.append(a),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_logic_row",email_id:e,form_id:r,meta_name:i,type:n,nonce:frmGlobal.nonce},success:function(e){a.insertAdjacentHTML("beforebegin",e),a.remove();var t=o.querySelector(".frm_logic_row:last-child"),n=t?t.querySelector(".frm-logic-rule-text"):null;n&&(n.textContent=o.dataset.ruleText||""),l&&l.classList.add("frm_hidden"),s&&(s.classList.remove("frm_hidden"),s.style.display="")}})}function bo(){return ho(jQuery(this).data("emailkey"),this),!1}function wo(){var e;if(this.checked){var t=this.getAttribute("data-emailkey");if(t&&null!==(e=this.dataset.toggleclass)&&void 0!==e&&e.startsWith("frm_logic_rows_")){var n=document.getElementById("frm_logic_row_".concat(t));n&&!n.querySelector(".frm_logic_row")&&ho(t,this)}}}function jo(){var e=jQuery("select.frm_single_post_field");e.css("border-color","");var t=this,n=jQuery(t).val();if(""===n||"checkbox"===n)return!1;e.each(function(){if(jQuery(this).val()===n&&this.name!==t.name)return this.style.borderColor="red",jQuery(t).val(""),G(a.field_already_used),!1})}function xo(){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 Eo(){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 ko(){var e,t,n=document.getElementById("frm_posttax_rows").childNodes,r=document.querySelector(".frm_post_parent_field"),o=document.querySelector(".frm_post_menu_order_field"),i=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_replace_posttax_options",post_type:i,nonce:frmGlobal.nonce},success:function(r){for(var o=0;o<n.length;o++)"DIV"===n[o].tagName&&(e=n[o].getElementsByTagName("select")[0],(t=document.createElement("select")).innerHTML=r,t.className=e.className,t.name=e.name,n[o].replaceChild(t,e))}}),r&&Qo(r,i,"frm_get_post_parent_option",function(e,t){r.querySelector(".frm_post_parent_opt_wrapper").innerHTML=e.replaceAll("REPLACETHISNAME",t),ki(r)}),o&&Qo(o,i,"frm_should_use_post_menu_order_option")}function Qo(e,t,n,r){var o=(e.querySelector(".frm_autocomplete_value_input")||e.querySelector("select")).getAttribute("name");jQuery.ajax({url:ajaxurl,method:"POST",data:{action:n,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 r&&r(t,o)}else console.error(t)},error:function(e){return console.error(e)}})}function So(){Lo("tax",this)}function Ao(){Lo("meta",this)}function Lo(e,t){var n,r,o=jQuery('input[name="id"]').val(),i=jQuery(t).closest(".frm_form_action_settings"),a=i.data("actionkey"),l=i.find(".frm_post_type").val(),s=0,c=document.querySelectorAll(".frm_post".concat(e,"_row"));c.length&&(r=n=c[c.length-1].id.replace("frm_post".concat(e,"_"),""),s=!isNaN(parseFloat(r))&&isFinite(r)?1+parseInt(n,10):1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_post".concat(e,"_row"),form_id:o,meta_name:s,tax_key:s,post_type:l,action_key:a,nonce:frmGlobal.nonce},success:function(t){var n,r;if(jQuery(document.getElementById("frm_post".concat(e,"_rows"))).append(t),jQuery(".frm_add_post".concat(e,"_row.button")).hide(),"meta"===e)for(jQuery(".frm_name_value").show(),n=document.querySelectorAll(".frm_toggle_cf_opts"),r=0;r<n.length-1;++r)n[r].style.display="none";else"tax"===e&&jQuery(".frm_posttax_labels").show()}})}function Io(){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"),n=jQuery(this).closest(".frm_posttax_row").attr("id").replace("frm_posttax_",""),r=jQuery(this).val(),o=jQuery(document.getElementById("".concat(n,"_show_exclude"))).is(":checked")?1:0,i=jQuery('select[name$="[post_category]['.concat(n,'][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:n,action_key:t,meta_name:r,field_id:i,show_exclude:o,nonce:frmGlobal.nonce},success:function(e){jQuery(document.getElementById("frm_posttax_".concat(n))).replaceWith(e)}})}}function qo(){var e=jQuery(this).closest(".frm_postmeta_row"),t=e.find(".frm_cancelnew"),n=e.find(".frm_enternew");return e.find("select.frm_cancelnew").is(":visible")?(t.hide(),n.show()):(t.show(),n.hide()),e.find("input.frm_enternew, select.frm_cancelnew").val(""),!1}function Bo(){var e=jQuery(this),t=e.val();"checkbox"===e.attr("type")&&!1===this.checked&&(t="");var n=e.data("toggleclass");""===t?jQuery(".".concat(n)).hide():(jQuery(".".concat(n)).show(),jQuery(".hide_".concat(n,"_").concat(t)).hide())}function Co(){Xr()||(eo(this),Vr(document.querySelector(".frm_form_settings")))}function No(e){return e.preventDefault(),To(jQuery(this),this.getAttribute("data-code")),!1}function To(e,t){var n=!1,r=e;if("object"===o(e)){if(e.hasClass("frm_noallow"))return;void 0===(r=jQuery(e).closest("[data-fills]").attr("data-fills"))&&void 0!==(r=e.closest("div").attr("class"))&&(r=r.split(" ")[1])}if(void 0===r){var i=document.activeElement;"search"===i.type?null===(r=i.id.replace("-search-input","")).match(/\d/gi)&&(r=(i=jQuery(".frm-single-settings:visible .".concat(r))).attr("id")):r=i.id}r&&(n=jQuery("#wp-".concat(r,"-wrap.wp-editor-wrap")).length>0);var a=jQuery(document.getElementById(r));if(void 0===e.attr("data-shortcode")&&(!a.length||void 0===a.attr("data-shortcode"))){var l=e.parents("ul.frm_code_list").attr("data-shortcode");"undefined"!==l&&"no"===l||(t="[".concat(t,"]"))}if(n&&(wpActiveEditor=r),!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:r,success:function(e){if(n){var t=document.createElement("p");t.innerText=e,send_to_editor(t.innerHTML)}else Oo(a,e)}})}else t=function(e,t,n){return"object"===o(t)&&t instanceof jQuery&&0===n[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),n?send_to_editor(t):Oo(a,t);return!1}function Oo(e,t){if(document.selection)e[0].focus(),document.selection.createRange().text=t;else{var n=e[0],r=n.selectionEnd;t=function(e,t,n,r){var o=e.data("sep");if(void 0===o)return t;var i=e.val();if(!i.trim().length)return t;var a=new RegExp("".concat(o,"\\s*$")),l=new RegExp("^\\s*".concat(o));return i.substr(0,n).trim().length&&!1===a.test(i.substr(0,n))&&(t=o+t),i.substr(r,i.length).trim().length&&!1===l.test(i.substr(r,i.length))&&(t+=o),t}(e,t,n.selectionStart,r),n.value=n.value.substr(0,n.selectionStart)+t+n.value.substr(n.selectionEnd,n.value.length);var o=r+t.length;!function(e,t){if(e.classList.contains("frm_classes")&&Fo(t)){var n=e.value.split(" ").filter(Fo);n.length&&(e.value=function(e,t,n){var r=e.split(" ").filter(function(e){return(e=e.trim()).length&&!t.includes(e)});return r.includes(n)||r.push(n),r.join(" ")}(e.value,n,t.trim()))}}(n,t),n.focus(),n.setSelectionRange(o,o)}Kr(e)}function Fo(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 Do(){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"),Ni(t,"change")):(e.classList.add("frm_hidden"),t.classList.remove("frm_hidden"),Ni(e,"change"))}function Mo(){var e=document.getElementById("frm-id-key-condition-id").checked?"frm-id-condition":"frm-key-condition",t=document.getElementById("frm-is-condition").value,n=document.getElementById("frm-text-condition").value,r=document.getElementById("frm-insert-condition"),o=(e=document.getElementById(e)).options[e.selectedIndex].value,i="if ".concat(o," ").concat(t,'="').concat(n,'"]');r.setAttribute("data-code","".concat(i+a.conditional_text,"[/if ").concat(o)),r.innerHTML="[".concat(i,"[/if ").concat(o,"]")}function Po(e){return e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href")}function Ho(e){var t;e.parentNode.parentNode.classList.contains("frm_has_shortcodes")&&(ni(),"use"===(t=ti(e)).tagName?Po(t=t.firstElementChild).includes("frm_close_icon")||Wo(t,"nofocus"):t.classList.contains("frm_close_icon")||Wo(t,"nofocus"))}function zo(e){e.preventDefault(),e.stopPropagation(),Wo(this)}function Ro(e){var t=e.target;!function(e){var t;if(e.id.startsWith("field_options_type_")){var n=e.id.split("_"),r=n.length&&n[n.length-1];null!==(t=document.querySelector("#frm-single-settings-".concat(r)))&&void 0!==t&&t.classList.contains("frm-type-".concat(e.value))||Go()}}(t),m(t)}function Go(e){var t;void 0===e&&(e=T("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:T("Save and Reload?","formidable"),content:(t=_(e),t.style.padding="var(--gap-md)",t),footer:function(){var e=frmDom.modal.footerButton({text:T("Save and Reload","formidable"),buttonType:"primary"});h(e,function(){var e;(e=document.getElementById("frm_submit_side_top")).classList.contains("frm_submit_ajax")&&e.setAttribute("data-new-addon-installed",!0),e.click()});var t=frmDom.modal.footerButton({text:T("Cancel","formidable"),buttonType:"cancel"});return t.classList.add("dismiss"),frmDom.div({children:[t,e]})}()})}function Uo(e){var t;if(e instanceof Event){var n=document.querySelectorAll(".frm-single-settings .frm-show-box.frmsvg use"),r=Array.from(n).find(function(e){return"#frm_close_icon"===e.getAttribute("href")});if(void 0===r)return;t=r.parentElement}else t=e;var o=t.getBoundingClientRect(),i=document.getElementById("frm_adv_info"),a=i.parentElement.getBoundingClientRect();i.style.top="".concat(o.top-a.top+32,"px"),i.style.left="".concat(o.left-a.left-280,"px")}function Wo(e,t){var n=ei(e),r=document.getElementById("frm_adv_info"),o=e.className;if("svg"===e.tagName&&(e=e.firstElementChild),"use"===e.tagName&&(o=Po(e)),o.includes("frm_close_icon"))ni(r);else{if(Uo(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"),r.setAttribute("data-fills",n.id),r.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"!==t&&("none"!==n.style.display?n.focus():jQuery(tinymce.get(n.id)).trigger("focus")),function(e){["address","body"].forEach(function(t){!function(e,t){var n,r=a.contextualShortcodes["".concat(t,"Selector")],o=a.contextualShortcodes[t],l=e.matches(r),s=i(o);try{for(s.s();!(n=s.n()).done;){var c,d=n.value,u=null===(c=document.querySelector('#frm-adv-info-tab .frm_code_list [data-code="'.concat(d,'"]')))||void 0===c?void 0:c.closest("li");null==u||u.classList.toggle("frm_hidden",!l)}}catch(e){s.e(e)}finally{s.f()}}(e,t)})}(n)}}function $o(e){return 0===a.contextualShortcodes.length||!function(e){var t=e.querySelector("a");if(!t)return!1;var n=t.dataset.code;return a.contextualShortcodes.address.includes(n)||a.contextualShortcodes.body.includes(n)}(e)||function(e){var t=e.querySelector("a").dataset.code,n=document.getElementById("frm_adv_info").dataset.fills,r=document.getElementById(n),o=a.contextualShortcodes;return o.address.includes(t)?r.matches(o.addressSelector):r.matches(o.bodySelector)}(e)}function Vo(){L||(L=1,window.addEventListener("beforeunload",Yo))}function Ko(){L=0}function Jo(){L=0}function Xo(){L=0}function Yo(e){L&&(e.preventDefault(),e.returnValue="")}function Zo(e,t){var n={my:"top",at:"top+".concat(t),of:window};e.dialog("option","position",n)}function ei(e){if(e.classList.contains("frm-input-icon"))return e.previousElementSibling;for(var t,n=e.nextElementSibling;n&&("INPUT"!==n.tagName&&"TEXTAREA"!==n.tagName||n.classList.contains("frm-token-input-field"));)n=ei(n);return n||(n=null===(t=e.closest(".frm-field-formula"))||void 0===t?void 0:t.querySelector(".frm-calc-field")),n}function ti(e){var t;if(null!==(t=e.nextElementSibling)&&void 0!==t&&t.classList.contains("frm-input-icon"))return e.nextElementSibling;for(var n=e.previousElementSibling;null!==n&&"I"!==n.tagName&&"svg"!==n.tagName;)n=ti(n);return n}function ni(e){if((void 0!==e||(e=document.getElementById("frm_adv_info")))&&null===document.getElementById("frm_dyncontent")){e.style.display="none";for(var t=document.querySelectorAll(".frm-show-box.frm_close_icon"),n=0;n<t.length;n++)t[n].classList.remove("frm_close_icon"),t[n].classList.add("frm_more_horiz_solid_icon");for(var r=document.querySelectorAll(".frm_has_shortcodes use"),o=0;o<r.length;o++)if("#frm_close_icon"===Po(r[o])){if(r[o].closest(".frm_remove_field"))continue;r[o].setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_more_horiz_solid_icon")}}}function ri(e,t){t.stopPropagation(),jQuery(".frm_code_list .frmids, .frm_code_list .frmkeys").addClass("frm_hidden"),jQuery(".frm_code_list .".concat(e)).removeClass("frm_hidden"),jQuery(".frmids, .frmkeys").removeClass("current"),jQuery(".".concat(e)).addClass("current")}function oi(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 ii(){return!0===R(this)&&(jQuery(".frm_uninstall .frm-wait").css("visibility","visible"),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_uninstall&nonce=".concat(frmGlobal.nonce),success:function(e){jQuery(".frm_uninstall").fadeOut("slow"),window.location=e}})),!1}function ai(){var e=jQuery(this),t=this.name,n=this.getAttribute("data-plugin"),r=t.replace("edd_".concat(n,"_license_"),""),o=document.getElementById("edd_".concat(n,"_license_key")).value;e.get(0).disabled=!0,jQuery.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_".concat(r),license:o,plugin:n,nonce:frmGlobal.nonce},success:function(t){e.get(0).disabled=!1;var i=e.closest(".edd_frm_license_row");"deactivate"===r&&(o="",document.getElementById("edd_".concat(n,"_license_key")).value=""),i.find(".edd_frm_license").html(o);var a=e.get(0).closest(".frm_form_field"),l=!0===t.success;a.querySelector(".frm_icon_font.frm_action_success").classList.toggle("frm_hidden",!l||"deactivate"===r),a.querySelector(".frm_icon_font.frm_action_error").classList.toggle("frm_hidden",l);var s=i.find(".frm_license_msg");s.html(t.message),""!==t.message&&setTimeout(function(){if(s.html(""),i.find(".frm_icon_font").addClass("frm_hidden"),l){var e="activate"===r;i.get(0).querySelector(".edd_frm_unauthorized").classList.toggle("frm_hidden",e),i.get(0).querySelector(".edd_frm_authorized").classList.toggle("frm_hidden",!e)}},2e3)}})}function li(e){e.preventDefault();var t=jQuery(e.target).find("input:checked");if(t.length){var n,r,o,i,a=[];t.each(function(e){a[e]=this.value}),n=a,r=e.target,(i=(o=jQuery(r)).next(".frm-importer-process")).find(".form-total").text(n.length),i.find(".form-current").text("1"),o.hide(),i.find(".process-completed").hide(),i.show(),D.importQueue=n,D.imported=0,si(i)}}function si(e){var t=D.importQueue[0],n=jQuery("#welcome-panel").find('input[name="slug"]').val(),r={action:"frm_import_".concat(n),form_id:t,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,r,function(n){var r;n.success&&(r=n.data.error?"<p>".concat(n.data.name,": ").concat(n.data.msg,"</p>"):'<p>Imported <a href="'.concat(n.data.link,'" target="_blank">').concat(n.data.name,"</a></p>"),e.find(".status").prepend(r),e.find(".status").show(),D.importQueue=jQuery.grep(D.importQueue,function(e){return e!=t}),D.imported++,0===D.importQueue.length?(e.find(".process-count").hide(),e.find(".forms-completed").text(D.imported),e.find(".process-completed").show()):(e.find(".form-current").text(D.imported+1),si(e)))})}function ci(e){e.preventDefault();var t=!1,n=jQuery('input[name="frm_export_forms[]"]');jQuery('input[name="frm_export_forms[]"]:checked').val()||(n.closest(".frm-table-box").addClass("frm_blank_field"),t="stop");var r=jQuery('input[name="type[]"]');if(jQuery('input[name="type[]"]:checked').val()||"checkbox"!==r.attr("type")||(r.closest("p").addClass("frm_blank_field"),t="stop"),"stop"===t)return!1;e.stopPropagation(),this.submit()}function di(){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 ui(){null!==jQuery(this).val().match(/\.csv$/i)?jQuery(".show_csv").fadeIn():jQuery(".show_csv").fadeOut()}function fi(){var e=document.querySelector('select[name="format"]');return e?e.value:""}function mi(e){var t,n,r=e.target.value;pi(r),_i.call(e.target),t=r,n=document.getElementById("frm-export-select-all"),"csv"===t?(n.checked=!1,n.disabled=!0):n.disabled=!1}function _i(){var e=jQuery(this),t=e.find(":selected"),n=t.data("support"),r=n.indexOf("|");jQuery('input[name="type[]"]').each(function(){this.checked=!1,n.includes(this.value)?(this.disabled=!1,-1===r&&(this.checked=!0)):this.disabled=!0}),"csv"===e.val()?(jQuery(".csv_opts").show(),jQuery(".xml_opts").hide()):(jQuery(".csv_opts").hide(),jQuery(".xml_opts").show());var o=t.data("count"),i=jQuery('input[name="frm_export_forms[]"]');"single"===o?(i.prop("multiple",!1),i.prop("checked",!1)):(i.prop("multiple",!0),i.prop("disabled",!1)),e.trigger("change")}function pi(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")}),qi.call(document.querySelector(".frm-auto-search")))}}function gi(){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 vi(){jQuery(".frm_multiselect").hide().each(frmDom.bootstrap.multiselect.init)}function yi(e){e.preventDefault(),wi(this,"frm_multiple_addons")}function hi(e){e.preventDefault(),wi(this,"frm_activate_addon")}function bi(e){e.preventDefault(),wi(this,"frm_install_addon")}function wi(e,t){n(1105).toggleAddonState(e,t)}function ji(){Ei()}function xi(e){!function(e,t,n){var r=jQuery("#frm_leave_email_error");r.removeClass("frm_hidden").attr("frm-error",n),jQuery("#frm_leave_email").one("keyup",function(){r.addClass("frm_hidden")})}(0,0,e)}function Ei(){var e=document.getElementById("frmapi-email-form");jQuery.ajax({dataType:"json",url:e.getAttribute("data-url"),success:function(t){var n=t.renderedHtml;n=n.replace(/<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi,""),e.innerHTML=n}})}function ki(e){frmDom.autocomplete.initSelectionAutocomplete(e)}function Qi(e){var t=this.parentNode.parentNode,n=t.elements.type.value;e.preventDefault(),this.classList.add("frm_loading_button"),Ai(t,n,this)}function Si(e){var t=this.elements.type.value,n=this.querySelector("button");e.preventDefault(),n.classList.add("frm_loading_button"),Ai(this,t,n)}function Ai(e,t,n){var r=function(e){var t,n,r={},o=e.elements;for(n=0;n<o.length;n++){var i=o[n],a=i.name,l=i.value,s=a.match(/(.*)\[(.*)\]/);("radio"!==i.type&&"checkbox"!==i.type||i.checked)&&(null===s?Reflect.has(r,a)?(Array.isArray(r[a])||(r[a]=[r[a]]),r[a].push(l)):r[a]=l:(a=s[1],t=s[2],Reflect.has(r,a)||(r[a]={}),r[a][t]=l))}return r}(e),o=r.template_name,i=r.template_desc,a=e.elements.link.value,l={action:t,xml:a,name:o,desc:i,form:JSON.stringify(r),nonce:frmGlobal.nonce},s={formData:r};Ti(l=wp.hooks.applyFilters("frm_before_install_new_form",l,s),function(t){if(void 0!==t.redirect){var r=t.redirect;if(void 0===e.elements.redirect)window.location=r;else{var o=document.getElementById("frm-redirect-link");void 0!==a&&o&&(o.setAttribute("href",r),o.classList.remove("frm_grey","disabled"),(i=e.parentNode.parentNode).classList.add("frm_grey"),i.nextElementSibling.classList.remove("frm_grey"),n.classList.add("frm_grey","disabled"))}}else jQuery(".spinner").css("visibility","hidden"),"string"==typeof t.message&&function(e){var t=_(e);t.style.padding="20px 40px",frmDom.modal.maybeCreateModal("frmInstallFormErrorModal",{title:T("Unable to install template","formidable"),content:t}).classList.add("frm_common_modal")}(t.message);var i;n.classList.remove("frm_loading_button")})}function Li(e){var t=document.getElementById("frm_captcha_threshold_container");t&&t.classList.toggle("frm_hidden","v3"!==e.target.value)}function Ii(e){var t=this.getAttribute("data-id");e.preventDefault(),Ti({action:"frm_forms_trash",id:t,nonce:frmGlobal.nonce},function(){var e=document.getElementById("frm-template-custom-".concat(t));Oi(e,function(){e.remove()})})}function qi(){var e,t,n=!1,r=this.value.toLowerCase(),o=this.getAttribute("data-tosearch"),i=document.getElementsByClassName(o);for("SELECT"===this.tagName&&(r=function(e){for(var t,n=[],r=null==e?void 0:e.options,o=0,i=null==r?void 0:r.length;o<i;o++)(t=r[o]).selected&&n.push(t.value);return n}(this),r=r.join("|").toLowerCase(),n=!0),e=0;e<i.length;e++){var a=i[e].textContent.toLowerCase(),l=!("xml"===fi()&&i[e].classList.contains("frm-is-repeater"));""===r?(l&&$o(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.remove("frm-search-result")):n&&new RegExp(r).test(a)||a.includes(r)||Bi(a,r)?(l&&$o(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.add("frm-search-result")):(i[e].classList.add("frm_hidden"),i[e].classList.remove("frm-search-result"))}(t=document.querySelector("#frm-insert-fields"))&&t.querySelectorAll(":scope > .frm-with-line").forEach(function(e){var t=e.nextElementSibling;if(t){var n=t.querySelectorAll(":scope > li.frmbutton"),r=Array.from(n).every(function(e){return e.classList.contains("frm_hidden")});e.classList.toggle("frm_hidden",r)}}),jQuery(this).trigger("frmAfterSearch")}function Bi(e,t){return"s"!==t&&"s"!==e[e.length-1]&&"".concat(e,"s").includes(t)}function Ci(e){e.stopPropagation()}function Ni(e,t){var n=document.createEvent("HTMLEvents");n.initEvent(t,!1,!0),e.dispatchEvent(n)}function Ti(e,t){var n,r=new XMLHttpRequest,o="string"==typeof e?e:Object.keys(e).map(function(t){return"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(e[t]))}).join("&");return r.open("post",ajaxurl,!0),r.onreadystatechange=function(){if(r.readyState>3&&200==r.status){n=r.responseText;try{n=JSON.parse(n)}catch(e){}t(n)}},r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.send(o),r}function Oi(e,t){e.classList.add("frm-fade"),setTimeout(t,1e3)}function Fi(e){jQuery(e).css("visibility","hidden")}function Di(e){jQuery(e).css("visibility","visible")}function Mi(e,t){return n(4260).initModal(e,t)}function Pi(e,t,n){if("#"===t){var r=document.getElementById(e);if(void 0!==n)r.style.display=n?"block":"none";else{var o=r.style.display;r.style.display="none"===o?"block":"none"}}else void 0!==n?n?e.show():e.hide():e.is(":visible")?e.hide():e.show()}function Hi(){window.onbeforeunload=null;var e=jQuery(window);e.off("beforeunload.widgets"),e.off("beforeunload.edit-post")}function zi(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));if(t&&"form"===t.dataset.type)if(t=jQuery(t),this.options[this.selectedIndex].value){t.find(".frm-not-set")[0].classList.add("frm_hidden");var n=t.find(".frm-embed-message");n.html(n.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 Ri(e){var t=e.target,n=t.value.trim();if(!n.includes("[")||!n.includes("]")){if(isNaN(n.replace(/,/,""))){var r=T("Please enter a valid number.","formidable");return frmAdminBuild.infoModal(r),void function(e){var t=document.querySelectorAll("#frm_info_modal .dismiss, #frm_info_modal #frm-info-click, .ui-widget-overlay.ui-front");function n(){e.classList.add("frm_invalid_field"),setTimeout(function(){return e.focus()},0),t.forEach(function(e){e.removeEventListener("click",n)})}t.forEach(function(e){e.addEventListener("click",n)})}(t)}t.classList.remove("frm_invalid_field")}}function Gi(){var e=jQuery(this).closest(".frm-single-settings"),t=e.find(".frmjs_product_choices"),n=e.find(".frm_prod_options_heading"),r=this.options[this.selectedIndex].value,o=e[0].querySelector(".frm_display_format_options");o&&o.setAttribute("data-product-type",r),t.removeClass("frm_prod_type_single frm_prod_type_user_def"),n.removeClass("frm_prod_user_def"),"single"===r?t.addClass("frm_prod_type_single"):"user_def"===r&&(t.addClass("frm_prod_type_user_def"),n.addClass("frm_prod_user_def")),wp.hooks.doAction("frm_product_type_toggled",r,e[0])}function Ui(e){var t=document.getElementById("frm_field_id_".concat(e));return!!t&&"product"===t.getAttribute("data-type")}function Wi(){var e=function(e,t){return window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]},t=function(e,t,n){window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]=n},n=[1,2,3,4,5,6,7,8,9,10,11,12].map(function(e){return"frm".concat(e)}),o=["first","middle","last"];document.addEventListener("change",function(i){i.target.matches(".frm_name_layout_dropdown")&&function(i){var a,l=i.target.value.split("_"),s=i.target.dataset.fieldId,c=document.querySelector("#field_".concat(s,"_inner_container .frm_combo_inputs_container")),d=(a=l.length,"frm".concat(parseInt(12/a)));o.forEach(function(e){var o,i=c.querySelector('[data-sub-field-name="'.concat(e,'"]'));i&&(i.classList.add("frm_hidden"),(o=i.classList).remove.apply(o,r(n)),t(s,e,i))}),l.forEach(function(t){var n=e(s,t);n&&(n.classList.remove("frm_hidden"),n.classList.add(d),c.append(n))}),o.forEach(function(e){var n=document.querySelector(".frm_sub_field_options-".concat(e,'[data-field-id="').concat(s,'"]'));n&&(n.classList.add("frm_hidden"),t(s,"".concat(e,"_options"),n))}),l.forEach(function(t){var n=e(s,"".concat(t,"_options"));n&&n.classList.remove("frm_hidden")})}(i)},!1)}function $i(e,t){var n,r,o,i=!1,a=!1;(n=t.newOption?(new DOMParser).parseFromString(t.newOption,"text/html").body.childNodes[0]:t).querySelectorAll("svg").forEach(function(e){(r=e.getElementsByTagNameNS("http://www.w3.org/2000/svg","use")[0])&&("#frm_drag_icon"===(o=Po(r))&&(i=!0),"#frm_save_icon"===o&&(a=!0))}),i||n.prepend(E.drag.cloneNode(!0)),n.querySelector("[id^=field_key_".concat(e,"-]"))&&!a&&n.querySelector("[id^=field_key_".concat(e,"-]")).after(E.save.cloneNode(!0)),t.newOption&&(t.newOption=n)}function Vi(){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"),n=t.find('[type="email"]').not(".frm_verify");if(n.length){if(document.getElementById("frm_empty_inbox")){document.getElementById("frm-add-my-email-address").remove();var r=document.getElementById("frm_leave_email_wrapper");if(r){r.classList.add("frm_hidden");var o=p({className:"frm-wait frm_spinner"});o.style.visibility="visible",o.style.float="none",o.style.width="unset",r.parentElement.insertBefore(o,r.nextElementSibling)}}n.val(e),jQuery.ajax({type:"POST",url:t.attr("action"),data:"".concat(t.serialize(),"&action=frm_forms_preview")}).done(function(e){if(jQuery(e).find(".frm_message").text().trim().includes("Thanks!")){var t=document.getElementById("frmapi-email-form").parentElement.querySelector(".frm_spinner");t&&t.remove(),wp.hooks.applyFilters("frm_thank_you_on_signup",!0)&&document.getElementById("frm_leave_email_wrapper").replaceWith(p(T("Thank you for signing up!","formidable")))}else xi("invalid")})}}else xi("invalid");else xi("empty")}function Ki(e){var t;if(H||e.stopPropagation(),!(e.target.classList.contains("frm-show-box")||null!==(t=e.target.parentElement)&&void 0!==t&&t.classList.contains("frm-show-box"))){var n=document.getElementById("frm_adv_info");n&&(n.dataset.fills===e.target.id&&void 0!==e.target.id||e.target.closest("#frm_adv_info")||"none"===n.style.display||ni(n))}}return{init:function(){var e,t,o,i,a,l,s;!function(){jQuery(document).on("click","#frm-add-my-email-address",function(e){e.preventDefault(),Vi()});var e=document.getElementById("frm_empty_inbox"),t=document.getElementById("frm_leave_email");if(e&&t){var n=document.getElementById("frm-leave-email-modal");n.classList.remove("frm_hidden"),n.querySelector(".frm_modal_footer").classList.add("frm_hidden"),t.addEventListener("keyup",function(e){if("Enter"===e.key){var t=document.getElementById("frm-add-my-email-address");t&&t.click()}})}}(),t=document.querySelector(".frm-admin-footer-links"),o=null!==(e=document.querySelector(".frm_page_container"))&&void 0!==e?e:document.getElementById("wpbody-content"),t&&o&&(o.append(t),t.classList.remove("frm_hidden")),document.addEventListener("show.bs.dropdown",function(){$()}),D={},jQuery(".wp-admin").on("click",function(e){var t=jQuery(e.target),n=jQuery(".dropdown.open");!n.length||t.hasClass("dropdown")||t.closest(".dropdown").length||n.removeClass("open")}),jQuery("#frm_bs_dropdown:not(.open) a").on("click",Ct),void 0===I&&(I=jQuery(document.getElementById("form_id")).val()),document.querySelectorAll(".frm-warning-dismiss").forEach(function(e){h(e,Nt)}),frmAdminBuild.inboxBannerInit(),k.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=_({className:"frm_warning_style",text:T("Only 10 columns can be selected at a time.","formidable")});t.style.margin=0;var n=e.querySelector("legend");n.parentNode.insertBefore(t,n.nextElementSibling);var r=Array.from(e.querySelectorAll('input[type="checkbox"]')),o=function(){r.reduce(function(e,t){return t.checked?e+1:e},0)>=10?(t.classList.remove("frm_hidden"),r.forEach(function(e){e.checked||(e.parentNode.classList.add("frm_noallow"),e.disabled=!0)})):t.classList.add("frm_hidden")};o(),r.forEach(function(e){e.addEventListener("change",function(e){e.target.checked?o():(t.classList.add("frm_hidden"),r.forEach(function(e){e.parentNode.classList.remove("frm_noallow"),e.disabled=!1}))})})}}}(),ki(),jQuery("[data-frmprint]").on("click",function(){return window.print(),!1})),jQuery(document).on("change","select[data-toggleclass], input[data-toggleclass]",Bo),function(){function e(e){var t=e.options[e.selectedIndex];e.querySelectorAll("option[data-dependency]:not([data-dependency-skip])").forEach(function(e){var n=document.querySelector(e.dataset.dependency);null==n||n.classList.toggle("frm_hidden",t!==e)})}document.querySelectorAll("select.frm_select_with_dependency").forEach(e),frmDom.util.documentOn("change","select.frm_select_with_dependency",function(t){return e(t.target)})}(),(jQuery(document.getElementById("frm_adv_info")).length>0||jQuery(".frm_field_list").length>0)&&frmAdminBuild.panelInit(),i=jQuery(".wrap, .frm_wrap"),a=document.getElementById("frm_confirm_modal"),l=!1,s=!1,jQuery(a).on("click","[data-deletefield]",In),jQuery(a).on("click","[data-removeid]",V),jQuery(a).on("click","[data-trashtemplate]",Ii),i.on("click",".frm_remove_tag, .frm_remove_form_action",V),i.on("click","a[data-frmverify]",z),i.on("click","a[data-frmtoggle]",U),i.on("click","a[data-frmhide], a[data-frmshow]",W),i.on("change","input[data-frmhide], input[data-frmshow]",W),i.on("click",".widget-top,a.widget-action",J),function(e){e.on("keydown",".widget-top",function(e){e.currentTarget===e.target&&("Enter"!==e.key&&" "!==e.key||(e.preventDefault(),J(e,e.currentTarget)))});var t=function(e){return function(t){t.key===e&&(t.preventDefault(),t.currentTarget.click())}};e.on("keydown",".frm_form_action_settings .frm_duplicate_form_action, .frm_form_action_settings .frm_remove_form_action",t(" ")),e.on("keydown",".frm_form_action_settings .frm_toggle",t("Enter"))}(i),i.on("mouseenter.frm",".frm_bstooltip, .frm_help",function(){jQuery(this).off("mouseenter.frm"),function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=e;(n.hasAttribute("data-toggle")||n.hasAttribute("data-bs-toggle"))&&(n.parentElement.setAttribute("title",n.getAttribute("title")),n.removeAttribute("title"),n.classList.remove("frm_bstooltip"),n.parentElement.classList.add("frm_bstooltip"),n=n.parentElement);var r=new bootstrap.Tooltip(n);t&&($(),r.show())}(this,!0)}),jQuery(document).on("click","#doaction, #doaction2",function(e){var t="doaction"===this.id?"top":"bottom",n=document.getElementById("bulk-action-selector-".concat(t)),r=document.getElementById("confirm-bulk-delete-".concat(t));if(n&&r){if(l=this,!s&&"bulk_delete"===n.value)return e.preventDefault(),R(r),!1}else l=!1}),jQuery(document).on("click","#frm-confirmed-click",function(e){if(!1!==l&&!e.target.classList.contains("frm-btn-inactive"))return"confirm-bulk-delete"===this.getAttribute("href")?(e.preventDefault(),s=!0,l.click(),!1):void 0}),n(4260).initUpgradeModal(),frmDom.util.documentOn("click","[data-modal-title]",to);var c=jQuery(document.getElementById("frm_shortcodediv"));c.length>0&&(jQuery("a.edit-frm_shortcode").on("click",function(){return c.is(":hidden")&&(c.slideDown("fast"),this.style.display="none"),!1}),jQuery(".cancel-frm_shortcode","#frm_shortcodediv").on("click",function(){return c.slideUp("fast"),c.siblings("a.edit-frm_shortcode").show(),!1})),jQuery(document).on("click","#frm-nav-tabs a",X),jQuery(".post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a").on("click",function(){var e=this.classList.contains("frm_show_upgrade_tab");if(!this.classList.contains("frm_noallow")||e)return e&&this.classList.contains("frm_show_expired_modal")?(wp.hooks.doAction("frm_show_expired_modal",this),!1):(e&&no(this),Y(this),!1)}),Y(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),Vr(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)",qi),jQuery(document).on("focusin click",".frm-auto-search",Ci);var d=jQuery(".frm-auto-search");""!==d.val()&&d.trigger("keyup"),FrmFormsConnect.init(),jQuery(document).on("click",".frm-install-addon",bi),jQuery(document).on("click",".frm-activate-addon",hi),jQuery(document).on("click",".frm-solution-multiple",yi),jQuery("button, input[type=submit]").on("click",Hi),document.addEventListener("click",function(e){if("LABEL"===e.target.nodeName){var t=e.target.getAttribute("for");if(t){var n=document.getElementById(t);if(n&&n.nextElementSibling){var r=n.nextElementSibling.querySelector("button.dropdown-toggle.multiselect");r&&setTimeout(function(){return r.click()},0)}}}}),frmAdminBuild.hooks.addFilter("frm_before_embed_modal",function(e,t){var n,r,o=t.element;if("form"!==t.type)return e;var i=o.closest("tr");if(i)n=parseInt(i.querySelector(".column-id").textContent),r=i.querySelector(".column-form_key").textContent;else{n=document.getElementById("form_id").value;var a=document.getElementById("frm_form_key");if(a)r=a.value;else{var l=document.getElementById("frm-previewDrop");l&&(r=l.nextElementSibling.querySelector(".dropdown-item a").getAttribute("href").split("form=")[1])}}return[n,r]}),document.querySelectorAll("#frm-show-fields > li, .frm_grid_container li").forEach(function(e,t){e.addEventListener("click",function(){var e,t,n;t=(null===(e=this.querySelector("li"))||void 0===e?void 0:e.dataset.fid)||this.dataset.fid,(n=document.querySelectorAll("[id^=frm_delete_field_".concat(t,"-]"))).length<2||r(n).slice(1).forEach(function(e,n){e.classList.contains("frm_other_option")||$i(t,e)})})});var u=document.getElementById("frm_small_screen_proceed_button");u&&h(u,function(){var e;null===(e=document.getElementById("frm_small_device_message_container"))||void 0===e||e.remove(),b("small_screen_proceed",new FormData)});var f=document.getElementById("frm_sale_banner"),m=null==f?void 0:f.querySelector(".dismiss");f&&(h(f,function(e){e.target.closest(".dismiss")||(window.location.href=f.getAttribute("data-url"))}),m&&h(m,function(){f.remove();var e=new FormData;b("sale_banner_dismiss",e)}))},buildInit:function(){jQuery("#frm_builder_page").on("mouseup","*:not(.frm-show-box)",Ki),w=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return frmDom.util.debounce(e,t)}(de,10),j=document.getElementById("post-body-content"),x=jQuery(j),jQuery(".frm_field_loading").length&&qe(jQuery(".frm_field_loading").first().attr("id")),Z("ul.frm_sorting"),document.querySelectorAll(".field_type_list > li:not(.frm_show_upgrade):not(.frm_show_update)").forEach(re),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",$r),jQuery(".frm_submit_no_ajax").on("click",Jr),Yr(),jQuery("a.edit-form-status").on("click",Nr),jQuery(".cancel-form-status").on("click",Tr),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")}),vi(),Gn();var e,t=jQuery(Q),n=document.getElementById("frm_form_editor_container");t.on("click",".frm_add_logic_row",Nn),t.on("click",".frm_add_watch_lookup_row",On),t.on("change",".frm_get_values_form",zn),t.on("change",".frm_logic_field_opts",Ar),t.on("frm-multiselect-changed",'select[name^="field_options[admin_only_"]',Or),jQuery(document.getElementById("frm-insert-fields")).on("click",".frm_add_field",Ce),k.on("click",".frm_clone_field",Fe),t.on("blur",'input[id^="frm_calc"]',nt),t.on("change","input.frm_format_opt, input.frm_max_length_opt",mt),t.on("change click","[data-changeme]",ut),t.on("click","input.frm_req_field",_t),t.on("click",".frm_mark_unique",gt),t.on("change",".frm_repeat_format",rr),t.on("change",".frm_repeat_limit",or),t.on("change",".frm_js_checkbox_limit",ir),t.on("input",'input[name^="field_options[add_label_"]',function(){ar(this,"add")}),t.on("input",'input[name^="field_options[remove_label_"]',function(){ar(this,"remove")}),t.on("change",'select[name^="field_options[data_type_"]',Rn),jQuery(n).on("click",".frm-collapse-page",Un),jQuery(n).on("click",".frm-collapse-section",Vn),t.on("click",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",Kn),t.on("keydown",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),Kn.call(this,e))}),jQuery(n).on("show.bs.dropdown hide.bs.dropdown",$e),t.on("change",".frm_toggle_sep_values",xt),t.on("change",".frm_toggle_image_options",Et),t.on("click",".frm_remove_image_option",qt),t.on("click",".frm_choose_image_box",It),t.on("change",".frm_hide_image_text",Lt),t.on("change",".frm_field_options_image_size",St),t.on("click",".frm_multiselect_opt",Bt),k.on("mousedown","input, textarea, select",Tt),k.on("click","input[type=radio], input[type=checkbox]",Tt),k.on("click",".frm_delete_field",Pt),k.on("click",".frm_select_field",Ht),jQuery(document).on("click",".frm_delete_field_group",zt),jQuery(document).on("click",".frm_clone_field_group",Rt),jQuery(document).on("click","#frm_field_group_controls > span:first-child",Gt),jQuery(document).on("click",".frm-row-layout-option",on),jQuery(document).on("click",".frm-merge-fields-into-row .frm-row-layout-option",an),jQuery(document).on("click",".frm-custom-field-group-layout",sn),jQuery(document).on("click",".frm-merge-fields-into-row .frm-custom-field-group-layout",dn),jQuery(document).on("click",".frm-break-field-group",pn),k.on("click","#frm_field_group_popup .frm_grid_container input",gn),jQuery(document).on("click",".frm-cancel-custom-field-group-layout",vn),jQuery(document).on("click",".frm-save-custom-field-group-layout",hn),k.on("click","ul.frm_sorting",bn),jQuery(document).on("click",".frm-merge-fields-into-row",Sn),jQuery(document).on("click",".frm-delete-field-groups",Ln),k.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",He)}),k.on("mousemove","ul.frm_sorting",ze),k.on("show.bs.dropdown",".frm-field-action-icons",Ue),jQuery(document).on("show.bs.dropdown","#frm_field_group_controls",We),t.on("click",".frm_single_option a[data-removeid]",Ot),t.on("mousedown",".frm_single_option input[type=radio]",Ft),t.on("focusin",".frm_single_option input[type=text]",Dt),t.on("click",".frm_add_opt",bt),t.on("change",".frm_single_option input",sr),t.on("change",".frm_image_id",sr),t.on("change",".frm_toggle_mult_sel",wt),k.on("click",".frm_primary_label",Xn),k.on("click",".frm_description",Yn),k.on("click","li.ui-state-default:not(.frm_noallow)",er),k.on("dblclick","li.ui-state-default",nr),t.on("change",".frm_tax_form_select",lr),t.on("change","select.conf_field",vt),t.on("change",".frm_get_field_selection",Lr),t.on("click",".frm-show-inline-modal",Mr),t.on("keydown",".frm-show-inline-modal",function(e){var t=e.key;"Enter"!==t&&" "!==t||(e.preventDefault(),Mr.call(this,e))}),t.on("click",".frm-inline-modal .dismiss",Pr),jQuery(document).on("change","[data-frmchange]",zr),document.addEventListener("click",Hr),t.on("change",".frm_include_extras_field",at),t.on("change",'select[name^="field_options[form_select_"]',zi),jQuery(document).on("submit","#frm_js_build_form",Ko),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",Vo),ct(),frmDom.util.documentOn("change",".frm_product_price",Ri),jQuery(document).on("change",".frmjs_prod_data_type_opt",Gi),jQuery(document).on("focus",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',Dn),jQuery(document).on("blur",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',Pn),frmDom.util.documentOn("click",".frm-show-field-settings",er),frmDom.util.documentOn("change","select.frm_format_dropdown, select.frm_phone_type_dropdown",tr),t.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_"]'),n=Array.from(t),r=n.indexOf(e);if(!(r<0)){var o=n.slice(r+1).find(function(e){return null!==e.offsetParent});if(o){o.focus();var i=o.value.length;o.setSelectionRange(i,i)}}}(e.currentTarget)}),!1!==(e=Mi("#frm-bulk-modal","700px"))&&(jQuery(".frm-insert-preset").on("click",ht),jQuery(Q).on("click","a.frm-bulk-edit-link",function(t){t.preventDefault();var n="",r=jQuery(this).closest("[data-fid]").data("fid"),o=xr(r),i=Ui(r),a=document.getElementById("frm_field_".concat(r,"_opts"));if(a){var l=a.getElementsByTagName("li");document.getElementById("bulk-field-id").value=r;for(var s=0;s<l.length;s++){var c=l[s].getAttribute("data-optkey");if("000"!==c){var d=document.getElementsByName("field_options[options_".concat(r,"][").concat(c,"][label]"))[0];void 0!==d&&(n+=d.value,o&&(n+="|".concat(document.getElementsByName("field_options[options_".concat(r,"][").concat(c,"][value]"))[0].value)),i&&(n+="|".concat(document.getElementsByName("field_options[options_".concat(r,"][").concat(c,"][price]"))[0].value)),n+="\r\n")}s>=l.length-1&&(document.getElementById("frm_bulk_options").value=n)}return e.dialog("open"),!1}}),jQuery("#frm-update-bulk-opts").on("click",function(){var t=document.getElementById("bulk-field-id").value;document.getElementById("bulk-option-type").value||(this.classList.add("frm_loading_button"),frmAdminBuild.updateOpts(t,document.getElementById("frm_bulk_options").value,e),Vo())})),Dr(),document.addEventListener("frm_added_field",Dr),Oe(),Wi(),Br(),frmDom.util.documentOn("change",".frm_show_password_setting_input",function(e){var t=e.target.getAttribute("data-fid"),n=document.getElementById("frm_field_id_".concat(t));n&&n.classList.toggle("frm_disabled_show_password",!e.target.checked)}),document.addEventListener("scroll",Uo,!0),document.addEventListener("change",Ro),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(Jn)},9999),frm_admin_js.pricingFieldsModal&&"object"===o(frm_admin_js.pricingFieldsModal)&&G(frm_admin_js.pricingFieldsModal,"550px")},settingsInit:function(){var e=jQuery(document.getElementById("frm_notification_settings"));e.on("click",".frm_email_buttons",fo),e.on("click",".frm_remove_field",mo),e.on("change",".frm_to_row, .frm_from_row",_o),e.on("change",".frm_tax_selector",Io),e.on("change","select.frm_single_post_field",jo),e.on("change","select.frm_toggle_post_content",xo),e.on("change","select.frm_dyncontent_opt",Eo),e.on("change",".frm_post_type",ko),e.on("click",".frm_add_postmeta_row",Ao),e.on("click",".frm_add_posttax_row",So),e.on("click",".frm_toggle_cf_opts",qo),e.on("click",".frm_duplicate_form_action",io),jQuery(".frm_actions_list").on("click",".frm_active_action",so),jQuery(document).on("frmAfterSearch","#actions-search-input",K),vi(),document.querySelectorAll(".frm_actions_list a[data-actiontype]").forEach(function(e){return po(e.dataset.actiontype)}),jQuery(".frm_submit_settings_btn").on("click",Co),Yr();var t=jQuery(".frm_form_settings");t.on("click",".frm_add_form_logic",bo),t.on("change","input[data-emailkey][data-toggleclass]",wo),t.on("click",".frm_already_used",yo),document.addEventListener("click",function(e){var t=e.target;t.closest(".frm_image_preview_wrapper")&&(t.closest(".frm_choose_image_box")?It.bind(t)(e):t.closest(".frm_remove_image_option")&&qt.bind(t)(e))}),t.on("mouseup","*:not(.frm-show-box)",Ki),jQuery(document.getElementById("no_save")).on("change",function(){this.checked&&!0!==confirm(a.no_save_warning)&&jQuery(this).attr("checked",!1)}),document.querySelectorAll('a[href="#spam_settings"]').forEach(function(e){e.addEventListener("click",function(e){e.preventDefault();var t=document.querySelector('.frm-category-tabs a[href="#spam_settings"]');t&&(Y(t),setTimeout(function(){var e=document.getElementById("frm-categorydiv");e&&e.scrollIntoView({block:"start"})},50))})});var n=document.getElementById("frm_include_captcha");if(n){var r=n.checked;n.addEventListener("change",function(){var e=document.getElementById("frm_captcha_add_warning"),t=document.getElementById("frm_captcha_remove_warning");e&&t&&(this.checked!==r?this.checked?(e.style.display="block",t.style.display="none"):(e.style.display="none",t.style.display="block"):(e.style.display="none",t.style.display="none"))})}jQuery('select[name="options[edit_action]"]').on("change",oo);var o=document.getElementById("logged_in");jQuery(o).on("change",function(){this.checked?Di(".hide_logged_in"):Fi(".hide_logged_in")});var i=jQuery(document.getElementById("frm_cookie_expiration"));jQuery(document.getElementById("frm_single_entry_type")).on("change",function(){"cookie"===this.value?i.fadeIn("slow"):i.fadeOut("slow")});var l=document.getElementById("single_entry");jQuery(l).on("change",function(){this.checked?Di(".hide_single_entry"):Fi(".hide_single_entry"),this.checked&&"cookie"===jQuery(document.getElementById("frm_single_entry_type")).val()?i.fadeIn("slow"):i.fadeOut("slow")}),jQuery(".hide_save_draft").hide();var s=jQuery(document.getElementById("save_draft"));s.on("change",function(){this.checked?jQuery(".hide_save_draft").fadeIn("slow"):jQuery(".hide_save_draft").fadeOut("slow")}),Kr(s);var c=document.getElementById("editable");jQuery(c).on("change",function(){this.checked?(jQuery(".hide_editable").fadeIn("slow"),Kr(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",Or),jQuery(document).on("submit",".frm_form_settings",Jo),jQuery(document).on("change","#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea",Vo),ki(),jQuery(document).on("frm-action-loaded",oi),frmDom.util.documentOn("change",'.frm_on_submit_type input[type="radio"]',function(e){if(e.target.checked){var t=e.target.closest(".frm_form_action_settings");t.querySelectorAll(".frm_on_submit_dependent_setting:not(.frm_hidden)").forEach(function(e){e.classList.add("frm_hidden")}),t.querySelectorAll(".frm_on_submit_dependent_setting[data-show-if-".concat(e.target.value,"]")).forEach(function(e){e.classList.remove("frm_hidden")}),t.setAttribute("data-on-submit-type",e.target.value)}}),wp.hooks.addAction("frm_reset_fields_updated","formidableAdmin",Xo)},panelInit:function(){jQuery(".frm_wrap, #postbox-container-1").on("click",".frm_insert_code",No),jQuery(document).on("change",".frm_insert_val",function(){To(jQuery(this).data("target"),jQuery(this).val()),jQuery(this).val("")}),jQuery(document).on("click change",'[name="frm-id-key-condition"]',Do),jQuery(document).on("keyup change",".frm-build-logic",Mo),ro(),jQuery(document).on("frmElementAdded",function(e,t){ro(t)}),jQuery(document).on("mousedown",".frm-show-box",zo);var e=document.getElementById("form_settings_page"),t=document.body.classList.contains("post-type-frm_display"),n=document.getElementById("frm_insert_fields_tab");(e||t||H)&&jQuery(document).on("focusin","form input, form textarea",function(r){var o,i,a;if(r.stopPropagation(),Ho(this),jQuery(this).is(":not(:submit, input[type=button], .frm-search-input, input[type=checkbox])")){if(jQuery(r.target).closest("#frm_adv_info").length)return;if(e||H)o=jQuery("#frm_html_tab"),jQuery(this).closest("#html_settings").length>0?(o.show(),o.siblings().hide(),jQuery("#frm_html_tab a").trigger("click"),void 0===(a=this.id)||a.includes("-search-input")||(jQuery("#frm-adv-info-tab").attr("data-fills",a.trim()),this.classList.contains("field_custom_html")&&(a="field_custom_html"),jQuery.inArray(a,["after_html","before_html","submit_html","field_custom_html"])>=0&&(jQuery(".frm_code_list li:not(.show_".concat(a,")")).addClass("frm_hidden"),jQuery(".frm_code_list li.show_".concat(a)).removeClass("frm_hidden")))):((i=jQuery(".frm-category-tabs li"))[0]&&(i[0].style.display=""),n.click(),o.hide(),o.siblings().show());else if(t){var l=new CustomEvent("frm_legacy_views_handle_field_focus");l.frmData={idAttrValue:this.id},document.dispatchEvent(l)}}}),jQuery(".frm_wrap, #postbox-container-1").on("mousedown","#frm_adv_info a, .frm_field_list a",function(e){e.preventDefault()});var r=jQuery("#frm_adv_info");r.on("click",".subsubsub a.frmids",function(e){ri("frmids",e)}),r.on("click",".subsubsub a.frmkeys",function(e){ri("frmkeys",e)})},inboxInit:function(){var e;jQuery(".frm_inbox_dismiss").on("click",function(e){var t=this.parentNode.parentNode,n=t.getAttribute("data-message"),r=this.getAttribute("href"),o=t.cloneNode(!0),i=document.querySelector(".frm-dismissed-inbox-messages");if("free_templates"!==n||this.classList.contains("frm_inbox_dismiss")){e.preventDefault();var a={action:"frm_inbox_dismiss",key:n,nonce:frmGlobal.nonce},l="frm_inbox_slide_in"===t.id;l&&(t.classList.remove("s11-fadein"),t.classList.add("s11-fadeout"),t.addEventListener("animationend",function(){return t.remove()},{once:!0})),Ti(a,function(){if(!l)return"#"!==r?(window.location=r,!0):void Oi(t,function(){var e;i&&(o.classList.remove("frm-fade"),null===(e=o.querySelector(".frm-inbox-message-heading .frm_inbox_dismiss"))||void 0===e||e.remove(),i.append(o)),1===t.parentNode.querySelectorAll(".frm-inbox-message-container").length&&(document.getElementById("frm_empty_inbox").classList.remove("frm_hidden"),t.parentNode.closest(".frm-active").classList.add("frm-empty-inbox"),ji()),t.remove()})})}}),!1===(null===(e=document.getElementById("frm_empty_inbox"))||void 0===e?void 0:e.classList.contains("frm_hidden"))&&ji()},solutionInit:function(){jQuery(document).on("submit","#frm-new-template",Si)},styleInit:function(){var e=jQuery(".frm_image_preview_wrapper");e.on("click",".frm_choose_image_box",It),e.on("click",".frm_remove_image_option",qt),wp.hooks.doAction("frm_style_editor_init")},customCSSInit:function(){console.warn("Calling frmAdminBuild.customCSSInit is deprecated.")},globalSettingsInit:function(){jQuery(document).on("click","[data-frmuninstall]",ii),vi();var e=document.getElementById("licenses_settings");e&&jQuery(e).on("click",".edd_frm_save_license",ai),jQuery(document).on("click","#frm-new-template button",Qi),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",Li),document.querySelector(".frm_captchas").addEventListener("change",function(e){var t,n=null===(t=document.querySelector('.frm_captchas input[checked="checked"]'))||void 0===t?void 0:t.value,r=e.target.value!==n;document.querySelector(".captcha_settings .frm_note_style").classList.toggle("frm_hidden",!r)}),frmDom.util.documentOn("submit",".frm_settings_form",function(){L=0});var n=document.getElementById("manage_styles_settings");n&&n.addEventListener("change",function(e){var t=e.target;"SELECT"===t.nodeName&&t.dataset.name&&!t.getAttribute("name")&&t.setAttribute("name",t.dataset.name)});var r=document.getElementById("payments_settings"),o=null==r?void 0:r.querySelectorAll('[name="frm_payment_section"]');o&&o.forEach(function(e){e.addEventListener("change",function(){if(e.checked){var t=r.querySelector('label[for="'.concat(e.id,'"]'));t&&t.setAttribute("aria-selected","true"),o.forEach(function(t){if(t!==e){var n=r.querySelector('label[for="'.concat(t.id,'"]'));n&&n.setAttribute("aria-selected","false")}})}})})},exportInit:function(){jQuery(".frm_form_importer").on("submit",li),jQuery(document.getElementById("frm_export_xml")).on("submit",ci),jQuery("#frm_export_xml input, #frm_export_xml select").on("change",di),jQuery('input[name="frm_import_file"]').on("change",ui),document.querySelector('select[name="format"]').addEventListener("change",mi),jQuery('input[name="frm_export_forms[]"]').on("click",gi),vi(),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()}),pi(fi()),document.querySelector("#frm-export-select-all").addEventListener("change",function(e){document.querySelectorAll('[name="frm_export_forms[]"]').forEach(function(t){t.checked=e.target.checked})})},inboxBannerInit:function(){var e=document.getElementById("frm_banner");if(e){var t=e.querySelector(".frm-banner-dismiss");document.addEventListener("click",function(n){n.target===t&&Ti({action:"frm_inbox_dismiss",key:e.dataset.key,nonce:frmGlobal.nonce},function(){jQuery(e).fadeOut(400,function(){e.remove()})})})}},updateOpts:function(e,t,n){var r=xr(e),o=Ui(e)?"frm_bulk_products":"frm_import_options";jQuery.ajax({type:"POST",url:ajaxurl,data:{action:o,field_id:e,opts:t,separate:r,nonce:frmGlobal.nonce},success:function(t){document.getElementById("frm_field_".concat(e,"_opts")).innerHTML=t,wp.hooks.doAction("frm_after_bulk_edit_opts",e),ur(e),void 0!==n&&(n.dialog("close"),document.getElementById("frm-update-bulk-opts").classList.remove("frm_loading_button"))}})},triggerRemoveLogic:function(e,t){jQuery("#frm_logic_".concat(e,"_").concat(t," .frm_remove_tag")).trigger("click")},downloadXML:function(e,t,n){var r="".concat(ajaxurl,"?action=frm_").concat(e,"_xml&ids=").concat(t);null!==n&&(r="".concat(r,"&is_template=").concat(n)),location.href=r},hooks:{applyFilters:function(e){for(var t,n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return(t=wp.hooks).applyFilters.apply(t,[e].concat(r))},addFilter:function(e,t,n){return wp.hooks.addFilter(e,"formidable",t,n)},doAction:function(e){for(var t,n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return(t=wp.hooks).doAction.apply(t,[e].concat(r))},addAction:function(e,t,n){return wp.hooks.addAction(e,"formidable",t,n)}},settings:{validate:{validateField:s,getRangeSettingsDefaults:d,validateNumberRangeSetting:u,validateStepSetting:f,validateRangeSettings:m}},applyZebraStriping:function(e,t){var n=document.querySelectorAll("".concat(e," tr").concat(t?":not(.".concat(t,")"):""));if(!(n.length<1)){var r=!0;n.forEach(function(e){e.classList.remove("frm-odd","frm-even"),e.classList.add(r?"frm-odd":"frm-even"),r=!r}),document.querySelectorAll(e).forEach(function(e){return e.classList.add("frm-zebra-striping")})}},initModal:Mi,infoModal:G,offsetModalY:Zo,adjustConditionalLogicOptionOrders:mr,addRadioCheckboxOpt:pr,installNewForm:Ai,toggleAddonState:wi,purifyHtml:br,loadApiEmailForm:Ei,addMyEmailAddress:Vi,fillDropdownOpts:gr,showSaveAndReloadModal:Go,clearSettingsBox:et,deleteField:Bn,insertFormField:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(n){var r=I,o=0;"summary"===e&&(o=k.children('li[data-type="break"]').length>0?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:Object.assign(be(e,0,r,o),{field_options:t}),success:function(t){n(t),setTimeout(function(){qr(),Ye(t,!0);var n=xe(t);n&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:n,fieldType:e,form_id:r})},10)},error:ke})})},confirmLinkClick:R,handleInsertFieldByDraggingResponse:je,handleAddFieldClickResponse:Te,syncLayoutClasses:fe,moveFieldSettings:uo,maybeCollapseSettings:Kn}},window.frmAdminBuild=frmAdminBuildJS(),jQuery(document).ready(function(){var e;frmAdminBuild.init(),document.querySelectorAll(".frm-dropdown-menu").forEach(function(e){e.classList.add("dropdown-menu");var t,n,r=e.querySelector(".frm-dropdown-toggle");r&&(r.hasAttribute("role")||r.setAttribute("role","button"),r.hasAttribute("tabindex")||r.setAttribute("tabindex",0)),"UL"===e.tagName&&(n=(n=(n=(n=(n=(n=(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=n)}),null===(e=document.querySelector(".preview.dropdown .frm-dropdown-toggle"))||void 0===e||e.setAttribute("data-bs-toggle","dropdown"),document.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))})}),window.frm_show_div=function(e,t,n,r){t==n?jQuery(r+e).fadeIn("slow").css("visibility","visible"):jQuery(r+e).fadeOut("slow")},window.frmCheckAll=function(e,t){jQuery('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmCheckAllLevel=function(e,t,n){jQuery(".frm_catlevel_".concat(n)).children(".frm_checkbox").children("label").children('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmGetFieldValues=function(e,t,n,r,o,i){e&&jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_get_field_values&current_field=".concat(t,"&field_id=").concat(e,"&name=").concat(o,"&t=").concat(r,"&form_action=").concat(jQuery('input[name="frm_action"]').val(),"&nonce=").concat(frmGlobal.nonce),success:function(e){document.getElementById("frm_show_selected_values_".concat(t,"_").concat(n)).innerHTML=e,"function"==typeof i&&i()}})},n(4365),window.frmImportCsv=function(e){var t="";"undefined"!=typeof __FRMURLVARS&&(t=__FRMURLVARS),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_import_csv&nonce=".concat(frmGlobal.nonce,"&frm_skip_cookie=1").concat(t),success:function(t){var n=jQuery(".frm_admin_progress_bar").attr("aria-valuemax"),r=n-t,o=r/n*100;jQuery(".frm_admin_progress_bar").css("width","".concat(o,"%")).attr("aria-valuenow",r),parseInt(t,10)>0?(jQuery(".frm_csv_remaining").html(t),frmImportCsv(e)):(jQuery(document.getElementById("frm_import_message")).html(frm_admin_js.import_complete),setTimeout(function(){location.href="?page=formidable-entries&frm_action=list&form=".concat(e,"&import-message=1")},2e3))}})}})();
1 +/* exported frm_add_logic_row, frm_remove_tag, frm_show_div, frmCheckAll, frmCheckAllLevel */
2 +/* eslint-disable jsdoc/require-param, prefer-const, no-redeclare, @wordpress/no-unused-vars-before-return, jsdoc/check-types, jsdoc/check-tag-names, @wordpress/i18n-translator-comments, @wordpress/valid-sprintf, jsdoc/require-returns-description, jsdoc/require-param-type, no-unused-expressions, compat/compat */
3 +
4 +window.FrmFormsConnect = window.FrmFormsConnect || ( function( document, window, $ ) {
5 +
6 + /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl */
7 +
8 + const el = {
9 + messageBox: null,
10 + reset: null,
11 +
12 + setElements: function() {
13 + el.messageBox = document.querySelector( '.frm_pro_license_msg' );
14 + el.reset = document.getElementById( 'frm_reconnect_link' );
15 + }
16 + };
17 +
18 + /**
19 + * Public functions and properties.
20 + *
21 + * @since 4.03
22 + *
23 + * @type {Object}
24 + */
25 + const app = {
26 +
27 + /**
28 + * Register connect button event.
29 + *
30 + * @since 4.03
31 + */
32 + init: function() {
33 + el.setElements();
34 +
35 + $( document.getElementById( 'frm_deauthorize_link' ) ).on( 'click', app.deauthorize );
36 + $( '.frm_authorize_link' ).on( 'click', app.authorize );
37 + // Handles FF dashboard Authorize & Reauthorize events.
38 + // Attach click event to parent as #frm_deauthorize_link & #frm_reconnect_link dynamically recreated by bootstrap.setupBootstrapDropdowns in dom.js
39 + $( '.frm-dashboard-license-options' ).on( 'click', '#frm_deauthorize_link', app.deauthorize );
40 + $( '.frm-dashboard-license-options' ).on( 'click', '#frm_reconnect_link', app.reauthorize );
41 +
42 + if ( el.reset !== null ) {
43 + $( el.reset ).on( 'click', app.reauthorize );
44 + }
45 + },
46 +
47 + /* Manual license authorization */
48 + authorize: function() {
49 + /*jshint validthis:true */
50 + const button = this;
51 + const pluginSlug = this.getAttribute( 'data-plugin' );
52 + const input = document.getElementById( 'edd_' + pluginSlug + '_license_key' );
53 + const license = input.value;
54 + let wpmu = document.getElementById( 'proplug-wpmu' );
55 + this.classList.add( 'frm_loading_button' );
56 + if ( wpmu === null ) {
57 + wpmu = 0;
58 + } else if ( wpmu.checked ) {
59 + wpmu = 1;
60 + } else {
61 + wpmu = 0;
62 + }
63 +
64 + $.ajax({
65 + type: 'POST', url: ajaxurl, dataType: 'json',
66 + data: {
67 + action: 'frm_addon_activate',
68 + license: license,
69 + plugin: pluginSlug,
70 + wpmu: wpmu,
71 + nonce: frmGlobal.nonce
72 + },
73 + success: function( msg ) {
74 + app.afterAuthorize( msg, input );
75 + button.classList.remove( 'frm_loading_button' );
76 + }
77 + });
78 + },
79 +
80 + afterAuthorize: function( msg, input ) {
81 + if ( msg.success === true ) {
82 + input.value = '•••••••••••••••••••';
83 + }
84 +
85 + wp.hooks.doAction( 'frm_after_authorize', msg );
86 + app.showMessage( msg );
87 + },
88 +
89 + showProgress: function( msg ) {
90 + if ( el.messageBox === null ) {
91 + // In case the message box was added after page load.
92 + el.setElements();
93 + }
94 +
95 + const messageBox = el.messageBox;
96 + if ( messageBox === null ) {
97 + return;
98 + }
99 +
100 + if ( msg.success === true ) {
101 + messageBox.classList.remove( 'frm_error_style' );
102 + messageBox.classList.add( 'frm_message', 'frm_updated_message' );
103 + } else {
104 + messageBox.classList.add( 'frm_error_style' );
105 + messageBox.classList.remove( 'frm_message', 'frm_updated_message' );
106 + }
107 + messageBox.classList.remove( 'frm_hidden' );
108 + messageBox.innerHTML = msg.message;
109 + },
110 +
111 + showMessage: function( msg ) {
112 + if ( el.messageBox === null ) {
113 + // In case the message box was added after page load.
114 + el.setElements();
115 + }
116 + const messageBox = el.messageBox;
117 +
118 + if ( msg.success === true ) {
119 + app.showAuthorized( true );
120 + app.showInlineSuccess();
121 +
122 + /**
123 + * Triggers the after license is authorized action for a confirmation/success modal.
124 + * @param {Object} msg An object containing message data received from Authorize request.
125 + */
126 + wp.hooks.doAction( 'frmAdmin.afterLicenseAuthorizeSuccess', { msg });
127 + }
128 + app.showProgress( msg );
129 +
130 + if ( msg.message !== '' ) {
131 + setTimeout( function() {
132 + messageBox.innerHTML = '';
133 + messageBox.classList.add( 'frm_hidden' );
134 + messageBox.classList.remove( 'frm_error_style', 'frm_message', 'frm_updated_message' );
135 + }, 10000 );
136 + const refreshPage = document.querySelector( '.frm-admin-page-dashboard' );
137 + if ( refreshPage ) {
138 + setTimeout( function() {
139 + window.location.reload();
140 + }, 1000 );
141 + }
142 + }
143 + },
144 +
145 + showAuthorized: function( show ) {
146 + const from = show ? 'unauthorized' : 'authorized';
147 + const to = show ? 'authorized' : 'unauthorized';
148 + const container = document.querySelectorAll( '.frm_' + from + '_box' );
149 + if ( container.length ) {
150 + // Replace all authorized boxes with unauthorized boxes.
151 + container.forEach( function( box ) {
152 + box.className = box.className.replace( 'frm_' + from + '_box', 'frm_' + to + '_box' );
153 + });
154 + }
155 + },
156 +
157 + /**
158 + * Use the data-success element to replace the element content.
159 + */
160 + showInlineSuccess: function() {
161 + const successElement = document.querySelectorAll( '.frm-confirm-msg [data-success]' );
162 + if ( successElement.length ) {
163 + successElement.forEach( function( element ) {
164 + element.innerHTML = frmAdminBuild.purifyHtml( element.getAttribute( 'data-success' ) );
165 + });
166 + }
167 + },
168 +
169 + /* Clear the site license cache */
170 + reauthorize: function() {
171 + /*jshint validthis:true */
172 + this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;float:none"></span>';
173 +
174 + $.ajax({
175 + type: 'POST',
176 + url: ajaxurl,
177 + dataType: 'json',
178 + data: {
179 + action: 'frm_reset_cache',
180 + plugin: 'formidable_pro',
181 + nonce: frmGlobal.nonce
182 + },
183 + success: function( msg ) {
184 + el.reset.textContent = msg.message;
185 + if ( el.reset.getAttribute( 'data-refresh' ) === '1' ) {
186 + window.location.reload();
187 + }
188 + }
189 + });
190 + return false;
191 + },
192 +
193 + deauthorize: function() {
194 + /*jshint validthis:true */
195 + if ( ! confirm( frmGlobal.deauthorize ) ) {
196 + return false;
197 + }
198 + const pluginSlug = this.getAttribute( 'data-plugin' ),
199 + input = document.getElementById( 'edd_' + pluginSlug + '_license_key' ),
200 + license = input.value,
201 + link = this;
202 +
203 + this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;"></span>';
204 +
205 + $.ajax({
206 + type: 'POST',
207 + url: ajaxurl,
208 + data: {
209 + action: 'frm_addon_deactivate',
210 + license: license,
211 + plugin: pluginSlug,
212 + nonce: frmGlobal.nonce
213 + },
214 + success: function() {
215 + app.showAuthorized( false );
216 + input.value = '';
217 + link.replaceWith( 'Disconnected' );
218 +
219 + /**
220 + * Triggers the after license is deauthorized sruccess action.
221 + */
222 + wp.hooks.doAction( 'frmAdmin.afterLicenseDeauthorizeSuccess', {});
223 +
224 + }
225 + });
226 + return false;
227 + }
228 + };
229 +
230 + // Provide access to public functions/properties.
231 + return app;
232 +
233 +}( document, window, jQuery ) );
234 +
235 +function frmAdminBuildJS() {
236 + //'use strict';
237 +
238 + /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl, fromDom */
239 +
240 + const frmAdminJs = frm_admin_js; // eslint-disable-line camelcase
241 + const { tag, div, span, a, svg, img } = frmDom;
242 + const { onClickPreventDefault } = frmDom.util;
243 + const { doJsonFetch, doJsonPost } = frmDom.ajax;
244 + const icons = {
245 + save: svg({ href: '#frm_save_icon' }),
246 + drag: svg({ href: '#frm_drag_icon', classList: [ 'frm_drag_icon', 'frm-drag' ] })
247 + };
248 +
249 + let $newFields = jQuery( document.getElementById( 'frm-show-fields' ) ),
250 + builderForm = document.getElementById( 'new_fields' ),
251 + thisForm = document.getElementById( 'form_id' ),
252 + copyHelper = false,
253 + fieldsUpdated = 0,
254 + thisFormId = 0,
255 + autoId = 0,
256 + optionMap = {},
257 + lastNewActionIdReturned = 0;
258 +
259 + const { __, sprintf } = wp.i18n;
260 + let debouncedSyncAfterDragAndDrop, postBodyContent, $postBodyContent;
261 +
262 + const dragState = {
263 + dragging: false
264 + };
265 +
266 + if ( thisForm !== null ) {
267 + thisFormId = thisForm.value;
268 + }
269 +
270 + const currentURL = new URL( window.location.href );
271 + const urlParams = currentURL.searchParams;
272 + const builderPage = document.getElementById( 'frm_builder_page' );
273 +
274 + // Global settings
275 + let s;
276 +
277 + function showElement( element ) {
278 + if ( ! element[0]) {
279 + return;
280 + }
281 + element[0].style.display = '';
282 + }
283 +
284 + function empty( $obj ) {
285 + if ( $obj !== null ) {
286 + while ( $obj.firstChild ) {
287 + $obj.removeChild( $obj.firstChild );
288 + }
289 + }
290 + }
291 +
292 + function addClass( $obj, className ) {
293 + if ( $obj.classList ) {
294 + $obj.classList.add( className );
295 + } else {
296 + $obj.className += ' ' + className;
297 + }
298 + }
299 +
300 + function confirmClick( e ) {
301 + /*jshint validthis:true */
302 + e.stopPropagation();
303 + e.preventDefault();
304 + confirmLinkClick( this );
305 + }
306 +
307 + function confirmLinkClick( link ) {
308 + const message = link.getAttribute( 'data-frmverify' ),
309 + loadedFrom = link.getAttribute( 'data-loaded-from' ) ;
310 +
311 + if ( message === null || link.id === 'frm-confirmed-click' ) {
312 + return true;
313 + }
314 +
315 + if ( 'entries-list' === loadedFrom ) {
316 + return wp.hooks.applyFilters( 'frm_on_multiple_entries_delete', { link, initModal });
317 + }
318 +
319 + return confirmModal( link );
320 + }
321 +
322 + function confirmModal( link ) {
323 + let verify, $confirmMessage, i, dataAtts, btnClass,
324 + $info = initModal( '#frm_confirm_modal', '400px' ),
325 + continueButton = document.getElementById( 'frm-confirmed-click' );
326 +
327 + if ( $info === false ) {
328 + return false;
329 + }
330 +
331 + verify = link.getAttribute( 'data-frmverify' );
332 + btnClass = verify ? link.getAttribute( 'data-frmverify-btn' ) : '';
333 + $confirmMessage = jQuery( '.frm-confirm-msg' );
334 + $confirmMessage.empty();
335 +
336 + if ( verify ) {
337 + $confirmMessage.append( document.createTextNode( verify ) );
338 + if ( btnClass ) {
339 + continueButton.classList.add( btnClass );
340 + }
341 + }
342 +
343 + removeAtts = continueButton.dataset;
344 + for ( i in dataAtts ) {
345 + continueButton.removeAttribute( 'data-' + i );
346 + }
347 +
348 + dataAtts = link.dataset;
349 + for ( i in dataAtts ) {
350 + if ( i !== 'frmverify' ) {
351 + continueButton.setAttribute( 'data-' + i, dataAtts[i]);
352 + }
353 + }
354 +
355 + /**
356 + * Triggers the pre-open action for a confirmation modal. This action passes
357 + * relevant modal information and associated link to any listening hooks.
358 + *
359 + * @param {Object} options An object containing modal elements and data.
360 + * @param {HTMLElement} options.$info The HTML element containing modal information.
361 + * @param {string} options.link The link associated with the modal action.
362 + */
363 + wp.hooks.doAction( 'frmAdmin.beforeOpenConfirmModal', { $info, link });
364 +
365 + $info.dialog( 'open' );
366 + continueButton.setAttribute( 'href', link.getAttribute( 'href' ) );
367 + return false;
368 + }
369 +
370 + function infoModal( msg ) {
371 + const $info = initModal( '#frm_info_modal', '400px' );
372 +
373 + if ( $info === false ) {
374 + return false;
375 + }
376 +
377 + jQuery( '.frm-info-msg' ).html( msg );
378 +
379 + $info.dialog( 'open' );
380 + return false;
381 + }
382 +
383 + function toggleItem( e ) {
384 + /*jshint validthis:true */
385 + const toggle = this.getAttribute( 'data-frmtoggle' );
386 + const text = this.getAttribute( 'data-toggletext' );
387 + const $items = jQuery( toggle );
388 +
389 + e.preventDefault();
390 +
391 + $items.toggle();
392 +
393 + if ( text !== null && text !== '' ) {
394 + this.setAttribute( 'data-toggletext', this.innerHTML );
395 + this.textContent = text;
396 + }
397 +
398 + return false;
399 + }
400 +
401 + /**
402 + * Toggle a class on target elements when an anchor is clicked, or when a radio or checkbox has been selected.
403 + *
404 + * @param {Event} e Event with either the change or click type.
405 + * @returns {false}
406 + */
407 + function hideShowItem( e ) {
408 + /*jshint validthis:true */
409 + let hide = this.getAttribute( 'data-frmhide' );
410 + let show = this.getAttribute( 'data-frmshow' );
411 +
412 + // Flip unchecked checkboxes so an off value undoes the on value.
413 + if ( isUncheckedCheckbox( this ) ) {
414 + if ( hide !== null ) {
415 + show = hide;
416 + hide = null;
417 + } else if ( show !== null ) {
418 + hide = show;
419 + show = null;
420 + }
421 + }
422 +
423 + e.preventDefault();
424 +
425 + const toggleClass = this.getAttribute( 'data-toggleclass' ) || 'frm_hidden';
426 +
427 + if ( hide !== null ) {
428 + jQuery( hide ).addClass( toggleClass );
429 + }
430 +
431 + if ( show !== null ) {
432 + jQuery( show ).removeClass( toggleClass );
433 + }
434 +
435 + const current = this.parentNode.querySelectorAll( 'a.current' );
436 + if ( current !== null ) {
437 + for ( let i = 0; i < current.length; i++ ) {
438 + current[ i ].classList.remove( 'current' );
439 + }
440 + this.classList.add( 'current' );
441 + }
442 +
443 + return false;
444 + }
445 +
446 + function isUncheckedCheckbox( element ) {
447 + return 'INPUT' === element.nodeName && 'checkbox' === element.type && ! element.checked;
448 + }
449 +
450 + function setupMenuOffset() {
451 + window.onscroll = document.documentElement.onscroll = setMenuOffset;
452 + setMenuOffset();
453 + }
454 +
455 + function setMenuOffset() {
456 + const fields = document.getElementById( 'frm_adv_info' );
457 + if ( fields === null ) {
458 + return;
459 + }
460 +
461 + const currentOffset = document.documentElement.scrollTop || document.body.scrollTop; // body for Safari
462 + if ( currentOffset === 0 ) {
463 + fields.classList.remove( 'frm_fixed' );
464 + return;
465 + }
466 +
467 + const posEle = document.getElementById( 'frm_position_ele' );
468 + if ( posEle === null ) {
469 + return;
470 + }
471 +
472 + const eleOffset = jQuery( posEle ).offset();
473 + const offset = eleOffset.top;
474 + let desiredOffset = offset - currentOffset;
475 + let menuHeight = 0;
476 +
477 + const menu = document.getElementById( 'wpadminbar' );
478 + if ( menu !== null ) {
479 + menuHeight = menu.offsetHeight;
480 + }
481 +
482 + if ( desiredOffset < menuHeight ) {
483 + desiredOffset = menuHeight;
484 + }
485 +
486 + if ( desiredOffset > menuHeight ) {
487 + fields.classList.remove( 'frm_fixed' );
488 + } else {
489 + fields.classList.add( 'frm_fixed' );
490 + if ( desiredOffset !== 32 ) {
491 + fields.style.top = desiredOffset + 'px';
492 + }
493 + }
494 + }
495 +
496 + function loadTooltips() {
497 + let wrapClass = jQuery( '.wrap, .frm_wrap' ),
498 + confirmModal = document.getElementById( 'frm_confirm_modal' ),
499 + doAction = false,
500 + confirmedBulkDelete = false;
501 +
502 + jQuery( confirmModal ).on( 'click', '[data-deletefield]', deleteFieldConfirmed );
503 + jQuery( confirmModal ).on( 'click', '[data-removeid]', removeThisTag );
504 + jQuery( confirmModal ).on( 'click', '[data-trashtemplate]', trashTemplate );
505 +
506 + wrapClass.on( 'click', '.frm_remove_tag, .frm_remove_form_action', removeThisTag );
507 + wrapClass.on( 'click', 'a[data-frmverify]', confirmClick );
508 + wrapClass.on( 'click', 'a[data-frmtoggle]', toggleItem );
509 + wrapClass.on( 'click', 'a[data-frmhide], a[data-frmshow]', hideShowItem );
510 + wrapClass.on( 'change', 'input[data-frmhide], input[data-frmshow]', hideShowItem );
511 + wrapClass.on( 'click', '.widget-top,a.widget-action', clickWidget );
512 +
513 + wrapClass.on( 'mouseenter.frm', '.frm_bstooltip, .frm_help', function() {
514 + jQuery( this ).off( 'mouseenter.frm' );
515 +
516 + jQuery( '.frm_bstooltip, .frm_help' ).tooltip();
517 + jQuery( this ).tooltip( 'show' );
518 + });
519 +
520 + jQuery( '.frm_bstooltip, .frm_help' ).tooltip( );
521 +
522 + jQuery( document ).on( 'click', '#doaction, #doaction2', function( event ) {
523 + const isTop = this.id === 'doaction',
524 + suffix = isTop ? 'top' : 'bottom',
525 + bulkActionSelector = document.getElementById( 'bulk-action-selector-' + suffix ),
526 + confirmBulkDelete = document.getElementById( 'confirm-bulk-delete-' + suffix );
527 +
528 + if ( bulkActionSelector !== null && confirmBulkDelete !== null ) {
529 + doAction = this;
530 +
531 + if ( ! confirmedBulkDelete && bulkActionSelector.value === 'bulk_delete' ) {
532 + event.preventDefault();
533 + confirmLinkClick( confirmBulkDelete );
534 + return false;
535 + }
536 + } else {
537 + doAction = false;
538 + }
539 + });
540 +
541 + jQuery( document ).on( 'click', '#frm-confirmed-click', function( event ) {
542 + if ( doAction === false || event.target.classList.contains( 'frm-btn-inactive' ) ) {
543 + return;
544 + }
545 +
546 + if ( this.getAttribute( 'href' ) === 'confirm-bulk-delete' ) {
547 + event.preventDefault();
548 + confirmedBulkDelete = true;
549 + doAction.click();
550 + return false;
551 + }
552 + });
553 + }
554 +
555 + function deleteTooltips() {
556 + document.querySelectorAll( '.tooltip' ).forEach(
557 + function( tooltip ) {
558 + tooltip.remove();
559 + }
560 + );
561 + }
562 +
563 + function removeThisTag() {
564 + /*jshint validthis:true */
565 + let show, hide, removeMore;
566 +
567 + if ( parseInt( this.getAttribute( 'data-skip-frm-js' ) ) || confirmLinkClick( this ) === false ) {
568 + return;
569 + }
570 +
571 + const deleteButton = jQuery( this );
572 + const id = deleteButton.attr( 'data-removeid' );
573 +
574 + show = deleteButton.attr( 'data-showlast' );
575 + if ( typeof show === 'undefined' ) {
576 + show = '';
577 + }
578 +
579 + hide = deleteButton.attr( 'data-hidelast' );
580 + if ( typeof hide === 'undefined' ) {
581 + hide = '';
582 + }
583 +
584 + removeMore = deleteButton.attr( 'data-removemore' );
585 +
586 + if ( show !== '' ) {
587 + if ( deleteButton.closest( '.frm_add_remove' ).find( '.frm_remove_tag:visible' ).length > 1 ) {
588 + show = '';
589 + hide = '';
590 + }
591 + } else if ( id.indexOf( 'frm_postmeta_' ) === 0 ) {
592 + if ( jQuery( '#frm_postmeta_rows .frm_postmeta_row' ).length < 2 ) {
593 + show = '.frm_add_postmeta_row.button';
594 + }
595 + if ( jQuery( '.frm_toggle_cf_opts' ).length && jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().length ) {
596 + if ( show !== '' ) {
597 + show += ',';
598 + }
599 + show += '#' + jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().attr( 'id' ) + ' .frm_toggle_cf_opts';
600 + }
601 + }
602 +
603 + const $fadeEle = jQuery( document.getElementById( id ) );
604 + $fadeEle.fadeOut( 400, function() {
605 + $fadeEle.remove();
606 + fieldUpdated();
607 +
608 + if ( hide !== '' ) {
609 + jQuery( hide ).hide();
610 + }
611 +
612 + if ( show !== '' ) {
613 + jQuery( show + ' a,' + show ).removeClass( 'frm_hidden' ).fadeIn( 'slow' );
614 + }
615 +
616 + if ( this.closest( '.frm_form_action_settings' ) ) {
617 + const type = this.closest( '.frm_form_action_settings' ).querySelector( '.frm_action_name' ).value;
618 + afterActionRemoved( type );
619 + }
620 + document.querySelector( '.tooltip' )?.remove();
621 + });
622 +
623 + if ( typeof removeMore !== 'undefined' ) {
624 + removeMore = jQuery( removeMore );
625 + removeMore.fadeOut( 400, function() {
626 + removeMore.remove();
627 + });
628 + }
629 +
630 + if ( show !== '' ) {
631 + jQuery( this ).closest( '.frm_logic_rows' ).fadeOut( 'slow' );
632 + }
633 +
634 + return false;
635 + }
636 +
637 + function afterActionRemoved( type ) {
638 + checkActiveAction( type );
639 +
640 + const hookName = 'frm_after_action_removed';
641 + const hookArgs = { type };
642 + wp.hooks.doAction( hookName, hookArgs );
643 + }
644 +
645 + function clickWidget( event, b ) {
646 + /*jshint validthis:true */
647 + if ( typeof b === 'undefined' ) {
648 + b = this;
649 + }
650 +
651 + popCalcFields( b, false );
652 +
653 + const cont = jQuery( b ).closest( '.frm_form_action_settings' );
654 + const target = event.target;
655 +
656 + if ( cont.length && typeof target !== 'undefined' ) {
657 + const className = target.parentElement.className;
658 + if ( 'string' === typeof className ) {
659 + if ( className.indexOf( 'frm_email_icons' ) > -1 || className.indexOf( 'frm_toggle' ) > -1 ) {
660 + // clicking on delete icon shouldn't open it
661 + event.stopPropagation();
662 + return;
663 + }
664 + }
665 + }
666 +
667 + let inside = cont.children( '.widget-inside' );
668 +
669 + if ( cont.length && inside.find( 'p, div, table' ).length < 1 ) {
670 + const actionId = cont.find( 'input[name$="[ID]"]' ).val();
671 + const actionType = cont.find( 'input[name$="[post_excerpt]"]' ).val();
672 + if ( actionType ) {
673 + inside.html( '<span class="frm-wait frm_spinner"></span>' );
674 + cont.find( '.spinner' ).fadeIn( 'slow' );
675 + jQuery.ajax({
676 + type: 'POST',
677 + url: ajaxurl,
678 + data: {
679 + action: 'frm_form_action_fill',
680 + action_id: actionId,
681 + action_type: actionType,
682 + nonce: frmGlobal.nonce
683 + },
684 + success: function( html ) {
685 + inside.html( html );
686 + initiateMultiselect();
687 + showInputIcon( '#' + cont.attr( 'id' ) );
688 + frmDom.autocomplete.initAutocomplete( 'page', inside );
689 + jQuery( b ).trigger( 'frm-action-loaded' );
690 +
691 + /**
692 + * Fires after filling form action content when opening.
693 + *
694 + * @since 5.5.4
695 + *
696 + * @param {Object} insideElement JQuery object of form action inside element.
697 + */
698 + wp.hooks.doAction( 'frm_filled_form_action', inside );
699 + }
700 + });
701 + }
702 + }
703 +
704 + jQuery( b ).closest( '.frm_field_box' ).siblings().find( '.widget-inside' ).slideUp( 'fast' );
705 + if ( ( typeof b.className !== 'undefined' && b.className.indexOf( 'widget-action' ) !== -1 ) || jQuery( b ).closest( '.start_divider' ).length < 1 ) {
706 + return;
707 + }
708 +
709 + inside = jQuery( b ).closest( 'div.widget' ).children( '.widget-inside' );
710 + if ( inside.is( ':hidden' ) ) {
711 + inside.slideDown( 'fast' );
712 + } else {
713 + inside.slideUp( 'fast' );
714 + }
715 + }
716 +
717 + function clickNewTab() {
718 + /*jshint validthis:true */
719 + const t = this.getAttribute( 'href' );
720 + if ( typeof t === 'undefined' ) {
721 + return false;
722 + }
723 +
724 + const c = t.replace( '#', '.' );
725 + const $link = jQuery( this );
726 +
727 + $link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' );
728 + $link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide();
729 +
730 + const tabContent = document.getElementById( t.replace( '#', '' ) );
731 + if ( tabContent ) {
732 + tabContent.style.display = 'block';
733 + }
734 +
735 + // clearSettingsBox would hide field settings when opening the fields modal and we want to skip it there.
736 + if ( this.id === 'frm_insert_fields_tab' && ! this.closest( '#frm_adv_info' ) ) {
737 + clearSettingsBox();
738 + }
739 + return false;
740 + }
741 +
742 + function clickTab( link, auto ) {
743 + link = jQuery( link );
744 + const t = link.attr( 'href' );
745 + if ( typeof t === 'undefined' ) {
746 + return;
747 + }
748 +
749 + const c = t.replace( '#', '.' );
750 +
751 + link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' );
752 + if ( link.closest( 'div' ).find( '.tabs-panel' ).length ) {
753 + link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide();
754 + } else if ( document.getElementById( 'form_global_settings' ) !== null ) {
755 + /* global settings */
756 + const ajax = link.data( 'frmajax' );
757 + link.closest( '.frm_wrap' ).find( '.tabs-panel, .hide_with_tabs' ).hide();
758 + if ( typeof ajax !== 'undefined' && ajax == '1' ) {
759 + loadSettingsTab( t );
760 + }
761 + } else {
762 + /* form settings page */
763 + jQuery( '#frm-categorydiv .tabs-panel, .hide_with_tabs' ).hide();
764 + }
765 + jQuery( t ).show();
766 + jQuery( c ).show();
767 +
768 + hideShortcodes();
769 +
770 + if ( auto !== 'auto' ) {
771 + // Hide success message on tab change.
772 + jQuery( '.frm_updated_message' ).hide();
773 + jQuery( '.frm_warning_style' ).hide();
774 + }
775 +
776 + if ( jQuery( link ).closest( '#frm_adv_info' ).length ) {
777 + return;
778 + }
779 +
780 + if ( jQuery( '.frm_form_settings' ).length ) {
781 + jQuery( '.frm_form_settings' ).attr( 'action', '?page=formidable&frm_action=settings&id=' + jQuery( '.frm_form_settings input[name="id"]' ).val() + '&t=' + t.replace( '#', '' ) );
782 + } else {
783 + jQuery( '.frm_settings_form' ).attr( 'action', '?page=formidable-settings&t=' + t.replace( '#', '' ) );
784 + }
785 + }
786 +
787 + function setupSortable( sortableSelector ) {
788 + document.querySelectorAll( sortableSelector ).forEach(
789 + list => {
790 + makeDroppable( list );
791 + Array.from( list.children ).forEach( child => makeDraggable( child, '.frm-move' ) );
792 +
793 + const $sectionTitle = jQuery( list ).children( '[data-type="divider"]' ).children( '.divider_section_only' );
794 + if ( $sectionTitle.length ) {
795 + makeDroppable( $sectionTitle );
796 + }
797 + }
798 + );
799 + setupFieldOptionSorting( jQuery( '#frm_builder_page' ) );
800 + }
801 +
802 + function makeDroppable( list ) {
803 + jQuery( list ).droppable({
804 + accept: '.frmbutton, li.frm_field_box',
805 + deactivate: handleFieldDrop,
806 + over: onDragOverDroppable,
807 + out: onDraggableLeavesDroppable,
808 + tolerance: 'pointer'
809 + });
810 + }
811 +
812 + function onDragOverDroppable( event, ui ) {
813 + const droppable = getDroppableForOnDragOver( event.target );
814 + const draggable = ui.draggable[0];
815 +
816 + if ( ! allowDrop( draggable, droppable, event ) ) {
817 + droppable.classList.remove( 'frm-over-droppable' );
818 + jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' );
819 + return;
820 + }
821 +
822 + document.querySelectorAll( '.frm-over-droppable' ).forEach( droppable => droppable.classList.remove( 'frm-over-droppable' ) );
823 + droppable.classList.add( 'frm-over-droppable' );
824 + jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' );
825 + }
826 +
827 + /**
828 + * Maybe change the droppable.
829 + * Section titles are made droppable, but are not a list, so we need to change the droppable to the section's list instead.
830 + *
831 + * @param {Element} droppable
832 + * @returns {Element}
833 + */
834 + function getDroppableForOnDragOver( droppable ) {
835 + if ( droppable.classList.contains( 'divider_section_only' ) ) {
836 + droppable = jQuery( droppable ).nextAll( '.start_divider.frm_sorting' ).get( 0 );
837 + }
838 + return droppable;
839 + }
840 +
841 + function onDraggableLeavesDroppable( event ) {
842 + const droppable = event.target;
843 + droppable.classList.remove( 'frm-over-droppable' );
844 + }
845 +
846 + function makeDraggable( draggable, handle ) {
847 + const settings = {
848 + helper: getDraggableHelper,
849 + revert: 'invalid',
850 + delay: 10,
851 + start: handleDragStart,
852 + stop: handleDragStop,
853 + drag: handleDrag,
854 + cursor: 'grabbing',
855 + refreshPositions: true,
856 + cursorAt: {
857 + top: 0,
858 + left: 90 // The width of draggable button is 180. 90 should center the draggable on the cursor.
859 + }
860 + };
861 + if ( 'string' === typeof handle ) {
862 + settings.handle = handle;
863 + }
864 + jQuery( draggable ).draggable( settings );
865 + }
866 +
867 + function getDraggableHelper( event ) {
868 + const draggable = event.delegateTarget;
869 +
870 + if ( isFieldGroup( draggable ) ) {
871 + const newTextFieldClone = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_ttext' ).cloneNode( true );
872 + newTextFieldClone.querySelector( 'use' ).setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_field_group_layout_icon' );
873 + newTextFieldClone.querySelector( 'span' ).textContent = __( 'Field Group', 'formidable' );
874 + newTextFieldClone.classList.add( 'frm_field_box' );
875 + newTextFieldClone.classList.add( 'ui-sortable-helper' );
876 + return newTextFieldClone;
877 + }
878 +
879 + let copyTarget;
880 + const isNewField = draggable.classList.contains( 'frmbutton' );
881 + if ( isNewField ) {
882 + copyTarget = draggable.cloneNode( true );
883 + copyTarget.classList.add( 'ui-sortable-helper' );
884 + draggable.classList.add( 'frm-new-field' );
885 + return copyTarget;
886 + }
887 +
888 + if ( draggable.hasAttribute( 'data-ftype' ) ) {
889 + const fieldType = draggable.getAttribute( 'data-ftype' );
890 + copyTarget = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_t' + fieldType );
891 + copyTarget = copyTarget.cloneNode( true );
892 + copyTarget.classList.add( 'form-field' );
893 +
894 + copyTarget.classList.add( 'ui-sortable-helper' );
895 +
896 + if ( copyTarget ) {
897 + return copyTarget.cloneNode( true );
898 + }
899 + }
900 +
901 + return div({ className: 'frmbutton' });
902 + }
903 +
904 + function handleDragStart( event, ui ) {
905 + dragState.dragging = true;
906 +
907 + const container = postBodyContent;
908 + container.classList.add( 'frm-dragging-field' );
909 +
910 + document.body.classList.add( 'frm-dragging' );
911 + ui.helper.addClass( 'frm-sortable-helper' );
912 + ui.helper.initialOffset = container.scrollTop;
913 +
914 + event.target.classList.add( 'frm-drag-fade' );
915 +
916 + unselectFieldGroups();
917 + deleteEmptyDividerWrappers();
918 + maybeRemoveGroupHoverTarget();
919 + closeOpenFieldDropdowns();
920 + deleteTooltips();
921 + }
922 +
923 + function handleDragStop() {
924 + const container = postBodyContent;
925 + container.classList.remove( 'frm-dragging-field' );
926 + document.body.classList.remove( 'frm-dragging' );
927 +
928 + const fade = document.querySelector( '.frm-drag-fade' );
929 + if ( fade ) {
930 + fade.classList.remove( 'frm-drag-fade' );
931 + }
932 + }
933 +
934 + function handleDrag( event, ui ) {
935 + maybeScrollBuilder( event );
936 + const draggable = event.target;
937 + const droppable = getDroppableTarget();
938 +
939 + let placeholder = document.getElementById( 'frm_drag_placeholder' );
940 + if ( ! allowDrop( draggable, droppable, event ) ) {
941 + if ( placeholder ) {
942 + placeholder.remove();
943 + }
944 + return;
945 + }
946 +
947 + if ( ! placeholder ) {
948 + placeholder = tag( 'li', {
949 + id: 'frm_drag_placeholder',
950 + className: 'sortable-placeholder'
951 + });
952 + }
953 + const frmSortableHelper = ui.helper.get( 0 );
954 + if ( frmSortableHelper.classList.contains( 'form-field' ) || frmSortableHelper.classList.contains( 'frm_field_box' ) ) {
955 + // Sync the y position of the draggable so it still follows the cursor after scrolling up and down the field list.
956 + frmSortableHelper.style.transform = 'translateY(' + getDragOffset( ui.helper ) + 'px)';
957 + }
958 +
959 + if ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) ) {
960 + placeholder.style.left = 0;
961 + handleDragOverYAxis({ droppable, y: event.clientY, placeholder });
962 + return;
963 + }
964 +
965 + placeholder.style.top = '';
966 + handleDragOverFieldGroup({ droppable, x: event.clientX, placeholder });
967 + }
968 +
969 + function maybeScrollBuilder( event ) {
970 + $postBodyContent.scrollTop(
971 + ( _, v ) => {
972 + const moved = event.clientY;
973 + const h = postBodyContent.offsetHeight;
974 + const relativePos = event.clientY - postBodyContent.offsetTop;
975 + const y = relativePos - h / 2;
976 +
977 + if ( relativePos > ( h - 50 ) && moved > 5 ) {
978 + // Scrolling down.
979 + return v + y * 0.1;
980 + }
981 +
982 + if ( relativePos < 70 && moved < 130 ) {
983 + // Scrolling up.
984 + return v - Math.abs( y * 0.1 );
985 + }
986 +
987 + return v;
988 + }
989 + );
990 + }
991 +
992 + function getDragOffset( $helper ) {
993 + return postBodyContent.scrollTop - $helper.initialOffset;
994 + }
995 +
996 + function getDroppableTarget() {
997 + let droppable = document.getElementById( 'frm-show-fields' );
998 + while ( droppable.querySelector( '.frm-over-droppable' ) ) {
999 + droppable = droppable.querySelector( '.frm-over-droppable' );
1000 + }
1001 + if ( 'frm-show-fields' === droppable.id && ! droppable.classList.contains( 'frm-over-droppable' ) ) {
1002 + droppable = false;
1003 + }
1004 + return droppable;
1005 + }
1006 +
1007 + function handleFieldDrop( _, ui ) {
1008 + if ( ! dragState.dragging ) {
1009 + // dragState.dragging is set to true on drag start.
1010 + // The deactivate event gets called for every droppable. This check to make sure it happens once.
1011 + return;
1012 + }
1013 +
1014 + dragState.dragging = false;
1015 +
1016 + const draggable = ui.draggable[0];
1017 + const placeholder = document.getElementById( 'frm_drag_placeholder' );
1018 +
1019 + if ( ! placeholder ) {
1020 + ui.helper.remove();
1021 + debouncedSyncAfterDragAndDrop();
1022 + return;
1023 + }
1024 +
1025 + maybeOpenCollapsedPage( placeholder );
1026 +
1027 + const $previousFieldContainer = ui.helper.parent();
1028 + const previousSection = ui.helper.get( 0 ).closest( 'ul.start_divider' );
1029 + const newSection = placeholder.closest( 'ul.frm_sorting' );
1030 +
1031 + if ( draggable.classList.contains( 'frm-new-field' ) ) {
1032 + insertNewFieldByDragging( draggable.id );
1033 + } else {
1034 + moveFieldThatAlreadyExists( draggable, placeholder );
1035 + }
1036 +
1037 + const previousSectionId = previousSection ? parseInt( previousSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0;
1038 + const newSectionId = newSection.classList.contains( 'start_divider' ) ? parseInt( newSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0;
1039 +
1040 + placeholder.remove();
1041 + ui.helper.remove();
1042 +
1043 + const $previousContainerFields = $previousFieldContainer.length ? getFieldsInRow( $previousFieldContainer ) : [];
1044 + maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields );
1045 + maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields );
1046 +
1047 + if ( previousSectionId !== newSectionId ) {
1048 + updateFieldAfterMovingBetweenSections( jQuery( draggable ), previousSection );
1049 + }
1050 +
1051 + debouncedSyncAfterDragAndDrop();
1052 + }
1053 +
1054 + /**
1055 + * If a page if collapsed, expand it before dragging since only the page break will move.
1056 + *
1057 + * @param {Element} placeholder
1058 + * @returns {void}
1059 + */
1060 + function maybeOpenCollapsedPage( placeholder ) {
1061 + if ( ! placeholder.previousElementSibling || ! placeholder.previousElementSibling.classList.contains( 'frm-is-collapsed' ) ) {
1062 + return;
1063 + }
1064 +
1065 + const $pageBreakField = jQuery( placeholder ).prevUntil( '[data-type="break"]' );
1066 + if ( ! $pageBreakField.length ) {
1067 + return;
1068 + }
1069 +
1070 + const collapseButton = $pageBreakField.find( '.frm-collapse-page' ).get( 0 );
1071 + if ( collapseButton ) {
1072 + collapseButton.click();
1073 + }
1074 + }
1075 +
1076 + function maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields ) {
1077 + if ( ! $previousFieldContainer.length ) {
1078 + return;
1079 + }
1080 +
1081 + if ( $previousContainerFields.length ) {
1082 + syncLayoutClasses( $previousContainerFields.first() );
1083 + } else {
1084 + maybeDeleteAnEmptyFieldGroup( $previousFieldContainer.get( 0 ) );
1085 + }
1086 + }
1087 +
1088 + function maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields ) {
1089 + if ( 0 !== $previousContainerFields.length || 1 !== getFieldsInRow( jQuery( draggable.parentNode ) ).length ) {
1090 + syncLayoutClasses( jQuery( draggable ) );
1091 + }
1092 + }
1093 +
1094 + /**
1095 + * Remove an empty field group, but don't remove an empty section.
1096 + *
1097 + * @param {Element} previousFieldContainer
1098 + * @returns {void}
1099 + */
1100 + function maybeDeleteAnEmptyFieldGroup( previousFieldContainer ) {
1101 + const closestFieldBox = previousFieldContainer.closest( 'li.frm_field_box' );
1102 + if ( closestFieldBox && ! closestFieldBox.classList.contains( 'edit_field_type_divider' ) ) {
1103 + closestFieldBox.remove();
1104 + }
1105 + }
1106 +
1107 + function handleDragOverYAxis({ droppable, y, placeholder }) {
1108 + const $list = jQuery( droppable );
1109 +
1110 + let top;
1111 +
1112 + $children = $list.children().not( '.edit_field_type_end_divider' );
1113 + if ( 0 === $children.length ) {
1114 + $list.prepend( placeholder );
1115 + top = 0;
1116 + } else {
1117 + const insertAtIndex = determineIndexBasedOffOfMousePositionInList( $list, y );
1118 +
1119 + if ( insertAtIndex === $children.length ) {
1120 + const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) );
1121 + top = $lastChild.offset().top + $lastChild.outerHeight();
1122 + $list.append( placeholder );
1123 +
1124 + // Make sure nothing gets inserted after the end divider.
1125 + const $endDivider = $list.children( '.edit_field_type_end_divider' );
1126 + if ( $endDivider.length ) {
1127 + $list.append( $endDivider );
1128 + }
1129 + } else {
1130 + top = jQuery( $children.get( insertAtIndex ) ).offset().top;
1131 + jQuery( $children.get( insertAtIndex ) ).before( placeholder );
1132 + }
1133 + }
1134 +
1135 + top -= $list.offset().top;
1136 + placeholder.style.top = top + 'px';
1137 + }
1138 +
1139 + function determineIndexBasedOffOfMousePositionInList( $list, y ) {
1140 + const $items = $list.children().not( '.edit_field_type_end_divider' );
1141 + const length = $items.length;
1142 +
1143 + let index, item, itemTop, returnIndex;
1144 +
1145 + if ( ! document.querySelector( '.frm-has-fields .frm_no_fields' ) ) {
1146 + // Always return 0 when there are no fields.
1147 + return 0;
1148 + }
1149 +
1150 + returnIndex = 0;
1151 + for ( index = length - 1; index >= 0; --index ) {
1152 + item = $items.get( index );
1153 + itemTop = jQuery( item ).offset().top;
1154 + if ( y > itemTop ) {
1155 + returnIndex = index;
1156 + if ( y > itemTop + ( jQuery( item ).outerHeight() / 2 ) ) {
1157 + returnIndex = index + 1;
1158 + }
1159 + break;
1160 + }
1161 + }
1162 +
1163 + return returnIndex;
1164 + }
1165 +
1166 + function handleDragOverFieldGroup({ droppable, x, placeholder }) {
1167 + const $row = jQuery( droppable );
1168 + const $children = getFieldsInRow( $row );
1169 +
1170 + if ( ! $children.length ) {
1171 + return;
1172 + }
1173 +
1174 + let left;
1175 + const insertAtIndex = determineIndexBasedOffOfMousePositionInRow( $row, x );
1176 +
1177 + if ( insertAtIndex === $children.length ) {
1178 + const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) );
1179 + left = $lastChild.offset().left + $lastChild.outerWidth();
1180 + $row.append( placeholder );
1181 + } else {
1182 + left = jQuery( $children.get( insertAtIndex ) ).offset().left;
1183 + jQuery( $children.get( insertAtIndex ) ).before( placeholder );
1184 +
1185 + const amountToOffsetLeftBy = 0 === insertAtIndex ? 4 : 8; // Offset by 8 in between rows, but only 4 for the first item in a group.
1186 + left -= amountToOffsetLeftBy; // Offset the placeholder slightly so it appears between two fields.
1187 + }
1188 +
1189 + left -= $row.offset().left;
1190 +
1191 + placeholder.style.left = left + 'px';
1192 + }
1193 +
1194 + function syncAfterDragAndDrop() {
1195 + fixUnwrappedListItems();
1196 + toggleSectionHolder();
1197 + maybeFixEndDividers();
1198 + maybeDeleteEmptyFieldGroups();
1199 + updateFieldOrder();
1200 +
1201 + const event = new Event( 'frm_sync_after_drag_and_drop', { bubbles: false });
1202 + document.dispatchEvent( event );
1203 + }
1204 +
1205 + function maybeFixEndDividers() {
1206 + document.querySelectorAll( '.edit_field_type_end_divider' ).forEach(
1207 + endDivider => endDivider.parentNode.appendChild( endDivider )
1208 + );
1209 + }
1210 +
1211 + function maybeDeleteEmptyFieldGroups() {
1212 + document.querySelectorAll( 'li.form_field_box:not(.form-field)' ).forEach(
1213 + fieldGroup => ! fieldGroup.children.length && fieldGroup.remove()
1214 + );
1215 + }
1216 +
1217 + function fixUnwrappedListItems() {
1218 + const lists = document.querySelectorAll( 'ul#frm-show-fields, ul.start_divider' );
1219 + lists.forEach(
1220 + list => {
1221 + list.childNodes.forEach(
1222 + child => {
1223 + if ( 'undefined' === typeof child.classList ) {
1224 + return;
1225 + }
1226 +
1227 + if ( child.classList.contains( 'edit_field_type_end_divider' ) ) {
1228 + // Never wrap end divider in place.
1229 + return;
1230 + }
1231 +
1232 + if ( 'undefined' !== typeof child.classList && child.classList.contains( 'form-field' ) ) {
1233 + wrapFieldLiInPlace( child );
1234 + }
1235 + }
1236 + );
1237 + }
1238 + );
1239 + }
1240 +
1241 + function deleteEmptyDividerWrappers() {
1242 + const dividers = document.querySelectorAll( 'ul.start_divider' );
1243 + if ( ! dividers.length ) {
1244 + return;
1245 + }
1246 + dividers.forEach(
1247 + function( divider ) {
1248 + const children = [].slice.call( divider.children );
1249 + children.forEach(
1250 + function( child ) {
1251 + if ( 0 === child.children.length ) {
1252 + child.remove();
1253 + } else if ( 1 === child.children.length && 'ul' === child.firstElementChild.nodeName.toLowerCase() && 0 === child.firstElementChild.children.length ) {
1254 + child.remove();
1255 + }
1256 + }
1257 + );
1258 + }
1259 + );
1260 + }
1261 +
1262 + function getFieldsInRow( $row ) {
1263 + let $fields = jQuery();
1264 +
1265 + const row = $row.get( 0 );
1266 + if ( ! row.children ) {
1267 + return $fields;
1268 + }
1269 +
1270 + Array.from( row.children ).forEach(
1271 + child => {
1272 + if ( 'none' === child.style.display ) {
1273 + return;
1274 + }
1275 +
1276 + const classes = child.classList;
1277 + if ( ! classes.contains( 'form-field' ) || classes.contains( 'edit_field_type_end_divider' ) || classes.contains( 'frm-sortable-helper' ) ) {
1278 + return;
1279 + }
1280 +
1281 + $fields = $fields.add( child );
1282 + }
1283 + );
1284 + return $fields;
1285 + }
1286 +
1287 + function determineIndexBasedOffOfMousePositionInRow( $row, x ) {
1288 + let $inputs = getFieldsInRow( $row ),
1289 + length = $inputs.length,
1290 + index, input, inputLeft, returnIndex;
1291 +
1292 + returnIndex = 0;
1293 + for ( index = length - 1; index >= 0; --index ) {
1294 + input = $inputs.get( index );
1295 + inputLeft = jQuery( input ).offset().left;
1296 + if ( x > inputLeft ) {
1297 + returnIndex = index;
1298 + if ( x > inputLeft + ( jQuery( input ).outerWidth() / 2 ) ) {
1299 + returnIndex = index + 1;
1300 + }
1301 + break;
1302 + }
1303 + }
1304 +
1305 + return returnIndex;
1306 + }
1307 +
1308 + function syncLayoutClasses( $item, type ) {
1309 + let $fields, size, layoutClasses, classToAddFunction;
1310 +
1311 + if ( 'undefined' === typeof type ) {
1312 + type = 'even';
1313 + }
1314 +
1315 + $fields = $item.parent().children( 'li.form-field, li.frmbutton_loadingnow' ).not( '.edit_field_type_end_divider' );
1316 + size = $fields.length;
1317 + layoutClasses = getLayoutClasses();
1318 +
1319 + if ( 'even' === type && 5 !== size ) {
1320 + $fields.each( getSyncLayoutClass( layoutClasses, getEvenClassForSize( size ) ) );
1321 + } else if ( 'clear' === type ) {
1322 + $fields.each( getSyncLayoutClass( layoutClasses, '' ) );
1323 + } else {
1324 + if ( -1 !== [ 'left', 'right', 'middle', 'even' ].indexOf( type ) ) {
1325 + classToAddFunction = function( index ) {
1326 + return getClassForBlock( size, type, index );
1327 + };
1328 + } else {
1329 + classToAddFunction = function( index ) {
1330 + const size = type[ index ];
1331 + return getLayoutClassForSize( size );
1332 + };
1333 + }
1334 +
1335 + $fields.each( getSyncLayoutClass( layoutClasses, classToAddFunction ) );
1336 + }
1337 +
1338 + updateFieldGroupControls( $item.parent(), $fields.length );
1339 + }
1340 +
1341 + function updateFieldGroupControls( $row, count ) {
1342 + let rowOffset, shouldShowControls, controls;
1343 +
1344 + rowOffset = $row.offset();
1345 +
1346 + if ( 'undefined' === typeof rowOffset ) {
1347 + return;
1348 + }
1349 +
1350 + shouldShowControls = count >= 2;
1351 +
1352 + controls = document.getElementById( 'frm_field_group_controls' );
1353 + if ( null === controls ) {
1354 + if ( ! shouldShowControls ) {
1355 + // exit early. if we do not need controls and they do not exist, do nothing.
1356 + return;
1357 + }
1358 +
1359 + controls = div();
1360 + controls.id = 'frm_field_group_controls';
1361 + controls.setAttribute( 'role', 'group' );
1362 + controls.setAttribute( 'tabindex', 0 );
1363 + setFieldControlsHtml( controls );
1364 + builderPage.appendChild( controls );
1365 + }
1366 +
1367 + $row.append( controls );
1368 + controls.style.display = shouldShowControls ? 'block' : 'none';
1369 + }
1370 +
1371 + function setFieldControlsHtml( controls ) {
1372 + let layoutOption, moveOption;
1373 +
1374 + layoutOption = document.createElement( 'span' );
1375 + layoutOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_field_group_layout_icon"></use></svg>';
1376 + const layoutOptionLabel = __( 'Set Row Layout', 'formidable' );
1377 + addTooltip( layoutOption, layoutOptionLabel );
1378 + makeTabbable( layoutOption, layoutOptionLabel );
1379 +
1380 + moveOption = document.createElement( 'span' );
1381 + moveOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_thick_move_icon"></use></svg>';
1382 + moveOption.classList.add( 'frm-move' );
1383 + const moveOptionLabel = __( 'Move Field Group', 'formidable' );
1384 + addTooltip( moveOption, moveOptionLabel );
1385 + makeTabbable( moveOption, moveOptionLabel );
1386 +
1387 + controls.innerHTML = '';
1388 + controls.appendChild( layoutOption );
1389 + controls.appendChild( moveOption );
1390 + controls.appendChild( getFieldControlsDropdown() );
1391 + }
1392 +
1393 + function addTooltip( element, title ) {
1394 + element.setAttribute( 'data-toggle', 'tooltip' );
1395 + element.setAttribute( 'data-container', 'body' );
1396 + element.setAttribute( 'title', title );
1397 + element.addEventListener(
1398 + 'mouseover',
1399 + function() {
1400 + if ( null === element.getAttribute( 'data-original-title' ) ) {
1401 + jQuery( element ).tooltip();
1402 + }
1403 + }
1404 + );
1405 + }
1406 +
1407 + function getFieldControlsDropdown() {
1408 + const dropdown = span({ className: 'dropdown' });
1409 + const trigger = a({
1410 + className: 'frm_bstooltip frm-hover-icon frm-dropdown-toggle dropdown-toggle',
1411 + children: [
1412 + span({
1413 + child: svg({ href: '#frm_thick_more_vert_icon' })
1414 + }),
1415 + span({
1416 + className: 'screen-reader-text',
1417 + text: __( 'Toggle More Options Dropdown', 'formidable' )
1418 + })
1419 + ]
1420 + });
1421 +
1422 + frmDom.setAttributes(
1423 + trigger,
1424 + {
1425 + 'title': __( 'More Options', 'formidable' ),
1426 + 'data-toggle': 'dropdown',
1427 + 'data-container': 'body'
1428 + }
1429 + );
1430 + makeTabbable( trigger, __( 'More Options', 'formidable' ) );
1431 + dropdown.appendChild( trigger );
1432 +
1433 + const ul = div({
1434 + className: 'frm-dropdown-menu dropdown-menu dropdown-menu-right'
1435 + });
1436 + ul.setAttribute( 'role', 'menu' );
1437 + dropdown.appendChild( ul );
1438 +
1439 + return dropdown;
1440 + }
1441 +
1442 + function getSyncLayoutClass( layoutClasses, classToAdd ) {
1443 + return function( itemIndex ) {
1444 + let currentClassToAdd, length, layoutClassIndex, currentClass, activeLayoutClass, fieldId, layoutClassesInput;
1445 +
1446 + currentClassToAdd = 'function' === typeof classToAdd ? classToAdd( itemIndex ) : classToAdd;
1447 + length = layoutClasses.length;
1448 + activeLayoutClass = false;
1449 + for ( layoutClassIndex = 0; layoutClassIndex < length; ++layoutClassIndex ) {
1450 + currentClass = layoutClasses[ layoutClassIndex ];
1451 + if ( this.classList.contains( currentClass ) ) {
1452 + activeLayoutClass = currentClass;
1453 + break;
1454 + }
1455 + }
1456 +
1457 + fieldId = this.dataset.fid;
1458 +
1459 + if ( 'undefined' === typeof fieldId ) {
1460 + // we are syncing the drag/drop placeholder before the actual field has loaded.
1461 + // this will get called again afterward and the input will exist then.
1462 + this.classList.add( currentClassToAdd );
1463 + return;
1464 + }
1465 +
1466 + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) );
1467 + layoutClassesInput = document.getElementById( 'frm_classes_' + fieldId );
1468 +
1469 + if ( null === layoutClassesInput ) {
1470 + // not every field type has a layout class input.
1471 + return;
1472 + }
1473 +
1474 + if ( false === activeLayoutClass ) {
1475 + if ( '' !== currentClassToAdd ) {
1476 + layoutClassesInput.value = layoutClassesInput.value.concat( ' ' + currentClassToAdd );
1477 + }
1478 + } else {
1479 + this.classList.remove( activeLayoutClass );
1480 + layoutClassesInput.value = layoutClassesInput.value.replace( activeLayoutClass, currentClassToAdd );
1481 + }
1482 +
1483 + if ( this.classList.contains( 'frm_first' ) ) {
1484 + this.classList.remove( 'frm_first' );
1485 + layoutClassesInput.value = layoutClassesInput.value.replace( 'frm_first', '' ).trim();
1486 + }
1487 +
1488 + if ( 0 === itemIndex ) {
1489 + this.classList.add( 'frm_first' );
1490 + layoutClassesInput.value = layoutClassesInput.value.concat( ' frm_first' );
1491 + }
1492 +
1493 + jQuery( layoutClassesInput ).trigger( 'change' );
1494 + };
1495 + }
1496 +
1497 + function getLayoutClasses() {
1498 + 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' ];
1499 + }
1500 +
1501 + function setupFieldOptionSorting( sort ) {
1502 + const opts = {
1503 + items: '.frm_sortable_field_opts li',
1504 + axis: 'y',
1505 + opacity: 0.65,
1506 + forcePlaceholderSize: false,
1507 + handle: '.frm-drag',
1508 + helper: function( e, li ) {
1509 + copyHelper = li.clone().insertAfter( li );
1510 + return li.clone();
1511 + },
1512 + stop: function( e, ui ) {
1513 + copyHelper && copyHelper.remove();
1514 + const fieldId = ui.item.attr( 'id' ).replace( 'frm_delete_field_', '' ).replace( '-' + ui.item.data( 'optkey' ) + '_container', '' );
1515 + resetDisplayedOpts( fieldId );
1516 + fieldUpdated();
1517 + }
1518 + };
1519 + jQuery( sort ).sortable( opts );
1520 + }
1521 +
1522 + // Get the section where a field is dropped
1523 + function getSectionForFieldPlacement( currentItem ) {
1524 + let section = '';
1525 + if ( typeof currentItem !== 'undefined' && ! currentItem.hasClass( 'edit_field_type_divider' ) ) {
1526 + section = currentItem.closest( '.edit_field_type_divider' );
1527 + }
1528 + return section;
1529 + }
1530 +
1531 + // Get the form ID where a field is dropped
1532 + function getFormIdForFieldPlacement( section ) {
1533 + let formId = '';
1534 +
1535 + if ( typeof section[0] !== 'undefined' ) {
1536 + const sDivide = section.children( '.start_divider' );
1537 + sDivide.children( '.edit_field_type_end_divider' ).appendTo( sDivide );
1538 + if ( typeof section.attr( 'data-formid' ) !== 'undefined' ) {
1539 + const fieldId = section.attr( 'data-fid' );
1540 + formId = jQuery( 'input[name="field_options[form_select_' + fieldId + ']"]' ).val();
1541 + }
1542 + }
1543 +
1544 + if ( typeof formId === 'undefined' || formId === '' ) {
1545 + formId = thisFormId;
1546 + }
1547 +
1548 + return formId;
1549 + }
1550 +
1551 + // Get the section ID where a field is dropped
1552 + function getSectionIdForFieldPlacement( section ) {
1553 + let sectionId = 0;
1554 + if ( typeof section[0] !== 'undefined' ) {
1555 + sectionId = section.attr( 'id' ).replace( 'frm_field_id_', '' );
1556 + }
1557 +
1558 + return sectionId;
1559 + }
1560 +
1561 + /**
1562 + * Update a field after it is dragged and dropped into, out of, or between sections
1563 + *
1564 + * @param {Object} currentItem
1565 + * @param {Object} previousSection
1566 + * @returns {void}
1567 + */
1568 + function updateFieldAfterMovingBetweenSections( currentItem, previousSection ) {
1569 + if ( ! currentItem.hasClass( 'form-field' ) ) {
1570 + // currentItem is a field group. Call for children recursively.
1571 + getFieldsInRow( jQuery( currentItem.get( 0 ).firstChild ) ).each(
1572 + function() {
1573 + updateFieldAfterMovingBetweenSections( jQuery( this ), previousSection );
1574 + }
1575 + );
1576 + return;
1577 + }
1578 +
1579 + const fieldId = currentItem.attr( 'id' ).replace( 'frm_field_id_', '' );
1580 + const section = getSectionForFieldPlacement( currentItem );
1581 + const formId = getFormIdForFieldPlacement( section );
1582 + const sectionId = getSectionIdForFieldPlacement( section );
1583 + const previousFormId = previousSection ? getFormIdForFieldPlacement( jQuery( previousSection.parentNode ) ) : 0;
1584 +
1585 + jQuery.ajax({
1586 + type: 'POST',
1587 + url: ajaxurl,
1588 + data: {
1589 + action: 'frm_update_field_after_move',
1590 + form_id: formId,
1591 + field: fieldId,
1592 + section_id: sectionId,
1593 + previous_form_id: previousFormId,
1594 + nonce: frmGlobal.nonce
1595 + },
1596 + success: function() {
1597 + toggleSectionHolder();
1598 + updateInSectionValue( fieldId, sectionId );
1599 + }
1600 + });
1601 + }
1602 +
1603 + // Update the in_section field value
1604 + function updateInSectionValue( fieldId, sectionId ) {
1605 + document.getElementById( 'frm_in_section_' + fieldId ).value = sectionId;
1606 + }
1607 +
1608 + /**
1609 + * Add a new field by dragging and dropping it from the Fields sidebar
1610 + *
1611 + * @param {string} fieldType
1612 + */
1613 + function insertNewFieldByDragging( fieldType ) {
1614 + const placeholder = document.getElementById( 'frm_drag_placeholder' );
1615 + const loadingID = fieldType.replace( '|', '-' ) + '_' + getAutoId();
1616 + const loading = tag(
1617 + 'li',
1618 + {
1619 + id: loadingID,
1620 + className: 'frm-wait frmbutton_loadingnow'
1621 + }
1622 + );
1623 + const $placeholder = jQuery( loading );
1624 + const currentItem = jQuery( placeholder );
1625 + const section = getSectionForFieldPlacement( currentItem );
1626 + const formId = getFormIdForFieldPlacement( section );
1627 + const sectionId = getSectionIdForFieldPlacement( section );
1628 +
1629 + placeholder.parentNode.insertBefore( loading, placeholder );
1630 + placeholder.remove();
1631 + syncLayoutClasses( $placeholder );
1632 +
1633 + let hasBreak = 0;
1634 + if ( 'summary' === fieldType ) {
1635 + // see if we need to insert a page break before this newly-added summary field. Check for at least 1 page break
1636 + hasBreak = jQuery( '.frmbutton_loadingnow#' + loadingID ).prevAll( 'li[data-type="break"]' ).length ? 1 : 0;
1637 + }
1638 +
1639 + jQuery.ajax({
1640 + type: 'POST', url: ajaxurl,
1641 + data: {
1642 + action: 'frm_insert_field',
1643 + form_id: formId,
1644 + field_type: fieldType,
1645 + section_id: sectionId,
1646 + nonce: frmGlobal.nonce,
1647 + has_break: hasBreak,
1648 + last_row_field_ids: getFieldIdsInSubmitRow()
1649 + },
1650 + success: function( msg ) {
1651 + let replaceWith;
1652 + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' );
1653 + const $siblings = $placeholder.siblings( 'li.form-field' ).not( '.edit_field_type_end_divider' );
1654 + if ( ! $siblings.length ) {
1655 + // if dragging into a new row, we need to wrap the li first.
1656 + replaceWith = wrapFieldLi( msg );
1657 + } else {
1658 + replaceWith = msgAsjQueryObject( msg );
1659 + if ( ! $placeholder.get( 0 ).parentNode.parentNode.classList.contains( 'ui-draggable' ) ) {
1660 + // If a field group wasn't draggable because it only had a single field, make it draggable.
1661 + makeDraggable( $placeholder.get( 0 ).parentNode.parentNode, '.frm-move' );
1662 + }
1663 + }
1664 + $placeholder.replaceWith( replaceWith );
1665 + updateFieldOrder();
1666 + afterAddField( msg, false );
1667 + if ( $siblings.length ) {
1668 + syncLayoutClasses( $siblings.first() );
1669 + }
1670 + toggleSectionHolder();
1671 +
1672 + if ( ! $siblings.length ) {
1673 + makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) );
1674 + makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' );
1675 + } else {
1676 + makeDraggable( replaceWith.get( 0 ), '.frm-move' );
1677 + }
1678 +
1679 + },
1680 + error: handleInsertFieldError
1681 + });
1682 + }
1683 +
1684 + function getFieldIdsInSubmitRow() {
1685 + const submitField = document.querySelector( '.edit_field_type_submit' );
1686 + if ( ! submitField ) {
1687 + return [];
1688 + }
1689 +
1690 + const lastRowFields = submitField.parentNode.children;
1691 + const ids = [];
1692 + for ( let i = 0; i < lastRowFields.length; i++ ) {
1693 + ids.push( lastRowFields[ i ].dataset.fid );
1694 + }
1695 +
1696 + return ids;
1697 + }
1698 +
1699 + function moveFieldThatAlreadyExists( draggable, placeholder ) {
1700 + placeholder.parentNode.insertBefore( draggable, placeholder );
1701 + }
1702 +
1703 + function msgAsjQueryObject( msg ) {
1704 + const element = div();
1705 + element.innerHTML = msg;
1706 + return jQuery( element.firstChild );
1707 + }
1708 +
1709 + function handleInsertFieldError( jqXHR, _, errorThrown ) {
1710 + maybeShowInsertFieldError( errorThrown, jqXHR );
1711 + }
1712 +
1713 + function maybeShowInsertFieldError( errorThrown, jqXHR ) {
1714 + if ( ! jqXHRAborted( jqXHR ) ) {
1715 + infoModal( errorThrown + '. Please try again.' );
1716 + }
1717 + }
1718 +
1719 + function jqXHRAborted( jqXHR ) {
1720 + return jqXHR.status === 0 || jqXHR.readyState === 0;
1721 + }
1722 +
1723 + /**
1724 + * Get a unique id that automatically increments with every function call.
1725 + * Can be used for any UI that requires a unique id.
1726 + * Not to be used in data.
1727 + *
1728 + * @returns {integer}
1729 + */
1730 + function getAutoId() {
1731 + return ++autoId;
1732 + }
1733 +
1734 + /**
1735 + * Determine if a draggable element can be droppable into a droppable element.
1736 + *
1737 + * Don't allow page break, embed form, or section inside section field
1738 + * Don't allow page breaks inside of field groups.
1739 + * Don't allow field groups with sections inside of sections.
1740 + * Don't allow field groups in field groups.
1741 + * Don't allow hidden fields inside of field groups but allow them in sections.
1742 + * Don't allow any fields below the submit button field.
1743 + * Don't allow submit button field above any fields.
1744 + *
1745 + * @param {HTMLElement} draggable
1746 + * @param {HTMLElement} droppable
1747 + * @param {Event} event
1748 + * @returns {Boolean}
1749 + */
1750 + function allowDrop( draggable, droppable, event ) {
1751 + if ( false === droppable ) {
1752 + // Don't show drop placeholder if dragging somewhere off of the droppable area.
1753 + return false;
1754 + }
1755 +
1756 + if ( droppable.closest( '.frm-sortable-helper' ) ) {
1757 + // Do not allow drop into draggable.
1758 + return false;
1759 + }
1760 +
1761 + const isSubmitBtn = draggable.classList.contains( 'edit_field_type_submit' );
1762 + const containSubmitBtn = ! draggable.classList.contains( 'form_field' ) && !! draggable.querySelector( '.edit_field_type_submit' );
1763 +
1764 + if ( 'frm-show-fields' === droppable.id ) {
1765 + const draggableIndex = determineIndexBasedOffOfMousePositionInList( jQuery( droppable ), event.clientY );
1766 +
1767 + if ( isSubmitBtn || containSubmitBtn ) {
1768 + // Do not allow dropping submit button to above position.
1769 + const lastRowIndex = droppable.childElementCount - 1;
1770 + return draggableIndex > lastRowIndex;
1771 + }
1772 +
1773 + // Do not allow dropping other fields to below submit button.
1774 + const submitButtonIndex = jQuery( droppable.querySelector( '.edit_field_type_submit' ).closest( '#frm-show-fields > li' ) ).index();
1775 + return draggableIndex <= submitButtonIndex;
1776 + }
1777 +
1778 + if ( isSubmitBtn ) {
1779 + if ( droppable.classList.contains( 'start_divider' ) ) {
1780 + // Don't allow dropping submit button into a repeater.
1781 + return false;
1782 + }
1783 +
1784 + if ( isLastRow( droppable.parentElement ) ) {
1785 + // Allow dropping submit button into the last row.
1786 + return true;
1787 + }
1788 +
1789 + if ( ! isLastRow( droppable.parentElement.nextElementSibling ) ) {
1790 + // Don't a dropping submit button into the row that isn't the second one from bottom.
1791 + return false;
1792 + }
1793 +
1794 + // Allow dropping submit button into the second row from bottom if there is only submit button in the last row.
1795 + return ! draggable.parentElement.querySelector( 'li.frm_field_box:not(.edit_field_type_submit)' );
1796 + }
1797 +
1798 + if ( ! droppable.classList.contains( 'start_divider' ) ) {
1799 + const $fieldsInRow = getFieldsInRow( jQuery( droppable ) );
1800 + if ( ! groupCanFitAnotherField( $fieldsInRow, jQuery( draggable ) ) ) {
1801 + // Field group is full and cannot accept another field.
1802 + return false;
1803 + }
1804 + }
1805 +
1806 + const isNewField = draggable.classList.contains( 'frm-new-field' );
1807 + if ( isNewField ) {
1808 + return allowNewFieldDrop( draggable, droppable );
1809 + }
1810 +
1811 + return allowMoveField( draggable, droppable );
1812 + }
1813 +
1814 + /**
1815 + * Checks if given element is the last row in form builder.
1816 + *
1817 + * @param {HTMLElement} element Element.
1818 + * @return {Boolean}
1819 + */
1820 + function isLastRow( element ) {
1821 + return element && element.matches( '#frm-show-fields > li:last-child' );
1822 + }
1823 +
1824 + // Don't allow a new page break or hidden field in a field group.
1825 + // Don't allow a new field into a field group that includes a page break or hidden field.
1826 + // Don't allow a new section inside of a section.
1827 + // Don't allow an embedded form in a section.
1828 + function allowNewFieldDrop( draggable, droppable ) {
1829 + const classes = draggable.classList;
1830 + const newPageBreakField = classes.contains( 'frm_tbreak' );
1831 + const newHiddenField = classes.contains( 'frm_thidden' );
1832 + const newSectionField = classes.contains( 'frm_tdivider' );
1833 + const newEmbedField = classes.contains( 'frm_tform' );
1834 + const newUserIdField = classes.contains( 'frm_tuser_id' );
1835 +
1836 + const newFieldWillBeAddedToAGroup = ! ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) );
1837 + if ( newFieldWillBeAddedToAGroup ) {
1838 + if ( groupIncludesBreakOrHiddenOrUserId( droppable ) ) {
1839 + // Never allow any field beside a page break or a hidden field.
1840 + return false;
1841 + }
1842 +
1843 + return ! newHiddenField && ! newPageBreakField && ! newUserIdField;
1844 + }
1845 +
1846 + const fieldTypeIsAlwaysAllowed = ! newPageBreakField && ! newHiddenField && ! newSectionField && ! newEmbedField;
1847 + if ( fieldTypeIsAlwaysAllowed ) {
1848 + return true;
1849 + }
1850 +
1851 + const newFieldWillBeAddedToASection = droppable.classList.contains( 'start_divider' ) || null !== droppable.closest( '.start_divider' );
1852 + if ( newFieldWillBeAddedToASection ) {
1853 + // Don't allow a section or an embedded form in a section.
1854 + return ! newEmbedField && ! newSectionField;
1855 + }
1856 +
1857 + return true;
1858 + }
1859 +
1860 + function allowMoveField( draggable, droppable ) {
1861 + if ( isFieldGroup( draggable ) ) {
1862 + return allowMoveFieldGroup( draggable, droppable );
1863 + }
1864 +
1865 + const isPageBreak = draggable.classList.contains( 'edit_field_type_break' );
1866 + if ( isPageBreak ) {
1867 + // Page breaks are only allowed in the main list of fields, not in sections or in field groups.
1868 + return false;
1869 + }
1870 +
1871 + if ( droppable.classList.contains( 'start_divider' ) ) {
1872 + return allowMoveFieldToSection( draggable );
1873 + }
1874 +
1875 + const isHiddenField = draggable.classList.contains( 'edit_field_type_hidden' );
1876 + const isUserIdField = draggable.classList.contains( 'edit_field_type_user_id' );
1877 + if ( isHiddenField || isUserIdField ) {
1878 + // Hidden fields and user id fields should not be added to field groups since they're not shown
1879 + // and don't make sense with the grid distribution.
1880 + return false;
1881 + }
1882 +
1883 + return allowMoveFieldToGroup( draggable, droppable );
1884 + }
1885 +
1886 + function isFieldGroup( draggable ) {
1887 + return draggable.classList.contains( 'frm_field_box' ) && ! draggable.classList.contains( 'form-field' );
1888 + }
1889 +
1890 + function allowMoveFieldGroup( fieldGroup, droppable ) {
1891 + if ( droppable.classList.contains( 'start_divider' ) && null === fieldGroup.querySelector( '.start_divider' ) ) {
1892 + // Allow a field group with no section inside of a section.
1893 + return true;
1894 + }
1895 + return false;
1896 + }
1897 +
1898 + function allowMoveFieldToSection( draggable ) {
1899 + const draggableIncludeEmbedForm = draggable.classList.contains( 'edit_field_type_form' ) || draggable.querySelector( '.edit_field_type_form' );
1900 + if ( draggableIncludeEmbedForm ) {
1901 + // Do not allow an embedded form inside of a section.
1902 + return false;
1903 + }
1904 +
1905 + const draggableIncludesSection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' );
1906 + if ( draggableIncludesSection ) {
1907 + // Do not allow a section inside of a section.
1908 + return false;
1909 + }
1910 +
1911 + return true;
1912 + }
1913 +
1914 + function allowMoveFieldToGroup( draggable, group ) {
1915 + if ( groupIncludesBreakOrHiddenOrUserId( group ) ) {
1916 + // Never allow any field beside a page break or a hidden field.
1917 + return false;
1918 + }
1919 +
1920 + const isFieldGroup = jQuery( draggable ).children( 'ul.frm_sorting' ).not( '.start_divider' ).length > 0;
1921 + if ( isFieldGroup ) {
1922 + // Do not allow a field group directly inside of a field group unless it's in a section.
1923 + return false;
1924 + }
1925 +
1926 + const draggableIncludesASection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' );
1927 + const draggableIsEmbedField = draggable.classList.contains( 'edit_field_type_form' );
1928 + const groupIsInASection = null !== group.closest( '.start_divider' );
1929 + if ( groupIsInASection && ( draggableIncludesASection || draggableIsEmbedField ) ) {
1930 + // Do not allow a section or an embed field inside of a section.
1931 + return false;
1932 + }
1933 +
1934 + return true;
1935 + }
1936 +
1937 + function groupIncludesBreakOrHiddenOrUserId( group ) {
1938 + return null !== group.querySelector( '.edit_field_type_break, .edit_field_type_hidden, .edit_field_type_user_id' );
1939 + }
1940 +
1941 + function groupCanFitAnotherField( fieldsInRow, $field ) {
1942 + let fieldId;
1943 + if ( fieldsInRow.length < 6 ) {
1944 + return true;
1945 + }
1946 + if ( fieldsInRow.length > 6 ) {
1947 + return false;
1948 + }
1949 + fieldId = $field.attr( 'data-fid' );
1950 + // allow 6 if we're not changing field groups.
1951 + return 1 === jQuery( fieldsInRow ).filter( '[data-fid="' + fieldId + '"]' ).length;
1952 + }
1953 +
1954 + function loadFields( fieldId ) {
1955 + const thisField = document.getElementById( fieldId );
1956 + const $thisField = jQuery( thisField );
1957 + const field = [];
1958 + const addHtmlToField = element => {
1959 + const frmHiddenFdata = element.querySelector( '.frm_hidden_fdata' );
1960 + element.classList.add( 'frm_load_now' );
1961 + if ( frmHiddenFdata !== null ) {
1962 + field.push( frmHiddenFdata.innerHTML );
1963 + }
1964 + };
1965 +
1966 + let nextElement = thisField;
1967 + addHtmlToField( nextElement );
1968 +
1969 + let nextField = getNextField( nextElement );
1970 + while ( nextField && field.length < 15 ) {
1971 + addHtmlToField( nextField );
1972 + nextElement = nextField;
1973 + nextField = getNextField( nextField );
1974 + }
1975 +
1976 + jQuery.ajax({
1977 + type: 'POST',
1978 + url: ajaxurl,
1979 + data: {
1980 + action: 'frm_load_field',
1981 + field: field,
1982 + form_id: thisFormId,
1983 + nonce: frmGlobal.nonce
1984 + },
1985 + success: html => handleAjaxLoadFieldSuccess( html, $thisField, field )
1986 + });
1987 + }
1988 +
1989 + function getNextField( field ) {
1990 + if ( field.nextElementSibling ) {
1991 + return field.nextElementSibling;
1992 + }
1993 + return field.parentNode?.closest( '.frm_field_box' )?.nextElementSibling?.querySelector( '.form-field' );
1994 + }
1995 +
1996 + function handleAjaxLoadFieldSuccess( html, $thisField, field ) {
1997 + let key, $nextSet;
1998 +
1999 + html = html.replace( /^\s+|\s+$/g, '' );
2000 + if ( html.indexOf( '{' ) !== 0 ) {
2001 + jQuery( '.frm_load_now' ).removeClass( '.frm_load_now' ).html( 'Error' );
2002 + return;
2003 + }
2004 +
2005 + html = JSON.parse( html );
2006 + for ( key in html ) {
2007 + jQuery( '#frm_field_id_' + key ).replaceWith( html[key]);
2008 + setupSortable( '#frm_field_id_' + key + '.edit_field_type_divider ul.frm_sorting' );
2009 + makeDraggable( document.getElementById( 'frm_field_id_' + key ) );
2010 + }
2011 +
2012 + $nextSet = $thisField.nextAll( '.frm_field_loading:not(.frm_load_now)' );
2013 + if ( $nextSet.length ) {
2014 + loadFields( $nextSet.attr( 'id' ) );
2015 + } else {
2016 + // go up a level
2017 + $nextSet = jQuery( document.getElementById( 'frm-show-fields' ) ).find( '.frm_field_loading:not(.frm_load_now)' );
2018 + if ( $nextSet.length ) {
2019 + loadFields( $nextSet.attr( 'id' ) );
2020 + }
2021 + }
2022 +
2023 + initiateMultiselect();
2024 + renumberPageBreaks();
2025 + maybeHideQuantityProductFieldOption();
2026 +
2027 + const loadedEvent = new Event( 'frm_ajax_loaded_field', { bubbles: false });
2028 + loadedEvent.frmFields = field.map( f => JSON.parse( f ) );
2029 + document.dispatchEvent( loadedEvent );
2030 + }
2031 +
2032 + function addFieldClick() {
2033 + /*jshint validthis:true */
2034 + const $thisObj = jQuery( this );
2035 + // there is no real way to disable a <a> (with a valid href attribute) in HTML - https://css-tricks.com/how-to-disable-links/
2036 + if ( $thisObj.hasClass( 'disabled' ) ) {
2037 + return false;
2038 + }
2039 +
2040 + const $button = $thisObj.closest( '.frmbutton' );
2041 + const fieldType = $button.attr( 'id' );
2042 +
2043 + let hasBreak = 0;
2044 + if ( 'summary' === fieldType ) {
2045 + hasBreak = $newFields.children( 'li[data-type="break"]' ).length > 0 ? 1 : 0;
2046 + }
2047 +
2048 + const formId = thisFormId;
2049 + jQuery.ajax({
2050 + type: 'POST',
2051 + url: ajaxurl,
2052 + data: {
2053 + action: 'frm_insert_field',
2054 + form_id: formId,
2055 + field_type: fieldType,
2056 + section_id: 0,
2057 + nonce: frmGlobal.nonce,
2058 + has_break: hasBreak,
2059 + last_row_field_ids: getFieldIdsInSubmitRow()
2060 + },
2061 + success: function( msg ) {
2062 + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' );
2063 + const replaceWith = wrapFieldLi( msg );
2064 +
2065 + const submitField = $newFields[0].querySelector( '.edit_field_type_submit' );
2066 + if ( ! submitField ) {
2067 + $newFields.append( replaceWith );
2068 + } else {
2069 + jQuery( submitField.closest( '.frm_field_box:not(.form-field)' ) ).before( replaceWith );
2070 + }
2071 +
2072 + afterAddField( msg, true );
2073 +
2074 + replaceWith.each(
2075 + function() {
2076 + makeDroppable( this.querySelector( 'ul.frm_sorting' ) );
2077 + makeDraggable( this.querySelector( '.form-field' ), '.frm-move' );
2078 + }
2079 + );
2080 + },
2081 + error: handleInsertFieldError
2082 + });
2083 + return false;
2084 + }
2085 +
2086 + function maybeHideQuantityProductFieldOption() {
2087 + let hide = true,
2088 + opts = document.querySelectorAll( '.frmjs_prod_field_opt_cont' );
2089 +
2090 + if ( $newFields.find( 'li.edit_field_type_product' ).length > 1 ) {
2091 + hide = false;
2092 + }
2093 +
2094 + for ( let i = 0; i < opts.length; i++ ) {
2095 + if ( hide ) {
2096 + opts[ i ].classList.add( 'frm_hidden' );
2097 + } else {
2098 + opts[ i ].classList.remove( 'frm_hidden' );
2099 + }
2100 + }
2101 + }
2102 +
2103 + function duplicateField() {
2104 + let $field, fieldId, children, newRowId, fieldOrder;
2105 +
2106 + $field = jQuery( this ).closest( 'li.form-field' );
2107 +
2108 + if ( $field.hasClass( 'frm-page-collapsed' ) ) {
2109 + return false;
2110 + }
2111 +
2112 + closeOpenFieldDropdowns();
2113 + fieldId = $field.data( 'fid' );
2114 + children = fieldsInSection( fieldId );
2115 + newRowId = this.getAttribute( 'frm-target-row-id' );
2116 +
2117 + if ( null !== newRowId ) {
2118 + fieldOrder = this.getAttribute( 'frm-field-order' );
2119 + }
2120 +
2121 + jQuery.ajax({
2122 + type: 'POST',
2123 + url: ajaxurl,
2124 + data: {
2125 + action: 'frm_duplicate_field',
2126 + field_id: fieldId,
2127 + form_id: thisFormId,
2128 + children: children,
2129 + nonce: frmGlobal.nonce
2130 + },
2131 + success: function( msg ) {
2132 + let newRow;
2133 +
2134 + let replaceWith;
2135 +
2136 + if ( null !== newRowId ) {
2137 + newRow = document.getElementById( newRowId );
2138 + if ( null !== newRow ) {
2139 + replaceWith = msgAsjQueryObject( msg );
2140 + jQuery( newRow ).append( replaceWith );
2141 + makeDraggable( replaceWith.get( 0 ), '.frm-move' );
2142 + if ( null !== fieldOrder ) {
2143 + newRow.lastElementChild.setAttribute( 'frm-field-order', fieldOrder );
2144 + }
2145 + jQuery( newRow ).trigger(
2146 + 'frm_added_duplicated_field_to_row',
2147 + {
2148 + duplicatedFieldHtml: msg,
2149 + originalFieldId: fieldId
2150 + }
2151 + );
2152 + afterAddField( msg, false );
2153 + return;
2154 + }
2155 + }
2156 +
2157 + if ( $field.siblings( 'li.form-field' ).length ) {
2158 + replaceWith = msgAsjQueryObject( msg );
2159 + $field.after( replaceWith );
2160 + syncLayoutClasses( $field );
2161 + makeDraggable( replaceWith.get( 0 ), '.frm-move' );
2162 + } else {
2163 + replaceWith = wrapFieldLi( msg );
2164 + $field.parent().parent().after( replaceWith );
2165 + makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) );
2166 + makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' );
2167 + }
2168 +
2169 + updateFieldOrder();
2170 + afterAddField( msg, false );
2171 + maybeDuplicateUnsavedSettings( fieldId, msg );
2172 + toggleOneSectionHolder( replaceWith.find( '.start_divider' ) );
2173 + $field[0].querySelector( '.frm-dropdown-menu.dropdown-menu-right' )?.classList.remove( 'show' );
2174 + }
2175 + });
2176 + return false;
2177 + }
2178 +
2179 + function maybeDuplicateUnsavedSettings( originalFieldId, newFieldHtml ) {
2180 + let originalSettings, newFieldId, copySettings, fieldOptionKeys, originalDefault, copyDefault;
2181 +
2182 + originalSettings = document.getElementById( 'frm-single-settings-' + originalFieldId );
2183 + if ( null === originalSettings ) {
2184 + return;
2185 + }
2186 +
2187 + newFieldId = jQuery( newFieldHtml ).attr( 'data-fid' );
2188 + if ( 'undefined' === typeof newFieldId ) {
2189 + return;
2190 + }
2191 +
2192 + copySettings = document.getElementById( 'frm-single-settings-' + newFieldId );
2193 + if ( null === copySettings ) {
2194 + return;
2195 + }
2196 +
2197 + fieldOptionKeys = [
2198 + 'name', 'required', 'unique', 'read_only', 'placeholder', 'description', 'size', 'max', 'format', 'prepend', 'append', 'separate_value'
2199 + ];
2200 +
2201 + originalSettings.querySelectorAll( 'input[name^="field_options["], textarea[name^="field_options["]' ).forEach(
2202 + function( originalSetting ) {
2203 + let key, tagType, copySetting;
2204 +
2205 + key = getKeyFromSettingInput( originalSetting );
2206 +
2207 + if ( 'options' === key ) {
2208 + copyOption( originalSetting, copySettings, originalFieldId, newFieldId );
2209 + return;
2210 + }
2211 +
2212 + if ( -1 === fieldOptionKeys.indexOf( key ) ) {
2213 + return;
2214 + }
2215 +
2216 + tagType = originalSetting.matches( 'input' ) ? 'input' : 'textarea';
2217 + copySetting = copySettings.querySelector( tagType + '[name="field_options[' + key + '_' + newFieldId + ']"]' );
2218 + if ( null === copySetting ) {
2219 + return;
2220 + }
2221 +
2222 + if ( 'checkbox' === originalSetting.type ) {
2223 + if ( originalSetting.checked !== copySetting.checked ) {
2224 + jQuery( copySetting ).trigger( 'click' );
2225 + }
2226 + } else if ( 'text' === originalSetting.type || 'textarea' === tagType ) {
2227 + if ( originalSetting.value !== copySetting.value ) {
2228 + copySetting.value = originalSetting.value;
2229 + jQuery( copySetting ).trigger( 'change' );
2230 + }
2231 + }
2232 + }
2233 + );
2234 +
2235 + originalDefault = originalSettings.querySelector( 'input[name="default_value_' + originalFieldId + '"]' );
2236 + if ( null !== originalDefault ) {
2237 + copyDefault = copySettings.querySelector( 'input[name="default_value_' + newFieldId + '"]' );
2238 + if ( null !== copyDefault && originalDefault.value !== copyDefault.value ) {
2239 + copyDefault.value = originalDefault.value;
2240 + jQuery( copyDefault ).trigger( 'change' );
2241 + }
2242 + }
2243 + }
2244 +
2245 + function copyOption( originalSetting, copySettings, originalFieldId, newFieldId ) {
2246 + let remainingKeyDetails, copyKey, copySetting;
2247 + remainingKeyDetails = originalSetting.name.substr( 23 + ( '' + originalFieldId ).length );
2248 + copyKey = 'field_options[options_' + newFieldId + ']' + remainingKeyDetails;
2249 + copySetting = copySettings.querySelector( 'input[name="' + copyKey + '"]' );
2250 + if ( null !== copySetting && copySetting.value !== originalSetting.value ) {
2251 + copySetting.value = originalSetting.value;
2252 + jQuery( copySetting ).trigger( 'change' );
2253 + }
2254 + }
2255 +
2256 + function getKeyFromSettingInput( input ) {
2257 + let nameWithoutPrefix, nameSplit;
2258 + nameWithoutPrefix = input.name.substr( 14 );
2259 + nameSplit = nameWithoutPrefix.split( '_' );
2260 + nameSplit.pop();
2261 + return nameSplit.join( '_' );
2262 + }
2263 +
2264 + function closeOpenFieldDropdowns() {
2265 + const openSettings = document.querySelector( '.frm-field-settings-open' );
2266 + if ( null !== openSettings ) {
2267 + openSettings.classList.remove( 'frm-field-settings-open' );
2268 + jQuery( document ).off( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings );
2269 + jQuery( '.frm-field-action-icons .dropdown.open' ).removeClass( 'open' );
2270 + }
2271 + }
2272 +
2273 + function handleClickOutsideOfFieldSettings( event ) {
2274 + if ( ! jQuery( event.originalEvent.target ).closest( '.frm-field-action-icons' ).length ) {
2275 + closeOpenFieldDropdowns();
2276 + }
2277 + }
2278 +
2279 + function checkForMultiselectKeysOnMouseMove( event ) {
2280 + const keyIsDown = ! ! ( event.ctrlKey || event.metaKey || event.shiftKey );
2281 + jQuery( builderPage ).toggleClass( 'frm-multiselect-key-is-down', keyIsDown );
2282 + checkForActiveHoverTarget( event );
2283 + }
2284 +
2285 + function checkForActiveHoverTarget( event ) {
2286 + let container, elementFromPoint, list, previousHoverTarget;
2287 +
2288 + container = postBodyContent;
2289 + if ( container.classList.contains( 'frm-dragging-field' ) ) {
2290 + return;
2291 + }
2292 +
2293 + if ( null !== document.querySelector( '.frm-field-group-hover-target .frm-field-settings-open' ) ) {
2294 + // do not set a hover target if a dropdown is open for the current hover target.
2295 + return;
2296 + }
2297 +
2298 + elementFromPoint = document.elementFromPoint( event.clientX, event.clientY );
2299 + if ( null !== elementFromPoint && ! elementFromPoint.classList.contains( 'edit_field_type_divider' ) ) {
2300 +
2301 + list = elementFromPoint.closest( 'ul.frm_sorting' );
2302 +
2303 + if ( null !== list && ! list.classList.contains( 'start_divider' ) && 'frm-show-fields' !== list.id ) {
2304 + previousHoverTarget = maybeRemoveGroupHoverTarget();
2305 + if ( false !== previousHoverTarget && ! jQuery( previousHoverTarget ).is( list ) ) {
2306 + destroyFieldGroupPopup();
2307 + }
2308 + updateFieldGroupControls( jQuery( list ), getFieldsInRow( jQuery( list ) ).length );
2309 + list.classList.add( 'frm-field-group-hover-target' );
2310 + jQuery( '#wpbody-content' ).on( 'mousemove', maybeRemoveHoverTargetOnMouseMove );
2311 + }
2312 + }
2313 + }
2314 +
2315 + function maybeRemoveGroupHoverTarget() {
2316 + let controls, previousHoverTarget;
2317 +
2318 + controls = document.getElementById( 'frm_field_group_controls' );
2319 + if ( null !== controls ) {
2320 + controls.style.display = 'none';
2321 + }
2322 +
2323 + previousHoverTarget = document.querySelector( '.frm-field-group-hover-target' );
2324 + if ( null === previousHoverTarget ) {
2325 + return false;
2326 + }
2327 +
2328 + jQuery( '#wpbody-content' ).off( 'mousemove', maybeRemoveHoverTargetOnMouseMove );
2329 + previousHoverTarget.classList.remove( 'frm-field-group-hover-target' );
2330 + return previousHoverTarget;
2331 + }
2332 +
2333 + function maybeRemoveHoverTargetOnMouseMove( event ) {
2334 + const elementFromPoint = document.elementFromPoint( event.clientX, event.clientY );
2335 + if ( null !== elementFromPoint && null !== elementFromPoint.closest( '#frm-show-fields' ) ) {
2336 + return;
2337 + }
2338 + maybeRemoveGroupHoverTarget();
2339 + }
2340 +
2341 + function onFieldActionDropdownShow( isFieldGroup ) {
2342 + unselectFieldGroups();
2343 + // maybe offset the dropdown if it goes off of the right of the screen.
2344 + setTimeout(
2345 + function() {
2346 + let ul, $ul;
2347 + ul = document.querySelector( '.dropdown.show .frm-dropdown-menu' );
2348 + if ( null === ul ) {
2349 + return;
2350 + }
2351 + if ( null === ul.getAttribute( 'aria-label' ) ) {
2352 + ul.setAttribute( 'aria-label', __( 'More Options', 'formidable' ) );
2353 + }
2354 + if ( 0 === ul.children.length ) {
2355 + fillFieldActionDropdown( ul, true === isFieldGroup );
2356 + }
2357 + $ul = jQuery( ul );
2358 + if ( $ul.offset().left > jQuery( window ).width() - $ul.outerWidth() ) {
2359 + ul.style.left = ( -$ul.outerWidth() ) + 'px';
2360 + }
2361 + const firstAnchor = ul.firstElementChild.querySelector( 'a' );
2362 + if ( firstAnchor ) {
2363 + firstAnchor.focus();
2364 + }
2365 + },
2366 + 0
2367 + );
2368 + }
2369 +
2370 + function onFieldGroupActionDropdownShow() {
2371 + onFieldActionDropdownShow( true );
2372 + }
2373 +
2374 + function changeSectionStyle( e ) {
2375 + const collapsedSection = e.target.closest( '.frm-section-collapsed' );
2376 + if ( ! collapsedSection ) {
2377 + return;
2378 + }
2379 +
2380 + if ( e.type === 'show' ) {
2381 + collapsedSection.style.zIndex = 3;
2382 + } else {
2383 + collapsedSection.style.zIndex = 1;
2384 + }
2385 + }
2386 +
2387 + function fillFieldActionDropdown( ul, isFieldGroup ) {
2388 + let classSuffix, options;
2389 + classSuffix = isFieldGroup ? '_field_group' : '_field';
2390 + options = [ getDeleteActionOption( isFieldGroup ), getDuplicateActionOption( isFieldGroup ) ];
2391 + if ( ! isFieldGroup ) {
2392 + options.push(
2393 + { class: 'frm_select', icon: 'frm_settings_icon', label: __( 'Field Settings', 'formidable' ) }
2394 + );
2395 + }
2396 + options.forEach(
2397 + function( option ) {
2398 + let li, anchor, span;
2399 + li = document.createElement( 'div' );
2400 + li.classList.add( 'frm_more_options_li', 'dropdown-item' );
2401 +
2402 + anchor = document.createElement( 'a' );
2403 + anchor.classList.add( option.class + classSuffix );
2404 + anchor.setAttribute( 'href', '#' );
2405 + makeTabbable( anchor );
2406 +
2407 + span = document.createElement( 'span' );
2408 + span.textContent = option.label;
2409 + anchor.innerHTML = '<svg class="frmsvg"><use xlink:href="#' + option.icon + '"></use></svg>';
2410 + anchor.appendChild( document.createTextNode( ' ' ) );
2411 + anchor.appendChild( span );
2412 +
2413 + li.appendChild( anchor );
2414 + ul.appendChild( li );
2415 + }
2416 + );
2417 + }
2418 +
2419 + function getDeleteActionOption( isFieldGroup ) {
2420 + const option = { class: 'frm_delete', icon: 'frm_delete_icon' };
2421 + option.label = isFieldGroup ? __( 'Delete Group', 'formidable' ) : __( 'Delete', 'formidable' );
2422 + return option;
2423 + }
2424 +
2425 + function getDuplicateActionOption( isFieldGroup ) {
2426 + const option = { class: 'frm_clone', icon: 'frm_clone_icon' };
2427 + option.label = isFieldGroup ? __( 'Duplicate Group', 'formidable' ) : __( 'Duplicate', 'formidable' );
2428 + return option;
2429 + }
2430 +
2431 + function wrapFieldLi( field ) {
2432 + const wrapper = div();
2433 +
2434 + if ( 'string' === typeof field ) {
2435 + wrapper.innerHTML = field;
2436 + } else {
2437 + wrapper.appendChild( field );
2438 + }
2439 +
2440 + let result = jQuery();
2441 + Array.from( wrapper.children ).forEach(
2442 + li => {
2443 + result = result.add(
2444 + jQuery( '<li>' )
2445 + .addClass( 'frm_field_box' )
2446 + .html(
2447 + jQuery( '<ul>' ).addClass( 'frm_grid_container frm_sorting' ).append( li )
2448 + )
2449 + );
2450 + }
2451 + );
2452 +
2453 + return result;
2454 + }
2455 +
2456 + function wrapFieldLiInPlace( li ) {
2457 + const ul = tag(
2458 + 'ul',
2459 + {
2460 + className: 'frm_grid_container frm_sorting'
2461 + }
2462 + );
2463 + const wrapper = tag(
2464 + 'li',
2465 + {
2466 + className: 'frm_field_box',
2467 + child: ul
2468 + }
2469 + );
2470 +
2471 + li.replaceWith( wrapper );
2472 + ul.appendChild( li );
2473 +
2474 + makeDroppable( ul );
2475 + makeDraggable( wrapper, '.frm-move' );
2476 + }
2477 +
2478 + function afterAddField( msg, addFocus ) {
2479 + const regex = /id="(\S+)"/;
2480 + const match = regex.exec( msg );
2481 + const field = document.getElementById( match[1]);
2482 + const section = '#' + match[1] + '.edit_field_type_divider ul.frm_sorting.start_divider';
2483 + const $thisSection = jQuery( section );
2484 + const type = field.getAttribute( 'data-type' );
2485 +
2486 + checkHtmlForNewFields( msg );
2487 +
2488 + let toggled = false;
2489 +
2490 + fieldUpdated();
2491 + setupSortable( section );
2492 +
2493 + if ( 'quantity' === type ) {
2494 + // try to automatically attach a product field
2495 + maybeSetProductField( field );
2496 + }
2497 +
2498 + if ( 'product' === type || 'quantity' === type ) {
2499 + // quantity too needs to be a part of the if stmt especially cos of the very
2500 + // 1st quantity field (or even if it's just one quantity field in the form).
2501 + maybeHideQuantityProductFieldOption();
2502 + }
2503 +
2504 + if ( $thisSection.length ) {
2505 + $thisSection.parent( '.frm_field_box' ).children( '.frm_no_section_fields' ).addClass( 'frm_block' );
2506 + } else {
2507 + const $parentSection = jQuery( field ).closest( 'ul.frm_sorting.start_divider' );
2508 + if ( $parentSection.length ) {
2509 + toggleOneSectionHolder( $parentSection );
2510 + toggled = true;
2511 + }
2512 + }
2513 +
2514 + if ( msg.indexOf( 'frm-collapse-page' ) !== -1 ) {
2515 + renumberPageBreaks();
2516 + }
2517 +
2518 + addClass( field, 'frm-newly-added' );
2519 + setTimeout( function() {
2520 + field.classList.remove( 'frm-newly-added' );
2521 + }, 1000 );
2522 +
2523 + if ( addFocus ) {
2524 + const bounding = field.getBoundingClientRect(),
2525 + container = document.getElementById( 'post-body-content' ),
2526 + inView = ( bounding.top >= 0 &&
2527 + bounding.left >= 0 &&
2528 + bounding.right <= ( window.innerWidth || document.documentElement.clientWidth ) &&
2529 + bounding.bottom <= ( window.innerHeight || document.documentElement.clientHeight )
2530 + );
2531 +
2532 + if ( ! inView ) {
2533 + container.scroll({
2534 + top: container.scrollHeight,
2535 + left: 0,
2536 + behavior: 'smooth'
2537 + });
2538 + }
2539 +
2540 + if ( toggled === false ) {
2541 + toggleOneSectionHolder( $thisSection );
2542 + }
2543 + }
2544 +
2545 + deselectFields();
2546 + initiateMultiselect();
2547 +
2548 + const addedEvent = new Event( 'frm_added_field', { bubbles: false });
2549 + addedEvent.frmField = field;
2550 + addedEvent.frmSection = section;
2551 + addedEvent.frmType = type;
2552 + addedEvent.frmToggles = toggled;
2553 + document.dispatchEvent( addedEvent );
2554 + }
2555 +
2556 + /**
2557 + * Since multiple new fields may get added when a new field is inserted, check the HTML.
2558 + *
2559 + * @param {string} html
2560 + * @returns {void}
2561 + */
2562 + function checkHtmlForNewFields( html ) {
2563 + const element = div();
2564 + element.innerHTML = html;
2565 + element.querySelectorAll( '.form-field' ).forEach( addFieldIdToDraftFieldsInput );
2566 + }
2567 +
2568 + /**
2569 + * @param {HTMLElement} field
2570 + * @returns {void}
2571 + */
2572 + function addFieldIdToDraftFieldsInput( field ) {
2573 + if ( ! field.dataset.fid ) {
2574 + return;
2575 + }
2576 +
2577 + const draftInput = document.getElementById( 'draft_fields' );
2578 + if ( ! draftInput ) {
2579 + return;
2580 + }
2581 +
2582 + if ( '' === draftInput.value ) {
2583 + draftInput.value = field.dataset.fid;
2584 + } else {
2585 + const split = draftInput.value.split( ',' );
2586 + if ( ! split.includes( field.dataset.fid ) ) {
2587 + draftInput.value += ',' + field.dataset.fid;
2588 + }
2589 + }
2590 + }
2591 +
2592 + function clearSettingsBox( preventFieldGroups ) {
2593 + jQuery( '#new_fields .frm-single-settings' ).addClass( 'frm_hidden' );
2594 + jQuery( '#frm-options-panel > .frm-single-settings' ).removeClass( 'frm_hidden' );
2595 + deselectFields( preventFieldGroups );
2596 + }
2597 +
2598 + function deselectFields( preventFieldGroups ) {
2599 + jQuery( 'li.ui-state-default.selected' ).removeClass( 'selected' );
2600 + jQuery( '.frm-show-field-settings.selected' ).removeClass( 'selected' );
2601 + if ( ! preventFieldGroups ) {
2602 + unselectFieldGroups();
2603 + }
2604 + }
2605 +
2606 + function scrollToField( field ) {
2607 + const newPos = field.getBoundingClientRect().top,
2608 + container = document.getElementById( 'post-body-content' );
2609 +
2610 + if ( typeof animate === 'undefined' ) {
2611 + jQuery( container ).scrollTop( newPos );
2612 + } else {
2613 + // TODO: smooth scroll
2614 + jQuery( container ).animate({ scrollTop: newPos }, 500 );
2615 + }
2616 + }
2617 +
2618 + function checkCalculationCreatedByUser() {
2619 + const calculation = this.value;
2620 + let warningMessage = checkMatchingParens( calculation );
2621 + warningMessage += checkShortcodes( calculation, this );
2622 +
2623 + if ( warningMessage !== '' ) {
2624 + infoModal( calculation + '\n\n' + warningMessage );
2625 + }
2626 + }
2627 +
2628 + /**
2629 + * Checks the Detail Page slug to see if it's a reserved word and displays a message if it is.
2630 + */
2631 + function checkDetailPageSlug() {
2632 + let slug = jQuery( '#param' ).val(),
2633 + msg;
2634 + slug = slug.trim().toLowerCase();
2635 + if ( Array.isArray( frmAdminJs.unsafe_params ) && frmAdminJs.unsafe_params.includes( slug ) ) {
2636 + msg = frmAdminJs.slug_is_reserved;
2637 + msg = msg.replace( '****', addHtmlTags( slug, 'strong' ) );
2638 + msg += '<br /><br />';
2639 + msg += addHtmlTags( '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frmAdminJs.reserved_words + '</a>', 'div' );
2640 + infoModal( msg );
2641 + }
2642 + }
2643 +
2644 + /**
2645 + * Checks View filter value for params named with reserved words and displays a message if any are found.
2646 + */
2647 + function checkFilterParamNames() {
2648 + let regEx = /\[\s*get\s*param\s*=\s*['"]?([a-zA-Z-_]+)['"]?/ig,
2649 + filterValue = jQuery( this ).val(),
2650 + match = regEx.exec( filterValue ),
2651 + unsafeParams = '';
2652 +
2653 + while ( match !== null ) {
2654 + if ( Array.isArray( frmAdminJs.unsafe_params ) && frmAdminJs.unsafe_params.includes( match[1]) ) {
2655 + if ( unsafeParams !== '' ) {
2656 + unsafeParams += '", "' + match[ 1 ];
2657 + } else {
2658 + unsafeParams = match[ 1 ];
2659 + }
2660 + }
2661 + match = regEx.exec( filterValue );
2662 + }
2663 +
2664 + if ( unsafeParams !== '' ) {
2665 + let msg = frmAdminJs.param_is_reserved;
2666 + msg = msg.replace( '****', addHtmlTags( unsafeParams, 'strong' ) );
2667 + msg += '<br /><br />';
2668 + msg += ' <a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frmAdminJs.reserved_words + '</a>';
2669 +
2670 + infoModal( msg );
2671 + }
2672 + }
2673 +
2674 + function addHtmlTags( text, tag ) {
2675 + tag = tag ? tag : 'p';
2676 + return '<' + tag + '>' + text + '</' + tag + '>';
2677 + }
2678 +
2679 + /**
2680 + * Checks a string for parens, brackets, and curly braces and returns a message if any unmatched are found.
2681 + * @param formula
2682 + * @returns {string}
2683 + */
2684 + function checkMatchingParens( formula ) {
2685 +
2686 + let stack = [],
2687 + formulaArray = formula.split( '' ),
2688 + length = formulaArray.length,
2689 + opening = [ '{', '[', '(' ],
2690 + closing = {
2691 + '}': '{',
2692 + ')': '(',
2693 + ']': '['
2694 + },
2695 + unmatchedClosing = [],
2696 + msg = '',
2697 + i, top;
2698 +
2699 + for ( i = 0; i < length; i++ ) {
2700 + if ( opening.includes( formulaArray[i]) ) {
2701 + stack.push( formulaArray[i]);
2702 + continue;
2703 + }
2704 + if ( closing.hasOwnProperty( formulaArray[i]) ) {
2705 + top = stack.pop();
2706 + if ( top !== closing[formulaArray[i]]) {
2707 + unmatchedClosing.push( formulaArray[i]);
2708 + }
2709 + }
2710 + }
2711 +
2712 + if ( stack.length > 0 || unmatchedClosing.length > 0 ) {
2713 + msg = frmAdminJs.unmatched_parens + '\n\n';
2714 + return msg;
2715 + }
2716 +
2717 + return '';
2718 + }
2719 +
2720 + /**
2721 + * Checks a calculation for shortcodes that shouldn't be in it and returns a message if found.
2722 + * @param calculation
2723 + * @param inputElement
2724 + * @returns {string}
2725 + */
2726 + function checkShortcodes( calculation, inputElement ) {
2727 + let msg = checkNonNumericShortcodes( calculation, inputElement );
2728 + msg += checkNonFormShortcodes( calculation );
2729 +
2730 + return msg;
2731 + }
2732 +
2733 + /**
2734 + * Checks if a numeric calculation has shortcodes that output non-numeric strings and returns a message if found.
2735 + * @param calculation
2736 + *
2737 + * @param inputElement
2738 + * @returns {string}
2739 + */
2740 + function checkNonNumericShortcodes( calculation, inputElement ) {
2741 +
2742 + let msg = '';
2743 +
2744 + if ( isTextCalculation( inputElement ) ) {
2745 + return msg;
2746 + }
2747 +
2748 + const nonNumericShortcodes = getNonNumericShortcodes();
2749 +
2750 + if ( nonNumericShortcodes.test( calculation ) ) {
2751 + msg = frmAdminJs.text_shortcodes + '\n\n';
2752 + }
2753 +
2754 + return msg;
2755 + }
2756 +
2757 + /**
2758 + * Determines if the calculation input is from a text calculation.
2759 + *
2760 + * @param inputElement
2761 + */
2762 + function isTextCalculation( inputElement ) {
2763 + return jQuery( inputElement ).siblings( 'label[for^="calc_type"]' ).children( 'input' ).prop( 'checked' );
2764 + }
2765 +
2766 + /**
2767 + * Returns a regular expression of shortcodes that can't be used in numeric calculations.
2768 + * @returns {RegExp}
2769 + */
2770 + function getNonNumericShortcodes() {
2771 + return /\[(date|time|email|ip)\]/;
2772 + }
2773 +
2774 + /**
2775 + * Checks if a string has any shortcodes that do not belong in forms and returns a message if any are found.
2776 + * @param formula
2777 + * @returns {string}
2778 + */
2779 + function checkNonFormShortcodes( formula ) {
2780 + let nonFormShortcodes = getNonFormShortcodes(),
2781 + msg = '';
2782 +
2783 + if ( nonFormShortcodes.test( formula ) ) {
2784 + msg += frmAdminJs.view_shortcodes + '\n\n';
2785 + }
2786 +
2787 + return msg;
2788 + }
2789 +
2790 + /**
2791 + * Returns a regular expression of shortcodes that can't be used in forms but can be used in Views, Email
2792 + * Notifications, and other Formidable areas.
2793 + *
2794 + * @returns {RegExp}
2795 + */
2796 + function getNonFormShortcodes() {
2797 + return /\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g;
2798 + }
2799 +
2800 + function isCalcBoxType( box, listClass ) {
2801 + const list = jQuery( box ).find( '.frm_code_list' );
2802 + return 1 === list.length && list.hasClass( listClass );
2803 + }
2804 +
2805 + function extractExcludedOptions( exclude ) {
2806 + const opts = [];
2807 + if ( ! Array.isArray( exclude ) ) {
2808 + return opts;
2809 + }
2810 +
2811 + for ( let i = 0; i < exclude.length; i++ ) {
2812 + if ( exclude[ i ].startsWith( '[' ) ) {
2813 + opts.push( exclude[ i ]);
2814 + // remove it
2815 + exclude.splice( i, 1 );
2816 + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value
2817 + i--;
2818 + }
2819 + }
2820 +
2821 + return opts;
2822 + }
2823 +
2824 + function hasExcludedOption( field, excludedOpts ) {
2825 + let hasOption = false;
2826 + for ( let i = 0; i < excludedOpts.length; i++ ) {
2827 + const inputs = document.getElementsByName( getFieldOptionInputName( excludedOpts[ i ], field.fieldId ) );
2828 + // 2nd condition checks that there's at least one non-empty value
2829 + if ( inputs.length && jQuery( inputs[0]).val() ) {
2830 + hasOption = true;
2831 + break;
2832 + }
2833 + }
2834 + return hasOption;
2835 + }
2836 +
2837 + function getFieldOptionInputName( opt, fieldId ) {
2838 + const at = opt.indexOf( ']' );
2839 + return 'field_options' + opt.substring( 0, at ) + '_' + fieldId + opt.substring( at );
2840 + }
2841 +
2842 + function popCalcFields( v, force ) {
2843 + let box, exclude, fields, i, list,
2844 + p = jQuery( v ).closest( '.frm-single-settings' ),
2845 + calc = p.find( '.frm-calc-field' );
2846 +
2847 + if ( ! force && ( ! calc.length || calc.val() === '' || calc.is( ':hidden' ) ) ) {
2848 + return;
2849 + }
2850 +
2851 + const isSummary = isCalcBoxType( v, 'frm_js_summary_list' );
2852 +
2853 + const fieldId = p.find( 'input[name="frm_fields_submitted[]"]' ).val();
2854 +
2855 + if ( force ) {
2856 + box = v;
2857 + } else {
2858 + box = document.getElementById( 'frm-calc-box-' + fieldId );
2859 + }
2860 +
2861 + exclude = getExcludeArray( box, isSummary );
2862 + const excludedOpts = extractExcludedOptions( exclude );
2863 +
2864 + fields = getFieldList();
2865 + list = document.getElementById( 'frm-calc-list-' + fieldId );
2866 + list.innerHTML = '';
2867 +
2868 + for ( i = 0; i < fields.length; i++ ) {
2869 + if ( ( exclude && exclude.includes( fields[ i ].fieldType ) ) ||
2870 + ( excludedOpts.length && hasExcludedOption( fields[ i ], excludedOpts ) ) ) {
2871 + continue;
2872 + }
2873 +
2874 + const span = document.createElement( 'span' );
2875 + span.appendChild( document.createTextNode( '[' + fields[i].fieldId + ']' ) );
2876 +
2877 + const a = document.createElement( 'a' );
2878 + a.setAttribute( 'href', '#' );
2879 + a.setAttribute( 'data-code', fields[i].fieldId );
2880 + a.classList.add( 'frm_insert_code' );
2881 + a.appendChild( span );
2882 + a.appendChild( document.createTextNode( fields[i].fieldName ) );
2883 +
2884 + const li = document.createElement( 'li' );
2885 + li.classList.add( 'frm-field-list-' + fieldId );
2886 + li.classList.add( 'frm-field-list-' + fields[i].fieldType );
2887 + li.appendChild( a );
2888 + list.appendChild( li );
2889 + }
2890 + }
2891 +
2892 + function getExcludeArray( calcBox, isSummary ) {
2893 + const exclude = JSON.parse( calcBox.getElementsByClassName( 'frm_code_list' )[0].getAttribute( 'data-exclude' ) );
2894 +
2895 + if ( isSummary ) {
2896 + // includedExtras are those that are normally excluded from the summary but the form owner can choose to include,
2897 + // when they have been chosen to be included, then they can now be manually excluded in the calc box.
2898 + const includedExtras = getIncludedExtras();
2899 + if ( includedExtras.length ) {
2900 + for ( let i = 0; i < exclude.length; i++ ) {
2901 + if ( includedExtras.includes( exclude[ i ]) ) {
2902 + // remove it
2903 + exclude.splice( i, 1 );
2904 + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value
2905 + i--;
2906 + }
2907 + }
2908 + }
2909 + }
2910 +
2911 + return exclude;
2912 + }
2913 +
2914 + function getIncludedExtras() {
2915 + const checked = [];
2916 + const checkboxes = document.getElementsByClassName( 'frm_include_extras_field' );
2917 +
2918 + for ( let i = 0; i < checkboxes.length; i++ ) {
2919 + if ( checkboxes[i].checked ) {
2920 + checked.push( checkboxes[i].value );
2921 + }
2922 + }
2923 +
2924 + return checked;
2925 + }
2926 +
2927 + function rePopCalcFieldsForSummary() {
2928 + popCalcFields( jQuery( '.frm-inline-modal.postbox:has(.frm_js_summary_list)' )[0], true );
2929 + }
2930 +
2931 + function getFieldList( fieldType ) {
2932 + let i,
2933 + fields = [],
2934 + allFields = document.querySelectorAll( 'li.frm_field_box' ),
2935 + checkType = 'undefined' !== typeof fieldType;
2936 +
2937 + for ( i = 0; i < allFields.length; i++ ) {
2938 + // data-ftype is better (than data-type) cos of fields loaded by AJAX - which might not be ready yet
2939 + if ( checkType && allFields[ i ].getAttribute( 'data-ftype' ) !== fieldType ) {
2940 + continue;
2941 + }
2942 +
2943 + const fieldId = allFields[ i ].getAttribute( 'data-fid' );
2944 + if ( typeof fieldId !== 'undefined' && fieldId ) {
2945 + fields.push({
2946 + 'fieldId': fieldId,
2947 + 'fieldName': getPossibleValue( 'frm_name_' + fieldId ),
2948 + 'fieldType': getPossibleValue( 'field_options_type_' + fieldId ),
2949 + 'fieldKey': getPossibleValue( 'field_options_field_key_' + fieldId )
2950 + });
2951 + }
2952 + }
2953 +
2954 + return wp.hooks.applyFilters( 'frm_admin_get_field_list', fields, fieldType, allFields );
2955 + }
2956 +
2957 + function popProductFields( field ) {
2958 + let i, checked, id,
2959 + options = [],
2960 + current = getCurrentProductFields( field ),
2961 + fName = field.getAttribute( 'data-frmfname' ),
2962 + products = getFieldList( 'product' ),
2963 + quantities = getFieldList( 'quantity' ),
2964 + isSelect = field.tagName === 'SELECT', // for reverse compatibility.
2965 + // whether we have just 1 product and 1 quantity field & should therefore attach the latter to the former
2966 + auto = 1 === quantities.length && 1 === products.length;
2967 +
2968 + if ( isSelect ) {
2969 + // This fallback can be removed after 4.05.
2970 + current = field.getAttribute( 'data-frmcurrent' );
2971 + }
2972 +
2973 + for ( i = 0 ; i < products.length ; i++ ) {
2974 + // let's be double sure it's string, else indexOf will fail
2975 + id = products[ i ].fieldId.toString();
2976 + checked = auto || -1 !== current.indexOf( id );
2977 + if ( isSelect ) {
2978 + // This fallback can be removed after 4.05.
2979 + checked = checked ? ' selected' : '';
2980 + options.push( '<option value="' + id + '"' + checked + '>' + products[ i ].fieldName + '</option>' );
2981 + } else {
2982 + checked = checked ? ' checked' : '';
2983 + options.push( '<label class="frm6">' );
2984 + options.push( '<input type="checkbox" name="' + fName + '" value="' + id + '"' + checked + '> ' + products[ i ].fieldName );
2985 + options.push( '</label>' );
2986 + }
2987 + }
2988 +
2989 + field.innerHTML = options.join( '' );
2990 + }
2991 +
2992 + function getCurrentProductFields( prodFieldOpt ) {
2993 + const products = prodFieldOpt.querySelectorAll( '[type="checkbox"]:checked' ),
2994 + idsArray = [];
2995 +
2996 + for ( let i = 0; i < products.length; i++ ) {
2997 + idsArray.push( products[ i ].value );
2998 + }
2999 +
3000 + return idsArray;
3001 + }
3002 +
3003 + function popAllProductFields() {
3004 + const opts = document.querySelectorAll( '.frmjs_prod_field_opt' );
3005 + for ( let i = 0; i < opts.length; i++ ) {
3006 + popProductFields( opts[ i ]);
3007 + }
3008 + }
3009 +
3010 + function maybeSetProductField( field ) {
3011 + const fieldId = field.getAttribute( 'data-fid' ),
3012 + productFieldOpt = document.getElementById( 'field_options[product_field_' + fieldId + ']' );
3013 +
3014 + if ( null === productFieldOpt ) {
3015 + return;
3016 + }
3017 +
3018 + popProductFields( productFieldOpt );
3019 + // in order to move its settings to that LHS panel where
3020 + // the update form resides, else it'll lose this setting
3021 + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) );
3022 + }
3023 +
3024 + /**
3025 + * If the element doesn't exist, use a blank value.
3026 + */
3027 + function getPossibleValue( id ) {
3028 + const field = document.getElementById( id );
3029 + if ( field !== null ) {
3030 + return field.value;
3031 + }
3032 + return '';
3033 + }
3034 +
3035 + function liveChanges() {
3036 + /*jshint validthis:true */
3037 + let option,
3038 + newValue = this.value,
3039 + changes = document.getElementById( this.getAttribute( 'data-changeme' ) ),
3040 + att = this.getAttribute( 'data-changeatt' );
3041 +
3042 + if ( changes === null ) {
3043 + return;
3044 + }
3045 +
3046 + if ( att !== null ) {
3047 + if ( changes.tagName === 'SELECT' && att === 'placeholder' ) {
3048 + option = changes.options[0];
3049 + if ( option.value === '' ) {
3050 + option.innerHTML = newValue;
3051 + } else {
3052 + // Create a placeholder option if there are no blank values.
3053 + addBlankSelectOption( changes, newValue );
3054 + }
3055 + } else if ( att === 'class' ) {
3056 + changeFieldClass( changes, this );
3057 + } else if ( isSliderField( changes ) ) {
3058 + updateSliderFieldPreview( changes, att, newValue );
3059 + } else {
3060 + changes.setAttribute( att, newValue );
3061 + }
3062 + } else if ( changes.id.indexOf( 'setup-message' ) === 0 ) {
3063 + if ( newValue !== '' ) {
3064 + changes.innerHTML = '<input type="text" value="" disabled />';
3065 + }
3066 + } else {
3067 + changes.innerHTML = purifyHtml( newValue );
3068 + if ( 'TEXTAREA' === changes.nodeName && changes.classList.contains( 'wp-editor-area' ) ) {
3069 + // Trigger change events on wysiwyg textareas so we can also sync default values in the visual tab.
3070 + jQuery( changes ).trigger( 'change' );
3071 + }
3072 +
3073 + if ( changes.classList.contains( 'frm_primary_label' ) && 'break' === changes.nextElementSibling.getAttribute( 'data-ftype' ) ) {
3074 + changes.nextElementSibling.querySelector( '.frm_button_submit' ).textContent = newValue;
3075 + }
3076 + }
3077 + }
3078 +
3079 + function updateSliderFieldPreview( field, att, newValue ) {
3080 + if ( frmGlobal.proIncludesSliderJs ) {
3081 + const hookName = 'frm_update_slider_field_preview';
3082 + const hookArgs = { field, att, newValue };
3083 + wp.hooks.doAction( hookName, hookArgs );
3084 + return;
3085 + }
3086 +
3087 + // This functionality has been moved to pro since v5.4.3. This code should be removed eventually.
3088 + if ( 'value' === att ) {
3089 + if ( '' === newValue ) {
3090 + newValue = getSliderMidpoint( field );
3091 + }
3092 + field.value = newValue;
3093 + } else {
3094 + field.setAttribute( att, newValue );
3095 + }
3096 +
3097 + if ( -1 === [ 'value', 'min', 'max' ].indexOf( att ) ) {
3098 + return;
3099 + }
3100 +
3101 + if ( ( 'max' === att || 'min' === att ) && '' === getSliderDefaultValueInput( field.id ) ) {
3102 + field.value = getSliderMidpoint( field );
3103 + }
3104 +
3105 + field.parentNode.querySelector( '.frm_range_value' ).textContent = field.value;
3106 + }
3107 +
3108 + function getSliderDefaultValueInput( previewInputId ) {
3109 + return document.querySelector( 'input[data-changeme="' + previewInputId + '"][data-changeatt="value"]' ).value;
3110 + }
3111 +
3112 + function getSliderMidpoint( sliderInput ) {
3113 + const max = parseFloat( sliderInput.getAttribute( 'max' ) );
3114 + const min = parseFloat( sliderInput.getAttribute( 'min' ) );
3115 + return ( max - min ) / 2 + min;
3116 + }
3117 +
3118 + function isSliderField( previewInput ) {
3119 + return 'range' === previewInput.type && previewInput.parentNode.classList.contains( 'frm_range_container' );
3120 + }
3121 +
3122 + function toggleInvalidMsg() {
3123 + /*jshint validthis:true */
3124 + let typeDropdown, fieldType,
3125 + fieldId = this.getAttribute( 'data-fid' ),
3126 + value = '';
3127 +
3128 + [ 'field_options_max_', 'frm_format_' ].forEach( function( id ) {
3129 + const input = document.getElementById( id + fieldId );
3130 + if ( ! input ) {
3131 + return;
3132 + }
3133 +
3134 + value += input.value;
3135 + });
3136 +
3137 + typeDropdown = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0];
3138 + fieldType = typeDropdown.options[typeDropdown.selectedIndex].value;
3139 +
3140 + if ( fieldType === 'text' ) {
3141 + toggleValidationBox( '' !== value, '.frm_invalid_msg' + fieldId );
3142 + }
3143 + }
3144 +
3145 + function markRequired() {
3146 + /*jshint validthis:true */
3147 + const thisid = this.id.replace( 'frm_', '' ),
3148 + fieldId = thisid.replace( 'req_field_', '' ),
3149 + checked = this.checked,
3150 + label = jQuery( '#field_label_' + fieldId + ' .frm_required' );
3151 +
3152 + toggleValidationBox( checked, '.frm_required_details' + fieldId );
3153 +
3154 + if ( checked ) {
3155 + const $reqBox = jQuery( 'input[name="field_options[required_indicator_' + fieldId + ']"]' );
3156 + if ( $reqBox.val() === '' ) {
3157 + $reqBox.val( '*' );
3158 + }
3159 + label.removeClass( 'frm_hidden' );
3160 + } else {
3161 + label.addClass( 'frm_hidden' );
3162 + }
3163 + }
3164 +
3165 + function toggleValidationBox( hasValue, messageClass ) {
3166 + $msg = jQuery( messageClass );
3167 + if ( hasValue ) {
3168 + $msg.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' );
3169 + } else {
3170 + //Fade out validation options
3171 + const v = $msg.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(' + messageClass + '):visible' ).length;
3172 + if ( v === 0 ) {
3173 + $msg.closest( '.frm_validation_msg' ).fadeOut( 'fast' );
3174 + }
3175 + }
3176 + }
3177 +
3178 + function markUnique() {
3179 + /*jshint validthis:true */
3180 + const fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3181 + const $thisField = jQuery( '.frm_unique_details' + fieldId );
3182 + if ( this.checked ) {
3183 + $thisField.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' );
3184 + $unqDetail = jQuery( '.frm_unique_details' + fieldId + ' input' );
3185 + if ( $unqDetail.val() === '' ) {
3186 + $unqDetail.val( frmAdminJs.default_unique );
3187 + }
3188 + } else {
3189 + const v = $thisField.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(.frm_unique_details' + fieldId + '):visible' ).length;
3190 + if ( v === 0 ) {
3191 + $thisField.closest( '.frm_validation_msg' ).fadeOut( 'fast' );
3192 + }
3193 + }
3194 + }
3195 +
3196 + //Fade confirmation field and validation option in or out
3197 + function addConf() {
3198 + /*jshint validthis:true */
3199 + const fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3200 + const val = jQuery( this ).val();
3201 + const $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) );
3202 +
3203 + toggleValidationBox( val !== '', '.frm_conf_details' + fieldId );
3204 +
3205 + if ( val !== '' ) {
3206 + //Add default validation message if empty
3207 + const valMsg = jQuery( '.frm_validation_box .frm_conf_details' + fieldId + ' input' );
3208 + if ( valMsg.val() === '' ) {
3209 + valMsg.val( frmAdminJs.default_conf );
3210 + }
3211 +
3212 + setConfirmationFieldDescriptions( fieldId );
3213 +
3214 + //Add or remove class for confirmation field styling
3215 + if ( val === 'inline' ) {
3216 + $thisField.removeClass( 'frm_conf_below' ).addClass( 'frm_conf_inline' );
3217 + } else if ( val === 'below' ) {
3218 + $thisField.removeClass( 'frm_conf_inline' ).addClass( 'frm_conf_below' );
3219 + }
3220 + jQuery( '.frm-conf-box-' + fieldId ).removeClass( 'frm_hidden' );
3221 + } else {
3222 + jQuery( '.frm-conf-box-' + fieldId ).addClass( 'frm_hidden' );
3223 + setTimeout( function() {
3224 + $thisField.removeClass( 'frm_conf_inline frm_conf_below' );
3225 + }, 200 );
3226 + }
3227 + }
3228 +
3229 + function setConfirmationFieldDescriptions( fieldId ) {
3230 + const fieldType = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0].value;
3231 +
3232 + const fieldDescription = document.getElementById( 'field_description_' + fieldId );
3233 + const hiddenDescName = 'field_options[description_' + fieldId + ']';
3234 + const newValue = frmAdminJs['enter_' + fieldType];
3235 + maybeSetNewDescription( fieldDescription, hiddenDescName, newValue );
3236 +
3237 + const confFieldDescription = document.getElementById( 'conf_field_description_' + fieldId );
3238 + const hiddenConfName = 'field_options[conf_desc_' + fieldId + ']';
3239 + const newConfValue = frmAdminJs['confirm_' + fieldType];
3240 + maybeSetNewDescription( confFieldDescription, hiddenConfName, newConfValue );
3241 + }
3242 +
3243 + function maybeSetNewDescription( descriptionDiv, hiddenName, newValue ) {
3244 + if ( descriptionDiv.innerHTML === frmAdminJs.desc ) {
3245 +
3246 + // Set the visible description value and the hidden description value
3247 + descriptionDiv.innerHTML = newValue;
3248 + document.getElementsByName( hiddenName )[0].value = newValue;
3249 + }
3250 + }
3251 +
3252 + function initBulkOptionsOverlay() {
3253 + /*jshint validthis:true */
3254 + const $info = initModal( '#frm-bulk-modal', '700px' );
3255 + if ( $info === false ) {
3256 + return;
3257 + }
3258 +
3259 + jQuery( '.frm-insert-preset' ).on( 'click', insertBulkPreset );
3260 +
3261 + jQuery( builderForm ).on( 'click', 'a.frm-bulk-edit-link', function( event ) {
3262 + event.preventDefault();
3263 + let i, key, label,
3264 + content = '',
3265 + optList,
3266 + opts,
3267 + fieldId = jQuery( this ).closest( '[data-fid]' ).data( 'fid' ),
3268 + separate = usingSeparateValues( fieldId ),
3269 + product = isProductField( fieldId );
3270 +
3271 + optList = document.getElementById( 'frm_field_' + fieldId + '_opts' );
3272 + if ( ! optList ) {
3273 + return;
3274 + }
3275 +
3276 + opts = optList.getElementsByTagName( 'li' );
3277 +
3278 + document.getElementById( 'bulk-field-id' ).value = fieldId;
3279 +
3280 + for ( i = 0; i < opts.length; i++ ) {
3281 + key = opts[i].getAttribute( 'data-optkey' );
3282 + if ( key !== '000' ) {
3283 + label = document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][label]' )[0];
3284 + if ( typeof label !== 'undefined' ) {
3285 + content += label.value;
3286 + if ( separate ) {
3287 + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][value]' )[0].value;
3288 + }
3289 + if ( product ) {
3290 + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][price]' )[0].value;
3291 + }
3292 + content += '\r\n';
3293 + }
3294 + }
3295 +
3296 + if ( i >= opts.length - 1 ) {
3297 + document.getElementById( 'frm_bulk_options' ).value = content;
3298 + }
3299 + }
3300 +
3301 + $info.dialog( 'open' );
3302 +
3303 + return false;
3304 + });
3305 +
3306 + jQuery( '#frm-update-bulk-opts' ).on( 'click', function() {
3307 + const fieldId = document.getElementById( 'bulk-field-id' ).value;
3308 + const optionType = document.getElementById( 'bulk-option-type' ).value;
3309 +
3310 + if ( optionType ) {
3311 + // Use custom handler for custom option type.
3312 + return;
3313 + }
3314 +
3315 + this.classList.add( 'frm_loading_button' );
3316 + frmAdminBuild.updateOpts( fieldId, document.getElementById( 'frm_bulk_options' ).value, $info );
3317 + fieldUpdated();
3318 + });
3319 + }
3320 +
3321 + function insertBulkPreset( event ) {
3322 + /*jshint validthis:true */
3323 + const opts = JSON.parse( this.getAttribute( 'data-opts' ) );
3324 + event.preventDefault();
3325 + document.getElementById( 'frm_bulk_options' ).value = opts.join( '\n' );
3326 + return false;
3327 + }
3328 +
3329 + //Add new option or "Other" option to radio/checkbox/dropdown
3330 + function addFieldOption() {
3331 + /*jshint validthis:true */
3332 + let fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
3333 + newOption = jQuery( '#frm_field_' + fieldId + '_opts .frm_option_template' ).prop( 'outerHTML' ),
3334 + optType = jQuery( this ).data( 'opttype' ),
3335 + optKey = 0,
3336 + oldKey = '000',
3337 + lastKey = getHighestOptKey( fieldId );
3338 +
3339 + if ( lastKey !== oldKey ) {
3340 + optKey = lastKey + 1;
3341 + }
3342 +
3343 + //Update hidden field
3344 + if ( optType === 'other' ) {
3345 + document.getElementById( 'other_input_' + fieldId ).value = 1;
3346 +
3347 + //Hide "Add Other" option now if this is radio field
3348 + const ftype = jQuery( this ).data( 'ftype' );
3349 + if ( ftype === 'radio' || ftype === 'select' ) {
3350 + jQuery( this ).fadeOut( 'slow' );
3351 + }
3352 +
3353 + const data = {
3354 + action: 'frm_add_field_option',
3355 + field_id: fieldId,
3356 + opt_key: optKey,
3357 + opt_type: optType,
3358 + nonce: frmGlobal.nonce
3359 + };
3360 + jQuery.post( ajaxurl, data, function( msg ) {
3361 + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( msg );
3362 + resetDisplayedOpts( fieldId );
3363 + });
3364 + } else {
3365 + newOption = newOption.replace( new RegExp( 'optkey="' + oldKey + '"', 'g' ), 'optkey="' + optKey + '"' );
3366 + newOption = newOption.replace( new RegExp( '-' + oldKey + '_', 'g' ), '-' + optKey + '_' );
3367 + newOption = newOption.replace( new RegExp( '-' + oldKey + '"', 'g' ), '-' + optKey + '"' );
3368 + newOption = newOption.replace( new RegExp( '\\[' + oldKey + '\\]', 'g' ), '[' + optKey + ']' );
3369 + newOption = newOption.replace( 'frm_hidden frm_option_template', '' );
3370 + newOption = { newOption };
3371 + addSaveAndDragIconsToOption( fieldId, newOption );
3372 + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( newOption.newOption );
3373 + resetDisplayedOpts( fieldId );
3374 + }
3375 + fieldUpdated();
3376 + }
3377 +
3378 + function getHighestOptKey( fieldId ) {
3379 + let i = 0,
3380 + optKey = 0,
3381 + opts = jQuery( '#frm_field_' + fieldId + '_opts li' ),
3382 + lastKey = 0;
3383 +
3384 + for ( i; i < opts.length; i++ ) {
3385 + optKey = opts[i].getAttribute( 'data-optkey' );
3386 + if ( opts.length === 1 ) {
3387 + return optKey;
3388 + }
3389 + if ( optKey !== '000' ) {
3390 + optKey = optKey.replace( 'other_', '' );
3391 + optKey = parseInt( optKey, 10 );
3392 + }
3393 +
3394 + if ( ! isNaN( lastKey ) && ( optKey > lastKey || lastKey === '000' ) ) {
3395 + lastKey = optKey;
3396 + }
3397 + }
3398 +
3399 + return lastKey;
3400 + }
3401 +
3402 + function toggleMultSel() {
3403 + /*jshint validthis:true */
3404 + const fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3405 + toggleMultiSelect( fieldId, this.value );
3406 + }
3407 +
3408 + function toggleMultiSelect( fieldId, value ) {
3409 + const setting = jQuery( '.frm_multiple_cont_' + fieldId );
3410 + if ( value === 'select' ) {
3411 + setting.fadeIn( 'fast' );
3412 + } else {
3413 + setting.fadeOut( 'fast' );
3414 + }
3415 + }
3416 +
3417 + function toggleSepValues() {
3418 + /*jshint validthis:true */
3419 + const fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3420 + toggle( jQuery( '.field_' + fieldId + '_option_key' ) );
3421 + jQuery( '.field_' + fieldId + '_option' ).toggleClass( 'frm_with_key' );
3422 + }
3423 +
3424 + function toggleImageOptions() {
3425 + /*jshint validthis:true */
3426 + let hasImageOptions, imageSize,
3427 + $field = jQuery( this ).closest( '.frm-single-settings' ),
3428 + fieldId = $field.data( 'fid' ),
3429 + displayField = document.getElementById( 'frm_field_id_' + fieldId );
3430 +
3431 + refreshOptionDisplayNow( jQuery( this ) );
3432 +
3433 + toggle( jQuery( '.field_' + fieldId + '_image_id' ) );
3434 + toggle( jQuery( '.frm_toggle_image_options_' + fieldId ) );
3435 + toggle( jQuery( '.frm_image_size_' + fieldId ) );
3436 + toggle( jQuery( '.frm_alignment_' + fieldId ) );
3437 + toggle( jQuery( '.frm-add-other#frm_add_field_' + fieldId ) );
3438 +
3439 + hasImageOptions = imagesAsOptions( fieldId );
3440 +
3441 + if ( hasImageOptions ) {
3442 + setAlignment( fieldId, 'inline' );
3443 + removeImageSizeClasses( displayField );
3444 + imageSize = getImageOptionSize( fieldId );
3445 + displayField.classList.add( 'frm_image_options' );
3446 + displayField.classList.add( 'frm_image_size_' + imageSize );
3447 + $field.find( '.frm-bulk-edit-link' ).hide();
3448 + } else {
3449 + displayField.classList.remove( 'frm_image_options' );
3450 + removeImageSizeClasses( displayField );
3451 + setAlignment( fieldId, 'block' );
3452 + $field.find( '.frm-bulk-edit-link' ).show();
3453 + }
3454 + }
3455 +
3456 + function removeImageSizeClasses( field ) {
3457 + field.classList.remove( 'frm_image_size_', 'frm_image_size_small', 'frm_image_size_medium', 'frm_image_size_large', 'frm_image_size_xlarge' );
3458 + }
3459 +
3460 + function setAlignment( fieldId, alignment ) {
3461 + jQuery( '#field_options_align_' + fieldId ).val( alignment ).trigger( 'change' );
3462 + }
3463 +
3464 + function setImageSize() {
3465 + const $field = jQuery( this ).closest( '.frm-single-settings' ),
3466 + fieldId = $field.data( 'fid' ),
3467 + displayField = document.getElementById( 'frm_field_id_' + fieldId );
3468 +
3469 + refreshOptionDisplay();
3470 +
3471 + if ( imagesAsOptions( fieldId ) ) {
3472 + removeImageSizeClasses( displayField );
3473 + displayField.classList.add( 'frm_image_options' );
3474 + displayField.classList.add( 'frm_image_size_' + getImageOptionSize( fieldId ) );
3475 + }
3476 + }
3477 +
3478 + function refreshOptionDisplayNow( object ) {
3479 + const $field = object.closest( '.frm-single-settings' ),
3480 + fieldID = $field.data( 'fid' );
3481 + jQuery( '.field_' + fieldID + '_option' ).trigger( 'change' );
3482 + }
3483 +
3484 + function refreshOptionDisplay() {
3485 + /*jshint validthis:true */
3486 + refreshOptionDisplayNow( jQuery( this ) );
3487 + }
3488 +
3489 + function addImageToOption( event ) {
3490 + const imagePreview = event.target.closest( '.frm_image_preview_wrapper' );
3491 +
3492 + event.preventDefault();
3493 +
3494 + wp.media.model.settings.post.id = 0;
3495 +
3496 + const fileFrame = wp.media.frames.file_frame = wp.media({
3497 + multiple: false,
3498 + library: {
3499 + type: [ 'image' ]
3500 + }
3501 + });
3502 +
3503 + fileFrame.on( 'select', function() {
3504 + const attachment = fileFrame.state().get( 'selection' ).first().toJSON();
3505 + const img = imagePreview.querySelector( 'img' );
3506 +
3507 + img.setAttribute( 'src', attachment.url );
3508 + img.classList.remove( 'frm_hidden' );
3509 + img.removeAttribute( 'srcset' ); // Prevent the old image from sticking around.
3510 +
3511 + imagePreview.querySelector( '.frm_image_preview_frame' ).style.display = 'block';
3512 + imagePreview.querySelector( '.frm_image_preview_title' ).textContent = attachment.filename;
3513 + imagePreview.querySelector( '.frm_choose_image_box' ).style.display = 'none';
3514 +
3515 + const $imagePreview = jQuery( imagePreview );
3516 + $imagePreview.siblings( 'input[name*="[label]"]' ).data( 'frmimgurl', attachment.url );
3517 + $imagePreview.find( 'input.frm_image_id' ).val( attachment.id ).trigger( 'change' );
3518 + wp.media.model.settings.post.id = 0;
3519 + });
3520 +
3521 + fileFrame.open();
3522 + }
3523 +
3524 + function removeImageFromOption( event ) {
3525 + const $this = jQuery( this ),
3526 + previewWrapper = $this.closest( '.frm_image_preview_wrapper' );
3527 +
3528 + event.preventDefault();
3529 + event.stopPropagation();
3530 +
3531 + previewWrapper.find( 'img' ).attr( 'src', '' );
3532 + previewWrapper.find( '.frm_image_preview_frame' ).hide();
3533 + previewWrapper.find( '.frm_choose_image_box' ).show();
3534 + previewWrapper.find( 'input.frm_image_id' ).val( 0 ).trigger( 'change' );
3535 + }
3536 +
3537 + function toggleMultiselect() {
3538 + /*jshint validthis:true */
3539 + const dropdown = jQuery( this ).closest( 'li' ).find( '.frm_form_fields select' );
3540 + if ( this.checked ) {
3541 + dropdown.attr( 'multiple', 'multiple' );
3542 + } else {
3543 + dropdown.removeAttr( 'multiple' );
3544 + }
3545 + }
3546 +
3547 + /**
3548 + * Allow typing on form switcher click without an extra click to search.
3549 + */
3550 + function focusSearchBox() {
3551 + const searchBox = document.getElementById( 'dropform-search-input' );
3552 + if ( searchBox !== null ) {
3553 + setTimeout( function() {
3554 + searchBox.focus();
3555 + }, 100 );
3556 + }
3557 + }
3558 +
3559 + /**
3560 + * Dismiss a warning message and send an AJAX request to update the dismissal state.
3561 + *
3562 + * @since 6.3
3563 + *
3564 + * @param {Event} event The event object associated with the click on the dismiss icon.
3565 + */
3566 + function dismissWarningMessage( event ) {
3567 + const target = event.target;
3568 +
3569 + const warningEl = target.closest( '.frm_warning_style' );
3570 + jQuery( warningEl ).fadeOut( 400, () => warningEl.remove() );
3571 +
3572 + const action = target.dataset.action;
3573 + const formData = new FormData();
3574 + doJsonPost( action, formData );
3575 + }
3576 +
3577 + /**
3578 + * If a field is clicked in the builder, prevent inputs from changing.
3579 + */
3580 + function stopFieldFocus( e ) {
3581 + e.preventDefault();
3582 + }
3583 +
3584 + function deleteFieldOption() {
3585 + /*jshint validthis:true */
3586 + let otherInput,
3587 + parentLi = this.parentNode,
3588 + parentUl = parentLi.parentNode,
3589 + fieldId = this.getAttribute( 'data-fid' );
3590 +
3591 + jQuery( parentLi ).fadeOut( 'slow', function() {
3592 + wp.hooks.doAction( 'frm_before_delete_field_option', this );
3593 + jQuery( parentLi ).remove();
3594 +
3595 + const hasOther = jQuery( parentUl ).find( '.frm_other_option' );
3596 + if ( hasOther.length < 1 ) {
3597 + otherInput = document.getElementById( 'other_input_' + fieldId );
3598 + if ( otherInput !== null ) {
3599 + otherInput.value = 0;
3600 + }
3601 + jQuery( '#other_button_' + fieldId ).fadeIn( 'slow' );
3602 + }
3603 + });
3604 + fieldUpdated();
3605 + }
3606 +
3607 + /**
3608 + * If a radio button is set as default, allow a click to
3609 + * deselect it.
3610 + */
3611 + function maybeUncheckRadio() {
3612 + let $self, uncheck, unbind, up;
3613 +
3614 + /*jshint validthis:true */
3615 + $self = jQuery( this );
3616 + if ( $self.is( ':checked' ) ) {
3617 + uncheck = function() {
3618 + setTimeout( function() {
3619 + $self.prop( 'checked', false );
3620 + }, 0 );
3621 + };
3622 + unbind = function() {
3623 + $self.off( 'mouseup', up );
3624 + };
3625 + up = function() {
3626 + uncheck();
3627 + unbind();
3628 + };
3629 + $self.on( 'mouseup', up );
3630 + $self.one( 'mouseout', unbind );
3631 + }
3632 + }
3633 +
3634 + /**
3635 + * If the field option has the default text, clear it out on click.
3636 + */
3637 + function maybeClearOptText() {
3638 + /*jshint validthis:true */
3639 + if ( this.value === frmAdminJs.new_option ) {
3640 + this.setAttribute( 'data-value-on-focus', this.value );
3641 + this.value = '';
3642 + }
3643 + }
3644 +
3645 + function confirmFieldsDeleteMessage( numberOfFields ) {
3646 + /* translators: %1$s: Number of fields that are selected to be deleted. */
3647 + return sprintf( __( 'Are you sure you want to delete these %1$s selected field(s)?', 'formidable' ), numberOfFields );
3648 + }
3649 +
3650 + function clickDeleteField() {
3651 + /*jshint validthis:true */
3652 + let confirmMsg = frmAdminJs.conf_delete,
3653 + maybeDivider = this.parentNode.parentNode.parentNode.parentNode.parentNode,
3654 + li = maybeDivider.parentNode,
3655 + field = jQuery( this ).closest( 'li.form-field' ),
3656 + fieldId = field.data( 'fid' );
3657 +
3658 + if ( field.data( 'ftype' ) === 'divider' ) {
3659 + const fieldBoxes = document.querySelectorAll( '.frm-field-group-hover-target .start_divider .frm_field_box' );
3660 + let fieldIdsToDelete = 0;
3661 + fieldBoxes.forEach( fieldBox => {
3662 + const fieldsInsideFieldBox = fieldBox.querySelectorAll( 'li.form-field' );
3663 + if ( fieldsInsideFieldBox ) {
3664 + fieldIdsToDelete += fieldsInsideFieldBox.length;
3665 + }
3666 + });
3667 + if ( fieldIdsToDelete ) {
3668 + confirmMsg = confirmFieldsDeleteMessage( ++fieldIdsToDelete );
3669 + }
3670 + }
3671 +
3672 + if ( li.classList.contains( 'frm-section-collapsed' ) || li.classList.contains( 'frm-page-collapsed' ) ) {
3673 + return false;
3674 + }
3675 +
3676 + // If deleting a section, use a special message.
3677 + if ( maybeDivider.className === 'divider_section_only' ) {
3678 + confirmMsg = frmAdminJs.conf_delete_sec;
3679 + }
3680 +
3681 + this.setAttribute( 'data-frmverify', confirmMsg );
3682 + this.setAttribute( 'data-frmverify-btn', 'frm-button-red' );
3683 + this.setAttribute( 'data-deletefield', fieldId );
3684 +
3685 + closeOpenFieldDropdowns();
3686 +
3687 + confirmLinkClick( this );
3688 + return false;
3689 + }
3690 +
3691 + function clickSelectField() {
3692 + this.closest( 'li.form-field' ).click();
3693 + }
3694 +
3695 + function clickDeleteFieldGroup() {
3696 + let hoverTarget, decoy;
3697 +
3698 + hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3699 + if ( null === hoverTarget ) {
3700 + return;
3701 + }
3702 +
3703 + hoverTarget.classList.add( 'frm-selected-field-group' );
3704 +
3705 + decoy = document.createElement( 'div' );
3706 + decoy.classList.add( 'frm-delete-field-groups', 'frm_hidden' );
3707 + document.body.appendChild( decoy );
3708 + decoy.click();
3709 + }
3710 +
3711 + function duplicateFieldGroup() {
3712 + const hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3713 + if ( null === hoverTarget ) {
3714 + return;
3715 + }
3716 +
3717 + const newRowId = 'frm_field_group_' + getAutoId();
3718 + const placeholderUlChild = document.createTextNode( '' );
3719 + wrapFieldLiInPlace( placeholderUlChild );
3720 +
3721 + const newRow = jQuery( placeholderUlChild ).closest( 'li' ).get( 0 );
3722 + newRow.classList.add( 'frm_hidden' );
3723 +
3724 + const newRowUl = newRow.querySelector( 'ul' );
3725 + newRowUl.id = newRowId;
3726 +
3727 + jQuery( hoverTarget.closest( 'li.frm_field_box' ) ).after( newRow );
3728 +
3729 + const $fields = getFieldsInRow( jQuery( hoverTarget ) );
3730 + const syncDetails = [];
3731 + const injectedCloneOptions = [];
3732 +
3733 + const expectedLength = $fields.length;
3734 + const originalFieldIdByDuplicatedFieldId = {};
3735 +
3736 + let duplicatedCount = 0;
3737 +
3738 + jQuery( newRow ).on(
3739 + 'frm_added_duplicated_field_to_row',
3740 + function( _, args ) {
3741 + originalFieldIdByDuplicatedFieldId[ jQuery( args.duplicatedFieldHtml ).attr( 'data-fid' ) ] = args.originalFieldId;
3742 +
3743 + if ( expectedLength > ++duplicatedCount ) {
3744 + return;
3745 + }
3746 +
3747 + const $newRowUl = jQuery( newRowUl );
3748 + const $duplicatedFields = getFieldsInRow( $newRowUl );
3749 +
3750 + injectedCloneOptions.forEach(
3751 + function( cloneOption ) {
3752 + cloneOption.remove();
3753 + }
3754 + );
3755 +
3756 + for ( let index = 0; index < expectedLength; ++index ) {
3757 + $newRowUl.append( $newRowUl.children( 'li.form-field[frm-field-order="' + index + '"]' ) );
3758 + }
3759 +
3760 + syncLayoutClasses( $duplicatedFields.first(), syncDetails );
3761 + newRow.classList.remove( 'frm_hidden' );
3762 + updateFieldOrder();
3763 +
3764 + getFieldsInRow( $newRowUl ).each(
3765 + function() {
3766 + maybeDuplicateUnsavedSettings( originalFieldIdByDuplicatedFieldId[ this.getAttribute( 'data-fid' ) ], jQuery( this ).prop( 'outerHTML' ) );
3767 + }
3768 + );
3769 + }
3770 + );
3771 +
3772 + $fields.each(
3773 + function( index ) {
3774 + let cloneOption;
3775 + cloneOption = document.createElement( 'li' );
3776 + cloneOption.classList.add( 'frm_clone_field' );
3777 + cloneOption.setAttribute( 'frm-target-row-id', newRowId );
3778 + cloneOption.setAttribute( 'frm-field-order', index );
3779 + this.appendChild( cloneOption );
3780 + cloneOption.click();
3781 + injectedCloneOptions.push( cloneOption );
3782 + syncDetails.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) );
3783 + }
3784 + );
3785 + }
3786 +
3787 + function clickFieldGroupLayout() {
3788 + let hoverTarget, sizeOfFieldGroup, popupWrapper;
3789 +
3790 + hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3791 +
3792 + if ( null === hoverTarget ) {
3793 + return;
3794 + }
3795 +
3796 + deselectFields();
3797 +
3798 + sizeOfFieldGroup = getSizeOfFieldGroupFromChildElement( hoverTarget.querySelector( 'li.form-field' ) );
3799 +
3800 + hoverTarget.classList.add( 'frm-has-open-field-group-popup' );
3801 + jQuery( document ).on( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick );
3802 +
3803 + popupWrapper = div();
3804 + popupWrapper.style.position = 'relative';
3805 + popupWrapper.appendChild( getFieldGroupPopup( sizeOfFieldGroup, this ) );
3806 + this.parentNode.appendChild( popupWrapper );
3807 +
3808 + const firstLayoutOption = popupWrapper.querySelector( '.frm-row-layout-option' );
3809 + if ( firstLayoutOption ) {
3810 + firstLayoutOption.focus();
3811 + }
3812 + }
3813 +
3814 + function destroyFieldGroupPopupOnOutsideClick( event ) {
3815 + if ( event.target.classList.contains( 'frm-custom-field-group-layout' ) || event.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) {
3816 + return;
3817 + }
3818 + if ( ! jQuery( event.target ).closest( '#frm_field_group_controls' ).length && ! jQuery( event.target ).closest( '#frm_field_group_popup' ).length ) {
3819 + destroyFieldGroupPopup();
3820 + }
3821 + }
3822 +
3823 + function getSizeOfFieldGroupFromChildElement( element ) {
3824 + const $ul = jQuery( element ).closest( 'ul' );
3825 + if ( $ul.length ) {
3826 + return getFieldsInRow( $ul ).length;
3827 + }
3828 + return getSelectedFieldCount();
3829 + }
3830 +
3831 + function getFieldGroupPopup( sizeOfFieldGroup, childElement ) {
3832 + let popup, wrapper, rowLayoutOptions, ul;
3833 +
3834 + popup = document.getElementById( 'frm_field_group_popup' );
3835 + if ( null === popup ) {
3836 + popup = div();
3837 + } else {
3838 + popup.innerHTML = '';
3839 + }
3840 +
3841 + popup.id = 'frm_field_group_popup';
3842 +
3843 + wrapper = div();
3844 + wrapper.style.padding = '0 24px 12px';
3845 + wrapper.appendChild( getRowLayoutTitle() );
3846 +
3847 + rowLayoutOptions = getRowLayoutOptions( sizeOfFieldGroup );
3848 +
3849 + ul = childElement.closest( 'ul.frm_sorting' );
3850 + if ( null !== ul ) {
3851 + maybeMarkRowLayoutAsActive( ul, rowLayoutOptions );
3852 + }
3853 +
3854 + wrapper.appendChild( rowLayoutOptions );
3855 +
3856 + popup.appendChild( wrapper );
3857 + popup.appendChild( separator() );
3858 +
3859 + popup.appendChild( getCustomLayoutOption() );
3860 + popup.appendChild( getBreakIntoDifferentRowsOption() );
3861 +
3862 + return popup;
3863 + }
3864 +
3865 + function maybeMarkRowLayoutAsActive( activeRow, options ) {
3866 + let length, index, currentRow;
3867 +
3868 + length = options.children.length;
3869 + for ( index = 0; index < length; ++index ) {
3870 + currentRow = options.children[ index ];
3871 + if ( rowLayoutsMatch( currentRow, activeRow ) ) {
3872 + currentRow.classList.add( 'frm-active-row-layout' );
3873 + return;
3874 + }
3875 + }
3876 + }
3877 +
3878 + function separator() {
3879 + return document.createElement( 'hr' );
3880 + }
3881 +
3882 + function getCustomLayoutOption() {
3883 + const option = div();
3884 + option.textContent = __( 'Custom layout', 'formidable' );
3885 + jQuery( option ).prepend( getIconClone( 'frm_gear_svg' ) );
3886 + option.classList.add( 'frm-custom-field-group-layout' );
3887 + makeTabbable( option );
3888 + return option;
3889 + }
3890 +
3891 + function makeTabbable( element, ariaLabel ) {
3892 + element.setAttribute( 'tabindex', 0 );
3893 + element.setAttribute( 'role', 'button' );
3894 + if ( 'undefined' !== typeof ariaLabel ) {
3895 + element.setAttribute( 'aria-label', ariaLabel );
3896 + }
3897 + }
3898 +
3899 + function getIconClone( iconId ) {
3900 + const clone = document.getElementById( iconId ).cloneNode( true );
3901 + clone.id = '';
3902 + return clone;
3903 + }
3904 +
3905 + function getBreakIntoDifferentRowsOption() {
3906 + const option = div();
3907 + option.textContent = __( 'Break into rows', 'formidable' );
3908 + jQuery( option ).prepend( getIconClone( 'frm_break_field_group_svg' ) );
3909 + option.classList.add( 'frm-break-field-group' );
3910 + makeTabbable( option );
3911 + return option;
3912 + }
3913 +
3914 + function getRowLayoutTitle() {
3915 + const rowLayoutTitle = div();
3916 + rowLayoutTitle.classList.add( 'frm-row-layout-title' );
3917 + rowLayoutTitle.textContent = __( 'Row Layout', 'formidable' );
3918 + return rowLayoutTitle;
3919 + }
3920 +
3921 + function getRowLayoutOptions( size ) {
3922 + let wrapper, padding;
3923 +
3924 + wrapper = getEmptyGridContainer();
3925 + if ( 5 !== size ) {
3926 + wrapper.appendChild( getRowLayoutOption( size, 'even' ) );
3927 + }
3928 + if ( size % 2 === 1 ) {
3929 + // only include the middle option for odd numbers because even doesn't make a lot of sense.
3930 + wrapper.appendChild( getRowLayoutOption( size, 'middle' ) );
3931 + }
3932 + if ( size < 6 ) {
3933 + wrapper.appendChild( getRowLayoutOption( size, 'left' ) );
3934 + wrapper.appendChild( getRowLayoutOption( size, 'right' ) );
3935 + } else {
3936 + padding = div();
3937 + padding.classList.add( 'frm_fourth' );
3938 + wrapper.prepend( padding );
3939 + }
3940 +
3941 + return wrapper;
3942 + }
3943 +
3944 + function getRowLayoutOption( size, type ) {
3945 + let option, useClass;
3946 +
3947 + option = div();
3948 + option.classList.add( 'frm-row-layout-option' );
3949 + makeTabbable( option, type );
3950 +
3951 + switch ( size ) {
3952 + case 6:
3953 + useClass = 'frm_half';
3954 + break;
3955 + case 5:
3956 + useClass = 'frm_third';
3957 + break;
3958 + default:
3959 + useClass = size % 2 === 1 ? 'frm_fourth' : 'frm_third';
3960 + break;
3961 + }
3962 +
3963 + option.classList.add( useClass );
3964 + option.setAttribute( 'layout-type', type );
3965 +
3966 + option.appendChild( getRowForSizeAndType( size, type ) );
3967 + return option;
3968 + }
3969 +
3970 + function rowLayoutsMatch( row1, row2 ) {
3971 + return getRowLayoutAsKey( row1 ) === getRowLayoutAsKey( row2 );
3972 + }
3973 +
3974 + function getRowLayoutAsKey( row ) {
3975 + let $fields, sizes;
3976 + if ( row.classList.contains( 'frm-row-layout-option' ) ) {
3977 + $fields = jQuery( row ).find( '.frm_grid_container' ).children();
3978 + } else {
3979 + $fields = getFieldsInRow( jQuery( row ) );
3980 + }
3981 + sizes = [];
3982 + $fields.each(
3983 + function() {
3984 + sizes.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) );
3985 + }
3986 + );
3987 + return sizes.join( '-' );
3988 + }
3989 +
3990 + function getRowForSizeAndType( size, type ) {
3991 + let row, index, block;
3992 +
3993 + row = getEmptyGridContainer();
3994 + for ( index = 0; index < size; ++index ) {
3995 + block = div();
3996 + block.classList.add( getClassForBlock( size, type, index ) );
3997 + block.style.height = '16px';
3998 + block.style.background = '#9EA9B8';
3999 + block.style.borderRadius = '1px';
4000 + row.appendChild( block );
4001 + }
4002 +
4003 + return row;
4004 + }
4005 +
4006 + /**
4007 + * @param {int} size 2-6.
4008 + * @param {string} type even, middle, left, or right.
4009 + * @param {int} index 0-5.
4010 + * @returns string
4011 + */
4012 + function getClassForBlock( size, type, index ) {
4013 + if ( 'even' === type ) {
4014 + return getEvenClassForSize( size, index );
4015 + } else if ( 'middle' === type ) {
4016 + if ( 3 === size ) {
4017 + return 1 === index ? 'frm6' : 'frm3';
4018 + }
4019 + if ( 5 === size ) {
4020 + return 2 === index ? 'frm4' : 'frm2';
4021 + }
4022 + } else if ( 'left' === type ) {
4023 + return 0 === index ? getLargeClassForSize( size ) : getSmallClassForSize( size );
4024 + } else if ( 'right' === type ) {
4025 + return index === size - 1 ? getLargeClassForSize( size ) : getSmallClassForSize( size );
4026 + }
4027 + return 'frm12';
4028 + }
4029 +
4030 + function getEvenClassForSize( size, index ) {
4031 + if ( -1 !== [ 2, 3, 4, 6 ].indexOf( size ) ) {
4032 + return getLayoutClassForSize( 12 / size );
4033 + }
4034 + if ( 5 === size && 'undefined' !== typeof index ) {
4035 + return 0 === index ? 'frm4' : 'frm2';
4036 + }
4037 + return 'frm12';
4038 + }
4039 +
4040 + function getSmallClassForSize( size ) {
4041 + switch ( size ) {
4042 + case 2: case 3:
4043 + return 'frm3';
4044 + case 4:
4045 + return 'frm2';
4046 + case 5:
4047 + return 'frm2';
4048 + case 6:
4049 + return 'frm1';
4050 + }
4051 + return 'frm12';
4052 + }
4053 +
4054 + function getLargeClassForSize( size ) {
4055 + switch ( size ) {
4056 + case 2:
4057 + return 'frm9';
4058 + case 3: case 4:
4059 + return 'frm6';
4060 + case 5:
4061 + return 'frm4';
4062 + case 6:
4063 + return 'frm7';
4064 + }
4065 + return 'frm12';
4066 + }
4067 +
4068 + function getEmptyGridContainer() {
4069 + const wrapper = div();
4070 + wrapper.classList.add( 'frm_grid_container' );
4071 + return wrapper;
4072 + }
4073 +
4074 + /**
4075 + * Handle when a field group layout option (that sets grid classes/column sizing) is selected in the "Row Layout" popup.
4076 + *
4077 + * @returns {void}
4078 + */
4079 + function handleFieldGroupLayoutOptionClick() {
4080 + const row = document.querySelector( '.frm-field-group-hover-target' );
4081 + if ( ! row ) {
4082 + // The field group layout options also get clicked when merging multiple rows.
4083 + // The following code isn't required for multiple rows though so just exit early.
4084 + return;
4085 + }
4086 +
4087 + const type = this.getAttribute( 'layout-type' );
4088 + syncLayoutClasses( getFieldsInRow( jQuery( row ) ).first(), type );
4089 + destroyFieldGroupPopup();
4090 + }
4091 +
4092 + function handleFieldGroupLayoutOptionInsideMergeClick() {
4093 + let $ul, type;
4094 + $ul = mergeSelectedFieldGroups();
4095 + type = this.getAttribute( 'layout-type' );
4096 + syncLayoutClasses( getFieldsInRow( $ul ).first(), type );
4097 + unselectFieldGroups();
4098 + }
4099 +
4100 + function mergeSelectedFieldGroups() {
4101 + const $selectedFieldGroups = jQuery( '.frm-selected-field-group' ),
4102 + $firstGroupUl = $selectedFieldGroups.first();
4103 + $selectedFieldGroups.not( $firstGroupUl ).each(
4104 + function() {
4105 + getFieldsInRow( jQuery( this ) ).each(
4106 + function() {
4107 + const previousParent = this.parentNode;
4108 + getFieldsInRow( $firstGroupUl ).last().after( this );
4109 + if ( ! jQuery( previousParent ).children( 'li.form-field' ).length ) {
4110 + // clean up the previous field group if we've removed all of its fields.
4111 + previousParent.closest( 'li.frm_field_box' ).remove();
4112 + }
4113 + }
4114 + );
4115 + }
4116 + );
4117 + updateFieldOrder();
4118 + syncLayoutClasses( getFieldsInRow( $firstGroupUl ).first() );
4119 + return $firstGroupUl;
4120 + }
4121 +
4122 + function customFieldGroupLayoutClick() {
4123 + let $fields;
4124 + if ( null !== this.closest( '.frm-merge-fields-into-row' ) ) {
4125 + return;
4126 + }
4127 + $fields = getFieldsInRow( jQuery( '.frm-field-group-hover-target' ) );
4128 + setupCustomLayoutOptions( $fields );
4129 + }
4130 +
4131 + function setupCustomLayoutOptions( $fields ) {
4132 + let size, popup, wrapper, layoutClass, inputRow, paddingElement, inputValueOverride, index, inputField, heading, label, buttonsWrapper, cancelButton, saveButton;
4133 +
4134 + size = $fields.length;
4135 +
4136 + popup = document.getElementById( 'frm_field_group_popup' );
4137 + popup.innerHTML = '';
4138 +
4139 + wrapper = div();
4140 + wrapper.style.padding = '0 24px';
4141 +
4142 + layoutClass = getEvenClassForSize( 5 === size ? 6 : size );
4143 +
4144 + inputRow = div();
4145 + inputRow.style.padding = '20px 0';
4146 + inputRow.classList.add( 'frm_grid_container' );
4147 +
4148 + if ( 5 === size ) {
4149 + // add a span to pad the inputs by 1 column, to account for the missing 2 columns.
4150 + paddingElement = document.createElement( 'span' );
4151 + paddingElement.classList.add( 'frm1' );
4152 + inputRow.appendChild( paddingElement );
4153 + }
4154 +
4155 + inputValueOverride = getSelectedFieldCount() > 0 ? getSizeOfLayoutClass( getEvenClassForSize( size ) ) : false;
4156 + if ( false !== inputValueOverride && inputValueOverride >= 12 ) {
4157 + inputValueOverride = Math.floor( 12 / size );
4158 + }
4159 +
4160 + for ( index = 0; index < size; ++index ) {
4161 + inputField = document.createElement( 'input' );
4162 + inputField.type = 'text';
4163 + inputField.classList.add( layoutClass );
4164 + inputField.classList.add( 'frm-custom-grid-size-input' );
4165 + inputField.value = false !== inputValueOverride ? inputValueOverride : getSizeOfLayoutClass( getLayoutClassName( $fields.get( index ).classList ) );
4166 + inputRow.appendChild( inputField );
4167 + }
4168 +
4169 + heading = div();
4170 + heading.classList.add( 'frm-builder-popup-heading' );
4171 + heading.textContent = __( 'Enter number of columns for each field', 'formidable' );
4172 +
4173 + label = div();
4174 + label.classList.add( 'frm-builder-popup-subheading' );
4175 + label.textContent = __( 'Layouts are based on a 12-column grid system', 'formidable' );
4176 +
4177 + wrapper.appendChild( heading );
4178 + wrapper.appendChild( label );
4179 +
4180 + wrapper.appendChild( inputRow );
4181 +
4182 + buttonsWrapper = div();
4183 + buttonsWrapper.style.textAlign = 'right';
4184 +
4185 + cancelButton = getSecondaryButton();
4186 + cancelButton.textContent = __( 'Cancel', 'formidable' );
4187 + cancelButton.classList.add( 'frm-cancel-custom-field-group-layout' );
4188 + cancelButton.style.marginRight = '10px';
4189 +
4190 + saveButton = getPrimaryButton();
4191 + saveButton.textContent = __( 'Save', 'formidable' );
4192 + saveButton.classList.add( 'frm-save-custom-field-group-layout' );
4193 +
4194 + buttonsWrapper.appendChild( cancelButton );
4195 + buttonsWrapper.appendChild( saveButton );
4196 +
4197 + wrapper.appendChild( buttonsWrapper );
4198 +
4199 + popup.appendChild( wrapper );
4200 +
4201 + setTimeout(
4202 + function() {
4203 + const firstInput = popup.querySelector( 'input.frm-custom-grid-size-input' ).focus();
4204 + if ( firstInput ) {
4205 + firstInput.focus();
4206 + }
4207 + },
4208 + 0
4209 + );
4210 + }
4211 +
4212 + function customFieldGroupLayoutInsideMergeClick() {
4213 + $fields = jQuery( '.frm-selected-field-group li.form-field' );
4214 + setupCustomLayoutOptions( $fields );
4215 + }
4216 +
4217 + function getPrimaryButton() {
4218 + const button = getButton();
4219 + button.classList.add( 'button-primary', 'frm-button-primary' );
4220 + return button;
4221 + }
4222 +
4223 + function getSecondaryButton() {
4224 + const button = getButton();
4225 + button.classList.add( 'button-secondary', 'frm-button-secondary' );
4226 + return button;
4227 + }
4228 +
4229 + function getButton() {
4230 + const button = document.createElement( 'a' );
4231 + button.setAttribute( 'href', '#' );
4232 + button.classList.add( 'button' );
4233 + button.style.textDecoration = 'none';
4234 + return button;
4235 + }
4236 +
4237 + function getSizeOfLayoutClass( className ) {
4238 + switch ( className ) {
4239 + case 'frm_half':
4240 + return 6;
4241 + case 'frm_third':
4242 + return 4;
4243 + case 'frm_two_thirds':
4244 + return 8;
4245 + case 'frm_fourth':
4246 + return 3;
4247 + case 'frm_three_fourths':
4248 + return 9;
4249 + case 'frm_sixth':
4250 + return 2;
4251 + }
4252 +
4253 + if ( 0 === className.indexOf( 'frm' ) ) {
4254 + return parseInt( className.substr( 3 ) );
4255 + }
4256 +
4257 + // Anything missing a layout class should be a full width row.
4258 + return 12;
4259 + }
4260 +
4261 + function getLayoutClassName( classList ) {
4262 + let classes, index, currentClass;
4263 + classes = getLayoutClasses();
4264 + for ( index = 0; index < classes.length; ++index ) {
4265 + currentClass = classes[ index ];
4266 + if ( classList.contains( currentClass ) ) {
4267 + return currentClass;
4268 + }
4269 + }
4270 + return '';
4271 + }
4272 +
4273 + function getLayoutClassForSize( size ) {
4274 + return 'frm' + size;
4275 + }
4276 +
4277 + function breakFieldGroupClick() {
4278 + const row = document.querySelector( '.frm-field-group-hover-target' );
4279 + breakRow( row );
4280 + destroyFieldGroupPopup();
4281 + }
4282 +
4283 + function breakRow( row ) {
4284 + const $row = jQuery( row );
4285 + getFieldsInRow( $row ).each(
4286 + function( index ) {
4287 + const field = this;
4288 + if ( 0 !== index ) {
4289 + $row.parent().after( wrapFieldLi( field ) );
4290 + }
4291 + stripLayoutFromFields( jQuery( field ) );
4292 + }
4293 + );
4294 + }
4295 +
4296 + function stripLayoutFromFields( field ) {
4297 + syncLayoutClasses( field, 'clear' );
4298 + }
4299 +
4300 + function focusFieldGroupInputOnClick() {
4301 + this.select();
4302 + }
4303 +
4304 + function cancelCustomFieldGroupClick() {
4305 + revertToFieldGroupPopupFirstPage( this );
4306 + }
4307 +
4308 + function revertToFieldGroupPopupFirstPage( triggerElement ) {
4309 + jQuery( document.getElementById( 'frm_field_group_popup' ) ).replaceWith(
4310 + getFieldGroupPopup( getSizeOfFieldGroupFromChildElement( triggerElement ), triggerElement )
4311 + );
4312 + }
4313 +
4314 + function destroyFieldGroupPopup() {
4315 + let popup, wrapper;
4316 + popup = document.getElementById( 'frm_field_group_popup' );
4317 + if ( popup === null ) {
4318 + return;
4319 + }
4320 + wrapper = document.querySelector( '.frm-has-open-field-group-popup' );
4321 + if ( null !== wrapper ) {
4322 + wrapper.classList.remove( 'frm-has-open-field-group-popup' );
4323 + popup.parentNode.remove();
4324 + }
4325 + jQuery( document ).off( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick );
4326 + }
4327 +
4328 + function saveCustomFieldGroupClick() {
4329 + let syncDetails, $controls, $ul;
4330 +
4331 + syncDetails = [];
4332 +
4333 + jQuery( document.getElementById( 'frm_field_group_popup' ).querySelectorAll( '.frm_grid_container input' ) )
4334 + .each(
4335 + function() {
4336 + syncDetails.push( parseInt( this.value ) );
4337 + }
4338 + );
4339 +
4340 + $controls = jQuery( document.getElementById( 'frm_field_group_controls' ) );
4341 +
4342 + if ( $controls.length && 'none' !== $controls.get( 0 ).style.display ) {
4343 + syncLayoutClasses( getFieldsInRow( jQuery( document.querySelector( '.frm-field-group-hover-target' ) ) ).first(), syncDetails );
4344 + } else {
4345 + $ul = mergeSelectedFieldGroups();
4346 + syncLayoutClasses( getFieldsInRow( $ul ).first(), syncDetails );
4347 + unselectFieldGroups();
4348 + }
4349 +
4350 + destroyFieldGroupPopup();
4351 + }
4352 +
4353 + function fieldGroupClick( e ) {
4354 + maybeShowFieldGroupMessage();
4355 +
4356 + if ( 'ul' !== e.originalEvent.target.nodeName.toLowerCase() ) {
4357 + // only continue if the group itself was clicked / ignore when a field is clicked.
4358 + return;
4359 + }
4360 +
4361 + const hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
4362 + if ( ! hoverTarget ) {
4363 + return;
4364 + }
4365 +
4366 + const ctrlOrCmdKeyIsDown = e.ctrlKey || e.metaKey;
4367 + const shiftKeyIsDown = e.shiftKey;
4368 + const groupIsActive = hoverTarget.classList.contains( 'frm-selected-field-group' );
4369 + const $selectedFieldGroups = getSelectedFieldGroups();
4370 +
4371 + let numberOfSelectedGroups = $selectedFieldGroups.length;
4372 +
4373 + if ( ctrlOrCmdKeyIsDown || shiftKeyIsDown ) {
4374 + // multi-selecting
4375 +
4376 + const selectedField = getSelectedField();
4377 + if ( null !== selectedField && ! jQuery( selectedField ).siblings( 'li.form-field' ).length ) {
4378 + // count a selected field on its own as a selected field group when multiselecting.
4379 + selectedField.parentNode.classList.add( 'frm-selected-field-group' );
4380 + ++numberOfSelectedGroups;
4381 + }
4382 +
4383 + if ( ctrlOrCmdKeyIsDown ) {
4384 + if ( groupIsActive ) {
4385 + // unselect if holding ctrl or cmd and the group was already active.
4386 + --numberOfSelectedGroups;
4387 + hoverTarget.classList.remove( 'frm-selected-field-group' );
4388 + syncAfterMultiSelect( numberOfSelectedGroups );
4389 + return; // exit early to avoid adding back frm-selected-field-group
4390 + }
4391 +
4392 + ++numberOfSelectedGroups;
4393 + } else if ( shiftKeyIsDown && ! groupIsActive ) {
4394 + ++numberOfSelectedGroups; // include the one we're selecting right now.
4395 + const $firstGroup = $selectedFieldGroups.first();
4396 +
4397 + let $range;
4398 + if ( $firstGroup.parent().index() < jQuery( hoverTarget.parentNode ).index() ) {
4399 + $range = $firstGroup.parent().nextUntil( hoverTarget.parentNode );
4400 + } else {
4401 + $range = $firstGroup.parent().prevUntil( hoverTarget.parentNode );
4402 + }
4403 +
4404 + $range.each(
4405 + function() {
4406 + const $fieldGroup = jQuery( this ).closest( 'li' ).find( 'ul.frm_sorting' );
4407 + if ( ! $fieldGroup.hasClass( 'frm-selected-field-group' ) ) {
4408 + ++numberOfSelectedGroups;
4409 + $fieldGroup.addClass( 'frm-selected-field-group' );
4410 + }
4411 + }
4412 + );
4413 +
4414 + // when holding shift and clicking, text gets selected. unselect it.
4415 + document.getSelection().removeAllRanges();
4416 + }
4417 + } else {
4418 + // not multi-selecting
4419 + unselectFieldGroups();
4420 + numberOfSelectedGroups = 1;
4421 + }
4422 +
4423 + hoverTarget.classList.add( 'frm-selected-field-group' );
4424 + syncAfterMultiSelect( numberOfSelectedGroups );
4425 +
4426 + maybeHideFieldGroupMessage();
4427 +
4428 + jQuery( document ).off( 'click', unselectFieldGroups );
4429 + jQuery( document ).on( 'click', unselectFieldGroups );
4430 + }
4431 +
4432 + /**
4433 + * Hide the field group message by manipulating classes.
4434 + *
4435 + * @param {Element} fieldGroupMessage The field group message element.
4436 + * @return {void}
4437 + */
4438 + function hideFieldGroupMessage( fieldGroupMessage ) {
4439 + if ( ! fieldGroupMessage ) {
4440 + return;
4441 + }
4442 +
4443 + fieldGroupMessage.classList.add( 'frm_hidden' );
4444 + fieldGroupMessage.classList.remove( 'frm-fadein-up-back' );
4445 + }
4446 +
4447 + /**
4448 + * Show the field group message by manipulating classes.
4449 + *
4450 + * @param {Element} fieldGroupMessage The field group message element.
4451 + * @return {void}
4452 + */
4453 + function showFieldGroupMessage( fieldGroupMessage ) {
4454 + if ( ! fieldGroupMessage ) {
4455 + return;
4456 + }
4457 +
4458 + fieldGroupMessage.classList.remove( 'frm_hidden' );
4459 + fieldGroupMessage.classList.add( 'frm-fadein-up-back' );
4460 + }
4461 +
4462 + /**
4463 + * Maybe show a message if there are at least two rows.
4464 + *
4465 + * @return {void}
4466 + */
4467 + function maybeShowFieldGroupMessage() {
4468 + let fieldGroupMessage = document.getElementById( 'frm-field-group-message' );
4469 + const rows = document.querySelectorAll( '.edit_form_item:not(.edit_field_type_end_divider)' );
4470 +
4471 + if ( rows.length < 2 ) {
4472 + hideFieldGroupMessage( fieldGroupMessage );
4473 + return;
4474 + }
4475 +
4476 + if ( fieldGroupMessage ) {
4477 + showFieldGroupMessage( fieldGroupMessage );
4478 + return;
4479 + }
4480 +
4481 + fieldGroupMessage = div({
4482 + id: 'frm-field-group-message',
4483 + className: 'frm-flex-center frm-fadein-up-back',
4484 + children: [
4485 + span({
4486 + id: 'frm-field-group-message-dismiss',
4487 + className: 'frm-flex-center',
4488 + child: svg({ href: '#frm_close_icon' })
4489 + })
4490 + ]
4491 + });
4492 +
4493 + // Insert the field group into the DOM
4494 + document.getElementById( 'post-body-content' ).appendChild( fieldGroupMessage );
4495 +
4496 + // Get and add the field group message text
4497 + const messageText = getFieldGroupMessageText();
4498 + fieldGroupMessage.prepend( messageText );
4499 +
4500 + // Set up a click event listener
4501 + document.getElementById( 'frm-field-group-message-dismiss' ).addEventListener( 'click', () => {
4502 + hideFieldGroupMessage( document.getElementById( 'frm-field-group-message' ) );
4503 + });
4504 + }
4505 +
4506 + /**
4507 + * Get a span element with text about selecting multiple fields.
4508 + *
4509 + * @return {HTMLElement} A span element with the message and style classes.
4510 + */
4511 + function getFieldGroupMessageText() {
4512 + const text = document.createElement( 'span' );
4513 + text.classList.add( 'frm-field-group-message-text', 'frm-flex-center' );
4514 + text.innerHTML = sprintf(
4515 + /* translators: %1$s: Start span HTML, %2$s: end span HTML */
4516 + frm_admin_js.holdShiftMsg, // eslint-disable-line camelcase
4517 + '<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>',
4518 + '</span>'
4519 + );
4520 +
4521 + return text;
4522 + }
4523 +
4524 + /**
4525 + * Maybe hide the field group message based on the number of selected rows.
4526 + *
4527 + * @return {void}
4528 + */
4529 + function maybeHideFieldGroupMessage() {
4530 + const selectedRowCount = document.querySelectorAll( '.frm-selected-field-group' ).length;
4531 + if ( selectedRowCount < 2 ) {
4532 + return;
4533 + }
4534 +
4535 + const fieldGroupMessage = document.getElementById( 'frm-field-group-message' );
4536 + hideFieldGroupMessage( fieldGroupMessage );
4537 + }
4538 +
4539 + function getSelectedField() {
4540 + return document.getElementById( 'frm-show-fields' ).querySelector( 'li.form-field.selected' );
4541 + }
4542 +
4543 + function getSelectedFieldGroups() {
4544 + const $fieldGroups = jQuery( '.frm-selected-field-group' );
4545 + if ( $fieldGroups.length ) {
4546 + return $fieldGroups;
4547 + }
4548 +
4549 + const selectedField = getSelectedField();
4550 + if ( selectedField ) {
4551 + // If there is only one field in a group and the field is selected, consider the field's group as selected for multi-select.
4552 + const selectedFieldGroup = selectedField.closest( 'ul' );
4553 + if ( selectedFieldGroup && 1 === getFieldsInRow( jQuery( selectedFieldGroup ) ).length ) {
4554 + selectedFieldGroup.classList.add( 'frm-selected-field-group' );
4555 + return jQuery( selectedFieldGroup );
4556 + }
4557 + }
4558 +
4559 + return jQuery();
4560 + }
4561 +
4562 + function syncAfterMultiSelect( numberOfSelectedGroups ) {
4563 + clearSettingsBox( true ); // unselect any fields if one is selected.
4564 + if ( numberOfSelectedGroups >= 2 || ( 1 === numberOfSelectedGroups && selectedGroupHasMultipleFields() ) ) {
4565 + addFieldMultiselectPopup();
4566 + } else {
4567 + maybeRemoveMultiselectPopup();
4568 + }
4569 + maybeRemoveGroupHoverTarget();
4570 + }
4571 +
4572 + function selectedGroupHasMultipleFields() {
4573 + return getFieldsInRow( jQuery( document.querySelector( '.frm-selected-field-group' ) ) ).length > 1;
4574 + }
4575 +
4576 + function unselectFieldGroups( event ) {
4577 + if ( 'undefined' !== typeof event ) {
4578 + if ( null !== event.originalEvent.target.closest( '#frm-show-fields' ) ) {
4579 + return;
4580 + }
4581 + if ( event.originalEvent.target.classList.contains( 'frm-merge-fields-into-row' ) ) {
4582 + return;
4583 + }
4584 + if ( null !== event.originalEvent.target.closest( '.frm-merge-fields-into-row' ) ) {
4585 + return;
4586 + }
4587 + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) {
4588 + return;
4589 + }
4590 + if ( event.originalEvent.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) {
4591 + return;
4592 + }
4593 + }
4594 + jQuery( '.frm-selected-field-group' ).removeClass( 'frm-selected-field-group' );
4595 + jQuery( document ).off( 'click', unselectFieldGroups );
4596 + maybeRemoveMultiselectPopup();
4597 + }
4598 +
4599 + function maybeRemoveMultiselectPopup() {
4600 + const popup = document.getElementById( 'frm_field_multiselect_popup' );
4601 + if ( null !== popup ) {
4602 + popup.remove();
4603 + }
4604 + }
4605 +
4606 + function addFieldMultiselectPopup() {
4607 + getFieldMultiselectPopup();
4608 + }
4609 +
4610 + function getFieldMultiselectPopup() {
4611 + let popup, mergeOption, caret, verticalSeparator, deleteOption;
4612 +
4613 + popup = document.getElementById( 'frm_field_multiselect_popup' );
4614 +
4615 + if ( null !== popup ) {
4616 + popup.classList.toggle( 'frm-unmergable', ! selectedFieldsAreMergeable() );
4617 + return popup;
4618 + }
4619 +
4620 + popup = div();
4621 + popup.id = 'frm_field_multiselect_popup';
4622 + if ( ! selectedFieldsAreMergeable() ) {
4623 + popup.classList.add( 'frm-unmergable' );
4624 + }
4625 +
4626 + mergeOption = div();
4627 + mergeOption.classList.add( 'frm-merge-fields-into-row' );
4628 + mergeOption.textContent = __( 'Merge into row', 'formidable' );
4629 +
4630 + caret = document.createElement( 'a' );
4631 + caret.style.marginLeft = '5px';
4632 + caret.classList.add( 'frm_icon_font', 'frm_arrowdown6_icon' );
4633 + caret.setAttribute( 'href', '#' );
4634 + mergeOption.appendChild( caret );
4635 +
4636 + popup.appendChild( mergeOption );
4637 +
4638 + verticalSeparator = div();
4639 + verticalSeparator.classList.add( 'frm-multiselect-popup-separator' );
4640 + popup.appendChild( verticalSeparator );
4641 +
4642 + deleteOption = div();
4643 + deleteOption.classList.add( 'frm-delete-field-groups' );
4644 + deleteOption.appendChild( getIconClone( 'frm_trash_svg' ) );
4645 + popup.appendChild( deleteOption );
4646 +
4647 + document.getElementById( 'post-body-content' ).appendChild( popup );
4648 +
4649 + jQuery( popup ).hide().fadeIn();
4650 +
4651 + return popup;
4652 + }
4653 +
4654 + function selectedFieldsAreMergeable() {
4655 + let selectedFieldGroups, totalFieldCount, length, index, fieldGroup;
4656 + selectedFieldGroups = document.querySelectorAll( '.frm-selected-field-group' );
4657 + length = selectedFieldGroups.length;
4658 + if ( 1 === length ) {
4659 + return false;
4660 + }
4661 + totalFieldCount = 0;
4662 + for ( index = 0; index < length; ++index ) {
4663 + fieldGroup = selectedFieldGroups[ index ];
4664 + if ( null !== fieldGroup.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ) ) {
4665 + return false;
4666 + }
4667 + totalFieldCount += getFieldsInRow( jQuery( fieldGroup ) ).length;
4668 + if ( totalFieldCount > 6 ) {
4669 + return false;
4670 + }
4671 + }
4672 + return true;
4673 + }
4674 +
4675 + function mergeFieldsIntoRowClick( event ) {
4676 + let size, popup;
4677 +
4678 + if ( null !== event.originalEvent.target.closest( '#frm_field_group_popup' ) ) {
4679 + // prevent clicks within the popup from triggering the button again.
4680 + return;
4681 + }
4682 +
4683 + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) {
4684 + // avoid switching back to the first page when clicking the custom option nested inside of the merge option.
4685 + return;
4686 + }
4687 +
4688 + size = getSelectedFieldCount();
4689 + popup = getFieldGroupPopup( size, document.querySelector( '.frm-selected-field-group' ).firstChild );
4690 + this.appendChild( popup );
4691 + }
4692 +
4693 + function getSelectedFieldCount() {
4694 + let count = 0;
4695 + jQuery( document.querySelectorAll( '.frm-selected-field-group' ) ).each(
4696 + function() {
4697 + count += getFieldsInRow( jQuery( this ) ).length;
4698 + }
4699 + );
4700 + return count;
4701 + }
4702 +
4703 + function deleteFieldGroupsClick() {
4704 + let fieldIdsToDelete, deleteOnConfirm, multiselectPopup;
4705 +
4706 + fieldIdsToDelete = getSelectedFieldIds();
4707 + deleteOnConfirm = getDeleteSelectedFieldGroupsOnConfirmFunction( fieldIdsToDelete );
4708 +
4709 + multiselectPopup = document.getElementById( 'frm_field_multiselect_popup' );
4710 + if ( null !== multiselectPopup ) {
4711 + multiselectPopup.remove();
4712 + }
4713 +
4714 + this.setAttribute( 'data-frmverify', confirmFieldsDeleteMessage( fieldIdsToDelete.length ) );
4715 + confirmLinkClick( this );
4716 +
4717 + jQuery( '#frm-confirmed-click' ).on( 'click', deleteOnConfirm );
4718 + jQuery( '#frm_confirm_modal' ).one( 'dialogclose', function() {
4719 + jQuery( '#frm-confirmed-click' ).off( 'click', deleteOnConfirm );
4720 + });
4721 + }
4722 +
4723 + function getSelectedFieldIds() {
4724 + const deleteFieldIds = [];
4725 + jQuery( '.frm-selected-field-group > li.form-field' )
4726 + .each(
4727 + function() {
4728 + deleteFieldIds.push( this.dataset.fid );
4729 + }
4730 + );
4731 + return deleteFieldIds;
4732 + }
4733 +
4734 + function getDeleteSelectedFieldGroupsOnConfirmFunction( deleteFieldIds ) {
4735 + return function( event ) {
4736 + event.preventDefault();
4737 + deleteAllSelectedFieldGroups( deleteFieldIds );
4738 + };
4739 + }
4740 +
4741 + function deleteAllSelectedFieldGroups( deleteFieldIds ) {
4742 + deleteFieldIds.forEach(
4743 + function( fieldId ) {
4744 + deleteFields( fieldId );
4745 + }
4746 + );
4747 + }
4748 +
4749 + function deleteFieldConfirmed() {
4750 + /*jshint validthis:true */
4751 + deleteFields( this.getAttribute( 'data-deletefield' ) );
4752 + }
4753 +
4754 + function deleteFields( fieldId ) {
4755 + const field = jQuery( '#frm_field_id_' + fieldId );
4756 +
4757 + deleteField( fieldId );
4758 +
4759 + if ( field.hasClass( 'edit_field_type_divider' ) ) {
4760 + field.find( 'li.frm_field_box' ).each( function() {
4761 + //TODO: maybe delete only end section
4762 + //if(n.hasClass('edit_field_type_end_divider')){
4763 + deleteField( this.getAttribute( 'data-fid' ) );
4764 + //}
4765 + });
4766 + }
4767 + toggleSectionHolder();
4768 + }
4769 +
4770 + /**
4771 + * Checks if there is only submit field in the form builder.
4772 + *
4773 + * @return {Boolean}
4774 + */
4775 + function hasOnlySubmitField() {
4776 + // If there are at least 2 rows, return false.
4777 + if ( $newFields.get( 0 ).childElementCount > 1 ) {
4778 + return false;
4779 + }
4780 +
4781 + const childUl = $newFields.get( 0 ).firstElementChild.firstElementChild;
4782 +
4783 + // Use query instead of children because there might be a div inside this ul.
4784 + const childLi = childUl.querySelectorAll( 'li.frm_field_box' );
4785 +
4786 + // If there are at least 2 items in the row, return false.
4787 + if ( childLi.length > 1 ) {
4788 + return false;
4789 + }
4790 +
4791 + return childLi[0].classList.contains( 'edit_field_type_submit' );
4792 + }
4793 +
4794 + function deleteField( fieldId ) {
4795 + jQuery.ajax({
4796 + type: 'POST',
4797 + url: ajaxurl,
4798 + data: {
4799 + action: 'frm_delete_field',
4800 + field_id: fieldId,
4801 + nonce: frmGlobal.nonce
4802 + },
4803 + success: function() {
4804 + const $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ),
4805 + settings = jQuery( '#frm-single-settings-' + fieldId );
4806 +
4807 + // Remove settings from sidebar.
4808 + if ( settings.is( ':visible' ) ) {
4809 + document.getElementById( 'frm_insert_fields_tab' ).click();
4810 + }
4811 + settings.remove();
4812 +
4813 + $thisField.fadeOut( 'slow', function() {
4814 + let $section = $thisField.closest( '.start_divider' ),
4815 + type = $thisField.data( 'type' ),
4816 + $adjacentFields = $thisField.siblings( 'li.form-field' ),
4817 + $liWrapper;
4818 +
4819 + if ( ! $adjacentFields.length ) {
4820 + if ( $thisField.is( '.edit_field_type_end_divider' ) ) {
4821 + $adjacentFields.length = $thisField.closest( 'li.form-field' ).siblings();
4822 + } else {
4823 + $liWrapper = $thisField.closest( 'ul.frm_sorting' ).parent();
4824 + }
4825 + }
4826 +
4827 + $thisField.remove();
4828 + if ( type === 'break' ) {
4829 + renumberPageBreaks();
4830 + } else if ( type === 'product' ) {
4831 + maybeHideQuantityProductFieldOption();
4832 + // a product field attached to a quantity field earlier might be the one deleted, so re-populate
4833 + popAllProductFields();
4834 + }
4835 +
4836 + if ( $adjacentFields.length ) {
4837 + syncLayoutClasses( $adjacentFields.first() );
4838 + } else {
4839 + $liWrapper.remove();
4840 + }
4841 +
4842 + if ( jQuery( '#frm-show-fields li' ).length === 0 || hasOnlySubmitField() ) {
4843 + const formEditorContainer = document.getElementById( 'frm_form_editor_container' );
4844 + formEditorContainer.classList.remove( 'frm-has-fields' );
4845 + formEditorContainer.classList.add( 'frm-empty-fields' );
4846 + } else if ( $section.length ) {
4847 + toggleOneSectionHolder( $section );
4848 + }
4849 +
4850 + // prevent "More Options" tooltips from staying around after their target field is deleted.
4851 + deleteTooltips();
4852 + });
4853 + wp.hooks.doAction( 'frm_after_delete_field', $thisField[0] );
4854 + }
4855 + });
4856 + }
4857 +
4858 + function addFieldLogicRow() {
4859 + /*jshint validthis:true */
4860 + const id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
4861 + formId = thisFormId,
4862 + logicRows = document.getElementById( 'frm_logic_row_' + id ).querySelectorAll( '.frm_logic_row' );
4863 + jQuery.ajax({
4864 + type: 'POST',
4865 + url: ajaxurl,
4866 + data: {
4867 + action: 'frm_add_logic_row',
4868 + form_id: formId,
4869 + field_id: id,
4870 + nonce: frmGlobal.nonce,
4871 + meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ),
4872 + fields: getFieldList()
4873 + },
4874 + success: function( html ) {
4875 + jQuery( document.getElementById( 'logic_' + id ) ).fadeOut( 'slow', function() {
4876 + const logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) );
4877 + logicRow.append( html );
4878 + logicRow.closest( '.frm_logic_rows' ).fadeIn( 'slow' );
4879 + });
4880 + }
4881 + });
4882 + return false;
4883 + }
4884 +
4885 + function getNewRowId( rows, replace, defaultValue ) {
4886 + if ( ! rows.length ) {
4887 + return 'undefined' !== typeof defaultValue ? defaultValue : 0;
4888 + }
4889 + return parseInt( rows[ rows.length - 1 ].id.replace( replace, '' ), 10 ) + 1;
4890 + }
4891 +
4892 + function addWatchLookupRow() {
4893 + /*jshint validthis:true */
4894 + let lastRowId,
4895 + id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
4896 + formId = thisFormId,
4897 + lookupBlockRows = document.getElementById( 'frm_watch_lookup_block_' + id ).children;
4898 + jQuery.ajax({
4899 + type: 'POST',
4900 + url: ajaxurl,
4901 + data: {
4902 + action: 'frm_add_watch_lookup_row',
4903 + form_id: formId,
4904 + field_id: id,
4905 + row_key: getNewRowId( lookupBlockRows, 'frm_watch_lookup_' + id + '_' ),
4906 + nonce: frmGlobal.nonce
4907 + },
4908 + success: function( newRow ) {
4909 + const watchRowBlock = jQuery( document.getElementById( 'frm_watch_lookup_block_' + id ) );
4910 + watchRowBlock.append( newRow );
4911 + watchRowBlock.fadeIn( 'slow' );
4912 + }
4913 + });
4914 + return false;
4915 + }
4916 +
4917 + function resetOptionTextDetails() {
4918 + jQuery( '.frm-single-settings ul input[type="text"][name^="field_options[options_"]' ).filter( '[data-value-on-load]' ).removeAttr( 'data-value-on-load' );
4919 + jQuery( 'input[type="hidden"][name^=optionmap]' ).remove();
4920 + }
4921 +
4922 + function optionTextAlreadyExists( input ) {
4923 + let fieldId = jQuery( input ).closest( '.frm-single-settings' ).attr( 'data-fid' ),
4924 + optionInputs = jQuery( input ).closest( 'ul' ).get( 0 ).querySelectorAll( '.field_' + fieldId + '_option' ),
4925 + index,
4926 + optionInput;
4927 +
4928 + for ( index in optionInputs ) {
4929 + optionInput = optionInputs[ index ];
4930 + if ( optionInput.id !== input.id && optionInput.value === input.value && optionInput.getAttribute( 'data-duplicate' ) !== 'true' ) {
4931 + return true;
4932 + }
4933 + }
4934 +
4935 + return false;
4936 + }
4937 +
4938 + function onOptionTextFocus() {
4939 + let input,
4940 + fieldId;
4941 +
4942 + if ( this.getAttribute( 'data-value-on-load' ) === null ) {
4943 + this.setAttribute( 'data-value-on-load', this.value );
4944 +
4945 + fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' );
4946 + input = document.createElement( 'input' );
4947 + input.value = this.value;
4948 + input.setAttribute( 'type', 'hidden' );
4949 + input.setAttribute( 'name', 'optionmap[' + fieldId + '][' + this.value + ']' );
4950 + this.parentNode.appendChild( input );
4951 +
4952 + if ( typeof optionMap[ fieldId ] === 'undefined' ) {
4953 + optionMap[ fieldId ] = {};
4954 + }
4955 +
4956 + optionMap[ fieldId ][ this.value ] = input;
4957 + }
4958 +
4959 + if ( this.getAttribute( 'data-duplicate' ) === 'true' ) {
4960 + this.removeAttribute( 'data-duplicate' );
4961 +
4962 + // we want to use original value if actually still a duplicate
4963 + if ( optionTextAlreadyExists( this ) ) {
4964 + this.setAttribute( 'data-value-on-focus', this.getAttribute( 'data-value-on-load' ) );
4965 + return;
4966 + }
4967 + }
4968 +
4969 + if ( '' !== this.value || frmAdminJs.new_option !== this.getAttribute( 'data-value-on-focus' ) ) {
4970 + this.setAttribute( 'data-value-on-focus', this.value );
4971 + }
4972 + }
4973 +
4974 + /**
4975 + * Returns an object that has the old and new values and labels, when a field choice is changed.
4976 + *
4977 + * @param {HTMLElement} input
4978 + * @returns {Object}
4979 + */
4980 + function getChoiceOldAndNewValues( input ) {
4981 + const { oldValue, oldLabel } = getChoiceOldValueAndLabel( input );
4982 + const { newValue, newLabel } = getChoiceNewValueAndLabel( input );
4983 +
4984 + return { oldValue, oldLabel, newValue, newLabel };
4985 + }
4986 +
4987 + /**
4988 + * Returns an object that has the new value and label, when a field choice is changed.
4989 + *
4990 + * @param {HTMLElement} choiceElement
4991 + * @returns {Object}
4992 + */
4993 + function getChoiceNewValueAndLabel( choiceElement ) {
4994 + const singleOptionContainer = choiceElement.closest( '.frm_single_option' );
4995 +
4996 + let newValue, newLabel;
4997 +
4998 + if ( choiceElement.parentElement.classList.contains( 'frm_single_option' ) ) { // label changed
4999 + newValue = singleOptionContainer.querySelector( '.frm_option_key input[type="text"]' ).value;
5000 + newLabel = choiceElement.value;
5001 + return { newValue, newLabel };
5002 + }
5003 +
5004 + // saved value changed
5005 + newLabel = singleOptionContainer.querySelector( 'input[type="text"]' ).value;
5006 + newValue = choiceElement.value;
5007 + return { newValue, newLabel };
5008 + }
5009 +
5010 + /**
5011 + * Returns an object that has the old value and label, when a field choice is changed.
5012 + *
5013 + * @param {HTMLElement} choiceElement
5014 + * @returns {Object}
5015 + */
5016 + function getChoiceOldValueAndLabel( choiceElement ) {
5017 + const usingSeparateValues = choiceElement.closest( '.frm-single-settings' ).querySelector( '.frm_toggle_sep_values' ).checked;
5018 + const singleOptionContainer = choiceElement.closest( '.frm_single_option' );
5019 +
5020 + let oldValue, oldLabel;
5021 +
5022 + if ( usingSeparateValues ) {
5023 + if ( choiceElement.parentElement.classList.contains( 'frm_single_option' ) ) { // label changed
5024 + oldValue = singleOptionContainer.querySelector( '.frm_option_key input[type="text"]' ).getAttribute( 'data-value-on-focus' );
5025 + oldLabel = choiceElement.getAttribute( 'data-value-on-focus' );
5026 + return { oldValue, oldLabel };
5027 + }
5028 + }
5029 + oldValue = choiceElement.getAttribute( 'data-value-on-focus' );
5030 + oldLabel = singleOptionContainer.querySelector( 'input[type="text"]' ).getAttribute( 'data-value-on-focus' );
5031 +
5032 + return { oldValue, oldLabel };
5033 + }
5034 +
5035 + function onOptionTextBlur() {
5036 + let originalValue,
5037 + fieldId,
5038 + fieldIndex,
5039 + logicId,
5040 + row,
5041 + rowLength,
5042 + rowIndex,
5043 + valueSelect,
5044 + opts,
5045 + fieldIds,
5046 + settingId,
5047 + setting,
5048 + optionMatches,
5049 + option;
5050 +
5051 + const { oldValue, oldLabel, newValue, newLabel } = getChoiceOldAndNewValues( this );
5052 +
5053 + if ( oldValue === newValue && oldLabel === newLabel ) {
5054 + return;
5055 + }
5056 +
5057 + const singleSettingsContainer = this.closest( '.frm-single-settings' );
5058 +
5059 + fieldId = singleSettingsContainer.getAttribute( 'data-fid' );
5060 + originalValue = this.getAttribute( 'data-value-on-load' );
5061 +
5062 + // check if the newValue is already mapped to another option
5063 + // if it is, mark as duplicate and return
5064 + if ( optionTextAlreadyExists( this ) ) {
5065 + this.setAttribute( 'data-duplicate', 'true' );
5066 +
5067 + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) {
5068 + // unmap any other change that may have happened before instead of changing it to something unused
5069 + optionMap[ fieldId ][ originalValue ].value = originalValue;
5070 + }
5071 +
5072 + return;
5073 + }
5074 +
5075 + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) {
5076 + optionMap[ fieldId ][ originalValue ].value = newValue;
5077 + }
5078 +
5079 + fieldIds = [];
5080 + rows = builderPage.querySelectorAll( '.frm_logic_row' );
5081 + rowLength = rows.length;
5082 + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) {
5083 + row = rows[ rowIndex ];
5084 + opts = row.querySelector( '.frm_logic_field_opts' );
5085 +
5086 + if ( opts.value !== fieldId ) {
5087 + continue;
5088 + }
5089 +
5090 + logicId = row.id.split( '_' )[ 2 ];
5091 + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' );
5092 +
5093 + if ( '' === oldValue ) {
5094 + optionMatches = [];
5095 + } else {
5096 + optionMatches = valueSelect.querySelectorAll( 'option[value="' + oldValue + '"]' );
5097 + }
5098 +
5099 + if ( ! optionMatches.length ) {
5100 + optionMatches = valueSelect.querySelectorAll( 'option[value="' + newValue + '"]' );
5101 +
5102 + if ( ! optionMatches.length ) {
5103 + if ( ! singleSettingsContainer.querySelector( '.frm_toggle_sep_values' ).checked ) {
5104 + option = searchSelectByText( valueSelect, oldValue ); // Find conditional logic option with oldValue
5105 + }
5106 +
5107 + if ( ! option ) {
5108 + option = document.createElement( 'option' );
5109 + valueSelect.appendChild( option );
5110 + }
5111 + }
5112 + }
5113 +
5114 + if ( optionMatches.length ) {
5115 + option = optionMatches[ optionMatches.length - 1 ];
5116 + }
5117 +
5118 + option.setAttribute( 'value', newValue );
5119 + option.textContent = newLabel;
5120 +
5121 + if ( fieldIds.indexOf( logicId ) === -1 ) {
5122 + fieldIds.push( logicId );
5123 + }
5124 + }
5125 +
5126 + for ( fieldIndex in fieldIds ) {
5127 + settingId = fieldIds[ fieldIndex ];
5128 + setting = document.getElementById( 'frm-single-settings-' + settingId );
5129 + moveFieldSettings( setting );
5130 + }
5131 + }
5132 +
5133 + /**
5134 + * Returns an option element that matches a string with its text content.
5135 + *
5136 + * @param {HTMLElement} selectElement
5137 + * @param {string} searchText
5138 + * @returns {HTMLElement|null}
5139 + */
5140 + function searchSelectByText( selectElement, searchText ) {
5141 + const options = selectElement.options;
5142 +
5143 + for ( let i = 0; i < options.length; i++ ) {
5144 + const option = options[i];
5145 + if ( searchText === option.textContent ) {
5146 + return option;
5147 + }
5148 + }
5149 +
5150 + return null;
5151 + }
5152 +
5153 + function updateGetValueFieldSelection() {
5154 + /*jshint validthis:true */
5155 + const fieldID = this.id.replace( 'get_values_form_', '' );
5156 + const fieldSelect = document.getElementById( 'get_values_field_' + fieldID );
5157 + const fieldType = this.getAttribute( 'data-fieldtype' );
5158 +
5159 + if ( this.value === '' ) {
5160 + fieldSelect.options.length = 1;
5161 + } else {
5162 + const formID = this.value;
5163 + jQuery.ajax({
5164 + type: 'POST', url: ajaxurl,
5165 + data: {
5166 + action: 'frm_get_options_for_get_values_field',
5167 + form_id: formID,
5168 + field_type: fieldType,
5169 + nonce: frmGlobal.nonce
5170 + },
5171 + success: function( fields ) {
5172 + fieldSelect.innerHTML = fields;
5173 + }
5174 + });
5175 + }
5176 + }
5177 +
5178 + // Clear the Watch Fields option when Lookup field switches to "Text" option
5179 + function maybeClearWatchFields() {
5180 + /*jshint validthis:true */
5181 + let link, lookupBlock,
5182 + fieldID = this.name.replace( 'field_options[data_type_', '' ).replace( ']', '' );
5183 +
5184 + link = document.getElementById( 'frm_add_watch_lookup_link_' + fieldID );
5185 + if ( ! link ) {
5186 + return;
5187 + }
5188 + link = link.parentNode;
5189 +
5190 + if ( this.value === 'text' ) {
5191 + lookupBlock = document.getElementById( 'frm_watch_lookup_block_' + fieldID );
5192 + if ( lookupBlock !== null ) {
5193 + // Clear and hide the Watch Fields option
5194 + lookupBlock.innerHTML = '';
5195 + link.classList.add( 'frm_hidden' );
5196 +
5197 + // Hide the Watch Fields row
5198 + link.previousElementSibling.style.display = 'none';
5199 + link.previousElementSibling.previousElementSibling.style.display = 'none';
5200 + link.previousElementSibling.previousElementSibling.previousElementSibling.style.display = 'none';
5201 + }
5202 + } else {
5203 + // Show the Watch Fields option
5204 + link.classList.remove( 'frm_hidden' );
5205 + }
5206 +
5207 + toggleMultiSelect( fieldID, this.value );
5208 + }
5209 +
5210 + // Number the pages and hide/show the first page as needed.
5211 + function renumberPageBreaks() {
5212 + let i, containerClass,
5213 + pages = document.getElementsByClassName( 'frm-page-num' );
5214 +
5215 + if ( pages.length > 1 ) {
5216 + document.getElementById( 'frm-fake-page' ).style.display = 'block';
5217 + for ( i = 0; i < pages.length; i++ ) {
5218 + containerClass = pages[i].parentNode.parentNode.parentNode.classList;
5219 + if ( i === 1 ) {
5220 + // Hide previous button on page 1
5221 + containerClass.add( 'frm-first-page' );
5222 + } else {
5223 + containerClass.remove( 'frm-first-page' );
5224 + }
5225 + pages[i].textContent = ( i + 1 );
5226 + }
5227 + } else {
5228 + document.getElementById( 'frm-fake-page' ).style.display = 'none';
5229 + }
5230 +
5231 + wp.hooks.doAction( 'frm_renumber_page_breaks', pages );
5232 + }
5233 +
5234 + // The fake field works differently than real fields.
5235 + function maybeCollapsePage() {
5236 + /*jshint validthis:true */
5237 + const field = jQuery( this ).closest( '.frm_field_box[data-ftype=break]' );
5238 + if ( field.length ) {
5239 + toggleCollapsePage( field );
5240 + } else {
5241 + toggleCollapseFakePage();
5242 + }
5243 + }
5244 +
5245 + // Find all fields in a page and hide/show them
5246 + function toggleCollapsePage( field ) {
5247 + const toCollapse = getAllFieldsForPage( field.get( 0 ).parentNode.closest( 'li.frm_field_box' ).nextElementSibling );
5248 + togglePage( field, toCollapse );
5249 + }
5250 +
5251 + function toggleCollapseFakePage() {
5252 + const topLevel = document.getElementById( 'frm-fake-page' ),
5253 + firstField = document.getElementById( 'frm-show-fields' ).firstElementChild,
5254 + toCollapse = getAllFieldsForPage( firstField );
5255 +
5256 + if ( firstField.getAttribute( 'data-ftype' ) === 'break' ) {
5257 + // Don't collapse if the first field is a page break.
5258 + return;
5259 + }
5260 +
5261 + togglePage( jQuery( topLevel ), toCollapse );
5262 + }
5263 +
5264 + function getAllFieldsForPage( firstWrapper ) {
5265 + let $fieldsForPage, currentWrapper;
5266 +
5267 + $fieldsForPage = jQuery();
5268 +
5269 + if ( null === firstWrapper ) {
5270 + return $fieldsForPage;
5271 + }
5272 +
5273 + currentWrapper = firstWrapper;
5274 +
5275 + do {
5276 + if ( null !== currentWrapper.querySelector( '.edit_field_type_break' ) ) {
5277 + break;
5278 + }
5279 + $fieldsForPage = $fieldsForPage.add( jQuery( currentWrapper ) );
5280 + currentWrapper = currentWrapper.nextElementSibling;
5281 + } while ( null !== currentWrapper );
5282 +
5283 + return $fieldsForPage;
5284 + }
5285 +
5286 + function togglePage( field, toCollapse ) {
5287 + let i,
5288 + fieldCount = toCollapse.length,
5289 + slide = Math.min( fieldCount, 3 );
5290 +
5291 + if ( field.hasClass( 'frm-page-collapsed' ) ) {
5292 + field.removeClass( 'frm-page-collapsed' );
5293 + toCollapse.removeClass( 'frm-is-collapsed' );
5294 + for ( i = 0; i < slide; i++ ) {
5295 + if ( i === slide - 1 ) {
5296 + jQuery( toCollapse[ i ]).slideDown( 150, function() {
5297 + toCollapse.show();
5298 + });
5299 + } else {
5300 + jQuery( toCollapse[ i ]).slideDown( 150 );
5301 + }
5302 + }
5303 + } else {
5304 + field.addClass( 'frm-page-collapsed' );
5305 + toCollapse.addClass( 'frm-is-collapsed' );
5306 + for ( i = 0; i < slide; i++ ) {
5307 + if ( i === slide - 1 ) {
5308 + jQuery( toCollapse[ i ]).slideUp( 150, function() {
5309 + toCollapse.css( 'cssText', 'display:none !important;' );
5310 + });
5311 + } else {
5312 + jQuery( toCollapse[ i ]).slideUp( 150 );
5313 + }
5314 + }
5315 + }
5316 + }
5317 +
5318 + function maybeCollapseSection() {
5319 + /*jshint validthis:true */
5320 + const parentCont = this.parentNode.parentNode.parentNode.parentNode;
5321 +
5322 + parentCont.classList.toggle( 'frm-section-collapsed' );
5323 + }
5324 +
5325 + function maybeCollapseSettings() {
5326 + /*jshint validthis:true */
5327 + this.classList.toggle( 'frm-collapsed' );
5328 +
5329 + // Toggles the "aria-expanded" attribute
5330 + const expanded = this.getAttribute( 'aria-expanded' ) === 'true' || false;
5331 + this.setAttribute( 'aria-expanded', ! expanded );
5332 + }
5333 +
5334 + function clickLabel() {
5335 + if ( ! this.id ) {
5336 + return;
5337 + }
5338 +
5339 + /*jshint validthis:true */
5340 + let setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0],
5341 + fieldId = this.id.replace( 'field_label_', '' ),
5342 + fieldType = document.getElementById( 'field_options_type_' + fieldId ),
5343 + fieldTypeName = fieldType.value;
5344 +
5345 + if ( typeof setting !== 'undefined' ) {
5346 + if ( fieldType.tagName === 'SELECT' ) {
5347 + fieldTypeName = fieldType.options[ fieldType.selectedIndex ].text.toLowerCase();
5348 + } else {
5349 + fieldTypeName = fieldTypeName.replace( '_', ' ' );
5350 + }
5351 +
5352 + fieldTypeName = normalizeFieldName( fieldTypeName );
5353 +
5354 + setTimeout( function() {
5355 + if ( setting.value.toLowerCase() === fieldTypeName ) {
5356 + setting.select();
5357 + } else {
5358 + setting.focus();
5359 + }
5360 + }, 50 );
5361 + }
5362 + }
5363 +
5364 + function clickDescription() {
5365 + /*jshint validthis:true */
5366 + const setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0];
5367 + if ( typeof setting !== 'undefined' ) {
5368 + setTimeout( function() {
5369 + setting.focus();
5370 + autoExpandSettings( setting );
5371 + }, 50 );
5372 + }
5373 + }
5374 +
5375 + function autoExpandSettings( setting ) {
5376 + const inSection = setting.closest( '.frm-collapse-me' );
5377 + if ( inSection !== null ) {
5378 + inSection.previousElementSibling.classList.remove( 'frm-collapsed' );
5379 + }
5380 + }
5381 +
5382 + function normalizeFieldName( fieldTypeName ) {
5383 + if ( fieldTypeName === 'divider' ) {
5384 + fieldTypeName = 'section';
5385 + } else if ( fieldTypeName === 'range' ) {
5386 + fieldTypeName = 'slider';
5387 + } else if ( fieldTypeName === 'data' ) {
5388 + fieldTypeName = 'dynamic';
5389 + } else if ( fieldTypeName === 'form' ) {
5390 + fieldTypeName = 'embed form';
5391 + }
5392 + return fieldTypeName;
5393 + }
5394 +
5395 + function clickVis( e ) {
5396 + /*jshint validthis:true */
5397 + let currentClass, originalList;
5398 +
5399 + currentClass = e.target.classList;
5400 +
5401 + if ( currentClass.contains( 'frm-collapse-page' ) || currentClass.contains( 'frm-sub-label' ) || e.target.closest( '.dropdown' ) !== null ) {
5402 + return;
5403 + }
5404 +
5405 + if ( this.closest( '.start_divider' ) !== null ) {
5406 + e.stopPropagation();
5407 + }
5408 +
5409 + if ( this.classList.contains( 'edit_field_type_divider' ) ) {
5410 + originalList = e.originalEvent.target.closest( 'ul.frm_sorting' );
5411 + if ( null !== originalList ) {
5412 + // prevent section click if clicking a field group within a section.
5413 + if ( originalList.classList.contains( 'edit_field_type_divider' ) || originalList.parentNode.parentNode.classList.contains( 'start_divider' ) ) {
5414 + return;
5415 + }
5416 + }
5417 + }
5418 +
5419 + clickAction( this );
5420 + }
5421 +
5422 + /**
5423 + * Update the phone format input based on the selected phone type.
5424 + *
5425 + * This function is triggered when a phone type is selected.
5426 + * If the selected type is 'custom' and the current format is 'international',
5427 + * the format input value is cleared to allow for custom input.
5428 + *
5429 + * @since 6.9
5430 + *
5431 + * @param {Event} event The event object from the phone type selection.
5432 + * @return {void}
5433 + */
5434 + function maybeUpdatePhoneFormatInput( event ) {
5435 + const phoneType = event.target;
5436 + if ( 'custom' === phoneType.value ) {
5437 + const formatInput = phoneType.parentElement.nextElementSibling.querySelector( '.frm_format_opt' );
5438 + if ( 'international' === formatInput.value ) {
5439 + formatInput.setAttribute( 'value', '' );
5440 + }
5441 + }
5442 + }
5443 +
5444 + /**
5445 + * Open Advanced settings on double click.
5446 + */
5447 + function openAdvanced() {
5448 + const fieldId = this.getAttribute( 'data-fid' );
5449 + autoExpandSettings( document.getElementById( 'field_options_field_key_' + fieldId ) );
5450 + }
5451 +
5452 + function toggleRepeatButtons() {
5453 + /*jshint validthis:true */
5454 + const $thisField = jQuery( this ).closest( '.frm_field_box' );
5455 + $thisField.find( '.repeat_icon_links' ).removeClass( 'repeat_format repeat_formatboth repeat_formattext' ).addClass( 'repeat_format' + this.value );
5456 + if ( this.value === 'text' || this.value === 'both' ) {
5457 + $thisField.find( '.frm_repeat_text' ).show();
5458 + $thisField.find( '.repeat_icon_links a' ).addClass( 'frm_button' );
5459 + } else {
5460 + $thisField.find( '.frm_repeat_text' ).hide();
5461 + $thisField.find( '.repeat_icon_links a' ).removeClass( 'frm_button' );
5462 + }
5463 + }
5464 +
5465 + function checkRepeatLimit() {
5466 + /*jshint validthis:true */
5467 + const val = this.value;
5468 + if ( val !== '' && ( val < 2 || val > 200 ) ) {
5469 + infoModal( frmAdminJs.repeat_limit_min );
5470 + this.value = '';
5471 + }
5472 + }
5473 +
5474 + function checkCheckboxSelectionsLimit() {
5475 + /*jshint validthis:true */
5476 + const val = this.value;
5477 + if ( val !== '' && ( val < 1 || val > 200 ) ) {
5478 + infoModal( frmAdminJs.checkbox_limit );
5479 + this.value = '';
5480 + }
5481 + }
5482 +
5483 + function updateRepeatText( obj, addRemove ) {
5484 + const $thisField = jQuery( obj ).closest( '.frm_field_box' );
5485 + $thisField.find( '.frm_' + addRemove + '_form_row .frm_repeat_label' ).text( obj.value );
5486 + }
5487 +
5488 + function fieldsInSection( id ) {
5489 + const children = [];
5490 + jQuery( document.getElementById( 'frm_field_id_' + id ) ).find( 'li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)' ).each( function() {
5491 + children.push( jQuery( this ).data( 'fid' ) );
5492 + });
5493 + return children;
5494 + }
5495 +
5496 + function toggleFormTax() {
5497 + /*jshint validthis:true */
5498 + const id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
5499 + const val = this.value;
5500 + const $showFields = document.getElementById( 'frm_show_selected_fields_' + id );
5501 + const $showForms = document.getElementById( 'frm_show_selected_forms_' + id );
5502 +
5503 + jQuery( $showForms ).find( 'select' ).val( '' );
5504 + if ( val === 'form' ) {
5505 + $showForms.style.display = 'inline';
5506 + empty( $showFields );
5507 + } else {
5508 + $showFields.style.display = 'none';
5509 + $showForms.style.display = 'none';
5510 + getTaxOrFieldSelection( val, id );
5511 + }
5512 +
5513 + }
5514 +
5515 + function resetOptOnChange() {
5516 + /*jshint validthis:true */
5517 + let field, thisOpt;
5518 +
5519 + field = getFieldKeyFromOpt( this );
5520 + if ( ! field ) {
5521 + return;
5522 + }
5523 +
5524 + thisOpt = jQuery( this ).closest( '.frm_single_option' );
5525 +
5526 + resetSingleOpt( field.fieldId, field.fieldKey, thisOpt );
5527 + }
5528 +
5529 + function getFieldKeyFromOpt( object ) {
5530 + let allOpts, fieldId, fieldKey;
5531 +
5532 + allOpts = jQuery( object ).closest( '.frm_sortable_field_opts' );
5533 + if ( ! allOpts.length ) {
5534 + return false;
5535 + }
5536 +
5537 + fieldId = allOpts.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_opts', '' );
5538 + fieldKey = allOpts.data( 'key' );
5539 +
5540 + return {
5541 + fieldId: fieldId,
5542 + fieldKey: fieldKey
5543 + };
5544 + }
5545 +
5546 + function resetSingleOpt( fieldId, fieldKey, thisOpt ) {
5547 + let saved, text, defaultVal, previewInput, labelForDisplay, optContainer,
5548 + optKey = thisOpt.data( 'optkey' ),
5549 + separateValues = usingSeparateValues( fieldId ),
5550 + single = jQuery( 'label[for="field_' + fieldKey + '-' + optKey + '"]' ),
5551 + baseName = 'field_options[options_' + fieldId + '][' + optKey + ']',
5552 + label = jQuery( 'input[name="' + baseName + '[label]"]' );
5553 +
5554 + if ( single.length < 1 ) {
5555 + resetDisplayedOpts( fieldId );
5556 +
5557 + // Set the default value.
5558 + defaultVal = thisOpt.find( 'input[name^="default_value_"]' );
5559 + if ( defaultVal.is( ':checked' ) && label.length > 0 ) {
5560 + jQuery( 'select[name^="item_meta[' + fieldId + ']"]' ).val( label.val() );
5561 + }
5562 + return;
5563 + }
5564 +
5565 + previewInput = single.children( 'input' );
5566 +
5567 + if ( label.length < 1 ) {
5568 + // Check for other label.
5569 + label = jQuery( 'input[name="' + baseName + '"]' );
5570 + saved = label.val();
5571 + } else if ( separateValues ) {
5572 + saved = jQuery( 'input[name="' + baseName + '[value]"]' ).val();
5573 + } else {
5574 + saved = label.val();
5575 + }
5576 +
5577 + if ( label.length < 1 ) {
5578 + return;
5579 + }
5580 +
5581 + // Set the displayed value.
5582 + text = single[0].childNodes;
5583 +
5584 + if ( imagesAsOptions( fieldId ) ) {
5585 + labelForDisplay = getImageDisplayValue( thisOpt, fieldId, label );
5586 + optContainer = single.find( '.frm_image_option_container' );
5587 +
5588 + if ( optContainer.length > 0 ) {
5589 + optContainer.replaceWith( labelForDisplay );
5590 + } else {
5591 + text[ text.length - 1 ].nodeValue = '';
5592 + single.append( labelForDisplay );
5593 + }
5594 + } else {
5595 + let firstInputIndex = false;
5596 + text.forEach( ( node, index ) => {
5597 + if ( firstInputIndex === false ) {
5598 + if ( node.tagName === 'INPUT' ) {
5599 + firstInputIndex = index;
5600 + }
5601 + } else if ( index === firstInputIndex + 1 ) {
5602 + let nodeValue = '';
5603 +
5604 + if ( buttonsAsOptions( fieldId ) ) {
5605 + nodeValue = div({ className: 'frm_label_button_container', text: ' ' + label.val() });
5606 + single[0].replaceChild( nodeValue, node );
5607 + } else {
5608 + node.nodeValue = ' ' + label.val();
5609 + }
5610 + } else {
5611 + single[0].removeChild( node );
5612 + }
5613 + });
5614 + }
5615 +
5616 + // Set saved value.
5617 + previewInput.val( saved );
5618 +
5619 + // Set the default value.
5620 + defaultVal = thisOpt.find( 'input[name^="default_value_"]' );
5621 + previewInput.prop( 'checked', defaultVal.is( ':checked' ) ? true : false );
5622 + }
5623 +
5624 + function buttonsAsOptions( fieldId ) {
5625 + const fields = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' );
5626 + const result = Array.from( fields ).find( field => field.checked && ( 'buttons' === field.value ) );
5627 +
5628 + return typeof result !== 'undefined';
5629 + }
5630 +
5631 + /**
5632 + * Set the displayed value for an image option.
5633 + */
5634 + function getImageDisplayValue( thisOpt, fieldId, label ) {
5635 + let image, imageUrl, showLabelWithImage, fieldType;
5636 +
5637 + image = thisOpt.find( 'img' );
5638 + if ( image ) {
5639 + imageUrl = image.attr( 'src' );
5640 + }
5641 +
5642 + showLabelWithImage = showingLabelWithImage( fieldId );
5643 + fieldType = radioOrCheckbox( fieldId );
5644 + return getImageLabel( label.val(), showLabelWithImage, imageUrl, fieldType );
5645 + }
5646 +
5647 + function getImageOptionSize( fieldId ) {
5648 + let val,
5649 + field = document.getElementById( 'field_options_image_size_' + fieldId ),
5650 + size = '';
5651 +
5652 + if ( field !== null ) {
5653 + val = field.value;
5654 + if ( val !== '' ) {
5655 + size = val;
5656 + }
5657 + }
5658 +
5659 + return size;
5660 + }
5661 +
5662 + function resetDisplayedOpts( fieldId ) {
5663 + let i, opts, type, placeholder, fieldInfo,
5664 + input = jQuery( '[name^="item_meta[' + fieldId + ']"]' );
5665 +
5666 + if ( input.length < 1 ) {
5667 + return;
5668 + }
5669 +
5670 + if ( input.is( 'select' ) ) {
5671 + placeholder = document.getElementById( 'frm_placeholder_' + fieldId );
5672 + if ( placeholder !== null && placeholder.value === '' ) {
5673 + fillDropdownOpts( input[0], { sourceID: fieldId });
5674 + } else {
5675 + fillDropdownOpts( input[0], {
5676 + sourceID: fieldId,
5677 + placeholder: placeholder.value
5678 + });
5679 + }
5680 + } else {
5681 + opts = getMultipleOpts( fieldId );
5682 + jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ).html( '' );
5683 + fieldInfo = getFieldKeyFromOpt( jQuery( '#frm_delete_field_' + fieldId + '-000_container' ) );
5684 +
5685 + const container = jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ),
5686 + hasImageOptions = imagesAsOptions( fieldId ),
5687 + imageSize = hasImageOptions ? getImageOptionSize( fieldId ) : '',
5688 + imageOptionClass = hasImageOptions ? ( 'frm_image_option frm_image_' + imageSize + ' ' ) : '',
5689 + isProduct = isProductField( fieldId );
5690 +
5691 + type = ( 'hidden' === input.attr( 'type' ) ? input.data( 'field-type' ) : input.attr( 'type' ) );
5692 + for ( i = 0; i < opts.length; i++ ) {
5693 + container.append( addRadioCheckboxOpt( type, opts[ i ], fieldId, fieldInfo.fieldKey, isProduct, imageOptionClass ) );
5694 + }
5695 + }
5696 +
5697 + adjustConditionalLogicOptionOrders( fieldId );
5698 + }
5699 +
5700 + /**
5701 + * Returns an object that has a value and label for new conditional logic option, for a given option value.
5702 + *
5703 + * @param {Number} fieldId
5704 + * @param {string} expectedOption
5705 + * @returns {Object}
5706 + */
5707 + function getNewConditionalLogicOption( fieldId, expectedOption ) {
5708 + const optionsContainer = document.getElementById( 'frm_field_' + fieldId + '_opts' );
5709 +
5710 + const expectedOptionInput = optionsContainer.querySelector( 'input[value="' + expectedOption + '"]' );
5711 +
5712 + if ( expectedOptionInput ) {
5713 + return getChoiceNewValueAndLabel( expectedOptionInput );
5714 + }
5715 +
5716 + return { newValue: expectedOption, newLabel: expectedOption };
5717 + }
5718 +
5719 + function adjustConditionalLogicOptionOrders( fieldId, type ) {
5720 + let row, opts, logicId, valueSelect, optionLength, optionIndex, expectedOption, optionMatch, fieldOptions,
5721 + rows = builderPage.querySelectorAll( '.frm_logic_row' ),
5722 + rowLength = rows.length;
5723 +
5724 + fieldOptions = wp.hooks.applyFilters( 'frm_conditional_logic_field_options', getFieldOptions( fieldId ), { type, fieldId });
5725 + optionLength = fieldOptions.length;
5726 +
5727 + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) {
5728 + row = rows[ rowIndex ];
5729 + opts = row.querySelector( '.frm_logic_field_opts' );
5730 +
5731 + if ( opts.value != fieldId ) {
5732 + continue;
5733 + }
5734 +
5735 + logicId = row.id.split( '_' )[ 2 ];
5736 + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' );
5737 +
5738 + for ( optionIndex = optionLength - 1; optionIndex >= 0; optionIndex-- ) {
5739 + expectedOption = fieldOptions[ optionIndex ];
5740 + let expectedOptionValue = document.getElementById( 'frm_field_' + fieldId + '_opts' ).querySelector( '.frm_option_key input[type="text"]' )?.value;
5741 + if ( ! expectedOptionValue ) {
5742 + expectedOptionValue = expectedOption;
5743 + }
5744 +
5745 + optionMatch = valueSelect.querySelector( 'option[value="' + expectedOptionValue + '"]' );
5746 +
5747 + const { newValue, newLabel } = getNewConditionalLogicOption( fieldId, expectedOption );
5748 +
5749 + const fieldChoices = document.querySelectorAll( '#frm_field_' + fieldId + '_opts input[data-value-on-focus]' );
5750 + const expectedChoiceEl = Array.from( fieldChoices ).find( element => element.value === expectedOption );
5751 + if ( expectedChoiceEl ) {
5752 + const oldValue = expectedChoiceEl.dataset.valueOnFocus;
5753 + const hasMatch = oldValue && valueSelect.querySelector( 'option[value="' + oldValue + '"]' );
5754 + if ( hasMatch ) {
5755 + continue;
5756 + }
5757 + }
5758 + prependValueSelectWithOptionMatch( valueSelect, optionMatch, newValue, newLabel );
5759 + }
5760 +
5761 + optionMatch = valueSelect.querySelector( 'option[value=""]' );
5762 + if ( optionMatch !== null ) {
5763 + valueSelect.prepend( optionMatch );
5764 + }
5765 + }
5766 + }
5767 +
5768 + function prependValueSelectWithOptionMatch( valueSelect, optionMatch, newValue, newLabel ) {
5769 + if ( optionMatch === null && ! valueSelect.querySelector( 'option[value="' + newValue + '"]' )) {
5770 + optionMatch = frmDom.tag( 'option', { text: newLabel });
5771 + optionMatch.value = newValue;
5772 + }
5773 +
5774 + valueSelect.prepend( optionMatch );
5775 + }
5776 +
5777 + function getFieldOptions( fieldId ) {
5778 + let index, input, li, listItems, optsContainer, length,
5779 + options = [];
5780 + optsContainer = document.getElementById( 'frm_field_' + fieldId + '_opts' );
5781 +
5782 + if ( ! optsContainer ) {
5783 + return options;
5784 + }
5785 + listItems = optsContainer.querySelectorAll( '.frm_single_option' );
5786 + length = listItems.length;
5787 +
5788 + for ( index = 0; index < length; index++ ) {
5789 + li = listItems[ index ];
5790 +
5791 + if ( li.classList.contains( 'frm_hidden' ) ) {
5792 + continue;
5793 + }
5794 +
5795 + input = li.querySelector( '.field_' + fieldId + '_option' );
5796 + options.push( input.value );
5797 + }
5798 + return options;
5799 + }
5800 +
5801 + function addRadioCheckboxOpt( type, opt, fieldId, fieldKey, isProduct, classes ) {
5802 + let other,
5803 + single = '',
5804 + isOther = opt.key.indexOf( 'other' ) !== -1,
5805 + id = 'field_' + fieldKey + '-' + opt.key,
5806 + inputType = type === 'scale' ? 'radio' : type;
5807 +
5808 + 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="" />';
5809 +
5810 + this.getSingle = function() {
5811 +
5812 + /**
5813 + * Get single option template.
5814 + * @param {Object} option Object containing the option data.
5815 + * @param {string} type The field type.
5816 + * @param {string} fieldId The field id.
5817 + * @param {string} classes The option clasnames.
5818 + * @param {string} id The input id attribute.
5819 + */
5820 + single = wp.hooks.applyFilters( 'frm_admin.build_single_option_template', single, { opt, type, fieldId, classes, id });
5821 +
5822 + if ( '' !== single ) {
5823 + return single;
5824 + }
5825 +
5826 + return '<div class="frm_' + type + ' ' + type + ' ' + classes + '" id="frm_' + type + '_' + fieldId + '-' + opt.key + '"><label for="' + id +
5827 + '"><input type="' + inputType +
5828 + '" name="item_meta[' + fieldId + ']' + ( type === 'checkbox' ? '[]' : '' ) +
5829 + '" value="' + purifyHtml( opt.saved ) + '" id="' + id + '"' + ( isProduct ? ' data-price="' + opt.price + '"' : '' ) + ( opt.checked ? ' checked="checked"' : '' ) + '> ' + purifyHtml( opt.label ) + '</label>' +
5830 + ( isOther ? other : '' ) +
5831 + '</div>';
5832 + };
5833 +
5834 + return this.getSingle();
5835 + }
5836 +
5837 + function fillDropdownOpts( field, atts ) {
5838 + if ( field === null ) {
5839 + return;
5840 + }
5841 + const sourceID = atts.sourceID,
5842 + placeholder = atts.placeholder,
5843 + isProduct = isProductField( sourceID ),
5844 + showOther = atts.other;
5845 +
5846 + removeDropdownOpts( field );
5847 + let opts = getMultipleOpts( sourceID ),
5848 + hasPlaceholder = ( typeof placeholder !== 'undefined' );
5849 +
5850 + for ( let i = 0; i < opts.length; i++ ) {
5851 + let label = opts[ i ].label,
5852 + isOther = opts[ i ].key.indexOf( 'other' ) !== -1;
5853 +
5854 + if ( hasPlaceholder && label !== '' ) {
5855 + addBlankSelectOption( field, placeholder );
5856 + } else if ( hasPlaceholder ) {
5857 + label = placeholder;
5858 + }
5859 + hasPlaceholder = false;
5860 +
5861 + if ( ! isOther || showOther ) {
5862 + const opt = document.createElement( 'option' );
5863 + opt.value = opts[ i ].saved;
5864 + opt.innerHTML = purifyHtml( label );
5865 +
5866 + if ( isProduct ) {
5867 + opt.setAttribute( 'data-price', opts[ i ].price );
5868 + }
5869 +
5870 + field.appendChild( opt );
5871 + }
5872 + }
5873 + }
5874 +
5875 + function addBlankSelectOption( field, placeholder ) {
5876 + const opt = document.createElement( 'option' ),
5877 + firstChild = field.firstChild;
5878 +
5879 + opt.value = '';
5880 + opt.innerHTML = placeholder;
5881 + if ( firstChild !== null ) {
5882 + field.insertBefore( opt, firstChild );
5883 + field.selectedIndex = 0;
5884 + } else {
5885 + field.appendChild( opt );
5886 + }
5887 + }
5888 +
5889 + function getMultipleOpts( fieldId ) {
5890 + let i, saved, labelName, label, key, optObj,
5891 + fieldType,
5892 + checked = false,
5893 + opts = [],
5894 + imageUrl = '';
5895 +
5896 + const optVals = jQuery( 'input[name^="field_options[options_' + fieldId + ']"]' );
5897 + const isProduct = isProductField( fieldId );
5898 + const showLabelWithImage = showingLabelWithImage( fieldId );
5899 + const hasImageOptions = imagesAsOptions( fieldId );
5900 + const separateValues = usingSeparateValues( fieldId );
5901 +
5902 + for ( i = 0; i < optVals.length; i++ ) {
5903 + 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 ) {
5904 + continue;
5905 + }
5906 +
5907 + saved = optVals[ i ].value;
5908 + label = saved;
5909 + key = optVals[ i ].name.replace( 'field_options[options_' + fieldId + '][', '' ).replace( '[label]', '' ).replace( ']', '' );
5910 +
5911 + if ( separateValues ) {
5912 + labelName = optVals[ i ].name.replace( '[label]', '[value]' );
5913 + saved = jQuery( 'input[name="' + labelName + '"]' ).val();
5914 + }
5915 +
5916 + if ( hasImageOptions ) {
5917 + imageUrl = getImageUrlFromInput( optVals[i]);
5918 + fieldType = radioOrCheckbox( fieldId );
5919 + label = getImageLabel( label, showLabelWithImage, imageUrl, fieldType );
5920 + }
5921 +
5922 + /**
5923 + * @since 5.0.04
5924 + */
5925 + label = frmAdminBuild.hooks.applyFilters( 'frm_choice_field_label', label, fieldId, optVals[ i ], hasImageOptions );
5926 +
5927 + checked = getChecked( optVals[ i ].id );
5928 +
5929 + optObj = {
5930 + saved: saved,
5931 + label: label,
5932 + checked: checked,
5933 + key: key
5934 + };
5935 +
5936 + if ( isProduct ) {
5937 + labelName = optVals[ i ].name.replace( '[label]', '[price]' );
5938 + optObj.price = jQuery( 'input[name="' + labelName + '"]' ).val();
5939 + }
5940 +
5941 + opts.push( optObj );
5942 + }
5943 +
5944 + return opts;
5945 + }
5946 +
5947 + function radioOrCheckbox( fieldId ) {
5948 + const settings = document.getElementById( 'frm-single-settings-' + fieldId );
5949 + if ( settings === null ) {
5950 + return 'radio';
5951 + }
5952 +
5953 + return settings.classList.contains( 'frm-type-checkbox' ) ? 'checkbox' : 'radio';
5954 + }
5955 +
5956 + function getImageUrlFromInput( optVal ) {
5957 + let img,
5958 + wrapper = jQuery( optVal ).siblings( '.frm_image_preview_wrapper' );
5959 +
5960 + if ( ! wrapper.length ) {
5961 + return '';
5962 + }
5963 +
5964 + img = wrapper.find( 'img' );
5965 + if ( ! img.length ) {
5966 + return '';
5967 + }
5968 +
5969 + return img.attr( 'src' );
5970 + }
5971 +
5972 + function purifyHtml( html ) {
5973 + if ( html instanceof Element || html instanceof Document ) {
5974 + html = html.outerHTML;
5975 + }
5976 +
5977 + const clean = jQuery.parseHTML( html ).reduce(
5978 + ( total, currentNode ) => {
5979 + const cleanNode = frmDom.cleanNode( currentNode );
5980 +
5981 + if ( '#text' === cleanNode.nodeName ) {
5982 + return total += cleanNode.textContent;
5983 + }
5984 +
5985 + return total + cleanNode.outerHTML;
5986 + },
5987 + ''
5988 + );
5989 +
5990 + if ( clean !== html ) {
5991 + // Clean it until nothing changes, in case the stripped result is now unsafe.
5992 + return purifyHtml( clean );
5993 + }
5994 +
5995 + return clean;
5996 + }
5997 +
5998 + function getImageLabel( label, showLabelWithImage, imageUrl, fieldType ) {
5999 + let imageLabelClass,
6000 + originalLabel = label,
6001 + shape = fieldType === 'checkbox' ? 'square' : 'circle',
6002 + labelImage,
6003 + labelNode,
6004 + imageLabel;
6005 +
6006 + originalLabel = purifyHtml( originalLabel );
6007 +
6008 + if ( imageUrl ) {
6009 + labelImage = img({ src: imageUrl, alt: originalLabel });
6010 + } else {
6011 + labelImage = div({ className: 'frm_empty_url' });
6012 + labelImage.innerHTML = frmAdminJs.image_placeholder_icon;
6013 + }
6014 +
6015 + imageLabelClass = showLabelWithImage ? ' frm_label_with_image' : '';
6016 +
6017 + imageLabel = tag( 'span', { className: 'frm_text_label_for_image_inner' });
6018 +
6019 + imageLabel.innerHTML = originalLabel;
6020 + labelNode = tag(
6021 + 'span',
6022 + {
6023 + className: 'frm_image_option_container' + imageLabelClass,
6024 + children: [
6025 + labelImage,
6026 + tag( 'span', { className: 'frm_text_label_for_image', child: imageLabel })
6027 + ]
6028 + }
6029 + );
6030 +
6031 + return labelNode;
6032 + }
6033 +
6034 + function getChecked( id ) {
6035 + field = jQuery( '#' + id );
6036 +
6037 + if ( field.length === 0 ) {
6038 + return false;
6039 + }
6040 +
6041 + checkbox = field.siblings( 'input[type=checkbox]' );
6042 +
6043 + return checkbox.length && checkbox.prop( 'checked' );
6044 + }
6045 +
6046 + function removeDropdownOpts( field ) {
6047 + let i;
6048 + if ( typeof field.options === 'undefined' ) {
6049 + return;
6050 + }
6051 +
6052 + for ( i = field.options.length - 1; i >= 0; i-- ) {
6053 + field.remove( i );
6054 + }
6055 + }
6056 +
6057 + /**
6058 + * Is the box checked to use separate values?
6059 + */
6060 + function usingSeparateValues( fieldId ) {
6061 + return isChecked( 'separate_value_' + fieldId );
6062 + }
6063 +
6064 + /**
6065 + * Is the box checked to use images as options?
6066 + */
6067 + function imagesAsOptions( fieldId ) {
6068 + let checked = false,
6069 + field = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' );
6070 +
6071 + for ( let i = 0; i < field.length; i++ ) {
6072 + if ( field[ i ].checked ) {
6073 + checked = '0' !== field[ i ].value;
6074 + }
6075 + }
6076 +
6077 + /**
6078 + * @since 5.0.04
6079 + */
6080 + return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_images_as_options', checked, fieldId );
6081 + }
6082 +
6083 + function showingLabelWithImage( fieldId ) {
6084 + const isShowing = ! isChecked( 'hide_image_text_' + fieldId );
6085 +
6086 + /**
6087 + * @since 5.0.04
6088 + */
6089 + return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_showing_label_with_image', isShowing, fieldId );
6090 + }
6091 +
6092 + function isChecked( id ) {
6093 + const field = document.getElementById( id );
6094 + if ( field === null ) {
6095 + return false;
6096 + }
6097 + return field.checked;
6098 + }
6099 +
6100 + function checkUniqueOpt( targetInput ) {
6101 + const settingsContainer = targetInput.closest( '.frm-single-settings' );
6102 + const fieldId = settingsContainer.getAttribute( 'data-fid' );
6103 + const areValuesSeparate = settingsContainer.querySelector( '[name="field_options[separate_value_' + fieldId + ']"]' ).checked;
6104 +
6105 + if ( areValuesSeparate && ! targetInput.name.endsWith( '[value]' ) ) {
6106 + return;
6107 + }
6108 +
6109 + const container = document.getElementById( 'frm_field_' + fieldId + '_opts' );
6110 + const conflicts = Array.from( container.querySelectorAll( 'input[type="text"]' ) ).filter(
6111 + input => input.id !== targetInput.id &&
6112 + areValuesSeparate === input.name.endsWith( '[value]' ) &&
6113 + input.value === targetInput.value
6114 + );
6115 +
6116 + if ( conflicts.length ) {
6117 + /* translators: %s: The detected option value. */
6118 + infoModal( sprintf( __( 'Duplicate option value "%s" detected', 'formidable' ), purifyHtml( targetInput.value ) ) );
6119 + }
6120 + }
6121 +
6122 + function getFieldValues() {
6123 + /*jshint validthis:true */
6124 + let isTaxonomy,
6125 + val = this.value;
6126 +
6127 + if ( val ) {
6128 + const parentIDs = this.parentNode.id.replace( 'frm_logic_', '' ).split( '_' );
6129 + const fieldID = parentIDs[0];
6130 + const metaKey = parentIDs[1];
6131 + const valueField = document.getElementById( 'frm_field_id_' + val );
6132 + const valueFieldType = valueField.getAttribute( 'data-ftype' );
6133 + const fill = document.getElementById( 'frm_show_selected_values_' + fieldID + '_' + metaKey );
6134 + const optionName = 'field_options[hide_opt_' + fieldID + '][]';
6135 + const optionID = 'frm_field_logic_opt_' + fieldID;
6136 + let input = false;
6137 + let showSelect = ( valueFieldType === 'select' || valueFieldType === 'checkbox' || valueFieldType === 'radio' );
6138 + const showText = ( valueFieldType === 'text' || valueFieldType === 'email' || valueFieldType === 'phone' || valueFieldType === 'url' || valueFieldType === 'number' );
6139 +
6140 + if ( showSelect ) {
6141 + isTaxonomy = document.getElementById( 'frm_has_hidden_options_' + val );
6142 + if ( isTaxonomy !== null ) {
6143 + // get the category options with ajax
6144 + showSelect = false;
6145 + }
6146 + }
6147 +
6148 + if ( showSelect || showText ) {
6149 + fill.innerHTML = '';
6150 + if ( showSelect ) {
6151 + input = document.createElement( 'select' );
6152 + } else {
6153 + input = document.createElement( 'input' );
6154 + input.type = 'text';
6155 + }
6156 + input.name = optionName;
6157 + input.id = optionID + '_' + metaKey;
6158 + fill.appendChild( input );
6159 +
6160 + if ( showSelect ) {
6161 + const fillField = document.getElementById( input.id );
6162 + fillDropdownOpts( fillField, {
6163 + sourceID: val,
6164 + placeholder: '',
6165 + other: true
6166 + });
6167 + }
6168 + } else {
6169 + const thisType = this.getAttribute( 'data-type' );
6170 + frmGetFieldValues( val, fieldID, metaKey, thisType );
6171 + }
6172 + }
6173 + }
6174 +
6175 + function getFieldSelection() {
6176 + /*jshint validthis:true */
6177 + const formId = this.value;
6178 + if ( formId ) {
6179 + const fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
6180 + getTaxOrFieldSelection( formId, fieldId );
6181 + }
6182 + }
6183 +
6184 + function getTaxOrFieldSelection( formId, fieldId ) {
6185 + if ( formId ) {
6186 + jQuery.ajax({
6187 + type: 'POST',
6188 + url: ajaxurl,
6189 + data: {
6190 + action: 'frm_get_field_selection',
6191 + field_id: fieldId,
6192 + form_id: formId,
6193 + nonce: frmGlobal.nonce
6194 + },
6195 + success: function( msg ) {
6196 + jQuery( '#frm_show_selected_fields_' + fieldId ).html( msg ).show();
6197 + }
6198 + });
6199 + }
6200 + }
6201 +
6202 + function updateFieldOrder() {
6203 + let self = this;
6204 +
6205 + this.initOnceInAllInstances = function() {
6206 + if ( 'undefined' !== typeof updateFieldOrder.prototype.orderFieldsObject ) {
6207 + return;
6208 + }
6209 +
6210 + // It will store the order input fields ( input[name="field_options[field_order_{fieldId}]"] ).
6211 + // It will help to reduce the DOM searches based on fieldId.
6212 + // The same object data is used across all "updateFieldOrder" instances.
6213 + updateFieldOrder.prototype.orderFieldsObject = {};
6214 +
6215 + // Get the Form group that will handle the fields settings.
6216 + // Perform a single DOM search and use it across all "updateFieldOrder" instances.
6217 + updateFieldOrder.prototype.fieldSettingsForm = document.getElementById( 'frm-end-form-marker' ).closest( 'form' );
6218 + };
6219 +
6220 + this.getFieldOrderInputById = function( fieldId, parent ) {
6221 + let field;
6222 + const orderFieldsObject = updateFieldOrder.prototype.orderFieldsObject;
6223 + const fieldSettingsForm = updateFieldOrder.prototype.fieldSettingsForm;
6224 +
6225 + if ( 'undefined' === typeof orderFieldsObject[ fieldId ]) {
6226 + field = fieldSettingsForm.querySelector( 'input[name="field_options[field_order_' + fieldId + ']"]' );
6227 + if ( null === field ) {
6228 + field = parent.querySelector( 'input[name="field_options[field_order_' + fieldId + ']"]' );
6229 + }
6230 + orderFieldsObject[ fieldId ] = field;
6231 + return field;
6232 + }
6233 +
6234 + return orderFieldsObject[ fieldId ];
6235 + };
6236 +
6237 + this.initOnceInAllInstances();
6238 + renumberPageBreaks();
6239 +
6240 + return ( function() {
6241 + let fieldId, field, currentOrder, newOrder,
6242 + moveFieldsClass = new moveFieldSettings(),
6243 + fields = jQuery( 'li.frm_field_box', jQuery( '#frm-show-fields' ) );
6244 +
6245 + for ( i = 0; i < fields.length; i++ ) {
6246 + fieldId = fields[ i ].getAttribute( 'data-fid' );
6247 + field = self.getFieldOrderInputById( fieldId, fields[ i ]);
6248 +
6249 + // get current field order, make sure we don't get the "field" reference as the "field" value will get updated later.
6250 + currentOrder = null !== field ? Object.assign({}, field.value )[0] : null;
6251 + newOrder = i + 1;
6252 +
6253 + if ( currentOrder != newOrder && null !== currentOrder ) {
6254 + field.value = newOrder;
6255 + singleField = fields[ i ].querySelector( '#frm-single-settings-' + fieldId );
6256 +
6257 + // add field that needs to be moved to "updateFieldOrder.prototype.fieldSettingsForm"
6258 + moveFieldsClass.append( singleField );
6259 + fieldUpdated();
6260 + }
6261 + }
6262 + // move all appended fields
6263 + moveFieldsClass.moveFields();
6264 + }() );
6265 + }
6266 +
6267 + function toggleSectionHolder() {
6268 + document.querySelectorAll( '.start_divider' ).forEach(
6269 + function( divider ) {
6270 + toggleOneSectionHolder( jQuery( divider ) );
6271 + }
6272 + );
6273 + }
6274 +
6275 + function toggleOneSectionHolder( $section ) {
6276 + let noSectionFields, $rows, length, index, sectionHasFields;
6277 +
6278 + if ( ! $section.length ) {
6279 + return;
6280 + }
6281 +
6282 + $rows = $section.find( 'ul.frm_sorting' );
6283 + sectionHasFields = false;
6284 + length = $rows.length;
6285 + for ( index = 0; index < length; ++index ) {
6286 + if ( 0 !== getFieldsInRow( jQuery( $rows.get( index ) ) ).length ) {
6287 + sectionHasFields = true;
6288 + break;
6289 + }
6290 + }
6291 +
6292 + noSectionFields = $section.parent().children( '.frm_no_section_fields' ).get( 0 );
6293 + noSectionFields.classList.toggle( 'frm_block', ! sectionHasFields );
6294 + }
6295 +
6296 + function handleShowPasswordLiveUpdate() {
6297 + frmDom.util.documentOn( 'change', '.frm_show_password_setting_input', event => {
6298 + const fieldId = event.target.getAttribute( 'data-fid' );
6299 + const fieldEl = document.getElementById( 'frm_field_id_' + fieldId );
6300 + if ( ! fieldEl ) {
6301 + return;
6302 + }
6303 +
6304 + fieldEl.classList.toggle( 'frm_disabled_show_password', ! event.target.checked );
6305 + });
6306 + }
6307 +
6308 + function slideDown() {
6309 + /*jshint validthis:true */
6310 + const id = jQuery( this ).data( 'slidedown' );
6311 + const $thisId = jQuery( document.getElementById( id ) );
6312 + if ( $thisId.is( ':hidden' ) ) {
6313 + $thisId.slideDown( 'fast' );
6314 + this.style.display = 'none';
6315 + }
6316 + return false;
6317 + }
6318 +
6319 + function slideUp() {
6320 + /*jshint validthis:true */
6321 + const id = jQuery( this ).data( 'slideup' );
6322 + const $thisId = jQuery( document.getElementById( id ) );
6323 + $thisId.slideUp( 'fast' );
6324 + $thisId.siblings( 'a' ).show();
6325 + return false;
6326 + }
6327 +
6328 + function adjustVisibilityValuesForEveryoneValues( element, option ) {
6329 + if ( '' === option.getAttribute( 'value' ) ) {
6330 + onEveryoneOptionSelected( jQuery( this ) );
6331 + } else {
6332 + unselectEveryoneOptionIfSelected( jQuery( this ) );
6333 + }
6334 + }
6335 +
6336 + function onEveryoneOptionSelected( $select ) {
6337 + $select.val( '' );
6338 + $select.next( '.btn-group' ).find( '.multiselect-container input[value!=""]' ).prop( 'checked', false );
6339 + }
6340 +
6341 + function unselectEveryoneOptionIfSelected( $select ) {
6342 + let selectedValues = $select.val(),
6343 + index;
6344 +
6345 + if ( selectedValues === null ) {
6346 + $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', true );
6347 + onEveryoneOptionSelected( $select );
6348 + return;
6349 + }
6350 +
6351 + index = selectedValues.indexOf( '' );
6352 + if ( index >= 0 ) {
6353 + selectedValues.splice( index, 1 );
6354 + $select.val( selectedValues );
6355 + $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', false );
6356 + }
6357 + }
6358 +
6359 + /**
6360 + * Get rid of empty container that inserts extra space.
6361 + */
6362 + function hideEmptyEle() {
6363 + jQuery( '.frm-hide-empty' ).each( function() {
6364 + if ( jQuery( this ).text().trim().length === 0 ) {
6365 + jQuery( this ).remove();
6366 + }
6367 + });
6368 + }
6369 +
6370 + /* Change the classes in the builder */
6371 + function changeFieldClass( field, setting ) {
6372 + let classes, replace, alignField,
6373 + replaceWith = ' ' + setting.value,
6374 + fieldId = field.getAttribute( 'data-fid' );
6375 +
6376 + // Include classes from multiple settings.
6377 + if ( typeof fieldId !== 'undefined' ) {
6378 + if ( setting.classList.contains( 'field_options_align' ) ) {
6379 + replaceWith += ' ' + document.getElementById( 'frm_classes_' + fieldId ).value;
6380 + } else if ( setting.classList.contains( 'frm_classes' ) ) {
6381 + alignField = document.getElementById( 'field_options_align_' + fieldId );
6382 + if ( alignField !== null ) {
6383 + replaceWith += ' ' + alignField.value;
6384 + }
6385 + }
6386 + }
6387 + replaceWith += ' ';
6388 +
6389 + // Allow for the column number dropdown.
6390 + replaceWith = replaceWith.replace( ' block ', ' ' ).replace( ' inline ', ' horizontal_radio ' );
6391 +
6392 + classes = field.className.split( ' frmstart ' )[1];
6393 + classes = 0 === classes.indexOf( 'frmend ' ) ? '' : classes.split( ' frmend ' )[0];
6394 +
6395 + if ( classes.trim() === '' ) {
6396 + replace = ' frmstart frmend ';
6397 + if ( -1 === field.className.indexOf( replace ) ) {
6398 + replace = ' frmstart frmend ';
6399 + }
6400 + replaceWith = ' frmstart ' + replaceWith.trim() + ' frmend ';
6401 + } else {
6402 + replace = classes.trim();
6403 + replaceWith = replaceWith.trim();
6404 + }
6405 +
6406 + field.className = field.className.replace( replace, replaceWith );
6407 + }
6408 +
6409 + function maybeShowInlineModal( e ) {
6410 + /*jshint validthis:true */
6411 + e.preventDefault();
6412 + showInlineModal( this );
6413 + }
6414 +
6415 + function showInlineModal( icon, input ) {
6416 + const box = document.getElementById( icon.getAttribute( 'data-open' ) ),
6417 + container = jQuery( icon ).closest( 'p' ),
6418 + inputTrigger = ( typeof input !== 'undefined' );
6419 +
6420 + if ( container.hasClass( 'frm-open' ) ) {
6421 + container.removeClass( 'frm-open' );
6422 + box.classList.add( 'frm_hidden' );
6423 + } else {
6424 + if ( ! inputTrigger ) {
6425 + input = getInputForIcon( icon );
6426 + }
6427 + if ( input !== null ) {
6428 + if ( ! inputTrigger ) {
6429 + input.focus();
6430 + }
6431 + container.after( box );
6432 + box.setAttribute( 'data-fills', input.id );
6433 +
6434 + if ( box.id.indexOf( 'frm-calc-box' ) === 0 ) {
6435 + popCalcFields( box, true );
6436 + }
6437 + }
6438 +
6439 + container.addClass( 'frm-open' );
6440 + box.classList.remove( 'frm_hidden' );
6441 +
6442 + /**
6443 + * @since 6.4.1
6444 + */
6445 + wp.hooks.doAction( 'frm_show_inline_modal', box, icon );
6446 + }
6447 + }
6448 +
6449 + function dismissInlineModal( e ) {
6450 + /*jshint validthis:true */
6451 + e.preventDefault();
6452 + this.parentNode.classList.add( 'frm_hidden' );
6453 + jQuery( '.frm-open [data-open="' + this.parentNode.id + '"]' ).closest( '.frm-open' ).removeClass( 'frm-open' );
6454 + }
6455 +
6456 + function changeInputtedValue() {
6457 + /*jshint validthis:true */
6458 + let i,
6459 + action = this.getAttribute( 'data-frmchange' ).split( ',' );
6460 +
6461 + for ( i = 0; i < action.length; i++ ) {
6462 + if ( action[i] === 'updateOption' ) {
6463 + changeHiddenSeparateValue( this );
6464 + } else if ( action[i] === 'updateDefault' ) {
6465 + changeDefaultRadioValue( this );
6466 + } else if ( action[i] === 'checkUniqueOpt' ) {
6467 + checkUniqueOpt( this );
6468 + } else {
6469 + this.value = this.value[ action[i] ]();
6470 + }
6471 + }
6472 + }
6473 +
6474 + /**
6475 + * When the saved value is changed, update the default value radio.
6476 + */
6477 + function changeDefaultRadioValue( input ) {
6478 + const parentLi = getOptionParent( input ),
6479 + key = parentLi.getAttribute( 'data-optkey' ),
6480 + fieldId = getOptionFieldId( parentLi, key ),
6481 + defaultRadio = parentLi.querySelector( 'input[name="default_value_' + fieldId + '"]' );
6482 +
6483 + if ( defaultRadio !== null ) {
6484 + defaultRadio.value = input.value;
6485 + }
6486 + }
6487 +
6488 + /**
6489 + * If separate values are not enabled, change the saved value when
6490 + * the displayed value is changed.
6491 + */
6492 + function changeHiddenSeparateValue( input ) {
6493 + let savedVal,
6494 + parentLi = getOptionParent( input ),
6495 + key = parentLi.getAttribute( 'data-optkey' ),
6496 + fieldId = getOptionFieldId( parentLi, key ),
6497 + sep = document.getElementById( 'separate_value_' + fieldId );
6498 +
6499 + if ( sep !== null && sep.checked === false ) {
6500 + // If separate values are not turned on.
6501 + savedVal = document.getElementById( 'field_key_' + fieldId + '-' + key );
6502 + savedVal.value = input.value;
6503 + changeDefaultRadioValue( savedVal );
6504 + }
6505 + }
6506 +
6507 + function getOptionParent( input ) {
6508 + let parentLi = input.parentNode;
6509 + if ( parentLi.tagName !== 'LI' ) {
6510 + parentLi = parentLi.parentNode;
6511 + }
6512 + return parentLi;
6513 + }
6514 +
6515 + function getOptionFieldId( li, key ) {
6516 + const liId = li.id;
6517 +
6518 + return liId.replace( 'frm_delete_field_', '' ).replace( '-' + key + '_container', '' );
6519 + }
6520 +
6521 + function submitBuild() {
6522 + /*jshint validthis:true */
6523 + const $thisEle = this;
6524 +
6525 + if ( showNameYourFormModal() ) {
6526 + return;
6527 + }
6528 +
6529 + preFormSave( this );
6530 +
6531 + const $form = jQuery( builderForm );
6532 + const v = JSON.stringify( $form.serializeArray() );
6533 +
6534 + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( v );
6535 + jQuery.ajax({
6536 + type: 'POST',
6537 + url: ajaxurl,
6538 + data: {action: 'frm_save_form', 'frm_compact_fields': v, nonce: frmGlobal.nonce},
6539 + success: function( msg ) {
6540 + afterFormSave( $thisEle );
6541 +
6542 + const $postStuff = document.getElementById( 'post-body-content' );
6543 + const $html = document.createElement( 'div' );
6544 + $html.setAttribute( 'class', 'frm_updated_message' );
6545 + $html.innerHTML = msg;
6546 + $postStuff.insertBefore( $html, $postStuff.firstChild );
6547 + reloadIfAddonActivatedAjaxSubmitOnly();
6548 + },
6549 + error: function() {
6550 + triggerSubmit( document.getElementById( 'frm_js_build_form' ) );
6551 + }
6552 + });
6553 + }
6554 +
6555 + function triggerSubmit( form ) {
6556 + const button = form.ownerDocument.createElement( 'input' );
6557 + button.style.display = 'none';
6558 + button.type = 'submit';
6559 + form.appendChild( button ).click();
6560 + form.removeChild( button );
6561 + }
6562 +
6563 + function triggerChange( element ) {
6564 + jQuery( element ).trigger( 'change' );
6565 + }
6566 +
6567 + function submitNoAjax() {
6568 + /*jshint validthis:true */
6569 + let form;
6570 +
6571 + if ( showNameYourFormModal() ) {
6572 + return;
6573 + }
6574 +
6575 + preFormSave( this );
6576 + form = jQuery( builderForm );
6577 + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( JSON.stringify( form.serializeArray() ) );
6578 + triggerSubmit( document.getElementById( 'frm_js_build_form' ) );
6579 + }
6580 +
6581 + /**
6582 + * Display a modal dialog for naming a new form template, if applicable.
6583 + *
6584 + * @return {boolean} True if the modal is successfully initialized and displayed; false otherwise.
6585 + */
6586 + function showNameYourFormModal() {
6587 + // Exit early if the 'new_template' URL parameter is not set to 'true'
6588 + if ( ! shouldShowNameYourFormNameModal() ) {
6589 + return false;
6590 + }
6591 +
6592 + const modalWidget = initModal( '#frm-form-templates-modal', '440px' );
6593 + if ( ! modalWidget ) {
6594 + return false;
6595 + }
6596 +
6597 + // Set the vertical offset for the modal and open it
6598 + offsetModalY( modalWidget, '72px' );
6599 + modalWidget.dialog( 'open' );
6600 +
6601 + return true;
6602 + }
6603 +
6604 + /**
6605 + * Returns true if 'Name Your Form' modal should be displayed.
6606 + *
6607 + * @returns {Boolean}
6608 + */
6609 + function shouldShowNameYourFormNameModal() {
6610 + const formNameInput = document.getElementById( 'frm_form_name' );
6611 + if ( formNameInput && formNameInput.value.trim() !== '' ) {
6612 + return false;
6613 + }
6614 +
6615 + return 'true' === urlParams.get( 'new_template' ) && document.querySelector( '#frm_top_bar #frm_bs_dropdown .frm_bstooltip' )?.textContent.trim() === frm_admin_js.noTitleText; // eslint-disable-line camelcase
6616 + }
6617 +
6618 + /**
6619 + * Manages event handling for the 'Name your form' modal.
6620 + *
6621 + * Attaches click and keydown event listeners to the save button and input field.
6622 + *
6623 + * @return {void}
6624 + */
6625 + function addFormNameModalEvents() {
6626 + const saveFormNameButton = document.getElementById( 'frm-save-form-name-button' );
6627 + const newFormNameInput = document.getElementById( 'frm_new_form_name_input' );
6628 +
6629 + // Attach click event listener
6630 + onClickPreventDefault( saveFormNameButton, onSaveFormNameButton );
6631 +
6632 + // Attach keydown event listener
6633 + newFormNameInput.addEventListener( 'keydown', function( event ) {
6634 + if ( event.key === 'Enter' ) {
6635 + onSaveFormNameButton.call( this, event );
6636 + }
6637 + });
6638 + }
6639 +
6640 + /**
6641 + * Handles the click event on the save form name button.
6642 + *
6643 + * @param {Event} event The click event object.
6644 + * @return {void}
6645 + */
6646 + const onSaveFormNameButton = ( event ) => {
6647 + const newFormName = document.getElementById( 'frm_new_form_name_input' ).value.trim();
6648 +
6649 + // Prepare FormData for the POST request
6650 + const formData = new FormData();
6651 + formData.append( 'form_id', urlParams.get( 'id' ) );
6652 + formData.append( 'form_name', newFormName );
6653 +
6654 + // Perform the POST request
6655 + doJsonPost( 'rename_form', formData ).then( data => {
6656 + // Remove the 'new_template' parameter from the URL and update the browser history
6657 + urlParams.delete( 'new_template' );
6658 + currentURL.search = urlParams.toString();
6659 + history.replaceState({}, '', currentURL.toString() );
6660 +
6661 + if ( null !== document.getElementById( 'frm_notification_settings' ) ) {
6662 + document.getElementById( 'frm_form_name' ).value = newFormName;
6663 + document.getElementById( 'frm_form_key' ).value = data.form_key;
6664 + }
6665 +
6666 + // Trigger the 'Save' button click using jQuery
6667 + jQuery( '#frm-publishing' ).find( '.frm_button_submit' ).trigger( 'click' );
6668 + });
6669 + };
6670 +
6671 + function preFormSave( b ) {
6672 + removeWPUnload();
6673 + if ( jQuery( 'form.inplace_form' ).length ) {
6674 + jQuery( '.inplace_save, .postbox' ).trigger( 'click' );
6675 + }
6676 +
6677 + if ( b.classList.contains( 'frm_button_submit' ) ) {
6678 + b.classList.add( 'frm_loading_form' );
6679 + } else {
6680 + b.classList.add( 'frm_loading_button' );
6681 + }
6682 + b.setAttribute( 'aria-busy', 'true' );
6683 +
6684 + adjustFormatInputBeforeSave();
6685 + }
6686 +
6687 + /**
6688 + * Updates the format input based on the selected phone type from dropdowns during the form save process.
6689 + *
6690 + * Triggered within the preFormSave function, this function iterates through all phone type dropdown elements
6691 + * and adjusts the format input value accordingly. Specifically, if the phone type is 'custom' but the format input
6692 + * is empty, it sets it to 'none'. If the phone type is 'international', it sets the format input value to 'international'
6693 + * before the form is saved.
6694 + *
6695 + * @since 6.9
6696 + *
6697 + * @param {HTMLButtonElement} submitButton The button that was submitted.
6698 + * @return {void}
6699 + */
6700 + function adjustFormatInputBeforeSave( submitButton ) {
6701 + const phoneTypes = document.querySelectorAll( '.frm_phone_type_dropdown' );
6702 + phoneTypes.forEach( phoneType => {
6703 + const value = phoneType.value;
6704 + if ( ! [ 'none', 'international' ].includes( value ) ) {
6705 + return;
6706 + }
6707 +
6708 + const formatInput = phoneType.parentElement.nextElementSibling.querySelector( '.frm_format_opt' );
6709 + if ( 'none' === value ) {
6710 + formatInput.setAttribute( 'value', '' );
6711 + }
6712 + if ( 'international' === value ) {
6713 + formatInput.setAttribute( 'value', 'international' );
6714 + }
6715 + });
6716 + }
6717 +
6718 + function afterFormSave( button ) {
6719 + button.classList.remove( 'frm_loading_form' );
6720 + button.classList.remove( 'frm_loading_button' );
6721 + resetOptionTextDetails();
6722 + fieldsUpdated = 0;
6723 + button.setAttribute( 'aria-busy', 'false' );
6724 +
6725 + setTimeout( function() {
6726 + jQuery( '.frm_updated_message' ).fadeOut( 'slow', function() {
6727 + this.parentNode.removeChild( this );
6728 + });
6729 + }, 5000 );
6730 + }
6731 +
6732 + function initUpgradeModal() {
6733 + const $info = initModal( '#frm_upgrade_modal' );
6734 + if ( $info === false ) {
6735 + return;
6736 + }
6737 +
6738 + document.addEventListener( 'click', handleUpgradeClick );
6739 + frmDom.util.documentOn( 'change', 'select.frm_select_with_upgrade', handleUpgradeClick );
6740 +
6741 + function handleUpgradeClick( event ) {
6742 + let element, link, content;
6743 +
6744 + element = event.target;
6745 +
6746 + if ( ! element.classList ) {
6747 + return;
6748 + }
6749 +
6750 + const showExpiredModal = element.classList.contains( 'frm_show_expired_modal' ) || null !== element.querySelector( '.frm_show_expired_modal' ) || element.closest( '.frm_show_expired_modal' );
6751 +
6752 + // If a `select` element is clicked, check if the selected option has a 'data-upgrade' attribute
6753 + if ( event.type === 'change' && element.classList.contains( 'frm_select_with_upgrade' ) ) {
6754 + const selectedOption = element.options[element.selectedIndex];
6755 + if ( selectedOption && selectedOption.dataset.upgrade ) {
6756 + element = selectedOption;
6757 + }
6758 + }
6759 +
6760 + if ( ! element.dataset.upgrade ) {
6761 + let parent = element.closest( '[data-upgrade]' );
6762 + if ( ! parent ) {
6763 + parent = element.closest( '.frm_field_box' );
6764 + if ( ! parent ) {
6765 + return;
6766 + }
6767 + // Fake it if it's missing to avoid error.
6768 + element.dataset.upgrade = '';
6769 + }
6770 + element = parent;
6771 + }
6772 +
6773 + if ( showExpiredModal ) {
6774 + const hookName = 'frm_show_expired_modal';
6775 + wp.hooks.doAction( hookName, element );
6776 + return;
6777 + }
6778 +
6779 + const upgradeLabel = element.dataset.upgrade;
6780 + if ( ! upgradeLabel || element.classList.contains( 'frm_show_upgrade_tab' ) ) {
6781 + return;
6782 + }
6783 +
6784 + event.preventDefault();
6785 +
6786 + const modal = $info.get( 0 );
6787 + const lockIcon = modal.querySelector( '.frm_lock_icon' );
6788 +
6789 + if ( lockIcon ) {
6790 + lockIcon.style.display = 'block';
6791 + lockIcon.classList.remove( 'frm_lock_open_icon' );
6792 + lockIcon.querySelector( 'use' ).setAttribute( 'href', '#frm_lock_icon' );
6793 + }
6794 +
6795 + const upgradeImageId = 'frm_upgrade_modal_image';
6796 + const oldImage = document.getElementById( upgradeImageId );
6797 + if ( oldImage ) {
6798 + oldImage.remove();
6799 + }
6800 +
6801 + if ( element.dataset.image ) {
6802 + if ( lockIcon ) {
6803 + lockIcon.style.display = 'none';
6804 + }
6805 + lockIcon.parentNode.insertBefore( img({ id: upgradeImageId, src: frmGlobal.url + '/images/' + element.dataset.image }), lockIcon );
6806 + }
6807 +
6808 + const level = modal.querySelector( '.license-level' );
6809 + if ( level ) {
6810 + level.textContent = getRequiredLicenseFromTrigger( element );
6811 + }
6812 +
6813 + // If one click upgrade, hide other content
6814 + addOneClick( element, 'modal', upgradeLabel );
6815 +
6816 + modal.querySelector( '.frm_are_not_installed' ).style.display = element.dataset.image ? 'none' : 'inline-block';
6817 + modal.querySelector( '.frm_feature_label' ).textContent = upgradeLabel;
6818 + modal.querySelector( 'h2' ).style.display = 'block';
6819 +
6820 + $info.dialog( 'open' );
6821 +
6822 + // set the utm medium
6823 + const button = modal.querySelector( '.button-primary:not(.frm-oneclick-button)' );
6824 + link = button.getAttribute( 'href' ).replace( /(medium=)[a-z_-]+/ig, '$1' + element.getAttribute( 'data-medium' ) );
6825 + content = element.getAttribute( 'data-content' );
6826 + if ( content === null ) {
6827 + content = '';
6828 + }
6829 + link = link.replace( /(content=)[a-z_-]+/ig, '$1' + content );
6830 + button.setAttribute( 'href', link );
6831 + }
6832 + }
6833 +
6834 + function getRequiredLicenseFromTrigger( element ) {
6835 + if ( element.dataset.requires ) {
6836 + return element.dataset.requires;
6837 + }
6838 + return 'Pro';
6839 + }
6840 +
6841 + function populateUpgradeTab( element ) {
6842 + const title = element.dataset.upgrade;
6843 +
6844 + const tab = element.getAttribute( 'href' ).replace( '#', '' );
6845 + const container = document.querySelector( '.frm_' + tab ) || document.querySelector( '.' + tab );
6846 +
6847 + if ( ! container ) {
6848 + return;
6849 + }
6850 +
6851 + if ( container.querySelector( '.frm-upgrade-message' ) ) {
6852 + // Tab has already been populated.
6853 + return;
6854 + }
6855 +
6856 + const h2 = container.querySelector( 'h2' );
6857 + h2.style.borderBottom = 'none';
6858 +
6859 + /* translators: %s: Form Setting section name (ie Form Permissions, Form Scheduling). */
6860 + h2.textContent = sprintf( __( '%s are not installed', 'formidable' ), title );
6861 +
6862 + container.classList.add( 'frmcenter' );
6863 +
6864 + const upgradeModal = document.getElementById( 'frm_upgrade_modal' );
6865 + appendClonedModalElementToContainer( 'frm-oneclick' );
6866 + appendClonedModalElementToContainer( 'frm-addon-status' );
6867 +
6868 + // 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).
6869 + const upgradeModalLink = upgradeModal.querySelector( '.frm-upgrade-link' );
6870 + if ( upgradeModalLink ) {
6871 + const upgradeButton = upgradeModalLink.cloneNode( true );
6872 + const level = upgradeButton.querySelector( '.license-level' );
6873 +
6874 + if ( level ) {
6875 + level.textContent = getRequiredLicenseFromTrigger( element );
6876 + }
6877 +
6878 + container.appendChild( upgradeButton );
6879 +
6880 + // Maybe append the secondary "Already purchased?" link from the upgradeModal as well.
6881 + if ( upgradeModalLink.nextElementSibling && upgradeModalLink.nextElementSibling.querySelector( '.frm-link-secondary' ) ) {
6882 + container.appendChild( upgradeModalLink.nextElementSibling.cloneNode( true ) );
6883 + }
6884 +
6885 + appendClonedModalElementToContainer( 'frm-oneclick-button' );
6886 + }
6887 +
6888 + appendClonedModalElementToContainer( 'frm-upgrade-message' );
6889 +
6890 + let upgradeLabel = element.dataset.message;
6891 +
6892 + if ( upgradeLabel === undefined ) {
6893 + upgradeLabel = element.dataset.upgrade;
6894 + }
6895 + addOneClick( element, 'tab', upgradeLabel );
6896 +
6897 + if ( element.dataset.screenshot ) {
6898 + container.appendChild( getScreenshotWrapper( element.dataset.screenshot ) );
6899 + }
6900 +
6901 + function appendClonedModalElementToContainer( className ) {
6902 + container.appendChild( upgradeModal.querySelector( '.' + className ).cloneNode( true ) );
6903 + }
6904 + }
6905 +
6906 + function getScreenshotWrapper( screenshot ) {
6907 + const folderUrl = frmGlobal.url + '/images/screenshots/';
6908 + const wrapper = div({
6909 + className: 'frm-settings-screenshot-wrapper',
6910 + children: [
6911 + getToolbar(),
6912 + div({ child: img({ src: folderUrl + screenshot }) })
6913 + ]
6914 + });
6915 +
6916 + function getToolbar() {
6917 + const children = getColorIcons();
6918 + children.push( img({ src: frmGlobal.url + '/images/tab.svg' }) );
6919 + return div({
6920 + className: 'frm-settings-screenshot-toolbar',
6921 + children
6922 + });
6923 + }
6924 +
6925 + function getColorIcons() {
6926 + return [ '#ED8181', '#EDE06A', '#80BE30' ].map(
6927 + color => {
6928 + const circle = div({ className: 'frm-minmax-icon' });
6929 + circle.style.backgroundColor = color;
6930 + return circle;
6931 + }
6932 + );
6933 + }
6934 +
6935 + return wrapper;
6936 + }
6937 +
6938 + /**
6939 + * Allow addons to be installed from the upgrade modal.
6940 + *
6941 + * @param {Element} link
6942 + * @param {String} context Either 'modal' or 'tab'.
6943 + * @param {String|undefined} upgradeLabel
6944 + */
6945 + function addOneClick( link, context, upgradeLabel ) {
6946 + let container;
6947 +
6948 + if ( 'modal' === context ) {
6949 + container = document.getElementById( 'frm_upgrade_modal' );
6950 + } else if ( 'tab' === context ) {
6951 + container = document.getElementById( link.getAttribute( 'href' ).substr( 1 ) );
6952 + } else {
6953 + return;
6954 + }
6955 +
6956 + const oneclickMessage = container.querySelector( '.frm-oneclick' );
6957 + const upgradeMessage = container.querySelector( '.frm-upgrade-message' );
6958 + const showLink = container.querySelector( '.frm-upgrade-link' );
6959 + const button = container.querySelector( '.frm-oneclick-button' );
6960 + const addonStatus = container.querySelector( '.frm-addon-status' );
6961 +
6962 + let oneclick = link.getAttribute( 'data-oneclick' );
6963 + let newMessage = link.getAttribute( 'data-message' );
6964 + let showIt = 'block';
6965 + let showMsg = 'block';
6966 + let hideIt = 'none';
6967 +
6968 + // If one click upgrade, hide other content.
6969 + if ( oneclickMessage !== null && typeof oneclick !== 'undefined' && oneclick ) {
6970 + if ( newMessage === null ) {
6971 + showMsg = 'none';
6972 + }
6973 + showIt = 'none';
6974 + hideIt = 'block';
6975 + oneclick = JSON.parse( oneclick );
6976 +
6977 + button.className = button.className.replace( ' frm-install-addon', '' ).replace( ' frm-activate-addon', '' );
6978 + button.className = button.className + ' ' + oneclick.class;
6979 + button.rel = oneclick.url;
6980 +
6981 + if ( oneclick.class === 'frm-activate-addon' ) {
6982 + oneclickMessage.textContent = __( 'This plugin is not activated. Would you like to activate it now?', 'formidable' );
6983 + button.textContent = __( 'Activate', 'formidable' );
6984 + } else {
6985 + oneclickMessage.textContent = __( 'That add-on is not installed. Would you like to install it now?', 'formidable' );
6986 + button.textContent = __( 'Install', 'formidable' );
6987 + }
6988 + }
6989 +
6990 + if ( ! newMessage ) {
6991 + newMessage = upgradeMessage.getAttribute( 'data-default' );
6992 + }
6993 + if ( undefined !== upgradeLabel ) {
6994 + newMessage = newMessage.replace( '<span class="frm_feature_label"></span>', upgradeLabel );
6995 + }
6996 +
6997 + upgradeMessage.innerHTML = newMessage;
6998 +
6999 + if ( link.dataset.upsellImage ) {
7000 + upgradeMessage.appendChild(
7001 + img({
7002 + src: link.dataset.upsellImage,
7003 + alt: link.dataset.upgrade
7004 + })
7005 + );
7006 + }
7007 +
7008 + // Either set the link or use the default.
7009 + showLink.href = getShowLinkHrefValue( link, showLink );
7010 +
7011 + addonStatus.style.display = 'none';
7012 +
7013 + oneclickMessage.style.display = hideIt;
7014 + button.style.display = hideIt === 'block' ? 'inline-block' : hideIt;
7015 + upgradeMessage.style.display = showMsg;
7016 + showLink.style.display = showIt === 'block' ? 'inline-block' : showIt;
7017 + }
7018 +
7019 + function getShowLinkHrefValue( link, showLink ) {
7020 + let customLink = link.getAttribute( 'data-link' );
7021 + if ( customLink === null || typeof customLink === 'undefined' || customLink === '' ) {
7022 + customLink = showLink.getAttribute( 'data-default' );
7023 + }
7024 + return customLink;
7025 + }
7026 +
7027 + /* Form settings */
7028 +
7029 + function showInputIcon( parentClass ) {
7030 + if ( typeof parentClass === 'undefined' ) {
7031 + parentClass = '';
7032 + }
7033 + maybeAddFieldSelection( parentClass );
7034 + 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>' );
7035 + }
7036 +
7037 + /**
7038 + * For reverse compatibility. Check for fields that were
7039 + * using the old sidebar.
7040 + */
7041 + function maybeAddFieldSelection( parentClass ) {
7042 + let i,
7043 + 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' );
7044 + for ( i = 0; i < missingClass.length; i++ ) {
7045 + missingClass[i].parentNode.classList.add( 'frm_has_shortcodes' );
7046 + }
7047 + }
7048 +
7049 + function showSuccessOpt() {
7050 + /*jshint validthis:true */
7051 + let c = 'success';
7052 + if ( this.name === 'options[edit_action]' ) {
7053 + c = 'edit';
7054 + }
7055 + const v = jQuery( this ).val();
7056 + jQuery( '.' + c + '_action_box' ).hide();
7057 + if ( v === 'redirect' ) {
7058 + jQuery( '.' + c + '_action_redirect_box.' + c + '_action_box' ).fadeIn( 'slow' );
7059 + } else if ( v === 'page' ) {
7060 + jQuery( '.' + c + '_action_page_box.' + c + '_action_box' ).fadeIn( 'slow' );
7061 + } else {
7062 + jQuery( '.' + c + '_action_message_box.' + c + '_action_box' ).fadeIn( 'slow' );
7063 + }
7064 + }
7065 +
7066 + function copyFormAction( event ) {
7067 + if ( waitForActionToLoadBeforeCopy( event.target ) ) {
7068 + return;
7069 + }
7070 +
7071 + const targetSettings = event.target.closest( '.frm_form_action_settings' );
7072 + const wysiwyg = targetSettings.querySelector( '.wp-editor-area' );
7073 + if ( wysiwyg ) {
7074 + // Temporary remove TinyMCE before cloning to avoid TinyMCE conflicts.
7075 + tinymce.EditorManager.execCommand( 'mceRemoveEditor', true, wysiwyg.id );
7076 + }
7077 +
7078 + const $action = jQuery( targetSettings ).clone();
7079 + const currentID = $action.attr( 'id' ).replace( 'frm_form_action_', '' );
7080 + const newID = newActionId( currentID );
7081 +
7082 + $action.find( '.frm_action_id, .frm-btn-group' ).remove();
7083 + $action.find( 'input[name$="[' + currentID + '][ID]"]' ).val( '' );
7084 + $action.find( '.widget-inside' ).hide();
7085 +
7086 + // the .html() gets original values, so they need to be set
7087 + $action.find( 'input[type=text], textarea, input[type=number]' ).prop( 'defaultValue', function() {
7088 + return this.value;
7089 + });
7090 +
7091 + $action.find( 'input[type=checkbox], input[type=radio]' ).prop( 'defaultChecked', function() {
7092 + return this.checked;
7093 + });
7094 +
7095 + const rename = new RegExp( '\\[' + currentID + '\\]', 'g' );
7096 + const reid = new RegExp( '_' + currentID + '"', 'g' );
7097 + const reclass = new RegExp( '-' + currentID + '"', 'g' );
7098 + const revalue = new RegExp( '"' + currentID + '"', 'g' ); // if a field id matches, this could cause trouble
7099 +
7100 + let html = $action.html().replace( rename, '[' + newID + ']' ).replace( reid, '_' + newID + '"' );
7101 + html = html.replace( reclass, '-' + newID + '"' ).replace( revalue, '"' + newID + '"' );
7102 +
7103 + const newAction = div({
7104 + id: 'frm_form_action_' + newID,
7105 + className: $action.get( 0 ).className
7106 + });
7107 + newAction.setAttribute( 'data-actionkey', newID );
7108 + newAction.innerHTML = html;
7109 + newAction.querySelectorAll( '.wp-editor-wrap, .wp-editor-wrap *' ).forEach(
7110 + element => {
7111 + if ( 'string' === typeof element.className ) {
7112 + element.className = element.className.replace( currentID, newID );
7113 + }
7114 + element.id = element.id.replace( currentID, newID );
7115 + }
7116 + );
7117 + newAction.classList.remove( 'open' );
7118 + document.getElementById( 'frm_notification_settings' ).appendChild( newAction );
7119 +
7120 + if ( wysiwyg ) {
7121 + // Re-initialize the original wysiwyg which was removed before cloning.
7122 + frmDom.wysiwyg.init( wysiwyg );
7123 + frmDom.wysiwyg.init( newAction.querySelector( '.wp-editor-area' ) );
7124 + }
7125 +
7126 + if ( newAction.classList.contains( 'frm_single_on_submit_settings' ) ) {
7127 + const autocompleteInput = newAction.querySelector( 'input.frm-page-search' );
7128 + if ( autocompleteInput ) {
7129 + frmDom.autocomplete.initAutocomplete( 'page', newAction );
7130 + }
7131 + }
7132 +
7133 + initiateMultiselect();
7134 +
7135 + const hookName = 'frm_after_duplicate_action';
7136 + wp.hooks.doAction( hookName, newAction );
7137 + }
7138 +
7139 + function waitForActionToLoadBeforeCopy( element ) {
7140 + let $trigger = jQuery( element ),
7141 + $original = $trigger.closest( '.frm_form_action_settings' ),
7142 + $inside = $original.find( '.widget-inside' ),
7143 + $top;
7144 +
7145 + if ( $inside.find( 'p, div, table' ).length ) {
7146 + return false;
7147 + }
7148 +
7149 + $top = $original.find( '.widget-top' );
7150 + $top.on( 'frm-action-loaded', function() {
7151 + $trigger.trigger( 'click' );
7152 + $original.removeClass( 'open' );
7153 + $inside.hide();
7154 + });
7155 + $top.trigger( 'click' );
7156 + return true;
7157 + }
7158 +
7159 + function newActionId( currentID ) {
7160 + let newID = parseInt( currentID, 10 ) + 11;
7161 + const exists = document.getElementById( 'frm_form_action_' + newID );
7162 + if ( exists !== null ) {
7163 + newID++;
7164 + newID = newActionId( newID );
7165 + }
7166 + return newID;
7167 + }
7168 +
7169 + function addFormAction() {
7170 + /*jshint validthis:true */
7171 + const type = jQuery( this ).data( 'actiontype' );
7172 +
7173 + if ( isAtLimitForActionType( type ) ) {
7174 + return;
7175 + }
7176 +
7177 + const actionId = getNewActionId();
7178 + const formId = thisFormId;
7179 +
7180 + const placeholderSetting = document.createElement( 'div' );
7181 + placeholderSetting.classList.add( 'frm_single_' + type + '_settings' );
7182 +
7183 + const actionsList = document.getElementById( 'frm_notification_settings' );
7184 + actionsList.appendChild( placeholderSetting );
7185 +
7186 + jQuery.ajax({
7187 + type: 'POST',
7188 + url: ajaxurl,
7189 + data: {
7190 + action: 'frm_add_form_action',
7191 + type: type,
7192 + list_id: actionId,
7193 + form_id: formId,
7194 + nonce: frmGlobal.nonce
7195 + },
7196 + success: handleAddFormActionSuccess
7197 + });
7198 +
7199 + function handleAddFormActionSuccess( html ) {
7200 + fieldUpdated();
7201 + placeholderSetting.remove();
7202 +
7203 + closeOpenActions();
7204 +
7205 + const newActionContainer = div();
7206 + newActionContainer.innerHTML = html;
7207 +
7208 + const widgetTop = newActionContainer.querySelector( '.widget-top' );
7209 + Array.from( newActionContainer.children ).forEach( child => actionsList.appendChild( child ) );
7210 +
7211 + jQuery( '.frm_form_action_settings' ).fadeIn( 'slow' );
7212 +
7213 + const newAction = document.getElementById( 'frm_form_action_' + actionId );
7214 +
7215 + newAction.classList.add( 'open' );
7216 + document.getElementById( 'post-body-content' ).scroll({
7217 + top: newAction.offsetTop + 10,
7218 + left: 0,
7219 + behavior: 'smooth'
7220 + });
7221 +
7222 + // Check if icon should be active
7223 + checkActiveAction( type );
7224 + showInputIcon( '#frm_form_action_' + actionId );
7225 +
7226 + initiateMultiselect();
7227 + frmDom.autocomplete.initAutocomplete( 'page', newAction );
7228 +
7229 + if ( widgetTop ) {
7230 + jQuery( widgetTop ).trigger( 'frm-action-loaded' );
7231 + }
7232 +
7233 + /**
7234 + * Fires after added a new form action.
7235 + *
7236 + * @since 5.5.4
7237 + *
7238 + * @param {HTMLElement} formAction Form action element.
7239 + */
7240 + frmAdminBuild.hooks.doAction( 'frm_added_form_action', newAction );
7241 + }
7242 + }
7243 +
7244 + function closeOpenActions() {
7245 + document.querySelectorAll( '.frm_form_action_settings.open' ).forEach(
7246 + setting => setting.classList.remove( 'open' )
7247 + );
7248 + }
7249 +
7250 + function toggleActionGroups() {
7251 + /*jshint validthis:true */
7252 + const actions = document.getElementById( 'frm_email_addon_menu' ).classList,
7253 + search = document.getElementById( 'actions-search-input' );
7254 +
7255 + if ( actions.contains( 'frm-all-actions' ) ) {
7256 + actions.remove( 'frm-all-actions' );
7257 + actions.add( 'frm-limited-actions' );
7258 + } else {
7259 + actions.add( 'frm-all-actions' );
7260 + actions.remove( 'frm-limited-actions' );
7261 + }
7262 +
7263 + // Reset search.
7264 + search.value = '';
7265 + triggerEvent( search, 'input' );
7266 + }
7267 +
7268 + function getNewActionId() {
7269 + let actionSettings = document.querySelectorAll( '.frm_form_action_settings' ),
7270 + len = getNewRowId( actionSettings, 'frm_form_action_' );
7271 + if ( typeof document.getElementById( 'frm_form_action_' + len ) !== 'undefined' ) {
7272 + len = len + 100;
7273 + }
7274 + if ( lastNewActionIdReturned >= len ) {
7275 + len = lastNewActionIdReturned + 1;
7276 + }
7277 + lastNewActionIdReturned = len;
7278 + return len;
7279 + }
7280 +
7281 + function clickAction( obj ) {
7282 + const $thisobj = jQuery( obj );
7283 +
7284 + if ( obj.className.indexOf( 'selected' ) !== -1 ) {
7285 + return;
7286 + }
7287 + if ( obj.className.indexOf( 'edit_field_type_end_divider' ) !== -1 && $thisobj.closest( '.edit_field_type_divider' ).hasClass( 'no_repeat_section' ) ) {
7288 + return;
7289 + }
7290 +
7291 + deselectFields();
7292 + $thisobj.addClass( 'selected' );
7293 + showFieldOptions( obj );
7294 + }
7295 +
7296 + /**
7297 + * When a field is selected, show the field settings in the sidebar.
7298 + */
7299 + function showFieldOptions( obj ) {
7300 + let i, singleField,
7301 + fieldId = obj.getAttribute( 'data-fid' ),
7302 + fieldType = obj.getAttribute( 'data-type' ),
7303 + allFieldSettings = document.querySelectorAll( '.frm-single-settings:not(.frm_hidden)' );
7304 +
7305 + for ( i = 0; i < allFieldSettings.length; i++ ) {
7306 + allFieldSettings[i].classList.add( 'frm_hidden' );
7307 + }
7308 +
7309 + singleField = document.getElementById( 'frm-single-settings-' + fieldId );
7310 + moveFieldSettings( singleField );
7311 +
7312 + if ( fieldType && 'quantity' === fieldType ) {
7313 + popProductFields( jQuery( singleField ).find( '.frmjs_prod_field_opt' )[0]);
7314 + }
7315 +
7316 + singleField.classList.remove( 'frm_hidden' );
7317 + document.getElementById( 'frm-options-panel-tab' ).click();
7318 +
7319 + const editor = singleField.querySelector( '.wp-editor-area' );
7320 + if ( editor ) {
7321 + frmDom.wysiwyg.init(
7322 + editor,
7323 + { setupCallback: setupTinyMceEventHandlers }
7324 + );
7325 + }
7326 +
7327 + wp.hooks.doAction( 'frmShowedFieldSettings', obj, singleField );
7328 + maybeAddShortcodesModalTriggerIcon( fieldType, fieldId, singleField );
7329 + }
7330 +
7331 + function maybeAddShortcodesModalTriggerIcon( fieldType, fieldId, singleField ) {
7332 + if ( ! shouldAddShortcodesModalTriggerIcon( fieldType ) ) {
7333 + return;
7334 + }
7335 +
7336 + const fieldSettingsSelector = '#frm-single-settings-' + fieldId;
7337 + if ( document.querySelector( fieldSettingsSelector + ' .frm-show-box' ) ) {
7338 + return;
7339 + }
7340 + singleField.querySelector( '.wp-editor-container' )?.classList.add( 'frm_has_shortcodes' );
7341 +
7342 + const wrapTextareaWithIconContainer = () => {
7343 + const textareas = document.querySelectorAll( fieldSettingsSelector + ' .frm_has_shortcodes textarea' );
7344 + textareas.forEach( textarea => {
7345 + const wrapperSpan = span({ className: 'frm-with-right-icon' });
7346 + textarea.parentNode.insertBefore( wrapperSpan, textarea );
7347 + wrapperSpan.appendChild( createModalTriggerIcon() );
7348 + wrapperSpan.appendChild( textarea );
7349 + });
7350 + };
7351 +
7352 + const createModalTriggerIcon = () => {
7353 + return frmDom.svg({ href: '#frm_more_horiz_solid_icon', classList: [ 'frm-show-box' ] });
7354 + };
7355 +
7356 + wrapTextareaWithIconContainer();
7357 + }
7358 +
7359 + function shouldAddShortcodesModalTriggerIcon( fieldType ) {
7360 + const fieldsWithShortcodesBox = wp.hooks.applyFilters( 'frm_fields_with_shortcode_popup', [ 'html' ]);
7361 +
7362 + return fieldsWithShortcodesBox.includes( fieldType );
7363 + }
7364 +
7365 + function setupTinyMceEventHandlers( editor ) {
7366 + editor.on( 'Change', function() {
7367 + handleTinyMceChange( editor );
7368 + });
7369 + }
7370 +
7371 + function handleTinyMceChange( editor ) {
7372 + if ( ! isTinyMceActive() || tinyMCE.activeEditor.isHidden() ) {
7373 + return;
7374 + }
7375 +
7376 + editor.targetElm.value = editor.getContent();
7377 + jQuery( editor.targetElm ).trigger( 'change' );
7378 + }
7379 +
7380 + function isTinyMceActive() {
7381 + let activeSettings, wrapper;
7382 +
7383 + activeSettings = document.querySelector( '.frm-single-settings:not(.frm_hidden)' );
7384 + if ( ! activeSettings ) {
7385 + return false;
7386 + }
7387 +
7388 + wrapper = activeSettings.querySelector( '.wp-editor-wrap' );
7389 + return null !== wrapper && wrapper.classList.contains( 'tmce-active' );
7390 + }
7391 +
7392 + /**
7393 + * Move the settings to the sidebar the first time they are changed or selected.
7394 + * Keep the end marker at the end of the form.
7395 + */
7396 + function moveFieldSettings( singleField ) {
7397 + let self = this;
7398 +
7399 + if ( singleField === null ) {
7400 + // The field may have not been loaded yet via ajax.
7401 + return;
7402 + }
7403 +
7404 + this.fragment = document.createDocumentFragment();
7405 +
7406 + this.initOnceInAllInstances = function() {
7407 + if ( 'undefined' !== typeof moveFieldSettings.prototype.endMarker ) {
7408 + return;
7409 + }
7410 + // perform a single search in the DOM and use it across all moveFieldSettings instances
7411 + moveFieldSettings.prototype.endMarker = document.getElementById( 'frm-end-form-marker' );
7412 + };
7413 +
7414 + this.append = function( field ) {
7415 + const classname = null !== field ? field.parentElement.classList : '';
7416 + if ( null === field || ( ! classname.contains( 'frm_field_box' ) && ! classname.contains( 'divider_section_only' ) ) ) {
7417 + return;
7418 + }
7419 + self.fragment.appendChild( field );
7420 + };
7421 +
7422 + this.moveFields = function() {
7423 + builderForm.insertBefore( self.fragment, moveFieldSettings.prototype.endMarker );
7424 + };
7425 +
7426 + this.initOnceInAllInstances();
7427 +
7428 + // Move the field if function is called as function with a singleField passed as arg.
7429 + // In this particular case only 1 field is needed to be moved so the field will get instantly moved.
7430 + // "singleField" may be undefined when it's called as a constructor instead of a function. Use the constructor to add multiple fields which are passed through "append" and move these all at once via "moveFields".
7431 + if ( 'undefined' !== typeof singleField ) {
7432 + this.append( singleField );
7433 + this.moveFields();
7434 + return;
7435 + }
7436 +
7437 + return {
7438 + append: this.append,
7439 + moveFields: this.moveFields
7440 + };
7441 +
7442 + }
7443 +
7444 + function showEmailRow() {
7445 + /*jshint validthis:true */
7446 + const actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' );
7447 + const rowType = this.getAttribute( 'data-emailrow' );
7448 +
7449 + jQuery( '#frm_form_action_' + actionKey + ' .frm_' + rowType + '_row' ).fadeIn( 'slow' );
7450 + jQuery( this ).fadeOut( 'slow' );
7451 + }
7452 +
7453 + function hideEmailRow() {
7454 + /*jshint validthis:true */
7455 + const actionBox = jQuery( this ).closest( '.frm_form_action_settings' ),
7456 + rowType = this.getAttribute( 'data-emailrow' ),
7457 + emailRowSelector = '.frm_' + rowType + '_row',
7458 + emailButtonSelector = '.frm_' + rowType + '_button';
7459 +
7460 + jQuery( actionBox ).find( emailButtonSelector ).fadeIn( 'slow' );
7461 + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow', function() {
7462 + jQuery( actionBox ).find( emailRowSelector + ' input' ).val( '' );
7463 + });
7464 + }
7465 +
7466 + function showEmailWarning() {
7467 + /*jshint validthis:true */
7468 + const actionBox = jQuery( this ).closest( '.frm_form_action_settings' ),
7469 + emailRowSelector = '.frm_from_to_match_row',
7470 + fromVal = actionBox.find( 'input[name$="[post_content][from]"]' ).val(),
7471 + toVal = actionBox.find( 'input[name$="[post_content][email_to]"]' ).val();
7472 +
7473 + if ( fromVal === toVal ) {
7474 + jQuery( actionBox ).find( emailRowSelector ).fadeIn( 'slow' );
7475 + } else {
7476 + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow' );
7477 + }
7478 + }
7479 +
7480 + function checkActiveAction( type ) {
7481 + const actionTriggers = document.querySelectorAll( '.frm_' + type + '_action' );
7482 +
7483 + if ( isAtLimitForActionType( type ) ) {
7484 + const addAlreadyUsedClass = getLimitForActionType( type ) > 0;
7485 + markActionTriggersInactive( actionTriggers, addAlreadyUsedClass );
7486 + return;
7487 + }
7488 +
7489 + markActionTriggersActive( actionTriggers );
7490 + }
7491 +
7492 + function markActionTriggersActive( triggers ) {
7493 + triggers.forEach(
7494 + trigger => {
7495 + if ( trigger.querySelector( '.frm_show_upgrade' ) ) {
7496 + // Prevent disabled action becoming active.
7497 + return;
7498 + }
7499 +
7500 + trigger.classList.remove( 'frm_inactive_action', 'frm_already_used' );
7501 + trigger.classList.add( 'frm_active_action' );
7502 + }
7503 + );
7504 + }
7505 +
7506 + function markActionTriggersInactive( triggers, addAlreadyUsedClass ) {
7507 + triggers.forEach(
7508 + trigger => {
7509 + trigger.classList.remove( 'frm_active_action' );
7510 + trigger.classList.add( 'frm_inactive_action' );
7511 + if ( addAlreadyUsedClass ) {
7512 + trigger.classList.add( 'frm_already_used' );
7513 + }
7514 + }
7515 + );
7516 + }
7517 +
7518 + function isAtLimitForActionType( type ) {
7519 + let atLimit = getNumberOfActionsForType( type ) >= getLimitForActionType( type );
7520 +
7521 + const hookName = 'frm_action_at_limit';
7522 + const hookArgs = { type };
7523 + atLimit = wp.hooks.applyFilters( hookName, atLimit, hookArgs );
7524 +
7525 + return atLimit;
7526 + }
7527 +
7528 + function getLimitForActionType( type ) {
7529 + return parseInt( jQuery( '.frm_' + type + '_action' ).data( 'limit' ), 10 );
7530 + }
7531 +
7532 + function getNumberOfActionsForType( type ) {
7533 + return jQuery( '.frm_single_' + type + '_settings' ).length;
7534 + }
7535 +
7536 + function actionLimitMessage() {
7537 + let message = frmAdminJs.only_one_action;
7538 + let limit = this.dataset.limit;
7539 +
7540 + if ( 'undefined' !== typeof limit ) {
7541 + limit = parseInt( limit );
7542 + if ( limit > 1 ) {
7543 + message = message.replace( 1, limit ).trim();
7544 + } else {
7545 + message += ' ' + frmAdminJs.edit_action_text;
7546 + }
7547 + }
7548 +
7549 + infoModal( message );
7550 + }
7551 +
7552 + function addFormLogicRow() {
7553 + /*jshint validthis:true */
7554 + const id = jQuery( this ).data( 'emailkey' );
7555 + const type = jQuery( this ).closest( '.frm_form_action_settings' ).find( '.frm_action_name' ).val();
7556 + const formId = document.getElementById( 'form_id' ).value;
7557 + const logicRowsContainer = document.getElementById( 'frm_logic_row_' + id );
7558 + const logicRows = logicRowsContainer.querySelectorAll( '.frm_logic_row' );
7559 + const newRowID = getNewRowId( logicRows, 'frm_logic_' + id + '_' );
7560 + const placeholder = div({
7561 + id: 'frm_logic_' + id + '_' + newRowID,
7562 + className: 'frm_logic_row frm_hidden'
7563 + });
7564 +
7565 + logicRowsContainer.appendChild( placeholder );
7566 + jQuery.ajax({
7567 + type: 'POST', url: ajaxurl,
7568 + data: {
7569 + action: 'frm_add_form_logic_row',
7570 + email_id: id,
7571 + form_id: formId,
7572 + meta_name: newRowID,
7573 + type: type,
7574 + nonce: frmGlobal.nonce
7575 + },
7576 + success: function( html ) {
7577 + jQuery( document.getElementById( 'logic_link_' + id ) ).fadeOut( 'slow', () => {
7578 + placeholder.insertAdjacentHTML( 'beforebegin', html );
7579 + placeholder.remove();
7580 +
7581 + // Show conditional logic options after "Add Conditional Logic" is clicked.
7582 + jQuery( logicRowsContainer ).parent( '.frm_logic_rows' ).fadeIn( 'slow' );
7583 + });
7584 + }
7585 + });
7586 + return false;
7587 + }
7588 +
7589 + function toggleSubmitLogic() {
7590 + /*jshint validthis:true */
7591 + if ( this.checked ) {
7592 + addSubmitLogic();
7593 + } else {
7594 + jQuery( '.frm_logic_row_submit' ).remove();
7595 + document.getElementById( 'frm_submit_logic_rows' ).style.display = 'none';
7596 + }
7597 + }
7598 +
7599 + /**
7600 + * Adds submit button Conditional Logic row and reveals submit button Conditional Logic
7601 + *
7602 + * @returns {boolean}
7603 + */
7604 + function addSubmitLogic() {
7605 + /*jshint validthis:true */
7606 + const formId = thisFormId,
7607 + logicRows = document.getElementById( 'frm_submit_logic_row' ).querySelectorAll( '.frm_logic_row' );
7608 + jQuery.ajax({
7609 + type: 'POST',
7610 + url: ajaxurl,
7611 + data: {
7612 + action: 'frm_add_submit_logic_row',
7613 + form_id: formId,
7614 + meta_name: getNewRowId( logicRows, 'frm_logic_submit_' ),
7615 + nonce: frmGlobal.nonce
7616 + },
7617 + success: function( html ) {
7618 + const $logicRow = jQuery( document.getElementById( 'frm_submit_logic_row' ) );
7619 + $logicRow.append( html );
7620 + $logicRow.parent( '.frm_submit_logic_rows' ).fadeIn( 'slow' );
7621 + }
7622 + });
7623 + return false;
7624 + }
7625 +
7626 + /**
7627 + * When the user selects a field for a submit condition, update corresponding options field accordingly.
7628 + */
7629 + function addSubmitLogicOpts() {
7630 + const fieldOpt = jQuery( this );
7631 + const fieldId = fieldOpt.find( ':selected' ).val();
7632 +
7633 + if ( fieldId ) {
7634 + const row = fieldOpt.data( 'row' );
7635 + frmGetFieldValues( fieldId, 'submit', row, '', 'options[submit_conditions][hide_opt][]' );
7636 + }
7637 + }
7638 +
7639 + function checkDupPost() {
7640 + /*jshint validthis:true */
7641 + const postField = jQuery( 'select.frm_single_post_field' );
7642 + postField.css( 'border-color', '' );
7643 + const $t = this;
7644 + const v = jQuery( $t ).val();
7645 + if ( v === '' || v === 'checkbox' ) {
7646 + return false;
7647 + }
7648 + postField.each( function() {
7649 + if ( jQuery( this ).val() === v && this.name !== $t.name ) {
7650 + this.style.borderColor = 'red';
7651 + jQuery( $t ).val( '' );
7652 + infoModal( frmAdminJs.field_already_used );
7653 + return false;
7654 + }
7655 + });
7656 + }
7657 +
7658 + function togglePostContent() {
7659 + /*jshint validthis:true */
7660 + const v = jQuery( this ).val();
7661 + if ( '' === v ) {
7662 + jQuery( '.frm_post_content_opt, select.frm_dyncontent_opt' ).hide().val( '' );
7663 + jQuery( '.frm_dyncontent_opt' ).hide();
7664 + } else if ( 'post_content' === v ) {
7665 + jQuery( '.frm_post_content_opt' ).show();
7666 + jQuery( '.frm_dyncontent_opt' ).hide();
7667 + jQuery( 'select.frm_dyncontent_opt' ).val( '' );
7668 + } else {
7669 + jQuery( '.frm_post_content_opt' ).hide().val( '' );
7670 + jQuery( 'select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt' ).show();
7671 + }
7672 + }
7673 +
7674 + function fillDyncontent() {
7675 + /*jshint validthis:true */
7676 + const v = jQuery( this ).val();
7677 + const $dyn = jQuery( document.getElementById( 'frm_dyncontent' ) );
7678 + if ( '' === v || 'new' === v ) {
7679 + $dyn.val( '' );
7680 + jQuery( '.frm_dyncontent_opt' ).show();
7681 + } else {
7682 + jQuery.ajax({
7683 + type: 'POST', url: ajaxurl,
7684 + data: {action: 'frm_display_get_content', id: v, nonce: frmGlobal.nonce},
7685 + success: function( val ) {
7686 + $dyn.val( val );
7687 + jQuery( '.frm_dyncontent_opt' ).show();
7688 + }
7689 + });
7690 + }
7691 + }
7692 +
7693 + function switchPostType() {
7694 + /*jshint validthis:true */
7695 + // update all rows of categories/taxonomies
7696 + let curSelect, newSelect,
7697 + catRows = document.getElementById( 'frm_posttax_rows' ).childNodes,
7698 + postParentField = document.querySelector( '.frm_post_parent_field' ),
7699 + postMenuOrderField = document.querySelector( '.frm_post_menu_order_field' ),
7700 + postType = this.value;
7701 +
7702 + // Get new category/taxonomy options
7703 + jQuery.ajax({
7704 + type: 'POST',
7705 + url: ajaxurl,
7706 + data: {
7707 + action: 'frm_replace_posttax_options',
7708 + post_type: postType,
7709 + nonce: frmGlobal.nonce
7710 + },
7711 + success: function( html ) {
7712 +
7713 + // Loop through each category row, and replace the first dropdown
7714 + for ( i = 0; i < catRows.length; i++ ) {
7715 + // Check if current element is a div
7716 + if ( catRows[i].tagName !== 'DIV' ) {
7717 + continue;
7718 + }
7719 +
7720 + // Get current category select
7721 + curSelect = catRows[i].getElementsByTagName( 'select' )[0];
7722 +
7723 + // Set up new select
7724 + newSelect = document.createElement( 'select' );
7725 + newSelect.innerHTML = html;
7726 + newSelect.className = curSelect.className;
7727 + newSelect.name = curSelect.name;
7728 +
7729 + // Replace the old select with the new select
7730 + catRows[i].replaceChild( newSelect, curSelect );
7731 + }
7732 + }
7733 + });
7734 +
7735 + // Get new post parent option.
7736 + if ( postParentField ) {
7737 + getActionOption(
7738 + postParentField,
7739 + postType,
7740 + 'frm_get_post_parent_option',
7741 + function( response, optName ) {
7742 + // The replaced string is declared in FrmProFormActionController::ajax_get_post_menu_order_option() in the pro version.
7743 + postParentField.querySelector( '.frm_post_parent_opt_wrapper' ).innerHTML = response.replaceAll( 'REPLACETHISNAME', optName );
7744 + frmDom.autocomplete.initAutocomplete( 'page', postParentField );
7745 + }
7746 + );
7747 + }
7748 +
7749 + if ( postMenuOrderField ) {
7750 + getActionOption( postMenuOrderField, postType, 'frm_should_use_post_menu_order_option' );
7751 + }
7752 + }
7753 +
7754 + function getActionOption( field, postType, action, successHandler ) {
7755 + const opt = field.querySelector( '.frm_autocomplete_value_input' ) || field.querySelector( 'select' ),
7756 + optName = opt.getAttribute( 'name' );
7757 +
7758 + jQuery.ajax({
7759 + url: ajaxurl,
7760 + method: 'POST',
7761 + data: {
7762 + action: action,
7763 + post_type: postType,
7764 + _wpnonce: frmGlobal.nonce
7765 + },
7766 + success: response => {
7767 + if ( 'string' !== typeof response ) {
7768 + console.error( response );
7769 + return;
7770 + }
7771 +
7772 + if ( '0' === response ) {
7773 + // This post type does not support this field.
7774 + field.classList.add( 'frm_hidden' );
7775 + field.value = '';
7776 + return;
7777 + }
7778 +
7779 + field.classList.remove( 'frm_hidden' );
7780 +
7781 + if ( 'function' === typeof successHandler ) {
7782 + successHandler( response, optName );
7783 + }
7784 + },
7785 + error: response => console.error( response )
7786 + });
7787 + }
7788 +
7789 + function addPosttaxRow() {
7790 + /*jshint validthis:true */
7791 + addPostRow( 'tax', this );
7792 + }
7793 +
7794 + function addPostmetaRow() {
7795 + /*jshint validthis:true */
7796 + addPostRow( 'meta', this );
7797 + }
7798 +
7799 + function addPostRow( type, button ) {
7800 + let name,
7801 + id = jQuery( 'input[name="id"]' ).val(),
7802 + settings = jQuery( button ).closest( '.frm_form_action_settings' ),
7803 + key = settings.data( 'actionkey' ),
7804 + postType = settings.find( '.frm_post_type' ).val(),
7805 + metaName = 0,
7806 + postTypeRows = document.querySelectorAll( '.frm_post' + type + '_row' );
7807 +
7808 + if ( postTypeRows.length ) {
7809 + name = postTypeRows[ postTypeRows.length - 1 ].id.replace( 'frm_post' + type + '_', '' );
7810 + if ( isNumeric( name ) ) {
7811 + metaName = 1 + parseInt( name, 10 );
7812 + } else {
7813 + metaName = 1;
7814 + }
7815 + }
7816 +
7817 + jQuery.ajax({
7818 + type: 'POST', url: ajaxurl,
7819 + data: {
7820 + action: 'frm_add_post' + type + '_row',
7821 + form_id: id,
7822 + meta_name: metaName,
7823 + tax_key: metaName,
7824 + post_type: postType,
7825 + action_key: key,
7826 + nonce: frmGlobal.nonce
7827 + },
7828 + success: function( html ) {
7829 + let cfOpts, optIndex;
7830 + jQuery( document.getElementById( 'frm_post' + type + '_rows' ) ).append( html );
7831 + jQuery( '.frm_add_post' + type + '_row.button' ).hide();
7832 +
7833 + if ( type === 'meta' ) {
7834 + jQuery( '.frm_name_value' ).show();
7835 + cfOpts = document.querySelectorAll( '.frm_toggle_cf_opts' );
7836 + for ( optIndex = 0; optIndex < cfOpts.length - 1; ++optIndex ) {
7837 + cfOpts[ optIndex ].style.display = 'none';
7838 + }
7839 + } else if ( type === 'tax' ) {
7840 + jQuery( '.frm_posttax_labels' ).show();
7841 + }
7842 + }
7843 + });
7844 + }
7845 +
7846 + function isNumeric( value ) {
7847 + return ! isNaN( parseFloat( value ) ) && isFinite( value );
7848 + }
7849 +
7850 + function changePosttaxRow() {
7851 + /*jshint validthis:true */
7852 + if ( ! jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).length ) {
7853 + return;
7854 + }
7855 +
7856 + jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).html( '<div class="spinner frm_spinner" style="display:block"></div>' );
7857 +
7858 + const postType = jQuery( this ).closest( '.frm_form_action_settings' ).find( 'select[name$="[post_content][post_type]"]' ).val(),
7859 + actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ),
7860 + taxKey = jQuery( this ).closest( '.frm_posttax_row' ).attr( 'id' ).replace( 'frm_posttax_', '' ),
7861 + metaName = jQuery( this ).val(),
7862 + showExclude = jQuery( document.getElementById( taxKey + '_show_exclude' ) ).is( ':checked' ) ? 1 : 0,
7863 + fieldId = jQuery( 'select[name$="[post_category][' + taxKey + '][field_id]"]' ).val(),
7864 + id = jQuery( 'input[name="id"]' ).val();
7865 +
7866 + jQuery.ajax({
7867 + type: 'POST',
7868 + url: ajaxurl,
7869 + data: {
7870 + action: 'frm_add_posttax_row',
7871 + form_id: id,
7872 + post_type: postType,
7873 + tax_key: taxKey,
7874 + action_key: actionKey,
7875 + meta_name: metaName,
7876 + field_id: fieldId,
7877 + show_exclude: showExclude,
7878 + nonce: frmGlobal.nonce
7879 + },
7880 + success: function( html ) {
7881 + const $tax = jQuery( document.getElementById( 'frm_posttax_' + taxKey ) );
7882 + $tax.replaceWith( html );
7883 + }
7884 + });
7885 + }
7886 +
7887 + function toggleCfOpts() {
7888 + /*jshint validthis:true */
7889 + const row = jQuery( this ).closest( '.frm_postmeta_row' );
7890 + const cancel = row.find( '.frm_cancelnew' );
7891 + const select = row.find( '.frm_enternew' );
7892 + if ( row.find( 'select.frm_cancelnew' ).is( ':visible' ) ) {
7893 + cancel.hide();
7894 + select.show();
7895 + } else {
7896 + cancel.show();
7897 + select.hide();
7898 + }
7899 +
7900 + row.find( 'input.frm_enternew, select.frm_cancelnew' ).val( '' );
7901 + return false;
7902 + }
7903 +
7904 + function toggleFormOpts() {
7905 + /*jshint validthis:true */
7906 + const changedOpt = jQuery( this );
7907 + let val = changedOpt.val();
7908 + if ( changedOpt.attr( 'type' ) === 'checkbox' ) {
7909 + if ( this.checked === false ) {
7910 + val = '';
7911 + }
7912 + }
7913 +
7914 + const toggleClass = changedOpt.data( 'toggleclass' );
7915 + if ( val === '' ) {
7916 + jQuery( '.' + toggleClass ).hide();
7917 + } else {
7918 + jQuery( '.' + toggleClass ).show();
7919 + jQuery( '.hide_' + toggleClass + '_' + val ).hide();
7920 + }
7921 + }
7922 +
7923 + function submitSettings() {
7924 + if ( showNameYourFormModal() ) {
7925 + return;
7926 + }
7927 +
7928 + /*jshint validthis:true */
7929 + preFormSave( this );
7930 + triggerSubmit( document.querySelector( '.frm_form_settings' ) );
7931 + }
7932 +
7933 + /* View Functions */
7934 + function showCount() {
7935 + /*jshint validthis:true */
7936 + const value = jQuery( this ).val();
7937 +
7938 + const $cont = document.getElementById( 'date_select_container' );
7939 + const tab = document.getElementById( 'frm_listing_tab' );
7940 + let label = tab.getAttribute( 'data-label' );
7941 + if ( value === 'calendar' ) {
7942 + jQuery( '.hide_dyncontent, .hide_single_content' ).removeClass( 'frm_hidden' );
7943 + jQuery( '.limit_container' ).addClass( 'frm_hidden' );
7944 + $cont.style.display = 'block';
7945 + } else if ( value === 'dynamic' ) {
7946 + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).removeClass( 'frm_hidden' );
7947 + } else if ( value === 'one' ) {
7948 + label = tab.getAttribute( 'data-one' );
7949 + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).addClass( 'frm_hidden' );
7950 + } else {
7951 + jQuery( '.hide_dyncontent' ).addClass( 'frm_hidden' );
7952 + jQuery( '.limit_container, .hide_single_content' ).removeClass( 'frm_hidden' );
7953 + }
7954 +
7955 + if ( value !== 'calendar' ) {
7956 + $cont.style.display = 'none';
7957 + }
7958 + tab.innerHTML = label;
7959 + }
7960 +
7961 + function displayFormSelected() {
7962 + /*jshint validthis:true */
7963 + const formId = jQuery( this ).val();
7964 + thisFormId = formId; // set the global form id
7965 + if ( formId === '' ) {
7966 + return;
7967 + }
7968 +
7969 + jQuery.ajax({
7970 + type: 'POST',
7971 + url: ajaxurl,
7972 + data: {
7973 + action: 'frm_get_cd_tags_box',
7974 + form_id: formId,
7975 + nonce: frmGlobal.nonce
7976 + },
7977 + success: function( html ) {
7978 + jQuery( '#frm_adv_info .categorydiv' ).html( html );
7979 + }
7980 + });
7981 +
7982 + jQuery.ajax({
7983 + type: 'POST',
7984 + url: ajaxurl,
7985 + data: {
7986 + action: 'frm_get_date_field_select',
7987 + form_id: formId,
7988 + nonce: frmGlobal.nonce
7989 + },
7990 + success: function( html ) {
7991 + jQuery( document.getElementById( 'date_select_container' ) ).html( html );
7992 + }
7993 + });
7994 + }
7995 +
7996 + function clickTabsAfterAjax() {
7997 + /*jshint validthis:true */
7998 + const t = jQuery( this ).attr( 'href' );
7999 + jQuery( this ).parent().addClass( 'tabs' ).siblings( 'li' ).removeClass( 'tabs' );
8000 + jQuery( t ).show().siblings( '.tabs-panel' ).hide();
8001 + return false;
8002 + }
8003 +
8004 + function clickContentTab() {
8005 + /*jshint validthis:true */
8006 + link = jQuery( this );
8007 + const t = link.attr( 'href' );
8008 + if ( typeof t === 'undefined' ) {
8009 + return false;
8010 + }
8011 +
8012 + const c = t.replace( '#', '.' );
8013 + link.closest( '.nav-tab-wrapper' ).find( 'a' ).removeClass( 'nav-tab-active' );
8014 + link.addClass( 'nav-tab-active' );
8015 + jQuery( '.nav-menu-content' ).not( t ).not( c ).hide();
8016 + jQuery( t + ',' + c ).show();
8017 +
8018 + return false;
8019 + }
8020 +
8021 + function addOrderRow() {
8022 + const logicRows = document.getElementById( 'frm_order_options' ).querySelectorAll( '.frm_logic_rows div' );
8023 + jQuery.ajax({
8024 + type: 'POST',
8025 + url: ajaxurl,
8026 + data: {
8027 + action: 'frm_add_order_row',
8028 + form_id: thisFormId,
8029 + order_key: getNewRowId( logicRows, 'frm_order_field_', 1 ),
8030 + nonce: frmGlobal.nonce
8031 + },
8032 + success: function( html ) {
8033 + jQuery( '#frm_order_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_order_row' ).hide();
8034 + }
8035 + });
8036 + }
8037 +
8038 + function addWhereRow() {
8039 + const rowDivs = document.getElementById( 'frm_where_options' ).querySelectorAll( '.frm_logic_rows div' );
8040 + jQuery.ajax({
8041 + type: 'POST',
8042 + url: ajaxurl,
8043 + data: {
8044 + action: 'frm_add_where_row',
8045 + form_id: thisFormId,
8046 + where_key: getNewRowId( rowDivs, 'frm_where_field_', 1 ),
8047 + nonce: frmGlobal.nonce
8048 + },
8049 + success: function( html ) {
8050 + jQuery( '#frm_where_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_where_row' ).hide();
8051 + }
8052 + });
8053 + }
8054 +
8055 + function insertWhereOptions() {
8056 + /*jshint validthis:true */
8057 + const value = this.value,
8058 + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' );
8059 +
8060 + jQuery.ajax({
8061 + type: 'POST',
8062 + url: ajaxurl,
8063 + data: {
8064 + action: 'frm_add_where_options',
8065 + where_key: whereKey,
8066 + field_id: value,
8067 + nonce: frmGlobal.nonce
8068 + },
8069 + success: function( html ) {
8070 + jQuery( document.getElementById( 'where_field_options_' + whereKey ) ).html( html );
8071 + }
8072 + });
8073 + }
8074 +
8075 + function hideWhereOptions() {
8076 + /*jshint validthis:true */
8077 + const value = this.value,
8078 + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' );
8079 +
8080 + if ( value === 'group_by' || value === 'group_by_newest' ) {
8081 + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'none';
8082 + } else {
8083 + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'inline-block';
8084 + }
8085 + }
8086 +
8087 + function setDefaultPostStatus() {
8088 + const urlQuery = window.location.search.substring( 1 );
8089 + if ( urlQuery.indexOf( 'action=edit' ) === -1 ) {
8090 + document.getElementById( 'post-visibility-display' ).textContent = frmAdminJs.private_label;
8091 + document.getElementById( 'hidden-post-visibility' ).value = 'private';
8092 + document.getElementById( 'visibility-radio-private' ).checked = true;
8093 + }
8094 + }
8095 +
8096 + /* Customization Panel */
8097 + function insertCode( e ) {
8098 + /*jshint validthis:true */
8099 + e.preventDefault();
8100 + insertFieldCode( jQuery( this ), this.getAttribute( 'data-code' ) );
8101 + return false;
8102 + }
8103 +
8104 + function insertFieldCode( element, variable ) {
8105 + let rich = false,
8106 + elementId = element;
8107 + if ( typeof element === 'object' ) {
8108 + if ( element.hasClass( 'frm_noallow' ) ) {
8109 + return;
8110 + }
8111 +
8112 + elementId = jQuery( element ).closest( '[data-fills]' ).attr( 'data-fills' );
8113 + if ( typeof elementId === 'undefined' ) {
8114 + elementId = element.closest( 'div' ).attr( 'class' );
8115 + if ( typeof elementId !== 'undefined' ) {
8116 + elementId = elementId.split( ' ' )[1];
8117 + }
8118 + }
8119 + }
8120 +
8121 + if ( typeof elementId === 'undefined' ) {
8122 + let active = document.activeElement;
8123 + if ( active.type === 'search' ) {
8124 + // If the search field has focus, find the correct field.
8125 + elementId = active.id.replace( '-search-input', '' );
8126 + if ( elementId.match( /\d/gi ) === null ) {
8127 + active = jQuery( '.frm-single-settings:visible .' + elementId );
8128 + elementId = active.attr( 'id' );
8129 + }
8130 + } else {
8131 + elementId = active.id;
8132 + }
8133 + }
8134 +
8135 + if ( elementId ) {
8136 + rich = jQuery( '#wp-' + elementId + '-wrap.wp-editor-wrap' ).length > 0;
8137 + }
8138 +
8139 + const contentBox = jQuery( document.getElementById( elementId ) );
8140 + if ( typeof element.attr( 'data-shortcode' ) === 'undefined' && ( ! contentBox.length || typeof contentBox.attr( 'data-shortcode' ) === 'undefined' ) ) {
8141 + // this helps to exclude those that don't want shortcode-like inserted content e.g. frm-pro's summary field
8142 + const doShortcode = element.parents( 'ul.frm_code_list' ).attr( 'data-shortcode' );
8143 + if ( doShortcode === 'undefined' || doShortcode !== 'no' ) {
8144 + variable = '[' + variable + ']';
8145 + }
8146 + }
8147 +
8148 + if ( rich ) {
8149 + wpActiveEditor = elementId;
8150 + }
8151 +
8152 + if ( ! contentBox.length ) {
8153 + return false;
8154 + }
8155 +
8156 + if ( variable === '[default-html]' || variable === '[default-plain]' ) {
8157 + let p = 0;
8158 + if ( variable === '[default-plain]' ) {
8159 + p = 1;
8160 + }
8161 + jQuery.ajax({
8162 + type: 'POST', url: ajaxurl,
8163 + data: {
8164 + action: 'frm_get_default_html',
8165 + form_id: jQuery( 'input[name="id"]' ).val(),
8166 + plain_text: p,
8167 + nonce: frmGlobal.nonce
8168 + },
8169 + elementId: elementId,
8170 + success: function( msg ) {
8171 + if ( rich ) {
8172 + const p = document.createElement( 'p' );
8173 + p.innerText = msg;
8174 + send_to_editor( p.innerHTML );
8175 + } else {
8176 + insertContent( contentBox, msg );
8177 + }
8178 + }
8179 + });
8180 + } else {
8181 + variable = maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox );
8182 + if ( rich ) {
8183 + send_to_editor( variable );
8184 + } else {
8185 + insertContent( contentBox, variable );
8186 + }
8187 + }
8188 + return false;
8189 + }
8190 +
8191 + function maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox ) {
8192 + if ( 'object' !== typeof element || ! ( element instanceof jQuery ) || 0 !== contentBox[0].id.indexOf( 'success_url_' ) ) {
8193 + return variable;
8194 + }
8195 +
8196 + element = element[0];
8197 + if ( ! element.closest( '#frm-insert-fields-box' ) ) {
8198 + // Only add sanitize_url=1 to field shortcodes.
8199 + return variable;
8200 + }
8201 +
8202 + if ( ! element.parentNode.classList.contains( 'frm_insert_url' ) ) {
8203 + variable = variable.replace( ']', ' sanitize_url=1]' );
8204 + }
8205 +
8206 + return variable;
8207 + }
8208 +
8209 + function insertContent( contentBox, variable ) {
8210 + if ( document.selection ) {
8211 + contentBox[0].focus();
8212 + document.selection.createRange().text = variable;
8213 + } else {
8214 + obj = contentBox[0];
8215 + const e = obj.selectionEnd;
8216 +
8217 + variable = maybeFormatInsertedContent( contentBox, variable, obj.selectionStart, e );
8218 +
8219 + obj.value = obj.value.substr( 0, obj.selectionStart ) + variable + obj.value.substr( obj.selectionEnd, obj.value.length );
8220 +
8221 + const s = e + variable.length;
8222 +
8223 + maybeRemoveLayoutClasses( obj, variable );
8224 +
8225 + obj.focus();
8226 + obj.setSelectionRange( s, s );
8227 + }
8228 + triggerChange( contentBox );
8229 + }
8230 +
8231 + /**
8232 + * When a layout class is added, remove any previous layout classes to avoid conflicts.
8233 + * We only expect one layout class to exist for a given field.
8234 + * For example, if a field has frm_half and we set it to frm_third, frm_half will be removed.
8235 + *
8236 + * @since 6.11
8237 + *
8238 + * @param {HTMLElement} obj
8239 + * @param {string} variable
8240 + * @return {void}
8241 + */
8242 + function maybeRemoveLayoutClasses( obj, variable ) {
8243 + if ( ! obj.classList.contains( 'frm_classes' ) || ! isALayoutClass( variable ) ) {
8244 + return;
8245 + }
8246 +
8247 + const removeClasses = obj.value.split( ' ' ).filter( isALayoutClass );
8248 + if ( removeClasses.length ) {
8249 + obj.value = maybeRemoveClasses( obj.value, removeClasses, variable.trim() );
8250 + }
8251 + }
8252 +
8253 + /**
8254 + * Check if a given class is a layout class.
8255 + *
8256 + * @since 6.11
8257 + *
8258 + * @param {string} className
8259 + * @return {boolean}
8260 + */
8261 + function isALayoutClass( className ) {
8262 + let layoutClasses = [ 'frm_half', 'frm_third', 'frm_two_thirds', 'frm_fourth', 'frm_three_fourths', 'frm_fifth', 'frm_sixth', 'frm2', 'frm3', 'frm4', 'frm6', 'frm8', 'frm9', 'frm10', 'frm12' ];
8263 + return layoutClasses.includes( className.trim() );
8264 + }
8265 +
8266 + /**
8267 + * @since 6.11
8268 + *
8269 + * @param {string} beforeValue
8270 + * @param {Array} removeClasses
8271 + * @param {string} variable
8272 + * @return {string}
8273 + */
8274 + function maybeRemoveClasses( beforeValue, removeClasses, variable ) {
8275 + const currentClasses = beforeValue.split( ' ' ).filter(
8276 + currentClass => {
8277 + currentClass = currentClass.trim();
8278 + return currentClass.length && ! removeClasses.includes( currentClass );
8279 + }
8280 + );
8281 + if ( ! currentClasses.includes( variable ) ) {
8282 + currentClasses.push( variable );
8283 + }
8284 + return currentClasses.join( ' ' );
8285 + }
8286 +
8287 + function maybeFormatInsertedContent( input, textToInsert, selectionStart, selectionEnd ) {
8288 + const separator = input.data( 'sep' );
8289 + if ( undefined === separator ) {
8290 + return textToInsert;
8291 + }
8292 +
8293 + const value = input.val();
8294 +
8295 + if ( ! value.trim().length ) {
8296 + return textToInsert;
8297 + }
8298 +
8299 + const startPattern = new RegExp( separator + '\\s*$' );
8300 + const endPattern = new RegExp( '^\\s*' + separator );
8301 +
8302 + if ( value.substr( 0, selectionStart ).trim().length && false === startPattern.test( value.substr( 0, selectionStart ) ) ) {
8303 + textToInsert = separator + textToInsert;
8304 + }
8305 +
8306 + if ( value.substr( selectionEnd, value.length ).trim().length && false === endPattern.test( value.substr( selectionEnd, value.length ) ) ) {
8307 + textToInsert += separator;
8308 + }
8309 +
8310 + return textToInsert;
8311 + }
8312 +
8313 + function resetLogicBuilder() {
8314 + /*jshint validthis:true */
8315 + const id = document.getElementById( 'frm-id-condition' ),
8316 + key = document.getElementById( 'frm-key-condition' );
8317 +
8318 + if ( this.checked ) {
8319 + id.classList.remove( 'frm_hidden' );
8320 + key.classList.add( 'frm_hidden' );
8321 + triggerEvent( key, 'change' );
8322 + } else {
8323 + id.classList.add( 'frm_hidden' );
8324 + key.classList.remove( 'frm_hidden' );
8325 + triggerEvent( id, 'change' );
8326 + }
8327 + }
8328 +
8329 + function setLogicExample() {
8330 + let field, code,
8331 + idKey = document.getElementById( 'frm-id-key-condition' ).checked ? 'frm-id-condition' : 'frm-key-condition',
8332 + is = document.getElementById( 'frm-is-condition' ).value,
8333 + text = document.getElementById( 'frm-text-condition' ).value,
8334 + result = document.getElementById( 'frm-insert-condition' );
8335 +
8336 + idKey = document.getElementById( idKey );
8337 + field = idKey.options[idKey.selectedIndex].value;
8338 + code = 'if ' + field + ' ' + is + '="' + text + '"]';
8339 + result.setAttribute( 'data-code', code + frmAdminJs.conditional_text + '[/if ' + field );
8340 + result.innerHTML = '[' + code + '[/if ' + field + ']';
8341 + }
8342 +
8343 + function showBuilderModal() {
8344 + /*jshint validthis:true */
8345 + const moreIcon = getIconForInput( this );
8346 + showInlineModal( moreIcon, this );
8347 + }
8348 +
8349 + function maybeShowModal( input ) {
8350 + let moreIcon;
8351 + if ( input.parentNode.parentNode.classList.contains( 'frm_has_shortcodes' ) ) {
8352 + hideShortcodes();
8353 + moreIcon = getIconForInput( input );
8354 + if ( moreIcon.tagName === 'use' ) {
8355 + moreIcon = moreIcon.firstElementChild;
8356 +
8357 + if ( moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ).indexOf( 'frm_close_icon' ) === -1 ) {
8358 + showShortcodeBox( moreIcon, 'nofocus' );
8359 + }
8360 + } else if ( ! moreIcon.classList.contains( 'frm_close_icon' ) ) {
8361 + showShortcodeBox( moreIcon, 'nofocus' );
8362 + }
8363 + }
8364 + }
8365 +
8366 + function showShortcodes( e ) {
8367 + /*jshint validthis:true */
8368 + e.preventDefault();
8369 + e.stopPropagation();
8370 +
8371 + showShortcodeBox( this );
8372 + }
8373 +
8374 + function updateShortcodesPopupPosition( target ) {
8375 + let moreIcon;
8376 + if ( target instanceof Event ) {
8377 + const useElements = document.querySelectorAll( '.frm-single-settings .frm-show-box.frmsvg use' );
8378 + const openTrigger = Array.from( useElements ).find( use => use.getAttribute( 'href' ) === '#frm_close_icon' );
8379 + if ( 'undefined' === typeof openTrigger ) {
8380 + return;
8381 + }
8382 + moreIcon = openTrigger.parentElement;
8383 + } else {
8384 + moreIcon = target;
8385 + }
8386 +
8387 + const moreIconPosition = moreIcon.getBoundingClientRect();
8388 + const shortCodesPopup = document.getElementById( 'frm_adv_info' );
8389 + const parentPos = shortCodesPopup.parentElement.getBoundingClientRect();
8390 +
8391 + shortCodesPopup.style.top = ( moreIconPosition.top - parentPos.top + 32 ) + 'px';
8392 + shortCodesPopup.style.left = ( moreIconPosition.left - parentPos.left - 280 ) + 'px';
8393 + }
8394 +
8395 + function showShortcodeBox( moreIcon, shouldFocus ) {
8396 + let input = getInputForIcon( moreIcon ),
8397 + box = document.getElementById( 'frm_adv_info' ),
8398 + classes = moreIcon.className;
8399 +
8400 + if ( moreIcon.tagName === 'svg' ) {
8401 + moreIcon = moreIcon.firstElementChild;
8402 + }
8403 + if ( moreIcon.tagName === 'use' ) {
8404 + classes = moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' );
8405 +
8406 + if ( null === classes ) {
8407 + // If the deprecated xlink:href is not defined, check for href.
8408 + classes = moreIcon.getAttribute( 'href' );
8409 + }
8410 + }
8411 +
8412 + if ( classes.indexOf( 'frm_close_icon' ) !== -1 ) {
8413 + hideShortcodes( box );
8414 + } else {
8415 + updateShortcodesPopupPosition( moreIcon );
8416 +
8417 + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' );
8418 + if ( input.classList.contains( 'frm_not_email_to' ) ) {
8419 + jQuery( '#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a' ).addClass( 'frm_noallow' );
8420 + } else if ( input.classList.contains( 'frm_not_email_subject' ) ) {
8421 + jQuery( '.frm_code_list li.hide_frm_not_email_subject a' ).addClass( 'frm_noallow' );
8422 + }
8423 +
8424 + box.setAttribute( 'data-fills', input.id );
8425 + box.style.display = 'block';
8426 +
8427 + if ( moreIcon.tagName === 'use' ) {
8428 + if ( moreIcon.hasAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) ) {
8429 + moreIcon.setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_close_icon' );
8430 + } else {
8431 + const newMoreIcon = document.createElementNS( 'http://www.w3.org/2000/svg', 'use' );
8432 + newMoreIcon.setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_close_icon' );
8433 + moreIcon.parentNode.replaceChild( newMoreIcon, moreIcon );
8434 + }
8435 + } else {
8436 + moreIcon.className = classes.replace( 'frm_more_horiz_solid_icon', 'frm_close_icon' );
8437 + }
8438 +
8439 + if ( shouldFocus !== 'nofocus' ) {
8440 + if ( 'none' !== input.style.display ) {
8441 + input.focus();
8442 + } else {
8443 + jQuery( tinymce.get( input.id ) ).trigger( 'focus' );
8444 + }
8445 + }
8446 + }
8447 + }
8448 +
8449 + function fieldUpdated() {
8450 + if ( ! fieldsUpdated ) {
8451 + fieldsUpdated = 1;
8452 + window.addEventListener( 'beforeunload', confirmExit );
8453 + }
8454 + }
8455 +
8456 + function buildSubmittedNoAjax() {
8457 + // set fieldsUpdated to 0 to avoid the unsaved changes pop up
8458 + fieldsUpdated = 0;
8459 + }
8460 +
8461 + function settingsSubmitted() {
8462 + // set fieldsUpdated to 0 to avoid the unsaved changes pop up
8463 + fieldsUpdated = 0;
8464 + }
8465 +
8466 + function saveAndReloadSettings() {
8467 + let page, form;
8468 + page = document.getElementById( 'form_settings_page' );
8469 + if ( null !== page ) {
8470 + form = page.querySelector( 'form.frm_form_settings' );
8471 + if ( null !== form ) {
8472 + fieldsUpdated = 0;
8473 + form.submit();
8474 + }
8475 + }
8476 + }
8477 +
8478 + function reloadIfAddonActivatedAjaxSubmitOnly() {
8479 + const submitButton = document.getElementById( 'frm_submit_side_top' );
8480 + if ( submitButton.hasAttribute( 'data-new-addon-installed' ) && 'true' === submitButton.getAttribute( 'data-new-addon-installed' ) ) {
8481 + submitButton.removeAttribute( 'data-new-addon-installed' );
8482 + window.location.reload();
8483 + }
8484 +
8485 + }
8486 +
8487 + function saveAndReloadFormBuilder() {
8488 + const submitButton = document.getElementById( 'frm_submit_side_top' );
8489 + if ( submitButton.classList.contains( 'frm_submit_ajax' ) ) {
8490 + submitButton.setAttribute( 'data-new-addon-installed', true );
8491 + }
8492 + submitButton.click();
8493 + }
8494 +
8495 + function confirmExit( event ) {
8496 + if ( fieldsUpdated ) {
8497 + event.preventDefault();
8498 + event.returnValue = '';
8499 + }
8500 + }
8501 +
8502 + function bindClickForDialogClose( $modal ) {
8503 + const closeModal = function() {
8504 + $modal.dialog( 'close' );
8505 + };
8506 + jQuery( '.ui-widget-overlay' ).on( 'click', closeModal );
8507 + $modal.on( 'click', 'a.dismiss', closeModal );
8508 + }
8509 +
8510 + function offsetModalY( $modal, amount ) {
8511 + const position = {
8512 + my: 'top',
8513 + at: 'top+' + amount,
8514 + of: window
8515 + };
8516 + $modal.dialog( 'option', 'position', position );
8517 + }
8518 +
8519 + /**
8520 + * Get the input box for the selected ... icon.
8521 + */
8522 + function getInputForIcon( moreIcon ) {
8523 + let input = moreIcon.nextElementSibling;
8524 +
8525 + while ( input !== null && input.tagName !== 'INPUT' && input.tagName !== 'TEXTAREA' ) {
8526 + input = getInputForIcon( input );
8527 + }
8528 +
8529 + return input;
8530 + }
8531 +
8532 + /**
8533 + * Get the ... icon for the selected input box.
8534 + */
8535 + function getIconForInput( input ) {
8536 + let moreIcon = input.previousElementSibling;
8537 +
8538 + while ( moreIcon !== null && moreIcon.tagName !== 'I' && moreIcon.tagName !== 'svg' ) {
8539 + moreIcon = getIconForInput( moreIcon );
8540 + }
8541 +
8542 + return moreIcon;
8543 + }
8544 +
8545 + function hideShortcodes( box ) {
8546 + let i, u, closeIcons, closeSvg;
8547 + if ( typeof box === 'undefined' ) {
8548 + box = document.getElementById( 'frm_adv_info' );
8549 + if ( box === null ) {
8550 + return;
8551 + }
8552 + }
8553 +
8554 + if ( document.getElementById( 'frm_dyncontent' ) !== null ) {
8555 + // Don't run when in the sidebar.
8556 + return;
8557 + }
8558 +
8559 + box.style.display = 'none';
8560 +
8561 + closeIcons = document.querySelectorAll( '.frm-show-box.frm_close_icon' );
8562 + for ( i = 0; i < closeIcons.length; i++ ) {
8563 + closeIcons[i].classList.remove( 'frm_close_icon' );
8564 + closeIcons[i].classList.add( 'frm_more_horiz_solid_icon' );
8565 + }
8566 +
8567 + closeSvg = document.querySelectorAll( '.frm_has_shortcodes use' );
8568 + for ( u = 0; u < closeSvg.length; u++ ) {
8569 + if ( closeSvg[u].getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) === '#frm_close_icon' ) {
8570 + closeSvg[u].setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_more_horiz_solid_icon' );
8571 + }
8572 + }
8573 + }
8574 +
8575 + function initToggleShortcodes() {
8576 + if ( typeof tinymce !== 'object' ) {
8577 + return;
8578 + }
8579 +
8580 + DOM = tinymce.DOM;
8581 + if ( typeof DOM.events !== 'undefined' && typeof DOM.events.add !== 'undefined' ) {
8582 + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseover', function() {
8583 + if ( jQuery( '*:focus' ).length > 0 ) {
8584 + return;
8585 + }
8586 + if ( this.id ) {
8587 + toggleAllowedShortcodes( this.id.slice( 3, -5 ) );
8588 + }
8589 + });
8590 + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseout', function() {
8591 + if ( jQuery( '*:focus' ).length > 0 ) {
8592 + return;
8593 + }
8594 + if ( this.id ) {
8595 + toggleAllowedShortcodes( this.id.slice( 3, -5 ) );
8596 + }
8597 + });
8598 + } else {
8599 + jQuery( '#frm_dyncontent' ).on( 'mouseover mouseout', '.wp-editor-wrap', function() {
8600 + if ( jQuery( '*:focus' ).length > 0 ) {
8601 + return;
8602 + }
8603 + if ( this.id ) {
8604 + toggleAllowedShortcodes( this.id.slice( 3, -5 ) );
8605 + }
8606 + });
8607 + }
8608 + }
8609 +
8610 + function toggleAllowedShortcodes( id ) {
8611 + let c, clickedID;
8612 + if ( typeof id === 'undefined' ) {
8613 + id = '';
8614 + }
8615 + c = id;
8616 +
8617 + if ( id.indexOf( '-search-input' ) !== -1 ) {
8618 + return;
8619 + }
8620 +
8621 + if ( id !== '' ) {
8622 + const $ele = jQuery( document.getElementById( id ) );
8623 + if ( $ele.attr( 'class' ) && id !== 'wpbody-content' && id !== 'content' && id !== 'dyncontent' && id !== 'success_msg' ) {
8624 + let d = $ele.attr( 'class' ).split( ' ' )[0];
8625 + if ( d === 'frm_long_input' || d === 'frm_98_width' || typeof d === 'undefined' ) {
8626 + d = '';
8627 + } else {
8628 + id = d.trim();
8629 + }
8630 + c = c + ' ' + d;
8631 + c = c.replace( 'widefat', '' ).replace( 'frm_with_left_label', '' );
8632 + }
8633 + }
8634 +
8635 + jQuery( '#frm-insert-fields-box,#frm-conditionals,#frm-adv-info-tab,#frm-dynamic-values' ).attr( 'data-fills', c.trim() );
8636 + const a = [
8637 + 'content', 'wpbody-content', 'dyncontent', 'success_url',
8638 + 'success_msg', 'edit_msg', 'frm_dyncontent', 'frm_not_email_message',
8639 + 'frm_not_email_subject'
8640 + ];
8641 + const b = [
8642 + 'before_content', 'after_content', 'frm_not_email_to',
8643 + 'dyn_default_value'
8644 + ];
8645 +
8646 + if ( jQuery.inArray( id, a ) >= 0 ) {
8647 + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' );
8648 + jQuery( '.frm_code_list a.hide_' + id ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
8649 + } else if ( jQuery.inArray( id, b ) >= 0 ) {
8650 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a:not(.show_' + id + ')' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
8651 + jQuery( '.frm_code_list a.show_' + id ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' );
8652 + } else {
8653 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
8654 + }
8655 +
8656 + // Automatically select a tab.
8657 + if ( id === 'dyn_default_value' ) {
8658 + clickedID = 'frm_dynamic_values';
8659 + document.getElementById( clickedID + '_tab' ).click();
8660 + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_inactive' ).addClass( 'frm_hidden' );
8661 + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_active' ).removeClass( 'frm_hidden' );
8662 + }
8663 + }
8664 +
8665 + function toggleAllowedHTML( input ) {
8666 + let b,
8667 + id = input.id;
8668 + if ( typeof id === 'undefined' || id.indexOf( '-search-input' ) !== -1 ) {
8669 + return;
8670 + }
8671 +
8672 + jQuery( '#frm-adv-info-tab' ).attr( 'data-fills', id.trim() );
8673 + if ( input.classList.contains( 'field_custom_html' ) ) {
8674 + id = 'field_custom_html';
8675 + }
8676 +
8677 + b = [ 'after_html', 'before_html', 'submit_html', 'field_custom_html' ];
8678 + if ( jQuery.inArray( id, b ) >= 0 ) {
8679 + jQuery( '.frm_code_list li:not(.show_' + id + ')' ).addClass( 'frm_hidden' );
8680 + jQuery( '.frm_code_list li.show_' + id ).removeClass( 'frm_hidden' );
8681 + }
8682 + }
8683 +
8684 + function toggleKeyID( switchTo, e ) {
8685 + e.stopPropagation();
8686 + jQuery( '.frm_code_list .frmids, .frm_code_list .frmkeys' ).addClass( 'frm_hidden' );
8687 + jQuery( '.frm_code_list .' + switchTo ).removeClass( 'frm_hidden' );
8688 + jQuery( '.frmids, .frmkeys' ).removeClass( 'current' );
8689 + jQuery( '.' + switchTo ).addClass( 'current' );
8690 + }
8691 +
8692 + function onActionLoaded( event ) {
8693 + const settings = event.target.closest( '.frm_form_action_settings' );
8694 + if ( settings && ( settings.classList.contains( 'frm_single_email_settings' ) || settings.classList.contains( 'frm_single_on_submit_settings' ) ) ) {
8695 + initWysiwygOnActionLoaded( settings );
8696 + }
8697 + }
8698 +
8699 + function initWysiwygOnActionLoaded( settings ) {
8700 + const wysiwyg = settings.querySelector( '.wp-editor-area' );
8701 + if ( wysiwyg ) {
8702 + frmDom.wysiwyg.init(
8703 + wysiwyg,
8704 + { height: 160, addFocusEvents: true }
8705 + );
8706 + }
8707 + }
8708 +
8709 + /* Global settings page */
8710 + function loadSettingsTab( anchor ) {
8711 + const holder = anchor.replace( '#', '' );
8712 + const holderContainer = jQuery( '.frm_' + holder + '_ajax' );
8713 + if ( holderContainer.length ) {
8714 + jQuery.ajax({
8715 + type: 'POST', url: ajaxurl,
8716 + data: {
8717 + 'action': 'frm_settings_tab',
8718 + 'tab': holder.replace( '_settings', '' ),
8719 + 'nonce': frmGlobal.nonce
8720 + },
8721 + success: function( html ) {
8722 + holderContainer.replaceWith( html );
8723 + }
8724 + });
8725 + }
8726 + }
8727 +
8728 + function uninstallNow() {
8729 + /*jshint validthis:true */
8730 + if ( confirmLinkClick( this ) === true ) {
8731 + jQuery( '.frm_uninstall .frm-wait' ).css( 'visibility', 'visible' );
8732 + jQuery.ajax({
8733 + type: 'POST',
8734 + url: ajaxurl,
8735 + data: 'action=frm_uninstall&nonce=' + frmGlobal.nonce,
8736 + success: function( msg ) {
8737 + jQuery( '.frm_uninstall' ).fadeOut( 'slow' );
8738 + window.location = msg;
8739 + }
8740 + });
8741 + }
8742 + return false;
8743 + }
8744 +
8745 + function saveAddonLicense() {
8746 + /*jshint validthis:true */
8747 + const button = jQuery( this );
8748 + const buttonName = this.name;
8749 + const pluginSlug = this.getAttribute( 'data-plugin' );
8750 + const action = buttonName.replace( 'edd_' + pluginSlug + '_license_', '' );
8751 + let license = document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value;
8752 + button.get(0).disabled = true;
8753 + jQuery.ajax({
8754 + type: 'POST', url: ajaxurl, dataType: 'json',
8755 + data: {action: 'frm_addon_' + action, license: license, plugin: pluginSlug, nonce: frmGlobal.nonce},
8756 + success: function( msg ) {
8757 + button.get(0).disabled = false;
8758 + const thisRow = button.closest( '.edd_frm_license_row' );
8759 + if ( action === 'deactivate' ) {
8760 + license = '';
8761 + document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value = '';
8762 + }
8763 + thisRow.find( '.edd_frm_license' ).html( license );
8764 + const eddWrapper = button.get(0).closest( '.frm_form_field' );
8765 + const actionIsSuccess = msg.success === true;
8766 + eddWrapper.querySelector( `.frm_icon_font.frm_action_success` ).classList.toggle( 'frm_hidden', ! actionIsSuccess || action === 'deactivate' );
8767 + eddWrapper.querySelector( `.frm_icon_font.frm_action_error` ).classList.toggle( 'frm_hidden', actionIsSuccess);
8768 +
8769 + const messageBox = thisRow.find( '.frm_license_msg' );
8770 + messageBox.html( msg.message );
8771 + if ( msg.message !== '' ) {
8772 + setTimeout( function() {
8773 + messageBox.html( '' );
8774 + thisRow.find( '.frm_icon_font' ).addClass( 'frm_hidden' );
8775 + if ( actionIsSuccess ) {
8776 + const actionIsActivate = action === 'activate';
8777 + thisRow.get(0).querySelector( '.edd_frm_unauthorized' ).classList.toggle( 'frm_hidden', actionIsActivate );
8778 + thisRow.get(0).querySelector( '.edd_frm_authorized' ).classList.toggle( 'frm_hidden', ! actionIsActivate );
8779 + }
8780 + }, 2000 );
8781 + }
8782 + }
8783 + });
8784 + }
8785 +
8786 + /* Import/Export page */
8787 +
8788 + function startFormMigration( event ) {
8789 + event.preventDefault();
8790 +
8791 + const checkedBoxes = jQuery( event.target ).find( 'input:checked' );
8792 + if ( ! checkedBoxes.length ) {
8793 + return;
8794 + }
8795 +
8796 + const ids = [];
8797 + checkedBoxes.each( function( i ) {
8798 + ids[i] = this.value;
8799 + });
8800 +
8801 + // Begin the import process.
8802 + importForms( ids, event.target );
8803 + }
8804 +
8805 + /**
8806 + * Begins the process of importing the forms.
8807 + */
8808 + function importForms( forms, targetForm ) {
8809 +
8810 + // Hide the form select section.
8811 + const $form = jQuery( targetForm ),
8812 + $processSettings = $form.next( '.frm-importer-process' );
8813 +
8814 + // Display total number of forms we have to import.
8815 + $processSettings.find( '.form-total' ).text( forms.length );
8816 + $processSettings.find( '.form-current' ).text( '1' );
8817 +
8818 + $form.hide();
8819 +
8820 + // Show processing status.
8821 + // '.process-completed' might have been shown earlier during a previous import, so hide now.
8822 + $processSettings.find( '.process-completed' ).hide();
8823 + $processSettings.show();
8824 +
8825 + // Create global import queue.
8826 + s.importQueue = forms;
8827 + s.imported = 0;
8828 +
8829 + // Import the first form in the queue.
8830 + importForm( $processSettings );
8831 + }
8832 +
8833 + /**
8834 + * Imports a single form from the import queue.
8835 + */
8836 + function importForm( $processSettings ) {
8837 + const formID = s.importQueue[0],
8838 + provider = jQuery( '#welcome-panel' ).find( 'input[name="slug"]' ).val(),
8839 + data = {
8840 + action: 'frm_import_' + provider,
8841 + form_id: formID,
8842 + nonce: frmGlobal.nonce
8843 + };
8844 +
8845 + // Trigger AJAX import for this form.
8846 + jQuery.post( ajaxurl, data, function( res ) {
8847 +
8848 + if ( res.success ) {
8849 + let statusUpdate;
8850 +
8851 + if ( res.data.error ) {
8852 + statusUpdate = '<p>' + res.data.name + ': ' + res.data.msg + '</p>';
8853 + } else {
8854 + statusUpdate = '<p>Imported <a href="' + res.data.link + '" target="_blank">' + res.data.name + '</a></p>';
8855 + }
8856 +
8857 + $processSettings.find( '.status' ).prepend( statusUpdate );
8858 + $processSettings.find( '.status' ).show();
8859 +
8860 + // Remove this form ID from the queue.
8861 + s.importQueue = jQuery.grep( s.importQueue, function( value ) {
8862 + return value != formID;
8863 + });
8864 + s.imported++;
8865 +
8866 + if ( s.importQueue.length === 0 ) {
8867 + $processSettings.find( '.process-count' ).hide();
8868 + $processSettings.find( '.forms-completed' ).text( s.imported );
8869 + $processSettings.find( '.process-completed' ).show();
8870 + } else {
8871 + // Import next form in the queue.
8872 + $processSettings.find( '.form-current' ).text( s.imported + 1 );
8873 + importForm( $processSettings );
8874 + }
8875 + }
8876 + });
8877 + }
8878 +
8879 + function validateExport( e ) {
8880 + /*jshint validthis:true */
8881 + e.preventDefault();
8882 +
8883 + let s = false;
8884 + const $exportForms = jQuery( 'input[name="frm_export_forms[]"]' );
8885 +
8886 + if ( ! jQuery( 'input[name="frm_export_forms[]"]:checked' ).val() ) {
8887 + $exportForms.closest( '.frm-table-box' ).addClass( 'frm_blank_field' );
8888 + s = 'stop';
8889 + }
8890 +
8891 + const $exportType = jQuery( 'input[name="type[]"]' );
8892 + if ( ! jQuery( 'input[name="type[]"]:checked' ).val() && $exportType.attr( 'type' ) === 'checkbox' ) {
8893 + $exportType.closest( 'p' ).addClass( 'frm_blank_field' );
8894 + s = 'stop';
8895 + }
8896 +
8897 + if ( s === 'stop' ) {
8898 + return false;
8899 + }
8900 +
8901 + e.stopPropagation();
8902 + this.submit();
8903 + }
8904 +
8905 + function removeExportError() {
8906 + /*jshint validthis:true */
8907 + const t = jQuery( this ).closest( '.frm_blank_field' );
8908 + if ( typeof t === 'undefined' ) {
8909 + return;
8910 + }
8911 +
8912 + const $thisName = this.name;
8913 + if ( $thisName === 'type[]' && jQuery( 'input[name="type[]"]:checked' ).val() ) {
8914 + t.removeClass( 'frm_blank_field' );
8915 + } else if ( $thisName === 'frm_export_forms[]' && jQuery( this ).val() ) {
8916 + t.removeClass( 'frm_blank_field' );
8917 + }
8918 +
8919 + }
8920 +
8921 + function checkCSVExtension() {
8922 + /*jshint validthis:true */
8923 + const f = jQuery( this ).val();
8924 + const re = /\.csv$/i;
8925 + if ( f.match( re ) !== null ) {
8926 + jQuery( '.show_csv' ).fadeIn();
8927 + } else {
8928 + jQuery( '.show_csv' ).fadeOut();
8929 + }
8930 + }
8931 +
8932 + function getExportOption() {
8933 + const exportFormatSelect = document.querySelector( 'select[name="format"]' );
8934 + if ( exportFormatSelect ) {
8935 + return exportFormatSelect.value;
8936 + }
8937 + return '';
8938 + }
8939 +
8940 + function exportTypeChanged( event ) {
8941 + const value = event.target.value;
8942 + showOrHideRepeaters( value );
8943 + checkExportTypes.call( event.target );
8944 + checkSelectedAllFormsCheckbox( value );
8945 + }
8946 +
8947 + function checkSelectedAllFormsCheckbox( exportType ) {
8948 + const selectAllCheckbox = document.getElementById( 'frm-export-select-all' );
8949 + if ( exportType === 'csv' ) {
8950 + selectAllCheckbox.checked = false;
8951 + selectAllCheckbox.disabled = true;
8952 + } else {
8953 + selectAllCheckbox.disabled = false;
8954 + }
8955 + }
8956 +
8957 + function checkExportTypes() {
8958 + /*jshint validthis:true */
8959 + const $dropdown = jQuery( this );
8960 + const $selected = $dropdown.find( ':selected' );
8961 + const s = $selected.data( 'support' );
8962 +
8963 + const multiple = s.indexOf( '|' );
8964 + jQuery( 'input[name="type[]"]' ).each( function() {
8965 + this.checked = false;
8966 + if ( s.indexOf( this.value ) >= 0 ) {
8967 + this.disabled = false;
8968 + if ( multiple === -1 ) {
8969 + this.checked = true;
8970 + }
8971 + } else {
8972 + this.disabled = true;
8973 + }
8974 + });
8975 +
8976 + if ( $dropdown.val() === 'csv' ) {
8977 + jQuery( '.csv_opts' ).show();
8978 + jQuery( '.xml_opts' ).hide();
8979 + } else {
8980 + jQuery( '.csv_opts' ).hide();
8981 + jQuery( '.xml_opts' ).show();
8982 + }
8983 +
8984 + const c = $selected.data( 'count' );
8985 + const exportField = jQuery( 'input[name="frm_export_forms[]"]' );
8986 + if ( c === 'single' ) {
8987 + exportField.prop( 'multiple', false );
8988 + exportField.prop( 'checked', false );
8989 + } else {
8990 + exportField.prop( 'multiple', true );
8991 + exportField.prop( 'disabled', false );
8992 + }
8993 + $dropdown.trigger( 'change' );
8994 + }
8995 +
8996 + function showOrHideRepeaters( exportOption ) {
8997 + if ( exportOption === '' ) {
8998 + return;
8999 + }
9000 +
9001 + const repeaters = document.querySelectorAll( '.frm-is-repeater' );
9002 + if ( ! repeaters.length ) {
9003 + return;
9004 + }
9005 +
9006 + if ( exportOption === 'csv' ) {
9007 + repeaters.forEach( form => {
9008 + form.classList.remove( 'frm_hidden' );
9009 + });
9010 + } else {
9011 + repeaters.forEach( form => {
9012 + form.classList.add( 'frm_hidden' );
9013 + });
9014 + }
9015 +
9016 + searchContent.call( document.querySelector( '.frm-auto-search' ) );
9017 + }
9018 +
9019 + function preventMultipleExport() {
9020 + const type = jQuery( 'select[name=format]' ),
9021 + selected = type.find( ':selected' ),
9022 + count = selected.data( 'count' ),
9023 + exportField = jQuery( 'input[name="frm_export_forms[]"]' );
9024 +
9025 + if ( count === 'single' ) {
9026 + // Disable all other fields to prevent multiple selections.
9027 + if ( this.checked ) {
9028 + exportField.prop( 'disabled', true );
9029 + this.removeAttribute( 'disabled' );
9030 + } else {
9031 + exportField.prop( 'disabled', false );
9032 + }
9033 + } else {
9034 + exportField.prop( 'disabled', false );
9035 + }
9036 + }
9037 +
9038 + function initiateMultiselect() {
9039 + jQuery( '.frm_multiselect' ).hide().each( frmDom.bootstrap.multiselect.init );
9040 + }
9041 +
9042 + /* Addons page */
9043 + function installMultipleAddons( e ) {
9044 + e.preventDefault();
9045 + toggleAddonState( this, 'frm_multiple_addons' );
9046 + }
9047 +
9048 + function activateAddon( e ) {
9049 + e.preventDefault();
9050 + toggleAddonState( this, 'frm_activate_addon' );
9051 + }
9052 +
9053 + function installAddon( e ) {
9054 + e.preventDefault();
9055 + toggleAddonState( this, 'frm_install_addon' );
9056 + }
9057 +
9058 + function toggleAddonState( clicked, action ) {
9059 + let button, plugin, el, message;
9060 +
9061 + // Remove any leftover error messages, output an icon and get the plugin basename that needs to be activated.
9062 + jQuery( '.frm-addon-error' ).remove();
9063 + button = jQuery( clicked );
9064 + plugin = button.attr( 'rel' );
9065 + el = button.parent();
9066 + message = el.parent().find( '.addon-status-label' );
9067 +
9068 + button.addClass( 'frm_loading_button' );
9069 +
9070 + // Process the Ajax to perform the activation.
9071 + jQuery.ajax({
9072 + url: ajaxurl,
9073 + type: 'POST',
9074 + async: true,
9075 + cache: false,
9076 + dataType: 'json',
9077 + data: {
9078 + action: action,
9079 + nonce: frmGlobal.nonce,
9080 + plugin: plugin
9081 + },
9082 + success: function( response ) {
9083 + response = response?.data ?? response;
9084 +
9085 + let saveAndReload;
9086 +
9087 + if ( 'string' !== typeof response && 'string' === typeof response.message ) {
9088 + if ( 'undefined' !== typeof response.saveAndReload ) {
9089 + saveAndReload = response.saveAndReload;
9090 + }
9091 + response = response.message;
9092 + }
9093 +
9094 + const error = extractErrorFromAddOnResponse( response );
9095 + if ( error ) {
9096 + addonError( error, el, button );
9097 + return;
9098 + }
9099 +
9100 + afterAddonInstall( response, button, message, el, saveAndReload, action );
9101 +
9102 + /**
9103 + * Trigger an action after successfully toggling the addon state.
9104 + *
9105 + * @param {Object} response
9106 + */
9107 + wp.hooks.doAction( 'frm_update_addon_state', response );
9108 + },
9109 + error: function() {
9110 + button.removeClass( 'frm_loading_button' );
9111 + }
9112 + });
9113 + }
9114 +
9115 + function installAddonWithCreds( e ) {
9116 + // Prevent the default action, let the user know we are attempting to install again and go with it.
9117 + e.preventDefault();
9118 +
9119 + // Now let's make another Ajax request once the user has submitted their credentials.
9120 + const proceed = jQuery( this );
9121 + const el = proceed.parent().parent();
9122 + const plugin = proceed.attr( 'rel' );
9123 +
9124 + proceed.addClass( 'frm_loading_button' );
9125 +
9126 + jQuery.ajax({
9127 + url: ajaxurl,
9128 + type: 'POST',
9129 + async: true,
9130 + cache: false,
9131 + dataType: 'json',
9132 + data: {
9133 + action: 'frm_install_addon',
9134 + nonce: frmAdminJs.nonce,
9135 + plugin: plugin,
9136 + hostname: el.find( '#hostname' ).val(),
9137 + username: el.find( '#username' ).val(),
9138 + password: el.find( '#password' ).val()
9139 + },
9140 + success: function( response ) {
9141 + response = response?.data ?? response;
9142 +
9143 + const error = extractErrorFromAddOnResponse( response );
9144 + if ( error ) {
9145 + addonError( error, el, proceed );
9146 + return;
9147 + }
9148 +
9149 + afterAddonInstall( response, proceed, message, el );
9150 + },
9151 + error: function() {
9152 + proceed.removeClass( 'frm_loading_button' );
9153 + }
9154 + });
9155 + }
9156 +
9157 + function afterAddonInstall( response, button, message, el, saveAndReload, action = 'frm_activate_addon' ) {
9158 + const addonStatuses = document.querySelectorAll( '.frm-addon-status' );
9159 + addonStatuses.forEach(
9160 + addonStatus => {
9161 + addonStatus.textContent = response;
9162 + addonStatus.style.display = 'block';
9163 + }
9164 + );
9165 +
9166 + // The Ajax request was successful, so let's update the output.
9167 + button.css({ opacity: '0' });
9168 +
9169 + document.querySelectorAll( '.frm-oneclick' ).forEach(
9170 + oneClick => {
9171 + oneClick.style.display = 'none';
9172 + }
9173 + );
9174 +
9175 + jQuery( '#frm_upgrade_modal h2' ).hide();
9176 + jQuery( '#frm_upgrade_modal .frm_lock_icon' ).addClass( 'frm_lock_open_icon' );
9177 + jQuery( '#frm_upgrade_modal .frm_lock_icon use' ).attr( 'xlink:href', '#frm_lock_open_icon' );
9178 +
9179 + // Proceed with CSS changes
9180 + const actionMap = {
9181 + frm_activate_addon: { class: 'frm-addon-active', message: frmAdminJs.active },
9182 + frm_deactivate_addon: { class: 'frm-addon-installed', message: frmAdminJs.installed },
9183 + frm_uninstall_addon: { class: 'frm-addon-not-installed', message: frmAdminJs.not_installed }
9184 + };
9185 + actionMap.frm_install_addon = actionMap.frm_activate_addon;
9186 +
9187 + const messageElement = message[0];
9188 + if ( messageElement ) {
9189 + messageElement.textContent = actionMap[action].message;
9190 + }
9191 +
9192 + const parentElement = el[0].parentElement;
9193 + parentElement.classList.remove( 'frm-addon-not-installed', 'frm-addon-installed', 'frm-addon-active' );
9194 + parentElement.classList.add( actionMap[action].class );
9195 +
9196 + const buttonElement = button[0];
9197 + buttonElement.classList.remove( 'frm_loading_button' );
9198 +
9199 + // Maybe refresh import and SMTP pages
9200 + const refreshPage = document.querySelectorAll( '.frm-admin-page-import, #frm-admin-smtp, #frm-welcome' );
9201 + if ( refreshPage.length > 0 ) {
9202 + window.location.reload();
9203 + return;
9204 + }
9205 +
9206 + if ([ 'settings', 'form_builder' ].includes( saveAndReload ) ) {
9207 + addonStatuses.forEach(
9208 + addonStatus => {
9209 + const inModal = null !== addonStatus.closest( '#frm_upgrade_modal' );
9210 + addonStatus.appendChild( getSaveAndReloadSettingsOptions( saveAndReload, inModal ) );
9211 + }
9212 + );
9213 + }
9214 + }
9215 +
9216 + function getSaveAndReloadSettingsOptions( saveAndReload, inModal ) {
9217 + const className = 'frm-save-and-reload-options';
9218 + const children = [ saveAndReloadSettingsButton( saveAndReload ) ];
9219 + if ( inModal ) {
9220 + children.push( closePopupButton() );
9221 + }
9222 + return div({ className, children });
9223 + }
9224 +
9225 + function saveAndReloadSettingsButton( saveAndReload ) {
9226 + const button = document.createElement( 'button' );
9227 + button.classList.add( 'frm-save-and-reload', 'button', 'button-primary', 'frm-button-primary' );
9228 + button.textContent = __( 'Save and Reload', 'formidable' );
9229 + button.addEventListener( 'click', () => {
9230 + if ( saveAndReload === 'form_builder' ) {
9231 + saveAndReloadFormBuilder();
9232 + } else if ( saveAndReload === 'settings' ) {
9233 + saveAndReloadSettings();
9234 + }
9235 + });
9236 + return button;
9237 + }
9238 +
9239 + function closePopupButton() {
9240 + const a = document.createElement( 'a' );
9241 + a.setAttribute( 'href', '#' );
9242 + a.classList.add( 'button', 'button-secondary', 'frm-button-secondary', 'dismiss' );
9243 + a.textContent = __( 'Close', 'formidable' );
9244 + return a;
9245 + }
9246 +
9247 + function extractErrorFromAddOnResponse( response ) {
9248 + if ( typeof response !== 'string' ) {
9249 + if ( typeof response.success !== 'undefined' && response.success ) {
9250 + return false;
9251 + }
9252 +
9253 + if ( response.form ) {
9254 + if ( jQuery( response.form ).is( '#message' ) ) {
9255 + return {
9256 + message: jQuery( response.form ).find( 'p' ).html()
9257 + };
9258 + }
9259 + }
9260 +
9261 + return response;
9262 + }
9263 +
9264 + return false;
9265 + }
9266 +
9267 + function addonError( response, el, button ) {
9268 + if ( response.form ) {
9269 + jQuery( '.frm-inline-error' ).remove();
9270 + button.closest( '.frm-card' )
9271 + .html( response.form )
9272 + .css({ padding: 5 })
9273 + .find( '#upgrade' )
9274 + .attr( 'rel', button.attr( 'rel' ) )
9275 + .on( 'click', installAddonWithCreds );
9276 + } else {
9277 + el.append( '<div class="frm-addon-error frm_error_style"><p><strong>' + response.message + '</strong></p></div>' );
9278 + button.removeClass( 'frm_loading_button' );
9279 + jQuery( '.frm-addon-error' ).delay( 4000 ).fadeOut();
9280 + }
9281 + }
9282 +
9283 + /* Templates */
9284 + function showActiveCampaignForm() {
9285 + loadApiEmailForm();
9286 + }
9287 +
9288 + function handleApiFormError( inputId, errorId, type, message ) {
9289 + const $error = jQuery( errorId );
9290 + $error.removeClass( 'frm_hidden' ).attr( 'frm-error', type );
9291 +
9292 + if ( typeof message !== 'undefined' ) {
9293 + $error.find( 'span[frm-error="' + type + '"]' ).text( message );
9294 + }
9295 +
9296 + jQuery( inputId ).one( 'keyup', function() {
9297 + $error.addClass( 'frm_hidden' );
9298 + });
9299 + }
9300 +
9301 + function handleEmailAddressError( type ) {
9302 + handleApiFormError( '#frm_leave_email', '#frm_leave_email_error', type );
9303 + }
9304 +
9305 + function loadApiEmailForm() {
9306 + const formContainer = document.getElementById( 'frmapi-email-form' );
9307 + jQuery.ajax({
9308 + dataType: 'json',
9309 + url: formContainer.getAttribute( 'data-url' ),
9310 + success: function( json ) {
9311 + let form = json.renderedHtml;
9312 + form = form.replace( /<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi, '' );
9313 + formContainer.innerHTML = form;
9314 + }
9315 + });
9316 + }
9317 + function initSelectionAutocomplete() {
9318 + frmDom.autocomplete.initSelectionAutocomplete();
9319 + }
9320 +
9321 + function nextInstallStep( thisStep ) {
9322 + thisStep.classList.add( 'frm_grey' );
9323 + thisStep.nextElementSibling.classList.remove( 'frm_grey' );
9324 + }
9325 +
9326 + function installTemplateFieldset( e ) {
9327 + /*jshint validthis:true */
9328 + const fieldset = this.parentNode.parentNode,
9329 + action = fieldset.elements.type.value,
9330 + button = this;
9331 + e.preventDefault();
9332 + button.classList.add( 'frm_loading_button' );
9333 + installNewForm( fieldset, action, button );
9334 + }
9335 +
9336 + function installTemplate( e ) {
9337 + /*jshint validthis:true */
9338 + const action = this.elements.type.value,
9339 + button = this.querySelector( 'button' );
9340 + e.preventDefault();
9341 + button.classList.add( 'frm_loading_button' );
9342 + installNewForm( this, action, button );
9343 + }
9344 +
9345 + function installNewForm( form, action, button ) {
9346 + const formData = formToData( form );
9347 + const formName = formData.template_name;
9348 + const formDesc = formData.template_desc;
9349 + const link = form.elements.link.value;
9350 +
9351 + let data = {
9352 + action: action,
9353 + xml: link,
9354 + name: formName,
9355 + desc: formDesc,
9356 + form: JSON.stringify( formData ),
9357 + nonce: frmGlobal.nonce
9358 + };
9359 +
9360 + const hookName = 'frm_before_install_new_form';
9361 + const filterArgs = { formData };
9362 + data = wp.hooks.applyFilters( hookName, data, filterArgs );
9363 +
9364 + postAjax( data, function( response ) {
9365 + if ( typeof response.redirect !== 'undefined' ) {
9366 + const redirect = response.redirect;
9367 + if ( typeof form.elements.redirect === 'undefined' ) {
9368 + window.location = redirect;
9369 + } else {
9370 + const href = document.getElementById( 'frm-redirect-link' );
9371 + if ( typeof link !== 'undefined' && href !== null ) {
9372 + // Show the next installation step.
9373 + href.setAttribute( 'href', redirect );
9374 + href.classList.remove( 'frm_grey', 'disabled' );
9375 + nextInstallStep( form.parentNode.parentNode );
9376 + button.classList.add( 'frm_grey', 'disabled' );
9377 + }
9378 + }
9379 + } else {
9380 + jQuery( '.spinner' ).css( 'visibility', 'hidden' );
9381 +
9382 + // Show response.message
9383 + if ( 'string' === typeof response.message ) {
9384 + showInstallFormErrorModal( response.message );
9385 + }
9386 + }
9387 + button.classList.remove( 'frm_loading_button' );
9388 + });
9389 + }
9390 +
9391 + function showInstallFormErrorModal( message ) {
9392 + const modalContent = div( message );
9393 + modalContent.style.padding = '20px 40px';
9394 + const modal = frmDom.modal.maybeCreateModal(
9395 + 'frmInstallFormErrorModal',
9396 + {
9397 + title: __( 'Unable to install template', 'formidable' ),
9398 + content: modalContent
9399 + }
9400 + );
9401 + modal.classList.add( 'frm_common_modal' );
9402 + }
9403 +
9404 + function handleCaptchaTypeChange( e ) {
9405 + const thresholdContainer = document.getElementById( 'frm_captcha_threshold_container' );
9406 + if ( thresholdContainer ) {
9407 + thresholdContainer.classList.toggle( 'frm_hidden', 'v3' !== e.target.value );
9408 + }
9409 + }
9410 +
9411 + function trashTemplate( e ) {
9412 + /*jshint validthis:true */
9413 + const id = this.getAttribute( 'data-id' );
9414 + e.preventDefault();
9415 +
9416 + data = {
9417 + action: 'frm_forms_trash',
9418 + id: id,
9419 + nonce: frmGlobal.nonce
9420 + };
9421 + postAjax( data, function() {
9422 + const card = document.getElementById( 'frm-template-custom-' + id );
9423 + fadeOut( card, function() {
9424 + card.parentNode.removeChild( card );
9425 + });
9426 + });
9427 + }
9428 +
9429 + function searchContent() {
9430 + /*jshint validthis:true */
9431 + let i,
9432 + regEx = false,
9433 + searchText = this.value.toLowerCase(),
9434 + toSearch = this.getAttribute( 'data-tosearch' ),
9435 + items = document.getElementsByClassName( toSearch );
9436 +
9437 + if ( this.tagName === 'SELECT' ) {
9438 + searchText = selectedOptions( this );
9439 + searchText = searchText.join( '|' ).toLowerCase();
9440 + regEx = true;
9441 + }
9442 +
9443 + if ( toSearch === 'frm-action' && searchText !== '' ) {
9444 + const addons = document.getElementById( 'frm_email_addon_menu' ).classList;
9445 + addons.remove( 'frm-all-actions' );
9446 + addons.add( 'frm-limited-actions' );
9447 + }
9448 +
9449 + for ( i = 0; i < items.length; i++ ) {
9450 + const innerText = items[i].innerText.toLowerCase();
9451 +
9452 + const itemCanBeShown = ! ( getExportOption() === 'xml' && items[i].classList.contains( 'frm-is-repeater' ) );
9453 + if ( searchText === '' ) {
9454 + if ( itemCanBeShown ) {
9455 + items[i].classList.remove( 'frm_hidden' );
9456 + }
9457 + items[i].classList.remove( 'frm-search-result' );
9458 + } else if ( ( regEx && new RegExp( searchText ).test( innerText ) ) || innerText.indexOf( searchText ) >= 0 || textMatchesPlural( innerText, searchText ) ) {
9459 + if ( itemCanBeShown ) {
9460 + items[i].classList.remove( 'frm_hidden' );
9461 + }
9462 + items[i].classList.add( 'frm-search-result' );
9463 + } else {
9464 + items[i].classList.add( 'frm_hidden' );
9465 + items[i].classList.remove( 'frm-search-result' );
9466 + }
9467 + }
9468 +
9469 + // Updates the visibility of category headings based on search results.
9470 + updateCatHeadingVisibility();
9471 +
9472 + jQuery( this ).trigger( 'frmAfterSearch' );
9473 + }
9474 +
9475 + /**
9476 + * Allow a search for "signatures" to still match "signature" for example when searching fields.
9477 + *
9478 + * @since 6.15
9479 + *
9480 + * @param {string} text The text in the element we are checking for a match.
9481 + * @param {string} searchText The text value that is being searched.
9482 + * @return {boolean}
9483 + */
9484 + function textMatchesPlural( text, searchText ) {
9485 + if ( searchText === 's' ) {
9486 + // Don't match everything when just "s" is searched.
9487 + return false;
9488 + }
9489 +
9490 + if ( text[ text.length - 1 ] === 's' ) {
9491 + // Do not match something with double s if the text already ends in s.
9492 + return false;
9493 + }
9494 +
9495 + return ( text + 's' ).indexOf( searchText ) >= 0;
9496 + }
9497 +
9498 + /**
9499 + * Updates the visibility of category headings based on search results.
9500 + * If all associated fields are hidden (indicating no search matches),
9501 + * the heading is hidden.
9502 + *
9503 + * @since 6.4.1
9504 + */
9505 + function updateCatHeadingVisibility() {
9506 + const insertFieldsElement = document.querySelector( '#frm-insert-fields' );
9507 + if ( ! insertFieldsElement ) {
9508 + return;
9509 + }
9510 +
9511 + const headingElements = insertFieldsElement.querySelectorAll( ':scope > .frm-with-line' );
9512 + headingElements.forEach( heading => {
9513 + const fieldsListElement = heading.nextElementSibling;
9514 + if ( ! fieldsListElement ) {
9515 + return;
9516 + }
9517 + const listItemElements = fieldsListElement.querySelectorAll( ':scope > li.frmbutton' );
9518 + const allHidden = Array.from( listItemElements ).every( li => li.classList.contains( 'frm_hidden' ) );
9519 +
9520 + // Add or remove class based on `allHidden` condition
9521 + heading.classList.toggle( 'frm_hidden', allHidden );
9522 + });
9523 + }
9524 +
9525 + function stopPropagation( e ) {
9526 + e.stopPropagation();
9527 + }
9528 +
9529 + /* Helpers */
9530 +
9531 + function selectedOptions( select ) {
9532 + let opt,
9533 + result = [],
9534 + options = select && select.options;
9535 +
9536 + for ( let i = 0, iLen = options.length; i < iLen; i++ ) {
9537 + opt = options[i];
9538 +
9539 + if ( opt.selected ) {
9540 + result.push( opt.value );
9541 + }
9542 + }
9543 + return result;
9544 + }
9545 +
9546 + function triggerEvent( element, event ) {
9547 + const evt = document.createEvent( 'HTMLEvents' );
9548 + evt.initEvent( event, false, true );
9549 + element.dispatchEvent( evt );
9550 + }
9551 +
9552 + function postAjax( data, success ) {
9553 + let response;
9554 +
9555 + const xmlHttp = new XMLHttpRequest();
9556 + const params = typeof data === 'string' ? data : Object.keys( data ).map(
9557 + function( k ) {
9558 + return encodeURIComponent( k ) + '=' + encodeURIComponent( data[k]);
9559 + }
9560 + ).join( '&' );
9561 +
9562 + xmlHttp.open( 'post', ajaxurl, true );
9563 + xmlHttp.onreadystatechange = function() {
9564 + if ( xmlHttp.readyState > 3 && xmlHttp.status == 200 ) {
9565 + response = xmlHttp.responseText;
9566 + try {
9567 + response = JSON.parse( response );
9568 + } catch ( e ) {
9569 + // The response may not be JSON, so just return it.
9570 + }
9571 + success( response );
9572 + }
9573 + };
9574 + xmlHttp.setRequestHeader( 'X-Requested-With', 'XMLHttpRequest' );
9575 + xmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
9576 + xmlHttp.send( params );
9577 + return xmlHttp;
9578 + }
9579 +
9580 + function fadeOut( element, success ) {
9581 + element.classList.add( 'frm-fade' );
9582 + setTimeout( success, 1000 );
9583 + }
9584 +
9585 + function invisible( classes ) {
9586 + jQuery( classes ).css( 'visibility', 'hidden' );
9587 + }
9588 +
9589 + function visible( classes ) {
9590 + jQuery( classes ).css( 'visibility', 'visible' );
9591 + }
9592 +
9593 + function initModal( id, width ) {
9594 + const $info = jQuery( id );
9595 + if ( ! $info.length ) {
9596 + return false;
9597 + }
9598 +
9599 + if ( typeof width === 'undefined' ) {
9600 + width = '550px';
9601 + }
9602 +
9603 + const dialogArgs = {
9604 + dialogClass: 'frm-dialog',
9605 + modal: true,
9606 + autoOpen: false,
9607 + closeOnEscape: true,
9608 + width: width,
9609 + resizable: false,
9610 + draggable: false,
9611 + open: function() {
9612 + jQuery( '.ui-dialog-titlebar' ).addClass( 'frm_hidden' ).removeClass( 'ui-helper-clearfix' );
9613 + jQuery( '#wpwrap' ).addClass( 'frm_overlay' );
9614 + jQuery( '.frm-dialog' ).removeClass( 'ui-widget ui-widget-content ui-corner-all' );
9615 + $info.removeClass( 'ui-dialog-content ui-widget-content' );
9616 + bindClickForDialogClose( $info );
9617 + },
9618 + close: function() {
9619 + jQuery( '#wpwrap' ).removeClass( 'frm_overlay' );
9620 + jQuery( '.spinner' ).css( 'visibility', 'hidden' );
9621 +
9622 + this.removeAttribute( 'data-option-type' );
9623 + const optionType = document.getElementById( 'bulk-option-type' );
9624 + if ( optionType ) {
9625 + optionType.value = '';
9626 + }
9627 + }
9628 + };
9629 +
9630 + $info.dialog( dialogArgs );
9631 +
9632 + return $info;
9633 + }
9634 +
9635 + function toggle( cname, id ) {
9636 + if ( id === '#' ) {
9637 + const cont = document.getElementById( cname );
9638 + const hidden = cont.style.display;
9639 + if ( hidden === 'none' ) {
9640 + cont.style.display = 'block';
9641 + } else {
9642 + cont.style.display = 'none';
9643 + }
9644 + } else {
9645 + const vis = cname.is( ':visible' );
9646 + if ( vis ) {
9647 + cname.hide();
9648 + } else {
9649 + cname.show();
9650 + }
9651 + }
9652 + }
9653 +
9654 + function removeWPUnload() {
9655 + window.onbeforeunload = null;
9656 + const w = jQuery( window );
9657 + w.off( 'beforeunload.widgets' );
9658 + w.off( 'beforeunload.edit-post' );
9659 + }
9660 +
9661 + function addMultiselectLabelListener() {
9662 + const clickListener = ( e ) => {
9663 + if ( 'LABEL' !== e.target.nodeName ) {
9664 + return;
9665 + }
9666 +
9667 + const labelFor = e.target.getAttribute( 'for' );
9668 + if ( ! labelFor ) {
9669 + return;
9670 + }
9671 +
9672 + const input = document.getElementById( labelFor );
9673 + if ( ! input || ! input.nextElementSibling ) {
9674 + return;
9675 + }
9676 +
9677 + const buttonToggle = input.nextElementSibling.querySelector( 'button.dropdown-toggle.multiselect' );
9678 + if ( ! buttonToggle ) {
9679 + return;
9680 + }
9681 +
9682 + const triggerMultiselectClick = () => buttonToggle.click();
9683 + setTimeout( triggerMultiselectClick, 0 );
9684 + };
9685 + document.addEventListener( 'click', clickListener );
9686 + }
9687 +
9688 + function maybeChangeEmbedFormMsg() {
9689 + const fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
9690 + let fieldItem = document.getElementById( 'frm_field_id_' + fieldId );
9691 + if ( null === fieldItem || 'form' !== fieldItem.dataset.type ) {
9692 + return;
9693 + }
9694 +
9695 + fieldItem = jQuery( fieldItem );
9696 +
9697 + if ( this.options[ this.selectedIndex ].value ) {
9698 + fieldItem.find( '.frm-not-set' )[0].classList.add( 'frm_hidden' );
9699 + const embedMsg = fieldItem.find( '.frm-embed-message' );
9700 + embedMsg.html( embedMsg.data( 'embedmsg' ) + this.options[ this.selectedIndex ].text );
9701 + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.remove( 'frm_hidden' );
9702 + } else {
9703 + fieldItem.find( '.frm-not-set' )[0].classList.remove( 'frm_hidden' );
9704 + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.add( 'frm_hidden' );
9705 + }
9706 + }
9707 +
9708 + function toggleProductType() {
9709 + const settings = jQuery( this ).closest( '.frm-single-settings' ),
9710 + container = settings.find( '.frmjs_product_choices' ),
9711 + heading = settings.find( '.frm_prod_options_heading' ),
9712 + currentVal = this.options[ this.selectedIndex ].value;
9713 +
9714 + container.removeClass( 'frm_prod_type_single frm_prod_type_user_def' );
9715 + heading.removeClass( 'frm_prod_user_def' );
9716 +
9717 + if ( 'single' === currentVal ) {
9718 + container.addClass( 'frm_prod_type_single' );
9719 + } else if ( 'user_def' === currentVal ) {
9720 + container.addClass( 'frm_prod_type_user_def' );
9721 + heading.addClass( 'frm_prod_user_def' );
9722 + }
9723 + }
9724 +
9725 + /**
9726 + * @param {Number | string} fieldId
9727 + * @return {boolean} True if the field is a product field.
9728 + */
9729 + function isProductField( fieldId ) {
9730 + const field = document.getElementById( 'frm_field_id_' + fieldId );
9731 + if ( field === null ) {
9732 + return false;
9733 + }
9734 + return 'product' === field.getAttribute( 'data-type' );
9735 + }
9736 +
9737 + /**
9738 + * Serialize form data with vanilla JS.
9739 + */
9740 + function formToData( form ) {
9741 + let subKey, i,
9742 + object = {},
9743 + formData = form.elements;
9744 +
9745 + for ( i = 0; i < formData.length; i++ ) {
9746 + let input = formData[i],
9747 + key = input.name,
9748 + value = input.value,
9749 + names = key.match( /(.*)\[(.*)\]/ );
9750 +
9751 + if ( ( input.type === 'radio' || input.type === 'checkbox' ) && ! input.checked ) {
9752 + continue;
9753 + }
9754 +
9755 + if ( names !== null ) {
9756 + key = names[1];
9757 + subKey = names[2];
9758 + if ( ! Reflect.has( object, key ) ) {
9759 + object[key] = {};
9760 + }
9761 + object[key][subKey] = value;
9762 + continue;
9763 + }
9764 +
9765 + // Reflect.has in favor of: object.hasOwnProperty(key)
9766 + if ( ! Reflect.has( object, key ) ) {
9767 + object[key] = value;
9768 + continue;
9769 + }
9770 + if ( ! Array.isArray( object[key]) ) {
9771 + object[key] = [ object[key] ];
9772 + }
9773 + object[key].push( value );
9774 + }
9775 +
9776 + return object;
9777 + }
9778 +
9779 + /**
9780 + * Show, hide, and sort subfields of Name field on form builder.
9781 + *
9782 + * @since 4.11
9783 + */
9784 + function handleNameFieldOnFormBuilder() {
9785 + /**
9786 + * Gets subfield element from cache.
9787 + *
9788 + * @param {String} fieldId Field ID.
9789 + * @param {String} key Cache key.
9790 + * @returns {HTMLElement|undefined} Return the element from cache or undefined if not found.
9791 + */
9792 + const getSubFieldElFromCache = ( fieldId, key ) => {
9793 + window.frmCachedSubFields = window.frmCachedSubFields || {};
9794 + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {};
9795 + return window.frmCachedSubFields[fieldId][key];
9796 + };
9797 +
9798 + /**
9799 + * Sets subfield element to cache.
9800 + *
9801 + * @param {String} fieldId Field ID.
9802 + * @param {String} key Cache key.
9803 + * @param {HTMLElement} el Element.
9804 + */
9805 + const setSubFieldElToCache = ( fieldId, key, el ) => {
9806 + window.frmCachedSubFields = window.frmCachedSubFields || {};
9807 + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {};
9808 + window.frmCachedSubFields[fieldId][key] = el;
9809 + };
9810 +
9811 + /**
9812 + * Gets column class from the number of columns.
9813 + *
9814 + * @param {Number} colCount Number of columns.
9815 + * @returns {string}
9816 + */
9817 + const getColClass = colCount => 'frm' + parseInt( 12 / colCount );
9818 +
9819 + const colClasses = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ].map( num => 'frm' + num );
9820 +
9821 + const allSubFieldNames = [ 'first', 'middle', 'last' ];
9822 +
9823 + /**
9824 + * Handles name layout change.
9825 + *
9826 + * @param {Event} event Event object.
9827 + */
9828 + const onChangeLayout = event => {
9829 + const value = event.target.value;
9830 + const subFieldNames = value.split( '_' );
9831 + const fieldId = event.target.dataset.fieldId;
9832 +
9833 + /*
9834 + * Live update form on the form builder.
9835 + */
9836 + const container = document.querySelector( '#field_' + fieldId + '_inner_container .frm_combo_inputs_container' );
9837 + const newColClass = getColClass( subFieldNames.length );
9838 +
9839 + // Set all sub field elements to cache and hide all of them first.
9840 + allSubFieldNames.forEach( name => {
9841 + const subFieldEl = container.querySelector( '[data-sub-field-name="' + name + '"]' );
9842 + if ( subFieldEl ) {
9843 + subFieldEl.classList.add( 'frm_hidden' );
9844 + subFieldEl.classList.remove( ...colClasses );
9845 + setSubFieldElToCache( fieldId, name, subFieldEl );
9846 + }
9847 + });
9848 +
9849 + subFieldNames.forEach( subFieldName => {
9850 + const subFieldEl = getSubFieldElFromCache( fieldId, subFieldName );
9851 + if ( ! subFieldEl ) {
9852 + return;
9853 + }
9854 +
9855 + subFieldEl.classList.remove( 'frm_hidden' );
9856 + subFieldEl.classList.add( newColClass );
9857 +
9858 + container.append( subFieldEl );
9859 + });
9860 +
9861 + /*
9862 + * Live update subfield options.
9863 + */
9864 + // Hide all subfield options.
9865 + allSubFieldNames.forEach( name => {
9866 + const optionsEl = document.querySelector( '.frm_sub_field_options-' + name + '[data-field-id="' + fieldId + '"]' );
9867 + if ( optionsEl ) {
9868 + optionsEl.classList.add( 'frm_hidden' );
9869 + setSubFieldElToCache( fieldId, name + '_options', optionsEl );
9870 + }
9871 + });
9872 +
9873 + subFieldNames.forEach( subFieldName => {
9874 + const optionsEl = getSubFieldElFromCache( fieldId, subFieldName + '_options' );
9875 + if ( ! optionsEl ) {
9876 + return;
9877 + }
9878 + optionsEl.classList.remove( 'frm_hidden' );
9879 + });
9880 + };
9881 +
9882 + const dropdownSelector = '.frm_name_layout_dropdown';
9883 + document.addEventListener( 'change', event => {
9884 + if ( event.target.matches( dropdownSelector ) ) {
9885 + onChangeLayout( event );
9886 + }
9887 + }, false );
9888 + }
9889 +
9890 + function debounce( func, wait = 100 ) {
9891 + return frmDom.util.debounce( func, wait );
9892 + }
9893 +
9894 + function addSaveAndDragIconsToOption( fieldId, liObject ) {
9895 + let li, useTag, useTagHref;
9896 + let hasDragIcon = false;
9897 + let hasSaveIcon = false;
9898 +
9899 + if ( liObject.newOption ) {
9900 + const parser = new DOMParser();
9901 + li = parser.parseFromString( liObject.newOption, 'text/html' ).body.childNodes[0];
9902 + } else {
9903 + li = liObject;
9904 + }
9905 +
9906 + const liIcons = li.querySelectorAll( 'svg' );
9907 +
9908 + liIcons.forEach( ( svg, key ) => {
9909 + useTag = svg.getElementsByTagNameNS( 'http://www.w3.org/2000/svg', 'use' )[0];
9910 + if ( ! useTag ) {
9911 + return;
9912 + }
9913 + useTagHref = useTag.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) || useTag.getAttribute( 'href' );
9914 +
9915 + if ( useTagHref === '#frm_drag_icon' ) {
9916 + hasDragIcon = true;
9917 + }
9918 +
9919 + if ( useTagHref === '#frm_save_icon' ) {
9920 + hasSaveIcon = true;
9921 + }
9922 + });
9923 +
9924 + if ( ! hasDragIcon ) {
9925 + li.prepend( icons.drag.cloneNode( true ) );
9926 + }
9927 +
9928 + if ( li.querySelector( `[id^=field_key_${fieldId}-]` ) && ! hasSaveIcon ) {
9929 + li.querySelector( `[id^=field_key_${fieldId}-]` ).after( icons.save.cloneNode( true ) );
9930 + }
9931 +
9932 + if ( liObject.newOption ) {
9933 + liObject.newOption = li;
9934 + }
9935 + }
9936 +
9937 + function maybeAddSaveAndDragIcons( fieldId ) {
9938 + fieldOptions = document.querySelectorAll( `[id^=frm_delete_field_${fieldId}-]` );
9939 + // return if there are no options.
9940 + if ( fieldOptions.length < 2 ) {
9941 + return;
9942 + }
9943 +
9944 + const options = [ ...fieldOptions ].slice( 1 );
9945 + options.forEach( ( li, _key ) => {
9946 + if ( li.classList.contains( 'frm_other_option' ) ) {
9947 + return;
9948 + }
9949 + addSaveAndDragIconsToOption( fieldId, li );
9950 + });
9951 + }
9952 +
9953 + function initOnSubmitAction() {
9954 + const onChangeType = event => {
9955 + if ( ! event.target.checked ) {
9956 + return;
9957 + }
9958 +
9959 + const actionEl = event.target.closest( '.frm_form_action_settings' );
9960 + actionEl.querySelectorAll( '.frm_on_submit_dependent_setting:not(.frm_hidden)' ).forEach( el => {
9961 + el.classList.add( 'frm_hidden' );
9962 + });
9963 +
9964 + const activeEls = actionEl.querySelectorAll( '.frm_on_submit_dependent_setting[data-show-if-' + event.target.value + ']' );
9965 + activeEls.forEach( activeEl => {
9966 + activeEl.classList.remove( 'frm_hidden' );
9967 + });
9968 +
9969 + actionEl.setAttribute( 'data-on-submit-type', event.target.value );
9970 + };
9971 +
9972 + frmDom.util.documentOn( 'change', '.frm_on_submit_type input[type="radio"]', onChangeType );
9973 + }
9974 +
9975 + /**
9976 + * Listen for click events for an API-loaded email collection form.
9977 + *
9978 + * This is used for the Active Campaign sign-up form in the inbox page (when there are no messages).
9979 + */
9980 + function initAddMyEmailAddress() {
9981 + jQuery( document ).on(
9982 + 'click',
9983 + '#frm-add-my-email-address',
9984 + event => {
9985 + event.preventDefault();
9986 + addMyEmailAddress();
9987 + }
9988 + );
9989 +
9990 + const emptyInbox = document.getElementById( 'frm_empty_inbox' );
9991 + const leaveEmailInput = document.getElementById( 'frm_leave_email' );
9992 +
9993 + if ( emptyInbox && leaveEmailInput ) {
9994 + const leaveEmailModal = document.getElementById( 'frm-leave-email-modal' );
9995 + leaveEmailModal.classList.remove( 'frm_hidden' );
9996 + leaveEmailModal.querySelector( '.frm_modal_footer' ).classList.add( 'frm_hidden' );
9997 +
9998 + leaveEmailInput.addEventListener(
9999 + 'keyup',
10000 + event => {
10001 + if ( 'Enter' === event.key ) {
10002 + const button = document.getElementById( 'frm-add-my-email-address' );
10003 + if ( button ) {
10004 + button.click();
10005 + }
10006 + }
10007 + }
10008 + );
10009 + }
10010 + }
10011 +
10012 + function addMyEmailAddress() {
10013 + const email = document.getElementById( 'frm_leave_email' ).value.trim();
10014 + if ( '' === email ) {
10015 + handleEmailAddressError( 'empty' );
10016 + return;
10017 + }
10018 +
10019 + const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i;
10020 + if ( regex.test( email ) === false ) {
10021 + handleEmailAddressError( 'invalid' );
10022 + return;
10023 + }
10024 +
10025 + const $hiddenForm = jQuery( '#frmapi-email-form' ).find( 'form' );
10026 + const $hiddenEmailField = $hiddenForm.find( '[type="email"]' ).not( '.frm_verify' );
10027 + if ( ! $hiddenEmailField.length ) {
10028 + return;
10029 + }
10030 +
10031 + const emptyInbox = document.getElementById( 'frm_empty_inbox' );
10032 + if ( emptyInbox ) {
10033 + document.getElementById( 'frm-add-my-email-address' ).remove();
10034 +
10035 + const emailWrapper = document.getElementById( 'frm_leave_email_wrapper' );
10036 + if ( emailWrapper ) {
10037 + emailWrapper.classList.add( 'frm_hidden' );
10038 + const spinner = span({ className: 'frm-wait frm_spinner' });
10039 + spinner.style.visibility = 'visible';
10040 + spinner.style.float = 'none';
10041 + spinner.style.width = 'unset';
10042 + emailWrapper.parentElement.insertBefore(
10043 + spinner,
10044 + emailWrapper.nextElementSibling
10045 + );
10046 + }
10047 + }
10048 +
10049 + $hiddenEmailField.val( email );
10050 + jQuery.ajax({
10051 + type: 'POST',
10052 + url: $hiddenForm.attr( 'action' ),
10053 + data: $hiddenForm.serialize() + '&action=frm_forms_preview'
10054 + }).done( function( data ) {
10055 + const message = jQuery( data ).find( '.frm_message' ).text().trim();
10056 + if ( message.indexOf( 'Thanks!' ) === -1 ) {
10057 + handleEmailAddressError( 'invalid' );
10058 + return;
10059 + }
10060 +
10061 + const apiForm = document.getElementById( 'frmapi-email-form' );
10062 + const spinner = apiForm.parentElement.querySelector( '.frm_spinner' );
10063 + if ( spinner ) {
10064 + spinner.remove();
10065 + }
10066 +
10067 + const showSuccessMessage = wp.hooks.applyFilters( 'frm_thank_you_on_signup', true );
10068 + if ( showSuccessMessage ) {
10069 + // Handle successful form submission.
10070 + // handle the Active Campaign form on the inbox page.
10071 + document.getElementById( 'frm_leave_email_wrapper' ).replaceWith(
10072 + span( __( 'Thank you for signing up!', 'formidable' ) )
10073 + );
10074 + }
10075 + });
10076 + }
10077 +
10078 + /**
10079 + * Adds footer links to the admin body content.
10080 + *
10081 + * @return {void}
10082 + */
10083 + function addAdminFooterLinks() {
10084 + const footerLinks = document.querySelector( '.frm-admin-footer-links' );
10085 + const container = document.querySelector( '.frm_page_container' ) ?? document.getElementById( 'wpbody-content' );
10086 +
10087 + if ( ! footerLinks || ! container ) {
10088 + return;
10089 + }
10090 +
10091 + container.appendChild( footerLinks );
10092 + footerLinks.classList.remove( 'frm_hidden' );
10093 + }
10094 +
10095 + /**
10096 + * Apply zebra striping to a table while ignoring empty rows.
10097 + *
10098 + * @param {string} tableSelector The CSS selector for the table.
10099 + * @param {string} emptyRowClass The class name used to identify empty rows.
10100 + */
10101 + function applyZebraStriping( tableSelector, emptyRowClass ) {
10102 + // Get all non-empty table rows within the specified table
10103 + const rows = document.querySelectorAll( `${tableSelector} tr${emptyRowClass ? `:not(.${emptyRowClass})` : ''}` );
10104 + if ( rows.length < 1 ) {
10105 + return;
10106 + }
10107 +
10108 + let isOdd = true;
10109 + rows.forEach( row => {
10110 + // Clean old "frm-odd" or "frm-even" classes and add the appropriate new class
10111 + row.classList.remove( 'frm-odd', 'frm-even' );
10112 + row.classList.add( isOdd ? 'frm-odd' : 'frm-even' );
10113 +
10114 + isOdd = ! isOdd;
10115 + });
10116 +
10117 + const tables = document.querySelectorAll( tableSelector );
10118 + tables.forEach( table => table.classList.add( 'frm-zebra-striping' ) );
10119 + };
10120 +
10121 + function maybeHideShortcodes( e ) {
10122 + if ( ! builderPage ) {
10123 + e.stopPropagation();
10124 + }
10125 +
10126 + if ( e.target.classList.contains( 'frm-show-box' ) || ( e.target.parentElement && e.target.parentElement.classList.contains( 'frm-show-box' ) ) ) {
10127 + return;
10128 + }
10129 +
10130 + const sidebar = document.getElementById( 'frm_adv_info' );
10131 + if ( ! sidebar ) {
10132 + return;
10133 + }
10134 +
10135 + if ( sidebar.dataset.fills === e.target.id && typeof e.target.id !== 'undefined' ) {
10136 + return;
10137 + }
10138 +
10139 + const isChild = e.target.closest( '#frm_adv_info' );
10140 +
10141 + if ( ! isChild && sidebar.style.display !== 'none' ) {
10142 + hideShortcodes( sidebar );
10143 + }
10144 + }
10145 +
10146 +
10147 + /**
10148 + * Initializes and manages the visibility of dependent elements based on the selected options in dropdowns with the 'frm_select_with_dependency' class.
10149 + * It sets up initial visibility at page load and updates it on each dropdown change.
10150 + *
10151 + * @since 6.9
10152 + *
10153 + * @return {void}
10154 + */
10155 + function initSelectDependencies() {
10156 + const selects = document.querySelectorAll( 'select.frm_select_with_dependency' );
10157 +
10158 + /**
10159 + * Toggles the visibility of dependent elements associated with a select element based on its current selection.
10160 + *
10161 + * @since 6.9
10162 + *
10163 + * @param {HTMLElement} select The select element whose dependencies need to be managed.
10164 + * @return {void}
10165 + */
10166 + function toggleDependencyVisibility( select ) {
10167 + const selectedOption = select.options[ select.selectedIndex ];
10168 + select.querySelectorAll( 'option[data-dependency]' ).forEach( option => {
10169 + const dependencyElement = document.querySelector( option.dataset.dependency );
10170 + dependencyElement?.classList.toggle( 'frm_hidden', selectedOption !== option );
10171 + });
10172 + }
10173 +
10174 + // Initial setup: Show dependencies based on the current selection in each dropdown
10175 + selects.forEach( toggleDependencyVisibility );
10176 +
10177 + // Update dependencies visibility on dropdown change
10178 + frmDom.util.documentOn( 'change', 'select.frm_select_with_dependency', ( event ) => toggleDependencyVisibility( event.target ) );
10179 + };
10180 +
10181 + return {
10182 + init: function() {
10183 + initAddMyEmailAddress();
10184 + addAdminFooterLinks();
10185 +
10186 + s = {};
10187 +
10188 + // Bootstrap dropdown button
10189 + jQuery( '.wp-admin' ).on( 'click', function( e ) {
10190 + const t = jQuery( e.target );
10191 + const $openDrop = jQuery( '.dropdown.open' );
10192 + if ( $openDrop.length && ! t.hasClass( 'dropdown' ) && ! t.closest( '.dropdown' ).length ) {
10193 + $openDrop.removeClass( 'open' );
10194 + }
10195 + });
10196 + jQuery( '#frm_bs_dropdown:not(.open) a' ).on( 'click', focusSearchBox );
10197 +
10198 + if ( typeof thisFormId === 'undefined' ) {
10199 + thisFormId = jQuery( document.getElementById( 'form_id' ) ).val();
10200 + }
10201 +
10202 + // Add event listener for dismissible warning messages.
10203 + document.querySelectorAll( '.frm-warning-dismiss' ).forEach( ( dismissIcon ) => {
10204 + onClickPreventDefault( dismissIcon, dismissWarningMessage );
10205 + });
10206 +
10207 + frmAdminBuild.inboxBannerInit();
10208 +
10209 + if ( $newFields.length > 0 ) {
10210 + // only load this on the form builder page
10211 + frmAdminBuild.buildInit();
10212 + } else if ( document.getElementById( 'frm_notification_settings' ) !== null ) {
10213 + // only load on form settings page
10214 + frmAdminBuild.settingsInit();
10215 + } else if ( document.getElementById( 'frm_styling_form' ) !== null ) {
10216 + // load styling settings js
10217 + frmAdminBuild.styleInit();
10218 + } else if ( document.getElementById( 'form_global_settings' ) !== null ) {
10219 + // global settings page
10220 + frmAdminBuild.globalSettingsInit();
10221 + } else if ( document.getElementById( 'frm_export_xml' ) !== null ) {
10222 + // import/export page
10223 + frmAdminBuild.exportInit();
10224 + } else if ( document.getElementById( 'frm_dyncontent' ) !== null ) {
10225 + // only load on views settings page
10226 + frmAdminBuild.viewInit();
10227 + } else if ( null !== document.querySelector( '.frm-inbox-wrapper' ) ) {
10228 + // Dashboard page inbox.
10229 + frmAdminBuild.inboxInit();
10230 + } else if ( document.getElementById( 'frm-welcome' ) !== null ) {
10231 + // Solution install page
10232 + frmAdminBuild.solutionInit();
10233 + } else {
10234 + initSelectionAutocomplete();
10235 +
10236 + jQuery( '[data-frmprint]' ).on( 'click', function() {
10237 + window.print();
10238 + return false;
10239 + });
10240 + }
10241 +
10242 + jQuery( document ).on( 'change', 'select[data-toggleclass], input[data-toggleclass]', toggleFormOpts );
10243 + initSelectDependencies();
10244 +
10245 + const $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) );
10246 + if ( $advInfo.length > 0 || jQuery( '.frm_field_list' ).length > 0 ) {
10247 + // only load on the form, form settings, and view settings pages
10248 + frmAdminBuild.panelInit();
10249 + }
10250 +
10251 + loadTooltips();
10252 + initUpgradeModal();
10253 +
10254 + // used on build, form settings, and view settings
10255 + const $shortCodeDiv = jQuery( document.getElementById( 'frm_shortcodediv' ) );
10256 + if ( $shortCodeDiv.length > 0 ) {
10257 + jQuery( 'a.edit-frm_shortcode' ).on( 'click', function() {
10258 + if ( $shortCodeDiv.is( ':hidden' ) ) {
10259 + $shortCodeDiv.slideDown( 'fast' );
10260 + this.style.display = 'none';
10261 + }
10262 + return false;
10263 + });
10264 +
10265 + jQuery( '.cancel-frm_shortcode', '#frm_shortcodediv' ).on( 'click', function() {
10266 + $shortCodeDiv.slideUp( 'fast' );
10267 + $shortCodeDiv.siblings( 'a.edit-frm_shortcode' ).show();
10268 + return false;
10269 + });
10270 + }
10271 +
10272 + // tabs
10273 + jQuery( document ).on( 'click', '#frm-nav-tabs a', clickNewTab );
10274 + jQuery( '.post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a' ).on( 'click', function() {
10275 + const showUpgradeTab = this.classList.contains( 'frm_show_upgrade_tab' );
10276 + if ( this.classList.contains( 'frm_noallow' ) && ! showUpgradeTab ) {
10277 + return;
10278 + }
10279 +
10280 + if ( showUpgradeTab ) {
10281 + populateUpgradeTab( this );
10282 + }
10283 +
10284 + clickTab( this );
10285 + return false;
10286 + });
10287 + clickTab( jQuery( '.starttab a' ), 'auto' );
10288 +
10289 + // submit the search form with dropdown
10290 + jQuery( document ).on( 'click', '#frm-fid-search-menu a', function() {
10291 + const val = this.id.replace( 'fid-', '' );
10292 + jQuery( 'select[name="fid"]' ).val( val );
10293 + triggerSubmit( document.getElementById( 'posts-filter' ) );
10294 + return false;
10295 + });
10296 +
10297 + jQuery( '.frm_select_box' ).on( 'click focus', function() {
10298 + this.select();
10299 + });
10300 +
10301 + jQuery( document ).on( 'input search change', '.frm-auto-search:not(#frm-form-templates-page #template-search-input)', searchContent );
10302 + jQuery( document ).on( 'focusin click', '.frm-auto-search', stopPropagation );
10303 + const autoSearch = jQuery( '.frm-auto-search' );
10304 + if ( autoSearch.val() !== '' ) {
10305 + autoSearch.trigger( 'keyup' );
10306 + }
10307 +
10308 + // Initialize Formidable Connection.
10309 + FrmFormsConnect.init();
10310 +
10311 + jQuery( document ).on( 'click', '.frm-install-addon', installAddon );
10312 + jQuery( document ).on( 'click', '.frm-activate-addon', activateAddon );
10313 + jQuery( document ).on( 'click', '.frm-solution-multiple', installMultipleAddons );
10314 +
10315 + // prevent annoying confirmation message from WordPress
10316 + jQuery( 'button, input[type=submit]' ).on( 'click', removeWPUnload );
10317 +
10318 + addMultiselectLabelListener();
10319 +
10320 + frmAdminBuild.hooks.addFilter(
10321 + 'frm_before_embed_modal',
10322 + ( ids, { element, type }) => {
10323 + if ( 'form' !== type ) {
10324 + return ids;
10325 + }
10326 +
10327 + let formId, formKey;
10328 + const row = element.closest( 'tr' );
10329 +
10330 + if ( row ) {
10331 + // Embed icon on form index.
10332 + formId = parseInt( row.querySelector( '.column-id' ).textContent );
10333 + formKey = row.querySelector( '.column-form_key' ).textContent;
10334 + } else {
10335 + // Embed button in form builder / form settings.
10336 + formId = document.getElementById( 'form_id' ).value;
10337 +
10338 + const formKeyInput = document.getElementById( 'frm_form_key' );
10339 + if ( formKeyInput ) {
10340 + formKey = formKeyInput.value;
10341 + } else {
10342 + const previewDrop = document.getElementById( 'frm-previewDrop' );
10343 + if ( previewDrop ) {
10344 + formKey = previewDrop.nextElementSibling.querySelector( '.dropdown-item a' ).getAttribute( 'href' ).split( 'form=' )[1];
10345 + }
10346 + }
10347 + }
10348 +
10349 + return [ formId, formKey ];
10350 + }
10351 + );
10352 +
10353 + document.querySelectorAll( '#frm-show-fields > li, .frm_grid_container li' ).forEach( ( el, _key ) => {
10354 + el.addEventListener( 'click', function() {
10355 + const fieldId = this.querySelector( 'li' )?.dataset.fid || this.dataset.fid;
10356 + maybeAddSaveAndDragIcons( fieldId );
10357 + });
10358 + });
10359 + },
10360 +
10361 + buildInit: function() {
10362 + jQuery( '#frm_builder_page' ).on( 'mouseup', '*:not(.frm-show-box)', maybeHideShortcodes );
10363 +
10364 + let loadFieldId, $builderForm, builderArea;
10365 +
10366 + debouncedSyncAfterDragAndDrop = debounce( syncAfterDragAndDrop, 10 );
10367 + postBodyContent = document.getElementById( 'post-body-content' );
10368 + $postBodyContent = jQuery( postBodyContent );
10369 +
10370 + if ( jQuery( '.frm_field_loading' ).length ) {
10371 + loadFieldId = jQuery( '.frm_field_loading' ).first().attr( 'id' );
10372 + loadFields( loadFieldId );
10373 + }
10374 +
10375 + setupSortable( 'ul.frm_sorting' );
10376 +
10377 + document.querySelectorAll( '.field_type_list > li:not(.frm_show_upgrade)' ).forEach( makeDraggable );
10378 +
10379 + 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();
10380 +
10381 + jQuery( '.frm_submit_ajax' ).on( 'click', submitBuild );
10382 + jQuery( '.frm_submit_no_ajax' ).on( 'click', submitNoAjax );
10383 +
10384 + addFormNameModalEvents();
10385 +
10386 + jQuery( 'a.edit-form-status' ).on( 'click', slideDown );
10387 + jQuery( '.cancel-form-status' ).on( 'click', slideUp );
10388 + jQuery( '.save-form-status' ).on( 'click', function() {
10389 + const newStatus = jQuery( document.getElementById( 'form_change_status' ) ).val();
10390 + jQuery( 'input[name="new_status"]' ).val( newStatus );
10391 + jQuery( document.getElementById( 'form-status-display' ) ).html( newStatus );
10392 + jQuery( '.cancel-form-status' ).trigger( 'click' );
10393 + return false;
10394 + });
10395 +
10396 + jQuery( '.frm_form_builder form' ).first().on( 'submit', function() {
10397 + jQuery( '.inplace_field' ).trigger( 'blur' );
10398 + });
10399 +
10400 + initiateMultiselect();
10401 + renumberPageBreaks();
10402 +
10403 + $builderForm = jQuery( builderForm );
10404 + builderArea = document.getElementById( 'frm_form_editor_container' );
10405 + $builderForm.on( 'click', '.frm_add_logic_row', addFieldLogicRow );
10406 + $builderForm.on( 'click', '.frm_add_watch_lookup_row', addWatchLookupRow );
10407 + $builderForm.on( 'change', '.frm_get_values_form', updateGetValueFieldSelection );
10408 + $builderForm.on( 'change', '.frm_logic_field_opts', getFieldValues );
10409 + $builderForm.on( 'frm-multiselect-changed', 'select[name^="field_options[admin_only_"]', adjustVisibilityValuesForEveryoneValues );
10410 +
10411 + jQuery( document.getElementById( 'frm-insert-fields' ) ).on( 'click', '.frm_add_field', addFieldClick );
10412 + $newFields.on( 'click', '.frm_clone_field', duplicateField );
10413 + $builderForm.on( 'blur', 'input[id^="frm_calc"]', checkCalculationCreatedByUser );
10414 + $builderForm.on( 'change', 'input.frm_format_opt, input.frm_max_length_opt', toggleInvalidMsg );
10415 + $builderForm.on( 'change click', '[data-changeme]', liveChanges );
10416 + $builderForm.on( 'click', 'input.frm_req_field', markRequired );
10417 + $builderForm.on( 'click', '.frm_mark_unique', markUnique );
10418 +
10419 + $builderForm.on( 'change', '.frm_repeat_format', toggleRepeatButtons );
10420 + $builderForm.on( 'change', '.frm_repeat_limit', checkRepeatLimit );
10421 + $builderForm.on( 'change', '.frm_js_checkbox_limit', checkCheckboxSelectionsLimit );
10422 + $builderForm.on( 'input', 'input[name^="field_options[add_label_"]', function() {
10423 + updateRepeatText( this, 'add' );
10424 + });
10425 + $builderForm.on( 'input', 'input[name^="field_options[remove_label_"]', function() {
10426 + updateRepeatText( this, 'remove' );
10427 + });
10428 + $builderForm.on( 'change', 'select[name^="field_options[data_type_"]', maybeClearWatchFields );
10429 + jQuery( builderArea ).on( 'click', '.frm-collapse-page', maybeCollapsePage );
10430 + jQuery( builderArea ).on( 'click', '.frm-collapse-section', maybeCollapseSection );
10431 + $builderForm.on( 'click', '.frm-single-settings h3', maybeCollapseSettings );
10432 + $builderForm.on( 'keydown', '.frm-single-settings h3', function( event ) {
10433 + // If so, only proceed if the key pressed was 'Enter' or 'Space'
10434 + if ( event.key === 'Enter' || event.key === ' ' ) {
10435 + event.preventDefault();
10436 + maybeCollapseSettings.call( this, event );
10437 + }
10438 + });
10439 +
10440 + jQuery( builderArea ).on( 'show.bs.dropdown hide.bs.dropdown', changeSectionStyle );
10441 +
10442 + $builderForm.on( 'click', '.frm_toggle_sep_values', toggleSepValues );
10443 + $builderForm.on( 'click', '.frm_toggle_image_options', toggleImageOptions );
10444 + $builderForm.on( 'click', '.frm_remove_image_option', removeImageFromOption );
10445 + $builderForm.on( 'click', '.frm_choose_image_box', addImageToOption );
10446 + $builderForm.on( 'change', '.frm_hide_image_text', refreshOptionDisplay );
10447 + $builderForm.on( 'change', '.frm_field_options_image_size', setImageSize );
10448 + $builderForm.on( 'click', '.frm_multiselect_opt', toggleMultiselect );
10449 + $newFields.on( 'mousedown', 'input, textarea, select', stopFieldFocus );
10450 + $newFields.on( 'click', 'input[type=radio], input[type=checkbox]', stopFieldFocus );
10451 + $newFields.on( 'click', '.frm_delete_field', clickDeleteField );
10452 + $newFields.on( 'click', '.frm_select_field', clickSelectField );
10453 + jQuery( document ).on( 'click', '.frm_delete_field_group', clickDeleteFieldGroup );
10454 + jQuery( document ).on( 'click', '.frm_clone_field_group', duplicateFieldGroup );
10455 + jQuery( document ).on( 'click', '#frm_field_group_controls > span:first-child', clickFieldGroupLayout );
10456 + jQuery( document ).on( 'click', '.frm-row-layout-option', handleFieldGroupLayoutOptionClick );
10457 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-row-layout-option', handleFieldGroupLayoutOptionInsideMergeClick );
10458 + jQuery( document ).on( 'click', '.frm-custom-field-group-layout', customFieldGroupLayoutClick );
10459 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-custom-field-group-layout', customFieldGroupLayoutInsideMergeClick );
10460 + jQuery( document ).on( 'click', '.frm-break-field-group', breakFieldGroupClick );
10461 + $newFields.on( 'click', '#frm_field_group_popup .frm_grid_container input', focusFieldGroupInputOnClick );
10462 + jQuery( document ).on( 'click', '.frm-cancel-custom-field-group-layout', cancelCustomFieldGroupClick );
10463 + jQuery( document ).on( 'click', '.frm-save-custom-field-group-layout', saveCustomFieldGroupClick );
10464 + $newFields.on( 'click', 'ul.frm_sorting', fieldGroupClick );
10465 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row', mergeFieldsIntoRowClick );
10466 + jQuery( document ).on( 'click', '.frm-delete-field-groups', deleteFieldGroupsClick );
10467 + $newFields.on( 'click', '.frm-field-action-icons [data-toggle="dropdown"]', function() {
10468 + this.closest( 'li.form-field' ).classList.add( 'frm-field-settings-open' );
10469 + jQuery( document ).on( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings );
10470 + });
10471 + $newFields.on( 'mousemove', 'ul.frm_sorting', checkForMultiselectKeysOnMouseMove );
10472 + $newFields.on( 'show.bs.dropdown', '.frm-field-action-icons', onFieldActionDropdownShow );
10473 + jQuery( document ).on( 'show.bs.dropdown', '#frm_field_group_controls', onFieldGroupActionDropdownShow );
10474 + $builderForm.on( 'click', '.frm_single_option a[data-removeid]', deleteFieldOption );
10475 + $builderForm.on( 'mousedown', '.frm_single_option input[type=radio]', maybeUncheckRadio );
10476 + $builderForm.on( 'focusin', '.frm_single_option input[type=text]', maybeClearOptText );
10477 + $builderForm.on( 'click', '.frm_add_opt', addFieldOption );
10478 + $builderForm.on( 'change', '.frm_single_option input', resetOptOnChange );
10479 + $builderForm.on( 'change', '.frm_image_id', resetOptOnChange );
10480 + $builderForm.on( 'change', '.frm_toggle_mult_sel', toggleMultSel );
10481 + $builderForm.on( 'focusin', '.frm_classes', showBuilderModal );
10482 +
10483 + $newFields.on( 'click', '.frm_primary_label', clickLabel );
10484 + $newFields.on( 'click', '.frm_description', clickDescription );
10485 + $newFields.on( 'click', 'li.ui-state-default:not(.frm_noallow)', clickVis );
10486 + $newFields.on( 'dblclick', 'li.ui-state-default', openAdvanced );
10487 + $builderForm.on( 'change', '.frm_tax_form_select', toggleFormTax );
10488 + $builderForm.on( 'change', 'select.conf_field', addConf );
10489 +
10490 + $builderForm.on( 'change', '.frm_get_field_selection', getFieldSelection );
10491 +
10492 + $builderForm.on( 'click', '.frm-show-inline-modal', maybeShowInlineModal );
10493 +
10494 + $builderForm.on( 'click', '.frm-inline-modal .dismiss', dismissInlineModal );
10495 + jQuery( document ).on( 'change', '[data-frmchange]', changeInputtedValue );
10496 +
10497 + $builderForm.on( 'change', '.frm_include_extras_field', rePopCalcFieldsForSummary );
10498 + $builderForm.on( 'change', 'select[name^="field_options[form_select_"]', maybeChangeEmbedFormMsg );
10499 +
10500 + jQuery( document ).on( 'submit', '#frm_js_build_form', buildSubmittedNoAjax );
10501 + 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 );
10502 +
10503 + popAllProductFields();
10504 +
10505 + jQuery( document ).on( 'change', '.frmjs_prod_data_type_opt', toggleProductType );
10506 +
10507 + jQuery( document ).on( 'focus', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextFocus );
10508 + jQuery( document ).on( 'blur', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextBlur );
10509 +
10510 + frmDom.util.documentOn( 'click', '.frm-show-field-settings', clickVis );
10511 + frmDom.util.documentOn( 'change', 'select.frm_phone_type_dropdown', maybeUpdatePhoneFormatInput );
10512 +
10513 + initBulkOptionsOverlay();
10514 + hideEmptyEle();
10515 + maybeHideQuantityProductFieldOption();
10516 + handleNameFieldOnFormBuilder();
10517 + toggleSectionHolder();
10518 + handleShowPasswordLiveUpdate();
10519 + document.addEventListener( 'scroll', updateShortcodesPopupPosition, true );
10520 + },
10521 +
10522 + settingsInit: function() {
10523 + const $formActions = jQuery( document.getElementById( 'frm_notification_settings' ) );
10524 +
10525 + let formSettings, $loggedIn, $cookieExp, $editable;
10526 +
10527 + // BCC, CC, and Reply To button functionality
10528 + $formActions.on( 'click', '.frm_email_buttons', showEmailRow );
10529 + $formActions.on( 'click', '.frm_remove_field', hideEmailRow );
10530 + $formActions.on( 'change', '.frm_to_row, .frm_from_row', showEmailWarning );
10531 + $formActions.on( 'change', '.frm_tax_selector', changePosttaxRow );
10532 + $formActions.on( 'change', 'select.frm_single_post_field', checkDupPost );
10533 + $formActions.on( 'change', 'select.frm_toggle_post_content', togglePostContent );
10534 + $formActions.on( 'change', 'select.frm_dyncontent_opt', fillDyncontent );
10535 + $formActions.on( 'change', '.frm_post_type', switchPostType );
10536 + $formActions.on( 'click', '.frm_add_postmeta_row', addPostmetaRow );
10537 + $formActions.on( 'click', '.frm_add_posttax_row', addPosttaxRow );
10538 + $formActions.on( 'click', '.frm_toggle_cf_opts', toggleCfOpts );
10539 + $formActions.on( 'click', '.frm_duplicate_form_action', copyFormAction );
10540 + jQuery( '.frm_actions_list' ).on( 'click', '.frm_active_action', addFormAction );
10541 + jQuery( '#frm-show-groups, #frm-hide-groups' ).on( 'click', toggleActionGroups );
10542 + initiateMultiselect();
10543 +
10544 + //set actions icons to inactive
10545 + jQuery( 'ul.frm_actions_list li' ).each( function() {
10546 + checkActiveAction( jQuery( this ).children( 'a' ).data( 'actiontype' ) );
10547 +
10548 + // If the icon is a background image, don't add BG color.
10549 + const icon = jQuery( this ).find( 'i' );
10550 + if ( icon.css( 'background-image' ) !== 'none' ) {
10551 + icon.addClass( 'frm-inverse' );
10552 + }
10553 + });
10554 +
10555 + jQuery( '.frm_submit_settings_btn' ).on( 'click', submitSettings );
10556 +
10557 + addFormNameModalEvents();
10558 +
10559 + formSettings = jQuery( '.frm_form_settings' );
10560 + formSettings.on( 'click', '.frm_add_form_logic', addFormLogicRow );
10561 + formSettings.on( 'click', '.frm_already_used', actionLimitMessage );
10562 +
10563 + formSettings.on( 'change', '#logic_link_submit', toggleSubmitLogic );
10564 + formSettings.on( 'click', '.frm_add_submit_logic', addSubmitLogic );
10565 + formSettings.on( 'change', '.frm_submit_logic_field_opts', addSubmitLogicOpts );
10566 +
10567 + document.addEventListener(
10568 + 'click',
10569 + function handleImageUploadClickEvents( event ) {
10570 + const { target } = event;
10571 +
10572 + if ( ! target.closest( '.frm_image_preview_wrapper' ) ) {
10573 + return;
10574 + }
10575 +
10576 + if ( target.closest( '.frm_choose_image_box' ) ) {
10577 + addImageToOption.bind( target )( event );
10578 + return;
10579 + }
10580 +
10581 + if ( target.closest( '.frm_remove_image_option' ) ) {
10582 + removeImageFromOption.bind( target )( event );
10583 + }
10584 + }
10585 + );
10586 +
10587 + // Close shortcode modal on click.
10588 + formSettings.on( 'mouseup', '*:not(.frm-show-box)', maybeHideShortcodes );
10589 +
10590 + //Warning when user selects "Do not store entries ..."
10591 + jQuery( document.getElementById( 'no_save' ) ).on( 'change', function() {
10592 + if ( this.checked ) {
10593 + if ( confirm( frmAdminJs.no_save_warning ) !== true ) {
10594 + // Uncheck box if user hits "Cancel"
10595 + jQuery( this ).attr( 'checked', false );
10596 + }
10597 + }
10598 + });
10599 +
10600 + jQuery( 'select[name="options[edit_action]"]' ).on( 'change', showSuccessOpt );
10601 +
10602 + $loggedIn = document.getElementById( 'logged_in' );
10603 + jQuery( $loggedIn ).on( 'change', function() {
10604 + if ( this.checked ) {
10605 + visible( '.hide_logged_in' );
10606 + } else {
10607 + invisible( '.hide_logged_in' );
10608 + }
10609 + });
10610 +
10611 + $cookieExp = jQuery( document.getElementById( 'frm_cookie_expiration' ) );
10612 + jQuery( document.getElementById( 'frm_single_entry_type' ) ).on( 'change', function() {
10613 + if ( this.value === 'cookie' ) {
10614 + $cookieExp.fadeIn( 'slow' );
10615 + } else {
10616 + $cookieExp.fadeOut( 'slow' );
10617 + }
10618 + });
10619 +
10620 + const $singleEntry = document.getElementById( 'single_entry' );
10621 + jQuery( $singleEntry ).on( 'change', function() {
10622 + if ( this.checked ) {
10623 + visible( '.hide_single_entry' );
10624 + } else {
10625 + invisible( '.hide_single_entry' );
10626 + }
10627 +
10628 + if ( this.checked && jQuery( document.getElementById( 'frm_single_entry_type' ) ).val() === 'cookie' ) {
10629 + $cookieExp.fadeIn( 'slow' );
10630 + } else {
10631 + $cookieExp.fadeOut( 'slow' );
10632 + }
10633 + });
10634 +
10635 + jQuery( '.hide_save_draft' ).hide();
10636 +
10637 + const $saveDraft = jQuery( document.getElementById( 'save_draft' ) );
10638 + $saveDraft.on( 'change', function() {
10639 + if ( this.checked ) {
10640 + jQuery( '.hide_save_draft' ).fadeIn( 'slow' );
10641 + } else {
10642 + jQuery( '.hide_save_draft' ).fadeOut( 'slow' );
10643 + }
10644 + });
10645 + triggerChange( $saveDraft );
10646 +
10647 + //If Allow editing is checked/unchecked
10648 + $editable = document.getElementById( 'editable' );
10649 + jQuery( $editable ).on( 'change', function() {
10650 + if ( this.checked ) {
10651 + jQuery( '.hide_editable' ).fadeIn( 'slow' );
10652 + triggerChange( document.getElementById( 'edit_action' ) );
10653 + } else {
10654 + jQuery( '.hide_editable' ).fadeOut( 'slow' );
10655 + jQuery( '.edit_action_message_box' ).fadeOut( 'slow' );//Hide On Update message box
10656 + }
10657 + });
10658 +
10659 + //If File Protection is checked/unchecked
10660 + jQuery( document ).on( 'change', '#protect_files', function() {
10661 + if ( this.checked ) {
10662 + jQuery( '.hide_protect_files' ).fadeIn( 'slow' );
10663 + } else {
10664 + jQuery( '.hide_protect_files' ).fadeOut( 'slow' );
10665 + }
10666 + });
10667 +
10668 + jQuery( document ).on( 'frm-multiselect-changed', '#protect_files_role', adjustVisibilityValuesForEveryoneValues );
10669 +
10670 + jQuery( document ).on( 'submit', '.frm_form_settings', settingsSubmitted );
10671 + jQuery( document ).on( 'change', '#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea', fieldUpdated );
10672 +
10673 + // Page Selection Autocomplete
10674 + initSelectionAutocomplete();
10675 +
10676 + jQuery( document ).on( 'frm-action-loaded', onActionLoaded );
10677 +
10678 + initOnSubmitAction();
10679 + },
10680 +
10681 + panelInit: function() {
10682 + let customPanel, settingsPage, viewPage, insertFieldsTab;
10683 +
10684 + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'click', '.frm_insert_code', insertCode );
10685 + jQuery( document ).on( 'change', '.frm_insert_val', function() {
10686 + insertFieldCode( jQuery( this ).data( 'target' ), jQuery( this ).val() );
10687 + jQuery( this ).val( '' );
10688 + });
10689 +
10690 + jQuery( document ).on( 'click change', '#frm-id-key-condition', resetLogicBuilder );
10691 + jQuery( document ).on( 'keyup change', '.frm-build-logic', setLogicExample );
10692 +
10693 + showInputIcon();
10694 + jQuery( document ).on( 'frmElementAdded', function( event, parentEle ) {
10695 + /* This is here for add-ons to trigger */
10696 + showInputIcon( parentEle );
10697 + });
10698 + jQuery( document ).on( 'mousedown', '.frm-show-box', showShortcodes );
10699 +
10700 + settingsPage = document.getElementById( 'form_settings_page' );
10701 + viewPage = document.body.classList.contains( 'post-type-frm_display' );
10702 + insertFieldsTab = document.getElementById( 'frm_insert_fields_tab' );
10703 +
10704 + if ( settingsPage !== null || viewPage || builderPage ) {
10705 + jQuery( document ).on( 'focusin', 'form input, form textarea', function( e ) {
10706 + let htmlTab;
10707 + e.stopPropagation();
10708 + maybeShowModal( this );
10709 +
10710 + if ( jQuery( this ).is( ':not(:submit, input[type=button], .frm-search-input, input[type=checkbox])' ) ) {
10711 + if ( jQuery( e.target ).closest( '#frm_adv_info' ).length ) {
10712 + // Don't trigger for fields inside of the modal.
10713 + return;
10714 + }
10715 +
10716 + if ( settingsPage !== null || builderPage ) {
10717 + /* form settings page */
10718 + htmlTab = jQuery( '#frm_html_tab' );
10719 + if ( jQuery( this ).closest( '#html_settings' ).length > 0 ) {
10720 + htmlTab.show();
10721 + htmlTab.siblings().hide();
10722 + jQuery( '#frm_html_tab a' ).trigger( 'click' );
10723 + toggleAllowedHTML( this );
10724 + } else {
10725 + showElement( jQuery( '.frm-category-tabs li' ) );
10726 + insertFieldsTab.click();
10727 + htmlTab.hide();
10728 + htmlTab.siblings().show();
10729 + }
10730 + } else if ( viewPage ) {
10731 + // Run on view page.
10732 + toggleAllowedShortcodes( this.id );
10733 + }
10734 + }
10735 + });
10736 + }
10737 +
10738 + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'mousedown', '#frm_adv_info a, .frm_field_list a', function( e ) {
10739 + e.preventDefault();
10740 + });
10741 +
10742 + customPanel = jQuery( '#frm_adv_info' );
10743 + customPanel.on( 'click', '.subsubsub a.frmids', function( e ) {
10744 + toggleKeyID( 'frmids', e );
10745 + });
10746 + customPanel.on( 'click', '.subsubsub a.frmkeys', function( e ) {
10747 + toggleKeyID( 'frmkeys', e );
10748 + });
10749 + },
10750 +
10751 + viewInit: function() {
10752 + let $addRemove,
10753 + $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) );
10754 + $advInfo.before( '<div id="frm_position_ele"></div>' );
10755 + setupMenuOffset();
10756 +
10757 + jQuery( document ).on( 'blur', '#param', checkDetailPageSlug );
10758 + jQuery( document ).on( 'blur', 'input[name^="options[where_val]"]', checkFilterParamNames );
10759 +
10760 + // Show loading indicator.
10761 + jQuery( '#publish' ).on( 'mousedown', function() {
10762 + fieldsUpdated = 0;
10763 + this.classList.add( 'frm_loading_button' );
10764 + });
10765 +
10766 + // move content tabs
10767 + jQuery( '#frm_dyncontent .handlediv' ).before( jQuery( '#frm_dyncontent .nav-menus-php' ) );
10768 +
10769 + // click content tabs
10770 + jQuery( '.nav-tab-wrapper a' ).on( 'click', clickContentTab );
10771 +
10772 + // click tabs after panel is replaced with ajax
10773 + jQuery( '#side-sortables' ).on( 'click', '.frm_doing_ajax.categorydiv .category-tabs a', clickTabsAfterAjax );
10774 +
10775 + initToggleShortcodes();
10776 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' );
10777 +
10778 + jQuery( 'input[name="show_count"]' ).on( 'change', showCount );
10779 +
10780 + jQuery( document.getElementById( 'form_id' ) ).on( 'change', displayFormSelected );
10781 +
10782 + $addRemove = jQuery( '.frm_repeat_rows' );
10783 + $addRemove.on( 'click', '.frm_add_order_row', addOrderRow );
10784 + $addRemove.on( 'click', '.frm_add_where_row', addWhereRow );
10785 + $addRemove.on( 'change', '.frm_insert_where_options', insertWhereOptions );
10786 + $addRemove.on( 'change', '.frm_where_is_options', hideWhereOptions );
10787 +
10788 + setDefaultPostStatus();
10789 + },
10790 +
10791 + inboxInit: function() {
10792 + jQuery( '.frm_inbox_dismiss' ).on( 'click', function( e ) {
10793 + const message = this.parentNode.parentNode;
10794 + const key = message.getAttribute( 'data-message' );
10795 + const href = this.getAttribute( 'href' );
10796 + const dismissedMessage = message.cloneNode( true );
10797 + const dismissedMessagesWrapper = document.querySelector( '.frm-dismissed-inbox-messages' );
10798 +
10799 + if ( 'free_templates' === key && ! this.classList.contains( 'frm_inbox_dismiss' ) ) {
10800 + return;
10801 + }
10802 +
10803 + e.preventDefault();
10804 +
10805 + data = {
10806 + action: 'frm_inbox_dismiss',
10807 + key,
10808 + nonce: frmGlobal.nonce
10809 + };
10810 +
10811 + const isInboxSlideIn = 'frm_inbox_slide_in' === message.id;
10812 + if ( isInboxSlideIn ) {
10813 + message.classList.remove( 's11-fadein' );
10814 + message.classList.add( 's11-fadeout' );
10815 + message.addEventListener( 'animationend', () => message.remove(), { once: true });
10816 + }
10817 +
10818 + postAjax(
10819 + data,
10820 + () => {
10821 + if ( isInboxSlideIn ) {
10822 + return;
10823 + }
10824 +
10825 + if ( href !== '#' ) {
10826 + window.location = href;
10827 + return true;
10828 + }
10829 +
10830 + fadeOut(
10831 + message,
10832 + () => {
10833 + if ( null !== dismissedMessagesWrapper ) {
10834 + dismissedMessage.classList.remove( 'frm-fade' );
10835 + dismissedMessage.querySelector( '.frm-inbox-message-heading' )?.removeChild( dismissedMessage.querySelector( '.frm-inbox-message-heading .frm_inbox_dismiss' ) );
10836 + dismissedMessagesWrapper.append( dismissedMessage );
10837 + }
10838 + if ( 1 === message.parentNode.querySelectorAll( '.frm-inbox-message-container' ).length ) {
10839 + document.getElementById( 'frm_empty_inbox' ).classList.remove( 'frm_hidden' );
10840 + message.parentNode.closest( '.frm-active' ).classList.add( 'frm-empty-inbox' );
10841 + showActiveCampaignForm();
10842 + }
10843 + message.parentNode.removeChild( message );
10844 + }
10845 + );
10846 + }
10847 + );
10848 + });
10849 +
10850 + if ( false === document.getElementById( 'frm_empty_inbox' )?.classList.contains( 'frm_hidden' ) ) {
10851 + showActiveCampaignForm();
10852 + }
10853 + },
10854 +
10855 + solutionInit: function() {
10856 + jQuery( document ).on( 'submit', '#frm-new-template', installTemplate );
10857 + },
10858 +
10859 + styleInit: function() {
10860 + const $previewWrapper = jQuery( '.frm_image_preview_wrapper' );
10861 + $previewWrapper.on( 'click', '.frm_choose_image_box', addImageToOption );
10862 + $previewWrapper.on( 'click', '.frm_remove_image_option', removeImageFromOption );
10863 +
10864 + wp.hooks.doAction( 'frm_style_editor_init' );
10865 + },
10866 +
10867 + customCSSInit: function() {
10868 + console.warn( 'Calling frmAdminBuild.customCSSInit is deprecated.' );
10869 + },
10870 +
10871 + globalSettingsInit: function() {
10872 + let licenseTab;
10873 +
10874 + jQuery( document ).on( 'click', '[data-frmuninstall]', uninstallNow );
10875 +
10876 + initiateMultiselect();
10877 +
10878 + // activate addon licenses
10879 + licenseTab = document.getElementById( 'licenses_settings' );
10880 + if ( licenseTab !== null ) {
10881 + jQuery( licenseTab ).on( 'click', '.edd_frm_save_license', saveAddonLicense );
10882 + }
10883 +
10884 + // Solution install page
10885 + jQuery( document ).on( 'click', '#frm-new-template button', installTemplateFieldset );
10886 +
10887 + jQuery( '#frm-dismissable-cta .dismiss' ).on( 'click', function( event ) {
10888 + event.preventDefault();
10889 + jQuery.post(
10890 + ajaxurl,
10891 + {
10892 + action: 'frm_lite_settings_upgrade',
10893 + nonce: frmGlobal.nonce
10894 + }
10895 + );
10896 + jQuery( '.settings-lite-cta' ).remove();
10897 + });
10898 +
10899 + const captchaType = document.getElementById( 'frm_re_type' );
10900 + if ( captchaType ) {
10901 + captchaType.addEventListener( 'change', handleCaptchaTypeChange );
10902 + }
10903 +
10904 + document.querySelector( '.frm_captchas' ).addEventListener( 'change', function( event ) {
10905 + const captchaValueOnLoad = document.querySelector( '.frm_captchas input[checked="checked"]' )?.value;
10906 + const showNote = event.target.value !== captchaValueOnLoad;
10907 + document.querySelector( '.captcha_settings .frm_note_style' ).classList.toggle( 'frm_hidden', ! showNote );
10908 + });
10909 +
10910 + // Set fieldsUpdated to 0 to avoid the unsaved changes pop up.
10911 + frmDom.util.documentOn( 'submit', '.frm_settings_form', () => fieldsUpdated = 0 );
10912 +
10913 + const manageStyleSettings = document.getElementById( 'manage_styles_settings' );
10914 + if ( manageStyleSettings ) {
10915 + manageStyleSettings.addEventListener(
10916 + 'change',
10917 + event => {
10918 + const target = event.target;
10919 + if ( 'SELECT' !== target.nodeName || ! target.dataset.name || target.getAttribute( 'name' ) ) {
10920 + return;
10921 + }
10922 +
10923 + target.setAttribute( 'name', target.dataset.name );
10924 + }
10925 + );
10926 + }
10927 + },
10928 +
10929 + exportInit: function() {
10930 + jQuery( '.frm_form_importer' ).on( 'submit', startFormMigration );
10931 + jQuery( document.getElementById( 'frm_export_xml' ) ).on( 'submit', validateExport );
10932 + jQuery( '#frm_export_xml input, #frm_export_xml select' ).on( 'change', removeExportError );
10933 + jQuery( 'input[name="frm_import_file"]' ).on( 'change', checkCSVExtension );
10934 + document.querySelector( 'select[name="format"]' ).addEventListener( 'change', exportTypeChanged );
10935 +
10936 + jQuery( 'input[name="frm_export_forms[]"]' ).on( 'click', preventMultipleExport );
10937 + initiateMultiselect();
10938 +
10939 + jQuery( '.frm-feature-banner .dismiss' ).on( 'click', function( event ) {
10940 + event.preventDefault();
10941 + jQuery.post( ajaxurl, {
10942 + action: 'frm_dismiss_migrator',
10943 + plugin: this.id,
10944 + nonce: frmGlobal.nonce
10945 + });
10946 + this.parentElement.remove();
10947 + });
10948 +
10949 + showOrHideRepeaters( getExportOption() );
10950 +
10951 + document.querySelector( '#frm-export-select-all' ).addEventListener( 'change', event => {
10952 + document.querySelectorAll( '[name="frm_export_forms[]"]' ).forEach( cb => cb.checked = event.target.checked );
10953 + });
10954 + },
10955 +
10956 + inboxBannerInit: function() {
10957 + const banner = document.getElementById( 'frm_banner' );
10958 + if ( ! banner ) {
10959 + return;
10960 + }
10961 +
10962 + const dismissButton = banner.querySelector( '.frm-banner-dismiss' );
10963 + document.addEventListener(
10964 + 'click',
10965 + function( event ) {
10966 + if ( event.target !== dismissButton ) {
10967 + return;
10968 + }
10969 +
10970 + const data = {
10971 + action: 'frm_inbox_dismiss',
10972 + key: banner.dataset.key,
10973 + nonce: frmGlobal.nonce
10974 + };
10975 + postAjax(
10976 + data,
10977 + function() {
10978 + jQuery( banner ).fadeOut(
10979 + 400,
10980 + function() {
10981 + banner.remove();
10982 + }
10983 + );
10984 + }
10985 + );
10986 + }
10987 + );
10988 + },
10989 +
10990 + updateOpts: function( fieldId, opts, modal ) {
10991 + const separate = usingSeparateValues( fieldId ),
10992 + action = isProductField( fieldId ) ? 'frm_bulk_products' : 'frm_import_options';
10993 + jQuery.ajax({
10994 + type: 'POST',
10995 + url: ajaxurl,
10996 + data: {
10997 + action: action,
10998 + field_id: fieldId,
10999 + opts: opts,
11000 + separate: separate,
11001 + nonce: frmGlobal.nonce
11002 + },
11003 + success: function( html ) {
11004 + document.getElementById( 'frm_field_' + fieldId + '_opts' ).innerHTML = html;
11005 + wp.hooks.doAction( 'frm_after_bulk_edit_opts', fieldId );
11006 + resetDisplayedOpts( fieldId );
11007 +
11008 + if ( typeof modal !== 'undefined' ) {
11009 + modal.dialog( 'close' );
11010 + document.getElementById( 'frm-update-bulk-opts' ).classList.remove( 'frm_loading_button' );
11011 + }
11012 + }
11013 + });
11014 + },
11015 +
11016 + /* remove conditional logic if the field doesn't exist */
11017 + triggerRemoveLogic: function( fieldID, metaName ) {
11018 + jQuery( '#frm_logic_' + fieldID + '_' + metaName + ' .frm_remove_tag' ).trigger( 'click' );
11019 + },
11020 +
11021 + downloadXML: function( controller, ids, isTemplate ) {
11022 + let url = ajaxurl + '?action=frm_' + controller + '_xml&ids=' + ids;
11023 + if ( isTemplate !== null ) {
11024 + url = url + '&is_template=' + isTemplate;
11025 + }
11026 + location.href = url;
11027 + },
11028 +
11029 + /**
11030 + * @since 5.0.04
11031 + */
11032 + hooks: {
11033 + applyFilters: function( hookName, ...args ) {
11034 + return wp.hooks.applyFilters( hookName, ...args );
11035 + },
11036 + addFilter: function( hookName, callback, priority ) {
11037 + return wp.hooks.addFilter( hookName, 'formidable', callback, priority );
11038 + },
11039 + doAction: function( hookName, ...args ) {
11040 + return wp.hooks.doAction( hookName, ...args );
11041 + },
11042 + addAction: function( hookName, callback, priority ) {
11043 + return wp.hooks.addAction( hookName, 'formidable', callback, priority );
11044 + }
11045 + },
11046 +
11047 + applyZebraStriping,
11048 + initModal,
11049 + infoModal,
11050 + offsetModalY,
11051 + adjustConditionalLogicOptionOrders,
11052 + addRadioCheckboxOpt,
11053 + installNewForm,
11054 + toggleAddonState,
11055 + purifyHtml,
11056 + loadApiEmailForm,
11057 + addMyEmailAddress
11058 + };
11059 +}
11060 +
11061 +window.frmAdminBuild = frmAdminBuildJS();
11062 +
11063 +jQuery( document ).ready(
11064 + () => {
11065 + frmAdminBuild.init();
11066 +
11067 + frmDom.bootstrap.setupBootstrapDropdowns( convertOldBootstrapDropdownsToBootstrap4 );
11068 + document.querySelector( '.preview.dropdown .frm-dropdown-toggle' )?.setAttribute( 'data-toggle', 'dropdown' );
11069 +
11070 + function convertOldBootstrapDropdownsToBootstrap4( frmDropdownMenu ) {
11071 + const toggle = frmDropdownMenu.querySelector( '.frm-dropdown-toggle' );
11072 + if ( toggle ) {
11073 + if ( ! toggle.hasAttribute( 'role' ) ) {
11074 + toggle.setAttribute( 'role', 'button' );
11075 + }
11076 + if ( ! toggle.hasAttribute( 'tabindex' ) ) {
11077 + toggle.setAttribute( 'tabindex', 0 );
11078 + }
11079 + }
11080 +
11081 + // Convert <li> and <ul> tags.
11082 + if ( 'UL' === frmDropdownMenu.tagName ) {
11083 + convertBootstrapUl( frmDropdownMenu );
11084 + }
11085 + }
11086 +
11087 + function convertBootstrapUl( ul ) {
11088 + let html = ul.outerHTML;
11089 + html = html.replace( '<ul ', '<div ' );
11090 + html = html.replace( '</ul>', '</div>' );
11091 + html = html.replaceAll( '<li>', '<div class="dropdown-item">' );
11092 + html = html.replaceAll( '<li class="', '<div class="dropdown-item ' );
11093 + html = html.replaceAll( '</li>', '</div>' );
11094 + ul.outerHTML = html;
11095 + }
11096 + }
11097 +);
11098 +
11099 +function frm_show_div( div, value, showIf, classId ) { // eslint-disable-line camelcase
11100 + if ( value == showIf ) {
11101 + jQuery( classId + div ).fadeIn( 'slow' ).css( 'visibility', 'visible' );
11102 + } else {
11103 + jQuery( classId + div ).fadeOut( 'slow' );
11104 + }
11105 +}
11106 +
11107 +function frmCheckAll( checked, n ) {
11108 + jQuery( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked );
11109 +}
11110 +
11111 +function frmCheckAllLevel( checked, n, level ) {
11112 + const $kids = jQuery( '.frm_catlevel_' + level ).children( '.frm_checkbox' ).children( 'label' );
11113 + $kids.children( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked );
11114 +}
11115 +
11116 +function frmGetFieldValues( fieldId, cur, rowNumber, fieldType, htmlName ) {
11117 +
11118 + if ( fieldId ) {
11119 + jQuery.ajax({
11120 + type: 'POST', url: ajaxurl,
11121 + data: 'action=frm_get_field_values&current_field=' + cur + '&field_id=' + fieldId + '&name=' + htmlName + '&t=' + fieldType + '&form_action=' + jQuery( 'input[name="frm_action"]' ).val() + '&nonce=' + frmGlobal.nonce,
11122 + success: function( msg ) {
11123 + document.getElementById( 'frm_show_selected_values_' + cur + '_' + rowNumber ).innerHTML = msg;
11124 + }
11125 + });
11126 + }
11127 +}
11128 +
11129 +function frmImportCsv( formID ) {
11130 + let urlVars = '';
11131 + if ( typeof __FRMURLVARS !== 'undefined' ) {
11132 + urlVars = __FRMURLVARS;
11133 + }
11134 +
11135 + jQuery.ajax({
11136 + type: 'POST', url: ajaxurl,
11137 + data: 'action=frm_import_csv&nonce=' + frmGlobal.nonce + '&frm_skip_cookie=1' + urlVars,
11138 + success: function( count ) {
11139 + const max = jQuery( '.frm_admin_progress_bar' ).attr( 'aria-valuemax' );
11140 + const imported = max - count;
11141 + const percent = ( imported / max ) * 100;
11142 + jQuery( '.frm_admin_progress_bar' ).css( 'width', percent + '%' ).attr( 'aria-valuenow', imported );
11143 +
11144 + if ( parseInt( count, 10 ) > 0 ) {
11145 + jQuery( '.frm_csv_remaining' ).html( count );
11146 + frmImportCsv( formID );
11147 + } else {
11148 + jQuery( document.getElementById( 'frm_import_message' ) ).html( frm_admin_js.import_complete ); // eslint-disable-line camelcase
11149 + setTimeout( function() {
11150 + location.href = '?page=formidable-entries&frm_action=list&form=' + formID + '&import-message=1';
11151 + }, 2000 );
11152 + }
11153 + }
11154 + });
11155 +}