PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.2
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 +10507 -1 6.31 → 5.5.2 View file →
@@ -1 +1,10507 @@
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,f=s[r].handlers;for(d=f.length;d>0&&!(l>=f[d-1].priority);d--);d===f.length?f[d]=c:f.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:()=>u});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),f=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 u=function(){return new f}},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--}))},f=c.length-1;f>=0;f--)d(f);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][""])},f=function(e,t){d(e,t),c()},u=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=u(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&&f(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:f,resetLocaleData:function(e,t){n.data={},n.pluralForms={},f(e,t)},subscribe:function(e){return i.add(e),function(){return i.delete(e)}},__:function(e,t){var n=u(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=u(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=u(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:()=>u,afterAddonInstall:()=>f,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?u(s,a,o):(f(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 f(e,t,r,i,a){var c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"frm_activate_addon",d=frm_admin_js,f=document.querySelectorAll(".frm-addon-status");f.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 u={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}};u.frm_install_addon=u.frm_activate_addon;var _=o(r,1)[0];_&&(_.textContent=u[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(u[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)&&f.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 u(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?u(i,r,t):f(e,t,message,r)},error:function(){t.removeClass("frm_loading_button")}})}},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"),f=i.querySelector(".frm-addon-status"),u=e.getAttribute("data-oneclick"),m=e.getAttribute("data-message"),_="block",p="block",g="none",y=i.querySelector(".frm-circled-icon");y&&(y.classList.remove("frm-circled-icon-green"),null===(a=y.querySelector("svg"))||void 0===a||a.replaceWith(o({href:"#frm_filled_lock_icon"})));var v=i.querySelector(".frm-learn-more");if(v&&(e.dataset.learnMore?(v.href=e.dataset.learnMore,v.style.display=""):v.style.display="none"),null!==l&&null!==d&&void 0!==u&&u){null===m&&(p="none"),_="none",g="block",u=JSON.parse(u),d.className=d.className.replace(" frm-install-addon","").replace(" frm-activate-addon",""),d.className="".concat(d.className," ").concat(u.class),d.rel=u.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==y||y.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),f.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 f=r.dataset.upgrade;if(f&&!r.classList.contains("frm_show_upgrade_tab")){t.preventDefault();var u=e.get(0);u.classList.remove("frm-success");var m=u.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=u.querySelector(".license-level");g&&(g.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(r)),i(r,"modal",f);var y=u.querySelector(".frm_are_not_installed");y.style.display=r.dataset.image||r.dataset.oneclick?"none":"inline-block",y.textContent=y.dataset.default,u.querySelector(".frm-upgrade-modal-title-prefix").style.display=r.dataset.oneclick?"inline":"none",u.querySelector(".frm_feature_label").textContent=f,u.querySelector(".frm-upgrade-modal-title-suffix").style.display="none",u.querySelector("h2").style.display="block",e.dialog("open");var v=u.querySelector(".button-primary:not(.frm-oneclick-button)");o=v.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)),v.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"))}(u)}}}}!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,f,u,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)&&(f=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)||f&&!l.sign?u="":(u=f?"+":"-",r=r.toString().replace(o.sign,"")),c=l.pad_char?"0"===l.pad_char?"0":l.pad_char.charAt(1):" ",d=l.width-(u+r).length,s=l.width&&d>0?c.repeat(d):"",p+=l.align?u+r+s:"0"===c?u+s+r:s+u+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 l(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||a(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function i(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=a(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,l=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return l=e.done,e},e:function(e){s=!0,i=e},f:function(){try{l||null==r.return||r.return()}finally{if(s)throw i}}}}function a(e,t){if(e){if("string"==typeof e)return l(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)?l(e,t):void 0}}function l(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})},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,a=frm_admin_js,l=frmDom,s=l.tag,c=l.div,d=l.span,f=l.a,u=l.svg,m=l.img,_=frmDom.util.onClickPreventDefault,p=frmDom.ajax.doJsonPost;a.contextualShortcodes=(t=null===(e=document.getElementById("frm_adv_info"))||void 0===e?void 0:e.dataset.contextualShortcodes)?((t=JSON.parse(t)).addressSelector="[id^=email_to], [id^=from_], [id^=cc], [id^=bcc]",t.bodySelector="[id^=email_message_]",t):[];var g,y,v,h={save:u({href:"#frm_save_icon"}),drag:u({href:"#frm_drag_icon",classList:["frm_drag_icon","frm-drag"]})},b=jQuery(document.getElementById("frm-show-fields")),j=document.getElementById("new_fields"),w=document.getElementById("form_id"),Q=!1,x=0,k=0,E=0,A={},S=0,L=wp.i18n,I=L.__,q=L.sprintf,B={dragging:!1};w&&(k=w.value);var C,N=new URL(window.location.href),T=N.searchParams,O=document.getElementById("frm_builder_page");function F(e){e.stopPropagation(),e.preventDefault(),D(this)}function D(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:Ni}):function(e){var t=Ni("#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 M(e,t){var r=Ni("#frm_info_modal",t||"400px");if(!1===r)return!1;"string"==typeof e&&(e={msg:e}),e=Object.assign({title:"",msg:I("Are you sure?","formidable"),img:"",closeText:I("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=pn(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 P(e){var t=this.getAttribute("data-frmtoggle"),r=this.getAttribute("data-toggletext"),n=jQuery(t);return e.preventDefault(),n.toggle(),null!==r&&""!==r&&(this.setAttribute("data-toggletext",this.innerHTML),this.textContent=r),!1}function H(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 z(){document.querySelectorAll(".tooltip").forEach(function(e){e.remove()})}function R(){var e,t,r;if(!parseInt(this.getAttribute("data-skip-frm-js"))&&!1!==D(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 a=document.getElementById(o),l=jQuery(a);return l.fadeOut(300,function(){var r;l.remove(),Ro(),""!==t&&(jQuery(t).hide(),function(e){var t=document.querySelector(e);if(t){var r,n=i(t.classList);try{for(n.s();!(r=n.n()).done;){var o=r.value,a=document.querySelector('input[data-toggleclass="'.concat(o,'"]'));if(null!=a&&a.checked)return void(a.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;co(e),"payment"===e&&["stripe","square","paypal"].forEach(function(e){return co(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,a),!1}}function G(){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 U(e,t){void 0===t&&(t=this),et(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),ui(),Yn("#".concat(r.attr("id"))),bi(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 W(){var e=this.getAttribute("href");if(null===e)return!1;var t=e.replace("#","."),r=jQuery(this);r.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab"),r.closest("div").children(".tabs-panel").not(e).not(t).hide();var n=document.getElementById(e.replace("#",""));return n&&(n.style.display="block"),"frm_insert_fields_tab"!==this.id||this.closest("#frm_adv_info")||Ke(),!1}function $(e,t){var r=(e=jQuery(e)).attr("href");if(void 0!==r){var n,o,i=r.replace("#",".");if(e.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab"),e.closest("div").find(".tabs-panel").length)e.closest("div").children(".tabs-panel").not(r).not(i).hide();else if(null!==document.getElementById("form_global_settings")){var a=e.data("frmajax");e.closest(".frm_wrap").find(".tabs-panel, .hide_with_tabs").hide(),void 0!==a&&"1"==a&&(n=r.replace("#",""),(o=jQuery(".frm_".concat(n,"_ajax"))).length&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_settings_tab",tab:n.replace("_settings",""),nonce:frmGlobal.nonce},success:function(e){o.replaceWith(e)}}))}else jQuery("#frm-categorydiv .tabs-panel, .hide_with_tabs").hide();jQuery(r).show(),jQuery(i).show(),Xo(),"auto"!==t&&(jQuery(".frm_updated_message").hide(),jQuery(".frm_warning_style").hide()),jQuery(e).closest("#frm_adv_info").length||(jQuery(".frm_form_settings").length?jQuery(".frm_form_settings").attr("action","?page=formidable&frm_action=settings&id=".concat(jQuery('.frm_form_settings input[name="id"]').val(),"&t=").concat(r.replace("#",""))):jQuery(".frm_settings_form").attr("action","?page=formidable-settings&t=".concat(r.replace("#",""))))}}function V(e){var t,r;document.querySelectorAll(e).forEach(function(e){K(e),Array.from(e.children).forEach(function(e){return Y(e,".frm-move")});var t=jQuery(e).children('[data-type="divider"]').children(".divider_section_only");t.length&&K(t)}),t=jQuery("#frm_builder_page"),r={items:".frm_sortable_field_opts li",axis:"y",opacity:.65,forcePlaceholderSize:!1,handle:".frm-drag",helper:function(e,t){return Q=t.clone().insertAfter(t),t.clone()},stop:function(e,t){Q&&Q.remove(),an(t.item.attr("id").replace("frm_delete_field_","").replace("-".concat(t.item.data("optkey"),"_container"),"")),Ro()}},jQuery(t).sortable(r)}function K(e){jQuery(e).droppable({accept:".frmbutton, li.frm_field_box",deactivate:ne,over:J,out:X,tolerance:"pointer"})}function J(e,t){var r=function(e){return e.classList.contains("divider_section_only")&&(e=jQuery(e).nextAll(".start_divider.frm_sorting").get(0)),e}(e.target);if(!we(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 X(e){e.target.classList.remove("frm-over-droppable")}function Y(e,t){var r={helper:Z,revert:"invalid",delay:10,start:ee,stop:te,drag:re,cursor:"grabbing",refreshPositions:!0,cursorAt:{top:0,left:90}};"string"==typeof t&&(r.handle=t),jQuery(e).draggable(r)}function Z(e){var t,r=e.delegateTarget;if(xe(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=I("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 c({className:"frmbutton"})}function ee(e,t){if(e.target.classList.contains("frm_at_limit"))return Le(),!1;B.dragging=!0;var r,n=y;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"),vr(),(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()})}),De(),Te(),z()}function te(){y.classList.remove("frm-dragging-field"),document.body.classList.remove("frm-dragging");var e=document.querySelector(".frm-drag-fade");e&&e.classList.remove("frm-drag-fade")}function re(e,t){!function(e){v.scrollTop(function(t,r){var n=e.clientY,o=y.offsetHeight,i=e.clientY-y.offsetTop,a=i-o/2;return i>o-50&&n>5?r+.1*a:i<70&&n<130?r-Math.abs(.1*a):r})}(e);var r=e.target,n=function(){for(var e=document.getElementById("frm-show-fields");e.querySelector(".frm-over-droppable");)e=e.querySelector(".frm-over-droppable");return"frm-show-fields"!==e.id||e.classList.contains("frm-over-droppable")||(e=!1),e}(),o=document.getElementById("frm_drag_placeholder");if(we(r,n,e)){o||(o=s("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,y.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=o.children().not(".edit_field_type_end_divider");if(0===i.length)o.prepend(n),t=0;else{var a=oe(o,r);if(a===i.length){var l=jQuery(i.get(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.get(a)).offset().top,jQuery(i.get(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=ae(o);if(i.length){var a=function(e,t){var r,n,o,i,a=ae(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 ne(e,t){if(B.dragging){B.dragging=!1;var r=t.draggable[0],n=document.getElementById("frm_drag_placeholder");if(!n)return t.helper.remove(),void g();!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(ge(e))wp.hooks.doAction("frm_stopped_inserting_by_dragging",e);else{var t=document.getElementById("frm_drag_placeholder"),r="".concat(e.replace("|","-"),"_").concat(je()),n=s("li",{id:r,className:"frm-wait frmbutton_loadingnow"}),o=jQuery(n),i=fe(jQuery(t)),a=ue(i),l=me(i);t.parentNode.insertBefore(n,t),t.remove(),le(o);var c=0;"summary"===e&&(c=jQuery(".frmbutton_loadingnow#".concat(r)).prevAll('li[data-type="break"]').length?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:pe(e,l,a,c),success:function(t){ye(t,o);var r=ve(t);r&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:r,fieldType:e,form_id:a})},error:be})}}(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")&&Y(t,".frm-move")}}(n.parentElement));var l=i?parseInt(i.closest(".edit_field_type_divider").getAttribute("data-fid")):0,c=a?parseInt(a.closest(".edit_field_type_divider").getAttribute("data-fid")):0;n.remove(),t.helper.remove();var d=o.length?ae(o):[];!function(e,t){var r;e.length&&(t.length?le(t.first()):(r=e.get(0).closest("li.frm_field_box"))&&!r.classList.contains("edit_field_type_divider")&&r.remove())}(o,d),function(e,t){0===t.length&&1===ae(jQuery(e.parentNode)).length||le(jQuery(e))}(r,d),l!==c&&_e(jQuery(r),i),g()}}function oe(e,t){var r,n,o,i,a=e.children().not(".edit_field_type_end_divider"),l=a.length;if(!document.querySelector(".frm-has-fields .frm_no_fields"))return 0;for(i=0,r=l-1;r>=0;--r)if(n=a.get(r),t>(o=jQuery(n).offset().top)){i=r,t>o+jQuery(n).outerHeight()/2&&(i=r+1);break}return i}function ie(){document.querySelectorAll("ul#frm-show-fields, ul.start_divider").forEach(function(e){e.childNodes.forEach(function(e){void 0!==e.classList&&(e.classList.contains("edit_field_type_end_divider")||void 0!==e.classList&&e.classList.contains("form-field")&&We(e))})}),An(),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()}),En();var e=new Event("frm_sync_after_drag_and_drop",{bubbles:!1});document.dispatchEvent(e)}function ae(e){var t=jQuery(),r=e.get(0);return r.children?(Array.from(r.children).forEach(function(e){if("none"!==e.style.display){var r=e.classList;!r.contains("form-field")||r.contains("edit_field_type_end_divider")||r.contains("frm-sortable-helper")||(t=t.add(e))}}),t):t}function le(e,t){var r;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(de(i,Kt(o))):"clear"===t?n.each(de(i,"")):(r=["left","right","middle","even"].includes(t)?function(e){return Vt(o,t,e)}:function(e){return sr(t[e])},n.each(de(i,r))),se(e.parent(),n.length)}function se(e,t){if(void 0!==e.offset()){var r=t>=2,n=document.getElementById("frm_field_group_controls");if(!n){if(!r)return;(n=c()).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=I("Set Row Layout","formidable");ce(t,r),Rt(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=I("Move Field Group","formidable");ce(n,o),Rt(n,o),e.innerHTML="",e.append(t),e.append(n),e.append(function(){var e=d({className:"dropdown"}),t=f({className:"frm_bstooltip frm-hover-icon frm-dropdown-toggle dropdown-toggle",children:[d({child:u({href:"#frm_thick_more_vert_icon"})}),d({className:"screen-reader-text",text:I("Toggle More Options Dropdown","formidable")})]});frmDom.setAttributes(t,{title:I("More Options","formidable"),"data-bs-toggle":"dropdown","data-bs-container":"body","data-bs-display":"static"}),Rt(t,I("More Options","formidable")),e.append(t);var r=c({className:"frm-dropdown-menu dropdown-menu dropdown-menu-right"});return r.setAttribute("role","menu"),e.append(r),e}())}(n),O.append(n)}e.append(n),n.style.display=r?"block":"none"}}function ce(e,t){e.setAttribute("data-bs-toggle","tooltip"),e.setAttribute("data-bs-container","body"),e.setAttribute("title",t),e.addEventListener("mouseover",function(){null===e.getAttribute("data-original-title")&&jQuery(e).tooltip()})}function de(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){io(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 fe(e){var t="";return void 0===e||e.hasClass("edit_field_type_divider")||(t=e.closest(".edit_field_type_divider")),t}function ue(e){var t="";if(void 0!==e[0]){var r=e.children(".start_divider");if(r.children(".edit_field_type_end_divider").appendTo(r),void 0!==e.attr("data-formid")){var n=e.attr("data-fid");t=jQuery('input[name="field_options[form_select_'.concat(n,']"]')).val()}}return void 0!==t&&""!==t||(t=k),t}function me(e){var t=0;return void 0!==e[0]&&(t=e.attr("id").replace("frm_field_id_","")),t}function _e(e,t){if(e.hasClass("form-field")){var r=e.attr("id").replace("frm_field_id_",""),n=fe(e),o=ue(n),i=me(n),a=t?ue(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(){An(),function(e,t){document.getElementById("frm_in_section_".concat(e)).value=t}(r,i)}})}else ae(jQuery(e.get(0).firstChild)).each(function(){_e(jQuery(this),t)})}function pe(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 ge(e){return wp.hooks.applyFilters("frm_should_stop_inserting_field",!1,e)}function ye(e,t){var r;document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var n=t.siblings("li.form-field").not(".edit_field_type_end_divider");n.length?(r=he(e),t.get(0).parentNode.parentNode.classList.contains("ui-draggable")||Y(t.get(0).parentNode.parentNode,".frm-move")):r=Ue(e),t.replaceWith(r),En(),$e(e,!1),n.length&&le(n.first()),An(),n.length?Y(r.get(0),".frm-move"):(K(r.get(0).querySelector("ul.frm_sorting")),Y(r.get(0).querySelector("li.form-field"),".frm-move"))}function ve(e){var t=e.match(/data-fid="(\d+)"/);return t?parseInt(t[1]):0}function he(e){var t=c();return t.innerHTML=e,jQuery(t.firstChild)}function be(e,t,r){!function(e,t){(function(e){return 0===e.status||0===e.readyState})(t)||M("".concat(e,". Please try again."))}(r,e)}function je(){return++E}function we(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=oe(jQuery(t),r.clientY);return n||o?i>t.childElementCount-1:i<=jQuery(t.querySelector(".edit_field_type_submit").closest("#frm-show-fields > li")).index()}if(n)return!(t.classList.contains("start_divider")||!Qe(t.parentElement)&&(!Qe(t.parentElement.nextElementSibling)||e.parentElement.querySelector("li.frm_field_box:not(.edit_field_type_submit)")));var a=t.classList.contains("start_divider")&&null!==t.closest(".repeat_section"),l=null!==t.closest(".repeat_section");if(a||l){if(e.classList.contains("edit_field_type_gdpr")||"gdpr"===e.id)return!1;if(wp.hooks.applyFilters("frm_deny_drop_in_repeater",!1,e))return!1}if(!a){if(!function(e,t){if(e.length<12)return!0;if(e.length>12)return!1;var r=t.attr("data-fid");return 1===jQuery(e).filter('[data-fid="'.concat(r,'"]')).length}(ae(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):!(ke(t)||o||n||l)}(e,t):function(e,t){if(xe(e))return function(e,t){return!(!t.classList.contains("start_divider")||null!==e.querySelector(".start_divider"))}(e,t);if(e.classList.contains("edit_field_type_break"))return!1;if(t.classList.contains("start_divider"))return function(e){return!e.classList.contains("edit_field_type_form")&&!e.querySelector(".edit_field_type_form")&&!(e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"))}(e);var r=e.classList.contains("edit_field_type_hidden"),n=e.classList.contains("edit_field_type_user_id");return!r&&!n&&function(e,t){if(ke(t))return!1;if(jQuery(e).children("ul.frm_sorting").not(".start_divider").length>0)return!1;var r=e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"),n=e.classList.contains("edit_field_type_form");return!(null!==t.closest(".start_divider")&&(r||n))}(e,t)}(e,t)}function Qe(e){return null==e?void 0:e.matches("#frm-show-fields > li:last-child")}function xe(e){return e.classList.contains("frm_field_box")&&!e.classList.contains("form-field")}function ke(e){return null!==e.querySelector(".edit_field_type_break, .edit_field_type_hidden, .edit_field_type_user_id")}function Ee(e){var t=document.getElementById(e),r=jQuery(t),n=[],o=function(e){var t=e.querySelector(".frm_hidden_fdata");e.classList.add("frm_load_now"),null!==t&&n.push(t.innerHTML)};o(t);for(var i=Ae(t);i&&n.length<15;)o(i),i=Ae(i);jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_load_field",field:n,form_id:k,nonce:frmGlobal.nonce},success:function(e){return function(e,t,r){var n,o;if(0===(e=e.replace(/^\s+|\s+$/g,"")).indexOf("{")){for(n in e=JSON.parse(e))if(Object.hasOwn(e,n)){jQuery("#frm_field_id_".concat(n)).replaceWith(e[n]);var i=document.getElementById("frm_field_id_".concat(n));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")})),V("#frm_field_id_".concat(n,".edit_field_type_divider ul.frm_sorting")),Y(document.getElementById("frm_field_id_".concat(n)))}((o=t.nextAll(".frm_field_loading:not(.frm_load_now)")).length||(o=jQuery(document.getElementById("frm-show-fields")).find(".frm_field_loading:not(.frm_load_now)")).length)&&Ee(o.attr("id")),ui(),Dr(),qe();var a=new Event("frm_ajax_loaded_field",{bubbles:!1});a.frmFields=r.map(function(e){return JSON.parse(e)}),document.dispatchEvent(a)}else jQuery(".frm_load_now").removeClass(".frm_load_now").html("Error")}(e,r,n)}})}function Ae(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 Se(){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 Le(),!1;if(frm_admin_js.paymentsSettingsModal&&"object"===o(frm_admin_js.paymentsSettingsModal)&&["product","quantity","total"].includes(r))return M(frm_admin_js.paymentsSettingsModal),!1;if(!ge(r)){var n=0;"summary"===r&&(n=b.children('li[data-type="break"]').length>0?1:0);var i=k;return jQuery.ajax({type:"POST",url:ajaxurl,data:pe(r,0,i,n),success:function(e){Ie(e);var t=ve(e);t&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:e,fieldId:t,fieldType:r,form_id:i})},error:be}),!1}}function Le(){var e=document.querySelector(".frm_wrap");if(e){var t=document.createElement("a");t.setAttribute("data-frmverify",I("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 Ie(e){document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var t=Ue(e),r=b[0].querySelector(".edit_field_type_submit");r?jQuery(r.closest(".frm_field_box:not(.form-field)")).before(t):b.append(t),$e(e,!0),t.each(function(){K(this.querySelector("ul.frm_sorting")),Y(this.querySelector(".form-field"),".frm-move")})}function qe(){var e=!0,t=document.querySelectorAll(".frmjs_prod_field_opt_cont");b.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 Be(){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||ae(jQuery(t.querySelector("ul"))).length<12}(e.get(0))){Te();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:k,children:o,nonce:frmGlobal.nonce},success:function(o){var i,a,l;if(null!==t&&(a=document.getElementById(t)))return l=he(o),jQuery(a).append(l),Y(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}),$e(o,!1),void Ce(e.get(0),l.get(0));e.siblings("li.form-field").length?(l=he(o),e.after(l),le(e),Y(l.get(0),".frm-move")):(l=Ue(o),e.parent().parent().after(l),K(l.get(0).querySelector("ul.frm_sorting")),Y(l.get(0).querySelector("li.form-field"),".frm-move")),En(),$e(o,!1),Ne(n,o),Sn(l.find(".start_divider")),null===(i=e[0].querySelector(".frm-dropdown-menu.dropdown-menu-right"))||void 0===i||i.classList.remove("show"),Ce(e.get(0),l.get(0))}}),!1}M(q(I("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 Ce(e,t){var r,n=e.closest(".frm-field-group-hover-target");if(n&&xe(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 Ne(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 Te(){var e=document.querySelector(".frm-field-settings-open");e&&(e.classList.remove("frm-field-settings-open"),jQuery(document).off("click","#frm_builder_page",Oe),jQuery(".frm-field-action-icons .dropdown.open").removeClass("open"))}function Oe(e){jQuery(e.originalEvent.target).closest(".frm-field-action-icons").length||Te()}function Fe(e){var t=Boolean(e.ctrlKey||e.metaKey||e.shiftKey);jQuery(O).toggleClass("frm-multiselect-key-is-down",t),function(e){if(!y.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=De();!1===n||jQuery(n).is(r)||ur(),se(jQuery(r),ae(jQuery(r)).length),r.classList.add("frm-field-group-hover-target"),jQuery("#wpbody-content").on("mousemove",Me)}}}}(e)}function De(){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",Me),t.classList.remove("frm-field-group-hover-target"),t)}function Me(e){var t=document.elementFromPoint(e.clientX,e.clientY);null!==t&&null!==t.closest("#frm-show-fields")||(De(),z())}function Pe(e){vr(),setTimeout(function(){var t=document.querySelector(".dropdown .frm-dropdown-menu.show");if(t){null===t.getAttribute("aria-label")&&t.setAttribute("aria-label",I("More Options","formidable")),0===t.children.length&&function(e,t){var r=t?"_field_group":"_field",n=[Re(t),Ge(t)];t||n.push({class:"frm_select",icon:"frm_settings_icon",label:I("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","#"),Rt(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"):y&&r.offset().left<y.getBoundingClientRect().left&&(t.style.right="auto",t.style.left="0");var n=t.firstElementChild.querySelector("a");n&&n.focus()}},0)}function He(){Pe(!0)}function ze(e){var t=e.target.closest(".frm-section-collapsed");t&&("show"===e.type?t.style.zIndex=3:t.style.zIndex=1)}function Re(e){var t={class:"frm_delete",icon:"frm_delete_icon"};return t.label=I(e?"Delete Group":"Delete","formidable"),t}function Ge(e){var t={class:"frm_clone",icon:"frm_clone_icon"};return t.label=I(e?"Duplicate Group":"Duplicate","formidable"),t}function Ue(e){var t=c();"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 We(e){var t=s("ul",{className:"frm_grid_container frm_sorting"}),r=s("li",{className:"frm_field_box",child:t});e.replaceWith(r),t.append(e),K(t),Y(r,".frm-move")}function $e(e,t){var r,n,i=/id="(\S+)"/.exec(e),a=document.getElementById(i[1]),l="#".concat(i[1],".edit_field_type_divider ul.frm_sorting.start_divider"),s=jQuery(l),d=a.getAttribute("data-type");r=e,(n=c()).innerHTML=r,n.querySelectorAll(".form-field").forEach(Ve);var f,u,m=!1;if(Ro(),V(l),"quantity"===d&&function(e){var t=e.getAttribute("data-fid"),r=document.getElementById("field_options[product_field_".concat(t,"]"));r&&(nt(r),io(document.getElementById("frm-single-settings-".concat(t))))}(a),"product"!==d&&"quantity"!==d||qe(),s.length)s.parent(".frm_field_box").children(".frm_no_section_fields").addClass("frm_block");else{var _=jQuery(a).closest("ul.frm_sorting.start_divider");_.length&&(Sn(_),m=!0)}e.includes("frm-collapse-page")&&Dr(),u="frm-newly-added",(f=a).classList?f.classList.add(u):f.className+=" ".concat(u),setTimeout(function(){a.classList.remove("frm-newly-added")},1e3);var p,g=a.querySelector("#frm-last-row-fields-order");if(g&&((p=JSON.parse(g.value))&&"object"===o(p)&&Object.keys(p).forEach(function(e){var t=document.querySelector('input[name="field_options[field_order_'.concat(e,']"]'));t&&(t.value=p[e])})),t){var y=a.getBoundingClientRect(),v=document.getElementById("post-body-content");y.top>=0&&y.left>=0&&y.right<=(window.innerWidth||document.documentElement.clientWidth)&&y.bottom<=(window.innerHeight||document.documentElement.clientHeight)||v.scroll({top:v.scrollHeight,left:0,behavior:"smooth"}),!1===m&&Sn(s)}Je(),ui(),document.getElementById("frm-show-fields").classList.remove("frm-over-droppable"),function(e){var t=document.getElementById(e);null!=t&&t.dataset.limit&&Ar(e)>=t.dataset.limit&&t.classList.add("frm_at_limit")}(d),a.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),a.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")});var h=new Event("frm_added_field",{bubbles:!1});h.frmField=a,h.frmSection=l,h.frmType=d,h.frmToggles=m,document.dispatchEvent(h)}function Ve(e){if(e.dataset.fid){var t=document.getElementById("draft_fields");t&&(""===t.value?t.value=e.dataset.fid:t.value.split(",").includes(e.dataset.fid)||(t.value+=",".concat(e.dataset.fid)))}}function Ke(e){jQuery("#new_fields .frm-single-settings").addClass("frm_hidden"),jQuery("#frm-options-panel > .frm-single-settings").removeClass("frm_hidden"),Je(e)}function Je(e){jQuery("li.ui-state-default.selected").removeClass("selected"),jQuery(".frm-show-field-settings.selected").removeClass("selected"),e||vr()}function Xe(){var e=this.value,t=function(e){var t,r=[],n=e.split(""),o=n.length,i=["{","[","("],l={"}":"{",")":"(","]":"["},s=!1;for(t=0;t<o;t++)i.includes(n[t])?r.push(n[t]):Object.hasOwn(l,n[t])&&r.pop()!==l[n[t]]&&(s=!0);return r.length>0||s?"".concat(a.unmatched_parens,"\n\n"):""}(e);t+=function(e,t){var r=function(e,t){var r="";return function(e){return jQuery(e).siblings('label[for^="calc_type"]').children("input").prop("checked")}(t)||/\[(date|time|email|ip)\]/.test(e)&&(r="".concat(a.text_shortcodes,"\n\n")),r}(e,t);return r+=function(e){var t="";return/\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g.test(e)&&(t+="".concat(a.view_shortcodes,"\n\n")),t}(e)}(e,this),""!==t&&M("".concat(e,"\n\n").concat(t))}function Ye(e,t){for(var r=!1,n=0;n<t.length;n++){var o=document.getElementsByName(Ze(t[n],e.fieldId));if(o.length&&jQuery(o[0]).val()){r=!0;break}}return r}function Ze(e,t){var r=e.indexOf("]");return"field_options".concat(e.substring(0,r),"_").concat(t).concat(e.substring(r))}function et(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=function(e){var t=jQuery(e).find(".frm_code_list");return 1===t.length&&t.hasClass("frm_js_summary_list")}(e),i=r.find('input[name="frm_fields_submitted[]"]').val(),a=function(e,t){var r=e.querySelector(".frm_code_list"),n=JSON.parse(r.getAttribute("data-exclude"));if(t){var o=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(o.length)for(var i=0;i<n.length;i++)o.includes(n[i])&&(n.splice(i,1),i--)}return n}(t?e:document.getElementById("frm-calc-box-".concat(i)),o),l=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}(a),s=rt(),c=document.getElementById("frm-calc-list-".concat(i));c.innerHTML="";for(var f=0;f<s.length;f++)if(!(null!=a&&a.includes(s[f].fieldType)||l.length&&Ye(s[f],l))){var u=document.createElement("a");u.setAttribute("href","#"),u.setAttribute("data-code",s[f].fieldId),u.classList.add("frm_insert_code"),u.append(d(s[f].fieldName)),u.append(d({className:"frm-text-sm frm-text-grey-500",text:"[".concat(s[f].fieldId,"]")}));var m=document.createElement("li");m.classList.add("frm-field-list-".concat(i)),m.classList.add("frm-field-list-".concat(s[f].fieldType)),m.append(u),c.append(m)}}}function tt(){et(jQuery(".frm-inline-modal.postbox:has(.frm_js_summary_list)")[0],!0)}function rt(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:it("frm_name_".concat(i)),fieldType:it("field_options_type_".concat(i)),fieldKey:it("field_options_field_key_".concat(i))})}return wp.hooks.applyFilters("frm_admin_get_field_list",r,e,n)}function nt(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=rt("product"),s=rt("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 ot(){for(var e=document.querySelectorAll(".frmjs_prod_field_opt"),t=0;t<e.length;t++)nt(e[t])}function it(e){var t=document.getElementById(e);return t?t.value:""}function at(){var e,t,r,n,o,i,a,l,s,c=this.value,d=document.getElementById(this.getAttribute("data-changeme")),f=this.getAttribute("data-changeatt");d&&(null!==f?"SELECT"===d.tagName&&"placeholder"===f?""===(e=d.options[0]).value?e.innerHTML=c:un(d,c):"class"===f?(r=d,l=" ".concat((n=this).value),void 0!==(s=r.getAttribute("data-fid"))&&(n.classList.contains("field_options_align")?l+=" ".concat(document.getElementById("frm_classes_".concat(s)).value):n.classList.contains("frm_classes")&&(a=document.getElementById("field_options_align_".concat(s)))&&(l+=" ".concat(a.value))),l=(l+=" ").replace(" block "," vertical_radio ").replace(" inline "," horizontal_radio "),""===(o=0===(o=r.className.split(" frmstart ")[1]).indexOf("frmend ")?"":o.split(" frmend ")[0]).trim()?(i=" frmstart frmend ",r.className.includes(i)||(i=" frmstart frmend "),l=" frmstart ".concat(l.trim()," frmend ")):(i=o.trim(),l=l.trim()),r.className=r.className.replace(i,l)):"range"===(t=d).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=lt(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=lt(e)),e.parentNode.querySelector(".frm_range_value").textContent=e.value}}(d,f,c):d.setAttribute(f,c):0===d.id.indexOf("setup-message")?""!==c&&(d.innerHTML='<input type="text" value="" disabled />'):(d.innerHTML=pn(c),"TEXTAREA"===d.nodeName&&d.classList.contains("wp-editor-area")&&jQuery(d).trigger("change"),d.classList.contains("frm_primary_label")&&"break"===d.nextElementSibling.getAttribute("data-ftype")&&(d.nextElementSibling.querySelector(".frm_button_submit").textContent=c)))}function lt(e){var t=parseFloat(e.getAttribute("max")),r=parseFloat(e.getAttribute("min"));return(t-r)/2+r}function st(){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&&dt(""!==t,".frm_invalid_msg".concat(e))}function ct(){var e=this.id.replace("frm_","").replace("req_field_",""),t=this.checked,r=jQuery("#field_label_".concat(e," .frm_required"));if(dt(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 dt(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 ft(){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(a.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 ut(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(this).val(),r=jQuery(document.getElementById("frm_field_id_".concat(e)));if(dt(""!==t,".frm_conf_details".concat(e)),""!==t){var n=jQuery(".frm_validation_box .frm_conf_details".concat(e," input"));""===n.val()&&n.val(a.default_conf),function(e){var t=document.getElementsByName("field_options[type_".concat(e,"]"))[0].value;mt(document.getElementById("field_description_".concat(e)),"field_options[description_".concat(e,"]"),a["enter_".concat(t)]),mt(document.getElementById("conf_field_description_".concat(e)),"field_options[conf_desc_".concat(e,"]"),a["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 mt(e,t,r){e.innerHTML===a.desc&&(e.innerHTML=r,document.getElementsByName(t)[0].value=r)}function _t(e){var t=JSON.parse(this.getAttribute("data-opts"));return e.preventDefault(),document.getElementById("frm_bulk_options").value=t.join("\n"),!1}function pt(){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),an(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",""),zi(n,o={newOption:o});var f=this.closest(".frm_single_option");f?f.after(o.newOption):jQuery("#frm_field_".concat(n,"_opts")).append(o.newOption),an(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")}),Ro()}function gt(){yt(jQuery(this).closest(".frm-single-settings").data("fid"),this.value)}function yt(e,t){var r=jQuery(".frm_multiple_cont_".concat(e));"select"===t?r.fadeIn("fast"):r.fadeOut("fast")}function vt(){var e=jQuery(this).closest(".frm-single-settings").data("fid");Ti(jQuery(".field_".concat(e,"_option_key")),"",this.checked),jQuery(".field_".concat(e,"_option")).toggleClass("frm_with_key")}function ht(){var e=jQuery(this).closest(".frm-single-settings"),t=e.data("fid"),r=document.getElementById("frm_field_id_".concat(t));Qt(jQuery(this));var n=hn(t);if(Ti(jQuery(".field_".concat(t,"_image_id")),"",n),Ti(jQuery(".frm_toggle_image_options_".concat(t)),"",n),Ti(jQuery(".frm_image_size_".concat(t)),"",n),Ti(jQuery(".frm_alignment_".concat(t)),"",n),Ti(jQuery(".frm-add-other#frm_add_field_".concat(t)),"",n),bt(r),n){jt(t,"inline");var o=on(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"),jt(t,"block"),e.find(".frm-bulk-edit-link").show();wp.hooks.doAction("frm_image_options_toggled",e[0],n)}function bt(e){e.classList.remove("frm_image_size_","frm_image_size_small","frm_image_size_medium","frm_image_size_large","frm_image_size_xlarge")}function jt(e,t){jQuery("#field_options_align_".concat(e)).val(t).trigger("change")}function wt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));xt(),hn(e)&&(bt(t),t.classList.add("frm_image_options"),t.classList.add("frm_image_size_".concat(on(e))))}function Qt(e){var t=e.closest(".frm-single-settings").data("fid");jQuery(".field_".concat(t,"_option")).trigger("change")}function xt(){Qt(jQuery(this))}function kt(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 Et(e){var t=jQuery(this).closest(".frm_image_preview_wrapper");e.preventDefault(),e.stopPropagation(),t.find("img").attr("src",""),t.find(".frm_image_preview_frame").hide(),t.find(".frm_choose_image_box").show(),t.find("input.frm_image_id").val(0).trigger("change")}function At(){var e=jQuery(this).closest("li").find(".frm_form_fields select");this.checked?e.attr("multiple","multiple"):e.removeAttr("multiple")}function St(){var e=document.getElementById("dropform-search-input");e&&setTimeout(function(){e.focus()},100)}function Lt(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;p(n,o)}function It(e){e.preventDefault()}function qt(){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"))}),Ro()}function Bt(){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 Ct(){this.value===a.new_option&&(this.setAttribute("data-value-on-focus",this.value),this.value="")}function Nt(e){return q(I("Are you sure you want to delete these %1$s selected field(s)?","formidable"),e)}function Tt(){var e=a.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"),l=0;i.forEach(function(e){var t=e.querySelectorAll("li.form-field");t&&(l+=t.length)}),l&&(e=Nt(++l))}return r.classList.contains("frm-section-collapsed")||r.classList.contains("frm-page-collapsed")||("divider_section_only"===t.className&&(e=a.conf_delete_sec),this.setAttribute("data-frmverify",e),this.setAttribute("data-frmverify-btn","frm-button-red"),this.setAttribute("data-deletefield",o),Te(),D(this)),!1}function Ot(){this.closest("li.form-field").click()}function Ft(){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 Dt(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t="frm_field_group_".concat(je()),r=document.createTextNode("");We(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=ae(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=ae(r);l.forEach(function(e){e.remove()});for(var f=0;f<s;++f)r.append(r.children('li.form-field[frm-field-order="'.concat(f,'"]')));le(i.first(),a),n.classList.remove("frm_hidden"),En(),ae(r).each(function(){Ne(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(ar(lr(this.classList)))})}}function Mt(){var e=document.querySelector(".frm-field-group-hover-target");if(e){Je();var t=Ht(e.querySelector("li.form-field"));e.classList.add("frm-has-open-field-group-popup"),jQuery(document).on("click","#frm_builder_page",Pt);var r=c();r.style.position="relative",r.append(zt(t,this)),this.parentNode.append(r);var n=r.querySelector(".frm-row-layout-option");n&&n.focus()}}function Pt(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||ur()}function Ht(e){var t=jQuery(e).closest("ul");return t.length?ae(t).length:wr()}function zt(e,t){var r=document.getElementById("frm_field_group_popup");r?r.innerHTML="":r=c(),r.id="frm_field_group_popup";var n,o=c();o.style.padding="0 24px 12px",o.append(((n=c()).classList.add("frm-row-layout-title"),n.textContent=I("Row Layout","formidable"),n));var i,a=function(e){var t=Yt();if(e>6)return t.append(Ut(e,"even")),t;if(5!==e&&t.append(Ut(e,"even")),e%2==1&&t.append(Ut(e,"middle")),e<6)t.append(Ut(e,"left")),t.append(Ut(e,"right"));else{var r=c();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(Wt(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=c()).textContent=I("Custom layout","formidable"),jQuery(i).prepend(Gt("frm_gear_svg")),i.classList.add("frm-custom-field-group-layout"),Rt(i),i)),r.append(function(){var e=c();return e.textContent=I("Break into rows","formidable"),jQuery(e).prepend(Gt("frm_break_field_group_svg")),e.classList.add("frm-break-field-group"),Rt(e),e}()),r}function Rt(e,t){e.setAttribute("tabindex",0),e.setAttribute("role","button"),void 0!==t&&e.setAttribute("aria-label",t)}function Gt(e){var t=document.getElementById(e).cloneNode(!0);return t.id="",t}function Ut(e,t){var r,n=c();switch(n.classList.add("frm-row-layout-option"),Rt(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=Yt(),n=0;n<e;++n){var o=c();o.classList.add(Vt(e,t,n)),o.style.height="16px",o.style.background="#9EA9B8",o.style.borderRadius="1px",r.append(o)}return r}(e,t)),n}function Wt(e,t){return $t(e)===$t(t)}function $t(e){var t;t=e.classList.contains("frm-row-layout-option")?jQuery(e).find(".frm_grid_container").children():ae(jQuery(e));var r=[];return t.each(function(){r.push(ar(lr(this.classList)))}),r.join("-")}function Vt(e,t,r){if("even"===t)return Kt(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?Xt(e):Jt(e);if("right"===t)return r===e-1?Xt(e):Jt(e)}return"frm12"}function Kt(e,t){return e>6?"frm1":[2,3,4,6].includes(e)?sr(12/e):5===e&&void 0!==t?0===t?"frm4":"frm2":"frm12"}function Jt(e){switch(e){case 2:case 3:return"frm3";case 4:case 5:return"frm2";case 6:return"frm1";default:return"frm12"}}function Xt(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 Yt(){var e=c();return e.classList.add("frm_grid_container"),e}function Zt(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t=this.getAttribute("layout-type");le(ae(jQuery(e)).first(),t),ur()}}function er(){var e=tr(),t=this.getAttribute("layout-type");le(ae(e).first(),t),vr()}function tr(){var e=jQuery(".frm-selected-field-group"),t=e.first();return e.not(t).each(function(){ae(jQuery(this)).each(function(){var e=this.parentNode;ae(t).last().after(this),jQuery(e).children("li.form-field").length||e.closest("li.frm_field_box").remove()})}),En(),le(ae(t).first()),t}function rr(){null===this.closest(".frm-merge-fields-into-row")&&nr(ae(jQuery(".frm-field-group-hover-target")))}function nr(e){var t=e.length,r=document.getElementById("frm_field_group_popup");r.innerHTML="";var n=c();n.style.padding="0 24px";var o=Kt(5===t?6:t),i=c();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=wr()>0&&ar(Kt(t));!1!==l&&l>=12&&(l=Math.floor(12/t));for(var s=0;s<t;++s){var d=document.createElement("input");d.type="text",d.classList.add(o),d.classList.add("frm-custom-grid-size-input"),d.value=!1!==l?l:ar(lr(e.get(s).classList)),i.append(d)}var f=c();f.classList.add("frm-builder-popup-heading"),f.textContent=I("Enter number of columns for each field","formidable");var u=c();u.classList.add("frm-builder-popup-subheading"),u.textContent=I("Layouts are based on a 12-column grid system","formidable"),n.append(f),n.append(u),n.append(i);var m=c();m.style.textAlign="right";var _,p=((_=ir()).classList.add("button-secondary","frm-button-secondary"),_);p.textContent=I("Cancel","formidable"),p.classList.add("frm-cancel-custom-field-group-layout"),p.style.marginRight="10px";var g=function(){var e=ir();return e.classList.add("button-primary","frm-button-primary"),e}();g.textContent=I("Save","formidable"),g.classList.add("frm-save-custom-field-group-layout"),m.append(p),m.append(g),n.append(m),r.append(n),setTimeout(function(){var e=r.querySelector("input.frm-custom-grid-size-input").focus();e&&e.focus()},0)}function or(){nr(jQuery(".frm-selected-field-group li.form-field"))}function ir(){var e=document.createElement("a");return e.setAttribute("href","#"),e.classList.add("button"),e.style.textDecoration="none",e}function ar(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 lr(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 sr(e){return"frm".concat(e)}function cr(){var e,t;e=document.querySelector(".frm-field-group-hover-target"),ae(t=jQuery(e)).each(function(e){0!==e&&t.parent().after(Ue(this)),function(e){le(e,"clear")}(jQuery(this))}),ur()}function dr(){this.select()}function fr(){jQuery(document.getElementById("frm_field_group_popup")).replaceWith(zt(Ht(this),this))}function ur(){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",Pt)}}function mr(){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?le(ae(jQuery(document.querySelector(".frm-field-group-hover-target"))).first(),e):(le(ae(tr()).first(),e),vr()),ur()}function _r(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)pr(e);else if(e)!function(e){e&&(e.classList.remove("frm_hidden"),e.classList.add("frm-fadein-up-back"))}(e);else{e=c({id:"frm-field-group-message",className:"frm-flex-center frm-fadein-up-back",children:[d({id:"frm-field-group-message-dismiss",className:"frm-flex-center",child:u({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=q(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(){pr(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=gr();if(t){var r=t.closest("ul");if(r&&1===ae(jQuery(r)).length)return r.classList.add("frm-selected-field-group"),jQuery(r)}return jQuery()}(),a=i.length;if(r||n){var l=gr();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 yr(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 vr(),a=1;t.classList.add("frm-selected-field-group"),yr(a),document.querySelectorAll(".frm-selected-field-group").length<2||pr(document.getElementById("frm-field-group-message")),jQuery(document).off("click",vr),jQuery(document).on("click",vr)}}}function pr(e){e&&(e.classList.add("frm_hidden"),e.classList.remove("frm-fadein-up-back"))}function gr(){return document.getElementById("frm-show-fields").querySelector("li.form-field.selected")}function yr(e){Ke(!0),e>=2||1===e&&ae(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",!br()),e;(e=c()).id="frm_field_multiselect_popup",br()||e.classList.add("frm-unmergable");var t=c();t.classList.add("frm-merge-fields-into-row"),t.textContent=I("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=c();n.classList.add("frm-multiselect-popup-separator"),e.append(n);var o=c();o.classList.add("frm-delete-field-groups"),o.append(Gt("frm_trash_svg")),e.append(o),document.getElementById("post-body-content").append(e),jQuery(e).hide().fadeIn()}():hr(),De()}function vr(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",vr),hr()}function hr(){var e=document.getElementById("frm_field_multiselect_popup");e&&e.remove()}function br(){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+=ae(jQuery(o)).length)>12)return!1}return!0}function jr(e){if(null===e.originalEvent.target.closest("#frm_field_group_popup")&&!e.originalEvent.target.classList.contains("frm-custom-field-group-layout")){var t=zt(wr(),document.querySelector(".frm-selected-field-group").firstChild);this.append(t)}}function wr(){var e=0;return jQuery(document.querySelectorAll(".frm-selected-field-group")).each(function(){e+=ae(jQuery(this)).length}),e}function Qr(){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){kr(e)})}(e)}}(t),n=document.getElementById("frm_field_multiselect_popup");n&&n.remove(),this.setAttribute("data-frmverify",Nt(t.length)),D(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 xr(){kr(this.getAttribute("data-deletefield"))}function kr(e){var t=jQuery("#frm_field_id_".concat(e));Er(e),t.hasClass("edit_field_type_divider")&&t.find("li.frm_field_box[data-fid]").each(function(){Er(this.getAttribute("data-fid"))}),An()}function Er(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?Dr():"product"===r&&(qe(),ot()),n.length?le(n.first()):e.remove(),0===jQuery("#frm-show-fields li").length||function(){if(b.get(0).childElementCount>1)return!1;var e=b.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&&Sn(t);z()}),o.length&&(r=o.data("type"),(n=document.getElementById(r))&&n.dataset.limit&&Ar(r)-1<n.dataset.limit&&n.classList.remove("frm_at_limit"),wp.hooks.doAction("frm_after_delete_field",o[0]))}})}function Ar(e){return document.getElementById("frm-show-fields").querySelectorAll('li.form-field[data-ftype="'.concat(e,'"]')).length}function Sr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=k,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:Lr(r,"frm_logic_".concat(e,"_")),fields:rt()},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 Lr(e,t,r){return e.length?parseInt(e[e.length-1].id.replace(t,""),10)+1:void 0!==r?r:0}function Ir(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=k,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:Lr(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 qr(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 Br(){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===A[t]&&(A[t]={}),A[t][this.value]=e),"true"===this.getAttribute("data-duplicate")&&(this.removeAttribute("data-duplicate"),qr(this))?this.setAttribute("data-value-on-focus",this.getAttribute("data-value-on-load")):""===this.value&&a.new_option===this.getAttribute("data-value-on-focus")||this.setAttribute("data-value-on-focus",this.value)}function Cr(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 Nr(){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=Cr(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(qr(this))return this.setAttribute("data-duplicate","true"),void(void 0!==A[s]&&void 0!==A[s][c]&&(A[s][c].value=c));void 0!==A[s]&&void 0!==A[s][c]&&(A[s][c].value=i);for(var d=[],f=O.querySelectorAll(".frm_logic_row"),u=f.length,m=0;m<u;m++){var _=f[m];if(_.querySelector(".frm_logic_field_opts").value===s){var p,g=_.id.split("_")[2],y=_.querySelector('select[name="field_options[hide_opt_'.concat(g,'][]"]')),v=void 0,h=void 0;(v=""===n?[]:y.querySelectorAll('option[value="'.concat(n,'"]'))).length||(v=y.querySelectorAll('option[value="'.concat(i,'"]'))).length||(null!==(p=l.querySelector(".frm_toggle_sep_values"))&&void 0!==p&&p.checked||(h=Tr(y,n)),h||(h=document.createElement("option"),y.append(h))),v.length&&(h=v[v.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],io(document.getElementById("frm-single-settings-".concat(t))))}}function Tr(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 Or(){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 Fr(){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"),yt(r,this.value))}function Dr(){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 Mr(){var e,t,r,n=jQuery(this).closest(".frm_field_box[data-ftype=break]");n.length?function(e){var t=Pr(e.get(0).parentNode.closest("li.frm_field_box").nextElementSibling);Hr(e,t)}(n):(e=document.getElementById("frm-fake-page"),t=document.getElementById("frm-show-fields").firstElementChild,r=Pr(t),"break"!==t.getAttribute("data-ftype")&&Hr(jQuery(e),r))}function Pr(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 Hr(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 zr(){this.parentNode.parentNode.parentNode.parentNode.classList.toggle("frm-section-collapsed")}function Rr(){this.nextElementSibling&&(this.nextElementSibling.style.animation=""),this.classList.toggle("frm-collapsed");var e="true"===this.getAttribute("aria-expanded")||!1;this.setAttribute("aria-expanded",!e),Gr(this.nextElementSibling)}function Gr(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 Ur(){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 Wr(){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0];void 0!==e&&setTimeout(function(){e.focus(),$r(e)},50)}function $r(e){var t=e.closest(".frm-collapse-me");null!==t&&t.previousElementSibling.classList.remove("frm-collapsed")}function Vr(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")||(Je(),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));io(a),o&&"quantity"===o&&nt(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:oo}),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=d({className:"frm-with-right-icon"});e.parentNode.insertBefore(t,e),t.append(i()),t.append(e)})}}}(o,n,a)}(t))}}function Kr(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 Jr(){var e=this.getAttribute("data-fid");$r(document.getElementById("field_options_field_key_".concat(e)))}function Xr(){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 Yr(){var e=this.value;""!==e&&(e<2||e>200)&&(M(a.repeat_limit_min),this.value="")}function Zr(){var e=this.value;""!==e&&(e<1||e>200)&&(M(a.checkbox_limit),this.value="")}function en(e,t){jQuery(e).closest(".frm_field_box").find(".frm_".concat(t,"_form_row .frm_repeat_label")).text(e.value)}function tn(){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",kn(t,e))}function rn(){var e=nn(this);if(e){var t=jQuery(this).closest(".frm_single_option");!function(e,t,r){var n=r.data("optkey"),o=vn(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 an(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,d=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 f=i[0].childNodes;if(hn(e)){var u=function(e,t,r){var n,o=e.find("img");o&&(n=o.attr("src"));var i=bn(t);return gn(r.val(),i,n)}(r,e,l),m=i.find(".frm_image_option_container");m.length>0?m.replaceWith(u):(f[f.length-1].nodeValue="",i.append(u))}else{var _=!1;f.forEach(function(t,r){if(!1===_)"INPUT"===t.tagName&&(_=r);else if(r===_+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=c({className:"frm_label_button_container",text:" ".concat(l.val())}),i[0].replaceChild(n,t))}else t.remove()})}d.val(s),defaultVal=r.find('input[name^="default_value_"]'),d.prop("checked",!!defaultVal.is(":checked"))}}(e.fieldId,e.fieldKey,t)}}function nn(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 on(e){var t,r=document.getElementById("field_options_image_size_".concat(e)),n="";return r&&""!==(t=r.value)&&(n=t),n}function an(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?fn(t[0],{sourceID:e,placeholder:n.value}):fn(t[0],{sourceID:e})}else{var o=mn(e),i=jQuery("#field_".concat(e,"_inner_container > .frm_form_fields")),a=hn(e),l=a?on(e):"",s=a?"frm_image_option frm_image_".concat(l," "):"";i.html("");for(var c=nn(jQuery("#frm_delete_field_".concat(e,"-000_container"))),d=Pi(e),f="hidden"===t.attr("type")?t.data("field-type"):t.attr("type"),u=0;u<o.length;u++)i.append(dn(f,o[u],e,c.fieldKey,d,s))}sn(e)}else sn(e)}}function ln(e,t){var r=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('input[value="'.concat(t,'"]'));return r?Cr(r):{newValue:t,newLabel:t}}function sn(e,t){for(var r=O.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[f],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=ln(e,r),l=a.newValue,s=a.newLabel,d=document.querySelectorAll("#frm_field_".concat(e,"_opts input[data-value-on-focus]")),u=Array.from(d).find(function(e){return e.value===r});if(u){var m=u.dataset.valueOnFocus;if(m&&c.querySelector('option[value="'.concat(m,'"]')))return 1}cn(c,i,l,s)},f=i-1;f>=0;f--)d();var u=c.querySelector('option[value=""]');null!==u&&c.prepend(u)}}}function cn(e,t,r,n){null!==t||e.querySelector('option[value="'.concat(r,'"]'))||((t=frmDom.tag("option",{text:n})).value=r),e.prepend(t)}function dn(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(pn(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(pn(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 fn(e,t){if(e){var r=t.sourceID,n=t.placeholder,o=Pi(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=mn(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?un(e,n):l&&(c=n),l=!1,!d||i){var f=document.createElement("option");f.value=a[s].saved,f.innerHTML=pn(c),o&&f.setAttribute("data-price",a[s].price),e.append(f)}}}}function un(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 mn(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=Pi(e),f=bn(e),u=hn(e),m=vn(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)),u&&(o=gn(o,f,_n(c[t]))),a={saved:r,label:o=frmAdminBuild.hooks.applyFilters("frm_choice_field_label",o,e,c[t],u),checked:yn(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 _n(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 pn(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?pn(t):t}function gn(e,t,r){var n,o=e;o=pn(o),r?n=m({src:r,alt:o}):(n=c({className:"frm_empty_url"})).innerHTML=a.image_placeholder_icon;var i=t?" frm_label_with_image":"",l=[n];if(t){var d=s("span",{className:"frm_text_label_for_image_inner"});d.innerHTML=o,l.push(s("span",{className:"frm_text_label_for_image",child:d}))}return s("span",{className:"frm_image_option_container".concat(i),children:l})}function yn(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 vn(e){return jn("separate_value_".concat(e))}function hn(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 bn(e){var t=!jn("hide_image_text_".concat(e));return frmAdminBuild.hooks.applyFilters("frm_choice_field_showing_label_with_image",t,e)}function jn(e){var t=document.getElementById(e);return!!t&&t.checked}function wn(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&&M(q(I('Duplicate option value "%s" detected',"formidable"),pn(e.value)))}}function Qn(){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 f=document.querySelector("#frm_logic_".concat(r,"_").concat(n,' [name="field_options[hide_field_cond_').concat(r,'][]"]')).value;i.innerHTML="";var u=c&&!["LIKE","not LIKE","LIKE%","%LIKE"].includes(f);u?s=document.createElement("select"):(s=document.createElement("input")).type="text",s.name=a,s.id="".concat(l,"_").concat(n),i.append(s),u&&fn(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 xn(){var e=this.value;e&&kn(e,jQuery(this).closest(".frm-single-settings").data("fid"))}function kn(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 En(){var e=this;return this.initOnceInAllInstances=function(){void 0===En.prototype.orderFieldsObject&&(En.prototype.orderFieldsObject={},En.prototype.fieldSettingsForm=document.getElementById("frm-end-form-marker").closest("form"))},this.getFieldOrderInputById=function(e,t){var r,n=En.prototype.orderFieldsObject,o=En.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(),Dr(),function(){var t,r,n,o,i,a,l=new io,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),Ro());l.moveFields()}()}function An(){document.querySelectorAll(".start_divider").forEach(function(e){Sn(jQuery(e))})}function Sn(e){if(e.length){for(var t=e.find("ul.frm_sorting"),r=!1,n=t.length,o=0;o<n;++o)if(0!==ae(jQuery(t.get(o))).length){r=!0;break}e.parent().children(".frm_no_section_fields").get(0).classList.toggle("frm_block",!r)}}function Ln(){var e=jQuery(this).data("slidedown"),t=jQuery(document.getElementById(e));return t.is(":hidden")&&(t.slideDown("fast"),this.style.display="none"),!1}function In(){var e=jQuery(this).data("slideup"),t=jQuery(document.getElementById(e));return t.slideUp("fast"),t.siblings("a").show(),!1}function qn(e,t){""===t.getAttribute("value")?Bn(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 Bn(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 Bn(e){e.val(""),e.next(".btn-group").find('.multiselect-container input[value!=""]').prop("checked",!1)}function Cn(){jQuery(".frm-hide-empty").each(function(){0===jQuery(this).text().trim().length&&jQuery(this).remove()})}function Nn(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=Ko(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")&&et(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 Tn(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 On(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 Fn(){var e,t=this.getAttribute("data-frmchange").split(",");for(e=0;e<t.length;e++)"updateOption"===t[e]?Mn(this):"updateDefault"===t[e]?Dn(this):"checkUniqueOpt"===t[e]?wn(this):this.value=this.value[t[e]]()}function Dn(e){var t=Pn(e),r=t.getAttribute("data-optkey"),n=Hn(t,r),o=t.querySelector('input[name="default_value_'.concat(n,'"]'));null!==o&&(o.value=e.value)}function Mn(e){var t,r=Pn(e),n=r.getAttribute("data-optkey"),o=Hn(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,Dn(t))}function Pn(e){var t=e.parentNode;return"LI"!==t.tagName&&(t=t.parentNode),t}function Hn(e,t){return e.id.replace("frm_delete_field_","").replace("-".concat(t,"_container"),"")}function zn(){var e=this;if(!Wn()){Kn(this);var t=jQuery(j),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(),x=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(){Rn(document.getElementById("frm_js_build_form"))}})}}function Rn(e){var t=e.ownerDocument.createElement("input");t.style.display="none",t.type="submit",e.append(t),t.click(),t.remove()}function Gn(e){jQuery(e).trigger("change")}function Un(){if(!Wn()){Kn(this);var e=jQuery(j);jQuery(document.getElementById("frm_compact_fields")).val(JSON.stringify(e.serializeArray())),Rn(document.getElementById("frm_js_build_form"))}}function Wn(){if((t=document.getElementById("frm_form_name"))&&""!==t.value.trim()||"true"!==T.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=Ni("#frm-form-templates-modal","440px");return!!r&&(Vo(r,"72px"),r.dialog("open"),!0)}function $n(){var e=document.getElementById("frm-save-form-name-button"),t=document.getElementById("frm_new_form_name_input");_(e,Vn),t.addEventListener("keydown",function(e){"Enter"===e.key&&Vn(e)})}var Vn=function(e){var t=document.getElementById("frm_new_form_name_input").value.trim(),r=new FormData;r.append("form_id",T.get("id")),r.append("form_name",t),p("rename_form",r).then(function(e){T.delete("new_template"),N.search=T.toString(),history.replaceState({},"",N.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 Kn(e){var t,r;Oi(),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 Jn(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:c({className:"inside",child:d(i)})}))}}function Xn(e){var t,n,o,i=e.dataset.upgrade,a=e.getAttribute("href").replace("#",""),l=document.querySelector(".frm_".concat(a))||document.querySelector(".".concat(a));if(l&&!l.querySelector(".frm-upgrade-message")){var s=l.querySelector("h2");s.style.borderBottom="none",s.textContent=q(I("%s are not installed","formidable"),i),l.classList.add("frmcenter");var d=document.getElementById("frm_upgrade_modal");v("frm-oneclick"),v("frm-addon-status");var f=d.querySelector(".frm-upgrade-link");if(f){var u,_,p=f.closest(".frm-upgrade-modal-actions"),g=(_=p?(p=p.cloneNode(!0)).querySelector(".frm-upgrade-link"):f.cloneNode(!0)).querySelector(".license-level");g&&(g.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(e)),l.append(p||_),null!==(u=f.nextElementSibling)&&void 0!==u&&u.querySelector(".frm-link-secondary")&&l.append(f.nextElementSibling.cloneNode(!0)),v("frm-oneclick-button")}v("frm-upgrade-message");var y=e.dataset.message;void 0===y&&(y=e.dataset.upgrade),function(e,t,n){r(4260).addOneClick(e,"tab",n)}(e,0,y),e.dataset.screenshot&&l.append((t=e.dataset.screenshot,o="".concat(frmGlobal.url,"/images/screenshots/"),c({className:"frm-settings-screenshot-wrapper",children:[(n=["#ED8181","#EDE06A","#80BE30"].map(function(e){var t=c({className:"frm-minmax-icon"});return t.style.backgroundColor=e,t}),n.push(m({src:"".concat(frmGlobal.url,"/images/tab.svg")})),c({className:"frm-settings-screenshot-toolbar",children:n})),c({child:m({src:o+t})})]})))}function v(e){l.append(d.querySelector(".".concat(e)).cloneNode(!0))}}function Yn(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 Zn(){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 eo(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=to(l),d=null===(t=o.querySelector(".frm_action_name"))||void 0===t?void 0:t.value,f=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+\)$/,""),ro(d));a[0].querySelector(".widget-title h4 span:not(.frm-border-icon)").textContent=f,a[0].querySelector('input[name$="['.concat(l,'][post_title]"]')).value=f,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"),m=new RegExp("_".concat(l,'"'),"g"),_=new RegExp("_".concat(l," "),"g"),p=new RegExp("-".concat(l,'"'),"g"),g=new RegExp('"'.concat(l,'"'),"g"),y=a.html().replace(u,"[".concat(s,"]")).replace(m,"_".concat(s,'"'));y=(y=y.replace(_,"_".concat(s," "))).replace(p,"-".concat(s,'"')).replace(g,'"'.concat(s,'"'));var v=c({id:"frm_form_action_".concat(s),className:a.get(0).className});v.setAttribute("data-actionkey",s),v.innerHTML=y,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")&&bi(v),ui(),wp.hooks.doAction("frm_after_duplicate_action",v)}}function to(e){var t=parseInt(e,10)+11;return document.getElementById("frm_form_action_".concat(t))&&(t=to(++t)),t}function ro(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 no(){var e,t=jQuery(this).data("actiontype");if(!fo(t)){var r=(e=Lr(document.querySelectorAll(".frm_form_action_settings"),"frm_form_action_"),void 0!==document.getElementById("frm_form_action_".concat(e))&&(e+=100),S>=e&&(e=S+1),S=e,e),n=k,o=ro(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;Ro(),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=c();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,d,f=document.getElementById("frm_form_action_".concat(r));f.classList.add("open"),document.getElementById("post-body-content").scroll({top:f.offsetTop+10,left:0,behavior:"smooth"}),co(t),(d=["stripe","square","paypal"]).includes(s=t)&&d.forEach(function(e){e!==s&&co(e)}),Yn("#frm_form_action_".concat(r)),ui(),bi(f),l&&jQuery(l).trigger("frm-action-loaded"),frmAdminBuild.hooks.doAction("frm_added_form_action",f)}})}}function oo(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 io(e){var t=this;if(null!==e)return this.fragment=document.createDocumentFragment(),this.initOnceInAllInstances=function(){void 0===io.prototype.endMarker&&(io.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(){j.insertBefore(t.fragment,io.prototype.endMarker)},this.initOnceInAllInstances(),void 0!==e?(this.append(e),void this.moveFields()):{append:this.append,moveFields:this.moveFields}}function ao(){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 lo(){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 so(){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 co(e){var t,r,n=document.querySelectorAll(".frm_".concat(e,"_action"));fo(e)?(t=n,r=uo(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 fo(e){var t=function(e){return["paypal","stripe","square"].includes(e)&&(e="payment"),jQuery(".frm_single_".concat(e,"_settings")).length}(e)>=uo(e),r={type:e};return wp.hooks.applyFilters("frm_action_at_limit",t,r)}function uo(e){return parseInt(jQuery(".frm_".concat(e,"_action")).data("limit"),10)}function mo(){var e=a.only_one_action,t=this.dataset.limit,r=this.dataset.actiontype;r&&["paypal","stripe","square","payment"].includes(r)&&(e="stripe"===r?a.only_one_stripe_action:a.only_one_payment_action),void 0!==t&&((t=parseInt(t))>1?e=e.replace(1,t).trim():e+=" ".concat(a.edit_action_text)),M(e)}function _o(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=Lr(o.querySelectorAll(".frm_logic_row"),"frm_logic_".concat(e,"_")),a=c({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 po(){return _o(jQuery(this).data("emailkey"),this),!1}function go(){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")&&_o(t,this)}}}function yo(){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(""),M(a.field_already_used),!1})}function vo(){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 ho(){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 bo(){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&&jo(n,i,"frm_get_post_parent_option",function(e,t){n.querySelector(".frm_post_parent_opt_wrapper").innerHTML=e.replaceAll("REPLACETHISNAME",t),bi(n)}),o&&jo(o,i,"frm_should_use_post_menu_order_option")}function jo(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 wo(){xo("tax",this)}function Qo(){xo("meta",this)}function xo(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 ko(){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 Eo(){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 Ao(){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 So(){Wn()||(Kn(this),Rn(document.querySelector(".frm_form_settings")))}function Lo(e){return e.preventDefault(),Io(jQuery(this),this.getAttribute("data-code")),!1}function Io(e,t){var r=!1,n=e;if("object"===o(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 i=document.activeElement;"search"===i.type?null===(n=i.id.replace("-search-input","")).match(/\d/gi)&&(n=(i=jQuery(".frm-single-settings:visible .".concat(n))).attr("id")):n=i.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 qo(a,e)}})}else t=function(e,t,r){return"object"===o(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):qo(a,t);return!1}function qo(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")&&Bo(t)){var r=e.value.split(" ").filter(Bo);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)}Gn(e)}function Bo(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 Co(){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"),Li(t,"change")):(e.classList.add("frm_hidden"),t.classList.remove("frm_hidden"),Li(e,"change"))}function No(){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+a.conditional_text,"[/if ").concat(o)),n.innerHTML="[".concat(i,"[/if ").concat(o,"]")}function To(e){return e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href")}function Oo(e){var t;e.parentNode.parentNode.classList.contains("frm_has_shortcodes")&&(Xo(),"use"===(t=Jo(e)).tagName?To(t=t.firstElementChild).includes("frm_close_icon")||Ho(t,"nofocus"):t.classList.contains("frm_close_icon")||Ho(t,"nofocus"))}function Fo(e){e.preventDefault(),e.stopPropagation(),Ho(this)}function Do(e){!function(e){var t;if(e.id.startsWith("field_options_type_")){var r=e.id.split("_"),n=r.length&&r[r.length-1];null!==(t=document.querySelector("#frm-single-settings-".concat(n)))&&void 0!==t&&t.classList.contains("frm-type-".concat(e.value))||Mo()}}(e.target)}function Mo(e){var t;void 0===e&&(e=I("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:I("Save and Reload?","formidable"),content:(t=c(e),t.style.padding="var(--gap-md)",t),footer:function(){var e=frmDom.modal.footerButton({text:I("Save and Reload","formidable"),buttonType:"primary"});_(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:I("Cancel","formidable"),buttonType:"cancel"});return t.classList.add("dismiss"),frmDom.div({children:[t,e]})}()})}function Po(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 Ho(e,t){var r=Ko(e),n=document.getElementById("frm_adv_info"),o=e.className;if("svg"===e.tagName&&(e=e.firstElementChild),"use"===e.tagName&&(o=To(e)),o.includes("frm_close_icon"))Xo(n);else{if(Po(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 l=document.createElementNS("http://www.w3.org/2000/svg","use");l.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon"),e.parentNode.replaceChild(l,e)}else e.className=o.replace("frm_more_horiz_solid_icon","frm_close_icon");"nofocus"!==t&&("none"!==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=a.contextualShortcodes["".concat(t,"Selector")],o=a.contextualShortcodes[t],l=e.matches(n),s=i(o);try{for(s.s();!(r=s.n()).done;){var c,d=r.value,f=null===(c=document.querySelector('#frm-adv-info-tab .frm_code_list [data-code="'.concat(d,'"]')))||void 0===c?void 0:c.closest("li");null==f||f.classList.toggle("frm_hidden",!l)}}catch(e){s.e(e)}finally{s.f()}}(e,t)})}(r)}}function zo(e){return 0===a.contextualShortcodes.length||!function(e){var t=e.querySelector("a");if(!t)return!1;var r=t.dataset.code;return a.contextualShortcodes.address.includes(r)||a.contextualShortcodes.body.includes(r)}(e)||function(e){var t=e.querySelector("a").dataset.code,r=document.getElementById("frm_adv_info").dataset.fills,n=document.getElementById(r),o=a.contextualShortcodes;return o.address.includes(t)?n.matches(o.addressSelector):n.matches(o.bodySelector)}(e)}function Ro(){x||(x=1,window.addEventListener("beforeunload",$o))}function Go(){x=0}function Uo(){x=0}function Wo(){x=0}function $o(e){x&&(e.preventDefault(),e.returnValue="")}function Vo(e,t){var r={my:"top",at:"top+".concat(t),of:window};e.dialog("option","position",r)}function Ko(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=Ko(r);return r||(r=null===(t=e.closest(".frm-field-formula"))||void 0===t?void 0:t.querySelector(".frm-calc-field")),r}function Jo(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=Jo(r);return r}function Xo(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"===To(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 Yo(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 Zo(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 ei(){return!0===D(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 ti(){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 ri(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(),C.importQueue=r,C.imported=0,ni(i)}}function ni(e){var t=C.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(),C.importQueue=jQuery.grep(C.importQueue,function(e){return e!=t}),C.imported++,0===C.importQueue.length?(e.find(".process-count").hide(),e.find(".forms-completed").text(C.imported),e.find(".process-completed").show()):(e.find(".form-current").text(C.imported+1),ni(e)))})}function oi(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 ii(){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 ai(){null!==jQuery(this).val().match(/\.csv$/i)?jQuery(".show_csv").fadeIn():jQuery(".show_csv").fadeOut()}function li(){var e=document.querySelector('select[name="format"]');return e?e.value:""}function si(e){var t,r,n=e.target.value;di(n),ci.call(e.target),t=n,r=document.getElementById("frm-export-select-all"),"csv"===t?(r.checked=!1,r.disabled=!0):r.disabled=!1}function ci(){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 di(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")}),Ei.call(document.querySelector(".frm-auto-search")))}}function fi(){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 ui(){jQuery(".frm_multiselect").hide().each(frmDom.bootstrap.multiselect.init)}function mi(e){e.preventDefault(),gi(this,"frm_multiple_addons")}function _i(e){e.preventDefault(),gi(this,"frm_activate_addon")}function pi(e){e.preventDefault(),gi(this,"frm_install_addon")}function gi(e,t){r(1105).toggleAddonState(e,t)}function yi(){hi()}function vi(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 hi(){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 bi(e){frmDom.autocomplete.initSelectionAutocomplete(e)}function ji(e){var t=this.parentNode.parentNode,r=t.elements.type.value;e.preventDefault(),this.classList.add("frm_loading_button"),Qi(t,r,this)}function wi(e){var t=this.elements.type.value,r=this.querySelector("button");e.preventDefault(),r.classList.add("frm_loading_button"),Qi(this,t,r)}function Qi(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};Ii(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=c(e);t.style.padding="20px 40px",frmDom.modal.maybeCreateModal("frmInstallFormErrorModal",{title:I("Unable to install template","formidable"),content:t}).classList.add("frm_common_modal")}(t.message);var i;r.classList.remove("frm_loading_button")})}function xi(e){var t=document.getElementById("frm_captcha_threshold_container");t&&t.classList.toggle("frm_hidden","v3"!==e.target.value)}function ki(e){var t=this.getAttribute("data-id");e.preventDefault(),Ii({action:"frm_forms_trash",id:t,nonce:frmGlobal.nonce},function(){var e=document.getElementById("frm-template-custom-".concat(t));qi(e,function(){e.remove()})})}function Ei(){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"===li()&&i[e].classList.contains("frm-is-repeater"));""===n?(l&&zo(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.remove("frm-search-result")):r&&new RegExp(n).test(a)||a.includes(n)||Ai(a,n)?(l&&zo(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 Ai(e,t){return"s"!==t&&"s"!==e[e.length-1]&&"".concat(e,"s").includes(t)}function Si(e){e.stopPropagation()}function Li(e,t){var r=document.createEvent("HTMLEvents");r.initEvent(t,!1,!0),e.dispatchEvent(r)}function Ii(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 qi(e,t){e.classList.add("frm-fade"),setTimeout(t,1e3)}function Bi(e){jQuery(e).css("visibility","hidden")}function Ci(e){jQuery(e).css("visibility","visible")}function Ni(e,t){return r(4260).initModal(e,t)}function Ti(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 Oi(){window.onbeforeunload=null;var e=jQuery(window);e.off("beforeunload.widgets"),e.off("beforeunload.edit-post")}function Fi(){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 Di(e){var t=e.target,r=t.value.trim();if(!r.includes("[")||!r.includes("]")){if(isNaN(r.replace(/,/,""))){var n=I("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 Mi(){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 Pi(e){var t=document.getElementById("frm_field_id_".concat(e));return!!t&&"product"===t.getAttribute("data-type")}function Hi(){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 zi(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=To(n))&&(i=!0),"#frm_save_icon"===o&&(a=!0))}),i||r.prepend(h.drag.cloneNode(!0)),r.querySelector("[id^=field_key_".concat(e,"-]"))&&!a&&r.querySelector("[id^=field_key_".concat(e,"-]")).after(h.save.cloneNode(!0)),t.newOption&&(t.newOption=r)}function Ri(){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=d({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(d(I("Thank you for signing up!","formidable")))}else vi("invalid")})}}else vi("invalid");else vi("empty")}function Gi(e){var t;if(O||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||Xo(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(),Ri()});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(){z()}),C={},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",St),void 0===k&&(k=jQuery(document.getElementById("form_id")).val()),document.querySelectorAll(".frm-warning-dismiss").forEach(function(e){_(e,Lt)}),frmAdminBuild.inboxBannerInit(),b.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=c({className:"frm_warning_style",text:I("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}))})})}}}(),bi(),jQuery("[data-frmprint]").on("click",function(){return window.print(),!1})),jQuery(document).on("change","select[data-toggleclass], input[data-toggleclass]",Ao),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]",xr),jQuery(a).on("click","[data-removeid]",R),jQuery(a).on("click","[data-trashtemplate]",ki),i.on("click",".frm_remove_tag, .frm_remove_form_action",R),i.on("click","a[data-frmverify]",F),i.on("click","a[data-frmtoggle]",P),i.on("click","a[data-frmhide], a[data-frmshow]",H),i.on("change","input[data-frmhide], input[data-frmshow]",H),i.on("click",".widget-top,a.widget-action",U),function(e){e.on("keydown",".widget-top",function(e){e.currentTarget===e.target&&("Enter"!==e.key&&" "!==e.key||(e.preventDefault(),U(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),jQuery(r).tooltip(),t&&(z(),jQuery(r).tooltip("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(),D(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]",Jn);var d=jQuery(document.getElementById("frm_shortcodediv"));d.length>0&&(jQuery("a.edit-frm_shortcode").on("click",function(){return d.is(":hidden")&&(d.slideDown("fast"),this.style.display="none"),!1}),jQuery(".cancel-frm_shortcode","#frm_shortcodediv").on("click",function(){return d.slideUp("fast"),d.siblings("a.edit-frm_shortcode").show(),!1})),jQuery(document).on("click","#frm-nav-tabs a",W),jQuery(".post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a").on("click",function(){var e=this.classList.contains("frm_show_upgrade_tab");if(!this.classList.contains("frm_noallow")||e)return e&&Xn(this),$(this),!1}),$(jQuery(".starttab a"),"auto"),jQuery(document).on("click","#frm-fid-search-menu a",function(){var e=this.id.replace("fid-","");return jQuery('select[name="fid"]').val(e),Rn(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)",Ei),jQuery(document).on("focusin click",".frm-auto-search",Si);var f=jQuery(".frm-auto-search");""!==f.val()&&f.trigger("keyup"),FrmFormsConnect.init(),jQuery(document).on("click",".frm-install-addon",pi),jQuery(document).on("click",".frm-activate-addon",_i),jQuery(document).on("click",".frm-solution-multiple",mi),jQuery("button, input[type=submit]").on("click",Oi),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]}),document.querySelectorAll("#frm-show-fields > li, .frm_grid_container li").forEach(function(e,t){e.addEventListener("click",function(){var e,t,r;t=(null===(e=this.querySelector("li"))||void 0===e?void 0:e.dataset.fid)||this.dataset.fid,(r=document.querySelectorAll("[id^=frm_delete_field_".concat(t,"-]"))).length<2||n(r).slice(1).forEach(function(e,r){e.classList.contains("frm_other_option")||zi(t,e)})})});var u=document.getElementById("frm_small_screen_proceed_button");u&&_(u,function(){var e;null===(e=document.getElementById("frm_small_device_message_container"))||void 0===e||e.remove(),p("small_screen_proceed",new FormData)});var m=document.getElementById("frm_sale_banner"),g=null==m?void 0:m.querySelector(".dismiss");m&&(_(m,function(e){e.target.closest(".dismiss")||(window.location.href=m.getAttribute("data-url"))}),g&&_(g,function(){m.remove();var e=new FormData;p("sale_banner_dismiss",e)}))},buildInit:function(){jQuery("#frm_builder_page").on("mouseup","*:not(.frm-show-box)",Gi),g=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return frmDom.util.debounce(e,t)}(ie,10),y=document.getElementById("post-body-content"),v=jQuery(y),jQuery(".frm_field_loading").length&&Ee(jQuery(".frm_field_loading").first().attr("id")),V("ul.frm_sorting"),document.querySelectorAll(".field_type_list > li:not(.frm_show_upgrade):not(.frm_show_update)").forEach(Y),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",zn),jQuery(".frm_submit_no_ajax").on("click",Un),$n(),jQuery("a.edit-form-status").on("click",Ln),jQuery(".cancel-form-status").on("click",In),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")}),ui(),Dr();var e,t=jQuery(j),r=document.getElementById("frm_form_editor_container");t.on("click",".frm_add_logic_row",Sr),t.on("click",".frm_add_watch_lookup_row",Ir),t.on("change",".frm_get_values_form",Or),t.on("change",".frm_logic_field_opts",Qn),t.on("frm-multiselect-changed",'select[name^="field_options[admin_only_"]',qn),jQuery(document.getElementById("frm-insert-fields")).on("click",".frm_add_field",Se),b.on("click",".frm_clone_field",Be),t.on("blur",'input[id^="frm_calc"]',Xe),t.on("change","input.frm_format_opt, input.frm_max_length_opt",st),t.on("change click","[data-changeme]",at),t.on("click","input.frm_req_field",ct),t.on("click",".frm_mark_unique",ft),t.on("change",".frm_repeat_format",Xr),t.on("change",".frm_repeat_limit",Yr),t.on("change",".frm_js_checkbox_limit",Zr),t.on("input",'input[name^="field_options[add_label_"]',function(){en(this,"add")}),t.on("input",'input[name^="field_options[remove_label_"]',function(){en(this,"remove")}),t.on("change",'select[name^="field_options[data_type_"]',Fr),jQuery(r).on("click",".frm-collapse-page",Mr),jQuery(r).on("click",".frm-collapse-section",zr),t.on("click",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",Rr),t.on("keydown",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),Rr.call(this,e))}),jQuery(r).on("show.bs.dropdown hide.bs.dropdown",ze),t.on("change",".frm_toggle_sep_values",vt),t.on("change",".frm_toggle_image_options",ht),t.on("click",".frm_remove_image_option",Et),t.on("click",".frm_choose_image_box",kt),t.on("change",".frm_hide_image_text",xt),t.on("change",".frm_field_options_image_size",wt),t.on("click",".frm_multiselect_opt",At),b.on("mousedown","input, textarea, select",It),b.on("click","input[type=radio], input[type=checkbox]",It),b.on("click",".frm_delete_field",Tt),b.on("click",".frm_select_field",Ot),jQuery(document).on("click",".frm_delete_field_group",Ft),jQuery(document).on("click",".frm_clone_field_group",Dt),jQuery(document).on("click","#frm_field_group_controls > span:first-child",Mt),jQuery(document).on("click",".frm-row-layout-option",Zt),jQuery(document).on("click",".frm-merge-fields-into-row .frm-row-layout-option",er),jQuery(document).on("click",".frm-custom-field-group-layout",rr),jQuery(document).on("click",".frm-merge-fields-into-row .frm-custom-field-group-layout",or),jQuery(document).on("click",".frm-break-field-group",cr),b.on("click","#frm_field_group_popup .frm_grid_container input",dr),jQuery(document).on("click",".frm-cancel-custom-field-group-layout",fr),jQuery(document).on("click",".frm-save-custom-field-group-layout",mr),b.on("click","ul.frm_sorting",_r),jQuery(document).on("click",".frm-merge-fields-into-row",jr),jQuery(document).on("click",".frm-delete-field-groups",Qr),b.on("click",'.frm-field-action-icons [data-toggle="dropdown"]',function(){this.closest("li.form-field").classList.add("frm-field-settings-open"),jQuery(document).on("click","#frm_builder_page",Oe)}),b.on("mousemove","ul.frm_sorting",Fe),b.on("show.bs.dropdown",".frm-field-action-icons",Pe),jQuery(document).on("show.bs.dropdown","#frm_field_group_controls",He),t.on("click",".frm_single_option a[data-removeid]",qt),t.on("mousedown",".frm_single_option input[type=radio]",Bt),t.on("focusin",".frm_single_option input[type=text]",Ct),t.on("click",".frm_add_opt",pt),t.on("change",".frm_single_option input",rn),t.on("change",".frm_image_id",rn),t.on("change",".frm_toggle_mult_sel",gt),b.on("click",".frm_primary_label",Ur),b.on("click",".frm_description",Wr),b.on("click","li.ui-state-default:not(.frm_noallow)",Vr),b.on("dblclick","li.ui-state-default",Jr),t.on("change",".frm_tax_form_select",tn),t.on("change","select.conf_field",ut),t.on("change",".frm_get_field_selection",xn),t.on("click",".frm-show-inline-modal",Nn),t.on("keydown",".frm-show-inline-modal",function(e){var t=e.key;"Enter"!==t&&" "!==t||(e.preventDefault(),Nn.call(this,e))}),t.on("click",".frm-inline-modal .dismiss",Tn),jQuery(document).on("change","[data-frmchange]",Fn),document.addEventListener("click",On),t.on("change",".frm_include_extras_field",tt),t.on("change",'select[name^="field_options[form_select_"]',Fi),jQuery(document).on("submit","#frm_js_build_form",Go),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",Ro),ot(),frmDom.util.documentOn("change",".frm_product_price",Di),jQuery(document).on("change",".frmjs_prod_data_type_opt",Mi),jQuery(document).on("focus",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',Br),jQuery(document).on("blur",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',Nr),frmDom.util.documentOn("click",".frm-show-field-settings",Vr),frmDom.util.documentOn("change","select.frm_format_dropdown, select.frm_phone_type_dropdown",Kr),t.on("keydown",'.frm_single_option input[name^="field_options["], .frm_single_option input[name^="rows_"]',function(e){"Enter"===e.key&&function(e){var t=e.closest(".frm_single_option").parentElement.querySelectorAll('.frm_single_option input[name^="field_options[" ], .frm_single_option input[name^="rows_"]'),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!==(e=Ni("#frm-bulk-modal","700px"))&&(jQuery(".frm-insert-preset").on("click",_t),jQuery(j).on("click","a.frm-bulk-edit-link",function(t){t.preventDefault();var r="",n=jQuery(this).closest("[data-fid]").data("fid"),o=vn(n),i=Pi(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&&(r+=d.value,o&&(r+="|".concat(document.getElementsByName("field_options[options_".concat(n,"][").concat(c,"][value]"))[0].value)),i&&(r+="|".concat(document.getElementsByName("field_options[options_".concat(n,"][").concat(c,"][price]"))[0].value)),r+="\r\n")}s>=l.length-1&&(document.getElementById("frm_bulk_options").value=r)}return e.dialog("open"),!1}}),jQuery("#frm-update-bulk-opts").on("click",function(){var t=document.getElementById("bulk-field-id").value;document.getElementById("bulk-option-type").value||(this.classList.add("frm_loading_button"),frmAdminBuild.updateOpts(t,document.getElementById("frm_bulk_options").value,e),Ro())})),Cn(),document.addEventListener("frm_added_field",Cn),qe(),Hi(),An(),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",Po,!0),document.addEventListener("change",Do),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(Gr)},9999),frm_admin_js.pricingFieldsModal&&"object"===o(frm_admin_js.pricingFieldsModal)&&M(frm_admin_js.pricingFieldsModal,"550px")},settingsInit:function(){var e=jQuery(document.getElementById("frm_notification_settings"));e.on("click",".frm_email_buttons",ao),e.on("click",".frm_remove_field",lo),e.on("change",".frm_to_row, .frm_from_row",so),e.on("change",".frm_tax_selector",ko),e.on("change","select.frm_single_post_field",yo),e.on("change","select.frm_toggle_post_content",vo),e.on("change","select.frm_dyncontent_opt",ho),e.on("change",".frm_post_type",bo),e.on("click",".frm_add_postmeta_row",Qo),e.on("click",".frm_add_posttax_row",wo),e.on("click",".frm_toggle_cf_opts",Eo),e.on("click",".frm_duplicate_form_action",eo),jQuery(".frm_actions_list").on("click",".frm_active_action",no),jQuery(document).on("frmAfterSearch","#actions-search-input",G),ui(),document.querySelectorAll(".frm_actions_list a[data-actiontype]").forEach(function(e){return co(e.dataset.actiontype)}),jQuery(".frm_submit_settings_btn").on("click",So),$n();var t=jQuery(".frm_form_settings");t.on("click",".frm_add_form_logic",po),t.on("change","input[data-emailkey][data-toggleclass]",go),t.on("click",".frm_already_used",mo),document.addEventListener("click",function(e){var t=e.target;t.closest(".frm_image_preview_wrapper")&&(t.closest(".frm_choose_image_box")?kt.bind(t)(e):t.closest(".frm_remove_image_option")&&Et.bind(t)(e))}),t.on("mouseup","*:not(.frm-show-box)",Gi),jQuery(document.getElementById("no_save")).on("change",function(){this.checked&&!0!==confirm(a.no_save_warning)&&jQuery(this).attr("checked",!1)}),jQuery('select[name="options[edit_action]"]').on("change",Zn);var r=document.getElementById("logged_in");jQuery(r).on("change",function(){this.checked?Ci(".hide_logged_in"):Bi(".hide_logged_in")});var n=jQuery(document.getElementById("frm_cookie_expiration"));jQuery(document.getElementById("frm_single_entry_type")).on("change",function(){"cookie"===this.value?n.fadeIn("slow"):n.fadeOut("slow")});var o=document.getElementById("single_entry");jQuery(o).on("change",function(){this.checked?Ci(".hide_single_entry"):Bi(".hide_single_entry"),this.checked&&"cookie"===jQuery(document.getElementById("frm_single_entry_type")).val()?n.fadeIn("slow"):n.fadeOut("slow")}),jQuery(".hide_save_draft").hide();var i=jQuery(document.getElementById("save_draft"));i.on("change",function(){this.checked?jQuery(".hide_save_draft").fadeIn("slow"):jQuery(".hide_save_draft").fadeOut("slow")}),Gn(i);var l=document.getElementById("editable");jQuery(l).on("change",function(){this.checked?(jQuery(".hide_editable").fadeIn("slow"),Gn(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",qn),jQuery(document).on("submit",".frm_form_settings",Uo),jQuery(document).on("change","#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea",Ro),bi(),jQuery(document).on("frm-action-loaded",Zo),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",Wo)},panelInit:function(){jQuery(".frm_wrap, #postbox-container-1").on("click",".frm_insert_code",Lo),jQuery(document).on("change",".frm_insert_val",function(){Io(jQuery(this).data("target"),jQuery(this).val()),jQuery(this).val("")}),jQuery(document).on("click change",'[name="frm-id-key-condition"]',Co),jQuery(document).on("keyup change",".frm-build-logic",No),Yn(),jQuery(document).on("frmElementAdded",function(e,t){Yn(t)}),jQuery(document).on("mousedown",".frm-show-box",Fo);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||O)&&jQuery(document).on("focusin","form input, form textarea",function(n){var o,i,a;if(n.stopPropagation(),Oo(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||O)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){Yo("frmids",e)}),n.on("click",".subsubsub a.frmkeys",function(e){Yo("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})),Ii(a,function(){if(!l)return"#"!==n?(window.location=n,!0):void qi(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"),yi()),t.remove()})})}}),!1===(null===(e=document.getElementById("frm_empty_inbox"))||void 0===e?void 0:e.classList.contains("frm_hidden"))&&yi()},solutionInit:function(){jQuery(document).on("submit","#frm-new-template",wi)},styleInit:function(){var e=jQuery(".frm_image_preview_wrapper");e.on("click",".frm_choose_image_box",kt),e.on("click",".frm_remove_image_option",Et),wp.hooks.doAction("frm_style_editor_init")},customCSSInit:function(){console.warn("Calling frmAdminBuild.customCSSInit is deprecated.")},globalSettingsInit:function(){jQuery(document).on("click","[data-frmuninstall]",ei),ui();var e=document.getElementById("licenses_settings");e&&jQuery(e).on("click",".edd_frm_save_license",ti),jQuery(document).on("click","#frm-new-template button",ji),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",xi),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(){x=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",ri),jQuery(document.getElementById("frm_export_xml")).on("submit",oi),jQuery("#frm_export_xml input, #frm_export_xml select").on("change",ii),jQuery('input[name="frm_import_file"]').on("change",ai),document.querySelector('select[name="format"]').addEventListener("change",si),jQuery('input[name="frm_export_forms[]"]').on("click",fi),ui(),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()}),di(li()),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&&Ii({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=vn(e),o=Pi(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),an(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)}},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:Ni,infoModal:M,offsetModalY:Vo,adjustConditionalLogicOptionOrders:sn,addRadioCheckboxOpt:dn,installNewForm:Qi,toggleAddonState:gi,purifyHtml:pn,loadApiEmailForm:hi,addMyEmailAddress:Ri,fillDropdownOpts:fn,showSaveAndReloadModal:Mo,clearSettingsBox:Ke,deleteField:Er,insertFormField:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(r){var n=k,o=0;"summary"===e&&(o=b.children('li[data-type="break"]').length>0?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:Object.assign(pe(e,0,n,o),{field_options:t}),success:function(t){r(t),setTimeout(function(){En(),$e(t,!0);var r=ve(t);r&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:r,fieldType:e,form_id:n})},10)},error:be})})},confirmLinkClick:D,handleInsertFieldByDraggingResponse:ye,handleAddFieldClickResponse:Ie,syncLayoutClasses:le,moveFieldSettings:io,maybeCollapseSettings:Rr}},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()}})},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;
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 + cursorAt: {
886 + top: 0,
887 + left: 90 // The width of draggable button is 180. 90 should center the draggable on the cursor.
888 + }
889 + };
890 + if ( 'string' === typeof handle ) {
891 + settings.handle = handle;
892 + }
893 + jQuery( draggable ).draggable( settings );
894 + }
895 +
896 + function getDraggableHelper( event ) {
897 + const draggable = event.delegateTarget;
898 +
899 + if ( isFieldGroup( draggable ) ) {
900 + const newTextFieldClone = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_ttext' ).cloneNode( true );
901 + newTextFieldClone.querySelector( 'use' ).setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_field_group_layout_icon' );
902 + newTextFieldClone.querySelector( 'span' ).textContent = __( 'Field Group' );
903 + newTextFieldClone.classList.add( 'frm_field_box' );
904 + newTextFieldClone.classList.add( 'ui-sortable-helper' );
905 + return newTextFieldClone;
906 + }
907 +
908 + let copyTarget;
909 + const isNewField = draggable.classList.contains( 'frmbutton' );
910 + if ( isNewField ) {
911 + copyTarget = draggable.cloneNode( true );
912 + copyTarget.classList.add( 'ui-sortable-helper' );
913 + draggable.classList.add( 'frm-new-field' );
914 + return copyTarget;
915 + }
916 +
917 + if ( draggable.hasAttribute( 'data-ftype' ) ) {
918 + const fieldType = draggable.getAttribute( 'data-ftype' );
919 + copyTarget = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_t' + fieldType );
920 + copyTarget = copyTarget.cloneNode( true );
921 + copyTarget.classList.add( 'form-field' );
922 +
923 + copyTarget.classList.add( 'ui-sortable-helper' );
924 +
925 + if ( copyTarget ) {
926 + return copyTarget.cloneNode( true );
927 + }
928 + }
929 +
930 + return div({ className: 'frmbutton' });
931 + }
932 +
933 + function handleDragStart( event, ui ) {
934 + const container = document.getElementById( 'post-body-content' );
935 + container.classList.add( 'frm-dragging-field' );
936 +
937 + document.body.classList.add( 'frm-dragging' );
938 + ui.helper.addClass( 'frm-sortable-helper' );
939 +
940 + event.target.classList.add( 'frm-drag-fade' );
941 +
942 + unselectFieldGroups();
943 + deleteEmptyDividerWrappers();
944 + maybeRemoveGroupHoverTarget();
945 + closeOpenFieldDropdowns();
946 + deleteTooltips();
947 + }
948 +
949 + function handleDragStop() {
950 + const container = document.getElementById( 'post-body-content' );
951 + container.classList.remove( 'frm-dragging-field' );
952 + document.body.classList.remove( 'frm-dragging' );
953 +
954 + const fade = document.querySelector( '.frm-drag-fade' );
955 + if ( fade ) {
956 + fade.classList.remove( 'frm-drag-fade' );
957 + }
958 + }
959 +
960 + function handleDrag( event ) {
961 + const draggable = event.target;
962 + const droppable = getDroppableTarget();
963 +
964 + let placeholder = document.getElementById( 'frm_drag_placeholder' );
965 +
966 + if ( ! allowDrop( draggable, droppable ) ) {
967 + if ( placeholder ) {
968 + placeholder.remove();
969 + }
970 + return;
971 + }
972 +
973 + if ( ! placeholder ) {
974 + placeholder = tag( 'li', {
975 + id: 'frm_drag_placeholder',
976 + className: 'sortable-placeholder'
977 + });
978 + }
979 +
980 + if ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) ) {
981 + placeholder.style.left = 0;
982 + handleDragOverYAxis({ droppable, y: event.clientY, placeholder });
983 + return;
984 + }
985 +
986 + placeholder.style.top = '';
987 + handleDragOverFieldGroup({ droppable, x: event.clientX, placeholder });
988 + }
989 +
990 + function getDroppableTarget() {
991 + let droppable = document.getElementById( 'frm-show-fields' );
992 + while ( droppable.querySelector( '.frm-over-droppable' ) ) {
993 + droppable = droppable.querySelector( '.frm-over-droppable' );
994 + }
995 + if ( 'frm-show-fields' === droppable.id && ! droppable.classList.contains( 'frm-over-droppable' ) ) {
996 + droppable = false;
997 + }
998 + return droppable;
999 + }
1000 +
1001 + function handleFieldDrop( _, ui ) {
1002 + const draggable = ui.draggable[0];
1003 + const placeholder = document.getElementById( 'frm_drag_placeholder' );
1004 +
1005 + if ( ! placeholder ) {
1006 + ui.helper.remove();
1007 + debouncedSyncAfterDragAndDrop();
1008 + return;
1009 + }
1010 +
1011 + maybeOpenCollapsedPage( placeholder );
1012 +
1013 + const $previousFieldContainer = ui.helper.parent();
1014 + const previousSection = ui.helper.get( 0 ).closest( 'ul.frm_sorting' );
1015 + const newSection = placeholder.closest( 'ul.frm_sorting' );
1016 +
1017 + if ( draggable.classList.contains( 'frm-new-field' ) ) {
1018 + insertNewFieldByDragging( draggable.id );
1019 + } else {
1020 + moveFieldThatAlreadyExists( draggable, placeholder );
1021 + }
1022 +
1023 + const previousSectionId = previousSection && previousSection.classList.contains( 'start_divider' ) ? parseInt( previousSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0;
1024 + const newSectionId = newSection.classList.contains( 'start_divider' ) ? parseInt( newSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0;
1025 +
1026 + placeholder.remove();
1027 + ui.helper.remove();
1028 +
1029 + const $previousContainerFields = $previousFieldContainer.length ? getFieldsInRow( $previousFieldContainer ) : [];
1030 + maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields );
1031 + maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields );
1032 +
1033 + if ( previousSectionId !== newSectionId ) {
1034 + updateFieldAfterMovingBetweenSections( jQuery( draggable ) );
1035 + }
1036 +
1037 + debouncedSyncAfterDragAndDrop();
1038 + }
1039 +
1040 + /**
1041 + * If a page if collapsed, expand it before dragging since only the page break will move.
1042 + *
1043 + * @param {Element} placeholder
1044 + * @returns {void}
1045 + */
1046 + function maybeOpenCollapsedPage( placeholder ) {
1047 + if ( ! placeholder.previousElementSibling || ! placeholder.previousElementSibling.classList.contains( 'frm-is-collapsed' ) ) {
1048 + return;
1049 + }
1050 +
1051 + const $pageBreakField = jQuery( placeholder ).prevUntil( '[data-type="break"]' );
1052 + if ( ! $pageBreakField.length ) {
1053 + return;
1054 + }
1055 +
1056 + const collapseButton = $pageBreakField.find( '.frm-collapse-page' ).get( 0 );
1057 + if ( collapseButton ) {
1058 + collapseButton.click();
1059 + }
1060 + }
1061 +
1062 + function maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields ) {
1063 + if ( ! $previousFieldContainer.length ) {
1064 + return;
1065 + }
1066 +
1067 + if ( $previousContainerFields.length ) {
1068 + syncLayoutClasses( $previousContainerFields.first() );
1069 + } else {
1070 + maybeDeleteAnEmptyFieldGroup( $previousFieldContainer.get( 0 ) );
1071 + }
1072 + }
1073 +
1074 + function maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields ) {
1075 + if ( 0 !== $previousContainerFields.length || 1 !== getFieldsInRow( jQuery( draggable.parentNode ) ).length ) {
1076 + syncLayoutClasses( jQuery( draggable ) );
1077 + }
1078 + }
1079 +
1080 + /**
1081 + * Remove an empty field group, but don't remove an empty section.
1082 + *
1083 + * @param {Element} previousFieldContainer
1084 + * @returns {void}
1085 + */
1086 + function maybeDeleteAnEmptyFieldGroup( previousFieldContainer ) {
1087 + const closestFieldBox = previousFieldContainer.closest( 'li.frm_field_box' );
1088 + if ( closestFieldBox && ! closestFieldBox.classList.contains( 'edit_field_type_divider' ) ) {
1089 + closestFieldBox.remove();
1090 + }
1091 + }
1092 +
1093 + function handleDragOverYAxis({ droppable, y, placeholder }) {
1094 + const $list = jQuery( droppable );
1095 +
1096 + let top;
1097 +
1098 + $children = $list.children().not( '.edit_field_type_end_divider' );
1099 + if ( 0 === $children.length ) {
1100 + $list.prepend( placeholder );
1101 + top = 0;
1102 + } else {
1103 + const insertAtIndex = determineIndexBasedOffOfMousePositionInList( $list, y );
1104 +
1105 + if ( insertAtIndex === $children.length ) {
1106 + const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) );
1107 + top = $lastChild.offset().top + $lastChild.outerHeight();
1108 + $list.append( placeholder );
1109 +
1110 + // Make sure nothing gets inserted after the end divider.
1111 + const $endDivider = $list.children( '.edit_field_type_end_divider' );
1112 + if ( $endDivider.length ) {
1113 + $list.append( $endDivider );
1114 + }
1115 + } else {
1116 + top = jQuery( $children.get( insertAtIndex ) ).offset().top;
1117 + jQuery( $children.get( insertAtIndex ) ).before( placeholder );
1118 + }
1119 + }
1120 +
1121 + top -= $list.offset().top;
1122 + placeholder.style.top = top + 'px';
1123 + }
1124 +
1125 + function determineIndexBasedOffOfMousePositionInList( $list, y ) {
1126 + const $items = $list.children().not( '.edit_field_type_end_divider' );
1127 + const length = $items.length;
1128 +
1129 + let index, item, itemTop, returnIndex;
1130 +
1131 + returnIndex = 0;
1132 + for ( index = length - 1; index >= 0; --index ) {
1133 + item = $items.get( index );
1134 + itemTop = jQuery( item ).offset().top;
1135 + if ( y > itemTop ) {
1136 + returnIndex = index;
1137 + if ( y > itemTop + ( jQuery( item ).outerHeight() / 2 ) ) {
1138 + returnIndex = index + 1;
1139 + }
1140 + break;
1141 + }
1142 + }
1143 +
1144 + return returnIndex;
1145 + }
1146 +
1147 + function handleDragOverFieldGroup({ droppable, x, placeholder }) {
1148 + const $row = jQuery( droppable );
1149 + const $children = getFieldsInRow( $row );
1150 +
1151 + if ( ! $children.length ) {
1152 + return;
1153 + }
1154 +
1155 + let left;
1156 + const insertAtIndex = determineIndexBasedOffOfMousePositionInRow( $row, x );
1157 +
1158 + if ( insertAtIndex === $children.length ) {
1159 + const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) );
1160 + left = $lastChild.offset().left + $lastChild.outerWidth();
1161 + $row.append( placeholder );
1162 + } else {
1163 + left = jQuery( $children.get( insertAtIndex ) ).offset().left;
1164 + jQuery( $children.get( insertAtIndex ) ).before( placeholder );
1165 +
1166 + const amountToOffsetLeftBy = 0 === insertAtIndex ? 4 : 8; // Offset by 8 in between rows, but only 4 for the first item in a group.
1167 + left -= amountToOffsetLeftBy; // Offset the placeholder slightly so it appears between two fields.
1168 + }
1169 +
1170 + left -= $row.offset().left;
1171 +
1172 + placeholder.style.left = left + 'px';
1173 + }
1174 +
1175 + function syncAfterDragAndDrop() {
1176 + fixUnwrappedListItems();
1177 + toggleSectionHolder();
1178 + maybeFixEndDividers();
1179 + maybeDeleteEmptyFieldGroups();
1180 + updateFieldOrder();
1181 +
1182 + const event = new Event( 'frm_sync_after_drag_and_drop', { bubbles: false });
1183 + document.dispatchEvent( event );
1184 + }
1185 +
1186 + function maybeFixEndDividers() {
1187 + document.querySelectorAll( '.edit_field_type_end_divider' ).forEach(
1188 + endDivider => endDivider.parentNode.appendChild( endDivider )
1189 + );
1190 + }
1191 +
1192 + function maybeDeleteEmptyFieldGroups() {
1193 + document.querySelectorAll( 'li.form_field_box:not(.form-field)' ).forEach(
1194 + fieldGroup => ! fieldGroup.children.length && fieldGroup.remove()
1195 + );
1196 + }
1197 +
1198 + function fixUnwrappedListItems() {
1199 + const lists = document.querySelectorAll( 'ul#frm-show-fields, ul.start_divider' );
1200 + lists.forEach(
1201 + list => {
1202 + list.childNodes.forEach(
1203 + child => {
1204 + if ( 'undefined' === typeof child.classList ) {
1205 + return;
1206 + }
1207 +
1208 + if ( child.classList.contains( 'edit_field_type_end_divider' ) ) {
1209 + // Never wrap end divider in place.
1210 + return;
1211 + }
1212 +
1213 + if ( 'undefined' !== typeof child.classList && child.classList.contains( 'form-field' ) ) {
1214 + wrapFieldLiInPlace( child );
1215 + }
1216 + }
1217 + );
1218 + }
1219 + );
1220 + }
1221 +
1222 + function deleteEmptyDividerWrappers() {
1223 + const dividers = document.querySelectorAll( 'ul.start_divider' );
1224 + if ( ! dividers.length ) {
1225 + return;
1226 + }
1227 + dividers.forEach(
1228 + function( divider ) {
1229 + const children = [].slice.call( divider.children );
1230 + children.forEach(
1231 + function( child ) {
1232 + if ( 0 === child.children.length ) {
1233 + child.remove();
1234 + } else if ( 1 === child.children.length && 'ul' === child.firstElementChild.nodeName.toLowerCase() && 0 === child.firstElementChild.children.length ) {
1235 + child.remove();
1236 + }
1237 + }
1238 + );
1239 + }
1240 + );
1241 + }
1242 +
1243 + function getFieldsInRow( $row ) {
1244 + let $fields = jQuery();
1245 +
1246 + const row = $row.get( 0 );
1247 + if ( ! row.children ) {
1248 + return $fields;
1249 + }
1250 +
1251 + Array.from( row.children ).forEach(
1252 + child => {
1253 + if ( 'none' === child.style.display ) {
1254 + return;
1255 + }
1256 +
1257 + const classes = child.classList;
1258 + if ( ! classes.contains( 'form-field' ) || classes.contains( 'edit_field_type_end_divider' ) || classes.contains( 'frm-sortable-helper' ) ) {
1259 + return;
1260 + }
1261 +
1262 + $fields = $fields.add( child );
1263 + }
1264 + );
1265 + return $fields;
1266 + }
1267 +
1268 + function determineIndexBasedOffOfMousePositionInRow( $row, x ) {
1269 + var $inputs = getFieldsInRow( $row ),
1270 + length = $inputs.length,
1271 + index, input, inputLeft, returnIndex;
1272 +
1273 + returnIndex = 0;
1274 + for ( index = length - 1; index >= 0; --index ) {
1275 + input = $inputs.get( index );
1276 + inputLeft = jQuery( input ).offset().left;
1277 + if ( x > inputLeft ) {
1278 + returnIndex = index;
1279 + if ( x > inputLeft + ( jQuery( input ).outerWidth() / 2 ) ) {
1280 + returnIndex = index + 1;
1281 + }
1282 + break;
1283 + }
1284 + }
1285 +
1286 + return returnIndex;
1287 + }
1288 +
1289 + function syncLayoutClasses( $item, type ) {
1290 + var $fields, size, layoutClasses, classToAddFunction;
1291 +
1292 + if ( 'undefined' === typeof type ) {
1293 + type = 'even';
1294 + }
1295 +
1296 + $fields = $item.parent().children( 'li.form-field, li.frmbutton_loadingnow' ).not( '.edit_field_type_end_divider' );
1297 + size = $fields.length;
1298 + layoutClasses = getLayoutClasses();
1299 +
1300 + if ( 'even' === type && 5 !== size ) {
1301 + $fields.each( getSyncLayoutClass( layoutClasses, getEvenClassForSize( size ) ) );
1302 + } else if ( 'clear' === type ) {
1303 + $fields.each( getSyncLayoutClass( layoutClasses, '' ) );
1304 + } else {
1305 + if ( -1 !== [ 'left', 'right', 'middle', 'even' ].indexOf( type ) ) {
1306 + classToAddFunction = function( index ) {
1307 + return getClassForBlock( size, type, index );
1308 + };
1309 + } else {
1310 + classToAddFunction = function( index ) {
1311 + var size = type[ index ];
1312 + return getLayoutClassForSize( size );
1313 + };
1314 + }
1315 +
1316 + $fields.each( getSyncLayoutClass( layoutClasses, classToAddFunction ) );
1317 + }
1318 +
1319 + updateFieldGroupControls( $item.parent(), $fields.length );
1320 + }
1321 +
1322 + function updateFieldGroupControls( $row, count ) {
1323 + var rowOffset, shouldShowControls, controls;
1324 +
1325 + rowOffset = $row.offset();
1326 +
1327 + if ( 'undefined' === typeof rowOffset ) {
1328 + return;
1329 + }
1330 +
1331 + shouldShowControls = count >= 2;
1332 +
1333 + controls = document.getElementById( 'frm_field_group_controls' );
1334 + if ( null === controls ) {
1335 + if ( ! shouldShowControls ) {
1336 + // exit early. if we do not need controls and they do not exist, do nothing.
1337 + return;
1338 + }
1339 +
1340 + controls = div();
1341 + controls.id = 'frm_field_group_controls';
1342 + controls.setAttribute( 'role', 'group' );
1343 + controls.setAttribute( 'tabindex', 0 );
1344 + setFieldControlsHtml( controls );
1345 + document.getElementById( 'frm_builder_page' ).appendChild( controls );
1346 + }
1347 +
1348 + $row.append( controls );
1349 + controls.style.display = shouldShowControls ? 'block' : 'none';
1350 + }
1351 +
1352 + function setFieldControlsHtml( controls ) {
1353 + var layoutOption, moveOption;
1354 +
1355 + layoutOption = document.createElement( 'span' );
1356 + layoutOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_field_group_layout_icon"></use></svg>';
1357 + const layoutOptionLabel = __( 'Set Row Layout', 'formidable' );
1358 + addTooltip( layoutOption, layoutOptionLabel );
1359 + makeTabbable( layoutOption, layoutOptionLabel );
1360 +
1361 + moveOption = document.createElement( 'span' );
1362 + moveOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_thick_move_icon"></use></svg>';
1363 + moveOption.classList.add( 'frm-move' );
1364 + const moveOptionLabel = __( 'Move Field Group', 'formidable' );
1365 + addTooltip( moveOption, moveOptionLabel );
1366 + makeTabbable( moveOption, moveOptionLabel );
1367 +
1368 + controls.innerHTML = '';
1369 + controls.appendChild( layoutOption );
1370 + controls.appendChild( moveOption );
1371 + controls.appendChild( getFieldControlsDropdown() );
1372 + }
1373 +
1374 + function addTooltip( element, title ) {
1375 + element.setAttribute( 'data-toggle', 'tooltip' );
1376 + element.setAttribute( 'data-container', 'body' );
1377 + element.setAttribute( 'title', title );
1378 + element.addEventListener(
1379 + 'mouseover',
1380 + function() {
1381 + if ( null === element.getAttribute( 'data-original-title' ) ) {
1382 + jQuery( element ).tooltip();
1383 + }
1384 + }
1385 + );
1386 + }
1387 +
1388 + function getFieldControlsDropdown() {
1389 + var dropdown, trigger, ul;
1390 +
1391 + dropdown = document.createElement( 'span' );
1392 + dropdown.classList.add( 'dropdown' );
1393 +
1394 + trigger = document.createElement( 'a' );
1395 + trigger.classList.add( 'frm_bstooltip', 'frm-hover-icon', 'frm-dropdown-toggle', 'dropdown-toggle' );
1396 + trigger.setAttribute( 'title', __( 'More Options', 'formidable' ) );
1397 + trigger.setAttribute( 'data-toggle', 'dropdown' );
1398 + trigger.setAttribute( 'data-container', 'body' );
1399 + makeTabbable( trigger, __( 'More Options', 'formidable' ) );
1400 + trigger.innerHTML = '<span><svg class="frmsvg"><use xlink:href="#frm_thick_more_vert_icon"></use></svg></span>';
1401 + dropdown.appendChild( trigger );
1402 +
1403 + ul = document.createElement( 'div' );
1404 + ul.classList.add( 'frm-dropdown-menu', 'dropdown-menu' );
1405 + ul.setAttribute( 'role', 'menu' );
1406 + dropdown.appendChild( ul );
1407 +
1408 + return dropdown;
1409 + }
1410 +
1411 + function getSyncLayoutClass( layoutClasses, classToAdd ) {
1412 + return function( itemIndex ) {
1413 + var currentClassToAdd, length, layoutClassIndex, currentClass, activeLayoutClass, fieldId, layoutClassesInput;
1414 +
1415 + currentClassToAdd = 'function' === typeof classToAdd ? classToAdd( itemIndex ) : classToAdd;
1416 + length = layoutClasses.length;
1417 + activeLayoutClass = false;
1418 + for ( layoutClassIndex = 0; layoutClassIndex < length; ++layoutClassIndex ) {
1419 + currentClass = layoutClasses[ layoutClassIndex ];
1420 + if ( this.classList.contains( currentClass ) ) {
1421 + activeLayoutClass = currentClass;
1422 + break;
1423 + }
1424 + }
1425 +
1426 + fieldId = this.dataset.fid;
1427 +
1428 + if ( 'undefined' === typeof fieldId ) {
1429 + // we are syncing the drag/drop placeholder before the actual field has loaded.
1430 + // this will get called again afterward and the input will exist then.
1431 + this.classList.add( currentClassToAdd );
1432 + return;
1433 + }
1434 +
1435 + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) );
1436 + layoutClassesInput = document.getElementById( 'frm_classes_' + fieldId );
1437 +
1438 + if ( null === layoutClassesInput ) {
1439 + // not every field type has a layout class input.
1440 + return;
1441 + }
1442 +
1443 + if ( false === activeLayoutClass ) {
1444 + if ( '' !== currentClassToAdd ) {
1445 + layoutClassesInput.value = layoutClassesInput.value.concat( ' ' + currentClassToAdd );
1446 + }
1447 + } else {
1448 + this.classList.remove( activeLayoutClass );
1449 + layoutClassesInput.value = layoutClassesInput.value.replace( activeLayoutClass, currentClassToAdd );
1450 + }
1451 +
1452 + if ( this.classList.contains( 'frm_first' ) ) {
1453 + this.classList.remove( 'frm_first' );
1454 + layoutClassesInput.value = layoutClassesInput.value.replace( 'frm_first', '' ).trim();
1455 + }
1456 +
1457 + if ( 0 === itemIndex ) {
1458 + this.classList.add( 'frm_first' );
1459 + layoutClassesInput.value = layoutClassesInput.value.concat( ' frm_first' );
1460 + }
1461 +
1462 + jQuery( layoutClassesInput ).trigger( 'change' );
1463 + };
1464 + }
1465 +
1466 + function getLayoutClasses() {
1467 + 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' ];
1468 + }
1469 +
1470 + function setupFieldOptionSorting( sort ) {
1471 + var opts = {
1472 + items: '.frm_sortable_field_opts li',
1473 + axis: 'y',
1474 + opacity: 0.65,
1475 + forcePlaceholderSize: false,
1476 + handle: '.frm-drag',
1477 + helper: function( e, li ) {
1478 + copyHelper = li.clone().insertAfter( li );
1479 + return li.clone();
1480 + },
1481 + stop: function( e, ui ) {
1482 + copyHelper && copyHelper.remove();
1483 + var fieldId = ui.item.attr( 'id' ).replace( 'frm_delete_field_', '' ).replace( '-' + ui.item.data( 'optkey' ) + '_container', '' );
1484 + resetDisplayedOpts( fieldId );
1485 + }
1486 + };
1487 + jQuery( sort ).sortable( opts );
1488 + }
1489 +
1490 + // Get the section where a field is dropped
1491 + function getSectionForFieldPlacement( currentItem ) {
1492 + var section = '';
1493 + if ( typeof currentItem !== 'undefined' && ! currentItem.hasClass( 'edit_field_type_divider' ) ) {
1494 + section = currentItem.closest( '.edit_field_type_divider' );
1495 + }
1496 + return section;
1497 + }
1498 +
1499 + // Get the form ID where a field is dropped
1500 + function getFormIdForFieldPlacement( section ) {
1501 + var formId = '';
1502 +
1503 + if ( typeof section[0] !== 'undefined' ) {
1504 + var sDivide = section.children( '.start_divider' );
1505 + sDivide.children( '.edit_field_type_end_divider' ).appendTo( sDivide );
1506 + if ( typeof section.attr( 'data-formid' ) !== 'undefined' ) {
1507 + var fieldId = section.attr( 'data-fid' );
1508 + formId = jQuery( 'input[name="field_options[form_select_' + fieldId + ']"]' ).val();
1509 + }
1510 + }
1511 +
1512 + if ( typeof formId === 'undefined' || formId === '' ) {
1513 + formId = thisFormId;
1514 + }
1515 +
1516 + return formId;
1517 + }
1518 +
1519 + // Get the section ID where a field is dropped
1520 + function getSectionIdForFieldPlacement( section ) {
1521 + var sectionId = 0;
1522 + if ( typeof section[0] !== 'undefined' ) {
1523 + sectionId = section.attr( 'id' ).replace( 'frm_field_id_', '' );
1524 + }
1525 +
1526 + return sectionId;
1527 + }
1528 +
1529 + /**
1530 + * Update a field after it is dragged and dropped into, out of, or between sections
1531 + *
1532 + * @param {object} currentItem
1533 + */
1534 + function updateFieldAfterMovingBetweenSections( currentItem ) {
1535 + if ( ! currentItem.hasClass( 'form-field' ) ) {
1536 + // currentItem is a field group. Call for children recursively.
1537 + getFieldsInRow( jQuery( currentItem.get( 0 ).firstChild ) ).each(
1538 + function() {
1539 + updateFieldAfterMovingBetweenSections( jQuery( this ) );
1540 + }
1541 + );
1542 + return;
1543 + }
1544 +
1545 + const fieldId = currentItem.attr( 'id' ).replace( 'frm_field_id_', '' );
1546 + const section = getSectionForFieldPlacement( currentItem );
1547 + const formId = getFormIdForFieldPlacement( section );
1548 + const sectionId = getSectionIdForFieldPlacement( section );
1549 +
1550 + jQuery.ajax({
1551 + type: 'POST',
1552 + url: ajaxurl,
1553 + data: {
1554 + action: 'frm_update_field_after_move',
1555 + form_id: formId,
1556 + field: fieldId,
1557 + section_id: sectionId,
1558 + nonce: frmGlobal.nonce
1559 + },
1560 + success: function() {
1561 + toggleSectionHolder();
1562 + updateInSectionValue( fieldId, sectionId );
1563 + }
1564 + });
1565 + }
1566 +
1567 + // Update the in_section field value
1568 + function updateInSectionValue( fieldId, sectionId ) {
1569 + document.getElementById( 'frm_in_section_' + fieldId ).value = sectionId;
1570 + }
1571 +
1572 + /**
1573 + * Add a new field by dragging and dropping it from the Fields sidebar
1574 + *
1575 + * @param {string} fieldType
1576 + */
1577 + function insertNewFieldByDragging( fieldType ) {
1578 + const placeholder = document.getElementById( 'frm_drag_placeholder' );
1579 + const loadingID = fieldType.replace( '|', '-' ) + '_' + getAutoId();
1580 + const loading = tag(
1581 + 'li',
1582 + {
1583 + id: loadingID,
1584 + className: 'frm-wait frmbutton_loadingnow'
1585 + }
1586 + );
1587 + const $placeholder = jQuery( loading );
1588 + const currentItem = jQuery( placeholder );
1589 + const section = getSectionForFieldPlacement( currentItem );
1590 + const formId = getFormIdForFieldPlacement( section );
1591 + const sectionId = getSectionIdForFieldPlacement( section );
1592 +
1593 + placeholder.parentNode.insertBefore( loading, placeholder );
1594 + placeholder.remove();
1595 + syncLayoutClasses( $placeholder );
1596 +
1597 + let hasBreak = 0;
1598 + if ( 'summary' === fieldType ) {
1599 + // see if we need to insert a page break before this newly-added summary field. Check for at least 1 page break
1600 + hasBreak = jQuery( '.frmbutton_loadingnow#' + loadingID ).prevAll( 'li[data-type="break"]' ).length ? 1 : 0;
1601 + }
1602 +
1603 + jQuery.ajax({
1604 + type: 'POST', url: ajaxurl,
1605 + data: {
1606 + action: 'frm_insert_field',
1607 + form_id: formId,
1608 + field_type: fieldType,
1609 + section_id: sectionId,
1610 + nonce: frmGlobal.nonce,
1611 + has_break: hasBreak
1612 + },
1613 + success: function( msg ) {
1614 + let replaceWith;
1615 + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' );
1616 + const $siblings = $placeholder.siblings( 'li.form-field' ).not( '.edit_field_type_end_divider' );
1617 + if ( ! $siblings.length ) {
1618 + // if dragging into a new row, we need to wrap the li first.
1619 + replaceWith = wrapFieldLi( msg );
1620 + } else {
1621 + replaceWith = msgAsjQueryObject( msg );
1622 + if ( ! $placeholder.get( 0 ).parentNode.parentNode.classList.contains( 'ui-draggable' ) ) {
1623 + // If a field group wasn't draggable because it only had a single field, make it draggable.
1624 + makeDraggable( $placeholder.get( 0 ).parentNode.parentNode, '.frm-move' );
1625 + }
1626 + }
1627 + $placeholder.replaceWith( replaceWith );
1628 + updateFieldOrder();
1629 + afterAddField( msg, false );
1630 + if ( $siblings.length ) {
1631 + syncLayoutClasses( $siblings.first() );
1632 + }
1633 + toggleSectionHolder();
1634 +
1635 + if ( ! $siblings.length ) {
1636 + makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) );
1637 + makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' );
1638 + } else {
1639 + makeDraggable( replaceWith.get( 0 ), '.frm-move' );
1640 + }
1641 +
1642 + },
1643 + error: handleInsertFieldError
1644 + });
1645 + }
1646 +
1647 + function moveFieldThatAlreadyExists( draggable, placeholder ) {
1648 + placeholder.parentNode.insertBefore( draggable, placeholder );
1649 + }
1650 +
1651 + function msgAsjQueryObject( msg ) {
1652 + const element = div();
1653 + element.innerHTML = msg;
1654 + return jQuery( element.firstChild );
1655 + }
1656 +
1657 + function handleInsertFieldError( jqXHR, _, errorThrown ) {
1658 + maybeShowInsertFieldError( errorThrown, jqXHR );
1659 + }
1660 +
1661 + function maybeShowInsertFieldError( errorThrown, jqXHR ) {
1662 + if ( ! jqXHRAborted( jqXHR ) ) {
1663 + infoModal( errorThrown + '. Please try again.' );
1664 + }
1665 + }
1666 +
1667 + function jqXHRAborted( jqXHR ) {
1668 + return jqXHR.status === 0 || jqXHR.readyState === 0;
1669 + }
1670 +
1671 + /**
1672 + * Get a unique id that automatically increments with every function call.
1673 + * Can be used for any UI that requires a unique id.
1674 + * Not to be used in data.
1675 + *
1676 + * @returns {integer}
1677 + */
1678 + function getAutoId() {
1679 + return ++autoId;
1680 + }
1681 +
1682 + // Don't allow page break, embed form, or section inside section field
1683 + // Don't allow page breaks inside of field groups.
1684 + // Don't allow field groups with sections inside of sections.
1685 + // Don't allow field groups in field groups.
1686 + // Don't allow hidden fields inside of field groups but allow them in sections.
1687 + function allowDrop( draggable, droppable ) {
1688 + if ( false === droppable ) {
1689 + // Don't show drop placeholder if dragging somewhere off of the droppable area.
1690 + return false;
1691 + }
1692 +
1693 + if ( droppable.closest( '.frm-sortable-helper' ) ) {
1694 + // Do not allow drop into draggable.
1695 + return false;
1696 + }
1697 +
1698 + if ( 'frm-show-fields' === droppable.id ) {
1699 + // Everything can be dropped into the main list of fields.
1700 + return true;
1701 + }
1702 +
1703 + if ( ! droppable.classList.contains( 'start_divider' ) ) {
1704 + const $fieldsInRow = getFieldsInRow( jQuery( droppable ) );
1705 + if ( ! groupCanFitAnotherField( $fieldsInRow, jQuery( draggable ) ) ) {
1706 + // Field group is full and cannot accept another field.
1707 + return false;
1708 + }
1709 + }
1710 +
1711 + const isNewField = draggable.classList.contains( 'frm-new-field' );
1712 + if ( isNewField ) {
1713 + return allowNewFieldDrop( draggable, droppable );
1714 + }
1715 +
1716 + return allowMoveField( draggable, droppable );
1717 + }
1718 +
1719 + // Don't allow a new page break or hidden field in a field group.
1720 + // Don't allow a new section inside of a section.
1721 + // Don't allow an embedded form in a section.
1722 + function allowNewFieldDrop( draggable, droppable ) {
1723 + const classes = draggable.classList;
1724 + const newPageBreakField = classes.contains( 'frm_tbreak' );
1725 + const newHiddenField = classes.contains( 'frm_thidden' );
1726 + const newSectionField = classes.contains( 'frm_tdivider' );
1727 + const newEmbedField = classes.contains( 'frm_tform' );
1728 +
1729 + const fieldTypeIsAlwaysAllowed = ! newPageBreakField && ! newHiddenField && ! newSectionField && ! newEmbedField;
1730 + if ( fieldTypeIsAlwaysAllowed ) {
1731 + return true;
1732 + }
1733 +
1734 + const newFieldWillBeAddedToASection = droppable.classList.contains( 'start_divider' ) || null !== droppable.closest( '.start_divider' );
1735 + if ( newFieldWillBeAddedToASection ) {
1736 + // Don't allow a section or an embedded form in a section.
1737 + return ! newEmbedField && ! newSectionField;
1738 + }
1739 +
1740 + const newFieldWillBeAddedToAGroup = ! ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) );
1741 + if ( newFieldWillBeAddedToAGroup ) {
1742 + return ! newHiddenField && ! newPageBreakField;
1743 + }
1744 +
1745 + return true;
1746 + }
1747 +
1748 + function allowMoveField( draggable, droppable ) {
1749 + if ( isFieldGroup( draggable ) ) {
1750 + return allowMoveFieldGroup( draggable, droppable );
1751 + }
1752 +
1753 + const isPageBreak = draggable.classList.contains( 'edit_field_type_break' );
1754 + if ( isPageBreak ) {
1755 + // Page breaks are only allowed in the main list of fields, not in sections or in field groups.
1756 + return false;
1757 + }
1758 +
1759 + if ( droppable.classList.contains( 'start_divider' ) ) {
1760 + return allowMoveFieldToSection( draggable );
1761 + }
1762 +
1763 + return allowMoveFieldToGroup( draggable, droppable );
1764 + }
1765 +
1766 + function isFieldGroup( draggable ) {
1767 + return draggable.classList.contains( 'frm_field_box' ) && ! draggable.classList.contains( 'form-field' );
1768 + }
1769 +
1770 + function allowMoveFieldGroup( fieldGroup, droppable ) {
1771 + if ( droppable.classList.contains( 'start_divider' ) && null === fieldGroup.querySelector( '.start_divider' ) ) {
1772 + // Allow a field group with no section inside of a section.
1773 + return true;
1774 + }
1775 + return false;
1776 + }
1777 +
1778 + function allowMoveFieldToSection( draggable ) {
1779 + const draggableIncludeEmbedForm = draggable.classList.contains( 'edit_field_type_form' ) || draggable.querySelector( '.edit_field_type_form' );
1780 + if ( draggableIncludeEmbedForm ) {
1781 + // Do not allow an embedded form inside of a section.
1782 + return false;
1783 + }
1784 +
1785 + const draggableIncludesSection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' );
1786 + if ( draggableIncludesSection ) {
1787 + // Do not allow a section inside of a section.
1788 + return false;
1789 + }
1790 +
1791 + return true;
1792 + }
1793 +
1794 + function allowMoveFieldToGroup( draggable, group ) {
1795 + const groupIncludesBreakOrHidden = null !== group.querySelector( '.edit_field_type_break, .edit_field_type_hidden' );
1796 + if ( groupIncludesBreakOrHidden ) {
1797 + // Never allow any field beside a page break or a hidden field.
1798 + return false;
1799 + }
1800 +
1801 + const isFieldGroup = jQuery( draggable ).children( 'ul.frm_sorting' ).not( '.start_divider' ).length > 0;
1802 + if ( isFieldGroup ) {
1803 + // Do not allow a field group directly inside of a field group unless it's in a section.
1804 + return false;
1805 + }
1806 +
1807 + const draggableIncludesASection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' );
1808 + const draggableIsEmbedField = draggable.classList.contains( 'edit_field_type_form' );
1809 + const groupIsInASection = null !== group.closest( '.start_divider' );
1810 + if ( groupIsInASection && ( draggableIncludesASection || draggableIsEmbedField ) ) {
1811 + // Do not allow a section or an embed field inside of a section.
1812 + return false;
1813 + }
1814 +
1815 + return true;
1816 + }
1817 +
1818 + function groupCanFitAnotherField( fieldsInRow, $field ) {
1819 + var fieldId;
1820 + if ( fieldsInRow.length < 6 ) {
1821 + return true;
1822 + }
1823 + if ( fieldsInRow.length > 6 ) {
1824 + return false;
1825 + }
1826 + fieldId = $field.attr( 'data-fid' );
1827 + // allow 6 if we're not changing field groups.
1828 + return 1 === jQuery( fieldsInRow ).filter( '[data-fid="' + fieldId + '"]' ).length;
1829 + }
1830 +
1831 + function loadFields( fieldId ) {
1832 + const thisField = document.getElementById( fieldId );
1833 + const $thisField = jQuery( thisField );
1834 + const field = [];
1835 + const addHtmlToField = element => {
1836 + const frmHiddenFdata = element.querySelector( '.frm_hidden_fdata' );
1837 + element.classList.add( 'frm_load_now' );
1838 + if ( frmHiddenFdata !== null ) {
1839 + field.push( frmHiddenFdata.innerHTML );
1840 + }
1841 + };
1842 +
1843 + let nextElement = thisField;
1844 + addHtmlToField( nextElement );
1845 + while ( nextElement.nextElementSibling && field.length < 15 ) {
1846 + addHtmlToField( nextElement.nextElementSibling );
1847 + nextElement = nextElement.nextElementSibling;
1848 + }
1849 +
1850 + jQuery.ajax({
1851 + type: 'POST',
1852 + url: ajaxurl,
1853 + data: {
1854 + action: 'frm_load_field',
1855 + field: field,
1856 + form_id: thisFormId,
1857 + nonce: frmGlobal.nonce
1858 + },
1859 + success: html => handleAjaxLoadFieldSuccess( html, $thisField, field )
1860 + });
1861 + }
1862 +
1863 + function handleAjaxLoadFieldSuccess( html, $thisField, field ) {
1864 + let key, $nextSet;
1865 +
1866 + html = html.replace( /^\s+|\s+$/g, '' );
1867 + if ( html.indexOf( '{' ) !== 0 ) {
1868 + jQuery( '.frm_load_now' ).removeClass( '.frm_load_now' ).html( 'Error' );
1869 + return;
1870 + }
1871 +
1872 + html = JSON.parse( html );
1873 + for ( key in html ) {
1874 + jQuery( '#frm_field_id_' + key ).replaceWith( html[key]);
1875 + setupSortable( '#frm_field_id_' + key + '.edit_field_type_divider ul.frm_sorting' );
1876 + makeDraggable( document.getElementById( 'frm_field_id_' + key ) );
1877 + }
1878 +
1879 + $nextSet = $thisField.nextAll( '.frm_field_loading:not(.frm_load_now)' );
1880 + if ( $nextSet.length ) {
1881 + loadFields( $nextSet.attr( 'id' ) );
1882 + } else {
1883 + // go up a level
1884 + $nextSet = jQuery( document.getElementById( 'frm-show-fields' ) ).find( '.frm_field_loading:not(.frm_load_now)' );
1885 + if ( $nextSet.length ) {
1886 + loadFields( $nextSet.attr( 'id' ) );
1887 + }
1888 + }
1889 +
1890 + initiateMultiselect();
1891 + renumberPageBreaks();
1892 + maybeHideQuantityProductFieldOption();
1893 +
1894 + const loadedEvent = new Event( 'frm_ajax_loaded_field', { bubbles: false });
1895 + loadedEvent.frmFields = field.map( f => JSON.parse( f ) );
1896 + document.dispatchEvent( loadedEvent );
1897 + }
1898 +
1899 + function addFieldClick() {
1900 + /*jshint validthis:true */
1901 + const $thisObj = jQuery( this );
1902 + // there is no real way to disable a <a> (with a valid href attribute) in HTML - https://css-tricks.com/how-to-disable-links/
1903 + if ( $thisObj.hasClass( 'disabled' ) ) {
1904 + return false;
1905 + }
1906 +
1907 + const $button = $thisObj.closest( '.frmbutton' );
1908 + const fieldType = $button.attr( 'id' );
1909 +
1910 + let hasBreak = 0;
1911 + if ( 'summary' === fieldType ) {
1912 + hasBreak = $newFields.children( 'li[data-type="break"]' ).length > 0 ? 1 : 0;
1913 + }
1914 +
1915 + const formId = thisFormId;
1916 + jQuery.ajax({
1917 + type: 'POST',
1918 + url: ajaxurl,
1919 + data: {
1920 + action: 'frm_insert_field',
1921 + form_id: formId,
1922 + field_type: fieldType,
1923 + section_id: 0,
1924 + nonce: frmGlobal.nonce,
1925 + has_break: hasBreak
1926 + },
1927 + success: function( msg ) {
1928 + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' );
1929 + const replaceWith = wrapFieldLi( msg );
1930 + $newFields.append( replaceWith );
1931 + afterAddField( msg, true );
1932 +
1933 + replaceWith.each(
1934 + function() {
1935 + makeDroppable( this.querySelector( 'ul.frm_sorting' ) );
1936 + makeDraggable( this.querySelector( '.form-field' ), '.frm-move' );
1937 + }
1938 + );
1939 + },
1940 + error: handleInsertFieldError
1941 + });
1942 + return false;
1943 + }
1944 +
1945 + function maybeHideQuantityProductFieldOption() {
1946 + var hide = true,
1947 + opts = document.querySelectorAll( '.frmjs_prod_field_opt_cont' );
1948 +
1949 + if ( $newFields.find( 'li.edit_field_type_product' ).length > 1 ) {
1950 + hide = false;
1951 + }
1952 +
1953 + for ( var i = 0; i < opts.length; i++ ) {
1954 + if ( hide ) {
1955 + opts[ i ].classList.add( 'frm_hidden' );
1956 + } else {
1957 + opts[ i ].classList.remove( 'frm_hidden' );
1958 + }
1959 + }
1960 + }
1961 +
1962 + function duplicateField() {
1963 + var $field, fieldId, children, newRowId, fieldOrder;
1964 +
1965 + $field = jQuery( this ).closest( 'li.form-field' );
1966 +
1967 + if ( $field.hasClass( 'frm-section-collapsed' ) || $field.hasClass( 'frm-page-collapsed' ) ) {
1968 + return false;
1969 + }
1970 +
1971 + closeOpenFieldDropdowns();
1972 +
1973 + fieldId = $field.data( 'fid' );
1974 + children = fieldsInSection( fieldId );
1975 + newRowId = this.getAttribute( 'frm-target-row-id' );
1976 +
1977 + if ( null !== newRowId ) {
1978 + fieldOrder = this.getAttribute( 'frm-field-order' );
1979 + }
1980 +
1981 + jQuery.ajax({
1982 + type: 'POST',
1983 + url: ajaxurl,
1984 + data: {
1985 + action: 'frm_duplicate_field',
1986 + field_id: fieldId,
1987 + form_id: thisFormId,
1988 + children: children,
1989 + nonce: frmGlobal.nonce
1990 + },
1991 + success: function( msg ) {
1992 + var newRow;
1993 +
1994 + let replaceWith;
1995 +
1996 + if ( null !== newRowId ) {
1997 + newRow = document.getElementById( newRowId );
1998 + if ( null !== newRow ) {
1999 + replaceWith = msgAsjQueryObject( msg );
2000 + jQuery( newRow ).append( replaceWith );
2001 + makeDraggable( replaceWith.get( 0 ), '.frm-move' );
2002 + if ( null !== fieldOrder ) {
2003 + newRow.lastElementChild.setAttribute( 'frm-field-order', fieldOrder );
2004 + }
2005 + jQuery( newRow ).trigger(
2006 + 'frm_added_duplicated_field_to_row',
2007 + {
2008 + duplicatedFieldHtml: msg,
2009 + originalFieldId: fieldId
2010 + }
2011 + );
2012 + afterAddField( msg, false );
2013 + return;
2014 + }
2015 + }
2016 +
2017 + if ( $field.siblings( 'li.form-field' ).length ) {
2018 + replaceWith = msgAsjQueryObject( msg );
2019 + $field.after( replaceWith );
2020 + syncLayoutClasses( $field );
2021 + makeDraggable( replaceWith.get( 0 ), '.frm-move' );
2022 + } else {
2023 + replaceWith = wrapFieldLi( msg );
2024 + $field.parent().parent().after( replaceWith );
2025 + makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) );
2026 + makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' );
2027 + }
2028 +
2029 + updateFieldOrder();
2030 + afterAddField( msg, false );
2031 + maybeDuplicateUnsavedSettings( fieldId, msg );
2032 + }
2033 + });
2034 + return false;
2035 + }
2036 +
2037 + function maybeDuplicateUnsavedSettings( originalFieldId, newFieldHtml ) {
2038 + var originalSettings, newFieldId, copySettings, fieldOptionKeys, originalDefault, copyDefault;
2039 +
2040 + originalSettings = document.getElementById( 'frm-single-settings-' + originalFieldId );
2041 + if ( null === originalSettings ) {
2042 + return;
2043 + }
2044 +
2045 + newFieldId = jQuery( newFieldHtml ).attr( 'data-fid' );
2046 + if ( 'undefined' === typeof newFieldId ) {
2047 + return;
2048 + }
2049 +
2050 + copySettings = document.getElementById( 'frm-single-settings-' + newFieldId );
2051 + if ( null === copySettings ) {
2052 + return;
2053 + }
2054 +
2055 + fieldOptionKeys = [
2056 + 'name', 'required', 'unique', 'read_only', 'placeholder', 'description', 'size', 'max', 'format', 'prepend', 'append', 'separate_value'
2057 + ];
2058 +
2059 + originalSettings.querySelectorAll( 'input[name^="field_options["], textarea[name^="field_options["]' ).forEach(
2060 + function( originalSetting ) {
2061 + var key, tagType, copySetting;
2062 +
2063 + key = getKeyFromSettingInput( originalSetting );
2064 +
2065 + if ( 'options' === key ) {
2066 + copyOption( originalSetting, copySettings, originalFieldId, newFieldId );
2067 + return;
2068 + }
2069 +
2070 + if ( -1 === fieldOptionKeys.indexOf( key ) ) {
2071 + return;
2072 + }
2073 +
2074 + tagType = originalSetting.matches( 'input' ) ? 'input' : 'textarea';
2075 + copySetting = copySettings.querySelector( tagType + '[name="field_options[' + key + '_' + newFieldId + ']"]' );
2076 + if ( null === copySetting ) {
2077 + return;
2078 + }
2079 +
2080 + if ( 'checkbox' === originalSetting.type ) {
2081 + if ( originalSetting.checked !== copySetting.checked ) {
2082 + jQuery( copySetting ).trigger( 'click' );
2083 + }
2084 + } else if ( 'text' === originalSetting.type || 'textarea' === tagType ) {
2085 + if ( originalSetting.value !== copySetting.value ) {
2086 + copySetting.value = originalSetting.value;
2087 + jQuery( copySetting ).trigger( 'change' );
2088 + }
2089 + }
2090 + }
2091 + );
2092 +
2093 + originalDefault = originalSettings.querySelector( 'input[name="default_value_' + originalFieldId + '"]' );
2094 + if ( null !== originalDefault ) {
2095 + copyDefault = copySettings.querySelector( 'input[name="default_value_' + newFieldId + '"]' );
2096 + if ( null !== copyDefault && originalDefault.value !== copyDefault.value ) {
2097 + copyDefault.value = originalDefault.value;
2098 + jQuery( copyDefault ).trigger( 'change' );
2099 + }
2100 + }
2101 + }
2102 +
2103 + function copyOption( originalSetting, copySettings, originalFieldId, newFieldId ) {
2104 + var remainingKeyDetails, copyKey, copySetting;
2105 + remainingKeyDetails = originalSetting.name.substr( 23 + ( '' + originalFieldId ).length );
2106 + copyKey = 'field_options[options_' + newFieldId + ']' + remainingKeyDetails;
2107 + copySetting = copySettings.querySelector( 'input[name="' + copyKey + '"]' );
2108 + if ( null !== copySetting && copySetting.value !== originalSetting.value ) {
2109 + copySetting.value = originalSetting.value;
2110 + jQuery( copySetting ).trigger( 'change' );
2111 + }
2112 + }
2113 +
2114 + function getKeyFromSettingInput( input ) {
2115 + var nameWithoutPrefix, nameSplit;
2116 + nameWithoutPrefix = input.name.substr( 14 );
2117 + nameSplit = nameWithoutPrefix.split( '_' );
2118 + nameSplit.pop();
2119 + return nameSplit.join( '_' );
2120 + }
2121 +
2122 + function closeOpenFieldDropdowns() {
2123 + var openSettings = document.querySelector( '.frm-field-settings-open' );
2124 + if ( null !== openSettings ) {
2125 + openSettings.classList.remove( 'frm-field-settings-open' );
2126 + jQuery( document ).off( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings );
2127 + jQuery( '.frm-field-action-icons .dropdown.open' ).removeClass( 'open' );
2128 + }
2129 + }
2130 +
2131 + function handleClickOutsideOfFieldSettings( event ) {
2132 + if ( ! jQuery( event.originalEvent.target ).closest( '.frm-field-action-icons' ).length ) {
2133 + closeOpenFieldDropdowns();
2134 + }
2135 + }
2136 +
2137 + function checkForMultiselectKeysOnMouseMove( event ) {
2138 + var keyIsDown = ! ! ( event.ctrlKey || event.metaKey || event.shiftKey );
2139 + jQuery( document.getElementById( 'frm_builder_page' ) ).toggleClass( 'frm-multiselect-key-is-down', keyIsDown );
2140 + checkForActiveHoverTarget( event );
2141 + }
2142 +
2143 + function checkForActiveHoverTarget( event ) {
2144 + var container, elementFromPoint, list, previousHoverTarget;
2145 +
2146 + container = document.getElementById( 'post-body-content' );
2147 + if ( container.classList.contains( 'frm-dragging-field' ) ) {
2148 + return;
2149 + }
2150 +
2151 + if ( null !== document.querySelector( '.frm-field-group-hover-target .frm-field-settings-open' ) ) {
2152 + // do not set a hover target if a dropdown is open for the current hover target.
2153 + return;
2154 + }
2155 +
2156 + elementFromPoint = document.elementFromPoint( event.clientX, event.clientY );
2157 + if ( null !== elementFromPoint && ! elementFromPoint.classList.contains( 'edit_field_type_divider' ) ) {
2158 +
2159 + list = elementFromPoint.closest( 'ul.frm_sorting' );
2160 +
2161 + if ( null !== list && ! list.classList.contains( 'start_divider' ) && 'frm-show-fields' !== list.id ) {
2162 + previousHoverTarget = maybeRemoveGroupHoverTarget();
2163 + if ( false !== previousHoverTarget && ! jQuery( previousHoverTarget ).is( list ) ) {
2164 + destroyFieldGroupPopup();
2165 + }
2166 + updateFieldGroupControls( jQuery( list ), getFieldsInRow( jQuery( list ) ).length );
2167 + list.classList.add( 'frm-field-group-hover-target' );
2168 + jQuery( '#wpbody-content' ).on( 'mousemove', maybeRemoveHoverTargetOnMouseMove );
2169 + }
2170 + }
2171 + }
2172 +
2173 + function maybeRemoveGroupHoverTarget() {
2174 + var controls, previousHoverTarget;
2175 +
2176 + controls = document.getElementById( 'frm_field_group_controls' );
2177 + if ( null !== controls ) {
2178 + controls.style.display = 'none';
2179 + }
2180 +
2181 + previousHoverTarget = document.querySelector( '.frm-field-group-hover-target' );
2182 + if ( null === previousHoverTarget ) {
2183 + return false;
2184 + }
2185 +
2186 + jQuery( '#wpbody-content' ).off( 'mousemove', maybeRemoveHoverTargetOnMouseMove );
2187 + previousHoverTarget.classList.remove( 'frm-field-group-hover-target' );
2188 + return previousHoverTarget;
2189 + }
2190 +
2191 + function maybeRemoveHoverTargetOnMouseMove( event ) {
2192 + var elementFromPoint = document.elementFromPoint( event.clientX, event.clientY );
2193 + if ( null !== elementFromPoint && null !== elementFromPoint.closest( '#frm-show-fields' ) ) {
2194 + return;
2195 + }
2196 + maybeRemoveGroupHoverTarget();
2197 + }
2198 +
2199 + function onFieldActionDropdownShow( isFieldGroup ) {
2200 + unselectFieldGroups();
2201 + // maybe offset the dropdown if it goes off of the right of the screen.
2202 + setTimeout(
2203 + function() {
2204 + var ul, $ul;
2205 + ul = document.querySelector( '.dropdown.show .frm-dropdown-menu' );
2206 + if ( null === ul ) {
2207 + return;
2208 + }
2209 + if ( null === ul.getAttribute( 'aria-label' ) ) {
2210 + ul.setAttribute( 'aria-label', __( 'More Options', 'formidable' ) );
2211 + }
2212 + if ( 0 === ul.children.length ) {
2213 + fillFieldActionDropdown( ul, true === isFieldGroup );
2214 + }
2215 + $ul = jQuery( ul );
2216 + if ( $ul.offset().left > jQuery( window ).width() - $ul.outerWidth() ) {
2217 + ul.style.left = ( -$ul.outerWidth() ) + 'px';
2218 + }
2219 + const firstAnchor = ul.firstElementChild.querySelector( 'a' );
2220 + if ( firstAnchor ) {
2221 + firstAnchor.focus();
2222 + }
2223 + },
2224 + 0
2225 + );
2226 + }
2227 +
2228 + function onFieldGroupActionDropdownShow() {
2229 + onFieldActionDropdownShow( true );
2230 + }
2231 +
2232 + function fillFieldActionDropdown( ul, isFieldGroup ) {
2233 + var classSuffix, options;
2234 + classSuffix = isFieldGroup ? '_field_group' : '_field';
2235 + options = [ getDeleteActionOption( isFieldGroup ), getDuplicateActionOption( isFieldGroup ) ];
2236 + if ( ! isFieldGroup ) {
2237 + options.push(
2238 + { class: 'frm_select', icon: 'frm_settings_icon', label: __( 'Field settings', 'formidable' ) }
2239 + );
2240 + }
2241 + options.forEach(
2242 + function( option ) {
2243 + var li, anchor, span;
2244 + li = document.createElement( 'div' );
2245 + li.classList.add( 'frm_dropdown_li', 'frm_more_options_li', 'dropdown-item' );
2246 +
2247 + anchor = document.createElement( 'a' );
2248 + anchor.classList.add( option.class + classSuffix );
2249 + anchor.setAttribute( 'href', '#' );
2250 + makeTabbable( anchor );
2251 +
2252 + span = document.createElement( 'span' );
2253 + span.textContent = option.label;
2254 + anchor.innerHTML = '<svg class="frmsvg"><use xlink:href="#' + option.icon + '"></use></svg>';
2255 + anchor.appendChild( document.createTextNode( ' ' ) );
2256 + anchor.appendChild( span );
2257 +
2258 + li.appendChild( anchor );
2259 + ul.appendChild( li );
2260 + }
2261 + );
2262 + }
2263 +
2264 + function getDeleteActionOption( isFieldGroup ) {
2265 + var option = { class: 'frm_delete', icon: 'frm_delete_icon' };
2266 + option.label = isFieldGroup ? __( 'Delete Group', 'formidable' ) : __( 'Delete', 'formidable' );
2267 + return option;
2268 + }
2269 +
2270 + function getDuplicateActionOption( isFieldGroup ) {
2271 + var option = { class: 'frm_clone', icon: 'frm_clone_icon' };
2272 + option.label = isFieldGroup ? __( 'Duplicate Group', 'formidable' ) : __( 'Duplicate', 'formidable' );
2273 + return option;
2274 + }
2275 +
2276 + function wrapFieldLi( field ) {
2277 + const wrapper = div();
2278 +
2279 + if ( 'string' === typeof field ) {
2280 + wrapper.innerHTML = field;
2281 + } else {
2282 + wrapper.appendChild( field );
2283 + }
2284 +
2285 + let result = jQuery();
2286 + Array.from( wrapper.children ).forEach(
2287 + li => {
2288 + result = result.add(
2289 + jQuery( '<li>' )
2290 + .addClass( 'frm_field_box' )
2291 + .html(
2292 + jQuery( '<ul>' ).addClass( 'frm_grid_container frm_sorting' ).append( li )
2293 + )
2294 + );
2295 + }
2296 + );
2297 +
2298 + return result;
2299 + }
2300 +
2301 + function wrapFieldLiInPlace( li ) {
2302 + const ul = tag(
2303 + 'ul',
2304 + {
2305 + className: 'frm_grid_container frm_sorting'
2306 + }
2307 + );
2308 + const wrapper = tag(
2309 + 'li',
2310 + {
2311 + className: 'frm_field_box',
2312 + child: ul
2313 + }
2314 + );
2315 +
2316 + li.replaceWith( wrapper );
2317 + ul.appendChild( li );
2318 +
2319 + makeDroppable( ul );
2320 + makeDraggable( wrapper, '.frm-move' );
2321 + }
2322 +
2323 + function afterAddField( msg, addFocus ) {
2324 + var regex = /id="(\S+)"/,
2325 + match = regex.exec( msg ),
2326 + field = document.getElementById( match[1]),
2327 + section = '#' + match[1] + '.edit_field_type_divider ul.frm_sorting.start_divider',
2328 + $thisSection = jQuery( section ),
2329 + type = field.getAttribute( 'data-type' ),
2330 + toggled = false,
2331 + $parentSection;
2332 +
2333 + setupSortable( section );
2334 +
2335 + if ( 'quantity' === type ) {
2336 + // try to automatically attach a product field
2337 + maybeSetProductField( field );
2338 + }
2339 +
2340 + if ( 'product' === type || 'quantity' === type ) {
2341 + // quantity too needs to be a part of the if stmt especially cos of the very
2342 + // 1st quantity field (or even if it's just one quantity field in the form).
2343 + maybeHideQuantityProductFieldOption();
2344 + }
2345 +
2346 + if ( $thisSection.length ) {
2347 + $thisSection.parent( '.frm_field_box' ).children( '.frm_no_section_fields' ).addClass( 'frm_block' );
2348 + } else {
2349 + $parentSection = jQuery( field ).closest( 'ul.frm_sorting.start_divider' );
2350 + if ( $parentSection.length ) {
2351 + toggleOneSectionHolder( $parentSection );
2352 + toggled = true;
2353 + }
2354 + }
2355 +
2356 + if ( msg.indexOf( 'frm-collapse-page' ) !== -1 ) {
2357 + renumberPageBreaks();
2358 + }
2359 +
2360 + addClass( field, 'frm-newly-added' );
2361 + setTimeout( function() {
2362 + field.classList.remove( 'frm-newly-added' );
2363 + }, 1000 );
2364 +
2365 + if ( addFocus ) {
2366 + var bounding = field.getBoundingClientRect(),
2367 + container = document.getElementById( 'post-body-content' ),
2368 + inView = ( bounding.top >= 0 &&
2369 + bounding.left >= 0 &&
2370 + bounding.right <= ( window.innerWidth || document.documentElement.clientWidth ) &&
2371 + bounding.bottom <= ( window.innerHeight || document.documentElement.clientHeight )
2372 + );
2373 +
2374 + if ( ! inView ) {
2375 + container.scroll({
2376 + top: container.scrollHeight,
2377 + left: 0,
2378 + behavior: 'smooth'
2379 + });
2380 + }
2381 +
2382 + if ( toggled === false ) {
2383 + toggleOneSectionHolder( $thisSection );
2384 + }
2385 + }
2386 +
2387 + deselectFields();
2388 + initiateMultiselect();
2389 +
2390 + const addedEvent = new Event( 'frm_added_field', { bubbles: false });
2391 + addedEvent.frmField = field;
2392 + addedEvent.frmSection = section;
2393 + addedEvent.frmType = type;
2394 + addedEvent.frmToggles = toggled;
2395 + document.dispatchEvent( addedEvent );
2396 + }
2397 +
2398 + function clearSettingsBox( preventFieldGroups ) {
2399 + jQuery( '#new_fields .frm-single-settings' ).addClass( 'frm_hidden' );
2400 + jQuery( '#frm-options-panel > .frm-single-settings' ).removeClass( 'frm_hidden' );
2401 + deselectFields( preventFieldGroups );
2402 + }
2403 +
2404 + function deselectFields( preventFieldGroups ) {
2405 + jQuery( 'li.ui-state-default.selected' ).removeClass( 'selected' );
2406 + if ( ! preventFieldGroups ) {
2407 + unselectFieldGroups();
2408 + }
2409 + }
2410 +
2411 + function scrollToField( field ) {
2412 + var newPos = field.getBoundingClientRect().top,
2413 + container = document.getElementById( 'post-body-content' );
2414 +
2415 + if ( typeof animate === 'undefined' ) {
2416 + jQuery( container ).scrollTop( newPos );
2417 + } else {
2418 + // TODO: smooth scroll
2419 + jQuery( container ).animate({ scrollTop: newPos }, 500 );
2420 + }
2421 + }
2422 +
2423 + function checkCalculationCreatedByUser() {
2424 + var calculation = this.value;
2425 + var warningMessage = checkMatchingParens( calculation );
2426 + warningMessage += checkShortcodes( calculation, this );
2427 +
2428 + if ( warningMessage !== '' ) {
2429 + infoModal( calculation + '\n\n' + warningMessage );
2430 + }
2431 + }
2432 +
2433 + /**
2434 + * Checks the Detail Page slug to see if it's a reserved word and displays a message if it is.
2435 + */
2436 + function checkDetailPageSlug() {
2437 + var slug = jQuery( '#param' ).val(),
2438 + msg;
2439 + slug = slug.trim().toLowerCase();
2440 + if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( slug ) ) {
2441 + msg = frm_admin_js.slug_is_reserved;
2442 + msg = msg.replace( '****', addHtmlTags( slug, 'strong' ) );
2443 + msg += '<br /><br />';
2444 + msg += addHtmlTags( '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>', 'div' );
2445 + infoModal( msg );
2446 + }
2447 + }
2448 +
2449 + /**
2450 + * Checks View filter value for params named with reserved words and displays a message if any are found.
2451 + */
2452 + function checkFilterParamNames() {
2453 + var regEx = /\[\s*get\s*param\s*=\s*['"]?([a-zA-Z-_]+)['"]?/ig,
2454 + filterValue = jQuery( this ).val(),
2455 + match = regEx.exec( filterValue ),
2456 + unsafeParams = '';
2457 +
2458 + while ( match !== null ) {
2459 + if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( match[1]) ) {
2460 + if ( unsafeParams !== '' ) {
2461 + unsafeParams += '", "' + match[ 1 ];
2462 + } else {
2463 + unsafeParams = match[ 1 ];
2464 + }
2465 + }
2466 + match = regEx.exec( filterValue );
2467 + }
2468 +
2469 + if ( unsafeParams !== '' ) {
2470 + msg = frm_admin_js.param_is_reserved;
2471 + msg = msg.replace( '****', addHtmlTags( unsafeParams, 'strong' ) );
2472 + msg += '<br /><br />';
2473 + msg += ' <a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>';
2474 +
2475 + infoModal( msg );
2476 + }
2477 + }
2478 +
2479 + function addHtmlTags( text, tag ) {
2480 + tag = tag ? tag : 'p';
2481 + return '<' + tag + '>' + text + '</' + tag + '>';
2482 + }
2483 +
2484 + /**
2485 + * Checks a string for parens, brackets, and curly braces and returns a message if any unmatched are found.
2486 + * @param formula
2487 + * @returns {string}
2488 + */
2489 + function checkMatchingParens( formula ) {
2490 +
2491 + var stack = [],
2492 + formulaArray = formula.split( '' ),
2493 + length = formulaArray.length,
2494 + opening = [ '{', '[', '(' ],
2495 + closing = {
2496 + '}': '{',
2497 + ')': '(',
2498 + ']': '['
2499 + },
2500 + unmatchedClosing = [],
2501 + msg = '',
2502 + i, top;
2503 +
2504 + for ( i = 0; i < length; i++ ) {
2505 + if ( opening.includes( formulaArray[i]) ) {
2506 + stack.push( formulaArray[i]);
2507 + continue;
2508 + }
2509 + if ( closing.hasOwnProperty( formulaArray[i]) ) {
2510 + top = stack.pop();
2511 + if ( top !== closing[formulaArray[i]]) {
2512 + unmatchedClosing.push( formulaArray[i]);
2513 + }
2514 + }
2515 + }
2516 +
2517 + if ( stack.length > 0 || unmatchedClosing.length > 0 ) {
2518 + msg = frm_admin_js.unmatched_parens + '\n\n';
2519 + return msg;
2520 + }
2521 +
2522 + return '';
2523 + }
2524 +
2525 + /**
2526 + * Checks a calculation for shortcodes that shouldn't be in it and returns a message if found.
2527 + * @param calculation
2528 + * @param inputElement
2529 + * @returns {string}
2530 + */
2531 + function checkShortcodes( calculation, inputElement ) {
2532 + var msg = checkNonNumericShortcodes( calculation, inputElement );
2533 + msg += checkNonFormShortcodes( calculation );
2534 +
2535 + return msg;
2536 + }
2537 +
2538 + /**
2539 + * Checks if a numeric calculation has shortcodes that output non-numeric strings and returns a message if found.
2540 + * @param calculation
2541 + *
2542 + * @param inputElement
2543 + * @returns {string}
2544 + */
2545 + function checkNonNumericShortcodes( calculation, inputElement ) {
2546 +
2547 + var msg = '';
2548 +
2549 + if ( isTextCalculation( inputElement ) ) {
2550 + return msg;
2551 + }
2552 +
2553 + var nonNumericShortcodes = getNonNumericShortcodes();
2554 +
2555 + if ( nonNumericShortcodes.test( calculation ) ) {
2556 + msg = frm_admin_js.text_shortcodes + '\n\n';
2557 + }
2558 +
2559 + return msg;
2560 + }
2561 +
2562 + /**
2563 + * Determines if the calculation input is from a text calculation.
2564 + *
2565 + * @param inputElement
2566 + */
2567 + function isTextCalculation( inputElement ) {
2568 + return jQuery( inputElement ).siblings( 'label[for^="calc_type"]' ).children( 'input' ).prop( 'checked' );
2569 + }
2570 +
2571 + /**
2572 + * Returns a regular expression of shortcodes that can't be used in numeric calculations.
2573 + * @returns {RegExp}
2574 + */
2575 + function getNonNumericShortcodes() {
2576 + return /\[(date|time|email|ip)\]/;
2577 + }
2578 +
2579 + /**
2580 + * Checks if a string has any shortcodes that do not belong in forms and returns a message if any are found.
2581 + * @param formula
2582 + * @returns {string}
2583 + */
2584 + function checkNonFormShortcodes( formula ) {
2585 + var nonFormShortcodes = getNonFormShortcodes(),
2586 + msg = '';
2587 +
2588 + if ( nonFormShortcodes.test( formula ) ) {
2589 + msg += frm_admin_js.view_shortcodes + '\n\n';
2590 + }
2591 +
2592 + return msg;
2593 + }
2594 +
2595 + /**
2596 + * Returns a regular expression of shortcodes that can't be used in forms but can be used in Views, Email
2597 + * Notifications, and other Formidable areas.
2598 + *
2599 + * @returns {RegExp}
2600 + */
2601 + function getNonFormShortcodes() {
2602 + return /\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g;
2603 + }
2604 +
2605 + function isCalcBoxType( box, listClass ) {
2606 + var list = jQuery( box ).find( '.frm_code_list' );
2607 + return 1 === list.length && list.hasClass( listClass );
2608 + }
2609 +
2610 + function extractExcludedOptions( exclude ) {
2611 + var opts = [];
2612 + if ( ! Array.isArray( exclude ) ) {
2613 + return opts;
2614 + }
2615 +
2616 + for ( var i = 0; i < exclude.length; i++ ) {
2617 + if ( exclude[ i ].startsWith( '[' ) ) {
2618 + opts.push( exclude[ i ]);
2619 + // remove it
2620 + exclude.splice( i, 1 );
2621 + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value
2622 + i--;
2623 + }
2624 + }
2625 +
2626 + return opts;
2627 + }
2628 +
2629 + function hasExcludedOption( field, excludedOpts ) {
2630 + var hasOption = false;
2631 + for ( var i = 0; i < excludedOpts.length; i++ ) {
2632 + var inputs = document.getElementsByName( getFieldOptionInputName( excludedOpts[ i ], field.fieldId ) );
2633 + // 2nd condition checks that there's at least one non-empty value
2634 + if ( inputs.length && jQuery( inputs[0]).val() ) {
2635 + hasOption = true;
2636 + break;
2637 + }
2638 + }
2639 + return hasOption;
2640 + }
2641 +
2642 + function getFieldOptionInputName( opt, fieldId ) {
2643 + var at = opt.indexOf( ']' );
2644 + return 'field_options' + opt.substring( 0, at ) + '_' + fieldId + opt.substring( at );
2645 + }
2646 +
2647 + function popCalcFields( v, force ) {
2648 + var box, exclude, fields, i, list,
2649 + p = jQuery( v ).closest( '.frm-single-settings' ),
2650 + calc = p.find( '.frm-calc-field' );
2651 +
2652 + if ( ! force && ( ! calc.length || calc.val() === '' || calc.is( ':hidden' ) ) ) {
2653 + return;
2654 + }
2655 +
2656 + var isSummary = isCalcBoxType( v, 'frm_js_summary_list' );
2657 +
2658 + var fieldId = p.find( 'input[name="frm_fields_submitted[]"]' ).val();
2659 +
2660 + if ( force ) {
2661 + box = v;
2662 + } else {
2663 + box = document.getElementById( 'frm-calc-box-' + fieldId );
2664 + }
2665 +
2666 + exclude = getExcludeArray( box, isSummary );
2667 + var excludedOpts = extractExcludedOptions( exclude );
2668 +
2669 + fields = getFieldList();
2670 + list = document.getElementById( 'frm-calc-list-' + fieldId );
2671 + list.innerHTML = '';
2672 +
2673 + for ( i = 0; i < fields.length; i++ ) {
2674 + if ( ( exclude && exclude.includes( fields[ i ].fieldType ) ) ||
2675 + ( excludedOpts.length && hasExcludedOption( fields[ i ], excludedOpts ) ) ) {
2676 + continue;
2677 + }
2678 +
2679 + var span = document.createElement( 'span' );
2680 + span.appendChild( document.createTextNode( '[' + fields[i].fieldId + ']' ) );
2681 +
2682 + var a = document.createElement( 'a' );
2683 + a.setAttribute( 'href', '#' );
2684 + a.setAttribute( 'data-code', fields[i].fieldId );
2685 + a.classList.add( 'frm_insert_code' );
2686 + a.appendChild( span );
2687 + a.appendChild( document.createTextNode( fields[i].fieldName ) );
2688 +
2689 + var li = document.createElement( 'li' );
2690 + li.classList.add( 'frm-field-list-' + fieldId );
2691 + li.classList.add( 'frm-field-list-' + fields[i].fieldType );
2692 + li.appendChild( a );
2693 + list.appendChild( li );
2694 + }
2695 + }
2696 +
2697 + function getExcludeArray( calcBox, isSummary ) {
2698 + var exclude = JSON.parse( calcBox.getElementsByClassName( 'frm_code_list' )[0].getAttribute( 'data-exclude' ) );
2699 +
2700 + if ( isSummary ) {
2701 + // includedExtras are those that are normally excluded from the summary but the form owner can choose to include,
2702 + // when they have been chosen to be included, then they can now be manually excluded in the calc box.
2703 + var includedExtras = getIncludedExtras();
2704 + if ( includedExtras.length ) {
2705 + for ( var i = 0; i < exclude.length; i++ ) {
2706 + if ( includedExtras.includes( exclude[ i ]) ) {
2707 + // remove it
2708 + exclude.splice( i, 1 );
2709 + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value
2710 + i--;
2711 + }
2712 + }
2713 + }
2714 + }
2715 +
2716 + return exclude;
2717 + }
2718 +
2719 + function getIncludedExtras() {
2720 + var checked = [];
2721 + var checkboxes = document.getElementsByClassName( 'frm_include_extras_field' );
2722 +
2723 + for ( var i = 0; i < checkboxes.length; i++ ) {
2724 + if ( checkboxes[i].checked ) {
2725 + checked.push( checkboxes[i].value );
2726 + }
2727 + }
2728 +
2729 + return checked;
2730 + }
2731 +
2732 + function rePopCalcFieldsForSummary() {
2733 + popCalcFields( jQuery( '.frm-inline-modal.postbox:has(.frm_js_summary_list)' )[0], true );
2734 + }
2735 +
2736 + function getFieldList( fieldType ) {
2737 + var i,
2738 + fields = [],
2739 + allFields = document.querySelectorAll( 'li.frm_field_box' ),
2740 + checkType = 'undefined' !== typeof fieldType;
2741 +
2742 + for ( i = 0; i < allFields.length; i++ ) {
2743 + // data-ftype is better (than data-type) cos of fields loaded by AJAX - which might not be ready yet
2744 + if ( checkType && allFields[ i ].getAttribute( 'data-ftype' ) !== fieldType ) {
2745 + continue;
2746 + }
2747 +
2748 + var fieldId = allFields[ i ].getAttribute( 'data-fid' );
2749 + if ( typeof fieldId !== 'undefined' && fieldId ) {
2750 + fields.push({
2751 + 'fieldId': fieldId,
2752 + 'fieldName': getPossibleValue( 'frm_name_' + fieldId ),
2753 + 'fieldType': getPossibleValue( 'field_options_type_' + fieldId ),
2754 + 'fieldKey': getPossibleValue( 'field_options_field_key_' + fieldId )
2755 + });
2756 + }
2757 + }
2758 +
2759 + return fields;
2760 + }
2761 +
2762 + function popProductFields( field ) {
2763 + var i, checked, id,
2764 + options = [],
2765 + current = getCurrentProductFields( field ),
2766 + fName = field.getAttribute( 'data-frmfname' ),
2767 + products = getFieldList( 'product' ),
2768 + quantities = getFieldList( 'quantity' ),
2769 + isSelect = field.tagName === 'SELECT', // for reverse compatibility.
2770 + // whether we have just 1 product and 1 quantity field & should therefore attach the latter to the former
2771 + auto = 1 === quantities.length && 1 === products.length;
2772 +
2773 + if ( isSelect ) {
2774 + // This fallback can be removed after 4.05.
2775 + current = field.getAttribute( 'data-frmcurrent' );
2776 + }
2777 +
2778 + for ( i = 0 ; i < products.length ; i++ ) {
2779 + // let's be double sure it's string, else indexOf will fail
2780 + id = products[ i ].fieldId.toString();
2781 + checked = auto || -1 !== current.indexOf( id );
2782 + if ( isSelect ) {
2783 + // This fallback can be removed after 4.05.
2784 + checked = checked ? ' selected' : '';
2785 + options.push( '<option value="' + id + '"' + checked + '>' + products[ i ].fieldName + '</option>' );
2786 + } else {
2787 + checked = checked ? ' checked' : '';
2788 + options.push( '<label class="frm6">' );
2789 + options.push( '<input type="checkbox" name="' + fName + '" value="' + id + '"' + checked + '> ' + products[ i ].fieldName );
2790 + options.push( '</label>' );
2791 + }
2792 + }
2793 +
2794 + field.innerHTML = options.join( '' );
2795 + }
2796 +
2797 + function getCurrentProductFields( prodFieldOpt ) {
2798 + var products = prodFieldOpt.querySelectorAll( '[type="checkbox"]:checked' ),
2799 + idsArray = [];
2800 +
2801 + for ( var i = 0; i < products.length; i++ ) {
2802 + idsArray.push( products[ i ].value );
2803 + }
2804 +
2805 + return idsArray;
2806 + }
2807 +
2808 + function popAllProductFields() {
2809 + var opts = document.querySelectorAll( '.frmjs_prod_field_opt' );
2810 + for ( var i = 0; i < opts.length; i++ ) {
2811 + popProductFields( opts[ i ]);
2812 + }
2813 + }
2814 +
2815 + function maybeSetProductField( field ) {
2816 + var fieldId = field.getAttribute( 'data-fid' ),
2817 + productFieldOpt = document.getElementById( 'field_options[product_field_' + fieldId + ']' );
2818 +
2819 + if ( null === productFieldOpt ) {
2820 + return;
2821 + }
2822 +
2823 + popProductFields( productFieldOpt );
2824 + // in order to move its settings to that LHS panel where
2825 + // the update form resides, else it'll lose this setting
2826 + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) );
2827 + }
2828 +
2829 + /**
2830 + * If the element doesn't exist, use a blank value.
2831 + */
2832 + function getPossibleValue( id ) {
2833 + field = document.getElementById( id );
2834 + if ( field !== null ) {
2835 + return field.value;
2836 + } else {
2837 + return '';
2838 + }
2839 + }
2840 +
2841 + function liveChanges() {
2842 + /*jshint validthis:true */
2843 + var option,
2844 + newValue = this.value,
2845 + changes = document.getElementById( this.getAttribute( 'data-changeme' ) ),
2846 + att = this.getAttribute( 'data-changeatt' );
2847 +
2848 + if ( changes === null ) {
2849 + return;
2850 + }
2851 +
2852 + if ( att !== null ) {
2853 + if ( changes.tagName === 'SELECT' && att === 'placeholder' ) {
2854 + option = changes.options[0];
2855 + if ( option.value === '' ) {
2856 + option.innerHTML = newValue;
2857 + } else {
2858 + // Create a placeholder option if there are no blank values.
2859 + addBlankSelectOption( changes, newValue );
2860 + }
2861 + } else if ( att === 'class' ) {
2862 + changeFieldClass( changes, this );
2863 + } else if ( isSliderField( changes ) ) {
2864 + updateSliderFieldPreview( changes, att, newValue );
2865 + } else {
2866 + changes.setAttribute( att, newValue );
2867 + }
2868 + } else if ( changes.id.indexOf( 'setup-message' ) === 0 ) {
2869 + if ( newValue !== '' ) {
2870 + changes.innerHTML = '<input type="text" value="" disabled />';
2871 + }
2872 + } else {
2873 + changes.innerHTML = newValue;
2874 + if ( changes.classList.contains( 'frm_primary_label' ) && 'break' === changes.nextElementSibling.getAttribute( 'data-ftype' ) ) {
2875 + changes.nextElementSibling.querySelector( '.frm_button_submit' ).textContent = newValue;
2876 + }
2877 + }
2878 + }
2879 +
2880 + function updateSliderFieldPreview( field, att, newValue ) {
2881 + if ( frmGlobal.proIncludesSliderJs ) {
2882 + const hookName = 'frm_update_slider_field_preview';
2883 + const hookArgs = { field, att, newValue };
2884 + wp.hooks.doAction( hookName, hookArgs );
2885 + return;
2886 + }
2887 +
2888 + // This functionality has been moved to pro since v5.4.3. This code should be removed eventually.
2889 + if ( 'value' === att ) {
2890 + if ( '' === newValue ) {
2891 + newValue = getSliderMidpoint( field );
2892 + }
2893 + field.value = newValue;
2894 + } else {
2895 + field.setAttribute( att, newValue );
2896 + }
2897 +
2898 + if ( -1 === [ 'value', 'min', 'max' ].indexOf( att ) ) {
2899 + return;
2900 + }
2901 +
2902 + if ( ( 'max' === att || 'min' === att ) && '' === getSliderDefaultValueInput( field.id ) ) {
2903 + field.value = getSliderMidpoint( field );
2904 + }
2905 +
2906 + field.parentNode.querySelector( '.frm_range_value' ).textContent = field.value;
2907 + }
2908 +
2909 + function getSliderDefaultValueInput( previewInputId ) {
2910 + return document.querySelector( 'input[data-changeme="' + previewInputId + '"][data-changeatt="value"]' ).value;
2911 + }
2912 +
2913 + function getSliderMidpoint( sliderInput ) {
2914 + const max = parseFloat( sliderInput.getAttribute( 'max' ) );
2915 + const min = parseFloat( sliderInput.getAttribute( 'min' ) );
2916 + return ( max - min ) / 2 + min;
2917 + }
2918 +
2919 + function isSliderField( previewInput ) {
2920 + return 'range' === previewInput.type && previewInput.parentNode.classList.contains( 'frm_range_container' );
2921 + }
2922 +
2923 + function toggleInvalidMsg() {
2924 + /*jshint validthis:true */
2925 + var typeDropdown, fieldType,
2926 + fieldId = this.getAttribute( 'data-fid' ),
2927 + value = '';
2928 +
2929 + [ 'field_options_max_', 'frm_format_' ].forEach( function( id ) {
2930 + var input = document.getElementById( id + fieldId );
2931 + if ( ! input ) {
2932 + return;
2933 + }
2934 +
2935 + value += input.value;
2936 + });
2937 +
2938 + typeDropdown = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0];
2939 + fieldType = typeDropdown.options[typeDropdown.selectedIndex].value;
2940 +
2941 + if ( fieldType === 'text' ) {
2942 + toggleValidationBox( '' !== value, '.frm_invalid_msg' + fieldId );
2943 + }
2944 + }
2945 +
2946 + function markRequired() {
2947 + /*jshint validthis:true */
2948 + var thisid = this.id.replace( 'frm_', '' ),
2949 + fieldId = thisid.replace( 'req_field_', '' ),
2950 + checked = this.checked,
2951 + label = jQuery( '#field_label_' + fieldId + ' .frm_required' );
2952 +
2953 + toggleValidationBox( checked, '.frm_required_details' + fieldId );
2954 +
2955 + if ( checked ) {
2956 + var $reqBox = jQuery( 'input[name="field_options[required_indicator_' + fieldId + ']"]' );
2957 + if ( $reqBox.val() === '' ) {
2958 + $reqBox.val( '*' );
2959 + }
2960 + label.removeClass( 'frm_hidden' );
2961 + } else {
2962 + label.addClass( 'frm_hidden' );
2963 + }
2964 + }
2965 +
2966 + function toggleValidationBox( hasValue, messageClass ) {
2967 + $msg = jQuery( messageClass );
2968 + if ( hasValue ) {
2969 + $msg.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' );
2970 + } else {
2971 + //Fade out validation options
2972 + var v = $msg.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(' + messageClass + '):visible' ).length;
2973 + if ( v === 0 ) {
2974 + $msg.closest( '.frm_validation_msg' ).fadeOut( 'fast' );
2975 + }
2976 + }
2977 + }
2978 +
2979 + function markUnique() {
2980 + /*jshint validthis:true */
2981 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
2982 + var $thisField = jQuery( '.frm_unique_details' + fieldId );
2983 + if ( this.checked ) {
2984 + $thisField.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' );
2985 + $unqDetail = jQuery( '.frm_unique_details' + fieldId + ' input' );
2986 + if ( $unqDetail.val() === '' ) {
2987 + $unqDetail.val( frm_admin_js.default_unique );
2988 + }
2989 + } else {
2990 + var v = $thisField.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(.frm_unique_details' + fieldId + '):visible' ).length;
2991 + if ( v === 0 ) {
2992 + $thisField.closest( '.frm_validation_msg' ).fadeOut( 'fast' );
2993 + }
2994 + }
2995 + }
2996 +
2997 + //Fade confirmation field and validation option in or out
2998 + function addConf() {
2999 + /*jshint validthis:true */
3000 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3001 + var val = jQuery( this ).val();
3002 + var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) );
3003 +
3004 + toggleValidationBox( val !== '', '.frm_conf_details' + fieldId );
3005 +
3006 + if ( val !== '' ) {
3007 + //Add default validation message if empty
3008 + var valMsg = jQuery( '.frm_validation_box .frm_conf_details' + fieldId + ' input' );
3009 + if ( valMsg.val() === '' ) {
3010 + valMsg.val( frm_admin_js.default_conf );
3011 + }
3012 +
3013 + setConfirmationFieldDescriptions( fieldId );
3014 +
3015 + //Add or remove class for confirmation field styling
3016 + if ( val === 'inline' ) {
3017 + $thisField.removeClass( 'frm_conf_below' ).addClass( 'frm_conf_inline' );
3018 + } else if ( val === 'below' ) {
3019 + $thisField.removeClass( 'frm_conf_inline' ).addClass( 'frm_conf_below' );
3020 + }
3021 + jQuery( '.frm-conf-box-' + fieldId ).removeClass( 'frm_hidden' );
3022 + } else {
3023 + jQuery( '.frm-conf-box-' + fieldId ).addClass( 'frm_hidden' );
3024 + setTimeout( function() {
3025 + $thisField.removeClass( 'frm_conf_inline frm_conf_below' );
3026 + }, 200 );
3027 + }
3028 + }
3029 +
3030 + function setConfirmationFieldDescriptions( fieldId ) {
3031 + var fieldType = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0].value;
3032 +
3033 + var fieldDescription = document.getElementById( 'field_description_' + fieldId );
3034 + var hiddenDescName = 'field_options[description_' + fieldId + ']';
3035 + var newValue = frm_admin_js['enter_' + fieldType];
3036 + maybeSetNewDescription( fieldDescription, hiddenDescName, newValue );
3037 +
3038 + var confFieldDescription = document.getElementById( 'conf_field_description_' + fieldId );
3039 + var hiddenConfName = 'field_options[conf_desc_' + fieldId + ']';
3040 + var newConfValue = frm_admin_js['confirm_' + fieldType];
3041 + maybeSetNewDescription( confFieldDescription, hiddenConfName, newConfValue );
3042 + }
3043 +
3044 + function maybeSetNewDescription( descriptionDiv, hiddenName, newValue ) {
3045 + if ( descriptionDiv.innerHTML === frm_admin_js.desc ) {
3046 +
3047 + // Set the visible description value and the hidden description value
3048 + descriptionDiv.innerHTML = newValue;
3049 + document.getElementsByName( hiddenName )[0].value = newValue;
3050 + }
3051 + }
3052 +
3053 + function initBulkOptionsOverlay() {
3054 + /*jshint validthis:true */
3055 + var $info = initModal( '#frm-bulk-modal', '700px' );
3056 + if ( $info === false ) {
3057 + return;
3058 + }
3059 +
3060 + jQuery( '.frm-insert-preset' ).on( 'click', insertBulkPreset );
3061 +
3062 + jQuery( builderForm ).on( 'click', 'a.frm-bulk-edit-link', function( event ) {
3063 + event.preventDefault();
3064 + var i, key, label,
3065 + content = '',
3066 + optList,
3067 + opts,
3068 + fieldId = jQuery( this ).closest( '[data-fid]' ).data( 'fid' ),
3069 + separate = usingSeparateValues( fieldId ),
3070 + product = isProductField( fieldId );
3071 +
3072 + optList = document.getElementById( 'frm_field_' + fieldId + '_opts' );
3073 + if ( ! optList ) {
3074 + return;
3075 + }
3076 +
3077 + opts = optList.getElementsByTagName( 'li' );
3078 +
3079 + document.getElementById( 'bulk-field-id' ).value = fieldId;
3080 +
3081 + for ( i = 0; i < opts.length; i++ ) {
3082 + key = opts[i].getAttribute( 'data-optkey' );
3083 + if ( key !== '000' ) {
3084 + label = document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][label]' )[0];
3085 + if ( typeof label !== 'undefined' ) {
3086 + content += label.value;
3087 + if ( separate ) {
3088 + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][value]' )[0].value;
3089 + }
3090 + if ( product ) {
3091 + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][price]' )[0].value;
3092 + }
3093 + content += '\r\n';
3094 + }
3095 + }
3096 +
3097 + if ( i >= opts.length - 1 ) {
3098 + document.getElementById( 'frm_bulk_options' ).value = content;
3099 + }
3100 + }
3101 +
3102 + $info.dialog( 'open' );
3103 +
3104 + return false;
3105 + });
3106 +
3107 + jQuery( '#frm-update-bulk-opts' ).on( 'click', function() {
3108 + var fieldId = document.getElementById( 'bulk-field-id' ).value;
3109 + var optionType = document.getElementById( 'bulk-option-type' ).value;
3110 +
3111 + if ( optionType ) {
3112 + // Use custom handler for custom option type.
3113 + return;
3114 + }
3115 +
3116 + this.classList.add( 'frm_loading_button' );
3117 + frmAdminBuild.updateOpts( fieldId, document.getElementById( 'frm_bulk_options' ).value, $info );
3118 + });
3119 + }
3120 +
3121 + function insertBulkPreset( event ) {
3122 + /*jshint validthis:true */
3123 + var opts = JSON.parse( this.getAttribute( 'data-opts' ) );
3124 + event.preventDefault();
3125 + document.getElementById( 'frm_bulk_options' ).value = opts.join( '\n' );
3126 + return false;
3127 + }
3128 +
3129 + //Add new option or "Other" option to radio/checkbox/dropdown
3130 + function addFieldOption() {
3131 + /*jshint validthis:true */
3132 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
3133 + newOption = jQuery( '#frm_field_' + fieldId + '_opts .frm_option_template' ).prop( 'outerHTML' ),
3134 + optType = jQuery( this ).data( 'opttype' ),
3135 + optKey = 0,
3136 + oldKey = '000',
3137 + lastKey = getHighestOptKey( fieldId );
3138 +
3139 + if ( lastKey !== oldKey ) {
3140 + optKey = lastKey + 1;
3141 + }
3142 +
3143 + //Update hidden field
3144 + if ( optType === 'other' ) {
3145 + document.getElementById( 'other_input_' + fieldId ).value = 1;
3146 +
3147 + //Hide "Add Other" option now if this is radio field
3148 + var ftype = jQuery( this ).data( 'ftype' );
3149 + if ( ftype === 'radio' || ftype === 'select' ) {
3150 + jQuery( this ).fadeOut( 'slow' );
3151 + }
3152 +
3153 + var data = {
3154 + action: 'frm_add_field_option',
3155 + field_id: fieldId,
3156 + opt_key: optKey,
3157 + opt_type: optType,
3158 + nonce: frmGlobal.nonce
3159 + };
3160 + jQuery.post( ajaxurl, data, function( msg ) {
3161 + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( msg );
3162 + resetDisplayedOpts( fieldId );
3163 + });
3164 + } else {
3165 + newOption = newOption.replace( new RegExp( 'optkey="' + oldKey + '"', 'g' ), 'optkey="' + optKey + '"' );
3166 + newOption = newOption.replace( new RegExp( '-' + oldKey + '_', 'g' ), '-' + optKey + '_' );
3167 + newOption = newOption.replace( new RegExp( '-' + oldKey + '"', 'g' ), '-' + optKey + '"' );
3168 + newOption = newOption.replace( new RegExp( '\\[' + oldKey + '\\]', 'g' ), '[' + optKey + ']' );
3169 + newOption = newOption.replace( 'frm_hidden frm_option_template', '' );
3170 + newOption = { newOption };
3171 + addSaveAndDragIconsToOption( fieldId, newOption );
3172 + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( newOption.newOption );
3173 + resetDisplayedOpts( fieldId );
3174 + }
3175 + }
3176 +
3177 + function getHighestOptKey( fieldId ) {
3178 + var i = 0,
3179 + optKey = 0,
3180 + opts = jQuery( '#frm_field_' + fieldId + '_opts li' ),
3181 + lastKey = 0;
3182 +
3183 + for ( i; i < opts.length; i++ ) {
3184 + optKey = opts[i].getAttribute( 'data-optkey' );
3185 + if ( opts.length === 1 ) {
3186 + return optKey;
3187 + }
3188 + if ( optKey !== '000' ) {
3189 + optKey = optKey.replace( 'other_', '' );
3190 + optKey = parseInt( optKey, 10 );
3191 + }
3192 +
3193 + if ( ! isNaN( lastKey ) && ( optKey > lastKey || lastKey === '000' ) ) {
3194 + lastKey = optKey;
3195 + }
3196 + }
3197 +
3198 + return lastKey;
3199 + }
3200 +
3201 + function toggleMultSel() {
3202 + /*jshint validthis:true */
3203 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3204 + toggleMultiSelect( fieldId, this.value );
3205 + }
3206 +
3207 + function toggleMultiSelect( fieldId, value ) {
3208 + var setting = jQuery( '.frm_multiple_cont_' + fieldId );
3209 + if ( value === 'select' ) {
3210 + setting.fadeIn( 'fast' );
3211 + } else {
3212 + setting.fadeOut( 'fast' );
3213 + }
3214 + }
3215 +
3216 + function toggleSepValues() {
3217 + /*jshint validthis:true */
3218 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
3219 + toggle( jQuery( '.field_' + fieldId + '_option_key' ) );
3220 + jQuery( '.field_' + fieldId + '_option' ).toggleClass( 'frm_with_key' );
3221 + }
3222 +
3223 + function toggleImageOptions() {
3224 + /*jshint validthis:true */
3225 + var hasImageOptions, imageSize,
3226 + $field = jQuery( this ).closest( '.frm-single-settings' ),
3227 + fieldId = $field.data( 'fid' ),
3228 + displayField = document.getElementById( 'frm_field_id_' + fieldId );
3229 +
3230 + refreshOptionDisplayNow( jQuery( this ) );
3231 +
3232 + toggle( jQuery( '.field_' + fieldId + '_image_id' ) );
3233 + toggle( jQuery( '.frm_toggle_image_options_' + fieldId ) );
3234 + toggle( jQuery( '.frm_image_size_' + fieldId ) );
3235 + toggle( jQuery( '.frm_alignment_' + fieldId ) );
3236 + toggle( jQuery( '.frm-add-other#frm_add_field_' + fieldId ) );
3237 +
3238 + hasImageOptions = imagesAsOptions( fieldId );
3239 +
3240 + if ( hasImageOptions ) {
3241 + setAlignment( fieldId, 'inline' );
3242 + removeImageSizeClasses( displayField );
3243 + imageSize = getImageOptionSize( fieldId );
3244 + displayField.classList.add( 'frm_image_options' );
3245 + displayField.classList.add( 'frm_image_size_' + imageSize );
3246 + $field.find( '.frm-bulk-edit-link' ).hide();
3247 + } else {
3248 + displayField.classList.remove( 'frm_image_options' );
3249 + removeImageSizeClasses( displayField );
3250 + setAlignment( fieldId, 'block' );
3251 + $field.find( '.frm-bulk-edit-link' ).show();
3252 + }
3253 + }
3254 +
3255 + function removeImageSizeClasses( field ) {
3256 + field.classList.remove( 'frm_image_size_', 'frm_image_size_small', 'frm_image_size_medium', 'frm_image_size_large', 'frm_image_size_xlarge' );
3257 + }
3258 +
3259 + function setAlignment( fieldId, alignment ) {
3260 + jQuery( '#field_options_align_' + fieldId ).val( alignment ).trigger( 'change' );
3261 + }
3262 +
3263 + function setImageSize() {
3264 + var $field = jQuery( this ).closest( '.frm-single-settings' ),
3265 + fieldId = $field.data( 'fid' ),
3266 + displayField = document.getElementById( 'frm_field_id_' + fieldId );
3267 +
3268 + refreshOptionDisplay();
3269 +
3270 + if ( imagesAsOptions( fieldId ) ) {
3271 + removeImageSizeClasses( displayField );
3272 + displayField.classList.add( 'frm_image_options' );
3273 + displayField.classList.add( 'frm_image_size_' + getImageOptionSize( fieldId ) );
3274 + }
3275 + }
3276 +
3277 + function refreshOptionDisplayNow( object ) {
3278 + var $field = object.closest( '.frm-single-settings' ),
3279 + fieldID = $field.data( 'fid' );
3280 + jQuery( '.field_' + fieldID + '_option' ).trigger( 'change' );
3281 + }
3282 +
3283 + function refreshOptionDisplay() {
3284 + /*jshint validthis:true */
3285 + refreshOptionDisplayNow( jQuery( this ) );
3286 + }
3287 +
3288 + function addImageToOption( event ) {
3289 + const imagePreview = event.target.closest( '.frm_image_preview_wrapper' );
3290 +
3291 + event.preventDefault();
3292 +
3293 + wp.media.model.settings.post.id = 0;
3294 +
3295 + const fileFrame = wp.media.frames.file_frame = wp.media({
3296 + multiple: false,
3297 + library: {
3298 + type: [ 'image' ]
3299 + }
3300 + });
3301 +
3302 + fileFrame.on( 'select', function() {
3303 + const attachment = fileFrame.state().get( 'selection' ).first().toJSON();
3304 + const img = imagePreview.querySelector( 'img' );
3305 +
3306 + img.setAttribute( 'src', attachment.url );
3307 + img.classList.remove( 'frm_hidden' );
3308 + img.removeAttribute( 'srcset' ); // Prevent the old image from sticking around.
3309 +
3310 + imagePreview.querySelector( '.frm_image_preview_frame' ).style.display = 'block';
3311 + imagePreview.querySelector( '.frm_image_preview_title' ).textContent = attachment.filename;
3312 + imagePreview.querySelector( '.frm_choose_image_box' ).style.display = 'none';
3313 +
3314 + const $imagePreview = jQuery( imagePreview );
3315 + $imagePreview.siblings( 'input[name*="[label]"]' ).data( 'frmimgurl', attachment.url );
3316 + $imagePreview.find( 'input.frm_image_id' ).val( attachment.id ).trigger( 'change' );
3317 + wp.media.model.settings.post.id = 0;
3318 + });
3319 +
3320 + fileFrame.open();
3321 + }
3322 +
3323 + function removeImageFromOption( event ) {
3324 + var $this = jQuery( this ),
3325 + previewWrapper = $this.closest( '.frm_image_preview_wrapper' );
3326 +
3327 + event.preventDefault();
3328 + event.stopPropagation();
3329 +
3330 + previewWrapper.find( 'img' ).attr( 'src', '' );
3331 + previewWrapper.find( '.frm_image_preview_frame' ).hide();
3332 + previewWrapper.find( '.frm_choose_image_box' ).show();
3333 + previewWrapper.find( 'input.frm_image_id' ).val( 0 ).trigger( 'change' );
3334 + }
3335 +
3336 + function toggleMultiselect() {
3337 + /*jshint validthis:true */
3338 + var dropdown = jQuery( this ).closest( 'li' ).find( '.frm_form_fields select' );
3339 + if ( this.checked ) {
3340 + dropdown.attr( 'multiple', 'multiple' );
3341 + } else {
3342 + dropdown.removeAttr( 'multiple' );
3343 + }
3344 + }
3345 +
3346 + /**
3347 + * Allow typing on form switcher click without an extra click to search.
3348 + */
3349 + function focusSearchBox() {
3350 + var searchBox = document.getElementById( 'dropform-search-input' );
3351 + if ( searchBox !== null ) {
3352 + setTimeout( function() {
3353 + searchBox.focus();
3354 + }, 100 );
3355 + }
3356 + }
3357 +
3358 + /**
3359 + * If a field is clicked in the builder, prevent inputs from changing.
3360 + */
3361 + function stopFieldFocus( e ) {
3362 + e.preventDefault();
3363 + }
3364 +
3365 + function deleteFieldOption() {
3366 + /*jshint validthis:true */
3367 + var otherInput,
3368 + parentLi = this.parentNode,
3369 + parentUl = parentLi.parentNode,
3370 + fieldId = this.getAttribute( 'data-fid' );
3371 +
3372 + jQuery( parentLi ).fadeOut( 'slow', function() {
3373 + jQuery( parentLi ).remove();
3374 +
3375 + var hasOther = jQuery( parentUl ).find( '.frm_other_option' );
3376 + if ( hasOther.length < 1 ) {
3377 + otherInput = document.getElementById( 'other_input_' + fieldId );
3378 + if ( otherInput !== null ) {
3379 + otherInput.value = 0;
3380 + }
3381 + jQuery( '#other_button_' + fieldId ).fadeIn( 'slow' );
3382 + }
3383 + });
3384 + }
3385 +
3386 + /**
3387 + * If a radio button is set as default, allow a click to
3388 + * deselect it.
3389 + */
3390 + function maybeUncheckRadio() {
3391 + var $self, uncheck, unbind, up;
3392 +
3393 + /*jshint validthis:true */
3394 + $self = jQuery( this );
3395 + if ( $self.is( ':checked' ) ) {
3396 + uncheck = function() {
3397 + setTimeout( function() {
3398 + $self.prop( 'checked', false );
3399 + }, 0 );
3400 + };
3401 + unbind = function() {
3402 + $self.off( 'mouseup', up );
3403 + };
3404 + up = function() {
3405 + uncheck();
3406 + unbind();
3407 + };
3408 + $self.on( 'mouseup', up );
3409 + $self.one( 'mouseout', unbind );
3410 + }
3411 + }
3412 +
3413 + /**
3414 + * If the field option has the default text, clear it out on click.
3415 + */
3416 + function maybeClearOptText() {
3417 + /*jshint validthis:true */
3418 + if ( this.value === frm_admin_js.new_option ) {
3419 + this.setAttribute( 'data-value-on-focus', this.value );
3420 + this.value = '';
3421 + }
3422 + }
3423 +
3424 + function clickDeleteField() {
3425 + /*jshint validthis:true */
3426 + var confirmMsg = frm_admin_js.conf_delete,
3427 + maybeDivider = this.parentNode.parentNode.parentNode.parentNode.parentNode,
3428 + li = maybeDivider.parentNode,
3429 + field = jQuery( this ).closest( 'li.form-field' ),
3430 + fieldId = field.data( 'fid' );
3431 +
3432 + if ( li.classList.contains( 'frm-section-collapsed' ) || li.classList.contains( 'frm-page-collapsed' ) ) {
3433 + return false;
3434 + }
3435 +
3436 + // If deleting a section, use a special message.
3437 + if ( maybeDivider.className === 'divider_section_only' ) {
3438 + confirmMsg = frm_admin_js.conf_delete_sec;
3439 + this.setAttribute( 'data-frmcaution', frm_admin_js.caution );
3440 + }
3441 +
3442 + this.setAttribute( 'data-frmverify', confirmMsg );
3443 + this.setAttribute( 'data-deletefield', fieldId );
3444 +
3445 + closeOpenFieldDropdowns();
3446 +
3447 + confirmLinkClick( this );
3448 + return false;
3449 + }
3450 +
3451 + function clickSelectField() {
3452 + this.closest( 'li.form-field' ).click();
3453 + }
3454 +
3455 + function clickDeleteFieldGroup() {
3456 + var hoverTarget, decoy;
3457 +
3458 + hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3459 + if ( null === hoverTarget ) {
3460 + return;
3461 + }
3462 +
3463 + hoverTarget.classList.add( 'frm-selected-field-group' );
3464 +
3465 + decoy = document.createElement( 'div' );
3466 + decoy.classList.add( 'frm-delete-field-groups', 'frm_hidden' );
3467 + document.body.appendChild( decoy );
3468 + decoy.click();
3469 + }
3470 +
3471 + function duplicateFieldGroup() {
3472 + var hoverTarget, newRowId, $newRow, $fields, syncDetails, expectedLength, duplicatedCount, originalFieldIdByDuplicatedFieldId, injectedCloneOptions;
3473 +
3474 + hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3475 +
3476 + if ( null === hoverTarget ) {
3477 + return;
3478 + }
3479 +
3480 + newRowId = 'frm_field_group_' + getAutoId();
3481 + $newRow = wrapFieldLi( '' );
3482 + $newRowUl = $newRow.find( 'ul' );
3483 + $newRowUl.attr( 'id', newRowId );
3484 + $newRow.addClass( 'frm_hidden' );
3485 + jQuery( hoverTarget ).closest( 'li.frm_field_box' ).after( $newRow );
3486 +
3487 + $fields = getFieldsInRow( jQuery( hoverTarget ) );
3488 + syncDetails = [];
3489 + injectedCloneOptions = [];
3490 +
3491 + expectedLength = $fields.length;
3492 + duplicatedCount = 0;
3493 + originalFieldIdByDuplicatedFieldId = {};
3494 +
3495 + $newRow.on(
3496 + 'frm_added_duplicated_field_to_row',
3497 + function( event, args ) {
3498 + var $duplicatedFields, index;
3499 +
3500 + originalFieldIdByDuplicatedFieldId[ jQuery( args.duplicatedFieldHtml ).attr( 'data-fid' ) ] = args.originalFieldId;
3501 +
3502 + if ( expectedLength > ++duplicatedCount ) {
3503 + return;
3504 + }
3505 +
3506 + $duplicatedFields = getFieldsInRow( $newRowUl );
3507 +
3508 + injectedCloneOptions.forEach(
3509 + function( cloneOption ) {
3510 + cloneOption.remove();
3511 + }
3512 + );
3513 +
3514 + for ( index = 0; index < expectedLength; ++index ) {
3515 + $newRowUl.append( $newRowUl.children( 'li.form-field[frm-field-order="' + index + '"]' ) );
3516 + }
3517 +
3518 + syncLayoutClasses( $duplicatedFields.first(), syncDetails );
3519 + $newRow.removeClass( 'frm_hidden' );
3520 + updateFieldOrder();
3521 +
3522 + getFieldsInRow( $newRowUl ).each(
3523 + function() {
3524 + maybeDuplicateUnsavedSettings( originalFieldIdByDuplicatedFieldId[ this.getAttribute( 'data-fid' ) ], jQuery( this ).prop( 'outerHTML' ) );
3525 + }
3526 + );
3527 + }
3528 + );
3529 +
3530 + $fields.each(
3531 + function( index ) {
3532 + var cloneOption;
3533 + cloneOption = document.createElement( 'li' );
3534 + cloneOption.classList.add( 'frm_clone_field' );
3535 + cloneOption.setAttribute( 'frm-target-row-id', newRowId );
3536 + cloneOption.setAttribute( 'frm-field-order', index );
3537 + this.appendChild( cloneOption );
3538 + cloneOption.click();
3539 + injectedCloneOptions.push( cloneOption );
3540 + syncDetails.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) );
3541 + }
3542 + );
3543 + }
3544 +
3545 + function clickFieldGroupLayout() {
3546 + var hoverTarget, sizeOfFieldGroup, popupWrapper;
3547 +
3548 + hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3549 +
3550 + if ( null === hoverTarget ) {
3551 + return;
3552 + }
3553 +
3554 + deselectFields();
3555 +
3556 + sizeOfFieldGroup = getSizeOfFieldGroupFromChildElement( hoverTarget.querySelector( 'li.form-field' ) );
3557 +
3558 + hoverTarget.classList.add( 'frm-has-open-field-group-popup' );
3559 + jQuery( document ).on( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick );
3560 +
3561 + popupWrapper = div();
3562 + popupWrapper.style.position = 'relative';
3563 + popupWrapper.appendChild( getFieldGroupPopup( sizeOfFieldGroup, this ) );
3564 + this.parentNode.appendChild( popupWrapper );
3565 +
3566 + const firstLayoutOption = popupWrapper.querySelector( '.frm-row-layout-option' );
3567 + if ( firstLayoutOption ) {
3568 + firstLayoutOption.focus();
3569 + }
3570 + }
3571 +
3572 + function destroyFieldGroupPopupOnOutsideClick( event ) {
3573 + if ( event.target.classList.contains( 'frm-custom-field-group-layout' ) || event.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) {
3574 + return;
3575 + }
3576 + if ( ! jQuery( event.target ).closest( '#frm_field_group_controls' ).length && ! jQuery( event.target ).closest( '#frm_field_group_popup' ).length ) {
3577 + destroyFieldGroupPopup();
3578 + }
3579 + }
3580 +
3581 + function getSizeOfFieldGroupFromChildElement( element ) {
3582 + var $ul = jQuery( element ).closest( 'ul' );
3583 + if ( $ul.length ) {
3584 + return getFieldsInRow( $ul ).length;
3585 + }
3586 + return getSelectedFieldCount();
3587 + }
3588 +
3589 + function getFieldGroupPopup( sizeOfFieldGroup, childElement ) {
3590 + var popup, wrapper, rowLayoutOptions, ul;
3591 +
3592 + popup = document.getElementById( 'frm_field_group_popup' );
3593 + if ( null === popup ) {
3594 + popup = div();
3595 + } else {
3596 + popup.innerHTML = '';
3597 + }
3598 +
3599 + popup.id = 'frm_field_group_popup';
3600 +
3601 + wrapper = div();
3602 + wrapper.style.padding = '0 24px 12px';
3603 + wrapper.appendChild( getRowLayoutTitle() );
3604 +
3605 + rowLayoutOptions = getRowLayoutOptions( sizeOfFieldGroup );
3606 +
3607 + ul = childElement.closest( 'ul.frm_sorting' );
3608 + if ( null !== ul ) {
3609 + maybeMarkRowLayoutAsActive( ul, rowLayoutOptions );
3610 + }
3611 +
3612 + wrapper.appendChild( rowLayoutOptions );
3613 +
3614 + popup.appendChild( wrapper );
3615 + popup.appendChild( separator() );
3616 +
3617 + popup.appendChild( getCustomLayoutOption() );
3618 + popup.appendChild( getBreakIntoDifferentRowsOption() );
3619 +
3620 + return popup;
3621 + }
3622 +
3623 + function maybeMarkRowLayoutAsActive( activeRow, options ) {
3624 + var length, index, currentRow;
3625 +
3626 + length = options.children.length;
3627 + for ( index = 0; index < length; ++index ) {
3628 + currentRow = options.children[ index ];
3629 + if ( rowLayoutsMatch( currentRow, activeRow ) ) {
3630 + currentRow.classList.add( 'frm-active-row-layout' );
3631 + return;
3632 + }
3633 + }
3634 + }
3635 +
3636 + function separator() {
3637 + var hr = document.createElement( 'hr' );
3638 + return hr;
3639 + }
3640 +
3641 + function getCustomLayoutOption() {
3642 + var option = div();
3643 + option.textContent = __( 'Custom layout', 'formidable' );
3644 + jQuery( option ).prepend( getIconClone( 'frm_gear_svg' ) );
3645 + option.classList.add( 'frm-custom-field-group-layout' );
3646 + makeTabbable( option );
3647 + return option;
3648 + }
3649 +
3650 + function makeTabbable( element, ariaLabel ) {
3651 + element.setAttribute( 'tabindex', 0 );
3652 + element.setAttribute( 'role', 'button' );
3653 + if ( 'undefined' !== typeof ariaLabel ) {
3654 + element.setAttribute( 'aria-label', ariaLabel );
3655 + }
3656 + }
3657 +
3658 + function getIconClone( iconId ) {
3659 + var clone = document.getElementById( iconId ).cloneNode( true );
3660 + clone.id = '';
3661 + return clone;
3662 + }
3663 +
3664 + function getBreakIntoDifferentRowsOption() {
3665 + var option = div();
3666 + option.textContent = __( 'Break into rows', 'formidable' );
3667 + jQuery( option ).prepend( getIconClone( 'frm_break_field_group_svg' ) );
3668 + option.classList.add( 'frm-break-field-group' );
3669 + makeTabbable( option );
3670 + return option;
3671 + }
3672 +
3673 + function getRowLayoutTitle() {
3674 + var rowLayoutTitle = div();
3675 + rowLayoutTitle.classList.add( 'frm-row-layout-title' );
3676 + rowLayoutTitle.textContent = __( 'Row Layout', 'formidable' );
3677 + return rowLayoutTitle;
3678 + }
3679 +
3680 + function getRowLayoutOptions( size ) {
3681 + var wrapper, padding;
3682 +
3683 + wrapper = getEmptyGridContainer();
3684 + if ( 5 !== size ) {
3685 + wrapper.appendChild( getRowLayoutOption( size, 'even' ) );
3686 + }
3687 + if ( size % 2 === 1 ) {
3688 + // only include the middle option for odd numbers because even doesn't make a lot of sense.
3689 + wrapper.appendChild( getRowLayoutOption( size, 'middle' ) );
3690 + }
3691 + if ( size < 6 ) {
3692 + wrapper.appendChild( getRowLayoutOption( size, 'left' ) );
3693 + wrapper.appendChild( getRowLayoutOption( size, 'right' ) );
3694 + } else {
3695 + padding = div();
3696 + padding.classList.add( 'frm_fourth' );
3697 + wrapper.prepend( padding );
3698 + }
3699 +
3700 + return wrapper;
3701 + }
3702 +
3703 + function getRowLayoutOption( size, type ) {
3704 + var option, useClass;
3705 +
3706 + option = div();
3707 + option.classList.add( 'frm-row-layout-option' );
3708 + makeTabbable( option, type );
3709 +
3710 + switch ( size ) {
3711 + case 6:
3712 + useClass = 'frm_half';
3713 + break;
3714 + case 5:
3715 + useClass = 'frm_third';
3716 + break;
3717 + default:
3718 + useClass = size % 2 === 1 ? 'frm_fourth' : 'frm_third';
3719 + break;
3720 + }
3721 +
3722 + option.classList.add( useClass );
3723 + option.setAttribute( 'layout-type', type );
3724 +
3725 + option.appendChild( getRowForSizeAndType( size, type ) );
3726 + return option;
3727 + }
3728 +
3729 + function rowLayoutsMatch( row1, row2 ) {
3730 + return getRowLayoutAsKey( row1 ) === getRowLayoutAsKey( row2 );
3731 + }
3732 +
3733 + function getRowLayoutAsKey( row ) {
3734 + var $fields, sizes;
3735 + if ( row.classList.contains( 'frm-row-layout-option' ) ) {
3736 + $fields = jQuery( row ).find( '.frm_grid_container' ).children();
3737 + } else {
3738 + $fields = getFieldsInRow( jQuery( row ) );
3739 + }
3740 + sizes = [];
3741 + $fields.each(
3742 + function() {
3743 + sizes.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) );
3744 + }
3745 + );
3746 + return sizes.join( '-' );
3747 + }
3748 +
3749 + function getRowForSizeAndType( size, type ) {
3750 + var row, index, block;
3751 +
3752 + row = getEmptyGridContainer();
3753 + for ( index = 0; index < size; ++index ) {
3754 + block = div();
3755 + block.classList.add( getClassForBlock( size, type, index ) );
3756 + block.style.height = '16px';
3757 + block.style.background = '#9EA9B8';
3758 + block.style.borderRadius = '1px';
3759 + row.appendChild( block );
3760 + }
3761 +
3762 + return row;
3763 + }
3764 +
3765 + /**
3766 + * @param {int} size 2-6.
3767 + * @param {string} type even, middle, left, or right.
3768 + * @param {int} index 0-5.
3769 + * @returns string
3770 + */
3771 + function getClassForBlock( size, type, index ) {
3772 + if ( 'even' === type ) {
3773 + return getEvenClassForSize( size, index );
3774 + } else if ( 'middle' === type ) {
3775 + if ( 3 === size ) {
3776 + return 1 === index ? 'frm6' : 'frm3';
3777 + }
3778 + if ( 5 === size ) {
3779 + return 2 === index ? 'frm4' : 'frm2';
3780 + }
3781 + } else if ( 'left' === type ) {
3782 + return 0 === index ? getLargeClassForSize( size ) : getSmallClassForSize( size );
3783 + } else if ( 'right' === type ) {
3784 + return index === size - 1 ? getLargeClassForSize( size ) : getSmallClassForSize( size );
3785 + }
3786 + return 'frm12';
3787 + }
3788 +
3789 + function getEvenClassForSize( size, index ) {
3790 + if ( -1 !== [ 2, 3, 4, 6 ].indexOf( size ) ) {
3791 + return getLayoutClassForSize( 12 / size );
3792 + }
3793 + if ( 5 === size && 'undefined' !== typeof index ) {
3794 + return 0 === index ? 'frm4' : 'frm2';
3795 + }
3796 + return 'frm12';
3797 + }
3798 +
3799 + function getSmallClassForSize( size ) {
3800 + switch ( size ) {
3801 + case 2: case 3:
3802 + return 'frm3';
3803 + case 4:
3804 + return 'frm2';
3805 + case 5:
3806 + return 'frm2';
3807 + case 6:
3808 + return 'frm1';
3809 + }
3810 + return 'frm12';
3811 + }
3812 +
3813 + function getLargeClassForSize( size ) {
3814 + switch ( size ) {
3815 + case 2:
3816 + return 'frm9';
3817 + case 3: case 4:
3818 + return 'frm6';
3819 + case 5:
3820 + return 'frm4';
3821 + case 6:
3822 + return 'frm7';
3823 + }
3824 + return 'frm12';
3825 + }
3826 +
3827 + function getEmptyGridContainer() {
3828 + var wrapper = div();
3829 + wrapper.classList.add( 'frm_grid_container' );
3830 + return wrapper;
3831 + }
3832 +
3833 + function handleFieldGroupLayoutOptionClick() {
3834 + var type, row;
3835 + type = this.getAttribute( 'layout-type' );
3836 + row = document.querySelector( '.frm-field-group-hover-target' );
3837 + size = getFieldsInRow( jQuery( row ) ).length;
3838 + syncLayoutClasses( getFieldsInRow( jQuery( row ) ).first(), type );
3839 + destroyFieldGroupPopup();
3840 + }
3841 +
3842 + function handleFieldGroupLayoutOptionInsideMergeClick() {
3843 + var $ul, type;
3844 + $ul = mergeSelectedFieldGroups();
3845 + type = this.getAttribute( 'layout-type' );
3846 + syncLayoutClasses( getFieldsInRow( $ul ).first(), type );
3847 + unselectFieldGroups();
3848 + }
3849 +
3850 + function mergeSelectedFieldGroups() {
3851 + var $selectedFieldGroups = jQuery( '.frm-selected-field-group' ),
3852 + $firstGroupUl = $selectedFieldGroups.first();
3853 + $selectedFieldGroups.not( $firstGroupUl ).each(
3854 + function() {
3855 + getFieldsInRow( jQuery( this ) ).each(
3856 + function() {
3857 + var previousParent = this.parentNode;
3858 + getFieldsInRow( $firstGroupUl ).last().after( this );
3859 + if ( ! jQuery( previousParent ).children( 'li.form-field' ).length ) {
3860 + // clean up the previous field group if we've removed all of its fields.
3861 + previousParent.closest( 'li.frm_field_box' ).remove();
3862 + }
3863 + }
3864 + );
3865 + }
3866 + );
3867 + updateFieldOrder();
3868 + syncLayoutClasses( getFieldsInRow( $firstGroupUl ).first() );
3869 + return $firstGroupUl;
3870 + }
3871 +
3872 + function customFieldGroupLayoutClick() {
3873 + var $fields;
3874 + if ( null !== this.closest( '.frm-merge-fields-into-row' ) ) {
3875 + return;
3876 + }
3877 + $fields = getFieldsInRow( jQuery( '.frm-field-group-hover-target' ) );
3878 + setupCustomLayoutOptions( $fields );
3879 + }
3880 +
3881 + function setupCustomLayoutOptions( $fields ) {
3882 + var size, popup, wrapper, layoutClass, inputRow, paddingElement, inputValueOverride, index, inputField, heading, label, buttonsWrapper, cancelButton, saveButton;
3883 +
3884 + size = $fields.length;
3885 +
3886 + popup = document.getElementById( 'frm_field_group_popup' );
3887 + popup.innerHTML = '';
3888 +
3889 + wrapper = div();
3890 + wrapper.style.padding = '24px';
3891 +
3892 + layoutClass = getEvenClassForSize( 5 === size ? 6 : size );
3893 +
3894 + inputRow = div();
3895 + inputRow.style.padding = '20px 0';
3896 + inputRow.classList.add( 'frm_grid_container' );
3897 +
3898 + if ( 5 === size ) {
3899 + // add a span to pad the inputs by 1 column, to account for the missing 2 columns.
3900 + paddingElement = document.createElement( 'span' );
3901 + paddingElement.classList.add( 'frm1' );
3902 + inputRow.appendChild( paddingElement );
3903 + }
3904 +
3905 + inputValueOverride = getSelectedFieldCount() > 0 ? getSizeOfLayoutClass( getEvenClassForSize( size ) ) : false;
3906 + if ( false !== inputValueOverride && inputValueOverride >= 12 ) {
3907 + inputValueOverride = Math.floor( 12 / size );
3908 + }
3909 +
3910 + for ( index = 0; index < size; ++index ) {
3911 + inputField = document.createElement( 'input' );
3912 + inputField.type = 'text';
3913 + inputField.classList.add( layoutClass );
3914 + inputField.classList.add( 'frm-custom-grid-size-input' );
3915 + inputField.value = false !== inputValueOverride ? inputValueOverride : getSizeOfLayoutClass( getLayoutClassName( $fields.get( index ).classList ) );
3916 + inputRow.appendChild( inputField );
3917 + }
3918 +
3919 + heading = div();
3920 + heading.classList.add( 'frm-builder-popup-heading' );
3921 + heading.textContent = __( 'Enter number of columns for each field', 'formidable' );
3922 +
3923 + label = div();
3924 + label.classList.add( 'frm-builder-popup-subheading' );
3925 + label.textContent = __( 'Layouts are based on a 12-column grid system', 'formidable' );
3926 +
3927 + wrapper.appendChild( heading );
3928 + wrapper.appendChild( label );
3929 +
3930 + wrapper.appendChild( inputRow );
3931 +
3932 + buttonsWrapper = div();
3933 + buttonsWrapper.style.textAlign = 'right';
3934 +
3935 + cancelButton = getSecondaryButton();
3936 + cancelButton.textContent = __( 'Cancel', 'formidable' );
3937 + cancelButton.classList.add( 'frm-cancel-custom-field-group-layout' );
3938 + cancelButton.style.marginRight = '10px';
3939 +
3940 + saveButton = getPrimaryButton();
3941 + saveButton.textContent = __( 'Save', 'formidable' );
3942 + saveButton.classList.add( 'frm-save-custom-field-group-layout' );
3943 +
3944 + buttonsWrapper.appendChild( cancelButton );
3945 + buttonsWrapper.appendChild( saveButton );
3946 +
3947 + wrapper.appendChild( buttonsWrapper );
3948 +
3949 + popup.appendChild( wrapper );
3950 +
3951 + setTimeout(
3952 + function() {
3953 + const firstInput = popup.querySelector( 'input.frm-custom-grid-size-input' ).focus();
3954 + if ( firstInput ) {
3955 + firstInput.focus();
3956 + }
3957 + },
3958 + 0
3959 + );
3960 + }
3961 +
3962 + function customFieldGroupLayoutInsideMergeClick() {
3963 + $fields = jQuery( '.frm-selected-field-group li.form-field' );
3964 + setupCustomLayoutOptions( $fields );
3965 + }
3966 +
3967 + function getPrimaryButton() {
3968 + var button = getButton();
3969 + button.classList.add( 'button-primary', 'frm-button-primary' );
3970 + return button;
3971 + }
3972 +
3973 + function getSecondaryButton() {
3974 + var button = getButton();
3975 + button.classList.add( 'button-secondary', 'frm-button-secondary' );
3976 + return button;
3977 + }
3978 +
3979 + function getButton() {
3980 + var button = document.createElement( 'a' );
3981 + button.setAttribute( 'href', '#' );
3982 + button.classList.add( 'button' );
3983 + button.style.textDecoration = 'none';
3984 + return button;
3985 + }
3986 +
3987 + function getSizeOfLayoutClass( className ) {
3988 + switch ( className ) {
3989 + case 'frm_half':
3990 + return 6;
3991 + case 'frm_third':
3992 + return 4;
3993 + case 'frm_two_thirds':
3994 + return 8;
3995 + case 'frm_fourth':
3996 + return 3;
3997 + case 'frm_three_fourths':
3998 + return 9;
3999 + case 'frm_sixth':
4000 + return 2;
4001 + }
4002 +
4003 + if ( 0 === className.indexOf( 'frm' ) ) {
4004 + return parseInt( className.substr( 3 ) );
4005 + }
4006 +
4007 + // Anything missing a layout class should be a full width row.
4008 + return 12;
4009 + }
4010 +
4011 + function getLayoutClassName( classList ) {
4012 + var classes, index, currentClass;
4013 + classes = getLayoutClasses();
4014 + for ( index = 0; index < classes.length; ++index ) {
4015 + currentClass = classes[ index ];
4016 + if ( classList.contains( currentClass ) ) {
4017 + return currentClass;
4018 + }
4019 + }
4020 + return '';
4021 + }
4022 +
4023 + function getLayoutClassForSize( size ) {
4024 + return 'frm' + size;
4025 + }
4026 +
4027 + function breakFieldGroupClick() {
4028 + var row = document.querySelector( '.frm-field-group-hover-target' );
4029 + breakRow( row );
4030 + destroyFieldGroupPopup();
4031 + }
4032 +
4033 + function breakRow( row ) {
4034 + const $row = jQuery( row );
4035 + getFieldsInRow( $row ).each(
4036 + function( index ) {
4037 + const field = this;
4038 + if ( 0 !== index ) {
4039 + $row.parent().after( wrapFieldLi( field ) );
4040 + }
4041 + stripLayoutFromFields( jQuery( field ) );
4042 + }
4043 + );
4044 + }
4045 +
4046 + function stripLayoutFromFields( field ) {
4047 + syncLayoutClasses( field, 'clear' );
4048 + }
4049 +
4050 + function focusFieldGroupInputOnClick() {
4051 + this.select();
4052 + }
4053 +
4054 + function cancelCustomFieldGroupClick() {
4055 + revertToFieldGroupPopupFirstPage( this );
4056 + }
4057 +
4058 + function revertToFieldGroupPopupFirstPage( triggerElement ) {
4059 + jQuery( document.getElementById( 'frm_field_group_popup' ) ).replaceWith(
4060 + getFieldGroupPopup( getSizeOfFieldGroupFromChildElement( triggerElement ), triggerElement )
4061 + );
4062 + }
4063 +
4064 + function destroyFieldGroupPopup() {
4065 + var popup, wrapper;
4066 + popup = document.getElementById( 'frm_field_group_popup' );
4067 + if ( popup === null ) {
4068 + return;
4069 + }
4070 + wrapper = document.querySelector( '.frm-has-open-field-group-popup' );
4071 + if ( null !== wrapper ) {
4072 + wrapper.classList.remove( 'frm-has-open-field-group-popup' );
4073 + popup.parentNode.remove();
4074 + }
4075 + jQuery( document ).off( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick );
4076 + }
4077 +
4078 + function saveCustomFieldGroupClick() {
4079 + var syncDetails, $controls, $ul;
4080 +
4081 + syncDetails = [];
4082 +
4083 + jQuery( document.getElementById( 'frm_field_group_popup' ).querySelectorAll( '.frm_grid_container input' ) )
4084 + .each(
4085 + function() {
4086 + syncDetails.push( parseInt( this.value ) );
4087 + }
4088 + );
4089 +
4090 + $controls = jQuery( document.getElementById( 'frm_field_group_controls' ) );
4091 +
4092 + if ( $controls.length && 'none' !== $controls.get( 0 ).style.display ) {
4093 + syncLayoutClasses( getFieldsInRow( jQuery( document.querySelector( '.frm-field-group-hover-target' ) ) ).first(), syncDetails );
4094 + } else {
4095 + $ul = mergeSelectedFieldGroups();
4096 + syncLayoutClasses( getFieldsInRow( $ul ).first(), syncDetails );
4097 + unselectFieldGroups();
4098 + }
4099 +
4100 + destroyFieldGroupPopup();
4101 + }
4102 +
4103 + function fieldGroupClick( e ) {
4104 + if ( 'ul' !== e.originalEvent.target.nodeName.toLowerCase() ) {
4105 + // only continue if the group itself was clicked / ignore when a field is clicked.
4106 + return;
4107 + }
4108 +
4109 + const hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
4110 + if ( ! hoverTarget ) {
4111 + return;
4112 + }
4113 +
4114 + const ctrlOrCmdKeyIsDown = e.ctrlKey || e.metaKey;
4115 + const shiftKeyIsDown = e.shiftKey;
4116 + const groupIsActive = hoverTarget.classList.contains( 'frm-selected-field-group' );
4117 + const $selectedFieldGroups = getSelectedFieldGroups();
4118 +
4119 + let numberOfSelectedGroups = $selectedFieldGroups.length;
4120 +
4121 + if ( ctrlOrCmdKeyIsDown || shiftKeyIsDown ) {
4122 + // multi-selecting
4123 +
4124 + const selectedField = getSelectedField();
4125 + if ( null !== selectedField && ! jQuery( selectedField ).siblings( 'li.form-field' ).length ) {
4126 + // count a selected field on its own as a selected field group when multiselecting.
4127 + selectedField.parentNode.classList.add( 'frm-selected-field-group' );
4128 + ++numberOfSelectedGroups;
4129 + }
4130 +
4131 + if ( ctrlOrCmdKeyIsDown ) {
4132 + if ( groupIsActive ) {
4133 + // unselect if holding ctrl or cmd and the group was already active.
4134 + --numberOfSelectedGroups;
4135 + hoverTarget.classList.remove( 'frm-selected-field-group' );
4136 + syncAfterMultiSelect( numberOfSelectedGroups );
4137 + return; // exit early to avoid adding back frm-selected-field-group
4138 + } else {
4139 + ++numberOfSelectedGroups;
4140 + }
4141 + } else if ( shiftKeyIsDown && ! groupIsActive ) {
4142 + ++numberOfSelectedGroups; // include the one we're selecting right now.
4143 + const $firstGroup = $selectedFieldGroups.first();
4144 +
4145 + let $range;
4146 + if ( $firstGroup.parent().index() < jQuery( hoverTarget.parentNode ).index() ) {
4147 + $range = $firstGroup.parent().nextUntil( hoverTarget.parentNode );
4148 + } else {
4149 + $range = $firstGroup.parent().prevUntil( hoverTarget.parentNode );
4150 + }
4151 +
4152 + $range.each(
4153 + function() {
4154 + var $fieldGroup = jQuery( this ).closest( 'li' ).find( 'ul.frm_sorting' );
4155 + if ( ! $fieldGroup.hasClass( 'frm-selected-field-group' ) ) {
4156 + ++numberOfSelectedGroups;
4157 + $fieldGroup.addClass( 'frm-selected-field-group' );
4158 + }
4159 + }
4160 + );
4161 +
4162 + // when holding shift and clicking, text gets selected. unselect it.
4163 + document.getSelection().removeAllRanges();
4164 + }
4165 + } else {
4166 + // not multi-selecting
4167 + unselectFieldGroups();
4168 + numberOfSelectedGroups = 1;
4169 + }
4170 +
4171 + hoverTarget.classList.add( 'frm-selected-field-group' );
4172 + syncAfterMultiSelect( numberOfSelectedGroups );
4173 +
4174 + jQuery( document ).off( 'click', unselectFieldGroups );
4175 + jQuery( document ).on( 'click', unselectFieldGroups );
4176 + }
4177 +
4178 + function getSelectedField() {
4179 + return document.getElementById( 'frm-show-fields' ).querySelector( 'li.form-field.selected' );
4180 + }
4181 +
4182 + function getSelectedFieldGroups() {
4183 + const $fieldGroups = jQuery( '.frm-selected-field-group' );
4184 + if ( $fieldGroups.length ) {
4185 + return $fieldGroups;
4186 + }
4187 +
4188 + const selectedField = getSelectedField();
4189 + if ( selectedField ) {
4190 + // If there is only one field in a group and the field is selected, consider the field's group as selected for multi-select.
4191 + const selectedFieldGroup = selectedField.closest( 'ul' );
4192 + if ( selectedFieldGroup && 1 === getFieldsInRow( jQuery( selectedFieldGroup ) ).length ) {
4193 + selectedFieldGroup.classList.add( 'frm-selected-field-group' );
4194 + return jQuery( selectedFieldGroup );
4195 + }
4196 + }
4197 +
4198 + return jQuery();
4199 + }
4200 +
4201 + function syncAfterMultiSelect( numberOfSelectedGroups ) {
4202 + clearSettingsBox( true ); // unselect any fields if one is selected.
4203 + if ( numberOfSelectedGroups >= 2 || ( 1 === numberOfSelectedGroups && selectedGroupHasMultipleFields() ) ) {
4204 + addFieldMultiselectPopup();
4205 + } else {
4206 + maybeRemoveMultiselectPopup();
4207 + }
4208 + maybeRemoveGroupHoverTarget();
4209 + }
4210 +
4211 + function selectedGroupHasMultipleFields() {
4212 + return getFieldsInRow( jQuery( document.querySelector( '.frm-selected-field-group' ) ) ).length > 1;
4213 + }
4214 +
4215 + function unselectFieldGroups( event ) {
4216 + if ( 'undefined' !== typeof event ) {
4217 + if ( null !== event.originalEvent.target.closest( '#frm-show-fields' ) ) {
4218 + return;
4219 + }
4220 + if ( event.originalEvent.target.classList.contains( 'frm-merge-fields-into-row' ) ) {
4221 + return;
4222 + }
4223 + if ( null !== event.originalEvent.target.closest( '.frm-merge-fields-into-row' ) ) {
4224 + return;
4225 + }
4226 + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) {
4227 + return;
4228 + }
4229 + if ( event.originalEvent.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) {
4230 + return;
4231 + }
4232 + }
4233 + jQuery( '.frm-selected-field-group' ).removeClass( 'frm-selected-field-group' );
4234 + jQuery( document ).off( 'click', unselectFieldGroups );
4235 + maybeRemoveMultiselectPopup();
4236 + }
4237 +
4238 + function maybeRemoveMultiselectPopup() {
4239 + var popup = document.getElementById( 'frm_field_multiselect_popup' );
4240 + if ( null !== popup ) {
4241 + popup.remove();
4242 + }
4243 + }
4244 +
4245 + function addFieldMultiselectPopup() {
4246 + getFieldMultiselectPopup();
4247 + }
4248 +
4249 + function getFieldMultiselectPopup() {
4250 + var popup, mergeOption, caret, verticalSeparator, deleteOption;
4251 +
4252 + popup = document.getElementById( 'frm_field_multiselect_popup' );
4253 +
4254 + if ( null !== popup ) {
4255 + popup.classList.toggle( 'frm-unmergable', ! selectedFieldsAreMergable() );
4256 + return popup;
4257 + }
4258 +
4259 + popup = div();
4260 + popup.id = 'frm_field_multiselect_popup';
4261 + if ( ! selectedFieldsAreMergable() ) {
4262 + popup.classList.add( 'frm-unmergable' );
4263 + }
4264 +
4265 + mergeOption = div();
4266 + mergeOption.classList.add( 'frm-merge-fields-into-row' );
4267 + mergeOption.textContent = __( 'Merge into row', 'formidable' );
4268 +
4269 + caret = document.createElement( 'a' );
4270 + caret.style.marginLeft = '5px';
4271 + caret.classList.add( 'frm_icon_font', 'frm_arrowdown6_icon' );
4272 + caret.setAttribute( 'href', '#' );
4273 + mergeOption.appendChild( caret );
4274 +
4275 + popup.appendChild( mergeOption );
4276 +
4277 + verticalSeparator = div();
4278 + verticalSeparator.classList.add( 'frm-multiselect-popup-separator' );
4279 + popup.appendChild( verticalSeparator );
4280 +
4281 + deleteOption = div();
4282 + deleteOption.classList.add( 'frm-delete-field-groups' );
4283 + deleteOption.appendChild( getIconClone( 'frm_trash_svg' ) );
4284 + popup.appendChild( deleteOption );
4285 +
4286 + document.getElementById( 'post-body-content' ).appendChild( popup );
4287 +
4288 + jQuery( popup ).hide().fadeIn();
4289 +
4290 + return popup;
4291 + }
4292 +
4293 + function selectedFieldsAreMergable() {
4294 + var selectedFieldGroups, totalFieldCount, length, index, fieldGroup;
4295 + selectedFieldGroups = document.querySelectorAll( '.frm-selected-field-group' );
4296 + length = selectedFieldGroups.length;
4297 + if ( 1 === length ) {
4298 + return false;
4299 + }
4300 + totalFieldCount = 0;
4301 + for ( index = 0; index < length; ++index ) {
4302 + fieldGroup = selectedFieldGroups[ index ];
4303 + if ( null !== fieldGroup.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ) ) {
4304 + return false;
4305 + }
4306 + totalFieldCount += getFieldsInRow( jQuery( fieldGroup ) ).length;
4307 + if ( totalFieldCount > 6 ) {
4308 + return false;
4309 + }
4310 + }
4311 + return true;
4312 + }
4313 +
4314 + function mergeFieldsIntoRowClick( event ) {
4315 + var size, popup;
4316 +
4317 + if ( null !== event.originalEvent.target.closest( '#frm_field_group_popup' ) ) {
4318 + // prevent clicks within the popup from triggering the button again.
4319 + return;
4320 + }
4321 +
4322 + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) {
4323 + // avoid switching back to the first page when clicking the custom option nested inside of the merge option.
4324 + return;
4325 + }
4326 +
4327 + size = getSelectedFieldCount();
4328 + popup = getFieldGroupPopup( size, document.querySelector( '.frm-selected-field-group' ).firstChild );
4329 + this.appendChild( popup );
4330 + }
4331 +
4332 + function getSelectedFieldCount() {
4333 + var count = 0;
4334 + jQuery( document.querySelectorAll( '.frm-selected-field-group' ) ).each(
4335 + function() {
4336 + count += getFieldsInRow( jQuery( this ) ).length;
4337 + }
4338 + );
4339 + return count;
4340 + }
4341 +
4342 + function deleteFieldGroupsClick() {
4343 + var fieldIdsToDelete, deleteOnConfirm, multiselectPopup;
4344 +
4345 + fieldIdsToDelete = getSelectedFieldIds();
4346 + deleteOnConfirm = getDeleteSelectedFieldGroupsOnConfirmFunction( fieldIdsToDelete );
4347 +
4348 + multiselectPopup = document.getElementById( 'frm_field_multiselect_popup' );
4349 + if ( null !== multiselectPopup ) {
4350 + multiselectPopup.remove();
4351 + }
4352 +
4353 + this.setAttribute( 'data-frmcaution', __( 'Heads up', 'formidable' ) );
4354 + /* translators: %1$s: Number of fields that are selected to be deleted. */
4355 + this.setAttribute( 'data-frmverify', __( 'Are you sure you want to delete these %1$s selected fields?', 'formidable' ).replace( '%1$s', fieldIdsToDelete.length ) );
4356 + confirmLinkClick( this );
4357 +
4358 + jQuery( '#frm-confirmed-click' ).on( 'click', deleteOnConfirm );
4359 + jQuery( '#frm_confirm_modal' ).one( 'dialogclose', function() {
4360 + jQuery( '#frm-confirmed-click' ).off( 'click', deleteOnConfirm );
4361 + });
4362 + }
4363 +
4364 + function getSelectedFieldIds() {
4365 + var deleteFieldIds = [];
4366 + jQuery( '.frm-selected-field-group > li.form-field' )
4367 + .each(
4368 + function() {
4369 + deleteFieldIds.push( this.dataset.fid );
4370 + }
4371 + );
4372 + return deleteFieldIds;
4373 + }
4374 +
4375 + function getDeleteSelectedFieldGroupsOnConfirmFunction( deleteFieldIds ) {
4376 + return function( event ) {
4377 + event.preventDefault();
4378 + deleteAllSelectedFieldGroups( deleteFieldIds );
4379 + };
4380 + }
4381 +
4382 + function deleteAllSelectedFieldGroups( deleteFieldIds ) {
4383 + deleteFieldIds.forEach(
4384 + function( fieldId ) {
4385 + deleteFields( fieldId );
4386 + }
4387 + );
4388 + }
4389 +
4390 + function deleteFieldConfirmed() {
4391 + /*jshint validthis:true */
4392 + deleteFields( this.getAttribute( 'data-deletefield' ) );
4393 + }
4394 +
4395 + function deleteFields( fieldId ) {
4396 + var field = jQuery( '#frm_field_id_' + fieldId );
4397 +
4398 + deleteField( fieldId );
4399 +
4400 + if ( field.hasClass( 'edit_field_type_divider' ) ) {
4401 + field.find( 'li.frm_field_box' ).each( function() {
4402 + //TODO: maybe delete only end section
4403 + //if(n.hasClass('edit_field_type_end_divider')){
4404 + deleteField( this.getAttribute( 'data-fid' ) );
4405 + //}
4406 + });
4407 + }
4408 + toggleSectionHolder();
4409 + }
4410 +
4411 + function deleteField( fieldId ) {
4412 + jQuery.ajax({
4413 + type: 'POST',
4414 + url: ajaxurl,
4415 + data: {
4416 + action: 'frm_delete_field',
4417 + field_id: fieldId,
4418 + nonce: frmGlobal.nonce
4419 + },
4420 + success: function() {
4421 + var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ),
4422 + settings = jQuery( '#frm-single-settings-' + fieldId );
4423 +
4424 + // Remove settings from sidebar.
4425 + if ( settings.is( ':visible' ) ) {
4426 + document.getElementById( 'frm_insert_fields_tab' ).click();
4427 + }
4428 + settings.remove();
4429 +
4430 + $thisField.fadeOut( 'slow', function() {
4431 + var $section = $thisField.closest( '.start_divider' ),
4432 + type = $thisField.data( 'type' ),
4433 + $adjacentFields = $thisField.siblings( 'li.form-field' ),
4434 + $liWrapper;
4435 +
4436 + if ( ! $adjacentFields.length ) {
4437 + if ( $thisField.is( '.edit_field_type_end_divider' ) ) {
4438 + $adjacentFields.length = $thisField.closest( 'li.form-field' ).siblings();
4439 + } else {
4440 + $liWrapper = $thisField.closest( 'ul.frm_sorting' ).parent();
4441 + }
4442 + }
4443 +
4444 + $thisField.remove();
4445 + if ( type === 'break' ) {
4446 + renumberPageBreaks();
4447 + }
4448 + if ( type === 'product' ) {
4449 + maybeHideQuantityProductFieldOption();
4450 + // a product field attached to a quantity field earlier might be the one deleted, so re-populate
4451 + popAllProductFields();
4452 + }
4453 + if ( jQuery( '#frm-show-fields li' ).length === 0 ) {
4454 + document.getElementById( 'frm_form_editor_container' ).classList.remove( 'frm-has-fields' );
4455 + } else if ( $section.length ) {
4456 + toggleOneSectionHolder( $section );
4457 + }
4458 + if ( $adjacentFields.length ) {
4459 + syncLayoutClasses( $adjacentFields.first() );
4460 + } else {
4461 + $liWrapper.remove();
4462 + }
4463 +
4464 + // prevent "More Options" tooltips from staying around after their target field is deleted.
4465 + deleteTooltips();
4466 + });
4467 + }
4468 + });
4469 + }
4470 +
4471 + function addFieldLogicRow() {
4472 + /*jshint validthis:true */
4473 + var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
4474 + formId = thisFormId,
4475 + logicRows = document.getElementById( 'frm_logic_row_' + id ).querySelectorAll( '.frm_logic_row' );
4476 + jQuery.ajax({
4477 + type: 'POST',
4478 + url: ajaxurl,
4479 + data: {
4480 + action: 'frm_add_logic_row',
4481 + form_id: formId,
4482 + field_id: id,
4483 + nonce: frmGlobal.nonce,
4484 + meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ),
4485 + fields: getFieldList()
4486 + },
4487 + success: function( html ) {
4488 + jQuery( document.getElementById( 'logic_' + id ) ).fadeOut( 'slow', function() {
4489 + var logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) );
4490 + logicRow.append( html );
4491 + logicRow.closest( '.frm_logic_rows' ).fadeIn( 'slow' );
4492 + });
4493 + }
4494 + });
4495 + return false;
4496 + }
4497 +
4498 + function getNewRowId( rows, replace, defaultValue ) {
4499 + if ( ! rows.length ) {
4500 + return 'undefined' !== typeof defaultValue ? defaultValue : 0;
4501 + }
4502 + return parseInt( rows[ rows.length - 1 ].id.replace( replace, '' ), 10 ) + 1;
4503 + }
4504 +
4505 + function addWatchLookupRow() {
4506 + /*jshint validthis:true */
4507 + var lastRowId,
4508 + id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
4509 + formId = thisFormId,
4510 + lookupBlockRows = document.getElementById( 'frm_watch_lookup_block_' + id ).children;
4511 + jQuery.ajax({
4512 + type: 'POST',
4513 + url: ajaxurl,
4514 + data: {
4515 + action: 'frm_add_watch_lookup_row',
4516 + form_id: formId,
4517 + field_id: id,
4518 + row_key: getNewRowId( lookupBlockRows, 'frm_watch_lookup_' + id + '_' ),
4519 + nonce: frmGlobal.nonce
4520 + },
4521 + success: function( newRow ) {
4522 + var watchRowBlock = jQuery( document.getElementById( 'frm_watch_lookup_block_' + id ) );
4523 + watchRowBlock.append( newRow );
4524 + watchRowBlock.fadeIn( 'slow' );
4525 + }
4526 + });
4527 + return false;
4528 + }
4529 +
4530 + function resetOptionTextDetails() {
4531 + jQuery( '.frm-single-settings ul input[type="text"][name^="field_options[options_"]' ).filter( '[data-value-on-load]' ).removeAttr( 'data-value-on-load' );
4532 + jQuery( 'input[type="hidden"][name^=optionmap]' ).remove();
4533 + }
4534 +
4535 + function optionTextAlreadyExists( input ) {
4536 + var fieldId = jQuery( input ).closest( '.frm-single-settings' ).attr( 'data-fid' ),
4537 + optionInputs = jQuery( input ).closest( 'ul' ).get( 0 ).querySelectorAll( '.field_' + fieldId + '_option' ),
4538 + index,
4539 + optionInput;
4540 +
4541 + for ( index in optionInputs ) {
4542 + optionInput = optionInputs[ index ];
4543 + if ( optionInput.id !== input.id && optionInput.value === input.value && optionInput.getAttribute( 'data-duplicate' ) !== 'true' ) {
4544 + return true;
4545 + }
4546 + }
4547 +
4548 + return false;
4549 + }
4550 +
4551 + function onOptionTextFocus() {
4552 + var input,
4553 + fieldId;
4554 +
4555 + if ( this.getAttribute( 'data-value-on-load' ) === null ) {
4556 + this.setAttribute( 'data-value-on-load', this.value );
4557 +
4558 + fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' );
4559 + input = document.createElement( 'input' );
4560 + input.value = this.value;
4561 + input.setAttribute( 'type', 'hidden' );
4562 + input.setAttribute( 'name', 'optionmap[' + fieldId + '][' + this.value + ']' );
4563 + this.parentNode.appendChild( input );
4564 +
4565 + if ( typeof optionMap[ fieldId ] === 'undefined' ) {
4566 + optionMap[ fieldId ] = {};
4567 + }
4568 +
4569 + optionMap[ fieldId ][ this.value ] = input;
4570 + }
4571 +
4572 + if ( this.getAttribute( 'data-duplicate' ) === 'true' ) {
4573 + this.removeAttribute( 'data-duplicate' );
4574 +
4575 + // we want to use original value if actually still a duplicate
4576 + if ( optionTextAlreadyExists( this ) ) {
4577 + this.setAttribute( 'data-value-on-focus', this.getAttribute( 'data-value-on-load' ) );
4578 + return;
4579 + }
4580 + }
4581 +
4582 + if ( '' !== this.value || frm_admin_js.new_option !== this.getAttribute( 'data-value-on-focus' ) ) {
4583 + this.setAttribute( 'data-value-on-focus', this.value );
4584 + }
4585 + }
4586 +
4587 + function onOptionTextBlur() {
4588 + var originalValue,
4589 + oldValue = this.getAttribute( 'data-value-on-focus' ),
4590 + newValue = this.value,
4591 + fieldId,
4592 + fieldIndex,
4593 + logicId,
4594 + row,
4595 + rowLength,
4596 + rowIndex,
4597 + valueSelect,
4598 + opts,
4599 + fieldIds,
4600 + settingId,
4601 + setting,
4602 + optionMatches,
4603 + option;
4604 +
4605 + if ( oldValue === newValue ) {
4606 + return;
4607 + }
4608 +
4609 + fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' );
4610 + originalValue = this.getAttribute( 'data-value-on-load' );
4611 +
4612 + // check if the newValue is already mapped to another option
4613 + // if it is, mark as duplicate and return
4614 + if ( optionTextAlreadyExists( this ) ) {
4615 + this.setAttribute( 'data-duplicate', 'true' );
4616 +
4617 + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) {
4618 + // unmap any other change that may have happened before instead of changing it to something unused
4619 + optionMap[ fieldId ][ originalValue ].value = originalValue;
4620 + }
4621 +
4622 + return;
4623 + }
4624 +
4625 + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) {
4626 + optionMap[ fieldId ][ originalValue ].value = newValue;
4627 + }
4628 +
4629 + fieldIds = [];
4630 + rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' );
4631 + rowLength = rows.length;
4632 + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) {
4633 + row = rows[ rowIndex ];
4634 + opts = row.querySelector( '.frm_logic_field_opts' );
4635 +
4636 + if ( opts.value !== fieldId ) {
4637 + continue;
4638 + }
4639 +
4640 + logicId = row.id.split( '_' )[ 2 ];
4641 + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' );
4642 +
4643 + if ( '' === oldValue ) {
4644 + optionMatches = [];
4645 + } else {
4646 + optionMatches = valueSelect.querySelectorAll( 'option[value="' + oldValue + '"]' );
4647 + }
4648 +
4649 + if ( ! optionMatches.length ) {
4650 + optionMatches = valueSelect.querySelectorAll( 'option[value="' + newValue + '"]' );
4651 +
4652 + if ( ! optionMatches.length ) {
4653 + option = document.createElement( 'option' );
4654 + valueSelect.appendChild( option );
4655 + }
4656 + }
4657 +
4658 + if ( optionMatches.length ) {
4659 + option = optionMatches[ optionMatches.length - 1 ];
4660 + }
4661 +
4662 + option.setAttribute( 'value', newValue );
4663 + option.textContent = newValue;
4664 +
4665 + if ( fieldIds.indexOf( logicId ) === -1 ) {
4666 + fieldIds.push( logicId );
4667 + }
4668 + }
4669 +
4670 + for ( fieldIndex in fieldIds ) {
4671 + settingId = fieldIds[ fieldIndex ];
4672 + setting = document.getElementById( 'frm-single-settings-' + settingId );
4673 + moveFieldSettings( setting );
4674 + }
4675 + }
4676 +
4677 + function updateGetValueFieldSelection() {
4678 + /*jshint validthis:true */
4679 + var fieldID = this.id.replace( 'get_values_form_', '' );
4680 + var fieldSelect = document.getElementById( 'get_values_field_' + fieldID );
4681 + var fieldType = this.getAttribute( 'data-fieldtype' );
4682 +
4683 + if ( this.value === '' ) {
4684 + fieldSelect.options.length = 1;
4685 + } else {
4686 + var formID = this.value;
4687 + jQuery.ajax({
4688 + type: 'POST', url: ajaxurl,
4689 + data: {
4690 + action: 'frm_get_options_for_get_values_field',
4691 + form_id: formID,
4692 + field_type: fieldType,
4693 + nonce: frmGlobal.nonce
4694 + },
4695 + success: function( fields ) {
4696 + fieldSelect.innerHTML = fields;
4697 + }
4698 + });
4699 + }
4700 + }
4701 +
4702 + // Clear the Watch Fields option when Lookup field switches to "Text" option
4703 + function maybeClearWatchFields() {
4704 + /*jshint validthis:true */
4705 + var link, lookupBlock,
4706 + fieldID = this.name.replace( 'field_options[data_type_', '' ).replace( ']', '' );
4707 +
4708 + link = document.getElementById( 'frm_add_watch_lookup_link_' + fieldID ).parentNode;
4709 +
4710 + if ( this.value === 'text' ) {
4711 + lookupBlock = document.getElementById( 'frm_watch_lookup_block_' + fieldID );
4712 + if ( lookupBlock !== null ) {
4713 + // Clear and hide the Watch Fields option
4714 + lookupBlock.innerHTML = '';
4715 + link.classList.add( 'frm_hidden' );
4716 +
4717 + // Hide the Watch Fields row
4718 + link.previousElementSibling.style.display = 'none';
4719 + link.previousElementSibling.previousElementSibling.style.display = 'none';
4720 + link.previousElementSibling.previousElementSibling.previousElementSibling.style.display = 'none';
4721 + }
4722 + } else {
4723 + // Show the Watch Fields option
4724 + link.classList.remove( 'frm_hidden' );
4725 + }
4726 +
4727 + toggleMultiSelect( fieldID, this.value );
4728 + }
4729 +
4730 + // Number the pages and hide/show the first page as needed.
4731 + function renumberPageBreaks() {
4732 + var i, containerClass,
4733 + pages = document.getElementsByClassName( 'frm-page-num' );
4734 +
4735 + if ( pages.length > 1 ) {
4736 + document.getElementById( 'frm-fake-page' ).style.display = 'block';
4737 + for ( i = 0; i < pages.length; i++ ) {
4738 + containerClass = pages[i].parentNode.parentNode.parentNode.classList;
4739 + if ( i === 1 ) {
4740 + // Hide previous button on page 1
4741 + containerClass.add( 'frm-first-page' );
4742 + } else {
4743 + containerClass.remove( 'frm-first-page' );
4744 + }
4745 + pages[i].innerHTML = ( i + 1 );
4746 + }
4747 + } else {
4748 + document.getElementById( 'frm-fake-page' ).style.display = 'none';
4749 + }
4750 + }
4751 +
4752 + // The fake field works differently than real fields.
4753 + function maybeCollapsePage() {
4754 + /*jshint validthis:true */
4755 + var field = jQuery( this ).closest( '.frm_field_box[data-ftype=break]' );
4756 + if ( field.length ) {
4757 + toggleCollapsePage( field );
4758 + } else {
4759 + toggleCollapseFakePage();
4760 + }
4761 + }
4762 +
4763 + // Find all fields in a page and hide/show them
4764 + function toggleCollapsePage( field ) {
4765 + var toCollapse = getAllFieldsForPage( field.get( 0 ).parentNode.closest( 'li.frm_field_box' ).nextElementSibling );
4766 + togglePage( field, toCollapse );
4767 + }
4768 +
4769 + function toggleCollapseFakePage() {
4770 + var topLevel = document.getElementById( 'frm-fake-page' ),
4771 + firstField = document.getElementById( 'frm-show-fields' ).firstElementChild,
4772 + toCollapse = getAllFieldsForPage( firstField );
4773 +
4774 + if ( firstField.getAttribute( 'data-ftype' ) === 'break' ) {
4775 + // Don't collapse if the first field is a page break.
4776 + return;
4777 + }
4778 +
4779 + togglePage( jQuery( topLevel ), toCollapse );
4780 + }
4781 +
4782 + function getAllFieldsForPage( firstWrapper ) {
4783 + var $fieldsForPage, currentWrapper;
4784 +
4785 + $fieldsForPage = jQuery();
4786 +
4787 + if ( null === firstWrapper ) {
4788 + return $fieldsForPage;
4789 + }
4790 +
4791 + currentWrapper = firstWrapper;
4792 +
4793 + do {
4794 + if ( null !== currentWrapper.querySelector( '.edit_field_type_break' ) ) {
4795 + break;
4796 + }
4797 + $fieldsForPage = $fieldsForPage.add( jQuery( currentWrapper ) );
4798 + currentWrapper = currentWrapper.nextElementSibling;
4799 + } while ( null !== currentWrapper );
4800 +
4801 + return $fieldsForPage;
4802 + }
4803 +
4804 + function togglePage( field, toCollapse ) {
4805 + var i,
4806 + fieldCount = toCollapse.length,
4807 + slide = Math.min( fieldCount, 3 );
4808 +
4809 + if ( field.hasClass( 'frm-page-collapsed' ) ) {
4810 + field.removeClass( 'frm-page-collapsed' );
4811 + toCollapse.removeClass( 'frm-is-collapsed' );
4812 + for ( i = 0; i < slide; i++ ) {
4813 + if ( i === slide - 1 ) {
4814 + jQuery( toCollapse[ i ]).slideDown( 150, function() {
4815 + toCollapse.show();
4816 + });
4817 + } else {
4818 + jQuery( toCollapse[ i ]).slideDown( 150 );
4819 + }
4820 + }
4821 + } else {
4822 + field.addClass( 'frm-page-collapsed' );
4823 + toCollapse.addClass( 'frm-is-collapsed' );
4824 + for ( i = 0; i < slide; i++ ) {
4825 + if ( i === slide - 1 ) {
4826 + jQuery( toCollapse[ i ]).slideUp( 150, function() {
4827 + toCollapse.css( 'cssText', 'display:none !important;' );
4828 + });
4829 + } else {
4830 + jQuery( toCollapse[ i ]).slideUp( 150 );
4831 + }
4832 + }
4833 + }
4834 + }
4835 +
4836 + function maybeCollapseSection() {
4837 + /*jshint validthis:true */
4838 + var parentCont = this.parentNode.parentNode.parentNode.parentNode;
4839 +
4840 + parentCont.classList.toggle( 'frm-section-collapsed' );
4841 + }
4842 +
4843 + function maybeCollapseSettings() {
4844 + /*jshint validthis:true */
4845 + this.classList.toggle( 'frm-collapsed' );
4846 + }
4847 +
4848 + function clickLabel() {
4849 + if ( ! this.id ) {
4850 + return;
4851 + }
4852 +
4853 + /*jshint validthis:true */
4854 + var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0],
4855 + fieldId = this.id.replace( 'field_label_', '' ),
4856 + fieldType = document.getElementById( 'field_options_type_' + fieldId ),
4857 + fieldTypeName = fieldType.value;
4858 +
4859 + if ( typeof setting !== 'undefined' ) {
4860 + if ( fieldType.tagName === 'SELECT' ) {
4861 + fieldTypeName = fieldType.options[ fieldType.selectedIndex ].text.toLowerCase();
4862 + } else {
4863 + fieldTypeName = fieldTypeName.replace( '_', ' ' );
4864 + }
4865 +
4866 + fieldTypeName = normalizeFieldName( fieldTypeName );
4867 +
4868 + setTimeout( function() {
4869 + if ( setting.value.toLowerCase() === fieldTypeName ) {
4870 + setting.select();
4871 + } else {
4872 + setting.focus();
4873 + }
4874 + }, 50 );
4875 + }
4876 + }
4877 +
4878 + function clickDescription() {
4879 + /*jshint validthis:true */
4880 + var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0];
4881 + if ( typeof setting !== 'undefined' ) {
4882 + setTimeout( function() {
4883 + setting.focus();
4884 + autoExpandSettings( setting );
4885 + }, 50 );
4886 + }
4887 + }
4888 +
4889 + function autoExpandSettings( setting ) {
4890 + var inSection = setting.closest( '.frm-collapse-me' );
4891 + if ( inSection !== null ) {
4892 + inSection.previousElementSibling.classList.remove( 'frm-collapsed' );
4893 + }
4894 + }
4895 +
4896 + function normalizeFieldName( fieldTypeName ) {
4897 + if ( fieldTypeName === 'divider' ) {
4898 + fieldTypeName = 'section';
4899 + } else if ( fieldTypeName === 'range' ) {
4900 + fieldTypeName = 'slider';
4901 + } else if ( fieldTypeName === 'data' ) {
4902 + fieldTypeName = 'dynamic';
4903 + } else if ( fieldTypeName === 'form' ) {
4904 + fieldTypeName = 'embed form';
4905 + }
4906 + return fieldTypeName;
4907 + }
4908 +
4909 + function clickVis( e ) {
4910 + /*jshint validthis:true */
4911 + var currentClass, originalList;
4912 +
4913 + currentClass = e.target.classList;
4914 +
4915 + if ( currentClass.contains( 'frm-collapse-page' ) || currentClass.contains( 'frm-sub-label' ) || e.target.closest( '.dropdown' ) !== null ) {
4916 + return;
4917 + }
4918 +
4919 + if ( this.closest( '.start_divider' ) !== null ) {
4920 + e.stopPropagation();
4921 + }
4922 +
4923 + if ( this.classList.contains( 'edit_field_type_divider' ) ) {
4924 + originalList = e.originalEvent.target.closest( 'ul.frm_sorting' );
4925 + if ( null !== originalList ) {
4926 + // prevent section click if clicking a field group within a section.
4927 + if ( originalList.classList.contains( 'edit_field_type_divider' ) || originalList.parentNode.parentNode.classList.contains( 'start_divider' ) ) {
4928 + return;
4929 + }
4930 + }
4931 + }
4932 +
4933 + clickAction( this );
4934 + }
4935 +
4936 + /**
4937 + * Open Advanced settings on double click.
4938 + */
4939 + function openAdvanced() {
4940 + var fieldId = this.getAttribute( 'data-fid' );
4941 + autoExpandSettings( document.getElementById( 'field_options_field_key_' + fieldId ) );
4942 + }
4943 +
4944 + function toggleRepeatButtons() {
4945 + /*jshint validthis:true */
4946 + var $thisField = jQuery( this ).closest( '.frm_field_box' );
4947 + $thisField.find( '.repeat_icon_links' ).removeClass( 'repeat_format repeat_formatboth repeat_formattext' ).addClass( 'repeat_format' + this.value );
4948 + if ( this.value === 'text' || this.value === 'both' ) {
4949 + $thisField.find( '.frm_repeat_text' ).show();
4950 + $thisField.find( '.repeat_icon_links a' ).addClass( 'frm_button' );
4951 + } else {
4952 + $thisField.find( '.frm_repeat_text' ).hide();
4953 + $thisField.find( '.repeat_icon_links a' ).removeClass( 'frm_button' );
4954 + }
4955 + }
4956 +
4957 + function checkRepeatLimit() {
4958 + /*jshint validthis:true */
4959 + var val = this.value;
4960 + if ( val !== '' && ( val < 2 || val > 200 ) ) {
4961 + infoModal( frm_admin_js.repeat_limit_min );
4962 + this.value = '';
4963 + }
4964 + }
4965 +
4966 + function checkCheckboxSelectionsLimit() {
4967 + /*jshint validthis:true */
4968 + var val = this.value;
4969 + if ( val !== '' && ( val < 1 || val > 200 ) ) {
4970 + infoModal( frm_admin_js.checkbox_limit );
4971 + this.value = '';
4972 + }
4973 + }
4974 +
4975 + function updateRepeatText( obj, addRemove ) {
4976 + var $thisField = jQuery( obj ).closest( '.frm_field_box' );
4977 + $thisField.find( '.frm_' + addRemove + '_form_row .frm_repeat_label' ).text( obj.value );
4978 + }
4979 +
4980 + function fieldsInSection( id ) {
4981 + var children = [];
4982 + jQuery( document.getElementById( 'frm_field_id_' + id ) ).find( 'li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)' ).each( function() {
4983 + children.push( jQuery( this ).data( 'fid' ) );
4984 + });
4985 + return children;
4986 + }
4987 +
4988 + function toggleFormTax() {
4989 + /*jshint validthis:true */
4990 + var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
4991 + var val = this.value;
4992 + var $showFields = document.getElementById( 'frm_show_selected_fields_' + id );
4993 + var $showForms = document.getElementById( 'frm_show_selected_forms_' + id );
4994 +
4995 + jQuery( $showForms ).find( 'select' ).val( '' );
4996 + if ( val === 'form' ) {
4997 + $showForms.style.display = 'inline';
4998 + empty( $showFields );
4999 + } else {
5000 + $showFields.style.display = 'none';
5001 + $showForms.style.display = 'none';
5002 + getTaxOrFieldSelection( val, id );
5003 + }
5004 +
5005 + }
5006 +
5007 + function resetOptOnChange() {
5008 + /*jshint validthis:true */
5009 + var field, thisOpt;
5010 +
5011 + field = getFieldKeyFromOpt( this );
5012 + if ( ! field ) {
5013 + return;
5014 + }
5015 +
5016 + thisOpt = jQuery( this ).closest( '.frm_single_option' );
5017 +
5018 + resetSingleOpt( field.fieldId, field.fieldKey, thisOpt );
5019 + }
5020 +
5021 + function getFieldKeyFromOpt( object ) {
5022 + var allOpts, fieldId, fieldKey;
5023 +
5024 + allOpts = jQuery( object ).closest( '.frm_sortable_field_opts' );
5025 + if ( ! allOpts.length ) {
5026 + return false;
5027 + }
5028 +
5029 + fieldId = allOpts.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_opts', '' );
5030 + fieldKey = allOpts.data( 'key' );
5031 +
5032 + return {
5033 + fieldId: fieldId,
5034 + fieldKey: fieldKey
5035 + };
5036 + }
5037 +
5038 + function resetSingleOpt( fieldId, fieldKey, thisOpt ) {
5039 + var saved, text, defaultVal, previewInput, labelForDisplay, optContainer,
5040 + optKey = thisOpt.data( 'optkey' ),
5041 + separateValues = usingSeparateValues( fieldId ),
5042 + single = jQuery( 'label[for="field_' + fieldKey + '-' + optKey + '"]' ),
5043 + baseName = 'field_options[options_' + fieldId + '][' + optKey + ']',
5044 + label = jQuery( 'input[name="' + baseName + '[label]"]' );
5045 +
5046 + if ( single.length < 1 ) {
5047 + resetDisplayedOpts( fieldId );
5048 +
5049 + // Set the default value.
5050 + defaultVal = thisOpt.find( 'input[name^="default_value_"]' );
5051 + if ( defaultVal.is( ':checked' ) && label.length > 0 ) {
5052 + jQuery( 'select[name^="item_meta[' + fieldId + ']"]' ).val( label.val() );
5053 + }
5054 + return;
5055 + }
5056 +
5057 + previewInput = single.children( 'input' );
5058 +
5059 + if ( label.length < 1 ) {
5060 + // Check for other label.
5061 + label = jQuery( 'input[name="' + baseName + '"]' );
5062 + saved = label.val();
5063 + } else if ( separateValues ) {
5064 + saved = jQuery( 'input[name="' + baseName + '[value]"]' ).val();
5065 + } else {
5066 + saved = label.val();
5067 + }
5068 +
5069 + if ( label.length < 1 ) {
5070 + return;
5071 + }
5072 +
5073 + // Set the displayed value.
5074 + text = single[0].childNodes;
5075 +
5076 + if ( imagesAsOptions( fieldId ) ) {
5077 + labelForDisplay = getImageDisplayValue( thisOpt, fieldId, label );
5078 + optContainer = single.find( '.frm_image_option_container' );
5079 +
5080 + if ( optContainer.length > 0 ) {
5081 + optContainer.replaceWith( labelForDisplay );
5082 + } else {
5083 + text[ text.length - 1 ].nodeValue = '';
5084 + single.append( labelForDisplay );
5085 + }
5086 + } else {
5087 + text[ text.length - 1 ].nodeValue = ' ' + label.val();
5088 + }
5089 +
5090 + // Set saved value.
5091 + previewInput.val( saved );
5092 +
5093 + // Set the default value.
5094 + defaultVal = thisOpt.find( 'input[name^="default_value_"]' );
5095 + previewInput.prop( 'checked', defaultVal.is( ':checked' ) ? true : false );
5096 + }
5097 +
5098 + /**
5099 + * Set the displayed value for an image option.
5100 + */
5101 + function getImageDisplayValue( thisOpt, fieldId, label ) {
5102 + var image, imageUrl, showLabelWithImage, fieldType;
5103 +
5104 + image = thisOpt.find( 'img' );
5105 + if ( image ) {
5106 + imageUrl = image.attr( 'src' );
5107 + }
5108 +
5109 + showLabelWithImage = showingLabelWithImage( fieldId );
5110 + fieldType = radioOrCheckbox( fieldId );
5111 + return getImageLabel( label.val(), showLabelWithImage, imageUrl, fieldType );
5112 + }
5113 +
5114 + function getImageOptionSize( fieldId ) {
5115 + var val,
5116 + field = document.getElementById( 'field_options_image_size_' + fieldId ),
5117 + size = '';
5118 +
5119 + if ( field !== null ) {
5120 + val = field.value;
5121 + if ( val !== '' ) {
5122 + size = val;
5123 + }
5124 + }
5125 +
5126 + return size;
5127 + }
5128 +
5129 + function resetDisplayedOpts( fieldId ) {
5130 + var i, opts, type, placeholder, fieldInfo,
5131 + input = jQuery( '[name^="item_meta[' + fieldId + ']"]' );
5132 +
5133 + if ( input.length < 1 ) {
5134 + return;
5135 + }
5136 +
5137 + if ( input.is( 'select' ) ) {
5138 + placeholder = document.getElementById( 'frm_placeholder_' + fieldId );
5139 + if ( placeholder !== null && placeholder.value === '' ) {
5140 + fillDropdownOpts( input[0], { sourceID: fieldId });
5141 + } else {
5142 + fillDropdownOpts( input[0], {
5143 + sourceID: fieldId,
5144 + placeholder: placeholder.value
5145 + });
5146 + }
5147 + } else {
5148 + opts = getMultipleOpts( fieldId );
5149 + type = input.attr( 'type' );
5150 + jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ).html( '' );
5151 + fieldInfo = getFieldKeyFromOpt( jQuery( '#frm_delete_field_' + fieldId + '-000_container' ) );
5152 +
5153 + var container = jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ),
5154 + hasImageOptions = imagesAsOptions( fieldId ),
5155 + imageSize = hasImageOptions ? getImageOptionSize( fieldId ) : '',
5156 + imageOptionClass = hasImageOptions ? ( 'frm_image_option frm_image_' + imageSize + ' ' ) : '',
5157 + isProduct = isProductField( fieldId );
5158 +
5159 + for ( i = 0; i < opts.length; i++ ) {
5160 + container.append( addRadioCheckboxOpt( type, opts[ i ], fieldId, fieldInfo.fieldKey, isProduct, imageOptionClass ) );
5161 + }
5162 + }
5163 +
5164 + adjustConditionalLogicOptionOrders( fieldId );
5165 + }
5166 +
5167 + function adjustConditionalLogicOptionOrders( fieldId ) {
5168 + var row, opts, logicId, valueSelect, rowOptions, expectedOrder, optionLength, optionIndex, expectedOption, optionMatch,
5169 + rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ),
5170 + rowLength = rows.length,
5171 + fieldOptions = getFieldOptions( fieldId ),
5172 + optionLength = fieldOptions.length;
5173 +
5174 + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) {
5175 + row = rows[ rowIndex ];
5176 + opts = row.querySelector( '.frm_logic_field_opts' );
5177 +
5178 + if ( opts.value != fieldId ) {
5179 + continue;
5180 + }
5181 +
5182 + logicId = row.id.split( '_' )[ 2 ];
5183 + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' );
5184 +
5185 + for ( optionIndex = optionLength - 1; optionIndex >= 0; optionIndex-- ) {
5186 + expectedOption = fieldOptions[ optionIndex ];
5187 + optionMatch = valueSelect.querySelector( 'option[value="' + expectedOption + '"]' );
5188 +
5189 + if ( optionMatch === null ) {
5190 + optionMatch = document.createElement( 'option' );
5191 + optionMatch.setAttribute( 'value', expectedOption );
5192 + optionMatch.textContent = expectedOption;
5193 + }
5194 +
5195 + valueSelect.prepend( optionMatch );
5196 + }
5197 +
5198 + optionMatch = valueSelect.querySelector( 'option[value=""]' );
5199 + if ( optionMatch !== null ) {
5200 + valueSelect.prepend( optionMatch );
5201 + }
5202 + }
5203 + }
5204 +
5205 + function getFieldOptions( fieldId ) {
5206 + var index, input, li,
5207 + listItems = document.getElementById( 'frm_field_' + fieldId + '_opts' ).querySelectorAll( '.frm_single_option' ),
5208 + options = [],
5209 + length = listItems.length;
5210 + for ( index = 0; index < length; index++ ) {
5211 + li = listItems[ index ];
5212 +
5213 + if ( li.classList.contains( 'frm_hidden' ) ) {
5214 + continue;
5215 + }
5216 +
5217 + input = li.querySelector( '.field_' + fieldId + '_option' );
5218 + options.push( input.value );
5219 + }
5220 + return options;
5221 + }
5222 +
5223 + function addRadioCheckboxOpt( type, opt, fieldId, fieldKey, isProduct, classes ) {
5224 + var other, single,
5225 + isOther = opt.key.indexOf( 'other' ) !== -1,
5226 +
5227 + id = 'field_' + fieldKey + '-' + opt.key;
5228 +
5229 + 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="" />';
5230 +
5231 + single = '<div class="frm_' + type + ' ' + type + ' ' + classes + '" id="frm_' + type + '_' + fieldId + '-' + opt.key + '"><label for="' + id +
5232 + '"><input type="' + type +
5233 + '" name="item_meta[' + fieldId + ']' + ( type === 'checkbox' ? '[]' : '' ) +
5234 + '" value="' + opt.saved + '" id="' + id + '"' + ( isProduct ? ' data-price="' + opt.price + '"' : '' ) + ( opt.checked ? ' checked="checked"' : '' ) + '> ' + opt.label + '</label>' +
5235 + ( isOther ? other : '' ) +
5236 + '</div>';
5237 +
5238 + return single;
5239 + }
5240 +
5241 + function fillDropdownOpts( field, atts ) {
5242 + if ( field === null ) {
5243 + return;
5244 + }
5245 + var sourceID = atts.sourceID,
5246 + placeholder = atts.placeholder,
5247 + isProduct = isProductField( sourceID ),
5248 + showOther = atts.other;
5249 +
5250 + removeDropdownOpts( field );
5251 + var opts = getMultipleOpts( sourceID ),
5252 + hasPlaceholder = ( typeof placeholder !== 'undefined' );
5253 +
5254 + for ( var i = 0; i < opts.length; i++ ) {
5255 + var label = opts[ i ].label,
5256 + isOther = opts[ i ].key.indexOf( 'other' ) !== -1;
5257 +
5258 + if ( hasPlaceholder && label !== '' ) {
5259 + addBlankSelectOption( field, placeholder );
5260 + } else if ( hasPlaceholder ) {
5261 + label = placeholder;
5262 + }
5263 + hasPlaceholder = false;
5264 +
5265 + if ( ! isOther || showOther ) {
5266 + var opt = document.createElement( 'option' );
5267 + opt.value = opts[ i ].saved;
5268 + opt.innerHTML = label;
5269 +
5270 + if ( isProduct ) {
5271 + opt.setAttribute( 'data-price', opts[ i ].price );
5272 + }
5273 +
5274 + field.appendChild( opt );
5275 + }
5276 + }
5277 + }
5278 +
5279 + function addBlankSelectOption( field, placeholder ) {
5280 + var opt = document.createElement( 'option' ),
5281 + firstChild = field.firstChild;
5282 +
5283 + opt.value = '';
5284 + opt.innerHTML = placeholder;
5285 + if ( firstChild !== null ) {
5286 + field.insertBefore( opt, firstChild );
5287 + field.selectedIndex = 0;
5288 + } else {
5289 + field.appendChild( opt );
5290 + }
5291 + }
5292 +
5293 + function getMultipleOpts( fieldId ) {
5294 + var i, saved, labelName, label, key, optObj,
5295 + image, savedLabel, input, field, checkbox, fieldType,
5296 + checked = false,
5297 + opts = [],
5298 + imageUrl = '',
5299 +
5300 + optVals = jQuery( 'input[name^="field_options[options_' + fieldId + ']"]' ),
5301 + separateValues = usingSeparateValues( fieldId ),
5302 + hasImageOptions = imagesAsOptions( fieldId ),
5303 + showLabelWithImage = showingLabelWithImage( fieldId ),
5304 + isProduct = isProductField( fieldId );
5305 +
5306 + for ( i = 0; i < optVals.length; i++ ) {
5307 + 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 ) {
5308 + continue;
5309 + }
5310 + saved = optVals[ i ].value;
5311 + label = saved;
5312 + key = optVals[ i ].name.replace( 'field_options[options_' + fieldId + '][', '' ).replace( '[label]', '' ).replace( ']', '' );
5313 +
5314 + if ( separateValues ) {
5315 + labelName = optVals[ i ].name.replace( '[label]', '[value]' );
5316 + saved = jQuery( 'input[name="' + labelName + '"]' ).val();
5317 + }
5318 +
5319 + if ( hasImageOptions ) {
5320 + imageUrl = getImageUrlFromInput( optVals[i]);
5321 + fieldType = radioOrCheckbox( fieldId );
5322 + label = getImageLabel( label, showLabelWithImage, imageUrl, fieldType );
5323 + }
5324 +
5325 + /**
5326 + * @since 5.0.04
5327 + */
5328 + label = frmAdminBuild.hooks.applyFilters( 'frm_choice_field_label', label, fieldId, optVals[ i ], hasImageOptions );
5329 +
5330 + checked = getChecked( optVals[ i ].id );
5331 +
5332 + optObj = {
5333 + saved: saved,
5334 + label: label,
5335 + checked: checked,
5336 + key: key
5337 + };
5338 +
5339 + if ( isProduct ) {
5340 + labelName = optVals[ i ].name.replace( '[label]', '[price]' );
5341 + optObj.price = jQuery( 'input[name="' + labelName + '"]' ).val();
5342 + }
5343 +
5344 + opts.push( optObj );
5345 + }
5346 +
5347 + return opts;
5348 + }
5349 +
5350 + function radioOrCheckbox( fieldId ) {
5351 + var settings = document.getElementById( 'frm-single-settings-' + fieldId );
5352 + if ( settings === null ) {
5353 + return 'radio';
5354 + }
5355 +
5356 + return settings.classList.contains( 'frm-type-checkbox' ) ? 'checkbox' : 'radio';
5357 + }
5358 +
5359 + function getImageUrlFromInput( optVal ) {
5360 + var img,
5361 + wrapper = jQuery( optVal ).siblings( '.frm_image_preview_wrapper' );
5362 +
5363 + if ( ! wrapper.length ) {
5364 + return '';
5365 + }
5366 +
5367 + img = wrapper.find( 'img' );
5368 + if ( ! img.length ) {
5369 + return '';
5370 + }
5371 +
5372 + return img.attr( 'src' );
5373 + }
5374 +
5375 + function getImageLabel( label, showLabelWithImage, imageUrl, fieldType ) {
5376 + var imageLabelClass, fullLabel,
5377 + originalLabel = label,
5378 + shape = fieldType === 'checkbox' ? 'square' : 'circle';
5379 +
5380 + fullLabel = '<div class="frm_selected_checkmark"><svg class="frmsvg"><use xlink:href="#frm_checkmark_' + shape + '_icon"></svg></div>';
5381 + if ( imageUrl ) {
5382 + fullLabel += '<img src="' + imageUrl + '" alt="' + originalLabel + '" />';
5383 + } else {
5384 + fullLabel += '<div class="frm_empty_url">' + frm_admin_js.image_placeholder_icon + '</div>';
5385 + }
5386 + if ( showLabelWithImage ) {
5387 + fullLabel += '<span class="frm_text_label_for_image"><span class="frm_text_label_for_image_inner">' + originalLabel + '</span></span>';
5388 + }
5389 +
5390 + imageLabelClass = showLabelWithImage ? ' frm_label_with_image' : '';
5391 +
5392 + return ( '<span class="frm_image_option_container' + imageLabelClass + '">' + fullLabel + '</span>' );
5393 + }
5394 +
5395 + function getChecked( id ) {
5396 + field = jQuery( '#' + id );
5397 +
5398 + if ( field.length === 0 ) {
5399 + return false;
5400 + }
5401 +
5402 + checkbox = field.siblings( 'input[type=checkbox]' );
5403 +
5404 + return checkbox.length && checkbox.prop( 'checked' );
5405 + }
5406 +
5407 + function removeDropdownOpts( field ) {
5408 + var i;
5409 + if ( typeof field.options === 'undefined' ) {
5410 + return;
5411 + }
5412 +
5413 + for ( i = field.options.length - 1; i >= 0; i-- ) {
5414 + field.remove( i );
5415 + }
5416 + }
5417 +
5418 + /**
5419 + * Is the box checked to use separate values?
5420 + */
5421 + function usingSeparateValues( fieldId ) {
5422 + return isChecked( 'separate_value_' + fieldId );
5423 + }
5424 +
5425 + /**
5426 + * Is the box checked to use images as options?
5427 + */
5428 + function imagesAsOptions( fieldId ) {
5429 + var checked = false,
5430 + field = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' );
5431 +
5432 + for ( var i = 0; i < field.length; i++ ) {
5433 + if ( field[ i ].checked ) {
5434 + checked = '0' !== field[ i ].value;
5435 + }
5436 + }
5437 +
5438 + /**
5439 + * @since 5.0.04
5440 + */
5441 + return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_images_as_options', checked, fieldId );
5442 + }
5443 +
5444 + function showingLabelWithImage( fieldId ) {
5445 + const isShowing = ! isChecked( 'hide_image_text_' + fieldId );
5446 +
5447 + /**
5448 + * @since 5.0.04
5449 + */
5450 + return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_showing_label_with_image', isShowing, fieldId );
5451 + }
5452 +
5453 + function isChecked( id ) {
5454 + var field = document.getElementById( id );
5455 + if ( field === null ) {
5456 + return false;
5457 + } else {
5458 + return field.checked;
5459 + }
5460 + }
5461 +
5462 + function checkUniqueOpt( targetInput ) {
5463 + const settingsContainer = targetInput.closest( '.frm-single-settings' );
5464 + const fieldId = settingsContainer.getAttribute( 'data-fid' );
5465 + const areValuesSeparate = settingsContainer.querySelector( '[name="field_options[separate_value_' + fieldId + ']"]' ).checked;
5466 +
5467 + if ( areValuesSeparate && ! targetInput.name.endsWith( '[value]' ) ) {
5468 + return;
5469 + }
5470 +
5471 + const container = document.getElementById( 'frm_field_' + fieldId + '_opts' );
5472 + const conflicts = Array.from( container.querySelectorAll( 'input[type="text"]' ) ).filter(
5473 + input => input.id !== targetInput.id &&
5474 + areValuesSeparate === input.name.endsWith( '[value]' ) &&
5475 + input.value === targetInput.value
5476 + );
5477 + if ( conflicts.length ) {
5478 + infoModal( __( 'Duplicate option value "%s" detected', 'formidable' ).replace( '%s', targetInput.value ) );
5479 + }
5480 + }
5481 +
5482 + function setStarValues() {
5483 + /*jshint validthis:true */
5484 + var fieldID = this.id.replace( 'radio_maxnum_', '' );
5485 + var container = jQuery( '#field_' + fieldID + '_inner_container .frm-star-group' );
5486 + var fieldKey = document.getElementsByName( 'field_options[field_key_' + fieldID + ']' )[0].value;
5487 + container.html( '' );
5488 +
5489 + var min = 1;
5490 + var max = this.value;
5491 + if ( min > max ) {
5492 + max = min;
5493 + }
5494 +
5495 + for ( var i = min; i <= max; i++ ) {
5496 + 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>' );
5497 + }
5498 + }
5499 +
5500 + function getFieldValues() {
5501 + /*jshint validthis:true */
5502 + var isTaxonomy,
5503 + val = this.value;
5504 +
5505 + if ( val ) {
5506 + var parentIDs = this.parentNode.id.replace( 'frm_logic_', '' ).split( '_' );
5507 + var fieldID = parentIDs[0];
5508 + var metaKey = parentIDs[1];
5509 + var valueField = document.getElementById( 'frm_field_id_' + val );
5510 + var valueFieldType = valueField.getAttribute( 'data-ftype' );
5511 + var fill = document.getElementById( 'frm_show_selected_values_' + fieldID + '_' + metaKey );
5512 + var optionName = 'field_options[hide_opt_' + fieldID + '][]';
5513 + var optionID = 'frm_field_logic_opt_' + fieldID;
5514 + var input = false;
5515 + var showSelect = ( valueFieldType === 'select' || valueFieldType === 'checkbox' || valueFieldType === 'radio' );
5516 + var showText = ( valueFieldType === 'text' || valueFieldType === 'email' || valueFieldType === 'phone' || valueFieldType === 'url' || valueFieldType === 'number' );
5517 +
5518 + if ( showSelect ) {
5519 + isTaxonomy = document.getElementById( 'frm_has_hidden_options_' + val );
5520 + if ( isTaxonomy !== null ) {
5521 + // get the category options with ajax
5522 + showSelect = false;
5523 + }
5524 + }
5525 +
5526 + if ( showSelect || showText ) {
5527 + fill.innerHTML = '';
5528 + if ( showSelect ) {
5529 + input = document.createElement( 'select' );
5530 + } else {
5531 + input = document.createElement( 'input' );
5532 + input.type = 'text';
5533 + }
5534 + input.name = optionName;
5535 + input.id = optionID + '_' + metaKey;
5536 + fill.appendChild( input );
5537 +
5538 + if ( showSelect ) {
5539 + var fillField = document.getElementById( input.id );
5540 + fillDropdownOpts( fillField, {
5541 + sourceID: val,
5542 + placeholder: '',
5543 + other: true
5544 + });
5545 + }
5546 + } else {
5547 + var thisType = this.getAttribute( 'data-type' );
5548 + frmGetFieldValues( val, fieldID, metaKey, thisType );
5549 + }
5550 + }
5551 + }
5552 +
5553 + function getFieldSelection() {
5554 + /*jshint validthis:true */
5555 + var formId = this.value;
5556 + if ( formId ) {
5557 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
5558 + getTaxOrFieldSelection( formId, fieldId );
5559 + }
5560 + }
5561 +
5562 + function getTaxOrFieldSelection( formId, fieldId ) {
5563 + if ( formId ) {
5564 + jQuery.ajax({
5565 + type: 'POST',
5566 + url: ajaxurl,
5567 + data: {
5568 + action: 'frm_get_field_selection',
5569 + field_id: fieldId,
5570 + form_id: formId,
5571 + nonce: frmGlobal.nonce
5572 + },
5573 + success: function( msg ) {
5574 + jQuery( '#frm_show_selected_fields_' + fieldId ).html( msg ).show();
5575 + }
5576 + });
5577 + }
5578 + }
5579 +
5580 + function updateFieldOrder() {
5581 + var fields, fieldId, field, currentOrder, newOrder;
5582 + renumberPageBreaks();
5583 + jQuery( '#frm-show-fields' ).each( function( i ) {
5584 + fields = jQuery( 'li.frm_field_box', this );
5585 + for ( i = 0; i < fields.length; i++ ) {
5586 + fieldId = fields[ i ].getAttribute( 'data-fid' );
5587 + field = jQuery( 'input[name="field_options[field_order_' + fieldId + ']"]' );
5588 + currentOrder = field.val();
5589 + newOrder = i + 1;
5590 +
5591 + if ( currentOrder != newOrder ) {
5592 + field.val( newOrder );
5593 + singleField = document.getElementById( 'frm-single-settings-' + fieldId );
5594 +
5595 + moveFieldSettings( singleField );
5596 + fieldUpdated();
5597 + }
5598 + }
5599 + });
5600 + }
5601 +
5602 + function toggleSectionHolder() {
5603 + document.querySelectorAll( '.start_divider' ).forEach(
5604 + function( divider ) {
5605 + toggleOneSectionHolder( jQuery( divider ) );
5606 + }
5607 + );
5608 + }
5609 +
5610 + function toggleOneSectionHolder( $section ) {
5611 + var noSectionFields, $rows, length, index, sectionHasFields;
5612 +
5613 + if ( ! $section.length ) {
5614 + return;
5615 + }
5616 +
5617 + $rows = $section.find( 'ul.frm_sorting' );
5618 + sectionHasFields = false;
5619 + length = $rows.length;
5620 + for ( index = 0; index < length; ++index ) {
5621 + if ( 0 !== getFieldsInRow( jQuery( $rows.get( index ) ) ).length ) {
5622 + sectionHasFields = true;
5623 + break;
5624 + }
5625 + }
5626 +
5627 + noSectionFields = $section.parent().children( '.frm_no_section_fields' ).get( 0 );
5628 + noSectionFields.classList.toggle( 'frm_block', ! sectionHasFields );
5629 + }
5630 +
5631 + function slideDown() {
5632 + /*jshint validthis:true */
5633 + var id = jQuery( this ).data( 'slidedown' );
5634 + var $thisId = jQuery( document.getElementById( id ) );
5635 + if ( $thisId.is( ':hidden' ) ) {
5636 + $thisId.slideDown( 'fast' );
5637 + this.style.display = 'none';
5638 + }
5639 + return false;
5640 + }
5641 +
5642 + function slideUp() {
5643 + /*jshint validthis:true */
5644 + var id = jQuery( this ).data( 'slideup' );
5645 + var $thisId = jQuery( document.getElementById( id ) );
5646 + $thisId.slideUp( 'fast' );
5647 + $thisId.siblings( 'a' ).show();
5648 + return false;
5649 + }
5650 +
5651 + function adjustVisibilityValuesForEveryoneValues( element, option ) {
5652 + if ( '' === option.getAttribute( 'value' ) ) {
5653 + onEveryoneOptionSelected( jQuery( this ) );
5654 + } else {
5655 + unselectEveryoneOptionIfSelected( jQuery( this ) );
5656 + }
5657 + }
5658 +
5659 + function onEveryoneOptionSelected( $select ) {
5660 + $select.val( '' );
5661 + $select.next( '.btn-group' ).find( '.multiselect-container input[value!=""]' ).prop( 'checked', false );
5662 + }
5663 +
5664 + function unselectEveryoneOptionIfSelected( $select ) {
5665 + var selectedValues = $select.val(),
5666 + index;
5667 +
5668 + if ( selectedValues === null ) {
5669 + $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', true );
5670 + onEveryoneOptionSelected( $select );
5671 + return;
5672 + }
5673 +
5674 + index = selectedValues.indexOf( '' );
5675 + if ( index >= 0 ) {
5676 + selectedValues.splice( index, 1 );
5677 + $select.val( selectedValues );
5678 + $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', false );
5679 + }
5680 + }
5681 +
5682 + /**
5683 + * Get rid of empty container that inserts extra space.
5684 + */
5685 + function hideEmptyEle() {
5686 + jQuery( '.frm-hide-empty' ).each( function() {
5687 + if ( jQuery( this ).text().trim().length === 0 ) {
5688 + jQuery( this ).remove();
5689 + }
5690 + });
5691 + }
5692 +
5693 + /* Change the classes in the builder */
5694 + function changeFieldClass( field, setting ) {
5695 + var classes, replace, alignField,
5696 + replaceWith = ' ' + setting.value,
5697 + fieldId = field.getAttribute( 'data-fid' );
5698 +
5699 + // Include classes from multiple settings.
5700 + if ( typeof fieldId !== 'undefined' ) {
5701 + if ( setting.classList.contains( 'field_options_align' ) ) {
5702 + replaceWith += ' ' + document.getElementById( 'frm_classes_' + fieldId ).value;
5703 + } else if ( setting.classList.contains( 'frm_classes' ) ) {
5704 + alignField = document.getElementById( 'field_options_align_' + fieldId );
5705 + if ( alignField !== null ) {
5706 + replaceWith += ' ' + alignField.value;
5707 + }
5708 + }
5709 + }
5710 + replaceWith += ' ';
5711 +
5712 + // Allow for the column number dropdown.
5713 + replaceWith = replaceWith.replace( ' block ', ' ' ).replace( ' inline ', ' horizontal_radio ' );
5714 +
5715 + classes = field.className.split( ' frmstart ' )[1];
5716 + classes = 0 === classes.indexOf( 'frmend ' ) ? '' : classes.split( ' frmend ' )[0];
5717 +
5718 + if ( classes.trim() === '' ) {
5719 + replace = ' frmstart frmend ';
5720 + if ( -1 === field.className.indexOf( replace ) ) {
5721 + replace = ' frmstart frmend ';
5722 + }
5723 + replaceWith = ' frmstart ' + replaceWith.trim() + ' frmend ';
5724 + } else {
5725 + replace = classes.trim();
5726 + replaceWith = replaceWith.trim();
5727 + }
5728 +
5729 + field.className = field.className.replace( replace, replaceWith );
5730 + }
5731 +
5732 + function maybeShowInlineModal( e ) {
5733 + /*jshint validthis:true */
5734 + e.preventDefault();
5735 + showInlineModal( this );
5736 + }
5737 +
5738 + function showInlineModal( icon, input ) {
5739 + var box = document.getElementById( icon.getAttribute( 'data-open' ) ),
5740 + container = jQuery( icon ).closest( 'p' ),
5741 + inputTrigger = ( typeof input !== 'undefined' );
5742 +
5743 + if ( container.hasClass( 'frm-open' ) ) {
5744 + container.removeClass( 'frm-open' );
5745 + box.classList.add( 'frm_hidden' );
5746 + } else {
5747 + if ( ! inputTrigger ) {
5748 + input = getInputForIcon( icon );
5749 + }
5750 + if ( input !== null ) {
5751 + if ( ! inputTrigger ) {
5752 + input.focus();
5753 + }
5754 + container.after( box );
5755 + box.setAttribute( 'data-fills', input.id );
5756 +
5757 + if ( box.id.indexOf( 'frm-calc-box' ) === 0 ) {
5758 + popCalcFields( box, true );
5759 + }
5760 + }
5761 +
5762 + container.addClass( 'frm-open' );
5763 + box.classList.remove( 'frm_hidden' );
5764 + }
5765 + }
5766 +
5767 + function dismissInlineModal( e ) {
5768 + /*jshint validthis:true */
5769 + e.preventDefault();
5770 + this.parentNode.classList.add( 'frm_hidden' );
5771 + jQuery( '.frm-open [data-open="' + this.parentNode.id + '"]' ).closest( '.frm-open' ).removeClass( 'frm-open' );
5772 + }
5773 +
5774 + function changeInputtedValue() {
5775 + /*jshint validthis:true */
5776 + var i,
5777 + action = this.getAttribute( 'data-frmchange' ).split( ',' );
5778 +
5779 + for ( i = 0; i < action.length; i++ ) {
5780 + if ( action[i] === 'updateOption' ) {
5781 + changeHiddenSeparateValue( this );
5782 + } else if ( action[i] === 'updateDefault' ) {
5783 + changeDefaultRadioValue( this );
5784 + } else if ( action[i] === 'checkUniqueOpt' ) {
5785 + checkUniqueOpt( this );
5786 + } else {
5787 + this.value = this.value[ action[i] ]();
5788 + }
5789 + }
5790 + }
5791 +
5792 + /**
5793 + * When the saved value is changed, update the default value radio.
5794 + */
5795 + function changeDefaultRadioValue( input ) {
5796 + var parentLi = getOptionParent( input ),
5797 + key = parentLi.getAttribute( 'data-optkey' ),
5798 + fieldId = getOptionFieldId( parentLi, key ),
5799 + defaultRadio = parentLi.querySelector( 'input[name="default_value_' + fieldId + '"]' );
5800 +
5801 + if ( defaultRadio !== null ) {
5802 + defaultRadio.value = input.value;
5803 + }
5804 + }
5805 +
5806 + /**
5807 + * If separate values are not enabled, change the saved value when
5808 + * the displayed value is changed.
5809 + */
5810 + function changeHiddenSeparateValue( input ) {
5811 + var savedVal,
5812 + parentLi = getOptionParent( input ),
5813 + key = parentLi.getAttribute( 'data-optkey' ),
5814 + fieldId = getOptionFieldId( parentLi, key ),
5815 + sep = document.getElementById( 'separate_value_' + fieldId );
5816 +
5817 + if ( sep !== null && sep.checked === false ) {
5818 + // If separate values are not turned on.
5819 + savedVal = document.getElementById( 'field_key_' + fieldId + '-' + key );
5820 + savedVal.value = input.value;
5821 + changeDefaultRadioValue( savedVal );
5822 + }
5823 + }
5824 +
5825 + function getOptionParent( input ) {
5826 + var parentLi = input.parentNode;
5827 + if ( parentLi.tagName !== 'LI' ) {
5828 + parentLi = parentLi.parentNode;
5829 + }
5830 + return parentLi;
5831 + }
5832 +
5833 + function getOptionFieldId( li, key ) {
5834 + var liId = li.id;
5835 +
5836 + return liId.replace( 'frm_delete_field_', '' ).replace( '-' + key + '_container', '' );
5837 + }
5838 +
5839 + function submitBuild() {
5840 + /*jshint validthis:true */
5841 + var $thisEle = jQuery( this );
5842 + var p = $thisEle.html();
5843 +
5844 + preFormSave( this );
5845 +
5846 + var $form = jQuery( builderForm );
5847 + var v = JSON.stringify( $form.serializeArray() );
5848 +
5849 + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( v );
5850 + jQuery.ajax({
5851 + type: 'POST',
5852 + url: ajaxurl,
5853 + data: {action: 'frm_save_form', 'frm_compact_fields': v, nonce: frmGlobal.nonce},
5854 + success: function( msg ) {
5855 + afterFormSave( $thisEle, p );
5856 +
5857 + var $postStuff = document.getElementById( 'post-body-content' );
5858 + var $html = document.createElement( 'div' );
5859 + $html.setAttribute( 'class', 'frm_updated_message' );
5860 + $html.innerHTML = msg;
5861 + $postStuff.insertBefore( $html, $postStuff.firstChild );
5862 + },
5863 + error: function() {
5864 + triggerSubmit( document.getElementById( 'frm_js_build_form' ) );
5865 + }
5866 + });
5867 + }
5868 +
5869 + function triggerSubmit( form ) {
5870 + var button = form.ownerDocument.createElement( 'input' );
5871 + button.style.display = 'none';
5872 + button.type = 'submit';
5873 + form.appendChild( button ).click();
5874 + form.removeChild( button );
5875 + }
5876 +
5877 + function triggerChange( element ) {
5878 + jQuery( element ).trigger( 'change' );
5879 + }
5880 +
5881 + function submitNoAjax() {
5882 + /*jshint validthis:true */
5883 + var form;
5884 +
5885 + preFormSave( this );
5886 + form = jQuery( builderForm );
5887 + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( JSON.stringify( form.serializeArray() ) );
5888 + triggerSubmit( document.getElementById( 'frm_js_build_form' ) );
5889 + }
5890 +
5891 + function preFormSave( b ) {
5892 + removeWPUnload();
5893 + if ( jQuery( 'form.inplace_form' ).length ) {
5894 + jQuery( '.inplace_save, .postbox' ).trigger( 'click' );
5895 + }
5896 +
5897 + $button = jQuery( b );
5898 +
5899 + if ( $button.hasClass( 'frm_button_submit' ) ) {
5900 + $button.addClass( 'frm_loading_form' );
5901 + $button.html( frm_admin_js.saving );
5902 + } else {
5903 + $button.addClass( 'frm_loading_button' );
5904 + $button.val( frm_admin_js.saving );
5905 + }
5906 + }
5907 +
5908 + function afterFormSave( $button, buttonVal ) {
5909 + $button.removeClass( 'frm_loading_form' ).removeClass( 'frm_loading_button' );
5910 + $button.html( frm_admin_js.saved );
5911 + resetOptionTextDetails();
5912 + fieldsUpdated = 0;
5913 +
5914 + setTimeout( function() {
5915 + jQuery( '.frm_updated_message' ).fadeOut( 'slow', function() {
5916 + this.parentNode.removeChild( this );
5917 + });
5918 + $button.fadeOut( 'slow', function() {
5919 + $button.html( buttonVal );
5920 + $button.show();
5921 + });
5922 + }, 5000 );
5923 + }
5924 +
5925 + function initUpgradeModal() {
5926 + const $info = initModal( '#frm_upgrade_modal' );
5927 + if ( $info === false ) {
5928 + return;
5929 + }
5930 +
5931 + document.addEventListener( 'click', handleUpgradeClick );
5932 +
5933 + function handleUpgradeClick( event ) {
5934 + let element, link, content;
5935 +
5936 + element = event.target;
5937 +
5938 + if ( ! element.classList ) {
5939 + return;
5940 + }
5941 +
5942 + const showExpiredModal = element.classList.contains( 'frm_show_expired_modal' ) || null !== element.querySelector( '.frm_show_expired_modal' ) || element.closest( '.frm_show_expired_modal' );
5943 +
5944 + if ( ! element.dataset.upgrade ) {
5945 + const parent = element.closest( '[data-upgrade]' );
5946 + if ( ! parent ) {
5947 + return;
5948 + }
5949 + element = parent;
5950 + }
5951 +
5952 + if ( showExpiredModal ) {
5953 + const hookName = 'frm_show_expired_modal';
5954 + wp.hooks.doAction( hookName, element );
5955 + return;
5956 + }
5957 +
5958 + const upgradeLabel = element.dataset.upgrade;
5959 + if ( ! upgradeLabel || element.classList.contains( 'frm_show_upgrade_tab' ) ) {
5960 + return;
5961 + }
5962 +
5963 + event.preventDefault();
5964 +
5965 + const modal = $info.get( 0 );
5966 + const lockIcon = modal.querySelector( '.frm_lock_icon' );
5967 +
5968 + if ( lockIcon ) {
5969 + lockIcon.style.display = 'block';
5970 + lockIcon.classList.remove( 'frm_lock_open_icon' );
5971 + lockIcon.querySelector( 'use' ).setAttribute( 'href', '#frm_lock_icon' );
5972 + }
5973 +
5974 + const upgradeImageId = 'frm_upgrade_modal_image';
5975 + const oldImage = document.getElementById( upgradeImageId );
5976 + if ( oldImage ) {
5977 + oldImage.remove();
5978 + }
5979 +
5980 + if ( element.dataset.image ) {
5981 + if ( lockIcon ) {
5982 + lockIcon.style.display = 'none';
5983 + }
5984 + lockIcon.parentNode.insertBefore( img({ id: upgradeImageId, src: frmGlobal.url + '/images/' + element.dataset.image }), lockIcon );
5985 + }
5986 +
5987 + const level = modal.querySelector( '.license-level' );
5988 + if ( level ) {
5989 + level.textContent = getRequiredLicenseFromTrigger( element );
5990 + }
5991 +
5992 + // If one click upgrade, hide other content
5993 + addOneClick( element, 'modal', upgradeLabel );
5994 +
5995 + modal.querySelector( '.frm_are_not_installed' ).style.display = element.dataset.image ? 'none' : 'inline-block';
5996 + modal.querySelector( '.frm_feature_label' ).textContent = upgradeLabel;
5997 + modal.querySelector( 'h2' ).style.display = 'block';
5998 +
5999 + $info.dialog( 'open' );
6000 +
6001 + // set the utm medium
6002 + const button = modal.querySelector( '.button-primary:not(.frm-oneclick-button)' );
6003 + link = button.getAttribute( 'href' ).replace( /(medium=)[a-z_-]+/ig, '$1' + element.getAttribute( 'data-medium' ) );
6004 + content = element.getAttribute( 'data-content' );
6005 + if ( content === null ) {
6006 + content = '';
6007 + }
6008 + link = link.replace( /(content=)[a-z_-]+/ig, '$1' + content );
6009 + button.setAttribute( 'href', link );
6010 + }
6011 + }
6012 +
6013 + // Move the top banner above the screen options to prevent overlap.
6014 + function moveTopBanner() {
6015 + const $banner = document.querySelector( '.frm-banner-alert' ) || document.querySelector( '.frm-upgrade-bar' );
6016 + if ( ! $banner ) {
6017 + return;
6018 + }
6019 +
6020 + const $screenMeta = document.getElementById( 'screen-meta' );
6021 + if ( ! $screenMeta ) {
6022 + return;
6023 + }
6024 +
6025 + const $parentDiv = document.getElementById( 'wpbody-content' );
6026 + $parentDiv.insertBefore( $banner, $screenMeta );
6027 + }
6028 +
6029 + function getRequiredLicenseFromTrigger( element ) {
6030 + if ( element.dataset.requires ) {
6031 + return element.dataset.requires;
6032 + }
6033 + return 'Pro';
6034 + }
6035 +
6036 + function populateUpgradeTab( element ) {
6037 + const title = element.dataset.upgrade;
6038 +
6039 + const tab = element.getAttribute( 'href' ).replace( '#', '' );
6040 + const container = document.querySelector( '.frm_' + tab ) || document.querySelector( '.' + tab );
6041 +
6042 + if ( ! container ) {
6043 + return;
6044 + }
6045 +
6046 + if ( container.querySelector( '.frm-upgrade-message' ) ) {
6047 + // Tab has already been populated.
6048 + return;
6049 + }
6050 +
6051 + const h2 = container.querySelector( 'h2' );
6052 + h2.style.borderBottom = 'none';
6053 +
6054 + /* translators: %s: Form Setting section name (ie Form Permissions, Form Scheduling). */
6055 + h2.textContent = __( '%s are not installed' ).replace( '%s', title );
6056 +
6057 + container.classList.add( 'frmcenter' );
6058 +
6059 + const upgradeModal = document.getElementById( 'frm_upgrade_modal' );
6060 + appendClonedModalElementToContainer( 'frm-oneclick' );
6061 + appendClonedModalElementToContainer( 'frm-addon-status' );
6062 +
6063 + // 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).
6064 + const upgradeModalLink = upgradeModal.querySelector( '.frm-upgrade-link' );
6065 + if ( upgradeModalLink ) {
6066 + const upgradeButton = upgradeModalLink.cloneNode( true );
6067 + const level = upgradeButton.querySelector( '.license-level' );
6068 +
6069 + if ( level ) {
6070 + level.textContent = getRequiredLicenseFromTrigger( element );
6071 + }
6072 +
6073 + container.appendChild( upgradeButton );
6074 +
6075 + // Maybe append the secondary "Already purchased?" link from the upgradeModal as well.
6076 + if ( upgradeModalLink.nextElementSibling && upgradeModalLink.nextElementSibling.querySelector( '.frm-link-secondary' ) ) {
6077 + container.appendChild( upgradeModalLink.nextElementSibling.cloneNode( true ) );
6078 + }
6079 +
6080 + appendClonedModalElementToContainer( 'frm-oneclick-button' );
6081 + }
6082 +
6083 + appendClonedModalElementToContainer( 'frm-upgrade-message' );
6084 + addOneClick( element, 'tab', element.dataset.message );
6085 +
6086 + if ( element.dataset.screenshot ) {
6087 + container.appendChild( getScreenshotWrapper( element.dataset.screenshot ) );
6088 + }
6089 +
6090 + function appendClonedModalElementToContainer( className ) {
6091 + container.appendChild( upgradeModal.querySelector( '.' + className ).cloneNode( true ) );
6092 + }
6093 + }
6094 +
6095 + function getScreenshotWrapper( screenshot ) {
6096 + const folderUrl = frmGlobal.url + '/images/screenshots/';
6097 + const wrapper = div({
6098 + className: 'frm-settings-screenshot-wrapper',
6099 + children: [
6100 + getToolbar(),
6101 + div({ child: img({ src: folderUrl + screenshot }) })
6102 + ]
6103 + });
6104 +
6105 + function getToolbar() {
6106 + const children = getColorIcons();
6107 + children.push( img({ src: frmGlobal.url + '/images/tab.svg' }) );
6108 + return div({
6109 + className: 'frm-settings-screenshot-toolbar',
6110 + children
6111 + });
6112 + }
6113 +
6114 + function getColorIcons() {
6115 + return [ '#ED8181', '#EDE06A', '#80BE30' ].map(
6116 + color => {
6117 + const circle = div({ className: 'frm-minmax-icon' });
6118 + circle.style.backgroundColor = color;
6119 + return circle;
6120 + }
6121 + );
6122 + }
6123 +
6124 + return wrapper;
6125 + }
6126 +
6127 + /**
6128 + * Allow addons to be installed from the upgrade modal.
6129 + *
6130 + * @param {Element} link
6131 + * @param {String} context Either 'modal' or 'tab'.
6132 + * @param {String|undefined} upgradeLabel
6133 + */
6134 + function addOneClick( link, context, upgradeLabel ) {
6135 + let container;
6136 +
6137 + if ( 'modal' === context ) {
6138 + container = document.getElementById( 'frm_upgrade_modal' );
6139 + } else if ( 'tab' === context ) {
6140 + container = document.getElementById( link.getAttribute( 'href' ).substr( 1 ) );
6141 + } else {
6142 + return;
6143 + }
6144 +
6145 + const oneclickMessage = container.querySelector( '.frm-oneclick' );
6146 + const upgradeMessage = container.querySelector( '.frm-upgrade-message' );
6147 + const showLink = container.querySelector( '.frm-upgrade-link' );
6148 + const button = container.querySelector( '.frm-oneclick-button' );
6149 + const addonStatus = container.querySelector( '.frm-addon-status' );
6150 +
6151 + let oneclick = link.getAttribute( 'data-oneclick' );
6152 + let newMessage = link.getAttribute( 'data-message' );
6153 + let showIt = 'block';
6154 + let showMsg = 'block';
6155 + let hideIt = 'none';
6156 +
6157 + // If one click upgrade, hide other content.
6158 + if ( oneclickMessage !== null && typeof oneclick !== 'undefined' && oneclick ) {
6159 + if ( newMessage === null ) {
6160 + showMsg = 'none';
6161 + }
6162 + showIt = 'none';
6163 + hideIt = 'block';
6164 + oneclick = JSON.parse( oneclick );
6165 +
6166 + button.className = button.className.replace( ' frm-install-addon', '' ).replace( ' frm-activate-addon', '' );
6167 + button.className = button.className + ' ' + oneclick.class;
6168 + button.textContent = __( 'Activate', 'formidable' );
6169 + button.rel = oneclick.url;
6170 + }
6171 +
6172 + if ( ! newMessage ) {
6173 + newMessage = upgradeMessage.getAttribute( 'data-default' );
6174 + }
6175 + if ( undefined !== upgradeLabel ) {
6176 + newMessage = newMessage.replace( '<span class="frm_feature_label"></span>', upgradeLabel );
6177 + }
6178 +
6179 + upgradeMessage.innerHTML = newMessage;
6180 +
6181 + // Either set the link or use the default.
6182 + showLink.href = getShowLinkHrefValue( link, showLink );
6183 +
6184 + addonStatus.style.display = 'none';
6185 +
6186 + oneclickMessage.style.display = hideIt;
6187 + button.style.display = hideIt === 'block' ? 'inline-block' : hideIt;
6188 + upgradeMessage.style.display = showMsg;
6189 + showLink.style.display = showIt === 'block' ? 'inline-block' : showIt;
6190 + }
6191 +
6192 + function getShowLinkHrefValue( link, showLink ) {
6193 + let customLink = link.getAttribute( 'data-link' );
6194 + if ( customLink === null || typeof customLink === 'undefined' || customLink === '' ) {
6195 + customLink = showLink.getAttribute( 'data-default' );
6196 + }
6197 + return customLink;
6198 + }
6199 +
6200 + /* Form settings */
6201 +
6202 + function showInputIcon( parentClass ) {
6203 + if ( typeof parentClass === 'undefined' ) {
6204 + parentClass = '';
6205 + }
6206 + maybeAddFieldSelection( parentClass );
6207 + 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>' );
6208 + }
6209 +
6210 + /**
6211 + * For reverse compatibility. Check for fields that were
6212 + * using the old sidebar.
6213 + */
6214 + function maybeAddFieldSelection( parentClass ) {
6215 + var i,
6216 + 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' );
6217 + for ( i = 0; i < missingClass.length; i++ ) {
6218 + missingClass[i].parentNode.classList.add( 'frm_has_shortcodes' );
6219 + }
6220 + }
6221 +
6222 + function showSuccessOpt() {
6223 + /*jshint validthis:true */
6224 + var c = 'success';
6225 + if ( this.name === 'options[edit_action]' ) {
6226 + c = 'edit';
6227 + }
6228 + var v = jQuery( this ).val();
6229 + jQuery( '.' + c + '_action_box' ).hide();
6230 + if ( v === 'redirect' ) {
6231 + jQuery( '.' + c + '_action_redirect_box.' + c + '_action_box' ).fadeIn( 'slow' );
6232 + } else if ( v === 'page' ) {
6233 + jQuery( '.' + c + '_action_page_box.' + c + '_action_box' ).fadeIn( 'slow' );
6234 + } else {
6235 + jQuery( '.' + c + '_action_message_box.' + c + '_action_box' ).fadeIn( 'slow' );
6236 + }
6237 + }
6238 +
6239 + function copyFormAction( event ) {
6240 + if ( waitForActionToLoadBeforeCopy( event.target ) ) {
6241 + return;
6242 + }
6243 +
6244 + const targetSettings = event.target.closest( '.frm_form_action_settings' );
6245 + const wysiwyg = targetSettings.querySelector( '.wp-editor-area' );
6246 + if ( wysiwyg ) {
6247 + // Temporary remove TinyMCE before cloning to avoid TinyMCE conflicts.
6248 + tinymce.EditorManager.execCommand( 'mceRemoveEditor', true, wysiwyg.id );
6249 + }
6250 +
6251 + const $action = jQuery( targetSettings ).clone();
6252 + const currentID = $action.attr( 'id' ).replace( 'frm_form_action_', '' );
6253 + const newID = newActionId( currentID );
6254 +
6255 + $action.find( '.frm_action_id, .frm-btn-group' ).remove();
6256 + $action.find( 'input[name$="[' + currentID + '][ID]"]' ).val( '' );
6257 + $action.find( '.widget-inside' ).hide();
6258 +
6259 + // the .html() gets original values, so they need to be set
6260 + $action.find( 'input[type=text], textarea, input[type=number]' ).prop( 'defaultValue', function() {
6261 + return this.value;
6262 + });
6263 +
6264 + $action.find( 'input[type=checkbox], input[type=radio]' ).prop( 'defaultChecked', function() {
6265 + return this.checked;
6266 + });
6267 +
6268 + const rename = new RegExp( '\\[' + currentID + '\\]', 'g' );
6269 + const reid = new RegExp( '_' + currentID + '"', 'g' );
6270 + const reclass = new RegExp( '-' + currentID + '"', 'g' );
6271 + const revalue = new RegExp( '"' + currentID + '"', 'g' ); // if a field id matches, this could cause trouble
6272 +
6273 + let html = $action.html().replace( rename, '[' + newID + ']' ).replace( reid, '_' + newID + '"' );
6274 + html = html.replace( reclass, '-' + newID + '"' ).replace( revalue, '"' + newID + '"' );
6275 +
6276 + const newAction = div({
6277 + id: 'frm_form_action_' + newID,
6278 + className: $action.get( 0 ).className
6279 + });
6280 + newAction.setAttribute( 'data-actionkey', newID );
6281 + newAction.innerHTML = html;
6282 + newAction.querySelectorAll( '.wp-editor-wrap, .wp-editor-wrap *' ).forEach(
6283 + element => {
6284 + if ( 'string' === typeof element.className ) {
6285 + element.className = element.className.replace( currentID, newID );
6286 + }
6287 + element.id = element.id.replace( currentID, newID );
6288 + }
6289 + );
6290 + newAction.classList.remove( 'open' );
6291 + document.getElementById( 'frm_notification_settings' ).appendChild( newAction );
6292 +
6293 + if ( wysiwyg ) {
6294 + // Re-initialize the original wysiwyg which was removed before cloning.
6295 + frmDom.wysiwyg.init( wysiwyg );
6296 + }
6297 + frmDom.wysiwyg.init( newAction.querySelector( '.wp-editor-area' ) );
6298 +
6299 + initiateMultiselect();
6300 +
6301 + const hookName = 'frm_after_duplicate_action';
6302 + wp.hooks.doAction( hookName, newAction );
6303 + }
6304 +
6305 + function waitForActionToLoadBeforeCopy( element ) {
6306 + var $trigger = jQuery( element ),
6307 + $original = $trigger.closest( '.frm_form_action_settings' ),
6308 + $inside = $original.find( '.widget-inside' ),
6309 + $top;
6310 +
6311 + if ( $inside.find( 'p, div, table' ).length ) {
6312 + return false;
6313 + }
6314 +
6315 + $top = $original.find( '.widget-top' );
6316 + $top.on( 'frm-action-loaded', function() {
6317 + $trigger.trigger( 'click' );
6318 + $original.removeClass( 'open' );
6319 + $inside.hide();
6320 + });
6321 + $top.trigger( 'click' );
6322 + return true;
6323 + }
6324 +
6325 + function newActionId( currentID ) {
6326 + var newID = parseInt( currentID, 10 ) + 11;
6327 + var exists = document.getElementById( 'frm_form_action_' + newID );
6328 + if ( exists !== null ) {
6329 + newID++;
6330 + newID = newActionId( newID );
6331 + }
6332 + return newID;
6333 + }
6334 +
6335 + function addFormAction() {
6336 + /*jshint validthis:true */
6337 + const type = jQuery( this ).data( 'actiontype' );
6338 +
6339 + if ( isAtLimitForActionType( type ) ) {
6340 + return;
6341 + }
6342 +
6343 + const actionId = getNewActionId();
6344 + const formId = thisFormId;
6345 +
6346 + const placeholderSetting = document.createElement( 'div' );
6347 + placeholderSetting.classList.add( 'frm_single_' + type + '_settings' );
6348 +
6349 + const actionsList = document.getElementById( 'frm_notification_settings' );
6350 + actionsList.appendChild( placeholderSetting );
6351 +
6352 + jQuery.ajax({
6353 + type: 'POST',
6354 + url: ajaxurl,
6355 + data: {
6356 + action: 'frm_add_form_action',
6357 + type: type,
6358 + list_id: actionId,
6359 + form_id: formId,
6360 + nonce: frmGlobal.nonce
6361 + },
6362 + success: handleAddFormActionSuccess
6363 + });
6364 +
6365 + function handleAddFormActionSuccess( html ) {
6366 + fieldUpdated();
6367 + placeholderSetting.remove();
6368 +
6369 + closeOpenActions();
6370 +
6371 + const newActionContainer = div();
6372 + newActionContainer.innerHTML = html;
6373 +
6374 + const widgetTop = newActionContainer.querySelector( '.widget-top' );
6375 + Array.from( newActionContainer.children ).forEach( child => actionsList.appendChild( child ) );
6376 +
6377 + jQuery( '.frm_form_action_settings' ).fadeIn( 'slow' );
6378 +
6379 + const newAction = document.getElementById( 'frm_form_action_' + actionId );
6380 +
6381 + newAction.classList.add( 'open' );
6382 + document.getElementById( 'post-body-content' ).scroll({
6383 + top: newAction.offsetTop + 10,
6384 + left: 0,
6385 + behavior: 'smooth'
6386 + });
6387 +
6388 + // Check if icon should be active
6389 + checkActiveAction( type );
6390 + showInputIcon( '#frm_form_action_' + actionId );
6391 +
6392 + initiateMultiselect();
6393 +
6394 + if ( widgetTop ) {
6395 + jQuery( widgetTop ).trigger( 'frm-action-loaded' );
6396 + }
6397 + }
6398 + }
6399 +
6400 + function closeOpenActions() {
6401 + document.querySelectorAll( '.frm_form_action_settings.open' ).forEach(
6402 + setting => setting.classList.remove( 'open' )
6403 + );
6404 + }
6405 +
6406 + function toggleActionGroups() {
6407 + /*jshint validthis:true */
6408 + var actions = document.getElementById( 'frm_email_addon_menu' ).classList,
6409 + search = document.getElementById( 'actions-search-input' );
6410 +
6411 + if ( actions.contains( 'frm-all-actions' ) ) {
6412 + actions.remove( 'frm-all-actions' );
6413 + actions.add( 'frm-limited-actions' );
6414 + } else {
6415 + actions.add( 'frm-all-actions' );
6416 + actions.remove( 'frm-limited-actions' );
6417 + }
6418 +
6419 + // Reset search.
6420 + search.value = '';
6421 + triggerEvent( search, 'input' );
6422 + }
6423 +
6424 + function getNewActionId() {
6425 + var actionSettings = document.querySelectorAll( '.frm_form_action_settings' ),
6426 + len = getNewRowId( actionSettings, 'frm_form_action_' );
6427 + if ( typeof document.getElementById( 'frm_form_action_' + len ) !== 'undefined' ) {
6428 + len = len + 100;
6429 + }
6430 + if ( lastNewActionIdReturned >= len ) {
6431 + len = lastNewActionIdReturned + 1;
6432 + }
6433 + lastNewActionIdReturned = len;
6434 + return len;
6435 + }
6436 +
6437 + function clickAction( obj ) {
6438 + var $thisobj = jQuery( obj );
6439 +
6440 + if ( obj.className.indexOf( 'selected' ) !== -1 ) {
6441 + return;
6442 + }
6443 + if ( obj.className.indexOf( 'edit_field_type_end_divider' ) !== -1 && $thisobj.closest( '.edit_field_type_divider' ).hasClass( 'no_repeat_section' ) ) {
6444 + return;
6445 + }
6446 +
6447 + deselectFields();
6448 + $thisobj.addClass( 'selected' );
6449 + showFieldOptions( obj );
6450 + }
6451 +
6452 + /**
6453 + * When a field is selected, show the field settings in the sidebar.
6454 + */
6455 + function showFieldOptions( obj ) {
6456 + var i, singleField,
6457 + fieldId = obj.getAttribute( 'data-fid' ),
6458 + fieldType = obj.getAttribute( 'data-type' ),
6459 + allFieldSettings = document.querySelectorAll( '.frm-single-settings:not(.frm_hidden)' );
6460 +
6461 + for ( i = 0; i < allFieldSettings.length; i++ ) {
6462 + allFieldSettings[i].classList.add( 'frm_hidden' );
6463 + }
6464 +
6465 + singleField = document.getElementById( 'frm-single-settings-' + fieldId );
6466 + moveFieldSettings( singleField );
6467 +
6468 + if ( fieldType && 'quantity' === fieldType ) {
6469 + popProductFields( jQuery( singleField ).find( '.frmjs_prod_field_opt' )[0]);
6470 + }
6471 +
6472 + singleField.classList.remove( 'frm_hidden' );
6473 + document.getElementById( 'frm-options-panel-tab' ).click();
6474 +
6475 + const editor = singleField.querySelector( '.wp-editor-area' );
6476 + if ( editor ) {
6477 + frmDom.wysiwyg.init(
6478 + editor,
6479 + { setupCallback: setupTinyMceEventHandlers }
6480 + );
6481 + }
6482 + }
6483 +
6484 + function setupTinyMceEventHandlers( editor ) {
6485 + editor.on( 'Change', function() {
6486 + handleTinyMceChange( editor );
6487 + });
6488 + }
6489 +
6490 + function handleTinyMceChange( editor ) {
6491 + if ( ! isTinyMceActive() || tinyMCE.activeEditor.isHidden() ) {
6492 + return;
6493 + }
6494 +
6495 + editor.targetElm.value = editor.getContent();
6496 + jQuery( editor.targetElm ).trigger( 'change' );
6497 + }
6498 +
6499 + function isTinyMceActive() {
6500 + var activeSettings, wrapper;
6501 +
6502 + activeSettings = document.querySelector( '.frm-single-settings:not(.frm_hidden)' );
6503 + if ( ! activeSettings ) {
6504 + return false;
6505 + }
6506 +
6507 + wrapper = activeSettings.querySelector( '.wp-editor-wrap' );
6508 + return null !== wrapper && wrapper.classList.contains( 'tmce-active' );
6509 + }
6510 +
6511 + /**
6512 + * Move the settings to the sidebar the first time they are changed or selected.
6513 + * Keep the end marker at the end of the form.
6514 + */
6515 + function moveFieldSettings( singleField ) {
6516 + if ( singleField === null ) {
6517 + // The field may have not been loaded yet via ajax.
6518 + return;
6519 + }
6520 +
6521 + var classes = singleField.parentElement.classList;
6522 + if ( classes.contains( 'frm_field_box' ) || classes.contains( 'divider_section_only' ) ) {
6523 + var endMarker = document.getElementById( 'frm-end-form-marker' );
6524 + builderForm.insertBefore( singleField, endMarker );
6525 + }
6526 + }
6527 +
6528 + function showEmailRow() {
6529 + /*jshint validthis:true */
6530 + var actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' );
6531 + var rowType = this.getAttribute( 'data-emailrow' );
6532 +
6533 + jQuery( '#frm_form_action_' + actionKey + ' .frm_' + rowType + '_row' ).fadeIn( 'slow' );
6534 + jQuery( this ).fadeOut( 'slow' );
6535 + }
6536 +
6537 + function hideEmailRow() {
6538 + /*jshint validthis:true */
6539 + var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ),
6540 + rowType = this.getAttribute( 'data-emailrow' ),
6541 + emailRowSelector = '.frm_' + rowType + '_row',
6542 + emailButtonSelector = '.frm_' + rowType + '_button';
6543 +
6544 + jQuery( actionBox ).find( emailButtonSelector ).fadeIn( 'slow' );
6545 + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow', function() {
6546 + jQuery( actionBox ).find( emailRowSelector + ' input' ).val( '' );
6547 + });
6548 + }
6549 +
6550 + function showEmailWarning() {
6551 + /*jshint validthis:true */
6552 + var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ),
6553 + emailRowSelector = '.frm_from_to_match_row',
6554 + fromVal = actionBox.find( 'input[name$="[post_content][from]"]' ).val(),
6555 + toVal = actionBox.find( 'input[name$="[post_content][email_to]"]' ).val();
6556 +
6557 + if ( fromVal === toVal ) {
6558 + jQuery( actionBox ).find( emailRowSelector ).fadeIn( 'slow' );
6559 + } else {
6560 + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow' );
6561 + }
6562 + }
6563 +
6564 + function checkActiveAction( type ) {
6565 + const actionTriggers = document.querySelectorAll( '.frm_' + type + '_action' );
6566 +
6567 + if ( isAtLimitForActionType( type ) ) {
6568 + const addAlreadyUsedClass = getLimitForActionType( type ) > 0;
6569 + markActionTriggersInactive( actionTriggers, addAlreadyUsedClass );
6570 + return;
6571 + }
6572 +
6573 + markActionTriggersActive( actionTriggers );
6574 + }
6575 +
6576 + function markActionTriggersActive( triggers ) {
6577 + triggers.forEach(
6578 + trigger => {
6579 + if ( trigger.querySelector( '.frm_show_upgrade' ) ) {
6580 + // Prevent disabled action becoming active.
6581 + return;
6582 + }
6583 +
6584 + trigger.classList.remove( 'frm_inactive_action', 'frm_already_used' );
6585 + trigger.classList.add( 'frm_active_action' );
6586 + }
6587 + );
6588 + }
6589 +
6590 + function markActionTriggersInactive( triggers, addAlreadyUsedClass ) {
6591 + triggers.forEach(
6592 + trigger => {
6593 + trigger.classList.remove( 'frm_active_action' );
6594 + trigger.classList.add( 'frm_inactive_action' );
6595 + if ( addAlreadyUsedClass ) {
6596 + trigger.classList.add( 'frm_already_used' );
6597 + }
6598 + }
6599 + );
6600 + }
6601 +
6602 + function isAtLimitForActionType( type ) {
6603 + let atLimit = getNumberOfActionsForType( type ) >= getLimitForActionType( type );
6604 +
6605 + const hookName = 'frm_action_at_limit';
6606 + const hookArgs = { type };
6607 + atLimit = wp.hooks.applyFilters( hookName, atLimit, hookArgs );
6608 +
6609 + return atLimit;
6610 + }
6611 +
6612 + function getLimitForActionType( type ) {
6613 + return parseInt( jQuery( '.frm_' + type + '_action' ).data( 'limit' ), 10 );
6614 + }
6615 +
6616 + function getNumberOfActionsForType( type ) {
6617 + return jQuery( '.frm_single_' + type + '_settings' ).length;
6618 + }
6619 +
6620 + function onlyOneActionMessage() {
6621 + infoModal( frm_admin_js.only_one_action );
6622 + }
6623 +
6624 + function addFormLogicRow() {
6625 + /*jshint validthis:true */
6626 + var id = jQuery( this ).data( 'emailkey' ),
6627 + type = jQuery( this ).closest( '.frm_form_action_settings' ).find( '.frm_action_name' ).val(),
6628 + formId = document.getElementById( 'form_id' ).value,
6629 + logicRows = document.getElementById( 'frm_form_action_' + id ).querySelectorAll( '.frm_logic_row' );
6630 + jQuery.ajax({
6631 + type: 'POST', url: ajaxurl,
6632 + data: {
6633 + action: 'frm_add_form_logic_row',
6634 + email_id: id,
6635 + form_id: formId,
6636 + meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ),
6637 + type: type,
6638 + nonce: frmGlobal.nonce
6639 + },
6640 + success: function( html ) {
6641 + jQuery( document.getElementById( 'logic_link_' + id ) ).fadeOut( 'slow', function() {
6642 + var $logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) );
6643 + $logicRow.append( html );
6644 + $logicRow.parent( '.frm_logic_rows' ).fadeIn( 'slow' );
6645 + });
6646 + }
6647 + });
6648 + return false;
6649 + }
6650 +
6651 + function toggleSubmitLogic() {
6652 + /*jshint validthis:true */
6653 + if ( this.checked ) {
6654 + addSubmitLogic();
6655 + } else {
6656 + jQuery( '.frm_logic_row_submit' ).remove();
6657 + document.getElementById( 'frm_submit_logic_rows' ).style.display = 'none';
6658 + }
6659 + }
6660 +
6661 + /**
6662 + * Adds submit button Conditional Logic row and reveals submit button Conditional Logic
6663 + *
6664 + * @returns {boolean}
6665 + */
6666 + function addSubmitLogic() {
6667 + /*jshint validthis:true */
6668 + var formId = thisFormId,
6669 + logicRows = document.getElementById( 'frm_submit_logic_row' ).querySelectorAll( '.frm_logic_row' );
6670 + jQuery.ajax({
6671 + type: 'POST',
6672 + url: ajaxurl,
6673 + data: {
6674 + action: 'frm_add_submit_logic_row',
6675 + form_id: formId,
6676 + meta_name: getNewRowId( logicRows, 'frm_logic_submit_' ),
6677 + nonce: frmGlobal.nonce
6678 + },
6679 + success: function( html ) {
6680 + var $logicRow = jQuery( document.getElementById( 'frm_submit_logic_row' ) );
6681 + $logicRow.append( html );
6682 + $logicRow.parent( '.frm_submit_logic_rows' ).fadeIn( 'slow' );
6683 + }
6684 + });
6685 + return false;
6686 + }
6687 +
6688 + /**
6689 + * When the user selects a field for a submit condition, update corresponding options field accordingly.
6690 + */
6691 + function addSubmitLogicOpts() {
6692 + var fieldOpt = jQuery( this );
6693 + var fieldId = fieldOpt.find( ':selected' ).val();
6694 +
6695 + if ( fieldId ) {
6696 + var row = fieldOpt.data( 'row' );
6697 + frmGetFieldValues( fieldId, 'submit', row, '', 'options[submit_conditions][hide_opt][]' );
6698 + }
6699 + }
6700 +
6701 + function formatEmailSetting() {
6702 + /*jshint validthis:true */
6703 + /*var val = jQuery( this ).val();
6704 + var email = val.match( /(\s[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi );
6705 + if(email !== null && email.length) {
6706 + //has email
6707 + //TODO: add < > if they aren't there
6708 + }*/
6709 + }
6710 +
6711 + function maybeShowFormMessages() {
6712 + var header = document.getElementById( 'frm_messages_header' );
6713 + if ( showFormMessages() ) {
6714 + header.style.display = 'block';
6715 + } else {
6716 + header.style.display = 'none';
6717 + }
6718 + }
6719 +
6720 + function showFormMessages() {
6721 + var action = document.getElementById( 'success_action' );
6722 + var selectedAction = action.options[action.selectedIndex].value;
6723 + if ( selectedAction === 'message' ) {
6724 + return true;
6725 + }
6726 +
6727 + var show = false;
6728 + var editable = document.getElementById( 'editable' );
6729 + if ( editable !== null ) {
6730 + show = editable.checked && jQuery( document.getElementById( 'edit_action' ) ).val() === 'message';
6731 + if ( ! show ) {
6732 + show = isChecked( 'save_draft' );
6733 + }
6734 + }
6735 + return show;
6736 + }
6737 +
6738 + function checkDupPost() {
6739 + /*jshint validthis:true */
6740 + var postField = jQuery( 'select.frm_single_post_field' );
6741 + postField.css( 'border-color', '' );
6742 + var $t = this;
6743 + var v = jQuery( $t ).val();
6744 + if ( v === '' || v === 'checkbox' ) {
6745 + return false;
6746 + }
6747 + postField.each( function() {
6748 + if ( jQuery( this ).val() === v && this.name !== $t.name ) {
6749 + this.style.borderColor = 'red';
6750 + jQuery( $t ).val( '' );
6751 + infoModal( 'Oops. You have already used that field.' );
6752 + return false;
6753 + }
6754 + });
6755 + }
6756 +
6757 + function togglePostContent() {
6758 + /*jshint validthis:true */
6759 + var v = jQuery( this ).val();
6760 + if ( '' === v ) {
6761 + jQuery( '.frm_post_content_opt, select.frm_dyncontent_opt' ).hide().val( '' );
6762 + jQuery( '.frm_dyncontent_opt' ).hide();
6763 + } else if ( 'post_content' === v ) {
6764 + jQuery( '.frm_post_content_opt' ).show();
6765 + jQuery( '.frm_dyncontent_opt' ).hide();
6766 + jQuery( 'select.frm_dyncontent_opt' ).val( '' );
6767 + } else {
6768 + jQuery( '.frm_post_content_opt' ).hide().val( '' );
6769 + jQuery( 'select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt' ).show();
6770 + }
6771 + }
6772 +
6773 + function fillDyncontent() {
6774 + /*jshint validthis:true */
6775 + var v = jQuery( this ).val();
6776 + var $dyn = jQuery( document.getElementById( 'frm_dyncontent' ) );
6777 + if ( '' === v || 'new' === v ) {
6778 + $dyn.val( '' );
6779 + jQuery( '.frm_dyncontent_opt' ).show();
6780 + } else {
6781 + jQuery.ajax({
6782 + type: 'POST', url: ajaxurl,
6783 + data: {action: 'frm_display_get_content', id: v, nonce: frmGlobal.nonce},
6784 + success: function( val ) {
6785 + $dyn.val( val );
6786 + jQuery( '.frm_dyncontent_opt' ).show();
6787 + }
6788 + });
6789 + }
6790 + }
6791 +
6792 + function switchPostType() {
6793 + /*jshint validthis:true */
6794 + // update all rows of categories/taxonomies
6795 + var curSelect, newSelect,
6796 + catRows = document.getElementById( 'frm_posttax_rows' ).childNodes,
6797 + postParentField = document.querySelector( '.frm_post_parent_field' ),
6798 + postMenuOrderField = document.querySelector( '.frm_post_menu_order_field' ),
6799 + postType = this.value;
6800 +
6801 + // Get new category/taxonomy options
6802 + jQuery.ajax({
6803 + type: 'POST',
6804 + url: ajaxurl,
6805 + data: {
6806 + action: 'frm_replace_posttax_options',
6807 + post_type: postType,
6808 + nonce: frmGlobal.nonce
6809 + },
6810 + success: function( html ) {
6811 +
6812 + // Loop through each category row, and replace the first dropdown
6813 + for ( i = 0; i < catRows.length; i++ ) {
6814 + // Check if current element is a div
6815 + if ( catRows[i].tagName !== 'DIV' ) {
6816 + continue;
6817 + }
6818 +
6819 + // Get current category select
6820 + curSelect = catRows[i].getElementsByTagName( 'select' )[0];
6821 +
6822 + // Set up new select
6823 + newSelect = document.createElement( 'select' );
6824 + newSelect.innerHTML = html;
6825 + newSelect.className = curSelect.className;
6826 + newSelect.name = curSelect.name;
6827 +
6828 + // Replace the old select with the new select
6829 + catRows[i].replaceChild( newSelect, curSelect );
6830 + }
6831 + }
6832 + });
6833 +
6834 + // Get new post parent option.
6835 + if ( postParentField ) {
6836 + getActionOption(
6837 + postParentField,
6838 + postType,
6839 + 'frm_get_post_parent_option',
6840 + function( response, optName ) {
6841 + // The replaced string is declared in FrmProFormActionController::ajax_get_post_menu_order_option() in the pro version.
6842 + postParentField.querySelector( '.frm_post_parent_opt_wrapper' ).innerHTML = response.replaceAll( 'REPLACETHISNAME', optName );
6843 + frmDom.autocomplete.initAutocomplete( 'page', postParentField );
6844 + }
6845 + );
6846 + }
6847 +
6848 + if ( postMenuOrderField ) {
6849 + getActionOption( postMenuOrderField, postType, 'frm_should_use_post_menu_order_option' );
6850 + }
6851 + }
6852 +
6853 + function getActionOption( field, postType, action, successHandler ) {
6854 + const opt = field.querySelector( '.frm_autocomplete_value_input' ) || field.querySelector( 'select' ),
6855 + optName = opt.getAttribute( 'name' );
6856 +
6857 + jQuery.ajax({
6858 + url: ajaxurl,
6859 + method: 'POST',
6860 + data: {
6861 + action: action,
6862 + post_type: postType,
6863 + _wpnonce: frmGlobal.nonce
6864 + },
6865 + success: response => {
6866 + if ( 'string' !== typeof response ) {
6867 + console.error( response );
6868 + return;
6869 + }
6870 +
6871 + if ( '0' === response ) {
6872 + // This post type does not support this field.
6873 + field.classList.add( 'frm_hidden' );
6874 + field.value = '';
6875 + return;
6876 + }
6877 +
6878 + field.classList.remove( 'frm_hidden' );
6879 +
6880 + if ( 'function' === typeof successHandler ) {
6881 + successHandler( response, optName );
6882 + }
6883 + },
6884 + error: response => console.error( response )
6885 + });
6886 + }
6887 +
6888 + function addPosttaxRow() {
6889 + /*jshint validthis:true */
6890 + addPostRow( 'tax', this );
6891 + }
6892 +
6893 + function addPostmetaRow() {
6894 + /*jshint validthis:true */
6895 + addPostRow( 'meta', this );
6896 + }
6897 +
6898 + function addPostRow( type, button ) {
6899 + var name,
6900 + id = jQuery( 'input[name="id"]' ).val(),
6901 + settings = jQuery( button ).closest( '.frm_form_action_settings' ),
6902 + key = settings.data( 'actionkey' ),
6903 + postType = settings.find( '.frm_post_type' ).val(),
6904 + metaName = 0,
6905 + postTypeRows = document.querySelectorAll( '.frm_post' + type + '_row' );
6906 +
6907 + if ( postTypeRows.length ) {
6908 + name = postTypeRows[ postTypeRows.length - 1 ].id.replace( 'frm_post' + type + '_', '' );
6909 + if ( isNumeric( name ) ) {
6910 + metaName = 1 + parseInt( name, 10 );
6911 + } else {
6912 + metaName = 1;
6913 + }
6914 + }
6915 +
6916 + jQuery.ajax({
6917 + type: 'POST', url: ajaxurl,
6918 + data: {
6919 + action: 'frm_add_post' + type + '_row',
6920 + form_id: id,
6921 + meta_name: metaName,
6922 + tax_key: metaName,
6923 + post_type: postType,
6924 + action_key: key,
6925 + nonce: frmGlobal.nonce
6926 + },
6927 + success: function( html ) {
6928 + var cfOpts, optIndex;
6929 + jQuery( document.getElementById( 'frm_post' + type + '_rows' ) ).append( html );
6930 + jQuery( '.frm_add_post' + type + '_row.button' ).hide();
6931 +
6932 + if ( type === 'meta' ) {
6933 + jQuery( '.frm_name_value' ).show();
6934 + cfOpts = document.querySelectorAll( '.frm_toggle_cf_opts' );
6935 + for ( optIndex = 0; optIndex < cfOpts.length - 1; ++optIndex ) {
6936 + cfOpts[ optIndex ].style.display = 'none';
6937 + }
6938 + } else if ( type === 'tax' ) {
6939 + jQuery( '.frm_posttax_labels' ).show();
6940 + }
6941 + }
6942 + });
6943 + }
6944 +
6945 + function isNumeric( value ) {
6946 + return ! isNaN( parseFloat( value ) ) && isFinite( value );
6947 + }
6948 +
6949 + function getMetaValue( id, metaName ) {
6950 + var newMeta = metaName;
6951 + if ( jQuery( document.getElementById( id + metaName ) ).length > 0 ) {
6952 + newMeta = getMetaValue( id, metaName + 1 );
6953 + }
6954 + return newMeta;
6955 + }
6956 +
6957 + function changePosttaxRow() {
6958 + /*jshint validthis:true */
6959 + if ( ! jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).length ) {
6960 + return;
6961 + }
6962 +
6963 + jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).html( '<div class="spinner frm_spinner" style="display:block"></div>' );
6964 +
6965 + var postType = jQuery( this ).closest( '.frm_form_action_settings' ).find( 'select[name$="[post_content][post_type]"]' ).val(),
6966 + actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ),
6967 + taxKey = jQuery( this ).closest( '.frm_posttax_row' ).attr( 'id' ).replace( 'frm_posttax_', '' ),
6968 + metaName = jQuery( this ).val(),
6969 + showExclude = jQuery( document.getElementById( taxKey + '_show_exclude' ) ).is( ':checked' ) ? 1 : 0,
6970 + fieldId = jQuery( 'select[name$="[post_category][' + taxKey + '][field_id]"]' ).val(),
6971 + id = jQuery( 'input[name="id"]' ).val();
6972 +
6973 + jQuery.ajax({
6974 + type: 'POST',
6975 + url: ajaxurl,
6976 + data: {
6977 + action: 'frm_add_posttax_row',
6978 + form_id: id,
6979 + post_type: postType,
6980 + tax_key: taxKey,
6981 + action_key: actionKey,
6982 + meta_name: metaName,
6983 + field_id: fieldId,
6984 + show_exclude: showExclude,
6985 + nonce: frmGlobal.nonce
6986 + },
6987 + success: function( html ) {
6988 + var $tax = jQuery( document.getElementById( 'frm_posttax_' + taxKey ) );
6989 + $tax.replaceWith( html );
6990 + }
6991 + });
6992 + }
6993 +
6994 + function toggleCfOpts() {
6995 + /*jshint validthis:true */
6996 + var row = jQuery( this ).closest( '.frm_postmeta_row' );
6997 + var cancel = row.find( '.frm_cancelnew' );
6998 + var select = row.find( '.frm_enternew' );
6999 + if ( row.find( 'select.frm_cancelnew' ).is( ':visible' ) ) {
7000 + cancel.hide();
7001 + select.show();
7002 + } else {
7003 + cancel.show();
7004 + select.hide();
7005 + }
7006 +
7007 + row.find( 'input.frm_enternew, select.frm_cancelnew' ).val( '' );
7008 + return false;
7009 + }
7010 +
7011 + function toggleFormOpts() {
7012 + /*jshint validthis:true */
7013 + var changedOpt = jQuery( this );
7014 + var val = changedOpt.val();
7015 + if ( changedOpt.attr( 'type' ) === 'checkbox' ) {
7016 + if ( this.checked === false ) {
7017 + val = '';
7018 + }
7019 + }
7020 +
7021 + var toggleClass = changedOpt.data( 'toggleclass' );
7022 + if ( val === '' ) {
7023 + jQuery( '.' + toggleClass ).hide();
7024 + } else {
7025 + jQuery( '.' + toggleClass ).show();
7026 + jQuery( '.hide_' + toggleClass + '_' + val ).hide();
7027 + }
7028 + }
7029 +
7030 + function submitSettings() {
7031 + /*jshint validthis:true */
7032 + preFormSave( this );
7033 + triggerSubmit( document.querySelector( '.frm_form_settings' ) );
7034 + }
7035 +
7036 + /* View Functions */
7037 + function showCount() {
7038 + /*jshint validthis:true */
7039 + var value = jQuery( this ).val();
7040 +
7041 + var $cont = document.getElementById( 'date_select_container' );
7042 + var tab = document.getElementById( 'frm_listing_tab' );
7043 + var label = tab.getAttribute( 'data-label' );
7044 + if ( value === 'calendar' ) {
7045 + jQuery( '.hide_dyncontent, .hide_single_content' ).removeClass( 'frm_hidden' );
7046 + jQuery( '.limit_container' ).addClass( 'frm_hidden' );
7047 + $cont.style.display = 'block';
7048 + } else if ( value === 'dynamic' ) {
7049 + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).removeClass( 'frm_hidden' );
7050 + } else if ( value === 'one' ) {
7051 + label = tab.getAttribute( 'data-one' );
7052 + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).addClass( 'frm_hidden' );
7053 + } else {
7054 + jQuery( '.hide_dyncontent' ).addClass( 'frm_hidden' );
7055 + jQuery( '.limit_container, .hide_single_content' ).removeClass( 'frm_hidden' );
7056 + }
7057 +
7058 + if ( value !== 'calendar' ) {
7059 + $cont.style.display = 'none';
7060 + }
7061 + tab.innerHTML = label;
7062 + }
7063 +
7064 + function displayFormSelected() {
7065 + /*jshint validthis:true */
7066 + var formId = jQuery( this ).val();
7067 + thisFormId = formId; // set the global form id
7068 + if ( formId === '' ) {
7069 + return;
7070 + }
7071 +
7072 + jQuery.ajax({
7073 + type: 'POST',
7074 + url: ajaxurl,
7075 + data: {
7076 + action: 'frm_get_cd_tags_box',
7077 + form_id: formId,
7078 + nonce: frmGlobal.nonce
7079 + },
7080 + success: function( html ) {
7081 + jQuery( '#frm_adv_info .categorydiv' ).html( html );
7082 + }
7083 + });
7084 +
7085 + jQuery.ajax({
7086 + type: 'POST',
7087 + url: ajaxurl,
7088 + data: {
7089 + action: 'frm_get_date_field_select',
7090 + form_id: formId,
7091 + nonce: frmGlobal.nonce
7092 + },
7093 + success: function( html ) {
7094 + jQuery( document.getElementById( 'date_select_container' ) ).html( html );
7095 + }
7096 + });
7097 + }
7098 +
7099 + function clickTabsAfterAjax() {
7100 + /*jshint validthis:true */
7101 + var t = jQuery( this ).attr( 'href' );
7102 + jQuery( this ).parent().addClass( 'tabs' ).siblings( 'li' ).removeClass( 'tabs' );
7103 + jQuery( t ).show().siblings( '.tabs-panel' ).hide();
7104 + return false;
7105 + }
7106 +
7107 + function clickContentTab() {
7108 + /*jshint validthis:true */
7109 + link = jQuery( this );
7110 + var t = link.attr( 'href' );
7111 + if ( typeof t === 'undefined' ) {
7112 + return false;
7113 + }
7114 +
7115 + var c = t.replace( '#', '.' );
7116 + link.closest( '.nav-tab-wrapper' ).find( 'a' ).removeClass( 'nav-tab-active' );
7117 + link.addClass( 'nav-tab-active' );
7118 + jQuery( '.nav-menu-content' ).not( t ).not( c ).hide();
7119 + jQuery( t + ',' + c ).show();
7120 +
7121 + return false;
7122 + }
7123 +
7124 + function addOrderRow() {
7125 + var logicRows = document.getElementById( 'frm_order_options' ).querySelectorAll( '.frm_logic_rows div' );
7126 + jQuery.ajax({
7127 + type: 'POST',
7128 + url: ajaxurl,
7129 + data: {
7130 + action: 'frm_add_order_row',
7131 + form_id: thisFormId,
7132 + order_key: getNewRowId( logicRows, 'frm_order_field_', 1 ),
7133 + nonce: frmGlobal.nonce
7134 + },
7135 + success: function( html ) {
7136 + jQuery( '#frm_order_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_order_row' ).hide();
7137 + }
7138 + });
7139 + }
7140 +
7141 + function addWhereRow() {
7142 + var rowDivs = document.getElementById( 'frm_where_options' ).querySelectorAll( '.frm_logic_rows div' );
7143 + jQuery.ajax({
7144 + type: 'POST',
7145 + url: ajaxurl,
7146 + data: {
7147 + action: 'frm_add_where_row',
7148 + form_id: thisFormId,
7149 + where_key: getNewRowId( rowDivs, 'frm_where_field_', 1 ),
7150 + nonce: frmGlobal.nonce
7151 + },
7152 + success: function( html ) {
7153 + jQuery( '#frm_where_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_where_row' ).hide();
7154 + }
7155 + });
7156 + }
7157 +
7158 + function insertWhereOptions() {
7159 + /*jshint validthis:true */
7160 + var value = this.value,
7161 + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' );
7162 +
7163 + jQuery.ajax({
7164 + type: 'POST',
7165 + url: ajaxurl,
7166 + data: {
7167 + action: 'frm_add_where_options',
7168 + where_key: whereKey,
7169 + field_id: value,
7170 + nonce: frmGlobal.nonce
7171 + },
7172 + success: function( html ) {
7173 + jQuery( document.getElementById( 'where_field_options_' + whereKey ) ).html( html );
7174 + }
7175 + });
7176 + }
7177 +
7178 + function hideWhereOptions() {
7179 + /*jshint validthis:true */
7180 + var value = this.value,
7181 + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' );
7182 +
7183 + if ( value === 'group_by' || value === 'group_by_newest' ) {
7184 + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'none';
7185 + } else {
7186 + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'inline-block';
7187 + }
7188 + }
7189 +
7190 + function setDefaultPostStatus() {
7191 + var urlQuery = window.location.search.substring( 1 );
7192 + if ( urlQuery.indexOf( 'action=edit' ) === -1 ) {
7193 + document.getElementById( 'post-visibility-display' ).innerHTML = frm_admin_js.private_label;
7194 + document.getElementById( 'hidden-post-visibility' ).value = 'private';
7195 + document.getElementById( 'visibility-radio-private' ).checked = true;
7196 + }
7197 + }
7198 +
7199 + /* Customization Panel */
7200 + function insertCode( e ) {
7201 + /*jshint validthis:true */
7202 + e.preventDefault();
7203 + insertFieldCode( jQuery( this ), this.getAttribute( 'data-code' ) );
7204 + return false;
7205 + }
7206 +
7207 + function insertFieldCode( element, variable ) {
7208 + var rich = false,
7209 + elementId = element;
7210 + if ( typeof element === 'object' ) {
7211 + if ( element.hasClass( 'frm_noallow' ) ) {
7212 + return;
7213 + }
7214 +
7215 + elementId = jQuery( element ).closest( '[data-fills]' ).attr( 'data-fills' );
7216 + if ( typeof elementId === 'undefined' ) {
7217 + elementId = element.closest( 'div' ).attr( 'class' );
7218 + if ( typeof elementId !== 'undefined' ) {
7219 + elementId = elementId.split( ' ' )[1];
7220 + }
7221 + }
7222 + }
7223 +
7224 + if ( typeof elementId === 'undefined' ) {
7225 + var active = document.activeElement;
7226 + if ( active.type === 'search' ) {
7227 + // If the search field has focus, find the correct field.
7228 + elementId = active.id.replace( '-search-input', '' );
7229 + if ( elementId.match( /\d/gi ) === null ) {
7230 + active = jQuery( '.frm-single-settings:visible .' + elementId );
7231 + elementId = active.attr( 'id' );
7232 + }
7233 + } else {
7234 + elementId = active.id;
7235 + }
7236 + }
7237 +
7238 + if ( elementId ) {
7239 + rich = jQuery( '#wp-' + elementId + '-wrap.wp-editor-wrap' ).length > 0;
7240 + }
7241 +
7242 + var contentBox = jQuery( document.getElementById( elementId ) );
7243 + if ( typeof element.attr( 'data-shortcode' ) === 'undefined' && ( ! contentBox.length || typeof contentBox.attr( 'data-shortcode' ) === 'undefined' ) ) {
7244 + // this helps to exclude those that don't want shortcode-like inserted content e.g. frm-pro's summary field
7245 + var doShortcode = element.parents( 'ul.frm_code_list' ).attr( 'data-shortcode' );
7246 + if ( doShortcode === 'undefined' || doShortcode !== 'no' ) {
7247 + variable = '[' + variable + ']';
7248 + }
7249 + }
7250 +
7251 + if ( rich ) {
7252 + wpActiveEditor = elementId;
7253 + }
7254 +
7255 + if ( ! contentBox.length ) {
7256 + return false;
7257 + }
7258 +
7259 + if ( variable === '[default-html]' || variable === '[default-plain]' ) {
7260 + var p = 0;
7261 + if ( variable === '[default-plain]' ) {
7262 + p = 1;
7263 + }
7264 + jQuery.ajax({
7265 + type: 'POST', url: ajaxurl,
7266 + data: {
7267 + action: 'frm_get_default_html',
7268 + form_id: jQuery( 'input[name="id"]' ).val(),
7269 + plain_text: p,
7270 + nonce: frmGlobal.nonce
7271 + },
7272 + elementId: elementId,
7273 + success: function( msg ) {
7274 + if ( rich ) {
7275 + let p = document.createElement( 'p' );
7276 + p.innerText = msg;
7277 + send_to_editor( p.innerHTML );
7278 + } else {
7279 + insertContent( contentBox, msg );
7280 + }
7281 + }
7282 + });
7283 + } else {
7284 + variable = maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox );
7285 + if ( rich ) {
7286 + send_to_editor( variable );
7287 + } else {
7288 + insertContent( contentBox, variable );
7289 + }
7290 + }
7291 + return false;
7292 + }
7293 +
7294 + function maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox ) {
7295 + if ( 'object' !== typeof element || ! ( element instanceof jQuery ) || 'success_url' !== contentBox[0].id ) {
7296 + return variable;
7297 + }
7298 +
7299 + element = element[0];
7300 + if ( ! element.closest( '#frm-insert-fields-box' ) ) {
7301 + // Only add sanitize_url=1 to field shortcodes.
7302 + return variable;
7303 + }
7304 +
7305 + if ( ! element.parentNode.classList.contains( 'frm_insert_url' ) ) {
7306 + variable = variable.replace( ']', ' sanitize_url=1]' );
7307 + }
7308 +
7309 + return variable;
7310 + }
7311 +
7312 + function insertContent( contentBox, variable ) {
7313 + if ( document.selection ) {
7314 + contentBox[0].focus();
7315 + document.selection.createRange().text = variable;
7316 + } else {
7317 + obj = contentBox[0];
7318 + var e = obj.selectionEnd;
7319 +
7320 + variable = maybeFormatInsertedContent( contentBox, variable, obj.selectionStart, e );
7321 +
7322 + obj.value = obj.value.substr( 0, obj.selectionStart ) + variable + obj.value.substr( obj.selectionEnd, obj.value.length );
7323 + var s = e + variable.length;
7324 + obj.focus();
7325 + obj.setSelectionRange( s, s );
7326 + }
7327 + triggerChange( contentBox );
7328 + }
7329 +
7330 + function maybeFormatInsertedContent( input, textToInsert, selectionStart, selectionEnd ) {
7331 + var separator = input.data( 'sep' );
7332 + if ( undefined === separator ) {
7333 + return textToInsert;
7334 + }
7335 +
7336 + var value = input.val();
7337 +
7338 + if ( ! value.trim().length ) {
7339 + return textToInsert;
7340 + }
7341 +
7342 + var startPattern = new RegExp( separator + '\\s*$' );
7343 + var endPattern = new RegExp( '^\\s*' + separator );
7344 +
7345 + if ( value.substr( 0, selectionStart ).trim().length && false === startPattern.test( value.substr( 0, selectionStart ) ) ) {
7346 + textToInsert = separator + textToInsert;
7347 + }
7348 +
7349 + if ( value.substr( selectionEnd, value.length ).trim().length && false === endPattern.test( value.substr( selectionEnd, value.length ) ) ) {
7350 + textToInsert += separator;
7351 + }
7352 +
7353 + return textToInsert;
7354 + }
7355 +
7356 + function resetLogicBuilder() {
7357 + /*jshint validthis:true */
7358 + var id = document.getElementById( 'frm-id-condition' ),
7359 + key = document.getElementById( 'frm-key-condition' );
7360 +
7361 + if ( this.checked ) {
7362 + id.classList.remove( 'frm_hidden' );
7363 + key.classList.add( 'frm_hidden' );
7364 + triggerEvent( key, 'change' );
7365 + } else {
7366 + id.classList.add( 'frm_hidden' );
7367 + key.classList.remove( 'frm_hidden' );
7368 + triggerEvent( id, 'change' );
7369 + }
7370 + }
7371 +
7372 + function setLogicExample() {
7373 + var field, code,
7374 + idKey = document.getElementById( 'frm-id-key-condition' ).checked ? 'frm-id-condition' : 'frm-key-condition',
7375 + is = document.getElementById( 'frm-is-condition' ).value,
7376 + text = document.getElementById( 'frm-text-condition' ).value,
7377 + result = document.getElementById( 'frm-insert-condition' );
7378 +
7379 + idKey = document.getElementById( idKey );
7380 + field = idKey.options[idKey.selectedIndex].value;
7381 + code = 'if ' + field + ' ' + is + '="' + text + '"]';
7382 + result.setAttribute( 'data-code', code + frm_admin_js.conditional_text + '[/if ' + field );
7383 + result.innerHTML = '[' + code + '[/if ' + field + ']';
7384 + }
7385 +
7386 + function showBuilderModal() {
7387 + /*jshint validthis:true */
7388 + var moreIcon = getIconForInput( this );
7389 + showInlineModal( moreIcon, this );
7390 + }
7391 +
7392 + function maybeShowModal( input ) {
7393 + var moreIcon;
7394 + if ( input.parentNode.parentNode.classList.contains( 'frm_has_shortcodes' ) ) {
7395 + hideShortcodes();
7396 + moreIcon = getIconForInput( input );
7397 + if ( moreIcon.tagName === 'use' ) {
7398 + moreIcon = moreIcon.firstElementChild;
7399 + if ( moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ).indexOf( 'frm_close_icon' ) === -1 ) {
7400 + showShortcodeBox( moreIcon, 'nofocus' );
7401 + }
7402 + } else if ( ! moreIcon.classList.contains( 'frm_close_icon' ) ) {
7403 + showShortcodeBox( moreIcon, 'nofocus' );
7404 + }
7405 + }
7406 + }
7407 +
7408 + function showShortcodes( e ) {
7409 + /*jshint validthis:true */
7410 + e.preventDefault();
7411 + e.stopPropagation();
7412 +
7413 + showShortcodeBox( this );
7414 + }
7415 +
7416 + function showShortcodeBox( moreIcon, shouldFocus ) {
7417 + var pos = moreIcon.getBoundingClientRect(),
7418 + input = getInputForIcon( moreIcon ),
7419 + box = document.getElementById( 'frm_adv_info' ),
7420 + classes = moreIcon.className,
7421 + parentPos = box.parentElement.getBoundingClientRect();
7422 +
7423 + if ( moreIcon.tagName === 'svg' ) {
7424 + moreIcon = moreIcon.firstElementChild;
7425 + }
7426 + if ( moreIcon.tagName === 'use' ) {
7427 + classes = moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' );
7428 + }
7429 +
7430 + if ( classes.indexOf( 'frm_close_icon' ) !== -1 ) {
7431 + hideShortcodes( box );
7432 + } else {
7433 + box.style.top = ( pos.top - parentPos.top + 32 ) + 'px';
7434 + box.style.left = ( pos.left - parentPos.left - 257 ) + 'px';
7435 +
7436 + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' );
7437 + if ( input.classList.contains( 'frm_not_email_to' ) ) {
7438 + jQuery( '#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a' ).addClass( 'frm_noallow' );
7439 + } else if ( input.classList.contains( 'frm_not_email_subject' ) ) {
7440 + jQuery( '.frm_code_list li.hide_frm_not_email_subject a' ).addClass( 'frm_noallow' );
7441 + }
7442 +
7443 + box.setAttribute( 'data-fills', input.id );
7444 + box.style.display = 'block';
7445 +
7446 + if ( moreIcon.tagName === 'use' ) {
7447 + moreIcon.setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_close_icon' );
7448 + } else {
7449 + moreIcon.className = classes.replace( 'frm_more_horiz_solid_icon', 'frm_close_icon' );
7450 + }
7451 +
7452 + if ( shouldFocus !== 'nofocus' ) {
7453 + if ( 'none' !== input.style.display ) {
7454 + input.focus();
7455 + } else {
7456 + jQuery( tinymce.get( input.id ) ).trigger( 'focus' );
7457 + }
7458 + }
7459 + }
7460 + }
7461 +
7462 + function fieldUpdated() {
7463 + if ( ! fieldsUpdated ) {
7464 + fieldsUpdated = 1;
7465 + window.addEventListener( 'beforeunload', confirmExit );
7466 + }
7467 + }
7468 +
7469 + function buildSubmittedNoAjax() {
7470 + // set fieldsUpdated to 0 to avoid the unsaved changes pop up
7471 + fieldsUpdated = 0;
7472 + }
7473 +
7474 + function settingsSubmitted() {
7475 + // set fieldsUpdated to 0 to avoid the unsaved changes pop up
7476 + fieldsUpdated = 0;
7477 + }
7478 +
7479 + function saveAndReloadSettings() {
7480 + var page, form;
7481 + page = document.getElementById( 'form_settings_page' );
7482 + if ( null !== page ) {
7483 + form = page.querySelector( 'form.frm_form_settings' );
7484 + if ( null !== form ) {
7485 + fieldsUpdated = 0;
7486 + form.submit();
7487 + }
7488 + }
7489 + }
7490 +
7491 + function saveAndReloadFormBuilder() {
7492 + document.getElementById( 'frm_submit_side_top' ).click();
7493 + }
7494 +
7495 + function confirmExit( event ) {
7496 + if ( fieldsUpdated ) {
7497 + event.preventDefault();
7498 + event.returnValue = '';
7499 + }
7500 + }
7501 +
7502 + function bindClickForDialogClose( $modal ) {
7503 + const closeModal = function() {
7504 + $modal.dialog( 'close' );
7505 + };
7506 + jQuery( '.ui-widget-overlay' ).on( 'click', closeModal );
7507 + $modal.on( 'click', 'a.dismiss', closeModal );
7508 + }
7509 +
7510 + function triggerNewFormModal( event ) {
7511 + var $modal,
7512 + dismiss = document.getElementById( 'frm_new_form_modal' ).querySelector( 'a.dismiss' );
7513 +
7514 + if ( typeof event !== 'undefined' ) {
7515 + event.preventDefault();
7516 + }
7517 +
7518 + dismiss.setAttribute( 'tabindex', -1 );
7519 +
7520 + $modal = initModal( '#frm_new_form_modal', '600px' );
7521 + offsetModalY( $modal, '50px' );
7522 + $modal.attr( 'frm-page', 'create' );
7523 + $modal.find( '#template-search-input' ).val( '' ).trigger( 'change' );
7524 + $modal.dialog( 'open' );
7525 +
7526 + dismiss.removeAttribute( 'tabindex' );
7527 + bindClickForDialogClose( $modal );
7528 +
7529 + addApplicationsToNewFormModal( $modal.get( 0 ) );
7530 + }
7531 +
7532 + function addApplicationsToNewFormModal( modal ) {
7533 + if ( modal.querySelector( '.frm-ready-made-solution' ) ) {
7534 + // Avoid adding duplicates if the modal is opened multiple times.
7535 + return;
7536 + }
7537 +
7538 + if ( ! frmGlobal.canAccessApplicationDashboard ) {
7539 + // User does not have privileges to see Ready Made Solutions.
7540 + return;
7541 + }
7542 +
7543 + doJsonFetch( 'get_applications_data&view=templates' ).then( addTemplatesOnFetchSuccess );
7544 +
7545 + const categoryList = modal.querySelector( 'ul.frm-categories-list' );
7546 +
7547 + function addTemplatesOnFetchSuccess( data ) {
7548 + data.templates.forEach( addTemplateToCategoryList );
7549 + }
7550 +
7551 + function addTemplateToCategoryList( template ) {
7552 + categoryList.insertBefore( getReadyMadeSolution( template ), categoryList.firstChild );
7553 + }
7554 +
7555 + function getReadyMadeSolution( template ) {
7556 + const image = tag( 'img' );
7557 + const thumbnailFolderUrl = frmGlobal.url + '/images/applications/thumbnails/';
7558 + const filenameToUse = template.hasLiteThumbnail ? template.key + '.png' : 'placeholder.svg';
7559 + image.setAttribute( 'src', thumbnailFolderUrl + filenameToUse );
7560 +
7561 + const imageWrapper = div({ child: image });
7562 + imageWrapper.style.textAlign = 'center';
7563 +
7564 + return tag(
7565 + 'li',
7566 + {
7567 + className: 'frm-searchable-template frm-ready-made-solution',
7568 + children: [
7569 + imageWrapper,
7570 + div({
7571 + children: [
7572 + span( __( 'Ready Made Solution', 'formidable' ) ),
7573 + tag( 'h3', template.name ),
7574 + a({
7575 + text: __( 'Check all applications', 'formidable' ),
7576 + href: frmGlobal.applicationsUrl
7577 + })
7578 + ]
7579 + }),
7580 + div({
7581 + className: 'frm-hover-icons',
7582 + child: a({
7583 + child: svg({ href: '#frm_plus_icon' }),
7584 + href: frmGlobal.applicationsUrl + '&triggerViewApplicationModal=1&template=' + template.key
7585 + })
7586 + })
7587 + ]
7588 + }
7589 + );
7590 + }
7591 + }
7592 +
7593 + function offsetModalY( $modal, amount ) {
7594 + const position = {
7595 + my: 'top',
7596 + at: 'top+' + amount,
7597 + of: window
7598 + };
7599 + $modal.dialog( 'option', 'position', position );
7600 + }
7601 +
7602 + /**
7603 + * Get the input box for the selected ... icon.
7604 + */
7605 + function getInputForIcon( moreIcon ) {
7606 + var input = moreIcon.nextElementSibling;
7607 +
7608 + while ( input !== null && input.tagName !== 'INPUT' && input.tagName !== 'TEXTAREA' ) {
7609 + input = getInputForIcon( input );
7610 + }
7611 +
7612 + return input;
7613 + }
7614 +
7615 + /**
7616 + * Get the ... icon for the selected input box.
7617 + */
7618 + function getIconForInput( input ) {
7619 + var moreIcon = input.previousElementSibling;
7620 +
7621 + while ( moreIcon !== null && moreIcon.tagName !== 'I' && moreIcon.tagName !== 'svg' ) {
7622 + moreIcon = getIconForInput( moreIcon );
7623 + }
7624 +
7625 + return moreIcon;
7626 + }
7627 +
7628 + function hideShortcodes( box ) {
7629 + var i, u, closeIcons, closeSvg;
7630 + if ( typeof box === 'undefined' ) {
7631 + box = document.getElementById( 'frm_adv_info' );
7632 + if ( box === null ) {
7633 + return;
7634 + }
7635 + }
7636 +
7637 + if ( document.getElementById( 'frm_dyncontent' ) !== null ) {
7638 + // Don't run when in the sidebar.
7639 + return;
7640 + }
7641 +
7642 + box.style.display = 'none';
7643 +
7644 + closeIcons = document.querySelectorAll( '.frm-show-box.frm_close_icon' );
7645 + for ( i = 0; i < closeIcons.length; i++ ) {
7646 + closeIcons[i].classList.remove( 'frm_close_icon' );
7647 + closeIcons[i].classList.add( 'frm_more_horiz_solid_icon' );
7648 + }
7649 +
7650 + closeSvg = document.querySelectorAll( '.frm_has_shortcodes use' );
7651 + for ( u = 0; u < closeSvg.length; u++ ) {
7652 + if ( closeSvg[u].getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) === '#frm_close_icon' ) {
7653 + closeSvg[u].setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_more_horiz_solid_icon' );
7654 + }
7655 + }
7656 + }
7657 +
7658 + function initToggleShortcodes() {
7659 + if ( typeof tinymce !== 'object' ) {
7660 + return;
7661 + }
7662 +
7663 + DOM = tinymce.DOM;
7664 + if ( typeof DOM.events !== 'undefined' && typeof DOM.events.add !== 'undefined' ) {
7665 + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseover', function() {
7666 + if ( jQuery( '*:focus' ).length > 0 ) {
7667 + return;
7668 + }
7669 + if ( this.id ) {
7670 + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7671 + }
7672 + });
7673 + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseout', function() {
7674 + if ( jQuery( '*:focus' ).length > 0 ) {
7675 + return;
7676 + }
7677 + if ( this.id ) {
7678 + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7679 + }
7680 + });
7681 + } else {
7682 + jQuery( '#frm_dyncontent' ).on( 'mouseover mouseout', '.wp-editor-wrap', function() {
7683 + if ( jQuery( '*:focus' ).length > 0 ) {
7684 + return;
7685 + }
7686 + if ( this.id ) {
7687 + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7688 + }
7689 + });
7690 + }
7691 + }
7692 +
7693 + function toggleAllowedShortcodes( id ) {
7694 + var c, clickedID;
7695 + if ( typeof id === 'undefined' ) {
7696 + id = '';
7697 + }
7698 + c = id;
7699 +
7700 + if ( id.indexOf( '-search-input' ) !== -1 ) {
7701 + return;
7702 + }
7703 +
7704 + if ( id !== '' ) {
7705 + var $ele = jQuery( document.getElementById( id ) );
7706 + if ( $ele.attr( 'class' ) && id !== 'wpbody-content' && id !== 'content' && id !== 'dyncontent' && id !== 'success_msg' ) {
7707 + var d = $ele.attr( 'class' ).split( ' ' )[0];
7708 + if ( d === 'frm_long_input' || d === 'frm_98_width' || typeof d === 'undefined' ) {
7709 + d = '';
7710 + } else {
7711 + id = d.trim();
7712 + }
7713 + c = c + ' ' + d;
7714 + c = c.replace( 'widefat', '' ).replace( 'frm_with_left_label', '' );
7715 + }
7716 + }
7717 +
7718 + jQuery( '#frm-insert-fields-box,#frm-conditionals,#frm-adv-info-tab,#frm-dynamic-values' ).attr( 'data-fills', c.trim() );
7719 + var a = [
7720 + 'content', 'wpbody-content', 'dyncontent', 'success_url',
7721 + 'success_msg', 'edit_msg', 'frm_dyncontent', 'frm_not_email_message',
7722 + 'frm_not_email_subject'
7723 + ];
7724 + var b = [
7725 + 'before_content', 'after_content', 'frm_not_email_to',
7726 + 'dyn_default_value'
7727 + ];
7728 +
7729 + if ( jQuery.inArray( id, a ) >= 0 ) {
7730 + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' );
7731 + jQuery( '.frm_code_list a.hide_' + id ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7732 + } else if ( jQuery.inArray( id, b ) >= 0 ) {
7733 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a:not(.show_' + id + ')' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7734 + jQuery( '.frm_code_list a.show_' + id ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' );
7735 + } else {
7736 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7737 + }
7738 +
7739 + // Automatically select a tab.
7740 + if ( id === 'dyn_default_value' ) {
7741 + clickedID = 'frm_dynamic_values';
7742 + document.getElementById( clickedID + '_tab' ).click();
7743 + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_inactive' ).addClass( 'frm_hidden' );
7744 + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_active' ).removeClass( 'frm_hidden' );
7745 + }
7746 + }
7747 +
7748 + function toggleAllowedHTML( input ) {
7749 + var b,
7750 + id = input.id;
7751 + if ( typeof id === 'undefined' || id.indexOf( '-search-input' ) !== -1 ) {
7752 + return;
7753 + }
7754 +
7755 + jQuery( '#frm-adv-info-tab' ).attr( 'data-fills', id.trim() );
7756 + if ( input.classList.contains( 'field_custom_html' ) ) {
7757 + id = 'field_custom_html';
7758 + }
7759 +
7760 + b = [ 'after_html', 'before_html', 'submit_html', 'field_custom_html' ];
7761 + if ( jQuery.inArray( id, b ) >= 0 ) {
7762 + jQuery( '.frm_code_list li:not(.show_' + id + ')' ).addClass( 'frm_hidden' );
7763 + jQuery( '.frm_code_list li.show_' + id ).removeClass( 'frm_hidden' );
7764 + }
7765 + }
7766 +
7767 + function toggleKeyID( switchTo, e ) {
7768 + e.stopPropagation();
7769 + jQuery( '.frm_code_list .frmids, .frm_code_list .frmkeys' ).addClass( 'frm_hidden' );
7770 + jQuery( '.frm_code_list .' + switchTo ).removeClass( 'frm_hidden' );
7771 + jQuery( '.frmids, .frmkeys' ).removeClass( 'current' );
7772 + jQuery( '.' + switchTo ).addClass( 'current' );
7773 + }
7774 +
7775 + function onActionLoaded( event ) {
7776 + const settings = event.target.closest( '.frm_form_action_settings' );
7777 + if ( settings && settings.classList.contains( 'frm_single_email_settings' ) ) {
7778 + onEmailActionLoaded( settings );
7779 + }
7780 + }
7781 +
7782 + function onEmailActionLoaded( settings ) {
7783 + const wysiwyg = settings.querySelector( '.wp-editor-area' );
7784 + if ( wysiwyg ) {
7785 + frmDom.wysiwyg.init(
7786 + wysiwyg, { height: 160, addFocusEvents: true }
7787 + );
7788 + }
7789 + }
7790 +
7791 + /* Styling */
7792 + function setPosClass() {
7793 + /*jshint validthis:true */
7794 + var value = this.value;
7795 + if ( value === 'none' ) {
7796 + value = 'top';
7797 + } else if ( value === 'no_label' ) {
7798 + value = 'none';
7799 + }
7800 +
7801 + document.querySelectorAll( '.frm_pos_container' ).forEach( container => {
7802 + // Fields that support floating label should have a directly child input/textarea/select.
7803 + const input = container.querySelector( ':scope > input, :scope > select, :scope > textarea' );
7804 +
7805 + if ( 'inside' === value && ! input ) {
7806 + value = 'top';
7807 + }
7808 +
7809 + container.classList.remove( 'frm_top_container', 'frm_left_container', 'frm_right_container', 'frm_none_container', 'frm_inside_container' );
7810 + container.classList.add( 'frm_' + value + '_container' );
7811 +
7812 + if ( 'inside' === value ) {
7813 + checkFloatingLabelsForStyles( input, container );
7814 + }
7815 + });
7816 + }
7817 +
7818 + function checkFloatingLabelsForStyles( input, container ) {
7819 + if ( ! container ) {
7820 + container = input.closest( '.frm_inside_container' );
7821 + }
7822 +
7823 + const shouldFloatTop = input.value || document.activeElement === input;
7824 +
7825 + container.classList.toggle( 'frm_label_float_top', shouldFloatTop );
7826 +
7827 + if ( 'SELECT' === input.tagName ) {
7828 + const firstOpt = input.querySelector( 'option:first-child' );
7829 +
7830 + if ( shouldFloatTop ) {
7831 + if ( firstOpt.hasAttribute( 'data-label' ) ) {
7832 + firstOpt.textContent = firstOpt.getAttribute( 'data-label' );
7833 + firstOpt.removeAttribute( 'data-label' );
7834 + }
7835 + } else {
7836 + if ( firstOpt.textContent ) {
7837 + firstOpt.setAttribute( 'data-label', firstOpt.textContent );
7838 + firstOpt.textContent = '';
7839 + }
7840 + }
7841 + }
7842 + }
7843 +
7844 + function collapseAllSections() {
7845 + jQuery( '.control-section.accordion-section.open' ).removeClass( 'open' );
7846 + }
7847 +
7848 + function textSquishCheck() {
7849 + var size = document.getElementById( 'frm_field_font_size' ).value.replace( /\D/g, '' );
7850 + var height = document.getElementById( 'frm_field_height' ).value.replace( /\D/g, '' );
7851 + var paddingEntered = document.getElementById( 'frm_field_pad' ).value.split( ' ' );
7852 + var paddingCount = paddingEntered.length;
7853 +
7854 + // If too many or too few padding entries, leave now
7855 + if ( paddingCount === 0 || paddingCount > 4 || height === '' ) {
7856 + return;
7857 + }
7858 +
7859 + // Get the top and bottom padding from entered values
7860 + var paddingTop = paddingEntered[0].replace( /\D/g, '' );
7861 + var paddingBottom = paddingTop;
7862 + if ( paddingCount >= 3 ) {
7863 + paddingBottom = paddingEntered[2].replace( /\D/g, '' );
7864 + }
7865 +
7866 + // Check if there is enough space for text
7867 + var textSpace = height - size - paddingTop - paddingBottom - 3;
7868 + if ( textSpace < 0 ) {
7869 + infoModal( frm_admin_js.css_invalid_size );
7870 + }
7871 + }
7872 +
7873 + /* Global settings page */
7874 + function loadSettingsTab( anchor ) {
7875 + var holder = anchor.replace( '#', '' );
7876 + var holderContainer = jQuery( '.frm_' + holder + '_ajax' );
7877 + if ( holderContainer.length ) {
7878 + jQuery.ajax({
7879 + type: 'POST', url: ajaxurl,
7880 + data: {
7881 + 'action': 'frm_settings_tab',
7882 + 'tab': holder.replace( '_settings', '' ),
7883 + 'nonce': frmGlobal.nonce
7884 + },
7885 + success: function( html ) {
7886 + holderContainer.replaceWith( html );
7887 + }
7888 + });
7889 + }
7890 + }
7891 +
7892 + function uninstallNow() {
7893 + /*jshint validthis:true */
7894 + if ( confirmLinkClick( this ) === true ) {
7895 + jQuery( '.frm_uninstall .frm-wait' ).css( 'visibility', 'visible' );
7896 + jQuery.ajax({
7897 + type: 'POST',
7898 + url: ajaxurl,
7899 + data: 'action=frm_uninstall&nonce=' + frmGlobal.nonce,
7900 + success: function( msg ) {
7901 + jQuery( '.frm_uninstall' ).fadeOut( 'slow' );
7902 + window.location = msg;
7903 + }
7904 + });
7905 + }
7906 + return false;
7907 + }
7908 +
7909 + function saveAddonLicense() {
7910 + /*jshint validthis:true */
7911 + var button = jQuery( this );
7912 + var buttonName = this.name;
7913 + var pluginSlug = this.getAttribute( 'data-plugin' );
7914 + var action = buttonName.replace( 'edd_' + pluginSlug + '_license_', '' );
7915 + var license = document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value;
7916 + jQuery.ajax({
7917 + type: 'POST', url: ajaxurl, dataType: 'json',
7918 + data: {action: 'frm_addon_' + action, license: license, plugin: pluginSlug, nonce: frmGlobal.nonce},
7919 + success: function( msg ) {
7920 + var thisRow = button.closest( '.edd_frm_license_row' );
7921 + if ( action === 'deactivate' ) {
7922 + license = '';
7923 + document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value = '';
7924 + }
7925 + thisRow.find( '.edd_frm_license' ).html( license );
7926 + if ( msg.success === true ) {
7927 + thisRow.find( '.frm_icon_font' ).removeClass( 'frm_hidden' );
7928 + thisRow.find( 'div.alignleft' ).toggleClass( 'frm_hidden', 1000 );
7929 + }
7930 +
7931 + var messageBox = thisRow.find( '.frm_license_msg' );
7932 + messageBox.html( msg.message );
7933 + if ( msg.message !== '' ) {
7934 + setTimeout( function() {
7935 + messageBox.html( '' );
7936 + }, 15000 );
7937 + }
7938 + }
7939 + });
7940 + }
7941 +
7942 + /* Import/Export page */
7943 +
7944 + function startFormMigration( event ) {
7945 + event.preventDefault();
7946 +
7947 + var checkedBoxes = jQuery( event.target ).find( 'input:checked' );
7948 + if ( ! checkedBoxes.length ) {
7949 + return;
7950 + }
7951 +
7952 + var ids = [];
7953 + checkedBoxes.each( function( i ) {
7954 + ids[i] = this.value;
7955 + });
7956 +
7957 + // Begin the import process.
7958 + importForms( ids, event.target );
7959 + }
7960 +
7961 + /**
7962 + * Begins the process of importing the forms.
7963 + */
7964 + function importForms( forms, targetForm ) {
7965 +
7966 + // Hide the form select section.
7967 + var $form = jQuery( targetForm ),
7968 + $processSettings = $form.next( '.frm-importer-process' );
7969 +
7970 + // Display total number of forms we have to import.
7971 + $processSettings.find( '.form-total' ).text( forms.length );
7972 + $processSettings.find( '.form-current' ).text( '1' );
7973 +
7974 + $form.hide();
7975 +
7976 + // Show processing status.
7977 + // '.process-completed' might have been shown earlier during a previous import, so hide now.
7978 + $processSettings.find( '.process-completed' ).hide();
7979 + $processSettings.show();
7980 +
7981 + // Create global import queue.
7982 + s.importQueue = forms;
7983 + s.imported = 0;
7984 +
7985 + // Import the first form in the queue.
7986 + importForm( $processSettings );
7987 + }
7988 +
7989 + /**
7990 + * Imports a single form from the import queue.
7991 + */
7992 + function importForm( $processSettings ) {
7993 + var formID = s.importQueue[0],
7994 + provider = $processSettings.closest( '.welcome-panel-content' ).find( 'input[name="slug"]' ).val(),
7995 + data = {
7996 + action: 'frm_import_' + provider,
7997 + form_id: formID,
7998 + nonce: frmGlobal.nonce
7999 + };
8000 +
8001 + // Trigger AJAX import for this form.
8002 + jQuery.post( ajaxurl, data, function( res ) {
8003 +
8004 + if ( res.success ) {
8005 + var statusUpdate;
8006 +
8007 + if ( res.data.error ) {
8008 + statusUpdate = '<p>' + res.data.name + ': ' + res.data.msg + '</p>';
8009 + } else {
8010 + statusUpdate = '<p>Imported <a href="' + res.data.link + '" target="_blank">' + res.data.name + '</a></p>';
8011 + }
8012 +
8013 + $processSettings.find( '.status' ).prepend( statusUpdate );
8014 + $processSettings.find( '.status' ).show();
8015 +
8016 + // Remove this form ID from the queue.
8017 + s.importQueue = jQuery.grep( s.importQueue, function( value ) {
8018 + return value != formID;
8019 + });
8020 + s.imported++;
8021 +
8022 + if ( s.importQueue.length === 0 ) {
8023 + $processSettings.find( '.process-count' ).hide();
8024 + $processSettings.find( '.forms-completed' ).text( s.imported );
8025 + $processSettings.find( '.process-completed' ).show();
8026 + } else {
8027 + // Import next form in the queue.
8028 + $processSettings.find( '.form-current' ).text( s.imported + 1 );
8029 + importForm( $processSettings );
8030 + }
8031 + }
8032 + });
8033 + }
8034 +
8035 + function validateExport( e ) {
8036 + /*jshint validthis:true */
8037 + e.preventDefault();
8038 +
8039 + var s = false;
8040 + var $exportForms = jQuery( 'input[name="frm_export_forms[]"]' );
8041 +
8042 + if ( ! jQuery( 'input[name="frm_export_forms[]"]:checked' ).val() ) {
8043 + $exportForms.closest( '.frm-table-box' ).addClass( 'frm_blank_field' );
8044 + s = 'stop';
8045 + }
8046 +
8047 + var $exportType = jQuery( 'input[name="type[]"]' );
8048 + if ( ! jQuery( 'input[name="type[]"]:checked' ).val() && $exportType.attr( 'type' ) === 'checkbox' ) {
8049 + $exportType.closest( 'p' ).addClass( 'frm_blank_field' );
8050 + s = 'stop';
8051 + }
8052 +
8053 + if ( s === 'stop' ) {
8054 + return false;
8055 + }
8056 +
8057 + e.stopPropagation();
8058 + this.submit();
8059 + }
8060 +
8061 + function removeExportError() {
8062 + /*jshint validthis:true */
8063 + var t = jQuery( this ).closest( '.frm_blank_field' );
8064 + if ( typeof t === 'undefined' ) {
8065 + return;
8066 + }
8067 +
8068 + var $thisName = this.name;
8069 + if ( $thisName === 'type[]' && jQuery( 'input[name="type[]"]:checked' ).val() ) {
8070 + t.removeClass( 'frm_blank_field' );
8071 + } else if ( $thisName === 'frm_export_forms[]' && jQuery( this ).val() ) {
8072 + t.removeClass( 'frm_blank_field' );
8073 + }
8074 +
8075 + }
8076 +
8077 + function checkCSVExtension() {
8078 + /*jshint validthis:true */
8079 + var f = jQuery( this ).val();
8080 + var re = /\.csv$/i;
8081 + if ( f.match( re ) !== null ) {
8082 + jQuery( '.show_csv' ).fadeIn();
8083 + } else {
8084 + jQuery( '.show_csv' ).fadeOut();
8085 + }
8086 + }
8087 +
8088 + function checkExportTypes() {
8089 + /*jshint validthis:true */
8090 + var $dropdown = jQuery( this );
8091 + var $selected = $dropdown.find( ':selected' );
8092 + var s = $selected.data( 'support' );
8093 +
8094 + var multiple = s.indexOf( '|' );
8095 + jQuery( 'input[name="type[]"]' ).each( function() {
8096 + this.checked = false;
8097 + if ( s.indexOf( this.value ) >= 0 ) {
8098 + this.disabled = false;
8099 + if ( multiple === -1 ) {
8100 + this.checked = true;
8101 + }
8102 + } else {
8103 + this.disabled = true;
8104 + }
8105 + });
8106 +
8107 + if ( $dropdown.val() === 'csv' ) {
8108 + jQuery( '.csv_opts' ).show();
8109 + jQuery( '.xml_opts' ).hide();
8110 + } else {
8111 + jQuery( '.csv_opts' ).hide();
8112 + jQuery( '.xml_opts' ).show();
8113 + }
8114 +
8115 + var c = $selected.data( 'count' );
8116 + var exportField = jQuery( 'input[name="frm_export_forms[]"]' );
8117 + if ( c === 'single' ) {
8118 + exportField.prop( 'multiple', false );
8119 + exportField.prop( 'checked', false );
8120 + } else {
8121 + exportField.prop( 'multiple', true );
8122 + exportField.prop( 'disabled', false );
8123 + }
8124 + }
8125 +
8126 + function preventMultipleExport() {
8127 + var type = jQuery( 'select[name=format]' ),
8128 + selected = type.find( ':selected' ),
8129 + count = selected.data( 'count' ),
8130 + exportField = jQuery( 'input[name="frm_export_forms[]"]' );
8131 +
8132 + if ( count === 'single' ) {
8133 + // Disable all other fields to prevent multiple selections.
8134 + if ( this.checked ) {
8135 + exportField.prop( 'disabled', true );
8136 + this.removeAttribute( 'disabled' );
8137 + } else {
8138 + exportField.prop( 'disabled', false );
8139 + }
8140 + } else {
8141 + exportField.prop( 'disabled', false );
8142 + }
8143 + }
8144 +
8145 + function initiateMultiselect() {
8146 + jQuery( '.frm_multiselect' ).hide().each( frmDom.bootstrap.multiselect.init );
8147 + }
8148 +
8149 + /* Addons page */
8150 + function installMultipleAddons( e ) {
8151 + e.preventDefault();
8152 + installOrActivate( this, 'frm_multiple_addons' );
8153 + }
8154 +
8155 + function activateAddon( e ) {
8156 + e.preventDefault();
8157 + installOrActivate( this, 'frm_activate_addon' );
8158 + }
8159 +
8160 + function installAddon( e ) {
8161 + e.preventDefault();
8162 + installOrActivate( this, 'frm_install_addon' );
8163 + }
8164 +
8165 + function installOrActivate( clicked, action ) {
8166 + let button, plugin, el, message;
8167 +
8168 + // Remove any leftover error messages, output an icon and get the plugin basename that needs to be activated.
8169 + jQuery( '.frm-addon-error' ).remove();
8170 + button = jQuery( clicked );
8171 + plugin = button.attr( 'rel' );
8172 + el = button.parent();
8173 + message = el.parent().find( '.addon-status-label' );
8174 +
8175 + button.addClass( 'frm_loading_button' );
8176 +
8177 + // Process the Ajax to perform the activation.
8178 + jQuery.ajax({
8179 + url: ajaxurl,
8180 + type: 'POST',
8181 + async: true,
8182 + cache: false,
8183 + dataType: 'json',
8184 + data: {
8185 + action: action,
8186 + nonce: frmGlobal.nonce,
8187 + plugin: plugin
8188 + },
8189 + success: function( response ) {
8190 + let saveAndReload;
8191 +
8192 + if ( 'string' !== typeof response && 'string' === typeof response.message ) {
8193 + if ( 'undefined' !== typeof response.saveAndReload ) {
8194 + saveAndReload = response.saveAndReload;
8195 + }
8196 + response = response.message;
8197 + }
8198 +
8199 + const error = extractErrorFromAddOnResponse( response );
8200 + if ( error ) {
8201 + addonError( error, el, button );
8202 + return;
8203 + }
8204 +
8205 + afterAddonInstall( response, button, message, el, saveAndReload );
8206 + },
8207 + error: function() {
8208 + button.removeClass( 'frm_loading_button' );
8209 + }
8210 + });
8211 + }
8212 +
8213 + function installAddonWithCreds( e ) {
8214 + // Prevent the default action, let the user know we are attempting to install again and go with it.
8215 + e.preventDefault();
8216 +
8217 + // Now let's make another Ajax request once the user has submitted their credentials.
8218 + const proceed = jQuery( this );
8219 + const el = proceed.parent().parent();
8220 + const plugin = proceed.attr( 'rel' );
8221 +
8222 + proceed.addClass( 'frm_loading_button' );
8223 +
8224 + jQuery.ajax({
8225 + url: ajaxurl,
8226 + type: 'POST',
8227 + async: true,
8228 + cache: false,
8229 + dataType: 'json',
8230 + data: {
8231 + action: 'frm_install_addon',
8232 + nonce: frm_admin_js.nonce,
8233 + plugin: plugin,
8234 + hostname: el.find( '#hostname' ).val(),
8235 + username: el.find( '#username' ).val(),
8236 + password: el.find( '#password' ).val()
8237 + },
8238 + success: function( response ) {
8239 + const error = extractErrorFromAddOnResponse( response );
8240 + if ( error ) {
8241 + addonError( error, el, proceed );
8242 + return;
8243 + }
8244 +
8245 + afterAddonInstall( response, proceed, message, el );
8246 + },
8247 + error: function() {
8248 + proceed.removeClass( 'frm_loading_button' );
8249 + }
8250 + });
8251 + }
8252 +
8253 + function afterAddonInstall( response, button, message, el, saveAndReload ) {
8254 + const addonStatuses = document.querySelectorAll( '.frm-addon-status' );
8255 + addonStatuses.forEach(
8256 + addonStatus => {
8257 + addonStatus.textContent = response;
8258 + addonStatus.style.display = 'block';
8259 + }
8260 + );
8261 +
8262 + // The Ajax request was successful, so let's update the output.
8263 + button.css({ opacity: '0' });
8264 + message.text( frm_admin_js.active );
8265 +
8266 + document.querySelectorAll( '.frm-oneclick' ).forEach(
8267 + oneClick => {
8268 + oneClick.style.display = 'none';
8269 + }
8270 + );
8271 +
8272 + jQuery( '#frm_upgrade_modal h2' ).hide();
8273 + jQuery( '#frm_upgrade_modal .frm_lock_icon' ).addClass( 'frm_lock_open_icon' );
8274 + jQuery( '#frm_upgrade_modal .frm_lock_icon use' ).attr( 'xlink:href', '#frm_lock_open_icon' );
8275 +
8276 + // Proceed with CSS changes
8277 + el.parent().removeClass( 'frm-addon-not-installed frm-addon-installed' ).addClass( 'frm-addon-active' );
8278 + button.removeClass( 'frm_loading_button' );
8279 +
8280 + // Maybe refresh import and SMTP pages
8281 + const refreshPage = document.querySelectorAll( '.frm-admin-page-import, #frm-admin-smtp, #frm-welcome' );
8282 + if ( refreshPage.length > 0 ) {
8283 + window.location.reload();
8284 + return;
8285 + }
8286 +
8287 + if ([ 'settings', 'form_builder' ].includes( saveAndReload ) ) {
8288 + addonStatuses.forEach(
8289 + addonStatus => {
8290 + const inModal = null !== addonStatus.closest( '#frm_upgrade_modal' );
8291 + addonStatus.appendChild( getSaveAndReloadSettingsOptions( saveAndReload, inModal ) );
8292 + }
8293 + );
8294 + }
8295 + }
8296 +
8297 + function getSaveAndReloadSettingsOptions( saveAndReload, inModal ) {
8298 + const className = 'frm-save-and-reload-options';
8299 + const children = [ saveAndReloadSettingsButton( saveAndReload ) ];
8300 + if ( inModal ) {
8301 + children.push( closePopupButton() );
8302 + }
8303 + return div({ className, children });
8304 + }
8305 +
8306 + function saveAndReloadSettingsButton( saveAndReload ) {
8307 + var button = document.createElement( 'button' );
8308 + button.classList.add( 'frm-save-and-reload', 'button', 'button-primary', 'frm-button-primary' );
8309 + button.textContent = __( 'Save and Reload', 'formidable' );
8310 + button.addEventListener( 'click', () => {
8311 + if ( saveAndReload === 'form_builder' ) {
8312 + saveAndReloadFormBuilder();
8313 + } else if ( saveAndReload === 'settings' ) {
8314 + saveAndReloadSettings();
8315 + }
8316 + });
8317 + return button;
8318 + }
8319 +
8320 + function closePopupButton() {
8321 + var a = document.createElement( 'a' );
8322 + a.setAttribute( 'href', '#' );
8323 + a.classList.add( 'button', 'button-secondary', 'frm-button-secondary', 'dismiss' );
8324 + a.textContent = __( 'Close', 'formidable' );
8325 + return a;
8326 + }
8327 +
8328 + function extractErrorFromAddOnResponse( response ) {
8329 + if ( typeof response !== 'string' ) {
8330 + if ( typeof response.success !== 'undefined' && response.success ) {
8331 + return false;
8332 + }
8333 +
8334 + if ( response.form ) {
8335 + if ( jQuery( response.form ).is( '#message' ) ) {
8336 + return {
8337 + message: jQuery( response.form ).find( 'p' ).html()
8338 + };
8339 + }
8340 + }
8341 +
8342 + return response;
8343 + }
8344 +
8345 + return false;
8346 + }
8347 +
8348 + function addonError( response, el, button ) {
8349 + if ( response.form ) {
8350 + jQuery( '.frm-inline-error' ).remove();
8351 + button.closest( '.frm-card' )
8352 + .html( response.form )
8353 + .css({ padding: 5 })
8354 + .find( '#upgrade' )
8355 + .attr( 'rel', button.attr( 'rel' ) )
8356 + .on( 'click', installAddonWithCreds );
8357 + } else {
8358 + el.append( '<div class="frm-addon-error frm_error_style"><p><strong>' + response.message + '</strong></p></div>' );
8359 + button.removeClass( 'frm_loading_button' );
8360 + jQuery( '.frm-addon-error' ).delay( 4000 ).fadeOut();
8361 + }
8362 + }
8363 +
8364 + /* Templates */
8365 +
8366 + function initNewFormModal() {
8367 + var installFormTrigger,
8368 + activeHoverIcons,
8369 + $modal,
8370 + handleError,
8371 + handleEmailAddressError,
8372 + handleConfirmEmailAddressError,
8373 + showFreeTemplatesForm,
8374 + firstLockedTemplate,
8375 + isShowFreeTemplatesFormFirst,
8376 + url,
8377 + urlParams;
8378 +
8379 + url = new URL( window.location.href );
8380 + urlParams = url.searchParams;
8381 +
8382 + isShowFreeTemplatesFormFirst = urlParams.get( 'free-templates' );
8383 +
8384 + jQuery( document ).on( 'click', '.frm-trigger-new-form-modal', triggerNewFormModal );
8385 + $modal = initModal( '#frm_new_form_modal', '600px' );
8386 +
8387 + if ( false === $modal ) {
8388 + return;
8389 + }
8390 +
8391 + setTimeout(
8392 + function() {
8393 + $modal.get( 0 ).querySelector( '.postbox' ).style.display = 'block'; // Fixes pro issue #3508, prevent a conflict that hides the postbox in modal.
8394 + },
8395 + 0
8396 + );
8397 +
8398 + installFormTrigger = document.createElement( 'a' );
8399 + installFormTrigger.classList.add( 'frm-install-template', 'frm_hidden' );
8400 + document.body.appendChild( installFormTrigger );
8401 +
8402 + jQuery( '.frm-install-template' ).on( 'click', function( event ) {
8403 + var $h3Clone = jQuery( this ).closest( 'li, td' ).find( 'h3' ).clone(),
8404 + nameLabel = document.getElementById( 'frm_new_name' ),
8405 + descLabel = document.getElementById( 'frm_new_desc' ),
8406 + oldName;
8407 +
8408 + $h3Clone.find( 'svg, .frm-plan-required-tag' ).remove();
8409 + oldName = $h3Clone.html().trim();
8410 +
8411 + event.preventDefault();
8412 +
8413 + document.getElementById( 'frm_template_name' ).value = oldName;
8414 + document.getElementById( 'frm_link' ).value = this.attributes.rel.value;
8415 + document.getElementById( 'frm_action_type' ).value = 'frm_install_template';
8416 + nameLabel.innerHTML = nameLabel.getAttribute( 'data-form' );
8417 + descLabel.innerHTML = descLabel.getAttribute( 'data-form' );
8418 + $modal.dialog( 'open' );
8419 + });
8420 +
8421 + jQuery( document ).on( 'submit', '#frm-new-template', installTemplate );
8422 +
8423 + jQuery( document ).on( 'click', '.frm-hover-icons .frm-preview-form', function( event ) {
8424 + var $li, link, iframe,
8425 + container = document.getElementById( 'frm-preview-block' );
8426 +
8427 + event.preventDefault();
8428 +
8429 + $li = jQuery( this ).closest( 'li' );
8430 + link = $li.attr( 'data-preview' );
8431 +
8432 + if ( link.indexOf( ajaxurl ) > -1 ) {
8433 + iframe = document.createElement( 'iframe' );
8434 + iframe.src = link;
8435 + iframe.height = '400';
8436 + iframe.width = '100%';
8437 + container.innerHTML = '';
8438 + container.appendChild( iframe );
8439 + } else {
8440 + frmApiPreview( container, link );
8441 + }
8442 +
8443 + jQuery( '#frm-preview-title' ).text( getStrippedTemplateName( $li ) );
8444 + $modal.attr( 'frm-page', 'preview' );
8445 + activeHoverIcons = jQuery( this ).closest( '.frm-hover-icons' );
8446 + });
8447 +
8448 + jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-create-form', function( event ) {
8449 + var $li, name, link, action;
8450 +
8451 + event.preventDefault();
8452 +
8453 + $li = jQuery( this ).closest( 'li' );
8454 +
8455 + if ( $li.is( '[data-href]' ) ) {
8456 + window.location = $li.attr( 'data-href' );
8457 + return;
8458 + }
8459 +
8460 + if ( $li.hasClass( 'frm-add-blank-form' ) ) {
8461 + name = link = '';
8462 + action = 'frm_install_form';
8463 + } else if ( $li.is( '[data-rel]' ) ) {
8464 + name = getStrippedTemplateName( $li );
8465 + link = $li.attr( 'data-rel' );
8466 + action = 'frm_install_template';
8467 + } else {
8468 + return;
8469 + }
8470 +
8471 + transitionToAddDetails( $modal, name, link, action );
8472 + });
8473 +
8474 + // Welcome page modals.
8475 + jQuery( document ).on( 'click', '.frm-create-blank-form', function( event ) {
8476 + event.preventDefault();
8477 + jQuery( '.frm-trigger-new-form-modal' ).trigger( 'click' );
8478 + transitionToAddDetails( $modal, '', '', 'frm_install_form' );
8479 +
8480 + // Close the modal with the cancel button.
8481 + jQuery( '.frm-modal-cancel.frm-back-to-all-templates' ).on( 'click', function() {
8482 + jQuery( '.ui-widget-overlay' ).trigger( 'click' );
8483 + });
8484 + });
8485 +
8486 + 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 ) {
8487 + var $hoverIcons, $trigger,
8488 + $li = jQuery( this ).closest( 'li' ),
8489 + triggerClass = $li.hasClass( 'frm-locked-template' ) ? 'frm-unlock-form' : 'frm-create-form';
8490 +
8491 + $hoverIcons = $li.find( '.frm-hover-icons' );
8492 + if ( ! $hoverIcons.length ) {
8493 + $li.trigger( 'mouseover' );
8494 + $hoverIcons = $li.find( '.frm-hover-icons' );
8495 + $hoverIcons.hide();
8496 + }
8497 +
8498 + $trigger = $hoverIcons.find( '.' + triggerClass );
8499 + $trigger.trigger( 'click' );
8500 + });
8501 +
8502 + jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-delete-form', function( event ) {
8503 + var $li,
8504 + trigger;
8505 +
8506 + event.preventDefault();
8507 +
8508 + $li = jQuery( this ).closest( 'li' );
8509 + $li.addClass( 'frm-deleting' );
8510 + trigger = document.createElement( 'a' );
8511 + trigger.setAttribute( 'href', '#' );
8512 + trigger.setAttribute( 'data-id', $li.attr( 'data-formid' ) );
8513 + $li.attr( 'id', 'frm-template-custom-' + $li.attr( 'data-formid' ) );
8514 + jQuery( trigger ).on( 'click', trashTemplate );
8515 + trigger.click();
8516 + setTemplateCount( $li.closest( '.accordion-section' ).get( 0 ) );
8517 + });
8518 +
8519 + showFreeTemplatesForm = function( $el ) {
8520 + var formContainer = document.getElementById( 'frmapi-email-form' );
8521 + jQuery.ajax({
8522 + dataType: 'json',
8523 + url: formContainer.getAttribute( 'data-url' ),
8524 + success: function( json ) {
8525 + var form = json.renderedHtml;
8526 + form = form.replace( /<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi, '' );
8527 + formContainer.innerHTML = form;
8528 + }
8529 + });
8530 +
8531 + $modal.attr( 'frm-page', 'email' );
8532 + $modal.attr( 'frm-this-form', $el.attr( 'data-key' ) );
8533 + $el.append( installFormTrigger );
8534 + };
8535 +
8536 + jQuery( document ).on( 'click', 'li.frm-locked-template .frm-hover-icons .frm-unlock-form', function( event ) {
8537 + var $li,
8538 + activePage;
8539 +
8540 + event.preventDefault();
8541 +
8542 + $li = jQuery( this ).closest( '.frm-locked-template' );
8543 +
8544 + if ( $li.hasClass( 'frm-free-template' ) ) {
8545 + showFreeTemplatesForm( $li );
8546 + return;
8547 + }
8548 +
8549 + if ( $modal.hasClass( 'frm-expired' ) ) {
8550 + activePage = 'renew';
8551 + } else {
8552 + activePage = 'upgrade';
8553 + }
8554 +
8555 + $modal.attr( 'frm-page', activePage );
8556 + });
8557 +
8558 + jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop', function() {
8559 + jQuery( this )
8560 + .closest( '.accordion-section-content' ).css( 'overflow', 'visible' )
8561 + .closest( '.accordion-section' ).css( 'z-index', 1 );
8562 + });
8563 +
8564 + jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop + .frm-dropdown-menu .frm-build-template', function() {
8565 + var name = this.getAttribute( 'data-fullname' ),
8566 + link = this.getAttribute( 'data-formid' ),
8567 + action = 'frm_build_template';
8568 + transitionToAddDetails( $modal, name, link, action );
8569 + });
8570 +
8571 + handleError = function( inputId, errorId, type, message ) {
8572 + var $error = jQuery( errorId );
8573 + $error.removeClass( 'frm_hidden' ).attr( 'frm-error', type );
8574 +
8575 + if ( typeof message !== 'undefined' ) {
8576 + $error.find( 'span[frm-error="' + type + '"]' ).text( message );
8577 + }
8578 +
8579 + jQuery( inputId ).one( 'keyup', function() {
8580 + $error.addClass( 'frm_hidden' );
8581 + });
8582 + };
8583 +
8584 + handleEmailAddressError = function( type ) {
8585 + handleError( '#frm_leave_email', '#frm_leave_email_error', type );
8586 + };
8587 +
8588 + jQuery( document ).on( 'click', '#frm-add-my-email-address', function( event ) {
8589 + var email = document.getElementById( 'frm_leave_email' ).value.trim(),
8590 + regex,
8591 + $hiddenForm,
8592 + $hiddenEmailField;
8593 +
8594 + event.preventDefault();
8595 +
8596 + if ( '' === email ) {
8597 + handleEmailAddressError( 'empty' );
8598 + return;
8599 + }
8600 +
8601 + 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;
8602 +
8603 + if ( regex.test( email ) === false ) {
8604 + handleEmailAddressError( 'invalid' );
8605 + return;
8606 + }
8607 +
8608 + $hiddenForm = jQuery( '#frmapi-email-form' ).find( 'form' );
8609 + $hiddenEmailField = $hiddenForm.find( '[type="email"]' ).not( '.frm_verify' );
8610 + if ( ! $hiddenEmailField.length ) {
8611 + return;
8612 + }
8613 +
8614 + $hiddenEmailField.val( email );
8615 + jQuery.ajax({
8616 + type: 'POST',
8617 + url: $hiddenForm.attr( 'action' ),
8618 + data: $hiddenForm.serialize() + '&action=frm_forms_preview'
8619 + }).done( function( data ) {
8620 + var message = jQuery( data ).find( '.frm_message' ).text().trim();
8621 + if ( message.indexOf( 'Thanks!' ) >= 0 ) {
8622 + $modal.attr( 'frm-page', 'code' );
8623 + } else {
8624 + handleEmailAddressError( 'invalid' );
8625 + }
8626 + });
8627 + });
8628 +
8629 + handleConfirmEmailAddressError = function( type, message ) {
8630 + handleError( '#frm_code_from_email', '#frm_code_from_email_error', type, message );
8631 + };
8632 +
8633 + jQuery( document ).on( 'click', '.frm-confirm-email-address', function( event ) {
8634 + var code = document.getElementById( 'frm_code_from_email' ).value.trim();
8635 +
8636 + event.preventDefault();
8637 +
8638 + if ( '' === code ) {
8639 + handleConfirmEmailAddressError( 'empty' );
8640 + return;
8641 + }
8642 +
8643 + jQuery.ajax({
8644 + type: 'POST',
8645 + url: ajaxurl,
8646 + dataType: 'json',
8647 + data: {
8648 + action: 'template_api_signup',
8649 + nonce: frmGlobal.nonce,
8650 + code: code,
8651 + key: $modal.attr( 'frm-this-form' )
8652 + },
8653 + success: function( response ) {
8654 + if ( response.success ) {
8655 + if ( isShowFreeTemplatesFormFirst ) {
8656 + // Remove free-templates param from URL then reload page.
8657 + urlParams.delete( 'free-templates' );
8658 + url.search = urlParams.toString();
8659 + window.location.href = url.toString();
8660 +
8661 + return;
8662 + }
8663 +
8664 + if ( typeof response.data !== 'undefined' && typeof response.data.url !== 'undefined' ) {
8665 + installFormTrigger.setAttribute( 'rel', response.data.url );
8666 + installFormTrigger.click();
8667 + $modal.attr( 'frm-page', 'details' );
8668 +
8669 + const hookName = 'frm_new_form_modal_form';
8670 + wp.hooks.doAction( hookName, $modal );
8671 +
8672 + document.getElementById( 'frm_action_type' ).value = 'frm_install_template';
8673 +
8674 + if ( typeof response.data.urlByKey !== 'undefined' ) {
8675 + updateTemplateModalFreeUrls( response.data.urlByKey );
8676 + }
8677 + }
8678 + } else {
8679 + if ( Array.isArray( response.data ) && response.data.length ) {
8680 + handleConfirmEmailAddressError( 'custom', response.data[0].message );
8681 + } else {
8682 + handleConfirmEmailAddressError( 'wrong-code' );
8683 + }
8684 +
8685 + jQuery( '#frm_code_from_email_options' ).removeClass( 'frm_hidden' );
8686 + }
8687 + }
8688 + });
8689 + });
8690 +
8691 + jQuery( document ).on( 'click', '#frm-change-email-address', function() {
8692 + $modal.attr( 'frm-page', 'email' );
8693 + });
8694 +
8695 + jQuery( document ).on( 'click', '#frm-resend-code', function() {
8696 + document.getElementById( 'frm_code_from_email' ).value = '';
8697 + jQuery( '#frm_code_from_email_options, #frm_code_from_email_error' ).addClass( 'frm_hidden' );
8698 + document.getElementById( 'frm-add-my-email-address' ).click();
8699 + });
8700 +
8701 + jQuery( document ).on( 'frmAfterSearch', '#frm_new_form_modal #template-search-input', function() {
8702 + var categories = $modal.get( 0 ).querySelector( '.frm-categories-list' ).children,
8703 + categoryIndex,
8704 + category,
8705 + searchableTemplates,
8706 + count;
8707 +
8708 + for ( categoryIndex in categories ) {
8709 + if ( isNaN( categoryIndex ) ) {
8710 + continue;
8711 + }
8712 +
8713 + category = categories[ categoryIndex ];
8714 + if ( ! category.classList.contains( 'accordion-section' ) ) {
8715 + continue;
8716 + }
8717 +
8718 + searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden)' );
8719 + count = searchableTemplates.length;
8720 + jQuery( category ).toggleClass( 'frm_hidden', this.value !== '' && ! count );
8721 + setTemplateCount( category, searchableTemplates );
8722 + }
8723 + });
8724 +
8725 + 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 ) {
8726 + document.getElementById( 'frm-create-title' ).removeAttribute( 'frm-type' );
8727 + $modal.attr( 'frm-page', 'create' );
8728 + });
8729 +
8730 + jQuery( document ).on( 'click', '.frm-use-this-template', function( event ) {
8731 + var $trigger;
8732 +
8733 + event.preventDefault();
8734 +
8735 + $trigger = activeHoverIcons.find( '.frm-create-form' );
8736 + if ( $trigger.closest( '.frm-selectable' ).hasClass( 'frm-locked-template' ) ) {
8737 + $trigger = activeHoverIcons.find( '.frm-unlock-form' );
8738 + }
8739 +
8740 + $trigger.trigger( 'click' );
8741 + });
8742 +
8743 + jQuery( document ).on( 'click', '.frm-submit-new-template', function( event ) {
8744 + var button;
8745 + event.preventDefault();
8746 + button = document.getElementById( 'frm-new-template' ).querySelector( 'button' );
8747 + if ( null !== button ) {
8748 + button.click();
8749 + }
8750 + });
8751 +
8752 + if ( urlParams.get( 'triggerNewFormModal' ) ) {
8753 + triggerNewFormModal();
8754 +
8755 + if ( isShowFreeTemplatesFormFirst ) {
8756 + firstLockedTemplate = jQuery( 'li.frm-locked-template.frm-free-template' ).eq( 0 );
8757 +
8758 + if ( firstLockedTemplate.length ) {
8759 + showFreeTemplatesForm( firstLockedTemplate );
8760 + }
8761 + }
8762 + }
8763 + }
8764 +
8765 + function updateTemplateModalFreeUrls( urlByKey ) {
8766 + jQuery( '#frm_new_form_modal' ).find( '.frm-selectable[data-key]' ).each( function() {
8767 + var $template = jQuery( this ),
8768 + key = $template.attr( 'data-key' );
8769 + if ( 'undefined' !== typeof urlByKey[ key ]) {
8770 + $template.removeClass( 'frm-locked-template' );
8771 + $template.find( 'h3 svg' ).remove(); // remove the lock from the title
8772 + $template.attr( 'data-rel', urlByKey[ key ]);
8773 + }
8774 + });
8775 + }
8776 +
8777 + function transitionToAddDetails( $modal, name, link, action ) {
8778 + var nameLabel = document.getElementById( 'frm_new_name' ),
8779 + descLabel = document.getElementById( 'frm_new_desc' ),
8780 + type = [ 'frm_install_template', 'frm_install_form' ].indexOf( action ) >= 0 ? 'form' : 'template',
8781 + templateNameInput = document.getElementById( 'frm_template_name' );
8782 +
8783 + templateNameInput.value = name;
8784 + document.getElementById( 'frm_link' ).value = link;
8785 + document.getElementById( 'frm_action_type' ).value = action;
8786 + nameLabel.textContent = nameLabel.getAttribute( 'data-' + type );
8787 + if ( descLabel !== null ) {
8788 + descLabel.textContent = descLabel.getAttribute( 'data-' + type );
8789 + }
8790 +
8791 + document.getElementById( 'frm-create-title' ).setAttribute( 'frm-type', type );
8792 +
8793 + $modal.attr( 'frm-page', 'details' );
8794 +
8795 + const hookName = 'frm_new_form_modal_form';
8796 + wp.hooks.doAction( hookName, $modal );
8797 +
8798 + if ( '' === name ) {
8799 + templateNameInput.focus();
8800 + }
8801 + }
8802 +
8803 + function getStrippedTemplateName( $li ) {
8804 + var $clone = $li.find( 'h3' ).clone();
8805 + $clone.find( 'svg, .frm-plan-required-tag, .frm-new-pill' ).remove();
8806 + return $clone.html().trim();
8807 + }
8808 +
8809 + function setTemplateCount( category, searchableTemplates ) {
8810 + var count,
8811 + templateIndex,
8812 + availableCounter,
8813 + availableCount;
8814 +
8815 + if ( typeof searchableTemplates === 'undefined' ) {
8816 + searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden):not(.frm-deleting)' );
8817 + }
8818 +
8819 + count = searchableTemplates.length;
8820 + category.querySelector( '.frm-template-count' ).textContent = count;
8821 +
8822 + jQuery( category ).find( '.frm-templates-plural' ).toggleClass( 'frm_hidden', count === 1 );
8823 + jQuery( category ).find( '.frm-templates-singular' ).toggleClass( 'frm_hidden', count !== 1 );
8824 +
8825 + availableCounter = category.querySelector( '.frm-available-templates-count' );
8826 + if ( availableCounter !== null ) {
8827 + availableCount = 0;
8828 + for ( templateIndex in searchableTemplates ) {
8829 + if ( ! isNaN( templateIndex ) && ! searchableTemplates[ templateIndex ].classList.contains( 'frm-locked-template' ) ) {
8830 + availableCount++;
8831 + }
8832 + }
8833 +
8834 + availableCounter.textContent = availableCount;
8835 + }
8836 + }
8837 +
8838 + function initSelectionAutocomplete() {
8839 + frmDom.autocomplete.initSelectionAutocomplete();
8840 + }
8841 +
8842 + function nextInstallStep( thisStep ) {
8843 + thisStep.classList.add( 'frm_grey' );
8844 + thisStep.nextElementSibling.classList.remove( 'frm_grey' );
8845 + }
8846 +
8847 + function frmApiPreview( cont, link ) {
8848 + cont.innerHTML = '<div class="frm-wait"></div>';
8849 + jQuery.ajax({
8850 + dataType: 'json',
8851 + url: link,
8852 + success: function( json ) {
8853 + var form = json.renderedHtml;
8854 + form = form.replace( /<script\b[^<]*(js\/jquery\/jquery)[^<]*><\/script>/gi, '' );
8855 + form = form.replace( /<link\b[^>]*(jquery-ui.min.css)[^>]*>/gi, '' );
8856 + form = form.replace( ' frm_logic_form ', ' ' );
8857 + form = form.replace( '<form ', '<form onsubmit="event.preventDefault();" ' );
8858 + cont.innerHTML = '<div class="frm-wait" id="frm-remove-me"></div><div class="frm-fade" id="frm-show-me">' +
8859 + form + '</div>';
8860 + setTimeout( function() {
8861 + document.getElementById( 'frm-remove-me' ).style.display = 'none';
8862 + document.getElementById( 'frm-show-me' ).style.opacity = '1';
8863 + }, 300 );
8864 + }
8865 + });
8866 + }
8867 +
8868 + function installTemplateFieldset( e ) {
8869 + /*jshint validthis:true */
8870 + var fieldset = this.parentNode.parentNode,
8871 + action = fieldset.elements.type.value,
8872 + button = this;
8873 + e.preventDefault();
8874 + button.classList.add( 'frm_loading_button' );
8875 + installNewForm( fieldset, action, button );
8876 + }
8877 +
8878 + function installTemplate( e ) {
8879 + /*jshint validthis:true */
8880 + var action = this.elements.type.value,
8881 + button = this.querySelector( 'button' );
8882 + e.preventDefault();
8883 + button.classList.add( 'frm_loading_button' );
8884 + installNewForm( this, action, button );
8885 + }
8886 +
8887 + function installNewForm( form, action, button ) {
8888 + const formData = formToData( form );
8889 + const formName = formData.template_name;
8890 + const formDesc = formData.template_desc;
8891 + const link = form.elements.link.value;
8892 +
8893 + let data = {
8894 + action: action,
8895 + xml: link,
8896 + name: formName,
8897 + desc: formDesc,
8898 + form: JSON.stringify( formData ),
8899 + nonce: frmGlobal.nonce
8900 + };
8901 +
8902 + const hookName = 'frm_before_install_new_form';
8903 + const filterArgs = { formData };
8904 + data = wp.hooks.applyFilters( hookName, data, filterArgs );
8905 +
8906 + postAjax( data, function( response ) {
8907 + if ( typeof response.redirect !== 'undefined' ) {
8908 + const redirect = response.redirect;
8909 + if ( typeof form.elements.redirect === 'undefined' ) {
8910 + window.location = redirect;
8911 + } else {
8912 + const href = document.getElementById( 'frm-redirect-link' );
8913 + if ( typeof link !== 'undefined' && href !== null ) {
8914 + // Show the next installation step.
8915 + href.setAttribute( 'href', redirect );
8916 + href.classList.remove( 'frm_grey', 'disabled' );
8917 + nextInstallStep( form.parentNode.parentNode );
8918 + button.classList.add( 'frm_grey', 'disabled' );
8919 + }
8920 + }
8921 + } else {
8922 + jQuery( '.spinner' ).css( 'visibility', 'hidden' );
8923 +
8924 + // Show response.message
8925 + if ( 'string' === typeof response.message ) {
8926 + showInstallFormErrorModal( response.message );
8927 + }
8928 + }
8929 + button.classList.remove( 'frm_loading_button' );
8930 + });
8931 + }
8932 +
8933 + function showInstallFormErrorModal( message ) {
8934 + const modalContent = div( message );
8935 + modalContent.style.padding = '20px 40px';
8936 + const modal = frmDom.modal.maybeCreateModal(
8937 + 'frmInstallFormErrorModal',
8938 + {
8939 + title: __( 'Unable to install template', 'formidable' ),
8940 + content: modalContent
8941 + }
8942 + );
8943 + modal.classList.add( 'frm_common_modal' );
8944 + }
8945 +
8946 + function handleCaptchaTypeChange( e ) {
8947 + const thresholdContainer = document.getElementById( 'frm_captcha_threshold_container' );
8948 + if ( thresholdContainer ) {
8949 + thresholdContainer.classList.toggle( 'frm_hidden', 'v3' !== e.target.value );
8950 + }
8951 + }
8952 +
8953 + function trashTemplate( e ) {
8954 + /*jshint validthis:true */
8955 + var id = this.getAttribute( 'data-id' );
8956 + e.preventDefault();
8957 +
8958 + data = {
8959 + action: 'frm_forms_trash',
8960 + id: id,
8961 + nonce: frmGlobal.nonce
8962 + };
8963 + postAjax( data, function() {
8964 + var card = document.getElementById( 'frm-template-custom-' + id );
8965 + fadeOut( card, function() {
8966 + card.parentNode.removeChild( card );
8967 + });
8968 + });
8969 + }
8970 +
8971 + function searchContent() {
8972 + /*jshint validthis:true */
8973 + var i,
8974 + regEx = false,
8975 + searchText = this.value.toLowerCase(),
8976 + toSearch = this.getAttribute( 'data-tosearch' ),
8977 + items = document.getElementsByClassName( toSearch );
8978 +
8979 + if ( this.tagName === 'SELECT' ) {
8980 + searchText = selectedOptions( this );
8981 + searchText = searchText.join( '|' ).toLowerCase();
8982 + regEx = true;
8983 + }
8984 +
8985 + if ( toSearch === 'frm-action' && searchText !== '' ) {
8986 + var addons = document.getElementById( 'frm_email_addon_menu' ).classList;
8987 + addons.remove( 'frm-all-actions' );
8988 + addons.add( 'frm-limited-actions' );
8989 + }
8990 +
8991 + for ( i = 0; i < items.length; i++ ) {
8992 + var innerText = items[i].innerText.toLowerCase();
8993 + if ( searchText === '' ) {
8994 + items[i].classList.remove( 'frm_hidden' );
8995 + items[i].classList.remove( 'frm-search-result' );
8996 + } else if ( ( regEx && new RegExp( searchText ).test( innerText ) ) || innerText.indexOf( searchText ) >= 0 ) {
8997 + items[i].classList.remove( 'frm_hidden' );
8998 + items[i].classList.add( 'frm-search-result' );
8999 + } else {
9000 + items[i].classList.add( 'frm_hidden' );
9001 + items[i].classList.remove( 'frm-search-result' );
9002 + }
9003 + }
9004 +
9005 + jQuery( this ).trigger( 'frmAfterSearch' );
9006 + }
9007 +
9008 + function stopPropagation( e ) {
9009 + e.stopPropagation();
9010 + }
9011 +
9012 + /* Helpers */
9013 +
9014 + function selectedOptions( select ) {
9015 + var opt,
9016 + result = [],
9017 + options = select && select.options;
9018 +
9019 + for ( var i = 0, iLen = options.length; i < iLen; i++ ) {
9020 + opt = options[i];
9021 +
9022 + if ( opt.selected ) {
9023 + result.push( opt.value );
9024 + }
9025 + }
9026 + return result;
9027 + }
9028 +
9029 + function triggerEvent( element, event ) {
9030 + var evt = document.createEvent( 'HTMLEvents' );
9031 + evt.initEvent( event, false, true );
9032 + element.dispatchEvent( evt );
9033 + }
9034 +
9035 + function postAjax( data, success ) {
9036 + let response;
9037 +
9038 + const xmlHttp = new XMLHttpRequest();
9039 + const params = typeof data === 'string' ? data : Object.keys( data ).map(
9040 + function( k ) {
9041 + return encodeURIComponent( k ) + '=' + encodeURIComponent( data[k]);
9042 + }
9043 + ).join( '&' );
9044 +
9045 + xmlHttp.open( 'post', ajaxurl, true );
9046 + xmlHttp.onreadystatechange = function() {
9047 + if ( xmlHttp.readyState > 3 && xmlHttp.status == 200 ) {
9048 + response = xmlHttp.responseText;
9049 + try {
9050 + response = JSON.parse( response );
9051 + } catch ( e ) {
9052 + // The response may not be JSON, so just return it.
9053 + }
9054 + success( response );
9055 + }
9056 + };
9057 + xmlHttp.setRequestHeader( 'X-Requested-With', 'XMLHttpRequest' );
9058 + xmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
9059 + xmlHttp.send( params );
9060 + return xmlHttp;
9061 + }
9062 +
9063 + function fadeOut( element, success ) {
9064 + element.classList.add( 'frm-fade' );
9065 + setTimeout( success, 1000 );
9066 + }
9067 +
9068 + function invisible( classes ) {
9069 + jQuery( classes ).css( 'visibility', 'hidden' );
9070 + }
9071 +
9072 + function visible( classes ) {
9073 + jQuery( classes ).css( 'visibility', 'visible' );
9074 + }
9075 +
9076 + function initModal( id, width ) {
9077 + const $info = jQuery( id );
9078 + if ( ! $info.length ) {
9079 + return false;
9080 + }
9081 +
9082 + if ( typeof width === 'undefined' ) {
9083 + width = '550px';
9084 + }
9085 +
9086 + const dialogArgs = {
9087 + dialogClass: 'frm-dialog',
9088 + modal: true,
9089 + autoOpen: false,
9090 + closeOnEscape: true,
9091 + width: width,
9092 + resizable: false,
9093 + draggable: false,
9094 + open: function() {
9095 + jQuery( '.ui-dialog-titlebar' ).addClass( 'frm_hidden' ).removeClass( 'ui-helper-clearfix' );
9096 + jQuery( '#wpwrap' ).addClass( 'frm_overlay' );
9097 + jQuery( '.frm-dialog' ).removeClass( 'ui-widget ui-widget-content ui-corner-all' );
9098 + $info.removeClass( 'ui-dialog-content ui-widget-content' );
9099 + bindClickForDialogClose( $info );
9100 + },
9101 + close: function() {
9102 + jQuery( '#wpwrap' ).removeClass( 'frm_overlay' );
9103 + jQuery( '.spinner' ).css( 'visibility', 'hidden' );
9104 +
9105 + this.removeAttribute( 'data-option-type' );
9106 + const optionType = document.getElementById( 'bulk-option-type' );
9107 + if ( optionType ) {
9108 + optionType.value = '';
9109 + }
9110 + }
9111 + };
9112 +
9113 + $info.dialog( dialogArgs );
9114 +
9115 + return $info;
9116 + }
9117 +
9118 + function toggle( cname, id ) {
9119 + if ( id === '#' ) {
9120 + var cont = document.getElementById( cname );
9121 + var hidden = cont.style.display;
9122 + if ( hidden === 'none' ) {
9123 + cont.style.display = 'block';
9124 + } else {
9125 + cont.style.display = 'none';
9126 + }
9127 + } else {
9128 + var vis = cname.is( ':visible' );
9129 + if ( vis ) {
9130 + cname.hide();
9131 + } else {
9132 + cname.show();
9133 + }
9134 + }
9135 + }
9136 +
9137 + function removeWPUnload() {
9138 + window.onbeforeunload = null;
9139 + var w = jQuery( window );
9140 + w.off( 'beforeunload.widgets' );
9141 + w.off( 'beforeunload.edit-post' );
9142 + }
9143 +
9144 + function addMultiselectLabelListener() {
9145 + const clickListener = ( e ) => {
9146 + if ( 'LABEL' !== e.target.nodeName ) {
9147 + return;
9148 + }
9149 +
9150 + const labelFor = e.target.getAttribute( 'for' );
9151 + if ( ! labelFor ) {
9152 + return;
9153 + }
9154 +
9155 + const input = document.getElementById( labelFor );
9156 + if ( ! input || ! input.nextElementSibling ) {
9157 + return;
9158 + }
9159 +
9160 + const buttonToggle = input.nextElementSibling.querySelector( 'button.dropdown-toggle.multiselect' );
9161 + if ( ! buttonToggle ) {
9162 + return;
9163 + }
9164 +
9165 + const triggerMultiselectClick = () => buttonToggle.click();
9166 + setTimeout( triggerMultiselectClick, 0 );
9167 + };
9168 + document.addEventListener( 'click', clickListener );
9169 + }
9170 +
9171 + function maybeChangeEmbedFormMsg() {
9172 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
9173 + var fieldItem = document.getElementById( 'frm_field_id_' + fieldId );
9174 + if ( null === fieldItem || 'form' !== fieldItem.dataset.type ) {
9175 + return;
9176 + }
9177 +
9178 + fieldItem = jQuery( fieldItem );
9179 +
9180 + if ( this.options[ this.selectedIndex ].value ) {
9181 + fieldItem.find( '.frm-not-set' )[0].classList.add( 'frm_hidden' );
9182 + var embedMsg = fieldItem.find( '.frm-embed-message' );
9183 + embedMsg.html( embedMsg.data( 'embedmsg' ) + this.options[ this.selectedIndex ].text );
9184 + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.remove( 'frm_hidden' );
9185 + } else {
9186 + fieldItem.find( '.frm-not-set' )[0].classList.remove( 'frm_hidden' );
9187 + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.add( 'frm_hidden' );
9188 + }
9189 + }
9190 +
9191 + function toggleProductType() {
9192 + var settings = jQuery( this ).closest( '.frm-single-settings' ),
9193 + container = settings.find( '.frmjs_product_choices' ),
9194 + heading = settings.find( '.frm_prod_options_heading' ),
9195 + currentVal = this.options[ this.selectedIndex ].value;
9196 +
9197 + container.removeClass( 'frm_prod_type_single frm_prod_type_user_def' );
9198 + heading.removeClass( 'frm_prod_user_def' );
9199 +
9200 + if ( 'single' === currentVal ) {
9201 + container.addClass( 'frm_prod_type_single' );
9202 + } else if ( 'user_def' === currentVal ) {
9203 + container.addClass( 'frm_prod_type_user_def' );
9204 + heading.addClass( 'frm_prod_user_def' );
9205 + }
9206 + }
9207 +
9208 + function isProductField( fieldId ) {
9209 + var field = document.getElementById( 'frm_field_id_' + fieldId );
9210 + if ( field === null ) {
9211 + return false;
9212 + } else {
9213 + return 'product' === field.getAttribute( 'data-type' );
9214 + }
9215 + }
9216 +
9217 + /**
9218 + * Serialize form data with vanilla JS.
9219 + */
9220 + function formToData( form ) {
9221 + var subKey, i,
9222 + object = {},
9223 + formData = form.elements;
9224 +
9225 + for ( i = 0; i < formData.length; i++ ) {
9226 + var input = formData[i],
9227 + key = input.name,
9228 + value = input.value,
9229 + names = key.match( /(.*)\[(.*)\]/ );
9230 +
9231 + if ( ( input.type === 'radio' || input.type === 'checkbox' ) && ! input.checked ) {
9232 + continue;
9233 + }
9234 +
9235 + if ( names !== null ) {
9236 + key = names[1];
9237 + subKey = names[2];
9238 + if ( ! Reflect.has( object, key ) ) {
9239 + object[key] = {};
9240 + }
9241 + object[key][subKey] = value;
9242 + continue;
9243 + }
9244 +
9245 + // Reflect.has in favor of: object.hasOwnProperty(key)
9246 + if ( ! Reflect.has( object, key ) ) {
9247 + object[key] = value;
9248 + continue;
9249 + }
9250 + if ( ! Array.isArray( object[key]) ) {
9251 + object[key] = [ object[key] ];
9252 + }
9253 + object[key].push( value );
9254 + }
9255 +
9256 + return object;
9257 + }
9258 +
9259 + /**
9260 + * Show, hide, and sort subfields of Name field on form builder.
9261 + *
9262 + * @since 4.11
9263 + */
9264 + function handleNameFieldOnFormBuilder() {
9265 + /**
9266 + * Gets subfield element from cache.
9267 + *
9268 + * @param {String} fieldId Field ID.
9269 + * @param {String} key Cache key.
9270 + * @returns {HTMLElement|undefined} Return the element from cache or undefined if not found.
9271 + */
9272 + const getSubFieldElFromCache = ( fieldId, key ) => {
9273 + window.frmCachedSubFields = window.frmCachedSubFields || {};
9274 + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {};
9275 + return window.frmCachedSubFields[fieldId][key];
9276 + };
9277 +
9278 + /**
9279 + * Sets subfield element to cache.
9280 + *
9281 + * @param {String} fieldId Field ID.
9282 + * @param {String} key Cache key.
9283 + * @param {HTMLElement} el Element.
9284 + */
9285 + const setSubFieldElToCache = ( fieldId, key, el ) => {
9286 + window.frmCachedSubFields = window.frmCachedSubFields || {};
9287 + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {};
9288 + window.frmCachedSubFields[fieldId][key] = el;
9289 + };
9290 +
9291 + /**
9292 + * Gets column class from the number of columns.
9293 + *
9294 + * @param {Number} colCount Number of columns.
9295 + * @returns {string}
9296 + */
9297 + const getColClass = colCount => 'frm' + parseInt( 12 / colCount );
9298 +
9299 + const colClasses = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ].map( num => 'frm' + num );
9300 +
9301 + const allSubFieldNames = [ 'first', 'middle', 'last' ];
9302 +
9303 + /**
9304 + * Handles name layout change.
9305 + *
9306 + * @param {Event} event Event object.
9307 + */
9308 + const onChangeLayout = event => {
9309 + const value = event.target.value;
9310 + const subFieldNames = value.split( '_' );
9311 + const fieldId = event.target.dataset.fieldId;
9312 +
9313 + /*
9314 + * Live update form on the form builder.
9315 + */
9316 + const container = document.querySelector( '#field_' + fieldId + '_inner_container .frm_combo_inputs_container' );
9317 + const newColClass = getColClass( subFieldNames.length );
9318 +
9319 + // Set all sub field elements to cache and hide all of them first.
9320 + allSubFieldNames.forEach( name => {
9321 + const subFieldEl = container.querySelector( '[data-sub-field-name="' + name + '"]' );
9322 + if ( subFieldEl ) {
9323 + subFieldEl.classList.add( 'frm_hidden' );
9324 + subFieldEl.classList.remove( ...colClasses );
9325 + setSubFieldElToCache( fieldId, name, subFieldEl );
9326 + }
9327 + });
9328 +
9329 + subFieldNames.forEach( subFieldName => {
9330 + const subFieldEl = getSubFieldElFromCache( fieldId, subFieldName );
9331 + if ( ! subFieldEl ) {
9332 + return;
9333 + }
9334 +
9335 + subFieldEl.classList.remove( 'frm_hidden' );
9336 + subFieldEl.classList.add( newColClass );
9337 +
9338 + container.append( subFieldEl );
9339 + });
9340 +
9341 + /*
9342 + * Live update subfield options.
9343 + */
9344 + // Hide all subfield options.
9345 + allSubFieldNames.forEach( name => {
9346 + const optionsEl = document.querySelector( '.frm_sub_field_options-' + name + '[data-field-id="' + fieldId + '"]' );
9347 + if ( optionsEl ) {
9348 + optionsEl.classList.add( 'frm_hidden' );
9349 + setSubFieldElToCache( fieldId, name + '_options', optionsEl );
9350 + }
9351 + });
9352 +
9353 + subFieldNames.forEach( subFieldName => {
9354 + const optionsEl = getSubFieldElFromCache( fieldId, subFieldName + '_options' );
9355 + if ( ! optionsEl ) {
9356 + return;
9357 + }
9358 + optionsEl.classList.remove( 'frm_hidden' );
9359 + });
9360 + };
9361 +
9362 + const dropdownSelector = '.frm_name_layout_dropdown';
9363 + document.addEventListener( 'change', event => {
9364 + if ( event.target.matches( dropdownSelector ) ) {
9365 + onChangeLayout( event );
9366 + }
9367 + }, false );
9368 + }
9369 +
9370 + function debounce( func, wait = 100 ) {
9371 + return frmDom.util.debounce( func, wait );
9372 + }
9373 +
9374 + function addSaveAndDragIconsToOption( fieldId, liObject ) {
9375 + let li, useTag, useTagHref;
9376 + let hasDragIcon = false;
9377 + let hasSaveIcon = false;
9378 +
9379 + if ( liObject.newOption ) {
9380 + const parser = new DOMParser();
9381 + li = parser.parseFromString( liObject.newOption, 'text/html' ).body.childNodes[0];
9382 + } else {
9383 + li = liObject;
9384 + }
9385 +
9386 + const liIcons = li.querySelectorAll( 'svg' );
9387 +
9388 + liIcons.forEach( ( svg, key ) => {
9389 + useTag = svg.getElementsByTagNameNS( 'http://www.w3.org/2000/svg', 'use' )[0];
9390 + if ( ! useTag ) {
9391 + return;
9392 + }
9393 + useTagHref = useTag.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) || useTag.getAttribute( 'href' );
9394 +
9395 + if ( useTagHref === '#frm_drag_icon' ) {
9396 + hasDragIcon = true;
9397 + }
9398 +
9399 + if ( useTagHref === '#frm_save_icon' ) {
9400 + hasSaveIcon = true;
9401 + }
9402 + });
9403 +
9404 + if ( ! hasDragIcon ) {
9405 + li.prepend( icons.drag.cloneNode( true ) );
9406 + }
9407 +
9408 + if ( li.querySelector( `[id^=field_key_${fieldId}-]` ) && ! hasSaveIcon ) {
9409 + li.querySelector( `[id^=field_key_${fieldId}-]` ).after( icons.save.cloneNode( true ) );
9410 + }
9411 +
9412 + if ( liObject.newOption ) {
9413 + liObject.newOption = li;
9414 + }
9415 + }
9416 +
9417 + function maybeAddSaveAndDragIcons( fieldId ) {
9418 + fieldOptions = document.querySelectorAll( `[id^=frm_delete_field_${fieldId}-]` );
9419 + // return if there are no options.
9420 + if ( fieldOptions.length < 2 ) {
9421 + return;
9422 + }
9423 +
9424 + let options = [ ...fieldOptions ].slice( 1 );
9425 + options.forEach( ( li, _key ) => {
9426 + if ( li.classList.contains( 'frm_other_option' ) ) {
9427 + return;
9428 + }
9429 + addSaveAndDragIconsToOption( fieldId, li );
9430 + });
9431 + }
9432 +
9433 + /**
9434 + * Does the same as jQuery( document ).on( 'event', 'selector', handler ).
9435 + *
9436 + * @since 5.4.2
9437 + *
9438 + * @param {String} event Event name.
9439 + * @param {String} selector Selector.
9440 + * @param {Function} handler Handler.
9441 + * @param {Boolean|Object} options Options to be added to `addEventListener()` method. Default is `false`.
9442 + */
9443 + function documentOn( event, selector, handler, options ) {
9444 + if ( 'undefined' === typeof options ) {
9445 + options = false;
9446 + }
9447 +
9448 + document.addEventListener( event, function( e ) {
9449 + var target;
9450 +
9451 + // loop parent nodes from the target to the delegation node.
9452 + for ( target = e.target; target && target != this; target = target.parentNode ) {
9453 + if ( target.matches( selector ) ) {
9454 + handler.call( target, e );
9455 + break;
9456 + }
9457 + }
9458 + }, options );
9459 + }
9460 +
9461 + return {
9462 + init: function() {
9463 + s = {};
9464 +
9465 + // Bootstrap dropdown button
9466 + jQuery( '.wp-admin' ).on( 'click', function( e ) {
9467 + var t = jQuery( e.target );
9468 + var $openDrop = jQuery( '.dropdown.open' );
9469 + if ( $openDrop.length && ! t.hasClass( 'dropdown' ) && ! t.closest( '.dropdown' ).length ) {
9470 + $openDrop.removeClass( 'open' );
9471 + }
9472 + });
9473 + jQuery( '#frm_bs_dropdown:not(.open) a' ).on( 'click', focusSearchBox );
9474 +
9475 + if ( typeof thisFormId === 'undefined' ) {
9476 + thisFormId = jQuery( document.getElementById( 'form_id' ) ).val();
9477 + }
9478 +
9479 + frmAdminBuild.inboxBannerInit();
9480 +
9481 + if ( $newFields.length > 0 ) {
9482 + // only load this on the form builder page
9483 + frmAdminBuild.buildInit();
9484 + } else if ( document.getElementById( 'frm_notification_settings' ) !== null ) {
9485 + // only load on form settings page
9486 + frmAdminBuild.settingsInit();
9487 + } else if ( document.getElementById( 'frm_styling_form' ) !== null ) {
9488 + // load styling settings js
9489 + frmAdminBuild.styleInit();
9490 + } else if ( document.getElementById( 'form_global_settings' ) !== null ) {
9491 + // global settings page
9492 + frmAdminBuild.globalSettingsInit();
9493 + } else if ( document.getElementById( 'frm_export_xml' ) !== null ) {
9494 + // import/export page
9495 + frmAdminBuild.exportInit();
9496 + } else if ( document.getElementById( 'frm_dyncontent' ) !== null ) {
9497 + // only load on views settings page
9498 + frmAdminBuild.viewInit();
9499 + } else if ( document.getElementById( 'frm_inbox_page' ) !== null ) {
9500 + // Inbox page
9501 + frmAdminBuild.inboxInit();
9502 + } else if ( document.getElementById( 'frm-welcome' ) !== null ) {
9503 + // Solution install page
9504 + frmAdminBuild.solutionInit();
9505 + } else {
9506 + // New form selection page
9507 + initNewFormModal();
9508 + initSelectionAutocomplete();
9509 +
9510 + jQuery( '[data-frmprint]' ).on( 'click', function() {
9511 + window.print();
9512 + return false;
9513 + });
9514 + }
9515 +
9516 + var $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) );
9517 + if ( $advInfo.length > 0 || jQuery( '.frm_field_list' ).length > 0 ) {
9518 + // only load on the form, form settings, and view settings pages
9519 + frmAdminBuild.panelInit();
9520 + }
9521 +
9522 + loadTooltips();
9523 + initUpgradeModal();
9524 + moveTopBanner();
9525 +
9526 + // used on build, form settings, and view settings
9527 + var $shortCodeDiv = jQuery( document.getElementById( 'frm_shortcodediv' ) );
9528 + if ( $shortCodeDiv.length > 0 ) {
9529 + jQuery( 'a.edit-frm_shortcode' ).on( 'click', function() {
9530 + if ( $shortCodeDiv.is( ':hidden' ) ) {
9531 + $shortCodeDiv.slideDown( 'fast' );
9532 + this.style.display = 'none';
9533 + }
9534 + return false;
9535 + });
9536 +
9537 + jQuery( '.cancel-frm_shortcode', '#frm_shortcodediv' ).on( 'click', function() {
9538 + $shortCodeDiv.slideUp( 'fast' );
9539 + $shortCodeDiv.siblings( 'a.edit-frm_shortcode' ).show();
9540 + return false;
9541 + });
9542 + }
9543 +
9544 + // tabs
9545 + jQuery( document ).on( 'click', '#frm-nav-tabs a', clickNewTab );
9546 + jQuery( '.post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a' ).on( 'click', function() {
9547 + const showUpgradeTab = this.classList.contains( 'frm_show_upgrade_tab' );
9548 + if ( this.classList.contains( 'frm_noallow' ) && ! showUpgradeTab ) {
9549 + return;
9550 + }
9551 +
9552 + if ( showUpgradeTab ) {
9553 + populateUpgradeTab( this );
9554 + }
9555 +
9556 + clickTab( this );
9557 + return false;
9558 + });
9559 + clickTab( jQuery( '.starttab a' ), 'auto' );
9560 +
9561 + // submit the search form with dropdown
9562 + jQuery( document ).on( 'click', '#frm-fid-search-menu a', function() {
9563 + var val = this.id.replace( 'fid-', '' );
9564 + jQuery( 'select[name="fid"]' ).val( val );
9565 + triggerSubmit( document.getElementById( 'posts-filter' ) );
9566 + return false;
9567 + });
9568 +
9569 + jQuery( '.frm_select_box' ).on( 'click focus', function() {
9570 + this.select();
9571 + });
9572 +
9573 + jQuery( document ).on( 'input search change', '.frm-auto-search', searchContent );
9574 + jQuery( document ).on( 'focusin click', '.frm-auto-search', stopPropagation );
9575 + var autoSearch = jQuery( '.frm-auto-search' );
9576 + if ( autoSearch.val() !== '' ) {
9577 + autoSearch.trigger( 'keyup' );
9578 + }
9579 +
9580 + // Initialize Formidable Connection.
9581 + FrmFormsConnect.init();
9582 +
9583 + jQuery( document ).on( 'click', '.frm-install-addon', installAddon );
9584 + jQuery( document ).on( 'click', '.frm-activate-addon', activateAddon );
9585 + jQuery( document ).on( 'click', '.frm-solution-multiple', installMultipleAddons );
9586 +
9587 + // prevent annoying confirmation message from WordPress
9588 + jQuery( 'button, input[type=submit]' ).on( 'click', removeWPUnload );
9589 +
9590 + addMultiselectLabelListener();
9591 +
9592 + frmAdminBuild.hooks.addFilter(
9593 + 'frm_before_embed_modal',
9594 + ( ids, { element, type }) => {
9595 + if ( 'form' !== type ) {
9596 + return ids;
9597 + }
9598 +
9599 + let formId, formKey;
9600 + const row = element.closest( 'tr' );
9601 +
9602 + if ( row ) {
9603 + // Embed icon on form index.
9604 + formId = parseInt( row.querySelector( '.column-id' ).textContent );
9605 + formKey = row.querySelector( '.column-form_key' ).textContent;
9606 + } else {
9607 + // Embed button in form builder / form settings.
9608 + formId = document.getElementById( 'form_id' ).value;
9609 +
9610 + const formKeyInput = document.getElementById( 'frm_form_key' );
9611 + if ( formKeyInput ) {
9612 + formKey = formKeyInput.value;
9613 + } else {
9614 + const previewDrop = document.getElementById( 'frm-previewDrop' );
9615 + if ( previewDrop ) {
9616 + formKey = previewDrop.nextElementSibling.querySelector( '.dropdown-item a' ).getAttribute( 'href' ).split( 'form=' )[1];
9617 + }
9618 + }
9619 + }
9620 +
9621 + return [ formId, formKey ];
9622 + }
9623 + );
9624 +
9625 + document.querySelectorAll( '#frm-show-fields > li, .frm_grid_container li' ).forEach( ( el, _key ) => {
9626 + el.addEventListener( 'click', function() {
9627 + let fieldId = this.querySelector( 'li' )?.dataset.fid || this.dataset.fid;
9628 + maybeAddSaveAndDragIcons( fieldId );
9629 + });
9630 + });
9631 + },
9632 +
9633 + buildInit: function() {
9634 + let loadFieldId, $builderForm, builderArea;
9635 +
9636 + debouncedSyncAfterDragAndDrop = debounce( syncAfterDragAndDrop, 10 );
9637 +
9638 + if ( jQuery( '.frm_field_loading' ).length ) {
9639 + loadFieldId = jQuery( '.frm_field_loading' ).first().attr( 'id' );
9640 + loadFields( loadFieldId );
9641 + }
9642 +
9643 + setupSortable( 'ul.frm_sorting' );
9644 +
9645 + document.querySelectorAll( '.field_type_list > li' ).forEach( makeDraggable );
9646 +
9647 + 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();
9648 +
9649 + jQuery( '.frm_submit_ajax' ).on( 'click', submitBuild );
9650 + jQuery( '.frm_submit_no_ajax' ).on( 'click', submitNoAjax );
9651 +
9652 + jQuery( 'a.edit-form-status' ).on( 'click', slideDown );
9653 + jQuery( '.cancel-form-status' ).on( 'click', slideUp );
9654 + jQuery( '.save-form-status' ).on( 'click', function() {
9655 + const newStatus = jQuery( document.getElementById( 'form_change_status' ) ).val();
9656 + jQuery( 'input[name="new_status"]' ).val( newStatus );
9657 + jQuery( document.getElementById( 'form-status-display' ) ).html( newStatus );
9658 + jQuery( '.cancel-form-status' ).trigger( 'click' );
9659 + return false;
9660 + });
9661 +
9662 + jQuery( '.frm_form_builder form' ).first().on( 'submit', function() {
9663 + jQuery( '.inplace_field' ).trigger( 'blur' );
9664 + });
9665 +
9666 + initiateMultiselect();
9667 + renumberPageBreaks();
9668 +
9669 + $builderForm = jQuery( builderForm );
9670 + builderArea = document.getElementById( 'frm_form_editor_container' );
9671 + $builderForm.on( 'click', '.frm_add_logic_row', addFieldLogicRow );
9672 + $builderForm.on( 'click', '.frm_add_watch_lookup_row', addWatchLookupRow );
9673 + $builderForm.on( 'change', '.frm_get_values_form', updateGetValueFieldSelection );
9674 + $builderForm.on( 'change', '.frm_logic_field_opts', getFieldValues );
9675 + $builderForm.on( 'change', '.radio_maxnum', setStarValues );
9676 + $builderForm.on( 'frm-multiselect-changed', 'select[name^="field_options[admin_only_"]', adjustVisibilityValuesForEveryoneValues );
9677 +
9678 + jQuery( document.getElementById( 'frm-insert-fields' ) ).on( 'click', '.frm_add_field', addFieldClick );
9679 + $newFields.on( 'click', '.frm_clone_field', duplicateField );
9680 + $builderForm.on( 'blur', 'input[id^="frm_calc"]', checkCalculationCreatedByUser );
9681 + $builderForm.on( 'change', 'input.frm_format_opt, input.frm_max_length_opt', toggleInvalidMsg );
9682 + $builderForm.on( 'change click', '[data-changeme]', liveChanges );
9683 + $builderForm.on( 'click', 'input.frm_req_field', markRequired );
9684 + $builderForm.on( 'click', '.frm_mark_unique', markUnique );
9685 +
9686 + $builderForm.on( 'change', '.frm_repeat_format', toggleRepeatButtons );
9687 + $builderForm.on( 'change', '.frm_repeat_limit', checkRepeatLimit );
9688 + $builderForm.on( 'change', '.frm_js_checkbox_limit', checkCheckboxSelectionsLimit );
9689 + $builderForm.on( 'input', 'input[name^="field_options[add_label_"]', function() {
9690 + updateRepeatText( this, 'add' );
9691 + });
9692 + $builderForm.on( 'input', 'input[name^="field_options[remove_label_"]', function() {
9693 + updateRepeatText( this, 'remove' );
9694 + });
9695 + $builderForm.on( 'change', 'select[name^="field_options[data_type_"]', maybeClearWatchFields );
9696 + jQuery( builderArea ).on( 'click', '.frm-collapse-page', maybeCollapsePage );
9697 + jQuery( builderArea ).on( 'click', '.frm-collapse-section', maybeCollapseSection );
9698 + $builderForm.on( 'click', '.frm-single-settings h3', maybeCollapseSettings );
9699 +
9700 + $builderForm.on( 'click', '.frm_toggle_sep_values', toggleSepValues );
9701 + $builderForm.on( 'click', '.frm_toggle_image_options', toggleImageOptions );
9702 + $builderForm.on( 'click', '.frm_remove_image_option', removeImageFromOption );
9703 + $builderForm.on( 'click', '.frm_choose_image_box', addImageToOption );
9704 + $builderForm.on( 'change', '.frm_hide_image_text', refreshOptionDisplay );
9705 + $builderForm.on( 'change', '.frm_field_options_image_size', setImageSize );
9706 + $builderForm.on( 'click', '.frm_multiselect_opt', toggleMultiselect );
9707 + $newFields.on( 'mousedown', 'input, textarea, select', stopFieldFocus );
9708 + $newFields.on( 'click', 'input[type=radio], input[type=checkbox]', stopFieldFocus );
9709 + $newFields.on( 'click', '.frm_delete_field', clickDeleteField );
9710 + $newFields.on( 'click', '.frm_select_field', clickSelectField );
9711 + jQuery( document ).on( 'click', '.frm_delete_field_group', clickDeleteFieldGroup );
9712 + jQuery( document ).on( 'click', '.frm_clone_field_group', duplicateFieldGroup );
9713 + jQuery( document ).on( 'click', '#frm_field_group_controls > span:first-child', clickFieldGroupLayout );
9714 + jQuery( document ).on( 'click', '.frm-row-layout-option', handleFieldGroupLayoutOptionClick );
9715 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-row-layout-option', handleFieldGroupLayoutOptionInsideMergeClick );
9716 + jQuery( document ).on( 'click', '.frm-custom-field-group-layout', customFieldGroupLayoutClick );
9717 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-custom-field-group-layout', customFieldGroupLayoutInsideMergeClick );
9718 + jQuery( document ).on( 'click', '.frm-break-field-group', breakFieldGroupClick );
9719 + $newFields.on( 'click', '#frm_field_group_popup .frm_grid_container input', focusFieldGroupInputOnClick );
9720 + jQuery( document ).on( 'click', '.frm-cancel-custom-field-group-layout', cancelCustomFieldGroupClick );
9721 + jQuery( document ).on( 'click', '.frm-save-custom-field-group-layout', saveCustomFieldGroupClick );
9722 + $newFields.on( 'click', 'ul.frm_sorting', fieldGroupClick );
9723 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row', mergeFieldsIntoRowClick );
9724 + jQuery( document ).on( 'click', '.frm-delete-field-groups', deleteFieldGroupsClick );
9725 + $newFields.on( 'click', '.frm-field-action-icons [data-toggle="dropdown"]', function() {
9726 + this.closest( 'li.form-field' ).classList.add( 'frm-field-settings-open' );
9727 + jQuery( document ).on( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings );
9728 + });
9729 + $newFields.on( 'mousemove', 'ul.frm_sorting', checkForMultiselectKeysOnMouseMove );
9730 + $newFields.on( 'show.bs.dropdown', '.frm-field-action-icons', onFieldActionDropdownShow );
9731 + jQuery( document ).on( 'show.bs.dropdown', '#frm_field_group_controls', onFieldGroupActionDropdownShow );
9732 + $builderForm.on( 'click', '.frm_single_option a[data-removeid]', deleteFieldOption );
9733 + $builderForm.on( 'mousedown', '.frm_single_option input[type=radio]', maybeUncheckRadio );
9734 + $builderForm.on( 'focusin', '.frm_single_option input[type=text]', maybeClearOptText );
9735 + $builderForm.on( 'click', '.frm_add_opt', addFieldOption );
9736 + $builderForm.on( 'change', '.frm_single_option input', resetOptOnChange );
9737 + $builderForm.on( 'change', '.frm_image_id', resetOptOnChange );
9738 + $builderForm.on( 'change', '.frm_toggle_mult_sel', toggleMultSel );
9739 + $builderForm.on( 'focusin', '.frm_classes', showBuilderModal );
9740 +
9741 + $newFields.on( 'click', '.frm_primary_label', clickLabel );
9742 + $newFields.on( 'click', '.frm_description', clickDescription );
9743 + $newFields.on( 'click', 'li.ui-state-default', clickVis );
9744 + $newFields.on( 'dblclick', 'li.ui-state-default', openAdvanced );
9745 + $builderForm.on( 'change', '.frm_tax_form_select', toggleFormTax );
9746 + $builderForm.on( 'change', 'select.conf_field', addConf );
9747 +
9748 + $builderForm.on( 'change', '.frm_get_field_selection', getFieldSelection );
9749 +
9750 + $builderForm.on( 'click', '.frm-show-inline-modal', maybeShowInlineModal );
9751 +
9752 + $builderForm.on( 'click', '.frm-inline-modal .dismiss', dismissInlineModal );
9753 + jQuery( document ).on( 'change', '[data-frmchange]', changeInputtedValue );
9754 +
9755 + $builderForm.on( 'change', '.frm_include_extras_field', rePopCalcFieldsForSummary );
9756 + $builderForm.on( 'change', 'select[name^="field_options[form_select_"]', maybeChangeEmbedFormMsg );
9757 +
9758 + jQuery( document ).on( 'submit', '#frm_js_build_form', buildSubmittedNoAjax );
9759 + 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 );
9760 +
9761 + popAllProductFields();
9762 +
9763 + jQuery( document ).on( 'change', '.frmjs_prod_data_type_opt', toggleProductType );
9764 +
9765 + jQuery( document ).on( 'focus', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextFocus );
9766 + jQuery( document ).on( 'blur', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextBlur );
9767 +
9768 + initBulkOptionsOverlay();
9769 + hideEmptyEle();
9770 + maybeHideQuantityProductFieldOption();
9771 + handleNameFieldOnFormBuilder();
9772 + toggleSectionHolder();
9773 + },
9774 +
9775 + settingsInit: function() {
9776 + const $formActions = jQuery( document.getElementById( 'frm_notification_settings' ) );
9777 +
9778 + let formSettings, $loggedIn, $cookieExp, $editable;
9779 +
9780 + // BCC, CC, and Reply To button functionality
9781 + $formActions.on( 'click', '.frm_email_buttons', showEmailRow );
9782 + $formActions.on( 'click', '.frm_remove_field', hideEmailRow );
9783 + $formActions.on( 'change', '.frm_to_row, .frm_from_row', showEmailWarning );
9784 + $formActions.on( 'change', '.frm_tax_selector', changePosttaxRow );
9785 + $formActions.on( 'change', 'select.frm_single_post_field', checkDupPost );
9786 + $formActions.on( 'change', 'select.frm_toggle_post_content', togglePostContent );
9787 + $formActions.on( 'change', 'select.frm_dyncontent_opt', fillDyncontent );
9788 + $formActions.on( 'change', '.frm_post_type', switchPostType );
9789 + $formActions.on( 'click', '.frm_add_postmeta_row', addPostmetaRow );
9790 + $formActions.on( 'click', '.frm_add_posttax_row', addPosttaxRow );
9791 + $formActions.on( 'click', '.frm_toggle_cf_opts', toggleCfOpts );
9792 + $formActions.on( 'click', '.frm_duplicate_form_action', copyFormAction );
9793 + jQuery( document ).on( 'change', 'select[data-toggleclass], input[data-toggleclass]', toggleFormOpts );
9794 + jQuery( '.frm_actions_list' ).on( 'click', '.frm_active_action', addFormAction );
9795 + jQuery( '#frm-show-groups, #frm-hide-groups' ).on( 'click', toggleActionGroups );
9796 + initiateMultiselect();
9797 +
9798 + //set actions icons to inactive
9799 + jQuery( 'ul.frm_actions_list li' ).each( function() {
9800 + checkActiveAction( jQuery( this ).children( 'a' ).data( 'actiontype' ) );
9801 +
9802 + // If the icon is a background image, don't add BG color.
9803 + const icon = jQuery( this ).find( 'i' );
9804 + if ( icon.css( 'background-image' ) !== 'none' ) {
9805 + icon.addClass( 'frm-inverse' );
9806 + }
9807 + });
9808 +
9809 + jQuery( '.frm_submit_settings_btn' ).on( 'click', submitSettings );
9810 +
9811 + formSettings = jQuery( '.frm_form_settings' );
9812 + formSettings.on( 'click', '.frm_add_form_logic', addFormLogicRow );
9813 + formSettings.on( 'blur', '.frm_email_blur', formatEmailSetting );
9814 + formSettings.on( 'click', '.frm_already_used', onlyOneActionMessage );
9815 +
9816 + formSettings.on( 'change', '#logic_link_submit', toggleSubmitLogic );
9817 + formSettings.on( 'click', '.frm_add_submit_logic', addSubmitLogic );
9818 + formSettings.on( 'change', '.frm_submit_logic_field_opts', addSubmitLogicOpts );
9819 +
9820 + document.addEventListener(
9821 + 'click',
9822 + function handleImageUploadClickEvents( event ) {
9823 + const { target } = event;
9824 +
9825 + if ( ! target.closest( '.frm_image_preview_wrapper' ) ) {
9826 + return;
9827 + }
9828 +
9829 + if ( target.closest( '.frm_choose_image_box' ) ) {
9830 + addImageToOption.bind( target )( event );
9831 + return;
9832 + }
9833 +
9834 + if ( target.closest( '.frm_remove_image_option' ) ) {
9835 + removeImageFromOption.bind( target )( event );
9836 + }
9837 + }
9838 + );
9839 +
9840 + // Close shortcode modal on click.
9841 + formSettings.on( 'mouseup', '*:not(.frm-show-box)', function( e ) {
9842 + e.stopPropagation();
9843 +
9844 + if ( e.target.classList.contains( 'frm-show-box' ) || e.target.parentElement.classList.contains( 'frm-show-box' ) ) {
9845 + return;
9846 + }
9847 +
9848 + const sidebar = document.getElementById( 'frm_adv_info' );
9849 + if ( ! sidebar ) {
9850 + return;
9851 + }
9852 +
9853 + if ( sidebar.getAttribute( 'data-fills' ) === e.target.id && typeof e.target.id !== 'undefined' ) {
9854 + return;
9855 + }
9856 +
9857 + const isChild = jQuery( e.target ).closest( '#frm_adv_info' ).length > 0;
9858 +
9859 + if ( ! isChild && sidebar.display !== 'none' ) {
9860 + hideShortcodes( sidebar );
9861 + }
9862 + });
9863 +
9864 + //Warning when user selects "Do not store entries ..."
9865 + jQuery( document.getElementById( 'no_save' ) ).on( 'change', function() {
9866 + if ( this.checked ) {
9867 + if ( confirm( frm_admin_js.no_save_warning ) !== true ) {
9868 + // Uncheck box if user hits "Cancel"
9869 + jQuery( this ).attr( 'checked', false );
9870 + }
9871 + }
9872 + });
9873 +
9874 + //Show/hide Messages header
9875 + jQuery( '#editable, #edit_action, #save_draft, #success_action' ).on( 'change', function() {
9876 + maybeShowFormMessages();
9877 + });
9878 + jQuery( 'select[name="options[success_action]"], select[name="options[edit_action]"]' ).on( 'change', showSuccessOpt );
9879 +
9880 + $loggedIn = document.getElementById( 'logged_in' );
9881 + jQuery( $loggedIn ).on( 'change', function() {
9882 + if ( this.checked ) {
9883 + visible( '.hide_logged_in' );
9884 + } else {
9885 + invisible( '.hide_logged_in' );
9886 + }
9887 + });
9888 +
9889 + $cookieExp = jQuery( document.getElementById( 'frm_cookie_expiration' ) );
9890 + jQuery( document.getElementById( 'frm_single_entry_type' ) ).on( 'change', function() {
9891 + if ( this.value === 'cookie' ) {
9892 + $cookieExp.fadeIn( 'slow' );
9893 + } else {
9894 + $cookieExp.fadeOut( 'slow' );
9895 + }
9896 + });
9897 +
9898 + var $singleEntry = document.getElementById( 'single_entry' );
9899 + jQuery( $singleEntry ).on( 'change', function() {
9900 + if ( this.checked ) {
9901 + visible( '.hide_single_entry' );
9902 + } else {
9903 + invisible( '.hide_single_entry' );
9904 + }
9905 +
9906 + if ( this.checked && jQuery( document.getElementById( 'frm_single_entry_type' ) ).val() === 'cookie' ) {
9907 + $cookieExp.fadeIn( 'slow' );
9908 + } else {
9909 + $cookieExp.fadeOut( 'slow' );
9910 + }
9911 + });
9912 +
9913 + jQuery( '.hide_save_draft' ).hide();
9914 +
9915 + var $saveDraft = jQuery( document.getElementById( 'save_draft' ) );
9916 + $saveDraft.on( 'change', function() {
9917 + if ( this.checked ) {
9918 + jQuery( '.hide_save_draft' ).fadeIn( 'slow' );
9919 + } else {
9920 + jQuery( '.hide_save_draft' ).fadeOut( 'slow' );
9921 + }
9922 + });
9923 + triggerChange( $saveDraft );
9924 +
9925 + //If Allow editing is checked/unchecked
9926 + $editable = document.getElementById( 'editable' );
9927 + jQuery( $editable ).on( 'change', function() {
9928 + if ( this.checked ) {
9929 + jQuery( '.hide_editable' ).fadeIn( 'slow' );
9930 + triggerChange( document.getElementById( 'edit_action' ) );
9931 + } else {
9932 + jQuery( '.hide_editable' ).fadeOut( 'slow' );
9933 + jQuery( '.edit_action_message_box' ).fadeOut( 'slow' );//Hide On Update message box
9934 + }
9935 + });
9936 +
9937 + //If File Protection is checked/unchecked
9938 + jQuery( document ).on( 'change', '#protect_files', function() {
9939 + if ( this.checked ) {
9940 + jQuery( '.hide_protect_files' ).fadeIn( 'slow' );
9941 + } else {
9942 + jQuery( '.hide_protect_files' ).fadeOut( 'slow' );
9943 + }
9944 + });
9945 +
9946 + jQuery( document ).on( 'frm-multiselect-changed', '#protect_files_role', adjustVisibilityValuesForEveryoneValues );
9947 +
9948 + jQuery( document ).on( 'submit', '.frm_form_settings', settingsSubmitted );
9949 + jQuery( document ).on( 'change', '#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea', fieldUpdated );
9950 +
9951 + // Page Selection Autocomplete
9952 + initSelectionAutocomplete();
9953 +
9954 + jQuery( document ).on( 'frm-action-loaded', onActionLoaded );
9955 + },
9956 +
9957 + panelInit: function() {
9958 + var customPanel, settingsPage, viewPage, insertFieldsTab;
9959 +
9960 + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'click', '.frm_insert_code', insertCode );
9961 + jQuery( document ).on( 'change', '.frm_insert_val', function() {
9962 + insertFieldCode( jQuery( this ).data( 'target' ), jQuery( this ).val() );
9963 + jQuery( this ).val( '' );
9964 + });
9965 +
9966 + jQuery( document ).on( 'click change', '#frm-id-key-condition', resetLogicBuilder );
9967 + jQuery( document ).on( 'keyup change', '.frm-build-logic', setLogicExample );
9968 +
9969 + showInputIcon();
9970 + jQuery( document ).on( 'frmElementAdded', function( event, parentEle ) {
9971 + /* This is here for add-ons to trigger */
9972 + showInputIcon( parentEle );
9973 + });
9974 + jQuery( document ).on( 'mousedown', '.frm-show-box', showShortcodes );
9975 +
9976 + settingsPage = document.getElementById( 'form_settings_page' );
9977 + viewPage = document.body.classList.contains( 'post-type-frm_display' );
9978 + insertFieldsTab = document.getElementById( 'frm_insert_fields_tab' );
9979 +
9980 + if ( settingsPage !== null || viewPage ) {
9981 + jQuery( document ).on( 'focusin', 'form input, form textarea', function( e ) {
9982 + var htmlTab;
9983 + e.stopPropagation();
9984 + maybeShowModal( this );
9985 +
9986 + if ( jQuery( this ).is( ':not(:submit, input[type=button], .frm-search-input, input[type=checkbox])' ) ) {
9987 + if ( jQuery( e.target ).closest( '#frm_adv_info' ).length ) {
9988 + // Don't trigger for fields inside of the modal.
9989 + return;
9990 + }
9991 +
9992 + if ( settingsPage !== null ) {
9993 + /* form settings page */
9994 + htmlTab = jQuery( '#frm_html_tab' );
9995 + if ( jQuery( this ).closest( '#html_settings' ).length > 0 ) {
9996 + htmlTab.show();
9997 + htmlTab.siblings().hide();
9998 + jQuery( '#frm_html_tab a' ).trigger( 'click' );
9999 + toggleAllowedHTML( this, e.type );
10000 + } else {
10001 + showElement( jQuery( '.frm-category-tabs li' ) );
10002 + insertFieldsTab.click();
10003 + htmlTab.hide();
10004 + htmlTab.siblings().show();
10005 + }
10006 + } else if ( viewPage ) {
10007 + // Run on view page.
10008 + toggleAllowedShortcodes( this.id, e.type );
10009 + }
10010 + }
10011 + });
10012 + }
10013 +
10014 + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'mousedown', '#frm_adv_info a, .frm_field_list a', function( e ) {
10015 + e.preventDefault();
10016 + });
10017 +
10018 + customPanel = jQuery( '#frm_adv_info' );
10019 + customPanel.on( 'click', '.subsubsub a.frmids', function( e ) {
10020 + toggleKeyID( 'frmids', e );
10021 + });
10022 + customPanel.on( 'click', '.subsubsub a.frmkeys', function( e ) {
10023 + toggleKeyID( 'frmkeys', e );
10024 + });
10025 + },
10026 +
10027 + viewInit: function() {
10028 + var $addRemove,
10029 + $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) );
10030 + $advInfo.before( '<div id="frm_position_ele"></div>' );
10031 + setupMenuOffset();
10032 +
10033 + jQuery( document ).on( 'blur', '#param', checkDetailPageSlug );
10034 + jQuery( document ).on( 'blur', 'input[name^="options[where_val]"]', checkFilterParamNames );
10035 +
10036 + // Show loading indicator.
10037 + jQuery( '#publish' ).on( 'mousedown', function() {
10038 + fieldsUpdated = 0;
10039 + this.classList.add( 'frm_loading_button' );
10040 + });
10041 +
10042 + // move content tabs
10043 + jQuery( '#frm_dyncontent .handlediv' ).before( jQuery( '#frm_dyncontent .nav-menus-php' ) );
10044 +
10045 + // click content tabs
10046 + jQuery( '.nav-tab-wrapper a' ).on( 'click', clickContentTab );
10047 +
10048 + // click tabs after panel is replaced with ajax
10049 + jQuery( '#side-sortables' ).on( 'click', '.frm_doing_ajax.categorydiv .category-tabs a', clickTabsAfterAjax );
10050 +
10051 + initToggleShortcodes();
10052 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' );
10053 +
10054 + jQuery( 'input[name="show_count"]' ).on( 'change', showCount );
10055 +
10056 + jQuery( document.getElementById( 'form_id' ) ).on( 'change', displayFormSelected );
10057 +
10058 + $addRemove = jQuery( '.frm_repeat_rows' );
10059 + $addRemove.on( 'click', '.frm_add_order_row', addOrderRow );
10060 + $addRemove.on( 'click', '.frm_add_where_row', addWhereRow );
10061 + $addRemove.on( 'change', '.frm_insert_where_options', insertWhereOptions );
10062 + $addRemove.on( 'change', '.frm_where_is_options', hideWhereOptions );
10063 +
10064 + setDefaultPostStatus();
10065 + },
10066 +
10067 + inboxInit: function() {
10068 + jQuery( '.frm_inbox_dismiss, footer .frm-button-secondary, footer .frm-button-primary' ).on( 'click', function( e ) {
10069 + var message = this.parentNode.parentNode,
10070 + key = message.getAttribute( 'data-message' ),
10071 + href = this.getAttribute( 'href' );
10072 +
10073 + if ( 'free_templates' === key && ! this.classList.contains( 'frm_inbox_dismiss' ) ) {
10074 + return;
10075 + }
10076 +
10077 + e.preventDefault();
10078 +
10079 + data = {
10080 + action: 'frm_inbox_dismiss',
10081 + key: key,
10082 + nonce: frmGlobal.nonce
10083 + };
10084 + postAjax( data, function() {
10085 + if ( href !== '#' ) {
10086 + window.location = href;
10087 + return true;
10088 + }
10089 + fadeOut( message, function() {
10090 + message.parentNode.removeChild( message );
10091 + });
10092 + });
10093 + });
10094 + jQuery( '#frm-dismiss-inbox' ).on( 'click', function( e ) {
10095 + data = {
10096 + action: 'frm_inbox_dismiss',
10097 + key: 'all',
10098 + nonce: frmGlobal.nonce
10099 + };
10100 + postAjax( data, function() {
10101 + fadeOut( document.getElementById( 'frm_message_list' ), function() {
10102 + document.getElementById( 'frm_empty_inbox' ).classList.remove( 'frm_hidden' );
10103 + });
10104 + });
10105 + });
10106 + },
10107 +
10108 + solutionInit: function() {
10109 + jQuery( document ).on( 'submit', '#frm-new-template', installTemplate );
10110 + },
10111 +
10112 + styleInit: function() {
10113 + const debouncedPreviewUpdate = debounce( changeStyling, 100 );
10114 +
10115 + collapseAllSections();
10116 +
10117 + document.getElementById( 'frm_field_height' ).addEventListener( 'change', textSquishCheck );
10118 + document.getElementById( 'frm_field_font_size' ).addEventListener( 'change', textSquishCheck );
10119 + document.getElementById( 'frm_field_pad' ).addEventListener( 'change', textSquishCheck );
10120 +
10121 + jQuery( 'input.hex' ).wpColorPicker({
10122 + change: function( event ) {
10123 + if ( null !== event.target.getAttribute( 'data-alpha-color-type' ) ) {
10124 + debouncedPreviewUpdate();
10125 + return;
10126 + } else {
10127 + const hexcolor = jQuery( this ).wpColorPicker( 'color' );
10128 + jQuery( event.target ).val( hexcolor ).trigger( 'change' );
10129 + }
10130 + }
10131 + });
10132 + jQuery( '.wp-color-result-text' ).text( function( i, oldText ) {
10133 + return oldText === 'Select Color' ? 'Select' : oldText;
10134 + });
10135 +
10136 + function changeStyling() {
10137 + 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();
10138 + locStr = JSON.stringify( locStr );
10139 + jQuery.ajax({
10140 + type: 'POST', url: ajaxurl,
10141 + data: {
10142 + action: 'frm_change_styling',
10143 + nonce: frmGlobal.nonce,
10144 + frm_style_setting: locStr
10145 + },
10146 + success: function( css ) {
10147 + document.getElementById( 'this_css' ).innerHTML = css;
10148 + }
10149 + });
10150 + }
10151 +
10152 + // update styling on change
10153 + jQuery( '#frm_styling_form .styling_settings' ).on( 'change', debouncedPreviewUpdate );
10154 +
10155 + // menu tabs
10156 + jQuery( '#menu-settings-column' ).on( 'click', function( e ) {
10157 + var panelId, wrapper,
10158 + target = jQuery( e.target );
10159 +
10160 + if ( e.target.className.indexOf( 'nav-tab-link' ) !== -1 ) {
10161 +
10162 + panelId = target.data( 'type' );
10163 +
10164 + wrapper = target.parents( '.accordion-section-content' ).first();
10165 +
10166 +
10167 + jQuery( '.tabs-panel-active', wrapper ).removeClass( 'tabs-panel-active' ).addClass( 'tabs-panel-inactive' );
10168 + jQuery( '#' + panelId, wrapper ).removeClass( 'tabs-panel-inactive' ).addClass( 'tabs-panel-active' );
10169 +
10170 + jQuery( '.tabs', wrapper ).removeClass( 'tabs' );
10171 + target.parent().addClass( 'tabs' );
10172 +
10173 + // select the search bar
10174 + jQuery( '.quick-search', wrapper ).trigger( 'focus' );
10175 +
10176 + e.preventDefault();
10177 + }
10178 + });
10179 +
10180 + jQuery( document ).on( 'change', '.frm-dropdown-menu input[type="radio"]', function() {
10181 + const radio = this;
10182 + const btnGrp = this.closest( '.btn-group' );
10183 + const btnId = btnGrp.getAttribute( 'id' );
10184 +
10185 + const select = document.getElementById( btnId.replace( '_select', '' ) );
10186 + if ( select ) {
10187 + select.value = radio.value;
10188 + }
10189 +
10190 + jQuery( btnGrp ).children( 'button' ).html( radio.nextElementSibling.innerHTML + ' <b class="caret"></b>' );
10191 +
10192 + const activeItem = btnGrp.querySelector( '.dropdown-item.active' );
10193 + if ( activeItem ) {
10194 + activeItem.classList.remove( 'active' );
10195 + }
10196 +
10197 + this.closest( '.dropdown-item' ).classList.add( 'active' );
10198 + });
10199 +
10200 + jQuery( '#frm_confirm_modal' ).on( 'click', '[data-resetstyle]', function( e ) {
10201 + var button = document.getElementById( 'frm_reset_style' );
10202 +
10203 + button.classList.add( 'frm_loading_button' );
10204 + e.stopPropagation();
10205 +
10206 + jQuery.ajax({
10207 + type: 'POST', url: ajaxurl,
10208 + data: {action: 'frm_settings_reset', nonce: frmGlobal.nonce},
10209 + success: function( errObj ) {
10210 + var key;
10211 + errObj = errObj.replace( /^\s+|\s+$/g, '' );
10212 + if ( errObj.indexOf( '{' ) === 0 ) {
10213 + errObj = JSON.parse( errObj );
10214 + }
10215 + for ( key in errObj ) {
10216 + jQuery( 'input[name$="[' + key + ']"], select[name$="[' + key + ']"]' ).val( errObj[key]);
10217 + }
10218 + jQuery( '#frm_submit_style, #frm_auto_width' ).prop( 'checked', false );
10219 + triggerChange( document.getElementById( 'frm_fieldset' ) );
10220 + button.classList.remove( 'frm_loading_button' );
10221 + }
10222 + });
10223 + });
10224 +
10225 + jQuery( '.frm_pro_form #datepicker_sample' ).datepicker({ changeMonth: true, changeYear: true });
10226 +
10227 + jQuery( document.getElementById( 'frm_position' ) ).on( 'change', setPosClass );
10228 +
10229 + jQuery( '.frm_image_preview_wrapper' ).on( 'click', '.frm_choose_image_box', addImageToOption );
10230 + jQuery( '.frm_image_preview_wrapper' ).on( 'click', '.frm_remove_image_option', removeImageFromOption );
10231 +
10232 + // Check floating label when focus or blur fields.
10233 + const floatingLabelSelector = '.frm_inside_container > input, .frm_inside_container > textarea, .frm_inside_container > select';
10234 + [ 'focus', 'blur', 'change' ].forEach( function( eventName ) {
10235 + documentOn(
10236 + eventName,
10237 + floatingLabelSelector,
10238 + function( event ) {
10239 + checkFloatingLabelsForStyles( event.target );
10240 + },
10241 + true
10242 + );
10243 + });
10244 +
10245 + // Trigger label position option on load.
10246 + const changeEvent = document.createEvent( 'HTMLEvents' );
10247 + changeEvent.initEvent( 'change', true, false );
10248 + document.getElementById( 'frm_position' ).dispatchEvent( changeEvent );
10249 + },
10250 +
10251 + customCSSInit: function() {
10252 + console.warn( 'Calling frmAdminBuild.customCSSInit is deprecated.' );
10253 + },
10254 +
10255 + globalSettingsInit: function() {
10256 + var licenseTab;
10257 +
10258 + jQuery( document ).on( 'click', '[data-frmuninstall]', uninstallNow );
10259 +
10260 + initiateMultiselect();
10261 +
10262 + // activate addon licenses
10263 + licenseTab = document.getElementById( 'licenses_settings' );
10264 + if ( licenseTab !== null ) {
10265 + jQuery( licenseTab ).on( 'click', '.edd_frm_save_license', saveAddonLicense );
10266 + }
10267 +
10268 + // Solution install page
10269 + jQuery( document ).on( 'click', '#frm-new-template button', installTemplateFieldset );
10270 +
10271 + jQuery( '#frm-dismissable-cta .dismiss' ).on( 'click', function( event ) {
10272 + event.preventDefault();
10273 + jQuery.post( ajaxurl, {
10274 + action: 'frm_lite_settings_upgrade'
10275 + });
10276 + jQuery( '.settings-lite-cta' ).remove();
10277 + });
10278 +
10279 + const captchaType = document.getElementById( 'frm_re_type' );
10280 + if ( captchaType ) {
10281 + captchaType.addEventListener( 'change', handleCaptchaTypeChange );
10282 + }
10283 + },
10284 +
10285 + exportInit: function() {
10286 + jQuery( '.frm_form_importer' ).on( 'submit', startFormMigration );
10287 + jQuery( document.getElementById( 'frm_export_xml' ) ).on( 'submit', validateExport );
10288 + jQuery( '#frm_export_xml input, #frm_export_xml select' ).on( 'change', removeExportError );
10289 + jQuery( 'input[name="frm_import_file"]' ).on( 'change', checkCSVExtension );
10290 + jQuery( 'select[name="format"]' ).on( 'change', checkExportTypes ).trigger( 'change' );
10291 + jQuery( 'input[name="frm_export_forms[]"]' ).on( 'click', preventMultipleExport );
10292 + initiateMultiselect();
10293 +
10294 + jQuery( '.frm-feature-banner .dismiss' ).on( 'click', function( event ) {
10295 + event.preventDefault();
10296 + jQuery.post( ajaxurl, {
10297 + action: 'frm_dismiss_migrator',
10298 + plugin: this.id,
10299 + nonce: frmGlobal.nonce
10300 + });
10301 + this.parentElement.remove();
10302 + });
10303 + },
10304 +
10305 + inboxBannerInit: function() {
10306 + const banner = document.getElementById( 'frm_banner' );
10307 + if ( ! banner ) {
10308 + return;
10309 + }
10310 +
10311 + const dismissButton = banner.querySelector( '.frm-banner-dismiss' );
10312 + document.addEventListener(
10313 + 'click',
10314 + function( event ) {
10315 + if ( event.target !== dismissButton ) {
10316 + return;
10317 + }
10318 +
10319 + const data = {
10320 + action: 'frm_inbox_dismiss',
10321 + key: banner.dataset.key,
10322 + nonce: frmGlobal.nonce
10323 + };
10324 + postAjax(
10325 + data,
10326 + function() {
10327 + jQuery( banner ).fadeOut(
10328 + 400,
10329 + function() {
10330 + banner.remove();
10331 + }
10332 + );
10333 + }
10334 + );
10335 + }
10336 + );
10337 + },
10338 +
10339 + updateOpts: function( fieldId, opts, modal ) {
10340 + var separate = usingSeparateValues( fieldId ),
10341 + action = isProductField( fieldId ) ? 'frm_bulk_products' : 'frm_import_options';
10342 + jQuery.ajax({
10343 + type: 'POST',
10344 + url: ajaxurl,
10345 + data: {
10346 + action: action,
10347 + field_id: fieldId,
10348 + opts: opts,
10349 + separate: separate,
10350 + nonce: frmGlobal.nonce
10351 + },
10352 + success: function( html ) {
10353 + document.getElementById( 'frm_field_' + fieldId + '_opts' ).innerHTML = html;
10354 + resetDisplayedOpts( fieldId );
10355 +
10356 + if ( typeof modal !== 'undefined' ) {
10357 + modal.dialog( 'close' );
10358 + document.getElementById( 'frm-update-bulk-opts' ).classList.remove( 'frm_loading_button' );
10359 + }
10360 + }
10361 + });
10362 + },
10363 +
10364 + /* remove conditional logic if the field doesn't exist */
10365 + triggerRemoveLogic: function( fieldID, metaName ) {
10366 + jQuery( '#frm_logic_' + fieldID + '_' + metaName + ' .frm_remove_tag' ).trigger( 'click' );
10367 + },
10368 +
10369 + downloadXML: function( controller, ids, isTemplate ) {
10370 + var url = ajaxurl + '?action=frm_' + controller + '_xml&ids=' + ids;
10371 + if ( isTemplate !== null ) {
10372 + url = url + '&is_template=' + isTemplate;
10373 + }
10374 + location.href = url;
10375 + },
10376 +
10377 + /**
10378 + * @since 5.0.04
10379 + */
10380 + hooks: {
10381 + applyFilters: function( hookName, ...args ) {
10382 + return wp.hooks.applyFilters( hookName, ...args );
10383 + },
10384 + addFilter: function( hookName, callback, priority ) {
10385 + return wp.hooks.addFilter( hookName, 'formidable', callback, priority );
10386 + }
10387 + }
10388 + };
10389 +}
10390 +
10391 +frmAdminBuild = frmAdminBuildJS();
10392 +
10393 +jQuery( document ).ready(
10394 + () => {
10395 + frmAdminBuild.init();
10396 +
10397 + frmDom.bootstrap.setupBootstrapDropdowns( convertOldBootstrapDropdownsToBootstrap4 );
10398 + function convertOldBootstrapDropdownsToBootstrap4( frmDropdownMenu ) {
10399 + const toggle = frmDropdownMenu.querySelector( '.frm-dropdown-toggle' );
10400 + if ( toggle ) {
10401 + if ( ! toggle.hasAttribute( 'role' ) ) {
10402 + toggle.setAttribute( 'role', 'button' );
10403 + }
10404 + if ( ! toggle.hasAttribute( 'tabindex' ) ) {
10405 + toggle.setAttribute( 'tabindex', 0 );
10406 + }
10407 + }
10408 +
10409 + // Convert <li> and <ul> tags.
10410 + if ( 'UL' === frmDropdownMenu.tagName ) {
10411 + convertBootstrapUl( frmDropdownMenu );
10412 + }
10413 + }
10414 +
10415 + function convertBootstrapUl( ul ) {
10416 + let html = ul.outerHTML;
10417 + html = html.replace( '<ul ', '<div ' );
10418 + html = html.replace( '</ul>', '</div>' );
10419 + html = html.replaceAll( '<li>', '<div class="dropdown-item">' );
10420 + html = html.replaceAll( '<li class="', '<div class="dropdown-item ' );
10421 + html = html.replaceAll( '</li>', '</div>' );
10422 + ul.outerHTML = html;
10423 + }
10424 + }
10425 +);
10426 +
10427 +function frm_remove_tag( htmlTag ) { // eslint-disable-line camelcase
10428 + console.warn( 'DEPRECATED: function frm_remove_tag in v2.0' );
10429 + jQuery( htmlTag ).remove();
10430 +}
10431 +
10432 +function frm_show_div( div, value, showIf, classId ) { // eslint-disable-line camelcase
10433 + if ( value == showIf ) {
10434 + jQuery( classId + div ).fadeIn( 'slow' ).css( 'visibility', 'visible' );
10435 + } else {
10436 + jQuery( classId + div ).fadeOut( 'slow' );
10437 + }
10438 +}
10439 +
10440 +function frmCheckAll( checked, n ) {
10441 + jQuery( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked );
10442 +}
10443 +
10444 +function frmCheckAllLevel( checked, n, level ) {
10445 + var $kids = jQuery( '.frm_catlevel_' + level ).children( '.frm_checkbox' ).children( 'label' );
10446 + $kids.children( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked );
10447 +}
10448 +
10449 +function frm_add_logic_row( id, formId ) { // eslint-disable-line camelcase
10450 + console.warn( 'DEPRECATED: function frm_add_logic_row in v2.0' );
10451 + jQuery.ajax({
10452 + type: 'POST',
10453 + url: ajaxurl,
10454 + data: {
10455 + action: 'frm_add_logic_row',
10456 + form_id: formId,
10457 + field_id: id,
10458 + meta_name: jQuery( '#frm_logic_row_' + id + ' > div' ).length,
10459 + nonce: frmGlobal.nonce
10460 + },
10461 + success: function( html ) {
10462 + jQuery( '#frm_logic_row_' + id ).append( html );
10463 + }
10464 + });
10465 + return false;
10466 +}
10467 +
10468 +function frmGetFieldValues( fieldId, cur, rowNumber, fieldType, htmlName ) {
10469 +
10470 + if ( fieldId ) {
10471 + jQuery.ajax({
10472 + type: 'POST', url: ajaxurl,
10473 + 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,
10474 + success: function( msg ) {
10475 + document.getElementById( 'frm_show_selected_values_' + cur + '_' + rowNumber ).innerHTML = msg;
10476 + }
10477 + });
10478 + }
10479 +}
10480 +
10481 +function frmImportCsv( formID ) {
10482 + var urlVars = '';
10483 + if ( typeof __FRMURLVARS !== 'undefined' ) {
10484 + urlVars = __FRMURLVARS;
10485 + }
10486 +
10487 + jQuery.ajax({
10488 + type: 'POST', url: ajaxurl,
10489 + data: 'action=frm_import_csv&nonce=' + frmGlobal.nonce + '&frm_skip_cookie=1' + urlVars,
10490 + success: function( count ) {
10491 + var max = jQuery( '.frm_admin_progress_bar' ).attr( 'aria-valuemax' );
10492 + var imported = max - count;
10493 + var percent = ( imported / max ) * 100;
10494 + jQuery( '.frm_admin_progress_bar' ).css( 'width', percent + '%' ).attr( 'aria-valuenow', imported );
10495 +
10496 + if ( parseInt( count, 10 ) > 0 ) {
10497 + jQuery( '.frm_csv_remaining' ).html( count );
10498 + frmImportCsv( formID );
10499 + } else {
10500 + jQuery( document.getElementById( 'frm_import_message' ) ).html( frm_admin_js.import_complete );
10501 + setTimeout( function() {
10502 + location.href = '?page=formidable-entries&frm_action=list&form=' + formID + '&import-message=1';
10503 + }, 2000 );
10504 + }
10505 + }
10506 + });
10507 +}