| @@ -1 +1,10425 @@ | ||
| 1 | -(()=>{var e={65:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(8793),o=r(1323);function i(e){var t=(0,n.A)(e);return function(e){return(0,o.A)(t,e)}}},1323:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n={"!":function(e){return!e},"*":function(e,t){return e*t},"/":function(e,t){return e/t},"%":function(e,t){return e%t},"+":function(e,t){return e+t},"-":function(e,t){return e-t},"<":function(e,t){return e<t},"<=":function(e,t){return e<=t},">":function(e,t){return e>t},">=":function(e,t){return e>=t},"==":function(e,t){return e===t},"!=":function(e,t){return e!==t},"&&":function(e,t){return e&&t},"||":function(e,t){return e||t},"?:":function(e,t,r){if(e)throw t;return r}};function o(e,t){var r,o,i,a,l,s,c=[];for(r=0;r<e.length;r++){if(l=e[r],a=n[l]){for(o=a.length,i=Array(o);o--;)i[o]=c.pop();try{s=a.apply(null,i)}catch(e){return e}}else s=t.hasOwnProperty(l)?t[l]:+l;c.push(s)}return c[0]}},1364:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(65);function o(e){var t=(0,n.A)(e);return function(e){return+t({n:e})}}},8793:(e,t,r)=>{"use strict";var n,o,i,a;function l(e){for(var t,r,l,s,c=[],d=[];t=e.match(a);){for(r=t[0],(l=e.substr(0,t.index).trim())&&c.push(l);s=d.pop();){if(i[r]){if(i[r][0]===s){r=i[r][1]||r;break}}else if(o.indexOf(s)>=0||n[s]<n[r]){d.push(s);break}c.push(s)}i[r]||d.push(r),e=e.substr(t.index+r.length)}return(e=e.trim())&&c.push(e),c.concat(d.reverse())}r.d(t,{A:()=>l}),n={"(":9,"!":8,"*":7,"/":7,"%":7,"+":6,"-":6,"<":5,"<=":5,">":5,">=":5,"==":4,"!=":4,"&&":3,"||":2,"?":1,"?:":1},o=["(","?"],i={")":["("],":":["?","?:"]},a=/<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/},7521:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(6956),o=r(7395);const i=function(e,t){return function(r,i,a){var l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10,s=e[t];if((0,o.A)(r)&&(0,n.A)(i))if("function"==typeof a)if("number"==typeof l){var c={callback:a,priority:l,namespace:i};if(s[r]){var d,u=s[r].handlers;for(d=u.length;d>0&&!(l>=u[d-1].priority);d--);d===u.length?u[d]=c:u.splice(d,0,c),s.__current.forEach(function(e){e.name===r&&e.currentIndex>=d&&e.currentIndex++})}else s[r]={handlers:[c],runs:0};"hookAdded"!==r&&e.doAction("hookAdded",r,i,a,l)}else console.error("If specified, the hook priority must be a number.");else console.error("The hook callback must be a function.")}}},11:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){return function(){var r,n,o=e[t];return null!==(r=null===(n=o.__current[o.__current.length-1])||void 0===n?void 0:n.name)&&void 0!==r?r:null}}},5375:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(7395);const o=function(e,t){return function(r){var o=e[t];if((0,n.A)(r))return o[r]&&o[r].runs?o[r].runs:0}}},3561:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){return function(r){var n=e[t];return void 0===r?void 0!==n.__current[0]:!!n.__current[0]&&r===n.__current[0].name}}},8830:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){return function(r,n){var o=e[t];return void 0!==n?r in o&&o[r].handlers.some(function(e){return e.namespace===n}):r in o}}},7765:(e,t,r)=>{"use strict";r.d(t,{A:()=>f});var n=r(3029),o=r(7521),i=r(4194),a=r(8830),l=r(6763),s=r(11),c=r(3561),d=r(5375),u=function e(){(0,n.A)(this,e),this.actions=Object.create(null),this.actions.__current=[],this.filters=Object.create(null),this.filters.__current=[],this.addAction=(0,o.A)(this,"actions"),this.addFilter=(0,o.A)(this,"filters"),this.removeAction=(0,i.A)(this,"actions"),this.removeFilter=(0,i.A)(this,"filters"),this.hasAction=(0,a.A)(this,"actions"),this.hasFilter=(0,a.A)(this,"filters"),this.removeAllActions=(0,i.A)(this,"actions",!0),this.removeAllFilters=(0,i.A)(this,"filters",!0),this.doAction=(0,l.A)(this,"actions"),this.applyFilters=(0,l.A)(this,"filters",!0),this.currentAction=(0,s.A)(this,"actions"),this.currentFilter=(0,s.A)(this,"filters"),this.doingAction=(0,c.A)(this,"actions"),this.doingFilter=(0,c.A)(this,"filters"),this.didAction=(0,d.A)(this,"actions"),this.didFilter=(0,d.A)(this,"filters")};const f=function(){return new u}},4194:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(6956),o=r(7395);const i=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(i,a){var l=e[t];if((0,o.A)(i)&&(r||(0,n.A)(a))){if(!l[i])return 0;var s=0;if(r)s=l[i].handlers.length,l[i]={runs:l[i].runs,handlers:[]};else for(var c=l[i].handlers,d=function(e){c[e].namespace===a&&(c.splice(e,1),s++,l.__current.forEach(function(t){t.name===i&&t.currentIndex>=e&&t.currentIndex--}))},u=c.length-1;u>=0;u--)d(u);return"hookRemoved"!==i&&e.doAction("hookRemoved",i,a),s}}}},6763:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return function(n){var o=e[t];o[n]||(o[n]={handlers:[],runs:0}),o[n].runs++;for(var i=o[n].handlers,a=arguments.length,l=new Array(a>1?a-1:0),s=1;s<a;s++)l[s-1]=arguments[s];if(!i||!i.length)return r?l[0]:void 0;var c={name:n,currentIndex:0};for(o.__current.push(c);c.currentIndex<i.length;){var d=i[c.currentIndex].callback.apply(null,l);r&&(l[0]=d),c.currentIndex++}return o.__current.pop(),r?l[0]:void 0}}},2133:(e,t,r)=>{"use strict";r.d(t,{se:()=>n});var n=(0,r(7765).A)();n.addAction,n.addFilter,n.removeAction,n.removeFilter,n.hasAction,n.hasFilter,n.removeAllActions,n.removeAllFilters,n.doAction,n.applyFilters,n.currentAction,n.currentFilter,n.doingAction,n.doingFilter,n.didAction,n.didFilter,n.actions,n.filters},7395:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e){return"string"!=typeof e||""===e?(console.error("The hook name must be a non-empty string."),!1):/^__/.test(e)?(console.error("The hook name cannot begin with `__`."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(e)||(console.error("The hook name can only contain numbers, letters, dashes, periods and underscores."),!1)}},6956:(e,t,r)=>{"use strict";r.d(t,{A:()=>n});const n=function(e){return"string"!=typeof e||""===e?(console.error("The namespace must be a non-empty string."),!1):!!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(e)||(console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes."),!1)}},772:(e,t,r)=>{"use strict";r.d(t,{h:()=>c});var n=r(4467),o=r(5397);function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach(function(t){(0,n.A)(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var l={"":{plural_forms:function(e){return 1===e?0:1}}},s=/^i18n\.(n?gettext|has_translation)(_|$)/,c=function(e,t,r){var n=new o.A({}),i=new Set,c=function(){i.forEach(function(e){return e()})},d=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default";n.data[t]=a(a(a({},l),n.data[t]),e),n.data[t][""]=a(a({},l[""]),n.data[t][""])},u=function(e,t){d(e,t),c()},f=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default",t=arguments.length>1?arguments[1]:void 0,r=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;return n.data[e]||d(void 0,e),n.dcnpgettext(e,t,r,o,i)},m=function(){return arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default"},_=function(e,t,n){var o=f(n,t,e);return r?(o=r.applyFilters("i18n.gettext_with_context",o,e,t,n),r.applyFilters("i18n.gettext_with_context_"+m(n),o,e,t,n)):o};if(e&&u(e,t),r){var p=function(e){s.test(e)&&c()};r.addAction("hookAdded","core/i18n",p),r.addAction("hookRemoved","core/i18n",p)}return{getLocaleData:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default";return n.data[e]},setLocaleData:u,resetLocaleData:function(e,t){n.data={},n.pluralForms={},u(e,t)},subscribe:function(e){return i.add(e),function(){return i.delete(e)}},__:function(e,t){var n=f(t,void 0,e);return r?(n=r.applyFilters("i18n.gettext",n,e,t),r.applyFilters("i18n.gettext_"+m(t),n,e,t)):n},_x:_,_n:function(e,t,n,o){var i=f(o,void 0,e,t,n);return r?(i=r.applyFilters("i18n.ngettext",i,e,t,n,o),r.applyFilters("i18n.ngettext_"+m(o),i,e,t,n,o)):i},_nx:function(e,t,n,o,i){var a=f(i,o,e,t,n);return r?(a=r.applyFilters("i18n.ngettext_with_context",a,e,t,n,o,i),r.applyFilters("i18n.ngettext_with_context_"+m(i),a,e,t,n,o,i)):a},isRTL:function(){return"rtl"===_("ltr","text direction")},hasTranslation:function(e,t,o){var i,a,l=t?t+""+e:e,s=!(null===(i=n.data)||void 0===i||null===(a=i[null!=o?o:"default"])||void 0===a||!a[l]);return r&&(s=r.applyFilters("i18n.has_translation",s,e,t,o),s=r.applyFilters("i18n.has_translation_"+m(o),s,e,t,o)),s}}}},5839:(e,t,r)=>{"use strict";r.d(t,{__:()=>a});var n=r(772),o=r(2133),i=(0,n.h)(void 0,void 0,o.se),a=(i.getLocaleData.bind(i),i.setLocaleData.bind(i),i.resetLocaleData.bind(i),i.subscribe.bind(i),i.__.bind(i));i._x.bind(i),i._n.bind(i),i._nx.bind(i),i.isRTL.bind(i),i.hasTranslation.bind(i)},9575:(e,t,r)=>{"use strict";r.d(t,{__:()=>n.__}),r(181),r(772);var n=r(5839)},181:(e,t,r)=>{"use strict";var n=r(8616),o=r.n(n);r(7604),o()(console.error)},1105:(e,t,r)=>{"use strict";r.r(t),r.d(t,{addonError:()=>f,afterAddonInstall:()=>u,extractErrorFromAddOnResponse:()=>d,toggleAddonState:()=>c});var n=r(9575);function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,l=[],s=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(l.push(n.value),l.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var a=frmDom,l=a.div,s=a.svg;function c(e,t){var r,n=null!==(r=window.ajaxurl)&&void 0!==r?r:frm_js.ajax_url;jQuery(".frm-addon-error").remove();var o=jQuery(e),i=o.attr("rel"),a=o.parent(),l=a.parent().find(".addon-status-label");o.addClass("frm_loading_button"),jQuery.ajax({url:n,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:t,nonce:frmGlobal.nonce,plugin:i},success:function(e){var r,n,i;"string"!=typeof(e=null!==(r=null===(n=e)||void 0===n?void 0:n.data)&&void 0!==r?r:e)&&"string"==typeof e.message&&(void 0!==e.saveAndReload&&(i=e.saveAndReload),e=e.message);var s=d(e);s?f(s,a,o):(u(e,o,l,a,i,t),wp.hooks.doAction("frm_update_addon_state",e))},error:function(){o.removeClass("frm_loading_button")}})}function d(e){return"string"!=typeof e&&!e.success&&(e.form&&jQuery(e.form).is("#message")?{message:jQuery(e.form).find("p").html()}:e)}function u(e,t,r,i,a){var c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"frm_activate_addon",d=frm_admin_js,u=document.querySelectorAll(".frm-addon-status");u.forEach(function(t){t.textContent=e,t.style.display="block"}),t.css({opacity:"0"}),document.querySelectorAll(".frm-oneclick").forEach(function(e){e.style.display="none"}),function(){var e=document.getElementById("frm_upgrade_modal");if(e){e.classList.add("frm-success");var t=e.querySelector(".frm-upgrade-message");if(t){var r=t.querySelector("img");t.replaceChildren((0,n.__)("Great! Everything's ready to go!","formidable"),document.createElement("br"),(0,n.__)("You just need to refresh the builder so the new field becomes available.","formidable")),r&&t.append(r)}var o=document.querySelector(".frm-addon-status");o&&(o.textContent="");var i,a=e.querySelector(".frm-circled-icon");if(a)a.classList.add("frm-circled-icon-green"),null===(i=a.querySelector("svg"))||void 0===i||i.replaceWith(s({href:"#frm_checkmark_icon"}))}}();var f={frm_activate_addon:{class:"frm-addon-active",message:d.active},frm_deactivate_addon:{class:"frm-addon-installed",message:d.installed},frm_uninstall_addon:{class:"frm-addon-not-installed",message:d.not_installed}};f.frm_install_addon=f.frm_activate_addon;var _=o(r,1)[0];_&&(_.textContent=f[c].message);var p=o(i,1)[0].parentElement;p.classList.remove("frm-addon-not-installed","frm-addon-installed","frm-addon-active"),p.classList.add(f[c].class),o(t,1)[0].classList.remove("frm_loading_button"),document.querySelectorAll(".frm-admin-page-import, #frm-admin-smtp, #frm-welcome").length>0?window.location.reload():["settings","form_builder"].includes(a)&&u.forEach(function(e){var t=null!==e.closest("#frm_upgrade_modal");e.append(function(e,t){var r,o=[m(e)];return t&&o.push(((r=document.createElement("a")).setAttribute("href","#"),r.classList.add("button","button-secondary","frm-button-secondary","dismiss"),r.textContent=(0,n.__)("Not Now","formidable"),r)),l({className:"frm-save-and-reload-options",children:o})}(a,t))})}function f(e,t,r){e.form?(jQuery(".frm-inline-error").remove(),r.closest(".frm-card").html(e.form).css({padding:5}).find("#upgrade").attr("rel",r.attr("rel")).on("click",_)):(t.append('<div class="frm-addon-error frm_error_style"><p><strong>'.concat(e.message,"</strong></p></div>")),r.removeClass("frm_loading_button"),jQuery(".frm-addon-error").delay(4e3).fadeOut())}function m(e){var t=document.createElement("button");return t.classList.add("frm-save-and-reload","button","button-primary","frm-button-primary"),t.textContent=(0,n.__)("Save and Reload","formidable"),t.addEventListener("click",function(){var t;"form_builder"===e?((t=document.getElementById("frm_submit_side_top")).classList.contains("frm_submit_ajax")&&t.setAttribute("data-new-addon-installed",!0),t.click()):"settings"===e&&function(){var e=document.getElementById("form_settings_page");if(e){var t=e.querySelector("form.frm_form_settings");null!==t&&(wp.hooks.doAction("frm_reset_fields_updated"),t.submit())}}()}),t}function _(e){e.preventDefault();var t=jQuery(this),r=t.parent().parent(),n=t.attr("rel");t.addClass("frm_loading_button"),jQuery.ajax({url:ajaxurl,type:"POST",async:!0,cache:!1,dataType:"json",data:{action:"frm_install_addon",nonce:frmAdminJs.nonce,plugin:n,hostname:r.find("#hostname").val(),username:r.find("#username").val(),password:r.find("#password").val()},success:function(e){var n,o,i=d(e=null!==(n=null===(o=e)||void 0===o?void 0:o.data)&&void 0!==n?n:e);i?f(i,r,t):u(e,t,message,r)},error:function(){t.removeClass("frm_loading_button")}})}},4365:()=>{!function(){function e(e){var t=e.querySelector(".frm-gc-item-type"),r=t.value,n=t.name.replace(/\[type\]$/,"");e.querySelectorAll(".frm-gc-type-settings").forEach(function(e){var t=e.dataset.type===r;e.toggleAttribute("hidden",!t),e.querySelectorAll("[data-frm-gc-field]").forEach(function(e){var r=e.dataset.frmGcField;t?e.name="".concat(n,"[").concat(r,"]"):e.removeAttribute("name")})})}function t(t){var r,n=t.querySelector(".frm_gc_add_item"),o=null!==(r=null==n?void 0:n.dataset.fieldNameBase)&&void 0!==r?r:"",i=t.querySelectorAll(".frm_gc_item_row");i.forEach(function(r,n){var i=r.querySelector(".frm-gc-item-type");i&&o&&(i.name="".concat(o,"[").concat(n,"][type]")),function(e,t,r){var n=e.querySelector('[data-frm-gc-field="type"]');if(n){n.id="".concat(t,"_type_").concat(r);var o=e.querySelector('[data-frm-gc-for="type"]');o&&(o.htmlFor=n.id)}e.querySelectorAll(".frm-gc-type-settings").forEach(function(e){var n=e.dataset.type;e.querySelectorAll("[data-frm-gc-field]").forEach(function(o){var i=o.dataset.frmGcField;o.id="".concat(t,"_").concat(i,"_").concat(n,"_").concat(r);var a=e.querySelector('[data-frm-gc-for="'.concat(i,'"]'));a&&(a.htmlFor=o.id)})})}(r,t.id,n),e(r)}),t.dataset.itemCount=i.length}function r(e){var t=e.getAttribute("aria-label");e.classList.add("is-copied"),e.setAttribute("aria-label",e.dataset.copiedLabel||"Copied!"),setTimeout(function(){e.classList.remove("is-copied"),e.setAttribute("aria-label",t)},1600)}document.addEventListener("click",function(e){var n=e.target.closest(".frm_gc_add_item");if(n){var o=n.closest(".frm_gated_content_settings"),i=o.querySelector(".frm_gc_items_list"),a=o.querySelector(".frm_gc_item_template");return i.append(a.content.cloneNode(!0)),t(o),void frmDom.autocomplete.initSelectionAutocomplete(i.lastElementChild)}var l=e.target.closest(".frm_gc_remove_item");if(l){var s=l.closest(".frm_gated_content_settings");return l.closest(".frm_gc_item_row").remove(),void t(s)}var c=e.target.closest(".frm_gc_copy_shortcode");if(c){var d,u=c.dataset.frmCopy;if(null!==(d=navigator.clipboard)&&void 0!==d&&d.writeText)navigator.clipboard.writeText(u).then(function(){return r(c)});else{var f=document.createElement("textarea");f.value=u,f.style.cssText="position:fixed;opacity:0;",document.body.append(f),f.select(),document.execCommand("copy"),f.remove(),r(c)}}}),document.addEventListener("change",function(t){var r=t.target.closest(".frm-gc-item-type");if(r)e(r.closest(".frm_gc_item_row"));else{var n=t.target.closest(".frm-gc-file-form-select");n&&function(e){var t=e.closest(".frm-gc-type-settings"),r=null==t?void 0:t.querySelector('[data-frm-gc-field="id"]');if(r){var n=e.value;Array.from(r.options).forEach(function(e){var t=e.dataset.formId;e.style.display=t?n&&t===n?"":"none":""});var o=r.options[r.selectedIndex];"none"===(null==o?void 0:o.style.display)&&(r.value="")}}(n)}}),jQuery(document).on("frm-multiselect-changed",'select[id^="event_"]',function(){var e=document.querySelector('.frm_gc_update_section[data-frm-gc-event-id="'.concat(this.id,'"]'));if(e){var t=Array.from(this.options).some(function(e){return e.selected&&"update"===e.value});e.hidden=!t}})}()},8095:(e,t,r)=>{"use strict";function n(e,t){var r=t();return r?(frmAdminBuild.infoModal(r),e.classList.add("frm_invalid_field"),function(e){var t=document.querySelectorAll("#frm_info_modal .dismiss, #frm_info_modal #frm-info-click, .ui-widget-overlay.ui-front");function r(){setTimeout(function(){return e.focus()},0),t.forEach(function(e){return e.removeEventListener("click",r)})}t.forEach(function(e){return e.addEventListener("click",r)})}(e)):e.classList.remove("frm_invalid_field"),r}r.r(t),r.d(t,{validateField:()=>n})},4746:(e,t,r)=>{"use strict";r.r(t),r.d(t,{getRangeSettingsDefaults:()=>l,validateNumberRangeSetting:()=>s,validateRangeSettings:()=>d,validateStepSetting:()=>c});var n=r(9575),o=r(8095),i=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return t?t.dataset.fid:null==r||null===(e=r.closest(".frm-single-settings"))||void 0===e?void 0:e.dataset.fid},a=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return t||(t=null==r?void 0:r.closest(".frm-single-settings")),null===(e=t)||void 0===e||null===(e=e.className.match(/frm-type-(\w+)/))||void 0===e?void 0:e[1]};function l(e){var t=a(e)||"number";return wp.hooks.applyFilters("frm_range_settings_defaults",{maxNum:9999999,minNum:0,step:1},{singleSettings:e,fieldType:t})}function s(e){if(e.closest(".frm-number-range")){var t=e.closest(".frm-single-settings"),r=i(t);if(r){var a=document.querySelector('[name="field_options[minnum_'.concat(r,']"]'));if(a){var s=document.querySelector('[name="field_options[maxnum_'.concat(r,']"]'));if(s)return(0,o.validateField)(e,function(){var e=l(t),r=e.minNum,o=e.maxNum;return parseFloat(a.value||r)>=parseFloat(s.value||o)?(0,n.__)("Minimum value cannot be greater than or equal to maximum value.","formidable"):""})}}}}function c(e){if(e.closest(".frm-step")){var t=e.closest(".frm-single-settings"),r=i(t);if(r){var a=document.querySelector('[name="field_options[step_'.concat(r,']"]'));if(a)return(0,o.validateField)(e,function(){var e=l(t),o=e.step,i=e.minNum,s=e.maxNum,c=parseFloat(a.value||o);if(c<=0)return(0,n.__)("Step value must be greater than 0.","formidable");var d=document.querySelector('[name="field_options[maxnum_'.concat(r,']"]'));if(!d)return"";var u=document.querySelector('[name="field_options[minnum_'.concat(r,']"]')),f=parseFloat((null==u?void 0:u.value)||i);return c>parseFloat(d.value||s)-f?(0,n.__)("Step value cannot be greater than the difference between the minimum and maximum values.","formidable"):""})}}}function d(e){var t=s(e);return t||(t=c(e)),wp.hooks.applyFilters("frm_validate_range_settings",t||"",{field:e})}},4260:(e,t,r)=>{"use strict";r.r(t),r.d(t,{addOneClick:()=>i,initModal:()=>a,initUpgradeModal:()=>l});var n=r(9575),o=frmDom.svg;function i(e,t,r){var i;if("modal"===t)i=document.getElementById("frm_upgrade_modal");else{if("tab"!==t)return;i=document.getElementById(e.getAttribute("href").substr(1))}var a,l=i.querySelector(".frm-oneclick"),s=i.querySelector(".frm-upgrade-message"),c=i.querySelector(".frm-upgrade-link"),d=i.querySelector(".frm-oneclick-button"),u=i.querySelector(".frm-addon-status"),f=e.getAttribute("data-oneclick"),m=e.getAttribute("data-message"),_="block",p="block",g="none",v=i.querySelector(".frm-circled-icon");v&&(v.classList.remove("frm-circled-icon-green"),null===(a=v.querySelector("svg"))||void 0===a||a.replaceWith(o({href:"#frm_filled_lock_icon"})));var y=i.querySelector(".frm-learn-more");if(y&&(e.dataset.learnMore?(y.href=e.dataset.learnMore,y.style.display=""):y.style.display="none"),null!==l&&null!==d&&void 0!==f&&f){null===m&&(p="none"),_="none",g="block",f=JSON.parse(f),d.className=d.className.replace(" frm-install-addon","").replace(" frm-activate-addon",""),d.className="".concat(d.className," ").concat(f.class),d.rel=f.url,l.textContent=(0,n.__)("This plugin is not activated. Would you like to activate it now?","formidable"),d.textContent=(0,n.__)("Activate","formidable");var h=e.querySelector("use");h&&(null==v||v.querySelector("svg").replaceWith(o({href:h.getAttribute("href")||h.getAttribute("xlink:href"),classList:["frm_svg32"]})))}m||(m=s.getAttribute("data-default")),void 0!==r&&(m=m.replace('<span class="frm_feature_label"></span>',r)),s.innerHTML=m,e.dataset.upsellImage&&s.append(frmDom.img({src:e.dataset.upsellImage,alt:e.dataset.upgrade})),c.href=function(e,t){var r=e.getAttribute("data-link");return null!=r&&""!==r||(r=t.getAttribute("data-default")),r}(e,c),u.style.display="none",l&&(l.style.display=g),d&&(d.style.display="block"===g?"inline-block":g),s.style.display=p,c.style.display="block"===_?"inline-block":_;var b=c.closest(".frm-upgrade-modal-actions");b&&(b.style.display="block"===_?"flex":_)}function a(e,t){var r=jQuery(e);if(!r.length)return!1;void 0===t&&(t="552px");var n={dialogClass:"frm-dialog",modal:!0,autoOpen:!1,closeOnEscape:!0,width:t,resizable:!1,draggable:!1,open:function(){var e,t;jQuery(".ui-dialog-titlebar").addClass("frm_hidden").removeClass("ui-helper-clearfix"),jQuery("#wpwrap").addClass("frm_overlay"),jQuery(".frm-dialog").removeClass("ui-widget ui-widget-content ui-corner-all"),r.removeClass("ui-dialog-content ui-widget-content"),e=r,t=function(){e.dialog("close")},jQuery(".ui-widget-overlay").on("click",t),e.on("click","a.dismiss",t)},close:function(){jQuery("#wpwrap").removeClass("frm_overlay"),jQuery(".spinner").css("visibility","hidden"),this.removeAttribute("data-option-type");var e=document.getElementById("bulk-option-type");e&&(e.value="")}};return r.dialog(n),r}function l(){var e=a("#frm_upgrade_modal");function t(t){var r,o,a;if((r=t.target).classList){var l=r.classList.contains("frm_show_expired_modal")||null!==r.querySelector(".frm_show_expired_modal")||r.closest(".frm_show_expired_modal");if("change"===t.type&&r.classList.contains("frm_select_with_upgrade")){var s,c=r.options[r.selectedIndex];null!=c&&null!==(s=c.dataset)&&void 0!==s&&s.upgrade&&(r=c)}if(!r.dataset.upgrade){var d=r.closest("[data-upgrade]");if(!d){if(!(d=r.closest(".frm_field_box")))return;r.dataset.upgrade=""}r=d}if(l)wp.hooks.doAction("frm_show_expired_modal",r);else{var u=r.dataset.upgrade;if(u&&!r.classList.contains("frm_show_upgrade_tab")){t.preventDefault();var f=e.get(0);f.classList.remove("frm-success");var m=f.querySelector(".frm_lock_icon");m&&(m.style.display="block",m.classList.remove("frm_lock_open_icon"),m.querySelector("use").setAttribute("href","#frm_lock_icon"));var _="frm_upgrade_modal_image",p=document.getElementById(_);p&&p.remove(),r.dataset.image&&m&&(m.style.display="none",m.parentNode.insertBefore(frmDom.img({id:_,src:"".concat(frmGlobal.url,"/images/").concat(r.dataset.image)}),m));var g=f.querySelector(".license-level");g&&(g.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(r)),i(r,"modal",u);var v=f.querySelector(".frm_are_not_installed");v.style.display=r.dataset.image||r.dataset.oneclick?"none":"inline-block",v.textContent=v.dataset.default,f.querySelector(".frm-upgrade-modal-title-prefix").style.display=r.dataset.oneclick?"inline":"none",f.querySelector(".frm_feature_label").textContent=u,f.querySelector(".frm-upgrade-modal-title-suffix").style.display="none",f.querySelector("h2").style.display="block",e.dialog("open");var y=f.querySelector(".button-primary:not(.frm-oneclick-button)");o=y.getAttribute("href").replace(/(medium=)[a-z_-]+/gi,"$1".concat(r.getAttribute("data-medium"))),null===(a=r.getAttribute("data-content"))&&(a=""),o=o.replace(/(content=)[a-z_-]+/gi,"$1".concat(a)),y.setAttribute("href",o),r.classList.contains("frm_show_update")&&function(e){var t=e.querySelector(".frm-upgrade-modal-title-prefix");t&&(t.style.display="none");var r=e.querySelector(".frm_are_not_installed");r&&(r.textContent=(0,n.__)("require an update","formidable"),r.style.display="");var o=e.querySelector(".frm-oneclick");o&&(o.style.display="none");var i=e.querySelector(".frm-oneclick-button");i&&(i.textContent=(0,n.__)("Update Now","formidable"))}(f)}}}}!1!==e&&(document.addEventListener("click",t),frmDom.util.documentOn("change","select.frm_select_with_upgrade",t))}},8616:e=>{e.exports=function(e,t){var r,n,o=0;function i(){var i,a,l=r,s=arguments.length;e:for(;l;){if(l.args.length===arguments.length){for(a=0;a<s;a++)if(l.args[a]!==arguments[a]){l=l.next;continue e}return l!==r&&(l===n&&(n=l.prev),l.prev.next=l.next,l.next&&(l.next.prev=l.prev),l.next=r,l.prev=null,r.prev=l,r=l),l.val}l=l.next}for(i=new Array(s),a=0;a<s;a++)i[a]=arguments[a];return l={args:i,val:e.apply(null,i)},r?(r.prev=l,l.next=r):n=l,o===t.maxSize?(n=n.prev).next=null:o++,r=l,l.val}return t=t||{},i.clear=function(){r=null,n=null,o=0},i}},7604:(e,t,r)=>{var n;!function(){"use strict";var o={not_string:/[^s]/,not_bool:/[^t]/,not_type:/[^T]/,not_primitive:/[^v]/,number:/[diefg]/,numeric_arg:/[bcdiefguxX]/,json:/[j]/,not_json:/[^j]/,text:/^[^\x25]+/,modulo:/^\x25{2}/,placeholder:/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,key:/^([a-z_][a-z_\d]*)/i,key_access:/^\.([a-z_][a-z_\d]*)/i,index_access:/^\[(\d+)\]/,sign:/^[+-]/};function i(e){return function(e,t){var r,n,a,l,s,c,d,u,f,m=1,_=e.length,p="";for(n=0;n<_;n++)if("string"==typeof e[n])p+=e[n];else if("object"==typeof e[n]){if((l=e[n]).keys)for(r=t[m],a=0;a<l.keys.length;a++){if(null==r)throw new Error(i('[sprintf] Cannot access property "%s" of undefined value "%s"',l.keys[a],l.keys[a-1]));r=r[l.keys[a]]}else r=l.param_no?t[l.param_no]:t[m++];if(o.not_type.test(l.type)&&o.not_primitive.test(l.type)&&r instanceof Function&&(r=r()),o.numeric_arg.test(l.type)&&"number"!=typeof r&&isNaN(r))throw new TypeError(i("[sprintf] expecting number but found %T",r));switch(o.number.test(l.type)&&(u=r>=0),l.type){case"b":r=parseInt(r,10).toString(2);break;case"c":r=String.fromCharCode(parseInt(r,10));break;case"d":case"i":r=parseInt(r,10);break;case"j":r=JSON.stringify(r,null,l.width?parseInt(l.width):0);break;case"e":r=l.precision?parseFloat(r).toExponential(l.precision):parseFloat(r).toExponential();break;case"f":r=l.precision?parseFloat(r).toFixed(l.precision):parseFloat(r);break;case"g":r=l.precision?String(Number(r.toPrecision(l.precision))):parseFloat(r);break;case"o":r=(parseInt(r,10)>>>0).toString(8);break;case"s":r=String(r),r=l.precision?r.substring(0,l.precision):r;break;case"t":r=String(!!r),r=l.precision?r.substring(0,l.precision):r;break;case"T":r=Object.prototype.toString.call(r).slice(8,-1).toLowerCase(),r=l.precision?r.substring(0,l.precision):r;break;case"u":r=parseInt(r,10)>>>0;break;case"v":r=r.valueOf(),r=l.precision?r.substring(0,l.precision):r;break;case"x":r=(parseInt(r,10)>>>0).toString(16);break;case"X":r=(parseInt(r,10)>>>0).toString(16).toUpperCase()}o.json.test(l.type)?p+=r:(!o.number.test(l.type)||u&&!l.sign?f="":(f=u?"+":"-",r=r.toString().replace(o.sign,"")),c=l.pad_char?"0"===l.pad_char?"0":l.pad_char.charAt(1):" ",d=l.width-(f+r).length,s=l.width&&d>0?c.repeat(d):"",p+=l.align?f+r+s:"0"===c?f+s+r:s+f+r)}return p}(function(e){if(l[e])return l[e];for(var t,r=e,n=[],i=0;r;){if(null!==(t=o.text.exec(r)))n.push(t[0]);else if(null!==(t=o.modulo.exec(r)))n.push("%");else{if(null===(t=o.placeholder.exec(r)))throw new SyntaxError("[sprintf] unexpected placeholder");if(t[2]){i|=1;var a=[],s=t[2],c=[];if(null===(c=o.key.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");for(a.push(c[1]);""!==(s=s.substring(c[0].length));)if(null!==(c=o.key_access.exec(s)))a.push(c[1]);else{if(null===(c=o.index_access.exec(s)))throw new SyntaxError("[sprintf] failed to parse named argument key");a.push(c[1])}t[2]=a}else i|=2;if(3===i)throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");n.push({placeholder:t[0],param_no:t[1],keys:t[2],sign:t[3],pad_char:t[4],align:t[5],width:t[6],precision:t[7],type:t[8]})}r=r.substring(t[0].length)}return l[e]=n}(e),arguments)}function a(e,t){return i.apply(null,[e].concat(t||[]))}var l=Object.create(null);"undefined"!=typeof window&&(window.sprintf=i,window.vsprintf=a,void 0===(n=function(){return{sprintf:i,vsprintf:a}}.call(t,r,t,e))||(e.exports=n))}()},5397:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(1364),o={contextDelimiter:"",onMissingKey:null};function i(e,t){var r;for(r in this.data=e,this.pluralForms={},this.options={},o)this.options[r]=void 0!==t&&r in t?t[r]:o[r]}i.prototype.getPluralForm=function(e,t){var r,o,i,a=this.pluralForms[e];return a||("function"!=typeof(i=(r=this.data[e][""])["Plural-Forms"]||r["plural-forms"]||r.plural_forms)&&(o=function(e){var t,r,n;for(t=e.split(";"),r=0;r<t.length;r++)if(0===(n=t[r].trim()).indexOf("plural="))return n.substr(7)}(r["Plural-Forms"]||r["plural-forms"]||r.plural_forms),i=(0,n.A)(o)),a=this.pluralForms[e]=i),a(t)},i.prototype.dcnpgettext=function(e,t,r,n,o){var i,a,l;return i=void 0===o?0:this.getPluralForm(e,o),a=r,t&&(a=t+this.options.contextDelimiter+r),(l=this.data[e][a])&&l[i]?l[i]:(this.options.onMissingKey&&this.options.onMissingKey(r,e),0===i?r:n)}},3029:(e,t,r)=>{"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}r.d(t,{A:()=>n})},4467:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(9922);function o(e,t,r){return(t=(0,n.A)(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}},2327:(e,t,r)=>{"use strict";r.d(t,{A:()=>o});var n=r(2284);function o(e,t){if("object"!=(0,n.A)(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!=(0,n.A)(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}},9922:(e,t,r)=>{"use strict";r.d(t,{A:()=>i});var n=r(2284),o=r(2327);function i(e){var t=(0,o.A)(e,"string");return"symbol"==(0,n.A)(t)?t:t+""}},2284:(e,t,r)=>{"use strict";function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}r.d(t,{A:()=>n})}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}function n(e){return function(e){if(Array.isArray(e))return d(e)}(e)||o(e)||c(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function i(e){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i(e)}function a(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e){if(Array.isArray(e))return e}function s(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=c(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,l=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){l=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(l)throw i}}}}function c(e,t){if(e){if("string"==typeof e)return d(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var u=r(8095).validateField,f=r(4746),m=f.getRangeSettingsDefaults,_=f.validateNumberRangeSetting,p=f.validateStepSetting,g=f.validateRangeSettings;window.FrmFormsConnect=window.FrmFormsConnect||function(e,t,r){var n={messageBox:null,reset:null,setElements:function(){n.messageBox=e.querySelector(".frm_pro_license_msg"),n.reset=e.getElementById("frm_reconnect_link")}},o={init:function(){n.setElements(),r(e.getElementById("frm_deauthorize_link")).on("click",o.deauthorize),r(".frm_authorize_link").on("click",o.authorize),r(".frm-dashboard-license-options").on("click","#frm_deauthorize_link",o.deauthorize),r(".frm-dashboard-license-options").on("click","#frm_reconnect_link",o.reauthorize),null!==n.reset&&r(n.reset).on("click",o.reauthorize)},authorize:function(){var t=this,n=this.getAttribute("data-plugin"),i=e.getElementById("edd_".concat(n,"_license_key")),a=i.value,l=e.getElementById("proplug-wpmu");this.classList.add("frm_loading_button"),l=l&&l.checked?1:0,r.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_activate",license:a,plugin:n,wpmu:l,nonce:frmGlobal.nonce},success:function(e){o.afterAuthorize(e,i),t.classList.remove("frm_loading_button")}})},afterAuthorize:function(e,t){!0===e.success&&(t.value="•••••••••••••••••••"),wp.hooks.doAction("frm_after_authorize",e),o.showMessage(e)},showProgress:function(e){null===n.messageBox&&n.setElements();var t=n.messageBox;null!==t&&(!0===e.success?(t.classList.remove("frm_error_style"),t.classList.add("frm_message","frm_updated_message")):(t.classList.add("frm_error_style"),t.classList.remove("frm_message","frm_updated_message")),t.classList.remove("frm_hidden"),t.innerHTML=e.message)},showMessage:function(r){null===n.messageBox&&n.setElements();var i=n.messageBox;!0===r.success&&(o.showAuthorized(!0),o.showInlineSuccess(),wp.hooks.doAction("frmAdmin.afterLicenseAuthorizeSuccess",{msg:r})),o.showProgress(r),""!==r.message&&(setTimeout(function(){i.innerHTML="",i.classList.add("frm_hidden"),i.classList.remove("frm_error_style","frm_message","frm_updated_message")},1e4),e.querySelector(".frm-admin-page-dashboard")&&setTimeout(function(){t.location.reload()},1e3))},showAuthorized:function(t){var r=t?"unauthorized":"authorized",n=t?"authorized":"unauthorized",o=e.querySelectorAll(".frm_".concat(r,"_box"));o.length&&o.forEach(function(e){e.className=e.className.replace("frm_".concat(r,"_box"),"frm_".concat(n,"_box"))})},showInlineSuccess:function(){var t=e.querySelectorAll(".frm-confirm-msg [data-success]");t.length&&t.forEach(function(e){e.innerHTML=frmAdminBuild.purifyHtml(e.getAttribute("data-success"))})},reauthorize:function(){return this.innerHTML='<span class="frm-wait frm_spinner" style="visibility:visible;float:none"></span>',r.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_reset_cache",plugin:"formidable_pro",nonce:frmGlobal.nonce},success:function(e){n.reset.textContent=e.message,"1"===n.reset.getAttribute("data-refresh")&&t.location.reload()}}),!1},deauthorize:function(){if(!confirm(frmGlobal.deauthorize))return!1;var t=this.getAttribute("data-plugin"),n=e.getElementById("edd_".concat(t,"_license_key")),i=n.value,a=this;return this.innerHTML='<span class="frm-wait frm_spinner" style="visibility:visible;"></span>',r.ajax({type:"POST",url:ajaxurl,data:{action:"frm_addon_deactivate",license:i,plugin:t,nonce:frmGlobal.nonce},success:function(){o.showAuthorized(!1),n.value="",a.replaceWith("Disconnected"),wp.hooks.doAction("frmAdmin.afterLicenseDeauthorizeSuccess",{})}}),!1}};return o}(document,window,jQuery),window.frmAdminBuildJS=function(){var e,t,f=frm_admin_js,v=frmDom,y=v.tag,h=v.div,b=v.span,w=v.a,j=v.svg,x=v.img,E=frmDom.util.onClickPreventDefault,k=frmDom.ajax.doJsonPost;f.contextualShortcodes=(t=null===(e=document.getElementById("frm_adv_info"))||void 0===e?void 0:e.dataset.contextualShortcodes)?((t=JSON.parse(t)).addressSelector="[id^=email_to], [id^=from_], [id^=cc], [id^=bcc]",t.bodySelector="[id^=email_message_]",t):[];var Q,S,A,L={save:j({href:"#frm_save_icon"}),drag:j({href:"#frm_drag_icon",classList:["frm_drag_icon","frm-drag"]})},I=jQuery(document.getElementById("frm-show-fields")),q=document.getElementById("new_fields"),B=document.getElementById("form_id"),C=!1,N=0,T=0,O=0,F={},D=0,M=wp.i18n,P=M.__,R=M.sprintf,z={dragging:!1,draggable:null,offsetsRefreshed:!1,submitButtonRow:null};B&&(T=B.value);var H,G=new URL(window.location.href),U=G.searchParams,W=document.getElementById("frm_builder_page");function $(e){e.stopPropagation(),e.preventDefault(),V(this)}function V(e){var t=e.getAttribute("data-frmverify"),r=e.getAttribute("data-loaded-from");return null===t||"frm-confirmed-click"===e.id||("entries-list"===r?wp.hooks.applyFilters("frm_on_multiple_entries_delete",{link:e,initModal:ea}):function(e){var t=ea("#frm_confirm_modal","400px"),r=document.getElementById("frm-confirmed-click");if(!1===t)return!1;r&&(r.style.display="block");var n=e.getAttribute("data-frmverify"),o=n?e.getAttribute("data-frmverify-btn"):"",i=jQuery(".frm-confirm-msg");i.empty(),n&&(i.append(document.createTextNode(n)),o&&(null==r||r.classList.add(o)));var a=e.dataset;if(r){for(var l in r.dataset)r.removeAttribute("data-".concat(l));for(var s in a)"frmverify"!==s&&r.setAttribute("data-".concat(s),a[s])}return wp.hooks.doAction("frmAdmin.beforeOpenConfirmModal",{$info:t,link:e}),t.dialog("open"),null==r||r.setAttribute("href",e.getAttribute("href")||e.getAttribute("data-href")),!1}(e))}function K(e,t){var r=ea("#frm_info_modal",t||"400px");if(!1===r)return!1;"string"==typeof e&&(e={msg:e}),e=Object.assign({title:"",msg:P("Are you sure?","formidable"),img:"",closeText:P("Got it!","formidable"),actionUrl:"",actionText:"",noCenter:!1},e);var n=r[0].querySelector(".info-modal-title");n.textContent=e.title||"",n.classList.toggle("frm_hidden",!e.title),e.msg&&(r[0].querySelector(".frm-info-msg").innerHTML=Tn(e.msg)),r[0].querySelector(".info-modal-img").src=e.img,r[0].querySelector(".info-modal-img-wrapper").classList.toggle("frm_hidden",!e.img);var o=document.getElementById("frm-info-click");e.closeText&&(o.textContent=e.closeText),o.classList.toggle("button-primary",!e.actionUrl),o.classList.toggle("frm-button-primary",!e.actionUrl),o.classList.toggle("button-secondary",Boolean(e.actionUrl)),o.classList.toggle("frm-button-secondary",Boolean(e.actionUrl));var i=r[0].querySelector(".info-modal-action-link");return e.actionUrl&&(i.href=e.actionUrl,e.actionText&&(i.textContent=e.actionText)),i.classList.toggle("frm_hidden",!e.actionUrl),r[0].querySelector(".info-modal-inside").classList.toggle("frmcenter",!e.noCenter),r[0].querySelector(".info-modal-buttons").classList.toggle("frmright",e.noCenter),r.dialog("open"),!1}function J(e){var t=this.getAttribute("data-frmtoggle"),r=this.getAttribute("data-toggletext"),n=jQuery(t);return e.preventDefault(),n.toggle(),null!==r&&""!==r&&(this.setAttribute("data-toggletext",this.innerHTML),this.textContent=r),!1}function X(e){var t=this.getAttribute("data-frmhide"),r=this.getAttribute("data-frmshow"),n=this.getAttribute("data-frmuncheck"),o=n?n.split(","):[];"INPUT"!==this.nodeName||"checkbox"!==this.type||this.checked||(null!==t?(r=t,t=null):null!==r&&(t=r,r=null)),e.preventDefault();var i=this.getAttribute("data-toggleclass")||"frm_hidden";null!==t&&jQuery(t).addClass(i),null!==r&&jQuery(r).removeClass(i);var a=this.parentNode.querySelectorAll("a.current");if(null!==a){for(var l=0;l<a.length;l++)a[l].classList.remove("current");this.classList.add("current")}return o.length&&o.forEach(function(e){var t=document.querySelector(e);t&&(t.checked=!1)}),!1}function Y(){document.querySelectorAll(".tooltip").forEach(function(e){e.remove()})}function Z(){var e,t,r;if(!parseInt(this.getAttribute("data-skip-frm-js"))&&!1!==V(this)){var n=jQuery(this),o=n.attr("data-removeid");void 0===(e=n.attr("data-showlast"))&&(e=""),void 0===(t=n.attr("data-hidelast"))&&(t=""),r=n.attr("data-removemore"),""!==e?n.closest(".frm_add_remove").find(".frm_remove_tag:visible").length>1&&(e="",t=""):0===o.indexOf("frm_postmeta_")&&(jQuery("#frm_postmeta_rows .frm_postmeta_row").length<2&&(e=".frm_add_postmeta_row.button"),jQuery(".frm_toggle_cf_opts").length&&jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().length&&(""!==e&&(e+=","),e+="#".concat(jQuery("#frm_postmeta_rows .frm_postmeta_row:not(#".concat(o,")")).last().attr("id")," .frm_toggle_cf_opts")));var i=document.getElementById(o),a=jQuery(i);return a.fadeOut(300,function(){var r;a.remove(),ci(),""!==t&&(jQuery(t).hide(),function(e){var t=document.querySelector(e);if(t){var r,n=s(t.classList);try{for(n.s();!(r=n.n()).done;){var o=r.value,i=document.querySelector('input[data-toggleclass="'.concat(o,'"]'));if(null!=i&&i.checked)return void(i.checked=!1)}}catch(e){n.e(e)}finally{n.f()}}}(t)),""!==e&&jQuery("".concat(e," a,").concat(e)).removeClass("frm_hidden").fadeIn("slow"),this.closest(".frm_form_action_settings")&&function(e){var t;Io(e),"payment"===e&&["stripe","square","paypal"].forEach(function(e){return Io(e)}),document.querySelector(".frm_form_action_settings")||null===(t=document.querySelector(".frm-no-actions-message"))||void 0===t||t.classList.remove("frm_hidden");var r={type:e};wp.hooks.doAction("frm_after_action_removed",r)}(this.closest(".frm_form_action_settings").querySelector(".frm_action_name").value),null===(r=document.querySelector(".tooltip"))||void 0===r||r.remove()}),void 0!==r&&(r=jQuery(r)).fadeOut(400,function(){r.remove()}),""!==e&&jQuery(this).closest(".frm_logic_rows").fadeOut("slow"),wp.hooks.doAction("frm_admin_tag_removed",o,i),!1}}function ee(){var e,t=document.querySelector("#frm-actions-filter-content .frm-action:not(.frm_hidden)");null===(e=document.getElementById("frm-actions-no-results"))||void 0===e||e.classList.toggle("frm_hidden",t)}function te(e,t){void 0===t&&(t=this),yt(t,!1);var r=jQuery(t).closest(".frm_form_action_settings"),n=e.target;if(r.length&&void 0!==n){var o=n.parentElement.className;if("string"==typeof o&&(o.includes("frm_email_icons")||o.includes("frm_toggle")))return void e.stopPropagation()}var i=r.children(".widget-inside");if(r.length&&i.find("p, div, table").length<1){var a=r.find('input[name$="[ID]"]').val(),l=r.find('input[name$="[post_excerpt]"]').val();l&&(i.html('<span class="frm-wait frm_spinner"></span>'),r.find(".spinner").fadeIn("slow"),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_form_action_fill",action_id:a,action_type:l,nonce:frmGlobal.nonce},success:function(e){i.html(e),Bi(),ho("#".concat(r.attr("id"))),Pi(i),jQuery(t).trigger("frm-action-loaded"),wp.hooks.doAction("frm_filled_form_action",i)}}))}jQuery(t).closest(".frm_field_box").siblings().find(".widget-inside").slideUp("fast"),void 0!==t.className&&t.className.includes("widget-action")||jQuery(t).closest(".start_divider").length<1||((i=jQuery(t).closest("div.widget").children(".widget-inside")).is(":hidden")?i.slideDown("fast"):i.slideUp("fast"))}function re(e,t){Array.from(e.children).forEach(function(e){e.classList.contains("tabs-panel")&&e.id!==t&&!e.classList.contains(t)&&(e.style.display="none")})}function ne(e){e.style.display="block"}function oe(){var e=this.getAttribute("href");if(null===e||"#"!==e.charAt(0))return!1;var t=e.slice(1),r=this.closest("li");r&&(r.classList.add("frm-tabs","active"),Array.from(r.parentNode.children).forEach(function(e){e!==r&&"LI"===e.tagName&&e.classList.remove("frm-tabs","active","starttab")}));var n=this.closest("div");n&&re(n,t);var o=document.getElementById(t);return o&&ne(o),"frm_insert_fields_tab"!==this.id||this.closest("#frm_adv_info")||mt(),!1}function ie(e,t){var r,n,o=(e=jQuery(e)).attr("href");if(void 0!==o&&"#"===o.charAt(0)){var i=o.slice(1);e.closest("li").addClass("frm-tabs active").siblings("li").removeClass("frm-tabs active starttab");var s,d,u=(r=e.closest("div"),n=1,l(r)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,l=[],s=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(l.push(n.value),l.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return l}}(r,n)||c(r,n)||a())[0];if(null!=u&&u.querySelector(".tabs-panel"))re(u,i);else if(null!==document.getElementById("form_global_settings")){var f=e.data("frmajax");e.closest(".frm_wrap").find(".tabs-panel, .hide_with_tabs").hide(),void 0!==f&&"1"==f&&(s=o.replace("#",""),(d=jQuery(".frm_".concat(s,"_ajax"))).length&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_settings_tab",tab:s.replace("_settings",""),nonce:frmGlobal.nonce},success:function(e){d.replaceWith(e)}}))}else jQuery("#frm-categorydiv .tabs-panel, .hide_with_tabs").hide();var m=document.getElementById(i);m&&ne(m),Array.from(document.getElementsByClassName(i)).forEach(function(e){return ne(e)}),vi(),"auto"!==t&&(jQuery(".frm_updated_message").hide(),jQuery(".frm_warning_style:not(.frm_force_visible_warning)").hide()),jQuery(e).closest("#frm_adv_info").length||(jQuery(".frm_form_settings").length?jQuery(".frm_form_settings").attr("action","?page=formidable&frm_action=settings&id=".concat(jQuery('.frm_form_settings input[name="id"]').val(),"&t=").concat(i)):jQuery(".frm_settings_form").attr("action","?page=formidable-settings&t=".concat(i)))}}function ae(e){document.querySelectorAll(e).forEach(function(e){le(e),Array.from(e.children).forEach(function(e){return de(e,".frm-move")});var t=jQuery(e).children('[data-type="divider"]').children(".divider_section_only");t.length&&le(t)})}function le(e){jQuery(e).droppable({accept:".frmbutton, li.frm_field_box",deactivate:ge,over:se,out:ce,tolerance:"pointer"})}function se(e,t){var r=function(e){return e.classList.contains("divider_section_only")&&(e=jQuery(e).nextAll(".start_divider.frm_sorting").get(0)),e}(e.target);if(!Oe(t.draggable[0],r,e))return r.classList.remove("frm-over-droppable"),void jQuery(r).parents("ul.frm_sorting").addClass("frm-over-droppable");document.querySelectorAll(".frm-over-droppable").forEach(function(e){return e.classList.remove("frm-over-droppable")}),r.classList.add("frm-over-droppable"),jQuery(r).parents("ul.frm_sorting").addClass("frm-over-droppable")}function ce(e){e.target.classList.remove("frm-over-droppable")}function de(e,t){var r={helper:ue,revert:"invalid",delay:10,start:fe,stop:me,drag:_e,cursor:"grabbing",cursorAt:{top:0,left:90}};"string"==typeof t&&(r.handle=t),jQuery(e).draggable(r)}function ue(e){var t,r=e.delegateTarget;if(De(r)){var n=document.getElementById("frm-insert-fields").querySelector(".frm_ttext").cloneNode(!0);return n.querySelector("use").setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_field_group_layout_icon"),n.querySelector("span").textContent=P("Field Group","formidable"),n.classList.add("frm_field_box"),n.classList.add("ui-sortable-helper"),n}if(r.classList.contains("frmbutton"))return(t=r.cloneNode(!0)).classList.add("ui-sortable-helper"),r.classList.add("frm-new-field"),t;if(r.hasAttribute("data-ftype")){var o=r.getAttribute("data-ftype");if(t=document.getElementById("frm-insert-fields").querySelector(".frm_t".concat(o)))return(t=t.cloneNode(!0)).classList.add("form-field"),t.classList.add("ui-sortable-helper"),t.cloneNode(!0)}return h({className:"frmbutton"})}function fe(e,t){if(e.target.classList.contains("frm_at_limit"))return $e(),!1;z.dragging=!0,z.draggable=null,z.offsetsRefreshed=!1;var r,n=S;n.classList.add("frm-dragging-field"),document.body.classList.add("frm-dragging"),t.helper.addClass("frm-sortable-helper"),t.helper.initialOffset=n.scrollTop,e.target.classList.add("frm-drag-fade"),Dr(),(r=document.querySelectorAll("ul.start_divider")).length&&r.forEach(function(e){[].slice.call(e.children).forEach(function(e){(0===e.children.length||1===e.children.length&&"ul"===e.firstElementChild.nodeName.toLowerCase()&&0===e.firstElementChild.children.length)&&e.remove()})}),rt(),Ze(),Y()}function me(){z.draggable=null,S.classList.remove("frm-dragging-field"),document.body.classList.remove("frm-dragging");var e=document.querySelector(".frm-drag-fade");e&&e.classList.remove("frm-drag-fade")}function _e(e,t){z.offsetsRefreshed||(z.offsetsRefreshed=!0,z.draggable=jQuery(e.target).draggable("instance")||null,pe(e)),function(e){var t=S.scrollTop;A.scrollTop(function(t,r){var n=e.clientY,o=S.offsetHeight,i=e.clientY-S.offsetTop,a=i-o/2;return i>o-50&&n>5?r+.1*a:i<70&&n<130?r-Math.abs(.1*a):r}),t!==S.scrollTop&&pe(e)}(e);var r=e.target,n=function(){for(var e=document.getElementById("frm-show-fields");e.querySelector(".frm-over-droppable");)e=e.querySelector(".frm-over-droppable");return"frm-show-fields"!==e.id||e.classList.contains("frm-over-droppable")||(e=!1),e}(),o=document.getElementById("frm_drag_placeholder");if(Oe(r,n,e)){o||(o=y("li",{id:"frm_drag_placeholder",className:"sortable-placeholder"}));var i,a=t.helper.get(0);if((a.classList.contains("form-field")||a.classList.contains("frm_field_box"))&&(a.style.transform="translateY(".concat((i=t.helper,S.scrollTop-i.initialOffset),"px)")),"frm-show-fields"===n.id||n.classList.contains("start_divider"))return o.style.left=0,void function(e){var t,r=e.y,n=e.placeholder,o=jQuery(e.droppable),i=ve(o);if(0===i.length)o.prepend(n),t=0;else{var a=ye(o,r,i);if(a===i.length){var l=jQuery(i[a-1]);t=l.offset().top+l.outerHeight(),o.append(n);var s=o.children(".edit_field_type_end_divider");s.length&&o.append(s)}else t=jQuery(i[a]).offset().top,jQuery(i[a]).before(n)}t-=o.offset().top,n.style.top="".concat(t,"px")}({droppable:n,y:e.clientY,placeholder:o});o.style.top="",function(e){var t,r=e.x,n=e.placeholder,o=jQuery(e.droppable),i=be(o);if(i.length){var a=function(e,t){var r,n,o,i,a=be(e);for(i=0,r=a.length-1;r>=0;--r)if(n=a.get(r),t>(o=jQuery(n).offset().left)){i=r,t>o+jQuery(n).outerWidth()/2&&(i=r+1);break}return i}(o,r);if(a===i.length){var l=jQuery(i.get(a-1));t=l.offset().left+l.outerWidth(),o.append(n)}else t=jQuery(i.get(a)).offset().left,jQuery(i.get(a)).before(n),t-=0===a?4:8;t-=o.offset().left,n.style.left="".concat(t,"px")}}({droppable:n,x:e.clientX,placeholder:o})}else o&&o.remove()}function pe(e){z.draggable&&jQuery.ui.ddmanager.prepareOffsets(z.draggable,e)}function ge(e,t){if(z.dragging){z.dragging=!1;var r=t.draggable[0],n=document.getElementById("frm_drag_placeholder");if(!n)return t.helper.remove(),void Q();!function(e){if(e.previousElementSibling&&e.previousElementSibling.classList.contains("frm-is-collapsed")){var t=jQuery(e).prevUntil('[data-type="break"]');if(t.length){var r=t.find(".frm-collapse-page").get(0);r&&r.click()}}}(n);var o=t.helper.parent(),i=t.helper.get(0).closest("ul.start_divider"),a=n.closest("ul.start_divider");r.classList.contains("frm-new-field")?function(e){if(Ie(e))wp.hooks.doAction("frm_stopped_inserting_by_dragging",e);else{var t=document.getElementById("frm_drag_placeholder"),r="".concat(e.replace("|","-"),"_").concat(Te()),n=y("li",{id:r,className:"frm-wait frmbutton_loadingnow"}),o=jQuery(n),i=ke(jQuery(t)),a=Qe(i),l=Se(i);t.parentNode.insertBefore(n,t),t.remove(),we(o);var s=0;"summary"===e&&(s=jQuery(".frmbutton_loadingnow#".concat(r)).prevAll('li[data-type="break"]').length?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:Le(e,l,a,s),success:function(t){qe(t,o);var r=Be(t);r&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:r,fieldType:e,form_id:a})},error:Ne})}}(r.id):(function(e,t){t.parentNode.insertBefore(e,t)}(r,n),function(e){if("UL"===e.nodeName&&!e.classList.contains("start_divider")&&"frm-show-fields"!==e.id){var t=e.closest("li");t&&!t.classList.contains("ui-draggable")&&de(t,".frm-move")}}(n.parentElement));var l=i?parseInt(i.closest(".edit_field_type_divider").getAttribute("data-fid")):0,s=a?parseInt(a.closest(".edit_field_type_divider").getAttribute("data-fid")):0;n.remove(),t.helper.remove();var c=o.length?be(o):[];!function(e,t){var r;e.length&&(t.length?we(t.first()):(r=e.get(0).closest("li.frm_field_box"))&&!r.classList.contains("edit_field_type_divider")&&r.remove())}(o,c),function(e,t){0===t.length&&1===be(jQuery(e.parentNode)).length||we(jQuery(e))}(r,c),l!==s&&Ae(jQuery(r),i),Q()}}function ve(e){var t=e.get(0);return t?Array.from(t.children).filter(function(e){return!e.classList.contains("edit_field_type_end_divider")}):[]}function ye(e,t,r){if(!document.querySelector(".frm-has-fields .frm_no_fields"))return 0;for(var n=r||ve(e),o=0,i=n.length-1,a=-1;o<=i;){var l=Math.floor((o+i)/2);t>n[l].getBoundingClientRect().top?(a=l,o=l+1):i=l-1}if(-1===a)return 0;var s=n[a].getBoundingClientRect();return t>s.top+s.height/2?a+1:a}function he(){document.querySelectorAll("ul#frm-show-fields, ul.start_divider").forEach(function(e){e.childNodes.forEach(function(e){void 0!==e.classList&&(e.classList.contains("edit_field_type_end_divider")||void 0!==e.classList&&e.classList.contains("form-field")&&dt(e))})}),$n(),document.querySelectorAll(".edit_field_type_end_divider").forEach(function(e){return e.parentNode.append(e)}),document.querySelectorAll("li.form_field_box:not(.form-field)").forEach(function(e){return!e.children.length&&e.remove()}),Wn();var e=new Event("frm_sync_after_drag_and_drop",{bubbles:!1});document.dispatchEvent(e)}function be(e){var t=jQuery(),r=e.get(0);return r.children?(Array.from(r.children).forEach(function(e){if("none"!==e.style.display){var r=e.classList;!r.contains("form-field")||r.contains("edit_field_type_end_divider")||r.contains("frm-sortable-helper")||(t=t.add(e))}}),t):t}function we(e,t){var r;void 0===t&&(t="even");var n=e.parent().children("li.form-field, li.frmbutton_loadingnow").not(".edit_field_type_end_divider"),o=n.length,i=["frm_full","frm_half","frm_third","frm_fourth","frm_sixth","frm_two_thirds","frm_three_fourths","frm1","frm2","frm3","frm4","frm5","frm6","frm7","frm8","frm9","frm10","frm11","frm12"];"even"===t&&5!==o?n.each(Ee(i,pr(o))):"clear"===t?n.each(Ee(i,"")):(r=["left","right","middle","even"].includes(t)?function(e){return _r(o,t,e)}:function(e){return Ar(t[e])},n.each(Ee(i,r))),je(e.parent(),n.length)}function je(e,t){if(void 0!==e.offset()){var r=t>=2,n=document.getElementById("frm_field_group_controls");if(!n){if(!r)return;(n=h()).id="frm_field_group_controls",n.setAttribute("role","group"),n.setAttribute("tabindex",0),function(e){var t=document.createElement("span");t.innerHTML='<svg class="frmsvg"><use href="#frm_field_group_layout_icon"></use></svg>';var r=P("Set Row Layout","formidable");xe(t,r),cr(t,r);var n=document.createElement("span");n.innerHTML='<svg class="frmsvg"><use href="#frm_thick_move_icon"></use></svg>',n.classList.add("frm-move");var o=P("Move Field Group","formidable");xe(n,o),cr(n,o),e.innerHTML="",e.append(t),e.append(n),e.append(function(){var e=b({className:"dropdown"}),t=w({className:"frm_bstooltip frm-hover-icon frm-dropdown-toggle dropdown-toggle",children:[b({child:j({href:"#frm_thick_more_vert_icon"})}),b({className:"screen-reader-text",text:P("Toggle More Options Dropdown","formidable")})]});frmDom.setAttributes(t,{title:P("More Options","formidable"),"data-bs-toggle":"dropdown","data-bs-container":"body","data-bs-display":"static"}),cr(t,P("More Options","formidable")),e.append(t);var r=h({className:"frm-dropdown-menu dropdown-menu dropdown-menu-right"});return r.setAttribute("role","menu"),e.append(r),e}())}(n),W.append(n)}e.append(n),n.style.display=r?"block":"none"}}function xe(e,t){e.setAttribute("data-bs-toggle","tooltip"),e.setAttribute("data-bs-container","body"),e.setAttribute("title",t),e.addEventListener("mouseover",function(){e.__bootstrapTooltip||(e.__bootstrapTooltip=new bootstrap.Tooltip(e))})}function Ee(e,t){return function(r){for(var n="function"==typeof t?t(r):t,o=e.length,i=!1,a=0;a<o;++a){var l=e[a];if(this.classList.contains(l)){i=l;break}}var s=this.dataset.fid;if(void 0!==s){Qo(document.getElementById("frm-single-settings-".concat(s)));var c=document.getElementById("frm_classes_".concat(s));c&&(!1===i?""!==n&&(c.value=c.value.concat(" ".concat(n))):(this.classList.remove(i),c.value=c.value.replace(i,n)),this.classList.contains("frm_first")&&(this.classList.remove("frm_first"),c.value=c.value.replace("frm_first","").trim()),0===r&&(this.classList.add("frm_first"),c.value=c.value.concat(" frm_first")),jQuery(c).trigger("change"))}else this.classList.add(n)}}function ke(e){var t="";return void 0===e||e.hasClass("edit_field_type_divider")||(t=e.closest(".edit_field_type_divider")),t}function Qe(e){var t="";if(void 0!==e[0]){var r=e.children(".start_divider");if(r.children(".edit_field_type_end_divider").appendTo(r),void 0!==e.attr("data-formid")){var n=e.attr("data-fid");t=jQuery('input[name="field_options[form_select_'.concat(n,']"]')).val()}}return void 0!==t&&""!==t||(t=T),t}function Se(e){var t=0;return void 0!==e[0]&&(t=e.attr("id").replace("frm_field_id_","")),t}function Ae(e,t){if(e.hasClass("form-field")){var r=e.attr("id").replace("frm_field_id_",""),n=ke(e),o=Qe(n),i=Se(n),a=t?Qe(jQuery(t.parentNode)):0;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_update_field_after_move",form_id:o,field:r,section_id:i,previous_form_id:a,nonce:frmGlobal.nonce},success:function(){$n(),function(e,t){document.getElementById("frm_in_section_".concat(e)).value=t}(r,i)}})}else be(jQuery(e.get(0).firstChild)).each(function(){Ae(jQuery(this),t)})}function Le(e,t,r,n){var o={action:"frm_insert_field",form_id:r,field_type:e,section_id:t,nonce:frmGlobal.nonce,has_break:n};return t>0&&document.getElementById("form_id").value!==r||(o.last_row_field_ids=function(){var e=document.querySelector(".edit_field_type_submit");if(!e)return[];for(var t=e.parentNode.children,r=[],n=0;n<t.length;n++)r.push(t[n].dataset.fid);return r}()),o}function Ie(e){return wp.hooks.applyFilters("frm_should_stop_inserting_field",!1,e)}function qe(e,t){var r;document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var n=t.siblings("li.form-field").not(".edit_field_type_end_divider");n.length?(r=Ce(e),t.get(0).parentNode.parentNode.classList.contains("ui-draggable")||de(t.get(0).parentNode.parentNode,".frm-move")):r=ct(e),t.replaceWith(r),Wn(),ut(e,!1),n.length&&we(n.first()),$n(),n.length?de(r.get(0),".frm-move"):(le(r.get(0).querySelector("ul.frm_sorting")),de(r.get(0).querySelector("li.form-field"),".frm-move"))}function Be(e){var t=e.match(/data-fid="(\d+)"/);return t?parseInt(t[1]):0}function Ce(e){var t=h();return t.innerHTML=e,jQuery(t.firstChild)}function Ne(e,t,r){!function(e,t){(function(e){return 0===e.status||0===e.readyState})(t)||K("".concat(e,". Please try again."))}(r,e)}function Te(){return++O}function Oe(e,t,r){if(!1===t)return!1;if(t.closest(".frm-sortable-helper"))return!1;var n=e.classList.contains("edit_field_type_submit"),o=!e.classList.contains("form_field")&&Boolean(e.querySelector(".edit_field_type_submit"));if("frm-show-fields"===t.id){var i=ye(jQuery(t),r.clientY);if(n||o)return i>t.childElementCount-1;var a=function(e){if(z.submitButtonRow&&z.submitButtonRow.parentNode===e)return z.submitButtonRow;var t=e.querySelector(".edit_field_type_submit");return z.submitButtonRow=t?t.closest("#frm-show-fields > li"):null,z.submitButtonRow}(t);return!a||i<=Array.prototype.indexOf.call(t.children,a)}if(n)return!(t.classList.contains("start_divider")||!Fe(t.parentElement)&&(!Fe(t.parentElement.nextElementSibling)||e.parentElement.querySelector("li.frm_field_box:not(.edit_field_type_submit)")));var l=t.classList.contains("start_divider")&&null!==t.closest(".repeat_section"),s=null!==t.closest(".repeat_section");if(l||s){if(e.classList.contains("edit_field_type_gdpr")||"gdpr"===e.id)return!1;if(wp.hooks.applyFilters("frm_deny_drop_in_repeater",!1,e))return!1}if(!l){if(!function(e,t){if(e.length<12)return!0;if(e.length>12)return!1;var r=t.attr("data-fid");return 1===jQuery(e).filter('[data-fid="'.concat(r,'"]')).length}(be(jQuery(t)),jQuery(e)))return!1;if("divider"===e.id&&t.closest(".start_divider"))return!1}return e.classList.contains("frm-new-field")?function(e,t){var r=e.classList,n=r.contains("frm_tbreak"),o=r.contains("frm_thidden"),i=r.contains("frm_tdivider"),a=r.contains("frm_tform"),l=r.contains("frm_tuser_id");return"frm-show-fields"===t.id||t.classList.contains("start_divider")?!(n||o||i||a)||(!(t.classList.contains("start_divider")||null!==t.closest(".start_divider"))||!a&&!i):!(Me(t)||o||n||l)}(e,t):function(e,t){if(De(e))return function(e,t){return!(!t.classList.contains("start_divider")||null!==e.querySelector(".start_divider"))}(e,t);if(e.classList.contains("edit_field_type_break"))return!1;if(t.classList.contains("start_divider"))return function(e){return!e.classList.contains("edit_field_type_form")&&!e.querySelector(".edit_field_type_form")&&!(e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"))}(e);var r=e.classList.contains("edit_field_type_hidden"),n=e.classList.contains("edit_field_type_user_id");return!r&&!n&&function(e,t){if(Me(t))return!1;if(jQuery(e).children("ul.frm_sorting").not(".start_divider").length>0)return!1;var r=e.classList.contains("edit_field_type_divider")||e.querySelector(".edit_field_type_divider"),n=e.classList.contains("edit_field_type_form");return!(null!==t.closest(".start_divider")&&(r||n))}(e,t)}(e,t)}function Fe(e){return null==e?void 0:e.matches("#frm-show-fields > li:last-child")}function De(e){return e.classList.contains("frm_field_box")&&!e.classList.contains("form-field")}function Me(e){return null!==e.querySelector(".edit_field_type_break, .edit_field_type_hidden, .edit_field_type_user_id")}var Pe=0,Re=!1;function ze(){for(;Pe<3;){var e=document.querySelector("#frm-show-fields .frm_field_loading:not(.frm_load_now)");if(!e)break;He(e)}Re&&0===Pe&&(on(),Ke())}function He(e){var t=[],r=function(e){e.classList.add("frm_load_now"),e.classList.contains("frm_field_loading")&&t.push(e.dataset.fid)};r(e);for(var n=Ge(e);n&&t.length<40;)r(n),n=Ge(n);t.length&&(++Pe,Re=!0,jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_load_field",field_ids:t,form_id:T,nonce:frmGlobal.nonce},success:Ue,complete:function(){--Pe,ze()}}))}function Ge(e){var t;return e.nextElementSibling?e.nextElementSibling:null===(t=e.parentNode)||void 0===t||null===(t=t.closest(".frm_field_box"))||void 0===t||null===(t=t.nextElementSibling)||void 0===t?void 0:t.querySelector(".form-field")}function Ue(e){var t;if(0===(e=e.replace(/^\s+|\s+$/g,"")).indexOf("{")){var r=JSON.parse(e),n=[],o=[];for(t in r)if(Object.hasOwn(r,t)){jQuery("#frm_field_id_".concat(t)).replaceWith(r[t].html),o.push({id:t,type:r[t].type});var i=document.getElementById("frm_field_id_".concat(t));i&&(n.push(i),i.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),i.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")})),ae("#frm_field_id_".concat(t,".edit_field_type_divider ul.frm_sorting")),de(document.getElementById("frm_field_id_".concat(t)))}Bi(n),z.dragging&&pe();var a=new Event("frm_ajax_loaded_field",{bubbles:!1});a.frmFields=o,document.dispatchEvent(a)}else jQuery(".frm_load_now").removeClass(".frm_load_now").html("Error")}function We(){var e=jQuery(this);if(e.hasClass("disabled"))return!1;var t=e.closest(".frmbutton"),r=t.attr("id");if(t.hasClass("frm_at_limit"))return $e(),!1;if(frm_admin_js.paymentsSettingsModal&&"object"===i(frm_admin_js.paymentsSettingsModal)&&["product","quantity","total"].includes(r))return K(frm_admin_js.paymentsSettingsModal),!1;if(!Ie(r)){var n=0;"summary"===r&&(n=I.children('li[data-type="break"]').length>0?1:0);var o=T;return jQuery.ajax({type:"POST",url:ajaxurl,data:Le(r,0,o,n),success:function(e){Ve(e);var t=Be(e);t&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:e,fieldId:t,fieldType:r,form_id:o})},error:Ne}),!1}}function $e(){var e=document.querySelector(".frm_wrap");if(e){var t=document.createElement("a");t.setAttribute("data-frmverify",P("This field type has reached its limit.","formidable")),e.append(t),t.click(),t.remove();var r=document.getElementById("frm-confirmed-click");r&&(r.style.display="none")}}function Ve(e){document.getElementById("frm_form_editor_container").classList.add("frm-has-fields");var t=ct(e),r=I[0].querySelector(".edit_field_type_submit");r?jQuery(r.closest(".frm_field_box:not(.form-field)")).before(t):I.append(t),ut(e,!0),t.each(function(){le(this.querySelector("ul.frm_sorting")),de(this.querySelector(".form-field"),".frm-move")})}function Ke(){var e=!0,t=document.querySelectorAll(".frmjs_prod_field_opt_cont");I.find("li.edit_field_type_product").length>1&&(e=!1);for(var r=0;r<t.length;r++)t[r].classList.toggle("frm_hidden",e)}function Je(){var e=jQuery(this).closest("li.form-field"),t=this.getAttribute("frm-target-row-id");if(null!=t&&t.startsWith("frm_field_group_")||function(e){if(e.classList.contains("frm-page-collapsed"))return!1;var t=e.closest("li.frm_field_box:not(.form-field)");return!t||be(jQuery(t.querySelector("ul"))).length<12}(e.get(0))){Ze();var r,n=e.data("fid"),o=function(e){var t=[];return jQuery(document.getElementById("frm_field_id_".concat(e))).find("li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)").each(function(){t.push(jQuery(this).data("fid"))}),t}(n);return null!==t&&(r=this.getAttribute("frm-field-order")),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_duplicate_field",field_id:n,form_id:T,children:o,nonce:frmGlobal.nonce},success:function(o){var i,a,l;if(null!==t&&(a=document.getElementById(t)))return l=Ce(o),jQuery(a).append(l),de(l.get(0),".frm-move"),null!==r&&a.lastElementChild.setAttribute("frm-field-order",r),jQuery(a).trigger("frm_added_duplicated_field_to_row",{duplicatedFieldHtml:o,originalFieldId:n}),ut(o,!1),void Xe(e.get(0),l.get(0));e.siblings("li.form-field").length?(l=Ce(o),e.after(l),we(e),de(l.get(0),".frm-move")):(l=ct(o),e.parent().parent().after(l),le(l.get(0).querySelector("ul.frm_sorting")),de(l.get(0).querySelector("li.form-field"),".frm-move")),Wn(),ut(o,!1),Ye(n,o),Vn(l.find(".start_divider")),null===(i=e[0].querySelector(".frm-dropdown-menu.dropdown-menu-right"))||void 0===i||i.classList.remove("show"),Xe(e.get(0),l.get(0))}}),!1}K(R(P("You can only have a maximum of %1$d fields in a field group. Delete or move out a field from the group and try again.","formidable"),12))}function Xe(e,t){var r,n=e.closest(".frm-field-group-hover-target");if(n&&De(n.parentElement)){var o=e.dataset.fid,i=null===(r=document.getElementById("frm_classes_".concat(o)))||void 0===r?void 0:r.value;if(i&&(i=i.replace("frm_first",""),!t.className.includes(i))){t.className+=" ".concat(i);var a=document.getElementById("frm_classes_".concat(t.dataset.fid));a&&(a.value=i)}}}function Ye(e,t){var r=document.getElementById("frm-single-settings-".concat(e));if(r){var n=jQuery(t).attr("data-fid");if(void 0!==n){var o=document.getElementById("frm-single-settings-".concat(n));if(o){var i=["name","required","unique","read_only","placeholder","description","size","max","format","prepend","append","separate_value"];r.querySelectorAll('input[name^="field_options["], textarea[name^="field_options["]').forEach(function(t){var r,a=((r=t.name.substr(14).split("_")).pop(),r.join("_"));if("options"!==a){if(i.includes(a)){var l=t.matches("input")?"input":"textarea",s=o.querySelector("".concat(l,'[name="field_options[').concat(a,"_").concat(n,']"]'));null!==s&&("checkbox"===t.type?t.checked!==s.checked&&jQuery(s).trigger("click"):"text"!==t.type&&"textarea"!==l||t.value!==s.value&&(s.value=t.value,jQuery(s).trigger("change")))}}else!function(e,t,r,n){var o=e.name.substr(23+"".concat(r).length),i="field_options[options_".concat(n,"]").concat(o),a=t.querySelector('input[name="'.concat(i,'"]'));null!==a&&a.value!==e.value&&(a.value=e.value,jQuery(a).trigger("change"))}(t,o,e,n)});var a=r.querySelector('input[name="default_value_'.concat(e,'"]'));if(null!==a){var l=o.querySelector('input[name="default_value_'.concat(n,'"]'));null!==l&&a.value!==l.value&&(l.value=a.value,jQuery(l).trigger("change"))}}}}}function Ze(){var e=document.querySelector(".frm-field-settings-open");e&&(e.classList.remove("frm-field-settings-open"),jQuery(document).off("click","#frm_builder_page",et),jQuery(".frm-field-action-icons .dropdown.open").removeClass("open"))}function et(e){jQuery(e.originalEvent.target).closest(".frm-field-action-icons").length||Ze()}function tt(e){var t=Boolean(e.ctrlKey||e.metaKey||e.shiftKey);jQuery(W).toggleClass("frm-multiselect-key-is-down",t),function(e){if(!S.classList.contains("frm-dragging-field")&&null===document.querySelector(".frm-field-group-hover-target .frm-field-settings-open")){var t=document.elementFromPoint(e.clientX,e.clientY);if(null!==t&&!t.classList.contains("edit_field_type_divider")){var r=t.closest("ul.frm_sorting");if(null!==r&&!r.classList.contains("start_divider")&&"frm-show-fields"!==r.id){var n=rt();!1===n||jQuery(n).is(r)||Br(),je(jQuery(r),be(jQuery(r)).length),r.classList.add("frm-field-group-hover-target"),jQuery("#wpbody-content").on("mousemove",nt)}}}}(e)}function rt(){var e=document.getElementById("frm_field_group_controls");e&&(e.style.display="none");var t=document.querySelector(".frm-field-group-hover-target");return!!t&&(jQuery("#wpbody-content").off("mousemove",nt),t.classList.remove("frm-field-group-hover-target"),t)}function nt(e){var t=document.elementFromPoint(e.clientX,e.clientY);null!==t&&null!==t.closest("#frm-show-fields")||(rt(),Y())}function ot(e){Dr(),setTimeout(function(){var t=document.querySelector(".dropdown .frm-dropdown-menu.show");if(t){null===t.getAttribute("aria-label")&&t.setAttribute("aria-label",P("More Options","formidable")),0===t.children.length&&function(e,t){var r=t?"_field_group":"_field",n=[lt(t),st(t)];t||n.push({class:"frm_select",icon:"frm_settings_icon",label:P("Field Settings","formidable")}),n.forEach(function(t){var n=document.createElement("div");n.classList.add("frm_more_options_li","dropdown-item");var o=document.createElement("a");o.classList.add(t.class+r),o.setAttribute("href","#"),cr(o);var i=document.createElement("span");i.textContent=t.label,o.innerHTML='<svg class="frmsvg"><use href="#'.concat(t.icon,'"></use></svg>'),o.append(document.createTextNode(" ")),o.append(i),n.append(o),e.append(n)})}(t,!0===e);var r=jQuery(t);r.offset().left>jQuery(window).width()-r.outerWidth()?t.style.left="".concat(-r.outerWidth(),"px"):S&&r.offset().left<S.getBoundingClientRect().left&&(t.style.right="auto",t.style.left="0");var n=t.firstElementChild.querySelector("a");n&&n.focus()}},0)}function it(){ot(!0)}function at(e){var t=e.target.closest(".frm-section-collapsed");t&&("show"===e.type?t.style.zIndex=3:t.style.zIndex=1)}function lt(e){var t={class:"frm_delete",icon:"frm_delete_icon"};return t.label=P(e?"Delete Group":"Delete","formidable"),t}function st(e){var t={class:"frm_clone",icon:"frm_clone_icon"};return t.label=P(e?"Duplicate Group":"Duplicate","formidable"),t}function ct(e){var t=h();"string"==typeof e?t.innerHTML=e:t.append(e);var r=jQuery();return Array.from(t.children).forEach(function(e){r=r.add(jQuery("<li>").addClass("frm_field_box").html(jQuery("<ul>").addClass("frm_grid_container frm_sorting").append(e)))}),r}function dt(e){var t=y("ul",{className:"frm_grid_container frm_sorting"}),r=y("li",{className:"frm_field_box",child:t});e.replaceWith(r),t.append(e),le(t),de(r,".frm-move")}function ut(e,t){var r,n,o=/id="(\S+)"/.exec(e),a=document.getElementById(o[1]),l="#".concat(o[1],".edit_field_type_divider ul.frm_sorting.start_divider"),s=jQuery(l),c=a.getAttribute("data-type");r=e,(n=h()).innerHTML=r,n.querySelectorAll(".form-field").forEach(ft);var d,u,f=!1;if(ci(),ae(l),"quantity"===c&&function(e){var t=e.getAttribute("data-fid"),r=document.getElementById("field_options[product_field_".concat(t,"]"));r&&(xt(r),Qo(document.getElementById("frm-single-settings-".concat(t))))}(a),"product"!==c&&"quantity"!==c||Ke(),s.length)s.parent(".frm_field_box").children(".frm_no_section_fields").addClass("frm_block");else{var m=jQuery(a).closest("ul.frm_sorting.start_divider");m.length&&(Vn(m),f=!0)}e.includes("frm-collapse-page")&&on(),u="frm-newly-added",(d=a).classList?d.classList.add(u):d.className+=" ".concat(u),setTimeout(function(){a.classList.remove("frm-newly-added")},1e3);var _,p=a.querySelector("#frm-last-row-fields-order");if(p&&((_=JSON.parse(p.value))&&"object"===i(_)&&Object.keys(_).forEach(function(e){var t=document.querySelector('input[name="field_options[field_order_'.concat(e,']"]'));t&&(t.value=_[e])})),t){var g=a.getBoundingClientRect(),v=document.getElementById("post-body-content");g.top>=0&&g.left>=0&&g.right<=(window.innerWidth||document.documentElement.clientWidth)&&g.bottom<=(window.innerHeight||document.documentElement.clientHeight)||v.scroll({top:v.scrollHeight,left:0,behavior:"smooth"}),!1===f&&Vn(s)}_t(),Bi(),document.getElementById("frm-show-fields").classList.remove("frm-over-droppable"),function(e){var t=document.getElementById(e);null!=t&&t.dataset.limit&&$r(e)>=t.dataset.limit&&t.classList.add("frm_at_limit")}(c),a.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))}),a.querySelectorAll(".frm-dropdown-menu").forEach(function(e){return e.classList.add("dropdown-menu")});var y=new Event("frm_added_field",{bubbles:!1});y.frmField=a,y.frmSection=l,y.frmType=c,y.frmToggles=f,document.dispatchEvent(y)}function ft(e){if(e.dataset.fid){var t=document.getElementById("draft_fields");t&&(""===t.value?t.value=e.dataset.fid:t.value.split(",").includes(e.dataset.fid)||(t.value+=",".concat(e.dataset.fid)))}}function mt(e){jQuery("#new_fields .frm-single-settings").addClass("frm_hidden"),jQuery("#frm-options-panel > .frm-single-settings").removeClass("frm_hidden"),_t(e)}function _t(e){jQuery("li.ui-state-default.selected").removeClass("selected"),jQuery(".frm-show-field-settings.selected").removeClass("selected"),e||Dr()}function pt(){var e=this.value,t=function(e){var t,r=[],n=e.split(""),o=n.length,i=["{","[","("],a={"}":"{",")":"(","]":"["},l=!1;for(t=0;t<o;t++)i.includes(n[t])?r.push(n[t]):Object.hasOwn(a,n[t])&&r.pop()!==a[n[t]]&&(l=!0);return r.length>0||l?"".concat(f.unmatched_parens,"\n\n"):""}(e);t+=function(e,t){var r=function(e,t){var r="";return function(e){return jQuery(e).siblings('label[for^="calc_type"]').children("input").prop("checked")}(t)||/\[(date|time|email|ip)\]/.test(e)&&(r="".concat(f.text_shortcodes,"\n\n")),r}(e,t);return r+=function(e){var t="";return/\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g.test(e)&&(t+="".concat(f.view_shortcodes,"\n\n")),t}(e)}(e,this),""!==t&&K("".concat(e,"\n\n").concat(t))}function gt(e,t){for(var r=!1,n=0;n<t.length;n++){var o=document.getElementsByName(vt(t[n],e.fieldId));if(o.length&&jQuery(o[0]).val()){r=!0;break}}return r}function vt(e,t){var r=e.indexOf("]");return"field_options".concat(e.substring(0,r),"_").concat(t).concat(e.substring(r))}function yt(e,t){var r=jQuery(e).closest(".frm-single-settings"),n=r.find(".frm-calc-field");if(t||n.length&&""!==n.val()&&!n.is(":hidden")){var o,i=function(e){var t=jQuery(e).find(".frm_code_list");return 1===t.length&&t.hasClass("frm_js_summary_list")}(e),a=r.find('input[name="frm_fields_submitted[]"]').val(),l=(o=t?e:document.getElementById("frm-calc-box-".concat(a))).querySelector(".frm_code_list"),s=function(e,t){var r=JSON.parse(e.getAttribute("data-exclude"));if(t){var n=function(){for(var e=[],t=document.getElementsByClassName("frm_include_extras_field"),r=0;r<t.length;r++)t[r].checked&&e.push(t[r].value);return e}();if(n.length)for(var o=0;o<r.length;o++)n.includes(r[o])&&(r.splice(o,1),o--)}return r}(l,i),c=function(e){var t=[];if(!Array.isArray(e))return t;for(var r=0;r<e.length;r++)e[r].startsWith("[")&&(t.push(e[r]),e.splice(r,1),r--);return t}(s),d=wp.hooks.applyFilters("frm_calc_field_list",jt(),{box:o,codeList:l,isSummary:i}),u=document.getElementById("frm-calc-list-".concat(a));u.innerHTML="";for(var f=0;f<d.length;f++)null!=s&&s.includes(d[f].fieldType)||c.length&>(d[f],c)||(bt(u,a,d[f].fieldId,d[f].fieldName,d[f].fieldType),i||ht(d[f],a,u))}}function ht(e,t,r){wp.hooks.doAction("frm_add_calc_field_shortcodes",{field:e,fieldId:t,list:r,addCalcFieldLiToList:bt})}function bt(e,t,r,n,o){var i=w({className:"frm_insert_code",children:[b(n),b({className:"frm-text-sm frm-text-grey-500",text:"[".concat(r,"]")})],data:{code:r}});e.append(y("li",{className:"frm-field-list-".concat(t," frm-field-list-").concat(o),child:i}))}function wt(){yt(jQuery(".frm-inline-modal.postbox:has(.frm_js_summary_list)")[0],!0)}function jt(e){var t,r=[],n=document.querySelectorAll("li.frm_field_box"),o=void 0!==e;for(t=0;t<n.length;t++)if(!o||n[t].getAttribute("data-ftype")===e){var i=n[t].getAttribute("data-fid");i&&r.push({fieldId:i,fieldName:kt("frm_name_".concat(i)),fieldType:kt("field_options_type_".concat(i)),fieldKey:kt("field_options_field_key_".concat(i))})}return wp.hooks.applyFilters("frm_admin_get_field_list",r,e,n)}function xt(e){var t,r,n,o=[],i=function(e){for(var t=e.querySelectorAll('[type="checkbox"]:checked'),r=[],n=0;n<t.length;n++)r.push(t[n].value);return r}(e),a=e.getAttribute("data-frmfname"),l=jt("product"),s=jt("quantity"),c="SELECT"===e.tagName,d=1===s.length&&1===l.length;for(c&&(i=e.getAttribute("data-frmcurrent")),t=0;t<l.length;t++)n=l[t].fieldId.toString(),r=d||i.includes(n),c?(r=r?" selected":"",o.push('<option value="'.concat(n,'"').concat(r,">").concat(l[t].fieldName,"</option>"))):(r=r?" checked":"",o.push('<label class="frm6">'),o.push('<input type="checkbox" name="'.concat(a,'" value="').concat(n,'"').concat(r,"> ").concat(l[t].fieldName)),o.push("</label>"));e.innerHTML=o.join("")}function Et(){for(var e=document.querySelectorAll(".frmjs_prod_field_opt"),t=0;t<e.length;t++)xt(e[t])}function kt(e){var t=document.getElementById(e);return t?t.value:""}function Qt(){var e,t,r=this.value,o=document.getElementById(this.getAttribute("data-changeme")),i=this.getAttribute("data-changeatt");o&&(null!==i?"SELECT"===o.tagName&&"placeholder"===i?""===(e=o.options[0]).value?e.innerHTML=r:Bn(o,r):"class"===i?function(e,t){var r,o,i,a=" ".concat(t.value),l=e.getAttribute("data-fid");if(""===a.trim()){var s=t.querySelector("option[data-align]");a=s?" ".concat(s.getAttribute("data-align")):""}void 0!==l&&(t.classList.contains("field_options_align")?a+=" ".concat(document.getElementById("frm_classes_".concat(l)).value):t.classList.contains("frm_classes")&&(i=document.getElementById("field_options_align_".concat(l)))&&(a+=" ".concat(i.value))),a=(a+=" ").replace(" block "," vertical_radio ").replace(" inline "," horizontal_radio "),""===(r=0===(r=e.className.split(" frmstart ")[1]).indexOf("frmend ")?"":r.split(" frmend ")[0]).trim()?(o=" frmstart frmend ",e.className.includes(o)||(o=" frmstart frmend "),a=" frmstart ".concat(a.trim()," frmend ")):(o=r.trim(),a=a.trim());var c=e.classList.contains("frm_first");e.className=e.className.replace(o,a),!c&&e.classList.contains("frm_first")&&function(e){var t=e.parentElement;if(t&&"UL"===t.nodeName&&!t.classList.contains("start_divider")){var r=t.parentElement;if(r&&De(r)&&!(be(jQuery(t)).get().indexOf(e)<1)){var o=y("ul",{className:"frm_grid_container frm_sorting"}),i=y("li",{className:"frm_field_box",child:o});r.after(i),o.append.apply(o,n(function(e){for(var t=[],r=e;r;)"LI"===r.nodeName&&t.push(r),r=r.nextElementSibling;return t}(e))),le(o),de(i,".frm-move"),je(jQuery(t),be(jQuery(t)).length)}}}(e)}(o,this):"range"===(t=o).type&&t.parentNode.classList.contains("frm_range_container")?function(e,t,r){if(frmGlobal.proIncludesSliderJs){var n={field:e,att:t,newValue:r};wp.hooks.doAction("frm_update_slider_field_preview",n)}else{var o;if("value"===t?(""===r&&(r=St(e)),e.value=r):e.setAttribute(t,r),["value","min","max"].includes(t))"max"!==t&&"min"!==t||""!==(o=e.id,document.querySelector('input[data-changeme="'.concat(o,'"][data-changeatt="value"]')).value)||(e.value=St(e)),e.parentNode.querySelector(".frm_range_value").textContent=e.value}}(o,i,r):o.setAttribute(i,r):0===o.id.indexOf("setup-message")?""!==r&&(o.innerHTML='<input type="text" value="" disabled />'):(o.innerHTML=Tn(r),"TEXTAREA"===o.nodeName&&o.classList.contains("wp-editor-area")&&jQuery(o).trigger("change"),o.classList.contains("frm_primary_label")&&"break"===o.nextElementSibling.getAttribute("data-ftype")&&(o.nextElementSibling.querySelector(".frm_button_submit").textContent=r)))}function St(e){var t=parseFloat(e.getAttribute("max")),r=parseFloat(e.getAttribute("min"));return(t-r)/2+r}function At(){var e=this.getAttribute("data-fid"),t="";["field_options_max_","frm_format_"].forEach(function(r){var n=document.getElementById(r+e);n&&(t+=n.value)});var r=document.getElementsByName("field_options[type_".concat(e,"]"))[0];"text"===r.options[r.selectedIndex].value&&It(""!==t,".frm_invalid_msg".concat(e))}function Lt(){var e=this.id.replace("frm_","").replace("req_field_",""),t=this.checked,r=jQuery("#field_label_".concat(e," .frm_required"));if(It(t,".frm_required_details".concat(e)),t){var n=jQuery('input[name="field_options[required_indicator_'.concat(e,']"]'));""===n.val()&&n.val("*"),r.removeClass("frm_hidden")}else r.addClass("frm_hidden")}function It(e,t){var r=jQuery(t);if(e)r.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");else{var n=r.fadeOut("fast").closest(".frm_validation_box"),o=n.css("display","block").children(":not(".concat(t,"):visible")).length;n.css("display",""),0===o&&r.closest(".frm_validation_msg").fadeOut("fast")}}function qt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(".frm_unique_details".concat(e));if(this.checked){t.fadeIn("fast").closest(".frm_validation_msg").fadeIn("fast");var r=jQuery(".frm_unique_details".concat(e," input"));""===r.val()&&r.val(f.default_unique)}else{var n=t.fadeOut("fast").closest(".frm_validation_box"),o=n.css("display","block").children(":not(.frm_unique_details".concat(e,"):visible")).length;n.css("display",""),0===o&&t.closest(".frm_validation_msg").fadeOut("fast")}}function Bt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=jQuery(this).val(),r=jQuery(document.getElementById("frm_field_id_".concat(e)));if(It(""!==t,".frm_conf_details".concat(e)),""!==t){var n=jQuery(".frm_validation_box .frm_conf_details".concat(e," input"));""===n.val()&&n.val(f.default_conf),function(e){var t=document.getElementsByName("field_options[type_".concat(e,"]"))[0].value;Ct(document.getElementById("field_description_".concat(e)),"field_options[description_".concat(e,"]"),f["enter_".concat(t)]),Ct(document.getElementById("conf_field_description_".concat(e)),"field_options[conf_desc_".concat(e,"]"),f["confirm_".concat(t)])}(e),"inline"===t?r.removeClass("frm_conf_below").addClass("frm_conf_inline"):"below"===t&&r.removeClass("frm_conf_inline").addClass("frm_conf_below"),jQuery(".frm-conf-box-".concat(e)).removeClass("frm_hidden")}else jQuery(".frm-conf-box-".concat(e)).addClass("frm_hidden"),setTimeout(function(){r.removeClass("frm_conf_inline frm_conf_below")},200)}function Ct(e,t,r){e.innerHTML===f.desc&&(e.innerHTML=r,document.getElementsByName(t)[0].value=r)}function Nt(e){var t=JSON.parse(this.getAttribute("data-opts"));return e.preventDefault(),document.getElementById("frm_bulk_options").value=t.join("\n"),!1}function Tt(){var e,t,r,n=jQuery(this).closest(".frm-single-settings").data("fid"),o=jQuery("#frm_field_".concat(n,"_opts .frm_option_template")).prop("outerHTML"),i=jQuery(this).data("opttype"),a=0,l="000",s=function(e){for(var t=0,r=0,n=jQuery("#frm_field_".concat(e,"_opts li")),o=0;t<n.length;t++){if(r=n[t].getAttribute("data-optkey"),1===n.length)return r;"000"!==r&&(r=r.replace("other_",""),r=parseInt(r,10)),!isNaN(o)&&(r>o||"000"===o)&&(o=r)}return o}(n);if(s!==l&&(a=s+1),"other"===i){document.getElementById("other_input_".concat(n)).value=1;var c=jQuery(this).data("ftype");"radio"!==c&&"select"!==c||jQuery(this).fadeOut("slow");var d={action:"frm_add_field_option",field_id:n,opt_key:a,opt_type:i,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,d,function(e){jQuery(document.getElementById("frm_field_".concat(n,"_opts"))).append(e),Qn(n)})}else{o=(o=(o=(o=(o=o.replace(new RegExp('optkey="'.concat(l,'"'),"g"),'optkey="'.concat(a,'"'))).replace(new RegExp("-".concat(l,"_"),"g"),"-".concat(a,"_"))).replace(new RegExp("-".concat(l,'"'),"g"),"-".concat(a,'"'))).replace(new RegExp("\\[".concat(l,"\\]"),"g"),"[".concat(a,"]"))).replace("frm_hidden frm_option_template",""),sa(n,o={newOption:o});var u=this.closest(".frm_single_option");u?u.after(o.newOption):jQuery("#frm_field_".concat(n,"_opts")).append(o.newOption),Qn(n)}null==(r=(e=this).classList.contains("frm-add-option-legacy")?null===(t=e.closest(".frm-collapse-me"))||void 0===t?void 0:t.querySelector(".frm_sortable_field_opts"):e.closest(".frm_sortable_field_opts"))||r.querySelectorAll(".frm_remove_tag.frm_disabled").forEach(function(e){return e.classList.remove("frm_disabled")}),ci()}function Ot(){Ft(jQuery(this).closest(".frm-single-settings").data("fid"),this.value)}function Ft(e,t){var r=jQuery(".frm_multiple_cont_".concat(e));"select"===t?r.fadeIn("fast"):r.fadeOut("fast")}function Dt(){var e=jQuery(this).closest(".frm-single-settings").data("fid");ta(jQuery(".field_".concat(e,"_option_key")),"",this.checked),jQuery(".field_".concat(e,"_option")).toggleClass("frm_with_key")}function Mt(){var e=jQuery(this).closest(".frm-single-settings"),t=e.data("fid"),r=document.getElementById("frm_field_id_".concat(t));Ht(jQuery(this));var n=Mn(t);if(ta(jQuery(".field_".concat(t,"_image_id")),"",n),ta(jQuery(".frm_toggle_image_options_".concat(t)),"",n),ta(jQuery(".frm_image_size_".concat(t)),"",n),ta(jQuery(".frm_alignment_".concat(t)),"",n),ta(jQuery(".frm-add-other#frm_add_field_".concat(t)),"",n),Pt(r),n){Rt(t,"inline");var o=kn(t);r.classList.add("frm_image_options"),r.classList.add("frm_image_size_".concat(o)),e.find(".frm-bulk-edit-link").hide()}else r.classList.remove("frm_image_options"),Rt(t,"block"),e.find(".frm-bulk-edit-link").show();wp.hooks.doAction("frm_image_options_toggled",e[0],n)}function Pt(e){e.classList.remove("frm_image_size_","frm_image_size_small","frm_image_size_medium","frm_image_size_large","frm_image_size_xlarge")}function Rt(e,t){jQuery("#field_options_align_".concat(e)).val(t).trigger("change")}function zt(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));Gt(),Mn(e)&&(Pt(t),t.classList.add("frm_image_options"),t.classList.add("frm_image_size_".concat(kn(e))))}function Ht(e){var t=e.closest(".frm-single-settings").data("fid");jQuery(".field_".concat(t,"_option")).trigger("change")}function Gt(){Ht(jQuery(this))}function Ut(e){var t,r=e.target.closest(".frm_image_preview_wrapper");if(null!==(t=wp)&&void 0!==t&&t.media&&(null==r||!r.dataset.upgrade)){e.preventDefault(),wp.media.model.settings.post.id=0;var n=wp.media.frames.file_frame=wp.media({multiple:!1,library:{type:["image"]}});n.on("select",function(){var e=n.state().get("selection").first().toJSON(),t=r.querySelector("img");t.setAttribute("src",e.url),t.classList.remove("frm_hidden"),t.removeAttribute("srcset"),r.querySelector(".frm_image_preview_frame").style.display="block",r.querySelector(".frm_image_preview_title").textContent=e.filename,r.querySelector(".frm_choose_image_box").style.display="none";var o=jQuery(r);o.siblings('input[name*="[label]"]').data("frmimgurl",e.url),o.find("input.frm_image_id").val(e.id).trigger("change"),wp.media.model.settings.post.id=0}),n.open()}}function Wt(e){var t=jQuery(this).closest(".frm_image_preview_wrapper");e.preventDefault(),e.stopPropagation(),t.find("img").attr("src",""),t.find(".frm_image_preview_frame").hide(),t.find(".frm_choose_image_box").show(),t.find("input.frm_image_id").val(0).trigger("change")}function $t(){var e=jQuery(this).closest("li").find(".frm_form_fields select");this.checked?e.attr("multiple","multiple"):e.removeAttr("multiple")}function Vt(){var e=document.getElementById("dropform-search-input");e&&setTimeout(function(){e.focus()},100)}function Kt(e){var t=e.target,r=t.closest(".frm_warning_style");jQuery(r).fadeOut(400,function(){return r.remove()});var n=t.dataset.action,o=new FormData;k(n,o)}function Jt(e){e.preventDefault()}function Xt(){var e,t,r=this.parentNode,n=r.parentNode,o=n.querySelectorAll("li:not(.frm_hidden)");2===o.length&&(null===(e=Array.from(o).find(function(e){return e!==r}).querySelector(".frm_remove_tag"))||void 0===e||e.classList.add("frm_disabled"));var i=this.getAttribute("data-fid");jQuery(r).fadeOut("fast",function(){wp.hooks.doAction("frm_before_delete_field_option",this),jQuery(r).remove(),jQuery(n).find(".frm_other_option").length<1&&((t=document.getElementById("other_input_".concat(i)))&&(t.value=0),jQuery("#other_button_".concat(i)).fadeIn("fast"))}),ci()}function Yt(){var e=jQuery(this);if(e.is(":checked")){var t,r=function(){e.off("mouseup",t)};t=function(){setTimeout(function(){e.prop("checked",!1)},0),r()},e.on("mouseup",t),e.one("mouseout",r)}}function Zt(){this.value===f.new_option&&(this.setAttribute("data-value-on-focus",this.value),this.value="")}function er(e){return R(P("Are you sure you want to delete these %1$s selected field(s)?","formidable"),e)}function tr(){var e=f.conf_delete,t=this.parentNode.parentNode.parentNode.parentNode.parentNode,r=t.parentNode,n=jQuery(this).closest("li.form-field"),o=n.data("fid");if("divider"===n.data("ftype")){var i=document.querySelectorAll(".frm-field-group-hover-target .start_divider .frm_field_box"),a=0;i.forEach(function(e){var t=e.querySelectorAll("li.form-field");t&&(a+=t.length)}),a&&(e=er(++a))}return r.classList.contains("frm-section-collapsed")||r.classList.contains("frm-page-collapsed")||("divider_section_only"===t.className&&(e=f.conf_delete_sec),this.setAttribute("data-frmverify",e),this.setAttribute("data-frmverify-btn","frm-button-red"),this.setAttribute("data-deletefield",o),Ze(),V(this)),!1}function rr(){this.closest("li.form-field").click()}function nr(){var e=document.querySelector(".frm-field-group-hover-target");if(e){e.classList.add("frm-selected-field-group");var t=document.createElement("div");t.classList.add("frm-delete-field-groups","frm_hidden"),document.body.append(t),t.click()}}function or(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t="frm_field_group_".concat(Te()),r=document.createTextNode("");dt(r);var n=jQuery(r).closest("li").get(0);n.classList.add("frm_hidden");var o=n.querySelector("ul");o.id=t,jQuery(e.closest("li.frm_field_box")).after(n);var i=be(jQuery(e)),a=[],l=[],s=i.length,c={},d=0;jQuery(n).on("frm_added_duplicated_field_to_row",function(e,t){if(c[jQuery(t.duplicatedFieldHtml).attr("data-fid")]=t.originalFieldId,!(s>++d)){var r=jQuery(o),i=be(r);l.forEach(function(e){e.remove()});for(var u=0;u<s;++u)r.append(r.children('li.form-field[frm-field-order="'.concat(u,'"]')));we(i.first(),a),n.classList.remove("frm_hidden"),Wn(),be(r).each(function(){Ye(c[this.getAttribute("data-fid")],jQuery(this).prop("outerHTML"))})}}),i.each(function(e){var r=document.createElement("li");r.classList.add("frm_clone_field"),r.setAttribute("frm-target-row-id",t),r.setAttribute("frm-field-order",e),this.append(r),r.click(),l.push(r),a.push(Qr(Sr(this.classList)))})}}function ir(){var e=document.querySelector(".frm-field-group-hover-target");if(e){_t();var t=lr(e.querySelector("li.form-field"));e.classList.add("frm-has-open-field-group-popup"),jQuery(document).on("click","#frm_builder_page",ar);var r=h();r.style.position="relative",r.append(sr(t,this)),this.parentNode.append(r);var n=r.querySelector(".frm-row-layout-option");n&&n.focus()}}function ar(e){e.target.classList.contains("frm-custom-field-group-layout")||e.target.classList.contains("frm-cancel-custom-field-group-layout")||jQuery(e.target).closest("#frm_field_group_controls").length||jQuery(e.target).closest("#frm_field_group_popup").length||Br()}function lr(e){var t=jQuery(e).closest("ul");return t.length?be(t).length:zr()}function sr(e,t){var r=document.getElementById("frm_field_group_popup");r?r.innerHTML="":r=h(),r.id="frm_field_group_popup";var n,o=h();o.style.padding="0 24px 12px",o.append(((n=h()).classList.add("frm-row-layout-title"),n.textContent=P("Row Layout","formidable"),n));var i,a=function(e){var t=yr();if(e>6)return t.append(ur(e,"even")),t;if(5!==e&&t.append(ur(e,"even")),e%2==1&&t.append(ur(e,"middle")),e<6)t.append(ur(e,"left")),t.append(ur(e,"right"));else{var r=h();r.classList.add("frm_fourth"),t.prepend(r)}return t}(e),l=t.closest("ul.frm_sorting");return l&&function(e,t){for(var r=t.children.length,n=0;n<r;++n){var o=t.children[n];if(fr(o,e))return void o.classList.add("frm-active-row-layout")}}(l,a),o.append(a),r.append(o),r.append(document.createElement("hr")),e<=6&&r.append(((i=h()).textContent=P("Custom layout","formidable"),jQuery(i).prepend(dr("frm_gear_svg")),i.classList.add("frm-custom-field-group-layout"),cr(i),i)),r.append(function(){var e=h();return e.textContent=P("Break into rows","formidable"),jQuery(e).prepend(dr("frm_break_field_group_svg")),e.classList.add("frm-break-field-group"),cr(e),e}()),r}function cr(e,t){e.setAttribute("tabindex",0),e.setAttribute("role","button"),void 0!==t&&e.setAttribute("aria-label",t)}function dr(e){var t=document.getElementById(e).cloneNode(!0);return t.id="",t}function ur(e,t){var r,n=h();switch(n.classList.add("frm-row-layout-option"),cr(n,t),e){case 6:r="frm_half";break;case 5:r="frm_third";break;default:r=e>6?"frm_full":e%2==1?"frm_fourth":"frm_third"}return n.classList.add(r),n.setAttribute("layout-type",t),n.append(function(e,t){for(var r=yr(),n=0;n<e;++n){var o=h();o.classList.add(_r(e,t,n)),o.style.height="16px",o.style.background="#9EA9B8",o.style.borderRadius="1px",r.append(o)}return r}(e,t)),n}function fr(e,t){return mr(e)===mr(t)}function mr(e){var t;t=e.classList.contains("frm-row-layout-option")?jQuery(e).find(".frm_grid_container").children():be(jQuery(e));var r=[];return t.each(function(){r.push(Qr(Sr(this.classList)))}),r.join("-")}function _r(e,t,r){if("even"===t)return pr(e,r);if("middle"===t){if(3===e)return 1===r?"frm6":"frm3";if(5===e)return 2===r?"frm4":"frm2"}else{if("left"===t)return 0===r?vr(e):gr(e);if("right"===t)return r===e-1?vr(e):gr(e)}return"frm12"}function pr(e,t){return e>6?"frm1":[2,3,4,6].includes(e)?Ar(12/e):5===e&&void 0!==t?0===t?"frm4":"frm2":"frm12"}function gr(e){switch(e){case 2:case 3:return"frm3";case 4:case 5:return"frm2";case 6:return"frm1";default:return"frm12"}}function vr(e){switch(e){case 2:return"frm9";case 3:case 4:return"frm6";case 5:return"frm4";case 6:return"frm7";default:return"frm12"}}function yr(){var e=h();return e.classList.add("frm_grid_container"),e}function hr(){var e=document.querySelector(".frm-field-group-hover-target");if(e){var t=this.getAttribute("layout-type");we(be(jQuery(e)).first(),t),Br()}}function br(){var e=wr(),t=this.getAttribute("layout-type");we(be(e).first(),t),Dr()}function wr(){var e=jQuery(".frm-selected-field-group"),t=e.first();return e.not(t).each(function(){be(jQuery(this)).each(function(){var e=this.parentNode;be(t).last().after(this),jQuery(e).children("li.form-field").length||e.closest("li.frm_field_box").remove()})}),Wn(),we(be(t).first()),t}function jr(){null===this.closest(".frm-merge-fields-into-row")&&xr(be(jQuery(".frm-field-group-hover-target")))}function xr(e){var t=e.length,r=document.getElementById("frm_field_group_popup");r.innerHTML="";var n=h();n.style.padding="0 24px";var o=pr(5===t?6:t),i=h();if(i.style.padding="20px 0",i.classList.add("frm_grid_container"),5===t){var a=document.createElement("span");a.classList.add("frm1"),i.append(a)}var l=zr()>0&&Qr(pr(t));!1!==l&&l>=12&&(l=Math.floor(12/t));for(var s=0;s<t;++s){var c=document.createElement("input");c.type="text",c.classList.add(o),c.classList.add("frm-custom-grid-size-input"),c.value=!1!==l?l:Qr(Sr(e.get(s).classList)),i.append(c)}var d=h();d.classList.add("frm-builder-popup-heading"),d.textContent=P("Enter number of columns for each field","formidable");var u=h();u.classList.add("frm-builder-popup-subheading"),u.textContent=P("Layouts are based on a 12-column grid system","formidable"),n.append(d),n.append(u),n.append(i);var f=h();f.style.textAlign="right";var m,_=((m=kr()).classList.add("button-secondary","frm-button-secondary"),m);_.textContent=P("Cancel","formidable"),_.classList.add("frm-cancel-custom-field-group-layout"),_.style.marginRight="10px";var p=function(){var e=kr();return e.classList.add("button-primary","frm-button-primary"),e}();p.textContent=P("Save","formidable"),p.classList.add("frm-save-custom-field-group-layout"),f.append(_),f.append(p),n.append(f),r.append(n),setTimeout(function(){var e=r.querySelector("input.frm-custom-grid-size-input").focus();e&&e.focus()},0)}function Er(){xr(jQuery(".frm-selected-field-group li.form-field"))}function kr(){var e=document.createElement("a");return e.setAttribute("href","#"),e.classList.add("button"),e.style.textDecoration="none",e}function Qr(e){switch(e){case"frm_half":return 6;case"frm_third":return 4;case"frm_two_thirds":return 8;case"frm_fourth":return 3;case"frm_three_fourths":return 9;case"frm_sixth":return 2;default:return 0===e.indexOf("frm")?parseInt(e.substr(3)):12}}function Sr(e){for(var t=["frm_full","frm_half","frm_third","frm_fourth","frm_sixth","frm_two_thirds","frm_three_fourths","frm1","frm2","frm3","frm4","frm5","frm6","frm7","frm8","frm9","frm10","frm11","frm12"],r=0;r<t.length;++r){var n=t[r];if(e.contains(n))return n}return""}function Ar(e){return"frm".concat(e)}function Lr(){var e,t;e=document.querySelector(".frm-field-group-hover-target"),be(t=jQuery(e)).each(function(e){0!==e&&t.parent().after(ct(this)),function(e){we(e,"clear")}(jQuery(this))}),Br()}function Ir(){this.select()}function qr(){jQuery(document.getElementById("frm_field_group_popup")).replaceWith(sr(lr(this),this))}function Br(){var e=document.getElementById("frm_field_group_popup");if(e){var t=document.querySelector(".frm-has-open-field-group-popup");t&&(t.classList.remove("frm-has-open-field-group-popup"),e.parentNode.remove()),jQuery(document).off("click","#frm_builder_page",ar)}}function Cr(){var e=[];jQuery(document.getElementById("frm_field_group_popup").querySelectorAll(".frm_grid_container input")).each(function(){e.push(parseInt(this.value))});var t=jQuery(document.getElementById("frm_field_group_controls"));t.length&&"none"!==t.get(0).style.display?we(be(jQuery(document.querySelector(".frm-field-group-hover-target"))).first(),e):(we(be(wr()).first(),e),Dr()),Br()}function Nr(e){if(function(){var e=document.getElementById("frm-field-group-message");if(document.querySelectorAll(".edit_form_item:not(.edit_field_type_end_divider)").length<2)Tr(e);else if(e)!function(e){e&&(e.classList.remove("frm_hidden"),e.classList.add("frm-fadein-up-back"))}(e);else{e=h({id:"frm-field-group-message",className:"frm-flex-center frm-fadein-up-back",children:[b({id:"frm-field-group-message-dismiss",className:"frm-flex-center",child:j({href:"#frm_close_icon"})})]}),document.getElementById("post-body-content").append(e);var t,r=((t=document.createElement("span")).classList.add("frm-field-group-message-text","frm-flex-center"),t.innerHTML=R(frm_admin_js.holdShiftMsg,'<span class="frm-meta-tag frm-flex-center"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-shift" viewBox="0 0 16 16"><path d="M7.3 2a1 1 0 0 1 1.4 0l6.4 6.8a1 1 0 0 1-.8 1.7h-2.8v3a1 1 0 0 1-1 1h-5a1 1 0 0 1-1-1v-3H1.7a1 1 0 0 1-.8-1.7L7.3 2zm7 7.5L8 2.7 1.7 9.5h2.8a1 1 0 0 1 1 1v3h5v-3a1 1 0 0 1 1-1h2.8z"/></svg>',"</span>"),t);e.prepend(r),document.getElementById("frm-field-group-message-dismiss").addEventListener("click",function(){Tr(document.getElementById("frm-field-group-message"))})}}(),"ul"===e.originalEvent.target.nodeName.toLowerCase()){var t=document.querySelector(".frm-field-group-hover-target");if(t){var r=e.ctrlKey||e.metaKey,n=e.shiftKey,o=t.classList.contains("frm-selected-field-group"),i=function(){var e=jQuery(".frm-selected-field-group");if(e.length)return e;var t=Or();if(t){var r=t.closest("ul");if(r&&1===be(jQuery(r)).length)return r.classList.add("frm-selected-field-group"),jQuery(r)}return jQuery()}(),a=i.length;if(r||n){var l=Or();if(null===l||jQuery(l).siblings("li.form-field").length||(l.parentNode.classList.add("frm-selected-field-group"),++a),r){if(o)return--a,t.classList.remove("frm-selected-field-group"),void Fr(a);++a}else if(n&&!o){++a;var s=i.first();(s.parent().index()<jQuery(t.parentNode).index()?s.parent().nextUntil(t.parentNode):s.parent().prevUntil(t.parentNode)).each(function(){var e=jQuery(this).closest("li").find("ul.frm_sorting");e.hasClass("frm-selected-field-group")||(++a,e.addClass("frm-selected-field-group"))})}}else Dr(),a=1;t.classList.add("frm-selected-field-group"),Fr(a),document.querySelectorAll(".frm-selected-field-group").length<2||Tr(document.getElementById("frm-field-group-message")),jQuery(document).off("click",Dr),jQuery(document).on("click",Dr)}}}function Tr(e){e&&(e.classList.add("frm_hidden"),e.classList.remove("frm-fadein-up-back"))}function Or(){return document.getElementById("frm-show-fields").querySelector("li.form-field.selected")}function Fr(e){mt(!0),e>=2||1===e&&be(jQuery(document.querySelector(".frm-selected-field-group"))).length>1?function(){var e=document.getElementById("frm_field_multiselect_popup");if(e)return e.classList.toggle("frm-unmergable",!Pr()),e;(e=h()).id="frm_field_multiselect_popup",Pr()||e.classList.add("frm-unmergable");var t=h();t.classList.add("frm-merge-fields-into-row"),t.textContent=P("Merge into row","formidable");var r=document.createElement("a");r.style.marginLeft="5px",r.classList.add("frm_icon_font","frm_arrowdown6_icon"),r.setAttribute("href","#"),t.append(r),e.append(t);var n=h();n.classList.add("frm-multiselect-popup-separator"),e.append(n);var o=h();o.classList.add("frm-delete-field-groups"),o.append(dr("frm_trash_svg")),e.append(o),document.getElementById("post-body-content").append(e),jQuery(e).hide().fadeIn()}():Mr(),rt()}function Dr(e){if(void 0!==e){if(null!==e.originalEvent.target.closest("#frm-show-fields"))return;if(e.originalEvent.target.classList.contains("frm-merge-fields-into-row"))return;if(null!==e.originalEvent.target.closest(".frm-merge-fields-into-row"))return;if(e.originalEvent.target.classList.contains("frm-custom-field-group-layout"))return;if(e.originalEvent.target.classList.contains("frm-cancel-custom-field-group-layout"))return}jQuery(".frm-selected-field-group").removeClass("frm-selected-field-group"),jQuery(document).off("click",Dr),Mr()}function Mr(){var e=document.getElementById("frm_field_multiselect_popup");e&&e.remove()}function Pr(){var e=document.querySelectorAll(".frm-selected-field-group"),t=e.length;if(1===t)return!1;for(var r=0,n=0;n<t;++n){var o=e[n];if(null!==o.querySelector(".edit_field_type_break, .edit_field_type_hidden"))return!1;if((r+=be(jQuery(o)).length)>12)return!1}return!0}function Rr(e){if(null===e.originalEvent.target.closest("#frm_field_group_popup")&&!e.originalEvent.target.classList.contains("frm-custom-field-group-layout")){var t=sr(zr(),document.querySelector(".frm-selected-field-group").firstChild);this.append(t)}}function zr(){var e=0;return jQuery(document.querySelectorAll(".frm-selected-field-group")).each(function(){e+=be(jQuery(this)).length}),e}function Hr(){var e,t=(e=[],jQuery(".frm-selected-field-group > li.form-field").each(function(){e.push(this.dataset.fid)}),e),r=function(e){return function(t){t.preventDefault(),function(e){e.forEach(function(e){Ur(e)})}(e)}}(t),n=document.getElementById("frm_field_multiselect_popup");n&&n.remove(),this.setAttribute("data-frmverify",er(t.length)),V(this);var o=document.getElementById("frm-confirmed-click");null==o||o.removeAttribute("data-deletefield"),jQuery(o).on("click",r),jQuery("#frm_confirm_modal").one("dialogclose",function(){jQuery(o).off("click",r)})}function Gr(){Ur(this.getAttribute("data-deletefield"))}function Ur(e){var t=jQuery("#frm_field_id_".concat(e));Wr(e),t.hasClass("edit_field_type_divider")&&t.find("li.frm_field_box[data-fid]").each(function(){Wr(this.getAttribute("data-fid"))}),$n()}function Wr(e){jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_delete_field",field_id:e,nonce:frmGlobal.nonce},success:function(){var t,r,n,o=jQuery(document.getElementById("frm_field_id_".concat(e))),i=jQuery("#frm-single-settings-".concat(e));i.is(":visible")&&(null===(t=document.querySelector(".frm-settings-panel .frm-tabs-navs ul > li:first-child"))||void 0===t||t.click(),document.querySelector("#frm-options-panel .frm-single-settings").classList.remove("frm_hidden")),function(e){var t=e[0].querySelectorAll(".frm-inline-modal[data-fills]");t.length&&t.forEach(function(e){e.classList.add("frm_hidden"),e.removeAttribute("data-fills"),e.closest("form").append(e)})}(i),i.remove(),o.fadeOut("slow",function(){var e,t=o.closest(".start_divider"),r=o.data("type"),n=o.siblings("li.form-field");if(n.length||(o.is(".edit_field_type_end_divider")?n.length=o.closest("li.form-field").siblings():e=o.closest("ul.frm_sorting").parent()),o.remove(),"break"===r?on():"product"===r&&(Ke(),Et()),n.length?we(n.first()):e.remove(),0===jQuery("#frm-show-fields li").length||function(){if(I.get(0).childElementCount>1)return!1;var e=I.get(0).firstElementChild.firstElementChild.querySelectorAll("li.frm_field_box");return!(e.length>1)&&e[0].classList.contains("edit_field_type_submit")}()){var i=document.getElementById("frm_form_editor_container");i.classList.remove("frm-has-fields"),i.classList.add("frm-empty-fields")}else t.length&&Vn(t);Y()}),o.length&&(r=o.data("type"),(n=document.getElementById(r))&&n.dataset.limit&&$r(r)-1<n.dataset.limit&&n.classList.remove("frm_at_limit"),wp.hooks.doAction("frm_after_delete_field",o[0]))}})}function $r(e){return document.getElementById("frm-show-fields").querySelectorAll('li.form-field[data-ftype="'.concat(e,'"]')).length}function Vr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=T,r=document.getElementById("frm_logic_row_".concat(e)).querySelectorAll(".frm_logic_row");return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_logic_row",form_id:t,field_id:e,nonce:frmGlobal.nonce,meta_name:Kr(r,"frm_logic_".concat(e,"_")),fields:jt()},success:function(t){jQuery(document.getElementById("logic_".concat(e))).fadeOut("fast",function(){var r=document.getElementById("frm_logic_row_".concat(e));r.insertAdjacentHTML("beforeend",t);var n=r.querySelector(".frm_logic_row:last-child .frm-logic-rule-text");n&&(n.textContent=r.dataset.ruleText);var o=r.closest(".frm_logic_rows");o.style.height="auto",jQuery(o).fadeIn("fast")})}}),!1}function Kr(e,t,r){return e.length?parseInt(e[e.length-1].id.replace(t,""),10)+1:void 0!==r?r:0}function Jr(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=T,r=document.getElementById("frm_watch_lookup_block_".concat(e)).children;return jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_watch_lookup_row",form_id:t,field_id:e,row_key:Kr(r,"frm_watch_lookup_".concat(e,"_")),nonce:frmGlobal.nonce},success:function(t){var r,n=jQuery(document.getElementById("frm_watch_lookup_block_".concat(e)));n.append(t),n.fadeIn("slow"),null===(r=document.getElementById("frm_watch_lookup_label_".concat(e)))||void 0===r||r.classList.remove("frm-force-hidden")}}),!1}function Xr(e){var t,r,n=jQuery(e).closest(".frm-single-settings").attr("data-fid"),o=jQuery(e).closest("ul").get(0).querySelectorAll(".field_".concat(n,"_option"));for(t in o)if(Object.hasOwn(o,t)&&(r=o[t]).id!==e.id&&r.value===e.value&&"true"!==r.getAttribute("data-duplicate"))return!0;return!1}function Yr(){var e,t;null===this.getAttribute("data-value-on-load")&&(this.setAttribute("data-value-on-load",this.value),t=jQuery(this).closest(".frm-single-settings").attr("data-fid"),(e=document.createElement("input")).value=this.value,e.setAttribute("type","hidden"),e.setAttribute("name","optionmap[".concat(t,"][").concat(this.value,"]")),this.parentNode.append(e),void 0===F[t]&&(F[t]={}),F[t][this.value]=e),"true"===this.getAttribute("data-duplicate")&&(this.removeAttribute("data-duplicate"),Xr(this))?this.setAttribute("data-value-on-focus",this.getAttribute("data-value-on-load")):""===this.value&&f.new_option===this.getAttribute("data-value-on-focus")||this.setAttribute("data-value-on-focus",this.value)}function Zr(e){var t,r=e.closest(".frm_single_option");return e.parentElement.classList.contains("frm_single_option")?{newValue:r.querySelector('.frm_option_key input[type="text"]').value,newLabel:t=e.value}:(t=r.querySelector('input[type="text"]').value,{newValue:e.value,newLabel:t})}function en(){var e,t,r=function(e){var t=function(e){var t,r,n=null!==(t=null===(r=e.closest(".frm-single-settings").querySelector(".frm_toggle_sep_values"))||void 0===r?void 0:r.checked)&&void 0!==t&&t,o=e.closest(".frm_single_option");return n&&e.parentElement.classList.contains("frm_single_option")?{oldValue:o.querySelector('.frm_option_key input[type="text"]').getAttribute("data-value-on-focus"),oldLabel:e.getAttribute("data-value-on-focus")}:{oldValue:e.getAttribute("data-value-on-focus"),oldLabel:o.querySelector('input[type="text"]').getAttribute("data-value-on-focus")}}(e),r=t.oldValue,n=t.oldLabel,o=Zr(e);return{oldValue:r,oldLabel:n,newValue:o.newValue,newLabel:o.newLabel}}(this),n=r.oldValue,o=r.oldLabel,i=r.newValue,a=r.newLabel;if(n!==i||o!==a){var l=this.closest(".frm-single-settings"),s=l.getAttribute("data-fid"),c=this.getAttribute("data-value-on-load");if(Xr(this))return this.setAttribute("data-duplicate","true"),void(void 0!==F[s]&&void 0!==F[s][c]&&(F[s][c].value=c));void 0!==F[s]&&void 0!==F[s][c]&&(F[s][c].value=i);for(var d=[],u=W.querySelectorAll(".frm_logic_row"),f=u.length,m=0;m<f;m++){var _=u[m];if(_.querySelector(".frm_logic_field_opts").value===s){var p,g=_.id.split("_")[2],v=_.querySelector('select[name="field_options[hide_opt_'.concat(g,'][]"]')),y=void 0,h=void 0;(y=""===n?[]:v.querySelectorAll('option[value="'.concat(n,'"]'))).length||(y=v.querySelectorAll('option[value="'.concat(i,'"]'))).length||(null!==(p=l.querySelector(".frm_toggle_sep_values"))&&void 0!==p&&p.checked||(h=tn(v,n)),h||(h=document.createElement("option"),v.append(h))),y.length&&(h=y[y.length-1]),h.setAttribute("value",i),h.textContent=a,d.includes(g)||d.push(g)}}for(e in d)Object.hasOwn(d,e)&&(t=d[e],Qo(document.getElementById("frm-single-settings-".concat(t))))}}function tn(e,t){for(var r=e.options,n=0;n<r.length;n++){var o=r[n];if(t===o.textContent)return o}return null}function rn(){var e=this.id.replace("get_values_form_",""),t=document.getElementById("get_values_field_".concat(e)),r=this.getAttribute("data-fieldtype");if(""===this.value)t.options.length=1;else{var n=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_options_for_get_values_field",form_id:n,field_type:r,nonce:frmGlobal.nonce},success:function(e){t.innerHTML=e}})}}function nn(){var e,t,r=this.name.replace("field_options[data_type_","").replace("]","");(e=document.getElementById("frm_add_watch_lookup_link_".concat(r)))&&(e=e.parentNode,"text"===this.value?(t=document.getElementById("frm_watch_lookup_block_".concat(r)))&&(t.innerHTML="",e.classList.add("frm_hidden"),e.previousElementSibling.style.display="none",e.previousElementSibling.previousElementSibling.style.display="none",e.previousElementSibling.previousElementSibling.previousElementSibling.style.display="none"):e.classList.remove("frm_hidden"),Ft(r,this.value))}function on(){var e,t,r=document.getElementsByClassName("frm-page-num");if(r.length>1)for(document.getElementById("frm-fake-page").style.display="block",e=0;e<r.length;e++)t=r[e].parentNode.parentNode.parentNode.classList,1===e?t.add("frm-first-page"):t.remove("frm-first-page"),r[e].textContent=e+1;else document.getElementById("frm-fake-page").style.display="none";wp.hooks.doAction("frm_renumber_page_breaks",r)}function an(){var e,t,r,n=jQuery(this).closest(".frm_field_box[data-ftype=break]");n.length?function(e){var t=ln(e.get(0).parentNode.closest("li.frm_field_box").nextElementSibling);sn(e,t)}(n):(e=document.getElementById("frm-fake-page"),t=document.getElementById("frm-show-fields").firstElementChild,r=ln(t),"break"!==t.getAttribute("data-ftype")&&sn(jQuery(e),r))}function ln(e){var t,r;if(t=jQuery(),null===e)return t;r=e;do{if(null!==r.querySelector(".edit_field_type_break"))break;t=t.add(jQuery(r)),r=r.nextElementSibling}while(null!==r);return t}function sn(e,t){var r,n=t.length,o=Math.min(n,3);if(e.hasClass("frm-page-collapsed"))for(e.removeClass("frm-page-collapsed"),t.removeClass("frm-is-collapsed"),r=0;r<o;r++)r===o-1?jQuery(t[r]).slideDown(150,function(){t.show()}):jQuery(t[r]).slideDown(150);else for(e.addClass("frm-page-collapsed"),t.addClass("frm-is-collapsed"),r=0;r<o;r++)r===o-1?jQuery(t[r]).slideUp(150,function(){t.css("cssText","display:none !important;")}):jQuery(t[r]).slideUp(150)}function cn(){this.parentNode.parentNode.parentNode.parentNode.classList.toggle("frm-section-collapsed")}function dn(){this.nextElementSibling&&(this.nextElementSibling.style.animation=""),this.classList.toggle("frm-collapsed");var e="true"===this.getAttribute("aria-expanded")||!1;this.setAttribute("aria-expanded",!e),un(this.nextElementSibling)}function un(e){if(e){var t=e.scrollHeight;t<=0||(t+=250,e.style.setProperty("--slide-height","".concat(t,"px")),e.style.setProperty("--slide-time","".concat(Math.ceil(.8*t),"ms")))}}function fn(){if(this.id){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0],t=this.id.replace("field_label_",""),r=document.getElementById("field_options_type_".concat(t)),n=r.value;void 0!==e&&(n=function(e){return"divider"===e?e="section":"range"===e?e="slider":"data"===e?e="dynamic":"form"===e&&(e="embed form"),e}(n="SELECT"===r.tagName?r.options[r.selectedIndex].text.toLowerCase():n.replace("_"," ")),setTimeout(function(){e.value.toLowerCase()===n?e.select():e.focus()},50))}}function mn(){var e=document.querySelectorAll('[data-changeme="'.concat(this.id,'"]'))[0];void 0!==e&&setTimeout(function(){e.focus(),_n(e)},50)}function _n(e){var t=e.closest(".frm-collapse-me");null!==t&&t.previousElementSibling.classList.remove("frm-collapsed")}function pn(e){var t,r,n=e.target.classList;if(!n.contains("frm-collapse-page")&&!n.contains("frm-sub-label")&&null===e.target.closest(".dropdown")){if(null!==this.closest(".start_divider")&&e.stopPropagation(),this.classList.contains("edit_field_type_divider")){var o=e.originalEvent.target.closest("ul.frm_sorting");if(null!==o&&(o.classList.contains("edit_field_type_divider")||o.parentNode.parentNode.classList.contains("start_divider")))return}t=this,r=jQuery(t),t.className.includes("selected")||t.className.includes("edit_field_type_end_divider")&&r.closest(".edit_field_type_divider").hasClass("no_repeat_section")||(_t(),r.addClass("selected"),function(e){var t,r,n=e.getAttribute("data-fid"),o=e.getAttribute("data-type"),i=document.querySelectorAll(".frm-single-settings:not(.frm_hidden)");for(r=0;r<i.length;r++)i[r].classList.add("frm_hidden");var a=document.getElementById("frm-single-settings-".concat(n));Qo(a),o&&"quantity"===o&&xt(jQuery(a).find(".frmjs_prod_field_opt")[0]),null===(t=document.querySelector(".frm-settings-panel.frm-scrollbar-wrapper"))||void 0===t||t.scrollTo({top:0,behavior:"instant"}),a.classList.remove("frm_hidden"),a.querySelectorAll("h3:not(.frm-collapsed) + .frm-collapse-me").forEach(function(e){return e.style.animation="none"}),document.getElementById("frm-options-panel-tab").click();var l=a.querySelector(".wp-editor-area");l&&frmDom.wysiwyg.init(l,{setupCallback:ko}),wp.hooks.doAction("frmShowedFieldSettings",e,a),function(e,t,r){var n;if(function(e){return wp.hooks.applyFilters("frm_fields_with_shortcode_popup",["html"]).includes(e)}(e)){var o="#frm-single-settings-".concat(t);if(!document.querySelector("".concat(o," .frm-show-box"))){null===(n=r.querySelector(".wp-editor-container"))||void 0===n||n.classList.add("frm_has_shortcodes");var i=function(){return frmDom.svg({href:"#frm_more_horiz_solid_icon",classList:["frm-show-box"]})};document.querySelectorAll("".concat(o," .frm_has_shortcodes textarea")).forEach(function(e){var t=b({className:"frm-with-right-icon"});e.parentNode.insertBefore(t,e),t.append(i()),t.append(e)})}}}(o,n,a)}(t))}}function gn(e){var t=e.target;if("custom"===t.value){var r=t.dataset.fieldId,n=document.getElementById("frm-field-format-custom-".concat(r)).querySelector(".frm_format_opt");"international"!==n.value&&"currency"!==n.value&&"number"!==n.value||n.setAttribute("value","")}setTimeout(function(){t.querySelectorAll("option").forEach(function(e){e.selected&&e.classList.contains("frm_show_upgrade")&&(t.value="none")})},0)}function vn(){var e=this.getAttribute("data-fid");_n(document.getElementById("field_options_field_key_".concat(e)))}function yn(){var e=jQuery(this).closest(".frm_field_box");e.find(".repeat_icon_links").removeClass("repeat_format repeat_formatboth repeat_formattext").addClass("repeat_format".concat(this.value)),"text"===this.value||"both"===this.value?(e.find(".frm_repeat_text").show(),e.find(".repeat_icon_links a").addClass("frm_button")):(e.find(".frm_repeat_text").hide(),e.find(".repeat_icon_links a").removeClass("frm_button"))}function hn(){var e=this.value;""!==e&&(e<2||e>200)&&(K(f.repeat_limit_min),this.value="")}function bn(){var e=this.value;""!==e&&(e<1||e>200)&&(K(f.checkbox_limit),this.value="")}function wn(e,t){jQuery(e).closest(".frm_field_box").find(".frm_".concat(t,"_form_row .frm_repeat_label")).text(e.value)}function jn(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=this.value,r=document.getElementById("frm_show_selected_fields_".concat(e)),n=document.getElementById("frm_show_selected_forms_".concat(e));jQuery(n).find("select").val(""),"form"===t?(n.style.display="inline",function(e){if(null!==e)for(;e.firstChild;)e.firstChild.remove()}(r)):(r.style.display="none",n.style.display="none",Un(t,e))}function xn(){var e=En(this);if(e){var t=jQuery(this).closest(".frm_single_option");!function(e,t,r){var n=r.data("optkey"),o=Dn(e),i=jQuery('label[for="field_'.concat(t,"-").concat(n,'"]')),a="field_options[options_".concat(e,"][").concat(n,"]"),l=jQuery('input[name="'.concat(a,'[label]"]'));if(i.length<1)return Qn(e),void(r.find('input[name^="default_value_"]').is(":checked")&&l.length>0&&jQuery('select[name^="item_meta['.concat(e,']"]')).val(l.val()));var s,c=i.children("input");if(s=l.length<1?(l=jQuery('input[name="'.concat(a,'"]'))).val():o?jQuery('input[name="'.concat(a,'[value]"]')).val():l.val(),!(l.length<1)){var d=i[0].childNodes;if(Mn(e)){var u=function(e,t,r){var n,o=e.find("img");o&&(n=o.attr("src"));var i=Pn(t);return On(r.val(),i,n)}(r,e,l),f=i.find(".frm_image_option_container");f.length>0?f.replaceWith(u):(d[d.length-1].nodeValue="",i.append(u))}else{var m=!1;d.forEach(function(t,r){if(!1===m)"INPUT"===t.tagName&&(m=r);else if(r===m+1){var n="";!function(e){var t=document.getElementsByName("field_options[image_options_".concat(e,"]")),r=Array.from(t).find(function(e){return e.checked&&"buttons"===e.value});return void 0!==r}(e)?t.nodeValue=" ".concat(l.val()):(n=h({className:"frm_label_button_container",text:" ".concat(l.val())}),i[0].replaceChild(n,t))}else t.remove()})}c.val(s),defaultVal=r.find('input[name^="default_value_"]'),c.prop("checked",!!defaultVal.is(":checked"))}}(e.fieldId,e.fieldKey,t)}}function En(e){var t=jQuery(e).closest(".frm_sortable_field_opts");return!!t.length&&{fieldId:t.attr("id").replace("frm_field_","").replace("_opts",""),fieldKey:t.data("key")}}function kn(e){var t,r=document.getElementById("field_options_image_size_".concat(e)),n="";return r&&""!==(t=r.value)&&(n=t),n}function Qn(e){var t=jQuery('[name^="item_meta['.concat(e,']"]'));if(!(t.length<1)){var r={fieldId:e,metaInput:t[0]};if(!1===wp.hooks.applyFilters("frm_custom_reset_displayed_opts",!1,r)){if(t.is("select")){var n=document.getElementById("frm_placeholder_".concat(e));n&&""!==n.value?qn(t[0],{sourceID:e,placeholder:n.value}):qn(t[0],{sourceID:e})}else{var o=Cn(e),i=jQuery("#field_".concat(e,"_inner_container > .frm_form_fields")),a=Mn(e),l=a?kn(e):"",s=a?"frm_image_option frm_image_".concat(l," "):"";i.html("");for(var c=En(jQuery("#frm_delete_field_".concat(e,"-000_container"))),d=aa(e),u="hidden"===t.attr("type")?t.data("field-type"):t.attr("type"),f=0;f<o.length;f++)i.append(In(u,o[f],e,c.fieldKey,d,s))}An(e)}else An(e)}}function Sn(e,t){var r=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('input[value="'.concat(t,'"]'));return r?Zr(r):{newValue:t,newLabel:t}}function An(e,t){for(var r=W.querySelectorAll(".frm_logic_row"),n=r.length,o=wp.hooks.applyFilters("frm_conditional_logic_field_options",function(e){var t=[],r=document.getElementById("frm_field_".concat(e,"_opts"));if(!r)return t;for(var n=r.querySelectorAll(".frm_single_option"),o=n.length,i=0;i<o;i++){var a=n[i];if(!a.classList.contains("frm_hidden")){var l=a.querySelector(".field_".concat(e,"_option"));t.push(l.value)}}return t}(e),{type:t,fieldId:e}),i=o.length,a=0;a<n;a++){var l=r[a];if(l.querySelector(".frm_logic_field_opts").value==e){for(var s=l.id.split("_")[2],c=l.querySelector('select[name="field_options[hide_opt_'.concat(s,'][]"]')),d=function(){var t,r=o[u],n=null===(t=document.getElementById("frm_field_".concat(e,"_opts")).querySelector('.frm_option_key input[type="text"]'))||void 0===t?void 0:t.value;n||(n=r);var i=c.querySelector('option[value="'.concat(n,'"]')),a=Sn(e,r),l=a.newValue,s=a.newLabel,d=document.querySelectorAll("#frm_field_".concat(e,"_opts input[data-value-on-focus]")),f=Array.from(d).find(function(e){return e.value===r});if(f){var m=f.dataset.valueOnFocus;if(m&&c.querySelector('option[value="'.concat(m,'"]')))return 1}Ln(c,i,l,s)},u=i-1;u>=0;u--)d();var f=c.querySelector('option[value=""]');null!==f&&c.prepend(f)}}}function Ln(e,t,r,n){null!==t||e.querySelector('option[value="'.concat(r,'"]'))||((t=frmDom.tag("option",{text:n})).value=r),e.prepend(t)}function In(e,t,r,n,o,i){var a="",l=t.key.includes("other"),s="field_".concat(n,"-").concat(t.key),c="scale"===e?"radio":e,d='<input type="text" id="field_'.concat(n,"-").concat(t.key,'-otext" class="frm_other_input frm_pos_none" name="item_meta[other][').concat(r,"][").concat(t.key,']" value="" />');return this.getSingle=function(){return""!==(a=wp.hooks.applyFilters("frm_admin.build_single_option_template",a,{opt:t,type:e,fieldId:r,classes:i,id:s}))?a:'<div class="frm_'.concat(e," ").concat(e," ").concat(i,'" id="frm_').concat(e,"_").concat(r,"-").concat(t.key,'">\n\t\t\t\t\t<label for="').concat(s,'">\n\t\t\t\t\t\t<input type="').concat(c,'" name="item_meta[').concat(r,"]").concat("checkbox"===e?"[]":"",'" value="').concat(Tn(t.saved),'" id="').concat(s,'"').concat(o?' data-price="'.concat(t.price,'"'):"").concat(t.checked?' checked="checked"':"",">\n\t\t\t\t\t\t").concat(Tn(t.label),"\n\t\t\t\t\t</label>\n\t\t\t\t\t").concat(l?d:"","\n\t\t\t\t</div>")},this.getSingle()}function qn(e,t){if(e){var r=t.sourceID,n=t.placeholder,o=aa(r),i=t.other;!function(e){var t;if(void 0!==e.options)for(t=e.options.length-1;t>=0;t--)e.remove(t)}(e);for(var a=Cn(r,e.id.includes("frm_field_logic_opt")),l=void 0!==n,s=0;s<a.length;s++){var c=a[s].label,d=a[s].key.includes("other");if(l&&""!==c?Bn(e,n):l&&(c=n),l=!1,!d||i){var u=document.createElement("option");u.value=a[s].saved,u.innerHTML=Tn(c),o&&u.setAttribute("data-price",a[s].price),e.append(u)}}}}function Bn(e,t){var r=document.createElement("option"),n=e.firstChild;r.value="",r.innerHTML=t,null!==n?(n.before(r),e.selectedIndex=0):e.append(r)}function Cn(e){var t,r,n,o,i,a,l=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=[],c=jQuery('input[name^="field_options[options_'.concat(e,']"]')).filter('[name$="[label]"], [name*="[other_"]'),d=aa(e),u=Pn(e),f=Mn(e),m=Dn(e);for(t=0;t<c.length;t++)c[t].name.indexOf("[000]")>0||(o=r=c[t].value,i=c[t].name.replace("field_options[options_".concat(e,"]["),"").replace("[label]","").replace("]",""),m&&(n=c[t].name.replace("[label]","[value]"),r=jQuery('input[name="'.concat(n,'"]')).val(),l&&""===o&&(o=""!==r?r:frm_admin_js.no_label)),f&&(o=On(o,u,Nn(c[t]))),a={saved:r,label:o=frmAdminBuild.hooks.applyFilters("frm_choice_field_label",o,e,c[t],f),checked:Fn(c[t].id),key:i},d&&(n=c[t].name.replace("[label]","[price]"),a.price=jQuery('input[name="'.concat(n,'"]')).val()),s.push(a));return s}function Nn(e){var t=jQuery(e).siblings(".frm_image_preview_wrapper");if(!t.length)return"";var r=t.find("img");return r.length?r.attr("src"):""}function Tn(e){(e instanceof Element||e instanceof Document)&&(e=e.outerHTML);var t=jQuery.parseHTML(e).reduce(function(e,t){var r=frmDom.cleanNode(t);return"#text"===r.nodeName?e+r.textContent:e+r.outerHTML},"");return t!==e?Tn(t):t}function On(e,t,r){var n,o=e;o=Tn(o),r?n=x({src:r,alt:o}):(n=h({className:"frm_empty_url"})).innerHTML=f.image_placeholder_icon;var i=t?" frm_label_with_image":"",a=[n];if(t){var l=y("span",{className:"frm_text_label_for_image_inner"});l.innerHTML=o,a.push(y("span",{className:"frm_text_label_for_image",child:l}))}return y("span",{className:"frm_image_option_container".concat(i),children:a})}function Fn(e){var t=jQuery("#".concat(e));if(0===t.length)return!1;var r=t.siblings("input[type=checkbox]");return r.length&&r.prop("checked")}function Dn(e){return Rn("separate_value_".concat(e))}function Mn(e){for(var t=!1,r=document.getElementsByName("field_options[image_options_".concat(e,"]")),n=0;n<r.length;n++)r[n].checked&&(t="0"!==r[n].value);return frmAdminBuild.hooks.applyFilters("frm_choice_field_images_as_options",t,e)}function Pn(e){var t=!Rn("hide_image_text_".concat(e));return frmAdminBuild.hooks.applyFilters("frm_choice_field_showing_label_with_image",t,e)}function Rn(e){var t=document.getElementById(e);return!!t&&t.checked}function zn(e){var t=e.closest(".frm-single-settings"),r=t.getAttribute("data-fid"),n=t.querySelector('[name="field_options[separate_value_'.concat(r,']"]')).checked;if(!n||e.name.endsWith("[value]")){var o=document.getElementById("frm_field_".concat(r,"_opts"));Array.from(o.querySelectorAll('input[type="text"]')).filter(function(t){return t.id!==e.id&&n===t.name.endsWith("[value]")&&t.value===e.value}).length&&K(R(P('Duplicate option value "%s" detected',"formidable"),Tn(e.value)))}}function Hn(){var e=this.value;if(e){var t=this.parentNode.id.replace("frm_logic_","").split("_"),r=t[0],n=t[1],o=document.getElementById("frm_field_id_".concat(e)).getAttribute("data-ftype"),i=document.getElementById("frm_show_selected_values_".concat(r,"_").concat(n)),a="field_options[hide_opt_".concat(r,"][]"),l="frm_field_logic_opt_".concat(r),s=!1,c="select"===o||"checkbox"===o||"radio"===o,d="text"===o||"email"===o||"phone"===o||"url"===o||"number"===o;if(c&&document.getElementById("frm_has_hidden_options_".concat(e))&&(c=!1),c||d){var u=document.querySelector("#frm_logic_".concat(r,"_").concat(n,' [name="field_options[hide_field_cond_').concat(r,'][]"]')).value;i.innerHTML="";var f=c&&!["LIKE","not LIKE","LIKE%","%LIKE"].includes(u);f?s=document.createElement("select"):(s=document.createElement("input")).type="text",s.name=a,s.id="".concat(l,"_").concat(n),i.append(s),f&&qn(document.getElementById(s.id),{sourceID:e,placeholder:"",other:!0})}else{var m=this.getAttribute("data-type");frmGetFieldValues(e,r,n,m,void 0,function(){var e=new CustomEvent("frm_logic_options_loaded");e.frmData={valueFieldType:o,fieldID:r,metaKey:n},document.dispatchEvent(e)})}}}function Gn(){var e=this.value;e&&Un(e,jQuery(this).closest(".frm-single-settings").data("fid"))}function Un(e,t){e&&jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_field_selection",field_id:t,form_id:e,nonce:frmGlobal.nonce},success:function(e){var r=jQuery("#frm_show_selected_fields_".concat(t));r.toggleClass("frm6",!e.includes("frm-inline-message")),r.html(e).show()}})}function Wn(){var e=this;return this.initOnceInAllInstances=function(){void 0===Wn.prototype.orderFieldsObject&&(Wn.prototype.orderFieldsObject={},Wn.prototype.fieldSettingsForm=document.getElementById("frm-end-form-marker").closest("form"))},this.getFieldOrderInputById=function(e,t){var r,n=Wn.prototype.orderFieldsObject,o=Wn.prototype.fieldSettingsForm;return void 0===n[e]?((r=o.querySelector('input[name="field_options[field_order_'.concat(e,']"]')))||(r=t.querySelector('input[name="field_options[field_order_'.concat(e,']"]'))),n[e]=r,r):n[e]},this.initOnceInAllInstances(),on(),function(){var t,r,n,o,i,a,l=new Qo,s=jQuery("li.frm_field_box",jQuery("#frm-show-fields"));for(i=0;i<s.length;i++)t=s[i].getAttribute("data-fid"),(n=(r=e.getFieldOrderInputById(t,s[i]))?Object.assign({},r.value)[0]:null)!=(o=i+1)&&null!==n&&(r.value=o,a=s[i].querySelector("#frm-single-settings-".concat(t)),l.append(a),ci());l.moveFields()}()}function $n(){document.querySelectorAll(".start_divider").forEach(function(e){Vn(jQuery(e))})}function Vn(e){if(e.length){for(var t=e.find("ul.frm_sorting"),r=!1,n=t.length,o=0;o<n;++o)if(0!==be(jQuery(t.get(o))).length){r=!0;break}e.parent().children(".frm_no_section_fields").get(0).classList.toggle("frm_block",!r)}}function Kn(){var e=jQuery(this).data("slidedown"),t=jQuery(document.getElementById(e));return t.is(":hidden")&&(t.slideDown("fast"),this.style.display="none"),!1}function Jn(){var e=jQuery(this).data("slideup"),t=jQuery(document.getElementById(e));return t.slideUp("fast"),t.siblings("a").show(),!1}function Xn(e,t){""===t.getAttribute("value")?Yn(jQuery(this)):function(e){var t=e.val();if(null===t)return e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!0),void Yn(e);var r=t.indexOf("");r>=0&&(t.splice(r,1),e.val(t),e.next(".btn-group").find('.multiselect-container input[value=""]').prop("checked",!1))}(jQuery(this))}function Yn(e){e.val(""),e.next(".btn-group").find('.multiselect-container input[value!=""]').prop("checked",!1)}function Zn(){jQuery(".frm-hide-empty").each(function(){0===jQuery(this).text().trim().length&&jQuery(this).remove()})}function eo(e){e.preventDefault(),function(e,t,r){var n=document.getElementById(e.getAttribute("data-open")),o=jQuery(e).closest("p,ul"),i=void 0!==t;if(o.hasClass("frm-open"))o.removeClass("frm-open"),n.classList.add("frm_hidden");else{if(i||(t=pi(e)),t){if(!i){var a=r.key;"Enter"!==a&&" "!==a&&t.focus()}o.after(n),n.setAttribute("data-fills",t.id.replace("-proxy-input","")),0===n.id.indexOf("frm-calc-box")&&yt(n,!0)}o.addClass("frm-open"),n.classList.remove("frm_hidden"),wp.hooks.doAction("frm_show_inline_modal",n,e)}}(this,void 0,e)}function to(e){e.preventDefault(),this.parentNode.classList.add("frm_hidden"),jQuery('.frm-open [data-open="'.concat(this.parentNode.id,'"]')).closest(".frm-open").removeClass("frm-open")}function ro(e){var t=e.target;t.closest(".frm-inline-modal.frm-modal-no-dismiss")||t.closest(".frm-show-inline-modal")||t.closest("#frm_adv_info")||t.closest(".frm-token-proxy-input")||document.querySelectorAll(".frm-inline-modal.frm-modal-no-dismiss:not(.frm_hidden)").forEach(function(e){e.classList.add("frm_hidden"),e.previousElementSibling.classList.remove("frm-open")})}function no(){var e,t=this.getAttribute("data-frmchange").split(",");for(e=0;e<t.length;e++)"updateOption"===t[e]?io(this):"updateDefault"===t[e]?oo(this):"checkUniqueOpt"===t[e]?zn(this):this.value=this.value[t[e]]()}function oo(e){var t=ao(e),r=t.getAttribute("data-optkey"),n=lo(t,r),o=t.querySelector('input[name="default_value_'.concat(n,'"]'));null!==o&&(o.value=e.value)}function io(e){var t,r=ao(e),n=r.getAttribute("data-optkey"),o=lo(r,n),i=document.getElementById("separate_value_".concat(o));i&&!1===i.checked&&((t=document.getElementById("field_key_".concat(o,"-").concat(n))).value=e.value,oo(t))}function ao(e){var t=e.parentNode;return"LI"!==t.tagName&&(t=t.parentNode),t}function lo(e,t){return e.id.replace("frm_delete_field_","").replace("-".concat(t,"_container"),"")}function so(){var e=this;if(!mo()){go(this);var t=jQuery(q),r=JSON.stringify(t.serializeArray());jQuery(document.getElementById("frm_compact_fields")).val(r),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_save_form",frm_compact_fields:r,nonce:frmGlobal.nonce},success:function(t){var r;(r=e).classList.remove("frm_loading_form"),r.classList.remove("frm_loading_button"),jQuery('.frm-single-settings ul input[type="text"][name^="field_options[options_"]').filter("[data-value-on-load]").removeAttr("data-value-on-load"),jQuery('input[type="hidden"][name^=optionmap]').remove(),N=0,r.setAttribute("aria-busy","false"),setTimeout(function(){jQuery(".frm_updated_message").fadeOut("slow",function(){this.remove()})},5e3);var n,o=document.getElementById("post-body-content"),i=document.createElement("div");i.setAttribute("class","frm_updated_message"),i.innerHTML=t,o.insertBefore(i,o.firstChild),(n=document.getElementById("frm_submit_side_top")).hasAttribute("data-new-addon-installed")&&"true"===n.getAttribute("data-new-addon-installed")&&(n.removeAttribute("data-new-addon-installed"),window.location.reload())},error:function(){co(document.getElementById("frm_js_build_form"))}})}}function co(e){var t=e.ownerDocument.createElement("input");t.style.display="none",t.type="submit",e.append(t),t.click(),t.remove()}function uo(e){jQuery(e).trigger("change")}function fo(){if(!mo()){go(this);var e=jQuery(q);jQuery(document.getElementById("frm_compact_fields")).val(JSON.stringify(e.serializeArray())),co(document.getElementById("frm_js_build_form"))}}function mo(){if((t=document.getElementById("frm_form_name"))&&""!==t.value.trim()||"true"!==U.get("new_template")||(null===(e=document.querySelector("#frm_top_bar #frm_bs_dropdown .frm_bstooltip"))||void 0===e?void 0:e.textContent.trim())!==frm_admin_js.noTitleText)return!1;var e,t,r=ea("#frm-form-templates-modal","440px");return!!r&&(_i(r,"72px"),r.dialog("open"),!0)}function _o(){var e=document.getElementById("frm-save-form-name-button"),t=document.getElementById("frm_new_form_name_input");E(e,po),t.addEventListener("keydown",function(e){"Enter"===e.key&&po(e)})}var po=function(e){var t=document.getElementById("frm_new_form_name_input").value.trim(),r=new FormData;r.append("form_id",U.get("id")),r.append("form_name",t),k("rename_form",r).then(function(e){U.delete("new_template"),G.search=U.toString(),history.replaceState({},"",G.toString()),null!==document.getElementById("frm_notification_settings")&&(document.getElementById("frm_form_name").value=t,document.getElementById("frm_form_key").value=e.form_key),jQuery("#frm-publishing").find(".frm_button_submit").trigger("click")})};function go(e){var t,r;ra(),jQuery("form.inplace_form").length&&jQuery(".inplace_save, .postbox").trigger("click"),e.classList.contains("frm_button_submit")?e.classList.add("frm_loading_form"):e.classList.add("frm_loading_button"),e.setAttribute("aria-busy","true"),t=document.querySelectorAll(".frm_format_dropdown, .frm_phone_type_dropdown"),r={none:"",international:"international",currency:"currency",number:"number"},t.forEach(function(e){var t=e.value;t in r&&(document.getElementById("frm_format_".concat(e.dataset.fieldId)).value=r[t])})}function vo(e){var t,r=null!==(t=e.target.dataset)&&void 0!==t&&t.modalTitle?e.target:e.target.closest("[data-modal-title]");if(r){var n=r.dataset,o=n.modalTitle,i=n.modalContent;o&&i&&(e.preventDefault(),frmDom.modal.maybeCreateModal("frmBasicModal",{title:o,content:h({className:"inside",child:b(i)})}))}}function yo(e){var t,n,i,s,u,f,m,_,p=e.dataset.upgrade,g=e.getAttribute("href").replace("#",""),v=document.querySelector(".frm_".concat(g))||document.querySelector(".".concat(g));if(v&&!v.querySelector(".frm-upgrade-message")){var y=v.querySelector("h2");y.style.borderBottom="none",y.textContent=R(P("%s are not installed","formidable"),p),v.classList.add("frmcenter");var b=document.getElementById("frm_upgrade_modal");A("frm-upgrade-message"),A("frm-oneclick"),A("frm-addon-status");var w=b.querySelector(".frm-upgrade-link");if(w){var j,E,k=w.closest(".frm-upgrade-modal-actions"),Q=(E=k?(k=k.cloneNode(!0)).querySelector(".frm-upgrade-link"):w.cloneNode(!0)).querySelector(".license-level");Q&&(Q.textContent=function(e){return e.dataset.requires?e.dataset.requires:"Pro"}(e)),e.dataset.gradientUpgrade&&E.classList.add("frm-gradient"),v.append(k||E),null!==(j=w.nextElementSibling)&&void 0!==j&&j.querySelector(".frm-link-secondary")&&v.append(w.nextElementSibling.cloneNode(!0)),A("frm-oneclick-button")}var S=e.dataset.message;void 0===S&&(S=e.dataset.upgrade),function(e,t,n){r(4260).addOneClick(e,"tab",n)}(e,0,S),e.dataset.upsellImages?v.append((t=e.dataset.upsellImages,n=p,s="".concat(frmGlobal.url,"/images/upsell/"),u=l(i=t.split(",").map(function(e){return x({src:s+e.trim(),alt:n})}))||o(i)||c(i)||a(),f=u[0],m=d(u).slice(1),_=[f],m.length&&_.push(h({className:"frm-upsell-images-row",children:m})),h({className:"frm-upsell-images",children:_}))):e.dataset.screenshot&&v.append(function(e){var t="".concat(frmGlobal.url,"/images/screenshots/");return h({className:"frm-settings-screenshot-wrapper",children:[function(){var e=["#ED8181","#EDE06A","#80BE30"].map(function(e){var t=h({className:"frm-minmax-icon"});return t.style.backgroundColor=e,t});return e.push(x({src:"".concat(frmGlobal.url,"/images/tab.svg")})),h({className:"frm-settings-screenshot-toolbar",children:e})}(),h({child:x({src:t+e})})]})}(e.dataset.screenshot))}function A(e){v.append(b.querySelector(".".concat(e)).cloneNode(!0))}}function ho(e){void 0===e&&(e=""),function(e){var t,r=jQuery("".concat(e," :not(.frm_has_shortcodes) .frm_not_email_message, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_to, ").concat(e," :not(.frm_has_shortcodes) .frm_not_email_subject"));for(t=0;t<r.length;t++)r[t].parentNode.classList.add("frm_has_shortcodes")}(e),jQuery("".concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) input,").concat(e," .frm_has_shortcodes:not(.frm-with-right-icon) textarea")).wrap('<span class="frm-with-right-icon"></span>').before('<svg class="frmsvg frm-show-box"><use href="#frm_more_horiz_solid_icon"/></svg>')}function bo(){var e="success";"options[edit_action]"===this.name&&(e="edit");var t=jQuery(this).val();jQuery(".".concat(e,"_action_box")).hide(),"redirect"===t?jQuery(".".concat(e,"_action_redirect_box.").concat(e,"_action_box")).fadeIn("slow"):"page"===t?jQuery(".".concat(e,"_action_page_box.").concat(e,"_action_box")).fadeIn("slow"):jQuery(".".concat(e,"_action_message_box.").concat(e,"_action_box")).fadeIn("slow")}function wo(e){var t,r,n;if(e.stopPropagation(),!function(e){var t=jQuery(e),r=t.closest(".frm_form_action_settings"),n=r.find(".widget-inside");if(n.find("p, div, table").length)return!1;var o=r.find(".widget-top");return o.one("frm-action-loaded",function(){t.trigger("click"),r.removeClass("open"),n.hide()}),o.trigger("click"),!0}(e.target)){var o=e.target.closest(".frm_form_action_settings"),i=o.querySelectorAll(".wp-editor-area");i.length&&i.forEach(function(e){tinymce.EditorManager.execCommand("mceRemoveEditor",!0,e.id)});var a=jQuery(o).clone(),l=a.attr("id").replace("frm_form_action_",""),s=jo(l),c=null===(t=o.querySelector(".frm_action_name"))||void 0===t?void 0:t.value,d=function(e,t){for(var r=new Set(t),n=e,o=2;r.has(n);)n="".concat(e," (").concat(o,")"),o++;return n}((null!==(r=null===(n=o.querySelector(".widget-title h4 span:not(.frm-border-icon)"))||void 0===n?void 0:n.textContent.trim())&&void 0!==r?r:"").replace(/ \(\d+\)$/,""),xo(c));a[0].querySelector(".widget-title h4 span:not(.frm-border-icon)").textContent=d,a[0].querySelector('input[name$="['.concat(l,'][post_title]"]')).value=d,a.find(".frm_action_id, .frm-btn-group").remove(),a.find('input[name$="['.concat(l,'][ID]"]')).val(""),a.find(".widget-inside").hide(),a.find("input[type=text], textarea, input[type=number]").prop("defaultValue",function(){return this.value}),a.find("input[type=checkbox], input[type=radio]").prop("defaultChecked",function(){return this.checked});var u=new RegExp("\\[".concat(l,"\\]"),"g"),f=new RegExp("_".concat(l,'"'),"g"),m=new RegExp("_".concat(l," "),"g"),_=new RegExp("-".concat(l,'"'),"g"),p=new RegExp('"'.concat(l,'"'),"g"),g=a.html().replace(u,"[".concat(s,"]")).replace(f,"_".concat(s,'"'));g=(g=g.replace(m,"_".concat(s," "))).replace(_,"-".concat(s,'"')).replace(p,'"'.concat(s,'"'));var v=h({id:"frm_form_action_".concat(s),className:a.get(0).className});v.setAttribute("data-actionkey",s),v.innerHTML=g,v.querySelectorAll(".wp-editor-wrap, .wp-editor-wrap *").forEach(function(e){"string"==typeof e.className&&(e.className=e.className.replace(l,s)),e.id=e.id.replace(l,s)}),v.classList.remove("open"),document.getElementById("frm_notification_settings").append(v),i.length&&(i.forEach(function(e){frmDom.wysiwyg.init(e)}),v.querySelectorAll(".wp-editor-area").forEach(function(e){frmDom.wysiwyg.init(e)})),v.classList.contains("frm_single_on_submit_settings")&&v.querySelector("input.frm-page-search")&&Pi(v),Bi(),wp.hooks.doAction("frm_after_duplicate_action",v)}}function jo(e){var t=parseInt(e,10)+11;return document.getElementById("frm_form_action_".concat(t))&&(t=jo(++t)),t}function xo(e){return Array.from(document.querySelectorAll(".frm_single_".concat(e,"_settings .widget-title h4 span:not(.frm-border-icon)")),function(e){return e.textContent.trim()})}function Eo(){var e,t=jQuery(this).data("actiontype");if(!qo(t)){var r=(e=Kr(document.querySelectorAll(".frm_form_action_settings"),"frm_form_action_"),void 0!==document.getElementById("frm_form_action_".concat(e))&&(e+=100),D>=e&&(e=D+1),D=e,e),n=T,o=xo(t),i=document.createElement("div");i.classList.add("frm_single_".concat(t,"_settings"));var a=document.getElementById("frm_notification_settings");a.append(i),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_action",type:t,list_id:r,form_id:n,nonce:frmGlobal.nonce,existing_titles:o},success:function(e){var n;ci(),i.remove(),null===(n=document.querySelector(".frm-no-actions-message"))||void 0===n||n.classList.add("frm_hidden"),document.querySelectorAll(".frm_form_action_settings.open").forEach(function(e){return e.classList.remove("open")});var o=h();o.innerHTML=e;var l=o.querySelector(".widget-top");Array.from(o.children).forEach(function(e){return a.append(e)}),jQuery(".frm_form_action_settings").fadeIn("slow");var s,c,d=document.getElementById("frm_form_action_".concat(r));d.classList.add("open"),document.getElementById("post-body-content").scroll({top:d.offsetTop+10,left:0,behavior:"smooth"}),Io(t),(c=["stripe","square","paypal"]).includes(s=t)&&c.forEach(function(e){e!==s&&Io(e)}),ho("#frm_form_action_".concat(r)),Bi(),Pi(d),l&&jQuery(l).trigger("frm-action-loaded"),frmAdminBuild.hooks.doAction("frm_added_form_action",d)}})}}function ko(e){e.on("Change",function(){!function(e){(function(){var e=document.querySelector(".frm-single-settings:not(.frm_hidden)");if(!e)return!1;var t=e.querySelector(".wp-editor-wrap");return t&&t.classList.contains("tmce-active")})()&&!tinyMCE.activeEditor.isHidden()&&(e.targetElm.value=e.getContent(),jQuery(e.targetElm).trigger("change"))}(e)})}function Qo(e){var t=this;if(null!==e)return this.fragment=document.createDocumentFragment(),this.initOnceInAllInstances=function(){void 0===Qo.prototype.endMarker&&(Qo.prototype.endMarker=document.getElementById("frm-end-form-marker"))},this.append=function(e){var r=e?e.parentElement.classList:"";e&&(r.contains("frm_field_box")||r.contains("divider_section_only"))&&t.fragment.append(e)},this.moveFields=function(){q.insertBefore(t.fragment,Qo.prototype.endMarker)},this.initOnceInAllInstances(),void 0!==e?(this.append(e),void this.moveFields()):{append:this.append,moveFields:this.moveFields}}function So(){var e=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),t=this.getAttribute("data-emailrow");jQuery("#frm_form_action_".concat(e," .frm_").concat(t,"_row")).fadeIn("slow"),jQuery(this).fadeOut("slow")}function Ao(){var e=jQuery(this).closest(".frm_form_action_settings"),t=this.getAttribute("data-emailrow"),r=".frm_".concat(t,"_row"),n=".frm_".concat(t,"_button");jQuery(e).find(n).fadeIn("slow"),jQuery(e).find(r).fadeOut("slow",function(){jQuery(e).find("".concat(r," input")).val("")})}function Lo(){var e=jQuery(this).closest(".frm_form_action_settings"),t=".frm_from_to_match_row";e.find('input[name$="[post_content][from]"]').val()===e.find('input[name$="[post_content][email_to]"]').val()?jQuery(e).find(t).fadeIn("slow"):jQuery(e).find(t).fadeOut("slow")}function Io(e){var t,r,n=document.querySelectorAll(".frm_".concat(e,"_action"));qo(e)?(t=n,r=Bo(e)>0,t.forEach(function(e){e.classList.remove("frm_active_action"),e.classList.add("frm_inactive_action"),r&&e.classList.add("frm_already_used")})):n.forEach(function(e){e.querySelector(".frm_show_upgrade")||(e.classList.remove("frm_inactive_action","frm_already_used"),e.classList.add("frm_active_action"))})}function qo(e){var t=function(e){return["paypal","stripe","square"].includes(e)&&(e="payment"),jQuery(".frm_single_".concat(e,"_settings")).length}(e)>=Bo(e),r={type:e};return wp.hooks.applyFilters("frm_action_at_limit",t,r)}function Bo(e){return parseInt(jQuery(".frm_".concat(e,"_action")).data("limit"),10)}function Co(){var e=f.only_one_action,t=this.dataset.limit,r=this.dataset.actiontype;r&&["paypal","stripe","square","payment"].includes(r)&&(e="stripe"===r?f.only_one_stripe_action:f.only_one_payment_action),void 0!==t&&((t=parseInt(t))>1?e=e.replace(1,t).trim():e+=" ".concat(f.edit_action_text)),K(e)}function No(e,t){var r=jQuery(t).closest(".frm_form_action_settings").find(".frm_action_name").val(),n=document.getElementById("form_id").value,o=document.getElementById("frm_logic_row_".concat(e)),i=Kr(o.querySelectorAll(".frm_logic_row"),"frm_logic_".concat(e,"_")),a=h({id:"frm_logic_".concat(e,"_").concat(i),className:"frm_logic_row frm_hidden"}),l=document.getElementById("logic_link_".concat(e)),s=l?o.closest(".frm_logic_rows"):null;o.append(a),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_form_logic_row",email_id:e,form_id:n,meta_name:i,type:r,nonce:frmGlobal.nonce},success:function(e){a.insertAdjacentHTML("beforebegin",e),a.remove();var t=o.querySelector(".frm_logic_row:last-child"),r=t?t.querySelector(".frm-logic-rule-text"):null;r&&(r.textContent=o.dataset.ruleText||""),l&&l.classList.add("frm_hidden"),s&&(s.classList.remove("frm_hidden"),s.style.display="")}})}function To(){return No(jQuery(this).data("emailkey"),this),!1}function Oo(){var e;if(this.checked){var t=this.getAttribute("data-emailkey");if(t&&null!==(e=this.dataset.toggleclass)&&void 0!==e&&e.startsWith("frm_logic_rows_")){var r=document.getElementById("frm_logic_row_".concat(t));r&&!r.querySelector(".frm_logic_row")&&No(t,this)}}}function Fo(){var e=jQuery("select.frm_single_post_field");e.css("border-color","");var t=this,r=jQuery(t).val();if(""===r||"checkbox"===r)return!1;e.each(function(){if(jQuery(this).val()===r&&this.name!==t.name)return this.style.borderColor="red",jQuery(t).val(""),K(f.field_already_used),!1})}function Do(){var e=jQuery(this).val();""===e?(jQuery(".frm_post_content_opt, select.frm_dyncontent_opt").hide().val(""),jQuery(".frm_dyncontent_opt").hide()):"post_content"===e?(jQuery(".frm_post_content_opt").show(),jQuery(".frm_dyncontent_opt").hide(),jQuery("select.frm_dyncontent_opt").val("")):(jQuery(".frm_post_content_opt").hide().val(""),jQuery("select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt").show())}function Mo(){var e=jQuery(this).val(),t=jQuery(document.getElementById("frm_dyncontent"));""===e||"new"===e?(t.val(""),jQuery(".frm_dyncontent_opt").show()):jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_display_get_content",id:e,nonce:frmGlobal.nonce},success:function(e){t.val(e),jQuery(".frm_dyncontent_opt").show()}})}function Po(){var e,t,r=document.getElementById("frm_posttax_rows").childNodes,n=document.querySelector(".frm_post_parent_field"),o=document.querySelector(".frm_post_menu_order_field"),i=this.value;jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_replace_posttax_options",post_type:i,nonce:frmGlobal.nonce},success:function(n){for(var o=0;o<r.length;o++)"DIV"===r[o].tagName&&(e=r[o].getElementsByTagName("select")[0],(t=document.createElement("select")).innerHTML=n,t.className=e.className,t.name=e.name,r[o].replaceChild(t,e))}}),n&&Ro(n,i,"frm_get_post_parent_option",function(e,t){n.querySelector(".frm_post_parent_opt_wrapper").innerHTML=e.replaceAll("REPLACETHISNAME",t),Pi(n)}),o&&Ro(o,i,"frm_should_use_post_menu_order_option")}function Ro(e,t,r,n){var o=(e.querySelector(".frm_autocomplete_value_input")||e.querySelector("select")).getAttribute("name");jQuery.ajax({url:ajaxurl,method:"POST",data:{action:r,post_type:t,_wpnonce:frmGlobal.nonce},success:function(t){if("string"==typeof t){if("0"===t)return e.classList.add("frm_hidden"),void(e.value="");e.classList.remove("frm_hidden"),"function"==typeof n&&n(t,o)}else console.error(t)},error:function(e){return console.error(e)}})}function zo(){Go("tax",this)}function Ho(){Go("meta",this)}function Go(e,t){var r,n,o=jQuery('input[name="id"]').val(),i=jQuery(t).closest(".frm_form_action_settings"),a=i.data("actionkey"),l=i.find(".frm_post_type").val(),s=0,c=document.querySelectorAll(".frm_post".concat(e,"_row"));c.length&&(n=r=c[c.length-1].id.replace("frm_post".concat(e,"_"),""),s=!isNaN(parseFloat(n))&&isFinite(n)?1+parseInt(r,10):1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_post".concat(e,"_row"),form_id:o,meta_name:s,tax_key:s,post_type:l,action_key:a,nonce:frmGlobal.nonce},success:function(t){var r,n;if(jQuery(document.getElementById("frm_post".concat(e,"_rows"))).append(t),jQuery(".frm_add_post".concat(e,"_row.button")).hide(),"meta"===e)for(jQuery(".frm_name_value").show(),r=document.querySelectorAll(".frm_toggle_cf_opts"),n=0;n<r.length-1;++n)r[n].style.display="none";else"tax"===e&&jQuery(".frm_posttax_labels").show()}})}function Uo(){if(jQuery(this).closest(".frm_posttax_row").find(".frm_posttax_opt_list").length){jQuery(this).closest(".frm_posttax_row").find(".frm_posttax_opt_list").html('<div class="spinner frm_spinner" style="display:block"></div>');var e=jQuery(this).closest(".frm_form_action_settings").find('select[name$="[post_content][post_type]"]').val(),t=jQuery(this).closest(".frm_form_action_settings").data("actionkey"),r=jQuery(this).closest(".frm_posttax_row").attr("id").replace("frm_posttax_",""),n=jQuery(this).val(),o=jQuery(document.getElementById("".concat(r,"_show_exclude"))).is(":checked")?1:0,i=jQuery('select[name$="[post_category]['.concat(r,'][field_id]"]')).val(),a=jQuery('input[name="id"]').val();jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_add_posttax_row",form_id:a,post_type:e,tax_key:r,action_key:t,meta_name:n,field_id:i,show_exclude:o,nonce:frmGlobal.nonce},success:function(e){jQuery(document.getElementById("frm_posttax_".concat(r))).replaceWith(e)}})}}function Wo(){var e=jQuery(this).closest(".frm_postmeta_row"),t=e.find(".frm_cancelnew"),r=e.find(".frm_enternew");return e.find("select.frm_cancelnew").is(":visible")?(t.hide(),r.show()):(t.show(),r.hide()),e.find("input.frm_enternew, select.frm_cancelnew").val(""),!1}function $o(){var e=jQuery(this),t=e.val();"checkbox"===e.attr("type")&&!1===this.checked&&(t="");var r=e.data("toggleclass");""===t?jQuery(".".concat(r)).hide():(jQuery(".".concat(r)).show(),jQuery(".hide_".concat(r,"_").concat(t)).hide())}function Vo(){mo()||(go(this),co(document.querySelector(".frm_form_settings")))}function Ko(e){return e.preventDefault(),Jo(jQuery(this),this.getAttribute("data-code")),!1}function Jo(e,t){var r=!1,n=e;if("object"===i(e)){if(e.hasClass("frm_noallow"))return;void 0===(n=jQuery(e).closest("[data-fills]").attr("data-fills"))&&void 0!==(n=e.closest("div").attr("class"))&&(n=n.split(" ")[1])}if(void 0===n){var o=document.activeElement;"search"===o.type?null===(n=o.id.replace("-search-input","")).match(/\d/gi)&&(n=(o=jQuery(".frm-single-settings:visible .".concat(n))).attr("id")):n=o.id}n&&(r=jQuery("#wp-".concat(n,"-wrap.wp-editor-wrap")).length>0);var a=jQuery(document.getElementById(n));if(void 0===e.attr("data-shortcode")&&(!a.length||void 0===a.attr("data-shortcode"))){var l=e.parents("ul.frm_code_list").attr("data-shortcode");"undefined"!==l&&"no"===l||(t="[".concat(t,"]"))}if(r&&(wpActiveEditor=n),!a.length)return!1;if("[default-html]"===t||"[default-plain]"===t){var s=0;"[default-plain]"===t&&(s=1),jQuery.ajax({type:"POST",url:ajaxurl,data:{action:"frm_get_default_html",form_id:jQuery('input[name="id"]').val(),plain_text:s,nonce:frmGlobal.nonce},elementId:n,success:function(e){if(r){var t=document.createElement("p");t.innerText=e,send_to_editor(t.innerHTML)}else Xo(a,e)}})}else t=function(e,t,r){return"object"===i(t)&&t instanceof jQuery&&0===r[0].id.indexOf("success_url_")&&(t=t[0]).closest("#frm-insert-fields-box")?(t.parentNode.classList.contains("frm_insert_url")||(e=e.replace("]"," sanitize_url=1]")),e):e}(t,e,a),r?send_to_editor(t):Xo(a,t);return!1}function Xo(e,t){if(document.selection)e[0].focus(),document.selection.createRange().text=t;else{var r=e[0],n=r.selectionEnd;t=function(e,t,r,n){var o=e.data("sep");if(void 0===o)return t;var i=e.val();if(!i.trim().length)return t;var a=new RegExp("".concat(o,"\\s*$")),l=new RegExp("^\\s*".concat(o));return i.substr(0,r).trim().length&&!1===a.test(i.substr(0,r))&&(t=o+t),i.substr(n,i.length).trim().length&&!1===l.test(i.substr(n,i.length))&&(t+=o),t}(e,t,r.selectionStart,n),r.value=r.value.substr(0,r.selectionStart)+t+r.value.substr(r.selectionEnd,r.value.length);var o=n+t.length;!function(e,t){if(e.classList.contains("frm_classes")&&Yo(t)){var r=e.value.split(" ").filter(Yo);r.length&&(e.value=function(e,t,r){var n=e.split(" ").filter(function(e){return(e=e.trim()).length&&!t.includes(e)});return n.includes(r)||n.push(r),n.join(" ")}(e.value,r,t.trim()))}}(r,t),r.focus(),r.setSelectionRange(o,o)}uo(e)}function Yo(e){return["frm_half","frm_third","frm_two_thirds","frm_fourth","frm_three_fourths","frm_fifth","frm_sixth","frm2","frm3","frm4","frm6","frm8","frm9","frm10","frm12"].includes(e.trim())}function Zo(){var e=document.getElementById("frm-id-condition"),t=document.getElementById("frm-key-condition");"id"===this.value?(e.classList.remove("frm_hidden"),t.classList.add("frm_hidden"),Ki(t,"change")):(e.classList.add("frm_hidden"),t.classList.remove("frm_hidden"),Ki(e,"change"))}function ei(){var e=document.getElementById("frm-id-key-condition-id").checked?"frm-id-condition":"frm-key-condition",t=document.getElementById("frm-is-condition").value,r=document.getElementById("frm-text-condition").value,n=document.getElementById("frm-insert-condition"),o=(e=document.getElementById(e)).options[e.selectedIndex].value,i="if ".concat(o," ").concat(t,'="').concat(r,'"]');n.setAttribute("data-code","".concat(i+f.conditional_text,"[/if ").concat(o)),n.innerHTML="[".concat(i,"[/if ").concat(o,"]")}function ti(e){return e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href")}function ri(e){var t;e.parentNode.parentNode.classList.contains("frm_has_shortcodes")&&(vi(),"use"===(t=gi(e)).tagName?ti(t=t.firstElementChild).includes("frm_close_icon")||li(t,"nofocus"):t.classList.contains("frm_close_icon")||li(t,"nofocus"))}function ni(e){e.preventDefault(),e.stopPropagation(),li(this)}function oi(e){var t=e.target;!function(e){var t;if(e.id.startsWith("field_options_type_")){var r=e.id.split("_"),n=r.length&&r[r.length-1];null!==(t=document.querySelector("#frm-single-settings-".concat(n)))&&void 0!==t&&t.classList.contains("frm-type-".concat(e.value))||ii()}}(t),g(t)}function ii(e){var t;void 0===e&&(e=P("You are changing the field type. Not all field settings will appear as expected until you reload the page. Would you like to reload the page now?","formidable")),frmDom.modal.maybeCreateModal("frmSaveAndReloadModal",{title:P("Save and Reload?","formidable"),content:(t=h(e),t.style.padding="var(--gap-md)",t),footer:function(){var e=frmDom.modal.footerButton({text:P("Save and Reload","formidable"),buttonType:"primary"});E(e,function(){var e;(e=document.getElementById("frm_submit_side_top")).classList.contains("frm_submit_ajax")&&e.setAttribute("data-new-addon-installed",!0),e.click()});var t=frmDom.modal.footerButton({text:P("Cancel","formidable"),buttonType:"cancel"});return t.classList.add("dismiss"),frmDom.div({children:[t,e]})}()})}function ai(e){var t;if(e instanceof Event){var r=document.querySelectorAll(".frm-single-settings .frm-show-box.frmsvg use"),n=Array.from(r).find(function(e){return"#frm_close_icon"===e.getAttribute("href")});if(void 0===n)return;t=n.parentElement}else t=e;var o=t.getBoundingClientRect(),i=document.getElementById("frm_adv_info"),a=i.parentElement.getBoundingClientRect();i.style.top="".concat(o.top-a.top+32,"px"),i.style.left="".concat(o.left-a.left-280,"px")}function li(e,t){var r=pi(e),n=document.getElementById("frm_adv_info"),o=e.className;if("svg"===e.tagName&&(e=e.firstElementChild),"use"===e.tagName&&(o=ti(e)),o.includes("frm_close_icon"))vi(n);else{if(ai(e),jQuery(".frm_code_list a").removeClass("frm_noallow"),r.classList.contains("frm_not_email_to")?jQuery("#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a").addClass("frm_noallow"):r.classList.contains("frm_not_email_subject")&&jQuery(".frm_code_list li.hide_frm_not_email_subject a").addClass("frm_noallow"),n.setAttribute("data-fills",r.id),n.style.display="block","use"===e.tagName)if(e.hasAttributeNS("http://www.w3.org/1999/xlink","href"))e.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon");else{var i=document.createElementNS("http://www.w3.org/2000/svg","use");i.setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_close_icon"),e.parentNode.replaceChild(i,e)}else e.className=o.replace("frm_more_horiz_solid_icon","frm_close_icon");"nofocus"!==t&&("none"!==r.style.display?r.focus():jQuery(tinymce.get(r.id)).trigger("focus")),function(e){["address","body"].forEach(function(t){!function(e,t){var r,n=f.contextualShortcodes["".concat(t,"Selector")],o=f.contextualShortcodes[t],i=e.matches(n),a=s(o);try{for(a.s();!(r=a.n()).done;){var l,c=r.value,d=null===(l=document.querySelector('#frm-adv-info-tab .frm_code_list [data-code="'.concat(c,'"]')))||void 0===l?void 0:l.closest("li");null==d||d.classList.toggle("frm_hidden",!i)}}catch(e){a.e(e)}finally{a.f()}}(e,t)})}(r)}}function si(e){return 0===f.contextualShortcodes.length||!function(e){var t=e.querySelector("a");if(!t)return!1;var r=t.dataset.code;return f.contextualShortcodes.address.includes(r)||f.contextualShortcodes.body.includes(r)}(e)||function(e){var t=e.querySelector("a").dataset.code,r=document.getElementById("frm_adv_info").dataset.fills,n=document.getElementById(r),o=f.contextualShortcodes;return o.address.includes(t)?n.matches(o.addressSelector):n.matches(o.bodySelector)}(e)}function ci(){N||(N=1,window.addEventListener("beforeunload",mi))}function di(){N=0}function ui(){N=0}function fi(){N=0}function mi(e){N&&(e.preventDefault(),e.returnValue="")}function _i(e,t){var r={my:"top",at:"top+".concat(t),of:window};e.dialog("option","position",r)}function pi(e){if(e.classList.contains("frm-input-icon"))return e.previousElementSibling;for(var t,r=e.nextElementSibling;r&&("INPUT"!==r.tagName&&"TEXTAREA"!==r.tagName||r.classList.contains("frm-token-input-field"));)r=pi(r);return r||(r=null===(t=e.closest(".frm-field-formula"))||void 0===t?void 0:t.querySelector(".frm-calc-field")),r}function gi(e){var t;if(null!==(t=e.nextElementSibling)&&void 0!==t&&t.classList.contains("frm-input-icon"))return e.nextElementSibling;for(var r=e.previousElementSibling;null!==r&&"I"!==r.tagName&&"svg"!==r.tagName;)r=gi(r);return r}function vi(e){if((void 0!==e||(e=document.getElementById("frm_adv_info")))&&null===document.getElementById("frm_dyncontent")){e.style.display="none";for(var t=document.querySelectorAll(".frm-show-box.frm_close_icon"),r=0;r<t.length;r++)t[r].classList.remove("frm_close_icon"),t[r].classList.add("frm_more_horiz_solid_icon");for(var n=document.querySelectorAll(".frm_has_shortcodes use"),o=0;o<n.length;o++)if("#frm_close_icon"===ti(n[o])){if(n[o].closest(".frm_remove_field"))continue;n[o].setAttributeNS("http://www.w3.org/1999/xlink","href","#frm_more_horiz_solid_icon")}}}function yi(e,t){t.stopPropagation(),jQuery(".frm_code_list .frmids, .frm_code_list .frmkeys").addClass("frm_hidden"),jQuery(".frm_code_list .".concat(e)).removeClass("frm_hidden"),jQuery(".frmids, .frmkeys").removeClass("current"),jQuery(".".concat(e)).addClass("current")}function hi(e){var t=e.target.closest(".frm_form_action_settings");t&&(t.classList.contains("frm_single_email_settings")||t.classList.contains("frm_single_on_submit_settings"))&&function(e){e.querySelectorAll(".wp-editor-area").forEach(function(e){frmDom.wysiwyg.init(e,{height:160,addFocusEvents:!0})})}(t)}function bi(){return!0===V(this)&&(jQuery(".frm_uninstall .frm-wait").css("visibility","visible"),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_uninstall&nonce=".concat(frmGlobal.nonce),success:function(e){jQuery(".frm_uninstall").fadeOut("slow"),window.location=e}})),!1}function wi(){var e=jQuery(this),t=this.name,r=this.getAttribute("data-plugin"),n=t.replace("edd_".concat(r,"_license_"),""),o=document.getElementById("edd_".concat(r,"_license_key")).value;e.get(0).disabled=!0,jQuery.ajax({type:"POST",url:ajaxurl,dataType:"json",data:{action:"frm_addon_".concat(n),license:o,plugin:r,nonce:frmGlobal.nonce},success:function(t){e.get(0).disabled=!1;var i=e.closest(".edd_frm_license_row");"deactivate"===n&&(o="",document.getElementById("edd_".concat(r,"_license_key")).value=""),i.find(".edd_frm_license").html(o);var a=e.get(0).closest(".frm_form_field"),l=!0===t.success;a.querySelector(".frm_icon_font.frm_action_success").classList.toggle("frm_hidden",!l||"deactivate"===n),a.querySelector(".frm_icon_font.frm_action_error").classList.toggle("frm_hidden",l);var s=i.find(".frm_license_msg");s.html(t.message),""!==t.message&&setTimeout(function(){if(s.html(""),i.find(".frm_icon_font").addClass("frm_hidden"),l){var e="activate"===n;i.get(0).querySelector(".edd_frm_unauthorized").classList.toggle("frm_hidden",e),i.get(0).querySelector(".edd_frm_authorized").classList.toggle("frm_hidden",!e)}},2e3)}})}function ji(e){e.preventDefault();var t=jQuery(e.target).find("input:checked");if(t.length){var r,n,o,i,a=[];t.each(function(e){a[e]=this.value}),r=a,n=e.target,(i=(o=jQuery(n)).next(".frm-importer-process")).find(".form-total").text(r.length),i.find(".form-current").text("1"),o.hide(),i.find(".process-completed").hide(),i.show(),H.importQueue=r,H.imported=0,xi(i)}}function xi(e){var t=H.importQueue[0],r=jQuery("#welcome-panel").find('input[name="slug"]').val(),n={action:"frm_import_".concat(r),form_id:t,nonce:frmGlobal.nonce};jQuery.post(ajaxurl,n,function(r){var n;r.success&&(n=r.data.error?"<p>".concat(r.data.name,": ").concat(r.data.msg,"</p>"):'<p>Imported <a href="'.concat(r.data.link,'" target="_blank">').concat(r.data.name,"</a></p>"),e.find(".status").prepend(n),e.find(".status").show(),H.importQueue=jQuery.grep(H.importQueue,function(e){return e!=t}),H.imported++,0===H.importQueue.length?(e.find(".process-count").hide(),e.find(".forms-completed").text(H.imported),e.find(".process-completed").show()):(e.find(".form-current").text(H.imported+1),xi(e)))})}function Ei(e){e.preventDefault();var t=!1,r=jQuery('input[name="frm_export_forms[]"]');jQuery('input[name="frm_export_forms[]"]:checked').val()||(r.closest(".frm-table-box").addClass("frm_blank_field"),t="stop");var n=jQuery('input[name="type[]"]');if(jQuery('input[name="type[]"]:checked').val()||"checkbox"!==n.attr("type")||(n.closest("p").addClass("frm_blank_field"),t="stop"),"stop"===t)return!1;e.stopPropagation(),this.submit()}function ki(){var e=jQuery(this).closest(".frm_blank_field");if(void 0!==e){var t=this.name;("type[]"===t&&jQuery('input[name="type[]"]:checked').val()||"frm_export_forms[]"===t&&jQuery(this).val())&&e.removeClass("frm_blank_field")}}function Qi(){null!==jQuery(this).val().match(/\.csv$/i)?jQuery(".show_csv").fadeIn():jQuery(".show_csv").fadeOut()}function Si(){var e=document.querySelector('select[name="format"]');return e?e.value:""}function Ai(e){var t,r,n=e.target.value;Ii(n),Li.call(e.target),t=n,r=document.getElementById("frm-export-select-all"),"csv"===t?(r.checked=!1,r.disabled=!0):r.disabled=!1}function Li(){var e=jQuery(this),t=e.find(":selected"),r=t.data("support"),n=r.indexOf("|");jQuery('input[name="type[]"]').each(function(){this.checked=!1,r.includes(this.value)?(this.disabled=!1,-1===n&&(this.checked=!0)):this.disabled=!0}),"csv"===e.val()?(jQuery(".csv_opts").show(),jQuery(".xml_opts").hide()):(jQuery(".csv_opts").hide(),jQuery(".xml_opts").show());var o=t.data("count"),i=jQuery('input[name="frm_export_forms[]"]');"single"===o?(i.prop("multiple",!1),i.prop("checked",!1)):(i.prop("multiple",!0),i.prop("disabled",!1)),e.trigger("change")}function Ii(e){if(""!==e){var t=document.querySelectorAll(".frm-is-repeater");t.length&&("csv"===e?t.forEach(function(e){e.classList.remove("frm_hidden")}):t.forEach(function(e){e.classList.add("frm_hidden")}),Wi.call(document.querySelector(".frm-auto-search")))}}function qi(){var e=jQuery("select[name=format]").find(":selected").data("count"),t=jQuery('input[name="frm_export_forms[]"]');"single"===e&&this.checked?(t.prop("disabled",!0),this.removeAttribute("disabled")):t.prop("disabled",!1)}function Bi(e){(e?jQuery(e).find(".frm_multiselect"):jQuery(".frm_multiselect")).hide().each(frmDom.bootstrap.multiselect.init)}function Ci(e){e.preventDefault(),Oi(this,"frm_multiple_addons")}function Ni(e){e.preventDefault(),Oi(this,"frm_activate_addon")}function Ti(e){e.preventDefault(),Oi(this,"frm_install_addon")}function Oi(e,t){r(1105).toggleAddonState(e,t)}function Fi(){Mi()}function Di(e){!function(e,t,r){var n=jQuery("#frm_leave_email_error");n.removeClass("frm_hidden").attr("frm-error",r),jQuery("#frm_leave_email").one("keyup",function(){n.addClass("frm_hidden")})}(0,0,e)}function Mi(){var e=document.getElementById("frmapi-email-form");jQuery.ajax({dataType:"json",url:e.getAttribute("data-url"),success:function(t){var r=t.renderedHtml;r=r.replace(/<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi,""),e.innerHTML=r}})}function Pi(e){frmDom.autocomplete.initSelectionAutocomplete(e)}function Ri(e){var t=this.parentNode.parentNode,r=t.elements.type.value;e.preventDefault(),this.classList.add("frm_loading_button"),Hi(t,r,this)}function zi(e){var t=this.elements.type.value,r=this.querySelector("button");e.preventDefault(),r.classList.add("frm_loading_button"),Hi(this,t,r)}function Hi(e,t,r){var n=function(e){var t,r,n={},o=e.elements;for(r=0;r<o.length;r++){var i=o[r],a=i.name,l=i.value,s=a.match(/(.*)\[(.*)\]/);("radio"!==i.type&&"checkbox"!==i.type||i.checked)&&(null===s?Reflect.has(n,a)?(Array.isArray(n[a])||(n[a]=[n[a]]),n[a].push(l)):n[a]=l:(a=s[1],t=s[2],Reflect.has(n,a)||(n[a]={}),n[a][t]=l))}return n}(e),o=n.template_name,i=n.template_desc,a=e.elements.link.value,l={action:t,xml:a,name:o,desc:i,form:JSON.stringify(n),nonce:frmGlobal.nonce},s={formData:n};Ji(l=wp.hooks.applyFilters("frm_before_install_new_form",l,s),function(t){if(void 0!==t.redirect){var n=t.redirect;if(void 0===e.elements.redirect)window.location=n;else{var o=document.getElementById("frm-redirect-link");void 0!==a&&o&&(o.setAttribute("href",n),o.classList.remove("frm_grey","disabled"),(i=e.parentNode.parentNode).classList.add("frm_grey"),i.nextElementSibling.classList.remove("frm_grey"),r.classList.add("frm_grey","disabled"))}}else jQuery(".spinner").css("visibility","hidden"),"string"==typeof t.message&&function(e){var t=h(e);t.style.padding="20px 40px",frmDom.modal.maybeCreateModal("frmInstallFormErrorModal",{title:P("Unable to install template","formidable"),content:t}).classList.add("frm_common_modal")}(t.message);var i;r.classList.remove("frm_loading_button")})}function Gi(e){var t=document.getElementById("frm_captcha_threshold_container");t&&t.classList.toggle("frm_hidden","v3"!==e.target.value)}function Ui(e){var t=this.getAttribute("data-id");e.preventDefault(),Ji({action:"frm_forms_trash",id:t,nonce:frmGlobal.nonce},function(){var e=document.getElementById("frm-template-custom-".concat(t));Xi(e,function(){e.remove()})})}function Wi(){var e,t,r=!1,n=this.value.toLowerCase(),o=this.getAttribute("data-tosearch"),i=document.getElementsByClassName(o);for("SELECT"===this.tagName&&(n=function(e){for(var t,r=[],n=null==e?void 0:e.options,o=0,i=null==n?void 0:n.length;o<i;o++)(t=n[o]).selected&&r.push(t.value);return r}(this),n=n.join("|").toLowerCase(),r=!0),e=0;e<i.length;e++){var a=i[e].textContent.toLowerCase(),l=!("xml"===Si()&&i[e].classList.contains("frm-is-repeater"));""===n?(l&&si(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.remove("frm-search-result")):r&&new RegExp(n).test(a)||a.includes(n)||$i(a,n)?(l&&si(i[e])&&i[e].classList.remove("frm_hidden"),i[e].classList.add("frm-search-result")):(i[e].classList.add("frm_hidden"),i[e].classList.remove("frm-search-result"))}(t=document.querySelector("#frm-insert-fields"))&&t.querySelectorAll(":scope > .frm-with-line").forEach(function(e){var t=e.nextElementSibling;if(t){var r=t.querySelectorAll(":scope > li.frmbutton"),n=Array.from(r).every(function(e){return e.classList.contains("frm_hidden")});e.classList.toggle("frm_hidden",n)}}),jQuery(this).trigger("frmAfterSearch")}function $i(e,t){return"s"!==t&&"s"!==e[e.length-1]&&"".concat(e,"s").includes(t)}function Vi(e){e.stopPropagation()}function Ki(e,t){var r=document.createEvent("HTMLEvents");r.initEvent(t,!1,!0),e.dispatchEvent(r)}function Ji(e,t){var r,n=new XMLHttpRequest,o="string"==typeof e?e:Object.keys(e).map(function(t){return"".concat(encodeURIComponent(t),"=").concat(encodeURIComponent(e[t]))}).join("&");return n.open("post",ajaxurl,!0),n.onreadystatechange=function(){if(n.readyState>3&&200==n.status){r=n.responseText;try{r=JSON.parse(r)}catch(e){}t(r)}},n.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n.send(o),n}function Xi(e,t){e.classList.add("frm-fade"),setTimeout(t,1e3)}function Yi(e){jQuery(e).css("visibility","hidden")}function Zi(e){jQuery(e).css("visibility","visible")}function ea(e,t){return r(4260).initModal(e,t)}function ta(e,t,r){if("#"===t){var n=document.getElementById(e);if(void 0!==r)n.style.display=r?"block":"none";else{var o=n.style.display;n.style.display="none"===o?"block":"none"}}else void 0!==r?r?e.show():e.hide():e.is(":visible")?e.hide():e.show()}function ra(){window.onbeforeunload=null;var e=jQuery(window);e.off("beforeunload.widgets"),e.off("beforeunload.edit-post")}function na(){var e=jQuery(this).closest(".frm-single-settings").data("fid"),t=document.getElementById("frm_field_id_".concat(e));if(t&&"form"===t.dataset.type)if(t=jQuery(t),this.options[this.selectedIndex].value){t.find(".frm-not-set")[0].classList.add("frm_hidden");var r=t.find(".frm-embed-message");r.html(r.data("embedmsg")+this.options[this.selectedIndex].text),t.find(".frm-embed-field-placeholder")[0].classList.remove("frm_hidden")}else t.find(".frm-not-set")[0].classList.remove("frm_hidden"),t.find(".frm-embed-field-placeholder")[0].classList.add("frm_hidden")}function oa(e){var t=e.target,r=t.value.trim();if(!r.includes("[")||!r.includes("]")){if(isNaN(r.replace(/,/,""))){var n=P("Please enter a valid number.","formidable");return frmAdminBuild.infoModal(n),void function(e){var t=document.querySelectorAll("#frm_info_modal .dismiss, #frm_info_modal #frm-info-click, .ui-widget-overlay.ui-front");function r(){e.classList.add("frm_invalid_field"),setTimeout(function(){return e.focus()},0),t.forEach(function(e){e.removeEventListener("click",r)})}t.forEach(function(e){e.addEventListener("click",r)})}(t)}t.classList.remove("frm_invalid_field")}}function ia(){var e=jQuery(this).closest(".frm-single-settings"),t=e.find(".frmjs_product_choices"),r=e.find(".frm_prod_options_heading"),n=this.options[this.selectedIndex].value,o=e[0].querySelector(".frm_display_format_options");o&&o.setAttribute("data-product-type",n),t.removeClass("frm_prod_type_single frm_prod_type_user_def"),r.removeClass("frm_prod_user_def"),"single"===n?t.addClass("frm_prod_type_single"):"user_def"===n&&(t.addClass("frm_prod_type_user_def"),r.addClass("frm_prod_user_def")),wp.hooks.doAction("frm_product_type_toggled",n,e[0])}function aa(e){var t=document.getElementById("frm_field_id_".concat(e));return!!t&&"product"===t.getAttribute("data-type")}function la(){var e=function(e,t){return window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]},t=function(e,t,r){window.frmCachedSubFields=window.frmCachedSubFields||{},window.frmCachedSubFields[e]=window.frmCachedSubFields[e]||{},window.frmCachedSubFields[e][t]=r},r=[1,2,3,4,5,6,7,8,9,10,11,12].map(function(e){return"frm".concat(e)}),o=["first","middle","last"];document.addEventListener("change",function(i){i.target.matches(".frm_name_layout_dropdown")&&function(i){var a,l=i.target.value.split("_"),s=i.target.dataset.fieldId,c=document.querySelector("#field_".concat(s,"_inner_container .frm_combo_inputs_container")),d=(a=l.length,"frm".concat(parseInt(12/a)));o.forEach(function(e){var o,i=c.querySelector('[data-sub-field-name="'.concat(e,'"]'));i&&(i.classList.add("frm_hidden"),(o=i.classList).remove.apply(o,n(r)),t(s,e,i))}),l.forEach(function(t){var r=e(s,t);r&&(r.classList.remove("frm_hidden"),r.classList.add(d),c.append(r))}),o.forEach(function(e){var r=document.querySelector(".frm_sub_field_options-".concat(e,'[data-field-id="').concat(s,'"]'));r&&(r.classList.add("frm_hidden"),t(s,"".concat(e,"_options"),r))}),l.forEach(function(t){var r=e(s,"".concat(t,"_options"));r&&r.classList.remove("frm_hidden")})}(i)},!1)}function sa(e,t){var r,n,o,i=!1,a=!1;(r=t.newOption?(new DOMParser).parseFromString(t.newOption,"text/html").body.childNodes[0]:t).querySelectorAll("svg").forEach(function(e){(n=e.getElementsByTagNameNS("http://www.w3.org/2000/svg","use")[0])&&("#frm_drag_icon"===(o=ti(n))&&(i=!0),"#frm_save_icon"===o&&(a=!0))}),i||r.prepend(L.drag.cloneNode(!0)),r.querySelector("[id^=field_key_".concat(e,"-]"))&&!a&&r.querySelector("[id^=field_key_".concat(e,"-]")).after(L.save.cloneNode(!0)),t.newOption&&(t.newOption=r)}function ca(){var e=document.getElementById("frm_leave_email").value.trim();if(""!==e)if(!1!==/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i.test(e)){var t=jQuery("#frmapi-email-form").find("form"),r=t.find('[type="email"]').not(".frm_verify");if(r.length){if(document.getElementById("frm_empty_inbox")){document.getElementById("frm-add-my-email-address").remove();var n=document.getElementById("frm_leave_email_wrapper");if(n){n.classList.add("frm_hidden");var o=b({className:"frm-wait frm_spinner"});o.style.visibility="visible",o.style.float="none",o.style.width="unset",n.parentElement.insertBefore(o,n.nextElementSibling)}}r.val(e),jQuery.ajax({type:"POST",url:t.attr("action"),data:"".concat(t.serialize(),"&action=frm_forms_preview")}).done(function(e){if(jQuery(e).find(".frm_message").text().trim().includes("Thanks!")){var t=document.getElementById("frmapi-email-form").parentElement.querySelector(".frm_spinner");t&&t.remove(),wp.hooks.applyFilters("frm_thank_you_on_signup",!0)&&document.getElementById("frm_leave_email_wrapper").replaceWith(b(P("Thank you for signing up!","formidable")))}else Di("invalid")})}}else Di("invalid");else Di("empty")}function da(e){var t;if(W||e.stopPropagation(),!(e.target.classList.contains("frm-show-box")||null!==(t=e.target.parentElement)&&void 0!==t&&t.classList.contains("frm-show-box"))){var r=document.getElementById("frm_adv_info");r&&(r.dataset.fills===e.target.id&&void 0!==e.target.id||e.target.closest("#frm_adv_info")||"none"===r.style.display||vi(r))}}return{init:function(){var e,t,o,i,a,l,s;!function(){jQuery(document).on("click","#frm-add-my-email-address",function(e){e.preventDefault(),ca()});var e=document.getElementById("frm_empty_inbox"),t=document.getElementById("frm_leave_email");if(e&&t){var r=document.getElementById("frm-leave-email-modal");r.classList.remove("frm_hidden"),r.querySelector(".frm_modal_footer").classList.add("frm_hidden"),t.addEventListener("keyup",function(e){if("Enter"===e.key){var t=document.getElementById("frm-add-my-email-address");t&&t.click()}})}}(),t=document.querySelector(".frm-admin-footer-links"),o=null!==(e=document.querySelector(".frm_page_container"))&&void 0!==e?e:document.getElementById("wpbody-content"),t&&o&&(o.append(t),t.classList.remove("frm_hidden")),document.addEventListener("show.bs.dropdown",function(){Y()}),H={},jQuery(".wp-admin").on("click",function(e){var t=jQuery(e.target),r=jQuery(".dropdown.open");!r.length||t.hasClass("dropdown")||t.closest(".dropdown").length||r.removeClass("open")}),jQuery("#frm_bs_dropdown:not(.open) a").on("click",Vt),void 0===T&&(T=jQuery(document.getElementById("form_id")).val()),document.querySelectorAll(".frm-warning-dismiss").forEach(function(e){E(e,Kt)}),frmAdminBuild.inboxBannerInit(),I.length>0?frmAdminBuild.buildInit():null!==document.getElementById("frm_notification_settings")?frmAdminBuild.settingsInit():null!==document.getElementById("frm_styling_form")?frmAdminBuild.styleInit():null!==document.getElementById("form_global_settings")?frmAdminBuild.globalSettingsInit():null!==document.getElementById("frm_export_xml")?frmAdminBuild.exportInit():null!==document.querySelector(".frm-inbox-wrapper")?frmAdminBuild.inboxInit():null!==document.getElementById("frm-welcome")?frmAdminBuild.solutionInit():(function(){if(document.body.classList.contains("frm-admin-page-entries")){var e=document.getElementById("screen-options-wrap");if(e){var t=h({className:"frm_warning_style",text:P("Only 10 columns can be selected at a time.","formidable")});t.style.margin=0;var r=e.querySelector("legend");r.parentNode.insertBefore(t,r.nextElementSibling);var n=Array.from(e.querySelectorAll('input[type="checkbox"]')),o=function(){n.reduce(function(e,t){return t.checked?e+1:e},0)>=10?(t.classList.remove("frm_hidden"),n.forEach(function(e){e.checked||(e.parentNode.classList.add("frm_noallow"),e.disabled=!0)})):t.classList.add("frm_hidden")};o(),n.forEach(function(e){e.addEventListener("change",function(e){e.target.checked?o():(t.classList.add("frm_hidden"),n.forEach(function(e){e.parentNode.classList.remove("frm_noallow"),e.disabled=!1}))})})}}}(),Pi(),jQuery("[data-frmprint]").on("click",function(){return window.print(),!1})),jQuery(document).on("change","select[data-toggleclass], input[data-toggleclass]",$o),function(){function e(e){var t=e.options[e.selectedIndex];e.querySelectorAll("option[data-dependency]:not([data-dependency-skip])").forEach(function(e){var r=document.querySelector(e.dataset.dependency);null==r||r.classList.toggle("frm_hidden",t!==e)})}document.querySelectorAll("select.frm_select_with_dependency").forEach(e),frmDom.util.documentOn("change","select.frm_select_with_dependency",function(t){return e(t.target)})}(),(jQuery(document.getElementById("frm_adv_info")).length>0||jQuery(".frm_field_list").length>0)&&frmAdminBuild.panelInit(),i=jQuery(".wrap, .frm_wrap"),a=document.getElementById("frm_confirm_modal"),l=!1,s=!1,jQuery(a).on("click","[data-deletefield]",Gr),jQuery(a).on("click","[data-removeid]",Z),jQuery(a).on("click","[data-trashtemplate]",Ui),i.on("click",".frm_remove_tag, .frm_remove_form_action",Z),i.on("click","a[data-frmverify]",$),i.on("click","a[data-frmtoggle]",J),i.on("click","a[data-frmhide], a[data-frmshow]",X),i.on("change","input[data-frmhide], input[data-frmshow]",X),i.on("click",".widget-top,a.widget-action",te),function(e){e.on("keydown",".widget-top",function(e){e.currentTarget===e.target&&("Enter"!==e.key&&" "!==e.key||(e.preventDefault(),te(e,e.currentTarget)))});var t=function(e){return function(t){t.key===e&&(t.preventDefault(),t.currentTarget.click())}};e.on("keydown",".frm_form_action_settings .frm_duplicate_form_action, .frm_form_action_settings .frm_remove_form_action",t(" ")),e.on("keydown",".frm_form_action_settings .frm_toggle",t("Enter"))}(i),i.on("mouseenter.frm",".frm_bstooltip, .frm_help",function(){jQuery(this).off("mouseenter.frm"),function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=e;(r.hasAttribute("data-toggle")||r.hasAttribute("data-bs-toggle"))&&(r.parentElement.setAttribute("title",r.getAttribute("title")),r.removeAttribute("title"),r.classList.remove("frm_bstooltip"),r.parentElement.classList.add("frm_bstooltip"),r=r.parentElement);var n=new bootstrap.Tooltip(r);t&&(Y(),n.show())}(this,!0)}),jQuery(document).on("click","#doaction, #doaction2",function(e){var t="doaction"===this.id?"top":"bottom",r=document.getElementById("bulk-action-selector-".concat(t)),n=document.getElementById("confirm-bulk-delete-".concat(t));if(r&&n){if(l=this,!s&&"bulk_delete"===r.value)return e.preventDefault(),V(n),!1}else l=!1}),jQuery(document).on("click","#frm-confirmed-click",function(e){if(!1!==l&&!e.target.classList.contains("frm-btn-inactive"))return"confirm-bulk-delete"===this.getAttribute("href")?(e.preventDefault(),s=!0,l.click(),!1):void 0}),r(4260).initUpgradeModal(),frmDom.util.documentOn("click","[data-modal-title]",vo);var c=jQuery(document.getElementById("frm_shortcodediv"));c.length>0&&(jQuery("a.edit-frm_shortcode").on("click",function(){return c.is(":hidden")&&(c.slideDown("fast"),this.style.display="none"),!1}),jQuery(".cancel-frm_shortcode","#frm_shortcodediv").on("click",function(){return c.slideUp("fast"),c.siblings("a.edit-frm_shortcode").show(),!1})),jQuery(document).on("click","#frm-nav-tabs a",oe),jQuery(".post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a").on("click",function(){var e=this.classList.contains("frm_show_upgrade_tab");if(!this.classList.contains("frm_noallow")||e)return e&&this.classList.contains("frm_show_expired_modal")?(wp.hooks.doAction("frm_show_expired_modal",this),!1):(e&&yo(this),ie(this),!1)}),ie(jQuery(".frm-category-tabs .starttab a"),"auto"),jQuery(document).on("click","#frm-fid-search-menu a",function(){var e=this.id.replace("fid-","");return jQuery('select[name="fid"]').val(e),co(document.getElementById("posts-filter")),!1}),jQuery(".frm_select_box").on("click focus",function(){this.select()}),jQuery(document).on("input search change",".frm-auto-search:not(#frm-form-templates-page #template-search-input)",Wi),jQuery(document).on("focusin click",".frm-auto-search",Vi);var d=jQuery(".frm-auto-search");""!==d.val()&&d.trigger("keyup"),FrmFormsConnect.init(),jQuery(document).on("click",".frm-install-addon",Ti),jQuery(document).on("click",".frm-activate-addon",Ni),jQuery(document).on("click",".frm-solution-multiple",Ci),jQuery("button, input[type=submit]").on("click",ra),document.addEventListener("click",function(e){if("LABEL"===e.target.nodeName){var t=e.target.getAttribute("for");if(t){var r=document.getElementById(t);if(r&&r.nextElementSibling){var n=r.nextElementSibling.querySelector("button.dropdown-toggle.multiselect");n&&setTimeout(function(){return n.click()},0)}}}}),frmAdminBuild.hooks.addFilter("frm_before_embed_modal",function(e,t){var r,n,o=t.element;if("form"!==t.type)return e;var i=o.closest("tr");if(i)r=parseInt(i.querySelector(".column-id").textContent),n=i.querySelector(".column-form_key").textContent;else{r=document.getElementById("form_id").value;var a=document.getElementById("frm_form_key");if(a)n=a.value;else{var l=document.getElementById("frm-previewDrop");l&&(n=l.nextElementSibling.querySelector(".dropdown-item a").getAttribute("href").split("form=")[1])}}return[r,n]}),I.on("click","> li, .frm_grid_container li",function(){var e,t=(null===(e=this.querySelector("li"))||void 0===e?void 0:e.dataset.fid)||this.dataset.fid;!function(e){var t=document.querySelectorAll("[id^=frm_delete_field_".concat(e,"-]"));t.length<2||n(t).slice(1).forEach(function(t,r){t.classList.contains("frm_other_option")||sa(e,t)})}(t),function(e){var t=document.getElementById("frm_field_".concat(e,"_opts"));if(t){var r=t.querySelector(".frm_option_template"),n=null==r?void 0:r.querySelector(".frm_remove_tag"),o=null==r?void 0:r.querySelector(".frm_add_opt");if(n&&o){var i=t.querySelectorAll(".frm_single_option:not(.frm_option_template)"),a=i.length>1;i.forEach(function(e){if(!e.querySelector(".frm_remove_tag")){var t=e.dataset.optkey;if(void 0!==t){var r=n.cloneNode(!0);["removeid","removemore"].forEach(function(e){var n=r.dataset[e];n&&(r.dataset[e]=n.replace("-000","-".concat(t)))}),r.classList.toggle("frm_disabled",!a);var i=e.querySelector(".frm_option_key");i?i.before(r,o.cloneNode(!0)):e.append(r,o.cloneNode(!0))}}})}}}(t)});var u=document.getElementById("frm_small_screen_proceed_button");u&&E(u,function(){var e;null===(e=document.getElementById("frm_small_device_message_container"))||void 0===e||e.remove(),k("small_screen_proceed",new FormData)});var f=document.getElementById("frm_sale_banner"),m=null==f?void 0:f.querySelector(".dismiss");f&&(E(f,function(e){e.target.closest(".dismiss")||(window.location.href=f.getAttribute("data-url"))}),m&&E(m,function(){f.remove();var e=new FormData;k("sale_banner_dismiss",e)}))},buildInit:function(){var e,t;jQuery("#frm_builder_page").on("mouseup","*:not(.frm-show-box)",da),Q=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;return frmDom.util.debounce(e,t)}(he,10),S=document.getElementById("post-body-content"),A=jQuery(S),ze(),ae("ul.frm_sorting"),e=jQuery("#frm_builder_page"),t={items:".frm_sortable_field_opts li",axis:"y",opacity:.65,forcePlaceholderSize:!1,handle:".frm-drag",helper:function(e,t){return C=t.clone().insertAfter(t),t.clone()},stop:function(e,t){C&&C.remove(),Qn(t.item.attr("id").replace("frm_delete_field_","").replace("-".concat(t.item.data("optkey"),"_container"),"")),ci()}},jQuery(e).sortable(t),document.querySelectorAll(".field_type_list > li:not(.frm_show_upgrade):not(.frm_show_update)").forEach(de),jQuery("ul.field_type_list, .field_type_list li, ul.frm_code_list, .frm_code_list li, .frm_code_list li a, #frm_adv_info #category-tabs li, #frm_adv_info #category-tabs li a").disableSelection(),jQuery(".frm_submit_ajax").on("click",so),jQuery(".frm_submit_no_ajax").on("click",fo),_o(),jQuery("a.edit-form-status").on("click",Kn),jQuery(".cancel-form-status").on("click",Jn),jQuery(".save-form-status").on("click",function(){var e=jQuery(document.getElementById("form_change_status")).val();return jQuery('input[name="new_status"]').val(e),jQuery(document.getElementById("form-status-display")).html(e),jQuery(".cancel-form-status").trigger("click"),!1}),jQuery(".frm_form_builder form").first().on("submit",function(){jQuery(".inplace_field").trigger("blur")}),Bi(),on();var r,n=jQuery(q),o=document.getElementById("frm_form_editor_container");n.on("click",".frm_add_logic_row",Vr),n.on("click",".frm_add_watch_lookup_row",Jr),n.on("change",".frm_get_values_form",rn),n.on("change",".frm_logic_field_opts",Hn),n.on("frm-multiselect-changed",'select[name^="field_options[admin_only_"]',Xn),jQuery(document.getElementById("frm-insert-fields")).on("click",".frm_add_field",We),I.on("click",".frm_clone_field",Je),n.on("blur",'input[id^="frm_calc"]',pt),n.on("change","input.frm_format_opt, input.frm_max_length_opt",At),n.on("change click","[data-changeme]",Qt),n.on("click","input.frm_req_field",Lt),n.on("click",".frm_mark_unique",qt),n.on("change",".frm_repeat_format",yn),n.on("change",".frm_repeat_limit",hn),n.on("change",".frm_js_checkbox_limit",bn),n.on("input",'input[name^="field_options[add_label_"]',function(){wn(this,"add")}),n.on("input",'input[name^="field_options[remove_label_"]',function(){wn(this,"remove")}),n.on("change",'select[name^="field_options[data_type_"]',nn),jQuery(o).on("click",".frm-collapse-page",an),jQuery(o).on("click",".frm-collapse-section",cn),n.on("click",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",dn),n.on("keydown",".frm-single-settings h3, .frm-single-settings h4.frm-collapsible",function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),dn.call(this,e))}),jQuery(o).on("show.bs.dropdown hide.bs.dropdown",at),n.on("change",".frm_toggle_sep_values",Dt),n.on("change",".frm_toggle_image_options",Mt),n.on("click",".frm_remove_image_option",Wt),n.on("click",".frm_choose_image_box",Ut),n.on("change",".frm_hide_image_text",Gt),n.on("change",".frm_field_options_image_size",zt),n.on("click",".frm_multiselect_opt",$t),I.on("mousedown","input, textarea, select",Jt),I.on("click","input[type=radio], input[type=checkbox]",Jt),I.on("click",".frm_delete_field",tr),I.on("click",".frm_select_field",rr),jQuery(document).on("click",".frm_delete_field_group",nr),jQuery(document).on("click",".frm_clone_field_group",or),jQuery(document).on("click","#frm_field_group_controls > span:first-child",ir),jQuery(document).on("click",".frm-row-layout-option",hr),jQuery(document).on("click",".frm-merge-fields-into-row .frm-row-layout-option",br),jQuery(document).on("click",".frm-custom-field-group-layout",jr),jQuery(document).on("click",".frm-merge-fields-into-row .frm-custom-field-group-layout",Er),jQuery(document).on("click",".frm-break-field-group",Lr),I.on("click","#frm_field_group_popup .frm_grid_container input",Ir),jQuery(document).on("click",".frm-cancel-custom-field-group-layout",qr),jQuery(document).on("click",".frm-save-custom-field-group-layout",Cr),I.on("click","ul.frm_sorting",Nr),jQuery(document).on("click",".frm-merge-fields-into-row",Rr),jQuery(document).on("click",".frm-delete-field-groups",Hr),I.on("click",'.frm-field-action-icons [data-toggle="dropdown"]',function(){this.closest("li.form-field").classList.add("frm-field-settings-open"),jQuery(document).on("click","#frm_builder_page",et)}),I.on("mousemove","ul.frm_sorting",tt),I.on("show.bs.dropdown",".frm-field-action-icons",ot),jQuery(document).on("show.bs.dropdown","#frm_field_group_controls",it),n.on("click",".frm_single_option a[data-removeid]",Xt),n.on("mousedown",".frm_single_option input[type=radio]",Yt),n.on("focusin",".frm_single_option input[type=text]",Zt),n.on("click",".frm_add_opt",Tt),n.on("change",".frm_single_option input",xn),n.on("change",".frm_image_id",xn),n.on("change",".frm_toggle_mult_sel",Ot),I.on("click",".frm_primary_label",fn),I.on("click",".frm_description",mn),I.on("click","li.ui-state-default:not(.frm_noallow)",pn),I.on("dblclick","li.ui-state-default",vn),n.on("change",".frm_tax_form_select",jn),n.on("change","select.conf_field",Bt),n.on("change",".frm_get_field_selection",Gn),n.on("click",".frm-show-inline-modal",eo),n.on("keydown",".frm-show-inline-modal",function(e){var t=e.key;"Enter"!==t&&" "!==t||(e.preventDefault(),eo.call(this,e))}),n.on("click",".frm-inline-modal .dismiss",to),jQuery(document).on("change","[data-frmchange]",no),document.addEventListener("click",ro),n.on("change",".frm_include_extras_field",wt),n.on("change",'select[name^="field_options[form_select_"]',na),jQuery(document).on("submit","#frm_js_build_form",di),jQuery(document).on("change","#frm_builder_page input:not(.frm-search-input):not(.frm-custom-grid-size-input), #frm_builder_page select, #frm_builder_page textarea",ci),Et(),frmDom.util.documentOn("change",".frm_product_price",oa),jQuery(document).on("change",".frmjs_prod_data_type_opt",ia),jQuery(document).on("focus",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',Yr),jQuery(document).on("blur",'.frm-single-settings ul input[type="text"][name^="field_options[options_"]',en),frmDom.util.documentOn("click",".frm-show-field-settings",pn),frmDom.util.documentOn("change","select.frm_format_dropdown, select.frm_phone_type_dropdown",gn),n.on("keydown",'.frm_single_option input[name^="field_options["], .frm_single_option input[name^="rows_"]',function(e){"Enter"===e.key&&function(e){var t=e.closest(".frm_single_option").parentElement.querySelectorAll('.frm_single_option input[name^="field_options[" ], .frm_single_option input[name^="rows_"]'),r=Array.from(t),n=r.indexOf(e);if(!(n<0)){var o=r.slice(n+1).find(function(e){return null!==e.offsetParent});if(o){o.focus();var i=o.value.length;o.setSelectionRange(i,i)}}}(e.currentTarget)}),!1!==(r=ea("#frm-bulk-modal","700px"))&&(jQuery(".frm-insert-preset").on("click",Nt),jQuery(q).on("click","a.frm-bulk-edit-link",function(e){e.preventDefault();var t="",n=jQuery(this).closest("[data-fid]").data("fid"),o=Dn(n),i=aa(n),a=document.getElementById("frm_field_".concat(n,"_opts"));if(a){var l=a.getElementsByTagName("li");document.getElementById("bulk-field-id").value=n;for(var s=0;s<l.length;s++){var c=l[s].getAttribute("data-optkey");if("000"!==c){var d=document.getElementsByName("field_options[options_".concat(n,"][").concat(c,"][label]"))[0];void 0!==d&&(t+=d.value,o&&(t+="|".concat(document.getElementsByName("field_options[options_".concat(n,"][").concat(c,"][value]"))[0].value)),i&&(t+="|".concat(document.getElementsByName("field_options[options_".concat(n,"][").concat(c,"][price]"))[0].value)),t+="\r\n")}s>=l.length-1&&(document.getElementById("frm_bulk_options").value=t)}return r.dialog("open"),!1}}),jQuery("#frm-update-bulk-opts").on("click",function(){var e=document.getElementById("bulk-field-id").value;document.getElementById("bulk-option-type").value||(this.classList.add("frm_loading_button"),frmAdminBuild.updateOpts(e,document.getElementById("frm_bulk_options").value,r),ci())})),Zn(),document.addEventListener("frm_added_field",Zn),Ke(),la(),$n(),frmDom.util.documentOn("change",".frm_show_password_setting_input",function(e){var t=e.target.getAttribute("data-fid"),r=document.getElementById("frm_field_id_".concat(t));r&&r.classList.toggle("frm_disabled_show_password",!e.target.checked)}),document.addEventListener("scroll",ai,!0),document.addEventListener("change",oi),document.querySelector(".frm_form_builder").addEventListener("mousedown",function(e){e.shiftKey&&e.preventDefault()}),wp.hooks.addAction("frmShowedFieldSettings","formidableAdmin",function(e,t){t.querySelectorAll(".frm-collapse-me").forEach(un)},9999),frm_admin_js.pricingFieldsModal&&"object"===i(frm_admin_js.pricingFieldsModal)&&K(frm_admin_js.pricingFieldsModal,"550px")},settingsInit:function(){var e=jQuery(document.getElementById("frm_notification_settings"));e.on("click",".frm_email_buttons",So),e.on("click",".frm_remove_field",Ao),e.on("change",".frm_to_row, .frm_from_row",Lo),e.on("change",".frm_tax_selector",Uo),e.on("change","select.frm_single_post_field",Fo),e.on("change","select.frm_toggle_post_content",Do),e.on("change","select.frm_dyncontent_opt",Mo),e.on("change",".frm_post_type",Po),e.on("click",".frm_add_postmeta_row",Ho),e.on("click",".frm_add_posttax_row",zo),e.on("click",".frm_toggle_cf_opts",Wo),e.on("click",".frm_duplicate_form_action",wo),jQuery(".frm_actions_list").on("click",".frm_active_action",Eo),jQuery(document).on("frmAfterSearch","#actions-search-input",ee),Bi(),document.querySelectorAll(".frm_actions_list a[data-actiontype]").forEach(function(e){return Io(e.dataset.actiontype)}),jQuery(".frm_submit_settings_btn").on("click",Vo),_o();var t=jQuery(".frm_form_settings");t.on("click",".frm_add_form_logic",To),t.on("change","input[data-emailkey][data-toggleclass]",Oo),t.on("click",".frm_already_used",Co),document.addEventListener("click",function(e){var t=e.target;t.closest(".frm_image_preview_wrapper")&&(t.closest(".frm_choose_image_box")?Ut.bind(t)(e):t.closest(".frm_remove_image_option")&&Wt.bind(t)(e))}),t.on("mouseup","*:not(.frm-show-box)",da),jQuery(document.getElementById("no_save")).on("change",function(){this.checked&&!0!==confirm(f.no_save_warning)&&jQuery(this).attr("checked",!1)}),document.querySelectorAll('a[href="#spam_settings"]').forEach(function(e){e.addEventListener("click",function(e){e.preventDefault();var t=document.querySelector('.frm-category-tabs a[href="#spam_settings"]');t&&(ie(t),setTimeout(function(){var e=document.getElementById("frm-categorydiv");e&&e.scrollIntoView({block:"start"})},50))})});var r=document.getElementById("frm_include_captcha");if(r){var n=r.checked;r.addEventListener("change",function(){var e=document.getElementById("frm_captcha_add_warning"),t=document.getElementById("frm_captcha_remove_warning");e&&t&&(this.checked!==n?this.checked?(e.style.display="block",t.style.display="none"):(e.style.display="none",t.style.display="block"):(e.style.display="none",t.style.display="none"))})}jQuery('select[name="options[edit_action]"]').on("change",bo);var o=document.getElementById("logged_in");jQuery(o).on("change",function(){this.checked?Zi(".hide_logged_in"):Yi(".hide_logged_in")});var i=jQuery(document.getElementById("frm_cookie_expiration"));jQuery(document.getElementById("frm_single_entry_type")).on("change",function(){"cookie"===this.value?i.fadeIn("slow"):i.fadeOut("slow")});var a=document.getElementById("single_entry");jQuery(a).on("change",function(){this.checked?Zi(".hide_single_entry"):Yi(".hide_single_entry"),this.checked&&"cookie"===jQuery(document.getElementById("frm_single_entry_type")).val()?i.fadeIn("slow"):i.fadeOut("slow")}),jQuery(".hide_save_draft").hide();var l=jQuery(document.getElementById("save_draft"));l.on("change",function(){this.checked?jQuery(".hide_save_draft").fadeIn("slow"):jQuery(".hide_save_draft").fadeOut("slow")}),uo(l);var s=document.getElementById("editable");jQuery(s).on("change",function(){this.checked?(jQuery(".hide_editable").fadeIn("slow"),uo(document.getElementById("edit_action"))):(jQuery(".hide_editable").fadeOut("slow"),jQuery(".edit_action_message_box").fadeOut("slow"))}),jQuery(document).on("change","#protect_files",function(){this.checked?jQuery(".hide_protect_files").fadeIn("slow"):jQuery(".hide_protect_files").fadeOut("slow")}),jQuery(document).on("frm-multiselect-changed","#protect_files_role",Xn),jQuery(document).on("submit",".frm_form_settings",ui),jQuery(document).on("change","#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea",ci),Pi(),jQuery(document).on("frm-action-loaded",hi),frmDom.util.documentOn("change",'.frm_on_submit_type input[type="radio"]',function(e){if(e.target.checked){var t=e.target.closest(".frm_form_action_settings");t.querySelectorAll(".frm_on_submit_dependent_setting:not(.frm_hidden)").forEach(function(e){e.classList.add("frm_hidden")}),t.querySelectorAll(".frm_on_submit_dependent_setting[data-show-if-".concat(e.target.value,"]")).forEach(function(e){e.classList.remove("frm_hidden")}),t.setAttribute("data-on-submit-type",e.target.value)}}),wp.hooks.addAction("frm_reset_fields_updated","formidableAdmin",fi)},panelInit:function(){jQuery(".frm_wrap, #postbox-container-1").on("click",".frm_insert_code",Ko),jQuery(document).on("change",".frm_insert_val",function(){Jo(jQuery(this).data("target"),jQuery(this).val()),jQuery(this).val("")}),jQuery(document).on("click change",'[name="frm-id-key-condition"]',Zo),jQuery(document).on("keyup change",".frm-build-logic",ei),ho(),jQuery(document).on("frmElementAdded",function(e,t){ho(t)}),jQuery(document).on("mousedown",".frm-show-box",ni);var e=document.getElementById("form_settings_page"),t=document.body.classList.contains("post-type-frm_display"),r=document.getElementById("frm_insert_fields_tab");(e||t||W)&&jQuery(document).on("focusin","form input, form textarea",function(n){var o,i,a;if(n.stopPropagation(),ri(this),jQuery(this).is(":not(:submit, input[type=button], .frm-search-input, input[type=checkbox])")){if(jQuery(n.target).closest("#frm_adv_info").length)return;if(e||W)o=jQuery("#frm_html_tab"),jQuery(this).closest("#html_settings").length>0?(o.show(),o.siblings().hide(),jQuery("#frm_html_tab a").trigger("click"),void 0===(a=this.id)||a.includes("-search-input")||(jQuery("#frm-adv-info-tab").attr("data-fills",a.trim()),this.classList.contains("field_custom_html")&&(a="field_custom_html"),jQuery.inArray(a,["after_html","before_html","submit_html","field_custom_html"])>=0&&(jQuery(".frm_code_list li:not(.show_".concat(a,")")).addClass("frm_hidden"),jQuery(".frm_code_list li.show_".concat(a)).removeClass("frm_hidden")))):((i=jQuery(".frm-category-tabs li"))[0]&&(i[0].style.display=""),r.click(),o.hide(),o.siblings().show());else if(t){var l=new CustomEvent("frm_legacy_views_handle_field_focus");l.frmData={idAttrValue:this.id},document.dispatchEvent(l)}}}),jQuery(".frm_wrap, #postbox-container-1").on("mousedown","#frm_adv_info a, .frm_field_list a",function(e){e.preventDefault()});var n=jQuery("#frm_adv_info");n.on("click",".subsubsub a.frmids",function(e){yi("frmids",e)}),n.on("click",".subsubsub a.frmkeys",function(e){yi("frmkeys",e)})},inboxInit:function(){var e;jQuery(".frm_inbox_dismiss").on("click",function(e){var t=this.parentNode.parentNode,r=t.getAttribute("data-message"),n=this.getAttribute("href"),o=t.cloneNode(!0),i=document.querySelector(".frm-dismissed-inbox-messages");if("free_templates"!==r||this.classList.contains("frm_inbox_dismiss")){e.preventDefault();var a={action:"frm_inbox_dismiss",key:r,nonce:frmGlobal.nonce},l="frm_inbox_slide_in"===t.id;l&&(t.classList.remove("s11-fadein"),t.classList.add("s11-fadeout"),t.addEventListener("animationend",function(){return t.remove()},{once:!0})),Ji(a,function(){if(!l)return"#"!==n?(window.location=n,!0):void Xi(t,function(){var e;i&&(o.classList.remove("frm-fade"),null===(e=o.querySelector(".frm-inbox-message-heading .frm_inbox_dismiss"))||void 0===e||e.remove(),i.append(o)),1===t.parentNode.querySelectorAll(".frm-inbox-message-container").length&&(document.getElementById("frm_empty_inbox").classList.remove("frm_hidden"),t.parentNode.closest(".frm-active").classList.add("frm-empty-inbox"),Fi()),t.remove()})})}}),!1===(null===(e=document.getElementById("frm_empty_inbox"))||void 0===e?void 0:e.classList.contains("frm_hidden"))&&Fi()},solutionInit:function(){jQuery(document).on("submit","#frm-new-template",zi)},styleInit:function(){var e=jQuery(".frm_image_preview_wrapper");e.on("click",".frm_choose_image_box",Ut),e.on("click",".frm_remove_image_option",Wt),wp.hooks.doAction("frm_style_editor_init")},customCSSInit:function(){console.warn("Calling frmAdminBuild.customCSSInit is deprecated.")},globalSettingsInit:function(){jQuery(document).on("click","[data-frmuninstall]",bi),Bi();var e=document.getElementById("licenses_settings");e&&jQuery(e).on("click",".edd_frm_save_license",wi),jQuery(document).on("click","#frm-new-template button",Ri),jQuery("#frm-dismissable-cta .dismiss").on("click",function(e){e.preventDefault(),jQuery.post(ajaxurl,{action:"frm_lite_settings_upgrade",nonce:frmGlobal.nonce}),jQuery(".settings-lite-cta").remove()});var t=document.getElementById("frm_re_type");t&&t.addEventListener("change",Gi),document.querySelector(".frm_captchas").addEventListener("change",function(e){var t,r=null===(t=document.querySelector('.frm_captchas input[checked="checked"]'))||void 0===t?void 0:t.value,n=e.target.value!==r;document.querySelector(".captcha_settings .frm_note_style").classList.toggle("frm_hidden",!n)}),frmDom.util.documentOn("submit",".frm_settings_form",function(){N=0});var r=document.getElementById("manage_styles_settings");r&&r.addEventListener("change",function(e){var t=e.target;"SELECT"===t.nodeName&&t.dataset.name&&!t.getAttribute("name")&&t.setAttribute("name",t.dataset.name)});var n=document.getElementById("payments_settings"),o=null==n?void 0:n.querySelectorAll('[name="frm_payment_section"]');o&&o.forEach(function(e){e.addEventListener("change",function(){if(e.checked){var t=n.querySelector('label[for="'.concat(e.id,'"]'));t&&t.setAttribute("aria-selected","true"),o.forEach(function(t){if(t!==e){var r=n.querySelector('label[for="'.concat(t.id,'"]'));r&&r.setAttribute("aria-selected","false")}})}})})},exportInit:function(){jQuery(".frm_form_importer").on("submit",ji),jQuery(document.getElementById("frm_export_xml")).on("submit",Ei),jQuery("#frm_export_xml input, #frm_export_xml select").on("change",ki),jQuery('input[name="frm_import_file"]').on("change",Qi),document.querySelector('select[name="format"]').addEventListener("change",Ai),jQuery('input[name="frm_export_forms[]"]').on("click",qi),Bi(),jQuery(".frm-feature-banner .dismiss").on("click",function(e){e.preventDefault(),jQuery.post(ajaxurl,{action:"frm_dismiss_migrator",plugin:this.id,nonce:frmGlobal.nonce}),this.parentElement.remove()}),Ii(Si()),document.querySelector("#frm-export-select-all").addEventListener("change",function(e){document.querySelectorAll('[name="frm_export_forms[]"]').forEach(function(t){t.checked=e.target.checked})})},inboxBannerInit:function(){var e=document.getElementById("frm_banner");if(e){var t=e.querySelector(".frm-banner-dismiss");document.addEventListener("click",function(r){r.target===t&&Ji({action:"frm_inbox_dismiss",key:e.dataset.key,nonce:frmGlobal.nonce},function(){jQuery(e).fadeOut(400,function(){e.remove()})})})}},updateOpts:function(e,t,r){var n=Dn(e),o=aa(e)?"frm_bulk_products":"frm_import_options";jQuery.ajax({type:"POST",url:ajaxurl,data:{action:o,field_id:e,opts:t,separate:n,nonce:frmGlobal.nonce},success:function(t){document.getElementById("frm_field_".concat(e,"_opts")).innerHTML=t,wp.hooks.doAction("frm_after_bulk_edit_opts",e),Qn(e),void 0!==r&&(r.dialog("close"),document.getElementById("frm-update-bulk-opts").classList.remove("frm_loading_button"))}})},triggerRemoveLogic:function(e,t){jQuery("#frm_logic_".concat(e,"_").concat(t," .frm_remove_tag")).trigger("click")},downloadXML:function(e,t,r){var n="".concat(ajaxurl,"?action=frm_").concat(e,"_xml&ids=").concat(t);null!==r&&(n="".concat(n,"&is_template=").concat(r)),location.href=n},hooks:{applyFilters:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return(t=wp.hooks).applyFilters.apply(t,[e].concat(n))},addFilter:function(e,t,r){return wp.hooks.addFilter(e,"formidable",t,r)},doAction:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return(t=wp.hooks).doAction.apply(t,[e].concat(n))},addAction:function(e,t,r){return wp.hooks.addAction(e,"formidable",t,r)}},settings:{validate:{validateField:u,getRangeSettingsDefaults:m,validateNumberRangeSetting:_,validateStepSetting:p,validateRangeSettings:g}},applyZebraStriping:function(e,t){var r=document.querySelectorAll("".concat(e," tr").concat(t?":not(.".concat(t,")"):""));if(!(r.length<1)){var n=!0;r.forEach(function(e){e.classList.remove("frm-odd","frm-even"),e.classList.add(n?"frm-odd":"frm-even"),n=!n}),document.querySelectorAll(e).forEach(function(e){return e.classList.add("frm-zebra-striping")})}},initModal:ea,infoModal:K,offsetModalY:_i,adjustConditionalLogicOptionOrders:An,addRadioCheckboxOpt:In,installNewForm:Hi,toggleAddonState:Oi,purifyHtml:Tn,loadApiEmailForm:Mi,addMyEmailAddress:ca,fillDropdownOpts:qn,showSaveAndReloadModal:ii,clearSettingsBox:mt,deleteField:Wr,insertFormField:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(r){var n=T,o=0;"summary"===e&&(o=I.children('li[data-type="break"]').length>0?1:0),jQuery.ajax({type:"POST",url:ajaxurl,data:Object.assign(Le(e,0,n,o),{field_options:t}),success:function(t){r(t),setTimeout(function(){Wn(),ut(t,!0);var r=Be(t);r&&wp.hooks.doAction("frm_after_field_added_in_form_builder",{field:t,fieldId:r,fieldType:e,form_id:n})},10)},error:Ne})})},confirmLinkClick:V,handleInsertFieldByDraggingResponse:qe,handleAddFieldClickResponse:Ve,syncLayoutClasses:we,moveFieldSettings:Qo,maybeCollapseSettings:dn}},window.frmAdminBuild=frmAdminBuildJS(),jQuery(document).ready(function(){var e;frmAdminBuild.init(),document.querySelectorAll(".frm-dropdown-menu").forEach(function(e){e.classList.add("dropdown-menu");var t,r,n=e.querySelector(".frm-dropdown-toggle");n&&(n.hasAttribute("role")||n.setAttribute("role","button"),n.hasAttribute("tabindex")||n.setAttribute("tabindex",0)),"UL"===e.tagName&&(r=(r=(r=(r=(r=(r=(t=e).outerHTML).replace("<ul ","<div ")).replace("</ul>","</div>")).replaceAll("<li>",'<div class="dropdown-item">')).replaceAll('<li class="','<div class="dropdown-item ')).replaceAll("</li>","</div>"),t.outerHTML=r)}),null===(e=document.querySelector(".preview.dropdown .frm-dropdown-toggle"))||void 0===e||e.setAttribute("data-bs-toggle","dropdown"),document.querySelectorAll("[data-toggle]").forEach(function(e){return e.setAttribute("data-bs-toggle",e.getAttribute("data-toggle"))})}),window.frm_show_div=function(e,t,r,n){t==r?jQuery(n+e).fadeIn("slow").css("visibility","visible"):jQuery(n+e).fadeOut("slow")},window.frmCheckAll=function(e,t){jQuery('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmCheckAllLevel=function(e,t,r){jQuery(".frm_catlevel_".concat(r)).children(".frm_checkbox").children("label").children('input[name^="'.concat(t,'"]')).prop("checked",Boolean(e))},window.frmGetFieldValues=function(e,t,r,n,o,i){e&&jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_get_field_values¤t_field=".concat(t,"&field_id=").concat(e,"&name=").concat(o,"&t=").concat(n,"&form_action=").concat(jQuery('input[name="frm_action"]').val(),"&nonce=").concat(frmGlobal.nonce),success:function(e){document.getElementById("frm_show_selected_values_".concat(t,"_").concat(r)).innerHTML=e,"function"==typeof i&&i()}})},r(4365),window.frmImportCsv=function(e){var t="";"undefined"!=typeof __FRMURLVARS&&(t=__FRMURLVARS),jQuery.ajax({type:"POST",url:ajaxurl,data:"action=frm_import_csv&nonce=".concat(frmGlobal.nonce,"&frm_skip_cookie=1").concat(t),success:function(t){var r=jQuery(".frm_admin_progress_bar").attr("aria-valuemax"),n=r-t,o=n/r*100;jQuery(".frm_admin_progress_bar").css("width","".concat(o,"%")).attr("aria-valuenow",n),parseInt(t,10)>0?(jQuery(".frm_csv_remaining").html(t),frmImportCsv(e)):(jQuery(document.getElementById("frm_import_message")).html(frm_admin_js.import_complete),setTimeout(function(){location.href="?page=formidable-entries&frm_action=list&form=".concat(e,"&import-message=1")},2e3))}})}})(); | |
| 1 | +/* exported frm_add_logic_row, frm_remove_tag, frm_show_div, frmCheckAll, frmCheckAllLevel */ | |
| 2 | + | |
| 3 | +var frmAdminBuild; | |
| 4 | + | |
| 5 | +var FrmFormsConnect = window.FrmFormsConnect || ( function( document, window, $ ) { | |
| 6 | + | |
| 7 | + /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl */ | |
| 8 | + | |
| 9 | + var el = { | |
| 10 | + licenseBox: document.getElementById( 'frm_license_top' ), | |
| 11 | + messageBox: document.getElementsByClassName( 'frm_pro_license_msg' )[0], | |
| 12 | + btn: document.getElementById( 'frm-settings-connect-btn' ), | |
| 13 | + reset: document.getElementById( 'frm_reconnect_link' ) | |
| 14 | + }; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * Public functions and properties. | |
| 18 | + * | |
| 19 | + * @since 4.03 | |
| 20 | + * | |
| 21 | + * @type {Object} | |
| 22 | + */ | |
| 23 | + var app = { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * Register connect button event. | |
| 27 | + * | |
| 28 | + * @since 4.03 | |
| 29 | + */ | |
| 30 | + init: function() { | |
| 31 | + $( document.getElementById( 'frm_deauthorize_link' ) ).on( 'click', app.deauthorize ); | |
| 32 | + $( '.frm_authorize_link' ).on( 'click', app.authorize ); | |
| 33 | + if ( el.reset !== null ) { | |
| 34 | + $( el.reset ).on( 'click', app.reauthorize ); | |
| 35 | + } | |
| 36 | + | |
| 37 | + $( el.btn ).on( 'click', function( e ) { | |
| 38 | + e.preventDefault(); | |
| 39 | + app.gotoUpgradeUrl(); | |
| 40 | + }); | |
| 41 | + | |
| 42 | + window.addEventListener( 'message', function( msg ) { | |
| 43 | + if ( msg.origin.replace( /\/$/, '' ) !== frmGlobal.app_url.replace( /\/$/, '' ) ) { | |
| 44 | + return; | |
| 45 | + } | |
| 46 | + | |
| 47 | + if ( ! msg.data || 'object' !== typeof msg.data ) { | |
| 48 | + console.error( 'Messages from "' + frmGlobal.app_url + '" must contain an api key string.' ); | |
| 49 | + return; | |
| 50 | + } | |
| 51 | + | |
| 52 | + app.updateForm( msg.data ); | |
| 53 | + }); | |
| 54 | + | |
| 55 | + jQuery( document ).on( 'mouseover', '#frm_new_form_modal .frm-selectable', function() { | |
| 56 | + var $item = jQuery( this ), | |
| 57 | + $icons = $item.find( '.frm-hover-icons' ), | |
| 58 | + $clone; | |
| 59 | + | |
| 60 | + if ( ! $icons.length ) { | |
| 61 | + $clone = jQuery( '#frm-hover-icons-template' ).clone(); | |
| 62 | + $clone.removeAttr( 'id' ); | |
| 63 | + $item.append( $clone ); | |
| 64 | + } | |
| 65 | + | |
| 66 | + $icons.show(); | |
| 67 | + }); | |
| 68 | + | |
| 69 | + jQuery( document ).on( 'mouseout', '#frm_new_form_modal .frm-selectable', function() { | |
| 70 | + var $item = jQuery( this ), | |
| 71 | + $icons = $item.find( '.frm-hover-icons' ); | |
| 72 | + | |
| 73 | + if ( $icons.length ) { | |
| 74 | + $icons.hide(); | |
| 75 | + } | |
| 76 | + }); | |
| 77 | + }, | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * Go to upgrade url. | |
| 81 | + * | |
| 82 | + * @since 4.03 | |
| 83 | + */ | |
| 84 | + gotoUpgradeUrl: function() { | |
| 85 | + var w = window.open( frmGlobal.app_url + '/api-connect/', '_blank', 'location=no,width=500,height=730,scrollbars=0' ); | |
| 86 | + w.focus(); | |
| 87 | + }, | |
| 88 | + | |
| 89 | + updateForm: function( response ) { | |
| 90 | + | |
| 91 | + // Start spinner. | |
| 92 | + var btn = el.btn; | |
| 93 | + btn.classList.add( 'frm_loading_button' ); | |
| 94 | + | |
| 95 | + if ( response.url !== '' ) { | |
| 96 | + app.showProgress({ | |
| 97 | + success: true, | |
| 98 | + message: 'Installing...' | |
| 99 | + }); | |
| 100 | + var fallback = setTimeout( function() { | |
| 101 | + app.showProgress({ | |
| 102 | + success: true, | |
| 103 | + message: 'Installing is taking longer than expected. <a class="frm-install-addon button button-primary frm-button-primary" rel="' + response.url + '" aria-label="Install">Install Now</a>' | |
| 104 | + }); | |
| 105 | + }, 10000 ); | |
| 106 | + $.ajax({ | |
| 107 | + type: 'POST', | |
| 108 | + url: ajaxurl, | |
| 109 | + dataType: 'json', | |
| 110 | + data: { | |
| 111 | + action: 'frm_connect', | |
| 112 | + plugin: response.url, | |
| 113 | + nonce: frmGlobal.nonce | |
| 114 | + }, | |
| 115 | + success: function() { | |
| 116 | + clearTimeout( fallback ); | |
| 117 | + app.activateKey( response ); | |
| 118 | + }, | |
| 119 | + error: function( xhr, textStatus, e ) { | |
| 120 | + clearTimeout( fallback ); | |
| 121 | + btn.classList.remove( 'frm_loading_button' ); | |
| 122 | + app.showMessage({ | |
| 123 | + success: false, | |
| 124 | + message: e | |
| 125 | + }); | |
| 126 | + } | |
| 127 | + }); | |
| 128 | + } else if ( response.key !== '' ) { | |
| 129 | + app.activateKey( response ); | |
| 130 | + } | |
| 131 | + }, | |
| 132 | + | |
| 133 | + activateKey: function( response ) { | |
| 134 | + var btn = el.btn; | |
| 135 | + if ( response.key === '' ) { | |
| 136 | + btn.classList.remove( 'frm_loading_button' ); | |
| 137 | + } else { | |
| 138 | + app.showProgress({ | |
| 139 | + success: true, | |
| 140 | + message: 'Activating...' | |
| 141 | + }); | |
| 142 | + $.ajax({ | |
| 143 | + type: 'POST', | |
| 144 | + url: ajaxurl, | |
| 145 | + dataType: 'json', | |
| 146 | + data: { | |
| 147 | + action: 'frm_addon_activate', | |
| 148 | + license: response.key, | |
| 149 | + plugin: 'formidable_pro', | |
| 150 | + wpmu: 0, | |
| 151 | + nonce: frmGlobal.nonce | |
| 152 | + }, | |
| 153 | + success: function( msg ) { | |
| 154 | + btn.classList.remove( 'frm_loading_button' ); | |
| 155 | + | |
| 156 | + if ( msg.success === true ) { | |
| 157 | + el.licenseBox.classList.replace( 'frm_unauthorized_box', 'frm_authorized_box' ); | |
| 158 | + } | |
| 159 | + | |
| 160 | + app.showMessage( msg ); | |
| 161 | + }, | |
| 162 | + error: function( xhr, textStatus, e ) { | |
| 163 | + btn.classList.remove( 'frm_loading_button' ); | |
| 164 | + app.showMessage({ | |
| 165 | + success: false, | |
| 166 | + message: e | |
| 167 | + }); | |
| 168 | + } | |
| 169 | + }); | |
| 170 | + } | |
| 171 | + }, | |
| 172 | + | |
| 173 | + /* Manual license authorization */ | |
| 174 | + authorize: function() { | |
| 175 | + /*jshint validthis:true */ | |
| 176 | + var button = this; | |
| 177 | + var pluginSlug = this.getAttribute( 'data-plugin' ); | |
| 178 | + var input = document.getElementById( 'edd_' + pluginSlug + '_license_key' ); | |
| 179 | + var license = input.value; | |
| 180 | + var wpmu = document.getElementById( 'proplug-wpmu' ); | |
| 181 | + this.classList.add( 'frm_loading_button' ); | |
| 182 | + if ( wpmu === null ) { | |
| 183 | + wpmu = 0; | |
| 184 | + } else if ( wpmu.checked ) { | |
| 185 | + wpmu = 1; | |
| 186 | + } else { | |
| 187 | + wpmu = 0; | |
| 188 | + } | |
| 189 | + | |
| 190 | + $.ajax({ | |
| 191 | + type: 'POST', url: ajaxurl, dataType: 'json', | |
| 192 | + data: { | |
| 193 | + action: 'frm_addon_activate', | |
| 194 | + license: license, | |
| 195 | + plugin: pluginSlug, | |
| 196 | + wpmu: wpmu, | |
| 197 | + nonce: frmGlobal.nonce | |
| 198 | + }, | |
| 199 | + success: function( msg ) { | |
| 200 | + app.afterAuthorize( msg, input ); | |
| 201 | + button.classList.remove( 'frm_loading_button' ); | |
| 202 | + } | |
| 203 | + }); | |
| 204 | + }, | |
| 205 | + | |
| 206 | + afterAuthorize: function( msg, input ) { | |
| 207 | + if ( msg.success === true ) { | |
| 208 | + input.value = '•••••••••••••••••••'; | |
| 209 | + } | |
| 210 | + | |
| 211 | + app.showMessage( msg ); | |
| 212 | + }, | |
| 213 | + | |
| 214 | + showProgress: function( msg ) { | |
| 215 | + var messageBox = el.messageBox; | |
| 216 | + if ( msg.success === true ) { | |
| 217 | + messageBox.classList.remove( 'frm_error_style' ); | |
| 218 | + messageBox.classList.add( 'frm_message', 'frm_updated_message' ); | |
| 219 | + } else { | |
| 220 | + messageBox.classList.add( 'frm_error_style' ); | |
| 221 | + messageBox.classList.remove( 'frm_message', 'frm_updated_message' ); | |
| 222 | + } | |
| 223 | + messageBox.classList.remove( 'frm_hidden' ); | |
| 224 | + messageBox.innerHTML = msg.message; | |
| 225 | + }, | |
| 226 | + | |
| 227 | + showMessage: function( msg ) { | |
| 228 | + var messageBox = el.messageBox; | |
| 229 | + | |
| 230 | + if ( msg.success === true ) { | |
| 231 | + var d = el.licenseBox; | |
| 232 | + d.className = d.className.replace( 'frm_unauthorized_box', 'frm_authorized_box' ); | |
| 233 | + messageBox.classList.remove( 'frm_error_style' ); | |
| 234 | + messageBox.classList.add( 'frm_message', 'frm_updated_message' ); | |
| 235 | + } else { | |
| 236 | + messageBox.classList.add( 'frm_error_style' ); | |
| 237 | + messageBox.classList.remove( 'frm_message', 'frm_updated_message' ); | |
| 238 | + } | |
| 239 | + | |
| 240 | + messageBox.classList.remove( 'frm_hidden' ); | |
| 241 | + messageBox.innerHTML = msg.message; | |
| 242 | + if ( msg.message !== '' ) { | |
| 243 | + setTimeout( function() { | |
| 244 | + messageBox.innerHTML = ''; | |
| 245 | + messageBox.classList.add( 'frm_hidden' ); | |
| 246 | + messageBox.classList.remove( 'frm_error_style', 'frm_message', 'frm_updated_message' ); | |
| 247 | + }, 10000 ); | |
| 248 | + var refreshPage = document.querySelectorAll( '#frm-welcome' ); | |
| 249 | + if ( refreshPage.length > 0 ) { | |
| 250 | + window.location.reload(); | |
| 251 | + } | |
| 252 | + } | |
| 253 | + }, | |
| 254 | + | |
| 255 | + /* Clear the site license cache */ | |
| 256 | + reauthorize: function() { | |
| 257 | + /*jshint validthis:true */ | |
| 258 | + this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;float:none"></span>'; | |
| 259 | + | |
| 260 | + $.ajax({ | |
| 261 | + type: 'POST', | |
| 262 | + url: ajaxurl, | |
| 263 | + dataType: 'json', | |
| 264 | + data: { | |
| 265 | + action: 'frm_reset_cache', | |
| 266 | + plugin: 'formidable_pro', | |
| 267 | + nonce: frmGlobal.nonce | |
| 268 | + }, | |
| 269 | + success: function( msg ) { | |
| 270 | + el.reset.innerHTML = msg.message; | |
| 271 | + if ( el.reset.getAttribute( 'data-refresh' ) === '1' ) { | |
| 272 | + window.location.reload(); | |
| 273 | + } | |
| 274 | + } | |
| 275 | + }); | |
| 276 | + return false; | |
| 277 | + }, | |
| 278 | + | |
| 279 | + deauthorize: function() { | |
| 280 | + /*jshint validthis:true */ | |
| 281 | + if ( ! confirm( frmGlobal.deauthorize ) ) { | |
| 282 | + return false; | |
| 283 | + } | |
| 284 | + var pluginSlug = this.getAttribute( 'data-plugin' ), | |
| 285 | + input = document.getElementById( 'edd_' + pluginSlug + '_license_key' ), | |
| 286 | + license = input.value, | |
| 287 | + link = this; | |
| 288 | + | |
| 289 | + this.innerHTML = '<span class="frm-wait frm_spinner" style="visibility:visible;"></span>'; | |
| 290 | + | |
| 291 | + $.ajax({ | |
| 292 | + type: 'POST', | |
| 293 | + url: ajaxurl, | |
| 294 | + data: { | |
| 295 | + action: 'frm_addon_deactivate', | |
| 296 | + license: license, | |
| 297 | + plugin: pluginSlug, | |
| 298 | + nonce: frmGlobal.nonce | |
| 299 | + }, | |
| 300 | + success: function() { | |
| 301 | + el.licenseBox.className = el.licenseBox.className.replace( 'frm_authorized_box', 'frm_unauthorized_box' ); | |
| 302 | + input.value = ''; | |
| 303 | + link.innerHTML = ''; | |
| 304 | + } | |
| 305 | + }); | |
| 306 | + return false; | |
| 307 | + } | |
| 308 | + }; | |
| 309 | + | |
| 310 | + // Provide access to public functions/properties. | |
| 311 | + return app; | |
| 312 | + | |
| 313 | +}( document, window, jQuery ) ); | |
| 314 | + | |
| 315 | +function frmAdminBuildJS() { | |
| 316 | + //'use strict'; | |
| 317 | + | |
| 318 | + /*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl, fromDom */ | |
| 319 | + | |
| 320 | + const { tag, div, span, a, svg, img } = frmDom; | |
| 321 | + const { doJsonFetch } = frmDom.ajax; | |
| 322 | + const icons = { | |
| 323 | + save: svg({ href: '#frm_save_icon' }), | |
| 324 | + drag: svg({ href: '#frm_drag_icon', classList: [ 'frm_drag_icon', 'frm-drag' ] }) | |
| 325 | + }; | |
| 326 | + | |
| 327 | + let $newFields = jQuery( document.getElementById( 'frm-show-fields' ) ), | |
| 328 | + builderForm = document.getElementById( 'new_fields' ), | |
| 329 | + thisForm = document.getElementById( 'form_id' ), | |
| 330 | + copyHelper = false, | |
| 331 | + fieldsUpdated = 0, | |
| 332 | + thisFormId = 0, | |
| 333 | + autoId = 0, | |
| 334 | + optionMap = {}, | |
| 335 | + lastNewActionIdReturned = 0; | |
| 336 | + | |
| 337 | + const { __ } = wp.i18n; | |
| 338 | + let debouncedSyncAfterDragAndDrop, postBodyContent, $postBodyContent; | |
| 339 | + | |
| 340 | + if ( thisForm !== null ) { | |
| 341 | + thisFormId = thisForm.value; | |
| 342 | + } | |
| 343 | + | |
| 344 | + // Global settings | |
| 345 | + var s; | |
| 346 | + | |
| 347 | + function showElement( element ) { | |
| 348 | + element[0].style.display = ''; | |
| 349 | + } | |
| 350 | + | |
| 351 | + function hideElement( element ) { | |
| 352 | + element[0].style.display = 'none'; | |
| 353 | + } | |
| 354 | + | |
| 355 | + function empty( $obj ) { | |
| 356 | + if ( $obj !== null ) { | |
| 357 | + while ( $obj.firstChild ) { | |
| 358 | + $obj.removeChild( $obj.firstChild ); | |
| 359 | + } | |
| 360 | + } | |
| 361 | + } | |
| 362 | + | |
| 363 | + function addClass( $obj, className ) { | |
| 364 | + if ( $obj.classList ) { | |
| 365 | + $obj.classList.add( className ); | |
| 366 | + } else { | |
| 367 | + $obj.className += ' ' + className; | |
| 368 | + } | |
| 369 | + } | |
| 370 | + | |
| 371 | + function confirmClick( e ) { | |
| 372 | + /*jshint validthis:true */ | |
| 373 | + e.stopPropagation(); | |
| 374 | + e.preventDefault(); | |
| 375 | + confirmLinkClick( this ); | |
| 376 | + } | |
| 377 | + | |
| 378 | + function confirmLinkClick( link ) { | |
| 379 | + var message = link.getAttribute( 'data-frmverify' ); | |
| 380 | + | |
| 381 | + if ( message === null || link.id === 'frm-confirmed-click' ) { | |
| 382 | + return true; | |
| 383 | + } else { | |
| 384 | + return confirmModal( link ); | |
| 385 | + } | |
| 386 | + } | |
| 387 | + | |
| 388 | + function confirmModal( link ) { | |
| 389 | + var verify, $confirmMessage, i, dataAtts, btnClass, | |
| 390 | + $info = initModal( '#frm_confirm_modal', '400px' ), | |
| 391 | + continueButton = document.getElementById( 'frm-confirmed-click' ); | |
| 392 | + | |
| 393 | + if ( $info === false ) { | |
| 394 | + return false; | |
| 395 | + } | |
| 396 | + | |
| 397 | + verify = link.getAttribute( 'data-frmverify' ); | |
| 398 | + btnClass = verify ? link.getAttribute( 'data-frmverify-btn' ) : ''; | |
| 399 | + $confirmMessage = jQuery( '.frm-confirm-msg' ); | |
| 400 | + $confirmMessage.empty(); | |
| 401 | + | |
| 402 | + if ( verify ) { | |
| 403 | + $confirmMessage.append( document.createTextNode( verify ) ); | |
| 404 | + if ( btnClass ) { | |
| 405 | + continueButton.classList.add( btnClass ); | |
| 406 | + } | |
| 407 | + } | |
| 408 | + | |
| 409 | + removeAtts = continueButton.dataset; | |
| 410 | + for ( i in dataAtts ) { | |
| 411 | + continueButton.removeAttribute( 'data-' + i ); | |
| 412 | + } | |
| 413 | + | |
| 414 | + dataAtts = link.dataset; | |
| 415 | + for ( i in dataAtts ) { | |
| 416 | + if ( i !== 'frmverify' ) { | |
| 417 | + continueButton.setAttribute( 'data-' + i, dataAtts[i]); | |
| 418 | + } | |
| 419 | + } | |
| 420 | + | |
| 421 | + $info.dialog( 'open' ); | |
| 422 | + continueButton.setAttribute( 'href', link.getAttribute( 'href' ) ); | |
| 423 | + return false; | |
| 424 | + } | |
| 425 | + | |
| 426 | + function infoModal( msg ) { | |
| 427 | + var $info = initModal( '#frm_info_modal', '400px' ); | |
| 428 | + | |
| 429 | + if ( $info === false ) { | |
| 430 | + return false; | |
| 431 | + } | |
| 432 | + | |
| 433 | + jQuery( '.frm-info-msg' ).html( msg ); | |
| 434 | + | |
| 435 | + $info.dialog( 'open' ); | |
| 436 | + return false; | |
| 437 | + } | |
| 438 | + | |
| 439 | + function toggleItem( e ) { | |
| 440 | + /*jshint validthis:true */ | |
| 441 | + var toggle = this.getAttribute( 'data-frmtoggle' ), | |
| 442 | + text = this.getAttribute( 'data-toggletext' ), | |
| 443 | + items = jQuery( toggle ); | |
| 444 | + | |
| 445 | + e.preventDefault(); | |
| 446 | + | |
| 447 | + if ( items.is( ':visible' ) ) { | |
| 448 | + items.show(); | |
| 449 | + } else { | |
| 450 | + items.hide(); | |
| 451 | + } | |
| 452 | + | |
| 453 | + if ( text !== null && text !== '' ) { | |
| 454 | + this.setAttribute( 'data-toggletext', this.innerHTML ); | |
| 455 | + this.innerHTML = text; | |
| 456 | + } | |
| 457 | + | |
| 458 | + return false; | |
| 459 | + } | |
| 460 | + | |
| 461 | + function hideShowItem( e ) { | |
| 462 | + /*jshint validthis:true */ | |
| 463 | + var hide = this.getAttribute( 'data-frmhide' ), | |
| 464 | + show = this.getAttribute( 'data-frmshow' ), | |
| 465 | + toggleClass = this.getAttribute( 'data-toggleclass' ); | |
| 466 | + | |
| 467 | + e.preventDefault(); | |
| 468 | + if ( toggleClass === null ) { | |
| 469 | + toggleClass = 'frm_hidden'; | |
| 470 | + } | |
| 471 | + | |
| 472 | + if ( hide !== null ) { | |
| 473 | + jQuery( hide ).addClass( toggleClass ); | |
| 474 | + } | |
| 475 | + | |
| 476 | + if ( show !== null ) { | |
| 477 | + jQuery( show ).removeClass( toggleClass ); | |
| 478 | + } | |
| 479 | + | |
| 480 | + var current = this.parentNode.querySelectorAll( 'a.current' ); | |
| 481 | + if ( current !== null ) { | |
| 482 | + for ( var i = 0; i < current.length; i++ ) { | |
| 483 | + current[ i ].classList.remove( 'current' ); | |
| 484 | + } | |
| 485 | + this.classList.add( 'current' ); | |
| 486 | + } | |
| 487 | + | |
| 488 | + return false; | |
| 489 | + } | |
| 490 | + | |
| 491 | + function setupMenuOffset() { | |
| 492 | + window.onscroll = document.documentElement.onscroll = setMenuOffset; | |
| 493 | + setMenuOffset(); | |
| 494 | + } | |
| 495 | + | |
| 496 | + function setMenuOffset() { | |
| 497 | + var fields = document.getElementById( 'frm_adv_info' ); | |
| 498 | + if ( fields === null ) { | |
| 499 | + return; | |
| 500 | + } | |
| 501 | + | |
| 502 | + var currentOffset = document.documentElement.scrollTop || document.body.scrollTop; // body for Safari | |
| 503 | + if ( currentOffset === 0 ) { | |
| 504 | + fields.classList.remove( 'frm_fixed' ); | |
| 505 | + return; | |
| 506 | + } | |
| 507 | + | |
| 508 | + var posEle = document.getElementById( 'frm_position_ele' ); | |
| 509 | + if ( posEle === null ) { | |
| 510 | + return; | |
| 511 | + } | |
| 512 | + | |
| 513 | + var eleOffset = jQuery( posEle ).offset(); | |
| 514 | + var offset = eleOffset.top; | |
| 515 | + var desiredOffset = offset - currentOffset; | |
| 516 | + var menuHeight = 0; | |
| 517 | + | |
| 518 | + var menu = document.getElementById( 'wpadminbar' ); | |
| 519 | + if ( menu !== null ) { | |
| 520 | + menuHeight = menu.offsetHeight; | |
| 521 | + } | |
| 522 | + | |
| 523 | + if ( desiredOffset < menuHeight ) { | |
| 524 | + desiredOffset = menuHeight; | |
| 525 | + } | |
| 526 | + | |
| 527 | + if ( desiredOffset > menuHeight ) { | |
| 528 | + fields.classList.remove( 'frm_fixed' ); | |
| 529 | + } else { | |
| 530 | + fields.classList.add( 'frm_fixed' ); | |
| 531 | + if ( desiredOffset !== 32 ) { | |
| 532 | + fields.style.top = desiredOffset + 'px'; | |
| 533 | + } | |
| 534 | + } | |
| 535 | + } | |
| 536 | + | |
| 537 | + function loadTooltips() { | |
| 538 | + var wrapClass = jQuery( '.wrap, .frm_wrap' ), | |
| 539 | + confirmModal = document.getElementById( 'frm_confirm_modal' ), | |
| 540 | + doAction = false, | |
| 541 | + confirmedBulkDelete = false; | |
| 542 | + | |
| 543 | + jQuery( confirmModal ).on( 'click', '[data-deletefield]', deleteFieldConfirmed ); | |
| 544 | + jQuery( confirmModal ).on( 'click', '[data-removeid]', removeThisTag ); | |
| 545 | + jQuery( confirmModal ).on( 'click', '[data-trashtemplate]', trashTemplate ); | |
| 546 | + | |
| 547 | + wrapClass.on( 'click', '.frm_remove_tag, .frm_remove_form_action', removeThisTag ); | |
| 548 | + wrapClass.on( 'click', 'a[data-frmverify]', confirmClick ); | |
| 549 | + wrapClass.on( 'click', 'a[data-frmtoggle]', toggleItem ); | |
| 550 | + wrapClass.on( 'click', 'a[data-frmhide], a[data-frmshow]', hideShowItem ); | |
| 551 | + wrapClass.on( 'change', 'input[data-frmhide], input[data-frmshow]', hideShowItem ); | |
| 552 | + wrapClass.on( 'click', '.widget-top,a.widget-action', clickWidget ); | |
| 553 | + | |
| 554 | + wrapClass.on( 'mouseenter.frm', '.frm_bstooltip, .frm_help', function() { | |
| 555 | + jQuery( this ).off( 'mouseenter.frm' ); | |
| 556 | + | |
| 557 | + jQuery( '.frm_bstooltip, .frm_help' ).tooltip( ); | |
| 558 | + jQuery( this ).tooltip( 'show' ); | |
| 559 | + }); | |
| 560 | + | |
| 561 | + jQuery( '.frm_bstooltip, .frm_help' ).tooltip( ); | |
| 562 | + | |
| 563 | + jQuery( document ).on( 'click', '#doaction, #doaction2', function( event ) { | |
| 564 | + var isTop = this.id === 'doaction', | |
| 565 | + suffix = isTop ? 'top' : 'bottom', | |
| 566 | + bulkActionSelector = document.getElementById( 'bulk-action-selector-' + suffix ), | |
| 567 | + confirmBulkDelete = document.getElementById( 'confirm-bulk-delete-' + suffix ); | |
| 568 | + | |
| 569 | + if ( bulkActionSelector !== null && confirmBulkDelete !== null ) { | |
| 570 | + doAction = this; | |
| 571 | + | |
| 572 | + if ( ! confirmedBulkDelete && bulkActionSelector.value === 'bulk_delete' ) { | |
| 573 | + event.preventDefault(); | |
| 574 | + confirmLinkClick( confirmBulkDelete ); | |
| 575 | + return false; | |
| 576 | + } | |
| 577 | + } else { | |
| 578 | + doAction = false; | |
| 579 | + } | |
| 580 | + }); | |
| 581 | + | |
| 582 | + jQuery( document ).on( 'click', '#frm-confirmed-click', function( event ) { | |
| 583 | + if ( doAction === false ) { | |
| 584 | + return; | |
| 585 | + } | |
| 586 | + | |
| 587 | + if ( this.getAttribute( 'href' ) === 'confirm-bulk-delete' ) { | |
| 588 | + event.preventDefault(); | |
| 589 | + confirmedBulkDelete = true; | |
| 590 | + doAction.click(); | |
| 591 | + return false; | |
| 592 | + } | |
| 593 | + }); | |
| 594 | + } | |
| 595 | + | |
| 596 | + function deleteTooltips() { | |
| 597 | + document.querySelectorAll( '.tooltip' ).forEach( | |
| 598 | + function( tooltip ) { | |
| 599 | + tooltip.remove(); | |
| 600 | + } | |
| 601 | + ); | |
| 602 | + } | |
| 603 | + | |
| 604 | + function removeThisTag() { | |
| 605 | + /*jshint validthis:true */ | |
| 606 | + let show, hide, removeMore; | |
| 607 | + | |
| 608 | + if ( parseInt( this.getAttribute( 'data-skip-frm-js' ) ) || confirmLinkClick( this ) === false ) { | |
| 609 | + return; | |
| 610 | + } | |
| 611 | + | |
| 612 | + const deleteButton = jQuery( this ); | |
| 613 | + const id = deleteButton.attr( 'data-removeid' ); | |
| 614 | + | |
| 615 | + show = deleteButton.attr( 'data-showlast' ); | |
| 616 | + if ( typeof show === 'undefined' ) { | |
| 617 | + show = ''; | |
| 618 | + } | |
| 619 | + | |
| 620 | + hide = deleteButton.attr( 'data-hidelast' ); | |
| 621 | + if ( typeof hide === 'undefined' ) { | |
| 622 | + hide = ''; | |
| 623 | + } | |
| 624 | + | |
| 625 | + removeMore = deleteButton.attr( 'data-removemore' ); | |
| 626 | + | |
| 627 | + if ( show !== '' ) { | |
| 628 | + if ( deleteButton.closest( '.frm_add_remove' ).find( '.frm_remove_tag:visible' ).length > 1 ) { | |
| 629 | + show = ''; | |
| 630 | + hide = ''; | |
| 631 | + } | |
| 632 | + } else if ( id.indexOf( 'frm_postmeta_' ) === 0 ) { | |
| 633 | + if ( jQuery( '#frm_postmeta_rows .frm_postmeta_row' ).length < 2 ) { | |
| 634 | + show = '.frm_add_postmeta_row.button'; | |
| 635 | + } | |
| 636 | + if ( jQuery( '.frm_toggle_cf_opts' ).length && jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().length ) { | |
| 637 | + if ( show !== '' ) { | |
| 638 | + show += ','; | |
| 639 | + } | |
| 640 | + show += '#' + jQuery( '#frm_postmeta_rows .frm_postmeta_row:not(#' + id + ')' ).last().attr( 'id' ) + ' .frm_toggle_cf_opts'; | |
| 641 | + } | |
| 642 | + } | |
| 643 | + | |
| 644 | + const $fadeEle = jQuery( document.getElementById( id ) ); | |
| 645 | + $fadeEle.fadeOut( 400, function() { | |
| 646 | + $fadeEle.remove(); | |
| 647 | + fieldUpdated(); | |
| 648 | + | |
| 649 | + if ( hide !== '' ) { | |
| 650 | + jQuery( hide ).hide(); | |
| 651 | + } | |
| 652 | + | |
| 653 | + if ( show !== '' ) { | |
| 654 | + jQuery( show + ' a,' + show ).removeClass( 'frm_hidden' ).fadeIn( 'slow' ); | |
| 655 | + } | |
| 656 | + | |
| 657 | + if ( this.closest( '.frm_form_action_settings' ) ) { | |
| 658 | + const type = this.closest( '.frm_form_action_settings' ).querySelector( '.frm_action_name' ).value; | |
| 659 | + afterActionRemoved( type ); | |
| 660 | + } | |
| 661 | + }); | |
| 662 | + | |
| 663 | + if ( typeof removeMore !== 'undefined' ) { | |
| 664 | + removeMore = jQuery( removeMore ); | |
| 665 | + removeMore.fadeOut( 400, function() { | |
| 666 | + removeMore.remove(); | |
| 667 | + }); | |
| 668 | + } | |
| 669 | + | |
| 670 | + if ( show !== '' ) { | |
| 671 | + jQuery( this ).closest( '.frm_logic_rows' ).fadeOut( 'slow' ); | |
| 672 | + } | |
| 673 | + | |
| 674 | + return false; | |
| 675 | + } | |
| 676 | + | |
| 677 | + function afterActionRemoved( type ) { | |
| 678 | + checkActiveAction( type ); | |
| 679 | + | |
| 680 | + const hookName = 'frm_after_action_removed'; | |
| 681 | + const hookArgs = { type }; | |
| 682 | + wp.hooks.doAction( hookName, hookArgs ); | |
| 683 | + } | |
| 684 | + | |
| 685 | + function clickWidget( event, b ) { | |
| 686 | + /*jshint validthis:true */ | |
| 687 | + if ( typeof b === 'undefined' ) { | |
| 688 | + b = this; | |
| 689 | + } | |
| 690 | + | |
| 691 | + popCalcFields( b, false ); | |
| 692 | + | |
| 693 | + const cont = jQuery( b ).closest( '.frm_form_action_settings' ); | |
| 694 | + const target = event.target; | |
| 695 | + | |
| 696 | + if ( cont.length && typeof target !== 'undefined' ) { | |
| 697 | + const className = target.parentElement.className; | |
| 698 | + if ( 'string' === typeof className ) { | |
| 699 | + if ( className.indexOf( 'frm_email_icons' ) > -1 || className.indexOf( 'frm_toggle' ) > -1 ) { | |
| 700 | + // clicking on delete icon shouldn't open it | |
| 701 | + event.stopPropagation(); | |
| 702 | + return; | |
| 703 | + } | |
| 704 | + } | |
| 705 | + } | |
| 706 | + | |
| 707 | + let inside = cont.children( '.widget-inside' ); | |
| 708 | + | |
| 709 | + if ( cont.length && inside.find( 'p, div, table' ).length < 1 ) { | |
| 710 | + const actionId = cont.find( 'input[name$="[ID]"]' ).val(); | |
| 711 | + const actionType = cont.find( 'input[name$="[post_excerpt]"]' ).val(); | |
| 712 | + if ( actionType ) { | |
| 713 | + inside.html( '<span class="frm-wait frm_spinner"></span>' ); | |
| 714 | + cont.find( '.spinner' ).fadeIn( 'slow' ); | |
| 715 | + jQuery.ajax({ | |
| 716 | + type: 'POST', | |
| 717 | + url: ajaxurl, | |
| 718 | + data: { | |
| 719 | + action: 'frm_form_action_fill', | |
| 720 | + action_id: actionId, | |
| 721 | + action_type: actionType, | |
| 722 | + nonce: frmGlobal.nonce | |
| 723 | + }, | |
| 724 | + success: function( html ) { | |
| 725 | + inside.html( html ); | |
| 726 | + initiateMultiselect(); | |
| 727 | + showInputIcon( '#' + cont.attr( 'id' ) ); | |
| 728 | + frmDom.autocomplete.initAutocomplete( 'page', inside ); | |
| 729 | + jQuery( b ).trigger( 'frm-action-loaded' ); | |
| 730 | + | |
| 731 | + /** | |
| 732 | + * Fires after filling form action content when opening. | |
| 733 | + * | |
| 734 | + * @since 5.5.4 | |
| 735 | + * | |
| 736 | + * @param {Object} insideElement JQuery object of form action inside element. | |
| 737 | + */ | |
| 738 | + wp.hooks.doAction( 'frm_filled_form_action', inside ); | |
| 739 | + } | |
| 740 | + }); | |
| 741 | + } | |
| 742 | + } | |
| 743 | + | |
| 744 | + jQuery( b ).closest( '.frm_field_box' ).siblings().find( '.widget-inside' ).slideUp( 'fast' ); | |
| 745 | + if ( ( typeof b.className !== 'undefined' && b.className.indexOf( 'widget-action' ) !== -1 ) || jQuery( b ).closest( '.start_divider' ).length < 1 ) { | |
| 746 | + return; | |
| 747 | + } | |
| 748 | + | |
| 749 | + inside = jQuery( b ).closest( 'div.widget' ).children( '.widget-inside' ); | |
| 750 | + if ( inside.is( ':hidden' ) ) { | |
| 751 | + inside.slideDown( 'fast' ); | |
| 752 | + } else { | |
| 753 | + inside.slideUp( 'fast' ); | |
| 754 | + } | |
| 755 | + } | |
| 756 | + | |
| 757 | + function clickNewTab() { | |
| 758 | + /*jshint validthis:true */ | |
| 759 | + var t = this.getAttribute( 'href' ), | |
| 760 | + c = t.replace( '#', '.' ), | |
| 761 | + $link = jQuery( this ); | |
| 762 | + | |
| 763 | + if ( typeof t === 'undefined' ) { | |
| 764 | + return false; | |
| 765 | + } | |
| 766 | + | |
| 767 | + $link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' ); | |
| 768 | + $link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide(); | |
| 769 | + document.getElementById( t.replace( '#', '' ) ).style.display = 'block'; | |
| 770 | + | |
| 771 | + if ( this.id === 'frm_insert_fields_tab' ) { | |
| 772 | + clearSettingsBox(); | |
| 773 | + } | |
| 774 | + return false; | |
| 775 | + } | |
| 776 | + | |
| 777 | + function clickTab( link, auto ) { | |
| 778 | + link = jQuery( link ); | |
| 779 | + var t = link.attr( 'href' ); | |
| 780 | + if ( typeof t === 'undefined' ) { | |
| 781 | + return; | |
| 782 | + } | |
| 783 | + | |
| 784 | + var c = t.replace( '#', '.' ); | |
| 785 | + | |
| 786 | + link.closest( 'li' ).addClass( 'frm-tabs active' ).siblings( 'li' ).removeClass( 'frm-tabs active starttab' ); | |
| 787 | + if ( link.closest( 'div' ).find( '.tabs-panel' ).length ) { | |
| 788 | + link.closest( 'div' ).children( '.tabs-panel' ).not( t ).not( c ).hide(); | |
| 789 | + } else { | |
| 790 | + if ( document.getElementById( 'form_global_settings' ) !== null ) { | |
| 791 | + /* global settings */ | |
| 792 | + var ajax = link.data( 'frmajax' ); | |
| 793 | + link.closest( '.frm_wrap' ).find( '.tabs-panel, .hide_with_tabs' ).hide(); | |
| 794 | + if ( typeof ajax !== 'undefined' && ajax == '1' ) { | |
| 795 | + loadSettingsTab( t ); | |
| 796 | + } | |
| 797 | + } else { | |
| 798 | + /* form settings page */ | |
| 799 | + jQuery( '#frm-categorydiv .tabs-panel, .hide_with_tabs' ).hide(); | |
| 800 | + } | |
| 801 | + } | |
| 802 | + jQuery( t ).show(); | |
| 803 | + jQuery( c ).show(); | |
| 804 | + | |
| 805 | + hideShortcodes(); | |
| 806 | + | |
| 807 | + if ( auto !== 'auto' ) { | |
| 808 | + // Hide success message on tab change. | |
| 809 | + jQuery( '.frm_updated_message' ).hide(); | |
| 810 | + jQuery( '.frm_warning_style' ).hide(); | |
| 811 | + } | |
| 812 | + | |
| 813 | + if ( jQuery( link ).closest( '#frm_adv_info' ).length ) { | |
| 814 | + return; | |
| 815 | + } | |
| 816 | + | |
| 817 | + if ( jQuery( '.frm_form_settings' ).length ) { | |
| 818 | + jQuery( '.frm_form_settings' ).attr( 'action', '?page=formidable&frm_action=settings&id=' + jQuery( '.frm_form_settings input[name="id"]' ).val() + '&t=' + t.replace( '#', '' ) ); | |
| 819 | + } else { | |
| 820 | + jQuery( '.frm_settings_form' ).attr( 'action', '?page=formidable-settings&t=' + t.replace( '#', '' ) ); | |
| 821 | + } | |
| 822 | + } | |
| 823 | + | |
| 824 | + function setupSortable( sortableSelector ) { | |
| 825 | + document.querySelectorAll( sortableSelector ).forEach( | |
| 826 | + list => { | |
| 827 | + makeDroppable( list ); | |
| 828 | + Array.from( list.children ).forEach( child => makeDraggable( child, '.frm-move' ) ); | |
| 829 | + | |
| 830 | + const $sectionTitle = jQuery( list ).children( '[data-type="divider"]' ).children( '.divider_section_only' ); | |
| 831 | + if ( $sectionTitle.length ) { | |
| 832 | + makeDroppable( $sectionTitle ); | |
| 833 | + } | |
| 834 | + } | |
| 835 | + ); | |
| 836 | + setupFieldOptionSorting( jQuery( '#frm_builder_page' ) ); | |
| 837 | + } | |
| 838 | + | |
| 839 | + function makeDroppable( list ) { | |
| 840 | + jQuery( list ).droppable({ | |
| 841 | + accept: '.frmbutton, li.frm_field_box', | |
| 842 | + deactivate: handleFieldDrop, | |
| 843 | + over: onDragOverDroppable, | |
| 844 | + out: onDraggableLeavesDroppable, | |
| 845 | + tolerance: 'pointer' | |
| 846 | + }); | |
| 847 | + } | |
| 848 | + | |
| 849 | + function onDragOverDroppable( event, ui ) { | |
| 850 | + const droppable = getDroppableForOnDragOver( event.target ); | |
| 851 | + const draggable = ui.draggable[0]; | |
| 852 | + | |
| 853 | + if ( ! allowDrop( draggable, droppable ) ) { | |
| 854 | + droppable.classList.remove( 'frm-over-droppable' ); | |
| 855 | + jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' ); | |
| 856 | + return; | |
| 857 | + } | |
| 858 | + | |
| 859 | + document.querySelectorAll( '.frm-over-droppable' ).forEach( droppable => droppable.classList.remove( 'frm-over-droppable' ) ); | |
| 860 | + droppable.classList.add( 'frm-over-droppable' ); | |
| 861 | + jQuery( droppable ).parents( 'ul.frm_sorting' ).addClass( 'frm-over-droppable' ); | |
| 862 | + } | |
| 863 | + | |
| 864 | + /** | |
| 865 | + * Maybe change the droppable. | |
| 866 | + * Section titles are made droppable, but are not a list, so we need to change the droppable to the section's list instead. | |
| 867 | + * | |
| 868 | + * @param {Element} droppable | |
| 869 | + * @returns {Element} | |
| 870 | + */ | |
| 871 | + function getDroppableForOnDragOver( droppable ) { | |
| 872 | + if ( droppable.classList.contains( 'divider_section_only' ) ) { | |
| 873 | + droppable = jQuery( droppable ).nextAll( '.start_divider.frm_sorting' ).get( 0 ); | |
| 874 | + } | |
| 875 | + return droppable; | |
| 876 | + } | |
| 877 | + | |
| 878 | + function onDraggableLeavesDroppable( event ) { | |
| 879 | + const droppable = event.target; | |
| 880 | + droppable.classList.remove( 'frm-over-droppable' ); | |
| 881 | + } | |
| 882 | + | |
| 883 | + function makeDraggable( draggable, handle ) { | |
| 884 | + const settings = { | |
| 885 | + helper: getDraggableHelper, | |
| 886 | + revert: 'invalid', | |
| 887 | + delay: 10, | |
| 888 | + start: handleDragStart, | |
| 889 | + stop: handleDragStop, | |
| 890 | + drag: handleDrag, | |
| 891 | + cursor: 'grabbing', | |
| 892 | + refreshPositions: true, | |
| 893 | + cursorAt: { | |
| 894 | + top: 0, | |
| 895 | + left: 90 // The width of draggable button is 180. 90 should center the draggable on the cursor. | |
| 896 | + } | |
| 897 | + }; | |
| 898 | + if ( 'string' === typeof handle ) { | |
| 899 | + settings.handle = handle; | |
| 900 | + } | |
| 901 | + jQuery( draggable ).draggable( settings ); | |
| 902 | + } | |
| 903 | + | |
| 904 | + function getDraggableHelper( event ) { | |
| 905 | + const draggable = event.delegateTarget; | |
| 906 | + | |
| 907 | + if ( isFieldGroup( draggable ) ) { | |
| 908 | + const newTextFieldClone = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_ttext' ).cloneNode( true ); | |
| 909 | + newTextFieldClone.querySelector( 'use' ).setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_field_group_layout_icon' ); | |
| 910 | + newTextFieldClone.querySelector( 'span' ).textContent = __( 'Field Group' ); | |
| 911 | + newTextFieldClone.classList.add( 'frm_field_box' ); | |
| 912 | + newTextFieldClone.classList.add( 'ui-sortable-helper' ); | |
| 913 | + return newTextFieldClone; | |
| 914 | + } | |
| 915 | + | |
| 916 | + let copyTarget; | |
| 917 | + const isNewField = draggable.classList.contains( 'frmbutton' ); | |
| 918 | + if ( isNewField ) { | |
| 919 | + copyTarget = draggable.cloneNode( true ); | |
| 920 | + copyTarget.classList.add( 'ui-sortable-helper' ); | |
| 921 | + draggable.classList.add( 'frm-new-field' ); | |
| 922 | + return copyTarget; | |
| 923 | + } | |
| 924 | + | |
| 925 | + if ( draggable.hasAttribute( 'data-ftype' ) ) { | |
| 926 | + const fieldType = draggable.getAttribute( 'data-ftype' ); | |
| 927 | + copyTarget = document.getElementById( 'frm-insert-fields' ).querySelector( '.frm_t' + fieldType ); | |
| 928 | + copyTarget = copyTarget.cloneNode( true ); | |
| 929 | + copyTarget.classList.add( 'form-field' ); | |
| 930 | + | |
| 931 | + copyTarget.classList.add( 'ui-sortable-helper' ); | |
| 932 | + | |
| 933 | + if ( copyTarget ) { | |
| 934 | + return copyTarget.cloneNode( true ); | |
| 935 | + } | |
| 936 | + } | |
| 937 | + | |
| 938 | + return div({ className: 'frmbutton' }); | |
| 939 | + } | |
| 940 | + | |
| 941 | + function handleDragStart( event, ui ) { | |
| 942 | + const container = postBodyContent; | |
| 943 | + container.classList.add( 'frm-dragging-field' ); | |
| 944 | + | |
| 945 | + document.body.classList.add( 'frm-dragging' ); | |
| 946 | + ui.helper.addClass( 'frm-sortable-helper' ); | |
| 947 | + ui.helper.initialOffset = container.scrollTop; | |
| 948 | + | |
| 949 | + event.target.classList.add( 'frm-drag-fade' ); | |
| 950 | + | |
| 951 | + unselectFieldGroups(); | |
| 952 | + deleteEmptyDividerWrappers(); | |
| 953 | + maybeRemoveGroupHoverTarget(); | |
| 954 | + closeOpenFieldDropdowns(); | |
| 955 | + deleteTooltips(); | |
| 956 | + } | |
| 957 | + | |
| 958 | + function handleDragStop() { | |
| 959 | + const container = postBodyContent; | |
| 960 | + container.classList.remove( 'frm-dragging-field' ); | |
| 961 | + document.body.classList.remove( 'frm-dragging' ); | |
| 962 | + | |
| 963 | + const fade = document.querySelector( '.frm-drag-fade' ); | |
| 964 | + if ( fade ) { | |
| 965 | + fade.classList.remove( 'frm-drag-fade' ); | |
| 966 | + } | |
| 967 | + } | |
| 968 | + | |
| 969 | + function handleDrag( event, ui ) { | |
| 970 | + maybeScrollBuilder( event ); | |
| 971 | + const draggable = event.target; | |
| 972 | + const droppable = getDroppableTarget(); | |
| 973 | + | |
| 974 | + let placeholder = document.getElementById( 'frm_drag_placeholder' ); | |
| 975 | + | |
| 976 | + if ( ! allowDrop( draggable, droppable ) ) { | |
| 977 | + if ( placeholder ) { | |
| 978 | + placeholder.remove(); | |
| 979 | + } | |
| 980 | + return; | |
| 981 | + } | |
| 982 | + | |
| 983 | + if ( ! placeholder ) { | |
| 984 | + placeholder = tag( 'li', { | |
| 985 | + id: 'frm_drag_placeholder', | |
| 986 | + className: 'sortable-placeholder' | |
| 987 | + }); | |
| 988 | + } | |
| 989 | + const frmSortableHelper = ui.helper.get( 0 ); | |
| 990 | + if ( frmSortableHelper.classList.contains( 'form-field' ) || frmSortableHelper.classList.contains( 'frm_field_box' ) ) { | |
| 991 | + // Sync the y position of the draggable so it still follows the cursor after scrolling up and down the field list. | |
| 992 | + frmSortableHelper.style.transform = 'translateY(' + getDragOffset( ui.helper ) + 'px)'; | |
| 993 | + } | |
| 994 | + | |
| 995 | + if ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) ) { | |
| 996 | + placeholder.style.left = 0; | |
| 997 | + handleDragOverYAxis({ droppable, y: event.clientY, placeholder }); | |
| 998 | + return; | |
| 999 | + } | |
| 1000 | + | |
| 1001 | + placeholder.style.top = ''; | |
| 1002 | + handleDragOverFieldGroup({ droppable, x: event.clientX, placeholder }); | |
| 1003 | + } | |
| 1004 | + | |
| 1005 | + function maybeScrollBuilder( event ) { | |
| 1006 | + $postBodyContent.scrollTop( | |
| 1007 | + ( _, v ) => { | |
| 1008 | + const moved = event.clientY; | |
| 1009 | + const h = postBodyContent.offsetHeight; | |
| 1010 | + const relativePos = event.clientY - postBodyContent.offsetTop; | |
| 1011 | + const y = relativePos - h / 2; | |
| 1012 | + | |
| 1013 | + if ( relativePos > ( h - 50 ) && moved > 5 ) { | |
| 1014 | + // Scrolling down. | |
| 1015 | + return v + y * 0.1; | |
| 1016 | + } | |
| 1017 | + | |
| 1018 | + if ( relativePos < 70 && moved < 130 ) { | |
| 1019 | + // Scrolling up. | |
| 1020 | + return v - Math.abs( y * 0.1 ); | |
| 1021 | + } | |
| 1022 | + | |
| 1023 | + return v; | |
| 1024 | + } | |
| 1025 | + ); | |
| 1026 | + } | |
| 1027 | + | |
| 1028 | + function getDragOffset( $helper ) { | |
| 1029 | + return postBodyContent.scrollTop - $helper.initialOffset; | |
| 1030 | + } | |
| 1031 | + | |
| 1032 | + function getDroppableTarget() { | |
| 1033 | + let droppable = document.getElementById( 'frm-show-fields' ); | |
| 1034 | + while ( droppable.querySelector( '.frm-over-droppable' ) ) { | |
| 1035 | + droppable = droppable.querySelector( '.frm-over-droppable' ); | |
| 1036 | + } | |
| 1037 | + if ( 'frm-show-fields' === droppable.id && ! droppable.classList.contains( 'frm-over-droppable' ) ) { | |
| 1038 | + droppable = false; | |
| 1039 | + } | |
| 1040 | + return droppable; | |
| 1041 | + } | |
| 1042 | + | |
| 1043 | + function handleFieldDrop( _, ui ) { | |
| 1044 | + const draggable = ui.draggable[0]; | |
| 1045 | + const placeholder = document.getElementById( 'frm_drag_placeholder' ); | |
| 1046 | + | |
| 1047 | + if ( ! placeholder ) { | |
| 1048 | + ui.helper.remove(); | |
| 1049 | + debouncedSyncAfterDragAndDrop(); | |
| 1050 | + return; | |
| 1051 | + } | |
| 1052 | + | |
| 1053 | + maybeOpenCollapsedPage( placeholder ); | |
| 1054 | + | |
| 1055 | + const $previousFieldContainer = ui.helper.parent(); | |
| 1056 | + const previousSection = ui.helper.get( 0 ).closest( 'ul.start_divider' ); | |
| 1057 | + const newSection = placeholder.closest( 'ul.frm_sorting' ); | |
| 1058 | + | |
| 1059 | + if ( draggable.classList.contains( 'frm-new-field' ) ) { | |
| 1060 | + insertNewFieldByDragging( draggable.id ); | |
| 1061 | + } else { | |
| 1062 | + moveFieldThatAlreadyExists( draggable, placeholder ); | |
| 1063 | + } | |
| 1064 | + | |
| 1065 | + const previousSectionId = previousSection ? parseInt( previousSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0; | |
| 1066 | + const newSectionId = newSection.classList.contains( 'start_divider' ) ? parseInt( newSection.closest( '.edit_field_type_divider' ).getAttribute( 'data-fid' ) ) : 0; | |
| 1067 | + | |
| 1068 | + placeholder.remove(); | |
| 1069 | + ui.helper.remove(); | |
| 1070 | + | |
| 1071 | + const $previousContainerFields = $previousFieldContainer.length ? getFieldsInRow( $previousFieldContainer ) : []; | |
| 1072 | + maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields ); | |
| 1073 | + maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields ); | |
| 1074 | + | |
| 1075 | + if ( previousSectionId !== newSectionId ) { | |
| 1076 | + updateFieldAfterMovingBetweenSections( jQuery( draggable ), previousSection ); | |
| 1077 | + } | |
| 1078 | + | |
| 1079 | + debouncedSyncAfterDragAndDrop(); | |
| 1080 | + } | |
| 1081 | + | |
| 1082 | + /** | |
| 1083 | + * If a page if collapsed, expand it before dragging since only the page break will move. | |
| 1084 | + * | |
| 1085 | + * @param {Element} placeholder | |
| 1086 | + * @returns {void} | |
| 1087 | + */ | |
| 1088 | + function maybeOpenCollapsedPage( placeholder ) { | |
| 1089 | + if ( ! placeholder.previousElementSibling || ! placeholder.previousElementSibling.classList.contains( 'frm-is-collapsed' ) ) { | |
| 1090 | + return; | |
| 1091 | + } | |
| 1092 | + | |
| 1093 | + const $pageBreakField = jQuery( placeholder ).prevUntil( '[data-type="break"]' ); | |
| 1094 | + if ( ! $pageBreakField.length ) { | |
| 1095 | + return; | |
| 1096 | + } | |
| 1097 | + | |
| 1098 | + const collapseButton = $pageBreakField.find( '.frm-collapse-page' ).get( 0 ); | |
| 1099 | + if ( collapseButton ) { | |
| 1100 | + collapseButton.click(); | |
| 1101 | + } | |
| 1102 | + } | |
| 1103 | + | |
| 1104 | + function maybeUpdatePreviousFieldContainerAfterDrop( $previousFieldContainer, $previousContainerFields ) { | |
| 1105 | + if ( ! $previousFieldContainer.length ) { | |
| 1106 | + return; | |
| 1107 | + } | |
| 1108 | + | |
| 1109 | + if ( $previousContainerFields.length ) { | |
| 1110 | + syncLayoutClasses( $previousContainerFields.first() ); | |
| 1111 | + } else { | |
| 1112 | + maybeDeleteAnEmptyFieldGroup( $previousFieldContainer.get( 0 ) ); | |
| 1113 | + } | |
| 1114 | + } | |
| 1115 | + | |
| 1116 | + function maybeUpdateDraggableClassAfterDrop( draggable, $previousContainerFields ) { | |
| 1117 | + if ( 0 !== $previousContainerFields.length || 1 !== getFieldsInRow( jQuery( draggable.parentNode ) ).length ) { | |
| 1118 | + syncLayoutClasses( jQuery( draggable ) ); | |
| 1119 | + } | |
| 1120 | + } | |
| 1121 | + | |
| 1122 | + /** | |
| 1123 | + * Remove an empty field group, but don't remove an empty section. | |
| 1124 | + * | |
| 1125 | + * @param {Element} previousFieldContainer | |
| 1126 | + * @returns {void} | |
| 1127 | + */ | |
| 1128 | + function maybeDeleteAnEmptyFieldGroup( previousFieldContainer ) { | |
| 1129 | + const closestFieldBox = previousFieldContainer.closest( 'li.frm_field_box' ); | |
| 1130 | + if ( closestFieldBox && ! closestFieldBox.classList.contains( 'edit_field_type_divider' ) ) { | |
| 1131 | + closestFieldBox.remove(); | |
| 1132 | + } | |
| 1133 | + } | |
| 1134 | + | |
| 1135 | + function handleDragOverYAxis({ droppable, y, placeholder }) { | |
| 1136 | + const $list = jQuery( droppable ); | |
| 1137 | + | |
| 1138 | + let top; | |
| 1139 | + | |
| 1140 | + $children = $list.children().not( '.edit_field_type_end_divider' ); | |
| 1141 | + if ( 0 === $children.length ) { | |
| 1142 | + $list.prepend( placeholder ); | |
| 1143 | + top = 0; | |
| 1144 | + } else { | |
| 1145 | + const insertAtIndex = determineIndexBasedOffOfMousePositionInList( $list, y ); | |
| 1146 | + | |
| 1147 | + if ( insertAtIndex === $children.length ) { | |
| 1148 | + const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) ); | |
| 1149 | + top = $lastChild.offset().top + $lastChild.outerHeight(); | |
| 1150 | + $list.append( placeholder ); | |
| 1151 | + | |
| 1152 | + // Make sure nothing gets inserted after the end divider. | |
| 1153 | + const $endDivider = $list.children( '.edit_field_type_end_divider' ); | |
| 1154 | + if ( $endDivider.length ) { | |
| 1155 | + $list.append( $endDivider ); | |
| 1156 | + } | |
| 1157 | + } else { | |
| 1158 | + top = jQuery( $children.get( insertAtIndex ) ).offset().top; | |
| 1159 | + jQuery( $children.get( insertAtIndex ) ).before( placeholder ); | |
| 1160 | + } | |
| 1161 | + } | |
| 1162 | + | |
| 1163 | + top -= $list.offset().top; | |
| 1164 | + placeholder.style.top = top + 'px'; | |
| 1165 | + } | |
| 1166 | + | |
| 1167 | + function determineIndexBasedOffOfMousePositionInList( $list, y ) { | |
| 1168 | + const $items = $list.children().not( '.edit_field_type_end_divider' ); | |
| 1169 | + const length = $items.length; | |
| 1170 | + | |
| 1171 | + let index, item, itemTop, returnIndex; | |
| 1172 | + | |
| 1173 | + returnIndex = 0; | |
| 1174 | + for ( index = length - 1; index >= 0; --index ) { | |
| 1175 | + item = $items.get( index ); | |
| 1176 | + itemTop = jQuery( item ).offset().top; | |
| 1177 | + if ( y > itemTop ) { | |
| 1178 | + returnIndex = index; | |
| 1179 | + if ( y > itemTop + ( jQuery( item ).outerHeight() / 2 ) ) { | |
| 1180 | + returnIndex = index + 1; | |
| 1181 | + } | |
| 1182 | + break; | |
| 1183 | + } | |
| 1184 | + } | |
| 1185 | + | |
| 1186 | + return returnIndex; | |
| 1187 | + } | |
| 1188 | + | |
| 1189 | + function handleDragOverFieldGroup({ droppable, x, placeholder }) { | |
| 1190 | + const $row = jQuery( droppable ); | |
| 1191 | + const $children = getFieldsInRow( $row ); | |
| 1192 | + | |
| 1193 | + if ( ! $children.length ) { | |
| 1194 | + return; | |
| 1195 | + } | |
| 1196 | + | |
| 1197 | + let left; | |
| 1198 | + const insertAtIndex = determineIndexBasedOffOfMousePositionInRow( $row, x ); | |
| 1199 | + | |
| 1200 | + if ( insertAtIndex === $children.length ) { | |
| 1201 | + const $lastChild = jQuery( $children.get( insertAtIndex - 1 ) ); | |
| 1202 | + left = $lastChild.offset().left + $lastChild.outerWidth(); | |
| 1203 | + $row.append( placeholder ); | |
| 1204 | + } else { | |
| 1205 | + left = jQuery( $children.get( insertAtIndex ) ).offset().left; | |
| 1206 | + jQuery( $children.get( insertAtIndex ) ).before( placeholder ); | |
| 1207 | + | |
| 1208 | + const amountToOffsetLeftBy = 0 === insertAtIndex ? 4 : 8; // Offset by 8 in between rows, but only 4 for the first item in a group. | |
| 1209 | + left -= amountToOffsetLeftBy; // Offset the placeholder slightly so it appears between two fields. | |
| 1210 | + } | |
| 1211 | + | |
| 1212 | + left -= $row.offset().left; | |
| 1213 | + | |
| 1214 | + placeholder.style.left = left + 'px'; | |
| 1215 | + } | |
| 1216 | + | |
| 1217 | + function syncAfterDragAndDrop() { | |
| 1218 | + fixUnwrappedListItems(); | |
| 1219 | + toggleSectionHolder(); | |
| 1220 | + maybeFixEndDividers(); | |
| 1221 | + maybeDeleteEmptyFieldGroups(); | |
| 1222 | + updateFieldOrder(); | |
| 1223 | + | |
| 1224 | + const event = new Event( 'frm_sync_after_drag_and_drop', { bubbles: false }); | |
| 1225 | + document.dispatchEvent( event ); | |
| 1226 | + } | |
| 1227 | + | |
| 1228 | + function maybeFixEndDividers() { | |
| 1229 | + document.querySelectorAll( '.edit_field_type_end_divider' ).forEach( | |
| 1230 | + endDivider => endDivider.parentNode.appendChild( endDivider ) | |
| 1231 | + ); | |
| 1232 | + } | |
| 1233 | + | |
| 1234 | + function maybeDeleteEmptyFieldGroups() { | |
| 1235 | + document.querySelectorAll( 'li.form_field_box:not(.form-field)' ).forEach( | |
| 1236 | + fieldGroup => ! fieldGroup.children.length && fieldGroup.remove() | |
| 1237 | + ); | |
| 1238 | + } | |
| 1239 | + | |
| 1240 | + function fixUnwrappedListItems() { | |
| 1241 | + const lists = document.querySelectorAll( 'ul#frm-show-fields, ul.start_divider' ); | |
| 1242 | + lists.forEach( | |
| 1243 | + list => { | |
| 1244 | + list.childNodes.forEach( | |
| 1245 | + child => { | |
| 1246 | + if ( 'undefined' === typeof child.classList ) { | |
| 1247 | + return; | |
| 1248 | + } | |
| 1249 | + | |
| 1250 | + if ( child.classList.contains( 'edit_field_type_end_divider' ) ) { | |
| 1251 | + // Never wrap end divider in place. | |
| 1252 | + return; | |
| 1253 | + } | |
| 1254 | + | |
| 1255 | + if ( 'undefined' !== typeof child.classList && child.classList.contains( 'form-field' ) ) { | |
| 1256 | + wrapFieldLiInPlace( child ); | |
| 1257 | + } | |
| 1258 | + } | |
| 1259 | + ); | |
| 1260 | + } | |
| 1261 | + ); | |
| 1262 | + } | |
| 1263 | + | |
| 1264 | + function deleteEmptyDividerWrappers() { | |
| 1265 | + const dividers = document.querySelectorAll( 'ul.start_divider' ); | |
| 1266 | + if ( ! dividers.length ) { | |
| 1267 | + return; | |
| 1268 | + } | |
| 1269 | + dividers.forEach( | |
| 1270 | + function( divider ) { | |
| 1271 | + const children = [].slice.call( divider.children ); | |
| 1272 | + children.forEach( | |
| 1273 | + function( child ) { | |
| 1274 | + if ( 0 === child.children.length ) { | |
| 1275 | + child.remove(); | |
| 1276 | + } else if ( 1 === child.children.length && 'ul' === child.firstElementChild.nodeName.toLowerCase() && 0 === child.firstElementChild.children.length ) { | |
| 1277 | + child.remove(); | |
| 1278 | + } | |
| 1279 | + } | |
| 1280 | + ); | |
| 1281 | + } | |
| 1282 | + ); | |
| 1283 | + } | |
| 1284 | + | |
| 1285 | + function getFieldsInRow( $row ) { | |
| 1286 | + let $fields = jQuery(); | |
| 1287 | + | |
| 1288 | + const row = $row.get( 0 ); | |
| 1289 | + if ( ! row.children ) { | |
| 1290 | + return $fields; | |
| 1291 | + } | |
| 1292 | + | |
| 1293 | + Array.from( row.children ).forEach( | |
| 1294 | + child => { | |
| 1295 | + if ( 'none' === child.style.display ) { | |
| 1296 | + return; | |
| 1297 | + } | |
| 1298 | + | |
| 1299 | + const classes = child.classList; | |
| 1300 | + if ( ! classes.contains( 'form-field' ) || classes.contains( 'edit_field_type_end_divider' ) || classes.contains( 'frm-sortable-helper' ) ) { | |
| 1301 | + return; | |
| 1302 | + } | |
| 1303 | + | |
| 1304 | + $fields = $fields.add( child ); | |
| 1305 | + } | |
| 1306 | + ); | |
| 1307 | + return $fields; | |
| 1308 | + } | |
| 1309 | + | |
| 1310 | + function determineIndexBasedOffOfMousePositionInRow( $row, x ) { | |
| 1311 | + var $inputs = getFieldsInRow( $row ), | |
| 1312 | + length = $inputs.length, | |
| 1313 | + index, input, inputLeft, returnIndex; | |
| 1314 | + | |
| 1315 | + returnIndex = 0; | |
| 1316 | + for ( index = length - 1; index >= 0; --index ) { | |
| 1317 | + input = $inputs.get( index ); | |
| 1318 | + inputLeft = jQuery( input ).offset().left; | |
| 1319 | + if ( x > inputLeft ) { | |
| 1320 | + returnIndex = index; | |
| 1321 | + if ( x > inputLeft + ( jQuery( input ).outerWidth() / 2 ) ) { | |
| 1322 | + returnIndex = index + 1; | |
| 1323 | + } | |
| 1324 | + break; | |
| 1325 | + } | |
| 1326 | + } | |
| 1327 | + | |
| 1328 | + return returnIndex; | |
| 1329 | + } | |
| 1330 | + | |
| 1331 | + function syncLayoutClasses( $item, type ) { | |
| 1332 | + var $fields, size, layoutClasses, classToAddFunction; | |
| 1333 | + | |
| 1334 | + if ( 'undefined' === typeof type ) { | |
| 1335 | + type = 'even'; | |
| 1336 | + } | |
| 1337 | + | |
| 1338 | + $fields = $item.parent().children( 'li.form-field, li.frmbutton_loadingnow' ).not( '.edit_field_type_end_divider' ); | |
| 1339 | + size = $fields.length; | |
| 1340 | + layoutClasses = getLayoutClasses(); | |
| 1341 | + | |
| 1342 | + if ( 'even' === type && 5 !== size ) { | |
| 1343 | + $fields.each( getSyncLayoutClass( layoutClasses, getEvenClassForSize( size ) ) ); | |
| 1344 | + } else if ( 'clear' === type ) { | |
| 1345 | + $fields.each( getSyncLayoutClass( layoutClasses, '' ) ); | |
| 1346 | + } else { | |
| 1347 | + if ( -1 !== [ 'left', 'right', 'middle', 'even' ].indexOf( type ) ) { | |
| 1348 | + classToAddFunction = function( index ) { | |
| 1349 | + return getClassForBlock( size, type, index ); | |
| 1350 | + }; | |
| 1351 | + } else { | |
| 1352 | + classToAddFunction = function( index ) { | |
| 1353 | + var size = type[ index ]; | |
| 1354 | + return getLayoutClassForSize( size ); | |
| 1355 | + }; | |
| 1356 | + } | |
| 1357 | + | |
| 1358 | + $fields.each( getSyncLayoutClass( layoutClasses, classToAddFunction ) ); | |
| 1359 | + } | |
| 1360 | + | |
| 1361 | + updateFieldGroupControls( $item.parent(), $fields.length ); | |
| 1362 | + } | |
| 1363 | + | |
| 1364 | + function updateFieldGroupControls( $row, count ) { | |
| 1365 | + var rowOffset, shouldShowControls, controls; | |
| 1366 | + | |
| 1367 | + rowOffset = $row.offset(); | |
| 1368 | + | |
| 1369 | + if ( 'undefined' === typeof rowOffset ) { | |
| 1370 | + return; | |
| 1371 | + } | |
| 1372 | + | |
| 1373 | + shouldShowControls = count >= 2; | |
| 1374 | + | |
| 1375 | + controls = document.getElementById( 'frm_field_group_controls' ); | |
| 1376 | + if ( null === controls ) { | |
| 1377 | + if ( ! shouldShowControls ) { | |
| 1378 | + // exit early. if we do not need controls and they do not exist, do nothing. | |
| 1379 | + return; | |
| 1380 | + } | |
| 1381 | + | |
| 1382 | + controls = div(); | |
| 1383 | + controls.id = 'frm_field_group_controls'; | |
| 1384 | + controls.setAttribute( 'role', 'group' ); | |
| 1385 | + controls.setAttribute( 'tabindex', 0 ); | |
| 1386 | + setFieldControlsHtml( controls ); | |
| 1387 | + document.getElementById( 'frm_builder_page' ).appendChild( controls ); | |
| 1388 | + } | |
| 1389 | + | |
| 1390 | + $row.append( controls ); | |
| 1391 | + controls.style.display = shouldShowControls ? 'block' : 'none'; | |
| 1392 | + } | |
| 1393 | + | |
| 1394 | + function setFieldControlsHtml( controls ) { | |
| 1395 | + var layoutOption, moveOption; | |
| 1396 | + | |
| 1397 | + layoutOption = document.createElement( 'span' ); | |
| 1398 | + layoutOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_field_group_layout_icon"></use></svg>'; | |
| 1399 | + const layoutOptionLabel = __( 'Set Row Layout', 'formidable' ); | |
| 1400 | + addTooltip( layoutOption, layoutOptionLabel ); | |
| 1401 | + makeTabbable( layoutOption, layoutOptionLabel ); | |
| 1402 | + | |
| 1403 | + moveOption = document.createElement( 'span' ); | |
| 1404 | + moveOption.innerHTML = '<svg class="frmsvg"><use xlink:href="#frm_thick_move_icon"></use></svg>'; | |
| 1405 | + moveOption.classList.add( 'frm-move' ); | |
| 1406 | + const moveOptionLabel = __( 'Move Field Group', 'formidable' ); | |
| 1407 | + addTooltip( moveOption, moveOptionLabel ); | |
| 1408 | + makeTabbable( moveOption, moveOptionLabel ); | |
| 1409 | + | |
| 1410 | + controls.innerHTML = ''; | |
| 1411 | + controls.appendChild( layoutOption ); | |
| 1412 | + controls.appendChild( moveOption ); | |
| 1413 | + controls.appendChild( getFieldControlsDropdown() ); | |
| 1414 | + } | |
| 1415 | + | |
| 1416 | + function addTooltip( element, title ) { | |
| 1417 | + element.setAttribute( 'data-toggle', 'tooltip' ); | |
| 1418 | + element.setAttribute( 'data-container', 'body' ); | |
| 1419 | + element.setAttribute( 'title', title ); | |
| 1420 | + element.addEventListener( | |
| 1421 | + 'mouseover', | |
| 1422 | + function() { | |
| 1423 | + if ( null === element.getAttribute( 'data-original-title' ) ) { | |
| 1424 | + jQuery( element ).tooltip(); | |
| 1425 | + } | |
| 1426 | + } | |
| 1427 | + ); | |
| 1428 | + } | |
| 1429 | + | |
| 1430 | + function getFieldControlsDropdown() { | |
| 1431 | + var dropdown, trigger, ul; | |
| 1432 | + | |
| 1433 | + dropdown = document.createElement( 'span' ); | |
| 1434 | + dropdown.classList.add( 'dropdown' ); | |
| 1435 | + | |
| 1436 | + trigger = document.createElement( 'a' ); | |
| 1437 | + trigger.classList.add( 'frm_bstooltip', 'frm-hover-icon', 'frm-dropdown-toggle', 'dropdown-toggle' ); | |
| 1438 | + trigger.setAttribute( 'title', __( 'More Options', 'formidable' ) ); | |
| 1439 | + trigger.setAttribute( 'data-toggle', 'dropdown' ); | |
| 1440 | + trigger.setAttribute( 'data-container', 'body' ); | |
| 1441 | + makeTabbable( trigger, __( 'More Options', 'formidable' ) ); | |
| 1442 | + trigger.innerHTML = '<span><svg class="frmsvg"><use xlink:href="#frm_thick_more_vert_icon"></use></svg></span>'; | |
| 1443 | + dropdown.appendChild( trigger ); | |
| 1444 | + | |
| 1445 | + ul = document.createElement( 'div' ); | |
| 1446 | + ul.classList.add( 'frm-dropdown-menu', 'dropdown-menu', 'dropdown-menu-right' ); | |
| 1447 | + ul.setAttribute( 'role', 'menu' ); | |
| 1448 | + dropdown.appendChild( ul ); | |
| 1449 | + | |
| 1450 | + return dropdown; | |
| 1451 | + } | |
| 1452 | + | |
| 1453 | + function getSyncLayoutClass( layoutClasses, classToAdd ) { | |
| 1454 | + return function( itemIndex ) { | |
| 1455 | + var currentClassToAdd, length, layoutClassIndex, currentClass, activeLayoutClass, fieldId, layoutClassesInput; | |
| 1456 | + | |
| 1457 | + currentClassToAdd = 'function' === typeof classToAdd ? classToAdd( itemIndex ) : classToAdd; | |
| 1458 | + length = layoutClasses.length; | |
| 1459 | + activeLayoutClass = false; | |
| 1460 | + for ( layoutClassIndex = 0; layoutClassIndex < length; ++layoutClassIndex ) { | |
| 1461 | + currentClass = layoutClasses[ layoutClassIndex ]; | |
| 1462 | + if ( this.classList.contains( currentClass ) ) { | |
| 1463 | + activeLayoutClass = currentClass; | |
| 1464 | + break; | |
| 1465 | + } | |
| 1466 | + } | |
| 1467 | + | |
| 1468 | + fieldId = this.dataset.fid; | |
| 1469 | + | |
| 1470 | + if ( 'undefined' === typeof fieldId ) { | |
| 1471 | + // we are syncing the drag/drop placeholder before the actual field has loaded. | |
| 1472 | + // this will get called again afterward and the input will exist then. | |
| 1473 | + this.classList.add( currentClassToAdd ); | |
| 1474 | + return; | |
| 1475 | + } | |
| 1476 | + | |
| 1477 | + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) ); | |
| 1478 | + layoutClassesInput = document.getElementById( 'frm_classes_' + fieldId ); | |
| 1479 | + | |
| 1480 | + if ( null === layoutClassesInput ) { | |
| 1481 | + // not every field type has a layout class input. | |
| 1482 | + return; | |
| 1483 | + } | |
| 1484 | + | |
| 1485 | + if ( false === activeLayoutClass ) { | |
| 1486 | + if ( '' !== currentClassToAdd ) { | |
| 1487 | + layoutClassesInput.value = layoutClassesInput.value.concat( ' ' + currentClassToAdd ); | |
| 1488 | + } | |
| 1489 | + } else { | |
| 1490 | + this.classList.remove( activeLayoutClass ); | |
| 1491 | + layoutClassesInput.value = layoutClassesInput.value.replace( activeLayoutClass, currentClassToAdd ); | |
| 1492 | + } | |
| 1493 | + | |
| 1494 | + if ( this.classList.contains( 'frm_first' ) ) { | |
| 1495 | + this.classList.remove( 'frm_first' ); | |
| 1496 | + layoutClassesInput.value = layoutClassesInput.value.replace( 'frm_first', '' ).trim(); | |
| 1497 | + } | |
| 1498 | + | |
| 1499 | + if ( 0 === itemIndex ) { | |
| 1500 | + this.classList.add( 'frm_first' ); | |
| 1501 | + layoutClassesInput.value = layoutClassesInput.value.concat( ' frm_first' ); | |
| 1502 | + } | |
| 1503 | + | |
| 1504 | + jQuery( layoutClassesInput ).trigger( 'change' ); | |
| 1505 | + }; | |
| 1506 | + } | |
| 1507 | + | |
| 1508 | + function getLayoutClasses() { | |
| 1509 | + 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' ]; | |
| 1510 | + } | |
| 1511 | + | |
| 1512 | + function setupFieldOptionSorting( sort ) { | |
| 1513 | + var opts = { | |
| 1514 | + items: '.frm_sortable_field_opts li', | |
| 1515 | + axis: 'y', | |
| 1516 | + opacity: 0.65, | |
| 1517 | + forcePlaceholderSize: false, | |
| 1518 | + handle: '.frm-drag', | |
| 1519 | + helper: function( e, li ) { | |
| 1520 | + copyHelper = li.clone().insertAfter( li ); | |
| 1521 | + return li.clone(); | |
| 1522 | + }, | |
| 1523 | + stop: function( e, ui ) { | |
| 1524 | + copyHelper && copyHelper.remove(); | |
| 1525 | + var fieldId = ui.item.attr( 'id' ).replace( 'frm_delete_field_', '' ).replace( '-' + ui.item.data( 'optkey' ) + '_container', '' ); | |
| 1526 | + resetDisplayedOpts( fieldId ); | |
| 1527 | + } | |
| 1528 | + }; | |
| 1529 | + jQuery( sort ).sortable( opts ); | |
| 1530 | + } | |
| 1531 | + | |
| 1532 | + // Get the section where a field is dropped | |
| 1533 | + function getSectionForFieldPlacement( currentItem ) { | |
| 1534 | + var section = ''; | |
| 1535 | + if ( typeof currentItem !== 'undefined' && ! currentItem.hasClass( 'edit_field_type_divider' ) ) { | |
| 1536 | + section = currentItem.closest( '.edit_field_type_divider' ); | |
| 1537 | + } | |
| 1538 | + return section; | |
| 1539 | + } | |
| 1540 | + | |
| 1541 | + // Get the form ID where a field is dropped | |
| 1542 | + function getFormIdForFieldPlacement( section ) { | |
| 1543 | + var formId = ''; | |
| 1544 | + | |
| 1545 | + if ( typeof section[0] !== 'undefined' ) { | |
| 1546 | + var sDivide = section.children( '.start_divider' ); | |
| 1547 | + sDivide.children( '.edit_field_type_end_divider' ).appendTo( sDivide ); | |
| 1548 | + if ( typeof section.attr( 'data-formid' ) !== 'undefined' ) { | |
| 1549 | + var fieldId = section.attr( 'data-fid' ); | |
| 1550 | + formId = jQuery( 'input[name="field_options[form_select_' + fieldId + ']"]' ).val(); | |
| 1551 | + } | |
| 1552 | + } | |
| 1553 | + | |
| 1554 | + if ( typeof formId === 'undefined' || formId === '' ) { | |
| 1555 | + formId = thisFormId; | |
| 1556 | + } | |
| 1557 | + | |
| 1558 | + return formId; | |
| 1559 | + } | |
| 1560 | + | |
| 1561 | + // Get the section ID where a field is dropped | |
| 1562 | + function getSectionIdForFieldPlacement( section ) { | |
| 1563 | + var sectionId = 0; | |
| 1564 | + if ( typeof section[0] !== 'undefined' ) { | |
| 1565 | + sectionId = section.attr( 'id' ).replace( 'frm_field_id_', '' ); | |
| 1566 | + } | |
| 1567 | + | |
| 1568 | + return sectionId; | |
| 1569 | + } | |
| 1570 | + | |
| 1571 | + /** | |
| 1572 | + * Update a field after it is dragged and dropped into, out of, or between sections | |
| 1573 | + * | |
| 1574 | + * @param {Object} currentItem | |
| 1575 | + * @param {Object} previousSection | |
| 1576 | + * @returns {void} | |
| 1577 | + */ | |
| 1578 | + function updateFieldAfterMovingBetweenSections( currentItem, previousSection ) { | |
| 1579 | + if ( ! currentItem.hasClass( 'form-field' ) ) { | |
| 1580 | + // currentItem is a field group. Call for children recursively. | |
| 1581 | + getFieldsInRow( jQuery( currentItem.get( 0 ).firstChild ) ).each( | |
| 1582 | + function() { | |
| 1583 | + updateFieldAfterMovingBetweenSections( jQuery( this ), previousSection ); | |
| 1584 | + } | |
| 1585 | + ); | |
| 1586 | + return; | |
| 1587 | + } | |
| 1588 | + | |
| 1589 | + const fieldId = currentItem.attr( 'id' ).replace( 'frm_field_id_', '' ); | |
| 1590 | + const section = getSectionForFieldPlacement( currentItem ); | |
| 1591 | + const formId = getFormIdForFieldPlacement( section ); | |
| 1592 | + const sectionId = getSectionIdForFieldPlacement( section ); | |
| 1593 | + const previousFormId = previousSection ? getFormIdForFieldPlacement( jQuery( previousSection.parentNode ) ) : 0; | |
| 1594 | + | |
| 1595 | + jQuery.ajax({ | |
| 1596 | + type: 'POST', | |
| 1597 | + url: ajaxurl, | |
| 1598 | + data: { | |
| 1599 | + action: 'frm_update_field_after_move', | |
| 1600 | + form_id: formId, | |
| 1601 | + field: fieldId, | |
| 1602 | + section_id: sectionId, | |
| 1603 | + previous_form_id: previousFormId, | |
| 1604 | + nonce: frmGlobal.nonce | |
| 1605 | + }, | |
| 1606 | + success: function() { | |
| 1607 | + toggleSectionHolder(); | |
| 1608 | + updateInSectionValue( fieldId, sectionId ); | |
| 1609 | + } | |
| 1610 | + }); | |
| 1611 | + } | |
| 1612 | + | |
| 1613 | + // Update the in_section field value | |
| 1614 | + function updateInSectionValue( fieldId, sectionId ) { | |
| 1615 | + document.getElementById( 'frm_in_section_' + fieldId ).value = sectionId; | |
| 1616 | + } | |
| 1617 | + | |
| 1618 | + /** | |
| 1619 | + * Add a new field by dragging and dropping it from the Fields sidebar | |
| 1620 | + * | |
| 1621 | + * @param {string} fieldType | |
| 1622 | + */ | |
| 1623 | + function insertNewFieldByDragging( fieldType ) { | |
| 1624 | + const placeholder = document.getElementById( 'frm_drag_placeholder' ); | |
| 1625 | + const loadingID = fieldType.replace( '|', '-' ) + '_' + getAutoId(); | |
| 1626 | + const loading = tag( | |
| 1627 | + 'li', | |
| 1628 | + { | |
| 1629 | + id: loadingID, | |
| 1630 | + className: 'frm-wait frmbutton_loadingnow' | |
| 1631 | + } | |
| 1632 | + ); | |
| 1633 | + const $placeholder = jQuery( loading ); | |
| 1634 | + const currentItem = jQuery( placeholder ); | |
| 1635 | + const section = getSectionForFieldPlacement( currentItem ); | |
| 1636 | + const formId = getFormIdForFieldPlacement( section ); | |
| 1637 | + const sectionId = getSectionIdForFieldPlacement( section ); | |
| 1638 | + | |
| 1639 | + placeholder.parentNode.insertBefore( loading, placeholder ); | |
| 1640 | + placeholder.remove(); | |
| 1641 | + syncLayoutClasses( $placeholder ); | |
| 1642 | + | |
| 1643 | + let hasBreak = 0; | |
| 1644 | + if ( 'summary' === fieldType ) { | |
| 1645 | + // see if we need to insert a page break before this newly-added summary field. Check for at least 1 page break | |
| 1646 | + hasBreak = jQuery( '.frmbutton_loadingnow#' + loadingID ).prevAll( 'li[data-type="break"]' ).length ? 1 : 0; | |
| 1647 | + } | |
| 1648 | + | |
| 1649 | + jQuery.ajax({ | |
| 1650 | + type: 'POST', url: ajaxurl, | |
| 1651 | + data: { | |
| 1652 | + action: 'frm_insert_field', | |
| 1653 | + form_id: formId, | |
| 1654 | + field_type: fieldType, | |
| 1655 | + section_id: sectionId, | |
| 1656 | + nonce: frmGlobal.nonce, | |
| 1657 | + has_break: hasBreak | |
| 1658 | + }, | |
| 1659 | + success: function( msg ) { | |
| 1660 | + let replaceWith; | |
| 1661 | + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' ); | |
| 1662 | + const $siblings = $placeholder.siblings( 'li.form-field' ).not( '.edit_field_type_end_divider' ); | |
| 1663 | + if ( ! $siblings.length ) { | |
| 1664 | + // if dragging into a new row, we need to wrap the li first. | |
| 1665 | + replaceWith = wrapFieldLi( msg ); | |
| 1666 | + } else { | |
| 1667 | + replaceWith = msgAsjQueryObject( msg ); | |
| 1668 | + if ( ! $placeholder.get( 0 ).parentNode.parentNode.classList.contains( 'ui-draggable' ) ) { | |
| 1669 | + // If a field group wasn't draggable because it only had a single field, make it draggable. | |
| 1670 | + makeDraggable( $placeholder.get( 0 ).parentNode.parentNode, '.frm-move' ); | |
| 1671 | + } | |
| 1672 | + } | |
| 1673 | + $placeholder.replaceWith( replaceWith ); | |
| 1674 | + updateFieldOrder(); | |
| 1675 | + afterAddField( msg, false ); | |
| 1676 | + if ( $siblings.length ) { | |
| 1677 | + syncLayoutClasses( $siblings.first() ); | |
| 1678 | + } | |
| 1679 | + toggleSectionHolder(); | |
| 1680 | + | |
| 1681 | + if ( ! $siblings.length ) { | |
| 1682 | + makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) ); | |
| 1683 | + makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' ); | |
| 1684 | + } else { | |
| 1685 | + makeDraggable( replaceWith.get( 0 ), '.frm-move' ); | |
| 1686 | + } | |
| 1687 | + | |
| 1688 | + }, | |
| 1689 | + error: handleInsertFieldError | |
| 1690 | + }); | |
| 1691 | + } | |
| 1692 | + | |
| 1693 | + function moveFieldThatAlreadyExists( draggable, placeholder ) { | |
| 1694 | + placeholder.parentNode.insertBefore( draggable, placeholder ); | |
| 1695 | + } | |
| 1696 | + | |
| 1697 | + function msgAsjQueryObject( msg ) { | |
| 1698 | + const element = div(); | |
| 1699 | + element.innerHTML = msg; | |
| 1700 | + return jQuery( element.firstChild ); | |
| 1701 | + } | |
| 1702 | + | |
| 1703 | + function handleInsertFieldError( jqXHR, _, errorThrown ) { | |
| 1704 | + maybeShowInsertFieldError( errorThrown, jqXHR ); | |
| 1705 | + } | |
| 1706 | + | |
| 1707 | + function maybeShowInsertFieldError( errorThrown, jqXHR ) { | |
| 1708 | + if ( ! jqXHRAborted( jqXHR ) ) { | |
| 1709 | + infoModal( errorThrown + '. Please try again.' ); | |
| 1710 | + } | |
| 1711 | + } | |
| 1712 | + | |
| 1713 | + function jqXHRAborted( jqXHR ) { | |
| 1714 | + return jqXHR.status === 0 || jqXHR.readyState === 0; | |
| 1715 | + } | |
| 1716 | + | |
| 1717 | + /** | |
| 1718 | + * Get a unique id that automatically increments with every function call. | |
| 1719 | + * Can be used for any UI that requires a unique id. | |
| 1720 | + * Not to be used in data. | |
| 1721 | + * | |
| 1722 | + * @returns {integer} | |
| 1723 | + */ | |
| 1724 | + function getAutoId() { | |
| 1725 | + return ++autoId; | |
| 1726 | + } | |
| 1727 | + | |
| 1728 | + // Don't allow page break, embed form, or section inside section field | |
| 1729 | + // Don't allow page breaks inside of field groups. | |
| 1730 | + // Don't allow field groups with sections inside of sections. | |
| 1731 | + // Don't allow field groups in field groups. | |
| 1732 | + // Don't allow hidden fields inside of field groups but allow them in sections. | |
| 1733 | + function allowDrop( draggable, droppable ) { | |
| 1734 | + if ( false === droppable ) { | |
| 1735 | + // Don't show drop placeholder if dragging somewhere off of the droppable area. | |
| 1736 | + return false; | |
| 1737 | + } | |
| 1738 | + | |
| 1739 | + if ( droppable.closest( '.frm-sortable-helper' ) ) { | |
| 1740 | + // Do not allow drop into draggable. | |
| 1741 | + return false; | |
| 1742 | + } | |
| 1743 | + | |
| 1744 | + if ( 'frm-show-fields' === droppable.id ) { | |
| 1745 | + // Everything can be dropped into the main list of fields. | |
| 1746 | + return true; | |
| 1747 | + } | |
| 1748 | + | |
| 1749 | + if ( ! droppable.classList.contains( 'start_divider' ) ) { | |
| 1750 | + const $fieldsInRow = getFieldsInRow( jQuery( droppable ) ); | |
| 1751 | + if ( ! groupCanFitAnotherField( $fieldsInRow, jQuery( draggable ) ) ) { | |
| 1752 | + // Field group is full and cannot accept another field. | |
| 1753 | + return false; | |
| 1754 | + } | |
| 1755 | + } | |
| 1756 | + | |
| 1757 | + const isNewField = draggable.classList.contains( 'frm-new-field' ); | |
| 1758 | + if ( isNewField ) { | |
| 1759 | + return allowNewFieldDrop( draggable, droppable ); | |
| 1760 | + } | |
| 1761 | + | |
| 1762 | + return allowMoveField( draggable, droppable ); | |
| 1763 | + } | |
| 1764 | + | |
| 1765 | + // Don't allow a new page break or hidden field in a field group. | |
| 1766 | + // Don't allow a new field into a field group that includes a page break or hidden field. | |
| 1767 | + // Don't allow a new section inside of a section. | |
| 1768 | + // Don't allow an embedded form in a section. | |
| 1769 | + function allowNewFieldDrop( draggable, droppable ) { | |
| 1770 | + const classes = draggable.classList; | |
| 1771 | + const newPageBreakField = classes.contains( 'frm_tbreak' ); | |
| 1772 | + const newHiddenField = classes.contains( 'frm_thidden' ); | |
| 1773 | + const newSectionField = classes.contains( 'frm_tdivider' ); | |
| 1774 | + const newEmbedField = classes.contains( 'frm_tform' ); | |
| 1775 | + | |
| 1776 | + const newFieldWillBeAddedToAGroup = ! ( 'frm-show-fields' === droppable.id || droppable.classList.contains( 'start_divider' ) ); | |
| 1777 | + if ( newFieldWillBeAddedToAGroup ) { | |
| 1778 | + if ( groupIncludesBreakOrHidden( droppable ) ) { | |
| 1779 | + // Never allow any field beside a page break or a hidden field. | |
| 1780 | + return false; | |
| 1781 | + } | |
| 1782 | + | |
| 1783 | + return ! newHiddenField && ! newPageBreakField; | |
| 1784 | + } | |
| 1785 | + | |
| 1786 | + const fieldTypeIsAlwaysAllowed = ! newPageBreakField && ! newHiddenField && ! newSectionField && ! newEmbedField; | |
| 1787 | + if ( fieldTypeIsAlwaysAllowed ) { | |
| 1788 | + return true; | |
| 1789 | + } | |
| 1790 | + | |
| 1791 | + const newFieldWillBeAddedToASection = droppable.classList.contains( 'start_divider' ) || null !== droppable.closest( '.start_divider' ); | |
| 1792 | + if ( newFieldWillBeAddedToASection ) { | |
| 1793 | + // Don't allow a section or an embedded form in a section. | |
| 1794 | + return ! newEmbedField && ! newSectionField; | |
| 1795 | + } | |
| 1796 | + | |
| 1797 | + return true; | |
| 1798 | + } | |
| 1799 | + | |
| 1800 | + function allowMoveField( draggable, droppable ) { | |
| 1801 | + if ( isFieldGroup( draggable ) ) { | |
| 1802 | + return allowMoveFieldGroup( draggable, droppable ); | |
| 1803 | + } | |
| 1804 | + | |
| 1805 | + const isPageBreak = draggable.classList.contains( 'edit_field_type_break' ); | |
| 1806 | + if ( isPageBreak ) { | |
| 1807 | + // Page breaks are only allowed in the main list of fields, not in sections or in field groups. | |
| 1808 | + return false; | |
| 1809 | + } | |
| 1810 | + | |
| 1811 | + if ( droppable.classList.contains( 'start_divider' ) ) { | |
| 1812 | + return allowMoveFieldToSection( draggable ); | |
| 1813 | + } | |
| 1814 | + | |
| 1815 | + const isHiddenField = draggable.classList.contains( 'edit_field_type_hidden' ); | |
| 1816 | + if ( isHiddenField ) { | |
| 1817 | + // Hidden fields should not be added to field groups since they're not shown and don't make sense with the grid distribution. | |
| 1818 | + return false; | |
| 1819 | + } | |
| 1820 | + | |
| 1821 | + return allowMoveFieldToGroup( draggable, droppable ); | |
| 1822 | + } | |
| 1823 | + | |
| 1824 | + function isFieldGroup( draggable ) { | |
| 1825 | + return draggable.classList.contains( 'frm_field_box' ) && ! draggable.classList.contains( 'form-field' ); | |
| 1826 | + } | |
| 1827 | + | |
| 1828 | + function allowMoveFieldGroup( fieldGroup, droppable ) { | |
| 1829 | + if ( droppable.classList.contains( 'start_divider' ) && null === fieldGroup.querySelector( '.start_divider' ) ) { | |
| 1830 | + // Allow a field group with no section inside of a section. | |
| 1831 | + return true; | |
| 1832 | + } | |
| 1833 | + return false; | |
| 1834 | + } | |
| 1835 | + | |
| 1836 | + function allowMoveFieldToSection( draggable ) { | |
| 1837 | + const draggableIncludeEmbedForm = draggable.classList.contains( 'edit_field_type_form' ) || draggable.querySelector( '.edit_field_type_form' ); | |
| 1838 | + if ( draggableIncludeEmbedForm ) { | |
| 1839 | + // Do not allow an embedded form inside of a section. | |
| 1840 | + return false; | |
| 1841 | + } | |
| 1842 | + | |
| 1843 | + const draggableIncludesSection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' ); | |
| 1844 | + if ( draggableIncludesSection ) { | |
| 1845 | + // Do not allow a section inside of a section. | |
| 1846 | + return false; | |
| 1847 | + } | |
| 1848 | + | |
| 1849 | + return true; | |
| 1850 | + } | |
| 1851 | + | |
| 1852 | + function allowMoveFieldToGroup( draggable, group ) { | |
| 1853 | + if ( groupIncludesBreakOrHidden( group ) ) { | |
| 1854 | + // Never allow any field beside a page break or a hidden field. | |
| 1855 | + return false; | |
| 1856 | + } | |
| 1857 | + | |
| 1858 | + const isFieldGroup = jQuery( draggable ).children( 'ul.frm_sorting' ).not( '.start_divider' ).length > 0; | |
| 1859 | + if ( isFieldGroup ) { | |
| 1860 | + // Do not allow a field group directly inside of a field group unless it's in a section. | |
| 1861 | + return false; | |
| 1862 | + } | |
| 1863 | + | |
| 1864 | + const draggableIncludesASection = draggable.classList.contains( 'edit_field_type_divider' ) || draggable.querySelector( '.edit_field_type_divider' ); | |
| 1865 | + const draggableIsEmbedField = draggable.classList.contains( 'edit_field_type_form' ); | |
| 1866 | + const groupIsInASection = null !== group.closest( '.start_divider' ); | |
| 1867 | + if ( groupIsInASection && ( draggableIncludesASection || draggableIsEmbedField ) ) { | |
| 1868 | + // Do not allow a section or an embed field inside of a section. | |
| 1869 | + return false; | |
| 1870 | + } | |
| 1871 | + | |
| 1872 | + return true; | |
| 1873 | + } | |
| 1874 | + | |
| 1875 | + function groupIncludesBreakOrHidden( group ) { | |
| 1876 | + return null !== group.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ); | |
| 1877 | + } | |
| 1878 | + | |
| 1879 | + function groupCanFitAnotherField( fieldsInRow, $field ) { | |
| 1880 | + var fieldId; | |
| 1881 | + if ( fieldsInRow.length < 6 ) { | |
| 1882 | + return true; | |
| 1883 | + } | |
| 1884 | + if ( fieldsInRow.length > 6 ) { | |
| 1885 | + return false; | |
| 1886 | + } | |
| 1887 | + fieldId = $field.attr( 'data-fid' ); | |
| 1888 | + // allow 6 if we're not changing field groups. | |
| 1889 | + return 1 === jQuery( fieldsInRow ).filter( '[data-fid="' + fieldId + '"]' ).length; | |
| 1890 | + } | |
| 1891 | + | |
| 1892 | + function loadFields( fieldId ) { | |
| 1893 | + const thisField = document.getElementById( fieldId ); | |
| 1894 | + const $thisField = jQuery( thisField ); | |
| 1895 | + const field = []; | |
| 1896 | + const addHtmlToField = element => { | |
| 1897 | + const frmHiddenFdata = element.querySelector( '.frm_hidden_fdata' ); | |
| 1898 | + element.classList.add( 'frm_load_now' ); | |
| 1899 | + if ( frmHiddenFdata !== null ) { | |
| 1900 | + field.push( frmHiddenFdata.innerHTML ); | |
| 1901 | + } | |
| 1902 | + }; | |
| 1903 | + | |
| 1904 | + let nextElement = thisField; | |
| 1905 | + addHtmlToField( nextElement ); | |
| 1906 | + while ( nextElement.nextElementSibling && field.length < 15 ) { | |
| 1907 | + addHtmlToField( nextElement.nextElementSibling ); | |
| 1908 | + nextElement = nextElement.nextElementSibling; | |
| 1909 | + } | |
| 1910 | + | |
| 1911 | + jQuery.ajax({ | |
| 1912 | + type: 'POST', | |
| 1913 | + url: ajaxurl, | |
| 1914 | + data: { | |
| 1915 | + action: 'frm_load_field', | |
| 1916 | + field: field, | |
| 1917 | + form_id: thisFormId, | |
| 1918 | + nonce: frmGlobal.nonce | |
| 1919 | + }, | |
| 1920 | + success: html => handleAjaxLoadFieldSuccess( html, $thisField, field ) | |
| 1921 | + }); | |
| 1922 | + } | |
| 1923 | + | |
| 1924 | + function handleAjaxLoadFieldSuccess( html, $thisField, field ) { | |
| 1925 | + let key, $nextSet; | |
| 1926 | + | |
| 1927 | + html = html.replace( /^\s+|\s+$/g, '' ); | |
| 1928 | + if ( html.indexOf( '{' ) !== 0 ) { | |
| 1929 | + jQuery( '.frm_load_now' ).removeClass( '.frm_load_now' ).html( 'Error' ); | |
| 1930 | + return; | |
| 1931 | + } | |
| 1932 | + | |
| 1933 | + html = JSON.parse( html ); | |
| 1934 | + for ( key in html ) { | |
| 1935 | + jQuery( '#frm_field_id_' + key ).replaceWith( html[key]); | |
| 1936 | + setupSortable( '#frm_field_id_' + key + '.edit_field_type_divider ul.frm_sorting' ); | |
| 1937 | + makeDraggable( document.getElementById( 'frm_field_id_' + key ) ); | |
| 1938 | + } | |
| 1939 | + | |
| 1940 | + $nextSet = $thisField.nextAll( '.frm_field_loading:not(.frm_load_now)' ); | |
| 1941 | + if ( $nextSet.length ) { | |
| 1942 | + loadFields( $nextSet.attr( 'id' ) ); | |
| 1943 | + } else { | |
| 1944 | + // go up a level | |
| 1945 | + $nextSet = jQuery( document.getElementById( 'frm-show-fields' ) ).find( '.frm_field_loading:not(.frm_load_now)' ); | |
| 1946 | + if ( $nextSet.length ) { | |
| 1947 | + loadFields( $nextSet.attr( 'id' ) ); | |
| 1948 | + } | |
| 1949 | + } | |
| 1950 | + | |
| 1951 | + initiateMultiselect(); | |
| 1952 | + renumberPageBreaks(); | |
| 1953 | + maybeHideQuantityProductFieldOption(); | |
| 1954 | + | |
| 1955 | + const loadedEvent = new Event( 'frm_ajax_loaded_field', { bubbles: false }); | |
| 1956 | + loadedEvent.frmFields = field.map( f => JSON.parse( f ) ); | |
| 1957 | + document.dispatchEvent( loadedEvent ); | |
| 1958 | + } | |
| 1959 | + | |
| 1960 | + function addFieldClick() { | |
| 1961 | + /*jshint validthis:true */ | |
| 1962 | + const $thisObj = jQuery( this ); | |
| 1963 | + // there is no real way to disable a <a> (with a valid href attribute) in HTML - https://css-tricks.com/how-to-disable-links/ | |
| 1964 | + if ( $thisObj.hasClass( 'disabled' ) ) { | |
| 1965 | + return false; | |
| 1966 | + } | |
| 1967 | + | |
| 1968 | + const $button = $thisObj.closest( '.frmbutton' ); | |
| 1969 | + const fieldType = $button.attr( 'id' ); | |
| 1970 | + | |
| 1971 | + let hasBreak = 0; | |
| 1972 | + if ( 'summary' === fieldType ) { | |
| 1973 | + hasBreak = $newFields.children( 'li[data-type="break"]' ).length > 0 ? 1 : 0; | |
| 1974 | + } | |
| 1975 | + | |
| 1976 | + const formId = thisFormId; | |
| 1977 | + jQuery.ajax({ | |
| 1978 | + type: 'POST', | |
| 1979 | + url: ajaxurl, | |
| 1980 | + data: { | |
| 1981 | + action: 'frm_insert_field', | |
| 1982 | + form_id: formId, | |
| 1983 | + field_type: fieldType, | |
| 1984 | + section_id: 0, | |
| 1985 | + nonce: frmGlobal.nonce, | |
| 1986 | + has_break: hasBreak | |
| 1987 | + }, | |
| 1988 | + success: function( msg ) { | |
| 1989 | + document.getElementById( 'frm_form_editor_container' ).classList.add( 'frm-has-fields' ); | |
| 1990 | + const replaceWith = wrapFieldLi( msg ); | |
| 1991 | + $newFields.append( replaceWith ); | |
| 1992 | + afterAddField( msg, true ); | |
| 1993 | + | |
| 1994 | + replaceWith.each( | |
| 1995 | + function() { | |
| 1996 | + makeDroppable( this.querySelector( 'ul.frm_sorting' ) ); | |
| 1997 | + makeDraggable( this.querySelector( '.form-field' ), '.frm-move' ); | |
| 1998 | + } | |
| 1999 | + ); | |
| 2000 | + }, | |
| 2001 | + error: handleInsertFieldError | |
| 2002 | + }); | |
| 2003 | + return false; | |
| 2004 | + } | |
| 2005 | + | |
| 2006 | + function maybeHideQuantityProductFieldOption() { | |
| 2007 | + var hide = true, | |
| 2008 | + opts = document.querySelectorAll( '.frmjs_prod_field_opt_cont' ); | |
| 2009 | + | |
| 2010 | + if ( $newFields.find( 'li.edit_field_type_product' ).length > 1 ) { | |
| 2011 | + hide = false; | |
| 2012 | + } | |
| 2013 | + | |
| 2014 | + for ( var i = 0; i < opts.length; i++ ) { | |
| 2015 | + if ( hide ) { | |
| 2016 | + opts[ i ].classList.add( 'frm_hidden' ); | |
| 2017 | + } else { | |
| 2018 | + opts[ i ].classList.remove( 'frm_hidden' ); | |
| 2019 | + } | |
| 2020 | + } | |
| 2021 | + } | |
| 2022 | + | |
| 2023 | + function duplicateField() { | |
| 2024 | + var $field, fieldId, children, newRowId, fieldOrder; | |
| 2025 | + | |
| 2026 | + $field = jQuery( this ).closest( 'li.form-field' ); | |
| 2027 | + | |
| 2028 | + if ( $field.hasClass( 'frm-section-collapsed' ) || $field.hasClass( 'frm-page-collapsed' ) ) { | |
| 2029 | + return false; | |
| 2030 | + } | |
| 2031 | + | |
| 2032 | + closeOpenFieldDropdowns(); | |
| 2033 | + | |
| 2034 | + fieldId = $field.data( 'fid' ); | |
| 2035 | + children = fieldsInSection( fieldId ); | |
| 2036 | + newRowId = this.getAttribute( 'frm-target-row-id' ); | |
| 2037 | + | |
| 2038 | + if ( null !== newRowId ) { | |
| 2039 | + fieldOrder = this.getAttribute( 'frm-field-order' ); | |
| 2040 | + } | |
| 2041 | + | |
| 2042 | + jQuery.ajax({ | |
| 2043 | + type: 'POST', | |
| 2044 | + url: ajaxurl, | |
| 2045 | + data: { | |
| 2046 | + action: 'frm_duplicate_field', | |
| 2047 | + field_id: fieldId, | |
| 2048 | + form_id: thisFormId, | |
| 2049 | + children: children, | |
| 2050 | + nonce: frmGlobal.nonce | |
| 2051 | + }, | |
| 2052 | + success: function( msg ) { | |
| 2053 | + var newRow; | |
| 2054 | + | |
| 2055 | + let replaceWith; | |
| 2056 | + | |
| 2057 | + if ( null !== newRowId ) { | |
| 2058 | + newRow = document.getElementById( newRowId ); | |
| 2059 | + if ( null !== newRow ) { | |
| 2060 | + replaceWith = msgAsjQueryObject( msg ); | |
| 2061 | + jQuery( newRow ).append( replaceWith ); | |
| 2062 | + makeDraggable( replaceWith.get( 0 ), '.frm-move' ); | |
| 2063 | + if ( null !== fieldOrder ) { | |
| 2064 | + newRow.lastElementChild.setAttribute( 'frm-field-order', fieldOrder ); | |
| 2065 | + } | |
| 2066 | + jQuery( newRow ).trigger( | |
| 2067 | + 'frm_added_duplicated_field_to_row', | |
| 2068 | + { | |
| 2069 | + duplicatedFieldHtml: msg, | |
| 2070 | + originalFieldId: fieldId | |
| 2071 | + } | |
| 2072 | + ); | |
| 2073 | + afterAddField( msg, false ); | |
| 2074 | + return; | |
| 2075 | + } | |
| 2076 | + } | |
| 2077 | + | |
| 2078 | + if ( $field.siblings( 'li.form-field' ).length ) { | |
| 2079 | + replaceWith = msgAsjQueryObject( msg ); | |
| 2080 | + $field.after( replaceWith ); | |
| 2081 | + syncLayoutClasses( $field ); | |
| 2082 | + makeDraggable( replaceWith.get( 0 ), '.frm-move' ); | |
| 2083 | + } else { | |
| 2084 | + replaceWith = wrapFieldLi( msg ); | |
| 2085 | + $field.parent().parent().after( replaceWith ); | |
| 2086 | + makeDroppable( replaceWith.get( 0 ).querySelector( 'ul.frm_sorting' ) ); | |
| 2087 | + makeDraggable( replaceWith.get( 0 ).querySelector( 'li.form-field' ), '.frm-move' ); | |
| 2088 | + } | |
| 2089 | + | |
| 2090 | + updateFieldOrder(); | |
| 2091 | + afterAddField( msg, false ); | |
| 2092 | + maybeDuplicateUnsavedSettings( fieldId, msg ); | |
| 2093 | + toggleOneSectionHolder( replaceWith.find( '.start_divider' ) ); | |
| 2094 | + } | |
| 2095 | + }); | |
| 2096 | + return false; | |
| 2097 | + } | |
| 2098 | + | |
| 2099 | + function maybeDuplicateUnsavedSettings( originalFieldId, newFieldHtml ) { | |
| 2100 | + var originalSettings, newFieldId, copySettings, fieldOptionKeys, originalDefault, copyDefault; | |
| 2101 | + | |
| 2102 | + originalSettings = document.getElementById( 'frm-single-settings-' + originalFieldId ); | |
| 2103 | + if ( null === originalSettings ) { | |
| 2104 | + return; | |
| 2105 | + } | |
| 2106 | + | |
| 2107 | + newFieldId = jQuery( newFieldHtml ).attr( 'data-fid' ); | |
| 2108 | + if ( 'undefined' === typeof newFieldId ) { | |
| 2109 | + return; | |
| 2110 | + } | |
| 2111 | + | |
| 2112 | + copySettings = document.getElementById( 'frm-single-settings-' + newFieldId ); | |
| 2113 | + if ( null === copySettings ) { | |
| 2114 | + return; | |
| 2115 | + } | |
| 2116 | + | |
| 2117 | + fieldOptionKeys = [ | |
| 2118 | + 'name', 'required', 'unique', 'read_only', 'placeholder', 'description', 'size', 'max', 'format', 'prepend', 'append', 'separate_value' | |
| 2119 | + ]; | |
| 2120 | + | |
| 2121 | + originalSettings.querySelectorAll( 'input[name^="field_options["], textarea[name^="field_options["]' ).forEach( | |
| 2122 | + function( originalSetting ) { | |
| 2123 | + var key, tagType, copySetting; | |
| 2124 | + | |
| 2125 | + key = getKeyFromSettingInput( originalSetting ); | |
| 2126 | + | |
| 2127 | + if ( 'options' === key ) { | |
| 2128 | + copyOption( originalSetting, copySettings, originalFieldId, newFieldId ); | |
| 2129 | + return; | |
| 2130 | + } | |
| 2131 | + | |
| 2132 | + if ( -1 === fieldOptionKeys.indexOf( key ) ) { | |
| 2133 | + return; | |
| 2134 | + } | |
| 2135 | + | |
| 2136 | + tagType = originalSetting.matches( 'input' ) ? 'input' : 'textarea'; | |
| 2137 | + copySetting = copySettings.querySelector( tagType + '[name="field_options[' + key + '_' + newFieldId + ']"]' ); | |
| 2138 | + if ( null === copySetting ) { | |
| 2139 | + return; | |
| 2140 | + } | |
| 2141 | + | |
| 2142 | + if ( 'checkbox' === originalSetting.type ) { | |
| 2143 | + if ( originalSetting.checked !== copySetting.checked ) { | |
| 2144 | + jQuery( copySetting ).trigger( 'click' ); | |
| 2145 | + } | |
| 2146 | + } else if ( 'text' === originalSetting.type || 'textarea' === tagType ) { | |
| 2147 | + if ( originalSetting.value !== copySetting.value ) { | |
| 2148 | + copySetting.value = originalSetting.value; | |
| 2149 | + jQuery( copySetting ).trigger( 'change' ); | |
| 2150 | + } | |
| 2151 | + } | |
| 2152 | + } | |
| 2153 | + ); | |
| 2154 | + | |
| 2155 | + originalDefault = originalSettings.querySelector( 'input[name="default_value_' + originalFieldId + '"]' ); | |
| 2156 | + if ( null !== originalDefault ) { | |
| 2157 | + copyDefault = copySettings.querySelector( 'input[name="default_value_' + newFieldId + '"]' ); | |
| 2158 | + if ( null !== copyDefault && originalDefault.value !== copyDefault.value ) { | |
| 2159 | + copyDefault.value = originalDefault.value; | |
| 2160 | + jQuery( copyDefault ).trigger( 'change' ); | |
| 2161 | + } | |
| 2162 | + } | |
| 2163 | + } | |
| 2164 | + | |
| 2165 | + function copyOption( originalSetting, copySettings, originalFieldId, newFieldId ) { | |
| 2166 | + var remainingKeyDetails, copyKey, copySetting; | |
| 2167 | + remainingKeyDetails = originalSetting.name.substr( 23 + ( '' + originalFieldId ).length ); | |
| 2168 | + copyKey = 'field_options[options_' + newFieldId + ']' + remainingKeyDetails; | |
| 2169 | + copySetting = copySettings.querySelector( 'input[name="' + copyKey + '"]' ); | |
| 2170 | + if ( null !== copySetting && copySetting.value !== originalSetting.value ) { | |
| 2171 | + copySetting.value = originalSetting.value; | |
| 2172 | + jQuery( copySetting ).trigger( 'change' ); | |
| 2173 | + } | |
| 2174 | + } | |
| 2175 | + | |
| 2176 | + function getKeyFromSettingInput( input ) { | |
| 2177 | + var nameWithoutPrefix, nameSplit; | |
| 2178 | + nameWithoutPrefix = input.name.substr( 14 ); | |
| 2179 | + nameSplit = nameWithoutPrefix.split( '_' ); | |
| 2180 | + nameSplit.pop(); | |
| 2181 | + return nameSplit.join( '_' ); | |
| 2182 | + } | |
| 2183 | + | |
| 2184 | + function closeOpenFieldDropdowns() { | |
| 2185 | + var openSettings = document.querySelector( '.frm-field-settings-open' ); | |
| 2186 | + if ( null !== openSettings ) { | |
| 2187 | + openSettings.classList.remove( 'frm-field-settings-open' ); | |
| 2188 | + jQuery( document ).off( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings ); | |
| 2189 | + jQuery( '.frm-field-action-icons .dropdown.open' ).removeClass( 'open' ); | |
| 2190 | + } | |
| 2191 | + } | |
| 2192 | + | |
| 2193 | + function handleClickOutsideOfFieldSettings( event ) { | |
| 2194 | + if ( ! jQuery( event.originalEvent.target ).closest( '.frm-field-action-icons' ).length ) { | |
| 2195 | + closeOpenFieldDropdowns(); | |
| 2196 | + } | |
| 2197 | + } | |
| 2198 | + | |
| 2199 | + function checkForMultiselectKeysOnMouseMove( event ) { | |
| 2200 | + var keyIsDown = ! ! ( event.ctrlKey || event.metaKey || event.shiftKey ); | |
| 2201 | + jQuery( document.getElementById( 'frm_builder_page' ) ).toggleClass( 'frm-multiselect-key-is-down', keyIsDown ); | |
| 2202 | + checkForActiveHoverTarget( event ); | |
| 2203 | + } | |
| 2204 | + | |
| 2205 | + function checkForActiveHoverTarget( event ) { | |
| 2206 | + var container, elementFromPoint, list, previousHoverTarget; | |
| 2207 | + | |
| 2208 | + container = postBodyContent; | |
| 2209 | + if ( container.classList.contains( 'frm-dragging-field' ) ) { | |
| 2210 | + return; | |
| 2211 | + } | |
| 2212 | + | |
| 2213 | + if ( null !== document.querySelector( '.frm-field-group-hover-target .frm-field-settings-open' ) ) { | |
| 2214 | + // do not set a hover target if a dropdown is open for the current hover target. | |
| 2215 | + return; | |
| 2216 | + } | |
| 2217 | + | |
| 2218 | + elementFromPoint = document.elementFromPoint( event.clientX, event.clientY ); | |
| 2219 | + if ( null !== elementFromPoint && ! elementFromPoint.classList.contains( 'edit_field_type_divider' ) ) { | |
| 2220 | + | |
| 2221 | + list = elementFromPoint.closest( 'ul.frm_sorting' ); | |
| 2222 | + | |
| 2223 | + if ( null !== list && ! list.classList.contains( 'start_divider' ) && 'frm-show-fields' !== list.id ) { | |
| 2224 | + previousHoverTarget = maybeRemoveGroupHoverTarget(); | |
| 2225 | + if ( false !== previousHoverTarget && ! jQuery( previousHoverTarget ).is( list ) ) { | |
| 2226 | + destroyFieldGroupPopup(); | |
| 2227 | + } | |
| 2228 | + updateFieldGroupControls( jQuery( list ), getFieldsInRow( jQuery( list ) ).length ); | |
| 2229 | + list.classList.add( 'frm-field-group-hover-target' ); | |
| 2230 | + jQuery( '#wpbody-content' ).on( 'mousemove', maybeRemoveHoverTargetOnMouseMove ); | |
| 2231 | + } | |
| 2232 | + } | |
| 2233 | + } | |
| 2234 | + | |
| 2235 | + function maybeRemoveGroupHoverTarget() { | |
| 2236 | + var controls, previousHoverTarget; | |
| 2237 | + | |
| 2238 | + controls = document.getElementById( 'frm_field_group_controls' ); | |
| 2239 | + if ( null !== controls ) { | |
| 2240 | + controls.style.display = 'none'; | |
| 2241 | + } | |
| 2242 | + | |
| 2243 | + previousHoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 2244 | + if ( null === previousHoverTarget ) { | |
| 2245 | + return false; | |
| 2246 | + } | |
| 2247 | + | |
| 2248 | + jQuery( '#wpbody-content' ).off( 'mousemove', maybeRemoveHoverTargetOnMouseMove ); | |
| 2249 | + previousHoverTarget.classList.remove( 'frm-field-group-hover-target' ); | |
| 2250 | + return previousHoverTarget; | |
| 2251 | + } | |
| 2252 | + | |
| 2253 | + function maybeRemoveHoverTargetOnMouseMove( event ) { | |
| 2254 | + var elementFromPoint = document.elementFromPoint( event.clientX, event.clientY ); | |
| 2255 | + if ( null !== elementFromPoint && null !== elementFromPoint.closest( '#frm-show-fields' ) ) { | |
| 2256 | + return; | |
| 2257 | + } | |
| 2258 | + maybeRemoveGroupHoverTarget(); | |
| 2259 | + } | |
| 2260 | + | |
| 2261 | + function onFieldActionDropdownShow( isFieldGroup ) { | |
| 2262 | + unselectFieldGroups(); | |
| 2263 | + // maybe offset the dropdown if it goes off of the right of the screen. | |
| 2264 | + setTimeout( | |
| 2265 | + function() { | |
| 2266 | + var ul, $ul; | |
| 2267 | + ul = document.querySelector( '.dropdown.show .frm-dropdown-menu' ); | |
| 2268 | + if ( null === ul ) { | |
| 2269 | + return; | |
| 2270 | + } | |
| 2271 | + if ( null === ul.getAttribute( 'aria-label' ) ) { | |
| 2272 | + ul.setAttribute( 'aria-label', __( 'More Options', 'formidable' ) ); | |
| 2273 | + } | |
| 2274 | + if ( 0 === ul.children.length ) { | |
| 2275 | + fillFieldActionDropdown( ul, true === isFieldGroup ); | |
| 2276 | + } | |
| 2277 | + $ul = jQuery( ul ); | |
| 2278 | + if ( $ul.offset().left > jQuery( window ).width() - $ul.outerWidth() ) { | |
| 2279 | + ul.style.left = ( -$ul.outerWidth() ) + 'px'; | |
| 2280 | + } | |
| 2281 | + const firstAnchor = ul.firstElementChild.querySelector( 'a' ); | |
| 2282 | + if ( firstAnchor ) { | |
| 2283 | + firstAnchor.focus(); | |
| 2284 | + } | |
| 2285 | + }, | |
| 2286 | + 0 | |
| 2287 | + ); | |
| 2288 | + } | |
| 2289 | + | |
| 2290 | + function onFieldGroupActionDropdownShow() { | |
| 2291 | + onFieldActionDropdownShow( true ); | |
| 2292 | + } | |
| 2293 | + | |
| 2294 | + function fillFieldActionDropdown( ul, isFieldGroup ) { | |
| 2295 | + var classSuffix, options; | |
| 2296 | + classSuffix = isFieldGroup ? '_field_group' : '_field'; | |
| 2297 | + options = [ getDeleteActionOption( isFieldGroup ), getDuplicateActionOption( isFieldGroup ) ]; | |
| 2298 | + if ( ! isFieldGroup ) { | |
| 2299 | + options.push( | |
| 2300 | + { class: 'frm_select', icon: 'frm_settings_icon', label: __( 'Field Settings', 'formidable' ) } | |
| 2301 | + ); | |
| 2302 | + } | |
| 2303 | + options.forEach( | |
| 2304 | + function( option ) { | |
| 2305 | + var li, anchor, span; | |
| 2306 | + li = document.createElement( 'div' ); | |
| 2307 | + li.classList.add( 'frm_more_options_li', 'dropdown-item' ); | |
| 2308 | + | |
| 2309 | + anchor = document.createElement( 'a' ); | |
| 2310 | + anchor.classList.add( option.class + classSuffix ); | |
| 2311 | + anchor.setAttribute( 'href', '#' ); | |
| 2312 | + makeTabbable( anchor ); | |
| 2313 | + | |
| 2314 | + span = document.createElement( 'span' ); | |
| 2315 | + span.textContent = option.label; | |
| 2316 | + anchor.innerHTML = '<svg class="frmsvg"><use xlink:href="#' + option.icon + '"></use></svg>'; | |
| 2317 | + anchor.appendChild( document.createTextNode( ' ' ) ); | |
| 2318 | + anchor.appendChild( span ); | |
| 2319 | + | |
| 2320 | + li.appendChild( anchor ); | |
| 2321 | + ul.appendChild( li ); | |
| 2322 | + } | |
| 2323 | + ); | |
| 2324 | + } | |
| 2325 | + | |
| 2326 | + function getDeleteActionOption( isFieldGroup ) { | |
| 2327 | + var option = { class: 'frm_delete', icon: 'frm_delete_icon' }; | |
| 2328 | + option.label = isFieldGroup ? __( 'Delete Group', 'formidable' ) : __( 'Delete', 'formidable' ); | |
| 2329 | + return option; | |
| 2330 | + } | |
| 2331 | + | |
| 2332 | + function getDuplicateActionOption( isFieldGroup ) { | |
| 2333 | + var option = { class: 'frm_clone', icon: 'frm_clone_icon' }; | |
| 2334 | + option.label = isFieldGroup ? __( 'Duplicate Group', 'formidable' ) : __( 'Duplicate', 'formidable' ); | |
| 2335 | + return option; | |
| 2336 | + } | |
| 2337 | + | |
| 2338 | + function wrapFieldLi( field ) { | |
| 2339 | + const wrapper = div(); | |
| 2340 | + | |
| 2341 | + if ( 'string' === typeof field ) { | |
| 2342 | + wrapper.innerHTML = field; | |
| 2343 | + } else { | |
| 2344 | + wrapper.appendChild( field ); | |
| 2345 | + } | |
| 2346 | + | |
| 2347 | + let result = jQuery(); | |
| 2348 | + Array.from( wrapper.children ).forEach( | |
| 2349 | + li => { | |
| 2350 | + result = result.add( | |
| 2351 | + jQuery( '<li>' ) | |
| 2352 | + .addClass( 'frm_field_box' ) | |
| 2353 | + .html( | |
| 2354 | + jQuery( '<ul>' ).addClass( 'frm_grid_container frm_sorting' ).append( li ) | |
| 2355 | + ) | |
| 2356 | + ); | |
| 2357 | + } | |
| 2358 | + ); | |
| 2359 | + | |
| 2360 | + return result; | |
| 2361 | + } | |
| 2362 | + | |
| 2363 | + function wrapFieldLiInPlace( li ) { | |
| 2364 | + const ul = tag( | |
| 2365 | + 'ul', | |
| 2366 | + { | |
| 2367 | + className: 'frm_grid_container frm_sorting' | |
| 2368 | + } | |
| 2369 | + ); | |
| 2370 | + const wrapper = tag( | |
| 2371 | + 'li', | |
| 2372 | + { | |
| 2373 | + className: 'frm_field_box', | |
| 2374 | + child: ul | |
| 2375 | + } | |
| 2376 | + ); | |
| 2377 | + | |
| 2378 | + li.replaceWith( wrapper ); | |
| 2379 | + ul.appendChild( li ); | |
| 2380 | + | |
| 2381 | + makeDroppable( ul ); | |
| 2382 | + makeDraggable( wrapper, '.frm-move' ); | |
| 2383 | + } | |
| 2384 | + | |
| 2385 | + function afterAddField( msg, addFocus ) { | |
| 2386 | + var regex = /id="(\S+)"/, | |
| 2387 | + match = regex.exec( msg ), | |
| 2388 | + field = document.getElementById( match[1]), | |
| 2389 | + section = '#' + match[1] + '.edit_field_type_divider ul.frm_sorting.start_divider', | |
| 2390 | + $thisSection = jQuery( section ), | |
| 2391 | + type = field.getAttribute( 'data-type' ), | |
| 2392 | + toggled = false, | |
| 2393 | + $parentSection; | |
| 2394 | + | |
| 2395 | + setupSortable( section ); | |
| 2396 | + | |
| 2397 | + if ( 'quantity' === type ) { | |
| 2398 | + // try to automatically attach a product field | |
| 2399 | + maybeSetProductField( field ); | |
| 2400 | + } | |
| 2401 | + | |
| 2402 | + if ( 'product' === type || 'quantity' === type ) { | |
| 2403 | + // quantity too needs to be a part of the if stmt especially cos of the very | |
| 2404 | + // 1st quantity field (or even if it's just one quantity field in the form). | |
| 2405 | + maybeHideQuantityProductFieldOption(); | |
| 2406 | + } | |
| 2407 | + | |
| 2408 | + if ( $thisSection.length ) { | |
| 2409 | + $thisSection.parent( '.frm_field_box' ).children( '.frm_no_section_fields' ).addClass( 'frm_block' ); | |
| 2410 | + } else { | |
| 2411 | + $parentSection = jQuery( field ).closest( 'ul.frm_sorting.start_divider' ); | |
| 2412 | + if ( $parentSection.length ) { | |
| 2413 | + toggleOneSectionHolder( $parentSection ); | |
| 2414 | + toggled = true; | |
| 2415 | + } | |
| 2416 | + } | |
| 2417 | + | |
| 2418 | + if ( msg.indexOf( 'frm-collapse-page' ) !== -1 ) { | |
| 2419 | + renumberPageBreaks(); | |
| 2420 | + } | |
| 2421 | + | |
| 2422 | + addClass( field, 'frm-newly-added' ); | |
| 2423 | + setTimeout( function() { | |
| 2424 | + field.classList.remove( 'frm-newly-added' ); | |
| 2425 | + }, 1000 ); | |
| 2426 | + | |
| 2427 | + if ( addFocus ) { | |
| 2428 | + var bounding = field.getBoundingClientRect(), | |
| 2429 | + container = document.getElementById( 'post-body-content' ), | |
| 2430 | + inView = ( bounding.top >= 0 && | |
| 2431 | + bounding.left >= 0 && | |
| 2432 | + bounding.right <= ( window.innerWidth || document.documentElement.clientWidth ) && | |
| 2433 | + bounding.bottom <= ( window.innerHeight || document.documentElement.clientHeight ) | |
| 2434 | + ); | |
| 2435 | + | |
| 2436 | + if ( ! inView ) { | |
| 2437 | + container.scroll({ | |
| 2438 | + top: container.scrollHeight, | |
| 2439 | + left: 0, | |
| 2440 | + behavior: 'smooth' | |
| 2441 | + }); | |
| 2442 | + } | |
| 2443 | + | |
| 2444 | + if ( toggled === false ) { | |
| 2445 | + toggleOneSectionHolder( $thisSection ); | |
| 2446 | + } | |
| 2447 | + } | |
| 2448 | + | |
| 2449 | + deselectFields(); | |
| 2450 | + initiateMultiselect(); | |
| 2451 | + | |
| 2452 | + const addedEvent = new Event( 'frm_added_field', { bubbles: false }); | |
| 2453 | + addedEvent.frmField = field; | |
| 2454 | + addedEvent.frmSection = section; | |
| 2455 | + addedEvent.frmType = type; | |
| 2456 | + addedEvent.frmToggles = toggled; | |
| 2457 | + document.dispatchEvent( addedEvent ); | |
| 2458 | + } | |
| 2459 | + | |
| 2460 | + function clearSettingsBox( preventFieldGroups ) { | |
| 2461 | + jQuery( '#new_fields .frm-single-settings' ).addClass( 'frm_hidden' ); | |
| 2462 | + jQuery( '#frm-options-panel > .frm-single-settings' ).removeClass( 'frm_hidden' ); | |
| 2463 | + deselectFields( preventFieldGroups ); | |
| 2464 | + } | |
| 2465 | + | |
| 2466 | + function deselectFields( preventFieldGroups ) { | |
| 2467 | + jQuery( 'li.ui-state-default.selected' ).removeClass( 'selected' ); | |
| 2468 | + if ( ! preventFieldGroups ) { | |
| 2469 | + unselectFieldGroups(); | |
| 2470 | + } | |
| 2471 | + } | |
| 2472 | + | |
| 2473 | + function scrollToField( field ) { | |
| 2474 | + var newPos = field.getBoundingClientRect().top, | |
| 2475 | + container = document.getElementById( 'post-body-content' ); | |
| 2476 | + | |
| 2477 | + if ( typeof animate === 'undefined' ) { | |
| 2478 | + jQuery( container ).scrollTop( newPos ); | |
| 2479 | + } else { | |
| 2480 | + // TODO: smooth scroll | |
| 2481 | + jQuery( container ).animate({ scrollTop: newPos }, 500 ); | |
| 2482 | + } | |
| 2483 | + } | |
| 2484 | + | |
| 2485 | + function checkCalculationCreatedByUser() { | |
| 2486 | + var calculation = this.value; | |
| 2487 | + var warningMessage = checkMatchingParens( calculation ); | |
| 2488 | + warningMessage += checkShortcodes( calculation, this ); | |
| 2489 | + | |
| 2490 | + if ( warningMessage !== '' ) { | |
| 2491 | + infoModal( calculation + '\n\n' + warningMessage ); | |
| 2492 | + } | |
| 2493 | + } | |
| 2494 | + | |
| 2495 | + /** | |
| 2496 | + * Checks the Detail Page slug to see if it's a reserved word and displays a message if it is. | |
| 2497 | + */ | |
| 2498 | + function checkDetailPageSlug() { | |
| 2499 | + var slug = jQuery( '#param' ).val(), | |
| 2500 | + msg; | |
| 2501 | + slug = slug.trim().toLowerCase(); | |
| 2502 | + if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( slug ) ) { | |
| 2503 | + msg = frm_admin_js.slug_is_reserved; | |
| 2504 | + msg = msg.replace( '****', addHtmlTags( slug, 'strong' ) ); | |
| 2505 | + msg += '<br /><br />'; | |
| 2506 | + msg += addHtmlTags( '<a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>', 'div' ); | |
| 2507 | + infoModal( msg ); | |
| 2508 | + } | |
| 2509 | + } | |
| 2510 | + | |
| 2511 | + /** | |
| 2512 | + * Checks View filter value for params named with reserved words and displays a message if any are found. | |
| 2513 | + */ | |
| 2514 | + function checkFilterParamNames() { | |
| 2515 | + var regEx = /\[\s*get\s*param\s*=\s*['"]?([a-zA-Z-_]+)['"]?/ig, | |
| 2516 | + filterValue = jQuery( this ).val(), | |
| 2517 | + match = regEx.exec( filterValue ), | |
| 2518 | + unsafeParams = ''; | |
| 2519 | + | |
| 2520 | + while ( match !== null ) { | |
| 2521 | + if ( Array.isArray( frm_admin_js.unsafe_params ) && frm_admin_js.unsafe_params.includes( match[1]) ) { | |
| 2522 | + if ( unsafeParams !== '' ) { | |
| 2523 | + unsafeParams += '", "' + match[ 1 ]; | |
| 2524 | + } else { | |
| 2525 | + unsafeParams = match[ 1 ]; | |
| 2526 | + } | |
| 2527 | + } | |
| 2528 | + match = regEx.exec( filterValue ); | |
| 2529 | + } | |
| 2530 | + | |
| 2531 | + if ( unsafeParams !== '' ) { | |
| 2532 | + msg = frm_admin_js.param_is_reserved; | |
| 2533 | + msg = msg.replace( '****', addHtmlTags( unsafeParams, 'strong' ) ); | |
| 2534 | + msg += '<br /><br />'; | |
| 2535 | + msg += ' <a href="https://codex.wordpress.org/WordPress_Query_Vars" target="_blank" class="frm-standard-link">' + frm_admin_js.reserved_words + '</a>'; | |
| 2536 | + | |
| 2537 | + infoModal( msg ); | |
| 2538 | + } | |
| 2539 | + } | |
| 2540 | + | |
| 2541 | + function addHtmlTags( text, tag ) { | |
| 2542 | + tag = tag ? tag : 'p'; | |
| 2543 | + return '<' + tag + '>' + text + '</' + tag + '>'; | |
| 2544 | + } | |
| 2545 | + | |
| 2546 | + /** | |
| 2547 | + * Checks a string for parens, brackets, and curly braces and returns a message if any unmatched are found. | |
| 2548 | + * @param formula | |
| 2549 | + * @returns {string} | |
| 2550 | + */ | |
| 2551 | + function checkMatchingParens( formula ) { | |
| 2552 | + | |
| 2553 | + var stack = [], | |
| 2554 | + formulaArray = formula.split( '' ), | |
| 2555 | + length = formulaArray.length, | |
| 2556 | + opening = [ '{', '[', '(' ], | |
| 2557 | + closing = { | |
| 2558 | + '}': '{', | |
| 2559 | + ')': '(', | |
| 2560 | + ']': '[' | |
| 2561 | + }, | |
| 2562 | + unmatchedClosing = [], | |
| 2563 | + msg = '', | |
| 2564 | + i, top; | |
| 2565 | + | |
| 2566 | + for ( i = 0; i < length; i++ ) { | |
| 2567 | + if ( opening.includes( formulaArray[i]) ) { | |
| 2568 | + stack.push( formulaArray[i]); | |
| 2569 | + continue; | |
| 2570 | + } | |
| 2571 | + if ( closing.hasOwnProperty( formulaArray[i]) ) { | |
| 2572 | + top = stack.pop(); | |
| 2573 | + if ( top !== closing[formulaArray[i]]) { | |
| 2574 | + unmatchedClosing.push( formulaArray[i]); | |
| 2575 | + } | |
| 2576 | + } | |
| 2577 | + } | |
| 2578 | + | |
| 2579 | + if ( stack.length > 0 || unmatchedClosing.length > 0 ) { | |
| 2580 | + msg = frm_admin_js.unmatched_parens + '\n\n'; | |
| 2581 | + return msg; | |
| 2582 | + } | |
| 2583 | + | |
| 2584 | + return ''; | |
| 2585 | + } | |
| 2586 | + | |
| 2587 | + /** | |
| 2588 | + * Checks a calculation for shortcodes that shouldn't be in it and returns a message if found. | |
| 2589 | + * @param calculation | |
| 2590 | + * @param inputElement | |
| 2591 | + * @returns {string} | |
| 2592 | + */ | |
| 2593 | + function checkShortcodes( calculation, inputElement ) { | |
| 2594 | + var msg = checkNonNumericShortcodes( calculation, inputElement ); | |
| 2595 | + msg += checkNonFormShortcodes( calculation ); | |
| 2596 | + | |
| 2597 | + return msg; | |
| 2598 | + } | |
| 2599 | + | |
| 2600 | + /** | |
| 2601 | + * Checks if a numeric calculation has shortcodes that output non-numeric strings and returns a message if found. | |
| 2602 | + * @param calculation | |
| 2603 | + * | |
| 2604 | + * @param inputElement | |
| 2605 | + * @returns {string} | |
| 2606 | + */ | |
| 2607 | + function checkNonNumericShortcodes( calculation, inputElement ) { | |
| 2608 | + | |
| 2609 | + var msg = ''; | |
| 2610 | + | |
| 2611 | + if ( isTextCalculation( inputElement ) ) { | |
| 2612 | + return msg; | |
| 2613 | + } | |
| 2614 | + | |
| 2615 | + var nonNumericShortcodes = getNonNumericShortcodes(); | |
| 2616 | + | |
| 2617 | + if ( nonNumericShortcodes.test( calculation ) ) { | |
| 2618 | + msg = frm_admin_js.text_shortcodes + '\n\n'; | |
| 2619 | + } | |
| 2620 | + | |
| 2621 | + return msg; | |
| 2622 | + } | |
| 2623 | + | |
| 2624 | + /** | |
| 2625 | + * Determines if the calculation input is from a text calculation. | |
| 2626 | + * | |
| 2627 | + * @param inputElement | |
| 2628 | + */ | |
| 2629 | + function isTextCalculation( inputElement ) { | |
| 2630 | + return jQuery( inputElement ).siblings( 'label[for^="calc_type"]' ).children( 'input' ).prop( 'checked' ); | |
| 2631 | + } | |
| 2632 | + | |
| 2633 | + /** | |
| 2634 | + * Returns a regular expression of shortcodes that can't be used in numeric calculations. | |
| 2635 | + * @returns {RegExp} | |
| 2636 | + */ | |
| 2637 | + function getNonNumericShortcodes() { | |
| 2638 | + return /\[(date|time|email|ip)\]/; | |
| 2639 | + } | |
| 2640 | + | |
| 2641 | + /** | |
| 2642 | + * Checks if a string has any shortcodes that do not belong in forms and returns a message if any are found. | |
| 2643 | + * @param formula | |
| 2644 | + * @returns {string} | |
| 2645 | + */ | |
| 2646 | + function checkNonFormShortcodes( formula ) { | |
| 2647 | + var nonFormShortcodes = getNonFormShortcodes(), | |
| 2648 | + msg = ''; | |
| 2649 | + | |
| 2650 | + if ( nonFormShortcodes.test( formula ) ) { | |
| 2651 | + msg += frm_admin_js.view_shortcodes + '\n\n'; | |
| 2652 | + } | |
| 2653 | + | |
| 2654 | + return msg; | |
| 2655 | + } | |
| 2656 | + | |
| 2657 | + /** | |
| 2658 | + * Returns a regular expression of shortcodes that can't be used in forms but can be used in Views, Email | |
| 2659 | + * Notifications, and other Formidable areas. | |
| 2660 | + * | |
| 2661 | + * @returns {RegExp} | |
| 2662 | + */ | |
| 2663 | + function getNonFormShortcodes() { | |
| 2664 | + return /\[id\]|\[key\]|\[if\s\w+\]|\[foreach\s\w+\]|\[created-at(\s*)?/g; | |
| 2665 | + } | |
| 2666 | + | |
| 2667 | + function isCalcBoxType( box, listClass ) { | |
| 2668 | + var list = jQuery( box ).find( '.frm_code_list' ); | |
| 2669 | + return 1 === list.length && list.hasClass( listClass ); | |
| 2670 | + } | |
| 2671 | + | |
| 2672 | + function extractExcludedOptions( exclude ) { | |
| 2673 | + var opts = []; | |
| 2674 | + if ( ! Array.isArray( exclude ) ) { | |
| 2675 | + return opts; | |
| 2676 | + } | |
| 2677 | + | |
| 2678 | + for ( var i = 0; i < exclude.length; i++ ) { | |
| 2679 | + if ( exclude[ i ].startsWith( '[' ) ) { | |
| 2680 | + opts.push( exclude[ i ]); | |
| 2681 | + // remove it | |
| 2682 | + exclude.splice( i, 1 ); | |
| 2683 | + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value | |
| 2684 | + i--; | |
| 2685 | + } | |
| 2686 | + } | |
| 2687 | + | |
| 2688 | + return opts; | |
| 2689 | + } | |
| 2690 | + | |
| 2691 | + function hasExcludedOption( field, excludedOpts ) { | |
| 2692 | + var hasOption = false; | |
| 2693 | + for ( var i = 0; i < excludedOpts.length; i++ ) { | |
| 2694 | + var inputs = document.getElementsByName( getFieldOptionInputName( excludedOpts[ i ], field.fieldId ) ); | |
| 2695 | + // 2nd condition checks that there's at least one non-empty value | |
| 2696 | + if ( inputs.length && jQuery( inputs[0]).val() ) { | |
| 2697 | + hasOption = true; | |
| 2698 | + break; | |
| 2699 | + } | |
| 2700 | + } | |
| 2701 | + return hasOption; | |
| 2702 | + } | |
| 2703 | + | |
| 2704 | + function getFieldOptionInputName( opt, fieldId ) { | |
| 2705 | + var at = opt.indexOf( ']' ); | |
| 2706 | + return 'field_options' + opt.substring( 0, at ) + '_' + fieldId + opt.substring( at ); | |
| 2707 | + } | |
| 2708 | + | |
| 2709 | + function popCalcFields( v, force ) { | |
| 2710 | + var box, exclude, fields, i, list, | |
| 2711 | + p = jQuery( v ).closest( '.frm-single-settings' ), | |
| 2712 | + calc = p.find( '.frm-calc-field' ); | |
| 2713 | + | |
| 2714 | + if ( ! force && ( ! calc.length || calc.val() === '' || calc.is( ':hidden' ) ) ) { | |
| 2715 | + return; | |
| 2716 | + } | |
| 2717 | + | |
| 2718 | + var isSummary = isCalcBoxType( v, 'frm_js_summary_list' ); | |
| 2719 | + | |
| 2720 | + var fieldId = p.find( 'input[name="frm_fields_submitted[]"]' ).val(); | |
| 2721 | + | |
| 2722 | + if ( force ) { | |
| 2723 | + box = v; | |
| 2724 | + } else { | |
| 2725 | + box = document.getElementById( 'frm-calc-box-' + fieldId ); | |
| 2726 | + } | |
| 2727 | + | |
| 2728 | + exclude = getExcludeArray( box, isSummary ); | |
| 2729 | + var excludedOpts = extractExcludedOptions( exclude ); | |
| 2730 | + | |
| 2731 | + fields = getFieldList(); | |
| 2732 | + list = document.getElementById( 'frm-calc-list-' + fieldId ); | |
| 2733 | + list.innerHTML = ''; | |
| 2734 | + | |
| 2735 | + for ( i = 0; i < fields.length; i++ ) { | |
| 2736 | + if ( ( exclude && exclude.includes( fields[ i ].fieldType ) ) || | |
| 2737 | + ( excludedOpts.length && hasExcludedOption( fields[ i ], excludedOpts ) ) ) { | |
| 2738 | + continue; | |
| 2739 | + } | |
| 2740 | + | |
| 2741 | + var span = document.createElement( 'span' ); | |
| 2742 | + span.appendChild( document.createTextNode( '[' + fields[i].fieldId + ']' ) ); | |
| 2743 | + | |
| 2744 | + var a = document.createElement( 'a' ); | |
| 2745 | + a.setAttribute( 'href', '#' ); | |
| 2746 | + a.setAttribute( 'data-code', fields[i].fieldId ); | |
| 2747 | + a.classList.add( 'frm_insert_code' ); | |
| 2748 | + a.appendChild( span ); | |
| 2749 | + a.appendChild( document.createTextNode( fields[i].fieldName ) ); | |
| 2750 | + | |
| 2751 | + var li = document.createElement( 'li' ); | |
| 2752 | + li.classList.add( 'frm-field-list-' + fieldId ); | |
| 2753 | + li.classList.add( 'frm-field-list-' + fields[i].fieldType ); | |
| 2754 | + li.appendChild( a ); | |
| 2755 | + list.appendChild( li ); | |
| 2756 | + } | |
| 2757 | + } | |
| 2758 | + | |
| 2759 | + function getExcludeArray( calcBox, isSummary ) { | |
| 2760 | + var exclude = JSON.parse( calcBox.getElementsByClassName( 'frm_code_list' )[0].getAttribute( 'data-exclude' ) ); | |
| 2761 | + | |
| 2762 | + if ( isSummary ) { | |
| 2763 | + // includedExtras are those that are normally excluded from the summary but the form owner can choose to include, | |
| 2764 | + // when they have been chosen to be included, then they can now be manually excluded in the calc box. | |
| 2765 | + var includedExtras = getIncludedExtras(); | |
| 2766 | + if ( includedExtras.length ) { | |
| 2767 | + for ( var i = 0; i < exclude.length; i++ ) { | |
| 2768 | + if ( includedExtras.includes( exclude[ i ]) ) { | |
| 2769 | + // remove it | |
| 2770 | + exclude.splice( i, 1 ); | |
| 2771 | + // https://love2dev.com/blog/javascript-remove-from-array/#remove-from-array-splice-value | |
| 2772 | + i--; | |
| 2773 | + } | |
| 2774 | + } | |
| 2775 | + } | |
| 2776 | + } | |
| 2777 | + | |
| 2778 | + return exclude; | |
| 2779 | + } | |
| 2780 | + | |
| 2781 | + function getIncludedExtras() { | |
| 2782 | + var checked = []; | |
| 2783 | + var checkboxes = document.getElementsByClassName( 'frm_include_extras_field' ); | |
| 2784 | + | |
| 2785 | + for ( var i = 0; i < checkboxes.length; i++ ) { | |
| 2786 | + if ( checkboxes[i].checked ) { | |
| 2787 | + checked.push( checkboxes[i].value ); | |
| 2788 | + } | |
| 2789 | + } | |
| 2790 | + | |
| 2791 | + return checked; | |
| 2792 | + } | |
| 2793 | + | |
| 2794 | + function rePopCalcFieldsForSummary() { | |
| 2795 | + popCalcFields( jQuery( '.frm-inline-modal.postbox:has(.frm_js_summary_list)' )[0], true ); | |
| 2796 | + } | |
| 2797 | + | |
| 2798 | + function getFieldList( fieldType ) { | |
| 2799 | + var i, | |
| 2800 | + fields = [], | |
| 2801 | + allFields = document.querySelectorAll( 'li.frm_field_box' ), | |
| 2802 | + checkType = 'undefined' !== typeof fieldType; | |
| 2803 | + | |
| 2804 | + for ( i = 0; i < allFields.length; i++ ) { | |
| 2805 | + // data-ftype is better (than data-type) cos of fields loaded by AJAX - which might not be ready yet | |
| 2806 | + if ( checkType && allFields[ i ].getAttribute( 'data-ftype' ) !== fieldType ) { | |
| 2807 | + continue; | |
| 2808 | + } | |
| 2809 | + | |
| 2810 | + var fieldId = allFields[ i ].getAttribute( 'data-fid' ); | |
| 2811 | + if ( typeof fieldId !== 'undefined' && fieldId ) { | |
| 2812 | + fields.push({ | |
| 2813 | + 'fieldId': fieldId, | |
| 2814 | + 'fieldName': getPossibleValue( 'frm_name_' + fieldId ), | |
| 2815 | + 'fieldType': getPossibleValue( 'field_options_type_' + fieldId ), | |
| 2816 | + 'fieldKey': getPossibleValue( 'field_options_field_key_' + fieldId ) | |
| 2817 | + }); | |
| 2818 | + } | |
| 2819 | + } | |
| 2820 | + | |
| 2821 | + return fields; | |
| 2822 | + } | |
| 2823 | + | |
| 2824 | + function popProductFields( field ) { | |
| 2825 | + var i, checked, id, | |
| 2826 | + options = [], | |
| 2827 | + current = getCurrentProductFields( field ), | |
| 2828 | + fName = field.getAttribute( 'data-frmfname' ), | |
| 2829 | + products = getFieldList( 'product' ), | |
| 2830 | + quantities = getFieldList( 'quantity' ), | |
| 2831 | + isSelect = field.tagName === 'SELECT', // for reverse compatibility. | |
| 2832 | + // whether we have just 1 product and 1 quantity field & should therefore attach the latter to the former | |
| 2833 | + auto = 1 === quantities.length && 1 === products.length; | |
| 2834 | + | |
| 2835 | + if ( isSelect ) { | |
| 2836 | + // This fallback can be removed after 4.05. | |
| 2837 | + current = field.getAttribute( 'data-frmcurrent' ); | |
| 2838 | + } | |
| 2839 | + | |
| 2840 | + for ( i = 0 ; i < products.length ; i++ ) { | |
| 2841 | + // let's be double sure it's string, else indexOf will fail | |
| 2842 | + id = products[ i ].fieldId.toString(); | |
| 2843 | + checked = auto || -1 !== current.indexOf( id ); | |
| 2844 | + if ( isSelect ) { | |
| 2845 | + // This fallback can be removed after 4.05. | |
| 2846 | + checked = checked ? ' selected' : ''; | |
| 2847 | + options.push( '<option value="' + id + '"' + checked + '>' + products[ i ].fieldName + '</option>' ); | |
| 2848 | + } else { | |
| 2849 | + checked = checked ? ' checked' : ''; | |
| 2850 | + options.push( '<label class="frm6">' ); | |
| 2851 | + options.push( '<input type="checkbox" name="' + fName + '" value="' + id + '"' + checked + '> ' + products[ i ].fieldName ); | |
| 2852 | + options.push( '</label>' ); | |
| 2853 | + } | |
| 2854 | + } | |
| 2855 | + | |
| 2856 | + field.innerHTML = options.join( '' ); | |
| 2857 | + } | |
| 2858 | + | |
| 2859 | + function getCurrentProductFields( prodFieldOpt ) { | |
| 2860 | + var products = prodFieldOpt.querySelectorAll( '[type="checkbox"]:checked' ), | |
| 2861 | + idsArray = []; | |
| 2862 | + | |
| 2863 | + for ( var i = 0; i < products.length; i++ ) { | |
| 2864 | + idsArray.push( products[ i ].value ); | |
| 2865 | + } | |
| 2866 | + | |
| 2867 | + return idsArray; | |
| 2868 | + } | |
| 2869 | + | |
| 2870 | + function popAllProductFields() { | |
| 2871 | + var opts = document.querySelectorAll( '.frmjs_prod_field_opt' ); | |
| 2872 | + for ( var i = 0; i < opts.length; i++ ) { | |
| 2873 | + popProductFields( opts[ i ]); | |
| 2874 | + } | |
| 2875 | + } | |
| 2876 | + | |
| 2877 | + function maybeSetProductField( field ) { | |
| 2878 | + var fieldId = field.getAttribute( 'data-fid' ), | |
| 2879 | + productFieldOpt = document.getElementById( 'field_options[product_field_' + fieldId + ']' ); | |
| 2880 | + | |
| 2881 | + if ( null === productFieldOpt ) { | |
| 2882 | + return; | |
| 2883 | + } | |
| 2884 | + | |
| 2885 | + popProductFields( productFieldOpt ); | |
| 2886 | + // in order to move its settings to that LHS panel where | |
| 2887 | + // the update form resides, else it'll lose this setting | |
| 2888 | + moveFieldSettings( document.getElementById( 'frm-single-settings-' + fieldId ) ); | |
| 2889 | + } | |
| 2890 | + | |
| 2891 | + /** | |
| 2892 | + * If the element doesn't exist, use a blank value. | |
| 2893 | + */ | |
| 2894 | + function getPossibleValue( id ) { | |
| 2895 | + field = document.getElementById( id ); | |
| 2896 | + if ( field !== null ) { | |
| 2897 | + return field.value; | |
| 2898 | + } else { | |
| 2899 | + return ''; | |
| 2900 | + } | |
| 2901 | + } | |
| 2902 | + | |
| 2903 | + function liveChanges() { | |
| 2904 | + /*jshint validthis:true */ | |
| 2905 | + var option, | |
| 2906 | + newValue = this.value, | |
| 2907 | + changes = document.getElementById( this.getAttribute( 'data-changeme' ) ), | |
| 2908 | + att = this.getAttribute( 'data-changeatt' ); | |
| 2909 | + | |
| 2910 | + if ( changes === null ) { | |
| 2911 | + return; | |
| 2912 | + } | |
| 2913 | + | |
| 2914 | + if ( att !== null ) { | |
| 2915 | + if ( changes.tagName === 'SELECT' && att === 'placeholder' ) { | |
| 2916 | + option = changes.options[0]; | |
| 2917 | + if ( option.value === '' ) { | |
| 2918 | + option.innerHTML = newValue; | |
| 2919 | + } else { | |
| 2920 | + // Create a placeholder option if there are no blank values. | |
| 2921 | + addBlankSelectOption( changes, newValue ); | |
| 2922 | + } | |
| 2923 | + } else if ( att === 'class' ) { | |
| 2924 | + changeFieldClass( changes, this ); | |
| 2925 | + } else if ( isSliderField( changes ) ) { | |
| 2926 | + updateSliderFieldPreview( changes, att, newValue ); | |
| 2927 | + } else { | |
| 2928 | + changes.setAttribute( att, newValue ); | |
| 2929 | + } | |
| 2930 | + } else if ( changes.id.indexOf( 'setup-message' ) === 0 ) { | |
| 2931 | + if ( newValue !== '' ) { | |
| 2932 | + changes.innerHTML = '<input type="text" value="" disabled />'; | |
| 2933 | + } | |
| 2934 | + } else { | |
| 2935 | + changes.innerHTML = newValue; | |
| 2936 | + if ( changes.classList.contains( 'frm_primary_label' ) && 'break' === changes.nextElementSibling.getAttribute( 'data-ftype' ) ) { | |
| 2937 | + changes.nextElementSibling.querySelector( '.frm_button_submit' ).textContent = newValue; | |
| 2938 | + } | |
| 2939 | + } | |
| 2940 | + } | |
| 2941 | + | |
| 2942 | + function updateSliderFieldPreview( field, att, newValue ) { | |
| 2943 | + if ( frmGlobal.proIncludesSliderJs ) { | |
| 2944 | + const hookName = 'frm_update_slider_field_preview'; | |
| 2945 | + const hookArgs = { field, att, newValue }; | |
| 2946 | + wp.hooks.doAction( hookName, hookArgs ); | |
| 2947 | + return; | |
| 2948 | + } | |
| 2949 | + | |
| 2950 | + // This functionality has been moved to pro since v5.4.3. This code should be removed eventually. | |
| 2951 | + if ( 'value' === att ) { | |
| 2952 | + if ( '' === newValue ) { | |
| 2953 | + newValue = getSliderMidpoint( field ); | |
| 2954 | + } | |
| 2955 | + field.value = newValue; | |
| 2956 | + } else { | |
| 2957 | + field.setAttribute( att, newValue ); | |
| 2958 | + } | |
| 2959 | + | |
| 2960 | + if ( -1 === [ 'value', 'min', 'max' ].indexOf( att ) ) { | |
| 2961 | + return; | |
| 2962 | + } | |
| 2963 | + | |
| 2964 | + if ( ( 'max' === att || 'min' === att ) && '' === getSliderDefaultValueInput( field.id ) ) { | |
| 2965 | + field.value = getSliderMidpoint( field ); | |
| 2966 | + } | |
| 2967 | + | |
| 2968 | + field.parentNode.querySelector( '.frm_range_value' ).textContent = field.value; | |
| 2969 | + } | |
| 2970 | + | |
| 2971 | + function getSliderDefaultValueInput( previewInputId ) { | |
| 2972 | + return document.querySelector( 'input[data-changeme="' + previewInputId + '"][data-changeatt="value"]' ).value; | |
| 2973 | + } | |
| 2974 | + | |
| 2975 | + function getSliderMidpoint( sliderInput ) { | |
| 2976 | + const max = parseFloat( sliderInput.getAttribute( 'max' ) ); | |
| 2977 | + const min = parseFloat( sliderInput.getAttribute( 'min' ) ); | |
| 2978 | + return ( max - min ) / 2 + min; | |
| 2979 | + } | |
| 2980 | + | |
| 2981 | + function isSliderField( previewInput ) { | |
| 2982 | + return 'range' === previewInput.type && previewInput.parentNode.classList.contains( 'frm_range_container' ); | |
| 2983 | + } | |
| 2984 | + | |
| 2985 | + function toggleInvalidMsg() { | |
| 2986 | + /*jshint validthis:true */ | |
| 2987 | + var typeDropdown, fieldType, | |
| 2988 | + fieldId = this.getAttribute( 'data-fid' ), | |
| 2989 | + value = ''; | |
| 2990 | + | |
| 2991 | + [ 'field_options_max_', 'frm_format_' ].forEach( function( id ) { | |
| 2992 | + var input = document.getElementById( id + fieldId ); | |
| 2993 | + if ( ! input ) { | |
| 2994 | + return; | |
| 2995 | + } | |
| 2996 | + | |
| 2997 | + value += input.value; | |
| 2998 | + }); | |
| 2999 | + | |
| 3000 | + typeDropdown = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0]; | |
| 3001 | + fieldType = typeDropdown.options[typeDropdown.selectedIndex].value; | |
| 3002 | + | |
| 3003 | + if ( fieldType === 'text' ) { | |
| 3004 | + toggleValidationBox( '' !== value, '.frm_invalid_msg' + fieldId ); | |
| 3005 | + } | |
| 3006 | + } | |
| 3007 | + | |
| 3008 | + function markRequired() { | |
| 3009 | + /*jshint validthis:true */ | |
| 3010 | + var thisid = this.id.replace( 'frm_', '' ), | |
| 3011 | + fieldId = thisid.replace( 'req_field_', '' ), | |
| 3012 | + checked = this.checked, | |
| 3013 | + label = jQuery( '#field_label_' + fieldId + ' .frm_required' ); | |
| 3014 | + | |
| 3015 | + toggleValidationBox( checked, '.frm_required_details' + fieldId ); | |
| 3016 | + | |
| 3017 | + if ( checked ) { | |
| 3018 | + var $reqBox = jQuery( 'input[name="field_options[required_indicator_' + fieldId + ']"]' ); | |
| 3019 | + if ( $reqBox.val() === '' ) { | |
| 3020 | + $reqBox.val( '*' ); | |
| 3021 | + } | |
| 3022 | + label.removeClass( 'frm_hidden' ); | |
| 3023 | + } else { | |
| 3024 | + label.addClass( 'frm_hidden' ); | |
| 3025 | + } | |
| 3026 | + } | |
| 3027 | + | |
| 3028 | + function toggleValidationBox( hasValue, messageClass ) { | |
| 3029 | + $msg = jQuery( messageClass ); | |
| 3030 | + if ( hasValue ) { | |
| 3031 | + $msg.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' ); | |
| 3032 | + } else { | |
| 3033 | + //Fade out validation options | |
| 3034 | + var v = $msg.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(' + messageClass + '):visible' ).length; | |
| 3035 | + if ( v === 0 ) { | |
| 3036 | + $msg.closest( '.frm_validation_msg' ).fadeOut( 'fast' ); | |
| 3037 | + } | |
| 3038 | + } | |
| 3039 | + } | |
| 3040 | + | |
| 3041 | + function markUnique() { | |
| 3042 | + /*jshint validthis:true */ | |
| 3043 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3044 | + var $thisField = jQuery( '.frm_unique_details' + fieldId ); | |
| 3045 | + if ( this.checked ) { | |
| 3046 | + $thisField.fadeIn( 'fast' ).closest( '.frm_validation_msg' ).fadeIn( 'fast' ); | |
| 3047 | + $unqDetail = jQuery( '.frm_unique_details' + fieldId + ' input' ); | |
| 3048 | + if ( $unqDetail.val() === '' ) { | |
| 3049 | + $unqDetail.val( frm_admin_js.default_unique ); | |
| 3050 | + } | |
| 3051 | + } else { | |
| 3052 | + var v = $thisField.fadeOut( 'fast' ).closest( '.frm_validation_box' ).children( ':not(.frm_unique_details' + fieldId + '):visible' ).length; | |
| 3053 | + if ( v === 0 ) { | |
| 3054 | + $thisField.closest( '.frm_validation_msg' ).fadeOut( 'fast' ); | |
| 3055 | + } | |
| 3056 | + } | |
| 3057 | + } | |
| 3058 | + | |
| 3059 | + //Fade confirmation field and validation option in or out | |
| 3060 | + function addConf() { | |
| 3061 | + /*jshint validthis:true */ | |
| 3062 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3063 | + var val = jQuery( this ).val(); | |
| 3064 | + var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ); | |
| 3065 | + | |
| 3066 | + toggleValidationBox( val !== '', '.frm_conf_details' + fieldId ); | |
| 3067 | + | |
| 3068 | + if ( val !== '' ) { | |
| 3069 | + //Add default validation message if empty | |
| 3070 | + var valMsg = jQuery( '.frm_validation_box .frm_conf_details' + fieldId + ' input' ); | |
| 3071 | + if ( valMsg.val() === '' ) { | |
| 3072 | + valMsg.val( frm_admin_js.default_conf ); | |
| 3073 | + } | |
| 3074 | + | |
| 3075 | + setConfirmationFieldDescriptions( fieldId ); | |
| 3076 | + | |
| 3077 | + //Add or remove class for confirmation field styling | |
| 3078 | + if ( val === 'inline' ) { | |
| 3079 | + $thisField.removeClass( 'frm_conf_below' ).addClass( 'frm_conf_inline' ); | |
| 3080 | + } else if ( val === 'below' ) { | |
| 3081 | + $thisField.removeClass( 'frm_conf_inline' ).addClass( 'frm_conf_below' ); | |
| 3082 | + } | |
| 3083 | + jQuery( '.frm-conf-box-' + fieldId ).removeClass( 'frm_hidden' ); | |
| 3084 | + } else { | |
| 3085 | + jQuery( '.frm-conf-box-' + fieldId ).addClass( 'frm_hidden' ); | |
| 3086 | + setTimeout( function() { | |
| 3087 | + $thisField.removeClass( 'frm_conf_inline frm_conf_below' ); | |
| 3088 | + }, 200 ); | |
| 3089 | + } | |
| 3090 | + } | |
| 3091 | + | |
| 3092 | + function setConfirmationFieldDescriptions( fieldId ) { | |
| 3093 | + var fieldType = document.getElementsByName( 'field_options[type_' + fieldId + ']' )[0].value; | |
| 3094 | + | |
| 3095 | + var fieldDescription = document.getElementById( 'field_description_' + fieldId ); | |
| 3096 | + var hiddenDescName = 'field_options[description_' + fieldId + ']'; | |
| 3097 | + var newValue = frm_admin_js['enter_' + fieldType]; | |
| 3098 | + maybeSetNewDescription( fieldDescription, hiddenDescName, newValue ); | |
| 3099 | + | |
| 3100 | + var confFieldDescription = document.getElementById( 'conf_field_description_' + fieldId ); | |
| 3101 | + var hiddenConfName = 'field_options[conf_desc_' + fieldId + ']'; | |
| 3102 | + var newConfValue = frm_admin_js['confirm_' + fieldType]; | |
| 3103 | + maybeSetNewDescription( confFieldDescription, hiddenConfName, newConfValue ); | |
| 3104 | + } | |
| 3105 | + | |
| 3106 | + function maybeSetNewDescription( descriptionDiv, hiddenName, newValue ) { | |
| 3107 | + if ( descriptionDiv.innerHTML === frm_admin_js.desc ) { | |
| 3108 | + | |
| 3109 | + // Set the visible description value and the hidden description value | |
| 3110 | + descriptionDiv.innerHTML = newValue; | |
| 3111 | + document.getElementsByName( hiddenName )[0].value = newValue; | |
| 3112 | + } | |
| 3113 | + } | |
| 3114 | + | |
| 3115 | + function initBulkOptionsOverlay() { | |
| 3116 | + /*jshint validthis:true */ | |
| 3117 | + var $info = initModal( '#frm-bulk-modal', '700px' ); | |
| 3118 | + if ( $info === false ) { | |
| 3119 | + return; | |
| 3120 | + } | |
| 3121 | + | |
| 3122 | + jQuery( '.frm-insert-preset' ).on( 'click', insertBulkPreset ); | |
| 3123 | + | |
| 3124 | + jQuery( builderForm ).on( 'click', 'a.frm-bulk-edit-link', function( event ) { | |
| 3125 | + event.preventDefault(); | |
| 3126 | + var i, key, label, | |
| 3127 | + content = '', | |
| 3128 | + optList, | |
| 3129 | + opts, | |
| 3130 | + fieldId = jQuery( this ).closest( '[data-fid]' ).data( 'fid' ), | |
| 3131 | + separate = usingSeparateValues( fieldId ), | |
| 3132 | + product = isProductField( fieldId ); | |
| 3133 | + | |
| 3134 | + optList = document.getElementById( 'frm_field_' + fieldId + '_opts' ); | |
| 3135 | + if ( ! optList ) { | |
| 3136 | + return; | |
| 3137 | + } | |
| 3138 | + | |
| 3139 | + opts = optList.getElementsByTagName( 'li' ); | |
| 3140 | + | |
| 3141 | + document.getElementById( 'bulk-field-id' ).value = fieldId; | |
| 3142 | + | |
| 3143 | + for ( i = 0; i < opts.length; i++ ) { | |
| 3144 | + key = opts[i].getAttribute( 'data-optkey' ); | |
| 3145 | + if ( key !== '000' ) { | |
| 3146 | + label = document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][label]' )[0]; | |
| 3147 | + if ( typeof label !== 'undefined' ) { | |
| 3148 | + content += label.value; | |
| 3149 | + if ( separate ) { | |
| 3150 | + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][value]' )[0].value; | |
| 3151 | + } | |
| 3152 | + if ( product ) { | |
| 3153 | + content += '|' + document.getElementsByName( 'field_options[options_' + fieldId + '][' + key + '][price]' )[0].value; | |
| 3154 | + } | |
| 3155 | + content += '\r\n'; | |
| 3156 | + } | |
| 3157 | + } | |
| 3158 | + | |
| 3159 | + if ( i >= opts.length - 1 ) { | |
| 3160 | + document.getElementById( 'frm_bulk_options' ).value = content; | |
| 3161 | + } | |
| 3162 | + } | |
| 3163 | + | |
| 3164 | + $info.dialog( 'open' ); | |
| 3165 | + | |
| 3166 | + return false; | |
| 3167 | + }); | |
| 3168 | + | |
| 3169 | + jQuery( '#frm-update-bulk-opts' ).on( 'click', function() { | |
| 3170 | + var fieldId = document.getElementById( 'bulk-field-id' ).value; | |
| 3171 | + var optionType = document.getElementById( 'bulk-option-type' ).value; | |
| 3172 | + | |
| 3173 | + if ( optionType ) { | |
| 3174 | + // Use custom handler for custom option type. | |
| 3175 | + return; | |
| 3176 | + } | |
| 3177 | + | |
| 3178 | + this.classList.add( 'frm_loading_button' ); | |
| 3179 | + frmAdminBuild.updateOpts( fieldId, document.getElementById( 'frm_bulk_options' ).value, $info ); | |
| 3180 | + }); | |
| 3181 | + } | |
| 3182 | + | |
| 3183 | + function insertBulkPreset( event ) { | |
| 3184 | + /*jshint validthis:true */ | |
| 3185 | + var opts = JSON.parse( this.getAttribute( 'data-opts' ) ); | |
| 3186 | + event.preventDefault(); | |
| 3187 | + document.getElementById( 'frm_bulk_options' ).value = opts.join( '\n' ); | |
| 3188 | + return false; | |
| 3189 | + } | |
| 3190 | + | |
| 3191 | + //Add new option or "Other" option to radio/checkbox/dropdown | |
| 3192 | + function addFieldOption() { | |
| 3193 | + /*jshint validthis:true */ | |
| 3194 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 3195 | + newOption = jQuery( '#frm_field_' + fieldId + '_opts .frm_option_template' ).prop( 'outerHTML' ), | |
| 3196 | + optType = jQuery( this ).data( 'opttype' ), | |
| 3197 | + optKey = 0, | |
| 3198 | + oldKey = '000', | |
| 3199 | + lastKey = getHighestOptKey( fieldId ); | |
| 3200 | + | |
| 3201 | + if ( lastKey !== oldKey ) { | |
| 3202 | + optKey = lastKey + 1; | |
| 3203 | + } | |
| 3204 | + | |
| 3205 | + //Update hidden field | |
| 3206 | + if ( optType === 'other' ) { | |
| 3207 | + document.getElementById( 'other_input_' + fieldId ).value = 1; | |
| 3208 | + | |
| 3209 | + //Hide "Add Other" option now if this is radio field | |
| 3210 | + var ftype = jQuery( this ).data( 'ftype' ); | |
| 3211 | + if ( ftype === 'radio' || ftype === 'select' ) { | |
| 3212 | + jQuery( this ).fadeOut( 'slow' ); | |
| 3213 | + } | |
| 3214 | + | |
| 3215 | + var data = { | |
| 3216 | + action: 'frm_add_field_option', | |
| 3217 | + field_id: fieldId, | |
| 3218 | + opt_key: optKey, | |
| 3219 | + opt_type: optType, | |
| 3220 | + nonce: frmGlobal.nonce | |
| 3221 | + }; | |
| 3222 | + jQuery.post( ajaxurl, data, function( msg ) { | |
| 3223 | + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( msg ); | |
| 3224 | + resetDisplayedOpts( fieldId ); | |
| 3225 | + }); | |
| 3226 | + } else { | |
| 3227 | + newOption = newOption.replace( new RegExp( 'optkey="' + oldKey + '"', 'g' ), 'optkey="' + optKey + '"' ); | |
| 3228 | + newOption = newOption.replace( new RegExp( '-' + oldKey + '_', 'g' ), '-' + optKey + '_' ); | |
| 3229 | + newOption = newOption.replace( new RegExp( '-' + oldKey + '"', 'g' ), '-' + optKey + '"' ); | |
| 3230 | + newOption = newOption.replace( new RegExp( '\\[' + oldKey + '\\]', 'g' ), '[' + optKey + ']' ); | |
| 3231 | + newOption = newOption.replace( 'frm_hidden frm_option_template', '' ); | |
| 3232 | + newOption = { newOption }; | |
| 3233 | + addSaveAndDragIconsToOption( fieldId, newOption ); | |
| 3234 | + jQuery( document.getElementById( 'frm_field_' + fieldId + '_opts' ) ).append( newOption.newOption ); | |
| 3235 | + resetDisplayedOpts( fieldId ); | |
| 3236 | + } | |
| 3237 | + } | |
| 3238 | + | |
| 3239 | + function getHighestOptKey( fieldId ) { | |
| 3240 | + var i = 0, | |
| 3241 | + optKey = 0, | |
| 3242 | + opts = jQuery( '#frm_field_' + fieldId + '_opts li' ), | |
| 3243 | + lastKey = 0; | |
| 3244 | + | |
| 3245 | + for ( i; i < opts.length; i++ ) { | |
| 3246 | + optKey = opts[i].getAttribute( 'data-optkey' ); | |
| 3247 | + if ( opts.length === 1 ) { | |
| 3248 | + return optKey; | |
| 3249 | + } | |
| 3250 | + if ( optKey !== '000' ) { | |
| 3251 | + optKey = optKey.replace( 'other_', '' ); | |
| 3252 | + optKey = parseInt( optKey, 10 ); | |
| 3253 | + } | |
| 3254 | + | |
| 3255 | + if ( ! isNaN( lastKey ) && ( optKey > lastKey || lastKey === '000' ) ) { | |
| 3256 | + lastKey = optKey; | |
| 3257 | + } | |
| 3258 | + } | |
| 3259 | + | |
| 3260 | + return lastKey; | |
| 3261 | + } | |
| 3262 | + | |
| 3263 | + function toggleMultSel() { | |
| 3264 | + /*jshint validthis:true */ | |
| 3265 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3266 | + toggleMultiSelect( fieldId, this.value ); | |
| 3267 | + } | |
| 3268 | + | |
| 3269 | + function toggleMultiSelect( fieldId, value ) { | |
| 3270 | + var setting = jQuery( '.frm_multiple_cont_' + fieldId ); | |
| 3271 | + if ( value === 'select' ) { | |
| 3272 | + setting.fadeIn( 'fast' ); | |
| 3273 | + } else { | |
| 3274 | + setting.fadeOut( 'fast' ); | |
| 3275 | + } | |
| 3276 | + } | |
| 3277 | + | |
| 3278 | + function toggleSepValues() { | |
| 3279 | + /*jshint validthis:true */ | |
| 3280 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 3281 | + toggle( jQuery( '.field_' + fieldId + '_option_key' ) ); | |
| 3282 | + jQuery( '.field_' + fieldId + '_option' ).toggleClass( 'frm_with_key' ); | |
| 3283 | + } | |
| 3284 | + | |
| 3285 | + function toggleImageOptions() { | |
| 3286 | + /*jshint validthis:true */ | |
| 3287 | + var hasImageOptions, imageSize, | |
| 3288 | + $field = jQuery( this ).closest( '.frm-single-settings' ), | |
| 3289 | + fieldId = $field.data( 'fid' ), | |
| 3290 | + displayField = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 3291 | + | |
| 3292 | + refreshOptionDisplayNow( jQuery( this ) ); | |
| 3293 | + | |
| 3294 | + toggle( jQuery( '.field_' + fieldId + '_image_id' ) ); | |
| 3295 | + toggle( jQuery( '.frm_toggle_image_options_' + fieldId ) ); | |
| 3296 | + toggle( jQuery( '.frm_image_size_' + fieldId ) ); | |
| 3297 | + toggle( jQuery( '.frm_alignment_' + fieldId ) ); | |
| 3298 | + toggle( jQuery( '.frm-add-other#frm_add_field_' + fieldId ) ); | |
| 3299 | + | |
| 3300 | + hasImageOptions = imagesAsOptions( fieldId ); | |
| 3301 | + | |
| 3302 | + if ( hasImageOptions ) { | |
| 3303 | + setAlignment( fieldId, 'inline' ); | |
| 3304 | + removeImageSizeClasses( displayField ); | |
| 3305 | + imageSize = getImageOptionSize( fieldId ); | |
| 3306 | + displayField.classList.add( 'frm_image_options' ); | |
| 3307 | + displayField.classList.add( 'frm_image_size_' + imageSize ); | |
| 3308 | + $field.find( '.frm-bulk-edit-link' ).hide(); | |
| 3309 | + } else { | |
| 3310 | + displayField.classList.remove( 'frm_image_options' ); | |
| 3311 | + removeImageSizeClasses( displayField ); | |
| 3312 | + setAlignment( fieldId, 'block' ); | |
| 3313 | + $field.find( '.frm-bulk-edit-link' ).show(); | |
| 3314 | + } | |
| 3315 | + } | |
| 3316 | + | |
| 3317 | + function removeImageSizeClasses( field ) { | |
| 3318 | + field.classList.remove( 'frm_image_size_', 'frm_image_size_small', 'frm_image_size_medium', 'frm_image_size_large', 'frm_image_size_xlarge' ); | |
| 3319 | + } | |
| 3320 | + | |
| 3321 | + function setAlignment( fieldId, alignment ) { | |
| 3322 | + jQuery( '#field_options_align_' + fieldId ).val( alignment ).trigger( 'change' ); | |
| 3323 | + } | |
| 3324 | + | |
| 3325 | + function setImageSize() { | |
| 3326 | + var $field = jQuery( this ).closest( '.frm-single-settings' ), | |
| 3327 | + fieldId = $field.data( 'fid' ), | |
| 3328 | + displayField = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 3329 | + | |
| 3330 | + refreshOptionDisplay(); | |
| 3331 | + | |
| 3332 | + if ( imagesAsOptions( fieldId ) ) { | |
| 3333 | + removeImageSizeClasses( displayField ); | |
| 3334 | + displayField.classList.add( 'frm_image_options' ); | |
| 3335 | + displayField.classList.add( 'frm_image_size_' + getImageOptionSize( fieldId ) ); | |
| 3336 | + } | |
| 3337 | + } | |
| 3338 | + | |
| 3339 | + function refreshOptionDisplayNow( object ) { | |
| 3340 | + var $field = object.closest( '.frm-single-settings' ), | |
| 3341 | + fieldID = $field.data( 'fid' ); | |
| 3342 | + jQuery( '.field_' + fieldID + '_option' ).trigger( 'change' ); | |
| 3343 | + } | |
| 3344 | + | |
| 3345 | + function refreshOptionDisplay() { | |
| 3346 | + /*jshint validthis:true */ | |
| 3347 | + refreshOptionDisplayNow( jQuery( this ) ); | |
| 3348 | + } | |
| 3349 | + | |
| 3350 | + function addImageToOption( event ) { | |
| 3351 | + const imagePreview = event.target.closest( '.frm_image_preview_wrapper' ); | |
| 3352 | + | |
| 3353 | + event.preventDefault(); | |
| 3354 | + | |
| 3355 | + wp.media.model.settings.post.id = 0; | |
| 3356 | + | |
| 3357 | + const fileFrame = wp.media.frames.file_frame = wp.media({ | |
| 3358 | + multiple: false, | |
| 3359 | + library: { | |
| 3360 | + type: [ 'image' ] | |
| 3361 | + } | |
| 3362 | + }); | |
| 3363 | + | |
| 3364 | + fileFrame.on( 'select', function() { | |
| 3365 | + const attachment = fileFrame.state().get( 'selection' ).first().toJSON(); | |
| 3366 | + const img = imagePreview.querySelector( 'img' ); | |
| 3367 | + | |
| 3368 | + img.setAttribute( 'src', attachment.url ); | |
| 3369 | + img.classList.remove( 'frm_hidden' ); | |
| 3370 | + img.removeAttribute( 'srcset' ); // Prevent the old image from sticking around. | |
| 3371 | + | |
| 3372 | + imagePreview.querySelector( '.frm_image_preview_frame' ).style.display = 'block'; | |
| 3373 | + imagePreview.querySelector( '.frm_image_preview_title' ).textContent = attachment.filename; | |
| 3374 | + imagePreview.querySelector( '.frm_choose_image_box' ).style.display = 'none'; | |
| 3375 | + | |
| 3376 | + const $imagePreview = jQuery( imagePreview ); | |
| 3377 | + $imagePreview.siblings( 'input[name*="[label]"]' ).data( 'frmimgurl', attachment.url ); | |
| 3378 | + $imagePreview.find( 'input.frm_image_id' ).val( attachment.id ).trigger( 'change' ); | |
| 3379 | + wp.media.model.settings.post.id = 0; | |
| 3380 | + }); | |
| 3381 | + | |
| 3382 | + fileFrame.open(); | |
| 3383 | + } | |
| 3384 | + | |
| 3385 | + function removeImageFromOption( event ) { | |
| 3386 | + var $this = jQuery( this ), | |
| 3387 | + previewWrapper = $this.closest( '.frm_image_preview_wrapper' ); | |
| 3388 | + | |
| 3389 | + event.preventDefault(); | |
| 3390 | + event.stopPropagation(); | |
| 3391 | + | |
| 3392 | + previewWrapper.find( 'img' ).attr( 'src', '' ); | |
| 3393 | + previewWrapper.find( '.frm_image_preview_frame' ).hide(); | |
| 3394 | + previewWrapper.find( '.frm_choose_image_box' ).show(); | |
| 3395 | + previewWrapper.find( 'input.frm_image_id' ).val( 0 ).trigger( 'change' ); | |
| 3396 | + } | |
| 3397 | + | |
| 3398 | + function toggleMultiselect() { | |
| 3399 | + /*jshint validthis:true */ | |
| 3400 | + var dropdown = jQuery( this ).closest( 'li' ).find( '.frm_form_fields select' ); | |
| 3401 | + if ( this.checked ) { | |
| 3402 | + dropdown.attr( 'multiple', 'multiple' ); | |
| 3403 | + } else { | |
| 3404 | + dropdown.removeAttr( 'multiple' ); | |
| 3405 | + } | |
| 3406 | + } | |
| 3407 | + | |
| 3408 | + /** | |
| 3409 | + * Allow typing on form switcher click without an extra click to search. | |
| 3410 | + */ | |
| 3411 | + function focusSearchBox() { | |
| 3412 | + var searchBox = document.getElementById( 'dropform-search-input' ); | |
| 3413 | + if ( searchBox !== null ) { | |
| 3414 | + setTimeout( function() { | |
| 3415 | + searchBox.focus(); | |
| 3416 | + }, 100 ); | |
| 3417 | + } | |
| 3418 | + } | |
| 3419 | + | |
| 3420 | + /** | |
| 3421 | + * If a field is clicked in the builder, prevent inputs from changing. | |
| 3422 | + */ | |
| 3423 | + function stopFieldFocus( e ) { | |
| 3424 | + e.preventDefault(); | |
| 3425 | + } | |
| 3426 | + | |
| 3427 | + function deleteFieldOption() { | |
| 3428 | + /*jshint validthis:true */ | |
| 3429 | + var otherInput, | |
| 3430 | + parentLi = this.parentNode, | |
| 3431 | + parentUl = parentLi.parentNode, | |
| 3432 | + fieldId = this.getAttribute( 'data-fid' ); | |
| 3433 | + | |
| 3434 | + jQuery( parentLi ).fadeOut( 'slow', function() { | |
| 3435 | + jQuery( parentLi ).remove(); | |
| 3436 | + | |
| 3437 | + var hasOther = jQuery( parentUl ).find( '.frm_other_option' ); | |
| 3438 | + if ( hasOther.length < 1 ) { | |
| 3439 | + otherInput = document.getElementById( 'other_input_' + fieldId ); | |
| 3440 | + if ( otherInput !== null ) { | |
| 3441 | + otherInput.value = 0; | |
| 3442 | + } | |
| 3443 | + jQuery( '#other_button_' + fieldId ).fadeIn( 'slow' ); | |
| 3444 | + } | |
| 3445 | + }); | |
| 3446 | + } | |
| 3447 | + | |
| 3448 | + /** | |
| 3449 | + * If a radio button is set as default, allow a click to | |
| 3450 | + * deselect it. | |
| 3451 | + */ | |
| 3452 | + function maybeUncheckRadio() { | |
| 3453 | + var $self, uncheck, unbind, up; | |
| 3454 | + | |
| 3455 | + /*jshint validthis:true */ | |
| 3456 | + $self = jQuery( this ); | |
| 3457 | + if ( $self.is( ':checked' ) ) { | |
| 3458 | + uncheck = function() { | |
| 3459 | + setTimeout( function() { | |
| 3460 | + $self.prop( 'checked', false ); | |
| 3461 | + }, 0 ); | |
| 3462 | + }; | |
| 3463 | + unbind = function() { | |
| 3464 | + $self.off( 'mouseup', up ); | |
| 3465 | + }; | |
| 3466 | + up = function() { | |
| 3467 | + uncheck(); | |
| 3468 | + unbind(); | |
| 3469 | + }; | |
| 3470 | + $self.on( 'mouseup', up ); | |
| 3471 | + $self.one( 'mouseout', unbind ); | |
| 3472 | + } | |
| 3473 | + } | |
| 3474 | + | |
| 3475 | + /** | |
| 3476 | + * If the field option has the default text, clear it out on click. | |
| 3477 | + */ | |
| 3478 | + function maybeClearOptText() { | |
| 3479 | + /*jshint validthis:true */ | |
| 3480 | + if ( this.value === frm_admin_js.new_option ) { | |
| 3481 | + this.setAttribute( 'data-value-on-focus', this.value ); | |
| 3482 | + this.value = ''; | |
| 3483 | + } | |
| 3484 | + } | |
| 3485 | + | |
| 3486 | + function clickDeleteField() { | |
| 3487 | + /*jshint validthis:true */ | |
| 3488 | + var confirmMsg = frm_admin_js.conf_delete, | |
| 3489 | + maybeDivider = this.parentNode.parentNode.parentNode.parentNode.parentNode, | |
| 3490 | + li = maybeDivider.parentNode, | |
| 3491 | + field = jQuery( this ).closest( 'li.form-field' ), | |
| 3492 | + fieldId = field.data( 'fid' ); | |
| 3493 | + | |
| 3494 | + if ( li.classList.contains( 'frm-section-collapsed' ) || li.classList.contains( 'frm-page-collapsed' ) ) { | |
| 3495 | + return false; | |
| 3496 | + } | |
| 3497 | + | |
| 3498 | + // If deleting a section, use a special message. | |
| 3499 | + if ( maybeDivider.className === 'divider_section_only' ) { | |
| 3500 | + confirmMsg = frm_admin_js.conf_delete_sec; | |
| 3501 | + } | |
| 3502 | + | |
| 3503 | + this.setAttribute( 'data-frmverify', confirmMsg ); | |
| 3504 | + this.setAttribute( 'data-frmverify-btn', 'frm-button-red' ); | |
| 3505 | + this.setAttribute( 'data-deletefield', fieldId ); | |
| 3506 | + | |
| 3507 | + closeOpenFieldDropdowns(); | |
| 3508 | + | |
| 3509 | + confirmLinkClick( this ); | |
| 3510 | + return false; | |
| 3511 | + } | |
| 3512 | + | |
| 3513 | + function clickSelectField() { | |
| 3514 | + this.closest( 'li.form-field' ).click(); | |
| 3515 | + } | |
| 3516 | + | |
| 3517 | + function clickDeleteFieldGroup() { | |
| 3518 | + var hoverTarget, decoy; | |
| 3519 | + | |
| 3520 | + hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3521 | + if ( null === hoverTarget ) { | |
| 3522 | + return; | |
| 3523 | + } | |
| 3524 | + | |
| 3525 | + hoverTarget.classList.add( 'frm-selected-field-group' ); | |
| 3526 | + | |
| 3527 | + decoy = document.createElement( 'div' ); | |
| 3528 | + decoy.classList.add( 'frm-delete-field-groups', 'frm_hidden' ); | |
| 3529 | + document.body.appendChild( decoy ); | |
| 3530 | + decoy.click(); | |
| 3531 | + } | |
| 3532 | + | |
| 3533 | + function duplicateFieldGroup() { | |
| 3534 | + const hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3535 | + if ( null === hoverTarget ) { | |
| 3536 | + return; | |
| 3537 | + } | |
| 3538 | + | |
| 3539 | + const newRowId = 'frm_field_group_' + getAutoId(); | |
| 3540 | + const placeholderUlChild = document.createTextNode( '' ); | |
| 3541 | + wrapFieldLiInPlace( placeholderUlChild ); | |
| 3542 | + | |
| 3543 | + const newRow = jQuery( placeholderUlChild ).closest( 'li' ).get( 0 ); | |
| 3544 | + newRow.classList.add( 'frm_hidden' ); | |
| 3545 | + | |
| 3546 | + const newRowUl = newRow.querySelector( 'ul' ); | |
| 3547 | + newRowUl.id = newRowId; | |
| 3548 | + | |
| 3549 | + jQuery( hoverTarget.closest( 'li.frm_field_box' ) ).after( newRow ); | |
| 3550 | + | |
| 3551 | + const $fields = getFieldsInRow( jQuery( hoverTarget ) ); | |
| 3552 | + const syncDetails = []; | |
| 3553 | + const injectedCloneOptions = []; | |
| 3554 | + | |
| 3555 | + const expectedLength = $fields.length; | |
| 3556 | + const originalFieldIdByDuplicatedFieldId = {}; | |
| 3557 | + | |
| 3558 | + let duplicatedCount = 0; | |
| 3559 | + | |
| 3560 | + jQuery( newRow ).on( | |
| 3561 | + 'frm_added_duplicated_field_to_row', | |
| 3562 | + function( _, args ) { | |
| 3563 | + originalFieldIdByDuplicatedFieldId[ jQuery( args.duplicatedFieldHtml ).attr( 'data-fid' ) ] = args.originalFieldId; | |
| 3564 | + | |
| 3565 | + if ( expectedLength > ++duplicatedCount ) { | |
| 3566 | + return; | |
| 3567 | + } | |
| 3568 | + | |
| 3569 | + const $newRowUl = jQuery( newRowUl ); | |
| 3570 | + const $duplicatedFields = getFieldsInRow( $newRowUl ); | |
| 3571 | + | |
| 3572 | + injectedCloneOptions.forEach( | |
| 3573 | + function( cloneOption ) { | |
| 3574 | + cloneOption.remove(); | |
| 3575 | + } | |
| 3576 | + ); | |
| 3577 | + | |
| 3578 | + for ( let index = 0; index < expectedLength; ++index ) { | |
| 3579 | + $newRowUl.append( $newRowUl.children( 'li.form-field[frm-field-order="' + index + '"]' ) ); | |
| 3580 | + } | |
| 3581 | + | |
| 3582 | + syncLayoutClasses( $duplicatedFields.first(), syncDetails ); | |
| 3583 | + newRow.classList.remove( 'frm_hidden' ); | |
| 3584 | + updateFieldOrder(); | |
| 3585 | + | |
| 3586 | + getFieldsInRow( $newRowUl ).each( | |
| 3587 | + function() { | |
| 3588 | + maybeDuplicateUnsavedSettings( originalFieldIdByDuplicatedFieldId[ this.getAttribute( 'data-fid' ) ], jQuery( this ).prop( 'outerHTML' ) ); | |
| 3589 | + } | |
| 3590 | + ); | |
| 3591 | + } | |
| 3592 | + ); | |
| 3593 | + | |
| 3594 | + $fields.each( | |
| 3595 | + function( index ) { | |
| 3596 | + var cloneOption; | |
| 3597 | + cloneOption = document.createElement( 'li' ); | |
| 3598 | + cloneOption.classList.add( 'frm_clone_field' ); | |
| 3599 | + cloneOption.setAttribute( 'frm-target-row-id', newRowId ); | |
| 3600 | + cloneOption.setAttribute( 'frm-field-order', index ); | |
| 3601 | + this.appendChild( cloneOption ); | |
| 3602 | + cloneOption.click(); | |
| 3603 | + injectedCloneOptions.push( cloneOption ); | |
| 3604 | + syncDetails.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) ); | |
| 3605 | + } | |
| 3606 | + ); | |
| 3607 | + } | |
| 3608 | + | |
| 3609 | + function clickFieldGroupLayout() { | |
| 3610 | + var hoverTarget, sizeOfFieldGroup, popupWrapper; | |
| 3611 | + | |
| 3612 | + hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3613 | + | |
| 3614 | + if ( null === hoverTarget ) { | |
| 3615 | + return; | |
| 3616 | + } | |
| 3617 | + | |
| 3618 | + deselectFields(); | |
| 3619 | + | |
| 3620 | + sizeOfFieldGroup = getSizeOfFieldGroupFromChildElement( hoverTarget.querySelector( 'li.form-field' ) ); | |
| 3621 | + | |
| 3622 | + hoverTarget.classList.add( 'frm-has-open-field-group-popup' ); | |
| 3623 | + jQuery( document ).on( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick ); | |
| 3624 | + | |
| 3625 | + popupWrapper = div(); | |
| 3626 | + popupWrapper.style.position = 'relative'; | |
| 3627 | + popupWrapper.appendChild( getFieldGroupPopup( sizeOfFieldGroup, this ) ); | |
| 3628 | + this.parentNode.appendChild( popupWrapper ); | |
| 3629 | + | |
| 3630 | + const firstLayoutOption = popupWrapper.querySelector( '.frm-row-layout-option' ); | |
| 3631 | + if ( firstLayoutOption ) { | |
| 3632 | + firstLayoutOption.focus(); | |
| 3633 | + } | |
| 3634 | + } | |
| 3635 | + | |
| 3636 | + function destroyFieldGroupPopupOnOutsideClick( event ) { | |
| 3637 | + if ( event.target.classList.contains( 'frm-custom-field-group-layout' ) || event.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) { | |
| 3638 | + return; | |
| 3639 | + } | |
| 3640 | + if ( ! jQuery( event.target ).closest( '#frm_field_group_controls' ).length && ! jQuery( event.target ).closest( '#frm_field_group_popup' ).length ) { | |
| 3641 | + destroyFieldGroupPopup(); | |
| 3642 | + } | |
| 3643 | + } | |
| 3644 | + | |
| 3645 | + function getSizeOfFieldGroupFromChildElement( element ) { | |
| 3646 | + var $ul = jQuery( element ).closest( 'ul' ); | |
| 3647 | + if ( $ul.length ) { | |
| 3648 | + return getFieldsInRow( $ul ).length; | |
| 3649 | + } | |
| 3650 | + return getSelectedFieldCount(); | |
| 3651 | + } | |
| 3652 | + | |
| 3653 | + function getFieldGroupPopup( sizeOfFieldGroup, childElement ) { | |
| 3654 | + var popup, wrapper, rowLayoutOptions, ul; | |
| 3655 | + | |
| 3656 | + popup = document.getElementById( 'frm_field_group_popup' ); | |
| 3657 | + if ( null === popup ) { | |
| 3658 | + popup = div(); | |
| 3659 | + } else { | |
| 3660 | + popup.innerHTML = ''; | |
| 3661 | + } | |
| 3662 | + | |
| 3663 | + popup.id = 'frm_field_group_popup'; | |
| 3664 | + | |
| 3665 | + wrapper = div(); | |
| 3666 | + wrapper.style.padding = '0 24px 12px'; | |
| 3667 | + wrapper.appendChild( getRowLayoutTitle() ); | |
| 3668 | + | |
| 3669 | + rowLayoutOptions = getRowLayoutOptions( sizeOfFieldGroup ); | |
| 3670 | + | |
| 3671 | + ul = childElement.closest( 'ul.frm_sorting' ); | |
| 3672 | + if ( null !== ul ) { | |
| 3673 | + maybeMarkRowLayoutAsActive( ul, rowLayoutOptions ); | |
| 3674 | + } | |
| 3675 | + | |
| 3676 | + wrapper.appendChild( rowLayoutOptions ); | |
| 3677 | + | |
| 3678 | + popup.appendChild( wrapper ); | |
| 3679 | + popup.appendChild( separator() ); | |
| 3680 | + | |
| 3681 | + popup.appendChild( getCustomLayoutOption() ); | |
| 3682 | + popup.appendChild( getBreakIntoDifferentRowsOption() ); | |
| 3683 | + | |
| 3684 | + return popup; | |
| 3685 | + } | |
| 3686 | + | |
| 3687 | + function maybeMarkRowLayoutAsActive( activeRow, options ) { | |
| 3688 | + var length, index, currentRow; | |
| 3689 | + | |
| 3690 | + length = options.children.length; | |
| 3691 | + for ( index = 0; index < length; ++index ) { | |
| 3692 | + currentRow = options.children[ index ]; | |
| 3693 | + if ( rowLayoutsMatch( currentRow, activeRow ) ) { | |
| 3694 | + currentRow.classList.add( 'frm-active-row-layout' ); | |
| 3695 | + return; | |
| 3696 | + } | |
| 3697 | + } | |
| 3698 | + } | |
| 3699 | + | |
| 3700 | + function separator() { | |
| 3701 | + var hr = document.createElement( 'hr' ); | |
| 3702 | + return hr; | |
| 3703 | + } | |
| 3704 | + | |
| 3705 | + function getCustomLayoutOption() { | |
| 3706 | + var option = div(); | |
| 3707 | + option.textContent = __( 'Custom layout', 'formidable' ); | |
| 3708 | + jQuery( option ).prepend( getIconClone( 'frm_gear_svg' ) ); | |
| 3709 | + option.classList.add( 'frm-custom-field-group-layout' ); | |
| 3710 | + makeTabbable( option ); | |
| 3711 | + return option; | |
| 3712 | + } | |
| 3713 | + | |
| 3714 | + function makeTabbable( element, ariaLabel ) { | |
| 3715 | + element.setAttribute( 'tabindex', 0 ); | |
| 3716 | + element.setAttribute( 'role', 'button' ); | |
| 3717 | + if ( 'undefined' !== typeof ariaLabel ) { | |
| 3718 | + element.setAttribute( 'aria-label', ariaLabel ); | |
| 3719 | + } | |
| 3720 | + } | |
| 3721 | + | |
| 3722 | + function getIconClone( iconId ) { | |
| 3723 | + var clone = document.getElementById( iconId ).cloneNode( true ); | |
| 3724 | + clone.id = ''; | |
| 3725 | + return clone; | |
| 3726 | + } | |
| 3727 | + | |
| 3728 | + function getBreakIntoDifferentRowsOption() { | |
| 3729 | + var option = div(); | |
| 3730 | + option.textContent = __( 'Break into rows', 'formidable' ); | |
| 3731 | + jQuery( option ).prepend( getIconClone( 'frm_break_field_group_svg' ) ); | |
| 3732 | + option.classList.add( 'frm-break-field-group' ); | |
| 3733 | + makeTabbable( option ); | |
| 3734 | + return option; | |
| 3735 | + } | |
| 3736 | + | |
| 3737 | + function getRowLayoutTitle() { | |
| 3738 | + var rowLayoutTitle = div(); | |
| 3739 | + rowLayoutTitle.classList.add( 'frm-row-layout-title' ); | |
| 3740 | + rowLayoutTitle.textContent = __( 'Row Layout', 'formidable' ); | |
| 3741 | + return rowLayoutTitle; | |
| 3742 | + } | |
| 3743 | + | |
| 3744 | + function getRowLayoutOptions( size ) { | |
| 3745 | + var wrapper, padding; | |
| 3746 | + | |
| 3747 | + wrapper = getEmptyGridContainer(); | |
| 3748 | + if ( 5 !== size ) { | |
| 3749 | + wrapper.appendChild( getRowLayoutOption( size, 'even' ) ); | |
| 3750 | + } | |
| 3751 | + if ( size % 2 === 1 ) { | |
| 3752 | + // only include the middle option for odd numbers because even doesn't make a lot of sense. | |
| 3753 | + wrapper.appendChild( getRowLayoutOption( size, 'middle' ) ); | |
| 3754 | + } | |
| 3755 | + if ( size < 6 ) { | |
| 3756 | + wrapper.appendChild( getRowLayoutOption( size, 'left' ) ); | |
| 3757 | + wrapper.appendChild( getRowLayoutOption( size, 'right' ) ); | |
| 3758 | + } else { | |
| 3759 | + padding = div(); | |
| 3760 | + padding.classList.add( 'frm_fourth' ); | |
| 3761 | + wrapper.prepend( padding ); | |
| 3762 | + } | |
| 3763 | + | |
| 3764 | + return wrapper; | |
| 3765 | + } | |
| 3766 | + | |
| 3767 | + function getRowLayoutOption( size, type ) { | |
| 3768 | + var option, useClass; | |
| 3769 | + | |
| 3770 | + option = div(); | |
| 3771 | + option.classList.add( 'frm-row-layout-option' ); | |
| 3772 | + makeTabbable( option, type ); | |
| 3773 | + | |
| 3774 | + switch ( size ) { | |
| 3775 | + case 6: | |
| 3776 | + useClass = 'frm_half'; | |
| 3777 | + break; | |
| 3778 | + case 5: | |
| 3779 | + useClass = 'frm_third'; | |
| 3780 | + break; | |
| 3781 | + default: | |
| 3782 | + useClass = size % 2 === 1 ? 'frm_fourth' : 'frm_third'; | |
| 3783 | + break; | |
| 3784 | + } | |
| 3785 | + | |
| 3786 | + option.classList.add( useClass ); | |
| 3787 | + option.setAttribute( 'layout-type', type ); | |
| 3788 | + | |
| 3789 | + option.appendChild( getRowForSizeAndType( size, type ) ); | |
| 3790 | + return option; | |
| 3791 | + } | |
| 3792 | + | |
| 3793 | + function rowLayoutsMatch( row1, row2 ) { | |
| 3794 | + return getRowLayoutAsKey( row1 ) === getRowLayoutAsKey( row2 ); | |
| 3795 | + } | |
| 3796 | + | |
| 3797 | + function getRowLayoutAsKey( row ) { | |
| 3798 | + var $fields, sizes; | |
| 3799 | + if ( row.classList.contains( 'frm-row-layout-option' ) ) { | |
| 3800 | + $fields = jQuery( row ).find( '.frm_grid_container' ).children(); | |
| 3801 | + } else { | |
| 3802 | + $fields = getFieldsInRow( jQuery( row ) ); | |
| 3803 | + } | |
| 3804 | + sizes = []; | |
| 3805 | + $fields.each( | |
| 3806 | + function() { | |
| 3807 | + sizes.push( getSizeOfLayoutClass( getLayoutClassName( this.classList ) ) ); | |
| 3808 | + } | |
| 3809 | + ); | |
| 3810 | + return sizes.join( '-' ); | |
| 3811 | + } | |
| 3812 | + | |
| 3813 | + function getRowForSizeAndType( size, type ) { | |
| 3814 | + var row, index, block; | |
| 3815 | + | |
| 3816 | + row = getEmptyGridContainer(); | |
| 3817 | + for ( index = 0; index < size; ++index ) { | |
| 3818 | + block = div(); | |
| 3819 | + block.classList.add( getClassForBlock( size, type, index ) ); | |
| 3820 | + block.style.height = '16px'; | |
| 3821 | + block.style.background = '#9EA9B8'; | |
| 3822 | + block.style.borderRadius = '1px'; | |
| 3823 | + row.appendChild( block ); | |
| 3824 | + } | |
| 3825 | + | |
| 3826 | + return row; | |
| 3827 | + } | |
| 3828 | + | |
| 3829 | + /** | |
| 3830 | + * @param {int} size 2-6. | |
| 3831 | + * @param {string} type even, middle, left, or right. | |
| 3832 | + * @param {int} index 0-5. | |
| 3833 | + * @returns string | |
| 3834 | + */ | |
| 3835 | + function getClassForBlock( size, type, index ) { | |
| 3836 | + if ( 'even' === type ) { | |
| 3837 | + return getEvenClassForSize( size, index ); | |
| 3838 | + } else if ( 'middle' === type ) { | |
| 3839 | + if ( 3 === size ) { | |
| 3840 | + return 1 === index ? 'frm6' : 'frm3'; | |
| 3841 | + } | |
| 3842 | + if ( 5 === size ) { | |
| 3843 | + return 2 === index ? 'frm4' : 'frm2'; | |
| 3844 | + } | |
| 3845 | + } else if ( 'left' === type ) { | |
| 3846 | + return 0 === index ? getLargeClassForSize( size ) : getSmallClassForSize( size ); | |
| 3847 | + } else if ( 'right' === type ) { | |
| 3848 | + return index === size - 1 ? getLargeClassForSize( size ) : getSmallClassForSize( size ); | |
| 3849 | + } | |
| 3850 | + return 'frm12'; | |
| 3851 | + } | |
| 3852 | + | |
| 3853 | + function getEvenClassForSize( size, index ) { | |
| 3854 | + if ( -1 !== [ 2, 3, 4, 6 ].indexOf( size ) ) { | |
| 3855 | + return getLayoutClassForSize( 12 / size ); | |
| 3856 | + } | |
| 3857 | + if ( 5 === size && 'undefined' !== typeof index ) { | |
| 3858 | + return 0 === index ? 'frm4' : 'frm2'; | |
| 3859 | + } | |
| 3860 | + return 'frm12'; | |
| 3861 | + } | |
| 3862 | + | |
| 3863 | + function getSmallClassForSize( size ) { | |
| 3864 | + switch ( size ) { | |
| 3865 | + case 2: case 3: | |
| 3866 | + return 'frm3'; | |
| 3867 | + case 4: | |
| 3868 | + return 'frm2'; | |
| 3869 | + case 5: | |
| 3870 | + return 'frm2'; | |
| 3871 | + case 6: | |
| 3872 | + return 'frm1'; | |
| 3873 | + } | |
| 3874 | + return 'frm12'; | |
| 3875 | + } | |
| 3876 | + | |
| 3877 | + function getLargeClassForSize( size ) { | |
| 3878 | + switch ( size ) { | |
| 3879 | + case 2: | |
| 3880 | + return 'frm9'; | |
| 3881 | + case 3: case 4: | |
| 3882 | + return 'frm6'; | |
| 3883 | + case 5: | |
| 3884 | + return 'frm4'; | |
| 3885 | + case 6: | |
| 3886 | + return 'frm7'; | |
| 3887 | + } | |
| 3888 | + return 'frm12'; | |
| 3889 | + } | |
| 3890 | + | |
| 3891 | + function getEmptyGridContainer() { | |
| 3892 | + var wrapper = div(); | |
| 3893 | + wrapper.classList.add( 'frm_grid_container' ); | |
| 3894 | + return wrapper; | |
| 3895 | + } | |
| 3896 | + | |
| 3897 | + /** | |
| 3898 | + * Handle when a field group layout option (that sets grid classes/column sizing) is selected in the "Row Layout" popup. | |
| 3899 | + * | |
| 3900 | + * @returns {void} | |
| 3901 | + */ | |
| 3902 | + function handleFieldGroupLayoutOptionClick() { | |
| 3903 | + const row = document.querySelector( '.frm-field-group-hover-target' ); | |
| 3904 | + if ( ! row ) { | |
| 3905 | + // The field group layout options also get clicked when merging multiple rows. | |
| 3906 | + // The following code isn't required for multiple rows though so just exit early. | |
| 3907 | + return; | |
| 3908 | + } | |
| 3909 | + | |
| 3910 | + const type = this.getAttribute( 'layout-type' ); | |
| 3911 | + syncLayoutClasses( getFieldsInRow( jQuery( row ) ).first(), type ); | |
| 3912 | + destroyFieldGroupPopup(); | |
| 3913 | + } | |
| 3914 | + | |
| 3915 | + function handleFieldGroupLayoutOptionInsideMergeClick() { | |
| 3916 | + var $ul, type; | |
| 3917 | + $ul = mergeSelectedFieldGroups(); | |
| 3918 | + type = this.getAttribute( 'layout-type' ); | |
| 3919 | + syncLayoutClasses( getFieldsInRow( $ul ).first(), type ); | |
| 3920 | + unselectFieldGroups(); | |
| 3921 | + } | |
| 3922 | + | |
| 3923 | + function mergeSelectedFieldGroups() { | |
| 3924 | + var $selectedFieldGroups = jQuery( '.frm-selected-field-group' ), | |
| 3925 | + $firstGroupUl = $selectedFieldGroups.first(); | |
| 3926 | + $selectedFieldGroups.not( $firstGroupUl ).each( | |
| 3927 | + function() { | |
| 3928 | + getFieldsInRow( jQuery( this ) ).each( | |
| 3929 | + function() { | |
| 3930 | + var previousParent = this.parentNode; | |
| 3931 | + getFieldsInRow( $firstGroupUl ).last().after( this ); | |
| 3932 | + if ( ! jQuery( previousParent ).children( 'li.form-field' ).length ) { | |
| 3933 | + // clean up the previous field group if we've removed all of its fields. | |
| 3934 | + previousParent.closest( 'li.frm_field_box' ).remove(); | |
| 3935 | + } | |
| 3936 | + } | |
| 3937 | + ); | |
| 3938 | + } | |
| 3939 | + ); | |
| 3940 | + updateFieldOrder(); | |
| 3941 | + syncLayoutClasses( getFieldsInRow( $firstGroupUl ).first() ); | |
| 3942 | + return $firstGroupUl; | |
| 3943 | + } | |
| 3944 | + | |
| 3945 | + function customFieldGroupLayoutClick() { | |
| 3946 | + var $fields; | |
| 3947 | + if ( null !== this.closest( '.frm-merge-fields-into-row' ) ) { | |
| 3948 | + return; | |
| 3949 | + } | |
| 3950 | + $fields = getFieldsInRow( jQuery( '.frm-field-group-hover-target' ) ); | |
| 3951 | + setupCustomLayoutOptions( $fields ); | |
| 3952 | + } | |
| 3953 | + | |
| 3954 | + function setupCustomLayoutOptions( $fields ) { | |
| 3955 | + var size, popup, wrapper, layoutClass, inputRow, paddingElement, inputValueOverride, index, inputField, heading, label, buttonsWrapper, cancelButton, saveButton; | |
| 3956 | + | |
| 3957 | + size = $fields.length; | |
| 3958 | + | |
| 3959 | + popup = document.getElementById( 'frm_field_group_popup' ); | |
| 3960 | + popup.innerHTML = ''; | |
| 3961 | + | |
| 3962 | + wrapper = div(); | |
| 3963 | + wrapper.style.padding = '24px'; | |
| 3964 | + | |
| 3965 | + layoutClass = getEvenClassForSize( 5 === size ? 6 : size ); | |
| 3966 | + | |
| 3967 | + inputRow = div(); | |
| 3968 | + inputRow.style.padding = '20px 0'; | |
| 3969 | + inputRow.classList.add( 'frm_grid_container' ); | |
| 3970 | + | |
| 3971 | + if ( 5 === size ) { | |
| 3972 | + // add a span to pad the inputs by 1 column, to account for the missing 2 columns. | |
| 3973 | + paddingElement = document.createElement( 'span' ); | |
| 3974 | + paddingElement.classList.add( 'frm1' ); | |
| 3975 | + inputRow.appendChild( paddingElement ); | |
| 3976 | + } | |
| 3977 | + | |
| 3978 | + inputValueOverride = getSelectedFieldCount() > 0 ? getSizeOfLayoutClass( getEvenClassForSize( size ) ) : false; | |
| 3979 | + if ( false !== inputValueOverride && inputValueOverride >= 12 ) { | |
| 3980 | + inputValueOverride = Math.floor( 12 / size ); | |
| 3981 | + } | |
| 3982 | + | |
| 3983 | + for ( index = 0; index < size; ++index ) { | |
| 3984 | + inputField = document.createElement( 'input' ); | |
| 3985 | + inputField.type = 'text'; | |
| 3986 | + inputField.classList.add( layoutClass ); | |
| 3987 | + inputField.classList.add( 'frm-custom-grid-size-input' ); | |
| 3988 | + inputField.value = false !== inputValueOverride ? inputValueOverride : getSizeOfLayoutClass( getLayoutClassName( $fields.get( index ).classList ) ); | |
| 3989 | + inputRow.appendChild( inputField ); | |
| 3990 | + } | |
| 3991 | + | |
| 3992 | + heading = div(); | |
| 3993 | + heading.classList.add( 'frm-builder-popup-heading' ); | |
| 3994 | + heading.textContent = __( 'Enter number of columns for each field', 'formidable' ); | |
| 3995 | + | |
| 3996 | + label = div(); | |
| 3997 | + label.classList.add( 'frm-builder-popup-subheading' ); | |
| 3998 | + label.textContent = __( 'Layouts are based on a 12-column grid system', 'formidable' ); | |
| 3999 | + | |
| 4000 | + wrapper.appendChild( heading ); | |
| 4001 | + wrapper.appendChild( label ); | |
| 4002 | + | |
| 4003 | + wrapper.appendChild( inputRow ); | |
| 4004 | + | |
| 4005 | + buttonsWrapper = div(); | |
| 4006 | + buttonsWrapper.style.textAlign = 'right'; | |
| 4007 | + | |
| 4008 | + cancelButton = getSecondaryButton(); | |
| 4009 | + cancelButton.textContent = __( 'Cancel', 'formidable' ); | |
| 4010 | + cancelButton.classList.add( 'frm-cancel-custom-field-group-layout' ); | |
| 4011 | + cancelButton.style.marginRight = '10px'; | |
| 4012 | + | |
| 4013 | + saveButton = getPrimaryButton(); | |
| 4014 | + saveButton.textContent = __( 'Save', 'formidable' ); | |
| 4015 | + saveButton.classList.add( 'frm-save-custom-field-group-layout' ); | |
| 4016 | + | |
| 4017 | + buttonsWrapper.appendChild( cancelButton ); | |
| 4018 | + buttonsWrapper.appendChild( saveButton ); | |
| 4019 | + | |
| 4020 | + wrapper.appendChild( buttonsWrapper ); | |
| 4021 | + | |
| 4022 | + popup.appendChild( wrapper ); | |
| 4023 | + | |
| 4024 | + setTimeout( | |
| 4025 | + function() { | |
| 4026 | + const firstInput = popup.querySelector( 'input.frm-custom-grid-size-input' ).focus(); | |
| 4027 | + if ( firstInput ) { | |
| 4028 | + firstInput.focus(); | |
| 4029 | + } | |
| 4030 | + }, | |
| 4031 | + 0 | |
| 4032 | + ); | |
| 4033 | + } | |
| 4034 | + | |
| 4035 | + function customFieldGroupLayoutInsideMergeClick() { | |
| 4036 | + $fields = jQuery( '.frm-selected-field-group li.form-field' ); | |
| 4037 | + setupCustomLayoutOptions( $fields ); | |
| 4038 | + } | |
| 4039 | + | |
| 4040 | + function getPrimaryButton() { | |
| 4041 | + var button = getButton(); | |
| 4042 | + button.classList.add( 'button-primary', 'frm-button-primary' ); | |
| 4043 | + return button; | |
| 4044 | + } | |
| 4045 | + | |
| 4046 | + function getSecondaryButton() { | |
| 4047 | + var button = getButton(); | |
| 4048 | + button.classList.add( 'button-secondary', 'frm-button-secondary' ); | |
| 4049 | + return button; | |
| 4050 | + } | |
| 4051 | + | |
| 4052 | + function getButton() { | |
| 4053 | + var button = document.createElement( 'a' ); | |
| 4054 | + button.setAttribute( 'href', '#' ); | |
| 4055 | + button.classList.add( 'button' ); | |
| 4056 | + button.style.textDecoration = 'none'; | |
| 4057 | + return button; | |
| 4058 | + } | |
| 4059 | + | |
| 4060 | + function getSizeOfLayoutClass( className ) { | |
| 4061 | + switch ( className ) { | |
| 4062 | + case 'frm_half': | |
| 4063 | + return 6; | |
| 4064 | + case 'frm_third': | |
| 4065 | + return 4; | |
| 4066 | + case 'frm_two_thirds': | |
| 4067 | + return 8; | |
| 4068 | + case 'frm_fourth': | |
| 4069 | + return 3; | |
| 4070 | + case 'frm_three_fourths': | |
| 4071 | + return 9; | |
| 4072 | + case 'frm_sixth': | |
| 4073 | + return 2; | |
| 4074 | + } | |
| 4075 | + | |
| 4076 | + if ( 0 === className.indexOf( 'frm' ) ) { | |
| 4077 | + return parseInt( className.substr( 3 ) ); | |
| 4078 | + } | |
| 4079 | + | |
| 4080 | + // Anything missing a layout class should be a full width row. | |
| 4081 | + return 12; | |
| 4082 | + } | |
| 4083 | + | |
| 4084 | + function getLayoutClassName( classList ) { | |
| 4085 | + var classes, index, currentClass; | |
| 4086 | + classes = getLayoutClasses(); | |
| 4087 | + for ( index = 0; index < classes.length; ++index ) { | |
| 4088 | + currentClass = classes[ index ]; | |
| 4089 | + if ( classList.contains( currentClass ) ) { | |
| 4090 | + return currentClass; | |
| 4091 | + } | |
| 4092 | + } | |
| 4093 | + return ''; | |
| 4094 | + } | |
| 4095 | + | |
| 4096 | + function getLayoutClassForSize( size ) { | |
| 4097 | + return 'frm' + size; | |
| 4098 | + } | |
| 4099 | + | |
| 4100 | + function breakFieldGroupClick() { | |
| 4101 | + var row = document.querySelector( '.frm-field-group-hover-target' ); | |
| 4102 | + breakRow( row ); | |
| 4103 | + destroyFieldGroupPopup(); | |
| 4104 | + } | |
| 4105 | + | |
| 4106 | + function breakRow( row ) { | |
| 4107 | + const $row = jQuery( row ); | |
| 4108 | + getFieldsInRow( $row ).each( | |
| 4109 | + function( index ) { | |
| 4110 | + const field = this; | |
| 4111 | + if ( 0 !== index ) { | |
| 4112 | + $row.parent().after( wrapFieldLi( field ) ); | |
| 4113 | + } | |
| 4114 | + stripLayoutFromFields( jQuery( field ) ); | |
| 4115 | + } | |
| 4116 | + ); | |
| 4117 | + } | |
| 4118 | + | |
| 4119 | + function stripLayoutFromFields( field ) { | |
| 4120 | + syncLayoutClasses( field, 'clear' ); | |
| 4121 | + } | |
| 4122 | + | |
| 4123 | + function focusFieldGroupInputOnClick() { | |
| 4124 | + this.select(); | |
| 4125 | + } | |
| 4126 | + | |
| 4127 | + function cancelCustomFieldGroupClick() { | |
| 4128 | + revertToFieldGroupPopupFirstPage( this ); | |
| 4129 | + } | |
| 4130 | + | |
| 4131 | + function revertToFieldGroupPopupFirstPage( triggerElement ) { | |
| 4132 | + jQuery( document.getElementById( 'frm_field_group_popup' ) ).replaceWith( | |
| 4133 | + getFieldGroupPopup( getSizeOfFieldGroupFromChildElement( triggerElement ), triggerElement ) | |
| 4134 | + ); | |
| 4135 | + } | |
| 4136 | + | |
| 4137 | + function destroyFieldGroupPopup() { | |
| 4138 | + var popup, wrapper; | |
| 4139 | + popup = document.getElementById( 'frm_field_group_popup' ); | |
| 4140 | + if ( popup === null ) { | |
| 4141 | + return; | |
| 4142 | + } | |
| 4143 | + wrapper = document.querySelector( '.frm-has-open-field-group-popup' ); | |
| 4144 | + if ( null !== wrapper ) { | |
| 4145 | + wrapper.classList.remove( 'frm-has-open-field-group-popup' ); | |
| 4146 | + popup.parentNode.remove(); | |
| 4147 | + } | |
| 4148 | + jQuery( document ).off( 'click', '#frm_builder_page', destroyFieldGroupPopupOnOutsideClick ); | |
| 4149 | + } | |
| 4150 | + | |
| 4151 | + function saveCustomFieldGroupClick() { | |
| 4152 | + var syncDetails, $controls, $ul; | |
| 4153 | + | |
| 4154 | + syncDetails = []; | |
| 4155 | + | |
| 4156 | + jQuery( document.getElementById( 'frm_field_group_popup' ).querySelectorAll( '.frm_grid_container input' ) ) | |
| 4157 | + .each( | |
| 4158 | + function() { | |
| 4159 | + syncDetails.push( parseInt( this.value ) ); | |
| 4160 | + } | |
| 4161 | + ); | |
| 4162 | + | |
| 4163 | + $controls = jQuery( document.getElementById( 'frm_field_group_controls' ) ); | |
| 4164 | + | |
| 4165 | + if ( $controls.length && 'none' !== $controls.get( 0 ).style.display ) { | |
| 4166 | + syncLayoutClasses( getFieldsInRow( jQuery( document.querySelector( '.frm-field-group-hover-target' ) ) ).first(), syncDetails ); | |
| 4167 | + } else { | |
| 4168 | + $ul = mergeSelectedFieldGroups(); | |
| 4169 | + syncLayoutClasses( getFieldsInRow( $ul ).first(), syncDetails ); | |
| 4170 | + unselectFieldGroups(); | |
| 4171 | + } | |
| 4172 | + | |
| 4173 | + destroyFieldGroupPopup(); | |
| 4174 | + } | |
| 4175 | + | |
| 4176 | + function fieldGroupClick( e ) { | |
| 4177 | + if ( 'ul' !== e.originalEvent.target.nodeName.toLowerCase() ) { | |
| 4178 | + // only continue if the group itself was clicked / ignore when a field is clicked. | |
| 4179 | + return; | |
| 4180 | + } | |
| 4181 | + | |
| 4182 | + const hoverTarget = document.querySelector( '.frm-field-group-hover-target' ); | |
| 4183 | + if ( ! hoverTarget ) { | |
| 4184 | + return; | |
| 4185 | + } | |
| 4186 | + | |
| 4187 | + const ctrlOrCmdKeyIsDown = e.ctrlKey || e.metaKey; | |
| 4188 | + const shiftKeyIsDown = e.shiftKey; | |
| 4189 | + const groupIsActive = hoverTarget.classList.contains( 'frm-selected-field-group' ); | |
| 4190 | + const $selectedFieldGroups = getSelectedFieldGroups(); | |
| 4191 | + | |
| 4192 | + let numberOfSelectedGroups = $selectedFieldGroups.length; | |
| 4193 | + | |
| 4194 | + if ( ctrlOrCmdKeyIsDown || shiftKeyIsDown ) { | |
| 4195 | + // multi-selecting | |
| 4196 | + | |
| 4197 | + const selectedField = getSelectedField(); | |
| 4198 | + if ( null !== selectedField && ! jQuery( selectedField ).siblings( 'li.form-field' ).length ) { | |
| 4199 | + // count a selected field on its own as a selected field group when multiselecting. | |
| 4200 | + selectedField.parentNode.classList.add( 'frm-selected-field-group' ); | |
| 4201 | + ++numberOfSelectedGroups; | |
| 4202 | + } | |
| 4203 | + | |
| 4204 | + if ( ctrlOrCmdKeyIsDown ) { | |
| 4205 | + if ( groupIsActive ) { | |
| 4206 | + // unselect if holding ctrl or cmd and the group was already active. | |
| 4207 | + --numberOfSelectedGroups; | |
| 4208 | + hoverTarget.classList.remove( 'frm-selected-field-group' ); | |
| 4209 | + syncAfterMultiSelect( numberOfSelectedGroups ); | |
| 4210 | + return; // exit early to avoid adding back frm-selected-field-group | |
| 4211 | + } else { | |
| 4212 | + ++numberOfSelectedGroups; | |
| 4213 | + } | |
| 4214 | + } else if ( shiftKeyIsDown && ! groupIsActive ) { | |
| 4215 | + ++numberOfSelectedGroups; // include the one we're selecting right now. | |
| 4216 | + const $firstGroup = $selectedFieldGroups.first(); | |
| 4217 | + | |
| 4218 | + let $range; | |
| 4219 | + if ( $firstGroup.parent().index() < jQuery( hoverTarget.parentNode ).index() ) { | |
| 4220 | + $range = $firstGroup.parent().nextUntil( hoverTarget.parentNode ); | |
| 4221 | + } else { | |
| 4222 | + $range = $firstGroup.parent().prevUntil( hoverTarget.parentNode ); | |
| 4223 | + } | |
| 4224 | + | |
| 4225 | + $range.each( | |
| 4226 | + function() { | |
| 4227 | + var $fieldGroup = jQuery( this ).closest( 'li' ).find( 'ul.frm_sorting' ); | |
| 4228 | + if ( ! $fieldGroup.hasClass( 'frm-selected-field-group' ) ) { | |
| 4229 | + ++numberOfSelectedGroups; | |
| 4230 | + $fieldGroup.addClass( 'frm-selected-field-group' ); | |
| 4231 | + } | |
| 4232 | + } | |
| 4233 | + ); | |
| 4234 | + | |
| 4235 | + // when holding shift and clicking, text gets selected. unselect it. | |
| 4236 | + document.getSelection().removeAllRanges(); | |
| 4237 | + } | |
| 4238 | + } else { | |
| 4239 | + // not multi-selecting | |
| 4240 | + unselectFieldGroups(); | |
| 4241 | + numberOfSelectedGroups = 1; | |
| 4242 | + } | |
| 4243 | + | |
| 4244 | + hoverTarget.classList.add( 'frm-selected-field-group' ); | |
| 4245 | + syncAfterMultiSelect( numberOfSelectedGroups ); | |
| 4246 | + | |
| 4247 | + jQuery( document ).off( 'click', unselectFieldGroups ); | |
| 4248 | + jQuery( document ).on( 'click', unselectFieldGroups ); | |
| 4249 | + } | |
| 4250 | + | |
| 4251 | + function getSelectedField() { | |
| 4252 | + return document.getElementById( 'frm-show-fields' ).querySelector( 'li.form-field.selected' ); | |
| 4253 | + } | |
| 4254 | + | |
| 4255 | + function getSelectedFieldGroups() { | |
| 4256 | + const $fieldGroups = jQuery( '.frm-selected-field-group' ); | |
| 4257 | + if ( $fieldGroups.length ) { | |
| 4258 | + return $fieldGroups; | |
| 4259 | + } | |
| 4260 | + | |
| 4261 | + const selectedField = getSelectedField(); | |
| 4262 | + if ( selectedField ) { | |
| 4263 | + // If there is only one field in a group and the field is selected, consider the field's group as selected for multi-select. | |
| 4264 | + const selectedFieldGroup = selectedField.closest( 'ul' ); | |
| 4265 | + if ( selectedFieldGroup && 1 === getFieldsInRow( jQuery( selectedFieldGroup ) ).length ) { | |
| 4266 | + selectedFieldGroup.classList.add( 'frm-selected-field-group' ); | |
| 4267 | + return jQuery( selectedFieldGroup ); | |
| 4268 | + } | |
| 4269 | + } | |
| 4270 | + | |
| 4271 | + return jQuery(); | |
| 4272 | + } | |
| 4273 | + | |
| 4274 | + function syncAfterMultiSelect( numberOfSelectedGroups ) { | |
| 4275 | + clearSettingsBox( true ); // unselect any fields if one is selected. | |
| 4276 | + if ( numberOfSelectedGroups >= 2 || ( 1 === numberOfSelectedGroups && selectedGroupHasMultipleFields() ) ) { | |
| 4277 | + addFieldMultiselectPopup(); | |
| 4278 | + } else { | |
| 4279 | + maybeRemoveMultiselectPopup(); | |
| 4280 | + } | |
| 4281 | + maybeRemoveGroupHoverTarget(); | |
| 4282 | + } | |
| 4283 | + | |
| 4284 | + function selectedGroupHasMultipleFields() { | |
| 4285 | + return getFieldsInRow( jQuery( document.querySelector( '.frm-selected-field-group' ) ) ).length > 1; | |
| 4286 | + } | |
| 4287 | + | |
| 4288 | + function unselectFieldGroups( event ) { | |
| 4289 | + if ( 'undefined' !== typeof event ) { | |
| 4290 | + if ( null !== event.originalEvent.target.closest( '#frm-show-fields' ) ) { | |
| 4291 | + return; | |
| 4292 | + } | |
| 4293 | + if ( event.originalEvent.target.classList.contains( 'frm-merge-fields-into-row' ) ) { | |
| 4294 | + return; | |
| 4295 | + } | |
| 4296 | + if ( null !== event.originalEvent.target.closest( '.frm-merge-fields-into-row' ) ) { | |
| 4297 | + return; | |
| 4298 | + } | |
| 4299 | + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) { | |
| 4300 | + return; | |
| 4301 | + } | |
| 4302 | + if ( event.originalEvent.target.classList.contains( 'frm-cancel-custom-field-group-layout' ) ) { | |
| 4303 | + return; | |
| 4304 | + } | |
| 4305 | + } | |
| 4306 | + jQuery( '.frm-selected-field-group' ).removeClass( 'frm-selected-field-group' ); | |
| 4307 | + jQuery( document ).off( 'click', unselectFieldGroups ); | |
| 4308 | + maybeRemoveMultiselectPopup(); | |
| 4309 | + } | |
| 4310 | + | |
| 4311 | + function maybeRemoveMultiselectPopup() { | |
| 4312 | + var popup = document.getElementById( 'frm_field_multiselect_popup' ); | |
| 4313 | + if ( null !== popup ) { | |
| 4314 | + popup.remove(); | |
| 4315 | + } | |
| 4316 | + } | |
| 4317 | + | |
| 4318 | + function addFieldMultiselectPopup() { | |
| 4319 | + getFieldMultiselectPopup(); | |
| 4320 | + } | |
| 4321 | + | |
| 4322 | + function getFieldMultiselectPopup() { | |
| 4323 | + var popup, mergeOption, caret, verticalSeparator, deleteOption; | |
| 4324 | + | |
| 4325 | + popup = document.getElementById( 'frm_field_multiselect_popup' ); | |
| 4326 | + | |
| 4327 | + if ( null !== popup ) { | |
| 4328 | + popup.classList.toggle( 'frm-unmergable', ! selectedFieldsAreMergable() ); | |
| 4329 | + return popup; | |
| 4330 | + } | |
| 4331 | + | |
| 4332 | + popup = div(); | |
| 4333 | + popup.id = 'frm_field_multiselect_popup'; | |
| 4334 | + if ( ! selectedFieldsAreMergable() ) { | |
| 4335 | + popup.classList.add( 'frm-unmergable' ); | |
| 4336 | + } | |
| 4337 | + | |
| 4338 | + mergeOption = div(); | |
| 4339 | + mergeOption.classList.add( 'frm-merge-fields-into-row' ); | |
| 4340 | + mergeOption.textContent = __( 'Merge into row', 'formidable' ); | |
| 4341 | + | |
| 4342 | + caret = document.createElement( 'a' ); | |
| 4343 | + caret.style.marginLeft = '5px'; | |
| 4344 | + caret.classList.add( 'frm_icon_font', 'frm_arrowdown6_icon' ); | |
| 4345 | + caret.setAttribute( 'href', '#' ); | |
| 4346 | + mergeOption.appendChild( caret ); | |
| 4347 | + | |
| 4348 | + popup.appendChild( mergeOption ); | |
| 4349 | + | |
| 4350 | + verticalSeparator = div(); | |
| 4351 | + verticalSeparator.classList.add( 'frm-multiselect-popup-separator' ); | |
| 4352 | + popup.appendChild( verticalSeparator ); | |
| 4353 | + | |
| 4354 | + deleteOption = div(); | |
| 4355 | + deleteOption.classList.add( 'frm-delete-field-groups' ); | |
| 4356 | + deleteOption.appendChild( getIconClone( 'frm_trash_svg' ) ); | |
| 4357 | + popup.appendChild( deleteOption ); | |
| 4358 | + | |
| 4359 | + document.getElementById( 'post-body-content' ).appendChild( popup ); | |
| 4360 | + | |
| 4361 | + jQuery( popup ).hide().fadeIn(); | |
| 4362 | + | |
| 4363 | + return popup; | |
| 4364 | + } | |
| 4365 | + | |
| 4366 | + function selectedFieldsAreMergable() { | |
| 4367 | + var selectedFieldGroups, totalFieldCount, length, index, fieldGroup; | |
| 4368 | + selectedFieldGroups = document.querySelectorAll( '.frm-selected-field-group' ); | |
| 4369 | + length = selectedFieldGroups.length; | |
| 4370 | + if ( 1 === length ) { | |
| 4371 | + return false; | |
| 4372 | + } | |
| 4373 | + totalFieldCount = 0; | |
| 4374 | + for ( index = 0; index < length; ++index ) { | |
| 4375 | + fieldGroup = selectedFieldGroups[ index ]; | |
| 4376 | + if ( null !== fieldGroup.querySelector( '.edit_field_type_break, .edit_field_type_hidden' ) ) { | |
| 4377 | + return false; | |
| 4378 | + } | |
| 4379 | + totalFieldCount += getFieldsInRow( jQuery( fieldGroup ) ).length; | |
| 4380 | + if ( totalFieldCount > 6 ) { | |
| 4381 | + return false; | |
| 4382 | + } | |
| 4383 | + } | |
| 4384 | + return true; | |
| 4385 | + } | |
| 4386 | + | |
| 4387 | + function mergeFieldsIntoRowClick( event ) { | |
| 4388 | + var size, popup; | |
| 4389 | + | |
| 4390 | + if ( null !== event.originalEvent.target.closest( '#frm_field_group_popup' ) ) { | |
| 4391 | + // prevent clicks within the popup from triggering the button again. | |
| 4392 | + return; | |
| 4393 | + } | |
| 4394 | + | |
| 4395 | + if ( event.originalEvent.target.classList.contains( 'frm-custom-field-group-layout' ) ) { | |
| 4396 | + // avoid switching back to the first page when clicking the custom option nested inside of the merge option. | |
| 4397 | + return; | |
| 4398 | + } | |
| 4399 | + | |
| 4400 | + size = getSelectedFieldCount(); | |
| 4401 | + popup = getFieldGroupPopup( size, document.querySelector( '.frm-selected-field-group' ).firstChild ); | |
| 4402 | + this.appendChild( popup ); | |
| 4403 | + } | |
| 4404 | + | |
| 4405 | + function getSelectedFieldCount() { | |
| 4406 | + var count = 0; | |
| 4407 | + jQuery( document.querySelectorAll( '.frm-selected-field-group' ) ).each( | |
| 4408 | + function() { | |
| 4409 | + count += getFieldsInRow( jQuery( this ) ).length; | |
| 4410 | + } | |
| 4411 | + ); | |
| 4412 | + return count; | |
| 4413 | + } | |
| 4414 | + | |
| 4415 | + function deleteFieldGroupsClick() { | |
| 4416 | + var fieldIdsToDelete, deleteOnConfirm, multiselectPopup; | |
| 4417 | + | |
| 4418 | + fieldIdsToDelete = getSelectedFieldIds(); | |
| 4419 | + deleteOnConfirm = getDeleteSelectedFieldGroupsOnConfirmFunction( fieldIdsToDelete ); | |
| 4420 | + | |
| 4421 | + multiselectPopup = document.getElementById( 'frm_field_multiselect_popup' ); | |
| 4422 | + if ( null !== multiselectPopup ) { | |
| 4423 | + multiselectPopup.remove(); | |
| 4424 | + } | |
| 4425 | + | |
| 4426 | + /* translators: %1$s: Number of fields that are selected to be deleted. */ | |
| 4427 | + this.setAttribute( 'data-frmverify', __( 'Are you sure you want to delete these %1$s selected fields?', 'formidable' ).replace( '%1$s', fieldIdsToDelete.length ) ); | |
| 4428 | + confirmLinkClick( this ); | |
| 4429 | + | |
| 4430 | + jQuery( '#frm-confirmed-click' ).on( 'click', deleteOnConfirm ); | |
| 4431 | + jQuery( '#frm_confirm_modal' ).one( 'dialogclose', function() { | |
| 4432 | + jQuery( '#frm-confirmed-click' ).off( 'click', deleteOnConfirm ); | |
| 4433 | + }); | |
| 4434 | + } | |
| 4435 | + | |
| 4436 | + function getSelectedFieldIds() { | |
| 4437 | + var deleteFieldIds = []; | |
| 4438 | + jQuery( '.frm-selected-field-group > li.form-field' ) | |
| 4439 | + .each( | |
| 4440 | + function() { | |
| 4441 | + deleteFieldIds.push( this.dataset.fid ); | |
| 4442 | + } | |
| 4443 | + ); | |
| 4444 | + return deleteFieldIds; | |
| 4445 | + } | |
| 4446 | + | |
| 4447 | + function getDeleteSelectedFieldGroupsOnConfirmFunction( deleteFieldIds ) { | |
| 4448 | + return function( event ) { | |
| 4449 | + event.preventDefault(); | |
| 4450 | + deleteAllSelectedFieldGroups( deleteFieldIds ); | |
| 4451 | + }; | |
| 4452 | + } | |
| 4453 | + | |
| 4454 | + function deleteAllSelectedFieldGroups( deleteFieldIds ) { | |
| 4455 | + deleteFieldIds.forEach( | |
| 4456 | + function( fieldId ) { | |
| 4457 | + deleteFields( fieldId ); | |
| 4458 | + } | |
| 4459 | + ); | |
| 4460 | + } | |
| 4461 | + | |
| 4462 | + function deleteFieldConfirmed() { | |
| 4463 | + /*jshint validthis:true */ | |
| 4464 | + deleteFields( this.getAttribute( 'data-deletefield' ) ); | |
| 4465 | + } | |
| 4466 | + | |
| 4467 | + function deleteFields( fieldId ) { | |
| 4468 | + var field = jQuery( '#frm_field_id_' + fieldId ); | |
| 4469 | + | |
| 4470 | + deleteField( fieldId ); | |
| 4471 | + | |
| 4472 | + if ( field.hasClass( 'edit_field_type_divider' ) ) { | |
| 4473 | + field.find( 'li.frm_field_box' ).each( function() { | |
| 4474 | + //TODO: maybe delete only end section | |
| 4475 | + //if(n.hasClass('edit_field_type_end_divider')){ | |
| 4476 | + deleteField( this.getAttribute( 'data-fid' ) ); | |
| 4477 | + //} | |
| 4478 | + }); | |
| 4479 | + } | |
| 4480 | + toggleSectionHolder(); | |
| 4481 | + } | |
| 4482 | + | |
| 4483 | + function deleteField( fieldId ) { | |
| 4484 | + jQuery.ajax({ | |
| 4485 | + type: 'POST', | |
| 4486 | + url: ajaxurl, | |
| 4487 | + data: { | |
| 4488 | + action: 'frm_delete_field', | |
| 4489 | + field_id: fieldId, | |
| 4490 | + nonce: frmGlobal.nonce | |
| 4491 | + }, | |
| 4492 | + success: function() { | |
| 4493 | + var $thisField = jQuery( document.getElementById( 'frm_field_id_' + fieldId ) ), | |
| 4494 | + settings = jQuery( '#frm-single-settings-' + fieldId ); | |
| 4495 | + | |
| 4496 | + // Remove settings from sidebar. | |
| 4497 | + if ( settings.is( ':visible' ) ) { | |
| 4498 | + document.getElementById( 'frm_insert_fields_tab' ).click(); | |
| 4499 | + } | |
| 4500 | + settings.remove(); | |
| 4501 | + | |
| 4502 | + $thisField.fadeOut( 'slow', function() { | |
| 4503 | + var $section = $thisField.closest( '.start_divider' ), | |
| 4504 | + type = $thisField.data( 'type' ), | |
| 4505 | + $adjacentFields = $thisField.siblings( 'li.form-field' ), | |
| 4506 | + $liWrapper; | |
| 4507 | + | |
| 4508 | + if ( ! $adjacentFields.length ) { | |
| 4509 | + if ( $thisField.is( '.edit_field_type_end_divider' ) ) { | |
| 4510 | + $adjacentFields.length = $thisField.closest( 'li.form-field' ).siblings(); | |
| 4511 | + } else { | |
| 4512 | + $liWrapper = $thisField.closest( 'ul.frm_sorting' ).parent(); | |
| 4513 | + } | |
| 4514 | + } | |
| 4515 | + | |
| 4516 | + $thisField.remove(); | |
| 4517 | + if ( type === 'break' ) { | |
| 4518 | + renumberPageBreaks(); | |
| 4519 | + } | |
| 4520 | + if ( type === 'product' ) { | |
| 4521 | + maybeHideQuantityProductFieldOption(); | |
| 4522 | + // a product field attached to a quantity field earlier might be the one deleted, so re-populate | |
| 4523 | + popAllProductFields(); | |
| 4524 | + } | |
| 4525 | + if ( jQuery( '#frm-show-fields li' ).length === 0 ) { | |
| 4526 | + document.getElementById( 'frm_form_editor_container' ).classList.remove( 'frm-has-fields' ); | |
| 4527 | + } else if ( $section.length ) { | |
| 4528 | + toggleOneSectionHolder( $section ); | |
| 4529 | + } | |
| 4530 | + if ( $adjacentFields.length ) { | |
| 4531 | + syncLayoutClasses( $adjacentFields.first() ); | |
| 4532 | + } else { | |
| 4533 | + $liWrapper.remove(); | |
| 4534 | + } | |
| 4535 | + | |
| 4536 | + // prevent "More Options" tooltips from staying around after their target field is deleted. | |
| 4537 | + deleteTooltips(); | |
| 4538 | + }); | |
| 4539 | + } | |
| 4540 | + }); | |
| 4541 | + } | |
| 4542 | + | |
| 4543 | + function addFieldLogicRow() { | |
| 4544 | + /*jshint validthis:true */ | |
| 4545 | + var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 4546 | + formId = thisFormId, | |
| 4547 | + logicRows = document.getElementById( 'frm_logic_row_' + id ).querySelectorAll( '.frm_logic_row' ); | |
| 4548 | + jQuery.ajax({ | |
| 4549 | + type: 'POST', | |
| 4550 | + url: ajaxurl, | |
| 4551 | + data: { | |
| 4552 | + action: 'frm_add_logic_row', | |
| 4553 | + form_id: formId, | |
| 4554 | + field_id: id, | |
| 4555 | + nonce: frmGlobal.nonce, | |
| 4556 | + meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ), | |
| 4557 | + fields: getFieldList() | |
| 4558 | + }, | |
| 4559 | + success: function( html ) { | |
| 4560 | + jQuery( document.getElementById( 'logic_' + id ) ).fadeOut( 'slow', function() { | |
| 4561 | + var logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) ); | |
| 4562 | + logicRow.append( html ); | |
| 4563 | + logicRow.closest( '.frm_logic_rows' ).fadeIn( 'slow' ); | |
| 4564 | + }); | |
| 4565 | + } | |
| 4566 | + }); | |
| 4567 | + return false; | |
| 4568 | + } | |
| 4569 | + | |
| 4570 | + function getNewRowId( rows, replace, defaultValue ) { | |
| 4571 | + if ( ! rows.length ) { | |
| 4572 | + return 'undefined' !== typeof defaultValue ? defaultValue : 0; | |
| 4573 | + } | |
| 4574 | + return parseInt( rows[ rows.length - 1 ].id.replace( replace, '' ), 10 ) + 1; | |
| 4575 | + } | |
| 4576 | + | |
| 4577 | + function addWatchLookupRow() { | |
| 4578 | + /*jshint validthis:true */ | |
| 4579 | + var lastRowId, | |
| 4580 | + id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ), | |
| 4581 | + formId = thisFormId, | |
| 4582 | + lookupBlockRows = document.getElementById( 'frm_watch_lookup_block_' + id ).children; | |
| 4583 | + jQuery.ajax({ | |
| 4584 | + type: 'POST', | |
| 4585 | + url: ajaxurl, | |
| 4586 | + data: { | |
| 4587 | + action: 'frm_add_watch_lookup_row', | |
| 4588 | + form_id: formId, | |
| 4589 | + field_id: id, | |
| 4590 | + row_key: getNewRowId( lookupBlockRows, 'frm_watch_lookup_' + id + '_' ), | |
| 4591 | + nonce: frmGlobal.nonce | |
| 4592 | + }, | |
| 4593 | + success: function( newRow ) { | |
| 4594 | + var watchRowBlock = jQuery( document.getElementById( 'frm_watch_lookup_block_' + id ) ); | |
| 4595 | + watchRowBlock.append( newRow ); | |
| 4596 | + watchRowBlock.fadeIn( 'slow' ); | |
| 4597 | + } | |
| 4598 | + }); | |
| 4599 | + return false; | |
| 4600 | + } | |
| 4601 | + | |
| 4602 | + function resetOptionTextDetails() { | |
| 4603 | + jQuery( '.frm-single-settings ul input[type="text"][name^="field_options[options_"]' ).filter( '[data-value-on-load]' ).removeAttr( 'data-value-on-load' ); | |
| 4604 | + jQuery( 'input[type="hidden"][name^=optionmap]' ).remove(); | |
| 4605 | + } | |
| 4606 | + | |
| 4607 | + function optionTextAlreadyExists( input ) { | |
| 4608 | + var fieldId = jQuery( input ).closest( '.frm-single-settings' ).attr( 'data-fid' ), | |
| 4609 | + optionInputs = jQuery( input ).closest( 'ul' ).get( 0 ).querySelectorAll( '.field_' + fieldId + '_option' ), | |
| 4610 | + index, | |
| 4611 | + optionInput; | |
| 4612 | + | |
| 4613 | + for ( index in optionInputs ) { | |
| 4614 | + optionInput = optionInputs[ index ]; | |
| 4615 | + if ( optionInput.id !== input.id && optionInput.value === input.value && optionInput.getAttribute( 'data-duplicate' ) !== 'true' ) { | |
| 4616 | + return true; | |
| 4617 | + } | |
| 4618 | + } | |
| 4619 | + | |
| 4620 | + return false; | |
| 4621 | + } | |
| 4622 | + | |
| 4623 | + function onOptionTextFocus() { | |
| 4624 | + var input, | |
| 4625 | + fieldId; | |
| 4626 | + | |
| 4627 | + if ( this.getAttribute( 'data-value-on-load' ) === null ) { | |
| 4628 | + this.setAttribute( 'data-value-on-load', this.value ); | |
| 4629 | + | |
| 4630 | + fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' ); | |
| 4631 | + input = document.createElement( 'input' ); | |
| 4632 | + input.value = this.value; | |
| 4633 | + input.setAttribute( 'type', 'hidden' ); | |
| 4634 | + input.setAttribute( 'name', 'optionmap[' + fieldId + '][' + this.value + ']' ); | |
| 4635 | + this.parentNode.appendChild( input ); | |
| 4636 | + | |
| 4637 | + if ( typeof optionMap[ fieldId ] === 'undefined' ) { | |
| 4638 | + optionMap[ fieldId ] = {}; | |
| 4639 | + } | |
| 4640 | + | |
| 4641 | + optionMap[ fieldId ][ this.value ] = input; | |
| 4642 | + } | |
| 4643 | + | |
| 4644 | + if ( this.getAttribute( 'data-duplicate' ) === 'true' ) { | |
| 4645 | + this.removeAttribute( 'data-duplicate' ); | |
| 4646 | + | |
| 4647 | + // we want to use original value if actually still a duplicate | |
| 4648 | + if ( optionTextAlreadyExists( this ) ) { | |
| 4649 | + this.setAttribute( 'data-value-on-focus', this.getAttribute( 'data-value-on-load' ) ); | |
| 4650 | + return; | |
| 4651 | + } | |
| 4652 | + } | |
| 4653 | + | |
| 4654 | + if ( '' !== this.value || frm_admin_js.new_option !== this.getAttribute( 'data-value-on-focus' ) ) { | |
| 4655 | + this.setAttribute( 'data-value-on-focus', this.value ); | |
| 4656 | + } | |
| 4657 | + } | |
| 4658 | + | |
| 4659 | + function onOptionTextBlur() { | |
| 4660 | + var originalValue, | |
| 4661 | + oldValue = this.getAttribute( 'data-value-on-focus' ), | |
| 4662 | + newValue = this.value, | |
| 4663 | + fieldId, | |
| 4664 | + fieldIndex, | |
| 4665 | + logicId, | |
| 4666 | + row, | |
| 4667 | + rowLength, | |
| 4668 | + rowIndex, | |
| 4669 | + valueSelect, | |
| 4670 | + opts, | |
| 4671 | + fieldIds, | |
| 4672 | + settingId, | |
| 4673 | + setting, | |
| 4674 | + optionMatches, | |
| 4675 | + option; | |
| 4676 | + | |
| 4677 | + if ( oldValue === newValue ) { | |
| 4678 | + return; | |
| 4679 | + } | |
| 4680 | + | |
| 4681 | + fieldId = jQuery( this ).closest( '.frm-single-settings' ).attr( 'data-fid' ); | |
| 4682 | + originalValue = this.getAttribute( 'data-value-on-load' ); | |
| 4683 | + | |
| 4684 | + // check if the newValue is already mapped to another option | |
| 4685 | + // if it is, mark as duplicate and return | |
| 4686 | + if ( optionTextAlreadyExists( this ) ) { | |
| 4687 | + this.setAttribute( 'data-duplicate', 'true' ); | |
| 4688 | + | |
| 4689 | + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) { | |
| 4690 | + // unmap any other change that may have happened before instead of changing it to something unused | |
| 4691 | + optionMap[ fieldId ][ originalValue ].value = originalValue; | |
| 4692 | + } | |
| 4693 | + | |
| 4694 | + return; | |
| 4695 | + } | |
| 4696 | + | |
| 4697 | + if ( typeof optionMap[ fieldId ] !== 'undefined' && typeof optionMap[ fieldId ][ originalValue ] !== 'undefined' ) { | |
| 4698 | + optionMap[ fieldId ][ originalValue ].value = newValue; | |
| 4699 | + } | |
| 4700 | + | |
| 4701 | + fieldIds = []; | |
| 4702 | + rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ); | |
| 4703 | + rowLength = rows.length; | |
| 4704 | + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) { | |
| 4705 | + row = rows[ rowIndex ]; | |
| 4706 | + opts = row.querySelector( '.frm_logic_field_opts' ); | |
| 4707 | + | |
| 4708 | + if ( opts.value !== fieldId ) { | |
| 4709 | + continue; | |
| 4710 | + } | |
| 4711 | + | |
| 4712 | + logicId = row.id.split( '_' )[ 2 ]; | |
| 4713 | + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' ); | |
| 4714 | + | |
| 4715 | + if ( '' === oldValue ) { | |
| 4716 | + optionMatches = []; | |
| 4717 | + } else { | |
| 4718 | + optionMatches = valueSelect.querySelectorAll( 'option[value="' + oldValue + '"]' ); | |
| 4719 | + } | |
| 4720 | + | |
| 4721 | + if ( ! optionMatches.length ) { | |
| 4722 | + optionMatches = valueSelect.querySelectorAll( 'option[value="' + newValue + '"]' ); | |
| 4723 | + | |
| 4724 | + if ( ! optionMatches.length ) { | |
| 4725 | + option = document.createElement( 'option' ); | |
| 4726 | + valueSelect.appendChild( option ); | |
| 4727 | + } | |
| 4728 | + } | |
| 4729 | + | |
| 4730 | + if ( optionMatches.length ) { | |
| 4731 | + option = optionMatches[ optionMatches.length - 1 ]; | |
| 4732 | + } | |
| 4733 | + | |
| 4734 | + option.setAttribute( 'value', newValue ); | |
| 4735 | + option.textContent = newValue; | |
| 4736 | + | |
| 4737 | + if ( fieldIds.indexOf( logicId ) === -1 ) { | |
| 4738 | + fieldIds.push( logicId ); | |
| 4739 | + } | |
| 4740 | + } | |
| 4741 | + | |
| 4742 | + for ( fieldIndex in fieldIds ) { | |
| 4743 | + settingId = fieldIds[ fieldIndex ]; | |
| 4744 | + setting = document.getElementById( 'frm-single-settings-' + settingId ); | |
| 4745 | + moveFieldSettings( setting ); | |
| 4746 | + } | |
| 4747 | + } | |
| 4748 | + | |
| 4749 | + function updateGetValueFieldSelection() { | |
| 4750 | + /*jshint validthis:true */ | |
| 4751 | + var fieldID = this.id.replace( 'get_values_form_', '' ); | |
| 4752 | + var fieldSelect = document.getElementById( 'get_values_field_' + fieldID ); | |
| 4753 | + var fieldType = this.getAttribute( 'data-fieldtype' ); | |
| 4754 | + | |
| 4755 | + if ( this.value === '' ) { | |
| 4756 | + fieldSelect.options.length = 1; | |
| 4757 | + } else { | |
| 4758 | + var formID = this.value; | |
| 4759 | + jQuery.ajax({ | |
| 4760 | + type: 'POST', url: ajaxurl, | |
| 4761 | + data: { | |
| 4762 | + action: 'frm_get_options_for_get_values_field', | |
| 4763 | + form_id: formID, | |
| 4764 | + field_type: fieldType, | |
| 4765 | + nonce: frmGlobal.nonce | |
| 4766 | + }, | |
| 4767 | + success: function( fields ) { | |
| 4768 | + fieldSelect.innerHTML = fields; | |
| 4769 | + } | |
| 4770 | + }); | |
| 4771 | + } | |
| 4772 | + } | |
| 4773 | + | |
| 4774 | + // Clear the Watch Fields option when Lookup field switches to "Text" option | |
| 4775 | + function maybeClearWatchFields() { | |
| 4776 | + /*jshint validthis:true */ | |
| 4777 | + var link, lookupBlock, | |
| 4778 | + fieldID = this.name.replace( 'field_options[data_type_', '' ).replace( ']', '' ); | |
| 4779 | + | |
| 4780 | + link = document.getElementById( 'frm_add_watch_lookup_link_' + fieldID ).parentNode; | |
| 4781 | + | |
| 4782 | + if ( this.value === 'text' ) { | |
| 4783 | + lookupBlock = document.getElementById( 'frm_watch_lookup_block_' + fieldID ); | |
| 4784 | + if ( lookupBlock !== null ) { | |
| 4785 | + // Clear and hide the Watch Fields option | |
| 4786 | + lookupBlock.innerHTML = ''; | |
| 4787 | + link.classList.add( 'frm_hidden' ); | |
| 4788 | + | |
| 4789 | + // Hide the Watch Fields row | |
| 4790 | + link.previousElementSibling.style.display = 'none'; | |
| 4791 | + link.previousElementSibling.previousElementSibling.style.display = 'none'; | |
| 4792 | + link.previousElementSibling.previousElementSibling.previousElementSibling.style.display = 'none'; | |
| 4793 | + } | |
| 4794 | + } else { | |
| 4795 | + // Show the Watch Fields option | |
| 4796 | + link.classList.remove( 'frm_hidden' ); | |
| 4797 | + } | |
| 4798 | + | |
| 4799 | + toggleMultiSelect( fieldID, this.value ); | |
| 4800 | + } | |
| 4801 | + | |
| 4802 | + // Number the pages and hide/show the first page as needed. | |
| 4803 | + function renumberPageBreaks() { | |
| 4804 | + var i, containerClass, | |
| 4805 | + pages = document.getElementsByClassName( 'frm-page-num' ); | |
| 4806 | + | |
| 4807 | + if ( pages.length > 1 ) { | |
| 4808 | + document.getElementById( 'frm-fake-page' ).style.display = 'block'; | |
| 4809 | + for ( i = 0; i < pages.length; i++ ) { | |
| 4810 | + containerClass = pages[i].parentNode.parentNode.parentNode.classList; | |
| 4811 | + if ( i === 1 ) { | |
| 4812 | + // Hide previous button on page 1 | |
| 4813 | + containerClass.add( 'frm-first-page' ); | |
| 4814 | + } else { | |
| 4815 | + containerClass.remove( 'frm-first-page' ); | |
| 4816 | + } | |
| 4817 | + pages[i].innerHTML = ( i + 1 ); | |
| 4818 | + } | |
| 4819 | + } else { | |
| 4820 | + document.getElementById( 'frm-fake-page' ).style.display = 'none'; | |
| 4821 | + } | |
| 4822 | + } | |
| 4823 | + | |
| 4824 | + // The fake field works differently than real fields. | |
| 4825 | + function maybeCollapsePage() { | |
| 4826 | + /*jshint validthis:true */ | |
| 4827 | + var field = jQuery( this ).closest( '.frm_field_box[data-ftype=break]' ); | |
| 4828 | + if ( field.length ) { | |
| 4829 | + toggleCollapsePage( field ); | |
| 4830 | + } else { | |
| 4831 | + toggleCollapseFakePage(); | |
| 4832 | + } | |
| 4833 | + } | |
| 4834 | + | |
| 4835 | + // Find all fields in a page and hide/show them | |
| 4836 | + function toggleCollapsePage( field ) { | |
| 4837 | + var toCollapse = getAllFieldsForPage( field.get( 0 ).parentNode.closest( 'li.frm_field_box' ).nextElementSibling ); | |
| 4838 | + togglePage( field, toCollapse ); | |
| 4839 | + } | |
| 4840 | + | |
| 4841 | + function toggleCollapseFakePage() { | |
| 4842 | + var topLevel = document.getElementById( 'frm-fake-page' ), | |
| 4843 | + firstField = document.getElementById( 'frm-show-fields' ).firstElementChild, | |
| 4844 | + toCollapse = getAllFieldsForPage( firstField ); | |
| 4845 | + | |
| 4846 | + if ( firstField.getAttribute( 'data-ftype' ) === 'break' ) { | |
| 4847 | + // Don't collapse if the first field is a page break. | |
| 4848 | + return; | |
| 4849 | + } | |
| 4850 | + | |
| 4851 | + togglePage( jQuery( topLevel ), toCollapse ); | |
| 4852 | + } | |
| 4853 | + | |
| 4854 | + function getAllFieldsForPage( firstWrapper ) { | |
| 4855 | + var $fieldsForPage, currentWrapper; | |
| 4856 | + | |
| 4857 | + $fieldsForPage = jQuery(); | |
| 4858 | + | |
| 4859 | + if ( null === firstWrapper ) { | |
| 4860 | + return $fieldsForPage; | |
| 4861 | + } | |
| 4862 | + | |
| 4863 | + currentWrapper = firstWrapper; | |
| 4864 | + | |
| 4865 | + do { | |
| 4866 | + if ( null !== currentWrapper.querySelector( '.edit_field_type_break' ) ) { | |
| 4867 | + break; | |
| 4868 | + } | |
| 4869 | + $fieldsForPage = $fieldsForPage.add( jQuery( currentWrapper ) ); | |
| 4870 | + currentWrapper = currentWrapper.nextElementSibling; | |
| 4871 | + } while ( null !== currentWrapper ); | |
| 4872 | + | |
| 4873 | + return $fieldsForPage; | |
| 4874 | + } | |
| 4875 | + | |
| 4876 | + function togglePage( field, toCollapse ) { | |
| 4877 | + var i, | |
| 4878 | + fieldCount = toCollapse.length, | |
| 4879 | + slide = Math.min( fieldCount, 3 ); | |
| 4880 | + | |
| 4881 | + if ( field.hasClass( 'frm-page-collapsed' ) ) { | |
| 4882 | + field.removeClass( 'frm-page-collapsed' ); | |
| 4883 | + toCollapse.removeClass( 'frm-is-collapsed' ); | |
| 4884 | + for ( i = 0; i < slide; i++ ) { | |
| 4885 | + if ( i === slide - 1 ) { | |
| 4886 | + jQuery( toCollapse[ i ]).slideDown( 150, function() { | |
| 4887 | + toCollapse.show(); | |
| 4888 | + }); | |
| 4889 | + } else { | |
| 4890 | + jQuery( toCollapse[ i ]).slideDown( 150 ); | |
| 4891 | + } | |
| 4892 | + } | |
| 4893 | + } else { | |
| 4894 | + field.addClass( 'frm-page-collapsed' ); | |
| 4895 | + toCollapse.addClass( 'frm-is-collapsed' ); | |
| 4896 | + for ( i = 0; i < slide; i++ ) { | |
| 4897 | + if ( i === slide - 1 ) { | |
| 4898 | + jQuery( toCollapse[ i ]).slideUp( 150, function() { | |
| 4899 | + toCollapse.css( 'cssText', 'display:none !important;' ); | |
| 4900 | + }); | |
| 4901 | + } else { | |
| 4902 | + jQuery( toCollapse[ i ]).slideUp( 150 ); | |
| 4903 | + } | |
| 4904 | + } | |
| 4905 | + } | |
| 4906 | + } | |
| 4907 | + | |
| 4908 | + function maybeCollapseSection() { | |
| 4909 | + /*jshint validthis:true */ | |
| 4910 | + var parentCont = this.parentNode.parentNode.parentNode.parentNode; | |
| 4911 | + | |
| 4912 | + parentCont.classList.toggle( 'frm-section-collapsed' ); | |
| 4913 | + } | |
| 4914 | + | |
| 4915 | + function maybeCollapseSettings() { | |
| 4916 | + /*jshint validthis:true */ | |
| 4917 | + this.classList.toggle( 'frm-collapsed' ); | |
| 4918 | + } | |
| 4919 | + | |
| 4920 | + function clickLabel() { | |
| 4921 | + if ( ! this.id ) { | |
| 4922 | + return; | |
| 4923 | + } | |
| 4924 | + | |
| 4925 | + /*jshint validthis:true */ | |
| 4926 | + var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0], | |
| 4927 | + fieldId = this.id.replace( 'field_label_', '' ), | |
| 4928 | + fieldType = document.getElementById( 'field_options_type_' + fieldId ), | |
| 4929 | + fieldTypeName = fieldType.value; | |
| 4930 | + | |
| 4931 | + if ( typeof setting !== 'undefined' ) { | |
| 4932 | + if ( fieldType.tagName === 'SELECT' ) { | |
| 4933 | + fieldTypeName = fieldType.options[ fieldType.selectedIndex ].text.toLowerCase(); | |
| 4934 | + } else { | |
| 4935 | + fieldTypeName = fieldTypeName.replace( '_', ' ' ); | |
| 4936 | + } | |
| 4937 | + | |
| 4938 | + fieldTypeName = normalizeFieldName( fieldTypeName ); | |
| 4939 | + | |
| 4940 | + setTimeout( function() { | |
| 4941 | + if ( setting.value.toLowerCase() === fieldTypeName ) { | |
| 4942 | + setting.select(); | |
| 4943 | + } else { | |
| 4944 | + setting.focus(); | |
| 4945 | + } | |
| 4946 | + }, 50 ); | |
| 4947 | + } | |
| 4948 | + } | |
| 4949 | + | |
| 4950 | + function clickDescription() { | |
| 4951 | + /*jshint validthis:true */ | |
| 4952 | + var setting = document.querySelectorAll( '[data-changeme="' + this.id + '"]' )[0]; | |
| 4953 | + if ( typeof setting !== 'undefined' ) { | |
| 4954 | + setTimeout( function() { | |
| 4955 | + setting.focus(); | |
| 4956 | + autoExpandSettings( setting ); | |
| 4957 | + }, 50 ); | |
| 4958 | + } | |
| 4959 | + } | |
| 4960 | + | |
| 4961 | + function autoExpandSettings( setting ) { | |
| 4962 | + var inSection = setting.closest( '.frm-collapse-me' ); | |
| 4963 | + if ( inSection !== null ) { | |
| 4964 | + inSection.previousElementSibling.classList.remove( 'frm-collapsed' ); | |
| 4965 | + } | |
| 4966 | + } | |
| 4967 | + | |
| 4968 | + function normalizeFieldName( fieldTypeName ) { | |
| 4969 | + if ( fieldTypeName === 'divider' ) { | |
| 4970 | + fieldTypeName = 'section'; | |
| 4971 | + } else if ( fieldTypeName === 'range' ) { | |
| 4972 | + fieldTypeName = 'slider'; | |
| 4973 | + } else if ( fieldTypeName === 'data' ) { | |
| 4974 | + fieldTypeName = 'dynamic'; | |
| 4975 | + } else if ( fieldTypeName === 'form' ) { | |
| 4976 | + fieldTypeName = 'embed form'; | |
| 4977 | + } | |
| 4978 | + return fieldTypeName; | |
| 4979 | + } | |
| 4980 | + | |
| 4981 | + function clickVis( e ) { | |
| 4982 | + /*jshint validthis:true */ | |
| 4983 | + var currentClass, originalList; | |
| 4984 | + | |
| 4985 | + currentClass = e.target.classList; | |
| 4986 | + | |
| 4987 | + if ( currentClass.contains( 'frm-collapse-page' ) || currentClass.contains( 'frm-sub-label' ) || e.target.closest( '.dropdown' ) !== null ) { | |
| 4988 | + return; | |
| 4989 | + } | |
| 4990 | + | |
| 4991 | + if ( this.closest( '.start_divider' ) !== null ) { | |
| 4992 | + e.stopPropagation(); | |
| 4993 | + } | |
| 4994 | + | |
| 4995 | + if ( this.classList.contains( 'edit_field_type_divider' ) ) { | |
| 4996 | + originalList = e.originalEvent.target.closest( 'ul.frm_sorting' ); | |
| 4997 | + if ( null !== originalList ) { | |
| 4998 | + // prevent section click if clicking a field group within a section. | |
| 4999 | + if ( originalList.classList.contains( 'edit_field_type_divider' ) || originalList.parentNode.parentNode.classList.contains( 'start_divider' ) ) { | |
| 5000 | + return; | |
| 5001 | + } | |
| 5002 | + } | |
| 5003 | + } | |
| 5004 | + | |
| 5005 | + clickAction( this ); | |
| 5006 | + } | |
| 5007 | + | |
| 5008 | + /** | |
| 5009 | + * Open Advanced settings on double click. | |
| 5010 | + */ | |
| 5011 | + function openAdvanced() { | |
| 5012 | + var fieldId = this.getAttribute( 'data-fid' ); | |
| 5013 | + autoExpandSettings( document.getElementById( 'field_options_field_key_' + fieldId ) ); | |
| 5014 | + } | |
| 5015 | + | |
| 5016 | + function toggleRepeatButtons() { | |
| 5017 | + /*jshint validthis:true */ | |
| 5018 | + var $thisField = jQuery( this ).closest( '.frm_field_box' ); | |
| 5019 | + $thisField.find( '.repeat_icon_links' ).removeClass( 'repeat_format repeat_formatboth repeat_formattext' ).addClass( 'repeat_format' + this.value ); | |
| 5020 | + if ( this.value === 'text' || this.value === 'both' ) { | |
| 5021 | + $thisField.find( '.frm_repeat_text' ).show(); | |
| 5022 | + $thisField.find( '.repeat_icon_links a' ).addClass( 'frm_button' ); | |
| 5023 | + } else { | |
| 5024 | + $thisField.find( '.frm_repeat_text' ).hide(); | |
| 5025 | + $thisField.find( '.repeat_icon_links a' ).removeClass( 'frm_button' ); | |
| 5026 | + } | |
| 5027 | + } | |
| 5028 | + | |
| 5029 | + function checkRepeatLimit() { | |
| 5030 | + /*jshint validthis:true */ | |
| 5031 | + var val = this.value; | |
| 5032 | + if ( val !== '' && ( val < 2 || val > 200 ) ) { | |
| 5033 | + infoModal( frm_admin_js.repeat_limit_min ); | |
| 5034 | + this.value = ''; | |
| 5035 | + } | |
| 5036 | + } | |
| 5037 | + | |
| 5038 | + function checkCheckboxSelectionsLimit() { | |
| 5039 | + /*jshint validthis:true */ | |
| 5040 | + var val = this.value; | |
| 5041 | + if ( val !== '' && ( val < 1 || val > 200 ) ) { | |
| 5042 | + infoModal( frm_admin_js.checkbox_limit ); | |
| 5043 | + this.value = ''; | |
| 5044 | + } | |
| 5045 | + } | |
| 5046 | + | |
| 5047 | + function updateRepeatText( obj, addRemove ) { | |
| 5048 | + var $thisField = jQuery( obj ).closest( '.frm_field_box' ); | |
| 5049 | + $thisField.find( '.frm_' + addRemove + '_form_row .frm_repeat_label' ).text( obj.value ); | |
| 5050 | + } | |
| 5051 | + | |
| 5052 | + function fieldsInSection( id ) { | |
| 5053 | + var children = []; | |
| 5054 | + jQuery( document.getElementById( 'frm_field_id_' + id ) ).find( 'li.frm_field_box:not(.no_repeat_section .edit_field_type_end_divider)' ).each( function() { | |
| 5055 | + children.push( jQuery( this ).data( 'fid' ) ); | |
| 5056 | + }); | |
| 5057 | + return children; | |
| 5058 | + } | |
| 5059 | + | |
| 5060 | + function toggleFormTax() { | |
| 5061 | + /*jshint validthis:true */ | |
| 5062 | + var id = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 5063 | + var val = this.value; | |
| 5064 | + var $showFields = document.getElementById( 'frm_show_selected_fields_' + id ); | |
| 5065 | + var $showForms = document.getElementById( 'frm_show_selected_forms_' + id ); | |
| 5066 | + | |
| 5067 | + jQuery( $showForms ).find( 'select' ).val( '' ); | |
| 5068 | + if ( val === 'form' ) { | |
| 5069 | + $showForms.style.display = 'inline'; | |
| 5070 | + empty( $showFields ); | |
| 5071 | + } else { | |
| 5072 | + $showFields.style.display = 'none'; | |
| 5073 | + $showForms.style.display = 'none'; | |
| 5074 | + getTaxOrFieldSelection( val, id ); | |
| 5075 | + } | |
| 5076 | + | |
| 5077 | + } | |
| 5078 | + | |
| 5079 | + function resetOptOnChange() { | |
| 5080 | + /*jshint validthis:true */ | |
| 5081 | + var field, thisOpt; | |
| 5082 | + | |
| 5083 | + field = getFieldKeyFromOpt( this ); | |
| 5084 | + if ( ! field ) { | |
| 5085 | + return; | |
| 5086 | + } | |
| 5087 | + | |
| 5088 | + thisOpt = jQuery( this ).closest( '.frm_single_option' ); | |
| 5089 | + | |
| 5090 | + resetSingleOpt( field.fieldId, field.fieldKey, thisOpt ); | |
| 5091 | + } | |
| 5092 | + | |
| 5093 | + function getFieldKeyFromOpt( object ) { | |
| 5094 | + var allOpts, fieldId, fieldKey; | |
| 5095 | + | |
| 5096 | + allOpts = jQuery( object ).closest( '.frm_sortable_field_opts' ); | |
| 5097 | + if ( ! allOpts.length ) { | |
| 5098 | + return false; | |
| 5099 | + } | |
| 5100 | + | |
| 5101 | + fieldId = allOpts.attr( 'id' ).replace( 'frm_field_', '' ).replace( '_opts', '' ); | |
| 5102 | + fieldKey = allOpts.data( 'key' ); | |
| 5103 | + | |
| 5104 | + return { | |
| 5105 | + fieldId: fieldId, | |
| 5106 | + fieldKey: fieldKey | |
| 5107 | + }; | |
| 5108 | + } | |
| 5109 | + | |
| 5110 | + function resetSingleOpt( fieldId, fieldKey, thisOpt ) { | |
| 5111 | + var saved, text, defaultVal, previewInput, labelForDisplay, optContainer, | |
| 5112 | + optKey = thisOpt.data( 'optkey' ), | |
| 5113 | + separateValues = usingSeparateValues( fieldId ), | |
| 5114 | + single = jQuery( 'label[for="field_' + fieldKey + '-' + optKey + '"]' ), | |
| 5115 | + baseName = 'field_options[options_' + fieldId + '][' + optKey + ']', | |
| 5116 | + label = jQuery( 'input[name="' + baseName + '[label]"]' ); | |
| 5117 | + | |
| 5118 | + if ( single.length < 1 ) { | |
| 5119 | + resetDisplayedOpts( fieldId ); | |
| 5120 | + | |
| 5121 | + // Set the default value. | |
| 5122 | + defaultVal = thisOpt.find( 'input[name^="default_value_"]' ); | |
| 5123 | + if ( defaultVal.is( ':checked' ) && label.length > 0 ) { | |
| 5124 | + jQuery( 'select[name^="item_meta[' + fieldId + ']"]' ).val( label.val() ); | |
| 5125 | + } | |
| 5126 | + return; | |
| 5127 | + } | |
| 5128 | + | |
| 5129 | + previewInput = single.children( 'input' ); | |
| 5130 | + | |
| 5131 | + if ( label.length < 1 ) { | |
| 5132 | + // Check for other label. | |
| 5133 | + label = jQuery( 'input[name="' + baseName + '"]' ); | |
| 5134 | + saved = label.val(); | |
| 5135 | + } else if ( separateValues ) { | |
| 5136 | + saved = jQuery( 'input[name="' + baseName + '[value]"]' ).val(); | |
| 5137 | + } else { | |
| 5138 | + saved = label.val(); | |
| 5139 | + } | |
| 5140 | + | |
| 5141 | + if ( label.length < 1 ) { | |
| 5142 | + return; | |
| 5143 | + } | |
| 5144 | + | |
| 5145 | + // Set the displayed value. | |
| 5146 | + text = single[0].childNodes; | |
| 5147 | + | |
| 5148 | + if ( imagesAsOptions( fieldId ) ) { | |
| 5149 | + labelForDisplay = getImageDisplayValue( thisOpt, fieldId, label ); | |
| 5150 | + optContainer = single.find( '.frm_image_option_container' ); | |
| 5151 | + | |
| 5152 | + if ( optContainer.length > 0 ) { | |
| 5153 | + optContainer.replaceWith( labelForDisplay ); | |
| 5154 | + } else { | |
| 5155 | + text[ text.length - 1 ].nodeValue = ''; | |
| 5156 | + single.append( labelForDisplay ); | |
| 5157 | + } | |
| 5158 | + } else { | |
| 5159 | + text[ text.length - 1 ].nodeValue = ' ' + label.val(); | |
| 5160 | + } | |
| 5161 | + | |
| 5162 | + // Set saved value. | |
| 5163 | + previewInput.val( saved ); | |
| 5164 | + | |
| 5165 | + // Set the default value. | |
| 5166 | + defaultVal = thisOpt.find( 'input[name^="default_value_"]' ); | |
| 5167 | + previewInput.prop( 'checked', defaultVal.is( ':checked' ) ? true : false ); | |
| 5168 | + } | |
| 5169 | + | |
| 5170 | + /** | |
| 5171 | + * Set the displayed value for an image option. | |
| 5172 | + */ | |
| 5173 | + function getImageDisplayValue( thisOpt, fieldId, label ) { | |
| 5174 | + var image, imageUrl, showLabelWithImage, fieldType; | |
| 5175 | + | |
| 5176 | + image = thisOpt.find( 'img' ); | |
| 5177 | + if ( image ) { | |
| 5178 | + imageUrl = image.attr( 'src' ); | |
| 5179 | + } | |
| 5180 | + | |
| 5181 | + showLabelWithImage = showingLabelWithImage( fieldId ); | |
| 5182 | + fieldType = radioOrCheckbox( fieldId ); | |
| 5183 | + return getImageLabel( label.val(), showLabelWithImage, imageUrl, fieldType ); | |
| 5184 | + } | |
| 5185 | + | |
| 5186 | + function getImageOptionSize( fieldId ) { | |
| 5187 | + var val, | |
| 5188 | + field = document.getElementById( 'field_options_image_size_' + fieldId ), | |
| 5189 | + size = ''; | |
| 5190 | + | |
| 5191 | + if ( field !== null ) { | |
| 5192 | + val = field.value; | |
| 5193 | + if ( val !== '' ) { | |
| 5194 | + size = val; | |
| 5195 | + } | |
| 5196 | + } | |
| 5197 | + | |
| 5198 | + return size; | |
| 5199 | + } | |
| 5200 | + | |
| 5201 | + function resetDisplayedOpts( fieldId ) { | |
| 5202 | + var i, opts, type, placeholder, fieldInfo, | |
| 5203 | + input = jQuery( '[name^="item_meta[' + fieldId + ']"]' ); | |
| 5204 | + | |
| 5205 | + if ( input.length < 1 ) { | |
| 5206 | + return; | |
| 5207 | + } | |
| 5208 | + | |
| 5209 | + if ( input.is( 'select' ) ) { | |
| 5210 | + placeholder = document.getElementById( 'frm_placeholder_' + fieldId ); | |
| 5211 | + if ( placeholder !== null && placeholder.value === '' ) { | |
| 5212 | + fillDropdownOpts( input[0], { sourceID: fieldId }); | |
| 5213 | + } else { | |
| 5214 | + fillDropdownOpts( input[0], { | |
| 5215 | + sourceID: fieldId, | |
| 5216 | + placeholder: placeholder.value | |
| 5217 | + }); | |
| 5218 | + } | |
| 5219 | + } else { | |
| 5220 | + opts = getMultipleOpts( fieldId ); | |
| 5221 | + type = input.attr( 'type' ); | |
| 5222 | + jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ).html( '' ); | |
| 5223 | + fieldInfo = getFieldKeyFromOpt( jQuery( '#frm_delete_field_' + fieldId + '-000_container' ) ); | |
| 5224 | + | |
| 5225 | + var container = jQuery( '#field_' + fieldId + '_inner_container > .frm_form_fields' ), | |
| 5226 | + hasImageOptions = imagesAsOptions( fieldId ), | |
| 5227 | + imageSize = hasImageOptions ? getImageOptionSize( fieldId ) : '', | |
| 5228 | + imageOptionClass = hasImageOptions ? ( 'frm_image_option frm_image_' + imageSize + ' ' ) : '', | |
| 5229 | + isProduct = isProductField( fieldId ); | |
| 5230 | + | |
| 5231 | + for ( i = 0; i < opts.length; i++ ) { | |
| 5232 | + container.append( addRadioCheckboxOpt( type, opts[ i ], fieldId, fieldInfo.fieldKey, isProduct, imageOptionClass ) ); | |
| 5233 | + } | |
| 5234 | + } | |
| 5235 | + | |
| 5236 | + adjustConditionalLogicOptionOrders( fieldId ); | |
| 5237 | + } | |
| 5238 | + | |
| 5239 | + function adjustConditionalLogicOptionOrders( fieldId ) { | |
| 5240 | + var row, opts, logicId, valueSelect, rowOptions, expectedOrder, optionLength, optionIndex, expectedOption, optionMatch, | |
| 5241 | + rows = document.getElementById( 'frm_builder_page' ).querySelectorAll( '.frm_logic_row' ), | |
| 5242 | + rowLength = rows.length, | |
| 5243 | + fieldOptions = getFieldOptions( fieldId ), | |
| 5244 | + optionLength = fieldOptions.length; | |
| 5245 | + | |
| 5246 | + for ( rowIndex = 0; rowIndex < rowLength; rowIndex++ ) { | |
| 5247 | + row = rows[ rowIndex ]; | |
| 5248 | + opts = row.querySelector( '.frm_logic_field_opts' ); | |
| 5249 | + | |
| 5250 | + if ( opts.value != fieldId ) { | |
| 5251 | + continue; | |
| 5252 | + } | |
| 5253 | + | |
| 5254 | + logicId = row.id.split( '_' )[ 2 ]; | |
| 5255 | + valueSelect = row.querySelector( 'select[name="field_options[hide_opt_' + logicId + '][]"]' ); | |
| 5256 | + | |
| 5257 | + for ( optionIndex = optionLength - 1; optionIndex >= 0; optionIndex-- ) { | |
| 5258 | + expectedOption = fieldOptions[ optionIndex ]; | |
| 5259 | + optionMatch = valueSelect.querySelector( 'option[value="' + expectedOption + '"]' ); | |
| 5260 | + | |
| 5261 | + if ( optionMatch === null ) { | |
| 5262 | + optionMatch = document.createElement( 'option' ); | |
| 5263 | + optionMatch.setAttribute( 'value', expectedOption ); | |
| 5264 | + optionMatch.textContent = expectedOption; | |
| 5265 | + } | |
| 5266 | + | |
| 5267 | + valueSelect.prepend( optionMatch ); | |
| 5268 | + } | |
| 5269 | + | |
| 5270 | + optionMatch = valueSelect.querySelector( 'option[value=""]' ); | |
| 5271 | + if ( optionMatch !== null ) { | |
| 5272 | + valueSelect.prepend( optionMatch ); | |
| 5273 | + } | |
| 5274 | + } | |
| 5275 | + } | |
| 5276 | + | |
| 5277 | + function getFieldOptions( fieldId ) { | |
| 5278 | + var index, input, li, | |
| 5279 | + listItems = document.getElementById( 'frm_field_' + fieldId + '_opts' ).querySelectorAll( '.frm_single_option' ), | |
| 5280 | + options = [], | |
| 5281 | + length = listItems.length; | |
| 5282 | + for ( index = 0; index < length; index++ ) { | |
| 5283 | + li = listItems[ index ]; | |
| 5284 | + | |
| 5285 | + if ( li.classList.contains( 'frm_hidden' ) ) { | |
| 5286 | + continue; | |
| 5287 | + } | |
| 5288 | + | |
| 5289 | + input = li.querySelector( '.field_' + fieldId + '_option' ); | |
| 5290 | + options.push( input.value ); | |
| 5291 | + } | |
| 5292 | + return options; | |
| 5293 | + } | |
| 5294 | + | |
| 5295 | + function addRadioCheckboxOpt( type, opt, fieldId, fieldKey, isProduct, classes ) { | |
| 5296 | + var other, single, | |
| 5297 | + isOther = opt.key.indexOf( 'other' ) !== -1, | |
| 5298 | + | |
| 5299 | + id = 'field_' + fieldKey + '-' + opt.key; | |
| 5300 | + | |
| 5301 | + 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="" />'; | |
| 5302 | + | |
| 5303 | + single = '<div class="frm_' + type + ' ' + type + ' ' + classes + '" id="frm_' + type + '_' + fieldId + '-' + opt.key + '"><label for="' + id + | |
| 5304 | + '"><input type="' + type + | |
| 5305 | + '" name="item_meta[' + fieldId + ']' + ( type === 'checkbox' ? '[]' : '' ) + | |
| 5306 | + '" value="' + opt.saved + '" id="' + id + '"' + ( isProduct ? ' data-price="' + opt.price + '"' : '' ) + ( opt.checked ? ' checked="checked"' : '' ) + '> ' + opt.label + '</label>' + | |
| 5307 | + ( isOther ? other : '' ) + | |
| 5308 | + '</div>'; | |
| 5309 | + | |
| 5310 | + return single; | |
| 5311 | + } | |
| 5312 | + | |
| 5313 | + function fillDropdownOpts( field, atts ) { | |
| 5314 | + if ( field === null ) { | |
| 5315 | + return; | |
| 5316 | + } | |
| 5317 | + var sourceID = atts.sourceID, | |
| 5318 | + placeholder = atts.placeholder, | |
| 5319 | + isProduct = isProductField( sourceID ), | |
| 5320 | + showOther = atts.other; | |
| 5321 | + | |
| 5322 | + removeDropdownOpts( field ); | |
| 5323 | + var opts = getMultipleOpts( sourceID ), | |
| 5324 | + hasPlaceholder = ( typeof placeholder !== 'undefined' ); | |
| 5325 | + | |
| 5326 | + for ( var i = 0; i < opts.length; i++ ) { | |
| 5327 | + var label = opts[ i ].label, | |
| 5328 | + isOther = opts[ i ].key.indexOf( 'other' ) !== -1; | |
| 5329 | + | |
| 5330 | + if ( hasPlaceholder && label !== '' ) { | |
| 5331 | + addBlankSelectOption( field, placeholder ); | |
| 5332 | + } else if ( hasPlaceholder ) { | |
| 5333 | + label = placeholder; | |
| 5334 | + } | |
| 5335 | + hasPlaceholder = false; | |
| 5336 | + | |
| 5337 | + if ( ! isOther || showOther ) { | |
| 5338 | + var opt = document.createElement( 'option' ); | |
| 5339 | + opt.value = opts[ i ].saved; | |
| 5340 | + opt.innerHTML = label; | |
| 5341 | + | |
| 5342 | + if ( isProduct ) { | |
| 5343 | + opt.setAttribute( 'data-price', opts[ i ].price ); | |
| 5344 | + } | |
| 5345 | + | |
| 5346 | + field.appendChild( opt ); | |
| 5347 | + } | |
| 5348 | + } | |
| 5349 | + } | |
| 5350 | + | |
| 5351 | + function addBlankSelectOption( field, placeholder ) { | |
| 5352 | + var opt = document.createElement( 'option' ), | |
| 5353 | + firstChild = field.firstChild; | |
| 5354 | + | |
| 5355 | + opt.value = ''; | |
| 5356 | + opt.innerHTML = placeholder; | |
| 5357 | + if ( firstChild !== null ) { | |
| 5358 | + field.insertBefore( opt, firstChild ); | |
| 5359 | + field.selectedIndex = 0; | |
| 5360 | + } else { | |
| 5361 | + field.appendChild( opt ); | |
| 5362 | + } | |
| 5363 | + } | |
| 5364 | + | |
| 5365 | + function getMultipleOpts( fieldId ) { | |
| 5366 | + var i, saved, labelName, label, key, optObj, | |
| 5367 | + image, savedLabel, input, field, checkbox, fieldType, | |
| 5368 | + checked = false, | |
| 5369 | + opts = [], | |
| 5370 | + imageUrl = '', | |
| 5371 | + | |
| 5372 | + optVals = jQuery( 'input[name^="field_options[options_' + fieldId + ']"]' ), | |
| 5373 | + separateValues = usingSeparateValues( fieldId ), | |
| 5374 | + hasImageOptions = imagesAsOptions( fieldId ), | |
| 5375 | + showLabelWithImage = showingLabelWithImage( fieldId ), | |
| 5376 | + isProduct = isProductField( fieldId ); | |
| 5377 | + | |
| 5378 | + for ( i = 0; i < optVals.length; i++ ) { | |
| 5379 | + 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 ) { | |
| 5380 | + continue; | |
| 5381 | + } | |
| 5382 | + saved = optVals[ i ].value; | |
| 5383 | + label = saved; | |
| 5384 | + key = optVals[ i ].name.replace( 'field_options[options_' + fieldId + '][', '' ).replace( '[label]', '' ).replace( ']', '' ); | |
| 5385 | + | |
| 5386 | + if ( separateValues ) { | |
| 5387 | + labelName = optVals[ i ].name.replace( '[label]', '[value]' ); | |
| 5388 | + saved = jQuery( 'input[name="' + labelName + '"]' ).val(); | |
| 5389 | + } | |
| 5390 | + | |
| 5391 | + if ( hasImageOptions ) { | |
| 5392 | + imageUrl = getImageUrlFromInput( optVals[i]); | |
| 5393 | + fieldType = radioOrCheckbox( fieldId ); | |
| 5394 | + label = getImageLabel( label, showLabelWithImage, imageUrl, fieldType ); | |
| 5395 | + } | |
| 5396 | + | |
| 5397 | + /** | |
| 5398 | + * @since 5.0.04 | |
| 5399 | + */ | |
| 5400 | + label = frmAdminBuild.hooks.applyFilters( 'frm_choice_field_label', label, fieldId, optVals[ i ], hasImageOptions ); | |
| 5401 | + | |
| 5402 | + checked = getChecked( optVals[ i ].id ); | |
| 5403 | + | |
| 5404 | + optObj = { | |
| 5405 | + saved: saved, | |
| 5406 | + label: label, | |
| 5407 | + checked: checked, | |
| 5408 | + key: key | |
| 5409 | + }; | |
| 5410 | + | |
| 5411 | + if ( isProduct ) { | |
| 5412 | + labelName = optVals[ i ].name.replace( '[label]', '[price]' ); | |
| 5413 | + optObj.price = jQuery( 'input[name="' + labelName + '"]' ).val(); | |
| 5414 | + } | |
| 5415 | + | |
| 5416 | + opts.push( optObj ); | |
| 5417 | + } | |
| 5418 | + | |
| 5419 | + return opts; | |
| 5420 | + } | |
| 5421 | + | |
| 5422 | + function radioOrCheckbox( fieldId ) { | |
| 5423 | + var settings = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 5424 | + if ( settings === null ) { | |
| 5425 | + return 'radio'; | |
| 5426 | + } | |
| 5427 | + | |
| 5428 | + return settings.classList.contains( 'frm-type-checkbox' ) ? 'checkbox' : 'radio'; | |
| 5429 | + } | |
| 5430 | + | |
| 5431 | + function getImageUrlFromInput( optVal ) { | |
| 5432 | + var img, | |
| 5433 | + wrapper = jQuery( optVal ).siblings( '.frm_image_preview_wrapper' ); | |
| 5434 | + | |
| 5435 | + if ( ! wrapper.length ) { | |
| 5436 | + return ''; | |
| 5437 | + } | |
| 5438 | + | |
| 5439 | + img = wrapper.find( 'img' ); | |
| 5440 | + if ( ! img.length ) { | |
| 5441 | + return ''; | |
| 5442 | + } | |
| 5443 | + | |
| 5444 | + return img.attr( 'src' ); | |
| 5445 | + } | |
| 5446 | + | |
| 5447 | + function getImageLabel( label, showLabelWithImage, imageUrl, fieldType ) { | |
| 5448 | + var imageLabelClass, fullLabel, | |
| 5449 | + originalLabel = label, | |
| 5450 | + shape = fieldType === 'checkbox' ? 'square' : 'circle'; | |
| 5451 | + | |
| 5452 | + fullLabel = '<div class="frm_selected_checkmark"><svg class="frmsvg"><use xlink:href="#frm_checkmark_' + shape + '_icon"></svg></div>'; | |
| 5453 | + if ( imageUrl ) { | |
| 5454 | + fullLabel += '<img src="' + imageUrl + '" alt="' + originalLabel + '" />'; | |
| 5455 | + } else { | |
| 5456 | + fullLabel += '<div class="frm_empty_url">' + frm_admin_js.image_placeholder_icon + '</div>'; | |
| 5457 | + } | |
| 5458 | + if ( showLabelWithImage ) { | |
| 5459 | + fullLabel += '<span class="frm_text_label_for_image"><span class="frm_text_label_for_image_inner">' + originalLabel + '</span></span>'; | |
| 5460 | + } | |
| 5461 | + | |
| 5462 | + imageLabelClass = showLabelWithImage ? ' frm_label_with_image' : ''; | |
| 5463 | + | |
| 5464 | + return ( '<span class="frm_image_option_container' + imageLabelClass + '">' + fullLabel + '</span>' ); | |
| 5465 | + } | |
| 5466 | + | |
| 5467 | + function getChecked( id ) { | |
| 5468 | + field = jQuery( '#' + id ); | |
| 5469 | + | |
| 5470 | + if ( field.length === 0 ) { | |
| 5471 | + return false; | |
| 5472 | + } | |
| 5473 | + | |
| 5474 | + checkbox = field.siblings( 'input[type=checkbox]' ); | |
| 5475 | + | |
| 5476 | + return checkbox.length && checkbox.prop( 'checked' ); | |
| 5477 | + } | |
| 5478 | + | |
| 5479 | + function removeDropdownOpts( field ) { | |
| 5480 | + var i; | |
| 5481 | + if ( typeof field.options === 'undefined' ) { | |
| 5482 | + return; | |
| 5483 | + } | |
| 5484 | + | |
| 5485 | + for ( i = field.options.length - 1; i >= 0; i-- ) { | |
| 5486 | + field.remove( i ); | |
| 5487 | + } | |
| 5488 | + } | |
| 5489 | + | |
| 5490 | + /** | |
| 5491 | + * Is the box checked to use separate values? | |
| 5492 | + */ | |
| 5493 | + function usingSeparateValues( fieldId ) { | |
| 5494 | + return isChecked( 'separate_value_' + fieldId ); | |
| 5495 | + } | |
| 5496 | + | |
| 5497 | + /** | |
| 5498 | + * Is the box checked to use images as options? | |
| 5499 | + */ | |
| 5500 | + function imagesAsOptions( fieldId ) { | |
| 5501 | + var checked = false, | |
| 5502 | + field = document.getElementsByName( 'field_options[image_options_' + fieldId + ']' ); | |
| 5503 | + | |
| 5504 | + for ( var i = 0; i < field.length; i++ ) { | |
| 5505 | + if ( field[ i ].checked ) { | |
| 5506 | + checked = '0' !== field[ i ].value; | |
| 5507 | + } | |
| 5508 | + } | |
| 5509 | + | |
| 5510 | + /** | |
| 5511 | + * @since 5.0.04 | |
| 5512 | + */ | |
| 5513 | + return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_images_as_options', checked, fieldId ); | |
| 5514 | + } | |
| 5515 | + | |
| 5516 | + function showingLabelWithImage( fieldId ) { | |
| 5517 | + const isShowing = ! isChecked( 'hide_image_text_' + fieldId ); | |
| 5518 | + | |
| 5519 | + /** | |
| 5520 | + * @since 5.0.04 | |
| 5521 | + */ | |
| 5522 | + return frmAdminBuild.hooks.applyFilters( 'frm_choice_field_showing_label_with_image', isShowing, fieldId ); | |
| 5523 | + } | |
| 5524 | + | |
| 5525 | + function isChecked( id ) { | |
| 5526 | + var field = document.getElementById( id ); | |
| 5527 | + if ( field === null ) { | |
| 5528 | + return false; | |
| 5529 | + } else { | |
| 5530 | + return field.checked; | |
| 5531 | + } | |
| 5532 | + } | |
| 5533 | + | |
| 5534 | + function checkUniqueOpt( targetInput ) { | |
| 5535 | + const settingsContainer = targetInput.closest( '.frm-single-settings' ); | |
| 5536 | + const fieldId = settingsContainer.getAttribute( 'data-fid' ); | |
| 5537 | + const areValuesSeparate = settingsContainer.querySelector( '[name="field_options[separate_value_' + fieldId + ']"]' ).checked; | |
| 5538 | + | |
| 5539 | + if ( areValuesSeparate && ! targetInput.name.endsWith( '[value]' ) ) { | |
| 5540 | + return; | |
| 5541 | + } | |
| 5542 | + | |
| 5543 | + const container = document.getElementById( 'frm_field_' + fieldId + '_opts' ); | |
| 5544 | + const conflicts = Array.from( container.querySelectorAll( 'input[type="text"]' ) ).filter( | |
| 5545 | + input => input.id !== targetInput.id && | |
| 5546 | + areValuesSeparate === input.name.endsWith( '[value]' ) && | |
| 5547 | + input.value === targetInput.value | |
| 5548 | + ); | |
| 5549 | + if ( conflicts.length ) { | |
| 5550 | + infoModal( __( 'Duplicate option value "%s" detected', 'formidable' ).replace( '%s', targetInput.value ) ); | |
| 5551 | + } | |
| 5552 | + } | |
| 5553 | + | |
| 5554 | + function setStarValues() { | |
| 5555 | + /*jshint validthis:true */ | |
| 5556 | + var fieldID = this.id.replace( 'radio_maxnum_', '' ); | |
| 5557 | + var container = jQuery( '#field_' + fieldID + '_inner_container .frm-star-group' ); | |
| 5558 | + var fieldKey = document.getElementsByName( 'field_options[field_key_' + fieldID + ']' )[0].value; | |
| 5559 | + container.html( '' ); | |
| 5560 | + | |
| 5561 | + var min = 1; | |
| 5562 | + var max = this.value; | |
| 5563 | + if ( min > max ) { | |
| 5564 | + max = min; | |
| 5565 | + } | |
| 5566 | + | |
| 5567 | + for ( var i = min; i <= max; i++ ) { | |
| 5568 | + 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>' ); | |
| 5569 | + } | |
| 5570 | + } | |
| 5571 | + | |
| 5572 | + function getFieldValues() { | |
| 5573 | + /*jshint validthis:true */ | |
| 5574 | + var isTaxonomy, | |
| 5575 | + val = this.value; | |
| 5576 | + | |
| 5577 | + if ( val ) { | |
| 5578 | + var parentIDs = this.parentNode.id.replace( 'frm_logic_', '' ).split( '_' ); | |
| 5579 | + var fieldID = parentIDs[0]; | |
| 5580 | + var metaKey = parentIDs[1]; | |
| 5581 | + var valueField = document.getElementById( 'frm_field_id_' + val ); | |
| 5582 | + var valueFieldType = valueField.getAttribute( 'data-ftype' ); | |
| 5583 | + var fill = document.getElementById( 'frm_show_selected_values_' + fieldID + '_' + metaKey ); | |
| 5584 | + var optionName = 'field_options[hide_opt_' + fieldID + '][]'; | |
| 5585 | + var optionID = 'frm_field_logic_opt_' + fieldID; | |
| 5586 | + var input = false; | |
| 5587 | + var showSelect = ( valueFieldType === 'select' || valueFieldType === 'checkbox' || valueFieldType === 'radio' ); | |
| 5588 | + var showText = ( valueFieldType === 'text' || valueFieldType === 'email' || valueFieldType === 'phone' || valueFieldType === 'url' || valueFieldType === 'number' ); | |
| 5589 | + | |
| 5590 | + if ( showSelect ) { | |
| 5591 | + isTaxonomy = document.getElementById( 'frm_has_hidden_options_' + val ); | |
| 5592 | + if ( isTaxonomy !== null ) { | |
| 5593 | + // get the category options with ajax | |
| 5594 | + showSelect = false; | |
| 5595 | + } | |
| 5596 | + } | |
| 5597 | + | |
| 5598 | + if ( showSelect || showText ) { | |
| 5599 | + fill.innerHTML = ''; | |
| 5600 | + if ( showSelect ) { | |
| 5601 | + input = document.createElement( 'select' ); | |
| 5602 | + } else { | |
| 5603 | + input = document.createElement( 'input' ); | |
| 5604 | + input.type = 'text'; | |
| 5605 | + } | |
| 5606 | + input.name = optionName; | |
| 5607 | + input.id = optionID + '_' + metaKey; | |
| 5608 | + fill.appendChild( input ); | |
| 5609 | + | |
| 5610 | + if ( showSelect ) { | |
| 5611 | + var fillField = document.getElementById( input.id ); | |
| 5612 | + fillDropdownOpts( fillField, { | |
| 5613 | + sourceID: val, | |
| 5614 | + placeholder: '', | |
| 5615 | + other: true | |
| 5616 | + }); | |
| 5617 | + } | |
| 5618 | + } else { | |
| 5619 | + var thisType = this.getAttribute( 'data-type' ); | |
| 5620 | + frmGetFieldValues( val, fieldID, metaKey, thisType ); | |
| 5621 | + } | |
| 5622 | + } | |
| 5623 | + } | |
| 5624 | + | |
| 5625 | + function getFieldSelection() { | |
| 5626 | + /*jshint validthis:true */ | |
| 5627 | + var formId = this.value; | |
| 5628 | + if ( formId ) { | |
| 5629 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 5630 | + getTaxOrFieldSelection( formId, fieldId ); | |
| 5631 | + } | |
| 5632 | + } | |
| 5633 | + | |
| 5634 | + function getTaxOrFieldSelection( formId, fieldId ) { | |
| 5635 | + if ( formId ) { | |
| 5636 | + jQuery.ajax({ | |
| 5637 | + type: 'POST', | |
| 5638 | + url: ajaxurl, | |
| 5639 | + data: { | |
| 5640 | + action: 'frm_get_field_selection', | |
| 5641 | + field_id: fieldId, | |
| 5642 | + form_id: formId, | |
| 5643 | + nonce: frmGlobal.nonce | |
| 5644 | + }, | |
| 5645 | + success: function( msg ) { | |
| 5646 | + jQuery( '#frm_show_selected_fields_' + fieldId ).html( msg ).show(); | |
| 5647 | + } | |
| 5648 | + }); | |
| 5649 | + } | |
| 5650 | + } | |
| 5651 | + | |
| 5652 | + function updateFieldOrder() { | |
| 5653 | + var fields, fieldId, field, currentOrder, newOrder; | |
| 5654 | + renumberPageBreaks(); | |
| 5655 | + jQuery( '#frm-show-fields' ).each( function( i ) { | |
| 5656 | + fields = jQuery( 'li.frm_field_box', this ); | |
| 5657 | + for ( i = 0; i < fields.length; i++ ) { | |
| 5658 | + fieldId = fields[ i ].getAttribute( 'data-fid' ); | |
| 5659 | + field = jQuery( 'input[name="field_options[field_order_' + fieldId + ']"]' ); | |
| 5660 | + currentOrder = field.val(); | |
| 5661 | + newOrder = i + 1; | |
| 5662 | + | |
| 5663 | + if ( currentOrder != newOrder ) { | |
| 5664 | + field.val( newOrder ); | |
| 5665 | + singleField = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 5666 | + | |
| 5667 | + moveFieldSettings( singleField ); | |
| 5668 | + fieldUpdated(); | |
| 5669 | + } | |
| 5670 | + } | |
| 5671 | + }); | |
| 5672 | + } | |
| 5673 | + | |
| 5674 | + function toggleSectionHolder() { | |
| 5675 | + document.querySelectorAll( '.start_divider' ).forEach( | |
| 5676 | + function( divider ) { | |
| 5677 | + toggleOneSectionHolder( jQuery( divider ) ); | |
| 5678 | + } | |
| 5679 | + ); | |
| 5680 | + } | |
| 5681 | + | |
| 5682 | + function toggleOneSectionHolder( $section ) { | |
| 5683 | + var noSectionFields, $rows, length, index, sectionHasFields; | |
| 5684 | + | |
| 5685 | + if ( ! $section.length ) { | |
| 5686 | + return; | |
| 5687 | + } | |
| 5688 | + | |
| 5689 | + $rows = $section.find( 'ul.frm_sorting' ); | |
| 5690 | + sectionHasFields = false; | |
| 5691 | + length = $rows.length; | |
| 5692 | + for ( index = 0; index < length; ++index ) { | |
| 5693 | + if ( 0 !== getFieldsInRow( jQuery( $rows.get( index ) ) ).length ) { | |
| 5694 | + sectionHasFields = true; | |
| 5695 | + break; | |
| 5696 | + } | |
| 5697 | + } | |
| 5698 | + | |
| 5699 | + noSectionFields = $section.parent().children( '.frm_no_section_fields' ).get( 0 ); | |
| 5700 | + noSectionFields.classList.toggle( 'frm_block', ! sectionHasFields ); | |
| 5701 | + } | |
| 5702 | + | |
| 5703 | + function slideDown() { | |
| 5704 | + /*jshint validthis:true */ | |
| 5705 | + var id = jQuery( this ).data( 'slidedown' ); | |
| 5706 | + var $thisId = jQuery( document.getElementById( id ) ); | |
| 5707 | + if ( $thisId.is( ':hidden' ) ) { | |
| 5708 | + $thisId.slideDown( 'fast' ); | |
| 5709 | + this.style.display = 'none'; | |
| 5710 | + } | |
| 5711 | + return false; | |
| 5712 | + } | |
| 5713 | + | |
| 5714 | + function slideUp() { | |
| 5715 | + /*jshint validthis:true */ | |
| 5716 | + var id = jQuery( this ).data( 'slideup' ); | |
| 5717 | + var $thisId = jQuery( document.getElementById( id ) ); | |
| 5718 | + $thisId.slideUp( 'fast' ); | |
| 5719 | + $thisId.siblings( 'a' ).show(); | |
| 5720 | + return false; | |
| 5721 | + } | |
| 5722 | + | |
| 5723 | + function adjustVisibilityValuesForEveryoneValues( element, option ) { | |
| 5724 | + if ( '' === option.getAttribute( 'value' ) ) { | |
| 5725 | + onEveryoneOptionSelected( jQuery( this ) ); | |
| 5726 | + } else { | |
| 5727 | + unselectEveryoneOptionIfSelected( jQuery( this ) ); | |
| 5728 | + } | |
| 5729 | + } | |
| 5730 | + | |
| 5731 | + function onEveryoneOptionSelected( $select ) { | |
| 5732 | + $select.val( '' ); | |
| 5733 | + $select.next( '.btn-group' ).find( '.multiselect-container input[value!=""]' ).prop( 'checked', false ); | |
| 5734 | + } | |
| 5735 | + | |
| 5736 | + function unselectEveryoneOptionIfSelected( $select ) { | |
| 5737 | + var selectedValues = $select.val(), | |
| 5738 | + index; | |
| 5739 | + | |
| 5740 | + if ( selectedValues === null ) { | |
| 5741 | + $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', true ); | |
| 5742 | + onEveryoneOptionSelected( $select ); | |
| 5743 | + return; | |
| 5744 | + } | |
| 5745 | + | |
| 5746 | + index = selectedValues.indexOf( '' ); | |
| 5747 | + if ( index >= 0 ) { | |
| 5748 | + selectedValues.splice( index, 1 ); | |
| 5749 | + $select.val( selectedValues ); | |
| 5750 | + $select.next( '.btn-group' ).find( '.multiselect-container input[value=""]' ).prop( 'checked', false ); | |
| 5751 | + } | |
| 5752 | + } | |
| 5753 | + | |
| 5754 | + /** | |
| 5755 | + * Get rid of empty container that inserts extra space. | |
| 5756 | + */ | |
| 5757 | + function hideEmptyEle() { | |
| 5758 | + jQuery( '.frm-hide-empty' ).each( function() { | |
| 5759 | + if ( jQuery( this ).text().trim().length === 0 ) { | |
| 5760 | + jQuery( this ).remove(); | |
| 5761 | + } | |
| 5762 | + }); | |
| 5763 | + } | |
| 5764 | + | |
| 5765 | + /* Change the classes in the builder */ | |
| 5766 | + function changeFieldClass( field, setting ) { | |
| 5767 | + var classes, replace, alignField, | |
| 5768 | + replaceWith = ' ' + setting.value, | |
| 5769 | + fieldId = field.getAttribute( 'data-fid' ); | |
| 5770 | + | |
| 5771 | + // Include classes from multiple settings. | |
| 5772 | + if ( typeof fieldId !== 'undefined' ) { | |
| 5773 | + if ( setting.classList.contains( 'field_options_align' ) ) { | |
| 5774 | + replaceWith += ' ' + document.getElementById( 'frm_classes_' + fieldId ).value; | |
| 5775 | + } else if ( setting.classList.contains( 'frm_classes' ) ) { | |
| 5776 | + alignField = document.getElementById( 'field_options_align_' + fieldId ); | |
| 5777 | + if ( alignField !== null ) { | |
| 5778 | + replaceWith += ' ' + alignField.value; | |
| 5779 | + } | |
| 5780 | + } | |
| 5781 | + } | |
| 5782 | + replaceWith += ' '; | |
| 5783 | + | |
| 5784 | + // Allow for the column number dropdown. | |
| 5785 | + replaceWith = replaceWith.replace( ' block ', ' ' ).replace( ' inline ', ' horizontal_radio ' ); | |
| 5786 | + | |
| 5787 | + classes = field.className.split( ' frmstart ' )[1]; | |
| 5788 | + classes = 0 === classes.indexOf( 'frmend ' ) ? '' : classes.split( ' frmend ' )[0]; | |
| 5789 | + | |
| 5790 | + if ( classes.trim() === '' ) { | |
| 5791 | + replace = ' frmstart frmend '; | |
| 5792 | + if ( -1 === field.className.indexOf( replace ) ) { | |
| 5793 | + replace = ' frmstart frmend '; | |
| 5794 | + } | |
| 5795 | + replaceWith = ' frmstart ' + replaceWith.trim() + ' frmend '; | |
| 5796 | + } else { | |
| 5797 | + replace = classes.trim(); | |
| 5798 | + replaceWith = replaceWith.trim(); | |
| 5799 | + } | |
| 5800 | + | |
| 5801 | + field.className = field.className.replace( replace, replaceWith ); | |
| 5802 | + } | |
| 5803 | + | |
| 5804 | + function maybeShowInlineModal( e ) { | |
| 5805 | + /*jshint validthis:true */ | |
| 5806 | + e.preventDefault(); | |
| 5807 | + showInlineModal( this ); | |
| 5808 | + } | |
| 5809 | + | |
| 5810 | + function showInlineModal( icon, input ) { | |
| 5811 | + var box = document.getElementById( icon.getAttribute( 'data-open' ) ), | |
| 5812 | + container = jQuery( icon ).closest( 'p' ), | |
| 5813 | + inputTrigger = ( typeof input !== 'undefined' ); | |
| 5814 | + | |
| 5815 | + if ( container.hasClass( 'frm-open' ) ) { | |
| 5816 | + container.removeClass( 'frm-open' ); | |
| 5817 | + box.classList.add( 'frm_hidden' ); | |
| 5818 | + } else { | |
| 5819 | + if ( ! inputTrigger ) { | |
| 5820 | + input = getInputForIcon( icon ); | |
| 5821 | + } | |
| 5822 | + if ( input !== null ) { | |
| 5823 | + if ( ! inputTrigger ) { | |
| 5824 | + input.focus(); | |
| 5825 | + } | |
| 5826 | + container.after( box ); | |
| 5827 | + box.setAttribute( 'data-fills', input.id ); | |
| 5828 | + | |
| 5829 | + if ( box.id.indexOf( 'frm-calc-box' ) === 0 ) { | |
| 5830 | + popCalcFields( box, true ); | |
| 5831 | + } | |
| 5832 | + } | |
| 5833 | + | |
| 5834 | + container.addClass( 'frm-open' ); | |
| 5835 | + box.classList.remove( 'frm_hidden' ); | |
| 5836 | + } | |
| 5837 | + } | |
| 5838 | + | |
| 5839 | + function dismissInlineModal( e ) { | |
| 5840 | + /*jshint validthis:true */ | |
| 5841 | + e.preventDefault(); | |
| 5842 | + this.parentNode.classList.add( 'frm_hidden' ); | |
| 5843 | + jQuery( '.frm-open [data-open="' + this.parentNode.id + '"]' ).closest( '.frm-open' ).removeClass( 'frm-open' ); | |
| 5844 | + } | |
| 5845 | + | |
| 5846 | + function changeInputtedValue() { | |
| 5847 | + /*jshint validthis:true */ | |
| 5848 | + var i, | |
| 5849 | + action = this.getAttribute( 'data-frmchange' ).split( ',' ); | |
| 5850 | + | |
| 5851 | + for ( i = 0; i < action.length; i++ ) { | |
| 5852 | + if ( action[i] === 'updateOption' ) { | |
| 5853 | + changeHiddenSeparateValue( this ); | |
| 5854 | + } else if ( action[i] === 'updateDefault' ) { | |
| 5855 | + changeDefaultRadioValue( this ); | |
| 5856 | + } else if ( action[i] === 'checkUniqueOpt' ) { | |
| 5857 | + checkUniqueOpt( this ); | |
| 5858 | + } else { | |
| 5859 | + this.value = this.value[ action[i] ](); | |
| 5860 | + } | |
| 5861 | + } | |
| 5862 | + } | |
| 5863 | + | |
| 5864 | + /** | |
| 5865 | + * When the saved value is changed, update the default value radio. | |
| 5866 | + */ | |
| 5867 | + function changeDefaultRadioValue( input ) { | |
| 5868 | + var parentLi = getOptionParent( input ), | |
| 5869 | + key = parentLi.getAttribute( 'data-optkey' ), | |
| 5870 | + fieldId = getOptionFieldId( parentLi, key ), | |
| 5871 | + defaultRadio = parentLi.querySelector( 'input[name="default_value_' + fieldId + '"]' ); | |
| 5872 | + | |
| 5873 | + if ( defaultRadio !== null ) { | |
| 5874 | + defaultRadio.value = input.value; | |
| 5875 | + } | |
| 5876 | + } | |
| 5877 | + | |
| 5878 | + /** | |
| 5879 | + * If separate values are not enabled, change the saved value when | |
| 5880 | + * the displayed value is changed. | |
| 5881 | + */ | |
| 5882 | + function changeHiddenSeparateValue( input ) { | |
| 5883 | + var savedVal, | |
| 5884 | + parentLi = getOptionParent( input ), | |
| 5885 | + key = parentLi.getAttribute( 'data-optkey' ), | |
| 5886 | + fieldId = getOptionFieldId( parentLi, key ), | |
| 5887 | + sep = document.getElementById( 'separate_value_' + fieldId ); | |
| 5888 | + | |
| 5889 | + if ( sep !== null && sep.checked === false ) { | |
| 5890 | + // If separate values are not turned on. | |
| 5891 | + savedVal = document.getElementById( 'field_key_' + fieldId + '-' + key ); | |
| 5892 | + savedVal.value = input.value; | |
| 5893 | + changeDefaultRadioValue( savedVal ); | |
| 5894 | + } | |
| 5895 | + } | |
| 5896 | + | |
| 5897 | + function getOptionParent( input ) { | |
| 5898 | + var parentLi = input.parentNode; | |
| 5899 | + if ( parentLi.tagName !== 'LI' ) { | |
| 5900 | + parentLi = parentLi.parentNode; | |
| 5901 | + } | |
| 5902 | + return parentLi; | |
| 5903 | + } | |
| 5904 | + | |
| 5905 | + function getOptionFieldId( li, key ) { | |
| 5906 | + var liId = li.id; | |
| 5907 | + | |
| 5908 | + return liId.replace( 'frm_delete_field_', '' ).replace( '-' + key + '_container', '' ); | |
| 5909 | + } | |
| 5910 | + | |
| 5911 | + function submitBuild() { | |
| 5912 | + /*jshint validthis:true */ | |
| 5913 | + var $thisEle = this; | |
| 5914 | + | |
| 5915 | + preFormSave( this ); | |
| 5916 | + | |
| 5917 | + var $form = jQuery( builderForm ); | |
| 5918 | + var v = JSON.stringify( $form.serializeArray() ); | |
| 5919 | + | |
| 5920 | + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( v ); | |
| 5921 | + jQuery.ajax({ | |
| 5922 | + type: 'POST', | |
| 5923 | + url: ajaxurl, | |
| 5924 | + data: {action: 'frm_save_form', 'frm_compact_fields': v, nonce: frmGlobal.nonce}, | |
| 5925 | + success: function( msg ) { | |
| 5926 | + afterFormSave( $thisEle ); | |
| 5927 | + | |
| 5928 | + var $postStuff = document.getElementById( 'post-body-content' ); | |
| 5929 | + var $html = document.createElement( 'div' ); | |
| 5930 | + $html.setAttribute( 'class', 'frm_updated_message' ); | |
| 5931 | + $html.innerHTML = msg; | |
| 5932 | + $postStuff.insertBefore( $html, $postStuff.firstChild ); | |
| 5933 | + }, | |
| 5934 | + error: function() { | |
| 5935 | + triggerSubmit( document.getElementById( 'frm_js_build_form' ) ); | |
| 5936 | + } | |
| 5937 | + }); | |
| 5938 | + } | |
| 5939 | + | |
| 5940 | + function triggerSubmit( form ) { | |
| 5941 | + var button = form.ownerDocument.createElement( 'input' ); | |
| 5942 | + button.style.display = 'none'; | |
| 5943 | + button.type = 'submit'; | |
| 5944 | + form.appendChild( button ).click(); | |
| 5945 | + form.removeChild( button ); | |
| 5946 | + } | |
| 5947 | + | |
| 5948 | + function triggerChange( element ) { | |
| 5949 | + jQuery( element ).trigger( 'change' ); | |
| 5950 | + } | |
| 5951 | + | |
| 5952 | + function submitNoAjax() { | |
| 5953 | + /*jshint validthis:true */ | |
| 5954 | + var form; | |
| 5955 | + | |
| 5956 | + preFormSave( this ); | |
| 5957 | + form = jQuery( builderForm ); | |
| 5958 | + jQuery( document.getElementById( 'frm_compact_fields' ) ).val( JSON.stringify( form.serializeArray() ) ); | |
| 5959 | + triggerSubmit( document.getElementById( 'frm_js_build_form' ) ); | |
| 5960 | + } | |
| 5961 | + | |
| 5962 | + function preFormSave( b ) { | |
| 5963 | + removeWPUnload(); | |
| 5964 | + if ( jQuery( 'form.inplace_form' ).length ) { | |
| 5965 | + jQuery( '.inplace_save, .postbox' ).trigger( 'click' ); | |
| 5966 | + } | |
| 5967 | + | |
| 5968 | + if ( b.classList.contains( 'frm_button_submit' ) ) { | |
| 5969 | + b.classList.add( 'frm_loading_form' ); | |
| 5970 | + } else { | |
| 5971 | + b.classList.add( 'frm_loading_button' ); | |
| 5972 | + } | |
| 5973 | + b.setAttribute( 'aria-busy', 'true' ); | |
| 5974 | + } | |
| 5975 | + | |
| 5976 | + function afterFormSave( button ) { | |
| 5977 | + button.classList.remove( 'frm_loading_form' ); | |
| 5978 | + button.classList.remove( 'frm_loading_button' ); | |
| 5979 | + resetOptionTextDetails(); | |
| 5980 | + fieldsUpdated = 0; | |
| 5981 | + button.setAttribute( 'aria-busy', 'false' ); | |
| 5982 | + | |
| 5983 | + setTimeout( function() { | |
| 5984 | + jQuery( '.frm_updated_message' ).fadeOut( 'slow', function() { | |
| 5985 | + this.parentNode.removeChild( this ); | |
| 5986 | + }); | |
| 5987 | + }, 5000 ); | |
| 5988 | + } | |
| 5989 | + | |
| 5990 | + function initUpgradeModal() { | |
| 5991 | + const $info = initModal( '#frm_upgrade_modal' ); | |
| 5992 | + if ( $info === false ) { | |
| 5993 | + return; | |
| 5994 | + } | |
| 5995 | + | |
| 5996 | + document.addEventListener( 'click', handleUpgradeClick ); | |
| 5997 | + | |
| 5998 | + function handleUpgradeClick( event ) { | |
| 5999 | + let element, link, content; | |
| 6000 | + | |
| 6001 | + element = event.target; | |
| 6002 | + | |
| 6003 | + if ( ! element.classList ) { | |
| 6004 | + return; | |
| 6005 | + } | |
| 6006 | + | |
| 6007 | + const showExpiredModal = element.classList.contains( 'frm_show_expired_modal' ) || null !== element.querySelector( '.frm_show_expired_modal' ) || element.closest( '.frm_show_expired_modal' ); | |
| 6008 | + | |
| 6009 | + if ( ! element.dataset.upgrade ) { | |
| 6010 | + const parent = element.closest( '[data-upgrade]' ); | |
| 6011 | + if ( ! parent ) { | |
| 6012 | + return; | |
| 6013 | + } | |
| 6014 | + element = parent; | |
| 6015 | + } | |
| 6016 | + | |
| 6017 | + if ( showExpiredModal ) { | |
| 6018 | + const hookName = 'frm_show_expired_modal'; | |
| 6019 | + wp.hooks.doAction( hookName, element ); | |
| 6020 | + return; | |
| 6021 | + } | |
| 6022 | + | |
| 6023 | + const upgradeLabel = element.dataset.upgrade; | |
| 6024 | + if ( ! upgradeLabel || element.classList.contains( 'frm_show_upgrade_tab' ) ) { | |
| 6025 | + return; | |
| 6026 | + } | |
| 6027 | + | |
| 6028 | + event.preventDefault(); | |
| 6029 | + | |
| 6030 | + const modal = $info.get( 0 ); | |
| 6031 | + const lockIcon = modal.querySelector( '.frm_lock_icon' ); | |
| 6032 | + | |
| 6033 | + if ( lockIcon ) { | |
| 6034 | + lockIcon.style.display = 'block'; | |
| 6035 | + lockIcon.classList.remove( 'frm_lock_open_icon' ); | |
| 6036 | + lockIcon.querySelector( 'use' ).setAttribute( 'href', '#frm_lock_icon' ); | |
| 6037 | + } | |
| 6038 | + | |
| 6039 | + const upgradeImageId = 'frm_upgrade_modal_image'; | |
| 6040 | + const oldImage = document.getElementById( upgradeImageId ); | |
| 6041 | + if ( oldImage ) { | |
| 6042 | + oldImage.remove(); | |
| 6043 | + } | |
| 6044 | + | |
| 6045 | + if ( element.dataset.image ) { | |
| 6046 | + if ( lockIcon ) { | |
| 6047 | + lockIcon.style.display = 'none'; | |
| 6048 | + } | |
| 6049 | + lockIcon.parentNode.insertBefore( img({ id: upgradeImageId, src: frmGlobal.url + '/images/' + element.dataset.image }), lockIcon ); | |
| 6050 | + } | |
| 6051 | + | |
| 6052 | + const level = modal.querySelector( '.license-level' ); | |
| 6053 | + if ( level ) { | |
| 6054 | + level.textContent = getRequiredLicenseFromTrigger( element ); | |
| 6055 | + } | |
| 6056 | + | |
| 6057 | + // If one click upgrade, hide other content | |
| 6058 | + addOneClick( element, 'modal', upgradeLabel ); | |
| 6059 | + | |
| 6060 | + modal.querySelector( '.frm_are_not_installed' ).style.display = element.dataset.image ? 'none' : 'inline-block'; | |
| 6061 | + modal.querySelector( '.frm_feature_label' ).textContent = upgradeLabel; | |
| 6062 | + modal.querySelector( 'h2' ).style.display = 'block'; | |
| 6063 | + | |
| 6064 | + $info.dialog( 'open' ); | |
| 6065 | + | |
| 6066 | + // set the utm medium | |
| 6067 | + const button = modal.querySelector( '.button-primary:not(.frm-oneclick-button)' ); | |
| 6068 | + link = button.getAttribute( 'href' ).replace( /(medium=)[a-z_-]+/ig, '$1' + element.getAttribute( 'data-medium' ) ); | |
| 6069 | + content = element.getAttribute( 'data-content' ); | |
| 6070 | + if ( content === null ) { | |
| 6071 | + content = ''; | |
| 6072 | + } | |
| 6073 | + link = link.replace( /(content=)[a-z_-]+/ig, '$1' + content ); | |
| 6074 | + button.setAttribute( 'href', link ); | |
| 6075 | + } | |
| 6076 | + } | |
| 6077 | + | |
| 6078 | + // Move the top banner above the screen options to prevent overlap. | |
| 6079 | + function moveTopBanner() { | |
| 6080 | + const $banner = document.querySelector( '.frm-banner-alert' ) || document.querySelector( '.frm-upgrade-bar' ); | |
| 6081 | + if ( ! $banner ) { | |
| 6082 | + return; | |
| 6083 | + } | |
| 6084 | + | |
| 6085 | + const $screenMeta = document.getElementById( 'screen-meta' ); | |
| 6086 | + if ( ! $screenMeta ) { | |
| 6087 | + return; | |
| 6088 | + } | |
| 6089 | + | |
| 6090 | + const $parentDiv = document.getElementById( 'wpbody-content' ); | |
| 6091 | + $parentDiv.insertBefore( $banner, $screenMeta ); | |
| 6092 | + } | |
| 6093 | + | |
| 6094 | + function getRequiredLicenseFromTrigger( element ) { | |
| 6095 | + if ( element.dataset.requires ) { | |
| 6096 | + return element.dataset.requires; | |
| 6097 | + } | |
| 6098 | + return 'Pro'; | |
| 6099 | + } | |
| 6100 | + | |
| 6101 | + function populateUpgradeTab( element ) { | |
| 6102 | + const title = element.dataset.upgrade; | |
| 6103 | + | |
| 6104 | + const tab = element.getAttribute( 'href' ).replace( '#', '' ); | |
| 6105 | + const container = document.querySelector( '.frm_' + tab ) || document.querySelector( '.' + tab ); | |
| 6106 | + | |
| 6107 | + if ( ! container ) { | |
| 6108 | + return; | |
| 6109 | + } | |
| 6110 | + | |
| 6111 | + if ( container.querySelector( '.frm-upgrade-message' ) ) { | |
| 6112 | + // Tab has already been populated. | |
| 6113 | + return; | |
| 6114 | + } | |
| 6115 | + | |
| 6116 | + const h2 = container.querySelector( 'h2' ); | |
| 6117 | + h2.style.borderBottom = 'none'; | |
| 6118 | + | |
| 6119 | + /* translators: %s: Form Setting section name (ie Form Permissions, Form Scheduling). */ | |
| 6120 | + h2.textContent = __( '%s are not installed' ).replace( '%s', title ); | |
| 6121 | + | |
| 6122 | + container.classList.add( 'frmcenter' ); | |
| 6123 | + | |
| 6124 | + const upgradeModal = document.getElementById( 'frm_upgrade_modal' ); | |
| 6125 | + appendClonedModalElementToContainer( 'frm-oneclick' ); | |
| 6126 | + appendClonedModalElementToContainer( 'frm-addon-status' ); | |
| 6127 | + | |
| 6128 | + // Borrow the call to action from the Upgrade upgradeModal which should exist on the settings page (it is still used for other upgrades including Actions). | |
| 6129 | + const upgradeModalLink = upgradeModal.querySelector( '.frm-upgrade-link' ); | |
| 6130 | + if ( upgradeModalLink ) { | |
| 6131 | + const upgradeButton = upgradeModalLink.cloneNode( true ); | |
| 6132 | + const level = upgradeButton.querySelector( '.license-level' ); | |
| 6133 | + | |
| 6134 | + if ( level ) { | |
| 6135 | + level.textContent = getRequiredLicenseFromTrigger( element ); | |
| 6136 | + } | |
| 6137 | + | |
| 6138 | + container.appendChild( upgradeButton ); | |
| 6139 | + | |
| 6140 | + // Maybe append the secondary "Already purchased?" link from the upgradeModal as well. | |
| 6141 | + if ( upgradeModalLink.nextElementSibling && upgradeModalLink.nextElementSibling.querySelector( '.frm-link-secondary' ) ) { | |
| 6142 | + container.appendChild( upgradeModalLink.nextElementSibling.cloneNode( true ) ); | |
| 6143 | + } | |
| 6144 | + | |
| 6145 | + appendClonedModalElementToContainer( 'frm-oneclick-button' ); | |
| 6146 | + } | |
| 6147 | + | |
| 6148 | + appendClonedModalElementToContainer( 'frm-upgrade-message' ); | |
| 6149 | + addOneClick( element, 'tab', element.dataset.message ); | |
| 6150 | + | |
| 6151 | + if ( element.dataset.screenshot ) { | |
| 6152 | + container.appendChild( getScreenshotWrapper( element.dataset.screenshot ) ); | |
| 6153 | + } | |
| 6154 | + | |
| 6155 | + function appendClonedModalElementToContainer( className ) { | |
| 6156 | + container.appendChild( upgradeModal.querySelector( '.' + className ).cloneNode( true ) ); | |
| 6157 | + } | |
| 6158 | + } | |
| 6159 | + | |
| 6160 | + function getScreenshotWrapper( screenshot ) { | |
| 6161 | + const folderUrl = frmGlobal.url + '/images/screenshots/'; | |
| 6162 | + const wrapper = div({ | |
| 6163 | + className: 'frm-settings-screenshot-wrapper', | |
| 6164 | + children: [ | |
| 6165 | + getToolbar(), | |
| 6166 | + div({ child: img({ src: folderUrl + screenshot }) }) | |
| 6167 | + ] | |
| 6168 | + }); | |
| 6169 | + | |
| 6170 | + function getToolbar() { | |
| 6171 | + const children = getColorIcons(); | |
| 6172 | + children.push( img({ src: frmGlobal.url + '/images/tab.svg' }) ); | |
| 6173 | + return div({ | |
| 6174 | + className: 'frm-settings-screenshot-toolbar', | |
| 6175 | + children | |
| 6176 | + }); | |
| 6177 | + } | |
| 6178 | + | |
| 6179 | + function getColorIcons() { | |
| 6180 | + return [ '#ED8181', '#EDE06A', '#80BE30' ].map( | |
| 6181 | + color => { | |
| 6182 | + const circle = div({ className: 'frm-minmax-icon' }); | |
| 6183 | + circle.style.backgroundColor = color; | |
| 6184 | + return circle; | |
| 6185 | + } | |
| 6186 | + ); | |
| 6187 | + } | |
| 6188 | + | |
| 6189 | + return wrapper; | |
| 6190 | + } | |
| 6191 | + | |
| 6192 | + /** | |
| 6193 | + * Allow addons to be installed from the upgrade modal. | |
| 6194 | + * | |
| 6195 | + * @param {Element} link | |
| 6196 | + * @param {String} context Either 'modal' or 'tab'. | |
| 6197 | + * @param {String|undefined} upgradeLabel | |
| 6198 | + */ | |
| 6199 | + function addOneClick( link, context, upgradeLabel ) { | |
| 6200 | + let container; | |
| 6201 | + | |
| 6202 | + if ( 'modal' === context ) { | |
| 6203 | + container = document.getElementById( 'frm_upgrade_modal' ); | |
| 6204 | + } else if ( 'tab' === context ) { | |
| 6205 | + container = document.getElementById( link.getAttribute( 'href' ).substr( 1 ) ); | |
| 6206 | + } else { | |
| 6207 | + return; | |
| 6208 | + } | |
| 6209 | + | |
| 6210 | + const oneclickMessage = container.querySelector( '.frm-oneclick' ); | |
| 6211 | + const upgradeMessage = container.querySelector( '.frm-upgrade-message' ); | |
| 6212 | + const showLink = container.querySelector( '.frm-upgrade-link' ); | |
| 6213 | + const button = container.querySelector( '.frm-oneclick-button' ); | |
| 6214 | + const addonStatus = container.querySelector( '.frm-addon-status' ); | |
| 6215 | + | |
| 6216 | + let oneclick = link.getAttribute( 'data-oneclick' ); | |
| 6217 | + let newMessage = link.getAttribute( 'data-message' ); | |
| 6218 | + let showIt = 'block'; | |
| 6219 | + let showMsg = 'block'; | |
| 6220 | + let hideIt = 'none'; | |
| 6221 | + | |
| 6222 | + // If one click upgrade, hide other content. | |
| 6223 | + if ( oneclickMessage !== null && typeof oneclick !== 'undefined' && oneclick ) { | |
| 6224 | + if ( newMessage === null ) { | |
| 6225 | + showMsg = 'none'; | |
| 6226 | + } | |
| 6227 | + showIt = 'none'; | |
| 6228 | + hideIt = 'block'; | |
| 6229 | + oneclick = JSON.parse( oneclick ); | |
| 6230 | + | |
| 6231 | + button.className = button.className.replace( ' frm-install-addon', '' ).replace( ' frm-activate-addon', '' ); | |
| 6232 | + button.className = button.className + ' ' + oneclick.class; | |
| 6233 | + button.textContent = __( 'Activate', 'formidable' ); | |
| 6234 | + button.rel = oneclick.url; | |
| 6235 | + } | |
| 6236 | + | |
| 6237 | + if ( ! newMessage ) { | |
| 6238 | + newMessage = upgradeMessage.getAttribute( 'data-default' ); | |
| 6239 | + } | |
| 6240 | + if ( undefined !== upgradeLabel ) { | |
| 6241 | + newMessage = newMessage.replace( '<span class="frm_feature_label"></span>', upgradeLabel ); | |
| 6242 | + } | |
| 6243 | + | |
| 6244 | + upgradeMessage.innerHTML = newMessage; | |
| 6245 | + | |
| 6246 | + // Either set the link or use the default. | |
| 6247 | + showLink.href = getShowLinkHrefValue( link, showLink ); | |
| 6248 | + | |
| 6249 | + addonStatus.style.display = 'none'; | |
| 6250 | + | |
| 6251 | + oneclickMessage.style.display = hideIt; | |
| 6252 | + button.style.display = hideIt === 'block' ? 'inline-block' : hideIt; | |
| 6253 | + upgradeMessage.style.display = showMsg; | |
| 6254 | + showLink.style.display = showIt === 'block' ? 'inline-block' : showIt; | |
| 6255 | + } | |
| 6256 | + | |
| 6257 | + function getShowLinkHrefValue( link, showLink ) { | |
| 6258 | + let customLink = link.getAttribute( 'data-link' ); | |
| 6259 | + if ( customLink === null || typeof customLink === 'undefined' || customLink === '' ) { | |
| 6260 | + customLink = showLink.getAttribute( 'data-default' ); | |
| 6261 | + } | |
| 6262 | + return customLink; | |
| 6263 | + } | |
| 6264 | + | |
| 6265 | + /* Form settings */ | |
| 6266 | + | |
| 6267 | + function showInputIcon( parentClass ) { | |
| 6268 | + if ( typeof parentClass === 'undefined' ) { | |
| 6269 | + parentClass = ''; | |
| 6270 | + } | |
| 6271 | + maybeAddFieldSelection( parentClass ); | |
| 6272 | + 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>' ); | |
| 6273 | + } | |
| 6274 | + | |
| 6275 | + /** | |
| 6276 | + * For reverse compatibility. Check for fields that were | |
| 6277 | + * using the old sidebar. | |
| 6278 | + */ | |
| 6279 | + function maybeAddFieldSelection( parentClass ) { | |
| 6280 | + var i, | |
| 6281 | + 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' ); | |
| 6282 | + for ( i = 0; i < missingClass.length; i++ ) { | |
| 6283 | + missingClass[i].parentNode.classList.add( 'frm_has_shortcodes' ); | |
| 6284 | + } | |
| 6285 | + } | |
| 6286 | + | |
| 6287 | + function showSuccessOpt() { | |
| 6288 | + /*jshint validthis:true */ | |
| 6289 | + var c = 'success'; | |
| 6290 | + if ( this.name === 'options[edit_action]' ) { | |
| 6291 | + c = 'edit'; | |
| 6292 | + } | |
| 6293 | + var v = jQuery( this ).val(); | |
| 6294 | + jQuery( '.' + c + '_action_box' ).hide(); | |
| 6295 | + if ( v === 'redirect' ) { | |
| 6296 | + jQuery( '.' + c + '_action_redirect_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 6297 | + } else if ( v === 'page' ) { | |
| 6298 | + jQuery( '.' + c + '_action_page_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 6299 | + } else { | |
| 6300 | + jQuery( '.' + c + '_action_message_box.' + c + '_action_box' ).fadeIn( 'slow' ); | |
| 6301 | + } | |
| 6302 | + } | |
| 6303 | + | |
| 6304 | + function copyFormAction( event ) { | |
| 6305 | + if ( waitForActionToLoadBeforeCopy( event.target ) ) { | |
| 6306 | + return; | |
| 6307 | + } | |
| 6308 | + | |
| 6309 | + const targetSettings = event.target.closest( '.frm_form_action_settings' ); | |
| 6310 | + const wysiwyg = targetSettings.querySelector( '.wp-editor-area' ); | |
| 6311 | + if ( wysiwyg ) { | |
| 6312 | + // Temporary remove TinyMCE before cloning to avoid TinyMCE conflicts. | |
| 6313 | + tinymce.EditorManager.execCommand( 'mceRemoveEditor', true, wysiwyg.id ); | |
| 6314 | + } | |
| 6315 | + | |
| 6316 | + const $action = jQuery( targetSettings ).clone(); | |
| 6317 | + const currentID = $action.attr( 'id' ).replace( 'frm_form_action_', '' ); | |
| 6318 | + const newID = newActionId( currentID ); | |
| 6319 | + | |
| 6320 | + $action.find( '.frm_action_id, .frm-btn-group' ).remove(); | |
| 6321 | + $action.find( 'input[name$="[' + currentID + '][ID]"]' ).val( '' ); | |
| 6322 | + $action.find( '.widget-inside' ).hide(); | |
| 6323 | + | |
| 6324 | + // the .html() gets original values, so they need to be set | |
| 6325 | + $action.find( 'input[type=text], textarea, input[type=number]' ).prop( 'defaultValue', function() { | |
| 6326 | + return this.value; | |
| 6327 | + }); | |
| 6328 | + | |
| 6329 | + $action.find( 'input[type=checkbox], input[type=radio]' ).prop( 'defaultChecked', function() { | |
| 6330 | + return this.checked; | |
| 6331 | + }); | |
| 6332 | + | |
| 6333 | + const rename = new RegExp( '\\[' + currentID + '\\]', 'g' ); | |
| 6334 | + const reid = new RegExp( '_' + currentID + '"', 'g' ); | |
| 6335 | + const reclass = new RegExp( '-' + currentID + '"', 'g' ); | |
| 6336 | + const revalue = new RegExp( '"' + currentID + '"', 'g' ); // if a field id matches, this could cause trouble | |
| 6337 | + | |
| 6338 | + let html = $action.html().replace( rename, '[' + newID + ']' ).replace( reid, '_' + newID + '"' ); | |
| 6339 | + html = html.replace( reclass, '-' + newID + '"' ).replace( revalue, '"' + newID + '"' ); | |
| 6340 | + | |
| 6341 | + const newAction = div({ | |
| 6342 | + id: 'frm_form_action_' + newID, | |
| 6343 | + className: $action.get( 0 ).className | |
| 6344 | + }); | |
| 6345 | + newAction.setAttribute( 'data-actionkey', newID ); | |
| 6346 | + newAction.innerHTML = html; | |
| 6347 | + newAction.querySelectorAll( '.wp-editor-wrap, .wp-editor-wrap *' ).forEach( | |
| 6348 | + element => { | |
| 6349 | + if ( 'string' === typeof element.className ) { | |
| 6350 | + element.className = element.className.replace( currentID, newID ); | |
| 6351 | + } | |
| 6352 | + element.id = element.id.replace( currentID, newID ); | |
| 6353 | + } | |
| 6354 | + ); | |
| 6355 | + newAction.classList.remove( 'open' ); | |
| 6356 | + document.getElementById( 'frm_notification_settings' ).appendChild( newAction ); | |
| 6357 | + | |
| 6358 | + if ( wysiwyg ) { | |
| 6359 | + // Re-initialize the original wysiwyg which was removed before cloning. | |
| 6360 | + frmDom.wysiwyg.init( wysiwyg ); | |
| 6361 | + frmDom.wysiwyg.init( newAction.querySelector( '.wp-editor-area' ) ); | |
| 6362 | + } | |
| 6363 | + | |
| 6364 | + if ( newAction.classList.contains( 'frm_single_on_submit_settings' ) ) { | |
| 6365 | + const autocompleteInput = newAction.querySelector( 'input.frm-page-search' ); | |
| 6366 | + if ( autocompleteInput ) { | |
| 6367 | + frmDom.autocomplete.initAutocomplete( 'page', newAction ); | |
| 6368 | + } | |
| 6369 | + } | |
| 6370 | + | |
| 6371 | + initiateMultiselect(); | |
| 6372 | + | |
| 6373 | + const hookName = 'frm_after_duplicate_action'; | |
| 6374 | + wp.hooks.doAction( hookName, newAction ); | |
| 6375 | + } | |
| 6376 | + | |
| 6377 | + function waitForActionToLoadBeforeCopy( element ) { | |
| 6378 | + var $trigger = jQuery( element ), | |
| 6379 | + $original = $trigger.closest( '.frm_form_action_settings' ), | |
| 6380 | + $inside = $original.find( '.widget-inside' ), | |
| 6381 | + $top; | |
| 6382 | + | |
| 6383 | + if ( $inside.find( 'p, div, table' ).length ) { | |
| 6384 | + return false; | |
| 6385 | + } | |
| 6386 | + | |
| 6387 | + $top = $original.find( '.widget-top' ); | |
| 6388 | + $top.on( 'frm-action-loaded', function() { | |
| 6389 | + $trigger.trigger( 'click' ); | |
| 6390 | + $original.removeClass( 'open' ); | |
| 6391 | + $inside.hide(); | |
| 6392 | + }); | |
| 6393 | + $top.trigger( 'click' ); | |
| 6394 | + return true; | |
| 6395 | + } | |
| 6396 | + | |
| 6397 | + function newActionId( currentID ) { | |
| 6398 | + var newID = parseInt( currentID, 10 ) + 11; | |
| 6399 | + var exists = document.getElementById( 'frm_form_action_' + newID ); | |
| 6400 | + if ( exists !== null ) { | |
| 6401 | + newID++; | |
| 6402 | + newID = newActionId( newID ); | |
| 6403 | + } | |
| 6404 | + return newID; | |
| 6405 | + } | |
| 6406 | + | |
| 6407 | + function addFormAction() { | |
| 6408 | + /*jshint validthis:true */ | |
| 6409 | + const type = jQuery( this ).data( 'actiontype' ); | |
| 6410 | + | |
| 6411 | + if ( isAtLimitForActionType( type ) ) { | |
| 6412 | + return; | |
| 6413 | + } | |
| 6414 | + | |
| 6415 | + const actionId = getNewActionId(); | |
| 6416 | + const formId = thisFormId; | |
| 6417 | + | |
| 6418 | + const placeholderSetting = document.createElement( 'div' ); | |
| 6419 | + placeholderSetting.classList.add( 'frm_single_' + type + '_settings' ); | |
| 6420 | + | |
| 6421 | + const actionsList = document.getElementById( 'frm_notification_settings' ); | |
| 6422 | + actionsList.appendChild( placeholderSetting ); | |
| 6423 | + | |
| 6424 | + jQuery.ajax({ | |
| 6425 | + type: 'POST', | |
| 6426 | + url: ajaxurl, | |
| 6427 | + data: { | |
| 6428 | + action: 'frm_add_form_action', | |
| 6429 | + type: type, | |
| 6430 | + list_id: actionId, | |
| 6431 | + form_id: formId, | |
| 6432 | + nonce: frmGlobal.nonce | |
| 6433 | + }, | |
| 6434 | + success: handleAddFormActionSuccess | |
| 6435 | + }); | |
| 6436 | + | |
| 6437 | + function handleAddFormActionSuccess( html ) { | |
| 6438 | + fieldUpdated(); | |
| 6439 | + placeholderSetting.remove(); | |
| 6440 | + | |
| 6441 | + closeOpenActions(); | |
| 6442 | + | |
| 6443 | + const newActionContainer = div(); | |
| 6444 | + newActionContainer.innerHTML = html; | |
| 6445 | + | |
| 6446 | + const widgetTop = newActionContainer.querySelector( '.widget-top' ); | |
| 6447 | + Array.from( newActionContainer.children ).forEach( child => actionsList.appendChild( child ) ); | |
| 6448 | + | |
| 6449 | + jQuery( '.frm_form_action_settings' ).fadeIn( 'slow' ); | |
| 6450 | + | |
| 6451 | + const newAction = document.getElementById( 'frm_form_action_' + actionId ); | |
| 6452 | + | |
| 6453 | + newAction.classList.add( 'open' ); | |
| 6454 | + document.getElementById( 'post-body-content' ).scroll({ | |
| 6455 | + top: newAction.offsetTop + 10, | |
| 6456 | + left: 0, | |
| 6457 | + behavior: 'smooth' | |
| 6458 | + }); | |
| 6459 | + | |
| 6460 | + // Check if icon should be active | |
| 6461 | + checkActiveAction( type ); | |
| 6462 | + showInputIcon( '#frm_form_action_' + actionId ); | |
| 6463 | + | |
| 6464 | + initiateMultiselect(); | |
| 6465 | + frmDom.autocomplete.initAutocomplete( 'page', newAction ); | |
| 6466 | + | |
| 6467 | + if ( widgetTop ) { | |
| 6468 | + jQuery( widgetTop ).trigger( 'frm-action-loaded' ); | |
| 6469 | + } | |
| 6470 | + | |
| 6471 | + /** | |
| 6472 | + * Fires after added a new form action. | |
| 6473 | + * | |
| 6474 | + * @since 5.5.4 | |
| 6475 | + * | |
| 6476 | + * @param {HTMLElement} formAction Form action element. | |
| 6477 | + */ | |
| 6478 | + frmAdminBuild.hooks.doAction( 'frm_added_form_action', newAction ); | |
| 6479 | + } | |
| 6480 | + } | |
| 6481 | + | |
| 6482 | + function closeOpenActions() { | |
| 6483 | + document.querySelectorAll( '.frm_form_action_settings.open' ).forEach( | |
| 6484 | + setting => setting.classList.remove( 'open' ) | |
| 6485 | + ); | |
| 6486 | + } | |
| 6487 | + | |
| 6488 | + function toggleActionGroups() { | |
| 6489 | + /*jshint validthis:true */ | |
| 6490 | + var actions = document.getElementById( 'frm_email_addon_menu' ).classList, | |
| 6491 | + search = document.getElementById( 'actions-search-input' ); | |
| 6492 | + | |
| 6493 | + if ( actions.contains( 'frm-all-actions' ) ) { | |
| 6494 | + actions.remove( 'frm-all-actions' ); | |
| 6495 | + actions.add( 'frm-limited-actions' ); | |
| 6496 | + } else { | |
| 6497 | + actions.add( 'frm-all-actions' ); | |
| 6498 | + actions.remove( 'frm-limited-actions' ); | |
| 6499 | + } | |
| 6500 | + | |
| 6501 | + // Reset search. | |
| 6502 | + search.value = ''; | |
| 6503 | + triggerEvent( search, 'input' ); | |
| 6504 | + } | |
| 6505 | + | |
| 6506 | + function getNewActionId() { | |
| 6507 | + var actionSettings = document.querySelectorAll( '.frm_form_action_settings' ), | |
| 6508 | + len = getNewRowId( actionSettings, 'frm_form_action_' ); | |
| 6509 | + if ( typeof document.getElementById( 'frm_form_action_' + len ) !== 'undefined' ) { | |
| 6510 | + len = len + 100; | |
| 6511 | + } | |
| 6512 | + if ( lastNewActionIdReturned >= len ) { | |
| 6513 | + len = lastNewActionIdReturned + 1; | |
| 6514 | + } | |
| 6515 | + lastNewActionIdReturned = len; | |
| 6516 | + return len; | |
| 6517 | + } | |
| 6518 | + | |
| 6519 | + function clickAction( obj ) { | |
| 6520 | + var $thisobj = jQuery( obj ); | |
| 6521 | + | |
| 6522 | + if ( obj.className.indexOf( 'selected' ) !== -1 ) { | |
| 6523 | + return; | |
| 6524 | + } | |
| 6525 | + if ( obj.className.indexOf( 'edit_field_type_end_divider' ) !== -1 && $thisobj.closest( '.edit_field_type_divider' ).hasClass( 'no_repeat_section' ) ) { | |
| 6526 | + return; | |
| 6527 | + } | |
| 6528 | + | |
| 6529 | + deselectFields(); | |
| 6530 | + $thisobj.addClass( 'selected' ); | |
| 6531 | + showFieldOptions( obj ); | |
| 6532 | + } | |
| 6533 | + | |
| 6534 | + /** | |
| 6535 | + * When a field is selected, show the field settings in the sidebar. | |
| 6536 | + */ | |
| 6537 | + function showFieldOptions( obj ) { | |
| 6538 | + var i, singleField, | |
| 6539 | + fieldId = obj.getAttribute( 'data-fid' ), | |
| 6540 | + fieldType = obj.getAttribute( 'data-type' ), | |
| 6541 | + allFieldSettings = document.querySelectorAll( '.frm-single-settings:not(.frm_hidden)' ); | |
| 6542 | + | |
| 6543 | + for ( i = 0; i < allFieldSettings.length; i++ ) { | |
| 6544 | + allFieldSettings[i].classList.add( 'frm_hidden' ); | |
| 6545 | + } | |
| 6546 | + | |
| 6547 | + singleField = document.getElementById( 'frm-single-settings-' + fieldId ); | |
| 6548 | + moveFieldSettings( singleField ); | |
| 6549 | + | |
| 6550 | + if ( fieldType && 'quantity' === fieldType ) { | |
| 6551 | + popProductFields( jQuery( singleField ).find( '.frmjs_prod_field_opt' )[0]); | |
| 6552 | + } | |
| 6553 | + | |
| 6554 | + singleField.classList.remove( 'frm_hidden' ); | |
| 6555 | + document.getElementById( 'frm-options-panel-tab' ).click(); | |
| 6556 | + | |
| 6557 | + const editor = singleField.querySelector( '.wp-editor-area' ); | |
| 6558 | + if ( editor ) { | |
| 6559 | + frmDom.wysiwyg.init( | |
| 6560 | + editor, | |
| 6561 | + { setupCallback: setupTinyMceEventHandlers } | |
| 6562 | + ); | |
| 6563 | + } | |
| 6564 | + } | |
| 6565 | + | |
| 6566 | + function setupTinyMceEventHandlers( editor ) { | |
| 6567 | + editor.on( 'Change', function() { | |
| 6568 | + handleTinyMceChange( editor ); | |
| 6569 | + }); | |
| 6570 | + } | |
| 6571 | + | |
| 6572 | + function handleTinyMceChange( editor ) { | |
| 6573 | + if ( ! isTinyMceActive() || tinyMCE.activeEditor.isHidden() ) { | |
| 6574 | + return; | |
| 6575 | + } | |
| 6576 | + | |
| 6577 | + editor.targetElm.value = editor.getContent(); | |
| 6578 | + jQuery( editor.targetElm ).trigger( 'change' ); | |
| 6579 | + } | |
| 6580 | + | |
| 6581 | + function isTinyMceActive() { | |
| 6582 | + var activeSettings, wrapper; | |
| 6583 | + | |
| 6584 | + activeSettings = document.querySelector( '.frm-single-settings:not(.frm_hidden)' ); | |
| 6585 | + if ( ! activeSettings ) { | |
| 6586 | + return false; | |
| 6587 | + } | |
| 6588 | + | |
| 6589 | + wrapper = activeSettings.querySelector( '.wp-editor-wrap' ); | |
| 6590 | + return null !== wrapper && wrapper.classList.contains( 'tmce-active' ); | |
| 6591 | + } | |
| 6592 | + | |
| 6593 | + /** | |
| 6594 | + * Move the settings to the sidebar the first time they are changed or selected. | |
| 6595 | + * Keep the end marker at the end of the form. | |
| 6596 | + */ | |
| 6597 | + function moveFieldSettings( singleField ) { | |
| 6598 | + if ( singleField === null ) { | |
| 6599 | + // The field may have not been loaded yet via ajax. | |
| 6600 | + return; | |
| 6601 | + } | |
| 6602 | + | |
| 6603 | + var classes = singleField.parentElement.classList; | |
| 6604 | + if ( classes.contains( 'frm_field_box' ) || classes.contains( 'divider_section_only' ) ) { | |
| 6605 | + var endMarker = document.getElementById( 'frm-end-form-marker' ); | |
| 6606 | + builderForm.insertBefore( singleField, endMarker ); | |
| 6607 | + } | |
| 6608 | + } | |
| 6609 | + | |
| 6610 | + function showEmailRow() { | |
| 6611 | + /*jshint validthis:true */ | |
| 6612 | + var actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ); | |
| 6613 | + var rowType = this.getAttribute( 'data-emailrow' ); | |
| 6614 | + | |
| 6615 | + jQuery( '#frm_form_action_' + actionKey + ' .frm_' + rowType + '_row' ).fadeIn( 'slow' ); | |
| 6616 | + jQuery( this ).fadeOut( 'slow' ); | |
| 6617 | + } | |
| 6618 | + | |
| 6619 | + function hideEmailRow() { | |
| 6620 | + /*jshint validthis:true */ | |
| 6621 | + var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ), | |
| 6622 | + rowType = this.getAttribute( 'data-emailrow' ), | |
| 6623 | + emailRowSelector = '.frm_' + rowType + '_row', | |
| 6624 | + emailButtonSelector = '.frm_' + rowType + '_button'; | |
| 6625 | + | |
| 6626 | + jQuery( actionBox ).find( emailButtonSelector ).fadeIn( 'slow' ); | |
| 6627 | + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow', function() { | |
| 6628 | + jQuery( actionBox ).find( emailRowSelector + ' input' ).val( '' ); | |
| 6629 | + }); | |
| 6630 | + } | |
| 6631 | + | |
| 6632 | + function showEmailWarning() { | |
| 6633 | + /*jshint validthis:true */ | |
| 6634 | + var actionBox = jQuery( this ).closest( '.frm_form_action_settings' ), | |
| 6635 | + emailRowSelector = '.frm_from_to_match_row', | |
| 6636 | + fromVal = actionBox.find( 'input[name$="[post_content][from]"]' ).val(), | |
| 6637 | + toVal = actionBox.find( 'input[name$="[post_content][email_to]"]' ).val(); | |
| 6638 | + | |
| 6639 | + if ( fromVal === toVal ) { | |
| 6640 | + jQuery( actionBox ).find( emailRowSelector ).fadeIn( 'slow' ); | |
| 6641 | + } else { | |
| 6642 | + jQuery( actionBox ).find( emailRowSelector ).fadeOut( 'slow' ); | |
| 6643 | + } | |
| 6644 | + } | |
| 6645 | + | |
| 6646 | + function checkActiveAction( type ) { | |
| 6647 | + const actionTriggers = document.querySelectorAll( '.frm_' + type + '_action' ); | |
| 6648 | + | |
| 6649 | + if ( isAtLimitForActionType( type ) ) { | |
| 6650 | + const addAlreadyUsedClass = getLimitForActionType( type ) > 0; | |
| 6651 | + markActionTriggersInactive( actionTriggers, addAlreadyUsedClass ); | |
| 6652 | + return; | |
| 6653 | + } | |
| 6654 | + | |
| 6655 | + markActionTriggersActive( actionTriggers ); | |
| 6656 | + } | |
| 6657 | + | |
| 6658 | + function markActionTriggersActive( triggers ) { | |
| 6659 | + triggers.forEach( | |
| 6660 | + trigger => { | |
| 6661 | + if ( trigger.querySelector( '.frm_show_upgrade' ) ) { | |
| 6662 | + // Prevent disabled action becoming active. | |
| 6663 | + return; | |
| 6664 | + } | |
| 6665 | + | |
| 6666 | + trigger.classList.remove( 'frm_inactive_action', 'frm_already_used' ); | |
| 6667 | + trigger.classList.add( 'frm_active_action' ); | |
| 6668 | + } | |
| 6669 | + ); | |
| 6670 | + } | |
| 6671 | + | |
| 6672 | + function markActionTriggersInactive( triggers, addAlreadyUsedClass ) { | |
| 6673 | + triggers.forEach( | |
| 6674 | + trigger => { | |
| 6675 | + trigger.classList.remove( 'frm_active_action' ); | |
| 6676 | + trigger.classList.add( 'frm_inactive_action' ); | |
| 6677 | + if ( addAlreadyUsedClass ) { | |
| 6678 | + trigger.classList.add( 'frm_already_used' ); | |
| 6679 | + } | |
| 6680 | + } | |
| 6681 | + ); | |
| 6682 | + } | |
| 6683 | + | |
| 6684 | + function isAtLimitForActionType( type ) { | |
| 6685 | + let atLimit = getNumberOfActionsForType( type ) >= getLimitForActionType( type ); | |
| 6686 | + | |
| 6687 | + const hookName = 'frm_action_at_limit'; | |
| 6688 | + const hookArgs = { type }; | |
| 6689 | + atLimit = wp.hooks.applyFilters( hookName, atLimit, hookArgs ); | |
| 6690 | + | |
| 6691 | + return atLimit; | |
| 6692 | + } | |
| 6693 | + | |
| 6694 | + function getLimitForActionType( type ) { | |
| 6695 | + return parseInt( jQuery( '.frm_' + type + '_action' ).data( 'limit' ), 10 ); | |
| 6696 | + } | |
| 6697 | + | |
| 6698 | + function getNumberOfActionsForType( type ) { | |
| 6699 | + return jQuery( '.frm_single_' + type + '_settings' ).length; | |
| 6700 | + } | |
| 6701 | + | |
| 6702 | + function onlyOneActionMessage() { | |
| 6703 | + infoModal( frm_admin_js.only_one_action ); | |
| 6704 | + } | |
| 6705 | + | |
| 6706 | + function addFormLogicRow() { | |
| 6707 | + /*jshint validthis:true */ | |
| 6708 | + var id = jQuery( this ).data( 'emailkey' ), | |
| 6709 | + type = jQuery( this ).closest( '.frm_form_action_settings' ).find( '.frm_action_name' ).val(), | |
| 6710 | + formId = document.getElementById( 'form_id' ).value, | |
| 6711 | + logicRows = document.getElementById( 'frm_form_action_' + id ).querySelectorAll( '.frm_logic_row' ); | |
| 6712 | + jQuery.ajax({ | |
| 6713 | + type: 'POST', url: ajaxurl, | |
| 6714 | + data: { | |
| 6715 | + action: 'frm_add_form_logic_row', | |
| 6716 | + email_id: id, | |
| 6717 | + form_id: formId, | |
| 6718 | + meta_name: getNewRowId( logicRows, 'frm_logic_' + id + '_' ), | |
| 6719 | + type: type, | |
| 6720 | + nonce: frmGlobal.nonce | |
| 6721 | + }, | |
| 6722 | + success: function( html ) { | |
| 6723 | + jQuery( document.getElementById( 'logic_link_' + id ) ).fadeOut( 'slow', function() { | |
| 6724 | + var $logicRow = jQuery( document.getElementById( 'frm_logic_row_' + id ) ); | |
| 6725 | + $logicRow.append( html ); | |
| 6726 | + $logicRow.parent( '.frm_logic_rows' ).fadeIn( 'slow' ); | |
| 6727 | + }); | |
| 6728 | + } | |
| 6729 | + }); | |
| 6730 | + return false; | |
| 6731 | + } | |
| 6732 | + | |
| 6733 | + function toggleSubmitLogic() { | |
| 6734 | + /*jshint validthis:true */ | |
| 6735 | + if ( this.checked ) { | |
| 6736 | + addSubmitLogic(); | |
| 6737 | + } else { | |
| 6738 | + jQuery( '.frm_logic_row_submit' ).remove(); | |
| 6739 | + document.getElementById( 'frm_submit_logic_rows' ).style.display = 'none'; | |
| 6740 | + } | |
| 6741 | + } | |
| 6742 | + | |
| 6743 | + /** | |
| 6744 | + * Adds submit button Conditional Logic row and reveals submit button Conditional Logic | |
| 6745 | + * | |
| 6746 | + * @returns {boolean} | |
| 6747 | + */ | |
| 6748 | + function addSubmitLogic() { | |
| 6749 | + /*jshint validthis:true */ | |
| 6750 | + var formId = thisFormId, | |
| 6751 | + logicRows = document.getElementById( 'frm_submit_logic_row' ).querySelectorAll( '.frm_logic_row' ); | |
| 6752 | + jQuery.ajax({ | |
| 6753 | + type: 'POST', | |
| 6754 | + url: ajaxurl, | |
| 6755 | + data: { | |
| 6756 | + action: 'frm_add_submit_logic_row', | |
| 6757 | + form_id: formId, | |
| 6758 | + meta_name: getNewRowId( logicRows, 'frm_logic_submit_' ), | |
| 6759 | + nonce: frmGlobal.nonce | |
| 6760 | + }, | |
| 6761 | + success: function( html ) { | |
| 6762 | + var $logicRow = jQuery( document.getElementById( 'frm_submit_logic_row' ) ); | |
| 6763 | + $logicRow.append( html ); | |
| 6764 | + $logicRow.parent( '.frm_submit_logic_rows' ).fadeIn( 'slow' ); | |
| 6765 | + } | |
| 6766 | + }); | |
| 6767 | + return false; | |
| 6768 | + } | |
| 6769 | + | |
| 6770 | + /** | |
| 6771 | + * When the user selects a field for a submit condition, update corresponding options field accordingly. | |
| 6772 | + */ | |
| 6773 | + function addSubmitLogicOpts() { | |
| 6774 | + var fieldOpt = jQuery( this ); | |
| 6775 | + var fieldId = fieldOpt.find( ':selected' ).val(); | |
| 6776 | + | |
| 6777 | + if ( fieldId ) { | |
| 6778 | + var row = fieldOpt.data( 'row' ); | |
| 6779 | + frmGetFieldValues( fieldId, 'submit', row, '', 'options[submit_conditions][hide_opt][]' ); | |
| 6780 | + } | |
| 6781 | + } | |
| 6782 | + | |
| 6783 | + function formatEmailSetting() { | |
| 6784 | + /*jshint validthis:true */ | |
| 6785 | + /*var val = jQuery( this ).val(); | |
| 6786 | + var email = val.match( /(\s[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi ); | |
| 6787 | + if(email !== null && email.length) { | |
| 6788 | + //has email | |
| 6789 | + //TODO: add < > if they aren't there | |
| 6790 | + }*/ | |
| 6791 | + } | |
| 6792 | + | |
| 6793 | + function showFormMessages() { | |
| 6794 | + var show = false; | |
| 6795 | + var editable = document.getElementById( 'editable' ); | |
| 6796 | + if ( editable !== null ) { | |
| 6797 | + show = editable.checked && jQuery( document.getElementById( 'edit_action' ) ).val() === 'message'; | |
| 6798 | + if ( ! show ) { | |
| 6799 | + show = isChecked( 'save_draft' ); | |
| 6800 | + } | |
| 6801 | + } | |
| 6802 | + return show; | |
| 6803 | + } | |
| 6804 | + | |
| 6805 | + function checkDupPost() { | |
| 6806 | + /*jshint validthis:true */ | |
| 6807 | + var postField = jQuery( 'select.frm_single_post_field' ); | |
| 6808 | + postField.css( 'border-color', '' ); | |
| 6809 | + var $t = this; | |
| 6810 | + var v = jQuery( $t ).val(); | |
| 6811 | + if ( v === '' || v === 'checkbox' ) { | |
| 6812 | + return false; | |
| 6813 | + } | |
| 6814 | + postField.each( function() { | |
| 6815 | + if ( jQuery( this ).val() === v && this.name !== $t.name ) { | |
| 6816 | + this.style.borderColor = 'red'; | |
| 6817 | + jQuery( $t ).val( '' ); | |
| 6818 | + infoModal( frm_admin_js.field_already_used ); | |
| 6819 | + return false; | |
| 6820 | + } | |
| 6821 | + }); | |
| 6822 | + } | |
| 6823 | + | |
| 6824 | + function togglePostContent() { | |
| 6825 | + /*jshint validthis:true */ | |
| 6826 | + var v = jQuery( this ).val(); | |
| 6827 | + if ( '' === v ) { | |
| 6828 | + jQuery( '.frm_post_content_opt, select.frm_dyncontent_opt' ).hide().val( '' ); | |
| 6829 | + jQuery( '.frm_dyncontent_opt' ).hide(); | |
| 6830 | + } else if ( 'post_content' === v ) { | |
| 6831 | + jQuery( '.frm_post_content_opt' ).show(); | |
| 6832 | + jQuery( '.frm_dyncontent_opt' ).hide(); | |
| 6833 | + jQuery( 'select.frm_dyncontent_opt' ).val( '' ); | |
| 6834 | + } else { | |
| 6835 | + jQuery( '.frm_post_content_opt' ).hide().val( '' ); | |
| 6836 | + jQuery( 'select.frm_dyncontent_opt, .frm_form_field.frm_dyncontent_opt' ).show(); | |
| 6837 | + } | |
| 6838 | + } | |
| 6839 | + | |
| 6840 | + function fillDyncontent() { | |
| 6841 | + /*jshint validthis:true */ | |
| 6842 | + var v = jQuery( this ).val(); | |
| 6843 | + var $dyn = jQuery( document.getElementById( 'frm_dyncontent' ) ); | |
| 6844 | + if ( '' === v || 'new' === v ) { | |
| 6845 | + $dyn.val( '' ); | |
| 6846 | + jQuery( '.frm_dyncontent_opt' ).show(); | |
| 6847 | + } else { | |
| 6848 | + jQuery.ajax({ | |
| 6849 | + type: 'POST', url: ajaxurl, | |
| 6850 | + data: {action: 'frm_display_get_content', id: v, nonce: frmGlobal.nonce}, | |
| 6851 | + success: function( val ) { | |
| 6852 | + $dyn.val( val ); | |
| 6853 | + jQuery( '.frm_dyncontent_opt' ).show(); | |
| 6854 | + } | |
| 6855 | + }); | |
| 6856 | + } | |
| 6857 | + } | |
| 6858 | + | |
| 6859 | + function switchPostType() { | |
| 6860 | + /*jshint validthis:true */ | |
| 6861 | + // update all rows of categories/taxonomies | |
| 6862 | + var curSelect, newSelect, | |
| 6863 | + catRows = document.getElementById( 'frm_posttax_rows' ).childNodes, | |
| 6864 | + postParentField = document.querySelector( '.frm_post_parent_field' ), | |
| 6865 | + postMenuOrderField = document.querySelector( '.frm_post_menu_order_field' ), | |
| 6866 | + postType = this.value; | |
| 6867 | + | |
| 6868 | + // Get new category/taxonomy options | |
| 6869 | + jQuery.ajax({ | |
| 6870 | + type: 'POST', | |
| 6871 | + url: ajaxurl, | |
| 6872 | + data: { | |
| 6873 | + action: 'frm_replace_posttax_options', | |
| 6874 | + post_type: postType, | |
| 6875 | + nonce: frmGlobal.nonce | |
| 6876 | + }, | |
| 6877 | + success: function( html ) { | |
| 6878 | + | |
| 6879 | + // Loop through each category row, and replace the first dropdown | |
| 6880 | + for ( i = 0; i < catRows.length; i++ ) { | |
| 6881 | + // Check if current element is a div | |
| 6882 | + if ( catRows[i].tagName !== 'DIV' ) { | |
| 6883 | + continue; | |
| 6884 | + } | |
| 6885 | + | |
| 6886 | + // Get current category select | |
| 6887 | + curSelect = catRows[i].getElementsByTagName( 'select' )[0]; | |
| 6888 | + | |
| 6889 | + // Set up new select | |
| 6890 | + newSelect = document.createElement( 'select' ); | |
| 6891 | + newSelect.innerHTML = html; | |
| 6892 | + newSelect.className = curSelect.className; | |
| 6893 | + newSelect.name = curSelect.name; | |
| 6894 | + | |
| 6895 | + // Replace the old select with the new select | |
| 6896 | + catRows[i].replaceChild( newSelect, curSelect ); | |
| 6897 | + } | |
| 6898 | + } | |
| 6899 | + }); | |
| 6900 | + | |
| 6901 | + // Get new post parent option. | |
| 6902 | + if ( postParentField ) { | |
| 6903 | + getActionOption( | |
| 6904 | + postParentField, | |
| 6905 | + postType, | |
| 6906 | + 'frm_get_post_parent_option', | |
| 6907 | + function( response, optName ) { | |
| 6908 | + // The replaced string is declared in FrmProFormActionController::ajax_get_post_menu_order_option() in the pro version. | |
| 6909 | + postParentField.querySelector( '.frm_post_parent_opt_wrapper' ).innerHTML = response.replaceAll( 'REPLACETHISNAME', optName ); | |
| 6910 | + frmDom.autocomplete.initAutocomplete( 'page', postParentField ); | |
| 6911 | + } | |
| 6912 | + ); | |
| 6913 | + } | |
| 6914 | + | |
| 6915 | + if ( postMenuOrderField ) { | |
| 6916 | + getActionOption( postMenuOrderField, postType, 'frm_should_use_post_menu_order_option' ); | |
| 6917 | + } | |
| 6918 | + } | |
| 6919 | + | |
| 6920 | + function getActionOption( field, postType, action, successHandler ) { | |
| 6921 | + const opt = field.querySelector( '.frm_autocomplete_value_input' ) || field.querySelector( 'select' ), | |
| 6922 | + optName = opt.getAttribute( 'name' ); | |
| 6923 | + | |
| 6924 | + jQuery.ajax({ | |
| 6925 | + url: ajaxurl, | |
| 6926 | + method: 'POST', | |
| 6927 | + data: { | |
| 6928 | + action: action, | |
| 6929 | + post_type: postType, | |
| 6930 | + _wpnonce: frmGlobal.nonce | |
| 6931 | + }, | |
| 6932 | + success: response => { | |
| 6933 | + if ( 'string' !== typeof response ) { | |
| 6934 | + console.error( response ); | |
| 6935 | + return; | |
| 6936 | + } | |
| 6937 | + | |
| 6938 | + if ( '0' === response ) { | |
| 6939 | + // This post type does not support this field. | |
| 6940 | + field.classList.add( 'frm_hidden' ); | |
| 6941 | + field.value = ''; | |
| 6942 | + return; | |
| 6943 | + } | |
| 6944 | + | |
| 6945 | + field.classList.remove( 'frm_hidden' ); | |
| 6946 | + | |
| 6947 | + if ( 'function' === typeof successHandler ) { | |
| 6948 | + successHandler( response, optName ); | |
| 6949 | + } | |
| 6950 | + }, | |
| 6951 | + error: response => console.error( response ) | |
| 6952 | + }); | |
| 6953 | + } | |
| 6954 | + | |
| 6955 | + function addPosttaxRow() { | |
| 6956 | + /*jshint validthis:true */ | |
| 6957 | + addPostRow( 'tax', this ); | |
| 6958 | + } | |
| 6959 | + | |
| 6960 | + function addPostmetaRow() { | |
| 6961 | + /*jshint validthis:true */ | |
| 6962 | + addPostRow( 'meta', this ); | |
| 6963 | + } | |
| 6964 | + | |
| 6965 | + function addPostRow( type, button ) { | |
| 6966 | + var name, | |
| 6967 | + id = jQuery( 'input[name="id"]' ).val(), | |
| 6968 | + settings = jQuery( button ).closest( '.frm_form_action_settings' ), | |
| 6969 | + key = settings.data( 'actionkey' ), | |
| 6970 | + postType = settings.find( '.frm_post_type' ).val(), | |
| 6971 | + metaName = 0, | |
| 6972 | + postTypeRows = document.querySelectorAll( '.frm_post' + type + '_row' ); | |
| 6973 | + | |
| 6974 | + if ( postTypeRows.length ) { | |
| 6975 | + name = postTypeRows[ postTypeRows.length - 1 ].id.replace( 'frm_post' + type + '_', '' ); | |
| 6976 | + if ( isNumeric( name ) ) { | |
| 6977 | + metaName = 1 + parseInt( name, 10 ); | |
| 6978 | + } else { | |
| 6979 | + metaName = 1; | |
| 6980 | + } | |
| 6981 | + } | |
| 6982 | + | |
| 6983 | + jQuery.ajax({ | |
| 6984 | + type: 'POST', url: ajaxurl, | |
| 6985 | + data: { | |
| 6986 | + action: 'frm_add_post' + type + '_row', | |
| 6987 | + form_id: id, | |
| 6988 | + meta_name: metaName, | |
| 6989 | + tax_key: metaName, | |
| 6990 | + post_type: postType, | |
| 6991 | + action_key: key, | |
| 6992 | + nonce: frmGlobal.nonce | |
| 6993 | + }, | |
| 6994 | + success: function( html ) { | |
| 6995 | + var cfOpts, optIndex; | |
| 6996 | + jQuery( document.getElementById( 'frm_post' + type + '_rows' ) ).append( html ); | |
| 6997 | + jQuery( '.frm_add_post' + type + '_row.button' ).hide(); | |
| 6998 | + | |
| 6999 | + if ( type === 'meta' ) { | |
| 7000 | + jQuery( '.frm_name_value' ).show(); | |
| 7001 | + cfOpts = document.querySelectorAll( '.frm_toggle_cf_opts' ); | |
| 7002 | + for ( optIndex = 0; optIndex < cfOpts.length - 1; ++optIndex ) { | |
| 7003 | + cfOpts[ optIndex ].style.display = 'none'; | |
| 7004 | + } | |
| 7005 | + } else if ( type === 'tax' ) { | |
| 7006 | + jQuery( '.frm_posttax_labels' ).show(); | |
| 7007 | + } | |
| 7008 | + } | |
| 7009 | + }); | |
| 7010 | + } | |
| 7011 | + | |
| 7012 | + function isNumeric( value ) { | |
| 7013 | + return ! isNaN( parseFloat( value ) ) && isFinite( value ); | |
| 7014 | + } | |
| 7015 | + | |
| 7016 | + function getMetaValue( id, metaName ) { | |
| 7017 | + var newMeta = metaName; | |
| 7018 | + if ( jQuery( document.getElementById( id + metaName ) ).length > 0 ) { | |
| 7019 | + newMeta = getMetaValue( id, metaName + 1 ); | |
| 7020 | + } | |
| 7021 | + return newMeta; | |
| 7022 | + } | |
| 7023 | + | |
| 7024 | + function changePosttaxRow() { | |
| 7025 | + /*jshint validthis:true */ | |
| 7026 | + if ( ! jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).length ) { | |
| 7027 | + return; | |
| 7028 | + } | |
| 7029 | + | |
| 7030 | + jQuery( this ).closest( '.frm_posttax_row' ).find( '.frm_posttax_opt_list' ).html( '<div class="spinner frm_spinner" style="display:block"></div>' ); | |
| 7031 | + | |
| 7032 | + var postType = jQuery( this ).closest( '.frm_form_action_settings' ).find( 'select[name$="[post_content][post_type]"]' ).val(), | |
| 7033 | + actionKey = jQuery( this ).closest( '.frm_form_action_settings' ).data( 'actionkey' ), | |
| 7034 | + taxKey = jQuery( this ).closest( '.frm_posttax_row' ).attr( 'id' ).replace( 'frm_posttax_', '' ), | |
| 7035 | + metaName = jQuery( this ).val(), | |
| 7036 | + showExclude = jQuery( document.getElementById( taxKey + '_show_exclude' ) ).is( ':checked' ) ? 1 : 0, | |
| 7037 | + fieldId = jQuery( 'select[name$="[post_category][' + taxKey + '][field_id]"]' ).val(), | |
| 7038 | + id = jQuery( 'input[name="id"]' ).val(); | |
| 7039 | + | |
| 7040 | + jQuery.ajax({ | |
| 7041 | + type: 'POST', | |
| 7042 | + url: ajaxurl, | |
| 7043 | + data: { | |
| 7044 | + action: 'frm_add_posttax_row', | |
| 7045 | + form_id: id, | |
| 7046 | + post_type: postType, | |
| 7047 | + tax_key: taxKey, | |
| 7048 | + action_key: actionKey, | |
| 7049 | + meta_name: metaName, | |
| 7050 | + field_id: fieldId, | |
| 7051 | + show_exclude: showExclude, | |
| 7052 | + nonce: frmGlobal.nonce | |
| 7053 | + }, | |
| 7054 | + success: function( html ) { | |
| 7055 | + var $tax = jQuery( document.getElementById( 'frm_posttax_' + taxKey ) ); | |
| 7056 | + $tax.replaceWith( html ); | |
| 7057 | + } | |
| 7058 | + }); | |
| 7059 | + } | |
| 7060 | + | |
| 7061 | + function toggleCfOpts() { | |
| 7062 | + /*jshint validthis:true */ | |
| 7063 | + var row = jQuery( this ).closest( '.frm_postmeta_row' ); | |
| 7064 | + var cancel = row.find( '.frm_cancelnew' ); | |
| 7065 | + var select = row.find( '.frm_enternew' ); | |
| 7066 | + if ( row.find( 'select.frm_cancelnew' ).is( ':visible' ) ) { | |
| 7067 | + cancel.hide(); | |
| 7068 | + select.show(); | |
| 7069 | + } else { | |
| 7070 | + cancel.show(); | |
| 7071 | + select.hide(); | |
| 7072 | + } | |
| 7073 | + | |
| 7074 | + row.find( 'input.frm_enternew, select.frm_cancelnew' ).val( '' ); | |
| 7075 | + return false; | |
| 7076 | + } | |
| 7077 | + | |
| 7078 | + function toggleFormOpts() { | |
| 7079 | + /*jshint validthis:true */ | |
| 7080 | + var changedOpt = jQuery( this ); | |
| 7081 | + var val = changedOpt.val(); | |
| 7082 | + if ( changedOpt.attr( 'type' ) === 'checkbox' ) { | |
| 7083 | + if ( this.checked === false ) { | |
| 7084 | + val = ''; | |
| 7085 | + } | |
| 7086 | + } | |
| 7087 | + | |
| 7088 | + var toggleClass = changedOpt.data( 'toggleclass' ); | |
| 7089 | + if ( val === '' ) { | |
| 7090 | + jQuery( '.' + toggleClass ).hide(); | |
| 7091 | + } else { | |
| 7092 | + jQuery( '.' + toggleClass ).show(); | |
| 7093 | + jQuery( '.hide_' + toggleClass + '_' + val ).hide(); | |
| 7094 | + } | |
| 7095 | + } | |
| 7096 | + | |
| 7097 | + function submitSettings() { | |
| 7098 | + /*jshint validthis:true */ | |
| 7099 | + preFormSave( this ); | |
| 7100 | + triggerSubmit( document.querySelector( '.frm_form_settings' ) ); | |
| 7101 | + } | |
| 7102 | + | |
| 7103 | + /* View Functions */ | |
| 7104 | + function showCount() { | |
| 7105 | + /*jshint validthis:true */ | |
| 7106 | + var value = jQuery( this ).val(); | |
| 7107 | + | |
| 7108 | + var $cont = document.getElementById( 'date_select_container' ); | |
| 7109 | + var tab = document.getElementById( 'frm_listing_tab' ); | |
| 7110 | + var label = tab.getAttribute( 'data-label' ); | |
| 7111 | + if ( value === 'calendar' ) { | |
| 7112 | + jQuery( '.hide_dyncontent, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 7113 | + jQuery( '.limit_container' ).addClass( 'frm_hidden' ); | |
| 7114 | + $cont.style.display = 'block'; | |
| 7115 | + } else if ( value === 'dynamic' ) { | |
| 7116 | + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 7117 | + } else if ( value === 'one' ) { | |
| 7118 | + label = tab.getAttribute( 'data-one' ); | |
| 7119 | + jQuery( '.hide_dyncontent, .limit_container, .hide_single_content' ).addClass( 'frm_hidden' ); | |
| 7120 | + } else { | |
| 7121 | + jQuery( '.hide_dyncontent' ).addClass( 'frm_hidden' ); | |
| 7122 | + jQuery( '.limit_container, .hide_single_content' ).removeClass( 'frm_hidden' ); | |
| 7123 | + } | |
| 7124 | + | |
| 7125 | + if ( value !== 'calendar' ) { | |
| 7126 | + $cont.style.display = 'none'; | |
| 7127 | + } | |
| 7128 | + tab.innerHTML = label; | |
| 7129 | + } | |
| 7130 | + | |
| 7131 | + function displayFormSelected() { | |
| 7132 | + /*jshint validthis:true */ | |
| 7133 | + var formId = jQuery( this ).val(); | |
| 7134 | + thisFormId = formId; // set the global form id | |
| 7135 | + if ( formId === '' ) { | |
| 7136 | + return; | |
| 7137 | + } | |
| 7138 | + | |
| 7139 | + jQuery.ajax({ | |
| 7140 | + type: 'POST', | |
| 7141 | + url: ajaxurl, | |
| 7142 | + data: { | |
| 7143 | + action: 'frm_get_cd_tags_box', | |
| 7144 | + form_id: formId, | |
| 7145 | + nonce: frmGlobal.nonce | |
| 7146 | + }, | |
| 7147 | + success: function( html ) { | |
| 7148 | + jQuery( '#frm_adv_info .categorydiv' ).html( html ); | |
| 7149 | + } | |
| 7150 | + }); | |
| 7151 | + | |
| 7152 | + jQuery.ajax({ | |
| 7153 | + type: 'POST', | |
| 7154 | + url: ajaxurl, | |
| 7155 | + data: { | |
| 7156 | + action: 'frm_get_date_field_select', | |
| 7157 | + form_id: formId, | |
| 7158 | + nonce: frmGlobal.nonce | |
| 7159 | + }, | |
| 7160 | + success: function( html ) { | |
| 7161 | + jQuery( document.getElementById( 'date_select_container' ) ).html( html ); | |
| 7162 | + } | |
| 7163 | + }); | |
| 7164 | + } | |
| 7165 | + | |
| 7166 | + function clickTabsAfterAjax() { | |
| 7167 | + /*jshint validthis:true */ | |
| 7168 | + var t = jQuery( this ).attr( 'href' ); | |
| 7169 | + jQuery( this ).parent().addClass( 'tabs' ).siblings( 'li' ).removeClass( 'tabs' ); | |
| 7170 | + jQuery( t ).show().siblings( '.tabs-panel' ).hide(); | |
| 7171 | + return false; | |
| 7172 | + } | |
| 7173 | + | |
| 7174 | + function clickContentTab() { | |
| 7175 | + /*jshint validthis:true */ | |
| 7176 | + link = jQuery( this ); | |
| 7177 | + var t = link.attr( 'href' ); | |
| 7178 | + if ( typeof t === 'undefined' ) { | |
| 7179 | + return false; | |
| 7180 | + } | |
| 7181 | + | |
| 7182 | + var c = t.replace( '#', '.' ); | |
| 7183 | + link.closest( '.nav-tab-wrapper' ).find( 'a' ).removeClass( 'nav-tab-active' ); | |
| 7184 | + link.addClass( 'nav-tab-active' ); | |
| 7185 | + jQuery( '.nav-menu-content' ).not( t ).not( c ).hide(); | |
| 7186 | + jQuery( t + ',' + c ).show(); | |
| 7187 | + | |
| 7188 | + return false; | |
| 7189 | + } | |
| 7190 | + | |
| 7191 | + function addOrderRow() { | |
| 7192 | + var logicRows = document.getElementById( 'frm_order_options' ).querySelectorAll( '.frm_logic_rows div' ); | |
| 7193 | + jQuery.ajax({ | |
| 7194 | + type: 'POST', | |
| 7195 | + url: ajaxurl, | |
| 7196 | + data: { | |
| 7197 | + action: 'frm_add_order_row', | |
| 7198 | + form_id: thisFormId, | |
| 7199 | + order_key: getNewRowId( logicRows, 'frm_order_field_', 1 ), | |
| 7200 | + nonce: frmGlobal.nonce | |
| 7201 | + }, | |
| 7202 | + success: function( html ) { | |
| 7203 | + jQuery( '#frm_order_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_order_row' ).hide(); | |
| 7204 | + } | |
| 7205 | + }); | |
| 7206 | + } | |
| 7207 | + | |
| 7208 | + function addWhereRow() { | |
| 7209 | + var rowDivs = document.getElementById( 'frm_where_options' ).querySelectorAll( '.frm_logic_rows div' ); | |
| 7210 | + jQuery.ajax({ | |
| 7211 | + type: 'POST', | |
| 7212 | + url: ajaxurl, | |
| 7213 | + data: { | |
| 7214 | + action: 'frm_add_where_row', | |
| 7215 | + form_id: thisFormId, | |
| 7216 | + where_key: getNewRowId( rowDivs, 'frm_where_field_', 1 ), | |
| 7217 | + nonce: frmGlobal.nonce | |
| 7218 | + }, | |
| 7219 | + success: function( html ) { | |
| 7220 | + jQuery( '#frm_where_options .frm_logic_rows' ).append( html ).show().prev( '.frm_add_where_row' ).hide(); | |
| 7221 | + } | |
| 7222 | + }); | |
| 7223 | + } | |
| 7224 | + | |
| 7225 | + function insertWhereOptions() { | |
| 7226 | + /*jshint validthis:true */ | |
| 7227 | + var value = this.value, | |
| 7228 | + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' ); | |
| 7229 | + | |
| 7230 | + jQuery.ajax({ | |
| 7231 | + type: 'POST', | |
| 7232 | + url: ajaxurl, | |
| 7233 | + data: { | |
| 7234 | + action: 'frm_add_where_options', | |
| 7235 | + where_key: whereKey, | |
| 7236 | + field_id: value, | |
| 7237 | + nonce: frmGlobal.nonce | |
| 7238 | + }, | |
| 7239 | + success: function( html ) { | |
| 7240 | + jQuery( document.getElementById( 'where_field_options_' + whereKey ) ).html( html ); | |
| 7241 | + } | |
| 7242 | + }); | |
| 7243 | + } | |
| 7244 | + | |
| 7245 | + function hideWhereOptions() { | |
| 7246 | + /*jshint validthis:true */ | |
| 7247 | + var value = this.value, | |
| 7248 | + whereKey = jQuery( this ).closest( '.frm_where_row' ).attr( 'id' ).replace( 'frm_where_field_', '' ); | |
| 7249 | + | |
| 7250 | + if ( value === 'group_by' || value === 'group_by_newest' ) { | |
| 7251 | + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'none'; | |
| 7252 | + } else { | |
| 7253 | + document.getElementById( 'where_field_options_' + whereKey ).style.display = 'inline-block'; | |
| 7254 | + } | |
| 7255 | + } | |
| 7256 | + | |
| 7257 | + function setDefaultPostStatus() { | |
| 7258 | + var urlQuery = window.location.search.substring( 1 ); | |
| 7259 | + if ( urlQuery.indexOf( 'action=edit' ) === -1 ) { | |
| 7260 | + document.getElementById( 'post-visibility-display' ).innerHTML = frm_admin_js.private_label; | |
| 7261 | + document.getElementById( 'hidden-post-visibility' ).value = 'private'; | |
| 7262 | + document.getElementById( 'visibility-radio-private' ).checked = true; | |
| 7263 | + } | |
| 7264 | + } | |
| 7265 | + | |
| 7266 | + /* Customization Panel */ | |
| 7267 | + function insertCode( e ) { | |
| 7268 | + /*jshint validthis:true */ | |
| 7269 | + e.preventDefault(); | |
| 7270 | + insertFieldCode( jQuery( this ), this.getAttribute( 'data-code' ) ); | |
| 7271 | + return false; | |
| 7272 | + } | |
| 7273 | + | |
| 7274 | + function insertFieldCode( element, variable ) { | |
| 7275 | + var rich = false, | |
| 7276 | + elementId = element; | |
| 7277 | + if ( typeof element === 'object' ) { | |
| 7278 | + if ( element.hasClass( 'frm_noallow' ) ) { | |
| 7279 | + return; | |
| 7280 | + } | |
| 7281 | + | |
| 7282 | + elementId = jQuery( element ).closest( '[data-fills]' ).attr( 'data-fills' ); | |
| 7283 | + if ( typeof elementId === 'undefined' ) { | |
| 7284 | + elementId = element.closest( 'div' ).attr( 'class' ); | |
| 7285 | + if ( typeof elementId !== 'undefined' ) { | |
| 7286 | + elementId = elementId.split( ' ' )[1]; | |
| 7287 | + } | |
| 7288 | + } | |
| 7289 | + } | |
| 7290 | + | |
| 7291 | + if ( typeof elementId === 'undefined' ) { | |
| 7292 | + var active = document.activeElement; | |
| 7293 | + if ( active.type === 'search' ) { | |
| 7294 | + // If the search field has focus, find the correct field. | |
| 7295 | + elementId = active.id.replace( '-search-input', '' ); | |
| 7296 | + if ( elementId.match( /\d/gi ) === null ) { | |
| 7297 | + active = jQuery( '.frm-single-settings:visible .' + elementId ); | |
| 7298 | + elementId = active.attr( 'id' ); | |
| 7299 | + } | |
| 7300 | + } else { | |
| 7301 | + elementId = active.id; | |
| 7302 | + } | |
| 7303 | + } | |
| 7304 | + | |
| 7305 | + if ( elementId ) { | |
| 7306 | + rich = jQuery( '#wp-' + elementId + '-wrap.wp-editor-wrap' ).length > 0; | |
| 7307 | + } | |
| 7308 | + | |
| 7309 | + var contentBox = jQuery( document.getElementById( elementId ) ); | |
| 7310 | + if ( typeof element.attr( 'data-shortcode' ) === 'undefined' && ( ! contentBox.length || typeof contentBox.attr( 'data-shortcode' ) === 'undefined' ) ) { | |
| 7311 | + // this helps to exclude those that don't want shortcode-like inserted content e.g. frm-pro's summary field | |
| 7312 | + var doShortcode = element.parents( 'ul.frm_code_list' ).attr( 'data-shortcode' ); | |
| 7313 | + if ( doShortcode === 'undefined' || doShortcode !== 'no' ) { | |
| 7314 | + variable = '[' + variable + ']'; | |
| 7315 | + } | |
| 7316 | + } | |
| 7317 | + | |
| 7318 | + if ( rich ) { | |
| 7319 | + wpActiveEditor = elementId; | |
| 7320 | + } | |
| 7321 | + | |
| 7322 | + if ( ! contentBox.length ) { | |
| 7323 | + return false; | |
| 7324 | + } | |
| 7325 | + | |
| 7326 | + if ( variable === '[default-html]' || variable === '[default-plain]' ) { | |
| 7327 | + var p = 0; | |
| 7328 | + if ( variable === '[default-plain]' ) { | |
| 7329 | + p = 1; | |
| 7330 | + } | |
| 7331 | + jQuery.ajax({ | |
| 7332 | + type: 'POST', url: ajaxurl, | |
| 7333 | + data: { | |
| 7334 | + action: 'frm_get_default_html', | |
| 7335 | + form_id: jQuery( 'input[name="id"]' ).val(), | |
| 7336 | + plain_text: p, | |
| 7337 | + nonce: frmGlobal.nonce | |
| 7338 | + }, | |
| 7339 | + elementId: elementId, | |
| 7340 | + success: function( msg ) { | |
| 7341 | + if ( rich ) { | |
| 7342 | + let p = document.createElement( 'p' ); | |
| 7343 | + p.innerText = msg; | |
| 7344 | + send_to_editor( p.innerHTML ); | |
| 7345 | + } else { | |
| 7346 | + insertContent( contentBox, msg ); | |
| 7347 | + } | |
| 7348 | + } | |
| 7349 | + }); | |
| 7350 | + } else { | |
| 7351 | + variable = maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox ); | |
| 7352 | + if ( rich ) { | |
| 7353 | + send_to_editor( variable ); | |
| 7354 | + } else { | |
| 7355 | + insertContent( contentBox, variable ); | |
| 7356 | + } | |
| 7357 | + } | |
| 7358 | + return false; | |
| 7359 | + } | |
| 7360 | + | |
| 7361 | + function maybeAddSanitizeUrlToShortcodeVariable( variable, element, contentBox ) { | |
| 7362 | + if ( 'object' !== typeof element || ! ( element instanceof jQuery ) || 'success_url' !== contentBox[0].id ) { | |
| 7363 | + return variable; | |
| 7364 | + } | |
| 7365 | + | |
| 7366 | + element = element[0]; | |
| 7367 | + if ( ! element.closest( '#frm-insert-fields-box' ) ) { | |
| 7368 | + // Only add sanitize_url=1 to field shortcodes. | |
| 7369 | + return variable; | |
| 7370 | + } | |
| 7371 | + | |
| 7372 | + if ( ! element.parentNode.classList.contains( 'frm_insert_url' ) ) { | |
| 7373 | + variable = variable.replace( ']', ' sanitize_url=1]' ); | |
| 7374 | + } | |
| 7375 | + | |
| 7376 | + return variable; | |
| 7377 | + } | |
| 7378 | + | |
| 7379 | + function insertContent( contentBox, variable ) { | |
| 7380 | + if ( document.selection ) { | |
| 7381 | + contentBox[0].focus(); | |
| 7382 | + document.selection.createRange().text = variable; | |
| 7383 | + } else { | |
| 7384 | + obj = contentBox[0]; | |
| 7385 | + var e = obj.selectionEnd; | |
| 7386 | + | |
| 7387 | + variable = maybeFormatInsertedContent( contentBox, variable, obj.selectionStart, e ); | |
| 7388 | + | |
| 7389 | + obj.value = obj.value.substr( 0, obj.selectionStart ) + variable + obj.value.substr( obj.selectionEnd, obj.value.length ); | |
| 7390 | + var s = e + variable.length; | |
| 7391 | + obj.focus(); | |
| 7392 | + obj.setSelectionRange( s, s ); | |
| 7393 | + } | |
| 7394 | + triggerChange( contentBox ); | |
| 7395 | + } | |
| 7396 | + | |
| 7397 | + function maybeFormatInsertedContent( input, textToInsert, selectionStart, selectionEnd ) { | |
| 7398 | + var separator = input.data( 'sep' ); | |
| 7399 | + if ( undefined === separator ) { | |
| 7400 | + return textToInsert; | |
| 7401 | + } | |
| 7402 | + | |
| 7403 | + var value = input.val(); | |
| 7404 | + | |
| 7405 | + if ( ! value.trim().length ) { | |
| 7406 | + return textToInsert; | |
| 7407 | + } | |
| 7408 | + | |
| 7409 | + var startPattern = new RegExp( separator + '\\s*$' ); | |
| 7410 | + var endPattern = new RegExp( '^\\s*' + separator ); | |
| 7411 | + | |
| 7412 | + if ( value.substr( 0, selectionStart ).trim().length && false === startPattern.test( value.substr( 0, selectionStart ) ) ) { | |
| 7413 | + textToInsert = separator + textToInsert; | |
| 7414 | + } | |
| 7415 | + | |
| 7416 | + if ( value.substr( selectionEnd, value.length ).trim().length && false === endPattern.test( value.substr( selectionEnd, value.length ) ) ) { | |
| 7417 | + textToInsert += separator; | |
| 7418 | + } | |
| 7419 | + | |
| 7420 | + return textToInsert; | |
| 7421 | + } | |
| 7422 | + | |
| 7423 | + function resetLogicBuilder() { | |
| 7424 | + /*jshint validthis:true */ | |
| 7425 | + var id = document.getElementById( 'frm-id-condition' ), | |
| 7426 | + key = document.getElementById( 'frm-key-condition' ); | |
| 7427 | + | |
| 7428 | + if ( this.checked ) { | |
| 7429 | + id.classList.remove( 'frm_hidden' ); | |
| 7430 | + key.classList.add( 'frm_hidden' ); | |
| 7431 | + triggerEvent( key, 'change' ); | |
| 7432 | + } else { | |
| 7433 | + id.classList.add( 'frm_hidden' ); | |
| 7434 | + key.classList.remove( 'frm_hidden' ); | |
| 7435 | + triggerEvent( id, 'change' ); | |
| 7436 | + } | |
| 7437 | + } | |
| 7438 | + | |
| 7439 | + function setLogicExample() { | |
| 7440 | + var field, code, | |
| 7441 | + idKey = document.getElementById( 'frm-id-key-condition' ).checked ? 'frm-id-condition' : 'frm-key-condition', | |
| 7442 | + is = document.getElementById( 'frm-is-condition' ).value, | |
| 7443 | + text = document.getElementById( 'frm-text-condition' ).value, | |
| 7444 | + result = document.getElementById( 'frm-insert-condition' ); | |
| 7445 | + | |
| 7446 | + idKey = document.getElementById( idKey ); | |
| 7447 | + field = idKey.options[idKey.selectedIndex].value; | |
| 7448 | + code = 'if ' + field + ' ' + is + '="' + text + '"]'; | |
| 7449 | + result.setAttribute( 'data-code', code + frm_admin_js.conditional_text + '[/if ' + field ); | |
| 7450 | + result.innerHTML = '[' + code + '[/if ' + field + ']'; | |
| 7451 | + } | |
| 7452 | + | |
| 7453 | + function showBuilderModal() { | |
| 7454 | + /*jshint validthis:true */ | |
| 7455 | + var moreIcon = getIconForInput( this ); | |
| 7456 | + showInlineModal( moreIcon, this ); | |
| 7457 | + } | |
| 7458 | + | |
| 7459 | + function maybeShowModal( input ) { | |
| 7460 | + var moreIcon; | |
| 7461 | + if ( input.parentNode.parentNode.classList.contains( 'frm_has_shortcodes' ) ) { | |
| 7462 | + hideShortcodes(); | |
| 7463 | + moreIcon = getIconForInput( input ); | |
| 7464 | + if ( moreIcon.tagName === 'use' ) { | |
| 7465 | + moreIcon = moreIcon.firstElementChild; | |
| 7466 | + if ( moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ).indexOf( 'frm_close_icon' ) === -1 ) { | |
| 7467 | + showShortcodeBox( moreIcon, 'nofocus' ); | |
| 7468 | + } | |
| 7469 | + } else if ( ! moreIcon.classList.contains( 'frm_close_icon' ) ) { | |
| 7470 | + showShortcodeBox( moreIcon, 'nofocus' ); | |
| 7471 | + } | |
| 7472 | + } | |
| 7473 | + } | |
| 7474 | + | |
| 7475 | + function showShortcodes( e ) { | |
| 7476 | + /*jshint validthis:true */ | |
| 7477 | + e.preventDefault(); | |
| 7478 | + e.stopPropagation(); | |
| 7479 | + | |
| 7480 | + showShortcodeBox( this ); | |
| 7481 | + } | |
| 7482 | + | |
| 7483 | + function showShortcodeBox( moreIcon, shouldFocus ) { | |
| 7484 | + var pos = moreIcon.getBoundingClientRect(), | |
| 7485 | + input = getInputForIcon( moreIcon ), | |
| 7486 | + box = document.getElementById( 'frm_adv_info' ), | |
| 7487 | + classes = moreIcon.className, | |
| 7488 | + parentPos = box.parentElement.getBoundingClientRect(); | |
| 7489 | + | |
| 7490 | + if ( moreIcon.tagName === 'svg' ) { | |
| 7491 | + moreIcon = moreIcon.firstElementChild; | |
| 7492 | + } | |
| 7493 | + if ( moreIcon.tagName === 'use' ) { | |
| 7494 | + classes = moreIcon.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ); | |
| 7495 | + } | |
| 7496 | + | |
| 7497 | + if ( classes.indexOf( 'frm_close_icon' ) !== -1 ) { | |
| 7498 | + hideShortcodes( box ); | |
| 7499 | + } else { | |
| 7500 | + box.style.top = ( pos.top - parentPos.top + 32 ) + 'px'; | |
| 7501 | + box.style.left = ( pos.left - parentPos.left - 280 ) + 'px'; | |
| 7502 | + | |
| 7503 | + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ); | |
| 7504 | + if ( input.classList.contains( 'frm_not_email_to' ) ) { | |
| 7505 | + jQuery( '#frm-insert-fields-box .frm_code_list li:not(.show_frm_not_email_to) a' ).addClass( 'frm_noallow' ); | |
| 7506 | + } else if ( input.classList.contains( 'frm_not_email_subject' ) ) { | |
| 7507 | + jQuery( '.frm_code_list li.hide_frm_not_email_subject a' ).addClass( 'frm_noallow' ); | |
| 7508 | + } | |
| 7509 | + | |
| 7510 | + box.setAttribute( 'data-fills', input.id ); | |
| 7511 | + box.style.display = 'block'; | |
| 7512 | + | |
| 7513 | + if ( moreIcon.tagName === 'use' ) { | |
| 7514 | + moreIcon.setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_close_icon' ); | |
| 7515 | + } else { | |
| 7516 | + moreIcon.className = classes.replace( 'frm_more_horiz_solid_icon', 'frm_close_icon' ); | |
| 7517 | + } | |
| 7518 | + | |
| 7519 | + if ( shouldFocus !== 'nofocus' ) { | |
| 7520 | + if ( 'none' !== input.style.display ) { | |
| 7521 | + input.focus(); | |
| 7522 | + } else { | |
| 7523 | + jQuery( tinymce.get( input.id ) ).trigger( 'focus' ); | |
| 7524 | + } | |
| 7525 | + } | |
| 7526 | + } | |
| 7527 | + } | |
| 7528 | + | |
| 7529 | + function fieldUpdated() { | |
| 7530 | + if ( ! fieldsUpdated ) { | |
| 7531 | + fieldsUpdated = 1; | |
| 7532 | + window.addEventListener( 'beforeunload', confirmExit ); | |
| 7533 | + } | |
| 7534 | + } | |
| 7535 | + | |
| 7536 | + function buildSubmittedNoAjax() { | |
| 7537 | + // set fieldsUpdated to 0 to avoid the unsaved changes pop up | |
| 7538 | + fieldsUpdated = 0; | |
| 7539 | + } | |
| 7540 | + | |
| 7541 | + function settingsSubmitted() { | |
| 7542 | + // set fieldsUpdated to 0 to avoid the unsaved changes pop up | |
| 7543 | + fieldsUpdated = 0; | |
| 7544 | + } | |
| 7545 | + | |
| 7546 | + function saveAndReloadSettings() { | |
| 7547 | + var page, form; | |
| 7548 | + page = document.getElementById( 'form_settings_page' ); | |
| 7549 | + if ( null !== page ) { | |
| 7550 | + form = page.querySelector( 'form.frm_form_settings' ); | |
| 7551 | + if ( null !== form ) { | |
| 7552 | + fieldsUpdated = 0; | |
| 7553 | + form.submit(); | |
| 7554 | + } | |
| 7555 | + } | |
| 7556 | + } | |
| 7557 | + | |
| 7558 | + function saveAndReloadFormBuilder() { | |
| 7559 | + document.getElementById( 'frm_submit_side_top' ).click(); | |
| 7560 | + } | |
| 7561 | + | |
| 7562 | + function confirmExit( event ) { | |
| 7563 | + if ( fieldsUpdated ) { | |
| 7564 | + event.preventDefault(); | |
| 7565 | + event.returnValue = ''; | |
| 7566 | + } | |
| 7567 | + } | |
| 7568 | + | |
| 7569 | + function bindClickForDialogClose( $modal ) { | |
| 7570 | + const closeModal = function() { | |
| 7571 | + $modal.dialog( 'close' ); | |
| 7572 | + }; | |
| 7573 | + jQuery( '.ui-widget-overlay' ).on( 'click', closeModal ); | |
| 7574 | + $modal.on( 'click', 'a.dismiss', closeModal ); | |
| 7575 | + } | |
| 7576 | + | |
| 7577 | + function triggerNewFormModal( event ) { | |
| 7578 | + var $modal, | |
| 7579 | + dismiss = document.getElementById( 'frm_new_form_modal' ).querySelector( 'a.dismiss' ); | |
| 7580 | + | |
| 7581 | + if ( typeof event !== 'undefined' ) { | |
| 7582 | + event.preventDefault(); | |
| 7583 | + } | |
| 7584 | + | |
| 7585 | + dismiss.setAttribute( 'tabindex', -1 ); | |
| 7586 | + | |
| 7587 | + $modal = initModal( '#frm_new_form_modal', '600px' ); | |
| 7588 | + offsetModalY( $modal, '50px' ); | |
| 7589 | + $modal.attr( 'frm-page', 'create' ); | |
| 7590 | + $modal.find( '#template-search-input' ).val( '' ).trigger( 'change' ); | |
| 7591 | + $modal.dialog( 'open' ); | |
| 7592 | + | |
| 7593 | + dismiss.removeAttribute( 'tabindex' ); | |
| 7594 | + bindClickForDialogClose( $modal ); | |
| 7595 | + | |
| 7596 | + addApplicationsToNewFormModal( $modal.get( 0 ) ); | |
| 7597 | + } | |
| 7598 | + | |
| 7599 | + function addApplicationsToNewFormModal( modal ) { | |
| 7600 | + if ( modal.querySelector( '.frm-ready-made-solution' ) ) { | |
| 7601 | + // Avoid adding duplicates if the modal is opened multiple times. | |
| 7602 | + return; | |
| 7603 | + } | |
| 7604 | + | |
| 7605 | + if ( ! frmGlobal.canAccessApplicationDashboard ) { | |
| 7606 | + // User does not have privileges to see Ready Made Solutions. | |
| 7607 | + return; | |
| 7608 | + } | |
| 7609 | + | |
| 7610 | + doJsonFetch( 'get_applications_data&view=templates' ).then( addTemplatesOnFetchSuccess ); | |
| 7611 | + | |
| 7612 | + const categoryList = modal.querySelector( 'ul.frm-categories-list' ); | |
| 7613 | + | |
| 7614 | + function addTemplatesOnFetchSuccess( data ) { | |
| 7615 | + data.templates.forEach( addTemplateToCategoryList ); | |
| 7616 | + } | |
| 7617 | + | |
| 7618 | + function addTemplateToCategoryList( template ) { | |
| 7619 | + categoryList.insertBefore( getReadyMadeSolution( template ), categoryList.firstChild ); | |
| 7620 | + } | |
| 7621 | + | |
| 7622 | + function getReadyMadeSolution( template ) { | |
| 7623 | + const image = tag( 'img' ); | |
| 7624 | + const thumbnailFolderUrl = frmGlobal.url + '/images/applications/thumbnails/'; | |
| 7625 | + const filenameToUse = template.hasLiteThumbnail ? template.key + '.png' : 'placeholder.svg'; | |
| 7626 | + image.setAttribute( 'src', thumbnailFolderUrl + filenameToUse ); | |
| 7627 | + | |
| 7628 | + const imageWrapper = div({ child: image }); | |
| 7629 | + const href = frmGlobal.applicationsUrl + '&triggerViewApplicationModal=1&template=' + template.key; | |
| 7630 | + | |
| 7631 | + return tag( | |
| 7632 | + 'li', | |
| 7633 | + { | |
| 7634 | + className: 'frm-searchable-template frm-ready-made-solution frm-selectable', | |
| 7635 | + data: { | |
| 7636 | + href: href | |
| 7637 | + }, | |
| 7638 | + children: [ | |
| 7639 | + imageWrapper, | |
| 7640 | + div({ | |
| 7641 | + className: 'frm-solution-details', | |
| 7642 | + children: [ | |
| 7643 | + span({ | |
| 7644 | + className: 'frm-meta-tag', | |
| 7645 | + text: __( 'Ready Made Solution', 'formidable' ) | |
| 7646 | + }), | |
| 7647 | + tag( 'h3', template.name ), | |
| 7648 | + a({ | |
| 7649 | + text: __( 'See all applications', 'formidable' ), | |
| 7650 | + href: frmGlobal.applicationsUrl | |
| 7651 | + }) | |
| 7652 | + ] | |
| 7653 | + }), | |
| 7654 | + div({ | |
| 7655 | + className: 'frm-hover-icons', | |
| 7656 | + child: a({ | |
| 7657 | + child: svg({ href: '#frm_plus_icon' }), | |
| 7658 | + href: href | |
| 7659 | + }) | |
| 7660 | + }) | |
| 7661 | + ] | |
| 7662 | + } | |
| 7663 | + ); | |
| 7664 | + } | |
| 7665 | + } | |
| 7666 | + | |
| 7667 | + function offsetModalY( $modal, amount ) { | |
| 7668 | + const position = { | |
| 7669 | + my: 'top', | |
| 7670 | + at: 'top+' + amount, | |
| 7671 | + of: window | |
| 7672 | + }; | |
| 7673 | + $modal.dialog( 'option', 'position', position ); | |
| 7674 | + } | |
| 7675 | + | |
| 7676 | + /** | |
| 7677 | + * Get the input box for the selected ... icon. | |
| 7678 | + */ | |
| 7679 | + function getInputForIcon( moreIcon ) { | |
| 7680 | + var input = moreIcon.nextElementSibling; | |
| 7681 | + | |
| 7682 | + while ( input !== null && input.tagName !== 'INPUT' && input.tagName !== 'TEXTAREA' ) { | |
| 7683 | + input = getInputForIcon( input ); | |
| 7684 | + } | |
| 7685 | + | |
| 7686 | + return input; | |
| 7687 | + } | |
| 7688 | + | |
| 7689 | + /** | |
| 7690 | + * Get the ... icon for the selected input box. | |
| 7691 | + */ | |
| 7692 | + function getIconForInput( input ) { | |
| 7693 | + var moreIcon = input.previousElementSibling; | |
| 7694 | + | |
| 7695 | + while ( moreIcon !== null && moreIcon.tagName !== 'I' && moreIcon.tagName !== 'svg' ) { | |
| 7696 | + moreIcon = getIconForInput( moreIcon ); | |
| 7697 | + } | |
| 7698 | + | |
| 7699 | + return moreIcon; | |
| 7700 | + } | |
| 7701 | + | |
| 7702 | + function hideShortcodes( box ) { | |
| 7703 | + var i, u, closeIcons, closeSvg; | |
| 7704 | + if ( typeof box === 'undefined' ) { | |
| 7705 | + box = document.getElementById( 'frm_adv_info' ); | |
| 7706 | + if ( box === null ) { | |
| 7707 | + return; | |
| 7708 | + } | |
| 7709 | + } | |
| 7710 | + | |
| 7711 | + if ( document.getElementById( 'frm_dyncontent' ) !== null ) { | |
| 7712 | + // Don't run when in the sidebar. | |
| 7713 | + return; | |
| 7714 | + } | |
| 7715 | + | |
| 7716 | + box.style.display = 'none'; | |
| 7717 | + | |
| 7718 | + closeIcons = document.querySelectorAll( '.frm-show-box.frm_close_icon' ); | |
| 7719 | + for ( i = 0; i < closeIcons.length; i++ ) { | |
| 7720 | + closeIcons[i].classList.remove( 'frm_close_icon' ); | |
| 7721 | + closeIcons[i].classList.add( 'frm_more_horiz_solid_icon' ); | |
| 7722 | + } | |
| 7723 | + | |
| 7724 | + closeSvg = document.querySelectorAll( '.frm_has_shortcodes use' ); | |
| 7725 | + for ( u = 0; u < closeSvg.length; u++ ) { | |
| 7726 | + if ( closeSvg[u].getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) === '#frm_close_icon' ) { | |
| 7727 | + closeSvg[u].setAttributeNS( 'http://www.w3.org/1999/xlink', 'href', '#frm_more_horiz_solid_icon' ); | |
| 7728 | + } | |
| 7729 | + } | |
| 7730 | + } | |
| 7731 | + | |
| 7732 | + function initToggleShortcodes() { | |
| 7733 | + if ( typeof tinymce !== 'object' ) { | |
| 7734 | + return; | |
| 7735 | + } | |
| 7736 | + | |
| 7737 | + DOM = tinymce.DOM; | |
| 7738 | + if ( typeof DOM.events !== 'undefined' && typeof DOM.events.add !== 'undefined' ) { | |
| 7739 | + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseover', function() { | |
| 7740 | + if ( jQuery( '*:focus' ).length > 0 ) { | |
| 7741 | + return; | |
| 7742 | + } | |
| 7743 | + if ( this.id ) { | |
| 7744 | + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 7745 | + } | |
| 7746 | + }); | |
| 7747 | + DOM.events.add( DOM.select( '.wp-editor-wrap' ), 'mouseout', function() { | |
| 7748 | + if ( jQuery( '*:focus' ).length > 0 ) { | |
| 7749 | + return; | |
| 7750 | + } | |
| 7751 | + if ( this.id ) { | |
| 7752 | + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 7753 | + } | |
| 7754 | + }); | |
| 7755 | + } else { | |
| 7756 | + jQuery( '#frm_dyncontent' ).on( 'mouseover mouseout', '.wp-editor-wrap', function() { | |
| 7757 | + if ( jQuery( '*:focus' ).length > 0 ) { | |
| 7758 | + return; | |
| 7759 | + } | |
| 7760 | + if ( this.id ) { | |
| 7761 | + toggleAllowedShortcodes( this.id.slice( 3, -5 ), 'focusin' ); | |
| 7762 | + } | |
| 7763 | + }); | |
| 7764 | + } | |
| 7765 | + } | |
| 7766 | + | |
| 7767 | + function toggleAllowedShortcodes( id ) { | |
| 7768 | + var c, clickedID; | |
| 7769 | + if ( typeof id === 'undefined' ) { | |
| 7770 | + id = ''; | |
| 7771 | + } | |
| 7772 | + c = id; | |
| 7773 | + | |
| 7774 | + if ( id.indexOf( '-search-input' ) !== -1 ) { | |
| 7775 | + return; | |
| 7776 | + } | |
| 7777 | + | |
| 7778 | + if ( id !== '' ) { | |
| 7779 | + var $ele = jQuery( document.getElementById( id ) ); | |
| 7780 | + if ( $ele.attr( 'class' ) && id !== 'wpbody-content' && id !== 'content' && id !== 'dyncontent' && id !== 'success_msg' ) { | |
| 7781 | + var d = $ele.attr( 'class' ).split( ' ' )[0]; | |
| 7782 | + if ( d === 'frm_long_input' || d === 'frm_98_width' || typeof d === 'undefined' ) { | |
| 7783 | + d = ''; | |
| 7784 | + } else { | |
| 7785 | + id = d.trim(); | |
| 7786 | + } | |
| 7787 | + c = c + ' ' + d; | |
| 7788 | + c = c.replace( 'widefat', '' ).replace( 'frm_with_left_label', '' ); | |
| 7789 | + } | |
| 7790 | + } | |
| 7791 | + | |
| 7792 | + jQuery( '#frm-insert-fields-box,#frm-conditionals,#frm-adv-info-tab,#frm-dynamic-values' ).attr( 'data-fills', c.trim() ); | |
| 7793 | + var a = [ | |
| 7794 | + 'content', 'wpbody-content', 'dyncontent', 'success_url', | |
| 7795 | + 'success_msg', 'edit_msg', 'frm_dyncontent', 'frm_not_email_message', | |
| 7796 | + 'frm_not_email_subject' | |
| 7797 | + ]; | |
| 7798 | + var b = [ | |
| 7799 | + 'before_content', 'after_content', 'frm_not_email_to', | |
| 7800 | + 'dyn_default_value' | |
| 7801 | + ]; | |
| 7802 | + | |
| 7803 | + if ( jQuery.inArray( id, a ) >= 0 ) { | |
| 7804 | + jQuery( '.frm_code_list a' ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' ); | |
| 7805 | + jQuery( '.frm_code_list a.hide_' + id ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 7806 | + } else if ( jQuery.inArray( id, b ) >= 0 ) { | |
| 7807 | + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a:not(.show_' + id + ')' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 7808 | + jQuery( '.frm_code_list a.show_' + id ).removeClass( 'frm_noallow' ).addClass( 'frm_allow' ); | |
| 7809 | + } else { | |
| 7810 | + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ).removeClass( 'frm_allow' ); | |
| 7811 | + } | |
| 7812 | + | |
| 7813 | + // Automatically select a tab. | |
| 7814 | + if ( id === 'dyn_default_value' ) { | |
| 7815 | + clickedID = 'frm_dynamic_values'; | |
| 7816 | + document.getElementById( clickedID + '_tab' ).click(); | |
| 7817 | + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_inactive' ).addClass( 'frm_hidden' ); | |
| 7818 | + jQuery( '#' + clickedID.replace( /_/g, '-' ) + ' .frm_show_active' ).removeClass( 'frm_hidden' ); | |
| 7819 | + } | |
| 7820 | + } | |
| 7821 | + | |
| 7822 | + function toggleAllowedHTML( input ) { | |
| 7823 | + var b, | |
| 7824 | + id = input.id; | |
| 7825 | + if ( typeof id === 'undefined' || id.indexOf( '-search-input' ) !== -1 ) { | |
| 7826 | + return; | |
| 7827 | + } | |
| 7828 | + | |
| 7829 | + jQuery( '#frm-adv-info-tab' ).attr( 'data-fills', id.trim() ); | |
| 7830 | + if ( input.classList.contains( 'field_custom_html' ) ) { | |
| 7831 | + id = 'field_custom_html'; | |
| 7832 | + } | |
| 7833 | + | |
| 7834 | + b = [ 'after_html', 'before_html', 'submit_html', 'field_custom_html' ]; | |
| 7835 | + if ( jQuery.inArray( id, b ) >= 0 ) { | |
| 7836 | + jQuery( '.frm_code_list li:not(.show_' + id + ')' ).addClass( 'frm_hidden' ); | |
| 7837 | + jQuery( '.frm_code_list li.show_' + id ).removeClass( 'frm_hidden' ); | |
| 7838 | + } | |
| 7839 | + } | |
| 7840 | + | |
| 7841 | + function toggleKeyID( switchTo, e ) { | |
| 7842 | + e.stopPropagation(); | |
| 7843 | + jQuery( '.frm_code_list .frmids, .frm_code_list .frmkeys' ).addClass( 'frm_hidden' ); | |
| 7844 | + jQuery( '.frm_code_list .' + switchTo ).removeClass( 'frm_hidden' ); | |
| 7845 | + jQuery( '.frmids, .frmkeys' ).removeClass( 'current' ); | |
| 7846 | + jQuery( '.' + switchTo ).addClass( 'current' ); | |
| 7847 | + } | |
| 7848 | + | |
| 7849 | + function onActionLoaded( event ) { | |
| 7850 | + const settings = event.target.closest( '.frm_form_action_settings' ); | |
| 7851 | + if ( settings && ( settings.classList.contains( 'frm_single_email_settings' ) || settings.classList.contains( 'frm_single_on_submit_settings' ) ) ) { | |
| 7852 | + initWysiwygOnActionLoaded( settings ); | |
| 7853 | + } | |
| 7854 | + } | |
| 7855 | + | |
| 7856 | + function initWysiwygOnActionLoaded( settings ) { | |
| 7857 | + const wysiwyg = settings.querySelector( '.wp-editor-area' ); | |
| 7858 | + if ( wysiwyg ) { | |
| 7859 | + frmDom.wysiwyg.init( | |
| 7860 | + wysiwyg, | |
| 7861 | + { height: 160, addFocusEvents: true } | |
| 7862 | + ); | |
| 7863 | + } | |
| 7864 | + } | |
| 7865 | + | |
| 7866 | + /* Global settings page */ | |
| 7867 | + function loadSettingsTab( anchor ) { | |
| 7868 | + var holder = anchor.replace( '#', '' ); | |
| 7869 | + var holderContainer = jQuery( '.frm_' + holder + '_ajax' ); | |
| 7870 | + if ( holderContainer.length ) { | |
| 7871 | + jQuery.ajax({ | |
| 7872 | + type: 'POST', url: ajaxurl, | |
| 7873 | + data: { | |
| 7874 | + 'action': 'frm_settings_tab', | |
| 7875 | + 'tab': holder.replace( '_settings', '' ), | |
| 7876 | + 'nonce': frmGlobal.nonce | |
| 7877 | + }, | |
| 7878 | + success: function( html ) { | |
| 7879 | + holderContainer.replaceWith( html ); | |
| 7880 | + } | |
| 7881 | + }); | |
| 7882 | + } | |
| 7883 | + } | |
| 7884 | + | |
| 7885 | + function uninstallNow() { | |
| 7886 | + /*jshint validthis:true */ | |
| 7887 | + if ( confirmLinkClick( this ) === true ) { | |
| 7888 | + jQuery( '.frm_uninstall .frm-wait' ).css( 'visibility', 'visible' ); | |
| 7889 | + jQuery.ajax({ | |
| 7890 | + type: 'POST', | |
| 7891 | + url: ajaxurl, | |
| 7892 | + data: 'action=frm_uninstall&nonce=' + frmGlobal.nonce, | |
| 7893 | + success: function( msg ) { | |
| 7894 | + jQuery( '.frm_uninstall' ).fadeOut( 'slow' ); | |
| 7895 | + window.location = msg; | |
| 7896 | + } | |
| 7897 | + }); | |
| 7898 | + } | |
| 7899 | + return false; | |
| 7900 | + } | |
| 7901 | + | |
| 7902 | + function saveAddonLicense() { | |
| 7903 | + /*jshint validthis:true */ | |
| 7904 | + var button = jQuery( this ); | |
| 7905 | + var buttonName = this.name; | |
| 7906 | + var pluginSlug = this.getAttribute( 'data-plugin' ); | |
| 7907 | + var action = buttonName.replace( 'edd_' + pluginSlug + '_license_', '' ); | |
| 7908 | + var license = document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value; | |
| 7909 | + jQuery.ajax({ | |
| 7910 | + type: 'POST', url: ajaxurl, dataType: 'json', | |
| 7911 | + data: {action: 'frm_addon_' + action, license: license, plugin: pluginSlug, nonce: frmGlobal.nonce}, | |
| 7912 | + success: function( msg ) { | |
| 7913 | + var thisRow = button.closest( '.edd_frm_license_row' ); | |
| 7914 | + if ( action === 'deactivate' ) { | |
| 7915 | + license = ''; | |
| 7916 | + document.getElementById( 'edd_' + pluginSlug + '_license_key' ).value = ''; | |
| 7917 | + } | |
| 7918 | + thisRow.find( '.edd_frm_license' ).html( license ); | |
| 7919 | + if ( msg.success === true ) { | |
| 7920 | + thisRow.find( '.frm_icon_font' ).removeClass( 'frm_hidden' ); | |
| 7921 | + thisRow.find( 'div.alignleft' ).toggleClass( 'frm_hidden', 1000 ); | |
| 7922 | + } | |
| 7923 | + | |
| 7924 | + var messageBox = thisRow.find( '.frm_license_msg' ); | |
| 7925 | + messageBox.html( msg.message ); | |
| 7926 | + if ( msg.message !== '' ) { | |
| 7927 | + setTimeout( function() { | |
| 7928 | + messageBox.html( '' ); | |
| 7929 | + }, 15000 ); | |
| 7930 | + } | |
| 7931 | + } | |
| 7932 | + }); | |
| 7933 | + } | |
| 7934 | + | |
| 7935 | + /* Import/Export page */ | |
| 7936 | + | |
| 7937 | + function startFormMigration( event ) { | |
| 7938 | + event.preventDefault(); | |
| 7939 | + | |
| 7940 | + var checkedBoxes = jQuery( event.target ).find( 'input:checked' ); | |
| 7941 | + if ( ! checkedBoxes.length ) { | |
| 7942 | + return; | |
| 7943 | + } | |
| 7944 | + | |
| 7945 | + var ids = []; | |
| 7946 | + checkedBoxes.each( function( i ) { | |
| 7947 | + ids[i] = this.value; | |
| 7948 | + }); | |
| 7949 | + | |
| 7950 | + // Begin the import process. | |
| 7951 | + importForms( ids, event.target ); | |
| 7952 | + } | |
| 7953 | + | |
| 7954 | + /** | |
| 7955 | + * Begins the process of importing the forms. | |
| 7956 | + */ | |
| 7957 | + function importForms( forms, targetForm ) { | |
| 7958 | + | |
| 7959 | + // Hide the form select section. | |
| 7960 | + var $form = jQuery( targetForm ), | |
| 7961 | + $processSettings = $form.next( '.frm-importer-process' ); | |
| 7962 | + | |
| 7963 | + // Display total number of forms we have to import. | |
| 7964 | + $processSettings.find( '.form-total' ).text( forms.length ); | |
| 7965 | + $processSettings.find( '.form-current' ).text( '1' ); | |
| 7966 | + | |
| 7967 | + $form.hide(); | |
| 7968 | + | |
| 7969 | + // Show processing status. | |
| 7970 | + // '.process-completed' might have been shown earlier during a previous import, so hide now. | |
| 7971 | + $processSettings.find( '.process-completed' ).hide(); | |
| 7972 | + $processSettings.show(); | |
| 7973 | + | |
| 7974 | + // Create global import queue. | |
| 7975 | + s.importQueue = forms; | |
| 7976 | + s.imported = 0; | |
| 7977 | + | |
| 7978 | + // Import the first form in the queue. | |
| 7979 | + importForm( $processSettings ); | |
| 7980 | + } | |
| 7981 | + | |
| 7982 | + /** | |
| 7983 | + * Imports a single form from the import queue. | |
| 7984 | + */ | |
| 7985 | + function importForm( $processSettings ) { | |
| 7986 | + var formID = s.importQueue[0], | |
| 7987 | + provider = $processSettings.closest( '.welcome-panel-content' ).find( 'input[name="slug"]' ).val(), | |
| 7988 | + data = { | |
| 7989 | + action: 'frm_import_' + provider, | |
| 7990 | + form_id: formID, | |
| 7991 | + nonce: frmGlobal.nonce | |
| 7992 | + }; | |
| 7993 | + | |
| 7994 | + // Trigger AJAX import for this form. | |
| 7995 | + jQuery.post( ajaxurl, data, function( res ) { | |
| 7996 | + | |
| 7997 | + if ( res.success ) { | |
| 7998 | + var statusUpdate; | |
| 7999 | + | |
| 8000 | + if ( res.data.error ) { | |
| 8001 | + statusUpdate = '<p>' + res.data.name + ': ' + res.data.msg + '</p>'; | |
| 8002 | + } else { | |
| 8003 | + statusUpdate = '<p>Imported <a href="' + res.data.link + '" target="_blank">' + res.data.name + '</a></p>'; | |
| 8004 | + } | |
| 8005 | + | |
| 8006 | + $processSettings.find( '.status' ).prepend( statusUpdate ); | |
| 8007 | + $processSettings.find( '.status' ).show(); | |
| 8008 | + | |
| 8009 | + // Remove this form ID from the queue. | |
| 8010 | + s.importQueue = jQuery.grep( s.importQueue, function( value ) { | |
| 8011 | + return value != formID; | |
| 8012 | + }); | |
| 8013 | + s.imported++; | |
| 8014 | + | |
| 8015 | + if ( s.importQueue.length === 0 ) { | |
| 8016 | + $processSettings.find( '.process-count' ).hide(); | |
| 8017 | + $processSettings.find( '.forms-completed' ).text( s.imported ); | |
| 8018 | + $processSettings.find( '.process-completed' ).show(); | |
| 8019 | + } else { | |
| 8020 | + // Import next form in the queue. | |
| 8021 | + $processSettings.find( '.form-current' ).text( s.imported + 1 ); | |
| 8022 | + importForm( $processSettings ); | |
| 8023 | + } | |
| 8024 | + } | |
| 8025 | + }); | |
| 8026 | + } | |
| 8027 | + | |
| 8028 | + function validateExport( e ) { | |
| 8029 | + /*jshint validthis:true */ | |
| 8030 | + e.preventDefault(); | |
| 8031 | + | |
| 8032 | + var s = false; | |
| 8033 | + var $exportForms = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 8034 | + | |
| 8035 | + if ( ! jQuery( 'input[name="frm_export_forms[]"]:checked' ).val() ) { | |
| 8036 | + $exportForms.closest( '.frm-table-box' ).addClass( 'frm_blank_field' ); | |
| 8037 | + s = 'stop'; | |
| 8038 | + } | |
| 8039 | + | |
| 8040 | + var $exportType = jQuery( 'input[name="type[]"]' ); | |
| 8041 | + if ( ! jQuery( 'input[name="type[]"]:checked' ).val() && $exportType.attr( 'type' ) === 'checkbox' ) { | |
| 8042 | + $exportType.closest( 'p' ).addClass( 'frm_blank_field' ); | |
| 8043 | + s = 'stop'; | |
| 8044 | + } | |
| 8045 | + | |
| 8046 | + if ( s === 'stop' ) { | |
| 8047 | + return false; | |
| 8048 | + } | |
| 8049 | + | |
| 8050 | + e.stopPropagation(); | |
| 8051 | + this.submit(); | |
| 8052 | + } | |
| 8053 | + | |
| 8054 | + function removeExportError() { | |
| 8055 | + /*jshint validthis:true */ | |
| 8056 | + var t = jQuery( this ).closest( '.frm_blank_field' ); | |
| 8057 | + if ( typeof t === 'undefined' ) { | |
| 8058 | + return; | |
| 8059 | + } | |
| 8060 | + | |
| 8061 | + var $thisName = this.name; | |
| 8062 | + if ( $thisName === 'type[]' && jQuery( 'input[name="type[]"]:checked' ).val() ) { | |
| 8063 | + t.removeClass( 'frm_blank_field' ); | |
| 8064 | + } else if ( $thisName === 'frm_export_forms[]' && jQuery( this ).val() ) { | |
| 8065 | + t.removeClass( 'frm_blank_field' ); | |
| 8066 | + } | |
| 8067 | + | |
| 8068 | + } | |
| 8069 | + | |
| 8070 | + function checkCSVExtension() { | |
| 8071 | + /*jshint validthis:true */ | |
| 8072 | + var f = jQuery( this ).val(); | |
| 8073 | + var re = /\.csv$/i; | |
| 8074 | + if ( f.match( re ) !== null ) { | |
| 8075 | + jQuery( '.show_csv' ).fadeIn(); | |
| 8076 | + } else { | |
| 8077 | + jQuery( '.show_csv' ).fadeOut(); | |
| 8078 | + } | |
| 8079 | + } | |
| 8080 | + | |
| 8081 | + function getExportOption() { | |
| 8082 | + const exportFormatSelect = document.querySelector( 'select[name="format"]' ); | |
| 8083 | + if ( exportFormatSelect ) { | |
| 8084 | + return exportFormatSelect.value; | |
| 8085 | + } else { | |
| 8086 | + return ''; | |
| 8087 | + } | |
| 8088 | + } | |
| 8089 | + | |
| 8090 | + function exportTypeChanged( event ) { | |
| 8091 | + showOrHideRepeaters( event.target.value ); | |
| 8092 | + checkExportTypes.call( event.target ); | |
| 8093 | + } | |
| 8094 | + | |
| 8095 | + function checkExportTypes() { | |
| 8096 | + /*jshint validthis:true */ | |
| 8097 | + var $dropdown = jQuery( this ); | |
| 8098 | + var $selected = $dropdown.find( ':selected' ); | |
| 8099 | + var s = $selected.data( 'support' ); | |
| 8100 | + | |
| 8101 | + var multiple = s.indexOf( '|' ); | |
| 8102 | + jQuery( 'input[name="type[]"]' ).each( function() { | |
| 8103 | + this.checked = false; | |
| 8104 | + if ( s.indexOf( this.value ) >= 0 ) { | |
| 8105 | + this.disabled = false; | |
| 8106 | + if ( multiple === -1 ) { | |
| 8107 | + this.checked = true; | |
| 8108 | + } | |
| 8109 | + } else { | |
| 8110 | + this.disabled = true; | |
| 8111 | + } | |
| 8112 | + }); | |
| 8113 | + | |
| 8114 | + if ( $dropdown.val() === 'csv' ) { | |
| 8115 | + jQuery( '.csv_opts' ).show(); | |
| 8116 | + jQuery( '.xml_opts' ).hide(); | |
| 8117 | + } else { | |
| 8118 | + jQuery( '.csv_opts' ).hide(); | |
| 8119 | + jQuery( '.xml_opts' ).show(); | |
| 8120 | + } | |
| 8121 | + | |
| 8122 | + var c = $selected.data( 'count' ); | |
| 8123 | + var exportField = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 8124 | + if ( c === 'single' ) { | |
| 8125 | + exportField.prop( 'multiple', false ); | |
| 8126 | + exportField.prop( 'checked', false ); | |
| 8127 | + } else { | |
| 8128 | + exportField.prop( 'multiple', true ); | |
| 8129 | + exportField.prop( 'disabled', false ); | |
| 8130 | + } | |
| 8131 | + $dropdown.trigger( 'change' ); | |
| 8132 | + } | |
| 8133 | + | |
| 8134 | + function showOrHideRepeaters( exportOption ) { | |
| 8135 | + if ( exportOption === '' ) { | |
| 8136 | + return; | |
| 8137 | + } | |
| 8138 | + | |
| 8139 | + const repeaters = document.querySelectorAll( '.frm-is-repeater' ); | |
| 8140 | + if ( ! repeaters.length ) { | |
| 8141 | + return; | |
| 8142 | + } | |
| 8143 | + | |
| 8144 | + if ( exportOption === 'csv' ) { | |
| 8145 | + repeaters.forEach( form => { | |
| 8146 | + form.classList.remove( 'frm_hidden' ); | |
| 8147 | + }); | |
| 8148 | + } else { | |
| 8149 | + repeaters.forEach( form => { | |
| 8150 | + form.classList.add( 'frm_hidden' ); | |
| 8151 | + }); | |
| 8152 | + } | |
| 8153 | + | |
| 8154 | + searchContent.call( document.querySelector( '.frm-auto-search' ) ); | |
| 8155 | + } | |
| 8156 | + | |
| 8157 | + function preventMultipleExport() { | |
| 8158 | + var type = jQuery( 'select[name=format]' ), | |
| 8159 | + selected = type.find( ':selected' ), | |
| 8160 | + count = selected.data( 'count' ), | |
| 8161 | + exportField = jQuery( 'input[name="frm_export_forms[]"]' ); | |
| 8162 | + | |
| 8163 | + if ( count === 'single' ) { | |
| 8164 | + // Disable all other fields to prevent multiple selections. | |
| 8165 | + if ( this.checked ) { | |
| 8166 | + exportField.prop( 'disabled', true ); | |
| 8167 | + this.removeAttribute( 'disabled' ); | |
| 8168 | + } else { | |
| 8169 | + exportField.prop( 'disabled', false ); | |
| 8170 | + } | |
| 8171 | + } else { | |
| 8172 | + exportField.prop( 'disabled', false ); | |
| 8173 | + } | |
| 8174 | + } | |
| 8175 | + | |
| 8176 | + function initiateMultiselect() { | |
| 8177 | + jQuery( '.frm_multiselect' ).hide().each( frmDom.bootstrap.multiselect.init ); | |
| 8178 | + } | |
| 8179 | + | |
| 8180 | + /* Addons page */ | |
| 8181 | + function installMultipleAddons( e ) { | |
| 8182 | + e.preventDefault(); | |
| 8183 | + installOrActivate( this, 'frm_multiple_addons' ); | |
| 8184 | + } | |
| 8185 | + | |
| 8186 | + function activateAddon( e ) { | |
| 8187 | + e.preventDefault(); | |
| 8188 | + installOrActivate( this, 'frm_activate_addon' ); | |
| 8189 | + } | |
| 8190 | + | |
| 8191 | + function installAddon( e ) { | |
| 8192 | + e.preventDefault(); | |
| 8193 | + installOrActivate( this, 'frm_install_addon' ); | |
| 8194 | + } | |
| 8195 | + | |
| 8196 | + function installOrActivate( clicked, action ) { | |
| 8197 | + let button, plugin, el, message; | |
| 8198 | + | |
| 8199 | + // Remove any leftover error messages, output an icon and get the plugin basename that needs to be activated. | |
| 8200 | + jQuery( '.frm-addon-error' ).remove(); | |
| 8201 | + button = jQuery( clicked ); | |
| 8202 | + plugin = button.attr( 'rel' ); | |
| 8203 | + el = button.parent(); | |
| 8204 | + message = el.parent().find( '.addon-status-label' ); | |
| 8205 | + | |
| 8206 | + button.addClass( 'frm_loading_button' ); | |
| 8207 | + | |
| 8208 | + // Process the Ajax to perform the activation. | |
| 8209 | + jQuery.ajax({ | |
| 8210 | + url: ajaxurl, | |
| 8211 | + type: 'POST', | |
| 8212 | + async: true, | |
| 8213 | + cache: false, | |
| 8214 | + dataType: 'json', | |
| 8215 | + data: { | |
| 8216 | + action: action, | |
| 8217 | + nonce: frmGlobal.nonce, | |
| 8218 | + plugin: plugin | |
| 8219 | + }, | |
| 8220 | + success: function( response ) { | |
| 8221 | + let saveAndReload; | |
| 8222 | + | |
| 8223 | + if ( 'string' !== typeof response && 'string' === typeof response.message ) { | |
| 8224 | + if ( 'undefined' !== typeof response.saveAndReload ) { | |
| 8225 | + saveAndReload = response.saveAndReload; | |
| 8226 | + } | |
| 8227 | + response = response.message; | |
| 8228 | + } | |
| 8229 | + | |
| 8230 | + const error = extractErrorFromAddOnResponse( response ); | |
| 8231 | + if ( error ) { | |
| 8232 | + addonError( error, el, button ); | |
| 8233 | + return; | |
| 8234 | + } | |
| 8235 | + | |
| 8236 | + afterAddonInstall( response, button, message, el, saveAndReload ); | |
| 8237 | + }, | |
| 8238 | + error: function() { | |
| 8239 | + button.removeClass( 'frm_loading_button' ); | |
| 8240 | + } | |
| 8241 | + }); | |
| 8242 | + } | |
| 8243 | + | |
| 8244 | + function installAddonWithCreds( e ) { | |
| 8245 | + // Prevent the default action, let the user know we are attempting to install again and go with it. | |
| 8246 | + e.preventDefault(); | |
| 8247 | + | |
| 8248 | + // Now let's make another Ajax request once the user has submitted their credentials. | |
| 8249 | + const proceed = jQuery( this ); | |
| 8250 | + const el = proceed.parent().parent(); | |
| 8251 | + const plugin = proceed.attr( 'rel' ); | |
| 8252 | + | |
| 8253 | + proceed.addClass( 'frm_loading_button' ); | |
| 8254 | + | |
| 8255 | + jQuery.ajax({ | |
| 8256 | + url: ajaxurl, | |
| 8257 | + type: 'POST', | |
| 8258 | + async: true, | |
| 8259 | + cache: false, | |
| 8260 | + dataType: 'json', | |
| 8261 | + data: { | |
| 8262 | + action: 'frm_install_addon', | |
| 8263 | + nonce: frm_admin_js.nonce, | |
| 8264 | + plugin: plugin, | |
| 8265 | + hostname: el.find( '#hostname' ).val(), | |
| 8266 | + username: el.find( '#username' ).val(), | |
| 8267 | + password: el.find( '#password' ).val() | |
| 8268 | + }, | |
| 8269 | + success: function( response ) { | |
| 8270 | + const error = extractErrorFromAddOnResponse( response ); | |
| 8271 | + if ( error ) { | |
| 8272 | + addonError( error, el, proceed ); | |
| 8273 | + return; | |
| 8274 | + } | |
| 8275 | + | |
| 8276 | + afterAddonInstall( response, proceed, message, el ); | |
| 8277 | + }, | |
| 8278 | + error: function() { | |
| 8279 | + proceed.removeClass( 'frm_loading_button' ); | |
| 8280 | + } | |
| 8281 | + }); | |
| 8282 | + } | |
| 8283 | + | |
| 8284 | + function afterAddonInstall( response, button, message, el, saveAndReload ) { | |
| 8285 | + const addonStatuses = document.querySelectorAll( '.frm-addon-status' ); | |
| 8286 | + addonStatuses.forEach( | |
| 8287 | + addonStatus => { | |
| 8288 | + addonStatus.textContent = response; | |
| 8289 | + addonStatus.style.display = 'block'; | |
| 8290 | + } | |
| 8291 | + ); | |
| 8292 | + | |
| 8293 | + // The Ajax request was successful, so let's update the output. | |
| 8294 | + button.css({ opacity: '0' }); | |
| 8295 | + message.text( frm_admin_js.active ); | |
| 8296 | + | |
| 8297 | + document.querySelectorAll( '.frm-oneclick' ).forEach( | |
| 8298 | + oneClick => { | |
| 8299 | + oneClick.style.display = 'none'; | |
| 8300 | + } | |
| 8301 | + ); | |
| 8302 | + | |
| 8303 | + jQuery( '#frm_upgrade_modal h2' ).hide(); | |
| 8304 | + jQuery( '#frm_upgrade_modal .frm_lock_icon' ).addClass( 'frm_lock_open_icon' ); | |
| 8305 | + jQuery( '#frm_upgrade_modal .frm_lock_icon use' ).attr( 'xlink:href', '#frm_lock_open_icon' ); | |
| 8306 | + | |
| 8307 | + // Proceed with CSS changes | |
| 8308 | + el.parent().removeClass( 'frm-addon-not-installed frm-addon-installed' ).addClass( 'frm-addon-active' ); | |
| 8309 | + button.removeClass( 'frm_loading_button' ); | |
| 8310 | + | |
| 8311 | + // Maybe refresh import and SMTP pages | |
| 8312 | + const refreshPage = document.querySelectorAll( '.frm-admin-page-import, #frm-admin-smtp, #frm-welcome' ); | |
| 8313 | + if ( refreshPage.length > 0 ) { | |
| 8314 | + window.location.reload(); | |
| 8315 | + return; | |
| 8316 | + } | |
| 8317 | + | |
| 8318 | + if ([ 'settings', 'form_builder' ].includes( saveAndReload ) ) { | |
| 8319 | + addonStatuses.forEach( | |
| 8320 | + addonStatus => { | |
| 8321 | + const inModal = null !== addonStatus.closest( '#frm_upgrade_modal' ); | |
| 8322 | + addonStatus.appendChild( getSaveAndReloadSettingsOptions( saveAndReload, inModal ) ); | |
| 8323 | + } | |
| 8324 | + ); | |
| 8325 | + } | |
| 8326 | + } | |
| 8327 | + | |
| 8328 | + function getSaveAndReloadSettingsOptions( saveAndReload, inModal ) { | |
| 8329 | + const className = 'frm-save-and-reload-options'; | |
| 8330 | + const children = [ saveAndReloadSettingsButton( saveAndReload ) ]; | |
| 8331 | + if ( inModal ) { | |
| 8332 | + children.push( closePopupButton() ); | |
| 8333 | + } | |
| 8334 | + return div({ className, children }); | |
| 8335 | + } | |
| 8336 | + | |
| 8337 | + function saveAndReloadSettingsButton( saveAndReload ) { | |
| 8338 | + var button = document.createElement( 'button' ); | |
| 8339 | + button.classList.add( 'frm-save-and-reload', 'button', 'button-primary', 'frm-button-primary' ); | |
| 8340 | + button.textContent = __( 'Save and Reload', 'formidable' ); | |
| 8341 | + button.addEventListener( 'click', () => { | |
| 8342 | + if ( saveAndReload === 'form_builder' ) { | |
| 8343 | + saveAndReloadFormBuilder(); | |
| 8344 | + } else if ( saveAndReload === 'settings' ) { | |
| 8345 | + saveAndReloadSettings(); | |
| 8346 | + } | |
| 8347 | + }); | |
| 8348 | + return button; | |
| 8349 | + } | |
| 8350 | + | |
| 8351 | + function closePopupButton() { | |
| 8352 | + var a = document.createElement( 'a' ); | |
| 8353 | + a.setAttribute( 'href', '#' ); | |
| 8354 | + a.classList.add( 'button', 'button-secondary', 'frm-button-secondary', 'dismiss' ); | |
| 8355 | + a.textContent = __( 'Close', 'formidable' ); | |
| 8356 | + return a; | |
| 8357 | + } | |
| 8358 | + | |
| 8359 | + function extractErrorFromAddOnResponse( response ) { | |
| 8360 | + if ( typeof response !== 'string' ) { | |
| 8361 | + if ( typeof response.success !== 'undefined' && response.success ) { | |
| 8362 | + return false; | |
| 8363 | + } | |
| 8364 | + | |
| 8365 | + if ( response.form ) { | |
| 8366 | + if ( jQuery( response.form ).is( '#message' ) ) { | |
| 8367 | + return { | |
| 8368 | + message: jQuery( response.form ).find( 'p' ).html() | |
| 8369 | + }; | |
| 8370 | + } | |
| 8371 | + } | |
| 8372 | + | |
| 8373 | + return response; | |
| 8374 | + } | |
| 8375 | + | |
| 8376 | + return false; | |
| 8377 | + } | |
| 8378 | + | |
| 8379 | + function addonError( response, el, button ) { | |
| 8380 | + if ( response.form ) { | |
| 8381 | + jQuery( '.frm-inline-error' ).remove(); | |
| 8382 | + button.closest( '.frm-card' ) | |
| 8383 | + .html( response.form ) | |
| 8384 | + .css({ padding: 5 }) | |
| 8385 | + .find( '#upgrade' ) | |
| 8386 | + .attr( 'rel', button.attr( 'rel' ) ) | |
| 8387 | + .on( 'click', installAddonWithCreds ); | |
| 8388 | + } else { | |
| 8389 | + el.append( '<div class="frm-addon-error frm_error_style"><p><strong>' + response.message + '</strong></p></div>' ); | |
| 8390 | + button.removeClass( 'frm_loading_button' ); | |
| 8391 | + jQuery( '.frm-addon-error' ).delay( 4000 ).fadeOut(); | |
| 8392 | + } | |
| 8393 | + } | |
| 8394 | + | |
| 8395 | + /* Templates */ | |
| 8396 | + | |
| 8397 | + function initNewFormModal() { | |
| 8398 | + var installFormTrigger, | |
| 8399 | + activeHoverIcons, | |
| 8400 | + $modal, | |
| 8401 | + handleError, | |
| 8402 | + handleEmailAddressError, | |
| 8403 | + handleConfirmEmailAddressError, | |
| 8404 | + showFreeTemplatesForm, | |
| 8405 | + firstLockedTemplate, | |
| 8406 | + isShowFreeTemplatesFormFirst, | |
| 8407 | + url, | |
| 8408 | + urlParams; | |
| 8409 | + | |
| 8410 | + url = new URL( window.location.href ); | |
| 8411 | + urlParams = url.searchParams; | |
| 8412 | + | |
| 8413 | + isShowFreeTemplatesFormFirst = urlParams.get( 'free-templates' ); | |
| 8414 | + | |
| 8415 | + jQuery( document ).on( 'click', '.frm-trigger-new-form-modal', triggerNewFormModal ); | |
| 8416 | + $modal = initModal( '#frm_new_form_modal', '600px' ); | |
| 8417 | + | |
| 8418 | + if ( false === $modal ) { | |
| 8419 | + return; | |
| 8420 | + } | |
| 8421 | + | |
| 8422 | + setTimeout( | |
| 8423 | + function() { | |
| 8424 | + $modal.get( 0 ).querySelector( '.postbox' ).style.display = 'block'; // Fixes pro issue #3508, prevent a conflict that hides the postbox in modal. | |
| 8425 | + }, | |
| 8426 | + 0 | |
| 8427 | + ); | |
| 8428 | + | |
| 8429 | + installFormTrigger = document.createElement( 'a' ); | |
| 8430 | + installFormTrigger.classList.add( 'frm-install-template', 'frm_hidden' ); | |
| 8431 | + document.body.appendChild( installFormTrigger ); | |
| 8432 | + | |
| 8433 | + jQuery( '.frm-install-template' ).on( 'click', function( event ) { | |
| 8434 | + var $h3Clone = jQuery( this ).closest( 'li, td' ).find( 'h3' ).clone(), | |
| 8435 | + nameLabel = document.getElementById( 'frm_new_name' ), | |
| 8436 | + descLabel = document.getElementById( 'frm_new_desc' ), | |
| 8437 | + oldName; | |
| 8438 | + | |
| 8439 | + $h3Clone.find( 'svg, .frm-plan-required-tag' ).remove(); | |
| 8440 | + oldName = $h3Clone.html().trim(); | |
| 8441 | + | |
| 8442 | + event.preventDefault(); | |
| 8443 | + | |
| 8444 | + document.getElementById( 'frm_template_name' ).value = oldName; | |
| 8445 | + document.getElementById( 'frm_link' ).value = this.attributes.rel.value; | |
| 8446 | + document.getElementById( 'frm_action_type' ).value = 'frm_install_template'; | |
| 8447 | + nameLabel.innerHTML = nameLabel.getAttribute( 'data-form' ); | |
| 8448 | + descLabel.innerHTML = descLabel.getAttribute( 'data-form' ); | |
| 8449 | + $modal.dialog( 'open' ); | |
| 8450 | + }); | |
| 8451 | + | |
| 8452 | + jQuery( document ).on( 'submit', '#frm-new-template', installTemplate ); | |
| 8453 | + | |
| 8454 | + jQuery( document ).on( 'click', '.frm-hover-icons .frm-preview-form', function( event ) { | |
| 8455 | + var $li, link, iframe, | |
| 8456 | + container = document.getElementById( 'frm-preview-block' ); | |
| 8457 | + | |
| 8458 | + event.preventDefault(); | |
| 8459 | + | |
| 8460 | + $li = jQuery( this ).closest( 'li' ); | |
| 8461 | + link = $li.attr( 'data-preview' ); | |
| 8462 | + | |
| 8463 | + if ( link.indexOf( ajaxurl ) > -1 ) { | |
| 8464 | + iframe = document.createElement( 'iframe' ); | |
| 8465 | + iframe.src = link; | |
| 8466 | + iframe.height = '400'; | |
| 8467 | + iframe.width = '100%'; | |
| 8468 | + container.innerHTML = ''; | |
| 8469 | + container.appendChild( iframe ); | |
| 8470 | + } else { | |
| 8471 | + frmApiPreview( container, link ); | |
| 8472 | + } | |
| 8473 | + | |
| 8474 | + jQuery( '#frm-preview-title' ).text( getStrippedTemplateName( $li ) ); | |
| 8475 | + $modal.attr( 'frm-page', 'preview' ); | |
| 8476 | + activeHoverIcons = jQuery( this ).closest( '.frm-hover-icons' ); | |
| 8477 | + }); | |
| 8478 | + | |
| 8479 | + jQuery( document ).on( 'click', 'li.frm-ready-made-solution[data-href]', function() { | |
| 8480 | + window.location = this.getAttribute( 'data-href' ); | |
| 8481 | + }); | |
| 8482 | + | |
| 8483 | + jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-create-form', function( event ) { | |
| 8484 | + var $li, name, link, action; | |
| 8485 | + | |
| 8486 | + event.preventDefault(); | |
| 8487 | + | |
| 8488 | + $li = jQuery( this ).closest( 'li' ); | |
| 8489 | + | |
| 8490 | + if ( $li.is( '[data-href]' ) ) { | |
| 8491 | + window.location = $li.attr( 'data-href' ); | |
| 8492 | + return; | |
| 8493 | + } | |
| 8494 | + | |
| 8495 | + if ( $li.hasClass( 'frm-add-blank-form' ) ) { | |
| 8496 | + name = link = ''; | |
| 8497 | + action = 'frm_install_form'; | |
| 8498 | + } else if ( $li.is( '[data-rel]' ) ) { | |
| 8499 | + name = getStrippedTemplateName( $li ); | |
| 8500 | + link = $li.attr( 'data-rel' ); | |
| 8501 | + action = 'frm_install_template'; | |
| 8502 | + } else { | |
| 8503 | + return; | |
| 8504 | + } | |
| 8505 | + | |
| 8506 | + transitionToAddDetails( $modal, name, link, action ); | |
| 8507 | + }); | |
| 8508 | + | |
| 8509 | + // Welcome page modals. | |
| 8510 | + jQuery( document ).on( 'click', '.frm-create-blank-form', function( event ) { | |
| 8511 | + event.preventDefault(); | |
| 8512 | + jQuery( '.frm-trigger-new-form-modal' ).trigger( 'click' ); | |
| 8513 | + transitionToAddDetails( $modal, '', '', 'frm_install_form' ); | |
| 8514 | + | |
| 8515 | + // Close the modal with the cancel button. | |
| 8516 | + jQuery( '.frm-modal-cancel.frm-back-to-all-templates' ).on( 'click', function() { | |
| 8517 | + jQuery( '.ui-widget-overlay' ).trigger( 'click' ); | |
| 8518 | + }); | |
| 8519 | + }); | |
| 8520 | + | |
| 8521 | + 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 ) { | |
| 8522 | + var $hoverIcons, $trigger, | |
| 8523 | + $li = jQuery( this ).closest( 'li' ), | |
| 8524 | + triggerClass = $li.hasClass( 'frm-locked-template' ) ? 'frm-unlock-form' : 'frm-create-form'; | |
| 8525 | + | |
| 8526 | + $hoverIcons = $li.find( '.frm-hover-icons' ); | |
| 8527 | + if ( ! $hoverIcons.length ) { | |
| 8528 | + $li.trigger( 'mouseover' ); | |
| 8529 | + $hoverIcons = $li.find( '.frm-hover-icons' ); | |
| 8530 | + $hoverIcons.hide(); | |
| 8531 | + } | |
| 8532 | + | |
| 8533 | + $trigger = $hoverIcons.find( '.' + triggerClass ); | |
| 8534 | + $trigger.trigger( 'click' ); | |
| 8535 | + }); | |
| 8536 | + | |
| 8537 | + jQuery( document ).on( 'click', 'li .frm-hover-icons .frm-delete-form', function( event ) { | |
| 8538 | + var $li, | |
| 8539 | + trigger; | |
| 8540 | + | |
| 8541 | + event.preventDefault(); | |
| 8542 | + | |
| 8543 | + $li = jQuery( this ).closest( 'li' ); | |
| 8544 | + $li.addClass( 'frm-deleting' ); | |
| 8545 | + trigger = document.createElement( 'a' ); | |
| 8546 | + trigger.setAttribute( 'href', '#' ); | |
| 8547 | + trigger.setAttribute( 'data-id', $li.attr( 'data-formid' ) ); | |
| 8548 | + $li.attr( 'id', 'frm-template-custom-' + $li.attr( 'data-formid' ) ); | |
| 8549 | + jQuery( trigger ).on( 'click', trashTemplate ); | |
| 8550 | + trigger.click(); | |
| 8551 | + setTemplateCount( $li.closest( '.accordion-section' ).get( 0 ) ); | |
| 8552 | + }); | |
| 8553 | + | |
| 8554 | + showFreeTemplatesForm = function( $el ) { | |
| 8555 | + var formContainer = document.getElementById( 'frmapi-email-form' ); | |
| 8556 | + jQuery.ajax({ | |
| 8557 | + dataType: 'json', | |
| 8558 | + url: formContainer.getAttribute( 'data-url' ), | |
| 8559 | + success: function( json ) { | |
| 8560 | + var form = json.renderedHtml; | |
| 8561 | + form = form.replace( /<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi, '' ); | |
| 8562 | + formContainer.innerHTML = form; | |
| 8563 | + } | |
| 8564 | + }); | |
| 8565 | + | |
| 8566 | + $modal.attr( 'frm-page', 'email' ); | |
| 8567 | + $modal.attr( 'frm-this-form', $el.attr( 'data-key' ) ); | |
| 8568 | + $el.append( installFormTrigger ); | |
| 8569 | + }; | |
| 8570 | + | |
| 8571 | + jQuery( document ).on( 'click', 'li.frm-locked-template .frm-hover-icons .frm-unlock-form', function( event ) { | |
| 8572 | + var $li, | |
| 8573 | + activePage; | |
| 8574 | + | |
| 8575 | + event.preventDefault(); | |
| 8576 | + | |
| 8577 | + $li = jQuery( this ).closest( '.frm-locked-template' ); | |
| 8578 | + | |
| 8579 | + if ( $li.hasClass( 'frm-free-template' ) ) { | |
| 8580 | + showFreeTemplatesForm( $li ); | |
| 8581 | + return; | |
| 8582 | + } | |
| 8583 | + | |
| 8584 | + if ( $modal.hasClass( 'frm-expired' ) ) { | |
| 8585 | + activePage = 'renew'; | |
| 8586 | + } else { | |
| 8587 | + activePage = 'upgrade'; | |
| 8588 | + } | |
| 8589 | + | |
| 8590 | + $modal.attr( 'frm-page', activePage ); | |
| 8591 | + }); | |
| 8592 | + | |
| 8593 | + jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop', function() { | |
| 8594 | + jQuery( this ) | |
| 8595 | + .closest( '.accordion-section-content' ).css( 'overflow', 'visible' ) | |
| 8596 | + .closest( '.accordion-section' ).css( 'z-index', 1 ); | |
| 8597 | + }); | |
| 8598 | + | |
| 8599 | + jQuery( document ).on( 'click', '#frm_new_form_modal #frm-template-drop + .frm-dropdown-menu .frm-build-template', function() { | |
| 8600 | + var name = this.getAttribute( 'data-fullname' ), | |
| 8601 | + link = this.getAttribute( 'data-formid' ), | |
| 8602 | + action = 'frm_build_template'; | |
| 8603 | + transitionToAddDetails( $modal, name, link, action ); | |
| 8604 | + }); | |
| 8605 | + | |
| 8606 | + handleError = function( inputId, errorId, type, message ) { | |
| 8607 | + var $error = jQuery( errorId ); | |
| 8608 | + $error.removeClass( 'frm_hidden' ).attr( 'frm-error', type ); | |
| 8609 | + | |
| 8610 | + if ( typeof message !== 'undefined' ) { | |
| 8611 | + $error.find( 'span[frm-error="' + type + '"]' ).text( message ); | |
| 8612 | + } | |
| 8613 | + | |
| 8614 | + jQuery( inputId ).one( 'keyup', function() { | |
| 8615 | + $error.addClass( 'frm_hidden' ); | |
| 8616 | + }); | |
| 8617 | + }; | |
| 8618 | + | |
| 8619 | + handleEmailAddressError = function( type ) { | |
| 8620 | + handleError( '#frm_leave_email', '#frm_leave_email_error', type ); | |
| 8621 | + }; | |
| 8622 | + | |
| 8623 | + jQuery( document ).on( 'click', '#frm-add-my-email-address', function( event ) { | |
| 8624 | + var email = document.getElementById( 'frm_leave_email' ).value.trim(), | |
| 8625 | + regex, | |
| 8626 | + $hiddenForm, | |
| 8627 | + $hiddenEmailField; | |
| 8628 | + | |
| 8629 | + event.preventDefault(); | |
| 8630 | + | |
| 8631 | + if ( '' === email ) { | |
| 8632 | + handleEmailAddressError( 'empty' ); | |
| 8633 | + return; | |
| 8634 | + } | |
| 8635 | + | |
| 8636 | + 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; | |
| 8637 | + | |
| 8638 | + if ( regex.test( email ) === false ) { | |
| 8639 | + handleEmailAddressError( 'invalid' ); | |
| 8640 | + return; | |
| 8641 | + } | |
| 8642 | + | |
| 8643 | + $hiddenForm = jQuery( '#frmapi-email-form' ).find( 'form' ); | |
| 8644 | + $hiddenEmailField = $hiddenForm.find( '[type="email"]' ).not( '.frm_verify' ); | |
| 8645 | + if ( ! $hiddenEmailField.length ) { | |
| 8646 | + return; | |
| 8647 | + } | |
| 8648 | + | |
| 8649 | + $hiddenEmailField.val( email ); | |
| 8650 | + jQuery.ajax({ | |
| 8651 | + type: 'POST', | |
| 8652 | + url: $hiddenForm.attr( 'action' ), | |
| 8653 | + data: $hiddenForm.serialize() + '&action=frm_forms_preview' | |
| 8654 | + }).done( function( data ) { | |
| 8655 | + var message = jQuery( data ).find( '.frm_message' ).text().trim(); | |
| 8656 | + if ( message.indexOf( 'Thanks!' ) >= 0 ) { | |
| 8657 | + $modal.attr( 'frm-page', 'code' ); | |
| 8658 | + } else { | |
| 8659 | + handleEmailAddressError( 'invalid' ); | |
| 8660 | + } | |
| 8661 | + }); | |
| 8662 | + }); | |
| 8663 | + | |
| 8664 | + handleConfirmEmailAddressError = function( type, message ) { | |
| 8665 | + handleError( '#frm_code_from_email', '#frm_code_from_email_error', type, message ); | |
| 8666 | + }; | |
| 8667 | + | |
| 8668 | + jQuery( document ).on( 'click', '.frm-confirm-email-address', function( event ) { | |
| 8669 | + var code = document.getElementById( 'frm_code_from_email' ).value.trim(); | |
| 8670 | + | |
| 8671 | + event.preventDefault(); | |
| 8672 | + | |
| 8673 | + if ( '' === code ) { | |
| 8674 | + handleConfirmEmailAddressError( 'empty' ); | |
| 8675 | + return; | |
| 8676 | + } | |
| 8677 | + | |
| 8678 | + jQuery.ajax({ | |
| 8679 | + type: 'POST', | |
| 8680 | + url: ajaxurl, | |
| 8681 | + dataType: 'json', | |
| 8682 | + data: { | |
| 8683 | + action: 'template_api_signup', | |
| 8684 | + nonce: frmGlobal.nonce, | |
| 8685 | + code: code, | |
| 8686 | + key: $modal.attr( 'frm-this-form' ) | |
| 8687 | + }, | |
| 8688 | + success: function( response ) { | |
| 8689 | + if ( response.success ) { | |
| 8690 | + if ( isShowFreeTemplatesFormFirst ) { | |
| 8691 | + // Remove free-templates param from URL then reload page. | |
| 8692 | + urlParams.delete( 'free-templates' ); | |
| 8693 | + url.search = urlParams.toString(); | |
| 8694 | + window.location.href = url.toString(); | |
| 8695 | + | |
| 8696 | + return; | |
| 8697 | + } | |
| 8698 | + | |
| 8699 | + if ( typeof response.data !== 'undefined' && typeof response.data.url !== 'undefined' ) { | |
| 8700 | + installFormTrigger.setAttribute( 'rel', response.data.url ); | |
| 8701 | + installFormTrigger.click(); | |
| 8702 | + $modal.attr( 'frm-page', 'details' ); | |
| 8703 | + | |
| 8704 | + const hookName = 'frm_new_form_modal_form'; | |
| 8705 | + wp.hooks.doAction( hookName, $modal ); | |
| 8706 | + | |
| 8707 | + document.getElementById( 'frm_action_type' ).value = 'frm_install_template'; | |
| 8708 | + | |
| 8709 | + if ( typeof response.data.urlByKey !== 'undefined' ) { | |
| 8710 | + updateTemplateModalFreeUrls( response.data.urlByKey ); | |
| 8711 | + } | |
| 8712 | + } | |
| 8713 | + } else { | |
| 8714 | + if ( Array.isArray( response.data ) && response.data.length ) { | |
| 8715 | + handleConfirmEmailAddressError( 'custom', response.data[0].message ); | |
| 8716 | + } else { | |
| 8717 | + handleConfirmEmailAddressError( 'wrong-code' ); | |
| 8718 | + } | |
| 8719 | + | |
| 8720 | + jQuery( '#frm_code_from_email_options' ).removeClass( 'frm_hidden' ); | |
| 8721 | + } | |
| 8722 | + } | |
| 8723 | + }); | |
| 8724 | + }); | |
| 8725 | + | |
| 8726 | + jQuery( document ).on( 'click', '#frm-change-email-address', function() { | |
| 8727 | + $modal.attr( 'frm-page', 'email' ); | |
| 8728 | + }); | |
| 8729 | + | |
| 8730 | + jQuery( document ).on( 'click', '#frm-resend-code', function() { | |
| 8731 | + document.getElementById( 'frm_code_from_email' ).value = ''; | |
| 8732 | + jQuery( '#frm_code_from_email_options, #frm_code_from_email_error' ).addClass( 'frm_hidden' ); | |
| 8733 | + document.getElementById( 'frm-add-my-email-address' ).click(); | |
| 8734 | + }); | |
| 8735 | + | |
| 8736 | + jQuery( document ).on( 'frmAfterSearch', '#frm_new_form_modal #template-search-input', function() { | |
| 8737 | + var categories = $modal.get( 0 ).querySelector( '.frm-categories-list' ).children, | |
| 8738 | + categoryIndex, | |
| 8739 | + category, | |
| 8740 | + searchableTemplates, | |
| 8741 | + count; | |
| 8742 | + | |
| 8743 | + for ( categoryIndex in categories ) { | |
| 8744 | + if ( isNaN( categoryIndex ) ) { | |
| 8745 | + continue; | |
| 8746 | + } | |
| 8747 | + | |
| 8748 | + category = categories[ categoryIndex ]; | |
| 8749 | + if ( ! category.classList.contains( 'accordion-section' ) ) { | |
| 8750 | + continue; | |
| 8751 | + } | |
| 8752 | + | |
| 8753 | + searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden)' ); | |
| 8754 | + count = searchableTemplates.length; | |
| 8755 | + jQuery( category ).toggleClass( 'frm_hidden', this.value !== '' && ! count ); | |
| 8756 | + setTemplateCount( category, searchableTemplates ); | |
| 8757 | + } | |
| 8758 | + }); | |
| 8759 | + | |
| 8760 | + 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 ) { | |
| 8761 | + document.getElementById( 'frm-create-title' ).removeAttribute( 'frm-type' ); | |
| 8762 | + $modal.attr( 'frm-page', 'create' ); | |
| 8763 | + }); | |
| 8764 | + | |
| 8765 | + jQuery( document ).on( 'click', '.frm-use-this-template', function( event ) { | |
| 8766 | + var $trigger; | |
| 8767 | + | |
| 8768 | + event.preventDefault(); | |
| 8769 | + | |
| 8770 | + $trigger = activeHoverIcons.find( '.frm-create-form' ); | |
| 8771 | + if ( $trigger.closest( '.frm-selectable' ).hasClass( 'frm-locked-template' ) ) { | |
| 8772 | + $trigger = activeHoverIcons.find( '.frm-unlock-form' ); | |
| 8773 | + } | |
| 8774 | + | |
| 8775 | + $trigger.trigger( 'click' ); | |
| 8776 | + }); | |
| 8777 | + | |
| 8778 | + jQuery( document ).on( 'click', '.frm-submit-new-template', function( event ) { | |
| 8779 | + var button; | |
| 8780 | + event.preventDefault(); | |
| 8781 | + button = document.getElementById( 'frm-new-template' ).querySelector( 'button' ); | |
| 8782 | + if ( null !== button ) { | |
| 8783 | + button.click(); | |
| 8784 | + } | |
| 8785 | + }); | |
| 8786 | + | |
| 8787 | + if ( urlParams.get( 'triggerNewFormModal' ) ) { | |
| 8788 | + triggerNewFormModal(); | |
| 8789 | + | |
| 8790 | + if ( isShowFreeTemplatesFormFirst ) { | |
| 8791 | + firstLockedTemplate = jQuery( 'li.frm-locked-template.frm-free-template' ).eq( 0 ); | |
| 8792 | + | |
| 8793 | + if ( firstLockedTemplate.length ) { | |
| 8794 | + showFreeTemplatesForm( firstLockedTemplate ); | |
| 8795 | + } | |
| 8796 | + } | |
| 8797 | + } | |
| 8798 | + } | |
| 8799 | + | |
| 8800 | + function updateTemplateModalFreeUrls( urlByKey ) { | |
| 8801 | + jQuery( '#frm_new_form_modal' ).find( '.frm-selectable[data-key]' ).each( function() { | |
| 8802 | + var $template = jQuery( this ), | |
| 8803 | + key = $template.attr( 'data-key' ); | |
| 8804 | + if ( 'undefined' !== typeof urlByKey[ key ]) { | |
| 8805 | + $template.removeClass( 'frm-locked-template' ); | |
| 8806 | + $template.find( 'h3 svg' ).remove(); // remove the lock from the title | |
| 8807 | + $template.attr( 'data-rel', urlByKey[ key ]); | |
| 8808 | + } | |
| 8809 | + }); | |
| 8810 | + } | |
| 8811 | + | |
| 8812 | + function transitionToAddDetails( $modal, name, link, action ) { | |
| 8813 | + var nameLabel = document.getElementById( 'frm_new_name' ), | |
| 8814 | + descLabel = document.getElementById( 'frm_new_desc' ), | |
| 8815 | + type = [ 'frm_install_template', 'frm_install_form' ].indexOf( action ) >= 0 ? 'form' : 'template', | |
| 8816 | + templateNameInput = document.getElementById( 'frm_template_name' ); | |
| 8817 | + | |
| 8818 | + templateNameInput.value = name; | |
| 8819 | + document.getElementById( 'frm_link' ).value = link; | |
| 8820 | + document.getElementById( 'frm_action_type' ).value = action; | |
| 8821 | + nameLabel.textContent = nameLabel.getAttribute( 'data-' + type ); | |
| 8822 | + if ( descLabel !== null ) { | |
| 8823 | + descLabel.textContent = descLabel.getAttribute( 'data-' + type ); | |
| 8824 | + } | |
| 8825 | + | |
| 8826 | + document.getElementById( 'frm-create-title' ).setAttribute( 'frm-type', type ); | |
| 8827 | + | |
| 8828 | + $modal.attr( 'frm-page', 'details' ); | |
| 8829 | + | |
| 8830 | + const hookName = 'frm_new_form_modal_form'; | |
| 8831 | + wp.hooks.doAction( hookName, $modal ); | |
| 8832 | + | |
| 8833 | + if ( '' === name ) { | |
| 8834 | + templateNameInput.focus(); | |
| 8835 | + } | |
| 8836 | + } | |
| 8837 | + | |
| 8838 | + function getStrippedTemplateName( $li ) { | |
| 8839 | + var $clone = $li.find( 'h3' ).clone(); | |
| 8840 | + $clone.find( 'svg, .frm-plan-required-tag, .frm-new-pill' ).remove(); | |
| 8841 | + return $clone.html().trim(); | |
| 8842 | + } | |
| 8843 | + | |
| 8844 | + function setTemplateCount( category, searchableTemplates ) { | |
| 8845 | + var count, | |
| 8846 | + templateIndex, | |
| 8847 | + availableCounter, | |
| 8848 | + availableCount; | |
| 8849 | + | |
| 8850 | + if ( typeof searchableTemplates === 'undefined' ) { | |
| 8851 | + searchableTemplates = category.querySelectorAll( '.frm-searchable-template:not(.frm_hidden):not(.frm-deleting)' ); | |
| 8852 | + } | |
| 8853 | + | |
| 8854 | + count = searchableTemplates.length; | |
| 8855 | + category.querySelector( '.frm-template-count' ).textContent = count; | |
| 8856 | + | |
| 8857 | + jQuery( category ).find( '.frm-templates-plural' ).toggleClass( 'frm_hidden', count === 1 ); | |
| 8858 | + jQuery( category ).find( '.frm-templates-singular' ).toggleClass( 'frm_hidden', count !== 1 ); | |
| 8859 | + | |
| 8860 | + availableCounter = category.querySelector( '.frm-available-templates-count' ); | |
| 8861 | + if ( availableCounter !== null ) { | |
| 8862 | + availableCount = 0; | |
| 8863 | + for ( templateIndex in searchableTemplates ) { | |
| 8864 | + if ( ! isNaN( templateIndex ) && ! searchableTemplates[ templateIndex ].classList.contains( 'frm-locked-template' ) ) { | |
| 8865 | + availableCount++; | |
| 8866 | + } | |
| 8867 | + } | |
| 8868 | + | |
| 8869 | + availableCounter.textContent = availableCount; | |
| 8870 | + } | |
| 8871 | + } | |
| 8872 | + | |
| 8873 | + function initSelectionAutocomplete() { | |
| 8874 | + frmDom.autocomplete.initSelectionAutocomplete(); | |
| 8875 | + } | |
| 8876 | + | |
| 8877 | + function nextInstallStep( thisStep ) { | |
| 8878 | + thisStep.classList.add( 'frm_grey' ); | |
| 8879 | + thisStep.nextElementSibling.classList.remove( 'frm_grey' ); | |
| 8880 | + } | |
| 8881 | + | |
| 8882 | + function frmApiPreview( cont, link ) { | |
| 8883 | + cont.innerHTML = '<div class="frm-wait"></div>'; | |
| 8884 | + jQuery.ajax({ | |
| 8885 | + dataType: 'json', | |
| 8886 | + url: link, | |
| 8887 | + success: function( json ) { | |
| 8888 | + var form = json.renderedHtml; | |
| 8889 | + form = form.replace( /<script\b[^<]*(js\/jquery\/jquery)[^<]*><\/script>/gi, '' ); | |
| 8890 | + form = form.replace( /<link\b[^>]*(jquery-ui.min.css)[^>]*>/gi, '' ); | |
| 8891 | + form = form.replace( ' frm_logic_form ', ' ' ); | |
| 8892 | + form = form.replace( '<form ', '<form onsubmit="event.preventDefault();" ' ); | |
| 8893 | + cont.innerHTML = '<div class="frm-wait" id="frm-remove-me"></div><div class="frm-fade" id="frm-show-me">' + | |
| 8894 | + form + '</div>'; | |
| 8895 | + setTimeout( function() { | |
| 8896 | + document.getElementById( 'frm-remove-me' ).style.display = 'none'; | |
| 8897 | + document.getElementById( 'frm-show-me' ).style.opacity = '1'; | |
| 8898 | + }, 300 ); | |
| 8899 | + } | |
| 8900 | + }); | |
| 8901 | + } | |
| 8902 | + | |
| 8903 | + function installTemplateFieldset( e ) { | |
| 8904 | + /*jshint validthis:true */ | |
| 8905 | + var fieldset = this.parentNode.parentNode, | |
| 8906 | + action = fieldset.elements.type.value, | |
| 8907 | + button = this; | |
| 8908 | + e.preventDefault(); | |
| 8909 | + button.classList.add( 'frm_loading_button' ); | |
| 8910 | + installNewForm( fieldset, action, button ); | |
| 8911 | + } | |
| 8912 | + | |
| 8913 | + function installTemplate( e ) { | |
| 8914 | + /*jshint validthis:true */ | |
| 8915 | + var action = this.elements.type.value, | |
| 8916 | + button = this.querySelector( 'button' ); | |
| 8917 | + e.preventDefault(); | |
| 8918 | + button.classList.add( 'frm_loading_button' ); | |
| 8919 | + installNewForm( this, action, button ); | |
| 8920 | + } | |
| 8921 | + | |
| 8922 | + function installNewForm( form, action, button ) { | |
| 8923 | + const formData = formToData( form ); | |
| 8924 | + const formName = formData.template_name; | |
| 8925 | + const formDesc = formData.template_desc; | |
| 8926 | + const link = form.elements.link.value; | |
| 8927 | + | |
| 8928 | + let data = { | |
| 8929 | + action: action, | |
| 8930 | + xml: link, | |
| 8931 | + name: formName, | |
| 8932 | + desc: formDesc, | |
| 8933 | + form: JSON.stringify( formData ), | |
| 8934 | + nonce: frmGlobal.nonce | |
| 8935 | + }; | |
| 8936 | + | |
| 8937 | + const hookName = 'frm_before_install_new_form'; | |
| 8938 | + const filterArgs = { formData }; | |
| 8939 | + data = wp.hooks.applyFilters( hookName, data, filterArgs ); | |
| 8940 | + | |
| 8941 | + postAjax( data, function( response ) { | |
| 8942 | + if ( typeof response.redirect !== 'undefined' ) { | |
| 8943 | + const redirect = response.redirect; | |
| 8944 | + if ( typeof form.elements.redirect === 'undefined' ) { | |
| 8945 | + window.location = redirect; | |
| 8946 | + } else { | |
| 8947 | + const href = document.getElementById( 'frm-redirect-link' ); | |
| 8948 | + if ( typeof link !== 'undefined' && href !== null ) { | |
| 8949 | + // Show the next installation step. | |
| 8950 | + href.setAttribute( 'href', redirect ); | |
| 8951 | + href.classList.remove( 'frm_grey', 'disabled' ); | |
| 8952 | + nextInstallStep( form.parentNode.parentNode ); | |
| 8953 | + button.classList.add( 'frm_grey', 'disabled' ); | |
| 8954 | + } | |
| 8955 | + } | |
| 8956 | + } else { | |
| 8957 | + jQuery( '.spinner' ).css( 'visibility', 'hidden' ); | |
| 8958 | + | |
| 8959 | + // Show response.message | |
| 8960 | + if ( 'string' === typeof response.message ) { | |
| 8961 | + showInstallFormErrorModal( response.message ); | |
| 8962 | + } | |
| 8963 | + } | |
| 8964 | + button.classList.remove( 'frm_loading_button' ); | |
| 8965 | + }); | |
| 8966 | + } | |
| 8967 | + | |
| 8968 | + function showInstallFormErrorModal( message ) { | |
| 8969 | + const modalContent = div( message ); | |
| 8970 | + modalContent.style.padding = '20px 40px'; | |
| 8971 | + const modal = frmDom.modal.maybeCreateModal( | |
| 8972 | + 'frmInstallFormErrorModal', | |
| 8973 | + { | |
| 8974 | + title: __( 'Unable to install template', 'formidable' ), | |
| 8975 | + content: modalContent | |
| 8976 | + } | |
| 8977 | + ); | |
| 8978 | + modal.classList.add( 'frm_common_modal' ); | |
| 8979 | + } | |
| 8980 | + | |
| 8981 | + function handleCaptchaTypeChange( e ) { | |
| 8982 | + const thresholdContainer = document.getElementById( 'frm_captcha_threshold_container' ); | |
| 8983 | + if ( thresholdContainer ) { | |
| 8984 | + thresholdContainer.classList.toggle( 'frm_hidden', 'v3' !== e.target.value ); | |
| 8985 | + } | |
| 8986 | + } | |
| 8987 | + | |
| 8988 | + function trashTemplate( e ) { | |
| 8989 | + /*jshint validthis:true */ | |
| 8990 | + var id = this.getAttribute( 'data-id' ); | |
| 8991 | + e.preventDefault(); | |
| 8992 | + | |
| 8993 | + data = { | |
| 8994 | + action: 'frm_forms_trash', | |
| 8995 | + id: id, | |
| 8996 | + nonce: frmGlobal.nonce | |
| 8997 | + }; | |
| 8998 | + postAjax( data, function() { | |
| 8999 | + var card = document.getElementById( 'frm-template-custom-' + id ); | |
| 9000 | + fadeOut( card, function() { | |
| 9001 | + card.parentNode.removeChild( card ); | |
| 9002 | + }); | |
| 9003 | + }); | |
| 9004 | + } | |
| 9005 | + | |
| 9006 | + function searchContent() { | |
| 9007 | + /*jshint validthis:true */ | |
| 9008 | + var i, | |
| 9009 | + regEx = false, | |
| 9010 | + searchText = this.value.toLowerCase(), | |
| 9011 | + toSearch = this.getAttribute( 'data-tosearch' ), | |
| 9012 | + items = document.getElementsByClassName( toSearch ); | |
| 9013 | + | |
| 9014 | + if ( this.tagName === 'SELECT' ) { | |
| 9015 | + searchText = selectedOptions( this ); | |
| 9016 | + searchText = searchText.join( '|' ).toLowerCase(); | |
| 9017 | + regEx = true; | |
| 9018 | + } | |
| 9019 | + | |
| 9020 | + if ( toSearch === 'frm-action' && searchText !== '' ) { | |
| 9021 | + var addons = document.getElementById( 'frm_email_addon_menu' ).classList; | |
| 9022 | + addons.remove( 'frm-all-actions' ); | |
| 9023 | + addons.add( 'frm-limited-actions' ); | |
| 9024 | + } | |
| 9025 | + | |
| 9026 | + for ( i = 0; i < items.length; i++ ) { | |
| 9027 | + var innerText = items[i].innerText.toLowerCase(); | |
| 9028 | + const itemCanBeShown = ! ( getExportOption() === 'xml' && items[i].classList.contains( 'frm-is-repeater' ) ); | |
| 9029 | + if ( searchText === '' ) { | |
| 9030 | + if ( itemCanBeShown ) { | |
| 9031 | + items[i].classList.remove( 'frm_hidden' ); | |
| 9032 | + } | |
| 9033 | + items[i].classList.remove( 'frm-search-result' ); | |
| 9034 | + } else if ( ( regEx && new RegExp( searchText ).test( innerText ) ) || innerText.indexOf( searchText ) >= 0 ) { | |
| 9035 | + if ( itemCanBeShown ) { | |
| 9036 | + items[i].classList.remove( 'frm_hidden' ); | |
| 9037 | + } | |
| 9038 | + items[i].classList.add( 'frm-search-result' ); | |
| 9039 | + } else { | |
| 9040 | + items[i].classList.add( 'frm_hidden' ); | |
| 9041 | + items[i].classList.remove( 'frm-search-result' ); | |
| 9042 | + } | |
| 9043 | + } | |
| 9044 | + | |
| 9045 | + jQuery( this ).trigger( 'frmAfterSearch' ); | |
| 9046 | + } | |
| 9047 | + | |
| 9048 | + function stopPropagation( e ) { | |
| 9049 | + e.stopPropagation(); | |
| 9050 | + } | |
| 9051 | + | |
| 9052 | + /* Helpers */ | |
| 9053 | + | |
| 9054 | + function selectedOptions( select ) { | |
| 9055 | + var opt, | |
| 9056 | + result = [], | |
| 9057 | + options = select && select.options; | |
| 9058 | + | |
| 9059 | + for ( var i = 0, iLen = options.length; i < iLen; i++ ) { | |
| 9060 | + opt = options[i]; | |
| 9061 | + | |
| 9062 | + if ( opt.selected ) { | |
| 9063 | + result.push( opt.value ); | |
| 9064 | + } | |
| 9065 | + } | |
| 9066 | + return result; | |
| 9067 | + } | |
| 9068 | + | |
| 9069 | + function triggerEvent( element, event ) { | |
| 9070 | + var evt = document.createEvent( 'HTMLEvents' ); | |
| 9071 | + evt.initEvent( event, false, true ); | |
| 9072 | + element.dispatchEvent( evt ); | |
| 9073 | + } | |
| 9074 | + | |
| 9075 | + function postAjax( data, success ) { | |
| 9076 | + let response; | |
| 9077 | + | |
| 9078 | + const xmlHttp = new XMLHttpRequest(); | |
| 9079 | + const params = typeof data === 'string' ? data : Object.keys( data ).map( | |
| 9080 | + function( k ) { | |
| 9081 | + return encodeURIComponent( k ) + '=' + encodeURIComponent( data[k]); | |
| 9082 | + } | |
| 9083 | + ).join( '&' ); | |
| 9084 | + | |
| 9085 | + xmlHttp.open( 'post', ajaxurl, true ); | |
| 9086 | + xmlHttp.onreadystatechange = function() { | |
| 9087 | + if ( xmlHttp.readyState > 3 && xmlHttp.status == 200 ) { | |
| 9088 | + response = xmlHttp.responseText; | |
| 9089 | + try { | |
| 9090 | + response = JSON.parse( response ); | |
| 9091 | + } catch ( e ) { | |
| 9092 | + // The response may not be JSON, so just return it. | |
| 9093 | + } | |
| 9094 | + success( response ); | |
| 9095 | + } | |
| 9096 | + }; | |
| 9097 | + xmlHttp.setRequestHeader( 'X-Requested-With', 'XMLHttpRequest' ); | |
| 9098 | + xmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' ); | |
| 9099 | + xmlHttp.send( params ); | |
| 9100 | + return xmlHttp; | |
| 9101 | + } | |
| 9102 | + | |
| 9103 | + function fadeOut( element, success ) { | |
| 9104 | + element.classList.add( 'frm-fade' ); | |
| 9105 | + setTimeout( success, 1000 ); | |
| 9106 | + } | |
| 9107 | + | |
| 9108 | + function invisible( classes ) { | |
| 9109 | + jQuery( classes ).css( 'visibility', 'hidden' ); | |
| 9110 | + } | |
| 9111 | + | |
| 9112 | + function visible( classes ) { | |
| 9113 | + jQuery( classes ).css( 'visibility', 'visible' ); | |
| 9114 | + } | |
| 9115 | + | |
| 9116 | + function initModal( id, width ) { | |
| 9117 | + const $info = jQuery( id ); | |
| 9118 | + if ( ! $info.length ) { | |
| 9119 | + return false; | |
| 9120 | + } | |
| 9121 | + | |
| 9122 | + if ( typeof width === 'undefined' ) { | |
| 9123 | + width = '550px'; | |
| 9124 | + } | |
| 9125 | + | |
| 9126 | + const dialogArgs = { | |
| 9127 | + dialogClass: 'frm-dialog', | |
| 9128 | + modal: true, | |
| 9129 | + autoOpen: false, | |
| 9130 | + closeOnEscape: true, | |
| 9131 | + width: width, | |
| 9132 | + resizable: false, | |
| 9133 | + draggable: false, | |
| 9134 | + open: function() { | |
| 9135 | + jQuery( '.ui-dialog-titlebar' ).addClass( 'frm_hidden' ).removeClass( 'ui-helper-clearfix' ); | |
| 9136 | + jQuery( '#wpwrap' ).addClass( 'frm_overlay' ); | |
| 9137 | + jQuery( '.frm-dialog' ).removeClass( 'ui-widget ui-widget-content ui-corner-all' ); | |
| 9138 | + $info.removeClass( 'ui-dialog-content ui-widget-content' ); | |
| 9139 | + bindClickForDialogClose( $info ); | |
| 9140 | + }, | |
| 9141 | + close: function() { | |
| 9142 | + jQuery( '#wpwrap' ).removeClass( 'frm_overlay' ); | |
| 9143 | + jQuery( '.spinner' ).css( 'visibility', 'hidden' ); | |
| 9144 | + | |
| 9145 | + this.removeAttribute( 'data-option-type' ); | |
| 9146 | + const optionType = document.getElementById( 'bulk-option-type' ); | |
| 9147 | + if ( optionType ) { | |
| 9148 | + optionType.value = ''; | |
| 9149 | + } | |
| 9150 | + } | |
| 9151 | + }; | |
| 9152 | + | |
| 9153 | + $info.dialog( dialogArgs ); | |
| 9154 | + | |
| 9155 | + return $info; | |
| 9156 | + } | |
| 9157 | + | |
| 9158 | + function toggle( cname, id ) { | |
| 9159 | + if ( id === '#' ) { | |
| 9160 | + var cont = document.getElementById( cname ); | |
| 9161 | + var hidden = cont.style.display; | |
| 9162 | + if ( hidden === 'none' ) { | |
| 9163 | + cont.style.display = 'block'; | |
| 9164 | + } else { | |
| 9165 | + cont.style.display = 'none'; | |
| 9166 | + } | |
| 9167 | + } else { | |
| 9168 | + var vis = cname.is( ':visible' ); | |
| 9169 | + if ( vis ) { | |
| 9170 | + cname.hide(); | |
| 9171 | + } else { | |
| 9172 | + cname.show(); | |
| 9173 | + } | |
| 9174 | + } | |
| 9175 | + } | |
| 9176 | + | |
| 9177 | + function removeWPUnload() { | |
| 9178 | + window.onbeforeunload = null; | |
| 9179 | + var w = jQuery( window ); | |
| 9180 | + w.off( 'beforeunload.widgets' ); | |
| 9181 | + w.off( 'beforeunload.edit-post' ); | |
| 9182 | + } | |
| 9183 | + | |
| 9184 | + function addMultiselectLabelListener() { | |
| 9185 | + const clickListener = ( e ) => { | |
| 9186 | + if ( 'LABEL' !== e.target.nodeName ) { | |
| 9187 | + return; | |
| 9188 | + } | |
| 9189 | + | |
| 9190 | + const labelFor = e.target.getAttribute( 'for' ); | |
| 9191 | + if ( ! labelFor ) { | |
| 9192 | + return; | |
| 9193 | + } | |
| 9194 | + | |
| 9195 | + const input = document.getElementById( labelFor ); | |
| 9196 | + if ( ! input || ! input.nextElementSibling ) { | |
| 9197 | + return; | |
| 9198 | + } | |
| 9199 | + | |
| 9200 | + const buttonToggle = input.nextElementSibling.querySelector( 'button.dropdown-toggle.multiselect' ); | |
| 9201 | + if ( ! buttonToggle ) { | |
| 9202 | + return; | |
| 9203 | + } | |
| 9204 | + | |
| 9205 | + const triggerMultiselectClick = () => buttonToggle.click(); | |
| 9206 | + setTimeout( triggerMultiselectClick, 0 ); | |
| 9207 | + }; | |
| 9208 | + document.addEventListener( 'click', clickListener ); | |
| 9209 | + } | |
| 9210 | + | |
| 9211 | + function maybeChangeEmbedFormMsg() { | |
| 9212 | + var fieldId = jQuery( this ).closest( '.frm-single-settings' ).data( 'fid' ); | |
| 9213 | + var fieldItem = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 9214 | + if ( null === fieldItem || 'form' !== fieldItem.dataset.type ) { | |
| 9215 | + return; | |
| 9216 | + } | |
| 9217 | + | |
| 9218 | + fieldItem = jQuery( fieldItem ); | |
| 9219 | + | |
| 9220 | + if ( this.options[ this.selectedIndex ].value ) { | |
| 9221 | + fieldItem.find( '.frm-not-set' )[0].classList.add( 'frm_hidden' ); | |
| 9222 | + var embedMsg = fieldItem.find( '.frm-embed-message' ); | |
| 9223 | + embedMsg.html( embedMsg.data( 'embedmsg' ) + this.options[ this.selectedIndex ].text ); | |
| 9224 | + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.remove( 'frm_hidden' ); | |
| 9225 | + } else { | |
| 9226 | + fieldItem.find( '.frm-not-set' )[0].classList.remove( 'frm_hidden' ); | |
| 9227 | + fieldItem.find( '.frm-embed-field-placeholder' )[0].classList.add( 'frm_hidden' ); | |
| 9228 | + } | |
| 9229 | + } | |
| 9230 | + | |
| 9231 | + function toggleProductType() { | |
| 9232 | + var settings = jQuery( this ).closest( '.frm-single-settings' ), | |
| 9233 | + container = settings.find( '.frmjs_product_choices' ), | |
| 9234 | + heading = settings.find( '.frm_prod_options_heading' ), | |
| 9235 | + currentVal = this.options[ this.selectedIndex ].value; | |
| 9236 | + | |
| 9237 | + container.removeClass( 'frm_prod_type_single frm_prod_type_user_def' ); | |
| 9238 | + heading.removeClass( 'frm_prod_user_def' ); | |
| 9239 | + | |
| 9240 | + if ( 'single' === currentVal ) { | |
| 9241 | + container.addClass( 'frm_prod_type_single' ); | |
| 9242 | + } else if ( 'user_def' === currentVal ) { | |
| 9243 | + container.addClass( 'frm_prod_type_user_def' ); | |
| 9244 | + heading.addClass( 'frm_prod_user_def' ); | |
| 9245 | + } | |
| 9246 | + } | |
| 9247 | + | |
| 9248 | + function isProductField( fieldId ) { | |
| 9249 | + var field = document.getElementById( 'frm_field_id_' + fieldId ); | |
| 9250 | + if ( field === null ) { | |
| 9251 | + return false; | |
| 9252 | + } else { | |
| 9253 | + return 'product' === field.getAttribute( 'data-type' ); | |
| 9254 | + } | |
| 9255 | + } | |
| 9256 | + | |
| 9257 | + /** | |
| 9258 | + * Serialize form data with vanilla JS. | |
| 9259 | + */ | |
| 9260 | + function formToData( form ) { | |
| 9261 | + var subKey, i, | |
| 9262 | + object = {}, | |
| 9263 | + formData = form.elements; | |
| 9264 | + | |
| 9265 | + for ( i = 0; i < formData.length; i++ ) { | |
| 9266 | + var input = formData[i], | |
| 9267 | + key = input.name, | |
| 9268 | + value = input.value, | |
| 9269 | + names = key.match( /(.*)\[(.*)\]/ ); | |
| 9270 | + | |
| 9271 | + if ( ( input.type === 'radio' || input.type === 'checkbox' ) && ! input.checked ) { | |
| 9272 | + continue; | |
| 9273 | + } | |
| 9274 | + | |
| 9275 | + if ( names !== null ) { | |
| 9276 | + key = names[1]; | |
| 9277 | + subKey = names[2]; | |
| 9278 | + if ( ! Reflect.has( object, key ) ) { | |
| 9279 | + object[key] = {}; | |
| 9280 | + } | |
| 9281 | + object[key][subKey] = value; | |
| 9282 | + continue; | |
| 9283 | + } | |
| 9284 | + | |
| 9285 | + // Reflect.has in favor of: object.hasOwnProperty(key) | |
| 9286 | + if ( ! Reflect.has( object, key ) ) { | |
| 9287 | + object[key] = value; | |
| 9288 | + continue; | |
| 9289 | + } | |
| 9290 | + if ( ! Array.isArray( object[key]) ) { | |
| 9291 | + object[key] = [ object[key] ]; | |
| 9292 | + } | |
| 9293 | + object[key].push( value ); | |
| 9294 | + } | |
| 9295 | + | |
| 9296 | + return object; | |
| 9297 | + } | |
| 9298 | + | |
| 9299 | + /** | |
| 9300 | + * Show, hide, and sort subfields of Name field on form builder. | |
| 9301 | + * | |
| 9302 | + * @since 4.11 | |
| 9303 | + */ | |
| 9304 | + function handleNameFieldOnFormBuilder() { | |
| 9305 | + /** | |
| 9306 | + * Gets subfield element from cache. | |
| 9307 | + * | |
| 9308 | + * @param {String} fieldId Field ID. | |
| 9309 | + * @param {String} key Cache key. | |
| 9310 | + * @returns {HTMLElement|undefined} Return the element from cache or undefined if not found. | |
| 9311 | + */ | |
| 9312 | + const getSubFieldElFromCache = ( fieldId, key ) => { | |
| 9313 | + window.frmCachedSubFields = window.frmCachedSubFields || {}; | |
| 9314 | + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {}; | |
| 9315 | + return window.frmCachedSubFields[fieldId][key]; | |
| 9316 | + }; | |
| 9317 | + | |
| 9318 | + /** | |
| 9319 | + * Sets subfield element to cache. | |
| 9320 | + * | |
| 9321 | + * @param {String} fieldId Field ID. | |
| 9322 | + * @param {String} key Cache key. | |
| 9323 | + * @param {HTMLElement} el Element. | |
| 9324 | + */ | |
| 9325 | + const setSubFieldElToCache = ( fieldId, key, el ) => { | |
| 9326 | + window.frmCachedSubFields = window.frmCachedSubFields || {}; | |
| 9327 | + window.frmCachedSubFields[fieldId] = window.frmCachedSubFields[fieldId] || {}; | |
| 9328 | + window.frmCachedSubFields[fieldId][key] = el; | |
| 9329 | + }; | |
| 9330 | + | |
| 9331 | + /** | |
| 9332 | + * Gets column class from the number of columns. | |
| 9333 | + * | |
| 9334 | + * @param {Number} colCount Number of columns. | |
| 9335 | + * @returns {string} | |
| 9336 | + */ | |
| 9337 | + const getColClass = colCount => 'frm' + parseInt( 12 / colCount ); | |
| 9338 | + | |
| 9339 | + const colClasses = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ].map( num => 'frm' + num ); | |
| 9340 | + | |
| 9341 | + const allSubFieldNames = [ 'first', 'middle', 'last' ]; | |
| 9342 | + | |
| 9343 | + /** | |
| 9344 | + * Handles name layout change. | |
| 9345 | + * | |
| 9346 | + * @param {Event} event Event object. | |
| 9347 | + */ | |
| 9348 | + const onChangeLayout = event => { | |
| 9349 | + const value = event.target.value; | |
| 9350 | + const subFieldNames = value.split( '_' ); | |
| 9351 | + const fieldId = event.target.dataset.fieldId; | |
| 9352 | + | |
| 9353 | + /* | |
| 9354 | + * Live update form on the form builder. | |
| 9355 | + */ | |
| 9356 | + const container = document.querySelector( '#field_' + fieldId + '_inner_container .frm_combo_inputs_container' ); | |
| 9357 | + const newColClass = getColClass( subFieldNames.length ); | |
| 9358 | + | |
| 9359 | + // Set all sub field elements to cache and hide all of them first. | |
| 9360 | + allSubFieldNames.forEach( name => { | |
| 9361 | + const subFieldEl = container.querySelector( '[data-sub-field-name="' + name + '"]' ); | |
| 9362 | + if ( subFieldEl ) { | |
| 9363 | + subFieldEl.classList.add( 'frm_hidden' ); | |
| 9364 | + subFieldEl.classList.remove( ...colClasses ); | |
| 9365 | + setSubFieldElToCache( fieldId, name, subFieldEl ); | |
| 9366 | + } | |
| 9367 | + }); | |
| 9368 | + | |
| 9369 | + subFieldNames.forEach( subFieldName => { | |
| 9370 | + const subFieldEl = getSubFieldElFromCache( fieldId, subFieldName ); | |
| 9371 | + if ( ! subFieldEl ) { | |
| 9372 | + return; | |
| 9373 | + } | |
| 9374 | + | |
| 9375 | + subFieldEl.classList.remove( 'frm_hidden' ); | |
| 9376 | + subFieldEl.classList.add( newColClass ); | |
| 9377 | + | |
| 9378 | + container.append( subFieldEl ); | |
| 9379 | + }); | |
| 9380 | + | |
| 9381 | + /* | |
| 9382 | + * Live update subfield options. | |
| 9383 | + */ | |
| 9384 | + // Hide all subfield options. | |
| 9385 | + allSubFieldNames.forEach( name => { | |
| 9386 | + const optionsEl = document.querySelector( '.frm_sub_field_options-' + name + '[data-field-id="' + fieldId + '"]' ); | |
| 9387 | + if ( optionsEl ) { | |
| 9388 | + optionsEl.classList.add( 'frm_hidden' ); | |
| 9389 | + setSubFieldElToCache( fieldId, name + '_options', optionsEl ); | |
| 9390 | + } | |
| 9391 | + }); | |
| 9392 | + | |
| 9393 | + subFieldNames.forEach( subFieldName => { | |
| 9394 | + const optionsEl = getSubFieldElFromCache( fieldId, subFieldName + '_options' ); | |
| 9395 | + if ( ! optionsEl ) { | |
| 9396 | + return; | |
| 9397 | + } | |
| 9398 | + optionsEl.classList.remove( 'frm_hidden' ); | |
| 9399 | + }); | |
| 9400 | + }; | |
| 9401 | + | |
| 9402 | + const dropdownSelector = '.frm_name_layout_dropdown'; | |
| 9403 | + document.addEventListener( 'change', event => { | |
| 9404 | + if ( event.target.matches( dropdownSelector ) ) { | |
| 9405 | + onChangeLayout( event ); | |
| 9406 | + } | |
| 9407 | + }, false ); | |
| 9408 | + } | |
| 9409 | + | |
| 9410 | + function debounce( func, wait = 100 ) { | |
| 9411 | + return frmDom.util.debounce( func, wait ); | |
| 9412 | + } | |
| 9413 | + | |
| 9414 | + function addSaveAndDragIconsToOption( fieldId, liObject ) { | |
| 9415 | + let li, useTag, useTagHref; | |
| 9416 | + let hasDragIcon = false; | |
| 9417 | + let hasSaveIcon = false; | |
| 9418 | + | |
| 9419 | + if ( liObject.newOption ) { | |
| 9420 | + const parser = new DOMParser(); | |
| 9421 | + li = parser.parseFromString( liObject.newOption, 'text/html' ).body.childNodes[0]; | |
| 9422 | + } else { | |
| 9423 | + li = liObject; | |
| 9424 | + } | |
| 9425 | + | |
| 9426 | + const liIcons = li.querySelectorAll( 'svg' ); | |
| 9427 | + | |
| 9428 | + liIcons.forEach( ( svg, key ) => { | |
| 9429 | + useTag = svg.getElementsByTagNameNS( 'http://www.w3.org/2000/svg', 'use' )[0]; | |
| 9430 | + if ( ! useTag ) { | |
| 9431 | + return; | |
| 9432 | + } | |
| 9433 | + useTagHref = useTag.getAttributeNS( 'http://www.w3.org/1999/xlink', 'href' ) || useTag.getAttribute( 'href' ); | |
| 9434 | + | |
| 9435 | + if ( useTagHref === '#frm_drag_icon' ) { | |
| 9436 | + hasDragIcon = true; | |
| 9437 | + } | |
| 9438 | + | |
| 9439 | + if ( useTagHref === '#frm_save_icon' ) { | |
| 9440 | + hasSaveIcon = true; | |
| 9441 | + } | |
| 9442 | + }); | |
| 9443 | + | |
| 9444 | + if ( ! hasDragIcon ) { | |
| 9445 | + li.prepend( icons.drag.cloneNode( true ) ); | |
| 9446 | + } | |
| 9447 | + | |
| 9448 | + if ( li.querySelector( `[id^=field_key_${fieldId}-]` ) && ! hasSaveIcon ) { | |
| 9449 | + li.querySelector( `[id^=field_key_${fieldId}-]` ).after( icons.save.cloneNode( true ) ); | |
| 9450 | + } | |
| 9451 | + | |
| 9452 | + if ( liObject.newOption ) { | |
| 9453 | + liObject.newOption = li; | |
| 9454 | + } | |
| 9455 | + } | |
| 9456 | + | |
| 9457 | + function maybeAddSaveAndDragIcons( fieldId ) { | |
| 9458 | + fieldOptions = document.querySelectorAll( `[id^=frm_delete_field_${fieldId}-]` ); | |
| 9459 | + // return if there are no options. | |
| 9460 | + if ( fieldOptions.length < 2 ) { | |
| 9461 | + return; | |
| 9462 | + } | |
| 9463 | + | |
| 9464 | + let options = [ ...fieldOptions ].slice( 1 ); | |
| 9465 | + options.forEach( ( li, _key ) => { | |
| 9466 | + if ( li.classList.contains( 'frm_other_option' ) ) { | |
| 9467 | + return; | |
| 9468 | + } | |
| 9469 | + addSaveAndDragIconsToOption( fieldId, li ); | |
| 9470 | + }); | |
| 9471 | + } | |
| 9472 | + | |
| 9473 | + function initOnSubmitAction() { | |
| 9474 | + const onChangeType = event => { | |
| 9475 | + if ( ! event.target.checked ) { | |
| 9476 | + return; | |
| 9477 | + } | |
| 9478 | + | |
| 9479 | + const actionEl = event.target.closest( '.frm_form_action_settings' ); | |
| 9480 | + actionEl.querySelectorAll( '.frm_on_submit_dependent_setting:not(.frm_hidden)' ).forEach( el => { | |
| 9481 | + el.classList.add( 'frm_hidden' ); | |
| 9482 | + }); | |
| 9483 | + | |
| 9484 | + const activeEls = actionEl.querySelectorAll( '.frm_on_submit_dependent_setting[data-show-if-' + event.target.value + ']' ); | |
| 9485 | + activeEls.forEach( activeEl => { | |
| 9486 | + activeEl.classList.remove( 'frm_hidden' ); | |
| 9487 | + }); | |
| 9488 | + | |
| 9489 | + actionEl.setAttribute( 'data-on-submit-type', event.target.value ); | |
| 9490 | + }; | |
| 9491 | + | |
| 9492 | + frmDom.util.documentOn( 'change', '.frm_on_submit_type input[type="radio"]', onChangeType ); | |
| 9493 | + } | |
| 9494 | + | |
| 9495 | + return { | |
| 9496 | + init: function() { | |
| 9497 | + s = {}; | |
| 9498 | + | |
| 9499 | + // Bootstrap dropdown button | |
| 9500 | + jQuery( '.wp-admin' ).on( 'click', function( e ) { | |
| 9501 | + var t = jQuery( e.target ); | |
| 9502 | + var $openDrop = jQuery( '.dropdown.open' ); | |
| 9503 | + if ( $openDrop.length && ! t.hasClass( 'dropdown' ) && ! t.closest( '.dropdown' ).length ) { | |
| 9504 | + $openDrop.removeClass( 'open' ); | |
| 9505 | + } | |
| 9506 | + }); | |
| 9507 | + jQuery( '#frm_bs_dropdown:not(.open) a' ).on( 'click', focusSearchBox ); | |
| 9508 | + | |
| 9509 | + if ( typeof thisFormId === 'undefined' ) { | |
| 9510 | + thisFormId = jQuery( document.getElementById( 'form_id' ) ).val(); | |
| 9511 | + } | |
| 9512 | + | |
| 9513 | + frmAdminBuild.inboxBannerInit(); | |
| 9514 | + | |
| 9515 | + if ( $newFields.length > 0 ) { | |
| 9516 | + // only load this on the form builder page | |
| 9517 | + frmAdminBuild.buildInit(); | |
| 9518 | + } else if ( document.getElementById( 'frm_notification_settings' ) !== null ) { | |
| 9519 | + // only load on form settings page | |
| 9520 | + frmAdminBuild.settingsInit(); | |
| 9521 | + } else if ( document.getElementById( 'frm_styling_form' ) !== null ) { | |
| 9522 | + // load styling settings js | |
| 9523 | + frmAdminBuild.styleInit(); | |
| 9524 | + } else if ( document.getElementById( 'form_global_settings' ) !== null ) { | |
| 9525 | + // global settings page | |
| 9526 | + frmAdminBuild.globalSettingsInit(); | |
| 9527 | + } else if ( document.getElementById( 'frm_export_xml' ) !== null ) { | |
| 9528 | + // import/export page | |
| 9529 | + frmAdminBuild.exportInit(); | |
| 9530 | + } else if ( document.getElementById( 'frm_dyncontent' ) !== null ) { | |
| 9531 | + // only load on views settings page | |
| 9532 | + frmAdminBuild.viewInit(); | |
| 9533 | + } else if ( document.getElementById( 'frm_inbox_page' ) !== null ) { | |
| 9534 | + // Inbox page | |
| 9535 | + frmAdminBuild.inboxInit(); | |
| 9536 | + } else if ( document.getElementById( 'frm-welcome' ) !== null ) { | |
| 9537 | + // Solution install page | |
| 9538 | + frmAdminBuild.solutionInit(); | |
| 9539 | + } else { | |
| 9540 | + // New form selection page | |
| 9541 | + initNewFormModal(); | |
| 9542 | + initSelectionAutocomplete(); | |
| 9543 | + | |
| 9544 | + jQuery( '[data-frmprint]' ).on( 'click', function() { | |
| 9545 | + window.print(); | |
| 9546 | + return false; | |
| 9547 | + }); | |
| 9548 | + } | |
| 9549 | + | |
| 9550 | + var $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) ); | |
| 9551 | + if ( $advInfo.length > 0 || jQuery( '.frm_field_list' ).length > 0 ) { | |
| 9552 | + // only load on the form, form settings, and view settings pages | |
| 9553 | + frmAdminBuild.panelInit(); | |
| 9554 | + } | |
| 9555 | + | |
| 9556 | + loadTooltips(); | |
| 9557 | + initUpgradeModal(); | |
| 9558 | + moveTopBanner(); | |
| 9559 | + | |
| 9560 | + // used on build, form settings, and view settings | |
| 9561 | + var $shortCodeDiv = jQuery( document.getElementById( 'frm_shortcodediv' ) ); | |
| 9562 | + if ( $shortCodeDiv.length > 0 ) { | |
| 9563 | + jQuery( 'a.edit-frm_shortcode' ).on( 'click', function() { | |
| 9564 | + if ( $shortCodeDiv.is( ':hidden' ) ) { | |
| 9565 | + $shortCodeDiv.slideDown( 'fast' ); | |
| 9566 | + this.style.display = 'none'; | |
| 9567 | + } | |
| 9568 | + return false; | |
| 9569 | + }); | |
| 9570 | + | |
| 9571 | + jQuery( '.cancel-frm_shortcode', '#frm_shortcodediv' ).on( 'click', function() { | |
| 9572 | + $shortCodeDiv.slideUp( 'fast' ); | |
| 9573 | + $shortCodeDiv.siblings( 'a.edit-frm_shortcode' ).show(); | |
| 9574 | + return false; | |
| 9575 | + }); | |
| 9576 | + } | |
| 9577 | + | |
| 9578 | + // tabs | |
| 9579 | + jQuery( document ).on( 'click', '#frm-nav-tabs a', clickNewTab ); | |
| 9580 | + jQuery( '.post-type-frm_display .frm-nav-tabs a, .frm-category-tabs a' ).on( 'click', function() { | |
| 9581 | + const showUpgradeTab = this.classList.contains( 'frm_show_upgrade_tab' ); | |
| 9582 | + if ( this.classList.contains( 'frm_noallow' ) && ! showUpgradeTab ) { | |
| 9583 | + return; | |
| 9584 | + } | |
| 9585 | + | |
| 9586 | + if ( showUpgradeTab ) { | |
| 9587 | + populateUpgradeTab( this ); | |
| 9588 | + } | |
| 9589 | + | |
| 9590 | + clickTab( this ); | |
| 9591 | + return false; | |
| 9592 | + }); | |
| 9593 | + clickTab( jQuery( '.starttab a' ), 'auto' ); | |
| 9594 | + | |
| 9595 | + // submit the search form with dropdown | |
| 9596 | + jQuery( document ).on( 'click', '#frm-fid-search-menu a', function() { | |
| 9597 | + var val = this.id.replace( 'fid-', '' ); | |
| 9598 | + jQuery( 'select[name="fid"]' ).val( val ); | |
| 9599 | + triggerSubmit( document.getElementById( 'posts-filter' ) ); | |
| 9600 | + return false; | |
| 9601 | + }); | |
| 9602 | + | |
| 9603 | + jQuery( '.frm_select_box' ).on( 'click focus', function() { | |
| 9604 | + this.select(); | |
| 9605 | + }); | |
| 9606 | + | |
| 9607 | + jQuery( document ).on( 'input search change', '.frm-auto-search', searchContent ); | |
| 9608 | + jQuery( document ).on( 'focusin click', '.frm-auto-search', stopPropagation ); | |
| 9609 | + var autoSearch = jQuery( '.frm-auto-search' ); | |
| 9610 | + if ( autoSearch.val() !== '' ) { | |
| 9611 | + autoSearch.trigger( 'keyup' ); | |
| 9612 | + } | |
| 9613 | + | |
| 9614 | + // Initialize Formidable Connection. | |
| 9615 | + FrmFormsConnect.init(); | |
| 9616 | + | |
| 9617 | + jQuery( document ).on( 'click', '.frm-install-addon', installAddon ); | |
| 9618 | + jQuery( document ).on( 'click', '.frm-activate-addon', activateAddon ); | |
| 9619 | + jQuery( document ).on( 'click', '.frm-solution-multiple', installMultipleAddons ); | |
| 9620 | + | |
| 9621 | + // prevent annoying confirmation message from WordPress | |
| 9622 | + jQuery( 'button, input[type=submit]' ).on( 'click', removeWPUnload ); | |
| 9623 | + | |
| 9624 | + addMultiselectLabelListener(); | |
| 9625 | + | |
| 9626 | + frmAdminBuild.hooks.addFilter( | |
| 9627 | + 'frm_before_embed_modal', | |
| 9628 | + ( ids, { element, type }) => { | |
| 9629 | + if ( 'form' !== type ) { | |
| 9630 | + return ids; | |
| 9631 | + } | |
| 9632 | + | |
| 9633 | + let formId, formKey; | |
| 9634 | + const row = element.closest( 'tr' ); | |
| 9635 | + | |
| 9636 | + if ( row ) { | |
| 9637 | + // Embed icon on form index. | |
| 9638 | + formId = parseInt( row.querySelector( '.column-id' ).textContent ); | |
| 9639 | + formKey = row.querySelector( '.column-form_key' ).textContent; | |
| 9640 | + } else { | |
| 9641 | + // Embed button in form builder / form settings. | |
| 9642 | + formId = document.getElementById( 'form_id' ).value; | |
| 9643 | + | |
| 9644 | + const formKeyInput = document.getElementById( 'frm_form_key' ); | |
| 9645 | + if ( formKeyInput ) { | |
| 9646 | + formKey = formKeyInput.value; | |
| 9647 | + } else { | |
| 9648 | + const previewDrop = document.getElementById( 'frm-previewDrop' ); | |
| 9649 | + if ( previewDrop ) { | |
| 9650 | + formKey = previewDrop.nextElementSibling.querySelector( '.dropdown-item a' ).getAttribute( 'href' ).split( 'form=' )[1]; | |
| 9651 | + } | |
| 9652 | + } | |
| 9653 | + } | |
| 9654 | + | |
| 9655 | + return [ formId, formKey ]; | |
| 9656 | + } | |
| 9657 | + ); | |
| 9658 | + | |
| 9659 | + document.querySelectorAll( '#frm-show-fields > li, .frm_grid_container li' ).forEach( ( el, _key ) => { | |
| 9660 | + el.addEventListener( 'click', function() { | |
| 9661 | + let fieldId = this.querySelector( 'li' )?.dataset.fid || this.dataset.fid; | |
| 9662 | + maybeAddSaveAndDragIcons( fieldId ); | |
| 9663 | + }); | |
| 9664 | + }); | |
| 9665 | + }, | |
| 9666 | + | |
| 9667 | + buildInit: function() { | |
| 9668 | + let loadFieldId, $builderForm, builderArea; | |
| 9669 | + | |
| 9670 | + debouncedSyncAfterDragAndDrop = debounce( syncAfterDragAndDrop, 10 ); | |
| 9671 | + postBodyContent = document.getElementById( 'post-body-content' ); | |
| 9672 | + $postBodyContent = jQuery( postBodyContent ); | |
| 9673 | + | |
| 9674 | + if ( jQuery( '.frm_field_loading' ).length ) { | |
| 9675 | + loadFieldId = jQuery( '.frm_field_loading' ).first().attr( 'id' ); | |
| 9676 | + loadFields( loadFieldId ); | |
| 9677 | + } | |
| 9678 | + | |
| 9679 | + setupSortable( 'ul.frm_sorting' ); | |
| 9680 | + | |
| 9681 | + document.querySelectorAll( '.field_type_list > li' ).forEach( makeDraggable ); | |
| 9682 | + | |
| 9683 | + 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(); | |
| 9684 | + | |
| 9685 | + jQuery( '.frm_submit_ajax' ).on( 'click', submitBuild ); | |
| 9686 | + jQuery( '.frm_submit_no_ajax' ).on( 'click', submitNoAjax ); | |
| 9687 | + | |
| 9688 | + jQuery( 'a.edit-form-status' ).on( 'click', slideDown ); | |
| 9689 | + jQuery( '.cancel-form-status' ).on( 'click', slideUp ); | |
| 9690 | + jQuery( '.save-form-status' ).on( 'click', function() { | |
| 9691 | + const newStatus = jQuery( document.getElementById( 'form_change_status' ) ).val(); | |
| 9692 | + jQuery( 'input[name="new_status"]' ).val( newStatus ); | |
| 9693 | + jQuery( document.getElementById( 'form-status-display' ) ).html( newStatus ); | |
| 9694 | + jQuery( '.cancel-form-status' ).trigger( 'click' ); | |
| 9695 | + return false; | |
| 9696 | + }); | |
| 9697 | + | |
| 9698 | + jQuery( '.frm_form_builder form' ).first().on( 'submit', function() { | |
| 9699 | + jQuery( '.inplace_field' ).trigger( 'blur' ); | |
| 9700 | + }); | |
| 9701 | + | |
| 9702 | + initiateMultiselect(); | |
| 9703 | + renumberPageBreaks(); | |
| 9704 | + | |
| 9705 | + $builderForm = jQuery( builderForm ); | |
| 9706 | + builderArea = document.getElementById( 'frm_form_editor_container' ); | |
| 9707 | + $builderForm.on( 'click', '.frm_add_logic_row', addFieldLogicRow ); | |
| 9708 | + $builderForm.on( 'click', '.frm_add_watch_lookup_row', addWatchLookupRow ); | |
| 9709 | + $builderForm.on( 'change', '.frm_get_values_form', updateGetValueFieldSelection ); | |
| 9710 | + $builderForm.on( 'change', '.frm_logic_field_opts', getFieldValues ); | |
| 9711 | + $builderForm.on( 'change', '.radio_maxnum', setStarValues ); | |
| 9712 | + $builderForm.on( 'frm-multiselect-changed', 'select[name^="field_options[admin_only_"]', adjustVisibilityValuesForEveryoneValues ); | |
| 9713 | + | |
| 9714 | + jQuery( document.getElementById( 'frm-insert-fields' ) ).on( 'click', '.frm_add_field', addFieldClick ); | |
| 9715 | + $newFields.on( 'click', '.frm_clone_field', duplicateField ); | |
| 9716 | + $builderForm.on( 'blur', 'input[id^="frm_calc"]', checkCalculationCreatedByUser ); | |
| 9717 | + $builderForm.on( 'change', 'input.frm_format_opt, input.frm_max_length_opt', toggleInvalidMsg ); | |
| 9718 | + $builderForm.on( 'change click', '[data-changeme]', liveChanges ); | |
| 9719 | + $builderForm.on( 'click', 'input.frm_req_field', markRequired ); | |
| 9720 | + $builderForm.on( 'click', '.frm_mark_unique', markUnique ); | |
| 9721 | + | |
| 9722 | + $builderForm.on( 'change', '.frm_repeat_format', toggleRepeatButtons ); | |
| 9723 | + $builderForm.on( 'change', '.frm_repeat_limit', checkRepeatLimit ); | |
| 9724 | + $builderForm.on( 'change', '.frm_js_checkbox_limit', checkCheckboxSelectionsLimit ); | |
| 9725 | + $builderForm.on( 'input', 'input[name^="field_options[add_label_"]', function() { | |
| 9726 | + updateRepeatText( this, 'add' ); | |
| 9727 | + }); | |
| 9728 | + $builderForm.on( 'input', 'input[name^="field_options[remove_label_"]', function() { | |
| 9729 | + updateRepeatText( this, 'remove' ); | |
| 9730 | + }); | |
| 9731 | + $builderForm.on( 'change', 'select[name^="field_options[data_type_"]', maybeClearWatchFields ); | |
| 9732 | + jQuery( builderArea ).on( 'click', '.frm-collapse-page', maybeCollapsePage ); | |
| 9733 | + jQuery( builderArea ).on( 'click', '.frm-collapse-section', maybeCollapseSection ); | |
| 9734 | + $builderForm.on( 'click', '.frm-single-settings h3', maybeCollapseSettings ); | |
| 9735 | + | |
| 9736 | + $builderForm.on( 'click', '.frm_toggle_sep_values', toggleSepValues ); | |
| 9737 | + $builderForm.on( 'click', '.frm_toggle_image_options', toggleImageOptions ); | |
| 9738 | + $builderForm.on( 'click', '.frm_remove_image_option', removeImageFromOption ); | |
| 9739 | + $builderForm.on( 'click', '.frm_choose_image_box', addImageToOption ); | |
| 9740 | + $builderForm.on( 'change', '.frm_hide_image_text', refreshOptionDisplay ); | |
| 9741 | + $builderForm.on( 'change', '.frm_field_options_image_size', setImageSize ); | |
| 9742 | + $builderForm.on( 'click', '.frm_multiselect_opt', toggleMultiselect ); | |
| 9743 | + $newFields.on( 'mousedown', 'input, textarea, select', stopFieldFocus ); | |
| 9744 | + $newFields.on( 'click', 'input[type=radio], input[type=checkbox]', stopFieldFocus ); | |
| 9745 | + $newFields.on( 'click', '.frm_delete_field', clickDeleteField ); | |
| 9746 | + $newFields.on( 'click', '.frm_select_field', clickSelectField ); | |
| 9747 | + jQuery( document ).on( 'click', '.frm_delete_field_group', clickDeleteFieldGroup ); | |
| 9748 | + jQuery( document ).on( 'click', '.frm_clone_field_group', duplicateFieldGroup ); | |
| 9749 | + jQuery( document ).on( 'click', '#frm_field_group_controls > span:first-child', clickFieldGroupLayout ); | |
| 9750 | + jQuery( document ).on( 'click', '.frm-row-layout-option', handleFieldGroupLayoutOptionClick ); | |
| 9751 | + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-row-layout-option', handleFieldGroupLayoutOptionInsideMergeClick ); | |
| 9752 | + jQuery( document ).on( 'click', '.frm-custom-field-group-layout', customFieldGroupLayoutClick ); | |
| 9753 | + jQuery( document ).on( 'click', '.frm-merge-fields-into-row .frm-custom-field-group-layout', customFieldGroupLayoutInsideMergeClick ); | |
| 9754 | + jQuery( document ).on( 'click', '.frm-break-field-group', breakFieldGroupClick ); | |
| 9755 | + $newFields.on( 'click', '#frm_field_group_popup .frm_grid_container input', focusFieldGroupInputOnClick ); | |
| 9756 | + jQuery( document ).on( 'click', '.frm-cancel-custom-field-group-layout', cancelCustomFieldGroupClick ); | |
| 9757 | + jQuery( document ).on( 'click', '.frm-save-custom-field-group-layout', saveCustomFieldGroupClick ); | |
| 9758 | + $newFields.on( 'click', 'ul.frm_sorting', fieldGroupClick ); | |
| 9759 | + jQuery( document ).on( 'click', '.frm-merge-fields-into-row', mergeFieldsIntoRowClick ); | |
| 9760 | + jQuery( document ).on( 'click', '.frm-delete-field-groups', deleteFieldGroupsClick ); | |
| 9761 | + $newFields.on( 'click', '.frm-field-action-icons [data-toggle="dropdown"]', function() { | |
| 9762 | + this.closest( 'li.form-field' ).classList.add( 'frm-field-settings-open' ); | |
| 9763 | + jQuery( document ).on( 'click', '#frm_builder_page', handleClickOutsideOfFieldSettings ); | |
| 9764 | + }); | |
| 9765 | + $newFields.on( 'mousemove', 'ul.frm_sorting', checkForMultiselectKeysOnMouseMove ); | |
| 9766 | + $newFields.on( 'show.bs.dropdown', '.frm-field-action-icons', onFieldActionDropdownShow ); | |
| 9767 | + jQuery( document ).on( 'show.bs.dropdown', '#frm_field_group_controls', onFieldGroupActionDropdownShow ); | |
| 9768 | + $builderForm.on( 'click', '.frm_single_option a[data-removeid]', deleteFieldOption ); | |
| 9769 | + $builderForm.on( 'mousedown', '.frm_single_option input[type=radio]', maybeUncheckRadio ); | |
| 9770 | + $builderForm.on( 'focusin', '.frm_single_option input[type=text]', maybeClearOptText ); | |
| 9771 | + $builderForm.on( 'click', '.frm_add_opt', addFieldOption ); | |
| 9772 | + $builderForm.on( 'change', '.frm_single_option input', resetOptOnChange ); | |
| 9773 | + $builderForm.on( 'change', '.frm_image_id', resetOptOnChange ); | |
| 9774 | + $builderForm.on( 'change', '.frm_toggle_mult_sel', toggleMultSel ); | |
| 9775 | + $builderForm.on( 'focusin', '.frm_classes', showBuilderModal ); | |
| 9776 | + | |
| 9777 | + $newFields.on( 'click', '.frm_primary_label', clickLabel ); | |
| 9778 | + $newFields.on( 'click', '.frm_description', clickDescription ); | |
| 9779 | + $newFields.on( 'click', 'li.ui-state-default', clickVis ); | |
| 9780 | + $newFields.on( 'dblclick', 'li.ui-state-default', openAdvanced ); | |
| 9781 | + $builderForm.on( 'change', '.frm_tax_form_select', toggleFormTax ); | |
| 9782 | + $builderForm.on( 'change', 'select.conf_field', addConf ); | |
| 9783 | + | |
| 9784 | + $builderForm.on( 'change', '.frm_get_field_selection', getFieldSelection ); | |
| 9785 | + | |
| 9786 | + $builderForm.on( 'click', '.frm-show-inline-modal', maybeShowInlineModal ); | |
| 9787 | + | |
| 9788 | + $builderForm.on( 'click', '.frm-inline-modal .dismiss', dismissInlineModal ); | |
| 9789 | + jQuery( document ).on( 'change', '[data-frmchange]', changeInputtedValue ); | |
| 9790 | + | |
| 9791 | + $builderForm.on( 'change', '.frm_include_extras_field', rePopCalcFieldsForSummary ); | |
| 9792 | + $builderForm.on( 'change', 'select[name^="field_options[form_select_"]', maybeChangeEmbedFormMsg ); | |
| 9793 | + | |
| 9794 | + jQuery( document ).on( 'submit', '#frm_js_build_form', buildSubmittedNoAjax ); | |
| 9795 | + 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 ); | |
| 9796 | + | |
| 9797 | + popAllProductFields(); | |
| 9798 | + | |
| 9799 | + jQuery( document ).on( 'change', '.frmjs_prod_data_type_opt', toggleProductType ); | |
| 9800 | + | |
| 9801 | + jQuery( document ).on( 'focus', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextFocus ); | |
| 9802 | + jQuery( document ).on( 'blur', '.frm-single-settings ul input[type="text"][name^="field_options[options_"]', onOptionTextBlur ); | |
| 9803 | + | |
| 9804 | + initBulkOptionsOverlay(); | |
| 9805 | + hideEmptyEle(); | |
| 9806 | + maybeHideQuantityProductFieldOption(); | |
| 9807 | + handleNameFieldOnFormBuilder(); | |
| 9808 | + toggleSectionHolder(); | |
| 9809 | + }, | |
| 9810 | + | |
| 9811 | + settingsInit: function() { | |
| 9812 | + const $formActions = jQuery( document.getElementById( 'frm_notification_settings' ) ); | |
| 9813 | + | |
| 9814 | + let formSettings, $loggedIn, $cookieExp, $editable; | |
| 9815 | + | |
| 9816 | + // BCC, CC, and Reply To button functionality | |
| 9817 | + $formActions.on( 'click', '.frm_email_buttons', showEmailRow ); | |
| 9818 | + $formActions.on( 'click', '.frm_remove_field', hideEmailRow ); | |
| 9819 | + $formActions.on( 'change', '.frm_to_row, .frm_from_row', showEmailWarning ); | |
| 9820 | + $formActions.on( 'change', '.frm_tax_selector', changePosttaxRow ); | |
| 9821 | + $formActions.on( 'change', 'select.frm_single_post_field', checkDupPost ); | |
| 9822 | + $formActions.on( 'change', 'select.frm_toggle_post_content', togglePostContent ); | |
| 9823 | + $formActions.on( 'change', 'select.frm_dyncontent_opt', fillDyncontent ); | |
| 9824 | + $formActions.on( 'change', '.frm_post_type', switchPostType ); | |
| 9825 | + $formActions.on( 'click', '.frm_add_postmeta_row', addPostmetaRow ); | |
| 9826 | + $formActions.on( 'click', '.frm_add_posttax_row', addPosttaxRow ); | |
| 9827 | + $formActions.on( 'click', '.frm_toggle_cf_opts', toggleCfOpts ); | |
| 9828 | + $formActions.on( 'click', '.frm_duplicate_form_action', copyFormAction ); | |
| 9829 | + jQuery( document ).on( 'change', 'select[data-toggleclass], input[data-toggleclass]', toggleFormOpts ); | |
| 9830 | + jQuery( '.frm_actions_list' ).on( 'click', '.frm_active_action', addFormAction ); | |
| 9831 | + jQuery( '#frm-show-groups, #frm-hide-groups' ).on( 'click', toggleActionGroups ); | |
| 9832 | + initiateMultiselect(); | |
| 9833 | + | |
| 9834 | + //set actions icons to inactive | |
| 9835 | + jQuery( 'ul.frm_actions_list li' ).each( function() { | |
| 9836 | + checkActiveAction( jQuery( this ).children( 'a' ).data( 'actiontype' ) ); | |
| 9837 | + | |
| 9838 | + // If the icon is a background image, don't add BG color. | |
| 9839 | + const icon = jQuery( this ).find( 'i' ); | |
| 9840 | + if ( icon.css( 'background-image' ) !== 'none' ) { | |
| 9841 | + icon.addClass( 'frm-inverse' ); | |
| 9842 | + } | |
| 9843 | + }); | |
| 9844 | + | |
| 9845 | + jQuery( '.frm_submit_settings_btn' ).on( 'click', submitSettings ); | |
| 9846 | + | |
| 9847 | + formSettings = jQuery( '.frm_form_settings' ); | |
| 9848 | + formSettings.on( 'click', '.frm_add_form_logic', addFormLogicRow ); | |
| 9849 | + formSettings.on( 'blur', '.frm_email_blur', formatEmailSetting ); | |
| 9850 | + formSettings.on( 'click', '.frm_already_used', onlyOneActionMessage ); | |
| 9851 | + | |
| 9852 | + formSettings.on( 'change', '#logic_link_submit', toggleSubmitLogic ); | |
| 9853 | + formSettings.on( 'click', '.frm_add_submit_logic', addSubmitLogic ); | |
| 9854 | + formSettings.on( 'change', '.frm_submit_logic_field_opts', addSubmitLogicOpts ); | |
| 9855 | + | |
| 9856 | + document.addEventListener( | |
| 9857 | + 'click', | |
| 9858 | + function handleImageUploadClickEvents( event ) { | |
| 9859 | + const { target } = event; | |
| 9860 | + | |
| 9861 | + if ( ! target.closest( '.frm_image_preview_wrapper' ) ) { | |
| 9862 | + return; | |
| 9863 | + } | |
| 9864 | + | |
| 9865 | + if ( target.closest( '.frm_choose_image_box' ) ) { | |
| 9866 | + addImageToOption.bind( target )( event ); | |
| 9867 | + return; | |
| 9868 | + } | |
| 9869 | + | |
| 9870 | + if ( target.closest( '.frm_remove_image_option' ) ) { | |
| 9871 | + removeImageFromOption.bind( target )( event ); | |
| 9872 | + } | |
| 9873 | + } | |
| 9874 | + ); | |
| 9875 | + | |
| 9876 | + // Close shortcode modal on click. | |
| 9877 | + formSettings.on( 'mouseup', '*:not(.frm-show-box)', function( e ) { | |
| 9878 | + e.stopPropagation(); | |
| 9879 | + | |
| 9880 | + if ( e.target.classList.contains( 'frm-show-box' ) || e.target.parentElement.classList.contains( 'frm-show-box' ) ) { | |
| 9881 | + return; | |
| 9882 | + } | |
| 9883 | + | |
| 9884 | + const sidebar = document.getElementById( 'frm_adv_info' ); | |
| 9885 | + if ( ! sidebar ) { | |
| 9886 | + return; | |
| 9887 | + } | |
| 9888 | + | |
| 9889 | + if ( sidebar.getAttribute( 'data-fills' ) === e.target.id && typeof e.target.id !== 'undefined' ) { | |
| 9890 | + return; | |
| 9891 | + } | |
| 9892 | + | |
| 9893 | + const isChild = jQuery( e.target ).closest( '#frm_adv_info' ).length > 0; | |
| 9894 | + | |
| 9895 | + if ( ! isChild && sidebar.display !== 'none' ) { | |
| 9896 | + hideShortcodes( sidebar ); | |
| 9897 | + } | |
| 9898 | + }); | |
| 9899 | + | |
| 9900 | + //Warning when user selects "Do not store entries ..." | |
| 9901 | + jQuery( document.getElementById( 'no_save' ) ).on( 'change', function() { | |
| 9902 | + if ( this.checked ) { | |
| 9903 | + if ( confirm( frm_admin_js.no_save_warning ) !== true ) { | |
| 9904 | + // Uncheck box if user hits "Cancel" | |
| 9905 | + jQuery( this ).attr( 'checked', false ); | |
| 9906 | + } | |
| 9907 | + } | |
| 9908 | + }); | |
| 9909 | + | |
| 9910 | + jQuery( 'select[name="options[edit_action]"]' ).on( 'change', showSuccessOpt ); | |
| 9911 | + | |
| 9912 | + $loggedIn = document.getElementById( 'logged_in' ); | |
| 9913 | + jQuery( $loggedIn ).on( 'change', function() { | |
| 9914 | + if ( this.checked ) { | |
| 9915 | + visible( '.hide_logged_in' ); | |
| 9916 | + } else { | |
| 9917 | + invisible( '.hide_logged_in' ); | |
| 9918 | + } | |
| 9919 | + }); | |
| 9920 | + | |
| 9921 | + $cookieExp = jQuery( document.getElementById( 'frm_cookie_expiration' ) ); | |
| 9922 | + jQuery( document.getElementById( 'frm_single_entry_type' ) ).on( 'change', function() { | |
| 9923 | + if ( this.value === 'cookie' ) { | |
| 9924 | + $cookieExp.fadeIn( 'slow' ); | |
| 9925 | + } else { | |
| 9926 | + $cookieExp.fadeOut( 'slow' ); | |
| 9927 | + } | |
| 9928 | + }); | |
| 9929 | + | |
| 9930 | + var $singleEntry = document.getElementById( 'single_entry' ); | |
| 9931 | + jQuery( $singleEntry ).on( 'change', function() { | |
| 9932 | + if ( this.checked ) { | |
| 9933 | + visible( '.hide_single_entry' ); | |
| 9934 | + } else { | |
| 9935 | + invisible( '.hide_single_entry' ); | |
| 9936 | + } | |
| 9937 | + | |
| 9938 | + if ( this.checked && jQuery( document.getElementById( 'frm_single_entry_type' ) ).val() === 'cookie' ) { | |
| 9939 | + $cookieExp.fadeIn( 'slow' ); | |
| 9940 | + } else { | |
| 9941 | + $cookieExp.fadeOut( 'slow' ); | |
| 9942 | + } | |
| 9943 | + }); | |
| 9944 | + | |
| 9945 | + jQuery( '.hide_save_draft' ).hide(); | |
| 9946 | + | |
| 9947 | + var $saveDraft = jQuery( document.getElementById( 'save_draft' ) ); | |
| 9948 | + $saveDraft.on( 'change', function() { | |
| 9949 | + if ( this.checked ) { | |
| 9950 | + jQuery( '.hide_save_draft' ).fadeIn( 'slow' ); | |
| 9951 | + } else { | |
| 9952 | + jQuery( '.hide_save_draft' ).fadeOut( 'slow' ); | |
| 9953 | + } | |
| 9954 | + }); | |
| 9955 | + triggerChange( $saveDraft ); | |
| 9956 | + | |
| 9957 | + //If Allow editing is checked/unchecked | |
| 9958 | + $editable = document.getElementById( 'editable' ); | |
| 9959 | + jQuery( $editable ).on( 'change', function() { | |
| 9960 | + if ( this.checked ) { | |
| 9961 | + jQuery( '.hide_editable' ).fadeIn( 'slow' ); | |
| 9962 | + triggerChange( document.getElementById( 'edit_action' ) ); | |
| 9963 | + } else { | |
| 9964 | + jQuery( '.hide_editable' ).fadeOut( 'slow' ); | |
| 9965 | + jQuery( '.edit_action_message_box' ).fadeOut( 'slow' );//Hide On Update message box | |
| 9966 | + } | |
| 9967 | + }); | |
| 9968 | + | |
| 9969 | + //If File Protection is checked/unchecked | |
| 9970 | + jQuery( document ).on( 'change', '#protect_files', function() { | |
| 9971 | + if ( this.checked ) { | |
| 9972 | + jQuery( '.hide_protect_files' ).fadeIn( 'slow' ); | |
| 9973 | + } else { | |
| 9974 | + jQuery( '.hide_protect_files' ).fadeOut( 'slow' ); | |
| 9975 | + } | |
| 9976 | + }); | |
| 9977 | + | |
| 9978 | + jQuery( document ).on( 'frm-multiselect-changed', '#protect_files_role', adjustVisibilityValuesForEveryoneValues ); | |
| 9979 | + | |
| 9980 | + jQuery( document ).on( 'submit', '.frm_form_settings', settingsSubmitted ); | |
| 9981 | + jQuery( document ).on( 'change', '#form_settings_page input:not(.frm-search-input), #form_settings_page select, #form_settings_page textarea', fieldUpdated ); | |
| 9982 | + | |
| 9983 | + // Page Selection Autocomplete | |
| 9984 | + initSelectionAutocomplete(); | |
| 9985 | + | |
| 9986 | + jQuery( document ).on( 'frm-action-loaded', onActionLoaded ); | |
| 9987 | + | |
| 9988 | + initOnSubmitAction(); | |
| 9989 | + }, | |
| 9990 | + | |
| 9991 | + panelInit: function() { | |
| 9992 | + var customPanel, settingsPage, viewPage, insertFieldsTab; | |
| 9993 | + | |
| 9994 | + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'click', '.frm_insert_code', insertCode ); | |
| 9995 | + jQuery( document ).on( 'change', '.frm_insert_val', function() { | |
| 9996 | + insertFieldCode( jQuery( this ).data( 'target' ), jQuery( this ).val() ); | |
| 9997 | + jQuery( this ).val( '' ); | |
| 9998 | + }); | |
| 9999 | + | |
| 10000 | + jQuery( document ).on( 'click change', '#frm-id-key-condition', resetLogicBuilder ); | |
| 10001 | + jQuery( document ).on( 'keyup change', '.frm-build-logic', setLogicExample ); | |
| 10002 | + | |
| 10003 | + showInputIcon(); | |
| 10004 | + jQuery( document ).on( 'frmElementAdded', function( event, parentEle ) { | |
| 10005 | + /* This is here for add-ons to trigger */ | |
| 10006 | + showInputIcon( parentEle ); | |
| 10007 | + }); | |
| 10008 | + jQuery( document ).on( 'mousedown', '.frm-show-box', showShortcodes ); | |
| 10009 | + | |
| 10010 | + settingsPage = document.getElementById( 'form_settings_page' ); | |
| 10011 | + viewPage = document.body.classList.contains( 'post-type-frm_display' ); | |
| 10012 | + insertFieldsTab = document.getElementById( 'frm_insert_fields_tab' ); | |
| 10013 | + | |
| 10014 | + if ( settingsPage !== null || viewPage ) { | |
| 10015 | + jQuery( document ).on( 'focusin', 'form input, form textarea', function( e ) { | |
| 10016 | + var htmlTab; | |
| 10017 | + e.stopPropagation(); | |
| 10018 | + maybeShowModal( this ); | |
| 10019 | + | |
| 10020 | + if ( jQuery( this ).is( ':not(:submit, input[type=button], .frm-search-input, input[type=checkbox])' ) ) { | |
| 10021 | + if ( jQuery( e.target ).closest( '#frm_adv_info' ).length ) { | |
| 10022 | + // Don't trigger for fields inside of the modal. | |
| 10023 | + return; | |
| 10024 | + } | |
| 10025 | + | |
| 10026 | + if ( settingsPage !== null ) { | |
| 10027 | + /* form settings page */ | |
| 10028 | + htmlTab = jQuery( '#frm_html_tab' ); | |
| 10029 | + if ( jQuery( this ).closest( '#html_settings' ).length > 0 ) { | |
| 10030 | + htmlTab.show(); | |
| 10031 | + htmlTab.siblings().hide(); | |
| 10032 | + jQuery( '#frm_html_tab a' ).trigger( 'click' ); | |
| 10033 | + toggleAllowedHTML( this, e.type ); | |
| 10034 | + } else { | |
| 10035 | + showElement( jQuery( '.frm-category-tabs li' ) ); | |
| 10036 | + insertFieldsTab.click(); | |
| 10037 | + htmlTab.hide(); | |
| 10038 | + htmlTab.siblings().show(); | |
| 10039 | + } | |
| 10040 | + } else if ( viewPage ) { | |
| 10041 | + // Run on view page. | |
| 10042 | + toggleAllowedShortcodes( this.id, e.type ); | |
| 10043 | + } | |
| 10044 | + } | |
| 10045 | + }); | |
| 10046 | + } | |
| 10047 | + | |
| 10048 | + jQuery( '.frm_wrap, #postbox-container-1' ).on( 'mousedown', '#frm_adv_info a, .frm_field_list a', function( e ) { | |
| 10049 | + e.preventDefault(); | |
| 10050 | + }); | |
| 10051 | + | |
| 10052 | + customPanel = jQuery( '#frm_adv_info' ); | |
| 10053 | + customPanel.on( 'click', '.subsubsub a.frmids', function( e ) { | |
| 10054 | + toggleKeyID( 'frmids', e ); | |
| 10055 | + }); | |
| 10056 | + customPanel.on( 'click', '.subsubsub a.frmkeys', function( e ) { | |
| 10057 | + toggleKeyID( 'frmkeys', e ); | |
| 10058 | + }); | |
| 10059 | + }, | |
| 10060 | + | |
| 10061 | + viewInit: function() { | |
| 10062 | + var $addRemove, | |
| 10063 | + $advInfo = jQuery( document.getElementById( 'frm_adv_info' ) ); | |
| 10064 | + $advInfo.before( '<div id="frm_position_ele"></div>' ); | |
| 10065 | + setupMenuOffset(); | |
| 10066 | + | |
| 10067 | + jQuery( document ).on( 'blur', '#param', checkDetailPageSlug ); | |
| 10068 | + jQuery( document ).on( 'blur', 'input[name^="options[where_val]"]', checkFilterParamNames ); | |
| 10069 | + | |
| 10070 | + // Show loading indicator. | |
| 10071 | + jQuery( '#publish' ).on( 'mousedown', function() { | |
| 10072 | + fieldsUpdated = 0; | |
| 10073 | + this.classList.add( 'frm_loading_button' ); | |
| 10074 | + }); | |
| 10075 | + | |
| 10076 | + // move content tabs | |
| 10077 | + jQuery( '#frm_dyncontent .handlediv' ).before( jQuery( '#frm_dyncontent .nav-menus-php' ) ); | |
| 10078 | + | |
| 10079 | + // click content tabs | |
| 10080 | + jQuery( '.nav-tab-wrapper a' ).on( 'click', clickContentTab ); | |
| 10081 | + | |
| 10082 | + // click tabs after panel is replaced with ajax | |
| 10083 | + jQuery( '#side-sortables' ).on( 'click', '.frm_doing_ajax.categorydiv .category-tabs a', clickTabsAfterAjax ); | |
| 10084 | + | |
| 10085 | + initToggleShortcodes(); | |
| 10086 | + jQuery( '.frm_code_list:not(.frm-dropdown-menu) a' ).addClass( 'frm_noallow' ); | |
| 10087 | + | |
| 10088 | + jQuery( 'input[name="show_count"]' ).on( 'change', showCount ); | |
| 10089 | + | |
| 10090 | + jQuery( document.getElementById( 'form_id' ) ).on( 'change', displayFormSelected ); | |
| 10091 | + | |
| 10092 | + $addRemove = jQuery( '.frm_repeat_rows' ); | |
| 10093 | + $addRemove.on( 'click', '.frm_add_order_row', addOrderRow ); | |
| 10094 | + $addRemove.on( 'click', '.frm_add_where_row', addWhereRow ); | |
| 10095 | + $addRemove.on( 'change', '.frm_insert_where_options', insertWhereOptions ); | |
| 10096 | + $addRemove.on( 'change', '.frm_where_is_options', hideWhereOptions ); | |
| 10097 | + | |
| 10098 | + setDefaultPostStatus(); | |
| 10099 | + }, | |
| 10100 | + | |
| 10101 | + inboxInit: function() { | |
| 10102 | + jQuery( '.frm_inbox_dismiss, footer .frm-button-secondary, footer .frm-button-primary' ).on( 'click', function( e ) { | |
| 10103 | + var message = this.parentNode.parentNode, | |
| 10104 | + key = message.getAttribute( 'data-message' ), | |
| 10105 | + href = this.getAttribute( 'href' ); | |
| 10106 | + | |
| 10107 | + if ( 'free_templates' === key && ! this.classList.contains( 'frm_inbox_dismiss' ) ) { | |
| 10108 | + return; | |
| 10109 | + } | |
| 10110 | + | |
| 10111 | + e.preventDefault(); | |
| 10112 | + | |
| 10113 | + data = { | |
| 10114 | + action: 'frm_inbox_dismiss', | |
| 10115 | + key: key, | |
| 10116 | + nonce: frmGlobal.nonce | |
| 10117 | + }; | |
| 10118 | + postAjax( data, function() { | |
| 10119 | + if ( href !== '#' ) { | |
| 10120 | + window.location = href; | |
| 10121 | + return true; | |
| 10122 | + } | |
| 10123 | + fadeOut( message, function() { | |
| 10124 | + message.parentNode.removeChild( message ); | |
| 10125 | + }); | |
| 10126 | + }); | |
| 10127 | + }); | |
| 10128 | + jQuery( '#frm-dismiss-inbox' ).on( 'click', function( e ) { | |
| 10129 | + data = { | |
| 10130 | + action: 'frm_inbox_dismiss', | |
| 10131 | + key: 'all', | |
| 10132 | + nonce: frmGlobal.nonce | |
| 10133 | + }; | |
| 10134 | + postAjax( data, function() { | |
| 10135 | + fadeOut( document.getElementById( 'frm_message_list' ), function() { | |
| 10136 | + document.getElementById( 'frm_empty_inbox' ).classList.remove( 'frm_hidden' ); | |
| 10137 | + }); | |
| 10138 | + }); | |
| 10139 | + }); | |
| 10140 | + }, | |
| 10141 | + | |
| 10142 | + solutionInit: function() { | |
| 10143 | + jQuery( document ).on( 'submit', '#frm-new-template', installTemplate ); | |
| 10144 | + }, | |
| 10145 | + | |
| 10146 | + styleInit: function() { | |
| 10147 | + const $previewWrapper = jQuery( '.frm_image_preview_wrapper' ); | |
| 10148 | + $previewWrapper.on( 'click', '.frm_choose_image_box', addImageToOption ); | |
| 10149 | + $previewWrapper.on( 'click', '.frm_remove_image_option', removeImageFromOption ); | |
| 10150 | + | |
| 10151 | + wp.hooks.doAction( 'frm_style_editor_init' ); | |
| 10152 | + }, | |
| 10153 | + | |
| 10154 | + customCSSInit: function() { | |
| 10155 | + console.warn( 'Calling frmAdminBuild.customCSSInit is deprecated.' ); | |
| 10156 | + }, | |
| 10157 | + | |
| 10158 | + globalSettingsInit: function() { | |
| 10159 | + var licenseTab; | |
| 10160 | + | |
| 10161 | + jQuery( document ).on( 'click', '[data-frmuninstall]', uninstallNow ); | |
| 10162 | + | |
| 10163 | + initiateMultiselect(); | |
| 10164 | + | |
| 10165 | + // activate addon licenses | |
| 10166 | + licenseTab = document.getElementById( 'licenses_settings' ); | |
| 10167 | + if ( licenseTab !== null ) { | |
| 10168 | + jQuery( licenseTab ).on( 'click', '.edd_frm_save_license', saveAddonLicense ); | |
| 10169 | + } | |
| 10170 | + | |
| 10171 | + // Solution install page | |
| 10172 | + jQuery( document ).on( 'click', '#frm-new-template button', installTemplateFieldset ); | |
| 10173 | + | |
| 10174 | + jQuery( '#frm-dismissable-cta .dismiss' ).on( 'click', function( event ) { | |
| 10175 | + event.preventDefault(); | |
| 10176 | + jQuery.post( ajaxurl, { | |
| 10177 | + action: 'frm_lite_settings_upgrade' | |
| 10178 | + }); | |
| 10179 | + jQuery( '.settings-lite-cta' ).remove(); | |
| 10180 | + }); | |
| 10181 | + | |
| 10182 | + const captchaType = document.getElementById( 'frm_re_type' ); | |
| 10183 | + if ( captchaType ) { | |
| 10184 | + captchaType.addEventListener( 'change', handleCaptchaTypeChange ); | |
| 10185 | + } | |
| 10186 | + | |
| 10187 | + document.querySelector( '.frm_captchas' ).addEventListener( 'change', function() { | |
| 10188 | + document.querySelector( '.captcha_settings .frm_note_style' ).classList.toggle( 'frm_hidden' ); | |
| 10189 | + }); | |
| 10190 | + }, | |
| 10191 | + | |
| 10192 | + exportInit: function() { | |
| 10193 | + jQuery( '.frm_form_importer' ).on( 'submit', startFormMigration ); | |
| 10194 | + jQuery( document.getElementById( 'frm_export_xml' ) ).on( 'submit', validateExport ); | |
| 10195 | + jQuery( '#frm_export_xml input, #frm_export_xml select' ).on( 'change', removeExportError ); | |
| 10196 | + jQuery( 'input[name="frm_import_file"]' ).on( 'change', checkCSVExtension ); | |
| 10197 | + document.querySelector( 'select[name="format"]' ).addEventListener( 'change', exportTypeChanged ); | |
| 10198 | + | |
| 10199 | + jQuery( 'input[name="frm_export_forms[]"]' ).on( 'click', preventMultipleExport ); | |
| 10200 | + initiateMultiselect(); | |
| 10201 | + | |
| 10202 | + jQuery( '.frm-feature-banner .dismiss' ).on( 'click', function( event ) { | |
| 10203 | + event.preventDefault(); | |
| 10204 | + jQuery.post( ajaxurl, { | |
| 10205 | + action: 'frm_dismiss_migrator', | |
| 10206 | + plugin: this.id, | |
| 10207 | + nonce: frmGlobal.nonce | |
| 10208 | + }); | |
| 10209 | + this.parentElement.remove(); | |
| 10210 | + }); | |
| 10211 | + | |
| 10212 | + showOrHideRepeaters( getExportOption() ); | |
| 10213 | + }, | |
| 10214 | + | |
| 10215 | + inboxBannerInit: function() { | |
| 10216 | + const banner = document.getElementById( 'frm_banner' ); | |
| 10217 | + if ( ! banner ) { | |
| 10218 | + return; | |
| 10219 | + } | |
| 10220 | + | |
| 10221 | + const dismissButton = banner.querySelector( '.frm-banner-dismiss' ); | |
| 10222 | + document.addEventListener( | |
| 10223 | + 'click', | |
| 10224 | + function( event ) { | |
| 10225 | + if ( event.target !== dismissButton ) { | |
| 10226 | + return; | |
| 10227 | + } | |
| 10228 | + | |
| 10229 | + const data = { | |
| 10230 | + action: 'frm_inbox_dismiss', | |
| 10231 | + key: banner.dataset.key, | |
| 10232 | + nonce: frmGlobal.nonce | |
| 10233 | + }; | |
| 10234 | + postAjax( | |
| 10235 | + data, | |
| 10236 | + function() { | |
| 10237 | + jQuery( banner ).fadeOut( | |
| 10238 | + 400, | |
| 10239 | + function() { | |
| 10240 | + banner.remove(); | |
| 10241 | + } | |
| 10242 | + ); | |
| 10243 | + } | |
| 10244 | + ); | |
| 10245 | + } | |
| 10246 | + ); | |
| 10247 | + }, | |
| 10248 | + | |
| 10249 | + updateOpts: function( fieldId, opts, modal ) { | |
| 10250 | + var separate = usingSeparateValues( fieldId ), | |
| 10251 | + action = isProductField( fieldId ) ? 'frm_bulk_products' : 'frm_import_options'; | |
| 10252 | + jQuery.ajax({ | |
| 10253 | + type: 'POST', | |
| 10254 | + url: ajaxurl, | |
| 10255 | + data: { | |
| 10256 | + action: action, | |
| 10257 | + field_id: fieldId, | |
| 10258 | + opts: opts, | |
| 10259 | + separate: separate, | |
| 10260 | + nonce: frmGlobal.nonce | |
| 10261 | + }, | |
| 10262 | + success: function( html ) { | |
| 10263 | + document.getElementById( 'frm_field_' + fieldId + '_opts' ).innerHTML = html; | |
| 10264 | + resetDisplayedOpts( fieldId ); | |
| 10265 | + | |
| 10266 | + if ( typeof modal !== 'undefined' ) { | |
| 10267 | + modal.dialog( 'close' ); | |
| 10268 | + document.getElementById( 'frm-update-bulk-opts' ).classList.remove( 'frm_loading_button' ); | |
| 10269 | + } | |
| 10270 | + } | |
| 10271 | + }); | |
| 10272 | + }, | |
| 10273 | + | |
| 10274 | + /* remove conditional logic if the field doesn't exist */ | |
| 10275 | + triggerRemoveLogic: function( fieldID, metaName ) { | |
| 10276 | + jQuery( '#frm_logic_' + fieldID + '_' + metaName + ' .frm_remove_tag' ).trigger( 'click' ); | |
| 10277 | + }, | |
| 10278 | + | |
| 10279 | + downloadXML: function( controller, ids, isTemplate ) { | |
| 10280 | + var url = ajaxurl + '?action=frm_' + controller + '_xml&ids=' + ids; | |
| 10281 | + if ( isTemplate !== null ) { | |
| 10282 | + url = url + '&is_template=' + isTemplate; | |
| 10283 | + } | |
| 10284 | + location.href = url; | |
| 10285 | + }, | |
| 10286 | + | |
| 10287 | + /** | |
| 10288 | + * @since 5.0.04 | |
| 10289 | + */ | |
| 10290 | + hooks: { | |
| 10291 | + applyFilters: function( hookName, ...args ) { | |
| 10292 | + return wp.hooks.applyFilters( hookName, ...args ); | |
| 10293 | + }, | |
| 10294 | + addFilter: function( hookName, callback, priority ) { | |
| 10295 | + return wp.hooks.addFilter( hookName, 'formidable', callback, priority ); | |
| 10296 | + }, | |
| 10297 | + doAction: function( hookName, ...args ) { | |
| 10298 | + return wp.hooks.doAction( hookName, ...args ); | |
| 10299 | + }, | |
| 10300 | + addAction: function( hookName, callback, priority ) { | |
| 10301 | + return wp.hooks.addAction( hookName, 'formidable', callback, priority ); | |
| 10302 | + } | |
| 10303 | + }, | |
| 10304 | + | |
| 10305 | + infoModal: infoModal | |
| 10306 | + }; | |
| 10307 | +} | |
| 10308 | + | |
| 10309 | +frmAdminBuild = frmAdminBuildJS(); | |
| 10310 | + | |
| 10311 | +jQuery( document ).ready( | |
| 10312 | + () => { | |
| 10313 | + frmAdminBuild.init(); | |
| 10314 | + | |
| 10315 | + frmDom.bootstrap.setupBootstrapDropdowns( convertOldBootstrapDropdownsToBootstrap4 ); | |
| 10316 | + function convertOldBootstrapDropdownsToBootstrap4( frmDropdownMenu ) { | |
| 10317 | + const toggle = frmDropdownMenu.querySelector( '.frm-dropdown-toggle' ); | |
| 10318 | + if ( toggle ) { | |
| 10319 | + if ( ! toggle.hasAttribute( 'role' ) ) { | |
| 10320 | + toggle.setAttribute( 'role', 'button' ); | |
| 10321 | + } | |
| 10322 | + if ( ! toggle.hasAttribute( 'tabindex' ) ) { | |
| 10323 | + toggle.setAttribute( 'tabindex', 0 ); | |
| 10324 | + } | |
| 10325 | + } | |
| 10326 | + | |
| 10327 | + // Convert <li> and <ul> tags. | |
| 10328 | + if ( 'UL' === frmDropdownMenu.tagName ) { | |
| 10329 | + convertBootstrapUl( frmDropdownMenu ); | |
| 10330 | + } | |
| 10331 | + } | |
| 10332 | + | |
| 10333 | + function convertBootstrapUl( ul ) { | |
| 10334 | + let html = ul.outerHTML; | |
| 10335 | + html = html.replace( '<ul ', '<div ' ); | |
| 10336 | + html = html.replace( '</ul>', '</div>' ); | |
| 10337 | + html = html.replaceAll( '<li>', '<div class="dropdown-item">' ); | |
| 10338 | + html = html.replaceAll( '<li class="', '<div class="dropdown-item ' ); | |
| 10339 | + html = html.replaceAll( '</li>', '</div>' ); | |
| 10340 | + ul.outerHTML = html; | |
| 10341 | + } | |
| 10342 | + } | |
| 10343 | +); | |
| 10344 | + | |
| 10345 | +function frm_remove_tag( htmlTag ) { // eslint-disable-line camelcase | |
| 10346 | + console.warn( 'DEPRECATED: function frm_remove_tag in v2.0' ); | |
| 10347 | + jQuery( htmlTag ).remove(); | |
| 10348 | +} | |
| 10349 | + | |
| 10350 | +function frm_show_div( div, value, showIf, classId ) { // eslint-disable-line camelcase | |
| 10351 | + if ( value == showIf ) { | |
| 10352 | + jQuery( classId + div ).fadeIn( 'slow' ).css( 'visibility', 'visible' ); | |
| 10353 | + } else { | |
| 10354 | + jQuery( classId + div ).fadeOut( 'slow' ); | |
| 10355 | + } | |
| 10356 | +} | |
| 10357 | + | |
| 10358 | +function frmCheckAll( checked, n ) { | |
| 10359 | + jQuery( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked ); | |
| 10360 | +} | |
| 10361 | + | |
| 10362 | +function frmCheckAllLevel( checked, n, level ) { | |
| 10363 | + var $kids = jQuery( '.frm_catlevel_' + level ).children( '.frm_checkbox' ).children( 'label' ); | |
| 10364 | + $kids.children( 'input[name^="' + n + '"]' ).prop( 'checked', ! ! checked ); | |
| 10365 | +} | |
| 10366 | + | |
| 10367 | +function frm_add_logic_row( id, formId ) { // eslint-disable-line camelcase | |
| 10368 | + console.warn( 'DEPRECATED: function frm_add_logic_row in v2.0' ); | |
| 10369 | + jQuery.ajax({ | |
| 10370 | + type: 'POST', | |
| 10371 | + url: ajaxurl, | |
| 10372 | + data: { | |
| 10373 | + action: 'frm_add_logic_row', | |
| 10374 | + form_id: formId, | |
| 10375 | + field_id: id, | |
| 10376 | + meta_name: jQuery( '#frm_logic_row_' + id + ' > div' ).length, | |
| 10377 | + nonce: frmGlobal.nonce | |
| 10378 | + }, | |
| 10379 | + success: function( html ) { | |
| 10380 | + jQuery( '#frm_logic_row_' + id ).append( html ); | |
| 10381 | + } | |
| 10382 | + }); | |
| 10383 | + return false; | |
| 10384 | +} | |
| 10385 | + | |
| 10386 | +function frmGetFieldValues( fieldId, cur, rowNumber, fieldType, htmlName ) { | |
| 10387 | + | |
| 10388 | + if ( fieldId ) { | |
| 10389 | + jQuery.ajax({ | |
| 10390 | + type: 'POST', url: ajaxurl, | |
| 10391 | + data: 'action=frm_get_field_values¤t_field=' + cur + '&field_id=' + fieldId + '&name=' + htmlName + '&t=' + fieldType + '&form_action=' + jQuery( 'input[name="frm_action"]' ).val() + '&nonce=' + frmGlobal.nonce, | |
| 10392 | + success: function( msg ) { | |
| 10393 | + document.getElementById( 'frm_show_selected_values_' + cur + '_' + rowNumber ).innerHTML = msg; | |
| 10394 | + } | |
| 10395 | + }); | |
| 10396 | + } | |
| 10397 | +} | |
| 10398 | + | |
| 10399 | +function frmImportCsv( formID ) { | |
| 10400 | + var urlVars = ''; | |
| 10401 | + if ( typeof __FRMURLVARS !== 'undefined' ) { | |
| 10402 | + urlVars = __FRMURLVARS; | |
| 10403 | + } | |
| 10404 | + | |
| 10405 | + jQuery.ajax({ | |
| 10406 | + type: 'POST', url: ajaxurl, | |
| 10407 | + data: 'action=frm_import_csv&nonce=' + frmGlobal.nonce + '&frm_skip_cookie=1' + urlVars, | |
| 10408 | + success: function( count ) { | |
| 10409 | + var max = jQuery( '.frm_admin_progress_bar' ).attr( 'aria-valuemax' ); | |
| 10410 | + var imported = max - count; | |
| 10411 | + var percent = ( imported / max ) * 100; | |
| 10412 | + jQuery( '.frm_admin_progress_bar' ).css( 'width', percent + '%' ).attr( 'aria-valuenow', imported ); | |
| 10413 | + | |
| 10414 | + if ( parseInt( count, 10 ) > 0 ) { | |
| 10415 | + jQuery( '.frm_csv_remaining' ).html( count ); | |
| 10416 | + frmImportCsv( formID ); | |
| 10417 | + } else { | |
| 10418 | + jQuery( document.getElementById( 'frm_import_message' ) ).html( frm_admin_js.import_complete ); | |
| 10419 | + setTimeout( function() { | |
| 10420 | + location.href = '?page=formidable-entries&frm_action=list&form=' + formID + '&import-message=1'; | |
| 10421 | + }, 2000 ); | |
| 10422 | + } | |
| 10423 | + } | |
| 10424 | + }); | |
| 10425 | +} | |