PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.3
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 +10542 -1 6.35 → 5.5.3 View file →
@@ -1 +1,10542 @@
1 -(()=>{var e={65:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(8793),o=r(1323);function i(e){var t=(0,n.A)(e);return function(e){return(0,o.A)(t,e)}}},1323:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n={"!":function(e){return!e},"*":function(e,t){return e*t},"/":function(e,t){return e/t},"%":function(e,t){return e%t},"+":function(e,t){return e+t},"-":function(e,t){return e-t},"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"==":function(e,t){return e===t},"!=":function(e,t){return e!==t},"&&":function(e,t){return e&&t},"||":function(e,t){return e||t},"?:":function(e,t,r){if(e)throw t;return r}};function o(e,t){var r,o,i,a,l,s,c=[];for(r=0;r<e.length;r++){if(l=e[r],a=n[l]){for(o=a.length,i=Array(o);o--;)i[o]=c.pop();try{s=a.apply(null,i)}catch(e){return e}}else s=t.hasOwnProperty(l)?t[l]:+l;c.push(s)}return c[0]}},1364:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(65);function o(e){var t=(0,n.A)(e);return function(e){return+t({n:e})}}},8793:(e,t,r)=>{"use strict";var n,o,i,a;function l(e){for(var t,r,l,s,c=[],d=[];t=e.match(a);){for(r=t[0],(l=e.substr(0,t.index).trim())&&c.push(l);s=d.pop();){if(i[r]){if(i[r][0]===s){r=i[r][1]||r;break}}else if(o.indexOf(s)>=0||n[s]<n[r]){d.push(s);break}c.push(s)}i[r]||d.push(r),e=e.substr(t.index+r.length)}return(e=e.trim())&&c.push(e),c.concat(d.reverse())}r.d(t,{A:()=>l}),n={"(":9,"!":8,"*":7,"/":7,"%":7,"+":6,"-":6,"<":5,"<=":5,">":5,">=":5,"==":4,"!=":4,"&&":3,"||":2,"?":1,"?:":1},o=["(","?"],i={")":["("],":":["?","?:"]},a=/<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/},7521:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(6956),o=r(7395);const i=function(e,t){return function(r,i,a){var l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10,s=e[t];if((0,o.A)(r)&&(0,n.A)(i))if("function"==typeof a)if("number"==typeof l){var c={callback:a,priority:l,namespace:i};if(s[r]){var d,u=s[r].handlers;for(d=u.length;d>0&&!(l>=u[d-1].priority);d--);d===u.length?u[d]=c:u.splice(d,0,c),s.__current.forEach(function(e){e.name===r&&e.currentIndex>=d&&e.currentIndex++})}else s[r]={handlers:[c],runs:0};"hookAdded"!==r&&e.doAction("hookAdded",r,i,a,l)}else console.error("If specified, the hook priority must be a number.");else console.error("The hook callback must be a function.")}}},11:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){return function(){var r,n,o=e[t];return null!==(r=null===(n=o.__current[o.__current.length-1])||void 0===n?void 0:n.name)&&void 0!==r?r:null}}},5375:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(7395);const o=function(e,t){return function(r){var o=e[t];if((0,n.A)(r))return o[r]&&o[r].runs?o[r].runs:0}}},3561:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){return function(r){var n=e[t];return void 0===r?void 0!==n.__current[0]:!!n.__current[0]&&r===n.__current[0].name}}},8830:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){return function(r,n){var o=e[t];return void 0!==n?r in o&&o[r].handlers.some(function(e){return e.namespace===n}):r in o}}},7765:(e,t,r)=>{"use strict";r.d(t,{A:()=>f});var n=r(3029),o=r(7521),i=r(4194),a=r(8830),l=r(6763),s=r(11),c=r(3561),d=r(5375),u=function e(){(0,n.A)(this,e),this.actions=Object.create(null),this.actions.__current=[],this.filters=Object.create(null),this.filters.__current=[],this.addAction=(0,o.A)(this,"actions"),this.addFilter=(0,o.A)(this,"filters"),this.removeAction=(0,i.A)(this,"actions"),this.removeFilter=(0,i.A)(this,"filters"),this.hasAction=(0,a.A)(this,"actions"),this.hasFilter=(0,a.A)(this,"filters"),this.removeAllActions=(0,i.A)(this,"actions",!0),this.removeAllFilters=(0,i.A)(this,"filters",!0),this.doAction=(0,l.A)(this,"actions"),this.applyFilters=(0,l.A)(this,"filters",!0),this.currentAction=(0,s.A)(this,"actions"),this.currentFilter=(0,s.A)(this,"filters"),this.doingAction=(0,c.A)(this,"actions"),this.doingFilter=(0,c.A)(this,"filters"),this.didAction=(0,d.A)(this,"actions"),this.didFilter=(0,d.A)(this,"filters")};const f=function(){return new u}},4194:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(6956),o=r(7395);const i=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(i,a){var l=e[t];if((0,o.A)(i)&&(r||(0,n.A)(a))){if(!l[i])return 0;var s=0;if(r)s=l[i].handlers.length,l[i]={runs:l[i].runs,handlers:[]};else for(var c=l[i].handlers,d=function(e){c[e].namespace===a&&(c.splice(e,1),s++,l.__current.forEach(function(t){t.name===i&&t.currentIndex>=e&&t.currentIndex--}))},u=c.length-1;u>=0;u--)d(u);return"hookRemoved"!==i&&e.doAction("hookRemoved",i,a),s}}}},6763:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(n){var o=e[t];o[n]||(o[n]={handlers:[],runs:0}),o[n].runs++;for(var i=o[n].handlers,a=arguments.length,l=new Array(a>1?a-1:0),s=1;s<a;s++)l[s-1]=arguments[s];if(!i||!i.length)return r?l[0]:void 0;var c={name:n,currentIndex:0};for(o.__current.push(c);c.currentIndex<i.length;){var d=i[c.currentIndex].callback.apply(null,l);r&&(l[0]=d),c.currentIndex++}return o.__current.pop(),r?l[0]:void 0}}},2133:(e,t,r)=>{"use strict";r.d(t,{se:()=>n});var n=(0,r(7765).A)();n.addAction,n.addFilter,n.removeAction,n.removeFilter,n.hasAction,n.hasFilter,n.removeAllActions,n.removeAllFilters,n.doAction,n.applyFilters,n.currentAction,n.currentFilter,n.doingAction,n.doingFilter,n.didAction,n.didFilter,n.actions,n.filters},7395:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e){return"string"!=typeof e||""===e?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(e)?(console.error("The hook name cannot begin with `__`."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(e)||(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)}},6956:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e){return"string"!=typeof e||""===e?(console.error("The namespace must be a non-empty string."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(e)||(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)}},772:(e,t,r)=>{"use strict";r.d(t,{h:()=>c});var n=r(4467),o=r(5397);function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach(function(t){(0,n.A)(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var l={"":{plural_forms:function(e){return 1===e?0:1}}},s=/^i18n\.(n?gettext|has_translation)(_|$)/,c=function(e,t,r){var n=new o.A({}),i=new Set,c=function(){i.forEach(function(e){return e()})},d=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default";n.data[t]=a(a(a({},l),n.data[t]),e),n.data[t][""]=a(a({},l[""]),n.data[t][""])},u=function(e,t){d(e,t),c()},f=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default",t=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;return n.data[e]||d(void 0,e),n.dcnpgettext(e,t,r,o,i)},m=function(){return arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default"},_=function(e,t,n){var o=f(n,t,e);return r?(o=r.applyFilters("i18n.gettext_with_context",o,e,t,n),r.applyFilters("i18n.gettext_with_context_"+m(n),o,e,t,n)):o};if(e&&u(e,t),r){var p=function(e){s.test(e)&&c()};r.addAction("hookAdded","core/i18n",p),r.addAction("hookRemoved","core/i18n",p)}return{getLocaleData:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default";return n.data[e]},setLocaleData:u,resetLocaleData:function(e,t){n.data={},n.pluralForms={},u(e,t)},subscribe:function(e){return i.add(e),function(){return i.delete(e)}},__:function(e,t){var n=f(t,void 0,e);return r?(n=r.applyFilters("i18n.gettext",n,e,t),r.applyFilters("i18n.gettext_"+m(t),n,e,t)):n},_x:_,_n:function(e,t,n,o){var i=f(o,void 0,e,t,n);return r?(i=r.applyFilters("i18n.ngettext",i,e,t,n,o),r.applyFilters("i18n.ngettext_"+m(o),i,e,t,n,o)):i},_nx:function(e,t,n,o,i){var a=f(i,o,e,t,n);return r?(a=r.applyFilters("i18n.ngettext_with_context",a,e,t,n,o,i),r.applyFilters("i18n.ngettext_with_context_"+m(i),a,e,t,n,o,i)):a},isRTL:function(){return"rtl"===_("ltr","text direction")},hasTranslation:function(e,t,o){var i,a,l=t?t+""+e:e,s=!(null===(i=n.data)||void 0===i||null===(a=i[null!=o?o:"default"])||void 0===a||!a[l]);return r&&(s=r.applyFilters("i18n.has_translation",s,e,t,o),s=r.applyFilters("i18n.has_translation_"+m(o),s,e,t,o)),s}}}},5839:(e,t,r)=>{"use strict";r.d(t,{__:()=>a});var n=r(772),o=r(2133),i=(0,n.h)(void 0,void 0,o.se),a=(i.getLocaleData.bind(i),i.setLocaleData.bind(i),i.resetLocaleData.bind(i),i.subscribe.bind(i),i.__.bind(i));i._x.bind(i),i._n.bind(i),i._nx.bind(i),i.isRTL.bind(i),i.hasTranslation.bind(i)},9575:(e,t,r)=>{"use strict";r.d(t,{__:()=>n.__}),r(181),r(772);var n=r(5839)},181:(e,t,r)=>{"use strict";var n=r(8616),o=r.n(n);r(7604),o()(console.error)},1105:(e,t,r)=>{"use strict";r.r(t),r.d(t,{addonError:()=>f,afterAddonInstall:()=>u,extractErrorFromAddOnResponse:()=>d,toggleAddonState:()=>c});var n=r(9575);function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,l=[],s=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(l.push(n.value),l.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var a=frmDom,l=a.div,s=a.svg;function c(e,t){var r,n=null!==(r=window.ajaxurl)&&void 0!==r?r:frm_js.ajax_url;jQuery(".frm-addon-error").remove();var o=jQuery(e),i=o.attr("rel"),a=o.parent(),l=a.parent().find(".addon-status-label");o.addClass("frm_loading_button"),jQuery.ajax({url:n,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:t,nonce:frmGlobal.nonce,plugin:i},success:function(e){var r,n,i;"string"!=typeof(e=null!==(r=null===(n=e)||void 0===n?void 0:n.data)&&void 0!==r?r:e)&&"string"==typeof e.message&&(void 0!==e.saveAndReload&&(i=e.saveAndReload),e=e.message);var s=d(e);s?f(s,a,o):(u(e,o,l,a,i,t),wp.hooks.doAction("frm_update_addon_state",e))},error:function(){o.removeClass("frm_loading_button")}})}function d(e){return"string"!=typeof e&&!e.success&&(e.form&&jQuery(e.form).is("#message")?{message:jQuery(e.form).find("p").html()}:e)}function u(e,t,r,i,a){var c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"frm_activate_addon",d=frm_admin_js,u=document.querySelectorAll(".frm-addon-status");u.forEach(function(t){t.textContent=e,t.style.display="block"}),t.css({opacity:"0"}),document.querySelectorAll(".frm-oneclick").forEach(function(e){e.style.display="none"}),function(){var e=document.getElementById("frm_upgrade_modal");if(e){e.classList.add("frm-success");var t=e.querySelector(".frm-upgrade-message");if(t){var r=t.querySelector("img");t.replaceChildren((0,n.__)("Great! Everything's ready to go!","formidable"),document.createElement("br"),(0,n.__)("You just need to refresh the builder so the new field becomes available.","formidable")),r&&t.append(r)}var o=document.querySelector(".frm-addon-status");o&&(o.textContent="");var i,a=e.querySelector(".frm-circled-icon");if(a)a.classList.add("frm-circled-icon-green"),null===(i=a.querySelector("svg"))||void 0===i||i.replaceWith(s({href:"#frm_checkmark_icon"}))}}();var f={frm_activate_addon:{class:"frm-addon-active",message:d.active},frm_deactivate_addon:{class:"frm-addon-installed",message:d.installed},frm_uninstall_addon:{class:"frm-addon-not-installed",message:d.not_installed}};f.frm_install_addon=f.frm_activate_addon;var _=o(r,1)[0];_&&(_.textContent=f[c].message);var p=o(i,1)[0].parentElement;p.classList.remove("frm-addon-not-installed","frm-addon-installed","frm-addon-active"),p.classList.add(f[c].class),o(t,1)[0].classList.remove("frm_loading_button"),document.querySelectorAll(".frm-admin-page-import, #frm-admin-smtp, #frm-welcome").length>0?window.location.reload():["settings","form_builder"].includes(a)&&u.forEach(function(e){var t=null!==e.closest("#frm_upgrade_modal");e.append(function(e,t){var r,o=[m(e)];return t&&o.push(((r=document.createElement("a")).setAttribute("href","#"),r.classList.add("button","button-secondary","frm-button-secondary","dismiss"),r.textContent=(0,n.__)("Not Now","formidable"),r)),l({className:"frm-save-and-reload-options",children:o})}(a,t))})}function f(e,t,r){e.form?(jQuery(".frm-inline-error").remove(),r.closest(".frm-card").html(e.form).css({padding:5}).find("#upgrade").attr("rel",r.attr("rel")).on("click",_)):(t.append('<div class="frm-addon-error frm_error_style"><p><strong>'.concat(e.message,"</strong></p></div>")),r.removeClass("frm_loading_button"),jQuery(".frm-addon-error").delay(4e3).fadeOut())}function m(e){var t=document.createElement("button");return t.classList.add("frm-save-and-reload","button","button-primary","frm-button-primary"),t.textContent=(0,n.__)("Save and Reload","formidable"),t.addEventListener("click",function(){var t;"form_builder"===e?((t=document.getElementById("frm_submit_side_top")).classList.contains("frm_submit_ajax")&&t.setAttribute("data-new-addon-installed",!0),t.click()):"settings"===e&&function(){var e=document.getElementById("form_settings_page");if(e){var t=e.querySelector("form.frm_form_settings");null!==t&&(wp.hooks.doAction("frm_reset_fields_updated"),t.submit())}}()}),t}function _(e){e.preventDefault();var t=jQuery(this),r=t.parent().parent(),n=t.attr("rel");t.addClass("frm_loading_button"),jQuery.ajax({url:ajaxurl,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:"frm_install_addon",nonce:frmAdminJs.nonce,plugin:n,hostname:r.find("#hostname").val(),username:r.find("#username").val(),password:r.find("#password").val()},success:function(e){var n,o,i=d(e=null!==(n=null===(o=e)||void 0===o?void 0:o.data)&&void 0!==n?n:e);i?f(i,r,t):u(e,t,message,r)},error:function(){t.removeClass("frm_loading_button")}})}},4365:()=>{!function(){function e(e){var t=e.querySelector(".frm-gc-item-type"),r=t.value,n=t.name.replace(/\[type\]$/,"");e.querySelectorAll(".frm-gc-type-settings").forEach(function(e){var t=e.dataset.type===r;e.toggleAttribute("hidden",!t),e.querySelectorAll("[data-frm-gc-field]").forEach(function(e){var r=e.dataset.frmGcField;t?e.name="".concat(n,"[").concat(r,"]"):e.removeAttribute("name")})})}function t(t){var r,n=t.querySelector(".frm_gc_add_item"),o=null!==(r=null==n?void 0:n.dataset.fieldNameBase)&&void 0!==r?r:"",i=t.querySelectorAll(".frm_gc_item_row");i.forEach(function(r,n){var i=r.querySelector(".frm-gc-item-type");i&&o&&(i.name="".concat(o,"[").concat(n,"][type]")),function(e,t,r){var n=e.querySelector('[data-frm-gc-field="type"]');if(n){n.id="".concat(t,"_type_").concat(r);var o=e.querySelector('[data-frm-gc-for="type"]');o&&(o.htmlFor=n.id)}e.querySelectorAll(".frm-gc-type-settings").forEach(function(e){var n=e.dataset.type;e.querySelectorAll("[data-frm-gc-field]").forEach(function(o){var i=o.dataset.frmGcField;o.id="".concat(t,"_").concat(i,"_").concat(n,"_").concat(r);var a=e.querySelector('[data-frm-gc-for="'.concat(i,'"]'));a&&(a.htmlFor=o.id)})})}(r,t.id,n),e(r)}),t.dataset.itemCount=i.length}function r(e){var t=e.getAttribute("aria-label");e.classList.add("is-copied"),e.setAttribute("aria-label",e.dataset.copiedLabel||"Copied!"),setTimeout(function(){e.classList.remove("is-copied"),e.setAttribute("aria-label",t)},1600)}document.addEventListener("click",function(e){var n=e.target.closest(".frm_gc_add_item");if(n){var o=n.closest(".frm_gated_content_settings"),i=o.querySelector(".frm_gc_items_list"),a=o.querySelector(".frm_gc_item_template");return i.append(a.content.cloneNode(!0)),t(o),void frmDom.autocomplete.initSelectionAutocomplete(i.lastElementChild)}var l=e.target.closest(".frm_gc_remove_item");if(l){var s=l.closest(".frm_gated_content_settings");return l.closest(".frm_gc_item_row").remove(),void t(s)}var c=e.target.closest(".frm_gc_copy_shortcode");if(c){var d,u=c.dataset.frmCopy;if(null!==(d=navigator.clipboard)&&void 0!==d&&d.writeText)navigator.clipboard.writeText(u).then(function(){return r(c)});else{var f=document.createElement("textarea");f.value=u,f.style.cssText="position:fixed;opacity:0;",document.body.append(f),f.select(),document.execCommand("copy"),f.remove(),r(c)}}}),document.addEventListener("change",function(t){var r=t.target.closest(".frm-gc-item-type");if(r)e(r.closest(".frm_gc_item_row"));else{var n=t.target.closest(".frm-gc-file-form-select");n&&function(e){var t=e.closest(".frm-gc-type-settings"),r=null==t?void 0:t.querySelector('[data-frm-gc-field="id"]');if(r){var n=e.value;Array.from(r.options).forEach(function(e){var t=e.dataset.formId;e.style.display=t?n&&t===n?"":"none":""});var o=r.options[r.selectedIndex];"none"===(null==o?void 0:o.style.display)&&(r.value="")}}(n)}}),jQuery(document).on("frm-multiselect-changed",'select[id^="event_"]',function(){var e=document.querySelector('.frm_gc_update_section[data-frm-gc-event-id="'.concat(this.id,'"]'));if(e){var t=Array.from(this.options).some(function(e){return e.selected&&"update"===e.value});e.hidden=!t}})}()},8095:(e,t,r)=>{"use strict";function n(e,t){var r=t();return r?(frmAdminBuild.infoModal(r),e.classList.add("frm_invalid_field"),function(e){var t=document.querySelectorAll("#frm_info_modal .dismiss, #frm_info_modal #frm-info-click, .ui-widget-overlay.ui-front");function r(){setTimeout(function(){return e.focus()},0),t.forEach(function(e){return e.removeEventListener("click",r)})}t.forEach(function(e){return e.addEventListener("click",r)})}(e)):e.classList.remove("frm_invalid_field"),r}r.r(t),r.d(t,{validateField:()=>n})},4746:(e,t,r)=>{"use strict";r.r(t),r.d(t,{getRangeSettingsDefaults:()=>l,validateNumberRangeSetting:()=>s,validateRangeSettings:()=>d,validateStepSetting:()=>c});var n=r(9575),o=r(8095),i=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return t?t.dataset.fid:null==r||null===(e=r.closest(".frm-single-settings"))||void 0===e?void 0:e.dataset.fid},a=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return t||(t=null==r?void 0:r.closest(".frm-single-settings")),null===(e=t)||void 0===e||null===(e=e.className.match(/frm-type-(\w+)/))||void 0===e?void 0:e[1]};function l(e){var t=a(e)||"number";return wp.hooks.applyFilters("frm_range_settings_defaults",{maxNum:9999999,minNum:0,step:1},{singleSettings:e,fieldType:t})}function s(e){if(e.closest(".frm-number-range")){var t=e.closest(".frm-single-settings"),r=i(t);if(r){var a=document.querySelector('[name="field_options[minnum_'.concat(r,']"]'));if(a){var s=document.querySelector('[name="field_options[maxnum_'.concat(r,']"]'));if(s)return(0,o.validateField)(e,function(){var e=l(t),r=e.minNum,o=e.maxNum;return parseFloat(a.value||r)>=parseFloat(s.value||o)?(0,n.__)("Minimum value cannot be greater than or equal to maximum value.","formidable"):""})}}}}function c(e){if(e.closest(".frm-step")){var t=e.closest(".frm-single-settings"),r=i(t);if(r){var a=document.querySelector('[name="field_options[step_'.concat(r,']"]'));if(a)return(0,o.validateField)(e,function(){var e=l(t),o=e.step,i=e.minNum,s=e.maxNum,c=parseFloat(a.value||o);if(c<=0)return(0,n.__)("Step value must be greater than 0.","formidable");var d=document.querySelector('[name="field_options[maxnum_'.concat(r,']"]'));if(!d)return"";var u=document.querySelector('[name="field_options[minnum_'.concat(r,']"]')),f=parseFloat((null==u?void 0:u.value)||i);return c>parseFloat(d.value||s)-f?(0,n.__)("Step value cannot be greater than the difference between the minimum and maximum values.","formidable"):""})}}}function d(e){var t=s(e);return t||(t=c(e)),wp.hooks.applyFilters("frm_validate_range_settings",t||"",{field:e})}},4260:(e,t,r)=>{"use strict";r.r(t),r.d(t,{addOneClick:()=>i,initModal:()=>a,initUpgradeModal:()=>l});var n=r(9575),o=frmDom.svg;function i(e,t,r){var i;if("modal"===t)i=document.getElementById("frm_upgrade_modal");else{if("tab"!==t)return;i=document.getElementById(e.getAttribute("href").substr(1))}var a,l=i.querySelector(".frm-oneclick"),s=i.querySelector(".frm-upgrade-message"),c=i.querySelector(".frm-upgrade-link"),d=i.querySelector(".frm-oneclick-button"),u=i.querySelector(".frm-addon-status"),f=e.getAttribute("data-oneclick"),m=e.getAttribute("data-message"),_="block",p="block",g="none",v=i.querySelector(".frm-circled-icon");v&&(v.classList.remove("frm-circled-icon-green"),null===(a=v.querySelector("svg"))||void 0===a||a.replaceWith(o({href:"#frm_filled_lock_icon"})));var y=i.querySelector(".frm-learn-more");if(y&&(e.dataset.learnMore?(y.href=e.dataset.learnMore,y.style.display=""):y.style.display="none"),null!==l&&null!==d&&void 0!==f&&f){null===m&&(p="none"),_="none",g="block",f=JSON.parse(f),d.className=d.className.replace(" frm-install-addon","").replace(" frm-activate-addon",""),d.className="".concat(d.className," ").concat(f.class),d.rel=f.url,l.textContent=(0,n.__)("This plugin is not activated. Would you like to activate it now?","formidable"),d.textContent=(0,n.__)("Activate","formidable");var h=e.querySelector("use");h&&(null==v||v.querySelector("svg").replaceWith(o({href:h.getAttribute("href")||h.getAttribute("xlink:href"),classList:["frm_svg32"]})))}m||(m=s.getAttribute("data-default")),void 0!==r&&(m=m.replace('<span class="frm_feature_label"></span>',r)),s.innerHTML=m,e.dataset.upsellImage&&s.append(frmDom.img({src:e.dataset.upsellImage,alt:e.dataset.upgrade})),c.href=function(e,t){var r=e.getAttribute("data-link");return null!=r&&""!==r||(r=t.getAttribute("data-default")),r}(e,c),u.style.display="none",l&&(l.style.display=g),d&&(d.style.display="block"===g?"inline-block":g),s.style.display=p,c.style.display="block"===_?"inline-block":_;var b=c.closest(".frm-upgrade-modal-actions");b&&(b.style.display="block"===_?"flex":_)}function a(e,t){var r=jQuery(e);if(!r.length)return!1;void 0===t&&(t="552px");var n={dialogClass:"frm-dialog",modal:!0,autoOpen:!1,closeOnEscape:!0,width:t,resizable:!1,draggable:!1,open:function(){var e,t;jQuery(".ui-dialog-titlebar").addClass("frm_hidden").removeClass("ui-helper-clearfix"),jQuery("#wpwrap").addClass("frm_overlay"),jQuery(".frm-dialog").removeClass("ui-widget ui-widget-content ui-corner-all"),r.removeClass("ui-dialog-content ui-widget-content"),e=r,t=function(){e.dialog("close")},jQuery(".ui-widget-overlay").on("click",t),e.on("click","a.dismiss",t)},close:function(){jQuery("#wpwrap").removeClass("frm_overlay"),jQuery(".spinner").css("visibility","hidden"),this.removeAttribute("data-option-type");var e=document.getElementById("bulk-option-type");e&&(e.value="")}};return r.dialog(n),r}function l(){var e=a("#frm_upgrade_modal");function t(t){var r,o,a;if((r=t.target).classList){var l=r.classList.contains("frm_show_expired_modal")||null!==r.querySelector(".frm_show_expired_modal")||r.closest(".frm_show_expired_modal");if("change"===t.type&&r.classList.contains("frm_select_with_upgrade")){var s,c=r.options[r.selectedIndex];null!=c&&null!==(s=c.dataset)&&void 0!==s&&s.upgrade&&(r=c)}if(!r.dataset.upgrade){var d=r.closest("[data-upgrade]");if(!d){if(!(d=r.closest(".frm_field_box")))return;r.dataset.upgrade=""}r=d}if(l)wp.hooks.doAction("frm_show_expired_modal",r);else{var u=r.dataset.upgrade;if(u&&!r.classList.contains("frm_show_upgrade_tab")){t.preventDefault();var f=e.get(0);f.classList.remove("frm-success");var m=f.querySelector(".frm_lock_icon");m&&(m.style.display="block",m.classList.remove("frm_lock_open_icon"),m.querySelector("use").setAttribute("href","#frm_lock_icon"));var _="frm_upgrade_modal_image",p=document.getElementById(_);p&&p.remove(),r.dataset.image&&m&&(m.style.display="none",m.parentNode.insertBefore(frmDom.img({id:_,src:"".concat(frmGlobal.url,"/images/").concat(r.dataset.image)}),m));var g=f.querySelector(".license-level");g&&(g.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(r)),i(r,"modal",u);var v=f.querySelector(".frm_are_not_installed");v.style.display=r.dataset.image||r.dataset.oneclick?"none":"inline-block",v.textContent=v.dataset.default,f.querySelector(".frm-upgrade-modal-title-prefix").style.display=r.dataset.oneclick?"inline":"none",f.querySelector(".frm_feature_label").textContent=u,f.querySelector(".frm-upgrade-modal-title-suffix").style.display="none",f.querySelector("h2").style.display="block",e.dialog("open");var y=f.querySelector(".button-primary:not(.frm-oneclick-button)");o=y.getAttribute("href").replace(/(medium=)[a-z_-]+/gi,"$1".concat(r.getAttribute("data-medium"))),null===(a=r.getAttribute("data-content"))&&(a=""),o=o.replace(/(content=)[a-z_-]+/gi,"$1".concat(a)),y.setAttribute("href",o),r.classList.contains("frm_show_update")&&function(e){var t=e.querySelector(".frm-upgrade-modal-title-prefix");t&&(t.style.display="none");var r=e.querySelector(".frm_are_not_installed");r&&(r.textContent=(0,n.__)("require an update","formidable"),r.style.display="");var o=e.querySelector(".frm-oneclick");o&&(o.style.display="none");var i=e.querySelector(".frm-oneclick-button");i&&(i.textContent=(0,n.__)("Update Now","formidable"))}(f)}}}}!1!==e&&(document.addEventListener("click",t),frmDom.util.documentOn("change","select.frm_select_with_upgrade",t))}},8616:e=>{e.exports=function(e,t){var r,n,o=0;function i(){var i,a,l=r,s=arguments.length;e:for(;l;){if(l.args.length===arguments.length){for(a=0;a<s;a++)if(l.args[a]!==arguments[a]){l=l.next;continue e}return l!==r&&(l===n&&(n=l.prev),l.prev.next=l.next,l.next&&(l.next.prev=l.prev),l.next=r,l.prev=null,r.prev=l,r=l),l.val}l=l.next}for(i=new Array(s),a=0;a<s;a++)i[a]=arguments[a];return l={args:i,val:e.apply(null,i)},r?(r.prev=l,l.next=r):n=l,o===t.maxSize?(n=n.prev).next=null:o++,r=l,l.val}return t=t||{},i.clear=function(){r=null,n=null,o=0},i}},7604:(e,t,r)=>{var n;!function(){"use strict";var o={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function i(e){return function(e,t){var r,n,a,l,s,c,d,u,f,m=1,_=e.length,p="";for(n=0;n<_;n++)if("string"==typeof e[n])p+=e[n];else if("object"==typeof e[n]){if((l=e[n]).keys)for(r=t[m],a=0;a<l.keys.length;a++){if(null==r)throw new Error(i('[sprintf] Cannot access property "%s" of undefined value "%s"',l.keys[a],l.keys[a-1]));r=r[l.keys[a]]}else r=l.param_no?t[l.param_no]:t[m++];if(o.not_type.test(l.type)&&o.not_primitive.test(l.type)&&r instanceof Function&&(r=r()),o.numeric_arg.test(l.type)&&"number"!=typeof r&&isNaN(r))throw new TypeError(i("[sprintf] expecting number but found %T",r));switch(o.number.test(l.type)&&(u=r>=0),l.type){case"b":r=parseInt(r,10).toString(2);break;case"c":r=String.fromCharCode(parseInt(r,10));break;case"d":case"i":r=parseInt(r,10);break;case"j":r=JSON.stringify(r,null,l.width?parseInt(l.width):0);break;case"e":r=l.precision?parseFloat(r).toExponential(l.precision):parseFloat(r).toExponential();break;case"f":r=l.precision?parseFloat(r).toFixed(l.precision):parseFloat(r);break;case"g":r=l.precision?String(Number(r.toPrecision(l.precision))):parseFloat(r);break;case"o":r=(parseInt(r,10)>>>0).toString(8);break;case"s":r=String(r),r=l.precision?r.substring(0,l.precision):r;break;case"t":r=String(!!r),r=l.precision?r.substring(0,l.precision):r;break;case"T":r=Object.prototype.toString.call(r).slice(8,-1).toLowerCase(),r=l.precision?r.substring(0,l.precision):r;break;case"u":r=parseInt(r,10)>>>0;break;case"v":r=r.valueOf(),r=l.precision?r.substring(0,l.precision):r;break;case"x":r=(parseInt(r,10)>>>0).toString(16);break;case"X":r=(parseInt(r,10)>>>0).toString(16).toUpperCase()}o.json.test(l.type)?p+=r:(!o.number.test(l.type)||u&&!l.sign?f="":(f=u?"+":"-",r=r.toString().replace(o.sign,"")),c=l.pad_char?"0"===l.pad_char?"0":l.pad_char.charAt(1):" ",d=l.width-(f+r).length,s=l.width&&d>0?c.repeat(d):"",p+=l.align?f+r+s:"0"===c?f+s+r:s+f+r)}return p}(function(e){if(l[e])return l[e];for(var t,r=e,n=[],i=0;r;){if(null!==(t=o.text.exec(r)))n.push(t[0]);else if(null!==(t=o.modulo.exec(r)))n.push("%");else{if(null===(t=o.placeholder.exec(r)))throw new SyntaxError("[sprintf] unexpected placeholder");if(t[2]){i|=1;var a=[],s=t[2],c=[];if(null===(c=o.key.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(a.push(c[1]);""!==(s=s.substring(c[0].length));)if(null!==(c=o.key_access.exec(s)))a.push(c[1]);else{if(null===(c=o.index_access.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");a.push(c[1])}t[2]=a}else i|=2;if(3===i)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");n.push({placeholder:t[0],param_no:t[1],keys:t[2],sign:t[3],pad_char:t[4],align:t[5],width:t[6],precision:t[7],type:t[8]})}r=r.substring(t[0].length)}return l[e]=n}(e),arguments)}function a(e,t){return i.apply(null,[e].concat(t||[]))}var l=Object.create(null);"undefined"!=typeof window&&(window.sprintf=i,window.vsprintf=a,void 0===(n=function(){return{sprintf:i,vsprintf:a}}.call(t,r,t,e))||(e.exports=n))}()},5397:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(1364),o={contextDelimiter:"",onMissingKey:null};function i(e,t){var r;for(r in this.data=e,this.pluralForms={},this.options={},o)this.options[r]=void 0!==t&&r in t?t[r]:o[r]}i.prototype.getPluralForm=function(e,t){var r,o,i,a=this.pluralForms[e];return a||("function"!=typeof(i=(r=this.data[e][""])["Plural-Forms"]||r["plural-forms"]||r.plural_forms)&&(o=function(e){var t,r,n;for(t=e.split(";"),r=0;r<t.length;r++)if(0===(n=t[r].trim()).indexOf("plural="))return n.substr(7)}(r["Plural-Forms"]||r["plural-forms"]||r.plural_forms),i=(0,n.A)(o)),a=this.pluralForms[e]=i),a(t)},i.prototype.dcnpgettext=function(e,t,r,n,o){var i,a,l;return i=void 0===o?0:this.getPluralForm(e,o),a=r,t&&(a=t+this.options.contextDelimiter+r),(l=this.data[e][a])&&l[i]?l[i]:(this.options.onMissingKey&&this.options.onMissingKey(r,e),0===i?r:n)}},3029:(e,t,r)=>{"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}r.d(t,{A:()=>n})},4467:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(9922);function o(e,t,r){return(t=(0,n.A)(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}},2327:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(2284);function o(e,t){if("object"!=(0,n.A)(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!=(0,n.A)(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}},9922:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(2284),o=r(2327);function i(e){var t=(0,o.A)(e,"string");return"symbol"==(0,n.A)(t)?t:t+""}},2284:(e,t,r)=>{"use strict";function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}r.d(t,{A:()=>n})}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}function n(e){return function(e){if(Array.isArray(e))return d(e)}(e)||o(e)||c(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function i(e){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i(e)}function a(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e){if(Array.isArray(e))return e}function s(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=c(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,l=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){l=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(l)throw i}}}}function c(e,t){if(e){if("string"==typeof e)return d(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var u=r(8095).validateField,f=r(4746),m=f.getRangeSettingsDefaults,_=f.validateNumberRangeSetting,p=f.validateStepSetting,g=f.validateRangeSettings;window.FrmFormsConnect=window.FrmFormsConnect||function(e,t,r){var n={messageBox:null,reset:null,setElements:function(){n.messageBox=e.querySelector(".frm_pro_license_msg"),n.reset=e.getElementById("frm_reconnect_link")}},o={init:function(){n.setElements(),r(e.getElementById("frm_deauthorize_link")).on("click",o.deauthorize),r(".frm_authorize_link").on("click",o.authorize),r(".frm-dashboard-license-options").on("click","#frm_deauthorize_link",o.deauthorize),r(".frm-dashboard-license-options").on("click","#frm_reconnect_link",o.reauthorize),null!==n.reset&&r(n.reset).on("click",o.reauthorize)},authorize:function(){var t=this,n=this.getAttribute("data-plugin"),i=e.getElementById("edd_".concat(n,"_license_key")),a=i.value,l=e.getElementById("proplug-wpmu");this.classList.add("frm_loading_button"),l=l&&l.checked?1:0,r.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_activate",license:a,plugin:n,wpmu:l,nonce:frmGlobal.nonce},success:function(e){o.afterAuthorize(e,i),t.classList.remove("frm_loading_button")}})},afterAuthorize:function(e,t){!0===e.success&&(t.value="•••••••••••••••••••"),wp.hooks.doAction("frm_after_authorize",e),o.showMessage(e)},showProgress:function(e){null===n.messageBox&&n.setElements();var t=n.messageBox;null!==t&&(!0===e.success?(t.classList.remove("frm_error_style"),t.classList.add("frm_message","frm_updated_message")):(t.classList.add("frm_error_style"),t.classList.remove("frm_message","frm_updated_message")),t.classList.remove("frm_hidden"),t.innerHTML=e.message)},showMessage:function(r){null===n.messageBox&&n.setElements();var i=n.messageBox;!0===r.success&&(o.showAuthorized(!0),o.showInlineSuccess(),wp.hooks.doAction("frmAdmin.afterLicenseAuthorizeSuccess",{msg:r})),o.showProgress(r),""!==r.message&&(setTimeout(function(){i.innerHTML="",i.classList.add("frm_hidden"),i.classList.remove("frm_error_style","frm_message","frm_updated_message")},1e4),e.querySelector(".frm-admin-page-dashboard")&&setTimeout(function(){t.location.reload()},1e3))},showAuthorized:function(t){var r=t?"unauthorized":"authorized",n=t?"authorized":"unauthorized",o=e.querySelectorAll(".frm_".concat(r,"_box"));o.length&&o.forEach(function(e){e.className=e.className.replace("frm_".concat(r,"_box"),"frm_".concat(n,"_box"))})},showInlineSuccess:function(){var t=e.querySelectorAll(".frm-confirm-msg [data-success]");t.length&&t.forEach(function(e){e.innerHTML=frmAdminBuild.purifyHtml(e.getAttribute("data-success"))})},reauthorize:function(){return this.innerHTML='<span class="frm-wait frm_spinner" style="visibility:visible;float:none"></span>',r.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_reset_cache",plugin:"formidable_pro",nonce:frmGlobal.nonce},success:function(e){n.reset.textContent=e.message,"1"===n.reset.getAttribute("data-refresh")&&t.location.reload()}}),!1},deauthorize:function(){if(!confirm(frmGlobal.deauthorize))return!1;var t=this.getAttribute("data-plugin"),n=e.getElementById("edd_".concat(t,"_license_key")),i=n.value,a=this;return this.innerHTML='<span class="frm-wait frm_spinner" style="visibility:visible;"></span>',r.ajax({type:"POST",url:ajaxurl,data:{action:"frm_addon_deactivate",license:i,plugin:t,nonce:frmGlobal.nonce},success:function(){o.showAuthorized(!1),n.value="",a.replaceWith("Disconnected"),wp.hooks.doAction("frmAdmin.afterLicenseDeauthorizeSuccess",{})}}),!1}};return o}(document,window,jQuery),window.frmAdminBuildJS=function(){var e,t,f=frm_admin_js,v=frmDom,y=v.tag,h=v.div,b=v.span,w=v.a,j=v.svg,x=v.img,E=frmDom.util.onClickPreventDefault,k=frmDom.ajax.doJsonPost;f.contextualShortcodes=(t=null===(e=document.getElementById("frm_adv_info"))||void 0===e?void 0:e.dataset.contextualShortcodes)?((t=JSON.parse(t)).addressSelector="[id^=email_to], [id^=from_], [id^=cc], [id^=bcc]",t.bodySelector="[id^=email_message_]",t):[];var Q,S,A,L={save:j({href:"#frm_save_icon"}),drag:j({href:"#frm_drag_icon",classList:["frm_drag_icon","frm-drag"]})},I=jQuery(document.getElementById("frm-show-fields")),q=document.getElementById("new_fields"),B=document.getElementById("form_id"),C=!1,N=0,T=0,O=0,F={},D=0,M=wp.i18n,P=M.__,R=M.sprintf,z={dragging:!1,draggable:null,offsetsRefreshed:!1,submitButtonRow:null};B&&(T=B.value);var H,G=new URL(window.location.href),U=G.searchParams,W=document.getElementById("frm_builder_page");function $(e){e.stopPropagation(),e.preventDefault(),V(this)}function V(e){var t=e.getAttribute("data-frmverify"),r=e.getAttribute("data-loaded-from");return null===t||"frm-confirmed-click"===e.id||("entries-list"===r?wp.hooks.applyFilters("frm_on_multiple_entries_delete",{link:e,initModal:ea}):function(e){var t=ea("#frm_confirm_modal","400px"),r=document.getElementById("frm-confirmed-click");if(!1===t)return!1;r&&(r.style.display="block");var n=e.getAttribute("data-frmverify"),o=n?e.getAttribute("data-frmverify-btn"):"",i=jQuery(".frm-confirm-msg");i.empty(),n&&(i.append(document.createTextNode(n)),o&&(null==r||r.classList.add(o)));var a=e.dataset;if(r){for(var l in r.dataset)r.removeAttribute("data-".concat(l));for(var s in a)"frmverify"!==s&&r.setAttribute("data-".concat(s),a[s])}return wp.hooks.doAction("frmAdmin.beforeOpenConfirmModal",{$info:t,link:e}),t.dialog("open"),null==r||r.setAttribute("href",e.getAttribute("href")||e.getAttribute("data-href")),!1}(e))}function K(e,t){var r=ea("#frm_info_modal",t||"400px");if(!1===r)return!1;"string"==typeof e&&(e={msg:e}),e=Object.assign({title:"",msg:P("Are you sure?","formidable"),img:"",closeText:P("Got it!","formidable"),actionUrl:"",actionText:"",noCenter:!1},e);var n=r[0].querySelector(".info-modal-title");n.textContent=e.title||"",n.classList.toggle("frm_hidden",!e.title),e.msg&&(r[0].querySelector(".frm-info-msg").innerHTML=Tn(e.msg)),r[0].querySelector(".info-modal-img").src=e.img,r[0].querySelector(".info-modal-img-wrapper").classList.toggle("frm_hidden",!e.img);var o=document.getElementById("frm-info-click");e.closeText&&(o.textContent=e.closeText),o.classList.toggle("button-primary",!e.actionUrl),o.classList.toggle("frm-button-primary",!e.actionUrl),o.classList.toggle("button-secondary",Boolean(e.actionUrl)),o.classList.toggle("frm-button-secondary",Boolean(e.actionUrl));var i=r[0].querySelector(".info-modal-action-link");return e.actionUrl&&(i.href=e.actionUrl,e.actionText&&(i.textContent=e.actionText)),i.classList.toggle("frm_hidden",!e.actionUrl),r[0].querySelector(".info-modal-inside").classList.toggle("frmcenter",!e.noCenter),r[0].querySelector(".info-modal-buttons").classList.toggle("frmright",e.noCenter),r.dialog("open"),!1}function J(e){var t=this.getAttribute("data-frmtoggle"),r=this.getAttribute("data-toggletext"),n=jQuery(t);return e.preventDefault(),n.toggle(),null!==r&&""!==r&&(this.setAttribute("data-toggletext",this.innerHTML),this.textContent=r),!1}function X(e){var t=this.getAttribute("data-frmhide"),r=this.getAttribute("data-frmshow"),n=this.getAttribute("data-frmuncheck"),o=n?n.split(","):[];"INPUT"!==this.nodeName||"checkbox"!==this.type||this.checked||(null!==t?(r=t,t=null):null!==r&&(t=r,r=null)),e.preventDefault();var i=this.getAttribute("data-toggleclass")||"frm_hidden";null!==t&&jQuery(t).addClass(i),null!==r&&jQuery(r).removeClass(i);var a=this.parentNode.querySelectorAll("a.current");if(null!==a){for(var l=0;l<a.length;l++)a[l].classList.remove("current");this.classList.add("current")}return o.length&&o.forEach(function(e){var t=document.querySelector(e);t&&(t.checked=!1)}),!1}function Y(){document.querySelectorAll(".tooltip").forEach(function(e){e.remove()})}function Z(){var e,t,r;if(!parseInt(this.getAttribute("data-skip-frm-js"))&&!1!==V(this)){var n=jQuery(this),o=n.attr("data-removeid");void 0===(e=n.attr("data-showlast"))&&(e=""),void 0===(t=n.attr("data-hidelast"))&&(t=""),r=n.attr("data-removemore"),""!==e?n.closest(".frm_add_remove").find(".frm_remove_tag:visible").length>1&&(e="",t=""):0===o.indexOf("frm_postmeta_")&&(jQuery("#frm_postmeta_rows .frm_postmeta_row").length<2&&(e=".frm_add_postmeta_row.button"),jQuery(".frm_toggle_cf_opts").length&&jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().length&&(""!==e&&(e+=","),e+="#".concat(jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().attr("id")," .frm_toggle_cf_opts")));var i=document.getElementById(o),a=jQuery(i);return a.fadeOut(300,function(){var r;a.remove(),ci(),""!==t&&(jQuery(t).hide(),function(e){var t=document.querySelector(e);if(t){var r,n=s(t.classList);try{for(n.s();!(r=n.n()).done;){var o=r.value,i=document.querySelector('input[data-toggleclass="'.concat(o,'"]'));if(null!=i&&i.checked)return void(i.checked=!1)}}catch(e){n.e(e)}finally{n.f()}}}(t)),""!==e&&jQuery("".concat(e," a,").concat(e)).removeClass("frm_hidden").fadeIn("slow"),this.closest(".frm_form_action_settings")&&function(e){var t;Io(e),"payment"===e&&["stripe","square","paypal"].forEach(function(e){return Io(e)}),document.querySelector(".frm_form_action_settings")||null===(t=document.querySelector(".frm-no-actions-message"))||void 0===t||t.classList.remove("frm_hidden");var r={type:e};wp.hooks.doAction("frm_after_action_removed",r)}(this.closest(".frm_form_action_settings").querySelector(".frm_action_name").value),null===(r=document.querySelector(".tooltip"))||void 0===r||r.remove()}),void 0!==r&&(r=jQuery(r)).fadeOut(400,function(){r.remove()}),""!==e&&jQuery(this).closest(".frm_logic_rows").fadeOut("slow"),wp.hooks.doAction("frm_admin_tag_removed",o,i),!1}}function ee(){var e,t=document.querySelector("#frm-actions-filter-content .frm-action:not(.frm_hidden)");null===(e=document.getElementById("frm-actions-no-results"))||void 0===e||e.classList.toggle("frm_hidden",t)}function te(e,t){void 0===t&&(t=this),yt(t,!1);var r=jQuery(t).closest(".frm_form_action_settings"),n=e.target;if(r.length&&void 0!==n){var o=n.parentElement.className;if("string"==typeof o&&(o.includes("frm_email_icons")||o.includes("frm_toggle")))return void e.stopPropagation()}var i=r.children(".widget-inside");if(r.length&&i.find("p, div, table").length<1){var a=r.find('input[name$="[ID]"]').val(),l=r.find('input[name$="[post_excerpt]"]').val();l&&(i.html('<span class="frm-wait frm_spinner"></span>'),r.find(".spinner").fadeIn("slow"),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_form_action_fill",action_id:a,action_type:l,nonce:frmGlobal.nonce},success:function(e){i.html(e),Bi(),ho("#".concat(r.attr("id"))),Pi(i),jQuery(t).trigger("frm-action-loaded"),wp.hooks.doAction("frm_filled_form_action",i)}}))}jQuery(t).closest(".frm_field_box").siblings().find(".widget-inside").slideUp("fast"),void 0!==t.className&&t.className.includes("widget-action")||jQuery(t).closest(".start_divider").length<1||((i=jQuery(t).closest("div.widget").children(".widget-inside")).is(":hidden")?i.slideDown("fast"):i.slideUp("fast"))}function re(e,t){Array.from(e.children).forEach(function(e){e.classList.contains("tabs-panel")&&e.id!==t&&!e.classList.contains(t)&&(e.style.display="none")})}function ne(e){e.style.display="block"}function oe(){var e=this.getAttribute("href");if(null===e||"#"!==e.charAt(0))return!1;var t=e.slice(1),r=this.closest("li");r&&(r.classList.add("frm-tabs","active"),Array.from(r.parentNode.children).forEach(function(e){e!==r&&"LI"===e.tagName&&e.classList.remove("frm-tabs","active","starttab")}));var n=this.closest("div");n&&re(n,t);var o=document.getElementById(t);return o&&ne(o),"frm_insert_fields_tab"!==this.id||this.closest("#frm_adv_info")||mt(),!1}function ie(e,t){var r,n,o=(e=jQuery(e)).attr("href");if(void 0!==o&&"#"===o.charAt(0)){var i=o.slice(1);e.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab");var s,d,u=(r=e.closest("div"),n=1,l(r)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,l=[],s=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(l.push(n.value),l.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return l}}(r,n)||c(r,n)||a())[0];if(null!=u&&u.querySelector(".tabs-panel"))re(u,i);else if(null!==document.getElementById("form_global_settings")){var f=e.data("frmajax");e.closest(".frm_wrap").find(".tabs-panel, .hide_with_tabs").hide(),void 0!==f&&"1"==f&&(s=o.replace("#",""),(d=jQuery(".frm_".concat(s,"_ajax"))).length&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_settings_tab",tab:s.replace("_settings",""),nonce:frmGlobal.nonce},success:function(e){d.replaceWith(e)}}))}else jQuery("#frm-categorydiv .tabs-panel, .hide_with_tabs").hide();var m=document.getElementById(i);m&&ne(m),Array.from(document.getElementsByClassName(i)).forEach(function(e){return ne(e)}),vi(),"auto"!==t&&(jQuery(".frm_updated_message").hide(),jQuery(".frm_warning_style:not(.frm_force_visible_warning)").hide()),jQuery(e).closest("#frm_adv_info").length||(jQuery(".frm_form_settings").length?jQuery(".frm_form_settings").attr("action","?page=formidable&frm_action=settings&id=".concat(jQuery('.frm_form_settings input[name="id"]').val(),"&t=").concat(i)):jQuery(".frm_settings_form").attr("action","?page=formidable-settings&t=".concat(i)))}}function ae(e){document.querySelectorAll(e).forEach(function(e){le(e),Array.from(e.children).forEach(function(e){return de(e,".frm-move")});var t=jQuery(e).children('[data-type="divider"]').children(".divider_section_only");t.length&&le(t)})}function le(e){jQuery(e).droppable({accept:".frmbutton, li.frm_field_box",deactivate:ge,over:se,out:ce,tolerance:"pointer"})}function se(e,t){var r=function(e){return e.classList.contains("divider_section_only")&&(e=jQuery(e).nextAll(".start_divider.frm_sorting").get(0)),e}(e.target);if(!Oe(t.draggable[0],r,e))return r.classList.remove("frm-over-droppable"),void jQuery(r).parents("ul.frm_sorting").addClass("frm-over-droppable");document.querySelectorAll(".frm-over-droppable").forEach(function(e){return e.classList.remove("frm-over-droppable")}),r.classList.add("frm-over-droppable"),jQuery(r).parents("ul.frm_sorting").addClass("frm-over-droppable")}function ce(e){e.target.classList.remove("frm-over-droppable")}function de(e,t){var r={helper:ue,revert:"invalid",delay:10,start:fe,stop:me,drag:_e,cursor:"grabbing",cursorAt:{top:0,left:90}};"string"==typeof t&&(r.handle=t),jQuery(e).draggable(r)}function ue(e){var t,r=e.delegateTarget;if(De(r)){var n=document.getElementById("frm-insert-fields").querySelector(".frm_ttext").cloneNode(!0);return n.querySelector("use").setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_field_group_layout_icon"),n.querySelector("span").textContent=P("Field Group","formidable"),n.classList.add("frm_field_box"),n.classList.add("ui-sortable-helper"),n}if(r.classList.contains("frmbutton"))return(t=r.cloneNode(!0)).classList.add("ui-sortable-helper"),r.classList.add("frm-new-field"),t;if(r.hasAttribute("data-ftype")){var o=r.getAttribute("data-ftype");if(t=document.getElementById("frm-insert-fields").querySelector(".frm_t".concat(o)))return(t=t.cloneNode(!0)).classList.add("form-field"),t.classList.add("ui-sortable-helper"),t.cloneNode(!0)}return h({className:"frmbutton"})}function fe(e,t){if(e.target.classList.contains("frm_at_limit"))return $e(),!1;z.dragging=!0,z.draggable=null,z.offsetsRefreshed=!1;var r,n=S;n.classList.add("frm-dragging-field"),document.body.classList.add("frm-dragging"),t.helper.addClass("frm-sortable-helper"),t.helper.initialOffset=n.scrollTop,e.target.classList.add("frm-drag-fade"),Dr(),(r=document.querySelectorAll("ul.start_divider")).length&&r.forEach(function(e){[].slice.call(e.children).forEach(function(e){(0===e.children.length||1===e.children.length&&"ul"===e.firstElementChild.nodeName.toLowerCase()&&0===e.firstElementChild.children.length)&&e.remove()})}),rt(),Ze(),Y()}function me(){z.draggable=null,S.classList.remove("frm-dragging-field"),document.body.classList.remove("frm-dragging");var e=document.querySelector(".frm-drag-fade");e&&e.classList.remove("frm-drag-fade")}function _e(e,t){z.offsetsRefreshed||(z.offsetsRefreshed=!0,z.draggable=jQuery(e.target).draggable("instance")||null,pe(e)),function(e){var t=S.scrollTop;A.scrollTop(function(t,r){var n=e.clientY,o=S.offsetHeight,i=e.clientY-S.offsetTop,a=i-o/2;return i>o-50&&n>5?r+.1*a:i<70&&n<130?r-Math.abs(.1*a):r}),t!==S.scrollTop&&pe(e)}(e);var r=e.target,n=function(){for(var e=document.getElementById("frm-show-fields");e.querySelector(".frm-over-droppable");)e=e.querySelector(".frm-over-droppable");return"frm-show-fields"!==e.id||e.classList.contains("frm-over-droppable")||(e=!1),e}(),o=document.getElementById("frm_drag_placeholder");if(Oe(r,n,e)){o||(o=y("li",{id:"frm_drag_placeholder",className:"sortable-placeholder"}));var i,a=t.helper.get(0);if((a.classList.contains("form-field")||a.classList.contains("frm_field_box"))&&(a.style.transform="translateY(".concat((i=t.helper,S.scrollTop-i.initialOffset),"px)")),"frm-show-fields"===n.id||n.classList.contains("start_divider"))return o.style.left=0,void function(e){var t,r=e.y,n=e.placeholder,o=jQuery(e.droppable),i=ve(o);if(0===i.length)o.prepend(n),t=0;else{var a=ye(o,r,i);if(a===i.length){var l=jQuery(i[a-1]);t=l.offset().top+l.outerHeight(),o.append(n);var s=o.children(".edit_field_type_end_divider");s.length&&o.append(s)}else t=jQuery(i[a]).offset().top,jQuery(i[a]).before(n)}t-=o.offset().top,n.style.top="".concat(t,"px")}({droppable:n,y:e.clientY,placeholder:o});o.style.top="",function(e){var t,r=e.x,n=e.placeholder,o=jQuery(e.droppable),i=be(o);if(i.length){var a=function(e,t){var r,n,o,i,a=be(e);for(i=0,r=a.length-1;r>=0;--r)if(n=a.get(r),t>(o=jQuery(n).offset().left)){i=r,t>o+jQuery(n).outerWidth()/2&&(i=r+1);break}return i}(o,r);if(a===i.length){var l=jQuery(i.get(a-1));t=l.offset().left+l.outerWidth(),o.append(n)}else t=jQuery(i.get(a)).offset().left,jQuery(i.get(a)).before(n),t-=0===a?4:8;t-=o.offset().left,n.style.left="".concat(t,"px")}}({droppable:n,x:e.clientX,placeholder:o})}else o&&o.remove()}function pe(e){z.draggable&&jQuery.ui.ddmanager.prepareOffsets(z.draggable,e)}function ge(e,t){if(z.dragging){z.dragging=!1;var r=t.draggable[0],n=document.getElementById("frm_drag_placeholder");if(!n)return t.helper.remove(),void Q();!function(e){if(e.previousElementSibling&&e.previousElementSibling.classList.contains("frm-is-collapsed")){var t=jQuery(e).prevUntil('[data-type="break"]');if(t.length){var r=t.find(".frm-collapse-page").get(0);r&&r.click()}}}(n);var o=t.helper.parent(),i=t.helper.get(0).closest("ul.start_divider"),a=n.closest("ul.start_divider");r.classList.contains("frm-new-field")?function(e){if(Ie(e))wp.hooks.doAction("frm_stopped_inserting_by_dragging",e);else{var t=document.getElementById("frm_drag_placeholder"),r="".concat(e.replace("|","-"),"_").concat(Te()),n=y("li",{id:r,className:"frm-wait frmbutton_loadingnow"}),o=jQuery(n),i=ke(jQuery(t)),a=Qe(i),l=Se(i);t.parentNode.insertBefore(n,t),t.remove(),we(o);var s=0;"summary"===e&&(s=jQuery(".frmbutton_loadingnow#".concat(r)).prevAll('li[data-type="break"]').length?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:Le(e,l,a,s),success:function(t){qe(t,o);var r=Be(t);r&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:r,fieldType:e,form_id:a})},error:Ne})}}(r.id):(function(e,t){t.parentNode.insertBefore(e,t)}(r,n),function(e){if("UL"===e.nodeName&&!e.classList.contains("start_divider")&&"frm-show-fields"!==e.id){var t=e.closest("li");t&&!t.classList.contains("ui-draggable")&&de(t,".frm-move")}}(n.parentElement));var l=i?parseInt(i.closest(".edit_field_type_divider").getAttribute("data-fid")):0,s=a?parseInt(a.closest(".edit_field_type_divider").getAttribute("data-fid")):0;n.remove(),t.helper.remove();var c=o.length?be(o):[];!function(e,t){var r;e.length&&(t.length?we(t.first()):(r=e.get(0).closest("li.frm_field_box"))&&!r.classList.contains("edit_field_type_divider")&&r.remove())}(o,c),function(e,t){0===t.length&&1===be(jQuery(e.parentNode)).length||we(jQuery(e))}(r,c),l!==s&&Ae(jQuery(r),i),Q()}}function ve(e){var t=e.get(0);return t?Array.from(t.children).filter(function(e){return!e.classList.contains("edit_field_type_end_divider")}):[]}function ye(e,t,r){if(!document.querySelector(".frm-has-fields .frm_no_fields"))return 0;for(var n=r||ve(e),o=0,i=n.length-1,a=-1;o<=i;){var l=Math.floor((o+i)/2);t>n[l].getBoundingClientRect().top?(a=l,o=l+1):i=l-1}if(-1===a)return 0;var s=n[a].getBoundingClientRect();return t>s.top+s.height/2?a+1:a}function he(){document.querySelectorAll("ul#frm-show-fields, ul.start_divider").forEach(function(e){e.childNodes.forEach(function(e){void 0!==e.classList&&(e.classList.contains("edit_field_type_end_divider")||void 0!==e.classList&&e.classList.contains("form-field")&&dt(e))})}),$n(),document.querySelectorAll(".edit_field_type_end_divider").forEach(function(e){return e.parentNode.append(e)}),document.querySelectorAll("li.form_field_box:not(.form-field)").forEach(function(e){return!e.children.length&&e.remove()}),Wn();var e=new Event("frm_sync_after_drag_and_drop",{bubbles:!1});document.dispatchEvent(e)}function be(e){var t=jQuery(),r=e.get(0);return r.children?(Array.from(r.children).forEach(function(e){if("none"!==e.style.display){var r=e.classList;!r.contains("form-field")||r.contains("edit_field_type_end_divider")||r.contains("frm-sortable-helper")||(t=t.add(e))}}),t):t}function we(e,t){var r;void 0===t&&(t="even");var n=e.parent().children("li.form-field, li.frmbutton_loadingnow").not(".edit_field_type_end_divider"),o=n.length,i=["frm_full","frm_half","frm_third","frm_fourth","frm_sixth","frm_two_thirds","frm_three_fourths","frm1","frm2","frm3","frm4","frm5","frm6","frm7","frm8","frm9","frm10","frm11","frm12"];"even"===t&&5!==o?n.each(Ee(i,pr(o))):"clear"===t?n.each(Ee(i,"")):(r=["left","right","middle","even"].includes(t)?function(e){return _r(o,t,e)}:function(e){return Ar(t[e])},n.each(Ee(i,r))),je(e.parent(),n.length)}function je(e,t){if(void 0!==e.offset()){var r=t>=2,n=document.getElementById("frm_field_group_controls");if(!n){if(!r)return;(n=h()).id="frm_field_group_controls",n.setAttribute("role","group"),n.setAttribute("tabindex",0),function(e){var t=document.createElement("span");t.innerHTML='<svg class="frmsvg"><use href="#frm_field_group_layout_icon"></use></svg>';var r=P("Set Row Layout","formidable");xe(t,r),cr(t,r);var n=document.createElement("span");n.innerHTML='<svg class="frmsvg"><use href="#frm_thick_move_icon"></use></svg>',n.classList.add("frm-move");var o=P("Move Field Group","formidable");xe(n,o),cr(n,o),e.innerHTML="",e.append(t),e.append(n),e.append(function(){var e=b({className:"dropdown"}),t=w({className:"frm_bstooltip frm-hover-icon frm-dropdown-toggle dropdown-toggle",children:[b({child:j({href:"#frm_thick_more_vert_icon"})}),b({className:"screen-reader-text",text:P("Toggle More Options Dropdown","formidable")})]});frmDom.setAttributes(t,{title:P("More Options","formidable"),"data-bs-toggle":"dropdown","data-bs-container":"body","data-bs-display":"static"}),cr(t,P("More Options","formidable")),e.append(t);var r=h({className:"frm-dropdown-menu dropdown-menu dropdown-menu-right"});return r.setAttribute("role","menu"),e.append(r),e}())}(n),W.append(n)}e.append(n),n.style.display=r?"block":"none"}}function xe(e,t){e.setAttribute("data-bs-toggle","tooltip"),e.setAttribute("data-bs-container","body"),e.setAttribute("title",t),e.addEventListener("mouseover",function(){e.__bootstrapTooltip||(e.__bootstrapTooltip=new bootstrap.Tooltip(e))})}function Ee(e,t){return function(r){for(var n="function"==typeof t?t(r):t,o=e.length,i=!1,a=0;a<o;++a){var l=e[a];if(this.classList.contains(l)){i=l;break}}var s=this.dataset.fid;if(void 0!==s){Qo(document.getElementById("frm-single-settings-".concat(s)));var c=document.getElementById("frm_classes_".concat(s));c&&(!1===i?""!==n&&(c.value=c.value.concat(" ".concat(n))):(this.classList.remove(i),c.value=c.value.replace(i,n)),this.classList.contains("frm_first")&&(this.classList.remove("frm_first"),c.value=c.value.replace("frm_first","").trim()),0===r&&(this.classList.add("frm_first"),c.value=c.value.concat(" frm_first")),jQuery(c).trigger("change"))}else this.classList.add(n)}}function ke(e){var t="";return void 0===e||e.hasClass("edit_field_type_divider")||(t=e.closest(".edit_field_type_divider")),t}function Qe(e){var t="";if(void 0!==e[0]){var r=e.children(".start_divider");if(r.children(".edit_field_type_end_divider").appendTo(r),void 0!==e.attr("data-formid")){var n=e.attr("data-fid");t=jQuery('input[name="field_options[form_select_'.concat(n,']"]')).val()}}return void 0!==t&&""!==t||(t=T),t}function Se(e){var t=0;return void 0!==e[0]&&(t=e.attr("id").replace("frm_field_id_","")),t}function Ae(e,t){if(e.hasClass("form-field")){var r=e.attr("id").replace("frm_field_id_",""),n=ke(e),o=Qe(n),i=Se(n),a=t?Qe(jQuery(t.parentNode)):0;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_update_field_after_move",form_id:o,field:r,section_id:i,previous_form_id:a,nonce:frmGlobal.nonce},success:function(){$n(),function(e,t){document.getElementById("frm_in_section_".concat(e)).value=t}(r,i)}})}else be(jQuery(e.get(0).firstChild)).each(function(){Ae(jQuery(this),t)})}function Le(e,t,r,n){var o={action:"frm_insert_field",form_id:r,field_type:e,section_id:t,nonce:frmGlobal.nonce,has_break:n};return t>0&&document.getElementById("form_id").value!==r||(o.last_row_field_ids=function(){var e=document.querySelector(".edit_field_type_submit");if(!e)return[];for(var t=e.parentNode.children,r=[],n=0;n<t.length;n++)r.push(t[n].dataset.fid);return r}()),o}function Ie(e){return wp.hooks.applyFilters("frm_should_stop_inserting_field",!1,e)}function qe(e,t){var r;document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var n=t.siblings("li.form-field").not(".edit_field_type_end_divider");n.length?(r=Ce(e),t.get(0).parentNode.parentNode.classList.contains("ui-draggable")||de(t.get(0).parentNode.parentNode,".frm-move")):r=ct(e),t.replaceWith(r),Wn(),ut(e,!1),n.length&&we(n.first()),$n(),n.length?de(r.get(0),".frm-move"):(le(r.get(0).querySelector("ul.frm_sorting")),de(r.get(0).querySelector("li.form-field"),".frm-move"))}function Be(e){var t=e.match(/data-fid="(\d+)"/);return t?parseInt(t[1]):0}function Ce(e){var t=h();return t.innerHTML=e,jQuery(t.firstChild)}function Ne(e,t,r){!function(e,t){(function(e){return 0===e.status||0===e.readyState})(t)||K("".concat(e,". Please try again."))}(r,e)}function Te(){return++O}function Oe(e,t,r){if(!1===t)return!1;if(t.closest(".frm-sortable-helper"))return!1;var n=e.classList.contains("edit_field_type_submit"),o=!e.classList.contains("form_field")&&Boolean(e.querySelector(".edit_field_type_submit"));if("frm-show-fields"===t.id){var i=ye(jQuery(t),r.clientY);if(n||o)return i>t.childElementCount-1;var a=function(e){if(z.submitButtonRow&&z.submitButtonRow.parentNode===e)return z.submitButtonRow;var t=e.querySelector(".edit_field_type_submit");return z.submitButtonRow=t?t.closest("#frm-show-fields > li"):null,z.submitButtonRow}(t);return!a||i<=Array.prototype.indexOf.call(t.children,a)}if(n)return!(t.classList.contains("start_divider")||!Fe(t.parentElement)&&(!Fe(t.parentElement.nextElementSibling)||e.parentElement.querySelector("li.frm_field_box:not(.edit_field_type_submit)")));var l=t.classList.contains("start_divider")&&null!==t.closest(".repeat_section"),s=null!==t.closest(".repeat_section");if(l||s){if(e.classList.contains("edit_field_type_gdpr")||"gdpr"===e.id)return!1;if(wp.hooks.applyFilters("frm_deny_drop_in_repeater",!1,e))return!1}if(!l){if(!function(e,t){if(e.length<12)return!0;if(e.length>12)return!1;var r=t.attr("data-fid");return 1===jQuery(e).filter('[data-fid="'.concat(r,'"]')).length}(be(jQuery(t)),jQuery(e)))return!1;if("divider"===e.id&&t.closest(".start_divider"))return!1}return e.classList.contains("frm-new-field")?function(e,t){var r=e.classList,n=r.contains("frm_tbreak"),o=r.contains("frm_thidden"),i=r.contains("frm_tdivider"),a=r.contains("frm_tform"),l=r.contains("frm_tuser_id");return"frm-show-fields"===t.id||t.classList.contains("start_divider")?!(n||o||i||a)||(!(t.classList.contains("start_divider")||null!==t.closest(".start_divider"))||!a&&!i):!(Me(t)||o||n||l)}(e,t):function(e,t){if(De(e))return function(e,t){return!(!t.classList.contains("start_divider")||null!==e.querySelector(".start_divider"))}(e,t);if(e.classList.contains("edit_field_type_break"))return!1;if(t.classList.contains("start_divider"))return function(e){return!e.classList.contains("edit_field_type_form")&&!e.querySelector(".edit_field_type_form")&&!(e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"))}(e);var r=e.classList.contains("edit_field_type_hidden"),n=e.classList.contains("edit_field_type_user_id");return!r&&!n&&function(e,t){if(Me(t))return!1;if(jQuery(e).children("ul.frm_sorting").not(".start_divider").length>0)return!1;var r=e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"),n=e.classList.contains("edit_field_type_form");return!(null!==t.closest(".start_divider")&&(r||n))}(e,t)}(e,t)}function Fe(e){return null==e?void 0:e.matches("#frm-show-fields > li:last-child")}function De(e){return e.classList.contains("frm_field_box")&&!e.classList.contains("form-field")}function Me(e){return null!==e.querySelector(".edit_field_type_break, .edit_field_type_hidden, .edit_field_type_user_id")}var Pe=0,Re=!1;function ze(){for(;Pe<3;){var e=document.querySelector("#frm-show-fields .frm_field_loading:not(.frm_load_now)");if(!e)break;He(e)}Re&&0===Pe&&(on(),Ke())}function He(e){var t=[],r=function(e){e.classList.add("frm_load_now"),e.classList.contains("frm_field_loading")&&t.push(e.dataset.fid)};r(e);for(var n=Ge(e);n&&t.length<40;)r(n),n=Ge(n);t.length&&(++Pe,Re=!0,jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_load_field",field_ids:t,form_id:T,nonce:frmGlobal.nonce},success:Ue,complete:function(){--Pe,ze()}}))}function Ge(e){var t;return e.nextElementSibling?e.nextElementSibling:null===(t=e.parentNode)||void 0===t||null===(t=t.closest(".frm_field_box"))||void 0===t||null===(t=t.nextElementSibling)||void 0===t?void 0:t.querySelector(".form-field")}function Ue(e){var t;if(0===(e=e.replace(/^\s+|\s+$/g,"")).indexOf("{")){var r=JSON.parse(e),n=[],o=[];for(t in r)if(Object.hasOwn(r,t)){jQuery("#frm_field_id_".concat(t)).replaceWith(r[t].html),o.push({id:t,type:r[t].type});var i=document.getElementById("frm_field_id_".concat(t));i&&(n.push(i),i.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),i.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")})),ae("#frm_field_id_".concat(t,".edit_field_type_divider ul.frm_sorting")),de(document.getElementById("frm_field_id_".concat(t)))}Bi(n),z.dragging&&pe();var a=new Event("frm_ajax_loaded_field",{bubbles:!1});a.frmFields=o,document.dispatchEvent(a)}else jQuery(".frm_load_now").removeClass(".frm_load_now").html("Error")}function We(){var e=jQuery(this);if(e.hasClass("disabled"))return!1;var t=e.closest(".frmbutton"),r=t.attr("id");if(t.hasClass("frm_at_limit"))return $e(),!1;if(frm_admin_js.paymentsSettingsModal&&"object"===i(frm_admin_js.paymentsSettingsModal)&&["product","quantity","total"].includes(r))return K(frm_admin_js.paymentsSettingsModal),!1;if(!Ie(r)){var n=0;"summary"===r&&(n=I.children('li[data-type="break"]').length>0?1:0);var o=T;return jQuery.ajax({type:"POST",url:ajaxurl,data:Le(r,0,o,n),success:function(e){Ve(e);var t=Be(e);t&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:e,fieldId:t,fieldType:r,form_id:o})},error:Ne}),!1}}function $e(){var e=document.querySelector(".frm_wrap");if(e){var t=document.createElement("a");t.setAttribute("data-frmverify",P("This field type has reached its limit.","formidable")),e.append(t),t.click(),t.remove();var r=document.getElementById("frm-confirmed-click");r&&(r.style.display="none")}}function Ve(e){document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var t=ct(e),r=I[0].querySelector(".edit_field_type_submit");r?jQuery(r.closest(".frm_field_box:not(.form-field)")).before(t):I.append(t),ut(e,!0),t.each(function(){le(this.querySelector("ul.frm_sorting")),de(this.querySelector(".form-field"),".frm-move")})}function Ke(){var e=!0,t=document.querySelectorAll(".frmjs_prod_field_opt_cont");I.find("li.edit_field_type_product").length>1&&(e=!1);for(var r=0;r<t.length;r++)t[r].classList.toggle("frm_hidden",e)}function Je(){var e=jQuery(this).closest("li.form-field"),t=this.getAttribute("frm-target-row-id");if(null!=t&&t.startsWith("frm_field_group_")||function(e){if(e.classList.contains("frm-page-collapsed"))return!1;var t=e.closest("li.frm_field_box:not(.form-field)");return!t||be(jQuery(t.querySelector("ul"))).length<12}(e.get(0))){Ze();var r,n=e.data("fid"),o=function(e){var t=[];return jQuery(document.getElementById("frm_field_id_".concat(e))).find("li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)").each(function(){t.push(jQuery(this).data("fid"))}),t}(n);return null!==t&&(r=this.getAttribute("frm-field-order")),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_duplicate_field",field_id:n,form_id:T,children:o,nonce:frmGlobal.nonce},success:function(o){var i,a,l;if(null!==t&&(a=document.getElementById(t)))return l=Ce(o),jQuery(a).append(l),de(l.get(0),".frm-move"),null!==r&&a.lastElementChild.setAttribute("frm-field-order",r),jQuery(a).trigger("frm_added_duplicated_field_to_row",{duplicatedFieldHtml:o,originalFieldId:n}),ut(o,!1),void Xe(e.get(0),l.get(0));e.siblings("li.form-field").length?(l=Ce(o),e.after(l),we(e),de(l.get(0),".frm-move")):(l=ct(o),e.parent().parent().after(l),le(l.get(0).querySelector("ul.frm_sorting")),de(l.get(0).querySelector("li.form-field"),".frm-move")),Wn(),ut(o,!1),Ye(n,o),Vn(l.find(".start_divider")),null===(i=e[0].querySelector(".frm-dropdown-menu.dropdown-menu-right"))||void 0===i||i.classList.remove("show"),Xe(e.get(0),l.get(0))}}),!1}K(R(P("You can only have a maximum of %1$d fields in a field group. Delete or move out a field from the group and try again.","formidable"),12))}function Xe(e,t){var r,n=e.closest(".frm-field-group-hover-target");if(n&&De(n.parentElement)){var o=e.dataset.fid,i=null===(r=document.getElementById("frm_classes_".concat(o)))||void 0===r?void 0:r.value;if(i&&(i=i.replace("frm_first",""),!t.className.includes(i))){t.className+=" ".concat(i);var a=document.getElementById("frm_classes_".concat(t.dataset.fid));a&&(a.value=i)}}}function Ye(e,t){var r=document.getElementById("frm-single-settings-".concat(e));if(r){var n=jQuery(t).attr("data-fid");if(void 0!==n){var o=document.getElementById("frm-single-settings-".concat(n));if(o){var i=["name","required","unique","read_only","placeholder","description","size","max","format","prepend","append","separate_value"];r.querySelectorAll('input[name^="field_options["], textarea[name^="field_options["]').forEach(function(t){var r,a=((r=t.name.substr(14).split("_")).pop(),r.join("_"));if("options"!==a){if(i.includes(a)){var l=t.matches("input")?"input":"textarea",s=o.querySelector("".concat(l,'[name="field_options[').concat(a,"_").concat(n,']"]'));null!==s&&("checkbox"===t.type?t.checked!==s.checked&&jQuery(s).trigger("click"):"text"!==t.type&&"textarea"!==l||t.value!==s.value&&(s.value=t.value,jQuery(s).trigger("change")))}}else!function(e,t,r,n){var o=e.name.substr(23+"".concat(r).length),i="field_options[options_".concat(n,"]").concat(o),a=t.querySelector('input[name="'.concat(i,'"]'));null!==a&&a.value!==e.value&&(a.value=e.value,jQuery(a).trigger("change"))}(t,o,e,n)});var a=r.querySelector('input[name="default_value_'.concat(e,'"]'));if(null!==a){var l=o.querySelector('input[name="default_value_'.concat(n,'"]'));null!==l&&a.value!==l.value&&(l.value=a.value,jQuery(l).trigger("change"))}}}}}function Ze(){var e=document.querySelector(".frm-field-settings-open");e&&(e.classList.remove("frm-field-settings-open"),jQuery(document).off("click","#frm_builder_page",et),jQuery(".frm-field-action-icons .dropdown.open").removeClass("open"))}function et(e){jQuery(e.originalEvent.target).closest(".frm-field-action-icons").length||Ze()}function tt(e){var t=Boolean(e.ctrlKey||e.metaKey||e.shiftKey);jQuery(W).toggleClass("frm-multiselect-key-is-down",t),function(e){if(!S.classList.contains("frm-dragging-field")&&null===document.querySelector(".frm-field-group-hover-target .frm-field-settings-open")){var t=document.elementFromPoint(e.clientX,e.clientY);if(null!==t&&!t.classList.contains("edit_field_type_divider")){var r=t.closest("ul.frm_sorting");if(null!==r&&!r.classList.contains("start_divider")&&"frm-show-fields"!==r.id){var n=rt();!1===n||jQuery(n).is(r)||Br(),je(jQuery(r),be(jQuery(r)).length),r.classList.add("frm-field-group-hover-target"),jQuery("#wpbody-content").on("mousemove",nt)}}}}(e)}function rt(){var e=document.getElementById("frm_field_group_controls");e&&(e.style.display="none");var t=document.querySelector(".frm-field-group-hover-target");return!!t&&(jQuery("#wpbody-content").off("mousemove",nt),t.classList.remove("frm-field-group-hover-target"),t)}function nt(e){var t=document.elementFromPoint(e.clientX,e.clientY);null!==t&&null!==t.closest("#frm-show-fields")||(rt(),Y())}function ot(e){Dr(),setTimeout(function(){var t=document.querySelector(".dropdown .frm-dropdown-menu.show");if(t){null===t.getAttribute("aria-label")&&t.setAttribute("aria-label",P("More Options","formidable")),0===t.children.length&&function(e,t){var r=t?"_field_group":"_field",n=[lt(t),st(t)];t||n.push({class:"frm_select",icon:"frm_settings_icon",label:P("Field Settings","formidable")}),n.forEach(function(t){var n=document.createElement("div");n.classList.add("frm_more_options_li","dropdown-item");var o=document.createElement("a");o.classList.add(t.class+r),o.setAttribute("href","#"),cr(o);var i=document.createElement("span");i.textContent=t.label,o.innerHTML='<svg class="frmsvg"><use href="#'.concat(t.icon,'"></use></svg>'),o.append(document.createTextNode(" ")),o.append(i),n.append(o),e.append(n)})}(t,!0===e);var r=jQuery(t);r.offset().left>jQuery(window).width()-r.outerWidth()?t.style.left="".concat(-r.outerWidth(),"px"):S&&r.offset().left<S.getBoundingClientRect().left&&(t.style.right="auto",t.style.left="0");var n=t.firstElementChild.querySelector("a");n&&n.focus()}},0)}function it(){ot(!0)}function at(e){var t=e.target.closest(".frm-section-collapsed");t&&("show"===e.type?t.style.zIndex=3:t.style.zIndex=1)}function lt(e){var t={class:"frm_delete",icon:"frm_delete_icon"};return t.label=P(e?"Delete Group":"Delete","formidable"),t}function st(e){var t={class:"frm_clone",icon:"frm_clone_icon"};return t.label=P(e?"Duplicate Group":"Duplicate","formidable"),t}function ct(e){var t=h();"string"==typeof e?t.innerHTML=e:t.append(e);var r=jQuery();return Array.from(t.children).forEach(function(e){r=r.add(jQuery("<li>").addClass("frm_field_box").html(jQuery("<ul>").addClass("frm_grid_container frm_sorting").append(e)))}),r}function dt(e){var t=y("ul",{className:"frm_grid_container frm_sorting"}),r=y("li",{className:"frm_field_box",child:t});e.replaceWith(r),t.append(e),le(t),de(r,".frm-move")}function ut(e,t){var r,n,o=/id="(\S+)"/.exec(e),a=document.getElementById(o[1]),l="#".concat(o[1],".edit_field_type_divider ul.frm_sorting.start_divider"),s=jQuery(l),c=a.getAttribute("data-type");r=e,(n=h()).innerHTML=r,n.querySelectorAll(".form-field").forEach(ft);var d,u,f=!1;if(ci(),ae(l),"quantity"===c&&function(e){var t=e.getAttribute("data-fid"),r=document.getElementById("field_options[product_field_".concat(t,"]"));r&&(xt(r),Qo(document.getElementById("frm-single-settings-".concat(t))))}(a),"product"!==c&&"quantity"!==c||Ke(),s.length)s.parent(".frm_field_box").children(".frm_no_section_fields").addClass("frm_block");else{var m=jQuery(a).closest("ul.frm_sorting.start_divider");m.length&&(Vn(m),f=!0)}e.includes("frm-collapse-page")&&on(),u="frm-newly-added",(d=a).classList?d.classList.add(u):d.className+=" ".concat(u),setTimeout(function(){a.classList.remove("frm-newly-added")},1e3);var _,p=a.querySelector("#frm-last-row-fields-order");if(p&&((_=JSON.parse(p.value))&&"object"===i(_)&&Object.keys(_).forEach(function(e){var t=document.querySelector('input[name="field_options[field_order_'.concat(e,']"]'));t&&(t.value=_[e])})),t){var g=a.getBoundingClientRect(),v=document.getElementById("post-body-content");g.top>=0&&g.left>=0&&g.right<=(window.innerWidth||document.documentElement.clientWidth)&&g.bottom<=(window.innerHeight||document.documentElement.clientHeight)||v.scroll({top:v.scrollHeight,left:0,behavior:"smooth"}),!1===f&&Vn(s)}_t(),Bi(),document.getElementById("frm-show-fields").classList.remove("frm-over-droppable"),function(e){var t=document.getElementById(e);null!=t&&t.dataset.limit&&$r(e)>=t.dataset.limit&&t.classList.add("frm_at_limit")}(c),a.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),a.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")});var y=new Event("frm_added_field",{bubbles:!1});y.frmField=a,y.frmSection=l,y.frmType=c,y.frmToggles=f,document.dispatchEvent(y)}function ft(e){if(e.dataset.fid){var t=document.getElementById("draft_fields");t&&(""===t.value?t.value=e.dataset.fid:t.value.split(",").includes(e.dataset.fid)||(t.value+=",".concat(e.dataset.fid)))}}function mt(e){jQuery("#new_fields .frm-single-settings").addClass("frm_hidden"),jQuery("#frm-options-panel > .frm-single-settings").removeClass("frm_hidden"),_t(e)}function _t(e){jQuery("li.ui-state-default.selected").removeClass("selected"),jQuery(".frm-show-field-settings.selected").removeClass("selected"),e||Dr()}function pt(){var e=this.value,t=function(e){var t,r=[],n=e.split(""),o=n.length,i=["{","[","("],a={"}":"{",")":"(","]":"["},l=!1;for(t=0;t<o;t++)i.includes(n[t])?r.push(n[t]):Object.hasOwn(a,n[t])&&r.pop()!==a[n[t]]&&(l=!0);return r.length>0||l?"".concat(f.unmatched_parens,"\n\n"):""}(e);t+=function(e,t){var r=function(e,t){var r="";return function(e){return jQuery(e).siblings('label[for^="calc_type"]').children("input").prop("checked")}(t)||/\[(date|time|email|ip)\]/.test(e)&&(r="".concat(f.text_shortcodes,"\n\n")),r}(e,t);return r+=function(e){var t="";return/\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g.test(e)&&(t+="".concat(f.view_shortcodes,"\n\n")),t}(e)}(e,this),""!==t&&K("".concat(e,"\n\n").concat(t))}function gt(e,t){for(var r=!1,n=0;n<t.length;n++){var o=document.getElementsByName(vt(t[n],e.fieldId));if(o.length&&jQuery(o[0]).val()){r=!0;break}}return r}function vt(e,t){var r=e.indexOf("]");return"field_options".concat(e.substring(0,r),"_").concat(t).concat(e.substring(r))}function yt(e,t){var r=jQuery(e).closest(".frm-single-settings"),n=r.find(".frm-calc-field");if(t||n.length&&""!==n.val()&&!n.is(":hidden")){var o,i=function(e){var t=jQuery(e).find(".frm_code_list");return 1===t.length&&t.hasClass("frm_js_summary_list")}(e),a=r.find('input[name="frm_fields_submitted[]"]').val(),l=(o=t?e:document.getElementById("frm-calc-box-".concat(a))).querySelector(".frm_code_list"),s=function(e,t){var r=JSON.parse(e.getAttribute("data-exclude"));if(t){var n=function(){for(var e=[],t=document.getElementsByClassName("frm_include_extras_field"),r=0;r<t.length;r++)t[r].checked&&e.push(t[r].value);return e}();if(n.length)for(var o=0;o<r.length;o++)n.includes(r[o])&&(r.splice(o,1),o--)}return r}(l,i),c=function(e){var t=[];if(!Array.isArray(e))return t;for(var r=0;r<e.length;r++)e[r].startsWith("[")&&(t.push(e[r]),e.splice(r,1),r--);return t}(s),d=wp.hooks.applyFilters("frm_calc_field_list",jt(),{box:o,codeList:l,isSummary:i}),u=document.getElementById("frm-calc-list-".concat(a));u.innerHTML="";for(var f=0;f<d.length;f++)null!=s&&s.includes(d[f].fieldType)||c.length&&gt(d[f],c)||(bt(u,a,d[f].fieldId,d[f].fieldName,d[f].fieldType),i||ht(d[f],a,u))}}function ht(e,t,r){wp.hooks.doAction("frm_add_calc_field_shortcodes",{field:e,fieldId:t,list:r,addCalcFieldLiToList:bt})}function bt(e,t,r,n,o){var i=w({className:"frm_insert_code",children:[b(n),b({className:"frm-text-sm frm-text-grey-500",text:"[".concat(r,"]")})],data:{code:r}});e.append(y("li",{className:"frm-field-list-".concat(t," frm-field-list-").concat(o),child:i}))}function wt(){yt(jQuery(".frm-inline-modal.postbox:has(.frm_js_summary_list)")[0],!0)}function jt(e){var t,r=[],n=document.querySelectorAll("li.frm_field_box"),o=void 0!==e;for(t=0;t<n.length;t++)if(!o||n[t].getAttribute("data-ftype")===e){var i=n[t].getAttribute("data-fid");i&&r.push({fieldId:i,fieldName:kt("frm_name_".concat(i)),fieldType:kt("field_options_type_".concat(i)),fieldKey:kt("field_options_field_key_".concat(i))})}return wp.hooks.applyFilters("frm_admin_get_field_list",r,e,n)}function xt(e){var t,r,n,o=[],i=function(e){for(var t=e.querySelectorAll('[type="checkbox"]:checked'),r=[],n=0;n<t.length;n++)r.push(t[n].value);return r}(e),a=e.getAttribute("data-frmfname"),l=jt("product"),s=jt("quantity"),c="SELECT"===e.tagName,d=1===s.length&&1===l.length;for(c&&(i=e.getAttribute("data-frmcurrent")),t=0;t<l.length;t++)n=l[t].fieldId.toString(),r=d||i.includes(n),c?(r=r?" selected":"",o.push('<option value="'.concat(n,'"').concat(r,">").concat(l[t].fieldName,"</option>"))):(r=r?" checked":"",o.push('<label class="frm6">'),o.push('<input type="checkbox" name="'.concat(a,'" value="').concat(n,'"').concat(r,"> ").concat(l[t].fieldName)),o.push("</label>"));e.innerHTML=o.join("")}function Et(){for(var e=document.querySelectorAll(".frmjs_prod_field_opt"),t=0;t<e.length;t++)xt(e[t])}function kt(e){var t=document.getElementById(e);return t?t.value:""}function Qt(){var e,t,r=this.value,o=document.getElementById(this.getAttribute("data-changeme")),i=this.getAttribute("data-changeatt");o&&(null!==i?"SELECT"===o.tagName&&"placeholder"===i?""===(e=o.options[0]).value?e.innerHTML=r:Bn(o,r):"class"===i?function(e,t){var r,o,i,a=" ".concat(t.value),l=e.getAttribute("data-fid");if(""===a.trim()){var s=t.querySelector("option[data-align]");a=s?" ".concat(s.getAttribute("data-align")):""}void 0!==l&&(t.classList.contains("field_options_align")?a+=" ".concat(document.getElementById("frm_classes_".concat(l)).value):t.classList.contains("frm_classes")&&(i=document.getElementById("field_options_align_".concat(l)))&&(a+=" ".concat(i.value))),a=(a+=" ").replace(" block "," vertical_radio ").replace(" inline "," horizontal_radio "),""===(r=0===(r=e.className.split(" frmstart ")[1]).indexOf("frmend ")?"":r.split(" frmend ")[0]).trim()?(o=" frmstart frmend ",e.className.includes(o)||(o=" frmstart frmend "),a=" frmstart ".concat(a.trim()," frmend ")):(o=r.trim(),a=a.trim());var c=e.classList.contains("frm_first");e.className=e.className.replace(o,a),!c&&e.classList.contains("frm_first")&&function(e){var t=e.parentElement;if(t&&"UL"===t.nodeName&&!t.classList.contains("start_divider")){var r=t.parentElement;if(r&&De(r)&&!(be(jQuery(t)).get().indexOf(e)<1)){var o=y("ul",{className:"frm_grid_container frm_sorting"}),i=y("li",{className:"frm_field_box",child:o});r.after(i),o.append.apply(o,n(function(e){for(var t=[],r=e;r;)"LI"===r.nodeName&&t.push(r),r=r.nextElementSibling;return t}(e))),le(o),de(i,".frm-move"),je(jQuery(t),be(jQuery(t)).length)}}}(e)}(o,this):"range"===(t=o).type&&t.parentNode.classList.contains("frm_range_container")?function(e,t,r){if(frmGlobal.proIncludesSliderJs){var n={field:e,att:t,newValue:r};wp.hooks.doAction("frm_update_slider_field_preview",n)}else{var o;if("value"===t?(""===r&&(r=St(e)),e.value=r):e.setAttribute(t,r),["value","min","max"].includes(t))"max"!==t&&"min"!==t||""!==(o=e.id,document.querySelector('input[data-changeme="'.concat(o,'"][data-changeatt="value"]')).value)||(e.value=St(e)),e.parentNode.querySelector(".frm_range_value").textContent=e.value}}(o,i,r):o.setAttribute(i,r):0===o.id.indexOf("setup-message")?""!==r&&(o.innerHTML='<input type="text" value="" disabled />'):(o.innerHTML=Tn(r),"TEXTAREA"===o.nodeName&&o.classList.contains("wp-editor-area")&&jQuery(o).trigger("change"),o.classList.contains("frm_primary_label")&&"break"===o.nextElementSibling.getAttribute("data-ftype")&&(o.nextElementSibling.querySelector(".frm_button_submit").textContent=r)))}function St(e){var t=parseFloat(e.getAttribute("max")),r=parseFloat(e.getAttribute("min"));return(t-r)/2+r}function At(){var e=this.getAttribute("data-fid"),t="";["field_options_max_","frm_format_"].forEach(function(r){var n=document.getElementById(r+e);n&&(t+=n.value)});var r=document.getElementsByName("field_options[type_".concat(e,"]"))[0];"text"===r.options[r.selectedIndex].value&&It(""!==t,".frm_invalid_msg".concat(e))}function Lt(){var e=this.id.replace("frm_","").replace("req_field_",""),t=this.checked,r=jQuery("#field_label_".concat(e," .frm_required"));if(It(t,".frm_required_details".concat(e)),t){var n=jQuery('input[name="field_options[required_indicator_'.concat(e,']"]'));""===n.val()&&n.val("*"),r.removeClass("frm_hidden")}else r.addClass("frm_hidden")}function It(e,t){var r=jQuery(t);if(e)r.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");else{var n=r.fadeOut("fast").closest(".frm_validation_box"),o=n.css("display","block").children(":not(".concat(t,"):visible")).length;n.css("display",""),0===o&&r.closest(".frm_validation_msg").fadeOut("fast")}}function qt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(".frm_unique_details".concat(e));if(this.checked){t.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");var r=jQuery(".frm_unique_details".concat(e," input"));""===r.val()&&r.val(f.default_unique)}else{var n=t.fadeOut("fast").closest(".frm_validation_box"),o=n.css("display","block").children(":not(.frm_unique_details".concat(e,"):visible")).length;n.css("display",""),0===o&&t.closest(".frm_validation_msg").fadeOut("fast")}}function Bt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(this).val(),r=jQuery(document.getElementById("frm_field_id_".concat(e)));if(It(""!==t,".frm_conf_details".concat(e)),""!==t){var n=jQuery(".frm_validation_box .frm_conf_details".concat(e," input"));""===n.val()&&n.val(f.default_conf),function(e){var t=document.getElementsByName("field_options[type_".concat(e,"]"))[0].value;Ct(document.getElementById("field_description_".concat(e)),"field_options[description_".concat(e,"]"),f["enter_".concat(t)]),Ct(document.getElementById("conf_field_description_".concat(e)),"field_options[conf_desc_".concat(e,"]"),f["confirm_".concat(t)])}(e),"inline"===t?r.removeClass("frm_conf_below").addClass("frm_conf_inline"):"below"===t&&r.removeClass("frm_conf_inline").addClass("frm_conf_below"),jQuery(".frm-conf-box-".concat(e)).removeClass("frm_hidden")}else jQuery(".frm-conf-box-".concat(e)).addClass("frm_hidden"),setTimeout(function(){r.removeClass("frm_conf_inline frm_conf_below")},200)}function Ct(e,t,r){e.innerHTML===f.desc&&(e.innerHTML=r,document.getElementsByName(t)[0].value=r)}function Nt(e){var t=JSON.parse(this.getAttribute("data-opts"));return e.preventDefault(),document.getElementById("frm_bulk_options").value=t.join("\n"),!1}function Tt(){var e,t,r,n=jQuery(this).closest(".frm-single-settings").data("fid"),o=jQuery("#frm_field_".concat(n,"_opts .frm_option_template")).prop("outerHTML"),i=jQuery(this).data("opttype"),a=0,l="000",s=function(e){for(var t=0,r=0,n=jQuery("#frm_field_".concat(e,"_opts li")),o=0;t<n.length;t++){if(r=n[t].getAttribute("data-optkey"),1===n.length)return r;"000"!==r&&(r=r.replace("other_",""),r=parseInt(r,10)),!isNaN(o)&&(r>o||"000"===o)&&(o=r)}return o}(n);if(s!==l&&(a=s+1),"other"===i){document.getElementById("other_input_".concat(n)).value=1;var c=jQuery(this).data("ftype");"radio"!==c&&"select"!==c||jQuery(this).fadeOut("slow");var d={action:"frm_add_field_option",field_id:n,opt_key:a,opt_type:i,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,d,function(e){jQuery(document.getElementById("frm_field_".concat(n,"_opts"))).append(e),Qn(n)})}else{o=(o=(o=(o=(o=o.replace(new RegExp('optkey="'.concat(l,'"'),"g"),'optkey="'.concat(a,'"'))).replace(new RegExp("-".concat(l,"_"),"g"),"-".concat(a,"_"))).replace(new RegExp("-".concat(l,'"'),"g"),"-".concat(a,'"'))).replace(new RegExp("\\[".concat(l,"\\]"),"g"),"[".concat(a,"]"))).replace("frm_hidden frm_option_template",""),sa(n,o={newOption:o});var u=this.closest(".frm_single_option");u?u.after(o.newOption):jQuery("#frm_field_".concat(n,"_opts")).append(o.newOption),Qn(n)}null==(r=(e=this).classList.contains("frm-add-option-legacy")?null===(t=e.closest(".frm-collapse-me"))||void 0===t?void 0:t.querySelector(".frm_sortable_field_opts"):e.closest(".frm_sortable_field_opts"))||r.querySelectorAll(".frm_remove_tag.frm_disabled").forEach(function(e){return e.classList.remove("frm_disabled")}),ci()}function Ot(){Ft(jQuery(this).closest(".frm-single-settings").data("fid"),this.value)}function Ft(e,t){var r=jQuery(".frm_multiple_cont_".concat(e));"select"===t?r.fadeIn("fast"):r.fadeOut("fast")}function Dt(){var e=jQuery(this).closest(".frm-single-settings").data("fid");ta(jQuery(".field_".concat(e,"_option_key")),"",this.checked),jQuery(".field_".concat(e,"_option")).toggleClass("frm_with_key")}function Mt(){var e=jQuery(this).closest(".frm-single-settings"),t=e.data("fid"),r=document.getElementById("frm_field_id_".concat(t));Ht(jQuery(this));var n=Mn(t);if(ta(jQuery(".field_".concat(t,"_image_id")),"",n),ta(jQuery(".frm_toggle_image_options_".concat(t)),"",n),ta(jQuery(".frm_image_size_".concat(t)),"",n),ta(jQuery(".frm_alignment_".concat(t)),"",n),ta(jQuery(".frm-add-other#frm_add_field_".concat(t)),"",n),Pt(r),n){Rt(t,"inline");var o=kn(t);r.classList.add("frm_image_options"),r.classList.add("frm_image_size_".concat(o)),e.find(".frm-bulk-edit-link").hide()}else r.classList.remove("frm_image_options"),Rt(t,"block"),e.find(".frm-bulk-edit-link").show();wp.hooks.doAction("frm_image_options_toggled",e[0],n)}function Pt(e){e.classList.remove("frm_image_size_","frm_image_size_small","frm_image_size_medium","frm_image_size_large","frm_image_size_xlarge")}function Rt(e,t){jQuery("#field_options_align_".concat(e)).val(t).trigger("change")}function zt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));Gt(),Mn(e)&&(Pt(t),t.classList.add("frm_image_options"),t.classList.add("frm_image_size_".concat(kn(e))))}function Ht(e){var t=e.closest(".frm-single-settings").data("fid");jQuery(".field_".concat(t,"_option")).trigger("change")}function Gt(){Ht(jQuery(this))}function Ut(e){var t,r=e.target.closest(".frm_image_preview_wrapper");if(null!==(t=wp)&&void 0!==t&&t.media&&(null==r||!r.dataset.upgrade)){e.preventDefault(),wp.media.model.settings.post.id=0;var n=wp.media.frames.file_frame=wp.media({multiple:!1,library:{type:["image"]}});n.on("select",function(){var e=n.state().get("selection").first().toJSON(),t=r.querySelector("img");t.setAttribute("src",e.url),t.classList.remove("frm_hidden"),t.removeAttribute("srcset"),r.querySelector(".frm_image_preview_frame").style.display="block",r.querySelector(".frm_image_preview_title").textContent=e.filename,r.querySelector(".frm_choose_image_box").style.display="none";var o=jQuery(r);o.siblings('input[name*="[label]"]').data("frmimgurl",e.url),o.find("input.frm_image_id").val(e.id).trigger("change"),wp.media.model.settings.post.id=0}),n.open()}}function Wt(e){var t=jQuery(this).closest(".frm_image_preview_wrapper");e.preventDefault(),e.stopPropagation(),t.find("img").attr("src",""),t.find(".frm_image_preview_frame").hide(),t.find(".frm_choose_image_box").show(),t.find("input.frm_image_id").val(0).trigger("change")}function $t(){var e=jQuery(this).closest("li").find(".frm_form_fields select");this.checked?e.attr("multiple","multiple"):e.removeAttr("multiple")}function Vt(){var e=document.getElementById("dropform-search-input");e&&setTimeout(function(){e.focus()},100)}function Kt(e){var t=e.target,r=t.closest(".frm_warning_style");jQuery(r).fadeOut(400,function(){return r.remove()});var n=t.dataset.action,o=new FormData;k(n,o)}function Jt(e){e.preventDefault()}function Xt(){var e,t,r=this.parentNode,n=r.parentNode,o=n.querySelectorAll("li:not(.frm_hidden)");2===o.length&&(null===(e=Array.from(o).find(function(e){return e!==r}).querySelector(".frm_remove_tag"))||void 0===e||e.classList.add("frm_disabled"));var i=this.getAttribute("data-fid");jQuery(r).fadeOut("fast",function(){wp.hooks.doAction("frm_before_delete_field_option",this),jQuery(r).remove(),jQuery(n).find(".frm_other_option").length<1&&((t=document.getElementById("other_input_".concat(i)))&&(t.value=0),jQuery("#other_button_".concat(i)).fadeIn("fast"))}),ci()}function Yt(){var e=jQuery(this);if(e.is(":checked")){var t,r=function(){e.off("mouseup",t)};t=function(){setTimeout(function(){e.prop("checked",!1)},0),r()},e.on("mouseup",t),e.one("mouseout",r)}}function Zt(){this.value===f.new_option&&(this.setAttribute("data-value-on-focus",this.value),this.value="")}function er(e){return R(P("Are you sure you want to delete these %1$s selected field(s)?","formidable"),e)}function tr(){var e=f.conf_delete,t=this.parentNode.parentNode.parentNode.parentNode.parentNode,r=t.parentNode,n=jQuery(this).closest("li.form-field"),o=n.data("fid");if("divider"===n.data("ftype")){var i=document.querySelectorAll(".frm-field-group-hover-target .start_divider .frm_field_box"),a=0;i.forEach(function(e){var t=e.querySelectorAll("li.form-field");t&&(a+=t.length)}),a&&(e=er(++a))}return r.classList.contains("frm-section-collapsed")||r.classList.contains("frm-page-collapsed")||("divider_section_only"===t.className&&(e=f.conf_delete_sec),this.setAttribute("data-frmverify",e),this.setAttribute("data-frmverify-btn","frm-button-red"),this.setAttribute("data-deletefield",o),Ze(),V(this)),!1}function rr(){this.closest("li.form-field").click()}function nr(){var e=document.querySelector(".frm-field-group-hover-target");if(e){e.classList.add("frm-selected-field-group");var t=document.createElement("div");t.classList.add("frm-delete-field-groups","frm_hidden"),document.body.append(t),t.click()}}function or(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t="frm_field_group_".concat(Te()),r=document.createTextNode("");dt(r);var n=jQuery(r).closest("li").get(0);n.classList.add("frm_hidden");var o=n.querySelector("ul");o.id=t,jQuery(e.closest("li.frm_field_box")).after(n);var i=be(jQuery(e)),a=[],l=[],s=i.length,c={},d=0;jQuery(n).on("frm_added_duplicated_field_to_row",function(e,t){if(c[jQuery(t.duplicatedFieldHtml).attr("data-fid")]=t.originalFieldId,!(s>++d)){var r=jQuery(o),i=be(r);l.forEach(function(e){e.remove()});for(var u=0;u<s;++u)r.append(r.children('li.form-field[frm-field-order="'.concat(u,'"]')));we(i.first(),a),n.classList.remove("frm_hidden"),Wn(),be(r).each(function(){Ye(c[this.getAttribute("data-fid")],jQuery(this).prop("outerHTML"))})}}),i.each(function(e){var r=document.createElement("li");r.classList.add("frm_clone_field"),r.setAttribute("frm-target-row-id",t),r.setAttribute("frm-field-order",e),this.append(r),r.click(),l.push(r),a.push(Qr(Sr(this.classList)))})}}function ir(){var e=document.querySelector(".frm-field-group-hover-target");if(e){_t();var t=lr(e.querySelector("li.form-field"));e.classList.add("frm-has-open-field-group-popup"),jQuery(document).on("click","#frm_builder_page",ar);var r=h();r.style.position="relative",r.append(sr(t,this)),this.parentNode.append(r);var n=r.querySelector(".frm-row-layout-option");n&&n.focus()}}function ar(e){e.target.classList.contains("frm-custom-field-group-layout")||e.target.classList.contains("frm-cancel-custom-field-group-layout")||jQuery(e.target).closest("#frm_field_group_controls").length||jQuery(e.target).closest("#frm_field_group_popup").length||Br()}function lr(e){var t=jQuery(e).closest("ul");return t.length?be(t).length:zr()}function sr(e,t){var r=document.getElementById("frm_field_group_popup");r?r.innerHTML="":r=h(),r.id="frm_field_group_popup";var n,o=h();o.style.padding="0 24px 12px",o.append(((n=h()).classList.add("frm-row-layout-title"),n.textContent=P("Row Layout","formidable"),n));var i,a=function(e){var t=yr();if(e>6)return t.append(ur(e,"even")),t;if(5!==e&&t.append(ur(e,"even")),e%2==1&&t.append(ur(e,"middle")),e<6)t.append(ur(e,"left")),t.append(ur(e,"right"));else{var r=h();r.classList.add("frm_fourth"),t.prepend(r)}return t}(e),l=t.closest("ul.frm_sorting");return l&&function(e,t){for(var r=t.children.length,n=0;n<r;++n){var o=t.children[n];if(fr(o,e))return void o.classList.add("frm-active-row-layout")}}(l,a),o.append(a),r.append(o),r.append(document.createElement("hr")),e<=6&&r.append(((i=h()).textContent=P("Custom layout","formidable"),jQuery(i).prepend(dr("frm_gear_svg")),i.classList.add("frm-custom-field-group-layout"),cr(i),i)),r.append(function(){var e=h();return e.textContent=P("Break into rows","formidable"),jQuery(e).prepend(dr("frm_break_field_group_svg")),e.classList.add("frm-break-field-group"),cr(e),e}()),r}function cr(e,t){e.setAttribute("tabindex",0),e.setAttribute("role","button"),void 0!==t&&e.setAttribute("aria-label",t)}function dr(e){var t=document.getElementById(e).cloneNode(!0);return t.id="",t}function ur(e,t){var r,n=h();switch(n.classList.add("frm-row-layout-option"),cr(n,t),e){case 6:r="frm_half";break;case 5:r="frm_third";break;default:r=e>6?"frm_full":e%2==1?"frm_fourth":"frm_third"}return n.classList.add(r),n.setAttribute("layout-type",t),n.append(function(e,t){for(var r=yr(),n=0;n<e;++n){var o=h();o.classList.add(_r(e,t,n)),o.style.height="16px",o.style.background="#9EA9B8",o.style.borderRadius="1px",r.append(o)}return r}(e,t)),n}function fr(e,t){return mr(e)===mr(t)}function mr(e){var t;t=e.classList.contains("frm-row-layout-option")?jQuery(e).find(".frm_grid_container").children():be(jQuery(e));var r=[];return t.each(function(){r.push(Qr(Sr(this.classList)))}),r.join("-")}function _r(e,t,r){if("even"===t)return pr(e,r);if("middle"===t){if(3===e)return 1===r?"frm6":"frm3";if(5===e)return 2===r?"frm4":"frm2"}else{if("left"===t)return 0===r?vr(e):gr(e);if("right"===t)return r===e-1?vr(e):gr(e)}return"frm12"}function pr(e,t){return e>6?"frm1":[2,3,4,6].includes(e)?Ar(12/e):5===e&&void 0!==t?0===t?"frm4":"frm2":"frm12"}function gr(e){switch(e){case 2:case 3:return"frm3";case 4:case 5:return"frm2";case 6:return"frm1";default:return"frm12"}}function vr(e){switch(e){case 2:return"frm9";case 3:case 4:return"frm6";case 5:return"frm4";case 6:return"frm7";default:return"frm12"}}function yr(){var e=h();return e.classList.add("frm_grid_container"),e}function hr(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t=this.getAttribute("layout-type");we(be(jQuery(e)).first(),t),Br()}}function br(){var e=wr(),t=this.getAttribute("layout-type");we(be(e).first(),t),Dr()}function wr(){var e=jQuery(".frm-selected-field-group"),t=e.first();return e.not(t).each(function(){be(jQuery(this)).each(function(){var e=this.parentNode;be(t).last().after(this),jQuery(e).children("li.form-field").length||e.closest("li.frm_field_box").remove()})}),Wn(),we(be(t).first()),t}function jr(){null===this.closest(".frm-merge-fields-into-row")&&xr(be(jQuery(".frm-field-group-hover-target")))}function xr(e){var t=e.length,r=document.getElementById("frm_field_group_popup");r.innerHTML="";var n=h();n.style.padding="0 24px";var o=pr(5===t?6:t),i=h();if(i.style.padding="20px 0",i.classList.add("frm_grid_container"),5===t){var a=document.createElement("span");a.classList.add("frm1"),i.append(a)}var l=zr()>0&&Qr(pr(t));!1!==l&&l>=12&&(l=Math.floor(12/t));for(var s=0;s<t;++s){var c=document.createElement("input");c.type="text",c.classList.add(o),c.classList.add("frm-custom-grid-size-input"),c.value=!1!==l?l:Qr(Sr(e.get(s).classList)),i.append(c)}var d=h();d.classList.add("frm-builder-popup-heading"),d.textContent=P("Enter number of columns for each field","formidable");var u=h();u.classList.add("frm-builder-popup-subheading"),u.textContent=P("Layouts are based on a 12-column grid system","formidable"),n.append(d),n.append(u),n.append(i);var f=h();f.style.textAlign="right";var m,_=((m=kr()).classList.add("button-secondary","frm-button-secondary"),m);_.textContent=P("Cancel","formidable"),_.classList.add("frm-cancel-custom-field-group-layout"),_.style.marginRight="10px";var p=function(){var e=kr();return e.classList.add("button-primary","frm-button-primary"),e}();p.textContent=P("Save","formidable"),p.classList.add("frm-save-custom-field-group-layout"),f.append(_),f.append(p),n.append(f),r.append(n),setTimeout(function(){var e=r.querySelector("input.frm-custom-grid-size-input").focus();e&&e.focus()},0)}function Er(){xr(jQuery(".frm-selected-field-group li.form-field"))}function kr(){var e=document.createElement("a");return e.setAttribute("href","#"),e.classList.add("button"),e.style.textDecoration="none",e}function Qr(e){switch(e){case"frm_half":return 6;case"frm_third":return 4;case"frm_two_thirds":return 8;case"frm_fourth":return 3;case"frm_three_fourths":return 9;case"frm_sixth":return 2;default:return 0===e.indexOf("frm")?parseInt(e.substr(3)):12}}function Sr(e){for(var t=["frm_full","frm_half","frm_third","frm_fourth","frm_sixth","frm_two_thirds","frm_three_fourths","frm1","frm2","frm3","frm4","frm5","frm6","frm7","frm8","frm9","frm10","frm11","frm12"],r=0;r<t.length;++r){var n=t[r];if(e.contains(n))return n}return""}function Ar(e){return"frm".concat(e)}function Lr(){var e,t;e=document.querySelector(".frm-field-group-hover-target"),be(t=jQuery(e)).each(function(e){0!==e&&t.parent().after(ct(this)),function(e){we(e,"clear")}(jQuery(this))}),Br()}function Ir(){this.select()}function qr(){jQuery(document.getElementById("frm_field_group_popup")).replaceWith(sr(lr(this),this))}function Br(){var e=document.getElementById("frm_field_group_popup");if(e){var t=document.querySelector(".frm-has-open-field-group-popup");t&&(t.classList.remove("frm-has-open-field-group-popup"),e.parentNode.remove()),jQuery(document).off("click","#frm_builder_page",ar)}}function Cr(){var e=[];jQuery(document.getElementById("frm_field_group_popup").querySelectorAll(".frm_grid_container input")).each(function(){e.push(parseInt(this.value))});var t=jQuery(document.getElementById("frm_field_group_controls"));t.length&&"none"!==t.get(0).style.display?we(be(jQuery(document.querySelector(".frm-field-group-hover-target"))).first(),e):(we(be(wr()).first(),e),Dr()),Br()}function Nr(e){if(function(){var e=document.getElementById("frm-field-group-message");if(document.querySelectorAll(".edit_form_item:not(.edit_field_type_end_divider)").length<2)Tr(e);else if(e)!function(e){e&&(e.classList.remove("frm_hidden"),e.classList.add("frm-fadein-up-back"))}(e);else{e=h({id:"frm-field-group-message",className:"frm-flex-center frm-fadein-up-back",children:[b({id:"frm-field-group-message-dismiss",className:"frm-flex-center",child:j({href:"#frm_close_icon"})})]}),document.getElementById("post-body-content").append(e);var t,r=((t=document.createElement("span")).classList.add("frm-field-group-message-text","frm-flex-center"),t.innerHTML=R(frm_admin_js.holdShiftMsg,'<span class="frm-meta-tag frm-flex-center"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-shift" viewBox="0 0 16 16"><path d="M7.3 2a1 1 0 0 1 1.4 0l6.4 6.8a1 1 0 0 1-.8 1.7h-2.8v3a1 1 0 0 1-1 1h-5a1 1 0 0 1-1-1v-3H1.7a1 1 0 0 1-.8-1.7L7.3 2zm7 7.5L8 2.7 1.7 9.5h2.8a1 1 0 0 1 1 1v3h5v-3a1 1 0 0 1 1-1h2.8z"/></svg>',"</span>"),t);e.prepend(r),document.getElementById("frm-field-group-message-dismiss").addEventListener("click",function(){Tr(document.getElementById("frm-field-group-message"))})}}(),"ul"===e.originalEvent.target.nodeName.toLowerCase()){var t=document.querySelector(".frm-field-group-hover-target");if(t){var r=e.ctrlKey||e.metaKey,n=e.shiftKey,o=t.classList.contains("frm-selected-field-group"),i=function(){var e=jQuery(".frm-selected-field-group");if(e.length)return e;var t=Or();if(t){var r=t.closest("ul");if(r&&1===be(jQuery(r)).length)return r.classList.add("frm-selected-field-group"),jQuery(r)}return jQuery()}(),a=i.length;if(r||n){var l=Or();if(null===l||jQuery(l).siblings("li.form-field").length||(l.parentNode.classList.add("frm-selected-field-group"),++a),r){if(o)return--a,t.classList.remove("frm-selected-field-group"),void Fr(a);++a}else if(n&&!o){++a;var s=i.first();(s.parent().index()<jQuery(t.parentNode).index()?s.parent().nextUntil(t.parentNode):s.parent().prevUntil(t.parentNode)).each(function(){var e=jQuery(this).closest("li").find("ul.frm_sorting");e.hasClass("frm-selected-field-group")||(++a,e.addClass("frm-selected-field-group"))})}}else Dr(),a=1;t.classList.add("frm-selected-field-group"),Fr(a),document.querySelectorAll(".frm-selected-field-group").length<2||Tr(document.getElementById("frm-field-group-message")),jQuery(document).off("click",Dr),jQuery(document).on("click",Dr)}}}function Tr(e){e&&(e.classList.add("frm_hidden"),e.classList.remove("frm-fadein-up-back"))}function Or(){return document.getElementById("frm-show-fields").querySelector("li.form-field.selected")}function Fr(e){mt(!0),e>=2||1===e&&be(jQuery(document.querySelector(".frm-selected-field-group"))).length>1?function(){var e=document.getElementById("frm_field_multiselect_popup");if(e)return e.classList.toggle("frm-unmergable",!Pr()),e;(e=h()).id="frm_field_multiselect_popup",Pr()||e.classList.add("frm-unmergable");var t=h();t.classList.add("frm-merge-fields-into-row"),t.textContent=P("Merge into row","formidable");var r=document.createElement("a");r.style.marginLeft="5px",r.classList.add("frm_icon_font","frm_arrowdown6_icon"),r.setAttribute("href","#"),t.append(r),e.append(t);var n=h();n.classList.add("frm-multiselect-popup-separator"),e.append(n);var o=h();o.classList.add("frm-delete-field-groups"),o.append(dr("frm_trash_svg")),e.append(o),document.getElementById("post-body-content").append(e),jQuery(e).hide().fadeIn()}():Mr(),rt()}function Dr(e){if(void 0!==e){if(null!==e.originalEvent.target.closest("#frm-show-fields"))return;if(e.originalEvent.target.classList.contains("frm-merge-fields-into-row"))return;if(null!==e.originalEvent.target.closest(".frm-merge-fields-into-row"))return;if(e.originalEvent.target.classList.contains("frm-custom-field-group-layout"))return;if(e.originalEvent.target.classList.contains("frm-cancel-custom-field-group-layout"))return}jQuery(".frm-selected-field-group").removeClass("frm-selected-field-group"),jQuery(document).off("click",Dr),Mr()}function Mr(){var e=document.getElementById("frm_field_multiselect_popup");e&&e.remove()}function Pr(){var e=document.querySelectorAll(".frm-selected-field-group"),t=e.length;if(1===t)return!1;for(var r=0,n=0;n<t;++n){var o=e[n];if(null!==o.querySelector(".edit_field_type_break, .edit_field_type_hidden"))return!1;if((r+=be(jQuery(o)).length)>12)return!1}return!0}function Rr(e){if(null===e.originalEvent.target.closest("#frm_field_group_popup")&&!e.originalEvent.target.classList.contains("frm-custom-field-group-layout")){var t=sr(zr(),document.querySelector(".frm-selected-field-group").firstChild);this.append(t)}}function zr(){var e=0;return jQuery(document.querySelectorAll(".frm-selected-field-group")).each(function(){e+=be(jQuery(this)).length}),e}function Hr(){var e,t=(e=[],jQuery(".frm-selected-field-group > li.form-field").each(function(){e.push(this.dataset.fid)}),e),r=function(e){return function(t){t.preventDefault(),function(e){e.forEach(function(e){Ur(e)})}(e)}}(t),n=document.getElementById("frm_field_multiselect_popup");n&&n.remove(),this.setAttribute("data-frmverify",er(t.length)),V(this);var o=document.getElementById("frm-confirmed-click");null==o||o.removeAttribute("data-deletefield"),jQuery(o).on("click",r),jQuery("#frm_confirm_modal").one("dialogclose",function(){jQuery(o).off("click",r)})}function Gr(){Ur(this.getAttribute("data-deletefield"))}function Ur(e){var t=jQuery("#frm_field_id_".concat(e));Wr(e),t.hasClass("edit_field_type_divider")&&t.find("li.frm_field_box[data-fid]").each(function(){Wr(this.getAttribute("data-fid"))}),$n()}function Wr(e){jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_delete_field",field_id:e,nonce:frmGlobal.nonce},success:function(){var t,r,n,o=jQuery(document.getElementById("frm_field_id_".concat(e))),i=jQuery("#frm-single-settings-".concat(e));i.is(":visible")&&(null===(t=document.querySelector(".frm-settings-panel .frm-tabs-navs ul > li:first-child"))||void 0===t||t.click(),document.querySelector("#frm-options-panel .frm-single-settings").classList.remove("frm_hidden")),function(e){var t=e[0].querySelectorAll(".frm-inline-modal[data-fills]");t.length&&t.forEach(function(e){e.classList.add("frm_hidden"),e.removeAttribute("data-fills"),e.closest("form").append(e)})}(i),i.remove(),o.fadeOut("slow",function(){var e,t=o.closest(".start_divider"),r=o.data("type"),n=o.siblings("li.form-field");if(n.length||(o.is(".edit_field_type_end_divider")?n.length=o.closest("li.form-field").siblings():e=o.closest("ul.frm_sorting").parent()),o.remove(),"break"===r?on():"product"===r&&(Ke(),Et()),n.length?we(n.first()):e.remove(),0===jQuery("#frm-show-fields li").length||function(){if(I.get(0).childElementCount>1)return!1;var e=I.get(0).firstElementChild.firstElementChild.querySelectorAll("li.frm_field_box");return!(e.length>1)&&e[0].classList.contains("edit_field_type_submit")}()){var i=document.getElementById("frm_form_editor_container");i.classList.remove("frm-has-fields"),i.classList.add("frm-empty-fields")}else t.length&&Vn(t);Y()}),o.length&&(r=o.data("type"),(n=document.getElementById(r))&&n.dataset.limit&&$r(r)-1<n.dataset.limit&&n.classList.remove("frm_at_limit"),wp.hooks.doAction("frm_after_delete_field",o[0]))}})}function $r(e){return document.getElementById("frm-show-fields").querySelectorAll('li.form-field[data-ftype="'.concat(e,'"]')).length}function Vr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=T,r=document.getElementById("frm_logic_row_".concat(e)).querySelectorAll(".frm_logic_row");return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_logic_row",form_id:t,field_id:e,nonce:frmGlobal.nonce,meta_name:Kr(r,"frm_logic_".concat(e,"_")),fields:jt()},success:function(t){jQuery(document.getElementById("logic_".concat(e))).fadeOut("fast",function(){var r=document.getElementById("frm_logic_row_".concat(e));r.insertAdjacentHTML("beforeend",t);var n=r.querySelector(".frm_logic_row:last-child .frm-logic-rule-text");n&&(n.textContent=r.dataset.ruleText);var o=r.closest(".frm_logic_rows");o.style.height="auto",jQuery(o).fadeIn("fast")})}}),!1}function Kr(e,t,r){return e.length?parseInt(e[e.length-1].id.replace(t,""),10)+1:void 0!==r?r:0}function Jr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=T,r=document.getElementById("frm_watch_lookup_block_".concat(e)).children;return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_watch_lookup_row",form_id:t,field_id:e,row_key:Kr(r,"frm_watch_lookup_".concat(e,"_")),nonce:frmGlobal.nonce},success:function(t){var r,n=jQuery(document.getElementById("frm_watch_lookup_block_".concat(e)));n.append(t),n.fadeIn("slow"),null===(r=document.getElementById("frm_watch_lookup_label_".concat(e)))||void 0===r||r.classList.remove("frm-force-hidden")}}),!1}function Xr(e){var t,r,n=jQuery(e).closest(".frm-single-settings").attr("data-fid"),o=jQuery(e).closest("ul").get(0).querySelectorAll(".field_".concat(n,"_option"));for(t in o)if(Object.hasOwn(o,t)&&(r=o[t]).id!==e.id&&r.value===e.value&&"true"!==r.getAttribute("data-duplicate"))return!0;return!1}function Yr(){var e,t;null===this.getAttribute("data-value-on-load")&&(this.setAttribute("data-value-on-load",this.value),t=jQuery(this).closest(".frm-single-settings").attr("data-fid"),(e=document.createElement("input")).value=this.value,e.setAttribute("type","hidden"),e.setAttribute("name","optionmap[".concat(t,"][").concat(this.value,"]")),this.parentNode.append(e),void 0===F[t]&&(F[t]={}),F[t][this.value]=e),"true"===this.getAttribute("data-duplicate")&&(this.removeAttribute("data-duplicate"),Xr(this))?this.setAttribute("data-value-on-focus",this.getAttribute("data-value-on-load")):""===this.value&&f.new_option===this.getAttribute("data-value-on-focus")||this.setAttribute("data-value-on-focus",this.value)}function Zr(e){var t,r=e.closest(".frm_single_option");return e.parentElement.classList.contains("frm_single_option")?{newValue:r.querySelector('.frm_option_key input[type="text"]').value,newLabel:t=e.value}:(t=r.querySelector('input[type="text"]').value,{newValue:e.value,newLabel:t})}function en(){var e,t,r=function(e){var t=function(e){var t,r,n=null!==(t=null===(r=e.closest(".frm-single-settings").querySelector(".frm_toggle_sep_values"))||void 0===r?void 0:r.checked)&&void 0!==t&&t,o=e.closest(".frm_single_option");return n&&e.parentElement.classList.contains("frm_single_option")?{oldValue:o.querySelector('.frm_option_key input[type="text"]').getAttribute("data-value-on-focus"),oldLabel:e.getAttribute("data-value-on-focus")}:{oldValue:e.getAttribute("data-value-on-focus"),oldLabel:o.querySelector('input[type="text"]').getAttribute("data-value-on-focus")}}(e),r=t.oldValue,n=t.oldLabel,o=Zr(e);return{oldValue:r,oldLabel:n,newValue:o.newValue,newLabel:o.newLabel}}(this),n=r.oldValue,o=r.oldLabel,i=r.newValue,a=r.newLabel;if(n!==i||o!==a){var l=this.closest(".frm-single-settings"),s=l.getAttribute("data-fid"),c=this.getAttribute("data-value-on-load");if(Xr(this))return this.setAttribute("data-duplicate","true"),void(void 0!==F[s]&&void 0!==F[s][c]&&(F[s][c].value=c));void 0!==F[s]&&void 0!==F[s][c]&&(F[s][c].value=i);for(var d=[],u=W.querySelectorAll(".frm_logic_row"),f=u.length,m=0;m<f;m++){var _=u[m];if(_.querySelector(".frm_logic_field_opts").value===s){var p,g=_.id.split("_")[2],v=_.querySelector('select[name="field_options[hide_opt_'.concat(g,'][]"]')),y=void 0,h=void 0;(y=""===n?[]:v.querySelectorAll('option[value="'.concat(n,'"]'))).length||(y=v.querySelectorAll('option[value="'.concat(i,'"]'))).length||(null!==(p=l.querySelector(".frm_toggle_sep_values"))&&void 0!==p&&p.checked||(h=tn(v,n)),h||(h=document.createElement("option"),v.append(h))),y.length&&(h=y[y.length-1]),h.setAttribute("value",i),h.textContent=a,d.includes(g)||d.push(g)}}for(e in d)Object.hasOwn(d,e)&&(t=d[e],Qo(document.getElementById("frm-single-settings-".concat(t))))}}function tn(e,t){for(var r=e.options,n=0;n<r.length;n++){var o=r[n];if(t===o.textContent)return o}return null}function rn(){var e=this.id.replace("get_values_form_",""),t=document.getElementById("get_values_field_".concat(e)),r=this.getAttribute("data-fieldtype");if(""===this.value)t.options.length=1;else{var n=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_options_for_get_values_field",form_id:n,field_type:r,nonce:frmGlobal.nonce},success:function(e){t.innerHTML=e}})}}function nn(){var e,t,r=this.name.replace("field_options[data_type_","").replace("]","");(e=document.getElementById("frm_add_watch_lookup_link_".concat(r)))&&(e=e.parentNode,"text"===this.value?(t=document.getElementById("frm_watch_lookup_block_".concat(r)))&&(t.innerHTML="",e.classList.add("frm_hidden"),e.previousElementSibling.style.display="none",e.previousElementSibling.previousElementSibling.style.display="none",e.previousElementSibling.previousElementSibling.previousElementSibling.style.display="none"):e.classList.remove("frm_hidden"),Ft(r,this.value))}function on(){var e,t,r=document.getElementsByClassName("frm-page-num");if(r.length>1)for(document.getElementById("frm-fake-page").style.display="block",e=0;e<r.length;e++)t=r[e].parentNode.parentNode.parentNode.classList,1===e?t.add("frm-first-page"):t.remove("frm-first-page"),r[e].textContent=e+1;else document.getElementById("frm-fake-page").style.display="none";wp.hooks.doAction("frm_renumber_page_breaks",r)}function an(){var e,t,r,n=jQuery(this).closest(".frm_field_box[data-ftype=break]");n.length?function(e){var t=ln(e.get(0).parentNode.closest("li.frm_field_box").nextElementSibling);sn(e,t)}(n):(e=document.getElementById("frm-fake-page"),t=document.getElementById("frm-show-fields").firstElementChild,r=ln(t),"break"!==t.getAttribute("data-ftype")&&sn(jQuery(e),r))}function ln(e){var t,r;if(t=jQuery(),null===e)return t;r=e;do{if(null!==r.querySelector(".edit_field_type_break"))break;t=t.add(jQuery(r)),r=r.nextElementSibling}while(null!==r);return t}function sn(e,t){var r,n=t.length,o=Math.min(n,3);if(e.hasClass("frm-page-collapsed"))for(e.removeClass("frm-page-collapsed"),t.removeClass("frm-is-collapsed"),r=0;r<o;r++)r===o-1?jQuery(t[r]).slideDown(150,function(){t.show()}):jQuery(t[r]).slideDown(150);else for(e.addClass("frm-page-collapsed"),t.addClass("frm-is-collapsed"),r=0;r<o;r++)r===o-1?jQuery(t[r]).slideUp(150,function(){t.css("cssText","display:none !important;")}):jQuery(t[r]).slideUp(150)}function cn(){this.parentNode.parentNode.parentNode.parentNode.classList.toggle("frm-section-collapsed")}function dn(){this.nextElementSibling&&(this.nextElementSibling.style.animation=""),this.classList.toggle("frm-collapsed");var e="true"===this.getAttribute("aria-expanded")||!1;this.setAttribute("aria-expanded",!e),un(this.nextElementSibling)}function un(e){if(e){var t=e.scrollHeight;t<=0||(t+=250,e.style.setProperty("--slide-height","".concat(t,"px")),e.style.setProperty("--slide-time","".concat(Math.ceil(.8*t),"ms")))}}function fn(){if(this.id){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0],t=this.id.replace("field_label_",""),r=document.getElementById("field_options_type_".concat(t)),n=r.value;void 0!==e&&(n=function(e){return"divider"===e?e="section":"range"===e?e="slider":"data"===e?e="dynamic":"form"===e&&(e="embed form"),e}(n="SELECT"===r.tagName?r.options[r.selectedIndex].text.toLowerCase():n.replace("_"," ")),setTimeout(function(){e.value.toLowerCase()===n?e.select():e.focus()},50))}}function mn(){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0];void 0!==e&&setTimeout(function(){e.focus(),_n(e)},50)}function _n(e){var t=e.closest(".frm-collapse-me");null!==t&&t.previousElementSibling.classList.remove("frm-collapsed")}function pn(e){var t,r,n=e.target.classList;if(!n.contains("frm-collapse-page")&&!n.contains("frm-sub-label")&&null===e.target.closest(".dropdown")){if(null!==this.closest(".start_divider")&&e.stopPropagation(),this.classList.contains("edit_field_type_divider")){var o=e.originalEvent.target.closest("ul.frm_sorting");if(null!==o&&(o.classList.contains("edit_field_type_divider")||o.parentNode.parentNode.classList.contains("start_divider")))return}t=this,r=jQuery(t),t.className.includes("selected")||t.className.includes("edit_field_type_end_divider")&&r.closest(".edit_field_type_divider").hasClass("no_repeat_section")||(_t(),r.addClass("selected"),function(e){var t,r,n=e.getAttribute("data-fid"),o=e.getAttribute("data-type"),i=document.querySelectorAll(".frm-single-settings:not(.frm_hidden)");for(r=0;r<i.length;r++)i[r].classList.add("frm_hidden");var a=document.getElementById("frm-single-settings-".concat(n));Qo(a),o&&"quantity"===o&&xt(jQuery(a).find(".frmjs_prod_field_opt")[0]),null===(t=document.querySelector(".frm-settings-panel.frm-scrollbar-wrapper"))||void 0===t||t.scrollTo({top:0,behavior:"instant"}),a.classList.remove("frm_hidden"),a.querySelectorAll("h3:not(.frm-collapsed) + .frm-collapse-me").forEach(function(e){return e.style.animation="none"}),document.getElementById("frm-options-panel-tab").click();var l=a.querySelector(".wp-editor-area");l&&frmDom.wysiwyg.init(l,{setupCallback:ko}),wp.hooks.doAction("frmShowedFieldSettings",e,a),function(e,t,r){var n;if(function(e){return wp.hooks.applyFilters("frm_fields_with_shortcode_popup",["html"]).includes(e)}(e)){var o="#frm-single-settings-".concat(t);if(!document.querySelector("".concat(o," .frm-show-box"))){null===(n=r.querySelector(".wp-editor-container"))||void 0===n||n.classList.add("frm_has_shortcodes");var i=function(){return frmDom.svg({href:"#frm_more_horiz_solid_icon",classList:["frm-show-box"]})};document.querySelectorAll("".concat(o," .frm_has_shortcodes textarea")).forEach(function(e){var t=b({className:"frm-with-right-icon"});e.parentNode.insertBefore(t,e),t.append(i()),t.append(e)})}}}(o,n,a)}(t))}}function gn(e){var t=e.target;if("custom"===t.value){var r=t.dataset.fieldId,n=document.getElementById("frm-field-format-custom-".concat(r)).querySelector(".frm_format_opt");"international"!==n.value&&"currency"!==n.value&&"number"!==n.value||n.setAttribute("value","")}setTimeout(function(){t.querySelectorAll("option").forEach(function(e){e.selected&&e.classList.contains("frm_show_upgrade")&&(t.value="none")})},0)}function vn(){var e=this.getAttribute("data-fid");_n(document.getElementById("field_options_field_key_".concat(e)))}function yn(){var e=jQuery(this).closest(".frm_field_box");e.find(".repeat_icon_links").removeClass("repeat_format repeat_formatboth repeat_formattext").addClass("repeat_format".concat(this.value)),"text"===this.value||"both"===this.value?(e.find(".frm_repeat_text").show(),e.find(".repeat_icon_links a").addClass("frm_button")):(e.find(".frm_repeat_text").hide(),e.find(".repeat_icon_links a").removeClass("frm_button"))}function hn(){var e=this.value;""!==e&&(e<2||e>200)&&(K(f.repeat_limit_min),this.value="")}function bn(){var e=this.value;""!==e&&(e<1||e>200)&&(K(f.checkbox_limit),this.value="")}function wn(e,t){jQuery(e).closest(".frm_field_box").find(".frm_".concat(t,"_form_row .frm_repeat_label")).text(e.value)}function jn(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=this.value,r=document.getElementById("frm_show_selected_fields_".concat(e)),n=document.getElementById("frm_show_selected_forms_".concat(e));jQuery(n).find("select").val(""),"form"===t?(n.style.display="inline",function(e){if(null!==e)for(;e.firstChild;)e.firstChild.remove()}(r)):(r.style.display="none",n.style.display="none",Un(t,e))}function xn(){var e=En(this);if(e){var t=jQuery(this).closest(".frm_single_option");!function(e,t,r){var n=r.data("optkey"),o=Dn(e),i=jQuery('label[for="field_'.concat(t,"-").concat(n,'"]')),a="field_options[options_".concat(e,"][").concat(n,"]"),l=jQuery('input[name="'.concat(a,'[label]"]'));if(i.length<1)return Qn(e),void(r.find('input[name^="default_value_"]').is(":checked")&&l.length>0&&jQuery('select[name^="item_meta['.concat(e,']"]')).val(l.val()));var s,c=i.children("input");if(s=l.length<1?(l=jQuery('input[name="'.concat(a,'"]'))).val():o?jQuery('input[name="'.concat(a,'[value]"]')).val():l.val(),!(l.length<1)){var d=i[0].childNodes;if(Mn(e)){var u=function(e,t,r){var n,o=e.find("img");o&&(n=o.attr("src"));var i=Pn(t);return On(r.val(),i,n)}(r,e,l),f=i.find(".frm_image_option_container");f.length>0?f.replaceWith(u):(d[d.length-1].nodeValue="",i.append(u))}else{var m=!1;d.forEach(function(t,r){if(!1===m)"INPUT"===t.tagName&&(m=r);else if(r===m+1){var n="";!function(e){var t=document.getElementsByName("field_options[image_options_".concat(e,"]")),r=Array.from(t).find(function(e){return e.checked&&"buttons"===e.value});return void 0!==r}(e)?t.nodeValue=" ".concat(l.val()):(n=h({className:"frm_label_button_container",text:" ".concat(l.val())}),i[0].replaceChild(n,t))}else t.remove()})}c.val(s),defaultVal=r.find('input[name^="default_value_"]'),c.prop("checked",!!defaultVal.is(":checked"))}}(e.fieldId,e.fieldKey,t)}}function En(e){var t=jQuery(e).closest(".frm_sortable_field_opts");return!!t.length&&{fieldId:t.attr("id").replace("frm_field_","").replace("_opts",""),fieldKey:t.data("key")}}function kn(e){var t,r=document.getElementById("field_options_image_size_".concat(e)),n="";return r&&""!==(t=r.value)&&(n=t),n}function Qn(e){var t=jQuery('[name^="item_meta['.concat(e,']"]'));if(!(t.length<1)){var r={fieldId:e,metaInput:t[0]};if(!1===wp.hooks.applyFilters("frm_custom_reset_displayed_opts",!1,r)){if(t.is("select")){var n=document.getElementById("frm_placeholder_".concat(e));n&&""!==n.value?qn(t[0],{sourceID:e,placeholder:n.value}):qn(t[0],{sourceID:e})}else{var o=Cn(e),i=jQuery("#field_".concat(e,"_inner_container > .frm_form_fields")),a=Mn(e),l=a?kn(e):"",s=a?"frm_image_option frm_image_".concat(l," "):"";i.html("");for(var c=En(jQuery("#frm_delete_field_".concat(e,"-000_container"))),d=aa(e),u="hidden"===t.attr("type")?t.data("field-type"):t.attr("type"),f=0;f<o.length;f++)i.append(In(u,o[f],e,c.fieldKey,d,s))}An(e)}else An(e)}}function Sn(e,t){var r=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('input[value="'.concat(t,'"]'));return r?Zr(r):{newValue:t,newLabel:t}}function An(e,t){for(var r=W.querySelectorAll(".frm_logic_row"),n=r.length,o=wp.hooks.applyFilters("frm_conditional_logic_field_options",function(e){var t=[],r=document.getElementById("frm_field_".concat(e,"_opts"));if(!r)return t;for(var n=r.querySelectorAll(".frm_single_option"),o=n.length,i=0;i<o;i++){var a=n[i];if(!a.classList.contains("frm_hidden")){var l=a.querySelector(".field_".concat(e,"_option"));t.push(l.value)}}return t}(e),{type:t,fieldId:e}),i=o.length,a=0;a<n;a++){var l=r[a];if(l.querySelector(".frm_logic_field_opts").value==e){for(var s=l.id.split("_")[2],c=l.querySelector('select[name="field_options[hide_opt_'.concat(s,'][]"]')),d=function(){var t,r=o[u],n=null===(t=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('.frm_option_key input[type="text"]'))||void 0===t?void 0:t.value;n||(n=r);var i=c.querySelector('option[value="'.concat(n,'"]')),a=Sn(e,r),l=a.newValue,s=a.newLabel,d=document.querySelectorAll("#frm_field_".concat(e,"_opts input[data-value-on-focus]")),f=Array.from(d).find(function(e){return e.value===r});if(f){var m=f.dataset.valueOnFocus;if(m&&c.querySelector('option[value="'.concat(m,'"]')))return 1}Ln(c,i,l,s)},u=i-1;u>=0;u--)d();var f=c.querySelector('option[value=""]');null!==f&&c.prepend(f)}}}function Ln(e,t,r,n){null!==t||e.querySelector('option[value="'.concat(r,'"]'))||((t=frmDom.tag("option",{text:n})).value=r),e.prepend(t)}function In(e,t,r,n,o,i){var a="",l=t.key.includes("other"),s="field_".concat(n,"-").concat(t.key),c="scale"===e?"radio":e,d='<input type="text" id="field_'.concat(n,"-").concat(t.key,'-otext" class="frm_other_input frm_pos_none" name="item_meta[other][').concat(r,"][").concat(t.key,']" value="" />');return this.getSingle=function(){return""!==(a=wp.hooks.applyFilters("frm_admin.build_single_option_template",a,{opt:t,type:e,fieldId:r,classes:i,id:s}))?a:'<div class="frm_'.concat(e," ").concat(e," ").concat(i,'" id="frm_').concat(e,"_").concat(r,"-").concat(t.key,'">\n\t\t\t\t\t<label for="').concat(s,'">\n\t\t\t\t\t\t<input type="').concat(c,'" name="item_meta[').concat(r,"]").concat("checkbox"===e?"[]":"",'" value="').concat(Tn(t.saved),'" id="').concat(s,'"').concat(o?' data-price="'.concat(t.price,'"'):"").concat(t.checked?' checked="checked"':"",">\n\t\t\t\t\t\t").concat(Tn(t.label),"\n\t\t\t\t\t</label>\n\t\t\t\t\t").concat(l?d:"","\n\t\t\t\t</div>")},this.getSingle()}function qn(e,t){if(e){var r=t.sourceID,n=t.placeholder,o=aa(r),i=t.other;!function(e){var t;if(void 0!==e.options)for(t=e.options.length-1;t>=0;t--)e.remove(t)}(e);for(var a=Cn(r,e.id.includes("frm_field_logic_opt")),l=void 0!==n,s=0;s<a.length;s++){var c=a[s].label,d=a[s].key.includes("other");if(l&&""!==c?Bn(e,n):l&&(c=n),l=!1,!d||i){var u=document.createElement("option");u.value=a[s].saved,u.innerHTML=Tn(c),o&&u.setAttribute("data-price",a[s].price),e.append(u)}}}}function Bn(e,t){var r=document.createElement("option"),n=e.firstChild;r.value="",r.innerHTML=t,null!==n?(n.before(r),e.selectedIndex=0):e.append(r)}function Cn(e){var t,r,n,o,i,a,l=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=[],c=jQuery('input[name^="field_options[options_'.concat(e,']"]')).filter('[name$="[label]"], [name*="[other_"]'),d=aa(e),u=Pn(e),f=Mn(e),m=Dn(e);for(t=0;t<c.length;t++)c[t].name.indexOf("[000]")>0||(o=r=c[t].value,i=c[t].name.replace("field_options[options_".concat(e,"]["),"").replace("[label]","").replace("]",""),m&&(n=c[t].name.replace("[label]","[value]"),r=jQuery('input[name="'.concat(n,'"]')).val(),l&&""===o&&(o=""!==r?r:frm_admin_js.no_label)),f&&(o=On(o,u,Nn(c[t]))),a={saved:r,label:o=frmAdminBuild.hooks.applyFilters("frm_choice_field_label",o,e,c[t],f),checked:Fn(c[t].id),key:i},d&&(n=c[t].name.replace("[label]","[price]"),a.price=jQuery('input[name="'.concat(n,'"]')).val()),s.push(a));return s}function Nn(e){var t=jQuery(e).siblings(".frm_image_preview_wrapper");if(!t.length)return"";var r=t.find("img");return r.length?r.attr("src"):""}function Tn(e){(e instanceof Element||e instanceof Document)&&(e=e.outerHTML);var t=jQuery.parseHTML(e).reduce(function(e,t){var r=frmDom.cleanNode(t);return"#text"===r.nodeName?e+r.textContent:e+r.outerHTML},"");return t!==e?Tn(t):t}function On(e,t,r){var n,o=e;o=Tn(o),r?n=x({src:r,alt:o}):(n=h({className:"frm_empty_url"})).innerHTML=f.image_placeholder_icon;var i=t?" frm_label_with_image":"",a=[n];if(t){var l=y("span",{className:"frm_text_label_for_image_inner"});l.innerHTML=o,a.push(y("span",{className:"frm_text_label_for_image",child:l}))}return y("span",{className:"frm_image_option_container".concat(i),children:a})}function Fn(e){var t=jQuery("#".concat(e));if(0===t.length)return!1;var r=t.siblings("input[type=checkbox]");return r.length&&r.prop("checked")}function Dn(e){return Rn("separate_value_".concat(e))}function Mn(e){for(var t=!1,r=document.getElementsByName("field_options[image_options_".concat(e,"]")),n=0;n<r.length;n++)r[n].checked&&(t="0"!==r[n].value);return frmAdminBuild.hooks.applyFilters("frm_choice_field_images_as_options",t,e)}function Pn(e){var t=!Rn("hide_image_text_".concat(e));return frmAdminBuild.hooks.applyFilters("frm_choice_field_showing_label_with_image",t,e)}function Rn(e){var t=document.getElementById(e);return!!t&&t.checked}function zn(e){var t=e.closest(".frm-single-settings"),r=t.getAttribute("data-fid"),n=t.querySelector('[name="field_options[separate_value_'.concat(r,']"]')).checked;if(!n||e.name.endsWith("[value]")){var o=document.getElementById("frm_field_".concat(r,"_opts"));Array.from(o.querySelectorAll('input[type="text"]')).filter(function(t){return t.id!==e.id&&n===t.name.endsWith("[value]")&&t.value===e.value}).length&&K(R(P('Duplicate option value "%s" detected',"formidable"),Tn(e.value)))}}function Hn(){var e=this.value;if(e){var t=this.parentNode.id.replace("frm_logic_","").split("_"),r=t[0],n=t[1],o=document.getElementById("frm_field_id_".concat(e)).getAttribute("data-ftype"),i=document.getElementById("frm_show_selected_values_".concat(r,"_").concat(n)),a="field_options[hide_opt_".concat(r,"][]"),l="frm_field_logic_opt_".concat(r),s=!1,c="select"===o||"checkbox"===o||"radio"===o,d="text"===o||"email"===o||"phone"===o||"url"===o||"number"===o;if(c&&document.getElementById("frm_has_hidden_options_".concat(e))&&(c=!1),c||d){var u=document.querySelector("#frm_logic_".concat(r,"_").concat(n,' [name="field_options[hide_field_cond_').concat(r,'][]"]')).value;i.innerHTML="";var f=c&&!["LIKE","not LIKE","LIKE%","%LIKE"].includes(u);f?s=document.createElement("select"):(s=document.createElement("input")).type="text",s.name=a,s.id="".concat(l,"_").concat(n),i.append(s),f&&qn(document.getElementById(s.id),{sourceID:e,placeholder:"",other:!0})}else{var m=this.getAttribute("data-type");frmGetFieldValues(e,r,n,m,void 0,function(){var e=new CustomEvent("frm_logic_options_loaded");e.frmData={valueFieldType:o,fieldID:r,metaKey:n},document.dispatchEvent(e)})}}}function Gn(){var e=this.value;e&&Un(e,jQuery(this).closest(".frm-single-settings").data("fid"))}function Un(e,t){e&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_field_selection",field_id:t,form_id:e,nonce:frmGlobal.nonce},success:function(e){var r=jQuery("#frm_show_selected_fields_".concat(t));r.toggleClass("frm6",!e.includes("frm-inline-message")),r.html(e).show()}})}function Wn(){var e=this;return this.initOnceInAllInstances=function(){void 0===Wn.prototype.orderFieldsObject&&(Wn.prototype.orderFieldsObject={},Wn.prototype.fieldSettingsForm=document.getElementById("frm-end-form-marker").closest("form"))},this.getFieldOrderInputById=function(e,t){var r,n=Wn.prototype.orderFieldsObject,o=Wn.prototype.fieldSettingsForm;return void 0===n[e]?((r=o.querySelector('input[name="field_options[field_order_'.concat(e,']"]')))||(r=t.querySelector('input[name="field_options[field_order_'.concat(e,']"]'))),n[e]=r,r):n[e]},this.initOnceInAllInstances(),on(),function(){var t,r,n,o,i,a,l=new Qo,s=jQuery("li.frm_field_box",jQuery("#frm-show-fields"));for(i=0;i<s.length;i++)t=s[i].getAttribute("data-fid"),(n=(r=e.getFieldOrderInputById(t,s[i]))?Object.assign({},r.value)[0]:null)!=(o=i+1)&&null!==n&&(r.value=o,a=s[i].querySelector("#frm-single-settings-".concat(t)),l.append(a),ci());l.moveFields()}()}function $n(){document.querySelectorAll(".start_divider").forEach(function(e){Vn(jQuery(e))})}function Vn(e){if(e.length){for(var t=e.find("ul.frm_sorting"),r=!1,n=t.length,o=0;o<n;++o)if(0!==be(jQuery(t.get(o))).length){r=!0;break}e.parent().children(".frm_no_section_fields").get(0).classList.toggle("frm_block",!r)}}function Kn(){var e=jQuery(this).data("slidedown"),t=jQuery(document.getElementById(e));return t.is(":hidden")&&(t.slideDown("fast"),this.style.display="none"),!1}function Jn(){var e=jQuery(this).data("slideup"),t=jQuery(document.getElementById(e));return t.slideUp("fast"),t.siblings("a").show(),!1}function Xn(e,t){""===t.getAttribute("value")?Yn(jQuery(this)):function(e){var t=e.val();if(null===t)return e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!0),void Yn(e);var r=t.indexOf("");r>=0&&(t.splice(r,1),e.val(t),e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!1))}(jQuery(this))}function Yn(e){e.val(""),e.next(".btn-group").find('.multiselect-container input[value!=""]').prop("checked",!1)}function Zn(){jQuery(".frm-hide-empty").each(function(){0===jQuery(this).text().trim().length&&jQuery(this).remove()})}function eo(e){e.preventDefault(),function(e,t,r){var n=document.getElementById(e.getAttribute("data-open")),o=jQuery(e).closest("p,ul"),i=void 0!==t;if(o.hasClass("frm-open"))o.removeClass("frm-open"),n.classList.add("frm_hidden");else{if(i||(t=pi(e)),t){if(!i){var a=r.key;"Enter"!==a&&" "!==a&&t.focus()}o.after(n),n.setAttribute("data-fills",t.id.replace("-proxy-input","")),0===n.id.indexOf("frm-calc-box")&&yt(n,!0)}o.addClass("frm-open"),n.classList.remove("frm_hidden"),wp.hooks.doAction("frm_show_inline_modal",n,e)}}(this,void 0,e)}function to(e){e.preventDefault(),this.parentNode.classList.add("frm_hidden"),jQuery('.frm-open [data-open="'.concat(this.parentNode.id,'"]')).closest(".frm-open").removeClass("frm-open")}function ro(e){var t=e.target;t.closest(".frm-inline-modal.frm-modal-no-dismiss")||t.closest(".frm-show-inline-modal")||t.closest("#frm_adv_info")||t.closest(".frm-token-proxy-input")||document.querySelectorAll(".frm-inline-modal.frm-modal-no-dismiss:not(.frm_hidden)").forEach(function(e){e.classList.add("frm_hidden"),e.previousElementSibling.classList.remove("frm-open")})}function no(){var e,t=this.getAttribute("data-frmchange").split(",");for(e=0;e<t.length;e++)"updateOption"===t[e]?io(this):"updateDefault"===t[e]?oo(this):"checkUniqueOpt"===t[e]?zn(this):this.value=this.value[t[e]]()}function oo(e){var t=ao(e),r=t.getAttribute("data-optkey"),n=lo(t,r),o=t.querySelector('input[name="default_value_'.concat(n,'"]'));null!==o&&(o.value=e.value)}function io(e){var t,r=ao(e),n=r.getAttribute("data-optkey"),o=lo(r,n),i=document.getElementById("separate_value_".concat(o));i&&!1===i.checked&&((t=document.getElementById("field_key_".concat(o,"-").concat(n))).value=e.value,oo(t))}function ao(e){var t=e.parentNode;return"LI"!==t.tagName&&(t=t.parentNode),t}function lo(e,t){return e.id.replace("frm_delete_field_","").replace("-".concat(t,"_container"),"")}function so(){var e=this;if(!mo()){go(this);var t=jQuery(q),r=JSON.stringify(t.serializeArray());jQuery(document.getElementById("frm_compact_fields")).val(r),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_save_form",frm_compact_fields:r,nonce:frmGlobal.nonce},success:function(t){var r;(r=e).classList.remove("frm_loading_form"),r.classList.remove("frm_loading_button"),jQuery('.frm-single-settings ul input[type="text"][name^="field_options[options_"]').filter("[data-value-on-load]").removeAttr("data-value-on-load"),jQuery('input[type="hidden"][name^=optionmap]').remove(),N=0,r.setAttribute("aria-busy","false"),setTimeout(function(){jQuery(".frm_updated_message").fadeOut("slow",function(){this.remove()})},5e3);var n,o=document.getElementById("post-body-content"),i=document.createElement("div");i.setAttribute("class","frm_updated_message"),i.innerHTML=t,o.insertBefore(i,o.firstChild),(n=document.getElementById("frm_submit_side_top")).hasAttribute("data-new-addon-installed")&&"true"===n.getAttribute("data-new-addon-installed")&&(n.removeAttribute("data-new-addon-installed"),window.location.reload())},error:function(){co(document.getElementById("frm_js_build_form"))}})}}function co(e){var t=e.ownerDocument.createElement("input");t.style.display="none",t.type="submit",e.append(t),t.click(),t.remove()}function uo(e){jQuery(e).trigger("change")}function fo(){if(!mo()){go(this);var e=jQuery(q);jQuery(document.getElementById("frm_compact_fields")).val(JSON.stringify(e.serializeArray())),co(document.getElementById("frm_js_build_form"))}}function mo(){if((t=document.getElementById("frm_form_name"))&&""!==t.value.trim()||"true"!==U.get("new_template")||(null===(e=document.querySelector("#frm_top_bar #frm_bs_dropdown .frm_bstooltip"))||void 0===e?void 0:e.textContent.trim())!==frm_admin_js.noTitleText)return!1;var e,t,r=ea("#frm-form-templates-modal","440px");return!!r&&(_i(r,"72px"),r.dialog("open"),!0)}function _o(){var e=document.getElementById("frm-save-form-name-button"),t=document.getElementById("frm_new_form_name_input");E(e,po),t.addEventListener("keydown",function(e){"Enter"===e.key&&po(e)})}var po=function(e){var t=document.getElementById("frm_new_form_name_input").value.trim(),r=new FormData;r.append("form_id",U.get("id")),r.append("form_name",t),k("rename_form",r).then(function(e){U.delete("new_template"),G.search=U.toString(),history.replaceState({},"",G.toString()),null!==document.getElementById("frm_notification_settings")&&(document.getElementById("frm_form_name").value=t,document.getElementById("frm_form_key").value=e.form_key),jQuery("#frm-publishing").find(".frm_button_submit").trigger("click")})};function go(e){var t,r;ra(),jQuery("form.inplace_form").length&&jQuery(".inplace_save, .postbox").trigger("click"),e.classList.contains("frm_button_submit")?e.classList.add("frm_loading_form"):e.classList.add("frm_loading_button"),e.setAttribute("aria-busy","true"),t=document.querySelectorAll(".frm_format_dropdown, .frm_phone_type_dropdown"),r={none:"",international:"international",currency:"currency",number:"number"},t.forEach(function(e){var t=e.value;t in r&&(document.getElementById("frm_format_".concat(e.dataset.fieldId)).value=r[t])})}function vo(e){var t,r=null!==(t=e.target.dataset)&&void 0!==t&&t.modalTitle?e.target:e.target.closest("[data-modal-title]");if(r){var n=r.dataset,o=n.modalTitle,i=n.modalContent;o&&i&&(e.preventDefault(),frmDom.modal.maybeCreateModal("frmBasicModal",{title:o,content:h({className:"inside",child:b(i)})}))}}function yo(e){var t,n,i,s,u,f,m,_,p=e.dataset.upgrade,g=e.getAttribute("href").replace("#",""),v=document.querySelector(".frm_".concat(g))||document.querySelector(".".concat(g));if(v&&!v.querySelector(".frm-upgrade-message")){var y=v.querySelector("h2");y.style.borderBottom="none",y.textContent=R(P("%s are not installed","formidable"),p),v.classList.add("frmcenter");var b=document.getElementById("frm_upgrade_modal");A("frm-upgrade-message"),A("frm-oneclick"),A("frm-addon-status");var w=b.querySelector(".frm-upgrade-link");if(w){var j,E,k=w.closest(".frm-upgrade-modal-actions"),Q=(E=k?(k=k.cloneNode(!0)).querySelector(".frm-upgrade-link"):w.cloneNode(!0)).querySelector(".license-level");Q&&(Q.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(e)),e.dataset.gradientUpgrade&&E.classList.add("frm-gradient"),v.append(k||E),null!==(j=w.nextElementSibling)&&void 0!==j&&j.querySelector(".frm-link-secondary")&&v.append(w.nextElementSibling.cloneNode(!0)),A("frm-oneclick-button")}var S=e.dataset.message;void 0===S&&(S=e.dataset.upgrade),function(e,t,n){r(4260).addOneClick(e,"tab",n)}(e,0,S),e.dataset.upsellImages?v.append((t=e.dataset.upsellImages,n=p,s="".concat(frmGlobal.url,"/images/upsell/"),u=l(i=t.split(",").map(function(e){return x({src:s+e.trim(),alt:n})}))||o(i)||c(i)||a(),f=u[0],m=d(u).slice(1),_=[f],m.length&&_.push(h({className:"frm-upsell-images-row",children:m})),h({className:"frm-upsell-images",children:_}))):e.dataset.screenshot&&v.append(function(e){var t="".concat(frmGlobal.url,"/images/screenshots/");return h({className:"frm-settings-screenshot-wrapper",children:[function(){var e=["#ED8181","#EDE06A","#80BE30"].map(function(e){var t=h({className:"frm-minmax-icon"});return t.style.backgroundColor=e,t});return e.push(x({src:"".concat(frmGlobal.url,"/images/tab.svg")})),h({className:"frm-settings-screenshot-toolbar",children:e})}(),h({child:x({src:t+e})})]})}(e.dataset.screenshot))}function A(e){v.append(b.querySelector(".".concat(e)).cloneNode(!0))}}function ho(e){void 0===e&&(e=""),function(e){var t,r=jQuery("".concat(e," :not(.frm_has_shortcodes) .frm_not_email_message, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_to, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_subject"));for(t=0;t<r.length;t++)r[t].parentNode.classList.add("frm_has_shortcodes")}(e),jQuery("".concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) input,").concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) textarea")).wrap('<span class="frm-with-right-icon"></span>').before('<svg class="frmsvg frm-show-box"><use href="#frm_more_horiz_solid_icon"/></svg>')}function bo(){var e="success";"options[edit_action]"===this.name&&(e="edit");var t=jQuery(this).val();jQuery(".".concat(e,"_action_box")).hide(),"redirect"===t?jQuery(".".concat(e,"_action_redirect_box.").concat(e,"_action_box")).fadeIn("slow"):"page"===t?jQuery(".".concat(e,"_action_page_box.").concat(e,"_action_box")).fadeIn("slow"):jQuery(".".concat(e,"_action_message_box.").concat(e,"_action_box")).fadeIn("slow")}function wo(e){var t,r,n;if(e.stopPropagation(),!function(e){var t=jQuery(e),r=t.closest(".frm_form_action_settings"),n=r.find(".widget-inside");if(n.find("p, div, table").length)return!1;var o=r.find(".widget-top");return o.one("frm-action-loaded",function(){t.trigger("click"),r.removeClass("open"),n.hide()}),o.trigger("click"),!0}(e.target)){var o=e.target.closest(".frm_form_action_settings"),i=o.querySelectorAll(".wp-editor-area");i.length&&i.forEach(function(e){tinymce.EditorManager.execCommand("mceRemoveEditor",!0,e.id)});var a=jQuery(o).clone(),l=a.attr("id").replace("frm_form_action_",""),s=jo(l),c=null===(t=o.querySelector(".frm_action_name"))||void 0===t?void 0:t.value,d=function(e,t){for(var r=new Set(t),n=e,o=2;r.has(n);)n="".concat(e," (").concat(o,")"),o++;return n}((null!==(r=null===(n=o.querySelector(".widget-title h4 span:not(.frm-border-icon)"))||void 0===n?void 0:n.textContent.trim())&&void 0!==r?r:"").replace(/ \(\d+\)$/,""),xo(c));a[0].querySelector(".widget-title h4 span:not(.frm-border-icon)").textContent=d,a[0].querySelector('input[name$="['.concat(l,'][post_title]"]')).value=d,a.find(".frm_action_id, .frm-btn-group").remove(),a.find('input[name$="['.concat(l,'][ID]"]')).val(""),a.find(".widget-inside").hide(),a.find("input[type=text], textarea, input[type=number]").prop("defaultValue",function(){return this.value}),a.find("input[type=checkbox], input[type=radio]").prop("defaultChecked",function(){return this.checked});var u=new RegExp("\\[".concat(l,"\\]"),"g"),f=new RegExp("_".concat(l,'"'),"g"),m=new RegExp("_".concat(l," "),"g"),_=new RegExp("-".concat(l,'"'),"g"),p=new RegExp('"'.concat(l,'"'),"g"),g=a.html().replace(u,"[".concat(s,"]")).replace(f,"_".concat(s,'"'));g=(g=g.replace(m,"_".concat(s," "))).replace(_,"-".concat(s,'"')).replace(p,'"'.concat(s,'"'));var v=h({id:"frm_form_action_".concat(s),className:a.get(0).className});v.setAttribute("data-actionkey",s),v.innerHTML=g,v.querySelectorAll(".wp-editor-wrap, .wp-editor-wrap *").forEach(function(e){"string"==typeof e.className&&(e.className=e.className.replace(l,s)),e.id=e.id.replace(l,s)}),v.classList.remove("open"),document.getElementById("frm_notification_settings").append(v),i.length&&(i.forEach(function(e){frmDom.wysiwyg.init(e)}),v.querySelectorAll(".wp-editor-area").forEach(function(e){frmDom.wysiwyg.init(e)})),v.classList.contains("frm_single_on_submit_settings")&&v.querySelector("input.frm-page-search")&&Pi(v),Bi(),wp.hooks.doAction("frm_after_duplicate_action",v)}}function jo(e){var t=parseInt(e,10)+11;return document.getElementById("frm_form_action_".concat(t))&&(t=jo(++t)),t}function xo(e){return Array.from(document.querySelectorAll(".frm_single_".concat(e,"_settings .widget-title h4 span:not(.frm-border-icon)")),function(e){return e.textContent.trim()})}function Eo(){var e,t=jQuery(this).data("actiontype");if(!qo(t)){var r=(e=Kr(document.querySelectorAll(".frm_form_action_settings"),"frm_form_action_"),void 0!==document.getElementById("frm_form_action_".concat(e))&&(e+=100),D>=e&&(e=D+1),D=e,e),n=T,o=xo(t),i=document.createElement("div");i.classList.add("frm_single_".concat(t,"_settings"));var a=document.getElementById("frm_notification_settings");a.append(i),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_action",type:t,list_id:r,form_id:n,nonce:frmGlobal.nonce,existing_titles:o},success:function(e){var n;ci(),i.remove(),null===(n=document.querySelector(".frm-no-actions-message"))||void 0===n||n.classList.add("frm_hidden"),document.querySelectorAll(".frm_form_action_settings.open").forEach(function(e){return e.classList.remove("open")});var o=h();o.innerHTML=e;var l=o.querySelector(".widget-top");Array.from(o.children).forEach(function(e){return a.append(e)}),jQuery(".frm_form_action_settings").fadeIn("slow");var s,c,d=document.getElementById("frm_form_action_".concat(r));d.classList.add("open"),document.getElementById("post-body-content").scroll({top:d.offsetTop+10,left:0,behavior:"smooth"}),Io(t),(c=["stripe","square","paypal"]).includes(s=t)&&c.forEach(function(e){e!==s&&Io(e)}),ho("#frm_form_action_".concat(r)),Bi(),Pi(d),l&&jQuery(l).trigger("frm-action-loaded"),frmAdminBuild.hooks.doAction("frm_added_form_action",d)}})}}function ko(e){e.on("Change",function(){!function(e){(function(){var e=document.querySelector(".frm-single-settings:not(.frm_hidden)");if(!e)return!1;var t=e.querySelector(".wp-editor-wrap");return t&&t.classList.contains("tmce-active")})()&&!tinyMCE.activeEditor.isHidden()&&(e.targetElm.value=e.getContent(),jQuery(e.targetElm).trigger("change"))}(e)})}function Qo(e){var t=this;if(null!==e)return this.fragment=document.createDocumentFragment(),this.initOnceInAllInstances=function(){void 0===Qo.prototype.endMarker&&(Qo.prototype.endMarker=document.getElementById("frm-end-form-marker"))},this.append=function(e){var r=e?e.parentElement.classList:"";e&&(r.contains("frm_field_box")||r.contains("divider_section_only"))&&t.fragment.append(e)},this.moveFields=function(){q.insertBefore(t.fragment,Qo.prototype.endMarker)},this.initOnceInAllInstances(),void 0!==e?(this.append(e),void this.moveFields()):{append:this.append,moveFields:this.moveFields}}function So(){var e=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),t=this.getAttribute("data-emailrow");jQuery("#frm_form_action_".concat(e," .frm_").concat(t,"_row")).fadeIn("slow"),jQuery(this).fadeOut("slow")}function Ao(){var e=jQuery(this).closest(".frm_form_action_settings"),t=this.getAttribute("data-emailrow"),r=".frm_".concat(t,"_row"),n=".frm_".concat(t,"_button");jQuery(e).find(n).fadeIn("slow"),jQuery(e).find(r).fadeOut("slow",function(){jQuery(e).find("".concat(r," input")).val("")})}function Lo(){var e=jQuery(this).closest(".frm_form_action_settings"),t=".frm_from_to_match_row";e.find('input[name$="[post_content][from]"]').val()===e.find('input[name$="[post_content][email_to]"]').val()?jQuery(e).find(t).fadeIn("slow"):jQuery(e).find(t).fadeOut("slow")}function Io(e){var t,r,n=document.querySelectorAll(".frm_".concat(e,"_action"));qo(e)?(t=n,r=Bo(e)>0,t.forEach(function(e){e.classList.remove("frm_active_action"),e.classList.add("frm_inactive_action"),r&&e.classList.add("frm_already_used")})):n.forEach(function(e){e.querySelector(".frm_show_upgrade")||(e.classList.remove("frm_inactive_action","frm_already_used"),e.classList.add("frm_active_action"))})}function qo(e){var t=function(e){return["paypal","stripe","square"].includes(e)&&(e="payment"),jQuery(".frm_single_".concat(e,"_settings")).length}(e)>=Bo(e),r={type:e};return wp.hooks.applyFilters("frm_action_at_limit",t,r)}function Bo(e){return parseInt(jQuery(".frm_".concat(e,"_action")).data("limit"),10)}function Co(){var e=f.only_one_action,t=this.dataset.limit,r=this.dataset.actiontype;r&&["paypal","stripe","square","payment"].includes(r)&&(e="stripe"===r?f.only_one_stripe_action:f.only_one_payment_action),void 0!==t&&((t=parseInt(t))>1?e=e.replace(1,t).trim():e+=" ".concat(f.edit_action_text)),K(e)}function No(e,t){var r=jQuery(t).closest(".frm_form_action_settings").find(".frm_action_name").val(),n=document.getElementById("form_id").value,o=document.getElementById("frm_logic_row_".concat(e)),i=Kr(o.querySelectorAll(".frm_logic_row"),"frm_logic_".concat(e,"_")),a=h({id:"frm_logic_".concat(e,"_").concat(i),className:"frm_logic_row frm_hidden"}),l=document.getElementById("logic_link_".concat(e)),s=l?o.closest(".frm_logic_rows"):null;o.append(a),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_logic_row",email_id:e,form_id:n,meta_name:i,type:r,nonce:frmGlobal.nonce},success:function(e){a.insertAdjacentHTML("beforebegin",e),a.remove();var t=o.querySelector(".frm_logic_row:last-child"),r=t?t.querySelector(".frm-logic-rule-text"):null;r&&(r.textContent=o.dataset.ruleText||""),l&&l.classList.add("frm_hidden"),s&&(s.classList.remove("frm_hidden"),s.style.display="")}})}function To(){return No(jQuery(this).data("emailkey"),this),!1}function Oo(){var e;if(this.checked){var t=this.getAttribute("data-emailkey");if(t&&null!==(e=this.dataset.toggleclass)&&void 0!==e&&e.startsWith("frm_logic_rows_")){var r=document.getElementById("frm_logic_row_".concat(t));r&&!r.querySelector(".frm_logic_row")&&No(t,this)}}}function Fo(){var e=jQuery("select.frm_single_post_field");e.css("border-color","");var t=this,r=jQuery(t).val();if(""===r||"checkbox"===r)return!1;e.each(function(){if(jQuery(this).val()===r&&this.name!==t.name)return this.style.borderColor="red",jQuery(t).val(""),K(f.field_already_used),!1})}function Do(){var e=jQuery(this).val();""===e?(jQuery(".frm_post_content_opt, select.frm_dyncontent_opt").hide().val(""),jQuery(".frm_dyncontent_opt").hide()):"post_content"===e?(jQuery(".frm_post_content_opt").show(),jQuery(".frm_dyncontent_opt").hide(),jQuery("select.frm_dyncontent_opt").val("")):(jQuery(".frm_post_content_opt").hide().val(""),jQuery("select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt").show())}function Mo(){var e=jQuery(this).val(),t=jQuery(document.getElementById("frm_dyncontent"));""===e||"new"===e?(t.val(""),jQuery(".frm_dyncontent_opt").show()):jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_display_get_content",id:e,nonce:frmGlobal.nonce},success:function(e){t.val(e),jQuery(".frm_dyncontent_opt").show()}})}function Po(){var e,t,r=document.getElementById("frm_posttax_rows").childNodes,n=document.querySelector(".frm_post_parent_field"),o=document.querySelector(".frm_post_menu_order_field"),i=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_replace_posttax_options",post_type:i,nonce:frmGlobal.nonce},success:function(n){for(var o=0;o<r.length;o++)"DIV"===r[o].tagName&&(e=r[o].getElementsByTagName("select")[0],(t=document.createElement("select")).innerHTML=n,t.className=e.className,t.name=e.name,r[o].replaceChild(t,e))}}),n&&Ro(n,i,"frm_get_post_parent_option",function(e,t){n.querySelector(".frm_post_parent_opt_wrapper").innerHTML=e.replaceAll("REPLACETHISNAME",t),Pi(n)}),o&&Ro(o,i,"frm_should_use_post_menu_order_option")}function Ro(e,t,r,n){var o=(e.querySelector(".frm_autocomplete_value_input")||e.querySelector("select")).getAttribute("name");jQuery.ajax({url:ajaxurl,method:"POST",data:{action:r,post_type:t,_wpnonce:frmGlobal.nonce},success:function(t){if("string"==typeof t){if("0"===t)return e.classList.add("frm_hidden"),void(e.value="");e.classList.remove("frm_hidden"),"function"==typeof n&&n(t,o)}else console.error(t)},error:function(e){return console.error(e)}})}function zo(){Go("tax",this)}function Ho(){Go("meta",this)}function Go(e,t){var r,n,o=jQuery('input[name="id"]').val(),i=jQuery(t).closest(".frm_form_action_settings"),a=i.data("actionkey"),l=i.find(".frm_post_type").val(),s=0,c=document.querySelectorAll(".frm_post".concat(e,"_row"));c.length&&(n=r=c[c.length-1].id.replace("frm_post".concat(e,"_"),""),s=!isNaN(parseFloat(n))&&isFinite(n)?1+parseInt(r,10):1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_post".concat(e,"_row"),form_id:o,meta_name:s,tax_key:s,post_type:l,action_key:a,nonce:frmGlobal.nonce},success:function(t){var r,n;if(jQuery(document.getElementById("frm_post".concat(e,"_rows"))).append(t),jQuery(".frm_add_post".concat(e,"_row.button")).hide(),"meta"===e)for(jQuery(".frm_name_value").show(),r=document.querySelectorAll(".frm_toggle_cf_opts"),n=0;n<r.length-1;++n)r[n].style.display="none";else"tax"===e&&jQuery(".frm_posttax_labels").show()}})}function Uo(){if(jQuery(this).closest(".frm_posttax_row").find(".frm_posttax_opt_list").length){jQuery(this).closest(".frm_posttax_row").find(".frm_posttax_opt_list").html('<div class="spinner frm_spinner" style="display:block"></div>');var e=jQuery(this).closest(".frm_form_action_settings").find('select[name$="[post_content][post_type]"]').val(),t=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),r=jQuery(this).closest(".frm_posttax_row").attr("id").replace("frm_posttax_",""),n=jQuery(this).val(),o=jQuery(document.getElementById("".concat(r,"_show_exclude"))).is(":checked")?1:0,i=jQuery('select[name$="[post_category]['.concat(r,'][field_id]"]')).val(),a=jQuery('input[name="id"]').val();jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_posttax_row",form_id:a,post_type:e,tax_key:r,action_key:t,meta_name:n,field_id:i,show_exclude:o,nonce:frmGlobal.nonce},success:function(e){jQuery(document.getElementById("frm_posttax_".concat(r))).replaceWith(e)}})}}function Wo(){var e=jQuery(this).closest(".frm_postmeta_row"),t=e.find(".frm_cancelnew"),r=e.find(".frm_enternew");return e.find("select.frm_cancelnew").is(":visible")?(t.hide(),r.show()):(t.show(),r.hide()),e.find("input.frm_enternew, select.frm_cancelnew").val(""),!1}function $o(){var e=jQuery(this),t=e.val();"checkbox"===e.attr("type")&&!1===this.checked&&(t="");var r=e.data("toggleclass");""===t?jQuery(".".concat(r)).hide():(jQuery(".".concat(r)).show(),jQuery(".hide_".concat(r,"_").concat(t)).hide())}function Vo(){mo()||(go(this),co(document.querySelector(".frm_form_settings")))}function Ko(e){return e.preventDefault(),Jo(jQuery(this),this.getAttribute("data-code")),!1}function Jo(e,t){var r=!1,n=e;if("object"===i(e)){if(e.hasClass("frm_noallow"))return;void 0===(n=jQuery(e).closest("[data-fills]").attr("data-fills"))&&void 0!==(n=e.closest("div").attr("class"))&&(n=n.split(" ")[1])}if(void 0===n){var o=document.activeElement;"search"===o.type?null===(n=o.id.replace("-search-input","")).match(/\d/gi)&&(n=(o=jQuery(".frm-single-settings:visible .".concat(n))).attr("id")):n=o.id}n&&(r=jQuery("#wp-".concat(n,"-wrap.wp-editor-wrap")).length>0);var a=jQuery(document.getElementById(n));if(void 0===e.attr("data-shortcode")&&(!a.length||void 0===a.attr("data-shortcode"))){var l=e.parents("ul.frm_code_list").attr("data-shortcode");"undefined"!==l&&"no"===l||(t="[".concat(t,"]"))}if(r&&(wpActiveEditor=n),!a.length)return!1;if("[default-html]"===t||"[default-plain]"===t){var s=0;"[default-plain]"===t&&(s=1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_default_html",form_id:jQuery('input[name="id"]').val(),plain_text:s,nonce:frmGlobal.nonce},elementId:n,success:function(e){if(r){var t=document.createElement("p");t.innerText=e,send_to_editor(t.innerHTML)}else Xo(a,e)}})}else t=function(e,t,r){return"object"===i(t)&&t instanceof jQuery&&0===r[0].id.indexOf("success_url_")&&(t=t[0]).closest("#frm-insert-fields-box")?(t.parentNode.classList.contains("frm_insert_url")||(e=e.replace("]"," sanitize_url=1]")),e):e}(t,e,a),r?send_to_editor(t):Xo(a,t);return!1}function Xo(e,t){if(document.selection)e[0].focus(),document.selection.createRange().text=t;else{var r=e[0],n=r.selectionEnd;t=function(e,t,r,n){var o=e.data("sep");if(void 0===o)return t;var i=e.val();if(!i.trim().length)return t;var a=new RegExp("".concat(o,"\\s*$")),l=new RegExp("^\\s*".concat(o));return i.substr(0,r).trim().length&&!1===a.test(i.substr(0,r))&&(t=o+t),i.substr(n,i.length).trim().length&&!1===l.test(i.substr(n,i.length))&&(t+=o),t}(e,t,r.selectionStart,n),r.value=r.value.substr(0,r.selectionStart)+t+r.value.substr(r.selectionEnd,r.value.length);var o=n+t.length;!function(e,t){if(e.classList.contains("frm_classes")&&Yo(t)){var r=e.value.split(" ").filter(Yo);r.length&&(e.value=function(e,t,r){var n=e.split(" ").filter(function(e){return(e=e.trim()).length&&!t.includes(e)});return n.includes(r)||n.push(r),n.join(" ")}(e.value,r,t.trim()))}}(r,t),r.focus(),r.setSelectionRange(o,o)}uo(e)}function Yo(e){return["frm_half","frm_third","frm_two_thirds","frm_fourth","frm_three_fourths","frm_fifth","frm_sixth","frm2","frm3","frm4","frm6","frm8","frm9","frm10","frm12"].includes(e.trim())}function Zo(){var e=document.getElementById("frm-id-condition"),t=document.getElementById("frm-key-condition");"id"===this.value?(e.classList.remove("frm_hidden"),t.classList.add("frm_hidden"),Ki(t,"change")):(e.classList.add("frm_hidden"),t.classList.remove("frm_hidden"),Ki(e,"change"))}function ei(){var e=document.getElementById("frm-id-key-condition-id").checked?"frm-id-condition":"frm-key-condition",t=document.getElementById("frm-is-condition").value,r=document.getElementById("frm-text-condition").value,n=document.getElementById("frm-insert-condition"),o=(e=document.getElementById(e)).options[e.selectedIndex].value,i="if ".concat(o," ").concat(t,'="').concat(r,'"]');n.setAttribute("data-code","".concat(i+f.conditional_text,"[/if ").concat(o)),n.innerHTML="[".concat(i,"[/if ").concat(o,"]")}function ti(e){return e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href")}function ri(e){var t;e.parentNode.parentNode.classList.contains("frm_has_shortcodes")&&(vi(),"use"===(t=gi(e)).tagName?ti(t=t.firstElementChild).includes("frm_close_icon")||li(t,"nofocus"):t.classList.contains("frm_close_icon")||li(t,"nofocus"))}function ni(e){e.preventDefault(),e.stopPropagation(),li(this)}function oi(e){var t=e.target;!function(e){var t;if(e.id.startsWith("field_options_type_")){var r=e.id.split("_"),n=r.length&&r[r.length-1];null!==(t=document.querySelector("#frm-single-settings-".concat(n)))&&void 0!==t&&t.classList.contains("frm-type-".concat(e.value))||ii()}}(t),g(t)}function ii(e){var t;void 0===e&&(e=P("You are changing the field type. Not all field settings will appear as expected until you reload the page. Would you like to reload the page now?","formidable")),frmDom.modal.maybeCreateModal("frmSaveAndReloadModal",{title:P("Save and Reload?","formidable"),content:(t=h(e),t.style.padding="var(--gap-md)",t),footer:function(){var e=frmDom.modal.footerButton({text:P("Save and Reload","formidable"),buttonType:"primary"});E(e,function(){var e;(e=document.getElementById("frm_submit_side_top")).classList.contains("frm_submit_ajax")&&e.setAttribute("data-new-addon-installed",!0),e.click()});var t=frmDom.modal.footerButton({text:P("Cancel","formidable"),buttonType:"cancel"});return t.classList.add("dismiss"),frmDom.div({children:[t,e]})}()})}function ai(e){var t;if(e instanceof Event){var r=document.querySelectorAll(".frm-single-settings .frm-show-box.frmsvg use"),n=Array.from(r).find(function(e){return"#frm_close_icon"===e.getAttribute("href")});if(void 0===n)return;t=n.parentElement}else t=e;var o=t.getBoundingClientRect(),i=document.getElementById("frm_adv_info"),a=i.parentElement.getBoundingClientRect();i.style.top="".concat(o.top-a.top+32,"px"),i.style.left="".concat(o.left-a.left-280,"px")}function li(e,t){var r=pi(e),n=document.getElementById("frm_adv_info"),o=e.className;if("svg"===e.tagName&&(e=e.firstElementChild),"use"===e.tagName&&(o=ti(e)),o.includes("frm_close_icon"))vi(n);else{if(ai(e),jQuery(".frm_code_list a").removeClass("frm_noallow"),r.classList.contains("frm_not_email_to")?jQuery("#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a").addClass("frm_noallow"):r.classList.contains("frm_not_email_subject")&&jQuery(".frm_code_list li.hide_frm_not_email_subject a").addClass("frm_noallow"),n.setAttribute("data-fills",r.id),n.style.display="block","use"===e.tagName)if(e.hasAttributeNS("http://www.w3.org/1999/xlink","href"))e.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon");else{var i=document.createElementNS("http://www.w3.org/2000/svg","use");i.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon"),e.parentNode.replaceChild(i,e)}else e.className=o.replace("frm_more_horiz_solid_icon","frm_close_icon");"nofocus"!==t&&("none"!==r.style.display?r.focus():jQuery(tinymce.get(r.id)).trigger("focus")),function(e){["address","body"].forEach(function(t){!function(e,t){var r,n=f.contextualShortcodes["".concat(t,"Selector")],o=f.contextualShortcodes[t],i=e.matches(n),a=s(o);try{for(a.s();!(r=a.n()).done;){var l,c=r.value,d=null===(l=document.querySelector('#frm-adv-info-tab .frm_code_list [data-code="'.concat(c,'"]')))||void 0===l?void 0:l.closest("li");null==d||d.classList.toggle("frm_hidden",!i)}}catch(e){a.e(e)}finally{a.f()}}(e,t)})}(r)}}function si(e){return 0===f.contextualShortcodes.length||!function(e){var t=e.querySelector("a");if(!t)return!1;var r=t.dataset.code;return f.contextualShortcodes.address.includes(r)||f.contextualShortcodes.body.includes(r)}(e)||function(e){var t=e.querySelector("a").dataset.code,r=document.getElementById("frm_adv_info").dataset.fills,n=document.getElementById(r),o=f.contextualShortcodes;return o.address.includes(t)?n.matches(o.addressSelector):n.matches(o.bodySelector)}(e)}function ci(){N||(N=1,window.addEventListener("beforeunload",mi))}function di(){N=0}function ui(){N=0}function fi(){N=0}function mi(e){N&&(e.preventDefault(),e.returnValue="")}function _i(e,t){var r={my:"top",at:"top+".concat(t),of:window};e.dialog("option","position",r)}function pi(e){if(e.classList.contains("frm-input-icon"))return e.previousElementSibling;for(var t,r=e.nextElementSibling;r&&("INPUT"!==r.tagName&&"TEXTAREA"!==r.tagName||r.classList.contains("frm-token-input-field"));)r=pi(r);return r||(r=null===(t=e.closest(".frm-field-formula"))||void 0===t?void 0:t.querySelector(".frm-calc-field")),r}function gi(e){var t;if(null!==(t=e.nextElementSibling)&&void 0!==t&&t.classList.contains("frm-input-icon"))return e.nextElementSibling;for(var r=e.previousElementSibling;null!==r&&"I"!==r.tagName&&"svg"!==r.tagName;)r=gi(r);return r}function vi(e){if((void 0!==e||(e=document.getElementById("frm_adv_info")))&&null===document.getElementById("frm_dyncontent")){e.style.display="none";for(var t=document.querySelectorAll(".frm-show-box.frm_close_icon"),r=0;r<t.length;r++)t[r].classList.remove("frm_close_icon"),t[r].classList.add("frm_more_horiz_solid_icon");for(var n=document.querySelectorAll(".frm_has_shortcodes use"),o=0;o<n.length;o++)if("#frm_close_icon"===ti(n[o])){if(n[o].closest(".frm_remove_field"))continue;n[o].setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_more_horiz_solid_icon")}}}function yi(e,t){t.stopPropagation(),jQuery(".frm_code_list .frmids, .frm_code_list .frmkeys").addClass("frm_hidden"),jQuery(".frm_code_list .".concat(e)).removeClass("frm_hidden"),jQuery(".frmids, .frmkeys").removeClass("current"),jQuery(".".concat(e)).addClass("current")}function hi(e){var t=e.target.closest(".frm_form_action_settings");t&&(t.classList.contains("frm_single_email_settings")||t.classList.contains("frm_single_on_submit_settings"))&&function(e){e.querySelectorAll(".wp-editor-area").forEach(function(e){frmDom.wysiwyg.init(e,{height:160,addFocusEvents:!0})})}(t)}function bi(){return!0===V(this)&&(jQuery(".frm_uninstall .frm-wait").css("visibility","visible"),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_uninstall&nonce=".concat(frmGlobal.nonce),success:function(e){jQuery(".frm_uninstall").fadeOut("slow"),window.location=e}})),!1}function wi(){var e=jQuery(this),t=this.name,r=this.getAttribute("data-plugin"),n=t.replace("edd_".concat(r,"_license_"),""),o=document.getElementById("edd_".concat(r,"_license_key")).value;e.get(0).disabled=!0,jQuery.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_".concat(n),license:o,plugin:r,nonce:frmGlobal.nonce},success:function(t){e.get(0).disabled=!1;var i=e.closest(".edd_frm_license_row");"deactivate"===n&&(o="",document.getElementById("edd_".concat(r,"_license_key")).value=""),i.find(".edd_frm_license").html(o);var a=e.get(0).closest(".frm_form_field"),l=!0===t.success;a.querySelector(".frm_icon_font.frm_action_success").classList.toggle("frm_hidden",!l||"deactivate"===n),a.querySelector(".frm_icon_font.frm_action_error").classList.toggle("frm_hidden",l);var s=i.find(".frm_license_msg");s.html(t.message),""!==t.message&&setTimeout(function(){if(s.html(""),i.find(".frm_icon_font").addClass("frm_hidden"),l){var e="activate"===n;i.get(0).querySelector(".edd_frm_unauthorized").classList.toggle("frm_hidden",e),i.get(0).querySelector(".edd_frm_authorized").classList.toggle("frm_hidden",!e)}},2e3)}})}function ji(e){e.preventDefault();var t=jQuery(e.target).find("input:checked");if(t.length){var r,n,o,i,a=[];t.each(function(e){a[e]=this.value}),r=a,n=e.target,(i=(o=jQuery(n)).next(".frm-importer-process")).find(".form-total").text(r.length),i.find(".form-current").text("1"),o.hide(),i.find(".process-completed").hide(),i.show(),H.importQueue=r,H.imported=0,xi(i)}}function xi(e){var t=H.importQueue[0],r=jQuery("#welcome-panel").find('input[name="slug"]').val(),n={action:"frm_import_".concat(r),form_id:t,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,n,function(r){var n;r.success&&(n=r.data.error?"<p>".concat(r.data.name,": ").concat(r.data.msg,"</p>"):'<p>Imported <a href="'.concat(r.data.link,'" target="_blank">').concat(r.data.name,"</a></p>"),e.find(".status").prepend(n),e.find(".status").show(),H.importQueue=jQuery.grep(H.importQueue,function(e){return e!=t}),H.imported++,0===H.importQueue.length?(e.find(".process-count").hide(),e.find(".forms-completed").text(H.imported),e.find(".process-completed").show()):(e.find(".form-current").text(H.imported+1),xi(e)))})}function Ei(e){e.preventDefault();var t=!1,r=jQuery('input[name="frm_export_forms[]"]');jQuery('input[name="frm_export_forms[]"]:checked').val()||(r.closest(".frm-table-box").addClass("frm_blank_field"),t="stop");var n=jQuery('input[name="type[]"]');if(jQuery('input[name="type[]"]:checked').val()||"checkbox"!==n.attr("type")||(n.closest("p").addClass("frm_blank_field"),t="stop"),"stop"===t)return!1;e.stopPropagation(),this.submit()}function ki(){var e=jQuery(this).closest(".frm_blank_field");if(void 0!==e){var t=this.name;("type[]"===t&&jQuery('input[name="type[]"]:checked').val()||"frm_export_forms[]"===t&&jQuery(this).val())&&e.removeClass("frm_blank_field")}}function Qi(){null!==jQuery(this).val().match(/\.csv$/i)?jQuery(".show_csv").fadeIn():jQuery(".show_csv").fadeOut()}function Si(){var e=document.querySelector('select[name="format"]');return e?e.value:""}function Ai(e){var t,r,n=e.target.value;Ii(n),Li.call(e.target),t=n,r=document.getElementById("frm-export-select-all"),"csv"===t?(r.checked=!1,r.disabled=!0):r.disabled=!1}function Li(){var e=jQuery(this),t=e.find(":selected"),r=t.data("support"),n=r.indexOf("|");jQuery('input[name="type[]"]').each(function(){this.checked=!1,r.includes(this.value)?(this.disabled=!1,-1===n&&(this.checked=!0)):this.disabled=!0}),"csv"===e.val()?(jQuery(".csv_opts").show(),jQuery(".xml_opts").hide()):(jQuery(".csv_opts").hide(),jQuery(".xml_opts").show());var o=t.data("count"),i=jQuery('input[name="frm_export_forms[]"]');"single"===o?(i.prop("multiple",!1),i.prop("checked",!1)):(i.prop("multiple",!0),i.prop("disabled",!1)),e.trigger("change")}function Ii(e){if(""!==e){var t=document.querySelectorAll(".frm-is-repeater");t.length&&("csv"===e?t.forEach(function(e){e.classList.remove("frm_hidden")}):t.forEach(function(e){e.classList.add("frm_hidden")}),Wi.call(document.querySelector(".frm-auto-search")))}}function qi(){var e=jQuery("select[name=format]").find(":selected").data("count"),t=jQuery('input[name="frm_export_forms[]"]');"single"===e&&this.checked?(t.prop("disabled",!0),this.removeAttribute("disabled")):t.prop("disabled",!1)}function Bi(e){(e?jQuery(e).find(".frm_multiselect"):jQuery(".frm_multiselect")).hide().each(frmDom.bootstrap.multiselect.init)}function Ci(e){e.preventDefault(),Oi(this,"frm_multiple_addons")}function Ni(e){e.preventDefault(),Oi(this,"frm_activate_addon")}function Ti(e){e.preventDefault(),Oi(this,"frm_install_addon")}function Oi(e,t){r(1105).toggleAddonState(e,t)}function Fi(){Mi()}function Di(e){!function(e,t,r){var n=jQuery("#frm_leave_email_error");n.removeClass("frm_hidden").attr("frm-error",r),jQuery("#frm_leave_email").one("keyup",function(){n.addClass("frm_hidden")})}(0,0,e)}function Mi(){var e=document.getElementById("frmapi-email-form");jQuery.ajax({dataType:"json",url:e.getAttribute("data-url"),success:function(t){var r=t.renderedHtml;r=r.replace(/<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi,""),e.innerHTML=r}})}function Pi(e){frmDom.autocomplete.initSelectionAutocomplete(e)}function Ri(e){var t=this.parentNode.parentNode,r=t.elements.type.value;e.preventDefault(),this.classList.add("frm_loading_button"),Hi(t,r,this)}function zi(e){var t=this.elements.type.value,r=this.querySelector("button");e.preventDefault(),r.classList.add("frm_loading_button"),Hi(this,t,r)}function Hi(e,t,r){var n=function(e){var t,r,n={},o=e.elements;for(r=0;r<o.length;r++){var i=o[r],a=i.name,l=i.value,s=a.match(/(.*)\[(.*)\]/);("radio"!==i.type&&"checkbox"!==i.type||i.checked)&&(null===s?Reflect.has(n,a)?(Array.isArray(n[a])||(n[a]=[n[a]]),n[a].push(l)):n[a]=l:(a=s[1],t=s[2],Reflect.has(n,a)||(n[a]={}),n[a][t]=l))}return n}(e),o=n.template_name,i=n.template_desc,a=e.elements.link.value,l={action:t,xml:a,name:o,desc:i,form:JSON.stringify(n),nonce:frmGlobal.nonce},s={formData:n};Ji(l=wp.hooks.applyFilters("frm_before_install_new_form",l,s),function(t){if(void 0!==t.redirect){var n=t.redirect;if(void 0===e.elements.redirect)window.location=n;else{var o=document.getElementById("frm-redirect-link");void 0!==a&&o&&(o.setAttribute("href",n),o.classList.remove("frm_grey","disabled"),(i=e.parentNode.parentNode).classList.add("frm_grey"),i.nextElementSibling.classList.remove("frm_grey"),r.classList.add("frm_grey","disabled"))}}else jQuery(".spinner").css("visibility","hidden"),"string"==typeof t.message&&function(e){var t=h(e);t.style.padding="20px 40px",frmDom.modal.maybeCreateModal("frmInstallFormErrorModal",{title:P("Unable to install template","formidable"),content:t}).classList.add("frm_common_modal")}(t.message);var i;r.classList.remove("frm_loading_button")})}function Gi(e){var t=document.getElementById("frm_captcha_threshold_container");t&&t.classList.toggle("frm_hidden","v3"!==e.target.value)}function Ui(e){var t=this.getAttribute("data-id");e.preventDefault(),Ji({action:"frm_forms_trash",id:t,nonce:frmGlobal.nonce},function(){var e=document.getElementById("frm-template-custom-".concat(t));Xi(e,function(){e.remove()})})}function Wi(){var e,t,r=!1,n=this.value.toLowerCase(),o=this.getAttribute("data-tosearch"),i=document.getElementsByClassName(o);for("SELECT"===this.tagName&&(n=function(e){for(var t,r=[],n=null==e?void 0:e.options,o=0,i=null==n?void 0:n.length;o<i;o++)(t=n[o]).selected&&r.push(t.value);return r}(this),n=n.join("|").toLowerCase(),r=!0),e=0;e<i.length;e++){var a=i[e].textContent.toLowerCase(),l=!("xml"===Si()&&i[e].classList.contains("frm-is-repeater"));""===n?(l&&si(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.remove("frm-search-result")):r&&new RegExp(n).test(a)||a.includes(n)||$i(a,n)?(l&&si(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.add("frm-search-result")):(i[e].classList.add("frm_hidden"),i[e].classList.remove("frm-search-result"))}(t=document.querySelector("#frm-insert-fields"))&&t.querySelectorAll(":scope > .frm-with-line").forEach(function(e){var t=e.nextElementSibling;if(t){var r=t.querySelectorAll(":scope > li.frmbutton"),n=Array.from(r).every(function(e){return e.classList.contains("frm_hidden")});e.classList.toggle("frm_hidden",n)}}),jQuery(this).trigger("frmAfterSearch")}function $i(e,t){return"s"!==t&&"s"!==e[e.length-1]&&"".concat(e,"s").includes(t)}function Vi(e){e.stopPropagation()}function Ki(e,t){var r=document.createEvent("HTMLEvents");r.initEvent(t,!1,!0),e.dispatchEvent(r)}function Ji(e,t){var r,n=new XMLHttpRequest,o="string"==typeof e?e:Object.keys(e).map(function(t){return"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(e[t]))}).join("&");return n.open("post",ajaxurl,!0),n.onreadystatechange=function(){if(n.readyState>3&&200==n.status){r=n.responseText;try{r=JSON.parse(r)}catch(e){}t(r)}},n.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n.send(o),n}function Xi(e,t){e.classList.add("frm-fade"),setTimeout(t,1e3)}function Yi(e){jQuery(e).css("visibility","hidden")}function Zi(e){jQuery(e).css("visibility","visible")}function ea(e,t){return r(4260).initModal(e,t)}function ta(e,t,r){if("#"===t){var n=document.getElementById(e);if(void 0!==r)n.style.display=r?"block":"none";else{var o=n.style.display;n.style.display="none"===o?"block":"none"}}else void 0!==r?r?e.show():e.hide():e.is(":visible")?e.hide():e.show()}function ra(){window.onbeforeunload=null;var e=jQuery(window);e.off("beforeunload.widgets"),e.off("beforeunload.edit-post")}function na(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));if(t&&"form"===t.dataset.type)if(t=jQuery(t),this.options[this.selectedIndex].value){t.find(".frm-not-set")[0].classList.add("frm_hidden");var r=t.find(".frm-embed-message");r.html(r.data("embedmsg")+this.options[this.selectedIndex].text),t.find(".frm-embed-field-placeholder")[0].classList.remove("frm_hidden")}else t.find(".frm-not-set")[0].classList.remove("frm_hidden"),t.find(".frm-embed-field-placeholder")[0].classList.add("frm_hidden")}function oa(e){var t=e.target,r=t.value.trim();if(!r.includes("[")||!r.includes("]")){if(isNaN(r.replace(/,/,""))){var n=P("Please enter a valid number.","formidable");return frmAdminBuild.infoModal(n),void function(e){var t=document.querySelectorAll("#frm_info_modal .dismiss, #frm_info_modal #frm-info-click, .ui-widget-overlay.ui-front");function r(){e.classList.add("frm_invalid_field"),setTimeout(function(){return e.focus()},0),t.forEach(function(e){e.removeEventListener("click",r)})}t.forEach(function(e){e.addEventListener("click",r)})}(t)}t.classList.remove("frm_invalid_field")}}function ia(){var e=jQuery(this).closest(".frm-single-settings"),t=e.find(".frmjs_product_choices"),r=e.find(".frm_prod_options_heading"),n=this.options[this.selectedIndex].value,o=e[0].querySelector(".frm_display_format_options");o&&o.setAttribute("data-product-type",n),t.removeClass("frm_prod_type_single frm_prod_type_user_def"),r.removeClass("frm_prod_user_def"),"single"===n?t.addClass("frm_prod_type_single"):"user_def"===n&&(t.addClass("frm_prod_type_user_def"),r.addClass("frm_prod_user_def")),wp.hooks.doAction("frm_product_type_toggled",n,e[0])}function aa(e){var t=document.getElementById("frm_field_id_".concat(e));return!!t&&"product"===t.getAttribute("data-type")}function la(){var e=function(e,t){return window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]},t=function(e,t,r){window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]=r},r=[1,2,3,4,5,6,7,8,9,10,11,12].map(function(e){return"frm".concat(e)}),o=["first","middle","last"];document.addEventListener("change",function(i){i.target.matches(".frm_name_layout_dropdown")&&function(i){var a,l=i.target.value.split("_"),s=i.target.dataset.fieldId,c=document.querySelector("#field_".concat(s,"_inner_container .frm_combo_inputs_container")),d=(a=l.length,"frm".concat(parseInt(12/a)));o.forEach(function(e){var o,i=c.querySelector('[data-sub-field-name="'.concat(e,'"]'));i&&(i.classList.add("frm_hidden"),(o=i.classList).remove.apply(o,n(r)),t(s,e,i))}),l.forEach(function(t){var r=e(s,t);r&&(r.classList.remove("frm_hidden"),r.classList.add(d),c.append(r))}),o.forEach(function(e){var r=document.querySelector(".frm_sub_field_options-".concat(e,'[data-field-id="').concat(s,'"]'));r&&(r.classList.add("frm_hidden"),t(s,"".concat(e,"_options"),r))}),l.forEach(function(t){var r=e(s,"".concat(t,"_options"));r&&r.classList.remove("frm_hidden")})}(i)},!1)}function sa(e,t){var r,n,o,i=!1,a=!1;(r=t.newOption?(new DOMParser).parseFromString(t.newOption,"text/html").body.childNodes[0]:t).querySelectorAll("svg").forEach(function(e){(n=e.getElementsByTagNameNS("http://www.w3.org/2000/svg","use")[0])&&("#frm_drag_icon"===(o=ti(n))&&(i=!0),"#frm_save_icon"===o&&(a=!0))}),i||r.prepend(L.drag.cloneNode(!0)),r.querySelector("[id^=field_key_".concat(e,"-]"))&&!a&&r.querySelector("[id^=field_key_".concat(e,"-]")).after(L.save.cloneNode(!0)),t.newOption&&(t.newOption=r)}function ca(){var e=document.getElementById("frm_leave_email").value.trim();if(""!==e)if(!1!==/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i.test(e)){var t=jQuery("#frmapi-email-form").find("form"),r=t.find('[type="email"]').not(".frm_verify");if(r.length){if(document.getElementById("frm_empty_inbox")){document.getElementById("frm-add-my-email-address").remove();var n=document.getElementById("frm_leave_email_wrapper");if(n){n.classList.add("frm_hidden");var o=b({className:"frm-wait frm_spinner"});o.style.visibility="visible",o.style.float="none",o.style.width="unset",n.parentElement.insertBefore(o,n.nextElementSibling)}}r.val(e),jQuery.ajax({type:"POST",url:t.attr("action"),data:"".concat(t.serialize(),"&action=frm_forms_preview")}).done(function(e){if(jQuery(e).find(".frm_message").text().trim().includes("Thanks!")){var t=document.getElementById("frmapi-email-form").parentElement.querySelector(".frm_spinner");t&&t.remove(),wp.hooks.applyFilters("frm_thank_you_on_signup",!0)&&document.getElementById("frm_leave_email_wrapper").replaceWith(b(P("Thank you for signing up!","formidable")))}else Di("invalid")})}}else Di("invalid");else Di("empty")}function da(e){var t;if(W||e.stopPropagation(),!(e.target.classList.contains("frm-show-box")||null!==(t=e.target.parentElement)&&void 0!==t&&t.classList.contains("frm-show-box"))){var r=document.getElementById("frm_adv_info");r&&(r.dataset.fills===e.target.id&&void 0!==e.target.id||e.target.closest("#frm_adv_info")||"none"===r.style.display||vi(r))}}return{init:function(){var e,t,o,i,a,l,s;!function(){jQuery(document).on("click","#frm-add-my-email-address",function(e){e.preventDefault(),ca()});var e=document.getElementById("frm_empty_inbox"),t=document.getElementById("frm_leave_email");if(e&&t){var r=document.getElementById("frm-leave-email-modal");r.classList.remove("frm_hidden"),r.querySelector(".frm_modal_footer").classList.add("frm_hidden"),t.addEventListener("keyup",function(e){if("Enter"===e.key){var t=document.getElementById("frm-add-my-email-address");t&&t.click()}})}}(),t=document.querySelector(".frm-admin-footer-links"),o=null!==(e=document.querySelector(".frm_page_container"))&&void 0!==e?e:document.getElementById("wpbody-content"),t&&o&&(o.append(t),t.classList.remove("frm_hidden")),document.addEventListener("show.bs.dropdown",function(){Y()}),H={},jQuery(".wp-admin").on("click",function(e){var t=jQuery(e.target),r=jQuery(".dropdown.open");!r.length||t.hasClass("dropdown")||t.closest(".dropdown").length||r.removeClass("open")}),jQuery("#frm_bs_dropdown:not(.open) a").on("click",Vt),void 0===T&&(T=jQuery(document.getElementById("form_id")).val()),document.querySelectorAll(".frm-warning-dismiss").forEach(function(e){E(e,Kt)}),frmAdminBuild.inboxBannerInit(),I.length>0?frmAdminBuild.buildInit():null!==document.getElementById("frm_notification_settings")?frmAdminBuild.settingsInit():null!==document.getElementById("frm_styling_form")?frmAdminBuild.styleInit():null!==document.getElementById("form_global_settings")?frmAdminBuild.globalSettingsInit():null!==document.getElementById("frm_export_xml")?frmAdminBuild.exportInit():null!==document.querySelector(".frm-inbox-wrapper")?frmAdminBuild.inboxInit():null!==document.getElementById("frm-welcome")?frmAdminBuild.solutionInit():(function(){if(document.body.classList.contains("frm-admin-page-entries")){var e=document.getElementById("screen-options-wrap");if(e){var t=h({className:"frm_warning_style",text:P("Only 10 columns can be selected at a time.","formidable")});t.style.margin=0;var r=e.querySelector("legend");r.parentNode.insertBefore(t,r.nextElementSibling);var n=Array.from(e.querySelectorAll('input[type="checkbox"]')),o=function(){n.reduce(function(e,t){return t.checked?e+1:e},0)>=10?(t.classList.remove("frm_hidden"),n.forEach(function(e){e.checked||(e.parentNode.classList.add("frm_noallow"),e.disabled=!0)})):t.classList.add("frm_hidden")};o(),n.forEach(function(e){e.addEventListener("change",function(e){e.target.checked?o():(t.classList.add("frm_hidden"),n.forEach(function(e){e.parentNode.classList.remove("frm_noallow"),e.disabled=!1}))})})}}}(),Pi(),jQuery("[data-frmprint]").on("click",function(){return window.print(),!1})),jQuery(document).on("change","select[data-toggleclass], input[data-toggleclass]",$o),function(){function e(e){var t=e.options[e.selectedIndex];e.querySelectorAll("option[data-dependency]:not([data-dependency-skip])").forEach(function(e){var r=document.querySelector(e.dataset.dependency);null==r||r.classList.toggle("frm_hidden",t!==e)})}document.querySelectorAll("select.frm_select_with_dependency").forEach(e),frmDom.util.documentOn("change","select.frm_select_with_dependency",function(t){return e(t.target)})}(),(jQuery(document.getElementById("frm_adv_info")).length>0||jQuery(".frm_field_list").length>0)&&frmAdminBuild.panelInit(),i=jQuery(".wrap, .frm_wrap"),a=document.getElementById("frm_confirm_modal"),l=!1,s=!1,jQuery(a).on("click","[data-deletefield]",Gr),jQuery(a).on("click","[data-removeid]",Z),jQuery(a).on("click","[data-trashtemplate]",Ui),i.on("click",".frm_remove_tag, .frm_remove_form_action",Z),i.on("click","a[data-frmverify]",$),i.on("click","a[data-frmtoggle]",J),i.on("click","a[data-frmhide], a[data-frmshow]",X),i.on("change","input[data-frmhide], input[data-frmshow]",X),i.on("click",".widget-top,a.widget-action",te),function(e){e.on("keydown",".widget-top",function(e){e.currentTarget===e.target&&("Enter"!==e.key&&" "!==e.key||(e.preventDefault(),te(e,e.currentTarget)))});var t=function(e){return function(t){t.key===e&&(t.preventDefault(),t.currentTarget.click())}};e.on("keydown",".frm_form_action_settings .frm_duplicate_form_action, .frm_form_action_settings .frm_remove_form_action",t(" ")),e.on("keydown",".frm_form_action_settings .frm_toggle",t("Enter"))}(i),i.on("mouseenter.frm",".frm_bstooltip, .frm_help",function(){jQuery(this).off("mouseenter.frm"),function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=e;(r.hasAttribute("data-toggle")||r.hasAttribute("data-bs-toggle"))&&(r.parentElement.setAttribute("title",r.getAttribute("title")),r.removeAttribute("title"),r.classList.remove("frm_bstooltip"),r.parentElement.classList.add("frm_bstooltip"),r=r.parentElement);var n=new bootstrap.Tooltip(r);t&&(Y(),n.show())}(this,!0)}),jQuery(document).on("click","#doaction, #doaction2",function(e){var t="doaction"===this.id?"top":"bottom",r=document.getElementById("bulk-action-selector-".concat(t)),n=document.getElementById("confirm-bulk-delete-".concat(t));if(r&&n){if(l=this,!s&&"bulk_delete"===r.value)return e.preventDefault(),V(n),!1}else l=!1}),jQuery(document).on("click","#frm-confirmed-click",function(e){if(!1!==l&&!e.target.classList.contains("frm-btn-inactive"))return"confirm-bulk-delete"===this.getAttribute("href")?(e.preventDefault(),s=!0,l.click(),!1):void 0}),r(4260).initUpgradeModal(),frmDom.util.documentOn("click","[data-modal-title]",vo);var c=jQuery(document.getElementById("frm_shortcodediv"));c.length>0&&(jQuery("a.edit-frm_shortcode").on("click",function(){return c.is(":hidden")&&(c.slideDown("fast"),this.style.display="none"),!1}),jQuery(".cancel-frm_shortcode","#frm_shortcodediv").on("click",function(){return c.slideUp("fast"),c.siblings("a.edit-frm_shortcode").show(),!1})),jQuery(document).on("click","#frm-nav-tabs a",oe),jQuery(".post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a").on("click",function(){var e=this.classList.contains("frm_show_upgrade_tab");if(!this.classList.contains("frm_noallow")||e)return e&&this.classList.contains("frm_show_expired_modal")?(wp.hooks.doAction("frm_show_expired_modal",this),!1):(e&&yo(this),ie(this),!1)}),ie(jQuery(".frm-category-tabs .starttab a"),"auto"),jQuery(document).on("click","#frm-fid-search-menu a",function(){var e=this.id.replace("fid-","");return jQuery('select[name="fid"]').val(e),co(document.getElementById("posts-filter")),!1}),jQuery(".frm_select_box").on("click focus",function(){this.select()}),jQuery(document).on("input search change",".frm-auto-search:not(#frm-form-templates-page #template-search-input)",Wi),jQuery(document).on("focusin click",".frm-auto-search",Vi);var d=jQuery(".frm-auto-search");""!==d.val()&&d.trigger("keyup"),FrmFormsConnect.init(),jQuery(document).on("click",".frm-install-addon",Ti),jQuery(document).on("click",".frm-activate-addon",Ni),jQuery(document).on("click",".frm-solution-multiple",Ci),jQuery("button, input[type=submit]").on("click",ra),document.addEventListener("click",function(e){if("LABEL"===e.target.nodeName){var t=e.target.getAttribute("for");if(t){var r=document.getElementById(t);if(r&&r.nextElementSibling){var n=r.nextElementSibling.querySelector("button.dropdown-toggle.multiselect");n&&setTimeout(function(){return n.click()},0)}}}}),frmAdminBuild.hooks.addFilter("frm_before_embed_modal",function(e,t){var r,n,o=t.element;if("form"!==t.type)return e;var i=o.closest("tr");if(i)r=parseInt(i.querySelector(".column-id").textContent),n=i.querySelector(".column-form_key").textContent;else{r=document.getElementById("form_id").value;var a=document.getElementById("frm_form_key");if(a)n=a.value;else{var l=document.getElementById("frm-previewDrop");l&&(n=l.nextElementSibling.querySelector(".dropdown-item a").getAttribute("href").split("form=")[1])}}return[r,n]}),I.on("click","> li, .frm_grid_container li",function(){var e,t=(null===(e=this.querySelector("li"))||void 0===e?void 0:e.dataset.fid)||this.dataset.fid;!function(e){var t=document.querySelectorAll("[id^=frm_delete_field_".concat(e,"-]"));t.length<2||n(t).slice(1).forEach(function(t,r){t.classList.contains("frm_other_option")||sa(e,t)})}(t),function(e){var t=document.getElementById("frm_field_".concat(e,"_opts"));if(t){var r=t.querySelector(".frm_option_template"),n=null==r?void 0:r.querySelector(".frm_remove_tag"),o=null==r?void 0:r.querySelector(".frm_add_opt");if(n&&o){var i=t.querySelectorAll(".frm_single_option:not(.frm_option_template)"),a=i.length>1;i.forEach(function(e){if(!e.querySelector(".frm_remove_tag")){var t=e.dataset.optkey;if(void 0!==t){var r=n.cloneNode(!0);["removeid","removemore"].forEach(function(e){var n=r.dataset[e];n&&(r.dataset[e]=n.replace("-000","-".concat(t)))}),r.classList.toggle("frm_disabled",!a);var i=e.querySelector(".frm_option_key");i?i.before(r,o.cloneNode(!0)):e.append(r,o.cloneNode(!0))}}})}}}(t)});var u=document.getElementById("frm_small_screen_proceed_button");u&&E(u,function(){var e;null===(e=document.getElementById("frm_small_device_message_container"))||void 0===e||e.remove(),k("small_screen_proceed",new FormData)});var f=document.getElementById("frm_sale_banner"),m=null==f?void 0:f.querySelector(".dismiss");f&&(E(f,function(e){e.target.closest(".dismiss")||(window.location.href=f.getAttribute("data-url"))}),m&&E(m,function(){f.remove();var e=new FormData;k("sale_banner_dismiss",e)}))},buildInit:function(){var e,t;jQuery("#frm_builder_page").on("mouseup","*:not(.frm-show-box)",da),Q=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return frmDom.util.debounce(e,t)}(he,10),S=document.getElementById("post-body-content"),A=jQuery(S),ze(),ae("ul.frm_sorting"),e=jQuery("#frm_builder_page"),t={items:".frm_sortable_field_opts li",axis:"y",opacity:.65,forcePlaceholderSize:!1,handle:".frm-drag",helper:function(e,t){return C=t.clone().insertAfter(t),t.clone()},stop:function(e,t){C&&C.remove(),Qn(t.item.attr("id").replace("frm_delete_field_","").replace("-".concat(t.item.data("optkey"),"_container"),"")),ci()}},jQuery(e).sortable(t),document.querySelectorAll(".field_type_list > li:not(.frm_show_upgrade):not(.frm_show_update)").forEach(de),jQuery("ul.field_type_list, .field_type_list li, ul.frm_code_list, .frm_code_list li, .frm_code_list li a, #frm_adv_info #category-tabs li, #frm_adv_info #category-tabs li a").disableSelection(),jQuery(".frm_submit_ajax").on("click",so),jQuery(".frm_submit_no_ajax").on("click",fo),_o(),jQuery("a.edit-form-status").on("click",Kn),jQuery(".cancel-form-status").on("click",Jn),jQuery(".save-form-status").on("click",function(){var e=jQuery(document.getElementById("form_change_status")).val();return jQuery('input[name="new_status"]').val(e),jQuery(document.getElementById("form-status-display")).html(e),jQuery(".cancel-form-status").trigger("click"),!1}),jQuery(".frm_form_builder form").first().on("submit",function(){jQuery(".inplace_field").trigger("blur")}),Bi(),on();var r,n=jQuery(q),o=document.getElementById("frm_form_editor_container");n.on("click",".frm_add_logic_row",Vr),n.on("click",".frm_add_watch_lookup_row",Jr),n.on("change",".frm_get_values_form",rn),n.on("change",".frm_logic_field_opts",Hn),n.on("frm-multiselect-changed",'select[name^="field_options[admin_only_"]',Xn),jQuery(document.getElementById("frm-insert-fields")).on("click",".frm_add_field",We),I.on("click",".frm_clone_field",Je),n.on("blur",'input[id^="frm_calc"]',pt),n.on("change","input.frm_format_opt, input.frm_max_length_opt",At),n.on("change click","[data-changeme]",Qt),n.on("click","input.frm_req_field",Lt),n.on("click",".frm_mark_unique",qt),n.on("change",".frm_repeat_format",yn),n.on("change",".frm_repeat_limit",hn),n.on("change",".frm_js_checkbox_limit",bn),n.on("input",'input[name^="field_options[add_label_"]',function(){wn(this,"add")}),n.on("input",'input[name^="field_options[remove_label_"]',function(){wn(this,"remove")}),n.on("change",'select[name^="field_options[data_type_"]',nn),jQuery(o).on("click",".frm-collapse-page",an),jQuery(o).on("click",".frm-collapse-section",cn),n.on("click",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",dn),n.on("keydown",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),dn.call(this,e))}),jQuery(o).on("show.bs.dropdown hide.bs.dropdown",at),n.on("change",".frm_toggle_sep_values",Dt),n.on("change",".frm_toggle_image_options",Mt),n.on("click",".frm_remove_image_option",Wt),n.on("click",".frm_choose_image_box",Ut),n.on("change",".frm_hide_image_text",Gt),n.on("change",".frm_field_options_image_size",zt),n.on("click",".frm_multiselect_opt",$t),I.on("mousedown","input, textarea, select",Jt),I.on("click","input[type=radio], input[type=checkbox]",Jt),I.on("click",".frm_delete_field",tr),I.on("click",".frm_select_field",rr),jQuery(document).on("click",".frm_delete_field_group",nr),jQuery(document).on("click",".frm_clone_field_group",or),jQuery(document).on("click","#frm_field_group_controls > span:first-child",ir),jQuery(document).on("click",".frm-row-layout-option",hr),jQuery(document).on("click",".frm-merge-fields-into-row .frm-row-layout-option",br),jQuery(document).on("click",".frm-custom-field-group-layout",jr),jQuery(document).on("click",".frm-merge-fields-into-row .frm-custom-field-group-layout",Er),jQuery(document).on("click",".frm-break-field-group",Lr),I.on("click","#frm_field_group_popup .frm_grid_container input",Ir),jQuery(document).on("click",".frm-cancel-custom-field-group-layout",qr),jQuery(document).on("click",".frm-save-custom-field-group-layout",Cr),I.on("click","ul.frm_sorting",Nr),jQuery(document).on("click",".frm-merge-fields-into-row",Rr),jQuery(document).on("click",".frm-delete-field-groups",Hr),I.on("click",'.frm-field-action-icons [data-toggle="dropdown"]',function(){this.closest("li.form-field").classList.add("frm-field-settings-open"),jQuery(document).on("click","#frm_builder_page",et)}),I.on("mousemove","ul.frm_sorting",tt),I.on("show.bs.dropdown",".frm-field-action-icons",ot),jQuery(document).on("show.bs.dropdown","#frm_field_group_controls",it),n.on("click",".frm_single_option a[data-removeid]",Xt),n.on("mousedown",".frm_single_option input[type=radio]",Yt),n.on("focusin",".frm_single_option input[type=text]",Zt),n.on("click",".frm_add_opt",Tt),n.on("change",".frm_single_option input",xn),n.on("change",".frm_image_id",xn),n.on("change",".frm_toggle_mult_sel",Ot),I.on("click",".frm_primary_label",fn),I.on("click",".frm_description",mn),I.on("click","li.ui-state-default:not(.frm_noallow)",pn),I.on("dblclick","li.ui-state-default",vn),n.on("change",".frm_tax_form_select",jn),n.on("change","select.conf_field",Bt),n.on("change",".frm_get_field_selection",Gn),n.on("click",".frm-show-inline-modal",eo),n.on("keydown",".frm-show-inline-modal",function(e){var t=e.key;"Enter"!==t&&" "!==t||(e.preventDefault(),eo.call(this,e))}),n.on("click",".frm-inline-modal .dismiss",to),jQuery(document).on("change","[data-frmchange]",no),document.addEventListener("click",ro),n.on("change",".frm_include_extras_field",wt),n.on("change",'select[name^="field_options[form_select_"]',na),jQuery(document).on("submit","#frm_js_build_form",di),jQuery(document).on("change","#frm_builder_page input:not(.frm-search-input):not(.frm-custom-grid-size-input), #frm_builder_page select, #frm_builder_page textarea",ci),Et(),frmDom.util.documentOn("change",".frm_product_price",oa),jQuery(document).on("change",".frmjs_prod_data_type_opt",ia),jQuery(document).on("focus",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',Yr),jQuery(document).on("blur",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',en),frmDom.util.documentOn("click",".frm-show-field-settings",pn),frmDom.util.documentOn("change","select.frm_format_dropdown, select.frm_phone_type_dropdown",gn),n.on("keydown",'.frm_single_option input[name^="field_options["], .frm_single_option input[name^="rows_"]',function(e){"Enter"===e.key&&function(e){var t=e.closest(".frm_single_option").parentElement.querySelectorAll('.frm_single_option input[name^="field_options[" ], .frm_single_option input[name^="rows_"]'),r=Array.from(t),n=r.indexOf(e);if(!(n<0)){var o=r.slice(n+1).find(function(e){return null!==e.offsetParent});if(o){o.focus();var i=o.value.length;o.setSelectionRange(i,i)}}}(e.currentTarget)}),!1!==(r=ea("#frm-bulk-modal","700px"))&&(jQuery(".frm-insert-preset").on("click",Nt),jQuery(q).on("click","a.frm-bulk-edit-link",function(e){e.preventDefault();var t="",n=jQuery(this).closest("[data-fid]").data("fid"),o=Dn(n),i=aa(n),a=document.getElementById("frm_field_".concat(n,"_opts"));if(a){var l=a.getElementsByTagName("li");document.getElementById("bulk-field-id").value=n;for(var s=0;s<l.length;s++){var c=l[s].getAttribute("data-optkey");if("000"!==c){var d=document.getElementsByName("field_options[options_".concat(n,"][").concat(c,"][label]"))[0];void 0!==d&&(t+=d.value,o&&(t+="|".concat(document.getElementsByName("field_options[options_".concat(n,"][").concat(c,"][value]"))[0].value)),i&&(t+="|".concat(document.getElementsByName("field_options[options_".concat(n,"][").concat(c,"][price]"))[0].value)),t+="\r\n")}s>=l.length-1&&(document.getElementById("frm_bulk_options").value=t)}return r.dialog("open"),!1}}),jQuery("#frm-update-bulk-opts").on("click",function(){var e=document.getElementById("bulk-field-id").value;document.getElementById("bulk-option-type").value||(this.classList.add("frm_loading_button"),frmAdminBuild.updateOpts(e,document.getElementById("frm_bulk_options").value,r),ci())})),Zn(),document.addEventListener("frm_added_field",Zn),Ke(),la(),$n(),frmDom.util.documentOn("change",".frm_show_password_setting_input",function(e){var t=e.target.getAttribute("data-fid"),r=document.getElementById("frm_field_id_".concat(t));r&&r.classList.toggle("frm_disabled_show_password",!e.target.checked)}),document.addEventListener("scroll",ai,!0),document.addEventListener("change",oi),document.querySelector(".frm_form_builder").addEventListener("mousedown",function(e){e.shiftKey&&e.preventDefault()}),wp.hooks.addAction("frmShowedFieldSettings","formidableAdmin",function(e,t){t.querySelectorAll(".frm-collapse-me").forEach(un)},9999),frm_admin_js.pricingFieldsModal&&"object"===i(frm_admin_js.pricingFieldsModal)&&K(frm_admin_js.pricingFieldsModal,"550px")},settingsInit:function(){var e=jQuery(document.getElementById("frm_notification_settings"));e.on("click",".frm_email_buttons",So),e.on("click",".frm_remove_field",Ao),e.on("change",".frm_to_row, .frm_from_row",Lo),e.on("change",".frm_tax_selector",Uo),e.on("change","select.frm_single_post_field",Fo),e.on("change","select.frm_toggle_post_content",Do),e.on("change","select.frm_dyncontent_opt",Mo),e.on("change",".frm_post_type",Po),e.on("click",".frm_add_postmeta_row",Ho),e.on("click",".frm_add_posttax_row",zo),e.on("click",".frm_toggle_cf_opts",Wo),e.on("click",".frm_duplicate_form_action",wo),jQuery(".frm_actions_list").on("click",".frm_active_action",Eo),jQuery(document).on("frmAfterSearch","#actions-search-input",ee),Bi(),document.querySelectorAll(".frm_actions_list a[data-actiontype]").forEach(function(e){return Io(e.dataset.actiontype)}),jQuery(".frm_submit_settings_btn").on("click",Vo),_o();var t=jQuery(".frm_form_settings");t.on("click",".frm_add_form_logic",To),t.on("change","input[data-emailkey][data-toggleclass]",Oo),t.on("click",".frm_already_used",Co),document.addEventListener("click",function(e){var t=e.target;t.closest(".frm_image_preview_wrapper")&&(t.closest(".frm_choose_image_box")?Ut.bind(t)(e):t.closest(".frm_remove_image_option")&&Wt.bind(t)(e))}),t.on("mouseup","*:not(.frm-show-box)",da),jQuery(document.getElementById("no_save")).on("change",function(){this.checked&&!0!==confirm(f.no_save_warning)&&jQuery(this).attr("checked",!1)}),document.querySelectorAll('a[href="#spam_settings"]').forEach(function(e){e.addEventListener("click",function(e){e.preventDefault();var t=document.querySelector('.frm-category-tabs a[href="#spam_settings"]');t&&(ie(t),setTimeout(function(){var e=document.getElementById("frm-categorydiv");e&&e.scrollIntoView({block:"start"})},50))})});var r=document.getElementById("frm_include_captcha");if(r){var n=r.checked;r.addEventListener("change",function(){var e=document.getElementById("frm_captcha_add_warning"),t=document.getElementById("frm_captcha_remove_warning");e&&t&&(this.checked!==n?this.checked?(e.style.display="block",t.style.display="none"):(e.style.display="none",t.style.display="block"):(e.style.display="none",t.style.display="none"))})}jQuery('select[name="options[edit_action]"]').on("change",bo);var o=document.getElementById("logged_in");jQuery(o).on("change",function(){this.checked?Zi(".hide_logged_in"):Yi(".hide_logged_in")});var i=jQuery(document.getElementById("frm_cookie_expiration"));jQuery(document.getElementById("frm_single_entry_type")).on("change",function(){"cookie"===this.value?i.fadeIn("slow"):i.fadeOut("slow")});var a=document.getElementById("single_entry");jQuery(a).on("change",function(){this.checked?Zi(".hide_single_entry"):Yi(".hide_single_entry"),this.checked&&"cookie"===jQuery(document.getElementById("frm_single_entry_type")).val()?i.fadeIn("slow"):i.fadeOut("slow")}),jQuery(".hide_save_draft").hide();var l=jQuery(document.getElementById("save_draft"));l.on("change",function(){this.checked?jQuery(".hide_save_draft").fadeIn("slow"):jQuery(".hide_save_draft").fadeOut("slow")}),uo(l);var s=document.getElementById("editable");jQuery(s).on("change",function(){this.checked?(jQuery(".hide_editable").fadeIn("slow"),uo(document.getElementById("edit_action"))):(jQuery(".hide_editable").fadeOut("slow"),jQuery(".edit_action_message_box").fadeOut("slow"))}),jQuery(document).on("change","#protect_files",function(){this.checked?jQuery(".hide_protect_files").fadeIn("slow"):jQuery(".hide_protect_files").fadeOut("slow")}),jQuery(document).on("frm-multiselect-changed","#protect_files_role",Xn),jQuery(document).on("submit",".frm_form_settings",ui),jQuery(document).on("change","#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea",ci),Pi(),jQuery(document).on("frm-action-loaded",hi),frmDom.util.documentOn("change",'.frm_on_submit_type input[type="radio"]',function(e){if(e.target.checked){var t=e.target.closest(".frm_form_action_settings");t.querySelectorAll(".frm_on_submit_dependent_setting:not(.frm_hidden)").forEach(function(e){e.classList.add("frm_hidden")}),t.querySelectorAll(".frm_on_submit_dependent_setting[data-show-if-".concat(e.target.value,"]")).forEach(function(e){e.classList.remove("frm_hidden")}),t.setAttribute("data-on-submit-type",e.target.value)}}),wp.hooks.addAction("frm_reset_fields_updated","formidableAdmin",fi)},panelInit:function(){jQuery(".frm_wrap, #postbox-container-1").on("click",".frm_insert_code",Ko),jQuery(document).on("change",".frm_insert_val",function(){Jo(jQuery(this).data("target"),jQuery(this).val()),jQuery(this).val("")}),jQuery(document).on("click change",'[name="frm-id-key-condition"]',Zo),jQuery(document).on("keyup change",".frm-build-logic",ei),ho(),jQuery(document).on("frmElementAdded",function(e,t){ho(t)}),jQuery(document).on("mousedown",".frm-show-box",ni);var e=document.getElementById("form_settings_page"),t=document.body.classList.contains("post-type-frm_display"),r=document.getElementById("frm_insert_fields_tab");(e||t||W)&&jQuery(document).on("focusin","form input, form textarea",function(n){var o,i,a;if(n.stopPropagation(),ri(this),jQuery(this).is(":not(:submit, input[type=button], .frm-search-input, input[type=checkbox])")){if(jQuery(n.target).closest("#frm_adv_info").length)return;if(e||W)o=jQuery("#frm_html_tab"),jQuery(this).closest("#html_settings").length>0?(o.show(),o.siblings().hide(),jQuery("#frm_html_tab a").trigger("click"),void 0===(a=this.id)||a.includes("-search-input")||(jQuery("#frm-adv-info-tab").attr("data-fills",a.trim()),this.classList.contains("field_custom_html")&&(a="field_custom_html"),jQuery.inArray(a,["after_html","before_html","submit_html","field_custom_html"])>=0&&(jQuery(".frm_code_list li:not(.show_".concat(a,")")).addClass("frm_hidden"),jQuery(".frm_code_list li.show_".concat(a)).removeClass("frm_hidden")))):((i=jQuery(".frm-category-tabs li"))[0]&&(i[0].style.display=""),r.click(),o.hide(),o.siblings().show());else if(t){var l=new CustomEvent("frm_legacy_views_handle_field_focus");l.frmData={idAttrValue:this.id},document.dispatchEvent(l)}}}),jQuery(".frm_wrap, #postbox-container-1").on("mousedown","#frm_adv_info a, .frm_field_list a",function(e){e.preventDefault()});var n=jQuery("#frm_adv_info");n.on("click",".subsubsub a.frmids",function(e){yi("frmids",e)}),n.on("click",".subsubsub a.frmkeys",function(e){yi("frmkeys",e)})},inboxInit:function(){var e;jQuery(".frm_inbox_dismiss").on("click",function(e){var t=this.parentNode.parentNode,r=t.getAttribute("data-message"),n=this.getAttribute("href"),o=t.cloneNode(!0),i=document.querySelector(".frm-dismissed-inbox-messages");if("free_templates"!==r||this.classList.contains("frm_inbox_dismiss")){e.preventDefault();var a={action:"frm_inbox_dismiss",key:r,nonce:frmGlobal.nonce},l="frm_inbox_slide_in"===t.id;l&&(t.classList.remove("s11-fadein"),t.classList.add("s11-fadeout"),t.addEventListener("animationend",function(){return t.remove()},{once:!0})),Ji(a,function(){if(!l)return"#"!==n?(window.location=n,!0):void Xi(t,function(){var e;i&&(o.classList.remove("frm-fade"),null===(e=o.querySelector(".frm-inbox-message-heading .frm_inbox_dismiss"))||void 0===e||e.remove(),i.append(o)),1===t.parentNode.querySelectorAll(".frm-inbox-message-container").length&&(document.getElementById("frm_empty_inbox").classList.remove("frm_hidden"),t.parentNode.closest(".frm-active").classList.add("frm-empty-inbox"),Fi()),t.remove()})})}}),!1===(null===(e=document.getElementById("frm_empty_inbox"))||void 0===e?void 0:e.classList.contains("frm_hidden"))&&Fi()},solutionInit:function(){jQuery(document).on("submit","#frm-new-template",zi)},styleInit:function(){var e=jQuery(".frm_image_preview_wrapper");e.on("click",".frm_choose_image_box",Ut),e.on("click",".frm_remove_image_option",Wt),wp.hooks.doAction("frm_style_editor_init")},customCSSInit:function(){console.warn("Calling frmAdminBuild.customCSSInit is deprecated.")},globalSettingsInit:function(){jQuery(document).on("click","[data-frmuninstall]",bi),Bi();var e=document.getElementById("licenses_settings");e&&jQuery(e).on("click",".edd_frm_save_license",wi),jQuery(document).on("click","#frm-new-template button",Ri),jQuery("#frm-dismissable-cta .dismiss").on("click",function(e){e.preventDefault(),jQuery.post(ajaxurl,{action:"frm_lite_settings_upgrade",nonce:frmGlobal.nonce}),jQuery(".settings-lite-cta").remove()});var t=document.getElementById("frm_re_type");t&&t.addEventListener("change",Gi),document.querySelector(".frm_captchas").addEventListener("change",function(e){var t,r=null===(t=document.querySelector('.frm_captchas input[checked="checked"]'))||void 0===t?void 0:t.value,n=e.target.value!==r;document.querySelector(".captcha_settings .frm_note_style").classList.toggle("frm_hidden",!n)}),frmDom.util.documentOn("submit",".frm_settings_form",function(){N=0});var r=document.getElementById("manage_styles_settings");r&&r.addEventListener("change",function(e){var t=e.target;"SELECT"===t.nodeName&&t.dataset.name&&!t.getAttribute("name")&&t.setAttribute("name",t.dataset.name)});var n=document.getElementById("payments_settings"),o=null==n?void 0:n.querySelectorAll('[name="frm_payment_section"]');o&&o.forEach(function(e){e.addEventListener("change",function(){if(e.checked){var t=n.querySelector('label[for="'.concat(e.id,'"]'));t&&t.setAttribute("aria-selected","true"),o.forEach(function(t){if(t!==e){var r=n.querySelector('label[for="'.concat(t.id,'"]'));r&&r.setAttribute("aria-selected","false")}})}})})},exportInit:function(){jQuery(".frm_form_importer").on("submit",ji),jQuery(document.getElementById("frm_export_xml")).on("submit",Ei),jQuery("#frm_export_xml input, #frm_export_xml select").on("change",ki),jQuery('input[name="frm_import_file"]').on("change",Qi),document.querySelector('select[name="format"]').addEventListener("change",Ai),jQuery('input[name="frm_export_forms[]"]').on("click",qi),Bi(),jQuery(".frm-feature-banner .dismiss").on("click",function(e){e.preventDefault(),jQuery.post(ajaxurl,{action:"frm_dismiss_migrator",plugin:this.id,nonce:frmGlobal.nonce}),this.parentElement.remove()}),Ii(Si()),document.querySelector("#frm-export-select-all").addEventListener("change",function(e){document.querySelectorAll('[name="frm_export_forms[]"]').forEach(function(t){t.checked=e.target.checked})})},inboxBannerInit:function(){var e=document.getElementById("frm_banner");if(e){var t=e.querySelector(".frm-banner-dismiss");document.addEventListener("click",function(r){r.target===t&&Ji({action:"frm_inbox_dismiss",key:e.dataset.key,nonce:frmGlobal.nonce},function(){jQuery(e).fadeOut(400,function(){e.remove()})})})}},updateOpts:function(e,t,r){var n=Dn(e),o=aa(e)?"frm_bulk_products":"frm_import_options";jQuery.ajax({type:"POST",url:ajaxurl,data:{action:o,field_id:e,opts:t,separate:n,nonce:frmGlobal.nonce},success:function(t){document.getElementById("frm_field_".concat(e,"_opts")).innerHTML=t,wp.hooks.doAction("frm_after_bulk_edit_opts",e),Qn(e),void 0!==r&&(r.dialog("close"),document.getElementById("frm-update-bulk-opts").classList.remove("frm_loading_button"))}})},triggerRemoveLogic:function(e,t){jQuery("#frm_logic_".concat(e,"_").concat(t," .frm_remove_tag")).trigger("click")},downloadXML:function(e,t,r){var n="".concat(ajaxurl,"?action=frm_").concat(e,"_xml&ids=").concat(t);null!==r&&(n="".concat(n,"&is_template=").concat(r)),location.href=n},hooks:{applyFilters:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return(t=wp.hooks).applyFilters.apply(t,[e].concat(n))},addFilter:function(e,t,r){return wp.hooks.addFilter(e,"formidable",t,r)},doAction:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return(t=wp.hooks).doAction.apply(t,[e].concat(n))},addAction:function(e,t,r){return wp.hooks.addAction(e,"formidable",t,r)}},settings:{validate:{validateField:u,getRangeSettingsDefaults:m,validateNumberRangeSetting:_,validateStepSetting:p,validateRangeSettings:g}},applyZebraStriping:function(e,t){var r=document.querySelectorAll("".concat(e," tr").concat(t?":not(.".concat(t,")"):""));if(!(r.length<1)){var n=!0;r.forEach(function(e){e.classList.remove("frm-odd","frm-even"),e.classList.add(n?"frm-odd":"frm-even"),n=!n}),document.querySelectorAll(e).forEach(function(e){return e.classList.add("frm-zebra-striping")})}},initModal:ea,infoModal:K,offsetModalY:_i,adjustConditionalLogicOptionOrders:An,addRadioCheckboxOpt:In,installNewForm:Hi,toggleAddonState:Oi,purifyHtml:Tn,loadApiEmailForm:Mi,addMyEmailAddress:ca,fillDropdownOpts:qn,showSaveAndReloadModal:ii,clearSettingsBox:mt,deleteField:Wr,insertFormField:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(r){var n=T,o=0;"summary"===e&&(o=I.children('li[data-type="break"]').length>0?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:Object.assign(Le(e,0,n,o),{field_options:t}),success:function(t){r(t),setTimeout(function(){Wn(),ut(t,!0);var r=Be(t);r&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:r,fieldType:e,form_id:n})},10)},error:Ne})})},confirmLinkClick:V,handleInsertFieldByDraggingResponse:qe,handleAddFieldClickResponse:Ve,syncLayoutClasses:we,moveFieldSettings:Qo,maybeCollapseSettings:dn}},window.frmAdminBuild=frmAdminBuildJS(),jQuery(document).ready(function(){var e;frmAdminBuild.init(),document.querySelectorAll(".frm-dropdown-menu").forEach(function(e){e.classList.add("dropdown-menu");var t,r,n=e.querySelector(".frm-dropdown-toggle");n&&(n.hasAttribute("role")||n.setAttribute("role","button"),n.hasAttribute("tabindex")||n.setAttribute("tabindex",0)),"UL"===e.tagName&&(r=(r=(r=(r=(r=(r=(t=e).outerHTML).replace("<ul ","<div ")).replace("</ul>","</div>")).replaceAll("<li>",'<div class="dropdown-item">')).replaceAll('<li class="','<div class="dropdown-item ')).replaceAll("</li>","</div>"),t.outerHTML=r)}),null===(e=document.querySelector(".preview.dropdown .frm-dropdown-toggle"))||void 0===e||e.setAttribute("data-bs-toggle","dropdown"),document.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))})}),window.frm_show_div=function(e,t,r,n){t==r?jQuery(n+e).fadeIn("slow").css("visibility","visible"):jQuery(n+e).fadeOut("slow")},window.frmCheckAll=function(e,t){jQuery('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmCheckAllLevel=function(e,t,r){jQuery(".frm_catlevel_".concat(r)).children(".frm_checkbox").children("label").children('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmGetFieldValues=function(e,t,r,n,o,i){e&&jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_get_field_values&current_field=".concat(t,"&field_id=").concat(e,"&name=").concat(o,"&t=").concat(n,"&form_action=").concat(jQuery('input[name="frm_action"]').val(),"&nonce=").concat(frmGlobal.nonce),success:function(e){document.getElementById("frm_show_selected_values_".concat(t,"_").concat(r)).innerHTML=e,"function"==typeof i&&i()}})},r(4365),window.frmImportCsv=function(e){var t="";"undefined"!=typeof __FRMURLVARS&&(t=__FRMURLVARS),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_import_csv&nonce=".concat(frmGlobal.nonce,"&frm_skip_cookie=1").concat(t),success:function(t){var r=jQuery(".frm_admin_progress_bar").attr("aria-valuemax"),n=r-t,o=n/r*100;jQuery(".frm_admin_progress_bar").css("width","".concat(o,"%")).attr("aria-valuenow",n),parseInt(t,10)>0?(jQuery(".frm_csv_remaining").html(t),frmImportCsv(e)):(jQuery(document.getElementById("frm_import_message")).html(frm_admin_js.import_complete),setTimeout(function(){location.href="?page=formidable-entries&frm_action=list&form=".concat(e,"&import-message=1")},2e3))}})}})();
1 +/* exported frm_add_logic_row, frm_remove_tag, frm_show_div, frmCheckAll, frmCheckAllLevel */
2 +
3 +var frmAdminBuild;
4 +
5 +var FrmFormsConnect = window.FrmFormsConnect || ( function( document, window, $ ) {
6 +
7 + /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl */
8 +
9 + var el = {
10 + licenseBox: document.getElementById( 'frm_license_top' ),
11 + messageBox: document.getElementsByClassName( 'frm_pro_license_msg' )[0],
12 + btn: document.getElementById( 'frm-settings-connect-btn' ),
13 + reset: document.getElementById( 'frm_reconnect_link' )
14 + };
15 +
16 + /**
17 + * Public functions and properties.
18 + *
19 + * @since 4.03
20 + *
21 + * @type {Object}
22 + */
23 + var app = {
24 +
25 + /**
26 + * Register connect button event.
27 + *
28 + * @since 4.03
29 + */
30 + init: function() {
31 + $( document.getElementById( 'frm_deauthorize_link' ) ).on( 'click', app.deauthorize );
32 + $( '.frm_authorize_link' ).on( 'click', app.authorize );
33 + if ( el.reset !== null ) {
34 + $( el.reset ).on( 'click', app.reauthorize );
35 + }
36 +
37 + $( el.btn ).on( 'click', function( e ) {
38 + e.preventDefault();
39 + app.gotoUpgradeUrl();
40 + });
41 +
42 + window.addEventListener( 'message', function( msg ) {
43 + if ( msg.origin.replace( /\/$/, '' ) !== frmGlobal.app_url.replace( /\/$/, '' ) ) {
44 + return;
45 + }
46 +
47 + if ( ! msg.data || 'object' !== typeof msg.data ) {
48 + console.error( 'Messages from "' + frmGlobal.app_url + '" must contain an api key string.' );
49 + return;
50 + }
51 +
52 + app.updateForm( msg.data );
53 + });
54 +
55 + jQuery( document ).on( 'mouseover', '#frm_new_form_modal .frm-selectable', function() {
56 + var $item = jQuery( this ),
57 + $icons = $item.find( '.frm-hover-icons' ),
58 + $clone;
59 +
60 + if ( ! $icons.length ) {
61 + $clone = jQuery( '#frm-hover-icons-template' ).clone();
62 + $clone.removeAttr( 'id' );
63 + $item.append( $clone );
64 + }
65 +
66 + $icons.show();
67 + });
68 +
69 + jQuery( document ).on( 'mouseout', '#frm_new_form_modal .frm-selectable', function() {
70 + var $item = jQuery( this ),
71 + $icons = $item.find( '.frm-hover-icons' );
72 +
73 + if ( $icons.length ) {
74 + $icons.hide();
75 + }
76 + });
77 + },
78 +
79 + /**
80 + * Go to upgrade url.
81 + *
82 + * @since 4.03
83 + */
84 + gotoUpgradeUrl: function() {
85 + var w = window.open( frmGlobal.app_url + '/api-connect/', '_blank', 'location=no,width=500,height=730,scrollbars=0' );
86 + w.focus();
87 + },
88 +
89 + updateForm: function( response ) {
90 +
91 + // Start spinner.
92 + var btn = el.btn;
93 + btn.classList.add( 'frm_loading_button' );
94 +
95 + if ( response.url !== '' ) {
96 + app.showProgress({
97 + success: true,
98 + message: 'Installing...'
99 + });
100 + var fallback = setTimeout( function() {
101 + app.showProgress({
102 + success: true,
103 + message: 'Installing is taking longer than expected. <a class="frm-install-addon button button-primary frm-button-primary" rel="' + response.url + '" aria-label="Install">Install Now</a>'
104 + });
105 + }, 10000 );
106 + $.ajax({
107 + type: 'POST',
108 + url: ajaxurl,
109 + dataType: 'json',
110 + data: {
111 + action: 'frm_connect',
112 + plugin: response.url,
113 + nonce: frmGlobal.nonce
114 + },
115 + success: function() {
116 + clearTimeout( fallback );
117 + app.activateKey( response );
118 + },
119 + error: function( xhr, textStatus, e ) {
120 + clearTimeout( fallback );
121 + btn.classList.remove( 'frm_loading_button' );
122 + app.showMessage({
123 + success: false,
124 + message: e
125 + });
126 + }
127 + });
128 + } else if ( response.key !== '' ) {
129 + app.activateKey( response );
130 + }
131 + },
132 +
133 + activateKey: function( response ) {
134 + var btn = el.btn;
135 + if ( response.key === '' ) {
136 + btn.classList.remove( 'frm_loading_button' );
137 + } else {
138 + app.showProgress({
139 + success: true,
140 + message: 'Activating...'
141 + });
142 + $.ajax({
143 + type: 'POST',
144 + url: ajaxurl,
145 + dataType: 'json',
146 + data: {
147 + action: 'frm_addon_activate',
148 + license: response.key,
149 + plugin: 'formidable_pro',
150 + wpmu: 0,
151 + nonce: frmGlobal.nonce
152 + },
153 + success: function( msg ) {
154 + btn.classList.remove( 'frm_loading_button' );
155 +
156 + if ( msg.success === true ) {
157 + el.licenseBox.classList.replace( 'frm_unauthorized_box', 'frm_authorized_box' );
158 + }
159 +
160 + app.showMessage( msg );
161 + },
162 + error: function( xhr, textStatus, e ) {
163 + btn.classList.remove( 'frm_loading_button' );
164 + app.showMessage({
165 + success: false,
166 + message: e
167 + });
168 + }
169 + });
170 + }
171 + },
172 +
173 + /* Manual license authorization */
174 + authorize: function() {
175 + /*jshint validthis:true */
176 + var button = this;
177 + var pluginSlug = this.getAttribute( 'data-plugin' );
178 + var input = document.getElementById( 'edd_' + pluginSlug + '_license_key' );
179 + var license = input.value;
180 + var wpmu = document.getElementById( 'proplug-wpmu' );
181 + this.classList.add( 'frm_loading_button' );
182 + if ( wpmu === null ) {
183 + wpmu = 0;
184 + } else if ( wpmu.checked ) {
185 + wpmu = 1;
186 + } else {
187 + wpmu = 0;
188 + }
189 +
190 + $.ajax({
191 + type: 'POST', url: ajaxurl, dataType: 'json',
192 + data: {
193 + action: 'frm_addon_activate',
194 + license: license,
195 + plugin: pluginSlug,
196 + wpmu: wpmu,
197 + nonce: frmGlobal.nonce
198 + },
199 + success: function( msg ) {
200 + app.afterAuthorize( msg, input );
201 + button.classList.remove( 'frm_loading_button' );
202 + }
203 + });
204 + },
205 +
206 + afterAuthorize: function( msg, input ) {
207 + if ( msg.success === true ) {
208 + input.value = '•••••••••••••••••••';
209 + }
210 +
211 + app.showMessage( msg );
212 + },
213 +
214 + showProgress: function( msg ) {
215 + var messageBox = el.messageBox;
216 + if ( msg.success === true ) {
217 + messageBox.classList.remove( 'frm_error_style' );
218 + messageBox.classList.add( 'frm_message', 'frm_updated_message' );
219 + } else {
220 + messageBox.classList.add( 'frm_error_style' );
221 + messageBox.classList.remove( 'frm_message', 'frm_updated_message' );
222 + }
223 + messageBox.classList.remove( 'frm_hidden' );
224 + messageBox.innerHTML = msg.message;
225 + },
226 +
227 + showMessage: function( msg ) {
228 + var messageBox = el.messageBox;
229 +
230 + if ( msg.success === true ) {
231 + var d = el.licenseBox;
232 + d.className = d.className.replace( 'frm_unauthorized_box', 'frm_authorized_box' );
233 + messageBox.classList.remove( 'frm_error_style' );
234 + messageBox.classList.add( 'frm_message', 'frm_updated_message' );
235 + } else {
236 + messageBox.classList.add( 'frm_error_style' );
237 + messageBox.classList.remove( 'frm_message', 'frm_updated_message' );
238 + }
239 +
240 + messageBox.classList.remove( 'frm_hidden' );
241 + messageBox.innerHTML = msg.message;
242 + if ( msg.message !== '' ) {
243 + setTimeout( function() {
244 + messageBox.innerHTML = '';
245 + messageBox.classList.add( 'frm_hidden' );
246 + messageBox.classList.remove( 'frm_error_style', 'frm_message', 'frm_updated_message' );
247 + }, 10000 );
248 + var refreshPage = document.querySelectorAll( '#frm-welcome' );
249 + if ( refreshPage.length > 0 ) {
250 + window.location.reload();
251 + }
252 + }
253 + },
254 +
255 + /* Clear the site license cache */
256 + reauthorize: function() {
257 + /*jshint validthis:true */
258 + this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;float:none"></span>';
259 +
260 + $.ajax({
261 + type: 'POST',
262 + url: ajaxurl,
263 + dataType: 'json',
264 + data: {
265 + action: 'frm_reset_cache',
266 + plugin: 'formidable_pro',
267 + nonce: frmGlobal.nonce
268 + },
269 + success: function( msg ) {
270 + el.reset.innerHTML = msg.message;
271 + if ( el.reset.getAttribute( 'data-refresh' ) === '1' ) {
272 + window.location.reload();
273 + }
274 + }
275 + });
276 + return false;
277 + },
278 +
279 + deauthorize: function() {
280 + /*jshint validthis:true */
281 + if ( ! confirm( frmGlobal.deauthorize ) ) {
282 + return false;
283 + }
284 + var pluginSlug = this.getAttribute( 'data-plugin' ),
285 + input = document.getElementById( 'edd_' + pluginSlug + '_license_key' ),
286 + license = input.value,
287 + link = this;
288 +
289 + this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;"></span>';
290 +
291 + $.ajax({
292 + type: 'POST',
293 + url: ajaxurl,
294 + data: {
295 + action: 'frm_addon_deactivate',
296 + license: license,
297 + plugin: pluginSlug,
298 + nonce: frmGlobal.nonce
299 + },
300 + success: function() {
301 + el.licenseBox.className = el.licenseBox.className.replace( 'frm_authorized_box', 'frm_unauthorized_box' );
302 + input.value = '';
303 + link.innerHTML = '';
304 + }
305 + });
306 + return false;
307 + }
308 + };
309 +
310 + // Provide access to public functions/properties.
311 + return app;
312 +
313 +}( document, window, jQuery ) );
314 +
315 +function frmAdminBuildJS() {
316 + //'use strict';
317 +
318 + /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl, fromDom */
319 +
320 + const { tag, div, span, a, svg, img } = frmDom;
321 + const { doJsonFetch } = frmDom.ajax;
322 + const icons = {
323 + save: svg({ href: '#frm_save_icon' }),
324 + drag: svg({ href: '#frm_drag_icon', classList: [ 'frm_drag_icon', 'frm-drag' ] })
325 + };
326 +
327 + let $newFields = jQuery( document.getElementById( 'frm-show-fields' ) ),
328 + builderForm = document.getElementById( 'new_fields' ),
329 + thisForm = document.getElementById( 'form_id' ),
330 + copyHelper = false,
331 + fieldsUpdated = 0,
332 + thisFormId = 0,
333 + autoId = 0,
334 + optionMap = {},
335 + lastNewActionIdReturned = 0;
336 +
337 + const { __ } = wp.i18n;
338 + let debouncedSyncAfterDragAndDrop, postBodyContent;
339 +
340 + if ( thisForm !== null ) {
341 + thisFormId = thisForm.value;
342 + }
343 +
344 + // Global settings
345 + var s;
346 +
347 + function showElement( element ) {
348 + element[0].style.display = '';
349 + }
350 +
351 + function hideElement( element ) {
352 + element[0].style.display = 'none';
353 + }
354 +
355 + function empty( $obj ) {
356 + if ( $obj !== null ) {
357 + while ( $obj.firstChild ) {
358 + $obj.removeChild( $obj.firstChild );
359 + }
360 + }
361 + }
362 +
363 + function addClass( $obj, className ) {
364 + if ( $obj.classList ) {
365 + $obj.classList.add( className );
366 + } else {
367 + $obj.className += ' ' + className;
368 + }
369 + }
370 +
371 + function confirmClick( e ) {
372 + /*jshint validthis:true */
373 + e.stopPropagation();
374 + e.preventDefault();
375 + confirmLinkClick( this );
376 + }
377 +
378 + function confirmLinkClick( link ) {
379 + var message = link.getAttribute( 'data-frmverify' );
380 +
381 + if ( message === null || link.id === 'frm-confirmed-click' ) {
382 + return true;
383 + } else {
384 + return confirmModal( link );
385 + }
386 + }
387 +
388 + function confirmModal( link ) {
389 + var caution, verify, $confirmMessage, frmCaution, i, dataAtts,
390 + $info = initModal( '#frm_confirm_modal', '400px' ),
391 + continueButton = document.getElementById( 'frm-confirmed-click' );
392 +
393 + if ( $info === false ) {
394 + return false;
395 + }
396 +
397 + caution = link.getAttribute( 'data-frmcaution' );
398 + verify = link.getAttribute( 'data-frmverify' );
399 + $confirmMessage = jQuery( '.frm-confirm-msg' );
400 + $confirmMessage.empty();
401 +
402 + if ( caution ) {
403 + frmCaution = document.createElement( 'div' );
404 + frmCaution.classList.add( 'frm-caution' );
405 + frmCaution.appendChild( document.createTextNode( caution ) );
406 + $confirmMessage.append( frmCaution );
407 + }
408 +
409 + if ( verify ) {
410 + $confirmMessage.append( document.createTextNode( verify ) );
411 + }
412 +
413 + removeAtts = continueButton.dataset;
414 + for ( i in dataAtts ) {
415 + continueButton.removeAttribute( 'data-' + i );
416 + }
417 +
418 + dataAtts = link.dataset;
419 + for ( i in dataAtts ) {
420 + if ( i !== 'frmverify' ) {
421 + continueButton.setAttribute( 'data-' + i, dataAtts[i]);
422 + }
423 + }
424 +
425 + $info.dialog( 'open' );
426 + continueButton.setAttribute( 'href', link.getAttribute( 'href' ) );
427 + return false;
428 + }
429 +
430 + function infoModal( msg ) {
431 + var $info = initModal( '#frm_info_modal', '400px' );
432 +
433 + if ( $info === false ) {
434 + return false;
435 + }
436 +
437 + jQuery( '.frm-info-msg' ).html( msg );
438 +
439 + $info.dialog( 'open' );
440 + return false;
441 + }
442 +
443 + function toggleItem( e ) {
444 + /*jshint validthis:true */
445 + var toggle = this.getAttribute( 'data-frmtoggle' ),
446 + text = this.getAttribute( 'data-toggletext' ),
447 + items = jQuery( toggle );
448 +
449 + e.preventDefault();
450 +
451 + if ( items.is( ':visible' ) ) {
452 + items.show();
453 + } else {
454 + items.hide();
455 + }
456 +
457 + if ( text !== null && text !== '' ) {
458 + this.setAttribute( 'data-toggletext', this.innerHTML );
459 + this.innerHTML = text;
460 + }
461 +
462 + return false;
463 + }
464 +
465 + function hideShowItem( e ) {
466 + /*jshint validthis:true */
467 + var hide = this.getAttribute( 'data-frmhide' ),
468 + show = this.getAttribute( 'data-frmshow' ),
469 + toggleClass = this.getAttribute( 'data-toggleclass' );
470 +
471 + e.preventDefault();
472 + if ( toggleClass === null ) {
473 + toggleClass = 'frm_hidden';
474 + }
475 +
476 + if ( hide !== null ) {
477 + jQuery( hide ).addClass( toggleClass );
478 + }
479 +
480 + if ( show !== null ) {
481 + jQuery( show ).removeClass( toggleClass );
482 + }
483 +
484 + var current = this.parentNode.querySelectorAll( 'a.current' );
485 + if ( current !== null ) {
486 + for ( var i = 0; i < current.length; i++ ) {
487 + current[ i ].classList.remove( 'current' );
488 + }
489 + this.classList.add( 'current' );
490 + }
491 +
492 + return false;
493 + }
494 +
495 + function setupMenuOffset() {
496 + window.onscroll = document.documentElement.onscroll = setMenuOffset;
497 + setMenuOffset();
498 + }
499 +
500 + function setMenuOffset() {
501 + var fields = document.getElementById( 'frm_adv_info' );
502 + if ( fields === null ) {
503 + return;
504 + }
505 +
506 + var currentOffset = document.documentElement.scrollTop || document.body.scrollTop; // body for Safari
507 + if ( currentOffset === 0 ) {
508 + fields.classList.remove( 'frm_fixed' );
509 + return;
510 + }
511 +
512 + var posEle = document.getElementById( 'frm_position_ele' );
513 + if ( posEle === null ) {
514 + return;
515 + }
516 +
517 + var eleOffset = jQuery( posEle ).offset();
518 + var offset = eleOffset.top;
519 + var desiredOffset = offset - currentOffset;
520 + var menuHeight = 0;
521 +
522 + var menu = document.getElementById( 'wpadminbar' );
523 + if ( menu !== null ) {
524 + menuHeight = menu.offsetHeight;
525 + }
526 +
527 + if ( desiredOffset < menuHeight ) {
528 + desiredOffset = menuHeight;
529 + }
530 +
531 + if ( desiredOffset > menuHeight ) {
532 + fields.classList.remove( 'frm_fixed' );
533 + } else {
534 + fields.classList.add( 'frm_fixed' );
535 + if ( desiredOffset !== 32 ) {
536 + fields.style.top = desiredOffset + 'px';
537 + }
538 + }
539 + }
540 +
541 + function loadTooltips() {
542 + var wrapClass = jQuery( '.wrap, .frm_wrap' ),
543 + confirmModal = document.getElementById( 'frm_confirm_modal' ),
544 + doAction = false,
545 + confirmedBulkDelete = false;
546 +
547 + jQuery( confirmModal ).on( 'click', '[data-deletefield]', deleteFieldConfirmed );
548 + jQuery( confirmModal ).on( 'click', '[data-removeid]', removeThisTag );
549 + jQuery( confirmModal ).on( 'click', '[data-trashtemplate]', trashTemplate );
550 +
551 + wrapClass.on( 'click', '.frm_remove_tag, .frm_remove_form_action', removeThisTag );
552 + wrapClass.on( 'click', 'a[data-frmverify]', confirmClick );
553 + wrapClass.on( 'click', 'a[data-frmtoggle]', toggleItem );
554 + wrapClass.on( 'click', 'a[data-frmhide], a[data-frmshow]', hideShowItem );
555 + wrapClass.on( 'click', '.widget-top,a.widget-action', clickWidget );
556 +
557 + wrapClass.on( 'mouseenter.frm', '.frm_bstooltip, .frm_help', function() {
558 + jQuery( this ).off( 'mouseenter.frm' );
559 +
560 + jQuery( '.frm_bstooltip, .frm_help' ).tooltip( );
561 + jQuery( this ).tooltip( 'show' );
562 + });
563 +
564 + jQuery( '.frm_bstooltip, .frm_help' ).tooltip( );
565 +
566 + jQuery( document ).on( 'click', '#doaction, #doaction2', function( event ) {
567 + var isTop = this.id === 'doaction',
568 + suffix = isTop ? 'top' : 'bottom',
569 + bulkActionSelector = document.getElementById( 'bulk-action-selector-' + suffix ),
570 + confirmBulkDelete = document.getElementById( 'confirm-bulk-delete-' + suffix );
571 +
572 + if ( bulkActionSelector !== null && confirmBulkDelete !== null ) {
573 + doAction = this;
574 +
575 + if ( ! confirmedBulkDelete && bulkActionSelector.value === 'bulk_delete' ) {
576 + event.preventDefault();
577 + confirmLinkClick( confirmBulkDelete );
578 + return false;
579 + }
580 + } else {
581 + doAction = false;
582 + }
583 + });
584 +
585 + jQuery( document ).on( 'click', '#frm-confirmed-click', function( event ) {
586 + if ( doAction === false ) {
587 + return;
588 + }
589 +
590 + if ( this.getAttribute( 'href' ) === 'confirm-bulk-delete' ) {
591 + event.preventDefault();
592 + confirmedBulkDelete = true;
593 + doAction.click();
594 + return false;
595 + }
596 + });
597 + }
598 +
599 + function deleteTooltips() {
600 + document.querySelectorAll( '.tooltip' ).forEach(
601 + function( tooltip ) {
602 + tooltip.remove();
603 + }
604 + );
605 + }
606 +
607 + function removeThisTag() {
608 + /*jshint validthis:true */
609 + let show, hide, removeMore;
610 +
611 + if ( parseInt( this.getAttribute( 'data-skip-frm-js' ) ) || confirmLinkClick( this ) === false ) {
612 + return;
613 + }
614 +
615 + const deleteButton = jQuery( this );
616 + const id = deleteButton.attr( 'data-removeid' );
617 +
618 + show = deleteButton.attr( 'data-showlast' );
619 + if ( typeof show === 'undefined' ) {
620 + show = '';
621 + }
622 +
623 + hide = deleteButton.attr( 'data-hidelast' );
624 + if ( typeof hide === 'undefined' ) {
625 + hide = '';
626 + }
627 +
628 + removeMore = deleteButton.attr( 'data-removemore' );
629 +
630 + if ( show !== '' ) {
631 + if ( deleteButton.closest( '.frm_add_remove' ).find( '.frm_remove_tag:visible' ).length > 1 ) {
632 + show = '';
633 + hide = '';
634 + }
635 + } else if ( id.indexOf( 'frm_postmeta_' ) === 0 ) {
636 + if ( jQuery( '#frm_postmeta_rows .frm_postmeta_row' ).length < 2 ) {
637 + show = '.frm_add_postmeta_row.button';
638 + }
639 + if ( jQuery( '.frm_toggle_cf_opts' ).length && jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().length ) {
640 + if ( show !== '' ) {
641 + show += ',';
642 + }
643 + show += '#' + jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().attr( 'id' ) + ' .frm_toggle_cf_opts';
644 + }
645 + }
646 +
647 + const $fadeEle = jQuery( document.getElementById( id ) );
648 + $fadeEle.fadeOut( 400, function() {
649 + $fadeEle.remove();
650 + fieldUpdated();
651 +
652 + if ( hide !== '' ) {
653 + jQuery( hide ).hide();
654 + }
655 +
656 + if ( show !== '' ) {
657 + jQuery( show + ' a,' + show ).removeClass( 'frm_hidden' ).fadeIn( 'slow' );
658 + }
659 +
660 + if ( this.closest( '.frm_form_action_settings' ) ) {
661 + const type = this.closest( '.frm_form_action_settings' ).querySelector( '.frm_action_name' ).value;
662 + afterActionRemoved( type );
663 + }
664 + });
665 +
666 + if ( typeof removeMore !== 'undefined' ) {
667 + removeMore = jQuery( removeMore );
668 + removeMore.fadeOut( 400, function() {
669 + removeMore.remove();
670 + });
671 + }
672 +
673 + if ( show !== '' ) {
674 + jQuery( this ).closest( '.frm_logic_rows' ).fadeOut( 'slow' );
675 + }
676 +
677 + return false;
678 + }
679 +
680 + function afterActionRemoved( type ) {
681 + checkActiveAction( type );
682 +
683 + const hookName = 'frm_after_action_removed';
684 + const hookArgs = { type };
685 + wp.hooks.doAction( hookName, hookArgs );
686 + }
687 +
688 + function clickWidget( event, b ) {
689 + /*jshint validthis:true */
690 + if ( typeof b === 'undefined' ) {
691 + b = this;
692 + }
693 +
694 + popCalcFields( b, false );
695 +
696 + const cont = jQuery( b ).closest( '.frm_form_action_settings' );
697 + const target = event.target;
698 +
699 + if ( cont.length && typeof target !== 'undefined' ) {
700 + const className = target.parentElement.className;
701 + if ( 'string' === typeof className ) {
702 + if ( className.indexOf( 'frm_email_icons' ) > -1 || className.indexOf( 'frm_toggle' ) > -1 ) {
703 + // clicking on delete icon shouldn't open it
704 + event.stopPropagation();
705 + return;
706 + }
707 + }
708 + }
709 +
710 + let inside = cont.children( '.widget-inside' );
711 +
712 + if ( cont.length && inside.find( 'p, div, table' ).length < 1 ) {
713 + const actionId = cont.find( 'input[name$="[ID]"]' ).val();
714 + const actionType = cont.find( 'input[name$="[post_excerpt]"]' ).val();
715 + if ( actionType ) {
716 + inside.html( '<span class="frm-wait frm_spinner"></span>' );
717 + cont.find( '.spinner' ).fadeIn( 'slow' );
718 + jQuery.ajax({
719 + type: 'POST',
720 + url: ajaxurl,
721 + data: {
722 + action: 'frm_form_action_fill',
723 + action_id: actionId,
724 + action_type: actionType,
725 + nonce: frmGlobal.nonce
726 + },
727 + success: function( html ) {
728 + inside.html( html );
729 + initiateMultiselect();
730 + showInputIcon( '#' + cont.attr( 'id' ) );
731 + frmDom.autocomplete.initAutocomplete( 'page', inside );
732 + jQuery( b ).trigger( 'frm-action-loaded' );
733 + }
734 + });
735 + }
736 + }
737 +
738 + jQuery( b ).closest( '.frm_field_box' ).siblings().find( '.widget-inside' ).slideUp( 'fast' );
739 + if ( ( typeof b.className !== 'undefined' && b.className.indexOf( 'widget-action' ) !== -1 ) || jQuery( b ).closest( '.start_divider' ).length < 1 ) {
740 + return;
741 + }
742 +
743 + inside = jQuery( b ).closest( 'div.widget' ).children( '.widget-inside' );
744 + if ( inside.is( ':hidden' ) ) {
745 + inside.slideDown( 'fast' );
746 + } else {
747 + inside.slideUp( 'fast' );
748 + }
749 + }
750 +
751 + function clickNewTab() {
752 + /*jshint validthis:true */
753 + var t = this.getAttribute( 'href' ),
754 + c = t.replace( '#', '.' ),
755 + $link = jQuery( this );
756 +
757 + if ( typeof t === 'undefined' ) {
758 + return false;
759 + }
760 +
761 + $link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' );
762 + $link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide();
763 + document.getElementById( t.replace( '#', '' ) ).style.display = 'block';
764 +
765 + if ( this.id === 'frm_insert_fields_tab' ) {
766 + clearSettingsBox();
767 + }
768 + return false;
769 + }
770 +
771 + function clickTab( link, auto ) {
772 + link = jQuery( link );
773 + var t = link.attr( 'href' );
774 + if ( typeof t === 'undefined' ) {
775 + return;
776 + }
777 +
778 + var c = t.replace( '#', '.' );
779 +
780 + link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' );
781 + if ( link.closest( 'div' ).find( '.tabs-panel' ).length ) {
782 + link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide();
783 + } else {
784 + if ( document.getElementById( 'form_global_settings' ) !== null ) {
785 + /* global settings */
786 + var ajax = link.data( 'frmajax' );
787 + link.closest( '.frm_wrap' ).find( '.tabs-panel, .hide_with_tabs' ).hide();
788 + if ( typeof ajax !== 'undefined' && ajax == '1' ) {
789 + loadSettingsTab( t );
790 + }
791 + } else {
792 + /* form settings page */
793 + jQuery( '#frm-categorydiv .tabs-panel, .hide_with_tabs' ).hide();
794 + }
795 + }
796 + jQuery( t ).show();
797 + jQuery( c ).show();
798 +
799 + hideShortcodes();
800 +
801 + if ( auto !== 'auto' ) {
802 + // Hide success message on tab change.
803 + jQuery( '.frm_updated_message' ).hide();
804 + jQuery( '.frm_warning_style' ).hide();
805 + }
806 +
807 + if ( jQuery( link ).closest( '#frm_adv_info' ).length ) {
808 + return;
809 + }
810 +
811 + if ( jQuery( '.frm_form_settings' ).length ) {
812 + jQuery( '.frm_form_settings' ).attr( 'action', '?page=formidable&frm_action=settings&id=' + jQuery( '.frm_form_settings input[name="id"]' ).val() + '&t=' + t.replace( '#', '' ) );
813 + } else {
814 + jQuery( '.frm_settings_form' ).attr( 'action', '?page=formidable-settings&t=' + t.replace( '#', '' ) );
815 + }
816 + }
817 +
818 + function setupSortable( sortableSelector ) {
819 + document.querySelectorAll( sortableSelector ).forEach(
820 + list => {
821 + makeDroppable( list );
822 + Array.from( list.children ).forEach( child => makeDraggable( child, '.frm-move' ) );
823 +
824 + const $sectionTitle = jQuery( list ).children( '[data-type="divider"]' ).children( '.divider_section_only' );
825 + if ( $sectionTitle.length ) {
826 + makeDroppable( $sectionTitle );
827 + }
828 + }
829 + );
830 + setupFieldOptionSorting( jQuery( '#frm_builder_page' ) );
831 + }
832 +
833 + function makeDroppable( list ) {
834 + jQuery( list ).droppable({
835 + accept: '.frmbutton, li.frm_field_box',
836 + deactivate: handleFieldDrop,
837 + over: onDragOverDroppable,
838 + out: onDraggableLeavesDroppable,
839 + tolerance: 'pointer'
840 + });
841 + }
842 +
843 + function onDragOverDroppable( event, ui ) {
844 + const droppable = getDroppableForOnDragOver( event.target );
845 + const draggable = ui.draggable[0];
846 +
847 + if ( ! allowDrop( draggable, droppable ) ) {
848 + droppable.classList.remove( 'frm-over-droppable' );
849 + jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' );
850 + return;
851 + }
852 +
853 + document.querySelectorAll( '.frm-over-droppable' ).forEach( droppable => droppable.classList.remove( 'frm-over-droppable' ) );
854 + droppable.classList.add( 'frm-over-droppable' );
855 + jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' );
856 + }
857 +
858 + /**
859 + * Maybe change the droppable.
860 + * Section titles are made droppable, but are not a list, so we need to change the droppable to the section's list instead.
861 + *
862 + * @param {Element} droppable
863 + * @returns {Element}
864 + */
865 + function getDroppableForOnDragOver( droppable ) {
866 + if ( droppable.classList.contains( 'divider_section_only' ) ) {
867 + droppable = jQuery( droppable ).nextAll( '.start_divider.frm_sorting' ).get( 0 );
868 + }
869 + return droppable;
870 + }
871 +
872 + function onDraggableLeavesDroppable( event ) {
873 + const droppable = event.target;
874 + droppable.classList.remove( 'frm-over-droppable' );
875 + }
876 +
877 + function makeDraggable( draggable, handle ) {
878 + const settings = {
879 + helper: getDraggableHelper,
880 + revert: 'invalid',
881 + delay: 10,
882 + start: handleDragStart,
883 + stop: handleDragStop,
884 + drag: handleDrag,
885 + cursor: 'grabbing',
886 + cursorAt: {
887 + top: 0,
888 + left: 90 // The width of draggable button is 180. 90 should center the draggable on the cursor.
889 + }
890 + };
891 + if ( 'string' === typeof handle ) {
892 + settings.handle = handle;
893 + }
894 + jQuery( draggable ).draggable( settings );
895 + }
896 +
897 + function getDraggableHelper( event ) {
898 + const draggable = event.delegateTarget;
899 +
900 + if ( isFieldGroup( draggable ) ) {
901 + const newTextFieldClone = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_ttext' ).cloneNode( true );
902 + newTextFieldClone.querySelector( 'use' ).setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_field_group_layout_icon' );
903 + newTextFieldClone.querySelector( 'span' ).textContent = __( 'Field Group' );
904 + newTextFieldClone.classList.add( 'frm_field_box' );
905 + newTextFieldClone.classList.add( 'ui-sortable-helper' );
906 + return newTextFieldClone;
907 + }
908 +
909 + let copyTarget;
910 + const isNewField = draggable.classList.contains( 'frmbutton' );
911 + if ( isNewField ) {
912 + copyTarget = draggable.cloneNode( true );
913 + copyTarget.classList.add( 'ui-sortable-helper' );
914 + draggable.classList.add( 'frm-new-field' );
915 + return copyTarget;
916 + }
917 +
918 + if ( draggable.hasAttribute( 'data-ftype' ) ) {
919 + const fieldType = draggable.getAttribute( 'data-ftype' );
920 + copyTarget = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_t' + fieldType );
921 + copyTarget = copyTarget.cloneNode( true );
922 + copyTarget.classList.add( 'form-field' );
923 +
924 + copyTarget.classList.add( 'ui-sortable-helper' );
925 +
926 + if ( copyTarget ) {
927 + return copyTarget.cloneNode( true );
928 + }
929 + }
930 +
931 + return div({ className: 'frmbutton' });
932 + }
933 +
934 + function handleDragStart( event, ui ) {
935 + const container = postBodyContent;
936 + container.classList.add( 'frm-dragging-field' );
937 +
938 + document.body.classList.add( 'frm-dragging' );
939 + ui.helper.addClass( 'frm-sortable-helper' );
940 + ui.helper.initialOffset = container.scrollTop;
941 +
942 + event.target.classList.add( 'frm-drag-fade' );
943 +
944 + unselectFieldGroups();
945 + deleteEmptyDividerWrappers();
946 + maybeRemoveGroupHoverTarget();
947 + closeOpenFieldDropdowns();
948 + deleteTooltips();
949 + }
950 +
951 + function handleDragStop() {
952 + const container = postBodyContent;
953 + container.classList.remove( 'frm-dragging-field' );
954 + document.body.classList.remove( 'frm-dragging' );
955 +
956 + const fade = document.querySelector( '.frm-drag-fade' );
957 + if ( fade ) {
958 + fade.classList.remove( 'frm-drag-fade' );
959 + }
960 + }
961 +
962 + function handleDrag( event, ui ) {
963 + const draggable = event.target;
964 + const droppable = getDroppableTarget();
965 +
966 + let placeholder = document.getElementById( 'frm_drag_placeholder' );
967 +
968 + if ( ! allowDrop( draggable, droppable ) ) {
969 + if ( placeholder ) {
970 + placeholder.remove();
971 + }
972 + return;
973 + }
974 +
975 + if ( ! placeholder ) {
976 + placeholder = tag( 'li', {
977 + id: 'frm_drag_placeholder',
978 + className: 'sortable-placeholder'
979 + });
980 + }
981 +
982 + // Sync the y position of the draggable so it still follows the cursor after scrolling up and down the field list.
983 + ui.helper.get( 0 ).style.transform = 'translateY(' + getDragOffset( ui.helper ) + 'px)';
984 +
985 + if ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) ) {
986 + placeholder.style.left = 0;
987 + handleDragOverYAxis({ droppable, y: event.clientY, placeholder });
988 + return;
989 + }
990 +
991 + placeholder.style.top = '';
992 + handleDragOverFieldGroup({ droppable, x: event.clientX, placeholder });
993 + }
994 +
995 + function getDragOffset( $helper ) {
996 + return postBodyContent.scrollTop - $helper.initialOffset;
997 + }
998 +
999 + function getDroppableTarget() {
1000 + let droppable = document.getElementById( 'frm-show-fields' );
1001 + while ( droppable.querySelector( '.frm-over-droppable' ) ) {
1002 + droppable = droppable.querySelector( '.frm-over-droppable' );
1003 + }
1004 + if ( 'frm-show-fields' === droppable.id && ! droppable.classList.contains( 'frm-over-droppable' ) ) {
1005 + droppable = false;
1006 + }
1007 + return droppable;
1008 + }
1009 +
1010 + function handleFieldDrop( _, ui ) {
1011 + const draggable = ui.draggable[0];
1012 + const placeholder = document.getElementById( 'frm_drag_placeholder' );
1013 +
1014 + if ( ! placeholder ) {
1015 + ui.helper.remove();
1016 + debouncedSyncAfterDragAndDrop();
1017 + return;
1018 + }
1019 +
1020 + maybeOpenCollapsedPage( placeholder );
1021 +
1022 + const $previousFieldContainer = ui.helper.parent();
1023 + const previousSection = ui.helper.get( 0 ).closest( 'ul.frm_sorting' );
1024 + const newSection = placeholder.closest( 'ul.frm_sorting' );
1025 +
1026 + if ( draggable.classList.contains( 'frm-new-field' ) ) {
1027 + insertNewFieldByDragging( draggable.id );
1028 + } else {
1029 + moveFieldThatAlreadyExists( draggable, placeholder );
1030 + }
1031 +
1032 + const previousSectionId = previousSection && previousSection.classList.contains( 'start_divider' ) ? parseInt( previousSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0;
1033 + const newSectionId = newSection.classList.contains( 'start_divider' ) ? parseInt( newSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0;
1034 +
1035 + placeholder.remove();
1036 + ui.helper.remove();
1037 +
1038 + const $previousContainerFields = $previousFieldContainer.length ? getFieldsInRow( $previousFieldContainer ) : [];
1039 + maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields );
1040 + maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields );
1041 +
1042 + if ( previousSectionId !== newSectionId ) {
1043 + updateFieldAfterMovingBetweenSections( jQuery( draggable ) );
1044 + }
1045 +
1046 + debouncedSyncAfterDragAndDrop();
1047 + }
1048 +
1049 + /**
1050 + * If a page if collapsed, expand it before dragging since only the page break will move.
1051 + *
1052 + * @param {Element} placeholder
1053 + * @returns {void}
1054 + */
1055 + function maybeOpenCollapsedPage( placeholder ) {
1056 + if ( ! placeholder.previousElementSibling || ! placeholder.previousElementSibling.classList.contains( 'frm-is-collapsed' ) ) {
1057 + return;
1058 + }
1059 +
1060 + const $pageBreakField = jQuery( placeholder ).prevUntil( '[data-type="break"]' );
1061 + if ( ! $pageBreakField.length ) {
1062 + return;
1063 + }
1064 +
1065 + const collapseButton = $pageBreakField.find( '.frm-collapse-page' ).get( 0 );
1066 + if ( collapseButton ) {
1067 + collapseButton.click();
1068 + }
1069 + }
1070 +
1071 + function maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields ) {
1072 + if ( ! $previousFieldContainer.length ) {
1073 + return;
1074 + }
1075 +
1076 + if ( $previousContainerFields.length ) {
1077 + syncLayoutClasses( $previousContainerFields.first() );
1078 + } else {
1079 + maybeDeleteAnEmptyFieldGroup( $previousFieldContainer.get( 0 ) );
1080 + }
1081 + }
1082 +
1083 + function maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields ) {
1084 + if ( 0 !== $previousContainerFields.length || 1 !== getFieldsInRow( jQuery( draggable.parentNode ) ).length ) {
1085 + syncLayoutClasses( jQuery( draggable ) );
1086 + }
1087 + }
1088 +
1089 + /**
1090 + * Remove an empty field group, but don't remove an empty section.
1091 + *
1092 + * @param {Element} previousFieldContainer
1093 + * @returns {void}
1094 + */
1095 + function maybeDeleteAnEmptyFieldGroup( previousFieldContainer ) {
1096 + const closestFieldBox = previousFieldContainer.closest( 'li.frm_field_box' );
1097 + if ( closestFieldBox && ! closestFieldBox.classList.contains( 'edit_field_type_divider' ) ) {
1098 + closestFieldBox.remove();
1099 + }
1100 + }
1101 +
1102 + function handleDragOverYAxis({ droppable, y, placeholder }) {
1103 + const $list = jQuery( droppable );
1104 +
1105 + let top;
1106 +
1107 + $children = $list.children().not( '.edit_field_type_end_divider' );
1108 + if ( 0 === $children.length ) {
1109 + $list.prepend( placeholder );
1110 + top = 0;
1111 + } else {
1112 + const insertAtIndex = determineIndexBasedOffOfMousePositionInList( $list, y );
1113 +
1114 + if ( insertAtIndex === $children.length ) {
1115 + const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) );
1116 + top = $lastChild.offset().top + $lastChild.outerHeight();
1117 + $list.append( placeholder );
1118 +
1119 + // Make sure nothing gets inserted after the end divider.
1120 + const $endDivider = $list.children( '.edit_field_type_end_divider' );
1121 + if ( $endDivider.length ) {
1122 + $list.append( $endDivider );
1123 + }
1124 + } else {
1125 + top = jQuery( $children.get( insertAtIndex ) ).offset().top;
1126 + jQuery( $children.get( insertAtIndex ) ).before( placeholder );
1127 + }
1128 + }
1129 +
1130 + top -= $list.offset().top;
1131 + placeholder.style.top = top + 'px';
1132 + }
1133 +
1134 + function determineIndexBasedOffOfMousePositionInList( $list, y ) {
1135 + const $items = $list.children().not( '.edit_field_type_end_divider' );
1136 + const length = $items.length;
1137 +
1138 + let index, item, itemTop, returnIndex;
1139 +
1140 + returnIndex = 0;
1141 + for ( index = length - 1; index >= 0; --index ) {
1142 + item = $items.get( index );
1143 + itemTop = jQuery( item ).offset().top;
1144 + if ( y > itemTop ) {
1145 + returnIndex = index;
1146 + if ( y > itemTop + ( jQuery( item ).outerHeight() / 2 ) ) {
1147 + returnIndex = index + 1;
1148 + }
1149 + break;
1150 + }
1151 + }
1152 +
1153 + return returnIndex;
1154 + }
1155 +
1156 + function handleDragOverFieldGroup({ droppable, x, placeholder }) {
1157 + const $row = jQuery( droppable );
1158 + const $children = getFieldsInRow( $row );
1159 +
1160 + if ( ! $children.length ) {
1161 + return;
1162 + }
1163 +
1164 + let left;
1165 + const insertAtIndex = determineIndexBasedOffOfMousePositionInRow( $row, x );
1166 +
1167 + if ( insertAtIndex === $children.length ) {
1168 + const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) );
1169 + left = $lastChild.offset().left + $lastChild.outerWidth();
1170 + $row.append( placeholder );
1171 + } else {
1172 + left = jQuery( $children.get( insertAtIndex ) ).offset().left;
1173 + jQuery( $children.get( insertAtIndex ) ).before( placeholder );
1174 +
1175 + const amountToOffsetLeftBy = 0 === insertAtIndex ? 4 : 8; // Offset by 8 in between rows, but only 4 for the first item in a group.
1176 + left -= amountToOffsetLeftBy; // Offset the placeholder slightly so it appears between two fields.
1177 + }
1178 +
1179 + left -= $row.offset().left;
1180 +
1181 + placeholder.style.left = left + 'px';
1182 + }
1183 +
1184 + function syncAfterDragAndDrop() {
1185 + fixUnwrappedListItems();
1186 + toggleSectionHolder();
1187 + maybeFixEndDividers();
1188 + maybeDeleteEmptyFieldGroups();
1189 + updateFieldOrder();
1190 +
1191 + const event = new Event( 'frm_sync_after_drag_and_drop', { bubbles: false });
1192 + document.dispatchEvent( event );
1193 + }
1194 +
1195 + function maybeFixEndDividers() {
1196 + document.querySelectorAll( '.edit_field_type_end_divider' ).forEach(
1197 + endDivider => endDivider.parentNode.appendChild( endDivider )
1198 + );
1199 + }
1200 +
1201 + function maybeDeleteEmptyFieldGroups() {
1202 + document.querySelectorAll( 'li.form_field_box:not(.form-field)' ).forEach(
1203 + fieldGroup => ! fieldGroup.children.length && fieldGroup.remove()
1204 + );
1205 + }
1206 +
1207 + function fixUnwrappedListItems() {
1208 + const lists = document.querySelectorAll( 'ul#frm-show-fields, ul.start_divider' );
1209 + lists.forEach(
1210 + list => {
1211 + list.childNodes.forEach(
1212 + child => {
1213 + if ( 'undefined' === typeof child.classList ) {
1214 + return;
1215 + }
1216 +
1217 + if ( child.classList.contains( 'edit_field_type_end_divider' ) ) {
1218 + // Never wrap end divider in place.
1219 + return;
1220 + }
1221 +
1222 + if ( 'undefined' !== typeof child.classList && child.classList.contains( 'form-field' ) ) {
1223 + wrapFieldLiInPlace( child );
1224 + }
1225 + }
1226 + );
1227 + }
1228 + );
1229 + }
1230 +
1231 + function deleteEmptyDividerWrappers() {
1232 + const dividers = document.querySelectorAll( 'ul.start_divider' );
1233 + if ( ! dividers.length ) {
1234 + return;
1235 + }
1236 + dividers.forEach(
1237 + function( divider ) {
1238 + const children = [].slice.call( divider.children );
1239 + children.forEach(
1240 + function( child ) {
1241 + if ( 0 === child.children.length ) {
1242 + child.remove();
1243 + } else if ( 1 === child.children.length && 'ul' === child.firstElementChild.nodeName.toLowerCase() && 0 === child.firstElementChild.children.length ) {
1244 + child.remove();
1245 + }
1246 + }
1247 + );
1248 + }
1249 + );
1250 + }
1251 +
1252 + function getFieldsInRow( $row ) {
1253 + let $fields = jQuery();
1254 +
1255 + const row = $row.get( 0 );
1256 + if ( ! row.children ) {
1257 + return $fields;
1258 + }
1259 +
1260 + Array.from( row.children ).forEach(
1261 + child => {
1262 + if ( 'none' === child.style.display ) {
1263 + return;
1264 + }
1265 +
1266 + const classes = child.classList;
1267 + if ( ! classes.contains( 'form-field' ) || classes.contains( 'edit_field_type_end_divider' ) || classes.contains( 'frm-sortable-helper' ) ) {
1268 + return;
1269 + }
1270 +
1271 + $fields = $fields.add( child );
1272 + }
1273 + );
1274 + return $fields;
1275 + }
1276 +
1277 + function determineIndexBasedOffOfMousePositionInRow( $row, x ) {
1278 + var $inputs = getFieldsInRow( $row ),
1279 + length = $inputs.length,
1280 + index, input, inputLeft, returnIndex;
1281 +
1282 + returnIndex = 0;
1283 + for ( index = length - 1; index >= 0; --index ) {
1284 + input = $inputs.get( index );
1285 + inputLeft = jQuery( input ).offset().left;
1286 + if ( x > inputLeft ) {
1287 + returnIndex = index;
1288 + if ( x > inputLeft + ( jQuery( input ).outerWidth() / 2 ) ) {
1289 + returnIndex = index + 1;
1290 + }
1291 + break;
1292 + }
1293 + }
1294 +
1295 + return returnIndex;
1296 + }
1297 +
1298 + function syncLayoutClasses( $item, type ) {
1299 + var $fields, size, layoutClasses, classToAddFunction;
1300 +
1301 + if ( 'undefined' === typeof type ) {
1302 + type = 'even';
1303 + }
1304 +
1305 + $fields = $item.parent().children( 'li.form-field, li.frmbutton_loadingnow' ).not( '.edit_field_type_end_divider' );
1306 + size = $fields.length;
1307 + layoutClasses = getLayoutClasses();
1308 +
1309 + if ( 'even' === type && 5 !== size ) {
1310 + $fields.each( getSyncLayoutClass( layoutClasses, getEvenClassForSize( size ) ) );
1311 + } else if ( 'clear' === type ) {
1312 + $fields.each( getSyncLayoutClass( layoutClasses, '' ) );
1313 + } else {
1314 + if ( -1 !== [ 'left', 'right', 'middle', 'even' ].indexOf( type ) ) {
1315 + classToAddFunction = function( index ) {
1316 + return getClassForBlock( size, type, index );
1317 + };
1318 + } else {
1319 + classToAddFunction = function( index ) {
1320 + var size = type[ index ];
1321 + return getLayoutClassForSize( size );
1322 + };
1323 + }
1324 +
1325 + $fields.each( getSyncLayoutClass( layoutClasses, classToAddFunction ) );
1326 + }
1327 +
1328 + updateFieldGroupControls( $item.parent(), $fields.length );
1329 + }
1330 +
1331 + function updateFieldGroupControls( $row, count ) {
1332 + var rowOffset, shouldShowControls, controls;
1333 +
1334 + rowOffset = $row.offset();
1335 +
1336 + if ( 'undefined' === typeof rowOffset ) {
1337 + return;
1338 + }
1339 +
1340 + shouldShowControls = count >= 2;
1341 +
1342 + controls = document.getElementById( 'frm_field_group_controls' );
1343 + if ( null === controls ) {
1344 + if ( ! shouldShowControls ) {
1345 + // exit early. if we do not need controls and they do not exist, do nothing.
1346 + return;
1347 + }
1348 +
1349 + controls = div();
1350 + controls.id = 'frm_field_group_controls';
1351 + controls.setAttribute( 'role', 'group' );
1352 + controls.setAttribute( 'tabindex', 0 );
1353 + setFieldControlsHtml( controls );
1354 + document.getElementById( 'frm_builder_page' ).appendChild( controls );
1355 + }
1356 +
1357 + $row.append( controls );
1358 + controls.style.display = shouldShowControls ? 'block' : 'none';
1359 + }
1360 +
1361 + function setFieldControlsHtml( controls ) {
1362 + var layoutOption, moveOption;
1363 +
1364 + layoutOption = document.createElement( 'span' );
1365 + layoutOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_field_group_layout_icon"></use></svg>';
1366 + const layoutOptionLabel = __( 'Set Row Layout', 'formidable' );
1367 + addTooltip( layoutOption, layoutOptionLabel );
1368 + makeTabbable( layoutOption, layoutOptionLabel );
1369 +
1370 + moveOption = document.createElement( 'span' );
1371 + moveOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_thick_move_icon"></use></svg>';
1372 + moveOption.classList.add( 'frm-move' );
1373 + const moveOptionLabel = __( 'Move Field Group', 'formidable' );
1374 + addTooltip( moveOption, moveOptionLabel );
1375 + makeTabbable( moveOption, moveOptionLabel );
1376 +
1377 + controls.innerHTML = '';
1378 + controls.appendChild( layoutOption );
1379 + controls.appendChild( moveOption );
1380 + controls.appendChild( getFieldControlsDropdown() );
1381 + }
1382 +
1383 + function addTooltip( element, title ) {
1384 + element.setAttribute( 'data-toggle', 'tooltip' );
1385 + element.setAttribute( 'data-container', 'body' );
1386 + element.setAttribute( 'title', title );
1387 + element.addEventListener(
1388 + 'mouseover',
1389 + function() {
1390 + if ( null === element.getAttribute( 'data-original-title' ) ) {
1391 + jQuery( element ).tooltip();
1392 + }
1393 + }
1394 + );
1395 + }
1396 +
1397 + function getFieldControlsDropdown() {
1398 + var dropdown, trigger, ul;
1399 +
1400 + dropdown = document.createElement( 'span' );
1401 + dropdown.classList.add( 'dropdown' );
1402 +
1403 + trigger = document.createElement( 'a' );
1404 + trigger.classList.add( 'frm_bstooltip', 'frm-hover-icon', 'frm-dropdown-toggle', 'dropdown-toggle' );
1405 + trigger.setAttribute( 'title', __( 'More Options', 'formidable' ) );
1406 + trigger.setAttribute( 'data-toggle', 'dropdown' );
1407 + trigger.setAttribute( 'data-container', 'body' );
1408 + makeTabbable( trigger, __( 'More Options', 'formidable' ) );
1409 + trigger.innerHTML = '<span><svg class="frmsvg"><use xlink:href="#frm_thick_more_vert_icon"></use></svg></span>';
1410 + dropdown.appendChild( trigger );
1411 +
1412 + ul = document.createElement( 'div' );
1413 + ul.classList.add( 'frm-dropdown-menu', 'dropdown-menu' );
1414 + ul.setAttribute( 'role', 'menu' );
1415 + dropdown.appendChild( ul );
1416 +
1417 + return dropdown;
1418 + }
1419 +
1420 + function getSyncLayoutClass( layoutClasses, classToAdd ) {
1421 + return function( itemIndex ) {
1422 + var currentClassToAdd, length, layoutClassIndex, currentClass, activeLayoutClass, fieldId, layoutClassesInput;
1423 +
1424 + currentClassToAdd = 'function' === typeof classToAdd ? classToAdd( itemIndex ) : classToAdd;
1425 + length = layoutClasses.length;
1426 + activeLayoutClass = false;
1427 + for ( layoutClassIndex = 0; layoutClassIndex < length; ++layoutClassIndex ) {
1428 + currentClass = layoutClasses[ layoutClassIndex ];
1429 + if ( this.classList.contains( currentClass ) ) {
1430 + activeLayoutClass = currentClass;
1431 + break;
1432 + }
1433 + }
1434 +
1435 + fieldId = this.dataset.fid;
1436 +
1437 + if ( 'undefined' === typeof fieldId ) {
1438 + // we are syncing the drag/drop placeholder before the actual field has loaded.
1439 + // this will get called again afterward and the input will exist then.
1440 + this.classList.add( currentClassToAdd );
1441 + return;
1442 + }
1443 +
1444 + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) );
1445 + layoutClassesInput = document.getElementById( 'frm_classes_' + fieldId );
1446 +
1447 + if ( null === layoutClassesInput ) {
1448 + // not every field type has a layout class input.
1449 + return;
1450 + }
1451 +
1452 + if ( false === activeLayoutClass ) {
1453 + if ( '' !== currentClassToAdd ) {
1454 + layoutClassesInput.value = layoutClassesInput.value.concat( ' ' + currentClassToAdd );
1455 + }
1456 + } else {
1457 + this.classList.remove( activeLayoutClass );
1458 + layoutClassesInput.value = layoutClassesInput.value.replace( activeLayoutClass, currentClassToAdd );
1459 + }
1460 +
1461 + if ( this.classList.contains( 'frm_first' ) ) {
1462 + this.classList.remove( 'frm_first' );
1463 + layoutClassesInput.value = layoutClassesInput.value.replace( 'frm_first', '' ).trim();
1464 + }
1465 +
1466 + if ( 0 === itemIndex ) {
1467 + this.classList.add( 'frm_first' );
1468 + layoutClassesInput.value = layoutClassesInput.value.concat( ' frm_first' );
1469 + }
1470 +
1471 + jQuery( layoutClassesInput ).trigger( 'change' );
1472 + };
1473 + }
1474 +
1475 + function getLayoutClasses() {
1476 + 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' ];
1477 + }
1478 +
1479 + function setupFieldOptionSorting( sort ) {
1480 + var opts = {
1481 + items: '.frm_sortable_field_opts li',
1482 + axis: 'y',
1483 + opacity: 0.65,
1484 + forcePlaceholderSize: false,
1485 + handle: '.frm-drag',
1486 + helper: function( e, li ) {
1487 + copyHelper = li.clone().insertAfter( li );
1488 + return li.clone();
1489 + },
1490 + stop: function( e, ui ) {
1491 + copyHelper && copyHelper.remove();
1492 + var fieldId = ui.item.attr( 'id' ).replace( 'frm_delete_field_', '' ).replace( '-' + ui.item.data( 'optkey' ) + '_container', '' );
1493 + resetDisplayedOpts( fieldId );
1494 + }
1495 + };
1496 + jQuery( sort ).sortable( opts );
1497 + }
1498 +
1499 + // Get the section where a field is dropped
1500 + function getSectionForFieldPlacement( currentItem ) {
1501 + var section = '';
1502 + if ( typeof currentItem !== 'undefined' && ! currentItem.hasClass( 'edit_field_type_divider' ) ) {
1503 + section = currentItem.closest( '.edit_field_type_divider' );
1504 + }
1505 + return section;
1506 + }
1507 +
1508 + // Get the form ID where a field is dropped
1509 + function getFormIdForFieldPlacement( section ) {
1510 + var formId = '';
1511 +
1512 + if ( typeof section[0] !== 'undefined' ) {
1513 + var sDivide = section.children( '.start_divider' );
1514 + sDivide.children( '.edit_field_type_end_divider' ).appendTo( sDivide );
1515 + if ( typeof section.attr( 'data-formid' ) !== 'undefined' ) {
1516 + var fieldId = section.attr( 'data-fid' );
1517 + formId = jQuery( 'input[name="field_options[form_select_' + fieldId + ']"]' ).val();
1518 + }
1519 + }
1520 +
1521 + if ( typeof formId === 'undefined' || formId === '' ) {
1522 + formId = thisFormId;
1523 + }
1524 +
1525 + return formId;
1526 + }
1527 +
1528 + // Get the section ID where a field is dropped
1529 + function getSectionIdForFieldPlacement( section ) {
1530 + var sectionId = 0;
1531 + if ( typeof section[0] !== 'undefined' ) {
1532 + sectionId = section.attr( 'id' ).replace( 'frm_field_id_', '' );
1533 + }
1534 +
1535 + return sectionId;
1536 + }
1537 +
1538 + /**
1539 + * Update a field after it is dragged and dropped into, out of, or between sections
1540 + *
1541 + * @param {object} currentItem
1542 + */
1543 + function updateFieldAfterMovingBetweenSections( currentItem ) {
1544 + if ( ! currentItem.hasClass( 'form-field' ) ) {
1545 + // currentItem is a field group. Call for children recursively.
1546 + getFieldsInRow( jQuery( currentItem.get( 0 ).firstChild ) ).each(
1547 + function() {
1548 + updateFieldAfterMovingBetweenSections( jQuery( this ) );
1549 + }
1550 + );
1551 + return;
1552 + }
1553 +
1554 + const fieldId = currentItem.attr( 'id' ).replace( 'frm_field_id_', '' );
1555 + const section = getSectionForFieldPlacement( currentItem );
1556 + const formId = getFormIdForFieldPlacement( section );
1557 + const sectionId = getSectionIdForFieldPlacement( section );
1558 +
1559 + jQuery.ajax({
1560 + type: 'POST',
1561 + url: ajaxurl,
1562 + data: {
1563 + action: 'frm_update_field_after_move',
1564 + form_id: formId,
1565 + field: fieldId,
1566 + section_id: sectionId,
1567 + nonce: frmGlobal.nonce
1568 + },
1569 + success: function() {
1570 + toggleSectionHolder();
1571 + updateInSectionValue( fieldId, sectionId );
1572 + }
1573 + });
1574 + }
1575 +
1576 + // Update the in_section field value
1577 + function updateInSectionValue( fieldId, sectionId ) {
1578 + document.getElementById( 'frm_in_section_' + fieldId ).value = sectionId;
1579 + }
1580 +
1581 + /**
1582 + * Add a new field by dragging and dropping it from the Fields sidebar
1583 + *
1584 + * @param {string} fieldType
1585 + */
1586 + function insertNewFieldByDragging( fieldType ) {
1587 + const placeholder = document.getElementById( 'frm_drag_placeholder' );
1588 + const loadingID = fieldType.replace( '|', '-' ) + '_' + getAutoId();
1589 + const loading = tag(
1590 + 'li',
1591 + {
1592 + id: loadingID,
1593 + className: 'frm-wait frmbutton_loadingnow'
1594 + }
1595 + );
1596 + const $placeholder = jQuery( loading );
1597 + const currentItem = jQuery( placeholder );
1598 + const section = getSectionForFieldPlacement( currentItem );
1599 + const formId = getFormIdForFieldPlacement( section );
1600 + const sectionId = getSectionIdForFieldPlacement( section );
1601 +
1602 + placeholder.parentNode.insertBefore( loading, placeholder );
1603 + placeholder.remove();
1604 + syncLayoutClasses( $placeholder );
1605 +
1606 + let hasBreak = 0;
1607 + if ( 'summary' === fieldType ) {
1608 + // see if we need to insert a page break before this newly-added summary field. Check for at least 1 page break
1609 + hasBreak = jQuery( '.frmbutton_loadingnow#' + loadingID ).prevAll( 'li[data-type="break"]' ).length ? 1 : 0;
1610 + }
1611 +
1612 + jQuery.ajax({
1613 + type: 'POST', url: ajaxurl,
1614 + data: {
1615 + action: 'frm_insert_field',
1616 + form_id: formId,
1617 + field_type: fieldType,
1618 + section_id: sectionId,
1619 + nonce: frmGlobal.nonce,
1620 + has_break: hasBreak
1621 + },
1622 + success: function( msg ) {
1623 + let replaceWith;
1624 + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' );
1625 + const $siblings = $placeholder.siblings( 'li.form-field' ).not( '.edit_field_type_end_divider' );
1626 + if ( ! $siblings.length ) {
1627 + // if dragging into a new row, we need to wrap the li first.
1628 + replaceWith = wrapFieldLi( msg );
1629 + } else {
1630 + replaceWith = msgAsjQueryObject( msg );
1631 + if ( ! $placeholder.get( 0 ).parentNode.parentNode.classList.contains( 'ui-draggable' ) ) {
1632 + // If a field group wasn't draggable because it only had a single field, make it draggable.
1633 + makeDraggable( $placeholder.get( 0 ).parentNode.parentNode, '.frm-move' );
1634 + }
1635 + }
1636 + $placeholder.replaceWith( replaceWith );
1637 + updateFieldOrder();
1638 + afterAddField( msg, false );
1639 + if ( $siblings.length ) {
1640 + syncLayoutClasses( $siblings.first() );
1641 + }
1642 + toggleSectionHolder();
1643 +
1644 + if ( ! $siblings.length ) {
1645 + makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) );
1646 + makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' );
1647 + } else {
1648 + makeDraggable( replaceWith.get( 0 ), '.frm-move' );
1649 + }
1650 +
1651 + },
1652 + error: handleInsertFieldError
1653 + });
1654 + }
1655 +
1656 + function moveFieldThatAlreadyExists( draggable, placeholder ) {
1657 + placeholder.parentNode.insertBefore( draggable, placeholder );
1658 + }
1659 +
1660 + function msgAsjQueryObject( msg ) {
1661 + const element = div();
1662 + element.innerHTML = msg;
1663 + return jQuery( element.firstChild );
1664 + }
1665 +
1666 + function handleInsertFieldError( jqXHR, _, errorThrown ) {
1667 + maybeShowInsertFieldError( errorThrown, jqXHR );
1668 + }
1669 +
1670 + function maybeShowInsertFieldError( errorThrown, jqXHR ) {
1671 + if ( ! jqXHRAborted( jqXHR ) ) {
1672 + infoModal( errorThrown + '. Please try again.' );
1673 + }
1674 + }
1675 +
1676 + function jqXHRAborted( jqXHR ) {
1677 + return jqXHR.status === 0 || jqXHR.readyState === 0;
1678 + }
1679 +
1680 + /**
1681 + * Get a unique id that automatically increments with every function call.
1682 + * Can be used for any UI that requires a unique id.
1683 + * Not to be used in data.
1684 + *
1685 + * @returns {integer}
1686 + */
1687 + function getAutoId() {
1688 + return ++autoId;
1689 + }
1690 +
1691 + // Don't allow page break, embed form, or section inside section field
1692 + // Don't allow page breaks inside of field groups.
1693 + // Don't allow field groups with sections inside of sections.
1694 + // Don't allow field groups in field groups.
1695 + // Don't allow hidden fields inside of field groups but allow them in sections.
1696 + function allowDrop( draggable, droppable ) {
1697 + if ( false === droppable ) {
1698 + // Don't show drop placeholder if dragging somewhere off of the droppable area.
1699 + return false;
1700 + }
1701 +
1702 + if ( droppable.closest( '.frm-sortable-helper' ) ) {
1703 + // Do not allow drop into draggable.
1704 + return false;
1705 + }
1706 +
1707 + if ( 'frm-show-fields' === droppable.id ) {
1708 + // Everything can be dropped into the main list of fields.
1709 + return true;
1710 + }
1711 +
1712 + if ( ! droppable.classList.contains( 'start_divider' ) ) {
1713 + const $fieldsInRow = getFieldsInRow( jQuery( droppable ) );
1714 + if ( ! groupCanFitAnotherField( $fieldsInRow, jQuery( draggable ) ) ) {
1715 + // Field group is full and cannot accept another field.
1716 + return false;
1717 + }
1718 + }
1719 +
1720 + const isNewField = draggable.classList.contains( 'frm-new-field' );
1721 + if ( isNewField ) {
1722 + return allowNewFieldDrop( draggable, droppable );
1723 + }
1724 +
1725 + return allowMoveField( draggable, droppable );
1726 + }
1727 +
1728 + // Don't allow a new page break or hidden field in a field group.
1729 + // Don't allow a new field into a field group that includes a page break or hidden field.
1730 + // Don't allow a new section inside of a section.
1731 + // Don't allow an embedded form in a section.
1732 + function allowNewFieldDrop( draggable, droppable ) {
1733 + const classes = draggable.classList;
1734 + const newPageBreakField = classes.contains( 'frm_tbreak' );
1735 + const newHiddenField = classes.contains( 'frm_thidden' );
1736 + const newSectionField = classes.contains( 'frm_tdivider' );
1737 + const newEmbedField = classes.contains( 'frm_tform' );
1738 +
1739 + const newFieldWillBeAddedToAGroup = ! ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) );
1740 + if ( newFieldWillBeAddedToAGroup ) {
1741 + if ( groupIncludesBreakOrHidden( droppable ) ) {
1742 + // Never allow any field beside a page break or a hidden field.
1743 + return false;
1744 + }
1745 +
1746 + return ! newHiddenField && ! newPageBreakField;
1747 + }
1748 +
1749 + const fieldTypeIsAlwaysAllowed = ! newPageBreakField && ! newHiddenField && ! newSectionField && ! newEmbedField;
1750 + if ( fieldTypeIsAlwaysAllowed ) {
1751 + return true;
1752 + }
1753 +
1754 + const newFieldWillBeAddedToASection = droppable.classList.contains( 'start_divider' ) || null !== droppable.closest( '.start_divider' );
1755 + if ( newFieldWillBeAddedToASection ) {
1756 + // Don't allow a section or an embedded form in a section.
1757 + return ! newEmbedField && ! newSectionField;
1758 + }
1759 +
1760 + return true;
1761 + }
1762 +
1763 + function allowMoveField( draggable, droppable ) {
1764 + if ( isFieldGroup( draggable ) ) {
1765 + return allowMoveFieldGroup( draggable, droppable );
1766 + }
1767 +
1768 + const isPageBreak = draggable.classList.contains( 'edit_field_type_break' );
1769 + if ( isPageBreak ) {
1770 + // Page breaks are only allowed in the main list of fields, not in sections or in field groups.
1771 + return false;
1772 + }
1773 +
1774 + if ( droppable.classList.contains( 'start_divider' ) ) {
1775 + return allowMoveFieldToSection( draggable );
1776 + }
1777 +
1778 + const isHiddenField = draggable.classList.contains( 'edit_field_type_hidden' );
1779 + if ( isHiddenField ) {
1780 + // Hidden fields should not be added to field groups since they're not shown and don't make sense with the grid distribution.
1781 + return false;
1782 + }
1783 +
1784 + return allowMoveFieldToGroup( draggable, droppable );
1785 + }
1786 +
1787 + function isFieldGroup( draggable ) {
1788 + return draggable.classList.contains( 'frm_field_box' ) && ! draggable.classList.contains( 'form-field' );
1789 + }
1790 +
1791 + function allowMoveFieldGroup( fieldGroup, droppable ) {
1792 + if ( droppable.classList.contains( 'start_divider' ) && null === fieldGroup.querySelector( '.start_divider' ) ) {
1793 + // Allow a field group with no section inside of a section.
1794 + return true;
1795 + }
1796 + return false;
1797 + }
1798 +
1799 + function allowMoveFieldToSection( draggable ) {
1800 + const draggableIncludeEmbedForm = draggable.classList.contains( 'edit_field_type_form' ) || draggable.querySelector( '.edit_field_type_form' );
1801 + if ( draggableIncludeEmbedForm ) {
1802 + // Do not allow an embedded form inside of a section.
1803 + return false;
1804 + }
1805 +
1806 + const draggableIncludesSection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' );
1807 + if ( draggableIncludesSection ) {
1808 + // Do not allow a section inside of a section.
1809 + return false;
1810 + }
1811 +
1812 + return true;
1813 + }
1814 +
1815 + function allowMoveFieldToGroup( draggable, group ) {
1816 + if ( groupIncludesBreakOrHidden( group ) ) {
1817 + // Never allow any field beside a page break or a hidden field.
1818 + return false;
1819 + }
1820 +
1821 + const isFieldGroup = jQuery( draggable ).children( 'ul.frm_sorting' ).not( '.start_divider' ).length > 0;
1822 + if ( isFieldGroup ) {
1823 + // Do not allow a field group directly inside of a field group unless it's in a section.
1824 + return false;
1825 + }
1826 +
1827 + const draggableIncludesASection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' );
1828 + const draggableIsEmbedField = draggable.classList.contains( 'edit_field_type_form' );
1829 + const groupIsInASection = null !== group.closest( '.start_divider' );
1830 + if ( groupIsInASection && ( draggableIncludesASection || draggableIsEmbedField ) ) {
1831 + // Do not allow a section or an embed field inside of a section.
1832 + return false;
1833 + }
1834 +
1835 + return true;
1836 + }
1837 +
1838 + function groupIncludesBreakOrHidden( group ) {
1839 + return null !== group.querySelector( '.edit_field_type_break, .edit_field_type_hidden' );
1840 + }
1841 +
1842 + function groupCanFitAnotherField( fieldsInRow, $field ) {
1843 + var fieldId;
1844 + if ( fieldsInRow.length < 6 ) {
1845 + return true;
1846 + }
1847 + if ( fieldsInRow.length > 6 ) {
1848 + return false;
1849 + }
1850 + fieldId = $field.attr( 'data-fid' );
1851 + // allow 6 if we're not changing field groups.
1852 + return 1 === jQuery( fieldsInRow ).filter( '[data-fid="' + fieldId + '"]' ).length;
1853 + }
1854 +
1855 + function loadFields( fieldId ) {
1856 + const thisField = document.getElementById( fieldId );
1857 + const $thisField = jQuery( thisField );
1858 + const field = [];
1859 + const addHtmlToField = element => {
1860 + const frmHiddenFdata = element.querySelector( '.frm_hidden_fdata' );
1861 + element.classList.add( 'frm_load_now' );
1862 + if ( frmHiddenFdata !== null ) {
1863 + field.push( frmHiddenFdata.innerHTML );
1864 + }
1865 + };
1866 +
1867 + let nextElement = thisField;
1868 + addHtmlToField( nextElement );
1869 + while ( nextElement.nextElementSibling && field.length < 15 ) {
1870 + addHtmlToField( nextElement.nextElementSibling );
1871 + nextElement = nextElement.nextElementSibling;
1872 + }
1873 +
1874 + jQuery.ajax({
1875 + type: 'POST',
1876 + url: ajaxurl,
1877 + data: {
1878 + action: 'frm_load_field',
1879 + field: field,
1880 + form_id: thisFormId,
1881 + nonce: frmGlobal.nonce
1882 + },
1883 + success: html => handleAjaxLoadFieldSuccess( html, $thisField, field )
1884 + });
1885 + }
1886 +
1887 + function handleAjaxLoadFieldSuccess( html, $thisField, field ) {
1888 + let key, $nextSet;
1889 +
1890 + html = html.replace( /^\s+|\s+$/g, '' );
1891 + if ( html.indexOf( '{' ) !== 0 ) {
1892 + jQuery( '.frm_load_now' ).removeClass( '.frm_load_now' ).html( 'Error' );
1893 + return;
1894 + }
1895 +
1896 + html = JSON.parse( html );
1897 + for ( key in html ) {
1898 + jQuery( '#frm_field_id_' + key ).replaceWith( html[key]);
1899 + setupSortable( '#frm_field_id_' + key + '.edit_field_type_divider ul.frm_sorting' );
1900 + makeDraggable( document.getElementById( 'frm_field_id_' + key ) );
1901 + }
1902 +
1903 + $nextSet = $thisField.nextAll( '.frm_field_loading:not(.frm_load_now)' );
1904 + if ( $nextSet.length ) {
1905 + loadFields( $nextSet.attr( 'id' ) );
1906 + } else {
1907 + // go up a level
1908 + $nextSet = jQuery( document.getElementById( 'frm-show-fields' ) ).find( '.frm_field_loading:not(.frm_load_now)' );
1909 + if ( $nextSet.length ) {
1910 + loadFields( $nextSet.attr( 'id' ) );
1911 + }
1912 + }
1913 +
1914 + initiateMultiselect();
1915 + renumberPageBreaks();
1916 + maybeHideQuantityProductFieldOption();
1917 +
1918 + const loadedEvent = new Event( 'frm_ajax_loaded_field', { bubbles: false });
1919 + loadedEvent.frmFields = field.map( f => JSON.parse( f ) );
1920 + document.dispatchEvent( loadedEvent );
1921 + }
1922 +
1923 + function addFieldClick() {
1924 + /*jshint validthis:true */
1925 + const $thisObj = jQuery( this );
1926 + // there is no real way to disable a <a> (with a valid href attribute) in HTML - https://css-tricks.com/how-to-disable-links/
1927 + if ( $thisObj.hasClass( 'disabled' ) ) {
1928 + return false;
1929 + }
1930 +
1931 + const $button = $thisObj.closest( '.frmbutton' );
1932 + const fieldType = $button.attr( 'id' );
1933 +
1934 + let hasBreak = 0;
1935 + if ( 'summary' === fieldType ) {
1936 + hasBreak = $newFields.children( 'li[data-type="break"]' ).length > 0 ? 1 : 0;
1937 + }
1938 +
1939 + const formId = thisFormId;
1940 + jQuery.ajax({
1941 + type: 'POST',
1942 + url: ajaxurl,
1943 + data: {
1944 + action: 'frm_insert_field',
1945 + form_id: formId,
1946 + field_type: fieldType,
1947 + section_id: 0,
1948 + nonce: frmGlobal.nonce,
1949 + has_break: hasBreak
1950 + },
1951 + success: function( msg ) {
1952 + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' );
1953 + const replaceWith = wrapFieldLi( msg );
1954 + $newFields.append( replaceWith );
1955 + afterAddField( msg, true );
1956 +
1957 + replaceWith.each(
1958 + function() {
1959 + makeDroppable( this.querySelector( 'ul.frm_sorting' ) );
1960 + makeDraggable( this.querySelector( '.form-field' ), '.frm-move' );
1961 + }
1962 + );
1963 + },
1964 + error: handleInsertFieldError
1965 + });
1966 + return false;
1967 + }
1968 +
1969 + function maybeHideQuantityProductFieldOption() {
1970 + var hide = true,
1971 + opts = document.querySelectorAll( '.frmjs_prod_field_opt_cont' );
1972 +
1973 + if ( $newFields.find( 'li.edit_field_type_product' ).length > 1 ) {
1974 + hide = false;
1975 + }
1976 +
1977 + for ( var i = 0; i < opts.length; i++ ) {
1978 + if ( hide ) {
1979 + opts[ i ].classList.add( 'frm_hidden' );
1980 + } else {
1981 + opts[ i ].classList.remove( 'frm_hidden' );
1982 + }
1983 + }
1984 + }
1985 +
1986 + function duplicateField() {
1987 + var $field, fieldId, children, newRowId, fieldOrder;
1988 +
1989 + $field = jQuery( this ).closest( 'li.form-field' );
1990 +
1991 + if ( $field.hasClass( 'frm-section-collapsed' ) || $field.hasClass( 'frm-page-collapsed' ) ) {
1992 + return false;
1993 + }
1994 +
1995 + closeOpenFieldDropdowns();
1996 +
1997 + fieldId = $field.data( 'fid' );
1998 + children = fieldsInSection( fieldId );
1999 + newRowId = this.getAttribute( 'frm-target-row-id' );
2000 +
2001 + if ( null !== newRowId ) {
2002 + fieldOrder = this.getAttribute( 'frm-field-order' );
2003 + }
2004 +
2005 + jQuery.ajax({
2006 + type: 'POST',
2007 + url: ajaxurl,
2008 + data: {
2009 + action: 'frm_duplicate_field',
2010 + field_id: fieldId,
2011 + form_id: thisFormId,
2012 + children: children,
2013 + nonce: frmGlobal.nonce
2014 + },
2015 + success: function( msg ) {
2016 + var newRow;
2017 +
2018 + let replaceWith;
2019 +
2020 + if ( null !== newRowId ) {
2021 + newRow = document.getElementById( newRowId );
2022 + if ( null !== newRow ) {
2023 + replaceWith = msgAsjQueryObject( msg );
2024 + jQuery( newRow ).append( replaceWith );
2025 + makeDraggable( replaceWith.get( 0 ), '.frm-move' );
2026 + if ( null !== fieldOrder ) {
2027 + newRow.lastElementChild.setAttribute( 'frm-field-order', fieldOrder );
2028 + }
2029 + jQuery( newRow ).trigger(
2030 + 'frm_added_duplicated_field_to_row',
2031 + {
2032 + duplicatedFieldHtml: msg,
2033 + originalFieldId: fieldId
2034 + }
2035 + );
2036 + afterAddField( msg, false );
2037 + return;
2038 + }
2039 + }
2040 +
2041 + if ( $field.siblings( 'li.form-field' ).length ) {
2042 + replaceWith = msgAsjQueryObject( msg );
2043 + $field.after( replaceWith );
2044 + syncLayoutClasses( $field );
2045 + makeDraggable( replaceWith.get( 0 ), '.frm-move' );
2046 + } else {
2047 + replaceWith = wrapFieldLi( msg );
2048 + $field.parent().parent().after( replaceWith );
2049 + makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) );
2050 + makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' );
2051 + }
2052 +
2053 + updateFieldOrder();
2054 + afterAddField( msg, false );
2055 + maybeDuplicateUnsavedSettings( fieldId, msg );
2056 + toggleOneSectionHolder( replaceWith.find( '.start_divider' ) );
2057 + }
2058 + });
2059 + return false;
2060 + }
2061 +
2062 + function maybeDuplicateUnsavedSettings( originalFieldId, newFieldHtml ) {
2063 + var originalSettings, newFieldId, copySettings, fieldOptionKeys, originalDefault, copyDefault;
2064 +
2065 + originalSettings = document.getElementById( 'frm-single-settings-' + originalFieldId );
2066 + if ( null === originalSettings ) {
2067 + return;
2068 + }
2069 +
2070 + newFieldId = jQuery( newFieldHtml ).attr( 'data-fid' );
2071 + if ( 'undefined' === typeof newFieldId ) {
2072 + return;
2073 + }
2074 +
2075 + copySettings = document.getElementById( 'frm-single-settings-' + newFieldId );
2076 + if ( null === copySettings ) {
2077 + return;
2078 + }
2079 +
2080 + fieldOptionKeys = [
2081 + 'name', 'required', 'unique', 'read_only', 'placeholder', 'description', 'size', 'max', 'format', 'prepend', 'append', 'separate_value'
2082 + ];
2083 +
2084 + originalSettings.querySelectorAll( 'input[name^="field_options["], textarea[name^="field_options["]' ).forEach(
2085 + function( originalSetting ) {
2086 + var key, tagType, copySetting;
2087 +
2088 + key = getKeyFromSettingInput( originalSetting );
2089 +
2090 + if ( 'options' === key ) {
2091 + copyOption( originalSetting, copySettings, originalFieldId, newFieldId );
2092 + return;
2093 + }
2094 +
2095 + if ( -1 === fieldOptionKeys.indexOf( key ) ) {
2096 + return;
2097 + }
2098 +
2099 + tagType = originalSetting.matches( 'input' ) ? 'input' : 'textarea';
2100 + copySetting = copySettings.querySelector( tagType + '[name="field_options[' + key + '_' + newFieldId + ']"]' );
2101 + if ( null === copySetting ) {
2102 + return;
2103 + }
2104 +
2105 + if ( 'checkbox' === originalSetting.type ) {
2106 + if ( originalSetting.checked !== copySetting.checked ) {
2107 + jQuery( copySetting ).trigger( 'click' );
2108 + }
2109 + } else if ( 'text' === originalSetting.type || 'textarea' === tagType ) {
2110 + if ( originalSetting.value !== copySetting.value ) {
2111 + copySetting.value = originalSetting.value;
2112 + jQuery( copySetting ).trigger( 'change' );
2113 + }
2114 + }
2115 + }
2116 + );
2117 +
2118 + originalDefault = originalSettings.querySelector( 'input[name="default_value_' + originalFieldId + '"]' );
2119 + if ( null !== originalDefault ) {
2120 + copyDefault = copySettings.querySelector( 'input[name="default_value_' + newFieldId + '"]' );
2121 + if ( null !== copyDefault && originalDefault.value !== copyDefault.value ) {
2122 + copyDefault.value = originalDefault.value;
2123 + jQuery( copyDefault ).trigger( 'change' );
2124 + }
2125 + }
2126 + }
2127 +
2128 + function copyOption( originalSetting, copySettings, originalFieldId, newFieldId ) {
2129 + var remainingKeyDetails, copyKey, copySetting;
2130 + remainingKeyDetails = originalSetting.name.substr( 23 + ( '' + originalFieldId ).length );
2131 + copyKey = 'field_options[options_' + newFieldId + ']' + remainingKeyDetails;
2132 + copySetting = copySettings.querySelector( 'input[name="' + copyKey + '"]' );
2133 + if ( null !== copySetting && copySetting.value !== originalSetting.value ) {
2134 + copySetting.value = originalSetting.value;
2135 + jQuery( copySetting ).trigger( 'change' );
2136 + }
2137 + }
2138 +
2139 + function getKeyFromSettingInput( input ) {
2140 + var nameWithoutPrefix, nameSplit;
2141 + nameWithoutPrefix = input.name.substr( 14 );
2142 + nameSplit = nameWithoutPrefix.split( '_' );
2143 + nameSplit.pop();
2144 + return nameSplit.join( '_' );
2145 + }
2146 +
2147 + function closeOpenFieldDropdowns() {
2148 + var openSettings = document.querySelector( '.frm-field-settings-open' );
2149 + if ( null !== openSettings ) {
2150 + openSettings.classList.remove( 'frm-field-settings-open' );
2151 + jQuery( document ).off( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings );
2152 + jQuery( '.frm-field-action-icons .dropdown.open' ).removeClass( 'open' );
2153 + }
2154 + }
2155 +
2156 + function handleClickOutsideOfFieldSettings( event ) {
2157 + if ( ! jQuery( event.originalEvent.target ).closest( '.frm-field-action-icons' ).length ) {
2158 + closeOpenFieldDropdowns();
2159 + }
2160 + }
2161 +
2162 + function checkForMultiselectKeysOnMouseMove( event ) {
2163 + var keyIsDown = ! ! ( event.ctrlKey || event.metaKey || event.shiftKey );
2164 + jQuery( document.getElementById( 'frm_builder_page' ) ).toggleClass( 'frm-multiselect-key-is-down', keyIsDown );
2165 + checkForActiveHoverTarget( event );
2166 + }
2167 +
2168 + function checkForActiveHoverTarget( event ) {
2169 + var container, elementFromPoint, list, previousHoverTarget;
2170 +
2171 + container = postBodyContent;
2172 + if ( container.classList.contains( 'frm-dragging-field' ) ) {
2173 + return;
2174 + }
2175 +
2176 + if ( null !== document.querySelector( '.frm-field-group-hover-target .frm-field-settings-open' ) ) {
2177 + // do not set a hover target if a dropdown is open for the current hover target.
2178 + return;
2179 + }
2180 +
2181 + elementFromPoint = document.elementFromPoint( event.clientX, event.clientY );
2182 + if ( null !== elementFromPoint && ! elementFromPoint.classList.contains( 'edit_field_type_divider' ) ) {
2183 +
2184 + list = elementFromPoint.closest( 'ul.frm_sorting' );
2185 +
2186 + if ( null !== list && ! list.classList.contains( 'start_divider' ) && 'frm-show-fields' !== list.id ) {
2187 + previousHoverTarget = maybeRemoveGroupHoverTarget();
2188 + if ( false !== previousHoverTarget && ! jQuery( previousHoverTarget ).is( list ) ) {
2189 + destroyFieldGroupPopup();
2190 + }
2191 + updateFieldGroupControls( jQuery( list ), getFieldsInRow( jQuery( list ) ).length );
2192 + list.classList.add( 'frm-field-group-hover-target' );
2193 + jQuery( '#wpbody-content' ).on( 'mousemove', maybeRemoveHoverTargetOnMouseMove );
2194 + }
2195 + }
2196 + }
2197 +
2198 + function maybeRemoveGroupHoverTarget() {
2199 + var controls, previousHoverTarget;
2200 +
2201 + controls = document.getElementById( 'frm_field_group_controls' );
2202 + if ( null !== controls ) {
2203 + controls.style.display = 'none';
2204 + }
2205 +
2206 + previousHoverTarget = document.querySelector( '.frm-field-group-hover-target' );
2207 + if ( null === previousHoverTarget ) {
2208 + return false;
2209 + }
2210 +
2211 + jQuery( '#wpbody-content' ).off( 'mousemove', maybeRemoveHoverTargetOnMouseMove );
2212 + previousHoverTarget.classList.remove( 'frm-field-group-hover-target' );
2213 + return previousHoverTarget;
2214 + }
2215 +
2216 + function maybeRemoveHoverTargetOnMouseMove( event ) {
2217 + var elementFromPoint = document.elementFromPoint( event.clientX, event.clientY );
2218 + if ( null !== elementFromPoint && null !== elementFromPoint.closest( '#frm-show-fields' ) ) {
2219 + return;
2220 + }
2221 + maybeRemoveGroupHoverTarget();
2222 + }
2223 +
2224 + function onFieldActionDropdownShow( isFieldGroup ) {
2225 + unselectFieldGroups();
2226 + // maybe offset the dropdown if it goes off of the right of the screen.
2227 + setTimeout(
2228 + function() {
2229 + var ul, $ul;
2230 + ul = document.querySelector( '.dropdown.show .frm-dropdown-menu' );
2231 + if ( null === ul ) {
2232 + return;
2233 + }
2234 + if ( null === ul.getAttribute( 'aria-label' ) ) {
2235 + ul.setAttribute( 'aria-label', __( 'More Options', 'formidable' ) );
2236 + }
2237 + if ( 0 === ul.children.length ) {
2238 + fillFieldActionDropdown( ul, true === isFieldGroup );
2239 + }
2240 + $ul = jQuery( ul );
2241 + if ( $ul.offset().left > jQuery( window ).width() - $ul.outerWidth() ) {
2242 + ul.style.left = ( -$ul.outerWidth() ) + 'px';
2243 + }
2244 + const firstAnchor = ul.firstElementChild.querySelector( 'a' );
2245 + if ( firstAnchor ) {
2246 + firstAnchor.focus();
2247 + }
2248 + },
2249 + 0
2250 + );
2251 + }
2252 +
2253 + function onFieldGroupActionDropdownShow() {
2254 + onFieldActionDropdownShow( true );
2255 + }
2256 +
2257 + function fillFieldActionDropdown( ul, isFieldGroup ) {
2258 + var classSuffix, options;
2259 + classSuffix = isFieldGroup ? '_field_group' : '_field';
2260 + options = [ getDeleteActionOption( isFieldGroup ), getDuplicateActionOption( isFieldGroup ) ];
2261 + if ( ! isFieldGroup ) {
2262 + options.push(
2263 + { class: 'frm_select', icon: 'frm_settings_icon', label: __( 'Field settings', 'formidable' ) }
2264 + );
2265 + }
2266 + options.forEach(
2267 + function( option ) {
2268 + var li, anchor, span;
2269 + li = document.createElement( 'div' );
2270 + li.classList.add( 'frm_dropdown_li', 'frm_more_options_li', 'dropdown-item' );
2271 +
2272 + anchor = document.createElement( 'a' );
2273 + anchor.classList.add( option.class + classSuffix );
2274 + anchor.setAttribute( 'href', '#' );
2275 + makeTabbable( anchor );
2276 +
2277 + span = document.createElement( 'span' );
2278 + span.textContent = option.label;
2279 + anchor.innerHTML = '<svg class="frmsvg"><use xlink:href="#' + option.icon + '"></use></svg>';
2280 + anchor.appendChild( document.createTextNode( ' ' ) );
2281 + anchor.appendChild( span );
2282 +
2283 + li.appendChild( anchor );
2284 + ul.appendChild( li );
2285 + }
2286 + );
2287 + }
2288 +
2289 + function getDeleteActionOption( isFieldGroup ) {
2290 + var option = { class: 'frm_delete', icon: 'frm_delete_icon' };
2291 + option.label = isFieldGroup ? __( 'Delete Group', 'formidable' ) : __( 'Delete', 'formidable' );
2292 + return option;
2293 + }
2294 +
2295 + function getDuplicateActionOption( isFieldGroup ) {
2296 + var option = { class: 'frm_clone', icon: 'frm_clone_icon' };
2297 + option.label = isFieldGroup ? __( 'Duplicate Group', 'formidable' ) : __( 'Duplicate', 'formidable' );
2298 + return option;
2299 + }
2300 +
2301 + function wrapFieldLi( field ) {
2302 + const wrapper = div();
2303 +
2304 + if ( 'string' === typeof field ) {
2305 + wrapper.innerHTML = field;
2306 + } else {
2307 + wrapper.appendChild( field );
2308 + }
2309 +
2310 + let result = jQuery();
2311 + Array.from( wrapper.children ).forEach(
2312 + li => {
2313 + result = result.add(
2314 + jQuery( '<li>' )
2315 + .addClass( 'frm_field_box' )
2316 + .html(
2317 + jQuery( '<ul>' ).addClass( 'frm_grid_container frm_sorting' ).append( li )
2318 + )
2319 + );
2320 + }
2321 + );
2322 +
2323 + return result;
2324 + }
2325 +
2326 + function wrapFieldLiInPlace( li ) {
2327 + const ul = tag(
2328 + 'ul',
2329 + {
2330 + className: 'frm_grid_container frm_sorting'
2331 + }
2332 + );
2333 + const wrapper = tag(
2334 + 'li',
2335 + {
2336 + className: 'frm_field_box',
2337 + child: ul
2338 + }
2339 + );
2340 +
2341 + li.replaceWith( wrapper );
2342 + ul.appendChild( li );
2343 +
2344 + makeDroppable( ul );
2345 + makeDraggable( wrapper, '.frm-move' );
2346 + }
2347 +
2348 + function afterAddField( msg, addFocus ) {
2349 + var regex = /id="(\S+)"/,
2350 + match = regex.exec( msg ),
2351 + field = document.getElementById( match[1]),
2352 + section = '#' + match[1] + '.edit_field_type_divider ul.frm_sorting.start_divider',
2353 + $thisSection = jQuery( section ),
2354 + type = field.getAttribute( 'data-type' ),
2355 + toggled = false,
2356 + $parentSection;
2357 +
2358 + setupSortable( section );
2359 +
2360 + if ( 'quantity' === type ) {
2361 + // try to automatically attach a product field
2362 + maybeSetProductField( field );
2363 + }
2364 +
2365 + if ( 'product' === type || 'quantity' === type ) {
2366 + // quantity too needs to be a part of the if stmt especially cos of the very
2367 + // 1st quantity field (or even if it's just one quantity field in the form).
2368 + maybeHideQuantityProductFieldOption();
2369 + }
2370 +
2371 + if ( $thisSection.length ) {
2372 + $thisSection.parent( '.frm_field_box' ).children( '.frm_no_section_fields' ).addClass( 'frm_block' );
2373 + } else {
2374 + $parentSection = jQuery( field ).closest( 'ul.frm_sorting.start_divider' );
2375 + if ( $parentSection.length ) {
2376 + toggleOneSectionHolder( $parentSection );
2377 + toggled = true;
2378 + }
2379 + }
2380 +
2381 + if ( msg.indexOf( 'frm-collapse-page' ) !== -1 ) {
2382 + renumberPageBreaks();
2383 + }
2384 +
2385 + addClass( field, 'frm-newly-added' );
2386 + setTimeout( function() {
2387 + field.classList.remove( 'frm-newly-added' );
2388 + }, 1000 );
2389 +
2390 + if ( addFocus ) {
2391 + var bounding = field.getBoundingClientRect(),
2392 + container = document.getElementById( 'post-body-content' ),
2393 + inView = ( bounding.top >= 0 &&
2394 + bounding.left >= 0 &&
2395 + bounding.right <= ( window.innerWidth || document.documentElement.clientWidth ) &&
2396 + bounding.bottom <= ( window.innerHeight || document.documentElement.clientHeight )
2397 + );
2398 +
2399 + if ( ! inView ) {
2400 + container.scroll({
2401 + top: container.scrollHeight,
2402 + left: 0,
2403 + behavior: 'smooth'
2404 + });
2405 + }
2406 +
2407 + if ( toggled === false ) {
2408 + toggleOneSectionHolder( $thisSection );
2409 + }
2410 + }
2411 +
2412 + deselectFields();
2413 + initiateMultiselect();
2414 +
2415 + const addedEvent = new Event( 'frm_added_field', { bubbles: false });
2416 + addedEvent.frmField = field;
2417 + addedEvent.frmSection = section;
2418 + addedEvent.frmType = type;
2419 + addedEvent.frmToggles = toggled;
2420 + document.dispatchEvent( addedEvent );
2421 + }
2422 +
2423 + function clearSettingsBox( preventFieldGroups ) {
2424 + jQuery( '#new_fields .frm-single-settings' ).addClass( 'frm_hidden' );
2425 + jQuery( '#frm-options-panel > .frm-single-settings' ).removeClass( 'frm_hidden' );
2426 + deselectFields( preventFieldGroups );
2427 + }
2428 +
2429 + function deselectFields( preventFieldGroups ) {
2430 + jQuery( 'li.ui-state-default.selected' ).removeClass( 'selected' );
2431 + if ( ! preventFieldGroups ) {
2432 + unselectFieldGroups();
2433 + }
2434 + }
2435 +
2436 + function scrollToField( field ) {
2437 + var newPos = field.getBoundingClientRect().top,
2438 + container = document.getElementById( 'post-body-content' );
2439 +
2440 + if ( typeof animate === 'undefined' ) {
2441 + jQuery( container ).scrollTop( newPos );
2442 + } else {
2443 + // TODO: smooth scroll
2444 + jQuery( container ).animate({ scrollTop: newPos }, 500 );
2445 + }
2446 + }
2447 +
2448 + function checkCalculationCreatedByUser() {
2449 + var calculation = this.value;
2450 + var warningMessage = checkMatchingParens( calculation );
2451 + warningMessage += checkShortcodes( calculation, this );
2452 +
2453 + if ( warningMessage !== '' ) {
2454 + infoModal( calculation + '\n\n' + warningMessage );
2455 + }
2456 + }
2457 +
2458 + /**
2459 + * Checks the Detail Page slug to see if it's a reserved word and displays a message if it is.
2460 + */
2461 + function checkDetailPageSlug() {
2462 + var slug = jQuery( '#param' ).val(),
2463 + msg;
2464 + slug = slug.trim().toLowerCase();
2465 + if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( slug ) ) {
2466 + msg = frm_admin_js.slug_is_reserved;
2467 + msg = msg.replace( '****', addHtmlTags( slug, 'strong' ) );
2468 + msg += '<br /><br />';
2469 + msg += addHtmlTags( '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>', 'div' );
2470 + infoModal( msg );
2471 + }
2472 + }
2473 +
2474 + /**
2475 + * Checks View filter value for params named with reserved words and displays a message if any are found.
2476 + */
2477 + function checkFilterParamNames() {
2478 + var regEx = /\[\s*get\s*param\s*=\s*['"]?([a-zA-Z-_]+)['"]?/ig,
2479 + filterValue = jQuery( this ).val(),
2480 + match = regEx.exec( filterValue ),
2481 + unsafeParams = '';
2482 +
2483 + while ( match !== null ) {
2484 + if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( match[1]) ) {
2485 + if ( unsafeParams !== '' ) {
2486 + unsafeParams += '", "' + match[ 1 ];
2487 + } else {
2488 + unsafeParams = match[ 1 ];
2489 + }
2490 + }
2491 + match = regEx.exec( filterValue );
2492 + }
2493 +
2494 + if ( unsafeParams !== '' ) {
2495 + msg = frm_admin_js.param_is_reserved;
2496 + msg = msg.replace( '****', addHtmlTags( unsafeParams, 'strong' ) );
2497 + msg += '<br /><br />';
2498 + msg += ' <a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>';
2499 +
2500 + infoModal( msg );
2501 + }
2502 + }
2503 +
2504 + function addHtmlTags( text, tag ) {
2505 + tag = tag ? tag : 'p';
2506 + return '<' + tag + '>' + text + '</' + tag + '>';
2507 + }
2508 +
2509 + /**
2510 + * Checks a string for parens, brackets, and curly braces and returns a message if any unmatched are found.
2511 + * @param formula
2512 + * @returns {string}
2513 + */
2514 + function checkMatchingParens( formula ) {
2515 +
2516 + var stack = [],
2517 + formulaArray = formula.split( '' ),
2518 + length = formulaArray.length,
2519 + opening = [ '{', '[', '(' ],
2520 + closing = {
2521 + '}': '{',
2522 + ')': '(',
2523 + ']': '['
2524 + },
2525 + unmatchedClosing = [],
2526 + msg = '',
2527 + i, top;
2528 +
2529 + for ( i = 0; i < length; i++ ) {
2530 + if ( opening.includes( formulaArray[i]) ) {
2531 + stack.push( formulaArray[i]);
2532 + continue;
2533 + }
2534 + if ( closing.hasOwnProperty( formulaArray[i]) ) {
2535 + top = stack.pop();
2536 + if ( top !== closing[formulaArray[i]]) {
2537 + unmatchedClosing.push( formulaArray[i]);
2538 + }
2539 + }
2540 + }
2541 +
2542 + if ( stack.length > 0 || unmatchedClosing.length > 0 ) {
2543 + msg = frm_admin_js.unmatched_parens + '\n\n';
2544 + return msg;
2545 + }
2546 +
2547 + return '';
2548 + }
2549 +
2550 + /**
2551 + * Checks a calculation for shortcodes that shouldn't be in it and returns a message if found.
2552 + * @param calculation
2553 + * @param inputElement
2554 + * @returns {string}
2555 + */
2556 + function checkShortcodes( calculation, inputElement ) {
2557 + var msg = checkNonNumericShortcodes( calculation, inputElement );
2558 + msg += checkNonFormShortcodes( calculation );
2559 +
2560 + return msg;
2561 + }
2562 +
2563 + /**
2564 + * Checks if a numeric calculation has shortcodes that output non-numeric strings and returns a message if found.
2565 + * @param calculation
2566 + *
2567 + * @param inputElement
2568 + * @returns {string}
2569 + */
2570 + function checkNonNumericShortcodes( calculation, inputElement ) {
2571 +
2572 + var msg = '';
2573 +
2574 + if ( isTextCalculation( inputElement ) ) {
2575 + return msg;
2576 + }
2577 +
2578 + var nonNumericShortcodes = getNonNumericShortcodes();
2579 +
2580 + if ( nonNumericShortcodes.test( calculation ) ) {
2581 + msg = frm_admin_js.text_shortcodes + '\n\n';
2582 + }
2583 +
2584 + return msg;
2585 + }
2586 +
2587 + /**
2588 + * Determines if the calculation input is from a text calculation.
2589 + *
2590 + * @param inputElement
2591 + */
2592 + function isTextCalculation( inputElement ) {
2593 + return jQuery( inputElement ).siblings( 'label[for^="calc_type"]' ).children( 'input' ).prop( 'checked' );
2594 + }
2595 +
2596 + /**
2597 + * Returns a regular expression of shortcodes that can't be used in numeric calculations.
2598 + * @returns {RegExp}
2599 + */
2600 + function getNonNumericShortcodes() {
2601 + return /\[(date|time|email|ip)\]/;
2602 + }
2603 +
2604 + /**
2605 + * Checks if a string has any shortcodes that do not belong in forms and returns a message if any are found.
2606 + * @param formula
2607 + * @returns {string}
2608 + */
2609 + function checkNonFormShortcodes( formula ) {
2610 + var nonFormShortcodes = getNonFormShortcodes(),
2611 + msg = '';
2612 +
2613 + if ( nonFormShortcodes.test( formula ) ) {
2614 + msg += frm_admin_js.view_shortcodes + '\n\n';
2615 + }
2616 +
2617 + return msg;
2618 + }
2619 +
2620 + /**
2621 + * Returns a regular expression of shortcodes that can't be used in forms but can be used in Views, Email
2622 + * Notifications, and other Formidable areas.
2623 + *
2624 + * @returns {RegExp}
2625 + */
2626 + function getNonFormShortcodes() {
2627 + return /\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g;
2628 + }
2629 +
2630 + function isCalcBoxType( box, listClass ) {
2631 + var list = jQuery( box ).find( '.frm_code_list' );
2632 + return 1 === list.length && list.hasClass( listClass );
2633 + }
2634 +
2635 + function extractExcludedOptions( exclude ) {
2636 + var opts = [];
2637 + if ( ! Array.isArray( exclude ) ) {
2638 + return opts;
2639 + }
2640 +
2641 + for ( var i = 0; i < exclude.length; i++ ) {
2642 + if ( exclude[ i ].startsWith( '[' ) ) {
2643 + opts.push( exclude[ i ]);
2644 + // remove it
2645 + exclude.splice( i, 1 );
2646 + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value
2647 + i--;
2648 + }
2649 + }
2650 +
2651 + return opts;
2652 + }
2653 +
2654 + function hasExcludedOption( field, excludedOpts ) {
2655 + var hasOption = false;
2656 + for ( var i = 0; i < excludedOpts.length; i++ ) {
2657 + var inputs = document.getElementsByName( getFieldOptionInputName( excludedOpts[ i ], field.fieldId ) );
2658 + // 2nd condition checks that there's at least one non-empty value
2659 + if ( inputs.length && jQuery( inputs[0]).val() ) {
2660 + hasOption = true;
2661 + break;
2662 + }
2663 + }
2664 + return hasOption;
2665 + }
2666 +
2667 + function getFieldOptionInputName( opt, fieldId ) {
2668 + var at = opt.indexOf( ']' );
2669 + return 'field_options' + opt.substring( 0, at ) + '_' + fieldId + opt.substring( at );
2670 + }
2671 +
2672 + function popCalcFields( v, force ) {
2673 + var box, exclude, fields, i, list,
2674 + p = jQuery( v ).closest( '.frm-single-settings' ),
2675 + calc = p.find( '.frm-calc-field' );
2676 +
2677 + if ( ! force && ( ! calc.length || calc.val() === '' || calc.is( ':hidden' ) ) ) {
2678 + return;
2679 + }
2680 +
2681 + var isSummary = isCalcBoxType( v, 'frm_js_summary_list' );
2682 +
2683 + var fieldId = p.find( 'input[name="frm_fields_submitted[]"]' ).val();
2684 +
2685 + if ( force ) {
2686 + box = v;
2687 + } else {
2688 + box = document.getElementById( 'frm-calc-box-' + fieldId );
2689 + }
2690 +
2691 + exclude = getExcludeArray( box, isSummary );
2692 + var excludedOpts = extractExcludedOptions( exclude );
2693 +
2694 + fields = getFieldList();
2695 + list = document.getElementById( 'frm-calc-list-' + fieldId );
2696 + list.innerHTML = '';
2697 +
2698 + for ( i = 0; i < fields.length; i++ ) {
2699 + if ( ( exclude && exclude.includes( fields[ i ].fieldType ) ) ||
2700 + ( excludedOpts.length && hasExcludedOption( fields[ i ], excludedOpts ) ) ) {
2701 + continue;
2702 + }
2703 +
2704 + var span = document.createElement( 'span' );
2705 + span.appendChild( document.createTextNode( '[' + fields[i].fieldId + ']' ) );
2706 +
2707 + var a = document.createElement( 'a' );
2708 + a.setAttribute( 'href', '#' );
2709 + a.setAttribute( 'data-code', fields[i].fieldId );
2710 + a.classList.add( 'frm_insert_code' );
2711 + a.appendChild( span );
2712 + a.appendChild( document.createTextNode( fields[i].fieldName ) );
2713 +
2714 + var li = document.createElement( 'li' );
2715 + li.classList.add( 'frm-field-list-' + fieldId );
2716 + li.classList.add( 'frm-field-list-' + fields[i].fieldType );
2717 + li.appendChild( a );
2718 + list.appendChild( li );
2719 + }
2720 + }
2721 +
2722 + function getExcludeArray( calcBox, isSummary ) {
2723 + var exclude = JSON.parse( calcBox.getElementsByClassName( 'frm_code_list' )[0].getAttribute( 'data-exclude' ) );
2724 +
2725 + if ( isSummary ) {
2726 + // includedExtras are those that are normally excluded from the summary but the form owner can choose to include,
2727 + // when they have been chosen to be included, then they can now be manually excluded in the calc box.
2728 + var includedExtras = getIncludedExtras();
2729 + if ( includedExtras.length ) {
2730 + for ( var i = 0; i < exclude.length; i++ ) {
2731 + if ( includedExtras.includes( exclude[ i ]) ) {
2732 + // remove it
2733 + exclude.splice( i, 1 );
2734 + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value
2735 + i--;
2736 + }
2737 + }
2738 + }
2739 + }
2740 +
2741 + return exclude;
2742 + }
2743 +
2744 + function getIncludedExtras() {
2745 + var checked = [];
2746 + var checkboxes = document.getElementsByClassName( 'frm_include_extras_field' );
2747 +
2748 + for ( var i = 0; i < checkboxes.length; i++ ) {
2749 + if ( checkboxes[i].checked ) {
2750 + checked.push( checkboxes[i].value );
2751 + }
2752 + }
2753 +
2754 + return checked;
2755 + }
2756 +
2757 + function rePopCalcFieldsForSummary() {
2758 + popCalcFields( jQuery( '.frm-inline-modal.postbox:has(.frm_js_summary_list)' )[0], true );
2759 + }
2760 +
2761 + function getFieldList( fieldType ) {
2762 + var i,
2763 + fields = [],
2764 + allFields = document.querySelectorAll( 'li.frm_field_box' ),
2765 + checkType = 'undefined' !== typeof fieldType;
2766 +
2767 + for ( i = 0; i < allFields.length; i++ ) {
2768 + // data-ftype is better (than data-type) cos of fields loaded by AJAX - which might not be ready yet
2769 + if ( checkType && allFields[ i ].getAttribute( 'data-ftype' ) !== fieldType ) {
2770 + continue;
2771 + }
2772 +
2773 + var fieldId = allFields[ i ].getAttribute( 'data-fid' );
2774 + if ( typeof fieldId !== 'undefined' && fieldId ) {
2775 + fields.push({
2776 + 'fieldId': fieldId,
2777 + 'fieldName': getPossibleValue( 'frm_name_' + fieldId ),
2778 + 'fieldType': getPossibleValue( 'field_options_type_' + fieldId ),
2779 + 'fieldKey': getPossibleValue( 'field_options_field_key_' + fieldId )
2780 + });
2781 + }
2782 + }
2783 +
2784 + return fields;
2785 + }
2786 +
2787 + function popProductFields( field ) {
2788 + var i, checked, id,
2789 + options = [],
2790 + current = getCurrentProductFields( field ),
2791 + fName = field.getAttribute( 'data-frmfname' ),
2792 + products = getFieldList( 'product' ),
2793 + quantities = getFieldList( 'quantity' ),
2794 + isSelect = field.tagName === 'SELECT', // for reverse compatibility.
2795 + // whether we have just 1 product and 1 quantity field & should therefore attach the latter to the former
2796 + auto = 1 === quantities.length && 1 === products.length;
2797 +
2798 + if ( isSelect ) {
2799 + // This fallback can be removed after 4.05.
2800 + current = field.getAttribute( 'data-frmcurrent' );
2801 + }
2802 +
2803 + for ( i = 0 ; i < products.length ; i++ ) {
2804 + // let's be double sure it's string, else indexOf will fail
2805 + id = products[ i ].fieldId.toString();
2806 + checked = auto || -1 !== current.indexOf( id );
2807 + if ( isSelect ) {
2808 + // This fallback can be removed after 4.05.
2809 + checked = checked ? ' selected' : '';
2810 + options.push( '<option value="' + id + '"' + checked + '>' + products[ i ].fieldName + '</option>' );
2811 + } else {
2812 + checked = checked ? ' checked' : '';
2813 + options.push( '<label class="frm6">' );
2814 + options.push( '<input type="checkbox" name="' + fName + '" value="' + id + '"' + checked + '> ' + products[ i ].fieldName );
2815 + options.push( '</label>' );
2816 + }
2817 + }
2818 +
2819 + field.innerHTML = options.join( '' );
2820 + }
2821 +
2822 + function getCurrentProductFields( prodFieldOpt ) {
2823 + var products = prodFieldOpt.querySelectorAll( '[type="checkbox"]:checked' ),
2824 + idsArray = [];
2825 +
2826 + for ( var i = 0; i < products.length; i++ ) {
2827 + idsArray.push( products[ i ].value );
2828 + }
2829 +
2830 + return idsArray;
2831 + }
2832 +
2833 + function popAllProductFields() {
2834 + var opts = document.querySelectorAll( '.frmjs_prod_field_opt' );
2835 + for ( var i = 0; i < opts.length; i++ ) {
2836 + popProductFields( opts[ i ]);
2837 + }
2838 + }
2839 +
2840 + function maybeSetProductField( field ) {
2841 + var fieldId = field.getAttribute( 'data-fid' ),
2842 + productFieldOpt = document.getElementById( 'field_options[product_field_' + fieldId + ']' );
2843 +
2844 + if ( null === productFieldOpt ) {
2845 + return;
2846 + }
2847 +
2848 + popProductFields( productFieldOpt );
2849 + // in order to move its settings to that LHS panel where
2850 + // the update form resides, else it'll lose this setting
2851 + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) );
2852 + }
2853 +
2854 + /**
2855 + * If the element doesn't exist, use a blank value.
2856 + */
2857 + function getPossibleValue( id ) {
2858 + field = document.getElementById( id );
2859 + if ( field !== null ) {
2860 + return field.value;
2861 + } else {
2862 + return '';
2863 + }
2864 + }
2865 +
2866 + function liveChanges() {
2867 + /*jshint validthis:true */
2868 + var option,
2869 + newValue = this.value,
2870 + changes = document.getElementById( this.getAttribute( 'data-changeme' ) ),
2871 + att = this.getAttribute( 'data-changeatt' );
2872 +
2873 + if ( changes === null ) {
2874 + return;
2875 + }
2876 +
2877 + if ( att !== null ) {
2878 + if ( changes.tagName === 'SELECT' && att === 'placeholder' ) {
2879 + option = changes.options[0];
2880 + if ( option.value === '' ) {
2881 + option.innerHTML = newValue;
2882 + } else {
2883 + // Create a placeholder option if there are no blank values.
2884 + addBlankSelectOption( changes, newValue );
2885 + }
2886 + } else if ( att === 'class' ) {
2887 + changeFieldClass( changes, this );
2888 + } else if ( isSliderField( changes ) ) {
2889 + updateSliderFieldPreview( changes, att, newValue );
2890 + } else {
2891 + changes.setAttribute( att, newValue );
2892 + }
2893 + } else if ( changes.id.indexOf( 'setup-message' ) === 0 ) {
2894 + if ( newValue !== '' ) {
2895 + changes.innerHTML = '<input type="text" value="" disabled />';
2896 + }
2897 + } else {
2898 + changes.innerHTML = newValue;
2899 + if ( changes.classList.contains( 'frm_primary_label' ) && 'break' === changes.nextElementSibling.getAttribute( 'data-ftype' ) ) {
2900 + changes.nextElementSibling.querySelector( '.frm_button_submit' ).textContent = newValue;
2901 + }
2902 + }
2903 + }
2904 +
2905 + function updateSliderFieldPreview( field, att, newValue ) {
2906 + if ( frmGlobal.proIncludesSliderJs ) {
2907 + const hookName = 'frm_update_slider_field_preview';
2908 + const hookArgs = { field, att, newValue };
2909 + wp.hooks.doAction( hookName, hookArgs );
2910 + return;
2911 + }
2912 +
2913 + // This functionality has been moved to pro since v5.4.3. This code should be removed eventually.
2914 + if ( 'value' === att ) {
2915 + if ( '' === newValue ) {
2916 + newValue = getSliderMidpoint( field );
2917 + }
2918 + field.value = newValue;
2919 + } else {
2920 + field.setAttribute( att, newValue );
2921 + }
2922 +
2923 + if ( -1 === [ 'value', 'min', 'max' ].indexOf( att ) ) {
2924 + return;
2925 + }
2926 +
2927 + if ( ( 'max' === att || 'min' === att ) && '' === getSliderDefaultValueInput( field.id ) ) {
2928 + field.value = getSliderMidpoint( field );
2929 + }
2930 +
2931 + field.parentNode.querySelector( '.frm_range_value' ).textContent = field.value;
2932 + }
2933 +
2934 + function getSliderDefaultValueInput( previewInputId ) {
2935 + return document.querySelector( 'input[data-changeme="' + previewInputId + '"][data-changeatt="value"]' ).value;
2936 + }
2937 +
2938 + function getSliderMidpoint( sliderInput ) {
2939 + const max = parseFloat( sliderInput.getAttribute( 'max' ) );
2940 + const min = parseFloat( sliderInput.getAttribute( 'min' ) );
2941 + return ( max - min ) / 2 + min;
2942 + }
2943 +
2944 + function isSliderField( previewInput ) {
2945 + return 'range' === previewInput.type && previewInput.parentNode.classList.contains( 'frm_range_container' );
2946 + }
2947 +
2948 + function toggleInvalidMsg() {
2949 + /*jshint validthis:true */
2950 + var typeDropdown, fieldType,
2951 + fieldId = this.getAttribute( 'data-fid' ),
2952 + value = '';
2953 +
2954 + [ 'field_options_max_', 'frm_format_' ].forEach( function( id ) {
2955 + var input = document.getElementById( id + fieldId );
2956 + if ( ! input ) {
2957 + return;
2958 + }
2959 +
2960 + value += input.value;
2961 + });
2962 +
2963 + typeDropdown = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0];
2964 + fieldType = typeDropdown.options[typeDropdown.selectedIndex].value;
2965 +
2966 + if ( fieldType === 'text' ) {
2967 + toggleValidationBox( '' !== value, '.frm_invalid_msg' + fieldId );
2968 + }
2969 + }
2970 +
2971 + function markRequired() {
2972 + /*jshint validthis:true */
2973 + var thisid = this.id.replace( 'frm_', '' ),
2974 + fieldId = thisid.replace( 'req_field_', '' ),
2975 + checked = this.checked,
2976 + label = jQuery( '#field_label_' + fieldId + ' .frm_required' );
2977 +
2978 + toggleValidationBox( checked, '.frm_required_details' + fieldId );
2979 +
2980 + if ( checked ) {
2981 + var $reqBox = jQuery( 'input[name="field_options[required_indicator_' + fieldId + ']"]' );
2982 + if ( $reqBox.val() === '' ) {
2983 + $reqBox.val( '*' );
2984 + }
2985 + label.removeClass( 'frm_hidden' );
2986 + } else {
2987 + label.addClass( 'frm_hidden' );
2988 + }
2989 + }
2990 +
2991 + function toggleValidationBox( hasValue, messageClass ) {
2992 + $msg = jQuery( messageClass );
2993 + if ( hasValue ) {
2994 + $msg.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' );
2995 + } else {
2996 + //Fade out validation options
2997 + var v = $msg.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(' + messageClass + '):visible' ).length;
2998 + if ( v === 0 ) {
2999 + $msg.closest( '.frm_validation_msg' ).fadeOut( 'fast' );
3000 + }
3001 + }
3002 + }
3003 +
3004 + function markUnique() {
3005 + /*jshint validthis:true */
3006 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3007 + var $thisField = jQuery( '.frm_unique_details' + fieldId );
3008 + if ( this.checked ) {
3009 + $thisField.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' );
3010 + $unqDetail = jQuery( '.frm_unique_details' + fieldId + ' input' );
3011 + if ( $unqDetail.val() === '' ) {
3012 + $unqDetail.val( frm_admin_js.default_unique );
3013 + }
3014 + } else {
3015 + var v = $thisField.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(.frm_unique_details' + fieldId + '):visible' ).length;
3016 + if ( v === 0 ) {
3017 + $thisField.closest( '.frm_validation_msg' ).fadeOut( 'fast' );
3018 + }
3019 + }
3020 + }
3021 +
3022 + //Fade confirmation field and validation option in or out
3023 + function addConf() {
3024 + /*jshint validthis:true */
3025 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3026 + var val = jQuery( this ).val();
3027 + var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) );
3028 +
3029 + toggleValidationBox( val !== '', '.frm_conf_details' + fieldId );
3030 +
3031 + if ( val !== '' ) {
3032 + //Add default validation message if empty
3033 + var valMsg = jQuery( '.frm_validation_box .frm_conf_details' + fieldId + ' input' );
3034 + if ( valMsg.val() === '' ) {
3035 + valMsg.val( frm_admin_js.default_conf );
3036 + }
3037 +
3038 + setConfirmationFieldDescriptions( fieldId );
3039 +
3040 + //Add or remove class for confirmation field styling
3041 + if ( val === 'inline' ) {
3042 + $thisField.removeClass( 'frm_conf_below' ).addClass( 'frm_conf_inline' );
3043 + } else if ( val === 'below' ) {
3044 + $thisField.removeClass( 'frm_conf_inline' ).addClass( 'frm_conf_below' );
3045 + }
3046 + jQuery( '.frm-conf-box-' + fieldId ).removeClass( 'frm_hidden' );
3047 + } else {
3048 + jQuery( '.frm-conf-box-' + fieldId ).addClass( 'frm_hidden' );
3049 + setTimeout( function() {
3050 + $thisField.removeClass( 'frm_conf_inline frm_conf_below' );
3051 + }, 200 );
3052 + }
3053 + }
3054 +
3055 + function setConfirmationFieldDescriptions( fieldId ) {
3056 + var fieldType = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0].value;
3057 +
3058 + var fieldDescription = document.getElementById( 'field_description_' + fieldId );
3059 + var hiddenDescName = 'field_options[description_' + fieldId + ']';
3060 + var newValue = frm_admin_js['enter_' + fieldType];
3061 + maybeSetNewDescription( fieldDescription, hiddenDescName, newValue );
3062 +
3063 + var confFieldDescription = document.getElementById( 'conf_field_description_' + fieldId );
3064 + var hiddenConfName = 'field_options[conf_desc_' + fieldId + ']';
3065 + var newConfValue = frm_admin_js['confirm_' + fieldType];
3066 + maybeSetNewDescription( confFieldDescription, hiddenConfName, newConfValue );
3067 + }
3068 +
3069 + function maybeSetNewDescription( descriptionDiv, hiddenName, newValue ) {
3070 + if ( descriptionDiv.innerHTML === frm_admin_js.desc ) {
3071 +
3072 + // Set the visible description value and the hidden description value
3073 + descriptionDiv.innerHTML = newValue;
3074 + document.getElementsByName( hiddenName )[0].value = newValue;
3075 + }
3076 + }
3077 +
3078 + function initBulkOptionsOverlay() {
3079 + /*jshint validthis:true */
3080 + var $info = initModal( '#frm-bulk-modal', '700px' );
3081 + if ( $info === false ) {
3082 + return;
3083 + }
3084 +
3085 + jQuery( '.frm-insert-preset' ).on( 'click', insertBulkPreset );
3086 +
3087 + jQuery( builderForm ).on( 'click', 'a.frm-bulk-edit-link', function( event ) {
3088 + event.preventDefault();
3089 + var i, key, label,
3090 + content = '',
3091 + optList,
3092 + opts,
3093 + fieldId = jQuery( this ).closest( '[data-fid]' ).data( 'fid' ),
3094 + separate = usingSeparateValues( fieldId ),
3095 + product = isProductField( fieldId );
3096 +
3097 + optList = document.getElementById( 'frm_field_' + fieldId + '_opts' );
3098 + if ( ! optList ) {
3099 + return;
3100 + }
3101 +
3102 + opts = optList.getElementsByTagName( 'li' );
3103 +
3104 + document.getElementById( 'bulk-field-id' ).value = fieldId;
3105 +
3106 + for ( i = 0; i < opts.length; i++ ) {
3107 + key = opts[i].getAttribute( 'data-optkey' );
3108 + if ( key !== '000' ) {
3109 + label = document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][label]' )[0];
3110 + if ( typeof label !== 'undefined' ) {
3111 + content += label.value;
3112 + if ( separate ) {
3113 + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][value]' )[0].value;
3114 + }
3115 + if ( product ) {
3116 + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][price]' )[0].value;
3117 + }
3118 + content += '\r\n';
3119 + }
3120 + }
3121 +
3122 + if ( i >= opts.length - 1 ) {
3123 + document.getElementById( 'frm_bulk_options' ).value = content;
3124 + }
3125 + }
3126 +
3127 + $info.dialog( 'open' );
3128 +
3129 + return false;
3130 + });
3131 +
3132 + jQuery( '#frm-update-bulk-opts' ).on( 'click', function() {
3133 + var fieldId = document.getElementById( 'bulk-field-id' ).value;
3134 + var optionType = document.getElementById( 'bulk-option-type' ).value;
3135 +
3136 + if ( optionType ) {
3137 + // Use custom handler for custom option type.
3138 + return;
3139 + }
3140 +
3141 + this.classList.add( 'frm_loading_button' );
3142 + frmAdminBuild.updateOpts( fieldId, document.getElementById( 'frm_bulk_options' ).value, $info );
3143 + });
3144 + }
3145 +
3146 + function insertBulkPreset( event ) {
3147 + /*jshint validthis:true */
3148 + var opts = JSON.parse( this.getAttribute( 'data-opts' ) );
3149 + event.preventDefault();
3150 + document.getElementById( 'frm_bulk_options' ).value = opts.join( '\n' );
3151 + return false;
3152 + }
3153 +
3154 + //Add new option or "Other" option to radio/checkbox/dropdown
3155 + function addFieldOption() {
3156 + /*jshint validthis:true */
3157 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
3158 + newOption = jQuery( '#frm_field_' + fieldId + '_opts .frm_option_template' ).prop( 'outerHTML' ),
3159 + optType = jQuery( this ).data( 'opttype' ),
3160 + optKey = 0,
3161 + oldKey = '000',
3162 + lastKey = getHighestOptKey( fieldId );
3163 +
3164 + if ( lastKey !== oldKey ) {
3165 + optKey = lastKey + 1;
3166 + }
3167 +
3168 + //Update hidden field
3169 + if ( optType === 'other' ) {
3170 + document.getElementById( 'other_input_' + fieldId ).value = 1;
3171 +
3172 + //Hide "Add Other" option now if this is radio field
3173 + var ftype = jQuery( this ).data( 'ftype' );
3174 + if ( ftype === 'radio' || ftype === 'select' ) {
3175 + jQuery( this ).fadeOut( 'slow' );
3176 + }
3177 +
3178 + var data = {
3179 + action: 'frm_add_field_option',
3180 + field_id: fieldId,
3181 + opt_key: optKey,
3182 + opt_type: optType,
3183 + nonce: frmGlobal.nonce
3184 + };
3185 + jQuery.post( ajaxurl, data, function( msg ) {
3186 + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( msg );
3187 + resetDisplayedOpts( fieldId );
3188 + });
3189 + } else {
3190 + newOption = newOption.replace( new RegExp( 'optkey="' + oldKey + '"', 'g' ), 'optkey="' + optKey + '"' );
3191 + newOption = newOption.replace( new RegExp( '-' + oldKey + '_', 'g' ), '-' + optKey + '_' );
3192 + newOption = newOption.replace( new RegExp( '-' + oldKey + '"', 'g' ), '-' + optKey + '"' );
3193 + newOption = newOption.replace( new RegExp( '\\[' + oldKey + '\\]', 'g' ), '[' + optKey + ']' );
3194 + newOption = newOption.replace( 'frm_hidden frm_option_template', '' );
3195 + newOption = { newOption };
3196 + addSaveAndDragIconsToOption( fieldId, newOption );
3197 + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( newOption.newOption );
3198 + resetDisplayedOpts( fieldId );
3199 + }
3200 + }
3201 +
3202 + function getHighestOptKey( fieldId ) {
3203 + var i = 0,
3204 + optKey = 0,
3205 + opts = jQuery( '#frm_field_' + fieldId + '_opts li' ),
3206 + lastKey = 0;
3207 +
3208 + for ( i; i < opts.length; i++ ) {
3209 + optKey = opts[i].getAttribute( 'data-optkey' );
3210 + if ( opts.length === 1 ) {
3211 + return optKey;
3212 + }
3213 + if ( optKey !== '000' ) {
3214 + optKey = optKey.replace( 'other_', '' );
3215 + optKey = parseInt( optKey, 10 );
3216 + }
3217 +
3218 + if ( ! isNaN( lastKey ) && ( optKey > lastKey || lastKey === '000' ) ) {
3219 + lastKey = optKey;
3220 + }
3221 + }
3222 +
3223 + return lastKey;
3224 + }
3225 +
3226 + function toggleMultSel() {
3227 + /*jshint validthis:true */
3228 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3229 + toggleMultiSelect( fieldId, this.value );
3230 + }
3231 +
3232 + function toggleMultiSelect( fieldId, value ) {
3233 + var setting = jQuery( '.frm_multiple_cont_' + fieldId );
3234 + if ( value === 'select' ) {
3235 + setting.fadeIn( 'fast' );
3236 + } else {
3237 + setting.fadeOut( 'fast' );
3238 + }
3239 + }
3240 +
3241 + function toggleSepValues() {
3242 + /*jshint validthis:true */
3243 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3244 + toggle( jQuery( '.field_' + fieldId + '_option_key' ) );
3245 + jQuery( '.field_' + fieldId + '_option' ).toggleClass( 'frm_with_key' );
3246 + }
3247 +
3248 + function toggleImageOptions() {
3249 + /*jshint validthis:true */
3250 + var hasImageOptions, imageSize,
3251 + $field = jQuery( this ).closest( '.frm-single-settings' ),
3252 + fieldId = $field.data( 'fid' ),
3253 + displayField = document.getElementById( 'frm_field_id_' + fieldId );
3254 +
3255 + refreshOptionDisplayNow( jQuery( this ) );
3256 +
3257 + toggle( jQuery( '.field_' + fieldId + '_image_id' ) );
3258 + toggle( jQuery( '.frm_toggle_image_options_' + fieldId ) );
3259 + toggle( jQuery( '.frm_image_size_' + fieldId ) );
3260 + toggle( jQuery( '.frm_alignment_' + fieldId ) );
3261 + toggle( jQuery( '.frm-add-other#frm_add_field_' + fieldId ) );
3262 +
3263 + hasImageOptions = imagesAsOptions( fieldId );
3264 +
3265 + if ( hasImageOptions ) {
3266 + setAlignment( fieldId, 'inline' );
3267 + removeImageSizeClasses( displayField );
3268 + imageSize = getImageOptionSize( fieldId );
3269 + displayField.classList.add( 'frm_image_options' );
3270 + displayField.classList.add( 'frm_image_size_' + imageSize );
3271 + $field.find( '.frm-bulk-edit-link' ).hide();
3272 + } else {
3273 + displayField.classList.remove( 'frm_image_options' );
3274 + removeImageSizeClasses( displayField );
3275 + setAlignment( fieldId, 'block' );
3276 + $field.find( '.frm-bulk-edit-link' ).show();
3277 + }
3278 + }
3279 +
3280 + function removeImageSizeClasses( field ) {
3281 + field.classList.remove( 'frm_image_size_', 'frm_image_size_small', 'frm_image_size_medium', 'frm_image_size_large', 'frm_image_size_xlarge' );
3282 + }
3283 +
3284 + function setAlignment( fieldId, alignment ) {
3285 + jQuery( '#field_options_align_' + fieldId ).val( alignment ).trigger( 'change' );
3286 + }
3287 +
3288 + function setImageSize() {
3289 + var $field = jQuery( this ).closest( '.frm-single-settings' ),
3290 + fieldId = $field.data( 'fid' ),
3291 + displayField = document.getElementById( 'frm_field_id_' + fieldId );
3292 +
3293 + refreshOptionDisplay();
3294 +
3295 + if ( imagesAsOptions( fieldId ) ) {
3296 + removeImageSizeClasses( displayField );
3297 + displayField.classList.add( 'frm_image_options' );
3298 + displayField.classList.add( 'frm_image_size_' + getImageOptionSize( fieldId ) );
3299 + }
3300 + }
3301 +
3302 + function refreshOptionDisplayNow( object ) {
3303 + var $field = object.closest( '.frm-single-settings' ),
3304 + fieldID = $field.data( 'fid' );
3305 + jQuery( '.field_' + fieldID + '_option' ).trigger( 'change' );
3306 + }
3307 +
3308 + function refreshOptionDisplay() {
3309 + /*jshint validthis:true */
3310 + refreshOptionDisplayNow( jQuery( this ) );
3311 + }
3312 +
3313 + function addImageToOption( event ) {
3314 + const imagePreview = event.target.closest( '.frm_image_preview_wrapper' );
3315 +
3316 + event.preventDefault();
3317 +
3318 + wp.media.model.settings.post.id = 0;
3319 +
3320 + const fileFrame = wp.media.frames.file_frame = wp.media({
3321 + multiple: false,
3322 + library: {
3323 + type: [ 'image' ]
3324 + }
3325 + });
3326 +
3327 + fileFrame.on( 'select', function() {
3328 + const attachment = fileFrame.state().get( 'selection' ).first().toJSON();
3329 + const img = imagePreview.querySelector( 'img' );
3330 +
3331 + img.setAttribute( 'src', attachment.url );
3332 + img.classList.remove( 'frm_hidden' );
3333 + img.removeAttribute( 'srcset' ); // Prevent the old image from sticking around.
3334 +
3335 + imagePreview.querySelector( '.frm_image_preview_frame' ).style.display = 'block';
3336 + imagePreview.querySelector( '.frm_image_preview_title' ).textContent = attachment.filename;
3337 + imagePreview.querySelector( '.frm_choose_image_box' ).style.display = 'none';
3338 +
3339 + const $imagePreview = jQuery( imagePreview );
3340 + $imagePreview.siblings( 'input[name*="[label]"]' ).data( 'frmimgurl', attachment.url );
3341 + $imagePreview.find( 'input.frm_image_id' ).val( attachment.id ).trigger( 'change' );
3342 + wp.media.model.settings.post.id = 0;
3343 + });
3344 +
3345 + fileFrame.open();
3346 + }
3347 +
3348 + function removeImageFromOption( event ) {
3349 + var $this = jQuery( this ),
3350 + previewWrapper = $this.closest( '.frm_image_preview_wrapper' );
3351 +
3352 + event.preventDefault();
3353 + event.stopPropagation();
3354 +
3355 + previewWrapper.find( 'img' ).attr( 'src', '' );
3356 + previewWrapper.find( '.frm_image_preview_frame' ).hide();
3357 + previewWrapper.find( '.frm_choose_image_box' ).show();
3358 + previewWrapper.find( 'input.frm_image_id' ).val( 0 ).trigger( 'change' );
3359 + }
3360 +
3361 + function toggleMultiselect() {
3362 + /*jshint validthis:true */
3363 + var dropdown = jQuery( this ).closest( 'li' ).find( '.frm_form_fields select' );
3364 + if ( this.checked ) {
3365 + dropdown.attr( 'multiple', 'multiple' );
3366 + } else {
3367 + dropdown.removeAttr( 'multiple' );
3368 + }
3369 + }
3370 +
3371 + /**
3372 + * Allow typing on form switcher click without an extra click to search.
3373 + */
3374 + function focusSearchBox() {
3375 + var searchBox = document.getElementById( 'dropform-search-input' );
3376 + if ( searchBox !== null ) {
3377 + setTimeout( function() {
3378 + searchBox.focus();
3379 + }, 100 );
3380 + }
3381 + }
3382 +
3383 + /**
3384 + * If a field is clicked in the builder, prevent inputs from changing.
3385 + */
3386 + function stopFieldFocus( e ) {
3387 + e.preventDefault();
3388 + }
3389 +
3390 + function deleteFieldOption() {
3391 + /*jshint validthis:true */
3392 + var otherInput,
3393 + parentLi = this.parentNode,
3394 + parentUl = parentLi.parentNode,
3395 + fieldId = this.getAttribute( 'data-fid' );
3396 +
3397 + jQuery( parentLi ).fadeOut( 'slow', function() {
3398 + jQuery( parentLi ).remove();
3399 +
3400 + var hasOther = jQuery( parentUl ).find( '.frm_other_option' );
3401 + if ( hasOther.length < 1 ) {
3402 + otherInput = document.getElementById( 'other_input_' + fieldId );
3403 + if ( otherInput !== null ) {
3404 + otherInput.value = 0;
3405 + }
3406 + jQuery( '#other_button_' + fieldId ).fadeIn( 'slow' );
3407 + }
3408 + });
3409 + }
3410 +
3411 + /**
3412 + * If a radio button is set as default, allow a click to
3413 + * deselect it.
3414 + */
3415 + function maybeUncheckRadio() {
3416 + var $self, uncheck, unbind, up;
3417 +
3418 + /*jshint validthis:true */
3419 + $self = jQuery( this );
3420 + if ( $self.is( ':checked' ) ) {
3421 + uncheck = function() {
3422 + setTimeout( function() {
3423 + $self.prop( 'checked', false );
3424 + }, 0 );
3425 + };
3426 + unbind = function() {
3427 + $self.off( 'mouseup', up );
3428 + };
3429 + up = function() {
3430 + uncheck();
3431 + unbind();
3432 + };
3433 + $self.on( 'mouseup', up );
3434 + $self.one( 'mouseout', unbind );
3435 + }
3436 + }
3437 +
3438 + /**
3439 + * If the field option has the default text, clear it out on click.
3440 + */
3441 + function maybeClearOptText() {
3442 + /*jshint validthis:true */
3443 + if ( this.value === frm_admin_js.new_option ) {
3444 + this.setAttribute( 'data-value-on-focus', this.value );
3445 + this.value = '';
3446 + }
3447 + }
3448 +
3449 + function clickDeleteField() {
3450 + /*jshint validthis:true */
3451 + var confirmMsg = frm_admin_js.conf_delete,
3452 + maybeDivider = this.parentNode.parentNode.parentNode.parentNode.parentNode,
3453 + li = maybeDivider.parentNode,
3454 + field = jQuery( this ).closest( 'li.form-field' ),
3455 + fieldId = field.data( 'fid' );
3456 +
3457 + if ( li.classList.contains( 'frm-section-collapsed' ) || li.classList.contains( 'frm-page-collapsed' ) ) {
3458 + return false;
3459 + }
3460 +
3461 + // If deleting a section, use a special message.
3462 + if ( maybeDivider.className === 'divider_section_only' ) {
3463 + confirmMsg = frm_admin_js.conf_delete_sec;
3464 + this.setAttribute( 'data-frmcaution', frm_admin_js.caution );
3465 + }
3466 +
3467 + this.setAttribute( 'data-frmverify', confirmMsg );
3468 + this.setAttribute( 'data-deletefield', fieldId );
3469 +
3470 + closeOpenFieldDropdowns();
3471 +
3472 + confirmLinkClick( this );
3473 + return false;
3474 + }
3475 +
3476 + function clickSelectField() {
3477 + this.closest( 'li.form-field' ).click();
3478 + }
3479 +
3480 + function clickDeleteFieldGroup() {
3481 + var hoverTarget, decoy;
3482 +
3483 + hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3484 + if ( null === hoverTarget ) {
3485 + return;
3486 + }
3487 +
3488 + hoverTarget.classList.add( 'frm-selected-field-group' );
3489 +
3490 + decoy = document.createElement( 'div' );
3491 + decoy.classList.add( 'frm-delete-field-groups', 'frm_hidden' );
3492 + document.body.appendChild( decoy );
3493 + decoy.click();
3494 + }
3495 +
3496 + function duplicateFieldGroup() {
3497 + const hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3498 + if ( null === hoverTarget ) {
3499 + return;
3500 + }
3501 +
3502 + const newRowId = 'frm_field_group_' + getAutoId();
3503 + const placeholderUlChild = document.createTextNode( '' );
3504 + wrapFieldLiInPlace( placeholderUlChild );
3505 +
3506 + const newRow = jQuery( placeholderUlChild ).closest( 'li' ).get( 0 );
3507 + newRow.classList.add( 'frm_hidden' );
3508 +
3509 + const newRowUl = newRow.querySelector( 'ul' );
3510 + newRowUl.id = newRowId;
3511 +
3512 + jQuery( hoverTarget.closest( 'li.frm_field_box' ) ).after( newRow );
3513 +
3514 + const $fields = getFieldsInRow( jQuery( hoverTarget ) );
3515 + const syncDetails = [];
3516 + const injectedCloneOptions = [];
3517 +
3518 + const expectedLength = $fields.length;
3519 + const originalFieldIdByDuplicatedFieldId = {};
3520 +
3521 + let duplicatedCount = 0;
3522 +
3523 + jQuery( newRow ).on(
3524 + 'frm_added_duplicated_field_to_row',
3525 + function( _, args ) {
3526 + originalFieldIdByDuplicatedFieldId[ jQuery( args.duplicatedFieldHtml ).attr( 'data-fid' ) ] = args.originalFieldId;
3527 +
3528 + if ( expectedLength > ++duplicatedCount ) {
3529 + return;
3530 + }
3531 +
3532 + const $newRowUl = jQuery( newRowUl );
3533 + const $duplicatedFields = getFieldsInRow( $newRowUl );
3534 +
3535 + injectedCloneOptions.forEach(
3536 + function( cloneOption ) {
3537 + cloneOption.remove();
3538 + }
3539 + );
3540 +
3541 + for ( let index = 0; index < expectedLength; ++index ) {
3542 + $newRowUl.append( $newRowUl.children( 'li.form-field[frm-field-order="' + index + '"]' ) );
3543 + }
3544 +
3545 + syncLayoutClasses( $duplicatedFields.first(), syncDetails );
3546 + newRow.classList.remove( 'frm_hidden' );
3547 + updateFieldOrder();
3548 +
3549 + getFieldsInRow( $newRowUl ).each(
3550 + function() {
3551 + maybeDuplicateUnsavedSettings( originalFieldIdByDuplicatedFieldId[ this.getAttribute( 'data-fid' ) ], jQuery( this ).prop( 'outerHTML' ) );
3552 + }
3553 + );
3554 + }
3555 + );
3556 +
3557 + $fields.each(
3558 + function( index ) {
3559 + var cloneOption;
3560 + cloneOption = document.createElement( 'li' );
3561 + cloneOption.classList.add( 'frm_clone_field' );
3562 + cloneOption.setAttribute( 'frm-target-row-id', newRowId );
3563 + cloneOption.setAttribute( 'frm-field-order', index );
3564 + this.appendChild( cloneOption );
3565 + cloneOption.click();
3566 + injectedCloneOptions.push( cloneOption );
3567 + syncDetails.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) );
3568 + }
3569 + );
3570 + }
3571 +
3572 + function clickFieldGroupLayout() {
3573 + var hoverTarget, sizeOfFieldGroup, popupWrapper;
3574 +
3575 + hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3576 +
3577 + if ( null === hoverTarget ) {
3578 + return;
3579 + }
3580 +
3581 + deselectFields();
3582 +
3583 + sizeOfFieldGroup = getSizeOfFieldGroupFromChildElement( hoverTarget.querySelector( 'li.form-field' ) );
3584 +
3585 + hoverTarget.classList.add( 'frm-has-open-field-group-popup' );
3586 + jQuery( document ).on( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick );
3587 +
3588 + popupWrapper = div();
3589 + popupWrapper.style.position = 'relative';
3590 + popupWrapper.appendChild( getFieldGroupPopup( sizeOfFieldGroup, this ) );
3591 + this.parentNode.appendChild( popupWrapper );
3592 +
3593 + const firstLayoutOption = popupWrapper.querySelector( '.frm-row-layout-option' );
3594 + if ( firstLayoutOption ) {
3595 + firstLayoutOption.focus();
3596 + }
3597 + }
3598 +
3599 + function destroyFieldGroupPopupOnOutsideClick( event ) {
3600 + if ( event.target.classList.contains( 'frm-custom-field-group-layout' ) || event.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) {
3601 + return;
3602 + }
3603 + if ( ! jQuery( event.target ).closest( '#frm_field_group_controls' ).length && ! jQuery( event.target ).closest( '#frm_field_group_popup' ).length ) {
3604 + destroyFieldGroupPopup();
3605 + }
3606 + }
3607 +
3608 + function getSizeOfFieldGroupFromChildElement( element ) {
3609 + var $ul = jQuery( element ).closest( 'ul' );
3610 + if ( $ul.length ) {
3611 + return getFieldsInRow( $ul ).length;
3612 + }
3613 + return getSelectedFieldCount();
3614 + }
3615 +
3616 + function getFieldGroupPopup( sizeOfFieldGroup, childElement ) {
3617 + var popup, wrapper, rowLayoutOptions, ul;
3618 +
3619 + popup = document.getElementById( 'frm_field_group_popup' );
3620 + if ( null === popup ) {
3621 + popup = div();
3622 + } else {
3623 + popup.innerHTML = '';
3624 + }
3625 +
3626 + popup.id = 'frm_field_group_popup';
3627 +
3628 + wrapper = div();
3629 + wrapper.style.padding = '0 24px 12px';
3630 + wrapper.appendChild( getRowLayoutTitle() );
3631 +
3632 + rowLayoutOptions = getRowLayoutOptions( sizeOfFieldGroup );
3633 +
3634 + ul = childElement.closest( 'ul.frm_sorting' );
3635 + if ( null !== ul ) {
3636 + maybeMarkRowLayoutAsActive( ul, rowLayoutOptions );
3637 + }
3638 +
3639 + wrapper.appendChild( rowLayoutOptions );
3640 +
3641 + popup.appendChild( wrapper );
3642 + popup.appendChild( separator() );
3643 +
3644 + popup.appendChild( getCustomLayoutOption() );
3645 + popup.appendChild( getBreakIntoDifferentRowsOption() );
3646 +
3647 + return popup;
3648 + }
3649 +
3650 + function maybeMarkRowLayoutAsActive( activeRow, options ) {
3651 + var length, index, currentRow;
3652 +
3653 + length = options.children.length;
3654 + for ( index = 0; index < length; ++index ) {
3655 + currentRow = options.children[ index ];
3656 + if ( rowLayoutsMatch( currentRow, activeRow ) ) {
3657 + currentRow.classList.add( 'frm-active-row-layout' );
3658 + return;
3659 + }
3660 + }
3661 + }
3662 +
3663 + function separator() {
3664 + var hr = document.createElement( 'hr' );
3665 + return hr;
3666 + }
3667 +
3668 + function getCustomLayoutOption() {
3669 + var option = div();
3670 + option.textContent = __( 'Custom layout', 'formidable' );
3671 + jQuery( option ).prepend( getIconClone( 'frm_gear_svg' ) );
3672 + option.classList.add( 'frm-custom-field-group-layout' );
3673 + makeTabbable( option );
3674 + return option;
3675 + }
3676 +
3677 + function makeTabbable( element, ariaLabel ) {
3678 + element.setAttribute( 'tabindex', 0 );
3679 + element.setAttribute( 'role', 'button' );
3680 + if ( 'undefined' !== typeof ariaLabel ) {
3681 + element.setAttribute( 'aria-label', ariaLabel );
3682 + }
3683 + }
3684 +
3685 + function getIconClone( iconId ) {
3686 + var clone = document.getElementById( iconId ).cloneNode( true );
3687 + clone.id = '';
3688 + return clone;
3689 + }
3690 +
3691 + function getBreakIntoDifferentRowsOption() {
3692 + var option = div();
3693 + option.textContent = __( 'Break into rows', 'formidable' );
3694 + jQuery( option ).prepend( getIconClone( 'frm_break_field_group_svg' ) );
3695 + option.classList.add( 'frm-break-field-group' );
3696 + makeTabbable( option );
3697 + return option;
3698 + }
3699 +
3700 + function getRowLayoutTitle() {
3701 + var rowLayoutTitle = div();
3702 + rowLayoutTitle.classList.add( 'frm-row-layout-title' );
3703 + rowLayoutTitle.textContent = __( 'Row Layout', 'formidable' );
3704 + return rowLayoutTitle;
3705 + }
3706 +
3707 + function getRowLayoutOptions( size ) {
3708 + var wrapper, padding;
3709 +
3710 + wrapper = getEmptyGridContainer();
3711 + if ( 5 !== size ) {
3712 + wrapper.appendChild( getRowLayoutOption( size, 'even' ) );
3713 + }
3714 + if ( size % 2 === 1 ) {
3715 + // only include the middle option for odd numbers because even doesn't make a lot of sense.
3716 + wrapper.appendChild( getRowLayoutOption( size, 'middle' ) );
3717 + }
3718 + if ( size < 6 ) {
3719 + wrapper.appendChild( getRowLayoutOption( size, 'left' ) );
3720 + wrapper.appendChild( getRowLayoutOption( size, 'right' ) );
3721 + } else {
3722 + padding = div();
3723 + padding.classList.add( 'frm_fourth' );
3724 + wrapper.prepend( padding );
3725 + }
3726 +
3727 + return wrapper;
3728 + }
3729 +
3730 + function getRowLayoutOption( size, type ) {
3731 + var option, useClass;
3732 +
3733 + option = div();
3734 + option.classList.add( 'frm-row-layout-option' );
3735 + makeTabbable( option, type );
3736 +
3737 + switch ( size ) {
3738 + case 6:
3739 + useClass = 'frm_half';
3740 + break;
3741 + case 5:
3742 + useClass = 'frm_third';
3743 + break;
3744 + default:
3745 + useClass = size % 2 === 1 ? 'frm_fourth' : 'frm_third';
3746 + break;
3747 + }
3748 +
3749 + option.classList.add( useClass );
3750 + option.setAttribute( 'layout-type', type );
3751 +
3752 + option.appendChild( getRowForSizeAndType( size, type ) );
3753 + return option;
3754 + }
3755 +
3756 + function rowLayoutsMatch( row1, row2 ) {
3757 + return getRowLayoutAsKey( row1 ) === getRowLayoutAsKey( row2 );
3758 + }
3759 +
3760 + function getRowLayoutAsKey( row ) {
3761 + var $fields, sizes;
3762 + if ( row.classList.contains( 'frm-row-layout-option' ) ) {
3763 + $fields = jQuery( row ).find( '.frm_grid_container' ).children();
3764 + } else {
3765 + $fields = getFieldsInRow( jQuery( row ) );
3766 + }
3767 + sizes = [];
3768 + $fields.each(
3769 + function() {
3770 + sizes.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) );
3771 + }
3772 + );
3773 + return sizes.join( '-' );
3774 + }
3775 +
3776 + function getRowForSizeAndType( size, type ) {
3777 + var row, index, block;
3778 +
3779 + row = getEmptyGridContainer();
3780 + for ( index = 0; index < size; ++index ) {
3781 + block = div();
3782 + block.classList.add( getClassForBlock( size, type, index ) );
3783 + block.style.height = '16px';
3784 + block.style.background = '#9EA9B8';
3785 + block.style.borderRadius = '1px';
3786 + row.appendChild( block );
3787 + }
3788 +
3789 + return row;
3790 + }
3791 +
3792 + /**
3793 + * @param {int} size 2-6.
3794 + * @param {string} type even, middle, left, or right.
3795 + * @param {int} index 0-5.
3796 + * @returns string
3797 + */
3798 + function getClassForBlock( size, type, index ) {
3799 + if ( 'even' === type ) {
3800 + return getEvenClassForSize( size, index );
3801 + } else if ( 'middle' === type ) {
3802 + if ( 3 === size ) {
3803 + return 1 === index ? 'frm6' : 'frm3';
3804 + }
3805 + if ( 5 === size ) {
3806 + return 2 === index ? 'frm4' : 'frm2';
3807 + }
3808 + } else if ( 'left' === type ) {
3809 + return 0 === index ? getLargeClassForSize( size ) : getSmallClassForSize( size );
3810 + } else if ( 'right' === type ) {
3811 + return index === size - 1 ? getLargeClassForSize( size ) : getSmallClassForSize( size );
3812 + }
3813 + return 'frm12';
3814 + }
3815 +
3816 + function getEvenClassForSize( size, index ) {
3817 + if ( -1 !== [ 2, 3, 4, 6 ].indexOf( size ) ) {
3818 + return getLayoutClassForSize( 12 / size );
3819 + }
3820 + if ( 5 === size && 'undefined' !== typeof index ) {
3821 + return 0 === index ? 'frm4' : 'frm2';
3822 + }
3823 + return 'frm12';
3824 + }
3825 +
3826 + function getSmallClassForSize( size ) {
3827 + switch ( size ) {
3828 + case 2: case 3:
3829 + return 'frm3';
3830 + case 4:
3831 + return 'frm2';
3832 + case 5:
3833 + return 'frm2';
3834 + case 6:
3835 + return 'frm1';
3836 + }
3837 + return 'frm12';
3838 + }
3839 +
3840 + function getLargeClassForSize( size ) {
3841 + switch ( size ) {
3842 + case 2:
3843 + return 'frm9';
3844 + case 3: case 4:
3845 + return 'frm6';
3846 + case 5:
3847 + return 'frm4';
3848 + case 6:
3849 + return 'frm7';
3850 + }
3851 + return 'frm12';
3852 + }
3853 +
3854 + function getEmptyGridContainer() {
3855 + var wrapper = div();
3856 + wrapper.classList.add( 'frm_grid_container' );
3857 + return wrapper;
3858 + }
3859 +
3860 + function handleFieldGroupLayoutOptionClick() {
3861 + var type, row;
3862 + type = this.getAttribute( 'layout-type' );
3863 + row = document.querySelector( '.frm-field-group-hover-target' );
3864 + size = getFieldsInRow( jQuery( row ) ).length;
3865 + syncLayoutClasses( getFieldsInRow( jQuery( row ) ).first(), type );
3866 + destroyFieldGroupPopup();
3867 + }
3868 +
3869 + function handleFieldGroupLayoutOptionInsideMergeClick() {
3870 + var $ul, type;
3871 + $ul = mergeSelectedFieldGroups();
3872 + type = this.getAttribute( 'layout-type' );
3873 + syncLayoutClasses( getFieldsInRow( $ul ).first(), type );
3874 + unselectFieldGroups();
3875 + }
3876 +
3877 + function mergeSelectedFieldGroups() {
3878 + var $selectedFieldGroups = jQuery( '.frm-selected-field-group' ),
3879 + $firstGroupUl = $selectedFieldGroups.first();
3880 + $selectedFieldGroups.not( $firstGroupUl ).each(
3881 + function() {
3882 + getFieldsInRow( jQuery( this ) ).each(
3883 + function() {
3884 + var previousParent = this.parentNode;
3885 + getFieldsInRow( $firstGroupUl ).last().after( this );
3886 + if ( ! jQuery( previousParent ).children( 'li.form-field' ).length ) {
3887 + // clean up the previous field group if we've removed all of its fields.
3888 + previousParent.closest( 'li.frm_field_box' ).remove();
3889 + }
3890 + }
3891 + );
3892 + }
3893 + );
3894 + updateFieldOrder();
3895 + syncLayoutClasses( getFieldsInRow( $firstGroupUl ).first() );
3896 + return $firstGroupUl;
3897 + }
3898 +
3899 + function customFieldGroupLayoutClick() {
3900 + var $fields;
3901 + if ( null !== this.closest( '.frm-merge-fields-into-row' ) ) {
3902 + return;
3903 + }
3904 + $fields = getFieldsInRow( jQuery( '.frm-field-group-hover-target' ) );
3905 + setupCustomLayoutOptions( $fields );
3906 + }
3907 +
3908 + function setupCustomLayoutOptions( $fields ) {
3909 + var size, popup, wrapper, layoutClass, inputRow, paddingElement, inputValueOverride, index, inputField, heading, label, buttonsWrapper, cancelButton, saveButton;
3910 +
3911 + size = $fields.length;
3912 +
3913 + popup = document.getElementById( 'frm_field_group_popup' );
3914 + popup.innerHTML = '';
3915 +
3916 + wrapper = div();
3917 + wrapper.style.padding = '24px';
3918 +
3919 + layoutClass = getEvenClassForSize( 5 === size ? 6 : size );
3920 +
3921 + inputRow = div();
3922 + inputRow.style.padding = '20px 0';
3923 + inputRow.classList.add( 'frm_grid_container' );
3924 +
3925 + if ( 5 === size ) {
3926 + // add a span to pad the inputs by 1 column, to account for the missing 2 columns.
3927 + paddingElement = document.createElement( 'span' );
3928 + paddingElement.classList.add( 'frm1' );
3929 + inputRow.appendChild( paddingElement );
3930 + }
3931 +
3932 + inputValueOverride = getSelectedFieldCount() > 0 ? getSizeOfLayoutClass( getEvenClassForSize( size ) ) : false;
3933 + if ( false !== inputValueOverride && inputValueOverride >= 12 ) {
3934 + inputValueOverride = Math.floor( 12 / size );
3935 + }
3936 +
3937 + for ( index = 0; index < size; ++index ) {
3938 + inputField = document.createElement( 'input' );
3939 + inputField.type = 'text';
3940 + inputField.classList.add( layoutClass );
3941 + inputField.classList.add( 'frm-custom-grid-size-input' );
3942 + inputField.value = false !== inputValueOverride ? inputValueOverride : getSizeOfLayoutClass( getLayoutClassName( $fields.get( index ).classList ) );
3943 + inputRow.appendChild( inputField );
3944 + }
3945 +
3946 + heading = div();
3947 + heading.classList.add( 'frm-builder-popup-heading' );
3948 + heading.textContent = __( 'Enter number of columns for each field', 'formidable' );
3949 +
3950 + label = div();
3951 + label.classList.add( 'frm-builder-popup-subheading' );
3952 + label.textContent = __( 'Layouts are based on a 12-column grid system', 'formidable' );
3953 +
3954 + wrapper.appendChild( heading );
3955 + wrapper.appendChild( label );
3956 +
3957 + wrapper.appendChild( inputRow );
3958 +
3959 + buttonsWrapper = div();
3960 + buttonsWrapper.style.textAlign = 'right';
3961 +
3962 + cancelButton = getSecondaryButton();
3963 + cancelButton.textContent = __( 'Cancel', 'formidable' );
3964 + cancelButton.classList.add( 'frm-cancel-custom-field-group-layout' );
3965 + cancelButton.style.marginRight = '10px';
3966 +
3967 + saveButton = getPrimaryButton();
3968 + saveButton.textContent = __( 'Save', 'formidable' );
3969 + saveButton.classList.add( 'frm-save-custom-field-group-layout' );
3970 +
3971 + buttonsWrapper.appendChild( cancelButton );
3972 + buttonsWrapper.appendChild( saveButton );
3973 +
3974 + wrapper.appendChild( buttonsWrapper );
3975 +
3976 + popup.appendChild( wrapper );
3977 +
3978 + setTimeout(
3979 + function() {
3980 + const firstInput = popup.querySelector( 'input.frm-custom-grid-size-input' ).focus();
3981 + if ( firstInput ) {
3982 + firstInput.focus();
3983 + }
3984 + },
3985 + 0
3986 + );
3987 + }
3988 +
3989 + function customFieldGroupLayoutInsideMergeClick() {
3990 + $fields = jQuery( '.frm-selected-field-group li.form-field' );
3991 + setupCustomLayoutOptions( $fields );
3992 + }
3993 +
3994 + function getPrimaryButton() {
3995 + var button = getButton();
3996 + button.classList.add( 'button-primary', 'frm-button-primary' );
3997 + return button;
3998 + }
3999 +
4000 + function getSecondaryButton() {
4001 + var button = getButton();
4002 + button.classList.add( 'button-secondary', 'frm-button-secondary' );
4003 + return button;
4004 + }
4005 +
4006 + function getButton() {
4007 + var button = document.createElement( 'a' );
4008 + button.setAttribute( 'href', '#' );
4009 + button.classList.add( 'button' );
4010 + button.style.textDecoration = 'none';
4011 + return button;
4012 + }
4013 +
4014 + function getSizeOfLayoutClass( className ) {
4015 + switch ( className ) {
4016 + case 'frm_half':
4017 + return 6;
4018 + case 'frm_third':
4019 + return 4;
4020 + case 'frm_two_thirds':
4021 + return 8;
4022 + case 'frm_fourth':
4023 + return 3;
4024 + case 'frm_three_fourths':
4025 + return 9;
4026 + case 'frm_sixth':
4027 + return 2;
4028 + }
4029 +
4030 + if ( 0 === className.indexOf( 'frm' ) ) {
4031 + return parseInt( className.substr( 3 ) );
4032 + }
4033 +
4034 + // Anything missing a layout class should be a full width row.
4035 + return 12;
4036 + }
4037 +
4038 + function getLayoutClassName( classList ) {
4039 + var classes, index, currentClass;
4040 + classes = getLayoutClasses();
4041 + for ( index = 0; index < classes.length; ++index ) {
4042 + currentClass = classes[ index ];
4043 + if ( classList.contains( currentClass ) ) {
4044 + return currentClass;
4045 + }
4046 + }
4047 + return '';
4048 + }
4049 +
4050 + function getLayoutClassForSize( size ) {
4051 + return 'frm' + size;
4052 + }
4053 +
4054 + function breakFieldGroupClick() {
4055 + var row = document.querySelector( '.frm-field-group-hover-target' );
4056 + breakRow( row );
4057 + destroyFieldGroupPopup();
4058 + }
4059 +
4060 + function breakRow( row ) {
4061 + const $row = jQuery( row );
4062 + getFieldsInRow( $row ).each(
4063 + function( index ) {
4064 + const field = this;
4065 + if ( 0 !== index ) {
4066 + $row.parent().after( wrapFieldLi( field ) );
4067 + }
4068 + stripLayoutFromFields( jQuery( field ) );
4069 + }
4070 + );
4071 + }
4072 +
4073 + function stripLayoutFromFields( field ) {
4074 + syncLayoutClasses( field, 'clear' );
4075 + }
4076 +
4077 + function focusFieldGroupInputOnClick() {
4078 + this.select();
4079 + }
4080 +
4081 + function cancelCustomFieldGroupClick() {
4082 + revertToFieldGroupPopupFirstPage( this );
4083 + }
4084 +
4085 + function revertToFieldGroupPopupFirstPage( triggerElement ) {
4086 + jQuery( document.getElementById( 'frm_field_group_popup' ) ).replaceWith(
4087 + getFieldGroupPopup( getSizeOfFieldGroupFromChildElement( triggerElement ), triggerElement )
4088 + );
4089 + }
4090 +
4091 + function destroyFieldGroupPopup() {
4092 + var popup, wrapper;
4093 + popup = document.getElementById( 'frm_field_group_popup' );
4094 + if ( popup === null ) {
4095 + return;
4096 + }
4097 + wrapper = document.querySelector( '.frm-has-open-field-group-popup' );
4098 + if ( null !== wrapper ) {
4099 + wrapper.classList.remove( 'frm-has-open-field-group-popup' );
4100 + popup.parentNode.remove();
4101 + }
4102 + jQuery( document ).off( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick );
4103 + }
4104 +
4105 + function saveCustomFieldGroupClick() {
4106 + var syncDetails, $controls, $ul;
4107 +
4108 + syncDetails = [];
4109 +
4110 + jQuery( document.getElementById( 'frm_field_group_popup' ).querySelectorAll( '.frm_grid_container input' ) )
4111 + .each(
4112 + function() {
4113 + syncDetails.push( parseInt( this.value ) );
4114 + }
4115 + );
4116 +
4117 + $controls = jQuery( document.getElementById( 'frm_field_group_controls' ) );
4118 +
4119 + if ( $controls.length && 'none' !== $controls.get( 0 ).style.display ) {
4120 + syncLayoutClasses( getFieldsInRow( jQuery( document.querySelector( '.frm-field-group-hover-target' ) ) ).first(), syncDetails );
4121 + } else {
4122 + $ul = mergeSelectedFieldGroups();
4123 + syncLayoutClasses( getFieldsInRow( $ul ).first(), syncDetails );
4124 + unselectFieldGroups();
4125 + }
4126 +
4127 + destroyFieldGroupPopup();
4128 + }
4129 +
4130 + function fieldGroupClick( e ) {
4131 + if ( 'ul' !== e.originalEvent.target.nodeName.toLowerCase() ) {
4132 + // only continue if the group itself was clicked / ignore when a field is clicked.
4133 + return;
4134 + }
4135 +
4136 + const hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
4137 + if ( ! hoverTarget ) {
4138 + return;
4139 + }
4140 +
4141 + const ctrlOrCmdKeyIsDown = e.ctrlKey || e.metaKey;
4142 + const shiftKeyIsDown = e.shiftKey;
4143 + const groupIsActive = hoverTarget.classList.contains( 'frm-selected-field-group' );
4144 + const $selectedFieldGroups = getSelectedFieldGroups();
4145 +
4146 + let numberOfSelectedGroups = $selectedFieldGroups.length;
4147 +
4148 + if ( ctrlOrCmdKeyIsDown || shiftKeyIsDown ) {
4149 + // multi-selecting
4150 +
4151 + const selectedField = getSelectedField();
4152 + if ( null !== selectedField && ! jQuery( selectedField ).siblings( 'li.form-field' ).length ) {
4153 + // count a selected field on its own as a selected field group when multiselecting.
4154 + selectedField.parentNode.classList.add( 'frm-selected-field-group' );
4155 + ++numberOfSelectedGroups;
4156 + }
4157 +
4158 + if ( ctrlOrCmdKeyIsDown ) {
4159 + if ( groupIsActive ) {
4160 + // unselect if holding ctrl or cmd and the group was already active.
4161 + --numberOfSelectedGroups;
4162 + hoverTarget.classList.remove( 'frm-selected-field-group' );
4163 + syncAfterMultiSelect( numberOfSelectedGroups );
4164 + return; // exit early to avoid adding back frm-selected-field-group
4165 + } else {
4166 + ++numberOfSelectedGroups;
4167 + }
4168 + } else if ( shiftKeyIsDown && ! groupIsActive ) {
4169 + ++numberOfSelectedGroups; // include the one we're selecting right now.
4170 + const $firstGroup = $selectedFieldGroups.first();
4171 +
4172 + let $range;
4173 + if ( $firstGroup.parent().index() < jQuery( hoverTarget.parentNode ).index() ) {
4174 + $range = $firstGroup.parent().nextUntil( hoverTarget.parentNode );
4175 + } else {
4176 + $range = $firstGroup.parent().prevUntil( hoverTarget.parentNode );
4177 + }
4178 +
4179 + $range.each(
4180 + function() {
4181 + var $fieldGroup = jQuery( this ).closest( 'li' ).find( 'ul.frm_sorting' );
4182 + if ( ! $fieldGroup.hasClass( 'frm-selected-field-group' ) ) {
4183 + ++numberOfSelectedGroups;
4184 + $fieldGroup.addClass( 'frm-selected-field-group' );
4185 + }
4186 + }
4187 + );
4188 +
4189 + // when holding shift and clicking, text gets selected. unselect it.
4190 + document.getSelection().removeAllRanges();
4191 + }
4192 + } else {
4193 + // not multi-selecting
4194 + unselectFieldGroups();
4195 + numberOfSelectedGroups = 1;
4196 + }
4197 +
4198 + hoverTarget.classList.add( 'frm-selected-field-group' );
4199 + syncAfterMultiSelect( numberOfSelectedGroups );
4200 +
4201 + jQuery( document ).off( 'click', unselectFieldGroups );
4202 + jQuery( document ).on( 'click', unselectFieldGroups );
4203 + }
4204 +
4205 + function getSelectedField() {
4206 + return document.getElementById( 'frm-show-fields' ).querySelector( 'li.form-field.selected' );
4207 + }
4208 +
4209 + function getSelectedFieldGroups() {
4210 + const $fieldGroups = jQuery( '.frm-selected-field-group' );
4211 + if ( $fieldGroups.length ) {
4212 + return $fieldGroups;
4213 + }
4214 +
4215 + const selectedField = getSelectedField();
4216 + if ( selectedField ) {
4217 + // If there is only one field in a group and the field is selected, consider the field's group as selected for multi-select.
4218 + const selectedFieldGroup = selectedField.closest( 'ul' );
4219 + if ( selectedFieldGroup && 1 === getFieldsInRow( jQuery( selectedFieldGroup ) ).length ) {
4220 + selectedFieldGroup.classList.add( 'frm-selected-field-group' );
4221 + return jQuery( selectedFieldGroup );
4222 + }
4223 + }
4224 +
4225 + return jQuery();
4226 + }
4227 +
4228 + function syncAfterMultiSelect( numberOfSelectedGroups ) {
4229 + clearSettingsBox( true ); // unselect any fields if one is selected.
4230 + if ( numberOfSelectedGroups >= 2 || ( 1 === numberOfSelectedGroups && selectedGroupHasMultipleFields() ) ) {
4231 + addFieldMultiselectPopup();
4232 + } else {
4233 + maybeRemoveMultiselectPopup();
4234 + }
4235 + maybeRemoveGroupHoverTarget();
4236 + }
4237 +
4238 + function selectedGroupHasMultipleFields() {
4239 + return getFieldsInRow( jQuery( document.querySelector( '.frm-selected-field-group' ) ) ).length > 1;
4240 + }
4241 +
4242 + function unselectFieldGroups( event ) {
4243 + if ( 'undefined' !== typeof event ) {
4244 + if ( null !== event.originalEvent.target.closest( '#frm-show-fields' ) ) {
4245 + return;
4246 + }
4247 + if ( event.originalEvent.target.classList.contains( 'frm-merge-fields-into-row' ) ) {
4248 + return;
4249 + }
4250 + if ( null !== event.originalEvent.target.closest( '.frm-merge-fields-into-row' ) ) {
4251 + return;
4252 + }
4253 + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) {
4254 + return;
4255 + }
4256 + if ( event.originalEvent.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) {
4257 + return;
4258 + }
4259 + }
4260 + jQuery( '.frm-selected-field-group' ).removeClass( 'frm-selected-field-group' );
4261 + jQuery( document ).off( 'click', unselectFieldGroups );
4262 + maybeRemoveMultiselectPopup();
4263 + }
4264 +
4265 + function maybeRemoveMultiselectPopup() {
4266 + var popup = document.getElementById( 'frm_field_multiselect_popup' );
4267 + if ( null !== popup ) {
4268 + popup.remove();
4269 + }
4270 + }
4271 +
4272 + function addFieldMultiselectPopup() {
4273 + getFieldMultiselectPopup();
4274 + }
4275 +
4276 + function getFieldMultiselectPopup() {
4277 + var popup, mergeOption, caret, verticalSeparator, deleteOption;
4278 +
4279 + popup = document.getElementById( 'frm_field_multiselect_popup' );
4280 +
4281 + if ( null !== popup ) {
4282 + popup.classList.toggle( 'frm-unmergable', ! selectedFieldsAreMergable() );
4283 + return popup;
4284 + }
4285 +
4286 + popup = div();
4287 + popup.id = 'frm_field_multiselect_popup';
4288 + if ( ! selectedFieldsAreMergable() ) {
4289 + popup.classList.add( 'frm-unmergable' );
4290 + }
4291 +
4292 + mergeOption = div();
4293 + mergeOption.classList.add( 'frm-merge-fields-into-row' );
4294 + mergeOption.textContent = __( 'Merge into row', 'formidable' );
4295 +
4296 + caret = document.createElement( 'a' );
4297 + caret.style.marginLeft = '5px';
4298 + caret.classList.add( 'frm_icon_font', 'frm_arrowdown6_icon' );
4299 + caret.setAttribute( 'href', '#' );
4300 + mergeOption.appendChild( caret );
4301 +
4302 + popup.appendChild( mergeOption );
4303 +
4304 + verticalSeparator = div();
4305 + verticalSeparator.classList.add( 'frm-multiselect-popup-separator' );
4306 + popup.appendChild( verticalSeparator );
4307 +
4308 + deleteOption = div();
4309 + deleteOption.classList.add( 'frm-delete-field-groups' );
4310 + deleteOption.appendChild( getIconClone( 'frm_trash_svg' ) );
4311 + popup.appendChild( deleteOption );
4312 +
4313 + document.getElementById( 'post-body-content' ).appendChild( popup );
4314 +
4315 + jQuery( popup ).hide().fadeIn();
4316 +
4317 + return popup;
4318 + }
4319 +
4320 + function selectedFieldsAreMergable() {
4321 + var selectedFieldGroups, totalFieldCount, length, index, fieldGroup;
4322 + selectedFieldGroups = document.querySelectorAll( '.frm-selected-field-group' );
4323 + length = selectedFieldGroups.length;
4324 + if ( 1 === length ) {
4325 + return false;
4326 + }
4327 + totalFieldCount = 0;
4328 + for ( index = 0; index < length; ++index ) {
4329 + fieldGroup = selectedFieldGroups[ index ];
4330 + if ( null !== fieldGroup.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ) ) {
4331 + return false;
4332 + }
4333 + totalFieldCount += getFieldsInRow( jQuery( fieldGroup ) ).length;
4334 + if ( totalFieldCount > 6 ) {
4335 + return false;
4336 + }
4337 + }
4338 + return true;
4339 + }
4340 +
4341 + function mergeFieldsIntoRowClick( event ) {
4342 + var size, popup;
4343 +
4344 + if ( null !== event.originalEvent.target.closest( '#frm_field_group_popup' ) ) {
4345 + // prevent clicks within the popup from triggering the button again.
4346 + return;
4347 + }
4348 +
4349 + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) {
4350 + // avoid switching back to the first page when clicking the custom option nested inside of the merge option.
4351 + return;
4352 + }
4353 +
4354 + size = getSelectedFieldCount();
4355 + popup = getFieldGroupPopup( size, document.querySelector( '.frm-selected-field-group' ).firstChild );
4356 + this.appendChild( popup );
4357 + }
4358 +
4359 + function getSelectedFieldCount() {
4360 + var count = 0;
4361 + jQuery( document.querySelectorAll( '.frm-selected-field-group' ) ).each(
4362 + function() {
4363 + count += getFieldsInRow( jQuery( this ) ).length;
4364 + }
4365 + );
4366 + return count;
4367 + }
4368 +
4369 + function deleteFieldGroupsClick() {
4370 + var fieldIdsToDelete, deleteOnConfirm, multiselectPopup;
4371 +
4372 + fieldIdsToDelete = getSelectedFieldIds();
4373 + deleteOnConfirm = getDeleteSelectedFieldGroupsOnConfirmFunction( fieldIdsToDelete );
4374 +
4375 + multiselectPopup = document.getElementById( 'frm_field_multiselect_popup' );
4376 + if ( null !== multiselectPopup ) {
4377 + multiselectPopup.remove();
4378 + }
4379 +
4380 + this.setAttribute( 'data-frmcaution', __( 'Heads up', 'formidable' ) );
4381 + /* translators: %1$s: Number of fields that are selected to be deleted. */
4382 + this.setAttribute( 'data-frmverify', __( 'Are you sure you want to delete these %1$s selected fields?', 'formidable' ).replace( '%1$s', fieldIdsToDelete.length ) );
4383 + confirmLinkClick( this );
4384 +
4385 + jQuery( '#frm-confirmed-click' ).on( 'click', deleteOnConfirm );
4386 + jQuery( '#frm_confirm_modal' ).one( 'dialogclose', function() {
4387 + jQuery( '#frm-confirmed-click' ).off( 'click', deleteOnConfirm );
4388 + });
4389 + }
4390 +
4391 + function getSelectedFieldIds() {
4392 + var deleteFieldIds = [];
4393 + jQuery( '.frm-selected-field-group > li.form-field' )
4394 + .each(
4395 + function() {
4396 + deleteFieldIds.push( this.dataset.fid );
4397 + }
4398 + );
4399 + return deleteFieldIds;
4400 + }
4401 +
4402 + function getDeleteSelectedFieldGroupsOnConfirmFunction( deleteFieldIds ) {
4403 + return function( event ) {
4404 + event.preventDefault();
4405 + deleteAllSelectedFieldGroups( deleteFieldIds );
4406 + };
4407 + }
4408 +
4409 + function deleteAllSelectedFieldGroups( deleteFieldIds ) {
4410 + deleteFieldIds.forEach(
4411 + function( fieldId ) {
4412 + deleteFields( fieldId );
4413 + }
4414 + );
4415 + }
4416 +
4417 + function deleteFieldConfirmed() {
4418 + /*jshint validthis:true */
4419 + deleteFields( this.getAttribute( 'data-deletefield' ) );
4420 + }
4421 +
4422 + function deleteFields( fieldId ) {
4423 + var field = jQuery( '#frm_field_id_' + fieldId );
4424 +
4425 + deleteField( fieldId );
4426 +
4427 + if ( field.hasClass( 'edit_field_type_divider' ) ) {
4428 + field.find( 'li.frm_field_box' ).each( function() {
4429 + //TODO: maybe delete only end section
4430 + //if(n.hasClass('edit_field_type_end_divider')){
4431 + deleteField( this.getAttribute( 'data-fid' ) );
4432 + //}
4433 + });
4434 + }
4435 + toggleSectionHolder();
4436 + }
4437 +
4438 + function deleteField( fieldId ) {
4439 + jQuery.ajax({
4440 + type: 'POST',
4441 + url: ajaxurl,
4442 + data: {
4443 + action: 'frm_delete_field',
4444 + field_id: fieldId,
4445 + nonce: frmGlobal.nonce
4446 + },
4447 + success: function() {
4448 + var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ),
4449 + settings = jQuery( '#frm-single-settings-' + fieldId );
4450 +
4451 + // Remove settings from sidebar.
4452 + if ( settings.is( ':visible' ) ) {
4453 + document.getElementById( 'frm_insert_fields_tab' ).click();
4454 + }
4455 + settings.remove();
4456 +
4457 + $thisField.fadeOut( 'slow', function() {
4458 + var $section = $thisField.closest( '.start_divider' ),
4459 + type = $thisField.data( 'type' ),
4460 + $adjacentFields = $thisField.siblings( 'li.form-field' ),
4461 + $liWrapper;
4462 +
4463 + if ( ! $adjacentFields.length ) {
4464 + if ( $thisField.is( '.edit_field_type_end_divider' ) ) {
4465 + $adjacentFields.length = $thisField.closest( 'li.form-field' ).siblings();
4466 + } else {
4467 + $liWrapper = $thisField.closest( 'ul.frm_sorting' ).parent();
4468 + }
4469 + }
4470 +
4471 + $thisField.remove();
4472 + if ( type === 'break' ) {
4473 + renumberPageBreaks();
4474 + }
4475 + if ( type === 'product' ) {
4476 + maybeHideQuantityProductFieldOption();
4477 + // a product field attached to a quantity field earlier might be the one deleted, so re-populate
4478 + popAllProductFields();
4479 + }
4480 + if ( jQuery( '#frm-show-fields li' ).length === 0 ) {
4481 + document.getElementById( 'frm_form_editor_container' ).classList.remove( 'frm-has-fields' );
4482 + } else if ( $section.length ) {
4483 + toggleOneSectionHolder( $section );
4484 + }
4485 + if ( $adjacentFields.length ) {
4486 + syncLayoutClasses( $adjacentFields.first() );
4487 + } else {
4488 + $liWrapper.remove();
4489 + }
4490 +
4491 + // prevent "More Options" tooltips from staying around after their target field is deleted.
4492 + deleteTooltips();
4493 + });
4494 + }
4495 + });
4496 + }
4497 +
4498 + function addFieldLogicRow() {
4499 + /*jshint validthis:true */
4500 + var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
4501 + formId = thisFormId,
4502 + logicRows = document.getElementById( 'frm_logic_row_' + id ).querySelectorAll( '.frm_logic_row' );
4503 + jQuery.ajax({
4504 + type: 'POST',
4505 + url: ajaxurl,
4506 + data: {
4507 + action: 'frm_add_logic_row',
4508 + form_id: formId,
4509 + field_id: id,
4510 + nonce: frmGlobal.nonce,
4511 + meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ),
4512 + fields: getFieldList()
4513 + },
4514 + success: function( html ) {
4515 + jQuery( document.getElementById( 'logic_' + id ) ).fadeOut( 'slow', function() {
4516 + var logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) );
4517 + logicRow.append( html );
4518 + logicRow.closest( '.frm_logic_rows' ).fadeIn( 'slow' );
4519 + });
4520 + }
4521 + });
4522 + return false;
4523 + }
4524 +
4525 + function getNewRowId( rows, replace, defaultValue ) {
4526 + if ( ! rows.length ) {
4527 + return 'undefined' !== typeof defaultValue ? defaultValue : 0;
4528 + }
4529 + return parseInt( rows[ rows.length - 1 ].id.replace( replace, '' ), 10 ) + 1;
4530 + }
4531 +
4532 + function addWatchLookupRow() {
4533 + /*jshint validthis:true */
4534 + var lastRowId,
4535 + id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
4536 + formId = thisFormId,
4537 + lookupBlockRows = document.getElementById( 'frm_watch_lookup_block_' + id ).children;
4538 + jQuery.ajax({
4539 + type: 'POST',
4540 + url: ajaxurl,
4541 + data: {
4542 + action: 'frm_add_watch_lookup_row',
4543 + form_id: formId,
4544 + field_id: id,
4545 + row_key: getNewRowId( lookupBlockRows, 'frm_watch_lookup_' + id + '_' ),
4546 + nonce: frmGlobal.nonce
4547 + },
4548 + success: function( newRow ) {
4549 + var watchRowBlock = jQuery( document.getElementById( 'frm_watch_lookup_block_' + id ) );
4550 + watchRowBlock.append( newRow );
4551 + watchRowBlock.fadeIn( 'slow' );
4552 + }
4553 + });
4554 + return false;
4555 + }
4556 +
4557 + function resetOptionTextDetails() {
4558 + jQuery( '.frm-single-settings ul input[type="text"][name^="field_options[options_"]' ).filter( '[data-value-on-load]' ).removeAttr( 'data-value-on-load' );
4559 + jQuery( 'input[type="hidden"][name^=optionmap]' ).remove();
4560 + }
4561 +
4562 + function optionTextAlreadyExists( input ) {
4563 + var fieldId = jQuery( input ).closest( '.frm-single-settings' ).attr( 'data-fid' ),
4564 + optionInputs = jQuery( input ).closest( 'ul' ).get( 0 ).querySelectorAll( '.field_' + fieldId + '_option' ),
4565 + index,
4566 + optionInput;
4567 +
4568 + for ( index in optionInputs ) {
4569 + optionInput = optionInputs[ index ];
4570 + if ( optionInput.id !== input.id && optionInput.value === input.value && optionInput.getAttribute( 'data-duplicate' ) !== 'true' ) {
4571 + return true;
4572 + }
4573 + }
4574 +
4575 + return false;
4576 + }
4577 +
4578 + function onOptionTextFocus() {
4579 + var input,
4580 + fieldId;
4581 +
4582 + if ( this.getAttribute( 'data-value-on-load' ) === null ) {
4583 + this.setAttribute( 'data-value-on-load', this.value );
4584 +
4585 + fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' );
4586 + input = document.createElement( 'input' );
4587 + input.value = this.value;
4588 + input.setAttribute( 'type', 'hidden' );
4589 + input.setAttribute( 'name', 'optionmap[' + fieldId + '][' + this.value + ']' );
4590 + this.parentNode.appendChild( input );
4591 +
4592 + if ( typeof optionMap[ fieldId ] === 'undefined' ) {
4593 + optionMap[ fieldId ] = {};
4594 + }
4595 +
4596 + optionMap[ fieldId ][ this.value ] = input;
4597 + }
4598 +
4599 + if ( this.getAttribute( 'data-duplicate' ) === 'true' ) {
4600 + this.removeAttribute( 'data-duplicate' );
4601 +
4602 + // we want to use original value if actually still a duplicate
4603 + if ( optionTextAlreadyExists( this ) ) {
4604 + this.setAttribute( 'data-value-on-focus', this.getAttribute( 'data-value-on-load' ) );
4605 + return;
4606 + }
4607 + }
4608 +
4609 + if ( '' !== this.value || frm_admin_js.new_option !== this.getAttribute( 'data-value-on-focus' ) ) {
4610 + this.setAttribute( 'data-value-on-focus', this.value );
4611 + }
4612 + }
4613 +
4614 + function onOptionTextBlur() {
4615 + var originalValue,
4616 + oldValue = this.getAttribute( 'data-value-on-focus' ),
4617 + newValue = this.value,
4618 + fieldId,
4619 + fieldIndex,
4620 + logicId,
4621 + row,
4622 + rowLength,
4623 + rowIndex,
4624 + valueSelect,
4625 + opts,
4626 + fieldIds,
4627 + settingId,
4628 + setting,
4629 + optionMatches,
4630 + option;
4631 +
4632 + if ( oldValue === newValue ) {
4633 + return;
4634 + }
4635 +
4636 + fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' );
4637 + originalValue = this.getAttribute( 'data-value-on-load' );
4638 +
4639 + // check if the newValue is already mapped to another option
4640 + // if it is, mark as duplicate and return
4641 + if ( optionTextAlreadyExists( this ) ) {
4642 + this.setAttribute( 'data-duplicate', 'true' );
4643 +
4644 + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) {
4645 + // unmap any other change that may have happened before instead of changing it to something unused
4646 + optionMap[ fieldId ][ originalValue ].value = originalValue;
4647 + }
4648 +
4649 + return;
4650 + }
4651 +
4652 + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) {
4653 + optionMap[ fieldId ][ originalValue ].value = newValue;
4654 + }
4655 +
4656 + fieldIds = [];
4657 + rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' );
4658 + rowLength = rows.length;
4659 + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) {
4660 + row = rows[ rowIndex ];
4661 + opts = row.querySelector( '.frm_logic_field_opts' );
4662 +
4663 + if ( opts.value !== fieldId ) {
4664 + continue;
4665 + }
4666 +
4667 + logicId = row.id.split( '_' )[ 2 ];
4668 + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' );
4669 +
4670 + if ( '' === oldValue ) {
4671 + optionMatches = [];
4672 + } else {
4673 + optionMatches = valueSelect.querySelectorAll( 'option[value="' + oldValue + '"]' );
4674 + }
4675 +
4676 + if ( ! optionMatches.length ) {
4677 + optionMatches = valueSelect.querySelectorAll( 'option[value="' + newValue + '"]' );
4678 +
4679 + if ( ! optionMatches.length ) {
4680 + option = document.createElement( 'option' );
4681 + valueSelect.appendChild( option );
4682 + }
4683 + }
4684 +
4685 + if ( optionMatches.length ) {
4686 + option = optionMatches[ optionMatches.length - 1 ];
4687 + }
4688 +
4689 + option.setAttribute( 'value', newValue );
4690 + option.textContent = newValue;
4691 +
4692 + if ( fieldIds.indexOf( logicId ) === -1 ) {
4693 + fieldIds.push( logicId );
4694 + }
4695 + }
4696 +
4697 + for ( fieldIndex in fieldIds ) {
4698 + settingId = fieldIds[ fieldIndex ];
4699 + setting = document.getElementById( 'frm-single-settings-' + settingId );
4700 + moveFieldSettings( setting );
4701 + }
4702 + }
4703 +
4704 + function updateGetValueFieldSelection() {
4705 + /*jshint validthis:true */
4706 + var fieldID = this.id.replace( 'get_values_form_', '' );
4707 + var fieldSelect = document.getElementById( 'get_values_field_' + fieldID );
4708 + var fieldType = this.getAttribute( 'data-fieldtype' );
4709 +
4710 + if ( this.value === '' ) {
4711 + fieldSelect.options.length = 1;
4712 + } else {
4713 + var formID = this.value;
4714 + jQuery.ajax({
4715 + type: 'POST', url: ajaxurl,
4716 + data: {
4717 + action: 'frm_get_options_for_get_values_field',
4718 + form_id: formID,
4719 + field_type: fieldType,
4720 + nonce: frmGlobal.nonce
4721 + },
4722 + success: function( fields ) {
4723 + fieldSelect.innerHTML = fields;
4724 + }
4725 + });
4726 + }
4727 + }
4728 +
4729 + // Clear the Watch Fields option when Lookup field switches to "Text" option
4730 + function maybeClearWatchFields() {
4731 + /*jshint validthis:true */
4732 + var link, lookupBlock,
4733 + fieldID = this.name.replace( 'field_options[data_type_', '' ).replace( ']', '' );
4734 +
4735 + link = document.getElementById( 'frm_add_watch_lookup_link_' + fieldID ).parentNode;
4736 +
4737 + if ( this.value === 'text' ) {
4738 + lookupBlock = document.getElementById( 'frm_watch_lookup_block_' + fieldID );
4739 + if ( lookupBlock !== null ) {
4740 + // Clear and hide the Watch Fields option
4741 + lookupBlock.innerHTML = '';
4742 + link.classList.add( 'frm_hidden' );
4743 +
4744 + // Hide the Watch Fields row
4745 + link.previousElementSibling.style.display = 'none';
4746 + link.previousElementSibling.previousElementSibling.style.display = 'none';
4747 + link.previousElementSibling.previousElementSibling.previousElementSibling.style.display = 'none';
4748 + }
4749 + } else {
4750 + // Show the Watch Fields option
4751 + link.classList.remove( 'frm_hidden' );
4752 + }
4753 +
4754 + toggleMultiSelect( fieldID, this.value );
4755 + }
4756 +
4757 + // Number the pages and hide/show the first page as needed.
4758 + function renumberPageBreaks() {
4759 + var i, containerClass,
4760 + pages = document.getElementsByClassName( 'frm-page-num' );
4761 +
4762 + if ( pages.length > 1 ) {
4763 + document.getElementById( 'frm-fake-page' ).style.display = 'block';
4764 + for ( i = 0; i < pages.length; i++ ) {
4765 + containerClass = pages[i].parentNode.parentNode.parentNode.classList;
4766 + if ( i === 1 ) {
4767 + // Hide previous button on page 1
4768 + containerClass.add( 'frm-first-page' );
4769 + } else {
4770 + containerClass.remove( 'frm-first-page' );
4771 + }
4772 + pages[i].innerHTML = ( i + 1 );
4773 + }
4774 + } else {
4775 + document.getElementById( 'frm-fake-page' ).style.display = 'none';
4776 + }
4777 + }
4778 +
4779 + // The fake field works differently than real fields.
4780 + function maybeCollapsePage() {
4781 + /*jshint validthis:true */
4782 + var field = jQuery( this ).closest( '.frm_field_box[data-ftype=break]' );
4783 + if ( field.length ) {
4784 + toggleCollapsePage( field );
4785 + } else {
4786 + toggleCollapseFakePage();
4787 + }
4788 + }
4789 +
4790 + // Find all fields in a page and hide/show them
4791 + function toggleCollapsePage( field ) {
4792 + var toCollapse = getAllFieldsForPage( field.get( 0 ).parentNode.closest( 'li.frm_field_box' ).nextElementSibling );
4793 + togglePage( field, toCollapse );
4794 + }
4795 +
4796 + function toggleCollapseFakePage() {
4797 + var topLevel = document.getElementById( 'frm-fake-page' ),
4798 + firstField = document.getElementById( 'frm-show-fields' ).firstElementChild,
4799 + toCollapse = getAllFieldsForPage( firstField );
4800 +
4801 + if ( firstField.getAttribute( 'data-ftype' ) === 'break' ) {
4802 + // Don't collapse if the first field is a page break.
4803 + return;
4804 + }
4805 +
4806 + togglePage( jQuery( topLevel ), toCollapse );
4807 + }
4808 +
4809 + function getAllFieldsForPage( firstWrapper ) {
4810 + var $fieldsForPage, currentWrapper;
4811 +
4812 + $fieldsForPage = jQuery();
4813 +
4814 + if ( null === firstWrapper ) {
4815 + return $fieldsForPage;
4816 + }
4817 +
4818 + currentWrapper = firstWrapper;
4819 +
4820 + do {
4821 + if ( null !== currentWrapper.querySelector( '.edit_field_type_break' ) ) {
4822 + break;
4823 + }
4824 + $fieldsForPage = $fieldsForPage.add( jQuery( currentWrapper ) );
4825 + currentWrapper = currentWrapper.nextElementSibling;
4826 + } while ( null !== currentWrapper );
4827 +
4828 + return $fieldsForPage;
4829 + }
4830 +
4831 + function togglePage( field, toCollapse ) {
4832 + var i,
4833 + fieldCount = toCollapse.length,
4834 + slide = Math.min( fieldCount, 3 );
4835 +
4836 + if ( field.hasClass( 'frm-page-collapsed' ) ) {
4837 + field.removeClass( 'frm-page-collapsed' );
4838 + toCollapse.removeClass( 'frm-is-collapsed' );
4839 + for ( i = 0; i < slide; i++ ) {
4840 + if ( i === slide - 1 ) {
4841 + jQuery( toCollapse[ i ]).slideDown( 150, function() {
4842 + toCollapse.show();
4843 + });
4844 + } else {
4845 + jQuery( toCollapse[ i ]).slideDown( 150 );
4846 + }
4847 + }
4848 + } else {
4849 + field.addClass( 'frm-page-collapsed' );
4850 + toCollapse.addClass( 'frm-is-collapsed' );
4851 + for ( i = 0; i < slide; i++ ) {
4852 + if ( i === slide - 1 ) {
4853 + jQuery( toCollapse[ i ]).slideUp( 150, function() {
4854 + toCollapse.css( 'cssText', 'display:none !important;' );
4855 + });
4856 + } else {
4857 + jQuery( toCollapse[ i ]).slideUp( 150 );
4858 + }
4859 + }
4860 + }
4861 + }
4862 +
4863 + function maybeCollapseSection() {
4864 + /*jshint validthis:true */
4865 + var parentCont = this.parentNode.parentNode.parentNode.parentNode;
4866 +
4867 + parentCont.classList.toggle( 'frm-section-collapsed' );
4868 + }
4869 +
4870 + function maybeCollapseSettings() {
4871 + /*jshint validthis:true */
4872 + this.classList.toggle( 'frm-collapsed' );
4873 + }
4874 +
4875 + function clickLabel() {
4876 + if ( ! this.id ) {
4877 + return;
4878 + }
4879 +
4880 + /*jshint validthis:true */
4881 + var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0],
4882 + fieldId = this.id.replace( 'field_label_', '' ),
4883 + fieldType = document.getElementById( 'field_options_type_' + fieldId ),
4884 + fieldTypeName = fieldType.value;
4885 +
4886 + if ( typeof setting !== 'undefined' ) {
4887 + if ( fieldType.tagName === 'SELECT' ) {
4888 + fieldTypeName = fieldType.options[ fieldType.selectedIndex ].text.toLowerCase();
4889 + } else {
4890 + fieldTypeName = fieldTypeName.replace( '_', ' ' );
4891 + }
4892 +
4893 + fieldTypeName = normalizeFieldName( fieldTypeName );
4894 +
4895 + setTimeout( function() {
4896 + if ( setting.value.toLowerCase() === fieldTypeName ) {
4897 + setting.select();
4898 + } else {
4899 + setting.focus();
4900 + }
4901 + }, 50 );
4902 + }
4903 + }
4904 +
4905 + function clickDescription() {
4906 + /*jshint validthis:true */
4907 + var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0];
4908 + if ( typeof setting !== 'undefined' ) {
4909 + setTimeout( function() {
4910 + setting.focus();
4911 + autoExpandSettings( setting );
4912 + }, 50 );
4913 + }
4914 + }
4915 +
4916 + function autoExpandSettings( setting ) {
4917 + var inSection = setting.closest( '.frm-collapse-me' );
4918 + if ( inSection !== null ) {
4919 + inSection.previousElementSibling.classList.remove( 'frm-collapsed' );
4920 + }
4921 + }
4922 +
4923 + function normalizeFieldName( fieldTypeName ) {
4924 + if ( fieldTypeName === 'divider' ) {
4925 + fieldTypeName = 'section';
4926 + } else if ( fieldTypeName === 'range' ) {
4927 + fieldTypeName = 'slider';
4928 + } else if ( fieldTypeName === 'data' ) {
4929 + fieldTypeName = 'dynamic';
4930 + } else if ( fieldTypeName === 'form' ) {
4931 + fieldTypeName = 'embed form';
4932 + }
4933 + return fieldTypeName;
4934 + }
4935 +
4936 + function clickVis( e ) {
4937 + /*jshint validthis:true */
4938 + var currentClass, originalList;
4939 +
4940 + currentClass = e.target.classList;
4941 +
4942 + if ( currentClass.contains( 'frm-collapse-page' ) || currentClass.contains( 'frm-sub-label' ) || e.target.closest( '.dropdown' ) !== null ) {
4943 + return;
4944 + }
4945 +
4946 + if ( this.closest( '.start_divider' ) !== null ) {
4947 + e.stopPropagation();
4948 + }
4949 +
4950 + if ( this.classList.contains( 'edit_field_type_divider' ) ) {
4951 + originalList = e.originalEvent.target.closest( 'ul.frm_sorting' );
4952 + if ( null !== originalList ) {
4953 + // prevent section click if clicking a field group within a section.
4954 + if ( originalList.classList.contains( 'edit_field_type_divider' ) || originalList.parentNode.parentNode.classList.contains( 'start_divider' ) ) {
4955 + return;
4956 + }
4957 + }
4958 + }
4959 +
4960 + clickAction( this );
4961 + }
4962 +
4963 + /**
4964 + * Open Advanced settings on double click.
4965 + */
4966 + function openAdvanced() {
4967 + var fieldId = this.getAttribute( 'data-fid' );
4968 + autoExpandSettings( document.getElementById( 'field_options_field_key_' + fieldId ) );
4969 + }
4970 +
4971 + function toggleRepeatButtons() {
4972 + /*jshint validthis:true */
4973 + var $thisField = jQuery( this ).closest( '.frm_field_box' );
4974 + $thisField.find( '.repeat_icon_links' ).removeClass( 'repeat_format repeat_formatboth repeat_formattext' ).addClass( 'repeat_format' + this.value );
4975 + if ( this.value === 'text' || this.value === 'both' ) {
4976 + $thisField.find( '.frm_repeat_text' ).show();
4977 + $thisField.find( '.repeat_icon_links a' ).addClass( 'frm_button' );
4978 + } else {
4979 + $thisField.find( '.frm_repeat_text' ).hide();
4980 + $thisField.find( '.repeat_icon_links a' ).removeClass( 'frm_button' );
4981 + }
4982 + }
4983 +
4984 + function checkRepeatLimit() {
4985 + /*jshint validthis:true */
4986 + var val = this.value;
4987 + if ( val !== '' && ( val < 2 || val > 200 ) ) {
4988 + infoModal( frm_admin_js.repeat_limit_min );
4989 + this.value = '';
4990 + }
4991 + }
4992 +
4993 + function checkCheckboxSelectionsLimit() {
4994 + /*jshint validthis:true */
4995 + var val = this.value;
4996 + if ( val !== '' && ( val < 1 || val > 200 ) ) {
4997 + infoModal( frm_admin_js.checkbox_limit );
4998 + this.value = '';
4999 + }
5000 + }
5001 +
5002 + function updateRepeatText( obj, addRemove ) {
5003 + var $thisField = jQuery( obj ).closest( '.frm_field_box' );
5004 + $thisField.find( '.frm_' + addRemove + '_form_row .frm_repeat_label' ).text( obj.value );
5005 + }
5006 +
5007 + function fieldsInSection( id ) {
5008 + var children = [];
5009 + jQuery( document.getElementById( 'frm_field_id_' + id ) ).find( 'li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)' ).each( function() {
5010 + children.push( jQuery( this ).data( 'fid' ) );
5011 + });
5012 + return children;
5013 + }
5014 +
5015 + function toggleFormTax() {
5016 + /*jshint validthis:true */
5017 + var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
5018 + var val = this.value;
5019 + var $showFields = document.getElementById( 'frm_show_selected_fields_' + id );
5020 + var $showForms = document.getElementById( 'frm_show_selected_forms_' + id );
5021 +
5022 + jQuery( $showForms ).find( 'select' ).val( '' );
5023 + if ( val === 'form' ) {
5024 + $showForms.style.display = 'inline';
5025 + empty( $showFields );
5026 + } else {
5027 + $showFields.style.display = 'none';
5028 + $showForms.style.display = 'none';
5029 + getTaxOrFieldSelection( val, id );
5030 + }
5031 +
5032 + }
5033 +
5034 + function resetOptOnChange() {
5035 + /*jshint validthis:true */
5036 + var field, thisOpt;
5037 +
5038 + field = getFieldKeyFromOpt( this );
5039 + if ( ! field ) {
5040 + return;
5041 + }
5042 +
5043 + thisOpt = jQuery( this ).closest( '.frm_single_option' );
5044 +
5045 + resetSingleOpt( field.fieldId, field.fieldKey, thisOpt );
5046 + }
5047 +
5048 + function getFieldKeyFromOpt( object ) {
5049 + var allOpts, fieldId, fieldKey;
5050 +
5051 + allOpts = jQuery( object ).closest( '.frm_sortable_field_opts' );
5052 + if ( ! allOpts.length ) {
5053 + return false;
5054 + }
5055 +
5056 + fieldId = allOpts.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_opts', '' );
5057 + fieldKey = allOpts.data( 'key' );
5058 +
5059 + return {
5060 + fieldId: fieldId,
5061 + fieldKey: fieldKey
5062 + };
5063 + }
5064 +
5065 + function resetSingleOpt( fieldId, fieldKey, thisOpt ) {
5066 + var saved, text, defaultVal, previewInput, labelForDisplay, optContainer,
5067 + optKey = thisOpt.data( 'optkey' ),
5068 + separateValues = usingSeparateValues( fieldId ),
5069 + single = jQuery( 'label[for="field_' + fieldKey + '-' + optKey + '"]' ),
5070 + baseName = 'field_options[options_' + fieldId + '][' + optKey + ']',
5071 + label = jQuery( 'input[name="' + baseName + '[label]"]' );
5072 +
5073 + if ( single.length < 1 ) {
5074 + resetDisplayedOpts( fieldId );
5075 +
5076 + // Set the default value.
5077 + defaultVal = thisOpt.find( 'input[name^="default_value_"]' );
5078 + if ( defaultVal.is( ':checked' ) && label.length > 0 ) {
5079 + jQuery( 'select[name^="item_meta[' + fieldId + ']"]' ).val( label.val() );
5080 + }
5081 + return;
5082 + }
5083 +
5084 + previewInput = single.children( 'input' );
5085 +
5086 + if ( label.length < 1 ) {
5087 + // Check for other label.
5088 + label = jQuery( 'input[name="' + baseName + '"]' );
5089 + saved = label.val();
5090 + } else if ( separateValues ) {
5091 + saved = jQuery( 'input[name="' + baseName + '[value]"]' ).val();
5092 + } else {
5093 + saved = label.val();
5094 + }
5095 +
5096 + if ( label.length < 1 ) {
5097 + return;
5098 + }
5099 +
5100 + // Set the displayed value.
5101 + text = single[0].childNodes;
5102 +
5103 + if ( imagesAsOptions( fieldId ) ) {
5104 + labelForDisplay = getImageDisplayValue( thisOpt, fieldId, label );
5105 + optContainer = single.find( '.frm_image_option_container' );
5106 +
5107 + if ( optContainer.length > 0 ) {
5108 + optContainer.replaceWith( labelForDisplay );
5109 + } else {
5110 + text[ text.length - 1 ].nodeValue = '';
5111 + single.append( labelForDisplay );
5112 + }
5113 + } else {
5114 + text[ text.length - 1 ].nodeValue = ' ' + label.val();
5115 + }
5116 +
5117 + // Set saved value.
5118 + previewInput.val( saved );
5119 +
5120 + // Set the default value.
5121 + defaultVal = thisOpt.find( 'input[name^="default_value_"]' );
5122 + previewInput.prop( 'checked', defaultVal.is( ':checked' ) ? true : false );
5123 + }
5124 +
5125 + /**
5126 + * Set the displayed value for an image option.
5127 + */
5128 + function getImageDisplayValue( thisOpt, fieldId, label ) {
5129 + var image, imageUrl, showLabelWithImage, fieldType;
5130 +
5131 + image = thisOpt.find( 'img' );
5132 + if ( image ) {
5133 + imageUrl = image.attr( 'src' );
5134 + }
5135 +
5136 + showLabelWithImage = showingLabelWithImage( fieldId );
5137 + fieldType = radioOrCheckbox( fieldId );
5138 + return getImageLabel( label.val(), showLabelWithImage, imageUrl, fieldType );
5139 + }
5140 +
5141 + function getImageOptionSize( fieldId ) {
5142 + var val,
5143 + field = document.getElementById( 'field_options_image_size_' + fieldId ),
5144 + size = '';
5145 +
5146 + if ( field !== null ) {
5147 + val = field.value;
5148 + if ( val !== '' ) {
5149 + size = val;
5150 + }
5151 + }
5152 +
5153 + return size;
5154 + }
5155 +
5156 + function resetDisplayedOpts( fieldId ) {
5157 + var i, opts, type, placeholder, fieldInfo,
5158 + input = jQuery( '[name^="item_meta[' + fieldId + ']"]' );
5159 +
5160 + if ( input.length < 1 ) {
5161 + return;
5162 + }
5163 +
5164 + if ( input.is( 'select' ) ) {
5165 + placeholder = document.getElementById( 'frm_placeholder_' + fieldId );
5166 + if ( placeholder !== null && placeholder.value === '' ) {
5167 + fillDropdownOpts( input[0], { sourceID: fieldId });
5168 + } else {
5169 + fillDropdownOpts( input[0], {
5170 + sourceID: fieldId,
5171 + placeholder: placeholder.value
5172 + });
5173 + }
5174 + } else {
5175 + opts = getMultipleOpts( fieldId );
5176 + type = input.attr( 'type' );
5177 + jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ).html( '' );
5178 + fieldInfo = getFieldKeyFromOpt( jQuery( '#frm_delete_field_' + fieldId + '-000_container' ) );
5179 +
5180 + var container = jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ),
5181 + hasImageOptions = imagesAsOptions( fieldId ),
5182 + imageSize = hasImageOptions ? getImageOptionSize( fieldId ) : '',
5183 + imageOptionClass = hasImageOptions ? ( 'frm_image_option frm_image_' + imageSize + ' ' ) : '',
5184 + isProduct = isProductField( fieldId );
5185 +
5186 + for ( i = 0; i < opts.length; i++ ) {
5187 + container.append( addRadioCheckboxOpt( type, opts[ i ], fieldId, fieldInfo.fieldKey, isProduct, imageOptionClass ) );
5188 + }
5189 + }
5190 +
5191 + adjustConditionalLogicOptionOrders( fieldId );
5192 + }
5193 +
5194 + function adjustConditionalLogicOptionOrders( fieldId ) {
5195 + var row, opts, logicId, valueSelect, rowOptions, expectedOrder, optionLength, optionIndex, expectedOption, optionMatch,
5196 + rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ),
5197 + rowLength = rows.length,
5198 + fieldOptions = getFieldOptions( fieldId ),
5199 + optionLength = fieldOptions.length;
5200 +
5201 + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) {
5202 + row = rows[ rowIndex ];
5203 + opts = row.querySelector( '.frm_logic_field_opts' );
5204 +
5205 + if ( opts.value != fieldId ) {
5206 + continue;
5207 + }
5208 +
5209 + logicId = row.id.split( '_' )[ 2 ];
5210 + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' );
5211 +
5212 + for ( optionIndex = optionLength - 1; optionIndex >= 0; optionIndex-- ) {
5213 + expectedOption = fieldOptions[ optionIndex ];
5214 + optionMatch = valueSelect.querySelector( 'option[value="' + expectedOption + '"]' );
5215 +
5216 + if ( optionMatch === null ) {
5217 + optionMatch = document.createElement( 'option' );
5218 + optionMatch.setAttribute( 'value', expectedOption );
5219 + optionMatch.textContent = expectedOption;
5220 + }
5221 +
5222 + valueSelect.prepend( optionMatch );
5223 + }
5224 +
5225 + optionMatch = valueSelect.querySelector( 'option[value=""]' );
5226 + if ( optionMatch !== null ) {
5227 + valueSelect.prepend( optionMatch );
5228 + }
5229 + }
5230 + }
5231 +
5232 + function getFieldOptions( fieldId ) {
5233 + var index, input, li,
5234 + listItems = document.getElementById( 'frm_field_' + fieldId + '_opts' ).querySelectorAll( '.frm_single_option' ),
5235 + options = [],
5236 + length = listItems.length;
5237 + for ( index = 0; index < length; index++ ) {
5238 + li = listItems[ index ];
5239 +
5240 + if ( li.classList.contains( 'frm_hidden' ) ) {
5241 + continue;
5242 + }
5243 +
5244 + input = li.querySelector( '.field_' + fieldId + '_option' );
5245 + options.push( input.value );
5246 + }
5247 + return options;
5248 + }
5249 +
5250 + function addRadioCheckboxOpt( type, opt, fieldId, fieldKey, isProduct, classes ) {
5251 + var other, single,
5252 + isOther = opt.key.indexOf( 'other' ) !== -1,
5253 +
5254 + id = 'field_' + fieldKey + '-' + opt.key;
5255 +
5256 + 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="" />';
5257 +
5258 + single = '<div class="frm_' + type + ' ' + type + ' ' + classes + '" id="frm_' + type + '_' + fieldId + '-' + opt.key + '"><label for="' + id +
5259 + '"><input type="' + type +
5260 + '" name="item_meta[' + fieldId + ']' + ( type === 'checkbox' ? '[]' : '' ) +
5261 + '" value="' + opt.saved + '" id="' + id + '"' + ( isProduct ? ' data-price="' + opt.price + '"' : '' ) + ( opt.checked ? ' checked="checked"' : '' ) + '> ' + opt.label + '</label>' +
5262 + ( isOther ? other : '' ) +
5263 + '</div>';
5264 +
5265 + return single;
5266 + }
5267 +
5268 + function fillDropdownOpts( field, atts ) {
5269 + if ( field === null ) {
5270 + return;
5271 + }
5272 + var sourceID = atts.sourceID,
5273 + placeholder = atts.placeholder,
5274 + isProduct = isProductField( sourceID ),
5275 + showOther = atts.other;
5276 +
5277 + removeDropdownOpts( field );
5278 + var opts = getMultipleOpts( sourceID ),
5279 + hasPlaceholder = ( typeof placeholder !== 'undefined' );
5280 +
5281 + for ( var i = 0; i < opts.length; i++ ) {
5282 + var label = opts[ i ].label,
5283 + isOther = opts[ i ].key.indexOf( 'other' ) !== -1;
5284 +
5285 + if ( hasPlaceholder && label !== '' ) {
5286 + addBlankSelectOption( field, placeholder );
5287 + } else if ( hasPlaceholder ) {
5288 + label = placeholder;
5289 + }
5290 + hasPlaceholder = false;
5291 +
5292 + if ( ! isOther || showOther ) {
5293 + var opt = document.createElement( 'option' );
5294 + opt.value = opts[ i ].saved;
5295 + opt.innerHTML = label;
5296 +
5297 + if ( isProduct ) {
5298 + opt.setAttribute( 'data-price', opts[ i ].price );
5299 + }
5300 +
5301 + field.appendChild( opt );
5302 + }
5303 + }
5304 + }
5305 +
5306 + function addBlankSelectOption( field, placeholder ) {
5307 + var opt = document.createElement( 'option' ),
5308 + firstChild = field.firstChild;
5309 +
5310 + opt.value = '';
5311 + opt.innerHTML = placeholder;
5312 + if ( firstChild !== null ) {
5313 + field.insertBefore( opt, firstChild );
5314 + field.selectedIndex = 0;
5315 + } else {
5316 + field.appendChild( opt );
5317 + }
5318 + }
5319 +
5320 + function getMultipleOpts( fieldId ) {
5321 + var i, saved, labelName, label, key, optObj,
5322 + image, savedLabel, input, field, checkbox, fieldType,
5323 + checked = false,
5324 + opts = [],
5325 + imageUrl = '',
5326 +
5327 + optVals = jQuery( 'input[name^="field_options[options_' + fieldId + ']"]' ),
5328 + separateValues = usingSeparateValues( fieldId ),
5329 + hasImageOptions = imagesAsOptions( fieldId ),
5330 + showLabelWithImage = showingLabelWithImage( fieldId ),
5331 + isProduct = isProductField( fieldId );
5332 +
5333 + for ( i = 0; i < optVals.length; i++ ) {
5334 + 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 ) {
5335 + continue;
5336 + }
5337 + saved = optVals[ i ].value;
5338 + label = saved;
5339 + key = optVals[ i ].name.replace( 'field_options[options_' + fieldId + '][', '' ).replace( '[label]', '' ).replace( ']', '' );
5340 +
5341 + if ( separateValues ) {
5342 + labelName = optVals[ i ].name.replace( '[label]', '[value]' );
5343 + saved = jQuery( 'input[name="' + labelName + '"]' ).val();
5344 + }
5345 +
5346 + if ( hasImageOptions ) {
5347 + imageUrl = getImageUrlFromInput( optVals[i]);
5348 + fieldType = radioOrCheckbox( fieldId );
5349 + label = getImageLabel( label, showLabelWithImage, imageUrl, fieldType );
5350 + }
5351 +
5352 + /**
5353 + * @since 5.0.04
5354 + */
5355 + label = frmAdminBuild.hooks.applyFilters( 'frm_choice_field_label', label, fieldId, optVals[ i ], hasImageOptions );
5356 +
5357 + checked = getChecked( optVals[ i ].id );
5358 +
5359 + optObj = {
5360 + saved: saved,
5361 + label: label,
5362 + checked: checked,
5363 + key: key
5364 + };
5365 +
5366 + if ( isProduct ) {
5367 + labelName = optVals[ i ].name.replace( '[label]', '[price]' );
5368 + optObj.price = jQuery( 'input[name="' + labelName + '"]' ).val();
5369 + }
5370 +
5371 + opts.push( optObj );
5372 + }
5373 +
5374 + return opts;
5375 + }
5376 +
5377 + function radioOrCheckbox( fieldId ) {
5378 + var settings = document.getElementById( 'frm-single-settings-' + fieldId );
5379 + if ( settings === null ) {
5380 + return 'radio';
5381 + }
5382 +
5383 + return settings.classList.contains( 'frm-type-checkbox' ) ? 'checkbox' : 'radio';
5384 + }
5385 +
5386 + function getImageUrlFromInput( optVal ) {
5387 + var img,
5388 + wrapper = jQuery( optVal ).siblings( '.frm_image_preview_wrapper' );
5389 +
5390 + if ( ! wrapper.length ) {
5391 + return '';
5392 + }
5393 +
5394 + img = wrapper.find( 'img' );
5395 + if ( ! img.length ) {
5396 + return '';
5397 + }
5398 +
5399 + return img.attr( 'src' );
5400 + }
5401 +
5402 + function getImageLabel( label, showLabelWithImage, imageUrl, fieldType ) {
5403 + var imageLabelClass, fullLabel,
5404 + originalLabel = label,
5405 + shape = fieldType === 'checkbox' ? 'square' : 'circle';
5406 +
5407 + fullLabel = '<div class="frm_selected_checkmark"><svg class="frmsvg"><use xlink:href="#frm_checkmark_' + shape + '_icon"></svg></div>';
5408 + if ( imageUrl ) {
5409 + fullLabel += '<img src="' + imageUrl + '" alt="' + originalLabel + '" />';
5410 + } else {
5411 + fullLabel += '<div class="frm_empty_url">' + frm_admin_js.image_placeholder_icon + '</div>';
5412 + }
5413 + if ( showLabelWithImage ) {
5414 + fullLabel += '<span class="frm_text_label_for_image"><span class="frm_text_label_for_image_inner">' + originalLabel + '</span></span>';
5415 + }
5416 +
5417 + imageLabelClass = showLabelWithImage ? ' frm_label_with_image' : '';
5418 +
5419 + return ( '<span class="frm_image_option_container' + imageLabelClass + '">' + fullLabel + '</span>' );
5420 + }
5421 +
5422 + function getChecked( id ) {
5423 + field = jQuery( '#' + id );
5424 +
5425 + if ( field.length === 0 ) {
5426 + return false;
5427 + }
5428 +
5429 + checkbox = field.siblings( 'input[type=checkbox]' );
5430 +
5431 + return checkbox.length && checkbox.prop( 'checked' );
5432 + }
5433 +
5434 + function removeDropdownOpts( field ) {
5435 + var i;
5436 + if ( typeof field.options === 'undefined' ) {
5437 + return;
5438 + }
5439 +
5440 + for ( i = field.options.length - 1; i >= 0; i-- ) {
5441 + field.remove( i );
5442 + }
5443 + }
5444 +
5445 + /**
5446 + * Is the box checked to use separate values?
5447 + */
5448 + function usingSeparateValues( fieldId ) {
5449 + return isChecked( 'separate_value_' + fieldId );
5450 + }
5451 +
5452 + /**
5453 + * Is the box checked to use images as options?
5454 + */
5455 + function imagesAsOptions( fieldId ) {
5456 + var checked = false,
5457 + field = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' );
5458 +
5459 + for ( var i = 0; i < field.length; i++ ) {
5460 + if ( field[ i ].checked ) {
5461 + checked = '0' !== field[ i ].value;
5462 + }
5463 + }
5464 +
5465 + /**
5466 + * @since 5.0.04
5467 + */
5468 + return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_images_as_options', checked, fieldId );
5469 + }
5470 +
5471 + function showingLabelWithImage( fieldId ) {
5472 + const isShowing = ! isChecked( 'hide_image_text_' + fieldId );
5473 +
5474 + /**
5475 + * @since 5.0.04
5476 + */
5477 + return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_showing_label_with_image', isShowing, fieldId );
5478 + }
5479 +
5480 + function isChecked( id ) {
5481 + var field = document.getElementById( id );
5482 + if ( field === null ) {
5483 + return false;
5484 + } else {
5485 + return field.checked;
5486 + }
5487 + }
5488 +
5489 + function checkUniqueOpt( targetInput ) {
5490 + const settingsContainer = targetInput.closest( '.frm-single-settings' );
5491 + const fieldId = settingsContainer.getAttribute( 'data-fid' );
5492 + const areValuesSeparate = settingsContainer.querySelector( '[name="field_options[separate_value_' + fieldId + ']"]' ).checked;
5493 +
5494 + if ( areValuesSeparate && ! targetInput.name.endsWith( '[value]' ) ) {
5495 + return;
5496 + }
5497 +
5498 + const container = document.getElementById( 'frm_field_' + fieldId + '_opts' );
5499 + const conflicts = Array.from( container.querySelectorAll( 'input[type="text"]' ) ).filter(
5500 + input => input.id !== targetInput.id &&
5501 + areValuesSeparate === input.name.endsWith( '[value]' ) &&
5502 + input.value === targetInput.value
5503 + );
5504 + if ( conflicts.length ) {
5505 + infoModal( __( 'Duplicate option value "%s" detected', 'formidable' ).replace( '%s', targetInput.value ) );
5506 + }
5507 + }
5508 +
5509 + function setStarValues() {
5510 + /*jshint validthis:true */
5511 + var fieldID = this.id.replace( 'radio_maxnum_', '' );
5512 + var container = jQuery( '#field_' + fieldID + '_inner_container .frm-star-group' );
5513 + var fieldKey = document.getElementsByName( 'field_options[field_key_' + fieldID + ']' )[0].value;
5514 + container.html( '' );
5515 +
5516 + var min = 1;
5517 + var max = this.value;
5518 + if ( min > max ) {
5519 + max = min;
5520 + }
5521 +
5522 + for ( var i = min; i <= max; i++ ) {
5523 + container.append( '<input type="hidden" name="field_options[options_' + fieldID + '][' + i + ']" value="' + i + '"><input type="radio" name="item_meta[' + fieldID + ']" id="field_' + fieldKey + '-' + i + '" value="' + i + '" /><label for="field_' + fieldKey + '-' + i + '" class="star-rating"></label>' );
5524 + }
5525 + }
5526 +
5527 + function getFieldValues() {
5528 + /*jshint validthis:true */
5529 + var isTaxonomy,
5530 + val = this.value;
5531 +
5532 + if ( val ) {
5533 + var parentIDs = this.parentNode.id.replace( 'frm_logic_', '' ).split( '_' );
5534 + var fieldID = parentIDs[0];
5535 + var metaKey = parentIDs[1];
5536 + var valueField = document.getElementById( 'frm_field_id_' + val );
5537 + var valueFieldType = valueField.getAttribute( 'data-ftype' );
5538 + var fill = document.getElementById( 'frm_show_selected_values_' + fieldID + '_' + metaKey );
5539 + var optionName = 'field_options[hide_opt_' + fieldID + '][]';
5540 + var optionID = 'frm_field_logic_opt_' + fieldID;
5541 + var input = false;
5542 + var showSelect = ( valueFieldType === 'select' || valueFieldType === 'checkbox' || valueFieldType === 'radio' );
5543 + var showText = ( valueFieldType === 'text' || valueFieldType === 'email' || valueFieldType === 'phone' || valueFieldType === 'url' || valueFieldType === 'number' );
5544 +
5545 + if ( showSelect ) {
5546 + isTaxonomy = document.getElementById( 'frm_has_hidden_options_' + val );
5547 + if ( isTaxonomy !== null ) {
5548 + // get the category options with ajax
5549 + showSelect = false;
5550 + }
5551 + }
5552 +
5553 + if ( showSelect || showText ) {
5554 + fill.innerHTML = '';
5555 + if ( showSelect ) {
5556 + input = document.createElement( 'select' );
5557 + } else {
5558 + input = document.createElement( 'input' );
5559 + input.type = 'text';
5560 + }
5561 + input.name = optionName;
5562 + input.id = optionID + '_' + metaKey;
5563 + fill.appendChild( input );
5564 +
5565 + if ( showSelect ) {
5566 + var fillField = document.getElementById( input.id );
5567 + fillDropdownOpts( fillField, {
5568 + sourceID: val,
5569 + placeholder: '',
5570 + other: true
5571 + });
5572 + }
5573 + } else {
5574 + var thisType = this.getAttribute( 'data-type' );
5575 + frmGetFieldValues( val, fieldID, metaKey, thisType );
5576 + }
5577 + }
5578 + }
5579 +
5580 + function getFieldSelection() {
5581 + /*jshint validthis:true */
5582 + var formId = this.value;
5583 + if ( formId ) {
5584 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
5585 + getTaxOrFieldSelection( formId, fieldId );
5586 + }
5587 + }
5588 +
5589 + function getTaxOrFieldSelection( formId, fieldId ) {
5590 + if ( formId ) {
5591 + jQuery.ajax({
5592 + type: 'POST',
5593 + url: ajaxurl,
5594 + data: {
5595 + action: 'frm_get_field_selection',
5596 + field_id: fieldId,
5597 + form_id: formId,
5598 + nonce: frmGlobal.nonce
5599 + },
5600 + success: function( msg ) {
5601 + jQuery( '#frm_show_selected_fields_' + fieldId ).html( msg ).show();
5602 + }
5603 + });
5604 + }
5605 + }
5606 +
5607 + function updateFieldOrder() {
5608 + var fields, fieldId, field, currentOrder, newOrder;
5609 + renumberPageBreaks();
5610 + jQuery( '#frm-show-fields' ).each( function( i ) {
5611 + fields = jQuery( 'li.frm_field_box', this );
5612 + for ( i = 0; i < fields.length; i++ ) {
5613 + fieldId = fields[ i ].getAttribute( 'data-fid' );
5614 + field = jQuery( 'input[name="field_options[field_order_' + fieldId + ']"]' );
5615 + currentOrder = field.val();
5616 + newOrder = i + 1;
5617 +
5618 + if ( currentOrder != newOrder ) {
5619 + field.val( newOrder );
5620 + singleField = document.getElementById( 'frm-single-settings-' + fieldId );
5621 +
5622 + moveFieldSettings( singleField );
5623 + fieldUpdated();
5624 + }
5625 + }
5626 + });
5627 + }
5628 +
5629 + function toggleSectionHolder() {
5630 + document.querySelectorAll( '.start_divider' ).forEach(
5631 + function( divider ) {
5632 + toggleOneSectionHolder( jQuery( divider ) );
5633 + }
5634 + );
5635 + }
5636 +
5637 + function toggleOneSectionHolder( $section ) {
5638 + var noSectionFields, $rows, length, index, sectionHasFields;
5639 +
5640 + if ( ! $section.length ) {
5641 + return;
5642 + }
5643 +
5644 + $rows = $section.find( 'ul.frm_sorting' );
5645 + sectionHasFields = false;
5646 + length = $rows.length;
5647 + for ( index = 0; index < length; ++index ) {
5648 + if ( 0 !== getFieldsInRow( jQuery( $rows.get( index ) ) ).length ) {
5649 + sectionHasFields = true;
5650 + break;
5651 + }
5652 + }
5653 +
5654 + noSectionFields = $section.parent().children( '.frm_no_section_fields' ).get( 0 );
5655 + noSectionFields.classList.toggle( 'frm_block', ! sectionHasFields );
5656 + }
5657 +
5658 + function slideDown() {
5659 + /*jshint validthis:true */
5660 + var id = jQuery( this ).data( 'slidedown' );
5661 + var $thisId = jQuery( document.getElementById( id ) );
5662 + if ( $thisId.is( ':hidden' ) ) {
5663 + $thisId.slideDown( 'fast' );
5664 + this.style.display = 'none';
5665 + }
5666 + return false;
5667 + }
5668 +
5669 + function slideUp() {
5670 + /*jshint validthis:true */
5671 + var id = jQuery( this ).data( 'slideup' );
5672 + var $thisId = jQuery( document.getElementById( id ) );
5673 + $thisId.slideUp( 'fast' );
5674 + $thisId.siblings( 'a' ).show();
5675 + return false;
5676 + }
5677 +
5678 + function adjustVisibilityValuesForEveryoneValues( element, option ) {
5679 + if ( '' === option.getAttribute( 'value' ) ) {
5680 + onEveryoneOptionSelected( jQuery( this ) );
5681 + } else {
5682 + unselectEveryoneOptionIfSelected( jQuery( this ) );
5683 + }
5684 + }
5685 +
5686 + function onEveryoneOptionSelected( $select ) {
5687 + $select.val( '' );
5688 + $select.next( '.btn-group' ).find( '.multiselect-container input[value!=""]' ).prop( 'checked', false );
5689 + }
5690 +
5691 + function unselectEveryoneOptionIfSelected( $select ) {
5692 + var selectedValues = $select.val(),
5693 + index;
5694 +
5695 + if ( selectedValues === null ) {
5696 + $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', true );
5697 + onEveryoneOptionSelected( $select );
5698 + return;
5699 + }
5700 +
5701 + index = selectedValues.indexOf( '' );
5702 + if ( index >= 0 ) {
5703 + selectedValues.splice( index, 1 );
5704 + $select.val( selectedValues );
5705 + $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', false );
5706 + }
5707 + }
5708 +
5709 + /**
5710 + * Get rid of empty container that inserts extra space.
5711 + */
5712 + function hideEmptyEle() {
5713 + jQuery( '.frm-hide-empty' ).each( function() {
5714 + if ( jQuery( this ).text().trim().length === 0 ) {
5715 + jQuery( this ).remove();
5716 + }
5717 + });
5718 + }
5719 +
5720 + /* Change the classes in the builder */
5721 + function changeFieldClass( field, setting ) {
5722 + var classes, replace, alignField,
5723 + replaceWith = ' ' + setting.value,
5724 + fieldId = field.getAttribute( 'data-fid' );
5725 +
5726 + // Include classes from multiple settings.
5727 + if ( typeof fieldId !== 'undefined' ) {
5728 + if ( setting.classList.contains( 'field_options_align' ) ) {
5729 + replaceWith += ' ' + document.getElementById( 'frm_classes_' + fieldId ).value;
5730 + } else if ( setting.classList.contains( 'frm_classes' ) ) {
5731 + alignField = document.getElementById( 'field_options_align_' + fieldId );
5732 + if ( alignField !== null ) {
5733 + replaceWith += ' ' + alignField.value;
5734 + }
5735 + }
5736 + }
5737 + replaceWith += ' ';
5738 +
5739 + // Allow for the column number dropdown.
5740 + replaceWith = replaceWith.replace( ' block ', ' ' ).replace( ' inline ', ' horizontal_radio ' );
5741 +
5742 + classes = field.className.split( ' frmstart ' )[1];
5743 + classes = 0 === classes.indexOf( 'frmend ' ) ? '' : classes.split( ' frmend ' )[0];
5744 +
5745 + if ( classes.trim() === '' ) {
5746 + replace = ' frmstart frmend ';
5747 + if ( -1 === field.className.indexOf( replace ) ) {
5748 + replace = ' frmstart frmend ';
5749 + }
5750 + replaceWith = ' frmstart ' + replaceWith.trim() + ' frmend ';
5751 + } else {
5752 + replace = classes.trim();
5753 + replaceWith = replaceWith.trim();
5754 + }
5755 +
5756 + field.className = field.className.replace( replace, replaceWith );
5757 + }
5758 +
5759 + function maybeShowInlineModal( e ) {
5760 + /*jshint validthis:true */
5761 + e.preventDefault();
5762 + showInlineModal( this );
5763 + }
5764 +
5765 + function showInlineModal( icon, input ) {
5766 + var box = document.getElementById( icon.getAttribute( 'data-open' ) ),
5767 + container = jQuery( icon ).closest( 'p' ),
5768 + inputTrigger = ( typeof input !== 'undefined' );
5769 +
5770 + if ( container.hasClass( 'frm-open' ) ) {
5771 + container.removeClass( 'frm-open' );
5772 + box.classList.add( 'frm_hidden' );
5773 + } else {
5774 + if ( ! inputTrigger ) {
5775 + input = getInputForIcon( icon );
5776 + }
5777 + if ( input !== null ) {
5778 + if ( ! inputTrigger ) {
5779 + input.focus();
5780 + }
5781 + container.after( box );
5782 + box.setAttribute( 'data-fills', input.id );
5783 +
5784 + if ( box.id.indexOf( 'frm-calc-box' ) === 0 ) {
5785 + popCalcFields( box, true );
5786 + }
5787 + }
5788 +
5789 + container.addClass( 'frm-open' );
5790 + box.classList.remove( 'frm_hidden' );
5791 + }
5792 + }
5793 +
5794 + function dismissInlineModal( e ) {
5795 + /*jshint validthis:true */
5796 + e.preventDefault();
5797 + this.parentNode.classList.add( 'frm_hidden' );
5798 + jQuery( '.frm-open [data-open="' + this.parentNode.id + '"]' ).closest( '.frm-open' ).removeClass( 'frm-open' );
5799 + }
5800 +
5801 + function changeInputtedValue() {
5802 + /*jshint validthis:true */
5803 + var i,
5804 + action = this.getAttribute( 'data-frmchange' ).split( ',' );
5805 +
5806 + for ( i = 0; i < action.length; i++ ) {
5807 + if ( action[i] === 'updateOption' ) {
5808 + changeHiddenSeparateValue( this );
5809 + } else if ( action[i] === 'updateDefault' ) {
5810 + changeDefaultRadioValue( this );
5811 + } else if ( action[i] === 'checkUniqueOpt' ) {
5812 + checkUniqueOpt( this );
5813 + } else {
5814 + this.value = this.value[ action[i] ]();
5815 + }
5816 + }
5817 + }
5818 +
5819 + /**
5820 + * When the saved value is changed, update the default value radio.
5821 + */
5822 + function changeDefaultRadioValue( input ) {
5823 + var parentLi = getOptionParent( input ),
5824 + key = parentLi.getAttribute( 'data-optkey' ),
5825 + fieldId = getOptionFieldId( parentLi, key ),
5826 + defaultRadio = parentLi.querySelector( 'input[name="default_value_' + fieldId + '"]' );
5827 +
5828 + if ( defaultRadio !== null ) {
5829 + defaultRadio.value = input.value;
5830 + }
5831 + }
5832 +
5833 + /**
5834 + * If separate values are not enabled, change the saved value when
5835 + * the displayed value is changed.
5836 + */
5837 + function changeHiddenSeparateValue( input ) {
5838 + var savedVal,
5839 + parentLi = getOptionParent( input ),
5840 + key = parentLi.getAttribute( 'data-optkey' ),
5841 + fieldId = getOptionFieldId( parentLi, key ),
5842 + sep = document.getElementById( 'separate_value_' + fieldId );
5843 +
5844 + if ( sep !== null && sep.checked === false ) {
5845 + // If separate values are not turned on.
5846 + savedVal = document.getElementById( 'field_key_' + fieldId + '-' + key );
5847 + savedVal.value = input.value;
5848 + changeDefaultRadioValue( savedVal );
5849 + }
5850 + }
5851 +
5852 + function getOptionParent( input ) {
5853 + var parentLi = input.parentNode;
5854 + if ( parentLi.tagName !== 'LI' ) {
5855 + parentLi = parentLi.parentNode;
5856 + }
5857 + return parentLi;
5858 + }
5859 +
5860 + function getOptionFieldId( li, key ) {
5861 + var liId = li.id;
5862 +
5863 + return liId.replace( 'frm_delete_field_', '' ).replace( '-' + key + '_container', '' );
5864 + }
5865 +
5866 + function submitBuild() {
5867 + /*jshint validthis:true */
5868 + var $thisEle = jQuery( this );
5869 + var p = $thisEle.html();
5870 +
5871 + preFormSave( this );
5872 +
5873 + var $form = jQuery( builderForm );
5874 + var v = JSON.stringify( $form.serializeArray() );
5875 +
5876 + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( v );
5877 + jQuery.ajax({
5878 + type: 'POST',
5879 + url: ajaxurl,
5880 + data: {action: 'frm_save_form', 'frm_compact_fields': v, nonce: frmGlobal.nonce},
5881 + success: function( msg ) {
5882 + afterFormSave( $thisEle, p );
5883 +
5884 + var $postStuff = document.getElementById( 'post-body-content' );
5885 + var $html = document.createElement( 'div' );
5886 + $html.setAttribute( 'class', 'frm_updated_message' );
5887 + $html.innerHTML = msg;
5888 + $postStuff.insertBefore( $html, $postStuff.firstChild );
5889 + },
5890 + error: function() {
5891 + triggerSubmit( document.getElementById( 'frm_js_build_form' ) );
5892 + }
5893 + });
5894 + }
5895 +
5896 + function triggerSubmit( form ) {
5897 + var button = form.ownerDocument.createElement( 'input' );
5898 + button.style.display = 'none';
5899 + button.type = 'submit';
5900 + form.appendChild( button ).click();
5901 + form.removeChild( button );
5902 + }
5903 +
5904 + function triggerChange( element ) {
5905 + jQuery( element ).trigger( 'change' );
5906 + }
5907 +
5908 + function submitNoAjax() {
5909 + /*jshint validthis:true */
5910 + var form;
5911 +
5912 + preFormSave( this );
5913 + form = jQuery( builderForm );
5914 + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( JSON.stringify( form.serializeArray() ) );
5915 + triggerSubmit( document.getElementById( 'frm_js_build_form' ) );
5916 + }
5917 +
5918 + function preFormSave( b ) {
5919 + removeWPUnload();
5920 + if ( jQuery( 'form.inplace_form' ).length ) {
5921 + jQuery( '.inplace_save, .postbox' ).trigger( 'click' );
5922 + }
5923 +
5924 + $button = jQuery( b );
5925 +
5926 + if ( $button.hasClass( 'frm_button_submit' ) ) {
5927 + $button.addClass( 'frm_loading_form' );
5928 + $button.html( frm_admin_js.saving );
5929 + } else {
5930 + $button.addClass( 'frm_loading_button' );
5931 + $button.val( frm_admin_js.saving );
5932 + }
5933 + }
5934 +
5935 + function afterFormSave( $button, buttonVal ) {
5936 + $button.removeClass( 'frm_loading_form' ).removeClass( 'frm_loading_button' );
5937 + $button.html( frm_admin_js.saved );
5938 + resetOptionTextDetails();
5939 + fieldsUpdated = 0;
5940 +
5941 + setTimeout( function() {
5942 + jQuery( '.frm_updated_message' ).fadeOut( 'slow', function() {
5943 + this.parentNode.removeChild( this );
5944 + });
5945 + $button.fadeOut( 'slow', function() {
5946 + $button.html( buttonVal );
5947 + $button.show();
5948 + });
5949 + }, 5000 );
5950 + }
5951 +
5952 + function initUpgradeModal() {
5953 + const $info = initModal( '#frm_upgrade_modal' );
5954 + if ( $info === false ) {
5955 + return;
5956 + }
5957 +
5958 + document.addEventListener( 'click', handleUpgradeClick );
5959 +
5960 + function handleUpgradeClick( event ) {
5961 + let element, link, content;
5962 +
5963 + element = event.target;
5964 +
5965 + if ( ! element.classList ) {
5966 + return;
5967 + }
5968 +
5969 + const showExpiredModal = element.classList.contains( 'frm_show_expired_modal' ) || null !== element.querySelector( '.frm_show_expired_modal' ) || element.closest( '.frm_show_expired_modal' );
5970 +
5971 + if ( ! element.dataset.upgrade ) {
5972 + const parent = element.closest( '[data-upgrade]' );
5973 + if ( ! parent ) {
5974 + return;
5975 + }
5976 + element = parent;
5977 + }
5978 +
5979 + if ( showExpiredModal ) {
5980 + const hookName = 'frm_show_expired_modal';
5981 + wp.hooks.doAction( hookName, element );
5982 + return;
5983 + }
5984 +
5985 + const upgradeLabel = element.dataset.upgrade;
5986 + if ( ! upgradeLabel || element.classList.contains( 'frm_show_upgrade_tab' ) ) {
5987 + return;
5988 + }
5989 +
5990 + event.preventDefault();
5991 +
5992 + const modal = $info.get( 0 );
5993 + const lockIcon = modal.querySelector( '.frm_lock_icon' );
5994 +
5995 + if ( lockIcon ) {
5996 + lockIcon.style.display = 'block';
5997 + lockIcon.classList.remove( 'frm_lock_open_icon' );
5998 + lockIcon.querySelector( 'use' ).setAttribute( 'href', '#frm_lock_icon' );
5999 + }
6000 +
6001 + const upgradeImageId = 'frm_upgrade_modal_image';
6002 + const oldImage = document.getElementById( upgradeImageId );
6003 + if ( oldImage ) {
6004 + oldImage.remove();
6005 + }
6006 +
6007 + if ( element.dataset.image ) {
6008 + if ( lockIcon ) {
6009 + lockIcon.style.display = 'none';
6010 + }
6011 + lockIcon.parentNode.insertBefore( img({ id: upgradeImageId, src: frmGlobal.url + '/images/' + element.dataset.image }), lockIcon );
6012 + }
6013 +
6014 + const level = modal.querySelector( '.license-level' );
6015 + if ( level ) {
6016 + level.textContent = getRequiredLicenseFromTrigger( element );
6017 + }
6018 +
6019 + // If one click upgrade, hide other content
6020 + addOneClick( element, 'modal', upgradeLabel );
6021 +
6022 + modal.querySelector( '.frm_are_not_installed' ).style.display = element.dataset.image ? 'none' : 'inline-block';
6023 + modal.querySelector( '.frm_feature_label' ).textContent = upgradeLabel;
6024 + modal.querySelector( 'h2' ).style.display = 'block';
6025 +
6026 + $info.dialog( 'open' );
6027 +
6028 + // set the utm medium
6029 + const button = modal.querySelector( '.button-primary:not(.frm-oneclick-button)' );
6030 + link = button.getAttribute( 'href' ).replace( /(medium=)[a-z_-]+/ig, '$1' + element.getAttribute( 'data-medium' ) );
6031 + content = element.getAttribute( 'data-content' );
6032 + if ( content === null ) {
6033 + content = '';
6034 + }
6035 + link = link.replace( /(content=)[a-z_-]+/ig, '$1' + content );
6036 + button.setAttribute( 'href', link );
6037 + }
6038 + }
6039 +
6040 + // Move the top banner above the screen options to prevent overlap.
6041 + function moveTopBanner() {
6042 + const $banner = document.querySelector( '.frm-banner-alert' ) || document.querySelector( '.frm-upgrade-bar' );
6043 + if ( ! $banner ) {
6044 + return;
6045 + }
6046 +
6047 + const $screenMeta = document.getElementById( 'screen-meta' );
6048 + if ( ! $screenMeta ) {
6049 + return;
6050 + }
6051 +
6052 + const $parentDiv = document.getElementById( 'wpbody-content' );
6053 + $parentDiv.insertBefore( $banner, $screenMeta );
6054 + }
6055 +
6056 + function getRequiredLicenseFromTrigger( element ) {
6057 + if ( element.dataset.requires ) {
6058 + return element.dataset.requires;
6059 + }
6060 + return 'Pro';
6061 + }
6062 +
6063 + function populateUpgradeTab( element ) {
6064 + const title = element.dataset.upgrade;
6065 +
6066 + const tab = element.getAttribute( 'href' ).replace( '#', '' );
6067 + const container = document.querySelector( '.frm_' + tab ) || document.querySelector( '.' + tab );
6068 +
6069 + if ( ! container ) {
6070 + return;
6071 + }
6072 +
6073 + if ( container.querySelector( '.frm-upgrade-message' ) ) {
6074 + // Tab has already been populated.
6075 + return;
6076 + }
6077 +
6078 + const h2 = container.querySelector( 'h2' );
6079 + h2.style.borderBottom = 'none';
6080 +
6081 + /* translators: %s: Form Setting section name (ie Form Permissions, Form Scheduling). */
6082 + h2.textContent = __( '%s are not installed' ).replace( '%s', title );
6083 +
6084 + container.classList.add( 'frmcenter' );
6085 +
6086 + const upgradeModal = document.getElementById( 'frm_upgrade_modal' );
6087 + appendClonedModalElementToContainer( 'frm-oneclick' );
6088 + appendClonedModalElementToContainer( 'frm-addon-status' );
6089 +
6090 + // 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).
6091 + const upgradeModalLink = upgradeModal.querySelector( '.frm-upgrade-link' );
6092 + if ( upgradeModalLink ) {
6093 + const upgradeButton = upgradeModalLink.cloneNode( true );
6094 + const level = upgradeButton.querySelector( '.license-level' );
6095 +
6096 + if ( level ) {
6097 + level.textContent = getRequiredLicenseFromTrigger( element );
6098 + }
6099 +
6100 + container.appendChild( upgradeButton );
6101 +
6102 + // Maybe append the secondary "Already purchased?" link from the upgradeModal as well.
6103 + if ( upgradeModalLink.nextElementSibling && upgradeModalLink.nextElementSibling.querySelector( '.frm-link-secondary' ) ) {
6104 + container.appendChild( upgradeModalLink.nextElementSibling.cloneNode( true ) );
6105 + }
6106 +
6107 + appendClonedModalElementToContainer( 'frm-oneclick-button' );
6108 + }
6109 +
6110 + appendClonedModalElementToContainer( 'frm-upgrade-message' );
6111 + addOneClick( element, 'tab', element.dataset.message );
6112 +
6113 + if ( element.dataset.screenshot ) {
6114 + container.appendChild( getScreenshotWrapper( element.dataset.screenshot ) );
6115 + }
6116 +
6117 + function appendClonedModalElementToContainer( className ) {
6118 + container.appendChild( upgradeModal.querySelector( '.' + className ).cloneNode( true ) );
6119 + }
6120 + }
6121 +
6122 + function getScreenshotWrapper( screenshot ) {
6123 + const folderUrl = frmGlobal.url + '/images/screenshots/';
6124 + const wrapper = div({
6125 + className: 'frm-settings-screenshot-wrapper',
6126 + children: [
6127 + getToolbar(),
6128 + div({ child: img({ src: folderUrl + screenshot }) })
6129 + ]
6130 + });
6131 +
6132 + function getToolbar() {
6133 + const children = getColorIcons();
6134 + children.push( img({ src: frmGlobal.url + '/images/tab.svg' }) );
6135 + return div({
6136 + className: 'frm-settings-screenshot-toolbar',
6137 + children
6138 + });
6139 + }
6140 +
6141 + function getColorIcons() {
6142 + return [ '#ED8181', '#EDE06A', '#80BE30' ].map(
6143 + color => {
6144 + const circle = div({ className: 'frm-minmax-icon' });
6145 + circle.style.backgroundColor = color;
6146 + return circle;
6147 + }
6148 + );
6149 + }
6150 +
6151 + return wrapper;
6152 + }
6153 +
6154 + /**
6155 + * Allow addons to be installed from the upgrade modal.
6156 + *
6157 + * @param {Element} link
6158 + * @param {String} context Either 'modal' or 'tab'.
6159 + * @param {String|undefined} upgradeLabel
6160 + */
6161 + function addOneClick( link, context, upgradeLabel ) {
6162 + let container;
6163 +
6164 + if ( 'modal' === context ) {
6165 + container = document.getElementById( 'frm_upgrade_modal' );
6166 + } else if ( 'tab' === context ) {
6167 + container = document.getElementById( link.getAttribute( 'href' ).substr( 1 ) );
6168 + } else {
6169 + return;
6170 + }
6171 +
6172 + const oneclickMessage = container.querySelector( '.frm-oneclick' );
6173 + const upgradeMessage = container.querySelector( '.frm-upgrade-message' );
6174 + const showLink = container.querySelector( '.frm-upgrade-link' );
6175 + const button = container.querySelector( '.frm-oneclick-button' );
6176 + const addonStatus = container.querySelector( '.frm-addon-status' );
6177 +
6178 + let oneclick = link.getAttribute( 'data-oneclick' );
6179 + let newMessage = link.getAttribute( 'data-message' );
6180 + let showIt = 'block';
6181 + let showMsg = 'block';
6182 + let hideIt = 'none';
6183 +
6184 + // If one click upgrade, hide other content.
6185 + if ( oneclickMessage !== null && typeof oneclick !== 'undefined' && oneclick ) {
6186 + if ( newMessage === null ) {
6187 + showMsg = 'none';
6188 + }
6189 + showIt = 'none';
6190 + hideIt = 'block';
6191 + oneclick = JSON.parse( oneclick );
6192 +
6193 + button.className = button.className.replace( ' frm-install-addon', '' ).replace( ' frm-activate-addon', '' );
6194 + button.className = button.className + ' ' + oneclick.class;
6195 + button.textContent = __( 'Activate', 'formidable' );
6196 + button.rel = oneclick.url;
6197 + }
6198 +
6199 + if ( ! newMessage ) {
6200 + newMessage = upgradeMessage.getAttribute( 'data-default' );
6201 + }
6202 + if ( undefined !== upgradeLabel ) {
6203 + newMessage = newMessage.replace( '<span class="frm_feature_label"></span>', upgradeLabel );
6204 + }
6205 +
6206 + upgradeMessage.innerHTML = newMessage;
6207 +
6208 + // Either set the link or use the default.
6209 + showLink.href = getShowLinkHrefValue( link, showLink );
6210 +
6211 + addonStatus.style.display = 'none';
6212 +
6213 + oneclickMessage.style.display = hideIt;
6214 + button.style.display = hideIt === 'block' ? 'inline-block' : hideIt;
6215 + upgradeMessage.style.display = showMsg;
6216 + showLink.style.display = showIt === 'block' ? 'inline-block' : showIt;
6217 + }
6218 +
6219 + function getShowLinkHrefValue( link, showLink ) {
6220 + let customLink = link.getAttribute( 'data-link' );
6221 + if ( customLink === null || typeof customLink === 'undefined' || customLink === '' ) {
6222 + customLink = showLink.getAttribute( 'data-default' );
6223 + }
6224 + return customLink;
6225 + }
6226 +
6227 + /* Form settings */
6228 +
6229 + function showInputIcon( parentClass ) {
6230 + if ( typeof parentClass === 'undefined' ) {
6231 + parentClass = '';
6232 + }
6233 + maybeAddFieldSelection( parentClass );
6234 + 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>' );
6235 + }
6236 +
6237 + /**
6238 + * For reverse compatibility. Check for fields that were
6239 + * using the old sidebar.
6240 + */
6241 + function maybeAddFieldSelection( parentClass ) {
6242 + var i,
6243 + 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' );
6244 + for ( i = 0; i < missingClass.length; i++ ) {
6245 + missingClass[i].parentNode.classList.add( 'frm_has_shortcodes' );
6246 + }
6247 + }
6248 +
6249 + function showSuccessOpt() {
6250 + /*jshint validthis:true */
6251 + var c = 'success';
6252 + if ( this.name === 'options[edit_action]' ) {
6253 + c = 'edit';
6254 + }
6255 + var v = jQuery( this ).val();
6256 + jQuery( '.' + c + '_action_box' ).hide();
6257 + if ( v === 'redirect' ) {
6258 + jQuery( '.' + c + '_action_redirect_box.' + c + '_action_box' ).fadeIn( 'slow' );
6259 + } else if ( v === 'page' ) {
6260 + jQuery( '.' + c + '_action_page_box.' + c + '_action_box' ).fadeIn( 'slow' );
6261 + } else {
6262 + jQuery( '.' + c + '_action_message_box.' + c + '_action_box' ).fadeIn( 'slow' );
6263 + }
6264 + }
6265 +
6266 + function copyFormAction( event ) {
6267 + if ( waitForActionToLoadBeforeCopy( event.target ) ) {
6268 + return;
6269 + }
6270 +
6271 + const targetSettings = event.target.closest( '.frm_form_action_settings' );
6272 + const wysiwyg = targetSettings.querySelector( '.wp-editor-area' );
6273 + if ( wysiwyg ) {
6274 + // Temporary remove TinyMCE before cloning to avoid TinyMCE conflicts.
6275 + tinymce.EditorManager.execCommand( 'mceRemoveEditor', true, wysiwyg.id );
6276 + }
6277 +
6278 + const $action = jQuery( targetSettings ).clone();
6279 + const currentID = $action.attr( 'id' ).replace( 'frm_form_action_', '' );
6280 + const newID = newActionId( currentID );
6281 +
6282 + $action.find( '.frm_action_id, .frm-btn-group' ).remove();
6283 + $action.find( 'input[name$="[' + currentID + '][ID]"]' ).val( '' );
6284 + $action.find( '.widget-inside' ).hide();
6285 +
6286 + // the .html() gets original values, so they need to be set
6287 + $action.find( 'input[type=text], textarea, input[type=number]' ).prop( 'defaultValue', function() {
6288 + return this.value;
6289 + });
6290 +
6291 + $action.find( 'input[type=checkbox], input[type=radio]' ).prop( 'defaultChecked', function() {
6292 + return this.checked;
6293 + });
6294 +
6295 + const rename = new RegExp( '\\[' + currentID + '\\]', 'g' );
6296 + const reid = new RegExp( '_' + currentID + '"', 'g' );
6297 + const reclass = new RegExp( '-' + currentID + '"', 'g' );
6298 + const revalue = new RegExp( '"' + currentID + '"', 'g' ); // if a field id matches, this could cause trouble
6299 +
6300 + let html = $action.html().replace( rename, '[' + newID + ']' ).replace( reid, '_' + newID + '"' );
6301 + html = html.replace( reclass, '-' + newID + '"' ).replace( revalue, '"' + newID + '"' );
6302 +
6303 + const newAction = div({
6304 + id: 'frm_form_action_' + newID,
6305 + className: $action.get( 0 ).className
6306 + });
6307 + newAction.setAttribute( 'data-actionkey', newID );
6308 + newAction.innerHTML = html;
6309 + newAction.querySelectorAll( '.wp-editor-wrap, .wp-editor-wrap *' ).forEach(
6310 + element => {
6311 + if ( 'string' === typeof element.className ) {
6312 + element.className = element.className.replace( currentID, newID );
6313 + }
6314 + element.id = element.id.replace( currentID, newID );
6315 + }
6316 + );
6317 + newAction.classList.remove( 'open' );
6318 + document.getElementById( 'frm_notification_settings' ).appendChild( newAction );
6319 +
6320 + if ( wysiwyg ) {
6321 + // Re-initialize the original wysiwyg which was removed before cloning.
6322 + frmDom.wysiwyg.init( wysiwyg );
6323 + }
6324 + frmDom.wysiwyg.init( newAction.querySelector( '.wp-editor-area' ) );
6325 +
6326 + initiateMultiselect();
6327 +
6328 + const hookName = 'frm_after_duplicate_action';
6329 + wp.hooks.doAction( hookName, newAction );
6330 + }
6331 +
6332 + function waitForActionToLoadBeforeCopy( element ) {
6333 + var $trigger = jQuery( element ),
6334 + $original = $trigger.closest( '.frm_form_action_settings' ),
6335 + $inside = $original.find( '.widget-inside' ),
6336 + $top;
6337 +
6338 + if ( $inside.find( 'p, div, table' ).length ) {
6339 + return false;
6340 + }
6341 +
6342 + $top = $original.find( '.widget-top' );
6343 + $top.on( 'frm-action-loaded', function() {
6344 + $trigger.trigger( 'click' );
6345 + $original.removeClass( 'open' );
6346 + $inside.hide();
6347 + });
6348 + $top.trigger( 'click' );
6349 + return true;
6350 + }
6351 +
6352 + function newActionId( currentID ) {
6353 + var newID = parseInt( currentID, 10 ) + 11;
6354 + var exists = document.getElementById( 'frm_form_action_' + newID );
6355 + if ( exists !== null ) {
6356 + newID++;
6357 + newID = newActionId( newID );
6358 + }
6359 + return newID;
6360 + }
6361 +
6362 + function addFormAction() {
6363 + /*jshint validthis:true */
6364 + const type = jQuery( this ).data( 'actiontype' );
6365 +
6366 + if ( isAtLimitForActionType( type ) ) {
6367 + return;
6368 + }
6369 +
6370 + const actionId = getNewActionId();
6371 + const formId = thisFormId;
6372 +
6373 + const placeholderSetting = document.createElement( 'div' );
6374 + placeholderSetting.classList.add( 'frm_single_' + type + '_settings' );
6375 +
6376 + const actionsList = document.getElementById( 'frm_notification_settings' );
6377 + actionsList.appendChild( placeholderSetting );
6378 +
6379 + jQuery.ajax({
6380 + type: 'POST',
6381 + url: ajaxurl,
6382 + data: {
6383 + action: 'frm_add_form_action',
6384 + type: type,
6385 + list_id: actionId,
6386 + form_id: formId,
6387 + nonce: frmGlobal.nonce
6388 + },
6389 + success: handleAddFormActionSuccess
6390 + });
6391 +
6392 + function handleAddFormActionSuccess( html ) {
6393 + fieldUpdated();
6394 + placeholderSetting.remove();
6395 +
6396 + closeOpenActions();
6397 +
6398 + const newActionContainer = div();
6399 + newActionContainer.innerHTML = html;
6400 +
6401 + const widgetTop = newActionContainer.querySelector( '.widget-top' );
6402 + Array.from( newActionContainer.children ).forEach( child => actionsList.appendChild( child ) );
6403 +
6404 + jQuery( '.frm_form_action_settings' ).fadeIn( 'slow' );
6405 +
6406 + const newAction = document.getElementById( 'frm_form_action_' + actionId );
6407 +
6408 + newAction.classList.add( 'open' );
6409 + document.getElementById( 'post-body-content' ).scroll({
6410 + top: newAction.offsetTop + 10,
6411 + left: 0,
6412 + behavior: 'smooth'
6413 + });
6414 +
6415 + // Check if icon should be active
6416 + checkActiveAction( type );
6417 + showInputIcon( '#frm_form_action_' + actionId );
6418 +
6419 + initiateMultiselect();
6420 +
6421 + if ( widgetTop ) {
6422 + jQuery( widgetTop ).trigger( 'frm-action-loaded' );
6423 + }
6424 + }
6425 + }
6426 +
6427 + function closeOpenActions() {
6428 + document.querySelectorAll( '.frm_form_action_settings.open' ).forEach(
6429 + setting => setting.classList.remove( 'open' )
6430 + );
6431 + }
6432 +
6433 + function toggleActionGroups() {
6434 + /*jshint validthis:true */
6435 + var actions = document.getElementById( 'frm_email_addon_menu' ).classList,
6436 + search = document.getElementById( 'actions-search-input' );
6437 +
6438 + if ( actions.contains( 'frm-all-actions' ) ) {
6439 + actions.remove( 'frm-all-actions' );
6440 + actions.add( 'frm-limited-actions' );
6441 + } else {
6442 + actions.add( 'frm-all-actions' );
6443 + actions.remove( 'frm-limited-actions' );
6444 + }
6445 +
6446 + // Reset search.
6447 + search.value = '';
6448 + triggerEvent( search, 'input' );
6449 + }
6450 +
6451 + function getNewActionId() {
6452 + var actionSettings = document.querySelectorAll( '.frm_form_action_settings' ),
6453 + len = getNewRowId( actionSettings, 'frm_form_action_' );
6454 + if ( typeof document.getElementById( 'frm_form_action_' + len ) !== 'undefined' ) {
6455 + len = len + 100;
6456 + }
6457 + if ( lastNewActionIdReturned >= len ) {
6458 + len = lastNewActionIdReturned + 1;
6459 + }
6460 + lastNewActionIdReturned = len;
6461 + return len;
6462 + }
6463 +
6464 + function clickAction( obj ) {
6465 + var $thisobj = jQuery( obj );
6466 +
6467 + if ( obj.className.indexOf( 'selected' ) !== -1 ) {
6468 + return;
6469 + }
6470 + if ( obj.className.indexOf( 'edit_field_type_end_divider' ) !== -1 && $thisobj.closest( '.edit_field_type_divider' ).hasClass( 'no_repeat_section' ) ) {
6471 + return;
6472 + }
6473 +
6474 + deselectFields();
6475 + $thisobj.addClass( 'selected' );
6476 + showFieldOptions( obj );
6477 + }
6478 +
6479 + /**
6480 + * When a field is selected, show the field settings in the sidebar.
6481 + */
6482 + function showFieldOptions( obj ) {
6483 + var i, singleField,
6484 + fieldId = obj.getAttribute( 'data-fid' ),
6485 + fieldType = obj.getAttribute( 'data-type' ),
6486 + allFieldSettings = document.querySelectorAll( '.frm-single-settings:not(.frm_hidden)' );
6487 +
6488 + for ( i = 0; i < allFieldSettings.length; i++ ) {
6489 + allFieldSettings[i].classList.add( 'frm_hidden' );
6490 + }
6491 +
6492 + singleField = document.getElementById( 'frm-single-settings-' + fieldId );
6493 + moveFieldSettings( singleField );
6494 +
6495 + if ( fieldType && 'quantity' === fieldType ) {
6496 + popProductFields( jQuery( singleField ).find( '.frmjs_prod_field_opt' )[0]);
6497 + }
6498 +
6499 + singleField.classList.remove( 'frm_hidden' );
6500 + document.getElementById( 'frm-options-panel-tab' ).click();
6501 +
6502 + const editor = singleField.querySelector( '.wp-editor-area' );
6503 + if ( editor ) {
6504 + frmDom.wysiwyg.init(
6505 + editor,
6506 + { setupCallback: setupTinyMceEventHandlers }
6507 + );
6508 + }
6509 + }
6510 +
6511 + function setupTinyMceEventHandlers( editor ) {
6512 + editor.on( 'Change', function() {
6513 + handleTinyMceChange( editor );
6514 + });
6515 + }
6516 +
6517 + function handleTinyMceChange( editor ) {
6518 + if ( ! isTinyMceActive() || tinyMCE.activeEditor.isHidden() ) {
6519 + return;
6520 + }
6521 +
6522 + editor.targetElm.value = editor.getContent();
6523 + jQuery( editor.targetElm ).trigger( 'change' );
6524 + }
6525 +
6526 + function isTinyMceActive() {
6527 + var activeSettings, wrapper;
6528 +
6529 + activeSettings = document.querySelector( '.frm-single-settings:not(.frm_hidden)' );
6530 + if ( ! activeSettings ) {
6531 + return false;
6532 + }
6533 +
6534 + wrapper = activeSettings.querySelector( '.wp-editor-wrap' );
6535 + return null !== wrapper && wrapper.classList.contains( 'tmce-active' );
6536 + }
6537 +
6538 + /**
6539 + * Move the settings to the sidebar the first time they are changed or selected.
6540 + * Keep the end marker at the end of the form.
6541 + */
6542 + function moveFieldSettings( singleField ) {
6543 + if ( singleField === null ) {
6544 + // The field may have not been loaded yet via ajax.
6545 + return;
6546 + }
6547 +
6548 + var classes = singleField.parentElement.classList;
6549 + if ( classes.contains( 'frm_field_box' ) || classes.contains( 'divider_section_only' ) ) {
6550 + var endMarker = document.getElementById( 'frm-end-form-marker' );
6551 + builderForm.insertBefore( singleField, endMarker );
6552 + }
6553 + }
6554 +
6555 + function showEmailRow() {
6556 + /*jshint validthis:true */
6557 + var actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' );
6558 + var rowType = this.getAttribute( 'data-emailrow' );
6559 +
6560 + jQuery( '#frm_form_action_' + actionKey + ' .frm_' + rowType + '_row' ).fadeIn( 'slow' );
6561 + jQuery( this ).fadeOut( 'slow' );
6562 + }
6563 +
6564 + function hideEmailRow() {
6565 + /*jshint validthis:true */
6566 + var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ),
6567 + rowType = this.getAttribute( 'data-emailrow' ),
6568 + emailRowSelector = '.frm_' + rowType + '_row',
6569 + emailButtonSelector = '.frm_' + rowType + '_button';
6570 +
6571 + jQuery( actionBox ).find( emailButtonSelector ).fadeIn( 'slow' );
6572 + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow', function() {
6573 + jQuery( actionBox ).find( emailRowSelector + ' input' ).val( '' );
6574 + });
6575 + }
6576 +
6577 + function showEmailWarning() {
6578 + /*jshint validthis:true */
6579 + var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ),
6580 + emailRowSelector = '.frm_from_to_match_row',
6581 + fromVal = actionBox.find( 'input[name$="[post_content][from]"]' ).val(),
6582 + toVal = actionBox.find( 'input[name$="[post_content][email_to]"]' ).val();
6583 +
6584 + if ( fromVal === toVal ) {
6585 + jQuery( actionBox ).find( emailRowSelector ).fadeIn( 'slow' );
6586 + } else {
6587 + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow' );
6588 + }
6589 + }
6590 +
6591 + function checkActiveAction( type ) {
6592 + const actionTriggers = document.querySelectorAll( '.frm_' + type + '_action' );
6593 +
6594 + if ( isAtLimitForActionType( type ) ) {
6595 + const addAlreadyUsedClass = getLimitForActionType( type ) > 0;
6596 + markActionTriggersInactive( actionTriggers, addAlreadyUsedClass );
6597 + return;
6598 + }
6599 +
6600 + markActionTriggersActive( actionTriggers );
6601 + }
6602 +
6603 + function markActionTriggersActive( triggers ) {
6604 + triggers.forEach(
6605 + trigger => {
6606 + if ( trigger.querySelector( '.frm_show_upgrade' ) ) {
6607 + // Prevent disabled action becoming active.
6608 + return;
6609 + }
6610 +
6611 + trigger.classList.remove( 'frm_inactive_action', 'frm_already_used' );
6612 + trigger.classList.add( 'frm_active_action' );
6613 + }
6614 + );
6615 + }
6616 +
6617 + function markActionTriggersInactive( triggers, addAlreadyUsedClass ) {
6618 + triggers.forEach(
6619 + trigger => {
6620 + trigger.classList.remove( 'frm_active_action' );
6621 + trigger.classList.add( 'frm_inactive_action' );
6622 + if ( addAlreadyUsedClass ) {
6623 + trigger.classList.add( 'frm_already_used' );
6624 + }
6625 + }
6626 + );
6627 + }
6628 +
6629 + function isAtLimitForActionType( type ) {
6630 + let atLimit = getNumberOfActionsForType( type ) >= getLimitForActionType( type );
6631 +
6632 + const hookName = 'frm_action_at_limit';
6633 + const hookArgs = { type };
6634 + atLimit = wp.hooks.applyFilters( hookName, atLimit, hookArgs );
6635 +
6636 + return atLimit;
6637 + }
6638 +
6639 + function getLimitForActionType( type ) {
6640 + return parseInt( jQuery( '.frm_' + type + '_action' ).data( 'limit' ), 10 );
6641 + }
6642 +
6643 + function getNumberOfActionsForType( type ) {
6644 + return jQuery( '.frm_single_' + type + '_settings' ).length;
6645 + }
6646 +
6647 + function onlyOneActionMessage() {
6648 + infoModal( frm_admin_js.only_one_action );
6649 + }
6650 +
6651 + function addFormLogicRow() {
6652 + /*jshint validthis:true */
6653 + var id = jQuery( this ).data( 'emailkey' ),
6654 + type = jQuery( this ).closest( '.frm_form_action_settings' ).find( '.frm_action_name' ).val(),
6655 + formId = document.getElementById( 'form_id' ).value,
6656 + logicRows = document.getElementById( 'frm_form_action_' + id ).querySelectorAll( '.frm_logic_row' );
6657 + jQuery.ajax({
6658 + type: 'POST', url: ajaxurl,
6659 + data: {
6660 + action: 'frm_add_form_logic_row',
6661 + email_id: id,
6662 + form_id: formId,
6663 + meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ),
6664 + type: type,
6665 + nonce: frmGlobal.nonce
6666 + },
6667 + success: function( html ) {
6668 + jQuery( document.getElementById( 'logic_link_' + id ) ).fadeOut( 'slow', function() {
6669 + var $logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) );
6670 + $logicRow.append( html );
6671 + $logicRow.parent( '.frm_logic_rows' ).fadeIn( 'slow' );
6672 + });
6673 + }
6674 + });
6675 + return false;
6676 + }
6677 +
6678 + function toggleSubmitLogic() {
6679 + /*jshint validthis:true */
6680 + if ( this.checked ) {
6681 + addSubmitLogic();
6682 + } else {
6683 + jQuery( '.frm_logic_row_submit' ).remove();
6684 + document.getElementById( 'frm_submit_logic_rows' ).style.display = 'none';
6685 + }
6686 + }
6687 +
6688 + /**
6689 + * Adds submit button Conditional Logic row and reveals submit button Conditional Logic
6690 + *
6691 + * @returns {boolean}
6692 + */
6693 + function addSubmitLogic() {
6694 + /*jshint validthis:true */
6695 + var formId = thisFormId,
6696 + logicRows = document.getElementById( 'frm_submit_logic_row' ).querySelectorAll( '.frm_logic_row' );
6697 + jQuery.ajax({
6698 + type: 'POST',
6699 + url: ajaxurl,
6700 + data: {
6701 + action: 'frm_add_submit_logic_row',
6702 + form_id: formId,
6703 + meta_name: getNewRowId( logicRows, 'frm_logic_submit_' ),
6704 + nonce: frmGlobal.nonce
6705 + },
6706 + success: function( html ) {
6707 + var $logicRow = jQuery( document.getElementById( 'frm_submit_logic_row' ) );
6708 + $logicRow.append( html );
6709 + $logicRow.parent( '.frm_submit_logic_rows' ).fadeIn( 'slow' );
6710 + }
6711 + });
6712 + return false;
6713 + }
6714 +
6715 + /**
6716 + * When the user selects a field for a submit condition, update corresponding options field accordingly.
6717 + */
6718 + function addSubmitLogicOpts() {
6719 + var fieldOpt = jQuery( this );
6720 + var fieldId = fieldOpt.find( ':selected' ).val();
6721 +
6722 + if ( fieldId ) {
6723 + var row = fieldOpt.data( 'row' );
6724 + frmGetFieldValues( fieldId, 'submit', row, '', 'options[submit_conditions][hide_opt][]' );
6725 + }
6726 + }
6727 +
6728 + function formatEmailSetting() {
6729 + /*jshint validthis:true */
6730 + /*var val = jQuery( this ).val();
6731 + var email = val.match( /(\s[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi );
6732 + if(email !== null && email.length) {
6733 + //has email
6734 + //TODO: add < > if they aren't there
6735 + }*/
6736 + }
6737 +
6738 + function maybeShowFormMessages() {
6739 + var header = document.getElementById( 'frm_messages_header' );
6740 + if ( showFormMessages() ) {
6741 + header.style.display = 'block';
6742 + } else {
6743 + header.style.display = 'none';
6744 + }
6745 + }
6746 +
6747 + function showFormMessages() {
6748 + var action = document.getElementById( 'success_action' );
6749 + var selectedAction = action.options[action.selectedIndex].value;
6750 + if ( selectedAction === 'message' ) {
6751 + return true;
6752 + }
6753 +
6754 + var show = false;
6755 + var editable = document.getElementById( 'editable' );
6756 + if ( editable !== null ) {
6757 + show = editable.checked && jQuery( document.getElementById( 'edit_action' ) ).val() === 'message';
6758 + if ( ! show ) {
6759 + show = isChecked( 'save_draft' );
6760 + }
6761 + }
6762 + return show;
6763 + }
6764 +
6765 + function checkDupPost() {
6766 + /*jshint validthis:true */
6767 + var postField = jQuery( 'select.frm_single_post_field' );
6768 + postField.css( 'border-color', '' );
6769 + var $t = this;
6770 + var v = jQuery( $t ).val();
6771 + if ( v === '' || v === 'checkbox' ) {
6772 + return false;
6773 + }
6774 + postField.each( function() {
6775 + if ( jQuery( this ).val() === v && this.name !== $t.name ) {
6776 + this.style.borderColor = 'red';
6777 + jQuery( $t ).val( '' );
6778 + infoModal( frm_admin_js.field_already_used );
6779 + return false;
6780 + }
6781 + });
6782 + }
6783 +
6784 + function togglePostContent() {
6785 + /*jshint validthis:true */
6786 + var v = jQuery( this ).val();
6787 + if ( '' === v ) {
6788 + jQuery( '.frm_post_content_opt, select.frm_dyncontent_opt' ).hide().val( '' );
6789 + jQuery( '.frm_dyncontent_opt' ).hide();
6790 + } else if ( 'post_content' === v ) {
6791 + jQuery( '.frm_post_content_opt' ).show();
6792 + jQuery( '.frm_dyncontent_opt' ).hide();
6793 + jQuery( 'select.frm_dyncontent_opt' ).val( '' );
6794 + } else {
6795 + jQuery( '.frm_post_content_opt' ).hide().val( '' );
6796 + jQuery( 'select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt' ).show();
6797 + }
6798 + }
6799 +
6800 + function fillDyncontent() {
6801 + /*jshint validthis:true */
6802 + var v = jQuery( this ).val();
6803 + var $dyn = jQuery( document.getElementById( 'frm_dyncontent' ) );
6804 + if ( '' === v || 'new' === v ) {
6805 + $dyn.val( '' );
6806 + jQuery( '.frm_dyncontent_opt' ).show();
6807 + } else {
6808 + jQuery.ajax({
6809 + type: 'POST', url: ajaxurl,
6810 + data: {action: 'frm_display_get_content', id: v, nonce: frmGlobal.nonce},
6811 + success: function( val ) {
6812 + $dyn.val( val );
6813 + jQuery( '.frm_dyncontent_opt' ).show();
6814 + }
6815 + });
6816 + }
6817 + }
6818 +
6819 + function switchPostType() {
6820 + /*jshint validthis:true */
6821 + // update all rows of categories/taxonomies
6822 + var curSelect, newSelect,
6823 + catRows = document.getElementById( 'frm_posttax_rows' ).childNodes,
6824 + postParentField = document.querySelector( '.frm_post_parent_field' ),
6825 + postMenuOrderField = document.querySelector( '.frm_post_menu_order_field' ),
6826 + postType = this.value;
6827 +
6828 + // Get new category/taxonomy options
6829 + jQuery.ajax({
6830 + type: 'POST',
6831 + url: ajaxurl,
6832 + data: {
6833 + action: 'frm_replace_posttax_options',
6834 + post_type: postType,
6835 + nonce: frmGlobal.nonce
6836 + },
6837 + success: function( html ) {
6838 +
6839 + // Loop through each category row, and replace the first dropdown
6840 + for ( i = 0; i < catRows.length; i++ ) {
6841 + // Check if current element is a div
6842 + if ( catRows[i].tagName !== 'DIV' ) {
6843 + continue;
6844 + }
6845 +
6846 + // Get current category select
6847 + curSelect = catRows[i].getElementsByTagName( 'select' )[0];
6848 +
6849 + // Set up new select
6850 + newSelect = document.createElement( 'select' );
6851 + newSelect.innerHTML = html;
6852 + newSelect.className = curSelect.className;
6853 + newSelect.name = curSelect.name;
6854 +
6855 + // Replace the old select with the new select
6856 + catRows[i].replaceChild( newSelect, curSelect );
6857 + }
6858 + }
6859 + });
6860 +
6861 + // Get new post parent option.
6862 + if ( postParentField ) {
6863 + getActionOption(
6864 + postParentField,
6865 + postType,
6866 + 'frm_get_post_parent_option',
6867 + function( response, optName ) {
6868 + // The replaced string is declared in FrmProFormActionController::ajax_get_post_menu_order_option() in the pro version.
6869 + postParentField.querySelector( '.frm_post_parent_opt_wrapper' ).innerHTML = response.replaceAll( 'REPLACETHISNAME', optName );
6870 + frmDom.autocomplete.initAutocomplete( 'page', postParentField );
6871 + }
6872 + );
6873 + }
6874 +
6875 + if ( postMenuOrderField ) {
6876 + getActionOption( postMenuOrderField, postType, 'frm_should_use_post_menu_order_option' );
6877 + }
6878 + }
6879 +
6880 + function getActionOption( field, postType, action, successHandler ) {
6881 + const opt = field.querySelector( '.frm_autocomplete_value_input' ) || field.querySelector( 'select' ),
6882 + optName = opt.getAttribute( 'name' );
6883 +
6884 + jQuery.ajax({
6885 + url: ajaxurl,
6886 + method: 'POST',
6887 + data: {
6888 + action: action,
6889 + post_type: postType,
6890 + _wpnonce: frmGlobal.nonce
6891 + },
6892 + success: response => {
6893 + if ( 'string' !== typeof response ) {
6894 + console.error( response );
6895 + return;
6896 + }
6897 +
6898 + if ( '0' === response ) {
6899 + // This post type does not support this field.
6900 + field.classList.add( 'frm_hidden' );
6901 + field.value = '';
6902 + return;
6903 + }
6904 +
6905 + field.classList.remove( 'frm_hidden' );
6906 +
6907 + if ( 'function' === typeof successHandler ) {
6908 + successHandler( response, optName );
6909 + }
6910 + },
6911 + error: response => console.error( response )
6912 + });
6913 + }
6914 +
6915 + function addPosttaxRow() {
6916 + /*jshint validthis:true */
6917 + addPostRow( 'tax', this );
6918 + }
6919 +
6920 + function addPostmetaRow() {
6921 + /*jshint validthis:true */
6922 + addPostRow( 'meta', this );
6923 + }
6924 +
6925 + function addPostRow( type, button ) {
6926 + var name,
6927 + id = jQuery( 'input[name="id"]' ).val(),
6928 + settings = jQuery( button ).closest( '.frm_form_action_settings' ),
6929 + key = settings.data( 'actionkey' ),
6930 + postType = settings.find( '.frm_post_type' ).val(),
6931 + metaName = 0,
6932 + postTypeRows = document.querySelectorAll( '.frm_post' + type + '_row' );
6933 +
6934 + if ( postTypeRows.length ) {
6935 + name = postTypeRows[ postTypeRows.length - 1 ].id.replace( 'frm_post' + type + '_', '' );
6936 + if ( isNumeric( name ) ) {
6937 + metaName = 1 + parseInt( name, 10 );
6938 + } else {
6939 + metaName = 1;
6940 + }
6941 + }
6942 +
6943 + jQuery.ajax({
6944 + type: 'POST', url: ajaxurl,
6945 + data: {
6946 + action: 'frm_add_post' + type + '_row',
6947 + form_id: id,
6948 + meta_name: metaName,
6949 + tax_key: metaName,
6950 + post_type: postType,
6951 + action_key: key,
6952 + nonce: frmGlobal.nonce
6953 + },
6954 + success: function( html ) {
6955 + var cfOpts, optIndex;
6956 + jQuery( document.getElementById( 'frm_post' + type + '_rows' ) ).append( html );
6957 + jQuery( '.frm_add_post' + type + '_row.button' ).hide();
6958 +
6959 + if ( type === 'meta' ) {
6960 + jQuery( '.frm_name_value' ).show();
6961 + cfOpts = document.querySelectorAll( '.frm_toggle_cf_opts' );
6962 + for ( optIndex = 0; optIndex < cfOpts.length - 1; ++optIndex ) {
6963 + cfOpts[ optIndex ].style.display = 'none';
6964 + }
6965 + } else if ( type === 'tax' ) {
6966 + jQuery( '.frm_posttax_labels' ).show();
6967 + }
6968 + }
6969 + });
6970 + }
6971 +
6972 + function isNumeric( value ) {
6973 + return ! isNaN( parseFloat( value ) ) && isFinite( value );
6974 + }
6975 +
6976 + function getMetaValue( id, metaName ) {
6977 + var newMeta = metaName;
6978 + if ( jQuery( document.getElementById( id + metaName ) ).length > 0 ) {
6979 + newMeta = getMetaValue( id, metaName + 1 );
6980 + }
6981 + return newMeta;
6982 + }
6983 +
6984 + function changePosttaxRow() {
6985 + /*jshint validthis:true */
6986 + if ( ! jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).length ) {
6987 + return;
6988 + }
6989 +
6990 + jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).html( '<div class="spinner frm_spinner" style="display:block"></div>' );
6991 +
6992 + var postType = jQuery( this ).closest( '.frm_form_action_settings' ).find( 'select[name$="[post_content][post_type]"]' ).val(),
6993 + actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ),
6994 + taxKey = jQuery( this ).closest( '.frm_posttax_row' ).attr( 'id' ).replace( 'frm_posttax_', '' ),
6995 + metaName = jQuery( this ).val(),
6996 + showExclude = jQuery( document.getElementById( taxKey + '_show_exclude' ) ).is( ':checked' ) ? 1 : 0,
6997 + fieldId = jQuery( 'select[name$="[post_category][' + taxKey + '][field_id]"]' ).val(),
6998 + id = jQuery( 'input[name="id"]' ).val();
6999 +
7000 + jQuery.ajax({
7001 + type: 'POST',
7002 + url: ajaxurl,
7003 + data: {
7004 + action: 'frm_add_posttax_row',
7005 + form_id: id,
7006 + post_type: postType,
7007 + tax_key: taxKey,
7008 + action_key: actionKey,
7009 + meta_name: metaName,
7010 + field_id: fieldId,
7011 + show_exclude: showExclude,
7012 + nonce: frmGlobal.nonce
7013 + },
7014 + success: function( html ) {
7015 + var $tax = jQuery( document.getElementById( 'frm_posttax_' + taxKey ) );
7016 + $tax.replaceWith( html );
7017 + }
7018 + });
7019 + }
7020 +
7021 + function toggleCfOpts() {
7022 + /*jshint validthis:true */
7023 + var row = jQuery( this ).closest( '.frm_postmeta_row' );
7024 + var cancel = row.find( '.frm_cancelnew' );
7025 + var select = row.find( '.frm_enternew' );
7026 + if ( row.find( 'select.frm_cancelnew' ).is( ':visible' ) ) {
7027 + cancel.hide();
7028 + select.show();
7029 + } else {
7030 + cancel.show();
7031 + select.hide();
7032 + }
7033 +
7034 + row.find( 'input.frm_enternew, select.frm_cancelnew' ).val( '' );
7035 + return false;
7036 + }
7037 +
7038 + function toggleFormOpts() {
7039 + /*jshint validthis:true */
7040 + var changedOpt = jQuery( this );
7041 + var val = changedOpt.val();
7042 + if ( changedOpt.attr( 'type' ) === 'checkbox' ) {
7043 + if ( this.checked === false ) {
7044 + val = '';
7045 + }
7046 + }
7047 +
7048 + var toggleClass = changedOpt.data( 'toggleclass' );
7049 + if ( val === '' ) {
7050 + jQuery( '.' + toggleClass ).hide();
7051 + } else {
7052 + jQuery( '.' + toggleClass ).show();
7053 + jQuery( '.hide_' + toggleClass + '_' + val ).hide();
7054 + }
7055 + }
7056 +
7057 + function submitSettings() {
7058 + /*jshint validthis:true */
7059 + preFormSave( this );
7060 + triggerSubmit( document.querySelector( '.frm_form_settings' ) );
7061 + }
7062 +
7063 + /* View Functions */
7064 + function showCount() {
7065 + /*jshint validthis:true */
7066 + var value = jQuery( this ).val();
7067 +
7068 + var $cont = document.getElementById( 'date_select_container' );
7069 + var tab = document.getElementById( 'frm_listing_tab' );
7070 + var label = tab.getAttribute( 'data-label' );
7071 + if ( value === 'calendar' ) {
7072 + jQuery( '.hide_dyncontent, .hide_single_content' ).removeClass( 'frm_hidden' );
7073 + jQuery( '.limit_container' ).addClass( 'frm_hidden' );
7074 + $cont.style.display = 'block';
7075 + } else if ( value === 'dynamic' ) {
7076 + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).removeClass( 'frm_hidden' );
7077 + } else if ( value === 'one' ) {
7078 + label = tab.getAttribute( 'data-one' );
7079 + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).addClass( 'frm_hidden' );
7080 + } else {
7081 + jQuery( '.hide_dyncontent' ).addClass( 'frm_hidden' );
7082 + jQuery( '.limit_container, .hide_single_content' ).removeClass( 'frm_hidden' );
7083 + }
7084 +
7085 + if ( value !== 'calendar' ) {
7086 + $cont.style.display = 'none';
7087 + }
7088 + tab.innerHTML = label;
7089 + }
7090 +
7091 + function displayFormSelected() {
7092 + /*jshint validthis:true */
7093 + var formId = jQuery( this ).val();
7094 + thisFormId = formId; // set the global form id
7095 + if ( formId === '' ) {
7096 + return;
7097 + }
7098 +
7099 + jQuery.ajax({
7100 + type: 'POST',
7101 + url: ajaxurl,
7102 + data: {
7103 + action: 'frm_get_cd_tags_box',
7104 + form_id: formId,
7105 + nonce: frmGlobal.nonce
7106 + },
7107 + success: function( html ) {
7108 + jQuery( '#frm_adv_info .categorydiv' ).html( html );
7109 + }
7110 + });
7111 +
7112 + jQuery.ajax({
7113 + type: 'POST',
7114 + url: ajaxurl,
7115 + data: {
7116 + action: 'frm_get_date_field_select',
7117 + form_id: formId,
7118 + nonce: frmGlobal.nonce
7119 + },
7120 + success: function( html ) {
7121 + jQuery( document.getElementById( 'date_select_container' ) ).html( html );
7122 + }
7123 + });
7124 + }
7125 +
7126 + function clickTabsAfterAjax() {
7127 + /*jshint validthis:true */
7128 + var t = jQuery( this ).attr( 'href' );
7129 + jQuery( this ).parent().addClass( 'tabs' ).siblings( 'li' ).removeClass( 'tabs' );
7130 + jQuery( t ).show().siblings( '.tabs-panel' ).hide();
7131 + return false;
7132 + }
7133 +
7134 + function clickContentTab() {
7135 + /*jshint validthis:true */
7136 + link = jQuery( this );
7137 + var t = link.attr( 'href' );
7138 + if ( typeof t === 'undefined' ) {
7139 + return false;
7140 + }
7141 +
7142 + var c = t.replace( '#', '.' );
7143 + link.closest( '.nav-tab-wrapper' ).find( 'a' ).removeClass( 'nav-tab-active' );
7144 + link.addClass( 'nav-tab-active' );
7145 + jQuery( '.nav-menu-content' ).not( t ).not( c ).hide();
7146 + jQuery( t + ',' + c ).show();
7147 +
7148 + return false;
7149 + }
7150 +
7151 + function addOrderRow() {
7152 + var logicRows = document.getElementById( 'frm_order_options' ).querySelectorAll( '.frm_logic_rows div' );
7153 + jQuery.ajax({
7154 + type: 'POST',
7155 + url: ajaxurl,
7156 + data: {
7157 + action: 'frm_add_order_row',
7158 + form_id: thisFormId,
7159 + order_key: getNewRowId( logicRows, 'frm_order_field_', 1 ),
7160 + nonce: frmGlobal.nonce
7161 + },
7162 + success: function( html ) {
7163 + jQuery( '#frm_order_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_order_row' ).hide();
7164 + }
7165 + });
7166 + }
7167 +
7168 + function addWhereRow() {
7169 + var rowDivs = document.getElementById( 'frm_where_options' ).querySelectorAll( '.frm_logic_rows div' );
7170 + jQuery.ajax({
7171 + type: 'POST',
7172 + url: ajaxurl,
7173 + data: {
7174 + action: 'frm_add_where_row',
7175 + form_id: thisFormId,
7176 + where_key: getNewRowId( rowDivs, 'frm_where_field_', 1 ),
7177 + nonce: frmGlobal.nonce
7178 + },
7179 + success: function( html ) {
7180 + jQuery( '#frm_where_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_where_row' ).hide();
7181 + }
7182 + });
7183 + }
7184 +
7185 + function insertWhereOptions() {
7186 + /*jshint validthis:true */
7187 + var value = this.value,
7188 + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' );
7189 +
7190 + jQuery.ajax({
7191 + type: 'POST',
7192 + url: ajaxurl,
7193 + data: {
7194 + action: 'frm_add_where_options',
7195 + where_key: whereKey,
7196 + field_id: value,
7197 + nonce: frmGlobal.nonce
7198 + },
7199 + success: function( html ) {
7200 + jQuery( document.getElementById( 'where_field_options_' + whereKey ) ).html( html );
7201 + }
7202 + });
7203 + }
7204 +
7205 + function hideWhereOptions() {
7206 + /*jshint validthis:true */
7207 + var value = this.value,
7208 + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' );
7209 +
7210 + if ( value === 'group_by' || value === 'group_by_newest' ) {
7211 + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'none';
7212 + } else {
7213 + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'inline-block';
7214 + }
7215 + }
7216 +
7217 + function setDefaultPostStatus() {
7218 + var urlQuery = window.location.search.substring( 1 );
7219 + if ( urlQuery.indexOf( 'action=edit' ) === -1 ) {
7220 + document.getElementById( 'post-visibility-display' ).innerHTML = frm_admin_js.private_label;
7221 + document.getElementById( 'hidden-post-visibility' ).value = 'private';
7222 + document.getElementById( 'visibility-radio-private' ).checked = true;
7223 + }
7224 + }
7225 +
7226 + /* Customization Panel */
7227 + function insertCode( e ) {
7228 + /*jshint validthis:true */
7229 + e.preventDefault();
7230 + insertFieldCode( jQuery( this ), this.getAttribute( 'data-code' ) );
7231 + return false;
7232 + }
7233 +
7234 + function insertFieldCode( element, variable ) {
7235 + var rich = false,
7236 + elementId = element;
7237 + if ( typeof element === 'object' ) {
7238 + if ( element.hasClass( 'frm_noallow' ) ) {
7239 + return;
7240 + }
7241 +
7242 + elementId = jQuery( element ).closest( '[data-fills]' ).attr( 'data-fills' );
7243 + if ( typeof elementId === 'undefined' ) {
7244 + elementId = element.closest( 'div' ).attr( 'class' );
7245 + if ( typeof elementId !== 'undefined' ) {
7246 + elementId = elementId.split( ' ' )[1];
7247 + }
7248 + }
7249 + }
7250 +
7251 + if ( typeof elementId === 'undefined' ) {
7252 + var active = document.activeElement;
7253 + if ( active.type === 'search' ) {
7254 + // If the search field has focus, find the correct field.
7255 + elementId = active.id.replace( '-search-input', '' );
7256 + if ( elementId.match( /\d/gi ) === null ) {
7257 + active = jQuery( '.frm-single-settings:visible .' + elementId );
7258 + elementId = active.attr( 'id' );
7259 + }
7260 + } else {
7261 + elementId = active.id;
7262 + }
7263 + }
7264 +
7265 + if ( elementId ) {
7266 + rich = jQuery( '#wp-' + elementId + '-wrap.wp-editor-wrap' ).length > 0;
7267 + }
7268 +
7269 + var contentBox = jQuery( document.getElementById( elementId ) );
7270 + if ( typeof element.attr( 'data-shortcode' ) === 'undefined' && ( ! contentBox.length || typeof contentBox.attr( 'data-shortcode' ) === 'undefined' ) ) {
7271 + // this helps to exclude those that don't want shortcode-like inserted content e.g. frm-pro's summary field
7272 + var doShortcode = element.parents( 'ul.frm_code_list' ).attr( 'data-shortcode' );
7273 + if ( doShortcode === 'undefined' || doShortcode !== 'no' ) {
7274 + variable = '[' + variable + ']';
7275 + }
7276 + }
7277 +
7278 + if ( rich ) {
7279 + wpActiveEditor = elementId;
7280 + }
7281 +
7282 + if ( ! contentBox.length ) {
7283 + return false;
7284 + }
7285 +
7286 + if ( variable === '[default-html]' || variable === '[default-plain]' ) {
7287 + var p = 0;
7288 + if ( variable === '[default-plain]' ) {
7289 + p = 1;
7290 + }
7291 + jQuery.ajax({
7292 + type: 'POST', url: ajaxurl,
7293 + data: {
7294 + action: 'frm_get_default_html',
7295 + form_id: jQuery( 'input[name="id"]' ).val(),
7296 + plain_text: p,
7297 + nonce: frmGlobal.nonce
7298 + },
7299 + elementId: elementId,
7300 + success: function( msg ) {
7301 + if ( rich ) {
7302 + let p = document.createElement( 'p' );
7303 + p.innerText = msg;
7304 + send_to_editor( p.innerHTML );
7305 + } else {
7306 + insertContent( contentBox, msg );
7307 + }
7308 + }
7309 + });
7310 + } else {
7311 + variable = maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox );
7312 + if ( rich ) {
7313 + send_to_editor( variable );
7314 + } else {
7315 + insertContent( contentBox, variable );
7316 + }
7317 + }
7318 + return false;
7319 + }
7320 +
7321 + function maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox ) {
7322 + if ( 'object' !== typeof element || ! ( element instanceof jQuery ) || 'success_url' !== contentBox[0].id ) {
7323 + return variable;
7324 + }
7325 +
7326 + element = element[0];
7327 + if ( ! element.closest( '#frm-insert-fields-box' ) ) {
7328 + // Only add sanitize_url=1 to field shortcodes.
7329 + return variable;
7330 + }
7331 +
7332 + if ( ! element.parentNode.classList.contains( 'frm_insert_url' ) ) {
7333 + variable = variable.replace( ']', ' sanitize_url=1]' );
7334 + }
7335 +
7336 + return variable;
7337 + }
7338 +
7339 + function insertContent( contentBox, variable ) {
7340 + if ( document.selection ) {
7341 + contentBox[0].focus();
7342 + document.selection.createRange().text = variable;
7343 + } else {
7344 + obj = contentBox[0];
7345 + var e = obj.selectionEnd;
7346 +
7347 + variable = maybeFormatInsertedContent( contentBox, variable, obj.selectionStart, e );
7348 +
7349 + obj.value = obj.value.substr( 0, obj.selectionStart ) + variable + obj.value.substr( obj.selectionEnd, obj.value.length );
7350 + var s = e + variable.length;
7351 + obj.focus();
7352 + obj.setSelectionRange( s, s );
7353 + }
7354 + triggerChange( contentBox );
7355 + }
7356 +
7357 + function maybeFormatInsertedContent( input, textToInsert, selectionStart, selectionEnd ) {
7358 + var separator = input.data( 'sep' );
7359 + if ( undefined === separator ) {
7360 + return textToInsert;
7361 + }
7362 +
7363 + var value = input.val();
7364 +
7365 + if ( ! value.trim().length ) {
7366 + return textToInsert;
7367 + }
7368 +
7369 + var startPattern = new RegExp( separator + '\\s*$' );
7370 + var endPattern = new RegExp( '^\\s*' + separator );
7371 +
7372 + if ( value.substr( 0, selectionStart ).trim().length && false === startPattern.test( value.substr( 0, selectionStart ) ) ) {
7373 + textToInsert = separator + textToInsert;
7374 + }
7375 +
7376 + if ( value.substr( selectionEnd, value.length ).trim().length && false === endPattern.test( value.substr( selectionEnd, value.length ) ) ) {
7377 + textToInsert += separator;
7378 + }
7379 +
7380 + return textToInsert;
7381 + }
7382 +
7383 + function resetLogicBuilder() {
7384 + /*jshint validthis:true */
7385 + var id = document.getElementById( 'frm-id-condition' ),
7386 + key = document.getElementById( 'frm-key-condition' );
7387 +
7388 + if ( this.checked ) {
7389 + id.classList.remove( 'frm_hidden' );
7390 + key.classList.add( 'frm_hidden' );
7391 + triggerEvent( key, 'change' );
7392 + } else {
7393 + id.classList.add( 'frm_hidden' );
7394 + key.classList.remove( 'frm_hidden' );
7395 + triggerEvent( id, 'change' );
7396 + }
7397 + }
7398 +
7399 + function setLogicExample() {
7400 + var field, code,
7401 + idKey = document.getElementById( 'frm-id-key-condition' ).checked ? 'frm-id-condition' : 'frm-key-condition',
7402 + is = document.getElementById( 'frm-is-condition' ).value,
7403 + text = document.getElementById( 'frm-text-condition' ).value,
7404 + result = document.getElementById( 'frm-insert-condition' );
7405 +
7406 + idKey = document.getElementById( idKey );
7407 + field = idKey.options[idKey.selectedIndex].value;
7408 + code = 'if ' + field + ' ' + is + '="' + text + '"]';
7409 + result.setAttribute( 'data-code', code + frm_admin_js.conditional_text + '[/if ' + field );
7410 + result.innerHTML = '[' + code + '[/if ' + field + ']';
7411 + }
7412 +
7413 + function showBuilderModal() {
7414 + /*jshint validthis:true */
7415 + var moreIcon = getIconForInput( this );
7416 + showInlineModal( moreIcon, this );
7417 + }
7418 +
7419 + function maybeShowModal( input ) {
7420 + var moreIcon;
7421 + if ( input.parentNode.parentNode.classList.contains( 'frm_has_shortcodes' ) ) {
7422 + hideShortcodes();
7423 + moreIcon = getIconForInput( input );
7424 + if ( moreIcon.tagName === 'use' ) {
7425 + moreIcon = moreIcon.firstElementChild;
7426 + if ( moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ).indexOf( 'frm_close_icon' ) === -1 ) {
7427 + showShortcodeBox( moreIcon, 'nofocus' );
7428 + }
7429 + } else if ( ! moreIcon.classList.contains( 'frm_close_icon' ) ) {
7430 + showShortcodeBox( moreIcon, 'nofocus' );
7431 + }
7432 + }
7433 + }
7434 +
7435 + function showShortcodes( e ) {
7436 + /*jshint validthis:true */
7437 + e.preventDefault();
7438 + e.stopPropagation();
7439 +
7440 + showShortcodeBox( this );
7441 + }
7442 +
7443 + function showShortcodeBox( moreIcon, shouldFocus ) {
7444 + var pos = moreIcon.getBoundingClientRect(),
7445 + input = getInputForIcon( moreIcon ),
7446 + box = document.getElementById( 'frm_adv_info' ),
7447 + classes = moreIcon.className,
7448 + parentPos = box.parentElement.getBoundingClientRect();
7449 +
7450 + if ( moreIcon.tagName === 'svg' ) {
7451 + moreIcon = moreIcon.firstElementChild;
7452 + }
7453 + if ( moreIcon.tagName === 'use' ) {
7454 + classes = moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' );
7455 + }
7456 +
7457 + if ( classes.indexOf( 'frm_close_icon' ) !== -1 ) {
7458 + hideShortcodes( box );
7459 + } else {
7460 + box.style.top = ( pos.top - parentPos.top + 32 ) + 'px';
7461 + box.style.left = ( pos.left - parentPos.left - 257 ) + 'px';
7462 +
7463 + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' );
7464 + if ( input.classList.contains( 'frm_not_email_to' ) ) {
7465 + jQuery( '#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a' ).addClass( 'frm_noallow' );
7466 + } else if ( input.classList.contains( 'frm_not_email_subject' ) ) {
7467 + jQuery( '.frm_code_list li.hide_frm_not_email_subject a' ).addClass( 'frm_noallow' );
7468 + }
7469 +
7470 + box.setAttribute( 'data-fills', input.id );
7471 + box.style.display = 'block';
7472 +
7473 + if ( moreIcon.tagName === 'use' ) {
7474 + moreIcon.setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_close_icon' );
7475 + } else {
7476 + moreIcon.className = classes.replace( 'frm_more_horiz_solid_icon', 'frm_close_icon' );
7477 + }
7478 +
7479 + if ( shouldFocus !== 'nofocus' ) {
7480 + if ( 'none' !== input.style.display ) {
7481 + input.focus();
7482 + } else {
7483 + jQuery( tinymce.get( input.id ) ).trigger( 'focus' );
7484 + }
7485 + }
7486 + }
7487 + }
7488 +
7489 + function fieldUpdated() {
7490 + if ( ! fieldsUpdated ) {
7491 + fieldsUpdated = 1;
7492 + window.addEventListener( 'beforeunload', confirmExit );
7493 + }
7494 + }
7495 +
7496 + function buildSubmittedNoAjax() {
7497 + // set fieldsUpdated to 0 to avoid the unsaved changes pop up
7498 + fieldsUpdated = 0;
7499 + }
7500 +
7501 + function settingsSubmitted() {
7502 + // set fieldsUpdated to 0 to avoid the unsaved changes pop up
7503 + fieldsUpdated = 0;
7504 + }
7505 +
7506 + function saveAndReloadSettings() {
7507 + var page, form;
7508 + page = document.getElementById( 'form_settings_page' );
7509 + if ( null !== page ) {
7510 + form = page.querySelector( 'form.frm_form_settings' );
7511 + if ( null !== form ) {
7512 + fieldsUpdated = 0;
7513 + form.submit();
7514 + }
7515 + }
7516 + }
7517 +
7518 + function saveAndReloadFormBuilder() {
7519 + document.getElementById( 'frm_submit_side_top' ).click();
7520 + }
7521 +
7522 + function confirmExit( event ) {
7523 + if ( fieldsUpdated ) {
7524 + event.preventDefault();
7525 + event.returnValue = '';
7526 + }
7527 + }
7528 +
7529 + function bindClickForDialogClose( $modal ) {
7530 + const closeModal = function() {
7531 + $modal.dialog( 'close' );
7532 + };
7533 + jQuery( '.ui-widget-overlay' ).on( 'click', closeModal );
7534 + $modal.on( 'click', 'a.dismiss', closeModal );
7535 + }
7536 +
7537 + function triggerNewFormModal( event ) {
7538 + var $modal,
7539 + dismiss = document.getElementById( 'frm_new_form_modal' ).querySelector( 'a.dismiss' );
7540 +
7541 + if ( typeof event !== 'undefined' ) {
7542 + event.preventDefault();
7543 + }
7544 +
7545 + dismiss.setAttribute( 'tabindex', -1 );
7546 +
7547 + $modal = initModal( '#frm_new_form_modal', '600px' );
7548 + offsetModalY( $modal, '50px' );
7549 + $modal.attr( 'frm-page', 'create' );
7550 + $modal.find( '#template-search-input' ).val( '' ).trigger( 'change' );
7551 + $modal.dialog( 'open' );
7552 +
7553 + dismiss.removeAttribute( 'tabindex' );
7554 + bindClickForDialogClose( $modal );
7555 +
7556 + addApplicationsToNewFormModal( $modal.get( 0 ) );
7557 + }
7558 +
7559 + function addApplicationsToNewFormModal( modal ) {
7560 + if ( modal.querySelector( '.frm-ready-made-solution' ) ) {
7561 + // Avoid adding duplicates if the modal is opened multiple times.
7562 + return;
7563 + }
7564 +
7565 + if ( ! frmGlobal.canAccessApplicationDashboard ) {
7566 + // User does not have privileges to see Ready Made Solutions.
7567 + return;
7568 + }
7569 +
7570 + doJsonFetch( 'get_applications_data&view=templates' ).then( addTemplatesOnFetchSuccess );
7571 +
7572 + const categoryList = modal.querySelector( 'ul.frm-categories-list' );
7573 +
7574 + function addTemplatesOnFetchSuccess( data ) {
7575 + data.templates.forEach( addTemplateToCategoryList );
7576 + }
7577 +
7578 + function addTemplateToCategoryList( template ) {
7579 + categoryList.insertBefore( getReadyMadeSolution( template ), categoryList.firstChild );
7580 + }
7581 +
7582 + function getReadyMadeSolution( template ) {
7583 + const image = tag( 'img' );
7584 + const thumbnailFolderUrl = frmGlobal.url + '/images/applications/thumbnails/';
7585 + const filenameToUse = template.hasLiteThumbnail ? template.key + '.png' : 'placeholder.svg';
7586 + image.setAttribute( 'src', thumbnailFolderUrl + filenameToUse );
7587 +
7588 + const imageWrapper = div({ child: image });
7589 + imageWrapper.style.textAlign = 'center';
7590 +
7591 + return tag(
7592 + 'li',
7593 + {
7594 + className: 'frm-searchable-template frm-ready-made-solution',
7595 + children: [
7596 + imageWrapper,
7597 + div({
7598 + children: [
7599 + span( __( 'Ready Made Solution', 'formidable' ) ),
7600 + tag( 'h3', template.name ),
7601 + a({
7602 + text: __( 'Check all applications', 'formidable' ),
7603 + href: frmGlobal.applicationsUrl
7604 + })
7605 + ]
7606 + }),
7607 + div({
7608 + className: 'frm-hover-icons',
7609 + child: a({
7610 + child: svg({ href: '#frm_plus_icon' }),
7611 + href: frmGlobal.applicationsUrl + '&triggerViewApplicationModal=1&template=' + template.key
7612 + })
7613 + })
7614 + ]
7615 + }
7616 + );
7617 + }
7618 + }
7619 +
7620 + function offsetModalY( $modal, amount ) {
7621 + const position = {
7622 + my: 'top',
7623 + at: 'top+' + amount,
7624 + of: window
7625 + };
7626 + $modal.dialog( 'option', 'position', position );
7627 + }
7628 +
7629 + /**
7630 + * Get the input box for the selected ... icon.
7631 + */
7632 + function getInputForIcon( moreIcon ) {
7633 + var input = moreIcon.nextElementSibling;
7634 +
7635 + while ( input !== null && input.tagName !== 'INPUT' && input.tagName !== 'TEXTAREA' ) {
7636 + input = getInputForIcon( input );
7637 + }
7638 +
7639 + return input;
7640 + }
7641 +
7642 + /**
7643 + * Get the ... icon for the selected input box.
7644 + */
7645 + function getIconForInput( input ) {
7646 + var moreIcon = input.previousElementSibling;
7647 +
7648 + while ( moreIcon !== null && moreIcon.tagName !== 'I' && moreIcon.tagName !== 'svg' ) {
7649 + moreIcon = getIconForInput( moreIcon );
7650 + }
7651 +
7652 + return moreIcon;
7653 + }
7654 +
7655 + function hideShortcodes( box ) {
7656 + var i, u, closeIcons, closeSvg;
7657 + if ( typeof box === 'undefined' ) {
7658 + box = document.getElementById( 'frm_adv_info' );
7659 + if ( box === null ) {
7660 + return;
7661 + }
7662 + }
7663 +
7664 + if ( document.getElementById( 'frm_dyncontent' ) !== null ) {
7665 + // Don't run when in the sidebar.
7666 + return;
7667 + }
7668 +
7669 + box.style.display = 'none';
7670 +
7671 + closeIcons = document.querySelectorAll( '.frm-show-box.frm_close_icon' );
7672 + for ( i = 0; i < closeIcons.length; i++ ) {
7673 + closeIcons[i].classList.remove( 'frm_close_icon' );
7674 + closeIcons[i].classList.add( 'frm_more_horiz_solid_icon' );
7675 + }
7676 +
7677 + closeSvg = document.querySelectorAll( '.frm_has_shortcodes use' );
7678 + for ( u = 0; u < closeSvg.length; u++ ) {
7679 + if ( closeSvg[u].getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) === '#frm_close_icon' ) {
7680 + closeSvg[u].setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_more_horiz_solid_icon' );
7681 + }
7682 + }
7683 + }
7684 +
7685 + function initToggleShortcodes() {
7686 + if ( typeof tinymce !== 'object' ) {
7687 + return;
7688 + }
7689 +
7690 + DOM = tinymce.DOM;
7691 + if ( typeof DOM.events !== 'undefined' && typeof DOM.events.add !== 'undefined' ) {
7692 + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseover', function() {
7693 + if ( jQuery( '*:focus' ).length > 0 ) {
7694 + return;
7695 + }
7696 + if ( this.id ) {
7697 + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7698 + }
7699 + });
7700 + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseout', function() {
7701 + if ( jQuery( '*:focus' ).length > 0 ) {
7702 + return;
7703 + }
7704 + if ( this.id ) {
7705 + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7706 + }
7707 + });
7708 + } else {
7709 + jQuery( '#frm_dyncontent' ).on( 'mouseover mouseout', '.wp-editor-wrap', function() {
7710 + if ( jQuery( '*:focus' ).length > 0 ) {
7711 + return;
7712 + }
7713 + if ( this.id ) {
7714 + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7715 + }
7716 + });
7717 + }
7718 + }
7719 +
7720 + function toggleAllowedShortcodes( id ) {
7721 + var c, clickedID;
7722 + if ( typeof id === 'undefined' ) {
7723 + id = '';
7724 + }
7725 + c = id;
7726 +
7727 + if ( id.indexOf( '-search-input' ) !== -1 ) {
7728 + return;
7729 + }
7730 +
7731 + if ( id !== '' ) {
7732 + var $ele = jQuery( document.getElementById( id ) );
7733 + if ( $ele.attr( 'class' ) && id !== 'wpbody-content' && id !== 'content' && id !== 'dyncontent' && id !== 'success_msg' ) {
7734 + var d = $ele.attr( 'class' ).split( ' ' )[0];
7735 + if ( d === 'frm_long_input' || d === 'frm_98_width' || typeof d === 'undefined' ) {
7736 + d = '';
7737 + } else {
7738 + id = d.trim();
7739 + }
7740 + c = c + ' ' + d;
7741 + c = c.replace( 'widefat', '' ).replace( 'frm_with_left_label', '' );
7742 + }
7743 + }
7744 +
7745 + jQuery( '#frm-insert-fields-box,#frm-conditionals,#frm-adv-info-tab,#frm-dynamic-values' ).attr( 'data-fills', c.trim() );
7746 + var a = [
7747 + 'content', 'wpbody-content', 'dyncontent', 'success_url',
7748 + 'success_msg', 'edit_msg', 'frm_dyncontent', 'frm_not_email_message',
7749 + 'frm_not_email_subject'
7750 + ];
7751 + var b = [
7752 + 'before_content', 'after_content', 'frm_not_email_to',
7753 + 'dyn_default_value'
7754 + ];
7755 +
7756 + if ( jQuery.inArray( id, a ) >= 0 ) {
7757 + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' );
7758 + jQuery( '.frm_code_list a.hide_' + id ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7759 + } else if ( jQuery.inArray( id, b ) >= 0 ) {
7760 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a:not(.show_' + id + ')' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7761 + jQuery( '.frm_code_list a.show_' + id ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' );
7762 + } else {
7763 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7764 + }
7765 +
7766 + // Automatically select a tab.
7767 + if ( id === 'dyn_default_value' ) {
7768 + clickedID = 'frm_dynamic_values';
7769 + document.getElementById( clickedID + '_tab' ).click();
7770 + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_inactive' ).addClass( 'frm_hidden' );
7771 + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_active' ).removeClass( 'frm_hidden' );
7772 + }
7773 + }
7774 +
7775 + function toggleAllowedHTML( input ) {
7776 + var b,
7777 + id = input.id;
7778 + if ( typeof id === 'undefined' || id.indexOf( '-search-input' ) !== -1 ) {
7779 + return;
7780 + }
7781 +
7782 + jQuery( '#frm-adv-info-tab' ).attr( 'data-fills', id.trim() );
7783 + if ( input.classList.contains( 'field_custom_html' ) ) {
7784 + id = 'field_custom_html';
7785 + }
7786 +
7787 + b = [ 'after_html', 'before_html', 'submit_html', 'field_custom_html' ];
7788 + if ( jQuery.inArray( id, b ) >= 0 ) {
7789 + jQuery( '.frm_code_list li:not(.show_' + id + ')' ).addClass( 'frm_hidden' );
7790 + jQuery( '.frm_code_list li.show_' + id ).removeClass( 'frm_hidden' );
7791 + }
7792 + }
7793 +
7794 + function toggleKeyID( switchTo, e ) {
7795 + e.stopPropagation();
7796 + jQuery( '.frm_code_list .frmids, .frm_code_list .frmkeys' ).addClass( 'frm_hidden' );
7797 + jQuery( '.frm_code_list .' + switchTo ).removeClass( 'frm_hidden' );
7798 + jQuery( '.frmids, .frmkeys' ).removeClass( 'current' );
7799 + jQuery( '.' + switchTo ).addClass( 'current' );
7800 + }
7801 +
7802 + function onActionLoaded( event ) {
7803 + event.target.closest( '.frm_form_action_settings' ).querySelectorAll( '.frmsvg.frm-show-box' ).forEach( ( svg ) => {
7804 + if ( svg.nextElementSibling.type === 'text' ) {
7805 + svg.style.bottom = '-3px';
7806 + svg.style.marginRight = '0';
7807 + }
7808 + });
7809 +
7810 + const settings = event.target.closest( '.frm_form_action_settings' );
7811 + if ( settings && settings.classList.contains( 'frm_single_email_settings' ) ) {
7812 + onEmailActionLoaded( settings );
7813 + }
7814 + }
7815 +
7816 + function onEmailActionLoaded( settings ) {
7817 + const wysiwyg = settings.querySelector( '.wp-editor-area' );
7818 + if ( wysiwyg ) {
7819 + frmDom.wysiwyg.init(
7820 + wysiwyg, { height: 160, addFocusEvents: true }
7821 + );
7822 + }
7823 + }
7824 +
7825 + /* Styling */
7826 + function setPosClass() {
7827 + /*jshint validthis:true */
7828 + var value = this.value;
7829 + if ( value === 'none' ) {
7830 + value = 'top';
7831 + } else if ( value === 'no_label' ) {
7832 + value = 'none';
7833 + }
7834 +
7835 + document.querySelectorAll( '.frm_pos_container' ).forEach( container => {
7836 + // Fields that support floating label should have a directly child input/textarea/select.
7837 + const input = container.querySelector( ':scope > input, :scope > select, :scope > textarea' );
7838 +
7839 + if ( 'inside' === value && ! input ) {
7840 + value = 'top';
7841 + }
7842 +
7843 + container.classList.remove( 'frm_top_container', 'frm_left_container', 'frm_right_container', 'frm_none_container', 'frm_inside_container' );
7844 + container.classList.add( 'frm_' + value + '_container' );
7845 +
7846 + if ( 'inside' === value ) {
7847 + checkFloatingLabelsForStyles( input, container );
7848 + }
7849 + });
7850 + }
7851 +
7852 + function checkFloatingLabelsForStyles( input, container ) {
7853 + if ( ! container ) {
7854 + container = input.closest( '.frm_inside_container' );
7855 + }
7856 +
7857 + const shouldFloatTop = input.value || document.activeElement === input;
7858 +
7859 + container.classList.toggle( 'frm_label_float_top', shouldFloatTop );
7860 +
7861 + if ( 'SELECT' === input.tagName ) {
7862 + const firstOpt = input.querySelector( 'option:first-child' );
7863 +
7864 + if ( shouldFloatTop ) {
7865 + if ( firstOpt.hasAttribute( 'data-label' ) ) {
7866 + firstOpt.textContent = firstOpt.getAttribute( 'data-label' );
7867 + firstOpt.removeAttribute( 'data-label' );
7868 + }
7869 + } else {
7870 + if ( firstOpt.textContent ) {
7871 + firstOpt.setAttribute( 'data-label', firstOpt.textContent );
7872 + firstOpt.textContent = '';
7873 + }
7874 + }
7875 + }
7876 + }
7877 +
7878 + function collapseAllSections() {
7879 + jQuery( '.control-section.accordion-section.open' ).removeClass( 'open' );
7880 + }
7881 +
7882 + function textSquishCheck() {
7883 + var size = document.getElementById( 'frm_field_font_size' ).value.replace( /\D/g, '' );
7884 + var height = document.getElementById( 'frm_field_height' ).value.replace( /\D/g, '' );
7885 + var paddingEntered = document.getElementById( 'frm_field_pad' ).value.split( ' ' );
7886 + var paddingCount = paddingEntered.length;
7887 +
7888 + // If too many or too few padding entries, leave now
7889 + if ( paddingCount === 0 || paddingCount > 4 || height === '' ) {
7890 + return;
7891 + }
7892 +
7893 + // Get the top and bottom padding from entered values
7894 + var paddingTop = paddingEntered[0].replace( /\D/g, '' );
7895 + var paddingBottom = paddingTop;
7896 + if ( paddingCount >= 3 ) {
7897 + paddingBottom = paddingEntered[2].replace( /\D/g, '' );
7898 + }
7899 +
7900 + // Check if there is enough space for text
7901 + var textSpace = height - size - paddingTop - paddingBottom - 3;
7902 + if ( textSpace < 0 ) {
7903 + infoModal( frm_admin_js.css_invalid_size );
7904 + }
7905 + }
7906 +
7907 + /* Global settings page */
7908 + function loadSettingsTab( anchor ) {
7909 + var holder = anchor.replace( '#', '' );
7910 + var holderContainer = jQuery( '.frm_' + holder + '_ajax' );
7911 + if ( holderContainer.length ) {
7912 + jQuery.ajax({
7913 + type: 'POST', url: ajaxurl,
7914 + data: {
7915 + 'action': 'frm_settings_tab',
7916 + 'tab': holder.replace( '_settings', '' ),
7917 + 'nonce': frmGlobal.nonce
7918 + },
7919 + success: function( html ) {
7920 + holderContainer.replaceWith( html );
7921 + }
7922 + });
7923 + }
7924 + }
7925 +
7926 + function uninstallNow() {
7927 + /*jshint validthis:true */
7928 + if ( confirmLinkClick( this ) === true ) {
7929 + jQuery( '.frm_uninstall .frm-wait' ).css( 'visibility', 'visible' );
7930 + jQuery.ajax({
7931 + type: 'POST',
7932 + url: ajaxurl,
7933 + data: 'action=frm_uninstall&nonce=' + frmGlobal.nonce,
7934 + success: function( msg ) {
7935 + jQuery( '.frm_uninstall' ).fadeOut( 'slow' );
7936 + window.location = msg;
7937 + }
7938 + });
7939 + }
7940 + return false;
7941 + }
7942 +
7943 + function saveAddonLicense() {
7944 + /*jshint validthis:true */
7945 + var button = jQuery( this );
7946 + var buttonName = this.name;
7947 + var pluginSlug = this.getAttribute( 'data-plugin' );
7948 + var action = buttonName.replace( 'edd_' + pluginSlug + '_license_', '' );
7949 + var license = document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value;
7950 + jQuery.ajax({
7951 + type: 'POST', url: ajaxurl, dataType: 'json',
7952 + data: {action: 'frm_addon_' + action, license: license, plugin: pluginSlug, nonce: frmGlobal.nonce},
7953 + success: function( msg ) {
7954 + var thisRow = button.closest( '.edd_frm_license_row' );
7955 + if ( action === 'deactivate' ) {
7956 + license = '';
7957 + document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value = '';
7958 + }
7959 + thisRow.find( '.edd_frm_license' ).html( license );
7960 + if ( msg.success === true ) {
7961 + thisRow.find( '.frm_icon_font' ).removeClass( 'frm_hidden' );
7962 + thisRow.find( 'div.alignleft' ).toggleClass( 'frm_hidden', 1000 );
7963 + }
7964 +
7965 + var messageBox = thisRow.find( '.frm_license_msg' );
7966 + messageBox.html( msg.message );
7967 + if ( msg.message !== '' ) {
7968 + setTimeout( function() {
7969 + messageBox.html( '' );
7970 + }, 15000 );
7971 + }
7972 + }
7973 + });
7974 + }
7975 +
7976 + /* Import/Export page */
7977 +
7978 + function startFormMigration( event ) {
7979 + event.preventDefault();
7980 +
7981 + var checkedBoxes = jQuery( event.target ).find( 'input:checked' );
7982 + if ( ! checkedBoxes.length ) {
7983 + return;
7984 + }
7985 +
7986 + var ids = [];
7987 + checkedBoxes.each( function( i ) {
7988 + ids[i] = this.value;
7989 + });
7990 +
7991 + // Begin the import process.
7992 + importForms( ids, event.target );
7993 + }
7994 +
7995 + /**
7996 + * Begins the process of importing the forms.
7997 + */
7998 + function importForms( forms, targetForm ) {
7999 +
8000 + // Hide the form select section.
8001 + var $form = jQuery( targetForm ),
8002 + $processSettings = $form.next( '.frm-importer-process' );
8003 +
8004 + // Display total number of forms we have to import.
8005 + $processSettings.find( '.form-total' ).text( forms.length );
8006 + $processSettings.find( '.form-current' ).text( '1' );
8007 +
8008 + $form.hide();
8009 +
8010 + // Show processing status.
8011 + // '.process-completed' might have been shown earlier during a previous import, so hide now.
8012 + $processSettings.find( '.process-completed' ).hide();
8013 + $processSettings.show();
8014 +
8015 + // Create global import queue.
8016 + s.importQueue = forms;
8017 + s.imported = 0;
8018 +
8019 + // Import the first form in the queue.
8020 + importForm( $processSettings );
8021 + }
8022 +
8023 + /**
8024 + * Imports a single form from the import queue.
8025 + */
8026 + function importForm( $processSettings ) {
8027 + var formID = s.importQueue[0],
8028 + provider = $processSettings.closest( '.welcome-panel-content' ).find( 'input[name="slug"]' ).val(),
8029 + data = {
8030 + action: 'frm_import_' + provider,
8031 + form_id: formID,
8032 + nonce: frmGlobal.nonce
8033 + };
8034 +
8035 + // Trigger AJAX import for this form.
8036 + jQuery.post( ajaxurl, data, function( res ) {
8037 +
8038 + if ( res.success ) {
8039 + var statusUpdate;
8040 +
8041 + if ( res.data.error ) {
8042 + statusUpdate = '<p>' + res.data.name + ': ' + res.data.msg + '</p>';
8043 + } else {
8044 + statusUpdate = '<p>Imported <a href="' + res.data.link + '" target="_blank">' + res.data.name + '</a></p>';
8045 + }
8046 +
8047 + $processSettings.find( '.status' ).prepend( statusUpdate );
8048 + $processSettings.find( '.status' ).show();
8049 +
8050 + // Remove this form ID from the queue.
8051 + s.importQueue = jQuery.grep( s.importQueue, function( value ) {
8052 + return value != formID;
8053 + });
8054 + s.imported++;
8055 +
8056 + if ( s.importQueue.length === 0 ) {
8057 + $processSettings.find( '.process-count' ).hide();
8058 + $processSettings.find( '.forms-completed' ).text( s.imported );
8059 + $processSettings.find( '.process-completed' ).show();
8060 + } else {
8061 + // Import next form in the queue.
8062 + $processSettings.find( '.form-current' ).text( s.imported + 1 );
8063 + importForm( $processSettings );
8064 + }
8065 + }
8066 + });
8067 + }
8068 +
8069 + function validateExport( e ) {
8070 + /*jshint validthis:true */
8071 + e.preventDefault();
8072 +
8073 + var s = false;
8074 + var $exportForms = jQuery( 'input[name="frm_export_forms[]"]' );
8075 +
8076 + if ( ! jQuery( 'input[name="frm_export_forms[]"]:checked' ).val() ) {
8077 + $exportForms.closest( '.frm-table-box' ).addClass( 'frm_blank_field' );
8078 + s = 'stop';
8079 + }
8080 +
8081 + var $exportType = jQuery( 'input[name="type[]"]' );
8082 + if ( ! jQuery( 'input[name="type[]"]:checked' ).val() && $exportType.attr( 'type' ) === 'checkbox' ) {
8083 + $exportType.closest( 'p' ).addClass( 'frm_blank_field' );
8084 + s = 'stop';
8085 + }
8086 +
8087 + if ( s === 'stop' ) {
8088 + return false;
8089 + }
8090 +
8091 + e.stopPropagation();
8092 + this.submit();
8093 + }
8094 +
8095 + function removeExportError() {
8096 + /*jshint validthis:true */
8097 + var t = jQuery( this ).closest( '.frm_blank_field' );
8098 + if ( typeof t === 'undefined' ) {
8099 + return;
8100 + }
8101 +
8102 + var $thisName = this.name;
8103 + if ( $thisName === 'type[]' && jQuery( 'input[name="type[]"]:checked' ).val() ) {
8104 + t.removeClass( 'frm_blank_field' );
8105 + } else if ( $thisName === 'frm_export_forms[]' && jQuery( this ).val() ) {
8106 + t.removeClass( 'frm_blank_field' );
8107 + }
8108 +
8109 + }
8110 +
8111 + function checkCSVExtension() {
8112 + /*jshint validthis:true */
8113 + var f = jQuery( this ).val();
8114 + var re = /\.csv$/i;
8115 + if ( f.match( re ) !== null ) {
8116 + jQuery( '.show_csv' ).fadeIn();
8117 + } else {
8118 + jQuery( '.show_csv' ).fadeOut();
8119 + }
8120 + }
8121 +
8122 + function checkExportTypes() {
8123 + /*jshint validthis:true */
8124 + var $dropdown = jQuery( this );
8125 + var $selected = $dropdown.find( ':selected' );
8126 + var s = $selected.data( 'support' );
8127 +
8128 + var multiple = s.indexOf( '|' );
8129 + jQuery( 'input[name="type[]"]' ).each( function() {
8130 + this.checked = false;
8131 + if ( s.indexOf( this.value ) >= 0 ) {
8132 + this.disabled = false;
8133 + if ( multiple === -1 ) {
8134 + this.checked = true;
8135 + }
8136 + } else {
8137 + this.disabled = true;
8138 + }
8139 + });
8140 +
8141 + if ( $dropdown.val() === 'csv' ) {
8142 + jQuery( '.csv_opts' ).show();
8143 + jQuery( '.xml_opts' ).hide();
8144 + } else {
8145 + jQuery( '.csv_opts' ).hide();
8146 + jQuery( '.xml_opts' ).show();
8147 + }
8148 +
8149 + var c = $selected.data( 'count' );
8150 + var exportField = jQuery( 'input[name="frm_export_forms[]"]' );
8151 + if ( c === 'single' ) {
8152 + exportField.prop( 'multiple', false );
8153 + exportField.prop( 'checked', false );
8154 + } else {
8155 + exportField.prop( 'multiple', true );
8156 + exportField.prop( 'disabled', false );
8157 + }
8158 + }
8159 +
8160 + function preventMultipleExport() {
8161 + var type = jQuery( 'select[name=format]' ),
8162 + selected = type.find( ':selected' ),
8163 + count = selected.data( 'count' ),
8164 + exportField = jQuery( 'input[name="frm_export_forms[]"]' );
8165 +
8166 + if ( count === 'single' ) {
8167 + // Disable all other fields to prevent multiple selections.
8168 + if ( this.checked ) {
8169 + exportField.prop( 'disabled', true );
8170 + this.removeAttribute( 'disabled' );
8171 + } else {
8172 + exportField.prop( 'disabled', false );
8173 + }
8174 + } else {
8175 + exportField.prop( 'disabled', false );
8176 + }
8177 + }
8178 +
8179 + function initiateMultiselect() {
8180 + jQuery( '.frm_multiselect' ).hide().each( frmDom.bootstrap.multiselect.init );
8181 + }
8182 +
8183 + /* Addons page */
8184 + function installMultipleAddons( e ) {
8185 + e.preventDefault();
8186 + installOrActivate( this, 'frm_multiple_addons' );
8187 + }
8188 +
8189 + function activateAddon( e ) {
8190 + e.preventDefault();
8191 + installOrActivate( this, 'frm_activate_addon' );
8192 + }
8193 +
8194 + function installAddon( e ) {
8195 + e.preventDefault();
8196 + installOrActivate( this, 'frm_install_addon' );
8197 + }
8198 +
8199 + function installOrActivate( clicked, action ) {
8200 + let button, plugin, el, message;
8201 +
8202 + // Remove any leftover error messages, output an icon and get the plugin basename that needs to be activated.
8203 + jQuery( '.frm-addon-error' ).remove();
8204 + button = jQuery( clicked );
8205 + plugin = button.attr( 'rel' );
8206 + el = button.parent();
8207 + message = el.parent().find( '.addon-status-label' );
8208 +
8209 + button.addClass( 'frm_loading_button' );
8210 +
8211 + // Process the Ajax to perform the activation.
8212 + jQuery.ajax({
8213 + url: ajaxurl,
8214 + type: 'POST',
8215 + async: true,
8216 + cache: false,
8217 + dataType: 'json',
8218 + data: {
8219 + action: action,
8220 + nonce: frmGlobal.nonce,
8221 + plugin: plugin
8222 + },
8223 + success: function( response ) {
8224 + let saveAndReload;
8225 +
8226 + if ( 'string' !== typeof response && 'string' === typeof response.message ) {
8227 + if ( 'undefined' !== typeof response.saveAndReload ) {
8228 + saveAndReload = response.saveAndReload;
8229 + }
8230 + response = response.message;
8231 + }
8232 +
8233 + const error = extractErrorFromAddOnResponse( response );
8234 + if ( error ) {
8235 + addonError( error, el, button );
8236 + return;
8237 + }
8238 +
8239 + afterAddonInstall( response, button, message, el, saveAndReload );
8240 + },
8241 + error: function() {
8242 + button.removeClass( 'frm_loading_button' );
8243 + }
8244 + });
8245 + }
8246 +
8247 + function installAddonWithCreds( e ) {
8248 + // Prevent the default action, let the user know we are attempting to install again and go with it.
8249 + e.preventDefault();
8250 +
8251 + // Now let's make another Ajax request once the user has submitted their credentials.
8252 + const proceed = jQuery( this );
8253 + const el = proceed.parent().parent();
8254 + const plugin = proceed.attr( 'rel' );
8255 +
8256 + proceed.addClass( 'frm_loading_button' );
8257 +
8258 + jQuery.ajax({
8259 + url: ajaxurl,
8260 + type: 'POST',
8261 + async: true,
8262 + cache: false,
8263 + dataType: 'json',
8264 + data: {
8265 + action: 'frm_install_addon',
8266 + nonce: frm_admin_js.nonce,
8267 + plugin: plugin,
8268 + hostname: el.find( '#hostname' ).val(),
8269 + username: el.find( '#username' ).val(),
8270 + password: el.find( '#password' ).val()
8271 + },
8272 + success: function( response ) {
8273 + const error = extractErrorFromAddOnResponse( response );
8274 + if ( error ) {
8275 + addonError( error, el, proceed );
8276 + return;
8277 + }
8278 +
8279 + afterAddonInstall( response, proceed, message, el );
8280 + },
8281 + error: function() {
8282 + proceed.removeClass( 'frm_loading_button' );
8283 + }
8284 + });
8285 + }
8286 +
8287 + function afterAddonInstall( response, button, message, el, saveAndReload ) {
8288 + const addonStatuses = document.querySelectorAll( '.frm-addon-status' );
8289 + addonStatuses.forEach(
8290 + addonStatus => {
8291 + addonStatus.textContent = response;
8292 + addonStatus.style.display = 'block';
8293 + }
8294 + );
8295 +
8296 + // The Ajax request was successful, so let's update the output.
8297 + button.css({ opacity: '0' });
8298 + message.text( frm_admin_js.active );
8299 +
8300 + document.querySelectorAll( '.frm-oneclick' ).forEach(
8301 + oneClick => {
8302 + oneClick.style.display = 'none';
8303 + }
8304 + );
8305 +
8306 + jQuery( '#frm_upgrade_modal h2' ).hide();
8307 + jQuery( '#frm_upgrade_modal .frm_lock_icon' ).addClass( 'frm_lock_open_icon' );
8308 + jQuery( '#frm_upgrade_modal .frm_lock_icon use' ).attr( 'xlink:href', '#frm_lock_open_icon' );
8309 +
8310 + // Proceed with CSS changes
8311 + el.parent().removeClass( 'frm-addon-not-installed frm-addon-installed' ).addClass( 'frm-addon-active' );
8312 + button.removeClass( 'frm_loading_button' );
8313 +
8314 + // Maybe refresh import and SMTP pages
8315 + const refreshPage = document.querySelectorAll( '.frm-admin-page-import, #frm-admin-smtp, #frm-welcome' );
8316 + if ( refreshPage.length > 0 ) {
8317 + window.location.reload();
8318 + return;
8319 + }
8320 +
8321 + if ([ 'settings', 'form_builder' ].includes( saveAndReload ) ) {
8322 + addonStatuses.forEach(
8323 + addonStatus => {
8324 + const inModal = null !== addonStatus.closest( '#frm_upgrade_modal' );
8325 + addonStatus.appendChild( getSaveAndReloadSettingsOptions( saveAndReload, inModal ) );
8326 + }
8327 + );
8328 + }
8329 + }
8330 +
8331 + function getSaveAndReloadSettingsOptions( saveAndReload, inModal ) {
8332 + const className = 'frm-save-and-reload-options';
8333 + const children = [ saveAndReloadSettingsButton( saveAndReload ) ];
8334 + if ( inModal ) {
8335 + children.push( closePopupButton() );
8336 + }
8337 + return div({ className, children });
8338 + }
8339 +
8340 + function saveAndReloadSettingsButton( saveAndReload ) {
8341 + var button = document.createElement( 'button' );
8342 + button.classList.add( 'frm-save-and-reload', 'button', 'button-primary', 'frm-button-primary' );
8343 + button.textContent = __( 'Save and Reload', 'formidable' );
8344 + button.addEventListener( 'click', () => {
8345 + if ( saveAndReload === 'form_builder' ) {
8346 + saveAndReloadFormBuilder();
8347 + } else if ( saveAndReload === 'settings' ) {
8348 + saveAndReloadSettings();
8349 + }
8350 + });
8351 + return button;
8352 + }
8353 +
8354 + function closePopupButton() {
8355 + var a = document.createElement( 'a' );
8356 + a.setAttribute( 'href', '#' );
8357 + a.classList.add( 'button', 'button-secondary', 'frm-button-secondary', 'dismiss' );
8358 + a.textContent = __( 'Close', 'formidable' );
8359 + return a;
8360 + }
8361 +
8362 + function extractErrorFromAddOnResponse( response ) {
8363 + if ( typeof response !== 'string' ) {
8364 + if ( typeof response.success !== 'undefined' && response.success ) {
8365 + return false;
8366 + }
8367 +
8368 + if ( response.form ) {
8369 + if ( jQuery( response.form ).is( '#message' ) ) {
8370 + return {
8371 + message: jQuery( response.form ).find( 'p' ).html()
8372 + };
8373 + }
8374 + }
8375 +
8376 + return response;
8377 + }
8378 +
8379 + return false;
8380 + }
8381 +
8382 + function addonError( response, el, button ) {
8383 + if ( response.form ) {
8384 + jQuery( '.frm-inline-error' ).remove();
8385 + button.closest( '.frm-card' )
8386 + .html( response.form )
8387 + .css({ padding: 5 })
8388 + .find( '#upgrade' )
8389 + .attr( 'rel', button.attr( 'rel' ) )
8390 + .on( 'click', installAddonWithCreds );
8391 + } else {
8392 + el.append( '<div class="frm-addon-error frm_error_style"><p><strong>' + response.message + '</strong></p></div>' );
8393 + button.removeClass( 'frm_loading_button' );
8394 + jQuery( '.frm-addon-error' ).delay( 4000 ).fadeOut();
8395 + }
8396 + }
8397 +
8398 + /* Templates */
8399 +
8400 + function initNewFormModal() {
8401 + var installFormTrigger,
8402 + activeHoverIcons,
8403 + $modal,
8404 + handleError,
8405 + handleEmailAddressError,
8406 + handleConfirmEmailAddressError,
8407 + showFreeTemplatesForm,
8408 + firstLockedTemplate,
8409 + isShowFreeTemplatesFormFirst,
8410 + url,
8411 + urlParams;
8412 +
8413 + url = new URL( window.location.href );
8414 + urlParams = url.searchParams;
8415 +
8416 + isShowFreeTemplatesFormFirst = urlParams.get( 'free-templates' );
8417 +
8418 + jQuery( document ).on( 'click', '.frm-trigger-new-form-modal', triggerNewFormModal );
8419 + $modal = initModal( '#frm_new_form_modal', '600px' );
8420 +
8421 + if ( false === $modal ) {
8422 + return;
8423 + }
8424 +
8425 + setTimeout(
8426 + function() {
8427 + $modal.get( 0 ).querySelector( '.postbox' ).style.display = 'block'; // Fixes pro issue #3508, prevent a conflict that hides the postbox in modal.
8428 + },
8429 + 0
8430 + );
8431 +
8432 + installFormTrigger = document.createElement( 'a' );
8433 + installFormTrigger.classList.add( 'frm-install-template', 'frm_hidden' );
8434 + document.body.appendChild( installFormTrigger );
8435 +
8436 + jQuery( '.frm-install-template' ).on( 'click', function( event ) {
8437 + var $h3Clone = jQuery( this ).closest( 'li, td' ).find( 'h3' ).clone(),
8438 + nameLabel = document.getElementById( 'frm_new_name' ),
8439 + descLabel = document.getElementById( 'frm_new_desc' ),
8440 + oldName;
8441 +
8442 + $h3Clone.find( 'svg, .frm-plan-required-tag' ).remove();
8443 + oldName = $h3Clone.html().trim();
8444 +
8445 + event.preventDefault();
8446 +
8447 + document.getElementById( 'frm_template_name' ).value = oldName;
8448 + document.getElementById( 'frm_link' ).value = this.attributes.rel.value;
8449 + document.getElementById( 'frm_action_type' ).value = 'frm_install_template';
8450 + nameLabel.innerHTML = nameLabel.getAttribute( 'data-form' );
8451 + descLabel.innerHTML = descLabel.getAttribute( 'data-form' );
8452 + $modal.dialog( 'open' );
8453 + });
8454 +
8455 + jQuery( document ).on( 'submit', '#frm-new-template', installTemplate );
8456 +
8457 + jQuery( document ).on( 'click', '.frm-hover-icons .frm-preview-form', function( event ) {
8458 + var $li, link, iframe,
8459 + container = document.getElementById( 'frm-preview-block' );
8460 +
8461 + event.preventDefault();
8462 +
8463 + $li = jQuery( this ).closest( 'li' );
8464 + link = $li.attr( 'data-preview' );
8465 +
8466 + if ( link.indexOf( ajaxurl ) > -1 ) {
8467 + iframe = document.createElement( 'iframe' );
8468 + iframe.src = link;
8469 + iframe.height = '400';
8470 + iframe.width = '100%';
8471 + container.innerHTML = '';
8472 + container.appendChild( iframe );
8473 + } else {
8474 + frmApiPreview( container, link );
8475 + }
8476 +
8477 + jQuery( '#frm-preview-title' ).text( getStrippedTemplateName( $li ) );
8478 + $modal.attr( 'frm-page', 'preview' );
8479 + activeHoverIcons = jQuery( this ).closest( '.frm-hover-icons' );
8480 + });
8481 +
8482 + jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-create-form', function( event ) {
8483 + var $li, name, link, action;
8484 +
8485 + event.preventDefault();
8486 +
8487 + $li = jQuery( this ).closest( 'li' );
8488 +
8489 + if ( $li.is( '[data-href]' ) ) {
8490 + window.location = $li.attr( 'data-href' );
8491 + return;
8492 + }
8493 +
8494 + if ( $li.hasClass( 'frm-add-blank-form' ) ) {
8495 + name = link = '';
8496 + action = 'frm_install_form';
8497 + } else if ( $li.is( '[data-rel]' ) ) {
8498 + name = getStrippedTemplateName( $li );
8499 + link = $li.attr( 'data-rel' );
8500 + action = 'frm_install_template';
8501 + } else {
8502 + return;
8503 + }
8504 +
8505 + transitionToAddDetails( $modal, name, link, action );
8506 + });
8507 +
8508 + // Welcome page modals.
8509 + jQuery( document ).on( 'click', '.frm-create-blank-form', function( event ) {
8510 + event.preventDefault();
8511 + jQuery( '.frm-trigger-new-form-modal' ).trigger( 'click' );
8512 + transitionToAddDetails( $modal, '', '', 'frm_install_form' );
8513 +
8514 + // Close the modal with the cancel button.
8515 + jQuery( '.frm-modal-cancel.frm-back-to-all-templates' ).on( 'click', function() {
8516 + jQuery( '.ui-widget-overlay' ).trigger( 'click' );
8517 + });
8518 + });
8519 +
8520 + jQuery( document ).on( 'click', '.frm-featured-forms.frm-templates-list li [role="button"]:not(a), .frm-templates-list .accordion-section.open li [role="button"]:not(a)', function( event ) {
8521 + var $hoverIcons, $trigger,
8522 + $li = jQuery( this ).closest( 'li' ),
8523 + triggerClass = $li.hasClass( 'frm-locked-template' ) ? 'frm-unlock-form' : 'frm-create-form';
8524 +
8525 + $hoverIcons = $li.find( '.frm-hover-icons' );
8526 + if ( ! $hoverIcons.length ) {
8527 + $li.trigger( 'mouseover' );
8528 + $hoverIcons = $li.find( '.frm-hover-icons' );
8529 + $hoverIcons.hide();
8530 + }
8531 +
8532 + $trigger = $hoverIcons.find( '.' + triggerClass );
8533 + $trigger.trigger( 'click' );
8534 + });
8535 +
8536 + jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-delete-form', function( event ) {
8537 + var $li,
8538 + trigger;
8539 +
8540 + event.preventDefault();
8541 +
8542 + $li = jQuery( this ).closest( 'li' );
8543 + $li.addClass( 'frm-deleting' );
8544 + trigger = document.createElement( 'a' );
8545 + trigger.setAttribute( 'href', '#' );
8546 + trigger.setAttribute( 'data-id', $li.attr( 'data-formid' ) );
8547 + $li.attr( 'id', 'frm-template-custom-' + $li.attr( 'data-formid' ) );
8548 + jQuery( trigger ).on( 'click', trashTemplate );
8549 + trigger.click();
8550 + setTemplateCount( $li.closest( '.accordion-section' ).get( 0 ) );
8551 + });
8552 +
8553 + showFreeTemplatesForm = function( $el ) {
8554 + var formContainer = document.getElementById( 'frmapi-email-form' );
8555 + jQuery.ajax({
8556 + dataType: 'json',
8557 + url: formContainer.getAttribute( 'data-url' ),
8558 + success: function( json ) {
8559 + var form = json.renderedHtml;
8560 + form = form.replace( /<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi, '' );
8561 + formContainer.innerHTML = form;
8562 + }
8563 + });
8564 +
8565 + $modal.attr( 'frm-page', 'email' );
8566 + $modal.attr( 'frm-this-form', $el.attr( 'data-key' ) );
8567 + $el.append( installFormTrigger );
8568 + };
8569 +
8570 + jQuery( document ).on( 'click', 'li.frm-locked-template .frm-hover-icons .frm-unlock-form', function( event ) {
8571 + var $li,
8572 + activePage;
8573 +
8574 + event.preventDefault();
8575 +
8576 + $li = jQuery( this ).closest( '.frm-locked-template' );
8577 +
8578 + if ( $li.hasClass( 'frm-free-template' ) ) {
8579 + showFreeTemplatesForm( $li );
8580 + return;
8581 + }
8582 +
8583 + if ( $modal.hasClass( 'frm-expired' ) ) {
8584 + activePage = 'renew';
8585 + } else {
8586 + activePage = 'upgrade';
8587 + }
8588 +
8589 + $modal.attr( 'frm-page', activePage );
8590 + });
8591 +
8592 + jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop', function() {
8593 + jQuery( this )
8594 + .closest( '.accordion-section-content' ).css( 'overflow', 'visible' )
8595 + .closest( '.accordion-section' ).css( 'z-index', 1 );
8596 + });
8597 +
8598 + jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop + .frm-dropdown-menu .frm-build-template', function() {
8599 + var name = this.getAttribute( 'data-fullname' ),
8600 + link = this.getAttribute( 'data-formid' ),
8601 + action = 'frm_build_template';
8602 + transitionToAddDetails( $modal, name, link, action );
8603 + });
8604 +
8605 + handleError = function( inputId, errorId, type, message ) {
8606 + var $error = jQuery( errorId );
8607 + $error.removeClass( 'frm_hidden' ).attr( 'frm-error', type );
8608 +
8609 + if ( typeof message !== 'undefined' ) {
8610 + $error.find( 'span[frm-error="' + type + '"]' ).text( message );
8611 + }
8612 +
8613 + jQuery( inputId ).one( 'keyup', function() {
8614 + $error.addClass( 'frm_hidden' );
8615 + });
8616 + };
8617 +
8618 + handleEmailAddressError = function( type ) {
8619 + handleError( '#frm_leave_email', '#frm_leave_email_error', type );
8620 + };
8621 +
8622 + jQuery( document ).on( 'click', '#frm-add-my-email-address', function( event ) {
8623 + var email = document.getElementById( 'frm_leave_email' ).value.trim(),
8624 + regex,
8625 + $hiddenForm,
8626 + $hiddenEmailField;
8627 +
8628 + event.preventDefault();
8629 +
8630 + if ( '' === email ) {
8631 + handleEmailAddressError( 'empty' );
8632 + return;
8633 + }
8634 +
8635 + 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;
8636 +
8637 + if ( regex.test( email ) === false ) {
8638 + handleEmailAddressError( 'invalid' );
8639 + return;
8640 + }
8641 +
8642 + $hiddenForm = jQuery( '#frmapi-email-form' ).find( 'form' );
8643 + $hiddenEmailField = $hiddenForm.find( '[type="email"]' ).not( '.frm_verify' );
8644 + if ( ! $hiddenEmailField.length ) {
8645 + return;
8646 + }
8647 +
8648 + $hiddenEmailField.val( email );
8649 + jQuery.ajax({
8650 + type: 'POST',
8651 + url: $hiddenForm.attr( 'action' ),
8652 + data: $hiddenForm.serialize() + '&action=frm_forms_preview'
8653 + }).done( function( data ) {
8654 + var message = jQuery( data ).find( '.frm_message' ).text().trim();
8655 + if ( message.indexOf( 'Thanks!' ) >= 0 ) {
8656 + $modal.attr( 'frm-page', 'code' );
8657 + } else {
8658 + handleEmailAddressError( 'invalid' );
8659 + }
8660 + });
8661 + });
8662 +
8663 + handleConfirmEmailAddressError = function( type, message ) {
8664 + handleError( '#frm_code_from_email', '#frm_code_from_email_error', type, message );
8665 + };
8666 +
8667 + jQuery( document ).on( 'click', '.frm-confirm-email-address', function( event ) {
8668 + var code = document.getElementById( 'frm_code_from_email' ).value.trim();
8669 +
8670 + event.preventDefault();
8671 +
8672 + if ( '' === code ) {
8673 + handleConfirmEmailAddressError( 'empty' );
8674 + return;
8675 + }
8676 +
8677 + jQuery.ajax({
8678 + type: 'POST',
8679 + url: ajaxurl,
8680 + dataType: 'json',
8681 + data: {
8682 + action: 'template_api_signup',
8683 + nonce: frmGlobal.nonce,
8684 + code: code,
8685 + key: $modal.attr( 'frm-this-form' )
8686 + },
8687 + success: function( response ) {
8688 + if ( response.success ) {
8689 + if ( isShowFreeTemplatesFormFirst ) {
8690 + // Remove free-templates param from URL then reload page.
8691 + urlParams.delete( 'free-templates' );
8692 + url.search = urlParams.toString();
8693 + window.location.href = url.toString();
8694 +
8695 + return;
8696 + }
8697 +
8698 + if ( typeof response.data !== 'undefined' && typeof response.data.url !== 'undefined' ) {
8699 + installFormTrigger.setAttribute( 'rel', response.data.url );
8700 + installFormTrigger.click();
8701 + $modal.attr( 'frm-page', 'details' );
8702 +
8703 + const hookName = 'frm_new_form_modal_form';
8704 + wp.hooks.doAction( hookName, $modal );
8705 +
8706 + document.getElementById( 'frm_action_type' ).value = 'frm_install_template';
8707 +
8708 + if ( typeof response.data.urlByKey !== 'undefined' ) {
8709 + updateTemplateModalFreeUrls( response.data.urlByKey );
8710 + }
8711 + }
8712 + } else {
8713 + if ( Array.isArray( response.data ) && response.data.length ) {
8714 + handleConfirmEmailAddressError( 'custom', response.data[0].message );
8715 + } else {
8716 + handleConfirmEmailAddressError( 'wrong-code' );
8717 + }
8718 +
8719 + jQuery( '#frm_code_from_email_options' ).removeClass( 'frm_hidden' );
8720 + }
8721 + }
8722 + });
8723 + });
8724 +
8725 + jQuery( document ).on( 'click', '#frm-change-email-address', function() {
8726 + $modal.attr( 'frm-page', 'email' );
8727 + });
8728 +
8729 + jQuery( document ).on( 'click', '#frm-resend-code', function() {
8730 + document.getElementById( 'frm_code_from_email' ).value = '';
8731 + jQuery( '#frm_code_from_email_options, #frm_code_from_email_error' ).addClass( 'frm_hidden' );
8732 + document.getElementById( 'frm-add-my-email-address' ).click();
8733 + });
8734 +
8735 + jQuery( document ).on( 'frmAfterSearch', '#frm_new_form_modal #template-search-input', function() {
8736 + var categories = $modal.get( 0 ).querySelector( '.frm-categories-list' ).children,
8737 + categoryIndex,
8738 + category,
8739 + searchableTemplates,
8740 + count;
8741 +
8742 + for ( categoryIndex in categories ) {
8743 + if ( isNaN( categoryIndex ) ) {
8744 + continue;
8745 + }
8746 +
8747 + category = categories[ categoryIndex ];
8748 + if ( ! category.classList.contains( 'accordion-section' ) ) {
8749 + continue;
8750 + }
8751 +
8752 + searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden)' );
8753 + count = searchableTemplates.length;
8754 + jQuery( category ).toggleClass( 'frm_hidden', this.value !== '' && ! count );
8755 + setTemplateCount( category, searchableTemplates );
8756 + }
8757 + });
8758 +
8759 + jQuery( document ).on( 'click', '#frm_new_form_modal .frm-modal-back, #frm_new_form_modal .frm_modal_footer .frm-modal-cancel, #frm_new_form_modal .frm-back-to-all-templates', function( event ) {
8760 + document.getElementById( 'frm-create-title' ).removeAttribute( 'frm-type' );
8761 + $modal.attr( 'frm-page', 'create' );
8762 + });
8763 +
8764 + jQuery( document ).on( 'click', '.frm-use-this-template', function( event ) {
8765 + var $trigger;
8766 +
8767 + event.preventDefault();
8768 +
8769 + $trigger = activeHoverIcons.find( '.frm-create-form' );
8770 + if ( $trigger.closest( '.frm-selectable' ).hasClass( 'frm-locked-template' ) ) {
8771 + $trigger = activeHoverIcons.find( '.frm-unlock-form' );
8772 + }
8773 +
8774 + $trigger.trigger( 'click' );
8775 + });
8776 +
8777 + jQuery( document ).on( 'click', '.frm-submit-new-template', function( event ) {
8778 + var button;
8779 + event.preventDefault();
8780 + button = document.getElementById( 'frm-new-template' ).querySelector( 'button' );
8781 + if ( null !== button ) {
8782 + button.click();
8783 + }
8784 + });
8785 +
8786 + if ( urlParams.get( 'triggerNewFormModal' ) ) {
8787 + triggerNewFormModal();
8788 +
8789 + if ( isShowFreeTemplatesFormFirst ) {
8790 + firstLockedTemplate = jQuery( 'li.frm-locked-template.frm-free-template' ).eq( 0 );
8791 +
8792 + if ( firstLockedTemplate.length ) {
8793 + showFreeTemplatesForm( firstLockedTemplate );
8794 + }
8795 + }
8796 + }
8797 + }
8798 +
8799 + function updateTemplateModalFreeUrls( urlByKey ) {
8800 + jQuery( '#frm_new_form_modal' ).find( '.frm-selectable[data-key]' ).each( function() {
8801 + var $template = jQuery( this ),
8802 + key = $template.attr( 'data-key' );
8803 + if ( 'undefined' !== typeof urlByKey[ key ]) {
8804 + $template.removeClass( 'frm-locked-template' );
8805 + $template.find( 'h3 svg' ).remove(); // remove the lock from the title
8806 + $template.attr( 'data-rel', urlByKey[ key ]);
8807 + }
8808 + });
8809 + }
8810 +
8811 + function transitionToAddDetails( $modal, name, link, action ) {
8812 + var nameLabel = document.getElementById( 'frm_new_name' ),
8813 + descLabel = document.getElementById( 'frm_new_desc' ),
8814 + type = [ 'frm_install_template', 'frm_install_form' ].indexOf( action ) >= 0 ? 'form' : 'template',
8815 + templateNameInput = document.getElementById( 'frm_template_name' );
8816 +
8817 + templateNameInput.value = name;
8818 + document.getElementById( 'frm_link' ).value = link;
8819 + document.getElementById( 'frm_action_type' ).value = action;
8820 + nameLabel.textContent = nameLabel.getAttribute( 'data-' + type );
8821 + if ( descLabel !== null ) {
8822 + descLabel.textContent = descLabel.getAttribute( 'data-' + type );
8823 + }
8824 +
8825 + document.getElementById( 'frm-create-title' ).setAttribute( 'frm-type', type );
8826 +
8827 + $modal.attr( 'frm-page', 'details' );
8828 +
8829 + const hookName = 'frm_new_form_modal_form';
8830 + wp.hooks.doAction( hookName, $modal );
8831 +
8832 + if ( '' === name ) {
8833 + templateNameInput.focus();
8834 + }
8835 + }
8836 +
8837 + function getStrippedTemplateName( $li ) {
8838 + var $clone = $li.find( 'h3' ).clone();
8839 + $clone.find( 'svg, .frm-plan-required-tag, .frm-new-pill' ).remove();
8840 + return $clone.html().trim();
8841 + }
8842 +
8843 + function setTemplateCount( category, searchableTemplates ) {
8844 + var count,
8845 + templateIndex,
8846 + availableCounter,
8847 + availableCount;
8848 +
8849 + if ( typeof searchableTemplates === 'undefined' ) {
8850 + searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden):not(.frm-deleting)' );
8851 + }
8852 +
8853 + count = searchableTemplates.length;
8854 + category.querySelector( '.frm-template-count' ).textContent = count;
8855 +
8856 + jQuery( category ).find( '.frm-templates-plural' ).toggleClass( 'frm_hidden', count === 1 );
8857 + jQuery( category ).find( '.frm-templates-singular' ).toggleClass( 'frm_hidden', count !== 1 );
8858 +
8859 + availableCounter = category.querySelector( '.frm-available-templates-count' );
8860 + if ( availableCounter !== null ) {
8861 + availableCount = 0;
8862 + for ( templateIndex in searchableTemplates ) {
8863 + if ( ! isNaN( templateIndex ) && ! searchableTemplates[ templateIndex ].classList.contains( 'frm-locked-template' ) ) {
8864 + availableCount++;
8865 + }
8866 + }
8867 +
8868 + availableCounter.textContent = availableCount;
8869 + }
8870 + }
8871 +
8872 + function initSelectionAutocomplete() {
8873 + frmDom.autocomplete.initSelectionAutocomplete();
8874 + }
8875 +
8876 + function nextInstallStep( thisStep ) {
8877 + thisStep.classList.add( 'frm_grey' );
8878 + thisStep.nextElementSibling.classList.remove( 'frm_grey' );
8879 + }
8880 +
8881 + function frmApiPreview( cont, link ) {
8882 + cont.innerHTML = '<div class="frm-wait"></div>';
8883 + jQuery.ajax({
8884 + dataType: 'json',
8885 + url: link,
8886 + success: function( json ) {
8887 + var form = json.renderedHtml;
8888 + form = form.replace( /<script\b[^<]*(js\/jquery\/jquery)[^<]*><\/script>/gi, '' );
8889 + form = form.replace( /<link\b[^>]*(jquery-ui.min.css)[^>]*>/gi, '' );
8890 + form = form.replace( ' frm_logic_form ', ' ' );
8891 + form = form.replace( '<form ', '<form onsubmit="event.preventDefault();" ' );
8892 + cont.innerHTML = '<div class="frm-wait" id="frm-remove-me"></div><div class="frm-fade" id="frm-show-me">' +
8893 + form + '</div>';
8894 + setTimeout( function() {
8895 + document.getElementById( 'frm-remove-me' ).style.display = 'none';
8896 + document.getElementById( 'frm-show-me' ).style.opacity = '1';
8897 + }, 300 );
8898 + }
8899 + });
8900 + }
8901 +
8902 + function installTemplateFieldset( e ) {
8903 + /*jshint validthis:true */
8904 + var fieldset = this.parentNode.parentNode,
8905 + action = fieldset.elements.type.value,
8906 + button = this;
8907 + e.preventDefault();
8908 + button.classList.add( 'frm_loading_button' );
8909 + installNewForm( fieldset, action, button );
8910 + }
8911 +
8912 + function installTemplate( e ) {
8913 + /*jshint validthis:true */
8914 + var action = this.elements.type.value,
8915 + button = this.querySelector( 'button' );
8916 + e.preventDefault();
8917 + button.classList.add( 'frm_loading_button' );
8918 + installNewForm( this, action, button );
8919 + }
8920 +
8921 + function installNewForm( form, action, button ) {
8922 + const formData = formToData( form );
8923 + const formName = formData.template_name;
8924 + const formDesc = formData.template_desc;
8925 + const link = form.elements.link.value;
8926 +
8927 + let data = {
8928 + action: action,
8929 + xml: link,
8930 + name: formName,
8931 + desc: formDesc,
8932 + form: JSON.stringify( formData ),
8933 + nonce: frmGlobal.nonce
8934 + };
8935 +
8936 + const hookName = 'frm_before_install_new_form';
8937 + const filterArgs = { formData };
8938 + data = wp.hooks.applyFilters( hookName, data, filterArgs );
8939 +
8940 + postAjax( data, function( response ) {
8941 + if ( typeof response.redirect !== 'undefined' ) {
8942 + const redirect = response.redirect;
8943 + if ( typeof form.elements.redirect === 'undefined' ) {
8944 + window.location = redirect;
8945 + } else {
8946 + const href = document.getElementById( 'frm-redirect-link' );
8947 + if ( typeof link !== 'undefined' && href !== null ) {
8948 + // Show the next installation step.
8949 + href.setAttribute( 'href', redirect );
8950 + href.classList.remove( 'frm_grey', 'disabled' );
8951 + nextInstallStep( form.parentNode.parentNode );
8952 + button.classList.add( 'frm_grey', 'disabled' );
8953 + }
8954 + }
8955 + } else {
8956 + jQuery( '.spinner' ).css( 'visibility', 'hidden' );
8957 +
8958 + // Show response.message
8959 + if ( 'string' === typeof response.message ) {
8960 + showInstallFormErrorModal( response.message );
8961 + }
8962 + }
8963 + button.classList.remove( 'frm_loading_button' );
8964 + });
8965 + }
8966 +
8967 + function showInstallFormErrorModal( message ) {
8968 + const modalContent = div( message );
8969 + modalContent.style.padding = '20px 40px';
8970 + const modal = frmDom.modal.maybeCreateModal(
8971 + 'frmInstallFormErrorModal',
8972 + {
8973 + title: __( 'Unable to install template', 'formidable' ),
8974 + content: modalContent
8975 + }
8976 + );
8977 + modal.classList.add( 'frm_common_modal' );
8978 + }
8979 +
8980 + function handleCaptchaTypeChange( e ) {
8981 + const thresholdContainer = document.getElementById( 'frm_captcha_threshold_container' );
8982 + if ( thresholdContainer ) {
8983 + thresholdContainer.classList.toggle( 'frm_hidden', 'v3' !== e.target.value );
8984 + }
8985 + }
8986 +
8987 + function trashTemplate( e ) {
8988 + /*jshint validthis:true */
8989 + var id = this.getAttribute( 'data-id' );
8990 + e.preventDefault();
8991 +
8992 + data = {
8993 + action: 'frm_forms_trash',
8994 + id: id,
8995 + nonce: frmGlobal.nonce
8996 + };
8997 + postAjax( data, function() {
8998 + var card = document.getElementById( 'frm-template-custom-' + id );
8999 + fadeOut( card, function() {
9000 + card.parentNode.removeChild( card );
9001 + });
9002 + });
9003 + }
9004 +
9005 + function searchContent() {
9006 + /*jshint validthis:true */
9007 + var i,
9008 + regEx = false,
9009 + searchText = this.value.toLowerCase(),
9010 + toSearch = this.getAttribute( 'data-tosearch' ),
9011 + items = document.getElementsByClassName( toSearch );
9012 +
9013 + if ( this.tagName === 'SELECT' ) {
9014 + searchText = selectedOptions( this );
9015 + searchText = searchText.join( '|' ).toLowerCase();
9016 + regEx = true;
9017 + }
9018 +
9019 + if ( toSearch === 'frm-action' && searchText !== '' ) {
9020 + var addons = document.getElementById( 'frm_email_addon_menu' ).classList;
9021 + addons.remove( 'frm-all-actions' );
9022 + addons.add( 'frm-limited-actions' );
9023 + }
9024 +
9025 + for ( i = 0; i < items.length; i++ ) {
9026 + var innerText = items[i].innerText.toLowerCase();
9027 + if ( searchText === '' ) {
9028 + items[i].classList.remove( 'frm_hidden' );
9029 + items[i].classList.remove( 'frm-search-result' );
9030 + } else if ( ( regEx && new RegExp( searchText ).test( innerText ) ) || innerText.indexOf( searchText ) >= 0 ) {
9031 + items[i].classList.remove( 'frm_hidden' );
9032 + items[i].classList.add( 'frm-search-result' );
9033 + } else {
9034 + items[i].classList.add( 'frm_hidden' );
9035 + items[i].classList.remove( 'frm-search-result' );
9036 + }
9037 + }
9038 +
9039 + jQuery( this ).trigger( 'frmAfterSearch' );
9040 + }
9041 +
9042 + function stopPropagation( e ) {
9043 + e.stopPropagation();
9044 + }
9045 +
9046 + /* Helpers */
9047 +
9048 + function selectedOptions( select ) {
9049 + var opt,
9050 + result = [],
9051 + options = select && select.options;
9052 +
9053 + for ( var i = 0, iLen = options.length; i < iLen; i++ ) {
9054 + opt = options[i];
9055 +
9056 + if ( opt.selected ) {
9057 + result.push( opt.value );
9058 + }
9059 + }
9060 + return result;
9061 + }
9062 +
9063 + function triggerEvent( element, event ) {
9064 + var evt = document.createEvent( 'HTMLEvents' );
9065 + evt.initEvent( event, false, true );
9066 + element.dispatchEvent( evt );
9067 + }
9068 +
9069 + function postAjax( data, success ) {
9070 + let response;
9071 +
9072 + const xmlHttp = new XMLHttpRequest();
9073 + const params = typeof data === 'string' ? data : Object.keys( data ).map(
9074 + function( k ) {
9075 + return encodeURIComponent( k ) + '=' + encodeURIComponent( data[k]);
9076 + }
9077 + ).join( '&' );
9078 +
9079 + xmlHttp.open( 'post', ajaxurl, true );
9080 + xmlHttp.onreadystatechange = function() {
9081 + if ( xmlHttp.readyState > 3 && xmlHttp.status == 200 ) {
9082 + response = xmlHttp.responseText;
9083 + try {
9084 + response = JSON.parse( response );
9085 + } catch ( e ) {
9086 + // The response may not be JSON, so just return it.
9087 + }
9088 + success( response );
9089 + }
9090 + };
9091 + xmlHttp.setRequestHeader( 'X-Requested-With', 'XMLHttpRequest' );
9092 + xmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
9093 + xmlHttp.send( params );
9094 + return xmlHttp;
9095 + }
9096 +
9097 + function fadeOut( element, success ) {
9098 + element.classList.add( 'frm-fade' );
9099 + setTimeout( success, 1000 );
9100 + }
9101 +
9102 + function invisible( classes ) {
9103 + jQuery( classes ).css( 'visibility', 'hidden' );
9104 + }
9105 +
9106 + function visible( classes ) {
9107 + jQuery( classes ).css( 'visibility', 'visible' );
9108 + }
9109 +
9110 + function initModal( id, width ) {
9111 + const $info = jQuery( id );
9112 + if ( ! $info.length ) {
9113 + return false;
9114 + }
9115 +
9116 + if ( typeof width === 'undefined' ) {
9117 + width = '550px';
9118 + }
9119 +
9120 + const dialogArgs = {
9121 + dialogClass: 'frm-dialog',
9122 + modal: true,
9123 + autoOpen: false,
9124 + closeOnEscape: true,
9125 + width: width,
9126 + resizable: false,
9127 + draggable: false,
9128 + open: function() {
9129 + jQuery( '.ui-dialog-titlebar' ).addClass( 'frm_hidden' ).removeClass( 'ui-helper-clearfix' );
9130 + jQuery( '#wpwrap' ).addClass( 'frm_overlay' );
9131 + jQuery( '.frm-dialog' ).removeClass( 'ui-widget ui-widget-content ui-corner-all' );
9132 + $info.removeClass( 'ui-dialog-content ui-widget-content' );
9133 + bindClickForDialogClose( $info );
9134 + },
9135 + close: function() {
9136 + jQuery( '#wpwrap' ).removeClass( 'frm_overlay' );
9137 + jQuery( '.spinner' ).css( 'visibility', 'hidden' );
9138 +
9139 + this.removeAttribute( 'data-option-type' );
9140 + const optionType = document.getElementById( 'bulk-option-type' );
9141 + if ( optionType ) {
9142 + optionType.value = '';
9143 + }
9144 + }
9145 + };
9146 +
9147 + $info.dialog( dialogArgs );
9148 +
9149 + return $info;
9150 + }
9151 +
9152 + function toggle( cname, id ) {
9153 + if ( id === '#' ) {
9154 + var cont = document.getElementById( cname );
9155 + var hidden = cont.style.display;
9156 + if ( hidden === 'none' ) {
9157 + cont.style.display = 'block';
9158 + } else {
9159 + cont.style.display = 'none';
9160 + }
9161 + } else {
9162 + var vis = cname.is( ':visible' );
9163 + if ( vis ) {
9164 + cname.hide();
9165 + } else {
9166 + cname.show();
9167 + }
9168 + }
9169 + }
9170 +
9171 + function removeWPUnload() {
9172 + window.onbeforeunload = null;
9173 + var w = jQuery( window );
9174 + w.off( 'beforeunload.widgets' );
9175 + w.off( 'beforeunload.edit-post' );
9176 + }
9177 +
9178 + function addMultiselectLabelListener() {
9179 + const clickListener = ( e ) => {
9180 + if ( 'LABEL' !== e.target.nodeName ) {
9181 + return;
9182 + }
9183 +
9184 + const labelFor = e.target.getAttribute( 'for' );
9185 + if ( ! labelFor ) {
9186 + return;
9187 + }
9188 +
9189 + const input = document.getElementById( labelFor );
9190 + if ( ! input || ! input.nextElementSibling ) {
9191 + return;
9192 + }
9193 +
9194 + const buttonToggle = input.nextElementSibling.querySelector( 'button.dropdown-toggle.multiselect' );
9195 + if ( ! buttonToggle ) {
9196 + return;
9197 + }
9198 +
9199 + const triggerMultiselectClick = () => buttonToggle.click();
9200 + setTimeout( triggerMultiselectClick, 0 );
9201 + };
9202 + document.addEventListener( 'click', clickListener );
9203 + }
9204 +
9205 + function maybeChangeEmbedFormMsg() {
9206 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
9207 + var fieldItem = document.getElementById( 'frm_field_id_' + fieldId );
9208 + if ( null === fieldItem || 'form' !== fieldItem.dataset.type ) {
9209 + return;
9210 + }
9211 +
9212 + fieldItem = jQuery( fieldItem );
9213 +
9214 + if ( this.options[ this.selectedIndex ].value ) {
9215 + fieldItem.find( '.frm-not-set' )[0].classList.add( 'frm_hidden' );
9216 + var embedMsg = fieldItem.find( '.frm-embed-message' );
9217 + embedMsg.html( embedMsg.data( 'embedmsg' ) + this.options[ this.selectedIndex ].text );
9218 + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.remove( 'frm_hidden' );
9219 + } else {
9220 + fieldItem.find( '.frm-not-set' )[0].classList.remove( 'frm_hidden' );
9221 + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.add( 'frm_hidden' );
9222 + }
9223 + }
9224 +
9225 + function toggleProductType() {
9226 + var settings = jQuery( this ).closest( '.frm-single-settings' ),
9227 + container = settings.find( '.frmjs_product_choices' ),
9228 + heading = settings.find( '.frm_prod_options_heading' ),
9229 + currentVal = this.options[ this.selectedIndex ].value;
9230 +
9231 + container.removeClass( 'frm_prod_type_single frm_prod_type_user_def' );
9232 + heading.removeClass( 'frm_prod_user_def' );
9233 +
9234 + if ( 'single' === currentVal ) {
9235 + container.addClass( 'frm_prod_type_single' );
9236 + } else if ( 'user_def' === currentVal ) {
9237 + container.addClass( 'frm_prod_type_user_def' );
9238 + heading.addClass( 'frm_prod_user_def' );
9239 + }
9240 + }
9241 +
9242 + function isProductField( fieldId ) {
9243 + var field = document.getElementById( 'frm_field_id_' + fieldId );
9244 + if ( field === null ) {
9245 + return false;
9246 + } else {
9247 + return 'product' === field.getAttribute( 'data-type' );
9248 + }
9249 + }
9250 +
9251 + /**
9252 + * Serialize form data with vanilla JS.
9253 + */
9254 + function formToData( form ) {
9255 + var subKey, i,
9256 + object = {},
9257 + formData = form.elements;
9258 +
9259 + for ( i = 0; i < formData.length; i++ ) {
9260 + var input = formData[i],
9261 + key = input.name,
9262 + value = input.value,
9263 + names = key.match( /(.*)\[(.*)\]/ );
9264 +
9265 + if ( ( input.type === 'radio' || input.type === 'checkbox' ) && ! input.checked ) {
9266 + continue;
9267 + }
9268 +
9269 + if ( names !== null ) {
9270 + key = names[1];
9271 + subKey = names[2];
9272 + if ( ! Reflect.has( object, key ) ) {
9273 + object[key] = {};
9274 + }
9275 + object[key][subKey] = value;
9276 + continue;
9277 + }
9278 +
9279 + // Reflect.has in favor of: object.hasOwnProperty(key)
9280 + if ( ! Reflect.has( object, key ) ) {
9281 + object[key] = value;
9282 + continue;
9283 + }
9284 + if ( ! Array.isArray( object[key]) ) {
9285 + object[key] = [ object[key] ];
9286 + }
9287 + object[key].push( value );
9288 + }
9289 +
9290 + return object;
9291 + }
9292 +
9293 + /**
9294 + * Show, hide, and sort subfields of Name field on form builder.
9295 + *
9296 + * @since 4.11
9297 + */
9298 + function handleNameFieldOnFormBuilder() {
9299 + /**
9300 + * Gets subfield element from cache.
9301 + *
9302 + * @param {String} fieldId Field ID.
9303 + * @param {String} key Cache key.
9304 + * @returns {HTMLElement|undefined} Return the element from cache or undefined if not found.
9305 + */
9306 + const getSubFieldElFromCache = ( fieldId, key ) => {
9307 + window.frmCachedSubFields = window.frmCachedSubFields || {};
9308 + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {};
9309 + return window.frmCachedSubFields[fieldId][key];
9310 + };
9311 +
9312 + /**
9313 + * Sets subfield element to cache.
9314 + *
9315 + * @param {String} fieldId Field ID.
9316 + * @param {String} key Cache key.
9317 + * @param {HTMLElement} el Element.
9318 + */
9319 + const setSubFieldElToCache = ( fieldId, key, el ) => {
9320 + window.frmCachedSubFields = window.frmCachedSubFields || {};
9321 + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {};
9322 + window.frmCachedSubFields[fieldId][key] = el;
9323 + };
9324 +
9325 + /**
9326 + * Gets column class from the number of columns.
9327 + *
9328 + * @param {Number} colCount Number of columns.
9329 + * @returns {string}
9330 + */
9331 + const getColClass = colCount => 'frm' + parseInt( 12 / colCount );
9332 +
9333 + const colClasses = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ].map( num => 'frm' + num );
9334 +
9335 + const allSubFieldNames = [ 'first', 'middle', 'last' ];
9336 +
9337 + /**
9338 + * Handles name layout change.
9339 + *
9340 + * @param {Event} event Event object.
9341 + */
9342 + const onChangeLayout = event => {
9343 + const value = event.target.value;
9344 + const subFieldNames = value.split( '_' );
9345 + const fieldId = event.target.dataset.fieldId;
9346 +
9347 + /*
9348 + * Live update form on the form builder.
9349 + */
9350 + const container = document.querySelector( '#field_' + fieldId + '_inner_container .frm_combo_inputs_container' );
9351 + const newColClass = getColClass( subFieldNames.length );
9352 +
9353 + // Set all sub field elements to cache and hide all of them first.
9354 + allSubFieldNames.forEach( name => {
9355 + const subFieldEl = container.querySelector( '[data-sub-field-name="' + name + '"]' );
9356 + if ( subFieldEl ) {
9357 + subFieldEl.classList.add( 'frm_hidden' );
9358 + subFieldEl.classList.remove( ...colClasses );
9359 + setSubFieldElToCache( fieldId, name, subFieldEl );
9360 + }
9361 + });
9362 +
9363 + subFieldNames.forEach( subFieldName => {
9364 + const subFieldEl = getSubFieldElFromCache( fieldId, subFieldName );
9365 + if ( ! subFieldEl ) {
9366 + return;
9367 + }
9368 +
9369 + subFieldEl.classList.remove( 'frm_hidden' );
9370 + subFieldEl.classList.add( newColClass );
9371 +
9372 + container.append( subFieldEl );
9373 + });
9374 +
9375 + /*
9376 + * Live update subfield options.
9377 + */
9378 + // Hide all subfield options.
9379 + allSubFieldNames.forEach( name => {
9380 + const optionsEl = document.querySelector( '.frm_sub_field_options-' + name + '[data-field-id="' + fieldId + '"]' );
9381 + if ( optionsEl ) {
9382 + optionsEl.classList.add( 'frm_hidden' );
9383 + setSubFieldElToCache( fieldId, name + '_options', optionsEl );
9384 + }
9385 + });
9386 +
9387 + subFieldNames.forEach( subFieldName => {
9388 + const optionsEl = getSubFieldElFromCache( fieldId, subFieldName + '_options' );
9389 + if ( ! optionsEl ) {
9390 + return;
9391 + }
9392 + optionsEl.classList.remove( 'frm_hidden' );
9393 + });
9394 + };
9395 +
9396 + const dropdownSelector = '.frm_name_layout_dropdown';
9397 + document.addEventListener( 'change', event => {
9398 + if ( event.target.matches( dropdownSelector ) ) {
9399 + onChangeLayout( event );
9400 + }
9401 + }, false );
9402 + }
9403 +
9404 + function debounce( func, wait = 100 ) {
9405 + return frmDom.util.debounce( func, wait );
9406 + }
9407 +
9408 + function addSaveAndDragIconsToOption( fieldId, liObject ) {
9409 + let li, useTag, useTagHref;
9410 + let hasDragIcon = false;
9411 + let hasSaveIcon = false;
9412 +
9413 + if ( liObject.newOption ) {
9414 + const parser = new DOMParser();
9415 + li = parser.parseFromString( liObject.newOption, 'text/html' ).body.childNodes[0];
9416 + } else {
9417 + li = liObject;
9418 + }
9419 +
9420 + const liIcons = li.querySelectorAll( 'svg' );
9421 +
9422 + liIcons.forEach( ( svg, key ) => {
9423 + useTag = svg.getElementsByTagNameNS( 'http://www.w3.org/2000/svg', 'use' )[0];
9424 + if ( ! useTag ) {
9425 + return;
9426 + }
9427 + useTagHref = useTag.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) || useTag.getAttribute( 'href' );
9428 +
9429 + if ( useTagHref === '#frm_drag_icon' ) {
9430 + hasDragIcon = true;
9431 + }
9432 +
9433 + if ( useTagHref === '#frm_save_icon' ) {
9434 + hasSaveIcon = true;
9435 + }
9436 + });
9437 +
9438 + if ( ! hasDragIcon ) {
9439 + li.prepend( icons.drag.cloneNode( true ) );
9440 + }
9441 +
9442 + if ( li.querySelector( `[id^=field_key_${fieldId}-]` ) && ! hasSaveIcon ) {
9443 + li.querySelector( `[id^=field_key_${fieldId}-]` ).after( icons.save.cloneNode( true ) );
9444 + }
9445 +
9446 + if ( liObject.newOption ) {
9447 + liObject.newOption = li;
9448 + }
9449 + }
9450 +
9451 + function maybeAddSaveAndDragIcons( fieldId ) {
9452 + fieldOptions = document.querySelectorAll( `[id^=frm_delete_field_${fieldId}-]` );
9453 + // return if there are no options.
9454 + if ( fieldOptions.length < 2 ) {
9455 + return;
9456 + }
9457 +
9458 + let options = [ ...fieldOptions ].slice( 1 );
9459 + options.forEach( ( li, _key ) => {
9460 + if ( li.classList.contains( 'frm_other_option' ) ) {
9461 + return;
9462 + }
9463 + addSaveAndDragIconsToOption( fieldId, li );
9464 + });
9465 + }
9466 +
9467 + /**
9468 + * Does the same as jQuery( document ).on( 'event', 'selector', handler ).
9469 + *
9470 + * @since 5.4.2
9471 + *
9472 + * @param {String} event Event name.
9473 + * @param {String} selector Selector.
9474 + * @param {Function} handler Handler.
9475 + * @param {Boolean|Object} options Options to be added to `addEventListener()` method. Default is `false`.
9476 + */
9477 + function documentOn( event, selector, handler, options ) {
9478 + if ( 'undefined' === typeof options ) {
9479 + options = false;
9480 + }
9481 +
9482 + document.addEventListener( event, function( e ) {
9483 + var target;
9484 +
9485 + // loop parent nodes from the target to the delegation node.
9486 + for ( target = e.target; target && target != this; target = target.parentNode ) {
9487 + if ( target.matches( selector ) ) {
9488 + handler.call( target, e );
9489 + break;
9490 + }
9491 + }
9492 + }, options );
9493 + }
9494 +
9495 + return {
9496 + init: function() {
9497 + s = {};
9498 +
9499 + // Bootstrap dropdown button
9500 + jQuery( '.wp-admin' ).on( 'click', function( e ) {
9501 + var t = jQuery( e.target );
9502 + var $openDrop = jQuery( '.dropdown.open' );
9503 + if ( $openDrop.length && ! t.hasClass( 'dropdown' ) && ! t.closest( '.dropdown' ).length ) {
9504 + $openDrop.removeClass( 'open' );
9505 + }
9506 + });
9507 + jQuery( '#frm_bs_dropdown:not(.open) a' ).on( 'click', focusSearchBox );
9508 +
9509 + if ( typeof thisFormId === 'undefined' ) {
9510 + thisFormId = jQuery( document.getElementById( 'form_id' ) ).val();
9511 + }
9512 +
9513 + frmAdminBuild.inboxBannerInit();
9514 +
9515 + if ( $newFields.length > 0 ) {
9516 + // only load this on the form builder page
9517 + frmAdminBuild.buildInit();
9518 + } else if ( document.getElementById( 'frm_notification_settings' ) !== null ) {
9519 + // only load on form settings page
9520 + frmAdminBuild.settingsInit();
9521 + } else if ( document.getElementById( 'frm_styling_form' ) !== null ) {
9522 + // load styling settings js
9523 + frmAdminBuild.styleInit();
9524 + } else if ( document.getElementById( 'form_global_settings' ) !== null ) {
9525 + // global settings page
9526 + frmAdminBuild.globalSettingsInit();
9527 + } else if ( document.getElementById( 'frm_export_xml' ) !== null ) {
9528 + // import/export page
9529 + frmAdminBuild.exportInit();
9530 + } else if ( document.getElementById( 'frm_dyncontent' ) !== null ) {
9531 + // only load on views settings page
9532 + frmAdminBuild.viewInit();
9533 + } else if ( document.getElementById( 'frm_inbox_page' ) !== null ) {
9534 + // Inbox page
9535 + frmAdminBuild.inboxInit();
9536 + } else if ( document.getElementById( 'frm-welcome' ) !== null ) {
9537 + // Solution install page
9538 + frmAdminBuild.solutionInit();
9539 + } else {
9540 + // New form selection page
9541 + initNewFormModal();
9542 + initSelectionAutocomplete();
9543 +
9544 + jQuery( '[data-frmprint]' ).on( 'click', function() {
9545 + window.print();
9546 + return false;
9547 + });
9548 + }
9549 +
9550 + var $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) );
9551 + if ( $advInfo.length > 0 || jQuery( '.frm_field_list' ).length > 0 ) {
9552 + // only load on the form, form settings, and view settings pages
9553 + frmAdminBuild.panelInit();
9554 + }
9555 +
9556 + loadTooltips();
9557 + initUpgradeModal();
9558 + moveTopBanner();
9559 +
9560 + // used on build, form settings, and view settings
9561 + var $shortCodeDiv = jQuery( document.getElementById( 'frm_shortcodediv' ) );
9562 + if ( $shortCodeDiv.length > 0 ) {
9563 + jQuery( 'a.edit-frm_shortcode' ).on( 'click', function() {
9564 + if ( $shortCodeDiv.is( ':hidden' ) ) {
9565 + $shortCodeDiv.slideDown( 'fast' );
9566 + this.style.display = 'none';
9567 + }
9568 + return false;
9569 + });
9570 +
9571 + jQuery( '.cancel-frm_shortcode', '#frm_shortcodediv' ).on( 'click', function() {
9572 + $shortCodeDiv.slideUp( 'fast' );
9573 + $shortCodeDiv.siblings( 'a.edit-frm_shortcode' ).show();
9574 + return false;
9575 + });
9576 + }
9577 +
9578 + // tabs
9579 + jQuery( document ).on( 'click', '#frm-nav-tabs a', clickNewTab );
9580 + jQuery( '.post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a' ).on( 'click', function() {
9581 + const showUpgradeTab = this.classList.contains( 'frm_show_upgrade_tab' );
9582 + if ( this.classList.contains( 'frm_noallow' ) && ! showUpgradeTab ) {
9583 + return;
9584 + }
9585 +
9586 + if ( showUpgradeTab ) {
9587 + populateUpgradeTab( this );
9588 + }
9589 +
9590 + clickTab( this );
9591 + return false;
9592 + });
9593 + clickTab( jQuery( '.starttab a' ), 'auto' );
9594 +
9595 + // submit the search form with dropdown
9596 + jQuery( document ).on( 'click', '#frm-fid-search-menu a', function() {
9597 + var val = this.id.replace( 'fid-', '' );
9598 + jQuery( 'select[name="fid"]' ).val( val );
9599 + triggerSubmit( document.getElementById( 'posts-filter' ) );
9600 + return false;
9601 + });
9602 +
9603 + jQuery( '.frm_select_box' ).on( 'click focus', function() {
9604 + this.select();
9605 + });
9606 +
9607 + jQuery( document ).on( 'input search change', '.frm-auto-search', searchContent );
9608 + jQuery( document ).on( 'focusin click', '.frm-auto-search', stopPropagation );
9609 + var autoSearch = jQuery( '.frm-auto-search' );
9610 + if ( autoSearch.val() !== '' ) {
9611 + autoSearch.trigger( 'keyup' );
9612 + }
9613 +
9614 + // Initialize Formidable Connection.
9615 + FrmFormsConnect.init();
9616 +
9617 + jQuery( document ).on( 'click', '.frm-install-addon', installAddon );
9618 + jQuery( document ).on( 'click', '.frm-activate-addon', activateAddon );
9619 + jQuery( document ).on( 'click', '.frm-solution-multiple', installMultipleAddons );
9620 +
9621 + // prevent annoying confirmation message from WordPress
9622 + jQuery( 'button, input[type=submit]' ).on( 'click', removeWPUnload );
9623 +
9624 + addMultiselectLabelListener();
9625 +
9626 + frmAdminBuild.hooks.addFilter(
9627 + 'frm_before_embed_modal',
9628 + ( ids, { element, type }) => {
9629 + if ( 'form' !== type ) {
9630 + return ids;
9631 + }
9632 +
9633 + let formId, formKey;
9634 + const row = element.closest( 'tr' );
9635 +
9636 + if ( row ) {
9637 + // Embed icon on form index.
9638 + formId = parseInt( row.querySelector( '.column-id' ).textContent );
9639 + formKey = row.querySelector( '.column-form_key' ).textContent;
9640 + } else {
9641 + // Embed button in form builder / form settings.
9642 + formId = document.getElementById( 'form_id' ).value;
9643 +
9644 + const formKeyInput = document.getElementById( 'frm_form_key' );
9645 + if ( formKeyInput ) {
9646 + formKey = formKeyInput.value;
9647 + } else {
9648 + const previewDrop = document.getElementById( 'frm-previewDrop' );
9649 + if ( previewDrop ) {
9650 + formKey = previewDrop.nextElementSibling.querySelector( '.dropdown-item a' ).getAttribute( 'href' ).split( 'form=' )[1];
9651 + }
9652 + }
9653 + }
9654 +
9655 + return [ formId, formKey ];
9656 + }
9657 + );
9658 +
9659 + document.querySelectorAll( '#frm-show-fields > li, .frm_grid_container li' ).forEach( ( el, _key ) => {
9660 + el.addEventListener( 'click', function() {
9661 + let fieldId = this.querySelector( 'li' )?.dataset.fid || this.dataset.fid;
9662 + maybeAddSaveAndDragIcons( fieldId );
9663 + });
9664 + });
9665 + },
9666 +
9667 + buildInit: function() {
9668 + let loadFieldId, $builderForm, builderArea;
9669 +
9670 + debouncedSyncAfterDragAndDrop = debounce( syncAfterDragAndDrop, 10 );
9671 + postBodyContent = document.getElementById( 'post-body-content' );
9672 +
9673 + if ( jQuery( '.frm_field_loading' ).length ) {
9674 + loadFieldId = jQuery( '.frm_field_loading' ).first().attr( 'id' );
9675 + loadFields( loadFieldId );
9676 + }
9677 +
9678 + setupSortable( 'ul.frm_sorting' );
9679 +
9680 + document.querySelectorAll( '.field_type_list > li' ).forEach( makeDraggable );
9681 +
9682 + 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();
9683 +
9684 + jQuery( '.frm_submit_ajax' ).on( 'click', submitBuild );
9685 + jQuery( '.frm_submit_no_ajax' ).on( 'click', submitNoAjax );
9686 +
9687 + jQuery( 'a.edit-form-status' ).on( 'click', slideDown );
9688 + jQuery( '.cancel-form-status' ).on( 'click', slideUp );
9689 + jQuery( '.save-form-status' ).on( 'click', function() {
9690 + const newStatus = jQuery( document.getElementById( 'form_change_status' ) ).val();
9691 + jQuery( 'input[name="new_status"]' ).val( newStatus );
9692 + jQuery( document.getElementById( 'form-status-display' ) ).html( newStatus );
9693 + jQuery( '.cancel-form-status' ).trigger( 'click' );
9694 + return false;
9695 + });
9696 +
9697 + jQuery( '.frm_form_builder form' ).first().on( 'submit', function() {
9698 + jQuery( '.inplace_field' ).trigger( 'blur' );
9699 + });
9700 +
9701 + initiateMultiselect();
9702 + renumberPageBreaks();
9703 +
9704 + $builderForm = jQuery( builderForm );
9705 + builderArea = document.getElementById( 'frm_form_editor_container' );
9706 + $builderForm.on( 'click', '.frm_add_logic_row', addFieldLogicRow );
9707 + $builderForm.on( 'click', '.frm_add_watch_lookup_row', addWatchLookupRow );
9708 + $builderForm.on( 'change', '.frm_get_values_form', updateGetValueFieldSelection );
9709 + $builderForm.on( 'change', '.frm_logic_field_opts', getFieldValues );
9710 + $builderForm.on( 'change', '.radio_maxnum', setStarValues );
9711 + $builderForm.on( 'frm-multiselect-changed', 'select[name^="field_options[admin_only_"]', adjustVisibilityValuesForEveryoneValues );
9712 +
9713 + jQuery( document.getElementById( 'frm-insert-fields' ) ).on( 'click', '.frm_add_field', addFieldClick );
9714 + $newFields.on( 'click', '.frm_clone_field', duplicateField );
9715 + $builderForm.on( 'blur', 'input[id^="frm_calc"]', checkCalculationCreatedByUser );
9716 + $builderForm.on( 'change', 'input.frm_format_opt, input.frm_max_length_opt', toggleInvalidMsg );
9717 + $builderForm.on( 'change click', '[data-changeme]', liveChanges );
9718 + $builderForm.on( 'click', 'input.frm_req_field', markRequired );
9719 + $builderForm.on( 'click', '.frm_mark_unique', markUnique );
9720 +
9721 + $builderForm.on( 'change', '.frm_repeat_format', toggleRepeatButtons );
9722 + $builderForm.on( 'change', '.frm_repeat_limit', checkRepeatLimit );
9723 + $builderForm.on( 'change', '.frm_js_checkbox_limit', checkCheckboxSelectionsLimit );
9724 + $builderForm.on( 'input', 'input[name^="field_options[add_label_"]', function() {
9725 + updateRepeatText( this, 'add' );
9726 + });
9727 + $builderForm.on( 'input', 'input[name^="field_options[remove_label_"]', function() {
9728 + updateRepeatText( this, 'remove' );
9729 + });
9730 + $builderForm.on( 'change', 'select[name^="field_options[data_type_"]', maybeClearWatchFields );
9731 + jQuery( builderArea ).on( 'click', '.frm-collapse-page', maybeCollapsePage );
9732 + jQuery( builderArea ).on( 'click', '.frm-collapse-section', maybeCollapseSection );
9733 + $builderForm.on( 'click', '.frm-single-settings h3', maybeCollapseSettings );
9734 +
9735 + $builderForm.on( 'click', '.frm_toggle_sep_values', toggleSepValues );
9736 + $builderForm.on( 'click', '.frm_toggle_image_options', toggleImageOptions );
9737 + $builderForm.on( 'click', '.frm_remove_image_option', removeImageFromOption );
9738 + $builderForm.on( 'click', '.frm_choose_image_box', addImageToOption );
9739 + $builderForm.on( 'change', '.frm_hide_image_text', refreshOptionDisplay );
9740 + $builderForm.on( 'change', '.frm_field_options_image_size', setImageSize );
9741 + $builderForm.on( 'click', '.frm_multiselect_opt', toggleMultiselect );
9742 + $newFields.on( 'mousedown', 'input, textarea, select', stopFieldFocus );
9743 + $newFields.on( 'click', 'input[type=radio], input[type=checkbox]', stopFieldFocus );
9744 + $newFields.on( 'click', '.frm_delete_field', clickDeleteField );
9745 + $newFields.on( 'click', '.frm_select_field', clickSelectField );
9746 + jQuery( document ).on( 'click', '.frm_delete_field_group', clickDeleteFieldGroup );
9747 + jQuery( document ).on( 'click', '.frm_clone_field_group', duplicateFieldGroup );
9748 + jQuery( document ).on( 'click', '#frm_field_group_controls > span:first-child', clickFieldGroupLayout );
9749 + jQuery( document ).on( 'click', '.frm-row-layout-option', handleFieldGroupLayoutOptionClick );
9750 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-row-layout-option', handleFieldGroupLayoutOptionInsideMergeClick );
9751 + jQuery( document ).on( 'click', '.frm-custom-field-group-layout', customFieldGroupLayoutClick );
9752 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-custom-field-group-layout', customFieldGroupLayoutInsideMergeClick );
9753 + jQuery( document ).on( 'click', '.frm-break-field-group', breakFieldGroupClick );
9754 + $newFields.on( 'click', '#frm_field_group_popup .frm_grid_container input', focusFieldGroupInputOnClick );
9755 + jQuery( document ).on( 'click', '.frm-cancel-custom-field-group-layout', cancelCustomFieldGroupClick );
9756 + jQuery( document ).on( 'click', '.frm-save-custom-field-group-layout', saveCustomFieldGroupClick );
9757 + $newFields.on( 'click', 'ul.frm_sorting', fieldGroupClick );
9758 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row', mergeFieldsIntoRowClick );
9759 + jQuery( document ).on( 'click', '.frm-delete-field-groups', deleteFieldGroupsClick );
9760 + $newFields.on( 'click', '.frm-field-action-icons [data-toggle="dropdown"]', function() {
9761 + this.closest( 'li.form-field' ).classList.add( 'frm-field-settings-open' );
9762 + jQuery( document ).on( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings );
9763 + });
9764 + $newFields.on( 'mousemove', 'ul.frm_sorting', checkForMultiselectKeysOnMouseMove );
9765 + $newFields.on( 'show.bs.dropdown', '.frm-field-action-icons', onFieldActionDropdownShow );
9766 + jQuery( document ).on( 'show.bs.dropdown', '#frm_field_group_controls', onFieldGroupActionDropdownShow );
9767 + $builderForm.on( 'click', '.frm_single_option a[data-removeid]', deleteFieldOption );
9768 + $builderForm.on( 'mousedown', '.frm_single_option input[type=radio]', maybeUncheckRadio );
9769 + $builderForm.on( 'focusin', '.frm_single_option input[type=text]', maybeClearOptText );
9770 + $builderForm.on( 'click', '.frm_add_opt', addFieldOption );
9771 + $builderForm.on( 'change', '.frm_single_option input', resetOptOnChange );
9772 + $builderForm.on( 'change', '.frm_image_id', resetOptOnChange );
9773 + $builderForm.on( 'change', '.frm_toggle_mult_sel', toggleMultSel );
9774 + $builderForm.on( 'focusin', '.frm_classes', showBuilderModal );
9775 +
9776 + $newFields.on( 'click', '.frm_primary_label', clickLabel );
9777 + $newFields.on( 'click', '.frm_description', clickDescription );
9778 + $newFields.on( 'click', 'li.ui-state-default', clickVis );
9779 + $newFields.on( 'dblclick', 'li.ui-state-default', openAdvanced );
9780 + $builderForm.on( 'change', '.frm_tax_form_select', toggleFormTax );
9781 + $builderForm.on( 'change', 'select.conf_field', addConf );
9782 +
9783 + $builderForm.on( 'change', '.frm_get_field_selection', getFieldSelection );
9784 +
9785 + $builderForm.on( 'click', '.frm-show-inline-modal', maybeShowInlineModal );
9786 +
9787 + $builderForm.on( 'click', '.frm-inline-modal .dismiss', dismissInlineModal );
9788 + jQuery( document ).on( 'change', '[data-frmchange]', changeInputtedValue );
9789 +
9790 + $builderForm.on( 'change', '.frm_include_extras_field', rePopCalcFieldsForSummary );
9791 + $builderForm.on( 'change', 'select[name^="field_options[form_select_"]', maybeChangeEmbedFormMsg );
9792 +
9793 + jQuery( document ).on( 'submit', '#frm_js_build_form', buildSubmittedNoAjax );
9794 + 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 );
9795 +
9796 + popAllProductFields();
9797 +
9798 + jQuery( document ).on( 'change', '.frmjs_prod_data_type_opt', toggleProductType );
9799 +
9800 + jQuery( document ).on( 'focus', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextFocus );
9801 + jQuery( document ).on( 'blur', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextBlur );
9802 +
9803 + initBulkOptionsOverlay();
9804 + hideEmptyEle();
9805 + maybeHideQuantityProductFieldOption();
9806 + handleNameFieldOnFormBuilder();
9807 + toggleSectionHolder();
9808 + },
9809 +
9810 + settingsInit: function() {
9811 + const $formActions = jQuery( document.getElementById( 'frm_notification_settings' ) );
9812 +
9813 + let formSettings, $loggedIn, $cookieExp, $editable;
9814 +
9815 + // BCC, CC, and Reply To button functionality
9816 + $formActions.on( 'click', '.frm_email_buttons', showEmailRow );
9817 + $formActions.on( 'click', '.frm_remove_field', hideEmailRow );
9818 + $formActions.on( 'change', '.frm_to_row, .frm_from_row', showEmailWarning );
9819 + $formActions.on( 'change', '.frm_tax_selector', changePosttaxRow );
9820 + $formActions.on( 'change', 'select.frm_single_post_field', checkDupPost );
9821 + $formActions.on( 'change', 'select.frm_toggle_post_content', togglePostContent );
9822 + $formActions.on( 'change', 'select.frm_dyncontent_opt', fillDyncontent );
9823 + $formActions.on( 'change', '.frm_post_type', switchPostType );
9824 + $formActions.on( 'click', '.frm_add_postmeta_row', addPostmetaRow );
9825 + $formActions.on( 'click', '.frm_add_posttax_row', addPosttaxRow );
9826 + $formActions.on( 'click', '.frm_toggle_cf_opts', toggleCfOpts );
9827 + $formActions.on( 'click', '.frm_duplicate_form_action', copyFormAction );
9828 + jQuery( document ).on( 'change', 'select[data-toggleclass], input[data-toggleclass]', toggleFormOpts );
9829 + jQuery( '.frm_actions_list' ).on( 'click', '.frm_active_action', addFormAction );
9830 + jQuery( '#frm-show-groups, #frm-hide-groups' ).on( 'click', toggleActionGroups );
9831 + initiateMultiselect();
9832 +
9833 + //set actions icons to inactive
9834 + jQuery( 'ul.frm_actions_list li' ).each( function() {
9835 + checkActiveAction( jQuery( this ).children( 'a' ).data( 'actiontype' ) );
9836 +
9837 + // If the icon is a background image, don't add BG color.
9838 + const icon = jQuery( this ).find( 'i' );
9839 + if ( icon.css( 'background-image' ) !== 'none' ) {
9840 + icon.addClass( 'frm-inverse' );
9841 + }
9842 + });
9843 +
9844 + jQuery( '.frm_submit_settings_btn' ).on( 'click', submitSettings );
9845 +
9846 + formSettings = jQuery( '.frm_form_settings' );
9847 + formSettings.on( 'click', '.frm_add_form_logic', addFormLogicRow );
9848 + formSettings.on( 'blur', '.frm_email_blur', formatEmailSetting );
9849 + formSettings.on( 'click', '.frm_already_used', onlyOneActionMessage );
9850 +
9851 + formSettings.on( 'change', '#logic_link_submit', toggleSubmitLogic );
9852 + formSettings.on( 'click', '.frm_add_submit_logic', addSubmitLogic );
9853 + formSettings.on( 'change', '.frm_submit_logic_field_opts', addSubmitLogicOpts );
9854 +
9855 + document.addEventListener(
9856 + 'click',
9857 + function handleImageUploadClickEvents( event ) {
9858 + const { target } = event;
9859 +
9860 + if ( ! target.closest( '.frm_image_preview_wrapper' ) ) {
9861 + return;
9862 + }
9863 +
9864 + if ( target.closest( '.frm_choose_image_box' ) ) {
9865 + addImageToOption.bind( target )( event );
9866 + return;
9867 + }
9868 +
9869 + if ( target.closest( '.frm_remove_image_option' ) ) {
9870 + removeImageFromOption.bind( target )( event );
9871 + }
9872 + }
9873 + );
9874 +
9875 + // Close shortcode modal on click.
9876 + formSettings.on( 'mouseup', '*:not(.frm-show-box)', function( e ) {
9877 + e.stopPropagation();
9878 +
9879 + if ( e.target.classList.contains( 'frm-show-box' ) || e.target.parentElement.classList.contains( 'frm-show-box' ) ) {
9880 + return;
9881 + }
9882 +
9883 + const sidebar = document.getElementById( 'frm_adv_info' );
9884 + if ( ! sidebar ) {
9885 + return;
9886 + }
9887 +
9888 + if ( sidebar.getAttribute( 'data-fills' ) === e.target.id && typeof e.target.id !== 'undefined' ) {
9889 + return;
9890 + }
9891 +
9892 + const isChild = jQuery( e.target ).closest( '#frm_adv_info' ).length > 0;
9893 +
9894 + if ( ! isChild && sidebar.display !== 'none' ) {
9895 + hideShortcodes( sidebar );
9896 + }
9897 + });
9898 +
9899 + //Warning when user selects "Do not store entries ..."
9900 + jQuery( document.getElementById( 'no_save' ) ).on( 'change', function() {
9901 + if ( this.checked ) {
9902 + if ( confirm( frm_admin_js.no_save_warning ) !== true ) {
9903 + // Uncheck box if user hits "Cancel"
9904 + jQuery( this ).attr( 'checked', false );
9905 + }
9906 + }
9907 + });
9908 +
9909 + //Show/hide Messages header
9910 + jQuery( '#editable, #edit_action, #save_draft, #success_action' ).on( 'change', function() {
9911 + maybeShowFormMessages();
9912 + });
9913 + jQuery( 'select[name="options[success_action]"], select[name="options[edit_action]"]' ).on( 'change', showSuccessOpt );
9914 +
9915 + $loggedIn = document.getElementById( 'logged_in' );
9916 + jQuery( $loggedIn ).on( 'change', function() {
9917 + if ( this.checked ) {
9918 + visible( '.hide_logged_in' );
9919 + } else {
9920 + invisible( '.hide_logged_in' );
9921 + }
9922 + });
9923 +
9924 + $cookieExp = jQuery( document.getElementById( 'frm_cookie_expiration' ) );
9925 + jQuery( document.getElementById( 'frm_single_entry_type' ) ).on( 'change', function() {
9926 + if ( this.value === 'cookie' ) {
9927 + $cookieExp.fadeIn( 'slow' );
9928 + } else {
9929 + $cookieExp.fadeOut( 'slow' );
9930 + }
9931 + });
9932 +
9933 + var $singleEntry = document.getElementById( 'single_entry' );
9934 + jQuery( $singleEntry ).on( 'change', function() {
9935 + if ( this.checked ) {
9936 + visible( '.hide_single_entry' );
9937 + } else {
9938 + invisible( '.hide_single_entry' );
9939 + }
9940 +
9941 + if ( this.checked && jQuery( document.getElementById( 'frm_single_entry_type' ) ).val() === 'cookie' ) {
9942 + $cookieExp.fadeIn( 'slow' );
9943 + } else {
9944 + $cookieExp.fadeOut( 'slow' );
9945 + }
9946 + });
9947 +
9948 + jQuery( '.hide_save_draft' ).hide();
9949 +
9950 + var $saveDraft = jQuery( document.getElementById( 'save_draft' ) );
9951 + $saveDraft.on( 'change', function() {
9952 + if ( this.checked ) {
9953 + jQuery( '.hide_save_draft' ).fadeIn( 'slow' );
9954 + } else {
9955 + jQuery( '.hide_save_draft' ).fadeOut( 'slow' );
9956 + }
9957 + });
9958 + triggerChange( $saveDraft );
9959 +
9960 + //If Allow editing is checked/unchecked
9961 + $editable = document.getElementById( 'editable' );
9962 + jQuery( $editable ).on( 'change', function() {
9963 + if ( this.checked ) {
9964 + jQuery( '.hide_editable' ).fadeIn( 'slow' );
9965 + triggerChange( document.getElementById( 'edit_action' ) );
9966 + } else {
9967 + jQuery( '.hide_editable' ).fadeOut( 'slow' );
9968 + jQuery( '.edit_action_message_box' ).fadeOut( 'slow' );//Hide On Update message box
9969 + }
9970 + });
9971 +
9972 + //If File Protection is checked/unchecked
9973 + jQuery( document ).on( 'change', '#protect_files', function() {
9974 + if ( this.checked ) {
9975 + jQuery( '.hide_protect_files' ).fadeIn( 'slow' );
9976 + } else {
9977 + jQuery( '.hide_protect_files' ).fadeOut( 'slow' );
9978 + }
9979 + });
9980 +
9981 + jQuery( document ).on( 'frm-multiselect-changed', '#protect_files_role', adjustVisibilityValuesForEveryoneValues );
9982 +
9983 + jQuery( document ).on( 'submit', '.frm_form_settings', settingsSubmitted );
9984 + jQuery( document ).on( 'change', '#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea', fieldUpdated );
9985 +
9986 + // Page Selection Autocomplete
9987 + initSelectionAutocomplete();
9988 +
9989 + jQuery( document ).on( 'frm-action-loaded', onActionLoaded );
9990 + },
9991 +
9992 + panelInit: function() {
9993 + var customPanel, settingsPage, viewPage, insertFieldsTab;
9994 +
9995 + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'click', '.frm_insert_code', insertCode );
9996 + jQuery( document ).on( 'change', '.frm_insert_val', function() {
9997 + insertFieldCode( jQuery( this ).data( 'target' ), jQuery( this ).val() );
9998 + jQuery( this ).val( '' );
9999 + });
10000 +
10001 + jQuery( document ).on( 'click change', '#frm-id-key-condition', resetLogicBuilder );
10002 + jQuery( document ).on( 'keyup change', '.frm-build-logic', setLogicExample );
10003 +
10004 + showInputIcon();
10005 + jQuery( document ).on( 'frmElementAdded', function( event, parentEle ) {
10006 + /* This is here for add-ons to trigger */
10007 + showInputIcon( parentEle );
10008 + });
10009 + jQuery( document ).on( 'mousedown', '.frm-show-box', showShortcodes );
10010 +
10011 + settingsPage = document.getElementById( 'form_settings_page' );
10012 + viewPage = document.body.classList.contains( 'post-type-frm_display' );
10013 + insertFieldsTab = document.getElementById( 'frm_insert_fields_tab' );
10014 +
10015 + if ( settingsPage !== null || viewPage ) {
10016 + jQuery( document ).on( 'focusin', 'form input, form textarea', function( e ) {
10017 + var htmlTab;
10018 + e.stopPropagation();
10019 + maybeShowModal( this );
10020 +
10021 + if ( jQuery( this ).is( ':not(:submit, input[type=button], .frm-search-input, input[type=checkbox])' ) ) {
10022 + if ( jQuery( e.target ).closest( '#frm_adv_info' ).length ) {
10023 + // Don't trigger for fields inside of the modal.
10024 + return;
10025 + }
10026 +
10027 + if ( settingsPage !== null ) {
10028 + /* form settings page */
10029 + htmlTab = jQuery( '#frm_html_tab' );
10030 + if ( jQuery( this ).closest( '#html_settings' ).length > 0 ) {
10031 + htmlTab.show();
10032 + htmlTab.siblings().hide();
10033 + jQuery( '#frm_html_tab a' ).trigger( 'click' );
10034 + toggleAllowedHTML( this, e.type );
10035 + } else {
10036 + showElement( jQuery( '.frm-category-tabs li' ) );
10037 + insertFieldsTab.click();
10038 + htmlTab.hide();
10039 + htmlTab.siblings().show();
10040 + }
10041 + } else if ( viewPage ) {
10042 + // Run on view page.
10043 + toggleAllowedShortcodes( this.id, e.type );
10044 + }
10045 + }
10046 + });
10047 + }
10048 +
10049 + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'mousedown', '#frm_adv_info a, .frm_field_list a', function( e ) {
10050 + e.preventDefault();
10051 + });
10052 +
10053 + customPanel = jQuery( '#frm_adv_info' );
10054 + customPanel.on( 'click', '.subsubsub a.frmids', function( e ) {
10055 + toggleKeyID( 'frmids', e );
10056 + });
10057 + customPanel.on( 'click', '.subsubsub a.frmkeys', function( e ) {
10058 + toggleKeyID( 'frmkeys', e );
10059 + });
10060 + },
10061 +
10062 + viewInit: function() {
10063 + var $addRemove,
10064 + $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) );
10065 + $advInfo.before( '<div id="frm_position_ele"></div>' );
10066 + setupMenuOffset();
10067 +
10068 + jQuery( document ).on( 'blur', '#param', checkDetailPageSlug );
10069 + jQuery( document ).on( 'blur', 'input[name^="options[where_val]"]', checkFilterParamNames );
10070 +
10071 + // Show loading indicator.
10072 + jQuery( '#publish' ).on( 'mousedown', function() {
10073 + fieldsUpdated = 0;
10074 + this.classList.add( 'frm_loading_button' );
10075 + });
10076 +
10077 + // move content tabs
10078 + jQuery( '#frm_dyncontent .handlediv' ).before( jQuery( '#frm_dyncontent .nav-menus-php' ) );
10079 +
10080 + // click content tabs
10081 + jQuery( '.nav-tab-wrapper a' ).on( 'click', clickContentTab );
10082 +
10083 + // click tabs after panel is replaced with ajax
10084 + jQuery( '#side-sortables' ).on( 'click', '.frm_doing_ajax.categorydiv .category-tabs a', clickTabsAfterAjax );
10085 +
10086 + initToggleShortcodes();
10087 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' );
10088 +
10089 + jQuery( 'input[name="show_count"]' ).on( 'change', showCount );
10090 +
10091 + jQuery( document.getElementById( 'form_id' ) ).on( 'change', displayFormSelected );
10092 +
10093 + $addRemove = jQuery( '.frm_repeat_rows' );
10094 + $addRemove.on( 'click', '.frm_add_order_row', addOrderRow );
10095 + $addRemove.on( 'click', '.frm_add_where_row', addWhereRow );
10096 + $addRemove.on( 'change', '.frm_insert_where_options', insertWhereOptions );
10097 + $addRemove.on( 'change', '.frm_where_is_options', hideWhereOptions );
10098 +
10099 + setDefaultPostStatus();
10100 + },
10101 +
10102 + inboxInit: function() {
10103 + jQuery( '.frm_inbox_dismiss, footer .frm-button-secondary, footer .frm-button-primary' ).on( 'click', function( e ) {
10104 + var message = this.parentNode.parentNode,
10105 + key = message.getAttribute( 'data-message' ),
10106 + href = this.getAttribute( 'href' );
10107 +
10108 + if ( 'free_templates' === key && ! this.classList.contains( 'frm_inbox_dismiss' ) ) {
10109 + return;
10110 + }
10111 +
10112 + e.preventDefault();
10113 +
10114 + data = {
10115 + action: 'frm_inbox_dismiss',
10116 + key: key,
10117 + nonce: frmGlobal.nonce
10118 + };
10119 + postAjax( data, function() {
10120 + if ( href !== '#' ) {
10121 + window.location = href;
10122 + return true;
10123 + }
10124 + fadeOut( message, function() {
10125 + message.parentNode.removeChild( message );
10126 + });
10127 + });
10128 + });
10129 + jQuery( '#frm-dismiss-inbox' ).on( 'click', function( e ) {
10130 + data = {
10131 + action: 'frm_inbox_dismiss',
10132 + key: 'all',
10133 + nonce: frmGlobal.nonce
10134 + };
10135 + postAjax( data, function() {
10136 + fadeOut( document.getElementById( 'frm_message_list' ), function() {
10137 + document.getElementById( 'frm_empty_inbox' ).classList.remove( 'frm_hidden' );
10138 + });
10139 + });
10140 + });
10141 + },
10142 +
10143 + solutionInit: function() {
10144 + jQuery( document ).on( 'submit', '#frm-new-template', installTemplate );
10145 + },
10146 +
10147 + styleInit: function() {
10148 + const debouncedPreviewUpdate = debounce( changeStyling, 100 );
10149 +
10150 + collapseAllSections();
10151 +
10152 + document.getElementById( 'frm_field_height' ).addEventListener( 'change', textSquishCheck );
10153 + document.getElementById( 'frm_field_font_size' ).addEventListener( 'change', textSquishCheck );
10154 + document.getElementById( 'frm_field_pad' ).addEventListener( 'change', textSquishCheck );
10155 +
10156 + jQuery( 'input.hex' ).wpColorPicker({
10157 + change: function( event ) {
10158 + if ( null !== event.target.getAttribute( 'data-alpha-color-type' ) ) {
10159 + debouncedPreviewUpdate();
10160 + return;
10161 + } else {
10162 + const hexcolor = jQuery( this ).wpColorPicker( 'color' );
10163 + jQuery( event.target ).val( hexcolor ).trigger( 'change' );
10164 + }
10165 + }
10166 + });
10167 + jQuery( '.wp-color-result-text' ).text( function( i, oldText ) {
10168 + return oldText === 'Select Color' ? 'Select' : oldText;
10169 + });
10170 +
10171 + function changeStyling() {
10172 + var locStr = jQuery( 'input[name^="frm_style_setting[post_content]"], select[name^="frm_style_setting[post_content]"], textarea[name^="frm_style_setting[post_content]"], input[name="style_name"]' ).serializeArray();
10173 + locStr = JSON.stringify( locStr );
10174 + jQuery.ajax({
10175 + type: 'POST', url: ajaxurl,
10176 + data: {
10177 + action: 'frm_change_styling',
10178 + nonce: frmGlobal.nonce,
10179 + frm_style_setting: locStr
10180 + },
10181 + success: function( css ) {
10182 + document.getElementById( 'this_css' ).innerHTML = css;
10183 + }
10184 + });
10185 + }
10186 +
10187 + // update styling on change
10188 + jQuery( '#frm_styling_form .styling_settings' ).on( 'change', debouncedPreviewUpdate );
10189 +
10190 + // menu tabs
10191 + jQuery( '#menu-settings-column' ).on( 'click', function( e ) {
10192 + var panelId, wrapper,
10193 + target = jQuery( e.target );
10194 +
10195 + if ( e.target.className.indexOf( 'nav-tab-link' ) !== -1 ) {
10196 +
10197 + panelId = target.data( 'type' );
10198 +
10199 + wrapper = target.parents( '.accordion-section-content' ).first();
10200 +
10201 +
10202 + jQuery( '.tabs-panel-active', wrapper ).removeClass( 'tabs-panel-active' ).addClass( 'tabs-panel-inactive' );
10203 + jQuery( '#' + panelId, wrapper ).removeClass( 'tabs-panel-inactive' ).addClass( 'tabs-panel-active' );
10204 +
10205 + jQuery( '.tabs', wrapper ).removeClass( 'tabs' );
10206 + target.parent().addClass( 'tabs' );
10207 +
10208 + // select the search bar
10209 + jQuery( '.quick-search', wrapper ).trigger( 'focus' );
10210 +
10211 + e.preventDefault();
10212 + }
10213 + });
10214 +
10215 + jQuery( document ).on( 'change', '.frm-dropdown-menu input[type="radio"]', function() {
10216 + const radio = this;
10217 + const btnGrp = this.closest( '.btn-group' );
10218 + const btnId = btnGrp.getAttribute( 'id' );
10219 +
10220 + const select = document.getElementById( btnId.replace( '_select', '' ) );
10221 + if ( select ) {
10222 + select.value = radio.value;
10223 + }
10224 +
10225 + jQuery( btnGrp ).children( 'button' ).html( radio.nextElementSibling.innerHTML + ' <b class="caret"></b>' );
10226 +
10227 + const activeItem = btnGrp.querySelector( '.dropdown-item.active' );
10228 + if ( activeItem ) {
10229 + activeItem.classList.remove( 'active' );
10230 + }
10231 +
10232 + this.closest( '.dropdown-item' ).classList.add( 'active' );
10233 + });
10234 +
10235 + jQuery( '#frm_confirm_modal' ).on( 'click', '[data-resetstyle]', function( e ) {
10236 + var button = document.getElementById( 'frm_reset_style' );
10237 +
10238 + button.classList.add( 'frm_loading_button' );
10239 + e.stopPropagation();
10240 +
10241 + jQuery.ajax({
10242 + type: 'POST', url: ajaxurl,
10243 + data: {action: 'frm_settings_reset', nonce: frmGlobal.nonce},
10244 + success: function( errObj ) {
10245 + var key;
10246 + errObj = errObj.replace( /^\s+|\s+$/g, '' );
10247 + if ( errObj.indexOf( '{' ) === 0 ) {
10248 + errObj = JSON.parse( errObj );
10249 + }
10250 + for ( key in errObj ) {
10251 + jQuery( 'input[name$="[' + key + ']"], select[name$="[' + key + ']"]' ).val( errObj[key]);
10252 + }
10253 + jQuery( '#frm_submit_style, #frm_auto_width' ).prop( 'checked', false );
10254 + triggerChange( document.getElementById( 'frm_fieldset' ) );
10255 + button.classList.remove( 'frm_loading_button' );
10256 + }
10257 + });
10258 + });
10259 +
10260 + jQuery( '.frm_pro_form #datepicker_sample' ).datepicker({ changeMonth: true, changeYear: true });
10261 +
10262 + jQuery( document.getElementById( 'frm_position' ) ).on( 'change', setPosClass );
10263 +
10264 + jQuery( '.frm_image_preview_wrapper' ).on( 'click', '.frm_choose_image_box', addImageToOption );
10265 + jQuery( '.frm_image_preview_wrapper' ).on( 'click', '.frm_remove_image_option', removeImageFromOption );
10266 +
10267 + // Check floating label when focus or blur fields.
10268 + const floatingLabelSelector = '.frm_inside_container > input, .frm_inside_container > textarea, .frm_inside_container > select';
10269 + [ 'focus', 'blur', 'change' ].forEach( function( eventName ) {
10270 + documentOn(
10271 + eventName,
10272 + floatingLabelSelector,
10273 + function( event ) {
10274 + checkFloatingLabelsForStyles( event.target );
10275 + },
10276 + true
10277 + );
10278 + });
10279 +
10280 + // Trigger label position option on load.
10281 + const changeEvent = document.createEvent( 'HTMLEvents' );
10282 + changeEvent.initEvent( 'change', true, false );
10283 + document.getElementById( 'frm_position' ).dispatchEvent( changeEvent );
10284 + },
10285 +
10286 + customCSSInit: function() {
10287 + console.warn( 'Calling frmAdminBuild.customCSSInit is deprecated.' );
10288 + },
10289 +
10290 + globalSettingsInit: function() {
10291 + var licenseTab;
10292 +
10293 + jQuery( document ).on( 'click', '[data-frmuninstall]', uninstallNow );
10294 +
10295 + initiateMultiselect();
10296 +
10297 + // activate addon licenses
10298 + licenseTab = document.getElementById( 'licenses_settings' );
10299 + if ( licenseTab !== null ) {
10300 + jQuery( licenseTab ).on( 'click', '.edd_frm_save_license', saveAddonLicense );
10301 + }
10302 +
10303 + // Solution install page
10304 + jQuery( document ).on( 'click', '#frm-new-template button', installTemplateFieldset );
10305 +
10306 + jQuery( '#frm-dismissable-cta .dismiss' ).on( 'click', function( event ) {
10307 + event.preventDefault();
10308 + jQuery.post( ajaxurl, {
10309 + action: 'frm_lite_settings_upgrade'
10310 + });
10311 + jQuery( '.settings-lite-cta' ).remove();
10312 + });
10313 +
10314 + const captchaType = document.getElementById( 'frm_re_type' );
10315 + if ( captchaType ) {
10316 + captchaType.addEventListener( 'change', handleCaptchaTypeChange );
10317 + }
10318 + },
10319 +
10320 + exportInit: function() {
10321 + jQuery( '.frm_form_importer' ).on( 'submit', startFormMigration );
10322 + jQuery( document.getElementById( 'frm_export_xml' ) ).on( 'submit', validateExport );
10323 + jQuery( '#frm_export_xml input, #frm_export_xml select' ).on( 'change', removeExportError );
10324 + jQuery( 'input[name="frm_import_file"]' ).on( 'change', checkCSVExtension );
10325 + jQuery( 'select[name="format"]' ).on( 'change', checkExportTypes ).trigger( 'change' );
10326 + jQuery( 'input[name="frm_export_forms[]"]' ).on( 'click', preventMultipleExport );
10327 + initiateMultiselect();
10328 +
10329 + jQuery( '.frm-feature-banner .dismiss' ).on( 'click', function( event ) {
10330 + event.preventDefault();
10331 + jQuery.post( ajaxurl, {
10332 + action: 'frm_dismiss_migrator',
10333 + plugin: this.id,
10334 + nonce: frmGlobal.nonce
10335 + });
10336 + this.parentElement.remove();
10337 + });
10338 + },
10339 +
10340 + inboxBannerInit: function() {
10341 + const banner = document.getElementById( 'frm_banner' );
10342 + if ( ! banner ) {
10343 + return;
10344 + }
10345 +
10346 + const dismissButton = banner.querySelector( '.frm-banner-dismiss' );
10347 + document.addEventListener(
10348 + 'click',
10349 + function( event ) {
10350 + if ( event.target !== dismissButton ) {
10351 + return;
10352 + }
10353 +
10354 + const data = {
10355 + action: 'frm_inbox_dismiss',
10356 + key: banner.dataset.key,
10357 + nonce: frmGlobal.nonce
10358 + };
10359 + postAjax(
10360 + data,
10361 + function() {
10362 + jQuery( banner ).fadeOut(
10363 + 400,
10364 + function() {
10365 + banner.remove();
10366 + }
10367 + );
10368 + }
10369 + );
10370 + }
10371 + );
10372 + },
10373 +
10374 + updateOpts: function( fieldId, opts, modal ) {
10375 + var separate = usingSeparateValues( fieldId ),
10376 + action = isProductField( fieldId ) ? 'frm_bulk_products' : 'frm_import_options';
10377 + jQuery.ajax({
10378 + type: 'POST',
10379 + url: ajaxurl,
10380 + data: {
10381 + action: action,
10382 + field_id: fieldId,
10383 + opts: opts,
10384 + separate: separate,
10385 + nonce: frmGlobal.nonce
10386 + },
10387 + success: function( html ) {
10388 + document.getElementById( 'frm_field_' + fieldId + '_opts' ).innerHTML = html;
10389 + resetDisplayedOpts( fieldId );
10390 +
10391 + if ( typeof modal !== 'undefined' ) {
10392 + modal.dialog( 'close' );
10393 + document.getElementById( 'frm-update-bulk-opts' ).classList.remove( 'frm_loading_button' );
10394 + }
10395 + }
10396 + });
10397 + },
10398 +
10399 + /* remove conditional logic if the field doesn't exist */
10400 + triggerRemoveLogic: function( fieldID, metaName ) {
10401 + jQuery( '#frm_logic_' + fieldID + '_' + metaName + ' .frm_remove_tag' ).trigger( 'click' );
10402 + },
10403 +
10404 + downloadXML: function( controller, ids, isTemplate ) {
10405 + var url = ajaxurl + '?action=frm_' + controller + '_xml&ids=' + ids;
10406 + if ( isTemplate !== null ) {
10407 + url = url + '&is_template=' + isTemplate;
10408 + }
10409 + location.href = url;
10410 + },
10411 +
10412 + /**
10413 + * @since 5.0.04
10414 + */
10415 + hooks: {
10416 + applyFilters: function( hookName, ...args ) {
10417 + return wp.hooks.applyFilters( hookName, ...args );
10418 + },
10419 + addFilter: function( hookName, callback, priority ) {
10420 + return wp.hooks.addFilter( hookName, 'formidable', callback, priority );
10421 + }
10422 + }
10423 + };
10424 +}
10425 +
10426 +frmAdminBuild = frmAdminBuildJS();
10427 +
10428 +jQuery( document ).ready(
10429 + () => {
10430 + frmAdminBuild.init();
10431 +
10432 + frmDom.bootstrap.setupBootstrapDropdowns( convertOldBootstrapDropdownsToBootstrap4 );
10433 + function convertOldBootstrapDropdownsToBootstrap4( frmDropdownMenu ) {
10434 + const toggle = frmDropdownMenu.querySelector( '.frm-dropdown-toggle' );
10435 + if ( toggle ) {
10436 + if ( ! toggle.hasAttribute( 'role' ) ) {
10437 + toggle.setAttribute( 'role', 'button' );
10438 + }
10439 + if ( ! toggle.hasAttribute( 'tabindex' ) ) {
10440 + toggle.setAttribute( 'tabindex', 0 );
10441 + }
10442 + }
10443 +
10444 + // Convert <li> and <ul> tags.
10445 + if ( 'UL' === frmDropdownMenu.tagName ) {
10446 + convertBootstrapUl( frmDropdownMenu );
10447 + }
10448 + }
10449 +
10450 + function convertBootstrapUl( ul ) {
10451 + let html = ul.outerHTML;
10452 + html = html.replace( '<ul ', '<div ' );
10453 + html = html.replace( '</ul>', '</div>' );
10454 + html = html.replaceAll( '<li>', '<div class="dropdown-item">' );
10455 + html = html.replaceAll( '<li class="', '<div class="dropdown-item ' );
10456 + html = html.replaceAll( '</li>', '</div>' );
10457 + ul.outerHTML = html;
10458 + }
10459 + }
10460 +);
10461 +
10462 +function frm_remove_tag( htmlTag ) { // eslint-disable-line camelcase
10463 + console.warn( 'DEPRECATED: function frm_remove_tag in v2.0' );
10464 + jQuery( htmlTag ).remove();
10465 +}
10466 +
10467 +function frm_show_div( div, value, showIf, classId ) { // eslint-disable-line camelcase
10468 + if ( value == showIf ) {
10469 + jQuery( classId + div ).fadeIn( 'slow' ).css( 'visibility', 'visible' );
10470 + } else {
10471 + jQuery( classId + div ).fadeOut( 'slow' );
10472 + }
10473 +}
10474 +
10475 +function frmCheckAll( checked, n ) {
10476 + jQuery( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked );
10477 +}
10478 +
10479 +function frmCheckAllLevel( checked, n, level ) {
10480 + var $kids = jQuery( '.frm_catlevel_' + level ).children( '.frm_checkbox' ).children( 'label' );
10481 + $kids.children( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked );
10482 +}
10483 +
10484 +function frm_add_logic_row( id, formId ) { // eslint-disable-line camelcase
10485 + console.warn( 'DEPRECATED: function frm_add_logic_row in v2.0' );
10486 + jQuery.ajax({
10487 + type: 'POST',
10488 + url: ajaxurl,
10489 + data: {
10490 + action: 'frm_add_logic_row',
10491 + form_id: formId,
10492 + field_id: id,
10493 + meta_name: jQuery( '#frm_logic_row_' + id + ' > div' ).length,
10494 + nonce: frmGlobal.nonce
10495 + },
10496 + success: function( html ) {
10497 + jQuery( '#frm_logic_row_' + id ).append( html );
10498 + }
10499 + });
10500 + return false;
10501 +}
10502 +
10503 +function frmGetFieldValues( fieldId, cur, rowNumber, fieldType, htmlName ) {
10504 +
10505 + if ( fieldId ) {
10506 + jQuery.ajax({
10507 + type: 'POST', url: ajaxurl,
10508 + 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,
10509 + success: function( msg ) {
10510 + document.getElementById( 'frm_show_selected_values_' + cur + '_' + rowNumber ).innerHTML = msg;
10511 + }
10512 + });
10513 + }
10514 +}
10515 +
10516 +function frmImportCsv( formID ) {
10517 + var urlVars = '';
10518 + if ( typeof __FRMURLVARS !== 'undefined' ) {
10519 + urlVars = __FRMURLVARS;
10520 + }
10521 +
10522 + jQuery.ajax({
10523 + type: 'POST', url: ajaxurl,
10524 + data: 'action=frm_import_csv&nonce=' + frmGlobal.nonce + '&frm_skip_cookie=1' + urlVars,
10525 + success: function( count ) {
10526 + var max = jQuery( '.frm_admin_progress_bar' ).attr( 'aria-valuemax' );
10527 + var imported = max - count;
10528 + var percent = ( imported / max ) * 100;
10529 + jQuery( '.frm_admin_progress_bar' ).css( 'width', percent + '%' ).attr( 'aria-valuenow', imported );
10530 +
10531 + if ( parseInt( count, 10 ) > 0 ) {
10532 + jQuery( '.frm_csv_remaining' ).html( count );
10533 + frmImportCsv( formID );
10534 + } else {
10535 + jQuery( document.getElementById( 'frm_import_message' ) ).html( frm_admin_js.import_complete );
10536 + setTimeout( function() {
10537 + location.href = '?page=formidable-entries&frm_action=list&form=' + formID + '&import-message=1';
10538 + }, 2000 );
10539 + }
10540 + }
10541 + });
10542 +}