PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.07
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.07
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 +9659 -1 6.295.0.07 View file →
@@ -1 +1,9659 @@
1 -(()=>{var e={65:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(8793),o=n(1323);function i(e){var t=(0,r.A)(e);return function(e){return(0,o.A)(t,e)}}},1323:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r={"!":function(e){return!e},"*":function(e,t){return e*t},"/":function(e,t){return e/t},"%":function(e,t){return e%t},"+":function(e,t){return e+t},"-":function(e,t){return e-t},"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"==":function(e,t){return e===t},"!=":function(e,t){return e!==t},"&&":function(e,t){return e&&t},"||":function(e,t){return e||t},"?:":function(e,t,n){if(e)throw t;return n}};function o(e,t){var n,o,i,a,l,s,c=[];for(n=0;n<e.length;n++){if(l=e[n],a=r[l]){for(o=a.length,i=Array(o);o--;)i[o]=c.pop();try{s=a.apply(null,i)}catch(e){return e}}else s=t.hasOwnProperty(l)?t[l]:+l;c.push(s)}return c[0]}},1364:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(65);function o(e){var t=(0,r.A)(e);return function(e){return+t({n:e})}}},8793:(e,t,n)=>{"use strict";var r,o,i,a;function l(e){for(var t,n,l,s,c=[],d=[];t=e.match(a);){for(n=t[0],(l=e.substr(0,t.index).trim())&&c.push(l);s=d.pop();){if(i[n]){if(i[n][0]===s){n=i[n][1]||n;break}}else if(o.indexOf(s)>=0||r[s]<r[n]){d.push(s);break}c.push(s)}i[n]||d.push(n),e=e.substr(t.index+n.length)}return(e=e.trim())&&c.push(e),c.concat(d.reverse())}n.d(t,{A:()=>l}),r={"(":9,"!":8,"*":7,"/":7,"%":7,"+":6,"-":6,"<":5,"<=":5,">":5,">=":5,"==":4,"!=":4,"&&":3,"||":2,"?":1,"?:":1},o=["(","?"],i={")":["("],":":["?","?:"]},a=/<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/},7521:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(6956),o=n(7395);const i=function(e,t){return function(n,i,a){var l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10,s=e[t];if((0,o.A)(n)&&(0,r.A)(i))if("function"==typeof a)if("number"==typeof l){var c={callback:a,priority:l,namespace:i};if(s[n]){var d,u=s[n].handlers;for(d=u.length;d>0&&!(l>=u[d-1].priority);d--);d===u.length?u[d]=c:u.splice(d,0,c),s.__current.forEach(function(e){e.name===n&&e.currentIndex>=d&&e.currentIndex++})}else s[n]={handlers:[c],runs:0};"hookAdded"!==n&&e.doAction("hookAdded",n,i,a,l)}else console.error("If specified, the hook priority must be a number.");else console.error("The hook callback must be a function.")}}},11:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){return function(){var n,r,o=e[t];return null!==(n=null===(r=o.__current[o.__current.length-1])||void 0===r?void 0:r.name)&&void 0!==n?n:null}}},5375:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(7395);const o=function(e,t){return function(n){var o=e[t];if((0,r.A)(n))return o[n]&&o[n].runs?o[n].runs:0}}},3561:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){return function(n){var r=e[t];return void 0===n?void 0!==r.__current[0]:!!r.__current[0]&&n===r.__current[0].name}}},8830:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){return function(n,r){var o=e[t];return void 0!==r?n in o&&o[n].handlers.some(function(e){return e.namespace===r}):n in o}}},7765:(e,t,n)=>{"use strict";n.d(t,{A:()=>f});var r=n(3029),o=n(7521),i=n(4194),a=n(8830),l=n(6763),s=n(11),c=n(3561),d=n(5375),u=function e(){(0,r.A)(this,e),this.actions=Object.create(null),this.actions.__current=[],this.filters=Object.create(null),this.filters.__current=[],this.addAction=(0,o.A)(this,"actions"),this.addFilter=(0,o.A)(this,"filters"),this.removeAction=(0,i.A)(this,"actions"),this.removeFilter=(0,i.A)(this,"filters"),this.hasAction=(0,a.A)(this,"actions"),this.hasFilter=(0,a.A)(this,"filters"),this.removeAllActions=(0,i.A)(this,"actions",!0),this.removeAllFilters=(0,i.A)(this,"filters",!0),this.doAction=(0,l.A)(this,"actions"),this.applyFilters=(0,l.A)(this,"filters",!0),this.currentAction=(0,s.A)(this,"actions"),this.currentFilter=(0,s.A)(this,"filters"),this.doingAction=(0,c.A)(this,"actions"),this.doingFilter=(0,c.A)(this,"filters"),this.didAction=(0,d.A)(this,"actions"),this.didFilter=(0,d.A)(this,"filters")};const f=function(){return new u}},4194:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(6956),o=n(7395);const i=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(i,a){var l=e[t];if((0,o.A)(i)&&(n||(0,r.A)(a))){if(!l[i])return 0;var s=0;if(n)s=l[i].handlers.length,l[i]={runs:l[i].runs,handlers:[]};else for(var c=l[i].handlers,d=function(e){c[e].namespace===a&&(c.splice(e,1),s++,l.__current.forEach(function(t){t.name===i&&t.currentIndex>=e&&t.currentIndex--}))},u=c.length-1;u>=0;u--)d(u);return"hookRemoved"!==i&&e.doAction("hookRemoved",i,a),s}}}},6763:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(r){var o=e[t];o[r]||(o[r]={handlers:[],runs:0}),o[r].runs++;for(var i=o[r].handlers,a=arguments.length,l=new Array(a>1?a-1:0),s=1;s<a;s++)l[s-1]=arguments[s];if(!i||!i.length)return n?l[0]:void 0;var c={name:r,currentIndex:0};for(o.__current.push(c);c.currentIndex<i.length;){var d=i[c.currentIndex].callback.apply(null,l);n&&(l[0]=d),c.currentIndex++}return o.__current.pop(),n?l[0]:void 0}}},2133:(e,t,n)=>{"use strict";n.d(t,{se:()=>r});var r=(0,n(7765).A)();r.addAction,r.addFilter,r.removeAction,r.removeFilter,r.hasAction,r.hasFilter,r.removeAllActions,r.removeAllFilters,r.doAction,r.applyFilters,r.currentAction,r.currentFilter,r.doingAction,r.doingFilter,r.didAction,r.didFilter,r.actions,r.filters},7395:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e){return"string"!=typeof e||""===e?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(e)?(console.error("The hook name cannot begin with `__`."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(e)||(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)}},6956:(e,t,n)=>{"use strict";n.d(t,{A:()=>r});const r=function(e){return"string"!=typeof e||""===e?(console.error("The namespace must be a non-empty string."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(e)||(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)}},772:(e,t,n)=>{"use strict";n.d(t,{h:()=>c});var r=n(4467),o=n(5397);function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach(function(t){(0,r.A)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var l={"":{plural_forms:function(e){return 1===e?0:1}}},s=/^i18n\.(n?gettext|has_translation)(_|$)/,c=function(e,t,n){var r=new o.A({}),i=new Set,c=function(){i.forEach(function(e){return e()})},d=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default";r.data[t]=a(a(a({},l),r.data[t]),e),r.data[t][""]=a(a({},l[""]),r.data[t][""])},u=function(e,t){d(e,t),c()},f=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default",t=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;return r.data[e]||d(void 0,e),r.dcnpgettext(e,t,n,o,i)},m=function(){return arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default"},_=function(e,t,r){var o=f(r,t,e);return n?(o=n.applyFilters("i18n.gettext_with_context",o,e,t,r),n.applyFilters("i18n.gettext_with_context_"+m(r),o,e,t,r)):o};if(e&&u(e,t),n){var p=function(e){s.test(e)&&c()};n.addAction("hookAdded","core/i18n",p),n.addAction("hookRemoved","core/i18n",p)}return{getLocaleData:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default";return r.data[e]},setLocaleData:u,resetLocaleData:function(e,t){r.data={},r.pluralForms={},u(e,t)},subscribe:function(e){return i.add(e),function(){return i.delete(e)}},__:function(e,t){var r=f(t,void 0,e);return n?(r=n.applyFilters("i18n.gettext",r,e,t),n.applyFilters("i18n.gettext_"+m(t),r,e,t)):r},_x:_,_n:function(e,t,r,o){var i=f(o,void 0,e,t,r);return n?(i=n.applyFilters("i18n.ngettext",i,e,t,r,o),n.applyFilters("i18n.ngettext_"+m(o),i,e,t,r,o)):i},_nx:function(e,t,r,o,i){var a=f(i,o,e,t,r);return n?(a=n.applyFilters("i18n.ngettext_with_context",a,e,t,r,o,i),n.applyFilters("i18n.ngettext_with_context_"+m(i),a,e,t,r,o,i)):a},isRTL:function(){return"rtl"===_("ltr","text direction")},hasTranslation:function(e,t,o){var i,a,l=t?t+""+e:e,s=!(null===(i=r.data)||void 0===i||null===(a=i[null!=o?o:"default"])||void 0===a||!a[l]);return n&&(s=n.applyFilters("i18n.has_translation",s,e,t,o),s=n.applyFilters("i18n.has_translation_"+m(o),s,e,t,o)),s}}}},5839:(e,t,n)=>{"use strict";n.d(t,{__:()=>a});var r=n(772),o=n(2133),i=(0,r.h)(void 0,void 0,o.se),a=(i.getLocaleData.bind(i),i.setLocaleData.bind(i),i.resetLocaleData.bind(i),i.subscribe.bind(i),i.__.bind(i));i._x.bind(i),i._n.bind(i),i._nx.bind(i),i.isRTL.bind(i),i.hasTranslation.bind(i)},9575:(e,t,n)=>{"use strict";n.d(t,{__:()=>r.__}),n(181),n(772);var r=n(5839)},181:(e,t,n)=>{"use strict";var r=n(8616),o=n.n(r);n(7604),o()(console.error)},1105:(e,t,n)=>{"use strict";n.r(t),n.d(t,{addonError:()=>f,afterAddonInstall:()=>u,extractErrorFromAddOnResponse:()=>d,toggleAddonState:()=>c});var r=n(9575);function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,a,l=[],s=!0,c=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(r=i.call(n)).done)&&(l.push(r.value),l.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw o}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var a=frmDom,l=a.div,s=a.svg;function c(e,t){var n,r=null!==(n=window.ajaxurl)&&void 0!==n?n:frm_js.ajax_url;jQuery(".frm-addon-error").remove();var o=jQuery(e),i=o.attr("rel"),a=o.parent(),l=a.parent().find(".addon-status-label");o.addClass("frm_loading_button"),jQuery.ajax({url:r,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:t,nonce:frmGlobal.nonce,plugin:i},success:function(e){var n,r,i;"string"!=typeof(e=null!==(n=null===(r=e)||void 0===r?void 0:r.data)&&void 0!==n?n:e)&&"string"==typeof e.message&&(void 0!==e.saveAndReload&&(i=e.saveAndReload),e=e.message);var s=d(e);s?f(s,a,o):(u(e,o,l,a,i,t),wp.hooks.doAction("frm_update_addon_state",e))},error:function(){o.removeClass("frm_loading_button")}})}function d(e){return"string"!=typeof e&&!e.success&&(e.form&&jQuery(e.form).is("#message")?{message:jQuery(e.form).find("p").html()}:e)}function u(e,t,n,i,a){var c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"frm_activate_addon",d=frm_admin_js,u=document.querySelectorAll(".frm-addon-status");u.forEach(function(t){t.textContent=e,t.style.display="block"}),t.css({opacity:"0"}),document.querySelectorAll(".frm-oneclick").forEach(function(e){e.style.display="none"}),function(){var e=document.getElementById("frm_upgrade_modal");if(e){e.classList.add("frm-success");var t=e.querySelector(".frm-upgrade-message");if(t){var n=t.querySelector("img");t.replaceChildren((0,r.__)("Great! Everything's ready to go!","formidable"),document.createElement("br"),(0,r.__)("You just need to refresh the builder so the new field becomes available.","formidable")),n&&t.append(n)}var o=document.querySelector(".frm-addon-status");o&&(o.textContent="");var i,a=e.querySelector(".frm-circled-icon");if(a)a.classList.add("frm-circled-icon-green"),null===(i=a.querySelector("svg"))||void 0===i||i.replaceWith(s({href:"#frm_checkmark_icon"}))}}();var f={frm_activate_addon:{class:"frm-addon-active",message:d.active},frm_deactivate_addon:{class:"frm-addon-installed",message:d.installed},frm_uninstall_addon:{class:"frm-addon-not-installed",message:d.not_installed}};f.frm_install_addon=f.frm_activate_addon;var _=o(n,1)[0];_&&(_.textContent=f[c].message);var p=o(i,1)[0].parentElement;p.classList.remove("frm-addon-not-installed","frm-addon-installed","frm-addon-active"),p.classList.add(f[c].class),o(t,1)[0].classList.remove("frm_loading_button"),document.querySelectorAll(".frm-admin-page-import, #frm-admin-smtp, #frm-welcome").length>0?window.location.reload():["settings","form_builder"].includes(a)&&u.forEach(function(e){var t=null!==e.closest("#frm_upgrade_modal");e.append(function(e,t){var n,o=[m(e)];return t&&o.push(((n=document.createElement("a")).setAttribute("href","#"),n.classList.add("button","button-secondary","frm-button-secondary","dismiss"),n.textContent=(0,r.__)("Not Now","formidable"),n)),l({className:"frm-save-and-reload-options",children:o})}(a,t))})}function f(e,t,n){e.form?(jQuery(".frm-inline-error").remove(),n.closest(".frm-card").html(e.form).css({padding:5}).find("#upgrade").attr("rel",n.attr("rel")).on("click",_)):(t.append('<div class="frm-addon-error frm_error_style"><p><strong>'.concat(e.message,"</strong></p></div>")),n.removeClass("frm_loading_button"),jQuery(".frm-addon-error").delay(4e3).fadeOut())}function m(e){var t=document.createElement("button");return t.classList.add("frm-save-and-reload","button","button-primary","frm-button-primary"),t.textContent=(0,r.__)("Save and Reload","formidable"),t.addEventListener("click",function(){var t;"form_builder"===e?((t=document.getElementById("frm_submit_side_top")).classList.contains("frm_submit_ajax")&&t.setAttribute("data-new-addon-installed",!0),t.click()):"settings"===e&&function(){var e=document.getElementById("form_settings_page");if(null!==e){var t=e.querySelector("form.frm_form_settings");null!==t&&(wp.hooks.doAction("frm_reset_fields_updated"),t.submit())}}()}),t}function _(e){e.preventDefault();var t=jQuery(this),n=t.parent().parent(),r=t.attr("rel");t.addClass("frm_loading_button"),jQuery.ajax({url:ajaxurl,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:"frm_install_addon",nonce:frmAdminJs.nonce,plugin:r,hostname:n.find("#hostname").val(),username:n.find("#username").val(),password:n.find("#password").val()},success:function(e){var r,o,i=d(e=null!==(r=null===(o=e)||void 0===o?void 0:o.data)&&void 0!==r?r:e);i?f(i,n,t):u(e,t,message,n)},error:function(){t.removeClass("frm_loading_button")}})}},4260:(e,t,n)=>{"use strict";n.r(t),n.d(t,{addOneClick:()=>i,initModal:()=>a,initUpgradeModal:()=>l});var r=n(9575),o=frmDom.svg;function i(e,t,n){var i;if("modal"===t)i=document.getElementById("frm_upgrade_modal");else{if("tab"!==t)return;i=document.getElementById(e.getAttribute("href").substr(1))}var a,l=i.querySelector(".frm-oneclick"),s=i.querySelector(".frm-upgrade-message"),c=i.querySelector(".frm-upgrade-link"),d=i.querySelector(".frm-oneclick-button"),u=i.querySelector(".frm-addon-status"),f=e.getAttribute("data-oneclick"),m=e.getAttribute("data-message"),_="block",p="block",g="none",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&&(v.href=e.dataset.learnMore),null!==l&&null!==d&&void 0!==f&&f){null===m&&(p="none"),_="none",g="block",f=JSON.parse(f),d.className=d.className.replace(" frm-install-addon","").replace(" frm-activate-addon",""),d.className="".concat(d.className," ").concat(f.class),d.rel=f.url,l.textContent=(0,r.__)("This plugin is not activated. Would you like to activate it now?","formidable"),d.textContent=(0,r.__)("Activate","formidable");var h=e.querySelector("use");h&&(null==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!==n&&(m=m.replace('<span class="frm_feature_label"></span>',n)),s.innerHTML=m,e.dataset.upsellImage&&s.append(frmDom.img({src:e.dataset.upsellImage,alt:e.dataset.upgrade})),c.href=function(e,t){var n=e.getAttribute("data-link");return null!=n&&""!==n||(n=t.getAttribute("data-default")),n}(e,c),u.style.display="none",l&&(l.style.display=g),d&&(d.style.display="block"===g?"inline-block":g),s.style.display=p,c.style.display="block"===_?"inline-block":_;var b=c.closest(".frm-upgrade-modal-actions");b&&(b.style.display="block"===_?"flex":_)}function a(e,t){var n=jQuery(e);if(!n.length)return!1;void 0===t&&(t="552px");var r={dialogClass:"frm-dialog",modal:!0,autoOpen:!1,closeOnEscape:!0,width:t,resizable:!1,draggable:!1,open:function(){var e,t;jQuery(".ui-dialog-titlebar").addClass("frm_hidden").removeClass("ui-helper-clearfix"),jQuery("#wpwrap").addClass("frm_overlay"),jQuery(".frm-dialog").removeClass("ui-widget ui-widget-content ui-corner-all"),n.removeClass("ui-dialog-content ui-widget-content"),e=n,t=function(){e.dialog("close")},jQuery(".ui-widget-overlay").on("click",t),e.on("click","a.dismiss",t)},close:function(){jQuery("#wpwrap").removeClass("frm_overlay"),jQuery(".spinner").css("visibility","hidden"),this.removeAttribute("data-option-type");var e=document.getElementById("bulk-option-type");e&&(e.value="")}};return n.dialog(r),n}function l(){var e=a("#frm_upgrade_modal");function t(t){var n,o,a;if((n=t.target).classList){var l=n.classList.contains("frm_show_expired_modal")||null!==n.querySelector(".frm_show_expired_modal")||n.closest(".frm_show_expired_modal");if("change"===t.type&&n.classList.contains("frm_select_with_upgrade")){var s=n.options[n.selectedIndex];s&&s.dataset.upgrade&&(n=s)}if(!n.dataset.upgrade){var c=n.closest("[data-upgrade]");if(!c){if(!(c=n.closest(".frm_field_box")))return;n.dataset.upgrade=""}n=c}if(l)wp.hooks.doAction("frm_show_expired_modal",n);else{var d=n.dataset.upgrade;if(d&&!n.classList.contains("frm_show_upgrade_tab")){t.preventDefault();var u=e.get(0);u.classList.remove("frm-success");var f=u.querySelector(".frm_lock_icon");f&&(f.style.display="block",f.classList.remove("frm_lock_open_icon"),f.querySelector("use").setAttribute("href","#frm_lock_icon"));var m="frm_upgrade_modal_image",_=document.getElementById(m);_&&_.remove(),n.dataset.image&&f&&(f.style.display="none",f.parentNode.insertBefore(frmDom.img({id:m,src:"".concat(frmGlobal.url,"/images/").concat(n.dataset.image)}),f));var p=u.querySelector(".license-level");p&&(p.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(n)),i(n,"modal",d);var g=u.querySelector(".frm_are_not_installed");g.style.display=n.dataset.image||n.dataset.oneclick?"none":"inline-block",g.textContent=g.dataset.default,u.querySelector(".frm-upgrade-modal-title-prefix").style.display=n.dataset.oneclick?"inline":"none",u.querySelector(".frm_feature_label").textContent=d,u.querySelector(".frm-upgrade-modal-title-suffix").style.display="none",u.querySelector("h2").style.display="block",e.dialog("open");var y=u.querySelector(".button-primary:not(.frm-oneclick-button)");o=y.getAttribute("href").replace(/(medium=)[a-z_-]+/gi,"$1".concat(n.getAttribute("data-medium"))),null===(a=n.getAttribute("data-content"))&&(a=""),o=o.replace(/(content=)[a-z_-]+/gi,"$1".concat(a)),y.setAttribute("href",o),n.classList.contains("frm_show_update")&&function(e){var t=e.querySelector(".frm-upgrade-modal-title-prefix");t&&(t.style.display="none");var n=e.querySelector(".frm_are_not_installed");n&&(n.textContent=(0,r.__)("require an update","formidable"),n.style.display="");var o=e.querySelector(".frm-oneclick");o&&(o.style.display="none");var i=e.querySelector(".frm-oneclick-button");i&&(i.textContent=(0,r.__)("Update Now","formidable"))}(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 n,r,o=0;function i(){var i,a,l=n,s=arguments.length;e:for(;l;){if(l.args.length===arguments.length){for(a=0;a<s;a++)if(l.args[a]!==arguments[a]){l=l.next;continue e}return l!==n&&(l===r&&(r=l.prev),l.prev.next=l.next,l.next&&(l.next.prev=l.prev),l.next=n,l.prev=null,n.prev=l,n=l),l.val}l=l.next}for(i=new Array(s),a=0;a<s;a++)i[a]=arguments[a];return l={args:i,val:e.apply(null,i)},n?(n.prev=l,l.next=n):r=l,o===t.maxSize?(r=r.prev).next=null:o++,n=l,l.val}return t=t||{},i.clear=function(){n=null,r=null,o=0},i}},7604:(e,t,n)=>{var r;!function(){"use strict";var o={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function i(e){return function(e,t){var n,r,a,l,s,c,d,u,f,m=1,_=e.length,p="";for(r=0;r<_;r++)if("string"==typeof e[r])p+=e[r];else if("object"==typeof e[r]){if((l=e[r]).keys)for(n=t[m],a=0;a<l.keys.length;a++){if(null==n)throw new Error(i('[sprintf] Cannot access property "%s" of undefined value "%s"',l.keys[a],l.keys[a-1]));n=n[l.keys[a]]}else n=l.param_no?t[l.param_no]:t[m++];if(o.not_type.test(l.type)&&o.not_primitive.test(l.type)&&n instanceof Function&&(n=n()),o.numeric_arg.test(l.type)&&"number"!=typeof n&&isNaN(n))throw new TypeError(i("[sprintf] expecting number but found %T",n));switch(o.number.test(l.type)&&(u=n>=0),l.type){case"b":n=parseInt(n,10).toString(2);break;case"c":n=String.fromCharCode(parseInt(n,10));break;case"d":case"i":n=parseInt(n,10);break;case"j":n=JSON.stringify(n,null,l.width?parseInt(l.width):0);break;case"e":n=l.precision?parseFloat(n).toExponential(l.precision):parseFloat(n).toExponential();break;case"f":n=l.precision?parseFloat(n).toFixed(l.precision):parseFloat(n);break;case"g":n=l.precision?String(Number(n.toPrecision(l.precision))):parseFloat(n);break;case"o":n=(parseInt(n,10)>>>0).toString(8);break;case"s":n=String(n),n=l.precision?n.substring(0,l.precision):n;break;case"t":n=String(!!n),n=l.precision?n.substring(0,l.precision):n;break;case"T":n=Object.prototype.toString.call(n).slice(8,-1).toLowerCase(),n=l.precision?n.substring(0,l.precision):n;break;case"u":n=parseInt(n,10)>>>0;break;case"v":n=n.valueOf(),n=l.precision?n.substring(0,l.precision):n;break;case"x":n=(parseInt(n,10)>>>0).toString(16);break;case"X":n=(parseInt(n,10)>>>0).toString(16).toUpperCase()}o.json.test(l.type)?p+=n:(!o.number.test(l.type)||u&&!l.sign?f="":(f=u?"+":"-",n=n.toString().replace(o.sign,"")),c=l.pad_char?"0"===l.pad_char?"0":l.pad_char.charAt(1):" ",d=l.width-(f+n).length,s=l.width&&d>0?c.repeat(d):"",p+=l.align?f+n+s:"0"===c?f+s+n:s+f+n)}return p}(function(e){if(l[e])return l[e];for(var t,n=e,r=[],i=0;n;){if(null!==(t=o.text.exec(n)))r.push(t[0]);else if(null!==(t=o.modulo.exec(n)))r.push("%");else{if(null===(t=o.placeholder.exec(n)))throw new SyntaxError("[sprintf] unexpected placeholder");if(t[2]){i|=1;var a=[],s=t[2],c=[];if(null===(c=o.key.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(a.push(c[1]);""!==(s=s.substring(c[0].length));)if(null!==(c=o.key_access.exec(s)))a.push(c[1]);else{if(null===(c=o.index_access.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");a.push(c[1])}t[2]=a}else i|=2;if(3===i)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");r.push({placeholder:t[0],param_no:t[1],keys:t[2],sign:t[3],pad_char:t[4],align:t[5],width:t[6],precision:t[7],type:t[8]})}n=n.substring(t[0].length)}return l[e]=r}(e),arguments)}function a(e,t){return i.apply(null,[e].concat(t||[]))}var l=Object.create(null);"undefined"!=typeof window&&(window.sprintf=i,window.vsprintf=a,void 0===(r=function(){return{sprintf:i,vsprintf:a}}.call(t,n,t,e))||(e.exports=r))}()},5397:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(1364),o={contextDelimiter:"",onMissingKey:null};function i(e,t){var n;for(n in this.data=e,this.pluralForms={},this.options={},o)this.options[n]=void 0!==t&&n in t?t[n]:o[n]}i.prototype.getPluralForm=function(e,t){var n,o,i,a=this.pluralForms[e];return a||("function"!=typeof(i=(n=this.data[e][""])["Plural-Forms"]||n["plural-forms"]||n.plural_forms)&&(o=function(e){var t,n,r;for(t=e.split(";"),n=0;n<t.length;n++)if(0===(r=t[n].trim()).indexOf("plural="))return r.substr(7)}(n["Plural-Forms"]||n["plural-forms"]||n.plural_forms),i=(0,r.A)(o)),a=this.pluralForms[e]=i),a(t)},i.prototype.dcnpgettext=function(e,t,n,r,o){var i,a,l;return i=void 0===o?0:this.getPluralForm(e,o),a=n,t&&(a=t+this.options.contextDelimiter+n),(l=this.data[e][a])&&l[i]?l[i]:(this.options.onMissingKey&&this.options.onMissingKey(n,e),0===i?n:r)}},3029:(e,t,n)=>{"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}n.d(t,{A:()=>r})},4467:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(9922);function o(e,t,n){return(t=(0,r.A)(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},2327:(e,t,n)=>{"use strict";n.d(t,{A:()=>o});var r=n(2284);function o(e,t){if("object"!=(0,r.A)(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=(0,r.A)(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}},9922:(e,t,n)=>{"use strict";n.d(t,{A:()=>i});var r=n(2284),o=n(2327);function i(e){var t=(0,o.A)(e,"string");return"symbol"==(0,r.A)(t)?t:t+""}},2284:(e,t,n)=>{"use strict";function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}n.d(t,{A:()=>r})}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}function r(e){return function(e){if(Array.isArray(e))return i(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||o(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,t){if(e){if("string"==typeof e)return i(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function a(e){return a="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},a(e)}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},window.FrmFormsConnect=window.FrmFormsConnect||function(e,t,n){var r={messageBox:null,reset:null,setElements:function(){r.messageBox=e.querySelector(".frm_pro_license_msg"),r.reset=e.getElementById("frm_reconnect_link")}},o={init:function(){r.setElements(),n(e.getElementById("frm_deauthorize_link")).on("click",o.deauthorize),n(".frm_authorize_link").on("click",o.authorize),n(".frm-dashboard-license-options").on("click","#frm_deauthorize_link",o.deauthorize),n(".frm-dashboard-license-options").on("click","#frm_reconnect_link",o.reauthorize),null!==r.reset&&n(r.reset).on("click",o.reauthorize)},authorize:function(){var t=this,r=this.getAttribute("data-plugin"),i=e.getElementById("edd_".concat(r,"_license_key")),a=i.value,l=e.getElementById("proplug-wpmu");this.classList.add("frm_loading_button"),l=null===l?0:l.checked?1:0,n.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_activate",license:a,plugin:r,wpmu:l,nonce:frmGlobal.nonce},success:function(e){o.afterAuthorize(e,i),t.classList.remove("frm_loading_button")}})},afterAuthorize:function(e,t){!0===e.success&&(t.value="•••••••••••••••••••"),wp.hooks.doAction("frm_after_authorize",e),o.showMessage(e)},showProgress:function(e){null===r.messageBox&&r.setElements();var t=r.messageBox;null!==t&&(!0===e.success?(t.classList.remove("frm_error_style"),t.classList.add("frm_message","frm_updated_message")):(t.classList.add("frm_error_style"),t.classList.remove("frm_message","frm_updated_message")),t.classList.remove("frm_hidden"),t.innerHTML=e.message)},showMessage:function(n){null===r.messageBox&&r.setElements();var i=r.messageBox;!0===n.success&&(o.showAuthorized(!0),o.showInlineSuccess(),wp.hooks.doAction("frmAdmin.afterLicenseAuthorizeSuccess",{msg:n})),o.showProgress(n),""!==n.message&&(setTimeout(function(){i.innerHTML="",i.classList.add("frm_hidden"),i.classList.remove("frm_error_style","frm_message","frm_updated_message")},1e4),e.querySelector(".frm-admin-page-dashboard")&&setTimeout(function(){t.location.reload()},1e3))},showAuthorized:function(t){var n=t?"unauthorized":"authorized",r=t?"authorized":"unauthorized",o=e.querySelectorAll(".frm_".concat(n,"_box"));o.length&&o.forEach(function(e){e.className=e.className.replace("frm_".concat(n,"_box"),"frm_".concat(r,"_box"))})},showInlineSuccess:function(){var t=e.querySelectorAll(".frm-confirm-msg [data-success]");t.length&&t.forEach(function(e){e.innerHTML=frmAdminBuild.purifyHtml(e.getAttribute("data-success"))})},reauthorize:function(){return this.innerHTML='<span class="frm-wait frm_spinner" style="visibility:visible;float:none"></span>',n.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_reset_cache",plugin:"formidable_pro",nonce:frmGlobal.nonce},success:function(e){r.reset.textContent=e.message,"1"===r.reset.getAttribute("data-refresh")&&t.location.reload()}}),!1},deauthorize:function(){if(!confirm(frmGlobal.deauthorize))return!1;var t=this.getAttribute("data-plugin"),r=e.getElementById("edd_".concat(t,"_license_key")),i=r.value,a=this;return this.innerHTML='<span class="frm-wait frm_spinner" style="visibility:visible;"></span>',n.ajax({type:"POST",url:ajaxurl,data:{action:"frm_addon_deactivate",license:i,plugin:t,nonce:frmGlobal.nonce},success:function(){o.showAuthorized(!1),r.value="",a.replaceWith("Disconnected"),wp.hooks.doAction("frmAdmin.afterLicenseDeauthorizeSuccess",{})}}),!1}};return o}(document,window,jQuery),window.frmAdminBuildJS=function(){var e,t,i=frm_admin_js,l=frmDom,s=l.tag,c=l.div,d=l.span,u=l.a,f=l.svg,m=l.img,_=frmDom.util.onClickPreventDefault,p=frmDom.ajax.doJsonPost;i.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:f({href:"#frm_save_icon"}),drag:f({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,E=0,k=0,A={},S=0,L=wp.i18n,I=L.__,B=L.sprintf,q={dragging:!1};null!==w&&(E=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"),n=e.getAttribute("data-loaded-from");return null===t||"frm-confirmed-click"===e.id||("entries-list"===n?wp.hooks.applyFilters("frm_on_multiple_entries_delete",{link:e,initModal:Bi}):function(e){var t=Bi("#frm_confirm_modal","400px"),n=document.getElementById("frm-confirmed-click");if(!1===t)return!1;n&&(n.style.display="block");var r=e.getAttribute("data-frmverify"),o=r?e.getAttribute("data-frmverify-btn"):"",i=jQuery(".frm-confirm-msg");i.empty(),r&&(i.append(document.createTextNode(r)),o&&(null==n||n.classList.add(o)));var a=e.dataset;if(n){for(var l in n.dataset)n.removeAttribute("data-".concat(l));for(var s in a)"frmverify"!==s&&n.setAttribute("data-".concat(s),a[s])}return wp.hooks.doAction("frmAdmin.beforeOpenConfirmModal",{$info:t,link:e}),t.dialog("open"),null==n||n.setAttribute("href",e.getAttribute("href")||e.getAttribute("data-href")),!1}(e))}function M(e){var t=Bi("#frm_info_modal","400px");return!1===t||(jQuery(".frm-info-msg").html(e),t.dialog("open")),!1}function P(e){var t=this.getAttribute("data-frmtoggle"),n=this.getAttribute("data-toggletext"),r=jQuery(t);return e.preventDefault(),r.toggle(),null!==n&&""!==n&&(this.setAttribute("data-toggletext",this.innerHTML),this.textContent=n),!1}function H(e){var t=this.getAttribute("data-frmhide"),n=this.getAttribute("data-frmshow"),r=this.getAttribute("data-frmuncheck"),o=r?r.split(","):[];"INPUT"!==this.nodeName||"checkbox"!==this.type||this.checked||(null!==t?(n=t,t=null):null!==n&&(t=n,n=null)),e.preventDefault();var i=this.getAttribute("data-toggleclass")||"frm_hidden";null!==t&&jQuery(t).addClass(i),null!==n&&jQuery(n).removeClass(i);var a=this.parentNode.querySelectorAll("a.current");if(null!==a){for(var l=0;l<a.length;l++)a[l].classList.remove("current");this.classList.add("current")}return o.length&&o.forEach(function(e){var t=document.querySelector(e);t&&(t.checked=!1)}),!1}function z(){document.querySelectorAll(".tooltip").forEach(function(e){e.remove()})}function R(){var e,t,n;if(!parseInt(this.getAttribute("data-skip-frm-js"))&&!1!==D(this)){var r=jQuery(this),o=r.attr("data-removeid");void 0===(e=r.attr("data-showlast"))&&(e=""),void 0===(t=r.attr("data-hidelast"))&&(t=""),n=r.attr("data-removemore"),""!==e?r.closest(".frm_add_remove").find(".frm_remove_tag:visible").length>1&&(e="",t=""):0===o.indexOf("frm_postmeta_")&&(jQuery("#frm_postmeta_rows .frm_postmeta_row").length<2&&(e=".frm_add_postmeta_row.button"),jQuery(".frm_toggle_cf_opts").length&&jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().length&&(""!==e&&(e+=","),e+="#".concat(jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().attr("id")," .frm_toggle_cf_opts")));var i=document.getElementById(o),a=jQuery(i);return a.fadeOut(300,function(){var n;a.remove(),Po(),""!==t&&jQuery(t).hide(),""!==e&&jQuery("".concat(e," a,").concat(e)).removeClass("frm_hidden").fadeIn("slow"),this.closest(".frm_form_action_settings")&&function(e){so(e);var t={type:e};wp.hooks.doAction("frm_after_action_removed",t)}(this.closest(".frm_form_action_settings").querySelector(".frm_action_name").value),null===(n=document.querySelector(".tooltip"))||void 0===n||n.remove()}),void 0!==n&&(n=jQuery(n)).fadeOut(400,function(){n.remove()}),""!==e&&jQuery(this).closest(".frm_logic_rows").fadeOut("slow"),wp.hooks.doAction("frm_admin_tag_removed",o,i),!1}}function G(e,t){void 0===t&&(t=this),Ze(t,!1);var n=jQuery(t).closest(".frm_form_action_settings"),r=e.target;if(n.length&&void 0!==r){var o=r.parentElement.className;if("string"==typeof o&&(o.includes("frm_email_icons")||o.includes("frm_toggle")))return void e.stopPropagation()}var i=n.children(".widget-inside");if(n.length&&i.find("p, div, table").length<1){var a=n.find('input[name$="[ID]"]').val(),l=n.find('input[name$="[post_excerpt]"]').val();l&&(i.html('<span class="frm-wait frm_spinner"></span>'),n.find(".spinner").fadeIn("slow"),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_form_action_fill",action_id:a,action_type:l,nonce:frmGlobal.nonce},success:function(e){i.html(e),ci(),Xr("#".concat(n.attr("id"))),yi(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 U(){var e=this.getAttribute("href");if(void 0===e)return!1;var t=e.replace("#","."),n=jQuery(this);n.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab"),n.closest("div").children(".tabs-panel").not(e).not(t).hide();var r=document.getElementById(e.replace("#",""));return r&&(r.style.display="block"),"frm_insert_fields_tab"!==this.id||this.closest("#frm_adv_info")||$e(),!1}function W(e,t){var n=(e=jQuery(e)).attr("href");if(void 0!==n){var r,o,i=n.replace("#",".");if(e.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab"),e.closest("div").find(".tabs-panel").length)e.closest("div").children(".tabs-panel").not(n).not(i).hide();else if(null!==document.getElementById("form_global_settings")){var a=e.data("frmajax");e.closest(".frm_wrap").find(".tabs-panel, .hide_with_tabs").hide(),void 0!==a&&"1"==a&&(r=n.replace("#",""),(o=jQuery(".frm_".concat(r,"_ajax"))).length&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_settings_tab",tab:r.replace("_settings",""),nonce:frmGlobal.nonce},success:function(e){o.replaceWith(e)}}))}else jQuery("#frm-categorydiv .tabs-panel, .hide_with_tabs").hide();jQuery(n).show(),jQuery(i).show(),$o(),"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(n.replace("#",""))):jQuery(".frm_settings_form").attr("action","?page=formidable-settings&t=".concat(n.replace("#",""))))}}function V(e){var t,n;document.querySelectorAll(e).forEach(function(e){$(e),Array.from(e.children).forEach(function(e){return X(e,".frm-move")});var t=jQuery(e).children('[data-type="divider"]').children(".divider_section_only");t.length&&$(t)}),t=jQuery("#frm_builder_page"),n={items:".frm_sortable_field_opts li",axis:"y",opacity:.65,forcePlaceholderSize:!1,handle:".frm-drag",helper:function(e,t){return Q=t.clone().insertAfter(t),t.clone()},stop:function(e,t){Q&&Q.remove(),ir(t.item.attr("id").replace("frm_delete_field_","").replace("-".concat(t.item.data("optkey"),"_container"),"")),Po()}},jQuery(t).sortable(n)}function $(e){jQuery(e).droppable({accept:".frmbutton, li.frm_field_box",deactivate:ne,over:K,out:J,tolerance:"pointer"})}function K(e,t){var n=function(e){return e.classList.contains("divider_section_only")&&(e=jQuery(e).nextAll(".start_divider.frm_sorting").get(0)),e}(e.target);if(!je(t.draggable[0],n,e))return n.classList.remove("frm-over-droppable"),void jQuery(n).parents("ul.frm_sorting").addClass("frm-over-droppable");document.querySelectorAll(".frm-over-droppable").forEach(function(e){return e.classList.remove("frm-over-droppable")}),n.classList.add("frm-over-droppable"),jQuery(n).parents("ul.frm_sorting").addClass("frm-over-droppable")}function J(e){e.target.classList.remove("frm-over-droppable")}function X(e,t){var n={helper:Y,revert:"invalid",delay:10,start:Z,stop:ee,drag:te,cursor:"grabbing",refreshPositions:!0,cursorAt:{top:0,left:90}};"string"==typeof t&&(n.handle=t),jQuery(e).draggable(n)}function Y(e){var t,n=e.delegateTarget;if(Qe(n)){var r=document.getElementById("frm-insert-fields").querySelector(".frm_ttext").cloneNode(!0);return r.querySelector("use").setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_field_group_layout_icon"),r.querySelector("span").textContent=I("Field Group","formidable"),r.classList.add("frm_field_box"),r.classList.add("ui-sortable-helper"),r}if(n.classList.contains("frmbutton"))return(t=n.cloneNode(!0)).classList.add("ui-sortable-helper"),n.classList.add("frm-new-field"),t;if(n.hasAttribute("data-ftype")){var o=n.getAttribute("data-ftype");if(t=document.getElementById("frm-insert-fields").querySelector(".frm_t".concat(o)))return(t=t.cloneNode(!0)).classList.add("form-field"),t.classList.add("ui-sortable-helper"),t.cloneNode(!0)}return c({className:"frmbutton"})}function Z(e,t){if(e.target.classList.contains("frm_at_limit"))return Se(),!1;q.dragging=!0;var n,r=y;r.classList.add("frm-dragging-field"),document.body.classList.add("frm-dragging"),t.helper.addClass("frm-sortable-helper"),t.helper.initialOffset=r.scrollTop,e.target.classList.add("frm-drag-fade"),vn(),(n=document.querySelectorAll("ul.start_divider")).length&&n.forEach(function(e){[].slice.call(e.children).forEach(function(e){(0===e.children.length||1===e.children.length&&"ul"===e.firstElementChild.nodeName.toLowerCase()&&0===e.firstElementChild.children.length)&&e.remove()})}),Fe(),Ne(),z()}function ee(){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 te(e,t){!function(e){v.scrollTop(function(t,n){var r=e.clientY,o=y.offsetHeight,i=e.clientY-y.offsetTop,a=i-o/2;return i>o-50&&r>5?n+.1*a:i<70&&r<130?n-Math.abs(.1*a):n})}(e);var n=e.target,r=function(){for(var e=document.getElementById("frm-show-fields");e.querySelector(".frm-over-droppable");)e=e.querySelector(".frm-over-droppable");return"frm-show-fields"!==e.id||e.classList.contains("frm-over-droppable")||(e=!1),e}(),o=document.getElementById("frm_drag_placeholder");if(je(n,r,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"===r.id||r.classList.contains("start_divider"))return o.style.left=0,void function(e){var t,n=e.y,r=e.placeholder,o=jQuery(e.droppable),i=o.children().not(".edit_field_type_end_divider");if(0===i.length)o.prepend(r),t=0;else{var a=re(o,n);if(a===i.length){var l=jQuery(i.get(a-1));t=l.offset().top+l.outerHeight(),o.append(r);var s=o.children(".edit_field_type_end_divider");s.length&&o.append(s)}else t=jQuery(i.get(a)).offset().top,jQuery(i.get(a)).before(r)}t-=o.offset().top,r.style.top="".concat(t,"px")}({droppable:r,y:e.clientY,placeholder:o});o.style.top="",function(e){var t,n=e.x,r=e.placeholder,o=jQuery(e.droppable),i=ie(o);if(i.length){var a=function(e,t){var n,r,o,i,a=ie(e);for(i=0,n=a.length-1;n>=0;--n)if(r=a.get(n),t>(o=jQuery(r).offset().left)){i=n,t>o+jQuery(r).outerWidth()/2&&(i=n+1);break}return i}(o,n);if(a===i.length){var l=jQuery(i.get(a-1));t=l.offset().left+l.outerWidth(),o.append(r)}else t=jQuery(i.get(a)).offset().left,jQuery(i.get(a)).before(r),t-=0===a?4:8;t-=o.offset().left,r.style.left="".concat(t,"px")}}({droppable:r,x:e.clientX,placeholder:o})}else o&&o.remove()}function ne(e,t){if(q.dragging){q.dragging=!1;var n=t.draggable[0],r=document.getElementById("frm_drag_placeholder");if(!r)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 n=t.find(".frm-collapse-page").get(0);n&&n.click()}}}(r);var o=t.helper.parent(),i=t.helper.get(0).closest("ul.start_divider"),a=r.closest("ul.start_divider");n.classList.contains("frm-new-field")?function(e){if(pe(e))wp.hooks.doAction("frm_stopped_inserting_by_dragging",e);else{var t=document.getElementById("frm_drag_placeholder"),n="".concat(e.replace("|","-"),"_").concat(be()),r=s("li",{id:n,className:"frm-wait frmbutton_loadingnow"}),o=jQuery(r),i=de(jQuery(t)),a=ue(i),l=fe(i);t.parentNode.insertBefore(r,t),t.remove(),ae(o);var c=0;"summary"===e&&(c=jQuery(".frmbutton_loadingnow#".concat(n)).prevAll('li[data-type="break"]').length?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:_e(e,l,a,c),success:function(t){ge(t,o);var n=ye(t);n&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:n,fieldType:e,form_id:a})},error:he})}}(n.id):(function(e,t){t.parentNode.insertBefore(e,t)}(n,r),function(e){if("UL"===e.nodeName&&!e.classList.contains("start_divider")&&"frm-show-fields"!==e.id){var t=e.closest("li");t&&!t.classList.contains("ui-draggable")&&X(t,".frm-move")}}(r.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;r.remove(),t.helper.remove();var d=o.length?ie(o):[];!function(e,t){var n;e.length&&(t.length?ae(t.first()):(n=e.get(0).closest("li.frm_field_box"))&&!n.classList.contains("edit_field_type_divider")&&n.remove())}(o,d),function(e,t){0===t.length&&1===ie(jQuery(e.parentNode)).length||ae(jQuery(e))}(n,d),l!==c&&me(jQuery(n),i),g()}}function re(e,t){var n,r,o,i,a=e.children().not(".edit_field_type_end_divider"),l=a.length;if(!document.querySelector(".frm-has-fields .frm_no_fields"))return 0;for(i=0,n=l-1;n>=0;--n)if(r=a.get(n),t>(o=jQuery(r).offset().top)){i=n,t>o+jQuery(r).outerHeight()/2&&(i=n+1);break}return i}function oe(){document.querySelectorAll("ul#frm-show-fields, ul.start_divider").forEach(function(e){e.childNodes.forEach(function(e){void 0!==e.classList&&(e.classList.contains("edit_field_type_end_divider")||void 0!==e.classList&&e.classList.contains("form-field")&&Ue(e))})}),kr(),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()}),Er();var e=new Event("frm_sync_after_drag_and_drop",{bubbles:!1});document.dispatchEvent(e)}function ie(e){var t=jQuery(),n=e.get(0);return n.children?(Array.from(n.children).forEach(function(e){if("none"!==e.style.display){var n=e.classList;!n.contains("form-field")||n.contains("edit_field_type_end_divider")||n.contains("frm-sortable-helper")||(t=t.add(e))}}),t):t}function ae(e,t){var n;void 0===t&&(t="even");var r=e.parent().children("li.form-field, li.frmbutton_loadingnow").not(".edit_field_type_end_divider"),o=r.length,i=["frm_full","frm_half","frm_third","frm_fourth","frm_sixth","frm_two_thirds","frm_three_fourths","frm1","frm2","frm3","frm4","frm5","frm6","frm7","frm8","frm9","frm10","frm11","frm12"];"even"===t&&5!==o?r.each(ce(i,$t(o))):"clear"===t?r.each(ce(i,"")):(n=["left","right","middle","even"].includes(t)?function(e){return Vt(o,t,e)}:function(e){return sn(t[e])},r.each(ce(i,n))),le(e.parent(),r.length)}function le(e,t){if(void 0!==e.offset()){var n=t>=2,r=document.getElementById("frm_field_group_controls");if(null===r){if(!n)return;(r=c()).id="frm_field_group_controls",r.setAttribute("role","group"),r.setAttribute("tabindex",0),function(e){var t=document.createElement("span");t.innerHTML='<svg class="frmsvg"><use href="#frm_field_group_layout_icon"></use></svg>';var n=I("Set Row Layout","formidable");se(t,n),zt(t,n);var r=document.createElement("span");r.innerHTML='<svg class="frmsvg"><use href="#frm_thick_move_icon"></use></svg>',r.classList.add("frm-move");var o=I("Move Field Group","formidable");se(r,o),zt(r,o),e.innerHTML="",e.append(t),e.append(r),e.append(function(){var e=d({className:"dropdown"}),t=u({className:"frm_bstooltip frm-hover-icon frm-dropdown-toggle dropdown-toggle",children:[d({child:f({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"}),zt(t,I("More Options","formidable")),e.append(t);var n=c({className:"frm-dropdown-menu dropdown-menu dropdown-menu-right"});return n.setAttribute("role","menu"),e.append(n),e}())}(r),O.append(r)}e.append(r),r.style.display=n?"block":"none"}}function se(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 ce(e,t){return function(n){for(var r="function"==typeof t?t(n):t,o=e.length,i=!1,a=0;a<o;++a){var l=e[a];if(this.classList.contains(l)){i=l;break}}var s=this.dataset.fid;if(void 0!==s){oo(document.getElementById("frm-single-settings-".concat(s)));var c=document.getElementById("frm_classes_".concat(s));null!==c&&(!1===i?""!==r&&(c.value=c.value.concat(" ".concat(r))):(this.classList.remove(i),c.value=c.value.replace(i,r)),this.classList.contains("frm_first")&&(this.classList.remove("frm_first"),c.value=c.value.replace("frm_first","").trim()),0===n&&(this.classList.add("frm_first"),c.value=c.value.concat(" frm_first")),jQuery(c).trigger("change"))}else this.classList.add(r)}}function de(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 n=e.children(".start_divider");if(n.children(".edit_field_type_end_divider").appendTo(n),void 0!==e.attr("data-formid")){var r=e.attr("data-fid");t=jQuery('input[name="field_options[form_select_'.concat(r,']"]')).val()}}return void 0!==t&&""!==t||(t=E),t}function fe(e){var t=0;return void 0!==e[0]&&(t=e.attr("id").replace("frm_field_id_","")),t}function me(e,t){if(e.hasClass("form-field")){var n=e.attr("id").replace("frm_field_id_",""),r=de(e),o=ue(r),i=fe(r),a=t?ue(jQuery(t.parentNode)):0;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_update_field_after_move",form_id:o,field:n,section_id:i,previous_form_id:a,nonce:frmGlobal.nonce},success:function(){kr(),function(e,t){document.getElementById("frm_in_section_".concat(e)).value=t}(n,i)}})}else ie(jQuery(e.get(0).firstChild)).each(function(){me(jQuery(this),t)})}function _e(e,t,n,r){var o={action:"frm_insert_field",form_id:n,field_type:e,section_id:t,nonce:frmGlobal.nonce,has_break:r};return t>0&&document.getElementById("form_id").value!==n||(o.last_row_field_ids=function(){var e=document.querySelector(".edit_field_type_submit");if(!e)return[];for(var t=e.parentNode.children,n=[],r=0;r<t.length;r++)n.push(t[r].dataset.fid);return n}()),o}function pe(e){return wp.hooks.applyFilters("frm_should_stop_inserting_field",!1,e)}function ge(e,t){var n;document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var r=t.siblings("li.form-field").not(".edit_field_type_end_divider");r.length?(n=ve(e),t.get(0).parentNode.parentNode.classList.contains("ui-draggable")||X(t.get(0).parentNode.parentNode,".frm-move")):n=Ge(e),t.replaceWith(n),Er(),We(e,!1),r.length&&ae(r.first()),kr(),r.length?X(n.get(0),".frm-move"):($(n.get(0).querySelector("ul.frm_sorting")),X(n.get(0).querySelector("li.form-field"),".frm-move"))}function ye(e){var t=e.match(/data-fid="(\d+)"/);return t?parseInt(t[1]):0}function ve(e){var t=c();return t.innerHTML=e,jQuery(t.firstChild)}function he(e,t,n){!function(e,t){(function(e){return 0===e.status||0===e.readyState})(t)||M("".concat(e,". Please try again."))}(n,e)}function be(){return++k}function je(e,t,n){if(!1===t)return!1;if(t.closest(".frm-sortable-helper"))return!1;var r=e.classList.contains("edit_field_type_submit"),o=!e.classList.contains("form_field")&&!!e.querySelector(".edit_field_type_submit");if("frm-show-fields"===t.id){var i=re(jQuery(t),n.clientY);return r||o?i>t.childElementCount-1:i<=jQuery(t.querySelector(".edit_field_type_submit").closest("#frm-show-fields > li")).index()}if(r)return!(t.classList.contains("start_divider")||!we(t.parentElement)&&(!we(t.parentElement.nextElementSibling)||e.parentElement.querySelector("li.frm_field_box:not(.edit_field_type_submit)")));var a=t.classList.contains("start_divider")&&null!==t.closest(".repeat_section"),l=null!==t.closest(".repeat_section");if(a||l){if(e.classList.contains("edit_field_type_gdpr")||"gdpr"===e.id)return!1;if(wp.hooks.applyFilters("frm_deny_drop_in_repeater",!1,e))return!1}if(!a){if(!function(e,t){if(e.length<12)return!0;if(e.length>12)return!1;var n=t.attr("data-fid");return 1===jQuery(e).filter('[data-fid="'.concat(n,'"]')).length}(ie(jQuery(t)),jQuery(e)))return!1;if("divider"===e.id&&t.closest(".start_divider"))return!1}return e.classList.contains("frm-new-field")?function(e,t){var n=e.classList,r=n.contains("frm_tbreak"),o=n.contains("frm_thidden"),i=n.contains("frm_tdivider"),a=n.contains("frm_tform"),l=n.contains("frm_tuser_id");return"frm-show-fields"===t.id||t.classList.contains("start_divider")?!(r||o||i||a)||(!(t.classList.contains("start_divider")||null!==t.closest(".start_divider"))||!a&&!i):!(xe(t)||o||r||l)}(e,t):function(e,t){if(Qe(e))return function(e,t){return!(!t.classList.contains("start_divider")||null!==e.querySelector(".start_divider"))}(e,t);if(e.classList.contains("edit_field_type_break"))return!1;if(t.classList.contains("start_divider"))return function(e){return!e.classList.contains("edit_field_type_form")&&!e.querySelector(".edit_field_type_form")&&!(e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"))}(e);var n=e.classList.contains("edit_field_type_hidden"),r=e.classList.contains("edit_field_type_user_id");return!n&&!r&&function(e,t){if(xe(t))return!1;if(jQuery(e).children("ul.frm_sorting").not(".start_divider").length>0)return!1;var n=e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"),r=e.classList.contains("edit_field_type_form");return null===t.closest(".start_divider")||!n&&!r}(e,t)}(e,t)}function we(e){return e&&e.matches("#frm-show-fields > li:last-child")}function Qe(e){return e.classList.contains("frm_field_box")&&!e.classList.contains("form-field")}function xe(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),n=jQuery(t),r=[],o=function(e){var t=e.querySelector(".frm_hidden_fdata");e.classList.add("frm_load_now"),null!==t&&r.push(t.innerHTML)};o(t);for(var i=ke(t);i&&r.length<15;)o(i),i=ke(i);jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_load_field",field:r,form_id:E,nonce:frmGlobal.nonce},success:function(e){return function(e,t,n){var r,o;if(0===(e=e.replace(/^\s+|\s+$/g,"")).indexOf("{")){for(r in e=JSON.parse(e)){jQuery("#frm_field_id_".concat(r)).replaceWith(e[r]);var i=document.getElementById("frm_field_id_".concat(r));i&&(i.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),i.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")})),V("#frm_field_id_".concat(r,".edit_field_type_divider ul.frm_sorting")),X(document.getElementById("frm_field_id_".concat(r)))}((o=t.nextAll(".frm_field_loading:not(.frm_load_now)")).length||(o=jQuery(document.getElementById("frm-show-fields")).find(".frm_field_loading:not(.frm_load_now)")).length)&&Ee(o.attr("id")),ci(),Dn(),Ie();var a=new Event("frm_ajax_loaded_field",{bubbles:!1});a.frmFields=n.map(function(e){return JSON.parse(e)}),document.dispatchEvent(a)}else jQuery(".frm_load_now").removeClass(".frm_load_now").html("Error")}(e,n,r)}})}function ke(e){var t;return e.nextElementSibling?e.nextElementSibling:null===(t=e.parentNode)||void 0===t||null===(t=t.closest(".frm_field_box"))||void 0===t||null===(t=t.nextElementSibling)||void 0===t?void 0:t.querySelector(".form-field")}function Ae(){var e=jQuery(this);if(e.hasClass("disabled"))return!1;var t=e.closest(".frmbutton"),n=t.attr("id");if(t.hasClass("frm_at_limit"))return Se(),!1;if(!pe(n)){var r=0;"summary"===n&&(r=b.children('li[data-type="break"]').length>0?1:0);var o=E;return jQuery.ajax({type:"POST",url:ajaxurl,data:_e(n,0,o,r),success:function(e){Le(e);var t=ye(e);t&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:e,fieldId:t,fieldType:n,form_id:o})},error:he}),!1}}function Se(){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 n=document.getElementById("frm-confirmed-click");n&&(n.style.display="none")}}function Le(e){document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var t=Ge(e),n=b[0].querySelector(".edit_field_type_submit");n?jQuery(n.closest(".frm_field_box:not(.form-field)")).before(t):b.append(t),We(e,!0),t.each(function(){$(this.querySelector("ul.frm_sorting")),X(this.querySelector(".form-field"),".frm-move")})}function Ie(){var e=!0,t=document.querySelectorAll(".frmjs_prod_field_opt_cont");b.find("li.edit_field_type_product").length>1&&(e=!1);for(var n=0;n<t.length;n++)t[n].classList.toggle("frm_hidden",e)}function 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||ie(jQuery(t.querySelector("ul"))).length<12}(e.get(0))){Ne();var n,r=e.data("fid"),o=function(e){var t=[];return jQuery(document.getElementById("frm_field_id_".concat(e))).find("li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)").each(function(){t.push(jQuery(this).data("fid"))}),t}(r);return null!==t&&(n=this.getAttribute("frm-field-order")),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_duplicate_field",field_id:r,form_id:E,children:o,nonce:frmGlobal.nonce},success:function(o){var i,a,l;if(null!==t&&null!==(a=document.getElementById(t)))return l=ve(o),jQuery(a).append(l),X(l.get(0),".frm-move"),null!==n&&a.lastElementChild.setAttribute("frm-field-order",n),jQuery(a).trigger("frm_added_duplicated_field_to_row",{duplicatedFieldHtml:o,originalFieldId:r}),We(o,!1),void qe(e.get(0),l.get(0));e.siblings("li.form-field").length?(l=ve(o),e.after(l),ae(e),X(l.get(0),".frm-move")):(l=Ge(o),e.parent().parent().after(l),$(l.get(0).querySelector("ul.frm_sorting")),X(l.get(0).querySelector("li.form-field"),".frm-move")),Er(),We(o,!1),Ce(r,o),Ar(l.find(".start_divider")),null===(i=e[0].querySelector(".frm-dropdown-menu.dropdown-menu-right"))||void 0===i||i.classList.remove("show"),qe(e.get(0),l.get(0))}}),!1}M(B(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 qe(e,t){var n,r=e.closest(".frm-field-group-hover-target");if(r&&Qe(r.parentElement)){var o=e.dataset.fid,i=null===(n=document.getElementById("frm_classes_".concat(o)))||void 0===n?void 0:n.value;if(i&&(i=i.replace("frm_first",""),!t.className.includes(i))){t.className+=" ".concat(i);var a=document.getElementById("frm_classes_".concat(t.dataset.fid));a&&(a.value=i)}}}function Ce(e,t){var n=document.getElementById("frm-single-settings-".concat(e));if(null!==n){var r=jQuery(t).attr("data-fid");if(void 0!==r){var o=document.getElementById("frm-single-settings-".concat(r));if(null!==o){var i=["name","required","unique","read_only","placeholder","description","size","max","format","prepend","append","separate_value"];n.querySelectorAll('input[name^="field_options["], textarea[name^="field_options["]').forEach(function(t){var n,a=((n=t.name.substr(14).split("_")).pop(),n.join("_"));if("options"!==a){if(i.includes(a)){var l=t.matches("input")?"input":"textarea",s=o.querySelector("".concat(l,'[name="field_options[').concat(a,"_").concat(r,']"]'));null!==s&&("checkbox"===t.type?t.checked!==s.checked&&jQuery(s).trigger("click"):"text"!==t.type&&"textarea"!==l||t.value!==s.value&&(s.value=t.value,jQuery(s).trigger("change")))}}else!function(e,t,n,r){var o=e.name.substr(23+"".concat(n).length),i="field_options[options_".concat(r,"]").concat(o),a=t.querySelector('input[name="'.concat(i,'"]'));null!==a&&a.value!==e.value&&(a.value=e.value,jQuery(a).trigger("change"))}(t,o,e,r)});var a=n.querySelector('input[name="default_value_'.concat(e,'"]'));if(null!==a){var l=o.querySelector('input[name="default_value_'.concat(r,'"]'));null!==l&&a.value!==l.value&&(l.value=a.value,jQuery(l).trigger("change"))}}}}}function Ne(){var e=document.querySelector(".frm-field-settings-open");null!==e&&(e.classList.remove("frm-field-settings-open"),jQuery(document).off("click","#frm_builder_page",Te),jQuery(".frm-field-action-icons .dropdown.open").removeClass("open"))}function Te(e){jQuery(e.originalEvent.target).closest(".frm-field-action-icons").length||Ne()}function Oe(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 n=t.closest("ul.frm_sorting");if(null!==n&&!n.classList.contains("start_divider")&&"frm-show-fields"!==n.id){var r=Fe();!1===r||jQuery(r).is(n)||fn(),le(jQuery(n),ie(jQuery(n)).length),n.classList.add("frm-field-group-hover-target"),jQuery("#wpbody-content").on("mousemove",De)}}}}(e)}function Fe(){var e=document.getElementById("frm_field_group_controls");null!==e&&(e.style.display="none");var t=document.querySelector(".frm-field-group-hover-target");return null!==t&&(jQuery("#wpbody-content").off("mousemove",De),t.classList.remove("frm-field-group-hover-target"),t)}function De(e){var t=document.elementFromPoint(e.clientX,e.clientY);null!==t&&null!==t.closest("#frm-show-fields")||(Fe(),z())}function Me(e){vn(),setTimeout(function(){var t=document.querySelector(".dropdown .frm-dropdown-menu.show");if(null!==t){null===t.getAttribute("aria-label")&&t.setAttribute("aria-label",I("More Options","formidable")),0===t.children.length&&function(e,t){var n=t?"_field_group":"_field",r=[ze(t),Re(t)];t||r.push({class:"frm_select",icon:"frm_settings_icon",label:I("Field Settings","formidable")}),r.forEach(function(t){var r=document.createElement("div");r.classList.add("frm_more_options_li","dropdown-item");var o=document.createElement("a");o.classList.add(t.class+n),o.setAttribute("href","#"),zt(o);var i=document.createElement("span");i.textContent=t.label,o.innerHTML='<svg class="frmsvg"><use href="#'.concat(t.icon,'"></use></svg>'),o.append(document.createTextNode(" ")),o.append(i),r.append(o),e.append(r)})}(t,!0===e);var n=jQuery(t);n.offset().left>jQuery(window).width()-n.outerWidth()?t.style.left="".concat(-n.outerWidth(),"px"):y&&n.offset().left<y.getBoundingClientRect().left&&(t.style.right="auto",t.style.left="0");var r=t.firstElementChild.querySelector("a");r&&r.focus()}},0)}function Pe(){Me(!0)}function He(e){var t=e.target.closest(".frm-section-collapsed");t&&("show"===e.type?t.style.zIndex=3:t.style.zIndex=1)}function ze(e){var t={class:"frm_delete",icon:"frm_delete_icon"};return t.label=I(e?"Delete Group":"Delete","formidable"),t}function Re(e){var t={class:"frm_clone",icon:"frm_clone_icon"};return t.label=I(e?"Duplicate Group":"Duplicate","formidable"),t}function Ge(e){var t=c();"string"==typeof e?t.innerHTML=e:t.append(e);var n=jQuery();return Array.from(t.children).forEach(function(e){n=n.add(jQuery("<li>").addClass("frm_field_box").html(jQuery("<ul>").addClass("frm_grid_container frm_sorting").append(e)))}),n}function Ue(e){var t=s("ul",{className:"frm_grid_container frm_sorting"}),n=s("li",{className:"frm_field_box",child:t});e.replaceWith(n),t.append(e),$(t),X(n,".frm-move")}function We(e,t){var n,r,o=/id="(\S+)"/.exec(e),i=document.getElementById(o[1]),l="#".concat(o[1],".edit_field_type_divider ul.frm_sorting.start_divider"),s=jQuery(l),d=i.getAttribute("data-type");n=e,(r=c()).innerHTML=n,r.querySelectorAll(".form-field").forEach(Ve);var u,f,m=!1;if(Po(),V(l),"quantity"===d&&function(e){var t=e.getAttribute("data-fid"),n=document.getElementById("field_options[product_field_".concat(t,"]"));null!==n&&(nt(n),oo(document.getElementById("frm-single-settings-".concat(t))))}(i),"product"!==d&&"quantity"!==d||Ie(),s.length)s.parent(".frm_field_box").children(".frm_no_section_fields").addClass("frm_block");else{var _=jQuery(i).closest("ul.frm_sorting.start_divider");_.length&&(Ar(_),m=!0)}e.includes("frm-collapse-page")&&Dn(),f="frm-newly-added",(u=i).classList?u.classList.add(f):u.className+=" ".concat(f),setTimeout(function(){i.classList.remove("frm-newly-added")},1e3);var p,g=i.querySelector("#frm-last-row-fields-order");if(g&&((p=JSON.parse(g.value))&&"object"===a(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=i.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&&Ar(s)}Ke(),ci(),document.getElementById("frm-show-fields").classList.remove("frm-over-droppable"),function(e){var t=document.getElementById(e);null!=t&&t.dataset.limit&&An(e)>=t.dataset.limit&&t.classList.add("frm_at_limit")}(d),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")});var h=new Event("frm_added_field",{bubbles:!1});h.frmField=i,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 $e(e){jQuery("#new_fields .frm-single-settings").addClass("frm_hidden"),jQuery("#frm-options-panel > .frm-single-settings").removeClass("frm_hidden"),Ke(e)}function Ke(e){jQuery("li.ui-state-default.selected").removeClass("selected"),jQuery(".frm-show-field-settings.selected").removeClass("selected"),e||vn()}function Je(){var e=this.value,t=function(e){var t,n=[],r=e.split(""),o=r.length,a=["{","[","("],l={"}":"{",")":"(","]":"["},s=!1;for(t=0;t<o;t++)a.includes(r[t])?n.push(r[t]):Object.hasOwn(l,r[t])&&n.pop()!==l[r[t]]&&(s=!0);return n.length>0||s?"".concat(i.unmatched_parens,"\n\n"):""}(e);t+=function(e,t){var n=function(e,t){var n="";return function(e){return jQuery(e).siblings('label[for^="calc_type"]').children("input").prop("checked")}(t)||/\[(date|time|email|ip)\]/.test(e)&&(n="".concat(i.text_shortcodes,"\n\n")),n}(e,t);return n+=function(e){var t="";return/\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g.test(e)&&(t+="".concat(i.view_shortcodes,"\n\n")),t}(e)}(e,this),""!==t&&M("".concat(e,"\n\n").concat(t))}function Xe(e,t){for(var n=!1,r=0;r<t.length;r++){var o=document.getElementsByName(Ye(t[r],e.fieldId));if(o.length&&jQuery(o[0]).val()){n=!0;break}}return n}function Ye(e,t){var n=e.indexOf("]");return"field_options".concat(e.substring(0,n),"_").concat(t).concat(e.substring(n))}function Ze(e,t){var n=jQuery(e).closest(".frm-single-settings"),r=n.find(".frm-calc-field");if(t||r.length&&""!==r.val()&&!r.is(":hidden")){var o=function(e){var t=jQuery(e).find(".frm_code_list");return 1===t.length&&t.hasClass("frm_js_summary_list")}(e),i=n.find('input[name="frm_fields_submitted[]"]').val(),a=function(e,t){var n=e.querySelector(".frm_code_list"),r=JSON.parse(n.getAttribute("data-exclude"));if(t){var o=function(){for(var e=[],t=document.getElementsByClassName("frm_include_extras_field"),n=0;n<t.length;n++)t[n].checked&&e.push(t[n].value);return e}();if(o.length)for(var i=0;i<r.length;i++)o.includes(r[i])&&(r.splice(i,1),i--)}return r}(t?e:document.getElementById("frm-calc-box-".concat(i)),o),l=function(e){var t=[];if(!Array.isArray(e))return t;for(var n=0;n<e.length;n++)e[n].startsWith("[")&&(t.push(e[n]),e.splice(n,1),n--);return t}(a),s=tt(),c=document.getElementById("frm-calc-list-".concat(i));c.innerHTML="";for(var u=0;u<s.length;u++)if(!(null!=a&&a.includes(s[u].fieldType)||l.length&&Xe(s[u],l))){var f=document.createElement("a");f.setAttribute("href","#"),f.setAttribute("data-code",s[u].fieldId),f.classList.add("frm_insert_code"),f.append(d(s[u].fieldName)),f.append(d({className:"frm-text-sm frm-text-grey-500",text:"[".concat(s[u].fieldId,"]")}));var m=document.createElement("li");m.classList.add("frm-field-list-".concat(i)),m.classList.add("frm-field-list-".concat(s[u].fieldType)),m.append(f),c.append(m)}}}function et(){Ze(jQuery(".frm-inline-modal.postbox:has(.frm_js_summary_list)")[0],!0)}function tt(e){var t,n=[],r=document.querySelectorAll("li.frm_field_box"),o=void 0!==e;for(t=0;t<r.length;t++)if(!o||r[t].getAttribute("data-ftype")===e){var i=r[t].getAttribute("data-fid");i&&n.push({fieldId:i,fieldName:ot("frm_name_".concat(i)),fieldType:ot("field_options_type_".concat(i)),fieldKey:ot("field_options_field_key_".concat(i))})}return wp.hooks.applyFilters("frm_admin_get_field_list",n,e,r)}function nt(e){var t,n,r,o=[],i=function(e){for(var t=e.querySelectorAll('[type="checkbox"]:checked'),n=[],r=0;r<t.length;r++)n.push(t[r].value);return n}(e),a=e.getAttribute("data-frmfname"),l=tt("product"),s=tt("quantity"),c="SELECT"===e.tagName,d=1===s.length&&1===l.length;for(c&&(i=e.getAttribute("data-frmcurrent")),t=0;t<l.length;t++)r=l[t].fieldId.toString(),n=d||i.includes(r),c?(n=n?" selected":"",o.push('<option value="'.concat(r,'"').concat(n,">").concat(l[t].fieldName,"</option>"))):(n=n?" checked":"",o.push('<label class="frm6">'),o.push('<input type="checkbox" name="'.concat(a,'" value="').concat(r,'"').concat(n,"> ").concat(l[t].fieldName)),o.push("</label>"));e.innerHTML=o.join("")}function rt(){for(var e=document.querySelectorAll(".frmjs_prod_field_opt"),t=0;t<e.length;t++)nt(e[t])}function ot(e){var t=document.getElementById(e);return null!==t?t.value:""}function it(){var e,t,n,r,o,i,a,l,s,c=this.value,d=document.getElementById(this.getAttribute("data-changeme")),u=this.getAttribute("data-changeatt");null!==d&&(null!==u?"SELECT"===d.tagName&&"placeholder"===u?""===(e=d.options[0]).value?e.innerHTML=c:ur(d,c):"class"===u?(n=d,l=" ".concat((r=this).value),void 0!==(s=n.getAttribute("data-fid"))&&(r.classList.contains("field_options_align")?l+=" ".concat(document.getElementById("frm_classes_".concat(s)).value):r.classList.contains("frm_classes")&&null!==(a=document.getElementById("field_options_align_".concat(s)))&&(l+=" ".concat(a.value))),l=(l+=" ").replace(" block "," vertical_radio ").replace(" inline "," horizontal_radio "),""===(o=0===(o=n.className.split(" frmstart ")[1]).indexOf("frmend ")?"":o.split(" frmend ")[0]).trim()?(i=" frmstart frmend ",n.className.includes(i)||(i=" frmstart frmend "),l=" frmstart ".concat(l.trim()," frmend ")):(i=o.trim(),l=l.trim()),n.className=n.className.replace(i,l)):"range"===(t=d).type&&t.parentNode.classList.contains("frm_range_container")?function(e,t,n){if(frmGlobal.proIncludesSliderJs){var r={field:e,att:t,newValue:n};wp.hooks.doAction("frm_update_slider_field_preview",r)}else{var o;if("value"===t?(""===n&&(n=at(e)),e.value=n):e.setAttribute(t,n),["value","min","max"].includes(t))"max"!==t&&"min"!==t||""!==(o=e.id,document.querySelector('input[data-changeme="'.concat(o,'"][data-changeatt="value"]')).value)||(e.value=at(e)),e.parentNode.querySelector(".frm_range_value").textContent=e.value}}(d,u,c):d.setAttribute(u,c):0===d.id.indexOf("setup-message")?""!==c&&(d.innerHTML='<input type="text" value="" disabled />'):(d.innerHTML=_r(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 at(e){var t=parseFloat(e.getAttribute("max")),n=parseFloat(e.getAttribute("min"));return(t-n)/2+n}function lt(){var e=this.getAttribute("data-fid"),t="";["field_options_max_","frm_format_"].forEach(function(n){var r=document.getElementById(n+e);r&&(t+=r.value)});var n=document.getElementsByName("field_options[type_".concat(e,"]"))[0];"text"===n.options[n.selectedIndex].value&&ct(""!==t,".frm_invalid_msg".concat(e))}function st(){var e=this.id.replace("frm_","").replace("req_field_",""),t=this.checked,n=jQuery("#field_label_".concat(e," .frm_required"));if(ct(t,".frm_required_details".concat(e)),t){var r=jQuery('input[name="field_options[required_indicator_'.concat(e,']"]'));""===r.val()&&r.val("*"),n.removeClass("frm_hidden")}else n.addClass("frm_hidden")}function ct(e,t){var n=jQuery(t);if(e)n.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");else{var r=n.fadeOut("fast").closest(".frm_validation_box"),o=r.css("display","block").children(":not(".concat(t,"):visible")).length;r.css("display",""),0===o&&n.closest(".frm_validation_msg").fadeOut("fast")}}function dt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(".frm_unique_details".concat(e));if(this.checked){t.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");var n=jQuery(".frm_unique_details".concat(e," input"));""===n.val()&&n.val(i.default_unique)}else{var r=t.fadeOut("fast").closest(".frm_validation_box"),o=r.css("display","block").children(":not(.frm_unique_details".concat(e,"):visible")).length;r.css("display",""),0===o&&t.closest(".frm_validation_msg").fadeOut("fast")}}function ut(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(this).val(),n=jQuery(document.getElementById("frm_field_id_".concat(e)));if(ct(""!==t,".frm_conf_details".concat(e)),""!==t){var r=jQuery(".frm_validation_box .frm_conf_details".concat(e," input"));""===r.val()&&r.val(i.default_conf),function(e){var t=document.getElementsByName("field_options[type_".concat(e,"]"))[0].value;ft(document.getElementById("field_description_".concat(e)),"field_options[description_".concat(e,"]"),i["enter_".concat(t)]),ft(document.getElementById("conf_field_description_".concat(e)),"field_options[conf_desc_".concat(e,"]"),i["confirm_".concat(t)])}(e),"inline"===t?n.removeClass("frm_conf_below").addClass("frm_conf_inline"):"below"===t&&n.removeClass("frm_conf_inline").addClass("frm_conf_below"),jQuery(".frm-conf-box-".concat(e)).removeClass("frm_hidden")}else jQuery(".frm-conf-box-".concat(e)).addClass("frm_hidden"),setTimeout(function(){n.removeClass("frm_conf_inline frm_conf_below")},200)}function ft(e,t,n){e.innerHTML===i.desc&&(e.innerHTML=n,document.getElementsByName(t)[0].value=n)}function mt(e){var t=JSON.parse(this.getAttribute("data-opts"));return e.preventDefault(),document.getElementById("frm_bulk_options").value=t.join("\n"),!1}function _t(){var e,t,n,r=jQuery(this).closest(".frm-single-settings").data("fid"),o=jQuery("#frm_field_".concat(r,"_opts .frm_option_template")).prop("outerHTML"),i=jQuery(this).data("opttype"),a=0,l="000",s=function(e){for(var t=0,n=0,r=jQuery("#frm_field_".concat(e,"_opts li")),o=0;t<r.length;t++){if(n=r[t].getAttribute("data-optkey"),1===r.length)return n;"000"!==n&&(n=n.replace("other_",""),n=parseInt(n,10)),!isNaN(o)&&(n>o||"000"===o)&&(o=n)}return o}(r);if(s!==l&&(a=s+1),"other"===i){document.getElementById("other_input_".concat(r)).value=1;var c=jQuery(this).data("ftype");"radio"!==c&&"select"!==c||jQuery(this).fadeOut("slow");var d={action:"frm_add_field_option",field_id:r,opt_key:a,opt_type:i,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,d,function(e){jQuery(document.getElementById("frm_field_".concat(r,"_opts"))).append(e),ir(r)})}else{o=(o=(o=(o=(o=o.replace(new RegExp('optkey="'.concat(l,'"'),"g"),'optkey="'.concat(a,'"'))).replace(new RegExp("-".concat(l,"_"),"g"),"-".concat(a,"_"))).replace(new RegExp("-".concat(l,'"'),"g"),"-".concat(a,'"'))).replace(new RegExp("\\[".concat(l,"\\]"),"g"),"[".concat(a,"]"))).replace("frm_hidden frm_option_template",""),Di(r,o={newOption:o});var u=this.closest(".frm_single_option");u?u.after(o.newOption):jQuery("#frm_field_".concat(r,"_opts")).append(o.newOption),ir(r)}null==(n=(e=this).classList.contains("frm-add-option-legacy")?null===(t=e.closest(".frm-collapse-me"))||void 0===t?void 0:t.querySelector(".frm_sortable_field_opts"):e.closest(".frm_sortable_field_opts"))||n.querySelectorAll(".frm_remove_tag.frm_disabled").forEach(function(e){return e.classList.remove("frm_disabled")}),Po()}function pt(){gt(jQuery(this).closest(".frm-single-settings").data("fid"),this.value)}function gt(e,t){var n=jQuery(".frm_multiple_cont_".concat(e));"select"===t?n.fadeIn("fast"):n.fadeOut("fast")}function yt(){var e=jQuery(this).closest(".frm-single-settings").data("fid");qi(jQuery(".field_".concat(e,"_option_key"))),jQuery(".field_".concat(e,"_option")).toggleClass("frm_with_key")}function vt(){var e=jQuery(this).closest(".frm-single-settings"),t=e.data("fid"),n=document.getElementById("frm_field_id_".concat(t));wt(jQuery(this)),qi(jQuery(".field_".concat(t,"_image_id"))),qi(jQuery(".frm_toggle_image_options_".concat(t))),qi(jQuery(".frm_image_size_".concat(t))),qi(jQuery(".frm_alignment_".concat(t))),qi(jQuery(".frm-add-other#frm_add_field_".concat(t)));var r=vr(t);if(r){bt(t,"inline"),ht(n);var o=or(t);n.classList.add("frm_image_options"),n.classList.add("frm_image_size_".concat(o)),e.find(".frm-bulk-edit-link").hide()}else n.classList.remove("frm_image_options"),ht(n),bt(t,"block"),e.find(".frm-bulk-edit-link").show();wp.hooks.doAction("frm_image_options_toggled",e[0],r)}function ht(e){e.classList.remove("frm_image_size_","frm_image_size_small","frm_image_size_medium","frm_image_size_large","frm_image_size_xlarge")}function bt(e,t){jQuery("#field_options_align_".concat(e)).val(t).trigger("change")}function jt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));Qt(),vr(e)&&(ht(t),t.classList.add("frm_image_options"),t.classList.add("frm_image_size_".concat(or(e))))}function wt(e){var t=e.closest(".frm-single-settings").data("fid");jQuery(".field_".concat(t,"_option")).trigger("change")}function Qt(){wt(jQuery(this))}function xt(e){var t,n=e.target.closest(".frm_image_preview_wrapper");if(null!==(t=wp)&&void 0!==t&&t.media&&(null==n||!n.dataset.upgrade)){e.preventDefault(),wp.media.model.settings.post.id=0;var r=wp.media.frames.file_frame=wp.media({multiple:!1,library:{type:["image"]}});r.on("select",function(){var e=r.state().get("selection").first().toJSON(),t=n.querySelector("img");t.setAttribute("src",e.url),t.classList.remove("frm_hidden"),t.removeAttribute("srcset"),n.querySelector(".frm_image_preview_frame").style.display="block",n.querySelector(".frm_image_preview_title").textContent=e.filename,n.querySelector(".frm_choose_image_box").style.display="none";var o=jQuery(n);o.siblings('input[name*="[label]"]').data("frmimgurl",e.url),o.find("input.frm_image_id").val(e.id).trigger("change"),wp.media.model.settings.post.id=0}),r.open()}}function Et(e){var t=jQuery(this).closest(".frm_image_preview_wrapper");e.preventDefault(),e.stopPropagation(),t.find("img").attr("src",""),t.find(".frm_image_preview_frame").hide(),t.find(".frm_choose_image_box").show(),t.find("input.frm_image_id").val(0).trigger("change")}function kt(){var e=jQuery(this).closest("li").find(".frm_form_fields select");this.checked?e.attr("multiple","multiple"):e.removeAttr("multiple")}function At(){var e=document.getElementById("dropform-search-input");null!==e&&setTimeout(function(){e.focus()},100)}function St(e){var t=e.target,n=t.closest(".frm_warning_style");jQuery(n).fadeOut(400,function(){return n.remove()});var r=t.dataset.action,o=new FormData;p(r,o)}function Lt(e){e.preventDefault()}function It(){var e,t,n=this.parentNode,r=n.parentNode,o=r.querySelectorAll("li:not(.frm_hidden)");2===o.length&&(null===(e=Array.from(o).find(function(e){return e!==n}).querySelector(".frm_remove_tag"))||void 0===e||e.classList.add("frm_disabled"));var i=this.getAttribute("data-fid");jQuery(n).fadeOut("fast",function(){wp.hooks.doAction("frm_before_delete_field_option",this),jQuery(n).remove(),jQuery(r).find(".frm_other_option").length<1&&(null!==(t=document.getElementById("other_input_".concat(i)))&&(t.value=0),jQuery("#other_button_".concat(i)).fadeIn("fast"))}),Po()}function Bt(){var e=jQuery(this);if(e.is(":checked")){var t,n=function(){e.off("mouseup",t)};t=function(){setTimeout(function(){e.prop("checked",!1)},0),n()},e.on("mouseup",t),e.one("mouseout",n)}}function qt(){this.value===i.new_option&&(this.setAttribute("data-value-on-focus",this.value),this.value="")}function Ct(e){return B(I("Are you sure you want to delete these %1$s selected field(s)?","formidable"),e)}function Nt(){var e=i.conf_delete,t=this.parentNode.parentNode.parentNode.parentNode.parentNode,n=t.parentNode,r=jQuery(this).closest("li.form-field"),o=r.data("fid");if("divider"===r.data("ftype")){var a=document.querySelectorAll(".frm-field-group-hover-target .start_divider .frm_field_box"),l=0;a.forEach(function(e){var t=e.querySelectorAll("li.form-field");t&&(l+=t.length)}),l&&(e=Ct(++l))}return n.classList.contains("frm-section-collapsed")||n.classList.contains("frm-page-collapsed")||("divider_section_only"===t.className&&(e=i.conf_delete_sec),this.setAttribute("data-frmverify",e),this.setAttribute("data-frmverify-btn","frm-button-red"),this.setAttribute("data-deletefield",o),Ne(),D(this)),!1}function Tt(){this.closest("li.form-field").click()}function Ot(){var e=document.querySelector(".frm-field-group-hover-target");if(null!==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 Ft(){var e=document.querySelector(".frm-field-group-hover-target");if(null!==e){var t="frm_field_group_".concat(be()),n=document.createTextNode("");Ue(n);var r=jQuery(n).closest("li").get(0);r.classList.add("frm_hidden");var o=r.querySelector("ul");o.id=t,jQuery(e.closest("li.frm_field_box")).after(r);var i=ie(jQuery(e)),a=[],l=[],s=i.length,c={},d=0;jQuery(r).on("frm_added_duplicated_field_to_row",function(e,t){if(c[jQuery(t.duplicatedFieldHtml).attr("data-fid")]=t.originalFieldId,!(s>++d)){var n=jQuery(o),i=ie(n);l.forEach(function(e){e.remove()});for(var u=0;u<s;++u)n.append(n.children('li.form-field[frm-field-order="'.concat(u,'"]')));ae(i.first(),a),r.classList.remove("frm_hidden"),Er(),ie(n).each(function(){Ce(c[this.getAttribute("data-fid")],jQuery(this).prop("outerHTML"))})}}),i.each(function(e){var n=document.createElement("li");n.classList.add("frm_clone_field"),n.setAttribute("frm-target-row-id",t),n.setAttribute("frm-field-order",e),this.append(n),n.click(),l.push(n),a.push(an(ln(this.classList)))})}}function Dt(){var e=document.querySelector(".frm-field-group-hover-target");if(null!==e){Ke();var t=Pt(e.querySelector("li.form-field"));e.classList.add("frm-has-open-field-group-popup"),jQuery(document).on("click","#frm_builder_page",Mt);var n=c();n.style.position="relative",n.append(Ht(t,this)),this.parentNode.append(n);var r=n.querySelector(".frm-row-layout-option");r&&r.focus()}}function Mt(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||fn()}function Pt(e){var t=jQuery(e).closest("ul");return t.length?ie(t).length:wn()}function Ht(e,t){var n=document.getElementById("frm_field_group_popup");null===n?n=c():n.innerHTML="",n.id="frm_field_group_popup";var r,o=c();o.style.padding="0 24px 12px",o.append(((r=c()).classList.add("frm-row-layout-title"),r.textContent=I("Row Layout","formidable"),r));var i,a=function(e){var t=Xt();if(e>6)return t.append(Gt(e,"even")),t;if(5!==e&&t.append(Gt(e,"even")),e%2==1&&t.append(Gt(e,"middle")),e<6)t.append(Gt(e,"left")),t.append(Gt(e,"right"));else{var n=c();n.classList.add("frm_fourth"),t.prepend(n)}return t}(e),l=t.closest("ul.frm_sorting");return null!==l&&function(e,t){for(var n=t.children.length,r=0;r<n;++r){var o=t.children[r];if(Ut(o,e))return void o.classList.add("frm-active-row-layout")}}(l,a),o.append(a),n.append(o),n.append(document.createElement("hr")),e<=6&&n.append(((i=c()).textContent=I("Custom layout","formidable"),jQuery(i).prepend(Rt("frm_gear_svg")),i.classList.add("frm-custom-field-group-layout"),zt(i),i)),n.append(function(){var e=c();return e.textContent=I("Break into rows","formidable"),jQuery(e).prepend(Rt("frm_break_field_group_svg")),e.classList.add("frm-break-field-group"),zt(e),e}()),n}function zt(e,t){e.setAttribute("tabindex",0),e.setAttribute("role","button"),void 0!==t&&e.setAttribute("aria-label",t)}function Rt(e){var t=document.getElementById(e).cloneNode(!0);return t.id="",t}function Gt(e,t){var n,r=c();switch(r.classList.add("frm-row-layout-option"),zt(r,t),e){case 6:n="frm_half";break;case 5:n="frm_third";break;default:n=e>6?"frm_full":e%2==1?"frm_fourth":"frm_third"}return r.classList.add(n),r.setAttribute("layout-type",t),r.append(function(e,t){for(var n=Xt(),r=0;r<e;++r){var o=c();o.classList.add(Vt(e,t,r)),o.style.height="16px",o.style.background="#9EA9B8",o.style.borderRadius="1px",n.append(o)}return n}(e,t)),r}function Ut(e,t){return Wt(e)===Wt(t)}function Wt(e){var t;t=e.classList.contains("frm-row-layout-option")?jQuery(e).find(".frm_grid_container").children():ie(jQuery(e));var n=[];return t.each(function(){n.push(an(ln(this.classList)))}),n.join("-")}function Vt(e,t,n){if("even"===t)return $t(e,n);if("middle"===t){if(3===e)return 1===n?"frm6":"frm3";if(5===e)return 2===n?"frm4":"frm2"}else{if("left"===t)return 0===n?Jt(e):Kt(e);if("right"===t)return n===e-1?Jt(e):Kt(e)}return"frm12"}function $t(e,t){return e>6?"frm1":[2,3,4,6].includes(e)?sn(12/e):5===e&&void 0!==t?0===t?"frm4":"frm2":"frm12"}function Kt(e){switch(e){case 2:case 3:return"frm3";case 4:case 5:return"frm2";case 6:return"frm1";default:return"frm12"}}function Jt(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 Xt(){var e=c();return e.classList.add("frm_grid_container"),e}function Yt(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t=this.getAttribute("layout-type");ae(ie(jQuery(e)).first(),t),fn()}}function Zt(){var e=en(),t=this.getAttribute("layout-type");ae(ie(e).first(),t),vn()}function en(){var e=jQuery(".frm-selected-field-group"),t=e.first();return e.not(t).each(function(){ie(jQuery(this)).each(function(){var e=this.parentNode;ie(t).last().after(this),jQuery(e).children("li.form-field").length||e.closest("li.frm_field_box").remove()})}),Er(),ae(ie(t).first()),t}function tn(){null===this.closest(".frm-merge-fields-into-row")&&nn(ie(jQuery(".frm-field-group-hover-target")))}function nn(e){var t=e.length,n=document.getElementById("frm_field_group_popup");n.innerHTML="";var r=c();r.style.padding="0 24px";var o=$t(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=wn()>0&&an($t(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:an(ln(e.get(s).classList)),i.append(d)}var u=c();u.classList.add("frm-builder-popup-heading"),u.textContent=I("Enter number of columns for each field","formidable");var f=c();f.classList.add("frm-builder-popup-subheading"),f.textContent=I("Layouts are based on a 12-column grid system","formidable"),r.append(u),r.append(f),r.append(i);var m=c();m.style.textAlign="right";var _,p=((_=on()).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=on();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),r.append(m),n.append(r),setTimeout(function(){var e=n.querySelector("input.frm-custom-grid-size-input").focus();e&&e.focus()},0)}function rn(){nn(jQuery(".frm-selected-field-group li.form-field"))}function on(){var e=document.createElement("a");return e.setAttribute("href","#"),e.classList.add("button"),e.style.textDecoration="none",e}function an(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 ln(e){for(var t=["frm_full","frm_half","frm_third","frm_fourth","frm_sixth","frm_two_thirds","frm_three_fourths","frm1","frm2","frm3","frm4","frm5","frm6","frm7","frm8","frm9","frm10","frm11","frm12"],n=0;n<t.length;++n){var r=t[n];if(e.contains(r))return r}return""}function sn(e){return"frm".concat(e)}function cn(){var e,t;e=document.querySelector(".frm-field-group-hover-target"),ie(t=jQuery(e)).each(function(e){0!==e&&t.parent().after(Ge(this)),function(e){ae(e,"clear")}(jQuery(this))}),fn()}function dn(){this.select()}function un(){jQuery(document.getElementById("frm_field_group_popup")).replaceWith(Ht(Pt(this),this))}function fn(){var e=document.getElementById("frm_field_group_popup");if(null!==e){var t=document.querySelector(".frm-has-open-field-group-popup");null!==t&&(t.classList.remove("frm-has-open-field-group-popup"),e.parentNode.remove()),jQuery(document).off("click","#frm_builder_page",Mt)}}function mn(){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?ae(ie(jQuery(document.querySelector(".frm-field-group-hover-target"))).first(),e):(ae(ie(en()).first(),e),vn()),fn()}function _n(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)pn(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:f({href:"#frm_close_icon"})})]}),document.getElementById("post-body-content").append(e);var t,n=((t=document.createElement("span")).classList.add("frm-field-group-message-text","frm-flex-center"),t.innerHTML=B(frm_admin_js.holdShiftMsg,'<span class="frm-meta-tag frm-flex-center"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-shift" viewBox="0 0 16 16"><path d="M7.3 2a1 1 0 0 1 1.4 0l6.4 6.8a1 1 0 0 1-.8 1.7h-2.8v3a1 1 0 0 1-1 1h-5a1 1 0 0 1-1-1v-3H1.7a1 1 0 0 1-.8-1.7L7.3 2zm7 7.5L8 2.7 1.7 9.5h2.8a1 1 0 0 1 1 1v3h5v-3a1 1 0 0 1 1-1h2.8z"/></svg>',"</span>"),t);e.prepend(n),document.getElementById("frm-field-group-message-dismiss").addEventListener("click",function(){pn(document.getElementById("frm-field-group-message"))})}}(),"ul"===e.originalEvent.target.nodeName.toLowerCase()){var t=document.querySelector(".frm-field-group-hover-target");if(t){var n=e.ctrlKey||e.metaKey,r=e.shiftKey,o=t.classList.contains("frm-selected-field-group"),i=function(){var e=jQuery(".frm-selected-field-group");if(e.length)return e;var t=gn();if(t){var n=t.closest("ul");if(n&&1===ie(jQuery(n)).length)return n.classList.add("frm-selected-field-group"),jQuery(n)}return jQuery()}(),a=i.length;if(n||r){var l=gn();if(null===l||jQuery(l).siblings("li.form-field").length||(l.parentNode.classList.add("frm-selected-field-group"),++a),n){if(o)return--a,t.classList.remove("frm-selected-field-group"),void yn(a);++a}else if(r&&!o){++a;var s=i.first();(s.parent().index()<jQuery(t.parentNode).index()?s.parent().nextUntil(t.parentNode):s.parent().prevUntil(t.parentNode)).each(function(){var e=jQuery(this).closest("li").find("ul.frm_sorting");e.hasClass("frm-selected-field-group")||(++a,e.addClass("frm-selected-field-group"))})}}else vn(),a=1;t.classList.add("frm-selected-field-group"),yn(a),document.querySelectorAll(".frm-selected-field-group").length<2||pn(document.getElementById("frm-field-group-message")),jQuery(document).off("click",vn),jQuery(document).on("click",vn)}}}function pn(e){e&&(e.classList.add("frm_hidden"),e.classList.remove("frm-fadein-up-back"))}function gn(){return document.getElementById("frm-show-fields").querySelector("li.form-field.selected")}function yn(e){$e(!0),e>=2||1===e&&ie(jQuery(document.querySelector(".frm-selected-field-group"))).length>1?function(){var e=document.getElementById("frm_field_multiselect_popup");if(null!==e)return e.classList.toggle("frm-unmergable",!bn()),e;(e=c()).id="frm_field_multiselect_popup",bn()||e.classList.add("frm-unmergable");var t=c();t.classList.add("frm-merge-fields-into-row"),t.textContent=I("Merge into row","formidable");var n=document.createElement("a");n.style.marginLeft="5px",n.classList.add("frm_icon_font","frm_arrowdown6_icon"),n.setAttribute("href","#"),t.append(n),e.append(t);var r=c();r.classList.add("frm-multiselect-popup-separator"),e.append(r);var o=c();o.classList.add("frm-delete-field-groups"),o.append(Rt("frm_trash_svg")),e.append(o),document.getElementById("post-body-content").append(e),jQuery(e).hide().fadeIn()}():hn(),Fe()}function vn(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",vn),hn()}function hn(){var e=document.getElementById("frm_field_multiselect_popup");null!==e&&e.remove()}function bn(){var e=document.querySelectorAll(".frm-selected-field-group"),t=e.length;if(1===t)return!1;for(var n=0,r=0;r<t;++r){var o=e[r];if(null!==o.querySelector(".edit_field_type_break, .edit_field_type_hidden"))return!1;if((n+=ie(jQuery(o)).length)>12)return!1}return!0}function jn(e){if(null===e.originalEvent.target.closest("#frm_field_group_popup")&&!e.originalEvent.target.classList.contains("frm-custom-field-group-layout")){var t=Ht(wn(),document.querySelector(".frm-selected-field-group").firstChild);this.append(t)}}function wn(){var e=0;return jQuery(document.querySelectorAll(".frm-selected-field-group")).each(function(){e+=ie(jQuery(this)).length}),e}function Qn(){var e,t=(e=[],jQuery(".frm-selected-field-group > li.form-field").each(function(){e.push(this.dataset.fid)}),e),n=function(e){return function(t){t.preventDefault(),function(e){e.forEach(function(e){En(e)})}(e)}}(t),r=document.getElementById("frm_field_multiselect_popup");null!==r&&r.remove(),this.setAttribute("data-frmverify",Ct(t.length)),D(this);var o=document.getElementById("frm-confirmed-click");null==o||o.removeAttribute("data-deletefield"),jQuery(o).on("click",n),jQuery("#frm_confirm_modal").one("dialogclose",function(){jQuery(o).off("click",n)})}function xn(){En(this.getAttribute("data-deletefield"))}function En(e){var t=jQuery("#frm_field_id_".concat(e));kn(e),t.hasClass("edit_field_type_divider")&&t.find("li.frm_field_box[data-fid]").each(function(){kn(this.getAttribute("data-fid"))}),kr()}function kn(e){jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_delete_field",field_id:e,nonce:frmGlobal.nonce},success:function(){var t,n,r,o=jQuery(document.getElementById("frm_field_id_".concat(e))),i=jQuery("#frm-single-settings-".concat(e));i.is(":visible")&&(null===(t=document.querySelector(".frm-settings-panel .frm-tabs-navs ul > li:first-child"))||void 0===t||t.click(),document.querySelector("#frm-options-panel .frm-single-settings").classList.remove("frm_hidden")),function(e){var t=e[0].querySelectorAll(".frm-inline-modal[data-fills]");t.length&&t.forEach(function(e){e.classList.add("frm_hidden"),e.removeAttribute("data-fills"),e.closest("form").append(e)})}(i),i.remove(),o.fadeOut("slow",function(){var e,t=o.closest(".start_divider"),n=o.data("type"),r=o.siblings("li.form-field");if(r.length||(o.is(".edit_field_type_end_divider")?r.length=o.closest("li.form-field").siblings():e=o.closest("ul.frm_sorting").parent()),o.remove(),"break"===n?Dn():"product"===n&&(Ie(),rt()),r.length?ae(r.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&&Ar(t);z()}),o.length&&(n=o.data("type"),(r=document.getElementById(n))&&r.dataset.limit&&An(n)-1<r.dataset.limit&&r.classList.remove("frm_at_limit"),wp.hooks.doAction("frm_after_delete_field",o[0]))}})}function An(e){return document.getElementById("frm-show-fields").querySelectorAll('li.form-field[data-ftype="'.concat(e,'"]')).length}function Sn(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=E,n=document.getElementById("frm_logic_row_".concat(e)).querySelectorAll(".frm_logic_row");return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_logic_row",form_id:t,field_id:e,nonce:frmGlobal.nonce,meta_name:Ln(n,"frm_logic_".concat(e,"_")),fields:tt()},success:function(t){jQuery(document.getElementById("logic_".concat(e))).fadeOut("fast",function(){var n=document.getElementById("frm_logic_row_".concat(e));n.insertAdjacentHTML("beforeend",t);var r=n.querySelector(".frm_logic_row:last-child .frm-logic-rule-text");r&&(r.textContent=n.dataset.ruleText);var o=n.closest(".frm_logic_rows");o.style.height="auto",jQuery(o).fadeIn("fast")})}}),!1}function Ln(e,t,n){return e.length?parseInt(e[e.length-1].id.replace(t,""),10)+1:void 0!==n?n:0}function In(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=E,n=document.getElementById("frm_watch_lookup_block_".concat(e)).children;return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_watch_lookup_row",form_id:t,field_id:e,row_key:Ln(n,"frm_watch_lookup_".concat(e,"_")),nonce:frmGlobal.nonce},success:function(t){var n,r=jQuery(document.getElementById("frm_watch_lookup_block_".concat(e)));r.append(t),r.fadeIn("slow"),null===(n=document.getElementById("frm_watch_lookup_label_".concat(e)))||void 0===n||n.classList.remove("frm-force-hidden")}}),!1}function Bn(e){var t,n,r=jQuery(e).closest(".frm-single-settings").attr("data-fid"),o=jQuery(e).closest("ul").get(0).querySelectorAll(".field_".concat(r,"_option"));for(t in o)if(Object.hasOwn(o,t)&&(n=o[t]).id!==e.id&&n.value===e.value&&"true"!==n.getAttribute("data-duplicate"))return!0;return!1}function qn(){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"),Bn(this))?this.setAttribute("data-value-on-focus",this.getAttribute("data-value-on-load")):""===this.value&&i.new_option===this.getAttribute("data-value-on-focus")||this.setAttribute("data-value-on-focus",this.value)}function Cn(e){var t,n=e.closest(".frm_single_option");return e.parentElement.classList.contains("frm_single_option")?{newValue:n.querySelector('.frm_option_key input[type="text"]').value,newLabel:t=e.value}:(t=n.querySelector('input[type="text"]').value,{newValue:e.value,newLabel:t})}function Nn(){var e,t,n=function(e){var t=function(e){var t,n,r=null!==(t=null===(n=e.closest(".frm-single-settings").querySelector(".frm_toggle_sep_values"))||void 0===n?void 0:n.checked)&&void 0!==t&&t,o=e.closest(".frm_single_option");return r&&e.parentElement.classList.contains("frm_single_option")?{oldValue:o.querySelector('.frm_option_key input[type="text"]').getAttribute("data-value-on-focus"),oldLabel:e.getAttribute("data-value-on-focus")}:{oldValue:e.getAttribute("data-value-on-focus"),oldLabel:o.querySelector('input[type="text"]').getAttribute("data-value-on-focus")}}(e),n=t.oldValue,r=t.oldLabel,o=Cn(e);return{oldValue:n,oldLabel:r,newValue:o.newValue,newLabel:o.newLabel}}(this),r=n.oldValue,o=n.oldLabel,i=n.newValue,a=n.newLabel;if(r!==i||o!==a){var l=this.closest(".frm-single-settings"),s=l.getAttribute("data-fid"),c=this.getAttribute("data-value-on-load");if(Bn(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=[],u=O.querySelectorAll(".frm_logic_row"),f=u.length,m=0;m<f;m++){var _=u[m];if(_.querySelector(".frm_logic_field_opts").value===s){var p,g=_.id.split("_")[2],y=_.querySelector('select[name="field_options[hide_opt_'.concat(g,'][]"]')),v=void 0,h=void 0;(v=""===r?[]:y.querySelectorAll('option[value="'.concat(r,'"]'))).length||(v=y.querySelectorAll('option[value="'.concat(i,'"]'))).length||(null!==(p=l.querySelector(".frm_toggle_sep_values"))&&void 0!==p&&p.checked||(h=Tn(y,r)),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],oo(document.getElementById("frm-single-settings-".concat(t))))}}function Tn(e,t){for(var n=e.options,r=0;r<n.length;r++){var o=n[r];if(t===o.textContent)return o}return null}function On(){var e=this.id.replace("get_values_form_",""),t=document.getElementById("get_values_field_".concat(e)),n=this.getAttribute("data-fieldtype");if(""===this.value)t.options.length=1;else{var r=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_options_for_get_values_field",form_id:r,field_type:n,nonce:frmGlobal.nonce},success:function(e){t.innerHTML=e}})}}function Fn(){var e,t,n=this.name.replace("field_options[data_type_","").replace("]","");(e=document.getElementById("frm_add_watch_lookup_link_".concat(n)))&&(e=e.parentNode,"text"===this.value?null!==(t=document.getElementById("frm_watch_lookup_block_".concat(n)))&&(t.innerHTML="",e.classList.add("frm_hidden"),e.previousElementSibling.style.display="none",e.previousElementSibling.previousElementSibling.style.display="none",e.previousElementSibling.previousElementSibling.previousElementSibling.style.display="none"):e.classList.remove("frm_hidden"),gt(n,this.value))}function Dn(){var e,t,n=document.getElementsByClassName("frm-page-num");if(n.length>1)for(document.getElementById("frm-fake-page").style.display="block",e=0;e<n.length;e++)t=n[e].parentNode.parentNode.parentNode.classList,1===e?t.add("frm-first-page"):t.remove("frm-first-page"),n[e].textContent=e+1;else document.getElementById("frm-fake-page").style.display="none";wp.hooks.doAction("frm_renumber_page_breaks",n)}function Mn(){var e,t,n,r=jQuery(this).closest(".frm_field_box[data-ftype=break]");r.length?function(e){var t=Pn(e.get(0).parentNode.closest("li.frm_field_box").nextElementSibling);Hn(e,t)}(r):(e=document.getElementById("frm-fake-page"),t=document.getElementById("frm-show-fields").firstElementChild,n=Pn(t),"break"!==t.getAttribute("data-ftype")&&Hn(jQuery(e),n))}function Pn(e){var t,n;if(t=jQuery(),null===e)return t;n=e;do{if(null!==n.querySelector(".edit_field_type_break"))break;t=t.add(jQuery(n)),n=n.nextElementSibling}while(null!==n);return t}function Hn(e,t){var n,r=t.length,o=Math.min(r,3);if(e.hasClass("frm-page-collapsed"))for(e.removeClass("frm-page-collapsed"),t.removeClass("frm-is-collapsed"),n=0;n<o;n++)n===o-1?jQuery(t[n]).slideDown(150,function(){t.show()}):jQuery(t[n]).slideDown(150);else for(e.addClass("frm-page-collapsed"),t.addClass("frm-is-collapsed"),n=0;n<o;n++)n===o-1?jQuery(t[n]).slideUp(150,function(){t.css("cssText","display:none !important;")}):jQuery(t[n]).slideUp(150)}function zn(){this.parentNode.parentNode.parentNode.parentNode.classList.toggle("frm-section-collapsed")}function Rn(){this.classList.toggle("frm-collapsed");var e="true"===this.getAttribute("aria-expanded")||!1;this.setAttribute("aria-expanded",!e),Gn(this.nextElementSibling)}function Gn(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 Un(){if(this.id){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0],t=this.id.replace("field_label_",""),n=document.getElementById("field_options_type_".concat(t)),r=n.value;void 0!==e&&(r=function(e){return"divider"===e?e="section":"range"===e?e="slider":"data"===e?e="dynamic":"form"===e&&(e="embed form"),e}(r="SELECT"===n.tagName?n.options[n.selectedIndex].text.toLowerCase():r.replace("_"," ")),setTimeout(function(){e.value.toLowerCase()===r?e.select():e.focus()},50))}}function Wn(){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0];void 0!==e&&setTimeout(function(){e.focus(),Vn(e)},50)}function Vn(e){var t=e.closest(".frm-collapse-me");null!==t&&t.previousElementSibling.classList.remove("frm-collapsed")}function $n(e){var t,n,r=e.target.classList;if(!r.contains("frm-collapse-page")&&!r.contains("frm-sub-label")&&null===e.target.closest(".dropdown")){if(null!==this.closest(".start_divider")&&e.stopPropagation(),this.classList.contains("edit_field_type_divider")){var o=e.originalEvent.target.closest("ul.frm_sorting");if(null!==o&&(o.classList.contains("edit_field_type_divider")||o.parentNode.parentNode.classList.contains("start_divider")))return}t=this,n=jQuery(t),t.className.includes("selected")||t.className.includes("edit_field_type_end_divider")&&n.closest(".edit_field_type_divider").hasClass("no_repeat_section")||(Ke(),n.addClass("selected"),function(e){var t,n,r=e.getAttribute("data-fid"),o=e.getAttribute("data-type"),i=document.querySelectorAll(".frm-single-settings:not(.frm_hidden)");for(n=0;n<i.length;n++)i[n].classList.add("frm_hidden");var a=document.getElementById("frm-single-settings-".concat(r));oo(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"),document.getElementById("frm-options-panel-tab").click();var l=a.querySelector(".wp-editor-area");l&&frmDom.wysiwyg.init(l,{setupCallback:ro}),wp.hooks.doAction("frmShowedFieldSettings",e,a),function(e,t,n){var r;if(function(e){return wp.hooks.applyFilters("frm_fields_with_shortcode_popup",["html"]).includes(e)}(e)){var o="#frm-single-settings-".concat(t);if(!document.querySelector("".concat(o," .frm-show-box"))){null===(r=n.querySelector(".wp-editor-container"))||void 0===r||r.classList.add("frm_has_shortcodes");var i=function(){return frmDom.svg({href:"#frm_more_horiz_solid_icon",classList:["frm-show-box"]})};document.querySelectorAll("".concat(o," .frm_has_shortcodes textarea")).forEach(function(e){var t=d({className:"frm-with-right-icon"});e.parentNode.insertBefore(t,e),t.append(i()),t.append(e)})}}}(o,r,a)}(t))}}function Kn(e){var t=e.target;if("custom"===t.value){var n=t.dataset.fieldId,r=document.getElementById("frm-field-format-custom-".concat(n)).querySelector(".frm_format_opt");"international"!==r.value&&"currency"!==r.value&&"number"!==r.value||r.setAttribute("value","")}setTimeout(function(){t.querySelectorAll("option").forEach(function(e){e.selected&&e.classList.contains("frm_show_upgrade")&&(t.value="none")})},0)}function Jn(){var e=this.getAttribute("data-fid");Vn(document.getElementById("field_options_field_key_".concat(e)))}function Xn(){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 Yn(){var e=this.value;""!==e&&(e<2||e>200)&&(M(i.repeat_limit_min),this.value="")}function Zn(){var e=this.value;""!==e&&(e<1||e>200)&&(M(i.checkbox_limit),this.value="")}function er(e,t){jQuery(e).closest(".frm_field_box").find(".frm_".concat(t,"_form_row .frm_repeat_label")).text(e.value)}function tr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=this.value,n=document.getElementById("frm_show_selected_fields_".concat(e)),r=document.getElementById("frm_show_selected_forms_".concat(e));jQuery(r).find("select").val(""),"form"===t?(r.style.display="inline",function(e){if(null!==e)for(;e.firstChild;)e.firstChild.remove()}(n)):(n.style.display="none",r.style.display="none",xr(t,e))}function nr(){var e=rr(this);if(e){var t=jQuery(this).closest(".frm_single_option");!function(e,t,n){var r=n.data("optkey"),o=yr(e),i=jQuery('label[for="field_'.concat(t,"-").concat(r,'"]')),a="field_options[options_".concat(e,"][").concat(r,"]"),l=jQuery('input[name="'.concat(a,'[label]"]'));if(i.length<1)return ir(e),void(n.find('input[name^="default_value_"]').is(":checked")&&l.length>0&&jQuery('select[name^="item_meta['.concat(e,']"]')).val(l.val()));var s,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 u=i[0].childNodes;if(vr(e)){var f=function(e,t,n){var r,o=e.find("img");o&&(r=o.attr("src"));var i=hr(t);return pr(n.val(),i,r)}(n,e,l),m=i.find(".frm_image_option_container");m.length>0?m.replaceWith(f):(u[u.length-1].nodeValue="",i.append(f))}else{var _=!1;u.forEach(function(t,n){if(!1===_)"INPUT"===t.tagName&&(_=n);else if(n===_+1){var r="";!function(e){var t=document.getElementsByName("field_options[image_options_".concat(e,"]")),n=Array.from(t).find(function(e){return e.checked&&"buttons"===e.value});return void 0!==n}(e)?t.nodeValue=" ".concat(l.val()):(r=c({className:"frm_label_button_container",text:" ".concat(l.val())}),i[0].replaceChild(r,t))}else t.remove()})}d.val(s),defaultVal=n.find('input[name^="default_value_"]'),d.prop("checked",!!defaultVal.is(":checked"))}}(e.fieldId,e.fieldKey,t)}}function rr(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 or(e){var t,n=document.getElementById("field_options_image_size_".concat(e)),r="";return null!==n&&""!==(t=n.value)&&(r=t),r}function ir(e){var t=jQuery('[name^="item_meta['.concat(e,']"]'));if(!(t.length<1)){if(t.is("select")){var n=document.getElementById("frm_placeholder_".concat(e));null===n||""===n.value?dr(t[0],{sourceID:e}):dr(t[0],{sourceID:e,placeholder:n.value})}else{var r=fr(e);jQuery("#field_".concat(e,"_inner_container > .frm_form_fields")).html("");for(var o=rr(jQuery("#frm_delete_field_".concat(e,"-000_container"))),i=jQuery("#field_".concat(e,"_inner_container > .frm_form_fields")),a=vr(e),l=a?or(e):"",s=a?"frm_image_option frm_image_".concat(l," "):"",c=Oi(e),d="hidden"===t.attr("type")?t.data("field-type"):t.attr("type"),u=0;u<r.length;u++)i.append(cr(d,r[u],e,o.fieldKey,c,s))}lr(e)}}function ar(e,t){var n=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('input[value="'.concat(t,'"]'));return n?Cn(n):{newValue:t,newLabel:t}}function lr(e,t){for(var n=O.querySelectorAll(".frm_logic_row"),r=n.length,o=wp.hooks.applyFilters("frm_conditional_logic_field_options",function(e){var t=[],n=document.getElementById("frm_field_".concat(e,"_opts"));if(!n)return t;for(var r=n.querySelectorAll(".frm_single_option"),o=r.length,i=0;i<o;i++){var a=r[i];if(!a.classList.contains("frm_hidden")){var l=a.querySelector(".field_".concat(e,"_option"));t.push(l.value)}}return t}(e),{type:t,fieldId:e}),i=o.length,a=0;a<r;a++){var l=n[a];if(l.querySelector(".frm_logic_field_opts").value==e){for(var s=l.id.split("_")[2],c=l.querySelector('select[name="field_options[hide_opt_'.concat(s,'][]"]')),d=function(){var t,n=o[u],r=null===(t=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('.frm_option_key input[type="text"]'))||void 0===t?void 0:t.value;r||(r=n);var i=c.querySelector('option[value="'.concat(r,'"]')),a=ar(e,n),l=a.newValue,s=a.newLabel,d=document.querySelectorAll("#frm_field_".concat(e,"_opts input[data-value-on-focus]")),f=Array.from(d).find(function(e){return e.value===n});if(f){var m=f.dataset.valueOnFocus;if(m&&c.querySelector('option[value="'.concat(m,'"]')))return 1}sr(c,i,l,s)},u=i-1;u>=0;u--)d();var f=c.querySelector('option[value=""]');null!==f&&c.prepend(f)}}}function sr(e,t,n,r){null!==t||e.querySelector('option[value="'.concat(n,'"]'))||((t=frmDom.tag("option",{text:r})).value=n),e.prepend(t)}function cr(e,t,n,r,o,i){var a="",l=t.key.includes("other"),s="field_".concat(r,"-").concat(t.key),c="scale"===e?"radio":e,d='<input type="text" id="field_'.concat(r,"-").concat(t.key,'-otext" class="frm_other_input frm_pos_none" name="item_meta[other][').concat(n,"][").concat(t.key,']" value="" />');return this.getSingle=function(){return""!==(a=wp.hooks.applyFilters("frm_admin.build_single_option_template",a,{opt:t,type:e,fieldId:n,classes:i,id:s}))?a:'<div class="frm_'.concat(e," ").concat(e," ").concat(i,'" id="frm_').concat(e,"_").concat(n,"-").concat(t.key,'">\n\t\t\t\t\t<label for="').concat(s,'">\n\t\t\t\t\t\t<input type="').concat(c,'" name="item_meta[').concat(n,"]").concat("checkbox"===e?"[]":"",'" value="').concat(_r(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(_r(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 dr(e,t){if(null!==e){var n=t.sourceID,r=t.placeholder,o=Oi(n),i=t.other;!function(e){var t;if(void 0!==e.options)for(t=e.options.length-1;t>=0;t--)e.remove(t)}(e);for(var a=fr(n,e.id.includes("frm_field_logic_opt")),l=void 0!==r,s=0;s<a.length;s++){var c=a[s].label,d=a[s].key.includes("other");if(l&&""!==c?ur(e,r):l&&(c=r),l=!1,!d||i){var u=document.createElement("option");u.value=a[s].saved,u.innerHTML=_r(c),o&&u.setAttribute("data-price",a[s].price),e.append(u)}}}}function ur(e,t){var n=document.createElement("option"),r=e.firstChild;n.value="",n.innerHTML=t,null!==r?(r.before(n),e.selectedIndex=0):e.append(n)}function fr(e){var t,n,r,o,i,a,l=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=[],c=jQuery('input[name^="field_options[options_'.concat(e,']"]')).filter('[name$="[label]"], [name*="[other_"]'),d=Oi(e),u=hr(e),f=vr(e),m=yr(e);for(t=0;t<c.length;t++)c[t].name.indexOf("[000]")>0||(o=n=c[t].value,i=c[t].name.replace("field_options[options_".concat(e,"]["),"").replace("[label]","").replace("]",""),m&&(r=c[t].name.replace("[label]","[value]"),n=jQuery('input[name="'.concat(r,'"]')).val(),l&&""===o&&(o=""!==n?n:frm_admin_js.no_label)),f&&(o=pr(o,u,mr(c[t]))),a={saved:n,label:o=frmAdminBuild.hooks.applyFilters("frm_choice_field_label",o,e,c[t],f),checked:gr(c[t].id),key:i},d&&(r=c[t].name.replace("[label]","[price]"),a.price=jQuery('input[name="'.concat(r,'"]')).val()),s.push(a));return s}function mr(e){var t=jQuery(e).siblings(".frm_image_preview_wrapper");if(!t.length)return"";var n=t.find("img");return n.length?n.attr("src"):""}function _r(e){(e instanceof Element||e instanceof Document)&&(e=e.outerHTML);var t=jQuery.parseHTML(e).reduce(function(e,t){var n=frmDom.cleanNode(t);return"#text"===n.nodeName?e+n.textContent:e+n.outerHTML},"");return t!==e?_r(t):t}function pr(e,t,n){var r,o=e;o=_r(o),n?r=m({src:n,alt:o}):(r=c({className:"frm_empty_url"})).innerHTML=i.image_placeholder_icon;var a=t?" frm_label_with_image":"",l=s("span",{className:"frm_text_label_for_image_inner"});return l.innerHTML=o,s("span",{className:"frm_image_option_container".concat(a),children:[r,s("span",{className:"frm_text_label_for_image",child:l})]})}function gr(e){var t=jQuery("#".concat(e));if(0===t.length)return!1;var n=t.siblings("input[type=checkbox]");return n.length&&n.prop("checked")}function yr(e){return br("separate_value_".concat(e))}function vr(e){for(var t=!1,n=document.getElementsByName("field_options[image_options_".concat(e,"]")),r=0;r<n.length;r++)n[r].checked&&(t="0"!==n[r].value);return frmAdminBuild.hooks.applyFilters("frm_choice_field_images_as_options",t,e)}function hr(e){var t=!br("hide_image_text_".concat(e));return frmAdminBuild.hooks.applyFilters("frm_choice_field_showing_label_with_image",t,e)}function br(e){var t=document.getElementById(e);return null!==t&&t.checked}function jr(e){var t=e.closest(".frm-single-settings"),n=t.getAttribute("data-fid"),r=t.querySelector('[name="field_options[separate_value_'.concat(n,']"]')).checked;if(!r||e.name.endsWith("[value]")){var o=document.getElementById("frm_field_".concat(n,"_opts"));Array.from(o.querySelectorAll('input[type="text"]')).filter(function(t){return t.id!==e.id&&r===t.name.endsWith("[value]")&&t.value===e.value}).length&&M(B(I('Duplicate option value "%s" detected',"formidable"),_r(e.value)))}}function wr(){var e=this.value;if(e){var t=this.parentNode.id.replace("frm_logic_","").split("_"),n=t[0],r=t[1],o=document.getElementById("frm_field_id_".concat(e)).getAttribute("data-ftype"),i=document.getElementById("frm_show_selected_values_".concat(n,"_").concat(r)),a="field_options[hide_opt_".concat(n,"][]"),l="frm_field_logic_opt_".concat(n),s=!1,c="select"===o||"checkbox"===o||"radio"===o,d="text"===o||"email"===o||"phone"===o||"url"===o||"number"===o;if(c&&null!==document.getElementById("frm_has_hidden_options_".concat(e))&&(c=!1),c||d){var u=document.querySelector("#frm_logic_".concat(n,"_").concat(r,' [name="field_options[hide_field_cond_').concat(n,'][]"]')).value;i.innerHTML="";var f=c&&!["LIKE","not LIKE","LIKE%","%LIKE"].includes(u);f?s=document.createElement("select"):(s=document.createElement("input")).type="text",s.name=a,s.id="".concat(l,"_").concat(r),i.append(s),f&&dr(document.getElementById(s.id),{sourceID:e,placeholder:"",other:!0})}else{var m=this.getAttribute("data-type");frmGetFieldValues(e,n,r,m,void 0,function(){var e=new CustomEvent("frm_logic_options_loaded");e.frmData={valueFieldType:o,fieldID:n,metaKey:r},document.dispatchEvent(e)})}}}function Qr(){var e=this.value;e&&xr(e,jQuery(this).closest(".frm-single-settings").data("fid"))}function xr(e,t){e&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_field_selection",field_id:t,form_id:e,nonce:frmGlobal.nonce},success:function(e){var n=jQuery("#frm_show_selected_fields_".concat(t));n.toggleClass("frm6",!e.includes("frm-inline-message")),n.html(e).show()}})}function Er(){var e=this;return this.initOnceInAllInstances=function(){void 0===Er.prototype.orderFieldsObject&&(Er.prototype.orderFieldsObject={},Er.prototype.fieldSettingsForm=document.getElementById("frm-end-form-marker").closest("form"))},this.getFieldOrderInputById=function(e,t){var n,r=Er.prototype.orderFieldsObject,o=Er.prototype.fieldSettingsForm;return void 0===r[e]?(null===(n=o.querySelector('input[name="field_options[field_order_'.concat(e,']"]')))&&(n=t.querySelector('input[name="field_options[field_order_'.concat(e,']"]'))),r[e]=n,n):r[e]},this.initOnceInAllInstances(),Dn(),function(){var t,n,r,o,i,a,l=new oo,s=jQuery("li.frm_field_box",jQuery("#frm-show-fields"));for(i=0;i<s.length;i++)t=s[i].getAttribute("data-fid"),(r=null!==(n=e.getFieldOrderInputById(t,s[i]))?Object.assign({},n.value)[0]:null)!=(o=i+1)&&null!==r&&(n.value=o,a=s[i].querySelector("#frm-single-settings-".concat(t)),l.append(a),Po());l.moveFields()}()}function kr(){document.querySelectorAll(".start_divider").forEach(function(e){Ar(jQuery(e))})}function Ar(e){if(e.length){for(var t=e.find("ul.frm_sorting"),n=!1,r=t.length,o=0;o<r;++o)if(0!==ie(jQuery(t.get(o))).length){n=!0;break}e.parent().children(".frm_no_section_fields").get(0).classList.toggle("frm_block",!n)}}function Sr(){var e=jQuery(this).data("slidedown"),t=jQuery(document.getElementById(e));return t.is(":hidden")&&(t.slideDown("fast"),this.style.display="none"),!1}function Lr(){var e=jQuery(this).data("slideup"),t=jQuery(document.getElementById(e));return t.slideUp("fast"),t.siblings("a").show(),!1}function Ir(e,t){""===t.getAttribute("value")?Br(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 Br(e);var n=t.indexOf("");n>=0&&(t.splice(n,1),e.val(t),e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!1))}(jQuery(this))}function Br(e){e.val(""),e.next(".btn-group").find('.multiselect-container input[value!=""]').prop("checked",!1)}function qr(){jQuery(".frm-hide-empty").each(function(){0===jQuery(this).text().trim().length&&jQuery(this).remove()})}function Cr(e){e.preventDefault(),function(e,t,n){var r=document.getElementById(e.getAttribute("data-open")),o=jQuery(e).closest("p,ul"),i=void 0!==t;if(o.hasClass("frm-open"))o.removeClass("frm-open"),r.classList.add("frm_hidden");else{if(i||(t=Wo(e)),null!==t){if(!i){var a=n.key;"Enter"!==a&&" "!==a&&t.focus()}o.after(r),r.setAttribute("data-fills",t.id.replace("-proxy-input","")),0===r.id.indexOf("frm-calc-box")&&Ze(r,!0)}o.addClass("frm-open"),r.classList.remove("frm_hidden"),wp.hooks.doAction("frm_show_inline_modal",r,e)}}(this,void 0,e)}function Nr(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 Tr(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 Or(){var e,t=this.getAttribute("data-frmchange").split(",");for(e=0;e<t.length;e++)"updateOption"===t[e]?Dr(this):"updateDefault"===t[e]?Fr(this):"checkUniqueOpt"===t[e]?jr(this):this.value=this.value[t[e]]()}function Fr(e){var t=Mr(e),n=t.getAttribute("data-optkey"),r=Pr(t,n),o=t.querySelector('input[name="default_value_'.concat(r,'"]'));null!==o&&(o.value=e.value)}function Dr(e){var t,n=Mr(e),r=n.getAttribute("data-optkey"),o=Pr(n,r),i=document.getElementById("separate_value_".concat(o));null!==i&&!1===i.checked&&((t=document.getElementById("field_key_".concat(o,"-").concat(r))).value=e.value,Fr(t))}function Mr(e){var t=e.parentNode;return"LI"!==t.tagName&&(t=t.parentNode),t}function Pr(e,t){return e.id.replace("frm_delete_field_","").replace("-".concat(t,"_container"),"")}function Hr(){var e=this;if(!Ur()){$r(this);var t=jQuery(j),n=JSON.stringify(t.serializeArray());jQuery(document.getElementById("frm_compact_fields")).val(n),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_save_form",frm_compact_fields:n,nonce:frmGlobal.nonce},success:function(t){var n;(n=e).classList.remove("frm_loading_form"),n.classList.remove("frm_loading_button"),jQuery('.frm-single-settings ul input[type="text"][name^="field_options[options_"]').filter("[data-value-on-load]").removeAttr("data-value-on-load"),jQuery('input[type="hidden"][name^=optionmap]').remove(),x=0,n.setAttribute("aria-busy","false"),setTimeout(function(){jQuery(".frm_updated_message").fadeOut("slow",function(){this.remove()})},5e3);var r,o=document.getElementById("post-body-content"),i=document.createElement("div");i.setAttribute("class","frm_updated_message"),i.innerHTML=t,o.insertBefore(i,o.firstChild),(r=document.getElementById("frm_submit_side_top")).hasAttribute("data-new-addon-installed")&&"true"===r.getAttribute("data-new-addon-installed")&&(r.removeAttribute("data-new-addon-installed"),window.location.reload())},error:function(){zr(document.getElementById("frm_js_build_form"))}})}}function zr(e){var t=e.ownerDocument.createElement("input");t.style.display="none",t.type="submit",e.append(t),t.click(),t.remove()}function Rr(e){jQuery(e).trigger("change")}function Gr(){if(!Ur()){$r(this);var e=jQuery(j);jQuery(document.getElementById("frm_compact_fields")).val(JSON.stringify(e.serializeArray())),zr(document.getElementById("frm_js_build_form"))}}function Ur(){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,n=Bi("#frm-form-templates-modal","440px");return!!n&&(Uo(n,"72px"),n.dialog("open"),!0)}function Wr(){var e=document.getElementById("frm-save-form-name-button"),t=document.getElementById("frm_new_form_name_input");_(e,Vr),t.addEventListener("keydown",function(e){"Enter"===e.key&&Vr(e)})}var Vr=function(e){var t=document.getElementById("frm_new_form_name_input").value.trim(),n=new FormData;n.append("form_id",T.get("id")),n.append("form_name",t),p("rename_form",n).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 $r(e){var t,n;Ci(),jQuery("form.inplace_form").length&&jQuery(".inplace_save, .postbox").trigger("click"),e.classList.contains("frm_button_submit")?e.classList.add("frm_loading_form"):e.classList.add("frm_loading_button"),e.setAttribute("aria-busy","true"),t=document.querySelectorAll(".frm_format_dropdown, .frm_phone_type_dropdown"),n={none:"",international:"international",currency:"currency",number:"number"},t.forEach(function(e){var t=e.value;t in n&&(document.getElementById("frm_format_".concat(e.dataset.fieldId)).value=n[t])})}function Kr(e){var t,n=null!==(t=e.target.dataset)&&void 0!==t&&t.modalTitle?e.target:e.target.closest("[data-modal-title]");if(n){var r=n.dataset,o=r.modalTitle,i=r.modalContent;o&&i&&(e.preventDefault(),frmDom.modal.maybeCreateModal("frmBasicModal",{title:o,content:c({className:"inside",child:d(i)})}))}}function Jr(e){var t,r,o,i=e.dataset.upgrade,a=e.getAttribute("href").replace("#",""),l=document.querySelector(".frm_".concat(a))||document.querySelector(".".concat(a));if(l&&!l.querySelector(".frm-upgrade-message")){var s=l.querySelector("h2");s.style.borderBottom="none",s.textContent=B(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 u=d.querySelector(".frm-upgrade-link");if(u){var f,_,p=u.closest(".frm-upgrade-modal-actions"),g=(_=p?(p=p.cloneNode(!0)).querySelector(".frm-upgrade-link"):u.cloneNode(!0)).querySelector(".license-level");g&&(g.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(e)),l.append(p||_),null!==(f=u.nextElementSibling)&&void 0!==f&&f.querySelector(".frm-link-secondary")&&l.append(u.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,r){n(4260).addOneClick(e,"tab",r)}(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:[(r=["#ED8181","#EDE06A","#80BE30"].map(function(e){var t=c({className:"frm-minmax-icon"});return t.style.backgroundColor=e,t}),r.push(m({src:"".concat(frmGlobal.url,"/images/tab.svg")})),c({className:"frm-settings-screenshot-toolbar",children:r})),c({child:m({src:o+t})})]})))}function v(e){l.append(d.querySelector(".".concat(e)).cloneNode(!0))}}function Xr(e){void 0===e&&(e=""),function(e){var t,n=jQuery("".concat(e," :not(.frm_has_shortcodes) .frm_not_email_message, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_to, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_subject"));for(t=0;t<n.length;t++)n[t].parentNode.classList.add("frm_has_shortcodes")}(e),jQuery("".concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) input,").concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) textarea")).wrap('<span class="frm-with-right-icon"></span>').before('<svg class="frmsvg frm-show-box"><use href="#frm_more_horiz_solid_icon"/></svg>')}function Yr(){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 Zr(e){if(!function(e){var t=jQuery(e),n=t.closest(".frm_form_action_settings"),r=n.find(".widget-inside");if(r.find("p, div, table").length)return!1;var o=n.find(".widget-top");return o.on("frm-action-loaded",function(){t.trigger("click"),n.removeClass("open"),r.hide()}),o.trigger("click"),!0}(e.target)){var t=e.target.closest(".frm_form_action_settings"),n=t.querySelectorAll(".wp-editor-area");n.length&&n.forEach(function(e){tinymce.EditorManager.execCommand("mceRemoveEditor",!0,e.id)});var r=jQuery(t).clone(),o=r.attr("id").replace("frm_form_action_",""),i=eo(o);r.find(".frm_action_id, .frm-btn-group").remove(),r.find('input[name$="['.concat(o,'][ID]"]')).val(""),r.find(".widget-inside").hide(),r.find("input[type=text], textarea, input[type=number]").prop("defaultValue",function(){return this.value}),r.find("input[type=checkbox], input[type=radio]").prop("defaultChecked",function(){return this.checked});var a=new RegExp("\\[".concat(o,"\\]"),"g"),l=new RegExp("_".concat(o,'"'),"g"),s=new RegExp("-".concat(o,'"'),"g"),d=new RegExp('"'.concat(o,'"'),"g"),u=r.html().replace(a,"[".concat(i,"]")).replace(l,"_".concat(i,'"'));u=u.replace(s,"-".concat(i,'"')).replace(d,'"'.concat(i,'"'));var f=c({id:"frm_form_action_".concat(i),className:r.get(0).className});f.setAttribute("data-actionkey",i),f.innerHTML=u,f.querySelectorAll(".wp-editor-wrap, .wp-editor-wrap *").forEach(function(e){"string"==typeof e.className&&(e.className=e.className.replace(o,i)),e.id=e.id.replace(o,i)}),f.classList.remove("open"),document.getElementById("frm_notification_settings").append(f),n.length&&(n.forEach(function(e){frmDom.wysiwyg.init(e)}),f.querySelectorAll(".wp-editor-area").forEach(function(e){frmDom.wysiwyg.init(e)})),f.classList.contains("frm_single_on_submit_settings")&&f.querySelector("input.frm-page-search")&&yi(f),ci(),wp.hooks.doAction("frm_after_duplicate_action",f)}}function eo(e){var t=parseInt(e,10)+11;return null!==document.getElementById("frm_form_action_".concat(t))&&(t=eo(++t)),t}function to(){var e,t=jQuery(this).data("actiontype");if(!co(t)){var n=(e=Ln(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),r=E,o=document.createElement("div");o.classList.add("frm_single_".concat(t,"_settings"));var i=document.getElementById("frm_notification_settings");i.append(o),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_action",type:t,list_id:n,form_id:r,nonce:frmGlobal.nonce},success:function(e){Po(),o.remove(),document.querySelectorAll(".frm_form_action_settings.open").forEach(function(e){return e.classList.remove("open")});var r=c();r.innerHTML=e;var a=r.querySelector(".widget-top");Array.from(r.children).forEach(function(e){return i.append(e)}),jQuery(".frm_form_action_settings").fadeIn("slow");var l=document.getElementById("frm_form_action_".concat(n));l.classList.add("open"),document.getElementById("post-body-content").scroll({top:l.offsetTop+10,left:0,behavior:"smooth"}),so(t),Xr("#frm_form_action_".concat(n)),ci(),yi(l),a&&jQuery(a).trigger("frm-action-loaded"),frmAdminBuild.hooks.doAction("frm_added_form_action",l)}})}}function no(){var e=document.getElementById("frm_email_addon_menu").classList,t=document.getElementById("actions-search-input");e.contains("frm-all-actions")?(e.remove("frm-all-actions"),e.add("frm-limited-actions")):(e.add("frm-all-actions"),e.remove("frm-limited-actions")),t.value="",ki(t,"input")}function ro(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 null!==t&&t.classList.contains("tmce-active")})()&&!tinyMCE.activeEditor.isHidden()&&(e.targetElm.value=e.getContent(),jQuery(e.targetElm).trigger("change"))}(e)})}function oo(e){var t=this;if(null!==e)return this.fragment=document.createDocumentFragment(),this.initOnceInAllInstances=function(){void 0===oo.prototype.endMarker&&(oo.prototype.endMarker=document.getElementById("frm-end-form-marker"))},this.append=function(e){var n=null!==e?e.parentElement.classList:"";null!==e&&(n.contains("frm_field_box")||n.contains("divider_section_only"))&&t.fragment.append(e)},this.moveFields=function(){j.insertBefore(t.fragment,oo.prototype.endMarker)},this.initOnceInAllInstances(),void 0!==e?(this.append(e),void this.moveFields()):{append:this.append,moveFields:this.moveFields}}function io(){var e=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),t=this.getAttribute("data-emailrow");jQuery("#frm_form_action_".concat(e," .frm_").concat(t,"_row")).fadeIn("slow"),jQuery(this).fadeOut("slow")}function ao(){var e=jQuery(this).closest(".frm_form_action_settings"),t=this.getAttribute("data-emailrow"),n=".frm_".concat(t,"_row"),r=".frm_".concat(t,"_button");jQuery(e).find(r).fadeIn("slow"),jQuery(e).find(n).fadeOut("slow",function(){jQuery(e).find("".concat(n," input")).val("")})}function lo(){var e=jQuery(this).closest(".frm_form_action_settings"),t=".frm_from_to_match_row";e.find('input[name$="[post_content][from]"]').val()===e.find('input[name$="[post_content][email_to]"]').val()?jQuery(e).find(t).fadeIn("slow"):jQuery(e).find(t).fadeOut("slow")}function so(e){var t,n,r=document.querySelectorAll(".frm_".concat(e,"_action"));co(e)?(t=r,n=uo(e)>0,t.forEach(function(e){e.classList.remove("frm_active_action"),e.classList.add("frm_inactive_action"),n&&e.classList.add("frm_already_used")})):r.forEach(function(e){e.querySelector(".frm_show_upgrade")||(e.classList.remove("frm_inactive_action","frm_already_used"),e.classList.add("frm_active_action"))})}function co(e){var t=function(e){return jQuery(".frm_single_".concat(e,"_settings")).length}(e)>=uo(e),n={type:e};return wp.hooks.applyFilters("frm_action_at_limit",t,n)}function uo(e){return parseInt(jQuery(".frm_".concat(e,"_action")).data("limit"),10)}function fo(){var e=i.only_one_action,t=this.dataset.limit;void 0!==t&&((t=parseInt(t))>1?e=e.replace(1,t).trim():e+=" ".concat(i.edit_action_text)),M(e)}function mo(){var e=jQuery(this).data("emailkey"),t=jQuery(this).closest(".frm_form_action_settings").find(".frm_action_name").val(),n=document.getElementById("form_id").value,r=document.getElementById("frm_logic_row_".concat(e)),o=Ln(r.querySelectorAll(".frm_logic_row"),"frm_logic_".concat(e,"_")),i=c({id:"frm_logic_".concat(e,"_").concat(o),className:"frm_logic_row frm_hidden"});return r.append(i),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_logic_row",email_id:e,form_id:n,meta_name:o,type:t,nonce:frmGlobal.nonce},success:function(t){jQuery(document.getElementById("logic_link_".concat(e))).fadeOut("slow",function(){i.insertAdjacentHTML("beforebegin",t),i.remove(),jQuery(r).parent(".frm_logic_rows").fadeIn("slow")})}}),!1}function _o(){var e=jQuery("select.frm_single_post_field");e.css("border-color","");var t=this,n=jQuery(t).val();if(""===n||"checkbox"===n)return!1;e.each(function(){if(jQuery(this).val()===n&&this.name!==t.name)return this.style.borderColor="red",jQuery(t).val(""),M(i.field_already_used),!1})}function po(){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 go(){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 yo(){var e,t,n=document.getElementById("frm_posttax_rows").childNodes,r=document.querySelector(".frm_post_parent_field"),o=document.querySelector(".frm_post_menu_order_field"),i=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_replace_posttax_options",post_type:i,nonce:frmGlobal.nonce},success:function(r){for(var o=0;o<n.length;o++)"DIV"===n[o].tagName&&(e=n[o].getElementsByTagName("select")[0],(t=document.createElement("select")).innerHTML=r,t.className=e.className,t.name=e.name,n[o].replaceChild(t,e))}}),r&&vo(r,i,"frm_get_post_parent_option",function(e,t){r.querySelector(".frm_post_parent_opt_wrapper").innerHTML=e.replaceAll("REPLACETHISNAME",t),yi(r)}),o&&vo(o,i,"frm_should_use_post_menu_order_option")}function vo(e,t,n,r){var o=(e.querySelector(".frm_autocomplete_value_input")||e.querySelector("select")).getAttribute("name");jQuery.ajax({url:ajaxurl,method:"POST",data:{action:n,post_type:t,_wpnonce:frmGlobal.nonce},success:function(t){if("string"==typeof t){if("0"===t)return e.classList.add("frm_hidden"),void(e.value="");e.classList.remove("frm_hidden"),"function"==typeof r&&r(t,o)}else console.error(t)},error:function(e){return console.error(e)}})}function ho(){jo("tax",this)}function bo(){jo("meta",this)}function jo(e,t){var n,r,o=jQuery('input[name="id"]').val(),i=jQuery(t).closest(".frm_form_action_settings"),a=i.data("actionkey"),l=i.find(".frm_post_type").val(),s=0,c=document.querySelectorAll(".frm_post".concat(e,"_row"));c.length&&(r=n=c[c.length-1].id.replace("frm_post".concat(e,"_"),""),s=!isNaN(parseFloat(r))&&isFinite(r)?1+parseInt(n,10):1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_post".concat(e,"_row"),form_id:o,meta_name:s,tax_key:s,post_type:l,action_key:a,nonce:frmGlobal.nonce},success:function(t){var n,r;if(jQuery(document.getElementById("frm_post".concat(e,"_rows"))).append(t),jQuery(".frm_add_post".concat(e,"_row.button")).hide(),"meta"===e)for(jQuery(".frm_name_value").show(),n=document.querySelectorAll(".frm_toggle_cf_opts"),r=0;r<n.length-1;++r)n[r].style.display="none";else"tax"===e&&jQuery(".frm_posttax_labels").show()}})}function wo(){if(jQuery(this).closest(".frm_posttax_row").find(".frm_posttax_opt_list").length){jQuery(this).closest(".frm_posttax_row").find(".frm_posttax_opt_list").html('<div class="spinner frm_spinner" style="display:block"></div>');var e=jQuery(this).closest(".frm_form_action_settings").find('select[name$="[post_content][post_type]"]').val(),t=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),n=jQuery(this).closest(".frm_posttax_row").attr("id").replace("frm_posttax_",""),r=jQuery(this).val(),o=jQuery(document.getElementById("".concat(n,"_show_exclude"))).is(":checked")?1:0,i=jQuery('select[name$="[post_category]['.concat(n,'][field_id]"]')).val(),a=jQuery('input[name="id"]').val();jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_posttax_row",form_id:a,post_type:e,tax_key:n,action_key:t,meta_name:r,field_id:i,show_exclude:o,nonce:frmGlobal.nonce},success:function(e){jQuery(document.getElementById("frm_posttax_".concat(n))).replaceWith(e)}})}}function Qo(){var e=jQuery(this).closest(".frm_postmeta_row"),t=e.find(".frm_cancelnew"),n=e.find(".frm_enternew");return e.find("select.frm_cancelnew").is(":visible")?(t.hide(),n.show()):(t.show(),n.hide()),e.find("input.frm_enternew, select.frm_cancelnew").val(""),!1}function xo(){var e=jQuery(this),t=e.val();"checkbox"===e.attr("type")&&!1===this.checked&&(t="");var n=e.data("toggleclass");""===t?jQuery(".".concat(n)).hide():(jQuery(".".concat(n)).show(),jQuery(".hide_".concat(n,"_").concat(t)).hide())}function Eo(){Ur()||($r(this),zr(document.querySelector(".frm_form_settings")))}function ko(e){return e.preventDefault(),Ao(jQuery(this),this.getAttribute("data-code")),!1}function Ao(e,t){var n=!1,r=e;if("object"===a(e)){if(e.hasClass("frm_noallow"))return;void 0===(r=jQuery(e).closest("[data-fills]").attr("data-fills"))&&void 0!==(r=e.closest("div").attr("class"))&&(r=r.split(" ")[1])}if(void 0===r){var o=document.activeElement;"search"===o.type?null===(r=o.id.replace("-search-input","")).match(/\d/gi)&&(r=(o=jQuery(".frm-single-settings:visible .".concat(r))).attr("id")):r=o.id}r&&(n=jQuery("#wp-".concat(r,"-wrap.wp-editor-wrap")).length>0);var i=jQuery(document.getElementById(r));if(void 0===e.attr("data-shortcode")&&(!i.length||void 0===i.attr("data-shortcode"))){var l=e.parents("ul.frm_code_list").attr("data-shortcode");"undefined"!==l&&"no"===l||(t="[".concat(t,"]"))}if(n&&(wpActiveEditor=r),!i.length)return!1;if("[default-html]"===t||"[default-plain]"===t){var s=0;"[default-plain]"===t&&(s=1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_default_html",form_id:jQuery('input[name="id"]').val(),plain_text:s,nonce:frmGlobal.nonce},elementId:r,success:function(e){if(n){var t=document.createElement("p");t.innerText=e,send_to_editor(t.innerHTML)}else So(i,e)}})}else t=function(e,t,n){return"object"===a(t)&&t instanceof jQuery&&0===n[0].id.indexOf("success_url_")&&(t=t[0]).closest("#frm-insert-fields-box")?(t.parentNode.classList.contains("frm_insert_url")||(e=e.replace("]"," sanitize_url=1]")),e):e}(t,e,i),n?send_to_editor(t):So(i,t);return!1}function So(e,t){if(document.selection)e[0].focus(),document.selection.createRange().text=t;else{var n=e[0],r=n.selectionEnd;t=function(e,t,n,r){var o=e.data("sep");if(void 0===o)return t;var i=e.val();if(!i.trim().length)return t;var a=new RegExp("".concat(o,"\\s*$")),l=new RegExp("^\\s*".concat(o));return i.substr(0,n).trim().length&&!1===a.test(i.substr(0,n))&&(t=o+t),i.substr(r,i.length).trim().length&&!1===l.test(i.substr(r,i.length))&&(t+=o),t}(e,t,n.selectionStart,r),n.value=n.value.substr(0,n.selectionStart)+t+n.value.substr(n.selectionEnd,n.value.length);var o=r+t.length;!function(e,t){if(e.classList.contains("frm_classes")&&Lo(t)){var n=e.value.split(" ").filter(Lo);n.length&&(e.value=function(e,t,n){var r=e.split(" ").filter(function(e){return(e=e.trim()).length&&!t.includes(e)});return r.includes(n)||r.push(n),r.join(" ")}(e.value,n,t.trim()))}}(n,t),n.focus(),n.setSelectionRange(o,o)}Rr(e)}function Lo(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 Io(){var e=document.getElementById("frm-id-condition"),t=document.getElementById("frm-key-condition");"id"===this.value?(e.classList.remove("frm_hidden"),t.classList.add("frm_hidden"),ki(t,"change")):(e.classList.add("frm_hidden"),t.classList.remove("frm_hidden"),ki(e,"change"))}function Bo(){var e=document.getElementById("frm-id-key-condition-id").checked?"frm-id-condition":"frm-key-condition",t=document.getElementById("frm-is-condition").value,n=document.getElementById("frm-text-condition").value,r=document.getElementById("frm-insert-condition"),o=(e=document.getElementById(e)).options[e.selectedIndex].value,a="if ".concat(o," ").concat(t,'="').concat(n,'"]');r.setAttribute("data-code","".concat(a+i.conditional_text,"[/if ").concat(o)),r.innerHTML="[".concat(a,"[/if ").concat(o,"]")}function qo(e){return e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href")}function Co(e){var t;e.parentNode.parentNode.classList.contains("frm_has_shortcodes")&&($o(),"use"===(t=Vo(e)).tagName?qo(t=t.firstElementChild).includes("frm_close_icon")||Do(t,"nofocus"):t.classList.contains("frm_close_icon")||Do(t,"nofocus"))}function No(e){e.preventDefault(),e.stopPropagation(),Do(this)}function To(e){!function(e){var t;if(e.id.startsWith("field_options_type_")){var n=e.id.split("_"),r=n.length&&n[n.length-1];null!==(t=document.querySelector("#frm-single-settings-".concat(r)))&&void 0!==t&&t.classList.contains("frm-type-".concat(e.value))||Oo()}}(e.target)}function Oo(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 Fo(e){var t;if(e instanceof Event){var n=document.querySelectorAll(".frm-single-settings .frm-show-box.frmsvg use"),r=Array.from(n).find(function(e){return"#frm_close_icon"===e.getAttribute("href")});if(void 0===r)return;t=r.parentElement}else t=e;var o=t.getBoundingClientRect(),i=document.getElementById("frm_adv_info"),a=i.parentElement.getBoundingClientRect();i.style.top="".concat(o.top-a.top+32,"px"),i.style.left="".concat(o.left-a.left-280,"px")}function Do(e,t){var n=Wo(e),r=document.getElementById("frm_adv_info"),a=e.className;if("svg"===e.tagName&&(e=e.firstElementChild),"use"===e.tagName&&(a=qo(e)),a.includes("frm_close_icon"))$o(r);else{if(Fo(e),jQuery(".frm_code_list a").removeClass("frm_noallow"),n.classList.contains("frm_not_email_to")?jQuery("#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a").addClass("frm_noallow"):n.classList.contains("frm_not_email_subject")&&jQuery(".frm_code_list li.hide_frm_not_email_subject a").addClass("frm_noallow"),r.setAttribute("data-fills",n.id),r.style.display="block","use"===e.tagName)if(e.hasAttributeNS("http://www.w3.org/1999/xlink","href"))e.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon");else{var l=document.createElementNS("http://www.w3.org/2000/svg","use");l.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon"),e.parentNode.replaceChild(l,e)}else e.className=a.replace("frm_more_horiz_solid_icon","frm_close_icon");"nofocus"!==t&&("none"!==n.style.display?n.focus():jQuery(tinymce.get(n.id)).trigger("focus")),function(e){["address","body"].forEach(function(t){!function(e,t){var n,r=i.contextualShortcodes["".concat(t,"Selector")],a=i.contextualShortcodes[t],l=e.matches(r),s=function(e){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!t){if(Array.isArray(e)||(t=o(e))){t&&(e=t);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,l=!1;return{s:function(){t=t.call(e)},n:function(){var e=t.next();return a=e.done,e},e:function(e){l=!0,i=e},f:function(){try{a||null==t.return||t.return()}finally{if(l)throw i}}}}(a);try{for(s.s();!(n=s.n()).done;){var c,d=n.value,u=null===(c=document.querySelector('#frm-adv-info-tab .frm_code_list [data-code="'.concat(d,'"]')))||void 0===c?void 0:c.closest("li");null==u||u.classList.toggle("frm_hidden",!l)}}catch(e){s.e(e)}finally{s.f()}}(e,t)})}(n)}}function Mo(e){return 0===i.contextualShortcodes.length||!function(e){var t=e.querySelector("a");if(!t)return!1;var n=t.dataset.code;return i.contextualShortcodes.address.includes(n)||i.contextualShortcodes.body.includes(n)}(e)||function(e){var t=e.querySelector("a").dataset.code,n=document.getElementById("frm_adv_info").dataset.fills,r=document.getElementById(n),o=i.contextualShortcodes;return o.address.includes(t)?r.matches(o.addressSelector):r.matches(o.bodySelector)}(e)}function Po(){x||(x=1,window.addEventListener("beforeunload",Go))}function Ho(){x=0}function zo(){x=0}function Ro(){x=0}function Go(e){x&&(e.preventDefault(),e.returnValue="")}function Uo(e,t){var n={my:"top",at:"top+".concat(t),of:window};e.dialog("option","position",n)}function Wo(e){if(e.classList.contains("frm-input-icon"))return e.previousElementSibling;for(var t,n=e.nextElementSibling;null!==n&&("INPUT"!==n.tagName&&"TEXTAREA"!==n.tagName||n.classList.contains("frm-token-input-field"));)n=Wo(n);return n||(n=null===(t=e.closest(".frm-field-formula"))||void 0===t?void 0:t.querySelector(".frm-calc-field")),n}function Vo(e){var t;if(null!==(t=e.nextElementSibling)&&void 0!==t&&t.classList.contains("frm-input-icon"))return e.nextElementSibling;for(var n=e.previousElementSibling;null!==n&&"I"!==n.tagName&&"svg"!==n.tagName;)n=Vo(n);return n}function $o(e){if((void 0!==e||null!==(e=document.getElementById("frm_adv_info")))&&null===document.getElementById("frm_dyncontent")){e.style.display="none";for(var t=document.querySelectorAll(".frm-show-box.frm_close_icon"),n=0;n<t.length;n++)t[n].classList.remove("frm_close_icon"),t[n].classList.add("frm_more_horiz_solid_icon");for(var r=document.querySelectorAll(".frm_has_shortcodes use"),o=0;o<r.length;o++)if("#frm_close_icon"===qo(r[o])){if(r[o].closest(".frm_remove_field"))continue;r[o].setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_more_horiz_solid_icon")}}}function Ko(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 Jo(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 Xo(){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 Yo(){var e=jQuery(this),t=this.name,n=this.getAttribute("data-plugin"),r=t.replace("edd_".concat(n,"_license_"),""),o=document.getElementById("edd_".concat(n,"_license_key")).value;e.get(0).disabled=!0,jQuery.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_".concat(r),license:o,plugin:n,nonce:frmGlobal.nonce},success:function(t){e.get(0).disabled=!1;var i=e.closest(".edd_frm_license_row");"deactivate"===r&&(o="",document.getElementById("edd_".concat(n,"_license_key")).value=""),i.find(".edd_frm_license").html(o);var a=e.get(0).closest(".frm_form_field"),l=!0===t.success;a.querySelector(".frm_icon_font.frm_action_success").classList.toggle("frm_hidden",!l||"deactivate"===r),a.querySelector(".frm_icon_font.frm_action_error").classList.toggle("frm_hidden",l);var s=i.find(".frm_license_msg");s.html(t.message),""!==t.message&&setTimeout(function(){if(s.html(""),i.find(".frm_icon_font").addClass("frm_hidden"),l){var e="activate"===r;i.get(0).querySelector(".edd_frm_unauthorized").classList.toggle("frm_hidden",e),i.get(0).querySelector(".edd_frm_authorized").classList.toggle("frm_hidden",!e)}},2e3)}})}function Zo(e){e.preventDefault();var t=jQuery(e.target).find("input:checked");if(t.length){var n,r,o,i,a=[];t.each(function(e){a[e]=this.value}),n=a,r=e.target,(i=(o=jQuery(r)).next(".frm-importer-process")).find(".form-total").text(n.length),i.find(".form-current").text("1"),o.hide(),i.find(".process-completed").hide(),i.show(),C.importQueue=n,C.imported=0,ei(i)}}function ei(e){var t=C.importQueue[0],n=jQuery("#welcome-panel").find('input[name="slug"]').val(),r={action:"frm_import_".concat(n),form_id:t,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,r,function(n){var r;n.success&&(r=n.data.error?"<p>".concat(n.data.name,": ").concat(n.data.msg,"</p>"):'<p>Imported <a href="'.concat(n.data.link,'" target="_blank">').concat(n.data.name,"</a></p>"),e.find(".status").prepend(r),e.find(".status").show(),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),ei(e)))})}function ti(e){e.preventDefault();var t=!1,n=jQuery('input[name="frm_export_forms[]"]');jQuery('input[name="frm_export_forms[]"]:checked').val()||(n.closest(".frm-table-box").addClass("frm_blank_field"),t="stop");var r=jQuery('input[name="type[]"]');if(jQuery('input[name="type[]"]:checked').val()||"checkbox"!==r.attr("type")||(r.closest("p").addClass("frm_blank_field"),t="stop"),"stop"===t)return!1;e.stopPropagation(),this.submit()}function ni(){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 ri(){null!==jQuery(this).val().match(/\.csv$/i)?jQuery(".show_csv").fadeIn():jQuery(".show_csv").fadeOut()}function oi(){var e=document.querySelector('select[name="format"]');return e?e.value:""}function ii(e){var t,n,r=e.target.value;li(r),ai.call(e.target),t=r,n=document.getElementById("frm-export-select-all"),"csv"===t?(n.checked=!1,n.disabled=!0):n.disabled=!1}function ai(){var e=jQuery(this),t=e.find(":selected"),n=t.data("support"),r=n.indexOf("|");jQuery('input[name="type[]"]').each(function(){this.checked=!1,n.includes(this.value)?(this.disabled=!1,-1===r&&(this.checked=!0)):this.disabled=!0}),"csv"===e.val()?(jQuery(".csv_opts").show(),jQuery(".xml_opts").hide()):(jQuery(".csv_opts").hide(),jQuery(".xml_opts").show());var o=t.data("count"),i=jQuery('input[name="frm_export_forms[]"]');"single"===o?(i.prop("multiple",!1),i.prop("checked",!1)):(i.prop("multiple",!0),i.prop("disabled",!1)),e.trigger("change")}function li(e){if(""!==e){var t=document.querySelectorAll(".frm-is-repeater");t.length&&("csv"===e?t.forEach(function(e){e.classList.remove("frm_hidden")}):t.forEach(function(e){e.classList.add("frm_hidden")}),Qi.call(document.querySelector(".frm-auto-search")))}}function si(){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 ci(){jQuery(".frm_multiselect").hide().each(frmDom.bootstrap.multiselect.init)}function di(e){e.preventDefault(),mi(this,"frm_multiple_addons")}function ui(e){e.preventDefault(),mi(this,"frm_activate_addon")}function fi(e){e.preventDefault(),mi(this,"frm_install_addon")}function mi(e,t){n(1105).toggleAddonState(e,t)}function _i(){gi()}function pi(e){!function(e,t,n){var r=jQuery("#frm_leave_email_error");r.removeClass("frm_hidden").attr("frm-error",n),jQuery("#frm_leave_email").one("keyup",function(){r.addClass("frm_hidden")})}(0,0,e)}function gi(){var e=document.getElementById("frmapi-email-form");jQuery.ajax({dataType:"json",url:e.getAttribute("data-url"),success:function(t){var n=t.renderedHtml;n=n.replace(/<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi,""),e.innerHTML=n}})}function yi(e){frmDom.autocomplete.initSelectionAutocomplete(e)}function vi(e){var t=this.parentNode.parentNode,n=t.elements.type.value;e.preventDefault(),this.classList.add("frm_loading_button"),bi(t,n,this)}function hi(e){var t=this.elements.type.value,n=this.querySelector("button");e.preventDefault(),n.classList.add("frm_loading_button"),bi(this,t,n)}function bi(e,t,n){var r=function(e){var t,n,r={},o=e.elements;for(n=0;n<o.length;n++){var i=o[n],a=i.name,l=i.value,s=a.match(/(.*)\[(.*)\]/);("radio"!==i.type&&"checkbox"!==i.type||i.checked)&&(null===s?Reflect.has(r,a)?(Array.isArray(r[a])||(r[a]=[r[a]]),r[a].push(l)):r[a]=l:(a=s[1],t=s[2],Reflect.has(r,a)||(r[a]={}),r[a][t]=l))}return r}(e),o=r.template_name,i=r.template_desc,a=e.elements.link.value,l={action:t,xml:a,name:o,desc:i,form:JSON.stringify(r),nonce:frmGlobal.nonce},s={formData:r};Ai(l=wp.hooks.applyFilters("frm_before_install_new_form",l,s),function(t){if(void 0!==t.redirect){var r=t.redirect;if(void 0===e.elements.redirect)window.location=r;else{var o=document.getElementById("frm-redirect-link");void 0!==a&&null!==o&&(o.setAttribute("href",r),o.classList.remove("frm_grey","disabled"),(i=e.parentNode.parentNode).classList.add("frm_grey"),i.nextElementSibling.classList.remove("frm_grey"),n.classList.add("frm_grey","disabled"))}}else jQuery(".spinner").css("visibility","hidden"),"string"==typeof t.message&&function(e){var t=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;n.classList.remove("frm_loading_button")})}function ji(e){var t=document.getElementById("frm_captcha_threshold_container");t&&t.classList.toggle("frm_hidden","v3"!==e.target.value)}function wi(e){var t=this.getAttribute("data-id");e.preventDefault(),Ai({action:"frm_forms_trash",id:t,nonce:frmGlobal.nonce},function(){var e=document.getElementById("frm-template-custom-".concat(t));Si(e,function(){e.remove()})})}function Qi(){var e,t,n=!1,r=this.value.toLowerCase(),o=this.getAttribute("data-tosearch"),i=document.getElementsByClassName(o);if("SELECT"===this.tagName&&(r=function(e){for(var t,n=[],r=null==e?void 0:e.options,o=0,i=null==r?void 0:r.length;o<i;o++)(t=r[o]).selected&&n.push(t.value);return n}(this),r=r.join("|").toLowerCase(),n=!0),"frm-action"===o&&""!==r){var a=document.getElementById("frm_email_addon_menu").classList;a.remove("frm-all-actions"),a.add("frm-limited-actions")}for(e=0;e<i.length;e++){var l=i[e].innerText.toLowerCase(),s=!("xml"===oi()&&i[e].classList.contains("frm-is-repeater"));""===r?(s&&Mo(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.remove("frm-search-result")):n&&new RegExp(r).test(l)||l.includes(r)||xi(l,r)?(s&&Mo(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.add("frm-search-result")):(i[e].classList.add("frm_hidden"),i[e].classList.remove("frm-search-result"))}(t=document.querySelector("#frm-insert-fields"))&&t.querySelectorAll(":scope > .frm-with-line").forEach(function(e){var t=e.nextElementSibling;if(t){var n=t.querySelectorAll(":scope > li.frmbutton"),r=Array.from(n).every(function(e){return e.classList.contains("frm_hidden")});e.classList.toggle("frm_hidden",r)}}),jQuery(this).trigger("frmAfterSearch")}function xi(e,t){return"s"!==t&&"s"!==e[e.length-1]&&"".concat(e,"s").includes(t)}function Ei(e){e.stopPropagation()}function ki(e,t){var n=document.createEvent("HTMLEvents");n.initEvent(t,!1,!0),e.dispatchEvent(n)}function Ai(e,t){var n,r=new XMLHttpRequest,o="string"==typeof e?e:Object.keys(e).map(function(t){return"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(e[t]))}).join("&");return r.open("post",ajaxurl,!0),r.onreadystatechange=function(){if(r.readyState>3&&200==r.status){n=r.responseText;try{n=JSON.parse(n)}catch(e){}t(n)}},r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.setRequestHeader("Content-type","application/x-www-form-urlencoded"),r.send(o),r}function Si(e,t){e.classList.add("frm-fade"),setTimeout(t,1e3)}function Li(e){jQuery(e).css("visibility","hidden")}function Ii(e){jQuery(e).css("visibility","visible")}function Bi(e,t){return n(4260).initModal(e,t)}function qi(e,t){if("#"===t){var n=document.getElementById(e),r=n.style.display;n.style.display="none"===r?"block":"none"}else e.is(":visible")?e.hide():e.show()}function Ci(){window.onbeforeunload=null;var e=jQuery(window);e.off("beforeunload.widgets"),e.off("beforeunload.edit-post")}function Ni(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));if(null!==t&&"form"===t.dataset.type)if(t=jQuery(t),this.options[this.selectedIndex].value){t.find(".frm-not-set")[0].classList.add("frm_hidden");var n=t.find(".frm-embed-message");n.html(n.data("embedmsg")+this.options[this.selectedIndex].text),t.find(".frm-embed-field-placeholder")[0].classList.remove("frm_hidden")}else t.find(".frm-not-set")[0].classList.remove("frm_hidden"),t.find(".frm-embed-field-placeholder")[0].classList.add("frm_hidden")}function Ti(){var e=jQuery(this).closest(".frm-single-settings"),t=e.find(".frmjs_product_choices"),n=e.find(".frm_prod_options_heading"),r=this.options[this.selectedIndex].value;t.removeClass("frm_prod_type_single frm_prod_type_user_def"),n.removeClass("frm_prod_user_def"),"single"===r?t.addClass("frm_prod_type_single"):"user_def"===r&&(t.addClass("frm_prod_type_user_def"),n.addClass("frm_prod_user_def"))}function Oi(e){var t=document.getElementById("frm_field_id_".concat(e));return null!==t&&"product"===t.getAttribute("data-type")}function Fi(){var e=function(e,t){return window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]},t=function(e,t,n){window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]=n},n=[1,2,3,4,5,6,7,8,9,10,11,12].map(function(e){return"frm".concat(e)}),o=["first","middle","last"];document.addEventListener("change",function(i){i.target.matches(".frm_name_layout_dropdown")&&function(i){var a,l=i.target.value.split("_"),s=i.target.dataset.fieldId,c=document.querySelector("#field_".concat(s,"_inner_container .frm_combo_inputs_container")),d=(a=l.length,"frm".concat(parseInt(12/a)));o.forEach(function(e){var o,i=c.querySelector('[data-sub-field-name="'.concat(e,'"]'));i&&(i.classList.add("frm_hidden"),(o=i.classList).remove.apply(o,r(n)),t(s,e,i))}),l.forEach(function(t){var n=e(s,t);n&&(n.classList.remove("frm_hidden"),n.classList.add(d),c.append(n))}),o.forEach(function(e){var n=document.querySelector(".frm_sub_field_options-".concat(e,'[data-field-id="').concat(s,'"]'));n&&(n.classList.add("frm_hidden"),t(s,"".concat(e,"_options"),n))}),l.forEach(function(t){var n=e(s,"".concat(t,"_options"));n&&n.classList.remove("frm_hidden")})}(i)},!1)}function Di(e,t){var n,r,o,i=!1,a=!1;(n=t.newOption?(new DOMParser).parseFromString(t.newOption,"text/html").body.childNodes[0]:t).querySelectorAll("svg").forEach(function(e){(r=e.getElementsByTagNameNS("http://www.w3.org/2000/svg","use")[0])&&("#frm_drag_icon"===(o=qo(r))&&(i=!0),"#frm_save_icon"===o&&(a=!0))}),i||n.prepend(h.drag.cloneNode(!0)),n.querySelector("[id^=field_key_".concat(e,"-]"))&&!a&&n.querySelector("[id^=field_key_".concat(e,"-]")).after(h.save.cloneNode(!0)),t.newOption&&(t.newOption=n)}function Mi(){var e=document.getElementById("frm_leave_email").value.trim();if(""!==e)if(!1!==/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i.test(e)){var t=jQuery("#frmapi-email-form").find("form"),n=t.find('[type="email"]').not(".frm_verify");if(n.length){if(document.getElementById("frm_empty_inbox")){document.getElementById("frm-add-my-email-address").remove();var r=document.getElementById("frm_leave_email_wrapper");if(r){r.classList.add("frm_hidden");var o=d({className:"frm-wait frm_spinner"});o.style.visibility="visible",o.style.float="none",o.style.width="unset",r.parentElement.insertBefore(o,r.nextElementSibling)}}n.val(e),jQuery.ajax({type:"POST",url:t.attr("action"),data:"".concat(t.serialize(),"&action=frm_forms_preview")}).done(function(e){if(jQuery(e).find(".frm_message").text().trim().includes("Thanks!")){var t=document.getElementById("frmapi-email-form").parentElement.querySelector(".frm_spinner");t&&t.remove(),wp.hooks.applyFilters("frm_thank_you_on_signup",!0)&&document.getElementById("frm_leave_email_wrapper").replaceWith(d(I("Thank you for signing up!","formidable")))}else pi("invalid")})}}else pi("invalid");else pi("empty")}function Pi(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 n=document.getElementById("frm_adv_info");n&&(n.dataset.fills===e.target.id&&void 0!==e.target.id||e.target.closest("#frm_adv_info")||"none"===n.style.display||$o(n))}}return{init:function(){var e,t,o,i,a,l,s;!function(){jQuery(document).on("click","#frm-add-my-email-address",function(e){e.preventDefault(),Mi()});var e=document.getElementById("frm_empty_inbox"),t=document.getElementById("frm_leave_email");if(e&&t){var n=document.getElementById("frm-leave-email-modal");n.classList.remove("frm_hidden"),n.querySelector(".frm_modal_footer").classList.add("frm_hidden"),t.addEventListener("keyup",function(e){if("Enter"===e.key){var t=document.getElementById("frm-add-my-email-address");t&&t.click()}})}}(),t=document.querySelector(".frm-admin-footer-links"),o=null!==(e=document.querySelector(".frm_page_container"))&&void 0!==e?e:document.getElementById("wpbody-content"),t&&o&&(o.append(t),t.classList.remove("frm_hidden")),document.addEventListener("show.bs.dropdown",function(){z()}),C={},jQuery(".wp-admin").on("click",function(e){var t=jQuery(e.target),n=jQuery(".dropdown.open");!n.length||t.hasClass("dropdown")||t.closest(".dropdown").length||n.removeClass("open")}),jQuery("#frm_bs_dropdown:not(.open) a").on("click",At),void 0===E&&(E=jQuery(document.getElementById("form_id")).val()),document.querySelectorAll(".frm-warning-dismiss").forEach(function(e){_(e,St)}),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 n=e.querySelector("legend");n.parentNode.insertBefore(t,n.nextElementSibling);var r=Array.from(e.querySelectorAll('input[type="checkbox"]')),o=function(){r.reduce(function(e,t){return t.checked?e+1:e},0)>=10?(t.classList.remove("frm_hidden"),r.forEach(function(e){e.checked||(e.parentNode.classList.add("frm_noallow"),e.disabled=!0)})):t.classList.add("frm_hidden")};o(),r.forEach(function(e){e.addEventListener("change",function(e){e.target.checked?o():(t.classList.add("frm_hidden"),r.forEach(function(e){e.parentNode.classList.remove("frm_noallow"),e.disabled=!1}))})})}}}(),yi(),jQuery("[data-frmprint]").on("click",function(){return window.print(),!1})),jQuery(document).on("change","select[data-toggleclass], input[data-toggleclass]",xo),function(){function e(e){var t=e.options[e.selectedIndex];e.querySelectorAll("option[data-dependency]:not([data-dependency-skip])").forEach(function(e){var n=document.querySelector(e.dataset.dependency);null==n||n.classList.toggle("frm_hidden",t!==e)})}document.querySelectorAll("select.frm_select_with_dependency").forEach(e),frmDom.util.documentOn("change","select.frm_select_with_dependency",function(t){return e(t.target)})}(),(jQuery(document.getElementById("frm_adv_info")).length>0||jQuery(".frm_field_list").length>0)&&frmAdminBuild.panelInit(),i=jQuery(".wrap, .frm_wrap"),a=document.getElementById("frm_confirm_modal"),l=!1,s=!1,jQuery(a).on("click","[data-deletefield]",xn),jQuery(a).on("click","[data-removeid]",R),jQuery(a).on("click","[data-trashtemplate]",wi),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",G),i.on("mouseenter.frm",".frm_bstooltip, .frm_help",function(){jQuery(this).off("mouseenter.frm"),function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=e;(n.hasAttribute("data-toggle")||n.hasAttribute("data-bs-toggle"))&&(n.parentElement.setAttribute("title",n.getAttribute("title")),n.removeAttribute("title"),n.classList.remove("frm_bstooltip"),n.parentElement.classList.add("frm_bstooltip"),n=n.parentElement),jQuery(n).tooltip(),t&&(z(),jQuery(n).tooltip("show"))}(this,!0)}),jQuery(document).on("click","#doaction, #doaction2",function(e){var t="doaction"===this.id?"top":"bottom",n=document.getElementById("bulk-action-selector-".concat(t)),r=document.getElementById("confirm-bulk-delete-".concat(t));if(null!==n&&null!==r){if(l=this,!s&&"bulk_delete"===n.value)return e.preventDefault(),D(r),!1}else l=!1}),jQuery(document).on("click","#frm-confirmed-click",function(e){if(!1!==l&&!e.target.classList.contains("frm-btn-inactive"))return"confirm-bulk-delete"===this.getAttribute("href")?(e.preventDefault(),s=!0,l.click(),!1):void 0}),n(4260).initUpgradeModal(),frmDom.util.documentOn("click","[data-modal-title]",Kr);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",U),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&&Jr(this),W(this),!1}),W(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),zr(document.getElementById("posts-filter")),!1}),jQuery(".frm_select_box").on("click focus",function(){this.select()}),jQuery(document).on("input search change",".frm-auto-search:not(#frm-form-templates-page #template-search-input)",Qi),jQuery(document).on("focusin click",".frm-auto-search",Ei);var u=jQuery(".frm-auto-search");""!==u.val()&&u.trigger("keyup"),FrmFormsConnect.init(),jQuery(document).on("click",".frm-install-addon",fi),jQuery(document).on("click",".frm-activate-addon",ui),jQuery(document).on("click",".frm-solution-multiple",di),jQuery("button, input[type=submit]").on("click",Ci),document.addEventListener("click",function(e){if("LABEL"===e.target.nodeName){var t=e.target.getAttribute("for");if(t){var n=document.getElementById(t);if(n&&n.nextElementSibling){var r=n.nextElementSibling.querySelector("button.dropdown-toggle.multiselect");r&&setTimeout(function(){return r.click()},0)}}}}),frmAdminBuild.hooks.addFilter("frm_before_embed_modal",function(e,t){var n,r,o=t.element;if("form"!==t.type)return e;var i=o.closest("tr");if(i)n=parseInt(i.querySelector(".column-id").textContent),r=i.querySelector(".column-form_key").textContent;else{n=document.getElementById("form_id").value;var a=document.getElementById("frm_form_key");if(a)r=a.value;else{var l=document.getElementById("frm-previewDrop");l&&(r=l.nextElementSibling.querySelector(".dropdown-item a").getAttribute("href").split("form=")[1])}}return[n,r]}),document.querySelectorAll("#frm-show-fields > li, .frm_grid_container li").forEach(function(e,t){e.addEventListener("click",function(){var e,t,n;t=(null===(e=this.querySelector("li"))||void 0===e?void 0:e.dataset.fid)||this.dataset.fid,(n=document.querySelectorAll("[id^=frm_delete_field_".concat(t,"-]"))).length<2||r(n).slice(1).forEach(function(e,n){e.classList.contains("frm_other_option")||Di(t,e)})})});var f=document.getElementById("frm_small_screen_proceed_button");f&&_(f,function(){var e;null===(e=document.getElementById("frm_small_device_message_container"))||void 0===e||e.remove(),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)",Pi),g=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return frmDom.util.debounce(e,t)}(oe,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(X),jQuery("ul.field_type_list, .field_type_list li, ul.frm_code_list, .frm_code_list li, .frm_code_list li a, #frm_adv_info #category-tabs li, #frm_adv_info #category-tabs li a").disableSelection(),jQuery(".frm_submit_ajax").on("click",Hr),jQuery(".frm_submit_no_ajax").on("click",Gr),Wr(),jQuery("a.edit-form-status").on("click",Sr),jQuery(".cancel-form-status").on("click",Lr),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")}),ci(),Dn();var e,t=jQuery(j),n=document.getElementById("frm_form_editor_container");t.on("click",".frm_add_logic_row",Sn),t.on("click",".frm_add_watch_lookup_row",In),t.on("change",".frm_get_values_form",On),t.on("change",".frm_logic_field_opts",wr),t.on("frm-multiselect-changed",'select[name^="field_options[admin_only_"]',Ir),jQuery(document.getElementById("frm-insert-fields")).on("click",".frm_add_field",Ae),b.on("click",".frm_clone_field",Be),t.on("blur",'input[id^="frm_calc"]',Je),t.on("change","input.frm_format_opt, input.frm_max_length_opt",lt),t.on("change click","[data-changeme]",it),t.on("click","input.frm_req_field",st),t.on("click",".frm_mark_unique",dt),t.on("change",".frm_repeat_format",Xn),t.on("change",".frm_repeat_limit",Yn),t.on("change",".frm_js_checkbox_limit",Zn),t.on("input",'input[name^="field_options[add_label_"]',function(){er(this,"add")}),t.on("input",'input[name^="field_options[remove_label_"]',function(){er(this,"remove")}),t.on("change",'select[name^="field_options[data_type_"]',Fn),jQuery(n).on("click",".frm-collapse-page",Mn),jQuery(n).on("click",".frm-collapse-section",zn),t.on("click",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",Rn),t.on("keydown",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),Rn.call(this,e))}),jQuery(n).on("show.bs.dropdown hide.bs.dropdown",He),t.on("click",".frm_toggle_sep_values",yt),t.on("click",".frm_toggle_image_options",vt),t.on("click",".frm_remove_image_option",Et),t.on("click",".frm_choose_image_box",xt),t.on("change",".frm_hide_image_text",Qt),t.on("change",".frm_field_options_image_size",jt),t.on("click",".frm_multiselect_opt",kt),b.on("mousedown","input, textarea, select",Lt),b.on("click","input[type=radio], input[type=checkbox]",Lt),b.on("click",".frm_delete_field",Nt),b.on("click",".frm_select_field",Tt),jQuery(document).on("click",".frm_delete_field_group",Ot),jQuery(document).on("click",".frm_clone_field_group",Ft),jQuery(document).on("click","#frm_field_group_controls > span:first-child",Dt),jQuery(document).on("click",".frm-row-layout-option",Yt),jQuery(document).on("click",".frm-merge-fields-into-row .frm-row-layout-option",Zt),jQuery(document).on("click",".frm-custom-field-group-layout",tn),jQuery(document).on("click",".frm-merge-fields-into-row .frm-custom-field-group-layout",rn),jQuery(document).on("click",".frm-break-field-group",cn),b.on("click","#frm_field_group_popup .frm_grid_container input",dn),jQuery(document).on("click",".frm-cancel-custom-field-group-layout",un),jQuery(document).on("click",".frm-save-custom-field-group-layout",mn),b.on("click","ul.frm_sorting",_n),jQuery(document).on("click",".frm-merge-fields-into-row",jn),jQuery(document).on("click",".frm-delete-field-groups",Qn),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",Te)}),b.on("mousemove","ul.frm_sorting",Oe),b.on("show.bs.dropdown",".frm-field-action-icons",Me),jQuery(document).on("show.bs.dropdown","#frm_field_group_controls",Pe),t.on("click",".frm_single_option a[data-removeid]",It),t.on("mousedown",".frm_single_option input[type=radio]",Bt),t.on("focusin",".frm_single_option input[type=text]",qt),t.on("click",".frm_add_opt",_t),t.on("change",".frm_single_option input",nr),t.on("change",".frm_image_id",nr),t.on("change",".frm_toggle_mult_sel",pt),b.on("click",".frm_primary_label",Un),b.on("click",".frm_description",Wn),b.on("click","li.ui-state-default:not(.frm_noallow)",$n),b.on("dblclick","li.ui-state-default",Jn),t.on("change",".frm_tax_form_select",tr),t.on("change","select.conf_field",ut),t.on("change",".frm_get_field_selection",Qr),t.on("click",".frm-show-inline-modal",Cr),t.on("keydown",".frm-show-inline-modal",function(e){var t=e.key;"Enter"!==t&&" "!==t||(e.preventDefault(),Cr.call(this,e))}),t.on("click",".frm-inline-modal .dismiss",Nr),jQuery(document).on("change","[data-frmchange]",Or),document.addEventListener("click",Tr),t.on("change",".frm_include_extras_field",et),t.on("change",'select[name^="field_options[form_select_"]',Ni),jQuery(document).on("submit","#frm_js_build_form",Ho),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",Po),rt(),jQuery(document).on("change",".frmjs_prod_data_type_opt",Ti),jQuery(document).on("focus",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',qn),jQuery(document).on("blur",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',Nn),frmDom.util.documentOn("click",".frm-show-field-settings",$n),frmDom.util.documentOn("change","select.frm_format_dropdown, select.frm_phone_type_dropdown",Kn),t.on("keydown",'.frm_single_option input[name^="field_options["], .frm_single_option input[name^="rows_"]',function(e){"Enter"===e.key&&function(e){var t=e.closest(".frm_single_option").parentElement.querySelectorAll('.frm_single_option input[name^="field_options[" ], .frm_single_option input[name^="rows_"]'),n=Array.from(t),r=n.indexOf(e);if(!(r<0)){var o=n.slice(r+1).find(function(e){return null!==e.offsetParent});if(o){o.focus();var i=o.value.length;o.setSelectionRange(i,i)}}}(e.currentTarget)}),!1!==(e=Bi("#frm-bulk-modal","700px"))&&(jQuery(".frm-insert-preset").on("click",mt),jQuery(j).on("click","a.frm-bulk-edit-link",function(t){t.preventDefault();var n="",r=jQuery(this).closest("[data-fid]").data("fid"),o=yr(r),i=Oi(r),a=document.getElementById("frm_field_".concat(r,"_opts"));if(a){var l=a.getElementsByTagName("li");document.getElementById("bulk-field-id").value=r;for(var s=0;s<l.length;s++){var c=l[s].getAttribute("data-optkey");if("000"!==c){var d=document.getElementsByName("field_options[options_".concat(r,"][").concat(c,"][label]"))[0];void 0!==d&&(n+=d.value,o&&(n+="|".concat(document.getElementsByName("field_options[options_".concat(r,"][").concat(c,"][value]"))[0].value)),i&&(n+="|".concat(document.getElementsByName("field_options[options_".concat(r,"][").concat(c,"][price]"))[0].value)),n+="\r\n")}s>=l.length-1&&(document.getElementById("frm_bulk_options").value=n)}return e.dialog("open"),!1}}),jQuery("#frm-update-bulk-opts").on("click",function(){var t=document.getElementById("bulk-field-id").value;document.getElementById("bulk-option-type").value||(this.classList.add("frm_loading_button"),frmAdminBuild.updateOpts(t,document.getElementById("frm_bulk_options").value,e),Po())})),qr(),document.addEventListener("frm_added_field",qr),Ie(),Fi(),kr(),frmDom.util.documentOn("change",".frm_show_password_setting_input",function(e){var t=e.target.getAttribute("data-fid"),n=document.getElementById("frm_field_id_".concat(t));n&&n.classList.toggle("frm_disabled_show_password",!e.target.checked)}),document.addEventListener("scroll",Fo,!0),document.addEventListener("change",To),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(Gn)},9999)},settingsInit:function(){var e=jQuery(document.getElementById("frm_notification_settings"));e.on("click",".frm_email_buttons",io),e.on("click",".frm_remove_field",ao),e.on("change",".frm_to_row, .frm_from_row",lo),e.on("change",".frm_tax_selector",wo),e.on("change","select.frm_single_post_field",_o),e.on("change","select.frm_toggle_post_content",po),e.on("change","select.frm_dyncontent_opt",go),e.on("change",".frm_post_type",yo),e.on("click",".frm_add_postmeta_row",bo),e.on("click",".frm_add_posttax_row",ho),e.on("click",".frm_toggle_cf_opts",Qo),e.on("click",".frm_duplicate_form_action",Zr),jQuery(".frm_actions_list").on("click",".frm_active_action",to),jQuery("#frm-show-groups, #frm-hide-groups").on("click",no),ci(),jQuery("ul.frm_actions_list li").each(function(){so(jQuery(this).children("a").data("actiontype"));var e=jQuery(this).find("i");"none"!==e.css("background-image")&&e.addClass("frm-inverse")}),jQuery(".frm_submit_settings_btn").on("click",Eo),Wr();var t=jQuery(".frm_form_settings");t.on("click",".frm_add_form_logic",mo),t.on("click",".frm_already_used",fo),document.addEventListener("click",function(e){var t=e.target;t.closest(".frm_image_preview_wrapper")&&(t.closest(".frm_choose_image_box")?xt.bind(t)(e):t.closest(".frm_remove_image_option")&&Et.bind(t)(e))}),t.on("mouseup","*:not(.frm-show-box)",Pi),jQuery(document.getElementById("no_save")).on("change",function(){this.checked&&!0!==confirm(i.no_save_warning)&&jQuery(this).attr("checked",!1)}),jQuery('select[name="options[edit_action]"]').on("change",Yr);var n=document.getElementById("logged_in");jQuery(n).on("change",function(){this.checked?Ii(".hide_logged_in"):Li(".hide_logged_in")});var r=jQuery(document.getElementById("frm_cookie_expiration"));jQuery(document.getElementById("frm_single_entry_type")).on("change",function(){"cookie"===this.value?r.fadeIn("slow"):r.fadeOut("slow")});var o=document.getElementById("single_entry");jQuery(o).on("change",function(){this.checked?Ii(".hide_single_entry"):Li(".hide_single_entry"),this.checked&&"cookie"===jQuery(document.getElementById("frm_single_entry_type")).val()?r.fadeIn("slow"):r.fadeOut("slow")}),jQuery(".hide_save_draft").hide();var a=jQuery(document.getElementById("save_draft"));a.on("change",function(){this.checked?jQuery(".hide_save_draft").fadeIn("slow"):jQuery(".hide_save_draft").fadeOut("slow")}),Rr(a);var l=document.getElementById("editable");jQuery(l).on("change",function(){this.checked?(jQuery(".hide_editable").fadeIn("slow"),Rr(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",Ir),jQuery(document).on("submit",".frm_form_settings",zo),jQuery(document).on("change","#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea",Po),yi(),jQuery(document).on("frm-action-loaded",Jo),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",Ro)},panelInit:function(){jQuery(".frm_wrap, #postbox-container-1").on("click",".frm_insert_code",ko),jQuery(document).on("change",".frm_insert_val",function(){Ao(jQuery(this).data("target"),jQuery(this).val()),jQuery(this).val("")}),jQuery(document).on("click change",'[name="frm-id-key-condition"]',Io),jQuery(document).on("keyup change",".frm-build-logic",Bo),Xr(),jQuery(document).on("frmElementAdded",function(e,t){Xr(t)}),jQuery(document).on("mousedown",".frm-show-box",No);var e=document.getElementById("form_settings_page"),t=document.body.classList.contains("post-type-frm_display"),n=document.getElementById("frm_insert_fields_tab");(null!==e||t||O)&&jQuery(document).on("focusin","form input, form textarea",function(r){var o,i,a;if(r.stopPropagation(),Co(this),jQuery(this).is(":not(:submit, input[type=button], .frm-search-input, input[type=checkbox])")){if(jQuery(r.target).closest("#frm_adv_info").length)return;if(null!==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=""),n.click(),o.hide(),o.siblings().show());else if(t){var l=new CustomEvent("frm_legacy_views_handle_field_focus");l.frmData={idAttrValue:this.id},document.dispatchEvent(l)}}}),jQuery(".frm_wrap, #postbox-container-1").on("mousedown","#frm_adv_info a, .frm_field_list a",function(e){e.preventDefault()});var r=jQuery("#frm_adv_info");r.on("click",".subsubsub a.frmids",function(e){Ko("frmids",e)}),r.on("click",".subsubsub a.frmkeys",function(e){Ko("frmkeys",e)})},inboxInit:function(){var e;jQuery(".frm_inbox_dismiss").on("click",function(e){var t=this.parentNode.parentNode,n=t.getAttribute("data-message"),r=this.getAttribute("href"),o=t.cloneNode(!0),i=document.querySelector(".frm-dismissed-inbox-messages");if("free_templates"!==n||this.classList.contains("frm_inbox_dismiss")){e.preventDefault();var a={action:"frm_inbox_dismiss",key:n,nonce:frmGlobal.nonce},l="frm_inbox_slide_in"===t.id;l&&(t.classList.remove("s11-fadein"),t.classList.add("s11-fadeout"),t.addEventListener("animationend",function(){return t.remove()},{once:!0})),Ai(a,function(){if(!l)return"#"!==r?(window.location=r,!0):void Si(t,function(){var e;null!==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"),_i()),t.remove()})})}}),!1===(null===(e=document.getElementById("frm_empty_inbox"))||void 0===e?void 0:e.classList.contains("frm_hidden"))&&_i()},solutionInit:function(){jQuery(document).on("submit","#frm-new-template",hi)},styleInit:function(){var e=jQuery(".frm_image_preview_wrapper");e.on("click",".frm_choose_image_box",xt),e.on("click",".frm_remove_image_option",Et),wp.hooks.doAction("frm_style_editor_init")},customCSSInit:function(){console.warn("Calling frmAdminBuild.customCSSInit is deprecated.")},globalSettingsInit:function(){jQuery(document).on("click","[data-frmuninstall]",Xo),ci();var e=document.getElementById("licenses_settings");null!==e&&jQuery(e).on("click",".edd_frm_save_license",Yo),jQuery(document).on("click","#frm-new-template button",vi),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",ji),document.querySelector(".frm_captchas").addEventListener("change",function(e){var t,n=null===(t=document.querySelector('.frm_captchas input[checked="checked"]'))||void 0===t?void 0:t.value,r=e.target.value!==n;document.querySelector(".captcha_settings .frm_note_style").classList.toggle("frm_hidden",!r)}),frmDom.util.documentOn("submit",".frm_settings_form",function(){x=0});var n=document.getElementById("manage_styles_settings");n&&n.addEventListener("change",function(e){var t=e.target;"SELECT"===t.nodeName&&t.dataset.name&&!t.getAttribute("name")&&t.setAttribute("name",t.dataset.name)});var r=document.getElementById("payments_settings"),o=null==r?void 0:r.querySelectorAll('[name="frm_payment_section"]');o&&o.forEach(function(e){e.addEventListener("change",function(){if(e.checked){var t=r.querySelector('label[for="'.concat(e.id,'"]'));t&&t.setAttribute("aria-selected","true"),o.forEach(function(t){if(t!==e){var n=r.querySelector('label[for="'.concat(t.id,'"]'));n&&n.setAttribute("aria-selected","false")}})}})})},exportInit:function(){jQuery(".frm_form_importer").on("submit",Zo),jQuery(document.getElementById("frm_export_xml")).on("submit",ti),jQuery("#frm_export_xml input, #frm_export_xml select").on("change",ni),jQuery('input[name="frm_import_file"]').on("change",ri),document.querySelector('select[name="format"]').addEventListener("change",ii),jQuery('input[name="frm_export_forms[]"]').on("click",si),ci(),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()}),li(oi()),document.querySelector("#frm-export-select-all").addEventListener("change",function(e){document.querySelectorAll('[name="frm_export_forms[]"]').forEach(function(t){t.checked=e.target.checked})})},inboxBannerInit:function(){var e=document.getElementById("frm_banner");if(e){var t=e.querySelector(".frm-banner-dismiss");document.addEventListener("click",function(n){n.target===t&&Ai({action:"frm_inbox_dismiss",key:e.dataset.key,nonce:frmGlobal.nonce},function(){jQuery(e).fadeOut(400,function(){e.remove()})})})}},updateOpts:function(e,t,n){var r=yr(e),o=Oi(e)?"frm_bulk_products":"frm_import_options";jQuery.ajax({type:"POST",url:ajaxurl,data:{action:o,field_id:e,opts:t,separate:r,nonce:frmGlobal.nonce},success:function(t){document.getElementById("frm_field_".concat(e,"_opts")).innerHTML=t,wp.hooks.doAction("frm_after_bulk_edit_opts",e),ir(e),void 0!==n&&(n.dialog("close"),document.getElementById("frm-update-bulk-opts").classList.remove("frm_loading_button"))}})},triggerRemoveLogic:function(e,t){jQuery("#frm_logic_".concat(e,"_").concat(t," .frm_remove_tag")).trigger("click")},downloadXML:function(e,t,n){var r="".concat(ajaxurl,"?action=frm_").concat(e,"_xml&ids=").concat(t);null!==n&&(r="".concat(r,"&is_template=").concat(n)),location.href=r},hooks:{applyFilters:function(e){for(var t,n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return(t=wp.hooks).applyFilters.apply(t,[e].concat(r))},addFilter:function(e,t,n){return wp.hooks.addFilter(e,"formidable",t,n)},doAction:function(e){for(var t,n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return(t=wp.hooks).doAction.apply(t,[e].concat(r))},addAction:function(e,t,n){return wp.hooks.addAction(e,"formidable",t,n)}},applyZebraStriping:function(e,t){var n=document.querySelectorAll("".concat(e," tr").concat(t?":not(.".concat(t,")"):""));if(!(n.length<1)){var r=!0;n.forEach(function(e){e.classList.remove("frm-odd","frm-even"),e.classList.add(r?"frm-odd":"frm-even"),r=!r}),document.querySelectorAll(e).forEach(function(e){return e.classList.add("frm-zebra-striping")})}},initModal:Bi,infoModal:M,offsetModalY:Uo,adjustConditionalLogicOptionOrders:lr,addRadioCheckboxOpt:cr,installNewForm:bi,toggleAddonState:mi,purifyHtml:_r,loadApiEmailForm:gi,addMyEmailAddress:Mi,fillDropdownOpts:dr,showSaveAndReloadModal:Oo,clearSettingsBox:$e,deleteField:kn,insertFormField:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(n){var r=E,o=0;"summary"===e&&(o=b.children('li[data-type="break"]').length>0?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:Object.assign(_e(e,0,r,o),{field_options:t}),success:function(t){n(t),setTimeout(function(){Er(),We(t,!0);var n=ye(t);n&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:n,fieldType:e,form_id:r})},10)},error:he})})},confirmLinkClick:D,handleInsertFieldByDraggingResponse:ge,handleAddFieldClickResponse:Le,syncLayoutClasses:ae,moveFieldSettings:oo,maybeCollapseSettings:Rn}},window.frmAdminBuild=frmAdminBuildJS(),jQuery(document).ready(function(){var e;frmAdminBuild.init(),document.querySelectorAll(".frm-dropdown-menu").forEach(function(e){e.classList.add("dropdown-menu");var t,n,r=e.querySelector(".frm-dropdown-toggle");r&&(r.hasAttribute("role")||r.setAttribute("role","button"),r.hasAttribute("tabindex")||r.setAttribute("tabindex",0)),"UL"===e.tagName&&(n=(n=(n=(n=(n=(n=(t=e).outerHTML).replace("<ul ","<div ")).replace("</ul>","</div>")).replaceAll("<li>",'<div class="dropdown-item">')).replaceAll('<li class="','<div class="dropdown-item ')).replaceAll("</li>","</div>"),t.outerHTML=n)}),null===(e=document.querySelector(".preview.dropdown .frm-dropdown-toggle"))||void 0===e||e.setAttribute("data-bs-toggle","dropdown"),document.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))})}),window.frm_show_div=function(e,t,n,r){t==n?jQuery(r+e).fadeIn("slow").css("visibility","visible"):jQuery(r+e).fadeOut("slow")},window.frmCheckAll=function(e,t){jQuery('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmCheckAllLevel=function(e,t,n){jQuery(".frm_catlevel_".concat(n)).children(".frm_checkbox").children("label").children('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmGetFieldValues=function(e,t,n,r,o,i){e&&jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_get_field_values&current_field=".concat(t,"&field_id=").concat(e,"&name=").concat(o,"&t=").concat(r,"&form_action=").concat(jQuery('input[name="frm_action"]').val(),"&nonce=").concat(frmGlobal.nonce),success:function(e){document.getElementById("frm_show_selected_values_".concat(t,"_").concat(n)).innerHTML=e,"function"==typeof i&&i()}})},window.frmImportCsv=function(e){var t="";"undefined"!=typeof __FRMURLVARS&&(t=__FRMURLVARS),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_import_csv&nonce=".concat(frmGlobal.nonce,"&frm_skip_cookie=1").concat(t),success:function(t){var n=jQuery(".frm_admin_progress_bar").attr("aria-valuemax"),r=n-t,o=r/n*100;jQuery(".frm_admin_progress_bar").css("width","".concat(o,"%")).attr("aria-valuenow",r),parseInt(t,10)>0?(jQuery(".frm_csv_remaining").html(t),frmImportCsv(e)):(jQuery(document.getElementById("frm_import_message")).html(frm_admin_js.import_complete),setTimeout(function(){location.href="?page=formidable-entries&frm_action=list&form=".concat(e,"&import-message=1")},2e3))}})}})();
1 +/* exported frm_add_logic_row, frm_remove_tag, frm_show_div, frmCheckAll, frmCheckAllLevel */
2 +
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 */
319 +
320 + var $newFields = jQuery( document.getElementById( 'frm-show-fields' ) ),
321 + builderForm = document.getElementById( 'new_fields' ),
322 + thisForm = document.getElementById( 'form_id' ),
323 + cancelSort = false,
324 + copyHelper = false,
325 + fieldsUpdated = 0,
326 + thisFormId = 0,
327 + autoId = 0,
328 + optionMap = {},
329 + lastNewActionIdReturned = 0,
330 + __ = wp.i18n.__;
331 +
332 + if ( thisForm !== null ) {
333 + thisFormId = thisForm.value;
334 + }
335 +
336 + // Global settings
337 + var s;
338 +
339 + function showElement( element ) {
340 + element[0].style.display = '';
341 + }
342 +
343 + function hideElement( element ) {
344 + element[0].style.display = 'none';
345 + }
346 +
347 + function empty( $obj ) {
348 + if ( $obj !== null ) {
349 + while ( $obj.firstChild ) {
350 + $obj.removeChild( $obj.firstChild );
351 + }
352 + }
353 + }
354 +
355 + function addClass( $obj, className ) {
356 + if ( $obj.classList ) {
357 + $obj.classList.add( className );
358 + } else {
359 + $obj.className += ' ' + className;
360 + }
361 + }
362 +
363 + function confirmClick( e ) {
364 + /*jshint validthis:true */
365 + e.stopPropagation();
366 + e.preventDefault();
367 + confirmLinkClick( this );
368 + }
369 +
370 + function confirmLinkClick( link ) {
371 + var message = link.getAttribute( 'data-frmverify' );
372 +
373 + if ( message === null || link.id === 'frm-confirmed-click' ) {
374 + return true;
375 + } else {
376 + return confirmModal( link );
377 + }
378 + }
379 +
380 + function confirmModal( link ) {
381 + var caution, verify, $confirmMessage, frmCaution, i, dataAtts,
382 + $info = initModal( '#frm_confirm_modal', '400px' ),
383 + continueButton = document.getElementById( 'frm-confirmed-click' );
384 +
385 + if ( $info === false ) {
386 + return false;
387 + }
388 +
389 + caution = link.getAttribute( 'data-frmcaution' );
390 + verify = link.getAttribute( 'data-frmverify' );
391 + $confirmMessage = jQuery( '.frm-confirm-msg' );
392 + $confirmMessage.empty();
393 +
394 + if ( caution ) {
395 + frmCaution = document.createElement( 'div' );
396 + frmCaution.classList.add( 'frm-caution' );
397 + frmCaution.appendChild( document.createTextNode( caution ) );
398 + $confirmMessage.append( frmCaution );
399 + }
400 +
401 + if ( verify ) {
402 + $confirmMessage.append( document.createTextNode( verify ) );
403 + }
404 +
405 + removeAtts = continueButton.dataset;
406 + for ( i in dataAtts ) {
407 + continueButton.removeAttribute( 'data-' + i );
408 + }
409 +
410 + dataAtts = link.dataset;
411 + for ( i in dataAtts ) {
412 + if ( i !== 'frmverify' ) {
413 + continueButton.setAttribute( 'data-' + i, dataAtts[i]);
414 + }
415 + }
416 +
417 + $info.dialog( 'open' );
418 + continueButton.setAttribute( 'href', link.getAttribute( 'href' ) );
419 + return false;
420 + }
421 +
422 + function infoModal( msg ) {
423 + var $info = initModal( '#frm_info_modal', '400px' );
424 +
425 + if ( $info === false ) {
426 + return false;
427 + }
428 +
429 + jQuery( '.frm-info-msg' ).html( msg );
430 +
431 + $info.dialog( 'open' );
432 + return false;
433 + }
434 +
435 + function toggleItem( e ) {
436 + /*jshint validthis:true */
437 + var toggle = this.getAttribute( 'data-frmtoggle' ),
438 + text = this.getAttribute( 'data-toggletext' ),
439 + items = jQuery( toggle );
440 +
441 + e.preventDefault();
442 +
443 + if ( items.is( ':visible' ) ) {
444 + items.show();
445 + } else {
446 + items.hide();
447 + }
448 +
449 + if ( text !== null && text !== '' ) {
450 + this.setAttribute( 'data-toggletext', this.innerHTML );
451 + this.innerHTML = text;
452 + }
453 +
454 + return false;
455 + }
456 +
457 + function hideShowItem( e ) {
458 + /*jshint validthis:true */
459 + var hide = this.getAttribute( 'data-frmhide' ),
460 + show = this.getAttribute( 'data-frmshow' ),
461 + toggleClass = this.getAttribute( 'data-toggleclass' );
462 +
463 + e.preventDefault();
464 + if ( toggleClass === null ) {
465 + toggleClass = 'frm_hidden';
466 + }
467 +
468 + if ( hide !== null ) {
469 + jQuery( hide ).addClass( toggleClass );
470 + }
471 +
472 + if ( show !== null ) {
473 + jQuery( show ).removeClass( toggleClass );
474 + }
475 +
476 + var current = this.parentNode.querySelectorAll( 'a.current' );
477 + if ( current !== null ) {
478 + for ( var i = 0; i < current.length; i++ ) {
479 + current[ i ].classList.remove( 'current' );
480 + }
481 + this.classList.add( 'current' );
482 + }
483 +
484 + return false;
485 + }
486 +
487 + function setupMenuOffset() {
488 + window.onscroll = document.documentElement.onscroll = setMenuOffset;
489 + setMenuOffset();
490 + }
491 +
492 + function setMenuOffset() {
493 + var fields = document.getElementById( 'frm_adv_info' );
494 + if ( fields === null ) {
495 + return;
496 + }
497 +
498 + var currentOffset = document.documentElement.scrollTop || document.body.scrollTop; // body for Safari
499 + if ( currentOffset === 0 ) {
500 + fields.classList.remove( 'frm_fixed' );
501 + return;
502 + }
503 +
504 + var posEle = document.getElementById( 'frm_position_ele' );
505 + if ( posEle === null ) {
506 + return;
507 + }
508 +
509 + var eleOffset = jQuery( posEle ).offset();
510 + var offset = eleOffset.top;
511 + var desiredOffset = offset - currentOffset;
512 + var menuHeight = 0;
513 +
514 + var menu = document.getElementById( 'wpadminbar' );
515 + if ( menu !== null ) {
516 + menuHeight = menu.offsetHeight;
517 + }
518 +
519 + if ( desiredOffset < menuHeight ) {
520 + desiredOffset = menuHeight;
521 + }
522 +
523 + if ( desiredOffset > menuHeight ) {
524 + fields.classList.remove( 'frm_fixed' );
525 + } else {
526 + fields.classList.add( 'frm_fixed' );
527 + if ( desiredOffset !== 32 ) {
528 + fields.style.top = desiredOffset + 'px';
529 + }
530 + }
531 + }
532 +
533 + function loadTooltips() {
534 + var wrapClass = jQuery( '.wrap, .frm_wrap' ),
535 + confirmModal = document.getElementById( 'frm_confirm_modal' ),
536 + doAction = false,
537 + confirmedBulkDelete = false;
538 +
539 + jQuery( confirmModal ).on( 'click', '[data-deletefield]', deleteFieldConfirmed );
540 + jQuery( confirmModal ).on( 'click', '[data-removeid]', removeThisTag );
541 + jQuery( confirmModal ).on( 'click', '[data-trashtemplate]', trashTemplate );
542 +
543 + wrapClass.on( 'click', '.frm_remove_tag, .frm_remove_form_action', removeThisTag );
544 + wrapClass.on( 'click', 'a[data-frmverify]', confirmClick );
545 + wrapClass.on( 'click', 'a[data-frmtoggle]', toggleItem );
546 + wrapClass.on( 'click', 'a[data-frmhide], a[data-frmshow]', hideShowItem );
547 + wrapClass.on( 'click', '.widget-top,a.widget-action', clickWidget );
548 +
549 + wrapClass.on( 'mouseenter.frm', '.frm_bstooltip, .frm_help', function() {
550 + jQuery( this ).off( 'mouseenter.frm' );
551 +
552 + jQuery( '.frm_bstooltip, .frm_help' ).tooltip( );
553 + jQuery( this ).tooltip( 'show' );
554 + });
555 +
556 + jQuery( '.frm_bstooltip, .frm_help' ).tooltip( );
557 +
558 + jQuery( document ).on( 'click', '#doaction, #doaction2', function( event ) {
559 + var isTop = this.id === 'doaction',
560 + suffix = isTop ? 'top' : 'bottom',
561 + bulkActionSelector = document.getElementById( 'bulk-action-selector-' + suffix ),
562 + confirmBulkDelete = document.getElementById( 'confirm-bulk-delete-' + suffix );
563 +
564 + if ( bulkActionSelector !== null && confirmBulkDelete !== null ) {
565 + doAction = this;
566 +
567 + if ( ! confirmedBulkDelete && bulkActionSelector.value === 'bulk_delete' ) {
568 + event.preventDefault();
569 + confirmLinkClick( confirmBulkDelete );
570 + return false;
571 + }
572 + } else {
573 + doAction = false;
574 + }
575 + });
576 +
577 + jQuery( document ).on( 'click', '#frm-confirmed-click', function( event ) {
578 + if ( doAction === false ) {
579 + return;
580 + }
581 +
582 + if ( this.getAttribute( 'href' ) === 'confirm-bulk-delete' ) {
583 + event.preventDefault();
584 + confirmedBulkDelete = true;
585 + doAction.click();
586 + return false;
587 + }
588 + });
589 + }
590 +
591 + function deleteTooltips() {
592 + document.querySelectorAll( '.tooltip' ).forEach(
593 + function( tooltip ) {
594 + tooltip.remove();
595 + }
596 + );
597 + }
598 +
599 + function removeThisTag() {
600 + /*jshint validthis:true */
601 + var show, hide, removeMore,
602 + id = '',
603 + deleteButton = jQuery( this ),
604 + continueRemove = confirmLinkClick( this );
605 +
606 + if ( parseInt( this.getAttribute( 'data-skip-frm-js' ) ) ) {
607 + return;
608 + }
609 +
610 + if ( continueRemove === false ) {
611 + return;
612 + } else {
613 + id = deleteButton.attr( 'data-removeid' );
614 + show = deleteButton.attr( 'data-showlast' );
615 + removeMore = deleteButton.attr( 'data-removemore' );
616 + if ( typeof show === 'undefined' ) {
617 + show = '';
618 + }
619 + hide = deleteButton.attr( 'data-hidelast' );
620 + if ( typeof hide === 'undefined' ) {
621 + hide = '';
622 + }
623 + }
624 +
625 + if ( show !== '' ) {
626 + if ( deleteButton.closest( '.frm_add_remove' ).find( '.frm_remove_tag:visible' ).length > 1 ) {
627 + show = '';
628 + hide = '';
629 + }
630 + } else if ( id.indexOf( 'frm_postmeta_' ) === 0 ) {
631 + if ( jQuery( '#frm_postmeta_rows .frm_postmeta_row' ).length < 2 ) {
632 + show = '.frm_add_postmeta_row.button';
633 + }
634 + if ( jQuery( '.frm_toggle_cf_opts' ).length && jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().length ) {
635 + if ( show !== '' ) {
636 + show += ',';
637 + }
638 + show += '#' + jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().attr( 'id' ) + ' .frm_toggle_cf_opts';
639 + }
640 + }
641 +
642 + var $fadeEle = jQuery( document.getElementById( id ) );
643 + $fadeEle.fadeOut( 400, function() {
644 + $fadeEle.remove();
645 + fieldUpdated();
646 +
647 + if ( hide !== '' ) {
648 + jQuery( hide ).hide();
649 + }
650 +
651 + if ( show !== '' ) {
652 + jQuery( show + ' a,' + show ).removeClass( 'frm_hidden' ).fadeIn( 'slow' );
653 + }
654 +
655 + var action = jQuery( this ).closest( '.frm_form_action_settings' );
656 + if ( typeof action !== 'undefined' ) {
657 + var type = jQuery( this ).closest( '.frm_form_action_settings' ).find( '.frm_action_name' ).val();
658 + checkActiveAction( type );
659 + }
660 + });
661 +
662 + if ( typeof removeMore !== 'undefined' ) {
663 + removeMore = jQuery( removeMore );
664 + removeMore.fadeOut( 400, function() {
665 + removeMore.remove();
666 + });
667 + }
668 +
669 + if ( show !== '' ) {
670 + jQuery( this ).closest( '.frm_logic_rows' ).fadeOut( 'slow' );
671 + }
672 +
673 + return false;
674 + }
675 +
676 + function clickWidget( event, b ) {
677 + /*jshint validthis:true */
678 + var target = event.target;
679 + if ( typeof b === 'undefined' ) {
680 + b = this;
681 + }
682 +
683 + popCalcFields( b, false );
684 +
685 + var cont = jQuery( b ).closest( '.frm_form_action_settings' );
686 + if ( cont.length && typeof target !== 'undefined' ) {
687 + var className = target.parentElement.className;
688 + if ( 'string' === typeof className ) {
689 + if ( className.indexOf( 'frm_email_icons' ) > -1 || className.indexOf( 'frm_toggle' ) > -1 ) {
690 + // clicking on delete icon shouldn't open it
691 + event.stopPropagation();
692 + return;
693 + }
694 + }
695 + }
696 +
697 + var inside = cont.children( '.widget-inside' );
698 +
699 + if ( cont.length && inside.find( 'p, div, table' ).length < 1 ) {
700 + var actionId = cont.find( 'input[name$="[ID]"]' ).val();
701 + var actionType = cont.find( 'input[name$="[post_excerpt]"]' ).val();
702 + if ( actionType ) {
703 + inside.html( '<span class="frm-wait frm_spinner"></span>' );
704 + cont.find( '.spinner' ).fadeIn( 'slow' );
705 + jQuery.ajax({
706 + type: 'POST',
707 + url: ajaxurl,
708 + data: {
709 + action: 'frm_form_action_fill',
710 + action_id: actionId,
711 + action_type: actionType,
712 + nonce: frmGlobal.nonce
713 + },
714 + success: function( html ) {
715 + inside.html( html );
716 + initiateMultiselect();
717 + showInputIcon( '#' + cont.attr( 'id' ) );
718 + initAutocomplete( 'page', inside );
719 + jQuery( b ).trigger( 'frm-action-loaded' );
720 + }
721 + });
722 + }
723 + }
724 +
725 + jQuery( b ).closest( '.frm_field_box' ).siblings().find( '.widget-inside' ).slideUp( 'fast' );
726 + if ( ( typeof b.className !== 'undefined' && b.className.indexOf( 'widget-action' ) !== -1 ) || jQuery( b ).closest( '.start_divider' ).length < 1 ) {
727 + return;
728 + }
729 +
730 + inside = jQuery( b ).closest( 'div.widget' ).children( '.widget-inside' );
731 + if ( inside.is( ':hidden' ) ) {
732 + inside.slideDown( 'fast' );
733 + } else {
734 + inside.slideUp( 'fast' );
735 + }
736 + }
737 +
738 + function clickNewTab() {
739 + /*jshint validthis:true */
740 + var t = this.getAttribute( 'href' ),
741 + c = t.replace( '#', '.' ),
742 + $link = jQuery( this );
743 +
744 + if ( typeof t === 'undefined' ) {
745 + return false;
746 + }
747 +
748 + $link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' );
749 + $link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide();
750 + document.getElementById( t.replace( '#', '' ) ).style.display = 'block';
751 +
752 + if ( this.id === 'frm_insert_fields_tab' ) {
753 + clearSettingsBox();
754 + }
755 + return false;
756 + }
757 +
758 + function clickTab( link, auto ) {
759 + link = jQuery( link );
760 + var t = link.attr( 'href' );
761 + if ( typeof t === 'undefined' ) {
762 + return;
763 + }
764 +
765 + var c = t.replace( '#', '.' );
766 +
767 + link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' );
768 + if ( link.closest( 'div' ).find( '.tabs-panel' ).length ) {
769 + link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide();
770 + } else {
771 + if ( document.getElementById( 'form_global_settings' ) !== null ) {
772 + /* global settings */
773 + var ajax = link.data( 'frmajax' );
774 + link.closest( '.frm_wrap' ).find( '.tabs-panel, .hide_with_tabs' ).hide();
775 + if ( typeof ajax !== 'undefined' && ajax == '1' ) {
776 + loadSettingsTab( t );
777 + }
778 + } else {
779 + /* form settings page */
780 + jQuery( '#frm-categorydiv .tabs-panel, .hide_with_tabs' ).hide();
781 + }
782 + }
783 + jQuery( t ).show();
784 + jQuery( c ).show();
785 +
786 + hideShortcodes();
787 +
788 + if ( auto !== 'auto' ) {
789 + // Hide success message on tab change.
790 + jQuery( '.frm_updated_message' ).hide();
791 + jQuery( '.frm_warning_style' ).hide();
792 + }
793 +
794 + if ( jQuery( link ).closest( '#frm_adv_info' ).length ) {
795 + return;
796 + }
797 +
798 + if ( jQuery( '.frm_form_settings' ).length ) {
799 + jQuery( '.frm_form_settings' ).attr( 'action', '?page=formidable&frm_action=settings&id=' + jQuery( '.frm_form_settings input[name="id"]' ).val() + '&t=' + t.replace( '#', '' ) );
800 + } else {
801 + jQuery( '.frm_settings_form' ).attr( 'action', '?page=formidable-settings&t=' + t.replace( '#', '' ) );
802 + }
803 + }
804 +
805 + /* Form Builder */
806 + function setupSortable( sort ) {
807 + var startSort, container, $previousFieldContainer, opts;
808 +
809 + startSort = false;
810 + container = jQuery( '#post-body-content' );
811 +
812 + opts = {
813 + connectWith: 'ul.frm_sorting',
814 + items: 'li.frm_field_box',
815 + placeholder: 'sortable-placeholder',
816 + axis: 'y',
817 + cancel: '.widget,.frm_field_opts_list,input,textarea,select,.edit_field_type_end_divider,.frm_sortable_field_opts,.frm_noallow',
818 + accepts: 'field_type_list',
819 + forcePlaceholderSize: false,
820 + tolerance: 'pointer',
821 + handle: '.frm-move',
822 + over: function() {
823 + this.classList.add( 'drop-me' );
824 + },
825 + out: function() {
826 + this.classList.remove( 'drop-me' );
827 + },
828 + receive: function( event, ui ) {
829 + // Receive event occurs when an item in one sortable list is dragged into another sortable list
830 +
831 + if ( cancelSort ) {
832 + ui.item.addClass( 'frm_cancel_sort' );
833 + return;
834 + }
835 +
836 + if ( typeof ui.item.attr( 'id' ) !== 'undefined' ) {
837 + if ( ui.item.attr( 'id' ).indexOf( 'frm_field_id' ) > -1 ) {
838 + // An existing field was dragged and dropped into, out of, or between sections
839 + updateFieldAfterMovingBetweenSections( ui.item );
840 + } else {
841 + // A new field was dragged into the form
842 + insertNewFieldByDragging( this, ui.item, opts );
843 + }
844 + } else if ( ui.item.hasClass( 'frm_field_box' ) ) {
845 + // dragging a group.
846 + getFieldsInRow( ui.item.children( 'ul' ) ).each(
847 + function() {
848 + updateFieldAfterMovingBetweenSections( jQuery( this ) );
849 + }
850 + );
851 + }
852 + },
853 + change: function( event, ui ) {
854 + // don't allow some field types inside section
855 + if ( allowDrop( ui ) ) {
856 + ui.placeholder.addClass( 'sortable-placeholder' ).removeClass( 'no-drop-placeholder' );
857 + cancelSort = false;
858 + } else {
859 + ui.placeholder.addClass( 'no-drop-placeholder' ).removeClass( 'sortable-placeholder' );
860 + cancelSort = true;
861 + }
862 + },
863 + start: function( event, ui ) {
864 + unselectFieldGroups();
865 + deleteEmptyDividerWrappers();
866 + maybeRemoveGroupHoverTarget();
867 + closeOpenFieldDropdowns();
868 + container.get( 0 ).classList.add( 'frm-dragging-field' );
869 + if ( ui.item[0].offsetHeight > 120 ) {
870 + jQuery( sort ).sortable( 'refreshPositions' );
871 + }
872 + if ( ui.item[0].classList.contains( 'frm-page-collapsed' ) ) {
873 + // If a page if collapsed, expand it before dragging since only the page break will move.
874 + toggleCollapsePage( jQuery( ui.item[0]) );
875 + }
876 + $previousFieldContainer = ui.item.closest( 'ul.frm_sorting' );
877 + },
878 + helper: function( e, li ) {
879 + copyHelper = li.clone().insertAfter( li );
880 + return li.clone().addClass( 'frm-sortable-helper' );
881 + },
882 + beforeStop: function( event, ui ) {
883 + // If this was dropped at the beginning of a collpased page, open it.
884 + var previous = ui.item[0].previousElementSibling;
885 + if ( previous !== null && previous.classList.contains( 'frm-page-collapsed' ) ) {
886 + toggleCollapsePage( jQuery( previous ) );
887 + }
888 + },
889 + stop: function( event, ui ) {
890 + var moving, $previousContainerFields, $closestFieldBox;
891 +
892 + container.get( 0 ).classList.remove( 'frm-dragging-field' );
893 + moving = jQuery( this );
894 + copyHelper && copyHelper.remove();
895 +
896 + if ( cancelSort ) {
897 + moving.sortable( 'cancel' );
898 + syncAfterDragAndDrop();
899 + return;
900 + }
901 +
902 + $previousContainerFields = $previousFieldContainer.length ? getFieldsInRow( $previousFieldContainer ) : [];
903 + if ( $previousFieldContainer.length ) {
904 + if ( ! $previousContainerFields.length ) {
905 + $closestFieldBox = $previousFieldContainer.closest( 'li.frm_field_box' );
906 + if ( ! $closestFieldBox.hasClass( 'edit_field_type_divider' ) ) {
907 + // remove an empty field group, but don't remove an empty section.
908 + $closestFieldBox.remove();
909 + }
910 + } else {
911 + syncLayoutClasses( $previousContainerFields.first() );
912 + }
913 + }
914 +
915 + if ( ( 'frm-show-fields' === ui.item.parent().attr( 'id' ) || ui.item.parent().hasClass( 'start_divider' ) ) && ui.item.hasClass( 'form-field' ) ) {
916 + // dragging an item into a new row.
917 + wrapFieldLiInPlace( ui.item );
918 + if ( $previousContainerFields.length ) {
919 + // only if the previous container had other sibling fields, remove the previous layout class.
920 + syncLayoutClasses( ui.item );
921 + }
922 + } else {
923 + syncLayoutClasses( ui.item );
924 + }
925 +
926 + syncAfterDragAndDrop();
927 + },
928 + sort: function( event, ui ) {
929 + var $row, $children, $lastChild, currentIndex, left;
930 +
931 + container.scrollTop( function( i, v ) {
932 + var moved, h, relativePos, y;
933 +
934 + if ( startSort === false ) {
935 + startSort = event.clientY;
936 + return v;
937 + }
938 +
939 + moved = event.clientY - startSort;
940 + h = this.offsetHeight;
941 + relativePos = event.clientY - this.offsetTop;
942 + y = relativePos - h / 2;
943 + if ( relativePos > ( h - 50 ) && moved > 5 ) {
944 + // scrolling down
945 + return v + y * 0.1;
946 + } else if ( relativePos < 50 && moved < -5 ) {
947 + //scrolling up
948 + return v - Math.abs( y * 0.1 );
949 + }
950 + });
951 +
952 + maybeFixPlaceholderParent( ui, event );
953 +
954 + $row = ui.placeholder.parent();
955 + $children = getFieldsInRow( $row );
956 + currentIndex = determineIndexBasedOffOfMousePositionInRow( $row, event.clientX );
957 +
958 + if ( ! $children.length ) {
959 + return;
960 + }
961 +
962 + if ( currentIndex === $children.length ) {
963 + $lastChild = jQuery( $children.get( currentIndex - 1 ) );
964 + left = $lastChild.offset().left - ui.placeholder.parent().offset().left + $lastChild.outerWidth();
965 + $row.append( ui.placeholder );
966 + } else {
967 + left = jQuery( $children.get( currentIndex ) ).offset().left - $row.offset().left;
968 + jQuery( $children.get( currentIndex ) ).before( ui.placeholder );
969 + }
970 +
971 + ui.placeholder.get( 0 ).style.left = left + 'px';
972 + }
973 + };
974 +
975 + jQuery( sort ).sortable( opts );
976 +
977 + setupFieldOptionSorting( jQuery( '#frm_builder_page' ) );
978 + }
979 +
980 + function syncAfterDragAndDrop() {
981 + maybeRemoveNewCancelledFields();
982 + maybeUncancelFields();
983 + maybeFixEndDividers();
984 + fixUnwrappedListItems();
985 + toggleSectionHolder();
986 + updateFieldOrder();
987 +
988 + const event = new Event( 'frm_sync_after_drag_and_drop', { bubbles: false });
989 + document.dispatchEvent( event );
990 + }
991 +
992 + function maybeRemoveNewCancelledFields() {
993 + Array.from( document.getElementById( 'frm-show-fields' ).children ).forEach(
994 + function( fieldBox ) {
995 + if ( fieldBox.classList.contains( 'frmbutton' ) && fieldBox.classList.contains( 'ui-draggable' ) ) {
996 + fieldBox.remove();
997 + }
998 + }
999 + );
1000 + }
1001 +
1002 + function maybeUncancelFields() {
1003 + document.querySelectorAll( '.frm_cancel_sort' ).forEach(
1004 + function( field ) {
1005 + field.classList.remove( 'frm_cancel_sort' );
1006 + }
1007 + );
1008 + }
1009 +
1010 + /**
1011 + * Make sure the end dividers are always a child of a start divider, at the bottom at the list.
1012 + */
1013 + function maybeFixEndDividers() {
1014 + var endDividers = document.querySelectorAll( '.edit_field_type_end_divider' );
1015 + if ( ! endDividers.length ) {
1016 + return;
1017 + }
1018 + endDividers.forEach(
1019 + function( endDivider ) {
1020 + if ( endDivider.parentNode.classList.contains( 'start_divider' ) ) {
1021 + // avoid having to call closest, but still append it as it might not be the last child.
1022 + endDivider.parentNode.appendChild( endDivider );
1023 + return;
1024 + }
1025 + endDivider.closest( '.start_divider' ).appendChild( endDivider );
1026 + }
1027 + );
1028 + }
1029 +
1030 + /**
1031 + * Sortable struggles to put the field into the proper section if there are multiple in a field group. This helps fix some of those issues.
1032 + */
1033 + function maybeFixPlaceholderParent( ui, event ) {
1034 + var elementFromPoint, wrapper, shouldAppend;
1035 + elementFromPoint = document.elementFromPoint( event.clientX, event.clientY );
1036 + if ( null === elementFromPoint ) {
1037 + return;
1038 + }
1039 + wrapper = elementFromPoint.closest( '.frm_sorting' );
1040 + if ( null === wrapper ) {
1041 + return;
1042 + }
1043 + if ( ui.placeholder.closest( '.start_divider' ).parent().parent().find( '.start_divider' ).length < 2 ) {
1044 + // placeholder is not in a problematic position that needs to be fixed so leave it.
1045 + return;
1046 + }
1047 + shouldAppend = false;
1048 + if ( wrapper.classList.contains( 'start_divider' ) ) {
1049 + shouldAppend = jQuery( wrapper ).parent().parent().find( '.start_divider' ).length >= 2;
1050 + } else if ( null !== wrapper.closest( '.start_divider' ) ) {
1051 + shouldAppend = jQuery( wrapper ).closest( '.start_divider' ).parent().parent().find( '.start_divider' ).length >= 2;
1052 + }
1053 + if ( null !== wrapper.closest( '.frm-sortable-helper' ) ) {
1054 + // avoid ever appending to the sortable helper.
1055 + return;
1056 + }
1057 + if ( shouldAppend ) {
1058 + // TODO instead of appendTo, we might need to look for the closest item, and appear above/below it.
1059 + ui.placeholder.appendTo( wrapper );
1060 + }
1061 + }
1062 +
1063 + function fixUnwrappedListItems() {
1064 + document.querySelectorAll( 'ul.start_divider > li.form-field:not(.edit_field_type_end_divider)' ).forEach(
1065 + function( field ) {
1066 + wrapFieldLiInPlace( field );
1067 + }
1068 + );
1069 + }
1070 +
1071 + function deleteEmptyDividerWrappers() {
1072 + var dividers = document.querySelectorAll( 'ul.start_divider' );
1073 + if ( ! dividers.length ) {
1074 + return;
1075 + }
1076 + dividers.forEach(
1077 + function( divider ) {
1078 + var children = [].slice.call( divider.children );
1079 + children.forEach(
1080 + function( child ) {
1081 + if ( 0 === child.children.length ) {
1082 + child.remove();
1083 + } else if ( 1 === child.children.length && 'ul' === child.firstElementChild.nodeName.toLowerCase() && 0 === child.firstElementChild.children.length ) {
1084 + child.remove();
1085 + }
1086 + }
1087 + );
1088 + }
1089 + );
1090 + }
1091 +
1092 + /**
1093 + * @returns {bool} true if the placeholder parent should be fixed.
1094 + */
1095 + function shouldTryFixingPlaceholderParent( $placeholder ) {
1096 + var closestSection = $placeholder.closest( '.start_divider' );
1097 + if ( null === closestSection ) {
1098 + return false;
1099 + }
1100 + return jQuery( closestSection ).siblings( 'li.start_divider' ).length >= 1;
1101 + }
1102 +
1103 + function getFieldsInRow( $row ) {
1104 + return $row.children( 'li.form-field' ).not( '.ui-sortable-helper' ).not( '.edit_field_type_end_divider' ).filter(
1105 + function() {
1106 + return 'none' !== this.style.display;
1107 + }
1108 + );
1109 + }
1110 +
1111 + function determineIndexBasedOffOfMousePositionInRow( $row, x ) {
1112 + var $inputs = getFieldsInRow( $row ),
1113 + length = $inputs.length,
1114 + index, input, inputLeft, returnIndex;
1115 +
1116 + returnIndex = 0;
1117 + for ( index = length - 1; index >= 0; --index ) {
1118 + input = $inputs.get( index );
1119 + inputLeft = jQuery( input ).offset().left;
1120 + if ( x > inputLeft ) {
1121 + returnIndex = index;
1122 + if ( x > inputLeft + ( jQuery( input ).outerWidth() / 2 ) ) {
1123 + returnIndex = index + 1;
1124 + }
1125 + break;
1126 + }
1127 + }
1128 +
1129 + return returnIndex;
1130 + }
1131 +
1132 + function syncLayoutClasses( $item, type ) {
1133 + var $fields, size, layoutClasses, classToAddFunction;
1134 +
1135 + if ( 'undefined' === typeof type ) {
1136 + type = 'even';
1137 + }
1138 +
1139 + $fields = $item.parent().children( 'li.form-field, li.frmbutton_loadingnow' ).not( '.edit_field_type_end_divider' );
1140 + size = $fields.length;
1141 + layoutClasses = getLayoutClasses();
1142 +
1143 + if ( 'even' === type && 5 !== size ) {
1144 + $fields.each( getSyncLayoutClass( layoutClasses, getEvenClassForSize( size ) ) );
1145 + } else if ( 'clear' === type ) {
1146 + $fields.each( getSyncLayoutClass( layoutClasses, '' ) );
1147 + } else {
1148 + if ( -1 !== [ 'left', 'right', 'middle', 'even' ].indexOf( type ) ) {
1149 + classToAddFunction = function( index ) {
1150 + return getClassForBlock( size, type, index );
1151 + };
1152 + } else {
1153 + classToAddFunction = function( index ) {
1154 + var size = type[ index ];
1155 + return getLayoutClassForSize( size );
1156 + };
1157 + }
1158 +
1159 + $fields.each( getSyncLayoutClass( layoutClasses, classToAddFunction ) );
1160 + }
1161 +
1162 + updateFieldGroupControls( $item.parent(), $fields.length );
1163 + }
1164 +
1165 + function updateFieldGroupControls( $row, count ) {
1166 + var rowOffset, shouldShowControls, controls;
1167 +
1168 + rowOffset = $row.offset();
1169 +
1170 + if ( 'undefined' === typeof rowOffset ) {
1171 + return;
1172 + }
1173 +
1174 + shouldShowControls = count >= 2;
1175 +
1176 + controls = document.getElementById( 'frm_field_group_controls' );
1177 + if ( null === controls ) {
1178 + if ( ! shouldShowControls ) {
1179 + // exit early. if we do not need controls and they do not exist, do nothing.
1180 + return;
1181 + }
1182 +
1183 + controls = div();
1184 + controls.id = 'frm_field_group_controls';
1185 + controls.setAttribute( 'role', 'group' );
1186 + controls.setAttribute( 'tabindex', 0 );
1187 + setFieldControlsHtml( controls );
1188 + document.getElementById( 'frm_builder_page' ).appendChild( controls );
1189 + }
1190 +
1191 + $row.append( controls );
1192 + controls.style.display = shouldShowControls ? 'block' : 'none';
1193 + }
1194 +
1195 + function setFieldControlsHtml( controls ) {
1196 + var layoutOption, moveOption;
1197 +
1198 + layoutOption = document.createElement( 'span' );
1199 + layoutOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_field_group_layout_icon"></use></svg>';
1200 + const layoutOptionLabel = __( 'Set Row Layout', 'formidable' );
1201 + addTooltip( layoutOption, layoutOptionLabel );
1202 + makeTabbable( layoutOption, layoutOptionLabel );
1203 +
1204 + moveOption = document.createElement( 'span' );
1205 + moveOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_thick_move_icon"></use></svg>';
1206 + const moveOptionLabel = __( 'Move Field Group', 'formidable' );
1207 + addTooltip( moveOption, moveOptionLabel );
1208 + makeTabbable( moveOption, moveOptionLabel );
1209 +
1210 + controls.innerHTML = '';
1211 + controls.appendChild( layoutOption );
1212 + controls.appendChild( moveOption );
1213 + controls.appendChild( getFieldControlsDropdown() );
1214 + }
1215 +
1216 + function addTooltip( element, title ) {
1217 + element.setAttribute( 'data-toggle', 'tooltip' );
1218 + element.setAttribute( 'data-container', 'body' );
1219 + element.setAttribute( 'title', title );
1220 + element.addEventListener(
1221 + 'mouseover',
1222 + function() {
1223 + if ( null === element.getAttribute( 'data-original-title' ) ) {
1224 + jQuery( element ).tooltip();
1225 + }
1226 + }
1227 + );
1228 + }
1229 +
1230 + function getFieldControlsDropdown() {
1231 + var dropdown, trigger, ul;
1232 +
1233 + dropdown = document.createElement( 'span' );
1234 + dropdown.classList.add( 'dropdown' );
1235 +
1236 + trigger = document.createElement( 'a' );
1237 + trigger.classList.add( 'frm_bstooltip', 'frm-hover-icon', 'frm-dropdown-toggle', 'dropdown-toggle' );
1238 + trigger.setAttribute( 'title', __( 'More Options', 'formidable' ) );
1239 + trigger.setAttribute( 'data-toggle', 'dropdown' );
1240 + trigger.setAttribute( 'data-container', 'body' );
1241 + makeTabbable( trigger, __( 'More Options', 'formidable' ) );
1242 + trigger.innerHTML = '<span><svg class="frmsvg"><use xlink:href="#frm_thick_more_vert_icon"></use></svg></span>';
1243 + dropdown.appendChild( trigger );
1244 +
1245 + ul = document.createElement( 'ul' );
1246 + ul.classList.add( 'frm-dropdown-menu' );
1247 + ul.setAttribute( 'role', 'menu' );
1248 + dropdown.appendChild( ul );
1249 +
1250 + return dropdown;
1251 + }
1252 +
1253 + function getSyncLayoutClass( layoutClasses, classToAdd ) {
1254 + return function( itemIndex ) {
1255 + var currentClassToAdd, length, layoutClassIndex, currentClass, activeLayoutClass, fieldId, layoutClassesInput;
1256 +
1257 + currentClassToAdd = 'function' === typeof classToAdd ? classToAdd( itemIndex ) : classToAdd;
1258 + length = layoutClasses.length;
1259 + activeLayoutClass = false;
1260 + for ( layoutClassIndex = 0; layoutClassIndex < length; ++layoutClassIndex ) {
1261 + currentClass = layoutClasses[ layoutClassIndex ];
1262 + if ( this.classList.contains( currentClass ) ) {
1263 + activeLayoutClass = currentClass;
1264 + break;
1265 + }
1266 + }
1267 +
1268 + fieldId = this.dataset.fid;
1269 +
1270 + if ( 'undefined' === typeof fieldId ) {
1271 + // we are syncing the drag/drop placeholder before the actual field has loaded.
1272 + // this will get called again afterward and the input will exist then.
1273 + this.classList.add( currentClassToAdd );
1274 + return;
1275 + }
1276 +
1277 + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) );
1278 + layoutClassesInput = document.getElementById( 'frm_classes_' + fieldId );
1279 +
1280 + if ( null === layoutClassesInput ) {
1281 + // not every field type has a layout class input.
1282 + return;
1283 + }
1284 +
1285 + if ( false === activeLayoutClass ) {
1286 + if ( '' !== currentClassToAdd ) {
1287 + layoutClassesInput.value = layoutClassesInput.value.concat( ' ' + currentClassToAdd );
1288 + }
1289 + } else {
1290 + this.classList.remove( activeLayoutClass );
1291 + layoutClassesInput.value = layoutClassesInput.value.replace( activeLayoutClass, currentClassToAdd );
1292 + }
1293 +
1294 + if ( this.classList.contains( 'frm_first' ) ) {
1295 + this.classList.remove( 'frm_first' );
1296 + layoutClassesInput.value = layoutClassesInput.value.replace( 'frm_first', '' ).trim();
1297 + }
1298 +
1299 + if ( 0 === itemIndex ) {
1300 + this.classList.add( 'frm_first' );
1301 + layoutClassesInput.value = layoutClassesInput.value.concat( ' frm_first' );
1302 + }
1303 +
1304 + jQuery( layoutClassesInput ).trigger( 'change' );
1305 + };
1306 + }
1307 +
1308 + function getLayoutClasses() {
1309 + 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' ];
1310 + }
1311 +
1312 + function setupFieldOptionSorting( sort ) {
1313 + var opts = {
1314 + items: '.frm_sortable_field_opts li',
1315 + axis: 'y',
1316 + opacity: 0.65,
1317 + forcePlaceholderSize: false,
1318 + handle: '.frm-drag',
1319 + helper: function( e, li ) {
1320 + copyHelper = li.clone().insertAfter( li );
1321 + return li.clone();
1322 + },
1323 + stop: function( e, ui ) {
1324 + copyHelper && copyHelper.remove();
1325 + var fieldId = ui.item.attr( 'id' ).replace( 'frm_delete_field_', '' ).replace( '-' + ui.item.data( 'optkey' ) + '_container', '' );
1326 + resetDisplayedOpts( fieldId );
1327 + }
1328 + };
1329 +
1330 + jQuery( sort ).sortable( opts );
1331 + }
1332 +
1333 + // Get the section where a field is dropped
1334 + function getSectionForFieldPlacement( currentItem ) {
1335 + var section = '';
1336 + if ( typeof currentItem !== 'undefined' && ! currentItem.hasClass( 'edit_field_type_divider' ) ) {
1337 + section = currentItem.closest( '.edit_field_type_divider' );
1338 + }
1339 + return section;
1340 + }
1341 +
1342 + // Get the form ID where a field is dropped
1343 + function getFormIdForFieldPlacement( section ) {
1344 + var formId = '';
1345 +
1346 + if ( typeof section[0] !== 'undefined' ) {
1347 + var sDivide = section.children( '.start_divider' );
1348 + sDivide.children( '.edit_field_type_end_divider' ).appendTo( sDivide );
1349 + if ( typeof section.attr( 'data-formid' ) !== 'undefined' ) {
1350 + var fieldId = section.attr( 'data-fid' );
1351 + formId = jQuery( 'input[name="field_options[form_select_' + fieldId + ']"]' ).val();
1352 + }
1353 + }
1354 +
1355 + if ( typeof formId === 'undefined' || formId === '' ) {
1356 + formId = thisFormId;
1357 + }
1358 +
1359 + return formId;
1360 + }
1361 +
1362 + // Get the section ID where a field is dropped
1363 + function getSectionIdForFieldPlacement( section ) {
1364 + var sectionId = 0;
1365 + if ( typeof section[0] !== 'undefined' ) {
1366 + sectionId = section.attr( 'id' ).replace( 'frm_field_id_', '' );
1367 + }
1368 +
1369 + return sectionId;
1370 + }
1371 +
1372 + /**
1373 + * Update a field after it is dragged and dropped into, out of, or between sections
1374 + *
1375 + * @param {object} currentItem
1376 + */
1377 + function updateFieldAfterMovingBetweenSections( currentItem ) {
1378 + var fieldId, section, formId, sectionId;
1379 +
1380 + fieldId = currentItem.attr( 'id' ).replace( 'frm_field_id_', '' );
1381 + section = getSectionForFieldPlacement( currentItem );
1382 + formId = getFormIdForFieldPlacement( section );
1383 + sectionId = getSectionIdForFieldPlacement( section );
1384 +
1385 + if ( currentItem.parent().hasClass( 'start_divider' ) ) {
1386 + wrapFieldLiInPlace( currentItem );
1387 + }
1388 +
1389 + jQuery.ajax({
1390 + type: 'POST', url: ajaxurl,
1391 + data: {
1392 + action: 'frm_update_field_after_move',
1393 + form_id: formId,
1394 + field: fieldId,
1395 + section_id: sectionId,
1396 + nonce: frmGlobal.nonce
1397 + },
1398 + success: function() {
1399 + toggleSectionHolder();
1400 + updateInSectionValue( fieldId, sectionId );
1401 + }
1402 + });
1403 + }
1404 +
1405 + // Update the in_section field value
1406 + function updateInSectionValue( fieldId, sectionId ) {
1407 + document.getElementById( 'frm_in_section_' + fieldId ).value = sectionId;
1408 + }
1409 +
1410 + /**
1411 + * Add a new field by dragging and dropping it from the Fields sidebar
1412 + *
1413 + * @param {object} selectedItem
1414 + * @param {object} fieldButton
1415 + * @param {object} opts
1416 + */
1417 + function insertNewFieldByDragging( selectedItem, fieldButton ) {
1418 + var fieldType, addBtn, sortableData, currentItem, insertAtIndex, section, formId, sectionId, loadingID, hasBreak, $placeholder;
1419 +
1420 + fieldType = fieldButton.attr( 'id' );
1421 +
1422 + // We'll optimistically disable the button now. We'll re-enable if AJAX fails
1423 + if ( 'summary' === fieldType ) {
1424 + addBtn = fieldButton.children( '.frm_add_field' );
1425 + disableSummaryBtnBeforeAJAX( addBtn, fieldButton );
1426 + }
1427 +
1428 + sortableData = jQuery( selectedItem ).data().uiSortable;
1429 + currentItem = sortableData.currentItem;
1430 + insertAtIndex = determineIndexBasedOffOfMousePositionInRow( currentItem.parent(), currentItem.offset().left );
1431 + jQuery( getFieldsInRow( currentItem.parent() ).get( insertAtIndex ) ).before( currentItem );
1432 + section = getSectionForFieldPlacement( currentItem );
1433 + formId = getFormIdForFieldPlacement( section );
1434 + sectionId = getSectionIdForFieldPlacement( section );
1435 +
1436 + loadingID = fieldType.replace( '|', '-' ) + '_' + getAutoId();
1437 + $placeholder = jQuery( '<li class="frm-wait frmbutton_loadingnow" id="' + loadingID + '" ></li>' );
1438 + currentItem.replaceWith( $placeholder );
1439 +
1440 + syncLayoutClasses( $placeholder );
1441 +
1442 + hasBreak = 0;
1443 + if ( 'summary' === fieldType ) {
1444 + // see if we need to insert a page break before this newly-added summary field. Check for at least 1 page break
1445 + hasBreak = jQuery( '.frmbutton_loadingnow#' + loadingID ).prevAll( 'li[data-type="break"]' ).length ? 1 : 0;
1446 + }
1447 +
1448 + jQuery.ajax({
1449 + type: 'POST', url: ajaxurl,
1450 + data: {
1451 + action: 'frm_insert_field',
1452 + form_id: formId,
1453 + field_type: fieldType,
1454 + section_id: sectionId,
1455 + nonce: frmGlobal.nonce,
1456 + has_break: hasBreak
1457 + },
1458 + success: function( msg ) {
1459 + var $siblings, replaceWith;
1460 + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' );
1461 + $siblings = $placeholder.siblings( 'li.form-field' ).not( '.edit_field_type_end_divider' );
1462 + if ( ! $siblings.length ) {
1463 + // if dragging into a new row, we need to wrap the li first.
1464 + replaceWith = wrapFieldLi( msg );
1465 + } else {
1466 + replaceWith = msg;
1467 + }
1468 + $placeholder.replaceWith( replaceWith );
1469 + updateFieldOrder();
1470 + afterAddField( msg, false );
1471 + if ( $siblings.length ) {
1472 + syncLayoutClasses( $siblings.first() );
1473 + }
1474 + toggleSectionHolder();
1475 + },
1476 + error: function( jqXHR, textStatus, errorThrown ) {
1477 + maybeReenableSummaryBtnAfterAJAX( fieldType, addBtn, fieldButton, errorThrown );
1478 + }
1479 + });
1480 + }
1481 +
1482 + /**
1483 + * Get a unique id that automatically increments with every function call.
1484 + * Can be used for any UI that requires a unique id.
1485 + * Not to be used in data.
1486 + *
1487 + * @returns {integer}
1488 + */
1489 + function getAutoId() {
1490 + return ++autoId;
1491 + }
1492 +
1493 + // don't allow page break, embed form, or section inside section field
1494 + // don't allow page breaks inside of field groups.
1495 + // don't allow field groups with sections inside of sections.
1496 + // don't allow field groups in field groups.
1497 + // don't allow hidden fields inside of field groups but allow them in sections.
1498 + function allowDrop( ui ) {
1499 + var fieldsInRow, insideFieldGroup, insideSection, isNewField, isPageBreak, isFieldGroup, isSection;
1500 +
1501 + fieldsInRow = getFieldsInRow( ui.placeholder.parent() );
1502 +
1503 + if ( ! groupCanFitAnotherField( fieldsInRow, ui.item ) ) {
1504 + return false;
1505 + }
1506 +
1507 + insideFieldGroup = fieldsInRow.length > 0;
1508 + insideSection = ui.placeholder.closest( '.start_divider' ).length > 0;
1509 +
1510 + if ( ! insideSection && ! insideFieldGroup ) {
1511 + return true;
1512 + }
1513 +
1514 + if ( insideFieldGroup && ui.placeholder.siblings( '.edit_field_type_break, .edit_field_type_hidden' ).length ) {
1515 + // never allow any field beside a page break or a hidden field.
1516 + return false;
1517 + }
1518 +
1519 + if ( insideSection && ui.placeholder.siblings().length > 1 && ui.placeholder.prev().hasClass( 'edit_field_type_end_divider' ) ) {
1520 + return false;
1521 + }
1522 +
1523 + isNewField = ui.item.hasClass( 'frmbutton' );
1524 +
1525 + if ( isNewField ) {
1526 + isPageBreak = ui.item.hasClass( 'frm_tbreak' );
1527 +
1528 + if ( isPageBreak ) {
1529 + // do not allow page break in both sections and field groups.
1530 + return false;
1531 + }
1532 +
1533 + if ( insideFieldGroup && ( ui.item.hasClass( 'frm_thidden' ) || ui.item.hasClass( 'frm_tsummary' ) ) ) {
1534 + // do not allow a hidden field or summary field in a field group.
1535 + return false;
1536 + }
1537 +
1538 + if ( ! insideSection ) {
1539 + return true;
1540 + }
1541 +
1542 + return ! ui.item.hasClass( 'frm_tform' ) && ! ui.item.hasClass( 'frm_tdivider' ) && ! ui.item.hasClass( 'frm_tdivider-repeat' );
1543 + }
1544 +
1545 + isPageBreak = ui.item.hasClass( 'edit_field_type_break' );
1546 +
1547 + if ( isPageBreak ) {
1548 + // do not allow page break in both sections and field groups.
1549 + return false;
1550 + }
1551 +
1552 + isFieldGroup = ui.item.find( 'ul.frm_sorting' ).length > 0;
1553 + isSection = ui.item.hasClass( 'edit_field_type_divider' );
1554 +
1555 + if ( insideSection && isSection ) {
1556 + // but do not allow a section inside of a section.
1557 + return false;
1558 + }
1559 +
1560 + if ( isFieldGroup && insideFieldGroup ) {
1561 + // allow a field group inside of a field group if it is being placed within a section above/below another field group.
1562 + return insideSection && ui.placeholder.siblings( 'li.edit_field_type_end_divider' ).length > 0;
1563 + }
1564 +
1565 + if ( insideFieldGroup && ui.item.hasClass( 'edit_field_type_hidden' ) ) {
1566 + // do not allow a hidden field inside of a field group.
1567 + return false;
1568 + }
1569 +
1570 + if ( ! insideSection ) {
1571 + return true;
1572 + }
1573 +
1574 + if ( ui.item.find( '.edit_field_type_divider' ).length ) {
1575 + // if we are dragging a field group with a section, do not allow it in section.
1576 + return false;
1577 + }
1578 +
1579 + // moving an existing field
1580 + return ! ui.item.hasClass( 'edit_field_type_form' ) && ! isSection;
1581 + }
1582 +
1583 + function groupCanFitAnotherField( fieldsInRow, $field ) {
1584 + var fieldId;
1585 + if ( fieldsInRow.length < 6 ) {
1586 + return true;
1587 + }
1588 + if ( fieldsInRow.length > 6 ) {
1589 + return false;
1590 + }
1591 + fieldId = $field.attr( 'data-fid' );
1592 + // allow 6 if we're not changing field groups.
1593 + return 1 === jQuery( fieldsInRow ).filter( '[data-fid="' + fieldId + '"]' ).length;
1594 + }
1595 +
1596 + function loadFields( fieldId ) {
1597 + var addHtmlToField, nextElement,
1598 + thisField = document.getElementById( fieldId ),
1599 + $thisField = jQuery( thisField ),
1600 + field = [];
1601 +
1602 + addHtmlToField = function( element ) {
1603 + var frmHiddenFdata = element.querySelector( '.frm_hidden_fdata' );
1604 + element.classList.add( 'frm_load_now' );
1605 + if ( frmHiddenFdata !== null ) {
1606 + field.push( frmHiddenFdata.innerHTML );
1607 + }
1608 + };
1609 +
1610 + nextElement = thisField;
1611 + addHtmlToField( nextElement );
1612 + while ( nextElement.nextElementSibling && field.length < 15 ) {
1613 + addHtmlToField( nextElement.nextElementSibling );
1614 + nextElement = nextElement.nextElementSibling;
1615 + }
1616 +
1617 + jQuery.ajax({
1618 + type: 'POST', url: ajaxurl,
1619 + data: {
1620 + action: 'frm_load_field',
1621 + field: field,
1622 + form_id: thisFormId,
1623 + nonce: frmGlobal.nonce
1624 + },
1625 + success: function( html ) {
1626 + var key, $nextSet;
1627 +
1628 + html = html.replace( /^\s+|\s+$/g, '' );
1629 + if ( html.indexOf( '{' ) !== 0 ) {
1630 + jQuery( '.frm_load_now' ).removeClass( '.frm_load_now' ).html( 'Error' );
1631 + return;
1632 + }
1633 +
1634 + html = JSON.parse( html );
1635 +
1636 + for ( key in html ) {
1637 + jQuery( '#frm_field_id_' + key ).replaceWith( html[key]);
1638 + setupSortable( '#frm_field_id_' + key + '.edit_field_type_divider ul.frm_sorting' );
1639 + }
1640 +
1641 + $nextSet = $thisField.nextAll( '.frm_field_loading:not(.frm_load_now)' );
1642 + if ( $nextSet.length ) {
1643 + loadFields( $nextSet.attr( 'id' ) );
1644 + } else {
1645 + // go up a level
1646 + $nextSet = jQuery( document.getElementById( 'frm-show-fields' ) ).find( '.frm_field_loading:not(.frm_load_now)' );
1647 + if ( $nextSet.length ) {
1648 + loadFields( $nextSet.attr( 'id' ) );
1649 + }
1650 + }
1651 +
1652 + initiateMultiselect();
1653 + renumberPageBreaks();
1654 + maybeHideQuantityProductFieldOption();
1655 + }
1656 + });
1657 + }
1658 +
1659 + function addFieldClick() {
1660 + /*jshint validthis:true */
1661 + var $thisObj = jQuery( this );
1662 + // there is no real way to disable a <a> (with a valid href attribute) in HTML - https://css-tricks.com/how-to-disable-links/
1663 + if ( $thisObj.hasClass( 'disabled' ) ) {
1664 + return false;
1665 + }
1666 +
1667 + var $button = $thisObj.closest( '.frmbutton' );
1668 + var fieldType = $button.attr( 'id' );
1669 +
1670 + var hasBreak = 0;
1671 + if ( 'summary' === fieldType ) {
1672 + // We'll optimistically disable $button now. We'll re-enable if AJAX fails
1673 + disableSummaryBtnBeforeAJAX( $thisObj, $button );
1674 +
1675 + hasBreak = $newFields.children( 'li[data-type="break"]' ).length > 0 ? 1 : 0;
1676 + }
1677 +
1678 + var formId = thisFormId;
1679 +
1680 + jQuery.ajax({
1681 + type: 'POST',
1682 + url: ajaxurl,
1683 + data: {
1684 + action: 'frm_insert_field',
1685 + form_id: formId,
1686 + field_type: fieldType,
1687 + section_id: 0,
1688 + nonce: frmGlobal.nonce,
1689 + has_break: hasBreak
1690 + },
1691 + success: function( msg ) {
1692 + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' );
1693 + $newFields.append( wrapFieldLi( msg ) );
1694 + afterAddField( msg, true );
1695 + },
1696 + error: function( jqXHR, textStatus, errorThrown ) {
1697 + maybeReenableSummaryBtnAfterAJAX( fieldType, $thisObj, $button, errorThrown );
1698 + }
1699 + });
1700 + return false;
1701 + }
1702 +
1703 + function disableSummaryBtnBeforeAJAX( addBtn, fieldButton ) {
1704 + addBtn.addClass( 'disabled' );
1705 + fieldButton.draggable( 'disable' );
1706 + }
1707 +
1708 + function reenableAddSummaryBtn() {
1709 + var frmBtn = jQuery( 'li#summary' );
1710 + var addFieldLink = frmBtn.children( '.frm_add_field' );
1711 + frmBtn.draggable( 'enable' );
1712 + addFieldLink.removeClass( 'disabled' );
1713 + }
1714 +
1715 + function maybeDisableAddSummaryBtn() {
1716 + var summary = document.getElementById( 'summary' );
1717 + if ( summary && ! summary.classList.contains( 'frm_show_upgrade' ) && formHasSummaryField() ) {
1718 + disableAddSummaryBtn();
1719 + }
1720 + }
1721 +
1722 + function disableAddSummaryBtn() {
1723 + var frmBtn = jQuery( 'li#summary' );
1724 + var addFieldLink = frmBtn.children( '.frm_add_field' );
1725 + frmBtn.draggable( 'disable' );
1726 + addFieldLink.addClass( 'disabled' );
1727 + }
1728 +
1729 + function maybeReenableSummaryBtnAfterAJAX( fieldType, addBtn, fieldButton, errorThrown ) {
1730 + infoModal( errorThrown + '. Please try again.' );
1731 + if ( 'summary' === fieldType ) {
1732 + addBtn.removeClass( 'disabled' );
1733 + fieldButton.draggable( 'enable' );
1734 + }
1735 + }
1736 +
1737 + function formHasSummaryField() {
1738 + // .edit_field_type_summary is a better selector here in order to also cover fields loaded by AJAX
1739 + return $newFields.children( 'li.edit_field_type_summary' ).length > 0;
1740 + }
1741 +
1742 + function maybeHideQuantityProductFieldOption() {
1743 + var hide = true,
1744 + opts = document.querySelectorAll( '.frmjs_prod_field_opt_cont' );
1745 +
1746 + if ( $newFields.find( 'li.edit_field_type_product' ).length > 1 ) {
1747 + hide = false;
1748 + }
1749 +
1750 + for ( var i = 0; i < opts.length; i++ ) {
1751 + if ( hide ) {
1752 + opts[ i ].classList.add( 'frm_hidden' );
1753 + } else {
1754 + opts[ i ].classList.remove( 'frm_hidden' );
1755 + }
1756 + }
1757 + }
1758 +
1759 + function duplicateField() {
1760 + var $field, fieldId, children, newRowId, fieldOrder;
1761 +
1762 + $field = jQuery( this ).closest( 'li.form-field' );
1763 +
1764 + if ( $field.hasClass( 'frm-section-collapsed' ) || $field.hasClass( 'frm-page-collapsed' ) ) {
1765 + return false;
1766 + }
1767 +
1768 + closeOpenFieldDropdowns();
1769 +
1770 + fieldId = $field.data( 'fid' );
1771 + children = fieldsInSection( fieldId );
1772 + newRowId = this.getAttribute( 'frm-target-row-id' );
1773 +
1774 + if ( null !== newRowId ) {
1775 + fieldOrder = this.getAttribute( 'frm-field-order' );
1776 + }
1777 +
1778 + jQuery.ajax({
1779 + type: 'POST',
1780 + url: ajaxurl,
1781 + data: {
1782 + action: 'frm_duplicate_field',
1783 + field_id: fieldId,
1784 + form_id: thisFormId,
1785 + children: children,
1786 + nonce: frmGlobal.nonce
1787 + },
1788 + success: function( msg ) {
1789 + var newRow;
1790 +
1791 + if ( null !== newRowId ) {
1792 + newRow = document.getElementById( newRowId );
1793 + if ( null !== newRow ) {
1794 + jQuery( newRow ).append( msg );
1795 + if ( null !== fieldOrder ) {
1796 + newRow.lastElementChild.setAttribute( 'frm-field-order', fieldOrder );
1797 + }
1798 + jQuery( newRow ).trigger(
1799 + 'frm_added_duplicated_field_to_row',
1800 + {
1801 + duplicatedFieldHtml: msg,
1802 + originalFieldId: fieldId
1803 + }
1804 + );
1805 + afterAddField( msg, false );
1806 + return;
1807 + }
1808 + }
1809 +
1810 + if ( $field.siblings( 'li.form-field' ).length ) {
1811 + $field.after( msg );
1812 + syncLayoutClasses( $field );
1813 + } else {
1814 + $field.parent().parent().after( wrapFieldLi( msg ) );
1815 + }
1816 +
1817 + updateFieldOrder();
1818 + afterAddField( msg, false );
1819 + maybeDuplicateUnsavedSettings( fieldId, msg );
1820 + }
1821 + });
1822 + return false;
1823 + }
1824 +
1825 + function maybeDuplicateUnsavedSettings( originalFieldId, newFieldHtml ) {
1826 + var originalSettings, newFieldId, copySettings, fieldOptionKeys, originalDefault, copyDefault;
1827 +
1828 + originalSettings = document.getElementById( 'frm-single-settings-' + originalFieldId );
1829 + if ( null === originalSettings ) {
1830 + return;
1831 + }
1832 +
1833 + newFieldId = jQuery( newFieldHtml ).attr( 'data-fid' );
1834 + if ( 'undefined' === typeof newFieldId ) {
1835 + return;
1836 + }
1837 +
1838 + copySettings = document.getElementById( 'frm-single-settings-' + newFieldId );
1839 + if ( null === copySettings ) {
1840 + return;
1841 + }
1842 +
1843 + fieldOptionKeys = [
1844 + 'name', 'required', 'unique', 'read_only', 'placeholder', 'description', 'size', 'max', 'format', 'prepend', 'append', 'separate_value'
1845 + ];
1846 +
1847 + originalSettings.querySelectorAll( 'input[name^="field_options["], textarea[name^="field_options["]' ).forEach(
1848 + function( originalSetting ) {
1849 + var key, tagType, copySetting;
1850 +
1851 + key = getKeyFromSettingInput( originalSetting );
1852 +
1853 + if ( 'options' === key ) {
1854 + copyOption( originalSetting, copySettings, originalFieldId, newFieldId );
1855 + return;
1856 + }
1857 +
1858 + if ( -1 === fieldOptionKeys.indexOf( key ) ) {
1859 + return;
1860 + }
1861 +
1862 + tagType = originalSetting.matches( 'input' ) ? 'input' : 'textarea';
1863 + copySetting = copySettings.querySelector( tagType + '[name="field_options[' + key + '_' + newFieldId + ']"]' );
1864 + if ( null === copySetting ) {
1865 + return;
1866 + }
1867 +
1868 + if ( 'checkbox' === originalSetting.type ) {
1869 + if ( originalSetting.checked !== copySetting.checked ) {
1870 + jQuery( copySetting ).trigger( 'click' );
1871 + }
1872 + } else if ( 'text' === originalSetting.type || 'textarea' === tagType ) {
1873 + if ( originalSetting.value !== copySetting.value ) {
1874 + copySetting.value = originalSetting.value;
1875 + jQuery( copySetting ).trigger( 'change' );
1876 + }
1877 + }
1878 + }
1879 + );
1880 +
1881 + originalDefault = originalSettings.querySelector( 'input[name="default_value_' + originalFieldId + '"]' );
1882 + if ( null !== originalDefault ) {
1883 + copyDefault = copySettings.querySelector( 'input[name="default_value_' + newFieldId + '"]' );
1884 + if ( null !== copyDefault && originalDefault.value !== copyDefault.value ) {
1885 + copyDefault.value = originalDefault.value;
1886 + jQuery( copyDefault ).trigger( 'change' );
1887 + }
1888 + }
1889 + }
1890 +
1891 + function copyOption( originalSetting, copySettings, originalFieldId, newFieldId ) {
1892 + var remainingKeyDetails, copyKey, copySetting;
1893 + remainingKeyDetails = originalSetting.name.substr( 23 + ( '' + originalFieldId ).length );
1894 + copyKey = 'field_options[options_' + newFieldId + ']' + remainingKeyDetails;
1895 + copySetting = copySettings.querySelector( 'input[name="' + copyKey + '"]' );
1896 + if ( null !== copySetting && copySetting.value !== originalSetting.value ) {
1897 + copySetting.value = originalSetting.value;
1898 + jQuery( copySetting ).trigger( 'change' );
1899 + }
1900 + }
1901 +
1902 + function getKeyFromSettingInput( input ) {
1903 + var nameWithoutPrefix, nameSplit;
1904 + nameWithoutPrefix = input.name.substr( 14 );
1905 + nameSplit = nameWithoutPrefix.split( '_' );
1906 + nameSplit.pop();
1907 + return nameSplit.join( '_' );
1908 + }
1909 +
1910 + function closeOpenFieldDropdowns() {
1911 + var openSettings = document.querySelector( '.frm-field-settings-open' );
1912 + if ( null !== openSettings ) {
1913 + openSettings.classList.remove( 'frm-field-settings-open' );
1914 + jQuery( document ).off( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings );
1915 + jQuery( '.frm-field-action-icons .dropdown.open' ).removeClass( 'open' );
1916 + }
1917 + }
1918 +
1919 + function handleClickOutsideOfFieldSettings( event ) {
1920 + if ( ! jQuery( event.originalEvent.target ).closest( '.frm-field-action-icons' ).length ) {
1921 + closeOpenFieldDropdowns();
1922 + }
1923 + }
1924 +
1925 + function checkForMultiselectKeysOnMouseMove( event ) {
1926 + var keyIsDown = ! ! ( event.ctrlKey || event.metaKey || event.shiftKey );
1927 + jQuery( document.getElementById( 'frm_builder_page' ) ).toggleClass( 'frm-multiselect-key-is-down', keyIsDown );
1928 + checkForActiveHoverTarget( event );
1929 + }
1930 +
1931 + function checkForActiveHoverTarget( event ) {
1932 + var container, elementFromPoint, list, previousHoverTarget;
1933 +
1934 + container = document.getElementById( 'post-body-content' );
1935 + if ( container.classList.contains( 'frm-dragging-field' ) ) {
1936 + return;
1937 + }
1938 +
1939 + if ( null !== document.querySelector( '.frm-field-group-hover-target .frm-field-settings-open' ) ) {
1940 + // do not set a hover target if a dropdown is open for the current hover target.
1941 + return;
1942 + }
1943 +
1944 + elementFromPoint = document.elementFromPoint( event.clientX, event.clientY );
1945 + if ( null !== elementFromPoint && ! elementFromPoint.classList.contains( 'edit_field_type_divider' ) ) {
1946 +
1947 + list = elementFromPoint.closest( 'ul.frm_sorting' );
1948 +
1949 + if ( null !== list && ! list.classList.contains( 'start_divider' ) && 'frm-show-fields' !== list.id ) {
1950 + previousHoverTarget = maybeRemoveGroupHoverTarget();
1951 + if ( false !== previousHoverTarget && ! jQuery( previousHoverTarget ).is( list ) ) {
1952 + destroyFieldGroupPopup();
1953 + }
1954 + updateFieldGroupControls( jQuery( list ), getFieldsInRow( jQuery( list ) ).length );
1955 + list.classList.add( 'frm-field-group-hover-target' );
1956 + jQuery( '#wpbody-content' ).on( 'mousemove', maybeRemoveHoverTargetOnMouseMove );
1957 + }
1958 + }
1959 + }
1960 +
1961 + function maybeRemoveGroupHoverTarget() {
1962 + var controls, previousHoverTarget;
1963 +
1964 + controls = document.getElementById( 'frm_field_group_controls' );
1965 + if ( null !== controls ) {
1966 + controls.style.display = 'none';
1967 + }
1968 +
1969 + previousHoverTarget = document.querySelector( '.frm-field-group-hover-target' );
1970 + if ( null === previousHoverTarget ) {
1971 + return false;
1972 + }
1973 +
1974 + jQuery( '#wpbody-content' ).off( 'mousemove', maybeRemoveHoverTargetOnMouseMove );
1975 + previousHoverTarget.classList.remove( 'frm-field-group-hover-target' );
1976 + return previousHoverTarget;
1977 + }
1978 +
1979 + function maybeRemoveHoverTargetOnMouseMove( event ) {
1980 + var elementFromPoint = document.elementFromPoint( event.clientX, event.clientY );
1981 + if ( null !== elementFromPoint && null !== elementFromPoint.closest( '#frm-show-fields' ) ) {
1982 + return;
1983 + }
1984 + maybeRemoveGroupHoverTarget();
1985 + }
1986 +
1987 + function onFieldActionDropdownShow( isFieldGroup ) {
1988 + unselectFieldGroups();
1989 + // maybe offset the dropdown if it goes off of the right of the screen.
1990 + setTimeout(
1991 + function() {
1992 + var ul, $ul;
1993 + ul = document.querySelector( '.dropdown.open ul' );
1994 + if ( null === ul ) {
1995 + return;
1996 + }
1997 + if ( null === ul.getAttribute( 'aria-label' ) ) {
1998 + ul.setAttribute( 'aria-label', __( 'More Options', 'formidable' ) );
1999 + }
2000 + if ( 0 === ul.children.length ) {
2001 + fillFieldActionDropdown( ul, true === isFieldGroup );
2002 + }
2003 + $ul = jQuery( ul );
2004 + if ( $ul.offset().left > jQuery( window ).width() - $ul.outerWidth() ) {
2005 + ul.style.left = ( -$ul.outerWidth() ) + 'px';
2006 + }
2007 + const firstAnchor = ul.firstElementChild.querySelector( 'a' );
2008 + if ( firstAnchor ) {
2009 + firstAnchor.focus();
2010 + }
2011 + },
2012 + 0
2013 + );
2014 + }
2015 +
2016 + function onFieldGroupActionDropdownShow() {
2017 + onFieldActionDropdownShow( true );
2018 + }
2019 +
2020 + function fillFieldActionDropdown( ul, isFieldGroup ) {
2021 + var classSuffix, options;
2022 + classSuffix = isFieldGroup ? '_field_group' : '_field';
2023 + options = [ getDeleteActionOption( isFieldGroup ), getDuplicateActionOption( isFieldGroup ) ];
2024 + if ( ! isFieldGroup ) {
2025 + options.push(
2026 + { class: 'frm_select', icon: 'frm_settings_icon', label: __( 'Field settings', 'formidable' ) }
2027 + );
2028 + }
2029 + options.forEach(
2030 + function( option ) {
2031 + var li, anchor, span;
2032 + li = document.createElement( 'li' );
2033 + li.classList.add( 'frm_dropdown_li', 'frm_more_options_li' );
2034 +
2035 + anchor = document.createElement( 'a' );
2036 + anchor.classList.add( option.class + classSuffix );
2037 + anchor.setAttribute( 'href', '#' );
2038 + makeTabbable( anchor );
2039 +
2040 + span = document.createElement( 'span' );
2041 + span.textContent = option.label;
2042 + anchor.innerHTML = '<svg class="frmsvg"><use xlink:href="#' + option.icon + '"></use></svg>';
2043 + anchor.appendChild( document.createTextNode( ' ' ) );
2044 + anchor.appendChild( span );
2045 +
2046 + li.appendChild( anchor );
2047 + ul.appendChild( li );
2048 + }
2049 + );
2050 + }
2051 +
2052 + function getDeleteActionOption( isFieldGroup ) {
2053 + var option = { class: 'frm_delete', icon: 'frm_delete_icon' };
2054 + option.label = isFieldGroup ? __( 'Delete Group', 'formidable' ) : __( 'Delete', 'formidable' );
2055 + return option;
2056 + }
2057 +
2058 + function getDuplicateActionOption( isFieldGroup ) {
2059 + var option = { class: 'frm_clone', icon: 'frm_clone_icon' };
2060 + option.label = isFieldGroup ? __( 'Duplicate Group', 'formidable' ) : __( 'Duplicate', 'formidable' );
2061 + return option;
2062 + }
2063 +
2064 + function wrapFieldLi( li ) {
2065 + return jQuery( '<li>' )
2066 + .addClass( 'frm_field_box' )
2067 + .html(
2068 + jQuery( '<ul>' ).addClass( 'frm_grid_container frm_sorting' ).append( li )
2069 + );
2070 + }
2071 +
2072 + function wrapFieldLiInPlace( li ) {
2073 + jQuery( li ).wrap( '<li class="frm_field_box"><ul class="frm_grid_container frm_sorting"></ul></li>' );
2074 + }
2075 +
2076 + function afterAddField( msg, addFocus ) {
2077 + var regex = /id="(\S+)"/,
2078 + match = regex.exec( msg ),
2079 + field = document.getElementById( match[1]),
2080 + section = '#' + match[1] + '.edit_field_type_divider ul.frm_sorting.start_divider',
2081 + $thisSection = jQuery( section ),
2082 + type = field.getAttribute( 'data-type' ),
2083 + toggled = false,
2084 + $parentSection;
2085 +
2086 + setupSortable( section );
2087 +
2088 + if ( 'quantity' === type ) {
2089 + // try to automatically attach a product field
2090 + maybeSetProductField( field );
2091 + }
2092 +
2093 + if ( 'product' === type || 'quantity' === type ) {
2094 + // quantity too needs to be a part of the if stmt especially cos of the very
2095 + // 1st quantity field (or even if it's just one quantity field in the form).
2096 + maybeHideQuantityProductFieldOption();
2097 + }
2098 +
2099 + if ( $thisSection.length ) {
2100 + $thisSection.parent( '.frm_field_box' ).children( '.frm_no_section_fields' ).addClass( 'frm_block' );
2101 + } else {
2102 + $parentSection = jQuery( field ).closest( 'ul.frm_sorting.start_divider' );
2103 + if ( $parentSection.length ) {
2104 + toggleOneSectionHolder( $parentSection );
2105 + toggled = true;
2106 + }
2107 + }
2108 +
2109 + if ( msg.indexOf( 'frm-collapse-page' ) !== -1 ) {
2110 + renumberPageBreaks();
2111 + }
2112 +
2113 + addClass( field, 'frm-newly-added' );
2114 + setTimeout( function() {
2115 + field.classList.remove( 'frm-newly-added' );
2116 + }, 1000 );
2117 +
2118 + if ( addFocus ) {
2119 + var bounding = field.getBoundingClientRect(),
2120 + container = document.getElementById( 'post-body-content' ),
2121 + inView = ( bounding.top >= 0 &&
2122 + bounding.left >= 0 &&
2123 + bounding.right <= ( window.innerWidth || document.documentElement.clientWidth ) &&
2124 + bounding.bottom <= ( window.innerHeight || document.documentElement.clientHeight )
2125 + );
2126 +
2127 + if ( ! inView ) {
2128 + container.scroll({
2129 + top: container.scrollHeight,
2130 + left: 0,
2131 + behavior: 'smooth'
2132 + });
2133 + }
2134 +
2135 + if ( toggled === false ) {
2136 + toggleOneSectionHolder( $thisSection );
2137 + }
2138 + }
2139 +
2140 + deselectFields();
2141 + initiateMultiselect();
2142 +
2143 + const addedEvent = new Event( 'frm_added_field', { bubbles: false });
2144 + addedEvent.frmField = field;
2145 + addedEvent.frmSection = section;
2146 + addedEvent.frmType = type;
2147 + addedEvent.frmToggles = toggled;
2148 + document.dispatchEvent( addedEvent );
2149 + }
2150 +
2151 + function clearSettingsBox( preventFieldGroups ) {
2152 + jQuery( '#new_fields .frm-single-settings' ).addClass( 'frm_hidden' );
2153 + jQuery( '#frm-options-panel > .frm-single-settings' ).removeClass( 'frm_hidden' );
2154 + deselectFields( preventFieldGroups );
2155 + }
2156 +
2157 + function deselectFields( preventFieldGroups ) {
2158 + jQuery( 'li.ui-state-default.selected' ).removeClass( 'selected' );
2159 + if ( ! preventFieldGroups ) {
2160 + unselectFieldGroups();
2161 + }
2162 + }
2163 +
2164 + function scrollToField( field ) {
2165 + var newPos = field.getBoundingClientRect().top,
2166 + container = document.getElementById( 'post-body-content' );
2167 +
2168 + if ( typeof animate === 'undefined' ) {
2169 + jQuery( container ).scrollTop( newPos );
2170 + } else {
2171 + // TODO: smooth scroll
2172 + jQuery( container ).animate({ scrollTop: newPos }, 500 );
2173 + }
2174 + }
2175 +
2176 + function checkCalculationCreatedByUser() {
2177 + var calculation = this.value;
2178 + var warningMessage = checkMatchingParens( calculation );
2179 + warningMessage += checkShortcodes( calculation, this );
2180 +
2181 + if ( warningMessage !== '' ) {
2182 + infoModal( calculation + '\n\n' + warningMessage );
2183 + }
2184 + }
2185 +
2186 + /**
2187 + * Checks the Detail Page slug to see if it's a reserved word and displays a message if it is.
2188 + */
2189 + function checkDetailPageSlug() {
2190 + var slug = jQuery( '#param' ).val(),
2191 + msg;
2192 + slug = slug.trim().toLowerCase();
2193 + if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( slug ) ) {
2194 + msg = frm_admin_js.slug_is_reserved;
2195 + msg = msg.replace( '****', addHtmlTags( slug, 'strong' ) );
2196 + msg += '<br /><br />';
2197 + msg += addHtmlTags( '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>', 'div' );
2198 + infoModal( msg );
2199 + }
2200 + }
2201 +
2202 + /**
2203 + * Checks View filter value for params named with reserved words and displays a message if any are found.
2204 + */
2205 + function checkFilterParamNames() {
2206 + var regEx = /\[\s*get\s*param\s*=\s*['"]?([a-zA-Z-_]+)['"]?/ig,
2207 + filterValue = jQuery( this ).val(),
2208 + match = regEx.exec( filterValue ),
2209 + unsafeParams = '';
2210 +
2211 + while ( match !== null ) {
2212 + if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( match[1]) ) {
2213 + if ( unsafeParams !== '' ) {
2214 + unsafeParams += '", "' + match[ 1 ];
2215 + } else {
2216 + unsafeParams = match[ 1 ];
2217 + }
2218 + }
2219 + match = regEx.exec( filterValue );
2220 + }
2221 +
2222 + if ( unsafeParams !== '' ) {
2223 + msg = frm_admin_js.param_is_reserved;
2224 + msg = msg.replace( '****', addHtmlTags( unsafeParams, 'strong' ) );
2225 + msg += '<br /><br />';
2226 + msg += ' <a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>';
2227 +
2228 + infoModal( msg );
2229 + }
2230 + }
2231 +
2232 + function addHtmlTags( text, tag ) {
2233 + tag = tag ? tag : 'p';
2234 + return '<' + tag + '>' + text + '</' + tag + '>';
2235 + }
2236 +
2237 + /**
2238 + * Checks a string for parens, brackets, and curly braces and returns a message if any unmatched are found.
2239 + * @param formula
2240 + * @returns {string}
2241 + */
2242 + function checkMatchingParens( formula ) {
2243 +
2244 + var stack = [],
2245 + formulaArray = formula.split( '' ),
2246 + length = formulaArray.length,
2247 + opening = [ '{', '[', '(' ],
2248 + closing = {
2249 + '}': '{',
2250 + ')': '(',
2251 + ']': '['
2252 + },
2253 + unmatchedClosing = [],
2254 + msg = '',
2255 + i, top;
2256 +
2257 + for ( i = 0; i < length; i++ ) {
2258 + if ( opening.includes( formulaArray[i]) ) {
2259 + stack.push( formulaArray[i]);
2260 + continue;
2261 + }
2262 + if ( closing.hasOwnProperty( formulaArray[i]) ) {
2263 + top = stack.pop();
2264 + if ( top !== closing[formulaArray[i]]) {
2265 + unmatchedClosing.push( formulaArray[i]);
2266 + }
2267 + }
2268 + }
2269 +
2270 + if ( stack.length > 0 || unmatchedClosing.length > 0 ) {
2271 + msg = frm_admin_js.unmatched_parens + '\n\n';
2272 + return msg;
2273 + }
2274 +
2275 + return '';
2276 + }
2277 +
2278 + /**
2279 + * Checks a calculation for shortcodes that shouldn't be in it and returns a message if found.
2280 + * @param calculation
2281 + * @param inputElement
2282 + * @returns {string}
2283 + */
2284 + function checkShortcodes( calculation, inputElement ) {
2285 + var msg = checkNonNumericShortcodes( calculation, inputElement );
2286 + msg += checkNonFormShortcodes( calculation );
2287 +
2288 + return msg;
2289 + }
2290 +
2291 + /**
2292 + * Checks if a numeric calculation has shortcodes that output non-numeric strings and returns a message if found.
2293 + * @param calculation
2294 + *
2295 + * @param inputElement
2296 + * @returns {string}
2297 + */
2298 + function checkNonNumericShortcodes( calculation, inputElement ) {
2299 +
2300 + var msg = '';
2301 +
2302 + if ( isTextCalculation( inputElement ) ) {
2303 + return msg;
2304 + }
2305 +
2306 + var nonNumericShortcodes = getNonNumericShortcodes();
2307 +
2308 + if ( nonNumericShortcodes.test( calculation ) ) {
2309 + msg = frm_admin_js.text_shortcodes + '\n\n';
2310 + }
2311 +
2312 + return msg;
2313 + }
2314 +
2315 + /**
2316 + * Determines if the calculation input is from a text calculation.
2317 + *
2318 + * @param inputElement
2319 + */
2320 + function isTextCalculation( inputElement ) {
2321 + return jQuery( inputElement ).siblings( 'label[for^="calc_type"]' ).children( 'input' ).prop( 'checked' );
2322 + }
2323 +
2324 + /**
2325 + * Returns a regular expression of shortcodes that can't be used in numeric calculations.
2326 + * @returns {RegExp}
2327 + */
2328 + function getNonNumericShortcodes() {
2329 + return /\[(date|time|email|ip)\]/;
2330 + }
2331 +
2332 + /**
2333 + * Checks if a string has any shortcodes that do not belong in forms and returns a message if any are found.
2334 + * @param formula
2335 + * @returns {string}
2336 + */
2337 + function checkNonFormShortcodes( formula ) {
2338 + var nonFormShortcodes = getNonFormShortcodes(),
2339 + msg = '';
2340 +
2341 + if ( nonFormShortcodes.test( formula ) ) {
2342 + msg += frm_admin_js.view_shortcodes + '\n\n';
2343 + }
2344 +
2345 + return msg;
2346 + }
2347 +
2348 + /**
2349 + * Returns a regular expression of shortcodes that can't be used in forms but can be used in Views, Email
2350 + * Notifications, and other Formidable areas.
2351 + *
2352 + * @returns {RegExp}
2353 + */
2354 + function getNonFormShortcodes() {
2355 + return /\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g;
2356 + }
2357 +
2358 + function isCalcBoxType( box, listClass ) {
2359 + var list = jQuery( box ).find( '.frm_code_list' );
2360 + return 1 === list.length && list.hasClass( listClass );
2361 + }
2362 +
2363 + function extractExcludedOptions( exclude ) {
2364 + var opts = [];
2365 + if ( ! Array.isArray( exclude ) ) {
2366 + return opts;
2367 + }
2368 +
2369 + for ( var i = 0; i < exclude.length; i++ ) {
2370 + if ( exclude[ i ].startsWith( '[' ) ) {
2371 + opts.push( exclude[ i ]);
2372 + // remove it
2373 + exclude.splice( i, 1 );
2374 + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value
2375 + i--;
2376 + }
2377 + }
2378 +
2379 + return opts;
2380 + }
2381 +
2382 + function hasExcludedOption( field, excludedOpts ) {
2383 + var hasOption = false;
2384 + for ( var i = 0; i < excludedOpts.length; i++ ) {
2385 + var inputs = document.getElementsByName( getFieldOptionInputName( excludedOpts[ i ], field.fieldId ) );
2386 + // 2nd condition checks that there's at least one non-empty value
2387 + if ( inputs.length && jQuery( inputs[0]).val() ) {
2388 + hasOption = true;
2389 + break;
2390 + }
2391 + }
2392 + return hasOption;
2393 + }
2394 +
2395 + function getFieldOptionInputName( opt, fieldId ) {
2396 + var at = opt.indexOf( ']' );
2397 + return 'field_options' + opt.substring( 0, at ) + '_' + fieldId + opt.substring( at );
2398 + }
2399 +
2400 + function popCalcFields( v, force ) {
2401 + var box, exclude, fields, i, list,
2402 + p = jQuery( v ).closest( '.frm-single-settings' ),
2403 + calc = p.find( '.frm-calc-field' );
2404 +
2405 + if ( ! force && ( ! calc.length || calc.val() === '' || calc.is( ':hidden' ) ) ) {
2406 + return;
2407 + }
2408 +
2409 + var isSummary = isCalcBoxType( v, 'frm_js_summary_list' );
2410 +
2411 + var fieldId = p.find( 'input[name="frm_fields_submitted[]"]' ).val();
2412 +
2413 + if ( force ) {
2414 + box = v;
2415 + } else {
2416 + box = document.getElementById( 'frm-calc-box-' + fieldId );
2417 + }
2418 +
2419 + exclude = getExcludeArray( box, isSummary );
2420 + var excludedOpts = extractExcludedOptions( exclude );
2421 +
2422 + fields = getFieldList();
2423 + list = document.getElementById( 'frm-calc-list-' + fieldId );
2424 + list.innerHTML = '';
2425 +
2426 + for ( i = 0; i < fields.length; i++ ) {
2427 + if ( ( exclude && exclude.includes( fields[ i ].fieldType ) ) ||
2428 + ( excludedOpts.length && hasExcludedOption( fields[ i ], excludedOpts ) ) ) {
2429 + continue;
2430 + }
2431 +
2432 + var span = document.createElement( 'span' );
2433 + span.appendChild( document.createTextNode( '[' + fields[i].fieldId + ']' ) );
2434 +
2435 + var a = document.createElement( 'a' );
2436 + a.setAttribute( 'href', '#' );
2437 + a.setAttribute( 'data-code', fields[i].fieldId );
2438 + a.classList.add( 'frm_insert_code' );
2439 + a.appendChild( span );
2440 + a.appendChild( document.createTextNode( fields[i].fieldName ) );
2441 +
2442 + var li = document.createElement( 'li' );
2443 + li.classList.add( 'frm-field-list-' + fieldId );
2444 + li.classList.add( 'frm-field-list-' + fields[i].fieldType );
2445 + li.appendChild( a );
2446 + list.appendChild( li );
2447 + }
2448 + }
2449 +
2450 + function getExcludeArray( calcBox, isSummary ) {
2451 + var exclude = JSON.parse( calcBox.getElementsByClassName( 'frm_code_list' )[0].getAttribute( 'data-exclude' ) );
2452 +
2453 + if ( isSummary ) {
2454 + // includedExtras are those that are normally excluded from the summary but the form owner can choose to include,
2455 + // when they have been chosen to be included, then they can now be manually excluded in the calc box.
2456 + var includedExtras = getIncludedExtras();
2457 + if ( includedExtras.length ) {
2458 + for ( var i = 0; i < exclude.length; i++ ) {
2459 + if ( includedExtras.includes( exclude[ i ]) ) {
2460 + // remove it
2461 + exclude.splice( i, 1 );
2462 + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value
2463 + i--;
2464 + }
2465 + }
2466 + }
2467 + }
2468 +
2469 + return exclude;
2470 + }
2471 +
2472 + function getIncludedExtras() {
2473 + var checked = [];
2474 + var checkboxes = document.getElementsByClassName( 'frm_include_extras_field' );
2475 +
2476 + for ( var i = 0; i < checkboxes.length; i++ ) {
2477 + if ( checkboxes[i].checked ) {
2478 + checked.push( checkboxes[i].value );
2479 + }
2480 + }
2481 +
2482 + return checked;
2483 + }
2484 +
2485 + function rePopCalcFieldsForSummary() {
2486 + popCalcFields( jQuery( '.frm-inline-modal.postbox:has(.frm_js_summary_list)' )[0], true );
2487 + }
2488 +
2489 + function getFieldList( fieldType ) {
2490 + var i,
2491 + fields = [],
2492 + allFields = document.querySelectorAll( 'li.frm_field_box' ),
2493 + checkType = 'undefined' !== typeof fieldType;
2494 +
2495 + for ( i = 0; i < allFields.length; i++ ) {
2496 + // data-ftype is better (than data-type) cos of fields loaded by AJAX - which might not be ready yet
2497 + if ( checkType && allFields[ i ].getAttribute( 'data-ftype' ) !== fieldType ) {
2498 + continue;
2499 + }
2500 +
2501 + var fieldId = allFields[ i ].getAttribute( 'data-fid' );
2502 + if ( typeof fieldId !== 'undefined' && fieldId ) {
2503 + fields.push({
2504 + 'fieldId': fieldId,
2505 + 'fieldName': getPossibleValue( 'frm_name_' + fieldId ),
2506 + 'fieldType': getPossibleValue( 'field_options_type_' + fieldId ),
2507 + 'fieldKey': getPossibleValue( 'field_options_field_key_' + fieldId )
2508 + });
2509 + }
2510 + }
2511 +
2512 + return fields;
2513 + }
2514 +
2515 + function popProductFields( field ) {
2516 + var i, checked, id,
2517 + options = [],
2518 + current = getCurrentProductFields( field ),
2519 + fName = field.getAttribute( 'data-frmfname' ),
2520 + products = getFieldList( 'product' ),
2521 + quantities = getFieldList( 'quantity' ),
2522 + isSelect = field.tagName === 'SELECT', // for reverse compatibility.
2523 + // whether we have just 1 product and 1 quantity field & should therefore attach the latter to the former
2524 + auto = 1 === quantities.length && 1 === products.length;
2525 +
2526 + if ( isSelect ) {
2527 + // This fallback can be removed after 4.05.
2528 + current = field.getAttribute( 'data-frmcurrent' );
2529 + }
2530 +
2531 + for ( i = 0 ; i < products.length ; i++ ) {
2532 + // let's be double sure it's string, else indexOf will fail
2533 + id = products[ i ].fieldId.toString();
2534 + checked = auto || -1 !== current.indexOf( id );
2535 + if ( isSelect ) {
2536 + // This fallback can be removed after 4.05.
2537 + checked = checked ? ' selected' : '';
2538 + options.push( '<option value="' + id + '"' + checked + '>' + products[ i ].fieldName + '</option>' );
2539 + } else {
2540 + checked = checked ? ' checked' : '';
2541 + options.push( '<label class="frm6">' );
2542 + options.push( '<input type="checkbox" name="' + fName + '" value="' + id + '"' + checked + '> ' + products[ i ].fieldName );
2543 + options.push( '</label>' );
2544 + }
2545 + }
2546 +
2547 + field.innerHTML = options.join( '' );
2548 + }
2549 +
2550 + function getCurrentProductFields( prodFieldOpt ) {
2551 + var products = prodFieldOpt.querySelectorAll( '[type="checkbox"]:checked' ),
2552 + idsArray = [];
2553 +
2554 + for ( var i = 0; i < products.length; i++ ) {
2555 + idsArray.push( products[ i ].value );
2556 + }
2557 +
2558 + return idsArray;
2559 + }
2560 +
2561 + function popAllProductFields() {
2562 + var opts = document.querySelectorAll( '.frmjs_prod_field_opt' );
2563 + for ( var i = 0; i < opts.length; i++ ) {
2564 + popProductFields( opts[ i ]);
2565 + }
2566 + }
2567 +
2568 + function maybeSetProductField( field ) {
2569 + var fieldId = field.getAttribute( 'data-fid' ),
2570 + productFieldOpt = document.getElementById( 'field_options[product_field_' + fieldId + ']' );
2571 +
2572 + if ( null === productFieldOpt ) {
2573 + return;
2574 + }
2575 +
2576 + popProductFields( productFieldOpt );
2577 + // in order to move its settings to that LHS panel where
2578 + // the update form resides, else it'll lose this setting
2579 + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) );
2580 + }
2581 +
2582 + /**
2583 + * If the element doesn't exist, use a blank value.
2584 + */
2585 + function getPossibleValue( id ) {
2586 + field = document.getElementById( id );
2587 + if ( field !== null ) {
2588 + return field.value;
2589 + } else {
2590 + return '';
2591 + }
2592 + }
2593 +
2594 + function liveChanges() {
2595 + /*jshint validthis:true */
2596 + var option,
2597 + newValue = this.value,
2598 + changes = document.getElementById( this.getAttribute( 'data-changeme' ) ),
2599 + att = this.getAttribute( 'data-changeatt' );
2600 +
2601 + if ( changes === null ) {
2602 + return;
2603 + }
2604 +
2605 + if ( att !== null ) {
2606 + if ( changes.tagName === 'SELECT' && att === 'placeholder' ) {
2607 + option = changes.options[0];
2608 + if ( option.value === '' ) {
2609 + option.innerHTML = newValue;
2610 + } else {
2611 + // Create a placeholder option if there are no blank values.
2612 + addBlankSelectOption( changes, newValue );
2613 + }
2614 + } else if ( att === 'class' ) {
2615 + changeFieldClass( changes, this );
2616 + } else if ( isSliderField( changes ) ) {
2617 + updateSliderFieldPreview( changes, att, newValue );
2618 + } else {
2619 + changes.setAttribute( att, newValue );
2620 + }
2621 + } else if ( changes.id.indexOf( 'setup-message' ) === 0 ) {
2622 + if ( newValue !== '' ) {
2623 + changes.innerHTML = '<input type="text" value="" disabled />';
2624 + }
2625 + } else {
2626 + changes.innerHTML = newValue;
2627 + if ( changes.classList.contains( 'frm_primary_label' ) && 'break' === changes.nextElementSibling.getAttribute( 'data-ftype' ) ) {
2628 + changes.nextElementSibling.querySelector( '.frm_button_submit' ).textContent = newValue;
2629 + }
2630 + }
2631 + }
2632 +
2633 + function updateSliderFieldPreview( field, att, newValue ) {
2634 + if ( 'value' === att ) {
2635 + if ( '' === newValue ) {
2636 + newValue = getSliderMidpoint( field );
2637 + }
2638 + field.value = newValue;
2639 + } else {
2640 + field.setAttribute( att, newValue );
2641 + }
2642 +
2643 + if ( -1 === [ 'value', 'min', 'max' ].indexOf( att ) ) {
2644 + return;
2645 + }
2646 +
2647 + if ( ( 'max' === att || 'min' === att ) && '' === getSliderDefaultValueInput( field.id ) ) {
2648 + field.value = getSliderMidpoint( field );
2649 + }
2650 +
2651 + field.parentNode.querySelector( '.frm_range_value' ).textContent = field.value;
2652 + }
2653 +
2654 + function getSliderDefaultValueInput( previewInputId ) {
2655 + return document.querySelector( 'input[data-changeme="' + previewInputId + '"][data-changeatt="value"]' ).value;
2656 + }
2657 +
2658 + function getSliderMidpoint( sliderInput ) {
2659 + const max = parseFloat( sliderInput.getAttribute( 'max' ) );
2660 + const min = parseFloat( sliderInput.getAttribute( 'min' ) );
2661 + return ( max - min ) / 2 + min;
2662 + }
2663 +
2664 + function isSliderField( previewInput ) {
2665 + return 'range' === previewInput.type && previewInput.parentNode.classList.contains( 'frm_range_container' );
2666 + }
2667 +
2668 + function toggleInvalidMsg() {
2669 + /*jshint validthis:true */
2670 + var typeDropdown, fieldType,
2671 + fieldId = this.id.replace( 'frm_format_', '' ),
2672 + hasValue = this.value !== '';
2673 +
2674 + typeDropdown = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0];
2675 + fieldType = typeDropdown.options[typeDropdown.selectedIndex].value;
2676 +
2677 + if ( fieldType === 'text' ) {
2678 + toggleValidationBox( hasValue, '.frm_invalid_msg' + fieldId );
2679 + }
2680 + }
2681 +
2682 + function markRequired() {
2683 + /*jshint validthis:true */
2684 + var thisid = this.id.replace( 'frm_', '' ),
2685 + fieldId = thisid.replace( 'req_field_', '' ),
2686 + checked = this.checked,
2687 + label = jQuery( '#field_label_' + fieldId + ' .frm_required' );
2688 +
2689 + toggleValidationBox( checked, '.frm_required_details' + fieldId );
2690 +
2691 + if ( checked ) {
2692 + var $reqBox = jQuery( 'input[name="field_options[required_indicator_' + fieldId + ']"]' );
2693 + if ( $reqBox.val() === '' ) {
2694 + $reqBox.val( '*' );
2695 + }
2696 + label.removeClass( 'frm_hidden' );
2697 + } else {
2698 + label.addClass( 'frm_hidden' );
2699 + }
2700 + }
2701 +
2702 + function toggleValidationBox( hasValue, messageClass ) {
2703 + $msg = jQuery( messageClass );
2704 + if ( hasValue ) {
2705 + $msg.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' );
2706 + } else {
2707 + //Fade out validation options
2708 + var v = $msg.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(' + messageClass + '):visible' ).length;
2709 + if ( v === 0 ) {
2710 + $msg.closest( '.frm_validation_msg' ).fadeOut( 'fast' );
2711 + }
2712 + }
2713 + }
2714 +
2715 + function markUnique() {
2716 + /*jshint validthis:true */
2717 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
2718 + var $thisField = jQuery( '.frm_unique_details' + fieldId );
2719 + if ( this.checked ) {
2720 + $thisField.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' );
2721 + $unqDetail = jQuery( '.frm_unique_details' + fieldId + ' input' );
2722 + if ( $unqDetail.val() === '' ) {
2723 + $unqDetail.val( frm_admin_js.default_unique );
2724 + }
2725 + } else {
2726 + var v = $thisField.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(.frm_unique_details' + fieldId + '):visible' ).length;
2727 + if ( v === 0 ) {
2728 + $thisField.closest( '.frm_validation_msg' ).fadeOut( 'fast' );
2729 + }
2730 + }
2731 + }
2732 +
2733 + //Fade confirmation field and validation option in or out
2734 + function addConf() {
2735 + /*jshint validthis:true */
2736 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
2737 + var val = jQuery( this ).val();
2738 + var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) );
2739 +
2740 + toggleValidationBox( val !== '', '.frm_conf_details' + fieldId );
2741 +
2742 + if ( val !== '' ) {
2743 + //Add default validation message if empty
2744 + var valMsg = jQuery( '.frm_validation_box .frm_conf_details' + fieldId + ' input' );
2745 + if ( valMsg.val() === '' ) {
2746 + valMsg.val( frm_admin_js.default_conf );
2747 + }
2748 +
2749 + setConfirmationFieldDescriptions( fieldId );
2750 +
2751 + //Add or remove class for confirmation field styling
2752 + if ( val === 'inline' ) {
2753 + $thisField.removeClass( 'frm_conf_below' ).addClass( 'frm_conf_inline' );
2754 + } else if ( val === 'below' ) {
2755 + $thisField.removeClass( 'frm_conf_inline' ).addClass( 'frm_conf_below' );
2756 + }
2757 + jQuery( '.frm-conf-box-' + fieldId ).removeClass( 'frm_hidden' );
2758 + } else {
2759 + jQuery( '.frm-conf-box-' + fieldId ).addClass( 'frm_hidden' );
2760 + setTimeout( function() {
2761 + $thisField.removeClass( 'frm_conf_inline frm_conf_below' );
2762 + }, 200 );
2763 + }
2764 + }
2765 +
2766 + function setConfirmationFieldDescriptions( fieldId ) {
2767 + var fieldType = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0].value;
2768 +
2769 + var fieldDescription = document.getElementById( 'field_description_' + fieldId );
2770 + var hiddenDescName = 'field_options[description_' + fieldId + ']';
2771 + var newValue = frm_admin_js['enter_' + fieldType];
2772 + maybeSetNewDescription( fieldDescription, hiddenDescName, newValue );
2773 +
2774 + var confFieldDescription = document.getElementById( 'conf_field_description_' + fieldId );
2775 + var hiddenConfName = 'field_options[conf_desc_' + fieldId + ']';
2776 + var newConfValue = frm_admin_js['confirm_' + fieldType];
2777 + maybeSetNewDescription( confFieldDescription, hiddenConfName, newConfValue );
2778 + }
2779 +
2780 + function maybeSetNewDescription( descriptionDiv, hiddenName, newValue ) {
2781 + if ( descriptionDiv.innerHTML === frm_admin_js.desc ) {
2782 +
2783 + // Set the visible description value and the hidden description value
2784 + descriptionDiv.innerHTML = newValue;
2785 + document.getElementsByName( hiddenName )[0].value = newValue;
2786 + }
2787 + }
2788 +
2789 + function initBulkOptionsOverlay() {
2790 + /*jshint validthis:true */
2791 + var $info = initModal( '#frm-bulk-modal', '700px' );
2792 + if ( $info === false ) {
2793 + return;
2794 + }
2795 +
2796 + jQuery( '.frm-insert-preset' ).on( 'click', insertBulkPreset );
2797 +
2798 + jQuery( builderForm ).on( 'click', 'a.frm-bulk-edit-link', function( event ) {
2799 + event.preventDefault();
2800 + var i, key, label,
2801 + content = '',
2802 + optList,
2803 + opts,
2804 + fieldId = jQuery( this ).closest( '[data-fid]' ).data( 'fid' ),
2805 + separate = usingSeparateValues( fieldId ),
2806 + product = isProductField( fieldId );
2807 +
2808 + optList = document.getElementById( 'frm_field_' + fieldId + '_opts' );
2809 + if ( ! optList ) {
2810 + return;
2811 + }
2812 +
2813 + opts = optList.getElementsByTagName( 'li' );
2814 +
2815 + document.getElementById( 'bulk-field-id' ).value = fieldId;
2816 +
2817 + for ( i = 0; i < opts.length; i++ ) {
2818 + key = opts[i].getAttribute( 'data-optkey' );
2819 + if ( key !== '000' ) {
2820 + label = document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][label]' )[0];
2821 + if ( typeof label !== 'undefined' ) {
2822 + content += label.value;
2823 + if ( separate ) {
2824 + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][value]' )[0].value;
2825 + }
2826 + if ( product ) {
2827 + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][price]' )[0].value;
2828 + }
2829 + content += '\r\n';
2830 + }
2831 + }
2832 +
2833 + if ( i >= opts.length - 1 ) {
2834 + document.getElementById( 'frm_bulk_options' ).value = content;
2835 + }
2836 + }
2837 +
2838 + $info.dialog( 'open' );
2839 +
2840 + return false;
2841 + });
2842 +
2843 + jQuery( '#frm-update-bulk-opts' ).on( 'click', function() {
2844 + var fieldId = document.getElementById( 'bulk-field-id' ).value;
2845 + var optionType = document.getElementById( 'bulk-option-type' ).value;
2846 +
2847 + if ( optionType ) {
2848 + // Use custom handler for custom option type.
2849 + return;
2850 + }
2851 +
2852 + this.classList.add( 'frm_loading_button' );
2853 + frmAdminBuild.updateOpts( fieldId, document.getElementById( 'frm_bulk_options' ).value, $info );
2854 + });
2855 + }
2856 +
2857 + function insertBulkPreset( event ) {
2858 + /*jshint validthis:true */
2859 + var opts = JSON.parse( this.getAttribute( 'data-opts' ) );
2860 + event.preventDefault();
2861 + document.getElementById( 'frm_bulk_options' ).value = opts.join( '\n' );
2862 + return false;
2863 + }
2864 +
2865 + //Add new option or "Other" option to radio/checkbox/dropdown
2866 + function addFieldOption() {
2867 + /*jshint validthis:true */
2868 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
2869 + newOption = jQuery( '#frm_field_' + fieldId + '_opts .frm_option_template' ).prop( 'outerHTML' ),
2870 + optType = jQuery( this ).data( 'opttype' ),
2871 + optKey = 0,
2872 + oldKey = '000',
2873 + lastKey = getHighestOptKey( fieldId );
2874 +
2875 + if ( lastKey !== oldKey ) {
2876 + optKey = lastKey + 1;
2877 + }
2878 +
2879 + //Update hidden field
2880 + if ( optType === 'other' ) {
2881 + document.getElementById( 'other_input_' + fieldId ).value = 1;
2882 +
2883 + //Hide "Add Other" option now if this is radio field
2884 + var ftype = jQuery( this ).data( 'ftype' );
2885 + if ( ftype === 'radio' || ftype === 'select' ) {
2886 + jQuery( this ).fadeOut( 'slow' );
2887 + }
2888 +
2889 + var data = {
2890 + action: 'frm_add_field_option',
2891 + field_id: fieldId,
2892 + opt_key: optKey,
2893 + opt_type: optType,
2894 + nonce: frmGlobal.nonce
2895 + };
2896 + jQuery.post( ajaxurl, data, function( msg ) {
2897 + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( msg );
2898 + resetDisplayedOpts( fieldId );
2899 + });
2900 + } else {
2901 + newOption = newOption.replace( new RegExp( 'optkey="' + oldKey + '"', 'g' ), 'optkey="' + optKey + '"' );
2902 + newOption = newOption.replace( new RegExp( '-' + oldKey + '_', 'g' ), '-' + optKey + '_' );
2903 + newOption = newOption.replace( new RegExp( '-' + oldKey + '"', 'g' ), '-' + optKey + '"' );
2904 + newOption = newOption.replace( new RegExp( '\\[' + oldKey + '\\]', 'g' ), '[' + optKey + ']' );
2905 + newOption = newOption.replace( 'frm_hidden frm_option_template', '' );
2906 + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( newOption );
2907 + resetDisplayedOpts( fieldId );
2908 + }
2909 + }
2910 +
2911 + function getHighestOptKey( fieldId ) {
2912 + var i = 0,
2913 + optKey = 0,
2914 + opts = jQuery( '#frm_field_' + fieldId + '_opts li' ),
2915 + lastKey = 0;
2916 +
2917 + for ( i; i < opts.length; i++ ) {
2918 + optKey = opts[i].getAttribute( 'data-optkey' );
2919 + if ( opts.length === 1 ) {
2920 + return optKey;
2921 + }
2922 + if ( optKey !== '000' ) {
2923 + optKey = optKey.replace( 'other_', '' );
2924 + optKey = parseInt( optKey, 10 );
2925 + }
2926 +
2927 + if ( ! isNaN( lastKey ) && ( optKey > lastKey || lastKey === '000' ) ) {
2928 + lastKey = optKey;
2929 + }
2930 + }
2931 +
2932 + return lastKey;
2933 + }
2934 +
2935 + function toggleMultSel() {
2936 + /*jshint validthis:true */
2937 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
2938 + toggleMultiSelect( fieldId, this.value );
2939 + }
2940 +
2941 + function toggleMultiSelect( fieldId, value ) {
2942 + var setting = jQuery( '.frm_multiple_cont_' + fieldId );
2943 + if ( value === 'select' ) {
2944 + setting.fadeIn( 'fast' );
2945 + } else {
2946 + setting.fadeOut( 'fast' );
2947 + }
2948 + }
2949 +
2950 + function toggleSepValues() {
2951 + /*jshint validthis:true */
2952 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
2953 + toggle( jQuery( '.field_' + fieldId + '_option_key' ) );
2954 + jQuery( '.field_' + fieldId + '_option' ).toggleClass( 'frm_with_key' );
2955 + }
2956 +
2957 + function toggleImageOptions() {
2958 + /*jshint validthis:true */
2959 + var hasImageOptions, imageSize,
2960 + $field = jQuery( this ).closest( '.frm-single-settings' ),
2961 + fieldId = $field.data( 'fid' ),
2962 + displayField = document.getElementById( 'frm_field_id_' + fieldId );
2963 +
2964 + refreshOptionDisplayNow( jQuery( this ) );
2965 +
2966 + toggle( jQuery( '.field_' + fieldId + '_image_id' ) );
2967 + toggle( jQuery( '.frm_toggle_image_options_' + fieldId ) );
2968 + toggle( jQuery( '.frm_image_size_' + fieldId ) );
2969 + toggle( jQuery( '.frm_alignment_' + fieldId ) );
2970 + toggle( jQuery( '.frm-add-other#frm_add_field_' + fieldId ) );
2971 +
2972 + hasImageOptions = imagesAsOptions( fieldId );
2973 +
2974 + if ( hasImageOptions ) {
2975 + setAlignment( fieldId, 'inline' );
2976 + removeImageSizeClasses( displayField );
2977 + imageSize = getImageOptionSize( fieldId );
2978 + displayField.classList.add( 'frm_image_options' );
2979 + displayField.classList.add( 'frm_image_size_' + imageSize );
2980 + $field.find( '.frm-bulk-edit-link' ).hide();
2981 + } else {
2982 + displayField.classList.remove( 'frm_image_options' );
2983 + removeImageSizeClasses( displayField );
2984 + setAlignment( fieldId, 'block' );
2985 + $field.find( '.frm-bulk-edit-link' ).show();
2986 + }
2987 + }
2988 +
2989 + function removeImageSizeClasses( field ) {
2990 + field.classList.remove( 'frm_image_size_', 'frm_image_size_small', 'frm_image_size_medium', 'frm_image_size_large', 'frm_image_size_xlarge' );
2991 + }
2992 +
2993 + function setAlignment( fieldId, alignment ) {
2994 + jQuery( '#field_options_align_' + fieldId ).val( alignment ).trigger( 'change' );
2995 + }
2996 +
2997 + function setImageSize() {
2998 + var $field = jQuery( this ).closest( '.frm-single-settings' ),
2999 + fieldId = $field.data( 'fid' ),
3000 + displayField = document.getElementById( 'frm_field_id_' + fieldId );
3001 +
3002 + refreshOptionDisplay();
3003 +
3004 + if ( imagesAsOptions( fieldId ) ) {
3005 + removeImageSizeClasses( displayField );
3006 + displayField.classList.add( 'frm_image_options' );
3007 + displayField.classList.add( 'frm_image_size_' + getImageOptionSize( fieldId ) );
3008 + }
3009 + }
3010 +
3011 + function refreshOptionDisplayNow( object ) {
3012 + var $field = object.closest( '.frm-single-settings' ),
3013 + fieldID = $field.data( 'fid' );
3014 + jQuery( '.field_' + fieldID + '_option' ).trigger( 'change' );
3015 + }
3016 +
3017 + function refreshOptionDisplay() {
3018 + /*jshint validthis:true */
3019 + refreshOptionDisplayNow( jQuery( this ) );
3020 + }
3021 +
3022 + function addImageToOption( event ) {
3023 + var fileFrame,
3024 + $this = jQuery( this ),
3025 + $field = $this.closest( '.frm-single-settings' ),
3026 + $imagePreview = $this.closest( '.frm_image_preview_wrapper' ),
3027 + fieldId = $field.data( 'fid' ),
3028 + postID = 0;
3029 +
3030 + event.preventDefault();
3031 +
3032 + wp.media.model.settings.post.id = postID;
3033 +
3034 + fileFrame = wp.media.frames.file_frame = wp.media({
3035 + multiple: false,
3036 + library: {
3037 + type: [ 'image' ]
3038 + }
3039 + });
3040 +
3041 + fileFrame.on( 'select', function() {
3042 + const attachment = fileFrame.state().get( 'selection' ).first().toJSON();
3043 + $imagePreview.find( 'img' ).attr( 'src', attachment.url );
3044 + $imagePreview.find( '.frm_image_preview_frame' ).show();
3045 + $imagePreview.find( '.frm_image_preview_title' ).text( attachment.filename );
3046 + $imagePreview.siblings( 'input[name*="[label]"]' ).data( 'frmimgurl', attachment.url );
3047 + $imagePreview.find( '.frm_choose_image_box' ).hide();
3048 + $imagePreview.find( 'input.frm_image_id' ).val( attachment.id ).trigger( 'change' );
3049 + wp.media.model.settings.post.id = postID;
3050 + });
3051 +
3052 + fileFrame.open();
3053 + }
3054 +
3055 + function removeImageFromOption( event ) {
3056 + var $this = jQuery( this ),
3057 + $field = $this.closest( '.frm-single-settings' ),
3058 + fieldId = $field.data( 'fid' ),
3059 + previewWrapper = $this.closest( '.frm_image_preview_wrapper' );
3060 +
3061 + event.preventDefault();
3062 + event.stopPropagation();
3063 +
3064 + previewWrapper.find( 'img' ).attr( 'src', '' );
3065 + previewWrapper.find( '.frm_image_preview_frame' ).hide();
3066 + previewWrapper.find( '.frm_choose_image_box' ).show();
3067 + previewWrapper.find( 'input.frm_image_id' ).val( 0 ).trigger( 'change' );
3068 + }
3069 +
3070 + function toggleMultiselect() {
3071 + /*jshint validthis:true */
3072 + var dropdown = jQuery( this ).closest( 'li' ).find( '.frm_form_fields select' );
3073 + if ( this.checked ) {
3074 + dropdown.attr( 'multiple', 'multiple' );
3075 + } else {
3076 + dropdown.removeAttr( 'multiple' );
3077 + }
3078 + }
3079 +
3080 + /**
3081 + * Allow typing on form switcher click without an extra click to search.
3082 + */
3083 + function focusSearchBox() {
3084 + var searchBox = document.getElementById( 'dropform-search-input' );
3085 + if ( searchBox !== null ) {
3086 + setTimeout( function() {
3087 + searchBox.focus();
3088 + }, 100 );
3089 + }
3090 + }
3091 +
3092 + /**
3093 + * If a field is clicked in the builder, prevent inputs from changing.
3094 + */
3095 + function stopFieldFocus( e ) {
3096 + e.preventDefault();
3097 + }
3098 +
3099 + function deleteFieldOption() {
3100 + /*jshint validthis:true */
3101 + var otherInput,
3102 + parentLi = this.parentNode,
3103 + parentUl = parentLi.parentNode,
3104 + fieldId = this.getAttribute( 'data-fid' );
3105 +
3106 + jQuery( parentLi ).fadeOut( 'slow', function() {
3107 + jQuery( parentLi ).remove();
3108 +
3109 + var hasOther = jQuery( parentUl ).find( '.frm_other_option' );
3110 + if ( hasOther.length < 1 ) {
3111 + otherInput = document.getElementById( 'other_input_' + fieldId );
3112 + if ( otherInput !== null ) {
3113 + otherInput.value = 0;
3114 + }
3115 + jQuery( '#other_button_' + fieldId ).fadeIn( 'slow' );
3116 + }
3117 + });
3118 + }
3119 +
3120 + /**
3121 + * If a radio button is set as default, allow a click to
3122 + * deselect it.
3123 + */
3124 + function maybeUncheckRadio() {
3125 + var $self, uncheck, unbind, up;
3126 +
3127 + /*jshint validthis:true */
3128 + $self = jQuery( this );
3129 + if ( $self.is( ':checked' ) ) {
3130 + uncheck = function() {
3131 + setTimeout( function() {
3132 + $self.prop( 'checked', false );
3133 + }, 0 );
3134 + };
3135 + unbind = function() {
3136 + $self.off( 'mouseup', up );
3137 + };
3138 + up = function() {
3139 + uncheck();
3140 + unbind();
3141 + };
3142 + $self.on( 'mouseup', up );
3143 + $self.one( 'mouseout', unbind );
3144 + }
3145 + }
3146 +
3147 + /**
3148 + * If the field option has the default text, clear it out on click.
3149 + */
3150 + function maybeClearOptText() {
3151 + /*jshint validthis:true */
3152 + if ( this.value === frm_admin_js.new_option ) {
3153 + this.setAttribute( 'data-value-on-focus', this.value );
3154 + this.value = '';
3155 + }
3156 + }
3157 +
3158 + function clickDeleteField() {
3159 + /*jshint validthis:true */
3160 + var confirmMsg = frm_admin_js.conf_delete,
3161 + maybeDivider = this.parentNode.parentNode.parentNode.parentNode.parentNode,
3162 + li = maybeDivider.parentNode,
3163 + field = jQuery( this ).closest( 'li.form-field' ),
3164 + fieldId = field.data( 'fid' );
3165 +
3166 + if ( li.classList.contains( 'frm-section-collapsed' ) || li.classList.contains( 'frm-page-collapsed' ) ) {
3167 + return false;
3168 + }
3169 +
3170 + // If deleting a section, use a special message.
3171 + if ( maybeDivider.className === 'divider_section_only' ) {
3172 + confirmMsg = frm_admin_js.conf_delete_sec;
3173 + this.setAttribute( 'data-frmcaution', frm_admin_js.caution );
3174 + }
3175 +
3176 + this.setAttribute( 'data-frmverify', confirmMsg );
3177 + this.setAttribute( 'data-deletefield', fieldId );
3178 +
3179 + closeOpenFieldDropdowns();
3180 +
3181 + confirmLinkClick( this );
3182 + return false;
3183 + }
3184 +
3185 + function clickSelectField() {
3186 + this.closest( 'li.form-field' ).click();
3187 + }
3188 +
3189 + function clickDeleteFieldGroup() {
3190 + var hoverTarget, decoy;
3191 +
3192 + hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3193 + if ( null === hoverTarget ) {
3194 + return;
3195 + }
3196 +
3197 + hoverTarget.classList.add( 'frm-selected-field-group' );
3198 +
3199 + decoy = document.createElement( 'div' );
3200 + decoy.classList.add( 'frm-delete-field-groups', 'frm_hidden' );
3201 + document.body.appendChild( decoy );
3202 + decoy.click();
3203 + }
3204 +
3205 + function duplicateFieldGroup() {
3206 + var hoverTarget, newRowId, $newRow, $fields, syncDetails, expectedLength, duplicatedCount, originalFieldIdByDuplicatedFieldId, injectedCloneOptions;
3207 +
3208 + hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3209 +
3210 + if ( null === hoverTarget ) {
3211 + return;
3212 + }
3213 +
3214 + newRowId = 'frm_field_group_' + getAutoId();
3215 + $newRow = wrapFieldLi( '' );
3216 + $newRowUl = $newRow.find( 'ul' );
3217 + $newRowUl.attr( 'id', newRowId );
3218 + $newRow.addClass( 'frm_hidden' );
3219 + jQuery( hoverTarget ).closest( 'li.frm_field_box' ).after( $newRow );
3220 +
3221 + $fields = getFieldsInRow( jQuery( hoverTarget ) );
3222 + syncDetails = [];
3223 + injectedCloneOptions = [];
3224 +
3225 + expectedLength = $fields.length;
3226 + duplicatedCount = 0;
3227 + originalFieldIdByDuplicatedFieldId = {};
3228 +
3229 + $newRow.on(
3230 + 'frm_added_duplicated_field_to_row',
3231 + function( event, args ) {
3232 + var $duplicatedFields, index;
3233 +
3234 + originalFieldIdByDuplicatedFieldId[ jQuery( args.duplicatedFieldHtml ).attr( 'data-fid' ) ] = args.originalFieldId;
3235 +
3236 + if ( expectedLength > ++duplicatedCount ) {
3237 + return;
3238 + }
3239 +
3240 + $duplicatedFields = getFieldsInRow( $newRowUl );
3241 +
3242 + injectedCloneOptions.forEach(
3243 + function( cloneOption ) {
3244 + cloneOption.remove();
3245 + }
3246 + );
3247 +
3248 + for ( index = 0; index < expectedLength; ++index ) {
3249 + $newRowUl.append( $newRowUl.children( 'li.form-field[frm-field-order="' + index + '"]' ) );
3250 + }
3251 +
3252 + syncLayoutClasses( $duplicatedFields.first(), syncDetails );
3253 + $newRow.removeClass( 'frm_hidden' );
3254 + updateFieldOrder();
3255 +
3256 + getFieldsInRow( $newRowUl ).each(
3257 + function() {
3258 + maybeDuplicateUnsavedSettings( originalFieldIdByDuplicatedFieldId[ this.getAttribute( 'data-fid' ) ], jQuery( this ).prop( 'outerHTML' ) );
3259 + }
3260 + );
3261 + }
3262 + );
3263 +
3264 + $fields.each(
3265 + function( index ) {
3266 + var cloneOption;
3267 + cloneOption = document.createElement( 'li' );
3268 + cloneOption.classList.add( 'frm_clone_field' );
3269 + cloneOption.setAttribute( 'frm-target-row-id', newRowId );
3270 + cloneOption.setAttribute( 'frm-field-order', index );
3271 + this.appendChild( cloneOption );
3272 + cloneOption.click();
3273 + injectedCloneOptions.push( cloneOption );
3274 + syncDetails.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) );
3275 + }
3276 + );
3277 + }
3278 +
3279 + function clickFieldGroupLayout() {
3280 + var hoverTarget, sizeOfFieldGroup, popupWrapper;
3281 +
3282 + hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3283 +
3284 + if ( null === hoverTarget ) {
3285 + return;
3286 + }
3287 +
3288 + deselectFields();
3289 +
3290 + sizeOfFieldGroup = getSizeOfFieldGroupFromChildElement( hoverTarget.querySelector( 'li.form-field' ) );
3291 +
3292 + hoverTarget.classList.add( 'frm-has-open-field-group-popup' );
3293 + jQuery( document ).on( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick );
3294 +
3295 + popupWrapper = div();
3296 + popupWrapper.style.position = 'relative';
3297 + popupWrapper.appendChild( getFieldGroupPopup( sizeOfFieldGroup, this ) );
3298 + this.parentNode.appendChild( popupWrapper );
3299 +
3300 + const firstLayoutOption = popupWrapper.querySelector( '.frm-row-layout-option' );
3301 + if ( firstLayoutOption ) {
3302 + firstLayoutOption.focus();
3303 + }
3304 + }
3305 +
3306 + function destroyFieldGroupPopupOnOutsideClick( event ) {
3307 + if ( event.target.classList.contains( 'frm-custom-field-group-layout' ) || event.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) {
3308 + return;
3309 + }
3310 + if ( ! jQuery( event.target ).closest( '#frm_field_group_controls' ).length && ! jQuery( event.target ).closest( '#frm_field_group_popup' ).length ) {
3311 + destroyFieldGroupPopup();
3312 + }
3313 + }
3314 +
3315 + function getSizeOfFieldGroupFromChildElement( element ) {
3316 + var $ul = jQuery( element ).closest( 'ul' );
3317 + if ( $ul.length ) {
3318 + return getFieldsInRow( $ul ).length;
3319 + }
3320 + return getSelectedFieldCount();
3321 + }
3322 +
3323 + function getFieldGroupPopup( sizeOfFieldGroup, childElement ) {
3324 + var popup, wrapper, rowLayoutOptions, ul;
3325 +
3326 + popup = document.getElementById( 'frm_field_group_popup' );
3327 + if ( null === popup ) {
3328 + popup = div();
3329 + } else {
3330 + popup.innerHTML = '';
3331 + }
3332 +
3333 + popup.id = 'frm_field_group_popup';
3334 +
3335 + wrapper = div();
3336 + wrapper.style.padding = '0 24px 12px';
3337 + wrapper.appendChild( getRowLayoutTitle() );
3338 +
3339 + rowLayoutOptions = getRowLayoutOptions( sizeOfFieldGroup );
3340 +
3341 + ul = childElement.closest( 'ul.frm_sorting' );
3342 + if ( null !== ul ) {
3343 + maybeMarkRowLayoutAsActive( ul, rowLayoutOptions );
3344 + }
3345 +
3346 + wrapper.appendChild( rowLayoutOptions );
3347 +
3348 + popup.appendChild( wrapper );
3349 + popup.appendChild( separator() );
3350 +
3351 + popup.appendChild( getCustomLayoutOption() );
3352 + popup.appendChild( getBreakIntoDifferentRowsOption() );
3353 +
3354 + return popup;
3355 + }
3356 +
3357 + function maybeMarkRowLayoutAsActive( activeRow, options ) {
3358 + var length, index, currentRow;
3359 +
3360 + length = options.children.length;
3361 + for ( index = 0; index < length; ++index ) {
3362 + currentRow = options.children[ index ];
3363 + if ( rowLayoutsMatch( currentRow, activeRow ) ) {
3364 + currentRow.classList.add( 'frm-active-row-layout' );
3365 + return;
3366 + }
3367 + }
3368 + }
3369 +
3370 + function separator() {
3371 + var hr = document.createElement( 'hr' );
3372 + return hr;
3373 + }
3374 +
3375 + function getCustomLayoutOption() {
3376 + var option = div();
3377 + option.textContent = __( 'Custom layout', 'formidable' );
3378 + jQuery( option ).prepend( getIconClone( 'frm_gear_svg' ) );
3379 + option.classList.add( 'frm-custom-field-group-layout' );
3380 + makeTabbable( option );
3381 + return option;
3382 + }
3383 +
3384 + function makeTabbable( element, ariaLabel ) {
3385 + element.setAttribute( 'tabindex', 0 );
3386 + element.setAttribute( 'role', 'button' );
3387 + if ( 'undefined' !== typeof ariaLabel ) {
3388 + element.setAttribute( 'aria-label', ariaLabel );
3389 + }
3390 + }
3391 +
3392 + function getIconClone( iconId ) {
3393 + var clone = document.getElementById( iconId ).cloneNode( true );
3394 + clone.id = '';
3395 + return clone;
3396 + }
3397 +
3398 + function getBreakIntoDifferentRowsOption() {
3399 + var option = div();
3400 + option.textContent = __( 'Break into rows', 'formidable' );
3401 + jQuery( option ).prepend( getIconClone( 'frm_break_field_group_svg' ) );
3402 + option.classList.add( 'frm-break-field-group' );
3403 + makeTabbable( option );
3404 + return option;
3405 + }
3406 +
3407 + function getRowLayoutTitle() {
3408 + var rowLayoutTitle = div();
3409 + rowLayoutTitle.classList.add( 'frm-row-layout-title' );
3410 + rowLayoutTitle.textContent = __( 'Row Layout', 'formidable' );
3411 + return rowLayoutTitle;
3412 + }
3413 +
3414 + function getRowLayoutOptions( size ) {
3415 + var wrapper, padding;
3416 +
3417 + wrapper = getEmptyGridContainer();
3418 + if ( 5 !== size ) {
3419 + wrapper.appendChild( getRowLayoutOption( size, 'even' ) );
3420 + }
3421 + if ( size % 2 === 1 ) {
3422 + // only include the middle option for odd numbers because even doesn't make a lot of sense.
3423 + wrapper.appendChild( getRowLayoutOption( size, 'middle' ) );
3424 + }
3425 + if ( size < 6 ) {
3426 + wrapper.appendChild( getRowLayoutOption( size, 'left' ) );
3427 + wrapper.appendChild( getRowLayoutOption( size, 'right' ) );
3428 + } else {
3429 + padding = div();
3430 + padding.classList.add( 'frm_fourth' );
3431 + wrapper.prepend( padding );
3432 + }
3433 +
3434 + return wrapper;
3435 + }
3436 +
3437 + function getRowLayoutOption( size, type ) {
3438 + var option, useClass;
3439 +
3440 + option = div();
3441 + option.classList.add( 'frm-row-layout-option' );
3442 + makeTabbable( option, type );
3443 +
3444 + switch ( size ) {
3445 + case 6:
3446 + useClass = 'frm_half';
3447 + break;
3448 + case 5:
3449 + useClass = 'frm_third';
3450 + break;
3451 + default:
3452 + useClass = size % 2 === 1 ? 'frm_fourth' : 'frm_third';
3453 + break;
3454 + }
3455 +
3456 + option.classList.add( useClass );
3457 + option.setAttribute( 'layout-type', type );
3458 +
3459 + option.appendChild( getRowForSizeAndType( size, type ) );
3460 + return option;
3461 + }
3462 +
3463 + function rowLayoutsMatch( row1, row2 ) {
3464 + return getRowLayoutAsKey( row1 ) === getRowLayoutAsKey( row2 );
3465 + }
3466 +
3467 + function getRowLayoutAsKey( row ) {
3468 + var $fields, sizes;
3469 + if ( row.classList.contains( 'frm-row-layout-option' ) ) {
3470 + $fields = jQuery( row ).find( '.frm_grid_container' ).children();
3471 + } else {
3472 + $fields = getFieldsInRow( jQuery( row ) );
3473 + }
3474 + sizes = [];
3475 + $fields.each(
3476 + function() {
3477 + sizes.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) );
3478 + }
3479 + );
3480 + return sizes.join( '-' );
3481 + }
3482 +
3483 + function getRowForSizeAndType( size, type ) {
3484 + var row, index, block;
3485 +
3486 + row = getEmptyGridContainer();
3487 + for ( index = 0; index < size; ++index ) {
3488 + block = div();
3489 + block.classList.add( getClassForBlock( size, type, index ) );
3490 + block.style.height = '16px';
3491 + block.style.background = '#9EA9B8';
3492 + block.style.borderRadius = '1px';
3493 + row.appendChild( block );
3494 + }
3495 +
3496 + return row;
3497 + }
3498 +
3499 + /**
3500 + * @param {int} size 2-6.
3501 + * @param {string} type even, middle, left, or right.
3502 + * @param {int} index 0-5.
3503 + * @returns string
3504 + */
3505 + function getClassForBlock( size, type, index ) {
3506 + if ( 'even' === type ) {
3507 + return getEvenClassForSize( size, index );
3508 + } else if ( 'middle' === type ) {
3509 + if ( 3 === size ) {
3510 + return 1 === index ? 'frm6' : 'frm3';
3511 + }
3512 + if ( 5 === size ) {
3513 + return 2 === index ? 'frm4' : 'frm2';
3514 + }
3515 + } else if ( 'left' === type ) {
3516 + return 0 === index ? getLargeClassForSize( size ) : getSmallClassForSize( size );
3517 + } else if ( 'right' === type ) {
3518 + return index === size - 1 ? getLargeClassForSize( size ) : getSmallClassForSize( size );
3519 + }
3520 + return 'frm12';
3521 + }
3522 +
3523 + function getEvenClassForSize( size, index ) {
3524 + if ( -1 !== [ 2, 3, 4, 6 ].indexOf( size ) ) {
3525 + return getLayoutClassForSize( 12 / size );
3526 + }
3527 + if ( 5 === size && 'undefined' !== typeof index ) {
3528 + return 0 === index ? 'frm4' : 'frm2';
3529 + }
3530 + return 'frm12';
3531 + }
3532 +
3533 + function getSmallClassForSize( size ) {
3534 + switch ( size ) {
3535 + case 2: case 3:
3536 + return 'frm3';
3537 + case 4:
3538 + return 'frm2';
3539 + case 5:
3540 + return 'frm2';
3541 + case 6:
3542 + return 'frm1';
3543 + }
3544 + return 'frm12';
3545 + }
3546 +
3547 + function getLargeClassForSize( size ) {
3548 + switch ( size ) {
3549 + case 2:
3550 + return 'frm9';
3551 + case 3: case 4:
3552 + return 'frm6';
3553 + case 5:
3554 + return 'frm4';
3555 + case 6:
3556 + return 'frm7';
3557 + }
3558 + return 'frm12';
3559 + }
3560 +
3561 + function getEmptyGridContainer() {
3562 + var wrapper = div();
3563 + wrapper.classList.add( 'frm_grid_container' );
3564 + return wrapper;
3565 + }
3566 +
3567 + function div( atts ) {
3568 + var element = document.createElement( 'div' );
3569 + if ( 'object' === typeof atts ) {
3570 + if ( 'undefined' !== typeof atts.id ) {
3571 + element.id = atts.id;
3572 + }
3573 + }
3574 + return element;
3575 + }
3576 +
3577 + function handleFieldGroupLayoutOptionClick() {
3578 + var type, row;
3579 + type = this.getAttribute( 'layout-type' );
3580 + row = document.querySelector( '.frm-field-group-hover-target' );
3581 + size = getFieldsInRow( jQuery( row ) ).length;
3582 + syncLayoutClasses( getFieldsInRow( jQuery( row ) ).first(), type );
3583 + destroyFieldGroupPopup();
3584 + }
3585 +
3586 + function handleFieldGroupLayoutOptionInsideMergeClick() {
3587 + var $ul, type;
3588 + $ul = mergeSelectedFieldGroups();
3589 + type = this.getAttribute( 'layout-type' );
3590 + syncLayoutClasses( getFieldsInRow( $ul ).first(), type );
3591 + unselectFieldGroups();
3592 + }
3593 +
3594 + function mergeSelectedFieldGroups() {
3595 + var $selectedFieldGroups = jQuery( '.frm-selected-field-group' ),
3596 + $firstGroupUl = $selectedFieldGroups.first();
3597 + $selectedFieldGroups.not( $firstGroupUl ).each(
3598 + function() {
3599 + getFieldsInRow( jQuery( this ) ).each(
3600 + function() {
3601 + var previousParent = this.parentNode;
3602 + getFieldsInRow( $firstGroupUl ).last().after( this );
3603 + if ( ! jQuery( previousParent ).children( 'li.form-field' ).length ) {
3604 + // clean up the previous field group if we've removed all of its fields.
3605 + previousParent.closest( 'li.frm_field_box' ).remove();
3606 + }
3607 + }
3608 + );
3609 + }
3610 + );
3611 + updateFieldOrder();
3612 + syncLayoutClasses( getFieldsInRow( $firstGroupUl ).first() );
3613 + return $firstGroupUl;
3614 + }
3615 +
3616 + function customFieldGroupLayoutClick() {
3617 + var $fields;
3618 + if ( null !== this.closest( '.frm-merge-fields-into-row' ) ) {
3619 + return;
3620 + }
3621 + $fields = getFieldsInRow( jQuery( '.frm-field-group-hover-target' ) );
3622 + setupCustomLayoutOptions( $fields );
3623 + }
3624 +
3625 + function setupCustomLayoutOptions( $fields ) {
3626 + var size, popup, wrapper, layoutClass, inputRow, paddingElement, inputValueOverride, index, inputField, heading, label, buttonsWrapper, cancelButton, saveButton;
3627 +
3628 + size = $fields.length;
3629 +
3630 + popup = document.getElementById( 'frm_field_group_popup' );
3631 + popup.innerHTML = '';
3632 +
3633 + wrapper = div();
3634 + wrapper.style.padding = '24px';
3635 +
3636 + layoutClass = getEvenClassForSize( 5 === size ? 6 : size );
3637 +
3638 + inputRow = div();
3639 + inputRow.style.padding = '20px 0';
3640 + inputRow.classList.add( 'frm_grid_container' );
3641 +
3642 + if ( 5 === size ) {
3643 + // add a span to pad the inputs by 1 column, to account for the missing 2 columns.
3644 + paddingElement = document.createElement( 'span' );
3645 + paddingElement.classList.add( 'frm1' );
3646 + inputRow.appendChild( paddingElement );
3647 + }
3648 +
3649 + inputValueOverride = getSelectedFieldCount() > 0 ? getSizeOfLayoutClass( getEvenClassForSize( size ) ) : false;
3650 + if ( false !== inputValueOverride && inputValueOverride >= 12 ) {
3651 + inputValueOverride = Math.floor( 12 / size );
3652 + }
3653 +
3654 + for ( index = 0; index < size; ++index ) {
3655 + inputField = document.createElement( 'input' );
3656 + inputField.type = 'text';
3657 + inputField.classList.add( layoutClass );
3658 + inputField.classList.add( 'frm-custom-grid-size-input' );
3659 + inputField.value = false !== inputValueOverride ? inputValueOverride : getSizeOfLayoutClass( getLayoutClassName( $fields.get( index ).classList ) );
3660 + inputRow.appendChild( inputField );
3661 + }
3662 +
3663 + heading = div();
3664 + heading.classList.add( 'frm-builder-popup-heading' );
3665 + heading.textContent = __( 'Enter number of columns for each field', 'formidable' );
3666 +
3667 + label = div();
3668 + label.classList.add( 'frm-builder-popup-subheading' );
3669 + label.textContent = __( 'Layouts are based on a 12-column grid system', 'formidable' );
3670 +
3671 + wrapper.appendChild( heading );
3672 + wrapper.appendChild( label );
3673 +
3674 + wrapper.appendChild( inputRow );
3675 +
3676 + buttonsWrapper = div();
3677 + buttonsWrapper.style.textAlign = 'right';
3678 +
3679 + cancelButton = getSecondaryButton();
3680 + cancelButton.textContent = __( 'Cancel', 'formidable' );
3681 + cancelButton.classList.add( 'frm-cancel-custom-field-group-layout' );
3682 + cancelButton.style.marginRight = '10px';
3683 +
3684 + saveButton = getPrimaryButton();
3685 + saveButton.textContent = __( 'Save', 'formidable' );
3686 + saveButton.classList.add( 'frm-save-custom-field-group-layout' );
3687 +
3688 + buttonsWrapper.appendChild( cancelButton );
3689 + buttonsWrapper.appendChild( saveButton );
3690 +
3691 + wrapper.appendChild( buttonsWrapper );
3692 +
3693 + popup.appendChild( wrapper );
3694 +
3695 + setTimeout(
3696 + function() {
3697 + const firstInput = popup.querySelector( 'input.frm-custom-grid-size-input' ).focus();
3698 + if ( firstInput ) {
3699 + firstInput.focus();
3700 + }
3701 + },
3702 + 0
3703 + );
3704 + }
3705 +
3706 + function customFieldGroupLayoutInsideMergeClick() {
3707 + $fields = jQuery( '.frm-selected-field-group li.form-field' );
3708 + setupCustomLayoutOptions( $fields );
3709 + }
3710 +
3711 + function getPrimaryButton() {
3712 + var button = getButton();
3713 + button.classList.add( 'button-primary', 'frm-button-primary' );
3714 + return button;
3715 + }
3716 +
3717 + function getSecondaryButton() {
3718 + var button = getButton();
3719 + button.classList.add( 'button-secondary', 'frm-button-secondary' );
3720 + return button;
3721 + }
3722 +
3723 + function getButton() {
3724 + var button = document.createElement( 'a' );
3725 + button.setAttribute( 'href', '#' );
3726 + button.classList.add( 'button' );
3727 + button.style.textDecoration = 'none';
3728 + return button;
3729 + }
3730 +
3731 + function getSizeOfLayoutClass( className ) {
3732 + switch ( className ) {
3733 + case 'frm_half':
3734 + return 6;
3735 + case 'frm_third':
3736 + return 4;
3737 + case 'frm_two_thirds':
3738 + return 8;
3739 + case 'frm_fourth':
3740 + return 3;
3741 + case 'frm_three_fourths':
3742 + return 9;
3743 + case 'frm_sixth':
3744 + return 2;
3745 + }
3746 +
3747 + if ( 0 === className.indexOf( 'frm' ) ) {
3748 + return parseInt( className.substr( 3 ) );
3749 + }
3750 +
3751 + // Anything missing a layout class should be a full width row.
3752 + return 12;
3753 + }
3754 +
3755 + function getLayoutClassName( classList ) {
3756 + var classes, index, currentClass;
3757 + classes = getLayoutClasses();
3758 + for ( index = 0; index < classes.length; ++index ) {
3759 + currentClass = classes[ index ];
3760 + if ( classList.contains( currentClass ) ) {
3761 + return currentClass;
3762 + }
3763 + }
3764 + return '';
3765 + }
3766 +
3767 + function getLayoutClassForSize( size ) {
3768 + return 'frm' + size;
3769 + }
3770 +
3771 + function breakFieldGroupClick() {
3772 + var row = document.querySelector( '.frm-field-group-hover-target' );
3773 + breakRow( row );
3774 + destroyFieldGroupPopup();
3775 + }
3776 +
3777 + function breakRow( row ) {
3778 + getFieldsInRow( jQuery( row ) ).each(
3779 + function( index ) {
3780 + if ( 0 !== index ) {
3781 + jQuery( row ).closest( 'li' ).after( wrapFieldLi( this ) );
3782 + }
3783 + stripLayoutFromFields( jQuery( this ) );
3784 + }
3785 + );
3786 + }
3787 +
3788 + function stripLayoutFromFields( field ) {
3789 + syncLayoutClasses( field, 'clear' );
3790 + }
3791 +
3792 + function focusFieldGroupInputOnClick() {
3793 + this.select();
3794 + }
3795 +
3796 + function cancelCustomFieldGroupClick() {
3797 + revertToFieldGroupPopupFirstPage( this );
3798 + }
3799 +
3800 + function revertToFieldGroupPopupFirstPage( triggerElement ) {
3801 + jQuery( document.getElementById( 'frm_field_group_popup' ) ).replaceWith(
3802 + getFieldGroupPopup( getSizeOfFieldGroupFromChildElement( triggerElement ), triggerElement )
3803 + );
3804 + }
3805 +
3806 + function destroyFieldGroupPopup() {
3807 + var popup, wrapper;
3808 + popup = document.getElementById( 'frm_field_group_popup' );
3809 + if ( popup === null ) {
3810 + return;
3811 + }
3812 + wrapper = document.querySelector( '.frm-has-open-field-group-popup' );
3813 + if ( null !== wrapper ) {
3814 + wrapper.classList.remove( 'frm-has-open-field-group-popup' );
3815 + popup.parentNode.remove();
3816 + }
3817 + jQuery( document ).off( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick );
3818 + }
3819 +
3820 + function saveCustomFieldGroupClick() {
3821 + var syncDetails, $controls, $ul;
3822 +
3823 + syncDetails = [];
3824 +
3825 + jQuery( document.getElementById( 'frm_field_group_popup' ).querySelectorAll( '.frm_grid_container input' ) )
3826 + .each(
3827 + function() {
3828 + syncDetails.push( parseInt( this.value ) );
3829 + }
3830 + );
3831 +
3832 + $controls = jQuery( document.getElementById( 'frm_field_group_controls' ) );
3833 +
3834 + if ( $controls.length && 'none' !== $controls.get( 0 ).style.display ) {
3835 + syncLayoutClasses( getFieldsInRow( jQuery( document.querySelector( '.frm-field-group-hover-target' ) ) ).first(), syncDetails );
3836 + } else {
3837 + $ul = mergeSelectedFieldGroups();
3838 + syncLayoutClasses( getFieldsInRow( $ul ).first(), syncDetails );
3839 + unselectFieldGroups();
3840 + }
3841 +
3842 + destroyFieldGroupPopup();
3843 + }
3844 +
3845 + function fieldGroupClick( e ) {
3846 + var hoverTarget, ctrlOrCmdKeyIsDown, shiftKeyIsDown, groupIsActive, $selectedFieldGroups, numberOfSelectedGroups, selectedField, $firstGroup, $range;
3847 +
3848 + if ( 'ul' !== e.originalEvent.target.nodeName.toLowerCase() ) {
3849 + // only continue if the group itself was clicked / ignore when a field is clicked.
3850 + return;
3851 + }
3852 +
3853 + hoverTarget = document.querySelector( '.frm-field-group-hover-target' );
3854 + if ( hoverTarget === null ) {
3855 + return;
3856 + }
3857 +
3858 + ctrlOrCmdKeyIsDown = e.ctrlKey || e.metaKey;
3859 + shiftKeyIsDown = e.shiftKey;
3860 + groupIsActive = hoverTarget.classList.contains( 'frm-selected-field-group' );
3861 + $selectedFieldGroups = jQuery( '.frm-selected-field-group' );
3862 + numberOfSelectedGroups = $selectedFieldGroups.length;
3863 +
3864 + if ( ctrlOrCmdKeyIsDown || shiftKeyIsDown ) {
3865 + // multi-selecting
3866 +
3867 + selectedField = document.querySelector( 'li.form-field.selected' );
3868 + if ( null !== selectedField && ! jQuery( selectedField ).siblings( 'li.form-field' ).length ) {
3869 + // count a selected field on its own as a selected field group when multiselecting.
3870 + selectedField.parentNode.classList.add( 'frm-selected-field-group' );
3871 + ++numberOfSelectedGroups;
3872 + }
3873 +
3874 + if ( ctrlOrCmdKeyIsDown ) {
3875 + if ( groupIsActive ) {
3876 + // unselect if holding ctrl or cmd and the group was already active.
3877 + --numberOfSelectedGroups;
3878 + hoverTarget.classList.remove( 'frm-selected-field-group' );
3879 + syncAfterMultiSelect( numberOfSelectedGroups );
3880 + return; // exit early to avoid adding back frm-selected-field-group
3881 + } else {
3882 + ++numberOfSelectedGroups;
3883 + }
3884 + } else if ( shiftKeyIsDown && ! groupIsActive ) {
3885 + ++numberOfSelectedGroups; // include the one we're selecting right now.
3886 + $firstGroup = $selectedFieldGroups.first();
3887 +
3888 + if ( $firstGroup.parent().index() < jQuery( hoverTarget.parentNode ).index() ) {
3889 + $range = $firstGroup.parent().nextUntil( hoverTarget.parentNode );
3890 + } else {
3891 + $range = $firstGroup.parent().prevUntil( hoverTarget.parentNode );
3892 + }
3893 +
3894 + $range.each(
3895 + function() {
3896 + var $fieldGroup = jQuery( this ).closest( 'li' ).find( 'ul.frm_sorting' );
3897 + if ( ! $fieldGroup.hasClass( 'frm-selected-field-group' ) ) {
3898 + ++numberOfSelectedGroups;
3899 + $fieldGroup.addClass( 'frm-selected-field-group' );
3900 + }
3901 + }
3902 + );
3903 +
3904 + // when holding shift and clicking, text gets selected. unselect it.
3905 + document.getSelection().removeAllRanges();
3906 + }
3907 + } else {
3908 + // not multi-selecting
3909 + unselectFieldGroups();
3910 + numberOfSelectedGroups = 1;
3911 + }
3912 +
3913 + hoverTarget.classList.add( 'frm-selected-field-group' );
3914 + syncAfterMultiSelect( numberOfSelectedGroups );
3915 +
3916 + jQuery( document ).off( 'click', unselectFieldGroups );
3917 + jQuery( document ).on( 'click', unselectFieldGroups );
3918 + }
3919 +
3920 + function syncAfterMultiSelect( numberOfSelectedGroups ) {
3921 + clearSettingsBox( true ); // unselect any fields if one is selected.
3922 + if ( numberOfSelectedGroups >= 2 || ( 1 === numberOfSelectedGroups && selectedGroupHasMultipleFields() ) ) {
3923 + addFieldMultiselectPopup();
3924 + } else {
3925 + maybeRemoveMultiselectPopup();
3926 + }
3927 + maybeRemoveGroupHoverTarget();
3928 + }
3929 +
3930 + function selectedGroupHasMultipleFields() {
3931 + return getFieldsInRow( jQuery( document.querySelector( '.frm-selected-field-group' ) ) ).length > 1;
3932 + }
3933 +
3934 + function unselectFieldGroups( event ) {
3935 + if ( 'undefined' !== typeof event ) {
3936 + if ( null !== event.originalEvent.target.closest( '#frm-show-fields' ) ) {
3937 + return;
3938 + }
3939 + if ( event.originalEvent.target.classList.contains( 'frm-merge-fields-into-row' ) ) {
3940 + return;
3941 + }
3942 + if ( null !== event.originalEvent.target.closest( '.frm-merge-fields-into-row' ) ) {
3943 + return;
3944 + }
3945 + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) {
3946 + return;
3947 + }
3948 + if ( event.originalEvent.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) {
3949 + return;
3950 + }
3951 + }
3952 + jQuery( '.frm-selected-field-group' ).removeClass( 'frm-selected-field-group' );
3953 + jQuery( document ).off( 'click', unselectFieldGroups );
3954 + maybeRemoveMultiselectPopup();
3955 + }
3956 +
3957 + function maybeRemoveMultiselectPopup() {
3958 + var popup = document.getElementById( 'frm_field_multiselect_popup' );
3959 + if ( null !== popup ) {
3960 + popup.remove();
3961 + }
3962 + }
3963 +
3964 + function addFieldMultiselectPopup() {
3965 + getFieldMultiselectPopup();
3966 + }
3967 +
3968 + function getFieldMultiselectPopup() {
3969 + var popup, mergeOption, caret, verticalSeparator, deleteOption;
3970 +
3971 + popup = document.getElementById( 'frm_field_multiselect_popup' );
3972 +
3973 + if ( null !== popup ) {
3974 + popup.classList.toggle( 'frm-unmergable', ! selectedFieldsAreMergable() );
3975 + return popup;
3976 + }
3977 +
3978 + popup = div();
3979 + popup.id = 'frm_field_multiselect_popup';
3980 + if ( ! selectedFieldsAreMergable() ) {
3981 + popup.classList.add( 'frm-unmergable' );
3982 + }
3983 +
3984 + mergeOption = div();
3985 + mergeOption.classList.add( 'frm-merge-fields-into-row' );
3986 + mergeOption.textContent = __( 'Merge into row', 'formidable' );
3987 +
3988 + caret = document.createElement( 'a' );
3989 + caret.style.marginLeft = '5px';
3990 + caret.classList.add( 'frm_icon_font', 'frm_arrowdown6_icon' );
3991 + caret.setAttribute( 'href', '#' );
3992 + mergeOption.appendChild( caret );
3993 +
3994 + popup.appendChild( mergeOption );
3995 +
3996 + verticalSeparator = div();
3997 + verticalSeparator.classList.add( 'frm-multiselect-popup-separator' );
3998 + popup.appendChild( verticalSeparator );
3999 +
4000 + deleteOption = div();
4001 + deleteOption.classList.add( 'frm-delete-field-groups' );
4002 + deleteOption.appendChild( getIconClone( 'frm_trash_svg' ) );
4003 + popup.appendChild( deleteOption );
4004 +
4005 + document.getElementById( 'post-body-content' ).appendChild( popup );
4006 +
4007 + jQuery( popup ).hide().fadeIn();
4008 +
4009 + return popup;
4010 + }
4011 +
4012 + function selectedFieldsAreMergable() {
4013 + var selectedFieldGroups, totalFieldCount, length, index, fieldGroup;
4014 + selectedFieldGroups = document.querySelectorAll( '.frm-selected-field-group' );
4015 + length = selectedFieldGroups.length;
4016 + if ( 1 === length ) {
4017 + return false;
4018 + }
4019 + totalFieldCount = 0;
4020 + for ( index = 0; index < length; ++index ) {
4021 + fieldGroup = selectedFieldGroups[ index ];
4022 + if ( null !== fieldGroup.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ) ) {
4023 + return false;
4024 + }
4025 + totalFieldCount += getFieldsInRow( jQuery( fieldGroup ) ).length;
4026 + if ( totalFieldCount > 6 ) {
4027 + return false;
4028 + }
4029 + }
4030 + return true;
4031 + }
4032 +
4033 + function mergeFieldsIntoRowClick( event ) {
4034 + var size, popup;
4035 +
4036 + if ( null !== event.originalEvent.target.closest( '#frm_field_group_popup' ) ) {
4037 + // prevent clicks within the popup from triggering the button again.
4038 + return;
4039 + }
4040 +
4041 + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) {
4042 + // avoid switching back to the first page when clicking the custom option nested inside of the merge option.
4043 + return;
4044 + }
4045 +
4046 + size = getSelectedFieldCount();
4047 + popup = getFieldGroupPopup( size, document.querySelector( '.frm-selected-field-group' ).firstChild );
4048 + this.appendChild( popup );
4049 + }
4050 +
4051 + function getSelectedFieldCount() {
4052 + var count = 0;
4053 + jQuery( document.querySelectorAll( '.frm-selected-field-group' ) ).each(
4054 + function() {
4055 + count += getFieldsInRow( jQuery( this ) ).length;
4056 + }
4057 + );
4058 + return count;
4059 + }
4060 +
4061 + function deleteFieldGroupsClick() {
4062 + var fieldIdsToDelete, deleteOnConfirm, multiselectPopup;
4063 +
4064 + fieldIdsToDelete = getSelectedFieldIds();
4065 + deleteOnConfirm = getDeleteSelectedFieldGroupsOnConfirmFunction( fieldIdsToDelete );
4066 +
4067 + multiselectPopup = document.getElementById( 'frm_field_multiselect_popup' );
4068 + if ( null !== multiselectPopup ) {
4069 + multiselectPopup.remove();
4070 + }
4071 +
4072 + this.setAttribute( 'data-frmcaution', __( 'Heads up', 'formidable' ) );
4073 + /* translators: %1$s: Number of fields that are selected to be deleted. */
4074 + this.setAttribute( 'data-frmverify', __( 'Are you sure you want to delete these %1$s selected fields?', 'formidable' ).replace( '%1$s', fieldIdsToDelete.length ) );
4075 + confirmLinkClick( this );
4076 +
4077 + jQuery( '#frm-confirmed-click' ).on( 'click', deleteOnConfirm );
4078 + jQuery( '#frm_confirm_modal' ).one( 'dialogclose', function() {
4079 + jQuery( '#frm-confirmed-click' ).off( 'click', deleteOnConfirm );
4080 + });
4081 + }
4082 +
4083 + function getSelectedFieldIds() {
4084 + var deleteFieldIds = [];
4085 + jQuery( '.frm-selected-field-group > li.form-field' )
4086 + .not( '.ui-sortable-helper' )
4087 + .each(
4088 + function() {
4089 + deleteFieldIds.push( this.dataset.fid );
4090 + }
4091 + );
4092 + return deleteFieldIds;
4093 + }
4094 +
4095 + function getDeleteSelectedFieldGroupsOnConfirmFunction( deleteFieldIds ) {
4096 + return function( event ) {
4097 + event.preventDefault();
4098 + deleteAllSelectedFieldGroups( deleteFieldIds );
4099 + };
4100 + }
4101 +
4102 + function deleteAllSelectedFieldGroups( deleteFieldIds ) {
4103 + deleteFieldIds.forEach(
4104 + function( fieldId ) {
4105 + deleteField( fieldId );
4106 + }
4107 + );
4108 + }
4109 +
4110 + function deleteFieldConfirmed() {
4111 + /*jshint validthis:true */
4112 + deleteFields( this.getAttribute( 'data-deletefield' ) );
4113 + }
4114 +
4115 + function deleteFields( fieldId ) {
4116 + var field = jQuery( '#frm_field_id_' + fieldId );
4117 +
4118 + deleteField( fieldId );
4119 +
4120 + if ( field.hasClass( 'edit_field_type_divider' ) ) {
4121 + field.find( 'li.frm_field_box' ).each( function() {
4122 + //TODO: maybe delete only end section
4123 + //if(n.hasClass('edit_field_type_end_divider')){
4124 + deleteField( this.getAttribute( 'data-fid' ) );
4125 + //}
4126 + });
4127 + }
4128 + toggleSectionHolder();
4129 + }
4130 +
4131 + function deleteField( fieldId ) {
4132 + jQuery.ajax({
4133 + type: 'POST',
4134 + url: ajaxurl,
4135 + data: {
4136 + action: 'frm_delete_field',
4137 + field_id: fieldId,
4138 + nonce: frmGlobal.nonce
4139 + },
4140 + success: function() {
4141 + var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ),
4142 + settings = jQuery( '#frm-single-settings-' + fieldId );
4143 +
4144 + // Remove settings from sidebar.
4145 + if ( settings.is( ':visible' ) ) {
4146 + document.getElementById( 'frm_insert_fields_tab' ).click();
4147 + }
4148 + settings.remove();
4149 +
4150 + $thisField.fadeOut( 'slow', function() {
4151 + var $section = $thisField.closest( '.start_divider' ),
4152 + type = $thisField.data( 'type' ),
4153 + $adjacentFields = $thisField.siblings( 'li.form-field' ),
4154 + $liWrapper;
4155 +
4156 + if ( ! $adjacentFields.length ) {
4157 + if ( $thisField.is( '.edit_field_type_end_divider' ) ) {
4158 + $adjacentFields.length = $thisField.closest( 'li.form-field' ).siblings();
4159 + } else {
4160 + $liWrapper = $thisField.closest( 'ul.frm_sorting' ).parent();
4161 + }
4162 + }
4163 +
4164 + $thisField.remove();
4165 + if ( type === 'break' ) {
4166 + renumberPageBreaks();
4167 + }
4168 + if ( type === 'summary' ) {
4169 + reenableAddSummaryBtn();
4170 + }
4171 + if ( type === 'product' ) {
4172 + maybeHideQuantityProductFieldOption();
4173 + // a product field attached to a quantity field earlier might be the one deleted, so re-populate
4174 + popAllProductFields();
4175 + }
4176 + if ( jQuery( '#frm-show-fields li' ).length === 0 ) {
4177 + document.getElementById( 'frm_form_editor_container' ).classList.remove( 'frm-has-fields' );
4178 + } else if ( $section.length ) {
4179 + toggleOneSectionHolder( $section );
4180 + }
4181 + if ( $adjacentFields.length ) {
4182 + syncLayoutClasses( $adjacentFields.first() );
4183 + } else {
4184 + $liWrapper.remove();
4185 + }
4186 +
4187 + // prevent "More Options" tooltips from staying around after their target field is deleted.
4188 + deleteTooltips();
4189 + });
4190 + }
4191 + });
4192 + }
4193 +
4194 + function addFieldLogicRow() {
4195 + /*jshint validthis:true */
4196 + var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
4197 + formId = thisFormId,
4198 + logicRows = document.getElementById( 'frm_logic_row_' + id ).querySelectorAll( '.frm_logic_row' );
4199 + jQuery.ajax({
4200 + type: 'POST',
4201 + url: ajaxurl,
4202 + data: {
4203 + action: 'frm_add_logic_row',
4204 + form_id: formId,
4205 + field_id: id,
4206 + nonce: frmGlobal.nonce,
4207 + meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ),
4208 + fields: getFieldList()
4209 + },
4210 + success: function( html ) {
4211 + jQuery( document.getElementById( 'logic_' + id ) ).fadeOut( 'slow', function() {
4212 + var logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) );
4213 + logicRow.append( html );
4214 + logicRow.closest( '.frm_logic_rows' ).fadeIn( 'slow' );
4215 + });
4216 + }
4217 + });
4218 + return false;
4219 + }
4220 +
4221 + function getNewRowId( rows, replace, defaultValue ) {
4222 + if ( ! rows.length ) {
4223 + return 'undefined' !== typeof defaultValue ? defaultValue : 0;
4224 + }
4225 + return parseInt( rows[ rows.length - 1 ].id.replace( replace, '' ), 10 ) + 1;
4226 + }
4227 +
4228 + function addWatchLookupRow() {
4229 + /*jshint validthis:true */
4230 + var lastRowId,
4231 + id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ),
4232 + formId = thisFormId,
4233 + lookupBlockRows = document.getElementById( 'frm_watch_lookup_block_' + id ).children;
4234 + jQuery.ajax({
4235 + type: 'POST',
4236 + url: ajaxurl,
4237 + data: {
4238 + action: 'frm_add_watch_lookup_row',
4239 + form_id: formId,
4240 + field_id: id,
4241 + row_key: getNewRowId( lookupBlockRows, 'frm_watch_lookup_' + id + '_' ),
4242 + nonce: frmGlobal.nonce
4243 + },
4244 + success: function( newRow ) {
4245 + var watchRowBlock = jQuery( document.getElementById( 'frm_watch_lookup_block_' + id ) );
4246 + watchRowBlock.append( newRow );
4247 + watchRowBlock.fadeIn( 'slow' );
4248 + }
4249 + });
4250 + return false;
4251 + }
4252 +
4253 + function resetOptionTextDetails() {
4254 + jQuery( '.frm-single-settings ul input[type="text"][name^="field_options[options_"]' ).filter( '[data-value-on-load]' ).removeAttr( 'data-value-on-load' );
4255 + jQuery( 'input[type="hidden"][name^=optionmap]' ).remove();
4256 + }
4257 +
4258 + function optionTextAlreadyExists( input ) {
4259 + var fieldId = jQuery( input ).closest( '.frm-single-settings' ).attr( 'data-fid' ),
4260 + optionInputs = jQuery( input ).closest( 'ul' ).get( 0 ).querySelectorAll( '.field_' + fieldId + '_option' ),
4261 + index,
4262 + optionInput;
4263 +
4264 + for ( index in optionInputs ) {
4265 + optionInput = optionInputs[ index ];
4266 + if ( optionInput.id !== input.id && optionInput.value === input.value && optionInput.getAttribute( 'data-duplicate' ) !== 'true' ) {
4267 + return true;
4268 + }
4269 + }
4270 +
4271 + return false;
4272 + }
4273 +
4274 + function onOptionTextFocus() {
4275 + var input,
4276 + fieldId;
4277 +
4278 + if ( this.getAttribute( 'data-value-on-load' ) === null ) {
4279 + this.setAttribute( 'data-value-on-load', this.value );
4280 +
4281 + fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' );
4282 + input = document.createElement( 'input' );
4283 + input.value = this.value;
4284 + input.setAttribute( 'type', 'hidden' );
4285 + input.setAttribute( 'name', 'optionmap[' + fieldId + '][' + this.value + ']' );
4286 + this.parentNode.appendChild( input );
4287 +
4288 + if ( typeof optionMap[ fieldId ] === 'undefined' ) {
4289 + optionMap[ fieldId ] = {};
4290 + }
4291 +
4292 + optionMap[ fieldId ][ this.value ] = input;
4293 + }
4294 +
4295 + if ( this.getAttribute( 'data-duplicate' ) === 'true' ) {
4296 + this.removeAttribute( 'data-duplicate' );
4297 +
4298 + // we want to use original value if actually still a duplicate
4299 + if ( optionTextAlreadyExists( this ) ) {
4300 + this.setAttribute( 'data-value-on-focus', this.getAttribute( 'data-value-on-load' ) );
4301 + return;
4302 + }
4303 + }
4304 +
4305 + if ( '' !== this.value || frm_admin_js.new_option !== this.getAttribute( 'data-value-on-focus' ) ) {
4306 + this.setAttribute( 'data-value-on-focus', this.value );
4307 + }
4308 + }
4309 +
4310 + function onOptionTextBlur() {
4311 + var originalValue,
4312 + oldValue = this.getAttribute( 'data-value-on-focus' ),
4313 + newValue = this.value,
4314 + fieldId,
4315 + fieldIndex,
4316 + logicId,
4317 + row,
4318 + rowLength,
4319 + rowIndex,
4320 + valueSelect,
4321 + opts,
4322 + fieldIds,
4323 + settingId,
4324 + setting,
4325 + optionMatches,
4326 + option;
4327 +
4328 + if ( oldValue === newValue ) {
4329 + return;
4330 + }
4331 +
4332 + fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' );
4333 + originalValue = this.getAttribute( 'data-value-on-load' );
4334 +
4335 + // check if the newValue is already mapped to another option
4336 + // if it is, mark as duplicate and return
4337 + if ( optionTextAlreadyExists( this ) ) {
4338 + this.setAttribute( 'data-duplicate', 'true' );
4339 +
4340 + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) {
4341 + // unmap any other change that may have happened before instead of changing it to something unused
4342 + optionMap[ fieldId ][ originalValue ].value = originalValue;
4343 + }
4344 +
4345 + return;
4346 + }
4347 +
4348 + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) {
4349 + optionMap[ fieldId ][ originalValue ].value = newValue;
4350 + }
4351 +
4352 + fieldIds = [];
4353 + rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' );
4354 + rowLength = rows.length;
4355 + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) {
4356 + row = rows[ rowIndex ];
4357 + opts = row.querySelector( '.frm_logic_field_opts' );
4358 +
4359 + if ( opts.value !== fieldId ) {
4360 + continue;
4361 + }
4362 +
4363 + logicId = row.id.split( '_' )[ 2 ];
4364 + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' );
4365 +
4366 + if ( '' === oldValue ) {
4367 + optionMatches = [];
4368 + } else {
4369 + optionMatches = valueSelect.querySelectorAll( 'option[value="' + oldValue + '"]' );
4370 + }
4371 +
4372 + if ( ! optionMatches.length ) {
4373 + optionMatches = valueSelect.querySelectorAll( 'option[value="' + newValue + '"]' );
4374 +
4375 + if ( ! optionMatches.length ) {
4376 + option = document.createElement( 'option' );
4377 + valueSelect.appendChild( option );
4378 + }
4379 + }
4380 +
4381 + if ( optionMatches.length ) {
4382 + option = optionMatches[ optionMatches.length - 1 ];
4383 + }
4384 +
4385 + option.setAttribute( 'value', newValue );
4386 + option.textContent = newValue;
4387 +
4388 + if ( fieldIds.indexOf( logicId ) === -1 ) {
4389 + fieldIds.push( logicId );
4390 + }
4391 + }
4392 +
4393 + for ( fieldIndex in fieldIds ) {
4394 + settingId = fieldIds[ fieldIndex ];
4395 + setting = document.getElementById( 'frm-single-settings-' + settingId );
4396 + moveFieldSettings( setting );
4397 + }
4398 + }
4399 +
4400 + function updateGetValueFieldSelection() {
4401 + /*jshint validthis:true */
4402 + var fieldID = this.id.replace( 'get_values_form_', '' );
4403 + var fieldSelect = document.getElementById( 'get_values_field_' + fieldID );
4404 + var fieldType = this.getAttribute( 'data-fieldtype' );
4405 +
4406 + if ( this.value === '' ) {
4407 + fieldSelect.options.length = 1;
4408 + } else {
4409 + var formID = this.value;
4410 + jQuery.ajax({
4411 + type: 'POST', url: ajaxurl,
4412 + data: {
4413 + action: 'frm_get_options_for_get_values_field',
4414 + form_id: formID,
4415 + field_type: fieldType,
4416 + nonce: frmGlobal.nonce
4417 + },
4418 + success: function( fields ) {
4419 + fieldSelect.innerHTML = fields;
4420 + }
4421 + });
4422 + }
4423 + }
4424 +
4425 + // Clear the Watch Fields option when Lookup field switches to "Text" option
4426 + function maybeClearWatchFields() {
4427 + /*jshint validthis:true */
4428 + var link, lookupBlock,
4429 + fieldID = this.name.replace( 'field_options[data_type_', '' ).replace( ']', '' );
4430 +
4431 + link = document.getElementById( 'frm_add_watch_lookup_link_' + fieldID ).parentNode;
4432 +
4433 + if ( this.value === 'text' ) {
4434 + lookupBlock = document.getElementById( 'frm_watch_lookup_block_' + fieldID );
4435 + if ( lookupBlock !== null ) {
4436 + // Clear and hide the Watch Fields option
4437 + lookupBlock.innerHTML = '';
4438 + link.classList.add( 'frm_hidden' );
4439 +
4440 + // Hide the Watch Fields row
4441 + link.previousElementSibling.style.display = 'none';
4442 + link.previousElementSibling.previousElementSibling.style.display = 'none';
4443 + link.previousElementSibling.previousElementSibling.previousElementSibling.style.display = 'none';
4444 + }
4445 + } else {
4446 + // Show the Watch Fields option
4447 + link.classList.remove( 'frm_hidden' );
4448 + }
4449 +
4450 + toggleMultiSelect( fieldID, this.value );
4451 + }
4452 +
4453 + // Number the pages and hide/show the first page as needed.
4454 + function renumberPageBreaks() {
4455 + var i, containerClass,
4456 + pages = document.getElementsByClassName( 'frm-page-num' );
4457 +
4458 + if ( pages.length > 1 ) {
4459 + document.getElementById( 'frm-fake-page' ).style.display = 'block';
4460 + for ( i = 0; i < pages.length; i++ ) {
4461 + containerClass = pages[i].parentNode.parentNode.parentNode.classList;
4462 + if ( i === 1 ) {
4463 + // Hide previous button on page 1
4464 + containerClass.add( 'frm-first-page' );
4465 + } else {
4466 + containerClass.remove( 'frm-first-page' );
4467 + }
4468 + pages[i].innerHTML = ( i + 1 );
4469 + }
4470 + } else {
4471 + document.getElementById( 'frm-fake-page' ).style.display = 'none';
4472 + }
4473 + }
4474 +
4475 + // The fake field works differently than real fields.
4476 + function maybeCollapsePage() {
4477 + /*jshint validthis:true */
4478 + var field = jQuery( this ).closest( '.frm_field_box[data-ftype=break]' );
4479 + if ( field.length ) {
4480 + toggleCollapsePage( field );
4481 + } else {
4482 + toggleCollapseFakePage();
4483 + }
4484 + }
4485 +
4486 + // Find all fields in a page and hide/show them
4487 + function toggleCollapsePage( field ) {
4488 + var toCollapse = getAllFieldsForPage( field.get( 0 ).parentNode.closest( 'li.frm_field_box' ).nextElementSibling );
4489 + togglePage( field, toCollapse );
4490 + }
4491 +
4492 + function toggleCollapseFakePage() {
4493 + var topLevel = document.getElementById( 'frm-fake-page' ),
4494 + firstField = document.getElementById( 'frm-show-fields' ).firstElementChild,
4495 + toCollapse = getAllFieldsForPage( firstField );
4496 +
4497 + if ( firstField.getAttribute( 'data-ftype' ) === 'break' ) {
4498 + // Don't collapse if the first field is a page break.
4499 + return;
4500 + }
4501 +
4502 + togglePage( jQuery( topLevel ), toCollapse );
4503 + }
4504 +
4505 + function getAllFieldsForPage( firstWrapper ) {
4506 + var $fieldsForPage, currentWrapper;
4507 +
4508 + $fieldsForPage = jQuery();
4509 +
4510 + if ( null === firstWrapper ) {
4511 + return $fieldsForPage;
4512 + }
4513 +
4514 + currentWrapper = firstWrapper;
4515 +
4516 + do {
4517 + if ( null !== currentWrapper.querySelector( '.edit_field_type_break' ) ) {
4518 + break;
4519 + }
4520 + $fieldsForPage = $fieldsForPage.add( jQuery( currentWrapper ) );
4521 + currentWrapper = currentWrapper.nextElementSibling;
4522 + } while ( null !== currentWrapper );
4523 +
4524 + return $fieldsForPage;
4525 + }
4526 +
4527 + function togglePage( field, toCollapse ) {
4528 + var i,
4529 + fieldCount = toCollapse.length,
4530 + slide = Math.min( fieldCount, 3 );
4531 +
4532 + if ( field.hasClass( 'frm-page-collapsed' ) ) {
4533 + field.removeClass( 'frm-page-collapsed' );
4534 + toCollapse.removeClass( 'frm-is-collapsed' );
4535 + for ( i = 0; i < slide; i++ ) {
4536 + if ( i === slide - 1 ) {
4537 + jQuery( toCollapse[ i ]).slideDown( 150, function() {
4538 + toCollapse.show();
4539 + });
4540 + } else {
4541 + jQuery( toCollapse[ i ]).slideDown( 150 );
4542 + }
4543 + }
4544 + } else {
4545 + field.addClass( 'frm-page-collapsed' );
4546 + toCollapse.addClass( 'frm-is-collapsed' );
4547 + for ( i = 0; i < slide; i++ ) {
4548 + if ( i === slide - 1 ) {
4549 + jQuery( toCollapse[ i ]).slideUp( 150, function() {
4550 + toCollapse.css( 'cssText', 'display:none !important;' );
4551 + });
4552 + } else {
4553 + jQuery( toCollapse[ i ]).slideUp( 150 );
4554 + }
4555 + }
4556 + }
4557 + }
4558 +
4559 + function maybeCollapseSection() {
4560 + /*jshint validthis:true */
4561 + var parentCont = this.parentNode.parentNode.parentNode.parentNode;
4562 +
4563 + parentCont.classList.toggle( 'frm-section-collapsed' );
4564 + }
4565 +
4566 + function maybeCollapseSettings() {
4567 + /*jshint validthis:true */
4568 + this.classList.toggle( 'frm-collapsed' );
4569 + }
4570 +
4571 + function clickLabel() {
4572 + if ( ! this.id ) {
4573 + return;
4574 + }
4575 +
4576 + /*jshint validthis:true */
4577 + var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0],
4578 + fieldId = this.id.replace( 'field_label_', '' ),
4579 + fieldType = document.getElementById( 'field_options_type_' + fieldId ),
4580 + fieldTypeName = fieldType.value;
4581 +
4582 + if ( typeof setting !== 'undefined' ) {
4583 + if ( fieldType.tagName === 'SELECT' ) {
4584 + fieldTypeName = fieldType.options[ fieldType.selectedIndex ].text.toLowerCase();
4585 + } else {
4586 + fieldTypeName = fieldTypeName.replace( '_', ' ' );
4587 + }
4588 +
4589 + fieldTypeName = normalizeFieldName( fieldTypeName );
4590 +
4591 + setTimeout( function() {
4592 + if ( setting.value.toLowerCase() === fieldTypeName ) {
4593 + setting.select();
4594 + } else {
4595 + setting.focus();
4596 + }
4597 + }, 50 );
4598 + }
4599 + }
4600 +
4601 + function clickDescription() {
4602 + /*jshint validthis:true */
4603 + var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0];
4604 + if ( typeof setting !== 'undefined' ) {
4605 + setTimeout( function() {
4606 + setting.focus();
4607 + autoExpandSettings( setting );
4608 + }, 50 );
4609 + }
4610 + }
4611 +
4612 + function autoExpandSettings( setting ) {
4613 + var inSection = setting.closest( '.frm-collapse-me' );
4614 + if ( inSection !== null ) {
4615 + inSection.previousElementSibling.classList.remove( 'frm-collapsed' );
4616 + }
4617 + }
4618 +
4619 + function normalizeFieldName( fieldTypeName ) {
4620 + if ( fieldTypeName === 'divider' ) {
4621 + fieldTypeName = 'section';
4622 + } else if ( fieldTypeName === 'range' ) {
4623 + fieldTypeName = 'slider';
4624 + } else if ( fieldTypeName === 'data' ) {
4625 + fieldTypeName = 'dynamic';
4626 + } else if ( fieldTypeName === 'form' ) {
4627 + fieldTypeName = 'embed form';
4628 + }
4629 + return fieldTypeName;
4630 + }
4631 +
4632 + function clickVis( e ) {
4633 + /*jshint validthis:true */
4634 + var currentClass, originalList;
4635 +
4636 + currentClass = e.target.classList;
4637 +
4638 + if ( currentClass.contains( 'frm-collapse-page' ) || currentClass.contains( 'frm-sub-label' ) || e.target.closest( '.dropdown' ) !== null ) {
4639 + return;
4640 + }
4641 +
4642 + if ( this.closest( '.start_divider' ) !== null ) {
4643 + e.stopPropagation();
4644 + }
4645 +
4646 + if ( this.classList.contains( 'edit_field_type_divider' ) ) {
4647 + originalList = e.originalEvent.target.closest( 'ul.frm_sorting' );
4648 + if ( null !== originalList ) {
4649 + // prevent section click if clicking a field group within a section.
4650 + if ( originalList.classList.contains( 'edit_field_type_divider' ) || originalList.parentNode.parentNode.classList.contains( 'start_divider' ) ) {
4651 + return;
4652 + }
4653 + }
4654 + }
4655 +
4656 + clickAction( this );
4657 + }
4658 +
4659 + /**
4660 + * Open Advanced settings on double click.
4661 + */
4662 + function openAdvanced() {
4663 + var fieldId = this.getAttribute( 'data-fid' );
4664 + autoExpandSettings( document.getElementById( 'field_options_field_key_' + fieldId ) );
4665 + }
4666 +
4667 + function toggleRepeatButtons() {
4668 + /*jshint validthis:true */
4669 + var $thisField = jQuery( this ).closest( '.frm_field_box' );
4670 + $thisField.find( '.repeat_icon_links' ).removeClass( 'repeat_format repeat_formatboth repeat_formattext' ).addClass( 'repeat_format' + this.value );
4671 + if ( this.value === 'text' || this.value === 'both' ) {
4672 + $thisField.find( '.frm_repeat_text' ).show();
4673 + $thisField.find( '.repeat_icon_links a' ).addClass( 'frm_button' );
4674 + } else {
4675 + $thisField.find( '.frm_repeat_text' ).hide();
4676 + $thisField.find( '.repeat_icon_links a' ).removeClass( 'frm_button' );
4677 + }
4678 + }
4679 +
4680 + function checkRepeatLimit() {
4681 + /*jshint validthis:true */
4682 + var val = this.value;
4683 + if ( val !== '' && ( val < 2 || val > 200 ) ) {
4684 + infoModal( frm_admin_js.repeat_limit_min );
4685 + this.value = '';
4686 + }
4687 + }
4688 +
4689 + function checkCheckboxSelectionsLimit() {
4690 + /*jshint validthis:true */
4691 + var val = this.value;
4692 + if ( val !== '' && ( val < 1 || val > 200 ) ) {
4693 + infoModal( frm_admin_js.checkbox_limit );
4694 + this.value = '';
4695 + }
4696 + }
4697 +
4698 + function updateRepeatText( obj, addRemove ) {
4699 + var $thisField = jQuery( obj ).closest( '.frm_field_box' );
4700 + $thisField.find( '.frm_' + addRemove + '_form_row .frm_repeat_label' ).text( obj.value );
4701 + }
4702 +
4703 + function fieldsInSection( id ) {
4704 + var children = [];
4705 + jQuery( document.getElementById( 'frm_field_id_' + id ) ).find( 'li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)' ).each( function() {
4706 + children.push( jQuery( this ).data( 'fid' ) );
4707 + });
4708 + return children;
4709 + }
4710 +
4711 + function toggleFormTax() {
4712 + /*jshint validthis:true */
4713 + var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
4714 + var val = this.value;
4715 + var $showFields = document.getElementById( 'frm_show_selected_fields_' + id );
4716 + var $showForms = document.getElementById( 'frm_show_selected_forms_' + id );
4717 +
4718 + jQuery( $showForms ).find( 'select' ).val( '' );
4719 + if ( val === 'form' ) {
4720 + $showForms.style.display = 'inline';
4721 + empty( $showFields );
4722 + } else {
4723 + $showFields.style.display = 'none';
4724 + $showForms.style.display = 'none';
4725 + getTaxOrFieldSelection( val, id );
4726 + }
4727 +
4728 + }
4729 +
4730 + function resetOptOnChange() {
4731 + /*jshint validthis:true */
4732 + var field, thisOpt;
4733 +
4734 + field = getFieldKeyFromOpt( this );
4735 + if ( ! field ) {
4736 + return;
4737 + }
4738 +
4739 + thisOpt = jQuery( this ).closest( '.frm_single_option' );
4740 +
4741 + resetSingleOpt( field.fieldId, field.fieldKey, thisOpt );
4742 + }
4743 +
4744 + function getFieldKeyFromOpt( object ) {
4745 + var allOpts, fieldId, fieldKey;
4746 +
4747 + allOpts = jQuery( object ).closest( '.frm_sortable_field_opts' );
4748 + if ( ! allOpts.length ) {
4749 + return false;
4750 + }
4751 +
4752 + fieldId = allOpts.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_opts', '' );
4753 + fieldKey = allOpts.data( 'key' );
4754 +
4755 + return {
4756 + fieldId: fieldId,
4757 + fieldKey: fieldKey
4758 + };
4759 + }
4760 +
4761 + function resetSingleOpt( fieldId, fieldKey, thisOpt ) {
4762 + var saved, text, defaultVal, previewInput, labelForDisplay, optContainer,
4763 + optKey = thisOpt.data( 'optkey' ),
4764 + separateValues = usingSeparateValues( fieldId ),
4765 + single = jQuery( 'label[for="field_' + fieldKey + '-' + optKey + '"]' ),
4766 + baseName = 'field_options[options_' + fieldId + '][' + optKey + ']',
4767 + label = jQuery( 'input[name="' + baseName + '[label]"]' );
4768 +
4769 + if ( single.length < 1 ) {
4770 + resetDisplayedOpts( fieldId );
4771 +
4772 + // Set the default value.
4773 + defaultVal = thisOpt.find( 'input[name^="default_value_"]' );
4774 + if ( defaultVal.is( ':checked' ) && label.length > 0 ) {
4775 + jQuery( 'select[name^="item_meta[' + fieldId + ']"]' ).val( label.val() );
4776 + }
4777 + return;
4778 + }
4779 +
4780 + previewInput = single.children( 'input' );
4781 +
4782 + if ( label.length < 1 ) {
4783 + // Check for other label.
4784 + label = jQuery( 'input[name="' + baseName + '"]' );
4785 + saved = label.val();
4786 + } else if ( separateValues ) {
4787 + saved = jQuery( 'input[name="' + baseName + '[value]"]' ).val();
4788 + } else {
4789 + saved = label.val();
4790 + }
4791 +
4792 + if ( label.length < 1 ) {
4793 + return;
4794 + }
4795 +
4796 + // Set the displayed value.
4797 + text = single[0].childNodes;
4798 +
4799 + if ( imagesAsOptions( fieldId ) ) {
4800 + labelForDisplay = getImageDisplayValue( thisOpt, fieldId, label );
4801 + optContainer = single.find( '.frm_image_option_container' );
4802 +
4803 + if ( optContainer.length > 0 ) {
4804 + optContainer.replaceWith( labelForDisplay );
4805 + } else {
4806 + text[ text.length - 1 ].nodeValue = '';
4807 + single.append( labelForDisplay );
4808 + }
4809 + } else {
4810 + text[ text.length - 1 ].nodeValue = ' ' + label.val();
4811 + }
4812 +
4813 + // Set saved value.
4814 + previewInput.val( saved );
4815 +
4816 + // Set the default value.
4817 + defaultVal = thisOpt.find( 'input[name^="default_value_"]' );
4818 + previewInput.prop( 'checked', defaultVal.is( ':checked' ) ? true : false );
4819 + }
4820 +
4821 + /**
4822 + * Set the displayed value for an image option.
4823 + */
4824 + function getImageDisplayValue( thisOpt, fieldId, label ) {
4825 + var image, imageUrl, showLabelWithImage, fieldType;
4826 +
4827 + image = thisOpt.find( 'img' );
4828 + if ( image ) {
4829 + imageUrl = image.attr( 'src' );
4830 + }
4831 +
4832 + showLabelWithImage = showingLabelWithImage( fieldId );
4833 + fieldType = radioOrCheckbox( fieldId );
4834 + return getImageLabel( label.val(), showLabelWithImage, imageUrl, fieldType );
4835 + }
4836 +
4837 + function getImageOptionSize( fieldId ) {
4838 + var val,
4839 + field = document.getElementById( 'field_options_image_size_' + fieldId ),
4840 + size = '';
4841 +
4842 + if ( field !== null ) {
4843 + val = field.value;
4844 + if ( val !== '' ) {
4845 + size = val;
4846 + }
4847 + }
4848 +
4849 + return size;
4850 + }
4851 +
4852 + function resetDisplayedOpts( fieldId ) {
4853 + var i, opts, type, placeholder, fieldInfo,
4854 + input = jQuery( '[name^="item_meta[' + fieldId + ']"]' );
4855 +
4856 + if ( input.length < 1 ) {
4857 + return;
4858 + }
4859 +
4860 + if ( input.is( 'select' ) ) {
4861 + placeholder = document.getElementById( 'frm_placeholder_' + fieldId );
4862 + if ( placeholder !== null && placeholder.value === '' ) {
4863 + fillDropdownOpts( input[0], { sourceID: fieldId });
4864 + } else {
4865 + fillDropdownOpts( input[0], {
4866 + sourceID: fieldId,
4867 + placeholder: placeholder.value
4868 + });
4869 + }
4870 + } else {
4871 + opts = getMultipleOpts( fieldId );
4872 + type = input.attr( 'type' );
4873 + jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ).html( '' );
4874 + fieldInfo = getFieldKeyFromOpt( jQuery( '#frm_delete_field_' + fieldId + '-000_container' ) );
4875 +
4876 + var container = jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ),
4877 + hasImageOptions = imagesAsOptions( fieldId ),
4878 + imageSize = hasImageOptions ? getImageOptionSize( fieldId ) : '',
4879 + imageOptionClass = hasImageOptions ? ( 'frm_image_option frm_image_' + imageSize + ' ' ) : '',
4880 + isProduct = isProductField( fieldId );
4881 +
4882 + for ( i = 0; i < opts.length; i++ ) {
4883 + container.append( addRadioCheckboxOpt( type, opts[ i ], fieldId, fieldInfo.fieldKey, isProduct, imageOptionClass ) );
4884 + }
4885 + }
4886 +
4887 + adjustConditionalLogicOptionOrders( fieldId );
4888 + }
4889 +
4890 + function adjustConditionalLogicOptionOrders( fieldId ) {
4891 + var row, opts, logicId, valueSelect, rowOptions, expectedOrder, optionLength, optionIndex, expectedOption, optionMatch,
4892 + rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ),
4893 + rowLength = rows.length,
4894 + fieldOptions = getFieldOptions( fieldId ),
4895 + optionLength = fieldOptions.length;
4896 +
4897 + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) {
4898 + row = rows[ rowIndex ];
4899 + opts = row.querySelector( '.frm_logic_field_opts' );
4900 +
4901 + if ( opts.value != fieldId ) {
4902 + continue;
4903 + }
4904 +
4905 + logicId = row.id.split( '_' )[ 2 ];
4906 + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' );
4907 +
4908 + for ( optionIndex = optionLength - 1; optionIndex >= 0; optionIndex-- ) {
4909 + expectedOption = fieldOptions[ optionIndex ];
4910 + optionMatch = valueSelect.querySelector( 'option[value="' + expectedOption + '"]' );
4911 +
4912 + if ( optionMatch === null ) {
4913 + optionMatch = document.createElement( 'option' );
4914 + optionMatch.setAttribute( 'value', expectedOption );
4915 + optionMatch.textContent = expectedOption;
4916 + }
4917 +
4918 + valueSelect.prepend( optionMatch );
4919 + }
4920 +
4921 + optionMatch = valueSelect.querySelector( 'option[value=""]' );
4922 + if ( optionMatch !== null ) {
4923 + valueSelect.prepend( optionMatch );
4924 + }
4925 + }
4926 + }
4927 +
4928 + function getFieldOptions( fieldId ) {
4929 + var index, input, li,
4930 + listItems = document.getElementById( 'frm_field_' + fieldId + '_opts' ).querySelectorAll( '.frm_single_option' ),
4931 + options = [],
4932 + length = listItems.length;
4933 + for ( index = 0; index < length; index++ ) {
4934 + li = listItems[ index ];
4935 +
4936 + if ( li.classList.contains( 'frm_hidden' ) ) {
4937 + continue;
4938 + }
4939 +
4940 + input = li.querySelector( '.field_' + fieldId + '_option' );
4941 + options.push( input.value );
4942 + }
4943 + return options;
4944 + }
4945 +
4946 + function addRadioCheckboxOpt( type, opt, fieldId, fieldKey, isProduct, classes ) {
4947 + var other, single,
4948 + isOther = opt.key.indexOf( 'other' ) !== -1,
4949 +
4950 + id = 'field_' + fieldKey + '-' + opt.key;
4951 +
4952 + 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="" />';
4953 +
4954 + single = '<div class="frm_' + type + ' ' + type + ' ' + classes + '" id="frm_' + type + '_' + fieldId + '-' + opt.key + '"><label for="' + id +
4955 + '"><input type="' + type +
4956 + '" name="item_meta[' + fieldId + ']' + ( type === 'checkbox' ? '[]' : '' ) +
4957 + '" value="' + opt.saved + '" id="' + id + '"' + ( isProduct ? ' data-price="' + opt.price + '"' : '' ) + ( opt.checked ? ' checked="checked"' : '' ) + '> ' + opt.label + '</label>' +
4958 + ( isOther ? other : '' ) +
4959 + '</div>';
4960 +
4961 + return single;
4962 + }
4963 +
4964 + function fillDropdownOpts( field, atts ) {
4965 + if ( field === null ) {
4966 + return;
4967 + }
4968 + var sourceID = atts.sourceID,
4969 + placeholder = atts.placeholder,
4970 + isProduct = isProductField( sourceID ),
4971 + showOther = atts.other;
4972 +
4973 + removeDropdownOpts( field );
4974 + var opts = getMultipleOpts( sourceID ),
4975 + hasPlaceholder = ( typeof placeholder !== 'undefined' );
4976 +
4977 + for ( var i = 0; i < opts.length; i++ ) {
4978 + var label = opts[ i ].label,
4979 + isOther = opts[ i ].key.indexOf( 'other' ) !== -1;
4980 +
4981 + if ( hasPlaceholder && label !== '' ) {
4982 + addBlankSelectOption( field, placeholder );
4983 + } else if ( hasPlaceholder ) {
4984 + label = placeholder;
4985 + }
4986 + hasPlaceholder = false;
4987 +
4988 + if ( ! isOther || showOther ) {
4989 + var opt = document.createElement( 'option' );
4990 + opt.value = opts[ i ].saved;
4991 + opt.innerHTML = label;
4992 +
4993 + if ( isProduct ) {
4994 + opt.setAttribute( 'data-price', opts[ i ].price );
4995 + }
4996 +
4997 + field.appendChild( opt );
4998 + }
4999 + }
5000 + }
5001 +
5002 + function addBlankSelectOption( field, placeholder ) {
5003 + var opt = document.createElement( 'option' ),
5004 + firstChild = field.firstChild;
5005 +
5006 + opt.value = '';
5007 + opt.innerHTML = placeholder;
5008 + if ( firstChild !== null ) {
5009 + field.insertBefore( opt, firstChild );
5010 + field.selectedIndex = 0;
5011 + } else {
5012 + field.appendChild( opt );
5013 + }
5014 + }
5015 +
5016 + function getMultipleOpts( fieldId ) {
5017 + var i, saved, labelName, label, key, optObj,
5018 + image, savedLabel, input, field, checkbox, fieldType,
5019 + checked = false,
5020 + opts = [],
5021 + imageUrl = '',
5022 +
5023 + optVals = jQuery( 'input[name^="field_options[options_' + fieldId + ']"]' ),
5024 + separateValues = usingSeparateValues( fieldId ),
5025 + hasImageOptions = imagesAsOptions( fieldId ),
5026 + showLabelWithImage = showingLabelWithImage( fieldId ),
5027 + isProduct = isProductField( fieldId );
5028 +
5029 + for ( i = 0; i < optVals.length; i++ ) {
5030 + 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 ) {
5031 + continue;
5032 + }
5033 + saved = optVals[ i ].value;
5034 + label = saved;
5035 + key = optVals[ i ].name.replace( 'field_options[options_' + fieldId + '][', '' ).replace( '[label]', '' ).replace( ']', '' );
5036 +
5037 + if ( separateValues ) {
5038 + labelName = optVals[ i ].name.replace( '[label]', '[value]' );
5039 + saved = jQuery( 'input[name="' + labelName + '"]' ).val();
5040 + }
5041 +
5042 + if ( hasImageOptions ) {
5043 + imageUrl = getImageUrlFromInput( optVals[i]);
5044 + fieldType = radioOrCheckbox( fieldId );
5045 + label = getImageLabel( label, showLabelWithImage, imageUrl, fieldType );
5046 + }
5047 +
5048 + /**
5049 + * @since 5.0.04
5050 + */
5051 + label = frmAdminBuild.hooks.applyFilters( 'frm_choice_field_label', label, fieldId, optVals[ i ], hasImageOptions );
5052 +
5053 + checked = getChecked( optVals[ i ].id );
5054 +
5055 + optObj = {
5056 + saved: saved,
5057 + label: label,
5058 + checked: checked,
5059 + key: key
5060 + };
5061 +
5062 + if ( isProduct ) {
5063 + labelName = optVals[ i ].name.replace( '[label]', '[price]' );
5064 + optObj.price = jQuery( 'input[name="' + labelName + '"]' ).val();
5065 + }
5066 +
5067 + opts.push( optObj );
5068 + }
5069 +
5070 + return opts;
5071 + }
5072 +
5073 + function radioOrCheckbox( fieldId ) {
5074 + var settings = document.getElementById( 'frm-single-settings-' + fieldId );
5075 + if ( settings === null ) {
5076 + return 'radio';
5077 + }
5078 +
5079 + return settings.classList.contains( 'frm-type-checkbox' ) ? 'checkbox' : 'radio';
5080 + }
5081 +
5082 + function getImageUrlFromInput( optVal ) {
5083 + var img,
5084 + wrapper = jQuery( optVal ).siblings( '.frm_image_preview_wrapper' );
5085 +
5086 + if ( ! wrapper.length ) {
5087 + return '';
5088 + }
5089 +
5090 + img = wrapper.find( 'img' );
5091 + if ( ! img.length ) {
5092 + return '';
5093 + }
5094 +
5095 + return img.attr( 'src' );
5096 + }
5097 +
5098 + function getImageLabel( label, showLabelWithImage, imageUrl, fieldType ) {
5099 + var imageLabelClass, fullLabel,
5100 + originalLabel = label,
5101 + shape = fieldType === 'checkbox' ? 'square' : 'circle';
5102 +
5103 + fullLabel = '<div class="frm_selected_checkmark"><svg class="frmsvg"><use xlink:href="#frm_checkmark_' + shape + '_icon"></svg></div>';
5104 + if ( imageUrl ) {
5105 + fullLabel += '<img src="' + imageUrl + '" alt="' + originalLabel + '" />';
5106 + } else {
5107 + fullLabel += '<div class="frm_empty_url">' + frm_admin_js.image_placeholder_icon + '</div>';
5108 + }
5109 + if ( showLabelWithImage ) {
5110 + fullLabel += '<span class="frm_text_label_for_image"><span class="frm_text_label_for_image_inner">' + originalLabel + '</span></span>';
5111 + }
5112 +
5113 + imageLabelClass = showLabelWithImage ? ' frm_label_with_image' : '';
5114 +
5115 + return ( '<span class="frm_image_option_container' + imageLabelClass + '">' + fullLabel + '</span>' );
5116 + }
5117 +
5118 + function getChecked( id ) {
5119 + field = jQuery( '#' + id );
5120 +
5121 + if ( field.length === 0 ) {
5122 + return false;
5123 + }
5124 +
5125 + checkbox = field.siblings( 'input[type=checkbox]' );
5126 +
5127 + return checkbox.length && checkbox.prop( 'checked' );
5128 + }
5129 +
5130 + function removeDropdownOpts( field ) {
5131 + var i;
5132 + if ( typeof field.options === 'undefined' ) {
5133 + return;
5134 + }
5135 +
5136 + for ( i = field.options.length - 1; i >= 0; i-- ) {
5137 + field.remove( i );
5138 + }
5139 + }
5140 +
5141 + /**
5142 + * Is the box checked to use separate values?
5143 + */
5144 + function usingSeparateValues( fieldId ) {
5145 + return isChecked( 'separate_value_' + fieldId );
5146 + }
5147 +
5148 + /**
5149 + * Is the box checked to use images as options?
5150 + */
5151 + function imagesAsOptions( fieldId ) {
5152 + var checked = false,
5153 + field = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' );
5154 +
5155 + for ( var i = 0; i < field.length; i++ ) {
5156 + if ( field[ i ].checked ) {
5157 + checked = '0' !== field[ i ].value;
5158 + }
5159 + }
5160 +
5161 + /**
5162 + * @since 5.0.04
5163 + */
5164 + return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_images_as_options', checked, fieldId );
5165 + }
5166 +
5167 + function showingLabelWithImage( fieldId ) {
5168 + const isShowing = ! isChecked( 'hide_image_text_' + fieldId );
5169 +
5170 + /**
5171 + * @since 5.0.04
5172 + */
5173 + return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_showing_label_with_image', isShowing, fieldId );
5174 + }
5175 +
5176 + function isChecked( id ) {
5177 + var field = document.getElementById( id );
5178 + if ( field === null ) {
5179 + return false;
5180 + } else {
5181 + return field.checked;
5182 + }
5183 + }
5184 +
5185 + /* TODO: Is this still used? */
5186 + function checkUniqueOpt( id, text ) {
5187 + if ( id.indexOf( 'field_key_' ) === 0 ) {
5188 + var a = id.split( '-' );
5189 + jQuery.each( jQuery( 'label[id^="' + a[0] + '"]' ), function( k, v ) {
5190 + var c = false;
5191 + if ( ! c && jQuery( v ).attr( 'id' ) != id && jQuery( v ).html() == text ) {
5192 + c = true;
5193 + infoModal( 'Saved values cannot be identical.' );
5194 + }
5195 + });
5196 + }
5197 + }
5198 +
5199 + function setStarValues() {
5200 + /*jshint validthis:true */
5201 + var fieldID = this.id.replace( 'radio_maxnum_', '' );
5202 + var container = jQuery( '#field_' + fieldID + '_inner_container .frm-star-group' );
5203 + var fieldKey = document.getElementsByName( 'field_options[field_key_' + fieldID + ']' )[0].value;
5204 + container.html( '' );
5205 +
5206 + var min = 1;
5207 + var max = this.value;
5208 + if ( min > max ) {
5209 + max = min;
5210 + }
5211 +
5212 + for ( var i = min; i <= max; i++ ) {
5213 + 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>' );
5214 + }
5215 + }
5216 +
5217 + function setScaleValues() {
5218 + /*jshint validthis:true */
5219 + var isMin = this.id.indexOf( 'minnum' ) !== -1;
5220 + var fieldID = this.id.replace( 'scale_maxnum_', '' ).replace( 'scale_minnum_', '' );
5221 + var min = this.value;
5222 + var max = this.value;
5223 + if ( isMin ) {
5224 + max = document.getElementById( 'scale_maxnum_' + fieldID ).value;
5225 + } else {
5226 + min = document.getElementById( 'scale_minnum_' + fieldID ).value;
5227 + }
5228 +
5229 + updateScaleValues( parseInt( min, 10 ), parseInt( max, 10 ), fieldID );
5230 + }
5231 +
5232 + function updateScaleValues( min, max, fieldID ) {
5233 + var container = jQuery( '#field_' + fieldID + '_inner_container .frm_form_fields' );
5234 + container.html( '' );
5235 +
5236 + if ( min >= max ) {
5237 + max = min + 1;
5238 + }
5239 +
5240 + for ( var i = min; i <= max; i++ ) {
5241 + container.append( '<div class="frm_scale"><label><input type="hidden" name="field_options[options_' + fieldID + '][' + i + ']" value="' + i + '"> <input type="radio" name="item_meta[' + fieldID + ']" value="' + i + '"> ' + i + ' </label></div>' );
5242 + }
5243 + container.append( '<div class="clear"></div>' );
5244 + }
5245 +
5246 + function getFieldValues() {
5247 + /*jshint validthis:true */
5248 + var isTaxonomy,
5249 + val = this.value;
5250 +
5251 + if ( val ) {
5252 + var parentIDs = this.parentNode.id.replace( 'frm_logic_', '' ).split( '_' );
5253 + var fieldID = parentIDs[0];
5254 + var metaKey = parentIDs[1];
5255 + var valueField = document.getElementById( 'frm_field_id_' + val );
5256 + var valueFieldType = valueField.getAttribute( 'data-ftype' );
5257 + var fill = document.getElementById( 'frm_show_selected_values_' + fieldID + '_' + metaKey );
5258 + var optionName = 'field_options[hide_opt_' + fieldID + '][]';
5259 + var optionID = 'frm_field_logic_opt_' + fieldID;
5260 + var input = false;
5261 + var showSelect = ( valueFieldType === 'select' || valueFieldType === 'checkbox' || valueFieldType === 'radio' );
5262 + var showText = ( valueFieldType === 'text' || valueFieldType === 'email' || valueFieldType === 'phone' || valueFieldType === 'url' || valueFieldType === 'number' );
5263 +
5264 + if ( showSelect ) {
5265 + isTaxonomy = document.getElementById( 'frm_has_hidden_options_' + val );
5266 + if ( isTaxonomy !== null ) {
5267 + // get the category options with ajax
5268 + showSelect = false;
5269 + }
5270 + }
5271 +
5272 + if ( showSelect || showText ) {
5273 + fill.innerHTML = '';
5274 + if ( showSelect ) {
5275 + input = document.createElement( 'select' );
5276 + } else {
5277 + input = document.createElement( 'input' );
5278 + input.type = 'text';
5279 + }
5280 + input.name = optionName;
5281 + input.id = optionID + '_' + metaKey;
5282 + fill.appendChild( input );
5283 +
5284 + if ( showSelect ) {
5285 + var fillField = document.getElementById( input.id );
5286 + fillDropdownOpts( fillField, {
5287 + sourceID: val,
5288 + placeholder: '',
5289 + other: true
5290 + });
5291 + }
5292 + } else {
5293 + var thisType = this.getAttribute( 'data-type' );
5294 + frmGetFieldValues( val, fieldID, metaKey, thisType );
5295 + }
5296 + }
5297 + }
5298 +
5299 + function getFieldSelection() {
5300 + /*jshint validthis:true */
5301 + var formId = this.value;
5302 + if ( formId ) {
5303 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
5304 + getTaxOrFieldSelection( formId, fieldId );
5305 + }
5306 + }
5307 +
5308 + function getTaxOrFieldSelection( formId, fieldId ) {
5309 + if ( formId ) {
5310 + jQuery.ajax({
5311 + type: 'POST',
5312 + url: ajaxurl,
5313 + data: {
5314 + action: 'frm_get_field_selection',
5315 + field_id: fieldId,
5316 + form_id: formId,
5317 + nonce: frmGlobal.nonce
5318 + },
5319 + success: function( msg ) {
5320 + jQuery( '#frm_show_selected_fields_' + fieldId ).html( msg ).show();
5321 + }
5322 + });
5323 + }
5324 + }
5325 +
5326 + function updateFieldOrder() {
5327 + var fields, fieldId, field, currentOrder, newOrder;
5328 + renumberPageBreaks();
5329 + jQuery( '#frm-show-fields' ).each( function( i ) {
5330 + fields = jQuery( 'li.frm_field_box', this );
5331 + for ( i = 0; i < fields.length; i++ ) {
5332 + fieldId = fields[ i ].getAttribute( 'data-fid' );
5333 + field = jQuery( 'input[name="field_options[field_order_' + fieldId + ']"]' );
5334 + currentOrder = field.val();
5335 + newOrder = i + 1;
5336 +
5337 + if ( currentOrder != newOrder ) {
5338 + field.val( newOrder );
5339 + singleField = document.getElementById( 'frm-single-settings-' + fieldId );
5340 +
5341 + moveFieldSettings( singleField );
5342 + fieldUpdated();
5343 + }
5344 + }
5345 + });
5346 + }
5347 +
5348 + function toggleSectionHolder() {
5349 + document.querySelectorAll( '.start_divider' ).forEach(
5350 + function( divider ) {
5351 + toggleOneSectionHolder( jQuery( divider ) );
5352 + }
5353 + );
5354 + }
5355 +
5356 + function toggleOneSectionHolder( $section ) {
5357 + var noSectionFields, $rows, length, index, sectionHasFields;
5358 +
5359 + if ( ! $section.length ) {
5360 + return;
5361 + }
5362 +
5363 + $rows = $section.find( 'ul.frm_sorting' );
5364 + sectionHasFields = false;
5365 + length = $rows.length;
5366 + for ( index = 0; index < length; ++index ) {
5367 + if ( 0 !== getFieldsInRow( jQuery( $rows.get( index ) ) ).length ) {
5368 + sectionHasFields = true;
5369 + break;
5370 + }
5371 + }
5372 +
5373 + noSectionFields = $section.parent().children( '.frm_no_section_fields' ).get( 0 );
5374 + noSectionFields.classList.toggle( 'frm_block', ! sectionHasFields );
5375 + }
5376 +
5377 + function slideDown() {
5378 + /*jshint validthis:true */
5379 + var id = jQuery( this ).data( 'slidedown' );
5380 + var $thisId = jQuery( document.getElementById( id ) );
5381 + if ( $thisId.is( ':hidden' ) ) {
5382 + $thisId.slideDown( 'fast' );
5383 + this.style.display = 'none';
5384 + }
5385 + return false;
5386 + }
5387 +
5388 + function slideUp() {
5389 + /*jshint validthis:true */
5390 + var id = jQuery( this ).data( 'slideup' );
5391 + var $thisId = jQuery( document.getElementById( id ) );
5392 + $thisId.slideUp( 'fast' );
5393 + $thisId.siblings( 'a' ).show();
5394 + return false;
5395 + }
5396 +
5397 + function adjustVisibilityValuesForEveryoneValues( element, option ) {
5398 + if ( '' === option.getAttribute( 'value' ) ) {
5399 + onEveryoneOptionSelected( jQuery( this ) );
5400 + } else {
5401 + unselectEveryoneOptionIfSelected( jQuery( this ) );
5402 + }
5403 + }
5404 +
5405 + function onEveryoneOptionSelected( $select ) {
5406 + $select.val( '' );
5407 + $select.next( '.btn-group' ).find( '.multiselect-container li input[value!=""]' ).prop( 'checked', false );
5408 + }
5409 +
5410 + function unselectEveryoneOptionIfSelected( $select ) {
5411 + var selectedValues = $select.val(),
5412 + index;
5413 +
5414 + if ( selectedValues === null ) {
5415 + $select.next( '.btn-group' ).find( '.multiselect-container li input[value=""]' ).prop( 'checked', true );
5416 + onEveryoneOptionSelected( $select );
5417 + return;
5418 + }
5419 +
5420 + index = selectedValues.indexOf( '' );
5421 + if ( index >= 0 ) {
5422 + selectedValues.splice( index, 1 );
5423 + $select.val( selectedValues );
5424 + $select.next( '.btn-group' ).find( '.multiselect-container li input[value=""]' ).prop( 'checked', false );
5425 + }
5426 + }
5427 +
5428 + /**
5429 + * Get rid of empty container that inserts extra space.
5430 + */
5431 + function hideEmptyEle() {
5432 + jQuery( '.frm-hide-empty' ).each( function() {
5433 + if ( jQuery( this ).text().trim().length === 0 ) {
5434 + jQuery( this ).remove();
5435 + }
5436 + });
5437 + }
5438 +
5439 + /* Change the classes in the builder */
5440 + function changeFieldClass( field, setting ) {
5441 + var classes, replace, alignField,
5442 + replaceWith = ' ' + setting.value,
5443 + fieldId = field.getAttribute( 'data-fid' );
5444 +
5445 + // Include classes from multiple settings.
5446 + if ( typeof fieldId !== 'undefined' ) {
5447 + if ( setting.classList.contains( 'field_options_align' ) ) {
5448 + replaceWith += ' ' + document.getElementById( 'frm_classes_' + fieldId ).value;
5449 + } else if ( setting.classList.contains( 'frm_classes' ) ) {
5450 + alignField = document.getElementById( 'field_options_align_' + fieldId );
5451 + if ( alignField !== null ) {
5452 + replaceWith += ' ' + alignField.value;
5453 + }
5454 + }
5455 + }
5456 + replaceWith += ' ';
5457 +
5458 + // Allow for the column number dropdown.
5459 + replaceWith = replaceWith.replace( ' block ', ' ' ).replace( ' inline ', ' horizontal_radio ' ).replace( ' frm_alignright ', ' ' );
5460 +
5461 + classes = field.className.split( ' frmstart ' )[1];
5462 + classes = 0 === classes.indexOf( 'frmend ' ) ? '' : classes.split( ' frmend ' )[0];
5463 +
5464 + if ( classes.trim() === '' ) {
5465 + replace = ' frmstart frmend ';
5466 + if ( -1 === field.className.indexOf( replace ) ) {
5467 + replace = ' frmstart frmend ';
5468 + }
5469 + replaceWith = ' frmstart ' + replaceWith.trim() + ' frmend ';
5470 + } else {
5471 + replace = classes.trim();
5472 + replaceWith = replaceWith.trim();
5473 + }
5474 +
5475 + field.className = field.className.replace( replace, replaceWith );
5476 + }
5477 +
5478 + function maybeShowInlineModal( e ) {
5479 + /*jshint validthis:true */
5480 + e.preventDefault();
5481 + showInlineModal( this );
5482 + }
5483 +
5484 + function showInlineModal( icon, input ) {
5485 + var box = document.getElementById( icon.getAttribute( 'data-open' ) ),
5486 + container = jQuery( icon ).closest( 'p' ),
5487 + inputTrigger = ( typeof input !== 'undefined' );
5488 +
5489 + if ( container.hasClass( 'frm-open' ) ) {
5490 + container.removeClass( 'frm-open' );
5491 + box.classList.add( 'frm_hidden' );
5492 + } else {
5493 + if ( ! inputTrigger ) {
5494 + input = getInputForIcon( icon );
5495 + }
5496 + if ( input !== null ) {
5497 + if ( ! inputTrigger ) {
5498 + input.focus();
5499 + }
5500 + container.after( box );
5501 + box.setAttribute( 'data-fills', input.id );
5502 +
5503 + if ( box.id.indexOf( 'frm-calc-box' ) === 0 ) {
5504 + popCalcFields( box, true );
5505 + }
5506 + }
5507 +
5508 + container.addClass( 'frm-open' );
5509 + box.classList.remove( 'frm_hidden' );
5510 + }
5511 + }
5512 +
5513 + function dismissInlineModal( e ) {
5514 + /*jshint validthis:true */
5515 + e.preventDefault();
5516 + this.parentNode.classList.add( 'frm_hidden' );
5517 + jQuery( '.frm-open [data-open="' + this.parentNode.id + '"]' ).closest( '.frm-open' ).removeClass( 'frm-open' );
5518 + }
5519 +
5520 + function changeInputtedValue() {
5521 + /*jshint validthis:true */
5522 + var i,
5523 + action = this.getAttribute( 'data-frmchange' ).split( ',' );
5524 +
5525 + for ( i = 0; i < action.length; i++ ) {
5526 + if ( action[i] === 'updateOption' ) {
5527 + changeHiddenSeparateValue( this );
5528 + } else if ( action[i] === 'updateDefault' ) {
5529 + changeDefaultRadioValue( this );
5530 + } else {
5531 + this.value = this.value[ action[i] ]();
5532 + }
5533 + }
5534 + }
5535 +
5536 + /**
5537 + * When the saved value is changed, update the default value radio.
5538 + */
5539 + function changeDefaultRadioValue( input ) {
5540 + var parentLi = getOptionParent( input ),
5541 + key = parentLi.getAttribute( 'data-optkey' ),
5542 + fieldId = getOptionFieldId( parentLi, key ),
5543 + defaultRadio = parentLi.querySelector( 'input[name="default_value_' + fieldId + '"]' );
5544 +
5545 + if ( defaultRadio !== null ) {
5546 + defaultRadio.value = input.value;
5547 + }
5548 + }
5549 +
5550 + /**
5551 + * If separate values are not enabled, change the saved value when
5552 + * the displayed value is changed.
5553 + */
5554 + function changeHiddenSeparateValue( input ) {
5555 + var savedVal,
5556 + parentLi = getOptionParent( input ),
5557 + key = parentLi.getAttribute( 'data-optkey' ),
5558 + fieldId = getOptionFieldId( parentLi, key ),
5559 + sep = document.getElementById( 'separate_value_' + fieldId );
5560 +
5561 + if ( sep !== null && sep.checked === false ) {
5562 + // If separate values are not turned on.
5563 + savedVal = document.getElementById( 'field_key_' + fieldId + '-' + key );
5564 + savedVal.value = input.value;
5565 + changeDefaultRadioValue( savedVal );
5566 + }
5567 + }
5568 +
5569 + function getOptionParent( input ) {
5570 + var parentLi = input.parentNode;
5571 + if ( parentLi.tagName !== 'LI' ) {
5572 + parentLi = parentLi.parentNode;
5573 + }
5574 + return parentLi;
5575 + }
5576 +
5577 + function getOptionFieldId( li, key ) {
5578 + var liId = li.id;
5579 +
5580 + return liId.replace( 'frm_delete_field_', '' ).replace( '-' + key + '_container', '' );
5581 + }
5582 +
5583 + function submitBuild() {
5584 + /*jshint validthis:true */
5585 + var $thisEle = jQuery( this );
5586 + var p = $thisEle.html();
5587 +
5588 + preFormSave( this );
5589 +
5590 + var $form = jQuery( builderForm );
5591 + var v = JSON.stringify( $form.serializeArray() );
5592 +
5593 + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( v );
5594 + jQuery.ajax({
5595 + type: 'POST',
5596 + url: ajaxurl,
5597 + data: {action: 'frm_save_form', 'frm_compact_fields': v, nonce: frmGlobal.nonce},
5598 + success: function( msg ) {
5599 + afterFormSave( $thisEle, p );
5600 +
5601 + var $postStuff = document.getElementById( 'post-body-content' );
5602 + var $html = document.createElement( 'div' );
5603 + $html.setAttribute( 'class', 'frm_updated_message' );
5604 + $html.innerHTML = msg;
5605 + $postStuff.insertBefore( $html, $postStuff.firstChild );
5606 + },
5607 + error: function() {
5608 + triggerSubmit( document.getElementById( 'frm_js_build_form' ) );
5609 + }
5610 + });
5611 + }
5612 +
5613 + function triggerSubmit( form ) {
5614 + var button = form.ownerDocument.createElement( 'input' );
5615 + button.style.display = 'none';
5616 + button.type = 'submit';
5617 + form.appendChild( button ).click();
5618 + form.removeChild( button );
5619 + }
5620 +
5621 + function triggerChange( element ) {
5622 + jQuery( element ).trigger( 'change' );
5623 + }
5624 +
5625 + function submitNoAjax() {
5626 + /*jshint validthis:true */
5627 + var form;
5628 +
5629 + preFormSave( this );
5630 + form = jQuery( builderForm );
5631 + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( JSON.stringify( form.serializeArray() ) );
5632 + triggerSubmit( document.getElementById( 'frm_js_build_form' ) );
5633 + }
5634 +
5635 + function preFormSave( b ) {
5636 + removeWPUnload();
5637 + if ( jQuery( 'form.inplace_form' ).length ) {
5638 + jQuery( '.inplace_save, .postbox' ).trigger( 'click' );
5639 + }
5640 +
5641 + $button = jQuery( b );
5642 +
5643 + if ( $button.hasClass( 'frm_button_submit' ) ) {
5644 + $button.addClass( 'frm_loading_form' );
5645 + $button.html( frm_admin_js.saving );
5646 + } else {
5647 + $button.addClass( 'frm_loading_button' );
5648 + $button.val( frm_admin_js.saving );
5649 + }
5650 + }
5651 +
5652 + function afterFormSave( $button, buttonVal ) {
5653 + $button.removeClass( 'frm_loading_form' ).removeClass( 'frm_loading_button' );
5654 + $button.html( frm_admin_js.saved );
5655 + resetOptionTextDetails();
5656 + fieldsUpdated = 0;
5657 +
5658 + setTimeout( function() {
5659 + jQuery( '.frm_updated_message' ).fadeOut( 'slow', function() {
5660 + this.parentNode.removeChild( this );
5661 + });
5662 + $button.fadeOut( 'slow', function() {
5663 + $button.html( buttonVal );
5664 + $button.show();
5665 + });
5666 + }, 5000 );
5667 + }
5668 +
5669 + function initUpgradeModal() {
5670 + var $info = initModal( '#frm_upgrade_modal' );
5671 + if ( $info === false ) {
5672 + return;
5673 + }
5674 +
5675 + jQuery( document ).on( 'click', '[data-upgrade]', function( event ) {
5676 + var upgradeLabel, requires, button, link, content;
5677 +
5678 + event.preventDefault();
5679 + upgradeLabel = this.getAttribute( 'data-upgrade' );
5680 +
5681 + if ( '' === upgradeLabel ) {
5682 + // if the upgrade level is empty, it's because this upgrade is already active.
5683 + return;
5684 + }
5685 +
5686 + jQuery( '#frm_upgrade_modal .frm_lock_icon' ).removeClass( 'frm_lock_open_icon' );
5687 + jQuery( '#frm_upgrade_modal .frm_lock_icon use' ).attr( 'xlink:href', '#frm_lock_icon' );
5688 +
5689 + requires = this.getAttribute( 'data-requires' );
5690 + if ( typeof requires === 'undefined' || requires === null || requires === '' ) {
5691 + requires = 'Pro';
5692 + }
5693 + jQuery( '.license-level' ).text( requires );
5694 +
5695 + // If one click upgrade, hide other content
5696 + addOneClickModal( this );
5697 +
5698 + jQuery( '.frm_feature_label' ).text( upgradeLabel );
5699 + jQuery( '#frm_upgrade_modal h2' ).show();
5700 +
5701 + $info.dialog( 'open' );
5702 +
5703 + // set the utm medium
5704 + button = $info.find( '.button-primary:not(#frm-oneclick-button)' );
5705 + link = button.attr( 'href' ).replace( /(medium=)[a-z_-]+/ig, '$1' + this.getAttribute( 'data-medium' ) );
5706 + content = this.getAttribute( 'data-content' );
5707 + if ( content === undefined ) {
5708 + content = '';
5709 + }
5710 + link = link.replace( /(content=)[a-z_-]+/ig, '$1' + content );
5711 + button.attr( 'href', link );
5712 + return false;
5713 + });
5714 + }
5715 +
5716 + /**
5717 + * Allow addons to be installed from the upgrade modal.
5718 + */
5719 + function addOneClickModal( link ) {
5720 + var oneclickMessage = document.getElementById( 'frm-oneclick' ),
5721 + oneclick = link.getAttribute( 'data-oneclick' ),
5722 + customLink = link.getAttribute( 'data-link' ),
5723 + showLink = document.getElementById( 'frm-upgrade-modal-link' ),
5724 + upgradeMessage = document.getElementById( 'frm-upgrade-message' ),
5725 + newMessage = link.getAttribute( 'data-message' ),
5726 + button = document.getElementById( 'frm-oneclick-button' ),
5727 + showIt = 'block',
5728 + showMsg = 'block',
5729 + hideIt = 'none';
5730 +
5731 + // If one click upgrade, hide other content.
5732 + if ( oneclickMessage !== null && typeof oneclick !== 'undefined' && oneclick ) {
5733 + if ( newMessage === null ) {
5734 + showMsg = 'none';
5735 + }
5736 + showIt = 'none';
5737 + hideIt = 'block';
5738 + oneclick = JSON.parse( oneclick );
5739 +
5740 + button.className = button.className.replace( ' frm-install-addon', '' ).replace( ' frm-activate-addon', '' );
5741 + button.className = button.className + ' ' + oneclick.class;
5742 + button.rel = oneclick.url;
5743 + }
5744 +
5745 + // Use a custom message in the modal.
5746 + if ( newMessage === null || typeof newMessage === 'undefined' || newMessage === '' ) {
5747 + newMessage = upgradeMessage.getAttribute( 'data-default' );
5748 + }
5749 + upgradeMessage.innerHTML = newMessage;
5750 +
5751 + // Either set the link or use the default.
5752 + if ( customLink === null || typeof customLink === 'undefined' || customLink === '' ) {
5753 + customLink = showLink.getAttribute( 'data-default' );
5754 + }
5755 + showLink.href = customLink;
5756 +
5757 + document.getElementById( 'frm-addon-status' ).style.display = 'none';
5758 + oneclickMessage.style.display = hideIt;
5759 + button.style.display = hideIt === 'block' ? 'inline-block' : hideIt;
5760 + upgradeMessage.style.display = showMsg;
5761 + showLink.style.display = showIt === 'block' ? 'inline-block' : showIt;
5762 + }
5763 +
5764 + /* Form settings */
5765 +
5766 + function showInputIcon( parentClass ) {
5767 + if ( typeof parentClass === 'undefined' ) {
5768 + parentClass = '';
5769 + }
5770 + maybeAddFieldSelection( parentClass );
5771 + 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>' );
5772 + }
5773 +
5774 + /**
5775 + * For reverse compatibility. Check for fields that were
5776 + * using the old sidebar.
5777 + */
5778 + function maybeAddFieldSelection( parentClass ) {
5779 + var i,
5780 + 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' );
5781 + for ( i = 0; i < missingClass.length; i++ ) {
5782 + missingClass[i].parentNode.classList.add( 'frm_has_shortcodes' );
5783 + }
5784 + }
5785 +
5786 + function showSuccessOpt() {
5787 + /*jshint validthis:true */
5788 + var c = 'success';
5789 + if ( this.name === 'options[edit_action]' ) {
5790 + c = 'edit';
5791 + }
5792 + var v = jQuery( this ).val();
5793 + jQuery( '.' + c + '_action_box' ).hide();
5794 + if ( v === 'redirect' ) {
5795 + jQuery( '.' + c + '_action_redirect_box.' + c + '_action_box' ).fadeIn( 'slow' );
5796 + } else if ( v === 'page' ) {
5797 + jQuery( '.' + c + '_action_page_box.' + c + '_action_box' ).fadeIn( 'slow' );
5798 + } else {
5799 + jQuery( '.' + c + '_action_message_box.' + c + '_action_box' ).fadeIn( 'slow' );
5800 + }
5801 + }
5802 +
5803 + function copyFormAction() {
5804 + /*jshint validthis:true */
5805 + if ( waitForActionToLoadBeforeCopy( this ) ) {
5806 + return;
5807 + }
5808 +
5809 + var action = jQuery( this ).closest( '.frm_form_action_settings' ).clone();
5810 + var currentID = action.attr( 'id' ).replace( 'frm_form_action_', '' );
5811 + var newID = newActionId( currentID );
5812 + action.find( '.frm_action_id, .frm-btn-group' ).remove();
5813 + action.find( 'input[name$="[' + currentID + '][ID]"]' ).val( '' );
5814 + action.find( '.widget-inside' ).hide();
5815 +
5816 + // the .html() gets original values, so they need to be set
5817 + action.find( 'input[type=text], textarea, input[type=number]' ).prop( 'defaultValue', function() {
5818 + return this.value;
5819 + });
5820 +
5821 + action.find( 'input[type=checkbox], input[type=radio]' ).prop( 'defaultChecked', function() {
5822 + return this.checked;
5823 + });
5824 +
5825 + var rename = new RegExp( '\\[' + currentID + '\\]', 'g' );
5826 + var reid = new RegExp( '_' + currentID + '"', 'g' );
5827 + var reclass = new RegExp( '-' + currentID + '"', 'g' );
5828 + var revalue = new RegExp( '"' + currentID + '"', 'g' ); // if a field id matches, this could cause trouble
5829 +
5830 + var html = action.html().replace( rename, '[' + newID + ']' ).replace( reid, '_' + newID + '"' );
5831 + html = html.replace( reclass, '-' + newID + '"' ).replace( revalue, '"' + newID + '"' );
5832 + var div = '<div id="frm_form_action_' + newID + '" class="widget frm_form_action_settings frm_single_email_settings" data-actionkey="' + newID + '">';
5833 +
5834 + jQuery( '#frm_notification_settings' ).append( div + html + '</div>' );
5835 + initiateMultiselect();
5836 + }
5837 +
5838 + function waitForActionToLoadBeforeCopy( element ) {
5839 + var $trigger = jQuery( element ),
5840 + $original = $trigger.closest( '.frm_form_action_settings' ),
5841 + $inside = $original.find( '.widget-inside' ),
5842 + $top;
5843 +
5844 + if ( $inside.find( 'p, div, table' ).length ) {
5845 + return false;
5846 + }
5847 +
5848 + $top = $original.find( '.widget-top' );
5849 + $top.on( 'frm-action-loaded', function() {
5850 + $trigger.trigger( 'click' );
5851 + $original.removeClass( 'open' );
5852 + $inside.hide();
5853 + });
5854 + $top.trigger( 'click' );
5855 + return true;
5856 + }
5857 +
5858 + function newActionId( currentID ) {
5859 + var newID = parseInt( currentID, 10 ) + 11;
5860 + var exists = document.getElementById( 'frm_form_action_' + newID );
5861 + if ( exists !== null ) {
5862 + newID++;
5863 + newID = newActionId( newID );
5864 + }
5865 + return newID;
5866 + }
5867 +
5868 + function addFormAction() {
5869 + /*jshint validthis:true */
5870 + var type, actionId, formId, placeholderSetting, actionsList;
5871 +
5872 + type = jQuery( this ).data( 'actiontype' );
5873 +
5874 + if ( isAtLimitForActionType( type ) ) {
5875 + return;
5876 + }
5877 +
5878 + actionId = getNewActionId();
5879 + formId = thisFormId;
5880 +
5881 + placeholderSetting = document.createElement( 'div' );
5882 + placeholderSetting.classList.add( 'frm_single_' + type + '_settings' );
5883 +
5884 + actionsList = document.getElementById( 'frm_notification_settings' );
5885 + actionsList.appendChild( placeholderSetting );
5886 +
5887 + jQuery.ajax({
5888 + type: 'POST',
5889 + url: ajaxurl,
5890 + data: {
5891 + action: 'frm_add_form_action',
5892 + type: type,
5893 + list_id: actionId,
5894 + form_id: formId,
5895 + nonce: frmGlobal.nonce
5896 + },
5897 + success: function( html ) {
5898 + fieldUpdated();
5899 + placeholderSetting.remove();
5900 +
5901 + // Close any open actions first.
5902 + jQuery( '.frm_form_action_settings.open' ).removeClass( 'open' );
5903 +
5904 + jQuery( actionsList ).append( html );
5905 + jQuery( '.frm_form_action_settings' ).fadeIn( 'slow' );
5906 +
5907 + var newAction = document.getElementById( 'frm_form_action_' + actionId );
5908 +
5909 + newAction.classList.add( 'open' );
5910 + document.getElementById( 'post-body-content' ).scroll({
5911 + top: newAction.offsetTop + 10,
5912 + left: 0,
5913 + behavior: 'smooth'
5914 + });
5915 +
5916 + //check if icon should be active
5917 + checkActiveAction( type );
5918 + initiateMultiselect();
5919 + showInputIcon( '#frm_form_action_' + actionId );
5920 + }
5921 + });
5922 + }
5923 +
5924 + function toggleActionGroups() {
5925 + /*jshint validthis:true */
5926 + var actions = document.getElementById( 'frm_email_addon_menu' ).classList,
5927 + search = document.getElementById( 'actions-search-input' );
5928 +
5929 + if ( actions.contains( 'frm-all-actions' ) ) {
5930 + actions.remove( 'frm-all-actions' );
5931 + actions.add( 'frm-limited-actions' );
5932 + } else {
5933 + actions.add( 'frm-all-actions' );
5934 + actions.remove( 'frm-limited-actions' );
5935 + }
5936 +
5937 + // Reset search.
5938 + search.value = '';
5939 + triggerEvent( search, 'input' );
5940 + }
5941 +
5942 + function getNewActionId() {
5943 + var actionSettings = document.querySelectorAll( '.frm_form_action_settings' ),
5944 + len = getNewRowId( actionSettings, 'frm_form_action_' );
5945 + if ( typeof document.getElementById( 'frm_form_action_' + len ) !== 'undefined' ) {
5946 + len = len + 100;
5947 + }
5948 + if ( lastNewActionIdReturned >= len ) {
5949 + len = lastNewActionIdReturned + 1;
5950 + }
5951 + lastNewActionIdReturned = len;
5952 + return len;
5953 + }
5954 +
5955 + function clickAction( obj ) {
5956 + var $thisobj = jQuery( obj );
5957 +
5958 + if ( obj.className.indexOf( 'selected' ) !== -1 ) {
5959 + return;
5960 + }
5961 + if ( obj.className.indexOf( 'edit_field_type_end_divider' ) !== -1 && $thisobj.closest( '.edit_field_type_divider' ).hasClass( 'no_repeat_section' ) ) {
5962 + return;
5963 + }
5964 +
5965 + deselectFields();
5966 + $thisobj.addClass( 'selected' );
5967 + showFieldOptions( obj );
5968 + }
5969 +
5970 + /**
5971 + * When a field is selected, show the field settings in the sidebar.
5972 + */
5973 + function showFieldOptions( obj ) {
5974 + var i, singleField,
5975 + fieldId = obj.getAttribute( 'data-fid' ),
5976 + fieldType = obj.getAttribute( 'data-type' ),
5977 + allFieldSettings = document.querySelectorAll( '.frm-single-settings:not(.frm_hidden)' );
5978 +
5979 + for ( i = 0; i < allFieldSettings.length; i++ ) {
5980 + allFieldSettings[i].classList.add( 'frm_hidden' );
5981 + }
5982 +
5983 + singleField = document.getElementById( 'frm-single-settings-' + fieldId );
5984 + moveFieldSettings( singleField );
5985 +
5986 + if ( fieldType && 'quantity' === fieldType ) {
5987 + popProductFields( jQuery( singleField ).find( '.frmjs_prod_field_opt' )[0]);
5988 + }
5989 +
5990 + singleField.classList.remove( 'frm_hidden' );
5991 + document.getElementById( 'frm-options-panel-tab' ).click();
5992 + }
5993 +
5994 + /**
5995 + * Move the settings to the sidebar the first time they are changed or selected.
5996 + * Keep the end marker at the end of the form.
5997 + */
5998 + function moveFieldSettings( singleField ) {
5999 + if ( singleField === null ) {
6000 + // The field may have not been loaded yet via ajax.
6001 + return;
6002 + }
6003 +
6004 + var classes = singleField.parentElement.classList;
6005 + if ( classes.contains( 'frm_field_box' ) || classes.contains( 'divider_section_only' ) ) {
6006 + var endMarker = document.getElementById( 'frm-end-form-marker' );
6007 + builderForm.insertBefore( singleField, endMarker );
6008 + }
6009 + }
6010 +
6011 + function showEmailRow() {
6012 + /*jshint validthis:true */
6013 + var actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' );
6014 + var rowType = this.getAttribute( 'data-emailrow' );
6015 +
6016 + jQuery( '#frm_form_action_' + actionKey + ' .frm_' + rowType + '_row' ).fadeIn( 'slow' );
6017 + jQuery( this ).fadeOut( 'slow' );
6018 + }
6019 +
6020 + function hideEmailRow() {
6021 + /*jshint validthis:true */
6022 + var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ),
6023 + rowType = this.getAttribute( 'data-emailrow' ),
6024 + emailRowSelector = '.frm_' + rowType + '_row',
6025 + emailButtonSelector = '.frm_' + rowType + '_button';
6026 +
6027 + jQuery( actionBox ).find( emailButtonSelector ).fadeIn( 'slow' );
6028 + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow', function() {
6029 + jQuery( actionBox ).find( emailRowSelector + ' input' ).val( '' );
6030 + });
6031 + }
6032 +
6033 + function showEmailWarning() {
6034 + /*jshint validthis:true */
6035 + var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ),
6036 + emailRowSelector = '.frm_from_to_match_row',
6037 + fromVal = actionBox.find( 'input[name$="[post_content][from]"]' ).val(),
6038 + toVal = actionBox.find( 'input[name$="[post_content][email_to]"]' ).val();
6039 +
6040 + if ( fromVal === toVal ) {
6041 + jQuery( actionBox ).find( emailRowSelector ).fadeIn( 'slow' );
6042 + } else {
6043 + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow' );
6044 + }
6045 + }
6046 +
6047 + function checkActiveAction( type ) {
6048 + var $actionTriggers, limitClass;
6049 +
6050 + $actionTriggers = jQuery( '.frm_' + type + '_action' );
6051 +
6052 + if ( isAtLimitForActionType( type ) ) {
6053 + limitClass = 'frm_inactive_action';
6054 + if ( getLimitForActionType( type ) > 0 ) {
6055 + limitClass += ' frm_already_used';
6056 + }
6057 + $actionTriggers.removeClass( 'frm_active_action' ).addClass( limitClass );
6058 + } else {
6059 + $actionTriggers.removeClass( 'frm_inactive_action frm_already_used' ).addClass( 'frm_active_action' );
6060 + }
6061 + }
6062 +
6063 + function isAtLimitForActionType( type ) {
6064 + return getNumberOfActionsForType( type ) >= getLimitForActionType( type );
6065 + }
6066 +
6067 + function getLimitForActionType( type ) {
6068 + return parseInt( jQuery( '.frm_' + type + '_action' ).data( 'limit' ), 10 );
6069 + }
6070 +
6071 + function getNumberOfActionsForType( type ) {
6072 + return jQuery( '.frm_single_' + type + '_settings' ).length;
6073 + }
6074 +
6075 + function onlyOneActionMessage() {
6076 + infoModal( frm_admin_js.only_one_action );
6077 + }
6078 +
6079 + function addFormLogicRow() {
6080 + /*jshint validthis:true */
6081 + var id = jQuery( this ).data( 'emailkey' ),
6082 + type = jQuery( this ).closest( '.frm_form_action_settings' ).find( '.frm_action_name' ).val(),
6083 + formId = document.getElementById( 'form_id' ).value,
6084 + logicRows = document.getElementById( 'frm_form_action_' + id ).querySelectorAll( '.frm_logic_row' );
6085 + jQuery.ajax({
6086 + type: 'POST', url: ajaxurl,
6087 + data: {
6088 + action: 'frm_add_form_logic_row',
6089 + email_id: id,
6090 + form_id: formId,
6091 + meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ),
6092 + type: type,
6093 + nonce: frmGlobal.nonce
6094 + },
6095 + success: function( html ) {
6096 + jQuery( document.getElementById( 'logic_link_' + id ) ).fadeOut( 'slow', function() {
6097 + var $logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) );
6098 + $logicRow.append( html );
6099 + $logicRow.parent( '.frm_logic_rows' ).fadeIn( 'slow' );
6100 + });
6101 + }
6102 + });
6103 + return false;
6104 + }
6105 +
6106 + function toggleSubmitLogic() {
6107 + /*jshint validthis:true */
6108 + if ( this.checked ) {
6109 + addSubmitLogic();
6110 + } else {
6111 + jQuery( '.frm_logic_row_submit' ).remove();
6112 + document.getElementById( 'frm_submit_logic_rows' ).style.display = 'none';
6113 + }
6114 + }
6115 +
6116 + /**
6117 + * Adds submit button Conditional Logic row and reveals submit button Conditional Logic
6118 + *
6119 + * @returns {boolean}
6120 + */
6121 + function addSubmitLogic() {
6122 + /*jshint validthis:true */
6123 + var formId = thisFormId,
6124 + logicRows = document.getElementById( 'frm_submit_logic_row' ).querySelectorAll( '.frm_logic_row' );
6125 + jQuery.ajax({
6126 + type: 'POST',
6127 + url: ajaxurl,
6128 + data: {
6129 + action: 'frm_add_submit_logic_row',
6130 + form_id: formId,
6131 + meta_name: getNewRowId( logicRows, 'frm_logic_submit_' ),
6132 + nonce: frmGlobal.nonce
6133 + },
6134 + success: function( html ) {
6135 + var $logicRow = jQuery( document.getElementById( 'frm_submit_logic_row' ) );
6136 + $logicRow.append( html );
6137 + $logicRow.parent( '.frm_submit_logic_rows' ).fadeIn( 'slow' );
6138 + }
6139 + });
6140 + return false;
6141 + }
6142 +
6143 + /**
6144 + * When the user selects a field for a submit condition, update corresponding options field accordingly.
6145 + */
6146 + function addSubmitLogicOpts() {
6147 + var fieldOpt = jQuery( this );
6148 + var fieldId = fieldOpt.find( ':selected' ).val();
6149 +
6150 + if ( fieldId ) {
6151 + var row = fieldOpt.data( 'row' );
6152 + frmGetFieldValues( fieldId, 'submit', row, '', 'options[submit_conditions][hide_opt][]' );
6153 + }
6154 + }
6155 +
6156 + function formatEmailSetting() {
6157 + /*jshint validthis:true */
6158 + /*var val = jQuery( this ).val();
6159 + var email = val.match( /(\s[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi );
6160 + if(email !== null && email.length) {
6161 + //has email
6162 + //TODO: add < > if they aren't there
6163 + }*/
6164 + }
6165 +
6166 + function maybeShowFormMessages() {
6167 + var header = document.getElementById( 'frm_messages_header' );
6168 + if ( showFormMessages() ) {
6169 + header.style.display = 'block';
6170 + } else {
6171 + header.style.display = 'none';
6172 + }
6173 + }
6174 +
6175 + function showFormMessages() {
6176 + var action = document.getElementById( 'success_action' );
6177 + var selectedAction = action.options[action.selectedIndex].value;
6178 + if ( selectedAction === 'message' ) {
6179 + return true;
6180 + }
6181 +
6182 + var show = false;
6183 + var editable = document.getElementById( 'editable' );
6184 + if ( editable !== null ) {
6185 + show = editable.checked && jQuery( document.getElementById( 'edit_action' ) ).val() === 'message';
6186 + if ( ! show ) {
6187 + show = isChecked( 'save_draft' );
6188 + }
6189 + }
6190 + return show;
6191 + }
6192 +
6193 + function checkDupPost() {
6194 + /*jshint validthis:true */
6195 + var postField = jQuery( 'select.frm_single_post_field' );
6196 + postField.css( 'border-color', '' );
6197 + var $t = this;
6198 + var v = jQuery( $t ).val();
6199 + if ( v === '' || v === 'checkbox' ) {
6200 + return false;
6201 + }
6202 + postField.each( function() {
6203 + if ( jQuery( this ).val() === v && this.name !== $t.name ) {
6204 + this.style.borderColor = 'red';
6205 + jQuery( $t ).val( '' );
6206 + infoModal( 'Oops. You have already used that field.' );
6207 + return false;
6208 + }
6209 + });
6210 + }
6211 +
6212 + function togglePostContent() {
6213 + /*jshint validthis:true */
6214 + var v = jQuery( this ).val();
6215 + if ( '' === v ) {
6216 + jQuery( '.frm_post_content_opt, select.frm_dyncontent_opt' ).hide().val( '' );
6217 + jQuery( '.frm_dyncontent_opt' ).hide();
6218 + } else if ( 'post_content' === v ) {
6219 + jQuery( '.frm_post_content_opt' ).show();
6220 + jQuery( '.frm_dyncontent_opt' ).hide();
6221 + jQuery( 'select.frm_dyncontent_opt' ).val( '' );
6222 + } else {
6223 + jQuery( '.frm_post_content_opt' ).hide().val( '' );
6224 + jQuery( 'select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt' ).show();
6225 + }
6226 + }
6227 +
6228 + function fillDyncontent() {
6229 + /*jshint validthis:true */
6230 + var v = jQuery( this ).val();
6231 + var $dyn = jQuery( document.getElementById( 'frm_dyncontent' ) );
6232 + if ( '' === v || 'new' === v ) {
6233 + $dyn.val( '' );
6234 + jQuery( '.frm_dyncontent_opt' ).show();
6235 + } else {
6236 + jQuery.ajax({
6237 + type: 'POST', url: ajaxurl,
6238 + data: {action: 'frm_display_get_content', id: v, nonce: frmGlobal.nonce},
6239 + success: function( val ) {
6240 + $dyn.val( val );
6241 + jQuery( '.frm_dyncontent_opt' ).show();
6242 + }
6243 + });
6244 + }
6245 + }
6246 +
6247 + function switchPostType() {
6248 + /*jshint validthis:true */
6249 + // update all rows of categories/taxonomies
6250 + var curSelect, newSelect,
6251 + catRows = document.getElementById( 'frm_posttax_rows' ).childNodes,
6252 + postParentField = document.querySelector( '.frm_post_parent_field' ),
6253 + postMenuOrderField = document.querySelector( '.frm_post_menu_order_field' ),
6254 + postType = this.value;
6255 +
6256 + // Get new category/taxonomy options
6257 + jQuery.ajax({
6258 + type: 'POST',
6259 + url: ajaxurl,
6260 + data: {
6261 + action: 'frm_replace_posttax_options',
6262 + post_type: postType,
6263 + nonce: frmGlobal.nonce
6264 + },
6265 + success: function( html ) {
6266 +
6267 + // Loop through each category row, and replace the first dropdown
6268 + for ( i = 0; i < catRows.length; i++ ) {
6269 + // Check if current element is a div
6270 + if ( catRows[i].tagName !== 'DIV' ) {
6271 + continue;
6272 + }
6273 +
6274 + // Get current category select
6275 + curSelect = catRows[i].getElementsByTagName( 'select' )[0];
6276 +
6277 + // Set up new select
6278 + newSelect = document.createElement( 'select' );
6279 + newSelect.innerHTML = html;
6280 + newSelect.className = curSelect.className;
6281 + newSelect.name = curSelect.name;
6282 +
6283 + // Replace the old select with the new select
6284 + catRows[i].replaceChild( newSelect, curSelect );
6285 + }
6286 + }
6287 + });
6288 +
6289 + // Get new post parent option.
6290 + if ( postParentField ) {
6291 + getActionOption(
6292 + postParentField,
6293 + postType,
6294 + 'frm_get_post_parent_option',
6295 + function( response, optName ) {
6296 + // The replaced string is declared in FrmProFormActionController::ajax_get_post_menu_order_option() in the pro version.
6297 + postParentField.querySelector( '.frm_post_parent_opt_wrapper' ).innerHTML = response.replaceAll( 'REPLACETHISNAME', optName );
6298 + initAutocomplete( 'page', postParentField );
6299 + }
6300 + );
6301 + }
6302 +
6303 + if ( postMenuOrderField ) {
6304 + getActionOption( postMenuOrderField, postType, 'frm_should_use_post_menu_order_option' );
6305 + }
6306 + }
6307 +
6308 + function getActionOption( field, postType, action, successHandler ) {
6309 + const opt = field.querySelector( '.frm_autocomplete_value_input' ) || field.querySelector( 'select' ),
6310 + optName = opt.getAttribute( 'name' );
6311 +
6312 + jQuery.ajax({
6313 + url: ajaxurl,
6314 + method: 'POST',
6315 + data: {
6316 + action: action,
6317 + post_type: postType,
6318 + _wpnonce: frmGlobal.nonce
6319 + },
6320 + success: response => {
6321 + if ( 'string' !== typeof response ) {
6322 + console.error( response );
6323 + return;
6324 + }
6325 +
6326 + if ( '0' === response ) {
6327 + // This post type does not support this field.
6328 + field.classList.add( 'frm_hidden' );
6329 + field.value = '';
6330 + return;
6331 + }
6332 +
6333 + field.classList.remove( 'frm_hidden' );
6334 +
6335 + if ( 'function' === typeof successHandler ) {
6336 + successHandler( response, optName );
6337 + }
6338 + },
6339 + error: response => console.error( response )
6340 + });
6341 + }
6342 +
6343 + function addPosttaxRow() {
6344 + /*jshint validthis:true */
6345 + addPostRow( 'tax', this );
6346 + }
6347 +
6348 + function addPostmetaRow() {
6349 + /*jshint validthis:true */
6350 + addPostRow( 'meta', this );
6351 + }
6352 +
6353 + function addPostRow( type, button ) {
6354 + var name,
6355 + id = jQuery( 'input[name="id"]' ).val(),
6356 + settings = jQuery( button ).closest( '.frm_form_action_settings' ),
6357 + key = settings.data( 'actionkey' ),
6358 + postType = settings.find( '.frm_post_type' ).val(),
6359 + metaName = 0,
6360 + postTypeRows = document.querySelectorAll( '.frm_post' + type + '_row' );
6361 +
6362 + if ( postTypeRows.length ) {
6363 + name = postTypeRows[ postTypeRows.length - 1 ].id.replace( 'frm_post' + type + '_', '' );
6364 + if ( isNumeric( name ) ) {
6365 + metaName = 1 + parseInt( name, 10 );
6366 + } else {
6367 + metaName = 1;
6368 + }
6369 + }
6370 +
6371 + jQuery.ajax({
6372 + type: 'POST', url: ajaxurl,
6373 + data: {
6374 + action: 'frm_add_post' + type + '_row',
6375 + form_id: id,
6376 + meta_name: metaName,
6377 + tax_key: metaName,
6378 + post_type: postType,
6379 + action_key: key,
6380 + nonce: frmGlobal.nonce
6381 + },
6382 + success: function( html ) {
6383 + var cfOpts, optIndex;
6384 + jQuery( document.getElementById( 'frm_post' + type + '_rows' ) ).append( html );
6385 + jQuery( '.frm_add_post' + type + '_row.button' ).hide();
6386 +
6387 + if ( type === 'meta' ) {
6388 + jQuery( '.frm_name_value' ).show();
6389 + cfOpts = document.querySelectorAll( '.frm_toggle_cf_opts' );
6390 + for ( optIndex = 0; optIndex < cfOpts.length - 1; ++optIndex ) {
6391 + cfOpts[ optIndex ].style.display = 'none';
6392 + }
6393 + } else if ( type === 'tax' ) {
6394 + jQuery( '.frm_posttax_labels' ).show();
6395 + }
6396 + }
6397 + });
6398 + }
6399 +
6400 + function isNumeric( value ) {
6401 + return ! isNaN( parseFloat( value ) ) && isFinite( value );
6402 + }
6403 +
6404 + function getMetaValue( id, metaName ) {
6405 + var newMeta = metaName;
6406 + if ( jQuery( document.getElementById( id + metaName ) ).length > 0 ) {
6407 + newMeta = getMetaValue( id, metaName + 1 );
6408 + }
6409 + return newMeta;
6410 + }
6411 +
6412 + function changePosttaxRow() {
6413 + /*jshint validthis:true */
6414 + if ( ! jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).length ) {
6415 + return;
6416 + }
6417 +
6418 + jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).html( '<div class="spinner frm_spinner" style="display:block"></div>' );
6419 +
6420 + var postType = jQuery( this ).closest( '.frm_form_action_settings' ).find( 'select[name$="[post_content][post_type]"]' ).val(),
6421 + actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ),
6422 + taxKey = jQuery( this ).closest( '.frm_posttax_row' ).attr( 'id' ).replace( 'frm_posttax_', '' ),
6423 + metaName = jQuery( this ).val(),
6424 + showExclude = jQuery( document.getElementById( taxKey + '_show_exclude' ) ).is( ':checked' ) ? 1 : 0,
6425 + fieldId = jQuery( 'select[name$="[post_category][' + taxKey + '][field_id]"]' ).val(),
6426 + id = jQuery( 'input[name="id"]' ).val();
6427 +
6428 + jQuery.ajax({
6429 + type: 'POST',
6430 + url: ajaxurl,
6431 + data: {
6432 + action: 'frm_add_posttax_row',
6433 + form_id: id,
6434 + post_type: postType,
6435 + tax_key: taxKey,
6436 + action_key: actionKey,
6437 + meta_name: metaName,
6438 + field_id: fieldId,
6439 + show_exclude: showExclude,
6440 + nonce: frmGlobal.nonce
6441 + },
6442 + success: function( html ) {
6443 + var $tax = jQuery( document.getElementById( 'frm_posttax_' + taxKey ) );
6444 + $tax.replaceWith( html );
6445 + }
6446 + });
6447 + }
6448 +
6449 + function toggleCfOpts() {
6450 + /*jshint validthis:true */
6451 + var row = jQuery( this ).closest( '.frm_postmeta_row' );
6452 + var cancel = row.find( '.frm_cancelnew' );
6453 + var select = row.find( '.frm_enternew' );
6454 + if ( row.find( 'select.frm_cancelnew' ).is( ':visible' ) ) {
6455 + cancel.hide();
6456 + select.show();
6457 + } else {
6458 + cancel.show();
6459 + select.hide();
6460 + }
6461 +
6462 + row.find( 'input.frm_enternew, select.frm_cancelnew' ).val( '' );
6463 + return false;
6464 + }
6465 +
6466 + function toggleFormOpts() {
6467 + /*jshint validthis:true */
6468 + var changedOpt = jQuery( this );
6469 + var val = changedOpt.val();
6470 + if ( changedOpt.attr( 'type' ) === 'checkbox' ) {
6471 + if ( this.checked === false ) {
6472 + val = '';
6473 + }
6474 + }
6475 +
6476 + var toggleClass = changedOpt.data( 'toggleclass' );
6477 + if ( val === '' ) {
6478 + jQuery( '.' + toggleClass ).hide();
6479 + } else {
6480 + jQuery( '.' + toggleClass ).show();
6481 + jQuery( '.hide_' + toggleClass + '_' + val ).hide();
6482 + }
6483 + }
6484 +
6485 + function submitSettings() {
6486 + /*jshint validthis:true */
6487 + preFormSave( this );
6488 + triggerSubmit( document.querySelector( '.frm_form_settings' ) );
6489 + }
6490 +
6491 + /* View Functions */
6492 + function showCount() {
6493 + /*jshint validthis:true */
6494 + var value = jQuery( this ).val();
6495 +
6496 + var $cont = document.getElementById( 'date_select_container' );
6497 + var tab = document.getElementById( 'frm_listing_tab' );
6498 + var label = tab.getAttribute( 'data-label' );
6499 + if ( value === 'calendar' ) {
6500 + jQuery( '.hide_dyncontent, .hide_single_content' ).removeClass( 'frm_hidden' );
6501 + jQuery( '.limit_container' ).addClass( 'frm_hidden' );
6502 + $cont.style.display = 'block';
6503 + } else if ( value === 'dynamic' ) {
6504 + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).removeClass( 'frm_hidden' );
6505 + } else if ( value === 'one' ) {
6506 + label = tab.getAttribute( 'data-one' );
6507 + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).addClass( 'frm_hidden' );
6508 + } else {
6509 + jQuery( '.hide_dyncontent' ).addClass( 'frm_hidden' );
6510 + jQuery( '.limit_container, .hide_single_content' ).removeClass( 'frm_hidden' );
6511 + }
6512 +
6513 + if ( value !== 'calendar' ) {
6514 + $cont.style.display = 'none';
6515 + }
6516 + tab.innerHTML = label;
6517 + }
6518 +
6519 + function displayFormSelected() {
6520 + /*jshint validthis:true */
6521 + var formId = jQuery( this ).val();
6522 + thisFormId = formId; // set the global form id
6523 + if ( formId === '' ) {
6524 + return;
6525 + }
6526 +
6527 + jQuery.ajax({
6528 + type: 'POST',
6529 + url: ajaxurl,
6530 + data: {
6531 + action: 'frm_get_cd_tags_box',
6532 + form_id: formId,
6533 + nonce: frmGlobal.nonce
6534 + },
6535 + success: function( html ) {
6536 + jQuery( '#frm_adv_info .categorydiv' ).html( html );
6537 + }
6538 + });
6539 +
6540 + jQuery.ajax({
6541 + type: 'POST',
6542 + url: ajaxurl,
6543 + data: {
6544 + action: 'frm_get_date_field_select',
6545 + form_id: formId,
6546 + nonce: frmGlobal.nonce
6547 + },
6548 + success: function( html ) {
6549 + jQuery( document.getElementById( 'date_select_container' ) ).html( html );
6550 + }
6551 + });
6552 + }
6553 +
6554 + function clickTabsAfterAjax() {
6555 + /*jshint validthis:true */
6556 + var t = jQuery( this ).attr( 'href' );
6557 + jQuery( this ).parent().addClass( 'tabs' ).siblings( 'li' ).removeClass( 'tabs' );
6558 + jQuery( t ).show().siblings( '.tabs-panel' ).hide();
6559 + return false;
6560 + }
6561 +
6562 + function clickContentTab() {
6563 + /*jshint validthis:true */
6564 + link = jQuery( this );
6565 + var t = link.attr( 'href' );
6566 + if ( typeof t === 'undefined' ) {
6567 + return false;
6568 + }
6569 +
6570 + var c = t.replace( '#', '.' );
6571 + link.closest( '.nav-tab-wrapper' ).find( 'a' ).removeClass( 'nav-tab-active' );
6572 + link.addClass( 'nav-tab-active' );
6573 + jQuery( '.nav-menu-content' ).not( t ).not( c ).hide();
6574 + jQuery( t + ',' + c ).show();
6575 +
6576 + return false;
6577 + }
6578 +
6579 + function addOrderRow() {
6580 + var logicRows = document.getElementById( 'frm_order_options' ).querySelectorAll( '.frm_logic_rows div' );
6581 + jQuery.ajax({
6582 + type: 'POST',
6583 + url: ajaxurl,
6584 + data: {
6585 + action: 'frm_add_order_row',
6586 + form_id: thisFormId,
6587 + order_key: getNewRowId( logicRows, 'frm_order_field_', 1 ),
6588 + nonce: frmGlobal.nonce
6589 + },
6590 + success: function( html ) {
6591 + jQuery( '#frm_order_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_order_row' ).hide();
6592 + }
6593 + });
6594 + }
6595 +
6596 + function addWhereRow() {
6597 + var rowDivs = document.getElementById( 'frm_where_options' ).querySelectorAll( '.frm_logic_rows div' );
6598 + jQuery.ajax({
6599 + type: 'POST',
6600 + url: ajaxurl,
6601 + data: {
6602 + action: 'frm_add_where_row',
6603 + form_id: thisFormId,
6604 + where_key: getNewRowId( rowDivs, 'frm_where_field_', 1 ),
6605 + nonce: frmGlobal.nonce
6606 + },
6607 + success: function( html ) {
6608 + jQuery( '#frm_where_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_where_row' ).hide();
6609 + }
6610 + });
6611 + }
6612 +
6613 + function insertWhereOptions() {
6614 + /*jshint validthis:true */
6615 + var value = this.value,
6616 + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' );
6617 +
6618 + jQuery.ajax({
6619 + type: 'POST',
6620 + url: ajaxurl,
6621 + data: {
6622 + action: 'frm_add_where_options',
6623 + where_key: whereKey,
6624 + field_id: value,
6625 + nonce: frmGlobal.nonce
6626 + },
6627 + success: function( html ) {
6628 + jQuery( document.getElementById( 'where_field_options_' + whereKey ) ).html( html );
6629 + }
6630 + });
6631 + }
6632 +
6633 + function hideWhereOptions() {
6634 + /*jshint validthis:true */
6635 + var value = this.value,
6636 + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' );
6637 +
6638 + if ( value === 'group_by' || value === 'group_by_newest' ) {
6639 + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'none';
6640 + } else {
6641 + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'inline-block';
6642 + }
6643 + }
6644 +
6645 + function setDefaultPostStatus() {
6646 + var urlQuery = window.location.search.substring( 1 );
6647 + if ( urlQuery.indexOf( 'action=edit' ) === -1 ) {
6648 + document.getElementById( 'post-visibility-display' ).innerHTML = frm_admin_js.private_label;
6649 + document.getElementById( 'hidden-post-visibility' ).value = 'private';
6650 + document.getElementById( 'visibility-radio-private' ).checked = true;
6651 + }
6652 + }
6653 +
6654 + /* Customization Panel */
6655 + function insertCode( e ) {
6656 + /*jshint validthis:true */
6657 + e.preventDefault();
6658 + insertFieldCode( jQuery( this ), this.getAttribute( 'data-code' ) );
6659 + return false;
6660 + }
6661 +
6662 + function insertFieldCode( element, variable ) {
6663 + var rich = false,
6664 + elementId = element;
6665 + if ( typeof element === 'object' ) {
6666 + if ( element.hasClass( 'frm_noallow' ) ) {
6667 + return;
6668 + }
6669 +
6670 + elementId = jQuery( element ).closest( '[data-fills]' ).attr( 'data-fills' );
6671 + if ( typeof elementId === 'undefined' ) {
6672 + elementId = element.closest( 'div' ).attr( 'class' );
6673 + if ( typeof elementId !== 'undefined' ) {
6674 + elementId = elementId.split( ' ' )[1];
6675 + }
6676 + }
6677 + }
6678 +
6679 + if ( typeof elementId === 'undefined' ) {
6680 + var active = document.activeElement;
6681 + if ( active.type === 'search' ) {
6682 + // If the search field has focus, find the correct field.
6683 + elementId = active.id.replace( '-search-input', '' );
6684 + if ( elementId.match( /\d/gi ) === null ) {
6685 + active = jQuery( '.frm-single-settings:visible .' + elementId );
6686 + elementId = active.attr( 'id' );
6687 + }
6688 + } else {
6689 + elementId = active.id;
6690 + }
6691 + }
6692 +
6693 + if ( elementId ) {
6694 + rich = jQuery( '#wp-' + elementId + '-wrap.wp-editor-wrap' ).length > 0;
6695 + }
6696 +
6697 + var contentBox = jQuery( document.getElementById( elementId ) );
6698 + if ( typeof element.attr( 'data-shortcode' ) === 'undefined' && ( ! contentBox.length || typeof contentBox.attr( 'data-shortcode' ) === 'undefined' ) ) {
6699 + // this helps to exclude those that don't want shortcode-like inserted content e.g. frm-pro's summary field
6700 + var doShortcode = element.parents( 'ul.frm_code_list' ).attr( 'data-shortcode' );
6701 + if ( doShortcode === 'undefined' || doShortcode !== 'no' ) {
6702 + variable = '[' + variable + ']';
6703 + }
6704 + }
6705 +
6706 + if ( rich ) {
6707 + wpActiveEditor = elementId;
6708 + send_to_editor( variable );
6709 + return;
6710 + }
6711 +
6712 + if ( ! contentBox.length ) {
6713 + return false;
6714 + }
6715 +
6716 + if ( variable === '[default-html]' || variable === '[default-plain]' ) {
6717 + var p = 0;
6718 + if ( variable === '[default-plain]' ) {
6719 + p = 1;
6720 + }
6721 + jQuery.ajax({
6722 + type: 'POST', url: ajaxurl,
6723 + data: {
6724 + action: 'frm_get_default_html',
6725 + form_id: jQuery( 'input[name="id"]' ).val(),
6726 + plain_text: p,
6727 + nonce: frmGlobal.nonce
6728 + },
6729 + success: function( msg ) {
6730 + insertContent( contentBox, msg );
6731 + }
6732 + });
6733 + } else {
6734 + insertContent( contentBox, variable );
6735 + }
6736 + return false;
6737 + }
6738 +
6739 + function insertContent( contentBox, variable ) {
6740 + if ( document.selection ) {
6741 + contentBox[0].focus();
6742 + document.selection.createRange().text = variable;
6743 + } else {
6744 + obj = contentBox[0];
6745 + var e = obj.selectionEnd;
6746 +
6747 + variable = maybeFormatInsertedContent( contentBox, variable, obj.selectionStart, e );
6748 +
6749 + obj.value = obj.value.substr( 0, obj.selectionStart ) + variable + obj.value.substr( obj.selectionEnd, obj.value.length );
6750 + var s = e + variable.length;
6751 + obj.focus();
6752 + obj.setSelectionRange( s, s );
6753 + }
6754 + triggerChange( contentBox );
6755 + }
6756 +
6757 + function maybeFormatInsertedContent( input, textToInsert, selectionStart, selectionEnd ) {
6758 + var separator = input.data( 'sep' );
6759 + if ( undefined === separator ) {
6760 + return textToInsert;
6761 + }
6762 +
6763 + var value = input.val();
6764 +
6765 + if ( ! value.trim().length ) {
6766 + return textToInsert;
6767 + }
6768 +
6769 + var startPattern = new RegExp( separator + '\\s*$' );
6770 + var endPattern = new RegExp( '^\\s*' + separator );
6771 +
6772 + if ( value.substr( 0, selectionStart ).trim().length && false === startPattern.test( value.substr( 0, selectionStart ) ) ) {
6773 + textToInsert = separator + textToInsert;
6774 + }
6775 +
6776 + if ( value.substr( selectionEnd, value.length ).trim().length && false === endPattern.test( value.substr( selectionEnd, value.length ) ) ) {
6777 + textToInsert += separator;
6778 + }
6779 +
6780 + return textToInsert;
6781 + }
6782 +
6783 + function resetLogicBuilder() {
6784 + /*jshint validthis:true */
6785 + var id = document.getElementById( 'frm-id-condition' ),
6786 + key = document.getElementById( 'frm-key-condition' );
6787 +
6788 + if ( this.checked ) {
6789 + id.classList.remove( 'frm_hidden' );
6790 + key.classList.add( 'frm_hidden' );
6791 + triggerEvent( key, 'change' );
6792 + } else {
6793 + id.classList.add( 'frm_hidden' );
6794 + key.classList.remove( 'frm_hidden' );
6795 + triggerEvent( id, 'change' );
6796 + }
6797 + }
6798 +
6799 + function setLogicExample() {
6800 + var field, code,
6801 + idKey = document.getElementById( 'frm-id-key-condition' ).checked ? 'frm-id-condition' : 'frm-key-condition',
6802 + is = document.getElementById( 'frm-is-condition' ).value,
6803 + text = document.getElementById( 'frm-text-condition' ).value,
6804 + result = document.getElementById( 'frm-insert-condition' );
6805 +
6806 + idKey = document.getElementById( idKey );
6807 + field = idKey.options[idKey.selectedIndex].value;
6808 + code = 'if ' + field + ' ' + is + '="' + text + '"]';
6809 + result.setAttribute( 'data-code', code + frm_admin_js.conditional_text + '[/if ' + field );
6810 + result.innerHTML = '[' + code + '[/if ' + field + ']';
6811 + }
6812 +
6813 + function showBuilderModal() {
6814 + /*jshint validthis:true */
6815 + var moreIcon = getIconForInput( this );
6816 + showInlineModal( moreIcon, this );
6817 + }
6818 +
6819 + function maybeShowModal( input ) {
6820 + var moreIcon;
6821 + if ( input.parentNode.parentNode.classList.contains( 'frm_has_shortcodes' ) ) {
6822 + hideShortcodes();
6823 + moreIcon = getIconForInput( input );
6824 + if ( moreIcon.tagName === 'use' ) {
6825 + moreIcon = moreIcon.firstElementChild;
6826 + if ( moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ).indexOf( 'frm_close_icon' ) === -1 ) {
6827 + showShortcodeBox( moreIcon, 'nofocus' );
6828 + }
6829 + } else if ( ! moreIcon.classList.contains( 'frm_close_icon' ) ) {
6830 + showShortcodeBox( moreIcon, 'nofocus' );
6831 + }
6832 + }
6833 + }
6834 +
6835 + function showShortcodes( e ) {
6836 + /*jshint validthis:true */
6837 + e.preventDefault();
6838 + e.stopPropagation();
6839 +
6840 + showShortcodeBox( this );
6841 + }
6842 +
6843 + function showShortcodeBox( moreIcon, shouldFocus ) {
6844 + var pos = moreIcon.getBoundingClientRect(),
6845 + input = getInputForIcon( moreIcon ),
6846 + box = document.getElementById( 'frm_adv_info' ),
6847 + classes = moreIcon.className,
6848 + parentPos = box.parentElement.getBoundingClientRect();
6849 +
6850 + if ( moreIcon.tagName === 'svg' ) {
6851 + moreIcon = moreIcon.firstElementChild;
6852 + }
6853 + if ( moreIcon.tagName === 'use' ) {
6854 + classes = moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' );
6855 + }
6856 +
6857 + if ( classes.indexOf( 'frm_close_icon' ) !== -1 ) {
6858 + hideShortcodes( box );
6859 + } else {
6860 + box.style.top = ( pos.top - parentPos.top + 32 ) + 'px';
6861 + box.style.left = ( pos.left - parentPos.left - 257 ) + 'px';
6862 +
6863 + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' );
6864 + if ( input.classList.contains( 'frm_not_email_to' ) ) {
6865 + jQuery( '#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a' ).addClass( 'frm_noallow' );
6866 + } else if ( input.classList.contains( 'frm_not_email_subject' ) ) {
6867 + jQuery( '.frm_code_list li.hide_frm_not_email_subject a' ).addClass( 'frm_noallow' );
6868 + }
6869 +
6870 + box.setAttribute( 'data-fills', input.id );
6871 + box.style.display = 'block';
6872 +
6873 + if ( moreIcon.tagName === 'use' ) {
6874 + moreIcon.setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_close_icon' );
6875 + } else {
6876 + moreIcon.className = classes.replace( 'frm_more_horiz_solid_icon', 'frm_close_icon' );
6877 + }
6878 +
6879 + if ( shouldFocus !== 'nofocus' ) {
6880 + input.focus();
6881 + }
6882 + }
6883 + }
6884 +
6885 + function fieldUpdated() {
6886 + if ( ! fieldsUpdated ) {
6887 + fieldsUpdated = 1;
6888 + window.addEventListener( 'beforeunload', confirmExit );
6889 + }
6890 + }
6891 +
6892 + function buildSubmittedNoAjax() {
6893 + // set fieldsUpdated to 0 to avoid the unsaved changes pop up
6894 + fieldsUpdated = 0;
6895 + }
6896 +
6897 + function settingsSubmitted() {
6898 + // set fieldsUpdated to 0 to avoid the unsaved changes pop up
6899 + fieldsUpdated = 0;
6900 + }
6901 +
6902 + function saveAndReloadSettings() {
6903 + var page, form;
6904 + page = document.getElementById( 'form_settings_page' );
6905 + if ( null !== page ) {
6906 + form = page.querySelector( 'form.frm_form_settings' );
6907 + if ( null !== form ) {
6908 + fieldsUpdated = 0;
6909 + form.submit();
6910 + }
6911 + }
6912 + }
6913 +
6914 + function confirmExit( event ) {
6915 + if ( fieldsUpdated ) {
6916 + event.preventDefault();
6917 + event.returnValue = '';
6918 + }
6919 + }
6920 +
6921 + function bindClickForDialogClose( $modal ) {
6922 + const closeModal = function() {
6923 + $modal.dialog( 'close' );
6924 + };
6925 + jQuery( '.ui-widget-overlay' ).on( 'click', closeModal );
6926 + $modal.on( 'click', 'a.dismiss', closeModal );
6927 + }
6928 +
6929 + function triggerNewFormModal( event ) {
6930 + var $modal,
6931 + dismiss = document.getElementById( 'frm_new_form_modal' ).querySelector( 'a.dismiss' );
6932 +
6933 + if ( typeof event !== 'undefined' ) {
6934 + event.preventDefault();
6935 + }
6936 +
6937 + dismiss.setAttribute( 'tabindex', -1 );
6938 +
6939 + $modal = initModal( '#frm_new_form_modal', '600px' );
6940 + $modal.attr( 'frm-page', 'create' );
6941 + $modal.find( '#template-search-input' ).val( '' ).trigger( 'change' );
6942 + $modal.dialog( 'open' );
6943 +
6944 + dismiss.removeAttribute( 'tabindex' );
6945 + bindClickForDialogClose( $modal );
6946 + }
6947 +
6948 + /**
6949 + * Get the input box for the selected ... icon.
6950 + */
6951 + function getInputForIcon( moreIcon ) {
6952 + var input = moreIcon.nextElementSibling;
6953 + if ( input !== null && input.tagName !== 'INPUT' && input.tagName !== 'TEXTAREA' ) {
6954 + // Workaround for 1Password.
6955 + input = input.nextElementSibling;
6956 + }
6957 + return input;
6958 + }
6959 +
6960 + /**
6961 + * Get the ... icon for the selected input box.
6962 + */
6963 + function getIconForInput( input ) {
6964 + var moreIcon = input.previousElementSibling;
6965 + if ( moreIcon !== null && moreIcon.tagName !== 'I' && moreIcon.tagName !== 'svg' ) {
6966 + moreIcon = moreIcon.previousElementSibling;
6967 + }
6968 + return moreIcon;
6969 + }
6970 +
6971 + function hideShortcodes( box ) {
6972 + var i, u, closeIcons, closeSvg;
6973 + if ( typeof box === 'undefined' ) {
6974 + box = document.getElementById( 'frm_adv_info' );
6975 + if ( box === null ) {
6976 + return;
6977 + }
6978 + }
6979 +
6980 + if ( document.getElementById( 'frm_dyncontent' ) !== null ) {
6981 + // Don't run when in the sidebar.
6982 + return;
6983 + }
6984 +
6985 + box.style.display = 'none';
6986 +
6987 + closeIcons = document.querySelectorAll( '.frm-show-box.frm_close_icon' );
6988 + for ( i = 0; i < closeIcons.length; i++ ) {
6989 + closeIcons[i].classList.remove( 'frm_close_icon' );
6990 + closeIcons[i].classList.add( 'frm_more_horiz_solid_icon' );
6991 + }
6992 +
6993 + closeSvg = document.querySelectorAll( '.frm_has_shortcodes use' );
6994 + for ( u = 0; u < closeSvg.length; u++ ) {
6995 + if ( closeSvg[u].getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) === '#frm_close_icon' ) {
6996 + closeSvg[u].setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_more_horiz_solid_icon' );
6997 + }
6998 + }
6999 + }
7000 +
7001 + function initToggleShortcodes() {
7002 + if ( typeof tinymce !== 'object' ) {
7003 + return;
7004 + }
7005 +
7006 + DOM = tinymce.DOM;
7007 + if ( typeof DOM.events !== 'undefined' && typeof DOM.events.add !== 'undefined' ) {
7008 + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseover', function() {
7009 + if ( jQuery( '*:focus' ).length > 0 ) {
7010 + return;
7011 + }
7012 + if ( this.id ) {
7013 + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7014 + }
7015 + });
7016 + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseout', function() {
7017 + if ( jQuery( '*:focus' ).length > 0 ) {
7018 + return;
7019 + }
7020 + if ( this.id ) {
7021 + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7022 + }
7023 + });
7024 + } else {
7025 + jQuery( '#frm_dyncontent' ).on( 'mouseover mouseout', '.wp-editor-wrap', function() {
7026 + if ( jQuery( '*:focus' ).length > 0 ) {
7027 + return;
7028 + }
7029 + if ( this.id ) {
7030 + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' );
7031 + }
7032 + });
7033 + }
7034 + }
7035 +
7036 + function toggleAllowedShortcodes( id ) {
7037 + var c, clickedID;
7038 + if ( typeof id === 'undefined' ) {
7039 + id = '';
7040 + }
7041 + c = id;
7042 +
7043 + if ( id.indexOf( '-search-input' ) !== -1 ) {
7044 + return;
7045 + }
7046 +
7047 + if ( id !== '' ) {
7048 + var $ele = jQuery( document.getElementById( id ) );
7049 + if ( $ele.attr( 'class' ) && id !== 'wpbody-content' && id !== 'content' && id !== 'dyncontent' && id !== 'success_msg' ) {
7050 + var d = $ele.attr( 'class' ).split( ' ' )[0];
7051 + if ( d === 'frm_long_input' || d === 'frm_98_width' || typeof d === 'undefined' ) {
7052 + d = '';
7053 + } else {
7054 + id = d.trim();
7055 + }
7056 + c = c + ' ' + d;
7057 + c = c.replace( 'widefat', '' ).replace( 'frm_with_left_label', '' );
7058 + }
7059 + }
7060 +
7061 + jQuery( '#frm-insert-fields-box,#frm-conditionals,#frm-adv-info-tab,#frm-dynamic-values' ).attr( 'data-fills', c.trim() );
7062 + var a = [
7063 + 'content', 'wpbody-content', 'dyncontent', 'success_url',
7064 + 'success_msg', 'edit_msg', 'frm_dyncontent', 'frm_not_email_message',
7065 + 'frm_not_email_subject'
7066 + ];
7067 + var b = [
7068 + 'before_content', 'after_content', 'frm_not_email_to',
7069 + 'dyn_default_value'
7070 + ];
7071 +
7072 + if ( jQuery.inArray( id, a ) >= 0 ) {
7073 + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' );
7074 + jQuery( '.frm_code_list a.hide_' + id ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7075 + } else if ( jQuery.inArray( id, b ) >= 0 ) {
7076 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a:not(.show_' + id + ')' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7077 + jQuery( '.frm_code_list a.show_' + id ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' );
7078 + } else {
7079 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' );
7080 + }
7081 +
7082 + // Automatically select a tab.
7083 + if ( id === 'dyn_default_value' ) {
7084 + clickedID = 'frm_dynamic_values';
7085 + document.getElementById( clickedID + '_tab' ).click();
7086 + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_inactive' ).addClass( 'frm_hidden' );
7087 + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_active' ).removeClass( 'frm_hidden' );
7088 + }
7089 + }
7090 +
7091 + function toggleAllowedHTML( input ) {
7092 + var b,
7093 + id = input.id;
7094 + if ( typeof id === 'undefined' || id.indexOf( '-search-input' ) !== -1 ) {
7095 + return;
7096 + }
7097 +
7098 + jQuery( '#frm-adv-info-tab' ).attr( 'data-fills', id.trim() );
7099 + if ( input.classList.contains( 'field_custom_html' ) ) {
7100 + id = 'field_custom_html';
7101 + }
7102 +
7103 + b = [ 'after_html', 'before_html', 'submit_html', 'field_custom_html' ];
7104 + if ( jQuery.inArray( id, b ) >= 0 ) {
7105 + jQuery( '.frm_code_list li:not(.show_' + id + ')' ).addClass( 'frm_hidden' );
7106 + jQuery( '.frm_code_list li.show_' + id ).removeClass( 'frm_hidden' );
7107 + }
7108 + }
7109 +
7110 + function toggleKeyID( switchTo, e ) {
7111 + e.stopPropagation();
7112 + jQuery( '.frm_code_list .frmids, .frm_code_list .frmkeys' ).addClass( 'frm_hidden' );
7113 + jQuery( '.frm_code_list .' + switchTo ).removeClass( 'frm_hidden' );
7114 + jQuery( '.frmids, .frmkeys' ).removeClass( 'current' );
7115 + jQuery( '.' + switchTo ).addClass( 'current' );
7116 + }
7117 +
7118 + /* Styling */
7119 +
7120 + //function to append a new theme stylesheet with the new style changes
7121 + function updateUICSS( locStr ) {
7122 + var $cssLink, $link;
7123 +
7124 + if ( locStr == -1 ) {
7125 + jQuery( 'link.ui-theme' ).remove();
7126 + return false;
7127 + }
7128 +
7129 + $cssLink = jQuery( '<link href="' + locStr + '" type="text/css" rel="Stylesheet" class="ui-theme" />' );
7130 + jQuery( 'head' ).append( $cssLink );
7131 +
7132 + $link = jQuery( 'link.ui-theme' );
7133 + if ( $link.length > 1 ) {
7134 + $link.first().remove();
7135 + }
7136 + }
7137 +
7138 + function setPosClass() {
7139 + /*jshint validthis:true */
7140 + var value = this.value;
7141 + if ( value === 'none' ) {
7142 + value = 'top';
7143 + } else if ( value === 'no_label' ) {
7144 + value = 'none';
7145 + }
7146 + jQuery( '.frm_pos_container' ).removeClass( 'frm_top_container frm_left_container frm_right_container frm_none_container frm_inside_container' ).addClass( 'frm_' + value + '_container' );
7147 + }
7148 +
7149 + function collapseAllSections() {
7150 + jQuery( '.control-section.accordion-section.open' ).removeClass( 'open' );
7151 + }
7152 +
7153 + function textSquishCheck() {
7154 + var size = document.getElementById( 'frm_field_font_size' ).value.replace( /\D/g, '' );
7155 + var height = document.getElementById( 'frm_field_height' ).value.replace( /\D/g, '' );
7156 + var paddingEntered = document.getElementById( 'frm_field_pad' ).value.split( ' ' );
7157 + var paddingCount = paddingEntered.length;
7158 +
7159 + // If too many or too few padding entries, leave now
7160 + if ( paddingCount === 0 || paddingCount > 4 || height === '' ) {
7161 + return;
7162 + }
7163 +
7164 + // Get the top and bottom padding from entered values
7165 + var paddingTop = paddingEntered[0].replace( /\D/g, '' );
7166 + var paddingBottom = paddingTop;
7167 + if ( paddingCount >= 3 ) {
7168 + paddingBottom = paddingEntered[2].replace( /\D/g, '' );
7169 + }
7170 +
7171 + // Check if there is enough space for text
7172 + var textSpace = height - size - paddingTop - paddingBottom - 3;
7173 + if ( textSpace < 0 ) {
7174 + infoModal( frm_admin_js.css_invalid_size );
7175 + }
7176 + }
7177 +
7178 + /* Global settings page */
7179 + function loadSettingsTab( anchor ) {
7180 + var holder = anchor.replace( '#', '' );
7181 + var holderContainer = jQuery( '.frm_' + holder + '_ajax' );
7182 + if ( holderContainer.length ) {
7183 + jQuery.ajax({
7184 + type: 'POST', url: ajaxurl,
7185 + data: {
7186 + 'action': 'frm_settings_tab',
7187 + 'tab': holder.replace( '_settings', '' ),
7188 + 'nonce': frmGlobal.nonce
7189 + },
7190 + success: function( html ) {
7191 + holderContainer.replaceWith( html );
7192 + }
7193 + });
7194 + }
7195 + }
7196 +
7197 + function uninstallNow() {
7198 + /*jshint validthis:true */
7199 + if ( confirmLinkClick( this ) === true ) {
7200 + jQuery( '.frm_uninstall .frm-wait' ).css( 'visibility', 'visible' );
7201 + jQuery.ajax({
7202 + type: 'POST',
7203 + url: ajaxurl,
7204 + data: 'action=frm_uninstall&nonce=' + frmGlobal.nonce,
7205 + success: function( msg ) {
7206 + jQuery( '.frm_uninstall' ).fadeOut( 'slow' );
7207 + window.location = msg;
7208 + }
7209 + });
7210 + }
7211 + return false;
7212 + }
7213 +
7214 + function saveAddonLicense() {
7215 + /*jshint validthis:true */
7216 + var button = jQuery( this );
7217 + var buttonName = this.name;
7218 + var pluginSlug = this.getAttribute( 'data-plugin' );
7219 + var action = buttonName.replace( 'edd_' + pluginSlug + '_license_', '' );
7220 + var license = document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value;
7221 + jQuery.ajax({
7222 + type: 'POST', url: ajaxurl, dataType: 'json',
7223 + data: {action: 'frm_addon_' + action, license: license, plugin: pluginSlug, nonce: frmGlobal.nonce},
7224 + success: function( msg ) {
7225 + var thisRow = button.closest( '.edd_frm_license_row' );
7226 + if ( action === 'deactivate' ) {
7227 + license = '';
7228 + document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value = '';
7229 + }
7230 + thisRow.find( '.edd_frm_license' ).html( license );
7231 + if ( msg.success === true ) {
7232 + thisRow.find( '.frm_icon_font' ).removeClass( 'frm_hidden' );
7233 + thisRow.find( 'div.alignleft' ).toggleClass( 'frm_hidden', 1000 );
7234 + }
7235 +
7236 + var messageBox = thisRow.find( '.frm_license_msg' );
7237 + messageBox.html( msg.message );
7238 + if ( msg.message !== '' ) {
7239 + setTimeout( function() {
7240 + messageBox.html( '' );
7241 + }, 15000 );
7242 + }
7243 + }
7244 + });
7245 + }
7246 +
7247 + /* Import/Export page */
7248 +
7249 + function startFormMigration( event ) {
7250 + event.preventDefault();
7251 +
7252 + var checkedBoxes = jQuery( event.target ).find( 'input:checked' );
7253 + if ( ! checkedBoxes.length ) {
7254 + return;
7255 + }
7256 +
7257 + var ids = [];
7258 + checkedBoxes.each( function( i ) {
7259 + ids[i] = this.value;
7260 + });
7261 +
7262 + // Begin the import process.
7263 + importForms( ids, event.target );
7264 + }
7265 +
7266 + /**
7267 + * Begins the process of importing the forms.
7268 + */
7269 + function importForms( forms, targetForm ) {
7270 +
7271 + // Hide the form select section.
7272 + var $form = jQuery( targetForm ),
7273 + $processSettings = $form.next( '.frm-importer-process' );
7274 +
7275 + // Display total number of forms we have to import.
7276 + $processSettings.find( '.form-total' ).text( forms.length );
7277 + $processSettings.find( '.form-current' ).text( '1' );
7278 +
7279 + $form.hide();
7280 +
7281 + // Show processing status.
7282 + // '.process-completed' might have been shown earlier during a previous import, so hide now.
7283 + $processSettings.find( '.process-completed' ).hide();
7284 + $processSettings.show();
7285 +
7286 + // Create global import queue.
7287 + s.importQueue = forms;
7288 + s.imported = 0;
7289 +
7290 + // Import the first form in the queue.
7291 + importForm( $processSettings );
7292 + }
7293 +
7294 + /**
7295 + * Imports a single form from the import queue.
7296 + */
7297 + function importForm( $processSettings ) {
7298 + var formID = s.importQueue[0],
7299 + provider = $processSettings.closest( '.welcome-panel-content' ).find( 'input[name="slug"]' ).val(),
7300 + data = {
7301 + action: 'frm_import_' + provider,
7302 + form_id: formID,
7303 + nonce: frmGlobal.nonce
7304 + };
7305 +
7306 + // Trigger AJAX import for this form.
7307 + jQuery.post( ajaxurl, data, function( res ) {
7308 +
7309 + if ( res.success ) {
7310 + var statusUpdate;
7311 +
7312 + if ( res.data.error ) {
7313 + statusUpdate = '<p>' + res.data.name + ': ' + res.data.msg + '</p>';
7314 + } else {
7315 + statusUpdate = '<p>Imported <a href="' + res.data.link + '" target="_blank">' + res.data.name + '</a></p>';
7316 + }
7317 +
7318 + $processSettings.find( '.status' ).prepend( statusUpdate );
7319 + $processSettings.find( '.status' ).show();
7320 +
7321 + // Remove this form ID from the queue.
7322 + s.importQueue = jQuery.grep( s.importQueue, function( value ) {
7323 + return value != formID;
7324 + });
7325 + s.imported++;
7326 +
7327 + if ( s.importQueue.length === 0 ) {
7328 + $processSettings.find( '.process-count' ).hide();
7329 + $processSettings.find( '.forms-completed' ).text( s.imported );
7330 + $processSettings.find( '.process-completed' ).show();
7331 + } else {
7332 + // Import next form in the queue.
7333 + $processSettings.find( '.form-current' ).text( s.imported + 1 );
7334 + importForm( $processSettings );
7335 + }
7336 + }
7337 + });
7338 + }
7339 +
7340 + function validateExport( e ) {
7341 + /*jshint validthis:true */
7342 + e.preventDefault();
7343 +
7344 + var s = false;
7345 + var $exportForms = jQuery( 'input[name="frm_export_forms[]"]' );
7346 +
7347 + if ( ! jQuery( 'input[name="frm_export_forms[]"]:checked' ).val() ) {
7348 + $exportForms.closest( '.frm-table-box' ).addClass( 'frm_blank_field' );
7349 + s = 'stop';
7350 + }
7351 +
7352 + var $exportType = jQuery( 'input[name="type[]"]' );
7353 + if ( ! jQuery( 'input[name="type[]"]:checked' ).val() && $exportType.attr( 'type' ) === 'checkbox' ) {
7354 + $exportType.closest( 'p' ).addClass( 'frm_blank_field' );
7355 + s = 'stop';
7356 + }
7357 +
7358 + if ( s === 'stop' ) {
7359 + return false;
7360 + }
7361 +
7362 + e.stopPropagation();
7363 + this.submit();
7364 + }
7365 +
7366 + function removeExportError() {
7367 + /*jshint validthis:true */
7368 + var t = jQuery( this ).closest( '.frm_blank_field' );
7369 + if ( typeof t === 'undefined' ) {
7370 + return;
7371 + }
7372 +
7373 + var $thisName = this.name;
7374 + if ( $thisName === 'type[]' && jQuery( 'input[name="type[]"]:checked' ).val() ) {
7375 + t.removeClass( 'frm_blank_field' );
7376 + } else if ( $thisName === 'frm_export_forms[]' && jQuery( this ).val() ) {
7377 + t.removeClass( 'frm_blank_field' );
7378 + }
7379 +
7380 + }
7381 +
7382 + function checkCSVExtension() {
7383 + /*jshint validthis:true */
7384 + var f = jQuery( this ).val();
7385 + var re = /\.csv$/i;
7386 + if ( f.match( re ) !== null ) {
7387 + jQuery( '.show_csv' ).fadeIn();
7388 + } else {
7389 + jQuery( '.show_csv' ).fadeOut();
7390 + }
7391 + }
7392 +
7393 + function checkExportTypes() {
7394 + /*jshint validthis:true */
7395 + var $dropdown = jQuery( this );
7396 + var $selected = $dropdown.find( ':selected' );
7397 + var s = $selected.data( 'support' );
7398 +
7399 + var multiple = s.indexOf( '|' );
7400 + jQuery( 'input[name="type[]"]' ).each( function() {
7401 + this.checked = false;
7402 + if ( s.indexOf( this.value ) >= 0 ) {
7403 + this.disabled = false;
7404 + if ( multiple === -1 ) {
7405 + this.checked = true;
7406 + }
7407 + } else {
7408 + this.disabled = true;
7409 + }
7410 + });
7411 +
7412 + if ( $dropdown.val() === 'csv' ) {
7413 + jQuery( '.csv_opts' ).show();
7414 + jQuery( '.xml_opts' ).hide();
7415 + } else {
7416 + jQuery( '.csv_opts' ).hide();
7417 + jQuery( '.xml_opts' ).show();
7418 + }
7419 +
7420 + var c = $selected.data( 'count' );
7421 + var exportField = jQuery( 'input[name="frm_export_forms[]"]' );
7422 + if ( c === 'single' ) {
7423 + exportField.prop( 'multiple', false );
7424 + exportField.prop( 'checked', false );
7425 + } else {
7426 + exportField.prop( 'multiple', true );
7427 + exportField.prop( 'disabled', false );
7428 + }
7429 + }
7430 +
7431 + function preventMultipleExport() {
7432 + var type = jQuery( 'select[name=format]' ),
7433 + selected = type.find( ':selected' ),
7434 + count = selected.data( 'count' ),
7435 + exportField = jQuery( 'input[name="frm_export_forms[]"]' );
7436 +
7437 + if ( count === 'single' ) {
7438 + // Disable all other fields to prevent multiple selections.
7439 + if ( this.checked ) {
7440 + exportField.prop( 'disabled', true );
7441 + this.removeAttribute( 'disabled' );
7442 + } else {
7443 + exportField.prop( 'disabled', false );
7444 + }
7445 + } else {
7446 + exportField.prop( 'disabled', false );
7447 + }
7448 + }
7449 +
7450 + function multiselectAccessibility() {
7451 + jQuery( '.multiselect-container' ).find( 'input[type="checkbox"]' ).each( function() {
7452 + var checkbox = jQuery( this );
7453 + checkbox.closest( 'a' ).attr(
7454 + 'aria-describedby',
7455 + checkbox.is( ':checked' ) ? 'frm_press_space_checked' : 'frm_press_space_unchecked'
7456 + );
7457 + });
7458 + }
7459 +
7460 + function initiateMultiselect() {
7461 + jQuery( '.frm_multiselect' ).hide().each( function() {
7462 + var $select = jQuery( this ),
7463 + id = $select.is( '[id]' ) ? $select.attr( 'id' ).replace( '[]', '' ) : false,
7464 + labelledBy = id ? jQuery( '#for_' + id ) : false;
7465 + labelledBy = id && labelledBy.length ? 'aria-labelledby="' + labelledBy.attr( 'id' ) + '"' : '';
7466 + $select.multiselect({
7467 + templates: {
7468 + ul: '<ul class="multiselect-container frm-dropdown-menu"></ul>',
7469 + li: '<li><a tabindex="0"><label></label></a></li>',
7470 + button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown" aria-describedby="frm_multiselect_button" ' + labelledBy + '><span class="multiselect-selected-text"></span> <b class="caret"></b></button>'
7471 + },
7472 + buttonContainer: '<div class="btn-group frm-btn-group dropdown" />',
7473 + nonSelectedText: '',
7474 + onDropdownShown: function( event ) {
7475 + var action = jQuery( event.currentTarget.closest( '.frm_form_action_settings, #frm-show-fields' ) );
7476 + if ( action.length ) {
7477 + jQuery( '#wpcontent' ).on( 'click', function() {
7478 + if ( jQuery( '.multiselect-container.frm-dropdown-menu' ).is( ':visible' ) ) {
7479 + jQuery( event.currentTarget ).removeClass( 'open' );
7480 + }
7481 + });
7482 + }
7483 +
7484 + multiselectAccessibility();
7485 + },
7486 + onChange: function( element, option ) {
7487 + multiselectAccessibility();
7488 + $select.trigger( 'frm-multiselect-changed', element, option );
7489 + }
7490 + });
7491 + });
7492 + }
7493 +
7494 + /* Addons page */
7495 + function installMultipleAddons( e ) {
7496 + e.preventDefault();
7497 + installOrActivate( this, 'frm_multiple_addons' );
7498 + }
7499 +
7500 + function activateAddon( e ) {
7501 + e.preventDefault();
7502 + installOrActivate( this, 'frm_activate_addon' );
7503 + }
7504 +
7505 + function installAddon( e ) {
7506 + e.preventDefault();
7507 + installOrActivate( this, 'frm_install_addon' );
7508 + }
7509 +
7510 + function installOrActivate( clicked, action ) {
7511 + var button, plugin, el, message;
7512 +
7513 + // Remove any leftover error messages, output an icon and get the plugin basename that needs to be activated.
7514 + jQuery( '.frm-addon-error' ).remove();
7515 + button = jQuery( clicked );
7516 + plugin = button.attr( 'rel' );
7517 + el = button.parent();
7518 + message = el.parent().find( '.addon-status-label' );
7519 +
7520 + button.addClass( 'frm_loading_button' );
7521 +
7522 + // Process the Ajax to perform the activation.
7523 + jQuery.ajax({
7524 + url: ajaxurl,
7525 + type: 'POST',
7526 + async: true,
7527 + cache: false,
7528 + dataType: 'json',
7529 + data: {
7530 + action: action,
7531 + nonce: frmGlobal.nonce,
7532 + plugin: plugin
7533 + },
7534 + success: function( response ) {
7535 + var saveAndReload, error;
7536 +
7537 + if ( 'string' !== typeof response && 'string' === typeof response.message ) {
7538 + if ( 'undefined' !== typeof response.saveAndReload ) {
7539 + saveAndReload = response.saveAndReload;
7540 + }
7541 + response = response.message;
7542 + }
7543 +
7544 + error = extractErrorFromAddOnResponse( response );
7545 +
7546 + if ( error ) {
7547 + addonError( error, el, button );
7548 + return;
7549 + }
7550 +
7551 + afterAddonInstall( response, button, message, el, saveAndReload );
7552 + },
7553 + error: function() {
7554 + button.removeClass( 'frm_loading_button' );
7555 + }
7556 + });
7557 + }
7558 +
7559 + function installAddonWithCreds( e ) {
7560 + // Prevent the default action, let the user know we are attempting to install again and go with it.
7561 + e.preventDefault();
7562 +
7563 + // Now let's make another Ajax request once the user has submitted their credentials.
7564 + var proceed = jQuery( this ),
7565 + el = proceed.parent().parent(),
7566 + plugin = proceed.attr( 'rel' );
7567 +
7568 + proceed.addClass( 'frm_loading_button' );
7569 +
7570 + jQuery.ajax({
7571 + url: ajaxurl,
7572 + type: 'POST',
7573 + async: true,
7574 + cache: false,
7575 + dataType: 'json',
7576 + data: {
7577 + action: 'frm_install_addon',
7578 + nonce: frm_admin_js.nonce,
7579 + plugin: plugin,
7580 + hostname: el.find( '#hostname' ).val(),
7581 + username: el.find( '#username' ).val(),
7582 + password: el.find( '#password' ).val()
7583 + },
7584 + success: function( response ) {
7585 + var error = extractErrorFromAddOnResponse( response );
7586 +
7587 + if ( error ) {
7588 + addonError( error, el, proceed );
7589 + return;
7590 + }
7591 +
7592 + afterAddonInstall( response, proceed, message, el );
7593 + },
7594 + error: function() {
7595 + proceed.removeClass( 'frm_loading_button' );
7596 + }
7597 + });
7598 + }
7599 +
7600 + function afterAddonInstall( response, button, message, el, saveAndReload ) {
7601 + var $addonStatus, refreshPage;
7602 +
7603 + $addonStatus = jQuery( document.getElementById( 'frm-addon-status' ) );
7604 + // The Ajax request was successful, so let's update the output.
7605 + button.css({ opacity: '0' });
7606 + message.text( frm_admin_js.active );
7607 + jQuery( '#frm-oneclick' ).hide();
7608 + $addonStatus.text( response ).show();
7609 + jQuery( '#frm_upgrade_modal h2' ).hide();
7610 + jQuery( '#frm_upgrade_modal .frm_lock_icon' ).addClass( 'frm_lock_open_icon' );
7611 + jQuery( '#frm_upgrade_modal .frm_lock_icon use' ).attr( 'xlink:href', '#frm_lock_open_icon' );
7612 +
7613 + // Proceed with CSS changes
7614 + el.parent().removeClass( 'frm-addon-not-installed frm-addon-installed' ).addClass( 'frm-addon-active' );
7615 + button.removeClass( 'frm_loading_button' );
7616 +
7617 + // Maybe refresh import and SMTP pages
7618 + refreshPage = document.querySelectorAll( '.frm-admin-page-import, #frm-admin-smtp, #frm-welcome' );
7619 + if ( refreshPage.length > 0 ) {
7620 + window.location.reload();
7621 + } else if ( 'settings' === saveAndReload ) {
7622 + $addonStatus.append( getSaveAndReloadSettingsOptions() );
7623 + }
7624 + }
7625 +
7626 + function getSaveAndReloadSettingsOptions() {
7627 + var wrapper = div({ id: 'frm_save_and_reload_options' });
7628 + wrapper.appendChild( saveAndReloadSettingsButton() );
7629 + wrapper.appendChild( closePopupButton() );
7630 + return wrapper;
7631 + }
7632 +
7633 + function saveAndReloadSettingsButton() {
7634 + var button = document.createElement( 'button' );
7635 + button.id = 'frm_save_and_reload_settings';
7636 + button.classList.add( 'button', 'button-primary', 'frm-button-primary' );
7637 + button.textContent = __( 'Save and Reload', 'formidable' );
7638 + return button;
7639 + }
7640 +
7641 + function closePopupButton() {
7642 + var a = document.createElement( 'a' );
7643 + a.setAttribute( 'href', '#' );
7644 + a.classList.add( 'button', 'button-secondary', 'frm-button-secondary', 'dismiss' );
7645 + a.textContent = __( 'Close', 'formidable' );
7646 + return a;
7647 + }
7648 +
7649 + function extractErrorFromAddOnResponse( response ) {
7650 + if ( typeof response !== 'string' ) {
7651 + if ( typeof response.success !== 'undefined' && response.success ) {
7652 + return false;
7653 + }
7654 +
7655 + if ( response.form ) {
7656 + if ( jQuery( response.form ).is( '#message' ) ) {
7657 + return {
7658 + message: jQuery( response.form ).find( 'p' ).html()
7659 + };
7660 + }
7661 + }
7662 +
7663 + return response;
7664 + }
7665 +
7666 + return false;
7667 + }
7668 +
7669 + function addonError( response, el, button ) {
7670 + if ( response.form ) {
7671 + jQuery( '.frm-inline-error' ).remove();
7672 + button.closest( '.frm-card' )
7673 + .html( response.form )
7674 + .css({ padding: 5 })
7675 + .find( '#upgrade' )
7676 + .attr( 'rel', button.attr( 'rel' ) )
7677 + .on( 'click', installAddonWithCreds );
7678 + } else {
7679 + el.append( '<div class="frm-addon-error frm_error_style"><p><strong>' + response.message + '</strong></p></div>' );
7680 + button.removeClass( 'frm_loading_button' );
7681 + jQuery( '.frm-addon-error' ).delay( 4000 ).fadeOut();
7682 + }
7683 + }
7684 +
7685 + /* Templates */
7686 +
7687 + function initNewFormModal() {
7688 + var installFormTrigger,
7689 + activeHoverIcons,
7690 + $modal,
7691 + handleError,
7692 + handleEmailAddressError,
7693 + handleConfirmEmailAddressError,
7694 + showFreeTemplatesForm,
7695 + firstLockedTemplate,
7696 + isShowFreeTemplatesFormFirst,
7697 + url,
7698 + urlParams;
7699 +
7700 + url = new URL( window.location.href );
7701 + urlParams = url.searchParams;
7702 +
7703 + isShowFreeTemplatesFormFirst = urlParams.get( 'free-templates' );
7704 +
7705 + jQuery( document ).on( 'click', '.frm-trigger-new-form-modal', triggerNewFormModal );
7706 + $modal = initModal( '#frm_new_form_modal', '600px' );
7707 +
7708 + installFormTrigger = document.createElement( 'a' );
7709 + installFormTrigger.classList.add( 'frm-install-template', 'frm_hidden' );
7710 + document.body.appendChild( installFormTrigger );
7711 +
7712 + jQuery( '.frm-install-template' ).on( 'click', function( event ) {
7713 + var $h3Clone = jQuery( this ).closest( 'li, td' ).find( 'h3' ).clone(),
7714 + nameLabel = document.getElementById( 'frm_new_name' ),
7715 + descLabel = document.getElementById( 'frm_new_desc' ),
7716 + oldName;
7717 +
7718 + $h3Clone.find( 'svg, .frm-plan-required-tag' ).remove();
7719 + oldName = $h3Clone.html().trim();
7720 +
7721 + event.preventDefault();
7722 +
7723 + document.getElementById( 'frm_template_name' ).value = oldName;
7724 + document.getElementById( 'frm_link' ).value = this.attributes.rel.value;
7725 + document.getElementById( 'frm_action_type' ).value = 'frm_install_template';
7726 + nameLabel.innerHTML = nameLabel.getAttribute( 'data-form' );
7727 + descLabel.innerHTML = descLabel.getAttribute( 'data-form' );
7728 + $modal.dialog( 'open' );
7729 + });
7730 +
7731 + jQuery( document ).on( 'submit', '#frm-new-template', installTemplate );
7732 +
7733 + jQuery( document ).on( 'click', '.frm-hover-icons .frm-preview-form', function( event ) {
7734 + var $li, link, iframe,
7735 + container = document.getElementById( 'frm-preview-block' );
7736 +
7737 + event.preventDefault();
7738 +
7739 + $li = jQuery( this ).closest( 'li' );
7740 + link = $li.attr( 'data-preview' );
7741 +
7742 + if ( link.indexOf( ajaxurl ) > -1 ) {
7743 + iframe = document.createElement( 'iframe' );
7744 + iframe.src = link;
7745 + iframe.height = '400';
7746 + iframe.width = '100%';
7747 + container.innerHTML = '';
7748 + container.appendChild( iframe );
7749 + } else {
7750 + frmApiPreview( container, link );
7751 + }
7752 +
7753 + jQuery( '#frm-preview-title' ).text( getStrippedTemplateName( $li ) );
7754 + $modal.attr( 'frm-page', 'preview' );
7755 + activeHoverIcons = jQuery( this ).closest( '.frm-hover-icons' );
7756 + });
7757 +
7758 + jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-create-form', function( event ) {
7759 + var $li, name, link, action;
7760 +
7761 + event.preventDefault();
7762 +
7763 + $li = jQuery( this ).closest( 'li' );
7764 +
7765 + if ( $li.is( '[data-href]' ) ) {
7766 + window.location = $li.attr( 'data-href' );
7767 + return;
7768 + }
7769 +
7770 + if ( $li.hasClass( 'frm-add-blank-form' ) ) {
7771 + name = link = '';
7772 + action = 'frm_install_form';
7773 + } else if ( $li.is( '[data-rel]' ) ) {
7774 + name = getStrippedTemplateName( $li );
7775 + link = $li.attr( 'data-rel' );
7776 + action = 'frm_install_template';
7777 + } else {
7778 + return;
7779 + }
7780 +
7781 + transitionToAddDetails( $modal, name, link, action );
7782 + });
7783 +
7784 + // Welcome page modals.
7785 + jQuery( document ).on( 'click', '.frm-create-blank-form', function( event ) {
7786 + event.preventDefault();
7787 + jQuery( '.frm-trigger-new-form-modal' ).trigger( 'click' );
7788 + transitionToAddDetails( $modal, '', '', 'frm_install_form' );
7789 +
7790 + // Close the modal with the cancel button.
7791 + jQuery( '.frm-modal-cancel.frm-back-to-all-templates' ).on( 'click', function() {
7792 + jQuery( '.ui-widget-overlay' ).trigger( 'click' );
7793 + });
7794 + });
7795 +
7796 + 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 ) {
7797 + var $hoverIcons, $trigger,
7798 + $li = jQuery( this ).closest( 'li' ),
7799 + triggerClass = $li.hasClass( 'frm-locked-template' ) ? 'frm-unlock-form' : 'frm-create-form';
7800 +
7801 + $hoverIcons = $li.find( '.frm-hover-icons' );
7802 + if ( ! $hoverIcons.length ) {
7803 + $li.trigger( 'mouseover' );
7804 + $hoverIcons = $li.find( '.frm-hover-icons' );
7805 + $hoverIcons.hide();
7806 + }
7807 +
7808 + $trigger = $hoverIcons.find( '.' + triggerClass );
7809 + $trigger.trigger( 'click' );
7810 + });
7811 +
7812 + jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-delete-form', function( event ) {
7813 + var $li,
7814 + trigger;
7815 +
7816 + event.preventDefault();
7817 +
7818 + $li = jQuery( this ).closest( 'li' );
7819 + $li.addClass( 'frm-deleting' );
7820 + trigger = document.createElement( 'a' );
7821 + trigger.setAttribute( 'href', '#' );
7822 + trigger.setAttribute( 'data-id', $li.attr( 'data-formid' ) );
7823 + $li.attr( 'id', 'frm-template-custom-' + $li.attr( 'data-formid' ) );
7824 + jQuery( trigger ).on( 'click', trashTemplate );
7825 + trigger.click();
7826 + setTemplateCount( $li.closest( '.accordion-section' ).get( 0 ) );
7827 + });
7828 +
7829 + showFreeTemplatesForm = function( $el ) {
7830 + var formContainer = document.getElementById( 'frmapi-email-form' );
7831 + jQuery.ajax({
7832 + dataType: 'json',
7833 + url: formContainer.getAttribute( 'data-url' ),
7834 + success: function( json ) {
7835 + var form = json.renderedHtml;
7836 + form = form.replace( /<script\b[^<]*(community.formidableforms.com\/wp-includes\/js\/jquery\/jquery)[^<]*><\/script>/gi, '' );
7837 + form = form.replace( /<link\b[^>]*(formidableforms.css)[^>]*>/gi, '' );
7838 + formContainer.innerHTML = form;
7839 + }
7840 + });
7841 +
7842 + $modal.attr( 'frm-page', 'email' );
7843 + $modal.attr( 'frm-this-form', $el.attr( 'data-key' ) );
7844 + $el.append( installFormTrigger );
7845 + };
7846 +
7847 + jQuery( document ).on( 'click', 'li.frm-locked-template .frm-hover-icons .frm-unlock-form', function( event ) {
7848 + var $li,
7849 + activePage;
7850 +
7851 + event.preventDefault();
7852 +
7853 + $li = jQuery( this ).closest( '.frm-locked-template' );
7854 +
7855 + if ( $li.hasClass( 'frm-free-template' ) ) {
7856 + showFreeTemplatesForm( $li );
7857 + return;
7858 + }
7859 +
7860 + if ( $modal.hasClass( 'frm-expired' ) ) {
7861 + activePage = 'renew';
7862 + } else {
7863 + activePage = 'upgrade';
7864 + }
7865 +
7866 + $modal.attr( 'frm-page', activePage );
7867 + });
7868 +
7869 + jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop', function() {
7870 + jQuery( this )
7871 + .closest( '.accordion-section-content' ).css( 'overflow', 'visible' )
7872 + .closest( '.accordion-section' ).css( 'z-index', 1 );
7873 + });
7874 +
7875 + jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop + ul .frm-build-template', function() {
7876 + var name = this.getAttribute( 'data-fullname' ),
7877 + link = this.getAttribute( 'data-formid' ),
7878 + action = 'frm_build_template';
7879 + transitionToAddDetails( $modal, name, link, action );
7880 + });
7881 +
7882 + handleError = function( inputId, errorId, type, message ) {
7883 + var $error = jQuery( errorId );
7884 + $error.removeClass( 'frm_hidden' ).attr( 'frm-error', type );
7885 +
7886 + if ( typeof message !== 'undefined' ) {
7887 + $error.find( 'span[frm-error="' + type + '"]' ).text( message );
7888 + }
7889 +
7890 + jQuery( inputId ).one( 'keyup', function() {
7891 + $error.addClass( 'frm_hidden' );
7892 + });
7893 + };
7894 +
7895 + handleEmailAddressError = function( type ) {
7896 + handleError( '#frm_leave_email', '#frm_leave_email_error', type );
7897 + };
7898 +
7899 + jQuery( document ).on( 'click', '#frm-add-my-email-address', function( event ) {
7900 + var email = document.getElementById( 'frm_leave_email' ).value.trim(),
7901 + regex,
7902 + $hiddenForm,
7903 + $hiddenEmailField;
7904 +
7905 + event.preventDefault();
7906 +
7907 + if ( '' === email ) {
7908 + handleEmailAddressError( 'empty' );
7909 + return;
7910 + }
7911 +
7912 + 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;
7913 +
7914 + if ( regex.test( email ) === false ) {
7915 + handleEmailAddressError( 'invalid' );
7916 + return;
7917 + }
7918 +
7919 + $hiddenForm = jQuery( '#frmapi-email-form' ).find( 'form' );
7920 + $hiddenEmailField = $hiddenForm.find( '[type="email"]' ).not( '.frm_verify' );
7921 + if ( ! $hiddenEmailField.length ) {
7922 + return;
7923 + }
7924 +
7925 + $hiddenEmailField.val( email );
7926 + jQuery.ajax({
7927 + type: 'POST',
7928 + url: $hiddenForm.attr( 'action' ),
7929 + data: $hiddenForm.serialize() + '&action=frm_forms_preview'
7930 + }).done( function( data ) {
7931 + var message = jQuery( data ).find( '.frm_message' ).text().trim();
7932 + if ( message.indexOf( 'Thanks!' ) >= 0 ) {
7933 + $modal.attr( 'frm-page', 'code' );
7934 + } else {
7935 + handleEmailAddressError( 'invalid' );
7936 + }
7937 + });
7938 + });
7939 +
7940 + handleConfirmEmailAddressError = function( type, message ) {
7941 + handleError( '#frm_code_from_email', '#frm_code_from_email_error', type, message );
7942 + };
7943 +
7944 + jQuery( document ).on( 'click', '.frm-confirm-email-address', function( event ) {
7945 + var code = document.getElementById( 'frm_code_from_email' ).value.trim();
7946 +
7947 + event.preventDefault();
7948 +
7949 + if ( '' === code ) {
7950 + handleConfirmEmailAddressError( 'empty' );
7951 + return;
7952 + }
7953 +
7954 + jQuery.ajax({
7955 + type: 'POST',
7956 + url: ajaxurl,
7957 + dataType: 'json',
7958 + data: {
7959 + action: 'template_api_signup',
7960 + nonce: frmGlobal.nonce,
7961 + code: code,
7962 + key: $modal.attr( 'frm-this-form' )
7963 + },
7964 + success: function( response ) {
7965 + if ( response.success ) {
7966 + if ( isShowFreeTemplatesFormFirst ) {
7967 + // Remove free-templates param from URL then reload page.
7968 + urlParams.delete( 'free-templates' );
7969 + url.search = urlParams.toString();
7970 + window.location.href = url.toString();
7971 +
7972 + return;
7973 + }
7974 +
7975 + if ( typeof response.data !== 'undefined' && typeof response.data.url !== 'undefined' ) {
7976 + installFormTrigger.setAttribute( 'rel', response.data.url );
7977 + installFormTrigger.click();
7978 + $modal.attr( 'frm-page', 'details' );
7979 + document.getElementById( 'frm_action_type' ).value = 'frm_install_template';
7980 +
7981 + if ( typeof response.data.urlByKey !== 'undefined' ) {
7982 + updateTemplateModalFreeUrls( response.data.urlByKey );
7983 + }
7984 + }
7985 + } else {
7986 + if ( Array.isArray( response.data ) && response.data.length ) {
7987 + handleConfirmEmailAddressError( 'custom', response.data[0].message );
7988 + } else {
7989 + handleConfirmEmailAddressError( 'wrong-code' );
7990 + }
7991 +
7992 + jQuery( '#frm_code_from_email_options' ).removeClass( 'frm_hidden' );
7993 + }
7994 + }
7995 + });
7996 + });
7997 +
7998 + jQuery( document ).on( 'click', '#frm-change-email-address', function() {
7999 + $modal.attr( 'frm-page', 'email' );
8000 + });
8001 +
8002 + jQuery( document ).on( 'click', '#frm-resend-code', function() {
8003 + document.getElementById( 'frm_code_from_email' ).value = '';
8004 + jQuery( '#frm_code_from_email_options, #frm_code_from_email_error' ).addClass( 'frm_hidden' );
8005 + document.getElementById( 'frm-add-my-email-address' ).click();
8006 + });
8007 +
8008 + jQuery( document ).on( 'frmAfterSearch', '#frm_new_form_modal #template-search-input', function() {
8009 + var categories = $modal.get( 0 ).querySelector( '.frm-categories-list' ).children,
8010 + categoryIndex,
8011 + category,
8012 + searchableTemplates,
8013 + count;
8014 +
8015 + for ( categoryIndex in categories ) {
8016 + if ( isNaN( categoryIndex ) ) {
8017 + continue;
8018 + }
8019 +
8020 + category = categories[ categoryIndex ];
8021 + searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden)' );
8022 + count = searchableTemplates.length;
8023 + jQuery( category ).toggleClass( 'frm_hidden', this.value !== '' && ! count );
8024 + setTemplateCount( category, searchableTemplates );
8025 + }
8026 + });
8027 +
8028 + 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 ) {
8029 + document.getElementById( 'frm-create-title' ).removeAttribute( 'frm-type' );
8030 + $modal.attr( 'frm-page', 'create' );
8031 + });
8032 +
8033 + jQuery( document ).on( 'click', '.frm-use-this-template', function( event ) {
8034 + var $trigger;
8035 +
8036 + event.preventDefault();
8037 +
8038 + $trigger = activeHoverIcons.find( '.frm-create-form' );
8039 + if ( $trigger.closest( '.frm-selectable' ).hasClass( 'frm-locked-template' ) ) {
8040 + $trigger = activeHoverIcons.find( '.frm-unlock-form' );
8041 + }
8042 +
8043 + $trigger.trigger( 'click' );
8044 + });
8045 +
8046 + jQuery( document ).on( 'click', '.frm-submit-new-template', function( event ) {
8047 + var button;
8048 + event.preventDefault();
8049 + button = document.getElementById( 'frm-new-template' ).querySelector( 'button' );
8050 + if ( null !== button ) {
8051 + button.click();
8052 + }
8053 + });
8054 +
8055 + if ( urlParams.get( 'triggerNewFormModal' ) ) {
8056 + triggerNewFormModal();
8057 +
8058 + if ( isShowFreeTemplatesFormFirst ) {
8059 + firstLockedTemplate = jQuery( 'li.frm-locked-template.frm-free-template' ).eq( 0 );
8060 +
8061 + if ( firstLockedTemplate.length ) {
8062 + showFreeTemplatesForm( firstLockedTemplate );
8063 + }
8064 + }
8065 + }
8066 + }
8067 +
8068 + function updateTemplateModalFreeUrls( urlByKey ) {
8069 + jQuery( '#frm_new_form_modal' ).find( '.frm-selectable[data-key]' ).each( function() {
8070 + var $template = jQuery( this ),
8071 + key = $template.attr( 'data-key' );
8072 + if ( 'undefined' !== typeof urlByKey[ key ]) {
8073 + $template.removeClass( 'frm-locked-template' );
8074 + $template.find( 'h3 svg' ).remove(); // remove the lock from the title
8075 + $template.attr( 'data-rel', urlByKey[ key ]);
8076 + }
8077 + });
8078 + }
8079 +
8080 + function transitionToAddDetails( $modal, name, link, action ) {
8081 + var nameLabel = document.getElementById( 'frm_new_name' ),
8082 + descLabel = document.getElementById( 'frm_new_desc' ),
8083 + type = [ 'frm_install_template', 'frm_install_form' ].indexOf( action ) >= 0 ? 'form' : 'template',
8084 + templateNameInput = document.getElementById( 'frm_template_name' );
8085 +
8086 + templateNameInput.value = name;
8087 + document.getElementById( 'frm_link' ).value = link;
8088 + document.getElementById( 'frm_action_type' ).value = action;
8089 + nameLabel.textContent = nameLabel.getAttribute( 'data-' + type );
8090 + descLabel.textContent = descLabel.getAttribute( 'data-' + type );
8091 +
8092 + document.getElementById( 'frm-create-title' ).setAttribute( 'frm-type', type );
8093 +
8094 + $modal.attr( 'frm-page', 'details' );
8095 +
8096 + if ( '' === name ) {
8097 + templateNameInput.focus();
8098 + }
8099 + }
8100 +
8101 + function getStrippedTemplateName( $li ) {
8102 + var $clone = $li.find( 'h3' ).clone();
8103 + $clone.find( 'svg, .frm-plan-required-tag' ).remove();
8104 + return $clone.html().trim();
8105 + }
8106 +
8107 + function setTemplateCount( category, searchableTemplates ) {
8108 + var count,
8109 + templateIndex,
8110 + availableCounter,
8111 + availableCount;
8112 +
8113 + if ( typeof searchableTemplates === 'undefined' ) {
8114 + searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden):not(.frm-deleting)' );
8115 + }
8116 +
8117 + count = searchableTemplates.length;
8118 + category.querySelector( '.frm-template-count' ).textContent = count;
8119 +
8120 + jQuery( category ).find( '.frm-templates-plural' ).toggleClass( 'frm_hidden', count === 1 );
8121 + jQuery( category ).find( '.frm-templates-singular' ).toggleClass( 'frm_hidden', count !== 1 );
8122 +
8123 + availableCounter = category.querySelector( '.frm-available-templates-count' );
8124 + if ( availableCounter !== null ) {
8125 + availableCount = 0;
8126 + for ( templateIndex in searchableTemplates ) {
8127 + if ( ! isNaN( templateIndex ) && ! searchableTemplates[ templateIndex ].classList.contains( 'frm-locked-template' ) ) {
8128 + availableCount++;
8129 + }
8130 + }
8131 +
8132 + availableCounter.textContent = availableCount;
8133 + }
8134 + }
8135 +
8136 + function initSelectionAutocomplete() {
8137 + if ( jQuery.fn.autocomplete ) {
8138 + initAutocomplete( 'page' );
8139 + initAutocomplete( 'user' );
8140 + }
8141 + }
8142 +
8143 + /**
8144 + * Init autocomplete.
8145 + *
8146 + * @since 4.10.01 Add container param to init autocomplete elements inside an element.
8147 + *
8148 + * @param {String} type Type of data. Accepts `page` or `user`.
8149 + * @param {String|Object} container Container class or element. Default is null.
8150 + */
8151 + function initAutocomplete( type, container ) {
8152 + const basedUrlParams = '?action=frm_' + type + '_search&nonce=' + frmGlobal.nonce;
8153 + const elements = ! container ? jQuery( '.frm-' + type + '-search' ) : jQuery( container ).find( '.frm-' + type + '-search' );
8154 +
8155 + elements.each( function() {
8156 + let urlParams = basedUrlParams;
8157 + const element = jQuery( this );
8158 +
8159 + // Check if a custom post type is specific.
8160 + if ( element.attr( 'data-post-type' ) ) {
8161 + urlParams += '&post_type=' + element.attr( 'data-post-type' );
8162 + }
8163 + element.autocomplete({
8164 + delay: 100,
8165 + minLength: 0,
8166 + source: ajaxurl + urlParams,
8167 + change: autoCompleteSelectBlank,
8168 + select: autoCompleteSelectFromResults,
8169 + focus: autoCompleteFocus,
8170 + position: {
8171 + my: 'left top',
8172 + at: 'left bottom',
8173 + collision: 'flip'
8174 + },
8175 + response: function( event, ui ) {
8176 + if ( ! ui.content.length ) {
8177 + var noResult = { value: '', label: frm_admin_js.no_items_found };
8178 + ui.content.push( noResult );
8179 + }
8180 + },
8181 + create: function() {
8182 + var $container = jQuery( this ).parent();
8183 +
8184 + if ( $container.length === 0 ) {
8185 + $container = 'body';
8186 + }
8187 +
8188 + jQuery( this ).autocomplete( 'option', 'appendTo', $container );
8189 + }
8190 + })
8191 + .on( 'focus', function() {
8192 + // Show options on click to make it work more like a dropdown.
8193 + if ( this.value === '' || this.nextElementSibling.value < 1 ) {
8194 + jQuery( this ).autocomplete( 'search', this.value );
8195 + }
8196 + });
8197 + });
8198 + }
8199 +
8200 + /**
8201 + * Prevent the value from changing when using keyboard to scroll.
8202 + */
8203 + function autoCompleteFocus() {
8204 + return false;
8205 + }
8206 +
8207 + function autoCompleteSelectBlank( e, ui ) {
8208 + if ( ui.item === null ) {
8209 + this.nextElementSibling.value = '';
8210 + }
8211 + }
8212 +
8213 + function autoCompleteSelectFromResults( e, ui ) {
8214 + e.preventDefault();
8215 +
8216 + if ( ui.item.value === '' ) {
8217 + this.value = '';
8218 + } else {
8219 + this.value = ui.item.label;
8220 + }
8221 +
8222 + this.nextElementSibling.value = ui.item.value;
8223 + }
8224 +
8225 + function nextInstallStep( thisStep ) {
8226 + thisStep.classList.add( 'frm_grey' );
8227 + thisStep.nextElementSibling.classList.remove( 'frm_grey' );
8228 + }
8229 +
8230 + function frmApiPreview( cont, link ) {
8231 + cont.innerHTML = '<div class="frm-wait"></div>';
8232 + jQuery.ajax({
8233 + dataType: 'json',
8234 + url: link,
8235 + success: function( json ) {
8236 + var form = json.renderedHtml;
8237 + form = form.replace( /<script\b[^<]*(js\/jquery\/jquery)[^<]*><\/script>/gi, '' );
8238 + form = form.replace( /<link\b[^>]*(jquery-ui.min.css)[^>]*>/gi, '' );
8239 + form = form.replace( ' frm_logic_form ', ' ' );
8240 + form = form.replace( '<form ', '<form onsubmit="event.preventDefault();" ' );
8241 + cont.innerHTML = '<div class="frm-wait" id="frm-remove-me"></div><div class="frm-fade" id="frm-show-me">' +
8242 + form + '</div>';
8243 + setTimeout( function() {
8244 + document.getElementById( 'frm-remove-me' ).style.display = 'none';
8245 + document.getElementById( 'frm-show-me' ).style.opacity = '1';
8246 + }, 300 );
8247 + }
8248 + });
8249 + }
8250 +
8251 + function installTemplateFieldset( e ) {
8252 + /*jshint validthis:true */
8253 + var fieldset = this.parentNode.parentNode,
8254 + action = fieldset.elements.type.value,
8255 + button = this;
8256 + e.preventDefault();
8257 + button.classList.add( 'frm_loading_button' );
8258 + installNewForm( fieldset, action, button );
8259 + }
8260 +
8261 + function installTemplate( e ) {
8262 + /*jshint validthis:true */
8263 + var action = this.elements.type.value,
8264 + button = this.querySelector( 'button' );
8265 + e.preventDefault();
8266 + button.classList.add( 'frm_loading_button' );
8267 + installNewForm( this, action, button );
8268 + }
8269 +
8270 + function installNewForm( form, action, button ) {
8271 + var data, redirect, href, showError,
8272 + formData = formToData( form ),
8273 + formName = formData.template_name,
8274 + formDesc = formData.template_desc,
8275 + link = form.elements.link.value;
8276 +
8277 + data = {
8278 + action: action,
8279 + xml: link,
8280 + name: formName,
8281 + desc: formDesc,
8282 + form: JSON.stringify( formData ),
8283 + nonce: frmGlobal.nonce
8284 + };
8285 + postAjax( data, function( response ) {
8286 + redirect = response.redirect;
8287 + if ( typeof redirect !== 'undefined' ) {
8288 + if ( typeof form.elements.redirect === 'undefined' ) {
8289 + window.location = redirect;
8290 + } else {
8291 + href = document.getElementById( 'frm-redirect-link' );
8292 + if ( typeof link !== 'undefined' && href !== null ) {
8293 + // Show the next installation step.
8294 + href.setAttribute( 'href', redirect );
8295 + href.classList.remove( 'frm_grey', 'disabled' );
8296 + nextInstallStep( form.parentNode.parentNode );
8297 + button.classList.add( 'frm_grey', 'disabled' );
8298 + }
8299 + }
8300 + } else {
8301 + jQuery( '.spinner' ).css( 'visibility', 'hidden' );
8302 +
8303 + // Show response.message
8304 + if ( response.message && typeof form.elements.show_response !== 'undefined' ) {
8305 + showError = document.getElementById( form.elements.show_response.value );
8306 + if ( showError !== null ) {
8307 + showError.innerHTML = response.message;
8308 + showError.classList.remove( 'frm_hidden' );
8309 + }
8310 + }
8311 + }
8312 + button.classList.remove( 'frm_loading_button' );
8313 + });
8314 + }
8315 +
8316 + function trashTemplate( e ) {
8317 + /*jshint validthis:true */
8318 + var id = this.getAttribute( 'data-id' );
8319 + e.preventDefault();
8320 +
8321 + data = {
8322 + action: 'frm_forms_trash',
8323 + id: id,
8324 + nonce: frmGlobal.nonce
8325 + };
8326 + postAjax( data, function() {
8327 + var card = document.getElementById( 'frm-template-custom-' + id );
8328 + fadeOut( card, function() {
8329 + card.parentNode.removeChild( card );
8330 + });
8331 + });
8332 + }
8333 +
8334 + function searchContent() {
8335 + /*jshint validthis:true */
8336 + var i,
8337 + regEx = false,
8338 + searchText = this.value.toLowerCase(),
8339 + toSearch = this.getAttribute( 'data-tosearch' ),
8340 + items = document.getElementsByClassName( toSearch );
8341 +
8342 + if ( this.tagName === 'SELECT' ) {
8343 + searchText = selectedOptions( this );
8344 + searchText = searchText.join( '|' ).toLowerCase();
8345 + regEx = true;
8346 + }
8347 +
8348 + if ( toSearch === 'frm-action' && searchText !== '' ) {
8349 + var addons = document.getElementById( 'frm_email_addon_menu' ).classList;
8350 + addons.remove( 'frm-all-actions' );
8351 + addons.add( 'frm-limited-actions' );
8352 + }
8353 +
8354 + for ( i = 0; i < items.length; i++ ) {
8355 + var innerText = items[i].innerText.toLowerCase();
8356 + if ( searchText === '' ) {
8357 + items[i].classList.remove( 'frm_hidden' );
8358 + items[i].classList.remove( 'frm-search-result' );
8359 + } else if ( ( regEx && new RegExp( searchText ).test( innerText ) ) || innerText.indexOf( searchText ) >= 0 ) {
8360 + items[i].classList.remove( 'frm_hidden' );
8361 + items[i].classList.add( 'frm-search-result' );
8362 + } else {
8363 + items[i].classList.add( 'frm_hidden' );
8364 + items[i].classList.remove( 'frm-search-result' );
8365 + }
8366 + }
8367 +
8368 + jQuery( this ).trigger( 'frmAfterSearch' );
8369 + }
8370 +
8371 + function stopPropagation( e ) {
8372 + e.stopPropagation();
8373 + }
8374 +
8375 + /* Helpers */
8376 +
8377 + function selectedOptions( select ) {
8378 + var opt,
8379 + result = [],
8380 + options = select && select.options;
8381 +
8382 + for ( var i = 0, iLen = options.length; i < iLen; i++ ) {
8383 + opt = options[i];
8384 +
8385 + if ( opt.selected ) {
8386 + result.push( opt.value );
8387 + }
8388 + }
8389 + return result;
8390 + }
8391 +
8392 + function triggerEvent( element, event ) {
8393 + var evt = document.createEvent( 'HTMLEvents' );
8394 + evt.initEvent( event, false, true );
8395 + element.dispatchEvent( evt );
8396 + }
8397 +
8398 + function postAjax( data, success ) {
8399 + var response, params,
8400 + xmlHttp = new XMLHttpRequest();
8401 +
8402 + params = typeof data === 'string' ? data : Object.keys( data ).map(
8403 + function( k ) {
8404 + return encodeURIComponent( k ) + '=' + encodeURIComponent( data[k]);
8405 + }
8406 + ).join( '&' );
8407 +
8408 + xmlHttp.open( 'post', ajaxurl, true );
8409 + xmlHttp.onreadystatechange = function() {
8410 + if ( xmlHttp.readyState > 3 && xmlHttp.status == 200 ) {
8411 + response = xmlHttp.responseText;
8412 + try {
8413 + response = JSON.parse( response );
8414 + } catch ( e ) {
8415 + // The response may not be JSON, so just return it.
8416 + }
8417 + success( response );
8418 + }
8419 + };
8420 + xmlHttp.setRequestHeader( 'X-Requested-With', 'XMLHttpRequest' );
8421 + xmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
8422 + xmlHttp.send( params );
8423 + return xmlHttp;
8424 + }
8425 +
8426 + function fadeOut( element, success ) {
8427 + element.classList.add( 'frm-fade' );
8428 + setTimeout( success, 1000 );
8429 + }
8430 +
8431 + function invisible( classes ) {
8432 + jQuery( classes ).css( 'visibility', 'hidden' );
8433 + }
8434 +
8435 + function visible( classes ) {
8436 + jQuery( classes ).css( 'visibility', 'visible' );
8437 + }
8438 +
8439 + function initModal( id, width ) {
8440 + var $info = jQuery( id );
8441 + if ( $info.length < 1 ) {
8442 + return false;
8443 + }
8444 +
8445 + if ( typeof width === 'undefined' ) {
8446 + width = '550px';
8447 + }
8448 +
8449 + $info.dialog({
8450 + dialogClass: 'frm-dialog',
8451 + modal: true,
8452 + autoOpen: false,
8453 + closeOnEscape: true,
8454 + width: width,
8455 + resizable: false,
8456 + draggable: false,
8457 + open: function() {
8458 + jQuery( '.ui-dialog-titlebar' ).addClass( 'frm_hidden' ).removeClass( 'ui-helper-clearfix' );
8459 + jQuery( '#wpwrap' ).addClass( 'frm_overlay' );
8460 + jQuery( '.frm-dialog' ).removeClass( 'ui-widget ui-widget-content ui-corner-all' );
8461 + $info.removeClass( 'ui-dialog-content ui-widget-content' );
8462 + bindClickForDialogClose( $info );
8463 + },
8464 + close: function() {
8465 + jQuery( '#wpwrap' ).removeClass( 'frm_overlay' );
8466 + jQuery( '.spinner' ).css( 'visibility', 'hidden' );
8467 +
8468 + this.removeAttribute( 'data-option-type' );
8469 + const optionType = document.getElementById( 'bulk-option-type' );
8470 + if ( optionType ) {
8471 + optionType.value = '';
8472 + }
8473 + }
8474 + });
8475 +
8476 + return $info;
8477 + }
8478 +
8479 + function toggle( cname, id ) {
8480 + if ( id === '#' ) {
8481 + var cont = document.getElementById( cname );
8482 + var hidden = cont.style.display;
8483 + if ( hidden === 'none' ) {
8484 + cont.style.display = 'block';
8485 + } else {
8486 + cont.style.display = 'none';
8487 + }
8488 + } else {
8489 + var vis = cname.is( ':visible' );
8490 + if ( vis ) {
8491 + cname.hide();
8492 + } else {
8493 + cname.show();
8494 + }
8495 + }
8496 + }
8497 +
8498 + function removeWPUnload() {
8499 + window.onbeforeunload = null;
8500 + var w = jQuery( window );
8501 + w.off( 'beforeunload.widgets' );
8502 + w.off( 'beforeunload.edit-post' );
8503 + }
8504 +
8505 + function maybeChangeEmbedFormMsg() {
8506 + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' );
8507 + var fieldItem = document.getElementById( 'frm_field_id_' + fieldId );
8508 + if ( null === fieldItem || 'form' !== fieldItem.dataset.type ) {
8509 + return;
8510 + }
8511 +
8512 + fieldItem = jQuery( fieldItem );
8513 +
8514 + if ( this.options[ this.selectedIndex ].value ) {
8515 + fieldItem.find( '.frm-not-set' )[0].classList.add( 'frm_hidden' );
8516 + var embedMsg = fieldItem.find( '.frm-embed-message' );
8517 + embedMsg.html( embedMsg.data( 'embedmsg' ) + this.options[ this.selectedIndex ].text );
8518 + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.remove( 'frm_hidden' );
8519 + } else {
8520 + fieldItem.find( '.frm-not-set' )[0].classList.remove( 'frm_hidden' );
8521 + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.add( 'frm_hidden' );
8522 + }
8523 + }
8524 +
8525 + function toggleProductType() {
8526 + var settings = jQuery( this ).closest( '.frm-single-settings' ),
8527 + container = settings.find( '.frmjs_product_choices' ),
8528 + heading = settings.find( '.frm_prod_options_heading' ),
8529 + currentVal = this.options[ this.selectedIndex ].value;
8530 +
8531 + container.removeClass( 'frm_prod_type_single frm_prod_type_user_def' );
8532 + heading.removeClass( 'frm_prod_user_def' );
8533 +
8534 + if ( 'single' === currentVal ) {
8535 + container.addClass( 'frm_prod_type_single' );
8536 + } else if ( 'user_def' === currentVal ) {
8537 + container.addClass( 'frm_prod_type_user_def' );
8538 + heading.addClass( 'frm_prod_user_def' );
8539 + }
8540 + }
8541 +
8542 + function isProductField( fieldId ) {
8543 + var field = document.getElementById( 'frm_field_id_' + fieldId );
8544 + if ( field === null ) {
8545 + return false;
8546 + } else {
8547 + return 'product' === field.getAttribute( 'data-type' );
8548 + }
8549 + }
8550 +
8551 + /**
8552 + * Serialize form data with vanilla JS.
8553 + */
8554 + function formToData( form ) {
8555 + var subKey, i,
8556 + object = {},
8557 + formData = form.elements;
8558 +
8559 + for ( i = 0; i < formData.length; i++ ) {
8560 + var input = formData[i],
8561 + key = input.name,
8562 + value = input.value,
8563 + names = key.match( /(.*)\[(.*)\]/ );
8564 +
8565 + if ( ( input.type === 'radio' || input.type === 'checkbox' ) && ! input.checked ) {
8566 + continue;
8567 + }
8568 +
8569 + if ( names !== null ) {
8570 + key = names[1];
8571 + subKey = names[2];
8572 + if ( ! Reflect.has( object, key ) ) {
8573 + object[key] = {};
8574 + }
8575 + object[key][subKey] = value;
8576 + continue;
8577 + }
8578 +
8579 + // Reflect.has in favor of: object.hasOwnProperty(key)
8580 + if ( ! Reflect.has( object, key ) ) {
8581 + object[key] = value;
8582 + continue;
8583 + }
8584 + if ( ! Array.isArray( object[key]) ) {
8585 + object[key] = [ object[key] ];
8586 + }
8587 + object[key].push( value );
8588 + }
8589 +
8590 + return object;
8591 + }
8592 +
8593 + /**
8594 + * Show, hide, and sort subfields of Name field on form builder.
8595 + *
8596 + * @since 4.11
8597 + */
8598 + function handleNameFieldOnFormBuilder() {
8599 + /**
8600 + * Gets subfield element from cache.
8601 + *
8602 + * @param {String} fieldId Field ID.
8603 + * @param {String} key Cache key.
8604 + * @returns {HTMLElement|undefined} Return the element from cache or undefined if not found.
8605 + */
8606 + const getSubFieldElFromCache = ( fieldId, key ) => {
8607 + window.frmCachedSubFields = window.frmCachedSubFields || {};
8608 + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {};
8609 + return window.frmCachedSubFields[fieldId][key];
8610 + };
8611 +
8612 + /**
8613 + * Sets subfield element to cache.
8614 + *
8615 + * @param {String} fieldId Field ID.
8616 + * @param {String} key Cache key.
8617 + * @param {HTMLElement} el Element.
8618 + */
8619 + const setSubFieldElToCache = ( fieldId, key, el ) => {
8620 + window.frmCachedSubFields = window.frmCachedSubFields || {};
8621 + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {};
8622 + window.frmCachedSubFields[fieldId][key] = el;
8623 + };
8624 +
8625 + /**
8626 + * Gets column class from the number of columns.
8627 + *
8628 + * @param {Number} colCount Number of columns.
8629 + * @returns {string}
8630 + */
8631 + const getColClass = colCount => 'frm' + parseInt( 12 / colCount );
8632 +
8633 + const colClasses = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ].map( num => 'frm' + num );
8634 +
8635 + const allSubFieldNames = [ 'first', 'middle', 'last' ];
8636 +
8637 + /**
8638 + * Handles name layout change.
8639 + *
8640 + * @param {Event} event Event object.
8641 + */
8642 + const onChangeLayout = event => {
8643 + const value = event.target.value;
8644 + const subFieldNames = value.split( '_' );
8645 + const fieldId = event.target.dataset.fieldId;
8646 +
8647 + /*
8648 + * Live update form on the form builder.
8649 + */
8650 + const container = document.querySelector( '#field_' + fieldId + '_inner_container .frm_combo_inputs_container' );
8651 + const newColClass = getColClass( subFieldNames.length );
8652 +
8653 + // Set all sub field elements to cache and hide all of them first.
8654 + allSubFieldNames.forEach( name => {
8655 + const subFieldEl = container.querySelector( '[data-sub-field-name="' + name + '"]' );
8656 + if ( subFieldEl ) {
8657 + subFieldEl.classList.add( 'frm_hidden' );
8658 + subFieldEl.classList.remove( ...colClasses );
8659 + setSubFieldElToCache( fieldId, name, subFieldEl );
8660 + }
8661 + });
8662 +
8663 + subFieldNames.forEach( subFieldName => {
8664 + const subFieldEl = getSubFieldElFromCache( fieldId, subFieldName );
8665 + if ( ! subFieldEl ) {
8666 + return;
8667 + }
8668 +
8669 + subFieldEl.classList.remove( 'frm_hidden' );
8670 + subFieldEl.classList.add( newColClass );
8671 +
8672 + container.append( subFieldEl );
8673 + });
8674 +
8675 + /*
8676 + * Live update subfield options.
8677 + */
8678 + // Hide all subfield options.
8679 + allSubFieldNames.forEach( name => {
8680 + const optionsEl = document.querySelector( '.frm_sub_field_options-' + name + '[data-field-id="' + fieldId + '"]' );
8681 + if ( optionsEl ) {
8682 + optionsEl.classList.add( 'frm_hidden' );
8683 + setSubFieldElToCache( fieldId, name + '_options', optionsEl );
8684 + }
8685 + });
8686 +
8687 + subFieldNames.forEach( subFieldName => {
8688 + const optionsEl = getSubFieldElFromCache( fieldId, subFieldName + '_options' );
8689 + if ( ! optionsEl ) {
8690 + return;
8691 + }
8692 + optionsEl.classList.remove( 'frm_hidden' );
8693 + });
8694 + };
8695 +
8696 + const dropdownSelector = '.frm_name_layout_dropdown';
8697 + document.addEventListener( 'change', event => {
8698 + if ( event.target.matches( dropdownSelector ) ) {
8699 + onChangeLayout( event );
8700 + }
8701 + }, false );
8702 + }
8703 +
8704 + function debounce( func, wait = 100 ) {
8705 + let timeout;
8706 + return function( ...args ) {
8707 + clearTimeout( timeout );
8708 + timeout = setTimeout(
8709 + () => func.apply( this, args ),
8710 + wait
8711 + );
8712 + };
8713 + }
8714 +
8715 + return {
8716 + init: function() {
8717 + s = {};
8718 +
8719 + // Bootstrap dropdown button
8720 + jQuery( '.wp-admin' ).on( 'click', function( e ) {
8721 + var t = jQuery( e.target );
8722 + var $openDrop = jQuery( '.dropdown.open' );
8723 + if ( $openDrop.length && ! t.hasClass( 'dropdown' ) && ! t.closest( '.dropdown' ).length ) {
8724 + $openDrop.removeClass( 'open' );
8725 + }
8726 + });
8727 + jQuery( '#frm_bs_dropdown:not(.open) a' ).on( 'click', focusSearchBox );
8728 +
8729 + if ( typeof thisFormId === 'undefined' ) {
8730 + thisFormId = jQuery( document.getElementById( 'form_id' ) ).val();
8731 + }
8732 +
8733 + frmAdminBuild.inboxBannerInit();
8734 +
8735 + if ( $newFields.length > 0 ) {
8736 + // only load this on the form builder page
8737 + frmAdminBuild.buildInit();
8738 + } else if ( document.getElementById( 'frm_notification_settings' ) !== null ) {
8739 + // only load on form settings page
8740 + frmAdminBuild.settingsInit();
8741 + } else if ( document.getElementById( 'frm_styling_form' ) !== null ) {
8742 + // load styling settings js
8743 + frmAdminBuild.styleInit();
8744 + } else if ( document.getElementById( 'frm_custom_css_box' ) !== null ) {
8745 + // load styling settings js
8746 + frmAdminBuild.customCSSInit();
8747 + } else if ( document.getElementById( 'form_global_settings' ) !== null ) {
8748 + // global settings page
8749 + frmAdminBuild.globalSettingsInit();
8750 + } else if ( document.getElementById( 'frm_export_xml' ) !== null ) {
8751 + // import/export page
8752 + frmAdminBuild.exportInit();
8753 + } else if ( document.getElementById( 'frm_dyncontent' ) !== null ) {
8754 + // only load on views settings page
8755 + frmAdminBuild.viewInit();
8756 + } else if ( document.getElementById( 'frm_inbox_page' ) !== null ) {
8757 + // Inbox page
8758 + frmAdminBuild.inboxInit();
8759 + } else if ( document.getElementById( 'frm-welcome' ) !== null ) {
8760 + // Solution install page
8761 + frmAdminBuild.solutionInit();
8762 + } else {
8763 + // New form selection page
8764 + initNewFormModal();
8765 + initSelectionAutocomplete();
8766 +
8767 + jQuery( '[data-frmprint]' ).on( 'click', function() {
8768 + window.print();
8769 + return false;
8770 + });
8771 + }
8772 +
8773 + var $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) );
8774 + if ( $advInfo.length > 0 || jQuery( '.frm_field_list' ).length > 0 ) {
8775 + // only load on the form, form settings, and view settings pages
8776 + frmAdminBuild.panelInit();
8777 + }
8778 +
8779 + loadTooltips();
8780 + initUpgradeModal();
8781 +
8782 + // used on build, form settings, and view settings
8783 + var $shortCodeDiv = jQuery( document.getElementById( 'frm_shortcodediv' ) );
8784 + if ( $shortCodeDiv.length > 0 ) {
8785 + jQuery( 'a.edit-frm_shortcode' ).on( 'click', function() {
8786 + if ( $shortCodeDiv.is( ':hidden' ) ) {
8787 + $shortCodeDiv.slideDown( 'fast' );
8788 + this.style.display = 'none';
8789 + }
8790 + return false;
8791 + });
8792 +
8793 + jQuery( '.cancel-frm_shortcode', '#frm_shortcodediv' ).on( 'click', function() {
8794 + $shortCodeDiv.slideUp( 'fast' );
8795 + $shortCodeDiv.siblings( 'a.edit-frm_shortcode' ).show();
8796 + return false;
8797 + });
8798 + }
8799 +
8800 + // tabs
8801 + jQuery( document ).on( 'click', '#frm-nav-tabs a', clickNewTab );
8802 + jQuery( '.post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a' ).on( 'click', function() {
8803 + if ( ! this.classList.contains( 'frm_noallow' ) ) {
8804 + clickTab( this );
8805 + return false;
8806 + }
8807 + });
8808 + clickTab( jQuery( '.starttab a' ), 'auto' );
8809 +
8810 + // submit the search form with dropdown
8811 + jQuery( '#frm-fid-search-menu a' ).on( 'click', function() {
8812 + var val = this.id.replace( 'fid-', '' );
8813 + jQuery( 'select[name="fid"]' ).val( val );
8814 + triggerSubmit( document.getElementById( 'posts-filter' ) );
8815 + return false;
8816 + });
8817 +
8818 + jQuery( '.frm_select_box' ).on( 'click focus', function() {
8819 + this.select();
8820 + });
8821 +
8822 + jQuery( document ).on( 'input search change', '.frm-auto-search', searchContent );
8823 + jQuery( document ).on( 'focusin click', '.frm-auto-search', stopPropagation );
8824 + var autoSearch = jQuery( '.frm-auto-search' );
8825 + if ( autoSearch.val() !== '' ) {
8826 + autoSearch.trigger( 'keyup' );
8827 + }
8828 +
8829 + // Initialize Formidable Connection.
8830 + FrmFormsConnect.init();
8831 +
8832 + jQuery( document ).on( 'click', '.frm-install-addon', installAddon );
8833 + jQuery( document ).on( 'click', '.frm-activate-addon', activateAddon );
8834 + jQuery( document ).on( 'click', '.frm-solution-multiple', installMultipleAddons );
8835 +
8836 + // prevent annoying confirmation message from WordPress
8837 + jQuery( 'button, input[type=submit]' ).on( 'click', removeWPUnload );
8838 + },
8839 +
8840 + buildInit: function() {
8841 + var loadFieldId, $builderForm, builderArea;
8842 +
8843 + if ( jQuery( '.frm_field_loading' ).length ) {
8844 + loadFieldId = jQuery( '.frm_field_loading' ).first().attr( 'id' );
8845 + loadFields( loadFieldId );
8846 + }
8847 +
8848 + setupSortable( 'ul.frm_sorting' );
8849 +
8850 + jQuery( '.field_type_list > li:not(.frm_noallow)' ).draggable({
8851 + connectToSortable: '#frm-show-fields',
8852 + helper: 'clone',
8853 + revert: 'invalid',
8854 + delay: 10,
8855 + cancel: '.frm-dropdown-menu'
8856 + });
8857 + 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();
8858 +
8859 + jQuery( '.frm_submit_ajax' ).on( 'click', submitBuild );
8860 + jQuery( '.frm_submit_no_ajax' ).on( 'click', submitNoAjax );
8861 +
8862 + jQuery( 'a.edit-form-status' ).on( 'click', slideDown );
8863 + jQuery( '.cancel-form-status' ).on( 'click', slideUp );
8864 + jQuery( '.save-form-status' ).on( 'click', function() {
8865 + var newStatus = jQuery( document.getElementById( 'form_change_status' ) ).val();
8866 + jQuery( 'input[name="new_status"]' ).val( newStatus );
8867 + jQuery( document.getElementById( 'form-status-display' ) ).html( newStatus );
8868 + jQuery( '.cancel-form-status' ).trigger( 'click' );
8869 + return false;
8870 + });
8871 +
8872 + jQuery( '.frm_form_builder form' ).first().on( 'submit', function() {
8873 + jQuery( '.inplace_field' ).trigger( 'blur' );
8874 + });
8875 +
8876 + initiateMultiselect();
8877 + renumberPageBreaks();
8878 +
8879 + $builderForm = jQuery( builderForm );
8880 + builderArea = document.getElementById( 'frm_form_editor_container' );
8881 + $builderForm.on( 'click', '.frm_add_logic_row', addFieldLogicRow );
8882 + $builderForm.on( 'click', '.frm_add_watch_lookup_row', addWatchLookupRow );
8883 + $builderForm.on( 'change', '.frm_get_values_form', updateGetValueFieldSelection );
8884 + $builderForm.on( 'change', '.frm_logic_field_opts', getFieldValues );
8885 + $builderForm.on( 'change', '.scale_maxnum, .scale_minnum', setScaleValues );
8886 + $builderForm.on( 'change', '.radio_maxnum', setStarValues );
8887 + $builderForm.on( 'frm-multiselect-changed', 'select[name^="field_options[admin_only_"]', adjustVisibilityValuesForEveryoneValues );
8888 +
8889 + jQuery( document.getElementById( 'frm-insert-fields' ) ).on( 'click', '.frm_add_field', addFieldClick );
8890 + $newFields.on( 'click', '.frm_clone_field', duplicateField );
8891 + $builderForm.on( 'blur', 'input[id^="frm_calc"]', checkCalculationCreatedByUser );
8892 + $builderForm.on( 'change', 'input.frm_format_opt', toggleInvalidMsg );
8893 + $builderForm.on( 'change click', '[data-changeme]', liveChanges );
8894 + $builderForm.on( 'click', 'input.frm_req_field', markRequired );
8895 + $builderForm.on( 'click', '.frm_mark_unique', markUnique );
8896 +
8897 + $builderForm.on( 'change', '.frm_repeat_format', toggleRepeatButtons );
8898 + $builderForm.on( 'change', '.frm_repeat_limit', checkRepeatLimit );
8899 + $builderForm.on( 'change', '.frm_js_checkbox_limit', checkCheckboxSelectionsLimit );
8900 + $builderForm.on( 'input', 'input[name^="field_options[add_label_"]', function() {
8901 + updateRepeatText( this, 'add' );
8902 + });
8903 + $builderForm.on( 'input', 'input[name^="field_options[remove_label_"]', function() {
8904 + updateRepeatText( this, 'remove' );
8905 + });
8906 + $builderForm.on( 'change', 'select[name^="field_options[data_type_"]', maybeClearWatchFields );
8907 + jQuery( builderArea ).on( 'click', '.frm-collapse-page', maybeCollapsePage );
8908 + jQuery( builderArea ).on( 'click', '.frm-collapse-section', maybeCollapseSection );
8909 + $builderForm.on( 'click', '.frm-single-settings h3', maybeCollapseSettings );
8910 +
8911 + $builderForm.on( 'click', '.frm_toggle_sep_values', toggleSepValues );
8912 + $builderForm.on( 'click', '.frm_toggle_image_options', toggleImageOptions );
8913 + $builderForm.on( 'click', '.frm_remove_image_option', removeImageFromOption );
8914 + $builderForm.on( 'click', '.frm_choose_image_box', addImageToOption );
8915 + $builderForm.on( 'change', '.frm_hide_image_text', refreshOptionDisplay );
8916 + $builderForm.on( 'change', '.frm_field_options_image_size', setImageSize );
8917 + $builderForm.on( 'click', '.frm_multiselect_opt', toggleMultiselect );
8918 + $newFields.on( 'mousedown', 'input, textarea, select', stopFieldFocus );
8919 + $newFields.on( 'click', 'input[type=radio], input[type=checkbox]', stopFieldFocus );
8920 + $newFields.on( 'click', '.frm_delete_field', clickDeleteField );
8921 + $newFields.on( 'click', '.frm_select_field', clickSelectField );
8922 + jQuery( document ).on( 'click', '.frm_delete_field_group', clickDeleteFieldGroup );
8923 + jQuery( document ).on( 'click', '.frm_clone_field_group', duplicateFieldGroup );
8924 + jQuery( document ).on( 'click', '#frm_field_group_controls > span:first-child', clickFieldGroupLayout );
8925 + jQuery( document ).on( 'click', '.frm-row-layout-option', handleFieldGroupLayoutOptionClick );
8926 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-row-layout-option', handleFieldGroupLayoutOptionInsideMergeClick );
8927 + jQuery( document ).on( 'click', '.frm-custom-field-group-layout', customFieldGroupLayoutClick );
8928 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-custom-field-group-layout', customFieldGroupLayoutInsideMergeClick );
8929 + jQuery( document ).on( 'click', '.frm-break-field-group', breakFieldGroupClick );
8930 + $newFields.on( 'click', '#frm_field_group_popup .frm_grid_container input', focusFieldGroupInputOnClick );
8931 + jQuery( document ).on( 'click', '.frm-cancel-custom-field-group-layout', cancelCustomFieldGroupClick );
8932 + jQuery( document ).on( 'click', '.frm-save-custom-field-group-layout', saveCustomFieldGroupClick );
8933 + $newFields.on( 'click', 'ul.frm_sorting', fieldGroupClick );
8934 + jQuery( document ).on( 'click', '.frm-merge-fields-into-row', mergeFieldsIntoRowClick );
8935 + jQuery( document ).on( 'click', '.frm-delete-field-groups', deleteFieldGroupsClick );
8936 + $newFields.on( 'click', '.frm-field-action-icons [data-toggle="dropdown"]', function() {
8937 + this.closest( 'li.form-field' ).classList.add( 'frm-field-settings-open' );
8938 + jQuery( document ).on( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings );
8939 + });
8940 + $newFields.on( 'mousemove', 'ul.frm_sorting', checkForMultiselectKeysOnMouseMove );
8941 + $newFields.on( 'show.bs.dropdown', '.frm-field-action-icons', onFieldActionDropdownShow );
8942 + jQuery( document ).on( 'show.bs.dropdown', '#frm_field_group_controls', onFieldGroupActionDropdownShow );
8943 + $builderForm.on( 'click', '.frm_single_option a[data-removeid]', deleteFieldOption );
8944 + $builderForm.on( 'mousedown', '.frm_single_option input[type=radio]', maybeUncheckRadio );
8945 + $builderForm.on( 'focusin', '.frm_single_option input[type=text]', maybeClearOptText );
8946 + $builderForm.on( 'click', '.frm_add_opt', addFieldOption );
8947 + $builderForm.on( 'change', '.frm_single_option input', resetOptOnChange );
8948 + $builderForm.on( 'change', '.frm_image_id', resetOptOnChange );
8949 + $builderForm.on( 'change', '.frm_toggle_mult_sel', toggleMultSel );
8950 + $builderForm.on( 'focusin', '.frm_classes', showBuilderModal );
8951 +
8952 + $newFields.on( 'click', '.frm_primary_label', clickLabel );
8953 + $newFields.on( 'click', '.frm_description', clickDescription );
8954 + $newFields.on( 'click', 'li.ui-state-default', clickVis );
8955 + $newFields.on( 'dblclick', 'li.ui-state-default', openAdvanced );
8956 + $builderForm.on( 'change', '.frm_tax_form_select', toggleFormTax );
8957 + $builderForm.on( 'change', 'select.conf_field', addConf );
8958 +
8959 + $builderForm.on( 'change', '.frm_get_field_selection', getFieldSelection );
8960 +
8961 + $builderForm.on( 'click', '.frm-show-inline-modal', maybeShowInlineModal );
8962 +
8963 + $builderForm.on( 'click', '.frm-inline-modal .dismiss', dismissInlineModal );
8964 + jQuery( document ).on( 'change', '[data-frmchange]', changeInputtedValue );
8965 +
8966 + $builderForm.on( 'change', '.frm_include_extras_field', rePopCalcFieldsForSummary );
8967 + $builderForm.on( 'change', 'select[name^="field_options[form_select_"]', maybeChangeEmbedFormMsg );
8968 +
8969 + jQuery( document ).on( 'submit', '#frm_js_build_form', buildSubmittedNoAjax );
8970 + 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 );
8971 +
8972 + popAllProductFields();
8973 +
8974 + jQuery( document ).on( 'change', '.frmjs_prod_data_type_opt', toggleProductType );
8975 +
8976 + jQuery( document ).on( 'focus', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextFocus );
8977 + jQuery( document ).on( 'blur', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextBlur );
8978 +
8979 + initBulkOptionsOverlay();
8980 + hideEmptyEle();
8981 + maybeDisableAddSummaryBtn();
8982 + maybeHideQuantityProductFieldOption();
8983 + handleNameFieldOnFormBuilder();
8984 + toggleSectionHolder();
8985 + },
8986 +
8987 + settingsInit: function() {
8988 + var formSettings, $loggedIn, $cookieExp, $editable,
8989 + $formActions = jQuery( document.getElementById( 'frm_notification_settings' ) );
8990 + //BCC, CC, and Reply To button functionality
8991 + $formActions.on( 'click', '.frm_email_buttons', showEmailRow );
8992 + $formActions.on( 'click', '.frm_remove_field', hideEmailRow );
8993 + $formActions.on( 'change', '.frm_to_row, .frm_from_row', showEmailWarning );
8994 + $formActions.on( 'change', '.frm_tax_selector', changePosttaxRow );
8995 + $formActions.on( 'change', 'select.frm_single_post_field', checkDupPost );
8996 + $formActions.on( 'change', 'select.frm_toggle_post_content', togglePostContent );
8997 + $formActions.on( 'change', 'select.frm_dyncontent_opt', fillDyncontent );
8998 + $formActions.on( 'change', '.frm_post_type', switchPostType );
8999 + $formActions.on( 'click', '.frm_add_postmeta_row', addPostmetaRow );
9000 + $formActions.on( 'click', '.frm_add_posttax_row', addPosttaxRow );
9001 + $formActions.on( 'click', '.frm_toggle_cf_opts', toggleCfOpts );
9002 + $formActions.on( 'click', '.frm_duplicate_form_action', copyFormAction );
9003 + jQuery( 'select[data-toggleclass], input[data-toggleclass]' ).on( 'change', toggleFormOpts );
9004 + jQuery( '.frm_actions_list' ).on( 'click', '.frm_active_action', addFormAction );
9005 + jQuery( '#frm-show-groups, #frm-hide-groups' ).on( 'click', toggleActionGroups );
9006 + initiateMultiselect();
9007 +
9008 + //set actions icons to inactive
9009 + jQuery( 'ul.frm_actions_list li' ).each( function() {
9010 + checkActiveAction( jQuery( this ).children( 'a' ).data( 'actiontype' ) );
9011 +
9012 + // If the icon is a background image, don't add BG color.
9013 + var icon = jQuery( this ).find( 'i' );
9014 + if ( icon.css( 'background-image' ) !== 'none' ) {
9015 + icon.addClass( 'frm-inverse' );
9016 + }
9017 + });
9018 +
9019 + jQuery( '.frm_submit_settings_btn' ).on( 'click', submitSettings );
9020 +
9021 + formSettings = jQuery( '.frm_form_settings' );
9022 + formSettings.on( 'click', '.frm_add_form_logic', addFormLogicRow );
9023 + formSettings.on( 'blur', '.frm_email_blur', formatEmailSetting );
9024 + formSettings.on( 'click', '.frm_already_used', onlyOneActionMessage );
9025 +
9026 + formSettings.on( 'change', '#logic_link_submit', toggleSubmitLogic );
9027 + formSettings.on( 'click', '.frm_add_submit_logic', addSubmitLogic );
9028 + formSettings.on( 'change', '.frm_submit_logic_field_opts', addSubmitLogicOpts );
9029 +
9030 + // Close shortcode modal on click.
9031 + formSettings.on( 'mouseup', '*:not(.frm-show-box)', function( e ) {
9032 + e.stopPropagation();
9033 + if ( e.target.classList.contains( 'frm-show-box' ) ) {
9034 + return;
9035 + }
9036 + var sidebar = document.getElementById( 'frm_adv_info' ),
9037 + isChild = jQuery( e.target ).closest( '#frm_adv_info' ).length > 0;
9038 +
9039 + if ( sidebar.getAttribute( 'data-fills' ) === e.target.id && typeof e.target.id !== 'undefined' ) {
9040 + return;
9041 + }
9042 +
9043 + if ( sidebar !== null && ! isChild && sidebar.display !== 'none' ) {
9044 + hideShortcodes( sidebar );
9045 + }
9046 + });
9047 +
9048 + //Warning when user selects "Do not store entries ..."
9049 + jQuery( document.getElementById( 'no_save' ) ).on( 'change', function() {
9050 + if ( this.checked ) {
9051 + if ( confirm( frm_admin_js.no_save_warning ) !== true ) {
9052 + // Uncheck box if user hits "Cancel"
9053 + jQuery( this ).attr( 'checked', false );
9054 + }
9055 + }
9056 + });
9057 +
9058 + //Show/hide Messages header
9059 + jQuery( '#editable, #edit_action, #save_draft, #success_action' ).on( 'change', function() {
9060 + maybeShowFormMessages();
9061 + });
9062 + jQuery( 'select[name="options[success_action]"], select[name="options[edit_action]"]' ).on( 'change', showSuccessOpt );
9063 +
9064 + $loggedIn = document.getElementById( 'logged_in' );
9065 + jQuery( $loggedIn ).on( 'change', function() {
9066 + if ( this.checked ) {
9067 + visible( '.hide_logged_in' );
9068 + } else {
9069 + invisible( '.hide_logged_in' );
9070 + }
9071 + });
9072 +
9073 + $cookieExp = jQuery( document.getElementById( 'frm_cookie_expiration' ) );
9074 + jQuery( document.getElementById( 'frm_single_entry_type' ) ).on( 'change', function() {
9075 + if ( this.value === 'cookie' ) {
9076 + $cookieExp.fadeIn( 'slow' );
9077 + } else {
9078 + $cookieExp.fadeOut( 'slow' );
9079 + }
9080 + });
9081 +
9082 + var $singleEntry = document.getElementById( 'single_entry' );
9083 + jQuery( $singleEntry ).on( 'change', function() {
9084 + if ( this.checked ) {
9085 + visible( '.hide_single_entry' );
9086 + } else {
9087 + invisible( '.hide_single_entry' );
9088 + }
9089 +
9090 + if ( this.checked && jQuery( document.getElementById( 'frm_single_entry_type' ) ).val() === 'cookie' ) {
9091 + $cookieExp.fadeIn( 'slow' );
9092 + } else {
9093 + $cookieExp.fadeOut( 'slow' );
9094 + }
9095 + });
9096 +
9097 + jQuery( '.hide_save_draft' ).hide();
9098 +
9099 + var $saveDraft = jQuery( document.getElementById( 'save_draft' ) );
9100 + $saveDraft.on( 'change', function() {
9101 + if ( this.checked ) {
9102 + jQuery( '.hide_save_draft' ).fadeIn( 'slow' );
9103 + } else {
9104 + jQuery( '.hide_save_draft' ).fadeOut( 'slow' );
9105 + }
9106 + });
9107 + triggerChange( $saveDraft );
9108 +
9109 + //If Allow editing is checked/unchecked
9110 + $editable = document.getElementById( 'editable' );
9111 + jQuery( $editable ).on( 'change', function() {
9112 + if ( this.checked ) {
9113 + jQuery( '.hide_editable' ).fadeIn( 'slow' );
9114 + triggerChange( document.getElementById( 'edit_action' ) );
9115 + } else {
9116 + jQuery( '.hide_editable' ).fadeOut( 'slow' );
9117 + jQuery( '.edit_action_message_box' ).fadeOut( 'slow' );//Hide On Update message box
9118 + }
9119 + });
9120 +
9121 + //If File Protection is checked/unchecked
9122 + jQuery( document ).on( 'change', '#protect_files', function() {
9123 + if ( this.checked ) {
9124 + jQuery( '.hide_protect_files' ).fadeIn( 'slow' );
9125 + } else {
9126 + jQuery( '.hide_protect_files' ).fadeOut( 'slow' );
9127 + }
9128 + });
9129 +
9130 + jQuery( document ).on( 'frm-multiselect-changed', '#protect_files_role', adjustVisibilityValuesForEveryoneValues );
9131 +
9132 + jQuery( document ).on( 'submit', '.frm_form_settings', settingsSubmitted );
9133 + jQuery( document ).on( 'change', '#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea', fieldUpdated );
9134 + jQuery( document ).on( 'click', '#frm_save_and_reload_settings', saveAndReloadSettings );
9135 +
9136 + // Page Selection Autocomplete
9137 + initSelectionAutocomplete();
9138 + },
9139 +
9140 + panelInit: function() {
9141 + var customPanel, settingsPage, viewPage, insertFieldsTab;
9142 +
9143 + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'click', '.frm_insert_code', insertCode );
9144 + jQuery( document ).on( 'change', '.frm_insert_val', function() {
9145 + insertFieldCode( jQuery( this ).data( 'target' ), jQuery( this ).val() );
9146 + jQuery( this ).val( '' );
9147 + });
9148 +
9149 + jQuery( document ).on( 'click change', '#frm-id-key-condition', resetLogicBuilder );
9150 + jQuery( document ).on( 'keyup change', '.frm-build-logic', setLogicExample );
9151 +
9152 + showInputIcon();
9153 + jQuery( document ).on( 'frmElementAdded', function( event, parentEle ) {
9154 + /* This is here for add-ons to trigger */
9155 + showInputIcon( parentEle );
9156 + });
9157 + jQuery( document ).on( 'mousedown', '.frm-show-box', showShortcodes );
9158 +
9159 + settingsPage = document.getElementById( 'form_settings_page' );
9160 + viewPage = document.body.classList.contains( 'post-type-frm_display' );
9161 + insertFieldsTab = document.getElementById( 'frm_insert_fields_tab' );
9162 +
9163 + if ( settingsPage !== null || viewPage ) {
9164 + jQuery( document ).on( 'focusin', 'form input, form textarea', function( e ) {
9165 + var htmlTab;
9166 + e.stopPropagation();
9167 + maybeShowModal( this );
9168 +
9169 + if ( jQuery( this ).is( ':not(:submit, input[type=button], .frm-search-input, input[type=checkbox])' ) ) {
9170 + if ( jQuery( e.target ).closest( '#frm_adv_info' ).length ) {
9171 + // Don't trigger for fields inside of the modal.
9172 + return;
9173 + }
9174 +
9175 + if ( settingsPage !== null ) {
9176 + /* form settings page */
9177 + htmlTab = jQuery( '#frm_html_tab' );
9178 + if ( jQuery( this ).closest( '#html_settings' ).length > 0 ) {
9179 + htmlTab.show();
9180 + htmlTab.siblings().hide();
9181 + jQuery( '#frm_html_tab a' ).trigger( 'click' );
9182 + toggleAllowedHTML( this, e.type );
9183 + } else {
9184 + showElement( jQuery( '.frm-category-tabs li' ) );
9185 + insertFieldsTab.click();
9186 + htmlTab.hide();
9187 + htmlTab.siblings().show();
9188 + }
9189 + } else if ( viewPage ) {
9190 + // Run on view page.
9191 + toggleAllowedShortcodes( this.id, e.type );
9192 + }
9193 + }
9194 + });
9195 + }
9196 +
9197 + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'mousedown', '#frm_adv_info a, .frm_field_list a', function( e ) {
9198 + e.preventDefault();
9199 + });
9200 +
9201 + customPanel = jQuery( '#frm_adv_info' );
9202 + customPanel.on( 'click', '.subsubsub a.frmids', function( e ) {
9203 + toggleKeyID( 'frmids', e );
9204 + });
9205 + customPanel.on( 'click', '.subsubsub a.frmkeys', function( e ) {
9206 + toggleKeyID( 'frmkeys', e );
9207 + });
9208 + },
9209 +
9210 + viewInit: function() {
9211 + var $addRemove,
9212 + $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) );
9213 + $advInfo.before( '<div id="frm_position_ele"></div>' );
9214 + setupMenuOffset();
9215 +
9216 + jQuery( document ).on( 'blur', '#param', checkDetailPageSlug );
9217 + jQuery( document ).on( 'blur', 'input[name^="options[where_val]"]', checkFilterParamNames );
9218 +
9219 + // Show loading indicator.
9220 + jQuery( '#publish' ).on( 'mousedown', function() {
9221 + fieldsUpdated = 0;
9222 + this.classList.add( 'frm_loading_button' );
9223 + });
9224 +
9225 + // move content tabs
9226 + jQuery( '#frm_dyncontent .handlediv' ).before( jQuery( '#frm_dyncontent .nav-menus-php' ) );
9227 +
9228 + // click content tabs
9229 + jQuery( '.nav-tab-wrapper a' ).on( 'click', clickContentTab );
9230 +
9231 + // click tabs after panel is replaced with ajax
9232 + jQuery( '#side-sortables' ).on( 'click', '.frm_doing_ajax.categorydiv .category-tabs a', clickTabsAfterAjax );
9233 +
9234 + initToggleShortcodes();
9235 + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' );
9236 +
9237 + jQuery( 'input[name="show_count"]' ).on( 'change', showCount );
9238 +
9239 + jQuery( document.getElementById( 'form_id' ) ).on( 'change', displayFormSelected );
9240 +
9241 + $addRemove = jQuery( '.frm_repeat_rows' );
9242 + $addRemove.on( 'click', '.frm_add_order_row', addOrderRow );
9243 + $addRemove.on( 'click', '.frm_add_where_row', addWhereRow );
9244 + $addRemove.on( 'change', '.frm_insert_where_options', insertWhereOptions );
9245 + $addRemove.on( 'change', '.frm_where_is_options', hideWhereOptions );
9246 +
9247 + setDefaultPostStatus();
9248 + },
9249 +
9250 + inboxInit: function() {
9251 + jQuery( '.frm_inbox_dismiss, footer .frm-button-secondary, footer .frm-button-primary' ).on( 'click', function( e ) {
9252 + var message = this.parentNode.parentNode,
9253 + key = message.getAttribute( 'data-message' ),
9254 + href = this.getAttribute( 'href' );
9255 +
9256 + if ( 'free_templates' === key && ! this.classList.contains( 'frm_inbox_dismiss' ) ) {
9257 + return;
9258 + }
9259 +
9260 + e.preventDefault();
9261 +
9262 + data = {
9263 + action: 'frm_inbox_dismiss',
9264 + key: key,
9265 + nonce: frmGlobal.nonce
9266 + };
9267 + postAjax( data, function() {
9268 + if ( href !== '#' ) {
9269 + window.location = href;
9270 + return true;
9271 + }
9272 + fadeOut( message, function() {
9273 + message.parentNode.removeChild( message );
9274 + });
9275 + });
9276 + });
9277 + jQuery( '#frm-dismiss-inbox' ).on( 'click', function( e ) {
9278 + data = {
9279 + action: 'frm_inbox_dismiss',
9280 + key: 'all',
9281 + nonce: frmGlobal.nonce
9282 + };
9283 + postAjax( data, function() {
9284 + fadeOut( document.getElementById( 'frm_message_list' ), function() {
9285 + document.getElementById( 'frm_empty_inbox' ).classList.remove( 'frm_hidden' );
9286 + });
9287 + });
9288 + });
9289 + },
9290 +
9291 + solutionInit: function() {
9292 + jQuery( document ).on( 'submit', '#frm-new-template', installTemplate );
9293 + },
9294 +
9295 + styleInit: function() {
9296 + collapseAllSections();
9297 +
9298 + document.getElementById( 'frm_field_height' ).addEventListener( 'change', textSquishCheck );
9299 + document.getElementById( 'frm_field_font_size' ).addEventListener( 'change', textSquishCheck );
9300 + document.getElementById( 'frm_field_pad' ).addEventListener( 'change', textSquishCheck );
9301 +
9302 + jQuery( 'input.hex' ).wpColorPicker({
9303 + change: function( event ) {
9304 + var hexcolor = jQuery( this ).wpColorPicker( 'color' );
9305 + jQuery( event.target ).val( hexcolor ).trigger( 'change' );
9306 + }
9307 + });
9308 + jQuery( '.wp-color-result-text' ).text( function( i, oldText ) {
9309 + return oldText === 'Select Color' ? 'Select' : oldText;
9310 + });
9311 +
9312 + function changeStyling() {
9313 + 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();
9314 + locStr = JSON.stringify( locStr );
9315 + jQuery.ajax({
9316 + type: 'POST', url: ajaxurl,
9317 + data: {
9318 + action: 'frm_change_styling',
9319 + nonce: frmGlobal.nonce,
9320 + frm_style_setting: locStr
9321 + },
9322 + success: function( css ) {
9323 + document.getElementById( 'this_css' ).innerHTML = css;
9324 + }
9325 + });
9326 + }
9327 +
9328 + // update styling on change
9329 + jQuery( '#frm_styling_form .styling_settings' ).on( 'change', debounce( changeStyling, 100 ) );
9330 +
9331 + // menu tabs
9332 + jQuery( '#menu-settings-column' ).on( 'click', function( e ) {
9333 + var panelId, wrapper,
9334 + target = jQuery( e.target );
9335 +
9336 + if ( e.target.className.indexOf( 'nav-tab-link' ) !== -1 ) {
9337 +
9338 + panelId = target.data( 'type' );
9339 +
9340 + wrapper = target.parents( '.accordion-section-content' ).first();
9341 +
9342 +
9343 + jQuery( '.tabs-panel-active', wrapper ).removeClass( 'tabs-panel-active' ).addClass( 'tabs-panel-inactive' );
9344 + jQuery( '#' + panelId, wrapper ).removeClass( 'tabs-panel-inactive' ).addClass( 'tabs-panel-active' );
9345 +
9346 + jQuery( '.tabs', wrapper ).removeClass( 'tabs' );
9347 + target.parent().addClass( 'tabs' );
9348 +
9349 + // select the search bar
9350 + jQuery( '.quick-search', wrapper ).trigger( 'focus' );
9351 +
9352 + e.preventDefault();
9353 + }
9354 + });
9355 +
9356 + jQuery( '.multiselect-container.frm-dropdown-menu li a' ).on( 'click', function() {
9357 + var radio = this.children[0].children[0];
9358 + var btnGrp = jQuery( this ).closest( '.btn-group' );
9359 + var btnId = btnGrp.attr( 'id' );
9360 + document.getElementById( btnId.replace( '_select', '' ) ).value = radio.value;
9361 + btnGrp.children( 'button' ).html( radio.nextElementSibling.innerHTML + ' <b class="caret"></b>' );
9362 +
9363 + // set active class
9364 + btnGrp.find( 'li.active' ).removeClass( 'active' );
9365 + jQuery( this ).closest( 'li' ).addClass( 'active' );
9366 + });
9367 +
9368 + jQuery( '#frm_confirm_modal' ).on( 'click', '[data-resetstyle]', function( e ) {
9369 + var button = document.getElementById( 'frm_reset_style' );
9370 +
9371 + button.classList.add( 'frm_loading_button' );
9372 + e.stopPropagation();
9373 +
9374 + jQuery.ajax({
9375 + type: 'POST', url: ajaxurl,
9376 + data: {action: 'frm_settings_reset', nonce: frmGlobal.nonce},
9377 + success: function( errObj ) {
9378 + var key;
9379 + errObj = errObj.replace( /^\s+|\s+$/g, '' );
9380 + if ( errObj.indexOf( '{' ) === 0 ) {
9381 + errObj = JSON.parse( errObj );
9382 + }
9383 + for ( key in errObj ) {
9384 + jQuery( 'input[name$="[' + key + ']"], select[name$="[' + key + ']"]' ).val( errObj[key]);
9385 + }
9386 + jQuery( '#frm_submit_style, #frm_auto_width' ).prop( 'checked', false );
9387 + triggerChange( document.getElementById( 'frm_fieldset' ) );
9388 + button.classList.remove( 'frm_loading_button' );
9389 + }
9390 + });
9391 + });
9392 +
9393 + jQuery( '.frm_pro_form #datepicker_sample' ).datepicker({ changeMonth: true, changeYear: true });
9394 +
9395 + jQuery( document.getElementById( 'frm_position' ) ).on( 'change', setPosClass );
9396 +
9397 + jQuery( 'select[name$="[theme_selector]"]' ).on( 'change', function() {
9398 + var themeVal = jQuery( this ).val();
9399 + var css = themeVal;
9400 + if ( themeVal !== -1 ) {
9401 + if ( themeVal === 'ui-lightness' && frm_admin_js.pro_url !== '' ) {
9402 + css = frm_admin_js.pro_url + '/css/ui-lightness/jquery-ui.css';
9403 + jQuery( '.frm_date_color' ).show();
9404 + } else {
9405 + css = frm_admin_js.jquery_ui_url + '/themes/' + themeVal + '/jquery-ui.css';
9406 + jQuery( '.frm_date_color' ).hide();
9407 + }
9408 + }
9409 +
9410 + updateUICSS( css );
9411 + document.getElementById( 'frm_theme_css' ).value = themeVal;
9412 + return false;
9413 + }).trigger( 'change' );
9414 + },
9415 +
9416 + customCSSInit: function() {
9417 + /* deprecated since WP 4.9 */
9418 + var customCSS = document.getElementById( 'frm_custom_css_box' );
9419 + if ( customCSS !== null ) {
9420 + CodeMirror.fromTextArea( customCSS, {
9421 + lineNumbers: true
9422 + });
9423 + }
9424 + },
9425 +
9426 + globalSettingsInit: function() {
9427 + var licenseTab;
9428 +
9429 + jQuery( document ).on( 'click', '[data-frmuninstall]', uninstallNow );
9430 +
9431 + initiateMultiselect();
9432 +
9433 + // activate addon licenses
9434 + licenseTab = document.getElementById( 'licenses_settings' );
9435 + if ( licenseTab !== null ) {
9436 + jQuery( licenseTab ).on( 'click', '.edd_frm_save_license', saveAddonLicense );
9437 + }
9438 +
9439 + // Solution install page
9440 + jQuery( document ).on( 'click', '#frm-new-template button', installTemplateFieldset );
9441 +
9442 + jQuery( '#frm-dismissable-cta .dismiss' ).on( 'click', function( event ) {
9443 + event.preventDefault();
9444 + jQuery.post( ajaxurl, {
9445 + action: 'frm_lite_settings_upgrade'
9446 + });
9447 + jQuery( '.settings-lite-cta' ).remove();
9448 + });
9449 + },
9450 +
9451 + exportInit: function() {
9452 + jQuery( '.frm_form_importer' ).on( 'submit', startFormMigration );
9453 + jQuery( document.getElementById( 'frm_export_xml' ) ).on( 'submit', validateExport );
9454 + jQuery( '#frm_export_xml input, #frm_export_xml select' ).on( 'change', removeExportError );
9455 + jQuery( 'input[name="frm_import_file"]' ).on( 'change', checkCSVExtension );
9456 + jQuery( 'select[name="format"]' ).on( 'change', checkExportTypes ).trigger( 'change' );
9457 + jQuery( 'input[name="frm_export_forms[]"]' ).on( 'click', preventMultipleExport );
9458 + initiateMultiselect();
9459 +
9460 + jQuery( '.frm-feature-banner .dismiss' ).on( 'click', function( event ) {
9461 + event.preventDefault();
9462 + jQuery.post( ajaxurl, {
9463 + action: 'frm_dismiss_migrator',
9464 + plugin: this.id,
9465 + nonce: frmGlobal.nonce
9466 + });
9467 + this.parentElement.remove();
9468 + });
9469 + },
9470 +
9471 + inboxBannerInit: function() {
9472 + const banner = document.getElementById( 'frm_banner' );
9473 + if ( ! banner ) {
9474 + return;
9475 + }
9476 +
9477 + const dismissButton = banner.querySelector( '.frm-banner-dismiss' );
9478 + document.addEventListener(
9479 + 'click',
9480 + function( event ) {
9481 + if ( event.target !== dismissButton ) {
9482 + return;
9483 + }
9484 +
9485 + const data = {
9486 + action: 'frm_inbox_dismiss',
9487 + key: banner.dataset.key,
9488 + nonce: frmGlobal.nonce
9489 + };
9490 + postAjax(
9491 + data,
9492 + function() {
9493 + jQuery( banner ).fadeOut(
9494 + 400,
9495 + function() {
9496 + banner.remove();
9497 + }
9498 + );
9499 + }
9500 + );
9501 + }
9502 + );
9503 + },
9504 +
9505 + updateOpts: function( fieldId, opts, modal ) {
9506 + var separate = usingSeparateValues( fieldId ),
9507 + action = isProductField( fieldId ) ? 'frm_bulk_products' : 'frm_import_options';
9508 + jQuery.ajax({
9509 + type: 'POST',
9510 + url: ajaxurl,
9511 + data: {
9512 + action: action,
9513 + field_id: fieldId,
9514 + opts: opts,
9515 + separate: separate,
9516 + nonce: frmGlobal.nonce
9517 + },
9518 + success: function( html ) {
9519 + document.getElementById( 'frm_field_' + fieldId + '_opts' ).innerHTML = html;
9520 + resetDisplayedOpts( fieldId );
9521 +
9522 + if ( typeof modal !== 'undefined' ) {
9523 + modal.dialog( 'close' );
9524 + document.getElementById( 'frm-update-bulk-opts' ).classList.remove( 'frm_loading_button' );
9525 + }
9526 + }
9527 + });
9528 + },
9529 +
9530 + /* remove conditional logic if the field doesn't exist */
9531 + triggerRemoveLogic: function( fieldID, metaName ) {
9532 + jQuery( '#frm_logic_' + fieldID + '_' + metaName + ' .frm_remove_tag' ).trigger( 'click' );
9533 + },
9534 +
9535 + downloadXML: function( controller, ids, isTemplate ) {
9536 + var url = ajaxurl + '?action=frm_' + controller + '_xml&ids=' + ids;
9537 + if ( isTemplate !== null ) {
9538 + url = url + '&is_template=' + isTemplate;
9539 + }
9540 + location.href = url;
9541 + },
9542 +
9543 + /**
9544 + * @since 5.0.04
9545 + */
9546 + hooks: {
9547 + applyFilters: function( hookName, ...args ) {
9548 + return wp.hooks.applyFilters( hookName, ...args );
9549 + },
9550 + addFilter: function( hookName, callback, priority ) {
9551 + return wp.hooks.addFilter( hookName, 'formidable', callback, priority );
9552 + }
9553 + }
9554 + };
9555 +}
9556 +
9557 +frmAdminBuild = frmAdminBuildJS();
9558 +
9559 +jQuery( document ).ready( function( $ ) {
9560 + frmAdminBuild.init();
9561 +});
9562 +
9563 +function frm_remove_tag( htmlTag ) { // eslint-disable-line camelcase
9564 + console.warn( 'DEPRECATED: function frm_remove_tag in v2.0' );
9565 + jQuery( htmlTag ).remove();
9566 +}
9567 +
9568 +function frm_show_div( div, value, showIf, classId ) { // eslint-disable-line camelcase
9569 + if ( value == showIf ) {
9570 + jQuery( classId + div ).fadeIn( 'slow' ).css( 'visibility', 'visible' );
9571 + } else {
9572 + jQuery( classId + div ).fadeOut( 'slow' );
9573 + }
9574 +}
9575 +
9576 +function frmCheckAll( checked, n ) {
9577 + jQuery( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked );
9578 +}
9579 +
9580 +function frmCheckAllLevel( checked, n, level ) {
9581 + var $kids = jQuery( '.frm_catlevel_' + level ).children( '.frm_checkbox' ).children( 'label' );
9582 + $kids.children( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked );
9583 +}
9584 +
9585 +function frm_add_logic_row( id, formId ) { // eslint-disable-line camelcase
9586 + console.warn( 'DEPRECATED: function frm_add_logic_row in v2.0' );
9587 + jQuery.ajax({
9588 + type: 'POST',
9589 + url: ajaxurl,
9590 + data: {
9591 + action: 'frm_add_logic_row',
9592 + form_id: formId,
9593 + field_id: id,
9594 + meta_name: jQuery( '#frm_logic_row_' + id + ' > div' ).length,
9595 + nonce: frmGlobal.nonce
9596 + },
9597 + success: function( html ) {
9598 + jQuery( '#frm_logic_row_' + id ).append( html );
9599 + }
9600 + });
9601 + return false;
9602 +}
9603 +
9604 +function frmGetFieldValues( fieldId, cur, rowNumber, fieldType, htmlName ) {
9605 +
9606 + if ( fieldId ) {
9607 + jQuery.ajax({
9608 + type: 'POST', url: ajaxurl,
9609 + 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,
9610 + success: function( msg ) {
9611 + document.getElementById( 'frm_show_selected_values_' + cur + '_' + rowNumber ).innerHTML = msg;
9612 + }
9613 + });
9614 + }
9615 +}
9616 +
9617 +function frmImportCsv( formID ) {
9618 + var urlVars = '';
9619 + if ( typeof __FRMURLVARS !== 'undefined' ) {
9620 + urlVars = __FRMURLVARS;
9621 + }
9622 +
9623 + jQuery.ajax({
9624 + type: 'POST', url: ajaxurl,
9625 + data: 'action=frm_import_csv&nonce=' + frmGlobal.nonce + '&frm_skip_cookie=1' + urlVars,
9626 + success: function( count ) {
9627 + var max = jQuery( '.frm_admin_progress_bar' ).attr( 'aria-valuemax' );
9628 + var imported = max - count;
9629 + var percent = ( imported / max ) * 100;
9630 + jQuery( '.frm_admin_progress_bar' ).css( 'width', percent + '%' ).attr( 'aria-valuenow', imported );
9631 +
9632 + if ( parseInt( count, 10 ) > 0 ) {
9633 + jQuery( '.frm_csv_remaining' ).html( count );
9634 + frmImportCsv( formID );
9635 + } else {
9636 + jQuery( document.getElementById( 'frm_import_message' ) ).html( frm_admin_js.import_complete );
9637 + setTimeout( function() {
9638 + location.href = '?page=formidable-entries&frm_action=list&form=' + formID + '&import-message=1';
9639 + }, 2000 );
9640 + }
9641 + }
9642 + });
9643 +}
9644 +
9645 +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
9646 +if ( ! String.prototype.trim ) {
9647 + String.prototype.trim = function() {
9648 + return this.replace( /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '' );
9649 + };
9650 +}
9651 +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#Polyfill
9652 +if ( ! String.prototype.startsWith ) {
9653 + Object.defineProperty( String.prototype, 'startsWith', {
9654 + value: function( search, pos ) {
9655 + pos = ! pos || pos < 0 ? 0 : +pos;
9656 + return this.substring( pos, pos + search.length ) === search;
9657 + }
9658 + });
9659 +}